aboutsummaryrefslogtreecommitdiffstats
path: root/epan/tap.c
diff options
context:
space:
mode:
authorJoão Valverde <joao.valverde@tecnico.ulisboa.pt>2017-10-01 00:56:03 +0100
committerJoão Valverde <j@v6e.pt>2017-12-14 08:43:57 +0000
commit995812c5f1add94df1c237596939130c1704b099 (patch)
tree42542c56b9a70c7d2d231c8bc36649be35af46b4 /epan/tap.c
parenta9821caab8a1f2c6e265bd5b63a060f1f241c704 (diff)
Refactor plugin registration and loading
Put different types of plugins (libwiretap, libwireshark) in different subdirectories, give libwiretap and libwireshark init routines that load the plugins, and have them scan the appropriate subdirectories so that we don't even *try* to, for example, load libwireshark plugins in programs that only use libwiretap. Compiled plugins are stored in subfolders of the plugin folders, with the subfolder name being the Wireshark minor version number (X.Y). There is another hierarchical level for each Wireshark library (libwireshark, libwscodecs and libwiretap). The folder names are respectively plugins/X.Y/{epan,codecs,wiretap}. Currently we only distribute "epan" (libwireshark) plugins. Change-Id: I3438787a6f45820d64ba4ca91cbe3c8864708acb Reviewed-on: https://code.wireshark.org/review/23983 Petri-Dish: João Valverde <j@v6e.pt> Tested-by: Petri Dish Buildbot Reviewed-by: João Valverde <j@v6e.pt>
Diffstat (limited to 'epan/tap.c')
-rw-r--r--epan/tap.c70
1 files changed, 10 insertions, 60 deletions
diff --git a/epan/tap.c b/epan/tap.c
index b942383a3c..45fa2f5aca 100644
--- a/epan/tap.c
+++ b/epan/tap.c
@@ -108,66 +108,22 @@ typedef struct _tap_listener_t {
static volatile tap_listener_t *tap_listener_queue=NULL;
#ifdef HAVE_PLUGINS
-
-#include <gmodule.h>
-
-#include <wsutil/plugins.h>
-
-/*
- * List of tap plugins.
- */
-typedef struct {
- void (*register_tap_listener_fn)(void); /* routine to call to register tap listener */
-} tap_plugin;
-
static GSList *tap_plugins = NULL;
-/*
- * Callback for each plugin found.
- */
-DIAG_OFF(pedantic)
-static gboolean
-check_for_tap_plugin(GModule *handle)
-{
- gpointer gp;
- void (*register_tap_listener_fn)(void);
- tap_plugin *plugin;
-
- /*
- * Do we have a register_tap_listener routine?
- */
- if (!g_module_symbol(handle, "plugin_register_tap_listener", &gp)) {
- /* No, so this isn't a tap plugin. */
- return FALSE;
- }
-
- /*
- * Yes - this plugin includes one or more taps.
- */
- register_tap_listener_fn = (void (*)(void))gp;
-
- /*
- * Add this one to the list of tap plugins.
- */
- plugin = (tap_plugin *)g_malloc(sizeof (tap_plugin));
- plugin->register_tap_listener_fn = register_tap_listener_fn;
- tap_plugins = g_slist_prepend(tap_plugins, plugin);
- return TRUE;
-}
-DIAG_ON(pedantic)
-
void
-register_tap_plugin_type(void)
+tap_register_plugin(const tap_plugin *plug)
{
- add_plugin_type("tap", check_for_tap_plugin);
+ tap_plugins = g_slist_prepend(tap_plugins, (tap_plugin *)plug);
}
static void
-register_tap_plugin_listener(gpointer data, gpointer user_data _U_)
+call_plugin_register_tap_listener(gpointer data, gpointer user_data _U_)
{
- tap_plugin *plugin = (tap_plugin *)data;
+ tap_plugin *plug = (tap_plugin *)data;
- (plugin->register_tap_listener_fn)();
+ if (plug->register_tap_listener) {
+ plug->register_tap_listener();
+ }
}
/*
@@ -176,15 +132,8 @@ register_tap_plugin_listener(gpointer data, gpointer user_data _U_)
void
register_all_plugin_tap_listeners(void)
{
- g_slist_foreach(tap_plugins, register_tap_plugin_listener, NULL);
-}
-
-static void
-tap_plugin_destroy(gpointer p)
-{
- g_free(p);
+ g_slist_foreach(tap_plugins, call_plugin_register_tap_listener, NULL);
}
-
#endif /* HAVE_PLUGINS */
/* **********************************************************************
@@ -771,7 +720,8 @@ void tap_cleanup(void)
}
#ifdef HAVE_PLUGINS
- g_slist_free_full(tap_plugins, tap_plugin_destroy);
+ g_slist_free(tap_plugins);
+ tap_plugins = NULL;
#endif /* HAVE_PLUGINS */
}