aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/extcap.pod5
-rwxr-xr-xdoc/extcap_example.py5
-rw-r--r--extcap_parser.c2
-rw-r--r--extcap_parser.h3
-rw-r--r--ui/gtk/extcap_gtk.c34
-rw-r--r--ui/gtk/extcap_gtk.h1
-rw-r--r--ui/qt/extcap_argument.cpp63
-rw-r--r--ui/qt/extcap_argument.h21
-rw-r--r--ui/qt/extcap_options_dialog.cpp9
9 files changed, 141 insertions, 2 deletions
diff --git a/doc/extcap.pod b/doc/extcap.pod
index 05cbdcbb93..84ce4c71f0 100644
--- a/doc/extcap.pod
+++ b/doc/extcap.pod
@@ -47,6 +47,7 @@ Argument type for UI filtering for raw, or UI type for selector:
fileselect (display a dialog to select a file from the filesystem, value as string)
multicheck (display a textbox for selecting multiple options, values as strings)
password (display a textbox with masked text)
+ timestamp (display a calendar)
=item value (options)
@@ -84,6 +85,10 @@ Example 4:
arg {number=0}{call=--username}{display=Username}{type=string}
arg {number=1}{call=--password}{display=Password}{type=password}
+Example 5:
+ arg {number=0}{call=--start}{display=Start Time}{type=timestamp}
+ arg {number=1}{call=--end}{display=End Time}{type=timestamp}
+
=head1 Security awareness
=over 4
diff --git a/doc/extcap_example.py b/doc/extcap_example.py
index 0847cb5648..446cccb8f1 100755
--- a/doc/extcap_example.py
+++ b/doc/extcap_example.py
@@ -106,6 +106,7 @@ def extcap_config(interface):
args.append ( (6, '--d1test', 'Double 1 Test', 'Long Test Value', 'double', '{default=123.456}'))
args.append ( (7, '--d2test', 'Double 2 Test', 'Long Test Value', 'double', '{default= 123,456}'))
args.append ( (8, '--password', 'Password', 'Package message password', 'password', '') )
+ args.append ( (9, '--ts', 'Start Time', 'Capture start time', 'timestamp', '') )
values.append ( (3, "if1", "Remote1", "true" ) )
values.append ( (3, "if2", "Remote2", "false" ) )
@@ -243,6 +244,7 @@ if __name__ == '__main__':
delay = 0
message = ""
fake_ip = ""
+ ts = 0
parser = ArgumentParser(
prog="Extcap Example",
@@ -264,6 +266,7 @@ if __name__ == '__main__':
parser.add_argument("--remote", help="Demonstrates a selector choice", default="if1", choices=["if1", "if2"] )
parser.add_argument("--message", help="Demonstrates string variable", nargs='?', default="" )
parser.add_argument("--fake_ip", help="Add a fake sender IP adress", nargs='?', default="127.0.0.1" )
+ parser.add_argument("--ts", help="Capture start time", action="store_true" )
try:
args, unknown = parser.parse_known_args()
@@ -306,6 +309,8 @@ if __name__ == '__main__':
if ( args.fake_ip == None or len(args.fake_ip) < 7 or len(args.fake_ip.split('.')) != 4 ):
fake_ip = "127.0.0.1"
+ ts = args.ts
+
if args.extcap_config:
extcap_config(interface)
elif args.extcap_dlts:
diff --git a/extcap_parser.c b/extcap_parser.c
index dbdb4f162f..889dbbe309 100644
--- a/extcap_parser.c
+++ b/extcap_parser.c
@@ -408,6 +408,8 @@ static extcap_arg *extcap_parse_arg_sentence(GList *args, extcap_token_sentence
target_arg->arg_type = EXTCAP_ARG_FILESELECT;
} else if (g_ascii_strcasecmp(param_value, "multicheck") == 0) {
target_arg->arg_type = EXTCAP_ARG_MULTICHECK;
+ } else if (g_ascii_strcasecmp(param_value, "timestamp") == 0) {
+ target_arg->arg_type = EXTCAP_ARG_TIMESTAMP;
} else {
printf("invalid type %s in ARG sentence\n", param_value);
extcap_free_arg(target_arg);
diff --git a/extcap_parser.h b/extcap_parser.h
index 0f29625061..c8c40328d7 100644
--- a/extcap_parser.h
+++ b/extcap_parser.h
@@ -52,7 +52,8 @@ typedef enum {
EXTCAP_ARG_SELECTOR,
EXTCAP_ARG_RADIO,
EXTCAP_ARG_MULTICHECK,
- EXTCAP_ARG_FILESELECT
+ EXTCAP_ARG_FILESELECT,
+ EXTCAP_ARG_TIMESTAMP
} extcap_arg_type;
typedef enum {
diff --git a/ui/gtk/extcap_gtk.c b/ui/gtk/extcap_gtk.c
index 55d93892c9..c2c679c353 100644
--- a/ui/gtk/extcap_gtk.c
+++ b/ui/gtk/extcap_gtk.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <gtk/gtk.h>
+#include <glib.h>
#include <ui/gtk/gui_utils.h>
#include <wsutil/filesystem.h>
@@ -134,6 +135,11 @@ GHashTable *extcap_gtk_get_state(GtkWidget *widget) {
int multi_num = 0;
+ guint year;
+ guint month;
+ guint day;
+ guint64 unix_ts;
+
widget_list = (GSList *) g_object_get_data(G_OBJECT(widget),
EXTCAP_GTK_DATA_KEY_WIDGETLIST);
@@ -183,6 +189,16 @@ GHashTable *extcap_gtk_get_state(GtkWidget *widget) {
continue;
}
break;
+ case EXTCAP_ARG_TIMESTAMP: {
+ GTimeZone* tz = g_time_zone_new("UTC");
+ gtk_calendar_get_date((GtkCalendar*)list_widget, &year, &month, &day);
+ GDateTime* datetime = g_date_time_new(tz, year, month, day, 0, 0, 0);
+ unix_ts = g_date_time_to_unix(datetime);
+ call_string = g_strdup_printf("%" G_GINT64_MODIFIER "u", unix_ts);
+ g_date_time_unref(datetime);
+ g_time_zone_unref(tz);
+ }
+ break;
case EXTCAP_ARG_RADIO:
if ((radio_widget = (GtkWidget *) g_object_get_data(
G_OBJECT(list_widget),
@@ -765,7 +781,7 @@ GSList *extcap_populate_gtk_vbox(GList *arguments, GtkWidget *vbox,
extcap_arg *arg_iter = NULL;
extcap_complex *prev_complex = NULL;
- gchar *prev_call, *default_str;
+ gchar *prev_call = NULL, *default_str;
GList * arg_list = g_list_first(arguments);
if ( arg_list == NULL )
@@ -850,6 +866,22 @@ GSList *extcap_populate_gtk_vbox(GList *arguments, GtkWidget *vbox,
if (default_str != NULL)
g_free(default_str);
break;
+ case EXTCAP_ARG_TIMESTAMP:
+ default_str = NULL;
+ if (prev_complex != NULL)
+ default_str = extcap_get_complex_as_string(prev_complex);
+ else if (arg_iter->default_complex != NULL)
+ default_str = extcap_get_complex_as_string(
+ arg_iter->default_complex);
+ label = gtk_label_new(arg_iter->display);
+ gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.1f);
+ if (default_str != NULL) {
+ gtk_entry_set_text(GTK_ENTRY(item), default_str);
+ g_free(default_str);
+ }
+
+ item = gtk_calendar_new();
+ break;
case EXTCAP_ARG_BOOLEAN:
case EXTCAP_ARG_BOOLFLAG:
item = gtk_check_button_new_with_label(arg_iter->display);
diff --git a/ui/gtk/extcap_gtk.h b/ui/gtk/extcap_gtk.h
index 614a76c787..cdc26167ab 100644
--- a/ui/gtk/extcap_gtk.h
+++ b/ui/gtk/extcap_gtk.h
@@ -40,6 +40,7 @@
#define EXTCAP_GTK_DATA_KEY_WIDGETLIST "EXTCAP_WIDGETLIST"
#define EXTCAP_GTK_DATA_KEY_TREEVIEW "EXTCAP_TREEVIEW"
#define EXTCAP_GTK_DATA_KEY_FILENAME "EXTCAP_FILENAME"
+#define EXTCAP_GTK_DATA_KEY_TIMESTAMP "EXTCAP_TIMESTAMP"
#define EXTCAP_GTK_DATA_KEY_ARGUMENT "EXTCAP_ARGUMENT"
/*
diff --git a/ui/qt/extcap_argument.cpp b/ui/qt/extcap_argument.cpp
index 400bc3edae..72734b7bc6 100644
--- a/ui/qt/extcap_argument.cpp
+++ b/ui/qt/extcap_argument.cpp
@@ -25,6 +25,7 @@
#include <QWidget>
#include <QLabel>
#include <QLineEdit>
+#include <QDateTimeEdit>
#include <QIntValidator>
#include <QDoubleValidator>
#include <QCheckBox>
@@ -54,6 +55,66 @@
#include <extcap_argument_file.h>
#include <extcap_argument_multiselect.h>
+ExtArgTimestamp::ExtArgTimestamp(extcap_arg * argument) :
+ ExtcapArgument(argument) {}
+
+QWidget * ExtArgTimestamp::createEditor(QWidget * parent)
+{
+ QDateTimeEdit * tsBox;
+ QString storeValue;
+ QString text = defaultValue();
+
+ if ( _argument->pref_valptr && *_argument->pref_valptr)
+ {
+ QString storeValue(*_argument->pref_valptr);
+
+ if ( storeValue.length() > 0 && storeValue.compare(text) != 0 )
+ text = storeValue.trimmed();
+ }
+
+ ts = QDateTime::fromTime_t(text.toInt());
+ tsBox = new QDateTimeEdit(ts, parent);
+ tsBox->setCalendarPopup(true);
+
+ if ( _argument->tooltip != NULL )
+ tsBox->setToolTip(QString().fromUtf8(_argument->tooltip));
+
+ connect(tsBox, SIGNAL(dateTimeChanged(QDateTime)), SLOT(onDateTimeChanged(QDateTime)));
+
+ return tsBox;
+}
+
+void ExtArgTimestamp::onDateTimeChanged(QDateTime t)
+{
+ ts = t;
+ emit valueChanged();
+}
+
+QString ExtArgTimestamp::defaultValue()
+{
+ return QString::number(QDateTime::currentDateTime().toTime_t());
+}
+
+bool ExtArgTimestamp::isValid()
+{
+ bool valid = true;
+
+ if ( value().length() == 0 && isRequired() )
+ valid = false;
+
+ return valid;
+}
+
+QString ExtArgTimestamp::value()
+{
+ return QString::number(ts.toTime_t());
+}
+
+QString ExtArgTimestamp::prefValue()
+{
+ return value();
+}
+
ExtArgSelector::ExtArgSelector(extcap_arg * argument) :
ExtcapArgument(argument), boxSelection(0) {}
@@ -687,6 +748,8 @@ ExtcapArgument * ExtcapArgument::create(extcap_arg * argument)
result = new ExtcapArgumentFileSelection(argument);
else if ( argument->arg_type == EXTCAP_ARG_MULTICHECK )
result = new ExtArgMultiSelect(argument);
+ else if ( argument->arg_type == EXTCAP_ARG_TIMESTAMP )
+ result = new ExtArgTimestamp(argument);
else
{
/* For everything else, we just print the label */
diff --git a/ui/qt/extcap_argument.h b/ui/qt/extcap_argument.h
index 5ff390c7d0..851fcfb009 100644
--- a/ui/qt/extcap_argument.h
+++ b/ui/qt/extcap_argument.h
@@ -31,6 +31,7 @@
#include <QComboBox>
#include <QButtonGroup>
#include <QCheckBox>
+#include <QDateTime>
#include <extcap_parser.h>
@@ -207,6 +208,26 @@ private:
bool defaultBool();
};
+class ExtArgTimestamp : public ExtcapArgument
+{
+ Q_OBJECT
+
+public:
+ ExtArgTimestamp(extcap_arg * argument);
+ virtual QWidget * createEditor(QWidget * parent);
+
+ virtual bool isValid();
+ virtual QString defaultValue();
+ virtual QString value();
+ virtual QString prefValue();
+
+private Q_SLOTS:
+ void onDateTimeChanged(QDateTime);
+
+private:
+ QDateTime ts;
+};
+
#endif /* UI_QT_EXTCAP_ARGUMENT_H_ */
/*
diff --git a/ui/qt/extcap_options_dialog.cpp b/ui/qt/extcap_options_dialog.cpp
index ae798e29d9..2aea0dc490 100644
--- a/ui/qt/extcap_options_dialog.cpp
+++ b/ui/qt/extcap_options_dialog.cpp
@@ -184,6 +184,11 @@ void ExtcapOptionsDialog::anyValueChanged()
if ( ! ((ExtArgText *)*iter)->isValid() )
allowStart = false;
}
+ else if ( dynamic_cast<ExtArgTimestamp *>((*iter)) != NULL)
+ {
+ if ( ! ((ExtArgTimestamp *)*iter)->isValid() )
+ allowStart = false;
+ }
else
if ( ! (*iter)->isValid() )
allowStart = false;
@@ -465,6 +470,10 @@ void ExtcapOptionsDialog::storeValues()
{
value = ((ExtArgText *)*iter)->prefValue();
}
+ else if ( dynamic_cast<ExtArgTimestamp *>((*iter)) != NULL)
+ {
+ value = ((ExtArgTimestamp *)*iter)->prefValue();
+ }
else
value = (*iter)->prefValue();