Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dfilter / syntax-tree.h
blob8932e9e90d8a7c0b2157378c5afafd0cf7b62e03
1 /*
2 * Wireshark - Network traffic analyzer
3 * By Gerald Combs <gerald@wireshark.org>
4 * Copyright 2001 Gerald Combs
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
9 #ifndef SYNTAX_TREE_H
10 #define SYNTAX_TREE_H
12 #include <stdio.h>
13 #include <inttypes.h>
15 #include <wsutil/ws_assert.h>
16 #include <wsutil/wslog.h>
17 #include <epan/ftypes/ftypes.h>
18 #include "dfilter-loc.h"
20 /** @file
23 #ifdef __cplusplus
24 extern "C" {
25 #endif /* __cplusplus */
27 #define ASSERT_STTYPE_NOT_REACHED(st) \
28 ws_error("Invalid syntax node type '%s'.", sttype_name(st))
30 #define ASSERT_STNODE_OP_NOT_REACHED(op) \
31 ws_error("Invalid stnode op '%s'.", stnode_op_name(op))
33 typedef enum {
34 STTYPE_UNINITIALIZED,
35 STTYPE_TEST,
36 STTYPE_UNPARSED, /* Must be resolved into a literal or a field. */
37 STTYPE_LITERAL,
38 STTYPE_REFERENCE,
39 STTYPE_STRING,
40 STTYPE_CHARCONST,
41 STTYPE_NUMBER,
42 STTYPE_FIELD,
43 STTYPE_FVALUE,
44 STTYPE_SLICE,
45 STTYPE_FUNCTION,
46 STTYPE_SET,
47 STTYPE_PCRE,
48 STTYPE_ARITHMETIC,
49 STTYPE_NUM_TYPES
50 } sttype_id_t;
52 typedef void * (*STTypeNewFunc)(void *);
53 typedef void * (*STTypeDupFunc)(const void *);
54 typedef void (*STTypeFreeFunc)(void *);
55 typedef char* (*STTypeToStrFunc)(const void *, bool pretty);
58 /* Type information */
59 typedef struct {
60 sttype_id_t id;
61 STTypeNewFunc func_new;
62 STTypeFreeFunc func_free;
63 STTypeDupFunc func_dup;
64 STTypeToStrFunc func_tostr;
65 } sttype_t;
67 typedef enum {
68 STNUM_NONE = 0,
69 STNUM_INTEGER,
70 STNUM_UNSIGNED,
71 STNUM_FLOAT,
72 } stnumber_t;
74 /* Lexical value is ambiguous (can be a protocol field or a literal). */
75 #define STFLAG_UNPARSED (1 << 0)
77 /** Node (type instance) information */
78 typedef struct stnode {
79 sttype_t *type;
80 void *data;
81 char *repr_token;
82 char *repr_display;
83 char *repr_debug;
84 df_loc_t location;
85 uint16_t flags;
86 } stnode_t;
88 typedef enum {
89 STNODE_OP_UNINITIALIZED,
90 STNODE_OP_NOT,
91 STNODE_OP_AND,
92 STNODE_OP_OR,
93 STNODE_OP_ALL_EQ,
94 STNODE_OP_ANY_EQ,
95 STNODE_OP_ALL_NE,
96 STNODE_OP_ANY_NE,
97 STNODE_OP_GT,
98 STNODE_OP_GE,
99 STNODE_OP_LT,
100 STNODE_OP_LE,
101 STNODE_OP_CONTAINS,
102 STNODE_OP_MATCHES,
103 STNODE_OP_IN,
104 STNODE_OP_NOT_IN,
105 STNODE_OP_BITWISE_AND,
106 STNODE_OP_UNARY_MINUS,
107 STNODE_OP_ADD,
108 STNODE_OP_SUBTRACT,
109 STNODE_OP_MULTIPLY,
110 STNODE_OP_DIVIDE,
111 STNODE_OP_MODULO,
112 } stnode_op_t;
114 typedef enum {
115 STNODE_MATCH_DEF,
116 STNODE_MATCH_ANY,
117 STNODE_MATCH_ALL,
118 } stmatch_t;
120 /* These are the sttype_t registration function prototypes. */
121 void sttype_register_field(void);
122 void sttype_register_function(void);
123 void sttype_register_number(void);
124 void sttype_register_pointer(void);
125 void sttype_register_set(void);
126 void sttype_register_slice(void);
127 void sttype_register_string(void);
128 void sttype_register_opers(void);
130 void
131 sttype_init(void);
133 void
134 sttype_cleanup(void);
136 void
137 sttype_register(sttype_t *type);
139 WS_DLL_PUBLIC
140 const char *
141 sttype_name(sttype_id_t type);
143 WS_DLL_PUBLIC
144 const char *
145 stnode_op_name(stnode_op_t op);
147 WS_DLL_PUBLIC
148 stnode_t*
149 stnode_new(sttype_id_t type_id, void *data, char *token, df_loc_t loc);
151 WS_DLL_PUBLIC
152 stnode_t*
153 stnode_new_empty(sttype_id_t type_id);
155 WS_DLL_PUBLIC
156 stnode_t*
157 stnode_dup(const stnode_t *org);
159 WS_DLL_PUBLIC
160 void
161 stnode_clear(stnode_t *node);
163 WS_DLL_PUBLIC
164 void
165 stnode_init(stnode_t *node, sttype_id_t type_id, void *data, char *token, df_loc_t loc);
167 WS_DLL_PUBLIC
168 void
169 stnode_replace(stnode_t *node, sttype_id_t type_id, void *data);
171 WS_DLL_PUBLIC
172 void
173 stnode_mutate(stnode_t *node, sttype_id_t type_id);
175 WS_DLL_PUBLIC
176 void
177 stnode_free(stnode_t *node);
179 WS_DLL_PUBLIC
180 const char*
181 stnode_type_name(stnode_t *node);
183 WS_DLL_PUBLIC
184 sttype_id_t
185 stnode_type_id(stnode_t *node);
187 WS_DLL_PUBLIC
188 void *
189 stnode_data(stnode_t *node);
191 WS_DLL_PUBLIC
192 GString *
193 stnode_string(stnode_t *node);
195 WS_DLL_PUBLIC
196 void *
197 stnode_steal_data(stnode_t *node);
199 WS_DLL_PUBLIC
200 const char *
201 stnode_token(stnode_t *node);
203 WS_DLL_PUBLIC
204 df_loc_t
205 stnode_location(stnode_t *node);
207 WS_DLL_PUBLIC
208 void
209 stnode_set_location(stnode_t *node, df_loc_t loc);
211 WS_DLL_PUBLIC
212 bool
213 stnode_get_flags(stnode_t *node, uint16_t flags);
215 WS_DLL_PUBLIC
216 void
217 stnode_set_flags(stnode_t *node, uint16_t flags);
219 void
220 stnode_merge_location(stnode_t *dst, stnode_t *n1, stnode_t *n2);
222 WS_DLL_PUBLIC
223 const char *
224 stnode_tostr(stnode_t *node, bool pretty);
226 #define stnode_todisplay(node) stnode_tostr(node, true)
228 #define stnode_todebug(node) stnode_tostr(node, false)
230 void
231 log_node_full(enum ws_log_level level,
232 const char *file, int line, const char *func,
233 stnode_t *node, const char *msg);
235 void
236 log_test_full(enum ws_log_level level,
237 const char *file, int line, const char *func,
238 stnode_t *node, const char *msg);
240 #ifdef WS_DEBUG
241 #define log_node(node) \
242 log_node_full(LOG_LEVEL_NOISY, __FILE__, __LINE__, __func__, node, #node)
243 #define log_test(node) \
244 log_test_full(LOG_LEVEL_NOISY, __FILE__, __LINE__, __func__, node, #node)
245 #define LOG_NODE(node) \
246 do { \
247 if (stnode_type_id(node) == STTYPE_TEST) \
248 log_test(node); \
249 else \
250 log_node(node); \
251 } while (0)
252 #else
253 #define log_node(node) (void)0
254 #define log_test(node) (void)0
255 #define LOG_NODE(node) (void)0
256 #endif
258 char *
259 dump_syntax_tree_str(stnode_t *root);
261 void
262 log_syntax_tree(enum ws_log_level, stnode_t *root, const char *msg, char **cache_ptr);
264 #ifdef WS_DEBUG
265 #define ws_assert_magic(obj, mnum) \
266 do { \
267 ws_assert(obj); \
268 if ((obj)->magic != (mnum)) { \
269 ws_log_full(LOG_DOMAIN_DFILTER, LOG_LEVEL_ERROR, \
270 __FILE__, __LINE__, __func__, \
271 "Magic num is 0x%08" PRIx32", " \
272 "but should be 0x%08" PRIx32, \
273 (obj)->magic, (mnum)); \
275 } while(0)
276 #else
277 #define ws_assert_magic(obj, mnum) (void)0
278 #endif
280 #ifdef __cplusplus
282 #endif /* __cplusplus */
284 #endif /* SYNTAX_TREE_H */