enumerating loaded plugins in "ipsec statusall"
authorMartin Willi <martin@strongswan.org>
Tue, 24 Jun 2008 12:49:04 +0000 (12:49 -0000)
committerMartin Willi <martin@strongswan.org>
Tue, 24 Jun 2008 12:49:04 +0000 (12:49 -0000)
src/charon/plugins/stroke/stroke_list.c
src/libstrongswan/plugins/plugin_loader.c
src/libstrongswan/plugins/plugin_loader.h

index bac05cf..44699ba 100644 (file)
@@ -204,7 +204,7 @@ static void status(private_stroke_list_t *this, stroke_msg_t *msg, FILE *out, bo
        ike_cfg_t *ike_cfg;
        child_cfg_t *child_cfg;
        ike_sa_t *ike_sa;
-       char *name = NULL;
+       char *name = NULL, *plugin;
        bool found = FALSE;
        time_t uptime;
        
@@ -222,6 +222,15 @@ static void status(private_stroke_list_t *this, stroke_msg_t *msg, FILE *out, bo
                                charon->processor->get_job_load(charon->processor));
                fprintf(out, " scheduled events: %d\n",
                                charon->scheduler->get_job_load(charon->scheduler));
+               fprintf(out, "  loaded plugins: ");
+               enumerator = lib->plugins->create_plugin_enumerator(lib->plugins);
+               while (enumerator->enumerate(enumerator, &plugin))
+               {
+                       fprintf(out, "%s ", plugin);
+               }
+               enumerator->destroy(enumerator);
+               fprintf(out, "\n");
+               
                iterator = charon->kernel_interface->create_address_iterator(
                                                                                                        charon->kernel_interface);
                fprintf(out, "Listening IP addresses:\n");
index 2895789..c2996f7 100644 (file)
@@ -15,9 +15,9 @@
  * $Id$
  */
 
+#define _GNU_SOURCE
 #include "plugin_loader.h"
 
-#define _GNU_SOURCE
 #include <string.h>
 #include <dlfcn.h>
 #include <limits.h>
@@ -43,6 +43,11 @@ struct private_plugin_loader_t {
         * list of loaded plugins
         */
        linked_list_t *plugins;
+       
+       /**
+        * names of loaded plugins
+        */
+       linked_list_t *names;
 };
 
 /**
@@ -116,6 +121,7 @@ static int load(private_plugin_loader_t *this, char *path, char *list)
                if (plugin)
                {       /* insert in front to destroy them in reverse order */
                        this->plugins->insert_last(this->plugins, plugin);
+                       this->names->insert_last(this->names, strdup(list));
                        count++;
                }
                if (pos)
@@ -136,20 +142,34 @@ static int load(private_plugin_loader_t *this, char *path, char *list)
 static void unload(private_plugin_loader_t *this)
 {
        plugin_t *plugin;
+       char *name;
        
        while (this->plugins->remove_first(this->plugins,
                                                                           (void**)&plugin) == SUCCESS)
        {
                plugin->destroy(plugin);
        }
+       while (this->names->remove_first(this->names, (void**)&name) == SUCCESS)
+       {
+               free(name);
+       }
 }
 
 /**
+ * Implementation of plugin_loader_t.create_plugin_enumerator
+ */
+static enumerator_t* create_plugin_enumerator(private_plugin_loader_t *this)
+{
+       return this->names->create_enumerator(this->names);
+}       
+
+/**
  * Implementation of plugin_loader_t.destroy
  */
 static void destroy(private_plugin_loader_t *this)
 {
        this->plugins->destroy_offset(this->plugins, offsetof(plugin_t, destroy));
+       this->plugins->destroy_function(this->plugins, free);
        free(this);
 }
 
@@ -162,9 +182,11 @@ plugin_loader_t *plugin_loader_create()
        
        this->public.load = (int(*)(plugin_loader_t*, char *path, char *prefix))load;
        this->public.unload = (void(*)(plugin_loader_t*))unload;
+       this->public.create_plugin_enumerator = (enumerator_t*(*)(plugin_loader_t*))create_plugin_enumerator;
        this->public.destroy = (void(*)(plugin_loader_t*))destroy;
        
        this->plugins = linked_list_create();
+       this->names = linked_list_create();
        
        return &this->public;
 }
index 45b7afa..bd24e75 100644 (file)
@@ -23,6 +23,8 @@
 
 typedef struct plugin_loader_t plugin_loader_t;
 
+#include <utils/enumerator.h>
+
 /**
  * The plugin_loader loads plugins from a directory and initializes them
  */
@@ -41,7 +43,14 @@ struct plugin_loader_t {
         * Unload all loaded plugins.
         */
        void (*unload)(plugin_loader_t *this);
-               
+       
+       /**
+        * Create an enumerator over all loaded plugin names.
+        *
+        * @return                              enumerator over char*
+        */
+       enumerator_t* (*create_plugin_enumerator)(plugin_loader_t *this);
+       
        /**
      * Unload loaded plugins, destroy plugin_loader instance.
      */