aboutsummaryrefslogtreecommitdiffstats
path: root/epan
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
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')
-rw-r--r--epan/epan.c31
-rw-r--r--epan/epan.h14
-rw-r--r--epan/prefs.c36
-rw-r--r--epan/prefs.h13
-rw-r--r--epan/proto.c104
-rw-r--r--epan/proto.h13
-rw-r--r--epan/tap.c70
-rw-r--r--epan/tap.h14
8 files changed, 118 insertions, 177 deletions
diff --git a/epan/epan.c b/epan/epan.c
index 1940f21fbf..5b7a64ac74 100644
--- a/epan/epan.c
+++ b/epan/epan.c
@@ -94,6 +94,10 @@
static wmem_allocator_t *pinfo_pool_cache = NULL;
+#ifdef HAVE_PLUGINS
+plugins_t *libwireshark_plugins = NULL;
+#endif
+
const gchar*
epan_get_version(void) {
return VERSION;
@@ -136,22 +140,6 @@ quiet_gcrypt_logger (void *dummy _U_, int level, const char *format, va_list arg
}
#endif // _WIN32
-/*
- * Register all the plugin types that are part of libwireshark, namely
- * dissector and tap plugins.
- *
- * Must be called before init_plugins(), which must be called before
- * any registration routines are called.
- */
-void
-epan_register_plugin_types(void)
-{
-#ifdef HAVE_PLUGINS
- register_dissector_plugin_type();
- register_tap_plugin_type();
-#endif
-}
-
gboolean
epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data),
void (*register_all_handoffs_func)(register_cb cb, gpointer client_data),
@@ -170,8 +158,12 @@ epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_da
addr_resolv_init();
except_init();
- /* initialize libgcrypt (beware, it won't be thread-safe) */
+#ifdef HAVE_PLUGINS
+ libwireshark_plugins = plugins_init("epan");
+#endif
+
+ /* initialize libgcrypt (beware, it won't be thread-safe) */
gcry_check_version(NULL);
#if defined(_WIN32)
gcry_set_log_handler (quiet_gcrypt_logger, NULL);
@@ -278,6 +270,11 @@ epan_cleanup(void)
except_deinit();
addr_resolv_cleanup();
+#ifdef HAVE_PLUGINS
+ plugins_cleanup(libwireshark_plugins);
+ libwireshark_plugins = NULL;
+#endif
+
if (pinfo_pool_cache != NULL) {
wmem_destroy_allocator(pinfo_pool_cache);
pinfo_pool_cache = NULL;
diff --git a/epan/epan.h b/epan/epan.h
index 5cafb780dc..8dc87451f9 100644
--- a/epan/epan.h
+++ b/epan/epan.h
@@ -30,6 +30,7 @@ extern "C" {
#include <epan/tvbuff.h>
#include <epan/prefs.h>
#include <epan/frame_data.h>
+#include <wsutil/plugins.h>
#include "register.h"
#include "ws_symbol_export.h"
@@ -57,6 +58,10 @@ struct packet_provider_funcs {
const char *(*get_user_comment)(struct packet_provider_data *prov, const frame_data *fd);
};
+#ifdef HAVE_PLUGINS
+extern plugins_t *libwireshark_plugins;
+#endif
+
/**
@mainpage Wireshark EPAN the packet analyzing engine. Source code can be found in the epan directory
@@ -100,15 +105,6 @@ Ref2 for further edits - delete when done
- \ref airpcapdefs
- \ref radiotap
*/
-/*
- * Register all the plugin types that are part of libwireshark.
- *
- * Must be called before init_plugins(), which must be called before
- * any registration routines are called, i.e. before epan_init().
- *
- * Must be called only once in a program.
- */
-WS_DLL_PUBLIC void epan_register_plugin_types(void);
/**
* Init the whole epan module.
diff --git a/epan/prefs.c b/epan/prefs.c
index 9ae9cfd21b..a3dfdd8859 100644
--- a/epan/prefs.c
+++ b/epan/prefs.c
@@ -737,6 +737,38 @@ prefs_register_stat(const char *name, const char *title,
apply_cb, TRUE);
}
+/*
+ * Register that a codec has preferences.
+ *
+ * "name" is a name for the codec to use on the command line with "-o"
+ * and in preference files.
+ *
+ * "title" is a short human-readable name for the codec.
+ *
+ * "description" is a longer human-readable description of the codec.
+ */
+module_t *codecs_module = NULL;
+
+module_t *
+prefs_register_codec(const char *name, const char *title,
+ const char *description, void (*apply_cb)(void))
+{
+ /*
+ * Have we yet created the "Codecs" subtree?
+ */
+ if (codecs_module == NULL) {
+ /*
+ * No. Register Codecs subtree as well as any preferences
+ * for non-dissector modules.
+ */
+ pre_init_prefs();
+ prefs_register_modules();
+ }
+
+ return prefs_register_module(codecs_module, name, title, description,
+ apply_cb, TRUE);
+}
+
module_t *
prefs_find_module(const char *name)
{
@@ -3479,6 +3511,10 @@ prefs_register_modules(void)
"This is the file that gets written to when the destination is set to \"file\"",
&prefs.pr_file, PREF_SAVE_FILENAME, NULL, TRUE);
+ /* Codecs */
+ codecs_module = prefs_register_module(NULL, "codecs", "Codecs",
+ "Codecs", NULL, TRUE);
+
/* Statistics */
stats_module = prefs_register_module(NULL, "statistics", "Statistics",
"Statistics", &stats_callback, TRUE);
diff --git a/epan/prefs.h b/epan/prefs.h
index f1eceb78bc..2eead89225 100644
--- a/epan/prefs.h
+++ b/epan/prefs.h
@@ -299,6 +299,19 @@ WS_DLL_PUBLIC module_t *prefs_register_stat(const char *name, const char *title,
const char *description, void (*apply_cb)(void));
/*
+ * Register that a codec has preferences.
+ *
+ * "name" is a name for the codec to use on the command line with "-o"
+ * and in preference files.
+ *
+ * "title" is a short human-readable name for the codec.
+ *
+ * "description" is a longer human-readable description of the codec.
+ */
+WS_DLL_PUBLIC module_t *prefs_register_codec(const char *name, const char *title,
+ const char *description, void (*apply_cb)(void));
+
+/*
* Register that a protocol has preferences and group it under a single
* subtree
*/
diff --git a/epan/proto.c b/epan/proto.c
index 29d2d8d360..373eaa5af6 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -55,7 +55,6 @@
#include "show_exception.h"
#include "in_cksum.h"
-#include <wsutil/plugins.h>
#include <wsutil/ws_printf.h> /* ws_debug_printf/ws_g_warning */
#include <wsutil/glib-compat.h>
@@ -434,98 +433,37 @@ check_charset(const guint8 table[256], const char *str)
}
#ifdef HAVE_PLUGINS
-/*
- * List of dissector plugins.
- */
-typedef struct {
- void (*register_protoinfo)(void); /* routine to call to register protocol information */
- void (*reg_handoff)(void); /* routine to call to register dissector handoff */
-} dissector_plugin;
-
static GSList *dissector_plugins = NULL;
-/*
- * Callback for each plugin found.
- */
-DIAG_OFF(pedantic)
-static gboolean
-check_for_dissector_plugin(GModule *handle)
+void
+proto_register_plugin(const proto_plugin *plug)
{
- gpointer gp;
- void (*register_protoinfo)(void);
- void (*reg_handoff)(void);
- dissector_plugin *plugin;
-
- /*
- * Do we have a register routine?
- */
- if (g_module_symbol(handle, "plugin_register", &gp)) {
- register_protoinfo = (void (*)(void))gp;
- }
- else {
- register_protoinfo = NULL;
- }
-
- /*
- * Do we have a reg_handoff routine?
- */
- if (g_module_symbol(handle, "plugin_reg_handoff", &gp)) {
- reg_handoff = (void (*)(void))gp;
- }
- else {
- reg_handoff = NULL;
+ if (!plug) {
+ /* XXX print useful warning */
+ return;
}
-
- /*
- * If we have neither, we're not a dissector plugin.
- */
- if (register_protoinfo == NULL && reg_handoff == NULL)
- return FALSE;
-
- /*
- * Add this one to the list of dissector plugins.
- */
- plugin = (dissector_plugin *)g_malloc(sizeof (dissector_plugin));
- plugin->register_protoinfo = register_protoinfo;
- plugin->reg_handoff = reg_handoff;
- dissector_plugins = g_slist_prepend(dissector_plugins, plugin);
- return TRUE;
+ dissector_plugins = g_slist_prepend(dissector_plugins, (proto_plugin *)plug);
}
-DIAG_ON(pedantic)
static void
-register_dissector_plugin(gpointer data, gpointer user_data _U_)
+call_plugin_register_protoinfo(gpointer data, gpointer user_data _U_)
{
- dissector_plugin *plugin = (dissector_plugin *)data;
+ proto_plugin *plug = (proto_plugin *)data;
- if (plugin->register_protoinfo)
- (plugin->register_protoinfo)();
+ if (plug->register_protoinfo) {
+ plug->register_protoinfo();
+ }
}
static void
-reg_handoff_dissector_plugin(gpointer data, gpointer user_data _U_)
+call_plugin_register_handoff(gpointer data, gpointer user_data _U_)
{
- dissector_plugin *plugin = (dissector_plugin *)data;
+ proto_plugin *plug = (proto_plugin *)data;
- if (plugin->reg_handoff)
- (plugin->reg_handoff)();
-}
-
-/*
- * Register dissector plugin type.
- */
-void
-register_dissector_plugin_type(void)
-{
- add_plugin_type("dissector", check_for_dissector_plugin);
-}
-
-static void
-dissector_plugin_destroy(gpointer p)
-{
- g_free(p);
+ if (plug->register_handoff) {
+ plug->register_handoff();
+ }
}
-
#endif /* HAVE_PLUGINS */
/* initialize data structures and register protocols and fields */
@@ -578,7 +516,7 @@ proto_init(void (register_all_protocols_func)(register_cb cb, gpointer client_da
plugins. */
if (cb)
(*cb)(RA_PLUGIN_REGISTER, NULL, client_data);
- g_slist_foreach(dissector_plugins, register_dissector_plugin, NULL);
+ g_slist_foreach(dissector_plugins, call_plugin_register_protoinfo, NULL);
#endif
/* Now call the "handoff registration" routines of all built-in
@@ -591,7 +529,7 @@ proto_init(void (register_all_protocols_func)(register_cb cb, gpointer client_da
/* Now do the same with plugins. */
if (cb)
(*cb)(RA_PLUGIN_HANDOFF, NULL, client_data);
- g_slist_foreach(dissector_plugins, reg_handoff_dissector_plugin, NULL);
+ g_slist_foreach(dissector_plugins, call_plugin_register_handoff, NULL);
#endif
/* sort the protocols by protocol name */
@@ -686,10 +624,8 @@ proto_cleanup(void)
proto_cleanup_base();
#ifdef HAVE_PLUGINS
- if (dissector_plugins) {
- g_slist_free_full(dissector_plugins, dissector_plugin_destroy);
- dissector_plugins = NULL;
- }
+ g_slist_free(dissector_plugins);
+ dissector_plugins = NULL;
#endif
}
diff --git a/epan/proto.h b/epan/proto.h
index eee7650873..914ee5c7b8 100644
--- a/epan/proto.h
+++ b/epan/proto.h
@@ -52,6 +52,9 @@
#include "register.h"
#include "ws_symbol_export.h"
#include "ws_attributes.h"
+#ifdef HAVE_PLUGINS
+#include "wsutil/plugins.h"
+#endif
#ifdef __cplusplus
extern "C" {
@@ -908,9 +911,13 @@ WS_DLL_PUBLIC void proto_tree_children_foreach(proto_tree *tree,
#define PNODE_POOL(proto_node) ((proto_node)->tree_data->pinfo->pool)
#ifdef HAVE_PLUGINS
-/** Register dissector plugin type with the plugin system.
- Called by epan_register_plugin_types(); do not call it yourself. */
-extern void register_dissector_plugin_type(void);
+typedef struct {
+ void (*register_protoinfo)(void); /* routine to call to register protocol information */
+ void (*register_handoff)(void); /* routine to call to register dissector handoff */
+} proto_plugin;
+
+/** Register dissector plugin with the plugin system. */
+WS_DLL_PUBLIC void proto_register_plugin(const proto_plugin *plugin);
#endif
/** Sets up memory used by proto routines. Called at program startup */
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 */
}
diff --git a/epan/tap.h b/epan/tap.h
index 395bf19ce8..f35aad9bdd 100644
--- a/epan/tap.h
+++ b/epan/tap.h
@@ -26,6 +26,9 @@
#include <epan/epan.h>
#include <epan/packet_info.h>
#include "ws_symbol_export.h"
+#ifdef HAVE_PLUGINS
+#include "wsutil/plugins.h"
+#endif
#ifdef __cplusplus
extern "C" {
@@ -47,14 +50,17 @@ typedef void (*tap_draw_cb)(void *tapdata);
** but does not, itself, require dissection */
#ifdef HAVE_PLUGINS
-/** Register tap plugin type with the plugin system.
- Called by epan_register_plugin_types(); do not call it yourself. */
-extern void register_tap_plugin_type(void);
+typedef struct {
+ void (*register_tap_listener)(void); /* routine to call to register tap listener */
+} tap_plugin;
+
+/** Register tap plugin with the plugin system. */
+WS_DLL_PUBLIC void tap_register_plugin(const tap_plugin *plug);
#endif
/*
* For all tap plugins, call their register routines.
- * Must be called after init_plugins(), and must be called only once in
+ * Must be called after plugins_init(), and must be called only once in
* a program.
*
* XXX - should probably be handled by epan_init(), as the tap mechanism