| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
dfilter.h
Go to the documentation of this file.
1
10#ifndef DFILTER_H
11#define DFILTER_H
12
13#include <wireshark.h>
14
15#include "dfilter-loc.h"
16#include <epan/proto.h>
17
18/* Passed back to user */
19 typedef struct epan_dfilter dfilter_t;
20
21#ifdef __cplusplus
22 extern "C" {
23#endif /* __cplusplus */
24
25 struct epan_dissect;
26
27#define DF_ERROR_GENERIC -1
28#define DF_ERROR_UNEXPECTED_END -2
29
30 typedef struct {
31 int code;
32 char *msg;
33 df_loc_t loc;
34} df_error_t;
35
36 df_error_t *
37df_error_new(int code, char *msg, df_loc_t *loc);
38
39 df_error_t *
40df_error_new_printf(int code, df_loc_t *loc, const char *fmt, ...)
41G_GNUC_PRINTF(3, 4);
42
43#define df_error_new_msg(msg) \
44 df_error_new_printf(DF_ERROR_GENERIC, NULL, "%s", msg)
45
46 df_error_t *
47df_error_new_vprintf(int code, df_loc_t *loc, const char *fmt, va_list ap);
48
49WS_DLL_PUBLIC
50 void
51df_error_free(df_error_t **ep);
52
53/* Module-level initialization */
54 void
55dfilter_init(const char* app_env_var_prefix);
56
57/* Module-level cleanup */
58 void
59dfilter_cleanup(void);
60
61/* Perform macro expansion. */
62WS_DLL_PUBLIC
63 char *
64dfilter_expand(const char *expr, df_error_t **err_ret);
65
66/* Save textual representation of syntax tree (for debugging purposes). */
67#define DF_SAVE_TREE (1U << 0)
68/* Perform macro substitution on filter text. */
69#define DF_EXPAND_MACROS (1U << 1)
70/* Do an optimization pass on the compiled filter. */
71#define DF_OPTIMIZE (1U << 2)
72/* Enable debug trace for flex. */
73#define DF_DEBUG_FLEX (1U << 3)
74/* Enable debug trace for lemon. */
75#define DF_DEBUG_LEMON (1U << 4)
76/* If the root of the syntax tree is a field, load and return the field values.
77 * By default the field is only checked for existence. */
78#define DF_RETURN_VALUES (1U << 5)
79
80/* Compiles a string to a dfilter_t.
81 * On success, sets the dfilter* pointed to by dfp
82 * to either a NULL pointer (if the filter is a null
83 * filter, as generated by an all-blank string) or to
84 * a pointer to the newly-allocated dfilter_t
85 * structure.
86 *
87 * On failure, *err_msg is set to point to the error
88 * message. This error message is allocated with
89 * g_malloc(), and must be freed with g_free().
90 * The dfilter* will be set to NULL after a failure.
91 *
92 * Returns true on success, false on failure.
93 */
94WS_DLL_PUBLIC
95 bool
96dfilter_compile_full(const char *text, dfilter_t **dfp,
97 df_error_t **errpp, unsigned flags,
98 const char *caller);
99
100#define dfilter_compile(text, dfp, errp) \
101 dfilter_compile_full(text, dfp, errp, \
102 DF_EXPAND_MACROS|DF_OPTIMIZE, \
103 __func__)
104
105 struct stnode;
106
111WS_DLL_PUBLIC
112 struct stnode *dfilter_get_syntax_tree(const char *text);
113
114/* Frees all memory used by dfilter, and frees
115 * the dfilter itself. */
116WS_DLL_PUBLIC
117 void
118dfilter_free(dfilter_t *df);
119
120/* Apply compiled dfilter */
121WS_DLL_PUBLIC
122 bool
123dfilter_apply_edt(dfilter_t *df, struct epan_dissect *edt);
124
125/* Apply compiled dfilter */
126 bool
127dfilter_apply(dfilter_t *df, proto_tree *tree);
128
129/* Apply compiled dfilter and return final set of fvalues (if they
130 * exist) in addition to true/false determination. */
131 bool
132dfilter_apply_full(dfilter_t *df, proto_tree *tree, GPtrArray **fvals);
133
134/* Prime a proto_tree using the fields/protocols used in a dfilter. */
135 void
136dfilter_prime_proto_tree(const dfilter_t *df, proto_tree *tree);
137
138/* Prime a proto_tree using the fields/protocols used in a dfilter, marked for print. */
139 void
140dfilter_prime_proto_tree_print(const dfilter_t *df, proto_tree *tree);
141
142/* Refresh references in a compiled display filter. */
143WS_DLL_PUBLIC
144 void
145dfilter_load_field_references(const dfilter_t *df, proto_tree *tree);
146
147/* Refresh references in a compiled display filter. */
148WS_DLL_PUBLIC
149 void
150dfilter_load_field_references_edt(const dfilter_t *df, struct epan_dissect *edt);
151
152/* Check if dfilter has interesting fields */
153 bool
154dfilter_has_interesting_fields(const dfilter_t *df);
155
156/* Check if dfilter is interested in a given field
157 *
158 * @param df The dfilter
159 * @param hfid The header field info ID to check
160 * @return true if the field is interesting to the dfilter
161 */
162 bool
163dfilter_interested_in_field(const dfilter_t *df, int hfid);
164
165/* Check if dfilter is interested in a given protocol
166 *
167 * @param df The dfilter
168 * @param proto_id The protocol ID to check
169 * @return true if the dfilter is interested in a field whose
170 * parent is proto_id
171 */
172 bool
173dfilter_interested_in_proto(const dfilter_t *df, int proto_id);
174
175WS_DLL_PUBLIC
176 bool
177dfilter_requires_columns(const dfilter_t *df);
178
179WS_DLL_PUBLIC
180GPtrArray *
181dfilter_deprecated_tokens(dfilter_t *df);
182
183WS_DLL_PUBLIC
184GSList *
185dfilter_get_warnings(dfilter_t *df);
186
187#define DF_DUMP_REFERENCES (1U << 0)
188#define DF_DUMP_SHOW_FTYPE (1U << 1)
189
190/* Print bytecode of dfilter to fp */
191WS_DLL_PUBLIC
192 void
193dfilter_dump(FILE *fp, dfilter_t *df, uint16_t flags);
194
195/* Text after macro expansion. */
196WS_DLL_PUBLIC
197 const char *
198dfilter_text(dfilter_t *df);
199
200/* Text representation of syntax tree (if it was saved, NULL otherwise). */
201WS_DLL_PUBLIC
202 const char *
203dfilter_syntax_tree(dfilter_t *df);
204
205WS_DLL_PUBLIC
206ftenum_t
207dfilter_get_return_type(dfilter_t *df);
208
209/* Print bytecode of dfilter to log */
210WS_DLL_PUBLIC
211 void
212dfilter_log_full(const char *domain, enum ws_log_level level,
213 const char *file, long line, const char *func,
214 dfilter_t *dfcode, const char *msg);
215
216#ifdef WS_DEBUG
217#define dfilter_log(dfcode, msg) \
218 dfilter_log_full(LOG_DOMAIN_DFILTER, LOG_LEVEL_NOISY, \
219 __FILE__, __LINE__, __func__, \
220 dfcode, msg)
221#else
222#define dfilter_log(dfcode, msg) (void)0
223#endif
224
225#define DFILTER_DEBUG_HERE(dfcode) \
226 dfilter_log_full(LOG_DOMAIN_DFILTER, LOG_LEVEL_ECHO, \
227 __FILE__, __LINE__, __func__, \
228 dfcode, #dfcode);
229
230#ifdef __cplusplus
231}
232#endif /* __cplusplus */
233
234#endif /* DFILTER_H */
dfilter-loc.h
dfilter_get_syntax_tree
WS_DLL_PUBLIC struct stnode * dfilter_get_syntax_tree(const char *text)
Definition dfilter.c:654
proto.h
_dfilter_loc
Definition dfilter-loc.h:16
_proto_node
Definition proto.h:907
df_error_t
Definition dfilter.h:30
epan_dfilter
Definition dfilter-int.h:35
epan_dissect
Definition epan_dissect.h:28
stnode
Definition syntax-tree.h:78