nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 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 ** pref_valptr; /**< A copy of the pointer containing the current preference value. */
121 gchar * device_name;
122  
123 GList * values;
124 } extcap_arg;
125  
126 typedef struct _extcap_if {
127 gchar * extcap_path;
128 GList * interfaces;
129 } extcap_if;
130  
131 typedef struct _extcap_interface {
132 gchar *call;
133 gchar *display;
134 gchar *version;
135  
136 extcap_sentence_type if_type;
137 struct _extcap_interface *next_interface;
138 } extcap_interface;
139  
140 typedef struct _extcap_dlt {
141 gint number;
142 gchar *name;
143 gchar *display;
144  
145 struct _extcap_dlt *next_dlt;
146 } extcap_dlt;
147  
148 /* Parser internals */
149 typedef struct _extcap_token_param {
150 gchar *arg;
151 gchar *value;
152  
153 extcap_param_type param_type;
154  
155 struct _extcap_token_param *next_token;
156 } extcap_token_param;
157  
158 typedef struct _extcap_token_sentence {
159 gchar *sentence;
160  
161 extcap_token_param *param_list;
162  
163 struct _extcap_token_sentence *next_sentence;
164 } extcap_token_sentence;
165  
166 #ifdef __cplusplus
167 extern "C" {
168 #endif
169  
170 extcap_interface *extcap_new_interface(void);
171 void extcap_free_interface(extcap_interface *interface);
172  
173 extcap_dlt *extcap_new_dlt(void);
174 void extcap_free_dlt(extcap_dlt *dlt);
175  
176 /* Parse a string into a complex type */
177 extcap_complex *extcap_parse_complex(extcap_arg_type complex_type,
178 const gchar *data);
179  
180 /* Free a complex */
181 void extcap_free_complex(extcap_complex *comp);
182  
183 /* Print a complex value out for debug */
184 void extcap_printf_complex(extcap_complex *comp);
185  
186 /*
187 * Return a string representation of a complex type
188 * Caller is responsible for calling g_free on the returned string
189 */
190 gchar *extcap_get_complex_as_string(extcap_complex *comp);
191  
192 gint extcap_complex_get_int(extcap_complex *comp);
193 guint extcap_complex_get_uint(extcap_complex *comp);
194 gint64 extcap_complex_get_long(extcap_complex *comp);
195 gdouble extcap_complex_get_double(extcap_complex *comp);
196 gboolean extcap_complex_get_bool(extcap_complex *comp);
197 gchar *extcap_complex_get_string(extcap_complex *comp);
198  
199 /* compares the default value of an element with a given parameter */
200 gboolean extcap_compare_is_default(extcap_arg *element, extcap_complex *test);
201  
202 void extcap_free_tokenized_param(extcap_token_param *v);
203 void extcap_free_tokenized_sentence(extcap_token_sentence *s);
204 void extcap_free_tokenized_sentence_list(extcap_token_sentence *f);
205  
206 /* Turn a sentence into logical tokens, don't validate beyond basic syntax */
207 extcap_token_sentence *extcap_tokenize_sentence(const gchar *s);
208  
209 /* Tokenize a set of sentences (such as the output of a g_spawn_sync) */
210 extcap_token_sentence *extcap_tokenize_sentences(const gchar *s);
211  
212 /* Find an argument in the extcap_arg list which matches the given arg=X number */
213 extcap_arg *extcap_find_numbered_arg(extcap_arg *first, int number);
214  
215 /* Find the first occurrence in a parameter list of a parameter of the given type */
216 extcap_token_param *extcap_find_param_by_type(extcap_token_param *first,
217 extcap_param_type t);
218  
219 void extcap_free_value(extcap_value *v);
220  
221 /* Free a single argument */
222 void extcap_free_arg(extcap_arg *a);
223  
224 /* Free an entire arg list */
225 void extcap_free_arg_list(GList *a);
226  
227 /*
228 * Parse a tokenized sentence and validate. If a new sentence is created, the result
229 * is returned in 'ra'. On error, < 0 is returned. Not all sentences will create a
230 * new returned sentence (VALUE sentences, for example)
231 */
232 extcap_arg * extcap_parse_arg_sentence(GList * args, extcap_token_sentence *s);
233  
234 /* Parse all sentences for args and values */
235 GList * extcap_parse_args(extcap_token_sentence *first_s);
236  
237 /*
238 * Parse a tokenized set of sentences and validate, looking for interface definitions.
239 */
240 int extcap_parse_interface_sentence(extcap_token_sentence *s,
241 extcap_interface **ri);
242  
243 /* Parse all sentences for interfaces */
244 int extcap_parse_interfaces(extcap_token_sentence *first_s,
245 extcap_interface **first_int);
246  
247 /* Parse a tokenized set of sentences and validate, looking for DLT definitions */
248 int extcap_parse_dlt_sentence(extcap_token_sentence *s, extcap_dlt **ri);
249  
250 /* Parse all sentences for DLTs */
251 int extcap_parse_dlts(extcap_token_sentence *first_s, extcap_dlt **first_dlt);
252  
253 #ifdef __cplusplus
254 }
255 #endif
256  
257 #endif
258  
259 /*
260 * Editor modelines - http://www.wireshark.org/tools/modelines.html
261 *
262 * Local variables:
263 * c-basic-offset: 4
264 * tab-width: 8
265 * indent-tabs-mode: nil
266 * End:
267 *
268 * vi: set shiftwidth=4 tabstop=8 expandtab:
269 * :indentSize=4:tabSize=8:noTabs=true:
270 */