3 * Copyright 2004, Luis E. Garcia Ontanon <luis@ontanon.org>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include "epan/proto.h"
16 #include <sys/types.h>
18 /* #define _AVP_DEBUGGING */
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);
27 /******* single copy strings *********/
28 typedef struct _scs_collection SCS_collection
;
30 #define SCS_SMALL_SIZE 16
31 #define SCS_MEDIUM_SIZE 256
32 #define SCS_LARGE_SIZE 4096
33 #define SCS_HUGE_SIZE 65536
35 extern char* scs_subscribe(SCS_collection
* collection
, const char* s
);
36 extern void scs_unsubscribe(SCS_collection
* collection
, char* s
);
37 extern char* scs_subscribe_printf(SCS_collection
* collection
, char* fmt
, ...)
40 /******* AVPs & Co. *********/
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 '&'
55 /* an avp is an object made of a name a value and an operator */
62 /* avp nodes are used in avp lists */
63 typedef struct _avp_node
{
65 struct _avp_node
* next
;
66 struct _avp_node
* prev
;
69 /* an avp list is a sorted set of avps */
70 typedef struct _avp_list
{
78 /* an avpl transformation operation */
79 typedef enum _avpl_match_mode
{
86 typedef enum _avpl_replace_mode
{
92 typedef struct _avpl_transf AVPL_Transf
;
100 avpl_match_mode match_mode
;
101 avpl_replace_mode replace_mode
;
107 /* loalnodes are used in LoALs */
108 typedef struct _loal_node
{
110 struct _loal_node
*next
;
111 struct _loal_node
*prev
;
115 /* a loal is a list of avp lists */
116 typedef struct _loal
{
123 /* avp library (re)initialization */
124 extern void avp_init(void);
126 /* If enabled set's up the debug facilities for the avp library */
127 #ifdef _AVP_DEBUGGING
128 extern void setup_avp_debug(FILE* fp
, int* general
, int* avp
, int* avp_op
, int* avpl
, int* avpl_op
);
129 #endif /* _AVP_DEBUGGING */
135 /* creates a new avp */
136 extern AVP
* new_avp(const char* name
, const char* value
, char op
);
138 /* creates a copy od an avp */
139 extern AVP
* avp_copy(AVP
* from
);
141 /* creates an avp from a field_info record */
142 extern AVP
* new_avp_from_finfo(const char* name
, field_info
* finfo
);
147 extern void delete_avp(AVP
* avp
);
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))
155 /* returns the src avp if the src avp matches(*) the op avp or NULL if it doesn't */
156 extern AVP
* match_avp(AVP
* src
, AVP
* op
);
160 * avplist constructors
163 /* creates an empty avp list */
164 extern AVPL
* new_avpl(const char* name
);
167 /* creates a copy of an avp list */
168 extern AVPL
* new_avpl_from_avpl(const char* name
, AVPL
* avpl
, bool copy_avps
);
170 extern AVPL
* new_avpl_loose_match(const char* name
, AVPL
* src
, AVPL
* op
, bool copy_avps
);
172 extern AVPL
* new_avpl_pairs_match(const char* name
, AVPL
* src
, AVPL
* op
, bool strict
, bool copy_avps
);
174 /* uses mode to call one of the former matches. NO_MATCH = merge(merge(copy(src),op)) */
175 extern AVPL
* new_avpl_from_match(avpl_match_mode mode
, const char* name
,AVPL
* src
, AVPL
* op
, bool copy_avps
);
182 /* it will insert an avp to an avpl */
183 extern bool insert_avp(AVPL
* avpl
, AVP
* avp
);
185 /* renames an avpl */
186 extern void rename_avpl(AVPL
* avpl
, char* name
);
188 /* it will add all the avps in src which don't match(*) any attribute in dest */
189 extern void merge_avpl(AVPL
* dest
, AVPL
* src
, bool copy
);
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 */
193 extern AVP
* get_avp_by_name(AVPL
* avpl
, char* name
, void** cookie
);
195 /* it will get the next avp from an avpl, using cookie to keep state */
196 extern AVP
* get_next_avp(AVPL
* avpl
, void** cookie
);
198 /* it will extract the first avp from an avp list */
199 extern AVP
* extract_first_avp(AVPL
* avpl
);
201 /* it will extract the last avp from an avp list */
202 extern AVP
* extract_last_avp(AVPL
* avpl
);
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 */
206 extern AVP
* extract_avp_by_name(AVPL
* avpl
, char* name
);
208 /* returns a newly allocated string containing a representation of the avp list */
209 extern char* avpl_to_str(AVPL
* avpl
);
210 extern char* avpl_to_dotstr(AVPL
*);
212 /* deletes an avp list and eventually its contents */
213 extern void delete_avpl(AVPL
* avpl
, bool avps_too
);
216 * AVPL transformations
218 extern void delete_avpl_transform(AVPL_Transf
* it
);
219 extern void avpl_transform(AVPL
* src
, AVPL_Transf
* op
);
226 /* creates an empty list of avp lists */
227 extern LoAL
* new_loal(const char* name
);
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 */
231 extern LoAL
* loal_from_file(char* filename
);
233 /* inserts an avplist into a LoAL */
234 extern void loal_append(LoAL
* loal
, AVPL
* avpl
);
236 /* extracts the first avp list from the loal */
237 extern AVPL
* extract_first_avpl(LoAL
* loal
);
239 /* extracts the last avp list from the loal */
240 extern AVPL
* extract_last_avpl(LoAL
* loal
);
242 /* it will get the next avp list from a LoAL, using cookie to keep state */
243 extern AVPL
* get_next_avpl(LoAL
* loal
,void** cookie
);
245 /* deletes a loal and eventually its contents */
246 extern void delete_loal(LoAL
* loal
, bool avpls_too
, bool avps_too
);