From d1cb746822a31dc2d3273984587ce1ad2756ee7c Mon Sep 17 00:00:00 2001 From: Paul Offord Date: Thu, 7 Jan 2016 07:39:14 +0000 Subject: [PATCH] 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 Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall --- epan/plugin_if.c | 34 +++++++++++++++++++++++++ epan/plugin_if.h | 25 +++++++++++++++++-- ui/gtk/main_toolbar.c | 56 +++++++++++++++++++++++++++++++++++++++++ ui/qt/main_window.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++ ui/qt/main_window.h | 1 + 5 files changed, 172 insertions(+), 2 deletions(-) diff --git a/epan/plugin_if.c b/epan/plugin_if.c index 11f9d85a5e..ac86f7858d 100644 --- a/epan/plugin_if.c +++ b/epan/plugin_if.c @@ -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; diff --git a/epan/plugin_if.h b/epan/plugin_if.h index 3d14a268f9..c74f86e422 100644 --- a/epan/plugin_if.h +++ b/epan/plugin_if.h @@ -36,6 +36,7 @@ #include #include #include +#include #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 * diff --git a/ui/gtk/main_toolbar.c b/ui/gtk/main_toolbar.c index c5d6ac2a8d..cefe30e380 100644 --- a/ui/gtk/main_toolbar.c +++ b/ui/gtk/main_toolbar.c @@ -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; } diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 4cb8cd93d2..8bfda67c0c 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -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_); } diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index e0cbdcc668..ad483b408c 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -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);