diff options
author | Roland Knall <roland.knall@br-automation.com> | 2016-09-05 13:29:23 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2016-09-06 04:19:45 +0000 |
commit | 9b39db04d3cda98b916b3970270b3a247143adfe (patch) | |
tree | 725f592fdeb3e017d80c51a17e5fca774850406c /extcap_parser.h | |
parent | 4ec767588248b4b42a423c56772707a974605875 (diff) |
extcap:Replace self-organized lists with glib ones
Replace the error-prone next/prev handling with GList and GHashTable
Cleanup extcap_parser to only expose necessary functions
Remove token know-how from extcap
Change-Id: I7cc5ea06f58ad6c7a85ac292f5d2cb3d33e59833
Reviewed-on: https://code.wireshark.org/review/17496
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'extcap_parser.h')
-rw-r--r-- | extcap_parser.h | 69 |
1 files changed, 10 insertions, 59 deletions
diff --git a/extcap_parser.h b/extcap_parser.h index b6cc762797..298fbd7558 100644 --- a/extcap_parser.h +++ b/extcap_parser.h @@ -26,6 +26,8 @@ #include <glib.h> #include <string.h> +#include <config.h> + typedef enum { EXTCAP_SENTENCE_UNKNOWN, EXTCAP_SENTENCE_ARG, @@ -76,6 +78,8 @@ typedef enum { EXTCAP_PARAM_VERSION } extcap_param_type; +#define ENUM_KEY(s) GUINT_TO_POINTER((guint)s) + /* Values for a given sentence; values are all stored as a call * and a value string, or a valid range, so we only need to store * those and repeat them */ @@ -134,45 +138,24 @@ typedef struct _extcap_interface { gchar *version; extcap_sentence_type if_type; - struct _extcap_interface *next_interface; } extcap_interface; typedef struct _extcap_dlt { gint number; gchar *name; gchar *display; - - struct _extcap_dlt *next_dlt; } extcap_dlt; -/* Parser internals */ -typedef struct _extcap_token_param { - gchar *arg; - gchar *value; - - extcap_param_type param_type; - - struct _extcap_token_param *next_token; -} extcap_token_param; - typedef struct _extcap_token_sentence { gchar *sentence; - extcap_token_param *param_list; - - struct _extcap_token_sentence *next_sentence; + GHashTable *param_list; } extcap_token_sentence; #ifdef __cplusplus extern "C" { #endif -extcap_interface *extcap_new_interface(void); -void extcap_free_interface(extcap_interface *interface); - -extcap_dlt *extcap_new_dlt(void); -void extcap_free_dlt(extcap_dlt *dlt); - /* Parse a string into a complex type */ extcap_complex *extcap_parse_complex(extcap_arg_type complex_type, const gchar *data); @@ -199,24 +182,6 @@ gchar *extcap_complex_get_string(extcap_complex *comp); /* compares the default value of an element with a given parameter */ gboolean extcap_compare_is_default(extcap_arg *element, extcap_complex *test); -void extcap_free_tokenized_param(extcap_token_param *v); -void extcap_free_tokenized_sentence(extcap_token_sentence *s); -void extcap_free_tokenized_sentence_list(extcap_token_sentence *f); - -/* Turn a sentence into logical tokens, don't validate beyond basic syntax */ -extcap_token_sentence *extcap_tokenize_sentence(const gchar *s); - -/* Tokenize a set of sentences (such as the output of a g_spawn_sync) */ -extcap_token_sentence *extcap_tokenize_sentences(const gchar *s); - -/* Find an argument in the extcap_arg list which matches the given arg=X number */ -extcap_arg *extcap_find_numbered_arg(extcap_arg *first, int number); - -/* Find the first occurrence in a parameter list of a parameter of the given type */ -extcap_token_param *extcap_find_param_by_type(extcap_token_param *first, - extcap_param_type t); - -void extcap_free_value(extcap_value *v); /* Free a single argument */ void extcap_free_arg(extcap_arg *a); @@ -224,31 +189,17 @@ void extcap_free_arg(extcap_arg *a); /* Free an entire arg list */ void extcap_free_arg_list(GList *a); -/* - * Parse a tokenized sentence and validate. If a new sentence is created, the result - * is returned in 'ra'. On error, < 0 is returned. Not all sentences will create a - * new returned sentence (VALUE sentences, for example) - */ -extcap_arg * extcap_parse_arg_sentence(GList * args, extcap_token_sentence *s); -/* Parse all sentences for args and values */ -GList * extcap_parse_args(extcap_token_sentence *first_s); +/** Parser for extcap data */ -/* - * Parse a tokenized set of sentences and validate, looking for interface definitions. - */ -int extcap_parse_interface_sentence(extcap_token_sentence *s, - extcap_interface **ri); +/* Parse all sentences for args and values */ +GList * extcap_parse_args(gchar *output); /* Parse all sentences for interfaces */ -int extcap_parse_interfaces(extcap_token_sentence *first_s, - extcap_interface **first_int); - -/* Parse a tokenized set of sentences and validate, looking for DLT definitions */ -int extcap_parse_dlt_sentence(extcap_token_sentence *s, extcap_dlt **ri); +GList * extcap_parse_interfaces(gchar *output); /* Parse all sentences for DLTs */ -int extcap_parse_dlts(extcap_token_sentence *first_s, extcap_dlt **first_dlt); +GList * extcap_parse_dlts(gchar *output); #ifdef __cplusplus } |