]> granicus.if.org Git - php/commitdiff
- install extension headers
authorMichael Wallner <mike@php.net>
Tue, 22 Nov 2005 19:17:58 +0000 (19:17 +0000)
committerMichael Wallner <mike@php.net>
Tue, 22 Nov 2005 19:17:58 +0000 (19:17 +0000)
- make the hash algo registry case insensitive
- "export" inline php_hash_bin2hex

ext/hash/config.m4
ext/hash/hash.c
ext/hash/hash_md.c
ext/hash/hash_sha.c
ext/hash/php_hash.h

index e2deffaff0fb01cb0dbb00cdff89b9dbc60b8c94..a8380594c0371652552cd8f282a59e8b5d09deb4 100644 (file)
@@ -7,4 +7,7 @@ PHP_ARG_ENABLE(hash, whether to enable hash support,
 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 16976dc521b4e557b9749538544eb27c0dafab28..1ab49fdd10893eb672bea82f908c47e0b06db3c7 100644 (file)
@@ -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 dbcf532dc7049ef77bbd0bb330a91d7b43d0d9d6..dbed4bb9f98b4b3f230a16f795e76e730ca3ef6e 100644 (file)
@@ -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 09734acb7f4420da02d67bccd31fedd07b391fbb..2d1e4c7a94e1e389b305d0a8ef28e02aeed5ae48 100644 (file)
@@ -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 0b50c3c084c457fc85b93e7a5d7d2ba3e4e5bee8..f6d932286fb7466098196e636b1c8452e5c7fa7f 100644 (file)
@@ -95,6 +95,17 @@ extern zend_module_entry hash_module_entry;
 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 */