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