[Automatic update for 2016-12-25]
[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 #include <config.h>
30
31 typedef enum {
32     EXTCAP_SENTENCE_UNKNOWN,
33     EXTCAP_SENTENCE_ARG,
34     EXTCAP_SENTENCE_VALUE,
35     EXTCAP_SENTENCE_EXTCAP,
36     EXTCAP_SENTENCE_INTERFACE,
37     EXTCAP_SENTENCE_DLT
38 } extcap_sentence_type;
39
40 typedef enum {
41     /* Simple types */
42     EXTCAP_ARG_UNKNOWN,
43     EXTCAP_ARG_INTEGER,
44     EXTCAP_ARG_UNSIGNED,
45     EXTCAP_ARG_LONG,
46     EXTCAP_ARG_DOUBLE,
47     EXTCAP_ARG_BOOLEAN,
48     EXTCAP_ARG_BOOLFLAG,
49     EXTCAP_ARG_STRING,
50     EXTCAP_ARG_PASSWORD,
51     /* Complex GUI types which are populated with value sentences */
52     EXTCAP_ARG_SELECTOR,
53     EXTCAP_ARG_RADIO,
54     EXTCAP_ARG_MULTICHECK,
55     EXTCAP_ARG_FILESELECT,
56     EXTCAP_ARG_TIMESTAMP
57 } extcap_arg_type;
58
59 typedef enum {
60     /* value types */
61     EXTCAP_PARAM_UNKNOWN,
62     EXTCAP_PARAM_ARGNUM,
63     EXTCAP_PARAM_CALL,
64     EXTCAP_PARAM_DISPLAY,
65     EXTCAP_PARAM_TYPE,
66     EXTCAP_PARAM_ARG,
67     EXTCAP_PARAM_DEFAULT,
68     EXTCAP_PARAM_VALUE,
69     EXTCAP_PARAM_RANGE,
70     EXTCAP_PARAM_TOOLTIP,
71     EXTCAP_PARAM_NAME,
72     EXTCAP_PARAM_ENABLED,
73     EXTCAP_PARAM_FILE_MUSTEXIST,
74     EXTCAP_PARAM_FILE_EXTENSION,
75     EXTCAP_PARAM_PARENT,
76     EXTCAP_PARAM_REQUIRED,
77     EXTCAP_PARAM_SAVE,
78     EXTCAP_PARAM_VALIDATION,
79     EXTCAP_PARAM_VERSION,
80     EXTCAP_PARAM_HELP
81 } extcap_param_type;
82
83 #define ENUM_KEY(s) GUINT_TO_POINTER((guint)s)
84
85 /* Values for a given sentence; values are all stored as a call
86  * and a value string, or a valid range, so we only need to store
87  * those and repeat them */
88 typedef struct _extcap_value {
89     int arg_num;
90
91     gchar *call;
92     gchar *display;
93     gboolean enabled;
94     gboolean is_default;
95     gchar *parent;
96 } extcap_value;
97
98 /* Complex-ish struct for storing complex values */
99 typedef struct _extcap_complex {
100     extcap_arg_type complex_type;
101     gchar * _val;
102 } extcap_complex;
103
104 /* An argument sentence and accompanying options */
105 typedef struct _extcap_arg {
106     int arg_num;
107
108     gchar *call;
109     gchar *display;
110     gchar *tooltip;
111
112     gchar * fileextension;
113     gboolean fileexists;
114
115     gboolean is_required;
116     gboolean save;
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     gchar ** pref_valptr; /**< A copy of the pointer containing the current preference value. */
127     gchar * device_name;
128
129     GList * values;
130 } extcap_arg;
131
132 typedef struct _extcap_interface {
133     gchar * call;
134     gchar * display;
135     gchar * version;
136     gchar * help;
137     gchar * extcap_path;
138
139     extcap_sentence_type if_type;
140 } extcap_interface;
141
142 typedef struct _extcap_dlt {
143     gint number;
144     gchar *name;
145     gchar *display;
146 } extcap_dlt;
147
148 typedef struct _extcap_token_sentence {
149     gchar *sentence;
150
151     GHashTable *param_list;
152 } extcap_token_sentence;
153
154 #ifdef __cplusplus
155 extern "C" {
156 #endif
157
158 /* Parse a string into a complex type */
159 extcap_complex *extcap_parse_complex(extcap_arg_type complex_type,
160         const gchar *data);
161
162 /* Free a complex */
163 void extcap_free_complex(extcap_complex *comp);
164
165 /* Print a complex value out for debug */
166 void extcap_printf_complex(extcap_complex *comp);
167
168 /*
169  * Return a string representation of a complex type
170  * Caller is responsible for calling g_free on the returned string
171  */
172 gchar *extcap_get_complex_as_string(extcap_complex *comp);
173
174 gint extcap_complex_get_int(extcap_complex *comp);
175 guint extcap_complex_get_uint(extcap_complex *comp);
176 gint64 extcap_complex_get_long(extcap_complex *comp);
177 gdouble extcap_complex_get_double(extcap_complex *comp);
178 gboolean extcap_complex_get_bool(extcap_complex *comp);
179 gchar *extcap_complex_get_string(extcap_complex *comp);
180
181 /* compares the default value of an element with a given parameter */
182 gboolean extcap_compare_is_default(extcap_arg *element, extcap_complex *test);
183
184
185 /* Free a single argument */
186 void extcap_free_arg(extcap_arg *a);
187
188 /* Free an entire arg list */
189 void extcap_free_arg_list(GList *a);
190
191
192 /** Parser for extcap data */
193
194 /* Parse all sentences for args and values */
195 GList * extcap_parse_args(gchar *output);
196
197 /* Parse all sentences for interfaces */
198 GList * extcap_parse_interfaces(gchar *output);
199
200 /* Parse all sentences for DLTs */
201 GList * extcap_parse_dlts(gchar *output);
202
203 #ifdef __cplusplus
204 }
205 #endif
206
207 #endif
208
209 /*
210  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
211  *
212  * Local variables:
213  * c-basic-offset: 4
214  * tab-width: 8
215  * indent-tabs-mode: nil
216  * End:
217  *
218  * vi: set shiftwidth=4 tabstop=8 expandtab:
219  * :indentSize=4:tabSize=8:noTabs=true:
220  */