From e3ecdc04ace5b36b14ef465d40a7d98e3dc85c12 Mon Sep 17 00:00:00 2001 From: ulfl Date: Sat, 26 Mar 2005 11:32:43 +0000 Subject: move some color_filter related things from file.c to color_filters.c git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@13920 f5534014-38df-0310-8fa8-9805f1628bb7 --- color_filters.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'color_filters.c') 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 #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 -- cgit v1.2.3