Mercurial > hg > freeDiameter
annotate libfdproto/dictionary.c @ 1093:44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Mon, 06 May 2013 16:33:22 +0800 |
parents | 7d7266115a34 |
children | 79dd22145f52 |
rev | line source |
---|---|
0 | 1 /********************************************************************************************************* |
2 * Software License Agreement (BSD License) * | |
740
4a9f08d6b6ba
Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * |
0 | 4 * * |
928
5053f1abcf5d
Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents:
910
diff
changeset
|
5 * Copyright (c) 2013, WIDE Project and NICT * |
0 | 6 * All rights reserved. * |
7 * * | |
8 * Redistribution and use of this software in source and binary forms, with or without modification, are * | |
9 * permitted provided that the following conditions are met: * | |
10 * * | |
11 * * Redistributions of source code must retain the above * | |
12 * copyright notice, this list of conditions and the * | |
13 * following disclaimer. * | |
14 * * | |
15 * * Redistributions in binary form must reproduce the above * | |
16 * copyright notice, this list of conditions and the * | |
17 * following disclaimer in the documentation and/or other * | |
18 * materials provided with the distribution. * | |
19 * * | |
20 * * Neither the name of the WIDE Project or NICT nor the * | |
21 * names of its contributors may be used to endorse or * | |
22 * promote products derived from this software without * | |
23 * specific prior written permission of WIDE Project and * | |
24 * NICT. * | |
25 * * | |
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * | |
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * | |
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * | |
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * | |
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * | |
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * | |
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * | |
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * | |
34 *********************************************************************************************************/ | |
35 | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
36 #include "fdproto-internal.h" |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
979
diff
changeset
|
37 #include <inttypes.h> |
0 | 38 |
39 /* Names of the base types */ | |
40 const char * type_base_name[] = { /* must keep in sync with dict_avp_basetype */ | |
41 "GROUPED", /* AVP_TYPE_GROUPED */ | |
42 "OCTETSTRING", /* AVP_TYPE_OCTETSTRING */ | |
43 "INTEGER32", /* AVP_TYPE_INTEGER32 */ | |
44 "INTEGER64", /* AVP_TYPE_INTEGER64 */ | |
45 "UNSIGNED32", /* AVP_TYPE_UNSIGNED32 */ | |
46 "UNSIGNED64", /* AVP_TYPE_UNSIGNED64 */ | |
47 "FLOAT32", /* AVP_TYPE_FLOAT32 */ | |
48 "FLOAT64" /* AVP_TYPE_FLOAT64 */ | |
49 }; | |
50 | |
51 /* The number of lists in an object */ | |
52 #define NB_LISTS_PER_OBJ 3 | |
53 | |
54 /* Some eye catchers definitions */ | |
55 #define OBJECT_EYECATCHER (0x0b13c7) | |
56 #define DICT_EYECATCHER (0x00d1c7) | |
57 | |
58 /* Definition of the dictionary objects */ | |
59 struct dict_object { | |
60 enum dict_object_type type; /* What type of object is this? */ | |
61 int objeyec;/* eyecatcher for this object */ | |
62 int typeyec;/* eyecatcher for this type of object */ | |
63 struct dictionary *dico; /* The dictionary this object belongs to */ | |
64 | |
65 union { | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
66 struct dict_vendor_data vendor; /* datastr_len = strlen(vendor_name) */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
67 struct dict_application_data application; /* datastr_len = strlen(application_name) */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
68 struct dict_type_data type; /* datastr_len = strlen(type_name) */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
69 struct dict_enumval_data enumval; /* datastr_len = strlen(enum_name) */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
70 struct dict_avp_data avp; /* datastr_len = strlen(avp_name) */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
71 struct dict_cmd_data cmd; /* datastr_len = strlen(cmd_name) */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
72 struct dict_rule_data rule; /* datastr_len = 0 */ |
0 | 73 } data; /* The data of this object */ |
74 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
75 size_t datastr_len; /* cached length of the string inside the data. Saved when the object is created. */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
76 |
0 | 77 struct dict_object * parent; /* The parent of this object, if any */ |
78 | |
79 struct fd_list list[NB_LISTS_PER_OBJ];/* used to chain objects.*/ | |
80 /* More information about the lists : | |
81 | |
972 | 82 - the use for each list depends on the type of object. See detail below. |
0 | 83 |
84 - a sentinel for a list has its 'o' field cleared. (this is the criteria to detect end of a loop) | |
85 | |
972 | 86 - The lists are always ordered. The criteria are described below. the functions to order them are referenced in dict_obj_info |
0 | 87 |
88 - The dict_lock must be held for any list operation. | |
89 | |
90 => VENDORS: | |
91 list[0]: list of the vendors, ordered by their id. The sentinel is g_dict_vendors (vendor with id 0) | |
92 list[1]: sentinel for the list of AVPs from this vendor, ordered by AVP code. | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
93 list[2]: sentinel for the list of AVPs from this vendor, ordered by AVP name (fd_os_cmp). |
0 | 94 |
95 => APPLICATIONS: | |
96 list[0]: list of the applications, ordered by their id. The sentinel is g_dict_applications (application with id 0) | |
97 list[1]: not used | |
98 list[2]: not used. | |
99 | |
100 => TYPES: | |
101 list[0]: list of the types, ordered by their names. The sentinel is g_list_types. | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
102 list[1]: sentinel for the type_enum list of this type, ordered by their constant name (fd_os_cmp). |
0 | 103 list[2]: sentinel for the type_enum list of this type, ordered by their constant value. |
104 | |
105 => TYPE_ENUMS: | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
106 list[0]: list of the contants for a given type, ordered by the constant name (fd_os_cmp). Sentinel is a (list[1]) element of a TYPE object. |
0 | 107 list[1]: list of the contants for a given type, ordered by the constant value. Sentinel is a (list[2]) element of a TYPE object. |
108 list[2]: not used | |
109 | |
110 => AVPS: | |
111 list[0]: list of the AVP from a given vendor, ordered by avp code. Sentinel is a list[1] element of a VENDOR object. | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
112 list[1]: list of the AVP from a given vendor, ordered by avp name (fd_os_cmp). Sentinel is a list[2] element of a VENDOR object. |
0 | 113 list[2]: sentinel for the rule list that apply to this AVP. |
114 | |
115 => COMMANDS: | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
116 list[0]: list of the commands, ordered by their names (fd_os_cmp). The sentinel is g_list_cmd_name. |
0 | 117 list[1]: list of the commands, ordered by their command code and 'R' flag. The sentinel is g_list_cmd_code. |
118 list[2]: sentinel for the rule list that apply to this command. | |
119 | |
120 => RULES: | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
121 list[0]: list of the rules for a given (grouped) AVP or Command, ordered by the AVP vendor & code to which they refer. sentinel is list[2] of a command or (grouped) avp. |
0 | 122 list[1]: not used |
123 list[2]: not used. | |
124 | |
125 */ | |
126 | |
127 /* Sentinel for the dispatch callbacks */ | |
128 struct fd_list disp_cbs; | |
129 | |
130 }; | |
131 | |
132 /* Definition of the dictionary structure */ | |
133 struct dictionary { | |
134 int dict_eyec; /* Eye-catcher for the dictionary (DICT_EYECATCHER) */ | |
135 | |
136 pthread_rwlock_t dict_lock; /* The global rwlock for the dictionary */ | |
137 | |
138 struct dict_object dict_vendors; /* Sentinel for the list of vendors, corresponding to vendor 0 */ | |
139 struct dict_object dict_applications; /* Sentinel for the list of applications, corresponding to app 0 */ | |
140 struct fd_list dict_types; /* Sentinel for the list of types */ | |
141 struct fd_list dict_cmd_name; /* Sentinel for the list of commands, ordered by names */ | |
142 struct fd_list dict_cmd_code; /* Sentinel for the list of commands, ordered by codes */ | |
143 | |
144 struct dict_object dict_cmd_error; /* Special command object for answers with the 'E' bit set */ | |
145 | |
446
66f58cecf3cd
Fix invalid array size (found by valgrind)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
146 int dict_count[DICT_TYPE_MAX + 1]; /* Number of objects of each type */ |
0 | 147 }; |
148 | |
149 /* Forward declarations of dump functions */ | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
150 static DECLARE_FD_DUMP_PROTOTYPE(dump_vendor_data, void * data ); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
151 static DECLARE_FD_DUMP_PROTOTYPE(dump_application_data, void * data ); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
152 static DECLARE_FD_DUMP_PROTOTYPE(dump_type_data, void * data ); |
0 | 153 /* the dump function for enum has a different prototype since it need the datatype */ |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
154 static DECLARE_FD_DUMP_PROTOTYPE(dump_avp_data, void * data ); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
155 static DECLARE_FD_DUMP_PROTOTYPE(dump_command_data, void * data ); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
156 static DECLARE_FD_DUMP_PROTOTYPE(dump_rule_data, void * data ); |
0 | 157 |
158 /* Forward declarations of search functions */ | |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
159 static int search_vendor ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ); |
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
160 static int search_application ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ); |
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
161 static int search_type ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ); |
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
162 static int search_enumval ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ); |
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
163 static int search_avp ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ); |
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
164 static int search_cmd ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ); |
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
165 static int search_rule ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ); |
0 | 166 |
167 /* The following array contains lot of data about the different types of objects, for automated handling */ | |
168 static struct { | |
169 enum dict_object_type type; /* information for this type */ | |
170 char * name; /* string describing this object, for debug */ | |
171 size_t datasize; /* The size of the data structure */ | |
172 int parent; /* 0: never; 1: may; 2: must */ | |
173 enum dict_object_type parenttype; /* The type of the parent, when relevant */ | |
174 int eyecatcher; /* A kind of signature for this object */ | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
175 DECLARE_FD_DUMP_PROTOTYPE( (*dump_data), void * data ); /* The function to dump the data section */ |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
176 int (*search_fct)(struct dictionary * dict, int criteria, const void * what, struct dict_object **result );; /* The function to search an object of this type */ |
0 | 177 int haslist[NB_LISTS_PER_OBJ]; /* Tell if this list is used */ |
178 } dict_obj_info[] = { { 0, "(error)", 0, 0, 0, 0, NULL, NULL, {0, 0, 0} } | |
179 | |
180 /* type name datasize parent parenttype | |
181 eyecatcher dump_data search_fct, haslist[] */ | |
182 | |
183 ,{ DICT_VENDOR, "VENDOR", sizeof(struct dict_vendor_data), 0, 0, | |
184 OBJECT_EYECATCHER + 1, dump_vendor_data, search_vendor, { 1, 0, 0 } } | |
185 | |
186 ,{ DICT_APPLICATION, "APPLICATION", sizeof(struct dict_application_data), 1, DICT_VENDOR, | |
187 OBJECT_EYECATCHER + 2, dump_application_data, search_application, { 1, 0, 0 } } | |
188 | |
189 ,{ DICT_TYPE, "TYPE", sizeof(struct dict_type_data), 1, DICT_APPLICATION, | |
190 OBJECT_EYECATCHER + 3, dump_type_data, search_type, { 1, 0, 0 } } | |
191 | |
192 ,{ DICT_ENUMVAL, "ENUMVAL", sizeof(struct dict_enumval_data), 2, DICT_TYPE, | |
193 OBJECT_EYECATCHER + 4, NULL, search_enumval, { 1, 1, 0 } } | |
194 | |
195 ,{ DICT_AVP, "AVP", sizeof(struct dict_avp_data), 1, DICT_TYPE, | |
196 OBJECT_EYECATCHER + 5, dump_avp_data, search_avp, { 1, 1, 0 } } | |
197 | |
198 ,{ DICT_COMMAND, "COMMAND", sizeof(struct dict_cmd_data), 1, DICT_APPLICATION, | |
199 OBJECT_EYECATCHER + 6, dump_command_data, search_cmd, { 1, 1, 0 } } | |
200 | |
201 ,{ DICT_RULE, "RULE", sizeof(struct dict_rule_data), 2, -1 /* special case: grouped avp or command */, | |
202 OBJECT_EYECATCHER + 7, dump_rule_data, search_rule, { 1, 0, 0 } } | |
203 | |
204 }; | |
205 | |
206 /* Macro to verify a "type" value */ | |
207 #define CHECK_TYPE( type ) ( ((type) > 0) && ((type) <= DICT_TYPE_MAX) ) | |
208 | |
209 /* Cast macro */ | |
210 #define _O( object ) ((struct dict_object *) (object)) | |
211 | |
212 /* Get information line for a given object */ | |
213 #define _OBINFO(object) (dict_obj_info[CHECK_TYPE(_O(object)->type) ? _O(object)->type : 0]) | |
214 | |
215 | |
216 | |
217 | |
218 /*******************************************************************************************************/ | |
219 /*******************************************************************************************************/ | |
220 /* */ | |
221 /* Objects management */ | |
222 /* */ | |
223 /*******************************************************************************************************/ | |
224 /*******************************************************************************************************/ | |
225 | |
226 /* Functions to manage the objects creation and destruction. */ | |
227 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
228 /* Duplicate a string inplace, save its length */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
229 #define DUP_string_len( str, plen ) { \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
230 *(plen) = strlen((str)); \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
231 str = os0dup( str, *(plen)); \ |
0 | 232 } |
233 | |
234 /* Initialize an object */ | |
235 static void init_object( struct dict_object * obj, enum dict_object_type type ) | |
236 { | |
237 int i; | |
238 | |
239 TRACE_ENTRY("%p %d", obj, type); | |
240 | |
241 /* Clean the object first */ | |
242 memset ( obj, 0, sizeof(struct dict_object)); | |
243 | |
244 CHECK_PARAMS_DO( CHECK_TYPE(type), return ); | |
245 | |
246 obj->type = type; | |
247 obj->objeyec = OBJECT_EYECATCHER; | |
248 obj->typeyec = _OBINFO(obj).eyecatcher; | |
249 | |
250 /* We don't initialize the data nor the parent here */ | |
251 | |
252 /* Now init the lists */ | |
253 for (i=0; i<NB_LISTS_PER_OBJ; i++) { | |
254 if (_OBINFO(obj).haslist[i] != 0) | |
255 fd_list_init(&obj->list[i], obj); | |
256 else | |
257 fd_list_init(&obj->list[i], NULL); | |
258 } | |
259 | |
260 fd_list_init(&obj->disp_cbs, NULL); | |
261 } | |
262 | |
263 /* Initialize the "data" part of an object */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
264 static int init_object_data(struct dict_object * dest, void * source, enum dict_object_type type) |
0 | 265 { |
266 TRACE_ENTRY("%p %p %d", dest, source, type); | |
267 CHECK_PARAMS( dest && source && CHECK_TYPE(type) ); | |
268 | |
269 /* Generic: copy the full data structure */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
270 memcpy( &dest->data, source, dict_obj_info[type].datasize ); |
0 | 271 |
272 /* Then strings must be duplicated, not copied */ | |
273 /* This function might be simplified by always defining the "name" field as the first field of the structures, but... it's error-prone */ | |
274 switch (type) { | |
275 case DICT_VENDOR: | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
276 DUP_string_len( dest->data.vendor.vendor_name, &dest->datastr_len ); |
0 | 277 break; |
278 | |
279 case DICT_APPLICATION: | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
280 DUP_string_len( dest->data.application.application_name, &dest->datastr_len ); |
0 | 281 break; |
282 | |
283 case DICT_TYPE: | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
284 DUP_string_len( dest->data.type.type_name, &dest->datastr_len ); |
0 | 285 break; |
286 | |
287 case DICT_ENUMVAL: | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
288 DUP_string_len( dest->data.enumval.enum_name, &dest->datastr_len ); |
0 | 289 break; |
290 | |
291 case DICT_AVP: | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
292 DUP_string_len( dest->data.avp.avp_name, &dest->datastr_len ); |
0 | 293 break; |
294 | |
295 case DICT_COMMAND: | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
296 DUP_string_len( dest->data.cmd.cmd_name, &dest->datastr_len ); |
0 | 297 break; |
298 | |
299 default: | |
300 /* Nothing to do for RULES */ | |
301 ; | |
302 } | |
303 | |
304 return 0; | |
305 } | |
306 | |
307 /* Check that an object is valid (1: OK, 0: error) */ | |
308 static int verify_object( struct dict_object * obj ) | |
309 { | |
310 TRACE_ENTRY("%p", obj); | |
311 | |
312 CHECK_PARAMS_DO( obj | |
313 && (obj->objeyec == OBJECT_EYECATCHER) | |
314 && CHECK_TYPE(obj->type) | |
315 && (obj->typeyec == dict_obj_info[obj->type].eyecatcher), | |
316 { | |
317 if (obj) { | |
979 | 318 TRACE_DEBUG(FULL, "Invalid object: %p, obj->objeyec: %x/%x, obj->type: %d, obj->objeyec: %x/%x, obj->typeyec: %x/%x", |
0 | 319 obj, |
320 obj->objeyec, OBJECT_EYECATCHER, | |
321 obj->type, | |
322 obj->objeyec, OBJECT_EYECATCHER, | |
323 obj->typeyec, _OBINFO(obj).eyecatcher); | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
324 } else { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
325 TRACE_DEBUG(FULL, "Invalid object : NULL pointer"); |
0 | 326 } |
327 return 0; | |
328 } ); | |
329 | |
330 /* The object is probably valid. */ | |
331 return 1; | |
332 } | |
333 | |
334 /* Free the data associated to an object */ | |
335 static void destroy_object_data(struct dict_object * obj) | |
336 { | |
337 /* TRACE_ENTRY("%p", obj); */ | |
338 | |
339 switch (obj->type) { | |
340 case DICT_VENDOR: | |
341 free( obj->data.vendor.vendor_name ); | |
342 break; | |
343 | |
344 case DICT_APPLICATION: | |
345 free( obj->data.application.application_name ); | |
346 break; | |
347 | |
348 case DICT_TYPE: | |
349 free( obj->data.type.type_name ); | |
350 break; | |
351 | |
352 case DICT_ENUMVAL: | |
353 free( obj->data.enumval.enum_name ); | |
354 break; | |
355 | |
356 case DICT_AVP: | |
357 free( obj->data.avp.avp_name ); | |
358 break; | |
359 | |
360 case DICT_COMMAND: | |
361 free( obj->data.cmd.cmd_name ); | |
362 break; | |
363 | |
364 default: | |
365 /* nothing to do */ | |
366 ; | |
367 } | |
368 } | |
369 | |
370 /* Forward declaration */ | |
371 static void destroy_object(struct dict_object * obj); | |
372 | |
373 /* Destroy all objects in a list - the lock must be held */ | |
374 static void destroy_list(struct fd_list * head) | |
375 { | |
376 /* TRACE_ENTRY("%p", head); */ | |
377 | |
378 /* loop in the list */ | |
379 while (!FD_IS_LIST_EMPTY(head)) | |
380 { | |
381 /* When destroying the object, it is unlinked from the list */ | |
382 destroy_object(_O(head->next->o)); | |
383 } | |
384 } | |
385 | |
386 /* Free an object and its sublists */ | |
387 static void destroy_object(struct dict_object * obj) | |
388 { | |
389 int i; | |
390 | |
391 /* TRACE_ENTRY("%p", obj); */ | |
392 | |
393 /* Update global count */ | |
394 if (obj->dico) | |
395 obj->dico->dict_count[obj->type]--; | |
396 | |
397 /* Mark the object as invalid */ | |
398 obj->objeyec = 0xdead; | |
399 | |
400 /* First, destroy the data associated to the object */ | |
401 destroy_object_data(obj); | |
402 | |
403 for (i=0; i<NB_LISTS_PER_OBJ; i++) { | |
404 if (_OBINFO(obj).haslist[i]) | |
405 /* unlink the element from the list */ | |
406 fd_list_unlink( &obj->list[i] ); | |
407 else | |
408 /* This is either a sentinel or unused (=emtpy) list, let's destroy it */ | |
409 destroy_list( &obj->list[i] ); | |
410 } | |
411 | |
412 /* Unlink all elements from the dispatch list; they will be freed when callback is unregistered */ | |
7
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
413 CHECK_POSIX_DO( pthread_rwlock_wrlock(&fd_disp_lock), /* continue */ ); |
0 | 414 while (!FD_IS_LIST_EMPTY(&obj->disp_cbs)) { |
415 fd_list_unlink( obj->disp_cbs.next ); | |
416 } | |
7
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
417 CHECK_POSIX_DO( pthread_rwlock_unlock(&fd_disp_lock), /* continue */ ); |
0 | 418 |
419 /* Last, destroy the object */ | |
420 free(obj); | |
421 } | |
422 | |
423 /*******************************************************************************************************/ | |
424 /*******************************************************************************************************/ | |
425 /* */ | |
426 /* Compare functions */ | |
427 /* */ | |
428 /*******************************************************************************************************/ | |
429 /*******************************************************************************************************/ | |
430 | |
431 /* Compare two values */ | |
432 #define ORDER_scalar( i1, i2 ) \ | |
433 ((i1 < i2 ) ? -1 : ( i1 > i2 ? 1 : 0 )) | |
434 | |
435 | |
436 /* Compare two vendor objects by their id (checks already performed) */ | |
437 static int order_vendor_by_id ( struct dict_object *o1, struct dict_object *o2 ) | |
438 { | |
439 TRACE_ENTRY("%p %p", o1, o2); | |
440 | |
441 return ORDER_scalar( o1->data.vendor.vendor_id, o2->data.vendor.vendor_id ); | |
442 } | |
443 | |
444 /* Compare two application objects by their id (checks already performed) */ | |
445 static int order_appli_by_id ( struct dict_object *o1, struct dict_object *o2 ) | |
446 { | |
447 TRACE_ENTRY("%p %p", o1, o2); | |
448 | |
449 return ORDER_scalar( o1->data.application.application_id, o2->data.application.application_id ); | |
450 } | |
451 | |
452 /* Compare two type objects by their name (checks already performed) */ | |
453 static int order_type_by_name ( struct dict_object *o1, struct dict_object *o2 ) | |
454 { | |
455 TRACE_ENTRY("%p %p", o1, o2); | |
456 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
457 return fd_os_cmp( o1->data.type.type_name, o1->datastr_len, o2->data.type.type_name, o2->datastr_len ); |
0 | 458 } |
459 | |
460 /* Compare two type_enum objects by their names (checks already performed) */ | |
461 static int order_enum_by_name ( struct dict_object *o1, struct dict_object *o2 ) | |
462 { | |
463 TRACE_ENTRY("%p %p", o1, o2); | |
464 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
465 return fd_os_cmp( o1->data.enumval.enum_name, o1->datastr_len, o2->data.enumval.enum_name, o2->datastr_len ); |
0 | 466 } |
467 | |
468 /* Compare two type_enum objects by their values (checks already performed) */ | |
469 static int order_enum_by_val ( struct dict_object *o1, struct dict_object *o2 ) | |
470 { | |
471 TRACE_ENTRY("%p %p", o1, o2); | |
472 | |
473 /* The comparison function depends on the type of data */ | |
474 switch ( o1->parent->data.type.type_base ) { | |
475 case AVP_TYPE_OCTETSTRING: | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
476 return fd_os_cmp( o1->data.enumval.enum_value.os.data, o1->data.enumval.enum_value.os.len, |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
477 o2->data.enumval.enum_value.os.data, o2->data.enumval.enum_value.os.len); |
0 | 478 |
479 case AVP_TYPE_INTEGER32: | |
480 return ORDER_scalar( o1->data.enumval.enum_value.i32, o2->data.enumval.enum_value.i32 ); | |
481 | |
482 case AVP_TYPE_INTEGER64: | |
483 return ORDER_scalar( o1->data.enumval.enum_value.i64, o2->data.enumval.enum_value.i64 ); | |
484 | |
485 case AVP_TYPE_UNSIGNED32: | |
486 return ORDER_scalar( o1->data.enumval.enum_value.u32, o2->data.enumval.enum_value.u32 ); | |
487 | |
488 case AVP_TYPE_UNSIGNED64: | |
489 return ORDER_scalar( o1->data.enumval.enum_value.u64, o2->data.enumval.enum_value.u64 ); | |
490 | |
491 case AVP_TYPE_FLOAT32: | |
492 return ORDER_scalar( o1->data.enumval.enum_value.f32, o2->data.enumval.enum_value.f32 ); | |
493 | |
494 case AVP_TYPE_FLOAT64: | |
495 return ORDER_scalar( o1->data.enumval.enum_value.f64, o2->data.enumval.enum_value.f64 ); | |
496 | |
497 case AVP_TYPE_GROUPED: | |
498 default: | |
499 ASSERT(0); | |
500 } | |
501 return 0; | |
502 } | |
503 | |
504 /* Compare two avp objects by their codes (checks already performed) */ | |
505 static int order_avp_by_code ( struct dict_object *o1, struct dict_object *o2 ) | |
506 { | |
507 TRACE_ENTRY("%p %p", o1, o2); | |
508 | |
509 return ORDER_scalar( o1->data.avp.avp_code, o2->data.avp.avp_code ); | |
510 } | |
511 | |
512 /* Compare two avp objects by their names (checks already performed) */ | |
513 static int order_avp_by_name ( struct dict_object *o1, struct dict_object *o2 ) | |
514 { | |
515 TRACE_ENTRY("%p %p", o1, o2); | |
516 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
517 return fd_os_cmp( o1->data.avp.avp_name, o1->datastr_len, o2->data.avp.avp_name, o2->datastr_len ); |
0 | 518 } |
519 | |
520 /* Compare two command objects by their names (checks already performed) */ | |
521 static int order_cmd_by_name ( struct dict_object *o1, struct dict_object *o2 ) | |
522 { | |
523 TRACE_ENTRY("%p %p", o1, o2); | |
524 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
525 return fd_os_cmp( o1->data.cmd.cmd_name, o1->datastr_len, o2->data.cmd.cmd_name, o2->datastr_len ); |
0 | 526 } |
527 | |
528 /* Compare two command objects by their codes and flags (request or answer) (checks already performed) */ | |
529 static int order_cmd_by_codefl( struct dict_object *o1, struct dict_object *o2 ) | |
530 { | |
531 uint8_t fl1, fl2; | |
532 int cmp = 0; | |
533 | |
534 TRACE_ENTRY("%p %p", o1, o2); | |
535 | |
536 cmp = ORDER_scalar( o1->data.cmd.cmd_code, o2->data.cmd.cmd_code ); | |
537 if (cmp) | |
538 return cmp; | |
539 | |
540 /* Same command code, we must compare the value of the 'R' flag */ | |
541 fl1 = o1->data.cmd.cmd_flag_val & CMD_FLAG_REQUEST; | |
542 fl2 = o2->data.cmd.cmd_flag_val & CMD_FLAG_REQUEST; | |
543 | |
544 /* We want requests first, so we reverse the operators here */ | |
545 return ORDER_scalar(fl2, fl1); | |
546 | |
547 } | |
548 | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
549 /* Compare two rule object by the AVP vendor & code that they refer (checks already performed) */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
550 static int order_rule_by_avpvc ( struct dict_object *o1, struct dict_object *o2 ) |
0 | 551 { |
552 TRACE_ENTRY("%p %p", o1, o2); | |
553 | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
554 return ORDER_scalar(o1->data.rule.rule_avp->data.avp.avp_vendor, o2->data.rule.rule_avp->data.avp.avp_vendor) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
555 ?: ORDER_scalar(o1->data.rule.rule_avp->data.avp.avp_code, o2->data.rule.rule_avp->data.avp.avp_code) ; |
0 | 556 } |
557 | |
558 /*******************************************************************************************************/ | |
559 /*******************************************************************************************************/ | |
560 /* */ | |
561 /* Search functions */ | |
562 /* */ | |
563 /*******************************************************************************************************/ | |
564 /*******************************************************************************************************/ | |
565 | |
566 /* Functions used to search for objects in the lists, according to some criteria */ | |
567 | |
568 /* On a general note, if result is not NULL, ENOENT is not returned but *result is NULL. */ | |
569 | |
570 /* The following macros assume that "what", "ret", "result" (variables), and "end" (label) exist | |
571 in the local context where they are called. They are meant to be called only from the functions that follow. */ | |
572 | |
573 /* For searchs of type "xxx_OF_xxx": children's parent or default parent */ | |
574 #define SEARCH_childs_parent( type_of_child, default_parent ) { \ | |
575 struct dict_object *__child = (struct dict_object *) what; \ | |
576 CHECK_PARAMS_DO( verify_object(__child) && \ | |
577 (__child->type == (type_of_child)), \ | |
578 { ret = EINVAL; goto end; } ); \ | |
579 ret = 0; \ | |
580 if (result) \ | |
581 *result = (__child->parent ? __child->parent :(default_parent));\ | |
582 } | |
583 | |
584 /* For search of strings in lists. isindex= 1 if the string is the ordering key of the list */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
585 /* it is expected that object->datastr_len is the length of the datafield parameter */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
586 #define SEARCH_os0_l( str, len, sentinel, datafield, isindex ) { \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
587 char * __str = (char *) (str); \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
588 size_t __strlen = (size_t)(len); \ |
0 | 589 int __cmp; \ |
590 struct fd_list * __li; \ | |
591 ret = 0; \ | |
602
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
592 for (__li = (sentinel)->next; __li != (sentinel); __li = __li->next) { \ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
593 __cmp = fd_os_cmp(__str, __strlen, \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
594 _O(__li->o)->data. datafield, _O(__li->o)->datastr_len);\ |
0 | 595 if (__cmp == 0) { \ |
596 if (result) \ | |
602
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
597 *result = _O(__li->o); \ |
0 | 598 goto end; \ |
599 } \ | |
600 if ((isindex) && (__cmp < 0)) \ | |
601 break; \ | |
602 } \ | |
603 if (result) \ | |
604 *result = NULL; \ | |
605 else \ | |
606 ret = ENOENT; \ | |
607 } | |
608 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
609 /* When len is not provided */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
610 #define SEARCH_os0( str, sentinel, datafield, isindex ) { \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
611 char * _str = (char *) (str); \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
612 size_t _strlen = strlen(_str); \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
613 SEARCH_os0_l( _str, _strlen, sentinel, datafield, isindex ); \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
614 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
615 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
616 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
617 /* For search of octetstrings in lists. */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
618 #define SEARCH_os( str, strlen, sentinel, osdatafield, isindex ) { \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
619 uint8_t * __str = (uint8_t *) (str); \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
620 size_t __strlen = (size_t)(strlen); \ |
0 | 621 int __cmp; \ |
622 struct fd_list * __li; \ | |
623 ret = 0; \ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
624 for (__li = (sentinel)->next; __li != (sentinel); __li = __li->next) { \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
625 __cmp = fd_os_cmp(__str, __strlen, \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
626 _O(__li->o)->data. osdatafield .data, \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
627 _O(__li->o)->data. osdatafield .len); \ |
0 | 628 if (__cmp == 0) { \ |
629 if (result) \ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
630 *result = _O(__li->o); \ |
0 | 631 goto end; \ |
632 } \ | |
633 if ((isindex) && (__cmp < 0)) \ | |
634 break; \ | |
635 } \ | |
636 if (result) \ | |
637 *result = NULL; \ | |
638 else \ | |
639 ret = ENOENT; \ | |
640 } | |
641 | |
910
8500947421cb
Fix bug in fd_dict_search for rules. Thank you Thomas for bug & fix.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
907
diff
changeset
|
642 /* For search of AVP name in rule lists -- the list is not ordered by AVP names! */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
643 #define SEARCH_ruleavpname( str, strlen, sentinel ) { \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
644 char * __str = (char *) (str); \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
645 size_t __strlen = (size_t) (strlen); \ |
0 | 646 int __cmp; \ |
647 struct fd_list * __li; \ | |
648 ret = 0; \ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
649 for (__li = (sentinel)->next; __li != (sentinel); __li = __li->next) { \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
650 __cmp = fd_os_cmp(__str, __strlen, \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
651 _O(__li->o)->data.rule.rule_avp->data.avp.avp_name, \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
652 _O(__li->o)->data.rule.rule_avp->datastr_len); \ |
0 | 653 if (__cmp == 0) { \ |
654 if (result) \ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
655 *result = _O(__li->o); \ |
0 | 656 goto end; \ |
657 } \ | |
658 } \ | |
659 if (result) \ | |
660 *result = NULL; \ | |
661 else \ | |
662 ret = ENOENT; \ | |
663 } | |
664 | |
665 /* For search of scalars in lists. isindex= 1 if the value is the ordering key of the list */ | |
666 #define SEARCH_scalar( value, sentinel, datafield, isindex, defaultobj ) { \ | |
667 int __cmp; \ | |
668 struct fd_list * __li; \ | |
669 ret = 0; \ | |
670 if ( ((defaultobj) != NULL) \ | |
671 && (_O(defaultobj)->data. datafield == value)) { \ | |
672 if (result) \ | |
673 *result = _O(defaultobj); \ | |
674 goto end; \ | |
675 } \ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
676 for (__li = (sentinel)->next; __li != (sentinel); __li = __li->next) { \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
677 __cmp= ORDER_scalar(value, _O(__li->o)->data. datafield ); \ |
0 | 678 if (__cmp == 0) { \ |
679 if (result) \ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
680 *result = _O(__li->o); \ |
0 | 681 goto end; \ |
682 } \ | |
683 if ((isindex) && (__cmp < 0)) \ | |
684 break; \ | |
685 } \ | |
686 if (result) \ | |
687 *result = NULL; \ | |
688 else \ | |
689 ret = ENOENT; \ | |
690 } | |
691 | |
692 /* For search of commands in lists by code and flag. R_flag_val = 0 or CMD_FLAG_REQUEST */ | |
693 #define SEARCH_codefl( value, R_flag_val, sentinel) { \ | |
694 int __cmp; \ | |
695 struct fd_list * __li; \ | |
696 ret = 0; \ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
697 for (__li = (sentinel)->next; __li != (sentinel); __li = __li->next) { \ |
0 | 698 __cmp = ORDER_scalar(value, \ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
699 _O(__li->o)->data.cmd.cmd_code ); \ |
0 | 700 if (__cmp == 0) { \ |
701 uint8_t __mask, __val; \ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
702 __mask = _O(__li->o)->data.cmd.cmd_flag_mask; \ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
703 __val = _O(__li->o)->data.cmd.cmd_flag_val; \ |
0 | 704 if ( ! (__mask & CMD_FLAG_REQUEST) ) \ |
705 continue; \ | |
706 if ( ( __val & CMD_FLAG_REQUEST ) != R_flag_val ) \ | |
707 continue; \ | |
708 if (result) \ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
709 *result = _O(__li->o); \ |
0 | 710 goto end; \ |
711 } \ | |
712 if (__cmp < 0) \ | |
713 break; \ | |
714 } \ | |
715 if (result) \ | |
716 *result = NULL; \ | |
717 else \ | |
718 ret = ENOENT; \ | |
719 } | |
720 | |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
721 /* For searchs of type "xxx_OF_xxx": if the search object is sentinel list for the "what" object */ |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
722 #define SEARCH_sentinel( type_of_what, what_list_nr, sentinel_list_nr ) { \ |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
723 struct dict_object *__what = (struct dict_object *) what; \ |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
724 CHECK_PARAMS_DO( verify_object(__what) && \ |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
725 (__what->type == (type_of_what)), \ |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
726 { ret = EINVAL; goto end; } ); \ |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
727 ret = 0; \ |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
728 if (result) { \ |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
729 /* this is similar to the "container_of" */ \ |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
730 *result = (struct dict_object *)((char *)(__what->list[what_list_nr].head) - \ |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
731 (size_t)&(((struct dict_object *)0)->list[sentinel_list_nr])); \ |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
732 } \ |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
733 } |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
734 |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
735 |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
736 static int search_vendor ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ) |
0 | 737 { |
738 int ret = 0; | |
739 vendor_id_t id; | |
740 | |
741 TRACE_ENTRY("%p %d %p %p", dict, criteria, what, result); | |
742 | |
743 switch (criteria) { | |
744 case VENDOR_BY_ID: | |
745 id = *(vendor_id_t *) what; | |
746 SEARCH_scalar( id, &dict->dict_vendors.list[0], vendor.vendor_id, 1, &dict->dict_vendors ); | |
747 break; | |
748 | |
749 case VENDOR_BY_NAME: | |
750 /* "what" is a vendor name */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
751 SEARCH_os0( what, &dict->dict_vendors.list[0], vendor.vendor_name, 0); |
0 | 752 break; |
753 | |
754 case VENDOR_OF_APPLICATION: | |
755 /* "what" should be an application object */ | |
756 SEARCH_childs_parent( DICT_APPLICATION, &dict->dict_vendors ); | |
757 break; | |
758 | |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
759 case VENDOR_OF_AVP: |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
760 /* "what" should be an avp object */ |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
761 SEARCH_sentinel( DICT_AVP, 0, 1 ); |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
762 break; |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
763 |
0 | 764 default: |
765 /* Invalid criteria */ | |
766 CHECK_PARAMS( criteria = 0 ); | |
767 } | |
768 end: | |
769 return ret; | |
770 } | |
771 | |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
772 static int search_application ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ) |
0 | 773 { |
774 int ret = 0; | |
775 application_id_t id; | |
776 | |
777 TRACE_ENTRY("%p %d %p %p", dict, criteria, what, result); | |
778 | |
779 switch (criteria) { | |
780 case APPLICATION_BY_ID: | |
781 id = *(application_id_t *) what; | |
782 | |
783 SEARCH_scalar( id, &dict->dict_applications.list[0], application.application_id, 1, &dict->dict_applications ); | |
784 break; | |
785 | |
786 case APPLICATION_BY_NAME: | |
787 /* "what" is an application name */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
788 SEARCH_os0( what, &dict->dict_applications.list[0], application.application_name, 0); |
0 | 789 break; |
790 | |
791 case APPLICATION_OF_TYPE: | |
792 /* "what" should be a type object */ | |
793 SEARCH_childs_parent( DICT_TYPE, &dict->dict_applications ); | |
794 break; | |
795 | |
796 case APPLICATION_OF_COMMAND: | |
797 /* "what" should be a command object */ | |
798 SEARCH_childs_parent( DICT_COMMAND, &dict->dict_applications ); | |
799 break; | |
800 | |
801 default: | |
802 /* Invalid criteria */ | |
803 CHECK_PARAMS( criteria = 0 ); | |
804 } | |
805 end: | |
806 return ret; | |
807 } | |
808 | |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
809 static int search_type ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ) |
0 | 810 { |
811 int ret = 0; | |
812 | |
813 TRACE_ENTRY("%p %d %p %p", dict, criteria, what, result); | |
814 | |
815 switch (criteria) { | |
816 case TYPE_BY_NAME: | |
817 /* "what" is a type name */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
818 SEARCH_os0( what, &dict->dict_types, type.type_name, 1); |
0 | 819 break; |
820 | |
821 case TYPE_OF_ENUMVAL: | |
822 /* "what" should be a type_enum object */ | |
823 SEARCH_childs_parent( DICT_ENUMVAL, NULL ); | |
824 break; | |
825 | |
826 case TYPE_OF_AVP: | |
827 /* "what" should be an avp object */ | |
828 SEARCH_childs_parent( DICT_AVP, NULL ); | |
829 break; | |
830 | |
831 | |
832 default: | |
833 /* Invalid criteria */ | |
834 CHECK_PARAMS( criteria = 0 ); | |
835 } | |
836 end: | |
837 return ret; | |
838 } | |
839 | |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
840 static int search_enumval ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ) |
0 | 841 { |
842 int ret = 0; | |
843 | |
844 TRACE_ENTRY("%p %d %p %p", dict, criteria, what, result); | |
845 | |
846 switch (criteria) { | |
847 case ENUMVAL_BY_STRUCT: | |
848 { | |
849 struct dict_object * parent = NULL; | |
850 struct dict_enumval_request * _what = (struct dict_enumval_request *) what; | |
851 | |
852 CHECK_PARAMS( _what && ( _what->type_obj || _what->type_name ) ); | |
853 | |
854 if (_what->type_obj != NULL) { | |
855 parent = _what->type_obj; | |
856 CHECK_PARAMS( verify_object(parent) && (parent->type == DICT_TYPE) ); | |
857 } else { | |
858 /* We received only the type name, we must find it first */ | |
859 CHECK_FCT_DO( search_type( dict, TYPE_BY_NAME, _what->type_name, &parent ), | |
860 CHECK_PARAMS( 0 ) ); | |
861 } | |
862 | |
863 /* From here the "parent" object is valid */ | |
864 | |
865 if ( _what->search.enum_name != NULL ) { | |
866 /* We are looking for this string */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
867 SEARCH_os0( _what->search.enum_name, &parent->list[1], enumval.enum_name, 1 ); |
0 | 868 } else { |
869 /* We are looking for the value in enum_value */ | |
870 switch (parent->data.type.type_base) { | |
871 case AVP_TYPE_OCTETSTRING: | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
872 SEARCH_os( _what->search.enum_value.os.data, |
0 | 873 _what->search.enum_value.os.len, |
874 &parent->list[2], | |
875 enumval.enum_value.os , | |
876 1 ); | |
877 break; | |
878 | |
879 case AVP_TYPE_INTEGER32: | |
880 SEARCH_scalar( _what->search.enum_value.i32, | |
881 &parent->list[2], | |
882 enumval.enum_value.i32, | |
883 1, | |
884 (struct dict_object *)NULL); | |
885 break; | |
886 | |
887 case AVP_TYPE_INTEGER64: | |
888 SEARCH_scalar( _what->search.enum_value.i64, | |
889 &parent->list[2], | |
890 enumval.enum_value.i64, | |
891 1, | |
892 (struct dict_object *)NULL); | |
893 break; | |
894 | |
895 case AVP_TYPE_UNSIGNED32: | |
896 SEARCH_scalar( _what->search.enum_value.u32, | |
897 &parent->list[2], | |
898 enumval.enum_value.u32, | |
899 1, | |
900 (struct dict_object *)NULL); | |
901 break; | |
902 | |
903 case AVP_TYPE_UNSIGNED64: | |
904 SEARCH_scalar( _what->search.enum_value.u64, | |
905 &parent->list[2], | |
906 enumval.enum_value.u64, | |
907 1, | |
908 (struct dict_object *)NULL); | |
909 break; | |
910 | |
911 case AVP_TYPE_FLOAT32: | |
912 SEARCH_scalar( _what->search.enum_value.f32, | |
913 &parent->list[2], | |
914 enumval.enum_value.f32, | |
915 1, | |
916 (struct dict_object *)NULL); | |
917 break; | |
918 | |
919 case AVP_TYPE_FLOAT64: | |
920 SEARCH_scalar( _what->search.enum_value.f64, | |
921 &parent->list[2], | |
922 enumval.enum_value.f64, | |
923 1, | |
924 (struct dict_object *)NULL); | |
925 break; | |
926 | |
927 default: | |
928 /* Invalid parent type basetype */ | |
929 CHECK_PARAMS( parent = NULL ); | |
930 } | |
931 } | |
932 | |
933 } | |
934 break; | |
935 | |
936 | |
937 default: | |
938 /* Invalid criteria */ | |
939 CHECK_PARAMS( criteria = 0 ); | |
940 } | |
941 end: | |
942 return ret; | |
943 } | |
944 | |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
945 static int search_avp ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ) |
0 | 946 { |
947 int ret = 0; | |
948 | |
949 TRACE_ENTRY("%p %d %p %p", dict, criteria, what, result); | |
950 | |
951 switch (criteria) { | |
952 case AVP_BY_CODE: | |
953 { | |
954 avp_code_t code; | |
955 code = *(avp_code_t *) what; | |
956 | |
957 SEARCH_scalar( code, &dict->dict_vendors.list[1], avp.avp_code, 1, (struct dict_object *)NULL ); | |
958 } | |
959 break; | |
960 | |
961 case AVP_BY_NAME: | |
962 /* "what" is the AVP name, vendor 0 */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
963 SEARCH_os0( what, &dict->dict_vendors.list[2], avp.avp_name, 1); |
0 | 964 break; |
965 | |
966 case AVP_BY_CODE_AND_VENDOR: | |
967 case AVP_BY_NAME_AND_VENDOR: | |
968 { | |
969 struct dict_avp_request * _what = (struct dict_avp_request *) what; | |
970 struct dict_object * vendor = NULL; | |
971 | |
972 CHECK_PARAMS( (criteria != AVP_BY_NAME_AND_VENDOR) || _what->avp_name ); | |
973 | |
974 /* Now look for the vendor first */ | |
975 CHECK_FCT( search_vendor( dict, VENDOR_BY_ID, &_what->avp_vendor, &vendor ) ); | |
976 if (vendor == NULL) { | |
977 if (result) | |
978 *result = NULL; | |
979 else | |
980 ret = ENOENT; | |
981 goto end; | |
982 } | |
983 | |
984 /* We now have our vendor = head of the appropriate avp list */ | |
985 if (criteria == AVP_BY_NAME_AND_VENDOR) { | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
986 SEARCH_os0( _what->avp_name, &vendor->list[2], avp.avp_name, 1); |
0 | 987 } else { |
988 /* AVP_BY_CODE_AND_VENDOR */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
989 SEARCH_scalar( _what->avp_code, &vendor->list[1], avp.avp_code, 1, (struct dict_object *)NULL ); |
0 | 990 } |
991 } | |
992 break; | |
993 | |
903
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
994 case AVP_BY_STRUCT: |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
995 { |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
996 struct dict_avp_request_ex * _what = (struct dict_avp_request_ex *) what; |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
997 struct dict_object * vendor = NULL; |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
998 |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
999 CHECK_PARAMS( _what->avp_vendor.vendor || _what->avp_vendor.vendor_id || _what->avp_vendor.vendor_name ); |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1000 CHECK_PARAMS( _what->avp_data.avp_code || _what->avp_data.avp_name ); |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1001 |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1002 /* Now look for the vendor first */ |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1003 if (_what->avp_vendor.vendor) { |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1004 CHECK_PARAMS( ! _what->avp_vendor.vendor_id && ! _what->avp_vendor.vendor_name ); |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1005 vendor = _what->avp_vendor.vendor; |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1006 } else if (_what->avp_vendor.vendor_id) { |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1007 CHECK_PARAMS( ! _what->avp_vendor.vendor_name ); |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1008 CHECK_FCT( search_vendor( dict, VENDOR_BY_ID, &_what->avp_vendor.vendor_id, &vendor ) ); |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1009 } else { |
906
ebe479bfcd4b
Fix typo in new code
Sebastien Decugis <sdecugis@freediameter.net>
parents:
903
diff
changeset
|
1010 CHECK_FCT( search_vendor( dict, VENDOR_BY_NAME, _what->avp_vendor.vendor_name, &vendor ) ); |
903
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1011 } |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1012 |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1013 if (vendor == NULL) { |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1014 if (result) |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1015 *result = NULL; |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1016 else |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1017 ret = ENOENT; |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1018 goto end; |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1019 } |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1020 |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1021 /* We now have our vendor = head of the appropriate avp list */ |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1022 if (_what->avp_data.avp_code) { |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1023 CHECK_PARAMS( ! _what->avp_data.avp_name ); |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1024 SEARCH_scalar( _what->avp_data.avp_code, &vendor->list[1], avp.avp_code, 1, (struct dict_object *)NULL ); |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1025 } else { |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1026 SEARCH_os0( _what->avp_data.avp_name, &vendor->list[2], avp.avp_name, 1); |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1027 } |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1028 } |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1029 break; |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1030 |
602
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1031 case AVP_BY_NAME_ALL_VENDORS: |
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1032 { |
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1033 struct fd_list * li; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1034 size_t wl = strlen((char *)what); |
602
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1035 |
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1036 /* First, search for vendor 0 */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1037 SEARCH_os0_l( what, wl, &dict->dict_vendors.list[2], avp.avp_name, 1); |
602
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1038 |
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1039 /* If not found, loop for all vendors, until found */ |
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1040 for (li = dict->dict_vendors.list[0].next; li != &dict->dict_vendors.list[0]; li = li->next) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1041 SEARCH_os0_l( what, wl, &_O(li->o)->list[2], avp.avp_name, 1); |
602
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1042 } |
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1043 } |
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1044 break; |
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1045 |
0 | 1046 default: |
1047 /* Invalid criteria */ | |
1048 CHECK_PARAMS( criteria = 0 ); | |
1049 } | |
1050 end: | |
1051 return ret; | |
1052 } | |
1053 | |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
1054 static int search_cmd ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ) |
0 | 1055 { |
1056 int ret = 0; | |
1057 | |
1058 TRACE_ENTRY("%p %d %p %p", dict, criteria, what, result); | |
1059 | |
1060 switch (criteria) { | |
1061 case CMD_BY_NAME: | |
1062 /* "what" is a command name */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1063 SEARCH_os0( what, &dict->dict_cmd_name, cmd.cmd_name, 1); |
0 | 1064 break; |
1065 | |
1066 case CMD_BY_CODE_R: | |
1067 case CMD_BY_CODE_A: | |
1068 { | |
1069 command_code_t code; | |
1070 uint8_t searchfl = 0; | |
1071 | |
1072 /* The command code that we are searching */ | |
1073 code = *(command_code_t *) what; | |
1074 | |
1075 /* The flag (request or answer) of the command we are searching */ | |
1076 if (criteria == CMD_BY_CODE_R) { | |
1077 searchfl = CMD_FLAG_REQUEST; | |
1078 } | |
1079 | |
1080 /* perform the search */ | |
1081 SEARCH_codefl( code, searchfl, &dict->dict_cmd_code ); | |
1082 } | |
1083 break; | |
1084 | |
1085 case CMD_ANSWER: | |
1086 { | |
1087 /* "what" is a command object of type "request" */ | |
1088 struct dict_object * req = (struct dict_object *) what; | |
1089 struct dict_object * ans = NULL; | |
1090 | |
1091 CHECK_PARAMS( verify_object(req) | |
1092 && (req->type == DICT_COMMAND) | |
1093 && (req->data.cmd.cmd_flag_mask & CMD_FLAG_REQUEST) | |
1094 && (req->data.cmd.cmd_flag_val & CMD_FLAG_REQUEST) ); | |
1095 | |
1096 /* The answer is supposed to be the next element in the list, if it exists */ | |
1097 ans = req->list[1].next->o; | |
1098 if ( ans == NULL ) { | |
1099 TRACE_DEBUG( FULL, "the request was the last element in the list" ); | |
1100 ret = ENOENT; | |
1101 goto end; | |
1102 } | |
1103 | |
1104 /* Now check that the ans element is really the correct one */ | |
1105 if ( (ans->data.cmd.cmd_code != req->data.cmd.cmd_code) | |
1106 || (!(ans->data.cmd.cmd_flag_mask & CMD_FLAG_REQUEST)) | |
1107 || ( ans->data.cmd.cmd_flag_val & CMD_FLAG_REQUEST ) ) { | |
1108 TRACE_DEBUG( FULL, "the answer does not follow the request in the list" ); | |
1109 ret = ENOENT; | |
1110 goto end; | |
1111 } | |
1112 | |
1113 if (result) | |
1114 *result = ans; | |
1115 ret = 0; | |
1116 } | |
1117 break; | |
1118 | |
1119 default: | |
1120 /* Invalid criteria */ | |
1121 CHECK_PARAMS( criteria = 0 ); | |
1122 } | |
1123 end: | |
1124 return ret; | |
1125 } | |
1126 | |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
1127 static int search_rule ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ) |
0 | 1128 { |
1129 int ret = 0; | |
1130 | |
1131 TRACE_ENTRY("%p %d %p %p", dict, criteria, what, result); | |
1132 | |
1133 switch (criteria) { | |
1134 case RULE_BY_AVP_AND_PARENT: | |
1135 { | |
1136 struct dict_object * parent = NULL; | |
1137 struct dict_object * avp = NULL; | |
1138 struct dict_rule_request * _what = (struct dict_rule_request *) what; | |
1139 | |
1140 CHECK_PARAMS( _what | |
1141 && (parent = _what->rule_parent) | |
1142 && (avp = _what->rule_avp ) ); | |
1143 | |
1144 CHECK_PARAMS( verify_object(parent) | |
1145 && ((parent->type == DICT_COMMAND) | |
1146 || ((parent->type == DICT_AVP) && (parent->data.avp.avp_basetype == AVP_TYPE_GROUPED))) ); | |
1147 | |
1148 CHECK_PARAMS( verify_object(avp) && (avp->type == DICT_AVP) ); | |
1149 | |
1150 /* Perform the search */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1151 SEARCH_ruleavpname( avp->data.avp.avp_name, avp->datastr_len, &parent->list[2]); |
0 | 1152 |
1153 } | |
1154 break; | |
1155 | |
1156 default: | |
1157 /* Invalid criteria */ | |
1158 CHECK_PARAMS( criteria = 0 ); | |
1159 } | |
1160 end: | |
1161 return ret; | |
1162 } | |
1163 | |
1164 /*******************************************************************************************************/ | |
1165 /*******************************************************************************************************/ | |
1166 /* */ | |
1167 /* Dump / debug functions */ | |
1168 /* */ | |
1169 /*******************************************************************************************************/ | |
1170 /*******************************************************************************************************/ | |
1171 /* The following functions are used to debug the module, and allow to print out the content of the dictionary */ | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1172 static DECLARE_FD_DUMP_PROTOTYPE(dump_vendor_data, void * data ) |
0 | 1173 { |
1174 struct dict_vendor_data * vendor = (struct dict_vendor_data *)data; | |
1175 | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1176 return fd_dump_extend( FD_DUMP_STD_PARAMS, "data: %-6u \"%s\"", vendor->vendor_id, vendor->vendor_name); |
0 | 1177 } |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1178 static DECLARE_FD_DUMP_PROTOTYPE(dump_application_data, void * data ) |
0 | 1179 { |
1180 struct dict_application_data * appli = (struct dict_application_data *) data; | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1181 return fd_dump_extend( FD_DUMP_STD_PARAMS, "data: %-6u \"%s\"", appli->application_id, appli->application_name); |
0 | 1182 } |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1183 static DECLARE_FD_DUMP_PROTOTYPE(dump_type_data, void * data ) |
0 | 1184 { |
1185 struct dict_type_data * type = ( struct dict_type_data * ) data; | |
1186 | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1187 return fd_dump_extend( FD_DUMP_STD_PARAMS, "data: %-12s \"%s\"", |
0 | 1188 type_base_name[type->type_base], |
1189 type->type_name); | |
1190 } | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1191 static DECLARE_FD_DUMP_PROTOTYPE(dump_enumval_data, struct dict_enumval_data * enumval, enum dict_avp_basetype type ) |
0 | 1192 { |
1193 const int LEN_MAX = 20; | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1194 CHECK_MALLOC_DO(fd_dump_extend( FD_DUMP_STD_PARAMS, "data: (%-12s) \"%s\" -> ", type_base_name[type], enumval->enum_name), return NULL); |
0 | 1195 switch (type) { |
1196 case AVP_TYPE_OCTETSTRING: | |
1197 { | |
1198 int i, n=LEN_MAX; | |
1199 if (enumval->enum_value.os.len < LEN_MAX) | |
1200 n = enumval->enum_value.os.len; | |
1201 for (i=0; i < n; i++) | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1202 CHECK_MALLOC_DO(fd_dump_extend( FD_DUMP_STD_PARAMS, "0x%2hhX/'%c' ", enumval->enum_value.os.data[i], ASCII(enumval->enum_value.os.data[i])), return NULL); |
0 | 1203 if (n == LEN_MAX) |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1204 CHECK_MALLOC_DO(fd_dump_extend( FD_DUMP_STD_PARAMS, "..."), return NULL); |
0 | 1205 } |
1206 break; | |
1207 | |
1208 case AVP_TYPE_INTEGER32: | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1209 CHECK_MALLOC_DO(fd_dump_extend( FD_DUMP_STD_PARAMS, "%i", enumval->enum_value.i32), return NULL); |
0 | 1210 break; |
1211 | |
1212 case AVP_TYPE_INTEGER64: | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1213 CHECK_MALLOC_DO(fd_dump_extend( FD_DUMP_STD_PARAMS, "%"PRId64, enumval->enum_value.i64), return NULL); |
0 | 1214 break; |
1215 | |
1216 case AVP_TYPE_UNSIGNED32: | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1217 CHECK_MALLOC_DO(fd_dump_extend( FD_DUMP_STD_PARAMS, "%u", enumval->enum_value.u32), return NULL); |
0 | 1218 break; |
1219 | |
1220 case AVP_TYPE_UNSIGNED64: | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1221 CHECK_MALLOC_DO(fd_dump_extend( FD_DUMP_STD_PARAMS, "%"PRIu64, enumval->enum_value.u64), return NULL); |
0 | 1222 break; |
1223 | |
1224 case AVP_TYPE_FLOAT32: | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1225 CHECK_MALLOC_DO(fd_dump_extend( FD_DUMP_STD_PARAMS, "%f", enumval->enum_value.f32), return NULL); |
0 | 1226 break; |
1227 | |
1228 case AVP_TYPE_FLOAT64: | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1229 CHECK_MALLOC_DO(fd_dump_extend( FD_DUMP_STD_PARAMS, "%g", enumval->enum_value.f64), return NULL); |
0 | 1230 break; |
1231 | |
1232 default: | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1233 CHECK_MALLOC_DO(fd_dump_extend( FD_DUMP_STD_PARAMS, "??? (ERROR unknown type %d)", type), return NULL); |
0 | 1234 } |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1235 return *buf; |
0 | 1236 } |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1237 static DECLARE_FD_DUMP_PROTOTYPE(dump_avp_data, void * data ) |
0 | 1238 { |
1239 struct dict_avp_data * avp = (struct dict_avp_data * ) data; | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1240 return fd_dump_extend( FD_DUMP_STD_PARAMS, "data: v/m:" DUMP_AVPFL_str "/" DUMP_AVPFL_str ", %12s, %-6u \"%s\"", |
0 | 1241 DUMP_AVPFL_val(avp->avp_flag_val), |
1242 DUMP_AVPFL_val(avp->avp_flag_mask), | |
1243 type_base_name[avp->avp_basetype], | |
1244 avp->avp_code, | |
1245 avp->avp_name ); | |
1246 } | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1247 static DECLARE_FD_DUMP_PROTOTYPE(dump_command_data, void * data ) |
0 | 1248 { |
1249 struct dict_cmd_data * cmd = (struct dict_cmd_data *) data; | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1250 return fd_dump_extend( FD_DUMP_STD_PARAMS, "data: v/m:" DUMP_CMDFL_str "/" DUMP_CMDFL_str ", %-6u \"%s\"", |
0 | 1251 DUMP_CMDFL_val(cmd->cmd_flag_val), DUMP_CMDFL_val(cmd->cmd_flag_mask), cmd->cmd_code, cmd->cmd_name); |
1252 } | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1253 static DECLARE_FD_DUMP_PROTOTYPE(dump_rule_data, void * data ) |
0 | 1254 { |
1255 struct dict_rule_data * rule = (struct dict_rule_data * )data; | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1256 return fd_dump_extend( FD_DUMP_STD_PARAMS, "data: pos:%d ord:%d m/M:%2d/%2d avp:\"%s\"", |
0 | 1257 rule->rule_position, |
1258 rule->rule_order, | |
1259 rule->rule_min, | |
1260 rule->rule_max, | |
1261 rule->rule_avp->data.avp.avp_name); | |
1262 } | |
1263 | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1264 static DECLARE_FD_DUMP_PROTOTYPE(dump_object, struct dict_object * obj, int parents, int depth, int indent ); |
0 | 1265 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1266 static DECLARE_FD_DUMP_PROTOTYPE(dump_list, struct fd_list * sentinel, int parents, int depth, int indent ) |
0 | 1267 { |
1268 struct fd_list * li = sentinel; | |
1269 /* We don't lock here, the caller must have taken the dictionary lock for reading already */ | |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1270 if (FD_IS_LIST_EMPTY(sentinel)) { |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1271 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n%*s{empty list}", indent, ""), return NULL); |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1272 } else { |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1273 while (li->next != sentinel) |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1274 { |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1275 li = li->next; |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1276 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n"), return NULL); |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1277 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, _O(li->o), parents, depth, indent ), return NULL); |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1278 } |
0 | 1279 } |
1280 } | |
1281 | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1282 static DECLARE_FD_DUMP_PROTOTYPE(dump_object, struct dict_object * obj, int parents, int depth, int indent ) |
0 | 1283 { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1284 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%*s{dictobj}(@%p): ", indent, "", obj), return NULL); |
0 | 1285 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1286 if (!verify_object(obj)) { |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1287 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID/NULL"), return NULL); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1288 return *buf; |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1289 } |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1290 |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1291 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%s p:%p ", |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1292 _OBINFO(obj).name, |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1293 obj->parent), return NULL); |
0 | 1294 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1295 if (obj->type == DICT_ENUMVAL) { |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1296 CHECK_MALLOC_DO( dump_enumval_data ( FD_DUMP_STD_PARAMS, &obj->data.enumval, obj->parent->data.type.type_base ), return NULL); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1297 } else { |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1298 CHECK_MALLOC_DO( _OBINFO(obj).dump_data(FD_DUMP_STD_PARAMS, &obj->data), return NULL); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1299 } |
0 | 1300 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1301 if (parents) { |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1302 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n%*sparent:", indent + 1, ""), return NULL); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1303 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, obj->parent, parents-1, 0, 0 ), return NULL); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1304 } |
0 | 1305 |
1306 if (depth) { | |
1307 int i; | |
1308 for (i=0; i<NB_LISTS_PER_OBJ; i++) { | |
1309 if ((obj->list[i].o == NULL) && (obj->list[i].next != &obj->list[i])) { | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1310 CHECK_MALLOC_DO( dump_list(FD_DUMP_STD_PARAMS, &obj->list[i], 0, depth - 1, indent + 2), return NULL); |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1311 break; /* we get duplicate information sorted by another criteria otherwise, which is not very useful */ |
0 | 1312 } |
1313 } | |
1314 } | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1315 |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1316 return *buf; |
0 | 1317 } |
1318 | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1319 DECLARE_FD_DUMP_PROTOTYPE(fd_dict_dump_object, struct dict_object * obj) |
0 | 1320 { |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1321 FD_DUMP_HANDLE_OFFSET(); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1322 |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1323 CHECK_MALLOC_DO( dump_object(FD_DUMP_STD_PARAMS, obj, 1, 2, 0), return NULL); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1324 |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1325 return *buf; |
0 | 1326 } |
1327 | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1328 DECLARE_FD_DUMP_PROTOTYPE(fd_dict_dump, struct dictionary * dict) |
0 | 1329 { |
1330 int i; | |
828
78307a61c578
Fix regression in dictionary dump
Sebastien Decugis <sdecugis@freediameter.net>
parents:
804
diff
changeset
|
1331 struct fd_list * li; |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1332 |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1333 FD_DUMP_HANDLE_OFFSET(); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1334 |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1335 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{dictionary}(@%p): ", dict), return NULL); |
0 | 1336 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1337 if ((dict == NULL) || (dict->dict_eyec != DICT_EYECATCHER)) { |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1338 return fd_dump_extend(FD_DUMP_STD_PARAMS, "INVALID/NULL"); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1339 } |
0 | 1340 |
1341 CHECK_POSIX_DO( pthread_rwlock_rdlock( &dict->dict_lock ), /* ignore */ ); | |
1342 | |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1343 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n {dict(%p) : VENDORS / AVP / RULES}\n", dict), goto error); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1344 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, &dict->dict_vendors, 0, 3, 3 ), goto error); |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1345 for (li = dict->dict_vendors.list[0].next; li != &dict->dict_vendors.list[0]; li = li->next) { |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1346 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n"), return NULL); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1347 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, li->o, 0, 3, 3 ), goto error); |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1348 } |
0 | 1349 |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1350 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n {dict(%p) : APPLICATIONS}\n", dict), goto error); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1351 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, &dict->dict_applications, 0, 1, 3 ), goto error); |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1352 for (li = dict->dict_applications.list[0].next; li != &dict->dict_applications.list[0]; li = li->next) { |
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1353 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n"), return NULL); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1354 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, li->o, 0, 1, 3 ), goto error); |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1355 } |
0 | 1356 |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1357 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n {dict(%p) : TYPES / ENUMVAL}", dict), goto error); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1358 CHECK_MALLOC_DO( dump_list(FD_DUMP_STD_PARAMS, &dict->dict_types, 0, 2, 3 ), goto error); |
0 | 1359 |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1360 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n {dict(%p) : COMMANDS / RULES}", dict), goto error); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1361 CHECK_MALLOC_DO( dump_list(FD_DUMP_STD_PARAMS, &dict->dict_cmd_code, 0, 0, 3 ), goto error); |
0 | 1362 |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1363 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n {dict(%p) : statistics}", dict), goto error); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1364 for (i=1; i<=DICT_TYPE_MAX; i++) |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1365 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n %5d: %s", dict->dict_count[i], dict_obj_info[i].name), goto error); |
0 | 1366 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1367 CHECK_POSIX_DO( pthread_rwlock_unlock( &dict->dict_lock ), /* ignore */ ); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1368 return *buf; |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1369 error: |
0 | 1370 /* Free the rwlock */ |
1371 CHECK_POSIX_DO( pthread_rwlock_unlock( &dict->dict_lock ), /* ignore */ ); | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1372 return NULL; |
0 | 1373 } |
1374 | |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1375 /**************************** Dump AVP values ********************************/ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1376 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1377 /* Default dump functions */ |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1378 static DECLARE_FD_DUMP_PROTOTYPE(dump_val_os, union avp_value * value) |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1379 { |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1380 int i; |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1381 |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1382 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "<"), return NULL); |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1383 for (i = 0; i < value->os.len; i++) { |
1036
aecdc2fbf222
Add fd_msg_dump_full function that dumps a message in human-readable format.
Thomas Klausner <tk@giga.or.at>
parents:
1030
diff
changeset
|
1384 if (i == 1024) { /* Dump only up to 1024 bytes of the buffer */ |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1385 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "[...] (len=%zd)", value->os.len), return NULL); |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1386 break; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1387 } |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1388 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%s%02hhX", (i==0 ? "" : " "), value->os.data[i]), return NULL); |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1389 } |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1390 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, ">"), return NULL); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1391 return *buf; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1392 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1393 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1394 static DECLARE_FD_DUMP_PROTOTYPE(dump_val_i32, union avp_value * value) |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1395 { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1396 return fd_dump_extend( FD_DUMP_STD_PARAMS, "%i (0x%x)", value->i32, value->i32); |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1397 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1398 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1399 static DECLARE_FD_DUMP_PROTOTYPE(dump_val_i64, union avp_value * value) |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1400 { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1401 return fd_dump_extend( FD_DUMP_STD_PARAMS, "%" PRId64 " (0x%" PRIx64 ")", value->i64, value->i64); |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1402 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1403 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1404 static DECLARE_FD_DUMP_PROTOTYPE(dump_val_u32, union avp_value * value) |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1405 { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1406 return fd_dump_extend( FD_DUMP_STD_PARAMS, "%u (0x%x)", value->u32, value->u32); |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1407 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1408 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1409 static DECLARE_FD_DUMP_PROTOTYPE(dump_val_u64, union avp_value * value) |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1410 { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1411 return fd_dump_extend( FD_DUMP_STD_PARAMS, "%" PRIu64 " (0x%" PRIx64 ")", value->u64, value->u64); |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1412 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1413 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1414 static DECLARE_FD_DUMP_PROTOTYPE(dump_val_f32, union avp_value * value) |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1415 { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1416 return fd_dump_extend( FD_DUMP_STD_PARAMS, "%f", value->f32); |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1417 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1418 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1419 static DECLARE_FD_DUMP_PROTOTYPE(dump_val_f64, union avp_value * value) |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1420 { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1421 return fd_dump_extend( FD_DUMP_STD_PARAMS, "%g", value->f64); |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1422 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1423 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1424 /* Get the dump function for basic dict_avp_basetype */ |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1425 static DECLARE_FD_DUMP_PROTOTYPE((*get_default_dump_val_cb(enum dict_avp_basetype datatype)), union avp_value *) |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1426 { |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1427 switch (datatype) { |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1428 case AVP_TYPE_OCTETSTRING: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1429 return &dump_val_os; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1430 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1431 case AVP_TYPE_INTEGER32: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1432 return &dump_val_i32; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1433 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1434 case AVP_TYPE_INTEGER64: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1435 return &dump_val_i64; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1436 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1437 case AVP_TYPE_UNSIGNED32: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1438 return &dump_val_u32; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1439 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1440 case AVP_TYPE_UNSIGNED64: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1441 return &dump_val_u64; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1442 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1443 case AVP_TYPE_FLOAT32: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1444 return &dump_val_f32; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1445 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1446 case AVP_TYPE_FLOAT64: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1447 return &dump_val_f64; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1448 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1449 case AVP_TYPE_GROUPED: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1450 TRACE_DEBUG(FULL, "error: grouped AVP with a value!"); |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1451 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1452 return NULL; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1453 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1454 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1455 /* indent inside an object (duplicate from messages.c) */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1456 #define INOBJHDR "%*s " |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1457 #define INOBJHDRVAL indent<0 ? 1 : indent, indent<0 ? "-" : "|" |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1458 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1459 typedef DECLARE_FD_DUMP_PROTOTYPE((*dump_val_cb_t), union avp_value *); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1460 |
1036
aecdc2fbf222
Add fd_msg_dump_full function that dumps a message in human-readable format.
Thomas Klausner <tk@giga.or.at>
parents:
1030
diff
changeset
|
1461 /* Formatter for the AVP value dump line */ |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1462 static DECLARE_FD_DUMP_PROTOTYPE(dump_avp_val, union avp_value *avp_value, |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1463 dump_val_cb_t def_dump_val_cb, |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1464 dump_val_cb_t dump_val_cb, |
804
c5b7d4a2cc77
Log message dumps in one call to the dump function to avoid fragmentation in the log files, as per Zack comment
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
788
diff
changeset
|
1465 enum dict_avp_basetype datatype, |
c5b7d4a2cc77
Log message dumps in one call to the dump function to avoid fragmentation in the log files, as per Zack comment
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
788
diff
changeset
|
1466 char * type_name, |
c5b7d4a2cc77
Log message dumps in one call to the dump function to avoid fragmentation in the log files, as per Zack comment
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
788
diff
changeset
|
1467 char * const_name, |
c5b7d4a2cc77
Log message dumps in one call to the dump function to avoid fragmentation in the log files, as per Zack comment
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
788
diff
changeset
|
1468 int indent, |
1036
aecdc2fbf222
Add fd_msg_dump_full function that dumps a message in human-readable format.
Thomas Klausner <tk@giga.or.at>
parents:
1030
diff
changeset
|
1469 int header) |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1470 { |
1036
aecdc2fbf222
Add fd_msg_dump_full function that dumps a message in human-readable format.
Thomas Klausner <tk@giga.or.at>
parents:
1030
diff
changeset
|
1471 if (header) { |
aecdc2fbf222
Add fd_msg_dump_full function that dumps a message in human-readable format.
Thomas Klausner <tk@giga.or.at>
parents:
1030
diff
changeset
|
1472 /* Header for all AVP values dumps: */ |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1473 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, INOBJHDR "value ", INOBJHDRVAL), return NULL); |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1474 |
1036
aecdc2fbf222
Add fd_msg_dump_full function that dumps a message in human-readable format.
Thomas Klausner <tk@giga.or.at>
parents:
1030
diff
changeset
|
1475 /* If the type is provided, write it */ |
aecdc2fbf222
Add fd_msg_dump_full function that dumps a message in human-readable format.
Thomas Klausner <tk@giga.or.at>
parents:
1030
diff
changeset
|
1476 if (type_name) { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1477 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "t: '%s' ", type_name), return NULL); |
1036
aecdc2fbf222
Add fd_msg_dump_full function that dumps a message in human-readable format.
Thomas Klausner <tk@giga.or.at>
parents:
1030
diff
changeset
|
1478 } |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1479 |
1036
aecdc2fbf222
Add fd_msg_dump_full function that dumps a message in human-readable format.
Thomas Klausner <tk@giga.or.at>
parents:
1030
diff
changeset
|
1480 /* Always give the base datatype anyway */ |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1481 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(%s) ", type_base_name[datatype]), return NULL); |
1036
aecdc2fbf222
Add fd_msg_dump_full function that dumps a message in human-readable format.
Thomas Klausner <tk@giga.or.at>
parents:
1030
diff
changeset
|
1482 |
aecdc2fbf222
Add fd_msg_dump_full function that dumps a message in human-readable format.
Thomas Klausner <tk@giga.or.at>
parents:
1030
diff
changeset
|
1483 /* Now, the value */ |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1484 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "v: "), return NULL); |
1036
aecdc2fbf222
Add fd_msg_dump_full function that dumps a message in human-readable format.
Thomas Klausner <tk@giga.or.at>
parents:
1030
diff
changeset
|
1485 } |
804
c5b7d4a2cc77
Log message dumps in one call to the dump function to avoid fragmentation in the log files, as per Zack comment
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
788
diff
changeset
|
1486 if (const_name) { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1487 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "'%s' (", const_name), return NULL); |
804
c5b7d4a2cc77
Log message dumps in one call to the dump function to avoid fragmentation in the log files, as per Zack comment
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
788
diff
changeset
|
1488 } |
c5b7d4a2cc77
Log message dumps in one call to the dump function to avoid fragmentation in the log files, as per Zack comment
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
788
diff
changeset
|
1489 if (dump_val_cb) { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1490 CHECK_MALLOC_DO( (*dump_val_cb)( FD_DUMP_STD_PARAMS, avp_value), fd_dump_extend( FD_DUMP_STD_PARAMS, "(dump failed)")); |
804
c5b7d4a2cc77
Log message dumps in one call to the dump function to avoid fragmentation in the log files, as per Zack comment
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
788
diff
changeset
|
1491 } else { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1492 CHECK_MALLOC_DO( (*def_dump_val_cb)( FD_DUMP_STD_PARAMS, avp_value), return NULL); |
804
c5b7d4a2cc77
Log message dumps in one call to the dump function to avoid fragmentation in the log files, as per Zack comment
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
788
diff
changeset
|
1493 } |
c5b7d4a2cc77
Log message dumps in one call to the dump function to avoid fragmentation in the log files, as per Zack comment
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
788
diff
changeset
|
1494 if (const_name) { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1495 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, ")"), return NULL); |
804
c5b7d4a2cc77
Log message dumps in one call to the dump function to avoid fragmentation in the log files, as per Zack comment
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
788
diff
changeset
|
1496 } |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1497 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1498 /* Done! */ |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1499 return *buf; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1500 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1501 |
804
c5b7d4a2cc77
Log message dumps in one call to the dump function to avoid fragmentation in the log files, as per Zack comment
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
788
diff
changeset
|
1502 /* Dump the value of an AVP of known type into the returned str */ |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1503 DECLARE_FD_DUMP_PROTOTYPE(fd_dict_dump_avp_value, union avp_value *avp_value, struct dict_object * model, int indent, int header) |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1504 { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1505 DECLARE_FD_DUMP_PROTOTYPE((*dump_val_cb), union avp_value *avp_value) = NULL; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1506 struct dict_object * type = NULL; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1507 char * type_name = NULL; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1508 char * const_name = NULL; |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1509 |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
1510 FD_DUMP_HANDLE_OFFSET(); |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1511 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1512 /* Check the parameters are correct */ |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1513 CHECK_PARAMS_DO( avp_value && verify_object(model) && (model->type == DICT_AVP), return NULL ); |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1514 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1515 /* Get the type definition of this AVP */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1516 type = model->parent; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1517 if (type) { |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1518 struct dict_enumval_request request; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1519 struct dict_object * enumval = NULL; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1520 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1521 type_name = type->data.type.type_name; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1522 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1523 /* overwrite the dump function ? */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1524 if (type->data.type.type_dump) |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1525 dump_val_cb = type->data.type.type_dump; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1526 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1527 /* Now check if the AVP value matches a constant */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1528 memset(&request, 0, sizeof(request)); |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1529 request.type_obj = type; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1530 memcpy(&request.search.enum_value, avp_value, sizeof(union avp_value)); |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1531 /* bypass checks */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1532 if ((search_enumval( type->dico, ENUMVAL_BY_STRUCT, &request, &enumval ) == 0) && (enumval)) { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1533 /* We found a constant, get its name */ |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1534 const_name = enumval->data.enumval.enum_name; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1535 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1536 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1537 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1538 /* And finally, dump the value */ |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1539 CHECK_MALLOC_DO( dump_avp_val(FD_DUMP_STD_PARAMS, avp_value, get_default_dump_val_cb(model->data.avp.avp_basetype), dump_val_cb, model->data.avp.avp_basetype, type_name, const_name, indent, header), return NULL ); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1540 return *buf; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1541 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1542 |
0 | 1543 /*******************************************************************************************************/ |
1544 /*******************************************************************************************************/ | |
1545 /* */ | |
1546 /* Exported functions */ | |
1547 /* */ | |
1548 /*******************************************************************************************************/ | |
1549 /*******************************************************************************************************/ | |
1550 | |
1
bafb831ba688
Fix names to proper case for freeDiameter
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
0
diff
changeset
|
1551 /* These are the functions exported outside libfreeDiameter. */ |
0 | 1552 |
1553 /* Get the data associated to an object */ | |
1554 int fd_dict_gettype ( struct dict_object * object, enum dict_object_type * type) | |
1555 { | |
1556 TRACE_ENTRY("%p %p", object, type); | |
1557 | |
1558 CHECK_PARAMS( type && verify_object(object) ); | |
1559 | |
1560 /* Copy the value and return */ | |
1561 *type = object->type; | |
1562 return 0; | |
1563 } | |
1564 | |
1565 int fd_dict_getdict ( struct dict_object * object, struct dictionary ** dict) | |
1566 { | |
1567 TRACE_ENTRY("%p %p", object, dict); | |
1568 | |
1569 CHECK_PARAMS( dict && verify_object(object) ); | |
1570 | |
1571 /* Copy the value and return */ | |
1572 *dict = object->dico; | |
1573 return 0; | |
1574 } | |
1575 | |
1576 | |
1577 /* Get the data associated to an object */ | |
1578 int fd_dict_getval ( struct dict_object * object, void * val) | |
1579 { | |
1580 TRACE_ENTRY("%p %p", object, val); | |
1581 | |
1582 CHECK_PARAMS( val && verify_object(object) ); | |
1583 | |
1584 /* Copy the value and return */ | |
1585 memcpy(val, &object->data, _OBINFO(object).datasize);; | |
1586 return 0; | |
1587 } | |
1588 | |
1589 /* Add a new object in the dictionary */ | |
1590 int fd_dict_new ( struct dictionary * dict, enum dict_object_type type, void * data, struct dict_object * parent, struct dict_object **ref ) | |
1591 { | |
1592 int ret = 0; | |
1593 struct dict_object * new = NULL; | |
1594 struct dict_object * vendor = NULL; | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1595 struct dict_object * locref = NULL; |
0 | 1596 |
1597 TRACE_ENTRY("%p %d(%s) %p %p %p", dict, type, dict_obj_info[CHECK_TYPE(type) ? type : 0].name, data, parent, ref); | |
1598 | |
1599 /* Check parameters */ | |
1600 CHECK_PARAMS( dict && (dict->dict_eyec == DICT_EYECATCHER) && CHECK_TYPE(type) && data ); | |
1601 | |
1602 /* Check the "parent" parameter */ | |
1603 switch (dict_obj_info[type].parent) { | |
1604 case 0: /* parent is forbidden */ | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1605 CHECK_PARAMS_DO( parent == NULL, goto error_param ); |
0 | 1606 |
1607 case 1: /* parent is optional */ | |
1608 if (parent == NULL) | |
1609 break; | |
1610 | |
1611 case 2: /* parent is mandatory */ | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1612 CHECK_PARAMS_DO( verify_object(parent), goto error_param ); |
0 | 1613 |
1614 if (type == DICT_RULE ) { /* Special case : grouped AVP or Command parents are allowed */ | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1615 CHECK_PARAMS_DO( (parent->type == DICT_COMMAND ) |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1616 || ( (parent->type == DICT_AVP) && (parent->data.avp.avp_basetype == AVP_TYPE_GROUPED ) ), goto error_param ); |
0 | 1617 } else { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1618 CHECK_PARAMS_DO( parent->type == dict_obj_info[type].parenttype, goto error_param ); |
0 | 1619 } |
1620 } | |
1621 | |
1622 /* For AVP object, we must also check that the "vendor" referenced exists */ | |
1623 if (type == DICT_AVP) { | |
1624 CHECK_FCT_DO( fd_dict_search( dict, DICT_VENDOR, VENDOR_BY_ID, &(((struct dict_avp_data *)data)->avp_vendor), (void*)&vendor, ENOENT ), | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1625 { TRACE_DEBUG(INFO, "Unable to find vendor '%d' referenced in the AVP data", ((struct dict_avp_data *)data)->avp_vendor); goto error_param; } ); |
0 | 1626 |
1627 /* Also check if a parent is provided, that the type are the same */ | |
1628 if (parent) { | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1629 CHECK_PARAMS_DO( parent->data.type.type_base == ((struct dict_avp_data *)data)->avp_basetype, goto error_param ); |
0 | 1630 } |
1631 } | |
1632 | |
1633 /* For RULE object, we must also check that the "avp" referenced exists */ | |
1634 if (type == DICT_RULE) { | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1635 CHECK_PARAMS_DO( verify_object(((struct dict_rule_data *)data)->rule_avp), goto error_param ); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1636 CHECK_PARAMS_DO( ((struct dict_rule_data *)data)->rule_avp->type == DICT_AVP, goto error_param ); |
0 | 1637 } |
1638 | |
1639 /* For COMMAND object, check that the 'R' flag is fixed */ | |
1640 if (type == DICT_COMMAND) { | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1641 CHECK_PARAMS_DO( ((struct dict_cmd_data *)data)->cmd_flag_mask & CMD_FLAG_REQUEST, goto error_param ); |
0 | 1642 } |
1643 | |
109
a522268ec95b
Less permissive in fd_dict_new
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1644 /* We have to check that the new values are not equal to the sentinels */ |
a522268ec95b
Less permissive in fd_dict_new
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1645 if (type == DICT_VENDOR) { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1646 CHECK_PARAMS_DO( ((struct dict_vendor_data *)data)->vendor_id != 0, goto error_param ); |
109
a522268ec95b
Less permissive in fd_dict_new
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1647 } |
a522268ec95b
Less permissive in fd_dict_new
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1648 if (type == DICT_APPLICATION) { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1649 CHECK_PARAMS_DO( ((struct dict_application_data *)data)->application_id != 0, goto error_param ); |
109
a522268ec95b
Less permissive in fd_dict_new
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1650 } |
a522268ec95b
Less permissive in fd_dict_new
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1651 |
0 | 1652 /* Parameters are valid, create the new object */ |
1653 CHECK_MALLOC( new = malloc(sizeof(struct dict_object)) ); | |
1654 | |
1655 /* Initialize the data of the new object */ | |
1656 init_object(new, type); | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1657 init_object_data(new, data, type); |
0 | 1658 new->dico = dict; |
1659 new->parent = parent; | |
1660 | |
1661 /* We will change the dictionary => acquire the write lock */ | |
1662 CHECK_POSIX_DO( ret = pthread_rwlock_wrlock(&dict->dict_lock), goto error_free ); | |
1663 | |
1664 /* Now link the object -- this also checks that no object with same keys already exists */ | |
1665 switch (type) { | |
1666 case DICT_VENDOR: | |
1667 /* A vendor object is linked in the g_dict_vendors.list[0], by their id */ | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1668 ret = fd_list_insert_ordered ( &dict->dict_vendors.list[0], &new->list[0], (int (*)(void*, void *))order_vendor_by_id, (void **)&locref ); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1669 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1670 goto error_unlock; |
0 | 1671 break; |
1672 | |
1673 case DICT_APPLICATION: | |
1674 /* An application object is linked in the g_dict_applciations.list[0], by their id */ | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1675 ret = fd_list_insert_ordered ( &dict->dict_applications.list[0], &new->list[0], (int (*)(void*, void *))order_appli_by_id, (void **)&locref ); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1676 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1677 goto error_unlock; |
0 | 1678 break; |
1679 | |
1680 case DICT_TYPE: | |
1681 /* A type object is linked in g_list_types by its name */ | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1682 ret = fd_list_insert_ordered ( &dict->dict_types, &new->list[0], (int (*)(void*, void *))order_type_by_name, (void **)&locref ); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1683 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1684 goto error_unlock; |
0 | 1685 break; |
1686 | |
1687 case DICT_ENUMVAL: | |
1688 /* A type_enum object is linked in it's parent 'type' object lists 1 and 2 by its name and values */ | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1689 ret = fd_list_insert_ordered ( &parent->list[1], &new->list[0], (int (*)(void*, void *))order_enum_by_name, (void **)&locref ); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1690 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1691 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1692 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1693 ret = fd_list_insert_ordered ( &parent->list[2], &new->list[1], (int (*)(void*, void *))order_enum_by_val, (void **)&locref ); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1694 if (ret) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1695 fd_list_unlink(&new->list[0]); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1696 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1697 } |
0 | 1698 break; |
1699 | |
1700 case DICT_AVP: | |
1701 /* An avp object is linked in lists 1 and 2 of its vendor, by code and name */ | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1702 ret = fd_list_insert_ordered ( &vendor->list[1], &new->list[0], (int (*)(void*, void *))order_avp_by_code, (void **)&locref ); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1703 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1704 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1705 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1706 ret = fd_list_insert_ordered ( &vendor->list[2], &new->list[1], (int (*)(void*, void *))order_avp_by_name, (void **)&locref ); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1707 if (ret) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1708 fd_list_unlink(&new->list[0]); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1709 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1710 } |
0 | 1711 break; |
1712 | |
1713 case DICT_COMMAND: | |
1714 /* A command object is linked in g_list_cmd_name and g_list_cmd_code by its name and code */ | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1715 ret = fd_list_insert_ordered ( &dict->dict_cmd_code, &new->list[1], (int (*)(void*, void *))order_cmd_by_codefl, (void **)&locref ); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1716 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1717 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1718 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1719 ret = fd_list_insert_ordered ( &dict->dict_cmd_name, &new->list[0], (int (*)(void*, void *))order_cmd_by_name, (void **)&locref ); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1720 if (ret) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1721 fd_list_unlink(&new->list[1]); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1722 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1723 } |
0 | 1724 break; |
1725 | |
1726 case DICT_RULE: | |
1727 /* A rule object is linked in list[2] of its parent command or AVP by the name of the AVP it refers */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1728 ret = fd_list_insert_ordered ( &parent->list[2], &new->list[0], (int (*)(void*, void *))order_rule_by_avpvc, (void **)&locref ); |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1729 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1730 goto error_unlock; |
0 | 1731 break; |
1732 | |
1733 default: | |
1734 ASSERT(0); | |
1735 } | |
1736 | |
1737 /* A new object has been created, increment the global counter */ | |
1738 dict->dict_count[type]++; | |
1739 | |
1740 /* Unlock the dictionary */ | |
1741 CHECK_POSIX_DO( ret = pthread_rwlock_unlock(&dict->dict_lock), goto error_free ); | |
1742 | |
1743 /* Save the pointer to the new object */ | |
1744 if (ref) | |
1745 *ref = new; | |
1746 | |
1747 return 0; | |
1748 | |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1749 error_param: |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1750 ret = EINVAL; |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1751 goto all_errors; |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1752 |
0 | 1753 error_unlock: |
1754 CHECK_POSIX_DO( pthread_rwlock_unlock(&dict->dict_lock), /* continue */ ); | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1755 if (ret == EEXIST) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1756 /* We have a duplicate key in locref. Check if the pointed object is the same or not */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1757 switch (type) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1758 case DICT_VENDOR: |
952
17ac99255475
Be explicit which entry already exists in the dictionary.
Thomas Klausner <tk@giga.or.at>
parents:
949
diff
changeset
|
1759 TRACE_DEBUG(FULL, "Vendor %s already in dictionary", new->data.vendor.vendor_name); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1760 /* if we are here, it means the two vendors id are identical */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1761 if (fd_os_cmp(locref->data.vendor.vendor_name, locref->datastr_len, |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1762 new->data.vendor.vendor_name, new->datastr_len)) { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1763 TRACE_DEBUG(INFO, "Conflicting vendor name: %s", new->data.vendor.vendor_name); |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1764 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1765 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1766 /* Otherwise (same name), we consider the function succeeded, since the (same) object is in the dictionary */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1767 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1768 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1769 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1770 case DICT_APPLICATION: |
952
17ac99255475
Be explicit which entry already exists in the dictionary.
Thomas Klausner <tk@giga.or.at>
parents:
949
diff
changeset
|
1771 TRACE_DEBUG(FULL, "Application %s already in dictionary", new->data.application.application_name); |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1772 /* got same id */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1773 if (fd_os_cmp(locref->data.application.application_name, locref->datastr_len, |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1774 new->data.application.application_name, new->datastr_len)) { |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1775 TRACE_DEBUG(FULL, "Conflicting application name"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1776 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1777 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1778 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1779 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1780 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1781 case DICT_TYPE: |
952
17ac99255475
Be explicit which entry already exists in the dictionary.
Thomas Klausner <tk@giga.or.at>
parents:
949
diff
changeset
|
1782 TRACE_DEBUG(FULL, "Type %s already in dictionary", new->data.type.type_name); |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1783 /* got same name */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1784 if (locref->data.type.type_base != new->data.type.type_base) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1785 TRACE_DEBUG(FULL, "Conflicting base type"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1786 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1787 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1788 /* discard new definition only it a callback is provided and different from the previous one */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1789 if ((new->data.type.type_interpret) && (locref->data.type.type_interpret != new->data.type.type_interpret)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1790 TRACE_DEBUG(FULL, "Conflicting interpret cb"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1791 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1792 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1793 if ((new->data.type.type_encode) && (locref->data.type.type_encode != new->data.type.type_encode)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1794 TRACE_DEBUG(FULL, "Conflicting encode cb"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1795 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1796 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1797 if ((new->data.type.type_dump) && (locref->data.type.type_dump != new->data.type.type_dump)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1798 TRACE_DEBUG(FULL, "Conflicting dump cb"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1799 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1800 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1801 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1802 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1803 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1804 case DICT_ENUMVAL: |
952
17ac99255475
Be explicit which entry already exists in the dictionary.
Thomas Klausner <tk@giga.or.at>
parents:
949
diff
changeset
|
1805 TRACE_DEBUG(FULL, "Enum %s already in dictionary", new->data.enumval.enum_name); |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1806 /* got either same name or same value. We check that both are true */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1807 if (order_enum_by_name(locref, new)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1808 TRACE_DEBUG(FULL, "Conflicting enum name"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1809 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1810 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1811 if (order_enum_by_val(locref, new)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1812 TRACE_DEBUG(FULL, "Conflicting enum value"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1813 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1814 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1815 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1816 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1817 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1818 case DICT_AVP: |
952
17ac99255475
Be explicit which entry already exists in the dictionary.
Thomas Klausner <tk@giga.or.at>
parents:
949
diff
changeset
|
1819 TRACE_DEBUG(FULL, "AVP %s already in dictionary", new->data.avp.avp_name); |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1820 /* got either same name or code */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1821 if (order_avp_by_code(locref, new)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1822 TRACE_DEBUG(FULL, "Conflicting AVP code"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1823 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1824 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1825 if (order_avp_by_name(locref, new)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1826 TRACE_DEBUG(FULL, "Conflicting AVP name"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1827 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1828 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1829 if (locref->data.avp.avp_vendor != new->data.avp.avp_vendor) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1830 TRACE_DEBUG(FULL, "Conflicting AVP vendor"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1831 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1832 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1833 if (locref->data.avp.avp_flag_mask != new->data.avp.avp_flag_mask) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1834 TRACE_DEBUG(FULL, "Conflicting AVP flags mask"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1835 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1836 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1837 if ((locref->data.avp.avp_flag_val & locref->data.avp.avp_flag_mask) != (new->data.avp.avp_flag_val & new->data.avp.avp_flag_mask)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1838 TRACE_DEBUG(FULL, "Conflicting AVP flags value"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1839 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1840 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1841 if (locref->data.avp.avp_basetype != new->data.avp.avp_basetype) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1842 TRACE_DEBUG(FULL, "Conflicting AVP base type"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1843 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1844 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1845 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1846 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1847 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1848 case DICT_COMMAND: |
952
17ac99255475
Be explicit which entry already exists in the dictionary.
Thomas Klausner <tk@giga.or.at>
parents:
949
diff
changeset
|
1849 TRACE_DEBUG(FULL, "Command %s already in dictionary", new->data.cmd.cmd_name); |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1850 /* We got either same name, or same code + R flag */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1851 if (order_cmd_by_name(locref, new)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1852 TRACE_DEBUG(FULL, "Conflicting command name"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1853 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1854 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1855 if (locref->data.cmd.cmd_code != new->data.cmd.cmd_code) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1856 TRACE_DEBUG(FULL, "Conflicting command code"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1857 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1858 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1859 if (locref->data.cmd.cmd_flag_mask != new->data.cmd.cmd_flag_mask) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1860 TRACE_DEBUG(FULL, "Conflicting command flags mask %hhx:%hhx", locref->data.cmd.cmd_flag_mask, new->data.cmd.cmd_flag_mask); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1861 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1862 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1863 if ((locref->data.cmd.cmd_flag_val & locref->data.cmd.cmd_flag_mask) != (new->data.cmd.cmd_flag_val & new->data.cmd.cmd_flag_mask)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1864 TRACE_DEBUG(FULL, "Conflicting command flags value"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1865 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1866 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1867 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1868 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1869 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1870 case DICT_RULE: |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1871 /* Both rules point to the same AVPs (code & vendor) */ |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1872 if (locref->data.rule.rule_position != new->data.rule.rule_position) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1873 TRACE_DEBUG(FULL, "Conflicting rule position"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1874 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1875 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1876 if ( ((locref->data.rule.rule_position == RULE_FIXED_HEAD) || |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1877 (locref->data.rule.rule_position == RULE_FIXED_TAIL)) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1878 && (locref->data.rule.rule_order != new->data.rule.rule_order)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1879 TRACE_DEBUG(FULL, "Conflicting rule order"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1880 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1881 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1882 if (locref->data.rule.rule_min != new->data.rule.rule_min) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1883 int r1 = locref->data.rule.rule_min; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1884 int r2 = new->data.rule.rule_min; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1885 int p = locref->data.rule.rule_position; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1886 if ( ((r1 != -1) && (r2 != -1)) /* none of the definitions contains the "default" value */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1887 || ((p == RULE_OPTIONAL) && (r1 != 0) && (r2 != 0)) /* the other value is not 0 for an optional rule */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1888 || ((r1 != 1) && (r2 != 1)) /* the other value is not 1 for another rule */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1889 ) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1890 TRACE_DEBUG(FULL, "Conflicting rule min"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1891 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1892 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1893 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1894 if (locref->data.rule.rule_max != new->data.rule.rule_max) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1895 TRACE_DEBUG(FULL, "Conflicting rule max"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1896 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1897 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1898 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1899 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1900 } |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1901 if (!ret) { |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1902 TRACE_DEBUG(FULL, "An existing object with the same data was found, ignoring the error..."); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1903 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1904 if (ref) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1905 *ref = locref; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1906 } |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1907 all_errors: |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1908 if (ret != 0) { |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1909 char * buf = NULL; |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1910 size_t len = 0; |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1911 |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1912 CHECK_MALLOC( dict_obj_info[CHECK_TYPE(type) ? type : 0].dump_data(&buf, &len, NULL, data) ); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1913 TRACE_DEBUG(INFO, "An error occurred while adding the following data in the dictionary: %s", buf); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1914 |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1915 if (ret == EEXIST) { |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1916 CHECK_MALLOC( dump_object(&buf, &len, NULL, locref, 0, 0, 0) ); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1917 TRACE_DEBUG(INFO, "Conflicting entry in the dictionary: %s", buf); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1918 } |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1919 free(buf); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1052
diff
changeset
|
1920 } |
0 | 1921 error_free: |
1922 free(new); | |
1923 return ret; | |
1924 } | |
1925 | |
778
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1926 |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1927 int fd_dict_delete(struct dict_object * obj) |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1928 { |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1929 int i; |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1930 struct dictionary * dict; |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1931 int ret=0; |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1932 |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1933 /* check params */ |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1934 CHECK_PARAMS( verify_object(obj) && obj->dico); |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1935 dict = obj->dico; |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1936 |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1937 /* Lock the dictionary for change */ |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1938 CHECK_POSIX( pthread_rwlock_wrlock(&dict->dict_lock) ); |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1939 |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1940 /* check the object is not sentinel for another list */ |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1941 for (i=0; i<NB_LISTS_PER_OBJ; i++) { |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1942 if (!_OBINFO(obj).haslist[i] && !(FD_IS_LIST_EMPTY(&obj->list[i]))) { |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1943 /* There are children, this is not good */ |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1944 ret = EINVAL; |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1945 TRACE_DEBUG (FULL, "Cannot delete object, list %d not empty:", i); |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1946 #if 0 |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1947 dump_list(&obj->list[i], 0,0,0); |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1948 #endif |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1949 break; |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1950 } |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1951 } |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1952 |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1953 /* ok, now destroy the object */ |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1954 if (!ret) |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1955 destroy_object(obj); |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1956 |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1957 /* Unlock */ |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1958 CHECK_POSIX( pthread_rwlock_unlock(&dict->dict_lock) ); |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1959 |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1960 return ret; |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1961 } |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1962 |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
770
diff
changeset
|
1963 |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
1964 int fd_dict_search ( struct dictionary * dict, enum dict_object_type type, int criteria, const void * what, struct dict_object **result, int retval ) |
0 | 1965 { |
1966 int ret = 0; | |
1967 | |
1968 TRACE_ENTRY("%p %d(%s) %d %p %p %d", dict, type, dict_obj_info[CHECK_TYPE(type) ? type : 0].name, criteria, what, result, retval); | |
1969 | |
1970 /* Check param */ | |
1971 CHECK_PARAMS( dict && (dict->dict_eyec == DICT_EYECATCHER) && CHECK_TYPE(type) ); | |
1972 | |
1973 /* Lock the dictionary for reading */ | |
1974 CHECK_POSIX( pthread_rwlock_rdlock(&dict->dict_lock) ); | |
1975 | |
1976 /* Now call the type-specific search function */ | |
1977 ret = dict_obj_info[type].search_fct (dict, criteria, what, result); | |
1978 | |
1979 /* Unlock */ | |
1980 CHECK_POSIX( pthread_rwlock_unlock(&dict->dict_lock) ); | |
1981 | |
1982 /* Update the return value as needed */ | |
1983 if ((result != NULL) && (*result == NULL)) | |
1984 ret = retval; | |
1985 | |
1986 return ret; | |
1987 } | |
1988 | |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1989 /* Function to retrieve list of objects in the dictionary. Use with care (read only). |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1990 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1991 All returned list must be accessed like this: |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1992 |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
1993 for (li = sentinel->next; li != sentinel; li=li->next) { |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1994 struct dict_object * obj = li->o; |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1995 ... |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1996 } |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1997 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1998 The following criteria are allowed, with corresponding parent. |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1999 The parent is either struct dictionary * or struct dict_object * |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2000 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2001 VENDOR_BY_ID : (parent = dictionary) returns list of vendors ordered by ID |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2002 APPLICATION_BY_ID : (parent = dictionary) returns list of applications ordered by ID |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2003 ** for these two lists, the Vendor with id 0 and applciation with id 0 are excluded. |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2004 You must resolve them separatly with dict_search. |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2005 |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2006 TYPE_BY_NAME : (parent = dictionary) returns list of types ordered by name (osstring order) |
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2007 ENUMVAL_BY_NAME : (parent = type object) return list of constants for this type ordered by name (osstring order) |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2008 ENUMVAL_BY_VALUE : (parent = type object) return list of constants for this type ordered by values |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2009 AVP_BY_NAME : (parent = vendor object) return list of AVP for this vendor ordered by name (osstring order) |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2010 AVP_BY_CODE : (parent = vendor object) return list of AVP for this vendor ordered by code |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2011 CMD_BY_NAME : (parent = dictionary) returns list of commands ordered by name (osstring order) |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2012 CMD_BY_CODE_R : (parent = dictionary) returns list of commands ordered by code |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2013 RULE_BY_AVP_AND_PARENT: (parent = command or grouped AVP object) return list of rules for this object ordered by AVP vendor/code |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2014 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2015 All other criteria are rejected. |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2016 */ |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2017 int fd_dict_getlistof(int criteria, void * parent, struct fd_list ** sentinel) |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2018 { |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2019 struct dictionary * dict = parent; |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2020 struct dict_object * obj_parent = parent; |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2021 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2022 TRACE_ENTRY("%i %p %p", criteria, parent, sentinel); |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2023 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2024 CHECK_PARAMS(sentinel && parent); |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2025 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2026 switch(criteria) { |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2027 case VENDOR_BY_ID: /* parent must be the dictionary */ |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2028 CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER); |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2029 *sentinel = &dict->dict_vendors.list[0]; |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2030 break; |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2031 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2032 case APPLICATION_BY_ID: /* parent must be the dictionary */ |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2033 CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER); |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2034 *sentinel = &dict->dict_applications.list[0]; |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2035 break; |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2036 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2037 case TYPE_BY_NAME: /* parent must be the dictionary */ |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2038 CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER); |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2039 *sentinel = &dict->dict_types; |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2040 break; |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2041 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2042 case ENUMVAL_BY_NAME: /* parent must be a type object */ |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2043 CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_TYPE)); |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2044 *sentinel = &obj_parent->list[1]; |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2045 break; |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2046 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2047 case ENUMVAL_BY_VALUE: /* parent must be a type object */ |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2048 CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_TYPE)); |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2049 *sentinel = &obj_parent->list[2]; |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2050 break; |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2051 |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2052 case AVP_BY_NAME: /* parent must be a VENDOR object */ |
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2053 CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_VENDOR)); |
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2054 *sentinel = &obj_parent->list[2]; |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2055 break; |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2056 |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2057 case AVP_BY_CODE: /* parent must be a VENDOR object */ |
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2058 CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_VENDOR)); |
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2059 *sentinel = &obj_parent->list[1]; |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2060 break; |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2061 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2062 case CMD_BY_NAME: /* parent must be the dictionary */ |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2063 CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER); |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2064 *sentinel = &dict->dict_cmd_name; |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2065 break; |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2066 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2067 case CMD_BY_CODE_R: /* parent must be the dictionary */ |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2068 CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER); |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2069 *sentinel = &dict->dict_cmd_code; |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2070 break; |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2071 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2072 case RULE_BY_AVP_AND_PARENT: /* parent must be command or grouped AVP */ |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2073 CHECK_PARAMS(verify_object(obj_parent)); |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2074 CHECK_PARAMS( (obj_parent->type == DICT_COMMAND) || |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2075 ((obj_parent->type == DICT_AVP) |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2076 && (obj_parent->data.avp.avp_basetype == AVP_TYPE_GROUPED)) ); |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2077 *sentinel = &obj_parent->list[2]; |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2078 break; |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2079 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2080 default: |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2081 CHECK_PARAMS(0); |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2082 } |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2083 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2084 return 0; |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2085 } |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2086 |
0 | 2087 /*******************************************************************************************************/ |
2088 /*******************************************************************************************************/ | |
2089 /* */ | |
2090 /* The init/fini functions */ | |
2091 /* */ | |
2092 /*******************************************************************************************************/ | |
2093 /*******************************************************************************************************/ | |
2094 | |
2095 /* Initialize the dictionary */ | |
2096 int fd_dict_init ( struct dictionary ** dict) | |
2097 { | |
2098 struct dictionary * new = NULL; | |
2099 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
2100 TRACE_ENTRY("%p", dict); |
0 | 2101 |
2102 /* Sanity checks */ | |
2103 ASSERT( (sizeof(type_base_name) / sizeof(type_base_name[0])) == (AVP_TYPE_MAX + 1) ); | |
2104 ASSERT( (sizeof(dict_obj_info) / sizeof(dict_obj_info[0])) == (DICT_TYPE_MAX + 1) ); | |
2105 CHECK_PARAMS(dict); | |
2106 | |
2107 /* Allocate the memory for the dictionary */ | |
2108 CHECK_MALLOC( new = malloc(sizeof(struct dictionary)) ); | |
2109 memset(new, 0, sizeof(struct dictionary)); | |
2110 | |
2111 new->dict_eyec = DICT_EYECATCHER; | |
2112 | |
2113 /* Initialize the lock for the dictionary */ | |
2114 CHECK_POSIX( pthread_rwlock_init(&new->dict_lock, NULL) ); | |
2115 | |
2116 /* Initialize the sentinel for vendors and AVP lists */ | |
2117 init_object( &new->dict_vendors, DICT_VENDOR ); | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
2118 #define NO_VENDOR_NAME "(no vendor)" |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
2119 new->dict_vendors.data.vendor.vendor_name = NO_VENDOR_NAME; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
2120 new->dict_vendors.datastr_len = CONSTSTRLEN(NO_VENDOR_NAME); |
770
27fef2ca2cf6
Improved usability of fd_dict_getlistof for vendors and apps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
769
diff
changeset
|
2121 /* new->dict_vendors.list[0].o = NULL; *//* overwrite since element is also sentinel for this list. */ |
111
3b6174b6b35b
Fix fd_dict_getdict command for sentinels in the dictionary
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
109
diff
changeset
|
2122 new->dict_vendors.dico = new; |
0 | 2123 |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2124 /* Initialize the sentinel for applications */ |
0 | 2125 init_object( &new->dict_applications, DICT_APPLICATION ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
2126 #define APPLICATION_0_NAME "Diameter Common Messages" |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
2127 new->dict_applications.data.application.application_name = APPLICATION_0_NAME; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
2128 new->dict_applications.datastr_len = CONSTSTRLEN(APPLICATION_0_NAME); |
770
27fef2ca2cf6
Improved usability of fd_dict_getlistof for vendors and apps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
769
diff
changeset
|
2129 /* new->dict_applications.list[0].o = NULL; *//* overwrite since since element is also sentinel for this list. */ |
111
3b6174b6b35b
Fix fd_dict_getdict command for sentinels in the dictionary
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
109
diff
changeset
|
2130 new->dict_applications.dico = new; |
0 | 2131 |
2132 /* Initialize the sentinel for types */ | |
2133 fd_list_init ( &new->dict_types, NULL ); | |
2134 | |
2135 /* Initialize the sentinels for commands */ | |
2136 fd_list_init ( &new->dict_cmd_name, NULL ); | |
2137 fd_list_init ( &new->dict_cmd_code, NULL ); | |
2138 | |
2139 /* Initialize the error command object */ | |
2140 init_object( &new->dict_cmd_error, DICT_COMMAND ); | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
2141 #define GENERIC_ERROR_NAME "(generic error format)" |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
2142 new->dict_cmd_error.data.cmd.cmd_name = GENERIC_ERROR_NAME; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
2143 new->dict_cmd_error.datastr_len = CONSTSTRLEN(GENERIC_ERROR_NAME); |
0 | 2144 new->dict_cmd_error.data.cmd.cmd_flag_mask=CMD_FLAG_ERROR | CMD_FLAG_REQUEST | CMD_FLAG_RETRANSMIT; |
2145 new->dict_cmd_error.data.cmd.cmd_flag_val =CMD_FLAG_ERROR; | |
111
3b6174b6b35b
Fix fd_dict_getdict command for sentinels in the dictionary
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
109
diff
changeset
|
2146 new->dict_cmd_error.dico = new; |
0 | 2147 |
2148 *dict = new; | |
2149 | |
2150 /* Done */ | |
2151 return 0; | |
2152 } | |
2153 | |
2154 /* Destroy a dictionary */ | |
2155 int fd_dict_fini ( struct dictionary ** dict) | |
2156 { | |
2157 int i; | |
2158 | |
2159 TRACE_ENTRY(""); | |
2160 CHECK_PARAMS( dict && *dict && ((*dict)->dict_eyec == DICT_EYECATCHER) ); | |
2161 | |
2162 /* Acquire the write lock to make sure no other operation is ongoing */ | |
2163 CHECK_POSIX( pthread_rwlock_wrlock(&(*dict)->dict_lock) ); | |
2164 | |
2165 /* Empty all the lists, free the elements */ | |
2166 destroy_list ( &(*dict)->dict_cmd_error.list[2] ); | |
2167 destroy_list ( &(*dict)->dict_cmd_code ); | |
2168 destroy_list ( &(*dict)->dict_cmd_name ); | |
2169 destroy_list ( &(*dict)->dict_types ); | |
2170 for (i=0; i< NB_LISTS_PER_OBJ; i++) { | |
2171 destroy_list ( &(*dict)->dict_applications.list[i] ); | |
2172 destroy_list ( &(*dict)->dict_vendors.list[i] ); | |
2173 } | |
2174 | |
2175 /* Dictionary is empty, now destroy the lock */ | |
2176 CHECK_POSIX( pthread_rwlock_unlock(&(*dict)->dict_lock) ); | |
2177 CHECK_POSIX( pthread_rwlock_destroy(&(*dict)->dict_lock) ); | |
2178 | |
2179 free(*dict); | |
2180 *dict = NULL; | |
2181 | |
2182 return 0; | |
2183 } | |
2184 | |
2185 /*******************************************************************************************************/ | |
2186 /*******************************************************************************************************/ | |
2187 /* */ | |
2188 /* Other functions */ | |
2189 /* */ | |
2190 /*******************************************************************************************************/ | |
2191 /*******************************************************************************************************/ | |
2192 | |
2193 /* Iterate a callback on the rules for an object */ | |
2194 int fd_dict_iterate_rules ( struct dict_object *parent, void * data, int (*cb)(void *, struct dict_rule_data *) ) | |
2195 { | |
2196 int ret = 0; | |
2197 struct fd_list * li; | |
2198 | |
2199 TRACE_ENTRY("%p %p %p", parent, data, cb); | |
2200 | |
2201 /* Check parameters */ | |
2202 CHECK_PARAMS( verify_object(parent) ); | |
2203 CHECK_PARAMS( (parent->type == DICT_COMMAND) | |
2204 || ((parent->type == DICT_AVP) && (parent->data.avp.avp_basetype == AVP_TYPE_GROUPED)) ); | |
2205 TRACE_DEBUG (FULL, "Iterating on rules of %s: '%s'.", | |
2206 _OBINFO(parent).name, | |
2207 parent->type == DICT_COMMAND ? | |
2208 parent->data.cmd.cmd_name | |
2209 : parent->data.avp.avp_name); | |
2210 | |
2211 /* Acquire the read lock */ | |
2212 CHECK_POSIX( pthread_rwlock_rdlock(&parent->dico->dict_lock) ); | |
2213 | |
2214 /* go through the list and call the cb on each rule data */ | |
2215 for (li = &(parent->list[2]); li->next != &(parent->list[2]); li = li->next) { | |
2216 ret = (*cb)(data, &(_O(li->next->o)->data.rule)); | |
2217 if (ret != 0) | |
2218 break; | |
2219 } | |
2220 | |
2221 /* Release the lock */ | |
2222 CHECK_POSIX( pthread_rwlock_unlock(&parent->dico->dict_lock) ); | |
2223 | |
2224 return ret; | |
2225 } | |
2226 | |
2227 /* Create the list of vendors. Returns a 0-terminated array, that must be freed after use. Returns NULL on error. */ | |
2228 uint32_t * fd_dict_get_vendorid_list(struct dictionary * dict) | |
2229 { | |
2230 uint32_t * ret = NULL; | |
2231 int i = 0; | |
2232 struct fd_list * li; | |
2233 | |
2234 TRACE_ENTRY(); | |
2235 | |
2236 /* Acquire the read lock */ | |
2237 CHECK_POSIX_DO( pthread_rwlock_rdlock(&dict->dict_lock), return NULL ); | |
2238 | |
2239 /* Allocate an array to contain all the elements */ | |
2240 CHECK_MALLOC_DO( ret = calloc( dict->dict_count[DICT_VENDOR] + 1, sizeof(uint32_t) ), goto out ); | |
2241 | |
2242 /* Copy the vendors IDs */ | |
2243 for (li = dict->dict_vendors.list[0].next; li != &(dict->dict_vendors.list[0]); li = li->next) { | |
2244 ret[i] = _O(li->o)->data.vendor.vendor_id; | |
2245 i++; | |
2246 ASSERT( i <= dict->dict_count[DICT_VENDOR] ); | |
2247 } | |
2248 out: | |
2249 /* Release the lock */ | |
2250 CHECK_POSIX_DO( pthread_rwlock_unlock(&dict->dict_lock), return NULL ); | |
2251 | |
2252 return ret; | |
2253 } | |
2254 | |
2255 /* Return the location of the cb list for an object, after checking its type */ | |
2256 int fd_dict_disp_cb(enum dict_object_type type, struct dict_object *obj, struct fd_list ** cb_list) | |
2257 { | |
2258 TRACE_ENTRY("%d %p %p", type, obj, cb_list); | |
2259 CHECK_PARAMS( verify_object(obj) ); | |
2260 CHECK_PARAMS( _OBINFO(obj).type == type ); | |
2261 CHECK_PARAMS( cb_list ); | |
2262 *cb_list = &obj->disp_cbs; | |
2263 return 0; | |
2264 } | |
2265 | |
2266 int fd_dict_get_error_cmd(struct dictionary * dict, struct dict_object **obj) | |
2267 { | |
2268 TRACE_ENTRY("%p %p", dict, obj); | |
2269 CHECK_PARAMS( dict && (dict->dict_eyec == DICT_EYECATCHER) && obj ); | |
2270 *obj = &dict->dict_cmd_error; | |
2271 return 0; | |
2272 } |