]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Added an enumerator for registered credential builders
authorMartin Willi <martin@revosec.ch>
Thu, 2 Sep 2010 07:46:09 +0000 (09:46 +0200)
committerMartin Willi <martin@revosec.ch>
Thu, 2 Sep 2010 08:49:02 +0000 (10:49 +0200)
src/libstrongswan/credentials/credential_factory.c
src/libstrongswan/credentials/credential_factory.h

index 4be52df8bec4340a646853a6d085f337eca3c461..c9444503afa86bc372151283fb3d58c64b1f114d 100644 (file)
@@ -149,6 +149,31 @@ METHOD(credential_factory_t, create, void*,
        return construct;
 }
 
+/**
+ * Filter function for builder enumerator
+ */
+static bool builder_filter(void *null, entry_t **entry, credential_type_t *type,
+                                                  void *dummy1, int *subtype,
+                                                  void *dummy2, builder_function_t *constructor)
+{
+       *type = (*entry)->type;
+       *subtype = (*entry)->subtype;
+       if (constructor)
+       {
+               *constructor = (*entry)->constructor;
+       }
+       return TRUE;
+}
+
+METHOD(credential_factory_t, create_builder_enumerator, enumerator_t*,
+       private_credential_factory_t *this)
+{
+       this->lock->read_lock(this->lock);
+       return enumerator_create_filter(
+                               this->constructors->create_enumerator(this->constructors),
+                               (void*)builder_filter, this->lock, (void*)this->lock->unlock);
+}
+
 METHOD(credential_factory_t, destroy, void,
        private_credential_factory_t *this)
 {
@@ -168,6 +193,7 @@ credential_factory_t *credential_factory_create()
        INIT(this,
                .public = {
                        .create = _create,
+                       .create_builder_enumerator = _create_builder_enumerator,
                        .add_builder = _add_builder,
                        .remove_builder = _remove_builder,
                        .destroy = _destroy,
index e8ffb6b9df4952d5306f2f24a10c4aadf6dae1f2..ee1351b15e8467dff515585f3db3dd97c835b985 100644 (file)
@@ -64,6 +64,12 @@ struct credential_factory_t {
         */
        void* (*create)(credential_factory_t *this, credential_type_t type,
                                        int subtype, ...);
+       /**
+        * Create an enumerator over registered builder functions.
+        *
+        * @return                              enumerator (credential_type_t, int, build_function_t)
+        */
+       enumerator_t* (*create_builder_enumerator)(credential_factory_t *this);
 
        /**
         * Register a credential builder function.