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
15 #include <wsutil/ws_assert.h>
16 #include <wsutil/wslog.h>
17 #include <epan/ftypes/ftypes.h>
18 #include "dfilter-loc.h"
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))
36 STTYPE_UNPARSED
, /* Must be resolved into a literal or a field. */
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 */
61 STTypeNewFunc func_new
;
62 STTypeFreeFunc func_free
;
63 STTypeDupFunc func_dup
;
64 STTypeToStrFunc func_tostr
;
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
{
89 STNODE_OP_UNINITIALIZED
,
105 STNODE_OP_BITWISE_AND
,
106 STNODE_OP_UNARY_MINUS
,
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);
134 sttype_cleanup(void);
137 sttype_register(sttype_t
*type
);
141 sttype_name(sttype_id_t type
);
145 stnode_op_name(stnode_op_t op
);
149 stnode_new(sttype_id_t type_id
, void *data
, char *token
, df_loc_t loc
);
153 stnode_new_empty(sttype_id_t type_id
);
157 stnode_dup(const stnode_t
*org
);
161 stnode_clear(stnode_t
*node
);
165 stnode_init(stnode_t
*node
, sttype_id_t type_id
, void *data
, char *token
, df_loc_t loc
);
169 stnode_replace(stnode_t
*node
, sttype_id_t type_id
, void *data
);
173 stnode_mutate(stnode_t
*node
, sttype_id_t type_id
);
177 stnode_free(stnode_t
*node
);
181 stnode_type_name(stnode_t
*node
);
185 stnode_type_id(stnode_t
*node
);
189 stnode_data(stnode_t
*node
);
193 stnode_string(stnode_t
*node
);
197 stnode_steal_data(stnode_t
*node
);
201 stnode_token(stnode_t
*node
);
205 stnode_location(stnode_t
*node
);
209 stnode_set_location(stnode_t
*node
, df_loc_t loc
);
213 stnode_get_flags(stnode_t
*node
, uint16_t flags
);
217 stnode_set_flags(stnode_t
*node
, uint16_t flags
);
220 stnode_merge_location(stnode_t
*dst
, stnode_t
*n1
, stnode_t
*n2
);
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)
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
);
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
);
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) \
247 if (stnode_type_id(node) == STTYPE_TEST) \
253 #define log_node(node) (void)0
254 #define log_test(node) (void)0
255 #define LOG_NODE(node) (void)0
259 dump_syntax_tree_str(stnode_t
*root
);
262 log_syntax_tree(enum ws_log_level
, stnode_t
*root
, const char *msg
, char **cache_ptr
);
265 #define ws_assert_magic(obj, mnum) \
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)); \
277 #define ws_assert_magic(obj, mnum) (void)0
282 #endif /* __cplusplus */
284 #endif /* SYNTAX_TREE_H */