Implemented configuration of external application paths in preferences. Removed all hardcoded paths for external applications.

This commit is contained in:
Srivats P. 2011-03-20 20:50:07 +05:30
parent cb70fd83e6
commit 71382ae4ca
9 changed files with 376 additions and 50 deletions

View File

@ -18,7 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#include "mainwindow.h"
#include "../common/ostprotolib.h"
#include "../common/protocolmanager.h"
#include "settings.h"
#include <QApplication>
#include <QFile>
@ -31,11 +33,23 @@ extern ProtocolManager *OstProtocolManager;
QSettings *appSettings;
QMainWindow *mainWindow;
#if defined(Q_OS_WIN32)
QString kGzipPathDefaultValue;
QString kDiffPathDefaultValue;
QString kAwkPathDefaultValue;
#endif
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
int exitCode;
#if defined(Q_OS_WIN32)
kGzipPathDefaultValue = app.applicationDirPath() + "/gzip.exe";
kDiffPathDefaultValue = app.applicationDirPath() + "/diff.exe";
kAwkPathDefaultValue = app.applicationDirPath() + "/gawk.exe";
#endif
app.setApplicationName("Ostinato");
app.setOrganizationName("Ostinato");
app.setProperty("version", version);
@ -53,6 +67,12 @@ int main(int argc, char* argv[])
else
appSettings = new QSettings();
OstProtoLib::setExternalApplicationPaths(
appSettings->value(kTsharkPathKey, kTsharkPathDefaultValue).toString(),
appSettings->value(kGzipPathKey, kGzipPathDefaultValue).toString(),
appSettings->value(kDiffPathKey, kDiffPathDefaultValue).toString(),
appSettings->value(kAwkPathKey, kAwkPathDefaultValue).toString());
mainWindow = new MainWindow;
mainWindow->show();
exitCode = app.exec();

View File

@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "preferences.h"
#include "../common/ostprotolib.h"
#include "settings.h"
#include <QFileDialog>
@ -31,6 +32,14 @@ Preferences::Preferences()
wiresharkPathEdit->setText(appSettings->value(kWiresharkPathKey,
kWiresharkPathDefaultValue).toString());
tsharkPathEdit->setText(appSettings->value(kTsharkPathKey,
kTsharkPathDefaultValue).toString());
gzipPathEdit->setText(appSettings->value(kGzipPathKey,
kGzipPathDefaultValue).toString());
diffPathEdit->setText(appSettings->value(kDiffPathKey,
kDiffPathDefaultValue).toString());
awkPathEdit->setText(appSettings->value(kAwkPathKey,
kAwkPathDefaultValue).toString());
}
Preferences::~Preferences()
@ -40,6 +49,16 @@ Preferences::~Preferences()
void Preferences::accept()
{
appSettings->setValue(kWiresharkPathKey, wiresharkPathEdit->text());
appSettings->setValue(kTsharkPathKey, tsharkPathEdit->text());
appSettings->setValue(kGzipPathKey, gzipPathEdit->text());
appSettings->setValue(kDiffPathKey, diffPathEdit->text());
appSettings->setValue(kAwkPathKey, awkPathEdit->text());
OstProtoLib::setExternalApplicationPaths(
appSettings->value(kTsharkPathKey, kTsharkPathDefaultValue).toString(),
appSettings->value(kGzipPathKey, kGzipPathDefaultValue).toString(),
appSettings->value(kDiffPathKey, kDiffPathDefaultValue).toString(),
appSettings->value(kAwkPathKey, kAwkPathDefaultValue).toString());
QDialog::accept();
}
@ -54,3 +73,47 @@ void Preferences::on_wiresharkPathButton_clicked()
if (!path.isEmpty())
wiresharkPathEdit->setText(path);
}
void Preferences::on_tsharkPathButton_clicked()
{
QString path;
path = QFileDialog::getOpenFileName(0, "Locate tshark",
tsharkPathEdit->text());
if (!path.isEmpty())
tsharkPathEdit->setText(path);
}
void Preferences::on_gzipPathButton_clicked()
{
QString path;
path = QFileDialog::getOpenFileName(0, "Locate gzip",
gzipPathEdit->text());
if (!path.isEmpty())
gzipPathEdit->setText(path);
}
void Preferences::on_diffPathButton_clicked()
{
QString path;
path = QFileDialog::getOpenFileName(0, "Locate diff",
diffPathEdit->text());
if (!path.isEmpty())
diffPathEdit->setText(path);
}
void Preferences::on_awkPathButton_clicked()
{
QString path;
path = QFileDialog::getOpenFileName(0, "Locate awk",
awkPathEdit->text());
if (!path.isEmpty())
awkPathEdit->setText(path);
}

View File

@ -36,6 +36,10 @@ public slots:
private slots:
void on_wiresharkPathButton_clicked();
void on_tsharkPathButton_clicked();
void on_gzipPathButton_clicked();
void on_diffPathButton_clicked();
void on_awkPathButton_clicked();
};
#endif

View File

@ -6,7 +6,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>164</height>
<height>220</height>
</rect>
</property>
<property name="windowTitle" >
@ -24,37 +24,136 @@
<property name="frameShadow" >
<enum>QFrame::Sunken</enum>
</property>
<layout class="QVBoxLayout" >
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<string>Wireshark Path</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="wiresharkPathEdit" />
</item>
<item>
<widget class="QToolButton" name="wiresharkPathButton" >
<property name="text" >
<string>...</string>
</property>
</widget>
</item>
</layout>
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>'wireshark' Path</string>
</property>
<property name="buddy" >
<cstring>wiresharkPathEdit</cstring>
</property>
</widget>
</item>
<item>
<item row="0" column="1" >
<widget class="QLineEdit" name="wiresharkPathEdit" >
<property name="enabled" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QToolButton" name="wiresharkPathButton" >
<property name="text" >
<string>...</string>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>'tshark' Path</string>
</property>
<property name="buddy" >
<cstring>tsharkPathEdit</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QLineEdit" name="tsharkPathEdit" >
<property name="enabled" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="2" >
<widget class="QToolButton" name="tsharkPathButton" >
<property name="text" >
<string>...</string>
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="label_5" >
<property name="text" >
<string>'gzip' Path</string>
</property>
<property name="buddy" >
<cstring>diffPathEdit</cstring>
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="QLineEdit" name="gzipPathEdit" >
<property name="enabled" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="2" >
<widget class="QToolButton" name="gzipPathButton" >
<property name="text" >
<string>...</string>
</property>
</widget>
</item>
<item row="3" column="0" >
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>'diff' Path</string>
</property>
<property name="buddy" >
<cstring>diffPathEdit</cstring>
</property>
</widget>
</item>
<item row="3" column="1" >
<widget class="QLineEdit" name="diffPathEdit" >
<property name="enabled" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="3" column="2" >
<widget class="QToolButton" name="diffPathButton" >
<property name="text" >
<string>...</string>
</property>
</widget>
</item>
<item row="4" column="0" >
<widget class="QLabel" name="label_4" >
<property name="text" >
<string>'awk' Path</string>
</property>
<property name="buddy" >
<cstring>awkPathEdit</cstring>
</property>
</widget>
</item>
<item row="4" column="1" >
<widget class="QLineEdit" name="awkPathEdit" >
<property name="enabled" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="2" >
<widget class="QToolButton" name="awkPathButton" >
<property name="text" >
<string>...</string>
</property>
</widget>
</item>
<item row="5" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
<width>21</width>
<height>61</height>
</size>
</property>
</spacer>
@ -74,6 +173,19 @@
</item>
</layout>
</widget>
<tabstops>
<tabstop>wiresharkPathEdit</tabstop>
<tabstop>wiresharkPathButton</tabstop>
<tabstop>tsharkPathEdit</tabstop>
<tabstop>tsharkPathButton</tabstop>
<tabstop>gzipPathEdit</tabstop>
<tabstop>gzipPathButton</tabstop>
<tabstop>diffPathEdit</tabstop>
<tabstop>diffPathButton</tabstop>
<tabstop>awkPathEdit</tabstop>
<tabstop>awkPathButton</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources>
<include location="ostinato.qrc" />
</resources>

View File

@ -36,6 +36,44 @@ const QString kWiresharkPathDefaultValue(
const QString kWiresharkPathDefaultValue("/usr/bin/wireshark");
#endif
const QString kTsharkPathKey("TsharkPath");
#if defined(Q_OS_WIN32)
const QString kTsharkPathDefaultValue(
"C:/Program Files/Wireshark/tshark.exe");
#elif defined(Q_OS_MAC)
const QString kTsharkPathDefaultValue(
"/Applications/Wireshark.app/Contents/Resources/bin/tshark");
#else
const QString kTsharkPathDefaultValue("/usr/bin/tshark");
#endif
const QString kGzipPathKey("GzipPath");
#if defined(Q_OS_WIN32)
extern QString kGzipPathDefaultValue;
#elif defined(Q_OS_MAC)
const QString kGzipPathDefaultValue("/usr/bin/gzip");
#else
const QString kGzipPathDefaultValue("/usr/bin/gzip");
#endif
const QString kDiffPathKey("DiffPath");
#if defined(Q_OS_WIN32)
extern QString kDiffPathDefaultValue;
#elif defined(Q_OS_MAC)
const QString kDiffPathDefaultValue("/usr/bin/diff");
#else
const QString kDiffPathDefaultValue("/usr/bin/diff");
#endif
const QString kAwkPathKey("AwkPath");
#if defined(Q_OS_WIN32)
extern QString kAwkPathDefaultValue;
#elif defined(Q_OS_MAC)
const QString kAwkPathDefaultValue("/usr/bin/awk");
#else
const QString kAwkPathDefaultValue("/usr/bin/awk");
#endif
#endif

View File

@ -56,6 +56,7 @@ PROTOS += \
hexdump.proto \
sample.proto
HEADERS += \
ostprotolib.h \
abstractprotocol.h \
comboprotocol.h \
abstractfileformat.h \
@ -98,6 +99,7 @@ HEADERS += \
hexdump.h \
sample.h
SOURCES += \
ostprotolib.cpp \
abstractprotocol.cpp \
crc32c.cpp \
abstractfileformat.cpp \

55
common/ostprotolib.cpp Normal file
View File

@ -0,0 +1,55 @@
/*
Copyright (C) 2011 Srivats P.
This file is part of "Ostinato"
This 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 3 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, see <http://www.gnu.org/licenses/>
*/
#include "ostprotolib.h"
QString OstProtoLib::tsharkPath_;
QString OstProtoLib::gzipPath_;
QString OstProtoLib::diffPath_;
QString OstProtoLib::awkPath_;
void OstProtoLib::setExternalApplicationPaths(QString tsharkPath,
QString gzipPath, QString diffPath, QString awkPath)
{
tsharkPath_ = tsharkPath;
gzipPath_ = gzipPath;
diffPath_ = diffPath;
awkPath_ = awkPath;
}
QString OstProtoLib::tsharkPath()
{
return tsharkPath_;
}
QString OstProtoLib::gzipPath()
{
return gzipPath_;
}
QString OstProtoLib::diffPath()
{
return diffPath_;
}
QString OstProtoLib::awkPath()
{
return awkPath_;
}

42
common/ostprotolib.h Normal file
View File

@ -0,0 +1,42 @@
/*
Copyright (C) 2011 Srivats P.
This file is part of "Ostinato"
This 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 3 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, see <http://www.gnu.org/licenses/>
*/
#ifndef _OST_PROTO_LIB_H
#define _OST_PROTO_LIB_H
#include <QString>
class OstProtoLib
{
public:
static void setExternalApplicationPaths(QString tsharkPath,
QString gzipPath, QString diffPath, QString awkPath);
static QString tsharkPath();
static QString gzipPath();
static QString diffPath();
static QString awkPath();
private:
static QString tsharkPath_;
static QString gzipPath_;
static QString diffPath_;
static QString awkPath_;
};
#endif

View File

@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "pcapfileformat.h"
#include "pdml_p.h"
#include "ostprotolib.h"
#include "streambase.h"
#include "hexdump.pb.h"
@ -131,15 +132,14 @@ bool PcapFileFormat::openStreams(const QString fileName,
qDebug("decompressing to %s", file2.fileName().toAscii().constData());
gzip.setStandardOutputFile(file2.fileName());
// FIXME: hardcoded prog name
gzip.start("C:/Program Files/CmdLineTools/gzip.exe",
gzip.start(OstProtoLib::gzipPath(),
QStringList()
<< "-d"
<< "-c"
<< fileName);
if (!gzip.waitForStarted(-1))
{
error.append(QString("Unable to start gzip\n"));
error.append(QString("Unable to start gzip. Check path in Preferences.\n"));
goto _err_unzip_fail;
}
@ -214,15 +214,14 @@ bool PcapFileFormat::openStreams(const QString fileName,
emit target(0);
tshark.setStandardOutputFile(pdmlFile.fileName());
// FIXME: hardcoded prog name
tshark.start("C:/Program Files/Wireshark/Tshark.exe",
tshark.start(OstProtoLib::tsharkPath(),
QStringList()
<< QString("-r%1").arg(fileName)
<< "-otcp.desegment_tcp_streams:FALSE"
<< "-Tpdml");
if (!tshark.waitForStarted(-1))
{
error.append(QString("Unable to start tshark\n"));
error.append(QString("Unable to start tshark. Check path in preferences.\n"));
goto _non_pdml;
}
@ -287,27 +286,23 @@ bool PcapFileFormat::openStreams(const QString fileName,
tshark.setStandardOutputProcess(&awk);
awk.setStandardOutputFile(originalTextFile.fileName());
// FIXME: hardcoded prog name
tshark.start("C:/Program Files/Wireshark/Tshark.exe",
tshark.start(OstProtoLib::tsharkPath(),
QStringList()
<< QString("-r%1").arg(fileName)
<< "-otcp.desegment_tcp_streams:FALSE"
<< "-x");
if (!tshark.waitForStarted(-1))
{
error.append(QString("Unable to start tshark - %1\n")
.arg(tshark.exitCode()));
error.append(QString("Unable to start tshark. Check path in Preferences.\n"));
goto _diff_fail;
}
// FIXME: hardcoded prog name
awk.start("D:/srivatsp/projects/ostinato/pdml/bin/gawk.exe",
awk.start(OstProtoLib::awkPath(),
QStringList() << kAwkFilter);
if (!awk.waitForStarted(-1))
{
tshark.kill();
error.append(QString("Unable to start awk - %1\n")
.arg(awk.exitCode()));
error.append(QString("Unable to start awk. Check path in Preferences.\n"));
goto _diff_fail;
}
@ -351,27 +346,23 @@ bool PcapFileFormat::openStreams(const QString fileName,
tshark.setStandardOutputProcess(&awk);
awk.setStandardOutputFile(importedTextFile.fileName());
// FIXME: hardcoded prog name
tshark.start("C:/Program Files/Wireshark/Tshark.exe",
tshark.start(OstProtoLib::tsharkPath(),
QStringList()
<< QString("-r%1").arg(importedPcapFile.fileName())
<< "-otcp.desegment_tcp_streams:FALSE"
<< "-x");
if (!tshark.waitForStarted(-1))
{
error.append(QString("Unable to start tshark - %1\n")
.arg(tshark.exitCode()));
error.append(QString("Unable to start tshark. Check path in Preferences.\n"));
goto _diff_fail;
}
// FIXME: hardcoded prog name
awk.start("D:/srivatsp/projects/ostinato/pdml/bin/gawk.exe",
awk.start(OstProtoLib::awkPath(),
QStringList() << kAwkFilter);
if (!awk.waitForStarted(-1))
{
tshark.kill();
error.append(QString("Unable to start awk - %1\n")
.arg(awk.exitCode()));
error.append(QString("Unable to start awk. Check path in Preferences.\n"));
goto _diff_fail;
}
@ -401,8 +392,7 @@ bool PcapFileFormat::openStreams(const QString fileName,
emit target(0);
diff.setStandardOutputFile(diffFile.fileName());
// FIXME: hardcoded prog name
diff.start("D:/srivatsp/projects/ostinato/pdml/bin/diff.exe",
diff.start(OstProtoLib::diffPath(),
QStringList()
<< "-u"
<< "-F^ [1-9]"
@ -414,7 +404,7 @@ bool PcapFileFormat::openStreams(const QString fileName,
<< importedTextFile.fileName());
if (!diff.waitForStarted(-1))
{
error.append(QString("Unable to start diff\n")
error.append(QString("Unable to start diff. Check path in Preferences.\n")
.arg(diff.exitCode()));
goto _diff_fail;
}