aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--color_filters.c54
-rw-r--r--color_filters.h15
-rw-r--r--file.c61
3 files changed, 76 insertions, 54 deletions
diff --git a/color_filters.c b/color_filters.c
index 951921ff15..cfa0e602df 100644
--- a/color_filters.c
+++ b/color_filters.c
@@ -41,6 +41,7 @@
#include "file.h"
#include <epan/dfilter/dfilter.h>
#include "simple_dialog.h"
+#include "ui_util.h"
static gboolean read_filters(void);
static gboolean read_global_filters(void);
@@ -136,6 +137,59 @@ prime_edt(gpointer data, gpointer user_data)
epan_dissect_prime_dfilter(edt, colorf->c_colorfilter);
}
+gboolean
+color_filters_used(void)
+{
+ return color_filter_list != NULL;
+}
+
+
+typedef struct {
+ color_filter_t *colorf;
+ epan_dissect_t *edt;
+} apply_color_filter_args;
+
+/*
+ * If no color filter has been applied, apply this one.
+ * (The "if no color filter has been applied" is to handle the case where
+ * more than one color filter matches the packet.)
+ */
+static void
+apply_color_filter(gpointer filter_arg, gpointer argp)
+{
+ color_filter_t *colorf = filter_arg;
+ apply_color_filter_args *args = argp;
+
+ if (colorf->c_colorfilter != NULL && args->colorf == NULL) {
+ if (dfilter_apply_edt(colorf->c_colorfilter, args->edt))
+ args->colorf = colorf;
+ }
+}
+
+
+color_filter_t *
+color_filters_colorize_packet(gint row, epan_dissect_t *edt)
+{
+ apply_color_filter_args args;
+
+
+ /* We don't yet have a color filter to apply. */
+ args.colorf = NULL;
+
+ /* If we have color filters, "search" for the matching one. */
+ if (color_filters_used()) {
+ args.edt = edt;
+ g_slist_foreach(color_filter_list, apply_color_filter, &args);
+
+ /* If the packet matches a color filter, apply the colors. */
+ if (args.colorf != NULL) {
+ packet_list_set_colors(row, &(args.colorf->fg_color), &(args.colorf->bg_color));
+ }
+ }
+
+ return args.colorf;
+}
+
/* Prime the epan_dissect_t with all the compiler
* color filters in 'color_filter_list'. */
void
diff --git a/color_filters.h b/color_filters.h
index 5915e8f4f5..097c0757c5 100644
--- a/color_filters.h
+++ b/color_filters.h
@@ -78,6 +78,21 @@ gboolean color_filters_export(gchar *path, gboolean only_marked);
*/
void color_filters_prime_edt(epan_dissect_t *edt);
+/** Color filters currently used?
+ *
+ * @return TRUE, if filters are used
+ */
+gboolean color_filters_used(void);
+
+/** Colorize a specific packet.
+ *
+ * @param row the row in the packet list
+ * @param edt the dissected packet
+ * @return the matching color filter or NULL
+ */
+color_filter_t *
+color_filters_colorize_packet(gint row, epan_dissect_t *edt);
+
/** Create a new color filter.
*
* @param name the name of the filter
diff --git a/file.c b/file.c
index 776a1db78e..3ae46ee306 100644
--- a/file.c
+++ b/file.c
@@ -688,34 +688,11 @@ void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode)
cf->rfcode = rfcode;
}
-typedef struct {
- color_filter_t *colorf;
- epan_dissect_t *edt;
-} apply_color_filter_args;
-
-/*
- * If no color filter has been applied, apply this one.
- * (The "if no color filter has been applied" is to handle the case where
- * more than one color filter matches the packet.)
- */
-static void
-apply_color_filter(gpointer filter_arg, gpointer argp)
-{
- color_filter_t *colorf = filter_arg;
- apply_color_filter_args *args = argp;
-
- if (colorf->c_colorfilter != NULL && args->colorf == NULL) {
- if (dfilter_apply_edt(colorf->c_colorfilter, args->edt))
- args->colorf = colorf;
- }
-}
-
static int
add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
union wtap_pseudo_header *pseudo_header, const guchar *buf,
gboolean refilter)
{
- apply_color_filter_args args;
gint row;
gboolean create_proto_tree = FALSE;
epan_dissect_t *edt;
@@ -723,9 +700,6 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
/* just add some value here until we know if it is being displayed or not */
fdata->cum_bytes = cum_bytes + fdata->pkt_len;
- /* We don't yet have a color filter to apply. */
- args.colorf = NULL;
-
/* If we don't have the time stamp of the first packet in the
capture, it's because this is the first packet. Save the time
stamp of this packet as the time stamp of the first packet. */
@@ -778,7 +752,7 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
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) || color_filter_list != NULL
+ if ((cf->dfcode != NULL && refilter) || color_filters_used()
|| num_tap_filters != 0)
create_proto_tree = TRUE;
@@ -788,7 +762,7 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
if (cf->dfcode != NULL && refilter) {
epan_dissect_prime_dfilter(edt, cf->dfcode);
}
- if (color_filter_list) {
+ if (color_filters_used()) {
color_filters_prime_edt(edt);
}
tap_queue_init(edt);
@@ -806,16 +780,6 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
} 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 (color_filter_list != NULL) {
- args.edt = edt;
- g_slist_foreach(color_filter_list, apply_color_filter, &args);
- }
- }
-
-
if( (fdata->flags.passed_dfilter)
|| (edt->pi.fd->flags.ref_time) ){
/* This frame either passed the display filter list or is marked as
@@ -853,25 +817,14 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
row = packet_list_append(cf->cinfo.col_data, fdata);
- /* If the packet matches a color filter,
- * store matching color_filter_t object in frame data. */
- if (color_filter_list != NULL && (args.colorf != NULL)) {
- /* add the matching colorfilter to the frame data */
- fdata->color_filter = args.colorf;
- /* If packet is marked, use colors from preferences */
- if (fdata->flags.marked) {
- packet_list_set_colors(row, &prefs.gui_marked_fg, &prefs.gui_marked_bg);
- } else /* if (color_filter_list != NULL && (args.colorf != NULL)) */ {
- packet_list_set_colors(row, &(args.colorf->fg_color),
- &(args.colorf->bg_color));
- }
- } else {
- /* No color filter match */
- fdata->color_filter = NULL;
+ /* colorize packet: if packet is marked, use preferences,
+ otherwise try to apply color filters */
if (fdata->flags.marked) {
+ fdata->color_filter = NULL;
packet_list_set_colors(row, &prefs.gui_marked_fg, &prefs.gui_marked_bg);
+ } else {
+ fdata->color_filter = color_filters_colorize_packet(row, edt);
}
- }
/* Set the time of the previous displayed frame to the time of this
frame. */