From: Sara Golemon Date: Sat, 19 Nov 2005 20:13:08 +0000 (+0000) Subject: Expose registered hashing algos X-Git-Tag: RELEASE_2_0_2~161 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ef378683789d09b0ab9743c5ed770ec8b464ca1f;p=php Expose registered hashing algos --- diff --git a/ext/hash/hash.c b/ext/hash/hash.c index 01cb5af701..f6d5650b14 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -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)