Mercurial > hg > freeDiameter
annotate libfdproto/dictionary.c @ 910:8500947421cb
Fix bug in fd_dict_search for rules. Thank you Thomas for bug & fix.
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Sat, 19 Jan 2013 17:12:25 +0100 |
parents | b772af200865 |
children | 5053f1abcf5d ad5c976e0dc7 |
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 */ | |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
158 static int search_vendor ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ); |
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
159 static int search_application ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ); |
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
160 static int search_type ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ); |
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
161 static int search_enumval ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ); |
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
162 static int search_avp ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ); |
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
163 static int search_cmd ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ); |
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
164 static int search_rule ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ); |
0 | 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 */ | |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
175 int (*search_fct)(struct dictionary * dict, int criteria, const void * what, struct dict_object **result );; /* The function to search an object of this type */ |
0 | 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 | |
910
8500947421cb
Fix bug in fd_dict_search for rules. Thank you Thomas for bug & fix.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
907
diff
changeset
|
645 /* For search of AVP name in rule lists -- the list is not ordered by AVP names! */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
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 } \ | |
662 if (result) \ | |
663 *result = NULL; \ | |
664 else \ | |
665 ret = ENOENT; \ | |
666 } | |
667 | |
668 /* For search of scalars in lists. isindex= 1 if the value is the ordering key of the list */ | |
669 #define SEARCH_scalar( value, sentinel, datafield, isindex, defaultobj ) { \ | |
670 int __cmp; \ | |
671 struct fd_list * __li; \ | |
672 ret = 0; \ | |
673 if ( ((defaultobj) != NULL) \ | |
674 && (_O(defaultobj)->data. datafield == value)) { \ | |
675 if (result) \ | |
676 *result = _O(defaultobj); \ | |
677 goto end; \ | |
678 } \ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
679 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
|
680 __cmp= ORDER_scalar(value, _O(__li->o)->data. datafield ); \ |
0 | 681 if (__cmp == 0) { \ |
682 if (result) \ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
683 *result = _O(__li->o); \ |
0 | 684 goto end; \ |
685 } \ | |
686 if ((isindex) && (__cmp < 0)) \ | |
687 break; \ | |
688 } \ | |
689 if (result) \ | |
690 *result = NULL; \ | |
691 else \ | |
692 ret = ENOENT; \ | |
693 } | |
694 | |
695 /* For search of commands in lists by code and flag. R_flag_val = 0 or CMD_FLAG_REQUEST */ | |
696 #define SEARCH_codefl( value, R_flag_val, sentinel) { \ | |
697 int __cmp; \ | |
698 struct fd_list * __li; \ | |
699 ret = 0; \ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
700 for (__li = (sentinel)->next; __li != (sentinel); __li = __li->next) { \ |
0 | 701 __cmp = ORDER_scalar(value, \ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
702 _O(__li->o)->data.cmd.cmd_code ); \ |
0 | 703 if (__cmp == 0) { \ |
704 uint8_t __mask, __val; \ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
705 __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
|
706 __val = _O(__li->o)->data.cmd.cmd_flag_val; \ |
0 | 707 if ( ! (__mask & CMD_FLAG_REQUEST) ) \ |
708 continue; \ | |
709 if ( ( __val & CMD_FLAG_REQUEST ) != R_flag_val ) \ | |
710 continue; \ | |
711 if (result) \ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
712 *result = _O(__li->o); \ |
0 | 713 goto end; \ |
714 } \ | |
715 if (__cmp < 0) \ | |
716 break; \ | |
717 } \ | |
718 if (result) \ | |
719 *result = NULL; \ | |
720 else \ | |
721 ret = ENOENT; \ | |
722 } | |
723 | |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
724 static int search_vendor ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ) |
0 | 725 { |
726 int ret = 0; | |
727 vendor_id_t id; | |
728 | |
729 TRACE_ENTRY("%p %d %p %p", dict, criteria, what, result); | |
730 | |
731 switch (criteria) { | |
732 case VENDOR_BY_ID: | |
733 id = *(vendor_id_t *) what; | |
734 SEARCH_scalar( id, &dict->dict_vendors.list[0], vendor.vendor_id, 1, &dict->dict_vendors ); | |
735 break; | |
736 | |
737 case VENDOR_BY_NAME: | |
738 /* "what" is a vendor name */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
739 SEARCH_os0( what, &dict->dict_vendors.list[0], vendor.vendor_name, 0); |
0 | 740 break; |
741 | |
742 case VENDOR_OF_APPLICATION: | |
743 /* "what" should be an application object */ | |
744 SEARCH_childs_parent( DICT_APPLICATION, &dict->dict_vendors ); | |
745 break; | |
746 | |
747 default: | |
748 /* Invalid criteria */ | |
749 CHECK_PARAMS( criteria = 0 ); | |
750 } | |
751 end: | |
752 return ret; | |
753 } | |
754 | |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
755 static int search_application ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ) |
0 | 756 { |
757 int ret = 0; | |
758 application_id_t id; | |
759 | |
760 TRACE_ENTRY("%p %d %p %p", dict, criteria, what, result); | |
761 | |
762 switch (criteria) { | |
763 case APPLICATION_BY_ID: | |
764 id = *(application_id_t *) what; | |
765 | |
766 SEARCH_scalar( id, &dict->dict_applications.list[0], application.application_id, 1, &dict->dict_applications ); | |
767 break; | |
768 | |
769 case APPLICATION_BY_NAME: | |
770 /* "what" is an application name */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
771 SEARCH_os0( what, &dict->dict_applications.list[0], application.application_name, 0); |
0 | 772 break; |
773 | |
774 case APPLICATION_OF_TYPE: | |
775 /* "what" should be a type object */ | |
776 SEARCH_childs_parent( DICT_TYPE, &dict->dict_applications ); | |
777 break; | |
778 | |
779 case APPLICATION_OF_COMMAND: | |
780 /* "what" should be a command object */ | |
781 SEARCH_childs_parent( DICT_COMMAND, &dict->dict_applications ); | |
782 break; | |
783 | |
784 default: | |
785 /* Invalid criteria */ | |
786 CHECK_PARAMS( criteria = 0 ); | |
787 } | |
788 end: | |
789 return ret; | |
790 } | |
791 | |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
792 static int search_type ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ) |
0 | 793 { |
794 int ret = 0; | |
795 | |
796 TRACE_ENTRY("%p %d %p %p", dict, criteria, what, result); | |
797 | |
798 switch (criteria) { | |
799 case TYPE_BY_NAME: | |
800 /* "what" is a type name */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
801 SEARCH_os0( what, &dict->dict_types, type.type_name, 1); |
0 | 802 break; |
803 | |
804 case TYPE_OF_ENUMVAL: | |
805 /* "what" should be a type_enum object */ | |
806 SEARCH_childs_parent( DICT_ENUMVAL, NULL ); | |
807 break; | |
808 | |
809 case TYPE_OF_AVP: | |
810 /* "what" should be an avp object */ | |
811 SEARCH_childs_parent( DICT_AVP, NULL ); | |
812 break; | |
813 | |
814 | |
815 default: | |
816 /* Invalid criteria */ | |
817 CHECK_PARAMS( criteria = 0 ); | |
818 } | |
819 end: | |
820 return ret; | |
821 } | |
822 | |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
823 static int search_enumval ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ) |
0 | 824 { |
825 int ret = 0; | |
826 | |
827 TRACE_ENTRY("%p %d %p %p", dict, criteria, what, result); | |
828 | |
829 switch (criteria) { | |
830 case ENUMVAL_BY_STRUCT: | |
831 { | |
832 struct dict_object * parent = NULL; | |
833 struct dict_enumval_request * _what = (struct dict_enumval_request *) what; | |
834 | |
835 CHECK_PARAMS( _what && ( _what->type_obj || _what->type_name ) ); | |
836 | |
837 if (_what->type_obj != NULL) { | |
838 parent = _what->type_obj; | |
839 CHECK_PARAMS( verify_object(parent) && (parent->type == DICT_TYPE) ); | |
840 } else { | |
841 /* We received only the type name, we must find it first */ | |
842 CHECK_FCT_DO( search_type( dict, TYPE_BY_NAME, _what->type_name, &parent ), | |
843 CHECK_PARAMS( 0 ) ); | |
844 } | |
845 | |
846 /* From here the "parent" object is valid */ | |
847 | |
848 if ( _what->search.enum_name != NULL ) { | |
849 /* 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
|
850 SEARCH_os0( _what->search.enum_name, &parent->list[1], enumval.enum_name, 1 ); |
0 | 851 } else { |
852 /* We are looking for the value in enum_value */ | |
853 switch (parent->data.type.type_base) { | |
854 case AVP_TYPE_OCTETSTRING: | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
855 SEARCH_os( _what->search.enum_value.os.data, |
0 | 856 _what->search.enum_value.os.len, |
857 &parent->list[2], | |
858 enumval.enum_value.os , | |
859 1 ); | |
860 break; | |
861 | |
862 case AVP_TYPE_INTEGER32: | |
863 SEARCH_scalar( _what->search.enum_value.i32, | |
864 &parent->list[2], | |
865 enumval.enum_value.i32, | |
866 1, | |
867 (struct dict_object *)NULL); | |
868 break; | |
869 | |
870 case AVP_TYPE_INTEGER64: | |
871 SEARCH_scalar( _what->search.enum_value.i64, | |
872 &parent->list[2], | |
873 enumval.enum_value.i64, | |
874 1, | |
875 (struct dict_object *)NULL); | |
876 break; | |
877 | |
878 case AVP_TYPE_UNSIGNED32: | |
879 SEARCH_scalar( _what->search.enum_value.u32, | |
880 &parent->list[2], | |
881 enumval.enum_value.u32, | |
882 1, | |
883 (struct dict_object *)NULL); | |
884 break; | |
885 | |
886 case AVP_TYPE_UNSIGNED64: | |
887 SEARCH_scalar( _what->search.enum_value.u64, | |
888 &parent->list[2], | |
889 enumval.enum_value.u64, | |
890 1, | |
891 (struct dict_object *)NULL); | |
892 break; | |
893 | |
894 case AVP_TYPE_FLOAT32: | |
895 SEARCH_scalar( _what->search.enum_value.f32, | |
896 &parent->list[2], | |
897 enumval.enum_value.f32, | |
898 1, | |
899 (struct dict_object *)NULL); | |
900 break; | |
901 | |
902 case AVP_TYPE_FLOAT64: | |
903 SEARCH_scalar( _what->search.enum_value.f64, | |
904 &parent->list[2], | |
905 enumval.enum_value.f64, | |
906 1, | |
907 (struct dict_object *)NULL); | |
908 break; | |
909 | |
910 default: | |
911 /* Invalid parent type basetype */ | |
912 CHECK_PARAMS( parent = NULL ); | |
913 } | |
914 } | |
915 | |
916 } | |
917 break; | |
918 | |
919 | |
920 default: | |
921 /* Invalid criteria */ | |
922 CHECK_PARAMS( criteria = 0 ); | |
923 } | |
924 end: | |
925 return ret; | |
926 } | |
927 | |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
928 static int search_avp ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ) |
0 | 929 { |
930 int ret = 0; | |
931 | |
932 TRACE_ENTRY("%p %d %p %p", dict, criteria, what, result); | |
933 | |
934 switch (criteria) { | |
935 case AVP_BY_CODE: | |
936 { | |
937 avp_code_t code; | |
938 code = *(avp_code_t *) what; | |
939 | |
940 SEARCH_scalar( code, &dict->dict_vendors.list[1], avp.avp_code, 1, (struct dict_object *)NULL ); | |
941 } | |
942 break; | |
943 | |
944 case AVP_BY_NAME: | |
945 /* "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
|
946 SEARCH_os0( what, &dict->dict_vendors.list[2], avp.avp_name, 1); |
0 | 947 break; |
948 | |
949 case AVP_BY_CODE_AND_VENDOR: | |
950 case AVP_BY_NAME_AND_VENDOR: | |
951 { | |
952 struct dict_avp_request * _what = (struct dict_avp_request *) what; | |
953 struct dict_object * vendor = NULL; | |
954 | |
955 CHECK_PARAMS( (criteria != AVP_BY_NAME_AND_VENDOR) || _what->avp_name ); | |
956 | |
957 /* Now look for the vendor first */ | |
958 CHECK_FCT( search_vendor( dict, VENDOR_BY_ID, &_what->avp_vendor, &vendor ) ); | |
959 if (vendor == NULL) { | |
960 if (result) | |
961 *result = NULL; | |
962 else | |
963 ret = ENOENT; | |
964 goto end; | |
965 } | |
966 | |
967 /* We now have our vendor = head of the appropriate avp list */ | |
968 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
|
969 SEARCH_os0( _what->avp_name, &vendor->list[2], avp.avp_name, 1); |
0 | 970 } else { |
971 /* AVP_BY_CODE_AND_VENDOR */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
972 SEARCH_scalar( _what->avp_code, &vendor->list[1], avp.avp_code, 1, (struct dict_object *)NULL ); |
0 | 973 } |
974 } | |
975 break; | |
976 | |
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
|
977 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
|
978 { |
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 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
|
980 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
|
981 |
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 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
|
983 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
|
984 |
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 /* 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
|
986 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
|
987 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
|
988 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
|
989 } 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
|
990 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
|
991 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
|
992 } else { |
906
ebe479bfcd4b
Fix typo in new code
Sebastien Decugis <sdecugis@freediameter.net>
parents:
903
diff
changeset
|
993 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
|
994 } |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
995 |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
996 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
|
997 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
|
998 *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
|
999 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
|
1000 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
|
1001 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
|
1002 } |
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 |
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 /* 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
|
1005 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
|
1006 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
|
1007 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
|
1008 } 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
|
1009 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
|
1010 } |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1011 } |
4382d7420e65
Add new AVP_BY_STRUCT method for searching vendor-specific AVPs. This allows more flexibility and superseeds AVP_BY_NAME_AND_VENDOR and AVP_BY_CODE_AND_VENDOR.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
834
diff
changeset
|
1012 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
|
1013 |
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
|
1014 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
|
1015 { |
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 struct fd_list * li; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1017 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
|
1018 |
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1019 /* First, search for vendor 0 */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1020 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
|
1021 |
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1022 /* 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
|
1023 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
|
1024 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
|
1025 } |
0b5d21c87855
Added new AVP search criteria in the dictionary: AVP_BY_NAME_ALL_VENDORS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
446
diff
changeset
|
1026 } |
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 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
|
1028 |
0 | 1029 default: |
1030 /* Invalid criteria */ | |
1031 CHECK_PARAMS( criteria = 0 ); | |
1032 } | |
1033 end: | |
1034 return ret; | |
1035 } | |
1036 | |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
1037 static int search_cmd ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ) |
0 | 1038 { |
1039 int ret = 0; | |
1040 | |
1041 TRACE_ENTRY("%p %d %p %p", dict, criteria, what, result); | |
1042 | |
1043 switch (criteria) { | |
1044 case CMD_BY_NAME: | |
1045 /* "what" is a command name */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1046 SEARCH_os0( what, &dict->dict_cmd_name, cmd.cmd_name, 1); |
0 | 1047 break; |
1048 | |
1049 case CMD_BY_CODE_R: | |
1050 case CMD_BY_CODE_A: | |
1051 { | |
1052 command_code_t code; | |
1053 uint8_t searchfl = 0; | |
1054 | |
1055 /* The command code that we are searching */ | |
1056 code = *(command_code_t *) what; | |
1057 | |
1058 /* The flag (request or answer) of the command we are searching */ | |
1059 if (criteria == CMD_BY_CODE_R) { | |
1060 searchfl = CMD_FLAG_REQUEST; | |
1061 } | |
1062 | |
1063 /* perform the search */ | |
1064 SEARCH_codefl( code, searchfl, &dict->dict_cmd_code ); | |
1065 } | |
1066 break; | |
1067 | |
1068 case CMD_ANSWER: | |
1069 { | |
1070 /* "what" is a command object of type "request" */ | |
1071 struct dict_object * req = (struct dict_object *) what; | |
1072 struct dict_object * ans = NULL; | |
1073 | |
1074 CHECK_PARAMS( verify_object(req) | |
1075 && (req->type == DICT_COMMAND) | |
1076 && (req->data.cmd.cmd_flag_mask & CMD_FLAG_REQUEST) | |
1077 && (req->data.cmd.cmd_flag_val & CMD_FLAG_REQUEST) ); | |
1078 | |
1079 /* The answer is supposed to be the next element in the list, if it exists */ | |
1080 ans = req->list[1].next->o; | |
1081 if ( ans == NULL ) { | |
1082 TRACE_DEBUG( FULL, "the request was the last element in the list" ); | |
1083 ret = ENOENT; | |
1084 goto end; | |
1085 } | |
1086 | |
1087 /* Now check that the ans element is really the correct one */ | |
1088 if ( (ans->data.cmd.cmd_code != req->data.cmd.cmd_code) | |
1089 || (!(ans->data.cmd.cmd_flag_mask & CMD_FLAG_REQUEST)) | |
1090 || ( ans->data.cmd.cmd_flag_val & CMD_FLAG_REQUEST ) ) { | |
1091 TRACE_DEBUG( FULL, "the answer does not follow the request in the list" ); | |
1092 ret = ENOENT; | |
1093 goto end; | |
1094 } | |
1095 | |
1096 if (result) | |
1097 *result = ans; | |
1098 ret = 0; | |
1099 } | |
1100 break; | |
1101 | |
1102 default: | |
1103 /* Invalid criteria */ | |
1104 CHECK_PARAMS( criteria = 0 ); | |
1105 } | |
1106 end: | |
1107 return ret; | |
1108 } | |
1109 | |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
1110 static int search_rule ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ) |
0 | 1111 { |
1112 int ret = 0; | |
1113 | |
1114 TRACE_ENTRY("%p %d %p %p", dict, criteria, what, result); | |
1115 | |
1116 switch (criteria) { | |
1117 case RULE_BY_AVP_AND_PARENT: | |
1118 { | |
1119 struct dict_object * parent = NULL; | |
1120 struct dict_object * avp = NULL; | |
1121 struct dict_rule_request * _what = (struct dict_rule_request *) what; | |
1122 | |
1123 CHECK_PARAMS( _what | |
1124 && (parent = _what->rule_parent) | |
1125 && (avp = _what->rule_avp ) ); | |
1126 | |
1127 CHECK_PARAMS( verify_object(parent) | |
1128 && ((parent->type == DICT_COMMAND) | |
1129 || ((parent->type == DICT_AVP) && (parent->data.avp.avp_basetype == AVP_TYPE_GROUPED))) ); | |
1130 | |
1131 CHECK_PARAMS( verify_object(avp) && (avp->type == DICT_AVP) ); | |
1132 | |
1133 /* Perform the search */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1134 SEARCH_ruleavpname( avp->data.avp.avp_name, avp->datastr_len, &parent->list[2]); |
0 | 1135 |
1136 } | |
1137 break; | |
1138 | |
1139 default: | |
1140 /* Invalid criteria */ | |
1141 CHECK_PARAMS( criteria = 0 ); | |
1142 } | |
1143 end: | |
1144 return ret; | |
1145 } | |
1146 | |
1147 /*******************************************************************************************************/ | |
1148 /*******************************************************************************************************/ | |
1149 /* */ | |
1150 /* Dump / debug functions */ | |
1151 /* */ | |
1152 /*******************************************************************************************************/ | |
1153 /*******************************************************************************************************/ | |
1154 /* The following functions are used to debug the module, and allow to print out the content of the dictionary */ | |
1155 static void dump_vendor_data ( void * data ) | |
1156 { | |
1157 struct dict_vendor_data * vendor = (struct dict_vendor_data *)data; | |
1158 | |
1159 fd_log_debug("data: %-6u \"%s\"", vendor->vendor_id, vendor->vendor_name); | |
1160 } | |
1161 static void dump_application_data ( void * data ) | |
1162 { | |
1163 struct dict_application_data * appli = (struct dict_application_data *) data; | |
1164 fd_log_debug("data: %-6u \"%s\"", appli->application_id, appli->application_name); | |
1165 } | |
1166 static void dump_type_data ( void * data ) | |
1167 { | |
1168 struct dict_type_data * type = ( struct dict_type_data * ) data; | |
1169 | |
1170 fd_log_debug("data: %-12s \"%s\"", | |
1171 type_base_name[type->type_base], | |
1172 type->type_name); | |
1173 } | |
1174 static void dump_enumval_data ( struct dict_enumval_data * enumval, enum dict_avp_basetype type ) | |
1175 { | |
1176 const int LEN_MAX = 20; | |
1177 fd_log_debug("data: (%-12s) \"%s\" -> ", type_base_name[type], enumval->enum_name); | |
1178 switch (type) { | |
1179 case AVP_TYPE_OCTETSTRING: | |
1180 { | |
1181 int i, n=LEN_MAX; | |
1182 if (enumval->enum_value.os.len < LEN_MAX) | |
1183 n = enumval->enum_value.os.len; | |
1184 for (i=0; i < n; i++) | |
1185 fd_log_debug("0x%02.2X/'%c' ", enumval->enum_value.os.data[i], ASCII(enumval->enum_value.os.data[i])); | |
1186 if (n == LEN_MAX) | |
1187 fd_log_debug("..."); | |
1188 } | |
1189 break; | |
1190 | |
1191 case AVP_TYPE_INTEGER32: | |
1192 fd_log_debug("%i", enumval->enum_value.i32); | |
1193 break; | |
1194 | |
1195 case AVP_TYPE_INTEGER64: | |
1196 fd_log_debug("%lli", enumval->enum_value.i64); | |
1197 break; | |
1198 | |
1199 case AVP_TYPE_UNSIGNED32: | |
1200 fd_log_debug("%u", enumval->enum_value.u32); | |
1201 break; | |
1202 | |
1203 case AVP_TYPE_UNSIGNED64: | |
1204 fd_log_debug("%llu", enumval->enum_value.u64); | |
1205 break; | |
1206 | |
1207 case AVP_TYPE_FLOAT32: | |
1208 fd_log_debug("%f", enumval->enum_value.f32); | |
1209 break; | |
1210 | |
1211 case AVP_TYPE_FLOAT64: | |
1212 fd_log_debug("%g", enumval->enum_value.f64); | |
1213 break; | |
1214 | |
1215 default: | |
1216 fd_log_debug("??? (ERROR unknown type %d)", type); | |
1217 } | |
1218 } | |
1219 static void dump_avp_data ( void * data ) | |
1220 { | |
1221 struct dict_avp_data * avp = (struct dict_avp_data * ) data; | |
1222 fd_log_debug("data: v/m:" DUMP_AVPFL_str "/" DUMP_AVPFL_str ", %12s, %-6u \"%s\"", | |
1223 DUMP_AVPFL_val(avp->avp_flag_val), | |
1224 DUMP_AVPFL_val(avp->avp_flag_mask), | |
1225 type_base_name[avp->avp_basetype], | |
1226 avp->avp_code, | |
1227 avp->avp_name ); | |
1228 } | |
1229 static void dump_command_data ( void * data ) | |
1230 { | |
1231 struct dict_cmd_data * cmd = (struct dict_cmd_data *) data; | |
1232 fd_log_debug("data: v/m:" DUMP_CMDFL_str "/" DUMP_CMDFL_str ", %-6u \"%s\"", | |
1233 DUMP_CMDFL_val(cmd->cmd_flag_val), DUMP_CMDFL_val(cmd->cmd_flag_mask), cmd->cmd_code, cmd->cmd_name); | |
1234 } | |
1235 static void dump_rule_data ( void * data ) | |
1236 { | |
1237 struct dict_rule_data * rule = (struct dict_rule_data * )data; | |
1238 fd_log_debug("data: pos:%d ord:%d m/M:%2d/%2d avp:\"%s\"", | |
1239 rule->rule_position, | |
1240 rule->rule_order, | |
1241 rule->rule_min, | |
1242 rule->rule_max, | |
1243 rule->rule_avp->data.avp.avp_name); | |
1244 } | |
1245 | |
1246 static void dump_object ( struct dict_object * obj, int parents, int depth, int indent ); | |
1247 | |
1248 static void dump_list ( struct fd_list * sentinel, int parents, int depth, int indent ) | |
1249 { | |
1250 struct fd_list * li = sentinel; | |
1251 /* We don't lock here, the caller must have taken the dictionary lock for reading already */ | |
1252 while (li->next != sentinel) | |
1253 { | |
1254 li = li->next; | |
1255 dump_object( _O(li->o), parents, depth, indent ); | |
1256 } | |
1257 } | |
1258 | |
1259 static void dump_object ( struct dict_object * obj, int parents, int depth, int indent ) | |
1260 { | |
1261 if (obj == NULL) | |
1262 return; | |
1263 | |
1264 if (parents) | |
1265 dump_object (obj->parent, parents-1, 0, indent + 1 ); | |
1266 | |
1267 fd_log_debug("%*s@%p: %s%s (p:%-9p) ", | |
1268 indent, | |
1269 "", | |
1270 obj, | |
1271 verify_object(obj) ? "" : "INVALID ", | |
1272 _OBINFO(obj).name, | |
1273 obj->parent); | |
1274 | |
1275 if (obj->type == DICT_ENUMVAL) | |
1276 dump_enumval_data ( &obj->data.enumval, obj->parent->data.type.type_base ); | |
1277 else | |
1278 _OBINFO(obj).dump_data(&obj->data); | |
1279 | |
1280 fd_log_debug("\n"); | |
1281 | |
1282 if (depth) { | |
1283 int i; | |
1284 for (i=0; i<NB_LISTS_PER_OBJ; i++) { | |
1285 if ((obj->list[i].o == NULL) && (obj->list[i].next != &obj->list[i])) { | |
1286 fd_log_debug("%*s>%p: list[%d]:\n", indent, "", obj, i); | |
1287 dump_list(&obj->list[i], parents, depth - 1, indent + 2); | |
1288 } | |
1289 } | |
1290 } | |
1291 } | |
1292 | |
1293 void fd_dict_dump_object(struct dict_object * obj) | |
1294 { | |
1295 fd_log_debug("Dictionary object %p dump:\n", obj); | |
1296 dump_object( obj, 1, 2, 2 ); | |
1297 } | |
1298 | |
1299 void fd_dict_dump(struct dictionary * dict) | |
1300 { | |
1301 int i; | |
828
78307a61c578
Fix regression in dictionary dump
Sebastien Decugis <sdecugis@freediameter.net>
parents:
804
diff
changeset
|
1302 struct fd_list * li; |
0 | 1303 |
1304 CHECK_PARAMS_DO(dict && (dict->dict_eyec == DICT_EYECATCHER), return); | |
1305 | |
1306 CHECK_POSIX_DO( pthread_rwlock_rdlock( &dict->dict_lock ), /* ignore */ ); | |
1307 | |
1308 fd_log_debug("######################################################\n"); | |
1309 fd_log_debug("###### Dumping vendors, AVPs and related rules #######\n"); | |
1310 | |
1311 dump_object( &dict->dict_vendors, 0, 3, 0 ); | |
828
78307a61c578
Fix regression in dictionary dump
Sebastien Decugis <sdecugis@freediameter.net>
parents:
804
diff
changeset
|
1312 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
|
1313 dump_object( li->o, 0, 3, 0 ); |
0 | 1314 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1315 fd_log_debug("###### Dumping applications #######\n"); |
0 | 1316 |
1317 dump_object( &dict->dict_applications, 0, 1, 0 ); | |
828
78307a61c578
Fix regression in dictionary dump
Sebastien Decugis <sdecugis@freediameter.net>
parents:
804
diff
changeset
|
1318 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
|
1319 dump_object( li->o, 0, 1, 0 ); |
0 | 1320 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1321 fd_log_debug("###### Dumping types #######\n"); |
0 | 1322 |
1323 dump_list( &dict->dict_types, 0, 2, 0 ); | |
1324 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1325 fd_log_debug("###### Dumping commands per name #######\n"); |
0 | 1326 |
1327 dump_list( &dict->dict_cmd_name, 0, 2, 0 ); | |
1328 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1329 fd_log_debug("###### Dumping commands per code and flags #######\n"); |
0 | 1330 |
1331 dump_list( &dict->dict_cmd_code, 0, 0, 0 ); | |
1332 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1333 fd_log_debug("###### Statistics #######\n"); |
0 | 1334 |
1335 for (i=1; i<=DICT_TYPE_MAX; i++) | |
1336 fd_log_debug(" %5d objects of type %s\n", dict->dict_count[i], dict_obj_info[i].name); | |
1337 | |
1338 fd_log_debug("######################################################\n"); | |
1339 | |
1340 /* Free the rwlock */ | |
1341 CHECK_POSIX_DO( pthread_rwlock_unlock( &dict->dict_lock ), /* ignore */ ); | |
1342 } | |
1343 | |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1344 /**************************** Dump AVP values ********************************/ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1345 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1346 /* 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
|
1347 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
|
1348 { |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1349 int i; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1350 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
|
1351 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
|
1352 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
|
1353 break; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1354 } |
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
|
1355 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
|
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 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1358 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1359 |
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
|
1360 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
|
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 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
|
1363 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1364 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1365 |
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
|
1366 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
|
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 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
|
1369 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1370 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1371 |
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
|
1372 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
|
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 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
|
1375 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1376 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1377 |
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
|
1378 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
|
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 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
|
1381 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1382 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1383 |
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
|
1384 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
|
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 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
|
1387 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1388 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1389 |
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
|
1390 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
|
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 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
|
1393 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1394 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1395 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1396 /* 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
|
1397 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
|
1398 { |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1399 switch (datatype) { |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1400 case AVP_TYPE_OCTETSTRING: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1401 return &dump_val_os; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1402 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1403 case AVP_TYPE_INTEGER32: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1404 return &dump_val_i32; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1405 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1406 case AVP_TYPE_INTEGER64: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1407 return &dump_val_i64; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1408 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1409 case AVP_TYPE_UNSIGNED32: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1410 return &dump_val_u32; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1411 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1412 case AVP_TYPE_UNSIGNED64: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1413 return &dump_val_u64; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1414 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1415 case AVP_TYPE_FLOAT32: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1416 return &dump_val_f32; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1417 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1418 case AVP_TYPE_FLOAT64: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1419 return &dump_val_f64; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1420 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1421 case AVP_TYPE_GROUPED: |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1422 TRACE_DEBUG(FULL, "error: grouped AVP with a value!"); |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1423 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1424 return NULL; |
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 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1427 /* indent inside an object (duplicate from messages.c) */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1428 #define INOBJHDR "%*s " |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1429 #define INOBJHDRVAL indent<0 ? 1 : indent, indent<0 ? "-" : "|" |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1430 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1431 /* 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
|
1432 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
|
1433 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
|
1434 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
|
1435 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
|
1436 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
|
1437 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
|
1438 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
|
1439 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
|
1440 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
|
1441 size_t *outlen) |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1442 { |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1443 /* 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
|
1444 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
|
1445 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1446 /* 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
|
1447 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
|
1448 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
|
1449 } |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1450 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1451 /* 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
|
1452 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
|
1453 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1454 /* 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
|
1455 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
|
1456 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
|
1457 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
|
1458 } |
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 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
|
1460 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
|
1461 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
|
1462 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
|
1463 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
|
1464 } 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
|
1465 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
|
1466 } |
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 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
|
1468 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
|
1469 } |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1470 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1471 /* 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
|
1472 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
|
1473 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1474 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1475 |
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
|
1476 /* 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
|
1477 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
|
1478 { |
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
|
1479 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
|
1480 struct dict_object * type = NULL; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1481 char * type_name = NULL; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1482 char * const_name = NULL; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1483 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1484 /* 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
|
1485 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
|
1486 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1487 /* Get the type definition of this AVP */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1488 type = model->parent; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1489 if (type) { |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1490 struct dict_enumval_request request; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1491 struct dict_object * enumval = NULL; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1492 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1493 type_name = type->data.type.type_name; |
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 /* overwrite the dump function ? */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1496 if (type->data.type.type_dump) |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1497 dump_val_cb = type->data.type.type_dump; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1498 |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1499 /* Now check if the AVP value matches a constant */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1500 memset(&request, 0, sizeof(request)); |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1501 request.type_obj = type; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1502 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
|
1503 /* bypass checks */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1504 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
|
1505 /* We found a cosntant, get its name */ |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1506 const_name = enumval->data.enumval.enum_name; |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1507 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1508 } |
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 /* 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
|
1511 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
|
1512 return 0; |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1513 } |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
111
diff
changeset
|
1514 |
0 | 1515 /*******************************************************************************************************/ |
1516 /*******************************************************************************************************/ | |
1517 /* */ | |
1518 /* Exported functions */ | |
1519 /* */ | |
1520 /*******************************************************************************************************/ | |
1521 /*******************************************************************************************************/ | |
1522 | |
1
bafb831ba688
Fix names to proper case for freeDiameter
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
0
diff
changeset
|
1523 /* These are the functions exported outside libfreeDiameter. */ |
0 | 1524 |
1525 /* Get the data associated to an object */ | |
1526 int fd_dict_gettype ( struct dict_object * object, enum dict_object_type * type) | |
1527 { | |
1528 TRACE_ENTRY("%p %p", object, type); | |
1529 | |
1530 CHECK_PARAMS( type && verify_object(object) ); | |
1531 | |
1532 /* Copy the value and return */ | |
1533 *type = object->type; | |
1534 return 0; | |
1535 } | |
1536 | |
1537 int fd_dict_getdict ( struct dict_object * object, struct dictionary ** dict) | |
1538 { | |
1539 TRACE_ENTRY("%p %p", object, dict); | |
1540 | |
1541 CHECK_PARAMS( dict && verify_object(object) ); | |
1542 | |
1543 /* Copy the value and return */ | |
1544 *dict = object->dico; | |
1545 return 0; | |
1546 } | |
1547 | |
1548 | |
1549 /* Get the data associated to an object */ | |
1550 int fd_dict_getval ( struct dict_object * object, void * val) | |
1551 { | |
1552 TRACE_ENTRY("%p %p", object, val); | |
1553 | |
1554 CHECK_PARAMS( val && verify_object(object) ); | |
1555 | |
1556 /* Copy the value and return */ | |
1557 memcpy(val, &object->data, _OBINFO(object).datasize);; | |
1558 return 0; | |
1559 } | |
1560 | |
1561 /* Add a new object in the dictionary */ | |
1562 int fd_dict_new ( struct dictionary * dict, enum dict_object_type type, void * data, struct dict_object * parent, struct dict_object **ref ) | |
1563 { | |
1564 int ret = 0; | |
1565 struct dict_object * new = NULL; | |
1566 struct dict_object * vendor = NULL; | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1567 struct dict_object * locref = NULL; |
0 | 1568 |
1569 TRACE_ENTRY("%p %d(%s) %p %p %p", dict, type, dict_obj_info[CHECK_TYPE(type) ? type : 0].name, data, parent, ref); | |
1570 | |
1571 /* Check parameters */ | |
1572 CHECK_PARAMS( dict && (dict->dict_eyec == DICT_EYECATCHER) && CHECK_TYPE(type) && data ); | |
1573 | |
1574 /* Check the "parent" parameter */ | |
1575 switch (dict_obj_info[type].parent) { | |
1576 case 0: /* parent is forbidden */ | |
1577 CHECK_PARAMS( parent == NULL ); | |
1578 | |
1579 case 1: /* parent is optional */ | |
1580 if (parent == NULL) | |
1581 break; | |
1582 | |
1583 case 2: /* parent is mandatory */ | |
1584 CHECK_PARAMS( verify_object(parent) ); | |
1585 | |
1586 if (type == DICT_RULE ) { /* Special case : grouped AVP or Command parents are allowed */ | |
1587 CHECK_PARAMS( (parent->type == DICT_COMMAND ) | |
1588 || ( (parent->type == DICT_AVP) && (parent->data.avp.avp_basetype == AVP_TYPE_GROUPED ) ) ); | |
1589 } else { | |
1590 CHECK_PARAMS( parent->type == dict_obj_info[type].parenttype ); | |
1591 } | |
1592 } | |
1593 | |
1594 /* For AVP object, we must also check that the "vendor" referenced exists */ | |
1595 if (type == DICT_AVP) { | |
1596 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
|
1597 { TRACE_DEBUG(INFO, "Unable to find vendor '%d' referenced in the AVP data", ((struct dict_avp_data *)data)->avp_vendor); return EINVAL; } ); |
0 | 1598 |
1599 /* Also check if a parent is provided, that the type are the same */ | |
1600 if (parent) { | |
1601 CHECK_PARAMS( parent->data.type.type_base == ((struct dict_avp_data *)data)->avp_basetype ); | |
1602 } | |
1603 } | |
1604 | |
1605 /* For RULE object, we must also check that the "avp" referenced exists */ | |
1606 if (type == DICT_RULE) { | |
1607 CHECK_PARAMS( verify_object(((struct dict_rule_data *)data)->rule_avp) ); | |
1608 CHECK_PARAMS( ((struct dict_rule_data *)data)->rule_avp->type == DICT_AVP ); | |
1609 } | |
1610 | |
1611 /* For COMMAND object, check that the 'R' flag is fixed */ | |
1612 if (type == DICT_COMMAND) { | |
1613 CHECK_PARAMS( ((struct dict_cmd_data *)data)->cmd_flag_mask & CMD_FLAG_REQUEST ); | |
1614 } | |
1615 | |
109
a522268ec95b
Less permissive in fd_dict_new
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1616 /* 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
|
1617 if (type == DICT_VENDOR) { |
a522268ec95b
Less permissive in fd_dict_new
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1618 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
|
1619 } |
a522268ec95b
Less permissive in fd_dict_new
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1620 if (type == DICT_APPLICATION) { |
a522268ec95b
Less permissive in fd_dict_new
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1621 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
|
1622 } |
a522268ec95b
Less permissive in fd_dict_new
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1623 |
0 | 1624 /* Parameters are valid, create the new object */ |
1625 CHECK_MALLOC( new = malloc(sizeof(struct dict_object)) ); | |
1626 | |
1627 /* Initialize the data of the new object */ | |
1628 init_object(new, type); | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1629 init_object_data(new, data, type); |
0 | 1630 new->dico = dict; |
1631 new->parent = parent; | |
1632 | |
1633 /* We will change the dictionary => acquire the write lock */ | |
1634 CHECK_POSIX_DO( ret = pthread_rwlock_wrlock(&dict->dict_lock), goto error_free ); | |
1635 | |
1636 /* Now link the object -- this also checks that no object with same keys already exists */ | |
1637 switch (type) { | |
1638 case DICT_VENDOR: | |
1639 /* 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
|
1640 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
|
1641 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1642 goto error_unlock; |
0 | 1643 break; |
1644 | |
1645 case DICT_APPLICATION: | |
1646 /* 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
|
1647 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
|
1648 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1649 goto error_unlock; |
0 | 1650 break; |
1651 | |
1652 case DICT_TYPE: | |
1653 /* 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
|
1654 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
|
1655 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1656 goto error_unlock; |
0 | 1657 break; |
1658 | |
1659 case DICT_ENUMVAL: | |
1660 /* 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
|
1661 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
|
1662 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1663 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1664 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1665 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
|
1666 if (ret) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1667 fd_list_unlink(&new->list[0]); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1668 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1669 } |
0 | 1670 break; |
1671 | |
1672 case DICT_AVP: | |
1673 /* 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
|
1674 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
|
1675 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1676 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1677 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1678 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
|
1679 if (ret) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1680 fd_list_unlink(&new->list[0]); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1681 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1682 } |
0 | 1683 break; |
1684 | |
1685 case DICT_COMMAND: | |
1686 /* 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
|
1687 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
|
1688 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1689 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1690 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1691 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
|
1692 if (ret) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1693 fd_list_unlink(&new->list[1]); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1694 goto error_unlock; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1695 } |
0 | 1696 break; |
1697 | |
1698 case DICT_RULE: | |
1699 /* 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
|
1700 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
|
1701 if (ret) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1702 goto error_unlock; |
0 | 1703 break; |
1704 | |
1705 default: | |
1706 ASSERT(0); | |
1707 } | |
1708 | |
1709 /* A new object has been created, increment the global counter */ | |
1710 dict->dict_count[type]++; | |
1711 | |
1712 /* Unlock the dictionary */ | |
1713 CHECK_POSIX_DO( ret = pthread_rwlock_unlock(&dict->dict_lock), goto error_free ); | |
1714 | |
1715 /* Save the pointer to the new object */ | |
1716 if (ref) | |
1717 *ref = new; | |
1718 | |
1719 return 0; | |
1720 | |
1721 error_unlock: | |
1722 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
|
1723 if (ret == EEXIST) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1724 /* 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
|
1725 switch (type) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1726 case DICT_VENDOR: |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1727 /* 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
|
1728 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
|
1729 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
|
1730 TRACE_DEBUG(FULL, "Conflicting vendor name"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1731 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1732 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1733 /* 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
|
1734 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1735 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1736 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1737 case DICT_APPLICATION: |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1738 /* got same id */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1739 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
|
1740 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
|
1741 TRACE_DEBUG(FULL, "Conflicting application name"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1742 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1743 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1744 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1745 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1746 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1747 case DICT_TYPE: |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1748 /* got same name */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1749 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
|
1750 TRACE_DEBUG(FULL, "Conflicting base type"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1751 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1752 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1753 /* 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
|
1754 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
|
1755 TRACE_DEBUG(FULL, "Conflicting interpret cb"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1756 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1757 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1758 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
|
1759 TRACE_DEBUG(FULL, "Conflicting encode cb"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1760 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1761 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1762 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
|
1763 TRACE_DEBUG(FULL, "Conflicting dump cb"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1764 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1765 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1766 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1767 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1768 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1769 case DICT_ENUMVAL: |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1770 /* 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
|
1771 if (order_enum_by_name(locref, new)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1772 TRACE_DEBUG(FULL, "Conflicting enum name"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1773 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1774 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1775 if (order_enum_by_val(locref, new)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1776 TRACE_DEBUG(FULL, "Conflicting enum value"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1777 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1778 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1779 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1780 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1781 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1782 case DICT_AVP: |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1783 /* got either same name or code */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1784 if (order_avp_by_code(locref, new)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1785 TRACE_DEBUG(FULL, "Conflicting AVP code"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1786 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1787 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1788 if (order_avp_by_name(locref, new)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1789 TRACE_DEBUG(FULL, "Conflicting AVP name"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1790 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1791 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1792 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
|
1793 TRACE_DEBUG(FULL, "Conflicting AVP vendor"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1794 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1795 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1796 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
|
1797 TRACE_DEBUG(FULL, "Conflicting AVP flags mask"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1798 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1799 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1800 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
|
1801 TRACE_DEBUG(FULL, "Conflicting AVP flags value"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1802 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1803 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1804 if (locref->data.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
|
1805 TRACE_DEBUG(FULL, "Conflicting AVP base type"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1806 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1807 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1808 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1809 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1810 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1811 case DICT_COMMAND: |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1812 /* 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
|
1813 if (order_cmd_by_name(locref, new)) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1814 TRACE_DEBUG(FULL, "Conflicting command name"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1815 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1816 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1817 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
|
1818 TRACE_DEBUG(FULL, "Conflicting command code"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1819 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1820 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1821 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
|
1822 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
|
1823 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1824 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1825 if ((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
|
1826 TRACE_DEBUG(FULL, "Conflicting command flags value"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1827 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1828 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1829 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1830 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1831 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1832 case DICT_RULE: |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
1833 /* 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
|
1834 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
|
1835 TRACE_DEBUG(FULL, "Conflicting rule position"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1836 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1837 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1838 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
|
1839 (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
|
1840 && (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
|
1841 TRACE_DEBUG(FULL, "Conflicting rule order"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1842 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1843 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1844 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
|
1845 int r1 = locref->data.rule.rule_min; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1846 int r2 = new->data.rule.rule_min; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1847 int p = locref->data.rule.rule_position; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1848 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
|
1849 || ((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
|
1850 || ((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
|
1851 ) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1852 TRACE_DEBUG(FULL, "Conflicting rule min"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1853 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1854 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1855 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1856 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
|
1857 TRACE_DEBUG(FULL, "Conflicting rule max"); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1858 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1859 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1860 ret = 0; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1861 break; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1862 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1863 if (ret) { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1864 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
|
1865 if (TRACE_BOOL(INFO)) { |
84a23e90519d
More verbose information on conflicts
Sebastien Decugis <sdecugis@freediameter.net>
parents:
828
diff
changeset
|
1866 fd_log_debug("New object to insert:\n"); |
84a23e90519d
More verbose information on conflicts
Sebastien Decugis <sdecugis@freediameter.net>
parents:
828
diff
changeset
|
1867 dump_object(new, 0, 0, 3); |
84a23e90519d
More verbose information on conflicts
Sebastien Decugis <sdecugis@freediameter.net>
parents:
828
diff
changeset
|
1868 fd_log_debug("Object already in dictionary:\n"); |
84a23e90519d
More verbose information on conflicts
Sebastien Decugis <sdecugis@freediameter.net>
parents:
828
diff
changeset
|
1869 dump_object(locref, 0, 0 , 3); |
84a23e90519d
More verbose information on conflicts
Sebastien Decugis <sdecugis@freediameter.net>
parents:
828
diff
changeset
|
1870 } |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1871 } else { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1872 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
|
1873 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1874 if (ref) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1875 *ref = locref; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1876 } else { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1877 CHECK_FCT_DO( ret, ); /* log the error */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1878 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
602
diff
changeset
|
1879 |
0 | 1880 error_free: |
1881 free(new); | |
1882 return ret; | |
1883 } | |
1884 | |
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
|
1885 |
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
|
1886 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
|
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 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
|
1889 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
|
1890 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
|
1891 |
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 /* 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
|
1893 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
|
1894 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
|
1895 |
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 /* 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
|
1897 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
|
1898 |
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 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
|
1900 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
|
1901 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
|
1902 /* 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
|
1903 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
|
1904 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
|
1905 #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
|
1906 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
|
1907 #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
|
1908 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
|
1909 } |
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 } |
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 /* 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
|
1913 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
|
1914 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
|
1915 |
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 /* 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
|
1917 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
|
1918 |
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 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
|
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 |
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 |
907
b772af200865
Add a few const declaration so that C++ is less picky
Sebastien Decugis <sdecugis@freediameter.net>
parents:
906
diff
changeset
|
1923 int fd_dict_search ( struct dictionary * dict, enum dict_object_type type, int criteria, const void * what, struct dict_object **result, int retval ) |
0 | 1924 { |
1925 int ret = 0; | |
1926 | |
1927 TRACE_ENTRY("%p %d(%s) %d %p %p %d", dict, type, dict_obj_info[CHECK_TYPE(type) ? type : 0].name, criteria, what, result, retval); | |
1928 | |
1929 /* Check param */ | |
1930 CHECK_PARAMS( dict && (dict->dict_eyec == DICT_EYECATCHER) && CHECK_TYPE(type) ); | |
1931 | |
1932 /* Lock the dictionary for reading */ | |
1933 CHECK_POSIX( pthread_rwlock_rdlock(&dict->dict_lock) ); | |
1934 | |
1935 /* Now call the type-specific search function */ | |
1936 ret = dict_obj_info[type].search_fct (dict, criteria, what, result); | |
1937 | |
1938 /* Unlock */ | |
1939 CHECK_POSIX( pthread_rwlock_unlock(&dict->dict_lock) ); | |
1940 | |
1941 /* Update the return value as needed */ | |
1942 if ((result != NULL) && (*result == NULL)) | |
1943 ret = retval; | |
1944 | |
1945 return ret; | |
1946 } | |
1947 | |
764
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1948 /* 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
|
1949 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1950 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
|
1951 |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
1952 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
|
1953 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
|
1954 ... |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1955 } |
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 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
|
1958 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
|
1959 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1960 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
|
1961 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
|
1962 ** 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
|
1963 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
|
1964 |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
1965 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
|
1966 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
|
1967 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
|
1968 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
|
1969 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
|
1970 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
|
1971 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
|
1972 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
|
1973 |
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 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
|
1975 */ |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
1976 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
|
1977 { |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1978 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
|
1979 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
|
1980 |
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 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
|
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 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
|
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 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
|
1986 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
|
1987 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
|
1988 *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
|
1989 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
|
1990 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1991 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
|
1992 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
|
1993 *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
|
1994 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
|
1995 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
1996 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
|
1997 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
|
1998 *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
|
1999 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
|
2000 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2001 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
|
2002 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
|
2003 *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
|
2004 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
|
2005 |
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 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
|
2007 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
|
2008 *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
|
2009 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
|
2010 |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2011 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
|
2012 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
|
2013 *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
|
2014 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
|
2015 |
769
99136ec7d9d4
Fixed fd_dict_getlistof function, added a simple test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
764
diff
changeset
|
2016 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
|
2017 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
|
2018 *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
|
2019 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
|
2020 |
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 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
|
2022 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
|
2023 *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
|
2024 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
|
2025 |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2026 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
|
2027 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
|
2028 *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
|
2029 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
|
2030 |
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 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
|
2032 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
|
2033 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
|
2034 ((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
|
2035 && (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
|
2036 *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
|
2037 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
|
2038 |
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 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
|
2040 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
|
2041 } |
f53e5b5fdfd3
Added new experimental function fd_dict_getlistof -- see http://lists.freediameter.net/pipermail/help/2011-October/000268.html for context and rationale. WARNING: this function was not tested yet...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
2042 |
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 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
|
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 |
0 | 2046 /*******************************************************************************************************/ |
2047 /*******************************************************************************************************/ | |
2048 /* */ | |
2049 /* The init/fini functions */ | |
2050 /* */ | |
2051 /*******************************************************************************************************/ | |
2052 /*******************************************************************************************************/ | |
2053 | |
2054 /* Initialize the dictionary */ | |
2055 int fd_dict_init ( struct dictionary ** dict) | |
2056 { | |
2057 struct dictionary * new = NULL; | |
2058 | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
2059 TRACE_ENTRY("%p", dict); |
0 | 2060 |
2061 /* Sanity checks */ | |
2062 ASSERT( (sizeof(type_base_name) / sizeof(type_base_name[0])) == (AVP_TYPE_MAX + 1) ); | |
2063 ASSERT( (sizeof(dict_obj_info) / sizeof(dict_obj_info[0])) == (DICT_TYPE_MAX + 1) ); | |
2064 CHECK_PARAMS(dict); | |
2065 | |
2066 /* Allocate the memory for the dictionary */ | |
2067 CHECK_MALLOC( new = malloc(sizeof(struct dictionary)) ); | |
2068 memset(new, 0, sizeof(struct dictionary)); | |
2069 | |
2070 new->dict_eyec = DICT_EYECATCHER; | |
2071 | |
2072 /* Initialize the lock for the dictionary */ | |
2073 CHECK_POSIX( pthread_rwlock_init(&new->dict_lock, NULL) ); | |
2074 | |
2075 /* Initialize the sentinel for vendors and AVP lists */ | |
2076 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
|
2077 #define NO_VENDOR_NAME "(no vendor)" |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
687
diff
changeset
|
2078 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
|
2079 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
|
2080 /* 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
|
2081 new->dict_vendors.dico = new; |
0 | 2082 |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2083 /* Initialize the sentinel for applications */ |
0 | 2084 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
|
2085 #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
|
2086 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
|
2087 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
|
2088 /* 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
|
2089 new->dict_applications.dico = new; |
0 | 2090 |
2091 /* Initialize the sentinel for types */ | |
2092 fd_list_init ( &new->dict_types, NULL ); | |
2093 | |
2094 /* Initialize the sentinels for commands */ | |
2095 fd_list_init ( &new->dict_cmd_name, NULL ); | |
2096 fd_list_init ( &new->dict_cmd_code, NULL ); | |
2097 | |
2098 /* Initialize the error command object */ | |
2099 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
|
2100 #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
|
2101 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
|
2102 new->dict_cmd_error.datastr_len = CONSTSTRLEN(GENERIC_ERROR_NAME); |
0 | 2103 new->dict_cmd_error.data.cmd.cmd_flag_mask=CMD_FLAG_ERROR | CMD_FLAG_REQUEST | CMD_FLAG_RETRANSMIT; |
2104 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
|
2105 new->dict_cmd_error.dico = new; |
0 | 2106 |
2107 *dict = new; | |
2108 | |
2109 /* Done */ | |
2110 return 0; | |
2111 } | |
2112 | |
2113 /* Destroy a dictionary */ | |
2114 int fd_dict_fini ( struct dictionary ** dict) | |
2115 { | |
2116 int i; | |
2117 | |
2118 TRACE_ENTRY(""); | |
2119 CHECK_PARAMS( dict && *dict && ((*dict)->dict_eyec == DICT_EYECATCHER) ); | |
2120 | |
2121 /* Acquire the write lock to make sure no other operation is ongoing */ | |
2122 CHECK_POSIX( pthread_rwlock_wrlock(&(*dict)->dict_lock) ); | |
2123 | |
2124 /* Empty all the lists, free the elements */ | |
2125 destroy_list ( &(*dict)->dict_cmd_error.list[2] ); | |
2126 destroy_list ( &(*dict)->dict_cmd_code ); | |
2127 destroy_list ( &(*dict)->dict_cmd_name ); | |
2128 destroy_list ( &(*dict)->dict_types ); | |
2129 for (i=0; i< NB_LISTS_PER_OBJ; i++) { | |
2130 destroy_list ( &(*dict)->dict_applications.list[i] ); | |
2131 destroy_list ( &(*dict)->dict_vendors.list[i] ); | |
2132 } | |
2133 | |
2134 /* Dictionary is empty, now destroy the lock */ | |
2135 CHECK_POSIX( pthread_rwlock_unlock(&(*dict)->dict_lock) ); | |
2136 CHECK_POSIX( pthread_rwlock_destroy(&(*dict)->dict_lock) ); | |
2137 | |
2138 free(*dict); | |
2139 *dict = NULL; | |
2140 | |
2141 return 0; | |
2142 } | |
2143 | |
2144 /*******************************************************************************************************/ | |
2145 /*******************************************************************************************************/ | |
2146 /* */ | |
2147 /* Other functions */ | |
2148 /* */ | |
2149 /*******************************************************************************************************/ | |
2150 /*******************************************************************************************************/ | |
2151 | |
2152 /* Iterate a callback on the rules for an object */ | |
2153 int fd_dict_iterate_rules ( struct dict_object *parent, void * data, int (*cb)(void *, struct dict_rule_data *) ) | |
2154 { | |
2155 int ret = 0; | |
2156 struct fd_list * li; | |
2157 | |
2158 TRACE_ENTRY("%p %p %p", parent, data, cb); | |
2159 | |
2160 /* Check parameters */ | |
2161 CHECK_PARAMS( verify_object(parent) ); | |
2162 CHECK_PARAMS( (parent->type == DICT_COMMAND) | |
2163 || ((parent->type == DICT_AVP) && (parent->data.avp.avp_basetype == AVP_TYPE_GROUPED)) ); | |
2164 TRACE_DEBUG (FULL, "Iterating on rules of %s: '%s'.", | |
2165 _OBINFO(parent).name, | |
2166 parent->type == DICT_COMMAND ? | |
2167 parent->data.cmd.cmd_name | |
2168 : parent->data.avp.avp_name); | |
2169 | |
2170 /* Acquire the read lock */ | |
2171 CHECK_POSIX( pthread_rwlock_rdlock(&parent->dico->dict_lock) ); | |
2172 | |
2173 /* go through the list and call the cb on each rule data */ | |
2174 for (li = &(parent->list[2]); li->next != &(parent->list[2]); li = li->next) { | |
2175 ret = (*cb)(data, &(_O(li->next->o)->data.rule)); | |
2176 if (ret != 0) | |
2177 break; | |
2178 } | |
2179 | |
2180 /* Release the lock */ | |
2181 CHECK_POSIX( pthread_rwlock_unlock(&parent->dico->dict_lock) ); | |
2182 | |
2183 return ret; | |
2184 } | |
2185 | |
2186 /* Create the list of vendors. Returns a 0-terminated array, that must be freed after use. Returns NULL on error. */ | |
2187 uint32_t * fd_dict_get_vendorid_list(struct dictionary * dict) | |
2188 { | |
2189 uint32_t * ret = NULL; | |
2190 int i = 0; | |
2191 struct fd_list * li; | |
2192 | |
2193 TRACE_ENTRY(); | |
2194 | |
2195 /* Acquire the read lock */ | |
2196 CHECK_POSIX_DO( pthread_rwlock_rdlock(&dict->dict_lock), return NULL ); | |
2197 | |
2198 /* Allocate an array to contain all the elements */ | |
2199 CHECK_MALLOC_DO( ret = calloc( dict->dict_count[DICT_VENDOR] + 1, sizeof(uint32_t) ), goto out ); | |
2200 | |
2201 /* Copy the vendors IDs */ | |
2202 for (li = dict->dict_vendors.list[0].next; li != &(dict->dict_vendors.list[0]); li = li->next) { | |
2203 ret[i] = _O(li->o)->data.vendor.vendor_id; | |
2204 i++; | |
2205 ASSERT( i <= dict->dict_count[DICT_VENDOR] ); | |
2206 } | |
2207 out: | |
2208 /* Release the lock */ | |
2209 CHECK_POSIX_DO( pthread_rwlock_unlock(&dict->dict_lock), return NULL ); | |
2210 | |
2211 return ret; | |
2212 } | |
2213 | |
2214 /* Return the location of the cb list for an object, after checking its type */ | |
2215 int fd_dict_disp_cb(enum dict_object_type type, struct dict_object *obj, struct fd_list ** cb_list) | |
2216 { | |
2217 TRACE_ENTRY("%d %p %p", type, obj, cb_list); | |
2218 CHECK_PARAMS( verify_object(obj) ); | |
2219 CHECK_PARAMS( _OBINFO(obj).type == type ); | |
2220 CHECK_PARAMS( cb_list ); | |
2221 *cb_list = &obj->disp_cbs; | |
2222 return 0; | |
2223 } | |
2224 | |
2225 int fd_dict_get_error_cmd(struct dictionary * dict, struct dict_object **obj) | |
2226 { | |
2227 TRACE_ENTRY("%p %p", dict, obj); | |
2228 CHECK_PARAMS( dict && (dict->dict_eyec == DICT_EYECATCHER) && obj ); | |
2229 *obj = &dict->dict_cmd_error; | |
2230 return 0; | |
2231 } |