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