aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/plugins/plugin_loader.c
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2012-01-19 12:27:56 +0100
committerTobias Brunner <tobias@strongswan.org>2012-01-19 12:37:42 +0100
commitf1ba06c1c6eff3e7c6a5666bcb68d3f3e2e8a373 (patch)
treecf82f97e848a47f9d45ca1db048ca81c082d2c95 /src/libstrongswan/plugins/plugin_loader.c
parentfdf1f239ef33d9bb69a49138956c6fd52c74a053 (diff)
downloadstrongswan-f1ba06c1c6eff3e7c6a5666bcb68d3f3e2e8a373.tar.bz2
strongswan-f1ba06c1c6eff3e7c6a5666bcb68d3f3e2e8a373.tar.xz
Cache list of plugin names to further simplify its usage.
Also helpful for ipsec statusall to avoid having to enumerate plugins.
Diffstat (limited to 'src/libstrongswan/plugins/plugin_loader.c')
-rw-r--r--src/libstrongswan/plugins/plugin_loader.c65
1 files changed, 46 insertions, 19 deletions
diff --git a/src/libstrongswan/plugins/plugin_loader.c b/src/libstrongswan/plugins/plugin_loader.c
index 1747cba6e..164b68e60 100644
--- a/src/libstrongswan/plugins/plugin_loader.c
+++ b/src/libstrongswan/plugins/plugin_loader.c
@@ -45,6 +45,11 @@ struct private_plugin_loader_t {
* List of plugins, as plugin_entry_t
*/
linked_list_t *plugins;
+
+ /**
+ * List of names of loaded plugins
+ */
+ char *loaded_plugins;
};
/**
@@ -204,6 +209,38 @@ METHOD(plugin_loader_t, create_plugin_enumerator, enumerator_t*,
}
/**
+ * Create a list of the names of all loaded plugins
+ */
+static char* loaded_plugins_list(private_plugin_loader_t *this)
+{
+ int buf_len = 128, len = 0;
+ char *buf, *name;
+ enumerator_t *enumerator;
+ plugin_t *plugin;
+
+ buf = malloc(buf_len);
+ buf[0] = '\0';
+ enumerator = create_plugin_enumerator(this);
+ while (enumerator->enumerate(enumerator, &plugin, NULL))
+ {
+ name = plugin->get_name(plugin);
+ if (len + (strlen(name) + 1) >= buf_len)
+ {
+ buf_len <<= 1;
+ buf = realloc(buf, buf_len);
+ }
+ len += snprintf(&buf[len], buf_len - len, "%s ", name);
+ }
+ enumerator->destroy(enumerator);
+ if (len > 0 && buf[len - 1] == ' ')
+ {
+ buf[len - 1] = '\0';
+ }
+ return buf;
+}
+
+
+/**
* Check if a plugin is already loaded
*/
static bool plugin_loaded(private_plugin_loader_t *this, char *name)
@@ -516,6 +553,11 @@ METHOD(plugin_loader_t, load_plugins, bool,
/* unload plugins that we were not able to load any features for */
purge_plugins(this);
}
+ if (!critical_failed)
+ {
+ free(this->loaded_plugins);
+ this->loaded_plugins = loaded_plugins_list(this);
+ }
return !critical_failed;
}
@@ -558,6 +600,8 @@ METHOD(plugin_loader_t, unload, void,
}
enumerator->destroy(enumerator);
}
+ free(this->loaded_plugins);
+ this->loaded_plugins = NULL;
}
/**
@@ -609,25 +653,7 @@ METHOD(plugin_loader_t, reload, u_int,
METHOD(plugin_loader_t, loaded_plugins, char*,
private_plugin_loader_t *this)
{
-#define BUF_LEN 512
- char *buf = malloc(BUF_LEN);
- int len = 0;
- enumerator_t *enumerator;
- plugin_t *plugin;
-
- buf[0] = '\0';
- enumerator = create_plugin_enumerator(this);
- while (len < BUF_LEN && enumerator->enumerate(enumerator, &plugin, NULL))
- {
- len += snprintf(&buf[len], BUF_LEN - len, "%s ",
- plugin->get_name(plugin));
- }
- enumerator->destroy(enumerator);
- if (len > 0 && buf[len - 1] == ' ')
- {
- buf[len - 1] = '\0';
- }
- return buf;
+ return this->loaded_plugins ?: "";
}
METHOD(plugin_loader_t, destroy, void,
@@ -635,6 +661,7 @@ METHOD(plugin_loader_t, destroy, void,
{
unload(this);
this->plugins->destroy(this->plugins);
+ free(this->loaded_plugins);
free(this);
}