aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorRoland Knall <roland.knall@br-automation.com>2015-03-30 16:10:01 +0200
committerAnders Broman <a.broman58@gmail.com>2015-04-14 04:00:39 +0000
commiteeed4d1121f122aa5579153872193b9a91d8ad52 (patch)
tree671f1f43ba913c80270ee0cc54c7a536009c0cd9 /epan
parent035d7412892574fcdf6953110cc4e6384602062f (diff)
UI: Implementing menus for plugins
Plugins may utilize the tap interface to provide special tools or analysis options, not otherwise available in Wireshark, or perhaps not allowed to be distributed freely. Up until now, those tools either had to start automatically, or could not be started at all, or had to be started separately. It should be possible, that those tools may be started using a menu entry directly from Wireshark. This interface tries to achieve exactly that. This interface uses a clean interface, which can be implemented in any plugin or dissector. Documentation for this has been added to README.plugins. Separators are only supported for now in the Qt interface, but URLs can now be added as a simple item, and the UI will use the same methods used for other URL calls to open them. Change-Id: I170107dafb66f6badaa864d05a9091e5cbbf52c2 Reviewed-on: https://code.wireshark.org/review/7865 Reviewed-by: Roland Knall <rknall@gmail.com> Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan')
-rw-r--r--epan/CMakeLists.txt1
-rw-r--r--epan/Makefile.common2
-rw-r--r--epan/ext_menubar.c186
-rw-r--r--epan/ext_menubar.h165
4 files changed, 354 insertions, 0 deletions
diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt
index d745ec4d0f..0e12b74375 100644
--- a/epan/CMakeLists.txt
+++ b/epan/CMakeLists.txt
@@ -1593,6 +1593,7 @@ set(LIBWIRESHARK_FILES
except.c
expert.c
exported_pdu.c
+ ext_menubar.c
filter_expressions.c
follow.c
frame_data.c
diff --git a/epan/Makefile.common b/epan/Makefile.common
index 7a57270ba7..de70f8f8f5 100644
--- a/epan/Makefile.common
+++ b/epan/Makefile.common
@@ -51,6 +51,7 @@ LIBWIRESHARK_SRC = \
except.c \
expert.c \
exported_pdu.c \
+ ext_menubar.c \
filter_expressions.c \
follow.c \
frame_data.c \
@@ -190,6 +191,7 @@ LIBWIRESHARK_INCLUDES = \
exceptions.h \
expert.h \
exported_pdu.h \
+ ext_menubar.h \
filter_expressions.h \
follow.h \
frame_data.h \
diff --git a/epan/ext_menubar.c b/epan/ext_menubar.c
new file mode 100644
index 0000000000..e716b4d58b
--- /dev/null
+++ b/epan/ext_menubar.c
@@ -0,0 +1,186 @@
+/* ext_menubar.c
+ * A menubar API for Wireshark dissectors
+ *
+ * This enables wireshark dissectors, especially those implemented by plugins
+ * to register menubar entries, which then will call a pre-defined callback
+ * function for the dissector or plugin
+ *
+ * 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 <glib.h>
+#include <epan/epan.h>
+#include <epan/proto.h>
+
+#include "ext_menubar.h"
+
+static GList * menubar_entries = NULL;
+static GList * menubar_menunames = NULL;
+
+extern GList * ext_menubar_get_entries(void)
+{
+ return menubar_entries;
+}
+
+extern ext_menu_t * ext_menubar_register_menu(int proto_id, const gchar * menulabel,
+ gboolean is_plugin)
+{
+ ext_menubar_t * entry = NULL;
+ gchar * name = NULL;
+
+ /* A name for the entry must be provided */
+ g_assert(menulabel != NULL && strlen ( menulabel ) > 0 );
+
+ /* A protocol must exist for the given id */
+ g_assert(find_protocol_by_id(proto_id) != NULL);
+
+ /* Create unique name, which is used by GTK to provide the menu */
+ name = g_strconcat(proto_get_protocol_filter_name(proto_id), "Menu", NULL);
+
+ /* For now, a protocol may only register one main menu */
+ g_assert(g_list_find(menubar_menunames, name) == NULL);
+
+ entry = (ext_menubar_t *)g_malloc0(sizeof(ext_menubar_t));
+ entry->type = EXT_MENUBAR_MENU;
+ entry->proto = proto_id;
+ entry->is_plugin = is_plugin;
+
+ /* Create a name for this submenu */
+ entry->name = g_strdup(name);
+ entry->label = g_strdup(menulabel);
+ entry->tooltip = g_strdup(menulabel);
+
+ entry->submenu_cnt = 0;
+ entry->item_cnt = 0;
+
+ menubar_entries = g_list_append(menubar_entries, entry);
+ menubar_menunames = g_list_append(menubar_menunames, name);
+ g_free(name);
+
+ return entry;
+}
+
+extern ext_menu_t * ext_menubar_add_submenu(ext_menu_t * parent, const gchar *menulabel)
+{
+ ext_menubar_t * entry = NULL;
+ gchar * name = NULL;
+
+ /* A name for the entry must be provided */
+ g_assert(menulabel != NULL && strlen ( menulabel ) > 0 );
+
+ /* Parent must be a valid parent */
+ g_assert(parent != NULL && parent->type == EXT_MENUBAR_MENU);
+
+ parent->submenu_cnt++;
+
+ /* Create unique name, which is used by GTK to provide the menu */
+ name = (gchar *)g_malloc0(strlen(parent->name) + 4);
+ g_snprintf(name, strlen(parent->name) + 4, "%sS%02d",
+ parent->name, parent->submenu_cnt );
+
+ /* Create submenu entry */
+ entry = (ext_menubar_t *)g_malloc0(sizeof(ext_menubar_t));
+ entry->type = EXT_MENUBAR_MENU;
+ entry->parent = parent;
+ /* Just a convenience */
+ entry->proto = parent->proto;
+ entry->is_plugin = parent->is_plugin;
+ entry->name = g_strdup(name);
+ entry->label = g_strdup(menulabel);
+ entry->tooltip = g_strdup(menulabel);
+
+ parent->children = g_list_append(parent->children, entry);
+ g_free(name);
+
+ return entry;
+}
+
+static void ext_menubar_add_generic_entry (
+ ext_menubar_entry_t type, ext_menu_t * parent, const gchar * label,
+ const gchar * tooltip, ext_menubar_action_cb callback, gpointer user_data )
+{
+ ext_menubar_t * entry = NULL;
+ gchar * name = NULL;
+
+ /* A valid parent must exist */
+ g_assert(parent != NULL && parent->type == EXT_MENUBAR_MENU);
+ /* A label for the entry must be provided */
+ g_assert(label != NULL && strlen ( label ) > 0 );
+
+ parent->item_cnt++;
+
+ /* Create unique name, which is used by GTK to provide the menu */
+ name = (gchar *)g_malloc0(strlen(parent->name) + 4);
+ g_snprintf(name, strlen(parent->name) + 4, "%sI%02d",
+ parent->name, parent->item_cnt );
+
+ /* Create menu entry */
+ entry = (ext_menubar_t*)g_malloc0(sizeof(ext_menubar_t));
+ entry->type = type;
+ entry->name = g_strdup(name);
+ entry->label = g_strdup(label);
+
+ if ( tooltip != NULL && strlen(tooltip) > 0 )
+ entry->tooltip = g_strdup(tooltip);
+
+ entry->callback = callback;
+ entry->user_data = user_data;
+
+ parent->children = g_list_append(parent->children, entry);
+
+ g_free(name);
+}
+
+extern void ext_menubar_add_entry(ext_menu_t * parent, const gchar *label,
+ const gchar *tooltip, ext_menubar_action_cb callback, gpointer user_data)
+{
+ /* A callback must be provided */
+ g_assert(callback != NULL);
+
+ ext_menubar_add_generic_entry ( EXT_MENUBAR_ITEM, parent, label, tooltip, callback, user_data );
+}
+
+extern void ext_menubar_add_website(ext_menu_t * parent, const gchar *label,
+ const gchar *tooltip, const gchar *url)
+{
+ /* An url for the entry must be provided */
+ g_assert(url != NULL && strlen ( url ) > 0 );
+
+ ext_menubar_add_generic_entry ( EXT_MENUBAR_URL, parent, label, tooltip, NULL, (gpointer) g_strdup(url) );
+}
+
+extern void ext_menubar_add_separator(ext_menu_t *parent)
+{
+ ext_menubar_add_generic_entry ( EXT_MENUBAR_SEPARATOR, parent, g_strdup("-"), NULL, NULL, NULL );
+}
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
diff --git a/epan/ext_menubar.h b/epan/ext_menubar.h
new file mode 100644
index 0000000000..c812896d28
--- /dev/null
+++ b/epan/ext_menubar.h
@@ -0,0 +1,165 @@
+/* ext_menubar.h
+ * A menubar API for Wireshark dissectors
+ *
+ * This enables wireshark dissectors, especially those implemented by plugins
+ * to register menubar entries, which then will call a pre-defined callback
+ * function for the dissector or plugin
+ *
+ * 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.
+ */
+#ifndef EPAN_EXT_MENUBAR_H_
+#define EPAN_EXT_MENUBAR_H_
+
+#include "config.h"
+
+#include "ws_symbol_export.h"
+
+#include <glib.h>
+#include <epan/epan.h>
+#include <epan/packet_info.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#define EXT_MENUBAR_MAX_DEPTH 5
+
+/* menubar callback */
+typedef void (*ext_menubar_action_cb)(gpointer user_data);
+
+typedef enum
+{
+ EXT_MENUBAR_MENU,
+ EXT_MENUBAR_ITEM,
+ EXT_MENUBAR_SEPARATOR,
+ EXT_MENUBAR_URL
+} ext_menubar_entry_t;
+
+typedef struct _ext_menubar_t ext_menubar_t;
+typedef ext_menubar_t ext_menu_t;
+
+struct _ext_menubar_t
+{
+ ext_menubar_entry_t type;
+ ext_menu_t * parent;
+ int proto;
+ GList * children;
+ guint submenu_cnt;
+ guint item_cnt;
+
+ gchar * name;
+ gchar * label;
+
+ gchar * tooltip;
+ gboolean is_plugin;
+ gpointer user_data;
+ ext_menubar_action_cb callback;
+
+
+};
+
+/* Registers a new main menu.
+ *
+ * This will register a new main menu entry, underneath all other menu entries will
+ * be sorted
+ *
+ * @param proto_id the proto item for the protocol this menu entry belongs too
+ * @param name the entry name (the internal used one) for the menu item
+ * @param menulabel the entry label (the displayed name) for the menu item
+ * @param is_plugin must be set to TRUE for plugin registration
+ */
+WS_DLL_PUBLIC ext_menu_t * ext_menubar_register_menu(
+ int proto_id, const gchar * menulabel, gboolean is_plugin);
+
+/* Registers a new main menu.
+ *
+ * This will register a new sub menu entry, underneath the parent menu
+ *
+ * @param parent the parent menu for this submenu
+ * @param name the entry name (the internal used one) for the menu item
+ * @param menulabel the entry label (the displayed name) for the menu item
+ */
+WS_DLL_PUBLIC ext_menu_t * ext_menubar_add_submenu(
+ ext_menu_t * parent, const gchar *menulabel);
+
+/* Registers a new menubar entry.
+ *
+ * This registers a new menubar entry, which will have the given name, and
+ * call the provided callback on activation
+ *
+ * @param parent_menu the parent menu for this entry
+ * @param name the entry name (the internal used one) for the menu item
+ * @param label the entry label (the displayed name) for the menu item
+ * @param tooltip a tooltip to be displayed on mouse-over
+ * @param callback the action which will be invoked after click on the menu item
+ */
+WS_DLL_PUBLIC void ext_menubar_add_entry(
+ ext_menu_t * parent_menu,
+ const gchar *label,
+ const gchar *tooltip,
+ ext_menubar_action_cb callback,
+ gpointer user_data);
+
+/* Registers a new separator entry.
+ *
+ * @note This will not work using the legacy GTK interface, due to
+ * restrictions on how separators are handled in the menu
+ *
+ * @param parent_menu the parent menu for this entry
+ */
+WS_DLL_PUBLIC void ext_menubar_add_separator(ext_menu_t *parent_menu);
+
+/* Registers a entry for a website call
+ *
+ * This registers a new menubar entry, which will call the given website, using
+ * the predefined webbrowser
+ *
+ * @param parent_menu the parent menu for this entry
+ * @param name the entry name (the internal used one) for the menu item
+ * @param label the entry label (the displayed name) for the menu item
+ * @param tooltip a tooltip to be displayed on mouse-over
+ * @param url the url for the website
+ */
+WS_DLL_PUBLIC void ext_menubar_add_website(ext_menu_t * parent, const gchar *label,
+ const gchar *tooltip, const gchar *url);
+
+/* Private Method for retrieving the menubar entries
+ *
+ * Is only to be used by the UI interfaces to retrieve the menu entries
+ */
+WS_DLL_PUBLIC GList * ext_menubar_get_entries(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* EPAN_EXT_MENUBAR_H_ */
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */