plugin_if: Add function to get capture file info

This is an enhancement to allow a plugin to obtain capture file
and other status information via a simple plugin_if call

Added GTK port to this revision

Bug: 11968
Change-Id: Ibcf4e8b43c6f3b48e971fa4020a07cc273234fb8
Reviewed-on: https://code.wireshark.org/review/13103
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
Paul Offord 2016-01-07 07:39:14 +00:00 committed by Roland Knall
parent ca512cf47c
commit d1cb746822
5 changed files with 172 additions and 2 deletions

View File

@ -38,6 +38,7 @@
static GList * menubar_entries = NULL;
static GList * menubar_menunames = NULL;
extern GList * ext_menubar_get_entries(void)
{
return menubar_entries;
@ -249,6 +250,39 @@ extern void plugin_if_save_preference(const char * pref_module, const char * pre
plugin_if_call_gui_cb(PLUGIN_IF_PREFERENCE_SAVE, dataSet);
}
extern void plugin_if_get_ws_info(ws_info_t **ws_info_ptr)
{
static ws_info_t ws_info = { FALSE, FILE_CLOSED, NULL, 0, 0, FALSE };
#ifdef HAVE_LIBPCAP
GHashTable * dataSet;
gchar * pluginKey = g_strdup("ws_info");
dataSet = g_hash_table_new(g_str_hash, g_str_equal);
g_hash_table_insert(dataSet, pluginKey, &ws_info);
plugin_if_call_gui_cb(PLUGIN_IF_GET_WS_INFO, dataSet);
g_hash_table_destroy(dataSet);
g_free(pluginKey);
#else
/* Initialise the ws_info structure */
ws_info->ws_info_supported = false;
ws_info->cf_count = 0;
ws_info->cf_filename = NULL;
ws_info->cf_framenr = 0;
ws_info->frame_passed_dfilter = FALSE;
ws_info->cf_state = FILE_CLOSED;
#endif /* HAVE_LIBPCAP */
*ws_info_ptr = &ws_info;
}
extern void plugin_if_register_gui_cb(plugin_if_callback_t actionType, plugin_if_gui_cb callback)
{
gint * key = 0;

View File

@ -36,6 +36,7 @@
#include <glib.h>
#include <epan/epan.h>
#include <epan/packet_info.h>
#include <cfile.h>
#ifdef __cplusplus
extern "C" {
@ -162,6 +163,21 @@ WS_DLL_PUBLIC void ext_menubar_add_website(ext_menu_t * parent, const gchar *lab
const gchar *tooltip, const gchar *url);
/*
* Structure definition for the plugin_if_get_ws_info function
*/
typedef struct _ws_info_t
{
gboolean ws_info_supported; /* false if no libpcap */
file_state cf_state; /* Current state of capture file */
gchar *cf_filename; /* Name of capture file */
guint32 cf_count; /* Total number of frames */
guint32 cf_framenr; /**< Currently displayed frame number */
gboolean frame_passed_dfilter; /**< true = display, false = no display */
} ws_info_t;
/*
* Enumeration of possible actions, which are registered in GUI interfaces
*/
@ -176,8 +192,11 @@ typedef enum
/* Saves a preference entry */
PLUGIN_IF_PREFERENCE_SAVE,
/* Jumps to the provided frame number */
PLUGIN_IF_GOTO_FRAME
/* Jumps to the provided frame number */
PLUGIN_IF_GOTO_FRAME,
/* Gets status information about the currently loaded capture file */
PLUGIN_IF_GET_WS_INFO
} plugin_if_callback_t;
@ -194,6 +213,8 @@ WS_DLL_PUBLIC void plugin_if_save_preference(const char * pref_module, const cha
/* Jumps to the given frame number */
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);
/* Private Method for retrieving the menubar entries
*

View File

@ -73,6 +73,8 @@ static GtkToolItem *zoom_in_button, *zoom_out_button, *zoom_100_button, *coloriz
static GtkToolItem *resize_columns_button;
static GtkToolItem *color_display_button, *prefs_button, *help_button;
extern capture_file cfile;
/*
* Redraw all toolbars
*/
@ -280,6 +282,57 @@ plugin_if_maintoolbar_goto_frame(gconstpointer user_data)
}
}
#ifdef HAVE_LIBPCAP
static void plugin_if_maintoolbar_get_ws_info(gconstpointer user_data)
{
GHashTable * dataSet = (GHashTable *)user_data;
ws_info_t *ws_info = NULL;
if (g_hash_table_lookup_extended(dataSet, "ws_info", NULL, (void**)&ws_info))
{
capture_file *cf = &cfile;
if (cf->state != FILE_CLOSED)
{
ws_info->ws_info_supported = TRUE;
ws_info->cf_state = cf->state;
ws_info->cf_count = cf->count;
if (ws_info->cf_filename != NULL)
g_free(ws_info->cf_filename);
ws_info->cf_filename = g_strdup(cf->filename);
if (cf->state == FILE_READ_DONE)
{
ws_info->cf_framenr = (cf->current_frame)->num;
ws_info->frame_passed_dfilter = ((cf->current_frame)->flags.passed_dfilter) == 0 ? FALSE : TRUE;
}
else
{
ws_info->cf_framenr = 0;
ws_info->frame_passed_dfilter = FALSE;
}
}
else if (ws_info->cf_state != FILE_CLOSED)
{
/* Initialise the ws_info structure */
ws_info->ws_info_supported = TRUE;
ws_info->cf_count = 0;
if (ws_info->cf_filename != NULL)
g_free(ws_info->cf_filename);
ws_info->cf_filename = NULL;
ws_info->cf_framenr = 0;
ws_info->frame_passed_dfilter = FALSE;
ws_info->cf_state = FILE_CLOSED;
}
}
}
#endif /* HAVE_LIBPCAP */
/*
* Create all toolbars (currently only the main toolbar)
*/
@ -415,6 +468,9 @@ toolbar_new(void)
toolbar_redraw_all();
plugin_if_register_gui_cb(PLUGIN_IF_GOTO_FRAME, plugin_if_maintoolbar_goto_frame);
#ifdef HAVE_LIBPCAP
plugin_if_register_gui_cb(PLUGIN_IF_GET_WS_INFO, plugin_if_maintoolbar_get_ws_info);
#endif /* HAVE_LIBPCAP */
return main_tb;
}

View File

@ -136,6 +136,61 @@ static void plugin_if_mainwindow_gotoframe(gconstpointer user_data)
}
}
#ifdef HAVE_LIBPCAP
static void plugin_if_mainwindow_get_ws_info(gconstpointer user_data)
{
if (gbl_cur_main_window_ != NULL && user_data != NULL)
{
GHashTable * dataSet = (GHashTable *)user_data;
ws_info_t *ws_info = NULL;
if (g_hash_table_lookup_extended(dataSet, "ws_info", NULL, (void**)&ws_info))
{
CaptureFile *cfWrap = gbl_cur_main_window_->captureFile();
capture_file *cf = cfWrap->capFile();
ws_info->ws_info_supported = true;
if (cf != NULL)
{
ws_info->cf_state = cf->state;
ws_info->cf_count = cf->count;
if (ws_info->cf_filename != NULL)
g_free(ws_info->cf_filename);
ws_info->cf_filename = g_strdup(cf->filename);
if (cf->state == FILE_READ_DONE)
{
ws_info->cf_framenr = (cf->current_frame)->num;
ws_info->frame_passed_dfilter = ((cf->current_frame)->flags.passed_dfilter) == 0 ? FALSE : TRUE;
}
else
{
ws_info->cf_framenr = 0;
ws_info->frame_passed_dfilter = FALSE;
}
}
else if (ws_info->cf_state != FILE_CLOSED)
{
/* Initialise the ws_info structure */
ws_info->cf_count = 0;
if (ws_info->cf_filename != NULL)
g_free(ws_info->cf_filename);
ws_info->cf_filename = NULL;
ws_info->cf_framenr = 0;
ws_info->frame_passed_dfilter = false;
ws_info->cf_state = FILE_CLOSED;
}
}
}
}
#endif /* HAVE_LIBPCAP */
gpointer
simple_dialog(ESD_TYPE_E type, gint btn_mask, const gchar *msg_format, ...)
{
@ -616,6 +671,9 @@ MainWindow::MainWindow(QWidget *parent) :
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);
plugin_if_register_gui_cb(PLUGIN_IF_GOTO_FRAME, plugin_if_mainwindow_gotoframe);
#ifdef HAVE_LIBPCAP
plugin_if_register_gui_cb(PLUGIN_IF_GET_WS_INFO, plugin_if_mainwindow_get_ws_info);
#endif
main_ui_->mainStack->setCurrentWidget(main_welcome_);
}

View File

@ -93,6 +93,7 @@ public:
virtual QMenu *createPopupMenu();
void gotoFrame(int packet_num);
CaptureFile *captureFile() { return &capture_file_; }
protected:
bool eventFilter(QObject *obj, QEvent *event);