Wireshark  4.3.0
The Wireshark network protocol analyzer
dfilter-int.h
Go to the documentation of this file.
1 
10 #ifndef DFILTER_INT_H
11 #define DFILTER_INT_H
12 
13 #include "dfilter.h"
14 #include "syntax-tree.h"
15 
16 #include <epan/proto.h>
17 #include <stdio.h>
18 
19 typedef struct {
20  const header_field_info *hfinfo;
21  fvalue_t *value;
22  int proto_layer_num;
24 
25 typedef struct {
26  GPtrArray *array;
27 } df_cell_t;
28 
29 typedef struct {
30  GPtrArray *ptr;
31  unsigned idx;
33 
34 /* Passed back to user */
35 struct epan_dfilter {
36  GPtrArray *insns;
37  unsigned num_registers;
38  df_cell_t *registers;
39  int *interesting_fields;
40  int num_interesting_fields;
41  GPtrArray *deprecated;
42  GSList *warnings;
43  char *expanded_text;
44  GHashTable *references;
45  GHashTable *raw_references;
46  char *syntax_tree_str;
47  /* Used to pass arguments to functions. List of Lists (list of registers). */
48  GSList *function_stack;
49  GSList *set_stack;
50 };
51 
52 typedef struct {
53  df_error_t *error;
54  /* more fields. */
55 } dfstate_t;
56 
57 /*
58  * State for first stage of compilation (parsing).
59  */
60 typedef struct {
61  df_error_t *error; /* Must be first struct field. */
62  unsigned flags;
63  stnode_t *st_root;
64  GPtrArray *deprecated;
65  stnode_t *lval;
66  GString *quoted_string;
67  bool raw_string;
68  df_loc_t string_loc;
69  df_loc_t location;
70 } dfsyntax_t;
71 
72 /*
73  * State for second stage of compilation (semantic check and code generation).
74  */
75 typedef struct {
76  df_error_t *error; /* Must be first struct field. */
77  unsigned flags;
78  stnode_t *st_root;
79  unsigned field_count;
80  GPtrArray *insns;
81  GHashTable *loaded_fields;
82  GHashTable *loaded_raw_fields;
83  GHashTable *interesting_fields;
84  int next_insn_id;
85  int next_register;
86  GPtrArray *deprecated;
87  GHashTable *references; /* hfinfo -> pointer to array of references */
88  GHashTable *raw_references; /* hfinfo -> pointer to array of references */
89  char *expanded_text;
90  wmem_allocator_t *dfw_scope; /* Because we use exceptions for error handling sometimes
91  cleaning up memory allocations is inconvenient. Memory
92  allocated from this pool will be freed when the dfwork_t
93  context is destroyed. */
94  GSList *warnings;
95 } dfwork_t;
96 
97 /* Constructor/Destructor prototypes for Lemon Parser */
98 void *DfilterAlloc(void *(*)(size_t));
99 
100 void DfilterFree(void *, void (*)(void *));
101 
102 void Dfilter(void *, int, stnode_t *, dfsyntax_t *);
103 
104 /* Return value for error in scanner. */
105 #define SCAN_FAILED -1 /* not 0, as that means end-of-input */
106 
107 WS_DLL_PUBLIC
108 void
109 dfilter_vfail(void *state, int code, df_loc_t err_loc,
110  const char *format, va_list args);
111 
112 WS_DLL_PUBLIC
113 void
114 dfilter_fail(void *state, int code, df_loc_t err_loc,
115  const char *format, ...) G_GNUC_PRINTF(4, 5);
116 
117 WS_DLL_PUBLIC WS_NORETURN
118 void
119 dfilter_fail_throw(void *state, int code, df_loc_t err_loc,
120  const char *format, ...) G_GNUC_PRINTF(4, 5);
121 
122 void
123 dfw_set_error_location(dfwork_t *dfw, df_loc_t err_loc);
124 
125 void
126 add_deprecated_token(GPtrArray *deprecated, const char *token);
127 
128 void
129 add_compile_warning(dfwork_t *dfw, const char *format, ...);
130 
131 void
132 free_deprecated(GPtrArray *deprecated);
133 
134 void
135 DfilterTrace(FILE *TraceFILE, char *zTracePrompt);
136 
138 dfilter_resolve_unparsed(const char *name, GPtrArray *deprecated);
139 
140 /* Returns true if the create syntax node has a (value) string type. */
141 bool
142 dfilter_fvalue_from_literal(dfwork_t *dfw, ftenum_t ftype, stnode_t *st,
143  bool allow_partial_value, header_field_info *hfinfo_value_string);
144 
145 /* Returns true if the create syntax node has a (value) string type. */
146 bool
147 dfilter_fvalue_from_string(dfwork_t *dfw, ftenum_t ftype, stnode_t *st,
148  header_field_info *hfinfo_value_string);
149 
150 void
151 dfilter_fvalue_from_charconst(dfwork_t *dfw, ftenum_t ftype, stnode_t *st);
152 
153 void
154 dfilter_fvalue_from_number(dfwork_t *dfw, ftenum_t ftype, stnode_t *st);
155 
156 const char *tokenstr(int token);
157 
159 reference_new(const field_info *finfo, bool raw);
160 
161 void
162 reference_free(df_reference_t *ref);
163 
164 WS_DLL_PUBLIC
165 void
166 df_cell_append(df_cell_t *rp, fvalue_t *fv);
167 
168 WS_DLL_PUBLIC
169 GPtrArray *
170 df_cell_ref(df_cell_t *rp);
171 
172 #define df_cell_ptr(rp) ((rp)->array)
173 
174 WS_DLL_PUBLIC
175 size_t
176 df_cell_size(const df_cell_t *rp);
177 
178 WS_DLL_PUBLIC
179 fvalue_t **
180 df_cell_array(const df_cell_t *rp);
181 
182 WS_DLL_PUBLIC
183 bool
184 df_cell_is_empty(const df_cell_t *rp);
185 
186 WS_DLL_PUBLIC
187 bool
188 df_cell_is_null(const df_cell_t *rp);
189 
190 /* Pass true to free the array contents when the cell is cleared. */
191 WS_DLL_PUBLIC
192 void
193 df_cell_init(df_cell_t *rp, bool free_seg);
194 
195 WS_DLL_PUBLIC
196 void
197 df_cell_clear(df_cell_t *rp);
198 
199 /* Cell must not be cleared while iter is alive. */
200 WS_DLL_PUBLIC
201 void
202 df_cell_iter_init(df_cell_t *rp, df_cell_iter_t *iter);
203 
204 WS_DLL_PUBLIC
205 fvalue_t *
206 df_cell_iter_next(df_cell_iter_t *iter);
207 
208 
209 #endif
Definition: dfilter-loc.h:16
Definition: ftypes-int.h:17
Definition: proto.h:769
Definition: wmem_allocator.h:27
Definition: dfilter-int.h:29
Definition: dfilter-int.h:25
Definition: dfilter.h:30
Definition: dfilter-int.h:19
Definition: dfilter-int.h:52
Definition: dfilter-int.h:60
Definition: dfilter-int.h:75
Definition: dfilter-int.h:35
Definition: proto.h:816
Definition: syntax-tree.h:79