aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2001-01-26 06:14:53 +0000
committerGuy Harris <guy@alum.mit.edu>2001-01-26 06:14:53 +0000
commite7ea7a34e9415d5dda11b9da61dd36e0c1e790d5 (patch)
treee73ffb66b940b64f9c31c97e9555d56f48989cb0
parentf72f3b786190af6c5dff8ff705be17586cb2d5d2 (diff)
Clean up the dissector registration up a bit - arrange that all plugins
be loaded and their initialization routines called in right after we call the initialization routines for built-in dissectors, but don't call their handoff registration routines yet, and then call the handoff registration routines right after calling the handoff registration routines for built-in dissectors. Do all that in "proto_init()", rather than "epan_init()". That way, we call all dissector registration routines together, and then call all dissector handoff registration routines together; all the registration routines are called before any handoff registration routines, as is required, and, as "proto_init()" is called by "epan_init()" before "dfilter_init()" is called, all filterable fields have been registered before "dfilter_init()" is called, and no plugins have to call "dfilter_init()" themselves to get their fields registered. Remove pointers to "dfilter_init()" and "dfilter_cleanup()" from the plugin address table, as plugins shouldn't be calling them any more, and remove calls to them from plugins. svn path=/trunk/; revision=2940
-rw-r--r--epan/epan.c8
-rw-r--r--epan/plugins.c51
-rw-r--r--epan/plugins.h3
-rw-r--r--epan/proto.c31
-rw-r--r--epan/proto.h4
-rw-r--r--plugins/mgcp/packet-mgcp.c7
-rw-r--r--plugins/plugin_api.c4
-rw-r--r--plugins/plugin_api.h6
-rw-r--r--plugins/plugin_table.h8
9 files changed, 67 insertions, 55 deletions
diff --git a/epan/epan.c b/epan/epan.c
index 98b87d9cc2..74f89d9b15 100644
--- a/epan/epan.c
+++ b/epan/epan.c
@@ -1,6 +1,6 @@
/* epan.h
*
- * $Id: epan.c,v 1.4 2000/10/16 23:17:39 guy Exp $
+ * $Id: epan.c,v 1.5 2001/01/26 06:14:50 guy Exp $
*
* Ethereal Protocol Analyzer Library
*
@@ -13,7 +13,6 @@
#include <glib.h>
#include <epan.h>
-#include "plugins.h"
#include "conversation.h"
#include "dfilter.h"
#include "except.h"
@@ -48,11 +47,8 @@ epan_init(const char *plugin_dir)
except_init();
tvbuff_init();
packet_init();
- proto_init();
+ proto_init(plugin_dir);
dfilter_init();
-#ifdef HAVE_PLUGINS
- init_plugins(plugin_dir);
-#endif
}
void
diff --git a/epan/plugins.c b/epan/plugins.c
index 0957e4647a..003935b5aa 100644
--- a/epan/plugins.c
+++ b/epan/plugins.c
@@ -1,7 +1,7 @@
/* plugins.c
* plugin routines
*
- * $Id: plugins.c,v 1.18 2001/01/13 06:34:34 guy Exp $
+ * $Id: plugins.c,v 1.19 2001/01/26 06:14:50 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -441,6 +441,19 @@ init_plugin(gchar *name, gchar *version)
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
+ * 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)
{
@@ -631,7 +644,6 @@ void
init_plugins(const char *plugin_dir)
{
struct stat std_dir_stat, local_dir_stat, plugin_dir_stat;
- new_plugin *pt_plug;
if (plugin_list == NULL) /* ensure init_plugins is only run once */
{
@@ -810,20 +822,27 @@ init_plugins(const char *plugin_dir)
}
plugins_scan_dir(user_plug_dir);
}
-
- /*
- * For all new-style plugins, call the register-handoff routine.
- * (We defer this until after registering all new-style plugins,
- * in case one plugin registers itself with another plugin; we
- * need to register all plugins, so their dissector tables are
- * initialized.)
- *
- * 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 = new_plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
- (pt_plug->reg_handoff)();
}
+void
+register_all_plugin_handoffs(void)
+{
+ new_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 = new_plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
+ (pt_plug->reg_handoff)();
+}
#endif
diff --git a/epan/plugins.h b/epan/plugins.h
index 1d25afb584..6cf329a344 100644
--- a/epan/plugins.h
+++ b/epan/plugins.h
@@ -1,7 +1,7 @@
/* plugins.h
* definitions for plugins structures
*
- * $Id: plugins.h,v 1.4 2000/11/18 21:41:37 guy Exp $
+ * $Id: plugins.h,v 1.5 2001/01/26 06:14:50 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -61,5 +61,6 @@ void plugin_replace_filter(const gchar *, const gchar *, const gchar *, dfilter
char *init_plugin(gchar *name, gchar *version);
int save_plugin_status(void);
void init_plugins(const char *);
+void register_all_plugin_handoffs(void);
#endif /* __PLUGINS_H__ */
diff --git a/epan/proto.c b/epan/proto.c
index f9a48c278b..ad367ca6bd 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -1,7 +1,7 @@
/* proto.c
* Routines for protocol tree
*
- * $Id: proto.c,v 1.4 2001/01/03 06:55:58 guy Exp $
+ * $Id: proto.c,v 1.5 2001/01/26 06:14:50 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -43,6 +43,7 @@
#include "strutil.h"
#include "resolv.h"
#include "register.h"
+#include "plugins.h"
#include "packet-ipv6.h"
#include "proto.h"
@@ -160,7 +161,7 @@ gboolean proto_tree_is_visible = FALSE;
/* initialize data structures and register protocols and fields */
void
-proto_init(void)
+proto_init(const char *plugin_dir)
{
static hf_register_info hf[] = {
{ &hf_text_only,
@@ -196,18 +197,30 @@ proto_init(void)
tree_is_expanded[0] = FALSE;
num_tree_types = 1;
- /* Have each dissector register its protocols and fields, and
- do whatever one-time initialization it needs to do. */
+ /* Have each built-in dissector register its protocols, fields,
+ dissector tables, and dissectors to be called through a
+ handle, and do whatever one-time initialization it needs to
+ do. */
register_all_protocols();
- /* Now have the ones that register a "handoff", i.e. that
- specify that another dissector for a protocol under which
- this dissector's protocol lives call it. */
+#ifdef HAVE_PLUGINS
+ /* Now scan for plugins and load all the ones we find, calling
+ their register routines to do the stuff described above. */
+ init_plugins(plugin_dir);
+#endif
+
+ /* Now call the "handoff registration" routines of all built-in
+ dissectors; those routines register the dissector in other
+ dissectors' handoff tables, and fetch any dissector handles
+ they need. */
register_all_protocol_handoffs();
+ /* Now do the same with plugins. */
+ register_all_plugin_handoffs();
+
/* Register one special-case FT_TEXT_ONLY field for use when
- converting ethereal to new-style proto_tree. These fields
- are merely strings on the GUI tree; they are not filterable */
+ converting ethereal to new-style proto_tree. These fields
+ are merely strings on the GUI tree; they are not filterable */
proto_register_field_array(-1, hf, array_length(hf));
/* We've assigned all the subtree type values; allocate the array
diff --git a/epan/proto.h b/epan/proto.h
index a919f29380..8093ee886a 100644
--- a/epan/proto.h
+++ b/epan/proto.h
@@ -1,7 +1,7 @@
/* proto.h
* Definitions for protocol display
*
- * $Id: proto.h,v 1.3 2001/01/03 06:55:59 guy Exp $
+ * $Id: proto.h,v 1.4 2001/01/26 06:14:50 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -158,7 +158,7 @@ typedef struct field_info {
#define NullTVB NULL
/* Sets up memory used by proto routines. Called at program startup */
-void proto_init(void);
+void proto_init(const char *plugin_dir);
/* Frees memory used by proto routines. Called at program shutdown */
void proto_cleanup(void);
diff --git a/plugins/mgcp/packet-mgcp.c b/plugins/mgcp/packet-mgcp.c
index 020b0710e6..f6559269e2 100644
--- a/plugins/mgcp/packet-mgcp.c
+++ b/plugins/mgcp/packet-mgcp.c
@@ -2,7 +2,7 @@
* Routines for mgcp packet disassembly
* RFC 2705
*
- * $Id: packet-mgcp.c,v 1.15 2001/01/22 08:54:08 guy Exp $
+ * $Id: packet-mgcp.c,v 1.16 2001/01/26 06:14:53 guy Exp $
*
* Copyright (c) 2000 by Ed Warnicke <hagbard@physics.rutgers.edu>
*
@@ -1110,14 +1110,9 @@ G_MODULE_EXPORT void
plugin_init(plugin_address_table_t *pat){
/* initialise the table of pointers needed in Win32 DLLs */
plugin_address_table_init(pat);
- /* destroy the dfilter tree */
- dfilter_cleanup();
/* register the new protocol, protocol fields, and subtrees */
if (proto_mgcp == -1) { /* execute protocol initialization only once */
proto_register_mgcp();
}
- /* initialize the dfilter tree with all the header field and protocol
- * abbrevs defined, including xxx */
- dfilter_init();
}
/* End the functions we need for plugin stuff */
diff --git a/plugins/plugin_api.c b/plugins/plugin_api.c
index f53e2139b1..a076792863 100644
--- a/plugins/plugin_api.c
+++ b/plugins/plugin_api.c
@@ -1,7 +1,7 @@
/* plugin_api.c
* Routines for Ethereal plugins.
*
- * $Id: plugin_api.c,v 1.15 2001/01/13 06:34:35 guy Exp $
+ * $Id: plugin_api.c,v 1.16 2001/01/26 06:14:51 guy Exp $
*
* Ethereal - Network traffic analyzer
* Copyright 2000 by Gilbert Ramirez <gram@xiexie.org>
@@ -44,8 +44,6 @@ plugin_address_table_init(plugin_address_table_t *pat)
p_col_append_fstr = pat->p_col_append_fstr;
p_col_add_str = pat->p_col_add_str;
p_col_append_str = pat->p_col_append_str;
- p_dfilter_init = pat->p_dfilter_init;
- p_dfilter_cleanup = pat->p_dfilter_cleanup;
p_proto_register_protocol = pat->p_proto_register_protocol;
p_proto_register_field_array = pat->p_proto_register_field_array;
p_proto_register_subtree_array = pat->p_proto_register_subtree_array;
diff --git a/plugins/plugin_api.h b/plugins/plugin_api.h
index 6e9d496330..f6e01cf7a0 100644
--- a/plugins/plugin_api.h
+++ b/plugins/plugin_api.h
@@ -1,7 +1,7 @@
/* plugin_api.h
* Routines for Ethereal plugins.
*
- * $Id: plugin_api.h,v 1.15 2001/01/13 06:34:35 guy Exp $
+ * $Id: plugin_api.h,v 1.16 2001/01/26 06:14:51 guy Exp $
*
* Ethereal - Network traffic analyzer
* Copyright 2000 by Gilbert Ramirez <gram@xiexie.org>
@@ -40,9 +40,6 @@
#define col_add_str (*p_col_add_str)
#define col_append_str (*p_col_append_str)
-#define dfilter_init (*p_dfilter_init)
-#define dfilter_cleanup (*p_dfilter_cleanup)
-
#define proto_register_protocol (*p_proto_register_protocol)
#define proto_register_field_array (*p_proto_register_field_array)
#define proto_register_subtree_array (*p_proto_register_subtree_array)
@@ -163,7 +160,6 @@
#include "packet.h"
#include "prefs.h"
-#include "dfilter.h"
#include "plugin_table.h"
diff --git a/plugins/plugin_table.h b/plugins/plugin_table.h
index d2ffa9f17e..175b6a3b56 100644
--- a/plugins/plugin_table.h
+++ b/plugins/plugin_table.h
@@ -1,7 +1,7 @@
/* plugin_table.h
* Table of exported addresses for Ethereal plugins.
*
- * $Id: plugin_table.h,v 1.15 2001/01/13 06:34:35 guy Exp $
+ * $Id: plugin_table.h,v 1.16 2001/01/26 06:14:52 guy Exp $
*
* Ethereal - Network traffic analyzer
* Copyright 2000 by Gilbert Ramirez <gram@xiexie.org>
@@ -36,9 +36,6 @@ typedef void (*addr_col_append_fstr)(frame_data*, gint, gchar*, ...);
typedef void (*addr_col_add_str)(frame_data*, gint, const gchar*);
typedef void (*addr_col_append_str)(frame_data*, gint, gchar*);
-typedef void (*addr_dfilter_init)(void);
-typedef void (*addr_dfilter_cleanup)(void);
-
typedef int (*addr_proto_register_protocol)(char*, char*, char*);
typedef void (*addr_proto_register_field_array)(int, hf_register_info*, int);
typedef void (*addr_proto_register_subtree_array)(int**, int);
@@ -179,9 +176,6 @@ typedef struct {
addr_col_add_str p_col_add_str;
addr_col_append_str p_col_append_str;
- addr_dfilter_init p_dfilter_init;
- addr_dfilter_cleanup p_dfilter_cleanup;
-
packet_info *p_pi;
addr_proto_register_protocol p_proto_register_protocol;