diff options
Diffstat (limited to 'epan')
-rw-r--r-- | epan/CMakeLists.txt | 1 | ||||
-rw-r--r-- | epan/Makefile.common | 2 | ||||
-rw-r--r-- | epan/epan.c | 14 | ||||
-rw-r--r-- | epan/epan.h | 10 | ||||
-rw-r--r-- | epan/packet.c | 1 | ||||
-rw-r--r-- | epan/plugins.c | 575 | ||||
-rw-r--r-- | epan/plugins.h | 84 | ||||
-rw-r--r-- | epan/proto.c | 93 | ||||
-rw-r--r-- | epan/proto.h | 4 | ||||
-rw-r--r-- | epan/tap.c | 73 | ||||
-rw-r--r-- | epan/tap.h | 14 | ||||
-rw-r--r-- | epan/wslua/init_wslua.c | 35 | ||||
-rw-r--r-- | epan/wslua/init_wslua.h | 8 |
13 files changed, 242 insertions, 672 deletions
diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt index dea24df3a2..21dd8d2605 100644 --- a/epan/CMakeLists.txt +++ b/epan/CMakeLists.txt @@ -1503,7 +1503,6 @@ set(LIBWIRESHARK_FILES osi-utils.c packet-range.c packet.c - plugins.c print.c prefs.c proto.c diff --git a/epan/Makefile.common b/epan/Makefile.common index b3462760ee..0cb1052e19 100644 --- a/epan/Makefile.common +++ b/epan/Makefile.common @@ -70,7 +70,6 @@ LIBWIRESHARK_SRC = \ osi-utils.c \ packet-range.c \ packet.c \ - plugins.c \ prefs.c \ print.c \ proto.c \ @@ -218,7 +217,6 @@ LIBWIRESHARK_INCLUDES = \ packet.h \ packet_info.h \ params.h \ - plugins.h \ ppptypes.h \ print.h \ prefs.h \ diff --git a/epan/epan.c b/epan/epan.c index 6cb06f4c7b..80a4648e73 100644 --- a/epan/epan.c +++ b/epan/epan.c @@ -74,6 +74,20 @@ epan_get_version(void) { return VERSION; } +/* + * 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) +{ + register_dissector_plugin_type(); + register_tap_plugin_type(); +} + void epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data), void (*register_all_handoffs_func)(register_cb cb, gpointer client_data), diff --git a/epan/epan.h b/epan/epan.h index 44f2d4c51b..9347fb69f7 100644 --- a/epan/epan.h +++ b/epan/epan.h @@ -81,6 +81,16 @@ 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, this is used to be called only once in a program */ WS_DLL_PUBLIC void epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data), diff --git a/epan/packet.c b/epan/packet.c index 0ad68a5547..9befce39d1 100644 --- a/epan/packet.c +++ b/epan/packet.c @@ -47,7 +47,6 @@ #include "addr_resolv.h" #include "tvbuff.h" -#include "plugins.h" #include "epan_dissect.h" #include "emem.h" diff --git a/epan/plugins.c b/epan/plugins.c deleted file mode 100644 index 1104267118..0000000000 --- a/epan/plugins.c +++ /dev/null @@ -1,575 +0,0 @@ -/* plugins.c - * plugin routines - * - * $Id$ - * - * Wireshark - Network traffic analyzer - * By Gerald Combs <gerald@wireshark.org> - * Copyright 1998 Gerald Combs - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" - -#include "plugins.h" -#include <stdio.h> - -/* linked list of Lua plugins */ -wslua_plugin *wslua_plugin_list = NULL; - -#ifdef HAVE_PLUGINS - -#include <time.h> - -#ifdef HAVE_DIRENT_H -#include <dirent.h> -#endif - -#ifdef HAVE_DIRECT_H -#include <direct.h> -#endif - -#include <stdlib.h> -#include <string.h> -#include <errno.h> - -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif - -#include "wsutil/filesystem.h" -#include <wsutil/privileges.h> -#include <wsutil/file_util.h> -#include <wsutil/report_err.h> - -/* linked list of all plugins */ -plugin *plugin_list = NULL; - -static void register_all_wiretap_modules(void); -static void register_all_codecs(void); - -/* - * add a new plugin to the list - * returns : - * - 0 : OK - * - ENOMEM : memory allocation problem - * - EEXIST : the same plugin (i.e. name/version) was already registered. - */ -static int -add_plugin(void *handle, gchar *name, gchar *version, - void (*register_protoinfo)(void), - void (*reg_handoff)(void), - void (*register_tap_listener)(void), - void (*register_wtap_module)(void), - void (*register_codec_module)(void)) -{ - plugin *new_plug, *pt_plug; - - pt_plug = plugin_list; - if (!pt_plug) /* the list is empty */ - { - new_plug = (plugin *)g_malloc(sizeof(plugin)); - if (new_plug == NULL) - return ENOMEM; - plugin_list = new_plug; - } - else - { - while (1) - { - /* check if the same name/version is already registered */ - if (!strcmp(pt_plug->name, name) && - !strcmp(pt_plug->version, version)) - { - return EEXIST; - } - - /* we found the last plugin in the list */ - if (pt_plug->next == NULL) - break; - - pt_plug = pt_plug->next; - } - new_plug = (plugin *)g_malloc(sizeof(plugin)); - if (new_plug == NULL) - return ENOMEM; - pt_plug->next = new_plug; - } - - new_plug->handle = (GModule *)handle; - new_plug->name = name; - new_plug->version = version; - new_plug->register_protoinfo = register_protoinfo; - new_plug->reg_handoff = reg_handoff; - new_plug->register_tap_listener = register_tap_listener; - new_plug->register_wtap_module = register_wtap_module; - new_plug->register_codec_module = register_codec_module; - new_plug->next = NULL; - - return 0; -} - -/* - * XXX - when we remove support for old-style plugins (which we should - * probably do eventually, as all plugins should be written as new-style - * ones), we may want to have "init_plugins()" merely save a pointer - * to the plugin's "init" routine, just as we save a pointer to its - * "reg_handoff" routine, and have a "register_all_plugins()" routine - * to go through the list of plugins and call all of them. - * - * Then we'd have "epan_init()", or perhaps even something higher up - * in the call tree, call "init_plugins()", and have "proto_init()" - * call "register_all_plugins()" right after calling "register_all_protocols()"; - * this might be a bit cleaner. - */ -static void -plugins_scan_dir(const char *dirname) -{ -#define FILENAME_LEN 1024 - WS_DIR *dir; /* scanned directory */ - WS_DIRENT *file; /* current file */ - const char *name; - gchar filename[FILENAME_LEN]; /* current file name */ - GModule *handle; /* handle returned by g_module_open */ - gchar *version; - gpointer gp; - void (*register_protoinfo)(void); - void (*reg_handoff)(void); - void (*register_tap_listener)(void); - void (*register_wtap_module)(void); - void (*register_codec_module)(void); - - gchar *dot; - int cr; - - if ((dir = ws_dir_open(dirname, 0, NULL)) != NULL) - { - while ((file = ws_dir_read_name(dir)) != NULL) - { - name = ws_dir_get_name(file); - - /* - * GLib 2.x defines G_MODULE_SUFFIX as the extension used on - * this platform for loadable modules. - */ - /* skip anything but files with G_MODULE_SUFFIX */ - dot = strrchr(name, '.'); - if (dot == NULL || strcmp(dot+1, G_MODULE_SUFFIX) != 0) - continue; - - g_snprintf(filename, FILENAME_LEN, "%s" G_DIR_SEPARATOR_S "%s", - dirname, name); - if ((handle = g_module_open(filename, (GModuleFlags)0)) == NULL) - { - report_failure("Couldn't load module %s: %s", filename, - g_module_error()); - continue; - } - - if (!g_module_symbol(handle, "version", &gp)) - { - report_failure("The plugin %s has no version symbol", name); - g_module_close(handle); - continue; - } - version = (char *)gp; - - /* - * Do we have a register routine? - */ - if (g_module_symbol(handle, "plugin_register", &gp)) - { - /* - * Yes - this plugin includes one or more dissectors. - */ - register_protoinfo = (void (*)(void))gp; - } - else - { - /* - * No - no dissectors. - */ - register_protoinfo = NULL; - } - - /* - * Do we have a reg_handoff routine? - */ - if (g_module_symbol(handle, "plugin_reg_handoff", &gp)) - { - /* - * Yes. - */ - reg_handoff = (void (*)(void))gp; - } - else - { - /* - * No - that's OK even if we have dissectors, as long - * as the plugin registers by name *and* there's - * a caller looking for that name. - */ - reg_handoff = NULL; - } - - /* - * Do we have a register_tap_listener routine? - */ - if (g_module_symbol(handle, "plugin_register_tap_listener", &gp)) - { - /* - * Yes - this plugin includes one or more taps. - */ - register_tap_listener = (void (*)(void))gp; - } - else - { - /* - * No - no taps here. - */ - register_tap_listener = NULL; - } - - /* - * Do we have an old-style init routine? - */ - if (g_module_symbol(handle, "plugin_init", &gp)) - { - /* - * Yes - do we also have a register routine or a - * register_tap_listener routine? If so, this is a bogus - * hybrid of an old-style and new-style plugin. - */ - if (register_protoinfo != NULL || register_tap_listener != NULL) - { - report_failure("The plugin '%s' has an old plugin init routine\nand a new register or register_tap_listener routine.", - name); - g_module_close(handle); - continue; - } - - /* - * It's just an unsupported old-style plugin; - */ - report_failure("The plugin '%s' has an old plugin init routine. Support has been dropped.\n Information on how to update your plugin is available at \nhttp://anonsvn.wireshark.org/wireshark/trunk/doc/README.plugins", - name); - g_module_close(handle); - continue; - } - - /* - * Do we have a register_wtap_module routine? - */ - if (g_module_symbol(handle, "register_wtap_module", &gp)) - { - register_wtap_module = (void (*)(void))gp; - } - else - { - register_wtap_module = NULL; - } - - /* - * Do we have a register_codec_module routine? - */ - if (g_module_symbol(handle, "register_codec_module", &gp)) - { - register_codec_module = (void (*)(void))gp; - } - else - { - register_codec_module = NULL; - } - - /* - * Does this dissector do anything useful? - */ - if (register_protoinfo == NULL && - register_tap_listener == NULL && - register_wtap_module == NULL && - register_codec_module == NULL ) - { - /* - * No. - */ - report_failure("The plugin '%s' has neither a register routine, " - "a register_tap_listener or a register_wtap_module or a register_codec_module routine", - name); - g_module_close(handle); - continue; - } - - /* - * OK, attempt to add it to the list of plugins. - */ - if ((cr = add_plugin(handle, g_strdup(name), version, - register_protoinfo, reg_handoff, - register_tap_listener,register_wtap_module,register_codec_module))) - { - if (cr == EEXIST) - fprintf(stderr, "The plugin %s, version %s\n" - "was found in multiple directories\n", name, version); - else - fprintf(stderr, "Memory allocation problem\n" - "when processing plugin %s, version %s\n", - name, version); - g_module_close(handle); - continue; - } - - } - ws_dir_close(dir); - } -} - - -/* - * init plugins - */ -void -init_plugins(void) -{ - const char *plugin_dir; - const char *name; - char *plugin_dir_path; - char *plugins_pers_dir; - WS_DIR *dir; /* scanned directory */ - WS_DIRENT *file; /* current file */ - - if (plugin_list == NULL) /* ensure init_plugins is only run once */ - { - /* - * Scan the global plugin directory. - * If we're running from a build directory, scan the subdirectories - * of that directory, as the global plugin directory is the - * "plugins" directory of the source tree, and the subdirectories - * are the source directories for the plugins, with the plugins - * built in those subdirectories. - */ - plugin_dir = get_plugin_dir(); - if (running_in_build_directory()) - { - if ((dir = ws_dir_open(plugin_dir, 0, NULL)) != NULL) - { - while ((file = ws_dir_read_name(dir)) != NULL) - { - name = ws_dir_get_name(file); - if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) - continue; /* skip "." and ".." */ - /* - * Get the full path of a ".libs" subdirectory of that - * directory. - */ - plugin_dir_path = g_strdup_printf( - "%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S ".libs", - plugin_dir, name); - if (test_for_directory(plugin_dir_path) != EISDIR) { - /* - * Either it doesn't refer to a directory or it - * refers to something that doesn't exist. - * - * Assume that means that the plugins are in - * the subdirectory of the plugin directory, not - * a ".libs" subdirectory of that subdirectory. - */ - g_free(plugin_dir_path); - plugin_dir_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", - plugin_dir, name); - } - plugins_scan_dir(plugin_dir_path); - g_free(plugin_dir_path); - } - ws_dir_close(dir); - } - } - else - plugins_scan_dir(plugin_dir); - - /* - * If the program wasn't started with special privileges, - * scan the users plugin directory. (Even if we relinquish - * them, plugins aren't safe unless we've *permanently* - * relinquished them, and we can't do that in Wireshark as, - * if we need privileges to start capturing, we'd need to - * reclaim them before each time we start capturing.) - */ - if (!started_with_special_privs()) - { - plugins_pers_dir = get_plugins_pers_dir(); - plugins_scan_dir(plugins_pers_dir); - g_free(plugins_pers_dir); - } - } - - register_all_wiretap_modules(); - register_all_codecs(); -} - -void -register_all_plugin_registrations(void) -{ - plugin *pt_plug; - - /* - * For all plugins with register-handoff routines, call the routines. - * This is called from "proto_init()"; it must be called after - * "register_all_protocols()" and "init_plugins()" are called, - * in case one plugin registers itself either with a built-in - * dissector or with another plugin; we must first register all - * dissectors, whether built-in or plugin, so their dissector tables - * are initialized, and only then register all handoffs. - */ - for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next) - { - if (pt_plug->register_protoinfo) - (pt_plug->register_protoinfo)(); - } -} - -void -register_all_plugin_handoffs(void) -{ - plugin *pt_plug; - - /* - * For all plugins with register-handoff routines, call the routines. - * This is called from "proto_init()"; it must be called after - * "register_all_protocols()" and "init_plugins()" are called, - * in case one plugin registers itself either with a built-in - * dissector or with another plugin; we must first register all - * dissectors, whether built-in or plugin, so their dissector tables - * are initialized, and only then register all handoffs. - */ - for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next) - { - if (pt_plug->reg_handoff) - (pt_plug->reg_handoff)(); - } -} - -void -register_all_plugin_tap_listeners(void) -{ - plugin *pt_plug; - - /* - * For all plugins with register-tap-listener routines, call the - * routines. - */ - for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next) - { - if (pt_plug->register_tap_listener) - (pt_plug->register_tap_listener)(); - } -} - -static void -register_all_wiretap_modules(void) -{ - plugin *pt_plug; - - /* - * For all plugins with register_wtap_module routines, call the - * routines. - */ - for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next) - { - if (pt_plug->register_wtap_module) - (pt_plug->register_wtap_module)(); - } -} - -static void -register_all_codecs(void) -{ - plugin *pt_plug; - - /* - * For all plugins with register_wtap_module routines, call the - * routines. - */ - for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next) - { - if (pt_plug->register_codec_module) - (pt_plug->register_codec_module)(); - } -} - -#endif /* big HAVE_PLUGINS */ - -/* - * Dump plugin info to stdout. Copied from ui/gtk/plugins_dlg.c:plugins_scan. - */ -void -plugins_dump_all(void) -{ -#ifdef HAVE_PLUGINS - plugin *pt_plug; - const char *sep; -#endif -#ifdef HAVE_LUA - wslua_plugin *lua_plug; -#endif - -#ifdef HAVE_PLUGINS - for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next) - { - sep = ""; - - printf("%s\t%s\t", pt_plug->name, pt_plug->version); - if (pt_plug->register_protoinfo) - { - printf("dissector"); - sep = ", "; - } - if (pt_plug->register_tap_listener) - { - printf("%stap", sep); - sep = ", "; - } - if (pt_plug->register_wtap_module) - { - printf("%sfile format", sep); - sep = ", "; - } - if (pt_plug->register_codec_module) - { - printf("%scodec", sep); - } - printf("\t%s\n", g_module_name(pt_plug->handle)); - } -#endif - -#ifdef HAVE_LUA - for (lua_plug = wslua_plugin_list; lua_plug != NULL; lua_plug = lua_plug->next) - { - printf("%s\t%s\tlua script\t%s\n", lua_plug->name, lua_plug->version, lua_plug->filename); - } -#endif -} - -/* - * Editor modelines - * - * Local Variables: - * c-basic-offset: 4 - * tab-width: 8 - * indent-tabs-mode: nil - * End: - * - * ex: set shiftwidth=4 tabstop=8 expandtab: - * :indentSize=4:tabSize=8:noTabs=true: - */ diff --git a/epan/plugins.h b/epan/plugins.h deleted file mode 100644 index 10a4f5bfff..0000000000 --- a/epan/plugins.h +++ /dev/null @@ -1,84 +0,0 @@ -/* plugins.h - * definitions for plugins structures - * - * $Id$ - * - * Wireshark - Network traffic analyzer - * By Gerald Combs <gerald@wireshark.org> - * Copyright 1998 Gerald Combs - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef __PLUGINS_H__ -#define __PLUGINS_H__ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#include <glib.h> -#include <gmodule.h> - -#include "packet.h" -#include "ws_symbol_export.h" - -typedef struct _plugin { - GModule *handle; /* handle returned by g_module_open */ - gchar *name; /* plugin name */ - gchar *version; /* plugin version */ - void (*register_protoinfo)(void); /* routine to call to register protocol information */ - void (*reg_handoff)(void); /* routine to call to register dissector handoff */ - void (*register_tap_listener)(void); /* routine to call to register tap listener */ - void (*register_wtap_module)(void); /* routine to call to register a wiretap module */ - void (*register_codec_module)(void); /* routine to call to register a codec */ - struct _plugin *next; /* forward link */ -} plugin; - -WS_DLL_PUBLIC plugin *plugin_list; - -extern void init_plugins(void); -extern void register_all_plugin_registrations(void); -extern void register_all_plugin_handoffs(void); -WS_DLL_PUBLIC void register_all_plugin_tap_listeners(void); -WS_DLL_PUBLIC void plugins_dump_all(void); - -typedef struct _wslua_plugin { - gchar *name; /**< plugin name */ - gchar *version; /**< plugin version */ - gchar *filename; /**< plugin filename */ - struct _wslua_plugin *next; -} wslua_plugin; - -WS_DLL_PUBLIC wslua_plugin *wslua_plugin_list; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __PLUGINS_H__ */ - -/* - * Editor modelines - * - * Local Variables: - * c-basic-offset: 4 - * tab-width: 8 - * indent-tabs-mode: nil - * End: - * - * ex: set shiftwidth=4 tabstop=8 expandtab: - * :indentSize=4:tabSize=8:noTabs=true: - */ diff --git a/epan/proto.c b/epan/proto.c index f5c1f4205e..f3df3254a6 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -41,7 +41,6 @@ #include "strutil.h" #include "addr_resolv.h" #include "oids.h" -#include "plugins.h" #include "proto.h" #include "epan_dissect.h" #include "tvbuff.h" @@ -57,6 +56,8 @@ #include "wspython/wspy_register.h" +#include <wsutil/plugins.h> + #define SUBTREE_ONCE_ALLOCATION_NUMBER 8 #define SUBTREE_MAX_LEVELS 256 /* Throw an exception if we exceed this many tree items. */ @@ -324,6 +325,87 @@ proto_compare_name(gconstpointer p1_arg, gconstpointer p2_arg) return g_ascii_strcasecmp(p1->short_name, p2->short_name); } +#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. + */ +static gboolean +check_for_dissector_plugin(GModule *handle) +{ + 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 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_append(dissector_plugins, plugin); + return TRUE; +} + +static void +register_dissector_plugin(gpointer data, gpointer user_data _U_) +{ + dissector_plugin *plugin = (dissector_plugin *)data; + + if (plugin->register_protoinfo) + (plugin->register_protoinfo)(); +} + +static void +reg_handoff_dissector_plugin(gpointer data, gpointer user_data _U_) +{ + dissector_plugin *plugin = (dissector_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); +} +#endif /* HAVE_PLUGINS */ /* initialize data structures and register protocols and fields */ void @@ -368,12 +450,11 @@ proto_init(void (register_all_protocols_func)(register_cb cb, gpointer client_da #endif #ifdef HAVE_PLUGINS - /* Now scan for plugins and load all the ones we find, calling - their register routines to do the stuff described above. */ + /* Now call the registration routines for all disssector + plugins. */ if (cb) (*cb)(RA_PLUGIN_REGISTER, NULL, client_data); - init_plugins(); - register_all_plugin_registrations(); + g_slist_foreach(dissector_plugins, register_dissector_plugin, NULL); #endif /* Now call the "handoff registration" routines of all built-in @@ -393,7 +474,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); - register_all_plugin_handoffs(); + g_slist_foreach(dissector_plugins, reg_handoff_dissector_plugin, NULL); #endif /* sort the protocols by protocol name */ diff --git a/epan/proto.h b/epan/proto.h index ad12588f6f..0578325d17 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -603,6 +603,10 @@ WS_DLL_PUBLIC void proto_tree_children_foreach(proto_tree *tree, /** Retrieve the wmem_allocator_t from a proto_node */ #define PNODE_POOL(proto_node) ((proto_node)->tree_data->pinfo->pool) +/** 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); + /** Sets up memory used by proto routines. Called at program startup */ void proto_init(void (register_all_protocols_func)(register_cb cb, gpointer client_data), void (register_all_handoffs_func)(register_cb cb, gpointer client_data), diff --git a/epan/tap.c b/epan/tap.c index 7ac5e54bc6..f4036afdb6 100644 --- a/epan/tap.c +++ b/epan/tap.c @@ -77,6 +77,77 @@ typedef struct _tap_listener_t { } 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. + */ +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_append(tap_plugins, plugin); + return TRUE; +} + +void +register_tap_plugin_type(void) +{ + add_plugin_type("tap", check_for_tap_plugin); +} + +static void +register_tap_plugin_listener(gpointer data, gpointer user_data _U_) +{ + tap_plugin *plugin = (tap_plugin *)data; + + (plugin->register_tap_listener_fn)(); +} + +/* + * For all tap plugins, call their register routines. + */ +void +register_all_plugin_tap_listeners(void) +{ + g_slist_foreach(tap_plugins, register_tap_plugin_listener, NULL); +} +#endif /* HAVE_PLUGINS */ + /* ********************************************************************** * Init routine only called from epan at application startup * ********************************************************************** */ @@ -87,8 +158,6 @@ void tap_init(void) { tap_packet_index=0; - - return; } /* ********************************************************************** diff --git a/epan/tap.h b/epan/tap.h index b95b98df94..692cd39c22 100644 --- a/epan/tap.h +++ b/epan/tap.h @@ -46,6 +46,20 @@ typedef void (*tap_draw_cb)(void *tapdata); #define TL_IS_DISSECTOR_HELPER 0x00000004 /**< tap helps a dissector do work ** but does not, itself, require dissection */ +/** 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); + +/* + * For all tap plugins, call their register routines. + * Must be called after init_plugins(), and must be called only once in + * a program. + * + * XXX - should probably be handled by epan_init(), as the tap mechanism + * is part of libwireshark. + */ +WS_DLL_PUBLIC void register_all_plugin_tap_listeners(void); + extern void tap_init(void); /** This function registers that a dissector has the packet tap ability diff --git a/epan/wslua/init_wslua.c b/epan/wslua/init_wslua.c index afee46d91c..0f353e48e2 100644 --- a/epan/wslua/init_wslua.c +++ b/epan/wslua/init_wslua.c @@ -34,10 +34,19 @@ #include <math.h> #include <epan/expert.h> #include <epan/ex-opt.h> -#include <epan/plugins.h> #include <wsutil/privileges.h> #include <wsutil/file_util.h> +/* linked list of Lua plugins */ +typedef struct _wslua_plugin { + gchar *name; /**< plugin name */ + gchar *version; /**< plugin version */ + gchar *filename; /**< plugin filename */ + struct _wslua_plugin *next; +} wslua_plugin; + +static wslua_plugin *wslua_plugin_list = NULL; + static lua_State* L = NULL; packet_info* lua_pinfo; @@ -360,6 +369,30 @@ int wslua_count_plugins(void) { return plugins_counter; } +void wslua_plugins_get_descriptions(wslua_plugin_description_callback callback, void *user_data) { + wslua_plugin *lua_plug; + + for (lua_plug = wslua_plugin_list; lua_plug != NULL; lua_plug = lua_plug->next) + { + callback(lua_plug->name, lua_plug->version, "lua script", + lua_plug->filename, user_data); + } +} + +static void +print_wslua_plugin_description(const char *name, const char *version, + const char *description, const char *filename, + void *user_data _U_) +{ + printf("%s\t%s\t%s\t%s\n", name, version, description, filename); +} + +void +wslua_plugins_dump_all(void) +{ + wslua_plugins_get_descriptions(print_wslua_plugin_description, NULL); +} + int wslua_init(register_cb cb, gpointer client_data) { gchar* filename; const funnel_ops_t* ops = funnel_get_funnel_ops(); diff --git a/epan/wslua/init_wslua.h b/epan/wslua/init_wslua.h index 9072e6b9b1..72d083eb96 100644 --- a/epan/wslua/init_wslua.h +++ b/epan/wslua/init_wslua.h @@ -25,6 +25,14 @@ #ifndef __INIT_WSLUA_H__ #define __INIT_WSLUA_H__ +#include "ws_symbol_export.h" + WS_DLL_PUBLIC int wslua_count_plugins(void); +typedef void (*wslua_plugin_description_callback)(const char *, const char *, + const char *, const char *, + void *); +WS_DLL_PUBLIC void wslua_plugins_get_descriptions(wslua_plugin_description_callback callback, void *user_data); +WS_DLL_PUBLIC void wslua_plugins_dump_all(void); + #endif /* __INIT_WSLUA_H__ */ |