pfcp: correction of length
[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_RELOAD,
68     EXTCAP_PARAM_SAVE,
69     EXTCAP_PARAM_VALIDATION,
70     EXTCAP_PARAM_VERSION,
71     EXTCAP_PARAM_HELP,
72     EXTCAP_PARAM_CONTROL,
73     EXTCAP_PARAM_ROLE
74 } extcap_param_type;
75
76 #define ENUM_KEY(s) GUINT_TO_POINTER((guint)s)
77
78 /* Values for a given sentence; values are all stored as a call
79  * and a value string, or a valid range, so we only need to store
80  * those and repeat them */
81 typedef struct _extcap_value {
82     int arg_num;
83
84     gchar *call;
85     gchar *display;
86     gboolean enabled;
87     gboolean is_default;
88     gchar *parent;
89 } extcap_value;
90
91 /* Complex-ish struct for storing complex values */
92 typedef struct _extcap_complex {
93     extcap_arg_type complex_type;
94     gchar * _val;
95 } extcap_complex;
96
97 /* An argument sentence and accompanying options */
98 typedef struct _extcap_arg {
99     int arg_num;
100
101     gchar *call;
102     gchar *display;
103     gchar *tooltip;
104     gchar *placeholder;
105
106     gchar * fileextension;
107     gboolean fileexists;
108
109     gboolean is_required;
110     gboolean save;
111
112     gboolean reload;
113
114     gchar * regexp;
115
116     extcap_arg_type arg_type;
117
118     extcap_complex *range_start;
119     extcap_complex *range_end;
120     extcap_complex *default_complex;
121
122     gchar ** pref_valptr; /**< A copy of the pointer containing the current preference value. */
123     gchar * device_name;
124
125     GList * values;
126 } extcap_arg;
127
128 typedef struct _extcap_interface {
129     gchar * call;
130     gchar * display;
131     gchar * version;
132     gchar * help;
133     gchar * extcap_path;
134
135     extcap_sentence_type if_type;
136 } extcap_interface;
137
138 typedef struct _extcap_dlt {
139     gint number;
140     gchar *name;
141     gchar *display;
142 } extcap_dlt;
143
144 typedef struct _extcap_token_sentence {
145     gchar *sentence;
146
147     GHashTable *param_list;
148 } extcap_token_sentence;
149
150 #ifdef __cplusplus
151 extern "C" {
152 #endif
153
154 /* Parse a string into a complex type */
155 extcap_complex *extcap_parse_complex(extcap_arg_type complex_type,
156         const gchar *data);
157
158 /* Free a complex */
159 void extcap_free_complex(extcap_complex *comp);
160
161 /* Print a complex value out for debug */
162 void extcap_printf_complex(extcap_complex *comp);
163
164 /*
165  * Return a string representation of a complex type
166  * Caller is responsible for calling g_free on the returned string
167  */
168 gchar *extcap_get_complex_as_string(extcap_complex *comp);
169
170 gint extcap_complex_get_int(extcap_complex *comp);
171 guint extcap_complex_get_uint(extcap_complex *comp);
172 gint64 extcap_complex_get_long(extcap_complex *comp);
173 gdouble extcap_complex_get_double(extcap_complex *comp);
174 gboolean extcap_complex_get_bool(extcap_complex *comp);
175 gchar *extcap_complex_get_string(extcap_complex *comp);
176
177 /* compares the default value of an element with a given parameter */
178 gboolean extcap_compare_is_default(extcap_arg *element, extcap_complex *test);
179
180
181 /* Free a single argument */
182 void extcap_free_arg(extcap_arg *a);
183
184 /* Free an entire arg list */
185 void extcap_free_arg_list(GList *a);
186
187
188 /** Parser for extcap data */
189
190 /* Parse all sentences for args and values */
191 GList * extcap_parse_args(gchar *output);
192
193 /* Parse all sentences for values */
194 GList * extcap_parse_values(gchar *output);
195
196 /* Parse all sentences for interfaces */
197 GList * extcap_parse_interfaces(gchar *output, GList **control_items);
198
199 /* Parse all sentences for DLTs */
200 GList * extcap_parse_dlts(gchar *output);
201
202 #ifdef __cplusplus
203 }
204 #endif
205
206 #endif
207
208 /*
209  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
210  *
211  * Local variables:
212  * c-basic-offset: 4
213  * tab-width: 8
214  * indent-tabs-mode: nil
215  * End:
216  *
217  * vi: set shiftwidth=4 tabstop=8 expandtab:
218  * :indentSize=4:tabSize=8:noTabs=true:
219  */