summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Wallner <mike@php.net>2005-11-22 19:17:58 +0000
committerMichael Wallner <mike@php.net>2005-11-22 19:17:58 +0000
commit4c61cf6f4cb2418cdfb14fe04bc703d7a3f9dcab (patch)
tree89027db5ec395d10370d3816689980f87f74e389
parent066fb72fdd263147aa6b691fa7d68451f66b3225 (diff)
downloadphp-git-4c61cf6f4cb2418cdfb14fe04bc703d7a3f9dcab.tar.gz
- install extension headers
- make the hash algo registry case insensitive - "export" inline php_hash_bin2hex
-rw-r--r--ext/hash/config.m43
-rw-r--r--ext/hash/hash.c29
-rw-r--r--ext/hash/hash_md.c10
-rw-r--r--ext/hash/hash_sha.c10
-rw-r--r--ext/hash/php_hash.h11
5 files changed, 31 insertions, 32 deletions
diff --git a/ext/hash/config.m4 b/ext/hash/config.m4
index e2deffaff0..a8380594c0 100644
--- a/ext/hash/config.m4
+++ b/ext/hash/config.m4
@@ -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
diff --git a/ext/hash/hash.c b/ext/hash/hash.c
index 16976dc521..1ab49fdd10 100644
--- a/ext/hash/hash.c
+++ b/ext/hash/hash.c
@@ -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;
diff --git a/ext/hash/hash_md.c b/ext/hash/hash_md.c
index dbcf532dc7..dbed4bb9f9 100644
--- a/ext/hash/hash_md.c
+++ b/ext/hash/hash_md.c
@@ -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])
diff --git a/ext/hash/hash_sha.c b/ext/hash/hash_sha.c
index 09734acb7f..2d1e4c7a94 100644
--- a/ext/hash/hash_sha.c
+++ b/ext/hash/hash_sha.c
@@ -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])
diff --git a/ext/hash/php_hash.h b/ext/hash/php_hash.h
index 0b50c3c084..f6d932286f 100644
--- a/ext/hash/php_hash.h
+++ b/ext/hash/php_hash.h
@@ -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 */