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