wslua: Abort on out of memory
[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_SAVE,
75     EXTCAP_PARAM_VALIDATION,
76     EXTCAP_PARAM_VERSION
77 } extcap_param_type;
78
79 /* Values for a given sentence; values are all stored as a call
80  * and a value string, or a valid range, so we only need to store
81  * those and repeat them */
82 typedef struct _extcap_value {
83     int arg_num;
84
85     gchar *call;
86     gchar *display;
87     gboolean enabled;
88     gboolean is_default;
89     gchar *parent;
90 } extcap_value;
91
92 /* Complex-ish struct for storing complex values */
93 typedef struct _extcap_complex {
94     extcap_arg_type complex_type;
95     gchar * _val;
96 } extcap_complex;
97
98 /* An argument sentence and accompanying options */
99 typedef struct _extcap_arg {
100     int arg_num;
101
102     gchar *call;
103     gchar *display;
104     gchar *tooltip;
105
106     gchar * fileextension;
107     gboolean fileexists;
108
109     gboolean is_required;
110     gboolean save;
111
112     gchar * regexp;
113
114     extcap_arg_type arg_type;
115
116     extcap_complex *range_start;
117     extcap_complex *range_end;
118     extcap_complex *default_complex;
119
120     gchar * storeval;
121
122     GList * values;
123 } extcap_arg;
124
125 typedef struct _extcap_if {
126     gchar * extcap_path;
127     GList * interfaces;
128 } extcap_if;
129
130 typedef struct _extcap_interface {
131     gchar *call;
132     gchar *display;
133     gchar *version;
134
135     extcap_sentence_type if_type;
136     struct _extcap_interface *next_interface;
137 } extcap_interface;
138
139 typedef struct _extcap_dlt {
140     gint number;
141     gchar *name;
142     gchar *display;
143
144     struct _extcap_dlt *next_dlt;
145 } extcap_dlt;
146
147 /* Parser internals */
148 typedef struct _extcap_token_param {
149     gchar *arg;
150     gchar *value;
151
152     extcap_param_type param_type;
153
154     struct _extcap_token_param *next_token;
155 } extcap_token_param;
156
157 typedef struct _extcap_token_sentence {
158     gchar *sentence;
159
160     extcap_token_param *param_list;
161
162     struct _extcap_token_sentence *next_sentence;
163 } extcap_token_sentence;
164
165 #ifdef __cplusplus
166 extern "C" {
167 #endif
168
169 extcap_interface *extcap_new_interface(void);
170 void extcap_free_interface(extcap_interface *interface);
171
172 extcap_dlt *extcap_new_dlt(void);
173 void extcap_free_dlt(extcap_dlt *dlt);
174
175 /* Parse a string into a complex type */
176 extcap_complex *extcap_parse_complex(extcap_arg_type complex_type,
177         const gchar *data);
178
179 /* Free a complex */
180 void extcap_free_complex(extcap_complex *comp);
181
182 /* Print a complex value out for debug */
183 void extcap_printf_complex(extcap_complex *comp);
184
185 /*
186  * Return a string representation of a complex type
187  * Caller is responsible for calling g_free on the returned string
188  */
189 gchar *extcap_get_complex_as_string(extcap_complex *comp);
190
191 gint extcap_complex_get_int(extcap_complex *comp);
192 guint extcap_complex_get_uint(extcap_complex *comp);
193 gint64 extcap_complex_get_long(extcap_complex *comp);
194 gdouble extcap_complex_get_double(extcap_complex *comp);
195 gboolean extcap_complex_get_bool(extcap_complex *comp);
196 gchar *extcap_complex_get_string(extcap_complex *comp);
197
198 /* compares the default value of an element with a given parameter */
199 gboolean extcap_compare_is_default(extcap_arg *element, extcap_complex *test);
200
201 void extcap_free_tokenized_param(extcap_token_param *v);
202 void extcap_free_tokenized_sentence(extcap_token_sentence *s);
203 void extcap_free_tokenized_sentence_list(extcap_token_sentence *f);
204
205 /* Turn a sentence into logical tokens, don't validate beyond basic syntax */
206 extcap_token_sentence *extcap_tokenize_sentence(const gchar *s);
207
208 /* Tokenize a set of sentences (such as the output of a g_spawn_sync) */
209 extcap_token_sentence *extcap_tokenize_sentences(const gchar *s);
210
211 /* Find an argument in the extcap_arg list which matches the given arg=X number */
212 extcap_arg *extcap_find_numbered_arg(extcap_arg *first, int number);
213
214 /* Find the first occurrence in a parameter list of a parameter of the given type */
215 extcap_token_param *extcap_find_param_by_type(extcap_token_param *first,
216         extcap_param_type t);
217
218 void extcap_free_value(extcap_value *v);
219
220 /* Free a single argument */
221 void extcap_free_arg(extcap_arg *a);
222
223 /* Free an entire arg list */
224 void extcap_free_arg_list(GList *a);
225
226 /*
227  * Parse a tokenized sentence and validate.  If a new sentence is created, the result
228  * is returned in 'ra'.  On error, < 0 is returned.  Not all sentences will create a
229  * new returned sentence (VALUE sentences, for example)
230  */
231 extcap_arg * extcap_parse_arg_sentence(GList * args, extcap_token_sentence *s);
232
233 /* Parse all sentences for args and values */
234 GList * extcap_parse_args(extcap_token_sentence *first_s);
235
236 /*
237  * Parse a tokenized set of sentences and validate, looking for interface definitions.
238  */
239 int extcap_parse_interface_sentence(extcap_token_sentence *s,
240         extcap_interface **ri);
241
242 /* Parse all sentences for interfaces */
243 int extcap_parse_interfaces(extcap_token_sentence *first_s,
244         extcap_interface **first_int);
245
246 /* Parse a tokenized set of sentences and validate, looking for DLT definitions */
247 int extcap_parse_dlt_sentence(extcap_token_sentence *s, extcap_dlt **ri);
248
249 /* Parse all sentences for DLTs */
250 int extcap_parse_dlts(extcap_token_sentence *first_s, extcap_dlt **first_dlt);
251
252 #ifdef __cplusplus
253 }
254 #endif
255
256 #endif
257
258 /*
259  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
260  *
261  * Local variables:
262  * c-basic-offset: 4
263  * tab-width: 8
264  * indent-tabs-mode: nil
265  * End:
266  *
267  * vi: set shiftwidth=4 tabstop=8 expandtab:
268  * :indentSize=4:tabSize=8:noTabs=true:
269  */