Cache list of plugin names to further simplify its usage.
Also helpful for ipsec statusall to avoid having to enumerate plugins.
This commit is contained in:
+2
-14
@@ -201,18 +201,6 @@ METHOD(daemon_t, start, void,
|
||||
DEFAULT_THREADS));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log loaded plugins
|
||||
*/
|
||||
static void print_plugins()
|
||||
{
|
||||
char *plugins;
|
||||
|
||||
plugins = lib->plugins->loaded_plugins(lib->plugins);
|
||||
DBG1(DBG_DMN, "loaded plugins: %s", plugins);
|
||||
free(plugins);
|
||||
}
|
||||
|
||||
METHOD(daemon_t, initialize, bool,
|
||||
private_daemon_t *this)
|
||||
{
|
||||
@@ -233,8 +221,8 @@ METHOD(daemon_t, initialize, bool,
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
print_plugins();
|
||||
DBG1(DBG_DMN, "loaded plugins: %s",
|
||||
lib->plugins->loaded_plugins(lib->plugins));
|
||||
|
||||
this->public.ike_sa_manager = ike_sa_manager_create();
|
||||
if (this->public.ike_sa_manager == NULL)
|
||||
|
||||
@@ -414,8 +414,7 @@ METHOD(stroke_list_t, status, void,
|
||||
if (all)
|
||||
{
|
||||
peer_cfg_t *peer_cfg;
|
||||
plugin_t *plugin;
|
||||
char *pool, *plugins;
|
||||
char *pool;
|
||||
host_t *host;
|
||||
u_int32_t dpd;
|
||||
time_t since, now;
|
||||
@@ -449,9 +448,8 @@ METHOD(stroke_list_t, status, void,
|
||||
}
|
||||
fprintf(out, ", scheduled: %d\n",
|
||||
lib->scheduler->get_job_load(lib->scheduler));
|
||||
plugins = lib->plugins->loaded_plugins(lib->plugins);
|
||||
fprintf(out, " loaded plugins: %s\n", plugins);
|
||||
free(plugins);
|
||||
fprintf(out, " loaded plugins: %s\n",
|
||||
lib->plugins->loaded_plugins(lib->plugins));
|
||||
|
||||
first = TRUE;
|
||||
enumerator = this->attribute->create_pool_enumerator(this->attribute);
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -203,6 +208,38 @@ METHOD(plugin_loader_t, create_plugin_enumerator, enumerator_t*,
|
||||
(void*)plugin_filter, NULL, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,9 @@ struct plugin_loader_t {
|
||||
/**
|
||||
* Get a simple list the names of all loaded plugins.
|
||||
*
|
||||
* @return list of the names of all loaded plugins (allocated)
|
||||
* The function returns internal data, do not free.
|
||||
*
|
||||
* @return list of the names of all loaded plugins
|
||||
*/
|
||||
char* (*loaded_plugins)(plugin_loader_t *this);
|
||||
|
||||
|
||||
+2
-3
@@ -179,9 +179,8 @@ int command_usage(char *error)
|
||||
|
||||
if (active == help_idx)
|
||||
{
|
||||
char *plugins = lib->plugins->loaded_plugins(lib->plugins);
|
||||
fprintf(out, "loaded plugins: %s\n", plugins);
|
||||
free(plugins);
|
||||
fprintf(out, "loaded plugins: %s\n",
|
||||
lib->plugins->loaded_plugins(lib->plugins));
|
||||
}
|
||||
|
||||
fprintf(out, "usage:\n");
|
||||
|
||||
+2
-5
@@ -868,11 +868,8 @@ DBG_dump(const char *label, const void *p, size_t len)
|
||||
|
||||
static void show_loaded_plugins()
|
||||
{
|
||||
char *plugins;
|
||||
|
||||
plugins = lib->plugins->loaded_plugins(lib->plugins);
|
||||
whack_log(RC_COMMENT, "loaded plugins: %s", plugins);
|
||||
free(plugins);
|
||||
whack_log(RC_COMMENT, "loaded plugins: %s",
|
||||
lib->plugins->loaded_plugins(lib->plugins));
|
||||
}
|
||||
|
||||
void show_status(bool all, const char *name)
|
||||
|
||||
+2
-13
@@ -264,18 +264,6 @@ static const char *pkcs11_init_args = NULL;
|
||||
/* options read by optionsfrom */
|
||||
options_t *options;
|
||||
|
||||
/**
|
||||
* Log loaded plugins
|
||||
*/
|
||||
static void print_plugins()
|
||||
{
|
||||
char *plugins;
|
||||
|
||||
plugins = lib->plugins->loaded_plugins(lib->plugins);
|
||||
DBG1(DBG_DMN, "loaded plugins: %s", plugins);
|
||||
free(plugins);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
bool fork_desired = TRUE;
|
||||
@@ -693,7 +681,8 @@ int main(int argc, char **argv)
|
||||
{
|
||||
exit(SS_RC_INITIALIZATION_FAILED);
|
||||
}
|
||||
print_plugins();
|
||||
DBG1(DBG_DMN, "loaded plugins: %s",
|
||||
lib->plugins->loaded_plugins(lib->plugins));
|
||||
|
||||
init_builder();
|
||||
if (!init_secret() || !init_crypto())
|
||||
|
||||
@@ -275,18 +275,6 @@ usage(const char *message)
|
||||
exit_scepclient(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log loaded plugins
|
||||
*/
|
||||
static void print_plugins()
|
||||
{
|
||||
char *plugins;
|
||||
|
||||
plugins = lib->plugins->loaded_plugins(lib->plugins);
|
||||
DBG1(DBG_LIB, " loaded plugins: %s", plugins);
|
||||
free(plugins);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief main of scepclient
|
||||
*
|
||||
@@ -752,7 +740,8 @@ int main(int argc, char **argv)
|
||||
{
|
||||
exit_scepclient("plugin loading failed");
|
||||
}
|
||||
print_plugins();
|
||||
DBG1(DBG_LIB, " loaded plugins: %s",
|
||||
lib->plugins->loaded_plugins(lib->plugins));
|
||||
|
||||
if ((filetype_out == 0) && (!request_ca_certificate))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user