Mercurial > hg > freeDiameter
annotate libfreeDiameter/messages.c @ 100:05ea77b86f53
Fix invalid flag
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Tue, 08 Dec 2009 11:23:15 +0900 |
parents | 2c9444152e4b |
children | 6a294d977878 |
rev | line source |
---|---|
0 | 1 /********************************************************************************************************* |
2 * Software License Agreement (BSD License) * | |
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> * | |
4 * * | |
5 * Copyright (c) 2009, WIDE Project and NICT * | |
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 | |
36 /* Messages module. | |
37 * | |
38 * This module allows to manipulate the msg and avp structures that represents a Diameter message in memory. | |
39 */ | |
40 | |
1
bafb831ba688
Fix names to proper case for freeDiameter
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
0
diff
changeset
|
41 #include "libfD.h" |
0 | 42 |
43 #include <sys/param.h> | |
44 | |
45 /* Type of object */ | |
46 enum msg_objtype { | |
47 MSG_MSG = 1, | |
48 MSG_AVP | |
49 }; | |
50 | |
51 /* Chaining of elements as a free hierarchy */ | |
52 struct msg_avp_chain { | |
53 struct fd_list chaining; /* Chaining information at this level. */ | |
54 struct fd_list children; /* sentinel for the children of this object */ | |
55 enum msg_objtype type; /* Type of this object, _MSG_MSG or _MSG_AVP */ | |
56 }; | |
57 | |
58 /* Return the chain information from an AVP or MSG. Since it's the first field, we just cast */ | |
59 #define _C(_x) ((struct msg_avp_chain *)(_x)) | |
60 | |
61 /* Some details about chaining: | |
62 * | |
63 * A message is made of a header ( msg ) and 0 or more AVPs ( avp ). | |
64 * The structure is a kind of tree, where some AVPs (grouped AVPs) can contain other AVPs. | |
65 * Exemple: | |
66 * msg | |
67 * |-avp | |
68 * |-gavp | |
69 * | |-avp | |
70 * | |-avp | |
71 * | \-avp | |
72 * |-avp | |
73 * \-avp | |
74 * | |
75 * Each item (msg or avp) structure begins with a msg_avp_chain structure. | |
76 * The element at the top of the hierarchy (msg in our example) has all the fields of its "chaining" equal to the same value. | |
77 * | |
78 * All elements at the same level are linked by their "chaining" list. | |
79 * The "children" list is the sentinel for the lists of children of this element. | |
80 */ | |
81 | |
82 /* The following definitions are used to recognize objects in memory. */ | |
83 #define MSG_MSG_EYEC (0x11355463) | |
84 #define MSG_AVP_EYEC (0x11355467) | |
85 | |
86 /* The following structure represents an AVP instance. */ | |
87 struct avp { | |
88 struct msg_avp_chain avp_chain; /* Chaining information of this AVP */ | |
89 int avp_eyec; /* Must be equal to MSG_AVP_EYEC */ | |
90 struct dict_object *avp_model; /* If not NULL, pointer to the dictionary object of this avp */ | |
91 struct avp_hdr avp_public; /* AVP data that can be managed by other modules */ | |
92 | |
93 uint8_t *avp_source; /* If the message was parsed from a buffer, pointer to the AVP data start in the buffer. */ | |
94 uint8_t *avp_rawdata; /* when the data can not be interpreted, the raw data is copied here. The header is not part of it. */ | |
95 size_t avp_rawlen; /* The length of the raw buffer. */ | |
96 union avp_value avp_storage; /* To avoid many alloc/free, store the integer values here and set avp_public.avp_data to &storage */ | |
97 int avp_mustfreeos; /* 1 if an octetstring is malloc'd in avp_storage and must be freed. */ | |
98 }; | |
99 | |
100 /* Macro to compute the AVP header size */ | |
101 #define AVPHDRSZ_NOVEND 8 | |
102 #define AVPHDRSZ_VENDOR 12 | |
103 #define GETAVPHDRSZ( _flag ) ((_flag & AVP_FLAG_VENDOR) ? AVPHDRSZ_VENDOR : AVPHDRSZ_NOVEND) | |
104 | |
105 /* Macro to cast a msg_avp_t */ | |
106 #define _A(_x) ((struct avp *)(_x)) | |
107 /* Check the type and eyecatcher */ | |
108 #define CHECK_AVP(_x) ((_C(_x)->type == MSG_AVP) && (_A(_x)->avp_eyec == MSG_AVP_EYEC)) | |
109 | |
110 /* The following structure represents an instance of a message (command and children AVPs). */ | |
111 struct msg { | |
112 struct msg_avp_chain msg_chain; /* List of the AVPs in the message */ | |
113 int msg_eyec; /* Must be equal to MSG_MSG_EYEC */ | |
114 struct dict_object *msg_model; /* If not NULL, pointer to the dictionary object of this message */ | |
115 struct msg_hdr msg_public; /* Message data that can be managed by extensions. */ | |
116 | |
117 uint8_t *msg_rawbuffer; /* data buffer that was received, saved during fd_msg_parse_buffer and freed in fd_msg_parse_dict */ | |
118 int msg_routable; /* Is this a routable message? (0: undef, 1: routable, 2: non routable) */ | |
119 struct msg *msg_query; /* the associated query if the message is a received answer */ | |
83
c662d3eb6ff6
Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
120 struct rt_data *msg_rtdata; /* Routing list for the query */ |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
121 struct session *msg_sess; /* Cached message session if any */ |
0 | 122 struct { |
123 void (*fct)(void *, struct msg **); | |
124 void * data; | |
125 } msg_cb; /* Callback to be called when an answer is received, if not NULL */ | |
126 char * msg_src_id; /* Diameter Id of the peer this message was received from. This string is malloc'd and must be freed */ | |
127 }; | |
128 | |
129 /* Macro to compute the message header size */ | |
130 #define GETMSGHDRSZ() 20 | |
131 | |
132 /* Macro to cast a msg_avp_t */ | |
133 #define _M(_x) ((struct msg *)(_x)) | |
134 /* Check the type and eyecatcher */ | |
135 #define CHECK_MSG(_x) ((_C(_x)->type == MSG_MSG) && (_M(_x)->msg_eyec == MSG_MSG_EYEC)) | |
136 | |
137 #define VALIDATE_OBJ(_x) ( (CHECK_MSG(_x)) || (CHECK_AVP(_x)) ) | |
138 | |
139 | |
140 /* Macro to validate a MSGFL_ value */ | |
141 #define CHECK_MSGFL(_fl) ( ((_fl) & (- (MSGFL_MAX << 1) )) == 0 ) | |
142 | |
143 | |
144 /* initial sizes of AVP from their types, in bytes. */ | |
145 static int avp_value_sizes[] = { | |
146 0, /* AVP_TYPE_GROUPED: size is dynamic */ | |
147 0, /* AVP_TYPE_OCTETSTRING: size is dynamic */ | |
148 4, /* AVP_TYPE_INTEGER32: size is 32 bits */ | |
149 8, /* AVP_TYPE_INTEGER64: size is 64 bits */ | |
150 4, /* AVP_TYPE_UNSIGNED32: size is 32 bits */ | |
151 8, /* AVP_TYPE_UNSIGNED64: size is 64 bits */ | |
152 4, /* AVP_TYPE_FLOAT32: size is 32 bits */ | |
153 8 /* AVP_TYPE_FLOAT64: size is 64 bits */ | |
154 }; | |
155 #define CHECK_BASETYPE( _type ) ( ((_type) <= AVP_TYPE_MAX) && ((_type) >= 0) ) | |
156 #define GETINITIALSIZE( _type, _vend ) (avp_value_sizes[ CHECK_BASETYPE(_type) ? (_type) : 0] + GETAVPHDRSZ(_vend)) | |
157 | |
158 /* Forward declaration */ | |
159 static int parsedict_do_msg(struct dictionary * dict, struct msg * msg, int only_hdr); | |
160 | |
161 /***************************************************************************************************************/ | |
162 /* Creating objects */ | |
163 | |
164 /* Initialize a msg_avp_chain structure */ | |
165 static void init_chain(struct msg_avp_chain * chain, int type) | |
166 { | |
167 fd_list_init( &chain->chaining, (void *)chain); | |
168 fd_list_init( &chain->children, (void *)chain); | |
169 chain->type = type; | |
170 } | |
171 | |
172 /* Initialize a new AVP object */ | |
173 static void init_avp ( struct avp * avp ) | |
174 { | |
175 TRACE_ENTRY("%p", avp); | |
176 | |
177 memset(avp, 0, sizeof(struct avp)); | |
178 init_chain( &avp->avp_chain, MSG_AVP); | |
179 avp->avp_eyec = MSG_AVP_EYEC; | |
180 } | |
181 | |
182 /* Initialize a new MSG object */ | |
183 static void init_msg ( struct msg * msg ) | |
184 { | |
185 TRACE_ENTRY("%p", msg); | |
186 | |
187 memset(msg, 0, sizeof(struct msg)); | |
188 init_chain( &msg->msg_chain, MSG_MSG); | |
189 msg->msg_eyec = MSG_MSG_EYEC; | |
190 } | |
191 | |
192 | |
193 /* Create a new AVP instance */ | |
194 int fd_msg_avp_new ( struct dict_object * model, int flags, struct avp ** avp ) | |
195 { | |
196 struct avp *new = NULL; | |
197 | |
198 TRACE_ENTRY("%p %x %p", model, flags, avp); | |
199 | |
200 /* Check the parameters */ | |
201 CHECK_PARAMS( avp && CHECK_MSGFL(flags) ); | |
202 | |
203 if (model) { | |
204 enum dict_object_type dicttype; | |
205 CHECK_PARAMS( (fd_dict_gettype(model, &dicttype) == 0) && (dicttype == DICT_AVP) ); | |
206 } | |
207 | |
208 /* Create a new object */ | |
209 CHECK_MALLOC( new = malloc (sizeof(struct avp)) ); | |
210 | |
211 /* Initialize the fields */ | |
212 init_avp(new); | |
213 | |
214 if (model) { | |
215 struct dict_avp_data dictdata; | |
216 | |
217 CHECK_FCT( fd_dict_getval(model, &dictdata) ); | |
218 | |
219 new->avp_model = model; | |
220 new->avp_public.avp_code = dictdata.avp_code; | |
221 new->avp_public.avp_flags = dictdata.avp_flag_val; | |
222 new->avp_public.avp_len = GETINITIALSIZE(dictdata.avp_basetype, dictdata.avp_flag_val ); | |
223 new->avp_public.avp_vendor = dictdata.avp_vendor; | |
224 } | |
225 | |
226 /* The new object is ready, return */ | |
227 *avp = new; | |
228 return 0; | |
229 } | |
230 | |
231 /* Create a new message instance */ | |
232 int fd_msg_new ( struct dict_object * model, int flags, struct msg ** msg ) | |
233 { | |
234 struct msg * new = NULL; | |
235 | |
236 TRACE_ENTRY("%p %x %p", model, flags, msg); | |
237 | |
238 /* Check the parameters */ | |
239 CHECK_PARAMS( msg && CHECK_MSGFL(flags) ); | |
240 | |
241 if (model) { | |
242 enum dict_object_type dicttype; | |
243 CHECK_PARAMS( (fd_dict_gettype(model, &dicttype) == 0) && (dicttype == DICT_COMMAND) ); | |
244 } | |
245 | |
246 /* Create a new object */ | |
247 CHECK_MALLOC( new = malloc (sizeof(struct msg)) ); | |
248 | |
249 /* Initialize the fields */ | |
250 init_msg(new); | |
251 new->msg_public.msg_version = DIAMETER_VERSION; | |
252 new->msg_public.msg_length = GETMSGHDRSZ(); /* This will be updated later */ | |
253 | |
254 if (model) { | |
255 struct dictionary *dict; | |
256 struct dict_cmd_data dictdata; | |
257 struct dict_object *dictappl; | |
258 | |
259 CHECK_FCT( fd_dict_getdict(model, &dict) ); | |
260 CHECK_FCT( fd_dict_getval(model, &dictdata) ); | |
261 | |
262 new->msg_model = model; | |
263 new->msg_public.msg_flags = dictdata.cmd_flag_val; | |
264 new->msg_public.msg_code = dictdata.cmd_code; | |
265 | |
266 /* Initialize application from the parent, if any */ | |
267 CHECK_FCT( fd_dict_search( dict, DICT_APPLICATION, APPLICATION_OF_COMMAND, model, &dictappl, 0) ); | |
268 if (dictappl != NULL) { | |
269 struct dict_application_data appdata; | |
270 CHECK_FCT( fd_dict_getval(dictappl, &appdata) ); | |
271 new->msg_public.msg_appl = appdata.application_id; | |
272 } | |
273 } | |
274 | |
275 if (flags & MSGFL_ALLOC_ETEID) { | |
276 new->msg_public.msg_eteid = fd_msg_eteid_get(); | |
277 } | |
278 | |
279 /* The new object is ready, return */ | |
280 *msg = new; | |
281 return 0; | |
282 } | |
283 | |
284 /* Create answer from a request */ | |
285 int fd_msg_new_answer_from_req ( struct dictionary * dict, struct msg ** msg, int flags ) | |
286 { | |
287 struct dict_object * model = NULL; | |
288 struct msg *qry, *ans; | |
289 | |
290 TRACE_ENTRY("%p %x", msg, flags); | |
291 | |
292 /* Check the parameters */ | |
293 CHECK_PARAMS( msg ); | |
294 qry = *msg; | |
295 CHECK_PARAMS( CHECK_MSG(qry) && (qry->msg_public.msg_flags & CMD_FLAG_REQUEST) ); | |
296 | |
297 /* Find the model for the answer */ | |
298 if (flags & MSGFL_ANSW_ERROR) { | |
299 /* The model is the generic error format */ | |
300 CHECK_FCT( fd_dict_get_error_cmd(dict, &model) ); | |
301 } else { | |
302 /* The model is the answer corresponding to the query. It supposes that these are defined in the dictionary */ | |
303 CHECK_FCT_DO( parsedict_do_msg( dict, qry, 1), /* continue */ ); | |
304 if (qry->msg_model) { | |
305 CHECK_FCT( fd_dict_search ( dict, DICT_COMMAND, CMD_ANSWER, qry->msg_model, &model, EINVAL ) ); | |
306 } | |
307 } | |
308 | |
309 /* Create the answer */ | |
310 CHECK_FCT( fd_msg_new( model, flags, &ans ) ); | |
311 | |
312 /* Set informations in the answer as in the query */ | |
313 ans->msg_public.msg_code = qry->msg_public.msg_code; /* useful for MSGFL_ANSW_ERROR */ | |
314 ans->msg_public.msg_appl = qry->msg_public.msg_appl; | |
315 ans->msg_public.msg_eteid = qry->msg_public.msg_eteid; | |
316 ans->msg_public.msg_hbhid = qry->msg_public.msg_hbhid; | |
317 | |
318 /* associate with query */ | |
319 /* may do CHECK_FCT( msg_answ_associate( *msg, (msg_t *)qry ) ); but this is quicker */ | |
320 ans->msg_query = qry; | |
321 | |
322 /* Done */ | |
323 *msg = ans; | |
324 return 0; | |
325 } | |
326 | |
327 /***************************************************************************************************************/ | |
328 | |
329 /* Explore a message */ | |
330 int fd_msg_browse_internal ( msg_or_avp * reference, enum msg_brw_dir dir, msg_or_avp ** found, int * depth ) | |
331 { | |
332 struct msg_avp_chain *result = NULL; | |
333 int diff = 0; | |
334 struct fd_list *li = NULL; | |
335 | |
336 TRACE_ENTRY("%p %d %p %p", reference, dir, found, depth); | |
337 | |
338 /* Initialize the "found" result if any */ | |
339 if (found) | |
340 *found = NULL; | |
341 | |
342 /* Check the parameters */ | |
343 CHECK_PARAMS( VALIDATE_OBJ(reference) ); | |
344 | |
345 TRACE_DEBUG(FCTS, "chaining(%p): nxt:%p prv:%p hea:%p top:%p", | |
346 &_C(reference)->chaining, | |
347 _C(reference)->chaining.next, | |
348 _C(reference)->chaining.prev, | |
349 _C(reference)->chaining.head, | |
350 _C(reference)->chaining.o); | |
351 TRACE_DEBUG(FCTS, "children(%p): nxt:%p prv:%p hea:%p top:%p", | |
352 &_C(reference)->children, | |
353 _C(reference)->children.next, | |
354 _C(reference)->children.prev, | |
355 _C(reference)->children.head, | |
356 _C(reference)->children.o); | |
357 | |
358 /* Now search */ | |
359 switch (dir) { | |
360 case MSG_BRW_NEXT: | |
361 /* Check the reference is an AVP */ | |
362 CHECK_PARAMS( _C(reference)->type == MSG_AVP ); | |
363 | |
364 li = &_C(reference)->chaining; | |
365 | |
366 /* Check if the next element is not the sentinel ( ==> the parent) */ | |
367 if (li->next != li->head) | |
368 result = _C(li->next->o); | |
369 break; | |
370 | |
371 case MSG_BRW_PREV: | |
372 /* Check the reference is an AVP */ | |
373 CHECK_PARAMS( _C(reference)->type == MSG_AVP ); | |
374 | |
375 li = &_C(reference)->chaining; | |
376 | |
377 /* Check if the prev element is not the sentinel ( ==> the parent) */ | |
378 if (li->prev != li->head) | |
379 result = _C(li->prev->o); | |
380 break; | |
381 | |
382 case MSG_BRW_FIRST_CHILD: | |
383 li = &_C(reference)->children; | |
384 if (! FD_IS_LIST_EMPTY(li)) { | |
385 result = _C(li->next->o); | |
386 diff = 1; | |
387 } | |
388 break; | |
389 | |
390 case MSG_BRW_LAST_CHILD: | |
391 li = &_C(reference)->children; | |
392 if (! FD_IS_LIST_EMPTY(li)) { | |
393 result = _C(li->prev->o); | |
394 diff = 1; | |
395 } | |
396 break; | |
397 | |
398 case MSG_BRW_PARENT: | |
399 /* If the object is not chained, it has no parent */ | |
400 li = &_C(reference)->chaining; | |
401 if (li != li->head) { | |
402 /* The sentinel is the parent's children list */ | |
403 result = _C(li->head->o); | |
404 diff = -1; | |
405 } | |
406 break; | |
407 | |
408 case MSG_BRW_WALK: | |
409 /* First, try to find a child */ | |
410 li = &_C(reference)->children; | |
411 if ( ! FD_IS_LIST_EMPTY(li) ) { | |
412 result = _C(li->next->o); | |
413 diff = 1; | |
414 break; | |
415 } | |
416 | |
417 /* Then try to find a "next" at this level or one of the parent's */ | |
418 li = &_C(reference)->chaining; | |
419 do { | |
420 /* If this element has a "next" element, return it */ | |
421 if (li->next != li->head) { | |
422 result = _C(li->next->o); | |
423 break; | |
424 } | |
425 /* otherwise, check if we have a parent */ | |
426 if (li == li->head) { | |
427 /* no parent */ | |
428 break; | |
429 } | |
430 /* Go to the parent's chaining information and loop */ | |
431 diff -= 1; | |
432 li = &_C(li->head->o)->chaining; | |
433 } while (1); | |
434 break; | |
435 | |
436 default: | |
437 /* Other directions are invalid */ | |
438 CHECK_PARAMS( dir = 0 ); | |
439 } | |
440 | |
441 /* Save the found object, if any */ | |
442 if (found && result) | |
443 *found = (void *)result; | |
444 | |
445 /* Modify the depth according to the walk direction */ | |
446 if (depth && diff) | |
447 (*depth) += diff; | |
448 | |
449 /* Return ENOENT if found was NULL */ | |
450 if ((!found) && (!result)) | |
451 return ENOENT; | |
452 else | |
453 return 0; | |
454 } | |
455 | |
456 /* Add an AVP into a tree */ | |
457 int fd_msg_avp_add ( msg_or_avp * reference, enum msg_brw_dir dir, struct avp *avp) | |
458 { | |
459 TRACE_ENTRY("%p %d %p", reference, dir, avp); | |
460 | |
461 /* Check the parameters */ | |
462 CHECK_PARAMS( VALIDATE_OBJ(reference) && CHECK_AVP(avp) && FD_IS_LIST_EMPTY(&avp->avp_chain.chaining) ); | |
463 | |
464 /* Now insert */ | |
465 switch (dir) { | |
466 case MSG_BRW_NEXT: | |
467 /* Check the reference is an AVP -- we do not chain AVPs at same level as msgs. */ | |
468 CHECK_PARAMS( _C(reference)->type == MSG_AVP ); | |
469 | |
470 /* Insert the new avp after the reference */ | |
471 fd_list_insert_after( &_A(reference)->avp_chain.chaining, &avp->avp_chain.chaining ); | |
472 break; | |
473 | |
474 case MSG_BRW_PREV: | |
475 /* Check the reference is an AVP */ | |
476 CHECK_PARAMS( _C(reference)->type == MSG_AVP ); | |
477 | |
478 /* Insert the new avp before the reference */ | |
479 fd_list_insert_before( &_A(reference)->avp_chain.chaining, &avp->avp_chain.chaining ); | |
480 break; | |
481 | |
482 case MSG_BRW_FIRST_CHILD: | |
483 /* Insert the new avp after the children sentinel */ | |
484 fd_list_insert_after( &_C(reference)->children, &avp->avp_chain.chaining ); | |
485 break; | |
486 | |
487 case MSG_BRW_LAST_CHILD: | |
488 /* Insert the new avp before the children sentinel */ | |
489 fd_list_insert_before( &_C(reference)->children, &avp->avp_chain.chaining ); | |
490 break; | |
491 | |
492 default: | |
493 /* Other directions are invalid */ | |
494 CHECK_PARAMS( dir = 0 ); | |
495 } | |
496 | |
497 return 0; | |
498 } | |
499 | |
500 /* Search a given AVP model in a message */ | |
501 int fd_msg_search_avp ( struct msg * msg, struct dict_object * what, struct avp ** avp ) | |
502 { | |
503 struct avp * nextavp; | |
504 struct dict_avp_data dictdata; | |
505 enum dict_object_type dicttype; | |
506 | |
507 TRACE_ENTRY("%p %p %p", msg, what, avp); | |
508 | |
509 CHECK_PARAMS( CHECK_MSG(msg) && what ); | |
510 | |
511 CHECK_PARAMS( (fd_dict_gettype(what, &dicttype) == 0) && (dicttype == DICT_AVP) ); | |
512 CHECK_FCT( fd_dict_getval(what, &dictdata) ); | |
513 | |
514 /* Loop on all top AVPs */ | |
515 CHECK_FCT( fd_msg_browse(msg, MSG_BRW_FIRST_CHILD, (void *)&nextavp, NULL) ); | |
516 while (nextavp) { | |
517 | |
518 if ( (nextavp->avp_public.avp_code == dictdata.avp_code) | |
519 && (nextavp->avp_public.avp_vendor == dictdata.avp_vendor) ) /* always 0 if no V flag */ | |
520 break; | |
521 | |
522 /* Otherwise move to next AVP in the message */ | |
523 CHECK_FCT( fd_msg_browse(nextavp, MSG_BRW_NEXT, (void *)&nextavp, NULL) ); | |
524 } | |
525 | |
526 if (avp) | |
527 *avp = nextavp; | |
528 | |
529 if (avp && nextavp) { | |
530 struct dictionary * dict; | |
531 CHECK_FCT( fd_dict_getdict( what, &dict) ); | |
532 CHECK_FCT_DO( fd_msg_parse_dict( nextavp, dict ), /* nothing */ ); | |
533 } | |
534 | |
535 if (avp || nextavp) | |
536 return 0; | |
537 else | |
538 return ENOENT; | |
539 } | |
540 | |
541 | |
542 /***************************************************************************************************************/ | |
543 /* Deleting objects */ | |
544 | |
545 /* Destroy and free an AVP or message */ | |
546 static int destroy_obj (struct msg_avp_chain * obj ) | |
547 { | |
548 TRACE_ENTRY("%p", obj); | |
549 | |
550 /* Check the parameter is a valid object */ | |
551 CHECK_PARAMS( VALIDATE_OBJ(obj) && FD_IS_LIST_EMPTY( &obj->children ) ); | |
552 | |
553 /* Unlink this object if needed */ | |
554 fd_list_unlink( &obj->chaining ); | |
555 | |
556 /* Free the octetstring if needed */ | |
557 if ((obj->type == MSG_AVP) && (_A(obj)->avp_mustfreeos == 1)) { | |
558 free(_A(obj)->avp_storage.os.data); | |
559 } | |
560 /* Free the rawdata if needed */ | |
561 if ((obj->type == MSG_AVP) && (_A(obj)->avp_rawdata != NULL)) { | |
562 free(_A(obj)->avp_rawdata); | |
563 } | |
564 if ((obj->type == MSG_MSG) && (_M(obj)->msg_rawbuffer != NULL)) { | |
565 free(_M(obj)->msg_rawbuffer); | |
566 } | |
567 | |
568 if ((obj->type == MSG_MSG) && (_M(obj)->msg_src_id != NULL)) { | |
569 free(_M(obj)->msg_src_id); | |
570 } | |
571 | |
83
c662d3eb6ff6
Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
572 if ((obj->type == MSG_MSG) && (_M(obj)->msg_rtdata != NULL)) { |
c662d3eb6ff6
Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
573 fd_rtd_free(&_M(obj)->msg_rtdata); |
0 | 574 } |
575 | |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
576 if ((obj->type == MSG_MSG) && (_M(obj)->msg_sess != NULL)) { |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
577 CHECK_FCT_DO( fd_sess_reclaim_msg ( &_M(obj)->msg_sess ), /* continue */); |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
578 } |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
579 |
0 | 580 /* free the object */ |
581 free(obj); | |
582 | |
583 return 0; | |
584 } | |
585 | |
586 /* Destroy an object and all its children */ | |
587 static void destroy_tree(struct msg_avp_chain * obj) | |
588 { | |
589 struct fd_list *rem; | |
590 | |
591 TRACE_ENTRY("%p", obj); | |
592 | |
593 /* Destroy any subtree */ | |
594 while ( (rem = obj->children.next) != &obj->children) | |
595 destroy_tree(_C(rem->o)); | |
596 | |
597 /* Then unlink and destroy the object */ | |
598 CHECK_FCT_DO( destroy_obj(obj), /* nothing */ ); | |
599 } | |
600 | |
601 /* Free an object and its tree */ | |
602 int fd_msg_free ( msg_or_avp * object ) | |
603 { | |
604 TRACE_ENTRY("%p", object); | |
605 | |
606 if (CHECK_MSG(object)) { | |
607 if (_M(object)->msg_query) { | |
608 CHECK_FCT( fd_msg_free( _M(object)->msg_query ) ); | |
609 _M(object)->msg_query = NULL; | |
610 } | |
611 } | |
612 | |
613 destroy_tree(_C(object)); | |
614 return 0; | |
615 } | |
616 | |
617 | |
618 /***************************************************************************************************************/ | |
619 /* Debug functions: dumping */ | |
620 | |
621 /* indent inside an object */ | |
622 #define INOBJHDR "%*s " | |
623 #define INOBJHDRVAL indent<0 ? 1 : indent, indent<0 ? "-" : "|" | |
624 | |
625 /* Dump a msg_t object */ | |
626 static void obj_dump_msg (struct msg * msg, int indent ) | |
627 { | |
628 int ret = 0; | |
629 | |
630 fd_log_debug("%*sMSG: %p\n", INOBJHDRVAL, msg); | |
631 | |
632 if (!CHECK_MSG(msg)) { | |
633 fd_log_debug(INOBJHDR "INVALID!\n", INOBJHDRVAL); | |
634 return; | |
635 } | |
636 | |
637 if (!msg->msg_model) { | |
638 | |
639 fd_log_debug(INOBJHDR "(no model)\n", INOBJHDRVAL); | |
640 | |
641 } else { | |
642 | |
643 enum dict_object_type dicttype; | |
644 struct dict_cmd_data dictdata; | |
645 ret = fd_dict_gettype(msg->msg_model, &dicttype); | |
646 if (ret || (dicttype != DICT_COMMAND)) { | |
647 fd_log_debug(INOBJHDR "(invalid model: %d %d)\n", INOBJHDRVAL, ret, dicttype); | |
648 goto public; | |
649 } | |
650 ret = fd_dict_getval(msg->msg_model, &dictdata); | |
651 if (ret != 0) { | |
652 fd_log_debug(INOBJHDR "(error getting model data: %s)\n", INOBJHDRVAL, strerror(ret)); | |
653 goto public; | |
654 } | |
655 fd_log_debug(INOBJHDR "model : v/m:" DUMP_CMDFL_str "/" DUMP_CMDFL_str ", %u \"%s\"\n", INOBJHDRVAL, | |
656 DUMP_CMDFL_val(dictdata.cmd_flag_val), DUMP_CMDFL_val(dictdata.cmd_flag_mask), dictdata.cmd_code, dictdata.cmd_name); | |
657 } | |
658 public: | |
659 fd_log_debug(INOBJHDR "public: V:%d L:%d fl:" DUMP_CMDFL_str " CC:%u A:%d hi:%x ei:%x\n", INOBJHDRVAL, | |
660 msg->msg_public.msg_version, | |
661 msg->msg_public.msg_length, | |
662 DUMP_CMDFL_val(msg->msg_public.msg_flags), | |
663 msg->msg_public.msg_code, | |
664 msg->msg_public.msg_appl, | |
665 msg->msg_public.msg_hbhid, | |
666 msg->msg_public.msg_eteid | |
667 ); | |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
668 fd_log_debug(INOBJHDR "intern: rwb:%p rt:%d cb:%p(%p) qry:%p sess:%p src:%s\n", |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
669 INOBJHDRVAL, msg->msg_rawbuffer, msg->msg_routable, msg->msg_cb.fct, msg->msg_cb.data, msg->msg_query, msg->msg_sess, msg->msg_src_id?:"(nil)"); |
0 | 670 } |
671 | |
672 #define DUMP_VALUE(_format, _parms...) fd_log_debug(INOBJHDR "value : t:'%s' v:'" _format "'\n", INOBJHDRVAL, typename, ## _parms); | |
673 /* Dump an AVP value that is not a constant */ | |
674 static void dump_basic_type(union avp_value * value, enum dict_avp_basetype type, const char * typename, int indent) | |
675 { | |
676 switch (type) { | |
677 case AVP_TYPE_GROUPED: | |
678 DUMP_VALUE("%s", "error: grouped AVP with a value!"); | |
679 break; | |
680 | |
681 case AVP_TYPE_OCTETSTRING: | |
682 { | |
683 /* Dump only up to 16 bytes of the buffer */ | |
684 unsigned char buf[8]; | |
685 memset(buf, 0, sizeof(buf)); | |
686 memcpy(buf, value->os.data, value->os.len < sizeof(buf) ? value->os.len : sizeof(buf) ); | |
4
883311bf7df3
Simplified a few strings
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
687 DUMP_VALUE("l:%d, v:%02.2X %02.2X %02.2X %02.2X %02.2X %02.2X %02.2X %02.2X ... ('%.*s')", |
0 | 688 value->os.len, |
689 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], | |
4
883311bf7df3
Simplified a few strings
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
690 value->os.len, value->os.data |
0 | 691 ); |
692 } | |
693 break; | |
694 | |
695 case AVP_TYPE_INTEGER32: | |
696 DUMP_VALUE("%i",value->i32); | |
697 break; | |
698 | |
699 case AVP_TYPE_INTEGER64: | |
700 DUMP_VALUE("%lli (0x%llx)",value->i64,value->i64); | |
701 break; | |
702 | |
703 case AVP_TYPE_UNSIGNED32: | |
704 DUMP_VALUE("%u",value->u32); | |
705 break; | |
706 | |
707 case AVP_TYPE_UNSIGNED64: | |
708 DUMP_VALUE("%llu",value->u64); | |
709 break; | |
710 | |
711 case AVP_TYPE_FLOAT32: | |
712 DUMP_VALUE("%f",value->f32); | |
713 break; | |
714 | |
715 case AVP_TYPE_FLOAT64: | |
716 DUMP_VALUE("%g",value->f64); | |
717 break; | |
718 | |
719 default: | |
720 DUMP_VALUE("%s %d", "error: invalid type :", type); | |
721 } | |
722 } | |
723 | |
724 /* Dump an AVP value that is a constant */ | |
725 #define DUMP_CONST(_format, _parms...) fd_log_debug(INOBJHDR "value : t:'%s' v:'%s' ( " _format " )\n", INOBJHDRVAL, typename, value->enum_name, ## _parms); | |
726 static void dump_constant_type(struct dict_enumval_data * value, enum dict_avp_basetype type, char * typename, int indent) | |
727 { | |
728 switch (type) { | |
729 case AVP_TYPE_GROUPED: | |
730 DUMP_CONST("%s", "error: grouped AVP with a constant value!"); | |
731 break; | |
732 case AVP_TYPE_OCTETSTRING: | |
733 DUMP_CONST("%s", "value skipped"); | |
734 break; | |
735 | |
736 case AVP_TYPE_INTEGER32: | |
737 DUMP_CONST("%i",value->enum_value.i32); | |
738 break; | |
739 | |
740 case AVP_TYPE_INTEGER64: | |
741 DUMP_CONST("%li",value->enum_value.i64); | |
742 break; | |
743 | |
744 case AVP_TYPE_UNSIGNED32: | |
745 DUMP_CONST("%u",value->enum_value.u32); | |
746 break; | |
747 | |
748 case AVP_TYPE_UNSIGNED64: | |
749 DUMP_CONST("%lu",value->enum_value.u64); | |
750 break; | |
751 | |
752 case AVP_TYPE_FLOAT32: | |
753 DUMP_CONST("%f",value->enum_value.f32); | |
754 break; | |
755 | |
756 case AVP_TYPE_FLOAT64: | |
757 DUMP_CONST("%g",value->enum_value.f64); | |
758 break; | |
759 | |
760 default: | |
761 DUMP_CONST("%s %d", "error: invalid type :", type); | |
762 } | |
763 } | |
764 | |
765 /* Dump an avp object */ | |
766 static void obj_dump_avp ( struct avp * avp, int indent ) | |
767 { | |
768 int ret = 0; | |
769 enum dict_avp_basetype type = -1; | |
770 | |
771 if (!CHECK_AVP(avp)) { | |
772 fd_log_debug(INOBJHDR "INVALID!\n", INOBJHDRVAL); | |
773 return; | |
774 } | |
775 | |
776 if (!avp->avp_model) { | |
777 | |
778 fd_log_debug(INOBJHDR "(no model)\n", INOBJHDRVAL); | |
779 | |
780 } else { | |
781 | |
782 enum dict_object_type dicttype; | |
783 struct dict_avp_data dictdata; | |
784 ret = fd_dict_gettype(avp->avp_model, &dicttype); | |
785 if (ret || (dicttype != DICT_AVP)) { | |
786 fd_log_debug(INOBJHDR "(invalid model: %d %d)\n", INOBJHDRVAL, ret, dicttype); | |
787 goto public; | |
788 } | |
789 ret = fd_dict_getval(avp->avp_model, &dictdata); | |
790 if (ret != 0) { | |
791 fd_log_debug(INOBJHDR "(error getting model data: %s)\n", INOBJHDRVAL, strerror(ret)); | |
792 goto public; | |
793 } | |
794 fd_log_debug(INOBJHDR "model : v/m:" DUMP_AVPFL_str "/" DUMP_AVPFL_str ", %12s, %u \"%s\"\n", INOBJHDRVAL, | |
795 DUMP_AVPFL_val(dictdata.avp_flag_val), | |
796 DUMP_AVPFL_val(dictdata.avp_flag_mask), | |
797 type_base_name[dictdata.avp_basetype], | |
798 dictdata.avp_code, | |
799 dictdata.avp_name ); | |
800 type = dictdata.avp_basetype; | |
801 } | |
802 public: | |
803 fd_log_debug(INOBJHDR "public: C:%u fl:" DUMP_AVPFL_str " L:%d V:%u data:@%p\n", INOBJHDRVAL, | |
804 avp->avp_public.avp_code, | |
805 DUMP_AVPFL_val(avp->avp_public.avp_flags), | |
806 avp->avp_public.avp_len, | |
807 avp->avp_public.avp_vendor, | |
808 avp->avp_public.avp_value | |
809 ); | |
810 /* Dump the value if set */ | |
811 if (avp->avp_public.avp_value) { | |
812 if (!avp->avp_model) { | |
813 fd_log_debug(INOBJHDR "(data set but no model: ERROR)\n", INOBJHDRVAL); | |
814 } else { | |
815 /* Try and find a constant name for this value */ | |
816 struct dictionary * dict = NULL; | |
817 struct dict_object * avp_type = NULL; | |
818 struct dict_object * avp_constant = NULL; | |
819 struct dict_type_data type_data; | |
820 struct dict_enumval_request request; | |
821 ret = fd_dict_getdict(avp->avp_model, & dict); | |
822 if (ret != 0) { | |
823 dump_basic_type(avp->avp_public.avp_value, type, type_base_name[type], indent); | |
824 goto end; | |
825 } | |
826 ret = fd_dict_search(dict, DICT_TYPE, TYPE_OF_AVP, avp->avp_model, &avp_type, ENOENT); | |
827 if (ret != 0) { | |
828 dump_basic_type(avp->avp_public.avp_value, type, type_base_name[type], indent); | |
829 goto end; | |
830 } | |
831 ret = fd_dict_getval(avp_type, &type_data); | |
832 if (ret != 0) { | |
833 dump_basic_type(avp->avp_public.avp_value, type, "(error getting type data)", indent); | |
834 goto end; | |
835 } | |
836 if (type_data.type_base != type) { | |
837 dump_basic_type(avp->avp_public.avp_value, type, "(mismatching type information!)", indent); | |
838 goto end; | |
839 } | |
840 /* Create a query for a constant */ | |
841 memset(&request, 0, sizeof(request)); | |
842 request.type_obj = avp_type; | |
843 memcpy(&request.search.enum_value, avp->avp_public.avp_value, sizeof(union avp_value)); | |
844 ret = fd_dict_search(dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &request, &avp_constant, ENOENT); | |
845 if (ret != 0) { | |
846 dump_basic_type(avp->avp_public.avp_value, type, type_data.type_name, indent); | |
847 goto end; | |
848 } | |
849 /* get the constant's information; we re-use request.search field */ | |
850 ret = fd_dict_getval(avp_constant, &request.search); | |
851 if (ret != 0) { | |
852 dump_basic_type(avp->avp_public.avp_value, type, "(error getting constant data)", indent); | |
853 goto end; | |
854 } | |
855 dump_constant_type(&request.search, type, type_data.type_name, indent); | |
856 } | |
857 } | |
858 end: | |
859 fd_log_debug(INOBJHDR "intern: src:%p mf:%d raw:%p(%d)\n", INOBJHDRVAL, avp->avp_source, avp->avp_mustfreeos, avp->avp_rawdata, avp->avp_rawlen); | |
860 } | |
861 | |
862 /* Dump a single object content */ | |
863 static void msg_dump_intern ( int level, msg_or_avp * obj, int indent ) | |
864 { | |
865 /* Log only if we are at least at level */ | |
866 if ( ! TRACE_BOOL(level) ) | |
867 return; | |
868 | |
869 /* Check the object */ | |
870 if (!VALIDATE_OBJ(obj)) { | |
871 fd_log_debug( ">>> invalid object (%p)!.\n", obj); | |
872 return; | |
873 } | |
874 | |
875 /* Dump the object */ | |
876 switch (_C(obj)->type) { | |
877 case MSG_AVP: | |
878 obj_dump_avp ( _A(obj), indent ); | |
879 break; | |
880 | |
881 case MSG_MSG: | |
882 obj_dump_msg ( _M(obj), indent ); | |
883 break; | |
884 | |
885 default: | |
886 ASSERT(0); | |
887 } | |
888 } | |
889 | |
890 /* Dump a message content -- for debug mostly */ | |
891 void fd_msg_dump_walk ( int level, msg_or_avp *obj ) | |
892 { | |
893 msg_or_avp * ref = obj; | |
894 int indent = 1; | |
895 | |
896 TRACE_DEBUG(level, "------ Dumping object %p (w)-------", obj); | |
897 do { | |
898 msg_dump_intern ( level, ref, indent ); | |
899 | |
900 /* Now find the next object */ | |
901 CHECK_FCT_DO( fd_msg_browse ( ref, MSG_BRW_WALK, &ref, &indent ), break ); | |
902 | |
903 /* dump next object */ | |
904 } while (ref); | |
905 | |
906 TRACE_DEBUG(level, "------ /end of object %p -------", obj); | |
907 } | |
908 | |
909 /* Dump a single object content -- for debug mostly */ | |
910 void fd_msg_dump_one ( int level, msg_or_avp * obj ) | |
911 { | |
912 TRACE_DEBUG(level, "------ Dumping object %p (s)-------", obj); | |
913 msg_dump_intern ( level, obj, 1 ); | |
914 TRACE_DEBUG(level, "------ /end of object %p -------", obj); | |
915 } | |
916 | |
917 | |
918 /***************************************************************************************************************/ | |
919 /* Simple meta-data management */ | |
920 | |
921 /* Retrieve the model of an object */ | |
922 int fd_msg_model ( msg_or_avp * reference, struct dict_object ** model ) | |
923 { | |
924 TRACE_ENTRY("%p %p", reference, model); | |
925 | |
926 /* Check the parameters */ | |
927 CHECK_PARAMS( model && VALIDATE_OBJ(reference) ); | |
928 | |
929 /* copy the model reference */ | |
930 switch (_C(reference)->type) { | |
931 case MSG_AVP: | |
932 *model = _A(reference)->avp_model; | |
933 break; | |
934 | |
935 case MSG_MSG: | |
936 *model = _M(reference)->msg_model; | |
937 break; | |
938 | |
939 default: | |
940 CHECK_PARAMS(0); | |
941 } | |
942 | |
943 return 0; | |
944 } | |
945 | |
946 /* Retrieve the address of the msg_public field of a message */ | |
947 int fd_msg_hdr ( struct msg *msg, struct msg_hdr **pdata ) | |
948 { | |
949 TRACE_ENTRY("%p %p", msg, pdata); | |
950 CHECK_PARAMS( CHECK_MSG(msg) && pdata ); | |
951 | |
952 *pdata = &msg->msg_public; | |
953 return 0; | |
954 } | |
955 | |
956 /* Retrieve the address of the avp_public field of an avp */ | |
957 int fd_msg_avp_hdr ( struct avp *avp, struct avp_hdr **pdata ) | |
958 { | |
959 TRACE_ENTRY("%p %p", avp, pdata); | |
960 CHECK_PARAMS( CHECK_AVP(avp) && pdata ); | |
961 | |
962 *pdata = &avp->avp_public; | |
963 return 0; | |
964 } | |
965 | |
966 /* Associate answers and queries */ | |
967 int fd_msg_answ_associate( struct msg * answer, struct msg * query ) | |
968 { | |
969 TRACE_ENTRY( "%p %p", answer, query ); | |
970 | |
971 CHECK_PARAMS( CHECK_MSG(answer) && CHECK_MSG(query) && (answer->msg_query == NULL ) ); | |
972 | |
973 answer->msg_query = query; | |
974 | |
975 return 0; | |
976 } | |
977 | |
978 int fd_msg_answ_getq( struct msg * answer, struct msg ** query ) | |
979 { | |
980 TRACE_ENTRY( "%p %p", answer, query ); | |
981 | |
982 CHECK_PARAMS( CHECK_MSG(answer) && query ); | |
983 | |
984 *query = answer->msg_query; | |
985 | |
986 return 0; | |
987 } | |
988 | |
989 int fd_msg_answ_detach( struct msg * answer ) | |
990 { | |
991 TRACE_ENTRY( "%p", answer ); | |
992 | |
993 CHECK_PARAMS( CHECK_MSG(answer) ); | |
994 | |
995 answer->msg_query = NULL; | |
996 | |
997 return 0; | |
998 } | |
999 | |
1000 /* Associate / get answer callbacks */ | |
1001 int fd_msg_anscb_associate( struct msg * msg, void ( *anscb)(void *, struct msg **), void * data ) | |
1002 { | |
1003 TRACE_ENTRY("%p %p %p", msg, anscb, data); | |
1004 | |
1005 /* Check the parameters */ | |
1006 CHECK_PARAMS( CHECK_MSG(msg) && anscb ); | |
100 | 1007 CHECK_PARAMS( msg->msg_public.msg_flags & CMD_FLAG_REQUEST ); /* we associate with requests only */ |
0 | 1008 CHECK_PARAMS( msg->msg_cb.fct == NULL ); /* No cb is already registered */ |
1009 | |
1010 /* Associate callback and data with the message, if any */ | |
1011 msg->msg_cb.fct = anscb; | |
1012 msg->msg_cb.data = data; | |
1013 | |
1014 return 0; | |
1015 } | |
1016 | |
1017 int fd_msg_anscb_get( struct msg * msg, void (**anscb)(void *, struct msg **), void ** data ) | |
1018 { | |
1019 TRACE_ENTRY("%p %p %p", msg, anscb, data); | |
1020 | |
1021 /* Check the parameters */ | |
1022 CHECK_PARAMS( CHECK_MSG(msg) && anscb && data ); | |
1023 | |
1024 /* Copy the result */ | |
1025 *anscb = msg->msg_cb.fct; | |
1026 *data = msg->msg_cb.data; | |
1027 | |
1028 return 0; | |
1029 } | |
1030 | |
1031 /* Associate routing lists */ | |
83
c662d3eb6ff6
Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
1032 int fd_msg_rt_associate( struct msg * msg, struct rt_data ** rtd ) |
0 | 1033 { |
83
c662d3eb6ff6
Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
1034 TRACE_ENTRY( "%p %p", msg, rtd ); |
0 | 1035 |
83
c662d3eb6ff6
Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
1036 CHECK_PARAMS( CHECK_MSG(msg) && rtd ); |
0 | 1037 |
83
c662d3eb6ff6
Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
1038 msg->msg_rtdata = *rtd; |
c662d3eb6ff6
Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
1039 *rtd = NULL; |
0 | 1040 |
1041 return 0; | |
1042 } | |
1043 | |
83
c662d3eb6ff6
Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
1044 int fd_msg_rt_get( struct msg * msg, struct rt_data ** rtd ) |
0 | 1045 { |
83
c662d3eb6ff6
Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
1046 TRACE_ENTRY( "%p %p", msg, rtd ); |
0 | 1047 |
83
c662d3eb6ff6
Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
1048 CHECK_PARAMS( CHECK_MSG(msg) && rtd ); |
0 | 1049 |
83
c662d3eb6ff6
Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
1050 *rtd = msg->msg_rtdata; |
c662d3eb6ff6
Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
37
diff
changeset
|
1051 msg->msg_rtdata = NULL; |
0 | 1052 |
1053 return 0; | |
1054 } | |
1055 | |
1056 /* Find if a message is routable */ | |
1057 int fd_msg_is_routable ( struct msg * msg ) | |
1058 { | |
1059 TRACE_ENTRY("%p", msg); | |
1060 | |
1061 CHECK_PARAMS_DO( CHECK_MSG(msg), return 0 /* pretend the message is not routable */ ); | |
1062 | |
1063 if ( ! msg->msg_routable ) { | |
37
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
35
diff
changeset
|
1064 /* To define if a message is routable, we rely on the "PXY" flag (for application 0). */ |
cc3c59fe98fe
Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
35
diff
changeset
|
1065 msg->msg_routable = ((msg->msg_public.msg_appl != 0) || (msg->msg_public.msg_flags & CMD_FLAG_PROXIABLE)) ? 1 : 2; |
0 | 1066 |
1067 /* Note : the 'real' criteria according to the Diameter I-D is that the message is | |
1068 routable if and only if the "Destination-Realm" AVP is required by the command ABNF. | |
1069 We could make a test for this here, but it's more computational work and our test | |
1070 seems accurate (until proven otherwise...) */ | |
1071 } | |
1072 | |
1073 return (msg->msg_routable == 1) ? 1 : 0; | |
1074 } | |
1075 | |
1076 /* Associate source peer */ | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1077 int fd_msg_source_set( struct msg * msg, char * diamid, int add_rr, struct dictionary * dict ) |
0 | 1078 { |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1079 TRACE_ENTRY( "%p %p %d %p", msg, diamid, add_rr, dict); |
0 | 1080 |
1081 /* Check we received a valid message */ | |
1082 CHECK_PARAMS( CHECK_MSG(msg) && dict ); | |
1083 | |
1084 /* Cleanup any previous source */ | |
1085 free(msg->msg_src_id); msg->msg_src_id = NULL; | |
1086 | |
1087 /* If the request is to cleanup the source, we are done */ | |
1088 if (diamid == NULL) { | |
1089 return 0; | |
1090 } | |
1091 | |
1092 /* Otherwise save the new informations */ | |
1093 CHECK_MALLOC( msg->msg_src_id = strdup(diamid) ); | |
1094 | |
1095 if (add_rr) { | |
1096 struct dict_object *avp_rr_model; | |
1097 avp_code_t code = AC_ROUTE_RECORD; | |
1098 struct avp *avp; | |
1099 union avp_value val; | |
1100 | |
1101 /* Find the model for Route-Record in the dictionary */ | |
1102 CHECK_FCT( fd_dict_search ( dict, DICT_AVP, AVP_BY_CODE, &code, &avp_rr_model, ENOENT) ); | |
1103 | |
1104 /* Create the AVP with this model */ | |
1105 CHECK_FCT( fd_msg_avp_new ( avp_rr_model, 0, &avp ) ); | |
1106 | |
1107 /* Set the AVP value with the diameter id */ | |
1108 memset(&val, 0, sizeof(val)); | |
1109 val.os.data = (unsigned char *)diamid; | |
1110 val.os.len = strlen(diamid); | |
1111 CHECK_FCT( fd_msg_avp_setvalue( avp, &val ) ); | |
1112 | |
1113 /* Add the AVP in the message */ | |
1114 CHECK_FCT( fd_msg_avp_add( msg, MSG_BRW_LAST_CHILD, avp ) ); | |
1115 } | |
1116 | |
1117 /* done */ | |
1118 return 0; | |
1119 } | |
1120 | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1121 int fd_msg_source_get( struct msg * msg, char ** diamid ) |
0 | 1122 { |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1123 TRACE_ENTRY( "%p %p", msg, diamid); |
0 | 1124 |
1125 /* Check we received valid parameters */ | |
1126 CHECK_PARAMS( CHECK_MSG(msg) ); | |
1127 CHECK_PARAMS( diamid ); | |
1128 | |
1129 /* Copy the informations */ | |
1130 *diamid = msg->msg_src_id; | |
1131 | |
1132 /* done */ | |
1133 return 0; | |
1134 } | |
1135 | |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1136 /* Retrieve the session of the message */ |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1137 int fd_msg_sess_get(struct dictionary * dict, struct msg * msg, struct session ** session, int * new) |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1138 { |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1139 struct avp * avp; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1140 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1141 TRACE_ENTRY("%p %p %p", msg, session, new); |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1142 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1143 /* Check we received valid parameters */ |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1144 CHECK_PARAMS( CHECK_MSG(msg) ); |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1145 CHECK_PARAMS( session ); |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1146 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1147 /* If we already resolved the session, just send it back */ |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1148 if (msg->msg_sess) { |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1149 *session = msg->msg_sess; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1150 if (new) |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1151 *new = 0; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1152 return 0; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1153 } |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1154 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1155 /* OK, we have to search for Session-Id AVP -- it is usually the first AVP, but let's be permissive here */ |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1156 /* -- note: we accept messages that have not yet been dictionary parsed... */ |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1157 CHECK_FCT( fd_msg_browse(msg, MSG_BRW_FIRST_CHILD, &avp, NULL) ); |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1158 while (avp) { |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1159 if ( (avp->avp_public.avp_code == AC_SESSION_ID) |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1160 && (avp->avp_public.avp_vendor == 0) ) |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1161 break; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1162 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1163 /* Otherwise move to next AVP in the message */ |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1164 CHECK_FCT( fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL) ); |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1165 } |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1166 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1167 if (!avp) { |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1168 TRACE_DEBUG(FULL, "No Session-Id AVP found in message %p", msg); |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1169 *session = NULL; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1170 return 0; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1171 } |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1172 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1173 if (!avp->avp_model) { |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1174 CHECK_FCT( fd_msg_parse_dict ( avp, dict ) ); |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1175 } |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1176 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1177 ASSERT( avp->avp_public.avp_value ); |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1178 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1179 /* Resolve the session and we are done */ |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1180 CHECK_FCT( fd_sess_fromsid_msg ( avp->avp_public.avp_value->os.data, avp->avp_public.avp_value->os.len, &msg->msg_sess, new) ); |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1181 *session = msg->msg_sess; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1182 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1183 return 0; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1184 } |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1185 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
83
diff
changeset
|
1186 |
0 | 1187 /******************* End-to-end counter *********************/ |
1188 uint32_t fd_eteid; | |
1189 pthread_mutex_t fd_eteid_lck = PTHREAD_MUTEX_INITIALIZER; | |
1190 | |
1191 void fd_msg_eteid_init(void) | |
1192 { | |
1193 fd_eteid = ((uint32_t)time(NULL) << 20) | ((uint32_t)lrand48() & ( (1 << 20) - 1 )); | |
1194 } | |
1195 | |
1196 uint32_t fd_msg_eteid_get ( void ) | |
1197 { | |
1198 uint32_t ret; | |
1199 | |
1200 CHECK_POSIX_DO( pthread_mutex_lock(&fd_eteid_lck), /* continue */ ); | |
1201 | |
1202 ret = fd_eteid ++; | |
1203 | |
1204 CHECK_POSIX_DO( pthread_mutex_unlock(&fd_eteid_lck), /* continue */ ); | |
1205 | |
1206 return ret; | |
1207 } | |
1208 | |
1209 /***************************************************************************************************************/ | |
1210 /* Manage AVPs values */ | |
1211 | |
1212 /* Set the value of an AVP */ | |
1213 int fd_msg_avp_setvalue ( struct avp *avp, union avp_value *value ) | |
1214 { | |
1215 enum dict_avp_basetype type = -1; | |
1216 | |
1217 TRACE_ENTRY("%p %p", avp, value); | |
1218 | |
1219 /* Check parameter */ | |
1220 CHECK_PARAMS( CHECK_AVP(avp) && avp->avp_model ); | |
1221 | |
1222 /* Retrieve information from the AVP model */ | |
1223 { | |
1224 enum dict_object_type dicttype; | |
1225 struct dict_avp_data dictdata; | |
1226 | |
1227 CHECK_PARAMS( (fd_dict_gettype(avp->avp_model, &dicttype) == 0) && (dicttype == DICT_AVP) ); | |
1228 CHECK_FCT( fd_dict_getval(avp->avp_model, &dictdata) ); | |
1229 type = dictdata.avp_basetype; | |
1230 CHECK_PARAMS( type != AVP_TYPE_GROUPED ); | |
1231 } | |
1232 | |
1233 /* First, clean any previous value */ | |
1234 if (avp->avp_mustfreeos != 0) { | |
1235 free(avp->avp_storage.os.data); | |
1236 avp->avp_mustfreeos = 0; | |
1237 } | |
1238 | |
1239 memset(&avp->avp_storage, 0, sizeof(union avp_value)); | |
1240 | |
1241 /* If the request was to delete a value: */ | |
1242 if (!value) { | |
1243 avp->avp_public.avp_value = NULL; | |
1244 return 0; | |
1245 } | |
1246 | |
1247 /* Now we have to set the value */ | |
1248 memcpy(&avp->avp_storage, value, sizeof(union avp_value)); | |
1249 | |
1250 /* Copy an octetstring if needed. */ | |
1251 if (type == AVP_TYPE_OCTETSTRING) { | |
1252 CHECK_MALLOC( avp->avp_storage.os.data = malloc(value->os.len) ); | |
1253 avp->avp_mustfreeos = 1; | |
1254 memcpy(avp->avp_storage.os.data, value->os.data, value->os.len); | |
1255 } | |
1256 | |
1257 /* Set the data pointer of the public part */ | |
1258 avp->avp_public.avp_value = &avp->avp_storage; | |
1259 | |
1260 return 0; | |
1261 } | |
1262 | |
1263 /* Set the value of an AVP, using formatted data */ | |
1264 int fd_msg_avp_value_encode ( void *data, struct avp *avp ) | |
1265 { | |
1266 enum dict_avp_basetype type = -1; | |
1267 struct dict_type_data type_data; | |
1268 | |
1269 TRACE_ENTRY("%p %p", data, avp); | |
1270 | |
1271 /* Check parameter */ | |
1272 CHECK_PARAMS( CHECK_AVP(avp) && avp->avp_model ); | |
1273 | |
1274 /* Retrieve information from the AVP model and it's parent type */ | |
1275 { | |
1276 enum dict_object_type dicttype; | |
1277 struct dict_avp_data dictdata; | |
1278 struct dictionary * dict; | |
1279 struct dict_object * parenttype = NULL; | |
1280 | |
1281 /* First check the base type of the AVP */ | |
1282 CHECK_PARAMS( (fd_dict_gettype(avp->avp_model, &dicttype) == 0) && (dicttype == DICT_AVP) ); | |
1283 CHECK_FCT( fd_dict_getval(avp->avp_model, &dictdata) ); | |
1284 type = dictdata.avp_basetype; | |
1285 CHECK_PARAMS( type != AVP_TYPE_GROUPED ); | |
1286 | |
1287 /* Then retrieve information about the parent's type (= derived type) */ | |
1288 CHECK_FCT( fd_dict_getdict( avp->avp_model, &dict ) ); | |
1289 CHECK_FCT( fd_dict_search( dict, DICT_TYPE, TYPE_OF_AVP, avp->avp_model, &parenttype, EINVAL) ); | |
1290 CHECK_FCT( fd_dict_getval(parenttype, &type_data) ); | |
1291 if (type_data.type_encode == NULL) { | |
1292 TRACE_DEBUG(INFO, "This AVP type does not provide a callback to encode formatted data. ENOTSUP."); | |
1293 return ENOTSUP; | |
1294 } | |
1295 } | |
1296 | |
1297 /* Ok, now we can encode the value */ | |
1298 | |
1299 /* First, clean any previous value */ | |
1300 if (avp->avp_mustfreeos != 0) { | |
1301 free(avp->avp_storage.os.data); | |
1302 avp->avp_mustfreeos = 0; | |
1303 } | |
1304 avp->avp_public.avp_value = NULL; | |
1305 memset(&avp->avp_storage, 0, sizeof(union avp_value)); | |
1306 | |
1307 /* Now call the type's callback to encode the data */ | |
1308 CHECK_FCT( (*type_data.type_encode)(data, &avp->avp_storage) ); | |
1309 | |
1310 /* If an octetstring has been allocated, let's mark it to be freed */ | |
1311 if (type == AVP_TYPE_OCTETSTRING) | |
1312 avp->avp_mustfreeos = 1; | |
1313 | |
1314 /* Set the data pointer of the public part */ | |
1315 avp->avp_public.avp_value = &avp->avp_storage; | |
1316 | |
1317 return 0; | |
1318 } | |
1319 | |
1320 /* Interpret the value of an AVP into formatted data */ | |
1321 int fd_msg_avp_value_interpret ( struct avp *avp, void *data ) | |
1322 { | |
1323 struct dict_type_data type_data; | |
1324 | |
1325 TRACE_ENTRY("%p %p", avp, data); | |
1326 | |
1327 /* Check parameter */ | |
1328 CHECK_PARAMS( CHECK_AVP(avp) && avp->avp_model && avp->avp_public.avp_value ); | |
1329 | |
1330 /* Retrieve information about the AVP parent type */ | |
1331 { | |
1332 struct dictionary * dict; | |
1333 struct dict_object * parenttype = NULL; | |
1334 | |
1335 CHECK_FCT( fd_dict_getdict( avp->avp_model, &dict ) ); | |
1336 CHECK_FCT( fd_dict_search( dict, DICT_TYPE, TYPE_OF_AVP, avp->avp_model, &parenttype, EINVAL) ); | |
1337 CHECK_FCT( fd_dict_getval(parenttype, &type_data) ); | |
1338 if (type_data.type_interpret == NULL) { | |
1339 TRACE_DEBUG(INFO, "This AVP type does not provide a callback to interpret value in formatted data. ENOTSUP."); | |
1340 return ENOTSUP; | |
1341 } | |
1342 } | |
1343 | |
1344 /* Ok, now we can interpret the value */ | |
1345 | |
1346 CHECK_FCT( (*type_data.type_interpret)(avp->avp_public.avp_value, data) ); | |
1347 | |
1348 return 0; | |
1349 } | |
1350 | |
1351 /***************************************************************************************************************/ | |
1352 /* Creating a buffer from memory objects (bufferize a struct msg) */ | |
1353 | |
1354 /* Following macros are used to store 32 and 64 bit fields into a buffer in network byte order */ | |
1355 #define PUT_in_buf_32( _u32data, _bufptr ) { \ | |
1356 *(uint32_t *)(_bufptr) = htonl((uint32_t)(_u32data)); \ | |
1357 } | |
1358 #define PUT_in_buf_64( _u64data, _bufptr ) { \ | |
1359 *(uint64_t *)(_bufptr) = htonll((uint64_t)(_u64data)); \ | |
1360 } | |
1361 | |
1362 /* Write a message header in the buffer */ | |
1363 static int bufferize_msg(unsigned char * buffer, size_t buflen, size_t * offset, struct msg * msg) | |
1364 { | |
1365 TRACE_ENTRY("%p %d %p %p", buffer, buflen, offset, msg); | |
1366 | |
1367 if ((buflen - *offset) < GETMSGHDRSZ()) | |
1368 return ENOSPC; | |
1369 | |
1370 if (*offset & 0x3) | |
1371 return EFAULT; /* We are supposed to start on 32 bit boundaries */ | |
1372 | |
1373 PUT_in_buf_32(msg->msg_public.msg_length, buffer + *offset); | |
1374 buffer[*offset] = msg->msg_public.msg_version; | |
1375 *offset += 4; | |
1376 | |
1377 PUT_in_buf_32(msg->msg_public.msg_code, buffer + *offset); | |
1378 buffer[*offset] = msg->msg_public.msg_flags; | |
1379 *offset += 4; | |
1380 | |
1381 PUT_in_buf_32(msg->msg_public.msg_appl, buffer + *offset); | |
1382 *offset += 4; | |
1383 | |
1384 PUT_in_buf_32(msg->msg_public.msg_hbhid, buffer + *offset); | |
1385 *offset += 4; | |
1386 | |
1387 PUT_in_buf_32(msg->msg_public.msg_eteid, buffer + *offset); | |
1388 *offset += 4; | |
1389 | |
1390 return 0; | |
1391 } | |
1392 | |
1393 static int bufferize_chain(unsigned char * buffer, size_t buflen, size_t * offset, struct fd_list * list); | |
1394 | |
1395 /* Write an AVP in the buffer */ | |
1396 static int bufferize_avp(unsigned char * buffer, size_t buflen, size_t * offset, struct avp * avp) | |
1397 { | |
1398 struct dict_avp_data dictdata; | |
1399 | |
1400 TRACE_ENTRY("%p %d %p %p", buffer, buflen, offset, avp); | |
1401 | |
1402 if ((buflen - *offset) < avp->avp_public.avp_len) | |
1403 return ENOSPC; | |
1404 | |
1405 /* Write the header */ | |
1406 PUT_in_buf_32(avp->avp_public.avp_code, buffer + *offset); | |
1407 *offset += 4; | |
1408 | |
1409 PUT_in_buf_32(avp->avp_public.avp_len, buffer + *offset); | |
1410 buffer[*offset] = avp->avp_public.avp_flags; | |
1411 *offset += 4; | |
1412 | |
1413 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) { | |
1414 PUT_in_buf_32(avp->avp_public.avp_vendor, buffer + *offset); | |
1415 *offset += 4; | |
1416 } | |
1417 | |
1418 /* Then we must write the AVP value */ | |
1419 | |
1420 if (avp->avp_model == NULL) { | |
1421 /* In the case where we don't know the type of AVP, just copy the raw data or source */ | |
1422 CHECK_PARAMS( avp->avp_source || avp->avp_rawdata ); | |
1423 | |
1424 if ( avp->avp_source != NULL ) { | |
1425 /* the message was not parsed completely */ | |
1426 size_t datalen = avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags); | |
1427 memcpy(&buffer[*offset], avp->avp_source, datalen); | |
1428 *offset += PAD4(datalen); | |
1429 } else { | |
1430 /* the content was stored in rawdata */ | |
1431 memcpy(&buffer[*offset], avp->avp_rawdata, avp->avp_rawlen); | |
1432 *offset += PAD4(avp->avp_rawlen); | |
1433 } | |
1434 | |
1435 } else { | |
1436 /* The AVP is defined in the dictionary */ | |
1437 CHECK_FCT( fd_dict_getval(avp->avp_model, &dictdata) ); | |
1438 | |
1439 CHECK_PARAMS( ( dictdata.avp_basetype == AVP_TYPE_GROUPED ) || avp->avp_public.avp_value ); | |
1440 | |
1441 switch (dictdata.avp_basetype) { | |
1442 case AVP_TYPE_GROUPED: | |
1443 return bufferize_chain(buffer, buflen, offset, &avp->avp_chain.children); | |
1444 | |
1445 case AVP_TYPE_OCTETSTRING: | |
1446 memcpy(&buffer[*offset], avp->avp_public.avp_value->os.data, avp->avp_public.avp_value->os.len); | |
1447 *offset += PAD4(avp->avp_public.avp_value->os.len); | |
1448 break; | |
1449 | |
1450 case AVP_TYPE_INTEGER32: | |
1451 PUT_in_buf_32(avp->avp_public.avp_value->i32, buffer + *offset); | |
1452 *offset += 4; | |
1453 break; | |
1454 | |
1455 case AVP_TYPE_INTEGER64: | |
1456 PUT_in_buf_64(avp->avp_public.avp_value->i64, buffer + *offset); | |
1457 *offset += 8; | |
1458 break; | |
1459 | |
1460 case AVP_TYPE_UNSIGNED32: | |
1461 PUT_in_buf_32(avp->avp_public.avp_value->u32, buffer + *offset); | |
1462 *offset += 4; | |
1463 break; | |
1464 | |
1465 case AVP_TYPE_UNSIGNED64: | |
1466 PUT_in_buf_64(avp->avp_public.avp_value->u64, buffer + *offset); | |
1467 *offset += 8; | |
1468 break; | |
1469 | |
1470 case AVP_TYPE_FLOAT32: | |
1471 /* We read the f32 as "u32" here to avoid casting to uint make decimals go away. | |
1472 The alternative would be something like "*(uint32_t *)(& f32)" but | |
1473 then the compiler complains about strict-aliasing rules. */ | |
1474 PUT_in_buf_32(avp->avp_public.avp_value->u32, buffer + *offset); | |
1475 *offset += 4; | |
1476 break; | |
1477 | |
1478 case AVP_TYPE_FLOAT64: | |
1479 /* Same remark as previously */ | |
1480 PUT_in_buf_64(avp->avp_public.avp_value->u64, buffer + *offset); | |
1481 *offset += 8; | |
1482 break; | |
1483 | |
1484 default: | |
1485 ASSERT(0); | |
1486 } | |
1487 } | |
1488 return 0; | |
1489 } | |
1490 | |
1491 /* Write a chain of AVPs in the buffer */ | |
1492 static int bufferize_chain(unsigned char * buffer, size_t buflen, size_t * offset, struct fd_list * list) | |
1493 { | |
1494 struct fd_list * avpch; | |
1495 | |
1496 TRACE_ENTRY("%p %d %p %p", buffer, buflen, offset, list); | |
1497 | |
1498 for (avpch = list->next; avpch != list; avpch = avpch->next) { | |
1499 /* Bufferize the AVP */ | |
1500 CHECK_FCT( bufferize_avp(buffer, buflen, offset, _A(avpch->o)) ); | |
1501 } | |
1502 return 0; | |
1503 } | |
1504 | |
1505 /* Create the message buffer, in network-byte order. We browse the tree twice, this could be probably improved if needed */ | |
1506 int fd_msg_bufferize ( struct msg * msg, unsigned char ** buffer, size_t * len ) | |
1507 { | |
1508 int ret = 0; | |
1509 unsigned char * buf = NULL; | |
1510 size_t offset = 0; | |
1511 | |
1512 TRACE_ENTRY("%p %p %p", msg, buffer, len); | |
1513 | |
1514 /* Check the parameters */ | |
1515 CHECK_PARAMS( buffer && CHECK_MSG(msg) ); | |
1516 | |
1517 /* Update the length. This also checks that all AVP have their values set */ | |
1518 CHECK_FCT( fd_msg_update_length(msg) ); | |
1519 | |
1520 /* Now allocate a buffer to store the message */ | |
1521 CHECK_MALLOC( buf = malloc(msg->msg_public.msg_length) ); | |
1522 | |
1523 /* Clear the memory, so that the padding is always 0 (should not matter) */ | |
1524 memset(buf, 0, msg->msg_public.msg_length); | |
1525 | |
1526 /* Write the message header in the buffer */ | |
1527 CHECK_FCT_DO( ret = bufferize_msg(buf, msg->msg_public.msg_length, &offset, msg), | |
1528 { | |
1529 free(buf); | |
1530 return ret; | |
1531 } ); | |
1532 | |
1533 /* Write the list of AVPs */ | |
1534 CHECK_FCT_DO( ret = bufferize_chain(buf, msg->msg_public.msg_length, &offset, &msg->msg_chain.children), | |
1535 { | |
1536 free(buf); | |
1537 return ret; | |
1538 } ); | |
1539 | |
1540 ASSERT(offset == msg->msg_public.msg_length); /* or the msg_update_length is buggy */ | |
1541 | |
1542 if (len) { | |
1543 *len = offset; | |
1544 } | |
1545 | |
1546 *buffer = buf; | |
1547 return 0; | |
1548 } | |
1549 | |
1550 | |
1551 /***************************************************************************************************************/ | |
1552 /* Parsing buffers and building AVP objects lists (not parsing the AVP values which requires dictionary knowledge) */ | |
1553 | |
1554 /* Parse a buffer containing a supposed list of AVPs */ | |
1555 static int parsebuf_list(unsigned char * buf, size_t buflen, struct fd_list * head) | |
1556 { | |
1557 size_t offset = 0; | |
1558 | |
1559 TRACE_ENTRY("%p %d %p", buf, buflen, head); | |
1560 | |
1561 while (offset < buflen) { | |
1562 struct avp * avp; | |
1563 | |
1564 if (buflen - offset <= AVPHDRSZ_NOVEND) { | |
1565 TRACE_DEBUG(INFO, "truncated buffer: remaining only %d bytes", buflen - offset); | |
1566 return EBADMSG; | |
1567 } | |
1568 | |
1569 /* Create a new AVP object */ | |
1570 CHECK_MALLOC( avp = malloc (sizeof(struct avp)) ); | |
1571 | |
1572 init_avp(avp); | |
1573 | |
1574 /* Initialize the header */ | |
1575 avp->avp_public.avp_code = ntohl(*(uint32_t *)(buf + offset)); | |
1576 avp->avp_public.avp_flags = buf[offset + 4]; | |
1577 avp->avp_public.avp_len = ((uint32_t)buf[offset+5]) << 16 | ((uint32_t)buf[offset+6]) << 8 | ((uint32_t)buf[offset+7]) ; | |
1578 | |
1579 offset += 8; | |
1580 | |
1581 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) { | |
1582 if (buflen - offset <= 4) { | |
1583 TRACE_DEBUG(INFO, "truncated buffer: remaining only %d bytes for vendor and data", buflen - offset); | |
1584 free(avp); | |
1585 return EBADMSG; | |
1586 } | |
1587 avp->avp_public.avp_vendor = ntohl(*(uint32_t *)(buf + offset)); | |
1588 offset += 4; | |
1589 } | |
1590 | |
1591 /* Check there is enough remaining data in the buffer */ | |
1592 if (buflen - offset < avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags)) { | |
1593 TRACE_DEBUG(INFO, "truncated buffer: remaining only %d bytes for data, and avp data size is %d", | |
1594 buflen - offset, | |
1595 avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags)); | |
1596 free(avp); | |
1597 return EBADMSG; | |
1598 } | |
1599 | |
1600 /* buf[offset] is now the beginning of the data */ | |
1601 avp->avp_source = &buf[offset]; | |
1602 | |
1603 /* Now eat the data and eventual padding */ | |
1604 offset += PAD4(avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags)); | |
1605 | |
1606 /* And insert this avp in the list, at the end */ | |
1607 fd_list_insert_before( head, &avp->avp_chain.chaining ); | |
1608 } | |
1609 | |
1610 return 0; | |
1611 } | |
1612 | |
1613 /* Create a message object from a buffer. Dictionary objects are not resolved, AVP contents are not interpreted, buffer is saved in msg */ | |
1614 int fd_msg_parse_buffer ( unsigned char ** buffer, size_t buflen, struct msg ** msg ) | |
1615 { | |
1616 struct msg * new = NULL; | |
1617 int ret = 0; | |
1618 uint32_t msglen = 0; | |
1619 unsigned char * buf; | |
1620 | |
1621 TRACE_ENTRY("%p %d %p", buffer, buflen, msg); | |
1622 | |
1623 CHECK_PARAMS( buffer && *buffer && msg && (buflen >= GETMSGHDRSZ()) ); | |
1624 buf = *buffer; | |
1625 *buffer = NULL; | |
1626 | |
1627 if ( buf[0] != DIAMETER_VERSION) { | |
1628 TRACE_DEBUG(INFO, "Invalid version in message: %d (supported: %d)", buf[0], DIAMETER_VERSION); | |
1629 free(buf); | |
1630 return EBADMSG; | |
1631 } | |
1632 | |
1633 msglen = ntohl(*(uint32_t *)buf) & 0x00ffffff; | |
1634 if ( buflen < msglen ) { | |
1635 TRACE_DEBUG(INFO, "Truncated message (%d / %d)", buflen, msglen ); | |
1636 free(buf); | |
1637 return EBADMSG; | |
1638 } | |
1639 | |
1640 /* Create a new object */ | |
1641 CHECK_MALLOC_DO( new = malloc (sizeof(struct msg)), { free(buf); return ENOMEM; } ); | |
1642 | |
1643 /* Initialize the fields */ | |
1644 init_msg(new); | |
1645 | |
1646 /* Now read from the buffer */ | |
1647 new->msg_public.msg_version = buf[0]; | |
1648 new->msg_public.msg_length = msglen; | |
1649 | |
1650 new->msg_public.msg_flags = buf[4]; | |
1651 new->msg_public.msg_code = ntohl(*(uint32_t *)(buf+4)) & 0x00ffffff; | |
1652 | |
1653 new->msg_public.msg_appl = ntohl(*(uint32_t *)(buf+8)); | |
1654 new->msg_public.msg_hbhid = ntohl(*(uint32_t *)(buf+12)); | |
1655 new->msg_public.msg_eteid = ntohl(*(uint32_t *)(buf+16)); | |
1656 | |
1657 new->msg_rawbuffer = buf; | |
1658 | |
1659 /* Parse the AVP list */ | |
1660 CHECK_FCT_DO( ret = parsebuf_list(buf + GETMSGHDRSZ(), buflen - GETMSGHDRSZ(), &new->msg_chain.children), { destroy_tree(_C(new)); return ret; } ); | |
1661 | |
1662 *msg = new; | |
1663 return 0; | |
1664 } | |
1665 | |
1666 | |
1667 /***************************************************************************************************************/ | |
1668 /* Parsing messages and AVP with dictionary information */ | |
1669 | |
1670 /* Resolve dictionary objects of the cmd and avp instances, from their headers. | |
1671 * When the model is found, the data is interpreted from the avp_source buffer and copied to avp_storage. | |
1672 * When the model is not found, the data is copied as rawdata and saved (in case we FW the message). | |
1673 * Therefore, after this function has been called, the source buffer can be freed. | |
1674 * For command, if the dictionary model is not found, an error is returned. | |
1675 */ | |
1676 | |
1677 static int parsedict_do_chain(struct dictionary * dict, struct fd_list * head, int mandatory); | |
1678 | |
1679 /* Process an AVP. If we are not in recheck, the avp_source must be set. */ | |
1680 static int parsedict_do_avp(struct dictionary * dict, struct avp * avp, int mandatory) | |
1681 { | |
1682 struct dict_avp_data dictdata; | |
1683 | |
1684 TRACE_ENTRY("%p %p %d", dict, avp, mandatory); | |
1685 | |
1686 /* First check we received an AVP as input */ | |
1687 CHECK_PARAMS( CHECK_AVP(avp) ); | |
1688 | |
1689 if (avp->avp_model != NULL) { | |
1690 /* the model has already been resolved. we do check it is still valid */ | |
1691 | |
1692 CHECK_FCT( fd_dict_getval(avp->avp_model, &dictdata) ); | |
1693 | |
1694 if ( avp->avp_public.avp_code == dictdata.avp_code ) { | |
1695 /* Ok then just process the children if any */ | |
1696 return parsedict_do_chain(dict, &avp->avp_chain.children, mandatory && (avp->avp_public.avp_flags & AVP_FLAG_MANDATORY)); | |
1697 } else { | |
1698 /* We just erase the old model */ | |
1699 avp->avp_model = NULL; | |
1700 } | |
1701 } | |
1702 | |
1703 /* Now try and resolve the model from the avp code and vendor */ | |
1704 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) { | |
1705 struct dict_avp_request avpreq; | |
1706 avpreq.avp_vendor = avp->avp_public.avp_vendor; | |
1707 avpreq.avp_code = avp->avp_public.avp_code; | |
1708 CHECK_FCT( fd_dict_search ( dict, DICT_AVP, AVP_BY_CODE_AND_VENDOR, &avpreq, &avp->avp_model, 0)); | |
1709 } else { | |
1710 /* no vendor */ | |
1711 CHECK_FCT( fd_dict_search ( dict, DICT_AVP, AVP_BY_CODE, &avp->avp_public.avp_code, &avp->avp_model, 0)); | |
1712 } | |
1713 | |
1714 /* First handle the case where we have not found this AVP in the dictionary */ | |
1715 if (!avp->avp_model) { | |
1716 | |
1717 if (mandatory && (avp->avp_public.avp_flags & AVP_FLAG_MANDATORY)) { | |
1718 TRACE_DEBUG(INFO, "Unsupported mandatory AVP found:"); | |
1719 msg_dump_intern(INFO, avp, 2); | |
1720 return ENOTSUP; | |
1721 } | |
1722 | |
1723 if (avp->avp_source) { | |
1724 /* we must copy the data from the source to the internal buffer area */ | |
1725 CHECK_PARAMS( !avp->avp_rawdata ); | |
1726 | |
1727 avp->avp_rawlen = avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags ); | |
1728 | |
1729 CHECK_MALLOC( avp->avp_rawdata = malloc(avp->avp_rawlen) ); | |
1730 | |
1731 memcpy(avp->avp_rawdata, avp->avp_source, avp->avp_rawlen); | |
1732 avp->avp_source = NULL; | |
1733 | |
1734 TRACE_DEBUG(FULL, "Unsupported optional AVP found, raw source data saved in avp_rawdata."); | |
1735 } | |
1736 | |
1737 return 0; | |
1738 } | |
1739 | |
1740 /* Ok we have resolved the object. Now we need to interpret its content. */ | |
1741 | |
1742 CHECK_FCT( fd_dict_getval(avp->avp_model, &dictdata) ); | |
1743 | |
1744 if (avp->avp_rawdata) { | |
1745 /* This happens if the dictionary object was defined after the first check */ | |
1746 avp->avp_source = avp->avp_rawdata; | |
1747 } | |
1748 | |
1749 /* A bit of sanity here... */ | |
1750 ASSERT(CHECK_BASETYPE(dictdata.avp_basetype)); | |
1751 | |
1752 /* Check the size is valid */ | |
1753 if ((avp_value_sizes[dictdata.avp_basetype] != 0) && | |
1754 (avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags ) != avp_value_sizes[dictdata.avp_basetype])) { | |
1755 TRACE_DEBUG(INFO, "The AVP size is not suitable for the type. EBADMSG."); | |
1756 return EBADMSG; | |
1757 } | |
1758 | |
1759 /* Now get the value inside */ | |
1760 switch (dictdata.avp_basetype) { | |
1761 case AVP_TYPE_GROUPED: | |
1762 /* This is a grouped AVP, so let's parse the list of AVPs inside */ | |
1763 CHECK_FCT( parsebuf_list(avp->avp_source, avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags ), &avp->avp_chain.children) ); | |
1764 | |
1765 return parsedict_do_chain(dict, &avp->avp_chain.children, mandatory && (avp->avp_public.avp_flags & AVP_FLAG_MANDATORY)); | |
1766 | |
1767 case AVP_TYPE_OCTETSTRING: | |
1768 /* We just have to copy the string into the storage area */ | |
1769 CHECK_PARAMS( avp->avp_public.avp_len > GETAVPHDRSZ( avp->avp_public.avp_flags ) ); | |
1770 avp->avp_storage.os.len = avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags ); | |
1771 CHECK_MALLOC( avp->avp_storage.os.data = malloc(avp->avp_storage.os.len) ); | |
1772 avp->avp_mustfreeos = 1; | |
1773 memcpy(avp->avp_storage.os.data, avp->avp_source, avp->avp_storage.os.len); | |
1774 break; | |
1775 | |
1776 case AVP_TYPE_INTEGER32: | |
1777 avp->avp_storage.i32 = (int32_t)ntohl(*(uint32_t *)avp->avp_source); | |
1778 break; | |
1779 | |
1780 case AVP_TYPE_INTEGER64: | |
1781 avp->avp_storage.i64 = (int64_t)ntohll(*(uint64_t *)avp->avp_source); | |
1782 break; | |
1783 | |
1784 case AVP_TYPE_UNSIGNED32: | |
1785 case AVP_TYPE_FLOAT32: /* For float, we must not cast, or the value is changed. Instead we use implicit cast by changing the member of the union */ | |
1786 avp->avp_storage.u32 = (uint32_t)ntohl(*(uint32_t *)avp->avp_source); | |
1787 break; | |
1788 | |
1789 case AVP_TYPE_UNSIGNED64: | |
1790 case AVP_TYPE_FLOAT64: /* same as 32 bits */ | |
1791 avp->avp_storage.u64 = (uint64_t)ntohll(*(uint64_t *)avp->avp_source); | |
1792 break; | |
1793 | |
1794 } | |
1795 | |
1796 /* The value is now set, so set the data pointer and return 0 */ | |
1797 avp->avp_public.avp_value = &avp->avp_storage; | |
1798 return 0; | |
1799 } | |
1800 | |
1801 /* Process a list of AVPs */ | |
1802 static int parsedict_do_chain(struct dictionary * dict, struct fd_list * head, int mandatory) | |
1803 { | |
1804 struct fd_list * avpch; | |
1805 | |
1806 TRACE_ENTRY("%p %p %d", dict, head, mandatory); | |
1807 | |
1808 /* Sanity check */ | |
1809 ASSERT ( head == head->head ); | |
1810 | |
1811 /* Now process the list */ | |
1812 for (avpch=head->next; avpch != head; avpch = avpch->next) { | |
1813 CHECK_FCT( parsedict_do_avp(dict, _A(avpch->o), mandatory) ); | |
1814 } | |
1815 | |
1816 /* Done */ | |
1817 return 0; | |
1818 } | |
1819 | |
1820 /* Process a msg header. */ | |
1821 static int parsedict_do_msg(struct dictionary * dict, struct msg * msg, int only_hdr) | |
1822 { | |
1823 int ret = 0; | |
1824 | |
1825 TRACE_ENTRY("%p %p %d", dict, msg, only_hdr); | |
1826 | |
1827 CHECK_PARAMS( CHECK_MSG(msg) ); | |
1828 | |
1829 /* Look for the model from the header */ | |
1830 CHECK_FCT( fd_dict_search ( dict, DICT_COMMAND, | |
1831 (msg->msg_public.msg_flags & CMD_FLAG_REQUEST) ? CMD_BY_CODE_R : CMD_BY_CODE_A, | |
1832 &msg->msg_public.msg_code, | |
1833 &msg->msg_model, ENOTSUP) ); | |
1834 | |
1835 if (!only_hdr) { | |
1836 /* Then process the children */ | |
1837 ret = parsedict_do_chain(dict, &msg->msg_chain.children, 1); | |
1838 | |
1839 /* Free the raw buffer if any */ | |
1840 if ((ret == 0) && (msg->msg_rawbuffer != NULL)) { | |
1841 free(msg->msg_rawbuffer); | |
1842 msg->msg_rawbuffer=NULL; | |
1843 } | |
1844 } | |
1845 | |
1846 return ret; | |
1847 } | |
1848 | |
1849 int fd_msg_parse_dict ( msg_or_avp * object, struct dictionary * dict ) | |
1850 { | |
1851 TRACE_ENTRY("%p %p", dict, object); | |
1852 | |
1853 CHECK_PARAMS( VALIDATE_OBJ(object) ); | |
1854 | |
1855 switch (_C(object)->type) { | |
1856 case MSG_MSG: | |
1857 return parsedict_do_msg(dict, _M(object), 0); | |
1858 | |
1859 case MSG_AVP: | |
1860 return parsedict_do_avp(dict, _A(object), 0); | |
1861 | |
1862 default: | |
1863 ASSERT(0); | |
1864 } | |
1865 return EINVAL; | |
1866 } | |
1867 | |
1868 /***************************************************************************************************************/ | |
1869 /* Parsing messages and AVP for rules (ABNF) compliance */ | |
1870 | |
1871 /* This function is used to get stats (first occurence position, last occurence position, number of occurences) | |
1872 of AVP instances of a given model in a chain of AVP */ | |
1873 static void parserules_stat_avps( struct dict_object * model_avp, struct fd_list *list, int * count, int * firstpos, int * lastpos) | |
1874 { | |
1875 struct fd_list * li; | |
1876 int curpos = 0; /* The current position in the list */ | |
1877 | |
1878 TRACE_ENTRY("%p %p %p %p %p", model_avp, list, count, firstpos, lastpos); | |
1879 | |
1880 *count = 0; /* number of instances found */ | |
1881 *firstpos = 0; /* position of the first instance */ | |
1882 *lastpos = 0; /* position of the last instance, starting from the end */ | |
1883 | |
1884 for (li = list->next; li != list; li = li->next) { | |
1885 /* Increment the current position counter */ | |
1886 curpos++; | |
1887 | |
1888 /* If we previously saved a "lastpos" information, increment it */ | |
1889 if (*lastpos != 0) | |
1890 (*lastpos)++; | |
1891 | |
1892 /* Check the type of the next AVP. We can compare the references directly, it is safe. */ | |
1893 if (_A(li->o)->avp_model == model_avp) { | |
1894 | |
1895 /* This AVP is of the type we are searching */ | |
1896 (*count)++; | |
1897 | |
1898 /* If we don't have yet a "firstpos", save it */ | |
1899 if (*firstpos == 0) | |
1900 *firstpos = curpos; | |
1901 | |
1902 /* Reset the lastpos */ | |
1903 (*lastpos) = 1; | |
1904 } | |
1905 } | |
1906 } | |
1907 | |
1908 /* We use this structure as parameter for the next function */ | |
1909 struct parserules_data { | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1910 struct fd_list * sentinel; /* Sentinel of the list of children AVP */ |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1911 struct fd_pei * pei; /* If the rule conflicts, save the error here */ |
0 | 1912 }; |
1913 | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1914 /* Create an empty AVP of a given model (to use in Failed-AVP) */ |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1915 static struct avp * empty_avp(struct dict_object * model_avp) |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1916 { |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1917 struct avp * avp = NULL; |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1918 struct dict_avp_data avp_info; |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1919 union avp_value val; |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1920 char os[1] = { '\0' }; |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1921 |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1922 /* Create an instance */ |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1923 CHECK_FCT_DO( fd_msg_avp_new(model_avp, 0, &avp ), return NULL ); |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1924 |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1925 /* Type of the AVP */ |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1926 CHECK_FCT_DO( fd_dict_getval(model_avp, &avp_info), return NULL ); |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1927 |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1928 /* Prepare the empty value */ |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1929 memset(&val, 0, sizeof(val)); |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1930 switch (avp_info.avp_basetype) { |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1931 case AVP_TYPE_OCTETSTRING: |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1932 val.os.data = os; |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1933 val.os.len = sizeof(os); |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1934 case AVP_TYPE_INTEGER32: |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1935 case AVP_TYPE_INTEGER64: |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1936 case AVP_TYPE_UNSIGNED32: |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1937 case AVP_TYPE_UNSIGNED64: |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1938 case AVP_TYPE_FLOAT32: |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1939 case AVP_TYPE_FLOAT64: |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1940 CHECK_FCT_DO( fd_msg_avp_setvalue(avp, &val), return NULL ); |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1941 /* For AVP_TYPE_GROUPED we don't do anything */ |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1942 } |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1943 |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
1944 return avp; |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1945 } |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1946 |
0 | 1947 /* Check that a list of AVPs is compliant with a given rule -- will be iterated on the list of rules */ |
1948 static int parserules_check_one_rule(void * data, struct dict_rule_data *rule) | |
1949 { | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1950 int count, first, last, min; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1951 struct parserules_data * pr_data = data; |
0 | 1952 |
1953 TRACE_ENTRY("%p %p", data, rule); | |
1954 | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1955 /* Get statistics of the AVP concerned by this rule in the parent instance */ |
0 | 1956 parserules_stat_avps( rule->rule_avp, pr_data->sentinel, &count, &first, &last); |
1957 | |
1958 if (TRACE_BOOL(ANNOYING)) | |
1959 { | |
1960 struct dict_avp_data avpdata; | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1961 int ret; |
0 | 1962 ret = fd_dict_getval(rule->rule_avp, &avpdata); |
1963 | |
1964 TRACE_DEBUG(ANNOYING, "Checking rule: p:%d(%d) m/M:%2d/%2d. Counted %d (first: %d, last:%d) of AVP '%s'", | |
1965 rule->rule_position, | |
1966 rule->rule_order, | |
1967 rule->rule_min, | |
1968 rule->rule_max, | |
1969 count, | |
1970 first, | |
1971 last, | |
1972 (ret == 0) ? avpdata.avp_name : "???" | |
1973 ); | |
1974 } | |
1975 | |
1976 /* Now check the rule is not conflicting */ | |
1977 | |
1978 /* Check the "min" value */ | |
1979 if ((min = rule->rule_min) == -1) { | |
1980 if (rule->rule_position == RULE_OPTIONAL) | |
1981 min = 0; | |
1982 else | |
1983 min = 1; | |
1984 } | |
1985 if (count < min) { | |
1986 TRACE_DEBUG(INFO, "Conflicting rule: the number of occurences (%d) is < the rule min (%d).", count, min); | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1987 if (pr_data->pei) { |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1988 pr_data->pei->pei_errcode = "DIAMETER_MISSING_AVP"; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1989 pr_data->pei->pei_avp = empty_avp(rule->rule_avp); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1990 } |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1991 return EBADMSG; |
0 | 1992 } |
1993 | |
1994 /* Check the "max" value */ | |
1995 if ((rule->rule_max != -1) && (count > rule->rule_max)) { | |
1996 TRACE_DEBUG(INFO, "Conflicting rule: the number of occurences (%d) is > the rule max (%d).", count, rule->rule_max); | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1997 if (pr_data->pei) { |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1998 if (rule->rule_max == 0) |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
1999 pr_data->pei->pei_errcode = "DIAMETER_AVP_NOT_ALLOWED"; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2000 else |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2001 pr_data->pei->pei_errcode = "DIAMETER_AVP_OCCURS_TOO_MANY_TIMES"; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2002 pr_data->pei->pei_avp = empty_avp(rule->rule_avp); /* Well we are supposed to return the (max + 1)th instance of the AVP instead... Pfff... */ TODO("Improve..."); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2003 } |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2004 return EBADMSG; |
0 | 2005 } |
2006 | |
2007 /* Check the position and order (if relevant) */ | |
2008 switch (rule->rule_position) { | |
2009 case RULE_OPTIONAL: | |
2010 case RULE_REQUIRED: | |
2011 /* No special position constraints */ | |
2012 break; | |
2013 | |
2014 case RULE_FIXED_HEAD: | |
2015 /* Since "0*1<fixed>" is a valid rule specifier, we only reject cases where the AVP appears *after* its fixed position */ | |
2016 if (first > rule->rule_order) { | |
2017 TRACE_DEBUG(INFO, "Conflicting rule: the FIXED_HEAD AVP appears first in (%d) position, the rule requires (%d).", first, rule->rule_order); | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2018 if (pr_data->pei) { |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2019 pr_data->pei->pei_errcode = "DIAMETER_MISSING_AVP"; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2020 pr_data->pei->pei_message = "AVP was not in its fixed position"; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2021 pr_data->pei->pei_avp = empty_avp(rule->rule_avp); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2022 } |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2023 return EBADMSG; |
0 | 2024 } |
2025 break; | |
2026 | |
2027 case RULE_FIXED_TAIL: | |
2028 /* Since "0*1<fixed>" is a valid rule specifier, we only reject cases where the AVP appears *before* its fixed position */ | |
2029 if (last > rule->rule_order) { /* We have a ">" here because we count in reverse order (i.e. from the end) */ | |
2030 TRACE_DEBUG(INFO, "Conflicting rule: the FIXED_TAIL AVP appears last in (%d) position, the rule requires (%d).", last, rule->rule_order); | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2031 if (pr_data->pei) { |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2032 pr_data->pei->pei_errcode = "DIAMETER_MISSING_AVP"; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2033 pr_data->pei->pei_message = "AVP was not in its fixed position"; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2034 pr_data->pei->pei_avp = empty_avp(rule->rule_avp); |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2035 } |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2036 return EBADMSG; |
0 | 2037 } |
2038 break; | |
2039 | |
2040 default: | |
2041 /* What is this position ??? */ | |
2042 ASSERT(0); | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2043 return ENOTSUP; |
0 | 2044 } |
2045 | |
2046 /* We've checked all the parameters */ | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2047 return 0; |
0 | 2048 } |
2049 | |
2050 /* Check the rules recursively */ | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2051 static int parserules_do ( struct dictionary * dict, msg_or_avp * object, struct fd_pei *error_info, int mandatory) |
0 | 2052 { |
2053 struct parserules_data data; | |
2054 struct dict_object * model = NULL; | |
2055 | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2056 TRACE_ENTRY("%p %p %p %d", dict, object, error_info, mandatory); |
0 | 2057 |
2058 /* object has already been checked and dict-parsed when we are called. */ | |
2059 | |
2060 /* First, handle the cases where there is no model */ | |
2061 { | |
2062 if (CHECK_MSG(object)) { | |
2063 if ( _M(object)->msg_public.msg_flags & CMD_FLAG_ERROR ) { | |
2064 /* The case of error messages: the ABNF is different */ | |
2065 CHECK_FCT( fd_dict_get_error_cmd(dict, &model) ); | |
2066 } else { | |
2067 model = _M(object)->msg_model; | |
2068 } | |
2069 /* Commands MUST be supported in the dictionary */ | |
2070 if (model == NULL) { | |
2071 TRACE_DEBUG(INFO, "Message with no dictionary model. EBADMSG"); | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2072 if (error_info) { |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2073 error_info->pei_errcode = "DIAMETER_COMMAND_UNSUPPORTED"; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2074 error_info->pei_protoerr = 1; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2075 } |
0 | 2076 return EBADMSG; |
2077 } | |
2078 } | |
2079 | |
2080 /* AVP with the 'M' flag must also be recognized in the dictionary -- except inside an optional grouped AVP */ | |
2081 if (CHECK_AVP(object) && ((model = _A(object)->avp_model) == NULL)) { | |
2082 if ( mandatory && (_A(object)->avp_public.avp_flags & AVP_FLAG_MANDATORY)) { | |
2083 /* Return an error in this case */ | |
2084 TRACE_DEBUG(INFO, "Mandatory AVP with no dictionary model. EBADMSG"); | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2085 if (error_info) { |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2086 error_info->pei_errcode = "DIAMETER_AVP_UNSUPPORTED"; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2087 error_info->pei_avp = object; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2088 } |
0 | 2089 return EBADMSG; |
2090 } else { | |
2091 /* We don't know any rule for this object, so assume OK */ | |
2092 TRACE_DEBUG(FULL, "Unknown informational AVP, ignoring..."); | |
2093 return 0; | |
2094 } | |
2095 } | |
2096 } | |
2097 | |
2098 /* At this point we know "model" is set and points to the object's model */ | |
2099 | |
2100 /* If we are an AVP with no children, just return OK */ | |
2101 if (CHECK_AVP(object)) { | |
2102 struct dict_avp_data dictdata; | |
2103 CHECK_FCT( fd_dict_getval(model, &dictdata) ); | |
2104 if (dictdata.avp_basetype != AVP_TYPE_GROUPED) { | |
2105 /* This object has no children and no rules */ | |
2106 return 0; | |
2107 } | |
2108 } | |
2109 | |
2110 /* If this object has children, first check the rules for all its children */ | |
2111 { | |
2112 int is_child_mand = 0; | |
2113 struct fd_list * ch = NULL; | |
2114 if ( CHECK_MSG(object) | |
2115 || (mandatory && (_A(object)->avp_public.avp_flags & AVP_FLAG_MANDATORY)) ) | |
2116 is_child_mand = 1; | |
2117 for (ch = _C(object)->children.next; ch != &_C(object)->children; ch = ch->next) { | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2118 CHECK_FCT( parserules_do ( dict, _C(ch->o), error_info, is_child_mand ) ); |
0 | 2119 } |
2120 } | |
2121 | |
2122 /* Now check all rules of this object */ | |
2123 data.sentinel = &_C(object)->children; | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2124 data.pei = error_info; |
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2125 CHECK_FCT( fd_dict_iterate_rules ( model, &data, parserules_check_one_rule ) ); |
0 | 2126 |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2127 return 0; |
0 | 2128 } |
2129 | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2130 int fd_msg_parse_rules ( msg_or_avp * object, struct dictionary * dict, struct fd_pei *error_info) |
0 | 2131 { |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2132 TRACE_ENTRY("%p %p %p", object, dict, error_info); |
0 | 2133 |
35
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
2134 if (error_info) |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
2135 memset(error_info, 0, sizeof(struct fd_pei)); |
6486e97f56ae
Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
34
diff
changeset
|
2136 |
0 | 2137 /* Resolve the dictionary objects when missing. This also validates the object. */ |
2138 CHECK_FCT( fd_msg_parse_dict ( object, dict ) ); | |
2139 | |
2140 /* Call the recursive function */ | |
34
0e2b57789361
Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
2141 return parserules_do ( dict, object, error_info, 1 ) ; |
0 | 2142 } |
2143 | |
2144 /***************************************************************************************************************/ | |
2145 | |
2146 /* Compute the lengh of an object and its subtree. */ | |
2147 int fd_msg_update_length ( msg_or_avp * object ) | |
2148 { | |
2149 size_t sz = 0; | |
2150 struct dict_object * model; | |
2151 union { | |
2152 struct dict_cmd_data cmddata; | |
2153 struct dict_avp_data avpdata; | |
2154 } dictdata; | |
2155 | |
2156 TRACE_ENTRY("%p", object); | |
2157 | |
2158 /* Get the model of the object. This also validates the object */ | |
2159 CHECK_FCT( fd_msg_model ( object, &model ) ); | |
2160 | |
2161 /* Get the information of the model */ | |
2162 if (model) { | |
2163 CHECK_FCT( fd_dict_getval(model, &dictdata) ); | |
2164 } else { | |
2165 /* For unknown AVP, just don't change the size */ | |
2166 if (_C(object)->type == MSG_AVP) | |
2167 return 0; | |
2168 } | |
2169 | |
2170 /* Deal with easy cases: AVPs without children */ | |
2171 if ((_C(object)->type == MSG_AVP) && (dictdata.avpdata.avp_basetype != AVP_TYPE_GROUPED)) { | |
2172 /* Sanity check */ | |
2173 ASSERT(FD_IS_LIST_EMPTY(&_A(object)->avp_chain.children)); | |
2174 | |
2175 /* Now check that the data is set in the AVP */ | |
2176 CHECK_PARAMS( _A(object)->avp_public.avp_value ); | |
2177 | |
2178 sz = GETAVPHDRSZ( _A(object)->avp_public.avp_flags ); | |
2179 | |
2180 switch (dictdata.avpdata.avp_basetype) { | |
2181 case AVP_TYPE_OCTETSTRING: | |
2182 sz += _A(object)->avp_public.avp_value->os.len; | |
2183 break; | |
2184 | |
2185 case AVP_TYPE_INTEGER32: | |
2186 case AVP_TYPE_INTEGER64: | |
2187 case AVP_TYPE_UNSIGNED32: | |
2188 case AVP_TYPE_UNSIGNED64: | |
2189 case AVP_TYPE_FLOAT32: | |
2190 case AVP_TYPE_FLOAT64: | |
2191 sz += avp_value_sizes[dictdata.avpdata.avp_basetype]; | |
2192 break; | |
2193 | |
2194 default: | |
2195 /* Something went wrong... */ | |
2196 ASSERT(0); | |
2197 } | |
2198 } | |
2199 else /* message or grouped AVP */ | |
2200 { | |
2201 struct fd_list * ch = NULL; | |
2202 | |
2203 /* First, compute the header size */ | |
2204 if (_C(object)->type == MSG_AVP) { | |
2205 sz = GETAVPHDRSZ( _A(object)->avp_public.avp_flags ); | |
2206 } else { | |
2207 sz = GETMSGHDRSZ( ); | |
2208 } | |
2209 | |
2210 /* Recurse in all children and update the sz information */ | |
2211 for (ch = _C(object)->children.next; ch != &_C(object)->children; ch = ch->next) { | |
2212 CHECK_FCT( fd_msg_update_length ( ch->o ) ); | |
2213 | |
2214 /* Add the padded size to the parent */ | |
2215 sz += PAD4( _A(ch->o)->avp_public.avp_len ); | |
2216 } | |
2217 } | |
2218 | |
2219 /* When we arrive here, the "sz" variable contains the size to write in the object */ | |
2220 if (_C(object)->type == MSG_AVP) | |
2221 _A(object)->avp_public.avp_len = sz; | |
2222 else | |
2223 _M(object)->msg_public.msg_length = sz; | |
2224 | |
2225 return 0; | |
2226 } | |
2227 | |
2228 /***************************************************************************************************************/ | |
7
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2229 /* Macro to check if further callbacks must be called */ |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2230 #define TEST_ACTION_STOP() \ |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2231 if ((*msg == NULL) || (*action != DISP_ACT_CONT)) \ |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2232 goto no_error; |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2233 |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2234 /* Call all dispatch callbacks for a given message */ |
90
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
2235 int fd_msg_dispatch ( struct msg ** msg, struct session * session, enum disp_action *action, const char ** error_code) |
7
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2236 { |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2237 struct dictionary * dict; |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2238 struct dict_object * app; |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2239 struct dict_object * cmd; |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2240 struct avp * avp; |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2241 struct fd_list * cb_list; |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2242 int ret = 0; |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2243 |
90
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
2244 TRACE_ENTRY("%p %p %p %p", msg, session, action, error_code); |
7
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2245 CHECK_PARAMS( msg && CHECK_MSG(*msg) && action); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2246 |
90
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
2247 if (error_code) |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
2248 *error_code = NULL; |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
2249 |
7
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2250 /* Take the dispatch lock */ |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2251 CHECK_FCT( pthread_rwlock_rdlock(&fd_disp_lock) ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2252 pthread_cleanup_push( fd_cleanup_rwlock, &fd_disp_lock ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2253 |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2254 /* First, call the DISP_HOW_ANY callbacks */ |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2255 CHECK_FCT_DO( ret = fd_disp_call_cb_int( NULL, msg, NULL, session, action, NULL, NULL, NULL, NULL ), goto error ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2256 |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2257 TEST_ACTION_STOP(); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2258 |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2259 /* If we don't know the model at this point, we stop cause we cannot get the dictionary. It's invalid: an error should already have been trigged by ANY callbacks */ |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2260 CHECK_PARAMS_DO(cmd = (*msg)->msg_model, { ret = EINVAL; goto error; } ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2261 |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2262 /* Now resolve message application */ |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2263 CHECK_FCT_DO( ret = fd_dict_getdict( cmd, &dict ), goto error ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2264 CHECK_FCT_DO( ret = fd_dict_search( dict, DICT_APPLICATION, APPLICATION_BY_ID, &(*msg)->msg_public.msg_appl, &app, 0 ), goto error ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2265 |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2266 if (app == NULL) { |
90
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
2267 if ((*msg)->msg_public.msg_flags & CMD_FLAG_REQUEST) { |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
2268 if (error_code) |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
2269 *error_code = "DIAMETER_APPLICATION_UNSUPPORTED"; |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
2270 *action = DISP_ACT_ERROR; |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
2271 } else { |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
2272 TRACE_DEBUG(INFO, "Received an answer to a local query with an unsupported application %d, discarding...", (*msg)->msg_public.msg_appl); |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
2273 fd_msg_dump_walk(INFO, *msg); |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
2274 fd_msg_free(*msg); |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
2275 *msg = NULL; |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
2276 } |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
2277 goto no_error; |
7
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2278 } |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2279 |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2280 /* So start browsing the message */ |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2281 CHECK_FCT_DO( ret = fd_msg_browse( *msg, MSG_BRW_FIRST_CHILD, &avp, NULL ), goto error ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2282 while (avp != NULL) { |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2283 /* Sanity */ |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2284 ASSERT( avp->avp_public.avp_value ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2285 |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2286 /* For unknown AVP, we don't have a callback registered, so just skip */ |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2287 if (avp->avp_model) { |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2288 struct dict_object * type, * enumval; |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2289 |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2290 /* Get the list of callback for this AVP */ |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2291 CHECK_FCT_DO( ret = fd_dict_disp_cb(DICT_AVP, avp->avp_model, &cb_list), goto error ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2292 |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2293 /* Check if the AVP has a constant value */ |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2294 CHECK_FCT_DO( ret = fd_dict_search(dict, DICT_TYPE, TYPE_OF_AVP, avp->avp_model, &type, 0), goto error ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2295 if (type) { |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2296 struct dict_enumval_request req; |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2297 memset(&req, 0, sizeof(struct dict_enumval_request)); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2298 req.type_obj = type; |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2299 memcpy( &req.search.enum_value, avp->avp_public.avp_value, sizeof(union avp_value) ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2300 CHECK_FCT_DO( ret = fd_dict_search(dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &req, &enumval, 0), goto error ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2301 } else { |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2302 /* No enumerated value in this case */ |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2303 enumval = NULL; |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2304 } |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2305 |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2306 /* Call the callbacks */ |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2307 CHECK_FCT_DO( ret = fd_disp_call_cb_int( cb_list, msg, avp, session, action, app, cmd, avp->avp_model, enumval ), goto error ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2308 TEST_ACTION_STOP(); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2309 } |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2310 /* Go to next AVP */ |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2311 CHECK_FCT_DO( ret = fd_msg_browse( avp, MSG_BRW_WALK, &avp, NULL ), goto error ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2312 } |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2313 |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2314 /* Now call command and application callbacks */ |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2315 CHECK_FCT_DO( ret = fd_dict_disp_cb(DICT_COMMAND, cmd, &cb_list), goto error ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2316 CHECK_FCT_DO( ret = fd_disp_call_cb_int( cb_list, msg, NULL, session, action, app, cmd, NULL, NULL ), goto error ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2317 TEST_ACTION_STOP(); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2318 |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2319 if (app) { |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2320 CHECK_FCT_DO( ret = fd_dict_disp_cb(DICT_APPLICATION, app, &cb_list), goto error ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2321 CHECK_FCT_DO( ret = fd_disp_call_cb_int( cb_list, msg, NULL, session, action, app, cmd, NULL, NULL ), goto error ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2322 TEST_ACTION_STOP(); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2323 } |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2324 |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2325 pthread_cleanup_pop(0); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2326 |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2327 no_error: |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2328 CHECK_POSIX(pthread_rwlock_unlock(&fd_disp_lock) ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2329 return 0; |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2330 |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2331 error: |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2332 CHECK_POSIX_DO(pthread_rwlock_unlock(&fd_disp_lock), /* ignore */ ); |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2333 return ret; |
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
2334 } |