Also helpful for ipsec statusall to avoid having to enumerate plugins.
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)
{
{
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)
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;
}
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);
* List of plugins, as plugin_entry_t
*/
linked_list_t *plugins;
+
+ /**
+ * List of names of loaded plugins
+ */
+ char *loaded_plugins;
};
/**
}
/**
+ * 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)
/* 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;
}
}
enumerator->destroy(enumerator);
}
+ free(this->loaded_plugins);
+ this->loaded_plugins = NULL;
}
/**
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,
{
unload(this);
this->plugins->destroy(this->plugins);
+ free(this->loaded_plugins);
free(this);
}
/**
* 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);
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");
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)
/* 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;
{
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())
}
/**
- * 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
*
* @param argc number of arguments
{
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))
{