diff options
-rw-r--r-- | include/ap_mmn.h | 3 | ||||
-rw-r--r-- | include/httpd.h | 8 | ||||
-rw-r--r-- | server/util.c | 13 | ||||
-rw-r--r-- | server/util_md5.c | 10 |
4 files changed, 25 insertions, 9 deletions
diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 538794f8dc..381d709d65 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -407,6 +407,7 @@ * 20120724.7 (2.5.0-dev) Add min_http_version/max_http_version to * core_server_config * 20120724.8 (2.5.0-dev) Add conn_log_level to core_server_config + * 20120724.9 (2.5.0-dev) Add ap_bin2hex() */ #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */ @@ -414,7 +415,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20120724 #endif -#define MODULE_MAGIC_NUMBER_MINOR 8 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 9 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/httpd.h b/include/httpd.h index c117ccf82e..4d12b3d506 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -2251,6 +2251,14 @@ AP_DECLARE(void) ap_get_sload(ap_sload_t *ld); */ AP_DECLARE(void) ap_get_loadavg(ap_loadavg_t *ld); +/** + * Convert binary data into a hex string + * @param src pointer to the data + * @param srclen length of the data + * @param dest pointer to buffer of length (2 * srclen + 1). The resulting + * string will be NUL-terminated. + */ +AP_DECLARE(void) ap_bin2hex(const void *src, apr_size_t srclen, char *dest); #define AP_NORESTART APR_OS_START_USEERR + 1 diff --git a/server/util.c b/server/util.c index 36c2784091..3b14e101a0 100644 --- a/server/util.c +++ b/server/util.c @@ -1958,6 +1958,19 @@ AP_DECLARE(apr_size_t) ap_escape_errorlog_item(char *dest, const char *source, return (d - (unsigned char *)dest); } +AP_DECLARE(void) ap_bin2hex(const void *src, apr_size_t srclen, char *dest) +{ + const unsigned char *in = src; + unsigned char *out = (unsigned char *)dest; + apr_size_t i; + + for (i = 0; i < srclen; i++) { + *out++ = c2x_table[in[i] >> 4]; + *out++ = c2x_table[in[i] & 0xf]; + } + *out = '\0'; +} + AP_DECLARE(int) ap_is_directory(apr_pool_t *p, const char *path) { apr_finfo_t finfo; diff --git a/server/util_md5.c b/server/util_md5.c index 83bfa75741..148c60ceb4 100644 --- a/server/util_md5.c +++ b/server/util_md5.c @@ -52,11 +52,9 @@ AP_DECLARE(char *) ap_md5_binary(apr_pool_t *p, const unsigned char *buf, int length) { - const char *hex = "0123456789abcdef"; apr_md5_ctx_t my_md5; unsigned char hash[APR_MD5_DIGESTSIZE]; - char *r, result[33]; /* (MD5_DIGESTSIZE * 2) + 1 */ - int i; + char result[2 * APR_MD5_DIGESTSIZE + 1]; /* * Take the MD5 hash of the string argument. @@ -69,11 +67,7 @@ AP_DECLARE(char *) ap_md5_binary(apr_pool_t *p, const unsigned char *buf, int le apr_md5_update(&my_md5, buf, (unsigned int)length); apr_md5_final(hash, &my_md5); - for (i = 0, r = result; i < APR_MD5_DIGESTSIZE; i++) { - *r++ = hex[hash[i] >> 4]; - *r++ = hex[hash[i] & 0xF]; - } - *r = '\0'; + ap_bin2hex(hash, APR_MD5_DIGESTSIZE, result); return apr_pstrndup(p, result, APR_MD5_DIGESTSIZE*2); } |