Added function to clear all credentials from mem_cred_t.
authorTobias Brunner <tobias@strongswan.org>
Fri, 24 Sep 2010 12:33:39 +0000 (14:33 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 14 Oct 2010 15:36:19 +0000 (17:36 +0200)
src/libstrongswan/credentials/sets/mem_cred.c
src/libstrongswan/credentials/sets/mem_cred.h

index f1d40dd..cabbdae 100644 (file)
@@ -361,15 +361,31 @@ METHOD(mem_cred_t, add_shared, void,
        this->lock->unlock(this->lock);
 }
 
-METHOD(mem_cred_t, destroy, void,
+METHOD(mem_cred_t, clear, void,
        private_mem_cred_t *this)
 {
+       this->lock->write_lock(this->lock);
        this->trusted->destroy_offset(this->trusted,
-                                                               offsetof(certificate_t, destroy));
+                                                                 offsetof(certificate_t, destroy));
        this->untrusted->destroy_offset(this->untrusted,
-                                                               offsetof(certificate_t, destroy));
+                                                                       offsetof(certificate_t, destroy));
        this->keys->destroy_offset(this->keys, offsetof(private_key_t, destroy));
        this->shared->destroy_function(this->shared, (void*)shared_entry_destroy);
+       this->trusted = linked_list_create();
+       this->untrusted = linked_list_create();
+       this->keys = linked_list_create();
+       this->shared = linked_list_create();
+       this->lock->unlock(this->lock);
+}
+
+METHOD(mem_cred_t, destroy, void,
+       private_mem_cred_t *this)
+{
+       _clear(this);
+       this->trusted->destroy(this->trusted);
+       this->untrusted->destroy(this->untrusted);
+       this->keys->destroy(this->keys);
+       this->shared->destroy(this->shared);
        this->lock->destroy(this->lock);
        free(this);
 }
@@ -393,6 +409,7 @@ mem_cred_t *mem_cred_create()
                        .add_cert = _add_cert,
                        .add_key = _add_key,
                        .add_shared = _add_shared,
+                       .clear = _clear,
                        .destroy = _destroy,
                },
                .trusted = linked_list_create(),
index ccb04e6..b26e43d 100644 (file)
@@ -59,6 +59,11 @@ struct mem_cred_t {
        void (*add_shared)(mem_cred_t *this, shared_key_t *shared, ...);
 
        /**
+        * Clear all credentials from the credential set.
+        */
+       void (*clear)(mem_cred_t *this);
+
+       /**
         * Destroy a mem_cred_t.
         */
        void (*destroy)(mem_cred_t *this);