]> granicus.if.org Git - php/commitdiff
add support for mhash 0.5.0
authorSascha Schumann <sas@php.net>
Fri, 21 May 1999 20:09:23 +0000 (20:09 +0000)
committerSascha Schumann <sas@php.net>
Fri, 21 May 1999 20:09:23 +0000 (20:09 +0000)
see http://sasweb.de/mhash/

ext/mhash/config.m4
ext/mhash/mhash.c
ext/mhash/php_mhash.h

index 0678f8701c3de9b6c8e81f21dd5a506e658c58d8..5a19821462d50a3bebdc15965dce3f3d7283c9df 100644 (file)
@@ -8,7 +8,7 @@ AC_ARG_WITH(mhash,
                           install directory.],
 [
   if test "$withval" != "no"; then
-    for i in /usr/local /usr $withval; do
+    for i in /usr/local /usr /opt/mhash $withval; do
       if test -f $i/include/mhash.h; then
         MHASH_DIR=$i
       fi
index 6d031a694fcf133ec0e84dbb0e1b4e74387971c1..c6894abac0c03300facb7f0df64a471152699abd 100644 (file)
@@ -37,6 +37,8 @@
 
 function_entry mhash_functions[] = {
        PHP_FE(mhash_get_block_size, NULL)
+       PHP_FE(mhash_get_hash_name, NULL)
+       PHP_FE(mhash_count, NULL)
        PHP_FE(mhash, NULL)
        {0},
 };
@@ -52,26 +54,33 @@ zend_module_entry mhash_module_entry = {
        STANDARD_MODULE_PROPERTIES,
 };
 
-#define MHASH_FAILED "mhash initialization failed"
-
-#define MHASH_ENTRY(a) REGISTER_LONG_CONSTANT("MHASH_" #a, a, 0)
+#define MHASH_FAILED_MSG "mhash initialization failed"
 
 static int php_minit_mhash(INIT_FUNC_ARGS)
 {
-       /* hashes */
-       MHASH_ENTRY(CRC32);
-       MHASH_ENTRY(MD5);
-       MHASH_ENTRY(SHA1);
-       MHASH_ENTRY(HAVAL);
-       MHASH_ENTRY(RIPEMD128);
-       MHASH_ENTRY(RIPEMD160);
-       MHASH_ENTRY(TIGER);
-       MHASH_ENTRY(SNEFRU);
-       MHASH_ENTRY(GOST);
+       int i;
+       char *name;
+       char buf[128];
+
+       for(i = 0; i <= mhash_count(); i++) {
+               name = mhash_get_hash_name(i);
+               if(name) {
+                       snprintf(buf, 127, "MHASH_%s", name);
+                       REGISTER_LONG_CONSTANT(buf, i, 0);
+                       free(name);
+               }
+       }
        
        return SUCCESS;
 }
 
+/* proto mhash_count()
+   get the number of available hashes */
+PHP_FUNCTION(mhash_count)
+{
+       RETURN_LONG(mhash_count());
+}
+
 /* proto mhash_get_block_size(int hash)
    get the block size of hash */
 PHP_FUNCTION(mhash_get_block_size)
@@ -87,12 +96,34 @@ PHP_FUNCTION(mhash_get_block_size)
        RETURN_LONG(mhash_get_block_size(hash->value.lval));
 }
 
+/* proto mhash_get_hash_name(int hash)
+   get the name of hash */
+PHP_FUNCTION(mhash_get_hash_name)
+{
+       pval *hash;
+       char *name;
+
+       if(ARG_COUNT(ht) != 1 || getParameters(ht, 1, &hash) == FAILURE) {
+               WRONG_PARAM_COUNT;
+       }
+
+       convert_to_long(hash);
+
+       name = mhash_get_hash_name(hash->value.lval);
+       if(name) {
+               RETVAL_STRING(name, 1);
+               free(name);
+       } else {
+               RETVAL_FALSE;
+       }
+}
+
 /* proto mhash(int hash, string data)
    hash data with hash */
 PHP_FUNCTION(mhash)
 {
        pval *hash, *data;
-       int td;
+       MHASH td;
        int bsize;
        unsigned char *hash_data;
        int i;
@@ -105,15 +136,15 @@ PHP_FUNCTION(mhash)
        convert_to_string(data);
 
        bsize = mhash_get_block_size(hash->value.lval);
-       td = init_mhash(hash->value.lval);
-       if(td == -1) {
-               php3_error(E_WARNING, MHASH_FAILED);
+       td = mhash_init(hash->value.lval);
+       if(td == MHASH_FAILED) {
+               php3_error(E_WARNING, MHASH_FAILED_MSG);
                RETURN_FALSE;
        }
 
        mhash(td, data->value.str.val, data->value.str.len);
 
-       hash_data = (char *) end_mhash(td);
+       hash_data = (unsigned char *) mhash_end(td);
        
        RETVAL_STRINGL(hash_data, bsize, 1);
        
index f2ce9d4cbcc295fc5c974f1222adfc10eefc20b3..e5341151d5103dab8e5d0d0fedf4961ab5deb7c3 100644 (file)
@@ -13,6 +13,8 @@ extern zend_module_entry mhash_module_entry;
 #define mhash_module_ptr &mhash_module_entry
 
 PHP_FUNCTION(mhash_get_block_size);
+PHP_FUNCTION(mhash_get_hash_name);
+PHP_FUNCTION(mhash_count);
 PHP_FUNCTION(mhash);
 
 #else