diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2008-05-17 22:54:29 +0000 |
---|---|---|
committer | Stig Bjørlykke <stig@bjorlykke.org> | 2008-05-17 22:54:29 +0000 |
commit | a392e8e88c85972de7fca2db0018dc1331bd9091 (patch) | |
tree | 01541382c736884992538c295bf24ab055840c54 | |
parent | d03fa8ee26318a23683d6b014a4e81ffeeb4e85b (diff) |
Added a common function to apply a selected filter according to
values from a context menu.
svn path=/trunk/; revision=25311
-rw-r--r-- | gtk/Makefile.common | 2 | ||||
-rw-r--r-- | gtk/filter_utils.c | 110 | ||||
-rw-r--r-- | gtk/filter_utils.h | 58 |
3 files changed, 170 insertions, 0 deletions
diff --git a/gtk/Makefile.common b/gtk/Makefile.common index e7031f7cb8..51d1a0e92b 100644 --- a/gtk/Makefile.common +++ b/gtk/Makefile.common @@ -59,6 +59,7 @@ WIRESHARK_GTK_SRC = \ file_dlg.c \ fileset_dlg.c \ filter_dlg.c \ + filter_utils.c \ find_dlg.c \ firewall_dlg.c \ follow_ssl.c \ @@ -222,6 +223,7 @@ noinst_HEADERS = \ file_dlg.h \ fileset_dlg.h \ filter_dlg.h \ + filter_utils.h \ find_dlg.h \ firewall_dlg.h \ follow_ssl.h \ diff --git a/gtk/filter_utils.c b/gtk/filter_utils.c new file mode 100644 index 0000000000..18bf161743 --- /dev/null +++ b/gtk/filter_utils.c @@ -0,0 +1,110 @@ +/* filter_utils.c + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gtk/gtk.h> +#include <string.h> + +#include "../globals.h" + +#include "gtk/main.h" +#include "gtk/gtkglobals.h" +#include "gtk/find_dlg.h" +#include "gtk/color_dlg.h" +#include "gtk/filter_utils.h" + +void +apply_selected_filter (guint callback_action, char *filter) +{ + int action, type; + char *str = NULL; + const char *current_filter; + + action = FILTER_ACTION(callback_action); + type = FILTER_ACTYPE(callback_action); + + current_filter = gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget)); + + switch(type){ + case ACTYPE_SELECTED: + str = g_strdup_printf("%s", filter); + break; + case ACTYPE_NOT_SELECTED: + str = g_strdup_printf("!(%s)", filter); + break; + case ACTYPE_AND_SELECTED: + if ((!current_filter) || (0 == strlen(current_filter))) + str = g_strdup_printf("%s", filter); + else + str = g_strdup_printf("(%s) && (%s)", current_filter, filter); + break; + case ACTYPE_OR_SELECTED: + if ((!current_filter) || (0 == strlen(current_filter))) + str = g_strdup_printf("%s", filter); + else + str = g_strdup_printf("(%s) || (%s)", current_filter, filter); + break; + case ACTYPE_AND_NOT_SELECTED: + if ((!current_filter) || (0 == strlen(current_filter))) + str = g_strdup_printf("!(%s)", filter); + else + str = g_strdup_printf("(%s) && !(%s)", current_filter, filter); + break; + case ACTYPE_OR_NOT_SELECTED: + if ((!current_filter) || (0 == strlen(current_filter))) + str = g_strdup_printf("!(%s)", filter); + else + str = g_strdup_printf("(%s) || !(%s)", current_filter, filter); + break; + } + + switch(action){ + case ACTION_MATCH: + gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), str); + main_filter_packets(&cfile, str, FALSE); + gdk_window_raise(top_level->window); + break; + case ACTION_PREPARE: + gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), str); + break; + case ACTION_FIND_FRAME: + find_frame_with_filter(str); + break; + case ACTION_FIND_NEXT: + find_previous_next_frame_with_filter(str, FALSE); + break; + case ACTION_FIND_PREVIOUS: + find_previous_next_frame_with_filter(str, TRUE); + break; + case ACTION_COLORIZE: + color_display_with_filter(str); + break; + } + + if (str) { + g_free (str); + } +} diff --git a/gtk/filter_utils.h b/gtk/filter_utils.h new file mode 100644 index 0000000000..3e5b921e12 --- /dev/null +++ b/gtk/filter_utils.h @@ -0,0 +1,58 @@ +/* filter_utils.h + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#define GTK_MENU_FUNC(a) ((GtkItemFactoryCallback)(a)) + +/* Filter actions */ +#define ACTION_MATCH 0 +#define ACTION_PREPARE 1 +#define ACTION_FIND_FRAME 2 +#define ACTION_FIND_NEXT 3 +#define ACTION_FIND_PREVIOUS 4 +#define ACTION_COLORIZE 5 +#define ACTION_WEB_LOOKUP 6 + +/* Action type - says what to do with the filter */ +#define ACTYPE_SELECTED 0 +#define ACTYPE_NOT_SELECTED 1 +#define ACTYPE_AND_SELECTED 2 +#define ACTYPE_OR_SELECTED 3 +#define ACTYPE_AND_NOT_SELECTED 4 +#define ACTYPE_OR_NOT_SELECTED 5 + +/* Encoded callback arguments */ +#define CALLBACK_MATCH(type, extra) ((ACTION_MATCH<<16) | ((type)<<8) | (extra)) +#define CALLBACK_PREPARE(type, extra) ((ACTION_PREPARE<<16) | ((type)<<8) | (extra)) +#define CALLBACK_FIND_FRAME(type, extra) ((ACTION_FIND_FRAME<<16) | ((type)<<8) | (extra)) +#define CALLBACK_FIND_NEXT(type, extra) ((ACTION_FIND_NEXT<<16) | ((type)<<8) | (extra)) +#define CALLBACK_FIND_PREVIOUS(type, extra) ((ACTION_FIND_PREVIOUS<<16) | ((type)<<8) | (extra)) +#define CALLBACK_COLORIZE(type, extra) ((ACTION_COLORIZE<<16) | ((type)<<8) | (extra)) +#define CALLBACK_WEB_LOOKUP (ACTION_WEB_LOOKUP<<16) + +/* Extract components of callback argument */ +#define FILTER_ACTION(cb_arg) (((cb_arg)>>16) & 0xff) +#define FILTER_ACTYPE(cb_arg) (((cb_arg)>>8) & 0xff) +#define FILTER_EXTRA(cb_arg) ((cb_arg) & 0xff) + + +extern void apply_selected_filter (guint callback_action, char *filter); |