]> granicus.if.org Git - php/commitdiff
Expose registered hashing algos
authorSara Golemon <pollita@php.net>
Sat, 19 Nov 2005 20:13:08 +0000 (20:13 +0000)
committerSara Golemon <pollita@php.net>
Sat, 19 Nov 2005 20:13:08 +0000 (20:13 +0000)
ext/hash/hash.c

index 01cb5af7011df40cf80ddbee07b5dd30fd48e9de..f6d5650b14b948a8e4baa22d420b2812d71cf4e0 100644 (file)
@@ -282,6 +282,24 @@ PHP_FUNCTION(hash_final)
 }
 /* }}} */
 
+/* {{{ proto array hash_algos(void)
+Return a list of registered hashing algorithms */
+PHP_FUNCTION(hash_algos)
+{
+       HashPosition pos;
+       char *str;
+       int str_len;
+       long idx, type;
+
+       array_init(return_value);
+       for(zend_hash_internal_pointer_reset_ex(&php_hash_hashtable, &pos);
+               (type = zend_hash_get_current_key_ex(&php_hash_hashtable, &str, &str_len, &idx, 0, &pos)) != HASH_KEY_NON_EXISTANT;
+               zend_hash_move_forward_ex(&php_hash_hashtable, &pos)) {
+               add_next_index_stringl(return_value, str, str_len, 1);
+       }
+}
+/* }}} */
+
 /* Module Housekeeping */
 
 static void php_hash_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
@@ -337,13 +355,14 @@ PHP_MSHUTDOWN_FUNCTION(hash)
  */
 PHP_MINFO_FUNCTION(hash)
 {
+       HashPosition pos;
        char buffer[2048];
        char *s = buffer, *e = s + sizeof(buffer), *str;
        long idx, type;
 
-       for(zend_hash_internal_pointer_reset(&php_hash_hashtable);
-               (type = zend_hash_get_current_key(&php_hash_hashtable, &str, &idx, 0)) != HASH_KEY_NON_EXISTANT;
-               zend_hash_move_forward(&php_hash_hashtable)) {
+       for(zend_hash_internal_pointer_reset_ex(&php_hash_hashtable, &pos);
+               (type = zend_hash_get_current_key_ex(&php_hash_hashtable, &str, NULL, &idx, 0, &pos)) != HASH_KEY_NON_EXISTANT;
+               zend_hash_move_forward_ex(&php_hash_hashtable, &pos)) {
                s += snprintf(s, e - s, "%s, ", str);
        }
 
@@ -367,6 +386,8 @@ function_entry hash_functions[] = {
        PHP_FE(hash_update,                                                             NULL)
        PHP_FE(hash_final,                                                              NULL)
 
+       PHP_FE(hash_algos,                                                              NULL)
+
        /* BC Land */
 #ifdef PHP_HASH_MD5_NOT_IN_CORE
        PHP_NAMED_FE(md5, php_if_md5,                                   NULL)