Function added to mem_cred_t to add shared secret with a linked list of owners.
authorTobias Brunner <tobias@strongswan.org>
Fri, 19 Nov 2010 16:21:00 +0000 (17:21 +0100)
committerTobias Brunner <tobias@strongswan.org>
Fri, 3 Dec 2010 16:59:59 +0000 (17:59 +0100)
src/libstrongswan/credentials/sets/mem_cred.c
src/libstrongswan/credentials/sets/mem_cred.h

index c29a99f..19dbefa 100644 (file)
@@ -1,4 +1,6 @@
 /*
+ * Copyright (C) 2010 Tobias Brunner
+ * Hochschule fuer Technik Rapperwsil
  * Copyright (C) 2010 Martin Willi
  * Copyright (C) 2010 revosec AG
  *
@@ -342,33 +344,41 @@ METHOD(credential_set_t, create_shared_enumerator, enumerator_t*,
                                                (void*)shared_filter, data, (void*)shared_data_destroy);
 }
 
-METHOD(mem_cred_t, add_shared, void,
-       private_mem_cred_t *this, shared_key_t *shared, ...)
+METHOD(mem_cred_t, add_shared_list, void,
+       private_mem_cred_t *this, shared_key_t *shared, linked_list_t* owners)
 {
        shared_entry_t *entry;
-       identification_t *id;
-       va_list args;
 
        INIT(entry,
                .shared = shared,
-               .owners = linked_list_create(),
+               .owners = owners,
        );
 
+       this->lock->write_lock(this->lock);
+       this->shared->insert_last(this->shared, entry);
+       this->lock->unlock(this->lock);
+}
+
+METHOD(mem_cred_t, add_shared, void,
+       private_mem_cred_t *this, shared_key_t *shared, ...)
+{
+       identification_t *id;
+       linked_list_t *owners = linked_list_create();
+       va_list args;
+
        va_start(args, shared);
        do
        {
                id = va_arg(args, identification_t*);
                if (id)
                {
-                       entry->owners->insert_last(entry->owners, id);
+                       owners->insert_last(owners, id);
                }
        }
        while (id);
        va_end(args);
 
-       this->lock->write_lock(this->lock);
-       this->shared->insert_last(this->shared, entry);
-       this->lock->unlock(this->lock);
+       add_shared_list(this, shared, owners);
 }
 
 METHOD(mem_cred_t, clear_, void,
@@ -419,6 +429,7 @@ mem_cred_t *mem_cred_create()
                        .add_cert = _add_cert,
                        .add_key = _add_key,
                        .add_shared = _add_shared,
+                       .add_shared_list = _add_shared_list,
                        .clear = _clear_,
                        .destroy = _destroy,
                },
index b26e43d..c858ba9 100644 (file)
@@ -1,4 +1,6 @@
 /*
+ * Copyright (C) 2010 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
  * Copyright (C) 2010 Martin Willi
  * Copyright (C) 2010 revosec AG
  *
@@ -24,6 +26,7 @@
 typedef struct mem_cred_t mem_cred_t;
 
 #include <credentials/credential_set.h>
+#include <utils/linked_list.h>
 
 /**
  * Generic in-memory credential set.
@@ -54,11 +57,20 @@ struct mem_cred_t {
         * Add a shared key to the credential set.
         *
         * @param shared                shared key to add, gets owned by set
-        * @param ...                   NULL terminated list of owners identification_t*
+        * @param ...                   NULL terminated list of owners (identification_t*)
         */
        void (*add_shared)(mem_cred_t *this, shared_key_t *shared, ...);
 
        /**
+        * Add a shared key to the credential set.
+        *
+        * @param shared                shared key to add, gets owned by set
+        * @param owners                list of owners (identification_t*), gets owned
+        */
+       void (*add_shared_list)(mem_cred_t *this, shared_key_t *shared,
+                                                       linked_list_t *owners);
+
+       /**
         * Clear all credentials from the credential set.
         */
        void (*clear)(mem_cred_t *this);