The stats tree stuff should ultimately allow us to have plugin taps, so

add infrastructure for them, and display the plugin type (which could be
both dissector *and* tap) in the list of plugins.

svn path=/trunk/; revision=13543
This commit is contained in:
Guy Harris 2005-02-27 22:04:48 +00:00
parent e18e3db225
commit dd4b0b718b
5 changed files with 136 additions and 70 deletions

View File

@ -97,7 +97,7 @@ plugin *plugin_list;
*/
static int
add_plugin(void *handle, gchar *name, gchar *version,
void (*reg_handoff)(void))
void (*reg_handoff)(void), void (*register_tap_listener)(void))
{
plugin *new_plug, *pt_plug;
@ -133,6 +133,7 @@ add_plugin(void *handle, gchar *name, gchar *version,
new_plug->name = name;
new_plug->version = version;
new_plug->reg_handoff = reg_handoff;
new_plug->register_tap_listener = register_tap_listener;
new_plug->next = NULL;
return 0;
}
@ -171,6 +172,7 @@ plugins_scan_dir(const char *dirname)
gpointer gp;
void (*init)(void *);
void (*reg_handoff)(void);
void (*register_tap_listener)(void);
gchar *dot;
int cr;
@ -243,65 +245,92 @@ plugins_scan_dir(const char *dirname)
version = gp;
/*
* 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.
* We require the plugin to have a "plugin_init()" routine.
*/
if (!g_module_symbol(handle, "plugin_init", &gp))
{
g_warning("The plugin %s has no plugin_init routine",
name);
g_module_close(handle);
continue;
}
init = gp;
/*
* Do we have a reg_handoff routine?
*/
if (g_module_symbol(handle, "plugin_reg_handoff", &gp))
{
/*
* Yes - this plugin includes one or more dissectors.
*/
reg_handoff = gp;
/*
* We require it to have a "plugin_init()" routine.
*/
if (!g_module_symbol(handle, "plugin_init", &gp))
{
g_warning("The plugin %s has a plugin_reg_handoff symbol but no plugin_init routine",
name);
g_module_close(handle);
continue;
}
init = gp;
/*
* We have a "plugin_reg_handoff()" routine, so we don't
* need the protocol, filter string, or dissector pointer.
*/
if ((cr = add_plugin(handle, g_strdup(name), version,
reg_handoff)))
{
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;
}
/*
* Call its init routine.
*/
#ifdef PLUGINS_NEED_ADDRESS_TABLE
init(&patable);
#else
init(NULL);
#endif
}
else
{
/*
* This is an old-style dissector; warn that it won't
* be used, as those aren't supported.
* No - no dissectors here.
*/
fprintf(stderr,
"The plugin %s, version %s is an old-style plugin;\n"
"Those are no longer supported.\n", name, version);
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 = gp;
}
else
{
/*
* No - no taps here.
*/
register_tap_listener = NULL;
}
/*
* Does this dissector do anything useful?
*/
if (reg_handoff == NULL && register_tap_listener == NULL)
{
/*
* No.
*/
g_warning("The plugin %s has neither a reg_handoff nor a register_tap_listener 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,
reg_handoff, register_tap_listener)))
{
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;
}
/*
* Call its init routine.
*/
#ifdef PLUGINS_NEED_ADDRESS_TABLE
init(&patable);
#else
init(NULL);
#endif
}
#if GLIB_MAJOR_VERSION < 2
closedir(dir);
@ -404,22 +433,37 @@ init_plugins(const char *plugin_dir)
void
register_all_plugin_handoffs(void)
{
plugin *pt_plug;
plugin *pt_plug;
/*
* For all new-style plugins, call the register-handoff routine.
* 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.
*
* We treat those protocols as always being enabled; they should
* use the standard mechanism for enabling/disabling protocols, not
* the plugin-specific mechanism.
*/
for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
(pt_plug->reg_handoff)();
/*
* 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)();
}
}
#endif

View File

@ -35,6 +35,7 @@ typedef struct _plugin {
gchar *name; /* plugin name */
gchar *version; /* plugin version */
void (*reg_handoff)(void); /* routine to call to register dissector handoff */
void (*register_tap_listener)(void); /* routine to call to register tap listener */
struct _plugin *next; /* forward link */
} plugin;
@ -42,6 +43,7 @@ ETH_VAR_IMPORT plugin *plugin_list;
extern void init_plugins(const char *);
extern void register_all_plugin_handoffs(void);
extern void register_all_plugin_tap_listeners(void);
/* get the global plugin dir */
/* Return value is g_malloced so the caller should g_free() it. */

View File

@ -1630,6 +1630,7 @@ main(int argc, char *argv[])
/* Register all tap listeners; we do this before we parse the arguments,
as the "-z" argument can specify a registered tap. */
register_all_tap_listeners();
register_all_plugin_tap_listeners();
splash_update(splash_win, "Loading module preferences ...");

View File

@ -55,12 +55,30 @@ static void
plugins_scan(GtkWidget *list)
{
plugin *pt_plug;
GString *type;
char *sep;
pt_plug = plugin_list;
while (pt_plug)
{
simple_list_append(list, 0, pt_plug->name, 1, pt_plug->version, -1);
pt_plug = pt_plug->next;
type = g_string_new("");
sep = "";
if (pt_plug->reg_handoff)
{
type = g_string_append(type, sep);
type = g_string_append(type, "dissector");
sep = ",";
}
if (pt_plug->register_tap_listener)
{
type = g_string_append(type, sep);
type = g_string_append(type, "tap");
sep = ",";
}
simple_list_append(list, 0, pt_plug->name, 1, pt_plug->version,
2, type->str, -1);
g_string_free(type, TRUE);
pt_plug = pt_plug->next;
}
}
@ -70,7 +88,7 @@ about_plugins_page_new(void)
{
GtkWidget *scrolledwindow;
GtkWidget *plugins_list;
gchar *titles[] = {"Name", "Version"};
gchar *titles[] = {"Name", "Version", "Type"};
scrolledwindow = scrolled_window_new(NULL, NULL);
@ -79,7 +97,7 @@ about_plugins_page_new(void)
GTK_SHADOW_IN);
#endif
plugins_list = simple_list_new(2, titles);
plugins_list = simple_list_new(3 , titles);
plugins_scan(plugins_list);
gtk_container_add(GTK_CONTAINER(scrolledwindow), plugins_list);

View File

@ -700,6 +700,7 @@ main(int argc, char *argv[])
/* Register all tap listeners; we do this before we parse the arguments,
as the "-z" argument can specify a registered tap. */
register_all_tap_listeners();
register_all_plugin_tap_listeners();
/* Now register the preferences for any non-dissector modules.
We must do that before we read the preferences as well. */