]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
linked-list: Remove barely used find_last() method
authorTobias Brunner <tobias@strongswan.org>
Tue, 16 Jul 2013 10:00:57 +0000 (12:00 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 17 Jul 2013 15:42:53 +0000 (17:42 +0200)
src/libhydra/plugins/kernel_klips/kernel_klips_ipsec.c
src/libhydra/plugins/kernel_pfkey/kernel_pfkey_ipsec.c
src/libstrongswan/collections/linked_list.c
src/libstrongswan/collections/linked_list.h
src/libstrongswan/tests/test_linked_list.c

index 38c92ce716fb8674086a3646bca9949be5f7a755..82f80fd4cced45a73abf59839725f6b305dc52eb 100644 (file)
@@ -2022,7 +2022,7 @@ METHOD(kernel_ipsec_t, add_policy, status_t,
        else
        {
                /* apply the new one, if we have no such policy */
-               this->policies->insert_last(this->policies, policy);
+               this->policies->insert_first(this->policies, policy);
        }
 
        if (priority == POLICY_PRIORITY_ROUTED)
@@ -2088,7 +2088,8 @@ METHOD(kernel_ipsec_t, add_policy, status_t,
        this->mutex->lock(this->mutex);
 
        /* we try to find the policy again and install the route if needed */
-       if (this->policies->find_last(this->policies, NULL, (void**)&policy) != SUCCESS)
+       if (this->policies->find_first(this->policies, NULL,
+                                                                 (void**)&policy) != SUCCESS)
        {
                this->mutex->unlock(this->mutex);
                DBG2(DBG_KNL, "the policy %R === %R %N is already gone, ignoring",
index f00210b85120f3d8f29552eb9c8194ef4df68e3f..d975f15b9fe310e306c75bb55612f4f1d1c3ecf5 100644 (file)
@@ -2261,8 +2261,8 @@ static status_t add_policy_internal(private_kernel_pfkey_ipsec_t *this,
 
        /* we try to find the policy again and update the kernel index */
        this->mutex->lock(this->mutex);
-       if (this->policies->find_last(this->policies, NULL,
-                                                                (void**)&policy) != SUCCESS)
+       if (this->policies->find_first(this->policies, NULL,
+                                                                 (void**)&policy) != SUCCESS)
        {
                DBG2(DBG_KNL, "unable to update index, the policy is already gone, "
                                          "ignoring");
@@ -2319,7 +2319,7 @@ METHOD(kernel_ipsec_t, add_policy, status_t,
        }
        else
        {       /* use the new one, if we have no such policy */
-               this->policies->insert_last(this->policies, policy);
+               this->policies->insert_first(this->policies, policy);
                policy->used_by = linked_list_create();
        }
 
index 7594ddf222845f3a2c567e40cfe64c0b56cbfc68..4feb66fcfa16f3e20b44d9ec05a0317d2a68fb65 100644 (file)
@@ -395,28 +395,6 @@ METHOD(linked_list_t, find_first, status_t,
        return NOT_FOUND;
 }
 
-METHOD(linked_list_t, find_last, status_t,
-       private_linked_list_t *this, linked_list_match_t match,
-       void **item, void *d1, void *d2, void *d3, void *d4, void *d5)
-{
-       element_t *current = this->last;
-
-       while (current)
-       {
-               if ((match && match(current->value, d1, d2, d3, d4, d5)) ||
-                       (!match && item && current->value == *item))
-               {
-                       if (item != NULL)
-                       {
-                               *item = current->value;
-                       }
-                       return SUCCESS;
-               }
-               current = current->previous;
-       }
-       return NOT_FOUND;
-}
-
 METHOD(linked_list_t, invoke_offset, void,
        private_linked_list_t *this, size_t offset,
        void *d1, void *d2, void *d3, void *d4, void *d5)
@@ -538,7 +516,6 @@ linked_list_t *linked_list_create()
                        .get_first = _get_first,
                        .get_last = _get_last,
                        .find_first = (void*)_find_first,
-                       .find_last = (void*)_find_last,
                        .insert_first = _insert_first,
                        .insert_last = _insert_last,
                        .insert_before = (void*)_insert_before,
index 993ff10f8406b1f19bb0ecb65021078d6ff74443..9feced07aee7bc945d8d74acbd722b1783e13f97 100644 (file)
@@ -192,27 +192,6 @@ struct linked_list_t {
        status_t (*find_first) (linked_list_t *this, linked_list_match_t match,
                                                        void **item, ...);
 
-       /**
-        * Find the last matching element in the list.
-        *
-        * The first object passed to the match function is the current list item,
-        * followed by the user supplied data.
-        * If the supplied function returns TRUE this function returns SUCCESS, and
-        * the current object is returned in the third parameter, otherwise,
-        * the next item is checked.
-        *
-        * If match is NULL, *item and the current object are compared.
-        *
-        * @warning Only use pointers as user supplied data.
-        *
-        * @param match                 comparison function to call on each object, or NULL
-        * @param item                  the list item, if found
-        * @param ...                   user data to supply to match function (limited to 5 arguments)
-        * @return                              SUCCESS if found, NOT_FOUND otherwise
-        */
-       status_t (*find_last) (linked_list_t *this, linked_list_match_t match,
-                                                  void **item, ...);
-
        /**
         * Invoke a method on all of the contained objects.
         *
index fc055bb7f3cbd80bed340e605c496a7e4243005e..aeee48ff809f47470a91b6fd375ca624697cae9a 100644 (file)
@@ -195,20 +195,14 @@ START_TEST(test_find)
        void *a = (void*)1, *b = (void*)2;
 
        ck_assert(list->find_first(list, NULL, &a) == NOT_FOUND);
-       ck_assert(list->find_last(list, NULL, &a) == NOT_FOUND);
        list->insert_last(list, a);
        ck_assert(list->find_first(list, NULL, &a) == SUCCESS);
        ck_assert(list->find_first(list, NULL, &b) == NOT_FOUND);
-       ck_assert(list->find_last(list, NULL, &a) == SUCCESS);
-       ck_assert(list->find_last(list, NULL, &b) == NOT_FOUND);
        list->insert_last(list, b);
        ck_assert(list->find_first(list, NULL, &a) == SUCCESS);
        ck_assert(list->find_first(list, NULL, &b) == SUCCESS);
-       ck_assert(list->find_last(list, NULL, &a) == SUCCESS);
-       ck_assert(list->find_last(list, NULL, &b) == SUCCESS);
 
        ck_assert(list->find_first(list, NULL, NULL) == NOT_FOUND);
-       ck_assert(list->find_last(list, NULL, NULL) == NOT_FOUND);
 }
 END_TEST
 
@@ -228,31 +222,14 @@ START_TEST(test_find_callback)
        ck_assert(list->find_first(list, (linked_list_match_t)match_a_b, &x, a, b) == SUCCESS);
        ck_assert(a == x);
 
-       ck_assert(list->find_last(list, (linked_list_match_t)match_a, NULL, a) == SUCCESS);
-       x = NULL;
-       ck_assert(list->find_last(list, (linked_list_match_t)match_a, &x, a) == SUCCESS);
-       ck_assert(a == x);
-       ck_assert(list->find_last(list, (linked_list_match_t)match_b, &x, b) == NOT_FOUND);
-       ck_assert(a == x);
-       x = NULL;
-       ck_assert(list->find_last(list, (linked_list_match_t)match_a_b, &x, a, b) == SUCCESS);
-       ck_assert(a == x);
-
        list->insert_last(list, b);
        ck_assert(list->find_first(list, (linked_list_match_t)match_a, &x, a) == SUCCESS);
        ck_assert(a == x);
        ck_assert(list->find_first(list, (linked_list_match_t)match_b, &x, b) == SUCCESS);
        ck_assert(b == x);
-       ck_assert(list->find_last(list, (linked_list_match_t)match_a, &x, a) == SUCCESS);
-       ck_assert(a == x);
-       ck_assert(list->find_last(list, (linked_list_match_t)match_b, &x, b) == SUCCESS);
-       ck_assert(b == x);
        x = NULL;
        ck_assert(list->find_first(list, (linked_list_match_t)match_a_b, &x, a, b) == SUCCESS);
        ck_assert(a == x);
-       x = NULL;
-       ck_assert(list->find_last(list, (linked_list_match_t)match_a_b, &x, a, b) == SUCCESS);
-       ck_assert(b == x);
 }
 END_TEST