From d84d43372c3aee0ae5a1dd30edff8243acf41f14 Mon Sep 17 00:00:00 2001 From: Paul Offord Date: Sun, 5 Nov 2017 10:39:54 +0000 Subject: 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 Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- ui/qt/main_window.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 12 deletions(-) (limited to 'ui/qt/main_window.cpp') 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 -- cgit v1.2.3