diff options
author | Guy Harris <guy@alum.mit.edu> | 2001-01-28 21:17:29 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2001-01-28 21:17:29 +0000 |
commit | cc74cc0a5ff013512ae2157f70d0a5d32c3302cc (patch) | |
tree | 96b4f79629bd08207bb9f39f42a01193b6b22f59 /epan/plugins.c | |
parent | 7eaadf404879210df9e33309e3f3db2c72e56fc6 (diff) |
Get rid of support for old-style plugins (support for old-style plugins
requires that the dfilter code be initialized before the plugins are
added; this required us to *re*-initialize the dfilter code after
reading in all the plugins, as the plugins may themselves have added new
filterable fields - that was a bit of a mess), and make the
"Tools->Plugins" dialog box show the new-style plugins.
svn path=/trunk/; revision=2950
Diffstat (limited to 'epan/plugins.c')
-rw-r--r-- | epan/plugins.c | 413 |
1 files changed, 21 insertions, 392 deletions
diff --git a/epan/plugins.c b/epan/plugins.c index 410362b7dd..c61f32d1c2 100644 --- a/epan/plugins.c +++ b/epan/plugins.c @@ -1,7 +1,7 @@ /* plugins.c * plugin routines * - * $Id: plugins.c,v 1.20 2001/01/28 20:26:19 guy Exp $ + * $Id: plugins.c,v 1.21 2001/01/28 21:17:28 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -54,10 +54,6 @@ #include <sys/types.h> #endif -#ifdef HAVE_FCNTL_H -#include <fcntl.h> -#endif - #ifdef HAVE_UNISTD_H #include <unistd.h> #endif @@ -71,24 +67,6 @@ static plugin_address_table_t patable; /* linked list of all plugins */ plugin *plugin_list; -guint32 enabled_plugins_number; - -/* - * New-style plugins, which don't have an enabled flag (you use the - * standard mechanism for enabling and disabling protocols), and which - * don't have a protocol or filter string (you use the register handoff - * mechanism). - */ -typedef struct _new_plugin { - GModule *handle; /* handle returned by dlopen */ - gchar *name; /* plugin name */ - gchar *version; /* plugin version */ - void (*reg_handoff)(void); /* routine to call to register dissector handoff */ - struct _new_plugin *next; /* forward link */ -} new_plugin; - -/* linked list of all new-style plugins */ -static new_plugin *new_plugin_list; #ifdef WIN32 static gchar std_plug_dir[] = "c:/program files/ethereal/plugins/" VERSION; @@ -98,9 +76,7 @@ static gchar std_plug_dir[] = "/usr/lib/ethereal/plugins/" VERSION; static gchar local_plug_dir[] = "/usr/local/lib/ethereal/plugins/" VERSION; #endif static gchar *user_plug_dir = NULL; -static gchar *plugin_status_file = NULL; -#define PLUGINS_STATUS "plugins.status" #define PLUGINS_DIR_NAME "plugins" /* @@ -110,13 +86,9 @@ static gchar *plugin_status_file = NULL; * - ENOMEM : memory allocation problem * - EEXIST : the same plugin (i.e. name/version) was already registered. */ -int -add_plugin(void *handle, gchar *name, gchar *version, gchar *protocol, - gchar *filter_string, dfilter *filter, - void (*dissector) (const u_char *, - int, - frame_data *, - proto_tree *)) +static int +add_plugin(void *handle, gchar *name, gchar *version, + void (*reg_handoff)(void)) { plugin *new_plug, *pt_plug; @@ -151,297 +123,12 @@ add_plugin(void *handle, gchar *name, gchar *version, gchar *protocol, new_plug->handle = handle; new_plug->name = name; new_plug->version = version; - new_plug->enabled = FALSE; - new_plug->protocol = protocol; - new_plug->filter_string = g_strdup(filter_string); - new_plug->filter = filter; - new_plug->dissector = dissector; - new_plug->next = NULL; - return 0; -} - -/* - * enable a plugin - * returns a pointer to the enabled plugin, or NULL if the plugin wasn't found - * in the list - */ -void * -enable_plugin(const gchar *name, const gchar *version) -{ - plugin *pt_plug; - - pt_plug = plugin_list; - while (pt_plug) - { - if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version)) - { - pt_plug->enabled = TRUE; - enabled_plugins_number++; - return pt_plug; - } - pt_plug = pt_plug->next; - } - return NULL; -} - -/* - * disable a plugin - * returns a pointer to the disabled plugin, or NULL if the plugin wasn't found - * in the list - */ -void * -disable_plugin(const gchar *name, const gchar *version) -{ - plugin *pt_plug; - - pt_plug = plugin_list; - while (pt_plug) - { - if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version)) - { - pt_plug->enabled = FALSE; - enabled_plugins_number--; - return pt_plug; - } - pt_plug = pt_plug->next; - } - return NULL; -} - -/* - * find a plugin using its name/version - */ -void * -find_plugin(const gchar *name, const gchar *version) -{ - plugin *pt_plug; - - pt_plug = plugin_list; - while (pt_plug) - { - if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version)) - { - return pt_plug; - } - pt_plug = pt_plug->next; - } - return NULL; -} - -/* - * check if a plugin is enabled - */ -gboolean -is_enabled(const gchar *name, const gchar *version) -{ - plugin *pt_plug; - - pt_plug = plugin_list; - while (pt_plug) - { - if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version)) - return pt_plug->enabled; - pt_plug = pt_plug->next; - } - return FALSE; -} - -/* - * replace the filter used by a plugin (filter string and dfilter) - */ -void -plugin_replace_filter(const gchar *name, const gchar *version, - const gchar *filter_string, dfilter *filter) -{ - plugin *pt_plug; - - pt_plug = plugin_list; - while (pt_plug) - { - if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version)) - { - g_free(pt_plug->filter_string); - pt_plug->filter_string = g_strdup(filter_string); - dfilter_destroy(pt_plug->filter); - pt_plug->filter = filter; - return; - } - pt_plug = pt_plug->next; - } -} - -/* - * save plugin status, returns 0 on success, -1 on failure: - * file format : - * for each plugin, two lines are saved : - * plugin_name plugin_version [0|1] (0: disabled, 1: enabled) - * filter_string - * - * Ex : - * gryphon.so 0.8.0 1 - * tcp.port == 7000 - */ - -int -save_plugin_status(void) -{ - gchar *pf_path; - FILE *statusfile; - plugin *pt_plug; - - if (!plugin_status_file) { - plugin_status_file = (gchar *)g_malloc(strlen(get_home_dir()) + - strlen(PF_DIR) + - strlen(PLUGINS_STATUS) + 3); - sprintf(plugin_status_file, "%s/%s/%s", - get_home_dir(), PF_DIR, PLUGINS_STATUS); - } - statusfile=fopen(plugin_status_file, "w"); - if (!statusfile) { - pf_path = g_malloc(strlen(get_home_dir()) + strlen(PF_DIR) + 2); - sprintf(pf_path, "%s/%s", get_home_dir(), PF_DIR); -#ifdef WIN32 - mkdir(pf_path); -#else - mkdir(pf_path, 0755); -#endif - g_free(pf_path); - statusfile=fopen(plugin_status_file, "w"); - if (!statusfile) return -1; - } - - pt_plug = plugin_list; - while (pt_plug) - { - fprintf(statusfile,"%s %s %s\n%s\n", pt_plug->name, pt_plug->version, - (pt_plug->enabled ? "1" : "0"), pt_plug->filter_string); - pt_plug = pt_plug->next; - } - fclose(statusfile); - return 0; -} - -/* - * Check if the status of this plugin has been saved. - * If necessary, enable the plugin, and change the filter. - */ -static void -check_plugin_status(gchar *name, gchar *version, GModule *handle, - gchar *filter_string, FILE *statusfile) -{ - gchar *ref_string; - guint16 ref_string_len; - gchar line[512]; - dfilter *filter; - - if (!statusfile) return; - - ref_string = (gchar *)g_malloc(strlen(name) + strlen(version) + 2); - ref_string_len = sprintf(ref_string, "%s %s", name, version); - - while (!feof(statusfile)) - { - if (fgets(line, 512, statusfile) == NULL) return; - if (strncmp(line, ref_string, ref_string_len) != 0) { /* not the right plugin */ - if (fgets(line, 512, statusfile) == NULL) return; - } - else { /* found the plugin */ - if (line[ref_string_len+1] == '1') { - if (init_plugin(name, version) != NULL) - return; - } - - if (fgets(line, 512, statusfile) == NULL) return; - if (line[strlen(line)-1] == '\n') line[strlen(line)-1] = '\0'; - /* only compile the new filter if it is different from the default */ - if (strcmp(line, filter_string) && dfilter_compile(line, &filter) == 0) - plugin_replace_filter(name, version, line, filter); - return; - } - } - g_free(ref_string); -} - -/* - * add a new new-style plugin to the list - * returns : - * - 0 : OK - * - ENOMEM : memory allocation problem - * - EEXIST : the same plugin (i.e. name/version) was already registered. - */ -static int -new_add_plugin(void *handle, gchar *name, gchar *version, - void (*reg_handoff)(void)) -{ - new_plugin *new_plug, *pt_plug; - - pt_plug = new_plugin_list; - if (!pt_plug) /* the list is empty */ - { - new_plug = (new_plugin *)g_malloc(sizeof(new_plugin)); - if (new_plug == NULL) return ENOMEM; - new_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 = (new_plugin *)g_malloc(sizeof(new_plugin)); - if (new_plug == NULL) return ENOMEM; - pt_plug->next = new_plug; - } - - new_plug->handle = handle; - new_plug->name = name; - new_plug->version = version; new_plug->reg_handoff = reg_handoff; new_plug->next = NULL; return 0; } /* - * Initialize a plugin. - * Returns NULL on success, pointer to an error message on error. - */ -char * -init_plugin(gchar *name, gchar *version) -{ - plugin *pt_plug; - gpointer symbol; - void (*plugin_init)(void*); - - /* Try to find the plugin. */ - if ((pt_plug = enable_plugin(name, version)) == NULL) - return "Plugin not found"; - - /* Try to get the initialization routine for the plugin. */ - if (!g_module_symbol(pt_plug->handle, "plugin_init", &symbol)) - return "Failed to find plugin_init()"; - plugin_init = symbol; - - /* We found it; now call it. */ -#ifdef PLUGINS_NEED_ADDRESS_TABLE - plugin_init(&patable); -#else - plugin_init(NULL); -#endif - - return NULL; -} - -/* * 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 @@ -468,13 +155,8 @@ plugins_scan_dir(const char *dirname) gchar *version; void (*init)(void *); void (*reg_handoff)(void); - gchar *protocol; - gchar *filter_string; gchar *dot; - dfilter *filter = NULL; - void (*dissector) (const u_char *, int, frame_data *, proto_tree *); int cr; - FILE *statusfile; /* * We find the extension used on this platform for loadable modules @@ -500,16 +182,6 @@ plugins_scan_dir(const char *dirname) lt_lib_ext = ""; } - if (!plugin_status_file) - { - plugin_status_file = (gchar *)g_malloc(strlen(get_home_dir()) + - strlen(PF_DIR) + - strlen(PLUGINS_STATUS) + 3); - sprintf(plugin_status_file, "%s/%s/%s", - get_home_dir(), PF_DIR, PLUGINS_STATUS); - } - statusfile = fopen(plugin_status_file, "r"); - if ((dir = opendir(dirname)) != NULL) { while ((file = readdir(dir)) != NULL) @@ -534,11 +206,11 @@ plugins_scan_dir(const char *dirname) } /* - * If we have a "plugin_reg_handoff()" routine, we don't require - * the plugin to have "protocol", "filter_string", or "dissector" - * variables - we'll call the "plugin_reg_handoff()" routine and - * assume it'll register the dissector with the appropriate - * handoff tables. + * Old-style dissectors don't have a "plugin_reg_handoff()" + * routine; we no longer support them. + * + * New-style dissectors have one, because, otherwise, there's + * no way for them to arrange that they ever be called. */ if (g_module_symbol(handle, "plugin_reg_handoff", (gpointer*)®_handoff)) @@ -557,15 +229,15 @@ plugins_scan_dir(const char *dirname) * We have a "plugin_reg_handoff()" routine, so we don't * need the protocol, filter string, or dissector pointer. */ - if ((cr = new_add_plugin(handle, g_strdup(file->d_name), version, + if ((cr = add_plugin(handle, g_strdup(file->d_name), version, reg_handoff))) { if (cr == EEXIST) - fprintf(stderr, "The plugin : %s, version %s\n" + 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 %sn", + "when processing plugin %s, version %s\n", name, version); g_module_close(handle); continue; @@ -582,59 +254,18 @@ plugins_scan_dir(const char *dirname) } else { - if (g_module_symbol(handle, "protocol", (gpointer*)&protocol) == FALSE) - { - g_warning("The plugin %s has no protocol symbol and no plugin_reg_handoff symbol", name); - g_module_close(handle); - continue; - } - if (g_module_symbol(handle, "filter_string", (gpointer*)&filter_string) == FALSE) - { - g_warning("The plugin %s has no filter_string symbol and no plugin_reg_handoff symbol", name); - g_module_close(handle); - continue; - } - if (dfilter_compile(filter_string, &filter) != 0) - { - g_warning("The plugin %s has a non-compilable filter", name); - g_module_close(handle); - continue; - } - if (g_module_symbol(handle, "dissector", (gpointer*)&dissector) == FALSE) - { - if (filter != NULL) - dfilter_destroy(filter); - g_warning("The plugin %s has no dissector symbol and no plugin_reg_handoff symbol", name); - g_module_close(handle); - continue; - } - - if ((cr = add_plugin(handle, g_strdup(file->d_name), version, - protocol, filter_string, filter, dissector))) - { - 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 %sn", - name, version); - if (filter != NULL) - dfilter_destroy(filter); - g_module_close(handle); - continue; - } - if (statusfile) { - check_plugin_status(file->d_name, version, handle, - filter_string, statusfile); - rewind(statusfile); - } + /* + * This is an old-style dissector; warn that it won't + * be used, as those aren't supported. + */ + fprintf(stderr, + "The plugin %s, version %s is an old-style plugin;\n" + "Those are no longer supported.\n", name, version); } } closedir(dir); } g_free(hack_path); - if (statusfile) fclose(statusfile); } /* @@ -647,8 +278,6 @@ init_plugins(const char *plugin_dir) if (plugin_list == NULL) /* ensure init_plugins is only run once */ { - enabled_plugins_number = 0; - #ifdef PLUGINS_NEED_ADDRESS_TABLE /* Intialize address table */ patable.p_check_col = check_col; @@ -825,7 +454,7 @@ init_plugins(const char *plugin_dir) void register_all_plugin_handoffs(void) { - new_plugin *pt_plug; + plugin *pt_plug; /* * For all new-style plugins, call the register-handoff routine. @@ -840,7 +469,7 @@ register_all_plugin_handoffs(void) * use the standard mechanism for enabling/disabling protocols, not * the plugin-specific mechanism. */ - for (pt_plug = new_plugin_list; pt_plug != NULL; pt_plug = pt_plug->next) + for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next) (pt_plug->reg_handoff)(); } #endif |