aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
Diffstat (limited to 'epan')
-rw-r--r--epan/packet.c133
-rw-r--r--epan/packet.h29
-rw-r--r--epan/plugins.c3
-rw-r--r--epan/proto.c30
-rw-r--r--epan/proto.h5
5 files changed, 81 insertions, 119 deletions
diff --git a/epan/packet.c b/epan/packet.c
index 131bc21dc2..1b04a0db03 100644
--- a/epan/packet.c
+++ b/epan/packet.c
@@ -1,7 +1,7 @@
/* packet.c
* Routines for packet disassembly
*
- * $Id: packet.c,v 1.47 2001/12/03 01:35:22 guy Exp $
+ * $Id: packet.c,v 1.48 2001/12/03 04:00:14 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -205,21 +205,20 @@ dissect_packet(epan_dissect_t *edt, union wtap_pseudo_header *pseudo_header,
static GHashTable *dissector_tables = NULL;
-typedef struct {
+/*
+ * An dissector handle.
+ */
+struct dissector_handle {
+ const char *name; /* dissector name */
dissector_t dissector;
int proto_index;
-} dissector_entry_t;
+};
struct dtbl_entry {
- dissector_entry_t initial;
- dissector_entry_t current;
+ dissector_handle_t initial;
+ dissector_handle_t current;
};
-static void
-dissect_null(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
-{
-}
-
/* Finds a dissector table by field name. */
static dissector_table_t
find_dissector_table(const char *name)
@@ -229,8 +228,7 @@ find_dissector_table(const char *name)
}
void
-dissector_add(const char *name, guint32 pattern, dissector_t dissector,
- int proto)
+dissector_add(const char *name, guint32 pattern, dissector_handle_t handle)
{
dissector_table_t sub_dissectors = find_dissector_table( name);
dtbl_entry_t *dtbl_entry;
@@ -239,10 +237,8 @@ dissector_add(const char *name, guint32 pattern, dissector_t dissector,
g_assert( sub_dissectors);
dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
- dtbl_entry->current.dissector = dissector;
- dtbl_entry->current.proto_index = proto;
+ dtbl_entry->current = handle;
dtbl_entry->initial = dtbl_entry->current;
- proto_set_protocol_dissector(proto, dissector);
/* do the table insertion */
g_hash_table_insert( sub_dissectors, GUINT_TO_POINTER( pattern),
@@ -257,7 +253,7 @@ dissector_add(const char *name, guint32 pattern, dissector_t dissector,
/* If temporary dissectors are deleted, then the original dissector must */
/* be available. */
void
-dissector_delete(const char *name, guint32 pattern, dissector_t dissector)
+dissector_delete(const char *name, guint32 pattern, dissector_handle_t handle)
{
dissector_table_t sub_dissectors = find_dissector_table( name);
dtbl_entry_t *dtbl_entry;
@@ -285,8 +281,7 @@ dissector_delete(const char *name, guint32 pattern, dissector_t dissector)
}
void
-dissector_change(const char *name, guint32 pattern, dissector_t dissector,
- int proto)
+dissector_change(const char *name, guint32 pattern, dissector_handle_t handle)
{
dissector_table_t sub_dissectors = find_dissector_table( name);
dtbl_entry_t *dtbl_entry;
@@ -300,23 +295,21 @@ dissector_change(const char *name, guint32 pattern, dissector_t dissector,
dtbl_entry = g_hash_table_lookup(sub_dissectors,
GUINT_TO_POINTER(pattern));
if (dtbl_entry != NULL) {
- dtbl_entry->current.dissector = dissector ? dissector : dissect_null;
- dtbl_entry->current.proto_index = proto;
+ dtbl_entry->current = handle;
return;
}
/*
- * Don't create an entry if there is no dissector - I.E. the
+ * Don't create an entry if there is no dissector handle - I.E. the
* user said not to decode something that wasn't being decoded
* in the first place.
*/
- if (dissector == NULL)
+ if (handle == NULL)
return;
dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
- dtbl_entry->initial.proto_index = -1;
- dtbl_entry->current.dissector = dissector;
- dtbl_entry->current.proto_index = proto;
+ dtbl_entry->initial = NULL;
+ dtbl_entry->current = handle;
/* do the table insertion */
g_hash_table_insert( sub_dissectors, GUINT_TO_POINTER( pattern),
@@ -345,7 +338,7 @@ dissector_reset(const char *name, guint32 pattern)
/*
* Found - is there an initial value?
*/
- if (dtbl_entry->initial.dissector != NULL) {
+ if (dtbl_entry->initial != NULL) {
dtbl_entry->current = dtbl_entry->initial;
} else {
g_hash_table_remove(sub_dissectors, GUINT_TO_POINTER(pattern));
@@ -372,10 +365,22 @@ dissector_try_port(dissector_table_t sub_dissectors, guint32 port,
GUINT_TO_POINTER(port));
if (dtbl_entry != NULL) {
/*
- * Is this protocol enabled?
+ * Is there currently a dissector handle for this entry?
*/
- if (dtbl_entry->current.proto_index != -1 &&
- !proto_is_protocol_enabled(dtbl_entry->current.proto_index)) {
+ if (dtbl_entry->current == NULL) {
+ /*
+ * No - pretend this dissector didn't exist,
+ * so that other dissectors might have a chance
+ * to dissect this packet.
+ */
+ return FALSE;
+ }
+
+ /*
+ * Yes - is its protocol enabled?
+ */
+ if (dtbl_entry->current->proto_index != -1 &&
+ !proto_is_protocol_enabled(dtbl_entry->current->proto_index)) {
/*
* No - pretend this dissector didn't exist,
* so that other dissectors might have a chance
@@ -401,11 +406,11 @@ dissector_try_port(dissector_table_t sub_dissectors, guint32 port,
*/
pinfo->can_desegment = saved_can_desegment-(saved_can_desegment>0);
pinfo->match_port = port;
- if (dtbl_entry->current.proto_index != -1) {
+ if (dtbl_entry->current->proto_index != -1) {
pinfo->current_proto =
- proto_get_protocol_short_name(dtbl_entry->current.proto_index);
+ proto_get_protocol_short_name(dtbl_entry->current->proto_index);
}
- (*dtbl_entry->current.dissector)(tvb, pinfo, tree);
+ (*dtbl_entry->current->dissector)(tvb, pinfo, tree);
pinfo->current_proto = saved_proto;
pinfo->match_port = saved_match_port;
pinfo->can_desegment = saved_can_desegment;
@@ -414,18 +419,16 @@ dissector_try_port(dissector_table_t sub_dissectors, guint32 port,
return FALSE;
}
-gint
-dissector_get_proto (dtbl_entry_t *dtbl_entry)
+dissector_handle_t
+dtbl_entry_get_handle (dtbl_entry_t *dtbl_entry)
{
- g_assert(dtbl_entry);
- return(dtbl_entry->current.proto_index);
+ return dtbl_entry->current;
}
-gint
-dissector_get_initial_proto (dtbl_entry_t *dtbl_entry)
+dissector_handle_t
+dtbl_entry_get_initial_handle (dtbl_entry_t *dtbl_entry)
{
- g_assert(dtbl_entry);
- return(dtbl_entry->initial.proto_index);
+ return dtbl_entry->initial;
}
/**************************************************/
@@ -454,8 +457,16 @@ dissector_table_foreach_func (gpointer key, gpointer value, gpointer user_data)
g_assert(user_data);
dtbl_entry = value;
- if (dtbl_entry->current.proto_index == -1) {
- return;
+ if (dtbl_entry->current == NULL ||
+ dtbl_entry->current->proto_index == -1) {
+ /*
+ * Either there is no dissector for this entry, or
+ * the dissector doesn't have a protocol associated
+ * with it.
+ *
+ * XXX - should the latter check be done?
+ */
+ return;
}
info = user_data;
@@ -530,7 +541,7 @@ dissector_table_foreach_changed_func (gpointer key, gpointer value, gpointer use
g_assert(user_data);
dtbl_entry = value;
- if (dtbl_entry->initial.proto_index == dtbl_entry->current.proto_index) {
+ if (dtbl_entry->initial == dtbl_entry->current) {
/*
* Entry hasn't changed - don't call the function.
*/
@@ -695,11 +706,6 @@ register_heur_dissector_list(const char *name, heur_dissector_list_t *sub_dissec
static GHashTable *conv_dissector_lists = NULL;
-struct conv_dtbl_entry {
- dissector_t dissector;
- int proto_index;
-};
-
/* Finds a conversation dissector table by table name. */
static conv_dissector_list_t *
find_conv_dissector_list(const char *name)
@@ -709,21 +715,15 @@ find_conv_dissector_list(const char *name)
}
void
-conv_dissector_add(const char *name, dissector_t dissector, int proto)
+conv_dissector_add(const char *name, dissector_handle_t handle)
{
conv_dissector_list_t *sub_dissectors = find_conv_dissector_list(name);
- conv_dtbl_entry_t *dtbl_entry;
/* sanity check */
g_assert(sub_dissectors != NULL);
- dtbl_entry = g_malloc(sizeof (conv_dtbl_entry_t));
- dtbl_entry->dissector = dissector;
- dtbl_entry->proto_index = proto;
- proto_set_protocol_dissector(proto, dissector);
-
/* do the table insertion */
- *sub_dissectors = g_slist_append(*sub_dissectors, (gpointer)dtbl_entry);
+ *sub_dissectors = g_slist_append(*sub_dissectors, (gpointer)handle);
}
void
@@ -743,13 +743,6 @@ register_conv_dissector_list(const char *name, conv_dissector_list_t *sub_dissec
(gpointer) sub_dissectors);
}
-gint
-conv_dissector_get_proto (conv_dtbl_entry_t *dtbl_entry)
-{
- g_assert(dtbl_entry);
- return(dtbl_entry->proto_index);
-}
-
void
dissector_conv_foreach (char *name,
DATFunc func,
@@ -806,14 +799,12 @@ dissector_all_conv_foreach (DATFunc func,
*/
static GHashTable *registered_dissectors = NULL;
-/*
- * An entry in the list of registered dissectors.
- */
-struct dissector_handle {
- const char *name; /* dissector name */
- dissector_t dissector;
- int proto_index;
-};
+/* Get the short name of the protocol for a dissector handle. */
+char *
+dissector_handle_get_short_name(dissector_handle_t handle)
+{
+ return proto_get_protocol_short_name(handle->proto_index);
+}
/* Find a registered dissector by name. */
dissector_handle_t
diff --git a/epan/packet.h b/epan/packet.h
index 6af0d154af..83f69c2ee2 100644
--- a/epan/packet.h
+++ b/epan/packet.h
@@ -1,7 +1,7 @@
/* packet.h
* Definitions for packet disassembly structures and routines
*
- * $Id: packet.h,v 1.42 2001/11/27 07:13:32 guy Exp $
+ * $Id: packet.h,v 1.43 2001/12/03 04:00:14 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -80,6 +80,11 @@ typedef struct true_false_string {
extern void packet_init(void);
extern void packet_cleanup(void);
+/* Handle for dissectors you call directly or register with "dissector_add()".
+ This handle is opaque outside of "packet.c". */
+struct dissector_handle;
+typedef struct dissector_handle *dissector_handle_t;
+
/* Hash table for matching port numbers and dissectors */
typedef GHashTable* dissector_table_t;
@@ -92,8 +97,8 @@ typedef void (*DATFunc) (gchar *table_name, gpointer key, gpointer value, gpoint
/* Opaque structure - provides type checking but no access to components */
typedef struct dtbl_entry dtbl_entry_t;
-extern gint dissector_get_proto (dtbl_entry_t * entry);
-extern gint dissector_get_initial_proto (dtbl_entry_t * entry);
+extern dissector_handle_t dtbl_entry_get_handle (dtbl_entry_t *dtbl_entry);
+extern dissector_handle_t dtbl_entry_get_initial_handle (dtbl_entry_t * entry);
extern void dissector_table_foreach_changed (char *name, DATFunc func,
gpointer user_data);
extern void dissector_table_foreach (char *name, DATFunc func,
@@ -107,15 +112,15 @@ extern dissector_table_t register_dissector_table(const char *name);
/* Add a sub-dissector to a dissector table. Called by the protocol routine */
/* that wants to register a sub-dissector. */
extern void dissector_add(const char *abbrev, guint32 pattern,
- dissector_t dissector, int proto);
+ dissector_handle_t handle);
/* Add a sub-dissector to a dissector table. Called by the protocol routine */
/* that wants to de-register a sub-dissector. */
extern void dissector_delete(const char *name, guint32 pattern,
- dissector_t dissector);
+ dissector_handle_t handle);
extern void dissector_change(const char *abbrev, guint32 pattern,
- dissector_t dissector, int proto);
+ dissector_handle_t handle);
/* Reset a dissector in a sub-dissector table to its initial value. */
extern void dissector_reset(const char *name, guint32 pattern);
@@ -171,26 +176,22 @@ extern void register_conv_dissector_list(const char *name,
/* Add a sub-dissector to a conversation dissector list. Called by the
protocol routine that wants to register a sub-dissector. */
-extern void conv_dissector_add(const char *name, dissector_t dissector,
- int proto);
+extern void conv_dissector_add(const char *name, dissector_handle_t handle);
/* Opaque structure - provides type checking but no access to components */
typedef struct conv_dtbl_entry conv_dtbl_entry_t;
-extern gint conv_dissector_get_proto (conv_dtbl_entry_t * entry);
extern void dissector_conv_foreach(char *name, DATFunc func,
gpointer user_data);
extern void dissector_all_conv_foreach(DATFunc func, gpointer user_data);
-/* Handle for dissectors you call directly.
- This handle is opaque outside of "packet.c". */
-struct dissector_handle;
-typedef struct dissector_handle *dissector_handle_t;
-
/* Register a dissector. */
extern void register_dissector(const char *name, dissector_t dissector,
int proto);
+/* Get the short name of the protocol for a dissector handle. */
+extern char *dissector_handle_get_short_name(dissector_handle_t handle);
+
/* Find a dissector by name. */
extern dissector_handle_t find_dissector(const char *name);
diff --git a/epan/plugins.c b/epan/plugins.c
index da0509d939..3ba4313d06 100644
--- a/epan/plugins.c
+++ b/epan/plugins.c
@@ -1,7 +1,7 @@
/* plugins.c
* plugin routines
*
- * $Id: plugins.c,v 1.42 2001/11/26 05:41:13 hagbard Exp $
+ * $Id: plugins.c,v 1.43 2001/12/03 04:00:14 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -310,6 +310,7 @@ init_plugins(const char *plugin_dir)
patable.p_register_dissector = register_dissector;
patable.p_find_dissector = find_dissector;
+ patable.p_create_dissector_handle = create_dissector_handle;
patable.p_call_dissector = call_dissector;
patable.p_proto_is_protocol_enabled = proto_is_protocol_enabled;
diff --git a/epan/proto.c b/epan/proto.c
index 284b437627..d2238f9d14 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -1,7 +1,7 @@
/* proto.c
* Routines for protocol tree
*
- * $Id: proto.c,v 1.45 2001/11/22 03:07:06 hagbard Exp $
+ * $Id: proto.c,v 1.46 2001/12/03 04:00:15 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -133,7 +133,6 @@ typedef struct {
GList *last_field; /* pointer to end of list of fields */
gboolean is_enabled; /* TRUE if protocol is enabled */
gboolean can_disable; /* TRUE if protocol can be disabled */
- gpointer dissector;
} protocol_t;
/* List of all protocols */
@@ -1659,7 +1658,6 @@ proto_register_protocol(char *name, char *short_name, char *filter_name)
protocol->fields = NULL;
protocol->is_enabled = TRUE; /* protocol is enabled by default */
protocol->can_disable = TRUE;
- protocol->dissector = NULL;
protocols = g_list_insert_sorted(protocols, protocol,
proto_compare_name);
@@ -1820,32 +1818,6 @@ proto_set_cant_disable(int proto_id)
protocol->can_disable = FALSE;
}
-gpointer
-proto_get_protocol_dissector(int proto_id)
-{
- protocol_t *protocol;
-
- protocol = find_protocol_by_id(proto_id);
- if (protocol == NULL)
- return(NULL);
- return protocol->dissector;
-}
-
-void
-proto_set_protocol_dissector(int proto_id, gpointer dissector)
-{
- protocol_t *protocol;
-
- protocol = find_protocol_by_id(proto_id);
- if (protocol != NULL) {
- if (protocol->dissector != NULL) {
- /* Already set */
- return;
- }
- protocol->dissector = dissector;
- }
-}
-
/* for use with static arrays only, since we don't allocate our own copies
of the header_field_info struct contained withing the hf_register_info struct */
void
diff --git a/epan/proto.h b/epan/proto.h
index 9e23889b29..8f031b905b 100644
--- a/epan/proto.h
+++ b/epan/proto.h
@@ -1,7 +1,7 @@
/* proto.h
* Definitions for protocol display
*
- * $Id: proto.h,v 1.22 2001/11/26 05:41:13 hagbard Exp $
+ * $Id: proto.h,v 1.23 2001/12/03 04:00:15 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -506,9 +506,6 @@ extern void proto_set_decoding(int proto_id, gboolean enabled);
/* Disable disabling of protocol */
extern void proto_set_cant_disable(int proto_id);
-gpointer proto_get_protocol_dissector(int proto_id);
-extern void proto_set_protocol_dissector(int proto_id, gpointer dissector);
-
/* Get length of registered field according to field type.
* 0 means undeterminable at registration time.
* -1 means unknown field */