X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_persistent_handle_api.c;h=c89c53980d45dc29f26ac682bfdd65b6557da3c8;hp=8fc1b02f72d1a775d9a0a00c256472712774fd2c;hb=accf1817e811a7edabd687ef6105983f39f13942;hpb=fa6e9a361695e1c273266c79d0d27ff19059bb8a diff --git a/http_persistent_handle_api.c b/http_persistent_handle_api.c index 8fc1b02..c89c539 100644 --- a/http_persistent_handle_api.c +++ b/http_persistent_handle_api.c @@ -13,9 +13,9 @@ /* $Id$ */ #include "php_http.h" +#include "php_http_api.h" #ifdef HTTP_HAVE_PERSISTENT_HANDLES - #include "php_http_persistent_handle_api.h" static HashTable http_persistent_handles_hash; @@ -114,28 +114,31 @@ PHP_HTTP_API void _http_persistent_handle_cleanup_ex(const char *name_str, size_ UNLOCK(); } -PHP_HTTP_API int _http_persistent_handle_statall_ex(char ***names, int **counts, int persistent) +PHP_HTTP_API HashTable *_http_persistent_handle_statall_ex(HashTable *ht) { - int i, n; - char *key; + zval *tmp; + HashPosition pos; + HashKey key = initHashKey(0); http_persistent_handles_hash_entry *hentry; LOCK(); - if ((n = zend_hash_num_elements(&http_persistent_handles_hash))) { - *names = safe_pemalloc(n, sizeof(char **), 0, persistent); - *counts = safe_pemalloc(n, sizeof(int), 0, persistent); + if (zend_hash_num_elements(&http_persistent_handles_hash)) { + if (!ht) { + ALLOC_HASHTABLE(ht); + zend_hash_init(ht, 0, NULL, ZVAL_PTR_DTOR, 0); + } - for ( i = 0, zend_hash_internal_pointer_reset(&http_persistent_handles_hash); - HASH_KEY_NON_EXISTANT != zend_hash_get_current_key(&http_persistent_handles_hash, &key, NULL, 0) && - SUCCESS == zend_hash_get_current_data(&http_persistent_handles_hash, (void *) &hentry); - ++i, zend_hash_move_forward(&http_persistent_handles_hash)) { - (*names)[i] = pestrdup(key, persistent); - (*counts)[i] = zend_hash_num_elements(&hentry->list); + FOREACH_HASH_KEYVAL(pos, &http_persistent_handles_hash, key, hentry) { + MAKE_STD_ZVAL(tmp); + ZVAL_LONG(tmp, zend_hash_num_elements(&hentry->list)); + zend_hash_add(ht, key.str, key.len, (void *) &tmp, sizeof(zval *), NULL); } + } else if (ht) { + ht = NULL; } UNLOCK(); - return n; + return ht; } PHP_HTTP_API STATUS _http_persistent_handle_acquire_ex(const char *name_str, size_t name_len, void **handle) @@ -147,7 +150,7 @@ PHP_HTTP_API STATUS _http_persistent_handle_acquire_ex(const char *name_str, siz LOCK(); if (SUCCESS == zend_hash_find(&http_persistent_handles_hash, (char *) name_str, name_len+1, (void *) &hentry)) { - zend_hash_internal_pointer_reset(&hentry->list); + zend_hash_internal_pointer_end(&hentry->list); if ( HASH_KEY_NON_EXISTANT != zend_hash_get_current_key(&hentry->list, NULL, &index, 0) && SUCCESS == zend_hash_get_current_data(&hentry->list, (void *) &lentry)) { *handle = lentry->handle;