From 5bbfd264ec7580f21cd50ecc3f07c31d1d530939 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Wed, 6 May 2009 11:09:57 +0200 Subject: [PATCH] fixed remove_child_cfg(), use correct enumerator for remove_at --- src/charon/config/peer_cfg.c | 45 +++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/src/charon/config/peer_cfg.c b/src/charon/config/peer_cfg.c index c54333178..da796d6a2 100644 --- a/src/charon/config/peer_cfg.c +++ b/src/charon/config/peer_cfg.c @@ -197,14 +197,40 @@ static void add_child_cfg(private_peer_cfg_t *this, child_cfg_t *child_cfg) this->mutex->unlock(this->mutex); } +/** + * child_cfg enumerator + */ +typedef struct { + enumerator_t public; + enumerator_t *wrapped; + mutex_t *mutex; +} child_cfg_enumerator_t; + /** * Implementation of peer_cfg_t.remove_child_cfg. */ -static void remove_child_cfg(private_peer_cfg_t *this, enumerator_t *enumerator) +static void remove_child_cfg(private_peer_cfg_t *this, + child_cfg_enumerator_t *enumerator) +{ + this->child_cfgs->remove_at(this->child_cfgs, enumerator->wrapped); +} + +/** + * Implementation of child_cfg_enumerator_t.destroy + */ +static void child_cfg_enumerator_destroy(child_cfg_enumerator_t *this) { - this->mutex->lock(this->mutex); - this->child_cfgs->remove_at(this->child_cfgs, enumerator); this->mutex->unlock(this->mutex); + this->wrapped->destroy(this->wrapped); + free(this); +} + +/** + * Implementation of child_cfg_enumerator_t.enumerate + */ +static bool child_cfg_enumerate(child_cfg_enumerator_t *this, child_cfg_t **chd) +{ + return this->wrapped->enumerate(this->wrapped, chd); } /** @@ -212,12 +238,15 @@ static void remove_child_cfg(private_peer_cfg_t *this, enumerator_t *enumerator) */ static enumerator_t* create_child_cfg_enumerator(private_peer_cfg_t *this) { - enumerator_t *enumerator; - + child_cfg_enumerator_t *enumerator = malloc_thing(child_cfg_enumerator_t); + + enumerator->public.enumerate = (void*)child_cfg_enumerate; + enumerator->public.destroy = (void*)child_cfg_enumerator_destroy; + enumerator->mutex = this->mutex; + enumerator->wrapped = this->child_cfgs->create_enumerator(this->child_cfgs); + this->mutex->lock(this->mutex); - enumerator = this->child_cfgs->create_enumerator(this->child_cfgs); - return enumerator_create_cleaner(enumerator, - (void*)this->mutex->unlock, this->mutex); + return &enumerator->public; } /**