summaryrefslogtreecommitdiff
path: root/extcap_parser.c
diff options
context:
space:
mode:
authorRoland Knall <roland.knall@br-automation.com>2015-12-29 15:35:43 +0100
committerStig Bjørlykke <stig@bjorlykke.org>2016-01-05 14:41:12 +0000
commitcfd5457ec0575be3b1b8726daf95fdc4da0e50fb (patch)
treefe3ff5d04d5f0c8d077831b3fb9135ae9520960e /extcap_parser.c
parenta7e3ba03ce6eaeebc762322cb1691adeeda46ff8 (diff)
downloadwireshark-cfd5457ec0575be3b1b8726daf95fdc4da0e50fb.tar.gz
extcap: Add regular expression validation support
Regular expressions follow the Qt Regex syntax, which is formulated after the Perl Regex syntax. A more detailed overview of the possible rules can be found at: http://doc.qt.io/qt-4.8/qregexp.html If a required option is present, even the double-click on the interface will first start the options dialog (Qt only) Required fields are marked bold and put first in the dialog. Additionally if validation failes (which it will if a required field is kept empty, but also if a non-required textfield is violating the defined regex), the label of the field is marked with red. Change-Id: If04a1146d0dfa778332ab2a39122c7a6ee1e93d2 Reviewed-on: https://code.wireshark.org/review/12914 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'extcap_parser.c')
-rw-r--r--extcap_parser.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/extcap_parser.c b/extcap_parser.c
index ef683f1a40..d884298a3a 100644
--- a/extcap_parser.c
+++ b/extcap_parser.c
@@ -300,6 +300,21 @@ extcap_token_sentence *extcap_tokenize_sentence(const gchar *s) {
return NULL ;
}
+ /* caught a regex quantifier end bracket and not the end of the line.
+ * let's find the correct end bracket */
+ if ( *(e+1) != '{' && strlen ( e ) > 1 ) {
+ gchar *f = (e + 1);
+
+ while ( ( f = g_strstr_len(f, -1, "}") ) != NULL) {
+ if ( strlen ( f ) <= 1 || *(f+1) == '{' )
+ break;
+ f++;
+ }
+
+ if ( f != NULL )
+ e = f;
+ }
+
if ((eq = g_strstr_len(b, -1, "=")) == NULL) {
/* printf("debug - tokenizer - invalid, missing =\n"); */
extcap_free_tokenized_sentence(rs);
@@ -349,6 +364,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, "validation") == 0) {
+ tv->param_type = EXTCAP_PARAM_VALIDATION;
} else {
tv->param_type = EXTCAP_PARAM_UNKNOWN;
}
@@ -480,6 +497,7 @@ extcap_arg *extcap_new_arg(void) {
r->default_complex = NULL;
r->fileexists = FALSE;
r->fileextension = NULL;
+ r->regexp = NULL;
r->is_required = FALSE;
r->values = NULL;
@@ -509,6 +527,9 @@ void extcap_free_arg(extcap_arg *a) {
if (a->fileextension != NULL)
g_free(a->fileextension);
+ if (a->regexp != NULL)
+ g_free(a->regexp);
+
if (a->range_start != NULL)
extcap_free_complex(a->range_start);
@@ -605,6 +626,11 @@ extcap_arg *extcap_parse_arg_sentence(GList * args, extcap_token_sentence *s) {
target_arg->fileextension = g_strdup(v->value);
}
+ if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_VALIDATION))
+ != NULL) {
+ target_arg->regexp = g_strdup(v->value);
+ }
+
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');