aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/utils
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2006-02-08 15:25:34 +0000
committerMartin Willi <martin@strongswan.org>2006-02-08 15:25:34 +0000
commitc06dbbabd1498d614d4db88bb4205e2afcd6dab8 (patch)
tree694e4df33baf70813367276b6956d9e6a714742e /Source/charon/utils
parent384efc76d58eea98648988045de413a6cc027dff (diff)
downloadstrongswan-c06dbbabd1498d614d4db88bb4205e2afcd6dab8.tar.bz2
strongswan-c06dbbabd1498d614d4db88bb4205e2afcd6dab8.tar.xz
- fixed alot of bugs in child_proposal
- near to working state ;-)
Diffstat (limited to 'Source/charon/utils')
-rw-r--r--Source/charon/utils/linked_list.c28
-rw-r--r--Source/charon/utils/linked_list.h22
2 files changed, 45 insertions, 5 deletions
diff --git a/Source/charon/utils/linked_list.c b/Source/charon/utils/linked_list.c
index 69e0ffc12..f3e686a5a 100644
--- a/Source/charon/utils/linked_list.c
+++ b/Source/charon/utils/linked_list.c
@@ -360,6 +360,23 @@ static int get_count(private_linked_list_t *this)
return this->count;
}
+/**
+ * Implementation of linked_list_t.call_on_items.
+ */
+static void call_on_items(private_linked_list_t *this, void(*func)(void*))
+{
+ iterator_t *iterator;
+ void *item;
+
+ iterator = this->public.create_iterator(&(this->public),TRUE);
+
+ while (iterator->has_next(iterator))
+ {
+ iterator->current(iterator, &item);
+ (*func)(item);
+ }
+ iterator->destroy(iterator);
+}
/**
* Implementation of linked_list_t.insert_first.
@@ -408,7 +425,10 @@ static status_t remove_first(private_linked_list_t *this, void **item)
}
this->first = element->next;
- *item = element->value;
+ if (item != NULL)
+ {
+ *item = element->value;
+ }
this->count--;
@@ -478,7 +498,10 @@ static status_t remove_last(private_linked_list_t *this, void **item)
}
this->last = element->previous;
- *item = element->value;
+ if (item != NULL)
+ {
+ *item = element->value;
+ }
this->count--;
@@ -649,6 +672,7 @@ linked_list_t *linked_list_create()
this->public.get_count = (int (*) (linked_list_t *)) get_count;
this->public.create_iterator = (iterator_t * (*) (linked_list_t *,bool )) create_iterator;
+ this->public.call_on_items = (void (*) (linked_list_t *, void(*func)(void*)))call_on_items;
this->public.get_first = (status_t (*) (linked_list_t *, void **item)) get_first;
this->public.get_last = (status_t (*) (linked_list_t *, void **item)) get_last;
this->public.insert_first = (void (*) (linked_list_t *, void *item)) insert_first;
diff --git a/Source/charon/utils/linked_list.h b/Source/charon/utils/linked_list.h
index 113d64260..8647f064d 100644
--- a/Source/charon/utils/linked_list.h
+++ b/Source/charon/utils/linked_list.h
@@ -64,6 +64,22 @@ struct linked_list_t {
* @return new iterator_t object
*/
iterator_t * (*create_iterator) (linked_list_t *linked_list, bool forward);
+
+ /**
+ * @brief Call a function with list element as argument.
+ *
+ * This method accepts a function, which will be called for
+ * each list element once. The function must accept the list
+ * element as the first argument. Handy for destruction of
+ * list elements.
+ *
+ * @todo Additional vararg which are passed to the
+ * function would be nice...
+ *
+ * @param linked_list calling object
+ * @param func function to call
+ */
+ void (*call_on_items) (linked_list_t *linked_list, void(*func)(void*));
/**
* @brief Inserts a new item at the beginning of the list.
@@ -77,7 +93,7 @@ struct linked_list_t {
* @brief Removes the first item in the list and returns its value.
*
* @param linked_list calling object
- * @param[out] item returned value of first item
+ * @param[out] item returned value of first item, or NULL
* @return
* - SUCCESS
* - NOT_FOUND, if list is empty
@@ -143,7 +159,7 @@ struct linked_list_t {
* @brief Removes the last item in the list and returns its value.
*
* @param linked_list calling object
- * @param[out] item item returned value of last item
+ * @param[out] item returned value of last item, or NULL
* @return
* - SUCCESS
* - NOT_FOUND if list is empty
@@ -154,7 +170,7 @@ struct linked_list_t {
* @brief Returns the value of the last list item without removing it.
*
* @param linked_list calling object
- * @param[out] item item returned value of last item
+ * @param[out] item returned value of last item
* @return
* - SUCCESS
* - NOT_FOUND if list is empty