diff options
author | Andre Luyer <andre@luyer.nl> | 2020-03-14 18:00:07 +0100 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2020-04-22 21:31:48 +0000 |
commit | 30f4f1b0560fbd67867a38bf5e418aac67abc3eb (patch) | |
tree | 55a4cf2b3334d0ec239f975ef11a2a21c8ef9bf1 /ui | |
parent | dc4a5b5addcf990589f7a1afa6963d9de9a5f2b2 (diff) |
Qt: update import via GUI to match import features using text2pcap
Update "Import From Hex Dump" via GUI to allow the same timestamp format as
supported by the command line tool text2pcap. Added support for:
%F Equivalent to %Y-%m-%d (the ISO 8601 date format).
%s The number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
While at it changed the following:
- Subsecond timestamp dot format (.) is now shown in the timestamp Example Label.
- A timestamp format without any format (%) now disables Import button.
The field "Timestamp format" in the GUI now accepts exactly the same formatting
as the text2pcap's -t time format option.
Change-Id: Ie48362f86ed3214288635767d1fc4161599d1907
Reviewed-on: https://code.wireshark.org/review/36417
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/qt/import_text_dialog.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/ui/qt/import_text_dialog.cpp b/ui/qt/import_text_dialog.cpp index 92f178363f..7018e609e8 100644 --- a/ui/qt/import_text_dialog.cpp +++ b/ui/qt/import_text_dialog.cpp @@ -356,8 +356,9 @@ void ImportTextDialog::on_encapComboBox_currentIndexChanged(int index) bool ImportTextDialog::checkDateTimeFormat(const QString &time_format) { - const QString valid_code = "aAbBcdDHIjmMpSTUwWxXyYzZ%"; + const QString valid_code = "aAbBcdDFHIjmMpsSTUwWxXyYzZ%"; int idx = 0; + int ret = false; while ((idx = time_format.indexOf("%", idx)) != -1) { idx++; @@ -365,22 +366,33 @@ bool ImportTextDialog::checkDateTimeFormat(const QString &time_format) return false; } idx++; + ret = true; } - return true; + return ret; } void ImportTextDialog::on_dateTimeLineEdit_textChanged(const QString &time_format) { if (time_format.length() > 0) { if (checkDateTimeFormat(time_format)) { - time_t cur_time; + struct timespec timenow; struct tm *cur_tm; char time_str[100]; + QString timefmt = QString(time_format); - time(&cur_time); - cur_tm = localtime(&cur_time); +#ifdef _WIN32 + timespec_get(&timenow, TIME_UTC); /* supported by Linux and Windows */ +#else + clock_gettime(CLOCK_REALTIME, &timenow); /* supported by Linux and MacOS */ +#endif + /* On windows strftime/wcsftime does not support %s yet, this works on all OSs */ + timefmt.replace(QString("%s"), QString::number(timenow.tv_sec)); + /* subsecond example as usec */ + timefmt.replace(QString("."), QString(".%1").arg(timenow.tv_nsec/1000, 6, 10, QChar('0'))); + + cur_tm = localtime(&timenow.tv_sec); if (cur_tm != NULL) - strftime(time_str, sizeof time_str, ti_ui_->dateTimeLineEdit->text().toUtf8().constData(), cur_tm); + strftime(time_str, sizeof time_str, timefmt.toUtf8(), cur_tm); else g_strlcpy(time_str, "Not representable", sizeof time_str); ti_ui_->timestampExampleLabel->setText(QString(tr("Example: %1")).arg(time_str)); |