diff options
author | Guy Harris <guy@alum.mit.edu> | 2013-12-02 08:30:29 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2013-12-02 08:30:29 +0000 |
commit | 0cc1545d05be6f655c950904b1da776190f3af16 (patch) | |
tree | b82725615b527304bfb2e9e7d9f3b6dfc50ce7fd /wiretap/wtap.c | |
parent | baf569188ac49ad38912b82d23ff241321cd654f (diff) |
Move most of the plugin code from epan to wsutil and remove all
knowledge of particular types of plugins. Instead, let particular types
of plugins register with the common plugin code, giving a name and a
routine to recognize that type of plugin.
In particular applications, only process the relevant plugin types.
Add a Makefile.common to the codecs directory.
svn path=/trunk/; revision=53710
Diffstat (limited to 'wiretap/wtap.c')
-rw-r--r-- | wiretap/wtap.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/wiretap/wtap.c b/wiretap/wtap.c index c932d24c86..712a11b7da 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -43,6 +43,75 @@ #include <wsutil/file_util.h> #include "buffer.h" +#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 GSList *wtap_plugins = NULL; + +/* + * Callback for each plugin found. + */ +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_append(wtap_plugins, plugin); + return TRUE; +} + +void +wtap_register_plugin_types(void) +{ + add_plugin_type("file format", check_for_wtap_plugin); +} + +static void +register_wtap_module_plugin(gpointer data, gpointer user_data _U_) +{ + wtap_plugin *plugin = (wtap_plugin *)data; + + (plugin->register_wtap_module)(); +} + +/* + * 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); +} +#endif /* HAVE_PLUGINS */ + /* * Return the size of the file, as reported by the OS. * (gint64, in case that's 64 bits.) |