3 * Copyright 2004, Luis E. Garcia Ontanon <luis@ontanon.org>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "epan/proto.h"
30 #include <sys/types.h>
36 /* #define _AVP_DEBUGGING */
39 /******* dbg_print *********/
40 #define DEBUG_BUFFER_SIZE 4096
41 extern void dbg_print(const gint
* which
, gint how
, FILE* where
, const gchar
* fmt
, ... );
44 /******* single copy strings *********/
45 typedef struct _scs_collection SCS_collection
;
47 #define SCS_SMALL_SIZE 16
48 #define SCS_MEDIUM_SIZE 256
49 #define SCS_LARGE_SIZE 4096
50 #define SCS_HUGE_SIZE 65536
52 extern gchar
* scs_subscribe(SCS_collection
* collection
, const gchar
* s
);
53 extern void scs_unsubscribe(SCS_collection
* collection
, gchar
* s
);
54 extern gchar
* scs_subscribe_printf(SCS_collection
* collection
, gchar
* fmt
, ...);
56 /******* AVPs & Co. *********/
58 /* these are the defined oreators of avps */
59 #define AVP_OP_EQUAL '='
60 #define AVP_OP_NOTEQUAL '!'
61 #define AVP_OP_STARTS '^'
62 #define AVP_OP_ENDS '$'
63 #define AVP_OP_CONTAINS '~'
64 #define AVP_OP_LOWER '<'
65 #define AVP_OP_HIGHER '>'
66 #define AVP_OP_EXISTS '?'
67 #define AVP_OP_ONEOFF '|'
68 #define AVP_OP_TRANSF '&'
71 /* an avp is an object made of a name a value and an operator */
78 /* avp nodes are used in avp lists */
79 typedef struct _avp_node
{
81 struct _avp_node
* next
;
82 struct _avp_node
* prev
;
85 /* an avp list is a sorted set of avps */
86 typedef struct _avp_list
{
94 /* an avpl transformation operation */
95 typedef enum _avpl_match_mode
{
102 typedef enum _avpl_replace_mode
{
108 typedef struct _avpl_transf AVPL_Transf
;
110 struct _avpl_transf
{
116 avpl_match_mode match_mode
;
117 avpl_replace_mode replace_mode
;
123 /* loalnodes are used in LoALs */
124 typedef struct _loal_node
{
126 struct _loal_node
*next
;
127 struct _loal_node
*prev
;
131 /* a loal is a list of avp lists */
132 typedef struct _loal
{
139 /* avp library (re)initialization */
140 extern void avp_init(void);
142 /* If enabled set's up the debug facilities for the avp library */
143 #ifdef _AVP_DEBUGGING
144 extern void setup_avp_debug(FILE* fp
, int* general
, int* avp
, int* avp_op
, int* avpl
, int* avpl_op
);
145 #endif /* _AVP_DEBUGGING */
151 /* creates a new avp */
152 extern AVP
* new_avp(const gchar
* name
, const gchar
* value
, gchar op
);
154 /* creates a copy od an avp */
155 extern AVP
* avp_copy(AVP
* from
);
157 /* creates an avp from a field_info record */
158 extern AVP
* new_avp_from_finfo(const gchar
* name
, field_info
* finfo
);
163 extern void delete_avp(AVP
* avp
);
168 /* returns a newly allocated string containing a representation of the avp */
169 #define avp_to_str(avp) (g_strdup_printf("%s%c%s",avp->n,avp->o,avp->v))
171 /* returns the src avp if the src avp matches(*) the op avp or NULL if it doesn't */
172 extern AVP
* match_avp(AVP
* src
, AVP
* op
);
176 * avplist constructors
179 /* creates an empty avp list */
180 extern AVPL
* new_avpl(const gchar
* name
);
183 /* creates a copy of an avp list */
184 extern AVPL
* new_avpl_from_avpl(const gchar
* name
, AVPL
* avpl
, gboolean copy_avps
);
186 /* creates an avp list containing any avps in src matching any avps in op
187 it will eventually create an empty list in none match */
188 extern AVPL
* new_avpl_loose_match(const gchar
* name
,AVPL
* src
, AVPL
* op
, gboolean copy_avps
);
190 /* creates an avp list containing any avps in src matching every avp in op
191 it will not create a list if there is not a match for every attribute in op */
192 extern AVPL
* new_avpl_every_match(const gchar
* name
,AVPL
* src
, AVPL
* op
, gboolean copy_avps
);
194 /* creates an avp list containing every avp in src matching every avp in op
195 it will not create a list unless every avp in op is matched only once to avery avp in op */
196 extern AVPL
* new_avpl_exact_match(const gchar
* name
,AVPL
* src
, AVPL
* op
, gboolean copy_avps
);
198 /* uses mode to call one of the former matches. NO_MATCH = merge(merge(copy(src),op)) */
199 extern AVPL
* new_avpl_from_match(avpl_match_mode mode
, const gchar
* name
,AVPL
* src
, AVPL
* op
, gboolean copy_avps
);
206 /* it will insert an avp to an avpl */
207 extern gboolean
insert_avp(AVPL
* avpl
, AVP
* avp
);
209 /* renames an avpl */
210 extern void rename_avpl(AVPL
* avpl
, gchar
* name
);
212 /* it will add all the avps in src which don't match(*) any attribute in dest */
213 extern void merge_avpl(AVPL
* dest
, AVPL
* src
, gboolean copy
);
215 /* it will return the first avp in an avpl whose name matches the given name.
216 will return NULL if there is not anyone matching */
217 extern AVP
* get_avp_by_name(AVPL
* avpl
, gchar
* name
, void** cookie
);
219 /* it will get the next avp from an avpl, using cookie to keep state */
220 extern AVP
* get_next_avp(AVPL
* avpl
, void** cookie
);
222 /* it will extract the first avp from an avp list */
223 extern AVP
* extract_first_avp(AVPL
* avpl
);
225 /* it will extract the last avp from an avp list */
226 extern AVP
* extract_last_avp(AVPL
* avpl
);
228 /* it will extract the first avp in an avpl whose name matches the given name.
229 it will not extract any and return NULL if there is not anyone matching */
230 extern AVP
* extract_avp_by_name(AVPL
* avpl
, gchar
* name
);
232 /* returns a newly allocated string containing a representation of the avp list */
233 extern gchar
* avpl_to_str(AVPL
* avpl
);
234 extern gchar
* avpl_to_dotstr(AVPL
*);
236 /* deletes an avp list and eventually its contents */
237 extern void delete_avpl(AVPL
* avpl
, gboolean avps_too
);
240 * AVPL transformations
242 extern void delete_avpl_transform(AVPL_Transf
* it
);
243 extern void avpl_transform(AVPL
* src
, AVPL_Transf
* op
);
250 /* creates an empty list of avp lists */
251 extern LoAL
* new_loal(const gchar
* name
);
253 /* given a file loads all the avpls contained in it
254 every line is formatted as it is the output of avplist_to_string */
255 extern LoAL
* loal_from_file(gchar
* filename
);
257 /* inserts an avplist into a LoAL */
258 extern void loal_append(LoAL
* loal
, AVPL
* avpl
);
260 /* extracts the first avp list from the loal */
261 extern AVPL
* extract_first_avpl(LoAL
* loal
);
263 /* extracts the last avp list from the loal */
264 extern AVPL
* extract_last_avpl(LoAL
* loal
);
266 /* it will get the next avp list from a LoAL, using cookie to keep state */
267 extern AVPL
* get_next_avpl(LoAL
* loal
,void** cookie
);
269 /* deletes a loal and eventually its contents */
270 extern void delete_loal(LoAL
* loal
, gboolean avpls_too
, gboolean avps_too
);