From fc2f31810a6096909c8f81f9f74659edbec7a55b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mo=C5=84?= Date: Sun, 12 Oct 2014 17:26:04 +0200 Subject: Fix handling of extcap boolflags which defaults to true. Example: arg {number=0}{call=--test}{type=boolflag}{default=true} Before this change --test was never added to argument list (no matter if user left it selected or explicitly deselected it). After this change --test will be added to argument list unless user explicitly deselects it. Change-Id: Ia5bc11f900b03e630aba882ef918dcb7f0b79291 Reviewed-on: https://code.wireshark.org/review/4618 Reviewed-by: Pascal Quantin Tested-by: Pascal Quantin --- extcap.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) (limited to 'extcap.c') diff --git a/extcap.c b/extcap.c index 81682186f0..c52eda6e34 100644 --- a/extcap.c +++ b/extcap.c @@ -342,6 +342,24 @@ extcap_interface_list(char **err_str) { return ret; } +static void extcap_free_if_configuration(GList *list) +{ + GList *elem; + + for (elem = g_list_first(list); elem; elem = elem->next) + { + GList *arg_list; + if (elem->data == NULL) + { + continue; + } + + arg_list = g_list_first((GList *)elem->data); + g_list_free_full(arg_list, g_free); + } + g_list_free(list); +} + static gboolean search_cb(const gchar *extcap _U_, gchar *output, void *data, char **err_str _U_) { extcap_token_sentence *tokens = NULL; @@ -519,8 +537,52 @@ extcaps_init_initerfaces(capture_options *capture_opts) add_arg(interface_opts.name); add_arg(EXTCAP_ARGUMENT_RUN_PIPE); add_arg(interface_opts.extcap_fifo); - if (interface_opts.extcap_args != NULL) + if (interface_opts.extcap_args == NULL) + { + /* User did not perform interface configuration. + * + * Check if there are any boolean flags that are set by default + * and hence their argument should be added. + */ + GList *arglist; + GList *elem; + + arglist = extcap_get_if_configuration(interface_opts.name); + for (elem = g_list_first(arglist); elem; elem = elem->next) + { + GList * arg_list; + extcap_arg *arg_iter; + + if (elem->data == NULL) + { + continue; + } + + arg_list = g_list_first((GList *)elem->data); + while (arg_list != NULL) + { + /* In case of boolflags only first element in arg_list is relevant. */ + arg_iter = (extcap_arg*) (arg_list->data); + + if (arg_iter->arg_type == EXTCAP_ARG_BOOLFLAG) + { + if (arg_iter->default_complex != NULL + && extcap_complex_get_bool(arg_iter->default_complex)) + { + add_arg(arg_iter->call); + } + } + + arg_list = arg_list->next; + } + } + + extcap_free_if_configuration(arglist); + } + else + { g_hash_table_foreach(interface_opts.extcap_args, extcap_arg_cb, args); + } add_arg(NULL); #undef add_arg -- cgit v1.2.3