2014-02-25 13:05:11 +00:00
|
|
|
/* extcap_parser.c
|
|
|
|
*
|
|
|
|
* Routines for extcap external capture
|
|
|
|
* Copyright 2013, Mike Ryan <mikeryan@lacklustre.net>
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-08-22 21:13:05 +00:00
|
|
|
#include <config.h>
|
2014-02-25 13:05:11 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
#include "extcap.h"
|
2014-02-25 13:05:11 +00:00
|
|
|
#include "extcap_parser.h"
|
|
|
|
|
|
|
|
void extcap_printf_complex(extcap_complex *comp) {
|
2014-10-06 18:03:47 +00:00
|
|
|
gchar *ret = extcap_get_complex_as_string(comp);
|
|
|
|
printf("%s", ret);
|
|
|
|
g_free(ret);
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar *extcap_get_complex_as_string(extcap_complex *comp) {
|
2016-01-28 09:41:38 +00:00
|
|
|
return (comp ? g_strdup(comp->_val) : NULL);
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extcap_complex *extcap_parse_complex(extcap_arg_type complex_type,
|
2016-12-07 18:59:53 +00:00
|
|
|
const gchar *data) {
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
extcap_complex *rc = g_new0(extcap_complex, 1);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2016-04-06 14:34:34 +00:00
|
|
|
rc->_val = g_strdup(data);
|
2014-10-06 18:03:47 +00:00
|
|
|
rc->complex_type = complex_type;
|
|
|
|
|
|
|
|
return rc;
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean extcap_compare_is_default(extcap_arg *element, extcap_complex *test) {
|
2016-12-07 18:59:53 +00:00
|
|
|
if (element == NULL || element->default_complex == NULL || test == NULL)
|
2016-01-28 09:41:38 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
if (g_strcmp0(element->default_complex->_val, test->_val) == 0)
|
2016-01-28 09:41:38 +00:00
|
|
|
return TRUE;
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
return FALSE;
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void extcap_free_complex(extcap_complex *comp) {
|
2016-12-07 18:59:53 +00:00
|
|
|
if (comp)
|
2016-01-28 09:41:38 +00:00
|
|
|
g_free(comp->_val);
|
2014-10-06 18:03:47 +00:00
|
|
|
g_free(comp);
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
gint extcap_complex_get_int(extcap_complex *comp) {
|
2016-12-07 18:59:53 +00:00
|
|
|
if (comp == NULL || comp->_val == NULL || comp->complex_type != EXTCAP_ARG_INTEGER)
|
2016-01-28 09:41:38 +00:00
|
|
|
return (gint)0;
|
|
|
|
|
|
|
|
return (gint) g_ascii_strtoll(comp->_val, NULL, 10);
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
guint extcap_complex_get_uint(extcap_complex *comp) {
|
2016-12-07 18:59:53 +00:00
|
|
|
if (comp == NULL || comp->_val == NULL || comp->complex_type != EXTCAP_ARG_UNSIGNED)
|
2016-01-28 09:41:38 +00:00
|
|
|
return (guint)0;
|
|
|
|
return (guint) g_ascii_strtoull(comp->_val, NULL, 10);
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
gint64 extcap_complex_get_long(extcap_complex *comp) {
|
2016-12-07 18:59:53 +00:00
|
|
|
if (comp == NULL || comp->_val == NULL || comp->complex_type != EXTCAP_ARG_LONG)
|
2016-01-28 09:41:38 +00:00
|
|
|
return (gint64)0;
|
2016-12-07 18:59:53 +00:00
|
|
|
return g_ascii_strtoll(comp->_val, NULL, 10);
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
gdouble extcap_complex_get_double(extcap_complex *comp) {
|
2016-12-07 18:59:53 +00:00
|
|
|
if (comp == NULL || comp->_val == NULL || comp->complex_type != EXTCAP_ARG_DOUBLE)
|
2016-01-28 09:41:38 +00:00
|
|
|
return (gdouble)0;
|
2016-12-07 18:59:53 +00:00
|
|
|
return g_strtod(comp->_val, NULL);
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean extcap_complex_get_bool(extcap_complex *comp) {
|
2016-12-07 18:59:53 +00:00
|
|
|
if (comp == NULL || comp->_val == NULL)
|
2014-10-06 18:03:47 +00:00
|
|
|
return FALSE;
|
2016-01-28 09:41:38 +00:00
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
if (comp->complex_type != EXTCAP_ARG_BOOLEAN && comp->complex_type != EXTCAP_ARG_BOOLFLAG)
|
2016-01-28 09:41:38 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
return g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, comp->_val, G_REGEX_CASELESS, (GRegexMatchFlags)0);
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar *extcap_complex_get_string(extcap_complex *comp) {
|
2016-01-28 09:41:38 +00:00
|
|
|
/* Not checking for argument type, to use this method as fallback if only strings are needed */
|
|
|
|
return comp != NULL ? comp->_val : NULL;
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
static extcap_token_sentence *extcap_tokenize_sentence(const gchar *s) {
|
2016-12-07 18:59:53 +00:00
|
|
|
GRegex *regex = NULL;
|
|
|
|
GMatchInfo *match_info = NULL;
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar *param_value = NULL;
|
2016-09-05 11:29:23 +00:00
|
|
|
guint param_type = EXTCAP_PARAM_UNKNOWN;
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
extcap_token_sentence *rs = g_new0(extcap_token_sentence, 1);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
rs->sentence = NULL;
|
|
|
|
|
2016-01-04 13:19:55 +00:00
|
|
|
/* Regex for catching just the allowed values for sentences */
|
2016-12-07 18:59:53 +00:00
|
|
|
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);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
if (g_match_info_matches(match_info))
|
2016-01-04 13:19:55 +00:00
|
|
|
rs->sentence = g_match_info_fetch(match_info, 0);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
g_match_info_free(match_info);
|
|
|
|
g_regex_unref(regex);
|
2016-01-04 13:19:55 +00:00
|
|
|
}
|
|
|
|
/* No valid sentence found, exiting here */
|
2016-12-07 18:59:53 +00:00
|
|
|
if (rs->sentence == NULL) {
|
2016-09-05 11:29:23 +00:00
|
|
|
g_free(rs);
|
2016-01-04 13:19:55 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
2016-09-08 12:26:58 +00:00
|
|
|
rs->param_list = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
|
|
|
|
|
2016-01-04 13:19:55 +00:00
|
|
|
/* 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 */
|
2016-12-07 18:59:53 +00:00
|
|
|
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)
|
2016-01-04 13:19:55 +00:00
|
|
|
break;
|
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
param_value = g_match_info_fetch(match_info, 2);
|
2016-09-05 11:29:23 +00:00
|
|
|
|
|
|
|
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;
|
2015-12-07 12:30:26 +00:00
|
|
|
} else if (g_ascii_strcasecmp(arg, "placeholder") == 0) {
|
|
|
|
param_type = EXTCAP_PARAM_PLACEHOLDER;
|
2016-09-05 11:29:23 +00:00
|
|
|
} 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, "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, "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;
|
2016-09-05 05:54:47 +00:00
|
|
|
} else if (g_ascii_strcasecmp(arg, "help") == 0) {
|
|
|
|
param_type = EXTCAP_PARAM_HELP;
|
2016-01-04 13:19:55 +00:00
|
|
|
} else {
|
2016-09-05 11:29:23 +00:00
|
|
|
param_type = EXTCAP_PARAM_UNKNOWN;
|
2015-12-29 14:35:43 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
g_hash_table_insert(rs->param_list, ENUM_KEY(param_type), param_value);
|
2015-12-29 14:35:43 +00:00
|
|
|
|
2016-01-04 13:19:55 +00:00
|
|
|
g_match_info_next(match_info, &error);
|
2016-09-08 12:26:58 +00:00
|
|
|
g_free(arg);
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2016-01-04 13:19:55 +00:00
|
|
|
g_match_info_free(match_info);
|
|
|
|
g_regex_unref(regex);
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rs;
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
static GList *extcap_tokenize_sentences(const gchar *s) {
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
GList *sentences = NULL;
|
2016-09-05 11:29:23 +00:00
|
|
|
extcap_token_sentence *item = NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
gchar **list, **list_iter;
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
list_iter = list = g_strsplit(s, "\n", 0);
|
2016-12-07 18:59:53 +00:00
|
|
|
while (*list_iter != NULL) {
|
2016-09-05 11:29:23 +00:00
|
|
|
item = extcap_tokenize_sentence(*list_iter);
|
|
|
|
if (item)
|
|
|
|
sentences = g_list_append(sentences, item);
|
2014-10-06 18:03:47 +00:00
|
|
|
list_iter++;
|
|
|
|
}
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
g_strfreev(list);
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
return sentences;
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
static void extcap_free_value(extcap_value *v) {
|
2014-10-06 18:03:47 +00:00
|
|
|
if (v == NULL)
|
|
|
|
return;
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-01-12 12:45:20 +00:00
|
|
|
g_free(v->call);
|
|
|
|
g_free(v->display);
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
g_free(v);
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void extcap_free_valuelist(gpointer data, gpointer user_data _U_) {
|
2014-10-06 18:03:47 +00:00
|
|
|
extcap_free_value((extcap_value *) data);
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void extcap_free_arg(extcap_arg *a) {
|
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (a == NULL)
|
|
|
|
return;
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-01-12 12:45:20 +00:00
|
|
|
g_free(a->call);
|
|
|
|
g_free(a->display);
|
|
|
|
g_free(a->tooltip);
|
2015-12-07 12:30:26 +00:00
|
|
|
g_free(a->placeholder);
|
2016-01-12 12:45:20 +00:00
|
|
|
g_free(a->fileextension);
|
|
|
|
g_free(a->regexp);
|
2015-12-29 06:57:36 +00:00
|
|
|
g_free(a->device_name);
|
2015-12-29 14:35:43 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (a->range_start != NULL)
|
|
|
|
extcap_free_complex(a->range_start);
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (a->range_end != NULL)
|
|
|
|
extcap_free_complex(a->range_end);
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (a->default_complex != NULL)
|
|
|
|
extcap_free_complex(a->default_complex);
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
g_list_foreach(a->values, (GFunc) extcap_free_valuelist, NULL);
|
2016-09-08 12:26:58 +00:00
|
|
|
g_list_free(a->values);
|
|
|
|
g_free(a);
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void extcap_free_arg_list(GList *a) {
|
2016-09-08 12:26:58 +00:00
|
|
|
g_list_foreach(a, (GFunc)extcap_free_arg, NULL);
|
2014-10-06 18:03:47 +00:00
|
|
|
g_list_free(a);
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint glist_find_numbered_arg(gconstpointer listelem, gconstpointer needle) {
|
2016-12-07 18:59:53 +00:00
|
|
|
if (((const extcap_arg *) listelem)->arg_num == *((const int *) needle))
|
2014-10-06 18:03:47 +00:00
|
|
|
return 0;
|
|
|
|
return 1;
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
static void extcap_free_tokenized_sentence(gpointer s, gpointer user_data _U_) {
|
2016-09-08 12:26:58 +00:00
|
|
|
extcap_token_sentence *t = (extcap_token_sentence *)s;
|
2016-09-05 11:29:23 +00:00
|
|
|
|
2016-09-08 12:26:58 +00:00
|
|
|
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)
|
2016-09-05 11:29:23 +00:00
|
|
|
return;
|
|
|
|
|
2016-09-08 12:26:58 +00:00
|
|
|
g_list_foreach(sentences, extcap_free_tokenized_sentence, NULL);
|
|
|
|
g_list_free(sentences);
|
2016-09-05 11:29:23 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
static extcap_arg *extcap_parse_arg_sentence(GList *args, extcap_token_sentence *s) {
|
|
|
|
gchar *param_value = NULL;
|
2016-09-05 11:29:23 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
extcap_arg *target_arg = NULL;
|
|
|
|
extcap_value *value = NULL;
|
2016-12-07 18:59:53 +00:00
|
|
|
GList *entry = NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
int tint;
|
|
|
|
extcap_sentence_type sent = EXTCAP_SENTENCE_UNKNOWN;
|
|
|
|
|
|
|
|
if (s == NULL)
|
|
|
|
return target_arg;
|
|
|
|
|
|
|
|
if (g_ascii_strcasecmp(s->sentence, "arg") == 0) {
|
|
|
|
sent = EXTCAP_SENTENCE_ARG;
|
|
|
|
/* printf("ARG sentence\n"); */
|
|
|
|
} else if (g_ascii_strcasecmp(s->sentence, "value") == 0) {
|
|
|
|
sent = EXTCAP_SENTENCE_VALUE;
|
|
|
|
/* printf("VALUE sentence\n"); */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sent == EXTCAP_SENTENCE_ARG) {
|
2016-01-28 09:41:38 +00:00
|
|
|
target_arg = g_new0(extcap_arg, 1);
|
|
|
|
target_arg->arg_type = EXTCAP_ARG_UNKNOWN;
|
2015-12-29 06:57:36 +00:00
|
|
|
target_arg->save = TRUE;
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
|
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_ARGNUM))) == NULL) {
|
2014-10-06 18:03:47 +00:00
|
|
|
extcap_free_arg(target_arg);
|
2016-12-07 18:59:53 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if (sscanf(param_value, "%d", &(target_arg->arg_num)) != 1) {
|
2014-10-06 18:03:47 +00:00
|
|
|
extcap_free_arg(target_arg);
|
2016-12-07 18:59:53 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_CALL))) == NULL) {
|
2014-10-06 18:03:47 +00:00
|
|
|
extcap_free_arg(target_arg);
|
2016-12-07 18:59:53 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2016-09-05 11:29:23 +00:00
|
|
|
target_arg->call = g_strdup(param_value);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
/* No value only parameters allowed */
|
|
|
|
if (strlen(target_arg->call) == 0) {
|
|
|
|
extcap_free_arg(target_arg);
|
2016-12-07 18:59:53 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DISPLAY))) == NULL) {
|
2014-10-06 18:03:47 +00:00
|
|
|
extcap_free_arg(target_arg);
|
2016-12-07 18:59:53 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2016-09-05 11:29:23 +00:00
|
|
|
target_arg->display = g_strdup(param_value);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_TOOLTIP)))
|
2014-10-06 18:03:47 +00:00
|
|
|
!= NULL) {
|
2016-09-05 11:29:23 +00:00
|
|
|
target_arg->tooltip = g_strdup(param_value);
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 12:30:26 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_PLACEHOLDER)))
|
|
|
|
!= NULL) {
|
|
|
|
target_arg->placeholder = g_strdup(param_value);
|
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_FILE_MUSTEXIST)))
|
2014-10-06 18:03:47 +00:00
|
|
|
!= NULL) {
|
2016-12-07 18:59:53 +00:00
|
|
|
target_arg->fileexists = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, param_value, G_REGEX_CASELESS, (GRegexMatchFlags)0);
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_FILE_EXTENSION)))
|
2015-12-29 13:57:53 +00:00
|
|
|
!= NULL) {
|
2016-09-05 11:29:23 +00:00
|
|
|
target_arg->fileextension = g_strdup(param_value);
|
2015-12-29 13:57:53 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_VALIDATION)))
|
2015-12-29 14:35:43 +00:00
|
|
|
!= NULL) {
|
2016-09-05 11:29:23 +00:00
|
|
|
target_arg->regexp = g_strdup(param_value);
|
2015-12-29 14:35:43 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_REQUIRED)))
|
2015-12-29 13:50:55 +00:00
|
|
|
!= NULL) {
|
2016-12-07 18:59:53 +00:00
|
|
|
target_arg->is_required = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, param_value, G_REGEX_CASELESS, (GRegexMatchFlags)0);
|
2015-12-29 13:50:55 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_TYPE)))
|
2014-10-06 18:03:47 +00:00
|
|
|
== NULL) {
|
|
|
|
/* printf("no type in ARG sentence\n"); */
|
|
|
|
extcap_free_arg(target_arg);
|
2016-12-07 18:59:53 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if (g_ascii_strcasecmp(param_value, "integer") == 0) {
|
2014-10-06 18:03:47 +00:00
|
|
|
target_arg->arg_type = EXTCAP_ARG_INTEGER;
|
2016-09-05 11:29:23 +00:00
|
|
|
} else if (g_ascii_strcasecmp(param_value, "unsigned") == 0) {
|
2014-10-06 18:03:47 +00:00
|
|
|
target_arg->arg_type = EXTCAP_ARG_UNSIGNED;
|
2016-09-05 11:29:23 +00:00
|
|
|
} else if (g_ascii_strcasecmp(param_value, "long") == 0) {
|
2014-10-06 18:03:47 +00:00
|
|
|
target_arg->arg_type = EXTCAP_ARG_LONG;
|
2016-09-05 11:29:23 +00:00
|
|
|
} else if (g_ascii_strcasecmp(param_value, "double") == 0) {
|
2014-10-06 18:03:47 +00:00
|
|
|
target_arg->arg_type = EXTCAP_ARG_DOUBLE;
|
2016-09-05 11:29:23 +00:00
|
|
|
} else if (g_ascii_strcasecmp(param_value, "boolean") == 0) {
|
2014-10-06 18:03:47 +00:00
|
|
|
target_arg->arg_type = EXTCAP_ARG_BOOLEAN;
|
2016-09-05 11:29:23 +00:00
|
|
|
} else if (g_ascii_strcasecmp(param_value, "boolflag") == 0) {
|
2014-10-06 18:03:47 +00:00
|
|
|
target_arg->arg_type = EXTCAP_ARG_BOOLFLAG;
|
2016-09-05 11:29:23 +00:00
|
|
|
} else if (g_ascii_strcasecmp(param_value, "selector") == 0) {
|
2014-10-06 18:03:47 +00:00
|
|
|
target_arg->arg_type = EXTCAP_ARG_SELECTOR;
|
2016-09-05 11:29:23 +00:00
|
|
|
} else if (g_ascii_strcasecmp(param_value, "radio") == 0) {
|
2014-10-06 18:03:47 +00:00
|
|
|
target_arg->arg_type = EXTCAP_ARG_RADIO;
|
2016-09-05 11:29:23 +00:00
|
|
|
} else if (g_ascii_strcasecmp(param_value, "string") == 0) {
|
2014-10-06 18:03:47 +00:00
|
|
|
target_arg->arg_type = EXTCAP_ARG_STRING;
|
2016-09-05 11:29:23 +00:00
|
|
|
} else if (g_ascii_strcasecmp(param_value, "password") == 0) {
|
2016-01-18 11:01:14 +00:00
|
|
|
target_arg->arg_type = EXTCAP_ARG_PASSWORD;
|
2016-01-28 09:41:38 +00:00
|
|
|
/* default setting is to not save passwords */
|
2015-12-29 06:57:36 +00:00
|
|
|
target_arg->save = FALSE;
|
2016-09-05 11:29:23 +00:00
|
|
|
} else if (g_ascii_strcasecmp(param_value, "fileselect") == 0) {
|
2014-10-06 18:03:47 +00:00
|
|
|
target_arg->arg_type = EXTCAP_ARG_FILESELECT;
|
2016-09-05 11:29:23 +00:00
|
|
|
} else if (g_ascii_strcasecmp(param_value, "multicheck") == 0) {
|
2014-10-06 18:03:47 +00:00
|
|
|
target_arg->arg_type = EXTCAP_ARG_MULTICHECK;
|
2016-11-09 12:56:12 +00:00
|
|
|
} else if (g_ascii_strcasecmp(param_value, "timestamp") == 0) {
|
|
|
|
target_arg->arg_type = EXTCAP_ARG_TIMESTAMP;
|
2014-10-06 18:03:47 +00:00
|
|
|
} else {
|
2016-09-05 11:29:23 +00:00
|
|
|
printf("invalid type %s in ARG sentence\n", param_value);
|
2014-10-06 18:03:47 +00:00
|
|
|
extcap_free_arg(target_arg);
|
2016-12-07 18:59:53 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_SAVE)))
|
2016-01-28 09:41:38 +00:00
|
|
|
!= NULL) {
|
2016-12-07 18:59:53 +00:00
|
|
|
target_arg->save = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, param_value, G_REGEX_CASELESS, (GRegexMatchFlags)0);
|
2016-01-28 09:41:38 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_RANGE)))
|
2014-10-06 18:03:47 +00:00
|
|
|
!= NULL) {
|
2016-09-05 11:29:23 +00:00
|
|
|
gchar *cp = g_strstr_len(param_value, -1, ",");
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
if (cp == NULL) {
|
|
|
|
printf("invalid range, expected value,value got %s\n",
|
2016-12-07 18:59:53 +00:00
|
|
|
param_value);
|
2014-10-06 18:03:47 +00:00
|
|
|
extcap_free_arg(target_arg);
|
2016-12-07 18:59:53 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((target_arg->range_start = extcap_parse_complex(
|
2016-12-07 18:59:53 +00:00
|
|
|
target_arg->arg_type, param_value)) == NULL) {
|
2014-10-06 18:03:47 +00:00
|
|
|
printf("invalid range, expected value,value got %s\n",
|
2016-12-07 18:59:53 +00:00
|
|
|
param_value);
|
2014-10-06 18:03:47 +00:00
|
|
|
extcap_free_arg(target_arg);
|
2016-12-07 18:59:53 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((target_arg->range_end = extcap_parse_complex(
|
2016-12-07 18:59:53 +00:00
|
|
|
target_arg->arg_type, cp + 1)) == NULL) {
|
2014-10-06 18:03:47 +00:00
|
|
|
printf("invalid range, expected value,value got %s\n",
|
2016-12-07 18:59:53 +00:00
|
|
|
param_value);
|
2014-10-06 18:03:47 +00:00
|
|
|
extcap_free_arg(target_arg);
|
2016-12-07 18:59:53 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DEFAULT)))
|
2014-10-06 18:03:47 +00:00
|
|
|
!= NULL) {
|
2016-12-07 18:59:53 +00:00
|
|
|
if (target_arg->arg_type != EXTCAP_ARG_MULTICHECK && target_arg->arg_type != EXTCAP_ARG_SELECTOR)
|
2016-01-28 09:41:38 +00:00
|
|
|
{
|
|
|
|
if ((target_arg->default_complex = extcap_parse_complex(
|
2016-12-07 18:59:53 +00:00
|
|
|
target_arg->arg_type, param_value)) == NULL) {
|
2016-09-05 11:29:23 +00:00
|
|
|
printf("invalid default, couldn't parse %s\n", param_value);
|
2016-01-28 09:41:38 +00:00
|
|
|
}
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (sent == EXTCAP_SENTENCE_VALUE) {
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_ARG)))
|
2014-10-06 18:03:47 +00:00
|
|
|
== NULL) {
|
|
|
|
printf("no arg in VALUE sentence\n");
|
2016-12-07 18:59:53 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if (sscanf(param_value, "%d", &tint) != 1) {
|
2014-10-06 18:03:47 +00:00
|
|
|
printf("invalid arg in VALUE sentence\n");
|
2016-12-07 18:59:53 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((entry = g_list_find_custom(args, &tint, glist_find_numbered_arg))
|
|
|
|
== NULL) {
|
|
|
|
printf("couldn't find arg %d in list for VALUE sentence\n", tint);
|
2016-12-07 18:59:53 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
value = g_new0(extcap_value, 1);
|
2014-10-06 18:03:47 +00:00
|
|
|
value->arg_num = tint;
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_VALUE)))
|
2014-10-06 18:03:47 +00:00
|
|
|
== NULL) {
|
|
|
|
/* printf("no value in VALUE sentence\n"); */
|
|
|
|
extcap_free_value(value);
|
2016-12-07 18:59:53 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2016-09-05 11:29:23 +00:00
|
|
|
value->call = g_strdup(param_value);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DISPLAY)))
|
2014-10-06 18:03:47 +00:00
|
|
|
== NULL) {
|
|
|
|
/* printf("no display in VALUE sentence\n"); */
|
|
|
|
extcap_free_value(value);
|
2016-12-07 18:59:53 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2016-09-05 11:29:23 +00:00
|
|
|
value->display = g_strdup(param_value);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_PARENT)))
|
2014-10-06 18:03:47 +00:00
|
|
|
!= NULL) {
|
2016-09-05 11:29:23 +00:00
|
|
|
value->parent = g_strdup(param_value);
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DEFAULT)))
|
2014-10-06 18:03:47 +00:00
|
|
|
!= NULL) {
|
|
|
|
/* printf("found default value\n"); */
|
2016-12-07 18:59:53 +00:00
|
|
|
value->is_default = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, param_value, G_REGEX_CASELESS, (GRegexMatchFlags)0);
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_ENABLED)))
|
2014-10-06 18:03:47 +00:00
|
|
|
!= NULL) {
|
2016-12-07 18:59:53 +00:00
|
|
|
value->enabled = g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, param_value, G_REGEX_CASELESS, (GRegexMatchFlags)0);
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
((extcap_arg *) entry->data)->values = g_list_append(
|
|
|
|
((extcap_arg *) entry->data)->values, value);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return target_arg;
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
GList *extcap_parse_args(gchar *output) {
|
|
|
|
GList *result = NULL;
|
|
|
|
GList *walker = NULL;
|
|
|
|
GList *temp = NULL;
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
walker = extcap_tokenize_sentences(output);
|
|
|
|
temp = walker;
|
|
|
|
|
|
|
|
while (walker) {
|
2014-10-06 18:03:47 +00:00
|
|
|
extcap_arg *ra = NULL;
|
2016-12-07 18:59:53 +00:00
|
|
|
extcap_token_sentence *sentence = (extcap_token_sentence *)walker->data;
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((ra = extcap_parse_arg_sentence(result, sentence)) != NULL)
|
|
|
|
result = g_list_append(result, (gpointer) ra);
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
walker = g_list_next(walker);
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-09-08 12:26:58 +00:00
|
|
|
extcap_free_tokenized_sentences(temp);
|
2016-09-05 11:29:23 +00:00
|
|
|
|
|
|
|
return result;
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
static extcap_interface *extcap_parse_interface_sentence(extcap_token_sentence *s) {
|
2014-10-06 18:03:47 +00:00
|
|
|
extcap_sentence_type sent = EXTCAP_SENTENCE_UNKNOWN;
|
2016-12-07 18:59:53 +00:00
|
|
|
gchar *param_value = NULL;
|
|
|
|
extcap_interface *ri = NULL;
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (s == NULL)
|
2016-09-05 11:29:23 +00:00
|
|
|
return NULL;
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (g_ascii_strcasecmp(s->sentence, "interface") == 0) {
|
|
|
|
sent = EXTCAP_SENTENCE_INTERFACE;
|
2016-01-12 12:45:20 +00:00
|
|
|
} else if (g_ascii_strcasecmp(s->sentence, "extcap") == 0) {
|
|
|
|
sent = EXTCAP_SENTENCE_EXTCAP;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2014-10-06 18:03:47 +00:00
|
|
|
if (sent == EXTCAP_SENTENCE_UNKNOWN)
|
2016-09-05 11:29:23 +00:00
|
|
|
return NULL;
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-09-05 05:54:47 +00:00
|
|
|
ri = g_new0(extcap_interface, 1);
|
2016-01-12 12:45:20 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
ri->if_type = sent;
|
|
|
|
|
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_VALUE)))
|
2016-01-12 12:45:20 +00:00
|
|
|
== NULL && sent == EXTCAP_SENTENCE_INTERFACE) {
|
2014-10-06 18:03:47 +00:00
|
|
|
printf("No value in INTERFACE sentence\n");
|
2016-09-05 11:29:23 +00:00
|
|
|
g_free(ri);
|
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2016-09-05 11:29:23 +00:00
|
|
|
ri->call = g_strdup(param_value);
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DISPLAY)))
|
2016-01-12 12:45:20 +00:00
|
|
|
== NULL && sent == EXTCAP_SENTENCE_INTERFACE) {
|
2014-10-06 18:03:47 +00:00
|
|
|
printf("No display in INTERFACE sentence\n");
|
2016-09-05 11:29:23 +00:00
|
|
|
g_free(ri->call);
|
|
|
|
g_free(ri);
|
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2016-09-05 11:29:23 +00:00
|
|
|
ri->display = g_strdup(param_value);
|
2016-01-12 12:45:20 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_VERSION)))
|
2016-01-12 12:45:20 +00:00
|
|
|
!= NULL) {
|
2016-09-05 11:29:23 +00:00
|
|
|
ri->version = g_strdup(param_value);
|
2016-01-12 12:45:20 +00:00
|
|
|
}
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-09-05 05:54:47 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_HELP)))
|
|
|
|
!= NULL) {
|
|
|
|
ri->help = g_strdup(param_value);
|
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
return ri;
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
GList *extcap_parse_interfaces(gchar *output) {
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
GList *result = NULL;
|
|
|
|
GList *tokens = NULL;
|
|
|
|
GList *walker = extcap_tokenize_sentences(output);
|
2016-09-05 11:29:23 +00:00
|
|
|
tokens = walker;
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
while (walker) {
|
2016-12-07 18:59:53 +00:00
|
|
|
extcap_interface *ri = NULL;
|
|
|
|
extcap_token_sentence *if_sentence = (extcap_token_sentence *) walker->data;
|
2016-09-05 11:29:23 +00:00
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
if (if_sentence != NULL && (ri = extcap_parse_interface_sentence(if_sentence)) != NULL)
|
2016-09-05 11:29:23 +00:00
|
|
|
result = g_list_append(result, ri);
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
walker = g_list_next(walker);
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-09-08 12:26:58 +00:00
|
|
|
extcap_free_tokenized_sentences(tokens);
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
return result;
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
/* Parse a tokenized set of sentences and validate, looking for DLT definitions */
|
2016-12-07 18:59:53 +00:00
|
|
|
static extcap_dlt *extcap_parse_dlt_sentence(extcap_token_sentence *s) {
|
2016-09-05 11:29:23 +00:00
|
|
|
gchar *param_value = NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
extcap_sentence_type sent = EXTCAP_SENTENCE_UNKNOWN;
|
2016-12-07 18:59:53 +00:00
|
|
|
extcap_dlt *result = NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
if (s == NULL)
|
2016-09-05 11:29:23 +00:00
|
|
|
return result;
|
2014-10-06 18:03:47 +00:00
|
|
|
|
|
|
|
if (g_ascii_strcasecmp(s->sentence, "dlt") == 0) {
|
|
|
|
sent = EXTCAP_SENTENCE_DLT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sent == EXTCAP_SENTENCE_UNKNOWN)
|
2016-09-05 11:29:23 +00:00
|
|
|
return result;
|
|
|
|
|
|
|
|
result = g_new0(extcap_dlt, 1);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
result->number = -1;
|
|
|
|
result->name = NULL;
|
|
|
|
result->display = NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_ARGNUM)))
|
2014-10-06 18:03:47 +00:00
|
|
|
== NULL) {
|
|
|
|
printf("No number in DLT sentence\n");
|
2016-09-05 11:29:23 +00:00
|
|
|
g_free(result);
|
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2016-09-05 11:29:23 +00:00
|
|
|
if (sscanf(param_value, "%d", &(result->number)) != 1) {
|
2014-10-06 18:03:47 +00:00
|
|
|
printf("Invalid number in DLT sentence\n");
|
2016-09-05 11:29:23 +00:00
|
|
|
g_free(result);
|
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_NAME)))
|
2014-10-06 18:03:47 +00:00
|
|
|
== NULL) {
|
|
|
|
printf("No name in DLT sentence\n");
|
2016-09-05 11:29:23 +00:00
|
|
|
g_free(result);
|
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2016-09-05 11:29:23 +00:00
|
|
|
result->name = g_strdup(param_value);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((param_value = (gchar *)g_hash_table_lookup(s->param_list, ENUM_KEY(EXTCAP_PARAM_DISPLAY)))
|
2014-10-06 18:03:47 +00:00
|
|
|
== NULL) {
|
|
|
|
printf("No display in DLT sentence\n");
|
2016-09-05 11:29:23 +00:00
|
|
|
g_free(result->name);
|
|
|
|
g_free(result);
|
|
|
|
return NULL;
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2016-09-05 11:29:23 +00:00
|
|
|
result->display = g_strdup(param_value);
|
2014-10-06 18:03:47 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
return result;
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
GList *extcap_parse_dlts(gchar *output) {
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-12-07 18:59:53 +00:00
|
|
|
GList *walker = NULL;
|
|
|
|
GList *temp = NULL;
|
|
|
|
GList *result = NULL;
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
walker = extcap_tokenize_sentences(output);
|
|
|
|
|
|
|
|
temp = walker;
|
|
|
|
|
|
|
|
while (walker) {
|
|
|
|
extcap_dlt *data = NULL;
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
if ((data = extcap_parse_dlt_sentence((extcap_token_sentence *)walker->data)) != NULL)
|
|
|
|
result = g_list_append(result, data);
|
|
|
|
|
|
|
|
walker = g_list_next(walker);
|
2014-10-06 18:03:47 +00:00
|
|
|
}
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-09-08 12:26:58 +00:00
|
|
|
extcap_free_tokenized_sentences(temp);
|
2014-02-25 13:05:11 +00:00
|
|
|
|
2016-09-05 11:29:23 +00:00
|
|
|
return result;
|
2014-02-25 13:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
2014-10-06 18:03:47 +00:00
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
2014-02-25 13:05:11 +00:00
|
|
|
* End:
|
|
|
|
*
|
2014-10-06 18:03:47 +00:00
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
2014-02-25 13:05:11 +00:00
|
|
|
*/
|