summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorRoland Knall <roland.knall@br-automation.com>2015-06-05 11:19:37 +0200
committerAnders Broman <a.broman58@gmail.com>2015-06-25 16:23:08 +0000
commitacc581081e84c93e878a678fbb3655aba253607a (patch)
tree10ad9f0c0195475d01f42d64509e0c6ef53abb79 /ui
parentd4aa1a1c24e984339806c4ddb000ea9f9b352659 (diff)
downloadwireshark-acc581081e84c93e878a678fbb3655aba253607a.tar.gz
Plugin Interface: Add GUI callbacks
Rename ext_menubar to a more appropriate plugin_if. External menus can be implemented by plugins to present additional menus for deep-packet analysis. One side-effect of such menus being implemented as plugins is, that they are being executed in different threads and therefore can only use limited access to the main GUI. Also, there is no safe cross-gui (GTK and Qt) way for many features. This patch implements a first functionality, by which a plugin implemented using ext_menubar can apply a display filter to the main view. For now the implementation supports filtering, as well as saving a preference. Change-Id: Iffe4caa954bbeb8ce356352de4dae348a50efba9 Reviewed-on: https://code.wireshark.org/review/8773 Reviewed-by: Roland Knall <rknall@gmail.com> Petri-Dish: Anders Broman <a.broman58@gmail.com> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui')
-rw-r--r--ui/gtk/main_filter_toolbar.c24
-rw-r--r--ui/gtk/main_menubar.c2
-rw-r--r--ui/gtk/packet_list.c24
-rw-r--r--ui/preference_utils.c42
-rw-r--r--ui/preference_utils.h10
-rw-r--r--ui/qt/main_window.cpp44
-rw-r--r--ui/qt/main_window.h2
7 files changed, 145 insertions, 3 deletions
diff --git a/ui/gtk/main_filter_toolbar.c b/ui/gtk/main_filter_toolbar.c
index f47e7819dc..eed3ee3cc2 100644
--- a/ui/gtk/main_filter_toolbar.c
+++ b/ui/gtk/main_filter_toolbar.c
@@ -39,6 +39,7 @@
#include "filter_autocomplete.h"
#include "epan/prefs.h"
+#include "epan/plugin_if.h"
#include "keys.h"
#include "gtkglobals.h"
@@ -109,6 +110,26 @@ filter_save_cb(GtkWidget *w _U_, GtkWindow *parent_w)
filter_expression_save_dlg(parent_w);
}
+static void
+plugin_if_filter_apply(gconstpointer filter_text)
+{
+ /* code is derived from voip_calls_dlg.c::voip_calls_on_filter */
+
+ int pos = 0;
+ size_t filter_length;
+ size_t max_filter_length = 2048;
+ gchar *filter_string;
+
+ if ( main_display_filter_widget != 0 )
+ {
+ filter_string = g_strndup((const char *)filter_text, max_filter_length);
+ filter_length = strlen(filter_string);
+ pos = (int)filter_length;
+
+ if ( filter_length < max_filter_length )
+ gtk_editable_insert_text(GTK_EDITABLE(main_display_filter_widget), filter_string, -1, &pos);
+ }
+}
GtkWidget *
filter_toolbar_new(void)
@@ -279,6 +300,9 @@ filter_toolbar_new(void)
/* make current preferences effective */
toolbar_redraw_all();
+ plugin_if_register_gui_cb(PLUGIN_IF_FILTER_ACTION_APPLY, plugin_if_filter_apply );
+ plugin_if_register_gui_cb(PLUGIN_IF_FILTER_ACTION_PREPARE, plugin_if_filter_apply );
+
return filter_tb;
}
diff --git a/ui/gtk/main_menubar.c b/ui/gtk/main_menubar.c
index b4c24d986a..50292d049e 100644
--- a/ui/gtk/main_menubar.c
+++ b/ui/gtk/main_menubar.c
@@ -36,7 +36,7 @@
#include <epan/epan_dissect.h>
#include <epan/column.h>
#include <epan/stats_tree_priv.h>
-#include <epan/ext_menubar.h>
+#include <epan/plugin_if.h>
#include "globals.h"
#include "color_filters.h"
diff --git a/ui/gtk/packet_list.c b/ui/gtk/packet_list.c
index f9a4f298e7..57ab4f95bb 100644
--- a/ui/gtk/packet_list.c
+++ b/ui/gtk/packet_list.c
@@ -34,6 +34,7 @@
#include <epan/packet.h>
#include <epan/column.h>
#include <epan/strutil.h>
+#include <epan/plugin_if.h>
#include "ui/main_statusbar.h"
#include "ui/packet_list_utils.h"
@@ -91,6 +92,7 @@ static void show_cell_data_func(GtkTreeViewColumn *col,
static gint row_number_from_iter(GtkTreeIter *iter);
static void scroll_to_current(void);
static gboolean query_packet_list_tooltip_cb(GtkWidget *widget, gint x, gint y, gboolean keyboard_tip, GtkTooltip *tooltip, gpointer data _U_);
+static void plugin_if_pktlist_preference(gconstpointer user_data);
GtkWidget *
packet_list_create(void)
@@ -105,6 +107,8 @@ packet_list_create(void)
g_object_set_data(G_OBJECT(popup_menu_object), E_MPACKET_LIST_KEY, view);
+ plugin_if_register_gui_cb(PLUGIN_IF_PREFERENCE_SAVE, plugin_if_pktlist_preference);
+
return scrollwin;
}
@@ -1730,6 +1734,26 @@ query_packet_list_tooltip_cb(GtkWidget *widget, gint x, gint y, gboolean keyboar
return result;
}
+void plugin_if_pktlist_preference(gconstpointer user_data)
+{
+ if ( packetlist != NULL && user_data != NULL )
+ {
+ GHashTable * dataSet = (GHashTable *) user_data;
+ if ( g_hash_table_contains(dataSet, "pref_module" ) &&
+ g_hash_table_contains(dataSet, "pref_value" ) &&
+ g_hash_table_contains(dataSet, "pref_value" ) )
+ {
+ const char * module_name = (const char *)g_hash_table_lookup(dataSet, "pref_module");
+ const char * pref_name = (const char *)g_hash_table_lookup(dataSet, "pref_key");
+ const char * pref_value = (const char *)g_hash_table_lookup(dataSet, "pref_value");
+
+ if ( prefs_store_ext(module_name, pref_name, pref_value) )
+ packet_list_recreate();
+
+ }
+ }
+}
+
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
diff --git a/ui/preference_utils.c b/ui/preference_utils.c
index 1e358bd7d0..0f80ef6742 100644
--- a/ui/preference_utils.c
+++ b/ui/preference_utils.c
@@ -273,6 +273,48 @@ prefs_main_write(void)
}
}
+gboolean
+prefs_store_ext(const char * module_name, const char *pref_name, const char *pref_value)
+{
+ module_t * module = NULL;
+ pref_t * pref = NULL;
+ gboolean pref_changed = TRUE;
+
+ if ( ! prefs_is_registered_protocol(module_name))
+ return FALSE;
+
+ module = prefs_find_module(module_name);
+ if ( ! module )
+ return FALSE;
+
+ pref = prefs_find_preference(module, pref_name);
+
+ if (!pref)
+ return FALSE;
+
+ if ( pref->type == PREF_STRING )
+ {
+ g_free((void *)pref->stashed_val.string);
+ pref->stashed_val.string = (gchar *) g_strdup(pref_value);
+ /* unstash - taken from preferences_util */
+ if (strcmp(*pref->varp.string, pref->stashed_val.string) != 0)
+ {
+ pref_changed = TRUE;
+ g_free((void *)*pref->varp.string);
+ *pref->varp.string = g_strdup(pref->stashed_val.string);
+ }
+ }
+
+ if ( pref_changed )
+ {
+ prefs_main_write();
+ prefs_apply_all();
+ prefs_to_capture_opts();
+ }
+
+ return TRUE;
+}
+
gint
column_prefs_add_custom(gint fmt, const gchar *title, const gchar *custom_field, gint custom_occurrence)
{
diff --git a/ui/preference_utils.h b/ui/preference_utils.h
index 882555d70a..a0b345d043 100644
--- a/ui/preference_utils.h
+++ b/ui/preference_utils.h
@@ -80,6 +80,16 @@ extern void prefs_to_capture_opts(void);
*/
extern void prefs_main_write(void);
+/** Convenient function for plugin_if
+ *
+ * @param module the module for the preference
+ * @param key the key for the preference
+ * @param value the new value as string for the preference
+ *
+ * @return true if the value has been stored successfully
+ */
+extern gboolean prefs_store_ext(const char * module, const char * key, const char * value);
+
/** Add a custom column.
*
* @param fmt column format
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp
index abae150c71..35e110c39b 100644
--- a/ui/qt/main_window.cpp
+++ b/ui/qt/main_window.cpp
@@ -27,7 +27,7 @@
#include <wsutil/filesystem.h>
#include <epan/prefs.h>
#include <epan/stats_tree_priv.h>
-#include <epan/ext_menubar.h>
+#include <epan/plugin_if.h>
#ifdef HAVE_LIBPCAP
#include "ui/capture.h"
@@ -42,6 +42,7 @@
#include "ui/main_statusbar.h"
#include "ui/recent.h"
#include "ui/util.h"
+#include "ui/preference_utils.h"
#include "byte_view_tab.h"
#include "display_filter_edit.h"
@@ -83,6 +84,42 @@ void pipe_input_set_handler(gint source, gpointer user_data, ws_process_id *chil
gbl_cur_main_window_->setPipeInputHandler(source, user_data, child_process, input_cb);
}
+void plugin_if_mainwindow_apply_filter(gconstpointer user_data)
+{
+ if ( gbl_cur_main_window_ != NULL && user_data != NULL )
+ {
+ GHashTable * dataSet = (GHashTable *) user_data;
+
+ if ( g_hash_table_contains(dataSet, "filter_string" ) )
+ {
+ QString filter((const char *)g_hash_table_lookup(dataSet, "filter_string"));
+ gbl_cur_main_window_->filterPackets(filter);
+ }
+ }
+}
+
+void plugin_if_mainwindow_preference(gconstpointer user_data)
+{
+ if ( gbl_cur_main_window_ != NULL && user_data != NULL )
+ {
+ GHashTable * dataSet = (GHashTable *) user_data;
+ if ( g_hash_table_contains(dataSet, "pref_module" ) &&
+ g_hash_table_contains(dataSet, "pref_value" ) &&
+ g_hash_table_contains(dataSet, "pref_value" ) )
+ {
+ const char * module_name = (const char *)g_hash_table_lookup(dataSet, "pref_module");
+ const char * pref_name = (const char *)g_hash_table_lookup(dataSet, "pref_key");
+ const char * pref_value = (const char *)g_hash_table_lookup(dataSet, "pref_value");
+
+ if ( prefs_store_ext(module_name, pref_name, pref_value) )
+ {
+ wsApp->emitAppSignal(WiresharkApplication::PacketDissectionChanged);
+ wsApp->emitAppSignal(WiresharkApplication::PreferencesChanged);
+ }
+ }
+ }
+}
+
gpointer
simple_dialog(ESD_TYPE_E type, gint btn_mask, const gchar *msg_format, ...)
{
@@ -479,6 +516,11 @@ MainWindow::MainWindow(QWidget *parent) :
this->main_welcome_->getInterfaceTree(), SLOT(interfaceListChanged()));
#endif
+ /* Create plugin_if hooks */
+ plugin_if_register_gui_cb(PLUGIN_IF_FILTER_ACTION_APPLY, plugin_if_mainwindow_apply_filter );
+ plugin_if_register_gui_cb(PLUGIN_IF_FILTER_ACTION_PREPARE, plugin_if_mainwindow_apply_filter );
+ plugin_if_register_gui_cb(PLUGIN_IF_PREFERENCE_SAVE, plugin_if_mainwindow_preference);
+
main_ui_->mainStack->setCurrentWidget(main_welcome_);
}
diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h
index 220bc63ffe..dbb85847aa 100644
--- a/ui/qt/main_window.h
+++ b/ui/qt/main_window.h
@@ -33,7 +33,7 @@
#include "ui/ui_util.h"
#include <epan/prefs.h>
-#include <epan/ext_menubar.h>
+#include <epan/plugin_if.h>
#ifdef HAVE_LIBPCAP
#include "capture_opts.h"