diff options
author | Gerald Combs <gerald@wireshark.org> | 2014-09-09 16:42:58 -0400 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2014-12-20 17:39:29 +0000 |
commit | 9ba9cd83a4f72339b15aebbc1fbdde32f08ef3bc (patch) | |
tree | 4ed17ac7d9681f43bf1e0e1069bb2a84a48a8387 | |
parent | 2bb8255e29e26c7c14f7a83ce33b41f9af18501e (diff) | |
download | wireshark-9ba9cd83a4f72339b15aebbc1fbdde32f08ef3bc.tar.gz wireshark-9ba9cd83a4f72339b15aebbc1fbdde32f08ef3bc.tar.bz2 wireshark-9ba9cd83a4f72339b15aebbc1fbdde32f08ef3bc.zip |
Qt: Add a CaptureFile class.
Wrap the capture_file struct in a QObject which translates cf_cb_* and
capture_cb_* events into signals. Move the global cfile to
capture_file.cpp.
Don't use a void pointer for the capture file struct.
Change-Id: Ic5d5efb4bb1db64aa0247245890e5669b1da723a
Reviewed-on: https://code.wireshark.org/review/5885
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
-rw-r--r-- | capchild/capture_ifinfo.c | 5 | ||||
-rw-r--r-- | capchild/capture_session.h | 10 | ||||
-rw-r--r-- | capchild/capture_sync.c | 2 | ||||
-rw-r--r-- | echld/dispatcher.c | 2 | ||||
-rw-r--r-- | file.c | 4 | ||||
-rw-r--r-- | file.h | 20 | ||||
-rw-r--r-- | tshark.c | 2 | ||||
-rw-r--r-- | ui/capture.c | 4 | ||||
-rw-r--r-- | ui/capture.h | 4 | ||||
-rw-r--r-- | ui/gtk/main.c | 2 | ||||
-rw-r--r-- | ui/qt/CMakeLists.txt | 2 | ||||
-rw-r--r-- | ui/qt/Makefile.common | 2 | ||||
-rw-r--r-- | ui/qt/Wireshark.pro | 2 | ||||
-rw-r--r-- | ui/qt/capture_file.cpp | 212 | ||||
-rw-r--r-- | ui/qt/capture_file.h | 92 | ||||
-rw-r--r-- | ui/qt/main.cpp | 36 | ||||
-rw-r--r-- | ui/qt/main_window.cpp | 149 | ||||
-rw-r--r-- | ui/qt/main_window.h | 28 | ||||
-rw-r--r-- | ui/qt/main_window_slots.cpp | 234 | ||||
-rw-r--r-- | ui/qt/wireshark_application.cpp | 115 | ||||
-rw-r--r-- | ui/qt/wireshark_application.h | 10 |
21 files changed, 567 insertions, 370 deletions
diff --git a/capchild/capture_ifinfo.c b/capchild/capture_ifinfo.c index 0ae807ec53..eb86215c89 100644 --- a/capchild/capture_ifinfo.c +++ b/capchild/capture_ifinfo.c @@ -47,8 +47,9 @@ #include <glib.h> #include "capture_opts.h" -#include <capchild/capture_session.h> -#include <capchild/capture_sync.h> + +#include "capchild/capture_session.h" +#include "capchild/capture_sync.h" #ifdef HAVE_EXTCAP #include "extcap.h" #endif diff --git a/capchild/capture_session.h b/capchild/capture_session.h index 951b51e499..06cfb88902 100644 --- a/capchild/capture_session.h +++ b/capchild/capture_session.h @@ -41,10 +41,12 @@ typedef enum { CAPTURE_RUNNING /**< capture child signalled ok, capture is running now */ } capture_state; +struct _capture_file; + /* * State of a capture session. */ -typedef struct { +typedef struct _capture_session { int fork_child; /**< If not -1, in parent, process ID of child */ int fork_child_status; /**< Child exit status */ #ifdef _WIN32 @@ -57,15 +59,15 @@ typedef struct { #endif gboolean session_started; capture_options *capture_opts; /**< options for this capture */ - void *cf; /**< handle to cfile (note: untyped handle) */ + struct _capture_file *cf; /**< handle to cfile */ } capture_session; extern void -capture_session_init(capture_session *cap_session, void *cf); +capture_session_init(capture_session *cap_session, struct _capture_file *cf); #else /* dummy is needed because clang throws the error: empty struct has size 0 in C, size 1 in C++ */ -typedef struct {int dummy;} capture_session; +typedef struct _capture_session {int dummy;} capture_session; #endif /* HAVE_LIBPCAP */ diff --git a/capchild/capture_sync.c b/capchild/capture_sync.c index 8542105a04..e1c6870745 100644 --- a/capchild/capture_sync.c +++ b/capchild/capture_sync.c @@ -127,7 +127,7 @@ static void (*fetch_dumpcap_pid)(int) = NULL; void -capture_session_init(capture_session *cap_session, void *cf) +capture_session_init(capture_session *cap_session, struct _capture_file *cf) { cap_session->cf = cf; cap_session->fork_child = -1; /* invalid process handle */ diff --git a/echld/dispatcher.c b/echld/dispatcher.c index 03da38151c..6788e27038 100644 --- a/echld/dispatcher.c +++ b/echld/dispatcher.c @@ -138,7 +138,7 @@ static echld_epan_stuff_t stuff; static void init_stuff(void) { #ifdef HAVE_LIBPCAP capture_opts_init(&stuff.cap_opts); - capture_session_init(&stuff.cap_sess, (void *)&stuff.cfile); + capture_session_init(&stuff.cap_sess, &stuff.cfile); #endif } @@ -195,14 +195,14 @@ cf_callback_add(cf_callback_t func, gpointer user_data) } void -cf_callback_remove(cf_callback_t func) +cf_callback_remove(cf_callback_t func, gpointer user_data) { cf_callback_data_t *cb; GList *cb_item = cf_callbacks; while (cb_item != NULL) { cb = (cf_callback_data_t *)cb_item->data; - if (cb->cb_fct == func) { + if (cb->cb_fct == func && cb->user_data == user_data) { cf_callbacks = g_list_remove(cf_callbacks, cb); g_free(cb); return; @@ -95,11 +95,29 @@ typedef struct { field_info *finfo; } match_data; +/** + * Add a capture file event callback. + * + * @param func The function to be called for each event. + * The function will be passed three parameters: The event type (event), + * event-dependent data (data), and user-supplied data (user_data). + * Event-dependent data may be a capture_file pointer, character pointer, + * or NULL. + * @param user_data User-supplied data to pass to the callback. May be NULL. + */ + extern void cf_callback_add(cf_callback_t func, gpointer user_data); +/** + * Remove a capture file event callback. + * + * @param func The function to be removed. + * @param user_data User-supplied data. Must be the same value supplied to cf_callback_add. + */ + extern void -cf_callback_remove(cf_callback_t func); +cf_callback_remove(cf_callback_t func, gpointer user_data); /** * Open a capture file. @@ -1164,7 +1164,7 @@ main(int argc, char *argv[]) #ifdef HAVE_LIBPCAP capture_opts_init(&global_capture_opts); - capture_session_init(&global_capture_session, (void *)&cfile); + capture_session_init(&global_capture_session, &cfile); #endif timestamp_set_type(TS_RELATIVE); diff --git a/ui/capture.c b/ui/capture.c index cfc75b979d..254cda3f4e 100644 --- a/ui/capture.c +++ b/ui/capture.c @@ -105,14 +105,14 @@ capture_callback_add(capture_callback_t func, gpointer user_data) } void -capture_callback_remove(capture_callback_t func) +capture_callback_remove(capture_callback_t func, gpointer user_data) { capture_callback_data_t *cb; GList *cb_item = capture_callbacks; while(cb_item != NULL) { cb = (capture_callback_data_t *)cb_item->data; - if(cb->cb_fct == func) { + if(cb->cb_fct == func && cb->user_data == user_data) { capture_callbacks = g_list_remove(capture_callbacks, cb); g_free(cb); return; diff --git a/ui/capture.h b/ui/capture.h index 6407e4b2d8..5057b82910 100644 --- a/ui/capture.h +++ b/ui/capture.h @@ -30,7 +30,7 @@ */ #include "capture_opts.h" -#include <capchild/capture_session.h> +#include "capchild/capture_session.h" #ifdef __cplusplus extern "C" { @@ -55,7 +55,7 @@ extern void capture_callback_add(capture_callback_t func, gpointer user_data); extern void -capture_callback_remove(capture_callback_t func); +capture_callback_remove(capture_callback_t func, gpointer user_data); /** * Start a capture session. diff --git a/ui/gtk/main.c b/ui/gtk/main.c index 622bb6ee16..83ab1fd482 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -2469,7 +2469,7 @@ main(int argc, char *argv[]) by preference settings and then again by the command line parameters. */ capture_opts_init(&global_capture_opts); - capture_session_init(&global_capture_session, (void *)&cfile); + capture_session_init(&global_capture_session, &cfile); #endif init_report_err(failure_alert_box, open_failure_alert_box, diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt index 32ad0cf112..73de482498 100644 --- a/ui/qt/CMakeLists.txt +++ b/ui/qt/CMakeLists.txt @@ -26,6 +26,7 @@ set(WIRESHARK_QT_HEADERS accordion_frame.h byte_view_tab.h byte_view_text.h + capture_file.h capture_file_dialog.h capture_file_properties_dialog.h capture_filter_combo.h @@ -122,6 +123,7 @@ set(WIRESHARK_QT_SRC accordion_frame.cpp byte_view_tab.cpp byte_view_text.cpp + capture_file.cpp capture_file_dialog.cpp capture_file_properties_dialog.cpp capture_filter_combo.cpp diff --git a/ui/qt/Makefile.common b/ui/qt/Makefile.common index e7b0d247cb..6fd892c1e1 100644 --- a/ui/qt/Makefile.common +++ b/ui/qt/Makefile.common @@ -116,6 +116,7 @@ MOC_HDRS = \ accordion_frame.h \ byte_view_tab.h \ byte_view_text.h \ + capture_file.h \ capture_file_dialog.h \ capture_file_properties_dialog.h \ capture_filter_combo.h \ @@ -309,6 +310,7 @@ WIRESHARK_QT_SRC = \ accordion_frame.cpp \ byte_view_tab.cpp \ byte_view_text.cpp \ + capture_file.cpp \ capture_file_dialog.cpp \ capture_file_properties_dialog.cpp \ capture_filter_combo.cpp \ diff --git a/ui/qt/Wireshark.pro b/ui/qt/Wireshark.pro index 34e2db4a42..7390e08517 100644 --- a/ui/qt/Wireshark.pro +++ b/ui/qt/Wireshark.pro @@ -547,6 +547,7 @@ win32: QMAKE_CLEAN += *.pdb HEADERS += \ byte_view_tab.h \ byte_view_text.h \ + capture_file.h \ capture_file_dialog.h \ capture_filter_combo.h \ capture_filter_edit.h \ @@ -589,6 +590,7 @@ SOURCES += \ accordion_frame.cpp \ byte_view_tab.cpp \ byte_view_text.cpp \ + capture_file.cpp \ capture_file_dialog.cpp \ capture_file_properties_dialog.cpp \ capture_filter_combo.cpp \ diff --git a/ui/qt/capture_file.cpp b/ui/qt/capture_file.cpp new file mode 100644 index 0000000000..fc25f6424f --- /dev/null +++ b/ui/qt/capture_file.cpp @@ -0,0 +1,212 @@ +/* capture_file.cpp + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "capture_file.h" + +/* + * @file Capture file class + * + * Wraps the capture_file struct, cfile global, and callbacks. + */ + +#include "globals.h" +capture_file cfile; + +#include "file.h" +#include "log.h" + +#include "ui/capture.h" + +// To do: +// - Add isValid or isOpen methods instead of checking capFile() for NULL. +// - Add getters and (if needed) setters: +// - Base filename +// - Full filename + +#include <QDebug> + +CaptureFile::CaptureFile(QObject *parent, capture_file *cap_file) : + QObject(parent), + cap_file_(cap_file) +{ +#ifdef HAVE_LIBPCAP + capture_callback_add(captureCallback, (gpointer) this); +#endif + cf_callback_add(captureFileCallback, (gpointer) this); +} + +CaptureFile::~CaptureFile() +{ + cf_callback_remove(captureFileCallback, this); +} + +capture_file *CaptureFile::globalCapFile() +{ + return &cfile; +} + +gpointer CaptureFile::window() +{ + if (cap_file_) return cap_file_->window; + return NULL; +} + +void CaptureFile::captureFileCallback(gint event, gpointer data, gpointer user_data) +{ + CaptureFile *capture_file = static_cast<CaptureFile *>(user_data); + if (!capture_file) return; + + capture_file->captureFileEvent(event, data); +} + +#ifdef HAVE_LIBPCAP +void CaptureFile::captureCallback(gint event, capture_session *cap_session, gpointer user_data) +{ + CaptureFile *capture_file = static_cast<CaptureFile *>(user_data); + if (!capture_file) return; + + capture_file->captureEvent(event, cap_session); +} +#endif + +void CaptureFile::captureFileEvent(int event, gpointer data) +{ + qDebug() << "=cfe" << event << data; + switch(event) { + case(cf_cb_file_opened): + g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Opened"); + cap_file_ = (capture_file *) data; + qDebug() << "=cfe fo" << cap_file_; + emit captureFileOpened(); + break; + case(cf_cb_file_closing): + g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Closing"); + emit captureFileClosing(); + break; + case(cf_cb_file_closed): + g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Closed"); + qDebug() << "=cfe fc" << cap_file_; + emit captureFileClosed(); + cap_file_ = NULL; + break; + case(cf_cb_file_read_started): + g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Read started"); + emit captureFileReadStarted(); + break; + case(cf_cb_file_read_finished): + g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Read finished"); + emit captureFileReadFinished(); + break; + case(cf_cb_file_reload_started): + g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Reload started"); + emit captureFileReadStarted(); + break; + case(cf_cb_file_reload_finished): + g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Reload finished"); + emit captureFileReadFinished(); + break; + + case(cf_cb_packet_selected): + case(cf_cb_packet_unselected): + case(cf_cb_field_unselected): + // Signals and slots handled elsewhere. + break; + +// case(cf_cb_file_save_started): // data = string +// g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Save started"); +// break; +// case(cf_cb_file_save_finished): +// g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Save finished"); +// break; +// case(cf_cb_file_save_failed): +// g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Save failed"); +// break; + default: + g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: main_cf_callback %d %p", event, data); + g_warning("CaptureFile::captureFileCallback: event %u unknown", event); + break; + } +} + +void CaptureFile::captureEvent(int event, capture_session *cap_session) +{ +#ifndef HAVE_LIBPCAP + Q_UNUSED(event) + Q_UNUSED(cap_session) +#else + qDebug() << "=ce" << event << cap_session->cf; + switch(event) { + case(capture_cb_capture_prepared): + g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture prepared"); + emit captureCapturePrepared(cap_session); + cap_file_ = cap_session->cf; + break; + case(capture_cb_capture_update_started): + g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update started"); + emit captureCaptureUpdateStarted(cap_session); + break; + case(capture_cb_capture_update_continue): + g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update continue"); + emit captureCaptureUpdateContinue(cap_session); + break; + case(capture_cb_capture_update_finished): + g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update finished"); + emit captureCaptureUpdateFinished(cap_session); + break; + case(capture_cb_capture_fixed_started): + g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed started"); + emit captureCaptureFixedStarted(cap_session); + break; + case(capture_cb_capture_fixed_continue): + g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed continue"); + break; + case(capture_cb_capture_fixed_finished): + g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed finished"); + emit captureCaptureFixedFinished(cap_session); + break; + case(capture_cb_capture_stopping): + g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture stopping"); + /* Beware: this state won't be called, if the capture child + * closes the capturing on it's own! */ + emit captureCaptureStopping(cap_session); + break; + case(capture_cb_capture_failed): + g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture failed"); + emit captureCaptureFailed(cap_session); + break; + default: + g_warning("main_capture_callback: event %u unknown", event); + } +#endif // HAVE_LIBPCAP +} + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/qt/capture_file.h b/ui/qt/capture_file.h new file mode 100644 index 0000000000..db0cab2b88 --- /dev/null +++ b/ui/qt/capture_file.h @@ -0,0 +1,92 @@ +/* capture_file.h + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef CAPTURE_FILE_H +#define CAPTURE_FILE_H + +#include <QObject> + +#include "config.h" + +#include <glib.h> + +typedef struct _capture_file capture_file; +typedef struct _capture_session capture_session; + +class CaptureFile : public QObject +{ + Q_OBJECT +public: + explicit CaptureFile(QObject *parent = 0, capture_file *cap_file = NULL); + ~CaptureFile(); + + capture_file *capFile() const { return cap_file_; } + void setCapFile(capture_file *cap_file) { cap_file_ = cap_file; } + + // XXX This shouldn't be needed. + static capture_file *globalCapFile(); + + gpointer window(); + +signals: + void captureFileOpened() const; + void captureFileReadStarted() const; + void captureFileReadFinished() const; + void captureFileClosing() const; + void captureFileClosed() const; + + void captureCapturePrepared(capture_session *cap_session); + void captureCaptureUpdateStarted(capture_session *cap_session); + void captureCaptureUpdateContinue(capture_session *cap_session); + void captureCaptureUpdateFinished(capture_session *cap_session); + void captureCaptureFixedStarted(capture_session *cap_session); + void captureCaptureFixedFinished(capture_session *cap_session); + void captureCaptureStopping(capture_session *cap_session); + void captureCaptureFailed(capture_session *cap_session); + +public slots: + +private: + static void captureFileCallback(gint event, gpointer data, gpointer user_data); +#ifdef HAVE_LIBPCAP + static void captureCallback(gint event, capture_session *cap_session, gpointer user_data); +#endif + + void captureFileEvent(int event, gpointer data); + void captureEvent(int event, capture_session *cap_session); + + capture_file *cap_file_; +}; + +#endif // CAPTURE_FILE_H + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp index ce20d5d741..8bc39b0be2 100644 --- a/ui/qt/main.cpp +++ b/ui/qt/main.cpp @@ -25,8 +25,6 @@ #include "main_window.h" #include "wireshark_application.h" -#include "globals.h" - #include <glib.h> #include <signal.h> @@ -143,6 +141,7 @@ #include <QTextCodec> #endif +#include "capture_file.h" #include "conversation_dialog.h" #include "endpoint_dialog.h" @@ -150,34 +149,12 @@ capture_options global_capture_opts; #endif -capture_file cfile; - #ifdef HAVE_AIRPCAP int airpcap_dll_ret_val = -1; #endif GString *comp_info_str, *runtime_info_str; -//static gboolean have_capture_file = FALSE; /* XXX - is there an equivalent in cfile? */ - -#ifdef HAVE_LIBPCAP -extern capture_options global_capture_opts; - -static void -main_capture_callback(gint event, capture_session *cap_session, gpointer user_data ) -{ - Q_UNUSED(user_data); - wsApp->captureCallback(event, cap_session); -} -#endif // HAVE_LIBPCAP - -static void -main_cf_callback(gint event, gpointer data, gpointer user_data ) -{ - Q_UNUSED(user_data); - wsApp->captureFileCallback(event, data); -} - /* update the main window */ void main_window_update(void) { @@ -828,11 +805,6 @@ int main(int argc, char *argv[]) signal(SIGPIPE, SIG_IGN); #endif -#ifdef HAVE_LIBPCAP - capture_callback_add(main_capture_callback, NULL); -#endif - cf_callback_add(main_cf_callback, NULL); - set_console_log_handler(); #ifdef HAVE_LIBPCAP @@ -1294,7 +1266,7 @@ int main(int argc, char *argv[]) set_disabled_protos_list(); } - build_column_format_array(&cfile.cinfo, prefs_p->num_cols, TRUE); + build_column_format_array(&CaptureFile::globalCapFile()->cinfo, prefs_p->num_cols, TRUE); wsApp->setMonospaceFont(prefs.gui_qt_font_name); @@ -1355,7 +1327,7 @@ int main(int argc, char *argv[]) if(go_to_packet != 0) { /* Jump to the specified frame number, kept for backward compatibility. */ - cf_goto_frame(&cfile, go_to_packet); + cf_goto_frame(CaptureFile::globalCapFile(), go_to_packet); } } #ifdef HAVE_LIBPCAP @@ -1377,7 +1349,7 @@ int main(int argc, char *argv[]) to use for this capture. */ if (global_capture_opts.ifaces->len == 0) collect_ifaces(&global_capture_opts); - cfile.window = main_w; + CaptureFile::globalCapFile()->window = main_w; if (capture_start(&global_capture_opts, main_w->captureSession(), main_window_update)) { /* The capture started. Open stat windows; we do so after creating the main window, to avoid GTK warnings, and after successfully diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 8d3ffdfbad..cfa317e338 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -22,8 +22,6 @@ #include "main_window.h" #include "ui_main_window.h" -#include "globals.h" - #include <epan/addr_resolv.h> #include <epan/epan_dissect.h> #include <wsutil/filesystem.h> @@ -149,7 +147,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), main_ui_(new Ui::MainWindow), df_combo_box_(new DisplayFilterCombo()), - cap_file_(NULL), previous_focus_(NULL), show_hide_actions_(NULL), time_display_actions_(NULL), @@ -168,7 +165,7 @@ MainWindow::MainWindow(QWidget *parent) : } gbl_cur_main_window_ = this; #ifdef HAVE_LIBPCAP - capture_session_init(&cap_session_, (void *)&cfile); + capture_session_init(&cap_session_, CaptureFile::globalCapFile()); #endif main_ui_->setupUi(this); setTitlebarForCaptureFile(); @@ -277,31 +274,37 @@ MainWindow::MainWindow(QWidget *parent) : initTimePrecisionFormatMenu(); updateNameResolutionActions(); - connect(wsApp, SIGNAL(captureCapturePrepared(capture_session *)), + connect(&capture_file_, SIGNAL(captureCapturePrepared(capture_session *)), this, SLOT(captureCapturePrepared(capture_session *))); - connect(wsApp, SIGNAL(captureCaptureUpdateStarted(capture_session *)), + connect(&capture_file_, SIGNAL(captureCaptureUpdateStarted(capture_session *)), this, SLOT(captureCaptureUpdateStarted(capture_session *))); - connect(wsApp, SIGNAL(captureCaptureUpdateFinished(capture_session *)), + connect(&capture_file_, SIGNAL(captureCaptureUpdateFinished(capture_session *)), this, SLOT(captureCaptureUpdateFinished(capture_session *))); - connect(wsApp, SIGNAL(captureCaptureFixedStarted(capture_session *)), + connect(&capture_file_, SIGNAL(captureCaptureFixedStarted(capture_session *)), this, SLOT(captureCaptureFixedStarted(capture_session *))); - connect(wsApp, SIGNAL(captureCaptureFixedFinished(capture_session *)), + connect(&capture_file_, SIGNAL(captureCaptureFixedFinished(capture_session *)), this, SLOT(captureCaptureFixedFinished(capture_session *))); - connect(wsApp, SIGNAL(captureCaptureStopping(capture_session *)), + connect(&capture_file_, SIGNAL(captureCaptureStopping(capture_session *)), this, SLOT(captureCaptureStopping(capture_session *))); - connect(wsApp, SIGNAL(captureCaptureFailed(capture_session *)), + connect(&capture_file_, SIGNAL(captureCaptureFailed(capture_session *)), this, SLOT(captureCaptureFailed(capture_session *))); - connect(wsApp, SIGNAL(captureFileOpened(const capture_file*)), - this, SLOT(captureFileOpened(const capture_file*))); - connect(wsApp, SIGNAL(captureFileReadStarted(const capture_file*)), - this, SLOT(captureFileReadStarted(const capture_file*))); - connect(wsApp, SIGNAL(captureFileReadFinished(const capture_file*)), - this, SLOT(captureFileReadFinished(const capture_file*))); - connect(wsApp, SIGNAL(captureFileClosing(const capture_file*)), - this, SLOT(captureFileClosing(const capture_file*))); - connect(wsApp, SIGNAL(captureFileClosed(const capture_file*)), - this, SLOT(captureFileClosed(const capture_file*))); + connect(&capture_file_, SIGNAL(captureFileOpened()), + this, SLOT(captureFileOpened())); + connect(&capture_file_, SIGNAL(captureFileReadStarted()), + this, SLOT(captureFileReadStarted())); + connect(&capture_file_, SIGNAL(captureFileReadFinished()), + this, SLOT(captureFileReadFinished())); + connect(&capture_file_, SIGNAL(captureFileClosing()), + this, SLOT(captureFileClosing())); + connect(&capture_file_, SIGNAL(captureFileClosed()), + this, SLOT(captureFileClosed())); + + connect(&capture_file_, SIGNAL(captureFileReadStarted()), + wsApp, SLOT(captureFileReadStarted())); + connect(&capture_file_, SIGNAL(captureFileReadFinished()), + wsApp, SLOT(updateTaps())); + connect(wsApp, SIGNAL(columnsChanged()), this, SLOT(recreatePacketList())); connect(wsApp, SIGNAL(packetDissectionChanged()), @@ -615,11 +618,11 @@ void MainWindow::mergeCaptureFile() dfilter_t *rfcode = NULL; int err; - if (!cap_file_) + if (!capture_file_.capFile()) return; if (prefs.gui_ask_unsaved) { - if (cf_has_unsaved_data(cap_file_)) { + if (cf_has_unsaved_data(capture_file_.capFile())) { QMessageBox msg_dialog; gchar *display_basename; int response; @@ -627,14 +630,14 @@ void MainWindow::mergeCaptureFile() msg_dialog.setIcon(QMessageBox::Question); /* This file has unsaved data; ask the user whether to save the capture. */ - if (cap_file_->is_tempfile) { + if (capture_file_.capFile()->is_tempfile) { msg_dialog.setText(tr("Save packets before merging?")); msg_dialog.setInformativeText(tr("A temporary capture file can't be merged.")); } else { /* * Format the message. */ - display_basename = g_filename_display_basename(cap_file_->filename); + display_basename = g_filename_display_basename(capture_file_.capFile()->filename); msg_dialog.setText(QString(tr("Save changes in \"%1\" before merging?")).arg(display_basename)); g_free(display_basename); msg_dialog.setInformativeText(tr("Changes must be saved before the files can be merged.")); @@ -649,7 +652,7 @@ void MainWindow::mergeCaptureFile() case QMessageBox::Save: /* Save the file but don't close it */ - saveCaptureFile(cap_file_, FALSE); + saveCaptureFile(capture_file_.capFile(), FALSE); break; case QMessageBox::Cancel: @@ -661,7 +664,7 @@ void MainWindow::mergeCaptureFile() } for (;;) { - CaptureFileDialog merge_dlg(this, cap_file_, display_filter); + CaptureFileDialog merge_dlg(this, capture_file_.capFile(), display_filter); int file_type; cf_status_t merge_status; char *in_filenames[2]; @@ -689,7 +692,7 @@ void MainWindow::mergeCaptureFile() if (merge_dlg.merge(file_name)) { if (dfilter_compile(display_filter.toUtf8().constData(), &rfcode)) { - cf_set_rfcode(cap_file_, rfcode); + cf_set_rfcode(capture_file_.capFile(), rfcode); } else { /* Not valid. Tell the user, and go back and run the file selection box again once they dismiss the alert. */ @@ -703,23 +706,23 @@ void MainWindow::mergeCaptureFile() return; } - file_type = cap_file_->cd_t; + file_type = capture_file_.capFile()->cd_t; /* Try to merge or append the two files */ tmpname = NULL; if (merge_dlg.mergeType() == 0) { /* chronological order */ - in_filenames[0] = cap_file_->filename; + in_filenames[0] = capture_file_.capFile()->filename; in_filenames[1] = file_name.toUtf8().data(); merge_status = cf_merge_files(&tmpname, 2, in_filenames, file_type, FALSE); } else if (merge_dlg.mergeType() <= 0) { /* prepend file */ in_filenames[0] = file_name.toUtf8().data(); - in_filenames[1] = cap_file_->filename; + in_filenames[1] = capture_file_.capFile()->filename; merge_status = cf_merge_files(&tmpname, 2, in_filenames, file_type, TRUE); } else { /* append file */ - in_filenames[0] = cap_file_->filename; + in_filenames[0] = capture_file_.capFile()->filename; in_filenames[1] = file_name.toUtf8().data(); merge_status = cf_merge_files(&tmpname, 2, in_filenames, file_type, TRUE); } @@ -731,13 +734,13 @@ void MainWindow::mergeCaptureFile() continue; } - cf_close(cap_file_); + cf_close(capture_file_.capFile()); /* Try to open the merged capture file. */ - cfile.window = this; - if (cf_open(&cfile, tmpname, WTAP_TYPE_AUTO, TRUE /* temporary file */, &err) != CF_OK) { + CaptureFile::globalCapFile()->window = this; + if (cf_open(CaptureFile::globalCapFile(), tmpname, WTAP_TYPE_AUTO, TRUE /* temporary file */, &err) != CF_OK) { /* We couldn't open it; fail. */ - cfile.window = NULL; + CaptureFile::globalCapFile()->window = NULL; if (rfcode != NULL) dfilter_free(rfcode); g_free(tmpname); @@ -747,9 +750,9 @@ void MainWindow::mergeCaptureFile() /* Attach the new read filter to "cf" ("cf_open()" succeeded, so it closed the previous capture file, and thus destroyed any previous read filter attached to "cf"). */ - cfile.rfcode = rfcode; + CaptureFile::globalCapFile()->rfcode = rfcode; - switch (cf_read(&cfile, FALSE)) { + switch (cf_read(CaptureFile::globalCapFile(), FALSE)) { case CF_READ_OK: case CF_READ_ERROR: @@ -1017,16 +1020,16 @@ void MainWindow::exportSelectedPackets() { gchar *dirname; gboolean discard_comments = FALSE; - if (!cap_file_) + if (!capture_file_.capFile()) return; /* Init the packet range */ - packet_range_init(&range, cap_file_); + packet_range_init(&range, capture_file_.capFile()); range.process_filtered = TRUE; range.include_dependents = TRUE; for (;;) { - CaptureFileDialog esp_dlg(this, cap_file_); + CaptureFileDialog esp_dlg(this, capture_file_.capFile()); switch (prefs.gui_fileopen_style) { @@ -1091,7 +1094,7 @@ void MainWindow::exportSelectedPackets() { * name and the read file name may be relative (if supplied on * the command line). From Joerg Mayer. */ - if (files_identical(cap_file_->filename, file_name.toUtf8().constData())) { + if (files_identical(capture_file_.capFile()->filename, file_name.toUtf8().constData())) { QMessageBox msg_box; gchar *display_basename = g_filename_display_basename(file_name.toUtf8().constData()); @@ -1119,7 +1122,7 @@ void MainWindow::exportSelectedPackets() { //#endif /* Attempt to save the file */ - status = cf_export_specified_packets(cap_file_, file_name.toUtf8().constData(), &range, file_type, compressed); + status = cf_export_specified_packets(capture_file_.capFile(), file_name.toUtf8().constData(), &range, file_type, compressed); switch (status) { case CF_WRITE_OK: @@ -1147,14 +1150,14 @@ void MainWindow::exportSelectedPackets() { } void MainWindow::exportDissections(export_type_e export_type) { - ExportDissectionDialog ed_dlg(this, cap_file_, export_type); + ExportDissectionDialog ed_dlg(this, capture_file_.capFile(), export_type); packet_range_t range; - if (!cap_file_) + if (!capture_file_.capFile()) return; /* Init the packet range */ - packet_range_init(&range, cap_file_); + packet_range_init(&range, capture_file_.capFile()); range.process_filtered = TRUE; range.include_dependents = TRUE; @@ -1220,11 +1223,11 @@ void MainWindow::fileAddExtension(QString &file_name, int file_type, bool compre bool MainWindow::testCaptureFileClose(bool from_quit, QString &before_what) { bool capture_in_progress = FALSE; - if (!cap_file_ || cap_file_->state == FILE_CLOSED) + if (!capture_file_.capFile() || capture_file_.capFile()->state == FILE_CLOSED) return true; /* Already closed, nothing to do */ #ifdef HAVE_LIBPCAP - if (cap_file_->state == FILE_READ_IN_PROGRESS) { + if (capture_file_.capFile()->state == FILE_READ_IN_PROGRESS) { /* This is true if we're reading a capture file *or* if we're doing a live capture. If we're reading a capture file, the main loop is busy reading packets, and only accepting input from the @@ -1235,7 +1238,7 @@ bool MainWindow::testCaptureFileClose(bool from_quit, QString &before_what) { #endif if (prefs.gui_ask_unsaved) { - if (cf_has_unsaved_data(cap_file_) || capture_in_progress) { + if (cf_has_unsaved_data(capture_file_.capFile()) || capture_in_progress) { QMessageBox msg_dialog; QString question; QPushButton *saveButton; @@ -1245,7 +1248,7 @@ bool MainWindow::testCaptureFileClose(bool from_quit, QString &before_what) { msg_dialog.setWindowTitle("Unsaved packets..."); /* This file has unsaved data or there's a capture in progress; ask the user whether to save the data. */ - if (cap_file_->is_tempfile) { + if (capture_file_.capFile()->is_tempfile) { msg_dialog.setText(tr("You have unsaved packets")); msg_dialog.setInformativeText(tr("They will be lost if you don't save them.")); @@ -1269,7 +1272,7 @@ bool MainWindow::testCaptureFileClose(bool from_quit, QString &before_what) { msg_dialog.setText(question); msg_dialog.setInformativeText(tr("Your captured packets will be lost if you don't save them.")); } else { - gchar *display_basename = g_filename_display_basename(cap_file_->filename); + gchar *display_basename = g_filename_display_basename(capture_file_.capFile()->filename); question.append(QString(tr("Do you want to save the changes you've made to the capture file \"%1\"%2?")) .arg(display_basename) .arg(before_what) @@ -1295,7 +1298,7 @@ bool MainWindow::testCaptureFileClose(bool from_quit, QString &before_what) { msg_dialog.setDefaultButton(saveButton); if (from_quit) { - if (cap_file_->state == FILE_READ_IN_PROGRESS) { + if (capture_file_.capFile()->state == FILE_READ_IN_PROGRESS) { discardButton = msg_dialog.addButton(tr("Stop and Quit without Saving"), QMessageBox::DestructiveRole); } else { @@ -1326,7 +1329,7 @@ bool MainWindow::testCaptureFileClose(bool from_quit, QString &before_what) { captureStop(); #endif /* Save the file and close it */ - saveCaptureFile(cap_file_, TRUE); + saveCaptureFile(capture_file_.capFile(), TRUE); } else if(msg_dialog.clickedButton() == discardButton) { @@ -1339,7 +1342,7 @@ bool MainWindow::testCaptureFileClose(bool from_quit, QString &before_what) { captureStop(); #endif /* Just close the file, discarding changes */ - cf_close(cap_file_); + cf_close(capture_file_.capFile()); return true; } else //cancelButton or some other unspecified button @@ -1349,7 +1352,7 @@ bool MainWindow::testCaptureFileClose(bool from_quit, QString &before_what) { } else { /* Unchanged file, just close it */ - cf_close(cap_file_); + cf_close(capture_file_.capFile()); } } else { /* User asked not to be bothered by those prompts, just close it. @@ -1360,7 +1363,7 @@ bool MainWindow::testCaptureFileClose(bool from_quit, QString &before_what) { if (capture_in_progress) captureStop(); #endif - cf_close(cap_file_); + cf_close(capture_file_.capFile()); } return true; /* File closed */ @@ -1369,7 +1372,7 @@ bool MainWindow::testCaptureFileClose(bool from_quit, QString &before_what) { void MainWindow::captureStop() { stopCapture(); - while(cap_file_ && cap_file_->state == FILE_READ_IN_PROGRESS) { + while(capture_file_.capFile() && capture_file_.capFile()->state == FILE_READ_IN_PROGRESS) { WiresharkApplication::processEvents(); } } @@ -1520,7 +1523,7 @@ void MainWindow::initTimePrecisionFormatMenu() // Titlebar void MainWindow::setTitlebarForCaptureFile() { - if (cap_file_ && cap_file_->filename) { + if (capture_file_.capFile() && capture_file_.capFile()->filename) { // // Qt *REALLY* doesn't like windows that sometimes have a // title set with setWindowTitle() and other times have a @@ -1541,7 +1544,7 @@ void MainWindow::setTitlebarForCaptureFile() // live capture at time T1 and then, after you've saved the live // capture to a user file, associated with a user file at time T2. // - if (cap_file_->is_tempfile) { + if (capture_file_.capFile()->is_tempfile) { // // For a temporary file, put the source of the data // in the window title, not whatever random pile @@ -1553,7 +1556,7 @@ void MainWindow::setTitlebarForCaptureFile() // gchar *window_name; setWindowFilePath(NULL); - window_name = g_strdup_printf("Capturing from %s[*]", cf_get_tempfile_source(cap_file_)); //TODO : Fix Translate + window_name = g_strdup_printf("Capturing from %s[*]", cf_get_tempfile_source(capture_file_.capFile())); //TODO : Fix Translate setWindowTitle(window_name); g_free(window_name); } else { @@ -1567,7 +1570,7 @@ void MainWindow::setTitlebarForCaptureFile() // file path to UTF-8. If that fails, we're somewhat // stuck. // - char *utf8_filename = g_filename_to_utf8(cap_file_->filename, + char *utf8_filename = g_filename_to_utf8(capture_file_.capFile()->filename, -1, NULL, NULL, @@ -1582,7 +1585,7 @@ void MainWindow::setTitlebarForCaptureFile() g_free(utf8_filename); } } - setWindowModified(cf_has_unsaved_data(cap_file_)); + setWindowModified(cf_has_unsaved_data(capture_file_.capFile())); } else { /* We have no capture file. */ setWindowFilePath(NULL); @@ -1601,8 +1604,8 @@ void MainWindow::setTitlebarForCaptureInProgress() gchar *window_name; setWindowFilePath(NULL); - if (cap_file_) { - window_name = g_strdup_printf("Capturing from %s", cf_get_tempfile_source(cap_file_)); //TODO : Fix Translate + if (capture_file_.capFile()) { + window_name = g_strdup_printf("Capturing from %s", cf_get_tempfile_source(capture_file_.capFile())); //TODO : Fix Translate setWindowTitle(window_name); g_free(window_name); } else { @@ -1617,17 +1620,17 @@ void MainWindow::setMenusForFollowStream() { gboolean is_tcp = FALSE, is_udp = FALSE; - if (!cap_file_) + if (!capture_file_.capFile()) return; - if (!cap_file_->edt) + if (!capture_file_.capFile()->edt) return; main_ui_->actionAnalyzeFollowTCPStream->setEnabled(false); main_ui_->actionAnalyzeFollowUDPStream->setEnabled(false); main_ui_->actionAnalyzeFollowSSLStream->setEnabled(false); - proto_get_frame_protocols(cap_file_->edt->pi.layers, NULL, &is_tcp, &is_udp, NULL, NULL); + proto_get_frame_protocols(capture_file_.capFile()->edt->pi.layers, NULL, &is_tcp, &is_udp, NULL, NULL); if (is_tcp) { @@ -1639,7 +1642,7 @@ void MainWindow::setMenusForFollowStream() main_ui_->actionAnalyzeFollowUDPStream->setEnabled(true); } - if ( epan_dissect_packet_contains_field(cap_file_->edt, "ssl") ) + if ( epan_dissect_packet_contains_field(capture_file_.capFile()->edt, "ssl") ) { main_ui_->actionAnalyzeFollowSSLStream->setEnabled(true); } @@ -1650,7 +1653,7 @@ void MainWindow::setMenusForFollowStream() and whether it could be saved except by copying the raw packet data. */ void MainWindow::setMenusForCaptureFile(bool force_disable) { - if (force_disable || cap_file_ == NULL || cap_file_->state == FILE_READ_IN_PROGRESS) { + if (force_disable || capture_file_.capFile() == NULL || capture_file_.capFile()->state == FILE_READ_IN_PROGRESS) { /* We have no capture file or we're currently reading a file */ main_ui_->actionFileMerge->setEnabled(false); main_ui_->actionFileClose->setEnabled(false); @@ -1665,17 +1668,17 @@ void MainWindow::setMenusForCaptureFile(bool force_disable) main_ui_->menuFileExportObjects->setEnabled(false); main_ui_->actionViewReload->setEnabled(false); } else { - main_ui_->actionFileMerge->setEnabled(cf_can_write_with_wiretap(cap_file_)); + main_ui_->actionFileMerge->setEnabled(cf_can_write_with_wiretap(capture_file_.capFile())); main_ui_->actionFileClose->setEnabled(true); - main_ui_->actionFileSave->setEnabled(cf_can_save(cap_file_)); - main_ui_->actionFileSaveAs->setEnabled(cf_can_save_as(cap_file_)); + main_ui_->actionFileSave->setEnabled(cf_can_save(capture_file_.capFile())); + main_ui_->actionFileSaveAs->setEnabled(cf_can_save_as(capture_file_.capFile())); main_ui_->actionStatisticsCaptureFileProperties->setEnabled(true); /* * "Export Specified Packets..." should be available only if * we can write the file out in at least one format. */ - main_ui_->actionFileExportPackets->setEnabled(cf_can_write_with_wiretap(cap_file_)); + main_ui_->actionFileExportPackets->setEnabled(cf_can_write_with_wiretap(capture_file_.capFile())); main_ui_->menuFileExportPacketDissections->setEnabled(true); main_ui_->actionFileExportPacketBytes->setEnabled(true); main_ui_->actionFileExportPDU->setEnabled(true); diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index 6268845fa8..a31eeaeea7 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -48,16 +48,18 @@ # include <QSocketNotifier> #endif -#include "main_welcome.h" -#include "packet_list.h" +#include "about_dialog.h" +#include "capture_file.h" +#include "capture_file_dialog.h" +#include "capture_file_properties_dialog.h" +#include "capture_interfaces_dialog.h" #include "display_filter_combo.h" -#include "progress_bar.h" #include "file_set_dialog.h" #include "filter_action.h" -#include "capture_file_dialog.h" #include "follow_stream_dialog.h" -#include "capture_interfaces_dialog.h" -#include "about_dialog.h" +#include "main_welcome.h" +#include "packet_list.h" +#include "progress_bar.h" class QAction; class QActionGroup; @@ -108,7 +110,7 @@ private: QSplitter extra_split_; MainWelcome *main_welcome_; DisplayFilterCombo *df_combo_box_; - capture_file *cap_file_; + CaptureFile capture_file_; QFont mono_font_; // XXX - packet_list_, proto_tree_, and byte_view_tab_ should // probably be full-on values instead of pointers. @@ -186,7 +188,7 @@ public slots: void layoutToolbars(); void updateNameResolutionActions(); - void captureCapturePrepared(capture_session *cap_session); + void captureCapturePrepared(capture_session *); void captureCaptureUpdateStarted(capture_session *cap_session); void captureCaptureUpdateFinished(capture_session *cap_session); void captureCaptureFixedStarted(capture_session *cap_session); @@ -194,11 +196,11 @@ public slots: void captureCaptureStopping(capture_session *cap_session); void captureCaptureFailed(capture_session *cap_session); - void captureFileOpened(const capture_file *cf); - void captureFileReadStarted(const capture_file *cf); - void captureFileReadFinished(const capture_file *cf); - void captureFileClosing(const capture_file *cf); - void captureFileClosed(const capture_file *cf); + void captureFileOpened(); + void captureFileReadStarted(); + void captureFileReadFinished(); + void captureFileClosing(); + void captureFileClosed(); void configurationProfileChanged(const gchar *profile_name); void filterExpressionsChanged(); diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 483eb38ecc..b0391c22f8 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -32,8 +32,6 @@ #include "main_window.h" #include "ui_main_window.h" -#include "globals.h" - #ifdef _WIN32 #include <windows.h> #include <io.h> @@ -128,7 +126,7 @@ void MainWindow::openCaptureFile(QString& cf_path, QString& read_filter, unsigne for (;;) { if (cf_path.isEmpty()) { - CaptureFileDialog open_dlg(this, cap_file_, read_filter); + CaptureFileDialog open_dlg(this, capture_file_.capFile(), read_filter); switch (prefs.gui_fileopen_style) { @@ -158,7 +156,7 @@ void MainWindow::openCaptureFile(QString& cf_path, QString& read_filter, unsigne } if (dfilter_compile(read_filter.toUtf8().constData(), &rfcode)) { - cf_set_rfcode(&cfile, rfcode); + cf_set_rfcode(CaptureFile::globalCapFile(), rfcode); } else { /* Not valid. Tell the user, and go back and run the file selection box again once they dismiss the alert. */ @@ -179,20 +177,20 @@ void MainWindow::openCaptureFile(QString& cf_path, QString& read_filter, unsigne } /* Try to open the capture file. This closes the current file if it succeeds. */ - cfile.window = this; - if (cf_open(&cfile, cf_path.toUtf8().constData(), type, FALSE, &err) != CF_OK) { + CaptureFile::globalCapFile()->window = this; + if (cf_open(CaptureFile::globalCapFile(), cf_path.toUtf8().constData(), type, FALSE, &err) != CF_OK) { /* We couldn't open it; don't dismiss the open dialog box, just leave it around so that the user can, after they dismiss the alert box popped up for the open error, try again. */ - cfile.window = NULL; + CaptureFile::globalCapFile()->window = NULL; if (rfcode != NULL) dfilter_free(rfcode); cf_path.clear(); continue; } - switch (cf_read(&cfile, FALSE)) { + switch (cf_read(CaptureFile::globalCapFile(), FALSE)) { case CF_READ_OK: case CF_READ_ERROR: @@ -206,7 +204,7 @@ void MainWindow::openCaptureFile(QString& cf_path, QString& read_filter, unsigne capture file has been closed - just free the capture file name string and return (without changing the last containing directory). */ - cap_file_ = NULL; + capture_file_.setCapFile(NULL); return; } break; @@ -221,7 +219,7 @@ void MainWindow::filterPackets(QString& new_filter, bool force) { cf_status_t cf_status; - cf_status = cf_filter_packets(&cfile, new_filter.toUtf8().data(), force); + cf_status = cf_filter_packets(CaptureFile::globalCapFile(), new_filter.toUtf8().data(), force); if (cf_status == CF_OK) { emit displayFilterSuccess(true); @@ -415,7 +413,7 @@ void MainWindow::filterAction(QString &action_filter, FilterAction::Action actio // Capture callbacks -void MainWindow::captureCapturePrepared(capture_session *cap_session) { +void MainWindow::captureCapturePrepared(capture_session *) { #ifdef HAVE_LIBPCAP setTitlebarForCaptureInProgress(); @@ -429,11 +427,9 @@ void MainWindow::captureCapturePrepared(capture_session *cap_session) { // /* Don't set up main window for a capture file. */ // main_set_for_capture_file(FALSE); main_ui_->mainStack->setCurrentWidget(&master_split_); - cap_file_ = (capture_file *) cap_session->cf; -#else - Q_UNUSED(cap_session) #endif // HAVE_LIBPCAP } + void MainWindow::captureCaptureUpdateStarted(capture_session *cap_session) { Q_UNUSED(cap_session); #ifdef HAVE_LIBPCAP @@ -523,42 +519,38 @@ void MainWindow::captureCaptureFailed(capture_session *cap_session) { } -// Callbacks from cfile.c via WiresharkApplication::captureFileCallback +// Callbacks from cfile.c and file.c via CaptureFile::captureFileCallback -void MainWindow::captureFileOpened(const capture_file *cf) { - if (cf->window != this) return; - cap_file_ = (capture_file *) cf; +void MainWindow::captureFileOpened() { + if (capture_file_.window() != this) return; - file_set_dialog_.fileOpened(cf); + file_set_dialog_.fileOpened(capture_file_.capFile()); setMenusForFileSet(true); - emit setCaptureFile(cap_file_); + emit setCaptureFile(capture_file_.capFile()); } -void MainWindow::captureFileReadStarted(const capture_file *cf) { - if (cf != cap_file_) return; +void MainWindow::captureFileReadStarted() { // tap_param_dlg_update(); /* Set up main window for a capture file. */ // main_set_for_capture_file(TRUE); main_ui_->statusBar->popFileStatus(); - QString msg = QString(tr("Loading: %1")).arg(get_basename(cf->filename)); + QString msg = QString(tr("Loading: %1")).arg(get_basename(capture_file_.capFile()->filename)); main_ui_->statusBar->pushFileStatus(msg); main_ui_->mainStack->setCurrentWidget(&master_split_); WiresharkApplication::processEvents(); } -void MainWindow::captureFileReadFinished(const capture_file *cf) { - if (cf != cap_file_) return; - +void MainWindow::captureFileReadFinished() { gchar *dir_path; - if (!cf->is_tempfile && cf->filename) { + if (!capture_file_.capFile()->is_tempfile && capture_file_.capFile()->filename) { /* Add this filename to the list of recent files in the "Recent Files" submenu */ - add_menu_recent_capture_file(cf->filename); + add_menu_recent_capture_file(capture_file_.capFile()->filename); /* Remember folder for next Open dialog and save it in recent */ - dir_path = get_dirname(g_strdup(cf->filename)); + dir_path = get_dirname(g_strdup(capture_file_.capFile()->filename)); wsApp->setLastOpenDir(dir_path); g_free(dir_path); } @@ -570,14 +562,12 @@ void MainWindow::captureFileReadFinished(const capture_file *cf) { setForCapturedPackets(true); main_ui_->statusBar->popFileStatus(); - QString msg = QString().sprintf("%s", get_basename(cf->filename)); + QString msg = QString().sprintf("%s", get_basename(capture_file_.capFile()->filename)); main_ui_->statusBar->pushFileStatus(msg); - emit setDissectedCaptureFile(cap_file_); + emit setDissectedCaptureFile(capture_file_.capFile()); } -void MainWindow::captureFileClosing(const capture_file *cf) { - if (cf != cap_file_) return; - +void MainWindow::captureFileClosing() { setMenusForCaptureFile(true); setForCapturedPackets(false); setMenusForSelectedPacket(); @@ -591,8 +581,7 @@ void MainWindow::captureFileClosing(const capture_file *cf) { emit setDissectedCaptureFile(NULL); } -void MainWindow::captureFileClosed(const capture_file *cf) { - if (cf != cap_file_) return; +void MainWindow::captureFileClosed() { packets_bar_update(); file_set_dialog_.fileClosed(); @@ -602,7 +591,6 @@ void MainWindow::captureFileClosed(const capture_file *cf) { main_ui_->statusBar->hideExpert(); main_ui_->statusBar->popFileStatus(); - cap_file_ = NULL; if (df_combo_box_) { @@ -694,7 +682,7 @@ void MainWindow::startCapture() { this capture. */ collect_ifaces(&global_capture_opts); - cfile.window = this; + CaptureFile::globalCapFile()->window = this; if (capture_start(&global_capture_opts, &cap_session_, main_window_update)) { /* The capture succeeded, which means the capture filter syntax is valid; add this capture filter to the recent capture filter list. */ @@ -705,7 +693,7 @@ void MainWindow::startCapture() { } } } else { - cfile.window = NULL; + CaptureFile::globalCapFile()->window = NULL; } #endif // HAVE_LIBPCAP } @@ -896,21 +884,21 @@ void MainWindow::setMenusForSelectedPacket() time reference frame). (XXX - why check frame_selected?) */ gboolean another_is_time_ref = FALSE; - if (cap_file_) { - frame_selected = cap_file_->current_frame != NULL; - have_frames = cap_file_->count > 0; - have_marked = frame_selected && cap_file_->marked_count > 0; + if (capture_file_.capFile()) { + frame_selected = capture_file_.capFile()->current_frame != NULL; + have_frames = capture_file_.capFile()->count > 0; + have_marked = frame_selected && capture_file_.capFile()->marked_count > 0; another_is_marked = have_marked && - !(cap_file_->marked_count == 1 && cap_file_->current_frame->flags.marked); - have_filtered = cap_file_->displayed_count > 0 && cap_file_->displayed_count != cap_file_->count; - have_ignored = cap_file_->ignored_count > 0; - have_time_ref = cap_file_->ref_time_count > 0; + !(capture_file_.capFile()->marked_count == 1 && capture_file_.capFile()->current_frame->flags.marked); + have_filtered = capture_file_.capFile()->displayed_count > 0 && capture_file_.capFile()->displayed_count != capture_file_.capFile()->count; + have_ignored = capture_file_.capFile()->ignored_count > 0; + have_time_ref = capture_file_.capFile()->ref_time_count > 0; another_is_time_ref = frame_selected && have_time_ref && - !(cap_file_->ref_time_count == 1 && cap_file_->current_frame->flags.ref_time); + !(capture_file_.capFile()->ref_time_count == 1 && capture_file_.capFile()->current_frame->flags.ref_time); - if (cap_file_->edt) + if (capture_file_.capFile()->edt) { - proto_get_frame_protocols(cap_file_->edt->pi.layers, NULL, &is_tcp, NULL, &is_sctp, NULL); + proto_get_frame_protocols(capture_file_.capFile()->edt->pi.layers, NULL, &is_tcp, NULL, &is_sctp, NULL); } } // if (cfile.edt && cfile.edt->tree) { @@ -952,7 +940,7 @@ void MainWindow::setMenusForSelectedPacket() // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/EditMenu/EditPacket", // frame_selected); //#endif /* WANT_PACKET_EDITOR */ - main_ui_->actionEditPacketComment->setEnabled(frame_selected && wtap_dump_can_write(cap_file_->linktypes, WTAP_COMMENT_PER_PACKET)); + main_ui_->actionEditPacketComment->setEnabled(frame_selected && wtap_dump_can_write(capture_file_.capFile()->linktypes, WTAP_COMMENT_PER_PACKET)); main_ui_->actionEditIgnorePacket->setEnabled(frame_selected); main_ui_->actionEditIgnoreAllDisplayed->setEnabled(have_filtered); @@ -1085,11 +1073,11 @@ void MainWindow::setMenusForSelectedTreeRow(field_info *fi) { // XXX Add commented items below - if (cap_file_) { - cap_file_->finfo_selected = fi; + if (capture_file_.capFile()) { + capture_file_.capFile()->finfo_selected = fi; } - if (cap_file_ != NULL && fi != NULL) { + if (capture_file_.capFile() != NULL && fi != NULL) { /* header_field_info *hfinfo = fi->hfinfo; const char *abbrev; @@ -1104,7 +1092,7 @@ void MainWindow::setMenusForSelectedTreeRow(field_info *fi) { } properties = prefs_is_registered_protocol(abbrev); */ - bool can_match_selected = proto_can_match_selected(cap_file_->finfo_selected, cap_file_->edt); + bool can_match_selected = proto_can_match_selected(capture_file_.capFile()->finfo_selected, capture_file_.capFile()->edt); // set_menu_sensitivity(ui_manager_tree_view_menu, // "/TreeViewPopup/GotoCorrespondingPacket", hfinfo->type == FT_FRAMENUM); // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/Copy", @@ -1159,7 +1147,7 @@ void MainWindow::setMenusForSelectedTreeRow(field_info *fi) { main_ui_->actionAnalyzePAFAndNotSelected->setEnabled(can_match_selected); main_ui_->actionAnalyzePAFOrNotSelected->setEnabled(can_match_selected); - main_ui_->actionViewExpandSubtrees->setEnabled(cap_file_->finfo_selected->tree_type != -1); + main_ui_->actionViewExpandSubtrees->setEnabled(capture_file_.capFile()->finfo_selected->tree_type != -1); // prev_abbrev = g_object_get_data(G_OBJECT(ui_manager_tree_view_menu), "menu_abbrev"); // if (!prev_abbrev || (strcmp (prev_abbrev, abbrev) != 0)) { // /* No previous protocol or protocol changed - update Protocol Preferences menu */ @@ -1239,8 +1227,8 @@ void MainWindow::startInterfaceCapture(bool valid) void MainWindow::redissectPackets() { - if (cap_file_) - cf_redissect_packets(cap_file_); + if (capture_file_.capFile()) + cf_redissect_packets(capture_file_.capFile()); main_ui_->statusBar->expertUpdate(); } @@ -1248,14 +1236,14 @@ void MainWindow::recreatePacketList() { prefs.num_cols = g_list_length(prefs.col_list); - col_cleanup(&cfile.cinfo); - build_column_format_array(&cfile.cinfo, prefs.num_cols, FALSE); + col_cleanup(&CaptureFile::globalCapFile()->cinfo); + build_column_format_array(&CaptureFile::globalCapFile()->cinfo, prefs.num_cols, FALSE); packet_list_->redrawVisiblePackets(); packet_list_->hide(); packet_list_->show(); - cfile.columns_changed = FALSE; /* Reset value */ + CaptureFile::globalCapFile()->columns_changed = FALSE; /* Reset value */ } void MainWindow::fieldsChanged() @@ -1266,21 +1254,21 @@ void MainWindow::fieldsChanged() // Syntax check filter // TODO: Check if syntax filter is still valid after fields have changed // and update background color. - if (cfile.dfilter) { + if (CaptureFile::globalCapFile()->dfilter) { // Check if filter is still valid dfilter_t *dfp = NULL; - if (!dfilter_compile(cfile.dfilter, &dfp)) { + if (!dfilter_compile(CaptureFile::globalCapFile()->dfilter, &dfp)) { // TODO: Not valid, enable "Apply" button. - g_free(cfile.dfilter); - cfile.dfilter = NULL; + g_free(CaptureFile::globalCapFile()->dfilter); + CaptureFile::globalCapFile()->dfilter = NULL; } dfilter_free(dfp); } - if (have_custom_cols(&cfile.cinfo)) { + if (have_custom_cols(&CaptureFile::globalCapFile()->cinfo)) { /* Recreate packet list according to new/changed/deleted fields */ recreatePacketList(); - } else if (cfile.state != FILE_CLOSED) { + } else if (CaptureFile::globalCapFile()->state != FILE_CLOSED) { /* Redissect packets if we have any */ redissectPackets(); } @@ -1374,12 +1362,12 @@ void MainWindow::on_actionFileClose_triggered() { void MainWindow::on_actionFileSave_triggered() { - saveCaptureFile(cap_file_, FALSE); + saveCaptureFile(capture_file_.capFile(), FALSE); } void MainWindow::on_actionFileSaveAs_triggered() { - saveAsCaptureFile(cap_file_, FALSE, TRUE); + saveAsCaptureFile(capture_file_.capFile(), FALSE, TRUE); } void MainWindow::on_actionFileSetListFiles_triggered() @@ -1441,7 +1429,7 @@ void MainWindow::on_actionFileExportPacketBytes_triggered() { QString file_name; - if (!cap_file_ || !cap_file_->finfo_selected) return; + if (!capture_file_.capFile() || !capture_file_.capFile()->finfo_selected) return; file_name = QFileDialog::getSaveFileName(this, tr("Wireshark: Export Selected Packet Bytes"), @@ -1453,14 +1441,14 @@ void MainWindow::on_actionFileExportPacketBytes_triggered() const guint8 *data_p; int fd; - data_p = tvb_get_ptr(cap_file_->finfo_selected->ds_tvb, 0, -1) + - cap_file_->finfo_selected->start; + data_p = tvb_get_ptr(capture_file_.capFile()->finfo_selected->ds_tvb, 0, -1) + + capture_file_.capFile()->finfo_selected->start; fd = ws_open(file_name.toUtf8().constData(), O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666); if (fd == -1) { open_failure_alert_box(file_name.toUtf8().constData(), errno, TRUE); return; } - if (write(fd, data_p, cfile.finfo_selected->length) < 0) { + if (write(fd, data_p, capture_file_.capFile()->finfo_selected->length) < 0) { write_failure_alert_box(file_name.toUtf8().constData(), errno); ::close(fd); return; @@ -1552,27 +1540,27 @@ void MainWindow::on_actionFileExportSSLSessionKeys_triggered() void MainWindow::on_actionFileExportObjectsDICOM_triggered() { - new ExportObjectDialog(this, cap_file_, ExportObjectDialog::Dicom); + new ExportObjectDialog(this, capture_file_.capFile(), ExportObjectDialog::Dicom); } void MainWindow::on_actionFileExportObjectsHTTP_triggered() { - new ExportObjectDialog(this, cap_file_, ExportObjectDialog::Http); + new ExportObjectDialog(this, capture_file_.capFile(), ExportObjectDialog::Http); } void MainWindow::on_actionFileExportObjectsSMB_triggered() { - new ExportObjectDialog(this, cap_file_, ExportObjectDialog::Smb); + new ExportObjectDialog(this, capture_file_.capFile(), ExportObjectDialog::Smb); } void MainWindow::on_actionFileExportObjectsTFTP_triggered() { - new ExportObjectDialog(this, cap_file_, ExportObjectDialog::Tftp); + new ExportObjectDialog(this, capture_file_.capFile(), ExportObjectDialog::Tftp); } void MainWindow::on_actionFilePrint_triggered() { - PrintDialog pdlg(this, cap_file_); + PrintDialog pdlg(this, capture_file_.capFile()); pdlg.exec(); } @@ -1585,23 +1573,23 @@ void MainWindow::actionEditCopyTriggered(MainWindow::CopySelected selection_type char label_str[ITEM_LABEL_LENGTH]; QString clip; - if (!cap_file_) return; + if (!capture_file_.capFile()) return; switch(selection_type) { case CopySelectedDescription: - if (cap_file_->finfo_selected->rep && - strlen (cap_file_->finfo_selected->rep->representation) > 0) { - clip.append(cap_file_->finfo_selected->rep->representation); + if (capture_file_.capFile()->finfo_selected->rep && + strlen (capture_file_.capFile()->finfo_selected->rep->representation) > 0) { + clip.append(capture_file_.capFile()->finfo_selected->rep->representation); } break; case CopySelectedFieldName: - if (cap_file_->finfo_selected->hfinfo->abbrev != 0) { - clip.append(cap_file_->finfo_selected->hfinfo->abbrev); + if (capture_file_.capFile()->finfo_selected->hfinfo->abbrev != 0) { + clip.append(capture_file_.capFile()->finfo_selected->hfinfo->abbrev); } break; case CopySelectedValue: - if (cap_file_->edt != 0) { - gchar* field_str = get_node_field_value(cap_file_->finfo_selected, cap_file_->edt); + if (capture_file_.capFile()->edt != 0) { + gchar* field_str = get_node_field_value(capture_file_.capFile()->finfo_selected, capture_file_.capFile()->edt); clip.append(field_str); g_free(field_str); } @@ -1610,7 +1598,7 @@ void MainWindow::actionEditCopyTriggered(MainWindow::CopySelected selection_type if (clip.length() == 0) { /* If no representation then... Try to read the value */ - proto_item_fill_label(cap_file_->finfo_selected, label_str); + proto_item_fill_label(capture_file_.capFile()->finfo_selected, label_str); clip.append(label_str); } @@ -1684,14 +1672,14 @@ void MainWindow::on_actionEditUnmarkAllDisplayed_triggered() void MainWindow::on_actionEditNextMark_triggered() { - if (cap_file_) - cf_find_packet_marked(cap_file_, SD_FORWARD); + if (capture_file_.capFile()) + cf_find_packet_marked(capture_file_.capFile(), SD_FORWARD); } void MainWindow::on_actionEditPreviousMark_triggered() { - if (cap_file_) - cf_find_packet_marked(cap_file_, SD_BACKWARD); + if (capture_file_.capFile()) + cf_find_packet_marked(capture_file_.capFile(), SD_BACKWARD); } void MainWindow::on_actionEditIgnorePacket_triggered() @@ -1721,19 +1709,19 @@ void MainWindow::on_actionEditUnsetAllTimeReferences_triggered() void MainWindow::on_actionEditNextTimeReference_triggered() { - if (!cap_file_) return; - cf_find_packet_time_reference(cap_file_, SD_FORWARD); + if (!capture_file_.capFile()) return; + cf_find_packet_time_reference(capture_file_.capFile(), SD_FORWARD); } void MainWindow::on_actionEditPreviousTimeReference_triggered() { - if (!cap_file_) return; - cf_find_packet_time_reference(cap_file_, SD_BACKWARD); + if (!capture_file_.capFile()) return; + cf_find_packet_time_reference(capture_file_.capFile(), SD_BACKWARD); } void MainWindow::on_actionEditTimeShift_triggered() { - TimeShiftDialog ts_dialog(this, cap_file_); + TimeShiftDialog ts_dialog(this, capture_file_.capFile()); connect(this, SIGNAL(setCaptureFile(capture_file*)), &ts_dialog, SLOT(setCaptureFile(capture_file*))); ts_dialog.exec(); @@ -1810,9 +1798,9 @@ void MainWindow::setTimestampFormat(QAction *action) if (recent.gui_time_format != tsf) { timestamp_set_type(tsf); recent.gui_time_format = tsf; - if (cap_file_) { + if (capture_file_.capFile()) { /* This call adjusts column width */ - cf_timestamp_auto_precision(cap_file_); + cf_timestamp_auto_precision(capture_file_.capFile()); } if (packet_list_) { packet_list_->redrawVisiblePackets(); @@ -1832,9 +1820,9 @@ void MainWindow::setTimestampPrecision(QAction *action) /* the actual precision will be set in packet_list_queue_draw() below */ timestamp_set_precision(tsp); recent.gui_time_precision = tsp; - if (cap_file_) { + if (capture_file_.capFile()) { /* This call adjusts column width */ - cf_timestamp_auto_precision(cap_file_); + cf_timestamp_auto_precision(capture_file_.capFile()); } if (packet_list_) { packet_list_->redrawVisiblePackets(); @@ -1851,9 +1839,9 @@ void MainWindow::on_actionViewTimeDisplaySecondsWithHoursAndMinutes_triggered(bo } timestamp_set_seconds_type(recent.gui_seconds_format); - if (cap_file_) { + if (capture_file_.capFile()) { /* This call adjusts column width */ - cf_timestamp_auto_precision(cap_file_); + cf_timestamp_auto_precision(capture_file_.capFile()); } if (packet_list_) { packet_list_->redrawVisiblePackets(); @@ -1932,7 +1920,7 @@ void MainWindow::on_actionViewResizeColumns_triggered() void MainWindow::on_actionViewReload_triggered() { - cf_reload(&cfile); + cf_reload(CaptureFile::globalCapFile()); } // Expand / collapse slots in proto_tree @@ -1948,9 +1936,9 @@ void MainWindow::matchFieldFilter(FilterAction::Action action, FilterAction::Act if (packet_list_->contextMenuActive()) { field_filter = packet_list_->getFilterFromRowAndColumn(); - } else if (cap_file_ && cap_file_->finfo_selected) { - field_filter = proto_construct_match_selected_string(cap_file_->finfo_selected, - cap_file_->edt); + } else if (capture_file_.capFile() && capture_file_.capFile()->finfo_selected) { + field_filter = proto_construct_match_selected_string(capture_file_.capFile()->finfo_selected, + capture_file_.capFile()->edt); } else { return; } @@ -2037,14 +2025,14 @@ void MainWindow::on_actionAnalyzeDecodeAs_triggered() create_new = true; } - DecodeAsDialog da_dialog(this, cap_file_, create_new); + DecodeAsDialog da_dialog(this, capture_file_.capFile(), create_new); connect(this, SIGNAL(setCaptureFile(capture_file*)), &da_dialog, SLOT(setCaptureFile(capture_file*))); da_dialog.exec(); } void MainWindow::openFollowStreamDialog(follow_type_t type) { - FollowStreamDialog *fsd = new FollowStreamDialog(this, type, cap_file_); + FollowStreamDialog *fsd = new FollowStreamDialog(this, type, capture_file_.capFile()); connect(fsd, SIGNAL(updateFilter(QString&, bool)), this, SLOT(filterPackets(QString&, bool))); connect(fsd, SIGNAL(goToPacket(int)), packet_list_, SLOT(goToPacket(int))); @@ -2069,7 +2057,7 @@ void MainWindow::on_actionAnalyzeFollowSSLStream_triggered() void MainWindow::openSCTPAllAssocsDialog() { - SCTPAllAssocsDialog *sctp_dialog = new SCTPAllAssocsDialog(this, cap_file_); + SCTPAllAssocsDialog *sctp_dialog = new SCTPAllAssocsDialog(this, capture_file_.capFile()); connect(sctp_dialog, SIGNAL(filterPackets(QString&,bool)), this, SLOT(filterPackets(QString&,bool))); connect(this, SIGNAL(setCaptureFile(capture_file*)), @@ -2096,7 +2084,7 @@ void MainWindow::on_actionSCTPShowAllAssociations_triggered() void MainWindow::on_actionSCTPAnalyseThisAssociation_triggered() { - SCTPAssocAnalyseDialog *sctp_analyse = new SCTPAssocAnalyseDialog(this, NULL, cap_file_); + SCTPAssocAnalyseDialog *sctp_analyse = new SCTPAssocAnalyseDialog(this, NULL, capture_file_.capFile()); connect(sctp_analyse, SIGNAL(filterPackets(QString&,bool)), this, SLOT(filterPackets(QString&,bool))); @@ -2115,7 +2103,7 @@ void MainWindow::on_actionSCTPAnalyseThisAssociation_triggered() void MainWindow::on_actionSCTPFilterThisAssociation_triggered() { - sctp_assoc_info_t* assoc = SCTPAssocAnalyseDialog::findAssocForPacket(cap_file_); + sctp_assoc_info_t* assoc = SCTPAssocAnalyseDialog::findAssocForPacket(capture_file_.capFile()); if (assoc) { QString newFilter = QString("sctp.assoc_index==%1").arg(assoc->assoc_id); assoc = NULL; @@ -2130,7 +2118,7 @@ void MainWindow::on_actionSCTPFilterThisAssociation_triggered() void MainWindow::on_actionStatisticsFlowGraph_triggered() { - SequenceDialog *sequence_dialog = new SequenceDialog(this, cap_file_); + SequenceDialog *sequence_dialog = new SequenceDialog(this, capture_file_.capFile()); connect(sequence_dialog, SIGNAL(goToPacket(int)), packet_list_, SLOT(goToPacket(int))); connect(this, SIGNAL(setCaptureFile(capture_file*)), @@ -2140,7 +2128,7 @@ void MainWindow::on_actionStatisticsFlowGraph_triggered() void MainWindow::openTcpStreamDialog(int graph_type) { - TCPStreamDialog *stream_dialog = new TCPStreamDialog(this, cap_file_, (tcp_graph_type)graph_type); + TCPStreamDialog *stream_dialog = new TCPStreamDialog(this, capture_file_.capFile(), (tcp_graph_type)graph_type); connect(stream_dialog, SIGNAL(goToPacket(int)), packet_list_, SLOT(goToPacket(int))); connect(this, SIGNAL(setCaptureFile(capture_file*)), @@ -2175,7 +2163,7 @@ void MainWindow::on_actionStatisticsTcpStreamWindowScaling_triggered() void MainWindow::openStatisticsTreeDialog(const gchar *abbr) { - StatsTreeDialog *st_dialog = new StatsTreeDialog(this, cap_file_, abbr); + StatsTreeDialog *st_dialog = new StatsTreeDialog(this, capture_file_.capFile(), abbr); // connect(st_dialog, SIGNAL(goToPacket(int)), // packet_list_, SLOT(goToPacket(int))); connect(this, SIGNAL(setCaptureFile(capture_file*)), @@ -2240,7 +2228,7 @@ void MainWindow::on_actionStatistics29WestQueues_Queries_by_Receiver_triggered() void MainWindow::on_actionStatistics29WestUIM_Streams_triggered() { - LBMStreamDialog *stream_dialog = new LBMStreamDialog(this, cap_file_); + LBMStreamDialog *stream_dialog = new LBMStreamDialog(this, capture_file_.capFile()); // connect(stream_dialog, SIGNAL(goToPacket(int)), // packet_list_, SLOT(goToPacket(int))); connect(this, SIGNAL(setCaptureFile(capture_file*)), @@ -2250,7 +2238,7 @@ void MainWindow::on_actionStatistics29WestUIM_Streams_triggered() void MainWindow::on_actionStatistics29WestUIM_Stream_Flow_Graph_triggered() { - LBMUIMFlowDialog * uimflow_dialog = new LBMUIMFlowDialog(this, cap_file_); + LBMUIMFlowDialog * uimflow_dialog = new LBMUIMFlowDialog(this, capture_file_.capFile()); connect(uimflow_dialog, SIGNAL(goToPacket(int)), packet_list_, SLOT(goToPacket(int))); connect(this, SIGNAL(setCaptureFile(capture_file*)), @@ -2260,7 +2248,7 @@ void MainWindow::on_actionStatistics29WestUIM_Stream_Flow_Graph_triggered() void MainWindow::on_actionStatistics29WestLBTRM_triggered() { - LBMLBTRMTransportDialog * lbtrm_dialog = new LBMLBTRMTransportDialog(this, cap_file_); + LBMLBTRMTransportDialog * lbtrm_dialog = new LBMLBTRMTransportDialog(this, capture_file_.capFile()); connect(lbtrm_dialog, SIGNAL(goToPacket(int)), packet_list_, SLOT(goToPacket(int))); connect(this, SIGNAL(setCaptureFile(capture_file*)), @@ -2269,7 +2257,7 @@ void MainWindow::on_actionStatistics29WestLBTRM_triggered() } void MainWindow::on_actionStatistics29WestLBTRU_triggered() { - LBMLBTRUTransportDialog * lbtru_dialog = new LBMLBTRUTransportDialog(this, cap_file_); + LBMLBTRUTransportDialog * lbtru_dialog = new LBMLBTRUTransportDialog(this, capture_file_.capFile()); connect(lbtru_dialog, SIGNAL(goToPacket(int)), packet_list_, SLOT(goToPacket(int))); connect(this, SIGNAL(setCaptureFile(capture_file*)), @@ -2309,7 +2297,7 @@ void MainWindow::on_actionStatisticsCollectd_triggered() void MainWindow::statCommandConversations(const char *arg, void *userdata) { - ConversationDialog *conv_dialog = new ConversationDialog(this, cap_file_, GPOINTER_TO_INT(userdata), arg); + ConversationDialog *conv_dialog = new ConversationDialog(this, capture_file_.capFile(), GPOINTER_TO_INT(userdata), arg); connect(conv_dialog, SIGNAL(filterAction(QString&,FilterAction::Action,FilterAction::ActionType)), this, SLOT(filterAction(QString&,FilterAction::Action,FilterAction::ActionType))); connect(conv_dialog, SIGNAL(openFollowStreamDialog(follow_type_t)), @@ -2328,7 +2316,7 @@ void MainWindow::on_actionStatisticsConversations_triggered() void MainWindow::statCommandEndpoints(const char *arg, void *userdata) { - EndpointDialog *endp_dialog = new EndpointDialog(this, cap_file_, GPOINTER_TO_INT(userdata), arg); + EndpointDialog *endp_dialog = new EndpointDialog(this, capture_file_.capFile(), GPOINTER_TO_INT(userdata), arg); connect(endp_dialog, SIGNAL(filterAction(QString&,FilterAction::Action,FilterAction::ActionType)), this, SLOT(filterAction(QString&,FilterAction::Action,FilterAction::ActionType))); connect(endp_dialog, SIGNAL(openFollowStreamDialog(follow_type_t)), @@ -2374,7 +2362,7 @@ void MainWindow::statCommandIOGraph(const char *arg, void *userdata) { Q_UNUSED(arg); Q_UNUSED(userdata); - IOGraphDialog *iog_dialog = new IOGraphDialog(this, cap_file_); + IOGraphDialog *iog_dialog = new IOGraphDialog(this, capture_file_.capFile()); connect(iog_dialog, SIGNAL(goToPacket(int)), packet_list_, SLOT(goToPacket(int))); connect(this, SIGNAL(setCaptureFile(capture_file*)), iog_dialog, SLOT(setCaptureFile(capture_file*))); @@ -2394,7 +2382,7 @@ void MainWindow::on_actionStatisticsSametime_triggered() void MainWindow::openVoipCallsDialog(bool all_flows) { - VoipCallsDialog *voip_calls_dialog = new VoipCallsDialog(this, cap_file_, all_flows); + VoipCallsDialog *voip_calls_dialog = new VoipCallsDialog(this, capture_file_.capFile(), all_flows); connect(voip_calls_dialog, SIGNAL(goToPacket(int)), packet_list_, SLOT(goToPacket(int))); connect(voip_calls_dialog, SIGNAL(updateFilter(QString&, bool)), @@ -2629,7 +2617,7 @@ void MainWindow::on_actionCaptureStop_triggered() void MainWindow::on_actionStatisticsCaptureFileProperties_triggered() { - CaptureFilePropertiesDialog *capture_file_properties_dialog = new CaptureFilePropertiesDialog(this, cap_file_); + CaptureFilePropertiesDialog *capture_file_properties_dialog = new CaptureFilePropertiesDialog(this, capture_file_.capFile()); connect(capture_file_properties_dialog, SIGNAL(captureCommentChanged()), this, SLOT(updateForUnsavedChanges())); connect(this, SIGNAL(setCaptureFile(capture_file*)), diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp index d17ebe0f4b..426db1a60d 100644 --- a/ui/qt/wireshark_application.cpp +++ b/ui/qt/wireshark_application.cpp @@ -206,114 +206,6 @@ void WiresharkApplication::updateTaps() draw_tap_listeners(FALSE); } -void WiresharkApplication::captureCallback(int event _U_, capture_session *cap_session _U_) -{ -#ifdef HAVE_LIBPCAP - switch(event) { - case(capture_cb_capture_prepared): - g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture prepared"); - emit captureCapturePrepared(cap_session); - break; - case(capture_cb_capture_update_started): - g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update started"); - emit captureCaptureUpdateStarted(cap_session); - break; - case(capture_cb_capture_update_continue): - g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update continue"); - emit captureCaptureUpdateContinue(cap_session); - break; - case(capture_cb_capture_update_finished): - g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update finished"); - emit captureCaptureUpdateFinished(cap_session); - break; - case(capture_cb_capture_fixed_started): - g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed started"); - emit captureCaptureFixedStarted(cap_session); - break; - case(capture_cb_capture_fixed_continue): - g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed continue"); - break; - case(capture_cb_capture_fixed_finished): - g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed finished"); - emit captureCaptureFixedFinished(cap_session); - break; - case(capture_cb_capture_stopping): - g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture stopping"); - /* Beware: this state won't be called, if the capture child - * closes the capturing on it's own! */ - emit captureCaptureStopping(cap_session); - break; - case(capture_cb_capture_failed): - g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture failed"); - emit captureCaptureFailed(cap_session); - break; - default: - g_warning("main_capture_callback: event %u unknown", event); - g_assert_not_reached(); - } -#endif // HAVE_LIBPCAP -} - -void WiresharkApplication::captureFileCallback(int event, void * data) -{ - capture_file *cf = (capture_file *) data; - - switch(event) { - - case(cf_cb_file_opened): - g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Opened"); - emit captureFileOpened(cf); - break; - case(cf_cb_file_closing): - g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Closing"); - emit captureFileClosing(cf); - break; - case(cf_cb_file_closed): - g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Closed"); - emit captureFileClosed(cf); - break; - case(cf_cb_file_read_started): - g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Read started"); - emit captureFileReadStarted(cf); - QTimer::singleShot(TAP_UPDATE_DEFAULT_INTERVAL / 5, this, SLOT(updateTaps())); - QTimer::singleShot(TAP_UPDATE_DEFAULT_INTERVAL / 2, this, SLOT(updateTaps())); - break; - case(cf_cb_file_read_finished): - g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Read finished"); - emit captureFileReadFinished(cf); - updateTaps(); - break; - case(cf_cb_file_reload_started): - g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Reload started"); - emit captureFileReadStarted(cf); - break; - case(cf_cb_file_reload_finished): - g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Reload finished"); - emit captureFileReadFinished(cf); - break; - - case(cf_cb_packet_selected): - case(cf_cb_packet_unselected): - case(cf_cb_field_unselected): - // Pure signals and slots - break; - -// case(cf_cb_file_save_started): // data = string -// g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Save started"); -// break; -// case(cf_cb_file_save_finished): -// g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Save finished"); -// break; -// case(cf_cb_file_save_failed): -// g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Save failed"); -// break; - default: - g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: main_cf_callback %d %p", event, data); -// g_warning("main_cf_callback: event %u unknown", event); -// g_assert_not_reached(); - } -} - QDir WiresharkApplication::lastOpenDir() { return QDir(last_open_dir); } @@ -532,6 +424,13 @@ void WiresharkApplication::clearRecentItems() { emit updateRecentItemStatus(NULL, 0, false); } +void WiresharkApplication::captureFileReadStarted() +{ + // Doesn't appear to do anything. Logic probably needs to be in file.c. + QTimer::singleShot(TAP_UPDATE_DEFAULT_INTERVAL / 5, this, SLOT(updateTaps())); + QTimer::singleShot(TAP_UPDATE_DEFAULT_INTERVAL / 2, this, SLOT(updateTaps())); +} + void WiresharkApplication::cleanup() { software_update_cleanup(); diff --git a/ui/qt/wireshark_application.h b/ui/qt/wireshark_application.h index 981dc8e74c..f6f43e8632 100644 --- a/ui/qt/wireshark_application.h +++ b/ui/qt/wireshark_application.h @@ -82,8 +82,6 @@ public: e_prefs * readConfigurationFiles(char **gdp_path, char **dp_path); QList<recent_item_status *> recentItems() const; void addRecentItem(const QString &filename, qint64 size, bool accessible); - void captureCallback(int event, capture_session * cap_session); - void captureFileCallback(int event, void * data); QDir lastOpenDir(); void setLastOpenDir(const char *dir_name); void setLastOpenDir(QString *dir_str); @@ -130,7 +128,7 @@ signals: void addressResolutionChanged(); void fieldsChanged(); - // XXX It might make more sense to move these to main.cpp or main_window.cpp or their own class. +#if 0 void captureCapturePrepared(capture_session *cap_session); void captureCaptureUpdateStarted(capture_session *cap_session); void captureCaptureUpdateContinue(capture_session *cap_session); @@ -139,17 +137,22 @@ signals: void captureCaptureFixedFinished(capture_session *cap_session); void captureCaptureStopping(capture_session *cap_session); void captureCaptureFailed(capture_session *cap_session); +#endif +#if 0 void captureFileOpened(const capture_file *cf); void captureFileReadStarted(const capture_file *cf); void captureFileReadFinished(const capture_file *cf); void captureFileClosing(const capture_file *cf); void captureFileClosed(const capture_file *cf); +#endif void openStatCommandDialog(const QString &menu_path, const char *arg, void *userdata); public slots: void clearRecentItems(); + void captureFileReadStarted(); + void updateTaps(); private slots: void cleanup(); @@ -157,7 +160,6 @@ private slots: void itemStatusFinished(const QString filename = "", qint64 size = 0, bool accessible = false); void refreshRecentFiles(void); void refreshAddressResolution(void); - void updateTaps(); }; extern WiresharkApplication *wsApp; |