extcap: add masked to options.
[metze/wireshark/wip.git] / extcap_parser.h
1 /* extcap_parser.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef __EXTCAP_PARSER_H__
23 #define __EXTCAP_PARSER_H__
24
25 #include <stdio.h>
26 #include <glib.h>
27 #include <string.h>
28
29 typedef enum {
30     EXTCAP_SENTENCE_UNKNOWN,
31     EXTCAP_SENTENCE_ARG,
32     EXTCAP_SENTENCE_VALUE,
33     EXTCAP_SENTENCE_EXTCAP,
34     EXTCAP_SENTENCE_INTERFACE,
35     EXTCAP_SENTENCE_DLT
36 } extcap_sentence_type;
37
38 typedef enum {
39     /* Simple types */
40     EXTCAP_ARG_UNKNOWN,
41     EXTCAP_ARG_INTEGER,
42     EXTCAP_ARG_UNSIGNED,
43     EXTCAP_ARG_LONG,
44     EXTCAP_ARG_DOUBLE,
45     EXTCAP_ARG_BOOLEAN,
46     EXTCAP_ARG_BOOLFLAG,
47     EXTCAP_ARG_STRING,
48     EXTCAP_ARG_PASSWORD,
49     /* Complex GUI types which are populated with value sentences */
50     EXTCAP_ARG_SELECTOR,
51     EXTCAP_ARG_RADIO,
52     EXTCAP_ARG_MULTICHECK,
53     EXTCAP_ARG_FILESELECT
54 } extcap_arg_type;
55
56 typedef enum {
57     /* value types */
58     EXTCAP_PARAM_UNKNOWN,
59     EXTCAP_PARAM_ARGNUM,
60     EXTCAP_PARAM_CALL,
61     EXTCAP_PARAM_DISPLAY,
62     EXTCAP_PARAM_TYPE,
63     EXTCAP_PARAM_ARG,
64     EXTCAP_PARAM_DEFAULT,
65     EXTCAP_PARAM_VALUE,
66     EXTCAP_PARAM_RANGE,
67     EXTCAP_PARAM_TOOLTIP,
68     EXTCAP_PARAM_NAME,
69     EXTCAP_PARAM_ENABLED,
70     EXTCAP_PARAM_FILE_MUSTEXIST,
71     EXTCAP_PARAM_FILE_EXTENSION,
72     EXTCAP_PARAM_PARENT,
73     EXTCAP_PARAM_REQUIRED,
74     EXTCAP_PARAM_VALIDATION,
75     EXTCAP_PARAM_VERSION
76 } extcap_param_type;
77
78 /* Values for a given sentence; values are all stored as a call
79  * and a value string, or a valid range, so we only need to store
80  * those and repeat them */
81 typedef struct _extcap_value {
82     int arg_num;
83
84     gchar *call;
85     gchar *display;
86     gboolean enabled;
87     gboolean is_default;
88     gchar *parent;
89 } extcap_value;
90
91 /* Complex-ish struct for storing complex values */
92 typedef struct _extcap_complex {
93     extcap_arg_type complex_type;
94     union {
95         int int_value;
96         unsigned int uint_value;
97         long long_value;
98         double double_value;
99         gboolean bool_value;
100         gchar *string_value;
101     } complex_value;
102     gboolean value_filled;
103 } extcap_complex;
104
105 /* An argument sentence and accompanying options */
106 typedef struct _extcap_arg {
107     int arg_num;
108
109     gchar *call;
110     gchar *display;
111     gchar *tooltip;
112
113     gchar * fileextension;
114     gboolean fileexists;
115
116     gboolean is_required;
117
118     gchar * regexp;
119
120     extcap_arg_type arg_type;
121
122     extcap_complex *range_start;
123     extcap_complex *range_end;
124     extcap_complex *default_complex;
125
126     GList * values;
127 } extcap_arg;
128
129 typedef struct _extcap_if {
130     gchar * extcap_path;
131     GList * interfaces;
132 } extcap_if;
133
134 typedef struct _extcap_interface {
135     gchar *call;
136     gchar *display;
137     gchar *version;
138
139     extcap_sentence_type if_type;
140     struct _extcap_interface *next_interface;
141 } extcap_interface;
142
143 typedef struct _extcap_dlt {
144     gint number;
145     gchar *name;
146     gchar *display;
147
148     struct _extcap_dlt *next_dlt;
149 } extcap_dlt;
150
151 /* Parser internals */
152 typedef struct _extcap_token_param {
153     gchar *arg;
154     gchar *value;
155
156     extcap_param_type param_type;
157
158     struct _extcap_token_param *next_token;
159 } extcap_token_param;
160
161 typedef struct _extcap_token_sentence {
162     gchar *sentence;
163
164     extcap_token_param *param_list;
165
166     struct _extcap_token_sentence *next_sentence;
167 } extcap_token_sentence;
168
169 #ifdef __cplusplus
170 extern "C" {
171 #endif
172
173 extcap_interface *extcap_new_interface(void);
174 void extcap_free_interface(extcap_interface *interface);
175
176 extcap_dlt *extcap_new_dlt(void);
177 void extcap_free_dlt(extcap_dlt *dlt);
178
179 /* Parse a string into a complex type */
180 extcap_complex *extcap_parse_complex(extcap_arg_type complex_type,
181         const gchar *data);
182
183 /* Free a complex */
184 void extcap_free_complex(extcap_complex *comp);
185
186 /* Print a complex value out for debug */
187 void extcap_printf_complex(extcap_complex *comp);
188
189 /*
190  * Return a string representation of a complex type
191  * Caller is responsible for calling g_free on the returned string
192  */
193 gchar *extcap_get_complex_as_string(extcap_complex *comp);
194
195 int extcap_complex_get_int(extcap_complex *comp);
196 unsigned int extcap_complex_get_uint(extcap_complex *comp);
197 long extcap_complex_get_long(extcap_complex *comp);
198 double extcap_complex_get_double(extcap_complex *comp);
199 gboolean extcap_complex_get_bool(extcap_complex *comp);
200 gchar *extcap_complex_get_string(extcap_complex *comp);
201
202 /* compares the default value of an element with a given parameter */
203 gboolean extcap_compare_is_default(extcap_arg *element, extcap_complex *test);
204
205 void extcap_free_tokenized_param(extcap_token_param *v);
206 void extcap_free_tokenized_sentence(extcap_token_sentence *s);
207 void extcap_free_tokenized_sentence_list(extcap_token_sentence *f);
208
209 /* Turn a sentence into logical tokens, don't validate beyond basic syntax */
210 extcap_token_sentence *extcap_tokenize_sentence(const gchar *s);
211
212 /* Tokenize a set of sentences (such as the output of a g_spawn_sync) */
213 extcap_token_sentence *extcap_tokenize_sentences(const gchar *s);
214
215 /* Find an argument in the extcap_arg list which matches the given arg=X number */
216 extcap_arg *extcap_find_numbered_arg(extcap_arg *first, int number);
217
218 /* Find the first occurrence in a parameter list of a parameter of the given type */
219 extcap_token_param *extcap_find_param_by_type(extcap_token_param *first,
220         extcap_param_type t);
221
222 void extcap_free_value(extcap_value *v);
223
224 extcap_arg *extcap_new_arg(void);
225
226 /* Free a single argument */
227 void extcap_free_arg(extcap_arg *a);
228
229 /* Free an entire arg list */
230 void extcap_free_arg_list(GList *a);
231
232 /*
233  * Parse a tokenized sentence and validate.  If a new sentence is created, the result
234  * is returned in 'ra'.  On error, < 0 is returned.  Not all sentences will create a
235  * new returned sentence (VALUE sentences, for example)
236  */
237 extcap_arg * extcap_parse_arg_sentence(GList * args, extcap_token_sentence *s);
238
239 /* Parse all sentences for args and values */
240 GList * extcap_parse_args(extcap_token_sentence *first_s);
241
242 /*
243  * Parse a tokenized set of sentences and validate, looking for interface definitions.
244  */
245 int extcap_parse_interface_sentence(extcap_token_sentence *s,
246         extcap_interface **ri);
247
248 /* Parse all sentences for interfaces */
249 int extcap_parse_interfaces(extcap_token_sentence *first_s,
250         extcap_interface **first_int);
251
252 /* Parse a tokenized set of sentences and validate, looking for DLT definitions */
253 int extcap_parse_dlt_sentence(extcap_token_sentence *s, extcap_dlt **ri);
254
255 /* Parse all sentences for DLTs */
256 int extcap_parse_dlts(extcap_token_sentence *first_s, extcap_dlt **first_dlt);
257
258 #ifdef __cplusplus
259 }
260 #endif
261
262 #endif
263
264 /*
265  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
266  *
267  * Local variables:
268  * c-basic-offset: 4
269  * tab-width: 8
270  * indent-tabs-mode: nil
271  * End:
272  *
273  * vi: set shiftwidth=4 tabstop=8 expandtab:
274  * :indentSize=4:tabSize=8:noTabs=true:
275  */