diff options
Diffstat (limited to 'wiretap')
-rw-r--r-- | wiretap/wtap.c | 75 | ||||
-rw-r--r-- | wiretap/wtap.h | 14 |
2 files changed, 29 insertions, 60 deletions
diff --git a/wiretap/wtap.c b/wiretap/wtap.c index 4d81d982e1..58fd2c1d7b 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -37,72 +37,24 @@ #ifdef HAVE_PLUGINS -#include <wsutil/plugins.h> - -/* - * List of wiretap plugins. - */ -typedef struct { - void (*register_wtap_module)(void); /* routine to call to register a wiretap module */ -} wtap_plugin; +static plugins_t *libwiretap_plugins; static GSList *wtap_plugins = NULL; -/* - * Callback for each plugin found. - */ -DIAG_OFF(pedantic) -static gboolean -check_for_wtap_plugin(GModule *handle) -{ - gpointer gp; - void (*register_wtap_module)(void); - wtap_plugin *plugin; - - /* - * Do we have a register_wtap_module routine? - */ - if (!g_module_symbol(handle, "register_wtap_module", &gp)) { - /* No, so this isn't a wiretap module plugin. */ - return FALSE; - } - - /* - * Yes - this plugin includes one or more wiretap modules. - */ - register_wtap_module = (void (*)(void))gp; - - /* - * Add this one to the list of wiretap module plugins. - */ - plugin = (wtap_plugin *)g_malloc(sizeof (wtap_plugin)); - plugin->register_wtap_module = register_wtap_module; - wtap_plugins = g_slist_prepend(wtap_plugins, plugin); - return TRUE; -} -DIAG_ON(pedantic) - -static void -wtap_register_plugin_types(void) +void +wtap_register_plugin(const wtap_plugin *plug) { - add_plugin_type("libwiretap", check_for_wtap_plugin); + wtap_plugins = g_slist_prepend(wtap_plugins, (wtap_plugin *)plug); } static void -register_wtap_module_plugin(gpointer data, gpointer user_data _U_) +call_plugin_register_wtap_module(gpointer data, gpointer user_data _U_) { - wtap_plugin *plugin = (wtap_plugin *)data; - - (plugin->register_wtap_module)(); -} + wtap_plugin *plug = (wtap_plugin *)data; -/* - * For all wiretap module plugins, call their register routines. - */ -void -register_all_wiretap_modules(void) -{ - g_slist_foreach(wtap_plugins, register_wtap_module_plugin, NULL); + if (plug->register_wtap_module) { + plug->register_wtap_module(); + } } #endif /* HAVE_PLUGINS */ @@ -1481,7 +1433,8 @@ wtap_init(void) wtap_opttypes_initialize(); wtap_init_encap_types(); #ifdef HAVE_PLUGINS - wtap_register_plugin_types(); + libwiretap_plugins = plugins_init("wiretap"); + g_slist_foreach(wtap_plugins, call_plugin_register_wtap_module, NULL); #endif } @@ -1495,6 +1448,12 @@ wtap_cleanup(void) wtap_opttypes_cleanup(); ws_buffer_cleanup(); cleanup_open_routines(); +#ifdef HAVE_PLUGINS + g_slist_free(wtap_plugins); + wtap_plugins = NULL; + plugins_cleanup(libwiretap_plugins); + libwiretap_plugins = NULL; +#endif } /* diff --git a/wiretap/wtap.h b/wiretap/wtap.h index 567c961e24..4e11751d4c 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -29,6 +29,9 @@ #include "wtap_opttypes.h" #include "ws_symbol_export.h" #include "ws_attributes.h" +#ifdef HAVE_PLUGINS +#include "wsutil/plugins.h" +#endif #ifdef __cplusplus extern "C" { @@ -2002,10 +2005,17 @@ GSList *wtap_get_file_extension_type_extensions(guint extension_type); /*** dynamically register new file types and encapsulations ***/ WS_DLL_PUBLIC -void register_all_wiretap_modules(void); -WS_DLL_PUBLIC void wtap_register_file_type_extension(const struct file_extension_info *ei); +#ifdef HAVE_PLUGINS +typedef struct { + void (*register_wtap_module)(void); /* routine to call to register a wiretap module */ +} wtap_plugin; + +WS_DLL_PUBLIC +void wtap_register_plugin(const wtap_plugin *plug); +#endif + WS_DLL_PUBLIC void wtap_register_open_info(struct open_info *oi, const gboolean first_routine); WS_DLL_PUBLIC |