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