Move the code to build the balanced tree of fields into "proto_init()",
move the code from "dfilter_lookup_token()" into "proto_registrar_get_byname()", and get rid of "dfilter_lookup_token()" and have its callers call "proto_registrar_get_byname()" instead. svn path=/trunk/; revision=5287
This commit is contained in:
parent
6c553bf998
commit
30f02bc99c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Id: dfilter-int.h,v 1.5 2002/01/21 07:37:37 guy Exp $
|
||||
* $Id: dfilter-int.h,v 1.6 2002/04/29 07:55:32 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -57,11 +57,6 @@ void Dfilter(void*, int, stnode_t*, dfwork_t*);
|
|||
/* Scanner's lval */
|
||||
extern stnode_t *df_lval;
|
||||
|
||||
/* Given a field abbreviation, returns the proto ID, or -1 if
|
||||
* it doesn't exist. */
|
||||
header_field_info*
|
||||
dfilter_lookup_token(char *abbrev);
|
||||
|
||||
/* Set dfilter_error_msg_buf and dfilter_error_msg */
|
||||
void
|
||||
dfilter_fail(char *format, ...);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Id: dfilter.c,v 1.8 2002/04/08 20:11:31 gram Exp $
|
||||
* $Id: dfilter.c,v 1.9 2002/04/29 07:55:32 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -38,15 +38,8 @@
|
|||
#include "dfvm.h"
|
||||
#include <epan/epan_dissect.h>
|
||||
|
||||
|
||||
/* Balanced tree of abbreviations and IDs */
|
||||
static GTree *dfilter_tokens = NULL;
|
||||
|
||||
#define DFILTER_TOKEN_ID_OFFSET 1
|
||||
|
||||
/* Comparision function for tree insertion. A wrapper around strcmp() */
|
||||
static int g_strcmp(gconstpointer a, gconstpointer b);
|
||||
|
||||
/* Global error message space for dfilter_compile errors */
|
||||
static gchar dfilter_error_msg_buf[1024];
|
||||
gchar *dfilter_error_msg; /* NULL when no error resulted */
|
||||
|
@ -85,68 +78,6 @@ dfilter_fail(char *format, ...)
|
|||
void
|
||||
dfilter_init(void)
|
||||
{
|
||||
int id, num_symbols;
|
||||
char *abbrev;
|
||||
header_field_info *hfinfo, *same_name_hfinfo, *same_name_next_hfinfo;
|
||||
|
||||
num_symbols = proto_registrar_n();
|
||||
|
||||
if (dfilter_tokens) {
|
||||
/* XXX - needed? */
|
||||
g_message("I expected hf_ids to be NULL\n");
|
||||
g_tree_destroy(dfilter_tokens);
|
||||
|
||||
/* Make sure the hfinfo->same_name links are broken */
|
||||
for (id = 0; id < num_symbols; id++) {
|
||||
hfinfo = proto_registrar_get_nth(id);
|
||||
hfinfo->same_name_next = NULL;
|
||||
hfinfo->same_name_prev = NULL;
|
||||
}
|
||||
}
|
||||
dfilter_tokens = g_tree_new(g_strcmp);
|
||||
|
||||
/* Populate the abbrev/ID GTree (header-field symbol table) */
|
||||
|
||||
|
||||
for (id = 0; id < num_symbols; id++) {
|
||||
if (id == hf_text_only) {
|
||||
continue;
|
||||
}
|
||||
abbrev = proto_registrar_get_abbrev(id);
|
||||
hfinfo = proto_registrar_get_nth(id);
|
||||
|
||||
g_assert(abbrev); /* Not Null */
|
||||
g_assert(abbrev[0] != 0); /* Not empty string */
|
||||
|
||||
/* We allow multiple hfinfo's to be registered under the same
|
||||
* abbreviation. This was done for X.25, as, depending
|
||||
* on whether it's modulo-8 or modulo-128 operation,
|
||||
* some bitfield fields may be in different bits of
|
||||
* a byte, and we want to be able to refer to that field
|
||||
* with one name regardless of whether the packets
|
||||
* are modulo-8 or modulo-128 packets. */
|
||||
same_name_hfinfo = g_tree_lookup(dfilter_tokens, abbrev);
|
||||
if (same_name_hfinfo) {
|
||||
/* There's already a field with this name.
|
||||
* Put it after that field in the list of
|
||||
* fields with this name, then allow the code
|
||||
* after this if{} block to replace the old
|
||||
* hfinfo with the new hfinfo in the GTree. Thus,
|
||||
* we end up with a linked-list of same-named hfinfo's,
|
||||
* with the root of the list being the hfinfo in the GTree */
|
||||
same_name_next_hfinfo =
|
||||
same_name_hfinfo->same_name_next;
|
||||
|
||||
hfinfo->same_name_next = same_name_next_hfinfo;
|
||||
if (same_name_next_hfinfo)
|
||||
same_name_next_hfinfo->same_name_prev = hfinfo;
|
||||
|
||||
same_name_hfinfo->same_name_next = hfinfo;
|
||||
hfinfo->same_name_prev = same_name_hfinfo;
|
||||
}
|
||||
g_tree_insert(dfilter_tokens, abbrev, hfinfo);
|
||||
}
|
||||
|
||||
if (ParserObj) {
|
||||
g_message("I expected ParserObj to be NULL\n");
|
||||
/* Free the Lemon Parser object */
|
||||
|
@ -163,12 +94,6 @@ dfilter_init(void)
|
|||
void
|
||||
dfilter_cleanup(void)
|
||||
{
|
||||
/* Free the abbrev/ID GTree */
|
||||
if (dfilter_tokens) {
|
||||
g_tree_destroy(dfilter_tokens);
|
||||
dfilter_tokens = NULL;
|
||||
}
|
||||
|
||||
/* Free the Lemon Parser object */
|
||||
if (ParserObj) {
|
||||
DfilterFree(ParserObj, g_free);
|
||||
|
@ -178,24 +103,6 @@ dfilter_cleanup(void)
|
|||
sttype_cleanup();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Lookup an abbreviation in our token tree, returing the ID #
|
||||
* If the abbreviation doesn't exit, returns -1 */
|
||||
header_field_info*
|
||||
dfilter_lookup_token(char *abbrev)
|
||||
{
|
||||
g_assert(abbrev != NULL);
|
||||
return g_tree_lookup(dfilter_tokens, abbrev);
|
||||
}
|
||||
|
||||
/* String comparison func for dfilter_token GTree */
|
||||
static int
|
||||
g_strcmp(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
return strcmp((const char*)a, (const char*)b);
|
||||
}
|
||||
|
||||
static dfilter_t*
|
||||
dfilter_new(void)
|
||||
{
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
%{
|
||||
/*
|
||||
* $Id: scanner.l,v 1.6 2002/04/11 03:26:26 gram Exp $
|
||||
* $Id: scanner.l,v 1.7 2002/04/29 07:55:32 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
* Copyright 2001 Gerald Combs
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
@ -131,7 +130,7 @@ static gboolean str_to_guint32(char *s, guint32* pint);
|
|||
/* Is it a field name? */
|
||||
header_field_info *hfinfo;
|
||||
|
||||
hfinfo = dfilter_lookup_token(yytext);
|
||||
hfinfo = proto_registrar_get_byname(yytext);
|
||||
if (hfinfo) {
|
||||
/* Yes, it's a field name */
|
||||
return set_lval(TOKEN_FIELD, hfinfo);
|
||||
|
|
104
epan/proto.c
104
epan/proto.c
|
@ -1,7 +1,7 @@
|
|||
/* proto.c
|
||||
* Routines for protocol tree
|
||||
*
|
||||
* $Id: proto.c,v 1.66 2002/04/28 23:39:58 guy Exp $
|
||||
* $Id: proto.c,v 1.67 2002/04/29 07:55:31 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -120,6 +120,9 @@ proto_tree_set_int(field_info *fi, gint32 value);
|
|||
|
||||
static int proto_register_field_init(header_field_info *hfinfo, int parent);
|
||||
|
||||
/* Comparision function for tree insertion. A wrapper around strcmp() */
|
||||
static int g_strcmp(gconstpointer a, gconstpointer b);
|
||||
|
||||
/* special-case header field used within proto.c */
|
||||
int hf_text_only = 1;
|
||||
|
||||
|
@ -161,6 +164,9 @@ static GMemChunk *gmc_item_labels = NULL;
|
|||
/* List which stores protocols and fields that have been registered */
|
||||
static GPtrArray *gpa_hfinfo = NULL;
|
||||
|
||||
/* Balanced tree of abbreviations and IDs */
|
||||
static GTree *gpa_name_tree = NULL;
|
||||
|
||||
/* Points to the first element of an array of Booleans, indexed by
|
||||
a subtree item type; that array element is TRUE if subtrees of
|
||||
an item of that type are to be expanded. */
|
||||
|
@ -174,6 +180,9 @@ void
|
|||
proto_init(const char *plugin_dir,void (register_all_protocols)(void),
|
||||
void (register_all_protocol_handoffs)(void))
|
||||
{
|
||||
int id, num_symbols;
|
||||
char *abbrev;
|
||||
header_field_info *hfinfo, *same_name_hfinfo, *same_name_next_hfinfo;
|
||||
static hf_register_info hf[] = {
|
||||
{ &hf_text_only,
|
||||
{ "", "", FT_NONE, BASE_NONE, NULL, 0x0,
|
||||
|
@ -246,15 +255,85 @@ proto_init(const char *plugin_dir,void (register_all_protocols)(void),
|
|||
are merely strings on the GUI tree; they are not filterable */
|
||||
proto_register_field_array(-1, hf, array_length(hf));
|
||||
|
||||
num_symbols = proto_registrar_n();
|
||||
|
||||
if (gpa_name_tree) {
|
||||
/* XXX - needed? */
|
||||
g_message("I expected gpa_name_tree to be NULL\n");
|
||||
g_tree_destroy(gpa_name_tree);
|
||||
|
||||
/* Make sure the hfinfo->same_name links are broken */
|
||||
for (id = 0; id < num_symbols; id++) {
|
||||
hfinfo = proto_registrar_get_nth(id);
|
||||
hfinfo->same_name_next = NULL;
|
||||
hfinfo->same_name_prev = NULL;
|
||||
}
|
||||
}
|
||||
gpa_name_tree = g_tree_new(g_strcmp);
|
||||
|
||||
/* Populate the abbrev/ID GTree (header-field symbol table) */
|
||||
|
||||
for (id = 0; id < num_symbols; id++) {
|
||||
if (id == hf_text_only) {
|
||||
continue;
|
||||
}
|
||||
abbrev = proto_registrar_get_abbrev(id);
|
||||
hfinfo = proto_registrar_get_nth(id);
|
||||
|
||||
g_assert(abbrev); /* Not Null */
|
||||
g_assert(abbrev[0] != 0); /* Not empty string */
|
||||
|
||||
/* We allow multiple hfinfo's to be registered under the same
|
||||
* abbreviation. This was done for X.25, as, depending
|
||||
* on whether it's modulo-8 or modulo-128 operation,
|
||||
* some bitfield fields may be in different bits of
|
||||
* a byte, and we want to be able to refer to that field
|
||||
* with one name regardless of whether the packets
|
||||
* are modulo-8 or modulo-128 packets. */
|
||||
same_name_hfinfo = g_tree_lookup(gpa_name_tree, abbrev);
|
||||
if (same_name_hfinfo) {
|
||||
/* There's already a field with this name.
|
||||
* Put it after that field in the list of
|
||||
* fields with this name, then allow the code
|
||||
* after this if{} block to replace the old
|
||||
* hfinfo with the new hfinfo in the GTree. Thus,
|
||||
* we end up with a linked-list of same-named hfinfo's,
|
||||
* with the root of the list being the hfinfo in the GTree */
|
||||
same_name_next_hfinfo =
|
||||
same_name_hfinfo->same_name_next;
|
||||
|
||||
hfinfo->same_name_next = same_name_next_hfinfo;
|
||||
if (same_name_next_hfinfo)
|
||||
same_name_next_hfinfo->same_name_prev = hfinfo;
|
||||
|
||||
same_name_hfinfo->same_name_next = hfinfo;
|
||||
hfinfo->same_name_prev = same_name_hfinfo;
|
||||
}
|
||||
g_tree_insert(gpa_name_tree, abbrev, hfinfo);
|
||||
}
|
||||
|
||||
/* We've assigned all the subtree type values; allocate the array
|
||||
for them, and zero it out. */
|
||||
tree_is_expanded = g_malloc(num_tree_types*sizeof (gint *));
|
||||
memset(tree_is_expanded, '\0', num_tree_types*sizeof (gint *));
|
||||
}
|
||||
|
||||
/* String comparison func for dfilter_token GTree */
|
||||
static int
|
||||
g_strcmp(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
return strcmp((const char*)a, (const char*)b);
|
||||
}
|
||||
|
||||
void
|
||||
proto_cleanup(void)
|
||||
{
|
||||
/* Free the abbrev/ID GTree */
|
||||
if (gpa_name_tree) {
|
||||
g_tree_destroy(gpa_name_tree);
|
||||
gpa_name_tree = NULL;
|
||||
}
|
||||
|
||||
if (gmc_hfinfo)
|
||||
g_mem_chunk_destroy(gmc_hfinfo);
|
||||
if (gmc_field_info)
|
||||
|
@ -364,29 +443,12 @@ proto_registrar_get_nth(int hfindex)
|
|||
}
|
||||
|
||||
/* Finds a record in the hf_info_records array by name.
|
||||
* XXX - the display filter code maintains a balanced tree
|
||||
* of filter names and hfinfo pointers; should that be moved
|
||||
* up into here, so the display filter code could just use
|
||||
* this routine?
|
||||
*/
|
||||
header_field_info*
|
||||
proto_registrar_get_byname(const char *field_name)
|
||||
proto_registrar_get_byname(char *field_name)
|
||||
{
|
||||
header_field_info *hfinfo;
|
||||
int i, len;
|
||||
|
||||
len = gpa_hfinfo->len;
|
||||
|
||||
for (i = 0; i < len ; i++) {
|
||||
hfinfo = proto_registrar_get_nth(i);
|
||||
|
||||
if (strcmp(hfinfo->abbrev, field_name) == 0) {
|
||||
/* Found it. */
|
||||
return hfinfo;
|
||||
}
|
||||
}
|
||||
/* Not found. */
|
||||
return NULL;
|
||||
g_assert(field_name != NULL);
|
||||
return g_tree_lookup(gpa_name_tree, field_name);
|
||||
}
|
||||
|
||||
/* Add a text-only node, leaving it to our caller to fill the text in */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* proto.h
|
||||
* Definitions for protocol display
|
||||
*
|
||||
* $Id: proto.h,v 1.30 2002/04/18 20:19:10 guy Exp $
|
||||
* $Id: proto.h,v 1.31 2002/04/29 07:55:31 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -499,7 +499,7 @@ extern char* proto_registrar_get_abbrev(int n);
|
|||
extern header_field_info* proto_registrar_get_nth(int hfindex);
|
||||
|
||||
/* get the header field information based upon a field name */
|
||||
extern header_field_info* proto_registrar_get_byname(const char *field_name);
|
||||
extern header_field_info* proto_registrar_get_byname(char *field_name);
|
||||
|
||||
/* Returns enum ftenum for item # n */
|
||||
extern int proto_registrar_get_ftype(int n);
|
||||
|
|
Loading…
Reference in New Issue