2014-12-22 23:51:36 +00:00
|
|
|
/* wireshark_dialog.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 "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2015-08-24 19:30:56 +00:00
|
|
|
#include "cfile.h"
|
|
|
|
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/tap.h>
|
|
|
|
|
2016-02-28 18:23:20 +00:00
|
|
|
#include "wireshark_application.h"
|
2014-12-22 23:51:36 +00:00
|
|
|
#include "wireshark_dialog.h"
|
2017-07-25 14:15:18 +00:00
|
|
|
#include <ui/qt/utils/qt_ui_utils.h>
|
2016-02-28 18:23:20 +00:00
|
|
|
#include "ui/recent.h"
|
2017-10-14 20:14:14 +00:00
|
|
|
#include "ui/ws_ui_util.h"
|
2014-12-22 23:51:36 +00:00
|
|
|
|
2015-08-24 19:30:56 +00:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
2014-12-22 23:51:36 +00:00
|
|
|
|
|
|
|
// To do:
|
|
|
|
// - Use a dynamic property + Q_PROPERTY for the subtitle.
|
2015-08-26 19:48:56 +00:00
|
|
|
// - Make our nested event loop more robust. See tryDeleteLater for details.
|
2014-12-22 23:51:36 +00:00
|
|
|
|
2016-06-24 17:52:44 +00:00
|
|
|
WiresharkDialog::WiresharkDialog(QWidget &parent, CaptureFile &capture_file) :
|
|
|
|
GeometryStateDialog(&parent, Qt::Window),
|
2014-12-22 23:51:36 +00:00
|
|
|
cap_file_(capture_file),
|
2015-08-24 19:30:56 +00:00
|
|
|
file_closed_(false),
|
|
|
|
retap_depth_(0),
|
|
|
|
dialog_closed_(false)
|
2014-12-22 23:51:36 +00:00
|
|
|
{
|
2015-02-17 20:29:31 +00:00
|
|
|
setWindowIcon(wsApp->normalIcon());
|
2015-08-24 19:30:56 +00:00
|
|
|
setWindowTitleFromSubtitle();
|
|
|
|
|
|
|
|
connect(&cap_file_, SIGNAL(captureFileRetapStarted()), this, SLOT(beginRetapPackets()));
|
2015-08-26 19:48:56 +00:00
|
|
|
connect(&cap_file_, SIGNAL(captureFileRetapFinished()), this, SLOT(endRetapPackets()));
|
2014-12-22 23:51:36 +00:00
|
|
|
connect(&cap_file_, SIGNAL(captureFileClosing()), this, SLOT(captureFileClosing()));
|
2015-09-25 09:05:45 +00:00
|
|
|
connect(&cap_file_, SIGNAL(captureFileClosed()), this, SLOT(captureFileClosed()));
|
2014-12-22 23:51:36 +00:00
|
|
|
}
|
|
|
|
|
2015-07-24 17:24:15 +00:00
|
|
|
void WiresharkDialog::accept()
|
|
|
|
{
|
|
|
|
QDialog::accept();
|
2015-08-24 19:30:56 +00:00
|
|
|
|
|
|
|
// Cancel any taps in progress?
|
|
|
|
// cap_file_.setCaptureStopFlag();
|
|
|
|
removeTapListeners();
|
|
|
|
dialog_closed_ = true;
|
|
|
|
tryDeleteLater();
|
2015-07-24 17:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Should we do this in WiresharkDialog?
|
|
|
|
void WiresharkDialog::reject()
|
|
|
|
{
|
|
|
|
QDialog::reject();
|
2015-08-24 19:30:56 +00:00
|
|
|
|
|
|
|
// Cancel any taps in progress?
|
|
|
|
// cap_file_.setCaptureStopFlag();
|
|
|
|
removeTapListeners();
|
|
|
|
dialog_closed_ = true;
|
|
|
|
tryDeleteLater();
|
2015-07-24 17:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-22 23:51:36 +00:00
|
|
|
void WiresharkDialog::setWindowSubtitle(const QString &subtitle)
|
|
|
|
{
|
|
|
|
subtitle_ = subtitle;
|
2014-12-29 22:12:43 +00:00
|
|
|
setWindowTitleFromSubtitle();
|
2014-12-22 23:51:36 +00:00
|
|
|
}
|
|
|
|
|
2014-12-29 22:12:43 +00:00
|
|
|
void WiresharkDialog::setWindowTitleFromSubtitle()
|
2014-12-22 23:51:36 +00:00
|
|
|
{
|
|
|
|
QString title = wsApp->windowTitleString(QStringList() << subtitle_ << cap_file_.fileTitle());
|
|
|
|
QDialog::setWindowTitle(title);
|
|
|
|
}
|
|
|
|
|
2015-08-24 19:30:56 +00:00
|
|
|
// See if we can destroy ourselves. The user may have clicked "Close" while
|
|
|
|
// we were deep in the bowels of a routine that retaps packets. Track our
|
|
|
|
// tapping state using retap_depth_ and our closed state using dialog_closed_.
|
2015-08-26 19:48:56 +00:00
|
|
|
//
|
|
|
|
// The Delta Object Rules (http://delta.affinix.com/dor/) page on nested
|
|
|
|
// event loops effectively says "don't do that." However, we don't really
|
|
|
|
// have a choice if we want to have a usable application that retaps packets.
|
|
|
|
|
2015-08-24 19:30:56 +00:00
|
|
|
void WiresharkDialog::tryDeleteLater()
|
|
|
|
{
|
2015-08-26 19:48:56 +00:00
|
|
|
if (retap_depth_ < 1 && dialog_closed_) {
|
|
|
|
disconnect();
|
|
|
|
deleteLater();
|
|
|
|
}
|
2015-08-24 19:30:56 +00:00
|
|
|
}
|
|
|
|
|
2014-12-22 23:51:36 +00:00
|
|
|
void WiresharkDialog::updateWidgets()
|
|
|
|
{
|
2014-12-29 22:12:43 +00:00
|
|
|
setWindowTitleFromSubtitle();
|
2014-12-22 23:51:36 +00:00
|
|
|
}
|
|
|
|
|
2015-08-24 19:30:56 +00:00
|
|
|
bool WiresharkDialog::registerTapListener(const char *tap_name, void *tap_data, const char *filter, guint flags, void(*tap_reset)(void *), gboolean(*tap_packet)(void *, struct _packet_info *, struct epan_dissect *, const void *), void(*tap_draw)(void *))
|
|
|
|
{
|
2016-06-19 09:01:56 +00:00
|
|
|
GString *error_string = register_tap_listener(tap_name, tap_data, filter, flags,
|
2015-08-24 19:30:56 +00:00
|
|
|
tap_reset, tap_packet, tap_draw);
|
|
|
|
if (error_string) {
|
|
|
|
QMessageBox::warning(this, tr("Failed to attach to tap \"%1\"").arg(tap_name),
|
2016-06-19 09:01:56 +00:00
|
|
|
error_string->str);
|
|
|
|
g_string_free(error_string, TRUE);
|
2015-08-24 19:30:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tap_listeners_ << tap_data;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WiresharkDialog::endRetapPackets()
|
|
|
|
{
|
|
|
|
retap_depth_--;
|
|
|
|
tryDeleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WiresharkDialog::removeTapListeners()
|
|
|
|
{
|
|
|
|
while (!tap_listeners_.isEmpty()) {
|
|
|
|
remove_tap_listener(tap_listeners_.takeFirst());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 23:51:36 +00:00
|
|
|
void WiresharkDialog::captureFileClosing()
|
|
|
|
{
|
2015-09-25 09:05:45 +00:00
|
|
|
if (file_closed_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
removeTapListeners();
|
|
|
|
updateWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WiresharkDialog::captureFileClosed()
|
|
|
|
{
|
|
|
|
if (file_closed_)
|
|
|
|
return;
|
|
|
|
|
2015-08-24 19:30:56 +00:00
|
|
|
removeTapListeners();
|
2014-12-22 23:51:36 +00:00
|
|
|
updateWidgets();
|
2015-09-25 09:05:45 +00:00
|
|
|
file_closed_ = true;
|
2014-12-22 23:51:36 +00:00
|
|
|
}
|
2014-12-29 16:11:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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:
|
|
|
|
*/
|