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