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