diff --git a/debian/libwireshark0.symbols b/debian/libwireshark0.symbols index 2fb16404c6..2665dcbaba 100644 --- a/debian/libwireshark0.symbols +++ b/debian/libwireshark0.symbols @@ -998,6 +998,8 @@ libwireshark.so.0 libwireshark0 #MINVER# p_set_proto_depth@Base 3.3.0 parse_key_string@Base 1.9.1 plugin_if_apply_filter@Base 1.99.8 + plugin_if_get_capture_file@Base 3.3.0 + plugin_if_get_frame_data@Base 3.3.0 plugin_if_get_ws_info@Base 2.1.0 plugin_if_goto_frame@Base 2.0.0 plugin_if_register_gui_cb@Base 1.99.8 diff --git a/epan/plugin_if.c b/epan/plugin_if.c index c8b45a44ae..821053be6d 100644 --- a/epan/plugin_if.c +++ b/epan/plugin_if.c @@ -575,6 +575,40 @@ extern void plugin_if_get_ws_info(ws_info_t **ws_info_ptr) *ws_info_ptr = &ws_info; } +extern void* plugin_if_get_frame_data(plugin_if_frame_data_cb extract_cb, void* user_data) { + GHashTable* dataSet = NULL; + void* ret_value = NULL; + + dataSet = g_hash_table_new(g_str_hash, g_str_equal); + + g_hash_table_insert(dataSet, g_strdup("extract_cb"), extract_cb); + g_hash_table_insert(dataSet, g_strdup("user_data"), user_data); + g_hash_table_insert(dataSet, g_strdup("ret_value_ptr"), &ret_value); + + plugin_if_call_gui_cb(PLUGIN_IF_GET_FRAME_DATA, dataSet); + + g_hash_table_destroy(dataSet); + + return ret_value; +} + +extern void* plugin_if_get_capture_file(plugin_if_capture_file_cb extract_cb, void* user_data) { + GHashTable* dataSet = NULL; + void* ret_value = NULL; + + dataSet = g_hash_table_new(g_str_hash, g_str_equal); + + g_hash_table_insert(dataSet, g_strdup("extract_cb"), extract_cb); + g_hash_table_insert(dataSet, g_strdup("user_data"), user_data); + g_hash_table_insert(dataSet, g_strdup("ret_value_ptr"), &ret_value); + + plugin_if_call_gui_cb(PLUGIN_IF_GET_CAPTURE_FILE, dataSet); + + g_hash_table_destroy(dataSet); + + return ret_value; +} + extern void plugin_if_register_gui_cb(plugin_if_callback_t actionType, plugin_if_gui_cb callback) { plugin_if_init_hashtable(); diff --git a/epan/plugin_if.h b/epan/plugin_if.h index 21e23f5396..7791c66d15 100644 --- a/epan/plugin_if.h +++ b/epan/plugin_if.h @@ -382,6 +382,12 @@ typedef enum /* Gets status information about the currently loaded capture file */ PLUGIN_IF_GET_WS_INFO, + /* Gets information from frame_data for current packet */ + PLUGIN_IF_GET_FRAME_DATA, + + /* Gets information from capture_file */ + PLUGIN_IF_GET_CAPTURE_FILE, + /* Remove toolbar */ PLUGIN_IF_REMOVE_TOOLBAR @@ -404,6 +410,14 @@ WS_DLL_PUBLIC void plugin_if_goto_frame(guint32 framenr); /* Takes a snapshot of status information from Wireshark */ WS_DLL_PUBLIC void plugin_if_get_ws_info(ws_info_t ** ws_info); +typedef void* (*plugin_if_frame_data_cb)(frame_data*, void*); +/* Gets frame_data for current packet, data are extracted by extract_cb */ +WS_DLL_PUBLIC void* plugin_if_get_frame_data(plugin_if_frame_data_cb extract_cb, void *user_data); + +typedef void* (*plugin_if_capture_file_cb)(capture_file*, void*); +/* Gets capture_file, data are extracted by extract_cb */ +WS_DLL_PUBLIC void* plugin_if_get_capture_file(plugin_if_capture_file_cb extract_cb, void* user_data); + /* Private Method for retrieving the menubar entries * * Is only to be used by the UI interfaces to retrieve the menu entries diff --git a/plugins/epan/pluginifdemo/pluginifdemo.c b/plugins/epan/pluginifdemo/pluginifdemo.c index 5cd01f6dbe..1290783be9 100644 --- a/plugins/epan/pluginifdemo/pluginifdemo.c +++ b/plugins/epan/pluginifdemo/pluginifdemo.c @@ -85,6 +85,14 @@ proto_register_pluginifdemo(void) pluginifdemo_toolbar_register(tb); } +void* get_frame_data_cb(frame_data* fdata, void* user_data _U_) { + return GUINT_TO_POINTER(fdata->num); +} + +void* get_capture_file_cb(capture_file* cf, void* user_data _U_) { + return cf->filename; +} + void toolbar_cb(gpointer toolbar_item, gpointer item_data, gpointer user_data _U_) { if ( ! toolbar_item ) @@ -93,8 +101,19 @@ void toolbar_cb(gpointer toolbar_item, gpointer item_data, gpointer user_data _U gchar * message = 0; ext_toolbar_t * entry = (ext_toolbar_t *)toolbar_item; - if ( entry->item_type == EXT_TOOLBAR_BUTTON ) - pluginifdemo_toolbar_log ( "Button pressed at toolbar" ); + if (entry->item_type == EXT_TOOLBAR_BUTTON) { + pluginifdemo_toolbar_log("Button pressed at toolbar"); + guint32 fnum = GPOINTER_TO_UINT(plugin_if_get_frame_data(get_frame_data_cb, NULL)); + if (fnum) { + message = g_strdup_printf("Current frame is: %u", fnum); + pluginifdemo_toolbar_log(message); + } + const gchar* fnm = (const gchar*)plugin_if_get_capture_file(get_capture_file_cb, NULL); + if (fnm) { + message = g_strdup_printf("Capture file name is: %s", fnm); + pluginifdemo_toolbar_log(message); + } + } else if ( entry->item_type == EXT_TOOLBAR_BOOLEAN ) { gboolean data = *((gboolean *)item_data); diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 4c1a7c0243..edbdeb635f 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -228,6 +228,50 @@ static void plugin_if_mainwindow_get_ws_info(GHashTable * data_set) #endif /* HAVE_LIBPCAP */ +static void plugin_if_mainwindow_get_frame_data(GHashTable* data_set) +{ + if (!gbl_cur_main_window_ || !data_set) + return; + + plugin_if_frame_data_cb extract_cb; + void* user_data; + void** ret_value_ptr; + + if (g_hash_table_lookup_extended(data_set, "extract_cb", NULL, (void**)&extract_cb) && + g_hash_table_lookup_extended(data_set, "user_data", NULL, (void**)&user_data) && + g_hash_table_lookup_extended(data_set, "ret_value_ptr", NULL, (void**)&ret_value_ptr)) + { + QList rows = gbl_cur_main_window_->selectedRows(); + if (rows.count() > 0) { + frame_data* fdata = gbl_cur_main_window_->frameDataForRow(rows.at(0)); + if (fdata) { + *ret_value_ptr = extract_cb(fdata, user_data); + } + } + } +} + +static void plugin_if_mainwindow_get_capture_file(GHashTable* data_set) +{ + if (!gbl_cur_main_window_ || !data_set) + return; + + plugin_if_capture_file_cb extract_cb; + void* user_data; + void** ret_value_ptr; + + if (g_hash_table_lookup_extended(data_set, "extract_cb", NULL, (void**)&extract_cb) && + g_hash_table_lookup_extended(data_set, "user_data", NULL, (void**)&user_data) && + g_hash_table_lookup_extended(data_set, "ret_value_ptr", NULL, (void**)&ret_value_ptr)) + { + CaptureFile* cfWrap = gbl_cur_main_window_->captureFile(); + capture_file* cf = cfWrap->capFile(); + if (cf) { + *ret_value_ptr = extract_cb(cf, user_data); + } + } +} + static void plugin_if_mainwindow_update_toolbars(GHashTable * data_set) { if (!gbl_cur_main_window_ || !data_set) @@ -642,6 +686,8 @@ MainWindow::MainWindow(QWidget *parent) : #ifdef HAVE_LIBPCAP plugin_if_register_gui_cb(PLUGIN_IF_GET_WS_INFO, plugin_if_mainwindow_get_ws_info); #endif + plugin_if_register_gui_cb(PLUGIN_IF_GET_FRAME_DATA, plugin_if_mainwindow_get_frame_data); + plugin_if_register_gui_cb(PLUGIN_IF_GET_CAPTURE_FILE, plugin_if_mainwindow_get_capture_file); plugin_if_register_gui_cb(PLUGIN_IF_REMOVE_TOOLBAR, plugin_if_mainwindow_update_toolbars); /* Register Interface Toolbar callbacks */