diff options
author | Tobias Brunner <tobias@strongswan.org> | 2011-06-09 09:49:28 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2011-07-06 09:43:46 +0200 |
commit | 2bf9d39da64382e143b7201ec12888e42279da93 (patch) | |
tree | 236da89468b4e1d786d08abdf0f45450b1500e1d /src | |
parent | c225f9b5585e1589d98a77b089924a8d4a70e216 (diff) | |
download | strongswan-2bf9d39da64382e143b7201ec12888e42279da93.tar.bz2 strongswan-2bf9d39da64382e143b7201ec12888e42279da93.tar.xz |
Make sure the enumerator stops after all items have been enumerated.
This also changes how insert_before behaves, before enumeration items
are inserted first, after enumeration last.
Diffstat (limited to 'src')
-rw-r--r-- | src/libstrongswan/utils/linked_list.c | 20 | ||||
-rw-r--r-- | src/libstrongswan/utils/linked_list.h | 7 |
2 files changed, 23 insertions, 4 deletions
diff --git a/src/libstrongswan/utils/linked_list.c b/src/libstrongswan/utils/linked_list.c index aaea530bb..e4c1a3308 100644 --- a/src/libstrongswan/utils/linked_list.c +++ b/src/libstrongswan/utils/linked_list.c @@ -110,11 +110,20 @@ struct private_enumerator_t { * current item */ element_t *current; + + /** + * enumerator has enumerated all items + */ + bool finished; }; METHOD(enumerator_t, enumerate, bool, private_enumerator_t *this, void **item) { + if (this->finished) + { + return FALSE; + } if (!this->current) { this->current = this->list->first; @@ -125,6 +134,7 @@ METHOD(enumerator_t, enumerate, bool, } if (!this->current) { + this->finished = TRUE; return FALSE; } *item = this->current->value; @@ -151,6 +161,7 @@ METHOD(linked_list_t, reset_enumerator, void, private_linked_list_t *this, private_enumerator_t *enumerator) { enumerator->current = NULL; + enumerator->finished = FALSE; } METHOD(linked_list_t, get_count, int, @@ -267,7 +278,14 @@ METHOD(linked_list_t, insert_before, void, current = enumerator->current; if (!current) { - this->public.insert_last(&this->public, item); + if (enumerator->finished) + { + this->public.insert_last(&this->public, item); + } + else + { + this->public.insert_first(&this->public, item); + } return; } element = element_create(item); diff --git a/src/libstrongswan/utils/linked_list.h b/src/libstrongswan/utils/linked_list.h index 47c003d32..cb3d53e58 100644 --- a/src/libstrongswan/utils/linked_list.h +++ b/src/libstrongswan/utils/linked_list.h @@ -95,9 +95,10 @@ struct linked_list_t { /** * Inserts a new item before the item the enumerator currently points to. * - * If the enumerator's position is invalid, e.g. at the end of the list, - * the item is inserted last. This is helpful when inserting items into a - * sorted list. + * If this method is called before starting the enumeration the item is + * inserted first. If it is called after all items have been enumerated + * the item is inserted last. This is helpful when inserting items into + * a sorted list. * * @note The position of the enumerator is not changed. * |