Wireshark 4.5.0
The Wireshark network protocol analyzer
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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
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_HUGE_SIZE 65535
31
32extern char* scs_subscribe(SCS_collection* collection, const char* s);
33extern void scs_unsubscribe(SCS_collection* collection, char* s);
34extern 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 oreators 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 */
53typedef struct _avp {
54 char* n;
55 char* v;
56 char o;
57} AVP;
58
59/* avp nodes are used in avp lists */
60typedef 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 */
67typedef struct _avp_list {
68 char* name;
69 uint32_t len;
70 AVPN null;
71} AVPL;
72
73
74
75/* an avpl transformation operation */
76typedef enum _avpl_match_mode {
77 AVPL_NO_MATCH,
78 AVPL_STRICT,
79 AVPL_LOOSE,
80 AVPL_EVERY
81} avpl_match_mode;
82
83typedef enum _avpl_replace_mode {
84 AVPL_NO_REPLACE,
85 AVPL_INSERT,
86 AVPL_REPLACE
87} avpl_replace_mode;
88
89typedef struct _avpl_transf AVPL_Transf;
90
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 */
105typedef 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 */
113typedef struct _loal {
114 char* name;
115 unsigned len;
116 LoALnode null;
117} LoAL;
118
119
120/* avp library (re)initialization */
121extern void avp_init(void);
122
123/* If enabled set's up the debug facilities for the avp library */
124#ifdef _AVP_DEBUGGING
125extern 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 */
133extern AVP* new_avp(const char* name, const char* value, char op);
134
135/* creates a copy od an avp */
136extern AVP* avp_copy(AVP* from);
137
138/* creates an avp from a field_info record */
139extern AVP* new_avp_from_finfo(const char* name, field_info* finfo);
140
141/*
142 * avp destructor
143 */
144extern 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 */
153extern AVP* match_avp(AVP* src, AVP* op);
154
155
156/*
157 * avplist constructors
158 */
159
160/* creates an empty avp list */
161extern AVPL* new_avpl(const char* name);
162
163
164/* creates a copy of an avp list */
165extern AVPL* new_avpl_from_avpl(const char* name, AVPL* avpl, bool copy_avps);
166
167extern AVPL* new_avpl_loose_match(const char* name, AVPL* src, AVPL* op, bool copy_avps);
168
169extern 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)) */
172extern 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 */
180extern bool insert_avp(AVPL* avpl, AVP* avp);
181
182/* renames an avpl */
183extern 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 */
186extern 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 */
190extern 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 */
193extern AVP* get_next_avp(AVPL* avpl, void** cookie);
194
195/* it will extract the first avp from an avp list */
196extern AVP* extract_first_avp(AVPL* avpl);
197
198/* it will extract the last avp from an avp list */
199extern 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 */
203extern AVP* extract_avp_by_name(AVPL* avpl, char* name);
204
205/* returns a newly allocated string containing a representation of the avp list */
206extern char* avpl_to_str(AVPL* avpl);
207extern char* avpl_to_dotstr(AVPL*);
208
209/* deletes an avp list and eventually its contents */
210extern void delete_avpl(AVPL* avpl, bool avps_too);
211
212/*
213 * AVPL transformations
214 */
215extern void delete_avpl_transform(AVPL_Transf* it);
216extern 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 */
224extern 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 */
228extern LoAL* loal_from_file(char* filename);
229
230/* inserts an avplist into a LoAL */
231extern void loal_append(LoAL* loal, AVPL* avpl);
232
233/* extracts the first avp list from the loal */
234extern AVPL* extract_first_avpl(LoAL* loal);
235
236/* extracts the last avp list from the loal */
237extern AVPL* extract_last_avpl(LoAL* loal);
238
239/* it will get the next avp list from a LoAL, using cookie to keep state */
240extern AVPL* get_next_avpl(LoAL* loal,void** cookie);
241
242/* deletes a loal and eventually its contents */
243extern void delete_loal(LoAL* loal, bool avpls_too, bool avps_too);
244
245
246#endif
Definition mate_util.h:67
Definition mate_util.h:60
Definition mate_util.h:53
Definition mate_util.h:91
Definition mate_util.h:105
Definition mate_util.h:113
Definition mate_util.c:71
Definition proto.h:816