aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2011-05-13 11:52:49 +0200
committerTobias Brunner <tobias@strongswan.org>2011-07-06 09:43:45 +0200
commit0b6ff2a9fe52ebcbfab7d72b60a9af5d8712f4f5 (patch)
treec67a532306aa40a9cd97d36220b7a3660d3a0c24 /src
parentfbf014b0c10365d241ff8aeb83618bb929d09f8f (diff)
downloadstrongswan-0b6ff2a9fe52ebcbfab7d72b60a9af5d8712f4f5.tar.bz2
strongswan-0b6ff2a9fe52ebcbfab7d72b60a9af5d8712f4f5.tar.xz
Added a replace function to linked_list_t.
Diffstat (limited to 'src')
-rw-r--r--src/libstrongswan/utils/linked_list.c14
-rw-r--r--src/libstrongswan/utils/linked_list.h10
2 files changed, 24 insertions, 0 deletions
diff --git a/src/libstrongswan/utils/linked_list.c b/src/libstrongswan/utils/linked_list.c
index cc5590e9b..a44bcc13e 100644
--- a/src/libstrongswan/utils/linked_list.c
+++ b/src/libstrongswan/utils/linked_list.c
@@ -476,6 +476,19 @@ METHOD(linked_list_t, insert_after, void,
insert_item_after(this, enumerator->current, item);
}
+METHOD(linked_list_t, replace, void*,
+ private_linked_list_t *this, private_enumerator_t *enumerator,
+ void *item)
+{
+ void *old = NULL;
+ if (enumerator->current)
+ {
+ old = enumerator->current->value;
+ enumerator->current->value = item;
+ }
+ return old;
+}
+
METHOD(linked_list_t, get_last, status_t,
private_linked_list_t *this, void **item)
{
@@ -722,6 +735,7 @@ linked_list_t *linked_list_create()
.insert_last = _insert_last,
.insert_after = (void*)_insert_after,
.insert_before = (void*)_insert_before,
+ .replace = (void*)_replace,
.remove_first = _remove_first,
.remove_last = _remove_last,
.remove = _remove_,
diff --git a/src/libstrongswan/utils/linked_list.h b/src/libstrongswan/utils/linked_list.h
index 25daaab35..54ec48a51 100644
--- a/src/libstrongswan/utils/linked_list.h
+++ b/src/libstrongswan/utils/linked_list.h
@@ -126,6 +126,16 @@ struct linked_list_t {
void *item);
/**
+ * Replaces the item the enumerator currently points to with the given item.
+ *
+ * @param enumerator enumerator with position
+ * @param item item value to replace current item with
+ * @return current item or NULL if the enumerator is at an
+ * invalid position
+ */
+ void *(*replace)(linked_list_t *this, enumerator_t *enumerator, void *item);
+
+ /**
* Remove an item from the list where the enumerator points to.
*
* @param enumerator enumerator with position