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:
parent
a269ae1b6a
commit
a1969dd6f6
@ -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
|
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;
|
g_ptr_array_add((GPtrArray *)user_data, value);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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 plugin *a = *(const plugin **)_a;
|
||||||
const struct plugin_description *b = *(const struct plugin_description **)_b;
|
const plugin *b = *(const plugin **)_b;
|
||||||
|
|
||||||
return strcmp(a->name, b->name);
|
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
|
WS_DLL_PUBLIC void
|
||||||
plugins_get_descriptions(plugin_description_callback callback, void *user_data)
|
plugins_get_descriptions(plugin_description_callback callback, void *user_data)
|
||||||
{
|
{
|
||||||
GPtrArray *descriptions;
|
GPtrArray *descriptions;
|
||||||
struct plugin_description *desc;
|
struct description_callback cb;
|
||||||
|
|
||||||
descriptions = g_ptr_array_sized_new(g_hash_table_size(plugins_table));
|
descriptions = g_ptr_array_sized_new(g_hash_table_size(plugins_table));
|
||||||
g_hash_table_foreach(plugins_table, add_plugin_type_description, descriptions);
|
g_hash_table_foreach(plugins_table, add_plugin_to_descriptions, descriptions);
|
||||||
g_ptr_array_sort(descriptions, compare_descriptions);
|
g_ptr_array_sort(descriptions, compare_plugins);
|
||||||
for (guint i = 0; i < descriptions->len; i++) {
|
cb.callback = callback;
|
||||||
desc = (struct plugin_description *)descriptions->pdata[i];
|
cb.callback_data = user_data;
|
||||||
callback(desc->name, desc->version, desc->types, desc->filename, user_data);
|
g_ptr_array_foreach(descriptions, call_description_callback, &cb);
|
||||||
}
|
g_ptr_array_free(descriptions, FALSE);
|
||||||
g_ptr_array_free(descriptions, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user