diff options
author | Roland Knall <roland.knall@br-automation.com> | 2018-03-02 15:41:00 +0100 |
---|---|---|
committer | Roland Knall <rknall@gmail.com> | 2018-04-05 09:31:23 +0000 |
commit | 6124ee2a1c06ccc96c3e9aa62c136f34085bfa61 (patch) | |
tree | a54fe1c4247e3f4519f71940d74c6a3f665d8a07 /extcap_parser.c | |
parent | c2422d78281e10beb6ce4ebda1d61c9d0ca63a09 (diff) |
extcap: Reload values on request
Allow certaing elements to be reloaded upon request. The way
this works is, certain elements can be configured to be reloadable.
By doing so, the extcap is asked once more just for the values
list of this item, together with all already set options, and
reloads the available options depending on the response.
Only supported for selector. Radio and Multiselect will need
additional patches, also moving those parts outside of extcap_argument.cpp
might make sense before hand.
Change-Id: I2e9e3d109b334bf878835a7cc9354f468bc22dee
Reviewed-on: https://code.wireshark.org/review/26223
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'extcap_parser.c')
-rw-r--r-- | extcap_parser.c | 143 |
1 files changed, 95 insertions, 48 deletions
diff --git a/extcap_parser.c b/extcap_parser.c index ca351743d5..24608d4af5 100644 --- a/extcap_parser.c +++ b/extcap_parser.c @@ -175,6 +175,8 @@ static extcap_token_sentence *extcap_tokenize_sentence(const gchar *s) { param_type = EXTCAP_PARAM_ENABLED; } else if (g_ascii_strcasecmp(arg, "parent") == 0) { param_type = EXTCAP_PARAM_PARENT; + } else if (g_ascii_strcasecmp(arg, "reload") == 0) { + param_type = EXTCAP_PARAM_RELOAD; } else if (g_ascii_strcasecmp(arg, "required") == 0) { param_type = EXTCAP_PARAM_REQUIRED; } else if (g_ascii_strcasecmp(arg, "save") == 0) { @@ -321,13 +323,74 @@ static void extcap_free_tokenized_sentences(GList *sentences) { g_list_free(sentences); } +static extcap_value *extcap_parse_value_sentence(extcap_token_sentence *s) { + extcap_value *value = NULL; + gchar *param_value = NULL; + + int tint = 0; + + if (s == NULL) + return value; + + if (g_ascii_strcasecmp(s->sentence, "value") == 0) { + + if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_ARG))) + == NULL) { + printf("no arg in VALUE sentence\n"); + return NULL; + } + + if (sscanf(param_value, "%d", &tint) != 1) { + printf("invalid arg in VALUE sentence\n"); + return NULL; + } + + value = g_new0(extcap_value, 1); + value->arg_num = tint; + + if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_VALUE))) + == NULL) { + /* printf("no value in VALUE sentence\n"); */ + extcap_free_value(value); + return NULL; + } + value->call = g_strdup(param_value); + + if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DISPLAY))) + == NULL) { + /* printf("no display in VALUE sentence\n"); */ + extcap_free_value(value); + return NULL; + } + value->display = g_strdup(param_value); + + if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_PARENT))) + != NULL) { + value->parent = g_strdup(param_value); + } + + if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DEFAULT))) + != NULL) { + /* printf("found default value\n"); */ + value->is_default = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, param_value, G_REGEX_CASELESS, (GRegexMatchFlags)0); + } + + if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_ENABLED))) + != NULL) { + value->enabled = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, param_value, G_REGEX_CASELESS, (GRegexMatchFlags)0); + } + } + + return value; +} + static extcap_arg *extcap_parse_arg_sentence(GList *args, extcap_token_sentence *s) { gchar *param_value = NULL; extcap_arg *target_arg = NULL; extcap_value *value = NULL; GList *entry = NULL; - int tint; + extcap_sentence_type sent = EXTCAP_SENTENCE_UNKNOWN; if (s == NULL) @@ -451,6 +514,11 @@ static extcap_arg *extcap_parse_arg_sentence(GList *args, extcap_token_sentence target_arg->save = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, param_value, G_REGEX_CASELESS, (GRegexMatchFlags)0); } + if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_RELOAD))) + != NULL) { + target_arg->reload = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, param_value, G_REGEX_CASELESS, (GRegexMatchFlags)0); + } + if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_RANGE))) != NULL) { gchar *cp = g_strstr_len(param_value, -1, ","); @@ -491,58 +559,14 @@ static extcap_arg *extcap_parse_arg_sentence(GList *args, extcap_token_sentence } } else if (sent == EXTCAP_SENTENCE_VALUE) { - if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_ARG))) - == NULL) { - printf("no arg in VALUE sentence\n"); - return NULL; - } - - if (sscanf(param_value, "%d", &tint) != 1) { - printf("invalid arg in VALUE sentence\n"); - return NULL; - } + value = extcap_parse_value_sentence(s); - if ((entry = g_list_find_custom(args, &tint, glist_find_numbered_arg)) + if ((entry = g_list_find_custom(args, &value->arg_num, glist_find_numbered_arg)) == NULL) { - printf("couldn't find arg %d in list for VALUE sentence\n", tint); + printf("couldn't find arg %d in list for VALUE sentence\n", value->arg_num); return NULL; } - value = g_new0(extcap_value, 1); - value->arg_num = tint; - - if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_VALUE))) - == NULL) { - /* printf("no value in VALUE sentence\n"); */ - extcap_free_value(value); - return NULL; - } - value->call = g_strdup(param_value); - - if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DISPLAY))) - == NULL) { - /* printf("no display in VALUE sentence\n"); */ - extcap_free_value(value); - return NULL; - } - value->display = g_strdup(param_value); - - if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_PARENT))) - != NULL) { - value->parent = g_strdup(param_value); - } - - if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DEFAULT))) - != NULL) { - /* printf("found default value\n"); */ - value->is_default = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, param_value, G_REGEX_CASELESS, (GRegexMatchFlags)0); - } - - if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_ENABLED))) - != NULL) { - value->enabled = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, param_value, G_REGEX_CASELESS, (GRegexMatchFlags)0); - } - ((extcap_arg *) entry->data)->values = g_list_append( ((extcap_arg *) entry->data)->values, value); @@ -575,6 +599,29 @@ GList *extcap_parse_args(gchar *output) { return result; } +GList *extcap_parse_values(gchar *output) { + GList *result = NULL; + GList *walker = NULL; + GList *temp = NULL; + + walker = extcap_tokenize_sentences(output); + temp = walker; + + while (walker) { + extcap_value *ra = NULL; + extcap_token_sentence *sentence = (extcap_token_sentence *)walker->data; + + if ((ra = extcap_parse_value_sentence(sentence)) != NULL) + result = g_list_append(result, (gpointer) ra); + + walker = g_list_next(walker); + } + + extcap_free_tokenized_sentences(temp); + + return result; +} + static extcap_interface *extcap_parse_interface_sentence(extcap_token_sentence *s) { extcap_sentence_type sent = EXTCAP_SENTENCE_UNKNOWN; gchar *param_value = NULL; |