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