aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ui/gtk/Makefile.common1
-rw-r--r--ui/gtk/capture_dlg.c36
-rw-r--r--ui/gtk/cfilter_combo_utils.c95
-rw-r--r--ui/gtk/cfilter_combo_utils.h2
-rw-r--r--ui/qt/display_filter_combo.cpp16
-rw-r--r--ui/recent.c130
-rw-r--r--ui/recent.h16
-rw-r--r--ui/recent_utils.h6
8 files changed, 167 insertions, 135 deletions
diff --git a/ui/gtk/Makefile.common b/ui/gtk/Makefile.common
index aeb90ec099..f10496b0b8 100644
--- a/ui/gtk/Makefile.common
+++ b/ui/gtk/Makefile.common
@@ -51,7 +51,6 @@ WIRESHARK_GTK_SRC = \
capture_file_dlg.c \
capture_if_dlg.c \
capture_info_dlg.c \
- cfilter_combo_utils.c \
color_dlg.c \
color_edit_dlg.c \
color_utils.c \
diff --git a/ui/gtk/capture_dlg.c b/ui/gtk/capture_dlg.c
index a22be5397b..ebbfe61e65 100644
--- a/ui/gtk/capture_dlg.c
+++ b/ui/gtk/capture_dlg.c
@@ -2613,6 +2613,7 @@ void options_interface_cb(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColum
gchar *tok, *name;
GtkCellRenderer *renderer;
GtkListStore *store;
+ const gchar *new_cfilter;
window = (GtkWidget *)userdata;
caller = gtk_widget_get_toplevel(GTK_WIDGET(window));
@@ -2898,21 +2899,28 @@ void options_interface_cb(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColum
/* Create the capture filter combo box*/
filter_cm = gtk_combo_box_text_new_with_entry();
- cfilter_list = (GList *)g_object_get_data(G_OBJECT(opt_edit_w), E_CFILTER_FL_KEY);
- g_object_set_data(G_OBJECT(opt_edit_w), E_CFILTER_FL_KEY, cfilter_list);
g_object_set_data(G_OBJECT(opt_edit_w), E_CFILTER_CM_KEY, filter_cm);
filter_te = gtk_bin_get_child(GTK_BIN(filter_cm));
colorize_filter_te_as_empty(filter_te);
g_signal_connect(filter_te, "changed", G_CALLBACK(capture_filter_check_syntax_cb), NULL);
g_signal_connect(filter_te, "destroy", G_CALLBACK(capture_filter_destroy_cb), NULL);
+ cfilter_list = recent_get_cfilter_list(name);
for (cf_entry = cfilter_list; cf_entry != NULL; cf_entry = g_list_next(cf_entry)) {
- if (cf_entry->data && (strlen((const char *)cf_entry->data) > 0)) {
- gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(filter_cm), (const gchar *)cf_entry->data);
+ new_cfilter = (const gchar *)cf_entry->data;
+ /* If this is the current dfilter or the default cfilter, don't put
+ it in the list, as it'll be added later. */
+ if ((device.cfilter == NULL || strcmp(device.cfilter, new_cfilter) != 0) &&
+ (global_capture_opts.default_options.cfilter == NULL || strcmp(global_capture_opts.default_options.cfilter, new_cfilter) != 0)) {
+ gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(filter_cm), new_cfilter);
}
}
if (global_capture_opts.default_options.cfilter && (strlen(global_capture_opts.default_options.cfilter) > 0)) {
- gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(filter_cm), global_capture_opts.default_options.cfilter);
+ /* If this is the current dfilter, don't put it in the list, as it'll be
+ added later. */
+ if (device.cfilter == NULL || strcmp(device.cfilter, global_capture_opts.default_options.cfilter) != 0) {
+ gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(filter_cm), global_capture_opts.default_options.cfilter);
+ }
}
if (device.cfilter && (strlen(device.cfilter) > 0)) {
gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(filter_cm), device.cfilter);
@@ -4505,6 +4513,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
gboolean if_present = TRUE;
GList *all_cfilter_list, *cf_entry;
window_geometry_t tl_geom;
+ const gchar *new_cfilter;
if (interfaces_dialog_window_present()) {
destroy_if_window();
@@ -4780,17 +4789,17 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
/* Create the capture filter combo box*/
all_filter_cm = gtk_combo_box_text_new_with_entry();
- all_cfilter_list = (GList *)g_object_get_data(G_OBJECT(cap_open_w), E_ALL_CFILTER_FL_KEY);
- g_object_set_data(G_OBJECT(cap_open_w), E_ALL_CFILTER_FL_KEY, all_cfilter_list);
g_object_set_data(G_OBJECT(cap_open_w), E_ALL_CFILTER_CM_KEY, all_filter_cm);
all_filter_te = gtk_bin_get_child(GTK_BIN(all_filter_cm));
colorize_filter_te_as_empty(all_filter_te);
g_signal_connect(all_filter_te, "changed", G_CALLBACK(capture_all_filter_check_syntax_cb), NULL);
g_signal_connect(all_filter_te, "destroy", G_CALLBACK(capture_filter_destroy_cb), NULL);
+ all_cfilter_list = recent_get_cfilter_list(NULL);
for (cf_entry = all_cfilter_list; cf_entry != NULL; cf_entry = g_list_next(cf_entry)) {
- if (cf_entry->data && (strlen((const char *)cf_entry->data) > 0)) {
- gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(all_filter_cm), (const gchar *)cf_entry->data);
+ new_cfilter = (const gchar *)cf_entry->data;
+ if (global_capture_opts.default_options.cfilter == NULL || strcmp(global_capture_opts.default_options.cfilter, new_cfilter) != 0) {
+ gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(all_filter_cm), new_cfilter);
}
}
if (global_capture_opts.default_options.cfilter && (strlen(global_capture_opts.default_options.cfilter) > 0)) {
@@ -5308,14 +5317,17 @@ capture_start_cb(GtkWidget *w _U_, gpointer d _U_)
collect_ifaces(&global_capture_opts);
if (capture_start(&global_capture_opts, &global_capture_session, main_window_update)) {
- /* The capture succeeded, which means the capture filter syntax is
- valid; add this capture filter to the recent capture filter list. */
+ /* The capture succeeded, which means the capture filters specified are
+ valid; add them to the recent capture filter lists for the interfaces. */
for (i = 0; i < global_capture_opts.ifaces->len; i++) {
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i);
if (interface_opts.cfilter) {
- cfilter_combo_add_recent(interface_opts.cfilter);
+ recent_add_cfilter(interface_opts.name, interface_opts.cfilter);
}
}
+ if (global_capture_opts.default_options.cfilter) {
+ recent_add_cfilter(NULL, global_capture_opts.default_options.cfilter);
+ }
}
}
diff --git a/ui/gtk/cfilter_combo_utils.c b/ui/gtk/cfilter_combo_utils.c
deleted file mode 100644
index 47cbd54b19..0000000000
--- a/ui/gtk/cfilter_combo_utils.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/* cfilter_combo_utils.c
- * Capture filter combo box routines
- *
- * $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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include "config.h"
-
-#include <stdio.h>
-#include <string.h>
-
-#include <gtk/gtk.h>
-
-#include "ui/recent.h"
-#include "ui/recent_utils.h"
-
-#include "ui/gtk/main.h"
-#include "ui/gtk/gtkglobals.h"
-#include "ui/gtk/cfilter_combo_utils.h"
-
-
-/* XXX: use a preference for this setting! */
-static guint cfilter_combo_max_recent = 20;
-
-static gboolean
-cfilter_combo_add(gchar *s) {
- GList *li;
- GList *fl = (GList*)g_object_get_data(G_OBJECT(top_level), E_CFILTER_FL_KEY);
-
- li = g_list_first(fl);
- while (li) {
- /* If the filter is already in the list, remove the old one and
- * append the new one at the latest position (at g_list_append() below) */
- if (li->data && strcmp(s, (char *)li->data) == 0) {
- fl = g_list_remove(fl, li->data);
- break;
- }
- li = li->next;
- }
- fl = g_list_append(fl, s);
- g_object_set_data(G_OBJECT(top_level), E_CFILTER_FL_KEY, fl);
- return TRUE;
-}
-
-
-/* write all non empty capture filters (until maximum count)
- * of the combo box GList to the user's recent file */
-void
- cfilter_combo_recent_write_all(FILE *rf) {
- GList *cfilter_list = (GList*)g_object_get_data(G_OBJECT(top_level), E_CFILTER_FL_KEY);
- GList *li;
- guint max_count = 0;
-
- /* write all non empty capture filter strings to the recent file (until max count) */
- li = g_list_first(cfilter_list);
- while (li && (max_count++ <= cfilter_combo_max_recent) ) {
- if (li->data && strlen((const char *)li->data)) {
- fprintf (rf, RECENT_KEY_CAPTURE_FILTER ": %s\n", (char *)li->data);
- }
- li = li->next;
- }
-}
-
-/* add a capture filter coming from the user's recent file to the cfilter combo box */
-gboolean
- cfilter_combo_add_recent(const gchar *s) {
- gchar *dupstr;
-
- if (s) {
- dupstr = g_strdup(s);
- if (!cfilter_combo_add(dupstr)) {
- g_free(dupstr);
- return FALSE;
- }
- }
- return TRUE;
-}
diff --git a/ui/gtk/cfilter_combo_utils.h b/ui/gtk/cfilter_combo_utils.h
index 37cd1636ac..e197175c39 100644
--- a/ui/gtk/cfilter_combo_utils.h
+++ b/ui/gtk/cfilter_combo_utils.h
@@ -30,8 +30,6 @@
*/
#define E_CFILTER_CM_KEY "capture_filter_combo"
-#define E_CFILTER_FL_KEY "capture_filter_list"
#define E_ALL_CFILTER_CM_KEY "capture_all_filter_combo"
-#define E_ALL_CFILTER_FL_KEY "capture_all_filter_list"
#endif /* __CFILTER_COMBO_UTILS_H__ */
diff --git a/ui/qt/display_filter_combo.cpp b/ui/qt/display_filter_combo.cpp
index ce46feb828..cf852faa33 100644
--- a/ui/qt/display_filter_combo.cpp
+++ b/ui/qt/display_filter_combo.cpp
@@ -121,22 +121,6 @@ extern "C" gboolean dfilter_combo_add_recent(const gchar *filter) {
}
-// xxx - Move to an as-yet-to-be-written capture filter module along with ::addRecentCapture and ::writeRecentCapture
-QList<QString> cfilters;
-
-extern "C" gboolean cfilter_combo_add_recent(const gchar *filter) {
- cfilters.append(filter);
- return TRUE;
-}
-
-extern "C" void cfilter_combo_recent_write_all(FILE *rf) {
- QString cfilter;
-
- foreach (cfilter, cfilters) {
- fprintf (rf, RECENT_KEY_CAPTURE_FILTER ": %s\n", cfilter.toUtf8().constData());
- }
-}
-
/*
* Editor modelines
*
diff --git a/ui/recent.c b/ui/recent.c
index c739397144..e5a14fcaad 100644
--- a/ui/recent.c
+++ b/ui/recent.c
@@ -283,6 +283,127 @@ window_geom_recent_write_all(FILE *rf)
g_hash_table_foreach(window_geom_hash, write_recent_geom, rf);
}
+/* Global list of recent capture filters. */
+static GList *recent_cfilter_list;
+
+/*
+ * Per-interface lists of recent capture filters; stored in a hash
+ * table indexed by interface name.
+ */
+static GHashTable *per_interface_cfilter_lists_hash;
+
+/* XXX: use a preference for this setting! */
+static guint cfilter_combo_max_recent = 20;
+
+/**
+ * Returns a list of recent capture filters.
+ *
+ * @param ifname interface name; NULL refers to the global list.
+ */
+GList *
+recent_get_cfilter_list(const gchar *ifname)
+{
+ if (ifname == NULL)
+ return recent_cfilter_list;
+ if (per_interface_cfilter_lists_hash == NULL) {
+ /* No such lists exist. */
+ return NULL;
+ }
+ return (GList *)g_hash_table_lookup(per_interface_cfilter_lists_hash, ifname);
+}
+
+/**
+ * Add a capture filter to the global recent capture filter list or
+ * the recent capture filter list for an interface.
+ *
+ * @param ifname interface name; NULL refers to the global list.
+ * @param s text of capture filter
+ */
+void
+recent_add_cfilter(const gchar *ifname, const gchar *s)
+{
+ GList *cfilter_list;
+ GList *li;
+ gchar *li_filter, *newfilter = NULL;
+
+ /* Don't add empty filters to the list. */
+ if (s[0] == '\0')
+ return;
+
+ if (ifname == NULL)
+ cfilter_list = recent_cfilter_list;
+ else {
+ if (per_interface_cfilter_lists_hash == NULL)
+ per_interface_cfilter_lists_hash = g_hash_table_new(g_str_hash, g_str_equal);
+ cfilter_list = (GList *)g_hash_table_lookup(per_interface_cfilter_lists_hash, ifname);
+ }
+
+ li = g_list_first(cfilter_list);
+ while (li) {
+ /* If the filter is already in the list, remove the old one and
+ * append the new one at the latest position (at g_list_append() below) */
+ li_filter = (char *)li->data;
+ if (strcmp(s, li_filter) == 0) {
+ /* No need to copy the string, we're just moving it. */
+ newfilter = li_filter;
+ recent_cfilter_list = g_list_remove(cfilter_list, li->data);
+ break;
+ }
+ li = li->next;
+ }
+ if (newfilter == NULL) {
+ /* The filter wasn't already in the list; make a copy to add. */
+ newfilter = g_strdup(s);
+ }
+ cfilter_list = g_list_append(cfilter_list, newfilter);
+
+ if (ifname == NULL)
+ recent_cfilter_list = cfilter_list;
+ else
+ g_hash_table_insert(per_interface_cfilter_lists_hash, g_strdup(ifname), cfilter_list);
+}
+
+static void
+cfilter_recent_write_all_list(FILE *rf, const gchar *ifname, GList *cfilter_list)
+{
+ guint max_count = 0;
+ GList *li;
+
+ /* write all non empty capture filter strings to the recent file (until max count) */
+ li = g_list_first(cfilter_list);
+ while (li && (max_count++ <= cfilter_combo_max_recent) ) {
+ if (li->data && strlen((const char *)li->data)) {
+ if (ifname == NULL)
+ fprintf (rf, RECENT_KEY_CAPTURE_FILTER ": %s\n", (char *)li->data);
+ else
+ fprintf (rf, RECENT_KEY_CAPTURE_FILTER ".%s: %s\n", ifname, (char *)li->data);
+ }
+ li = li->next;
+ }
+}
+
+static void
+cfilter_recent_write_all_hash_callback(gpointer key, gpointer value, gpointer user_data)
+{
+ cfilter_recent_write_all_list((FILE *)user_data, (const gchar *)key, (GList *)value);
+}
+
+/** Write all capture filter values to the recent file.
+ *
+ * @param rf recent file handle from caller
+ */
+static void
+cfilter_recent_write_all(FILE *rf)
+{
+ /* Write out the global list. */
+ cfilter_recent_write_all_list(rf, NULL, recent_cfilter_list);
+
+ /* Write out all the per-interface lists. */
+ if (per_interface_cfilter_lists_hash != NULL) {
+ g_hash_table_foreach(per_interface_cfilter_lists_hash, cfilter_recent_write_all_hash_callback, (gpointer)rf);
+ }
+}
+
/* Attempt to Write out "recent common" to the user's recent common file.
If we got an error report it with a dialog box and return FALSE,
otherwise return TRUE. */
@@ -333,7 +454,7 @@ write_recent(void)
"######## Recent capture filters (latest last), cannot be altered through command line ########\n"
"\n", rf);
- cfilter_combo_recent_write_all(rf);
+ cfilter_recent_write_all(rf);
fputs("\n"
"######## Recent display filters (latest last), cannot be altered through command line ########\n"
@@ -866,14 +987,17 @@ read_set_recent_pair_dynamic(gchar *key, const gchar *value,
return PREFS_SET_SYNTAX_ERR;
}
if (strcmp(key, RECENT_KEY_CAPTURE_FILE) == 0) {
- if(u3_active())
+ if (u3_active())
add_menu_recent_capture_file(u3_expand_device_path(value));
else
add_menu_recent_capture_file(value);
} else if (strcmp(key, RECENT_KEY_DISPLAY_FILTER) == 0) {
dfilter_combo_add_recent(value);
} else if (strcmp(key, RECENT_KEY_CAPTURE_FILTER) == 0) {
- cfilter_combo_add_recent(value);
+ recent_add_cfilter(NULL, value);
+ } else if (g_str_has_prefix(key, RECENT_KEY_CAPTURE_FILTER ".")) {
+ /* strrchr() can't fail - string has a prefix that ends with a "." */
+ recent_add_cfilter(strrchr(key, '.') + 1, value);
#ifdef HAVE_PCAP_REMOTE
} else if (strcmp(key, RECENT_KEY_REMOTE_HOST) == 0) {
capture_remote_combo_add_recent(value);
diff --git a/ui/recent.h b/ui/recent.h
index 0954e71b3b..374c4fbab7 100644
--- a/ui/recent.h
+++ b/ui/recent.h
@@ -182,6 +182,22 @@ extern void window_geom_save(const gchar *name, window_geometry_t *geom);
/* load the desired geometry for this window from the geometry hashtable */
extern gboolean window_geom_load(const gchar *name, window_geometry_t *geom);
+/**
+ * Returns a list of recent capture filters.
+ *
+ * @param ifname interface name; NULL refers to the global list.
+ */
+extern GList *recent_get_cfilter_list(const gchar *ifname);
+
+/**
+ * Add a capture filter to the global recent capture filter list or
+ * the recent capture filter list for an interface.
+ *
+ * @param ifname interface name; NULL refers to the global list.
+ * @param s text of capture filter
+ */
+extern void recent_add_cfilter(const gchar *ifname, const gchar *s);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/ui/recent_utils.h b/ui/recent_utils.h
index 4c5fbf1acf..684f27832f 100644
--- a/ui/recent_utils.h
+++ b/ui/recent_utils.h
@@ -39,12 +39,6 @@ extern void add_menu_recent_capture_file(const gchar *cf_name);
*/
extern void menu_recent_file_write_all(FILE *rf);
-/** Add a capture filter coming from the user's recent file to the cfilter combo box.
- *
- * @param s the filter string
- */
-extern gboolean cfilter_combo_add_recent(const gchar *s);
-
/** Write all non-empty capture filters (until maximum count)
* of the combo box GList to the user's recent file.
*