diff options
author | Paul Offord <paul.offord@advance7.com> | 2017-11-05 10:39:54 +0000 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2017-11-07 11:50:23 +0000 |
commit | d84d43372c3aee0ae5a1dd30edff8243acf41f14 (patch) | |
tree | 6a446d6f6deb5e8da52f09603bf55def2212d357 | |
parent | fa2649ac61755b462ec49ea0a2bbfb8569dd0bad (diff) |
Improvement to plugin_if_get_ws_info(...) functionality
A plugin can register an initialisation function to be called each time
Wireshark opens a new capture file. If plugin_if_get_ws_info(...) is
called from within the initialisation function it does not return the
name of the file being opened. This is because
plugin_if_get_ws_info(...), through calls to a number of other
functions, gets the file name details from a capture_file structure. At
the time of the call to the plugins initialisation function, the
capture_file structure in question has not yet been created.
This change ensures that if plugin_if_get_ws_info(...) is called from a
plugin's initialisation function, the name of the file to be open is
correctly returned. The change also fixes a bug where
plugin_if_ws_get(...) returns an incorrect file state if called from a
plugin initialisation function.
Bug: 14165
Change-Id: I28c85e480db96852e11bbaa14fb1f434b457ed52
Reviewed-on: https://code.wireshark.org/review/24251
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r-- | ui/qt/main_window.cpp | 71 | ||||
-rw-r--r-- | ui/qt/main_window.h | 7 | ||||
-rw-r--r-- | ui/qt/main_window_slots.cpp | 3 |
3 files changed, 69 insertions, 12 deletions
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index c2f0718515..bbaced0077 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -179,30 +179,63 @@ static void plugin_if_mainwindow_get_ws_info(gconstpointer user_data) ws_info->ws_info_supported = true; + /* If we have a filename attached to ws_info clear it */ + if (ws_info->cf_filename != NULL) + { + g_free(ws_info->cf_filename); + ws_info->cf_filename = NULL; + } + + /* Determine the true state of the capture file. We return the true state in + the ws_info structure and DON'T CHANGE the cf->state as we don't want to cause problems + with code that follows this. */ + if (cf) + { + if (cf->filename) + { + /* As we have a cf->filename we'll use the name and the state */ + ws_info->cf_filename = g_strdup(cf->filename); + ws_info->cf_state = cf->state; + } + else + { + /* When we come through here the cf->state can show FILE_READ_DONE even though the + file is actually closed (no filename). A better fix would be to have a + FILE_CLOSE_PENDING state but that involves a lot of code change elsewhere. */ + ws_info->cf_state = FILE_CLOSED; + } + } + + if (!ws_info->cf_filename) + { + /* We may have a filename associated with the main window so let's use it */ + QString fileNameString = gbl_cur_main_window_->getMwFileName(); + if (fileNameString.length()) + { + QByteArray ba = fileNameString.toLatin1(); + const char *c_file_name = ba.data(); + ws_info->cf_filename = g_strdup(c_file_name); + } + } + if (cf) { - ws_info->cf_state = cf->state; ws_info->cf_count = cf->count; - g_free(ws_info->cf_filename); - ws_info->cf_filename = g_strdup(cf->filename); - if (cf->state == FILE_READ_DONE && cf->current_frame) { ws_info->cf_framenr = cf->current_frame->num; ws_info->frame_passed_dfilter = (cf->current_frame->flags.passed_dfilter == 1); - } else { + } + 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 */ + } + else + { + /* Initialise the other ws_info structure values */ ws_info->cf_count = 0; - - 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; } } @@ -1890,6 +1923,9 @@ bool MainWindow::testCaptureFileClose(QString before_what, FileCloseContext cont return true; } #endif + /* Clear MainWindow file name details */ + gbl_cur_main_window_->setMwFileName(""); + /* captureStop() will close the file if not having any packets */ if (capture_file_.capFile() && context != Restart && context != Reload) // Don't really close if Restart or Reload @@ -2829,6 +2865,17 @@ void MainWindow::removeAdditionalToolbar(QString toolbarName) } +QString MainWindow::getMwFileName() +{ + return mwFileName_; +} + +void MainWindow::setMwFileName(QString fileName) +{ + mwFileName_ = fileName; + return; +} + /* * Editor modelines diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index 77c8c35b03..74f95da95f 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -109,6 +109,9 @@ public: void addInterfaceToolbar(const iface_toolbar *toolbar_entry); void removeInterfaceToolbar(const gchar *menu_title); + QString getMwFileName(); + void setMwFileName(QString fileName); + protected: virtual bool eventFilter(QObject *obj, QEvent *event); virtual void keyPressEvent(QKeyEvent *event); @@ -173,6 +176,10 @@ private: DragDropToolBar *filter_expression_toolbar_; bool was_maximized_; + /* the following values are maintained so that the capture file name and status + is available when there is no cf structure available */ + QString mwFileName_; + bool capture_stopping_; bool capture_filter_valid_; #ifdef HAVE_LIBPCAP diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index c4068eab80..2cced5b4c3 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -242,6 +242,9 @@ bool MainWindow::openCaptureFile(QString cf_path, QString read_filter, unsigned } } + /* Make the file name available via MainWindow */ + setMwFileName(cf_path); + /* Try to open the capture file. This closes the current file if it succeeds. */ CaptureFile::globalCapFile()->window = this; if (cf_open(CaptureFile::globalCapFile(), cf_path.toUtf8().constData(), type, is_tempfile, &err) != CF_OK) { |