diff options
author | Ulf Lamping <ulf.lamping@web.de> | 2006-10-02 21:55:26 +0000 |
---|---|---|
committer | Ulf Lamping <ulf.lamping@web.de> | 2006-10-02 21:55:26 +0000 |
commit | b2c8fb8f5584e06e2c642ef16f51afff12e389c5 (patch) | |
tree | e11a9de782b4b722823ec6544dc05c04c82643a5 /color_filters.c | |
parent | 765835ac7af9b449b47f76a7229024979284fddb (diff) |
refactor apply_color_filter() as it was a bit confusing - it will also be a bit faster now -
and some other minor code cleanup
svn path=/trunk/; revision=19398
Diffstat (limited to 'color_filters.c')
-rw-r--r-- | color_filters.c | 113 |
1 files changed, 46 insertions, 67 deletions
diff --git a/color_filters.c b/color_filters.c index 99343d389d..eba1867825 100644 --- a/color_filters.c +++ b/color_filters.c @@ -131,16 +131,6 @@ color_filter_new(const gchar *name, /* The name of the filter to create */ return colorf; } -static void -prime_edt(gpointer data, gpointer user_data) -{ - color_filter_t *colorf = data; - epan_dissect_t *edt = user_data; - - if (colorf->c_colorfilter != NULL) - epan_dissect_prime_dfilter(edt, colorf->c_colorfilter); -} - gboolean color_filters_used(void) { @@ -154,58 +144,48 @@ color_filters_enable(gboolean enable) } -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.) - */ +/* prepare the epan_dissect_t for the filter */ static void -apply_color_filter(gpointer filter_arg, gpointer argp) +prime_edt(gpointer data, gpointer user_data) { - color_filter_t *colorf = filter_arg; - apply_color_filter_args *args = argp; + color_filter_t *colorf = data; + epan_dissect_t *edt = user_data; - if (colorf->c_colorfilter != NULL && args->colorf == NULL) { - if (dfilter_apply_edt(colorf->c_colorfilter, args->edt)) - args->colorf = colorf; - } + if (colorf->c_colorfilter != NULL) + epan_dissect_prime_dfilter(edt, colorf->c_colorfilter); } +/* Prime the epan_dissect_t with all the compiler + * color filters in 'color_filter_list'. */ +void +color_filters_prime_edt(epan_dissect_t *edt) +{ + g_slist_foreach(color_filter_list, prime_edt, edt); +} +/* Colorize a single packet of the packet list */ 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; + GSList *curr; + color_filter_t *colorf; - /* If we have color filters, "search" for the matching one. */ + /* 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)); - } + curr = color_filter_list; + + while( (curr = g_slist_next(curr)) != NULL) { + colorf = curr->data; + if ((colorf->c_colorfilter != NULL) && + dfilter_apply_edt(colorf->c_colorfilter, edt)) { + /* this is the filter to use, apply it to the packet list */ + packet_list_set_colors(row, &(colorf->fg_color), &(colorf->bg_color)); + return colorf; + } + } } - return args.colorf; -} - -/* Prime the epan_dissect_t with all the compiler - * color filters in 'color_filter_list'. */ -void -color_filters_prime_edt(epan_dissect_t *edt) -{ - g_slist_foreach(color_filter_list, prime_edt, edt); + return NULL; } /* read filters from the given file */ @@ -500,6 +480,23 @@ color_filters_write(void) return TRUE; } +/* save filters in some other filter file (export) */ +gboolean +color_filters_export(gchar *path, gboolean only_marked) +{ + FILE *f; + + if ((f = eth_fopen(path, "w+")) == NULL) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "Could not open\n%s\nfor writing: %s.", + path, strerror(errno)); + return FALSE; + } + write_filters_file(f, only_marked); + fclose(f); + return TRUE; +} + /* delete users filter file and reload global filters */ gboolean color_filters_revert(void) @@ -518,21 +515,3 @@ color_filters_revert(void) color_filters_init(); return TRUE; } - - -/* save filters in some other filter file (export) */ -gboolean -color_filters_export(gchar *path, gboolean only_marked) -{ - FILE *f; - - if ((f = eth_fopen(path, "w+")) == NULL) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not open\n%s\nfor writing: %s.", - path, strerror(errno)); - return FALSE; - } - write_filters_file(f, only_marked); - fclose(f); - return TRUE; -} |