diff options
Diffstat (limited to 'epan')
-rw-r--r-- | epan/CMakeLists.txt | 2 | ||||
-rw-r--r-- | epan/Makefile.common | 4 | ||||
-rw-r--r-- | epan/plugin_if.c (renamed from epan/ext_menubar.c) | 89 | ||||
-rw-r--r-- | epan/plugin_if.h (renamed from epan/ext_menubar.h) | 42 |
4 files changed, 124 insertions, 13 deletions
diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt index aa37191ddc..36d141bf0d 100644 --- a/epan/CMakeLists.txt +++ b/epan/CMakeLists.txt @@ -1600,7 +1600,7 @@ set(LIBWIRESHARK_FILES except.c expert.c exported_pdu.c - ext_menubar.c + plugin_if.c filter_expressions.c follow.c frame_data.c diff --git a/epan/Makefile.common b/epan/Makefile.common index a8c3bb5ad1..fe81b1c7ea 100644 --- a/epan/Makefile.common +++ b/epan/Makefile.common @@ -51,7 +51,7 @@ LIBWIRESHARK_SRC = \ except.c \ expert.c \ exported_pdu.c \ - ext_menubar.c \ + plugin_if.c \ filter_expressions.c \ follow.c \ frame_data.c \ @@ -192,7 +192,7 @@ LIBWIRESHARK_INCLUDES = \ exceptions.h \ expert.h \ exported_pdu.h \ - ext_menubar.h \ + plugin_if.h \ filter_expressions.h \ follow.h \ frame_data.h \ diff --git a/epan/ext_menubar.c b/epan/plugin_if.c index 25501520c7..62244dd4fd 100644 --- a/epan/ext_menubar.c +++ b/epan/plugin_if.c @@ -1,9 +1,12 @@ -/* ext_menubar.c - * A menubar API for Wireshark dissectors +/* plugin_if.c + * An API for Wireshark plugins * * 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 + * function for the dissector or plugin. + * + * Also it implements additional methods, which allow plugins to interoperate + * with the main GUI. * * Wireshark - Network traffic analyzer * By Gerald Combs <gerald@wireshark.org> @@ -30,7 +33,7 @@ #include <epan/epan.h> #include <epan/proto.h> -#include "ext_menubar.h" +#include "plugin_if.h" static GList * menubar_entries = NULL; static GList * menubar_menunames = NULL; @@ -158,6 +161,84 @@ extern void ext_menubar_add_separator(ext_menu_t *parent) ext_menubar_add_generic_entry ( EXT_MENUBAR_SEPARATOR, parent, g_strdup("-"), NULL, NULL, NULL ); } +/* Implementation of GUI callback methods follows. + * This is a necessity, as using modern UI systems, gui interfaces often operate + * in different threads then the calling application. Even more so, if the calling + * application is implemented using a separate plugin. Therefore the external menubars + * cannot call gui functionality directly, the gui has to perform the function within + * it' own scope. */ + +static GHashTable * plugin_if_callback_functions; + +static void +plugin_if_init_hashtable(void) +{ + if ( plugin_if_callback_functions == 0 ) + plugin_if_callback_functions = g_hash_table_new(g_int_hash, g_int_equal); +} + +static void plugin_if_call_gui_cb(plugin_if_callback_t actionType, GHashTable * dataSet) +{ + plugin_if_gui_cb action; + gint * key = 0; + + key = (gint *)g_malloc0(sizeof(gint)); + *key = (gint) actionType; + + plugin_if_init_hashtable(); + + if ( g_hash_table_size(plugin_if_callback_functions) != 0 ) + { + if ( g_hash_table_contains(plugin_if_callback_functions, key) ) + { + action = (plugin_if_gui_cb)g_hash_table_lookup(plugin_if_callback_functions, key); + if ( action != NULL ) + action(dataSet); + } + } +} + +extern void plugin_if_apply_filter(const char * filter_string, gboolean force) +{ + plugin_if_callback_t actionType; + GHashTable * dataSet = NULL; + + actionType = ( force == TRUE ) ? PLUGIN_IF_FILTER_ACTION_APPLY : PLUGIN_IF_FILTER_ACTION_PREPARE; + dataSet = g_hash_table_new(g_str_hash, g_str_equal); + + g_hash_table_insert( dataSet, g_strdup("action_type"), (gpointer) &actionType ); + g_hash_table_insert( dataSet, g_strdup("filter_string"), g_strdup(filter_string) ); + g_hash_table_insert( dataSet, g_strdup("force"), (gpointer) &force ); + + plugin_if_call_gui_cb(actionType, dataSet); +} + +extern void plugin_if_save_preference(const char * pref_module, const char * pref_key, const char * pref_value) +{ + GHashTable * dataSet = NULL; + + dataSet = g_hash_table_new(g_str_hash, g_str_equal); + + g_hash_table_insert( dataSet, g_strdup("pref_module"), g_strdup(pref_module) ); + g_hash_table_insert( dataSet, g_strdup("pref_key"), g_strdup(pref_key) ); + g_hash_table_insert( dataSet, g_strdup("pref_value"), g_strdup(pref_value) ); + + plugin_if_call_gui_cb(PLUGIN_IF_PREFERENCE_SAVE, dataSet); +} + +extern void plugin_if_register_gui_cb(plugin_if_callback_t actionType, plugin_if_gui_cb callback) +{ + gint * key = 0; + + key = (gint *)g_malloc0(sizeof(gint)); + *key = actionType; + + plugin_if_init_hashtable(); + + if ( ! g_hash_table_contains(plugin_if_callback_functions, key ) ) + g_hash_table_insert(plugin_if_callback_functions, key, callback); +} + /* * Editor modelines * diff --git a/epan/ext_menubar.h b/epan/plugin_if.h index acffa8f2e8..df9ea6e846 100644 --- a/epan/ext_menubar.h +++ b/epan/plugin_if.h @@ -1,9 +1,12 @@ -/* ext_menubar.h - * A menubar API for Wireshark dissectors +/* plugin_if.h + * An API for Wireshark plugins * * 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 + * function for the dissector or plugin. + * + * Also it implements additional methods, which allow plugins to interoperate + * with the main GUI. * * Wireshark - Network traffic analyzer * By Gerald Combs <gerald@wireshark.org> @@ -23,8 +26,8 @@ * 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_ +#ifndef EPAN_PLUGIN_IF_H +#define EPAN_PLUGIN_IF_H #include <config.h> @@ -146,6 +149,33 @@ WS_DLL_PUBLIC void ext_menubar_add_separator(ext_menu_t *parent_menu); WS_DLL_PUBLIC void ext_menubar_add_website(ext_menu_t * parent, const gchar *label, const gchar *tooltip, const gchar *url); + +/* + * Enumeration of possible actions, which are registered in GUI interfaces + */ +typedef enum +{ + /* Applies a given string as filter */ + PLUGIN_IF_FILTER_ACTION_APPLY, + + /* Prepares the given string as filter */ + PLUGIN_IF_FILTER_ACTION_PREPARE, + + /* Saves a preference entry */ + PLUGIN_IF_PREFERENCE_SAVE +} plugin_if_callback_t; + + +typedef void (*plugin_if_gui_cb)(gconstpointer user_data); + +WS_DLL_PUBLIC void plugin_if_register_gui_cb(plugin_if_callback_t actionType, plugin_if_gui_cb callback); + +/* Applies the given filter string as display filter */ +WS_DLL_PUBLIC void plugin_if_apply_filter(const char * filter_string, gboolean force); + +/* Saves the given preference to the main preference storage */ +WS_DLL_PUBLIC void plugin_if_save_preference(const char * pref_module, const char * pref_key, const char * pref_value); + /* Private Method for retrieving the menubar entries * * Is only to be used by the UI interfaces to retrieve the menu entries @@ -156,7 +186,7 @@ WS_DLL_PUBLIC GList * ext_menubar_get_entries(void); } #endif /* __cplusplus */ -#endif /* EPAN_EXT_MENUBAR_H_ */ +#endif /* EPAN_PLUGIN_IF_H */ /* * Editor modelines |