diff options
author | Guy Harris <guy@alum.mit.edu> | 2002-02-18 01:08:44 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2002-02-18 01:08:44 +0000 |
commit | 6a21dc7e44e06bf3064d74a8e9624b9e01b04bbd (patch) | |
tree | 73281bb2d7e50e8527da2945d5627a31bae9e5c6 /epan | |
parent | d92a1cd8e1f58a1ec46793f9052aa893a279e523 (diff) | |
download | wireshark-6a21dc7e44e06bf3064d74a8e9624b9e01b04bbd.tar.gz |
Don't give tvbuffs names; instead, give data sources names, where a
"data source" has a name and a top-level tvbuff, and frames can have a
list of data sources associated with them.
Use the tvbuff pointer to determine which data source is the data source
for a given field; this means we don't have to worry about multiple data
sources with the same name - the only thing the name does is label the
notebook tab for the display of the data source, and label the hex dump
of the data source in print/Tethereal output.
Clean up a bunch of things discovered in the process of doing the above.
svn path=/trunk/; revision=4749
Diffstat (limited to 'epan')
-rw-r--r-- | epan/epan.c | 7 | ||||
-rw-r--r-- | epan/frame_data.h | 12 | ||||
-rw-r--r-- | epan/packet.c | 46 | ||||
-rw-r--r-- | epan/packet.h | 13 | ||||
-rw-r--r-- | epan/proto.c | 17 | ||||
-rw-r--r-- | epan/proto.h | 6 | ||||
-rw-r--r-- | epan/tvbuff.c | 38 | ||||
-rw-r--r-- | epan/tvbuff.h | 6 |
8 files changed, 100 insertions, 45 deletions
diff --git a/epan/epan.c b/epan/epan.c index 56afd53ea4..d503078dd3 100644 --- a/epan/epan.c +++ b/epan/epan.c @@ -1,6 +1,6 @@ /* epan.h * - * $Id: epan.c,v 1.16 2002/01/04 08:57:09 guy Exp $ + * $Id: epan.c,v 1.17 2002/02/18 01:08:41 guy Exp $ * * Ethereal Protocol Analyzer Library * @@ -95,10 +95,7 @@ epan_dissect_run(epan_dissect_t *edt, void* pseudo_header, const guint8* data, frame_data *fd, column_info *cinfo) { /* start with empty data source list */ - if (fd->data_src) { - g_slist_free(fd->data_src); - } - fd->data_src = NULL; + free_data_sources(fd); dissect_packet(edt, pseudo_header, data, fd, cinfo); } diff --git a/epan/frame_data.h b/epan/frame_data.h index 168e38d9c9..b972811e83 100644 --- a/epan/frame_data.h +++ b/epan/frame_data.h @@ -1,7 +1,7 @@ /* frame_data.h * Definitions for frame_data structures and routines * - * $Id: frame_data.h,v 1.3 2001/12/10 02:16:59 guy Exp $ + * $Id: frame_data.h,v 1.4 2002/02/18 01:08:41 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -26,6 +26,7 @@ #define __FRAME_DATA_H__ #include "column_info.h" +#include "tvbuff.h" /* XXX - some of this stuff is used only while a packet is being dissected; should we keep that stuff in the "packet_info" structure, instead, to @@ -54,6 +55,15 @@ typedef struct _frame_data { } flags; } frame_data; +/* + * A data source. + * Has a tvbuff and a name. + */ +typedef struct { + tvbuff_t *tvb; + char *name; +} data_source; + /* Utility routines used by packet*.c */ void p_add_proto_data(frame_data *, int, void *); diff --git a/epan/packet.c b/epan/packet.c index bffceebafd..ce3a5fee74 100644 --- a/epan/packet.c +++ b/epan/packet.c @@ -1,7 +1,7 @@ /* packet.c * Routines for packet disassembly * - * $Id: packet.c,v 1.59 2002/02/17 00:51:21 guy Exp $ + * $Id: packet.c,v 1.60 2002/02/18 01:08:41 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -180,6 +180,46 @@ postseq_cleanup_all_protocols(void) &call_postseq_cleanup_routine, NULL); } +/* Contains information about data sources. */ +static GMemChunk *data_source_chunk = NULL; + +/* + * Add a new data source to the list of data sources for a frame, given + * the tvbuff for the data source and its name. + */ +void +add_new_data_source(frame_data *fd, tvbuff_t *tvb, char *name) +{ + data_source *src; + + if (data_source_chunk == NULL) { + data_source_chunk = g_mem_chunk_new("data_source_chunk", + sizeof (data_source), 10 * sizeof (data_source), + G_ALLOC_AND_FREE); + } + src = g_mem_chunk_alloc(data_source_chunk); + src->tvb = tvb; + src->name = g_strdup(name); + fd->data_src = g_slist_append(fd->data_src, src); +} + +/* + * Free up a frame's list of data sources. + */ +void +free_data_sources(frame_data *fd) +{ + GSList *src_le; + data_source *src; + + for (src_le = fd->data_src; src_le != NULL; src_le = src_le->next) { + src = src_le->data; + g_free(src->name); + g_mem_chunk_free(data_source_chunk, src); + } + g_slist_free(fd->data_src); + fd->data_src = NULL; +} /* Creates the top-most tvbuff and calls dissect_frame() */ void @@ -220,9 +260,9 @@ dissect_packet(epan_dissect_t *edt, union wtap_pseudo_header *pseudo_header, } TRY { - edt->tvb = tvb_new_real_data(pd, fd->cap_len, fd->pkt_len, "Frame"); + edt->tvb = tvb_new_real_data(pd, fd->cap_len, fd->pkt_len); /* Add this tvbuffer into the data_src list */ - fd->data_src = g_slist_append( fd->data_src, edt->tvb); + add_new_data_source(fd, edt->tvb, "Frame"); /* Even though dissect_frame() catches all the exceptions a * sub-dissector can throw, dissect_frame() itself may throw diff --git a/epan/packet.h b/epan/packet.h index 24e01afc0a..35aa9d1da6 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.51 2002/02/17 00:51:21 guy Exp $ + * $Id: packet.h,v 1.52 2002/02/18 01:08:42 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -229,6 +229,17 @@ extern void register_postseq_cleanup_routine(void (*func)(void)); extern void postseq_cleanup_all_protocols(void); /* + * Add a new data source to the list of data sources for a frame, given + * the tvbuff for the data source and its name. + */ +extern void add_new_data_source(frame_data *fd, tvbuff_t *tvb, char *name); + +/* + * Free up a frame's list of data sources. + */ +extern void free_data_sources(frame_data *fd); + +/* * Dissectors should never modify the packet data. */ extern void dissect_packet(epan_dissect_t *edt, diff --git a/epan/proto.c b/epan/proto.c index 46a7826205..c14cea5857 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -1,7 +1,7 @@ /* proto.c * Routines for protocol tree * - * $Id: proto.c,v 1.51 2002/02/01 04:34:17 gram Exp $ + * $Id: proto.c,v 1.52 2002/02/18 01:08:42 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -1647,11 +1647,11 @@ alloc_field_info(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint fi->value = fvalue_new(fi->hfinfo->type); - /* add the data source name */ + /* add the data source tvbuff */ if (tvb) { - fi->ds_name = tvb_get_name(tvb); + fi->ds_tvb = tvb_get_ds_tvb(tvb); } else { - fi->ds_name = NULL; + fi->ds_tvb = NULL; } return fi; @@ -2789,7 +2789,7 @@ proto_get_finfo_ptr_array(proto_tree *tree, int id) typedef struct { guint offset; field_info *finfo; - gchar *name; + tvbuff_t *tvb; } offset_search_t; static gboolean @@ -2799,8 +2799,7 @@ check_for_offset(GNode *node, gpointer data) offset_search_t *offsearch = data; /* !fi == the top most container node which holds nothing */ - if (fi && fi->visible && fi->ds_name && - strcmp(offsearch->name, fi->ds_name) == 0) { + if (fi && fi->visible && fi->ds_tvb && offsearch->tvb == fi->ds_tvb) { if (offsearch->offset >= (guint) fi->start && offsearch->offset < (guint) (fi->start + fi->length)) { @@ -2820,13 +2819,13 @@ check_for_offset(GNode *node, gpointer data) * siblings of each node myself. When I have more time I'll do that. * (yeah right) */ field_info* -proto_find_field_from_offset(proto_tree *tree, guint offset, char* ds_name) +proto_find_field_from_offset(proto_tree *tree, guint offset, tvbuff_t *tvb) { offset_search_t offsearch; offsearch.offset = offset; offsearch.finfo = NULL; - offsearch.name = ds_name; + offsearch.tvb = tvb; g_node_traverse((GNode*)tree, G_PRE_ORDER, G_TRAVERSE_ALL, -1, check_for_offset, &offsearch); diff --git a/epan/proto.h b/epan/proto.h index 383fb1b34b..25d6de41d6 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -1,7 +1,7 @@ /* proto.h * Definitions for protocol display * - * $Id: proto.h,v 1.27 2002/02/05 22:10:20 guy Exp $ + * $Id: proto.h,v 1.28 2002/02/18 01:08:42 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -113,7 +113,7 @@ typedef struct field_info { char *representation; /* for GUI tree */ int visible; fvalue_t *value; - gchar *ds_name; /* data source name */ + tvbuff_t *ds_tvb; /* data source tvbuff */ } field_info; /* One of these exists for the entire protocol tree. Each proto_node @@ -584,6 +584,6 @@ extern char* proto_alloc_dfilter_string(field_info *finfo, guint8 *pd); extern field_info* -proto_find_field_from_offset(proto_tree *tree, guint offset, gchar *ds_name); +proto_find_field_from_offset(proto_tree *tree, guint offset, tvbuff_t *tvb); #endif /* proto.h */ diff --git a/epan/tvbuff.c b/epan/tvbuff.c index 8394fd7c63..4fd3c4ee46 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -9,7 +9,7 @@ * the data of a backing tvbuff, or can be a composite of * other tvbuffs. * - * $Id: tvbuff.c,v 1.29 2002/02/01 07:03:32 guy Exp $ + * $Id: tvbuff.c,v 1.30 2002/02/18 01:08:42 guy Exp $ * * Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu> * @@ -68,7 +68,7 @@ struct tvbuff { tvbuff_type type; gboolean initialized; guint usage_count; - gchar* ds_name; /* data source name */ + tvbuff_t* ds_tvb; /* data source top-level tvbuff */ /* The tvbuffs in which this tvbuff is a member * (that is, a backing tvbuff for a TVBUFF_SUBSET @@ -143,7 +143,7 @@ tvb_init(tvbuff_t *tvb, tvbuff_type type) tvb->real_data = NULL; tvb->raw_offset = -1; tvb->used_in = NULL; - tvb->ds_name = NULL; + tvb->ds_tvb = NULL; switch(type) { case TVBUFF_REAL_DATA: @@ -204,8 +204,6 @@ tvb_free(tvbuff_t* tvb) if (tvb->free_cb) { tvb->free_cb(tvb->real_data); } - if (tvb->ds_name) - g_free(tvb->ds_name); break; case TVBUFF_SUBSET: @@ -214,12 +212,6 @@ tvb_free(tvbuff_t* tvb) if (tvb->tvbuffs.subset.tvb) { tvb_decrement_usage_count(tvb->tvbuffs.subset.tvb, 1); } - - /* - * TVBUFF_SUBSET tvbuffs share a "ds_name" with - * the parent tvbuff, so this tvbuff's "ds_name" - * shouldn't be freed. - */ break; case TVBUFF_COMPOSITE: @@ -237,8 +229,6 @@ tvb_free(tvbuff_t* tvb) g_free(composite->end_offsets); if (tvb->real_data) g_free(tvb->real_data); - if (tvb->ds_name) - g_free(tvb->ds_name); break; } @@ -330,7 +320,7 @@ tvb_set_real_data(tvbuff_t* tvb, const guint8* data, guint length, gint reported } tvbuff_t* -tvb_new_real_data(const guint8* data, guint length, gint reported_length, const gchar* ds_name) +tvb_new_real_data(const guint8* data, guint length, gint reported_length) { tvbuff_t *tvb; @@ -340,8 +330,11 @@ tvb_new_real_data(const guint8* data, guint length, gint reported_length, const tvb_set_real_data(tvb, data, length, reported_length); - /* set the data source name */ - tvb->ds_name = g_strdup( ds_name); + /* + * This is the top-level real tvbuff for this data source, + * so its data source tvbuff is itself. + */ + tvb->ds_tvb = tvb; CLEANUP_POP; @@ -517,7 +510,12 @@ tvb_new_subset(tvbuff_t *backing, gint backing_offset, gint backing_length, gint tvb_set_subset(tvb, backing, backing_offset, backing_length, reported_length); - tvb->ds_name = backing->ds_name; + /* + * The top-level data source of this tvbuff is the top-level + * data source of its parent. + */ + tvb->ds_tvb = backing->ds_tvb; + CLEANUP_POP; return tvb; @@ -1615,8 +1613,8 @@ tvb_bytes_to_str(tvbuff_t *tvb, gint offset, gint len) return bytes_to_str(tvb_get_ptr(tvb, offset, len), len); } -gchar* -tvb_get_name(tvbuff_t* tvb) +tvbuff_t * +tvb_get_ds_tvb(tvbuff_t *tvb) { - return tvb->ds_name; + return tvb->ds_tvb; } diff --git a/epan/tvbuff.h b/epan/tvbuff.h index 2de3f63650..1e29ab0bd7 100644 --- a/epan/tvbuff.h +++ b/epan/tvbuff.h @@ -9,7 +9,7 @@ * the data of a backing tvbuff, or can be a composite of * other tvbuffs. * - * $Id: tvbuff.h,v 1.21 2002/02/01 04:34:17 gram Exp $ + * $Id: tvbuff.h,v 1.22 2002/02/18 01:08:42 guy Exp $ * * Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu> * @@ -140,7 +140,7 @@ extern void tvb_set_real_data(tvbuff_t*, const guint8* data, guint length, /* Combination of tvb_new() and tvb_set_real_data(). Can throw ReportedBoundsError. */ extern tvbuff_t* tvb_new_real_data(const guint8* data, guint length, - gint reported_length, const gchar *name); + gint reported_length); /* Define the subset of the backing buffer to use. @@ -379,7 +379,7 @@ extern gint tvb_memeql(tvbuff_t *tvb, gint offset, const guint8 *str, */ extern gchar *tvb_bytes_to_str(tvbuff_t *tvb, gint offset, gint len); -extern gchar *tvb_get_name(tvbuff_t *tvb); +extern tvbuff_t *tvb_get_ds_tvb(tvbuff_t *tvb); /************** END OF ACCESSORS ****************/ |