aboutsummaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2000-07-09 03:29:42 +0000
committerGuy Harris <guy@alum.mit.edu>2000-07-09 03:29:42 +0000
commit0a71de81373a2e08f0f0b7f76265d823ba46f821 (patch)
tree41d0d42efe9bb5a669c4f5448a652571fa6db814 /file.c
parent57d8e47ad0ef7be6aa8e9d378d9aac2d6468ed27 (diff)
Turn the code of "colorize_packet()" into a static routine that is given
a word to use in the progress dialog, and a flag indicating whether the display filter is to be reevaluated or not, and: have "colorize_packet()" call that routine with "Colorizing" and FALSE as those arguments; have the filtering code call that routine with "Filtering" and TRUE as those arguments; add an exported routine to call that routine with "Reprocessing" and TRUE as those arguments, to use to re-generate the packet list and to re-filter the packets if a protocol preference has been changed. Keep track of whether preferences are changed from their initial value by a preferences file or a command-line option, or from their previous value by the "Preferences" dialog box; have "prefs_apply_all()" only call the "apply" callback for a module if they have. Call "prefs_apply_all()" after the command-line arguments have been parsed and after "OK" has been clicked in the "Preferences" dialog box, to notify modules of preference changes if they've registered a callback for that. After "OK" has been clicked in the "Preferences" dialog box, if any preferences have changed, call the reprocessing routine, as the summary line for some frames and/or the current display filter's value when applied to some frames may have changed as a result of a preference change. Do the same after "OK" or "Apply" has been clicked in the "Display Options" dialog box (as it controls a protocol preferences item. svn path=/trunk/; revision=2126
Diffstat (limited to 'file.c')
-rw-r--r--file.c109
1 files changed, 74 insertions, 35 deletions
diff --git a/file.c b/file.c
index f1595d0737..f9c895e0e7 100644
--- a/file.c
+++ b/file.c
@@ -1,7 +1,7 @@
/* file.c
* File I/O routines
*
- * $Id: file.c,v 1.196 2000/07/07 23:09:03 guy Exp $
+ * $Id: file.c,v 1.197 2000/07/09 03:29:26 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -95,6 +95,9 @@ static guint32 prevsec, prevusec;
static void read_packet(capture_file *cf, int offset);
+static void rescan_packets(capture_file *cf, const char *action,
+ gboolean refilter);
+
static void set_selected_row(int row);
static void freeze_clist(capture_file *cf);
@@ -589,7 +592,8 @@ apply_color_filter(gpointer filter_arg, gpointer argp)
static int
add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
- union wtap_pseudo_header *pseudo_header, const u_char *buf)
+ union wtap_pseudo_header *pseudo_header, const u_char *buf,
+ gboolean refilter)
{
apply_color_filter_args args;
gint i, row;
@@ -620,37 +624,57 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
fdata->cinfo->col_data[i][0] = '\0';
}
- /* Apply the filters */
- if (cf->dfcode != NULL || filter_list != NULL) {
+ /* If either
+
+ we have a display filter and are re-applying it;
+
+ we have a list of color filters;
+
+ we have plugins to apply;
+
+ allocate a protocol tree root node, so that we'll construct
+ a protocol tree against which a filter expression can be
+ evaluated. */
+ if ((cf->dfcode != NULL && refilter) || filter_list != NULL
+#ifdef HAVE_PLUGINS
+ || enabled_plugins_number > 0
+#endif
+ )
protocol_tree = proto_tree_create_root();
- dissect_packet(pseudo_header, buf, fdata, protocol_tree);
- if (cf->dfcode != NULL)
- fdata->flags.passed_dfilter = dfilter_apply(cf->dfcode, protocol_tree, buf, fdata->cap_len) ? 1 : 0;
- else
- fdata->flags.passed_dfilter = 1;
- /* Apply color filters, if we have any. */
+ /* Dissect the frame. */
+ dissect_packet(pseudo_header, buf, fdata, protocol_tree);
+
+ /* If we have a display filter, apply it if we're refiltering, otherwise
+ leave the "passed_dfilter" flag alone.
+
+ If we don't have a display filter, set "passed_dfilter" to 1. */
+ if (cf->dfcode != NULL) {
+ if (refilter) {
+ if (cf->dfcode != NULL)
+ fdata->flags.passed_dfilter = dfilter_apply(cf->dfcode, protocol_tree, buf, fdata->cap_len) ? 1 : 0;
+ else
+ fdata->flags.passed_dfilter = 1;
+ }
+ } else
+ fdata->flags.passed_dfilter = 1;
+
+ /* If we have color filters, and the frame is to be displayed, apply
+ the color filters. */
+ if (fdata->flags.passed_dfilter) {
if (filter_list != NULL) {
args.protocol_tree = protocol_tree;
args.pd = buf;
args.fdata = fdata;
g_slist_foreach(filter_list, apply_color_filter, &args);
}
- proto_tree_free(protocol_tree);
- }
- else {
-#ifdef HAVE_PLUGINS
- if (enabled_plugins_number > 0)
- protocol_tree = proto_tree_create_root();
-#endif
- dissect_packet(pseudo_header, buf, fdata, protocol_tree);
- fdata->flags.passed_dfilter = 1;
-#ifdef HAVE_PLUGINS
- if (protocol_tree)
- proto_tree_free(protocol_tree);
-#endif
}
+ /* There are no more filters to apply, so we don't need any protocol
+ tree; free it if we created it. */
+ if (protocol_tree != NULL)
+ proto_tree_free(protocol_tree);
+
if (fdata->flags.passed_dfilter) {
/* This frame passed the display filter, so add it to the clist. */
@@ -766,7 +790,7 @@ read_packet(capture_file *cf, int offset)
cf->count++;
fdata->num = cf->count;
- add_packet_to_packet_list(fdata, cf, pseudo_header, buf);
+ add_packet_to_packet_list(fdata, cf, pseudo_header, buf, TRUE);
} else {
/* XXX - if we didn't have read filters, or if we could avoid
allocating the "frame_data" structure until we knew whether
@@ -814,18 +838,32 @@ filter_packets(capture_file *cf, gchar *dftext)
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);
+ /* Now rescan the packet list, applying the new filter. */
+ rescan_packets(cf, "Filtering", TRUE);
return 1;
}
void
colorize_packets(capture_file *cf)
{
+ rescan_packets(cf, "Colorizing", FALSE);
+}
+
+void
+redissect_packets(capture_file *cf)
+{
+ rescan_packets(cf, "Reprocessing", TRUE);
+}
+
+/* Rescan the list of packets, reconstructing the CList.
+
+ "action" describes why we're doing this; it's used in the progress
+ dialog box.
+
+ "refilter" is TRUE if we need to re-evaluate the filter expression. */
+static void
+rescan_packets(capture_file *cf, const char *action, gboolean refilter)
+{
frame_data *fdata;
progdlg_t *progbar;
gboolean stop_flag;
@@ -866,9 +904,9 @@ colorize_packets(capture_file *cf)
cf->first_displayed = NULL;
cf->last_displayed = NULL;
- /* Iterate through the list of packets, calling a routine
- to run the filter on the packet, see if it matches, and
- put it in the display list if so. */
+ /* Iterate through the list of frames. Call a routine for each frame
+ to check whether it should be displayed and, if so, add it to
+ the display list. */
firstsec = 0;
firstusec = 0;
prevsec = 0;
@@ -883,7 +921,7 @@ colorize_packets(capture_file *cf)
count = 0;
stop_flag = FALSE;
- progbar = create_progress_dlg("Filtering", "Stop", &stop_flag);
+ progbar = create_progress_dlg(action, "Stop", &stop_flag);
for (fdata = cf->plist; fdata != NULL; fdata = fdata->next) {
/* Update the progress bar, but do it only N_PROGBAR_UPDATES times;
@@ -923,7 +961,8 @@ colorize_packets(capture_file *cf)
wtap_seek_read (cf->wth, fdata->file_off, &cf->pseudo_header,
cf->pd, fdata->cap_len);
- row = add_packet_to_packet_list(fdata, cf, &cf->pseudo_header, cf->pd);
+ row = add_packet_to_packet_list(fdata, cf, &cf->pseudo_header, cf->pd,
+ refilter);
if (fdata == selected_frame)
selected_row = row;
}