Print extcap plugins with "tshark -G plugins".

This makes it match the "Plugins" tab of the "About" dialog.

While we're at it, use the same code to enumerate extcap plugins in that
dialog.

Change-Id: I50f402a7ab5d83d46baab070d145558ed8f688f4
Reviewed-on: https://code.wireshark.org/review/32589
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2019-03-26 14:52:39 -07:00
parent 4e688ec8da
commit 5dfde7ff83
4 changed files with 62 additions and 21 deletions

View File

@ -40,6 +40,7 @@
#include <wsutil/file_util.h>
#include <wsutil/filesystem.h>
#include <wsutil/ws_pipe.h>
#include <wsutil/ws_printf.h>
#include <wsutil/tempfile.h>
#include "capture_opts.h"
@ -151,7 +152,7 @@ thread_pool_wait(thread_pool_t *pool)
g_mutex_clear(&pool->data_mutex);
}
GHashTable *
static GHashTable *
extcap_loaded_interfaces(void)
{
if (prefs.capture_no_extcap)
@ -175,6 +176,53 @@ extcap_clear_interfaces(void)
_tool_for_ifname = NULL;
}
static gint
compare_tools(gconstpointer a, gconstpointer b)
{
return g_strcmp0((*(extcap_info *const *)a)->basename, (*(extcap_info *const *)b)->basename);
}
void
extcap_get_descriptions(plugin_description_callback callback, void *callback_data)
{
GHashTable * tools = extcap_loaded_interfaces();
GPtrArray *tools_array = g_ptr_array_new();
if (tools && g_hash_table_size(tools) > 0) {
GList * walker = g_list_first(g_hash_table_get_keys(tools));
while (walker && walker->data) {
extcap_info * tool = (extcap_info *)g_hash_table_lookup(tools, walker->data);
if (tool) {
g_ptr_array_add(tools_array, tool);
}
walker = g_list_next(walker);
}
}
g_ptr_array_sort(tools_array, compare_tools);
for (guint i = 0; i < tools_array->len; i++) {
extcap_info *tool = (extcap_info *)tools_array->pdata[i];
callback(tool->basename, tool->version, "extcap", tool->full_path, callback_data);
}
g_ptr_array_free(tools_array, TRUE);
}
static void
print_extcap_description(const char *basename, const char *version,
const char *description, const char *filename,
void *user_data _U_)
{
ws_debug_printf("%-16s\t%s\t%s\t%s\n", basename, version, description, filename);
}
void
extcap_dump_all(void)
{
extcap_get_descriptions(print_extcap_description, NULL);
}
/**
* Obtains a list of extcap program paths. Use g_slist_free_full(paths, g_free)
* to destroy the list.
@ -1937,10 +1985,7 @@ extcap_list_interfaces_cb(thread_pool_t *pool, void *data, char *output)
}
/* Handles loading of the interfaces.
*
* A list of interfaces can be obtained by calling \ref extcap_loaded_interfaces
*/
/* Handles loading of the interfaces. */
static void
extcap_load_interface_list(void)
{

View File

@ -20,6 +20,8 @@
#include <wsutil/unicode-utils.h>
#endif
#include <wsutil/plugins.h>
#include <ui/capture_ui_utils.h>
/* As boolean flags will be allowed any form of yes, true or any number != 0 (or starting with 0)
@ -87,14 +89,18 @@ extcap_get_tool_by_ifname(const gchar *ifname);
gchar *
extcap_get_help_for_ifname(const char *ifname);
/* get a list of all available extcap executables and their interfaces */
GHashTable *
extcap_loaded_interfaces(void);
/* remove all loaded interfaces */
void
extcap_clear_interfaces(void);
/* get information about all available extcap executables */
void
extcap_get_descriptions(plugin_description_callback callback, void *callback_data);
/* print information about all available extcap executables */
void
extcap_dump_all(void);
/* returns the configuration for the given interface name, or an
* empty list, if no configuration has been found
* @param ifname the interface name

View File

@ -978,6 +978,7 @@ main(int argc, char *argv[])
#ifdef HAVE_LUA
wslua_plugins_dump_all();
#endif
extcap_dump_all();
}
else if (strcmp(argv[2], "protocols") == 0)
proto_registrar_dump_protocols();

View File

@ -132,18 +132,7 @@ PluginListModel::PluginListModel(QObject * parent) : AStringListListModel(parent
wslua_plugins_get_descriptions(plugins_add_description, &plugin_data);
#endif
GHashTable * tools = extcap_loaded_interfaces();
if (tools && g_hash_table_size(tools) > 0) {
GList * walker = g_list_first(g_hash_table_get_keys(tools));
while (walker && walker->data) {
extcap_info * tool = (extcap_info *)g_hash_table_lookup(tools, walker->data);
if (tool) {
QStringList plugin_row = QStringList() << tool->basename << tool->version << tr("extcap") << tool->full_path;
plugin_data << plugin_row;
}
walker = g_list_next(walker);
}
}
extcap_get_descriptions(plugins_add_description, &plugin_data);
typeNames_ << QString("");
foreach(QStringList row, plugin_data)