Implemented "Import Options" for PCAP file format
This commit is contained in:
parent
00e03a44fd
commit
bb78afbca7
@ -230,6 +230,7 @@ void Port::updateStats(OstProto::PortStats *portStats)
|
|||||||
bool Port::openStreams(QString fileName, bool append, QString &error)
|
bool Port::openStreams(QString fileName, bool append, QString &error)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
QDialog *optDialog;
|
||||||
QProgressDialog progress("Opening Streams", "Cancel", 0, 0, mainWindow);
|
QProgressDialog progress("Opening Streams", "Cancel", 0, 0, mainWindow);
|
||||||
OstProto::StreamConfigList streams;
|
OstProto::StreamConfigList streams;
|
||||||
AbstractFileFormat *fmt = AbstractFileFormat::fileFormatFromFile(fileName);
|
AbstractFileFormat *fmt = AbstractFileFormat::fileFormatFromFile(fileName);
|
||||||
@ -237,6 +238,16 @@ bool Port::openStreams(QString fileName, bool append, QString &error)
|
|||||||
if (fmt == NULL)
|
if (fmt == NULL)
|
||||||
goto _fail;
|
goto _fail;
|
||||||
|
|
||||||
|
if (optDialog = fmt->openOptionsDialog())
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
optDialog->setParent(mainWindow, Qt::Dialog);
|
||||||
|
ret = optDialog->exec();
|
||||||
|
optDialog->setParent(0, Qt::Dialog);
|
||||||
|
if (ret == QDialog::Rejected)
|
||||||
|
goto _user_opt_cancel;
|
||||||
|
}
|
||||||
|
|
||||||
progress.setAutoReset(false);
|
progress.setAutoReset(false);
|
||||||
progress.setAutoClose(false);
|
progress.setAutoClose(false);
|
||||||
progress.setMinimumDuration(0);
|
progress.setMinimumDuration(0);
|
||||||
@ -295,6 +306,7 @@ bool Port::openStreams(QString fileName, bool append, QString &error)
|
|||||||
|
|
||||||
_user_cancel:
|
_user_cancel:
|
||||||
emit streamListChanged(mPortGroupId, mPortId);
|
emit streamListChanged(mPortGroupId, mPortId);
|
||||||
|
_user_opt_cancel:
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
_fail:
|
_fail:
|
||||||
|
@ -34,6 +34,16 @@ AbstractFileFormat::~AbstractFileFormat()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDialog* AbstractFileFormat::openOptionsDialog()
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDialog* AbstractFileFormat::saveOptionsDialog()
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
QStringList AbstractFileFormat::supportedFileTypes()
|
QStringList AbstractFileFormat::supportedFileTypes()
|
||||||
{
|
{
|
||||||
return QStringList()
|
return QStringList()
|
||||||
|
@ -25,6 +25,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
class QDialog;
|
||||||
|
|
||||||
class AbstractFileFormat : public QThread
|
class AbstractFileFormat : public QThread
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -37,6 +39,9 @@ public:
|
|||||||
virtual bool saveStreams(const OstProto::StreamConfigList streams,
|
virtual bool saveStreams(const OstProto::StreamConfigList streams,
|
||||||
const QString fileName, QString &error) = 0;
|
const QString fileName, QString &error) = 0;
|
||||||
|
|
||||||
|
virtual QDialog* openOptionsDialog();
|
||||||
|
virtual QDialog* saveOptionsDialog();
|
||||||
|
|
||||||
void openStreamsOffline(const QString fileName,
|
void openStreamsOffline(const QString fileName,
|
||||||
OstProto::StreamConfigList &streams, QString &error);
|
OstProto::StreamConfigList &streams, QString &error);
|
||||||
void saveStreamsOffline(const OstProto::StreamConfigList streams,
|
void saveStreamsOffline(const OstProto::StreamConfigList streams,
|
||||||
@ -44,11 +49,11 @@ public:
|
|||||||
|
|
||||||
bool result();
|
bool result();
|
||||||
|
|
||||||
|
static QStringList supportedFileTypes();
|
||||||
|
|
||||||
static AbstractFileFormat* fileFormatFromFile(const QString fileName);
|
static AbstractFileFormat* fileFormatFromFile(const QString fileName);
|
||||||
static AbstractFileFormat* fileFormatFromType(const QString fileType);
|
static AbstractFileFormat* fileFormatFromType(const QString fileType);
|
||||||
|
|
||||||
static QStringList supportedFileTypes();
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
bool isMyFileFormat(const QString fileName) = 0;
|
bool isMyFileFormat(const QString fileName) = 0;
|
||||||
bool isMyFileType(const QString fileType) = 0;
|
bool isMyFileType(const QString fileType) = 0;
|
||||||
|
@ -5,6 +5,7 @@ INCLUDEPATH += "../extra/qhexedit2/src"
|
|||||||
LIBS += \
|
LIBS += \
|
||||||
-lprotobuf
|
-lprotobuf
|
||||||
FORMS += \
|
FORMS += \
|
||||||
|
pcapfileimport.ui \
|
||||||
mac.ui \
|
mac.ui \
|
||||||
payload.ui \
|
payload.ui \
|
||||||
eth2.ui \
|
eth2.ui \
|
||||||
|
@ -53,19 +53,39 @@ const quint32 kDltEthernet = 1;
|
|||||||
|
|
||||||
PcapFileFormat pcapFileFormat;
|
PcapFileFormat pcapFileFormat;
|
||||||
|
|
||||||
|
PcapImportOptionsDialog::PcapImportOptionsDialog(QVariantMap *options)
|
||||||
|
: QDialog(NULL)
|
||||||
|
{
|
||||||
|
setupUi(this);
|
||||||
|
options_ = options;
|
||||||
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||||
|
}
|
||||||
|
|
||||||
|
PcapImportOptionsDialog::~PcapImportOptionsDialog()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PcapImportOptionsDialog::accept()
|
||||||
|
{
|
||||||
|
options_->insert("ViaPdml", viaPdml->isChecked());
|
||||||
|
options_->insert("DoDiff", doDiff->isChecked());
|
||||||
|
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
||||||
|
|
||||||
PcapFileFormat::PcapFileFormat()
|
PcapFileFormat::PcapFileFormat()
|
||||||
{
|
{
|
||||||
|
importDialog_ = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PcapFileFormat::~PcapFileFormat()
|
PcapFileFormat::~PcapFileFormat()
|
||||||
{
|
{
|
||||||
|
delete importDialog_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PcapFileFormat::openStreams(const QString fileName,
|
bool PcapFileFormat::openStreams(const QString fileName,
|
||||||
OstProto::StreamConfigList &streams, QString &error)
|
OstProto::StreamConfigList &streams, QString &error)
|
||||||
{
|
{
|
||||||
bool viaPdml = false; // TODO: shd be a param to function
|
|
||||||
|
|
||||||
bool isOk = false;
|
bool isOk = false;
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
QTemporaryFile file2;
|
QTemporaryFile file2;
|
||||||
@ -170,7 +190,7 @@ bool PcapFileFormat::openStreams(const QString fileName,
|
|||||||
|
|
||||||
pktBuf.resize(fileHdr.snapLen);
|
pktBuf.resize(fileHdr.snapLen);
|
||||||
|
|
||||||
if (viaPdml)
|
if (importOptions_.value("ViaPdml").toBool())
|
||||||
{
|
{
|
||||||
QTemporaryFile pdmlFile;
|
QTemporaryFile pdmlFile;
|
||||||
PdmlReader reader(&streams);
|
PdmlReader reader(&streams);
|
||||||
@ -424,6 +444,14 @@ _exit:
|
|||||||
return isOk;
|
return isOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDialog* PcapFileFormat::openOptionsDialog()
|
||||||
|
{
|
||||||
|
if (!importDialog_)
|
||||||
|
importDialog_ = new PcapImportOptionsDialog(&importOptions_);
|
||||||
|
|
||||||
|
return importDialog_;
|
||||||
|
}
|
||||||
|
|
||||||
bool PcapFileFormat::isMyFileFormat(const QString fileName)
|
bool PcapFileFormat::isMyFileFormat(const QString fileName)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -20,8 +20,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#define _PCAP_FILE_FORMAT_H
|
#define _PCAP_FILE_FORMAT_H
|
||||||
|
|
||||||
#include "abstractfileformat.h"
|
#include "abstractfileformat.h"
|
||||||
|
#include "ui_pcapfileimport.h"
|
||||||
|
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
|
#include <QVariantMap>
|
||||||
|
|
||||||
|
class PcapImportOptionsDialog: public QDialog, public Ui::PcapFileImport
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PcapImportOptionsDialog(QVariantMap *options);
|
||||||
|
~PcapImportOptionsDialog();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void accept();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVariantMap *options_;
|
||||||
|
};
|
||||||
|
|
||||||
class PdmlReader;
|
class PdmlReader;
|
||||||
class PcapFileFormat : public AbstractFileFormat
|
class PcapFileFormat : public AbstractFileFormat
|
||||||
@ -37,6 +52,8 @@ public:
|
|||||||
bool saveStreams(const OstProto::StreamConfigList streams,
|
bool saveStreams(const OstProto::StreamConfigList streams,
|
||||||
const QString fileName, QString &error);
|
const QString fileName, QString &error);
|
||||||
|
|
||||||
|
virtual QDialog* openOptionsDialog();
|
||||||
|
|
||||||
bool isMyFileFormat(const QString fileName);
|
bool isMyFileFormat(const QString fileName);
|
||||||
bool isMyFileType(const QString fileType);
|
bool isMyFileType(const QString fileType);
|
||||||
|
|
||||||
@ -61,6 +78,8 @@ private:
|
|||||||
bool readPacket(PcapPacketHeader &pktHdr, QByteArray &pktBuf);
|
bool readPacket(PcapPacketHeader &pktHdr, QByteArray &pktBuf);
|
||||||
|
|
||||||
QDataStream fd_;
|
QDataStream fd_;
|
||||||
|
QVariantMap importOptions_;
|
||||||
|
PcapImportOptionsDialog *importDialog_;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern PcapFileFormat pcapFileFormat;
|
extern PcapFileFormat pcapFileFormat;
|
||||||
|
Loading…
Reference in New Issue
Block a user