plugins: No need to allocate a new struct

Change-Id: Ic39cf1c7f199dc5e4879d954a649d21453dcc5e5
Reviewed-on: https://code.wireshark.org/review/23753
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: João Valverde <j@v6e.pt>
This commit is contained in:
João Valverde 2017-09-26 19:17:52 +01:00 committed by João Valverde
parent a269ae1b6a
commit a1969dd6f6

View File

@ -321,52 +321,48 @@ scan_plugins(plugin_load_failure_mode mode)
}
}
struct plugin_description {
const char *name;
const char *version;
const char *types;
const char *filename;
};
static void
add_plugin_type_description(gpointer key _U_, gpointer value, gpointer user_data)
add_plugin_to_descriptions(gpointer key _U_, gpointer value, gpointer user_data)
{
GPtrArray *descriptions = (GPtrArray *)user_data;
struct plugin_description *plug_desc;
plugin *plug = (plugin *)value;
plug_desc = g_new(struct plugin_description, 1);
plug_desc->name = plug->name;
plug_desc->version = plug->version;
plug_desc->types = plug->types->str;
plug_desc->filename = g_module_name(plug->handle);
g_ptr_array_add(descriptions, plug_desc);
g_ptr_array_add((GPtrArray *)user_data, value);
}
static int
compare_descriptions(gconstpointer _a, gconstpointer _b)
compare_plugins(gconstpointer _a, gconstpointer _b)
{
const struct plugin_description *a = *(const struct plugin_description **)_a;
const struct plugin_description *b = *(const struct plugin_description **)_b;
const plugin *a = *(const plugin **)_a;
const plugin *b = *(const plugin **)_b;
return strcmp(a->name, b->name);
}
struct description_callback {
plugin_description_callback callback;
gpointer callback_data;
};
static void
call_description_callback(gpointer data, gpointer user_data)
{
plugin *plug = (plugin *)data;
struct description_callback *desc = (struct description_callback *)user_data;
desc->callback(plug->name, plug->version, plug->types->str, g_module_name(plug->handle), desc->callback_data);
}
WS_DLL_PUBLIC void
plugins_get_descriptions(plugin_description_callback callback, void *user_data)
{
GPtrArray *descriptions;
struct plugin_description *desc;
struct description_callback cb;
descriptions = g_ptr_array_sized_new(g_hash_table_size(plugins_table));
g_hash_table_foreach(plugins_table, add_plugin_type_description, descriptions);
g_ptr_array_sort(descriptions, compare_descriptions);
for (guint i = 0; i < descriptions->len; i++) {
desc = (struct plugin_description *)descriptions->pdata[i];
callback(desc->name, desc->version, desc->types, desc->filename, user_data);
}
g_ptr_array_free(descriptions, TRUE);
g_hash_table_foreach(plugins_table, add_plugin_to_descriptions, descriptions);
g_ptr_array_sort(descriptions, compare_plugins);
cb.callback = callback;
cb.callback_data = user_data;
g_ptr_array_foreach(descriptions, call_description_callback, &cb);
g_ptr_array_free(descriptions, FALSE);
}
static void