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 void
108 dfilter_vfail(void *state, int code, df_loc_t err_loc,
109  const char *format, va_list args);
110 
111 void
112 dfilter_fail(void *state, int code, df_loc_t err_loc,
113  const char *format, ...) G_GNUC_PRINTF(4, 5);
114 
115 WS_NORETURN
116 void
117 dfilter_fail_throw(void *state, int code, df_loc_t err_loc,
118  const char *format, ...) G_GNUC_PRINTF(4, 5);
119 
120 void
121 dfw_set_error_location(dfwork_t *dfw, df_loc_t err_loc);
122 
123 void
124 add_deprecated_token(dfsyntax_t *dfs, const char *token);
125 
126 void
127 add_compile_warning(dfwork_t *dfw, const char *format, ...);
128 
129 void
130 free_deprecated(GPtrArray *deprecated);
131 
132 void
133 DfilterTrace(FILE *TraceFILE, char *zTracePrompt);
134 
136 dfilter_resolve_unparsed(dfsyntax_t *dfs, const char *name);
137 
138 /* Returns true if the create syntax node has a (value) string type. */
139 bool
140 dfilter_fvalue_from_literal(dfwork_t *dfw, ftenum_t ftype, stnode_t *st,
141  bool allow_partial_value, header_field_info *hfinfo_value_string);
142 
143 /* Returns true if the create syntax node has a (value) string type. */
144 bool
145 dfilter_fvalue_from_string(dfwork_t *dfw, ftenum_t ftype, stnode_t *st,
146  header_field_info *hfinfo_value_string);
147 
148 void
149 dfilter_fvalue_from_charconst(dfwork_t *dfw, ftenum_t ftype, stnode_t *st);
150 
151 const char *tokenstr(int token);
152 
154 reference_new(const field_info *finfo, bool raw);
155 
156 void
157 reference_free(df_reference_t *ref);
158 
159 void
160 df_cell_append(df_cell_t *rp, fvalue_t *fv);
161 
162 GPtrArray *
163 df_cell_ref(df_cell_t *rp);
164 
165 #define df_cell_ptr(rp) ((rp)->array)
166 
167 size_t
168 df_cell_size(const df_cell_t *rp);
169 
170 fvalue_t **
171 df_cell_array(const df_cell_t *rp);
172 
173 bool
174 df_cell_is_empty(const df_cell_t *rp);
175 
176 bool
177 df_cell_is_null(const df_cell_t *rp);
178 
179 /* Pass true to free the array contents when the cell is cleared. */
180 void
181 df_cell_init(df_cell_t *rp, bool free_seg);
182 
183 void
184 df_cell_clear(df_cell_t *rp);
185 
186 /* Cell must not be cleared while iter is alive. */
187 void
188 df_cell_iter_init(df_cell_t *rp, df_cell_iter_t *iter);
189 
190 fvalue_t *
191 df_cell_iter_next(df_cell_iter_t *iter);
192 
193 
194 #endif
Definition: dfilter-loc.h:16
Definition: ftypes-int.h:17
Definition: proto.h:762
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:809
Definition: syntax-tree.h:62