aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xdoc/extcap_example.py7
-rw-r--r--extcap.h4
-rw-r--r--extcap_parser.c264
-rw-r--r--extcap_parser.h22
-rw-r--r--ui/qt/extcap_argument.cpp142
-rw-r--r--ui/qt/extcap_argument.h8
-rw-r--r--ui/qt/extcap_argument_file.cpp3
-rw-r--r--ui/qt/extcap_argument_multiselect.cpp16
-rw-r--r--ui/qt/extcap_argument_multiselect.h1
-rw-r--r--ui/qt/extcap_options_dialog.cpp13
-rw-r--r--ui/qt/extcap_options_dialog.h1
11 files changed, 161 insertions, 320 deletions
diff --git a/doc/extcap_example.py b/doc/extcap_example.py
index 39bb571075..571605837e 100755
--- a/doc/extcap_example.py
+++ b/doc/extcap_example.py
@@ -73,11 +73,12 @@ def extcap_config(interface):
args = []
values = []
- args.append ( (0, '--delay', 'Time delay', 'Time delay between packages', 'integer', '{range=1,15}') )
+ args.append ( (0, '--delay', 'Time delay', 'Time delay between packages', 'integer', '{range=1,15}{default=5}') )
args.append ( (1, '--message', 'Message', 'Package message content', 'string', '{required=true}') )
- args.append ( (2, '--verify', 'Verify', 'Verify package content', 'boolflag', '') )
+ args.append ( (2, '--verify', 'Verify', 'Verify package content', 'boolflag', '{default=yes}') )
args.append ( (3, '--remote', 'Remote Channel', 'Remote Channel Selector', 'selector', ''))
- args.append ( (4, '--fake_ip', 'Fake IP Address', 'Use this ip address as sender', 'string', '{validation=\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b}'))
+ args.append ( (4, '--fake_ip', 'Fake IP Address', 'Use this ip address as sender', 'string', '{save=false}{validation=\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b}'))
+ args.append ( (5, '--password', 'Password', 'Package message password', 'password', '') )
values.append ( (3, "if1", "Remote1", "true" ) )
values.append ( (3, "if2", "Remote2", "false" ) )
diff --git a/extcap.h b/extcap.h
index 74fc0b3b6d..02c230014f 100644
--- a/extcap.h
+++ b/extcap.h
@@ -37,6 +37,10 @@
#ifdef HAVE_EXTCAP
+/* As boolean flags will be allowed any form of yes, true or any number != 0 (or starting with 0)
+ * The regex will be matched case-insensitive, so only the lower-case is defined here. */
+#define EXTCAP_BOOLEAN_REGEX "^.*([yt1-9])"
+
/* Prefix for the pipe interfaces */
#define EXTCAP_PIPE_PREFIX "wireshark_extcap"
diff --git a/extcap_parser.c b/extcap_parser.c
index a562ada52c..37c0e70728 100644
--- a/extcap_parser.c
+++ b/extcap_parser.c
@@ -28,6 +28,7 @@
#include <glib.h>
#include <string.h>
+#include "extcap.h"
#include "extcap_parser.h"
void extcap_printf_complex(extcap_complex *comp) {
@@ -37,210 +38,82 @@ void extcap_printf_complex(extcap_complex *comp) {
}
gchar *extcap_get_complex_as_string(extcap_complex *comp) {
- /* Pick an arbitrary size that should be big enough */
- gchar *ret = g_new(gchar, 32);
-
- if (comp == NULL) {
- g_snprintf(ret, 32, "(null)");
- return ret;
- }
-
- switch (comp->complex_type) {
- case EXTCAP_ARG_INTEGER:
- g_snprintf(ret, 32, "%d", comp->complex_value.int_value);
- break;
- case EXTCAP_ARG_UNSIGNED:
- g_snprintf(ret, 32, "%u", comp->complex_value.uint_value);
- break;
- case EXTCAP_ARG_LONG:
- g_snprintf(ret, 32, "%ld", comp->complex_value.long_value);
- break;
- case EXTCAP_ARG_DOUBLE:
- g_snprintf(ret, 32, "%f", comp->complex_value.double_value);
- break;
- case EXTCAP_ARG_BOOLEAN:
- g_snprintf(ret, 32, "%s",
- comp->complex_value.bool_value ? "true" : "false");
- break;
- case EXTCAP_ARG_STRING:
- case EXTCAP_ARG_PASSWORD:
- case EXTCAP_ARG_FILESELECT:
- g_free(ret);
- ret = g_strdup(comp->complex_value.string_value);
- break;
- default:
- /* Nulling out the return string */
- g_snprintf(ret, 32, " ");
- break;
- }
-
- return ret;
+ return (comp ? g_strdup(comp->_val) : NULL);
}
extcap_complex *extcap_parse_complex(extcap_arg_type complex_type,
const gchar *data) {
- extcap_complex *rc = g_new(extcap_complex, 1);
- gboolean success = FALSE;
- long double exp_f;
-
- switch (complex_type) {
- case EXTCAP_ARG_INTEGER:
- if (sscanf(data, "%Lf", &exp_f) == 1) {
- rc->complex_value.int_value = (int) exp_f;
- success = TRUE;
- break;
- }
- break;
- case EXTCAP_ARG_UNSIGNED:
- if (sscanf(data, "%Lf", &exp_f) == 1) {
- rc->complex_value.uint_value = (unsigned int) exp_f;
- success = TRUE;
- break;
- }
- break;
- case EXTCAP_ARG_LONG:
- if (sscanf(data, "%Lf", &exp_f) == 1) {
- rc->complex_value.long_value = (long) exp_f;
- success = TRUE;
- break;
- }
- break;
- case EXTCAP_ARG_DOUBLE:
- if (sscanf(data, "%Lf", &exp_f) == 1) {
- rc->complex_value.double_value = (double) exp_f;
- success = TRUE;
- break;
- }
- break;
- case EXTCAP_ARG_BOOLEAN:
- case EXTCAP_ARG_BOOLFLAG:
- if (data[0] == 't' || data[0] == 'T' || data[0] == '1') {
- rc->complex_value.bool_value = 1;
- } else {
- rc->complex_value.bool_value = 0;
- }
- success = TRUE;
- break;
- case EXTCAP_ARG_STRING:
- case EXTCAP_ARG_PASSWORD:
- case EXTCAP_ARG_FILESELECT:
- rc->complex_value.string_value = g_strdup(data);
- success = TRUE;
- break;
- default:
- break;
- }
- if (!success) {
- g_free(rc);
- return NULL ;
- }
+ extcap_complex *rc = g_new0(extcap_complex, 1);
+ rc->_val = g_strdup( (gchar *) data);
rc->complex_type = complex_type;
- rc->value_filled = TRUE;
return rc;
}
gboolean extcap_compare_is_default(extcap_arg *element, extcap_complex *test) {
- gboolean result = FALSE;
-
- if (element->default_complex == NULL)
- return result;
-
- switch (element->arg_type) {
- case EXTCAP_ARG_INTEGER:
- if (extcap_complex_get_int(test)
- == extcap_complex_get_int(element->default_complex))
- result = TRUE;
- break;
- case EXTCAP_ARG_UNSIGNED:
- if (extcap_complex_get_uint(test)
- == extcap_complex_get_uint(element->default_complex))
- result = TRUE;
- break;
- case EXTCAP_ARG_LONG:
- if (extcap_complex_get_long(test)
- == extcap_complex_get_long(element->default_complex))
- result = TRUE;
- break;
- case EXTCAP_ARG_DOUBLE:
- if (extcap_complex_get_double(test)
- == extcap_complex_get_double(element->default_complex))
- result = TRUE;
- break;
- case EXTCAP_ARG_BOOLEAN:
- case EXTCAP_ARG_BOOLFLAG:
- if (extcap_complex_get_bool(test)
- == extcap_complex_get_bool(element->default_complex))
- result = TRUE;
- break;
- case EXTCAP_ARG_STRING:
- case EXTCAP_ARG_PASSWORD:
- if (strcmp(extcap_complex_get_string(test),
- extcap_complex_get_string(element->default_complex)) == 0)
- result = TRUE;
- break;
-
- default:
- break;
- }
+ if ( element == NULL || element->default_complex == NULL || test == NULL )
+ return FALSE;
+
+ if ( g_strcmp0(element->default_complex->_val, test->_val) == 0 )
+ return TRUE;
- return result;
+ return FALSE;
}
void extcap_free_complex(extcap_complex *comp) {
- if (comp->complex_type == EXTCAP_ARG_STRING
- || comp->complex_type == EXTCAP_ARG_PASSWORD
- || comp->complex_type == EXTCAP_ARG_FILESELECT)
- g_free(comp->complex_value.string_value);
-
+ if ( comp )
+ g_free(comp->_val);
g_free(comp);
}
-int extcap_complex_get_int(extcap_complex *comp) {
- if ( comp == NULL )
- return (int)0;
- return comp->complex_value.int_value;
+gint extcap_complex_get_int(extcap_complex *comp) {
+ if ( comp == NULL || comp->_val == NULL || comp->complex_type != EXTCAP_ARG_INTEGER )
+ return (gint)0;
+
+ return (gint) g_ascii_strtoll(comp->_val, NULL, 10);
}
-unsigned int extcap_complex_get_uint(extcap_complex *comp) {
- if ( comp == NULL )
- return (unsigned int)0;
- return comp->complex_value.uint_value;
+guint extcap_complex_get_uint(extcap_complex *comp) {
+ if ( comp == NULL || comp->_val == NULL || comp->complex_type != EXTCAP_ARG_UNSIGNED )
+ return (guint)0;
+ return (guint) g_ascii_strtoull(comp->_val, NULL, 10);
}
-long extcap_complex_get_long(extcap_complex *comp) {
- if ( comp == NULL )
- return (long)0;
- return comp->complex_value.long_value;
+gint64 extcap_complex_get_long(extcap_complex *comp) {
+ if ( comp == NULL || comp->_val == NULL || comp->complex_type != EXTCAP_ARG_LONG )
+ return (gint64)0;
+ return g_ascii_strtoll( comp->_val, NULL, 10 );
}
-double extcap_complex_get_double(extcap_complex *comp) {
- if ( comp == NULL )
- return (double)0;
- return comp->complex_value.double_value;
+gdouble extcap_complex_get_double(extcap_complex *comp) {
+ if ( comp == NULL || comp->_val == NULL || comp->complex_type != EXTCAP_ARG_DOUBLE )
+ return (gdouble)0;
+ return g_strtod( comp->_val, NULL );
}
gboolean extcap_complex_get_bool(extcap_complex *comp) {
- if ( comp == NULL )
+ if ( comp == NULL || comp->_val == NULL )
return FALSE;
- return comp->complex_value.bool_value;
+
+ if ( comp->complex_type != EXTCAP_ARG_BOOLEAN && comp->complex_type != EXTCAP_ARG_BOOLFLAG )
+ return FALSE;
+
+ return g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, comp->_val, G_REGEX_CASELESS, (GRegexMatchFlags)0 );
}
gchar *extcap_complex_get_string(extcap_complex *comp) {
- return comp->complex_value.string_value;
+ /* Not checking for argument type, to use this method as fallback if only strings are needed */
+ return comp != NULL ? comp->_val : NULL;
}
void extcap_free_tokenized_param(extcap_token_param *v) {
- if (v == NULL)
- return;
-
- if (v->arg != NULL)
+ if (v != NULL)
+ {
g_free(v->arg);
-
- if (v->value != NULL)
g_free(v->value);
+ }
g_free(v);
}
@@ -349,6 +222,8 @@ extcap_token_sentence *extcap_tokenize_sentence(const gchar *s) {
tv->param_type = EXTCAP_PARAM_PARENT;
} else if (g_ascii_strcasecmp(tv->arg, "required") == 0) {
tv->param_type = EXTCAP_PARAM_REQUIRED;
+ } else if (g_ascii_strcasecmp(tv->arg, "save") == 0) {
+ tv->param_type = EXTCAP_PARAM_SAVE;
} else if (g_ascii_strcasecmp(tv->arg, "validation") == 0) {
tv->param_type = EXTCAP_PARAM_VALIDATION;
} else if (g_ascii_strcasecmp(tv->arg, "version") == 0) {
@@ -464,27 +339,6 @@ void extcap_free_dlt(extcap_dlt *d) {
g_free(d->display);
}
-extcap_arg *extcap_new_arg(void) {
- extcap_arg *r = g_new(extcap_arg, 1);
-
- r->call = NULL;
- r->display = NULL;
- r->tooltip = NULL;
- r->arg_type = EXTCAP_ARG_UNKNOWN;
- r->range_start = NULL;
- r->range_end = NULL;
- r->default_complex = NULL;
- r->fileexists = FALSE;
- r->fileextension = NULL;
- r->regexp = NULL;
- r->is_required = FALSE;
-
- r->values = NULL;
- /*r->next_arg = NULL; */
-
- return r;
-}
-
static void extcap_free_valuelist(gpointer data, gpointer user_data _U_) {
extcap_free_value((extcap_value *) data);
}
@@ -548,7 +402,8 @@ extcap_arg *extcap_parse_arg_sentence(GList * args, extcap_token_sentence *s) {
}
if (sent == EXTCAP_SENTENCE_ARG) {
- target_arg = extcap_new_arg();
+ target_arg = g_new0(extcap_arg, 1);
+ target_arg->arg_type = EXTCAP_ARG_UNKNOWN;
if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_ARGNUM))
== NULL) {
@@ -588,7 +443,7 @@ extcap_arg *extcap_parse_arg_sentence(GList * args, extcap_token_sentence *s) {
if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_FILE_MUSTEXIST))
!= NULL) {
- target_arg->fileexists = (v->value[0] == 't' || v->value[0] == 'T');
+ target_arg->fileexists = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, v->value, G_REGEX_CASELESS, (GRegexMatchFlags)0 );
}
if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_FILE_EXTENSION))
@@ -603,7 +458,7 @@ extcap_arg *extcap_parse_arg_sentence(GList * args, extcap_token_sentence *s) {
if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_REQUIRED))
!= NULL) {
- target_arg->is_required = (v->value[0] == 't' || v->value[0] == 'T');
+ target_arg->is_required = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, v->value, G_REGEX_CASELESS, (GRegexMatchFlags)0 );
}
if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_TYPE))
@@ -633,6 +488,8 @@ extcap_arg *extcap_parse_arg_sentence(GList * args, extcap_token_sentence *s) {
target_arg->arg_type = EXTCAP_ARG_STRING;
} else if (g_ascii_strcasecmp(v->value, "password") == 0) {
target_arg->arg_type = EXTCAP_ARG_PASSWORD;
+ /* default setting is to not save passwords */
+ target_arg->do_not_save = TRUE;
} else if (g_ascii_strcasecmp(v->value, "fileselect") == 0) {
target_arg->arg_type = EXTCAP_ARG_FILESELECT;
} else if (g_ascii_strcasecmp(v->value, "multicheck") == 0) {
@@ -643,6 +500,11 @@ extcap_arg *extcap_parse_arg_sentence(GList * args, extcap_token_sentence *s) {
return NULL ;
}
+ if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_SAVE))
+ != NULL) {
+ target_arg->do_not_save = ! g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, v->value, G_REGEX_CASELESS, (GRegexMatchFlags)0 );
+ }
+
if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_RANGE))
!= NULL) {
gchar *cp = g_strstr_len(v->value, -1, ",");
@@ -673,9 +535,12 @@ extcap_arg *extcap_parse_arg_sentence(GList * args, extcap_token_sentence *s) {
if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_DEFAULT))
!= NULL) {
- if ((target_arg->default_complex = extcap_parse_complex(
- target_arg->arg_type, v->value)) == NULL) {
- printf("invalid default, couldn't parse %s\n", v->value);
+ if ( target_arg->arg_type != EXTCAP_ARG_MULTICHECK && target_arg->arg_type != EXTCAP_ARG_SELECTOR )
+ {
+ if ((target_arg->default_complex = extcap_parse_complex(
+ target_arg->arg_type, v->value)) == NULL) {
+ printf("invalid default, couldn't parse %s\n", v->value);
+ }
}
}
@@ -698,13 +563,8 @@ extcap_arg *extcap_parse_arg_sentence(GList * args, extcap_token_sentence *s) {
return NULL ;
}
- value = g_new(extcap_value, 1);
- value->display = NULL;
- value->call = NULL;
- value->enabled = FALSE;
- value->is_default = FALSE;
+ value = g_new0(extcap_value, 1);
value->arg_num = tint;
- value->parent = NULL;
if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_VALUE))
== NULL) {
@@ -730,12 +590,12 @@ extcap_arg *extcap_parse_arg_sentence(GList * args, extcap_token_sentence *s) {
if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_DEFAULT))
!= NULL) {
/* printf("found default value\n"); */
- value->is_default = (v->value[0] == 't' || v->value[0] == 'T');
+ value->is_default = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, v->value, G_REGEX_CASELESS, (GRegexMatchFlags)0 );
}
if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_ENABLED))
!= NULL) {
- value->enabled = (v->value[0] == 't' || v->value[0] == 'T');
+ value->enabled = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, v->value, G_REGEX_CASELESS, (GRegexMatchFlags)0 );
}
((extcap_arg*) entry->data)->values = g_list_append(
diff --git a/extcap_parser.h b/extcap_parser.h
index 83600510aa..d1074c8a9b 100644
--- a/extcap_parser.h
+++ b/extcap_parser.h
@@ -71,6 +71,7 @@ typedef enum {
EXTCAP_PARAM_FILE_EXTENSION,
EXTCAP_PARAM_PARENT,
EXTCAP_PARAM_REQUIRED,
+ EXTCAP_PARAM_SAVE,
EXTCAP_PARAM_VALIDATION,
EXTCAP_PARAM_VERSION
} extcap_param_type;
@@ -91,15 +92,7 @@ typedef struct _extcap_value {
/* Complex-ish struct for storing complex values */
typedef struct _extcap_complex {
extcap_arg_type complex_type;
- union {
- int int_value;
- unsigned int uint_value;
- long long_value;
- double double_value;
- gboolean bool_value;
- gchar *string_value;
- } complex_value;
- gboolean value_filled;
+ gchar * _val;
} extcap_complex;
/* An argument sentence and accompanying options */
@@ -114,6 +107,7 @@ typedef struct _extcap_arg {
gboolean fileexists;
gboolean is_required;
+ gboolean do_not_save;
gchar * regexp;
@@ -192,10 +186,10 @@ void extcap_printf_complex(extcap_complex *comp);
*/
gchar *extcap_get_complex_as_string(extcap_complex *comp);
-int extcap_complex_get_int(extcap_complex *comp);
-unsigned int extcap_complex_get_uint(extcap_complex *comp);
-long extcap_complex_get_long(extcap_complex *comp);
-double extcap_complex_get_double(extcap_complex *comp);
+gint extcap_complex_get_int(extcap_complex *comp);
+guint extcap_complex_get_uint(extcap_complex *comp);
+gint64 extcap_complex_get_long(extcap_complex *comp);
+gdouble extcap_complex_get_double(extcap_complex *comp);
gboolean extcap_complex_get_bool(extcap_complex *comp);
gchar *extcap_complex_get_string(extcap_complex *comp);
@@ -221,8 +215,6 @@ extcap_token_param *extcap_find_param_by_type(extcap_token_param *first,
void extcap_free_value(extcap_value *v);
-extcap_arg *extcap_new_arg(void);
-
/* Free a single argument */
void extcap_free_arg(extcap_arg *a);
diff --git a/ui/qt/extcap_argument.cpp b/ui/qt/extcap_argument.cpp
index 38dc865770..0c06107f3e 100644
--- a/ui/qt/extcap_argument.cpp
+++ b/ui/qt/extcap_argument.cpp
@@ -41,6 +41,8 @@
#include <QStandardItemModel>
#include <QItemSelectionModel>
+#include <glib.h>
+#include <log.h>
#include <epan/prefs.h>
#include <color_utils.h>
@@ -138,19 +140,11 @@ QWidget * ExtArgRadio::createEditor(QWidget * parent)
QString callString = (*iter).call();
callStrings->append(callString);
- if ( _default != NULL && (*iter).isDefault() )
+ if ( (*iter).isDefault() )
{
radio->setChecked(true);
anyChecked = true;
}
- else if (_default != NULL)
- {
- if ( callString.compare(_default->toString()) == 0 )
- {
- radio->setChecked(true);
- anyChecked = true;
- }
- }
connect(radio, SIGNAL(clicked(bool)), SLOT(onBoolChanged(bool)));
selectorGroup->addButton(radio, count);
@@ -219,19 +213,13 @@ QWidget * ExtArgBool::createLabel(QWidget * parent)
QWidget * ExtArgBool::createEditor(QWidget * parent)
{
+ bool state = defaultBool();
+
boolBox = new QCheckBox(QString().fromUtf8(_argument->display), parent);
if ( _argument->tooltip != NULL )
boolBox->setToolTip(QString().fromUtf8(_argument->tooltip));
- if ( _argument->default_complex != NULL )
- if ( extcap_complex_get_bool(_argument->default_complex) == (gboolean)TRUE )
- boolBox->setCheckState(Qt::Checked);
-
- if ( _default != NULL )
- {
- if ( _default->toString().compare("true") )
- boolBox->setCheckState(Qt::Checked);
- }
+ boolBox->setCheckState(state ? Qt::Checked : Qt::Unchecked );
connect (boolBox, SIGNAL(stateChanged(int)), SLOT(onIntChanged(int)));
@@ -263,26 +251,37 @@ bool ExtArgBool::isValid()
return true;
}
-QString ExtArgBool::defaultValue()
+bool ExtArgBool::defaultBool()
{
- if ( _argument != 0 && _argument->default_complex != NULL )
- if ( extcap_complex_get_bool(_argument->default_complex) == (gboolean)TRUE )
- return QString("true");
+ bool result = false;
+
+ if ( _argument )
+ {
+ if ( _argument->default_complex )
+ {
+ if ( extcap_complex_get_bool(_argument->default_complex) == (gboolean)TRUE )
+ result = true;
+ }
+ }
+
+ return result;
+}
- return QString("false");
+QString ExtArgBool::defaultValue()
+{
+ return defaultBool() ? QString("true") : QString("false");
}
ExtArgText::ExtArgText(extcap_arg * argument) :
ExtcapArgument(argument), textBox(0)
{
- _default = new QVariant(QString(""));
}
QWidget * ExtArgText::createEditor(QWidget * parent)
{
- textBox = new QLineEdit(_default->toString(), parent);
+ QString text = defaultValue();
- textBox->setText(defaultValue());
+ textBox = new QLineEdit(text, parent);
if ( _argument->tooltip != NULL )
textBox->setToolTip(QString().fromUtf8(_argument->tooltip));
@@ -330,23 +329,12 @@ bool ExtArgText::isValid()
return valid;
}
-QString ExtArgText::defaultValue()
-{
- if ( _argument != 0 && _argument->default_complex != 0)
- {
- gchar * str = extcap_get_complex_as_string(_argument->default_complex);
- if ( str != 0 )
- return QString(str);
- }
-
- return QString();
-}
-
ExtArgNumber::ExtArgNumber(extcap_arg * argument) :
ExtArgText(argument) {}
QWidget * ExtArgNumber::createEditor(QWidget * parent)
{
+ QString text = defaultValue();
textBox = (QLineEdit *)ExtArgText::createEditor(parent);
textBox->disconnect(SIGNAL(textChanged(QString)));
@@ -354,13 +342,45 @@ QWidget * ExtArgNumber::createEditor(QWidget * parent)
{
QIntValidator * textValidator = new QIntValidator(parent);
if ( _argument->range_start != NULL )
- textValidator->setBottom(extcap_complex_get_int(_argument->range_start));
+ {
+ int val = 0;
+ if ( _argument->arg_type == EXTCAP_ARG_INTEGER )
+ val = extcap_complex_get_int(_argument->range_start);
+ else if ( _argument->arg_type == EXTCAP_ARG_UNSIGNED )
+ {
+ val = extcap_complex_get_uint(_argument->range_start);
+ if ( val > G_MAXINT )
+ {
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Defined value for range_start of %s exceeds valid integer range", _argument->call );
+ val = G_MAXINT;
+ }
+ }
+ textValidator->setBottom(val);
+ }
if ( _argument->arg_type == EXTCAP_ARG_UNSIGNED && textValidator->bottom() < 0 )
+ {
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "%s sets negative bottom range for unsigned value, setting to 0", _argument->call );
textValidator->setBottom(0);
+ }
if ( _argument->range_end != NULL )
- textValidator->setTop(extcap_complex_get_int(_argument->range_end));
+ {
+ int val = 0;
+ if ( _argument->arg_type == EXTCAP_ARG_INTEGER )
+ val = extcap_complex_get_int(_argument->range_end);
+ else if ( _argument->arg_type == EXTCAP_ARG_UNSIGNED )
+ {
+ val = extcap_complex_get_uint(_argument->range_end);
+ if ( val > G_MAXINT )
+ {
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Defined value for range_end of %s exceeds valid integer range", _argument->call );
+ val = G_MAXINT;
+ }
+ }
+
+ textValidator->setTop(val);
+ }
textBox->setValidator(textValidator);
}
else if ( _argument->arg_type == EXTCAP_ARG_DOUBLE )
@@ -374,7 +394,7 @@ QWidget * ExtArgNumber::createEditor(QWidget * parent)
textBox->setValidator(textValidator);
}
- textBox->setText(defaultValue());
+ textBox->setText(text.trimmed());
connect(textBox, SIGNAL(textChanged(QString)), SLOT(onStringChanged(QString)));
@@ -385,7 +405,7 @@ QString ExtArgNumber::defaultValue()
{
QString result;
- if ( _argument != 0 && _argument->default_complex != NULL )
+ if ( _argument != 0 )
{
if ( _argument->arg_type == EXTCAP_ARG_DOUBLE )
result = QString::number(extcap_complex_get_double(_argument->default_complex));
@@ -396,7 +416,10 @@ QString ExtArgNumber::defaultValue()
else if ( _argument->arg_type == EXTCAP_ARG_LONG )
result = QString::number(extcap_complex_get_long(_argument->default_complex));
else
- result = QString();
+ {
+ QString defValue = ExtcapArgument::defaultValue();
+ result = defValue.length() > 0 ? defValue : QString();
+ }
}
return result;
@@ -417,7 +440,7 @@ void ExtcapValue::setChildren(ExtcapValueList children)
}
ExtcapArgument::ExtcapArgument(extcap_arg * argument, QObject *parent) :
- QObject(parent), _argument(argument), _default(0), _label(0),
+ QObject(parent), _argument(argument), _label(0),
label_style(QString("QLabel { color: %1; }"))
{
if ( _argument->values != 0 )
@@ -515,29 +538,14 @@ bool ExtcapArgument::isValid()
QString ExtcapArgument::defaultValue()
{
- return QString();
-}
-
-void ExtcapArgument::setDefault(GHashTable * defaultsList)
-{
- if ( defaultsList != NULL && g_hash_table_size(defaultsList) > 0 )
+ if ( _argument != 0 && _argument->default_complex != 0)
{
- GList * keys = g_hash_table_get_keys(defaultsList);
- while ( keys != NULL )
- {
- if ( call().compare(QString().fromUtf8((gchar *)keys->data)) == 0 )
- {
- gpointer data = g_hash_table_lookup(defaultsList, keys->data);
- QString dataStr = QString().fromUtf8((gchar *)data);
- /* We assume an empty value but set entry must be a boolflag */
- if ( dataStr.length() == 0 )
- dataStr = "true";
- _default = new QVariant(dataStr);
- break;
- }
- keys = keys->next;
- }
+ gchar * str = extcap_get_complex_as_string(_argument->default_complex);
+ if ( str != 0 )
+ return QString(str);
}
+
+ return QString();
}
bool ExtcapArgument::isRequired()
@@ -564,7 +572,7 @@ bool ExtcapArgument::isDefault()
return false;
}
-ExtcapArgument * ExtcapArgument::create(extcap_arg * argument, GHashTable * device_defaults)
+ExtcapArgument * ExtcapArgument::create(extcap_arg * argument)
{
if ( argument == 0 || argument->display == 0 )
return 0;
@@ -592,8 +600,6 @@ ExtcapArgument * ExtcapArgument::create(extcap_arg * argument, GHashTable * devi
result = new ExtcapArgument(argument);
}
- result->setDefault(device_defaults);
-
return result;
}
diff --git a/ui/qt/extcap_argument.h b/ui/qt/extcap_argument.h
index 017a163378..c83111a2d3 100644
--- a/ui/qt/extcap_argument.h
+++ b/ui/qt/extcap_argument.h
@@ -98,7 +98,7 @@ public:
bool isValid();
bool isRequired();
- static ExtcapArgument * create(extcap_arg * argument = 0, GHashTable * device_defaults = 0);
+ static ExtcapArgument * create(extcap_arg * argument = 0);
Q_SIGNALS:
void valueChanged();
@@ -107,14 +107,11 @@ protected:
bool fileExists();
- void setDefault(GHashTable * defaultsList);
-
ExtcapValueList loadValues(QString parent);
ExtcapValueList values;
extcap_arg * _argument;
- QVariant * _default;
QWidget * _label;
const QString label_style;
@@ -136,7 +133,6 @@ public:
virtual QWidget * createEditor(QWidget * parent);
virtual QString value();
virtual bool isValid();
- virtual QString defaultValue();
protected:
@@ -197,6 +193,8 @@ public:
private:
QCheckBox * boolBox;
+
+ bool defaultBool();
};
#endif /* UI_QT_EXTCAP_ARGUMENT_H_ */
diff --git a/ui/qt/extcap_argument_file.cpp b/ui/qt/extcap_argument_file.cpp
index b93e889ef6..4d2e301aa1 100644
--- a/ui/qt/extcap_argument_file.cpp
+++ b/ui/qt/extcap_argument_file.cpp
@@ -43,7 +43,6 @@
ExtcapArgumentFileSelection::ExtcapArgumentFileSelection (extcap_arg * argument) :
ExtcapArgument(argument), textBox(0)
{
- _default = new QVariant(QString(""));
}
ExtcapArgumentFileSelection::~ExtcapArgumentFileSelection()
@@ -61,7 +60,7 @@ QWidget * ExtcapArgumentFileSelection::createEditor(QWidget * parent)
fileWidget->setContentsMargins(margins.left(), margins.right(), 0, margins.bottom());
QPushButton * button = new QPushButton(UTF8_HORIZONTAL_ELLIPSIS, fileWidget);
- textBox = new QLineEdit(_default->toString(), parent);
+ textBox = new QLineEdit(defaultValue(), parent);
textBox->setReadOnly(true);
if ( _argument->default_complex != NULL && _argument->arg_type == EXTCAP_ARG_STRING )
diff --git a/ui/qt/extcap_argument_multiselect.cpp b/ui/qt/extcap_argument_multiselect.cpp
index fc01dfb351..221f0f240b 100644
--- a/ui/qt/extcap_argument_multiselect.cpp
+++ b/ui/qt/extcap_argument_multiselect.cpp
@@ -119,8 +119,8 @@ QWidget * ExtArgMultiSelect::createEditor(QWidget * parent)
if (items.length() == 0)
return new QWidget();
- if ( _default != 0 )
- defaults = _default->toString().split(",", QString::SkipEmptyParts);
+ if ( defaultValue().length() > 0 )
+ defaults = defaultValue().split(",", QString::SkipEmptyParts);
viewModel = new QStandardItemModel();
QList<QStandardItem *>::const_iterator iter = items.constBegin();
@@ -173,18 +173,6 @@ QString ExtArgMultiSelect::value()
return result.join(QString(","));
}
-QString ExtArgMultiSelect::defaultValue()
-{
- if ( _argument != 0 && _argument->default_complex != 0)
- {
- gchar * str = extcap_get_complex_as_string(_argument->default_complex);
- if ( str != 0 )
- return QString(str);
- }
-
- return QString();
-}
-
void ExtArgMultiSelect::selectionChanged(const QItemSelection &, const QItemSelection &)
{
emit valueChanged();
diff --git a/ui/qt/extcap_argument_multiselect.h b/ui/qt/extcap_argument_multiselect.h
index 9e72faeca2..69259e0025 100644
--- a/ui/qt/extcap_argument_multiselect.h
+++ b/ui/qt/extcap_argument_multiselect.h
@@ -40,7 +40,6 @@ public:
virtual ~ExtArgMultiSelect();
virtual QString value();
- virtual QString defaultValue();
virtual bool isValid();
protected:
diff --git a/ui/qt/extcap_options_dialog.cpp b/ui/qt/extcap_options_dialog.cpp
index e2b5c165ca..f36d4afbd8 100644
--- a/ui/qt/extcap_options_dialog.cpp
+++ b/ui/qt/extcap_options_dialog.cpp
@@ -62,15 +62,14 @@ ExtcapOptionsDialog::ExtcapOptionsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ExtcapOptionsDialog),
device_name(""),
- device_idx(0),
- device_defaults(NULL)
+ device_idx(0)
{
ui->setupUi(this);
setWindowTitle(wsApp->windowTitleString(tr("Extcap Interface Options")));
- ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Start"));
+ ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Start"));
}
ExtcapOptionsDialog * ExtcapOptionsDialog::createForDevice(QString &dev_name, QWidget *parent)
@@ -99,7 +98,6 @@ ExtcapOptionsDialog * ExtcapOptionsDialog::createForDevice(QString &dev_name, QW
resultDialog = new ExtcapOptionsDialog(parent);
resultDialog->device_name = QString(dev_name);
resultDialog->device_idx = if_idx;
- resultDialog->device_defaults = device.external_cap_args_settings;
resultDialog->setWindowTitle(wsApp->windowTitleString(tr("Extcap Interface Options") + ": " + device.display_name));
@@ -205,7 +203,7 @@ void ExtcapOptionsDialog::updateWidgets()
item = g_list_first((GList *)(walker->data));
while ( item != NULL )
{
- argument = ExtcapArgument::create((extcap_arg *)(item->data), device_defaults);
+ argument = ExtcapArgument::create((extcap_arg *)(item->data));
if ( argument != NULL )
{
if ( argument->isRequired() )
@@ -266,9 +264,7 @@ void ExtcapOptionsDialog::updateWidgets()
// Not sure why we have to do this manually.
void ExtcapOptionsDialog::on_buttonBox_rejected()
{
- if (saveOptionToCaptureInfo()) {
- reject();
- }
+ reject();
}
void ExtcapOptionsDialog::on_buttonBox_helpRequested()
@@ -305,7 +301,6 @@ bool ExtcapOptionsDialog::saveOptionToCaptureInfo()
gchar * call_string = g_strdup(call.toStdString().c_str());
gchar * value_string = g_strdup(value.toStdString().c_str());
-
g_hash_table_insert(ret_args, call_string, value_string );
}
diff --git a/ui/qt/extcap_options_dialog.h b/ui/qt/extcap_options_dialog.h
index c508d62701..eb0761df8e 100644
--- a/ui/qt/extcap_options_dialog.h
+++ b/ui/qt/extcap_options_dialog.h
@@ -66,7 +66,6 @@ private:
Ui::ExtcapOptionsDialog *ui;
QString device_name;
guint device_idx;
- GHashTable * device_defaults;
ExtcapArgumentList extcapArguments;