When a new display filter is to be applied, don't set "cf.dfilter" or

"cf.dfcode" if the new filter doesn't compile, because the filter
currently in effect will be the one that was last applied - just free up
the text of the new filter, and whatever memory was allocated for the
new filter code.

This means we allocate a new dfilter when a new filter is to be applied,
rather than recycling stuff from the old filter, as we want the old
filter code to remain around if the new filter doesn't compile.

This means that "cf.dfilter" and "cf.dfcode" will be null if there's no
filter in effect.

svn path=/trunk/; revision=803
This commit is contained in:
Guy Harris 1999-10-11 06:39:26 +00:00
parent 29b9c8a285
commit 3b9013d393
10 changed files with 123 additions and 195 deletions

View File

@ -1,7 +1,7 @@
/* colors.c /* colors.c
* Definitions for color structures and routines * Definitions for color structures and routines
* *
* $Id: colors.c,v 1.12 1999/10/07 22:50:44 guy Exp $ * $Id: colors.c,v 1.13 1999/10/11 06:39:02 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -116,9 +116,8 @@ colors_init(capture_file *cf)
new_color_filter(cf->colors, default_colors[i].proto, default_colors[i].proto); new_color_filter(cf->colors, default_colors[i].proto, default_colors[i].proto);
color_filter(cf,i)->bg_color = color; color_filter(cf,i)->bg_color = color;
color_filter(cf,i)->c_colorfilter = dfilter_new(); color_filter(cf,i)->c_colorfilter = dfilter_compile(default_colors[i].proto);
if(dfilter_compile((color_filter(cf,i)->c_colorfilter), if(color_filter(cf,i)->c_colorfilter == NULL){
default_colors[i].proto) != 0){
simple_dialog(ESD_TYPE_WARN, NULL, simple_dialog(ESD_TYPE_WARN, NULL,
"Cannot compile default filter %s.\n%s", "Cannot compile default filter %s.\n%s",
default_colors[i].proto, dfilter_error_msg); default_colors[i].proto, dfilter_error_msg);
@ -244,14 +243,11 @@ read_filters(capture_file *cf)
name, filter, &bg_r, &bg_g, &bg_b, &fg_r, &fg_g, &fg_b) == 8){ name, filter, &bg_r, &bg_g, &bg_b, &fg_r, &fg_g, &fg_b) == 8){
/* we got a filter */ /* we got a filter */
/* test the dfilter before putting it into the list of color dfilters */ temp_dfilter = dfilter_compile(filter);
/*if(dfilter_compile((color_filter(cf,i)->c_colorfilter),filter) != 0){*/ if(temp_dfilter == NULL){
temp_dfilter = dfilter_new();
if(dfilter_compile(temp_dfilter, filter) != 0){
simple_dialog(ESD_TYPE_WARN, NULL, simple_dialog(ESD_TYPE_WARN, NULL,
"Could not compile filter %s from saved filters because\n%s", "Could not compile filter %s from saved filters because\n%s",
name, dfilter_error_msg); name, dfilter_error_msg);
dfilter_destroy(temp_dfilter);
continue; continue;
} }
new_color_filter(cf->colors, name, filter); new_color_filter(cf->colors, name, filter);
@ -493,7 +489,7 @@ color_ok_cb (GtkButton *button,
/* colorize list */ /* colorize list */
filter_packets(&cf); colorize_packets(&cf);
gtk_container_remove(GTK_CONTAINER(GTK_WIDGET(cf.colors->color_filters)->parent), gtk_container_remove(GTK_CONTAINER(GTK_WIDGET(cf.colors->color_filters)->parent),
cf.colors->color_filters); cf.colors->color_filters);
gtk_widget_destroy(dialog); gtk_widget_destroy(dialog);
@ -507,7 +503,7 @@ color_apply_cb (GtkButton *button,
{ {
capture_file *cf; capture_file *cf;
cf = (capture_file *)user_data; cf = (capture_file *)user_data;
filter_packets(cf); colorize_packets(cf);
} }
/* Exit dialog and do not process list */ /* Exit dialog and do not process list */
@ -593,12 +589,11 @@ colorize_ok_cb (GtkButton *button,
compiled_filter = dfilter_new(); compiled_filter = dfilter_compile(filter_text);
if( dfilter_compile( compiled_filter, filter_text) != 0 ){ if(compiled_filter == NULL ){
simple_dialog(ESD_TYPE_WARN, NULL, "Filter \"%s\" did not compile correctly.\n" simple_dialog(ESD_TYPE_WARN, NULL, "Filter \"%s\" did not compile correctly.\n"
" Please try again. Filter unchanged.\n%s\n", filter_name,dfilter_error_msg); " Please try again. Filter unchanged.\n%s\n", filter_name,dfilter_error_msg);
dfilter_destroy(compiled_filter);
} else { } else {
if( color_filter(&cf, cf.colors->row_selected)->c_colorfilter != NULL) if( color_filter(&cf, cf.colors->row_selected)->c_colorfilter != NULL)

View File

@ -3,7 +3,7 @@
/* dfilter-grammar.y /* dfilter-grammar.y
* Parser for display filters * Parser for display filters
* *
* $Id: dfilter-grammar.y,v 1.21 1999/10/11 03:03:10 guy Exp $ * $Id: dfilter-grammar.y,v 1.22 1999/10/11 06:39:04 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -94,14 +94,7 @@ static int ether_str_to_guint8_array(const char *s, guint8 *mac);
/* This is the dfilter we're currently processing. It's how /* This is the dfilter we're currently processing. It's how
* dfilter_compile communicates with us. * dfilter_compile communicates with us.
*/ */
dfilter *global_df = NULL;; dfilter *global_df = NULL;
/* list of GNodes allocated during parsing. If the parsing fails, we'll
* use this list to free all the GNodes. If the parsing succeeds, we'll
* just clear this list since dfilter_clear_filter() will take care of
* freeing the GNodes when they're no longer needed.
*/
GSList *gnode_slist = NULL;
%} %}
@ -369,7 +362,6 @@ dfilter_mknode_join(GNode *n1, enum node_type ntype, int operand, GNode *n2)
g_node_append(gnode_root, n1); g_node_append(gnode_root, n1);
g_node_append(gnode_root, n2); g_node_append(gnode_root, n2);
gnode_slist = g_slist_append(gnode_slist, gnode_root);
return gnode_root; return gnode_root;
} }
@ -389,7 +381,6 @@ dfilter_mknode_unary(int operand, GNode *n2)
gnode_root = g_node_new(node_root); gnode_root = g_node_new(node_root);
g_node_append(gnode_root, n2); g_node_append(gnode_root, n2);
gnode_slist = g_slist_append(gnode_slist, gnode_root);
return gnode_root; return gnode_root;
} }
@ -408,7 +399,6 @@ dfilter_mknode_numeric_variable(gint id)
node->value.variable = id; node->value.variable = id;
gnode = g_node_new(node); gnode = g_node_new(node);
gnode_slist = g_slist_append(gnode_slist, gnode);
return gnode; return gnode;
} }
@ -426,7 +416,6 @@ dfilter_mknode_ether_variable(gint id)
node->value.variable = id; node->value.variable = id;
gnode = g_node_new(node); gnode = g_node_new(node);
gnode_slist = g_slist_append(gnode_slist, gnode);
return gnode; return gnode;
} }
@ -444,7 +433,6 @@ dfilter_mknode_ipxnet_variable(gint id)
node->value.variable = id; node->value.variable = id;
gnode = g_node_new(node); gnode = g_node_new(node);
gnode_slist = g_slist_append(gnode_slist, gnode);
return gnode; return gnode;
} }
@ -462,7 +450,6 @@ dfilter_mknode_ipv4_variable(gint id)
node->value.variable = id; node->value.variable = id;
gnode = g_node_new(node); gnode = g_node_new(node);
gnode_slist = g_slist_append(gnode_slist, gnode);
return gnode; return gnode;
} }
@ -482,7 +469,6 @@ dfilter_mknode_bytes_variable(gint id, gint offset, guint length)
node->length = length; node->length = length;
gnode = g_node_new(node); gnode = g_node_new(node);
gnode_slist = g_slist_append(gnode_slist, gnode);
return gnode; return gnode;
} }
@ -500,7 +486,6 @@ dfilter_mknode_numeric_value(guint32 val)
node->value.numeric = val; node->value.numeric = val;
gnode = g_node_new(node); gnode = g_node_new(node);
gnode_slist = g_slist_append(gnode_slist, gnode);
return gnode; return gnode;
} }
@ -528,7 +513,6 @@ dfilter_mknode_ether_value(gchar *byte_string)
} }
gnode = g_node_new(node); gnode = g_node_new(node);
gnode_slist = g_slist_append(gnode_slist, gnode);
return gnode; return gnode;
} }
@ -546,7 +530,6 @@ dfilter_mknode_ipxnet_value(guint32 ipx_net_val)
node->value.numeric = ipx_net_val; node->value.numeric = ipx_net_val;
gnode = g_node_new(node); gnode = g_node_new(node);
gnode_slist = g_slist_append(gnode_slist, gnode);
return gnode; return gnode;
} }
@ -570,7 +553,6 @@ dfilter_mknode_ipv4_value(char *host)
node->value.numeric = htonl(node->value.numeric); node->value.numeric = htonl(node->value.numeric);
gnode = g_node_new(node); gnode = g_node_new(node);
gnode_slist = g_slist_append(gnode_slist, gnode);
return gnode; return gnode;
} }
@ -590,7 +572,6 @@ dfilter_mknode_bytes_value(GByteArray *barray)
node->length = barray->len; node->length = barray->len;
gnode = g_node_new(node); gnode = g_node_new(node);
gnode_slist = g_slist_append(gnode_slist, gnode);
return gnode; return gnode;
} }
@ -620,7 +601,6 @@ dfilter_mknode_existence(gint id)
node->value.variable = id; node->value.variable = id;
gnode = g_node_new(node); gnode = g_node_new(node);
gnode_slist = g_slist_append(gnode_slist, gnode);
return gnode; return gnode;
} }

View File

@ -2,7 +2,7 @@
* Definitions for routines common to multiple modules in the display * Definitions for routines common to multiple modules in the display
* filter code, but not used outside that code. * filter code, but not used outside that code.
* *
* $Id: dfilter-int.h,v 1.7 1999/10/11 03:03:11 guy Exp $ * $Id: dfilter-int.h,v 1.8 1999/10/11 06:39:04 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -34,7 +34,6 @@ void dfilter_scanner_cleanup(void);
/* in dfilter-grammar.y */ /* in dfilter-grammar.y */
extern dfilter *global_df; extern dfilter *global_df;
extern GSList *gnode_slist;
/* Here we provide interfaces to make our scanner act and look like lex */ /* Here we provide interfaces to make our scanner act and look like lex */
int dfilter_lex(void); int dfilter_lex(void);

139
dfilter.c
View File

@ -1,7 +1,7 @@
/* dfilter.c /* dfilter.c
* Routines for display filters * Routines for display filters
* *
* $Id: dfilter.c,v 1.25 1999/10/11 03:03:10 guy Exp $ * $Id: dfilter.c,v 1.26 1999/10/11 06:39:05 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -94,8 +94,6 @@ static GArray* get_values_from_ptree(dfilter_node *dnode, proto_tree *ptree, con
static GArray* get_values_from_dfilter(dfilter_node *dnode, GNode *gnode); static GArray* get_values_from_dfilter(dfilter_node *dnode, GNode *gnode);
static gboolean check_existence_in_ptree(dfilter_node *dnode, proto_tree *ptree); static gboolean check_existence_in_ptree(dfilter_node *dnode, proto_tree *ptree);
static void clear_byte_array(gpointer data, gpointer user_data); static void clear_byte_array(gpointer data, gpointer user_data);
static void unlink_gnode_children(gpointer gnode_ptr, gpointer user_data);
static void destroy_gnode(gpointer gnode_ptr, gpointer user_data);
/* this is not so pretty. I need my own g_array "function" (macro) to /* this is not so pretty. I need my own g_array "function" (macro) to
* retreive the pointer to the data stored in an array cell. I need this * retreive the pointer to the data stored in an array cell. I need this
@ -135,28 +133,28 @@ dfilter_cleanup(void)
* display filter each time, without having to clear any memory used, since * display filter each time, without having to clear any memory used, since
* dfilter_compile will take care of that automatically. * dfilter_compile will take care of that automatically.
* *
* Returns 0 on success, non-zero on failure. * Returns a pointer to a newly-allocated dfilter strucutre on success,
* NULL on failure.
* If a failure, dfilter_error_msg points to an appropriate error message. * If a failure, dfilter_error_msg points to an appropriate error message.
* This error message is a global string, so another invocation of * This error message is a global string, so another invocation of
* dfilter_compile will clear it. If the caller needs is stored, he * dfilter_compile will clear it. If the caller needs is stored, he
* needs to g_strdup it himself. * needs to g_strdup it himself.
*/ */
int dfilter*
dfilter_compile(dfilter *df, gchar *dfilter_text) dfilter_compile(gchar *dfilter_text)
{ {
dfilter *df;
int retval; int retval;
g_assert(dfilter_text != NULL); g_assert(dfilter_text != NULL);
dfilter_clear_filter(df); df = dfilter_new();
df->dftext = g_strdup(dfilter_text);
/* tell the scanner to use this string as input */ /* tell the scanner to use the filter string as input */
dfilter_scanner_text(df->dftext); dfilter_scanner_text(dfilter_text);
/* Assign global variable so dfilter_parse knows which dfilter we're /* Assign global variable so dfilter_parse knows which dfilter we're
* talking about. Reset the global error message. We don't have to set * talking about. Reset the global error message.
* gnode_slist since it will always be NULL by the time we get here.
*/ */
global_df = df; global_df = df;
dfilter_error_msg = NULL; dfilter_error_msg = NULL;
@ -183,42 +181,15 @@ dfilter_compile(dfilter *df, gchar *dfilter_text)
} }
} }
/* Clear the list of allocated nodes */ /* Set global_df to NULL just to be tidy. */
if (gnode_slist) { global_df = NULL;
g_slist_free(gnode_slist);
gnode_slist = NULL; if (retval == 0)
return df;
else {
dfilter_destroy(df);
return NULL;
} }
return retval;
}
/* clear the current filter, w/o clearing memchunk area which is where we'll
* put new nodes in a future filter */
void
dfilter_clear_filter(dfilter *df)
{
if (!df)
return;
if (df->dftext)
g_free(df->dftext);
if (df->dftree != NULL)
g_node_destroy(df->dftree);
/* clear the memory that the tree was using for nodes */
if (df->node_memchunk)
g_mem_chunk_reset(df->node_memchunk);
/* clear the memory that the tree was using for byte arrays */
if (df->list_of_byte_arrays) {
g_slist_foreach(df->list_of_byte_arrays, clear_byte_array, NULL);
g_slist_free(df->list_of_byte_arrays);
}
df->dftext = NULL;
df->dftree = NULL;
df->list_of_byte_arrays = NULL;
} }
/* Allocates new dfilter, initializes values, and returns pointer to dfilter */ /* Allocates new dfilter, initializes values, and returns pointer to dfilter */
@ -229,7 +200,6 @@ dfilter_new(void)
df = g_malloc(sizeof(dfilter)); df = g_malloc(sizeof(dfilter));
df->dftext = NULL;
df->dftree = NULL; df->dftree = NULL;
df->node_memchunk = g_mem_chunk_new("df->node_memchunk", df->node_memchunk = g_mem_chunk_new("df->node_memchunk",
sizeof(dfilter_node), 20 * sizeof(dfilter_node), G_ALLOC_ONLY); sizeof(dfilter_node), 20 * sizeof(dfilter_node), G_ALLOC_ONLY);
@ -245,7 +215,21 @@ dfilter_destroy(dfilter *df)
if (!df) if (!df)
return; return;
dfilter_clear_filter(df); if (df->dftree != NULL)
g_node_destroy(df->dftree);
/* clear the memory that the tree was using for nodes */
if (df->node_memchunk)
g_mem_chunk_reset(df->node_memchunk);
/* clear the memory that the tree was using for byte arrays */
if (df->list_of_byte_arrays) {
g_slist_foreach(df->list_of_byte_arrays, clear_byte_array, NULL);
g_slist_free(df->list_of_byte_arrays);
}
df->dftree = NULL;
df->list_of_byte_arrays = NULL;
/* Git rid of memchunk */ /* Git rid of memchunk */
if (df->node_memchunk) if (df->node_memchunk)
@ -267,64 +251,25 @@ clear_byte_array(gpointer data, gpointer user_data)
void void
dfilter_error(char *s) dfilter_error(char *s)
{ {
/* The only data we have to worry about freeing is the
* data used by any GNodes that were allocated during
* parsing. The data in those Gnodes will be cleared
* later via df->node_memchunk. Use gnode_slist to
* clear the GNodes, and set global_df to NULL just
* to be tidy.
*/
global_df = NULL;
/* I don't want to call g_node_destroy on each GNode ptr,
* since that function frees any children. That could
* mess me up later in the list if I try to free a GNode
* that has already been freed. So, I'll unlink the
* children firs,t then call g_node_destroy on each GNode ptr.
*/
if (!gnode_slist)
return;
g_slist_foreach(gnode_slist, unlink_gnode_children, NULL);
g_slist_foreach(gnode_slist, destroy_gnode, NULL);
/* notice we don't clear gnode_slist itself. dfilter_compile()
* will take care of that.
*/
} }
/* Called when an error other than a parsing error occurs. */ /* Called when an error other than a parsing error occurs. */
void void
dfilter_fail(char *format, ...) dfilter_fail(char *format, ...)
{ {
va_list ap; va_list ap;
/* If we've already reported one error, don't overwrite it with this /* If we've already reported one error, don't overwrite it with this
* one. */ * one. */
if (dfilter_error_msg != NULL) if (dfilter_error_msg != NULL)
return; return;
va_start(ap, format); va_start(ap, format);
vsnprintf(dfilter_error_msg_buf, sizeof dfilter_error_msg_buf, format, ap); vsnprintf(dfilter_error_msg_buf, sizeof dfilter_error_msg_buf, format, ap);
dfilter_error_msg = dfilter_error_msg_buf; dfilter_error_msg = dfilter_error_msg_buf;
va_end(ap); va_end(ap);
} }
static void
unlink_gnode_children(gpointer gnode_ptr, gpointer user_data)
{
if (gnode_ptr)
g_node_unlink((GNode*) gnode_ptr);
}
static void
destroy_gnode(gpointer gnode_ptr, gpointer user_data)
{
if (gnode_ptr)
g_node_destroy((GNode*) gnode_ptr);
}
/* lookup an abbreviation in our token tree, returing the ID # /* lookup an abbreviation in our token tree, returing the ID #
* If the abbreviation doesn't exit, returns -1 */ * If the abbreviation doesn't exit, returns -1 */
int dfilter_lookup_token(char *abbrev) int dfilter_lookup_token(char *abbrev)

View File

@ -1,7 +1,7 @@
/* dfilter.h /* dfilter.h
* Definitions for display filters * Definitions for display filters
* *
* $Id: dfilter.h,v 1.10 1999/08/26 06:20:49 gram Exp $ * $Id: dfilter.h,v 1.11 1999/10/11 06:39:04 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -26,7 +26,7 @@
#ifndef __DFILTER_H__ #ifndef __DFILTER_H__
#define __DFILTER_H__ #define __DFILTER_H__
#define DFILTER_CONTAINS_FILTER(x) ((x)->dftree) #define DFILTER_CONTAINS_FILTER(x) ((x) != NULL && (x)->dftree)
/* dfilter_error_msg is NULL if there was no error during dfilter_compile, /* dfilter_error_msg is NULL if there was no error during dfilter_compile,
* otherwise it points to a displayable error message. */ * otherwise it points to a displayable error message. */
@ -36,7 +36,6 @@ extern gchar dfilter_error_msg_buf[1024];
typedef struct { typedef struct {
GNode *dftree; GNode *dftree;
gchar *dftext;
/* space for dfilter_nodes */ /* space for dfilter_nodes */
GMemChunk *node_memchunk; GMemChunk *node_memchunk;
@ -59,12 +58,9 @@ dfilter* dfilter_new(void);
void dfilter_destroy(dfilter *df); void dfilter_destroy(dfilter *df);
/* Compile display filter text */ /* Compile display filter text */
int dfilter_compile(dfilter* df, gchar* dfilter_text); dfilter* dfilter_compile(gchar* dfilter_text);
/* Apply compiled dfilter to a proto_tree */ /* Apply compiled dfilter to a proto_tree */
gboolean dfilter_apply(dfilter *df, proto_tree *ptree, const guint8* pd); gboolean dfilter_apply(dfilter *df, proto_tree *ptree, const guint8* pd);
/* Clears the current filter int the dfilter */
void dfilter_clear_filter(dfilter *df);
#endif /* ! __DFILTER_H__ */ #endif /* ! __DFILTER_H__ */

62
file.c
View File

@ -1,7 +1,7 @@
/* file.c /* file.c
* File I/O routines * File I/O routines
* *
* $Id: file.c,v 1.104 1999/10/10 11:50:38 sharpe Exp $ * $Id: file.c,v 1.105 1999/10/11 06:39:06 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -771,25 +771,57 @@ wtap_dispatch_cb(u_char *user, const struct wtap_pkthdr *phdr, int offset,
} }
void void
filter_packets(capture_file *cf) filter_packets(capture_file *cf, gchar *dftext)
{
dfilter *dfcode;
if (dftext == NULL) {
/* The new filter is an empty filter (i.e., display all packets). */
dfcode = NULL;
} else {
/*
* We have a filter; try to compile it.
*/
dfcode = dfilter_compile(dftext);
if (dfcode == NULL) {
simple_dialog(ESD_TYPE_WARN, NULL, dfilter_error_msg);
return;
}
/* Was it empty? */
if (dfcode->dftree == NULL) {
/* Yes - free the filter text and filter code, and set them to
NULL. */
g_free(dftext);
dftext = NULL;
dfilter_destroy(dfcode);
dfcode = NULL;
}
}
/* We have a valid filter. Replace the current filter. */
if (cf->dfilter != NULL)
g_free(cf->dfilter);
cf->dfilter = dftext;
if (cf->dfcode != NULL)
dfilter_destroy(cf->dfcode);
cf->dfcode = dfcode;
/* Now go through the list of packets we've read from the capture file,
applying the current display filter, and, if the packet passes the
display filter, add it to the summary display, appropriately
colored. (That's how we colorize the display - it's like filtering
the display, only we don't install a new filter.) */
colorize_packets(cf);
}
void
colorize_packets(capture_file *cf)
{ {
frame_data *fd; frame_data *fd;
guint32 progbar_quantum; guint32 progbar_quantum;
guint32 progbar_nextstep; guint32 progbar_nextstep;
if (cf->dfilter == NULL) {
dfilter_clear_filter(cf->dfcode);
}
else {
/*
* Compile the filter.
*/
if (dfilter_compile(cf->dfcode, cf->dfilter) != 0) {
simple_dialog(ESD_TYPE_WARN, NULL, dfilter_error_msg);
return;
}
}
gtk_progress_set_activity_mode(GTK_PROGRESS(prog_bar), FALSE); gtk_progress_set_activity_mode(GTK_PROGRESS(prog_bar), FALSE);
/* Freeze the packet list while we redo it, so we don't get any /* Freeze the packet list while we redo it, so we don't get any

8
file.h
View File

@ -1,7 +1,7 @@
/* file.h /* file.h
* Definitions for file structures and routines * Definitions for file structures and routines
* *
* $Id: file.h,v 1.48 1999/10/02 20:23:53 guy Exp $ * $Id: file.h,v 1.49 1999/10/11 06:39:03 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -104,9 +104,6 @@ typedef struct _capture_file {
wtap *wth; /* Wiretap session */ wtap *wth; /* Wiretap session */
dfilter *rfcode; /* Compiled read filter program */ dfilter *rfcode; /* Compiled read filter program */
gchar *dfilter; /* Display filter string */ gchar *dfilter; /* Display filter string */
#if 0
GNode *dfcode; /* Compiled display filter program */
#endif
colfilter *colors; /* Colors for colorizing packet window */ colfilter *colors; /* Colors for colorizing packet window */
dfilter *dfcode; /* Compiled display filter program */ dfilter *dfcode; /* Compiled display filter program */
#ifdef HAVE_LIBPCAP #ifdef HAVE_LIBPCAP
@ -130,8 +127,9 @@ int read_cap_file(capture_file *);
int tail_cap_file(char *, capture_file *); int tail_cap_file(char *, capture_file *);
/* size_t read_frame_header(capture_file *); */ /* size_t read_frame_header(capture_file *); */
void filter_packets(capture_file *cf, gchar *dfilter);
void colorize_packets(capture_file *);
int print_packets(capture_file *cf, print_args_t *print_args); int print_packets(capture_file *cf, print_args_t *print_args);
void filter_packets(capture_file *);
void change_time_formats(capture_file *); void change_time_formats(capture_file *);
void select_packet(capture_file *, int); void select_packet(capture_file *, int);
void unselect_packet(capture_file *); void unselect_packet(capture_file *);

View File

@ -1,7 +1,7 @@
/* file_dlg.c /* file_dlg.c
* Dialog boxes for handling files * Dialog boxes for handling files
* *
* $Id: file_dlg.c,v 1.8 1999/10/08 07:31:10 guy Exp $ * $Id: file_dlg.c,v 1.9 1999/10/11 06:39:25 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -122,10 +122,9 @@ file_open_ok_cb(GtkWidget *w, GtkFileSelection *fs) {
filter_te = gtk_object_get_data(GTK_OBJECT(w), E_RFILTER_TE_KEY); filter_te = gtk_object_get_data(GTK_OBJECT(w), E_RFILTER_TE_KEY);
rfilter = gtk_entry_get_text(GTK_ENTRY(filter_te)); rfilter = gtk_entry_get_text(GTK_ENTRY(filter_te));
if (rfilter[0] != '\0') { if (rfilter[0] != '\0') {
rfcode = dfilter_new(); rfcode = dfilter_compile(rfilter);
if (dfilter_compile(rfcode, rfilter) != 0) { if (rfcode != NULL) {
simple_dialog(ESD_TYPE_WARN, NULL, dfilter_error_msg); simple_dialog(ESD_TYPE_WARN, NULL, dfilter_error_msg);
dfilter_destroy(rfcode);
return; return;
} }
} }

View File

@ -1,6 +1,6 @@
/* main.c /* main.c
* *
* $Id: main.c,v 1.18 1999/10/09 14:05:04 deniel Exp $ * $Id: main.c,v 1.19 1999/10/11 06:39:26 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -162,6 +162,7 @@ follow_stream_cb( GtkWidget *w, gpointer data ) {
char filename1[128+1]; char filename1[128+1];
GtkWidget *streamwindow, *box, *text, *vscrollbar, *table; GtkWidget *streamwindow, *box, *text, *vscrollbar, *table;
int tmp_fd; int tmp_fd;
gchar *follow_filter;
if( pi.ipproto == 6 ) { if( pi.ipproto == 6 ) {
/* we got tcp so we can follow */ /* we got tcp so we can follow */
@ -191,10 +192,10 @@ follow_stream_cb( GtkWidget *w, gpointer data ) {
/* Create a new filter that matches all packets in the TCP stream, /* Create a new filter that matches all packets in the TCP stream,
and set the display filter entry accordingly */ and set the display filter entry accordingly */
reset_tcp_reassembly(); reset_tcp_reassembly();
cf.dfilter = build_follow_filter( &pi ); follow_filter = build_follow_filter( &pi );
/* Run the display filter so it goes in effect. */ /* Run the display filter so it goes in effect. */
filter_packets(&cf); filter_packets(&cf, follow_filter);
/* the data_out_file should now be full of the streams information */ /* the data_out_file should now be full of the streams information */
fclose( data_out_file ); fclose( data_out_file );
@ -317,17 +318,12 @@ match_selected_cb(GtkWidget *w, gpointer data)
} }
} }
if( cf.dfilter != NULL ) {
/* get rid of this one */
g_free( cf.dfilter );
}
/* create a new one and set the display filter entry accordingly */ /* create a new one and set the display filter entry accordingly */
cf.dfilter = buf;
if (filter_te) { if (filter_te) {
gtk_entry_set_text(GTK_ENTRY(filter_te), cf.dfilter); gtk_entry_set_text(GTK_ENTRY(filter_te), buf);
} }
/* Run the display filter so it goes in effect. */ /* Run the display filter so it goes in effect. */
filter_packets(&cf); filter_packets(&cf, buf);
} }
/* Run the current display filter on the current packet set, and /* Run the current display filter on the current packet set, and
@ -337,18 +333,7 @@ filter_activate_cb(GtkWidget *w, gpointer data)
{ {
char *s = gtk_entry_get_text(GTK_ENTRY(w)); char *s = gtk_entry_get_text(GTK_ENTRY(w));
if (cf.dfilter) filter_packets(&cf, g_strdup(s));
g_free(cf.dfilter);
/* simple check for empty string. XXX - need to modify to search for /^\s+$/ */
if (s[0] == '\0' ) {
cf.dfilter = NULL;
}
else {
cf.dfilter = g_strdup(s);
}
filter_packets(&cf);
} }
/* What to do when a list item is selected/unselected */ /* What to do when a list item is selected/unselected */
@ -522,7 +507,7 @@ main(int argc, char *argv[])
cf.fh = NULL; cf.fh = NULL;
cf.rfcode = NULL; cf.rfcode = NULL;
cf.dfilter = NULL; cf.dfilter = NULL;
cf.dfcode = dfilter_new(); cf.dfcode = NULL;
#ifdef HAVE_LIBPCAP #ifdef HAVE_LIBPCAP
cf.cfilter = NULL; cf.cfilter = NULL;
#endif #endif
@ -876,10 +861,9 @@ main(int argc, char *argv[])
up on top of us. */ up on top of us. */
if (cf_name) { if (cf_name) {
if (rfilter != NULL) { if (rfilter != NULL) {
rfcode = dfilter_new(); rfcode = dfilter_compile(rfilter);
if (dfilter_compile(rfcode, rfilter) != 0) { if (rfcode == NULL) {
simple_dialog(ESD_TYPE_WARN, NULL, dfilter_error_msg); simple_dialog(ESD_TYPE_WARN, NULL, dfilter_error_msg);
dfilter_destroy(rfcode);
rfilter_parse_failed = TRUE; rfilter_parse_failed = TRUE;
} }
} }

View File

@ -1,7 +1,7 @@
/* summary.c /* summary.c
* Routines for capture file summary window * Routines for capture file summary window
* *
* $Id: summary.c,v 1.12 1999/09/09 02:42:26 gram Exp $ * $Id: summary.c,v 1.13 1999/10/11 06:39:01 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -249,8 +249,8 @@ traffic_bytes/seconds);
add_string_to_box(string_buff, capture_box); add_string_to_box(string_buff, capture_box);
/* Display filter */ /* Display filter */
if (DFILTER_CONTAINS_FILTER(cf.dfcode)) { if (cf.dfilter) {
snprintf(string_buff, SUM_STR_MAX, "Display filter: %s", cf.dfcode->dftext); snprintf(string_buff, SUM_STR_MAX, "Display filter: %s", cf.dfilter);
} else { } else {
sprintf(string_buff, "Display filter: none"); sprintf(string_buff, "Display filter: none");
} }