plugin_if: add plugin_if_get_frame_data() and plugin_if_get_capture_file()

Change-Id: I7505d4185f18d13d6836c9c9bb8f400d12f2a524
Reviewed-on: https://code.wireshark.org/review/38217
Petri-Dish: Tomáš Kukosa <keksa@email.cz>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
Tomas Kukosa 2020-08-21 10:23:03 +02:00 committed by Anders Broman
parent 7e46db8f86
commit 82a4968bc3
5 changed files with 117 additions and 2 deletions

View File

@ -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

View File

@ -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();

View File

@ -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

View File

@ -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);

View File

@ -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<int> 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 */