From: Martin Willi Date: Fri, 5 Dec 2008 10:01:52 +0000 (-0000) Subject: hashtable enumerator enumerates over both, key and values X-Git-Tag: 4.2.10~47 X-Git-Url: https://git.strongswan.org/?p=strongswan.git;a=commitdiff_plain;h=19e0010f51f871f9eb8e3c0b2bc451d7f32e556c hashtable enumerator enumerates over both, key and values --- diff --git a/src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c b/src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c index 8c472f2..acd5989 100644 --- a/src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c +++ b/src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c @@ -1751,7 +1751,7 @@ static void destroy(private_kernel_netlink_ipsec_t *this) close(this->socket_xfrm_events); this->socket_xfrm->destroy(this->socket_xfrm); enumerator = this->policies->create_enumerator(this->policies); - while (enumerator->enumerate(enumerator, (void**)&policy)) + while (enumerator->enumerate(enumerator, &policy, &policy)) { free(policy); } diff --git a/src/libstrongswan/utils/hashtable.c b/src/libstrongswan/utils/hashtable.c index 22ddeb1..9742921 100644 --- a/src/libstrongswan/utils/hashtable.c +++ b/src/libstrongswan/utils/hashtable.c @@ -322,16 +322,18 @@ static u_int get_count(private_hashtable_t *this) /** * Implementation of private_enumerator_t.enumerator.enumerate. */ -static bool enumerate(private_enumerator_t *this, void **item) +static bool enumerate(private_enumerator_t *this, void **key, void **value) { while (this->row < this->table->capacity) { if (this->current) { pair_t *pair; - if (this->current->enumerate(this->current, (void**)&pair)) + + if (this->current->enumerate(this->current, &pair)) { - *item = pair->value; + *key = pair->key; + *value = pair->value; return TRUE; } this->current->destroy(this->current); @@ -340,6 +342,7 @@ static bool enumerate(private_enumerator_t *this, void **item) else { linked_list_t *list; + if ((list = this->table->table[this->row]) != NULL) { this->current = list->create_enumerator(list); diff --git a/src/libstrongswan/utils/hashtable.h b/src/libstrongswan/utils/hashtable.h index f32da79..8e58d2e 100644 --- a/src/libstrongswan/utils/hashtable.h +++ b/src/libstrongswan/utils/hashtable.h @@ -52,9 +52,9 @@ typedef bool (*hashtable_equals_t)(void *key, void *other_key); struct hashtable_t { /** - * Create an enumerator over the hash table. + * Create an enumerator over the hash table key/value pairs. * - * @return enumerator over hash table entries + * @return enumerator over (void *key, void *value) */ enumerator_t *(*create_enumerator) (hashtable_t *this);