diff --git a/client/portswindow.cpp b/client/portswindow.cpp index a2cf238..1a7fdb5 100644 --- a/client/portswindow.cpp +++ b/client/portswindow.cpp @@ -455,6 +455,7 @@ void PortsWindow::on_actionOpen_Streams_triggered() QString fileName; QString errorStr; bool append = true; + bool ret; Q_ASSERT(plm->isPort(current)); @@ -485,10 +486,22 @@ void PortsWindow::on_actionOpen_Streams_triggered() Q_ASSERT(false); } - if (!plm->port(current).openStreams(fileName, append, errorStr)) - QMessageBox::critical(this, qApp->applicationName(), errorStr); - else if (!errorStr.isEmpty()) - QMessageBox::warning(this, qApp->applicationName(), errorStr); + ret = plm->port(current).openStreams(fileName, append, errorStr); + if (!ret || !errorStr.isEmpty()) + { + QMessageBox msgBox(this); + QStringList str = errorStr.split("\n\n\n\n"); + + msgBox.setIcon(ret ? QMessageBox::Warning : QMessageBox::Critical); + msgBox.setWindowTitle(qApp->applicationName()); + msgBox.setText(str.at(0)); + if (str.size() > 1) + msgBox.setDetailedText(str.at(1)); + msgBox.setStandardButtons(QMessageBox::Ok); + + msgBox.exec(); + } + _exit: return; } diff --git a/common/pcapfileformat.cpp b/common/pcapfileformat.cpp index 4d8a46a..89e122b 100644 --- a/common/pcapfileformat.cpp +++ b/common/pcapfileformat.cpp @@ -58,6 +58,10 @@ PcapImportOptionsDialog::PcapImportOptionsDialog(QVariantMap *options) { setupUi(this); options_ = options; + + viaPdml->setChecked(options_->value("ViaPdml").toBool()); + doDiff->setChecked(options_->value("DoDiff").toBool()); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); } @@ -75,6 +79,9 @@ void PcapImportOptionsDialog::accept() PcapFileFormat::PcapFileFormat() { + importOptions_.insert("ViaPdml", true); + importOptions_.insert("DoDiff", true); + importDialog_ = NULL; } @@ -192,9 +199,9 @@ bool PcapFileFormat::openStreams(const QString fileName, if (importOptions_.value("ViaPdml").toBool()) { + QProcess tshark; QTemporaryFile pdmlFile; PdmlReader reader(&streams); - QProcess tshark; if (!pdmlFile.open()) { @@ -229,9 +236,205 @@ bool PcapFileFormat::openStreams(const QString fileName, emit status("Reading PDML packets..."); emit target(100); // in percentage - isOk = reader.read(&pdmlFile, this, &stop_); // TODO: pass error string? + isOk = reader.read(&pdmlFile, this, &stop_); + + if (stop_) + goto _user_cancel; + + if (!isOk) + { + error.append(QString("Error processing PDML (%1, %2): %3\n") + .arg(reader.lineNumber()) + .arg(reader.columnNumber()) + .arg(reader.errorString())); + goto _exit; + } + + if (!importOptions_.value("DoDiff").toBool()) + goto _exit; + + + // !-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-! + // Let's do the diff ... + // !-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-! + + QProcess awk; + QProcess diff; + QTemporaryFile originalTextFile; + QTemporaryFile importedPcapFile; + QTemporaryFile importedTextFile; + QTemporaryFile diffFile; + const QString kAwkFilter = + "/^[^0]/ { " + "printf \" %s \", $1;" + "for (i=4; i %s", + originalTextFile.fileName().toAscii().constData(), + importedTextFile.fileName().toAscii().constData(), + diffFile.fileName().toAscii().constData()); + + emit status("Taking diff..."); + emit target(0); + + diff.setStandardOutputFile(diffFile.fileName()); + // FIXME: hardcoded prog name + diff.start("D:/srivatsp/projects/ostinato/pdml/bin/diff.exe", + QStringList() + << "-u" + << "-F^ [1-9]" + << QString("--label=%1 (actual)") + .arg(QFileInfo(fileName).fileName()) + << QString("--label=%1 (imported)") + .arg(QFileInfo(fileName).fileName()) + << originalTextFile.fileName() + << importedTextFile.fileName()); + if (!diff.waitForStarted(-1)) + { + error.append(QString("Unable to start diff\n") + .arg(diff.exitCode())); + goto _diff_fail; + } + + if (!diff.waitForFinished(-1)) + { + error.append(QString("Error running diff\n")); + goto _diff_fail; + } + + diffFile.close(); + if (diffFile.size()) + { + error.append("There is a diff between the original and imported streams. See details for diff.\n\n\n\n"); + diffFile.open(); + diffFile.seek(0); + error.append(QString(diffFile.readAll())); + } + goto _exit; - } _non_pdml: @@ -287,13 +490,14 @@ _user_cancel: isOk = true; goto _exit; -#if 1 +_diff_fail: + goto _exit; + _err_unsupported_encap: error = QString(tr("%1 has non-ethernet encapsulation (%2) which is " "not supported - Sorry!")) .arg(QFileInfo(fileName).fileName()).arg(fileHdr.network); goto _exit; -#endif _err_unsupported_version: error = QString(tr("%1 is in PCAP version %2.%3 format which is "