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