? ext-hash.diff.txt Index: config.m4 =================================================================== RCS file: /repository/pecl/hash/config.m4,v retrieving revision 1.2 diff -u -p -d -r1.2 config.m4 --- config.m4 20 Nov 2005 20:14:20 -0000 1.2 +++ config.m4 22 Nov 2005 14:34:42 -0000 @@ -7,4 +7,7 @@ PHP_ARG_ENABLE(hash, whether to enable h if test "$PHP_HASH" != "no"; then AC_DEFINE(HAVE_HASH_EXT,1,[Have HASH Extension]) PHP_NEW_EXTENSION(hash, hash.c hash_md.c hash_sha.c hash_ripemd.c hash_haval.c, $ext_shared) + ifdef([PHP_INSTALL_HEADERS], [ + PHP_INSTALL_HEADERS(ext/hash, php_hash.h php_hash_md.h php_hash_sha.h php_hash_ripemd.h php_hash_haval.h) + ], [ ]) fi Index: hash.c =================================================================== RCS file: /repository/pecl/hash/hash.c,v retrieving revision 1.7 diff -u -p -d -r1.7 hash.c --- hash.c 21 Nov 2005 06:05:37 -0000 1.7 +++ hash.c 22 Nov 2005 14:34:45 -0000 @@ -34,32 +34,29 @@ HashTable php_hash_hashtable; PHP_HASH_API php_hash_ops *php_hash_fetch_ops(const char *algo, int algo_len) { php_hash_ops *ops; + char *lower = estrndup(algo, algo_len); - if (zend_hash_find(&php_hash_hashtable, algo, algo_len + 1, (void**)&ops) == SUCCESS) { - return ops; + zend_str_tolower(lower, algo_len); + if (SUCCESS != zend_hash_find(&php_hash_hashtable, lower, algo_len + 1, (void**)&ops)) { + ops = NULL; } + efree(lower); - return NULL; + return ops; } PHP_HASH_API void php_hash_register_algo(const char *algo, php_hash_ops *ops) { - zend_hash_add(&php_hash_hashtable, algo, strlen(algo) + 1, ops, sizeof(php_hash_ops), NULL); + int algo_len = strlen(algo); + char *lower = estrndup(algo, algo_len); + + zend_str_tolower(lower, algo_len); + zend_hash_add(&php_hash_hashtable, lower, algo_len + 1, ops, sizeof(php_hash_ops), NULL); + efree(lower); } /* Userspace */ -inline void php_hash_bin2hex(char *out, unsigned char *in, int in_len) -{ - static const char hexits[16] = "0123456789abcdef"; - int i; - - for(i = 0; i < in_len; i++) { - out[i * 2] = hexits[in[i] >> 4]; - out[(i * 2) + 1] = hexits[in[i] & 0x0F]; - } -} - static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename) { char *algo, *data, *digest; @@ -258,7 +255,7 @@ PHP_FUNCTION(hash_update_stream) /* }}} */ /* {{{ proto bool hash_update_file(resource context, string filename[, resource context]) -Pump data into the hashing algorithm from an open stream */ +Pump data into the hashing algorithm from a file */ PHP_FUNCTION(hash_update_file) { zval *zhash, *zcontext = NULL; Index: hash_md.c =================================================================== RCS file: /repository/pecl/hash/hash_md.c,v retrieving revision 1.3 diff -u -p -d -r1.3 hash_md.c --- hash_md.c 21 Nov 2005 15:09:57 -0000 1.3 +++ hash_md.c 22 Nov 2005 14:34:45 -0000 @@ -34,14 +34,8 @@ php_hash_ops php_hash_md5_ops = { PHP_HASH_API void make_digest(char *md5str, unsigned char *digest) { - int i; - - for (i = 0; i < 16; i++) { - sprintf(md5str, "%02x", digest[i]); - md5str += 2; - } - - *md5str = '\0'; + php_hash_bin2hex(md5str, digest, 16); + md5str[16] = '\0'; } /* {{{ proto string md5(string str, [ bool raw_output]) Index: hash_sha.c =================================================================== RCS file: /repository/pecl/hash/hash_sha.c,v retrieving revision 1.5 diff -u -p -d -r1.5 hash_sha.c --- hash_sha.c 21 Nov 2005 15:09:58 -0000 1.5 +++ hash_sha.c 22 Nov 2005 14:34:47 -0000 @@ -89,14 +89,8 @@ php_hash_ops php_hash_sha1_ops = { PHP_HASH_API void make_sha1_digest(char *sha1str, unsigned char *digest) { - int i; - - for (i = 0; i < 20; i++) { - sprintf(sha1str, "%02x", digest[i]); - sha1str += 2; - } - - *sha1str = '\0'; + php_hash_bin2hex(sha1str, digest, 20); + sha1str[20] = '\0'; } /* {{{ proto string sha1(string str [, bool raw_output]) Index: php_hash.h =================================================================== RCS file: /repository/pecl/hash/php_hash.h,v retrieving revision 1.4 diff -u -p -d -r1.4 php_hash.h --- php_hash.h 21 Nov 2005 15:09:58 -0000 1.4 +++ php_hash.h 22 Nov 2005 14:34:49 -0000 @@ -95,6 +95,17 @@ extern zend_module_entry hash_module_ent PHP_HASH_API php_hash_ops *php_hash_fetch_ops(const char *algo, int algo_len); PHP_HASH_API void php_hash_register_algo(const char *algo, php_hash_ops *ops); +static inline void php_hash_bin2hex(char *out, unsigned char *in, int in_len) +{ + static const char hexits[16] = "0123456789abcdef"; + int i; + + for(i = 0; i < in_len; i++) { + out[i * 2] = hexits[in[i] >> 4]; + out[(i * 2) + 1] = hexits[in[i] & 0x0F]; + } +} + #endif /* PHP_HASH_H */