Mercurial > hg > freeDiameter
annotate libfdproto/dictionary.c @ 906:ebe479bfcd4b
Fix typo in new code
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Sat, 15 Dec 2012 19:06:21 +0100 |
parents | 4382d7420e65 |
children | b772af200865 |
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 | |
903
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
979 case AVP_BY_STRUCT: |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
980 { |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
981 struct dict_avp_request_ex * _what = (struct dict_avp_request_ex *) what; |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
982 struct dict_object * vendor = NULL; |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
983 |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
984 CHECK_PARAMS( _what->avp_vendor.vendor || _what->avp_vendor.vendor_id || _what->avp_vendor.vendor_name ); |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
985 CHECK_PARAMS( _what->avp_data.avp_code || _what->avp_data.avp_name ); |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
986 |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
987 /* Now look for the vendor first */ |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
988 if (_what->avp_vendor.vendor) { |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
989 CHECK_PARAMS( ! _what->avp_vendor.vendor_id && ! _what->avp_vendor.vendor_name ); |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
990 vendor = _what->avp_vendor.vendor; |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
991 } else if (_what->avp_vendor.vendor_id) { |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
992 CHECK_PARAMS( ! _what->avp_vendor.vendor_name ); |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
993 CHECK_FCT( search_vendor( dict, VENDOR_BY_ID, &_what->avp_vendor.vendor_id, &vendor ) ); |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
994 } else { |
906
ebe479bfcd4b
Fix typo in new code
Sebastien Decugis <sdecugis@freediameter.net>
parents:
903
diff
changeset
|
995 CHECK_FCT( search_vendor( dict, VENDOR_BY_NAME, _what->avp_vendor.vendor_name, &vendor ) ); |
903
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
996 } |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
997 |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
998 if (vendor == NULL) { |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
999 if (result) |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1000 *result = NULL; |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1001 else |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1002 ret = ENOENT; |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1003 goto end; |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1004 } |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1005 |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1006 /* We now have our vendor = head of the appropriate avp list */ |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1007 if (_what->avp_data.avp_code) { |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1008 CHECK_PARAMS( ! _what->avp_data.avp_name ); |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1009 SEARCH_scalar( _what->avp_data.avp_code, &vendor->list[1], avp.avp_code, 1, (struct dict_object *)NULL ); |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1010 } else { |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1011 SEARCH_os0( _what->avp_data.avp_name, &vendor->list[2], avp.avp_name, 1); |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1012 } |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1013 } |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1014 break; |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1015 |
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
|
1016 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
|
1017 { |
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1018 struct fd_list * li; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1019 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
|
1020 |
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1021 /* First, search for vendor 0 */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1022 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
|
1023 |
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1024 /* 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
|
1025 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
|
1026 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
|
1027 } |
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1028 } |
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1029 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
|
1030 |
0 | 1031 default: |
1032 /* Invalid criteria */ | |
1033 CHECK_PARAMS( criteria = 0 ); | |
1034 } | |
1035 end: | |
1036 return ret; | |
1037 } | |
1038 | |
1039 static int search_cmd ( struct dictionary * dict, int criteria, void * what, struct dict_object **result ) | |
1040 { | |
1041 int ret = 0; | |
1042 | |
1043 TRACE_ENTRY("%p %d %p %p", dict, criteria, what, result); | |
1044 | |
1045 switch (criteria) { | |
1046 case CMD_BY_NAME: | |
1047 /* "what" is a command name */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1048 SEARCH_os0( what, &dict->dict_cmd_name, cmd.cmd_name, 1); |
0 | 1049 break; |
1050 | |
1051 case CMD_BY_CODE_R: | |
1052 case CMD_BY_CODE_A: | |
1053 { | |
1054 command_code_t code; | |
1055 uint8_t searchfl = 0; | |
1056 | |
1057 /* The command code that we are searching */ | |
1058 code = *(command_code_t *) what; | |
1059 | |
1060 /* The flag (request or answer) of the command we are searching */ | |
1061 if (criteria == CMD_BY_CODE_R) { | |
1062 searchfl = CMD_FLAG_REQUEST; | |
1063 } | |
1064 | |
1065 /* perform the search */ | |
1066 SEARCH_codefl( code, searchfl, &dict->dict_cmd_code ); | |
1067 } | |
1068 break; | |
1069 | |
1070 case CMD_ANSWER: | |
1071 { | |
1072 /* "what" is a command object of type "request" */ | |
1073 struct dict_object * req = (struct dict_object *) what; | |
1074 struct dict_object * ans = NULL; | |
1075 | |
1076 CHECK_PARAMS( verify_object(req) | |
1077 && (req->type == DICT_COMMAND) | |
1078 && (req->data.cmd.cmd_flag_mask & CMD_FLAG_REQUEST) | |
1079 && (req->data.cmd.cmd_flag_val & CMD_FLAG_REQUEST) ); | |
1080 | |
1081 /* The answer is supposed to be the next element in the list, if it exists */ | |
1082 ans = req->list[1].next->o; | |
1083 if ( ans == NULL ) { | |
1084 TRACE_DEBUG( FULL, "the request was the last element in the list" ); | |
1085 ret = ENOENT; | |
1086 goto end; | |
1087 } | |
1088 | |
1089 /* Now check that the ans element is really the correct one */ | |
1090 if ( (ans->data.cmd.cmd_code != req->data.cmd.cmd_code) | |
1091 || (!(ans->data.cmd.cmd_flag_mask & CMD_FLAG_REQUEST)) | |
1092 || ( ans->data.cmd.cmd_flag_val & CMD_FLAG_REQUEST ) ) { | |
1093 TRACE_DEBUG( FULL, "the answer does not follow the request in the list" ); | |
1094 ret = ENOENT; | |
1095 goto end; | |
1096 } | |
1097 | |
1098 if (result) | |
1099 *result = ans; | |
1100 ret = 0; | |
1101 } | |
1102 break; | |
1103 | |
1104 default: | |
1105 /* Invalid criteria */ | |
1106 CHECK_PARAMS( criteria = 0 ); | |
1107 } | |
1108 end: | |
1109 return ret; | |
1110 } | |
1111 | |
1112 static int search_rule ( struct dictionary * dict, int criteria, void * what, struct dict_object **result ) | |
1113 { | |
1114 int ret = 0; | |
1115 | |
1116 TRACE_ENTRY("%p %d %p %p", dict, criteria, what, result); | |
1117 | |
1118 switch (criteria) { | |
1119 case RULE_BY_AVP_AND_PARENT: | |
1120 { | |
1121 struct dict_object * parent = NULL; | |
1122 struct dict_object * avp = NULL; | |
1123 struct dict_rule_request * _what = (struct dict_rule_request *) what; | |
1124 | |
1125 CHECK_PARAMS( _what | |
1126 && (parent = _what->rule_parent) | |
1127 && (avp = _what->rule_avp ) ); | |
1128 | |
1129 CHECK_PARAMS( verify_object(parent) | |
1130 && ((parent->type == DICT_COMMAND) | |
1131 || ((parent->type == DICT_AVP) && (parent->data.avp.avp_basetype == AVP_TYPE_GROUPED))) ); | |
1132 | |
1133 CHECK_PARAMS( verify_object(avp) && (avp->type == DICT_AVP) ); | |
1134 | |
1135 /* Perform the search */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1136 SEARCH_ruleavpname( avp->data.avp.avp_name, avp->datastr_len, &parent->list[2]); |
0 | 1137 |
1138 } | |
1139 break; | |
1140 | |
1141 default: | |
1142 /* Invalid criteria */ | |
1143 CHECK_PARAMS( criteria = 0 ); | |
1144 } | |
1145 end: | |
1146 return ret; | |
1147 } | |
1148 | |
1149 /*******************************************************************************************************/ | |
1150 /*******************************************************************************************************/ | |
1151 /* */ | |
1152 /* Dump / debug functions */ | |
1153 /* */ | |
1154 /*******************************************************************************************************/ | |
1155 /*******************************************************************************************************/ | |
1156 /* The following functions are used to debug the module, and allow to print out the content of the dictionary */ | |
1157 static void dump_vendor_data ( void * data ) | |
1158 { | |
1159 struct dict_vendor_data * vendor = (struct dict_vendor_data *)data; | |
1160 | |
1161 fd_log_debug("data: %-6u \"%s\"", vendor->vendor_id, vendor->vendor_name); | |
1162 } | |
1163 static void dump_application_data ( void * data ) | |
1164 { | |
1165 struct dict_application_data * appli = (struct dict_application_data *) data; | |
1166 fd_log_debug("data: %-6u \"%s\"", appli->application_id, appli->application_name); | |
1167 } | |
1168 static void dump_type_data ( void * data ) | |
1169 { | |
1170 struct dict_type_data * type = ( struct dict_type_data * ) data; | |
1171 | |
1172 fd_log_debug("data: %-12s \"%s\"", | |
1173 type_base_name[type->type_base], | |
1174 type->type_name); | |
1175 } | |
1176 static void dump_enumval_data ( struct dict_enumval_data * enumval, enum dict_avp_basetype type ) | |
1177 { | |
1178 const int LEN_MAX = 20; | |
1179 fd_log_debug("data: (%-12s) \"%s\" -> ", type_base_name[type], enumval->enum_name); | |
1180 switch (type) { | |
1181 case AVP_TYPE_OCTETSTRING: | |
1182 { | |
1183 int i, n=LEN_MAX; | |
1184 if (enumval->enum_value.os.len < LEN_MAX) | |
1185 n = enumval->enum_value.os.len; | |
1186 for (i=0; i < n; i++) | |
1187 fd_log_debug("0x%02.2X/'%c' ", enumval->enum_value.os.data[i], ASCII(enumval->enum_value.os.data[i])); | |
1188 if (n == LEN_MAX) | |
1189 fd_log_debug("..."); | |
1190 } | |
1191 break; | |
1192 | |
1193 case AVP_TYPE_INTEGER32: | |
1194 fd_log_debug("%i", enumval->enum_value.i32); | |
1195 break; | |
1196 | |
1197 case AVP_TYPE_INTEGER64: | |
1198 fd_log_debug("%lli", enumval->enum_value.i64); | |
1199 break; | |
1200 | |
1201 case AVP_TYPE_UNSIGNED32: | |
1202 fd_log_debug("%u", enumval->enum_value.u32); | |
1203 break; | |
1204 | |
1205 case AVP_TYPE_UNSIGNED64: | |
1206 fd_log_debug("%llu", enumval->enum_value.u64); | |
1207 break; | |
1208 | |
1209 case AVP_TYPE_FLOAT32: | |
1210 fd_log_debug("%f", enumval->enum_value.f32); | |
1211 break; | |
1212 | |
1213 case AVP_TYPE_FLOAT64: | |
1214 fd_log_debug("%g", enumval->enum_value.f64); | |
1215 break; | |
1216 | |
1217 default: | |
1218 fd_log_debug("??? (ERROR unknown type %d)", type); | |
1219 } | |
1220 } | |
1221 static void dump_avp_data ( void * data ) | |
1222 { | |
1223 struct dict_avp_data * avp = (struct dict_avp_data * ) data; | |
1224 fd_log_debug("data: v/m:" DUMP_AVPFL_str "/" DUMP_AVPFL_str ", %12s, %-6u \"%s\"", | |
1225 DUMP_AVPFL_val(avp->avp_flag_val), | |
1226 DUMP_AVPFL_val(avp->avp_flag_mask), | |
1227 type_base_name[avp->avp_basetype], | |
1228 avp->avp_code, | |
1229 avp->avp_name ); | |
1230 } | |
1231 static void dump_command_data ( void * data ) | |
1232 { | |
1233 struct dict_cmd_data * cmd = (struct dict_cmd_data *) data; | |
1234 fd_log_debug("data: v/m:" DUMP_CMDFL_str "/" DUMP_CMDFL_str ", %-6u \"%s\"", | |
1235 DUMP_CMDFL_val(cmd->cmd_flag_val), DUMP_CMDFL_val(cmd->cmd_flag_mask), cmd->cmd_code, cmd->cmd_name); | |
1236 } | |
1237 static void dump_rule_data ( void * data ) | |
1238 { | |
1239 struct dict_rule_data * rule = (struct dict_rule_data * )data; | |
1240 fd_log_debug("data: pos:%d ord:%d m/M:%2d/%2d avp:\"%s\"", | |
1241 rule->rule_position, | |
1242 rule->rule_order, | |
1243 rule->rule_min, | |
1244 rule->rule_max, | |
1245 rule->rule_avp->data.avp.avp_name); | |
1246 } | |
1247 | |
1248 static void dump_object ( struct dict_object * obj, int parents, int depth, int indent ); | |
1249 | |
1250 static void dump_list ( struct fd_list * sentinel, int parents, int depth, int indent ) | |
1251 { | |
1252 struct fd_list * li = sentinel; | |
1253 /* We don't lock here, the caller must have taken the dictionary lock for reading already */ | |
1254 while (li->next != sentinel) | |
1255 { | |
1256 li = li->next; | |
1257 dump_object( _O(li->o), parents, depth, indent ); | |
1258 } | |
1259 } | |
1260 | |
1261 static void dump_object ( struct dict_object * obj, int parents, int depth, int indent ) | |
1262 { | |
1263 if (obj == NULL) | |
1264 return; | |
1265 | |
1266 if (parents) | |
1267 dump_object (obj->parent, parents-1, 0, indent + 1 ); | |
1268 | |
1269 fd_log_debug("%*s@%p: %s%s (p:%-9p) ", | |
1270 indent, | |
1271 "", | |
1272 obj, | |
1273 verify_object(obj) ? "" : "INVALID ", | |
1274 _OBINFO(obj).name, | |
1275 obj->parent); | |
1276 | |
1277 if (obj->type == DICT_ENUMVAL) | |
1278 dump_enumval_data ( &obj->data.enumval, obj->parent->data.type.type_base ); | |
1279 else | |
1280 _OBINFO(obj).dump_data(&obj->data); | |
1281 | |
1282 fd_log_debug("\n"); | |
1283 | |
1284 if (depth) { | |
1285 int i; | |
1286 for (i=0; i<NB_LISTS_PER_OBJ; i++) { | |
1287 if ((obj->list[i].o == NULL) && (obj->list[i].next != &obj->list[i])) { | |
1288 fd_log_debug("%*s>%p: list[%d]:\n", indent, "", obj, i); | |
1289 dump_list(&obj->list[i], parents, depth - 1, indent + 2); | |
1290 } | |
1291 } | |
1292 } | |
1293 } | |
1294 | |
1295 void fd_dict_dump_object(struct dict_object * obj) | |
1296 { | |
1297 fd_log_debug("Dictionary object %p dump:\n", obj); | |
1298 dump_object( obj, 1, 2, 2 ); | |
1299 } | |
1300 | |
1301 void fd_dict_dump(struct dictionary * dict) | |
1302 { | |
1303 int i; | |
828
78307a61c578
Fix regression in dictionary dump
Sebastien Decugis <sdecugis@freediameter.net>
parents:
804
diff
changeset
|
1304 struct fd_list * li; |
0 | 1305 |
1306 CHECK_PARAMS_DO(dict && (dict->dict_eyec == DICT_EYECATCHER), return); | |
1307 | |
1308 CHECK_POSIX_DO( pthread_rwlock_rdlock( &dict->dict_lock ), /* ignore */ ); | |
1309 | |
1310 fd_log_debug("######################################################\n"); | |
1311 fd_log_debug("###### Dumping vendors, AVPs and related rules #######\n"); | |
1312 | |
1313 dump_object( &dict->dict_vendors, 0, 3, 0 ); | |
828
78307a61c578
Fix regression in dictionary dump
Sebastien Decugis <sdecugis@freediameter.net>
parents:
804
diff
changeset
|
1314 for (li = dict->dict_vendors.list[0].next; li != &dict->dict_vendors.list[0]; li = li->next) |
78307a61c578
Fix regression in dictionary dump
Sebastien Decugis <sdecugis@freediameter.net>
parents:
804
diff
changeset
|
1315 dump_object( li->o, 0, 3, 0 ); |
0 | 1316 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1317 fd_log_debug("###### Dumping applications #######\n"); |
0 | 1318 |
1319 dump_object( &dict->dict_applications, 0, 1, 0 ); | |
828
78307a61c578
Fix regression in dictionary dump
Sebastien Decugis <sdecugis@freediameter.net>
parents:
804
diff
changeset
|
1320 for (li = dict->dict_applications.list[0].next; li != &dict->dict_applications.list[0]; li = li->next) |
78307a61c578
Fix regression in dictionary dump
Sebastien Decugis <sdecugis@freediameter.net>
parents:
804
diff
changeset
|
1321 dump_object( li->o, 0, 1, 0 ); |
0 | 1322 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1323 fd_log_debug("###### Dumping types #######\n"); |
0 | 1324 |
1325 dump_list( &dict->dict_types, 0, 2, 0 ); | |
1326 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1327 fd_log_debug("###### Dumping commands per name #######\n"); |
0 | 1328 |
1329 dump_list( &dict->dict_cmd_name, 0, 2, 0 ); | |
1330 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1331 fd_log_debug("###### Dumping commands per code and flags #######\n"); |
0 | 1332 |
1333 dump_list( &dict->dict_cmd_code, 0, 0, 0 ); | |
1334 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1335 fd_log_debug("###### Statistics #######\n"); |
0 | 1336 |
1337 for (i=1; i<=DICT_TYPE_MAX; i++) | |
1338 fd_log_debug(" %5d objects of type %s\n", dict->dict_count[i], dict_obj_info[i].name); | |
1339 | |
1340 fd_log_debug("######################################################\n"); | |
1341 | |
1342 /* Free the rwlock */ | |
1343 CHECK_POSIX_DO( pthread_rwlock_unlock( &dict->dict_lock ), /* ignore */ ); | |
1344 } | |
1345 | |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1346 /**************************** Dump AVP values ********************************/ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1347 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1348 /* 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
|
1349 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
|
1350 { |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1351 int i; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1352 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
|
1353 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
|
1354 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
|
1355 break; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1356 } |
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 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
|
1358 } |
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
|
1359 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1360 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1361 |
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
|
1362 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
|
1363 { |
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
|
1364 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
|
1365 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1366 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1367 |
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
|
1368 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
|
1369 { |
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
|
1370 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
|
1371 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1372 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1373 |
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
|
1374 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
|
1375 { |
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
|
1376 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
|
1377 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1378 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1379 |
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
|
1380 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
|
1381 { |
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
|
1382 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
|
1383 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1384 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1385 |
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
|
1386 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
|
1387 { |
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
|
1388 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
|
1389 return 0; |
156
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 |
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_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
|
1393 { |
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
|
1394 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
|
1395 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1396 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1397 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1398 /* 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
|
1399 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
|
1400 { |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1401 switch (datatype) { |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1402 case AVP_TYPE_OCTETSTRING: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1403 return &dump_val_os; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1404 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1405 case AVP_TYPE_INTEGER32: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1406 return &dump_val_i32; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1407 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1408 case AVP_TYPE_INTEGER64: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1409 return &dump_val_i64; |
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 case AVP_TYPE_UNSIGNED32: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1412 return &dump_val_u32; |
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 case AVP_TYPE_UNSIGNED64: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1415 return &dump_val_u64; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1416 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1417 case AVP_TYPE_FLOAT32: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1418 return &dump_val_f32; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1419 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1420 case AVP_TYPE_FLOAT64: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1421 return &dump_val_f64; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1422 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1423 case AVP_TYPE_GROUPED: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1424 TRACE_DEBUG(FULL, "error: grouped AVP with a value!"); |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1425 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1426 return NULL; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1427 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1428 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1429 /* indent inside an object (duplicate from messages.c) */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1430 #define INOBJHDR "%*s " |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1431 #define INOBJHDRVAL indent<0 ? 1 : indent, indent<0 ? "-" : "|" |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1432 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1433 /* 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
|
1434 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
|
1435 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
|
1436 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
|
1437 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
|
1438 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
|
1439 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
|
1440 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
|
1441 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
|
1442 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
|
1443 size_t *outlen) |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1444 { |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1445 /* 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
|
1446 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
|
1447 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1448 /* 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
|
1449 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
|
1450 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
|
1451 } |
156
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 /* 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
|
1454 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
|
1455 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1456 /* 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
|
1457 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
|
1458 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
|
1459 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
|
1460 } |
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
|
1461 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
|
1462 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
|
1463 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
|
1464 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
|
1465 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
|
1466 } 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
|
1467 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
|
1468 } |
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
|
1469 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
|
1470 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
|
1471 } |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1472 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1473 /* 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
|
1474 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
|
1475 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1476 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1477 |
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
|
1478 /* 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
|
1479 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
|
1480 { |
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
|
1481 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
|
1482 struct dict_object * type = NULL; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1483 char * type_name = NULL; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1484 char * const_name = NULL; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1485 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1486 /* 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
|
1487 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
|
1488 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1489 /* Get the type definition of this AVP */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1490 type = model->parent; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1491 if (type) { |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1492 struct dict_enumval_request request; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1493 struct dict_object * enumval = NULL; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1494 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1495 type_name = type->data.type.type_name; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1496 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1497 /* overwrite the dump function ? */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1498 if (type->data.type.type_dump) |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1499 dump_val_cb = type->data.type.type_dump; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1500 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1501 /* Now check if the AVP value matches a constant */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1502 memset(&request, 0, sizeof(request)); |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1503 request.type_obj = type; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1504 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
|
1505 /* bypass checks */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1506 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
|
1507 /* We found a cosntant, get its name */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1508 const_name = enumval->data.enumval.enum_name; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1509 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1510 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1511 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1512 /* 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
|
1513 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
|
1514 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1515 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1516 |
0 | 1517 /*******************************************************************************************************/ |
1518 /*******************************************************************************************************/ | |
1519 /* */ | |
1520 /* Exported functions */ | |
1521 /* */ | |
1522 /*******************************************************************************************************/ | |
1523 /*******************************************************************************************************/ | |
1524 | |
1
bafb831ba688
Fix names to proper case for freeDiameter
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
0
diff
changeset
|
1525 /* These are the functions exported outside libfreeDiameter. */ |
0 | 1526 |
1527 /* Get the data associated to an object */ | |
1528 int fd_dict_gettype ( struct dict_object * object, enum dict_object_type * type) | |
1529 { | |
1530 TRACE_ENTRY("%p %p", object, type); | |
1531 | |
1532 CHECK_PARAMS( type && verify_object(object) ); | |
1533 | |
1534 /* Copy the value and return */ | |
1535 *type = object->type; | |
1536 return 0; | |
1537 } | |
1538 | |
1539 int fd_dict_getdict ( struct dict_object * object, struct dictionary ** dict) | |
1540 { | |
1541 TRACE_ENTRY("%p %p", object, dict); | |
1542 | |
1543 CHECK_PARAMS( dict && verify_object(object) ); | |
1544 | |
1545 /* Copy the value and return */ | |
1546 *dict = object->dico; | |
1547 return 0; | |
1548 } | |
1549 | |
1550 | |
1551 /* Get the data associated to an object */ | |
1552 int fd_dict_getval ( struct dict_object * object, void * val) | |
1553 { | |
1554 TRACE_ENTRY("%p %p", object, val); | |
1555 | |
1556 CHECK_PARAMS( val && verify_object(object) ); | |
1557 | |
1558 /* Copy the value and return */ | |
1559 memcpy(val, &object->data, _OBINFO(object).datasize);; | |
1560 return 0; | |
1561 } | |
1562 | |
1563 /* Add a new object in the dictionary */ | |
1564 int fd_dict_new ( struct dictionary * dict, enum dict_object_type type, void * data, struct dict_object * parent, struct dict_object **ref ) | |
1565 { | |
1566 int ret = 0; | |
1567 struct dict_object * new = NULL; | |
1568 struct dict_object * vendor = NULL; | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1569 struct dict_object * locref = NULL; |
0 | 1570 |
1571 TRACE_ENTRY("%p %d(%s) %p %p %p", dict, type, dict_obj_info[CHECK_TYPE(type) ? type : 0].name, data, parent, ref); | |
1572 | |
1573 /* Check parameters */ | |
1574 CHECK_PARAMS( dict && (dict->dict_eyec == DICT_EYECATCHER) && CHECK_TYPE(type) && data ); | |
1575 | |
1576 /* Check the "parent" parameter */ | |
1577 switch (dict_obj_info[type].parent) { | |
1578 case 0: /* parent is forbidden */ | |
1579 CHECK_PARAMS( parent == NULL ); | |
1580 | |
1581 case 1: /* parent is optional */ | |
1582 if (parent == NULL) | |
1583 break; | |
1584 | |
1585 case 2: /* parent is mandatory */ | |
1586 CHECK_PARAMS( verify_object(parent) ); | |
1587 | |
1588 if (type == DICT_RULE ) { /* Special case : grouped AVP or Command parents are allowed */ | |
1589 CHECK_PARAMS( (parent->type == DICT_COMMAND ) | |
1590 || ( (parent->type == DICT_AVP) && (parent->data.avp.avp_basetype == AVP_TYPE_GROUPED ) ) ); | |
1591 } else { | |
1592 CHECK_PARAMS( parent->type == dict_obj_info[type].parenttype ); | |
1593 } | |
1594 } | |
1595 | |
1596 /* For AVP object, we must also check that the "vendor" referenced exists */ | |
1597 if (type == DICT_AVP) { | |
1598 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
|
1599 { TRACE_DEBUG(INFO, "Unable to find vendor '%d' referenced in the AVP data", ((struct dict_avp_data *)data)->avp_vendor); return EINVAL; } ); |
0 | 1600 |
1601 /* Also check if a parent is provided, that the type are the same */ | |
1602 if (parent) { | |
1603 CHECK_PARAMS( parent->data.type.type_base == ((struct dict_avp_data *)data)->avp_basetype ); | |
1604 } | |
1605 } | |
1606 | |
1607 /* For RULE object, we must also check that the "avp" referenced exists */ | |
1608 if (type == DICT_RULE) { | |
1609 CHECK_PARAMS( verify_object(((struct dict_rule_data *)data)->rule_avp) ); | |
1610 CHECK_PARAMS( ((struct dict_rule_data *)data)->rule_avp->type == DICT_AVP ); | |
1611 } | |
1612 | |
1613 /* For COMMAND object, check that the 'R' flag is fixed */ | |
1614 if (type == DICT_COMMAND) { | |
1615 CHECK_PARAMS( ((struct dict_cmd_data *)data)->cmd_flag_mask & CMD_FLAG_REQUEST ); | |
1616 } | |
1617 | |
109
a522268ec95b
Less permissive in fd_dict_new
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1618 /* 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
|
1619 if (type == DICT_VENDOR) { |
a522268ec95b
Less permissive in fd_dict_new
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1620 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
|
1621 } |
a522268ec95b
Less permissive in fd_dict_new
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1622 if (type == DICT_APPLICATION) { |
a522268ec95b
Less permissive in fd_dict_new
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1623 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
|
1624 } |
a522268ec95b
Less permissive in fd_dict_new
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1625 |
0 | 1626 /* Parameters are valid, create the new object */ |
1627 CHECK_MALLOC( new = malloc(sizeof(struct dict_object)) ); | |
1628 | |
1629 /* Initialize the data of the new object */ | |
1630 init_object(new, type); | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1631 init_object_data(new, data, type); |
0 | 1632 new->dico = dict; |
1633 new->parent = parent; | |
1634 | |
1635 /* We will change the dictionary => acquire the write lock */ | |
1636 CHECK_POSIX_DO( ret = pthread_rwlock_wrlock(&dict->dict_lock), goto error_free ); | |
1637 | |
1638 /* Now link the object -- this also checks that no object with same keys already exists */ | |
1639 switch (type) { | |
1640 case DICT_VENDOR: | |
1641 /* 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
|
1642 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
|
1643 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1644 goto error_unlock; |
0 | 1645 break; |
1646 | |
1647 case DICT_APPLICATION: | |
1648 /* 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
|
1649 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
|
1650 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1651 goto error_unlock; |
0 | 1652 break; |
1653 | |
1654 case DICT_TYPE: | |
1655 /* 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
|
1656 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
|
1657 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1658 goto error_unlock; |
0 | 1659 break; |
1660 | |
1661 case DICT_ENUMVAL: | |
1662 /* 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
|
1663 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
|
1664 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1665 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1666 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1667 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
|
1668 if (ret) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1669 fd_list_unlink(&new->list[0]); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1670 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1671 } |
0 | 1672 break; |
1673 | |
1674 case DICT_AVP: | |
1675 /* 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
|
1676 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
|
1677 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1678 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1679 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1680 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
|
1681 if (ret) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1682 fd_list_unlink(&new->list[0]); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1683 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1684 } |
0 | 1685 break; |
1686 | |
1687 case DICT_COMMAND: | |
1688 /* 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
|
1689 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
|
1690 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1691 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1692 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1693 ret = fd_list_insert_ordered ( &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
|
1694 if (ret) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1695 fd_list_unlink(&new->list[1]); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1696 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1697 } |
0 | 1698 break; |
1699 | |
1700 case DICT_RULE: | |
1701 /* 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
|
1702 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
|
1703 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1704 goto error_unlock; |
0 | 1705 break; |
1706 | |
1707 default: | |
1708 ASSERT(0); | |
1709 } | |
1710 | |
1711 /* A new object has been created, increment the global counter */ | |
1712 dict->dict_count[type]++; | |
1713 | |
1714 /* Unlock the dictionary */ | |
1715 CHECK_POSIX_DO( ret = pthread_rwlock_unlock(&dict->dict_lock), goto error_free ); | |
1716 | |
1717 /* Save the pointer to the new object */ | |
1718 if (ref) | |
1719 *ref = new; | |
1720 | |
1721 return 0; | |
1722 | |
1723 error_unlock: | |
1724 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
|
1725 if (ret == EEXIST) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1726 /* 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
|
1727 switch (type) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1728 case DICT_VENDOR: |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1729 /* 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
|
1730 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
|
1731 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
|
1732 TRACE_DEBUG(FULL, "Conflicting vendor 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 /* 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
|
1736 ret = 0; |
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 case DICT_APPLICATION: |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1740 /* got same id */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1741 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
|
1742 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
|
1743 TRACE_DEBUG(FULL, "Conflicting application name"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1744 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1745 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1746 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1747 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1748 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1749 case DICT_TYPE: |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1750 /* got same name */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1751 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
|
1752 TRACE_DEBUG(FULL, "Conflicting base type"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1753 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1754 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1755 /* 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
|
1756 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
|
1757 TRACE_DEBUG(FULL, "Conflicting interpret cb"); |
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 ((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
|
1761 TRACE_DEBUG(FULL, "Conflicting encode cb"); |
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 ((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
|
1765 TRACE_DEBUG(FULL, "Conflicting dump cb"); |
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_ENUMVAL: |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1772 /* 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
|
1773 if (order_enum_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 enum 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 (order_enum_by_val(locref, new)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1778 TRACE_DEBUG(FULL, "Conflicting enum value"); |
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 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1782 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1783 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1784 case DICT_AVP: |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1785 /* got either same name or code */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1786 if (order_avp_by_code(locref, new)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1787 TRACE_DEBUG(FULL, "Conflicting AVP code"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1788 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1789 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1790 if (order_avp_by_name(locref, new)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1791 TRACE_DEBUG(FULL, "Conflicting AVP name"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1792 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1793 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1794 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
|
1795 TRACE_DEBUG(FULL, "Conflicting AVP vendor"); |
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.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
|
1799 TRACE_DEBUG(FULL, "Conflicting AVP flags mask"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1800 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1801 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1802 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
|
1803 TRACE_DEBUG(FULL, "Conflicting AVP flags value"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1804 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1805 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1806 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
|
1807 TRACE_DEBUG(FULL, "Conflicting AVP base type"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1808 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1809 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1810 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1811 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1812 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1813 case DICT_COMMAND: |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1814 /* 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
|
1815 if (order_cmd_by_name(locref, new)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1816 TRACE_DEBUG(FULL, "Conflicting command name"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1817 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1818 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1819 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
|
1820 TRACE_DEBUG(FULL, "Conflicting command code"); |
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 (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
|
1824 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
|
1825 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1826 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1827 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
|
1828 TRACE_DEBUG(FULL, "Conflicting command flags value"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1829 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1830 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1831 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1832 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1833 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1834 case DICT_RULE: |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1835 /* 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
|
1836 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
|
1837 TRACE_DEBUG(FULL, "Conflicting rule position"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1838 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1839 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1840 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
|
1841 (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
|
1842 && (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
|
1843 TRACE_DEBUG(FULL, "Conflicting rule order"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1844 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1845 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1846 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
|
1847 int r1 = locref->data.rule.rule_min; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1848 int r2 = new->data.rule.rule_min; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1849 int p = locref->data.rule.rule_position; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1850 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
|
1851 || ((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
|
1852 || ((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
|
1853 ) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1854 TRACE_DEBUG(FULL, "Conflicting rule min"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1855 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1856 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1857 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1858 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
|
1859 TRACE_DEBUG(FULL, "Conflicting rule max"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1860 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1861 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1862 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1863 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1864 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1865 if (ret) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1866 TRACE_DEBUG(INFO, "An existing object with different non-key data was found: EEXIST"); |
834
84a23e90519d
More verbose information on conflicts
Sebastien Decugis <sdecugis@freediameter.net>
parents:
828
diff
changeset
|
1867 if (TRACE_BOOL(INFO)) { |
84a23e90519d
More verbose information on conflicts
Sebastien Decugis <sdecugis@freediameter.net>
parents:
828
diff
changeset
|
1868 fd_log_debug("New object to insert:\n"); |
84a23e90519d
More verbose information on conflicts
Sebastien Decugis <sdecugis@freediameter.net>
parents:
828
diff
changeset
|
1869 dump_object(new, 0, 0, 3); |
84a23e90519d
More verbose information on conflicts
Sebastien Decugis <sdecugis@freediameter.net>
parents:
828
diff
changeset
|
1870 fd_log_debug("Object already in dictionary:\n"); |
84a23e90519d
More verbose information on conflicts
Sebastien Decugis <sdecugis@freediameter.net>
parents:
828
diff
changeset
|
1871 dump_object(locref, 0, 0 , 3); |
84a23e90519d
More verbose information on conflicts
Sebastien Decugis <sdecugis@freediameter.net>
parents:
828
diff
changeset
|
1872 } |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1873 } else { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1874 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
|
1875 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1876 if (ref) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1877 *ref = locref; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1878 } else { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1879 CHECK_FCT_DO( ret, ); /* log the error */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1880 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1881 |
0 | 1882 error_free: |
1883 free(new); | |
1884 return ret; | |
1885 } | |
1886 | |
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
|
1887 |
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
|
1888 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
|
1889 { |
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
|
1890 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
|
1891 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
|
1892 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
|
1893 |
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
|
1894 /* 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
|
1895 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
|
1896 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
|
1897 |
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
|
1898 /* 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
|
1899 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
|
1900 |
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
|
1901 /* 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
|
1902 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
|
1903 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
|
1904 /* 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
|
1905 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
|
1906 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
|
1907 #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
|
1908 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
|
1909 #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
|
1910 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
|
1911 } |
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
|
1912 } |
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
|
1913 |
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
|
1914 /* 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
|
1915 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
|
1916 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
|
1917 |
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
|
1918 /* 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
|
1919 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
|
1920 |
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
|
1921 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
|
1922 } |
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
|
1923 |
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
|
1924 |
0 | 1925 int fd_dict_search ( struct dictionary * dict, enum dict_object_type type, int criteria, void * what, struct dict_object **result, int retval ) |
1926 { | |
1927 int ret = 0; | |
1928 | |
1929 TRACE_ENTRY("%p %d(%s) %d %p %p %d", dict, type, dict_obj_info[CHECK_TYPE(type) ? type : 0].name, criteria, what, result, retval); | |
1930 | |
1931 /* Check param */ | |
1932 CHECK_PARAMS( dict && (dict->dict_eyec == DICT_EYECATCHER) && CHECK_TYPE(type) ); | |
1933 | |
1934 /* Lock the dictionary for reading */ | |
1935 CHECK_POSIX( pthread_rwlock_rdlock(&dict->dict_lock) ); | |
1936 | |
1937 /* Now call the type-specific search function */ | |
1938 ret = dict_obj_info[type].search_fct (dict, criteria, what, result); | |
1939 | |
1940 /* Unlock */ | |
1941 CHECK_POSIX( pthread_rwlock_unlock(&dict->dict_lock) ); | |
1942 | |
1943 /* Update the return value as needed */ | |
1944 if ((result != NULL) && (*result == NULL)) | |
1945 ret = retval; | |
1946 | |
1947 return ret; | |
1948 } | |
1949 | |
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
|
1950 /* 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
|
1951 |
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
|
1952 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
|
1953 |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
1954 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
|
1955 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
|
1956 ... |
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
|
1957 } |
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 |
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 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
|
1960 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
|
1961 |
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
|
1962 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
|
1963 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
|
1964 ** 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
|
1965 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
|
1966 |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
1967 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
|
1968 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
|
1969 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
|
1970 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
|
1971 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
|
1972 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
|
1973 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
|
1974 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
|
1975 |
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 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
|
1977 */ |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
1978 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
|
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 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
|
1981 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
|
1982 |
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 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
|
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 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
|
1986 |
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 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
|
1988 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
|
1989 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
|
1990 *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
|
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 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
|
1994 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
|
1995 *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
|
1996 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
|
1997 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1998 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
|
1999 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
|
2000 *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
|
2001 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
|
2002 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2003 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
|
2004 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
|
2005 *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
|
2006 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
|
2007 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2008 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
|
2009 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
|
2010 *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
|
2011 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
|
2012 |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2013 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
|
2014 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
|
2015 *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
|
2016 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
|
2017 |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2018 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
|
2019 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
|
2020 *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
|
2021 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
|
2022 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2023 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
|
2024 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
|
2025 *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
|
2026 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
|
2027 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2028 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
|
2029 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
|
2030 *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
|
2031 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
|
2032 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2033 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
|
2034 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
|
2035 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
|
2036 ((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
|
2037 && (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
|
2038 *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
|
2039 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
|
2040 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2041 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
|
2042 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
|
2043 } |
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
|
2044 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2045 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
|
2046 } |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2047 |
0 | 2048 /*******************************************************************************************************/ |
2049 /*******************************************************************************************************/ | |
2050 /* */ | |
2051 /* The init/fini functions */ | |
2052 /* */ | |
2053 /*******************************************************************************************************/ | |
2054 /*******************************************************************************************************/ | |
2055 | |
2056 /* Initialize the dictionary */ | |
2057 int fd_dict_init ( struct dictionary ** dict) | |
2058 { | |
2059 struct dictionary * new = NULL; | |
2060 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
2061 TRACE_ENTRY("%p", dict); |
0 | 2062 |
2063 /* Sanity checks */ | |
2064 ASSERT( (sizeof(type_base_name) / sizeof(type_base_name[0])) == (AVP_TYPE_MAX + 1) ); | |
2065 ASSERT( (sizeof(dict_obj_info) / sizeof(dict_obj_info[0])) == (DICT_TYPE_MAX + 1) ); | |
2066 CHECK_PARAMS(dict); | |
2067 | |
2068 /* Allocate the memory for the dictionary */ | |
2069 CHECK_MALLOC( new = malloc(sizeof(struct dictionary)) ); | |
2070 memset(new, 0, sizeof(struct dictionary)); | |
2071 | |
2072 new->dict_eyec = DICT_EYECATCHER; | |
2073 | |
2074 /* Initialize the lock for the dictionary */ | |
2075 CHECK_POSIX( pthread_rwlock_init(&new->dict_lock, NULL) ); | |
2076 | |
2077 /* Initialize the sentinel for vendors and AVP lists */ | |
2078 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
|
2079 #define NO_VENDOR_NAME "(no vendor)" |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
2080 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
|
2081 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
|
2082 /* 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
|
2083 new->dict_vendors.dico = new; |
0 | 2084 |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2085 /* Initialize the sentinel for applications */ |
0 | 2086 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
|
2087 #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
|
2088 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
|
2089 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
|
2090 /* 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
|
2091 new->dict_applications.dico = new; |
0 | 2092 |
2093 /* Initialize the sentinel for types */ | |
2094 fd_list_init ( &new->dict_types, NULL ); | |
2095 | |
2096 /* Initialize the sentinels for commands */ | |
2097 fd_list_init ( &new->dict_cmd_name, NULL ); | |
2098 fd_list_init ( &new->dict_cmd_code, NULL ); | |
2099 | |
2100 /* Initialize the error command object */ | |
2101 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
|
2102 #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
|
2103 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
|
2104 new->dict_cmd_error.datastr_len = CONSTSTRLEN(GENERIC_ERROR_NAME); |
0 | 2105 new->dict_cmd_error.data.cmd.cmd_flag_mask=CMD_FLAG_ERROR | CMD_FLAG_REQUEST | CMD_FLAG_RETRANSMIT; |
2106 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
|
2107 new->dict_cmd_error.dico = new; |
0 | 2108 |
2109 *dict = new; | |
2110 | |
2111 /* Done */ | |
2112 return 0; | |
2113 } | |
2114 | |
2115 /* Destroy a dictionary */ | |
2116 int fd_dict_fini ( struct dictionary ** dict) | |
2117 { | |
2118 int i; | |
2119 | |
2120 TRACE_ENTRY(""); | |
2121 CHECK_PARAMS( dict && *dict && ((*dict)->dict_eyec == DICT_EYECATCHER) ); | |
2122 | |
2123 /* Acquire the write lock to make sure no other operation is ongoing */ | |
2124 CHECK_POSIX( pthread_rwlock_wrlock(&(*dict)->dict_lock) ); | |
2125 | |
2126 /* Empty all the lists, free the elements */ | |
2127 destroy_list ( &(*dict)->dict_cmd_error.list[2] ); | |
2128 destroy_list ( &(*dict)->dict_cmd_code ); | |
2129 destroy_list ( &(*dict)->dict_cmd_name ); | |
2130 destroy_list ( &(*dict)->dict_types ); | |
2131 for (i=0; i< NB_LISTS_PER_OBJ; i++) { | |
2132 destroy_list ( &(*dict)->dict_applications.list[i] ); | |
2133 destroy_list ( &(*dict)->dict_vendors.list[i] ); | |
2134 } | |
2135 | |
2136 /* Dictionary is empty, now destroy the lock */ | |
2137 CHECK_POSIX( pthread_rwlock_unlock(&(*dict)->dict_lock) ); | |
2138 CHECK_POSIX( pthread_rwlock_destroy(&(*dict)->dict_lock) ); | |
2139 | |
2140 free(*dict); | |
2141 *dict = NULL; | |
2142 | |
2143 return 0; | |
2144 } | |
2145 | |
2146 /*******************************************************************************************************/ | |
2147 /*******************************************************************************************************/ | |
2148 /* */ | |
2149 /* Other functions */ | |
2150 /* */ | |
2151 /*******************************************************************************************************/ | |
2152 /*******************************************************************************************************/ | |
2153 | |
2154 /* Iterate a callback on the rules for an object */ | |
2155 int fd_dict_iterate_rules ( struct dict_object *parent, void * data, int (*cb)(void *, struct dict_rule_data *) ) | |
2156 { | |
2157 int ret = 0; | |
2158 struct fd_list * li; | |
2159 | |
2160 TRACE_ENTRY("%p %p %p", parent, data, cb); | |
2161 | |
2162 /* Check parameters */ | |
2163 CHECK_PARAMS( verify_object(parent) ); | |
2164 CHECK_PARAMS( (parent->type == DICT_COMMAND) | |
2165 || ((parent->type == DICT_AVP) && (parent->data.avp.avp_basetype == AVP_TYPE_GROUPED)) ); | |
2166 TRACE_DEBUG (FULL, "Iterating on rules of %s: '%s'.", | |
2167 _OBINFO(parent).name, | |
2168 parent->type == DICT_COMMAND ? | |
2169 parent->data.cmd.cmd_name | |
2170 : parent->data.avp.avp_name); | |
2171 | |
2172 /* Acquire the read lock */ | |
2173 CHECK_POSIX( pthread_rwlock_rdlock(&parent->dico->dict_lock) ); | |
2174 | |
2175 /* go through the list and call the cb on each rule data */ | |
2176 for (li = &(parent->list[2]); li->next != &(parent->list[2]); li = li->next) { | |
2177 ret = (*cb)(data, &(_O(li->next->o)->data.rule)); | |
2178 if (ret != 0) | |
2179 break; | |
2180 } | |
2181 | |
2182 /* Release the lock */ | |
2183 CHECK_POSIX( pthread_rwlock_unlock(&parent->dico->dict_lock) ); | |
2184 | |
2185 return ret; | |
2186 } | |
2187 | |
2188 /* Create the list of vendors. Returns a 0-terminated array, that must be freed after use. Returns NULL on error. */ | |
2189 uint32_t * fd_dict_get_vendorid_list(struct dictionary * dict) | |
2190 { | |
2191 uint32_t * ret = NULL; | |
2192 int i = 0; | |
2193 struct fd_list * li; | |
2194 | |
2195 TRACE_ENTRY(); | |
2196 | |
2197 /* Acquire the read lock */ | |
2198 CHECK_POSIX_DO( pthread_rwlock_rdlock(&dict->dict_lock), return NULL ); | |
2199 | |
2200 /* Allocate an array to contain all the elements */ | |
2201 CHECK_MALLOC_DO( ret = calloc( dict->dict_count[DICT_VENDOR] + 1, sizeof(uint32_t) ), goto out ); | |
2202 | |
2203 /* Copy the vendors IDs */ | |
2204 for (li = dict->dict_vendors.list[0].next; li != &(dict->dict_vendors.list[0]); li = li->next) { | |
2205 ret[i] = _O(li->o)->data.vendor.vendor_id; | |
2206 i++; | |
2207 ASSERT( i <= dict->dict_count[DICT_VENDOR] ); | |
2208 } | |
2209 out: | |
2210 /* Release the lock */ | |
2211 CHECK_POSIX_DO( pthread_rwlock_unlock(&dict->dict_lock), return NULL ); | |
2212 | |
2213 return ret; | |
2214 } | |
2215 | |
2216 /* Return the location of the cb list for an object, after checking its type */ | |
2217 int fd_dict_disp_cb(enum dict_object_type type, struct dict_object *obj, struct fd_list ** cb_list) | |
2218 { | |
2219 TRACE_ENTRY("%d %p %p", type, obj, cb_list); | |
2220 CHECK_PARAMS( verify_object(obj) ); | |
2221 CHECK_PARAMS( _OBINFO(obj).type == type ); | |
2222 CHECK_PARAMS( cb_list ); | |
2223 *cb_list = &obj->disp_cbs; | |
2224 return 0; | |
2225 } | |
2226 | |
2227 int fd_dict_get_error_cmd(struct dictionary * dict, struct dict_object **obj) | |
2228 { | |
2229 TRACE_ENTRY("%p %p", dict, obj); | |
2230 CHECK_PARAMS( dict && (dict->dict_eyec == DICT_EYECATCHER) && obj ); | |
2231 *obj = &dict->dict_cmd_error; | |
2232 return 0; | |
2233 } |