diff options
-rw-r--r-- | colors.c | 17 | ||||
-rw-r--r-- | dfilter.c | 35 | ||||
-rw-r--r-- | dfilter.h | 6 | ||||
-rw-r--r-- | file.c | 27 | ||||
-rw-r--r-- | gtk/file_dlg.c | 11 | ||||
-rw-r--r-- | gtk/main.c | 11 |
6 files changed, 57 insertions, 50 deletions
@@ -1,7 +1,7 @@ /* colors.c * Definitions for color structures and routines * - * $Id: colors.c,v 1.13 1999/10/11 06:39:02 guy Exp $ + * $Id: colors.c,v 1.14 1999/10/12 05:00:49 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -116,10 +116,10 @@ colors_init(capture_file *cf) new_color_filter(cf->colors, default_colors[i].proto, default_colors[i].proto); color_filter(cf,i)->bg_color = color; - color_filter(cf,i)->c_colorfilter = dfilter_compile(default_colors[i].proto); - if(color_filter(cf,i)->c_colorfilter == NULL){ + if (dfilter_compile(default_colors[i].proto, + &color_filter(cf,i)->c_colorfilter) != 0) { simple_dialog(ESD_TYPE_WARN, NULL, - "Cannot compile default filter %s.\n%s", + "Cannot compile default color filter %s.\n%s", default_colors[i].proto, dfilter_error_msg); /* should reject this filter */ } @@ -243,10 +243,9 @@ read_filters(capture_file *cf) name, filter, &bg_r, &bg_g, &bg_b, &fg_r, &fg_g, &fg_b) == 8){ /* we got a filter */ - temp_dfilter = dfilter_compile(filter); - if(temp_dfilter == NULL){ + if(dfilter_compile(filter, &temp_dfilter) != 0){ simple_dialog(ESD_TYPE_WARN, NULL, - "Could not compile filter %s from saved filters because\n%s", + "Could not compile color filter %s from saved filters.\n%s", name, dfilter_error_msg); continue; } @@ -589,9 +588,7 @@ colorize_ok_cb (GtkButton *button, - compiled_filter = dfilter_compile(filter_text); - - if(compiled_filter == NULL ){ + if(dfilter_compile(filter_text, &compiled_filter) != 0 ){ 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); } else { @@ -1,7 +1,7 @@ /* dfilter.c * Routines for display filters * - * $Id: dfilter.c,v 1.29 1999/10/12 04:21:10 gram Exp $ + * $Id: dfilter.c,v 1.30 1999/10/12 05:00:50 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -133,15 +133,20 @@ dfilter_cleanup(void) * display filter each time, without having to clear any memory used, since * dfilter_compile will take care of that automatically. * - * 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. + * Returns 0 on success, non-zero on failure. + * + * On success, sets the "dfilter *" pointed to by its second argument + * either to a null pointer (if the filter is a null filter, as + * generated by an all-blank string) or to a pointer to a newly-allocated + * dfilter structure (if the filter isn't null). + * + * On failure, "dfilter_error_msg" points to an appropriate error message. * This error message is a global string, so another invocation of * dfilter_compile will clear it. If the caller needs is stored, he * needs to g_strdup it himself. */ -dfilter* -dfilter_compile(gchar *dfilter_text) +int +dfilter_compile(gchar *dfilter_text, dfilter **dfp) { dfilter *df; int retval; @@ -184,12 +189,22 @@ dfilter_compile(gchar *dfilter_text) /* Set global_df to NULL just to be tidy. */ global_df = NULL; - if (retval == 0) - return df; - else { + if (retval == 0) { + /* Success. Check if the filter is empty; if so, discard + * it and set "*dfp" to NULL, otherwise set "*dfp" to + * point to the filter. */ + if (df->dftree == NULL) { + /* The filter is empty. */ + dfilter_destroy(df); + df = NULL; + } + *dfp = df; + } else { + /* Failure. Destroy the filter. */ dfilter_destroy(df); - return NULL; + df = NULL; } + return retval; } /* Allocates new dfilter, initializes values, and returns pointer to dfilter */ @@ -1,7 +1,7 @@ /* dfilter.h * Definitions for display filters * - * $Id: dfilter.h,v 1.13 1999/10/12 04:21:11 gram Exp $ + * $Id: dfilter.h,v 1.14 1999/10/12 05:00:47 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -26,8 +26,6 @@ #ifndef __DFILTER_H__ #define __DFILTER_H__ -#define DFILTER_CONTAINS_FILTER(x) ((x) != NULL && (x)->dftree) - /* dfilter_error_msg is NULL if there was no error during dfilter_compile, * otherwise it points to a displayable error message. */ extern gchar *dfilter_error_msg; @@ -58,7 +56,7 @@ dfilter* dfilter_new(void); void dfilter_destroy(dfilter *df); /* Compile display filter text */ -dfilter* dfilter_compile(gchar* dfilter_text); +int dfilter_compile(gchar* dfilter_text, dfilter** dfp); /* Apply compiled dfilter to a proto_tree */ gboolean dfilter_apply(dfilter *df, proto_tree *ptree, const guint8* pd); @@ -1,7 +1,7 @@ /* file.c * File I/O routines * - * $Id: file.c,v 1.107 1999/10/12 04:21:11 gram Exp $ + * $Id: file.c,v 1.108 1999/10/12 05:00:47 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -622,11 +622,11 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf } /* Apply the filters */ - if (DFILTER_CONTAINS_FILTER(cf->dfcode) || + if (cf->dfcode != NULL || CFILTERS_CONTAINS_FILTER(cf)) { protocol_tree = proto_tree_create_root(); dissect_packet(buf, fdata, protocol_tree); - if( DFILTER_CONTAINS_FILTER(cf->dfcode) ) + if (cf->dfcode != NULL) fdata->passed_dfilter = dfilter_apply(cf->dfcode, protocol_tree, cf->pd); else fdata->passed_dfilter = TRUE; @@ -749,12 +749,10 @@ wtap_dispatch_cb(u_char *user, const struct wtap_pkthdr *phdr, int offset, passed = TRUE; if (cf->rfcode) { - if (DFILTER_CONTAINS_FILTER(cf->rfcode)) { - protocol_tree = proto_tree_create_root(); - dissect_packet(buf, fdata, protocol_tree); - passed = dfilter_apply(cf->rfcode, protocol_tree, cf->pd); - proto_tree_free(protocol_tree); - } + protocol_tree = proto_tree_create_root(); + dissect_packet(buf, fdata, protocol_tree); + passed = dfilter_apply(cf->rfcode, protocol_tree, cf->pd); + proto_tree_free(protocol_tree); } if (passed) { plist_end = cf->plist_end; @@ -782,20 +780,17 @@ filter_packets(capture_file *cf, gchar *dftext) /* * We have a filter; try to compile it. */ - dfcode = dfilter_compile(dftext); - if (dfcode == NULL) { + if (dfilter_compile(dftext, &dfcode) != 0) { + /* The attempt failed; report an error. */ 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. */ + if (dfcode == NULL) { + /* Yes - free the filter text, and set it to null. */ g_free(dftext); dftext = NULL; - dfilter_destroy(dfcode); - dfcode = NULL; } } diff --git a/gtk/file_dlg.c b/gtk/file_dlg.c index 571dd1c47f..09e4fdd3d3 100644 --- a/gtk/file_dlg.c +++ b/gtk/file_dlg.c @@ -1,7 +1,7 @@ /* file_dlg.c * Dialog boxes for handling files * - * $Id: file_dlg.c,v 1.9 1999/10/11 06:39:25 guy Exp $ + * $Id: file_dlg.c,v 1.10 1999/10/12 05:01:07 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -121,12 +121,9 @@ file_open_ok_cb(GtkWidget *w, GtkFileSelection *fs) { cf_name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION (fs))); filter_te = gtk_object_get_data(GTK_OBJECT(w), E_RFILTER_TE_KEY); rfilter = gtk_entry_get_text(GTK_ENTRY(filter_te)); - if (rfilter[0] != '\0') { - rfcode = dfilter_compile(rfilter); - if (rfcode != NULL) { - simple_dialog(ESD_TYPE_WARN, NULL, dfilter_error_msg); - return; - } + if (dfilter_compile(rfilter, &rfcode) != 0) { + simple_dialog(ESD_TYPE_WARN, NULL, dfilter_error_msg); + return; } /* Try to open the capture file. */ diff --git a/gtk/main.c b/gtk/main.c index f58481ea4c..7a747cff2e 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.20 1999/10/11 18:02:46 guy Exp $ + * $Id: main.c,v 1.21 1999/10/12 05:01:07 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -862,14 +862,16 @@ main(int argc, char *argv[]) up on top of us. */ if (cf_name) { if (rfilter != NULL) { - rfcode = dfilter_compile(rfilter); - if (rfcode == NULL) { + if (dfilter_compile(rfilter, &rfcode) != 0) { simple_dialog(ESD_TYPE_WARN, NULL, dfilter_error_msg); rfilter_parse_failed = TRUE; } } if (!rfilter_parse_failed) { if ((err = open_cap_file(cf_name, &cf)) == 0) { + /* "open_cap_file()" succeeded, so it closed the previous + capture file, and thus destroyed any previous read filter + attached to "cf". */ cf.rfcode = rfcode; err = read_cap_file(&cf); s = strrchr(cf_name, '/'); @@ -878,6 +880,9 @@ main(int argc, char *argv[]) *s = '\0'; } set_menu_sensitivity("/File/Save As...", TRUE); + } else { + dfilter_destroy(rfcode); + cf.rfcode = NULL; } } } |