diff options
-rw-r--r-- | usr.sbin/httpd/src/ap/ap_base64.c | 215 | ||||
-rw-r--r-- | usr.sbin/httpd/src/ap/ap_checkpass.c | 42 | ||||
-rw-r--r-- | usr.sbin/httpd/src/ap/ap_cpystrn.c | 27 | ||||
-rw-r--r-- | usr.sbin/httpd/src/ap/ap_ctx.c | 148 | ||||
-rw-r--r-- | usr.sbin/httpd/src/ap/ap_ebcdic.c | 2 | ||||
-rw-r--r-- | usr.sbin/httpd/src/ap/ap_execve.c | 7 | ||||
-rw-r--r-- | usr.sbin/httpd/src/ap/ap_fnmatch.c | 323 | ||||
-rw-r--r-- | usr.sbin/httpd/src/ap/ap_getpass.c | 20 | ||||
-rw-r--r-- | usr.sbin/httpd/src/ap/ap_hook.c | 1242 | ||||
-rw-r--r-- | usr.sbin/httpd/src/ap/ap_md5c.c | 395 | ||||
-rw-r--r-- | usr.sbin/httpd/src/ap/ap_mm.c | 12 | ||||
-rw-r--r-- | usr.sbin/httpd/src/ap/ap_sha1.c | 74 | ||||
-rw-r--r-- | usr.sbin/httpd/src/ap/ap_signal.c | 19 | ||||
-rw-r--r-- | usr.sbin/httpd/src/ap/ap_slack.c | 54 | ||||
-rw-r--r-- | usr.sbin/httpd/src/ap/ap_snprintf.c | 1843 | ||||
-rw-r--r-- | usr.sbin/httpd/src/ap/ap_strtol.c | 8 |
16 files changed, 2238 insertions, 2193 deletions
diff --git a/usr.sbin/httpd/src/ap/ap_base64.c b/usr.sbin/httpd/src/ap/ap_base64.c index 7d48df7fb83..fce8edfb7fb 100644 --- a/usr.sbin/httpd/src/ap/ap_base64.c +++ b/usr.sbin/httpd/src/ap/ap_base64.c @@ -1,3 +1,5 @@ +/* $OpenBSD: ap_base64.c,v 1.8 2005/03/28 21:03:33 niallo Exp $ */ + /* ==================================================================== * The Apache Software License, Version 1.1 * @@ -71,142 +73,143 @@ /* aaaack but it's fast and const should make it shared text page. */ static const unsigned char pr2six[256] = { - /* ASCII table */ - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, - 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, - 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 + /* ASCII table */ + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, + 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, + 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }; -API_EXPORT(int) ap_base64decode_len(const char *bufcoded) +API_EXPORT(int) +ap_base64decode_len(const char *bufcoded) { - int nbytesdecoded; - register const unsigned char *bufin; - register int nprbytes; + int nbytesdecoded; + register const unsigned char *bufin; + register int nprbytes; - bufin = (const unsigned char *) bufcoded; - while (pr2six[*(bufin++)] <= 63); + bufin = (const unsigned char *) bufcoded; + while (pr2six[*(bufin++)] <= 63); - nprbytes = (bufin - (const unsigned char *) bufcoded) - 1; - nbytesdecoded = ((nprbytes + 3) / 4) * 3; + nprbytes = (bufin - (const unsigned char *) bufcoded) - 1; + nbytesdecoded = ((nprbytes + 3) / 4) * 3; - return nbytesdecoded + 1; + return nbytesdecoded + 1; } -API_EXPORT(int) ap_base64decode(char *bufplain, const char *bufcoded) +API_EXPORT(int) +ap_base64decode(char *bufplain, const char *bufcoded) { - int len; - - len = ap_base64decode_binary((unsigned char *) bufplain, bufcoded); - bufplain[len] = '\0'; - return len; + int len; + + len = ap_base64decode_binary((unsigned char *) bufplain, bufcoded); + bufplain[len] = '\0'; + return len; } /* This is the same as ap_base64udecode() except on EBCDIC machines, where * the conversion of the output to ebcdic is left out. */ -API_EXPORT(int) ap_base64decode_binary(unsigned char *bufplain, - const char *bufcoded) +API_EXPORT(int) +ap_base64decode_binary(unsigned char *bufplain, const char *bufcoded) { - int nbytesdecoded; - register const unsigned char *bufin; - register unsigned char *bufout; - register int nprbytes; - - bufin = (const unsigned char *) bufcoded; - while (pr2six[*(bufin++)] <= 63); - nprbytes = (bufin - (const unsigned char *) bufcoded) - 1; - nbytesdecoded = ((nprbytes + 3) / 4) * 3; - - bufout = (unsigned char *) bufplain; - bufin = (const unsigned char *) bufcoded; - - while (nprbytes > 4) { - *(bufout++) = - (unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); - *(bufout++) = - (unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); - *(bufout++) = - (unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); - bufin += 4; - nprbytes -= 4; - } - - /* Note: (nprbytes == 1) would be an error, so just ingore that case */ - if (nprbytes > 1) { - *(bufout++) = - (unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); - } - if (nprbytes > 2) { - *(bufout++) = - (unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); - } - if (nprbytes > 3) { - *(bufout++) = - (unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); - } - - nbytesdecoded -= (4 - nprbytes) & 3; - return nbytesdecoded; + int nbytesdecoded; + register const unsigned char *bufin; + register unsigned char *bufout; + register int nprbytes; + bufin = (const unsigned char *) bufcoded; + while (pr2six[*(bufin++)] <= 63); + nprbytes = (bufin - (const unsigned char *) bufcoded) - 1; + nbytesdecoded = ((nprbytes + 3) / 4) * 3; + + bufout = (unsigned char *) bufplain; + bufin = (const unsigned char *) bufcoded; + + while (nprbytes > 4) { + *(bufout++) = (unsigned char) (pr2six[*bufin] << 2 + | pr2six[bufin[1]] >> 4); + *(bufout++) = (unsigned char) (pr2six[bufin[1]] << 4 + | pr2six[bufin[2]] >> 2); + *(bufout++) = (unsigned char) (pr2six[bufin[2]] << 6 + | pr2six[bufin[3]]); + bufin += 4; + nprbytes -= 4; + } + + /* Note: (nprbytes == 1) would be an error, so just ingore that case */ + if (nprbytes > 1) + *(bufout++) = (unsigned char) (pr2six[*bufin] << 2 + | pr2six[bufin[1]] >> 4); + if (nprbytes > 2) + *(bufout++) = (unsigned char) (pr2six[bufin[1]] << 4 + | pr2six[bufin[2]] >> 2); + if (nprbytes > 3) + *(bufout++) = (unsigned char) (pr2six[bufin[2]] << 6 + | pr2six[bufin[3]]); + + nbytesdecoded -= (4 - nprbytes) & 3; + return nbytesdecoded; } static const char basis_64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -API_EXPORT(int) ap_base64encode_len(int len) +API_EXPORT(int) +ap_base64encode_len(int len) { - return ((len + 2) / 3 * 4) + 1; + return ((len + 2) / 3 * 4) + 1; } -API_EXPORT(int) ap_base64encode(char *encoded, const char *string, int len) +API_EXPORT(int) +ap_base64encode(char *encoded, const char *string, int len) { - return ap_base64encode_binary(encoded, (const unsigned char *) string, len); + return ap_base64encode_binary(encoded, (const unsigned char *) string, + len); } /* This is the same as ap_base64encode() except on EBCDIC machines, where * the conversion of the input to ascii is left out. */ -API_EXPORT(int) ap_base64encode_binary(char *encoded, - const unsigned char *string, int len) +API_EXPORT(int) +ap_base64encode_binary(char *encoded, const unsigned char *string, int len) { - int i; - char *p; - - p = encoded; - for (i = 0; i < len - 2; i += 3) { - *p++ = basis_64[(string[i] >> 2) & 0x3F]; - *p++ = basis_64[((string[i] & 0x3) << 4) | - ((int) (string[i + 1] & 0xF0) >> 4)]; - *p++ = basis_64[((string[i + 1] & 0xF) << 2) | - ((int) (string[i + 2] & 0xC0) >> 6)]; - *p++ = basis_64[string[i + 2] & 0x3F]; - } - if (i < len) { - *p++ = basis_64[(string[i] >> 2) & 0x3F]; - if (i == (len - 1)) { - *p++ = basis_64[((string[i] & 0x3) << 4)]; - *p++ = '='; + int i; + char *p; + + p = encoded; + for (i = 0; i < len - 2; i += 3) { + *p++ = basis_64[(string[i] >> 2) & 0x3F]; + *p++ = basis_64[((string[i] & 0x3) << 4) | + ((int) (string[i + 1] & 0xF0) >> 4)]; + *p++ = basis_64[((string[i + 1] & 0xF) << 2) | + ((int) (string[i + 2] & 0xC0) >> 6)]; + *p++ = basis_64[string[i + 2] & 0x3F]; } - else { - *p++ = basis_64[((string[i] & 0x3) << 4) | - ((int) (string[i + 1] & 0xF0) >> 4)]; - *p++ = basis_64[((string[i + 1] & 0xF) << 2)]; + if (i < len) { + *p++ = basis_64[(string[i] >> 2) & 0x3F]; + if (i == (len - 1)) { + *p++ = basis_64[((string[i] & 0x3) << 4)]; + *p++ = '='; + } + else { + *p++ = basis_64[((string[i] & 0x3) << 4) | + ((int) (string[i + 1] & 0xF0) >> 4)]; + *p++ = basis_64[((string[i + 1] & 0xF) << 2)]; + } + *p++ = '='; } - *p++ = '='; - } - *p++ = '\0'; - return p - encoded; + *p++ = '\0'; + return p - encoded; } diff --git a/usr.sbin/httpd/src/ap/ap_checkpass.c b/usr.sbin/httpd/src/ap/ap_checkpass.c index 915238f863a..0158cf9e583 100644 --- a/usr.sbin/httpd/src/ap/ap_checkpass.c +++ b/usr.sbin/httpd/src/ap/ap_checkpass.c @@ -1,3 +1,5 @@ +/* $OpenBSD */ + /* ==================================================================== * The Apache Software License, Version 1.1 * @@ -70,35 +72,31 @@ /* * Validate a plaintext password against a smashed one. Use either - * crypt() (if available), ap_MD5Encode() or ap_SHA1Encode depending - * upon the format of the smashed input password. + * crypt() (if available), ap_MD5Encode() or ap_SHA1Encode depending + * upon the format of the smashed input password. * * Return NULL if they match, or an explanatory text string if they don't. */ -API_EXPORT(char *) ap_validate_password(const char *passwd, const char *hash) +API_EXPORT(char *) +ap_validate_password(const char *passwd, const char *hash) { - char sample[120]; - - - /* FreeBSD style MD5 string - */ - if (strncmp(hash, AP_MD5PW_ID, AP_MD5PW_IDLEN) == 0) { - - ap_MD5Encode((const unsigned char *)passwd, - (const unsigned char *)hash, sample, sizeof(sample)); - } - /* Netscape / SHA1 ldap style strng - */ - else if (strncmp(hash, AP_SHA1PW_ID, AP_SHA1PW_IDLEN) == 0) { + char sample[120]; - ap_sha1_base64(passwd, strlen(passwd), sample); - } - else { + /* FreeBSD style MD5 string + */ + if (strncmp(hash, AP_MD5PW_ID, AP_MD5PW_IDLEN) == 0) + ap_MD5Encode((const unsigned char *)passwd, + (const unsigned char *)hash, sample, sizeof(sample)); + /* Netscape / SHA1 ldap style strng + */ + else if (strncmp(hash, AP_SHA1PW_ID, AP_SHA1PW_IDLEN) == 0) + ap_sha1_base64(passwd, strlen(passwd), sample); /* * It's not our algorithm, so feed it to crypt() if possible. */ - ap_cpystrn(sample, (char *)crypt(passwd, hash), sizeof(sample) - 1); - } - return (strcmp(sample, hash) == 0) ? NULL : "password mismatch"; + else + ap_cpystrn(sample, (char *)crypt(passwd, hash), + sizeof(sample) - 1); + return (strcmp(sample, hash) == 0) ? NULL : "password mismatch"; } diff --git a/usr.sbin/httpd/src/ap/ap_cpystrn.c b/usr.sbin/httpd/src/ap/ap_cpystrn.c index d7049a4c7d5..791df23b70a 100644 --- a/usr.sbin/httpd/src/ap/ap_cpystrn.c +++ b/usr.sbin/httpd/src/ap/ap_cpystrn.c @@ -1,3 +1,5 @@ +/* $OpenBSD */ + /* ==================================================================== * The Apache Software License, Version 1.1 * @@ -71,24 +73,23 @@ * ap_cpystrn() follows the same call structure as strncpy(). */ -API_EXPORT(char *) ap_cpystrn(char *dst, const char *src, size_t dst_size) +API_EXPORT(char *) +ap_cpystrn(char *dst, const char *src, size_t dst_size) { - char *d, *end; + char *d, *end; - if (!dst_size) - return (dst); + if (!dst_size) + return (dst); - d = dst; - end = dst + dst_size - 1; + d = dst; + end = dst + dst_size - 1; - for (; d < end; ++d, ++src) { - if (!(*d = *src)) { - return (d); - } - } + for (; d < end; ++d, ++src) + if (!(*d = *src)) + return (d); - *d = '\0'; /* always null terminate */ + *d = '\0'; /* always null terminate */ - return (d); + return (d); } diff --git a/usr.sbin/httpd/src/ap/ap_ctx.c b/usr.sbin/httpd/src/ap/ap_ctx.c index b85940e54ae..b5f785e0a73 100644 --- a/usr.sbin/httpd/src/ap/ap_ctx.c +++ b/usr.sbin/httpd/src/ap/ap_ctx.c @@ -1,3 +1,5 @@ +/* $OpenBSD */ + /* ==================================================================== * Copyright (c) 1998-2000 The Apache Group. All rights reserved. * @@ -64,88 +66,94 @@ #include "ap_config.h" #include "ap_ctx.h" -API_EXPORT(ap_ctx *) ap_ctx_new(pool *p) +API_EXPORT(ap_ctx *) +ap_ctx_new(pool *p) { - ap_ctx *ctx; - int i; + ap_ctx *ctx; + int i; - if (p != NULL) { - ctx = (ap_ctx *)ap_palloc(p, sizeof(ap_ctx_rec)); - ctx->cr_pool = p; - ctx->cr_entry = (ap_ctx_entry **) - ap_palloc(p, sizeof(ap_ctx_entry *)*(AP_CTX_MAX_ENTRIES+1)); - } - else { - ctx = (ap_ctx *)malloc(sizeof(ap_ctx_rec)); - ctx->cr_pool = NULL; - ctx->cr_entry = (ap_ctx_entry **) - malloc(sizeof(ap_ctx_entry *)*(AP_CTX_MAX_ENTRIES+1)); - } - for (i = 0; i < AP_CTX_MAX_ENTRIES+1; i++) - ctx->cr_entry[i] = NULL; - return ctx; + if (p != NULL) { + ctx = (ap_ctx *)ap_palloc(p, sizeof(ap_ctx_rec)); + ctx->cr_pool = p; + ctx->cr_entry = (ap_ctx_entry **) + ap_palloc(p, sizeof(ap_ctx_entry *)*(AP_CTX_MAX_ENTRIES+1)); + } + else { + ctx = (ap_ctx *)malloc(sizeof(ap_ctx_rec)); + ctx->cr_pool = NULL; + ctx->cr_entry = (ap_ctx_entry **) + malloc(sizeof(ap_ctx_entry *)*(AP_CTX_MAX_ENTRIES+1)); + } + for (i = 0; i < AP_CTX_MAX_ENTRIES+1; i++) + ctx->cr_entry[i] = NULL; + return ctx; } -API_EXPORT(void) ap_ctx_set(ap_ctx *ctx, char *key, void *val) +API_EXPORT(void) +ap_ctx_set(ap_ctx *ctx, char *key, void *val) { - int i; - ap_ctx_entry *ce; + int i; + ap_ctx_entry *ce; - ce = NULL; - for (i = 0; ctx->cr_entry[i] != NULL; i++) { - if (strcmp(ctx->cr_entry[i]->ce_key, key) == 0) { - ce = ctx->cr_entry[i]; - break; - } - } - if (ce == NULL) { - if (i == AP_CTX_MAX_ENTRIES) - return; - if (ctx->cr_pool != NULL) { - ce = (ap_ctx_entry *)ap_palloc(ctx->cr_pool, sizeof(ap_ctx_entry)); - ce->ce_key = ap_pstrdup(ctx->cr_pool, key); - } - else { - ce = (ap_ctx_entry *)malloc(sizeof(ap_ctx_entry)); - ce->ce_key = strdup(key); - } - ctx->cr_entry[i] = ce; - ctx->cr_entry[i+1] = NULL; - } - ce->ce_val = val; - return; + ce = NULL; + for (i = 0; ctx->cr_entry[i] != NULL; i++) { + if (strcmp(ctx->cr_entry[i]->ce_key, key) == 0) { + ce = ctx->cr_entry[i]; + break; + } + } + if (ce == NULL) { + if (i == AP_CTX_MAX_ENTRIES) + return; + if (ctx->cr_pool != NULL) { + ce = (ap_ctx_entry *)ap_palloc(ctx->cr_pool, + sizeof(ap_ctx_entry)); + ce->ce_key = ap_pstrdup(ctx->cr_pool, key); + } + else { + ce = (ap_ctx_entry *)malloc(sizeof(ap_ctx_entry)); + ce->ce_key = strdup(key); + } + ctx->cr_entry[i] = ce; + ctx->cr_entry[i+1] = NULL; + } + ce->ce_val = val; + return; } -API_EXPORT(void *) ap_ctx_get(ap_ctx *ctx, char *key) +API_EXPORT(void *) +ap_ctx_get(ap_ctx *ctx, char *key) { - int i; + int i; - for (i = 0; ctx->cr_entry[i] != NULL; i++) - if (strcmp(ctx->cr_entry[i]->ce_key, key) == 0) - return ctx->cr_entry[i]->ce_val; - return NULL; + for (i = 0; ctx->cr_entry[i] != NULL; i++) + if (strcmp(ctx->cr_entry[i]->ce_key, key) == 0) + return ctx->cr_entry[i]->ce_val; + return NULL; } -API_EXPORT(ap_ctx *) ap_ctx_overlay(pool *p, ap_ctx *over, ap_ctx *base) +API_EXPORT(ap_ctx *) +ap_ctx_overlay(pool *p, ap_ctx *over, ap_ctx *base) { - ap_ctx *new; - int i; + ap_ctx *new; + int i; -#ifdef POOL_DEBUG - if (p != NULL) { - if (!ap_pool_is_ancestor(over->cr_pool, p)) - ap_log_assert("ap_ctx_overlay: overlay's pool is not an ancestor of p", - __FILE__, __LINE__); - if (!ap_pool_is_ancestor(base->cr_pool, p)) - ap_log_assert("ap_ctx_overlay: base's pool is not an ancestor of p", - __FILE__, __LINE__); - } -#endif - if ((new = ap_ctx_new(p)) == NULL) - return NULL; - memcpy(new->cr_entry, base->cr_entry, - sizeof(ap_ctx_entry *)*(AP_CTX_MAX_ENTRIES+1)); - for (i = 0; over->cr_entry[i] != NULL; i++) - ap_ctx_set(new, over->cr_entry[i]->ce_key, over->cr_entry[i]->ce_val); - return new; + #ifdef POOL_DEBUG + if (p != NULL) { + if (!ap_pool_is_ancestor(over->cr_pool, p)) + ap_log_assert("ap_ctx_overlay: overlay's pool is not an" + " ancestor of p", __FILE__, __LINE__); + if (!ap_pool_is_ancestor(base->cr_pool, p)) + ap_log_assert("ap_ctx_overlay: base's pool is not an" + " ancestor of p", __FILE__, __LINE__); + } + #endif + if ((new = ap_ctx_new(p)) == NULL) + return NULL; + memcpy(new->cr_entry, base->cr_entry, + sizeof(ap_ctx_entry *)*(AP_CTX_MAX_ENTRIES+1)); + for (i = 0; over->cr_entry[i] != NULL; i++) + ap_ctx_set(new, over->cr_entry[i]->ce_key, + over->cr_entry[i]->ce_val); + return new; } diff --git a/usr.sbin/httpd/src/ap/ap_ebcdic.c b/usr.sbin/httpd/src/ap/ap_ebcdic.c index 2d3aadacaf5..50c1f35b1f4 100644 --- a/usr.sbin/httpd/src/ap/ap_ebcdic.c +++ b/usr.sbin/httpd/src/ap/ap_ebcdic.c @@ -1,3 +1,5 @@ +/* $OpenBSD */ + /* ==================================================================== * The Apache Software License, Version 1.1 * diff --git a/usr.sbin/httpd/src/ap/ap_execve.c b/usr.sbin/httpd/src/ap/ap_execve.c index 16bc27adc2b..0b89d4ebb1d 100644 --- a/usr.sbin/httpd/src/ap/ap_execve.c +++ b/usr.sbin/httpd/src/ap/ap_execve.c @@ -1,3 +1,5 @@ +/* $OpenBSD: ap_execve.c,v 1.11 2005/03/28 21:03:33 niallo Exp $ */ + /* ==================================================================== * The Apache Software License, Version 1.1 * @@ -92,4 +94,7 @@ /*---------------------------------------------------------------*/ extern void ap_execve_is_not_here(void); -void ap_execve_is_not_here(void) {} +void +ap_execve_is_not_here(void) +{ +} diff --git a/usr.sbin/httpd/src/ap/ap_fnmatch.c b/usr.sbin/httpd/src/ap/ap_fnmatch.c index d6f8ed2bc04..55a68cc39ae 100644 --- a/usr.sbin/httpd/src/ap/ap_fnmatch.c +++ b/usr.sbin/httpd/src/ap/ap_fnmatch.c @@ -1,3 +1,5 @@ +/* $OpenBSD */ + /* * Copyright (c) 1989, 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -39,192 +41,171 @@ #include "fnmatch.h" #include <string.h> -#define EOS '\0' +#define EOS '\0' static const char *rangematch(const char *, int, int); -API_EXPORT(int) ap_fnmatch(const char *pattern, const char *string, int flags) +API_EXPORT(int) +ap_fnmatch(const char *pattern, const char *string, int flags) { - const char *stringstart; - char c, test; - - for (stringstart = string;;) { - switch (c = *pattern++) { - case EOS: - return (*string == EOS ? 0 : FNM_NOMATCH); - case '?': - if (*string == EOS) { - return (FNM_NOMATCH); - } - if (*string == '/' && (flags & FNM_PATHNAME)) { - return (FNM_NOMATCH); - } - if (*string == '.' && (flags & FNM_PERIOD) && - (string == stringstart || - ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) { - return (FNM_NOMATCH); - } - ++string; - break; - case '*': - c = *pattern; - /* Collapse multiple stars. */ - while (c == '*') { - c = *++pattern; - } - - if (*string == '.' && (flags & FNM_PERIOD) && - (string == stringstart || - ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) { - return (FNM_NOMATCH); - } - - /* Optimize for pattern with * at end or before /. */ - if (c == EOS) { - if (flags & FNM_PATHNAME) { - return (strchr(string, '/') == NULL ? 0 : FNM_NOMATCH); - } - else { - return (0); - } - } - else if (c == '/' && flags & FNM_PATHNAME) { - if ((string = strchr(string, '/')) == NULL) { - return (FNM_NOMATCH); - } - break; - } - - /* General case, use recursion. */ - while ((test = *string) != EOS) { - if (!ap_fnmatch(pattern, string, flags & ~FNM_PERIOD)) { - return (0); - } - if (test == '/' && flags & FNM_PATHNAME) { - break; - } - ++string; - } - return (FNM_NOMATCH); - case '[': - if (*string == EOS) { - return (FNM_NOMATCH); - } - if (*string == '/' && flags & FNM_PATHNAME) { - return (FNM_NOMATCH); - } - if (*string == '.' && (flags & FNM_PERIOD) && - (string == stringstart || - ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) { - return (FNM_NOMATCH); - } - if ((pattern = rangematch(pattern, *string, flags)) == NULL) { - return (FNM_NOMATCH); - } - ++string; - break; - case '\\': - if (!(flags & FNM_NOESCAPE)) { - if ((c = *pattern++) == EOS) { - c = '\\'; - --pattern; + const char *stringstart; + char c, test; + + for (stringstart = string;;) { + switch (c = *pattern++) { + case EOS: + return (*string == EOS ? 0 : FNM_NOMATCH); + case '?': + if (*string == EOS) + return (FNM_NOMATCH); + if (*string == '/' && (flags & FNM_PATHNAME)) + return (FNM_NOMATCH); + if (*string == '.' && (flags & FNM_PERIOD) && + (string == stringstart || + ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + return (FNM_NOMATCH); + ++string; + break; + case '*': + c = *pattern; + /* Collapse multiple stars. */ + while (c == '*') + c = *++pattern; + + if (*string == '.' && (flags & FNM_PERIOD) && + (string == stringstart || + ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + return (FNM_NOMATCH); + + /* Optimize for pattern with * at end or before /. */ + if (c == EOS) { + if (flags & FNM_PATHNAME) + return (strchr(string, '/') == NULL ? 0 : FNM_NOMATCH); + else + return (0); + } + else if (c == '/' && flags & FNM_PATHNAME) { + if ((string = strchr(string, '/')) == NULL) + return (FNM_NOMATCH); + break; + } + + /* General case, use recursion. */ + while ((test = *string) != EOS) { + if (!ap_fnmatch(pattern, string, + flags & ~FNM_PERIOD)) + return (0); + if (test == '/' && flags & FNM_PATHNAME) + break; + ++string; + } + return (FNM_NOMATCH); + case '[': + if (*string == EOS) + return (FNM_NOMATCH); + if (*string == '/' && flags & FNM_PATHNAME) + return (FNM_NOMATCH); + if (*string == '.' && (flags & FNM_PERIOD) && + (string == stringstart || + ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + return (FNM_NOMATCH); + if ((pattern = rangematch(pattern, *string, flags)) + == NULL) + return (FNM_NOMATCH); + ++string; + break; + case '\\': + if (!(flags & FNM_NOESCAPE)) + if ((c = *pattern++) == EOS) { + c = '\\'; + --pattern; + } + /* FALLTHROUGH */ + default: + if (flags & FNM_CASE_BLIND) { + if (ap_tolower(c) != ap_tolower(*string)) + return (FNM_NOMATCH); + } + else if (c != *string) + return (FNM_NOMATCH); + string++; + break; } - } - /* FALLTHROUGH */ - default: - if (flags & FNM_CASE_BLIND) { - if (ap_tolower(c) != ap_tolower(*string)) { - return (FNM_NOMATCH); - } - } - else if (c != *string) { - return (FNM_NOMATCH); - } - string++; - break; + /* NOTREACHED */ } - /* NOTREACHED */ - } } -static const char *rangematch(const char *pattern, int test, int flags) +static const char * +rangematch(const char *pattern, int test, int flags) { - int negate, ok; - char c, c2; - - /* - * A bracket expression starting with an unquoted circumflex - * character produces unspecified results (IEEE 1003.2-1992, - * 3.13.2). This implementation treats it like '!', for - * consistency with the regular expression syntax. - * J.T. Conklin (conklin@ngai.kaleida.com) - */ - if ((negate = (*pattern == '!' || *pattern == '^'))) { - ++pattern; - } - - for (ok = 0; (c = *pattern++) != ']';) { - if (c == '\\' && !(flags & FNM_NOESCAPE)) { - c = *pattern++; - } - if (c == EOS) { - return (NULL); - } - if (*pattern == '-' && (c2 = *(pattern + 1)) != EOS && c2 != ']') { - pattern += 2; - if (c2 == '\\' && !(flags & FNM_NOESCAPE)) { - c2 = *pattern++; - } - if (c2 == EOS) { - return (NULL); - } - if ((c <= test && test <= c2) - || ((flags & FNM_CASE_BLIND) - && ((ap_tolower(c) <= ap_tolower(test)) - && (ap_tolower(test) <= ap_tolower(c2))))) { - ok = 1; - } - } - else if ((c == test) - || ((flags & FNM_CASE_BLIND) - && (ap_tolower(c) == ap_tolower(test)))) { - ok = 1; + int negate, ok; + char c, c2; + + /* + * A bracket expression starting with an unquoted circumflex + * character produces unspecified results (IEEE 1003.2-1992, + * 3.13.2). This implementation treats it like '!', for + * consistency with the regular expression syntax. + * J.T. Conklin (conklin@ngai.kaleida.com) + */ + if ((negate = (*pattern == '!' || *pattern == '^'))) + ++pattern; + + for (ok = 0; (c = *pattern++) != ']';) { + if (c == '\\' && !(flags & FNM_NOESCAPE)) + c = *pattern++; + if (c == EOS) + return (NULL); + if (*pattern == '-' && (c2 = *(pattern + 1)) != EOS && c2 + != ']') { + pattern += 2; + if (c2 == '\\' && !(flags & FNM_NOESCAPE)) + c2 = *pattern++; + if (c2 == EOS) + return (NULL); + if ((c <= test && test <= c2) + || ((flags & FNM_CASE_BLIND) + && ((ap_tolower(c) <= ap_tolower(test)) + && (ap_tolower(test) <= ap_tolower(c2))))) + ok = 1; + } + else if ((c == test) || ((flags & FNM_CASE_BLIND) + && (ap_tolower(c) == ap_tolower(test)))) + ok = 1; } - } - return (ok == negate ? NULL : pattern); + return (ok == negate ? NULL : pattern); } /* This function is an Apache addition */ /* return non-zero if pattern has any glob chars in it */ -API_EXPORT(int) ap_is_fnmatch(const char *pattern) +API_EXPORT(int) +ap_is_fnmatch(const char *pattern) { - int nesting; - - nesting = 0; - while (*pattern) { - switch (*pattern) { - case '?': - case '*': - return 1; - - case '\\': - if (*pattern++ == '\0') { - return 0; - } - break; - - case '[': /* '[' is only a glob if it has a matching ']' */ - ++nesting; - break; - - case ']': - if (nesting) { - return 1; - } - break; + int nesting; + + nesting = 0; + while (*pattern) { + switch (*pattern) { + case '?': + case '*': + return 1; + + case '\\': + if (*pattern++ == '\0') + return 0; + break; + + case '[': /* '[' is only a glob if it has a matching ']' */ + ++nesting; + break; + + case ']': + if (nesting) + return 1; + break; + } + ++pattern; } - ++pattern; - } - return 0; + return 0; } diff --git a/usr.sbin/httpd/src/ap/ap_getpass.c b/usr.sbin/httpd/src/ap/ap_getpass.c index ee2c2645145..b1804f0616a 100644 --- a/usr.sbin/httpd/src/ap/ap_getpass.c +++ b/usr.sbin/httpd/src/ap/ap_getpass.c @@ -1,3 +1,5 @@ +/* $OpenBSD: ap_getpass.c,v 1.8 2005/03/28 21:03:33 niallo Exp $ */ + /* ==================================================================== * The Apache Software License, Version 1.1 * @@ -88,15 +90,15 @@ * but the caller is *not* made aware of it. */ -API_EXPORT(int) ap_getpass(const char *prompt, char *pwbuf, size_t bufsiz) +API_EXPORT(int) +ap_getpass(const char *prompt, char *pwbuf, size_t bufsiz) { - char *pw_got; - int result = 0; + char *pw_got; + int result = 0; - pw_got = getpass(prompt); - if (strlen(pw_got) > (bufsiz - 1)) { - result = ERR_OVERFLOW; - } - ap_cpystrn(pwbuf, pw_got, bufsiz); - return result; + pw_got = getpass(prompt); + if (strlen(pw_got) > (bufsiz - 1)) + result = ERR_OVERFLOW; + ap_cpystrn(pwbuf, pw_got, bufsiz); + return result; } diff --git a/usr.sbin/httpd/src/ap/ap_hook.c b/usr.sbin/httpd/src/ap/ap_hook.c index 4eb551a1c5a..8f2359df4ae 100644 --- a/usr.sbin/httpd/src/ap/ap_hook.c +++ b/usr.sbin/httpd/src/ap/ap_hook.c @@ -93,15 +93,15 @@ static void ap_hook_destroy(ap_hook_entry *he); */ API_EXPORT(void) ap_hook_init(void) { - int i; - - if (ap_hook_pool != NULL) - return; - ap_hook_pool = (ap_hook_entry **)malloc(sizeof(ap_hook_entry *) - *(AP_HOOK_MAX_ENTRIES+1)); - for (i = 0; i < AP_HOOK_MAX_ENTRIES; i++) - ap_hook_pool[i] = NULL; - return; + int i; + + if (ap_hook_pool != NULL) + return; + ap_hook_pool = (ap_hook_entry **)malloc(sizeof(ap_hook_entry *) + *(AP_HOOK_MAX_ENTRIES+1)); + for (i = 0; i < AP_HOOK_MAX_ENTRIES; i++) + ap_hook_pool[i] = NULL; + return; } /* @@ -109,15 +109,15 @@ API_EXPORT(void) ap_hook_init(void) */ API_EXPORT(void) ap_hook_kill(void) { - int i; - - if (ap_hook_pool == NULL) - return; - for (i = 0; ap_hook_pool[i] != NULL; i++) - ap_hook_destroy(ap_hook_pool[i]); - free(ap_hook_pool); - ap_hook_pool = NULL; - return; + int i; + + if (ap_hook_pool == NULL) + return; + for (i = 0; ap_hook_pool[i] != NULL; i++) + ap_hook_destroy(ap_hook_pool[i]); + free(ap_hook_pool); + ap_hook_pool = NULL; + return; } /* @@ -126,33 +126,33 @@ API_EXPORT(void) ap_hook_kill(void) */ static ap_hook_entry *ap_hook_create(char *hook) { - int i; - ap_hook_entry *he; + int i; + ap_hook_entry *he; - for (i = 0; ap_hook_pool[i] != NULL; i++) - if (strcmp(ap_hook_pool[i]->he_hook, hook) == 0) - return ap_hook_pool[i]; + for (i = 0; ap_hook_pool[i] != NULL; i++) + if (strcmp(ap_hook_pool[i]->he_hook, hook) == 0) + return ap_hook_pool[i]; - if (i >= AP_HOOK_MAX_ENTRIES) - return NULL; + if (i >= AP_HOOK_MAX_ENTRIES) + return NULL; - if ((he = (ap_hook_entry *)malloc(sizeof(ap_hook_entry))) == NULL) - return NULL; - ap_hook_pool[i] = he; + if ((he = (ap_hook_entry *)malloc(sizeof(ap_hook_entry))) == NULL) + return NULL; + ap_hook_pool[i] = he; - he->he_hook = strdup(hook); - he->he_sig = AP_HOOK_SIG_UNKNOWN; - he->he_modeid = AP_HOOK_MODE_UNKNOWN; - he->he_modeval.v_int = 0; + he->he_hook = strdup(hook); + he->he_sig = AP_HOOK_SIG_UNKNOWN; + he->he_modeid = AP_HOOK_MODE_UNKNOWN; + he->he_modeval.v_int = 0; - he->he_func = (ap_hook_func **)malloc(sizeof(ap_hook_func *) - *(AP_HOOK_MAX_FUNCS+1)); - if (he->he_func == NULL) - return FALSE; + he->he_func = (ap_hook_func **)malloc(sizeof(ap_hook_func *) + *(AP_HOOK_MAX_FUNCS+1)); + if (he->he_func == NULL) + return FALSE; - for (i = 0; i < AP_HOOK_MAX_FUNCS; i++) - he->he_func[i] = NULL; - return he; + for (i = 0; i < AP_HOOK_MAX_FUNCS; i++) + he->he_func[i] = NULL; + return he; } /* @@ -160,12 +160,12 @@ static ap_hook_entry *ap_hook_create(char *hook) */ static ap_hook_entry *ap_hook_find(char *hook) { - int i; + int i; - for (i = 0; ap_hook_pool[i] != NULL; i++) - if (strcmp(ap_hook_pool[i]->he_hook, hook) == 0) - return ap_hook_pool[i]; - return NULL; + for (i = 0; ap_hook_pool[i] != NULL; i++) + if (strcmp(ap_hook_pool[i]->he_hook, hook) == 0) + return ap_hook_pool[i]; + return NULL; } /* @@ -173,16 +173,16 @@ static ap_hook_entry *ap_hook_find(char *hook) */ static void ap_hook_destroy(ap_hook_entry *he) { - int i; - - if (he == NULL) - return; - free(he->he_hook); - for (i = 0; he->he_func[i] != NULL; i++) - free(he->he_func[i]); - free(he->he_func); - free(he); - return; + int i; + + if (he == NULL) + return; + free(he->he_hook); + for (i = 0; he->he_func[i] != NULL; i++) + free(he->he_func[i]); + free(he->he_func); + free(he); + return; } /* @@ -191,34 +191,34 @@ static void ap_hook_destroy(ap_hook_entry *he) */ API_EXPORT(int) ap_hook_configure(char *hook, ap_hook_sig sig, ap_hook_mode modeid, ...) { - ap_hook_entry *he; - va_list ap; - int rc; - - va_start(ap, modeid); - if ((he = ap_hook_create(hook)) == NULL) - rc = FALSE; - else { - he->he_sig = sig; - he->he_modeid = modeid; - if (modeid == AP_HOOK_MODE_DECLINE || modeid == AP_HOOK_MODE_DECLTMP) { - if (AP_HOOK_SIG_HAS(sig, RC, char)) - he->he_modeval.v_char = va_arg(ap, va_type(char)); - else if (AP_HOOK_SIG_HAS(sig, RC, int)) - he->he_modeval.v_int = va_arg(ap, va_type(int)); - else if (AP_HOOK_SIG_HAS(sig, RC, long)) - he->he_modeval.v_long = va_arg(ap, va_type(long)); - else if (AP_HOOK_SIG_HAS(sig, RC, float)) - he->he_modeval.v_float = va_arg(ap, va_type(float)); - else if (AP_HOOK_SIG_HAS(sig, RC, double)) - he->he_modeval.v_double = va_arg(ap, va_type(double)); - else if (AP_HOOK_SIG_HAS(sig, RC, ptr)) - he->he_modeval.v_ptr = va_arg(ap, va_type(ptr)); - } - rc = TRUE; - } - va_end(ap); - return rc; + ap_hook_entry *he; + va_list ap; + int rc; + + va_start(ap, modeid); + if ((he = ap_hook_create(hook)) == NULL) + rc = FALSE; + else { + he->he_sig = sig; + he->he_modeid = modeid; + if (modeid == AP_HOOK_MODE_DECLINE || modeid == AP_HOOK_MODE_DECLTMP) { + if (AP_HOOK_SIG_HAS(sig, RC, char)) + he->he_modeval.v_char = va_arg(ap, va_type(char)); + else if (AP_HOOK_SIG_HAS(sig, RC, int)) + he->he_modeval.v_int = va_arg(ap, va_type(int)); + else if (AP_HOOK_SIG_HAS(sig, RC, long)) + he->he_modeval.v_long = va_arg(ap, va_type(long)); + else if (AP_HOOK_SIG_HAS(sig, RC, float)) + he->he_modeval.v_float = va_arg(ap, va_type(float)); + else if (AP_HOOK_SIG_HAS(sig, RC, double)) + he->he_modeval.v_double = va_arg(ap, va_type(double)); + else if (AP_HOOK_SIG_HAS(sig, RC, ptr)) + he->he_modeval.v_ptr = va_arg(ap, va_type(ptr)); + } + rc = TRUE; + } + va_end(ap); + return rc; } /* @@ -226,31 +226,31 @@ API_EXPORT(int) ap_hook_configure(char *hook, ap_hook_sig sig, ap_hook_mode mode */ API_EXPORT(int) ap_hook_register_I(char *hook, void *func, void *ctx) { - int i, j; - ap_hook_entry *he; - ap_hook_func *hf; + int i, j; + ap_hook_entry *he; + ap_hook_func *hf; - if ((he = ap_hook_create(hook)) == NULL) - return FALSE; + if ((he = ap_hook_create(hook)) == NULL) + return FALSE; - for (i = 0; he->he_func[i] != NULL; i++) - if (he->he_func[i]->hf_ptr == func) - return FALSE; + for (i = 0; he->he_func[i] != NULL; i++) + if (he->he_func[i]->hf_ptr == func) + return FALSE; - if (i == AP_HOOK_MAX_FUNCS) - return FALSE; + if (i == AP_HOOK_MAX_FUNCS) + return FALSE; - if ((hf = (ap_hook_func *)malloc(sizeof(ap_hook_func))) == NULL) - return FALSE; + if ((hf = (ap_hook_func *)malloc(sizeof(ap_hook_func))) == NULL) + return FALSE; - for (j = i; j >= 0; j--) - he->he_func[j+1] = he->he_func[j]; - he->he_func[0] = hf; + for (j = i; j >= 0; j--) + he->he_func[j+1] = he->he_func[j]; + he->he_func[0] = hf; - hf->hf_ptr = func; - hf->hf_ctx = ctx; + hf->hf_ptr = func; + hf->hf_ctx = ctx; - return TRUE; + return TRUE; } /* @@ -258,20 +258,20 @@ API_EXPORT(int) ap_hook_register_I(char *hook, void *func, void *ctx) */ API_EXPORT(int) ap_hook_unregister_I(char *hook, void *func) { - int i, j; - ap_hook_entry *he; - - if ((he = ap_hook_find(hook)) == NULL) - return FALSE; - for (i = 0; he->he_func[i] != NULL; i++) { - if (he->he_func[i]->hf_ptr == func) { - free(he->he_func[i]); - for (j = i; he->he_func[j] != NULL; j++) - he->he_func[j] = he->he_func[j+1]; - return TRUE; - } - } - return FALSE; + int i, j; + ap_hook_entry *he; + + if ((he = ap_hook_find(hook)) == NULL) + return FALSE; + for (i = 0; he->he_func[i] != NULL; i++) { + if (he->he_func[i]->hf_ptr == func) { + free(he->he_func[i]); + for (j = i; he->he_func[j] != NULL; j++) + he->he_func[j] = he->he_func[j+1]; + return TRUE; + } + } + return FALSE; } /* @@ -279,18 +279,18 @@ API_EXPORT(int) ap_hook_unregister_I(char *hook, void *func) */ API_EXPORT(ap_hook_state) ap_hook_status(char *hook) { - ap_hook_entry *he; - - if ((he = ap_hook_find(hook)) == NULL) - return AP_HOOK_STATE_NOTEXISTANT; - if ( he->he_func[0] != NULL - && he->he_sig != AP_HOOK_SIG_UNKNOWN - && he->he_modeid != AP_HOOK_MODE_UNKNOWN) - return AP_HOOK_STATE_REGISTERED; - if ( he->he_sig != AP_HOOK_SIG_UNKNOWN - && he->he_modeid != AP_HOOK_MODE_UNKNOWN) - return AP_HOOK_STATE_CONFIGURED; - return AP_HOOK_STATE_ESTABLISHED; + ap_hook_entry *he; + + if ((he = ap_hook_find(hook)) == NULL) + return AP_HOOK_STATE_NOTEXISTANT; + if ( he->he_func[0] != NULL + && he->he_sig != AP_HOOK_SIG_UNKNOWN + && he->he_modeid != AP_HOOK_MODE_UNKNOWN) + return AP_HOOK_STATE_REGISTERED; + if ( he->he_sig != AP_HOOK_SIG_UNKNOWN + && he->he_modeid != AP_HOOK_MODE_UNKNOWN) + return AP_HOOK_STATE_CONFIGURED; + return AP_HOOK_STATE_ESTABLISHED; } /* @@ -298,52 +298,52 @@ API_EXPORT(ap_hook_state) ap_hook_status(char *hook) */ API_EXPORT(int) ap_hook_use(char *hook, ap_hook_sig sig, ap_hook_mode modeid, ...) { - int i; - ap_hook_value modeval; - ap_hook_entry *he; - va_list ap; - int rc; - - va_start(ap, modeid); - - if (modeid == AP_HOOK_MODE_DECLINE || modeid == AP_HOOK_MODE_DECLTMP) { - if (AP_HOOK_SIG_HAS(sig, RC, char)) - modeval.v_char = va_arg(ap, va_type(char)); - else if (AP_HOOK_SIG_HAS(sig, RC, int)) - modeval.v_int = va_arg(ap, va_type(int)); - else if (AP_HOOK_SIG_HAS(sig, RC, long)) - modeval.v_long = va_arg(ap, va_type(long)); - else if (AP_HOOK_SIG_HAS(sig, RC, float)) - modeval.v_float = va_arg(ap, va_type(float)); - else if (AP_HOOK_SIG_HAS(sig, RC, double)) - modeval.v_double = va_arg(ap, va_type(double)); - else if (AP_HOOK_SIG_HAS(sig, RC, ptr)) - modeval.v_ptr = va_arg(ap, va_type(ptr)); - } - - if ((he = ap_hook_create(hook)) == NULL) - return FALSE; - - if (he->he_sig == AP_HOOK_SIG_UNKNOWN) - he->he_sig = sig; - if (he->he_modeid == AP_HOOK_MODE_UNKNOWN) { - he->he_modeid = modeid; - he->he_modeval = modeval; - } - - for (i = 0; he->he_func[i] != NULL; i++) - if (ap_hook_call_func(ap, he, he->he_func[i])) - break; - - if (i > 0 && he->he_modeid == AP_HOOK_MODE_ALL) - rc = TRUE; - else if (i == AP_HOOK_MAX_FUNCS || he->he_func[i] == NULL) - rc = FALSE; - else - rc = TRUE; - - va_end(ap); - return rc; + int i; + ap_hook_value modeval; + ap_hook_entry *he; + va_list ap; + int rc; + + va_start(ap, modeid); + + if (modeid == AP_HOOK_MODE_DECLINE || modeid == AP_HOOK_MODE_DECLTMP) { + if (AP_HOOK_SIG_HAS(sig, RC, char)) + modeval.v_char = va_arg(ap, va_type(char)); + else if (AP_HOOK_SIG_HAS(sig, RC, int)) + modeval.v_int = va_arg(ap, va_type(int)); + else if (AP_HOOK_SIG_HAS(sig, RC, long)) + modeval.v_long = va_arg(ap, va_type(long)); + else if (AP_HOOK_SIG_HAS(sig, RC, float)) + modeval.v_float = va_arg(ap, va_type(float)); + else if (AP_HOOK_SIG_HAS(sig, RC, double)) + modeval.v_double = va_arg(ap, va_type(double)); + else if (AP_HOOK_SIG_HAS(sig, RC, ptr)) + modeval.v_ptr = va_arg(ap, va_type(ptr)); + } + + if ((he = ap_hook_create(hook)) == NULL) + return FALSE; + + if (he->he_sig == AP_HOOK_SIG_UNKNOWN) + he->he_sig = sig; + if (he->he_modeid == AP_HOOK_MODE_UNKNOWN) { + he->he_modeid = modeid; + he->he_modeval = modeval; + } + + for (i = 0; he->he_func[i] != NULL; i++) + if (ap_hook_call_func(ap, he, he->he_func[i])) + break; + + if (i > 0 && he->he_modeid == AP_HOOK_MODE_ALL) + rc = TRUE; + else if (i == AP_HOOK_MAX_FUNCS || he->he_func[i] == NULL) + rc = FALSE; + else + rc = TRUE; + + va_end(ap); + return rc; } /* @@ -351,457 +351,457 @@ API_EXPORT(int) ap_hook_use(char *hook, ap_hook_sig sig, ap_hook_mode modeid, .. */ API_EXPORT(int) ap_hook_call(char *hook, ...) { - int i; - ap_hook_entry *he; - va_list ap; - int rc; - - va_start(ap, hook); - - if ((he = ap_hook_find(hook)) == NULL) { - va_end(ap); - return FALSE; - } - if ( he->he_sig == AP_HOOK_SIG_UNKNOWN - || he->he_modeid == AP_HOOK_MODE_UNKNOWN) { - va_end(ap); - return FALSE; - } - - for (i = 0; he->he_func[i] != NULL; i++) - if (ap_hook_call_func(ap, he, he->he_func[i])) - break; - - if (i > 0 && he->he_modeid == AP_HOOK_MODE_ALL) - rc = TRUE; - else if (i == AP_HOOK_MAX_FUNCS || he->he_func[i] == NULL) - rc = FALSE; - else - rc = TRUE; - - va_end(ap); - return rc; + int i; + ap_hook_entry *he; + va_list ap; + int rc; + + va_start(ap, hook); + + if ((he = ap_hook_find(hook)) == NULL) { + va_end(ap); + return FALSE; + } + if ( he->he_sig == AP_HOOK_SIG_UNKNOWN + || he->he_modeid == AP_HOOK_MODE_UNKNOWN) { + va_end(ap); + return FALSE; + } + + for (i = 0; he->he_func[i] != NULL; i++) + if (ap_hook_call_func(ap, he, he->he_func[i])) + break; + + if (i > 0 && he->he_modeid == AP_HOOK_MODE_ALL) + rc = TRUE; + else if (i == AP_HOOK_MAX_FUNCS || he->he_func[i] == NULL) + rc = FALSE; + else + rc = TRUE; + + va_end(ap); + return rc; } static int ap_hook_call_func(va_list ap, ap_hook_entry *he, ap_hook_func *hf) { - void *v_rc; - ap_hook_value v_tmp; - int rc; - - /* - * Now we dispatch the various function calls. We support function - * signatures with up to 9 types (1 return type, 8 argument types) where - * each argument can have 7 different types (ctx, char, int, long, float, - * double, ptr), so theoretically there are 9^7 (=4782969) combinations - * possible. But because we don't need all of them, of course, we - * implement only the following well chosen subset (duplicates are ok): - * - * 1. `The basic hook'. - * - * void func() - * - * 2. The standard set of signatures which form all combinations of - * int&ptr based signatures for up to 3 arguments. We provide - * them per default for module authors. - * - * int func() - * ptr func() - * int func(int) - * int func(ptr) - * ptr func(int) - * ptr func(ptr) - * int func(int,int) - * int func(int,ptr) - * int func(ptr,int) - * int func(ptr,ptr) - * ptr func(int,int) - * ptr func(int,ptr) - * ptr func(ptr,int) - * ptr func(ptr,ptr) - * int func(int,int,int) - * int func(int,int,ptr) - * int func(int,ptr,int) - * int func(int,ptr,ptr) - * int func(ptr,int,int) - * int func(ptr,int,ptr) - * int func(ptr,ptr,int) - * int func(ptr,ptr,ptr) - * ptr func(int,int,int) - * ptr func(int,int,ptr) - * ptr func(int,ptr,int) - * ptr func(int,ptr,ptr) - * ptr func(ptr,int,int) - * ptr func(ptr,int,ptr) - * ptr func(ptr,ptr,int) - * ptr func(ptr,ptr,ptr) - * - * 3. Actually currently used hooks. - * - * int func(ptr) [2x] - * int func(ptr,ptr) [2x] - * int func(ptr,ptr,int) [5x] - * int func(ptr,ptr,ptr,int) [1x] - * int func(ptr,ptr,ptr,int,ptr) [1x] - * int func(ptr,ptr,ptr,ptr,int) [1x] - * int func(ptr,ptr,ptr,ptr,int,ptr) [1x] - * ptr func(ptr,ptr) [3x] - * ptr func(ptr,ptr,ptr,ptr,ptr) [1x] - * void func(ptr) [2x] - * void func(ptr,int,int) [1x] - * void func(ptr,ptr) [5x] - * void func(ptr,ptr,ptr) [3x] - * void func(ptr,ptr,ptr,ptr) [2x] - * - * To simplify the programming task we generate the actual dispatch code - * for these calls via the embedded Perl script at the end of this source - * file. This script parses the above lines and generates the section - * below. So, when you need more signature variants just add them to the - * above list and run - * - * $ perl ap_hook.c - * - * This automatically updates the above code. - */ - - rc = TRUE; - v_rc = NULL; - if (!AP_HOOK_SIG_HAS(he->he_sig, RC, void)) { - if (he->he_modeid == AP_HOOK_MODE_DECLTMP) { - /* the return variable is a temporary one */ - if (AP_HOOK_SIG_HAS(he->he_sig, RC, char)) - v_rc = &v_tmp.v_char; - else if (AP_HOOK_SIG_HAS(he->he_sig, RC, int)) - v_rc = &v_tmp.v_int; - else if (AP_HOOK_SIG_HAS(he->he_sig, RC, long)) - v_rc = &v_tmp.v_long; - else if (AP_HOOK_SIG_HAS(he->he_sig, RC, float)) - v_rc = &v_tmp.v_float; - else if (AP_HOOK_SIG_HAS(he->he_sig, RC, double)) - v_rc = &v_tmp.v_double; - else if (AP_HOOK_SIG_HAS(he->he_sig, RC, ptr)) - v_rc = &v_tmp.v_ptr; - } - else { - /* the return variable is provided by caller */ - v_rc = va_arg(ap, void *); - } - } - - /* ----BEGIN GENERATED SECTION-------- */ - if (he->he_sig == AP_HOOK_SIG1(void)) { - /* Call: void func() */ - ((void(*)())(hf->hf_ptr))(); - } - else if (he->he_sig == AP_HOOK_SIG1(int)) { - /* Call: int func() */ - *((int *)v_rc) = ((int(*)())(hf->hf_ptr))(); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG1(ptr)) { - /* Call: ptr func() */ - *((void * *)v_rc) = ((void *(*)())(hf->hf_ptr))(); - rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); - } - else if (he->he_sig == AP_HOOK_SIG2(int, int)) { - /* Call: int func(int) */ - int v1 = va_arg(ap, va_type(int)); - *((int *)v_rc) = ((int(*)(int))(hf->hf_ptr))(v1); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG2(int, ptr)) { - /* Call: int func(ptr) */ - void *v1 = va_arg(ap, va_type(ptr)); - *((int *)v_rc) = ((int(*)(void *))(hf->hf_ptr))(v1); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG2(ptr, int)) { - /* Call: ptr func(int) */ - int v1 = va_arg(ap, va_type(int)); - *((void * *)v_rc) = ((void *(*)(int))(hf->hf_ptr))(v1); - rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); - } - else if (he->he_sig == AP_HOOK_SIG2(ptr, ptr)) { - /* Call: ptr func(ptr) */ - void *v1 = va_arg(ap, va_type(ptr)); - *((void * *)v_rc) = ((void *(*)(void *))(hf->hf_ptr))(v1); - rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); - } - else if (he->he_sig == AP_HOOK_SIG3(int, int, int)) { - /* Call: int func(int,int) */ - int v1 = va_arg(ap, va_type(int)); - int v2 = va_arg(ap, va_type(int)); - *((int *)v_rc) = ((int(*)(int, int))(hf->hf_ptr))(v1, v2); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG3(int, int, ptr)) { - /* Call: int func(int,ptr) */ - int v1 = va_arg(ap, va_type(int)); - void *v2 = va_arg(ap, va_type(ptr)); - *((int *)v_rc) = ((int(*)(int, void *))(hf->hf_ptr))(v1, v2); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG3(int, ptr, int)) { - /* Call: int func(ptr,int) */ - void *v1 = va_arg(ap, va_type(ptr)); - int v2 = va_arg(ap, va_type(int)); - *((int *)v_rc) = ((int(*)(void *, int))(hf->hf_ptr))(v1, v2); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG3(int, ptr, ptr)) { - /* Call: int func(ptr,ptr) */ - void *v1 = va_arg(ap, va_type(ptr)); - void *v2 = va_arg(ap, va_type(ptr)); - *((int *)v_rc) = ((int(*)(void *, void *))(hf->hf_ptr))(v1, v2); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG3(ptr, int, int)) { - /* Call: ptr func(int,int) */ - int v1 = va_arg(ap, va_type(int)); - int v2 = va_arg(ap, va_type(int)); - *((void * *)v_rc) = ((void *(*)(int, int))(hf->hf_ptr))(v1, v2); - rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); - } - else if (he->he_sig == AP_HOOK_SIG3(ptr, int, ptr)) { - /* Call: ptr func(int,ptr) */ - int v1 = va_arg(ap, va_type(int)); - void *v2 = va_arg(ap, va_type(ptr)); - *((void * *)v_rc) = ((void *(*)(int, void *))(hf->hf_ptr))(v1, v2); - rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); - } - else if (he->he_sig == AP_HOOK_SIG3(ptr, ptr, int)) { - /* Call: ptr func(ptr,int) */ - void *v1 = va_arg(ap, va_type(ptr)); - int v2 = va_arg(ap, va_type(int)); - *((void * *)v_rc) = ((void *(*)(void *, int))(hf->hf_ptr))(v1, v2); - rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); - } - else if (he->he_sig == AP_HOOK_SIG3(ptr, ptr, ptr)) { - /* Call: ptr func(ptr,ptr) */ - void *v1 = va_arg(ap, va_type(ptr)); - void *v2 = va_arg(ap, va_type(ptr)); - *((void * *)v_rc) = ((void *(*)(void *, void *))(hf->hf_ptr))(v1, v2); - rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); - } - else if (he->he_sig == AP_HOOK_SIG4(int, int, int, int)) { - /* Call: int func(int,int,int) */ - int v1 = va_arg(ap, va_type(int)); - int v2 = va_arg(ap, va_type(int)); - int v3 = va_arg(ap, va_type(int)); - *((int *)v_rc) = ((int(*)(int, int, int))(hf->hf_ptr))(v1, v2, v3); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG4(int, int, int, ptr)) { - /* Call: int func(int,int,ptr) */ - int v1 = va_arg(ap, va_type(int)); - int v2 = va_arg(ap, va_type(int)); - void *v3 = va_arg(ap, va_type(ptr)); - *((int *)v_rc) = ((int(*)(int, int, void *))(hf->hf_ptr))(v1, v2, v3); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG4(int, int, ptr, int)) { - /* Call: int func(int,ptr,int) */ - int v1 = va_arg(ap, va_type(int)); - void *v2 = va_arg(ap, va_type(ptr)); - int v3 = va_arg(ap, va_type(int)); - *((int *)v_rc) = ((int(*)(int, void *, int))(hf->hf_ptr))(v1, v2, v3); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG4(int, int, ptr, ptr)) { - /* Call: int func(int,ptr,ptr) */ - int v1 = va_arg(ap, va_type(int)); - void *v2 = va_arg(ap, va_type(ptr)); - void *v3 = va_arg(ap, va_type(ptr)); - *((int *)v_rc) = ((int(*)(int, void *, void *))(hf->hf_ptr))(v1, v2, v3); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG4(int, ptr, int, int)) { - /* Call: int func(ptr,int,int) */ - void *v1 = va_arg(ap, va_type(ptr)); - int v2 = va_arg(ap, va_type(int)); - int v3 = va_arg(ap, va_type(int)); - *((int *)v_rc) = ((int(*)(void *, int, int))(hf->hf_ptr))(v1, v2, v3); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG4(int, ptr, int, ptr)) { - /* Call: int func(ptr,int,ptr) */ - void *v1 = va_arg(ap, va_type(ptr)); - int v2 = va_arg(ap, va_type(int)); - void *v3 = va_arg(ap, va_type(ptr)); - *((int *)v_rc) = ((int(*)(void *, int, void *))(hf->hf_ptr))(v1, v2, v3); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG4(int, ptr, ptr, int)) { - /* Call: int func(ptr,ptr,int) */ - void *v1 = va_arg(ap, va_type(ptr)); - void *v2 = va_arg(ap, va_type(ptr)); - int v3 = va_arg(ap, va_type(int)); - *((int *)v_rc) = ((int(*)(void *, void *, int))(hf->hf_ptr))(v1, v2, v3); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG4(int, ptr, ptr, ptr)) { - /* Call: int func(ptr,ptr,ptr) */ - void *v1 = va_arg(ap, va_type(ptr)); - void *v2 = va_arg(ap, va_type(ptr)); - void *v3 = va_arg(ap, va_type(ptr)); - *((int *)v_rc) = ((int(*)(void *, void *, void *))(hf->hf_ptr))(v1, v2, v3); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG4(ptr, int, int, int)) { - /* Call: ptr func(int,int,int) */ - int v1 = va_arg(ap, va_type(int)); - int v2 = va_arg(ap, va_type(int)); - int v3 = va_arg(ap, va_type(int)); - *((void * *)v_rc) = ((void *(*)(int, int, int))(hf->hf_ptr))(v1, v2, v3); - rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); - } - else if (he->he_sig == AP_HOOK_SIG4(ptr, int, int, ptr)) { - /* Call: ptr func(int,int,ptr) */ - int v1 = va_arg(ap, va_type(int)); - int v2 = va_arg(ap, va_type(int)); - void *v3 = va_arg(ap, va_type(ptr)); - *((void * *)v_rc) = ((void *(*)(int, int, void *))(hf->hf_ptr))(v1, v2, v3); - rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); - } - else if (he->he_sig == AP_HOOK_SIG4(ptr, int, ptr, int)) { - /* Call: ptr func(int,ptr,int) */ - int v1 = va_arg(ap, va_type(int)); - void *v2 = va_arg(ap, va_type(ptr)); - int v3 = va_arg(ap, va_type(int)); - *((void * *)v_rc) = ((void *(*)(int, void *, int))(hf->hf_ptr))(v1, v2, v3); - rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); - } - else if (he->he_sig == AP_HOOK_SIG4(ptr, int, ptr, ptr)) { - /* Call: ptr func(int,ptr,ptr) */ - int v1 = va_arg(ap, va_type(int)); - void *v2 = va_arg(ap, va_type(ptr)); - void *v3 = va_arg(ap, va_type(ptr)); - *((void * *)v_rc) = ((void *(*)(int, void *, void *))(hf->hf_ptr))(v1, v2, v3); - rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); - } - else if (he->he_sig == AP_HOOK_SIG4(ptr, ptr, int, int)) { - /* Call: ptr func(ptr,int,int) */ - void *v1 = va_arg(ap, va_type(ptr)); - int v2 = va_arg(ap, va_type(int)); - int v3 = va_arg(ap, va_type(int)); - *((void * *)v_rc) = ((void *(*)(void *, int, int))(hf->hf_ptr))(v1, v2, v3); - rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); - } - else if (he->he_sig == AP_HOOK_SIG4(ptr, ptr, int, ptr)) { - /* Call: ptr func(ptr,int,ptr) */ - void *v1 = va_arg(ap, va_type(ptr)); - int v2 = va_arg(ap, va_type(int)); - void *v3 = va_arg(ap, va_type(ptr)); - *((void * *)v_rc) = ((void *(*)(void *, int, void *))(hf->hf_ptr))(v1, v2, v3); - rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); - } - else if (he->he_sig == AP_HOOK_SIG4(ptr, ptr, ptr, int)) { - /* Call: ptr func(ptr,ptr,int) */ - void *v1 = va_arg(ap, va_type(ptr)); - void *v2 = va_arg(ap, va_type(ptr)); - int v3 = va_arg(ap, va_type(int)); - *((void * *)v_rc) = ((void *(*)(void *, void *, int))(hf->hf_ptr))(v1, v2, v3); - rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); - } - else if (he->he_sig == AP_HOOK_SIG4(ptr, ptr, ptr, ptr)) { - /* Call: ptr func(ptr,ptr,ptr) */ - void *v1 = va_arg(ap, va_type(ptr)); - void *v2 = va_arg(ap, va_type(ptr)); - void *v3 = va_arg(ap, va_type(ptr)); - *((void * *)v_rc) = ((void *(*)(void *, void *, void *))(hf->hf_ptr))(v1, v2, v3); - rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); - } - else if (he->he_sig == AP_HOOK_SIG5(int, ptr, ptr, ptr, int)) { - /* Call: int func(ptr,ptr,ptr,int) */ - void *v1 = va_arg(ap, va_type(ptr)); - void *v2 = va_arg(ap, va_type(ptr)); - void *v3 = va_arg(ap, va_type(ptr)); - int v4 = va_arg(ap, va_type(int)); - *((int *)v_rc) = ((int(*)(void *, void *, void *, int))(hf->hf_ptr))(v1, v2, v3, v4); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG6(int, ptr, ptr, ptr, int, ptr)) { - /* Call: int func(ptr,ptr,ptr,int,ptr) */ - void *v1 = va_arg(ap, va_type(ptr)); - void *v2 = va_arg(ap, va_type(ptr)); - void *v3 = va_arg(ap, va_type(ptr)); - int v4 = va_arg(ap, va_type(int)); - void *v5 = va_arg(ap, va_type(ptr)); - *((int *)v_rc) = ((int(*)(void *, void *, void *, int, void *))(hf->hf_ptr))(v1, v2, v3, v4, v5); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG6(int, ptr, ptr, ptr, ptr, int)) { - /* Call: int func(ptr,ptr,ptr,ptr,int) */ - void *v1 = va_arg(ap, va_type(ptr)); - void *v2 = va_arg(ap, va_type(ptr)); - void *v3 = va_arg(ap, va_type(ptr)); - void *v4 = va_arg(ap, va_type(ptr)); - int v5 = va_arg(ap, va_type(int)); - *((int *)v_rc) = ((int(*)(void *, void *, void *, void *, int))(hf->hf_ptr))(v1, v2, v3, v4, v5); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG7(int, ptr, ptr, ptr, ptr, int, ptr)) { - /* Call: int func(ptr,ptr,ptr,ptr,int,ptr) */ - void *v1 = va_arg(ap, va_type(ptr)); - void *v2 = va_arg(ap, va_type(ptr)); - void *v3 = va_arg(ap, va_type(ptr)); - void *v4 = va_arg(ap, va_type(ptr)); - int v5 = va_arg(ap, va_type(int)); - void *v6 = va_arg(ap, va_type(ptr)); - *((int *)v_rc) = ((int(*)(void *, void *, void *, void *, int, void *))(hf->hf_ptr))(v1, v2, v3, v4, v5, v6); - rc = (*((int *)v_rc) != he->he_modeval.v_int); - } - else if (he->he_sig == AP_HOOK_SIG6(ptr, ptr, ptr, ptr, ptr, ptr)) { - /* Call: ptr func(ptr,ptr,ptr,ptr,ptr) */ - void *v1 = va_arg(ap, va_type(ptr)); - void *v2 = va_arg(ap, va_type(ptr)); - void *v3 = va_arg(ap, va_type(ptr)); - void *v4 = va_arg(ap, va_type(ptr)); - void *v5 = va_arg(ap, va_type(ptr)); - *((void * *)v_rc) = ((void *(*)(void *, void *, void *, void *, void *))(hf->hf_ptr))(v1, v2, v3, v4, v5); - rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); - } - else if (he->he_sig == AP_HOOK_SIG2(void, ptr)) { - /* Call: void func(ptr) */ - void *v1 = va_arg(ap, va_type(ptr)); - ((void(*)(void *))(hf->hf_ptr))(v1); - } - else if (he->he_sig == AP_HOOK_SIG4(void, ptr, int, int)) { - /* Call: void func(ptr,int,int) */ - void *v1 = va_arg(ap, va_type(ptr)); - int v2 = va_arg(ap, va_type(int)); - int v3 = va_arg(ap, va_type(int)); - ((void(*)(void *, int, int))(hf->hf_ptr))(v1, v2, v3); - } - else if (he->he_sig == AP_HOOK_SIG3(void, ptr, ptr)) { - /* Call: void func(ptr,ptr) */ - void *v1 = va_arg(ap, va_type(ptr)); - void *v2 = va_arg(ap, va_type(ptr)); - ((void(*)(void *, void *))(hf->hf_ptr))(v1, v2); - } - else if (he->he_sig == AP_HOOK_SIG4(void, ptr, ptr, ptr)) { - /* Call: void func(ptr,ptr,ptr) */ - void *v1 = va_arg(ap, va_type(ptr)); - void *v2 = va_arg(ap, va_type(ptr)); - void *v3 = va_arg(ap, va_type(ptr)); - ((void(*)(void *, void *, void *))(hf->hf_ptr))(v1, v2, v3); - } - else if (he->he_sig == AP_HOOK_SIG5(void, ptr, ptr, ptr, ptr)) { - /* Call: void func(ptr,ptr,ptr,ptr) */ - void *v1 = va_arg(ap, va_type(ptr)); - void *v2 = va_arg(ap, va_type(ptr)); - void *v3 = va_arg(ap, va_type(ptr)); - void *v4 = va_arg(ap, va_type(ptr)); - ((void(*)(void *, void *, void *, void *))(hf->hf_ptr))(v1, v2, v3, v4); - } - /* ----END GENERATED SECTION---------- */ - else - ap_log_assert("hook signature not implemented", __FILE__, __LINE__); - - if (he->he_modeid == AP_HOOK_MODE_ALL) - rc = FALSE; - else if (he->he_modeid == AP_HOOK_MODE_TOPMOST) - rc = TRUE; - - return rc; + void *v_rc; + ap_hook_value v_tmp; + int rc; + + /* + * Now we dispatch the various function calls. We support function + * signatures with up to 9 types (1 return type, 8 argument types) where + * each argument can have 7 different types (ctx, char, int, long, float, + * double, ptr), so theoretically there are 9^7 (=4782969) combinations + * possible. But because we don't need all of them, of course, we + * implement only the following well chosen subset (duplicates are ok): + * + * 1. `The basic hook'. + * + * void func() + * + * 2. The standard set of signatures which form all combinations of + * int&ptr based signatures for up to 3 arguments. We provide + * them per default for module authors. + * + * int func() + * ptr func() + * int func(int) + * int func(ptr) + * ptr func(int) + * ptr func(ptr) + * int func(int,int) + * int func(int,ptr) + * int func(ptr,int) + * int func(ptr,ptr) + * ptr func(int,int) + * ptr func(int,ptr) + * ptr func(ptr,int) + * ptr func(ptr,ptr) + * int func(int,int,int) + * int func(int,int,ptr) + * int func(int,ptr,int) + * int func(int,ptr,ptr) + * int func(ptr,int,int) + * int func(ptr,int,ptr) + * int func(ptr,ptr,int) + * int func(ptr,ptr,ptr) + * ptr func(int,int,int) + * ptr func(int,int,ptr) + * ptr func(int,ptr,int) + * ptr func(int,ptr,ptr) + * ptr func(ptr,int,int) + * ptr func(ptr,int,ptr) + * ptr func(ptr,ptr,int) + * ptr func(ptr,ptr,ptr) + * + * 3. Actually currently used hooks. + * + * int func(ptr) [2x] + * int func(ptr,ptr) [2x] + * int func(ptr,ptr,int) [5x] + * int func(ptr,ptr,ptr,int) [1x] + * int func(ptr,ptr,ptr,int,ptr) [1x] + * int func(ptr,ptr,ptr,ptr,int) [1x] + * int func(ptr,ptr,ptr,ptr,int,ptr) [1x] + * ptr func(ptr,ptr) [3x] + * ptr func(ptr,ptr,ptr,ptr,ptr) [1x] + * void func(ptr) [2x] + * void func(ptr,int,int) [1x] + * void func(ptr,ptr) [5x] + * void func(ptr,ptr,ptr) [3x] + * void func(ptr,ptr,ptr,ptr) [2x] + * + * To simplify the programming task we generate the actual dispatch code + * for these calls via the embedded Perl script at the end of this source + * file. This script parses the above lines and generates the section + * below. So, when you need more signature variants just add them to the + * above list and run + * + * $ perl ap_hook.c + * + * This automatically updates the above code. + */ + + rc = TRUE; + v_rc = NULL; + if (!AP_HOOK_SIG_HAS(he->he_sig, RC, void)) { + if (he->he_modeid == AP_HOOK_MODE_DECLTMP) { + /* the return variable is a temporary one */ + if (AP_HOOK_SIG_HAS(he->he_sig, RC, char)) + v_rc = &v_tmp.v_char; + else if (AP_HOOK_SIG_HAS(he->he_sig, RC, int)) + v_rc = &v_tmp.v_int; + else if (AP_HOOK_SIG_HAS(he->he_sig, RC, long)) + v_rc = &v_tmp.v_long; + else if (AP_HOOK_SIG_HAS(he->he_sig, RC, float)) + v_rc = &v_tmp.v_float; + else if (AP_HOOK_SIG_HAS(he->he_sig, RC, double)) + v_rc = &v_tmp.v_double; + else if (AP_HOOK_SIG_HAS(he->he_sig, RC, ptr)) + v_rc = &v_tmp.v_ptr; + } + else { + /* the return variable is provided by caller */ + v_rc = va_arg(ap, void *); + } + } + + /* ----BEGIN GENERATED SECTION-------- */ + if (he->he_sig == AP_HOOK_SIG1(void)) { + /* Call: void func() */ + ((void(*)())(hf->hf_ptr))(); + } + else if (he->he_sig == AP_HOOK_SIG1(int)) { + /* Call: int func() */ + *((int *)v_rc) = ((int(*)())(hf->hf_ptr))(); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG1(ptr)) { + /* Call: ptr func() */ + *((void * *)v_rc) = ((void *(*)())(hf->hf_ptr))(); + rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); + } + else if (he->he_sig == AP_HOOK_SIG2(int, int)) { + /* Call: int func(int) */ + int v1 = va_arg(ap, va_type(int)); + *((int *)v_rc) = ((int(*)(int))(hf->hf_ptr))(v1); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG2(int, ptr)) { + /* Call: int func(ptr) */ + void *v1 = va_arg(ap, va_type(ptr)); + *((int *)v_rc) = ((int(*)(void *))(hf->hf_ptr))(v1); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG2(ptr, int)) { + /* Call: ptr func(int) */ + int v1 = va_arg(ap, va_type(int)); + *((void * *)v_rc) = ((void *(*)(int))(hf->hf_ptr))(v1); + rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); + } + else if (he->he_sig == AP_HOOK_SIG2(ptr, ptr)) { + /* Call: ptr func(ptr) */ + void *v1 = va_arg(ap, va_type(ptr)); + *((void * *)v_rc) = ((void *(*)(void *))(hf->hf_ptr))(v1); + rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); + } + else if (he->he_sig == AP_HOOK_SIG3(int, int, int)) { + /* Call: int func(int,int) */ + int v1 = va_arg(ap, va_type(int)); + int v2 = va_arg(ap, va_type(int)); + *((int *)v_rc) = ((int(*)(int, int))(hf->hf_ptr))(v1, v2); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG3(int, int, ptr)) { + /* Call: int func(int,ptr) */ + int v1 = va_arg(ap, va_type(int)); + void *v2 = va_arg(ap, va_type(ptr)); + *((int *)v_rc) = ((int(*)(int, void *))(hf->hf_ptr))(v1, v2); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG3(int, ptr, int)) { + /* Call: int func(ptr,int) */ + void *v1 = va_arg(ap, va_type(ptr)); + int v2 = va_arg(ap, va_type(int)); + *((int *)v_rc) = ((int(*)(void *, int))(hf->hf_ptr))(v1, v2); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG3(int, ptr, ptr)) { + /* Call: int func(ptr,ptr) */ + void *v1 = va_arg(ap, va_type(ptr)); + void *v2 = va_arg(ap, va_type(ptr)); + *((int *)v_rc) = ((int(*)(void *, void *))(hf->hf_ptr))(v1, v2); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG3(ptr, int, int)) { + /* Call: ptr func(int,int) */ + int v1 = va_arg(ap, va_type(int)); + int v2 = va_arg(ap, va_type(int)); + *((void * *)v_rc) = ((void *(*)(int, int))(hf->hf_ptr))(v1, v2); + rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); + } + else if (he->he_sig == AP_HOOK_SIG3(ptr, int, ptr)) { + /* Call: ptr func(int,ptr) */ + int v1 = va_arg(ap, va_type(int)); + void *v2 = va_arg(ap, va_type(ptr)); + *((void * *)v_rc) = ((void *(*)(int, void *))(hf->hf_ptr))(v1, v2); + rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); + } + else if (he->he_sig == AP_HOOK_SIG3(ptr, ptr, int)) { + /* Call: ptr func(ptr,int) */ + void *v1 = va_arg(ap, va_type(ptr)); + int v2 = va_arg(ap, va_type(int)); + *((void * *)v_rc) = ((void *(*)(void *, int))(hf->hf_ptr))(v1, v2); + rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); + } + else if (he->he_sig == AP_HOOK_SIG3(ptr, ptr, ptr)) { + /* Call: ptr func(ptr,ptr) */ + void *v1 = va_arg(ap, va_type(ptr)); + void *v2 = va_arg(ap, va_type(ptr)); + *((void * *)v_rc) = ((void *(*)(void *, void *))(hf->hf_ptr))(v1, v2); + rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); + } + else if (he->he_sig == AP_HOOK_SIG4(int, int, int, int)) { + /* Call: int func(int,int,int) */ + int v1 = va_arg(ap, va_type(int)); + int v2 = va_arg(ap, va_type(int)); + int v3 = va_arg(ap, va_type(int)); + *((int *)v_rc) = ((int(*)(int, int, int))(hf->hf_ptr))(v1, v2, v3); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG4(int, int, int, ptr)) { + /* Call: int func(int,int,ptr) */ + int v1 = va_arg(ap, va_type(int)); + int v2 = va_arg(ap, va_type(int)); + void *v3 = va_arg(ap, va_type(ptr)); + *((int *)v_rc) = ((int(*)(int, int, void *))(hf->hf_ptr))(v1, v2, v3); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG4(int, int, ptr, int)) { + /* Call: int func(int,ptr,int) */ + int v1 = va_arg(ap, va_type(int)); + void *v2 = va_arg(ap, va_type(ptr)); + int v3 = va_arg(ap, va_type(int)); + *((int *)v_rc) = ((int(*)(int, void *, int))(hf->hf_ptr))(v1, v2, v3); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG4(int, int, ptr, ptr)) { + /* Call: int func(int,ptr,ptr) */ + int v1 = va_arg(ap, va_type(int)); + void *v2 = va_arg(ap, va_type(ptr)); + void *v3 = va_arg(ap, va_type(ptr)); + *((int *)v_rc) = ((int(*)(int, void *, void *))(hf->hf_ptr))(v1, v2, v3); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG4(int, ptr, int, int)) { + /* Call: int func(ptr,int,int) */ + void *v1 = va_arg(ap, va_type(ptr)); + int v2 = va_arg(ap, va_type(int)); + int v3 = va_arg(ap, va_type(int)); + *((int *)v_rc) = ((int(*)(void *, int, int))(hf->hf_ptr))(v1, v2, v3); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG4(int, ptr, int, ptr)) { + /* Call: int func(ptr,int,ptr) */ + void *v1 = va_arg(ap, va_type(ptr)); + int v2 = va_arg(ap, va_type(int)); + void *v3 = va_arg(ap, va_type(ptr)); + *((int *)v_rc) = ((int(*)(void *, int, void *))(hf->hf_ptr))(v1, v2, v3); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG4(int, ptr, ptr, int)) { + /* Call: int func(ptr,ptr,int) */ + void *v1 = va_arg(ap, va_type(ptr)); + void *v2 = va_arg(ap, va_type(ptr)); + int v3 = va_arg(ap, va_type(int)); + *((int *)v_rc) = ((int(*)(void *, void *, int))(hf->hf_ptr))(v1, v2, v3); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG4(int, ptr, ptr, ptr)) { + /* Call: int func(ptr,ptr,ptr) */ + void *v1 = va_arg(ap, va_type(ptr)); + void *v2 = va_arg(ap, va_type(ptr)); + void *v3 = va_arg(ap, va_type(ptr)); + *((int *)v_rc) = ((int(*)(void *, void *, void *))(hf->hf_ptr))(v1, v2, v3); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG4(ptr, int, int, int)) { + /* Call: ptr func(int,int,int) */ + int v1 = va_arg(ap, va_type(int)); + int v2 = va_arg(ap, va_type(int)); + int v3 = va_arg(ap, va_type(int)); + *((void * *)v_rc) = ((void *(*)(int, int, int))(hf->hf_ptr))(v1, v2, v3); + rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); + } + else if (he->he_sig == AP_HOOK_SIG4(ptr, int, int, ptr)) { + /* Call: ptr func(int,int,ptr) */ + int v1 = va_arg(ap, va_type(int)); + int v2 = va_arg(ap, va_type(int)); + void *v3 = va_arg(ap, va_type(ptr)); + *((void * *)v_rc) = ((void *(*)(int, int, void *))(hf->hf_ptr))(v1, v2, v3); + rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); + } + else if (he->he_sig == AP_HOOK_SIG4(ptr, int, ptr, int)) { + /* Call: ptr func(int,ptr,int) */ + int v1 = va_arg(ap, va_type(int)); + void *v2 = va_arg(ap, va_type(ptr)); + int v3 = va_arg(ap, va_type(int)); + *((void * *)v_rc) = ((void *(*)(int, void *, int))(hf->hf_ptr))(v1, v2, v3); + rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); + } + else if (he->he_sig == AP_HOOK_SIG4(ptr, int, ptr, ptr)) { + /* Call: ptr func(int,ptr,ptr) */ + int v1 = va_arg(ap, va_type(int)); + void *v2 = va_arg(ap, va_type(ptr)); + void *v3 = va_arg(ap, va_type(ptr)); + *((void * *)v_rc) = ((void *(*)(int, void *, void *))(hf->hf_ptr))(v1, v2, v3); + rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); + } + else if (he->he_sig == AP_HOOK_SIG4(ptr, ptr, int, int)) { + /* Call: ptr func(ptr,int,int) */ + void *v1 = va_arg(ap, va_type(ptr)); + int v2 = va_arg(ap, va_type(int)); + int v3 = va_arg(ap, va_type(int)); + *((void * *)v_rc) = ((void *(*)(void *, int, int))(hf->hf_ptr))(v1, v2, v3); + rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); + } + else if (he->he_sig == AP_HOOK_SIG4(ptr, ptr, int, ptr)) { + /* Call: ptr func(ptr,int,ptr) */ + void *v1 = va_arg(ap, va_type(ptr)); + int v2 = va_arg(ap, va_type(int)); + void *v3 = va_arg(ap, va_type(ptr)); + *((void * *)v_rc) = ((void *(*)(void *, int, void *))(hf->hf_ptr))(v1, v2, v3); + rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); + } + else if (he->he_sig == AP_HOOK_SIG4(ptr, ptr, ptr, int)) { + /* Call: ptr func(ptr,ptr,int) */ + void *v1 = va_arg(ap, va_type(ptr)); + void *v2 = va_arg(ap, va_type(ptr)); + int v3 = va_arg(ap, va_type(int)); + *((void * *)v_rc) = ((void *(*)(void *, void *, int))(hf->hf_ptr))(v1, v2, v3); + rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); + } + else if (he->he_sig == AP_HOOK_SIG4(ptr, ptr, ptr, ptr)) { + /* Call: ptr func(ptr,ptr,ptr) */ + void *v1 = va_arg(ap, va_type(ptr)); + void *v2 = va_arg(ap, va_type(ptr)); + void *v3 = va_arg(ap, va_type(ptr)); + *((void * *)v_rc) = ((void *(*)(void *, void *, void *))(hf->hf_ptr))(v1, v2, v3); + rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); + } + else if (he->he_sig == AP_HOOK_SIG5(int, ptr, ptr, ptr, int)) { + /* Call: int func(ptr,ptr,ptr,int) */ + void *v1 = va_arg(ap, va_type(ptr)); + void *v2 = va_arg(ap, va_type(ptr)); + void *v3 = va_arg(ap, va_type(ptr)); + int v4 = va_arg(ap, va_type(int)); + *((int *)v_rc) = ((int(*)(void *, void *, void *, int))(hf->hf_ptr))(v1, v2, v3, v4); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG6(int, ptr, ptr, ptr, int, ptr)) { + /* Call: int func(ptr,ptr,ptr,int,ptr) */ + void *v1 = va_arg(ap, va_type(ptr)); + void *v2 = va_arg(ap, va_type(ptr)); + void *v3 = va_arg(ap, va_type(ptr)); + int v4 = va_arg(ap, va_type(int)); + void *v5 = va_arg(ap, va_type(ptr)); + *((int *)v_rc) = ((int(*)(void *, void *, void *, int, void *))(hf->hf_ptr))(v1, v2, v3, v4, v5); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG6(int, ptr, ptr, ptr, ptr, int)) { + /* Call: int func(ptr,ptr,ptr,ptr,int) */ + void *v1 = va_arg(ap, va_type(ptr)); + void *v2 = va_arg(ap, va_type(ptr)); + void *v3 = va_arg(ap, va_type(ptr)); + void *v4 = va_arg(ap, va_type(ptr)); + int v5 = va_arg(ap, va_type(int)); + *((int *)v_rc) = ((int(*)(void *, void *, void *, void *, int))(hf->hf_ptr))(v1, v2, v3, v4, v5); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG7(int, ptr, ptr, ptr, ptr, int, ptr)) { + /* Call: int func(ptr,ptr,ptr,ptr,int,ptr) */ + void *v1 = va_arg(ap, va_type(ptr)); + void *v2 = va_arg(ap, va_type(ptr)); + void *v3 = va_arg(ap, va_type(ptr)); + void *v4 = va_arg(ap, va_type(ptr)); + int v5 = va_arg(ap, va_type(int)); + void *v6 = va_arg(ap, va_type(ptr)); + *((int *)v_rc) = ((int(*)(void *, void *, void *, void *, int, void *))(hf->hf_ptr))(v1, v2, v3, v4, v5, v6); + rc = (*((int *)v_rc) != he->he_modeval.v_int); + } + else if (he->he_sig == AP_HOOK_SIG6(ptr, ptr, ptr, ptr, ptr, ptr)) { + /* Call: ptr func(ptr,ptr,ptr,ptr,ptr) */ + void *v1 = va_arg(ap, va_type(ptr)); + void *v2 = va_arg(ap, va_type(ptr)); + void *v3 = va_arg(ap, va_type(ptr)); + void *v4 = va_arg(ap, va_type(ptr)); + void *v5 = va_arg(ap, va_type(ptr)); + *((void * *)v_rc) = ((void *(*)(void *, void *, void *, void *, void *))(hf->hf_ptr))(v1, v2, v3, v4, v5); + rc = (*((void * *)v_rc) != he->he_modeval.v_ptr); + } + else if (he->he_sig == AP_HOOK_SIG2(void, ptr)) { + /* Call: void func(ptr) */ + void *v1 = va_arg(ap, va_type(ptr)); + ((void(*)(void *))(hf->hf_ptr))(v1); + } + else if (he->he_sig == AP_HOOK_SIG4(void, ptr, int, int)) { + /* Call: void func(ptr,int,int) */ + void *v1 = va_arg(ap, va_type(ptr)); + int v2 = va_arg(ap, va_type(int)); + int v3 = va_arg(ap, va_type(int)); + ((void(*)(void *, int, int))(hf->hf_ptr))(v1, v2, v3); + } + else if (he->he_sig == AP_HOOK_SIG3(void, ptr, ptr)) { + /* Call: void func(ptr,ptr) */ + void *v1 = va_arg(ap, va_type(ptr)); + void *v2 = va_arg(ap, va_type(ptr)); + ((void(*)(void *, void *))(hf->hf_ptr))(v1, v2); + } + else if (he->he_sig == AP_HOOK_SIG4(void, ptr, ptr, ptr)) { + /* Call: void func(ptr,ptr,ptr) */ + void *v1 = va_arg(ap, va_type(ptr)); + void *v2 = va_arg(ap, va_type(ptr)); + void *v3 = va_arg(ap, va_type(ptr)); + ((void(*)(void *, void *, void *))(hf->hf_ptr))(v1, v2, v3); + } + else if (he->he_sig == AP_HOOK_SIG5(void, ptr, ptr, ptr, ptr)) { + /* Call: void func(ptr,ptr,ptr,ptr) */ + void *v1 = va_arg(ap, va_type(ptr)); + void *v2 = va_arg(ap, va_type(ptr)); + void *v3 = va_arg(ap, va_type(ptr)); + void *v4 = va_arg(ap, va_type(ptr)); + ((void(*)(void *, void *, void *, void *))(hf->hf_ptr))(v1, v2, v3, v4); + } + /* ----END GENERATED SECTION---------- */ + else + ap_log_assert("hook signature not implemented", __FILE__, __LINE__); + + if (he->he_modeid == AP_HOOK_MODE_ALL) + rc = FALSE; + else if (he->he_modeid == AP_HOOK_MODE_TOPMOST) + rc = TRUE; + + return rc; } diff --git a/usr.sbin/httpd/src/ap/ap_md5c.c b/usr.sbin/httpd/src/ap/ap_md5c.c index b441df53205..0716bffe1b5 100644 --- a/usr.sbin/httpd/src/ap/ap_md5c.c +++ b/usr.sbin/httpd/src/ap/ap_md5c.c @@ -1,35 +1,4 @@ -/* - * This is work is derived from material Copyright RSA Data Security, Inc. - * - * The RSA copyright statement and Licence for that original material is - * included below. This is followed by the Apache copyright statement and - * licence for the modifications made to that material. - */ - -/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm - */ - -/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All - rights reserved. - - License to copy and use this software is granted provided that it - is identified as the "RSA Data Security, Inc. MD5 Message-Digest - Algorithm" in all material mentioning or referencing this software - or this function. - - License is also granted to make and use derivative works provided - that such works are identified as "derived from the RSA Data - Security, Inc. MD5 Message-Digest Algorithm" in all material - mentioning or referencing the derived work. - - RSA Data Security, Inc. makes no representations concerning either - the merchantability of this software or the suitability of this - software for any particular purpose. It is provided "as is" - without express or implied warranty of any kind. - - These notices must be retained in any copies of any part of this - documentation and/or software. - */ +/* $OpenBSD: ap_md5c.c,v 1.10 2005/03/28 21:03:33 niallo Exp $ */ /* ==================================================================== * The Apache Software License, Version 1.1 @@ -106,54 +75,58 @@ #include "ap_md5.h" #include "ap.h" -static void Encode(unsigned char *output, const UINT4 *input, - unsigned int len); -static void Decode(UINT4 *output, const unsigned char *input, - unsigned int len); +static void Encode(unsigned char *output, const UINT4 *input, unsigned int len); +static void Decode(UINT4 *output, const unsigned char *input, unsigned int len); -API_EXPORT(void) ap_MD5Init(AP_MD5_CTX *context) +API_EXPORT(void) +ap_MD5Init(AP_MD5_CTX *context) { - MD5Init(context); + MD5Init(context); } -API_EXPORT(void) ap_MD5Update(AP_MD5_CTX *context, const unsigned char *input, - unsigned int inputLen) +API_EXPORT(void) +ap_MD5Update(AP_MD5_CTX *context, const unsigned char *input, + unsigned int inputLen) { - MD5Update(context, input, inputLen); + MD5Update(context, input, inputLen); } -API_EXPORT(void) ap_MD5Final(unsigned char digest[16], AP_MD5_CTX *context) +API_EXPORT(void) +ap_MD5Final(unsigned char digest[16], AP_MD5_CTX *context) { - MD5Final(digest, context); + MD5Final(digest, context); } /* Encodes input (UINT4) into output (unsigned char). Assumes len is a multiple of 4. */ -static void Encode(unsigned char *output, const UINT4 *input, unsigned int len) +static void +Encode(unsigned char *output, const UINT4 *input, unsigned int len) { - unsigned int i, j; - UINT4 k; - - for (i = 0, j = 0; j < len; i++, j += 4) { - k = input[i]; - output[j] = (unsigned char) (k & 0xff); - output[j + 1] = (unsigned char) ((k >> 8) & 0xff); - output[j + 2] = (unsigned char) ((k >> 16) & 0xff); - output[j + 3] = (unsigned char) ((k >> 24) & 0xff); - } + unsigned int i, j; + UINT4 k; + + for (i = 0, j = 0; j < len; i++, j += 4) { + k = input[i]; + output[j] = (unsigned char) (k & 0xff); + output[j + 1] = (unsigned char) ((k >> 8) & 0xff); + output[j + 2] = (unsigned char) ((k >> 16) & 0xff); + output[j + 3] = (unsigned char) ((k >> 24) & 0xff); + } } /* Decodes input (unsigned char) into output (UINT4). Assumes len is * a multiple of 4. */ -static void Decode(UINT4 *output, const unsigned char *input, unsigned int len) +static void +Decode(UINT4 *output, const unsigned char *input, unsigned int len) { - unsigned int i, j; + unsigned int i, j; - for (i = 0, j = 0; j < len; i++, j += 4) - output[i] = ((UINT4) input[j]) | (((UINT4) input[j + 1]) << 8) | - (((UINT4) input[j + 2]) << 16) | (((UINT4) input[j + 3]) << 24); + for (i = 0, j = 0; j < len; i++, j += 4) + output[i] = ((UINT4) input[j]) | (((UINT4) input[j + 1]) << 8) | + (((UINT4) input[j + 2]) << 16) + | (((UINT4) input[j + 3]) << 24); } /* @@ -161,168 +134,164 @@ static void Decode(UINT4 *output, const unsigned char *input, unsigned int len) * the FreeBSD 3.0 /usr/src/lib/libcrypt/crypt.c file, which is * licenced as stated at the top of this file. */ -API_EXPORT(void) ap_to64(char *s, unsigned long v, int n) +API_EXPORT(void) +ap_to64(char *s, unsigned long v, int n) { - static unsigned char itoa64[] = /* 0 ... 63 => ASCII - 64 */ - "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + static unsigned char itoa64[] = /* 0 ... 63 => ASCII - 64 */ + "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - while (--n >= 0) { - *s++ = itoa64[v&0x3f]; - v >>= 6; - } + while (--n >= 0) { + *s++ = itoa64[v&0x3f]; + v >>= 6; + } } -API_EXPORT(void) ap_MD5Encode(const unsigned char *pw, - const unsigned char *salt, - char *result, size_t nbytes) +API_EXPORT(void) +ap_MD5Encode(const unsigned char *pw, const unsigned char *salt, char *result, + size_t nbytes) { - /* - * Minimum size is 8 bytes for salt, plus 1 for the trailing NUL, - * plus 4 for the '$' separators, plus the password hash itself. - * Let's leave a goodly amount of leeway. - */ - - char passwd[120], *p; - const unsigned char *sp, *ep; - unsigned char final[16]; - int i; - unsigned int sl; - int pl; - unsigned int pwlen; - MD5_CTX ctx, ctx1; - unsigned long l; - - /* - * Refine the salt first. It's possible we were given an already-hashed - * string as the salt argument, so extract the actual salt value from it - * if so. Otherwise just use the string up to the first '$' as the salt. - */ - sp = salt; - - /* - * If it starts with the magic string, then skip that. - */ - if (strncmp((char *)sp, AP_MD5PW_ID, AP_MD5PW_IDLEN) == 0) { - sp += AP_MD5PW_IDLEN; - } - - /* - * It stops at the first '$' or 8 chars, whichever comes first - */ - for (ep = sp; (*ep != '\0') && (*ep != '$') && (ep < (sp + 8)); ep++) { - continue; - } - - /* - * Get the length of the true salt - */ - sl = ep - sp; - - /* - * 'Time to make the doughnuts..' - */ - MD5Init(&ctx); - - pwlen = strlen((char *)pw); - /* - * The password first, since that is what is most unknown - */ - MD5Update(&ctx, pw, pwlen); - - /* - * Then our magic string - */ - MD5Update(&ctx, (const unsigned char *) AP_MD5PW_ID, AP_MD5PW_IDLEN); - - /* - * Then the raw salt - */ - MD5Update(&ctx, sp, sl); - - /* - * Then just as many characters of the MD5(pw, salt, pw) - */ - MD5Init(&ctx1); - MD5Update(&ctx1, pw, pwlen); - MD5Update(&ctx1, sp, sl); - MD5Update(&ctx1, pw, pwlen); - MD5Final(final, &ctx1); - for(pl = pwlen; pl > 0; pl -= 16) { - MD5Update(&ctx, final, (pl > 16) ? 16 : (unsigned int) pl); - } - - /* - * Don't leave anything around in vm they could use. - */ - memset(final, 0, sizeof(final)); - - /* - * Then something really weird... - */ - for (i = pwlen; i != 0; i >>= 1) { - if (i & 1) { - MD5Update(&ctx, final, 1); - } - else { - MD5Update(&ctx, pw, 1); - } - } - - /* - * Now make the output string. We know our limitations, so we - * can use the string routines without bounds checking. - */ - ap_cpystrn(passwd, AP_MD5PW_ID, AP_MD5PW_IDLEN + 1); - ap_cpystrn(passwd + AP_MD5PW_IDLEN, (char *)sp, sl + 1); - passwd[AP_MD5PW_IDLEN + sl] = '$'; - passwd[AP_MD5PW_IDLEN + sl + 1] = '\0'; - - MD5Final(final, &ctx); - - /* - * And now, just to make sure things don't run too fast.. - * On a 60 Mhz Pentium this takes 34 msec, so you would - * need 30 seconds to build a 1000 entry dictionary... - */ - for (i = 0; i < 1000; i++) { + /* + * Minimum size is 8 bytes for salt, plus 1 for the trailing NUL, + * plus 4 for the '$' separators, plus the password hash itself. + * Let's leave a goodly amount of leeway. + */ + + char passwd[120], *p; + const unsigned char *sp, *ep; + unsigned char final[16]; + int i; + unsigned int sl; + int pl; + unsigned int pwlen; + MD5_CTX ctx, ctx1; + unsigned long l; + + /* + * Refine the salt first. It's possible we were given an already-hashed + * string as the salt argument, so extract the actual salt value from it + * if so. Otherwise just use the string up to the first '$' as the salt. + */ + sp = salt; + + /* + * If it starts with the magic string, then skip that. + */ + if (strncmp((char *)sp, AP_MD5PW_ID, AP_MD5PW_IDLEN) == 0) + sp += AP_MD5PW_IDLEN; + + /* + * It stops at the first '$' or 8 chars, whichever comes first + */ + for (ep = sp; (*ep != '\0') && (*ep != '$') && (ep < (sp + 8)); ep++) + continue; + + /* + * Get the length of the true salt + */ + sl = ep - sp; + + /* + * 'Time to make the doughnuts..' + */ + MD5Init(&ctx); + + pwlen = strlen((char *)pw); + /* + * The password first, since that is what is most unknown + */ + MD5Update(&ctx, pw, pwlen); + + /* + * Then our magic string + */ + MD5Update(&ctx, (const unsigned char *) AP_MD5PW_ID, AP_MD5PW_IDLEN); + + /* + * Then the raw salt + */ + MD5Update(&ctx, sp, sl); + + /* + * Then just as many characters of the MD5(pw, salt, pw) + */ MD5Init(&ctx1); - if (i & 1) { - MD5Update(&ctx1, pw, pwlen); - } - else { - MD5Update(&ctx1, final, 16); - } - if (i % 3) { - MD5Update(&ctx1, sp, sl); + MD5Update(&ctx1, pw, pwlen); + MD5Update(&ctx1, sp, sl); + MD5Update(&ctx1, pw, pwlen); + MD5Final(final, &ctx1); + for(pl = pwlen; pl > 0; pl -= 16) + MD5Update(&ctx, final, (pl > 16) ? 16 : (unsigned int) pl); + + /* + * Don't leave anything around in vm they could use. + */ + memset(final, 0, sizeof(final)); + + /* + * Then something really weird... + */ + for (i = pwlen; i != 0; i >>= 1) { + if (i & 1) + MD5Update(&ctx, final, 1); + else + MD5Update(&ctx, pw, 1); } - if (i % 7) { - MD5Update(&ctx1, pw, pwlen); + /* + * Now make the output string. We know our limitations, so we + * can use the string routines without bounds checking. + */ + ap_cpystrn(passwd, AP_MD5PW_ID, AP_MD5PW_IDLEN + 1); + ap_cpystrn(passwd + AP_MD5PW_IDLEN, (char *)sp, sl + 1); + passwd[AP_MD5PW_IDLEN + sl] = '$'; + passwd[AP_MD5PW_IDLEN + sl + 1] = '\0'; + + MD5Final(final, &ctx); + + /* + * And now, just to make sure things don't run too fast.. + * On a 60 Mhz Pentium this takes 34 msec, so you would + * need 30 seconds to build a 1000 entry dictionary... + */ + for (i = 0; i < 1000; i++) { + MD5Init(&ctx1); + if (i & 1) + MD5Update(&ctx1, pw, pwlen); + else + MD5Update(&ctx1, final, 16); + if (i % 3) + MD5Update(&ctx1, sp, sl); + + if (i % 7) + MD5Update(&ctx1, pw, pwlen); + + if (i & 1) + MD5Update(&ctx1, final, 16); + else + MD5Update(&ctx1, pw, pwlen); + MD5Final(final,&ctx1); } - if (i & 1) { - MD5Update(&ctx1, final, 16); - } - else { - MD5Update(&ctx1, pw, pwlen); - } - MD5Final(final,&ctx1); - } - - p = passwd + strlen(passwd); - - l = (final[ 0]<<16) | (final[ 6]<<8) | final[12]; ap_to64(p, l, 4); p += 4; - l = (final[ 1]<<16) | (final[ 7]<<8) | final[13]; ap_to64(p, l, 4); p += 4; - l = (final[ 2]<<16) | (final[ 8]<<8) | final[14]; ap_to64(p, l, 4); p += 4; - l = (final[ 3]<<16) | (final[ 9]<<8) | final[15]; ap_to64(p, l, 4); p += 4; - l = (final[ 4]<<16) | (final[10]<<8) | final[ 5]; ap_to64(p, l, 4); p += 4; - l = final[11] ; ap_to64(p, l, 2); p += 2; - *p = '\0'; - - /* - * Don't leave anything around in vm they could use. - */ - memset(final, 0, sizeof(final)); - - ap_cpystrn(result, passwd, nbytes - 1); + p = passwd + strlen(passwd); + + l = (final[ 0]<<16) | (final[ 6]<<8) | final[12]; ap_to64(p, l, 4); + p += 4; + l = (final[ 1]<<16) | (final[ 7]<<8) | final[13]; ap_to64(p, l, 4); + p += 4; + l = (final[ 2]<<16) | (final[ 8]<<8) | final[14]; ap_to64(p, l, 4); + p += 4; + l = (final[ 3]<<16) | (final[ 9]<<8) | final[15]; ap_to64(p, l, 4); + p += 4; + l = (final[ 4]<<16) | (final[10]<<8) | final[ 5]; ap_to64(p, l, 4); + p += 4; + l = final[11] ; ap_to64(p, l, 2); + p += 2; + *p = '\0'; + + /* + * Don't leave anything around in vm they could use. + */ + memset(final, 0, sizeof(final)); + + ap_cpystrn(result, passwd, nbytes - 1); } diff --git a/usr.sbin/httpd/src/ap/ap_mm.c b/usr.sbin/httpd/src/ap/ap_mm.c index e0cad1a5598..4392ad10af0 100644 --- a/usr.sbin/httpd/src/ap/ap_mm.c +++ b/usr.sbin/httpd/src/ap/ap_mm.c @@ -1,3 +1,5 @@ +/* $OpenBSD: ap_mm.c,v 1.4 2005/03/28 21:03:33 niallo Exp $ */ + /* ==================================================================== * Copyright (c) 1999-2000 The Apache Group. All rights reserved. * @@ -87,9 +89,9 @@ API_EXPORT(int) ap_mm_useable(void) { return FALSE; } #define STUB_STMT(stmt) { return; } #endif -API_EXPORT(int) ap_MM_create(size_t size, char *file) +API_EXPORT(int) ap_MM_create(size_t size, char *file) STUB(MM_create(size, file), FALSE) -API_EXPORT(int) ap_MM_permission(mode_t mode, uid_t owner, gid_t group) +API_EXPORT(int) ap_MM_permission(mode_t mode, uid_t owner, gid_t group) STUB(MM_permission(mode, owner, group), -1) API_EXPORT(void) ap_MM_destroy(void) STUB_STMT(MM_destroy()) @@ -118,7 +120,8 @@ API_EXPORT(char *) ap_MM_error(void) API_EXPORT(AP_MM *) ap_mm_create(size_t size, char *file) STUB(mm_create(size, file), NULL) -API_EXPORT(int) ap_mm_permission(AP_MM *mm, mode_t mode, uid_t owner, gid_t group) +API_EXPORT(int) ap_mm_permission(AP_MM *mm, mode_t mode, uid_t owner, + gid_t group) STUB(mm_permission(mm, mode, owner, group), -1) API_EXPORT(void) ap_mm_destroy(AP_MM *mm) STUB_STMT(mm_destroy(mm)) @@ -149,7 +152,8 @@ API_EXPORT(void) ap_mm_display_info(AP_MM *mm) API_EXPORT(void *) ap_mm_core_create(size_t size, char *file) STUB(mm_core_create(size, file), NULL) -API_EXPORT(int) ap_mm_core_permission(void *core, mode_t mode, uid_t owner, gid_t group) +API_EXPORT(int) ap_mm_core_permission(void *core, mode_t mode, uid_t owner, + gid_t group) STUB(mm_core_permission(core, mode, owner, group), -1) API_EXPORT(void) ap_mm_core_delete(void *core) STUB_STMT(mm_core_delete(core)) diff --git a/usr.sbin/httpd/src/ap/ap_sha1.c b/usr.sbin/httpd/src/ap/ap_sha1.c index 31e3910425b..6a1dac0733e 100644 --- a/usr.sbin/httpd/src/ap/ap_sha1.c +++ b/usr.sbin/httpd/src/ap/ap_sha1.c @@ -1,3 +1,5 @@ +/* $OpenBSD: ap_sha1.c,v 1.9 2005/03/28 21:03:33 niallo Exp $ */ + /* ==================================================================== * The Apache Software License, Version 1.1 * @@ -60,7 +62,7 @@ * * The exported function: * - * ap_sha1_base64(const char *clear, int len, char *out); + * ap_sha1_base64(const char *clear, int len, char *out); * * provides a means to SHA1 crypt/encode a plaintext password in * a way which makes password files compatible with those commonly @@ -81,10 +83,10 @@ * This software also makes use of the following component: * * NIST Secure Hash Algorithm - * heavily modified by Uwe Hollerbach uh@alumni.caltech edu - * from Peter C. Gutmann's implementation as found in - * Applied Cryptography by Bruce Schneier - * This code is hereby placed in the public domain + * heavily modified by Uwe Hollerbach uh@alumni.caltech edu + * from Peter C. Gutmann's implementation as found in + * Applied Cryptography by Bruce Schneier + * This code is hereby placed in the public domain */ #include <string.h> @@ -94,57 +96,59 @@ #include "ap.h" -API_EXPORT(void) ap_SHA1Init(AP_SHA1_CTX *sha_info) +API_EXPORT(void) +ap_SHA1Init(AP_SHA1_CTX *sha_info) { - SHA1Init(sha_info); + SHA1Init(sha_info); } /* update the SHA digest */ -API_EXPORT(void) ap_SHA1Update_binary(AP_SHA1_CTX *sha_info, - const unsigned char *buffer, - unsigned int count) +API_EXPORT(void) +ap_SHA1Update_binary(AP_SHA1_CTX *sha_info, const unsigned char *buffer, + unsigned int count) { - SHA1Update(sha_info, buffer, count); + SHA1Update(sha_info, buffer, count); } -API_EXPORT(void) ap_SHA1Update(AP_SHA1_CTX *sha_info, const char *buf, - unsigned int count) +API_EXPORT(void) +ap_SHA1Update(AP_SHA1_CTX *sha_info, const char *buf, unsigned int count) { - SHA1Update(sha_info, (const unsigned char *) buf, count); + SHA1Update(sha_info, (const unsigned char *) buf, count); } /* finish computing the SHA digest */ -API_EXPORT(void) ap_SHA1Final(unsigned char digest[SHA_DIGESTSIZE], - AP_SHA1_CTX *sha_info) +API_EXPORT(void) +ap_SHA1Final(unsigned char digest[SHA_DIGESTSIZE], AP_SHA1_CTX *sha_info) { - SHA1Final(digest, sha_info); + SHA1Final(digest, sha_info); } -API_EXPORT(void) ap_sha1_base64(const char *clear, int len, char *out) +API_EXPORT(void) +ap_sha1_base64(const char *clear, int len, char *out) { - int l; - AP_SHA1_CTX context; - unsigned char digest[SHA_DIGESTSIZE]; + int l; + AP_SHA1_CTX context; + unsigned char digest[SHA_DIGESTSIZE]; - if (strncmp(clear, AP_SHA1PW_ID, AP_SHA1PW_IDLEN) == 0) { - clear += AP_SHA1PW_IDLEN; - } + if (strncmp(clear, AP_SHA1PW_ID, AP_SHA1PW_IDLEN) == 0) + clear += AP_SHA1PW_IDLEN; - ap_SHA1Init(&context); - ap_SHA1Update(&context, clear, len); - ap_SHA1Final(digest, &context); + ap_SHA1Init(&context); + ap_SHA1Update(&context, clear, len); + ap_SHA1Final(digest, &context); - /* private marker. */ - ap_cpystrn(out, AP_SHA1PW_ID, AP_SHA1PW_IDLEN + 1); + /* private marker. */ + ap_cpystrn(out, AP_SHA1PW_ID, AP_SHA1PW_IDLEN + 1); - /* SHA1 hash is always 20 chars */ - l = ap_base64encode_binary(out + AP_SHA1PW_IDLEN, digest, sizeof(digest)); - out[l + AP_SHA1PW_IDLEN] = '\0'; + /* SHA1 hash is always 20 chars */ + l = ap_base64encode_binary(out + AP_SHA1PW_IDLEN, digest, + sizeof(digest)); + out[l + AP_SHA1PW_IDLEN] = '\0'; - /* - * output of base64 encoded SHA1 is always 28 chars + AP_SHA1PW_IDLEN - */ + /* + * output of base64 encoded SHA1 is always 28 chars + AP_SHA1PW_IDLEN + */ } diff --git a/usr.sbin/httpd/src/ap/ap_signal.c b/usr.sbin/httpd/src/ap/ap_signal.c index 17293d7667b..27f4bbd71da 100644 --- a/usr.sbin/httpd/src/ap/ap_signal.c +++ b/usr.sbin/httpd/src/ap/ap_signal.c @@ -1,3 +1,5 @@ +/* $OpenBSD */ + /* ==================================================================== * The Apache Software License, Version 1.1 * @@ -63,14 +65,15 @@ * from W. Richard Stevens' "Advanced Programming in the UNIX Environment" * (the version that does not automatically restart system calls). */ -Sigfunc *signal(int signo, Sigfunc * func) +Sigfunc * +signal(int signo, Sigfunc * func) { - struct sigaction act, oact; + struct sigaction act, oact; - act.sa_handler = func; - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - if (sigaction(signo, &act, &oact) < 0) - return SIG_ERR; - return oact.sa_handler; + act.sa_handler = func; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + if (sigaction(signo, &act, &oact) < 0) + return SIG_ERR; + return oact.sa_handler; } diff --git a/usr.sbin/httpd/src/ap/ap_slack.c b/usr.sbin/httpd/src/ap/ap_slack.c index b7b3381801e..eb62078ebbd 100644 --- a/usr.sbin/httpd/src/ap/ap_slack.c +++ b/usr.sbin/httpd/src/ap/ap_slack.c @@ -58,10 +58,10 @@ /* * ap_slack.c: File descriptor preallocation - * + * * 3/21/93 Rob McCool * 1995-96 Many changes by the Apache Group - * + * */ #include "httpd.h" @@ -69,31 +69,31 @@ int ap_slack(int fd, int line) { - static int low_warned; - int new_fd; + static int low_warned; + int new_fd; - /* otherwise just assume line == AP_SLACK_LOW */ - if (fd >= LOW_SLACK_LINE) { - return fd; - } - new_fd = fcntl(fd, F_DUPFD, LOW_SLACK_LINE); - if (new_fd == -1) { - if (!low_warned) { - /* Give them a warning here, because we really can't predict - * how libraries and such are going to fail. If we can't - * do this F_DUPFD there's a good chance that apache has too - * few descriptors available to it. Note we don't warn on - * the high line, because if it fails we'll eventually try - * the low line... - */ - ap_log_error(APLOG_MARK, APLOG_WARNING, NULL, - "unable to open a file descriptor above %u, " - "you may need to increase the number of descriptors", - LOW_SLACK_LINE); - low_warned = 1; + /* otherwise just assume line == AP_SLACK_LOW */ + if (fd >= LOW_SLACK_LINE) { + return fd; + } + new_fd = fcntl(fd, F_DUPFD, LOW_SLACK_LINE); + if (new_fd == -1) { + if (!low_warned) { + /* Give them a warning here, because we really can't predict + * how libraries and such are going to fail. If we can't + * do this F_DUPFD there's a good chance that apache has too + * few descriptors available to it. Note we don't warn on + * the high line, because if it fails we'll eventually try + * the low line... + */ + ap_log_error(APLOG_MARK, APLOG_WARNING, NULL, + "unable to open a file descriptor above %u, " + "you may need to increase the number of descriptors", + LOW_SLACK_LINE); + low_warned = 1; + } + return fd; } - return fd; - } - close(fd); - return new_fd; + close(fd); + return new_fd; } diff --git a/usr.sbin/httpd/src/ap/ap_snprintf.c b/usr.sbin/httpd/src/ap/ap_snprintf.c index 7e02372f83d..8f215f4524b 100644 --- a/usr.sbin/httpd/src/ap/ap_snprintf.c +++ b/usr.sbin/httpd/src/ap/ap_snprintf.c @@ -1,3 +1,5 @@ +/* $OpenBSD: ap_snprintf.c,v 1.14 2005/03/28 21:03:33 niallo Exp $ */ + /* ==================================================================== * The Apache Software License, Version 1.1 * @@ -73,7 +75,7 @@ #include <math.h> typedef enum { - NO = 0, YES = 1 + NO = 0, YES = 1 } boolean_e; #ifndef FALSE @@ -123,87 +125,90 @@ typedef int bool_int; #define NDIG 80 /* buf must have at least NDIG bytes */ -static char *ap_cvt(double arg, int ndigits, int *decpt, int *sign, int eflag, char *buf) +static char * +ap_cvt(double arg, int ndigits, int *decpt, int *sign, int eflag, char *buf) { - register int r2; - double fi, fj; - register char *p, *p1; - - if (ndigits >= NDIG - 1) - ndigits = NDIG - 2; - r2 = 0; - *sign = 0; - p = &buf[0]; - if (arg < 0) { - *sign = 1; - arg = -arg; - } - arg = modf(arg, &fi); - p1 = &buf[NDIG]; - /* - * Do integer part - */ - if (fi != 0) { + register int r2; + double fi, fj; + register char *p, *p1; + + if (ndigits >= NDIG - 1) + ndigits = NDIG - 2; + r2 = 0; + *sign = 0; + p = &buf[0]; + if (arg < 0) { + *sign = 1; + arg = -arg; + } + arg = modf(arg, &fi); p1 = &buf[NDIG]; - while (p1 > &buf[0] && fi != 0) { - fj = modf(fi / 10, &fi); - *--p1 = (int) ((fj + .03) * 10) + '0'; - r2++; + /* + * Do integer part + */ + if (fi != 0) { + p1 = &buf[NDIG]; + while (p1 > &buf[0] && fi != 0) { + fj = modf(fi / 10, &fi); + *--p1 = (int) ((fj + .03) * 10) + '0'; + r2++; + } + while (p1 < &buf[NDIG]) + *p++ = *p1++; } - while (p1 < &buf[NDIG]) - *p++ = *p1++; - } - else if (arg > 0) { - while ((fj = arg * 10) < 1) { - arg = fj; - r2--; + else if (arg > 0) { + while ((fj = arg * 10) < 1) { + arg = fj; + r2--; + } } - } - p1 = &buf[ndigits]; - if (eflag == 0) - p1 += r2; - *decpt = r2; - if (p1 < &buf[0]) { - buf[0] = '\0'; - return (buf); - } - while (p <= p1 && p < &buf[NDIG]) { - arg *= 10; - arg = modf(arg, &fj); - *p++ = (int) fj + '0'; - } - if (p1 >= &buf[NDIG]) { - buf[NDIG - 1] = '\0'; + p1 = &buf[ndigits]; + if (eflag == 0) + p1 += r2; + *decpt = r2; + if (p1 < &buf[0]) { + buf[0] = '\0'; + return (buf); + } + while (p <= p1 && p < &buf[NDIG]) { + arg *= 10; + arg = modf(arg, &fj); + *p++ = (int) fj + '0'; + } + if (p1 >= &buf[NDIG]) { + buf[NDIG - 1] = '\0'; + return (buf); + } + p = p1; + *p1 += 5; + while (*p1 > '9') { + *p1 = '0'; + if (p1 > buf) + ++ * --p1; + else { + *p1 = '1'; + (*decpt)++; + if (eflag == 0) { + if (p > buf) + *p = '0'; + p++; + } + } + } + *p = '\0'; return (buf); - } - p = p1; - *p1 += 5; - while (*p1 > '9') { - *p1 = '0'; - if (p1 > buf) - ++ * --p1; - else { - *p1 = '1'; - (*decpt)++; - if (eflag == 0) { - if (p > buf) - *p = '0'; - p++; - } } - } - *p = '\0'; - return (buf); -} -static char *ap_ecvt(double arg, int ndigits, int *decpt, int *sign, char *buf) -{ - return (ap_cvt(arg, ndigits, decpt, sign, 1, buf)); -} + static char + *ap_ecvt(double arg, int ndigits, int *decpt, int *sign, char *buf) + { + return (ap_cvt(arg, ndigits, decpt, sign, 1, buf)); + } -static char *ap_fcvt(double arg, int ndigits, int *decpt, int *sign, char *buf) -{ - return (ap_cvt(arg, ndigits, decpt, sign, 0, buf)); + static char * + ap_fcvt(double arg, int ndigits, int *decpt, int *sign, char *buf) + { + return (ap_cvt(arg, ndigits, decpt, sign, 0, buf)); } /* @@ -211,63 +216,64 @@ static char *ap_fcvt(double arg, int ndigits, int *decpt, int *sign, char *buf) * minimal length string */ -static char *ap_gcvt(double number, int ndigit, char *buf, boolean_e altform) +static char +*ap_gcvt(double number, int ndigit, char *buf, boolean_e altform) { - int sign, decpt; - register char *p1, *p2; - register int i; - char buf1[NDIG]; - - p1 = ap_ecvt(number, ndigit, &decpt, &sign, buf1); - p2 = buf; - if (sign) - *p2++ = '-'; - for (i = ndigit - 1; i > 0 && p1[i] == '0'; i--) - ndigit--; - if ((decpt >= 0 && decpt - ndigit > 4) - || (decpt < 0 && decpt < -3)) { /* use E-style */ - decpt--; - *p2++ = *p1++; - *p2++ = '.'; - for (i = 1; i < ndigit; i++) - *p2++ = *p1++; - *p2++ = 'e'; - if (decpt < 0) { - decpt = -decpt; - *p2++ = '-'; - } - else - *p2++ = '+'; - if (decpt / 100 > 0) - *p2++ = decpt / 100 + '0'; - if (decpt / 10 > 0) - *p2++ = (decpt % 100) / 10 + '0'; - *p2++ = decpt % 10 + '0'; - } - else { - if (decpt <= 0) { - if (*p1 != '0') - *p2++ = '.'; - while (decpt < 0) { - decpt++; - *p2++ = '0'; - } - } - for (i = 1; i <= ndigit; i++) { - *p2++ = *p1++; - if (i == decpt) + int sign, decpt; + register char *p1, *p2; + register int i; + char buf1[NDIG]; + + p1 = ap_ecvt(number, ndigit, &decpt, &sign, buf1); + p2 = buf; + if (sign) + *p2++ = '-'; + for (i = ndigit - 1; i > 0 && p1[i] == '0'; i--) + ndigit--; + if ((decpt >= 0 && decpt - ndigit > 4) + || (decpt < 0 && decpt < -3)) { /* use E-style */ + decpt--; + *p2++ = *p1++; *p2++ = '.'; + for (i = 1; i < ndigit; i++) + *p2++ = *p1++; + *p2++ = 'e'; + if (decpt < 0) { + decpt = -decpt; + *p2++ = '-'; + } + else + *p2++ = '+'; + if (decpt / 100 > 0) + *p2++ = decpt / 100 + '0'; + if (decpt / 10 > 0) + *p2++ = (decpt % 100) / 10 + '0'; + *p2++ = decpt % 10 + '0'; } - if (ndigit < decpt) { - while (ndigit++ < decpt) - *p2++ = '0'; - *p2++ = '.'; + else { + if (decpt <= 0) { + if (*p1 != '0') + *p2++ = '.'; + while (decpt < 0) { + decpt++; + *p2++ = '0'; + } + } + for (i = 1; i <= ndigit; i++) { + *p2++ = *p1++; + if (i == decpt) + *p2++ = '.'; + } + if (ndigit < decpt) { + while (ndigit++ < decpt) + *p2++ = '0'; + *p2++ = '.'; + } } - } - if (p2[-1] == '.' && !altform) - p2--; - *p2 = '\0'; - return (buf); + if (p2[-1] == '.' && !altform) + p2--; + *p2 = '\0'; + return (buf); } /* @@ -280,27 +286,27 @@ static char *ap_gcvt(double number, int ndigit, char *buf, boolean_e altform) * * NOTE: Evaluation of the c argument should not have any side-effects */ -#define INS_CHAR(c, sp, bep, cc) \ - { \ - if (sp >= bep) { \ - vbuff->curpos = sp; \ - if (flush_func(vbuff)) \ - return -1; \ - sp = vbuff->curpos; \ - bep = vbuff->endpos; \ - } \ - *sp++ = (c); \ - cc++; \ - } - -#define NUM( c ) ( c - '0' ) - -#define STR_TO_DEC( str, num ) \ - num = NUM( *str++ ) ; \ - while ( ap_isdigit( *str ) ) \ - { \ - num *= 10 ; \ - num += NUM( *str++ ) ; \ +#define INS_CHAR(c, sp, bep, cc) \ + { \ + if (sp >= bep) { \ + vbuff->curpos = sp; \ + if (flush_func(vbuff)) \ + return -1; \ + sp = vbuff->curpos; \ + bep = vbuff->endpos; \ + } \ + *sp++ = (c); \ + cc++; \ + } + +#define NUM( c ) ( c - '0' ) + +#define STR_TO_DEC( str, num ) \ + num = NUM( *str++ ) ; \ + while ( ap_isdigit( *str ) ) \ + { \ + num *= 10 ; \ + num += NUM( *str++ ) ; \ } /* @@ -313,26 +319,26 @@ static char *ap_gcvt(double number, int ndigit, char *buf, boolean_e altform) * NOTE: this makes use of the magic info that s is * always based on num_buf with a size of NUM_BUF_SIZE. */ -#define FIX_PRECISION( adjust, precision, s, s_len ) \ - if ( adjust ) { \ +#define FIX_PRECISION( adjust, precision, s, s_len ) \ + if ( adjust ) { \ int p = precision < NUM_BUF_SIZE - 1 ? precision : NUM_BUF_SIZE - 1; \ - while ( s_len < p ) \ - { \ - *--s = '0' ; \ - s_len++ ; \ - } \ + while ( s_len < p ) \ + { \ + *--s = '0' ; \ + s_len++ ; \ + } \ } /* * Macro that does padding. The padding is done by printing * the character ch. */ -#define PAD( width, len, ch ) do \ - { \ - INS_CHAR( ch, sp, bep, cc ) ; \ - width-- ; \ - } \ - while ( width > len ) +#define PAD( width, len, ch ) do \ + { \ + INS_CHAR( ch, sp, bep, cc ) ; \ + width-- ; \ + } \ + while ( width > len ) /* * Prefix the character ch to the string str @@ -358,144 +364,149 @@ static char *ap_gcvt(double number, int ndigit, char *buf, boolean_e altform) * (conv_10_quad), the other when we don't (conv_10). We're assuming the * latter is faster. */ -static char *conv_10(register wide_int num, register bool_int is_unsigned, - register bool_int *is_negative, char *buf_end, - register int *len) +static char * +conv_10(register wide_int num, register bool_int is_unsigned, + register bool_int *is_negative, char *buf_end, register int *len) { - register char *p = buf_end; - register u_wide_int magnitude; + register char *p = buf_end; + register u_wide_int magnitude; - if (is_unsigned) { - magnitude = (u_wide_int) num; - *is_negative = FALSE; - } - else { - *is_negative = (num < 0); + if (is_unsigned) { + magnitude = (u_wide_int) num; + *is_negative = FALSE; + } + else { + *is_negative = (num < 0); - /* - * On a 2's complement machine, negating the most negative integer - * results in a number that cannot be represented as a signed integer. - * Here is what we do to obtain the number's magnitude: - * a. add 1 to the number - * b. negate it (becomes positive) - * c. convert it to unsigned - * d. add 1 - */ - if (*is_negative) { - wide_int t = num + 1; - - magnitude = ((u_wide_int) -t) + 1; + /* + * On a 2's complement machine, negating the most negative + * integer results in a number that cannot be represented as + * a signed integer. + * Here is what we do to obtain the number's magnitude: + * a. add 1 to the number + * b. negate it (becomes positive) + * c. convert it to unsigned + * d. add 1 + */ + if (*is_negative) { + wide_int t = num + 1; + + magnitude = ((u_wide_int) -t) + 1; + } + else + magnitude = (u_wide_int) num; } - else - magnitude = (u_wide_int) num; - } - /* - * We use a do-while loop so that we write at least 1 digit - */ - do { - register u_wide_int new_magnitude = magnitude / 10; + /* + * We use a do-while loop so that we write at least 1 digit + */ + do { + register u_wide_int new_magnitude = magnitude / 10; - *--p = (char) (magnitude - new_magnitude * 10 + '0'); - magnitude = new_magnitude; - } - while (magnitude); + *--p = (char) (magnitude - new_magnitude * 10 + '0'); + magnitude = new_magnitude; + } + while (magnitude); - *len = buf_end - p; - return (p); + *len = buf_end - p; + return (p); } -static char *conv_10_quad(widest_int num, register bool_int is_unsigned, - register bool_int *is_negative, char *buf_end, - register int *len) +static char * +conv_10_quad(widest_int num, register bool_int is_unsigned, + register bool_int *is_negative, char *buf_end, register int *len) { - register char *p = buf_end; - u_widest_int magnitude; - - /* - * We see if we can use the faster non-quad version by checking the - * number against the largest long value it can be. If <=, we - * punt to the quicker version. - */ - if ((num <= ULONG_MAX && is_unsigned) || (num <= LONG_MAX && !is_unsigned)) - return(conv_10( (wide_int)num, is_unsigned, is_negative, - buf_end, len)); - - if (is_unsigned) { - magnitude = (u_widest_int) num; - *is_negative = FALSE; - } - else { - *is_negative = (num < 0); + register char *p = buf_end; + u_widest_int magnitude; /* - * On a 2's complement machine, negating the most negative integer - * results in a number that cannot be represented as a signed integer. - * Here is what we do to obtain the number's magnitude: - * a. add 1 to the number - * b. negate it (becomes positive) - * c. convert it to unsigned - * d. add 1 - */ - if (*is_negative) { - widest_int t = num + 1; - - magnitude = ((u_widest_int) -t) + 1; + * We see if we can use the faster non-quad version by checking the + * number against the largest long value it can be. If <=, we + * punt to the quicker version. + */ + if ((num <= ULONG_MAX && is_unsigned) || + (num <= LONG_MAX && !is_unsigned)) + return(conv_10( (wide_int)num, is_unsigned, is_negative, + buf_end, len)); + + if (is_unsigned) { + magnitude = (u_widest_int) num; + *is_negative = FALSE; } - else - magnitude = (u_widest_int) num; - } + else { + *is_negative = (num < 0); - /* - * We use a do-while loop so that we write at least 1 digit - */ - do { - u_widest_int new_magnitude = magnitude / 10; + /* + * On a 2's complement machine, negating the most negative + * integer * results in a number that cannot be represented as + * a signed integer. + * Here is what we do to obtain the number's magnitude: + * a. add 1 to the number + * b. negate it (becomes positive) + * c. convert it to unsigned + * d. add 1 + */ + if (*is_negative) { + widest_int t = num + 1; - *--p = (char) (magnitude - new_magnitude * 10 + '0'); - magnitude = new_magnitude; - } - while (magnitude); + magnitude = ((u_widest_int) -t) + 1; + } + else + magnitude = (u_widest_int) num; + } + + /* + * We use a do-while loop so that we write at least 1 digit + */ + do { + u_widest_int new_magnitude = magnitude / 10; - *len = buf_end - p; - return (p); + *--p = (char) (magnitude - new_magnitude * 10 + '0'); + magnitude = new_magnitude; + } + while (magnitude); + + *len = buf_end - p; + return (p); } -static char *conv_in_addr(struct in_addr *ia, char *buf_end, int *len) +static char* +conv_in_addr(struct in_addr *ia, char *buf_end, int *len) { - unsigned addr = ntohl(ia->s_addr); - char *p = buf_end; - bool_int is_negative; - int sub_len; - - p = conv_10((addr & 0x000000FF) , TRUE, &is_negative, p, &sub_len); - *--p = '.'; - p = conv_10((addr & 0x0000FF00) >> 8, TRUE, &is_negative, p, &sub_len); - *--p = '.'; - p = conv_10((addr & 0x00FF0000) >> 16, TRUE, &is_negative, p, &sub_len); - *--p = '.'; - p = conv_10((addr & 0xFF000000) >> 24, TRUE, &is_negative, p, &sub_len); - - *len = buf_end - p; - return (p); + unsigned addr = ntohl(ia->s_addr); + char *p = buf_end; + bool_int is_negative; + int sub_len; + + p = conv_10((addr & 0x000000FF) , TRUE, &is_negative, p, &sub_len); + *--p = '.'; + p = conv_10((addr & 0x0000FF00) >> 8, TRUE, &is_negative, p, &sub_len); + *--p = '.'; + p = conv_10((addr & 0x00FF0000) >> 16, TRUE, &is_negative, p, &sub_len); + *--p = '.'; + p = conv_10((addr & 0xFF000000) >> 24, TRUE, &is_negative, p, &sub_len); + + *len = buf_end - p; + return (p); } -static char *conv_sockaddr_in(struct sockaddr_in *si, char *buf_end, int *len) +static char * +conv_sockaddr_in(struct sockaddr_in *si, char *buf_end, int *len) { - char *p = buf_end; - bool_int is_negative; - int sub_len; + char *p = buf_end; + bool_int is_negative; + int sub_len; - p = conv_10(ntohs(si->sin_port), TRUE, &is_negative, p, &sub_len); - *--p = ':'; - p = conv_in_addr(&si->sin_addr, p, &sub_len); + p = conv_10(ntohs(si->sin_port), TRUE, &is_negative, p, &sub_len); + *--p = ':'; + p = conv_in_addr(&si->sin_addr, p, &sub_len); - *len = buf_end - p; - return (p); + *len = buf_end - p; + return (p); } @@ -506,88 +517,89 @@ static char *conv_sockaddr_in(struct sockaddr_in *si, char *buf_end, int *len) * The sign is returned in the is_negative argument (and is not placed * in buf). */ -static char *conv_fp(register char format, register double num, - boolean_e add_dp, int precision, bool_int *is_negative, - char *buf, int *len, int buflen) +static char * +conv_fp(register char format, register double num, boolean_e add_dp, + int precision, bool_int *is_negative, char *buf, int *len, int buflen) { - register char *s = buf; - register char *p; - int decimal_point; - char buf1[NDIG]; - - if (format == 'f') - p = ap_fcvt(num, precision, &decimal_point, is_negative, buf1); - else /* either e or E format */ - p = ap_ecvt(num, precision + 1, &decimal_point, is_negative, buf1); - - /* - * Check for Infinity and NaN - */ - if (ap_isalpha(*p)) { - *len = strlcpy(buf, p, buflen); /* we really need the wanted len here */ - *is_negative = FALSE; - return (buf); - } + register char *s = buf; + register char *p; + int decimal_point; + char buf1[NDIG]; + + if (format == 'f') + p = ap_fcvt(num, precision, &decimal_point, is_negative, buf1); + else /* either e or E format */ + p = ap_ecvt(num, precision + 1, &decimal_point, is_negative, + buf1); + /* + * Check for Infinity and NaN + */ + if (ap_isalpha(*p)) { + *len = strlcpy(buf, p, buflen); + /* we really need the wanted len here */ + *is_negative = FALSE; + return (buf); + } - if (format == 'f') { - if (decimal_point <= 0) { - *s++ = '0'; - if (precision > 0) { - *s++ = '.'; - while (decimal_point++ < 0) - *s++ = '0'; - } - else if (add_dp) - *s++ = '.'; + if (format == 'f') { + if (decimal_point <= 0) { + *s++ = '0'; + if (precision > 0) { + *s++ = '.'; + while (decimal_point++ < 0) + *s++ = '0'; + } + else if (add_dp) + *s++ = '.'; + } + else { + while (decimal_point-- > 0) + *s++ = *p++; + if (precision > 0 || add_dp) + *s++ = '.'; + } } else { - while (decimal_point-- > 0) *s++ = *p++; - if (precision > 0 || add_dp) - *s++ = '.'; + if (precision > 0 || add_dp) + *s++ = '.'; } - } - else { - *s++ = *p++; - if (precision > 0 || add_dp) - *s++ = '.'; - } - /* - * copy the rest of p, the NUL is NOT copied - */ - while (*p) - *s++ = *p++; - - if (format != 'f') { - char temp[EXPONENT_LENGTH]; /* for exponent conversion */ - int t_len; - bool_int exponent_is_negative; - - *s++ = format; /* either e or E */ - decimal_point--; - if (decimal_point != 0) { - p = conv_10((wide_int) decimal_point, FALSE, &exponent_is_negative, - &temp[EXPONENT_LENGTH], &t_len); - *s++ = exponent_is_negative ? '-' : '+'; - - /* - * Make sure the exponent has at least 2 digits - */ - if (t_len == 1) - *s++ = '0'; - while (t_len--) + /* + * copy the rest of p, the NUL is NOT copied + */ + while (*p) *s++ = *p++; - } - else { - *s++ = '+'; - *s++ = '0'; - *s++ = '0'; - } - } - *len = s - buf; - return (buf); + if (format != 'f') { + char temp[EXPONENT_LENGTH]; /* for exponent conversion */ + int t_len; + bool_int exponent_is_negative; + + *s++ = format; /* either e or E */ + decimal_point--; + if (decimal_point != 0) { + p = conv_10((wide_int) decimal_point, FALSE, + &exponent_is_negative, &temp[EXPONENT_LENGTH], + &t_len); + *s++ = exponent_is_negative ? '-' : '+'; + + /* + * Make sure the exponent has at least 2 digits + */ + if (t_len == 1) + *s++ = '0'; + while (t_len--) + *s++ = *p++; + } + else { + *s++ = '+'; + *s++ = '0'; + *s++ = '0'; + } + } + *len = s - buf; + return (buf); } @@ -604,596 +616,645 @@ static char *conv_fp(register char format, register double num, * As with conv_10, we have a faster version which is used when * the number isn't quad size. */ -static char *conv_p2(register u_wide_int num, register int nbits, - char format, char *buf_end, register int *len) +static char * +conv_p2(register u_wide_int num, register int nbits, char format, char *buf_end, + register int *len) { - register int mask = (1 << nbits) - 1; - register char *p = buf_end; - static const char low_digits[] = "0123456789abcdef"; - static const char upper_digits[] = "0123456789ABCDEF"; - register const char *digits = (format == 'X') ? upper_digits : low_digits; - - do { - *--p = digits[num & mask]; - num >>= nbits; - } - while (num); + register int mask = (1 << nbits) - 1; + register char *p = buf_end; + static const char low_digits[] = "0123456789abcdef"; + static const char upper_digits[] = "0123456789ABCDEF"; + register const char *digits = (format == 'X') ? upper_digits : + low_digits; + + do { + *--p = digits[num & mask]; + num >>= nbits; + } + while (num); - *len = buf_end - p; - return (p); + *len = buf_end - p; + return (p); } -static char *conv_p2_quad(u_widest_int num, register int nbits, - char format, char *buf_end, register int *len) +static char * +conv_p2_quad(u_widest_int num, register int nbits, char format, + char *buf_end, register int *len) { - register int mask = (1 << nbits) - 1; - register char *p = buf_end; - static const char low_digits[] = "0123456789abcdef"; - static const char upper_digits[] = "0123456789ABCDEF"; - register const char *digits = (format == 'X') ? upper_digits : low_digits; - - if (num <= ULONG_MAX) - return(conv_p2( (u_wide_int)num, nbits, format, buf_end, len)); - - do { - *--p = digits[num & mask]; - num >>= nbits; - } - while (num); + register int mask = (1 << nbits) - 1; + register char *p = buf_end; + static const char low_digits[] = "0123456789abcdef"; + static const char upper_digits[] = "0123456789ABCDEF"; + register const char *digits = (format == 'X') ? upper_digits : + low_digits; + + if (num <= ULONG_MAX) + return(conv_p2( (u_wide_int)num, nbits, format, buf_end, len)); + + do { + *--p = digits[num & mask]; + num >>= nbits; + } + while (num); - *len = buf_end - p; - return (p); + *len = buf_end - p; + return (p); } /* * Do format conversion placing the output in buffer */ -API_EXPORT(int) ap_vformatter(int (*flush_func)(ap_vformatter_buff *), +API_EXPORT(int) +ap_vformatter(int (*flush_func)(ap_vformatter_buff *), ap_vformatter_buff *vbuff, const char *fmt, va_list ap) { - register char *sp; - register char *bep; - register int cc = 0; - register int i; - - register char *s = NULL; - char *q; - int s_len; - - register int min_width = 0; - int precision = 0; - enum { + register char *sp; + register char *bep; + register int cc = 0; + register int i; + + register char *s = NULL; + char *q; + int s_len; + + register int min_width = 0; + int precision = 0; + enum { LEFT, RIGHT - } adjust; - char pad_char; - char prefix_char; - - double fp_num; - widest_int i_quad = (widest_int) 0; - u_widest_int ui_quad; - wide_int i_num = (wide_int) 0; - u_wide_int ui_num; - - char num_buf[NUM_BUF_SIZE]; - char char_buf[2]; /* for printing %% and %<unknown> */ - - enum var_type_enum { - IS_QUAD, IS_LONG, IS_SHORT, IS_INT - }; - enum var_type_enum var_type = IS_INT; - - /* - * Flag variables - */ - boolean_e alternate_form; - boolean_e print_sign; - boolean_e print_blank; - boolean_e adjust_precision; - boolean_e adjust_width; - bool_int is_negative; - - sp = vbuff->curpos; - bep = vbuff->endpos; - - while (*fmt) { - if (*fmt != '%') { - INS_CHAR(*fmt, sp, bep, cc); - } - else { - /* - * Default variable settings - */ - adjust = RIGHT; - alternate_form = print_sign = print_blank = NO; - pad_char = ' '; - prefix_char = NUL; - - fmt++; - - /* - * Try to avoid checking for flags, width or precision - */ - if (!ap_islower(*fmt)) { - /* - * Recognize flags: -, #, BLANK, + - */ - for (;; fmt++) { - if (*fmt == '-') - adjust = LEFT; - else if (*fmt == '+') - print_sign = YES; - else if (*fmt == '#') - alternate_form = YES; - else if (*fmt == ' ') - print_blank = YES; - else if (*fmt == '0') - pad_char = '0'; - else - break; - } + } adjust; + char pad_char; + char prefix_char; - /* - * Check if a width was specified - */ - if (ap_isdigit(*fmt)) { - STR_TO_DEC(fmt, min_width); - adjust_width = YES; - } - else if (*fmt == '*') { - min_width = va_arg(ap, int); - fmt++; - adjust_width = YES; - if (min_width < 0) { - adjust = LEFT; - min_width = -min_width; - } - } - else - adjust_width = NO; + double fp_num; + widest_int i_quad = (widest_int) 0; + u_widest_int ui_quad; + wide_int i_num = (wide_int) 0; + u_wide_int ui_num; - /* - * Check if a precision was specified - */ - if (*fmt == '.') { - adjust_precision = YES; - fmt++; - if (ap_isdigit(*fmt)) { - STR_TO_DEC(fmt, precision); - } - else if (*fmt == '*') { - precision = va_arg(ap, int); - fmt++; - if (precision < 0) - precision = 0; - } - else - precision = 0; - } - else - adjust_precision = NO; - } - else - adjust_precision = adjust_width = NO; - - /* - * Modifier check - */ - if (*fmt == 'q') { - var_type = IS_QUAD; - fmt++; - } - else if (*fmt == 'l') { - var_type = IS_LONG; - fmt++; - } - else if (*fmt == 'h') { - var_type = IS_SHORT; - fmt++; - } - else { - var_type = IS_INT; - } - - /* - * Argument extraction and printing. - * First we determine the argument type. - * Then, we convert the argument to a string. - * On exit from the switch, s points to the string that - * must be printed, s_len has the length of the string - * The precision requirements, if any, are reflected in s_len. - * - * NOTE: pad_char may be set to '0' because of the 0 flag. - * It is reset to ' ' by non-numeric formats - */ - switch (*fmt) { - case 'u': - if (var_type == IS_QUAD) { - i_quad = va_arg(ap, u_widest_int); - s = conv_10_quad(i_quad, 1, &is_negative, - &num_buf[NUM_BUF_SIZE], &s_len); - } - else { - if (var_type == IS_LONG) - i_num = (wide_int) va_arg(ap, u_wide_int); - else if (var_type == IS_SHORT) - i_num = (wide_int) (unsigned short) va_arg(ap, unsigned int); - else - i_num = (wide_int) va_arg(ap, unsigned int); - s = conv_10(i_num, 1, &is_negative, - &num_buf[NUM_BUF_SIZE], &s_len); - } - FIX_PRECISION(adjust_precision, precision, s, s_len); - break; - - case 'd': - case 'i': - if (var_type == IS_QUAD) { - i_quad = va_arg(ap, widest_int); - s = conv_10_quad(i_quad, 0, &is_negative, - &num_buf[NUM_BUF_SIZE], &s_len); - } - else { - if (var_type == IS_LONG) - i_num = (wide_int) va_arg(ap, wide_int); - else if (var_type == IS_SHORT) - i_num = (wide_int) (short) va_arg(ap, int); - else - i_num = (wide_int) va_arg(ap, int); - s = conv_10(i_num, 0, &is_negative, - &num_buf[NUM_BUF_SIZE], &s_len); - } - FIX_PRECISION(adjust_precision, precision, s, s_len); - - if (is_negative) - prefix_char = '-'; - else if (print_sign) - prefix_char = '+'; - else if (print_blank) - prefix_char = ' '; - break; - - - case 'o': - if (var_type == IS_QUAD) { - ui_quad = va_arg(ap, u_widest_int); - s = conv_p2_quad(ui_quad, 3, *fmt, - &num_buf[NUM_BUF_SIZE], &s_len); - } - else { - if (var_type == IS_LONG) - ui_num = (u_wide_int) va_arg(ap, u_wide_int); - else if (var_type == IS_SHORT) - ui_num = (u_wide_int) (unsigned short) va_arg(ap, unsigned int); - else - ui_num = (u_wide_int) va_arg(ap, unsigned int); - s = conv_p2(ui_num, 3, *fmt, - &num_buf[NUM_BUF_SIZE], &s_len); - } - FIX_PRECISION(adjust_precision, precision, s, s_len); - if (alternate_form && *s != '0') { - *--s = '0'; - s_len++; - } - break; - - - case 'x': - case 'X': - if (var_type == IS_QUAD) { - ui_quad = va_arg(ap, u_widest_int); - s = conv_p2_quad(ui_quad, 4, *fmt, - &num_buf[NUM_BUF_SIZE], &s_len); - } - else { - if (var_type == IS_LONG) - ui_num = (u_wide_int) va_arg(ap, u_wide_int); - else if (var_type == IS_SHORT) - ui_num = (u_wide_int) (unsigned short) va_arg(ap, unsigned int); - else - ui_num = (u_wide_int) va_arg(ap, unsigned int); - s = conv_p2(ui_num, 4, *fmt, - &num_buf[NUM_BUF_SIZE], &s_len); - } - FIX_PRECISION(adjust_precision, precision, s, s_len); - if (alternate_form && i_num != 0) { - *--s = *fmt; /* 'x' or 'X' */ - *--s = '0'; - s_len += 2; - } - break; + char num_buf[NUM_BUF_SIZE]; + char char_buf[2]; /* for printing %% and %<unknown> */ + enum var_type_enum { + IS_QUAD, IS_LONG, IS_SHORT, IS_INT + }; + enum var_type_enum var_type = IS_INT; - case 's': - s = va_arg(ap, char *); - if (s != NULL) { - s_len = strlen(s); - if (adjust_precision && precision < s_len) - s_len = precision; - } + /* + * Flag variables + */ + boolean_e alternate_form; + boolean_e print_sign; + boolean_e print_blank; + boolean_e adjust_precision; + boolean_e adjust_width; + bool_int is_negative; + + sp = vbuff->curpos; + bep = vbuff->endpos; + + while (*fmt) { + if (*fmt != '%') { + INS_CHAR(*fmt, sp, bep, cc); + } else { - s = S_NULL; - s_len = S_NULL_LEN; - } - pad_char = ' '; - break; - - - case 'f': - case 'e': - case 'E': - fp_num = va_arg(ap, double); - /* - * * We use &num_buf[ 1 ], so that we have room for the sign - */ - if (isnan(fp_num)) { - s = "nan"; - s_len = 3; - } - else - if (isinf(fp_num)) { - s = "inf"; - s_len = 3; - } - else - { - s = conv_fp(*fmt, fp_num, alternate_form, - (adjust_precision == NO) ? FLOAT_DIGITS : precision, - &is_negative, &num_buf[1], &s_len, - sizeof(num_buf) - 1); - if (is_negative) - prefix_char = '-'; - else if (print_sign) - prefix_char = '+'; - else if (print_blank) - prefix_char = ' '; - } - break; - + /* + * Default variable settings + */ + adjust = RIGHT; + alternate_form = print_sign = print_blank = NO; + pad_char = ' '; + prefix_char = NUL; - case 'g': - case 'G': - if (adjust_precision == NO) - precision = FLOAT_DIGITS; - else if (precision == 0) - precision = 1; - /* - * * We use &num_buf[ 1 ], so that we have room for the sign - */ - s = ap_gcvt(va_arg(ap, double), precision, &num_buf[1], - alternate_form); - if (*s == '-') - prefix_char = *s++; - else if (print_sign) - prefix_char = '+'; - else if (print_blank) - prefix_char = ' '; - - s_len = strlen(s); - - if (alternate_form && (q = strchr(s, '.')) == NULL) { - s[s_len++] = '.'; - s[s_len] = '\0'; /* delimit for following strchr() */ - } - if (*fmt == 'G' && (q = strchr(s, 'e')) != NULL) - *q = 'E'; - break; - - - case 'c': - char_buf[0] = (char) (va_arg(ap, int)); - s = &char_buf[0]; - s_len = 1; - pad_char = ' '; - break; - - - case '%': - char_buf[0] = '%'; - s = &char_buf[0]; - s_len = 1; - pad_char = ' '; - break; - - - case 'n': - if (var_type == IS_QUAD) - *(va_arg(ap, widest_int *)) = cc; - else if (var_type == IS_LONG) - *(va_arg(ap, long *)) = cc; - else if (var_type == IS_SHORT) - *(va_arg(ap, short *)) = cc; - else - *(va_arg(ap, int *)) = cc; - break; + fmt++; - /* - * This is where we extend the printf format, with a second - * type specifier - */ - case 'p': - switch(*++fmt) { - /* - * If the pointer size is equal to or smaller than the size - * of the largest unsigned int, we convert the pointer to a - * hex number, otherwise we print "%p" to indicate that we - * don't handle "%p". - */ - case 'p': -#ifdef AP_VOID_P_IS_QUAD - if (sizeof(void *) <= sizeof(u_widest_int)) { - ui_quad = (u_widest_int) va_arg(ap, void *); - s = conv_p2_quad(ui_quad, 4, 'x', - &num_buf[NUM_BUF_SIZE], &s_len); - } -#else - if (sizeof(void *) <= sizeof(u_wide_int)) { - ui_num = (u_wide_int) va_arg(ap, void *); - s = conv_p2(ui_num, 4, 'x', - &num_buf[NUM_BUF_SIZE], &s_len); - } -#endif - else { - s = "%p"; - s_len = 2; - prefix_char = NUL; - } - pad_char = ' '; - break; - - /* print a struct sockaddr_in as a.b.c.d:port */ - case 'I': - { - struct sockaddr_in *si; - - si = va_arg(ap, struct sockaddr_in *); - if (si != NULL) { - s = conv_sockaddr_in(si, &num_buf[NUM_BUF_SIZE], &s_len); - if (adjust_precision && precision < s_len) - s_len = precision; + /* + * Try to avoid checking for flags, width or precision + */ + if (!ap_islower(*fmt)) { + /* + * Recognize flags: -, #, BLANK, + + */ + for (;; fmt++) { + if (*fmt == '-') + adjust = LEFT; + else if (*fmt == '+') + print_sign = YES; + else if (*fmt == '#') + alternate_form = YES; + else if (*fmt == ' ') + print_blank = YES; + else if (*fmt == '0') + pad_char = '0'; + else + break; + } + + /* + * Check if a width was specified + */ + if (ap_isdigit(*fmt)) { + STR_TO_DEC(fmt, min_width); + adjust_width = YES; + } + else if (*fmt == '*') { + min_width = va_arg(ap, int); + fmt++; + adjust_width = YES; + if (min_width < 0) { + adjust = LEFT; + min_width = -min_width; + } + } + else + adjust_width = NO; + + /* + * Check if a precision was specified + */ + if (*fmt == '.') { + adjust_precision = YES; + fmt++; + if (ap_isdigit(*fmt)) { + STR_TO_DEC(fmt, precision); + } + else if (*fmt == '*') { + precision = va_arg(ap, int); + fmt++; + if (precision < 0) + precision = 0; + } + else + precision = 0; + } + else + adjust_precision = NO; } - else { - s = S_NULL; - s_len = S_NULL_LEN; + else + adjust_precision = adjust_width = NO; + + /* + * Modifier check + */ + if (*fmt == 'q') { + var_type = IS_QUAD; + fmt++; } - pad_char = ' '; - } - break; - - /* print a struct in_addr as a.b.c.d */ - case 'A': - { - struct in_addr *ia; - - ia = va_arg(ap, struct in_addr *); - if (ia != NULL) { - s = conv_in_addr(ia, &num_buf[NUM_BUF_SIZE], &s_len); - if (adjust_precision && precision < s_len) - s_len = precision; + else if (*fmt == 'l') { + var_type = IS_LONG; + fmt++; + } + else if (*fmt == 'h') { + var_type = IS_SHORT; + fmt++; } else { - s = S_NULL; - s_len = S_NULL_LEN; + var_type = IS_INT; } - pad_char = ' '; - } - break; - - case NUL: - /* if %p ends the string, oh well ignore it */ - continue; - - default: - s = "bogus %p"; - s_len = 8; - prefix_char = NUL; - break; - } - break; - case NUL: - /* - * The last character of the format string was %. - * We ignore it. - */ - continue; + /* + * Argument extraction and printing. + * First we determine the argument type. + * Then, we convert the argument to a string. + * On exit from the switch, s points to the string that + * must be printed, s_len has the length of the string + * The precision requirements, if any, are reflected in + * s_len. + * + * NOTE: pad_char may be set to '0' because of the 0 + * flag. + * It is reset to ' ' by non-numeric formats + */ + switch (*fmt) { + case 'u': + if (var_type == IS_QUAD) { + i_quad = va_arg(ap, u_widest_int); + s = conv_10_quad(i_quad, 1, &is_negative, + &num_buf[NUM_BUF_SIZE], &s_len); + } + else { + if (var_type == IS_LONG) + i_num = (wide_int) va_arg(ap, + u_wide_int); + else if (var_type == IS_SHORT) + i_num = (wide_int) + (unsigned short) va_arg(ap, + unsigned int); + else + i_num = (wide_int) va_arg(ap, + unsigned int); + s = conv_10(i_num, 1, &is_negative, + &num_buf[NUM_BUF_SIZE], &s_len); + } + FIX_PRECISION(adjust_precision, precision, s, + s_len); + break; + + case 'd': + case 'i': + if (var_type == IS_QUAD) { + i_quad = va_arg(ap, widest_int); + s = conv_10_quad(i_quad, 0, + &is_negative, + &num_buf[NUM_BUF_SIZE], &s_len); + } + else { + if (var_type == IS_LONG) + i_num = (wide_int) va_arg(ap, + wide_int); + else if (var_type == IS_SHORT) + i_num = (wide_int) (short) + va_arg(ap, int); + else + i_num = (wide_int) va_arg(ap, + int); + s = conv_10(i_num, 0, &is_negative, + &num_buf[NUM_BUF_SIZE], &s_len); + } + FIX_PRECISION(adjust_precision, precision, s, + s_len); + + if (is_negative) + prefix_char = '-'; + else if (print_sign) + prefix_char = '+'; + else if (print_blank) + prefix_char = ' '; + break; + + + case 'o': + if (var_type == IS_QUAD) { + ui_quad = va_arg(ap, u_widest_int); + s = conv_p2_quad(ui_quad, 3, *fmt, + &num_buf[NUM_BUF_SIZE], &s_len); + } + else { + if (var_type == IS_LONG) + ui_num = (u_wide_int) va_arg(ap, + u_wide_int); + else if (var_type == IS_SHORT) + ui_num = (u_wide_int) + (unsigned short) + va_arg(ap, unsigned int); + else + ui_num = (u_wide_int) va_arg(ap, + unsigned int); + s = conv_p2(ui_num, 3, *fmt, + &num_buf[NUM_BUF_SIZE], &s_len); + } + FIX_PRECISION(adjust_precision, precision, s, + s_len); + if (alternate_form && *s != '0') { + *--s = '0'; + s_len++; + } + break; + + + case 'x': + case 'X': + if (var_type == IS_QUAD) { + ui_quad = va_arg(ap, u_widest_int); + s = conv_p2_quad(ui_quad, 4, *fmt, + &num_buf[NUM_BUF_SIZE], &s_len); + } + else { + if (var_type == IS_LONG) + ui_num = (u_wide_int) va_arg(ap, + u_wide_int); + else if (var_type == IS_SHORT) + ui_num = (u_wide_int) + (unsigned short) va_arg(ap, + unsigned int); + else + ui_num = (u_wide_int) va_arg(ap, + unsigned int); + s = conv_p2(ui_num, 4, *fmt, + &num_buf[NUM_BUF_SIZE], &s_len); + } + FIX_PRECISION(adjust_precision, precision, s, + s_len); + if (alternate_form && i_num != 0) { + *--s = *fmt; /* 'x' or 'X' */ + *--s = '0'; + s_len += 2; + } + break; + + + case 's': + s = va_arg(ap, char *); + if (s != NULL) { + s_len = strlen(s); + if (adjust_precision && precision + < s_len) + s_len = precision; + } + else { + s = S_NULL; + s_len = S_NULL_LEN; + } + pad_char = ' '; + break; + + + case 'f': + case 'e': + case 'E': + fp_num = va_arg(ap, double); + /* + * * We use &num_buf[ 1 ], so that we have room + * for the sign + */ + if (isnan(fp_num)) { + s = "nan"; + s_len = 3; + } + else if (isinf(fp_num)) { + s = "inf"; + s_len = 3; + } else { + s = conv_fp(*fmt, fp_num, + alternate_form, + (adjust_precision == NO) ? + FLOAT_DIGITS : precision, + &is_negative, &num_buf[1], + &s_len, sizeof(num_buf) - 1); + if (is_negative) + prefix_char = '-'; + else if (print_sign) + prefix_char = '+'; + else if (print_blank) + prefix_char = ' '; + } + break; + + + case 'g': + case 'G': + if (adjust_precision == NO) + precision = FLOAT_DIGITS; + else if (precision == 0) + precision = 1; + /* + * * We use &num_buf[ 1 ], so that we have room + * for the sign + */ + s = ap_gcvt(va_arg(ap, double), precision, + &num_buf[1], alternate_form); + if (*s == '-') + prefix_char = *s++; + else if (print_sign) + prefix_char = '+'; + else if (print_blank) + prefix_char = ' '; + + s_len = strlen(s); + + if (alternate_form && (q = strchr(s, '.')) + == NULL) { + s[s_len++] = '.'; + s[s_len] = '\0'; + /* delimit for following strchr() */ + } + if (*fmt == 'G' && (q = strchr(s, 'e')) != NULL) + *q = 'E'; + break; + + + case 'c': + char_buf[0] = (char) (va_arg(ap, int)); + s = &char_buf[0]; + s_len = 1; + pad_char = ' '; + break; + + + case '%': + char_buf[0] = '%'; + s = &char_buf[0]; + s_len = 1; + pad_char = ' '; + break; + + + case 'n': + if (var_type == IS_QUAD) + *(va_arg(ap, widest_int *)) = cc; + else if (var_type == IS_LONG) + *(va_arg(ap, long *)) = cc; + else if (var_type == IS_SHORT) + *(va_arg(ap, short *)) = cc; + else + *(va_arg(ap, int *)) = cc; + break; + + /* + * This is where we extend the printf format, with a + * second type specifier + */ + case 'p': + switch(*++fmt) { + /* + * If the pointer size is equal to or + * smaller than the size of the largest + * unsigned int, we convert the pointer + * to a hex number, + * otherwise we print "%p" to indicate + * that we don't handle "%p". + */ + case 'p': + #ifdef AP_VOID_P_IS_QUAD + if (sizeof(void *) + <= sizeof(u_widest_int)) { + ui_quad = (u_widest_int) + va_arg(ap, void *); + s = conv_p2_quad(ui_quad, 4, + 'x', &num_buf[NUM_BUF_SIZE], + &s_len); + } + #else + if (sizeof(void *) + <= sizeof(u_wide_int)) { + ui_num = (u_wide_int) va_arg(ap, + void *); + s = conv_p2(ui_num, 4, 'x', + &num_buf[NUM_BUF_SIZE], + &s_len); + } + #endif + else { + s = "%p"; + s_len = 2; + prefix_char = NUL; + } + pad_char = ' '; + break; + + /* print a struct sockaddr_in as a.b.c.d:port */ + case 'I': + { + struct sockaddr_in *si; + + si = va_arg(ap, struct sockaddr_in *); + if (si != NULL) { + s = conv_sockaddr_in(si, + &num_buf[NUM_BUF_SIZE], + &s_len); + if (adjust_precision && + precision < s_len) + s_len = precision; + } + else { + s = S_NULL; + s_len = S_NULL_LEN; + } + pad_char = ' '; + break; + } + + /* print a struct in_addr as a.b.c.d */ + case 'A': + { + struct in_addr *ia; + + ia = va_arg(ap, struct in_addr *); + if (ia != NULL) { + s = conv_in_addr(ia, + &num_buf[NUM_BUF_SIZE], + &s_len); + if (adjust_precision && + precision < s_len) + s_len = precision; + } + else { + s = S_NULL; + s_len = S_NULL_LEN; + } + pad_char = ' '; + break; + } + + case NUL: + /* if %p ends the string, oh well ignore it */ + continue; + + default: + s = "bogus %p"; + s_len = 8; + prefix_char = NUL; + break; + } + break; + + case NUL: + /* + * The last character of the format string was + * %. We ignore it. + */ + continue; + + + /* + * The default case is for unrecognized %'s. + * We print %<char> to help the user identify what + * option is not understood. + * This is also useful in case the user wants to pass + * the output of format_converter to another function + * that understands some other %<char> (like syslog). + * Note that we can't point s inside fmt because the + * unknown <char> could be preceded by width etc. + */ + default: + char_buf[0] = '%'; + char_buf[1] = *fmt; + s = char_buf; + s_len = 2; + pad_char = ' '; + break; + } + if (prefix_char != NUL && s != S_NULL && + s != char_buf) { + *--s = prefix_char; + s_len++; + } - /* - * The default case is for unrecognized %'s. - * We print %<char> to help the user identify what - * option is not understood. - * This is also useful in case the user wants to pass - * the output of format_converter to another function - * that understands some other %<char> (like syslog). - * Note that we can't point s inside fmt because the - * unknown <char> could be preceded by width etc. - */ - default: - char_buf[0] = '%'; - char_buf[1] = *fmt; - s = char_buf; - s_len = 2; - pad_char = ' '; - break; - } - - if (prefix_char != NUL && s != S_NULL && s != char_buf) { - *--s = prefix_char; - s_len++; - } - - if (adjust_width && adjust == RIGHT && min_width > s_len) { - if (pad_char == '0' && prefix_char != NUL) { - INS_CHAR(*s, sp, bep, cc); - s++; - s_len--; - min_width--; + if (adjust_width && adjust == RIGHT && + min_width > s_len) { + if (pad_char == '0' && prefix_char != NUL) { + INS_CHAR(*s, sp, bep, cc); + s++; + s_len--; + min_width--; + } + PAD(min_width, s_len, pad_char); + } + + /* + * Print the string s. + */ + for (i = s_len; i != 0; i--) { + INS_CHAR(*s, sp, bep, cc); + s++; + } + + if (adjust_width && adjust == LEFT && min_width > s_len) + PAD(min_width, s_len, pad_char); } - PAD(min_width, s_len, pad_char); - } - - /* - * Print the string s. - */ - for (i = s_len; i != 0; i--) { - INS_CHAR(*s, sp, bep, cc); - s++; - } - - if (adjust_width && adjust == LEFT && min_width > s_len) - PAD(min_width, s_len, pad_char); + fmt++; } - fmt++; - } - vbuff->curpos = sp; + vbuff->curpos = sp; - return cc; + return cc; } -static int snprintf_flush(ap_vformatter_buff *vbuff) +static int +snprintf_flush(ap_vformatter_buff *vbuff) { - /* if the buffer fills we have to abort immediately, there is no way - * to "flush" an ap_snprintf... there's nowhere to flush it to. - */ - return -1; + /* if the buffer fills we have to abort immediately, there is no way + * to "flush" an ap_snprintf... there's nowhere to flush it to. + */ + return -1; } -API_EXPORT_NONSTD(int) ap_snprintf(char *buf, size_t len, const char *format,...) +API_EXPORT_NONSTD(int) +ap_snprintf(char *buf, size_t len, const char *format,...) { - int cc; - va_list ap; - ap_vformatter_buff vbuff; - - if (len == 0) - return 0; - - /* save one byte for nul terminator */ - vbuff.curpos = buf; - vbuff.endpos = buf + len - 1; - va_start(ap, format); - cc = ap_vformatter(snprintf_flush, &vbuff, format, ap); - va_end(ap); - *vbuff.curpos = '\0'; - return (cc == -1) ? len : cc; + int cc; + va_list ap; + ap_vformatter_buff vbuff; + + if (len == 0) + return 0; + + /* save one byte for nul terminator */ + vbuff.curpos = buf; + vbuff.endpos = buf + len - 1; + va_start(ap, format); + cc = ap_vformatter(snprintf_flush, &vbuff, format, ap); + va_end(ap); + *vbuff.curpos = '\0'; + return (cc == -1) ? len : cc; } -API_EXPORT(int) ap_vsnprintf(char *buf, size_t len, const char *format, - va_list ap) +API_EXPORT(int) +ap_vsnprintf(char *buf, size_t len, const char *format, va_list ap) { - int cc; - ap_vformatter_buff vbuff; - - if (len == 0) - return 0; - - /* save one byte for nul terminator */ - vbuff.curpos = buf; - vbuff.endpos = buf + len - 1; - cc = ap_vformatter(snprintf_flush, &vbuff, format, ap); - *vbuff.curpos = '\0'; - return (cc == -1) ? len : cc; + int cc; + ap_vformatter_buff vbuff; + + if (len == 0) + return 0; + + /* save one byte for nul terminator */ + vbuff.curpos = buf; + vbuff.endpos = buf + len - 1; + cc = ap_vformatter(snprintf_flush, &vbuff, format, ap); + *vbuff.curpos = '\0'; + return (cc == -1) ? len : cc; } diff --git a/usr.sbin/httpd/src/ap/ap_strtol.c b/usr.sbin/httpd/src/ap/ap_strtol.c index 83d0a2080ad..5471c4aa4a9 100644 --- a/usr.sbin/httpd/src/ap/ap_strtol.c +++ b/usr.sbin/httpd/src/ap/ap_strtol.c @@ -1,3 +1,5 @@ +/* $OpenBSD */ + /* ==================================================================== * The Apache Software License, Version 1.1 * @@ -106,7 +108,8 @@ * upper/lower case A-I, J-R, and S-Z are contiguous.) */ -API_EXPORT(long) ap_strtol(const char *nptr, char **endptr, int base) +API_EXPORT(long) +ap_strtol(const char *nptr, char **endptr, int base) { const char *s; unsigned long acc; @@ -123,7 +126,8 @@ API_EXPORT(long) ap_strtol(const char *nptr, char **endptr, int base) s = nptr; do { c = *s++; - } while (ap_isspace(c)); + } + while (ap_isspace(c)); if (c == '-') { neg = 1; c = *s++; |