From 5e4bbcda9839d9fd4480db8c4f9386ff388d166c Mon Sep 17 00:00:00 2001 From: Michael Mann Date: Tue, 22 Dec 2015 15:07:00 -0500 Subject: Refactor GUI dependencies out of color_filters.[ch] and move it to epan directory. This also moved color.h into color_filters.h Change-Id: Ic19e27aa1b3ec67e764aa7ee8bbef7b1187bb12e Reviewed-on: https://code.wireshark.org/review/12831 Petri-Dish: Michael Mann Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann --- CMakeLists.txt | 3 +- Makefile.common | 3 - Makefile.nmake | 16 +- color.h | 74 --- color_filters.c | 818 -------------------------------- color_filters.h | 215 --------- debian/libwireshark-dev.install | 1 - epan/CMakeLists.txt | 3 +- epan/Makefile.am | 2 +- epan/Makefile.common | 2 + epan/color_filters.c | 843 +++++++++++++++++++++++++++++++++ epan/color_filters.h | 235 +++++++++ epan/dissectors/file-file.c | 3 +- epan/dissectors/packet-frame.c | 3 +- epan/prefs.h | 2 +- file.c | 3 +- ui/gtk/capture_file_dlg.c | 15 +- ui/gtk/color_dlg.c | 57 ++- ui/gtk/color_edit_dlg.c | 3 +- ui/gtk/color_utils.c | 9 +- ui/gtk/color_utils.h | 10 +- ui/gtk/compare_stat.c | 9 +- ui/gtk/funnel_stat.c | 9 +- ui/gtk/main.c | 41 +- ui/gtk/main_menubar.c | 13 +- ui/gtk/packet_list.c | 2 +- ui/gtk/packet_list_store.c | 3 +- ui/qt/Wireshark.pro | 1 - ui/qt/color_utils.cpp | 22 - ui/qt/color_utils.h | 4 +- ui/qt/coloring_rules_dialog.cpp | 72 ++- ui/qt/column_preferences_frame.cpp | 2 - ui/qt/funnel_statistics.cpp | 10 +- ui/qt/main_window_slots.cpp | 28 +- ui/qt/module_preferences_scroll_area.h | 2 - ui/qt/packet_list.cpp | 3 +- ui/qt/packet_list_model.cpp | 3 +- ui/qt/packet_list_record.cpp | 3 +- ui/qt/preferences_dialog.h | 2 - ui/qt/wireshark_application.cpp | 12 +- ui/ui_util.h | 10 + ui/win32/file_dlg_win32.c | 16 +- wireshark-qt.cpp | 15 +- 43 files changed, 1334 insertions(+), 1268 deletions(-) delete mode 100644 color.h delete mode 100644 color_filters.c delete mode 100644 color_filters.h create mode 100644 epan/color_filters.c create mode 100644 epan/color_filters.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6995d28075..1090342539 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1014,7 +1014,7 @@ add_subdirectory( wiretap ) add_subdirectory( wsutil ) if(NOT WIN32) - add_custom_target(dumpabi DEPENDS dumpabi-libwireshark dumpabi-libwiretap dumpabi-libwsutil color.h) + add_custom_target(dumpabi DEPENDS dumpabi-libwireshark dumpabi-libwiretap dumpabi-libwsutil) endif() if(ENABLE_ECHLD) @@ -1695,7 +1695,6 @@ if( (BUILD_wireshark AND QT_FOUND) OR (BUILD_wireshark_gtk AND GTK_FOUND) ) set(WIRESHARK_SRC capture_info.c capture_opts.c - color_filters.c file.c fileset.c summary.c diff --git a/Makefile.common b/Makefile.common index 060e2b31a9..9f3c202a94 100644 --- a/Makefile.common +++ b/Makefile.common @@ -50,7 +50,6 @@ SHARK_COMMON_SRC = \ # corresponding headers SHARK_COMMON_INCLUDES = \ cfile.h \ - color.h \ extcap.h \ extcap_parser.h \ file.h \ @@ -64,7 +63,6 @@ WIRESHARK_COMMON_SRC = \ $(SHARK_COMMON_SRC) \ capture_info.c \ capture_opts.c \ - color_filters.c \ file.c \ fileset.c \ summary.c @@ -73,7 +71,6 @@ WIRESHARK_COMMON_SRC = \ WIRESHARK_COMMON_INCLUDES = \ capture_info.h \ capture_opts.h \ - color_filters.h \ globals.h \ log.h \ summary.h \ diff --git a/Makefile.nmake b/Makefile.nmake index 6a8f3da6a0..fa977e0d77 100644 --- a/Makefile.nmake +++ b/Makefile.nmake @@ -454,24 +454,24 @@ androiddump.exe : $(LIBS_CHECK) config.h androiddump.obj wsutil\libwsutil.lib wi mt.exe -nologo -manifest "androiddump.exe.manifest" -outputresource:androiddump.exe;1 !ENDIF -!IFDEF LIBSSH_DIR -sshdump.exe : $(LIBS_CHECK) config.h sshdump.obj wsutil\libwsutil.lib wiretap\wiretap-$(WTAP_VERSION).lib +randpktdump.exe : $(LIBS_CHECK) config.h randpktdump.obj randpkt-core.obj wsutil\libwsutil.lib wiretap\wiretap-$(WTAP_VERSION).lib @echo Linking $@ $(LINK) @<< - /OUT:sshdump.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:WINDOWS sshdump.obj $(sshdump_LIBS) + /OUT:randpktdump.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:WINDOWS randpktdump.obj randpkt-core.obj $(randpktdump_LIBS) << !IFDEF MANIFEST_INFO_REQUIRED - mt.exe -nologo -manifest "sshdump.exe.manifest" -outputresource:sshdump.exe;1 -!ENDIF + mt.exe -nologo -manifest "randpktdump.exe.manifest" -outputresource:randpktdump.exe;1 !ENDIF -randpktdump.exe : $(LIBS_CHECK) config.h randpktdump.obj randpkt-core.obj wsutil\libwsutil.lib wiretap\wiretap-$(WTAP_VERSION).lib +!IFDEF LIBSSH_DIR +sshdump.exe : $(LIBS_CHECK) config.h sshdump.obj wsutil\libwsutil.lib wiretap\wiretap-$(WTAP_VERSION).lib @echo Linking $@ $(LINK) @<< - /OUT:randpktdump.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:WINDOWS randpktdump.obj randpkt-core.obj $(randpktdump_LIBS) + /OUT:sshdump.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:WINDOWS sshdump.obj $(sshdump_LIBS) << !IFDEF MANIFEST_INFO_REQUIRED - mt.exe -nologo -manifest "randpktdump.exe.manifest" -outputresource:randpktdump.exe;1 + mt.exe -nologo -manifest "sshdump.exe.manifest" -outputresource:sshdump.exe;1 +!ENDIF !ENDIF dumpcap.exe : $(LIBS_CHECK) config.h $(dumpcap_OBJECTS) caputils wsutil\libwsutil.lib image\dumpcap.res diff --git a/color.h b/color.h deleted file mode 100644 index 47f13ac14f..0000000000 --- a/color.h +++ /dev/null @@ -1,74 +0,0 @@ -/* color.h - * Definitions for "toolkit-independent" colors - * - * Wireshark - Network traffic analyzer - * By Gerald Combs - * Copyright 1998 Gerald Combs - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef __COLOR_H__ -#define __COLOR_H__ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * Data structure holding RGB value for a color. - * - * XXX - yes, I know, there's a "pixel" value in there as well; for - * now, it's intended to look just like a GdkColor but not to require - * that any GTK+ header files be included in order to use it. - * The way we handle colors needs to be cleaned up somewhat, in order - * to keep toolkit-specific stuff separate from toolkit-independent stuff. - */ -typedef struct { - guint32 pixel; - guint16 red; - guint16 green; - guint16 blue; -} color_t; - -/** Initialize a color with R, G, and B values, including any toolkit-dependent - ** work that needs to be done. - * - * @param color the color_t to be filled - * @param red the red value for the color - * @param green the green value for the color - * @param blue the blue value for the color - * @return TRUE if it succeeds, FALSE if it fails - */ -gboolean initialize_color(color_t *color, guint16 red, guint16 green, guint16 blue); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __COLOR_H__ */ - -/* - * Editor modelines - http://www.wireshark.org/tools/modelines.html - * - * Local variables: - * c-basic-offset: 8 - * tab-width: 8 - * indent-tabs-mode: t - * End: - * - * vi: set shiftwidth=8 tabstop=8 noexpandtab: - * :indentSize=8:tabSize=8:noTabs=false: - */ diff --git a/color_filters.c b/color_filters.c deleted file mode 100644 index bf417a93fd..0000000000 --- a/color_filters.c +++ /dev/null @@ -1,818 +0,0 @@ -/* color_filters.c - * Routines for color filters - * - * Wireshark - Network traffic analyzer - * By Gerald Combs - * Copyright 1998 Gerald Combs - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -/* - * Updated 1 Dec 10 jjm - */ - -#include - -#include - -#include -#include -#include - -#include -#include - -#include -#include "color.h" -#include "color_filters.h" -#include "file.h" -#include -#include - -#include "ui/simple_dialog.h" -#include "ui/ui_util.h" - -#define RED_COMPONENT(x) (guint16) (((((x) >> 16) & 0xff) * 65535 / 255)) -#define GREEN_COMPONENT(x) (guint16) (((((x) >> 8) & 0xff) * 65535 / 255)) -#define BLUE_COMPONENT(x) (guint16) ( (((x) & 0xff) * 65535 / 255)) - -static gboolean read_users_filters(GSList **cfl); - -/* the currently active filters */ -static GSList *color_filter_list = NULL; - -/* keep "old" deleted filters in this list until - * the dissection no longer needs them (e.g. file is closed) */ -static GSList *color_filter_deleted_list = NULL; -static GSList *color_filter_valid_list = NULL; - -/* Color Filters can en-/disabled. */ -static gboolean filters_enabled = TRUE; - -/* Remember if there are temporary coloring filters set to - * add sensitivity to the "Reset Coloring 1-10" menu item - */ -static gboolean tmp_colors_set = FALSE; - -/* Create a new filter */ -color_filter_t * -color_filter_new(const gchar *name, /* The name of the filter to create */ - const gchar *filter_string, /* The string representing the filter */ - color_t *bg_color, /* The background color */ - color_t *fg_color, /* The foreground color */ - gboolean disabled) /* Is the filter disabled? */ -{ - color_filter_t *colorf; - - colorf = (color_filter_t *)g_malloc0(sizeof (color_filter_t)); - colorf->filter_name = g_strdup(name); - colorf->filter_text = g_strdup(filter_string); - colorf->bg_color = *bg_color; - colorf->fg_color = *fg_color; - colorf->disabled = disabled; - return colorf; -} - -/* Add ten empty (temporary) colorfilters for easy coloring */ -static void -color_filters_add_tmp(GSList **cfl) -{ - gchar *name = NULL; - guint32 i; - gchar** bg_colors; - gchar** fg_colors; - gulong cval; - color_t bg_color, fg_color; - color_filter_t *colorf; - - g_assert(strlen(prefs.gui_colorized_fg)==69); - g_assert(strlen(prefs.gui_colorized_bg)==69); - fg_colors = g_strsplit(prefs.gui_colorized_fg, ",", -1); - bg_colors = g_strsplit(prefs.gui_colorized_bg, ",", -1); - - for ( i=1 ; i<=10 ; i++ ) { - name = g_strdup_printf("%s%02d",CONVERSATION_COLOR_PREFIX,i); - - /* retrieve background and foreground colors */ - cval = strtoul(fg_colors[i-1], NULL, 16); - initialize_color(&fg_color, RED_COMPONENT(cval), - GREEN_COMPONENT(cval), - BLUE_COMPONENT(cval) ); - cval = strtoul(bg_colors[i-1], NULL, 16); - initialize_color(&bg_color, RED_COMPONENT(cval), - GREEN_COMPONENT(cval), - BLUE_COMPONENT(cval) ); - colorf = color_filter_new(name, NULL, &bg_color, &fg_color, TRUE); - colorf->filter_text = g_strdup("frame"); - *cfl = g_slist_append(*cfl, colorf); - - g_free(name); - } - - g_strfreev(fg_colors); - g_strfreev(bg_colors); - - return; -} - -static gint -color_filters_find_by_name_cb(gconstpointer arg1, gconstpointer arg2) -{ - const color_filter_t *colorf = (const color_filter_t *)arg1; - const gchar *name = (const gchar *)arg2; - - return (strstr(colorf->filter_name, name)==NULL) ? -1 : 0 ; -} - - -/* Set the filter off a temporary colorfilters and enable it */ -void -color_filters_set_tmp(guint8 filt_nr, const gchar *filter, gboolean disabled) -{ - gchar *name = NULL; - const gchar *tmpfilter = NULL; - GSList *cfl; - color_filter_t *colorf; - dfilter_t *compiled_filter; - gchar *err_msg; - guint8 i; - - /* Go through the temporary filters and look for the same filter string. - * If found, clear it so that a filter can be "moved" up and down the list - */ - for ( i=1 ; i<=10 ; i++ ) { - /* If we need to reset the temporary filter (filter==NULL), don't look - * for other rules with the same filter string - */ - if( i!=filt_nr && filter==NULL ) - continue; - - name = g_strdup_printf("%s%02d",CONVERSATION_COLOR_PREFIX,i); - cfl = g_slist_find_custom(color_filter_list, name, color_filters_find_by_name_cb); - colorf = (color_filter_t *)cfl->data; - - /* Only change the filter rule if this is the rule to change or if - * a matching filter string has been found - */ - if(colorf && ( (i==filt_nr) || (strstr(filter,colorf->filter_text)!=NULL) ) ) { - /* set filter string to "frame" if we are resetting the rules - * or if we found a matching filter string which need to be cleared - */ - tmpfilter = ( (filter==NULL) || (i!=filt_nr) ) ? "frame" : filter; - if (!dfilter_compile(tmpfilter, &compiled_filter, &err_msg)) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not compile color filter name: \"%s\"" - " text: \"%s\".\n%s", name, filter, err_msg); - g_free(err_msg); - } else { - if (colorf->filter_text != NULL) - g_free(colorf->filter_text); - if (colorf->c_colorfilter != NULL) - dfilter_free(colorf->c_colorfilter); - colorf->filter_text = g_strdup(tmpfilter); - colorf->c_colorfilter = compiled_filter; - colorf->disabled = ((i!=filt_nr) ? TRUE : disabled); - /* Remember that there are now temporary coloring filters set */ - if( filter ) - tmp_colors_set = TRUE; - } - } - g_free(name); - } - return; -} - -const color_filter_t * -color_filters_tmp_color(guint8 filter_num) { - gchar *name; - color_filter_t *colorf = NULL; - GSList *cfl; - - name = g_strdup_printf("%s%02d", CONVERSATION_COLOR_PREFIX, filter_num); - cfl = g_slist_find_custom(color_filter_list, name, color_filters_find_by_name_cb); - if (cfl) { - colorf = (color_filter_t *)cfl->data; - } - g_free(name); - - return colorf; -} - -/* Reset the temporary colorfilters */ -void -color_filters_reset_tmp(void) -{ - guint8 i; - - for ( i=1 ; i<=10 ; i++ ) { - color_filters_set_tmp(i, NULL, TRUE); - } - /* Remember that there are now *no* temporary coloring filters set */ - tmp_colors_set = FALSE; - return; -} - -/* delete the specified filter */ -void -color_filter_delete(color_filter_t *colorf) -{ - if (colorf->filter_name != NULL) - g_free(colorf->filter_name); - if (colorf->filter_text != NULL) - g_free(colorf->filter_text); - if (colorf->c_colorfilter != NULL) - dfilter_free(colorf->c_colorfilter); - g_free(colorf); -} - -/* delete the specified filter (called from g_slist_foreach) */ -static void -color_filter_delete_cb(gpointer filter_arg, gpointer unused _U_) -{ - color_filter_t *colorf = (color_filter_t *)filter_arg; - - color_filter_delete(colorf); -} - -/* delete the specified list */ -void -color_filter_list_delete(GSList **cfl) -{ - g_slist_foreach(*cfl, color_filter_delete_cb, NULL); - g_slist_free(*cfl); - *cfl = NULL; -} - -/* clone a single list entries from normal to edit list */ -static color_filter_t * -color_filter_clone(color_filter_t *colorf) -{ - color_filter_t *new_colorf; - - new_colorf = (color_filter_t *)g_malloc(sizeof (color_filter_t)); - new_colorf->filter_name = g_strdup(colorf->filter_name); - new_colorf->filter_text = g_strdup(colorf->filter_text); - new_colorf->bg_color = colorf->bg_color; - new_colorf->fg_color = colorf->fg_color; - new_colorf->disabled = colorf->disabled; - new_colorf->c_colorfilter = NULL; - new_colorf->color_edit_dlg_info = NULL; - new_colorf->selected = FALSE; - - return new_colorf; -} - -static void -color_filter_list_clone_cb(gpointer filter_arg, gpointer cfl_arg) -{ - GSList **cfl = (GSList **)cfl_arg; - color_filter_t *new_colorf; - - new_colorf = color_filter_clone((color_filter_t *)filter_arg); - *cfl = g_slist_append(*cfl, new_colorf); -} - -/* clone the specified list */ -static GSList * -color_filter_list_clone(GSList *cfl) -{ - GSList *new_list = NULL; - - g_slist_foreach(cfl, color_filter_list_clone_cb, &new_list); - - return new_list; -} - -/* Initialize the filter structures (reading from file) for general running, including app startup */ -void -color_filters_init(void) -{ - /* delete all currently existing filters */ - color_filter_list_delete(&color_filter_list); - - /* start the list with the temporary colorizing rules */ - color_filters_add_tmp(&color_filter_list); - - /* try to read the users filters */ - if (!read_users_filters(&color_filter_list)) - /* if that failed, try to read the global filters */ - color_filters_read_globals(&color_filter_list); -} - -void -color_filters_reload(void) -{ - /* "move" old entries to the deleted list - * we must keep them until the dissection no longer needs them */ - color_filter_deleted_list = g_slist_concat(color_filter_deleted_list, color_filter_list); - color_filter_list = NULL; - - /* start the list with the temporary colorizing rules */ - color_filters_add_tmp(&color_filter_list); - - /* try to read the users filters */ - if (!read_users_filters(&color_filter_list)) - /* if that failed, try to read the global filters */ - color_filters_read_globals(&color_filter_list); -} - -void -color_filters_cleanup(void) -{ - /* delete the previously deleted filters */ - color_filter_list_delete(&color_filter_deleted_list); -} - -static void -color_filters_clone_cb(gpointer filter_arg, gpointer user_data) -{ - color_filter_t * new_colorf = color_filter_clone((color_filter_t *)filter_arg); - color_filter_add_cb (new_colorf, user_data); -} - -void -color_filters_clone(gpointer user_data) -{ - g_slist_foreach(color_filter_list, color_filters_clone_cb, user_data); -} - - -static void -color_filter_compile_cb(gpointer filter_arg, gpointer unused _U_) -{ - color_filter_t *colorf = (color_filter_t *)filter_arg; - gchar *err_msg; - - g_assert(colorf->c_colorfilter == NULL); - if (!dfilter_compile(colorf->filter_text, &colorf->c_colorfilter, &err_msg)) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not compile color filter name: \"%s\" text: \"%s\".\n%s", - colorf->filter_name, colorf->filter_text, err_msg); - g_free(err_msg); - /* this filter was compilable before, so this should never happen */ - /* except if the OK button of the parent window has been clicked */ - /* so don't use g_assert_not_reached() but check the filters again */ - } -} - -static void -color_filter_validate_cb(gpointer filter_arg, gpointer unused _U_) -{ - color_filter_t *colorf = (color_filter_t *)filter_arg; - gchar *err_msg; - - g_assert(colorf->c_colorfilter == NULL); - if (!dfilter_compile(colorf->filter_text, &colorf->c_colorfilter, &err_msg)) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Removing color filter name: \"%s\" text: \"%s\".\n%s", - colorf->filter_name, colorf->filter_text, err_msg); - g_free(err_msg); - /* Delete the color filter from the list of color filters. */ - color_filter_valid_list = g_slist_remove(color_filter_valid_list, colorf); - color_filter_delete(colorf); - } -} - -/* apply changes from the edit list */ -void -color_filters_apply(GSList *tmp_cfl, GSList *edit_cfl) -{ - /* "move" old entries to the deleted list - * we must keep them until the dissection no longer needs them */ - color_filter_deleted_list = g_slist_concat(color_filter_deleted_list, color_filter_list); - color_filter_list = NULL; - - /* clone all list entries from tmp/edit to normal list */ - color_filter_valid_list = NULL; - color_filter_valid_list = color_filter_list_clone(tmp_cfl); - color_filter_valid_list = g_slist_concat(color_filter_valid_list, - color_filter_list_clone(edit_cfl) ); - - /* compile all filter */ - g_slist_foreach(color_filter_valid_list, color_filter_validate_cb, NULL); - - /* clone all list entries from tmp/edit to normal list */ - color_filter_list = color_filter_list_clone(color_filter_valid_list); - - /* compile all filter */ - g_slist_foreach(color_filter_list, color_filter_compile_cb, NULL); -} - -gboolean -color_filters_used(void) -{ - return color_filter_list != NULL && filters_enabled; -} - -gboolean -tmp_color_filters_used(void) -{ - return tmp_colors_set; -} - -void -color_filters_enable(gboolean enable) -{ - packet_list_enable_color(enable); -} - - -/* prepare the epan_dissect_t for the filter */ -static void -prime_edt(gpointer data, gpointer user_data) -{ - color_filter_t *colorf = (color_filter_t *)data; - epan_dissect_t *edt = (epan_dissect_t *)user_data; - - 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) -{ - if (color_filters_used()) - g_slist_foreach(color_filter_list, prime_edt, edt); -} - -/* * Return the color_t for later use */ -const color_filter_t * -color_filters_colorize_packet(epan_dissect_t *edt) -{ - GSList *curr; - color_filter_t *colorf; - - /* If we have color filters, "search" for the matching one. */ - if (color_filters_used()) { - curr = color_filter_list; - - while(curr != NULL) { - colorf = (color_filter_t *)curr->data; - if ( (!colorf->disabled) && - (colorf->c_colorfilter != NULL) && - dfilter_apply_edt(colorf->c_colorfilter, edt)) { - return colorf; - } - curr = g_slist_next(curr); - } - } - - return NULL; -} - -/* read filters from the given file */ -/* XXX - Would it make more sense to use GStrings here instead of reallocing - our buffers? */ -static gboolean -read_filters_file(FILE *f, gpointer user_data) -{ -#define INIT_BUF_SIZE 128 - gchar *name = NULL; - gchar *filter_exp = NULL; - guint32 name_len = INIT_BUF_SIZE; - guint32 filter_exp_len = INIT_BUF_SIZE; - guint32 i = 0; - int c; - guint16 fg_r, fg_g, fg_b, bg_r, bg_g, bg_b; - gboolean disabled = FALSE; - gboolean skip_end_of_line = FALSE; - - name = (gchar *)g_malloc(name_len + 1); - filter_exp = (gchar *)g_malloc(filter_exp_len + 1); - - while (1) { - - if (skip_end_of_line) { - do { - c = getc(f); - } while (c != EOF && c != '\n'); - if (c == EOF) - break; - disabled = FALSE; - skip_end_of_line = FALSE; - } - - while ((c = getc(f)) != EOF && g_ascii_isspace(c)) { - if (c == '\n') { - continue; - } - } - - if (c == EOF) - break; - - if (c == '!') { - disabled = TRUE; - continue; - } - - /* skip # comments and invalid lines */ - if (c != '@') { - skip_end_of_line = TRUE; - continue; - } - - /* we get the @ delimiter. - * Format is: - * @name@filter expression@[background r,g,b][foreground r,g,b] - */ - - /* retrieve name */ - i = 0; - while (1) { - c = getc(f); - if (c == EOF || c == '@') - break; - if (i >= name_len) { - /* buffer isn't long enough; double its length.*/ - name_len *= 2; - name = (gchar *)g_realloc(name, name_len + 1); - } - name[i++] = c; - } - name[i] = '\0'; - - if (c == EOF) { - break; - } else if (i == 0) { - skip_end_of_line = TRUE; - continue; - } - - /* retrieve filter expression */ - i = 0; - while (1) { - c = getc(f); - if (c == EOF || c == '@') - break; - if (i >= filter_exp_len) { - /* buffer isn't long enough; double its length.*/ - filter_exp_len *= 2; - filter_exp = (gchar *)g_realloc(filter_exp, filter_exp_len + 1); - } - filter_exp[i++] = c; - } - filter_exp[i] = '\0'; - - if (c == EOF) { - break; - } else if (i == 0) { - skip_end_of_line = TRUE; - continue; - } - - /* retrieve background and foreground colors */ - if (fscanf(f,"[%hu,%hu,%hu][%hu,%hu,%hu]", - &bg_r, &bg_g, &bg_b, &fg_r, &fg_g, &fg_b) == 6) { - - /* we got a complete color filter */ - - color_t bg_color, fg_color; - color_filter_t *colorf; - dfilter_t *temp_dfilter; - gchar *err_msg; - - if (!dfilter_compile(filter_exp, &temp_dfilter, &err_msg)) { - g_warning("Could not compile \"%s\" in colorfilters file.\n%s", - name, err_msg); - g_free(err_msg); - prefs.unknown_colorfilters = TRUE; - - skip_end_of_line = TRUE; - continue; - } - - if (!initialize_color(&fg_color, fg_r, fg_g, fg_b)) { - /* oops */ - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not allocate foreground color " - "specified in input file for %s.", name); - dfilter_free(temp_dfilter); - skip_end_of_line = TRUE; - continue; - } - if (!initialize_color(&bg_color, bg_r, bg_g, bg_b)) { - /* oops */ - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not allocate background color " - "specified in input file for %s.", name); - dfilter_free(temp_dfilter); - skip_end_of_line = TRUE; - continue; - } - - colorf = color_filter_new(name, filter_exp, &bg_color, - &fg_color, disabled); - if(user_data == &color_filter_list) { - GSList **cfl = (GSList **)user_data; - - /* internal call */ - colorf->c_colorfilter = temp_dfilter; - *cfl = g_slist_append(*cfl, colorf); - } else { - /* external call */ - /* just editing, don't need the compiled filter */ - dfilter_free(temp_dfilter); - color_filter_add_cb (colorf, user_data); - } - } /* if sscanf */ - - skip_end_of_line = TRUE; - } - - g_free(name); - g_free(filter_exp); - return TRUE; -} - -/* read filters from the user's filter file */ -static gboolean -read_users_filters(GSList **cfl) -{ - gchar *path; - FILE *f; - gboolean ret; - - /* decide what file to open (from dfilter code) */ - path = get_persconffile_path("colorfilters", TRUE); - if ((f = ws_fopen(path, "r")) == NULL) { - if (errno != ENOENT) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not open filter file\n\"%s\": %s.", path, - g_strerror(errno)); - } - g_free(path); - return FALSE; - } - g_free(path); - path = NULL; - - ret = read_filters_file(f, cfl); - fclose(f); - return ret; -} - -/* read filters from the filter file */ -gboolean -color_filters_read_globals(gpointer user_data) -{ - gchar *path; - FILE *f; - gboolean ret; - - /* decide what file to open (from dfilter code) */ - path = get_datafile_path("colorfilters"); - if ((f = ws_fopen(path, "r")) == NULL) { - if (errno != ENOENT) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not open global filter file\n\"%s\": %s.", path, - g_strerror(errno)); - } - g_free(path); - return FALSE; - } - g_free(path); - path = NULL; - - ret = read_filters_file(f, user_data); - fclose(f); - return ret; -} - -/* read filters from some other filter file (import) */ -gboolean -color_filters_import(const gchar *path, const gpointer user_data) -{ - FILE *f; - gboolean ret; - - if ((f = ws_fopen(path, "r")) == NULL) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not open\n%s\nfor reading: %s.", - path, g_strerror(errno)); - return FALSE; - } - - ret = read_filters_file(f, user_data); - fclose(f); - return ret; -} - -struct write_filter_data -{ - FILE *f; - gboolean only_selected; -}; - -/* save a single filter */ -static void -write_filter(gpointer filter_arg, gpointer data_arg) -{ - struct write_filter_data *data = (struct write_filter_data *)data_arg; - color_filter_t *colorf = (color_filter_t *)filter_arg; - FILE *f = data->f; - - if ( (colorf->selected || !data->only_selected) && - (strstr(colorf->filter_name,CONVERSATION_COLOR_PREFIX)==NULL) ) { - fprintf(f,"%s@%s@%s@[%u,%u,%u][%u,%u,%u]\n", - colorf->disabled ? "!" : "", - colorf->filter_name, - colorf->filter_text, - colorf->bg_color.red, - colorf->bg_color.green, - colorf->bg_color.blue, - colorf->fg_color.red, - colorf->fg_color.green, - colorf->fg_color.blue); - } -} - -/* save filters in a filter file */ -static gboolean -write_filters_file(const GSList *cfl, FILE *f, gboolean only_selected) -{ - struct write_filter_data data; - - data.f = f; - data.only_selected = only_selected; - - fprintf(f,"# DO NOT EDIT THIS FILE! It was created by Wireshark\n"); - g_slist_foreach((GSList *) cfl, write_filter, &data); - return TRUE; -} - -/* save filters in users filter file */ -gboolean -color_filters_write(GSList *cfl) -{ - gchar *pf_dir_path; - gchar *path; - FILE *f; - - /* Create the directory that holds personal configuration files, - if necessary. */ - if (create_persconffile_dir(&pf_dir_path) == -1) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Can't create directory\n\"%s\"\nfor color files: %s.", - pf_dir_path, g_strerror(errno)); - g_free(pf_dir_path); - return FALSE; - } - - path = get_persconffile_path("colorfilters", TRUE); - if ((f = ws_fopen(path, "w+")) == NULL) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not open\n%s\nfor writing: %s.", - path, g_strerror(errno)); - g_free(path); - return FALSE; - } - g_free(path); - write_filters_file(cfl, f, FALSE); - fclose(f); - return TRUE; -} - -/* save filters in some other filter file (export) */ -gboolean -color_filters_export(const gchar *path, const GSList *cfl, gboolean only_marked) -{ - FILE *f; - - if ((f = ws_fopen(path, "w+")) == NULL) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not open\n%s\nfor writing: %s.", - path, g_strerror(errno)); - return FALSE; - } - write_filters_file(cfl, f, only_marked); - fclose(f); - return TRUE; -} - -/* - * Editor modelines - http://www.wireshark.org/tools/modelines.html - * - * Local variables: - * c-basic-offset: 4 - * tab-width: 8 - * indent-tabs-mode: nil - * End: - * - * vi: set shiftwidth=4 tabstop=8 expandtab: - * :indentSize=4:tabSize=8:noTabs=true: - */ diff --git a/color_filters.h b/color_filters.h deleted file mode 100644 index 04aafc87ec..0000000000 --- a/color_filters.h +++ /dev/null @@ -1,215 +0,0 @@ -/* color_filters.h - * Definitions for color filters - * - * Wireshark - Network traffic analyzer - * By Gerald Combs - * Copyright 1998 Gerald Combs - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef __COLOR_FILTERS_H__ -#define __COLOR_FILTERS_H__ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -struct epan_dissect; - -#define CONVERSATION_COLOR_PREFIX "___conversation_color_filter___" -/** @file - * Color filters. - */ - -/* Data for a color filter. */ -typedef struct _color_filter { - gchar *filter_name; /* name of the filter */ - gchar *filter_text; /* text of the filter expression */ - color_t bg_color; /* background color for packets that match */ - color_t fg_color; /* foreground color for packets that match */ - gboolean disabled; /* set if the filter is disabled */ - gboolean selected; /* set if the filter is selected in the color dialog box. GTK+ only. */ - - /* only used inside of color_filters.c */ - struct epan_dfilter *c_colorfilter; /* compiled filter expression */ - - /* only used outside of color_filters.c (beside init) */ - void *color_edit_dlg_info; /* if filter is being edited, ptr to req'd info. GTK+ only. */ -} color_filter_t; - - -/** Init the color filters (incl. initial read from file). */ -void color_filters_init(void); - -/** Reload the color filters */ -void color_filters_reload(void); - -/** Cleanup remaining color filter zombies */ -void color_filters_cleanup(void); - -/** Color filters currently used? - * - * @return TRUE, if filters are used - */ -gboolean color_filters_used(void); - -/** Are there any temporary coloring filters used? - * - * @return TRUE, if temporary coloring filters are used - */ -gboolean tmp_color_filters_used(void); - -/** En-/disable color filters - * - * @param enable TRUE to enable (default) - */ -void -color_filters_enable(gboolean enable); - -/** Set the filter string of a temporary color filter - * - * @param filt_nr a number 1-10 pointing to a temporary color - * @param filter the new filter-string - * @param disabled whether the filter-rule should be disabled - */ -void -color_filters_set_tmp(guint8 filt_nr, const gchar *filter, gboolean disabled); - -/** Get a temporary color filter. - * - * @param filter_num A number from 1 to 10 specifying the color to fetch. - * @return The corresponding color or NULL. - */ -const color_filter_t * -color_filters_tmp_color(guint8 filter_num); - -/** Reset the temporary color filters - * - */ -void -color_filters_reset_tmp(void); - -/* Prime the epan_dissect_t with all the compiler - * color filters of the current filter list. - * - * @param the epan dissector details - */ -void color_filters_prime_edt(struct epan_dissect *edt); - -/** Colorize a specific packet. - * - * @param edt the dissected packet - * @return the matching color filter or NULL - */ -const color_filter_t * -color_filters_colorize_packet(struct epan_dissect *edt); - -/** Clone the currently active filter list. - * - * @param user_data will be returned by each call to to color_filter_add_cb() - */ -void color_filters_clone(gpointer user_data); - -/** Load filters (import) from some other filter file. - * - * @param path the path to the import file - * @param user_data will be returned by each call to to color_filter_add_cb() - * @return TRUE, if read succeeded - */ -gboolean color_filters_import(const gchar *path, const gpointer user_data); - -/** Read filters from the global filter file (not the users file). - * - * @param user_data will be returned by each call to to color_filter_add_cb() - * @return TRUE, if read succeeded - */ -gboolean color_filters_read_globals(gpointer user_data); - -/** A color filter was added (while importing). - * (color_filters.c calls this for every filter coming in) - * - * @param colorf the new color filter - * @param user_data from caller - */ -void color_filter_add_cb (color_filter_t *colorf, gpointer user_data); - - - -/** Apply a changed filter list. - * - * @param tmp_cfl the temporary color filter list to apply - * @param edit_cfl the edited permanent color filter list to apply - */ -void color_filters_apply(GSList *tmp_cfl, GSList *edit_cfl); - -/** Save filters in users filter file. - * - * @param cfl the filter list to write - * @return TRUE if write succeeded - */ -gboolean color_filters_write(GSList *cfl); - -/** Save filters (export) to some other filter file. - * - * @param path the path to the filter file - * @param cfl the filter list to write - * @param only_selected TRUE if only the selected filters should be saved - * @return TRUE, if write succeeded - */ -gboolean color_filters_export(const gchar *path, const GSList *cfl, gboolean only_selected); - -/** Create a new color filter (g_malloc'ed). - * - * @param name the name of the filter - * @param filter_string the filter string - * @param bg_color background color - * @param fg_color foreground color - * @param disabled gboolean - * @return the new color filter - */ -color_filter_t *color_filter_new( - const gchar *name, const gchar *filter_string, - color_t *bg_color, color_t *fg_color, gboolean disabled); - -/** Delete a single color filter (g_free'ed). - * - * @param colorf the color filter to be removed - */ -void color_filter_delete(color_filter_t *colorf); - -/** Delete a filter list including all entries. - * - * @param cfl the filter list to delete - */ -void color_filter_list_delete(GSList **cfl); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif - -/* - * Editor modelines - http://www.wireshark.org/tools/modelines.html - * - * Local variables: - * c-basic-offset: 4 - * tab-width: 8 - * indent-tabs-mode: nil - * End: - * - * vi: set shiftwidth=4 tabstop=8 expandtab: - * :indentSize=4:tabSize=8:noTabs=true: - */ diff --git a/debian/libwireshark-dev.install b/debian/libwireshark-dev.install index d42d843f91..14441b9a6a 100644 --- a/debian/libwireshark-dev.install +++ b/debian/libwireshark-dev.install @@ -1,6 +1,5 @@ usr/lib/*/libwireshark.so usr/lib/*/pkgconfig/wireshark.pc -color.h usr/include/wireshark obj-*/config.h usr/include/wireshark register.h usr/include/wireshark epan/stat_groups.h usr/include/wireshark diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt index 43ea761d66..fa0676286e 100644 --- a/epan/CMakeLists.txt +++ b/epan/CMakeLists.txt @@ -1592,6 +1592,7 @@ set(LIBWIRESHARK_FILES capture_dissectors.c charsets.c circuit.c + color_filters.c column.c column-utils.c conversation.c @@ -1764,7 +1765,7 @@ endif() ABICHECK(libwireshark) -set(TOP_LEVEL_HEADERS ${CMAKE_BINARY_DIR}/config.h ${CMAKE_SOURCE_DIR}/color.h ${CMAKE_SOURCE_DIR}/register.h) +set(TOP_LEVEL_HEADERS ${CMAKE_BINARY_DIR}/config.h ${CMAKE_SOURCE_DIR}/register.h) file(GLOB CRYPT_HEADERS crypt/*.h) file(GLOB COMPRESS_HEADERS compress/*.h) file(GLOB DFILTER_HEADERS dfilter/*.h ../tools/lemon/cppmagic.h) diff --git a/epan/Makefile.am b/epan/Makefile.am index 2383af0433..0749d60a99 100644 --- a/epan/Makefile.am +++ b/epan/Makefile.am @@ -300,7 +300,7 @@ endif dumpabi-libwireshark: all abi-descriptor.xml rm -rf abi-check-headers abi_dumps .libs/*.abi.tar.gz mkdir abi-check-headers - cp ../color.h ../config.h ../register.h abi-check-headers/ + cp ../config.h ../register.h abi-check-headers/ mkdir abi-check-headers/epan cp *.h abi-check-headers/epan mkdir abi-check-headers/crypt diff --git a/epan/Makefile.common b/epan/Makefile.common index bc57f50b42..d11786e993 100644 --- a/epan/Makefile.common +++ b/epan/Makefile.common @@ -32,6 +32,7 @@ LIBWIRESHARK_SRC = \ capture_dissectors.c \ charsets.c \ circuit.c \ + color_filters.c \ column.c \ column-utils.c \ conversation.c \ @@ -161,6 +162,7 @@ LIBWIRESHARK_INCLUDES = \ charsets.h \ chdlctypes.h \ circuit.h \ + color_filters.h \ column.h \ column-info.h \ column-utils.h \ diff --git a/epan/color_filters.c b/epan/color_filters.c new file mode 100644 index 0000000000..cc95a08a31 --- /dev/null +++ b/epan/color_filters.c @@ -0,0 +1,843 @@ +/* color_filters.c + * Routines for color filters + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +/* + * Updated 1 Dec 10 jjm + */ + +#include + +#include + +#include +#include +#include + +#include +#include + +#include +#include "color_filters.h" +#include "file.h" +#include +#include + + +#define RED_COMPONENT(x) (guint16) (((((x) >> 16) & 0xff) * 65535 / 255)) +#define GREEN_COMPONENT(x) (guint16) (((((x) >> 8) & 0xff) * 65535 / 255)) +#define BLUE_COMPONENT(x) (guint16) ( (((x) & 0xff) * 65535 / 255)) + +static gboolean read_users_filters(GSList **cfl, gchar** err_msg, initialize_color_func init_func, color_filter_add_cb_func add_cb); + +/* the currently active filters */ +static GSList *color_filter_list = NULL; + +/* keep "old" deleted filters in this list until + * the dissection no longer needs them (e.g. file is closed) */ +static GSList *color_filter_deleted_list = NULL; +static GSList *color_filter_valid_list = NULL; + +/* Color Filters can en-/disabled. */ +static gboolean filters_enabled = TRUE; + +/* Remember if there are temporary coloring filters set to + * add sensitivity to the "Reset Coloring 1-10" menu item + */ +static gboolean tmp_colors_set = FALSE; + +/* Create a new filter */ +color_filter_t * +color_filter_new(const gchar *name, /* The name of the filter to create */ + const gchar *filter_string, /* The string representing the filter */ + color_t *bg_color, /* The background color */ + color_t *fg_color, /* The foreground color */ + gboolean disabled) /* Is the filter disabled? */ +{ + color_filter_t *colorf; + + colorf = (color_filter_t *)g_malloc0(sizeof (color_filter_t)); + colorf->filter_name = g_strdup(name); + colorf->filter_text = g_strdup(filter_string); + colorf->bg_color = *bg_color; + colorf->fg_color = *fg_color; + colorf->disabled = disabled; + return colorf; +} + +/* Add ten empty (temporary) colorfilters for easy coloring */ +static void +color_filters_add_tmp(GSList **cfl, initialize_color_func init_func) +{ + gchar *name = NULL; + guint32 i; + gchar** bg_colors; + gchar** fg_colors; + gulong cval; + color_t bg_color, fg_color; + color_filter_t *colorf; + + g_assert(strlen(prefs.gui_colorized_fg)==69); + g_assert(strlen(prefs.gui_colorized_bg)==69); + fg_colors = g_strsplit(prefs.gui_colorized_fg, ",", -1); + bg_colors = g_strsplit(prefs.gui_colorized_bg, ",", -1); + + for ( i=1 ; i<=10 ; i++ ) { + name = g_strdup_printf("%s%02d",CONVERSATION_COLOR_PREFIX,i); + + /* retrieve background and foreground colors */ + cval = strtoul(fg_colors[i-1], NULL, 16); + init_func(&fg_color, RED_COMPONENT(cval), + GREEN_COMPONENT(cval), + BLUE_COMPONENT(cval) ); + cval = strtoul(bg_colors[i-1], NULL, 16); + init_func(&bg_color, RED_COMPONENT(cval), + GREEN_COMPONENT(cval), + BLUE_COMPONENT(cval) ); + colorf = color_filter_new(name, NULL, &bg_color, &fg_color, TRUE); + colorf->filter_text = g_strdup("frame"); + *cfl = g_slist_append(*cfl, colorf); + + g_free(name); + } + + g_strfreev(fg_colors); + g_strfreev(bg_colors); + + return; +} + +static gint +color_filters_find_by_name_cb(gconstpointer arg1, gconstpointer arg2) +{ + const color_filter_t *colorf = (const color_filter_t *)arg1; + const gchar *name = (const gchar *)arg2; + + return (strstr(colorf->filter_name, name)==NULL) ? -1 : 0 ; +} + + +/* Set the filter off a temporary colorfilters and enable it */ +gboolean +color_filters_set_tmp(guint8 filt_nr, const gchar *filter, gboolean disabled, gchar **err_msg) +{ + gchar *name = NULL; + const gchar *tmpfilter = NULL; + GSList *cfl; + color_filter_t *colorf; + dfilter_t *compiled_filter; + guint8 i; + gchar *local_err_msg = NULL; + /* Go through the temporary filters and look for the same filter string. + * If found, clear it so that a filter can be "moved" up and down the list + */ + for ( i=1 ; i<=10 ; i++ ) { + /* If we need to reset the temporary filter (filter==NULL), don't look + * for other rules with the same filter string + */ + if( i!=filt_nr && filter==NULL ) + continue; + + name = g_strdup_printf("%s%02d",CONVERSATION_COLOR_PREFIX,i); + cfl = g_slist_find_custom(color_filter_list, name, color_filters_find_by_name_cb); + colorf = (color_filter_t *)cfl->data; + + /* Only change the filter rule if this is the rule to change or if + * a matching filter string has been found + */ + if(colorf && ( (i==filt_nr) || (strstr(filter,colorf->filter_text)!=NULL) ) ) { + /* set filter string to "frame" if we are resetting the rules + * or if we found a matching filter string which need to be cleared + */ + tmpfilter = ( (filter==NULL) || (i!=filt_nr) ) ? "frame" : filter; + if (!dfilter_compile(tmpfilter, &compiled_filter, &local_err_msg)) { + *err_msg = g_strdup_printf( "Could not compile color filter name: \"%s\" text: \"%s\".\n%s", name, filter, local_err_msg); + g_free(local_err_msg); + return FALSE; + } else { + if (colorf->filter_text != NULL) + g_free(colorf->filter_text); + if (colorf->c_colorfilter != NULL) + dfilter_free(colorf->c_colorfilter); + colorf->filter_text = g_strdup(tmpfilter); + colorf->c_colorfilter = compiled_filter; + colorf->disabled = ((i!=filt_nr) ? TRUE : disabled); + /* Remember that there are now temporary coloring filters set */ + if( filter ) + tmp_colors_set = TRUE; + } + } + g_free(name); + } + return TRUE; +} + +const color_filter_t * +color_filters_tmp_color(guint8 filter_num) { + gchar *name; + color_filter_t *colorf = NULL; + GSList *cfl; + + name = g_strdup_printf("%s%02d", CONVERSATION_COLOR_PREFIX, filter_num); + cfl = g_slist_find_custom(color_filter_list, name, color_filters_find_by_name_cb); + if (cfl) { + colorf = (color_filter_t *)cfl->data; + } + g_free(name); + + return colorf; +} + +/* Reset the temporary colorfilters */ +gboolean +color_filters_reset_tmp(gchar **err_msg) +{ + guint8 i; + + for ( i=1 ; i<=10 ; i++ ) { + if (!color_filters_set_tmp(i, NULL, TRUE, err_msg)) + return FALSE; + } + /* Remember that there are now *no* temporary coloring filters set */ + tmp_colors_set = FALSE; + return TRUE; +} + +/* delete the specified filter */ +void +color_filter_delete(color_filter_t *colorf) +{ + if (colorf->filter_name != NULL) + g_free(colorf->filter_name); + if (colorf->filter_text != NULL) + g_free(colorf->filter_text); + if (colorf->c_colorfilter != NULL) + dfilter_free(colorf->c_colorfilter); + g_free(colorf); +} + +/* delete the specified filter (called from g_slist_foreach) */ +static void +color_filter_delete_cb(gpointer filter_arg, gpointer unused _U_) +{ + color_filter_t *colorf = (color_filter_t *)filter_arg; + + color_filter_delete(colorf); +} + +/* delete the specified list */ +void +color_filter_list_delete(GSList **cfl) +{ + g_slist_foreach(*cfl, color_filter_delete_cb, NULL); + g_slist_free(*cfl); + *cfl = NULL; +} + +/* clone a single list entries from normal to edit list */ +static color_filter_t * +color_filter_clone(color_filter_t *colorf) +{ + color_filter_t *new_colorf; + + new_colorf = (color_filter_t *)g_malloc(sizeof (color_filter_t)); + new_colorf->filter_name = g_strdup(colorf->filter_name); + new_colorf->filter_text = g_strdup(colorf->filter_text); + new_colorf->bg_color = colorf->bg_color; + new_colorf->fg_color = colorf->fg_color; + new_colorf->disabled = colorf->disabled; + new_colorf->c_colorfilter = NULL; + new_colorf->color_edit_dlg_info = NULL; + new_colorf->selected = FALSE; + + return new_colorf; +} + +static void +color_filter_list_clone_cb(gpointer filter_arg, gpointer cfl_arg) +{ + GSList **cfl = (GSList **)cfl_arg; + color_filter_t *new_colorf; + + new_colorf = color_filter_clone((color_filter_t *)filter_arg); + *cfl = g_slist_append(*cfl, new_colorf); +} + +/* clone the specified list */ +static GSList * +color_filter_list_clone(GSList *cfl) +{ + GSList *new_list = NULL; + + g_slist_foreach(cfl, color_filter_list_clone_cb, &new_list); + + return new_list; +} + +/* Initialize the filter structures (reading from file) for general running, including app startup */ +gboolean +color_filters_init(gchar** err_msg, initialize_color_func init_func, color_filter_add_cb_func add_cb) +{ + /* delete all currently existing filters */ + color_filter_list_delete(&color_filter_list); + + /* start the list with the temporary colorizing rules */ + color_filters_add_tmp(&color_filter_list, init_func); + + /* try to read the users filters */ + if (!read_users_filters(&color_filter_list, err_msg, init_func, add_cb)) { + gchar* local_err_msg = NULL; + + /* if that failed, try to read the global filters */ + if (!color_filters_read_globals(&color_filter_list, &local_err_msg, init_func, add_cb)) { + /* Show the first error */ + g_free(local_err_msg); + } + + return (*err_msg == NULL); + } + + return TRUE; +} + +gboolean +color_filters_reload(gchar** err_msg, initialize_color_func init_func, color_filter_add_cb_func add_cb) +{ + /* "move" old entries to the deleted list + * we must keep them until the dissection no longer needs them */ + color_filter_deleted_list = g_slist_concat(color_filter_deleted_list, color_filter_list); + color_filter_list = NULL; + + /* start the list with the temporary colorizing rules */ + color_filters_add_tmp(&color_filter_list, init_func); + + /* try to read the users filters */ + if (!read_users_filters(&color_filter_list, err_msg, init_func, add_cb)) { + gchar* local_err_msg = NULL; + + /* if that failed, try to read the global filters */ + if (!color_filters_read_globals(&color_filter_list, &local_err_msg, init_func, add_cb)) { + /* Show the first error */ + g_free(local_err_msg); + } + + return (*err_msg == NULL); + } + return TRUE; +} + +void +color_filters_cleanup(void) +{ + /* delete the previously deleted filters */ + color_filter_list_delete(&color_filter_deleted_list); +} + +typedef struct _color_clone +{ + gpointer user_data; + color_filter_add_cb_func add_cb; +} color_clone_t; + +static void +color_filters_clone_cb(gpointer filter_arg, gpointer user_data) +{ + color_clone_t* clone_data = (color_clone_t*)user_data; + color_filter_t * new_colorf = color_filter_clone((color_filter_t *)filter_arg); + + clone_data->add_cb (new_colorf, clone_data->user_data); +} + +void +color_filters_clone(gpointer user_data, color_filter_add_cb_func add_cb) +{ + color_clone_t clone_data; + + clone_data.user_data = user_data; + clone_data.add_cb = add_cb; + g_slist_foreach(color_filter_list, color_filters_clone_cb, &clone_data); +} + + +static void +color_filter_compile_cb(gpointer filter_arg, gpointer err) +{ + color_filter_t *colorf = (color_filter_t *)filter_arg; + gchar **err_msg = (gchar**)err; + gchar *local_err_msg = NULL; + + g_assert(colorf->c_colorfilter == NULL); + if (!dfilter_compile(colorf->filter_text, &colorf->c_colorfilter, &local_err_msg)) { + *err_msg = g_strdup_printf("Could not compile color filter name: \"%s\" text: \"%s\".\n%s", + colorf->filter_name, colorf->filter_text, local_err_msg); + g_free(local_err_msg); + /* this filter was compilable before, so this should never happen */ + /* except if the OK button of the parent window has been clicked */ + /* so don't use g_assert_not_reached() but check the filters again */ + } +} + +static void +color_filter_validate_cb(gpointer filter_arg, gpointer err) +{ + color_filter_t *colorf = (color_filter_t *)filter_arg; + gchar **err_msg = (gchar**)err; + gchar *local_err_msg; + + g_assert(colorf->c_colorfilter == NULL); + if (!dfilter_compile(colorf->filter_text, &colorf->c_colorfilter, &local_err_msg)) { + *err_msg = g_strdup_printf("Removing color filter name: \"%s\" text: \"%s\".\n%s", + colorf->filter_name, colorf->filter_text, local_err_msg); + g_free(local_err_msg); + /* Delete the color filter from the list of color filters. */ + color_filter_valid_list = g_slist_remove(color_filter_valid_list, colorf); + color_filter_delete(colorf); + } +} + +/* apply changes from the edit list */ +gboolean +color_filters_apply(GSList *tmp_cfl, GSList *edit_cfl, gchar** err_msg) +{ + gboolean ret = TRUE; + + *err_msg = NULL; + + /* "move" old entries to the deleted list + * we must keep them until the dissection no longer needs them */ + color_filter_deleted_list = g_slist_concat(color_filter_deleted_list, color_filter_list); + color_filter_list = NULL; + + /* clone all list entries from tmp/edit to normal list */ + color_filter_valid_list = NULL; + color_filter_valid_list = color_filter_list_clone(tmp_cfl); + color_filter_valid_list = g_slist_concat(color_filter_valid_list, + color_filter_list_clone(edit_cfl) ); + + /* compile all filter */ + g_slist_foreach(color_filter_valid_list, color_filter_validate_cb, err_msg); + if (*err_msg != NULL) { + ret = FALSE; + } + + /* clone all list entries from tmp/edit to normal list */ + color_filter_list = color_filter_list_clone(color_filter_valid_list); + + /* compile all filter */ + g_slist_foreach(color_filter_list, color_filter_compile_cb, err_msg); + if (*err_msg != NULL) { + ret = FALSE; + } + + return ret; +} + +gboolean +color_filters_used(void) +{ + return color_filter_list != NULL && filters_enabled; +} + +gboolean +tmp_color_filters_used(void) +{ + return tmp_colors_set; +} + +/* prepare the epan_dissect_t for the filter */ +static void +prime_edt(gpointer data, gpointer user_data) +{ + color_filter_t *colorf = (color_filter_t *)data; + epan_dissect_t *edt = (epan_dissect_t *)user_data; + + 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) +{ + if (color_filters_used()) + g_slist_foreach(color_filter_list, prime_edt, edt); +} + +/* * Return the color_t for later use */ +const color_filter_t * +color_filters_colorize_packet(epan_dissect_t *edt) +{ + GSList *curr; + color_filter_t *colorf; + + /* If we have color filters, "search" for the matching one. */ + if (color_filters_used()) { + curr = color_filter_list; + + while(curr != NULL) { + colorf = (color_filter_t *)curr->data; + if ( (!colorf->disabled) && + (colorf->c_colorfilter != NULL) && + dfilter_apply_edt(colorf->c_colorfilter, edt)) { + return colorf; + } + curr = g_slist_next(curr); + } + } + + return NULL; +} + +/* read filters from the given file */ +/* XXX - Would it make more sense to use GStrings here instead of reallocing + our buffers? */ +static gboolean +read_filters_file(FILE *f, gpointer user_data, gchar** err_msg, initialize_color_func init_func, color_filter_add_cb_func add_cb) +{ +#define INIT_BUF_SIZE 128 + gchar *name = NULL; + gchar *filter_exp = NULL; + guint32 name_len = INIT_BUF_SIZE; + guint32 filter_exp_len = INIT_BUF_SIZE; + guint32 i = 0; + int c; + guint16 fg_r, fg_g, fg_b, bg_r, bg_g, bg_b; + gboolean disabled = FALSE; + gboolean skip_end_of_line = FALSE; + gboolean ret = TRUE; + + name = (gchar *)g_malloc(name_len + 1); + filter_exp = (gchar *)g_malloc(filter_exp_len + 1); + + while (1) { + + if (skip_end_of_line) { + do { + c = getc(f); + } while (c != EOF && c != '\n'); + if (c == EOF) + break; + disabled = FALSE; + skip_end_of_line = FALSE; + } + + while ((c = getc(f)) != EOF && g_ascii_isspace(c)) { + if (c == '\n') { + continue; + } + } + + if (c == EOF) + break; + + if (c == '!') { + disabled = TRUE; + continue; + } + + /* skip # comments and invalid lines */ + if (c != '@') { + skip_end_of_line = TRUE; + continue; + } + + /* we get the @ delimiter. + * Format is: + * @name@filter expression@[background r,g,b][foreground r,g,b] + */ + + /* retrieve name */ + i = 0; + while (1) { + c = getc(f); + if (c == EOF || c == '@') + break; + if (i >= name_len) { + /* buffer isn't long enough; double its length.*/ + name_len *= 2; + name = (gchar *)g_realloc(name, name_len + 1); + } + name[i++] = c; + } + name[i] = '\0'; + + if (c == EOF) { + break; + } else if (i == 0) { + skip_end_of_line = TRUE; + continue; + } + + /* retrieve filter expression */ + i = 0; + while (1) { + c = getc(f); + if (c == EOF || c == '@') + break; + if (i >= filter_exp_len) { + /* buffer isn't long enough; double its length.*/ + filter_exp_len *= 2; + filter_exp = (gchar *)g_realloc(filter_exp, filter_exp_len + 1); + } + filter_exp[i++] = c; + } + filter_exp[i] = '\0'; + + if (c == EOF) { + break; + } else if (i == 0) { + skip_end_of_line = TRUE; + continue; + } + + /* retrieve background and foreground colors */ + if (fscanf(f,"[%hu,%hu,%hu][%hu,%hu,%hu]", + &bg_r, &bg_g, &bg_b, &fg_r, &fg_g, &fg_b) == 6) { + + /* we got a complete color filter */ + + color_t bg_color, fg_color; + color_filter_t *colorf; + dfilter_t *temp_dfilter; + gchar *local_err_msg = NULL; + + if (!dfilter_compile(filter_exp, &temp_dfilter, &local_err_msg)) { + g_warning("Could not compile \"%s\" in colorfilters file.\n%s", + name, local_err_msg); + g_free(local_err_msg); + prefs.unknown_colorfilters = TRUE; + + skip_end_of_line = TRUE; + continue; + } + + if (!init_func(&fg_color, fg_r, fg_g, fg_b)) { + /* oops */ + *err_msg = g_strdup_printf("Could not allocate foreground color specified in input file for %s.", name); + dfilter_free(temp_dfilter); + skip_end_of_line = TRUE; + ret = FALSE; + continue; + } + if (!init_func(&bg_color, bg_r, bg_g, bg_b)) { + /* oops */ + *err_msg = g_strdup_printf("Could not allocate background color specified in input file for %s.", name); + dfilter_free(temp_dfilter); + skip_end_of_line = TRUE; + ret = FALSE; + continue; + } + + colorf = color_filter_new(name, filter_exp, &bg_color, + &fg_color, disabled); + if(user_data == &color_filter_list) { + GSList **cfl = (GSList **)user_data; + + /* internal call */ + colorf->c_colorfilter = temp_dfilter; + *cfl = g_slist_append(*cfl, colorf); + } else { + /* external call */ + /* just editing, don't need the compiled filter */ + dfilter_free(temp_dfilter); + add_cb(colorf, user_data); + } + } /* if sscanf */ + + skip_end_of_line = TRUE; + } + + g_free(name); + g_free(filter_exp); + return ret; +} + +/* read filters from the user's filter file */ +static gboolean +read_users_filters(GSList **cfl, gchar** err_msg, initialize_color_func init_func, color_filter_add_cb_func add_cb) +{ + gchar *path; + FILE *f; + gboolean ret; + + /* decide what file to open (from dfilter code) */ + path = get_persconffile_path("colorfilters", TRUE); + if ((f = ws_fopen(path, "r")) == NULL) { + if (errno != ENOENT) { + *err_msg = g_strdup_printf("Could not open filter file\n\"%s\": %s.", path, + g_strerror(errno)); + } + g_free(path); + return FALSE; + } + g_free(path); + path = NULL; + + ret = read_filters_file(f, cfl, err_msg, init_func, add_cb); + fclose(f); + return ret; +} + +/* read filters from the filter file */ +gboolean +color_filters_read_globals(gpointer user_data, gchar** err_msg, initialize_color_func init_func, color_filter_add_cb_func add_cb) +{ + gchar *path; + FILE *f; + gboolean ret; + + /* decide what file to open (from dfilter code) */ + path = get_datafile_path("colorfilters"); + if ((f = ws_fopen(path, "r")) == NULL) { + if (errno != ENOENT) { + *err_msg = g_strdup_printf("Could not open global filter file\n\"%s\": %s.", path, + g_strerror(errno)); + } + g_free(path); + return FALSE; + } + g_free(path); + path = NULL; + + ret = read_filters_file(f, user_data, err_msg, init_func, add_cb); + fclose(f); + return ret; +} + +/* read filters from some other filter file (import) */ +gboolean +color_filters_import(const gchar *path, const gpointer user_data, gchar** err_msg, initialize_color_func init_func, color_filter_add_cb_func add_cb) +{ + FILE *f; + gboolean ret; + + if ((f = ws_fopen(path, "r")) == NULL) { + *err_msg = g_strdup_printf("Could not open\n%s\nfor reading: %s.", + path, g_strerror(errno)); + return FALSE; + } + + ret = read_filters_file(f, user_data, err_msg, init_func, add_cb); + fclose(f); + return ret; +} + +struct write_filter_data +{ + FILE *f; + gboolean only_selected; +}; + +/* save a single filter */ +static void +write_filter(gpointer filter_arg, gpointer data_arg) +{ + struct write_filter_data *data = (struct write_filter_data *)data_arg; + color_filter_t *colorf = (color_filter_t *)filter_arg; + FILE *f = data->f; + + if ( (colorf->selected || !data->only_selected) && + (strstr(colorf->filter_name,CONVERSATION_COLOR_PREFIX)==NULL) ) { + fprintf(f,"%s@%s@%s@[%u,%u,%u][%u,%u,%u]\n", + colorf->disabled ? "!" : "", + colorf->filter_name, + colorf->filter_text, + colorf->bg_color.red, + colorf->bg_color.green, + colorf->bg_color.blue, + colorf->fg_color.red, + colorf->fg_color.green, + colorf->fg_color.blue); + } +} + +/* save filters in a filter file */ +static gboolean +write_filters_file(const GSList *cfl, FILE *f, gboolean only_selected) +{ + struct write_filter_data data; + + data.f = f; + data.only_selected = only_selected; + + fprintf(f,"# DO NOT EDIT THIS FILE! It was created by Wireshark\n"); + g_slist_foreach((GSList *) cfl, write_filter, &data); + return TRUE; +} + +/* save filters in users filter file */ +gboolean +color_filters_write(GSList *cfl, gchar** err_msg) +{ + gchar *pf_dir_path; + gchar *path; + FILE *f; + + /* Create the directory that holds personal configuration files, + if necessary. */ + if (create_persconffile_dir(&pf_dir_path) == -1) { + *err_msg = g_strdup_printf("Can't create directory\n\"%s\"\nfor color files: %s.", + pf_dir_path, g_strerror(errno)); + g_free(pf_dir_path); + return FALSE; + } + + path = get_persconffile_path("colorfilters", TRUE); + if ((f = ws_fopen(path, "w+")) == NULL) { + *err_msg = g_strdup_printf("Could not open\n%s\nfor writing: %s.", + path, g_strerror(errno)); + g_free(path); + return FALSE; + } + g_free(path); + write_filters_file(cfl, f, FALSE); + fclose(f); + return TRUE; +} + +/* save filters in some other filter file (export) */ +gboolean +color_filters_export(const gchar *path, const GSList *cfl, gboolean only_marked, gchar** err_msg) +{ + FILE *f; + + if ((f = ws_fopen(path, "w+")) == NULL) { + *err_msg = g_strdup_printf("Could not open\n%s\nfor writing: %s.", + path, g_strerror(errno)); + return FALSE; + } + write_filters_file(cfl, f, only_marked); + fclose(f); + return TRUE; +} + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/epan/color_filters.h b/epan/color_filters.h new file mode 100644 index 0000000000..2fe8b018cb --- /dev/null +++ b/epan/color_filters.h @@ -0,0 +1,235 @@ +/* color_filters.h + * Definitions for color filters + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#ifndef __COLOR_FILTERS_H__ +#define __COLOR_FILTERS_H__ + +#include "ws_symbol_export.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +struct epan_dissect; + +/* + * Data structure holding RGB value for a color. + * + * XXX - yes, I know, there's a "pixel" value in there as well; for + * now, it's intended to look just like a GdkColor but not to require + * that any GTK+ header files be included in order to use it. + * The way we handle colors needs to be cleaned up somewhat, in order + * to keep toolkit-specific stuff separate from toolkit-independent stuff. + */ +typedef struct { + guint32 pixel; + guint16 red; + guint16 green; + guint16 blue; +} color_t; + +/** Initialize a color with R, G, and B values, including any toolkit-dependent + ** work that needs to be done. + * + * @param color the color_t to be filled + * @param red the red value for the color + * @param green the green value for the color + * @param blue the blue value for the color + * @return TRUE if it succeeds, FALSE if it fails + */ +typedef gboolean (*initialize_color_func)(color_t *color, guint16 red, guint16 green, guint16 blue); + +#define CONVERSATION_COLOR_PREFIX "___conversation_color_filter___" +/** @file + * Color filters. + */ + +/* Data for a color filter. */ +typedef struct _color_filter { + gchar *filter_name; /* name of the filter */ + gchar *filter_text; /* text of the filter expression */ + color_t bg_color; /* background color for packets that match */ + color_t fg_color; /* foreground color for packets that match */ + gboolean disabled; /* set if the filter is disabled */ + gboolean selected; /* set if the filter is selected in the color dialog box. GTK+ only. */ + + /* only used inside of color_filters.c */ + struct epan_dfilter *c_colorfilter; /* compiled filter expression */ + + /* only used outside of color_filters.c (beside init) */ + void *color_edit_dlg_info; /* if filter is being edited, ptr to req'd info. GTK+ only. */ +} color_filter_t; + +/** A color filter was added (while importing). + * (color_filters.c calls this for every filter coming in) + * + * @param colorf the new color filter + * @param user_data from caller + */ +typedef void (*color_filter_add_cb_func)(color_filter_t *colorf, gpointer user_data); + +/** Init the color filters (incl. initial read from file). */ +WS_DLL_PUBLIC gboolean color_filters_init(gchar** err_msg, initialize_color_func init_func, color_filter_add_cb_func add_cb); + +/** Reload the color filters */ +WS_DLL_PUBLIC gboolean color_filters_reload(gchar** err_msg, initialize_color_func init_func, color_filter_add_cb_func add_cb); + +/** Cleanup remaining color filter zombies */ +WS_DLL_PUBLIC void color_filters_cleanup(void); + +/** Color filters currently used? + * + * @return TRUE, if filters are used + */ +WS_DLL_PUBLIC gboolean color_filters_used(void); + +/** Are there any temporary coloring filters used? + * + * @return TRUE, if temporary coloring filters are used + */ +WS_DLL_PUBLIC gboolean tmp_color_filters_used(void); + +/** Set the filter string of a temporary color filter + * + * @param filt_nr a number 1-10 pointing to a temporary color + * @param filter the new filter-string + * @param disabled whether the filter-rule should be disabled + */ +WS_DLL_PUBLIC gboolean +color_filters_set_tmp(guint8 filt_nr, const gchar *filter, gboolean disabled, gchar **err_msg); + +/** Get a temporary color filter. + * + * @param filter_num A number from 1 to 10 specifying the color to fetch. + * @return The corresponding color or NULL. + */ +WS_DLL_PUBLIC const color_filter_t * +color_filters_tmp_color(guint8 filter_num); + +/** Reset the temporary color filters + * + */ +WS_DLL_PUBLIC gboolean +color_filters_reset_tmp(gchar **err_msg); + +/* Prime the epan_dissect_t with all the compiler + * color filters of the current filter list. + * + * @param the epan dissector details + */ +WS_DLL_PUBLIC void color_filters_prime_edt(struct epan_dissect *edt); + +/** Colorize a specific packet. + * + * @param edt the dissected packet + * @return the matching color filter or NULL + */ +WS_DLL_PUBLIC const color_filter_t * +color_filters_colorize_packet(struct epan_dissect *edt); + +/** Clone the currently active filter list. + * + * @param user_data will be returned by each call to to color_filter_add_cb() + */ +WS_DLL_PUBLIC void color_filters_clone(gpointer user_data, color_filter_add_cb_func add_cb); + +/** Load filters (import) from some other filter file. + * + * @param path the path to the import file + * @param user_data will be returned by each call to to color_filter_add_cb() + * @return TRUE, if read succeeded + */ +WS_DLL_PUBLIC gboolean color_filters_import(const gchar *path, const gpointer user_data, gchar** err_msg, initialize_color_func init_func, color_filter_add_cb_func add_cb); + +/** Read filters from the global filter file (not the users file). + * + * @param user_data will be returned by each call to to color_filter_add_cb() + * @return TRUE, if read succeeded + */ +WS_DLL_PUBLIC gboolean color_filters_read_globals(gpointer user_data, gchar** err_msg, initialize_color_func init_func, color_filter_add_cb_func add_cb); + + +/** Apply a changed filter list. + * + * @param tmp_cfl the temporary color filter list to apply + * @param edit_cfl the edited permanent color filter list to apply + */ +WS_DLL_PUBLIC gboolean color_filters_apply(GSList *tmp_cfl, GSList *edit_cfl, gchar** err_msg); + +/** Save filters in users filter file. + * + * @param cfl the filter list to write + * @return TRUE if write succeeded + */ +WS_DLL_PUBLIC gboolean color_filters_write(GSList *cfl, gchar** err_msg); + +/** Save filters (export) to some other filter file. + * + * @param path the path to the filter file + * @param cfl the filter list to write + * @param only_selected TRUE if only the selected filters should be saved + * @return TRUE, if write succeeded + */ +WS_DLL_PUBLIC gboolean color_filters_export(const gchar *path, const GSList *cfl, gboolean only_selected, gchar** err_msg); + +/** Create a new color filter (g_malloc'ed). + * + * @param name the name of the filter + * @param filter_string the filter string + * @param bg_color background color + * @param fg_color foreground color + * @param disabled gboolean + * @return the new color filter + */ +WS_DLL_PUBLIC color_filter_t *color_filter_new( + const gchar *name, const gchar *filter_string, + color_t *bg_color, color_t *fg_color, gboolean disabled); + +/** Delete a single color filter (g_free'ed). + * + * @param colorf the color filter to be removed + */ +WS_DLL_PUBLIC void color_filter_delete(color_filter_t *colorf); + +/** Delete a filter list including all entries. + * + * @param cfl the filter list to delete + */ +WS_DLL_PUBLIC void color_filter_list_delete(GSList **cfl); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/epan/dissectors/file-file.c b/epan/dissectors/file-file.c index b01f53cd33..e7a469a18e 100644 --- a/epan/dissectors/file-file.c +++ b/epan/dissectors/file-file.c @@ -39,8 +39,7 @@ #include #include -#include "color.h" -#include "color_filters.h" +#include #include "file-file.h" diff --git a/epan/dissectors/packet-frame.c b/epan/dissectors/packet-frame.c index 0776295f6c..2a7b498ac4 100644 --- a/epan/dissectors/packet-frame.c +++ b/epan/dissectors/packet-frame.c @@ -44,8 +44,7 @@ #include "packet-frame.h" #include "log.h" -#include "color.h" -#include "color_filters.h" +#include void proto_register_frame(void); void proto_reg_handoff_frame(void); diff --git a/epan/prefs.h b/epan/prefs.h index 0f2834e43b..b02a2b0c45 100644 --- a/epan/prefs.h +++ b/epan/prefs.h @@ -29,7 +29,7 @@ extern "C" { #include -#include "color.h" +#include "color_filters.h" #include #include diff --git a/file.c b/file.c index 05bca69949..d7f13bb7a2 100644 --- a/file.c +++ b/file.c @@ -53,9 +53,8 @@ #include #include #include +#include -#include "color.h" -#include "color_filters.h" #include "cfile.h" #include "file.h" #include "fileset.h" diff --git a/ui/gtk/capture_file_dlg.c b/ui/gtk/capture_file_dlg.c index e120034751..bf4a7ecc99 100644 --- a/ui/gtk/capture_file_dlg.c +++ b/ui/gtk/capture_file_dlg.c @@ -31,8 +31,7 @@ #include #include "globals.h" -#include "color.h" -#include "color_filters.h" +#include #include @@ -40,6 +39,7 @@ #include "ui/util.h" #include "ui/alert_box.h" +#include "ui/simple_dialog.h" #include "ui/file_dialog.h" #include "ui/recent.h" #include "ui/ui_util.h" @@ -2245,7 +2245,7 @@ file_color_import_cmd_cb(GtkWidget *color_filters, gpointer filter_list _U_) win32_import_color_file(GDK_WINDOW_HWND(gtk_widget_get_window(top_level)), color_filters); #else /* USE_WIN32_FILE_DIALOGS */ GtkWidget *main_vb, *cfglobal_but; - gchar *cf_name, *s; + gchar *cf_name, *s, *err_msg = NULL; /* No Apply button, and "OK" just sets our text widget, it doesn't activate it (i.e., it doesn't cause us to try to open the file). */ @@ -2277,11 +2277,13 @@ file_color_import_cmd_cb(GtkWidget *color_filters, gpointer filter_list _U_) } /* Try to open the color filter file. */ - if (!color_filters_import(cf_name, color_filters)) { + if (!color_filters_import(cf_name, color_filters, &err_msg, initialize_color, color_filter_add_cb)) { /* We couldn't open it; don't dismiss the open dialog box, just leave it around so that the user can, after they dismiss the alert box popped up for the open error, try again. */ + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); g_free(cf_name); continue; } @@ -2341,6 +2343,7 @@ file_color_export_cmd_cb(GtkWidget *w _U_, gpointer filter_list) GtkWidget *cfselect_cb; gchar *cf_name; gchar *dirname; + gchar *err_msg = NULL; color_selected = FALSE; @@ -2390,10 +2393,12 @@ file_color_export_cmd_cb(GtkWidget *w _U_, gpointer filter_list) /* Write out the filters (all, or only the ones that are currently displayed or selected) to the file with the specified name. */ - if (!color_filters_export(cf_name, (GSList *)filter_list, color_selected)) { + if (!color_filters_export(cf_name, (GSList *)filter_list, color_selected, &err_msg)) { /* The write failed; don't dismiss the open dialog box, just leave it around so that the user can, after they dismiss the alert box popped up for the error, try again. */ + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); g_free(cf_name); continue; } diff --git a/ui/gtk/color_dlg.c b/ui/gtk/color_dlg.c index dfbe60d773..edb6c6da13 100644 --- a/ui/gtk/color_dlg.c +++ b/ui/gtk/color_dlg.c @@ -28,8 +28,7 @@ #include #include - -#include "../color_filters.h" +#include #include "simple_dialog.h" @@ -149,6 +148,17 @@ int color_selected_count(void) return count; } + +/* a new color filter was read in from a filter file */ +void +color_filter_add_cb(color_filter_t *colorf, gpointer user_data) +{ + GtkWidget *color_filters = (GtkWidget*)user_data; + + add_filter_to_list(colorf, color_filters, FALSE); + + gtk_widget_grab_focus(color_filters); +} /* Create the "Coloring Rules" dialog. */ static GtkWidget* colorize_dialog_new (char *filter) @@ -406,7 +416,7 @@ colorize_dialog_new (char *filter) gtk_widget_grab_focus(color_filters); /* prepare filter list content */ - color_filters_clone(color_filters); + color_filters_clone(color_filters, color_filter_add_cb); g_object_set_data(G_OBJECT(color_win), COLOR_FILTER_LIST, &color_filter_edit_list); gtk_widget_show_all(color_win); @@ -734,18 +744,6 @@ add_filter_to_list(gpointer filter_arg, gpointer list_arg, gboolean prepend) } } - -/* a new color filter was read in from a filter file */ -void -color_filter_add_cb(color_filter_t *colorf, gpointer user_data) -{ - GtkWidget *color_filters = (GtkWidget*)user_data; - - add_filter_to_list(colorf, color_filters, FALSE); - - gtk_widget_grab_focus(color_filters); -} - /* Create a new filter, add it to the list, and pop up an "Edit color filter" dialog box to edit it. */ static void @@ -955,6 +953,7 @@ static void color_clear_cmd(GtkWidget *widget) { GtkWidget * color_filters; + gchar* err_msg = NULL; color_filters = (GtkWidget *)g_object_get_data(G_OBJECT(widget), COLOR_FILTERS_CL); @@ -964,7 +963,11 @@ color_clear_cmd(GtkWidget *widget) } /* try to read the global filters */ - color_filters_read_globals(color_filters); + if (!color_filters_read_globals(color_filters, &err_msg, initialize_color, color_filter_add_cb)) + { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } } /* User pressed "clear" button: ask user before really doing it */ @@ -1013,12 +1016,17 @@ color_clear_cb(GtkWidget *widget, gpointer data _U_) { static void overwrite_existing_colorfilters_cb(gpointer dialog _U_, gint btn, gpointer data _U_) { + gchar* err_msg = NULL; + switch (btn) { case(ESD_BTN_SAVE): /* overwrite the file*/ - if (!color_filters_write(color_filter_edit_list)) + if (!color_filters_write(color_filter_edit_list, &err_msg)) + { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not open colorfilter file: %s", g_strerror(errno)); + "Could not open colorfilter file: %s", err_msg); + g_free(err_msg); + } else prefs.unknown_colorfilters = FALSE; break; @@ -1032,6 +1040,7 @@ overwrite_existing_colorfilters_cb(gpointer dialog _U_, gint btn, gpointer data static void colorfilters_main_save(void) { + gchar* err_msg = NULL; if (prefs.unknown_colorfilters) { gpointer dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE, "Obsolete or unrecognized color filters have been detected. " @@ -1041,8 +1050,9 @@ colorfilters_main_save(void) simple_dialog_set_cb(dialog, overwrite_existing_colorfilters_cb, NULL); } else { - if (!color_filters_write(color_filter_edit_list)) - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not open filter file: %s", g_strerror(errno)); + if (!color_filters_write(color_filter_edit_list, &err_msg)) + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not open filter file: %s", err_msg); + g_free(err_msg); } } @@ -1064,6 +1074,8 @@ color_ok_cb(GtkButton *button _U_, gpointer user_data _U_) static void color_apply_cb(GtkButton *button _U_, gpointer user_data _U_) { + gchar* err_msg = NULL; + /* if we don't have a Save button, just save the settings now */ if (!prefs.gui_use_pref_save) colorfilters_main_save(); @@ -1071,7 +1083,10 @@ color_apply_cb(GtkButton *button _U_, gpointer user_data _U_) /* Apply the coloring rules, both the temporary ones in * color_filter_tmp_list as the permanent ones in color_filter_edit_list * */ - color_filters_apply(color_filter_tmp_list, color_filter_edit_list); + if (!color_filters_apply(color_filter_tmp_list, color_filter_edit_list, &err_msg)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } /* colorize list */ packet_list_colorize_packets(); diff --git a/ui/gtk/color_edit_dlg.c b/ui/gtk/color_edit_dlg.c index 33aa800c9c..5ee13a6e47 100644 --- a/ui/gtk/color_edit_dlg.c +++ b/ui/gtk/color_edit_dlg.c @@ -26,8 +26,7 @@ #include -#include "../color.h" -#include "../color_filters.h" +#include #include "ui/simple_dialog.h" diff --git a/ui/gtk/color_utils.c b/ui/gtk/color_utils.c index 73a98163e3..7d9d70af07 100644 --- a/ui/gtk/color_utils.c +++ b/ui/gtk/color_utils.c @@ -26,17 +26,14 @@ #include -#include "../color.h" - - #include "ui/gtk/color_utils.h" #if 0 static GdkColormap* sys_cmap; static GdkColormap* our_cmap = NULL; #endif -GdkColor WHITE = { 0, 65535, 65535, 65535 }; -/*GdkColor LTGREY = { 0, 57343, 57343, 57343 };*/ -GdkColor BLACK = { 0, 0, 0, 0 }; +/* static GdkColor WHITE = { 0, 65535, 65535, 65535 }; */ +/*static GdkColor LTGREY = { 0, 57343, 57343, 57343 };*/ +/* static GdkColor BLACK = { 0, 0, 0, 0 }; */ /* * Initialize a color with R, G, and B values, including any toolkit-dependent diff --git a/ui/gtk/color_utils.h b/ui/gtk/color_utils.h index c3923a51ea..15bddaef8d 100644 --- a/ui/gtk/color_utils.h +++ b/ui/gtk/color_utils.h @@ -24,20 +24,12 @@ #define __COLORS_H__ #include "ui/gtk/gui_utils.h" +#include /** @file * Definitions for color structures and routines */ -/** The color white. */ -extern GdkColor WHITE; - -/** The color light-grey. */ -extern GdkColor LTGREY; - -/** The color black. */ -extern GdkColor BLACK; - /** Initialize the colors. */ void colors_init(void); diff --git a/ui/gtk/compare_stat.c b/ui/gtk/compare_stat.c index 6b13fd2d55..851ed217b0 100644 --- a/ui/gtk/compare_stat.c +++ b/ui/gtk/compare_stat.c @@ -64,8 +64,7 @@ #include "globals.h" /* Color settings */ -#include "color.h" -#include "color_filters.h" +#include #include "packet_list.h" @@ -539,6 +538,7 @@ comparestat_draw(void *arg) frame_info *fInfo; guint32 first_file_amount, second_file_amount; char* addr_str; + gchar *err_msg = NULL; /* initial steps, clear all data before start*/ cs->zebra_time.secs=0; @@ -591,7 +591,10 @@ comparestat_draw(void *arg) g_string_printf(filter_str, "%s %s %s %s", "eth.dst==", addr_str, "|| eth.dst==", addr_str); wmem_free(NULL, addr_str); } - color_filters_set_tmp(COLOR_N, filter_str->str, FALSE); + if (!color_filters_set_tmp(COLOR_N, filter_str->str, FALSE, &err_msg)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } packet_list_colorize_packets(); /* Variance */ cs->stats.variance=compare_variance; diff --git a/ui/gtk/funnel_stat.c b/ui/gtk/funnel_stat.c index 96781a11f2..f7f15eb38a 100644 --- a/ui/gtk/funnel_stat.c +++ b/ui/gtk/funnel_stat.c @@ -44,7 +44,8 @@ #include #include "ui/progress_dlg.h" -#include "../color_filters.h" +#include "ui/simple_dialog.h" +#include #include "ui/gtk/gui_utils.h" #include "ui/gtk/dlg_utils.h" @@ -465,7 +466,11 @@ static void funnel_set_filter(funnel_ops_id_t *ops_id _U_, const char* filter_st } static void funnel_set_color_filter_slot(guint8 filt_nr, const gchar* filter_string) { - color_filters_set_tmp(filt_nr, (gchar *)filter_string, FALSE); + gchar *err_msg = NULL; + if (!color_filters_set_tmp(filt_nr, (gchar *)filter_string, FALSE, &err_msg)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } } static void funnel_apply_filter(funnel_ops_id_t *ops_id _U_) { diff --git a/ui/gtk/main.c b/ui/gtk/main.c index 8eab2b5b55..93e255f946 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -97,8 +97,7 @@ #include "../file.h" #include "../frame_tvbuff.h" #include "../summary.h" -#include "../color.h" -#include "../color_filters.h" +#include #include "../register.h" #include "../ringbuffer.h" #include "../log.h" @@ -355,6 +354,7 @@ void colorize_selected_ptree_cb(GtkWidget *w _U_, gpointer data _U_, guint8 filt_nr) { char *filter = NULL; + gchar *err_msg = NULL; if (cfile.finfo_selected) { filter = proto_construct_match_selected_string(cfile.finfo_selected, @@ -370,9 +370,16 @@ colorize_selected_ptree_cb(GtkWidget *w _U_, gpointer data _U_, guint8 filt_nr) color_display_with_filter(filter); } else { if (filt_nr==255) { - color_filters_reset_tmp(); + if (!color_filters_reset_tmp(&err_msg)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } } else { - color_filters_set_tmp(filt_nr,filter, FALSE); + if (!color_filters_set_tmp(filt_nr,filter, FALSE, &err_msg)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } + } packet_list_colorize_packets(); } @@ -1351,7 +1358,7 @@ main_colorize_changed(gboolean packet_list_colorize) /* change colorization */ if(packet_list_colorize != recent.packet_list_colorize) { recent.packet_list_colorize = packet_list_colorize; - color_filters_enable(packet_list_colorize); + packet_list_enable_color(packet_list_colorize); packet_list_colorize_packets(); } } @@ -2215,7 +2222,7 @@ main(int argc, char *argv[]) gint pl_size = 280, tv_size = 95, bv_size = 75; gchar *rc_file, *cf_name = NULL, *rfilter = NULL, *dfilter = NULL, *jfilter = NULL; dfilter_t *rfcode = NULL; - gchar *err_msg; + gchar *err_msg = NULL; gboolean rfilter_parse_failed = FALSE; e_prefs *prefs_p; char badopt; @@ -3135,7 +3142,7 @@ main(int argc, char *argv[]) g_free(rf_path); } - color_filters_enable(recent.packet_list_colorize); + packet_list_enable_color(recent.packet_list_colorize); /* rearrange all the widgets as we now have all recent settings ready for this */ main_widgets_rearrange(); @@ -3173,7 +3180,10 @@ main(int argc, char *argv[]) dnd_init(top_level); - color_filters_init(); + if (!color_filters_init(&err_msg, initialize_color, color_filter_add_cb)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } #ifdef HAVE_LIBPCAP capture_filter_init(); #endif @@ -3886,6 +3896,7 @@ void change_configuration_profile (const gchar *profile_name) char *gdp_path, *dp_path; char *rf_path; int rf_open_errno; + gchar* err_msg = NULL; /* First check if profile exists */ if (!profile_exists(profile_name, FALSE)) { @@ -3933,7 +3944,7 @@ void change_configuration_profile (const gchar *profile_name) } timestamp_set_type (recent.gui_time_format); timestamp_set_seconds_type (recent.gui_seconds_format); - color_filters_enable(recent.packet_list_colorize); + packet_list_enable_color(recent.packet_list_colorize); prefs_to_capture_opts(); prefs_apply_all(); @@ -3955,7 +3966,10 @@ void change_configuration_profile (const gchar *profile_name) } /* Reload color filters */ - color_filters_reload(); + if (!color_filters_reload(&err_msg, initialize_color, color_filter_add_cb)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } /* Reload list of interfaces on welcome page */ welcome_if_panel_reload(); @@ -3975,8 +3989,13 @@ void change_configuration_profile (const gchar *profile_name) void main_fields_changed (void) { + gchar* err_msg = NULL; + /* Reload color filters */ - color_filters_reload(); + if (!color_filters_reload(&err_msg, initialize_color, color_filter_add_cb)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } /* Syntax check filter */ filter_te_syntax_check_cb(main_display_filter_widget, NULL); diff --git a/ui/gtk/main_menubar.c b/ui/gtk/main_menubar.c index 4edfa5140f..8da4c80299 100644 --- a/ui/gtk/main_menubar.c +++ b/ui/gtk/main_menubar.c @@ -38,7 +38,7 @@ #include #include "globals.h" -#include "color_filters.h" +#include #include "ui/main_statusbar.h" #include "ui/preference_utils.h" @@ -193,9 +193,13 @@ colorize_conversation_cb(conversation_filter_t* color_filter, int action_num) { gchar *filter = NULL; packet_info *pi = &cfile.edt->pi; + gchar *err_msg = NULL; if (action_num == 255) { - color_filters_reset_tmp(); + if (!color_filters_reset_tmp(&err_msg)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } packet_list_colorize_packets(); } else if (cfile.current_frame) { if (color_filter == NULL) { @@ -239,7 +243,10 @@ colorize_conversation_cb(conversation_filter_t* color_filter, int action_num) color_display_with_filter(filter); } else { /* Set one of the temporary coloring filters */ - color_filters_set_tmp(action_num, filter, FALSE); + if (!color_filters_set_tmp(action_num, filter, FALSE, &err_msg)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } packet_list_colorize_packets(); } diff --git a/ui/gtk/packet_list.c b/ui/gtk/packet_list.c index 28a1aec161..98f4978a1e 100644 --- a/ui/gtk/packet_list.c +++ b/ui/gtk/packet_list.c @@ -49,7 +49,7 @@ #include "ui/gtk/packet_history.h" #include "ui/gtk/keys.h" #include "ui/gtk/menus.h" -#include "color_filters.h" +#include #include "ui/gtk/color_utils.h" #include "ui/gtk/packet_win.h" #include "ui/gtk/main.h" diff --git a/ui/gtk/packet_list_store.c b/ui/gtk/packet_list_store.c index d7696a3597..8c4e21606b 100644 --- a/ui/gtk/packet_list_store.c +++ b/ui/gtk/packet_list_store.c @@ -42,8 +42,7 @@ #include #include -#include "color.h" -#include "color_filters.h" +#include #include "frame_tvbuff.h" #include "globals.h" diff --git a/ui/qt/Wireshark.pro b/ui/qt/Wireshark.pro index ac42adad99..72467e0cca 100644 --- a/ui/qt/Wireshark.pro +++ b/ui/qt/Wireshark.pro @@ -191,7 +191,6 @@ SOURCES_WS_C = \ ../../capture_info.c \ ../../capture_opts.c \ ../../cfile.c \ - ../../color_filters.c \ ../../extcap.c \ ../../extcap_parser.c \ ../../file.c \ diff --git a/ui/qt/color_utils.cpp b/ui/qt/color_utils.cpp index e150a14003..d90d6046f7 100644 --- a/ui/qt/color_utils.cpp +++ b/ui/qt/color_utils.cpp @@ -23,28 +23,6 @@ #include "tango_colors.h" -/* - * Initialize a color with R, G, and B values, including any toolkit-dependent - * work that needs to be done. - */ -gboolean -initialize_color(color_t *color, guint16 red, guint16 green, guint16 blue) -{ - QColor qc; - - // color_t uses 16-bit components to match Gtk+. Qt use 8. - qc.setRgb(red>>8, green>>8, blue>>8); - if (!qc.isValid()) - return FALSE; - - // Match what color_filters.c does. - color->red = red; - color->green = green; - color->blue = blue; - color->pixel = 0; - return TRUE; -} - const QColor ColorUtils::expert_color_comment = QColor ( 0xb7, 0xf7, 0x74 ); /* Green */ const QColor ColorUtils::expert_color_chat = QColor ( 0x80, 0xb7, 0xf7 ); /* Light blue */ const QColor ColorUtils::expert_color_note = QColor ( 0xa0, 0xff, 0xff ); /* Bright turquoise */ diff --git a/ui/qt/color_utils.h b/ui/qt/color_utils.h index 8b1051837b..e9b1806363 100644 --- a/ui/qt/color_utils.h +++ b/ui/qt/color_utils.h @@ -26,7 +26,7 @@ #include -#include "color.h" +#include #include #include @@ -64,6 +64,8 @@ private: static const QList graph_colors_; }; +void color_filter_qt_add_cb(color_filter_t *colorf, gpointer user_data); + #endif // COLOR_UTILS_H /* diff --git a/ui/qt/coloring_rules_dialog.cpp b/ui/qt/coloring_rules_dialog.cpp index e8314f499a..846ff13112 100644 --- a/ui/qt/coloring_rules_dialog.cpp +++ b/ui/qt/coloring_rules_dialog.cpp @@ -28,9 +28,10 @@ #include "coloring_rules_dialog.h" #include -#include "color.h" -#include "color_filters.h" +#include "epan/color_filters.h" +#include "ui/simple_dialog.h" +#include "ui/simple_dialog.h" #include "epan/dfilter/dfilter.h" #include "epan/prefs.h" @@ -39,6 +40,7 @@ #include "wsutil/filesystem.h" #include "color_utils.h" +#include "ui/ui_util.h" #include "display_filter_combo.h" #include "syntax_line_edit.h" #include "wireshark_application.h" @@ -60,15 +62,6 @@ // - Make the filter column narrower? It's easy to run into Qt's annoying // habit of horizontally scrolling QTreeWidgets here. -// Callback for color_filters_clone. -void -color_filter_add_cb(color_filter_t *colorf, gpointer user_data) -{ - ColoringRulesDialog *coloring_rules_dialog = static_cast(user_data); - - if (!coloring_rules_dialog) return; - coloring_rules_dialog->addColor(colorf); -} enum { name_col_ = 0, @@ -93,7 +86,7 @@ ColoringRulesDialog::ColoringRulesDialog(QWidget *parent, QString add_filter) : ui->coloringRulesTreeWidget->setDropIndicatorShown(true); ui->coloringRulesTreeWidget->setDragDropMode(QAbstractItemView::InternalMove); - color_filters_clone(this); + color_filters_clone(this, color_filter_add_cb); for (int i = 0; i < ui->coloringRulesTreeWidget->columnCount(); i++) { ui->coloringRulesTreeWidget->setItemDelegateForColumn(i, &coloring_rules_tree_delegate_); @@ -330,7 +323,11 @@ void ColoringRulesDialog::on_buttonBox_clicked(QAbstractButton *button) if (button == import_button_) { QString file_name = QFileDialog::getOpenFileName(this, wsApp->windowTitleString(tr("Import Coloring Rules")), wsApp->lastOpenDir().path()); - color_filters_import(file_name.toUtf8().constData(), this); + gchar* err_msg = NULL; + if (!color_filters_import(file_name.toUtf8().constData(), this, &err_msg, initialize_color, color_filter_add_cb)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } } else if (button == export_button_) { int num_items = ui->coloringRulesTreeWidget->selectedItems().count(); @@ -345,7 +342,11 @@ void ColoringRulesDialog::on_buttonBox_clicked(QAbstractButton *button) wsApp->lastOpenDir().path()); if (!file_name.isEmpty()) { GSList *cfl = createColorFilterList(); - color_filters_export(file_name.toUtf8().constData(), cfl, FALSE); + gchar* err_msg = NULL; + if (!color_filters_export(file_name.toUtf8().constData(), cfl, FALSE, &err_msg)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } color_filter_list_delete(&cfl); } } @@ -354,6 +355,7 @@ void ColoringRulesDialog::on_buttonBox_clicked(QAbstractButton *button) void ColoringRulesDialog::on_buttonBox_accepted() { GSList *cfl = createColorFilterList(); + gchar* err_msg = NULL; if (prefs.unknown_colorfilters) { QMessageBox mb; mb.setText(tr("Your coloring rules file contains unknown rules")); @@ -365,9 +367,13 @@ void ColoringRulesDialog::on_buttonBox_accepted() int result = mb.exec(); if (result != QMessageBox::Save) return; } - color_filters_apply(conversation_colors_, cfl); - if (!color_filters_write(cfl)) { - QMessageBox::warning(this, tr("Unable to save coloring rules"), g_strerror(errno)); + if (!color_filters_apply(conversation_colors_, cfl, &err_msg)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } + if (!color_filters_write(cfl, &err_msg)) { + QMessageBox::warning(this, tr("Unable to save coloring rules: %s"), g_strerror(errno)); + g_free(err_msg); } color_filter_list_delete(&cfl); } @@ -430,6 +436,38 @@ void ColoringRulesTreeDelegate::ruleNameChanged(const QString name) } +/* + * Initialize a color with R, G, and B values, including any toolkit-dependent + * work that needs to be done. + */ +gboolean +initialize_color(color_t *color, guint16 red, guint16 green, guint16 blue) +{ + QColor qc; + + // color_t uses 16-bit components to match Gtk+. Qt use 8. + qc.setRgb(red>>8, green>>8, blue>>8); + if (!qc.isValid()) + return FALSE; + + // Match what color_filters.c does. + color->red = red; + color->green = green; + color->blue = blue; + color->pixel = 0; + return TRUE; +} + +// Callback for color_filters_clone. +void +color_filter_add_cb(color_filter_t *colorf, gpointer user_data) +{ + ColoringRulesDialog *coloring_rules_dialog = static_cast(user_data); + + if (!coloring_rules_dialog) return; + coloring_rules_dialog->addColor(colorf); +} + /* * Editor modelines * diff --git a/ui/qt/column_preferences_frame.cpp b/ui/qt/column_preferences_frame.cpp index 943861d352..87627124aa 100644 --- a/ui/qt/column_preferences_frame.cpp +++ b/ui/qt/column_preferences_frame.cpp @@ -23,8 +23,6 @@ #include -#include "color.h" - #include #include #include diff --git a/ui/qt/funnel_statistics.cpp b/ui/qt/funnel_statistics.cpp index abbb4f37ce..85e0f2b6a5 100644 --- a/ui/qt/funnel_statistics.cpp +++ b/ui/qt/funnel_statistics.cpp @@ -23,13 +23,13 @@ #include -#include "color.h" -#include "color_filters.h" +#include "epan/color_filters.h" #include "file.h" #include "epan/funnel.h" #include "ui/progress_dlg.h" +#include "ui/simple_dialog.h" #include "funnel_statistics.h" #include "funnel_string_dialog.h" @@ -230,7 +230,11 @@ void funnel_statistics_set_filter(funnel_ops_id_t *ops_id, const char* filter_st } void funnel_statistics_set_color_filter_slot(guint8 filter_num, const gchar* filter_string) { - color_filters_set_tmp(filter_num, (gchar *)filter_string, FALSE); + gchar *err_msg = NULL; + if (!color_filters_set_tmp(filter_num, (gchar *)filter_string, FALSE, &err_msg)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } } gboolean funnel_statistics_open_file(funnel_ops_id_t *ops_id, const char* fname, const char* filter, char**) { diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 91ce271fb9..29416f02f6 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -38,7 +38,7 @@ #include "ui/capture.h" #endif -#include "color_filters.h" +#include "epan/color_filters.h" #include "wsutil/file_util.h" #include "wsutil/filesystem.h" @@ -1397,7 +1397,11 @@ void MainWindow::checkDisplayFilter() void MainWindow::fieldsChanged() { - color_filters_reload(); + gchar *err_msg = NULL; + if (!color_filters_reload(&err_msg, initialize_color, color_filter_add_cb)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } tap_listeners_dfilter_recompile(); emit checkDisplayFilter(); @@ -2245,7 +2249,7 @@ void MainWindow::on_actionViewNormalSize_triggered() void MainWindow::on_actionViewColorizePacketList_triggered(bool checked) { recent.packet_list_colorize = checked; - color_filters_enable(checked); + packet_list_enable_color(checked); packet_list_->packetListModel()->resetColorized(); } @@ -2302,7 +2306,11 @@ void MainWindow::colorizeConversation(bool create_rule) packet_list_, SLOT(recolorPackets())); coloring_rules_dialog.exec(); } else { - color_filters_set_tmp(cc_num, filter, FALSE); + gchar *err_msg = NULL; + if (!color_filters_set_tmp(cc_num, filter, FALSE, &err_msg)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } packet_list_->recolorPackets(); } } @@ -2322,7 +2330,11 @@ void MainWindow::colorizeWithFilter() if (ok) { // Assume "Color X" - color_filters_set_tmp(color_number, filter.toUtf8().constData(), FALSE); + gchar *err_msg = NULL; + if (color_filters_set_tmp(color_number, filter.toUtf8().constData(), FALSE, &err_msg)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } packet_list_->recolorPackets(); } else { // New coloring rule @@ -2336,7 +2348,11 @@ void MainWindow::colorizeWithFilter() void MainWindow::on_actionViewColorizeResetColorization_triggered() { - color_filters_reset_tmp(); + gchar *err_msg = NULL; + if (!color_filters_reset_tmp(&err_msg)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } packet_list_->recolorPackets(); setMenusForSelectedPacket(); } diff --git a/ui/qt/module_preferences_scroll_area.h b/ui/qt/module_preferences_scroll_area.h index c2bfb72eb3..7b46e8dfe8 100644 --- a/ui/qt/module_preferences_scroll_area.h +++ b/ui/qt/module_preferences_scroll_area.h @@ -26,8 +26,6 @@ #include -#include "color.h" - #include #include diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index 2d92d30779..0f5d57d694 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -47,8 +47,7 @@ #include "wsutil/str_util.h" -#include "color.h" -#include "color_filters.h" +#include #include "frame_tvbuff.h" #include "color_utils.h" diff --git a/ui/qt/packet_list_model.cpp b/ui/qt/packet_list_model.cpp index db6e6f58f9..4bbb63658d 100644 --- a/ui/qt/packet_list_model.cpp +++ b/ui/qt/packet_list_model.cpp @@ -32,8 +32,7 @@ #include "ui/packet_list_utils.h" #include "ui/recent.h" -#include "color.h" -#include "color_filters.h" +#include #include "frame_tvbuff.h" #include "color_utils.h" diff --git a/ui/qt/packet_list_record.cpp b/ui/qt/packet_list_record.cpp index 73b788405d..26f147feed 100644 --- a/ui/qt/packet_list_record.cpp +++ b/ui/qt/packet_list_record.cpp @@ -28,8 +28,7 @@ #include #include -#include "color.h" -#include "color_filters.h" +#include #include "frame_tvbuff.h" #include diff --git a/ui/qt/preferences_dialog.h b/ui/qt/preferences_dialog.h index 95582e05f7..8c0824b228 100644 --- a/ui/qt/preferences_dialog.h +++ b/ui/qt/preferences_dialog.h @@ -26,8 +26,6 @@ #include -#include "color.h" - #include #include "wireshark_application.h" diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp index 45e0587b46..ec648a56fc 100644 --- a/ui/qt/wireshark_application.cpp +++ b/ui/qt/wireshark_application.cpp @@ -48,8 +48,10 @@ #include "ui/util.h" #include "qt_ui_utils.h" +#include "color_utils.h" +#include "coloring_rules_dialog.h" -#include "color_filters.h" +#include "epan/color_filters.h" #include "log.h" #include "recent_file_status.h" @@ -303,6 +305,7 @@ void WiresharkApplication::setConfigurationProfile(const gchar *profile_name) char *gdp_path, *dp_path; char *rf_path; int rf_open_errno; + gchar *err_msg = NULL; /* First check if profile exists */ if (!profile_exists(profile_name, FALSE)) { @@ -366,7 +369,7 @@ void WiresharkApplication::setConfigurationProfile(const gchar *profile_name) timestamp_set_type (recent.gui_time_format); timestamp_set_precision(recent.gui_time_precision); timestamp_set_seconds_type (recent.gui_seconds_format); - color_filters_enable(recent.packet_list_colorize); + packet_list_enable_color(recent.packet_list_colorize); tap_update_timer_.setInterval(prefs.tap_update_interval); prefs_to_capture_opts(); @@ -391,7 +394,10 @@ void WiresharkApplication::setConfigurationProfile(const gchar *profile_name) } /* Reload color filters */ - color_filters_reload(); + if (!color_filters_reload(&err_msg, initialize_color, color_filter_add_cb)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } emit localInterfaceListChanged(); emit packetDissectionChanged(); diff --git a/ui/ui_util.h b/ui/ui_util.h index 4fb6c0f63d..fd5f1daedb 100644 --- a/ui/ui_util.h +++ b/ui/ui_util.h @@ -31,6 +31,7 @@ #include "epan/packet_info.h" #include "epan/column-utils.h" +#include "epan/color_filters.h" #ifdef __cplusplus extern "C" { @@ -82,6 +83,15 @@ gboolean packet_list_check_end(void); /* GTK+ only */ gboolean packet_list_select_row_from_data(frame_data *fdata_needle); void packet_list_resize_column(gint col); +/* XXX - Yes this isn't the best place, but they are used by file_dlg_win32.c, which is supposed + to be GUI independent, but has lots of GTK leanings. But if you put these in a GTK UI + header file, file_dlg_win32.c complains about all of the GTK structures also in the header + files + Function names make it clear where they are coming from +*/ +gboolean initialize_color(color_t *color, guint16 red, guint16 green, guint16 blue); +void color_filter_add_cb(color_filter_t *colorf, gpointer user_data); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/ui/win32/file_dlg_win32.c b/ui/win32/file_dlg_win32.c index 9e9c32d6c5..747819024b 100644 --- a/ui/win32/file_dlg_win32.c +++ b/ui/win32/file_dlg_win32.c @@ -41,7 +41,7 @@ #include "epan/addr_resolv.h" #include "epan/prefs.h" -#include "color_filters.h" +#include "epan/color_filters.h" #include "ui/alert_box.h" #include "ui/help_url.h" @@ -49,6 +49,7 @@ #include "ui/simple_dialog.h" #include "ui/ssl_key_export.h" #include "ui/util.h" +#include "ui/ui_util.h" #include "file_dlg_win32.h" @@ -898,6 +899,7 @@ win32_export_color_file(HWND h_wnd, capture_file *cf, gpointer filter_list) { TCHAR file_name[MAX_PATH] = _T(""); gchar *dirname; int ofnsize; + gchar *err_msg = NULL; ofnsize = win32_get_ofnsize(); ofn = g_malloc0(ofnsize); @@ -927,8 +929,12 @@ win32_export_color_file(HWND h_wnd, capture_file *cf, gpointer filter_list) { /* XXX - Support marked filters */ if (GetSaveFileName(ofn)) { g_free( (void *) ofn); - if (!color_filters_export(utf_16to8(file_name), filter_list, FALSE /* all filters */)) + if (!color_filters_export(utf_16to8(file_name), filter_list, FALSE /* all filters */, &err_msg)) + { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); return; + } /* Save the directory name for future file dialogs. */ dirname = get_dirname(utf_16to8(file_name)); /* Overwrites cf_name */ @@ -944,6 +950,7 @@ win32_import_color_file(HWND h_wnd, gpointer color_filters) { TCHAR file_name[MAX_PATH] = _T(""); gchar *dirname; int ofnsize; + gchar *err_msg = NULL; ofnsize = win32_get_ofnsize(); ofn = g_malloc0(ofnsize); @@ -971,8 +978,11 @@ win32_import_color_file(HWND h_wnd, gpointer color_filters) { /* XXX - Support export limited to selected filters */ if (GetOpenFileName(ofn)) { g_free( (void *) ofn); - if (!color_filters_import(utf_16to8(file_name), color_filters)) + if (!color_filters_import(utf_16to8(file_name), color_filters, &err_msg, initialize_color, color_filter_add_cb)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); return; + } /* Save the directory name for future file dialogs. */ dirname = get_dirname(utf_16to8(file_name)); /* Overwrites cf_name */ diff --git a/wireshark-qt.cpp b/wireshark-qt.cpp index ec8b33cbab..cd63039447 100644 --- a/wireshark-qt.cpp +++ b/wireshark-qt.cpp @@ -72,8 +72,7 @@ /* general (not Qt specific) */ #include "file.h" -#include "color.h" -#include "color_filters.h" +#include "epan/color_filters.h" #include "log.h" #include "epan/rtd_table.h" @@ -89,6 +88,8 @@ #include "ui/util.h" #include "ui/qt/conversation_dialog.h" +#include "ui/qt/color_utils.h" +#include "ui/qt/coloring_rules_dialog.h" #include "ui/qt/endpoint_dialog.h" #include "ui/qt/main_window.h" #include "ui/qt/response_time_delay_dialog.h" @@ -1341,16 +1342,20 @@ int main(int argc, char *argv[]) g_free(rf_path); } - color_filters_enable(recent.packet_list_colorize); + packet_list_enable_color(recent.packet_list_colorize); g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: fetch recent color settings"); - color_filters_enable(TRUE); + packet_list_enable_color(TRUE); //////// //////// - color_filters_init(); + gchar* err_msg = NULL; + if (!color_filters_init(&err_msg, initialize_color, color_filter_add_cb)) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); + g_free(err_msg); + } //////// -- cgit v1.2.3