| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
mate_util.h
1/* mate_util.h
2 *
3 * Copyright 2004, Luis E. Garcia Ontanon <luis@ontanon.org>
4 *
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
8 *
9 * SPDX-License-Identifier: GPL-2.0-or-later
10 */
11
12
13#ifndef __AVP_H_
14#define __AVP_H_
15#include "epan/proto.h"
16#include <sys/types.h>
17
18/* #define _AVP_DEBUGGING */
19
20
21/******* dbg_print *********/
22#define DEBUG_BUFFER_SIZE 4096
23 extern void dbg_print(const int* which, int how, FILE* where,
24 const char* fmt, ... ) G_GNUC_PRINTF(4, 5);
25
26
27/******* single copy strings *********/
28typedef struct _scs_collection SCS_collection;
29
30#define SCS_HUGE_SIZE 65535
31
32 extern char* scs_subscribe(SCS_collection* collection, const char* s);
33 extern void scs_unsubscribe(SCS_collection* collection, char* s);
34 extern char* scs_subscribe_printf(SCS_collection* collection, char* fmt, ...)
35 G_GNUC_PRINTF(2, 3);
36
37/******* AVPs & Co. *********/
38
39/* these are the defined operators of avps */
40#define AVP_OP_EQUAL '='
41#define AVP_OP_NOTEQUAL '!'
42#define AVP_OP_STARTS '^'
43#define AVP_OP_ENDS '$'
44#define AVP_OP_CONTAINS '~'
45#define AVP_OP_LOWER '<'
46#define AVP_OP_HIGHER '>'
47#define AVP_OP_EXISTS '?'
48#define AVP_OP_ONEOFF '|'
49#define AVP_OP_TRANSF '&'
50
51
52/* an avp is an object made of a name a value and an operator */
53 typedef struct _avp {
54 char* n;
55 char* v;
56 char o;
57} AVP;
58
59/* avp nodes are used in avp lists */
60 typedef struct _avp_node {
61 AVP* avp;
62 struct _avp_node* next;
63 struct _avp_node* prev;
64} AVPN;
65
66/* an avp list is a sorted set of avps */
67 typedef struct _avp_list {
68 char* name;
69 uint32_t len;
70 AVPN null;
71} AVPL;
72
73
74
75/* an avpl transformation operation */
76 typedef enum _avpl_match_mode {
77 AVPL_NO_MATCH,
78 AVPL_STRICT,
79 AVPL_LOOSE,
80 AVPL_EVERY
81} avpl_match_mode;
82
83 typedef enum _avpl_replace_mode {
84 AVPL_NO_REPLACE,
85 AVPL_INSERT,
86 AVPL_REPLACE
87} avpl_replace_mode;
88
89 typedef struct _avpl_transf AVPL_Transf;
90
91 struct _avpl_transf {
92 char* name;
93
94 AVPL* match;
95 AVPL* replace;
96
97 avpl_match_mode match_mode;
98 avpl_replace_mode replace_mode;
99
100 GHashTable* map;
101 AVPL_Transf* next;
102};
103
104/* loalnodes are used in LoALs */
105 typedef struct _loal_node {
106 AVPL* avpl;
107 struct _loal_node *next;
108 struct _loal_node *prev;
109} LoALnode;
110
111
112/* a loal is a list of avp lists */
113 typedef struct _loal {
114 char* name;
115 unsigned len;
116 LoALnode null;
117} LoAL;
118
119
120/* avp library (re)initialization */
121 extern void avp_init(void);
122
123/* If enabled set's up the debug facilities for the avp library */
124#ifdef _AVP_DEBUGGING
125 extern void setup_avp_debug(FILE* fp, int* general, int* avp, int* avp_op, int* avpl, int* avpl_op);
126#endif /* _AVP_DEBUGGING */
127
128/*
129 * avp constructors
130 */
131
132/* creates a new avp */
133 extern AVP* new_avp(const char* name, const char* value, char op);
134
135/* creates a copy od an avp */
136 extern AVP* avp_copy(AVP* from);
137
138/* creates an avp from a field_info record */
139 extern AVP* new_avp_from_finfo(const char* name, field_info* finfo);
140
141/*
142 * avp destructor
143 */
144 extern void delete_avp(AVP* avp);
145
146/*
147 * avp methods
148 */
149/* returns a newly allocated string containing a representation of the avp */
150#define avp_to_str(avp) (ws_strdup_printf("%s%c%s",avp->n,avp->o,avp->v))
151
152/* returns the src avp if the src avp matches(*) the op avp or NULL if it doesn't */
153 extern AVP* match_avp(AVP* src, AVP* op);
154
155
156/*
157 * avplist constructors
158 */
159
160/* creates an empty avp list */
161 extern AVPL* new_avpl(const char* name);
162
163
164/* creates a copy of an avp list */
165 extern AVPL* new_avpl_from_avpl(const char* name, AVPL* avpl, bool copy_avps);
166
167 extern AVPL* new_avpl_loose_match(const char* name, AVPL* src, AVPL* op, bool copy_avps);
168
169 extern AVPL* new_avpl_pairs_match(const char* name, AVPL* src, AVPL* op, bool strict, bool copy_avps);
170
171/* uses mode to call one of the former matches. NO_MATCH = merge(merge(copy(src),op)) */
172 extern AVPL* new_avpl_from_match(avpl_match_mode mode, const char* name,AVPL* src, AVPL* op, bool copy_avps);
173
174
175/*
176 * functions on avpls
177 */
178
179/* it will insert an avp to an avpl */
180 extern bool insert_avp(AVPL* avpl, AVP* avp);
181
182/* renames an avpl */
183 extern void rename_avpl(AVPL* avpl, char* name);
184
185/* it will add all the avps in src which don't match(*) any attribute in dest */
186 extern void merge_avpl(AVPL* dest, AVPL* src, bool copy);
187
188/* it will return the first avp in an avpl whose name matches the given name.
189 will return NULL if there is not anyone matching */
190 extern AVP* get_avp_by_name(AVPL* avpl, char* name, void** cookie);
191
192/* it will get the next avp from an avpl, using cookie to keep state */
193 extern AVP* get_next_avp(AVPL* avpl, void** cookie);
194
195/* it will extract the first avp from an avp list */
196 extern AVP* extract_first_avp(AVPL* avpl);
197
198/* it will extract the last avp from an avp list */
199 extern AVP* extract_last_avp(AVPL* avpl);
200
201/* it will extract the first avp in an avpl whose name matches the given name.
202 it will not extract any and return NULL if there is not anyone matching */
203 extern AVP* extract_avp_by_name(AVPL* avpl, char* name);
204
205/* returns a newly allocated string containing a representation of the avp list */
206 extern char* avpl_to_str(AVPL* avpl);
207 extern char* avpl_to_dotstr(AVPL*);
208
209/* deletes an avp list and eventually its contents */
210 extern void delete_avpl(AVPL* avpl, bool avps_too);
211
212/*
213 * AVPL transformations
214 */
215 extern void delete_avpl_transform(AVPL_Transf* it);
216 extern void avpl_transform(AVPL* src, AVPL_Transf* op);
217
218
219/*
220 * Lists of AVP lists
221 */
222
223/* creates an empty list of avp lists */
224 extern LoAL* new_loal(const char* name);
225
226/* given a file loads all the avpls contained in it
227 every line is formatted as it is the output of avplist_to_string */
228 extern LoAL* loal_from_file(char* filename);
229
230/* inserts an avplist into a LoAL */
231 extern void loal_append(LoAL* loal, AVPL* avpl);
232
233/* extracts the first avp list from the loal */
234 extern AVPL* extract_first_avpl(LoAL* loal);
235
236/* extracts the last avp list from the loal */
237 extern AVPL* extract_last_avpl(LoAL* loal);
238
239/* it will get the next avp list from a LoAL, using cookie to keep state */
240 extern AVPL* get_next_avpl(LoAL* loal,void** cookie);
241
242/* deletes a loal and eventually its contents */
243 extern void delete_loal(LoAL* loal, bool avpls_too, bool avps_too);
244
245
246#endif
proto.h
_avp_list
Definition mate_util.h:67
_avp_node
Definition mate_util.h:60
_avp
Definition mate_util.h:53
_avpl_transf
Definition mate_util.h:91
_loal_node
Definition mate_util.h:105
_loal
Definition mate_util.h:113
_scs_collection
Definition mate_util.c:71
field_info
Definition proto.h:816