* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config.h>
#include <glib.h>
#include <string.h>
+#include "ui/iface_toolbar.h"
+#include "wsutil/strtoi.h"
+
+#include "extcap.h"
#include "extcap_parser.h"
+#include "ws_attributes.h"
void extcap_printf_complex(extcap_complex *comp) {
gchar *ret = extcap_get_complex_as_string(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;
- }
+ const gchar *data) {
- if (!success) {
- g_free(rc);
- return NULL ;
- }
+ extcap_complex *rc = g_new0(extcap_complex, 1);
+ rc->_val = g_strdup(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;
+ if (element == NULL || element->default_complex == NULL || test == NULL)
+ return FALSE;
- 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 (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;
-}
-
-gchar *extcap_complex_get_string(extcap_complex *comp) {
- return comp->complex_value.string_value;
-}
-
-void extcap_free_tokenized_param(extcap_token_param *v) {
- if (v == NULL)
- return;
-
- if (v->arg != NULL)
- g_free(v->arg);
-
- if (v->value != NULL)
- g_free(v->value);
-
- g_free(v);
-}
-
-void extcap_free_tokenized_sentence(extcap_token_sentence *s) {
- extcap_token_param *tv;
-
- if (s == NULL)
- return;
- if (s->sentence != NULL)
- g_free(s->sentence);
-
- while (s->param_list != NULL ) {
- tv = s->param_list;
- s->param_list = tv->next_token;
+ if (comp->complex_type != EXTCAP_ARG_BOOLEAN && comp->complex_type != EXTCAP_ARG_BOOLFLAG)
+ return FALSE;
- extcap_free_tokenized_param(tv);
- }
- g_free(s);
+ return g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, comp->_val, G_REGEX_CASELESS, (GRegexMatchFlags)0);
}
-void extcap_free_tokenized_sentence_list(extcap_token_sentence *f) {
- extcap_token_sentence *t;
-
- while (f != NULL ) {
- t = f->next_sentence;
- extcap_free_tokenized_sentence(f);
- f = t;
- }
+gchar *extcap_complex_get_string(extcap_complex *comp) {
+ /* Not checking for argument type, to use this method as fallback if only strings are needed */
+ return comp != NULL ? comp->_val : NULL;
}
-extcap_token_sentence *extcap_tokenize_sentence(const gchar *s) {
- extcap_token_param *tv = NULL;
- GRegex * regex = NULL;
- GMatchInfo * match_info = NULL;
- GError * error = NULL;
+static extcap_token_sentence *extcap_tokenize_sentence(const gchar *s) {
+ GRegex *regex = NULL;
+ GMatchInfo *match_info = NULL;
+ GError *error = NULL;
+ gchar *param_value = NULL;
+ guint param_type = EXTCAP_PARAM_UNKNOWN;
- extcap_token_sentence *rs = g_new(extcap_token_sentence, 1);
+ extcap_token_sentence *rs = g_new0(extcap_token_sentence, 1);
rs->sentence = NULL;
- rs->next_sentence = NULL;
- rs->param_list = NULL;
/* Regex for catching just the allowed values for sentences */
- if ( ( regex = g_regex_new ( "^[\\t| ]*(arg|value|interface|extcap|dlt)(?=[\\t| ]+\\{)",
- (GRegexCompileFlags) G_REGEX_CASELESS, (GRegexMatchFlags) 0, NULL ) ) != NULL ) {
- g_regex_match ( regex, s, (GRegexMatchFlags) 0, &match_info );
+ if ((regex = g_regex_new("^[\\t| ]*(arg|value|interface|extcap|dlt|control)(?=[\\t| ]+\\{)",
+ (GRegexCompileFlags) G_REGEX_CASELESS, (GRegexMatchFlags) 0, NULL)) != NULL) {
+ g_regex_match(regex, s, (GRegexMatchFlags) 0, &match_info);
- if ( g_match_info_matches ( match_info ) )
+ if (g_match_info_matches(match_info))
rs->sentence = g_match_info_fetch(match_info, 0);
- g_match_info_free ( match_info );
- g_regex_unref ( regex );
+ g_match_info_free(match_info);
+ g_regex_unref(regex);
}
/* No valid sentence found, exiting here */
- if ( rs->sentence == NULL ) {
- extcap_free_tokenized_sentence(rs);
+ if (rs->sentence == NULL) {
+ g_free(rs);
return NULL;
}
+ rs->param_list = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
+
/* Capture the argument and the value of the list. This will ensure,
* that regex patterns given to {validation=} are parsed correctly,
* as long as }{ does not occur within the pattern */
- regex = g_regex_new ( "\\{([a-zA-Z_-]*?)\\=(.*?)\\}(?=\\{|$|\\s)",
- (GRegexCompileFlags) G_REGEX_CASELESS, (GRegexMatchFlags) 0, NULL );
- if ( regex != NULL ) {
- g_regex_match_full(regex, s, -1, 0, (GRegexMatchFlags) 0, &match_info, &error );
- while(g_match_info_matches(match_info)) {
- gchar * arg = g_match_info_fetch ( match_info, 1 );
-
- if ( arg == NULL )
+ regex = g_regex_new("\\{([a-zA-Z_-]*?)\\=(.*?)\\}(?=\\{|$|\\s)",
+ (GRegexCompileFlags) G_REGEX_CASELESS, (GRegexMatchFlags) 0, NULL);
+ if (regex != NULL) {
+ g_regex_match_full(regex, s, -1, 0, (GRegexMatchFlags) 0, &match_info, &error);
+ while (g_match_info_matches(match_info)) {
+ gchar *arg = g_match_info_fetch(match_info, 1);
+
+ if (arg == NULL)
break;
- tv = g_new(extcap_token_param, 1);
- tv->arg = arg;
- tv->value = g_match_info_fetch ( match_info, 2 );
-
- if (g_ascii_strcasecmp(tv->arg, "number") == 0) {
- tv->param_type = EXTCAP_PARAM_ARGNUM;
- } else if (g_ascii_strcasecmp(tv->arg, "call") == 0) {
- tv->param_type = EXTCAP_PARAM_CALL;
- } else if (g_ascii_strcasecmp(tv->arg, "display") == 0) {
- tv->param_type = EXTCAP_PARAM_DISPLAY;
- } else if (g_ascii_strcasecmp(tv->arg, "type") == 0) {
- tv->param_type = EXTCAP_PARAM_TYPE;
- } else if (g_ascii_strcasecmp(tv->arg, "arg") == 0) {
- tv->param_type = EXTCAP_PARAM_ARG;
- } else if (g_ascii_strcasecmp(tv->arg, "default") == 0) {
- tv->param_type = EXTCAP_PARAM_DEFAULT;
- } else if (g_ascii_strcasecmp(tv->arg, "value") == 0) {
- tv->param_type = EXTCAP_PARAM_VALUE;
- } else if (g_ascii_strcasecmp(tv->arg, "range") == 0) {
- tv->param_type = EXTCAP_PARAM_RANGE;
- } else if (g_ascii_strcasecmp(tv->arg, "tooltip") == 0) {
- tv->param_type = EXTCAP_PARAM_TOOLTIP;
- } else if (g_ascii_strcasecmp(tv->arg, "mustexist") == 0) {
- tv->param_type = EXTCAP_PARAM_FILE_MUSTEXIST;
- } else if (g_ascii_strcasecmp(tv->arg, "fileext") == 0) {
- tv->param_type = EXTCAP_PARAM_FILE_EXTENSION;
- } else if (g_ascii_strcasecmp(tv->arg, "name") == 0) {
- tv->param_type = EXTCAP_PARAM_NAME;
- } else if (g_ascii_strcasecmp(tv->arg, "enabled") == 0) {
- tv->param_type = EXTCAP_PARAM_ENABLED;
- } else if (g_ascii_strcasecmp(tv->arg, "parent") == 0) {
- 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 if (g_ascii_strcasecmp(tv->arg, "version") == 0) {
- tv->param_type = EXTCAP_PARAM_VERSION;
+ param_value = g_match_info_fetch(match_info, 2);
+
+ if (g_ascii_strcasecmp(arg, "number") == 0) {
+ param_type = EXTCAP_PARAM_ARGNUM;
+ } else if (g_ascii_strcasecmp(arg, "call") == 0) {
+ param_type = EXTCAP_PARAM_CALL;
+ } else if (g_ascii_strcasecmp(arg, "display") == 0) {
+ param_type = EXTCAP_PARAM_DISPLAY;
+ } else if (g_ascii_strcasecmp(arg, "type") == 0) {
+ param_type = EXTCAP_PARAM_TYPE;
+ } else if (g_ascii_strcasecmp(arg, "arg") == 0) {
+ param_type = EXTCAP_PARAM_ARG;
+ } else if (g_ascii_strcasecmp(arg, "default") == 0) {
+ param_type = EXTCAP_PARAM_DEFAULT;
+ } else if (g_ascii_strcasecmp(arg, "value") == 0) {
+ param_type = EXTCAP_PARAM_VALUE;
+ } else if (g_ascii_strcasecmp(arg, "range") == 0) {
+ param_type = EXTCAP_PARAM_RANGE;
+ } else if (g_ascii_strcasecmp(arg, "tooltip") == 0) {
+ param_type = EXTCAP_PARAM_TOOLTIP;
+ } else if (g_ascii_strcasecmp(arg, "placeholder") == 0) {
+ param_type = EXTCAP_PARAM_PLACEHOLDER;
+ } else if (g_ascii_strcasecmp(arg, "mustexist") == 0) {
+ param_type = EXTCAP_PARAM_FILE_MUSTEXIST;
+ } else if (g_ascii_strcasecmp(arg, "fileext") == 0) {
+ param_type = EXTCAP_PARAM_FILE_EXTENSION;
+ } else if (g_ascii_strcasecmp(arg, "group") == 0) {
+ param_type = EXTCAP_PARAM_GROUP;
+ } else if (g_ascii_strcasecmp(arg, "name") == 0) {
+ param_type = EXTCAP_PARAM_NAME;
+ } else if (g_ascii_strcasecmp(arg, "enabled") == 0) {
+ 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) {
+ param_type = EXTCAP_PARAM_SAVE;
+ } else if (g_ascii_strcasecmp(arg, "validation") == 0) {
+ param_type = EXTCAP_PARAM_VALIDATION;
+ } else if (g_ascii_strcasecmp(arg, "version") == 0) {
+ param_type = EXTCAP_PARAM_VERSION;
+ } else if (g_ascii_strcasecmp(arg, "help") == 0) {
+ param_type = EXTCAP_PARAM_HELP;
+ } else if (g_ascii_strcasecmp(arg, "control") == 0) {
+ param_type = EXTCAP_PARAM_CONTROL;
+ } else if (g_ascii_strcasecmp(arg, "role") == 0) {
+ param_type = EXTCAP_PARAM_ROLE;
} else {
- tv->param_type = EXTCAP_PARAM_UNKNOWN;
+ param_type = EXTCAP_PARAM_UNKNOWN;
}
- tv->next_token = rs->param_list;
- rs->param_list = tv;
+ g_hash_table_insert(rs->param_list, ENUM_KEY(param_type), param_value);
g_match_info_next(match_info, &error);
+ g_free(arg);
}
g_match_info_free(match_info);
g_regex_unref(regex);
return rs;
}
-extcap_token_sentence *extcap_tokenize_sentences(const gchar *s) {
- extcap_token_sentence *first = NULL, *cur = NULL, *last = NULL;
+static GList *extcap_tokenize_sentences(const gchar *s) {
+ GList *sentences = NULL;
+ extcap_token_sentence *item = NULL;
gchar **list, **list_iter;
list_iter = list = g_strsplit(s, "\n", 0);
-
- while (*list_iter != NULL ) {
- cur = extcap_tokenize_sentence(*list_iter);
-
- if (cur != NULL) {
- if (first == NULL) {
- first = cur;
- last = cur;
- } else {
- last->next_sentence = cur;
- last = cur;
- }
- }
-
+ while (*list_iter != NULL) {
+ item = extcap_tokenize_sentence(*list_iter);
+ if (item)
+ sentences = g_list_append(sentences, item);
list_iter++;
}
g_strfreev(list);
- return first;
-}
-
-extcap_token_param *extcap_find_param_by_type(extcap_token_param *first,
- extcap_param_type t) {
- while (first != NULL ) {
- if (first->param_type == t) {
- return first;
- }
-
- first = first->next_token;
- }
-
- return NULL ;
+ return sentences;
}
-void extcap_free_value(extcap_value *v) {
+static void extcap_free_value(extcap_value *v) {
if (v == NULL)
return;
g_free(v);
}
-extcap_interface *extcap_new_interface(void) {
- extcap_interface *r = g_new(extcap_interface, 1);
-
- r->call = r->display = r->version = NULL;
- r->if_type = EXTCAP_SENTENCE_UNKNOWN;
- r->next_interface = NULL;
-
- return r;
-}
-
-void extcap_free_interface(extcap_interface *i) {
- extcap_interface *next_i = i;
-
- while (i) {
- next_i = i->next_interface;
- if (i->call != NULL)
- g_free(i->call);
-
- if (i->display != NULL)
- g_free(i->display);
-
- g_free(i);
- i = next_i;
- }
-}
-
-extcap_dlt *extcap_new_dlt(void) {
- extcap_dlt *r = g_new(extcap_dlt, 1);
-
- r->number = -1;
- r->name = r->display = NULL;
- r->next_dlt = NULL;
-
- return r;
-}
-
-void extcap_free_dlt(extcap_dlt *d) {
- if (d == NULL)
- return;
-
- g_free(d->name);
- 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);
}
g_free(a->call);
g_free(a->display);
g_free(a->tooltip);
+ g_free(a->placeholder);
g_free(a->fileextension);
g_free(a->regexp);
+ g_free(a->group);
+ g_free(a->device_name);
if (a->range_start != NULL)
extcap_free_complex(a->range_start);
extcap_free_complex(a->default_complex);
g_list_foreach(a->values, (GFunc) extcap_free_valuelist, NULL);
+ g_list_free(a->values);
+ g_free(a);
+}
+
+static void extcap_free_toolbar_value(iface_toolbar_value *v) {
+ if (v == NULL)
+ return;
+
+ g_free(v->value);
+ g_free(v->display);
+ g_free(v);
}
-static void extcap_free_arg_list_cb(gpointer listentry, gpointer data _U_) {
- if (listentry != NULL)
- extcap_free_arg((extcap_arg *) listentry);
+static void extcap_free_toolbar_control(iface_toolbar_control *c) {
+ if (c == NULL)
+ return;
+
+ g_free(c->display);
+ g_free(c->validation);
+ g_free(c->tooltip);
+ g_free(c->placeholder);
+ g_free(c);
}
void extcap_free_arg_list(GList *a) {
- g_list_foreach(a, extcap_free_arg_list_cb, NULL);
- g_list_free(a);
+ g_list_free_full(a, (GDestroyNotify)extcap_free_arg);
}
static gint glist_find_numbered_arg(gconstpointer listelem, gconstpointer needle) {
- if (((const extcap_arg *) listelem)->arg_num == *((const int*) needle))
+ if (((const extcap_arg *) listelem)->arg_num == *((const int *) needle))
return 0;
return 1;
}
-extcap_arg *extcap_parse_arg_sentence(GList * args, extcap_token_sentence *s) {
- extcap_token_param *v = NULL;
+static gint glist_find_numbered_control(gconstpointer listelem, gconstpointer needle) {
+ if (((const iface_toolbar_control *) listelem)->num == *((const int *) needle))
+ return 0;
+ return 1;
+}
+
+static void extcap_free_tokenized_sentence(gpointer s, gpointer user_data _U_) {
+ extcap_token_sentence *t = (extcap_token_sentence *)s;
+
+ if (t == NULL)
+ return;
+
+ g_free(t->sentence);
+ g_hash_table_destroy(t->param_list);
+ g_free(t);
+}
+
+static void extcap_free_tokenized_sentences(GList *sentences) {
+ if (sentences == NULL)
+ return;
+
+ g_list_foreach(sentences, extcap_free_tokenized_sentence, NULL);
+ 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;
+ GList *entry = NULL;
+
extcap_sentence_type sent = EXTCAP_SENTENCE_UNKNOWN;
if (s == NULL)
}
if (sent == EXTCAP_SENTENCE_ARG) {
- target_arg = extcap_new_arg();
+ target_arg = g_new0(extcap_arg, 1);
+ target_arg->arg_type = EXTCAP_ARG_UNKNOWN;
+ target_arg->save = TRUE;
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_ARGNUM))
- == NULL) {
+
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_ARGNUM))) == NULL) {
extcap_free_arg(target_arg);
- return NULL ;
+ return NULL;
}
- if (sscanf(v->value, "%d", &(target_arg->arg_num)) != 1) {
+ if (sscanf(param_value, "%d", &(target_arg->arg_num)) != 1) {
extcap_free_arg(target_arg);
- return NULL ;
+ return NULL;
}
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_CALL))
- == NULL) {
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_CALL))) == NULL) {
extcap_free_arg(target_arg);
- return NULL ;
+ return NULL;
}
- target_arg->call = g_strdup(v->value);
+ target_arg->call = g_strdup(param_value);
/* No value only parameters allowed */
if (strlen(target_arg->call) == 0) {
extcap_free_arg(target_arg);
- return NULL ;
+ return NULL;
}
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_DISPLAY))
- == NULL) {
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DISPLAY))) == NULL) {
extcap_free_arg(target_arg);
- return NULL ;
+ return NULL;
}
- target_arg->display = g_strdup(v->value);
+ target_arg->display = g_strdup(param_value);
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_TOOLTIP))
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_TOOLTIP)))
!= NULL) {
- target_arg->tooltip = g_strdup(v->value);
+ target_arg->tooltip = g_strdup(param_value);
}
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_FILE_MUSTEXIST))
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_PLACEHOLDER)))
!= NULL) {
- target_arg->fileexists = (v->value[0] == 't' || v->value[0] == 'T');
+ target_arg->placeholder = g_strdup(param_value);
}
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_FILE_EXTENSION))
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_FILE_MUSTEXIST)))
!= NULL) {
- target_arg->fileextension = g_strdup(v->value);
+ target_arg->fileexists = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, param_value, G_REGEX_CASELESS, (GRegexMatchFlags)0);
}
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_VALIDATION))
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_FILE_EXTENSION)))
!= NULL) {
- target_arg->regexp = g_strdup(v->value);
+ target_arg->fileextension = g_strdup(param_value);
}
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_REQUIRED))
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_VALIDATION)))
!= NULL) {
- target_arg->is_required = (v->value[0] == 't' || v->value[0] == 'T');
+ target_arg->regexp = g_strdup(param_value);
}
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_TYPE))
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_GROUP)))
+ != NULL) {
+ target_arg->group = g_strdup(param_value);
+ }
+
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_REQUIRED)))
+ != NULL) {
+ target_arg->is_required = 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_TYPE)))
== NULL) {
/* printf("no type in ARG sentence\n"); */
extcap_free_arg(target_arg);
- return NULL ;
+ return NULL;
}
- if (g_ascii_strcasecmp(v->value, "integer") == 0) {
+ if (g_ascii_strcasecmp(param_value, "integer") == 0) {
target_arg->arg_type = EXTCAP_ARG_INTEGER;
- } else if (g_ascii_strcasecmp(v->value, "unsigned") == 0) {
+ } else if (g_ascii_strcasecmp(param_value, "unsigned") == 0) {
target_arg->arg_type = EXTCAP_ARG_UNSIGNED;
- } else if (g_ascii_strcasecmp(v->value, "long") == 0) {
+ } else if (g_ascii_strcasecmp(param_value, "long") == 0) {
target_arg->arg_type = EXTCAP_ARG_LONG;
- } else if (g_ascii_strcasecmp(v->value, "double") == 0) {
+ } else if (g_ascii_strcasecmp(param_value, "double") == 0) {
target_arg->arg_type = EXTCAP_ARG_DOUBLE;
- } else if (g_ascii_strcasecmp(v->value, "boolean") == 0) {
+ } else if (g_ascii_strcasecmp(param_value, "boolean") == 0) {
target_arg->arg_type = EXTCAP_ARG_BOOLEAN;
- } else if (g_ascii_strcasecmp(v->value, "boolflag") == 0) {
+ } else if (g_ascii_strcasecmp(param_value, "boolflag") == 0) {
target_arg->arg_type = EXTCAP_ARG_BOOLFLAG;
- } else if (g_ascii_strcasecmp(v->value, "selector") == 0) {
+ } else if (g_ascii_strcasecmp(param_value, "selector") == 0) {
target_arg->arg_type = EXTCAP_ARG_SELECTOR;
- } else if (g_ascii_strcasecmp(v->value, "radio") == 0) {
+ } else if (g_ascii_strcasecmp(param_value, "radio") == 0) {
target_arg->arg_type = EXTCAP_ARG_RADIO;
- } else if (g_ascii_strcasecmp(v->value, "string") == 0) {
+ } else if (g_ascii_strcasecmp(param_value, "string") == 0) {
target_arg->arg_type = EXTCAP_ARG_STRING;
- } else if (g_ascii_strcasecmp(v->value, "password") == 0) {
+ } else if (g_ascii_strcasecmp(param_value, "password") == 0) {
target_arg->arg_type = EXTCAP_ARG_PASSWORD;
- } else if (g_ascii_strcasecmp(v->value, "fileselect") == 0) {
+ /* default setting is to not save passwords */
+ target_arg->save = FALSE;
+ } else if (g_ascii_strcasecmp(param_value, "fileselect") == 0) {
target_arg->arg_type = EXTCAP_ARG_FILESELECT;
- } else if (g_ascii_strcasecmp(v->value, "multicheck") == 0) {
+ } 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", v->value);
+ printf("invalid type %s in ARG sentence\n", param_value);
extcap_free_arg(target_arg);
- return NULL ;
+ return NULL;
+ }
+
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_SAVE)))
+ != NULL) {
+ target_arg->save = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, param_value, G_REGEX_CASELESS, (GRegexMatchFlags)0);
}
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_RANGE))
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_RELOAD)))
!= NULL) {
- gchar *cp = g_strstr_len(v->value, -1, ",");
+ 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, ",");
if (cp == NULL) {
printf("invalid range, expected value,value got %s\n",
- v->value);
+ param_value);
extcap_free_arg(target_arg);
- return NULL ;
+ return NULL;
}
if ((target_arg->range_start = extcap_parse_complex(
- target_arg->arg_type, v->value)) == NULL) {
+ target_arg->arg_type, param_value)) == NULL) {
printf("invalid range, expected value,value got %s\n",
- v->value);
+ param_value);
extcap_free_arg(target_arg);
- return NULL ;
+ return NULL;
}
if ((target_arg->range_end = extcap_parse_complex(
- target_arg->arg_type, cp + 1)) == NULL) {
+ target_arg->arg_type, cp + 1)) == NULL) {
printf("invalid range, expected value,value got %s\n",
- v->value);
+ param_value);
extcap_free_arg(target_arg);
- return NULL ;
+ return NULL;
}
}
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_DEFAULT))
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(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, param_value)) == NULL) {
+ printf("invalid default, couldn't parse %s\n", param_value);
+ }
}
}
} else if (sent == EXTCAP_SENTENCE_VALUE) {
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_ARG))
- == NULL) {
- printf("no arg in VALUE sentence\n");
- return NULL ;
- }
+ value = extcap_parse_value_sentence(s);
- if (sscanf(v->value, "%d", &tint) != 1) {
- printf("invalid arg in VALUE sentence\n");
- return NULL ;
- }
-
- ;
- 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);
- return NULL ;
+ printf("couldn't find arg %d in list for VALUE sentence\n", value->arg_num);
+ return NULL;
}
- value = g_new(extcap_value, 1);
- value->display = NULL;
- value->call = NULL;
- value->enabled = FALSE;
- value->is_default = FALSE;
- value->arg_num = tint;
- value->parent = NULL;
+ ((extcap_arg *) entry->data)->values = g_list_append(
+ ((extcap_arg *) entry->data)->values, value);
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_VALUE))
- == NULL) {
- /* printf("no value in VALUE sentence\n"); */
- extcap_free_value(value);
- return NULL ;
- }
- value->call = g_strdup(v->value);
+ return NULL;
+ }
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_DISPLAY))
- == NULL) {
- /* printf("no display in VALUE sentence\n"); */
- extcap_free_value(value);
- return NULL ;
- }
- value->display = g_strdup(v->value);
+ return target_arg;
+}
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_PARENT))
- != NULL) {
- value->parent = g_strdup(v->value);
- }
+GList *extcap_parse_args(gchar *output) {
+ GList *result = NULL;
+ GList *walker = NULL;
+ GList *temp = NULL;
- 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');
- }
+ walker = extcap_tokenize_sentences(output);
+ temp = walker;
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_ENABLED))
- != NULL) {
- value->enabled = (v->value[0] == 't' || v->value[0] == 'T');
- }
+ while (walker) {
+ extcap_arg *ra = NULL;
+ extcap_token_sentence *sentence = (extcap_token_sentence *)walker->data;
- ((extcap_arg*) entry->data)->values = g_list_append(
- ((extcap_arg*) entry->data)->values, value);
+ if ((ra = extcap_parse_arg_sentence(result, sentence)) != NULL)
+ result = g_list_append(result, (gpointer) ra);
- return NULL ;
+ walker = g_list_next(walker);
}
- return target_arg;
+ extcap_free_tokenized_sentences(temp);
+
+ return result;
}
-GList * extcap_parse_args(extcap_token_sentence *first_s) {
- GList * args = NULL;
+GList *extcap_parse_values(gchar *output) {
+ GList *result = NULL;
+ GList *walker = NULL;
+ GList *temp = NULL;
- while (first_s) {
- extcap_arg *ra = 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_arg_sentence(args, first_s)) != NULL)
- args = g_list_append(args, (gpointer) ra);
+ if ((ra = extcap_parse_value_sentence(sentence)) != NULL)
+ result = g_list_append(result, (gpointer) ra);
- first_s = first_s->next_sentence;
+ walker = g_list_next(walker);
}
- return args;
+ extcap_free_tokenized_sentences(temp);
+
+ return result;
}
-int extcap_parse_interface_sentence(extcap_token_sentence *s,
- extcap_interface **ri) {
- extcap_token_param *v = NULL;
+static extcap_interface *extcap_parse_interface_sentence(extcap_token_sentence *s) {
extcap_sentence_type sent = EXTCAP_SENTENCE_UNKNOWN;
-
- *ri = NULL;
+ gchar *param_value = NULL;
+ extcap_interface *ri = NULL;
if (s == NULL)
- return -1;
+ return NULL;
if (g_ascii_strcasecmp(s->sentence, "interface") == 0) {
sent = EXTCAP_SENTENCE_INTERFACE;
}
if (sent == EXTCAP_SENTENCE_UNKNOWN)
- return -1;
+ return NULL;
- *ri = extcap_new_interface();
+ ri = g_new0(extcap_interface, 1);
- (*ri)->if_type = sent;
+ ri->if_type = sent;
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_VALUE))
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_VALUE)))
== NULL && sent == EXTCAP_SENTENCE_INTERFACE) {
printf("No value in INTERFACE sentence\n");
- extcap_free_interface(*ri);
- return -1;
+ g_free(ri);
+ return NULL;
}
- if ( v != NULL )
- (*ri)->call = g_strdup(v->value);
+ ri->call = g_strdup(param_value);
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_DISPLAY))
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DISPLAY)))
== NULL && sent == EXTCAP_SENTENCE_INTERFACE) {
printf("No display in INTERFACE sentence\n");
- extcap_free_interface(*ri);
- return -1;
+ g_free(ri->call);
+ g_free(ri);
+ return NULL;
}
- if ( v != NULL )
- (*ri)->display = g_strdup(v->value);
+ ri->display = g_strdup(param_value);
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_VERSION))
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_VERSION)))
!= NULL) {
- (*ri)->version = g_strdup(v->value);
+ ri->version = g_strdup(param_value);
}
- return 1;
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_HELP)))
+ != NULL) {
+ ri->help = g_strdup(param_value);
+ }
+
+ return ri;
}
-int extcap_parse_interfaces(extcap_token_sentence *first_s,
- extcap_interface **first_int) {
- extcap_interface *first_i = NULL, *last_i = NULL;
+static iface_toolbar_control *extcap_parse_control_sentence(GList *control_items, extcap_token_sentence *s)
+{
+ extcap_sentence_type sent = EXTCAP_SENTENCE_UNKNOWN;
+ gchar *param_value = NULL;
+ iface_toolbar_control *control = NULL;
+ iface_toolbar_value *value = NULL;
+ GList *entry = NULL;
+ guint32 num = 0;
- while (first_s) {
- extcap_interface *ri;
+ if (s == NULL)
+ return NULL;
- if (extcap_parse_interface_sentence(first_s, &ri) >= 0 && ri != NULL) {
- if (first_i == NULL) {
- first_i = last_i = ri;
+ if (g_ascii_strcasecmp(s->sentence, "control") == 0) {
+ sent = EXTCAP_SENTENCE_CONTROL;
+ } else if (g_ascii_strcasecmp(s->sentence, "value") == 0) {
+ sent = EXTCAP_SENTENCE_VALUE;
+ }
+
+ if (sent == EXTCAP_SENTENCE_UNKNOWN)
+ return NULL;
+
+ if (sent == EXTCAP_SENTENCE_CONTROL) {
+ control = g_new0(iface_toolbar_control, 1);
+ control->ctrl_type = INTERFACE_TYPE_UNKNOWN;
+
+ param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_ARGNUM));
+ if (param_value == NULL) {
+ extcap_free_toolbar_control(control);
+ return NULL;
+ }
+
+ if (!ws_strtou32(param_value, NULL, &num)) {
+ extcap_free_toolbar_control(control);
+ return NULL;
+ }
+ control->num = (int)num;
+
+ param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DISPLAY));
+ if (param_value == NULL) {
+ extcap_free_toolbar_control(control);
+ return NULL;
+ }
+ control->display = g_strdup(param_value);
+
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_VALIDATION)))
+ != NULL) {
+ control->validation = g_strdup(param_value);
+ }
+
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_REQUIRED)))
+ != NULL) {
+ control->is_required = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, param_value, G_REGEX_CASELESS, (GRegexMatchFlags)0);
+ }
+
+ param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_TOOLTIP));
+ control->tooltip = g_strdup(param_value);
+
+ param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_PLACEHOLDER));
+ control->placeholder = g_strdup(param_value);
+
+ param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_TYPE));
+ if (param_value == NULL) {
+ extcap_free_toolbar_control(control);
+ return NULL;
+ }
+
+ extcap_arg_type arg_type = EXTCAP_ARG_UNKNOWN;
+ if (g_ascii_strcasecmp(param_value, "boolean") == 0) {
+ control->ctrl_type = INTERFACE_TYPE_BOOLEAN;
+ arg_type = EXTCAP_ARG_BOOLEAN;
+ } else if (g_ascii_strcasecmp(param_value, "button") == 0) {
+ control->ctrl_type = INTERFACE_TYPE_BUTTON;
+ } else if (g_ascii_strcasecmp(param_value, "selector") == 0) {
+ control->ctrl_type = INTERFACE_TYPE_SELECTOR;
+ } else if (g_ascii_strcasecmp(param_value, "string") == 0) {
+ control->ctrl_type = INTERFACE_TYPE_STRING;
+ arg_type = EXTCAP_ARG_STRING;
+ } else {
+ printf("invalid type %s in CONTROL sentence\n", param_value);
+ extcap_free_toolbar_control(control);
+ return NULL;
+ }
+
+ param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_ROLE));
+ if (param_value != NULL) {
+ if (g_ascii_strcasecmp(param_value, "control") == 0) {
+ control->ctrl_role = INTERFACE_ROLE_CONTROL;
+ } else if (g_ascii_strcasecmp(param_value, "help") == 0) {
+ control->ctrl_role = INTERFACE_ROLE_HELP;
+ } else if (g_ascii_strcasecmp(param_value, "logger") == 0) {
+ control->ctrl_role = INTERFACE_ROLE_LOGGER;
+ } else if (g_ascii_strcasecmp(param_value, "restore") == 0) {
+ control->ctrl_role = INTERFACE_ROLE_RESTORE;
} else {
- last_i->next_interface = ri;
- last_i = ri;
+ printf("invalid role %s in CONTROL sentence\n", param_value);
+ control->ctrl_role = INTERFACE_ROLE_UNKNOWN;
+ }
+ } else {
+ /* Default role */
+ control->ctrl_role = INTERFACE_ROLE_CONTROL;
+ }
+
+ param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DEFAULT));
+ if (param_value != NULL) {
+ if (arg_type != EXTCAP_ARG_UNKNOWN) {
+ extcap_complex *complex = extcap_parse_complex(arg_type, param_value);
+ if (complex != NULL) {
+ if (arg_type == EXTCAP_ARG_BOOLEAN) {
+ control->default_value.boolean = extcap_complex_get_bool(complex);
+ } else if (arg_type == EXTCAP_ARG_STRING) {
+ control->default_value.string = g_strdup(complex->_val);
+ }
+ extcap_free_complex(complex);
+ } else {
+ printf("invalid default, couldn't parse %s\n", param_value);
+ }
}
}
- first_s = first_s->next_sentence;
+ } else if (sent == EXTCAP_SENTENCE_VALUE) {
+ param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_CONTROL));
+ if (param_value == NULL) {
+ printf("no control in VALUE sentence\n");
+ return NULL;
+ }
+
+ if (!ws_strtou32(param_value, NULL, &num)) {
+ extcap_free_toolbar_control(control);
+ return NULL;
+ }
+
+ entry = g_list_find_custom(control_items, &num, glist_find_numbered_control);
+ if (entry == NULL) {
+ printf("couldn't find control %u in list for VALUE sentence\n", num);
+ return NULL;
+ }
+
+ value = g_new0(iface_toolbar_value, 1);
+ value->num = (int)num;
+
+ param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_VALUE));
+ if (param_value == NULL) {
+ extcap_free_toolbar_value(value);
+ return NULL;
+ }
+ value->value = g_strdup(param_value);
+
+ param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DISPLAY));
+ if (param_value == NULL) {
+ extcap_free_toolbar_value(value);
+ return NULL;
+ }
+ value->display = g_strdup(param_value);
+
+ param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DEFAULT));
+ if (param_value != NULL) {
+ value->is_default = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, param_value, G_REGEX_CASELESS, (GRegexMatchFlags)0);
+ }
+
+ control = (iface_toolbar_control *)entry->data;
+ control->values = g_list_append(control->values, value);
+
+ return NULL;
}
- *first_int = first_i;
+ return control;
+}
+
+GList *extcap_parse_interfaces(gchar *output, GList **control_items) {
+
+ GList *result = NULL;
+ GList *tokens = NULL;
+ GList *walker = extcap_tokenize_sentences(output);
+ tokens = walker;
+
+ while (walker) {
+ extcap_interface *ri = NULL;
+ iface_toolbar_control *ti = NULL;
+ extcap_token_sentence *if_sentence = (extcap_token_sentence *) walker->data;
+
+ if (if_sentence) {
+ if ((g_ascii_strcasecmp(if_sentence->sentence, "interface") == 0) ||
+ (g_ascii_strcasecmp(if_sentence->sentence, "extcap") == 0))
+ {
+ if ((ri = extcap_parse_interface_sentence(if_sentence))) {
+ result = g_list_append(result, ri);
+ }
+ } else if (control_items &&
+ ((g_ascii_strcasecmp(if_sentence->sentence, "control") == 0) ||
+ (g_ascii_strcasecmp(if_sentence->sentence, "value") == 0)))
+ {
+ if ((ti = extcap_parse_control_sentence(*control_items, if_sentence))) {
+ *control_items = g_list_append(*control_items, ti);
+ }
+ }
+ }
- return 1;
+ walker = g_list_next(walker);
+ }
+
+ extcap_free_tokenized_sentences(tokens);
+
+ return result;
}
-int extcap_parse_dlt_sentence(extcap_token_sentence *s, extcap_dlt **rd) {
- extcap_token_param *v = NULL;
+/* Parse a tokenized set of sentences and validate, looking for DLT definitions */
+static extcap_dlt *extcap_parse_dlt_sentence(extcap_token_sentence *s) {
+ gchar *param_value = NULL;
extcap_sentence_type sent = EXTCAP_SENTENCE_UNKNOWN;
-
- *rd = NULL;
+ extcap_dlt *result = NULL;
if (s == NULL)
- return -1;
+ return result;
if (g_ascii_strcasecmp(s->sentence, "dlt") == 0) {
sent = EXTCAP_SENTENCE_DLT;
}
if (sent == EXTCAP_SENTENCE_UNKNOWN)
- return -1;
+ return result;
+
+ result = g_new0(extcap_dlt, 1);
- *rd = extcap_new_dlt();
+ result->number = -1;
+ result->name = NULL;
+ result->display = NULL;
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_ARGNUM))
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_ARGNUM)))
== NULL) {
printf("No number in DLT sentence\n");
- extcap_free_dlt(*rd);
- return -1;
+ g_free(result);
+ return NULL;
}
- if (sscanf(v->value, "%d", &((*rd)->number)) != 1) {
+ if (sscanf(param_value, "%d", &(result->number)) != 1) {
printf("Invalid number in DLT sentence\n");
- extcap_free_dlt(*rd);
- return -1;
+ g_free(result);
+ return NULL;
}
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_NAME))
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_NAME)))
== NULL) {
printf("No name in DLT sentence\n");
- extcap_free_dlt(*rd);
- return -1;
+ g_free(result);
+ return NULL;
}
- (*rd)->name = g_strdup(v->value);
+ result->name = g_strdup(param_value);
- if ((v = extcap_find_param_by_type(s->param_list, EXTCAP_PARAM_DISPLAY))
+ if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DISPLAY)))
== NULL) {
printf("No display in DLT sentence\n");
- extcap_free_dlt(*rd);
- return -1;
+ g_free(result->name);
+ g_free(result);
+ return NULL;
}
- (*rd)->display = g_strdup(v->value);
+ result->display = g_strdup(param_value);
- return 1;
+ return result;
}
-int extcap_parse_dlts(extcap_token_sentence *first_s, extcap_dlt **first_dlt) {
- extcap_dlt *first_d = NULL, *last_d = NULL;
+GList *extcap_parse_dlts(gchar *output) {
- while (first_s) {
- extcap_dlt *rd;
+ GList *walker = NULL;
+ GList *temp = NULL;
+ GList *result = NULL;
- if (extcap_parse_dlt_sentence(first_s, &rd) >= 0 && rd != NULL) {
- if (first_d == NULL) {
- first_d = last_d = rd;
- } else {
- last_d->next_dlt = rd;
- last_d = rd;
- }
- }
+ walker = extcap_tokenize_sentences(output);
+
+ temp = walker;
- first_s = first_s->next_sentence;
+ while (walker) {
+ extcap_dlt *data = NULL;
+
+ if ((data = extcap_parse_dlt_sentence((extcap_token_sentence *)walker->data)) != NULL)
+ result = g_list_append(result, data);
+
+ walker = g_list_next(walker);
}
- *first_dlt = first_d;
+ extcap_free_tokenized_sentences(temp);
- return 1;
+ return result;
}
/*