annotate libfdproto/messages.c @ 1554:566bb46cc73f

Updated copyright information
author Sebastien Decugis <sdecugis@freediameter.net>
date Tue, 06 Oct 2020 21:34:53 +0800
parents 19ab8ac08a36
children 2dbc816d48f4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
740
4a9f08d6b6ba Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 730
diff changeset
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> *
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
1554
566bb46cc73f Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1549
diff changeset
5 * Copyright (c) 2020, WIDE Project and NICT *
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
36 /* Messages module.
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37 *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38 * This module allows to manipulate the msg and avp structures that represents a Diameter message in memory.
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39 */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40
658
f198d16fa7f4 Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 656
diff changeset
41 #include "fdproto-internal.h"
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
42
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
43 #include <sys/param.h>
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
44
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
45 /* Type of object */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
46 enum msg_objtype {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
47 MSG_MSG = 1,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
48 MSG_AVP
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
49 };
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
50
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
51 /* Chaining of elements as a free hierarchy */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
52 struct msg_avp_chain {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
53 struct fd_list chaining; /* Chaining information at this level. */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
54 struct fd_list children; /* sentinel for the children of this object */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
55 enum msg_objtype type; /* Type of this object, _MSG_MSG or _MSG_AVP */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
56 };
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
57
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
58 /* Return the chain information from an AVP or MSG. Since it's the first field, we just cast */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
59 #define _C(_x) ((struct msg_avp_chain *)(_x))
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
60
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
61 /* Some details about chaining:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
62 *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
63 * A message is made of a header ( msg ) and 0 or more AVPs ( avp ).
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
64 * The structure is a kind of tree, where some AVPs (grouped AVPs) can contain other AVPs.
871
254d81d21d0b Fix some typos.
Thomas Klausner <tk@giga.or.at>
parents: 824
diff changeset
65 * Example:
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
66 * msg
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
67 * |-avp
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
68 * |-gavp
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
69 * | |-avp
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
70 * | |-avp
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
71 * | \-avp
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
72 * |-avp
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
73 * \-avp
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
74 *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
75 * Each item (msg or avp) structure begins with a msg_avp_chain structure.
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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.
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
77 *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
78 * All elements at the same level are linked by their "chaining" list.
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
79 * The "children" list is the sentinel for the lists of children of this element.
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
80 */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
81
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
82 /* The following definitions are used to recognize objects in memory. */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
83 #define MSG_MSG_EYEC (0x11355463)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
84 #define MSG_AVP_EYEC (0x11355467)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
85
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
86 /* The following structure represents an AVP instance. */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
87 struct avp {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
88 struct msg_avp_chain avp_chain; /* Chaining information of this AVP */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
89 int avp_eyec; /* Must be equal to MSG_AVP_EYEC */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
90 struct dict_object *avp_model; /* If not NULL, pointer to the dictionary object of this avp */
1092
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
91 struct {
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
92 avp_code_t mnf_code;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
93 vendor_id_t mnf_vendor;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
94 } avp_model_not_found; /* When model resolution has failed, store a copy of the data here to avoid searching again */
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
95 struct avp_hdr avp_public; /* AVP data that can be managed by other modules */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
96
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
97 uint8_t *avp_source; /* If the message was parsed from a buffer, pointer to the AVP data start in the buffer. */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
98 uint8_t *avp_rawdata; /* when the data can not be interpreted, the raw data is copied here. The header is not part of it. */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
99 size_t avp_rawlen; /* The length of the raw buffer. */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
100 union avp_value avp_storage; /* To avoid many alloc/free, store the integer values here and set avp_public.avp_data to &storage */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
101 int avp_mustfreeos; /* 1 if an octetstring is malloc'd in avp_storage and must be freed. */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
102 };
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
103
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
104 /* Macro to compute the AVP header size */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
105 #define AVPHDRSZ_NOVEND 8
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
106 #define AVPHDRSZ_VENDOR 12
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
107 #define GETAVPHDRSZ( _flag ) ((_flag & AVP_FLAG_VENDOR) ? AVPHDRSZ_VENDOR : AVPHDRSZ_NOVEND)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
108
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
109 /* Macro to cast a msg_avp_t */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
110 #define _A(_x) ((struct avp *)(_x))
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
111 /* Check the type and eyecatcher */
915
9bd18fa4e601 Fix macro to avoid infinite loop in some situations
Sebastien Decugis <sdecugis@freediameter.net>
parents: 903
diff changeset
112 #define CHECK_AVP(_x) ((_x) && (_C(_x)->type == MSG_AVP) && (_A(_x)->avp_eyec == MSG_AVP_EYEC))
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
113
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
114 /* The following structure represents an instance of a message (command and children AVPs). */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
115 struct msg {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
116 struct msg_avp_chain msg_chain; /* List of the AVPs in the message */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
117 int msg_eyec; /* Must be equal to MSG_MSG_EYEC */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
118 struct dict_object *msg_model; /* If not NULL, pointer to the dictionary object of this message */
1092
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
119 struct {
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
120 command_code_t mnf_code;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
121 uint8_t mnf_flags;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
122 } msg_model_not_found; /* When model resolution has failed, store a copy of the data here to avoid searching again */
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
123 struct msg_hdr msg_public; /* Message data that can be managed by extensions. */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
124
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
125 uint8_t *msg_rawbuffer; /* data buffer that was received, saved during fd_msg_parse_buffer and freed in fd_msg_parse_dict */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
126 int msg_routable; /* Is this a routable message? (0: undef, 1: routable, 2: non routable) */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
127 struct msg *msg_query; /* the associated query if the message is a received answer */
637
22e8fac3b2d6 Split interface file in modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 400
diff changeset
128 int msg_associated; /* and the counter part information in the query, to avoid double free */
83
c662d3eb6ff6 Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
129 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
130 struct session *msg_sess; /* Cached message session if any */
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
131 struct {
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1009
diff changeset
132 void (*anscb)(void *, struct msg **);
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1009
diff changeset
133 void (*expirecb)(void *, DiamId_t, size_t, struct msg **);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
134 void * data;
646
cfc8da9264f4 Prepared first part of the changes for #10
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 638
diff changeset
135 struct timespec timeout;
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1009
diff changeset
136 } msg_cb; /* Callback to be called when an answer is received, or timeout expires, if not NULL */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
137 DiamId_t msg_src_id; /* Diameter Id of the peer this message was received from. This string is malloc'd and must be freed */
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
138 size_t msg_src_id_len; /* cached length of this string */
1098
f38d77f9cfd3 Initial implementation of the hook mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1096
diff changeset
139 struct fd_msg_pmdl msg_pmdl; /* list of permessagedata structures. */
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
140 };
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
141
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
142 /* Macro to compute the message header size */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
143 #define GETMSGHDRSZ() 20
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
144
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
145 /* Macro to cast a msg_avp_t */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
146 #define _M(_x) ((struct msg *)(_x))
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
147 /* Check the type and eyecatcher */
704
289632905e19 Added new sanity check
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 690
diff changeset
148 #define CHECK_MSG(_x) ((_x) && (_C(_x)->type == MSG_MSG) && (_M(_x)->msg_eyec == MSG_MSG_EYEC))
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
149
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
150 #define VALIDATE_OBJ(_x) ( (CHECK_MSG(_x)) || (CHECK_AVP(_x)) )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
151
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
152
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
153 /* Macro to validate a MSGFL_ value */
638
9448cba86673 Improved usability of dbg_interactive
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 637
diff changeset
154 #define CHECK_AVPFL(_fl) ( ((_fl) & (- (AVPFL_MAX << 1) )) == 0 )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
155 #define CHECK_MSGFL(_fl) ( ((_fl) & (- (MSGFL_MAX << 1) )) == 0 )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
156
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
157
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
158 /* initial sizes of AVP from their types, in bytes. */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
159 static int avp_value_sizes[] = {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
160 0, /* AVP_TYPE_GROUPED: size is dynamic */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
161 0, /* AVP_TYPE_OCTETSTRING: size is dynamic */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
162 4, /* AVP_TYPE_INTEGER32: size is 32 bits */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163 8, /* AVP_TYPE_INTEGER64: size is 64 bits */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
164 4, /* AVP_TYPE_UNSIGNED32: size is 32 bits */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
165 8, /* AVP_TYPE_UNSIGNED64: size is 64 bits */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
166 4, /* AVP_TYPE_FLOAT32: size is 32 bits */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
167 8 /* AVP_TYPE_FLOAT64: size is 64 bits */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
168 };
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
169 #define CHECK_BASETYPE( _type ) ( ((_type) <= AVP_TYPE_MAX) && ((_type) >= 0) )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
170 #define GETINITIALSIZE( _type, _vend ) (avp_value_sizes[ CHECK_BASETYPE(_type) ? (_type) : 0] + GETAVPHDRSZ(_vend))
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
171
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
172 /* Forward declaration */
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
173 static int parsedict_do_msg(struct dictionary * dict, struct msg * msg, int only_hdr, struct fd_pei *error_info);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
174
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
175 /***************************************************************************************************************/
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
176 /* Creating objects */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
177
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
178 /* Initialize a msg_avp_chain structure */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
179 static void init_chain(struct msg_avp_chain * chain, int type)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
180 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
181 fd_list_init( &chain->chaining, (void *)chain);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
182 fd_list_init( &chain->children, (void *)chain);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
183 chain->type = type;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
184 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
185
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
186 /* Initialize a new AVP object */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
187 static void init_avp ( struct avp * avp )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
188 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
189 TRACE_ENTRY("%p", avp);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
190
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
191 memset(avp, 0, sizeof(struct avp));
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
192 init_chain( &avp->avp_chain, MSG_AVP);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
193 avp->avp_eyec = MSG_AVP_EYEC;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
194 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
195
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
196 /* Initialize a new MSG object */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
197 static void init_msg ( struct msg * msg )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
198 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
199 TRACE_ENTRY("%p", msg);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
200
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
201 memset(msg, 0, sizeof(struct msg));
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
202 init_chain( &msg->msg_chain, MSG_MSG);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
203 msg->msg_eyec = MSG_MSG_EYEC;
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1101
diff changeset
204
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1101
diff changeset
205 fd_list_init(&msg->msg_pmdl.sentinel, NULL);
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1101
diff changeset
206 CHECK_POSIX_DO( pthread_mutex_init(&msg->msg_pmdl.lock, NULL), );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
207 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
208
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
209
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
210 /* Create a new AVP instance */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
211 int fd_msg_avp_new ( struct dict_object * model, int flags, struct avp ** avp )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
212 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
213 struct avp *new = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
214
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
215 TRACE_ENTRY("%p %x %p", model, flags, avp);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
216
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
217 /* Check the parameters */
638
9448cba86673 Improved usability of dbg_interactive
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 637
diff changeset
218 CHECK_PARAMS( avp && CHECK_AVPFL(flags) );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
219
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
220 if (model) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
221 enum dict_object_type dicttype;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
222 CHECK_PARAMS( (fd_dict_gettype(model, &dicttype) == 0) && (dicttype == DICT_AVP) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
223 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
224
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
225 /* Create a new object */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
226 CHECK_MALLOC( new = malloc (sizeof(struct avp)) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
227
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
228 /* Initialize the fields */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
229 init_avp(new);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
230
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
231 if (model) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
232 struct dict_avp_data dictdata;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
233
1298
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
234 CHECK_FCT_DO( fd_dict_getval(model, &dictdata), { free(new); return __ret__; } );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
235
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
236 new->avp_model = model;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
237 new->avp_public.avp_code = dictdata.avp_code;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
238 new->avp_public.avp_flags = dictdata.avp_flag_val;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
239 new->avp_public.avp_len = GETINITIALSIZE(dictdata.avp_basetype, dictdata.avp_flag_val );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
240 new->avp_public.avp_vendor = dictdata.avp_vendor;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
241 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
242
638
9448cba86673 Improved usability of dbg_interactive
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 637
diff changeset
243 if (flags & AVPFL_SET_BLANK_VALUE) {
9448cba86673 Improved usability of dbg_interactive
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 637
diff changeset
244 new->avp_public.avp_value = &new->avp_storage;
9448cba86673 Improved usability of dbg_interactive
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 637
diff changeset
245 }
9448cba86673 Improved usability of dbg_interactive
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 637
diff changeset
246
892
b2e8f1a3ef76 Allow the content of the Failed-AVP to be parseable to bufferize the message. The content is only padded currently
Sebastien Decugis <sdecugis@freediameter.net>
parents: 891
diff changeset
247 if (flags & AVPFL_SET_RAWDATA_FROM_AVP) {
b2e8f1a3ef76 Allow the content of the Failed-AVP to be parseable to bufferize the message. The content is only padded currently
Sebastien Decugis <sdecugis@freediameter.net>
parents: 891
diff changeset
248 new->avp_rawlen = (*avp)->avp_public.avp_len - GETAVPHDRSZ( (*avp)->avp_public.avp_flags );
b2e8f1a3ef76 Allow the content of the Failed-AVP to be parseable to bufferize the message. The content is only padded currently
Sebastien Decugis <sdecugis@freediameter.net>
parents: 891
diff changeset
249 if (new->avp_rawlen) {
1298
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
250 CHECK_MALLOC_DO( new->avp_rawdata = malloc(new->avp_rawlen), { free(new); return __ret__; } );
916
058e95c3a336 Initialize dummy AVP for Failed-AVP content with 0s instead of FFs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 915
diff changeset
251 memset(new->avp_rawdata, 0x00, new->avp_rawlen);
892
b2e8f1a3ef76 Allow the content of the Failed-AVP to be parseable to bufferize the message. The content is only padded currently
Sebastien Decugis <sdecugis@freediameter.net>
parents: 891
diff changeset
252 }
b2e8f1a3ef76 Allow the content of the Failed-AVP to be parseable to bufferize the message. The content is only padded currently
Sebastien Decugis <sdecugis@freediameter.net>
parents: 891
diff changeset
253 }
b2e8f1a3ef76 Allow the content of the Failed-AVP to be parseable to bufferize the message. The content is only padded currently
Sebastien Decugis <sdecugis@freediameter.net>
parents: 891
diff changeset
254
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
255 /* The new object is ready, return */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
256 *avp = new;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
257 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
258 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
259
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
260 /* Create a new message instance */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
261 int fd_msg_new ( struct dict_object * model, int flags, struct msg ** msg )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
262 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
263 struct msg * new = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
264
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
265 TRACE_ENTRY("%p %x %p", model, flags, msg);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
266
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
267 /* Check the parameters */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
268 CHECK_PARAMS( msg && CHECK_MSGFL(flags) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
269
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
270 if (model) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
271 enum dict_object_type dicttype;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
272 CHECK_PARAMS( (fd_dict_gettype(model, &dicttype) == 0) && (dicttype == DICT_COMMAND) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
273 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
274
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
275 /* Create a new object */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
276 CHECK_MALLOC( new = malloc (sizeof(struct msg)) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
277
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
278 /* Initialize the fields */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
279 init_msg(new);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
280 new->msg_public.msg_version = DIAMETER_VERSION;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
281 new->msg_public.msg_length = GETMSGHDRSZ(); /* This will be updated later */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
282
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
283 if (model) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
284 struct dictionary *dict;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
285 struct dict_cmd_data dictdata;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
286 struct dict_object *dictappl;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
287
1298
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
288 CHECK_FCT_DO( fd_dict_getdict(model, &dict), { free(new); return __ret__; } );
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
289 CHECK_FCT_DO( fd_dict_getval(model, &dictdata), { free(new); return __ret__; } );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
290
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
291 new->msg_model = model;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
292 new->msg_public.msg_flags = dictdata.cmd_flag_val;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
293 new->msg_public.msg_code = dictdata.cmd_code;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
294
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
295 /* Initialize application from the parent, if any */
1298
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
296 CHECK_FCT_DO( fd_dict_search( dict, DICT_APPLICATION, APPLICATION_OF_COMMAND, model, &dictappl, 0), { free(new); return __ret__; } );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
297 if (dictappl != NULL) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
298 struct dict_application_data appdata;
1298
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
299 CHECK_FCT_DO( fd_dict_getval(dictappl, &appdata), { free(new); return __ret__; } );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
300 new->msg_public.msg_appl = appdata.application_id;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
301 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
302 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
303
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
304 if (flags & MSGFL_ALLOC_ETEID) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
305 new->msg_public.msg_eteid = fd_msg_eteid_get();
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
306 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
307
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
308 /* The new object is ready, return */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
309 *msg = new;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
310 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
311 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
312
992
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
313 static int bufferize_avp(unsigned char * buffer, size_t buflen, size_t * offset, struct avp * avp);
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
314 static int parsebuf_list(unsigned char * buf, size_t buflen, struct fd_list * head);
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
315 static int parsedict_do_chain(struct dictionary * dict, struct fd_list * head, int mandatory, struct fd_pei *error_info);
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
316
992
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
317
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
318 /* Create answer from a request */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
319 int fd_msg_new_answer_from_req ( struct dictionary * dict, struct msg ** msg, int flags )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
320 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
321 struct dict_object * model = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
322 struct msg *qry, *ans;
112
6a294d977878 Default to add Session-Id in answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 100
diff changeset
323 struct session * sess = NULL;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
324
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
325 TRACE_ENTRY("%p %x", msg, flags);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
326
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
327 /* Check the parameters */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
328 CHECK_PARAMS( msg );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
329 qry = *msg;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
330 CHECK_PARAMS( CHECK_MSG(qry) && (qry->msg_public.msg_flags & CMD_FLAG_REQUEST) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
331
112
6a294d977878 Default to add Session-Id in answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 100
diff changeset
332 if (! (flags & MSGFL_ANSW_NOSID)) {
6a294d977878 Default to add Session-Id in answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 100
diff changeset
333 /* Get the session of the message */
6a294d977878 Default to add Session-Id in answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 100
diff changeset
334 CHECK_FCT_DO( fd_msg_sess_get(dict, qry, &sess, NULL), /* ignore an error */ );
6a294d977878 Default to add Session-Id in answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 100
diff changeset
335 }
6a294d977878 Default to add Session-Id in answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 100
diff changeset
336
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
337 /* Find the model for the answer */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
338 if (flags & MSGFL_ANSW_ERROR) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
339 /* The model is the generic error format */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
340 CHECK_FCT( fd_dict_get_error_cmd(dict, &model) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
341 } else {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
342 /* The model is the answer corresponding to the query. It supposes that these are defined in the dictionary */
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
343 CHECK_FCT_DO( parsedict_do_msg( dict, qry, 1, NULL), /* continue */ );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
344 if (qry->msg_model) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
345 CHECK_FCT( fd_dict_search ( dict, DICT_COMMAND, CMD_ANSWER, qry->msg_model, &model, EINVAL ) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
346 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
347 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
348
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
349 /* Create the answer */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
350 CHECK_FCT( fd_msg_new( model, flags, &ans ) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
351
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
352 /* Set informations in the answer as in the query */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
353 ans->msg_public.msg_code = qry->msg_public.msg_code; /* useful for MSGFL_ANSW_ERROR */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
354 ans->msg_public.msg_appl = qry->msg_public.msg_appl;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
355 ans->msg_public.msg_eteid = qry->msg_public.msg_eteid;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
356 ans->msg_public.msg_hbhid = qry->msg_public.msg_hbhid;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
357
112
6a294d977878 Default to add Session-Id in answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 100
diff changeset
358 /* Add the Session-Id AVP if session is known */
6a294d977878 Default to add Session-Id in answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 100
diff changeset
359 if (sess && dict) {
1092
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
360 static struct dict_object * sess_id_avp = NULL;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
361 os0_t sid;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
362 size_t sidlen;
112
6a294d977878 Default to add Session-Id in answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 100
diff changeset
363 struct avp * avp;
6a294d977878 Default to add Session-Id in answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 100
diff changeset
364 union avp_value val;
6a294d977878 Default to add Session-Id in answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 100
diff changeset
365
1092
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
366 if (!sess_id_avp) {
1298
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
367 CHECK_FCT_DO( fd_dict_search( dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &sess_id_avp, ENOENT), { free(ans); return __ret__; } );
1092
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
368 }
1298
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
369 CHECK_FCT_DO( fd_sess_getsid ( sess, &sid, &sidlen ), { free(ans); return __ret__; } );
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
370 CHECK_FCT_DO( fd_msg_avp_new ( sess_id_avp, 0, &avp ), { free(ans); return __ret__; } );
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
371 val.os.data = sid;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
372 val.os.len = sidlen;
1298
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
373 CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), { free(avp); free(ans); return __ret__; } );
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
374 CHECK_FCT_DO( fd_msg_avp_add( ans, MSG_BRW_FIRST_CHILD, avp ), { free(avp); free(ans); return __ret__; } );
291
2d3a799ad29c Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 280
diff changeset
375 ans->msg_sess = sess;
1298
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
376 CHECK_FCT_DO( fd_sess_ref_msg(sess), { free(ans); return __ret__; } );
112
6a294d977878 Default to add Session-Id in answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 100
diff changeset
377 }
6a294d977878 Default to add Session-Id in answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 100
diff changeset
378
992
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
379 /* Add all Proxy-Info AVPs from the query if any */
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
380 if (! (flags & MSGFL_ANSW_NOPROXYINFO)) {
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
381 struct avp * avp;
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
382 struct fd_pei pei;
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
383 struct fd_list avpcpylist = FD_LIST_INITIALIZER(avpcpylist);
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
384
1298
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
385 CHECK_FCT_DO( fd_msg_browse(qry, MSG_BRW_FIRST_CHILD, &avp, NULL) , { free(ans); return __ret__; } );
992
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
386 while (avp) {
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
387 if ( (avp->avp_public.avp_code == AC_PROXY_INFO)
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
388 && (avp->avp_public.avp_vendor == 0) ) {
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
389 /* We found a Proxy-Info, need to duplicate it in the answer */
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
390
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
391 /* In order to avoid dealing with all different possibilities of states, we just create a buffer then parse it */
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
392 unsigned char * buf = NULL;
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
393 size_t offset = 0;
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
394
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
395 /* Create a buffer with the content of the AVP. This is easier than going through the list */
1298
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
396 CHECK_FCT_DO( fd_msg_update_length(avp), { free(ans); return __ret__; } );
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
397 CHECK_MALLOC_DO( buf = malloc(avp->avp_public.avp_len), { free(ans); return __ret__; } );
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
398 CHECK_FCT_DO( bufferize_avp(buf, avp->avp_public.avp_len, &offset, avp), { free(buf); free(ans); return __ret__; } );
992
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
399
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
400 /* Now we parse this buffer to create a copy AVP */
1298
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
401 CHECK_FCT_DO( parsebuf_list(buf, avp->avp_public.avp_len, &avpcpylist), { free(buf); free(ans); return __ret__; } );
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
402
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
403 /* Parse dictionary objects now to remove the dependency on the buffer */
1298
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
404 CHECK_FCT_DO( parsedict_do_chain(dict, &avpcpylist, 0, &pei), { /* leaking the avpcpylist -- this should never happen anyway */ free(buf); free(ans); return __ret__; } );
992
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
405
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
406 /* Done for this AVP */
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
407 free(buf);
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
408
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
409 /* We move this AVP now so that we do not parse again in next loop */
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
410 fd_list_move_end(&ans->msg_chain.children, &avpcpylist);
992
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
411 }
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
412 /* move to next AVP in the message, we can have several Proxy-Info instances */
1298
0f215b0dda5e Fix some possible memory leaks in fd_msg_new
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1248
diff changeset
413 CHECK_FCT_DO( fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL), { free(ans); return __ret__; } );
992
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
414 }
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
415 }
80584f0e851a Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 979
diff changeset
416
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
417 /* associate with query */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
418 ans->msg_query = qry;
637
22e8fac3b2d6 Split interface file in modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 400
diff changeset
419 qry->msg_associated = 1;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
420
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
421 /* Done */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
422 *msg = ans;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
423 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
424 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
425
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
426 /***************************************************************************************************************/
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
427
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
428 /* Explore a message */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
429 int fd_msg_browse_internal ( msg_or_avp * reference, enum msg_brw_dir dir, msg_or_avp ** found, int * depth )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
430 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
431 struct msg_avp_chain *result = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
432 int diff = 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
433 struct fd_list *li = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
434
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
435 TRACE_ENTRY("%p %d %p %p", reference, dir, found, depth);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
436
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
437 /* Initialize the "found" result if any */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
438 if (found)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
439 *found = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
440
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
441 /* Check the parameters */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
442 CHECK_PARAMS( VALIDATE_OBJ(reference) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
443
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
444 TRACE_DEBUG(FCTS, "chaining(%p): nxt:%p prv:%p hea:%p top:%p",
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
445 &_C(reference)->chaining,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
446 _C(reference)->chaining.next,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
447 _C(reference)->chaining.prev,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
448 _C(reference)->chaining.head,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
449 _C(reference)->chaining.o);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
450 TRACE_DEBUG(FCTS, "children(%p): nxt:%p prv:%p hea:%p top:%p",
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
451 &_C(reference)->children,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
452 _C(reference)->children.next,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
453 _C(reference)->children.prev,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
454 _C(reference)->children.head,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
455 _C(reference)->children.o);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
456
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
457 /* Now search */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
458 switch (dir) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
459 case MSG_BRW_NEXT:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
460 /* Check the reference is an AVP */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
461 CHECK_PARAMS( _C(reference)->type == MSG_AVP );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
462
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
463 li = &_C(reference)->chaining;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
464
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
465 /* Check if the next element is not the sentinel ( ==> the parent) */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
466 if (li->next != li->head)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
467 result = _C(li->next->o);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
468 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
469
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
470 case MSG_BRW_PREV:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
471 /* Check the reference is an AVP */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
472 CHECK_PARAMS( _C(reference)->type == MSG_AVP );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
473
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
474 li = &_C(reference)->chaining;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
475
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
476 /* Check if the prev element is not the sentinel ( ==> the parent) */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
477 if (li->prev != li->head)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
478 result = _C(li->prev->o);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
479 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
480
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
481 case MSG_BRW_FIRST_CHILD:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
482 li = &_C(reference)->children;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
483 if (! FD_IS_LIST_EMPTY(li)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
484 result = _C(li->next->o);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
485 diff = 1;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
486 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
487 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
488
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
489 case MSG_BRW_LAST_CHILD:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
490 li = &_C(reference)->children;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
491 if (! FD_IS_LIST_EMPTY(li)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
492 result = _C(li->prev->o);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
493 diff = 1;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
494 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
495 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
496
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
497 case MSG_BRW_PARENT:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
498 /* If the object is not chained, it has no parent */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
499 li = &_C(reference)->chaining;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
500 if (li != li->head) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
501 /* The sentinel is the parent's children list */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
502 result = _C(li->head->o);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
503 diff = -1;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
504 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
505 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
506
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
507 case MSG_BRW_WALK:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
508 /* First, try to find a child */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
509 li = &_C(reference)->children;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
510 if ( ! FD_IS_LIST_EMPTY(li) ) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
511 result = _C(li->next->o);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
512 diff = 1;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
513 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
514 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
515
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
516 /* Then try to find a "next" at this level or one of the parent's */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
517 li = &_C(reference)->chaining;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
518 do {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
519 /* If this element has a "next" element, return it */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
520 if (li->next != li->head) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
521 result = _C(li->next->o);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
522 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
523 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
524 /* otherwise, check if we have a parent */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
525 if (li == li->head) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
526 /* no parent */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
527 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
528 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
529 /* Go to the parent's chaining information and loop */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
530 diff -= 1;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
531 li = &_C(li->head->o)->chaining;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
532 } while (1);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
533 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
534
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
535 default:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
536 /* Other directions are invalid */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
537 CHECK_PARAMS( dir = 0 );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
538 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
539
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
540 /* Save the found object, if any */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
541 if (found && result)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
542 *found = (void *)result;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
543
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
544 /* Modify the depth according to the walk direction */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
545 if (depth && diff)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
546 (*depth) += diff;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
547
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
548 /* Return ENOENT if found was NULL */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
549 if ((!found) && (!result))
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
550 return ENOENT;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
551 else
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
552 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
553 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
554
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
555 /* Add an AVP into a tree */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
556 int fd_msg_avp_add ( msg_or_avp * reference, enum msg_brw_dir dir, struct avp *avp)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
557 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
558 TRACE_ENTRY("%p %d %p", reference, dir, avp);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
559
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
560 /* Check the parameters */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
561 CHECK_PARAMS( VALIDATE_OBJ(reference) && CHECK_AVP(avp) && FD_IS_LIST_EMPTY(&avp->avp_chain.chaining) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
562
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
563 /* Now insert */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
564 switch (dir) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
565 case MSG_BRW_NEXT:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
566 /* Check the reference is an AVP -- we do not chain AVPs at same level as msgs. */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
567 CHECK_PARAMS( _C(reference)->type == MSG_AVP );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
568
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
569 /* Insert the new avp after the reference */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
570 fd_list_insert_after( &_A(reference)->avp_chain.chaining, &avp->avp_chain.chaining );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
571 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
572
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
573 case MSG_BRW_PREV:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
574 /* Check the reference is an AVP */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
575 CHECK_PARAMS( _C(reference)->type == MSG_AVP );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
576
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
577 /* Insert the new avp before the reference */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
578 fd_list_insert_before( &_A(reference)->avp_chain.chaining, &avp->avp_chain.chaining );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
579 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
580
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
581 case MSG_BRW_FIRST_CHILD:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
582 /* Insert the new avp after the children sentinel */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
583 fd_list_insert_after( &_C(reference)->children, &avp->avp_chain.chaining );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
584 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
585
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
586 case MSG_BRW_LAST_CHILD:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
587 /* Insert the new avp before the children sentinel */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
588 fd_list_insert_before( &_C(reference)->children, &avp->avp_chain.chaining );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
589 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
590
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
591 default:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
592 /* Other directions are invalid */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
593 CHECK_PARAMS( dir = 0 );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
594 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
595
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
596 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
597 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
598
1423
67c263056d78 fd_msg_search_avp: search msg_or_avp, not just msg
Luke Mewburn <luke@mewburn.net>
parents: 1405
diff changeset
599 /* Search a given AVP model in a message or AVP */
67c263056d78 fd_msg_search_avp: search msg_or_avp, not just msg
Luke Mewburn <luke@mewburn.net>
parents: 1405
diff changeset
600 int fd_msg_search_avp ( msg_or_avp * reference, struct dict_object * what, struct avp ** avp )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
601 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
602 struct avp * nextavp;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
603 struct dict_avp_data dictdata;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
604 enum dict_object_type dicttype;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
605
1423
67c263056d78 fd_msg_search_avp: search msg_or_avp, not just msg
Luke Mewburn <luke@mewburn.net>
parents: 1405
diff changeset
606 TRACE_ENTRY("%p %p %p", reference, what, avp);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
607
1423
67c263056d78 fd_msg_search_avp: search msg_or_avp, not just msg
Luke Mewburn <luke@mewburn.net>
parents: 1405
diff changeset
608 CHECK_PARAMS( VALIDATE_OBJ(reference) && what );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
609
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
610 CHECK_PARAMS( (fd_dict_gettype(what, &dicttype) == 0) && (dicttype == DICT_AVP) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
611 CHECK_FCT( fd_dict_getval(what, &dictdata) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
612
1423
67c263056d78 fd_msg_search_avp: search msg_or_avp, not just msg
Luke Mewburn <luke@mewburn.net>
parents: 1405
diff changeset
613 /* Loop on all top AVPs in message or AVP */
67c263056d78 fd_msg_search_avp: search msg_or_avp, not just msg
Luke Mewburn <luke@mewburn.net>
parents: 1405
diff changeset
614 CHECK_FCT( fd_msg_browse(reference, MSG_BRW_FIRST_CHILD, (void *)&nextavp, NULL) );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
615 while (nextavp) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
616
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
617 if ( (nextavp->avp_public.avp_code == dictdata.avp_code)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
618 && (nextavp->avp_public.avp_vendor == dictdata.avp_vendor) ) /* always 0 if no V flag */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
619 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
620
1423
67c263056d78 fd_msg_search_avp: search msg_or_avp, not just msg
Luke Mewburn <luke@mewburn.net>
parents: 1405
diff changeset
621 /* Otherwise move to next AVP in the message or AVP */
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
622 CHECK_FCT( fd_msg_browse(nextavp, MSG_BRW_NEXT, (void *)&nextavp, NULL) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
623 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
624
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
625 if (avp)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
626 *avp = nextavp;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
627
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
628 if (avp && nextavp) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
629 struct dictionary * dict;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
630 CHECK_FCT( fd_dict_getdict( what, &dict) );
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
631 CHECK_FCT_DO( fd_msg_parse_dict( nextavp, dict, NULL ), /* nothing */ );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
632 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
633
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
634 if (avp || nextavp)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
635 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
636 else
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
637 return ENOENT;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
638 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
639
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
640
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
641 /***************************************************************************************************************/
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
642 /* Deleting objects */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
643
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
644 /* Destroy and free an AVP or message */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
645 static int destroy_obj (struct msg_avp_chain * obj )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
646 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
647 TRACE_ENTRY("%p", obj);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
648
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
649 /* Check the parameter is a valid object */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
650 CHECK_PARAMS( VALIDATE_OBJ(obj) && FD_IS_LIST_EMPTY( &obj->children ) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
651
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
652 /* Unlink this object if needed */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
653 fd_list_unlink( &obj->chaining );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
654
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
655 /* Free the octetstring if needed */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
656 if ((obj->type == MSG_AVP) && (_A(obj)->avp_mustfreeos == 1)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
657 free(_A(obj)->avp_storage.os.data);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
658 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
659 /* Free the rawdata if needed */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
660 if ((obj->type == MSG_AVP) && (_A(obj)->avp_rawdata != NULL)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
661 free(_A(obj)->avp_rawdata);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
662 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
663 if ((obj->type == MSG_MSG) && (_M(obj)->msg_rawbuffer != NULL)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
664 free(_M(obj)->msg_rawbuffer);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
665 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
666
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
667 if ((obj->type == MSG_MSG) && (_M(obj)->msg_src_id != NULL)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
668 free(_M(obj)->msg_src_id);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
669 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
670
83
c662d3eb6ff6 Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
671 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
672 fd_rtd_free(&_M(obj)->msg_rtdata);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
673 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
674
85
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
675 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
676 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
677 }
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
678
1098
f38d77f9cfd3 Initial implementation of the hook mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1096
diff changeset
679 if ((obj->type == MSG_MSG) && (_M(obj)->msg_pmdl.sentinel.o != NULL)) {
f38d77f9cfd3 Initial implementation of the hook mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1096
diff changeset
680 ((void (*)(struct fd_msg_pmdl *))_M(obj)->msg_pmdl.sentinel.o)(&_M(obj)->msg_pmdl);
f38d77f9cfd3 Initial implementation of the hook mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1096
diff changeset
681 }
f38d77f9cfd3 Initial implementation of the hook mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1096
diff changeset
682
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
683 /* free the object */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
684 free(obj);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
685
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
686 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
687 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
688
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
689 /* Destroy an object and all its children */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
690 static void destroy_tree(struct msg_avp_chain * obj)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
691 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
692 struct fd_list *rem;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
693
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
694 TRACE_ENTRY("%p", obj);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
695
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
696 /* Destroy any subtree */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
697 while ( (rem = obj->children.next) != &obj->children)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
698 destroy_tree(_C(rem->o));
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
699
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
700 /* Then unlink and destroy the object */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
701 CHECK_FCT_DO( destroy_obj(obj), /* nothing */ );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
702 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
703
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
704 /* Free an object and its tree */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
705 int fd_msg_free ( msg_or_avp * object )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
706 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
707 TRACE_ENTRY("%p", object);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
708
1205
165569e8cba8 Allow NULL parameter in fd_msg_free
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1173
diff changeset
709 if (object == NULL)
165569e8cba8 Allow NULL parameter in fd_msg_free
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1173
diff changeset
710 return 0;
165569e8cba8 Allow NULL parameter in fd_msg_free
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1173
diff changeset
711
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
712 if (CHECK_MSG(object)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
713 if (_M(object)->msg_query) {
637
22e8fac3b2d6 Split interface file in modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 400
diff changeset
714 _M(_M(object)->msg_query)->msg_associated = 0;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
715 CHECK_FCT( fd_msg_free( _M(object)->msg_query ) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
716 _M(object)->msg_query = NULL;
637
22e8fac3b2d6 Split interface file in modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 400
diff changeset
717 } else {
22e8fac3b2d6 Split interface file in modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 400
diff changeset
718 if (_M(object)->msg_associated) {
22e8fac3b2d6 Split interface file in modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 400
diff changeset
719 TRACE_DEBUG(INFO, "Not freeing query %p referenced in an answer (will be freed along the answer).", object);
22e8fac3b2d6 Split interface file in modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 400
diff changeset
720 return 0;
22e8fac3b2d6 Split interface file in modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 400
diff changeset
721 }
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
722 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
723 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
724
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
725 destroy_tree(_C(object));
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
726 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
727 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
728
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
729
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
730 /***************************************************************************************************************/
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
731 /* Debug functions: dumping */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
732
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
733 /* messages and AVP formatters */
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
734 typedef DECLARE_FD_DUMP_PROTOTYPE( (*msg_dump_formatter_msg), struct msg * msg );
1095
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
735 typedef DECLARE_FD_DUMP_PROTOTYPE( (*msg_dump_formatter_avp), struct avp * avp, int level, int first, int last );
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
736
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
737 /* Core function to process the dumping */
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
738 static DECLARE_FD_DUMP_PROTOTYPE( msg_dump_process, msg_dump_formatter_msg msg_format, msg_dump_formatter_avp avp_format, msg_or_avp *obj, struct dictionary *dict, int force_parsing, int recurse )
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
739 {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
740 FD_DUMP_HANDLE_OFFSET();
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
741
1172
83d55d26ae80 Hand the case of invalid objects in the msg_dump functions
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1125
diff changeset
742 if (!VALIDATE_OBJ(obj)) {
1173
d0a7b76a3c1c Fix typos
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1172
diff changeset
743 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID MESSAGE OR AVP @%p", obj), return NULL);
1172
83d55d26ae80 Hand the case of invalid objects in the msg_dump functions
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1125
diff changeset
744 return *buf;
83d55d26ae80 Hand the case of invalid objects in the msg_dump functions
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1125
diff changeset
745 }
83d55d26ae80 Hand the case of invalid objects in the msg_dump functions
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1125
diff changeset
746
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
747 if (force_parsing) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
748 (void) fd_msg_parse_dict(obj, dict, NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
749 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
750
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
751 switch (_C(obj)->type) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
752 case MSG_AVP:
1095
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
753 CHECK_MALLOC_DO( (*avp_format)(FD_DUMP_STD_PARAMS, (struct avp *)obj, 0, 1, 1), return NULL);
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
754 break;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
755
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
756 case MSG_MSG:
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
757 CHECK_MALLOC_DO( (*msg_format)(FD_DUMP_STD_PARAMS, (struct msg *)obj), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
758 break;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
759
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
760 default:
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
761 ASSERT(0);
1173
d0a7b76a3c1c Fix typos
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1172
diff changeset
762 free(*buf);
1172
83d55d26ae80 Hand the case of invalid objects in the msg_dump functions
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1125
diff changeset
763 *buf = NULL;
83d55d26ae80 Hand the case of invalid objects in the msg_dump functions
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1125
diff changeset
764 return NULL;
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
765 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
766
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
767 if (recurse) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
768 struct avp * avp = NULL;
1095
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
769 int first = 1;
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
770 CHECK_FCT_DO( fd_msg_browse ( obj, MSG_BRW_FIRST_CHILD, &avp, NULL ), avp = NULL );
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
771 while (avp) {
1095
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
772 struct avp * nextavp = NULL;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
773 CHECK_FCT_DO( fd_msg_browse ( avp, MSG_BRW_NEXT, &nextavp, NULL ), nextavp = NULL );
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
774 CHECK_MALLOC_DO( (*avp_format)(FD_DUMP_STD_PARAMS, avp, 1, first, nextavp ? 0 : 1), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
775 avp = nextavp;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
776 first = 0;
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
777 };
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
778 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
779
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
780 return *buf;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
781 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
782
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
783 /*
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
784 * Tree View message dump
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
785 */
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
786 static DECLARE_FD_DUMP_PROTOTYPE( msg_format_treeview, struct msg * msg )
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
787 {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
788 if (!CHECK_MSG(msg)) {
1125
98d1ad9bf85a Fix initialization of random number; Cleanup the dump message display
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1121
diff changeset
789 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID MESSAGE"), return NULL);
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
790 return *buf;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
791 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
792
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
793 if (!msg->msg_model) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
794 if (msg->msg_model_not_found.mnf_code) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
795 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(not found in dictionary)\n"), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
796 } else {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
797 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(not searched in dictionary)\n"), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
798 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
799 } else {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
800 enum dict_object_type dicttype;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
801 struct dict_cmd_data dictdata;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
802 if (fd_dict_gettype(msg->msg_model, &dicttype) || (dicttype != DICT_COMMAND)) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
803 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(invalid model information)\n"), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
804 } else if (fd_dict_getval(msg->msg_model, &dictdata)) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
805 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(error getting model information)\n"), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
806 } else {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
807 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "'%s'\n", dictdata.cmd_name), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
808 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
809 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
810
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
811 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " Version: 0x%02hhX\n", msg->msg_public.msg_version), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
812 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " Length: %d\n", msg->msg_public.msg_length), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
813 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " Flags: 0x%02hhX (" DUMP_CMDFL_str ")\n", msg->msg_public.msg_flags, DUMP_CMDFL_val(msg->msg_public.msg_flags)), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
814 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " Command Code: %u\n", msg->msg_public.msg_code), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
815 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " ApplicationId: %d\n", msg->msg_public.msg_appl), return NULL);
1120
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
816 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " Hop-by-Hop Identifier: 0x%08X\n", msg->msg_public.msg_hbhid), return NULL);
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
817 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " End-to-End Identifier: 0x%08X\n", msg->msg_public.msg_eteid), return NULL);
1125
98d1ad9bf85a Fix initialization of random number; Cleanup the dump message display
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1121
diff changeset
818 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " {internal data}: src:%s(%zd) rwb:%p rt:%d cb:%p,%p(%p) qry:%p asso:%d sess:%p", msg->msg_src_id?:"(nil)", msg->msg_src_id_len, msg->msg_rawbuffer, msg->msg_routable, msg->msg_cb.anscb, msg->msg_cb.expirecb, msg->msg_cb.data, msg->msg_query, msg->msg_associated, msg->msg_sess), return NULL);
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
819
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
820 return *buf;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
821 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
822
1095
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
823 static DECLARE_FD_DUMP_PROTOTYPE( avp_format_treeview, struct avp * avp, int level, int first, int last )
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
824 {
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
825 char * name;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
826 struct dict_avp_data dictdata;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
827 struct dict_avp_data *dictinfo = NULL;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
828 struct dict_vendor_data vendordata;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
829 struct dict_vendor_data *vendorinfo = NULL;
1095
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
830
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
831 if (level) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
832 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n"), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
833 }
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
834
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
835 if (!CHECK_AVP(avp)) {
1125
98d1ad9bf85a Fix initialization of random number; Cleanup the dump message display
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1121
diff changeset
836 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID AVP"), return NULL);
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
837 return *buf;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
838 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
839
1125
98d1ad9bf85a Fix initialization of random number; Cleanup the dump message display
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1121
diff changeset
840 if (level) {
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
841 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%*sAVP: ", level * 3, ""), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
842 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
843
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
844 if (!avp->avp_model) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
845 if (avp->avp_model_not_found.mnf_code) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
846 name = "(not found in dictionary)";
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
847 } else {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
848 name = "(not searched in dictionary)";
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
849 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
850 } else {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
851 enum dict_object_type dicttype;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
852 if (fd_dict_gettype(avp->avp_model, &dicttype) || (dicttype != DICT_AVP)) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
853 name = "(invalid model information)";
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
854 } else if (fd_dict_getval(avp->avp_model, &dictdata)) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
855 name = "(error getting model information)";
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
856 } else {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
857 name = dictdata.avp_name;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
858 dictinfo = &dictdata;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
859 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
860 struct dictionary * dict;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
861 struct dict_object * vendor;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
862 if ((!fd_dict_getdict(avp->avp_model, &dict))
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
863 && (!fd_dict_search(dict, DICT_VENDOR, VENDOR_OF_AVP, avp->avp_model, &vendor, ENOENT))
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
864 && (!fd_dict_getval(vendor, &vendordata))) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
865 vendorinfo = &vendordata;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
866 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
867 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
868 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
869 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
870
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
871 if (dictinfo) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
872 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "'%s'(%u)", name, avp->avp_public.avp_code), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
873 } else {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
874 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%u%s", avp->avp_public.avp_code, name), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
875 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
876
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
877 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
878 if (vendorinfo) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
879 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " vend='%s'(%u)", vendorinfo->vendor_name, avp->avp_public.avp_vendor), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
880 } else {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
881 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " vend=%u", avp->avp_public.avp_vendor), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
882 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
883 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
884
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
885 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " l=%d f=" DUMP_AVPFL_str " val=", avp->avp_public.avp_len, DUMP_AVPFL_val(avp->avp_public.avp_flags)), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
886
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
887 if (dictinfo && (dictinfo->avp_basetype == AVP_TYPE_GROUPED)) {
1095
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
888 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(grouped)"), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
889 if (level) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
890 struct avp * inavp = NULL;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
891 int first = 1;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
892 CHECK_FCT_DO( fd_msg_browse ( avp, MSG_BRW_FIRST_CHILD, &inavp, NULL ), inavp = NULL );
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
893 while (inavp) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
894 struct avp * nextavp = NULL;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
895 CHECK_FCT_DO( fd_msg_browse ( inavp, MSG_BRW_NEXT, &nextavp, NULL ), inavp = NULL );
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
896 CHECK_MALLOC_DO( avp_format_treeview(FD_DUMP_STD_PARAMS, inavp, level + 1, first, nextavp ? 0 : 1), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
897 inavp = nextavp;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
898 first = 0;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
899 };
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
900 }
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
901 } else {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
902 if (avp->avp_public.avp_value) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
903 CHECK_MALLOC_DO( fd_dict_dump_avp_value(FD_DUMP_STD_PARAMS, avp->avp_public.avp_value, avp->avp_model, 0, 0), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
904 } else if (avp->avp_rawdata) {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
905 CHECK_MALLOC_DO( fd_dump_extend_hexdump(FD_DUMP_STD_PARAMS, avp->avp_rawdata, avp->avp_rawlen, 0, 0), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
906 } else {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
907 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(not set)"), return NULL);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
908 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
909 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
910
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
911 return *buf;
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
912 }
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
913
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
914 /* multi-line human-readable dump similar to wireshark output */
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
915 DECLARE_FD_DUMP_PROTOTYPE( fd_msg_dump_treeview, msg_or_avp *obj, struct dictionary *dict, int force_parsing, int recurse )
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
916 {
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
917 return msg_dump_process(FD_DUMP_STD_PARAMS, msg_format_treeview, avp_format_treeview, obj, dict, force_parsing, recurse);
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
918 }
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
919
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
920
1095
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
921 /*
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
922 * One-line dumper for compact but complete traces
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
923 */
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
924 static DECLARE_FD_DUMP_PROTOTYPE( msg_format_full, struct msg * msg )
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
925 {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
926 int success = 0;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
927 struct dict_cmd_data dictdata;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
928
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
929 if (!CHECK_MSG(msg)) {
1119
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
930 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID MESSAGE"), return NULL);
1095
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
931 return *buf;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
932 }
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
933
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
934 if (!msg->msg_model) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
935 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(no model) "), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
936 } else {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
937 enum dict_object_type dicttype=0;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
938 if (fd_dict_gettype(msg->msg_model, &dicttype) || (dicttype != DICT_COMMAND)) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
939 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(invalid model %d) ", dicttype), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
940 } else if (fd_dict_getval(msg->msg_model, &dictdata)) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
941 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(error getting model data) "), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
942 } else {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
943 success = 1;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
944 }
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
945 }
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
946 if (msg->msg_public.msg_appl) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
947 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS,
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
948 "%s(%u/%u)[" DUMP_CMDFL_str "], Length=%u, Hop-By-Hop-Id=0x%08x, End-to-End=0x%08x",
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
949 success ? dictdata.cmd_name : "unknown", msg->msg_public.msg_appl, msg->msg_public.msg_code, DUMP_CMDFL_val(msg->msg_public.msg_flags),
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
950 msg->msg_public.msg_length, msg->msg_public.msg_hbhid, msg->msg_public.msg_eteid), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
951 } else {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
952 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS,
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
953 "%s(%u)[" DUMP_CMDFL_str "], Length=%u, Hop-By-Hop-Id=0x%08x, End-to-End=0x%08x",
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
954 success ? dictdata.cmd_name : "unknown", msg->msg_public.msg_code, DUMP_CMDFL_val(msg->msg_public.msg_flags),
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
955 msg->msg_public.msg_length, msg->msg_public.msg_hbhid, msg->msg_public.msg_eteid), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
956 }
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
957 return *buf;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
958 }
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
959
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
960 static DECLARE_FD_DUMP_PROTOTYPE( avp_format_full, struct avp * avp, int level, int first, int last )
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
961 {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
962 int success = 0;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
963 struct dict_avp_data dictdata;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
964
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
965 if (level) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
966 if ((first) && ((*buf)[*offset - 1] == '=')) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
967 /* We are first AVP of a grouped AVP */
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
968 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{ "), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
969 } else {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
970 /* We follow another AVP, or a message header */
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
971 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, ", { "), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
972 }
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
973 }
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
974
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
975 if (!CHECK_AVP(avp)) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
976 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID AVP"), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
977 goto end;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
978 }
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
979
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
980
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
981 if (avp->avp_model) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
982 enum dict_object_type dicttype;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
983 if (fd_dict_gettype(avp->avp_model, &dicttype) || (dicttype != DICT_AVP)) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
984 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(invalid model: %d) ", dicttype), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
985 } else if (fd_dict_getval(avp->avp_model, &dictdata)) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
986 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(error getting model data) "), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
987 } else {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
988 success = 1;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
989 }
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
990 }
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
991
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
992 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
993 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%s(%u/%u)[" DUMP_AVPFL_str "]=",
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
994 success ? dictdata.avp_name : "unknown", avp->avp_public.avp_vendor, avp->avp_public.avp_code, DUMP_AVPFL_val(avp->avp_public.avp_flags)), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
995 } else {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
996 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%s(%u)[" DUMP_AVPFL_str "]=",
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
997 success ? dictdata.avp_name : "unknown", avp->avp_public.avp_code, DUMP_AVPFL_val(avp->avp_public.avp_flags)), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
998 }
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
999
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1000
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1001 if (success && (dictdata.avp_basetype == AVP_TYPE_GROUPED)) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1002 if (level) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1003 struct avp * inavp = NULL;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1004 int first = 1;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1005 CHECK_FCT_DO( fd_msg_browse ( avp, MSG_BRW_FIRST_CHILD, &inavp, NULL ), inavp = NULL );
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1006 while (inavp) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1007 struct avp * nextavp = NULL;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1008 CHECK_FCT_DO( fd_msg_browse ( inavp, MSG_BRW_NEXT, &nextavp, NULL ), inavp = NULL );
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1009 CHECK_MALLOC_DO( avp_format_full(FD_DUMP_STD_PARAMS, inavp, level + 1, first, nextavp ? 0 : 1), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1010 inavp = nextavp;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1011 first = 0;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1012 };
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1013 }
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1014 } else {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1015 if (avp->avp_public.avp_value) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1016 CHECK_MALLOC_DO( fd_dict_dump_avp_value(FD_DUMP_STD_PARAMS, avp->avp_public.avp_value, avp->avp_model, 0, 0), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1017 } else if (avp->avp_rawdata) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1018 CHECK_MALLOC_DO( fd_dump_extend_hexdump(FD_DUMP_STD_PARAMS, avp->avp_rawdata, avp->avp_rawlen, 0, 0), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1019 } else {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1020 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(not set)"), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1021 }
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1022 }
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1023
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1024 end:
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1025 if (level) {
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1026 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " }"), return NULL);
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1027 }
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1028
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1029 return *buf;
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1030 }
1096
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1031
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
1032 /* one-line dump with all the contents of the message */
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
1033 DECLARE_FD_DUMP_PROTOTYPE( fd_msg_dump_full, msg_or_avp *obj, struct dictionary *dict, int force_parsing, int recurse )
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
1034 {
1095
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1035 return msg_dump_process(FD_DUMP_STD_PARAMS, msg_format_full, avp_format_full, obj, dict, force_parsing, recurse);
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
1036 }
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
1037
1096
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1038
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1039
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1040 /*
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1041 * One-line dumper for compact but complete traces
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1042 */
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1043 static DECLARE_FD_DUMP_PROTOTYPE( msg_format_summary, struct msg * msg )
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1044 {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1045 if (!CHECK_MSG(msg)) {
1125
98d1ad9bf85a Fix initialization of random number; Cleanup the dump message display
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1121
diff changeset
1046 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID MESSAGE"), return NULL);
1096
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1047 return *buf;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1048 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1049
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1050 if (!msg->msg_model) {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1051 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(no model)"), return NULL);
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1052 } else {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1053 enum dict_object_type dicttype;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1054 struct dict_cmd_data dictdata;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1055 if (fd_dict_gettype(msg->msg_model, &dicttype) || (dicttype != DICT_COMMAND) || (fd_dict_getval(msg->msg_model, &dictdata))) {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1056 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(model error)"), return NULL);
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1057 } else {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1058 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "'%s'", dictdata.cmd_name), return NULL);
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1059 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1060 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1061 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%u/%u f:" DUMP_CMDFL_str " src:'%s' len:%d",
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1062 msg->msg_public.msg_appl, msg->msg_public.msg_code, DUMP_CMDFL_val(msg->msg_public.msg_flags), msg->msg_src_id?:"(nil)", msg->msg_public.msg_length), return NULL);
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1063
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1064 return *buf;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1065 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1066
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1067 static DECLARE_FD_DUMP_PROTOTYPE( avp_format_summary, struct avp * avp, int level, int first, int last )
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1068 {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1069 char * name;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1070 struct dict_avp_data dictdata;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1071 struct dict_avp_data *dictinfo = NULL;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1072 struct dict_vendor_data vendordata;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1073 struct dict_vendor_data *vendorinfo = NULL;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1074
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1075 if (level) {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1076 if (first) {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1077 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " {"), return NULL);
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1078 } else {
1120
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1079 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, ","), return NULL);
1096
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1080 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1081 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1082
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1083 if (!CHECK_AVP(avp)) {
1125
98d1ad9bf85a Fix initialization of random number; Cleanup the dump message display
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1121
diff changeset
1084 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID AVP"), return NULL);
1096
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1085 goto end;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1086 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1087
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1088 if (!level) {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1089 /* We have been called to explicitely dump this AVP, so we parse its name if available */
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1090 if (!avp->avp_model) {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1091 name = "(no model)";
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1092 } else {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1093 enum dict_object_type dicttype;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1094 if (fd_dict_gettype(avp->avp_model, &dicttype) || (dicttype != DICT_AVP) || (fd_dict_getval(avp->avp_model, &dictdata))) {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1095 name = "(model error)";
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1096 } else {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1097 name = dictdata.avp_name;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1098 dictinfo = &dictdata;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1099 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1100 struct dictionary * dict;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1101 struct dict_object * vendor;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1102 if ((!fd_dict_getdict(avp->avp_model, &dict))
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1103 && (!fd_dict_search(dict, DICT_VENDOR, VENDOR_OF_AVP, avp->avp_model, &vendor, ENOENT))
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1104 && (!fd_dict_getval(vendor, &vendordata))) {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1105 vendorinfo = &vendordata;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1106 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1107 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1108 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1109 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1110
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1111 if (dictinfo) {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1112 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "'%s'(%u)", name, avp->avp_public.avp_code), return NULL);
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1113 } else {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1114 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%u%s", avp->avp_public.avp_code, name), return NULL);
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1115 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1116
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1117 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1118 if (vendorinfo) {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1119 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " V='%s'(%u)", vendorinfo->vendor_name, avp->avp_public.avp_vendor), return NULL);
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1120 } else {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1121 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " V=%u", avp->avp_public.avp_vendor), return NULL);
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1122 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1123 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1124
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1125 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " L=%d F=" DUMP_AVPFL_str " V=", avp->avp_public.avp_len, DUMP_AVPFL_val(avp->avp_public.avp_flags)), return NULL);
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1126
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1127 if ((!dictinfo) || (dictinfo->avp_basetype != AVP_TYPE_GROUPED)) {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1128 if (avp->avp_public.avp_value) {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1129 CHECK_MALLOC_DO( fd_dict_dump_avp_value(FD_DUMP_STD_PARAMS, avp->avp_public.avp_value, avp->avp_model, 0, 0), return NULL);
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1130 } else if (avp->avp_rawdata) {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1131 CHECK_MALLOC_DO( fd_dump_extend_hexdump(FD_DUMP_STD_PARAMS, avp->avp_rawdata, avp->avp_rawlen, 0, 0), return NULL);
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1132 } else {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1133 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(not set)"), return NULL);
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1134 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1135 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1136 } else {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1137 /* For embedded AVPs, we only display (vendor,) code & length */
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1138 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) {
1120
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1139 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "V:%u/", avp->avp_public.avp_vendor), return NULL);
1096
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1140 }
1120
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1141 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "C:%u/l:%d", avp->avp_public.avp_code, avp->avp_public.avp_len), return NULL);
1096
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1142 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1143
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1144 end:
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1145 if ((level) && (last)) {
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1146 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "}"), return NULL);
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1147 }
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1148
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1149 return *buf;
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1150 }
1095
647c7e7015af Ported the fd_msg_dump_full function to the new mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
1151
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
1152 /* This one only prints a short display, does not go into the complete tree */
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1092
diff changeset
1153 DECLARE_FD_DUMP_PROTOTYPE( fd_msg_dump_summary, msg_or_avp *obj, struct dictionary *dict, int force_parsing, int recurse )
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
1154 {
1096
97a257c80de0 Implemented remaining flavour of message dump function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1095
diff changeset
1155 return msg_dump_process(FD_DUMP_STD_PARAMS, msg_format_summary, avp_format_summary, obj, dict, force_parsing, recurse);
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
1156 }
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
1157
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1158 /***************************************************************************************************************/
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1159 /* Simple meta-data management */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1160
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1161 /* Retrieve the model of an object */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1162 int fd_msg_model ( msg_or_avp * reference, struct dict_object ** model )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1163 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1164 TRACE_ENTRY("%p %p", reference, model);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1165
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1166 /* Check the parameters */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1167 CHECK_PARAMS( model && VALIDATE_OBJ(reference) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1168
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1169 /* copy the model reference */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1170 switch (_C(reference)->type) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1171 case MSG_AVP:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1172 *model = _A(reference)->avp_model;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1173 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1174
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1175 case MSG_MSG:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1176 *model = _M(reference)->msg_model;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1177 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1178
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1179 default:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1180 CHECK_PARAMS(0);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1181 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1182
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1183 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1184 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1185
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1186 /* Retrieve the address of the msg_public field of a message */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1187 int fd_msg_hdr ( struct msg *msg, struct msg_hdr **pdata )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1188 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1189 TRACE_ENTRY("%p %p", msg, pdata);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1190 CHECK_PARAMS( CHECK_MSG(msg) && pdata );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1191
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1192 *pdata = &msg->msg_public;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1193 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1194 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1195
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1196 /* Retrieve the address of the avp_public field of an avp */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1197 int fd_msg_avp_hdr ( struct avp *avp, struct avp_hdr **pdata )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1198 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1199 TRACE_ENTRY("%p %p", avp, pdata);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1200 CHECK_PARAMS( CHECK_AVP(avp) && pdata );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1201
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1202 *pdata = &avp->avp_public;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1203 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1204 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1205
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1206 /* Associate answers and queries */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1207 int fd_msg_answ_associate( struct msg * answer, struct msg * query )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1208 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1209 TRACE_ENTRY( "%p %p", answer, query );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1210
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1211 CHECK_PARAMS( CHECK_MSG(answer) && CHECK_MSG(query) && (answer->msg_query == NULL ) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1212
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1213 answer->msg_query = query;
637
22e8fac3b2d6 Split interface file in modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 400
diff changeset
1214 query->msg_associated = 1;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1215
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1216 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1217 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1218
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1219 int fd_msg_answ_getq( struct msg * answer, struct msg ** query )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1220 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1221 TRACE_ENTRY( "%p %p", answer, query );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1222
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1223 CHECK_PARAMS( CHECK_MSG(answer) && query );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1224
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1225 *query = answer->msg_query;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1226
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1227 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1228 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1229
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1230 int fd_msg_answ_detach( struct msg * answer )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1231 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1232 TRACE_ENTRY( "%p", answer );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1233
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1234 CHECK_PARAMS( CHECK_MSG(answer) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1235
637
22e8fac3b2d6 Split interface file in modules
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 400
diff changeset
1236 answer->msg_query->msg_associated = 0;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1237 answer->msg_query = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1238
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1239 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1240 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1241
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1242 /* Associate / get answer callbacks */
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1009
diff changeset
1243 int fd_msg_anscb_associate( struct msg * msg, void ( *anscb)(void *, struct msg **), void * data, void (*expirecb)(void *, DiamId_t, size_t, struct msg **), const struct timespec *timeout )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1244 {
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1009
diff changeset
1245 TRACE_ENTRY("%p %p %p %p", msg, anscb, expirecb, data);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1246
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1247 /* Check the parameters */
824
89c5849b0832 Allow retransmission of messages on timeout
Sebastien Decugis <sdecugis@freediameter.net>
parents: 808
diff changeset
1248 CHECK_PARAMS( CHECK_MSG(msg) );
893
8187364e39ea Fix answers sending
Sebastien Decugis <sdecugis@freediameter.net>
parents: 892
diff changeset
1249
8187364e39ea Fix answers sending
Sebastien Decugis <sdecugis@freediameter.net>
parents: 892
diff changeset
1250 if (! (msg->msg_public.msg_flags & CMD_FLAG_REQUEST ))
1009
e22434c66126 Be more restrictive on fd_msg_send() called with answer messages, the function now rejects the parameters if an answer callback is provided
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1005
diff changeset
1251 return anscb ? EINVAL : 0; /* we associate with requests only */
893
8187364e39ea Fix answers sending
Sebastien Decugis <sdecugis@freediameter.net>
parents: 892
diff changeset
1252
1099
6ce5c99a40af Fix some typos.
Thomas Klausner <tk@giga.or.at>
parents: 1096
diff changeset
1253 CHECK_PARAMS( (anscb == NULL) || (msg->msg_cb.anscb == NULL) ); /* We are not overwriting a cb */
6ce5c99a40af Fix some typos.
Thomas Klausner <tk@giga.or.at>
parents: 1096
diff changeset
1254 CHECK_PARAMS( (expirecb == NULL) || (msg->msg_cb.expirecb == NULL) ); /* We are not overwriting a cb */
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1255
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1256 /* Associate callback and data with the message, if any */
1229
4e52f009861a Fix setting of answer and expiry callbacks.
Thomas Klausner <tk@giga.or.at>
parents: 1212
diff changeset
1257 if (anscb) {
4e52f009861a Fix setting of answer and expiry callbacks.
Thomas Klausner <tk@giga.or.at>
parents: 1212
diff changeset
1258 msg->msg_cb.anscb = anscb;
4e52f009861a Fix setting of answer and expiry callbacks.
Thomas Klausner <tk@giga.or.at>
parents: 1212
diff changeset
1259 msg->msg_cb.data = data;
4e52f009861a Fix setting of answer and expiry callbacks.
Thomas Klausner <tk@giga.or.at>
parents: 1212
diff changeset
1260 }
4e52f009861a Fix setting of answer and expiry callbacks.
Thomas Klausner <tk@giga.or.at>
parents: 1212
diff changeset
1261 if (expirecb) {
4e52f009861a Fix setting of answer and expiry callbacks.
Thomas Klausner <tk@giga.or.at>
parents: 1212
diff changeset
1262 msg->msg_cb.expirecb = expirecb;
1327
82b386714795 Set callback data also when only setting expire callback (and not answer callback as well).
Thomas Klausner <tk@giga.or.at>
parents: 1305
diff changeset
1263 msg->msg_cb.data = data;
1229
4e52f009861a Fix setting of answer and expiry callbacks.
Thomas Klausner <tk@giga.or.at>
parents: 1212
diff changeset
1264 if (timeout) {
4e52f009861a Fix setting of answer and expiry callbacks.
Thomas Klausner <tk@giga.or.at>
parents: 1212
diff changeset
1265 memcpy(&msg->msg_cb.timeout, timeout, sizeof(struct timespec));
4e52f009861a Fix setting of answer and expiry callbacks.
Thomas Klausner <tk@giga.or.at>
parents: 1212
diff changeset
1266 }
646
cfc8da9264f4 Prepared first part of the changes for #10
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 638
diff changeset
1267 }
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1268
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1269 return 0;
1248
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1270 }
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1271
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1272 /* Remove a callback */
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1273 int fd_msg_anscb_reset(struct msg * msg, int clear_anscb, int clear_expirecb)
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1274 {
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1275 TRACE_ENTRY("%p %d %d", msg, clear_anscb, clear_expirecb);
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1276
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1277 /* Check the parameters */
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1278 CHECK_PARAMS( CHECK_MSG(msg) );
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1279
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1280 if (clear_anscb) {
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1281 msg->msg_cb.anscb = NULL;
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1282 msg->msg_cb.data = NULL;
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1283 }
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1284 if (clear_expirecb) {
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1285 msg->msg_cb.expirecb = NULL;
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1286 memset(&msg->msg_cb.timeout, 0, sizeof(struct timespec));
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1287 }
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1288
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1289 return 0;
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1290 }
c9a160b815ea Fix issue with anscb in the p_sr expiry mechanism. Thanks Guangming for the report.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1230
diff changeset
1291
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1292
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1009
diff changeset
1293 int fd_msg_anscb_get( struct msg * msg, void (**anscb)(void *, struct msg **), void (**expirecb)(void *, DiamId_t, size_t, struct msg **), void ** data )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1294 {
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1009
diff changeset
1295 TRACE_ENTRY("%p %p %p %p", msg, anscb, expirecb, data);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1296
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1297 /* Check the parameters */
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1009
diff changeset
1298 CHECK_PARAMS( CHECK_MSG(msg) );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1299
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1300 /* Copy the result */
1014
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1009
diff changeset
1301 if (anscb)
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1009
diff changeset
1302 *anscb = msg->msg_cb.anscb;
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1009
diff changeset
1303 if (data)
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1009
diff changeset
1304 *data = msg->msg_cb.data;
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1009
diff changeset
1305 if (expirecb)
908ffbb81f60 Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1009
diff changeset
1306 *expirecb = msg->msg_cb.expirecb;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1307
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1308 return 0;
649
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 648
diff changeset
1309 }
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 648
diff changeset
1310
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 648
diff changeset
1311 struct timespec *fd_msg_anscb_gettimeout( struct msg * msg )
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 648
diff changeset
1312 {
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 648
diff changeset
1313 TRACE_ENTRY("%p", msg);
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 648
diff changeset
1314
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 648
diff changeset
1315 /* Check the parameters */
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 648
diff changeset
1316 CHECK_PARAMS_DO( CHECK_MSG(msg), return NULL );
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 648
diff changeset
1317
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 648
diff changeset
1318 if (!msg->msg_cb.timeout.tv_sec) {
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 648
diff changeset
1319 return NULL;
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 648
diff changeset
1320 }
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 648
diff changeset
1321
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 648
diff changeset
1322 return &msg->msg_cb.timeout;
5e5d8152c229 Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 648
diff changeset
1323 }
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1324
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1325 /* Associate routing lists */
1212
c38bb8b69c43 Fix message rtd handling for extensions based on this data
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1205
diff changeset
1326 int fd_msg_rt_associate( struct msg * msg, struct rt_data * rtd )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1327 {
83
c662d3eb6ff6 Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
1328 TRACE_ENTRY( "%p %p", msg, rtd );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1329
83
c662d3eb6ff6 Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
1330 CHECK_PARAMS( CHECK_MSG(msg) && rtd );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1331
1212
c38bb8b69c43 Fix message rtd handling for extensions based on this data
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1205
diff changeset
1332 msg->msg_rtdata = rtd;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1333
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1334 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1335 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1336
83
c662d3eb6ff6 Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
1337 int fd_msg_rt_get( struct msg * msg, struct rt_data ** rtd )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1338 {
83
c662d3eb6ff6 Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
1339 TRACE_ENTRY( "%p %p", msg, rtd );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1340
83
c662d3eb6ff6 Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
1341 CHECK_PARAMS( CHECK_MSG(msg) && rtd );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1342
83
c662d3eb6ff6 Started support for routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 37
diff changeset
1343 *rtd = msg->msg_rtdata;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1344
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1345 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1346 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1347
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1348 /* Find if a message is routable */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1349 int fd_msg_is_routable ( struct msg * msg )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1350 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1351 TRACE_ENTRY("%p", msg);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1352
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1353 CHECK_PARAMS_DO( CHECK_MSG(msg), return 0 /* pretend the message is not routable */ );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1354
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1355 if ( ! msg->msg_routable ) {
37
cc3c59fe98fe Lot of cleanups in peer structure management
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 35
diff changeset
1356 /* 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
1357 msg->msg_routable = ((msg->msg_public.msg_appl != 0) || (msg->msg_public.msg_flags & CMD_FLAG_PROXIABLE)) ? 1 : 2;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1358
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1359 /* Note : the 'real' criteria according to the Diameter I-D is that the message is
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1360 routable if and only if the "Destination-Realm" AVP is required by the command ABNF.
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1361 We could make a test for this here, but it's more computational work and our test
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1362 seems accurate (until proven otherwise...) */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1363 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1364
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1365 return (msg->msg_routable == 1) ? 1 : 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1366 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1367
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
1368 /* cache the dictionary model for next function to avoid re-searching at every incoming message */
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
1369 static struct dict_object *cached_avp_rr_model = NULL;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
1370 static struct dictionary *cached_avp_rr_dict = NULL;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
1371 static pthread_mutex_t cached_avp_rr_lock = PTHREAD_MUTEX_INITIALIZER;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
1372
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1373 /* Associate source peer */
1120
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1374 int fd_msg_source_set( struct msg * msg, DiamId_t diamid, size_t diamidlen )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1375 {
1120
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1376 TRACE_ENTRY( "%p %p %zd", msg, diamid, diamidlen);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1377
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1378 /* Check we received a valid message */
1120
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1379 CHECK_PARAMS( CHECK_MSG(msg) );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1380
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1381 /* Cleanup any previous source */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
1382 free(msg->msg_src_id); msg->msg_src_id = NULL; msg->msg_src_id_len = 0;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1383
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1384 /* If the request is to cleanup the source, we are done */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1385 if (diamid == NULL) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1386 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1387 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1388
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1389 /* Otherwise save the new informations */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
1390 CHECK_MALLOC( msg->msg_src_id = os0dup(diamid, diamidlen) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
1391 msg->msg_src_id_len = diamidlen;
1120
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1392 /* done */
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1393 return 0;
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1394 }
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1395
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1396 /* Associate source peer */
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1397 int fd_msg_source_setrr( struct msg * msg, DiamId_t diamid, size_t diamidlen, struct dictionary * dict )
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1398 {
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1399 struct dict_object *avp_rr_model = NULL;
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1400 avp_code_t code = AC_ROUTE_RECORD;
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1401 struct avp *avp;
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1402 union avp_value val;
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1403
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1404 TRACE_ENTRY( "%p %p %zd %p", msg, diamid, diamidlen, dict);
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
1405
1120
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1406 /* Check we received a valid message */
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1407 CHECK_PARAMS( CHECK_MSG(msg) && dict );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1408
1120
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1409 /* Lock the cached values */
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1410 CHECK_POSIX( pthread_mutex_lock(&cached_avp_rr_lock) );
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1411 if (cached_avp_rr_dict == dict) {
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1412 avp_rr_model = cached_avp_rr_model;
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1413 }
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1414 CHECK_POSIX( pthread_mutex_unlock(&cached_avp_rr_lock) );
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1415
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1416 /* If it was not cached */
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1417 if (!avp_rr_model) {
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1418 /* Find the model for Route-Record in the dictionary */
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1419 CHECK_FCT( fd_dict_search ( dict, DICT_AVP, AVP_BY_CODE, &code, &avp_rr_model, ENOENT) );
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1420
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1421 /* Now cache this result */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
1422 CHECK_POSIX( pthread_mutex_lock(&cached_avp_rr_lock) );
1120
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1423 cached_avp_rr_dict = dict;
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1424 cached_avp_rr_model = avp_rr_model;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
1425 CHECK_POSIX( pthread_mutex_unlock(&cached_avp_rr_lock) );
1120
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1426 }
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1427
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1428 /* Create the AVP with this model */
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1429 CHECK_FCT( fd_msg_avp_new ( avp_rr_model, 0, &avp ) );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1430
1120
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1431 /* Set the AVP value with the diameter id */
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1432 memset(&val, 0, sizeof(val));
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1433 val.os.data = (uint8_t *)diamid;
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1434 val.os.len = diamidlen;
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1435 CHECK_FCT( fd_msg_avp_setvalue( avp, &val ) );
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1436
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1437 /* Add the AVP in the message */
c473581adff2 Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
1438 CHECK_FCT( fd_msg_avp_add( msg, MSG_BRW_LAST_CHILD, avp ) );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1439
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1440 /* done */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1441 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1442 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1443
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
1444 int fd_msg_source_get( struct msg * msg, DiamId_t* diamid, size_t * diamidlen )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1445 {
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
1446 TRACE_ENTRY( "%p %p %p", msg, diamid, diamidlen);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1447
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1448 /* Check we received valid parameters */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1449 CHECK_PARAMS( CHECK_MSG(msg) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1450 CHECK_PARAMS( diamid );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1451
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1452 /* Copy the informations */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1453 *diamid = msg->msg_src_id;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1454
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
1455 if (diamidlen)
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
1456 *diamidlen = msg->msg_src_id_len;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 704
diff changeset
1457
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1458 /* done */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1459 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1460 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1461
924
877592751fee Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents: 920
diff changeset
1462 /* Associate a session with a message, use only when the session was just created */
877592751fee Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents: 920
diff changeset
1463 int fd_msg_sess_set(struct msg * msg, struct session * session)
877592751fee Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents: 920
diff changeset
1464 {
877592751fee Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents: 920
diff changeset
1465 TRACE_ENTRY("%p %p", msg, session);
877592751fee Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents: 920
diff changeset
1466
877592751fee Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents: 920
diff changeset
1467 /* Check we received valid parameters */
877592751fee Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents: 920
diff changeset
1468 CHECK_PARAMS( CHECK_MSG(msg) );
877592751fee Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents: 920
diff changeset
1469 CHECK_PARAMS( session );
877592751fee Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents: 920
diff changeset
1470 CHECK_PARAMS( msg->msg_sess == NULL );
877592751fee Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents: 920
diff changeset
1471
877592751fee Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents: 920
diff changeset
1472 msg->msg_sess = session;
877592751fee Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents: 920
diff changeset
1473 return 0;
877592751fee Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents: 920
diff changeset
1474 }
877592751fee Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents: 920
diff changeset
1475
895
fbf77629cb7b Added received and sent timestamps in the messages; added logs on emission and reception
Sebastien Decugis <sdecugis@freediameter.net>
parents: 894
diff changeset
1476
85
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1477 /* 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
1478 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
1479 {
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1480 struct avp * avp;
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1481
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1482 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
1483
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1484 /* Check we received valid parameters */
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1485 CHECK_PARAMS( CHECK_MSG(msg) );
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1486 CHECK_PARAMS( session );
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1487
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1488 /* 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
1489 if (msg->msg_sess) {
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1490 *session = msg->msg_sess;
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1491 if (new)
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1492 *new = 0;
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1493 return 0;
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1494 }
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1495
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1496 /* 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
1497 /* -- 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
1498 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
1499 while (avp) {
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1500 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
1501 && (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
1502 break;
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1503
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1504 /* 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
1505 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
1506 }
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1507
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1508 if (!avp) {
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1509 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
1510 *session = NULL;
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1511 return 0;
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1512 }
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1513
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1514 if (!avp->avp_model) {
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
1515 CHECK_FCT( fd_msg_parse_dict ( avp, dict, NULL ) );
85
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1516 }
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1517
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1518 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
1519
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1520 /* Resolve the session and we are done */
919
b1776283d69e Do not kill framework when a message with 0b session-id is dispatched
Sebastien Decugis <sdecugis@freediameter.net>
parents: 916
diff changeset
1521 if (avp->avp_public.avp_value->os.len > 0) {
b1776283d69e Do not kill framework when a message with 0b session-id is dispatched
Sebastien Decugis <sdecugis@freediameter.net>
parents: 916
diff changeset
1522 CHECK_FCT( fd_sess_fromsid_msg ( avp->avp_public.avp_value->os.data, avp->avp_public.avp_value->os.len, &msg->msg_sess, new) );
b1776283d69e Do not kill framework when a message with 0b session-id is dispatched
Sebastien Decugis <sdecugis@freediameter.net>
parents: 916
diff changeset
1523 *session = msg->msg_sess;
b1776283d69e Do not kill framework when a message with 0b session-id is dispatched
Sebastien Decugis <sdecugis@freediameter.net>
parents: 916
diff changeset
1524 } else {
b1776283d69e Do not kill framework when a message with 0b session-id is dispatched
Sebastien Decugis <sdecugis@freediameter.net>
parents: 916
diff changeset
1525 TRACE_DEBUG(FULL, "Session-Id AVP with 0-byte length found in message %p", msg);
b1776283d69e Do not kill framework when a message with 0b session-id is dispatched
Sebastien Decugis <sdecugis@freediameter.net>
parents: 916
diff changeset
1526 *session = NULL;
b1776283d69e Do not kill framework when a message with 0b session-id is dispatched
Sebastien Decugis <sdecugis@freediameter.net>
parents: 916
diff changeset
1527 }
85
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1528
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1529 return 0;
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1530 }
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1531
1098
f38d77f9cfd3 Initial implementation of the hook mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1096
diff changeset
1532 /* Retrieve the location of the pmd list for the message; return NULL if failed */
f38d77f9cfd3 Initial implementation of the hook mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1096
diff changeset
1533 struct fd_msg_pmdl * fd_msg_pmdl_get(struct msg * msg)
f38d77f9cfd3 Initial implementation of the hook mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1096
diff changeset
1534 {
f38d77f9cfd3 Initial implementation of the hook mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1096
diff changeset
1535 CHECK_PARAMS_DO( CHECK_MSG(msg), return NULL );
f38d77f9cfd3 Initial implementation of the hook mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1096
diff changeset
1536 return &msg->msg_pmdl;
f38d77f9cfd3 Initial implementation of the hook mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1096
diff changeset
1537 }
f38d77f9cfd3 Initial implementation of the hook mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1096
diff changeset
1538
85
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 83
diff changeset
1539
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1540 /******************* End-to-end counter *********************/
686
f83d9878bf66 Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 658
diff changeset
1541 static uint32_t fd_eteid;
f83d9878bf66 Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 658
diff changeset
1542 static pthread_mutex_t fd_eteid_lck = PTHREAD_MUTEX_INITIALIZER;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1543
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1544 void fd_msg_eteid_init(void)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1545 {
1125
98d1ad9bf85a Fix initialization of random number; Cleanup the dump message display
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1121
diff changeset
1546 uint32_t t = (uint32_t)time(NULL);
98d1ad9bf85a Fix initialization of random number; Cleanup the dump message display
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1121
diff changeset
1547 srand48(t);
98d1ad9bf85a Fix initialization of random number; Cleanup the dump message display
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1121
diff changeset
1548 fd_eteid = (t << 20) | ((uint32_t)lrand48() & ( (1 << 20) - 1 ));
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1549 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1550
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1551 uint32_t fd_msg_eteid_get ( void )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1552 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1553 uint32_t ret;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1554
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1555 CHECK_POSIX_DO( pthread_mutex_lock(&fd_eteid_lck), /* continue */ );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1556
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1557 ret = fd_eteid ++;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1558
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1559 CHECK_POSIX_DO( pthread_mutex_unlock(&fd_eteid_lck), /* continue */ );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1560
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1561 return ret;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1562 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1563
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1564 /***************************************************************************************************************/
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1565 /* Manage AVPs values */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1566
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1567 /* Set the value of an AVP */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1568 int fd_msg_avp_setvalue ( struct avp *avp, union avp_value *value )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1569 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1570 enum dict_avp_basetype type = -1;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1571
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1572 TRACE_ENTRY("%p %p", avp, value);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1573
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1574 /* Check parameter */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1575 CHECK_PARAMS( CHECK_AVP(avp) && avp->avp_model );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1576
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1577 /* Retrieve information from the AVP model */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1578 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1579 enum dict_object_type dicttype;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1580 struct dict_avp_data dictdata;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1581
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1582 CHECK_PARAMS( (fd_dict_gettype(avp->avp_model, &dicttype) == 0) && (dicttype == DICT_AVP) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1583 CHECK_FCT( fd_dict_getval(avp->avp_model, &dictdata) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1584 type = dictdata.avp_basetype;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1585 CHECK_PARAMS( type != AVP_TYPE_GROUPED );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1586 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1587
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1588 /* First, clean any previous value */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1589 if (avp->avp_mustfreeos != 0) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1590 free(avp->avp_storage.os.data);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1591 avp->avp_mustfreeos = 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1592 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1593
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1594 memset(&avp->avp_storage, 0, sizeof(union avp_value));
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1595
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1596 /* If the request was to delete a value: */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1597 if (!value) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1598 avp->avp_public.avp_value = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1599 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1600 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1601
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1602 /* Now we have to set the value */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1603 memcpy(&avp->avp_storage, value, sizeof(union avp_value));
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1604
730
e21d79595045 minor improvements
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 720
diff changeset
1605 /* Duplicate an octetstring if needed. */
387
743195485eec Additional fixes for empty octet string AVPs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 386
diff changeset
1606 if (type == AVP_TYPE_OCTETSTRING) {
753
71833fa5e35f allow applications to create empty AVP also
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 752
diff changeset
1607 CHECK_MALLOC( avp->avp_storage.os.data = os0dup(value->os.data, value->os.len) );
71833fa5e35f allow applications to create empty AVP also
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 752
diff changeset
1608 avp->avp_mustfreeos = 1;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1609 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1610
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1611 /* Set the data pointer of the public part */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1612 avp->avp_public.avp_value = &avp->avp_storage;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1613
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1614 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1615 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1616
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1617 /* Set the value of an AVP, using formatted data */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1618 int fd_msg_avp_value_encode ( void *data, struct avp *avp )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1619 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1620 enum dict_avp_basetype type = -1;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1621 struct dict_type_data type_data;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1622
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1623 TRACE_ENTRY("%p %p", data, avp);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1624
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1625 /* Check parameter */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1626 CHECK_PARAMS( CHECK_AVP(avp) && avp->avp_model );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1627
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1628 /* Retrieve information from the AVP model and it's parent type */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1629 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1630 enum dict_object_type dicttype;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1631 struct dict_avp_data dictdata;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1632 struct dictionary * dict;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1633 struct dict_object * parenttype = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1634
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1635 /* First check the base type of the AVP */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1636 CHECK_PARAMS( (fd_dict_gettype(avp->avp_model, &dicttype) == 0) && (dicttype == DICT_AVP) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1637 CHECK_FCT( fd_dict_getval(avp->avp_model, &dictdata) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1638 type = dictdata.avp_basetype;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1639 CHECK_PARAMS( type != AVP_TYPE_GROUPED );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1640
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1641 /* Then retrieve information about the parent's type (= derived type) */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1642 CHECK_FCT( fd_dict_getdict( avp->avp_model, &dict ) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1643 CHECK_FCT( fd_dict_search( dict, DICT_TYPE, TYPE_OF_AVP, avp->avp_model, &parenttype, EINVAL) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1644 CHECK_FCT( fd_dict_getval(parenttype, &type_data) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1645 if (type_data.type_encode == NULL) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1646 TRACE_DEBUG(INFO, "This AVP type does not provide a callback to encode formatted data. ENOTSUP.");
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1647 return ENOTSUP;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1648 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1649 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1650
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1651 /* Ok, now we can encode the value */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1652
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1653 /* First, clean any previous value */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1654 if (avp->avp_mustfreeos != 0) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1655 free(avp->avp_storage.os.data);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1656 avp->avp_mustfreeos = 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1657 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1658 avp->avp_public.avp_value = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1659 memset(&avp->avp_storage, 0, sizeof(union avp_value));
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1660
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1661 /* Now call the type's callback to encode the data */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1662 CHECK_FCT( (*type_data.type_encode)(data, &avp->avp_storage) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1663
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1664 /* If an octetstring has been allocated, let's mark it to be freed */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1665 if (type == AVP_TYPE_OCTETSTRING)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1666 avp->avp_mustfreeos = 1;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1667
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1668 /* Set the data pointer of the public part */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1669 avp->avp_public.avp_value = &avp->avp_storage;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1670
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1671 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1672 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1673
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1674 /* Interpret the value of an AVP into formatted data */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1675 int fd_msg_avp_value_interpret ( struct avp *avp, void *data )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1676 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1677 struct dict_type_data type_data;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1678
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1679 TRACE_ENTRY("%p %p", avp, data);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1680
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1681 /* Check parameter */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1682 CHECK_PARAMS( CHECK_AVP(avp) && avp->avp_model && avp->avp_public.avp_value );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1683
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1684 /* Retrieve information about the AVP parent type */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1685 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1686 struct dictionary * dict;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1687 struct dict_object * parenttype = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1688
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1689 CHECK_FCT( fd_dict_getdict( avp->avp_model, &dict ) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1690 CHECK_FCT( fd_dict_search( dict, DICT_TYPE, TYPE_OF_AVP, avp->avp_model, &parenttype, EINVAL) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1691 CHECK_FCT( fd_dict_getval(parenttype, &type_data) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1692 if (type_data.type_interpret == NULL) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1693 TRACE_DEBUG(INFO, "This AVP type does not provide a callback to interpret value in formatted data. ENOTSUP.");
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1694 return ENOTSUP;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1695 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1696 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1697
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1698 /* Ok, now we can interpret the value */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1699
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1700 CHECK_FCT( (*type_data.type_interpret)(avp->avp_public.avp_value, data) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1701
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1702 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1703 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1704
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1705 /***************************************************************************************************************/
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1706 /* Creating a buffer from memory objects (bufferize a struct msg) */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1707
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1708 /* Following macros are used to store 32 and 64 bit fields into a buffer in network byte order */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1709 #define PUT_in_buf_32( _u32data, _bufptr ) { \
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1710 *(uint32_t *)(_bufptr) = htonl((uint32_t)(_u32data)); \
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1711 }
791
42fa209a8cc4 Attempt at fixing unaligned 64b direct memory access (sigbus on sparc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 765
diff changeset
1712
42fa209a8cc4 Attempt at fixing unaligned 64b direct memory access (sigbus on sparc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 765
diff changeset
1713 /* The location is not on 64b boundary, so we split the writing in two operations to avoid sigbus */
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1714 #define PUT_in_buf_64( _u64data, _bufptr ) { \
791
42fa209a8cc4 Attempt at fixing unaligned 64b direct memory access (sigbus on sparc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 765
diff changeset
1715 uint64_t __v = htonll((uint64_t)(_u64data)); \
792
0f566e550813 improved the previous fix... not sure it was correct
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 791
diff changeset
1716 memcpy(_bufptr, &__v, sizeof(__v)); \
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1717 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1718
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1719 /* Write a message header in the buffer */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1720 static int bufferize_msg(unsigned char * buffer, size_t buflen, size_t * offset, struct msg * msg)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1721 {
1027
0117a7746b21 Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1014
diff changeset
1722 TRACE_ENTRY("%p %zd %p %p", buffer, buflen, offset, msg);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1723
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1724 if ((buflen - *offset) < GETMSGHDRSZ())
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1725 return ENOSPC;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1726
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1727 if (*offset & 0x3)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1728 return EFAULT; /* We are supposed to start on 32 bit boundaries */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1729
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1730 PUT_in_buf_32(msg->msg_public.msg_length, buffer + *offset);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1731 buffer[*offset] = msg->msg_public.msg_version;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1732 *offset += 4;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1733
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1734 PUT_in_buf_32(msg->msg_public.msg_code, buffer + *offset);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1735 buffer[*offset] = msg->msg_public.msg_flags;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1736 *offset += 4;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1737
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1738 PUT_in_buf_32(msg->msg_public.msg_appl, buffer + *offset);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1739 *offset += 4;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1740
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1741 PUT_in_buf_32(msg->msg_public.msg_hbhid, buffer + *offset);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1742 *offset += 4;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1743
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1744 PUT_in_buf_32(msg->msg_public.msg_eteid, buffer + *offset);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1745 *offset += 4;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1746
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1747 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1748 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1749
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1750 static int bufferize_chain(unsigned char * buffer, size_t buflen, size_t * offset, struct fd_list * list);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1751
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1752 /* Write an AVP in the buffer */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1753 static int bufferize_avp(unsigned char * buffer, size_t buflen, size_t * offset, struct avp * avp)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1754 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1755 struct dict_avp_data dictdata;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1756
1027
0117a7746b21 Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1014
diff changeset
1757 TRACE_ENTRY("%p %zd %p %p", buffer, buflen, offset, avp);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1758
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1759 if ((buflen - *offset) < avp->avp_public.avp_len)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1760 return ENOSPC;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1761
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1762 /* Write the header */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1763 PUT_in_buf_32(avp->avp_public.avp_code, buffer + *offset);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1764 *offset += 4;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1765
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1766 PUT_in_buf_32(avp->avp_public.avp_len, buffer + *offset);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1767 buffer[*offset] = avp->avp_public.avp_flags;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1768 *offset += 4;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1769
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1770 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1771 PUT_in_buf_32(avp->avp_public.avp_vendor, buffer + *offset);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1772 *offset += 4;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1773 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1774
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1775 /* Then we must write the AVP value */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1776
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1777 if (avp->avp_model == NULL) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1778 /* In the case where we don't know the type of AVP, just copy the raw data or source */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1779 CHECK_PARAMS( avp->avp_source || avp->avp_rawdata );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1780
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
1781 if ( avp->avp_rawdata != NULL ) {
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
1782 /* the content was stored in rawdata */
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
1783 memcpy(&buffer[*offset], avp->avp_rawdata, avp->avp_rawlen);
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
1784 *offset += PAD4(avp->avp_rawlen);
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
1785 } else {
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1786 /* the message was not parsed completely */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1787 size_t datalen = avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1788 memcpy(&buffer[*offset], avp->avp_source, datalen);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1789 *offset += PAD4(datalen);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1790 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1791
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1792 } else {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1793 /* The AVP is defined in the dictionary */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1794 CHECK_FCT( fd_dict_getval(avp->avp_model, &dictdata) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1795
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1796 CHECK_PARAMS( ( dictdata.avp_basetype == AVP_TYPE_GROUPED ) || avp->avp_public.avp_value );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1797
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1798 switch (dictdata.avp_basetype) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1799 case AVP_TYPE_GROUPED:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1800 return bufferize_chain(buffer, buflen, offset, &avp->avp_chain.children);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1801
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1802 case AVP_TYPE_OCTETSTRING:
387
743195485eec Additional fixes for empty octet string AVPs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 386
diff changeset
1803 if (avp->avp_public.avp_value->os.len)
743195485eec Additional fixes for empty octet string AVPs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 386
diff changeset
1804 memcpy(&buffer[*offset], avp->avp_public.avp_value->os.data, avp->avp_public.avp_value->os.len);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1805 *offset += PAD4(avp->avp_public.avp_value->os.len);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1806 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1807
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1808 case AVP_TYPE_INTEGER32:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1809 PUT_in_buf_32(avp->avp_public.avp_value->i32, buffer + *offset);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1810 *offset += 4;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1811 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1812
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1813 case AVP_TYPE_INTEGER64:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1814 PUT_in_buf_64(avp->avp_public.avp_value->i64, buffer + *offset);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1815 *offset += 8;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1816 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1817
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1818 case AVP_TYPE_UNSIGNED32:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1819 PUT_in_buf_32(avp->avp_public.avp_value->u32, buffer + *offset);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1820 *offset += 4;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1821 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1822
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1823 case AVP_TYPE_UNSIGNED64:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1824 PUT_in_buf_64(avp->avp_public.avp_value->u64, buffer + *offset);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1825 *offset += 8;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1826 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1827
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1828 case AVP_TYPE_FLOAT32:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1829 /* We read the f32 as "u32" here to avoid casting to uint make decimals go away.
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1830 The alternative would be something like "*(uint32_t *)(& f32)" but
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1831 then the compiler complains about strict-aliasing rules. */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1832 PUT_in_buf_32(avp->avp_public.avp_value->u32, buffer + *offset);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1833 *offset += 4;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1834 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1835
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1836 case AVP_TYPE_FLOAT64:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1837 /* Same remark as previously */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1838 PUT_in_buf_64(avp->avp_public.avp_value->u64, buffer + *offset);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1839 *offset += 8;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1840 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1841
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1842 default:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1843 ASSERT(0);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1844 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1845 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1846 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1847 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1848
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1849 /* Write a chain of AVPs in the buffer */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1850 static int bufferize_chain(unsigned char * buffer, size_t buflen, size_t * offset, struct fd_list * list)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1851 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1852 struct fd_list * avpch;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1853
1027
0117a7746b21 Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1014
diff changeset
1854 TRACE_ENTRY("%p %zd %p %p", buffer, buflen, offset, list);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1855
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1856 for (avpch = list->next; avpch != list; avpch = avpch->next) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1857 /* Bufferize the AVP */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1858 CHECK_FCT( bufferize_avp(buffer, buflen, offset, _A(avpch->o)) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1859 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1860 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1861 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1862
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1863 /* Create the message buffer, in network-byte order. We browse the tree twice, this could be probably improved if needed */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1864 int fd_msg_bufferize ( struct msg * msg, unsigned char ** buffer, size_t * len )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1865 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1866 int ret = 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1867 unsigned char * buf = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1868 size_t offset = 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1869
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1870 TRACE_ENTRY("%p %p %p", msg, buffer, len);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1871
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1872 /* Check the parameters */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1873 CHECK_PARAMS( buffer && CHECK_MSG(msg) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1874
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1875 /* Update the length. This also checks that all AVP have their values set */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1876 CHECK_FCT( fd_msg_update_length(msg) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1877
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1878 /* Now allocate a buffer to store the message */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1879 CHECK_MALLOC( buf = malloc(msg->msg_public.msg_length) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1880
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1881 /* Clear the memory, so that the padding is always 0 (should not matter) */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1882 memset(buf, 0, msg->msg_public.msg_length);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1883
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1884 /* Write the message header in the buffer */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1885 CHECK_FCT_DO( ret = bufferize_msg(buf, msg->msg_public.msg_length, &offset, msg),
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1886 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1887 free(buf);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1888 return ret;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1889 } );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1890
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1891 /* Write the list of AVPs */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1892 CHECK_FCT_DO( ret = bufferize_chain(buf, msg->msg_public.msg_length, &offset, &msg->msg_chain.children),
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1893 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1894 free(buf);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1895 return ret;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1896 } );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1897
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1898 ASSERT(offset == msg->msg_public.msg_length); /* or the msg_update_length is buggy */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1899
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1900 if (len) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1901 *len = offset;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1902 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1903
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1904 *buffer = buf;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1905 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1906 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1907
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1908
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1909 /***************************************************************************************************************/
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1910 /* Parsing buffers and building AVP objects lists (not parsing the AVP values which requires dictionary knowledge) */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1911
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1912 /* Parse a buffer containing a supposed list of AVPs */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1913 static int parsebuf_list(unsigned char * buf, size_t buflen, struct fd_list * head)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1914 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1915 size_t offset = 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1916
1027
0117a7746b21 Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1014
diff changeset
1917 TRACE_ENTRY("%p %zd %p", buf, buflen, head);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1918
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1919 while (offset < buflen) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1920 struct avp * avp;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1921
920
cb439d57d0c5 Fix parsing of incoming AVPs with 0-byte length at the end of the message
Sebastien Decugis <sdecugis@freediameter.net>
parents: 919
diff changeset
1922 if (buflen - offset < AVPHDRSZ_NOVEND) {
1027
0117a7746b21 Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1014
diff changeset
1923 TRACE_DEBUG(INFO, "truncated buffer: remaining only %zd bytes", buflen - offset);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1924 return EBADMSG;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1925 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1926
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1927 /* Create a new AVP object */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1928 CHECK_MALLOC( avp = malloc (sizeof(struct avp)) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1929
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1930 init_avp(avp);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1931
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1932 /* Initialize the header */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1933 avp->avp_public.avp_code = ntohl(*(uint32_t *)(buf + offset));
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1934 avp->avp_public.avp_flags = buf[offset + 4];
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1935 avp->avp_public.avp_len = ((uint32_t)buf[offset+5]) << 16 | ((uint32_t)buf[offset+6]) << 8 | ((uint32_t)buf[offset+7]) ;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1936
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1937 offset += 8;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1938
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1939 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) {
920
cb439d57d0c5 Fix parsing of incoming AVPs with 0-byte length at the end of the message
Sebastien Decugis <sdecugis@freediameter.net>
parents: 919
diff changeset
1940 if (buflen - offset < 4) {
1027
0117a7746b21 Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1014
diff changeset
1941 TRACE_DEBUG(INFO, "truncated buffer: remaining only %zd bytes for vendor and data", buflen - offset);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1942 free(avp);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1943 return EBADMSG;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1944 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1945 avp->avp_public.avp_vendor = ntohl(*(uint32_t *)(buf + offset));
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1946 offset += 4;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1947 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1948
1403
6a35c5470ef4 Security fix: check invalid incoming data
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1327
diff changeset
1949 /* Check the length is valid */
6a35c5470ef4 Security fix: check invalid incoming data
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1327
diff changeset
1950 if ( avp->avp_public.avp_len < GETAVPHDRSZ(avp->avp_public.avp_flags) ) {
6a35c5470ef4 Security fix: check invalid incoming data
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1327
diff changeset
1951 TRACE_DEBUG(INFO, "Invalid AVP size %d",
6a35c5470ef4 Security fix: check invalid incoming data
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1327
diff changeset
1952 avp->avp_public.avp_len);
6a35c5470ef4 Security fix: check invalid incoming data
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1327
diff changeset
1953 free(avp);
6a35c5470ef4 Security fix: check invalid incoming data
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1327
diff changeset
1954 return EBADMSG;
6a35c5470ef4 Security fix: check invalid incoming data
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1327
diff changeset
1955 }
6a35c5470ef4 Security fix: check invalid incoming data
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1327
diff changeset
1956
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1957 /* Check there is enough remaining data in the buffer */
920
cb439d57d0c5 Fix parsing of incoming AVPs with 0-byte length at the end of the message
Sebastien Decugis <sdecugis@freediameter.net>
parents: 919
diff changeset
1958 if ( (avp->avp_public.avp_len > GETAVPHDRSZ(avp->avp_public.avp_flags))
cb439d57d0c5 Fix parsing of incoming AVPs with 0-byte length at the end of the message
Sebastien Decugis <sdecugis@freediameter.net>
parents: 919
diff changeset
1959 && (buflen - offset < avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags))) {
1027
0117a7746b21 Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1014
diff changeset
1960 TRACE_DEBUG(INFO, "truncated buffer: remaining only %zd bytes for data, and avp data size is %d",
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1961 buflen - offset,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1962 avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags));
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1963 free(avp);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1964 return EBADMSG;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1965 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1966
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1967 /* buf[offset] is now the beginning of the data */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1968 avp->avp_source = &buf[offset];
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1969
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1970 /* Now eat the data and eventual padding */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1971 offset += PAD4(avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags));
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1972
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1973 /* And insert this avp in the list, at the end */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1974 fd_list_insert_before( head, &avp->avp_chain.chaining );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1975 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1976
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1977 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1978 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1979
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1980 /* Create a message object from a buffer. Dictionary objects are not resolved, AVP contents are not interpreted, buffer is saved in msg */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1981 int fd_msg_parse_buffer ( unsigned char ** buffer, size_t buflen, struct msg ** msg )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1982 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1983 struct msg * new = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1984 int ret = 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1985 uint32_t msglen = 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1986 unsigned char * buf;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1987
1027
0117a7746b21 Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1014
diff changeset
1988 TRACE_ENTRY("%p %zd %p", buffer, buflen, msg);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1989
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1990 CHECK_PARAMS( buffer && *buffer && msg && (buflen >= GETMSGHDRSZ()) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1991 buf = *buffer;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1992
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1993 if ( buf[0] != DIAMETER_VERSION) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1994 TRACE_DEBUG(INFO, "Invalid version in message: %d (supported: %d)", buf[0], DIAMETER_VERSION);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1995 return EBADMSG;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1996 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1997
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1998 msglen = ntohl(*(uint32_t *)buf) & 0x00ffffff;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1999 if ( buflen < msglen ) {
1027
0117a7746b21 Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1014
diff changeset
2000 TRACE_DEBUG(INFO, "Truncated message (%zd / %d)", buflen, msglen );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2001 return EBADMSG;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2002 }
1403
6a35c5470ef4 Security fix: check invalid incoming data
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1327
diff changeset
2003 if ( msglen < GETMSGHDRSZ() ) {
6a35c5470ef4 Security fix: check invalid incoming data
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1327
diff changeset
2004 TRACE_DEBUG(INFO, "Invalid message length (%d)", msglen );
6a35c5470ef4 Security fix: check invalid incoming data
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1327
diff changeset
2005 return EBADMSG;
6a35c5470ef4 Security fix: check invalid incoming data
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1327
diff changeset
2006 }
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2007
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2008 /* Create a new object */
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1101
diff changeset
2009 CHECK_MALLOC( new = malloc (sizeof(struct msg)) );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2010
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2011 /* Initialize the fields */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2012 init_msg(new);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2013
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2014 /* Now read from the buffer */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2015 new->msg_public.msg_version = buf[0];
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2016 new->msg_public.msg_length = msglen;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2017
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2018 new->msg_public.msg_flags = buf[4];
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2019 new->msg_public.msg_code = ntohl(*(uint32_t *)(buf+4)) & 0x00ffffff;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2020
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2021 new->msg_public.msg_appl = ntohl(*(uint32_t *)(buf+8));
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2022 new->msg_public.msg_hbhid = ntohl(*(uint32_t *)(buf+12));
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2023 new->msg_public.msg_eteid = ntohl(*(uint32_t *)(buf+16));
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2024
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2025 /* Parse the AVP list */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2026 CHECK_FCT_DO( ret = parsebuf_list(buf + GETMSGHDRSZ(), buflen - GETMSGHDRSZ(), &new->msg_chain.children), { destroy_tree(_C(new)); return ret; } );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2027
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1101
diff changeset
2028 /* Parsing successful */
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1101
diff changeset
2029 new->msg_rawbuffer = buf;
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1101
diff changeset
2030 *buffer = NULL;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2031 *msg = new;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2032 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2033 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2034
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2035
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2036 /***************************************************************************************************************/
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2037 /* Parsing messages and AVP with dictionary information */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2038
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2039 /* Resolve dictionary objects of the cmd and avp instances, from their headers.
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2040 * When the model is found, the data is interpreted from the avp_source buffer and copied to avp_storage.
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2041 * When the model is not found, the data is copied as rawdata and saved (in case we FW the message).
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2042 * Therefore, after this function has been called, the source buffer can be freed.
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2043 * For command, if the dictionary model is not found, an error is returned.
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2044 */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2045
889
4a299daed8b2 Add information about parsing errors
Sebastien Decugis <sdecugis@freediameter.net>
parents: 871
diff changeset
2046 static char error_message[256];
4a299daed8b2 Add information about parsing errors
Sebastien Decugis <sdecugis@freediameter.net>
parents: 871
diff changeset
2047
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2048 /* Process an AVP. If we are not in recheck, the avp_source must be set. */
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2049 static int parsedict_do_avp(struct dictionary * dict, struct avp * avp, int mandatory, struct fd_pei *error_info)
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2050 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2051 struct dict_avp_data dictdata;
1300
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2052 struct dict_type_data derivedtypedata;
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2053 struct dict_object * avp_derived_type = NULL;
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
2054 uint8_t * source;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2055
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2056 TRACE_ENTRY("%p %p %d %p", dict, avp, mandatory, error_info);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2057
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2058 /* First check we received an AVP as input */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2059 CHECK_PARAMS( CHECK_AVP(avp) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2060
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2061 if (avp->avp_model != NULL) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2062 /* the model has already been resolved. we do check it is still valid */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2063
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2064 CHECK_FCT( fd_dict_getval(avp->avp_model, &dictdata) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2065
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2066 if ( avp->avp_public.avp_code == dictdata.avp_code ) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2067 /* Ok then just process the children if any */
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2068 return parsedict_do_chain(dict, &avp->avp_chain.children, mandatory && (avp->avp_public.avp_flags & AVP_FLAG_MANDATORY), error_info);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2069 } else {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2070 /* We just erase the old model */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2071 avp->avp_model = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2072 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2073 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2074
1092
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2075 /* Check if we already searched for this model without success */
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2076 if ((avp->avp_model_not_found.mnf_code != avp->avp_public.avp_code)
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2077 || (avp->avp_model_not_found.mnf_vendor != avp->avp_public.avp_vendor)) {
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2078
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2079 /* Now try and resolve the model from the avp code and vendor */
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2080 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) {
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2081 struct dict_avp_request_ex avpreq;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2082 memset(&avpreq, 0, sizeof(avpreq));
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2083 avpreq.avp_vendor.vendor_id = avp->avp_public.avp_vendor;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2084 avpreq.avp_data.avp_code = avp->avp_public.avp_code;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2085 CHECK_FCT( fd_dict_search ( dict, DICT_AVP, AVP_BY_STRUCT, &avpreq, &avp->avp_model, 0));
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2086 } else {
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2087 /* no vendor */
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2088 CHECK_FCT( fd_dict_search ( dict, DICT_AVP, AVP_BY_CODE, &avp->avp_public.avp_code, &avp->avp_model, 0));
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2089 }
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2090
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2091 if (!avp->avp_model) {
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2092 avp->avp_model_not_found.mnf_code = avp->avp_public.avp_code;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2093 avp->avp_model_not_found.mnf_vendor = avp->avp_public.avp_vendor;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2094 }
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2095 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2096
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2097 /* First handle the case where we have not found this AVP in the dictionary */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2098 if (!avp->avp_model) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2099
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2100 if (mandatory && (avp->avp_public.avp_flags & AVP_FLAG_MANDATORY)) {
1119
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
2101 TRACE_DEBUG(INFO, "Unsupported mandatory AVP found");
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2102 if (error_info) {
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2103 error_info->pei_errcode = "DIAMETER_AVP_UNSUPPORTED";
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2104 error_info->pei_avp = avp;
1119
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
2105 } else {
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
2106 char * buf = NULL;
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
2107 size_t buflen;
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
2108 CHECK_MALLOC(fd_msg_dump_treeview(&buf, &buflen, NULL, avp, NULL, 0, 0));
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
2109 LOG_E("Unsupported AVP: %s", buf);
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
2110 free(buf);
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2111 }
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2112 return ENOTSUP;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2113 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2114
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2115 if (avp->avp_source) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2116 /* we must copy the data from the source to the internal buffer area */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2117 CHECK_PARAMS( !avp->avp_rawdata );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2118
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2119 avp->avp_rawlen = avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2120
387
743195485eec Additional fixes for empty octet string AVPs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 386
diff changeset
2121 if (avp->avp_rawlen) {
743195485eec Additional fixes for empty octet string AVPs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 386
diff changeset
2122 CHECK_MALLOC( avp->avp_rawdata = malloc(avp->avp_rawlen) );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2123
387
743195485eec Additional fixes for empty octet string AVPs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 386
diff changeset
2124 memcpy(avp->avp_rawdata, avp->avp_source, avp->avp_rawlen);
743195485eec Additional fixes for empty octet string AVPs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 386
diff changeset
2125 }
743195485eec Additional fixes for empty octet string AVPs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 386
diff changeset
2126
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2127 avp->avp_source = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2128
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2129 TRACE_DEBUG(FULL, "Unsupported optional AVP found, raw source data saved in avp_rawdata.");
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2130 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2131
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2132 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2133 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2134
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2135 /* Ok we have resolved the object. Now we need to interpret its content. */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2136
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2137 CHECK_FCT( fd_dict_getval(avp->avp_model, &dictdata) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2138
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2139 if (avp->avp_rawdata) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2140 /* This happens if the dictionary object was defined after the first check */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2141 avp->avp_source = avp->avp_rawdata;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2142 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2143
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2144 /* A bit of sanity here... */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2145 ASSERT(CHECK_BASETYPE(dictdata.avp_basetype));
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2146
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2147 /* Check the size is valid */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2148 if ((avp_value_sizes[dictdata.avp_basetype] != 0) &&
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2149 (avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags ) != avp_value_sizes[dictdata.avp_basetype])) {
1119
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
2150 TRACE_DEBUG(INFO, "The AVP size is not suitable for the type");
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2151 if (error_info) {
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2152 error_info->pei_errcode = "DIAMETER_INVALID_AVP_LENGTH";
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2153 error_info->pei_avp = avp;
889
4a299daed8b2 Add information about parsing errors
Sebastien Decugis <sdecugis@freediameter.net>
parents: 871
diff changeset
2154 snprintf(error_message, sizeof(error_message), "I expected a size of %d for this AVP according to my dictionary", avp_value_sizes[dictdata.avp_basetype]);
4a299daed8b2 Add information about parsing errors
Sebastien Decugis <sdecugis@freediameter.net>
parents: 871
diff changeset
2155 error_info->pei_message = error_message;
1119
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
2156 } else {
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
2157 char * buf = NULL;
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
2158 size_t buflen;
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
2159 CHECK_MALLOC(fd_msg_dump_treeview(&buf, &buflen, NULL, avp, NULL, 0, 0));
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
2160 LOG_E("Invalid length AVP: %s", buf);
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
2161 free(buf);
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2162 }
891
9432ac55823c Tentative fix for the parse_or_error function
Sebastien Decugis <sdecugis@freediameter.net>
parents: 889
diff changeset
2163 avp->avp_model = NULL;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2164 return EBADMSG;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2165 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2166
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
2167 source = avp->avp_source;
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
2168 avp->avp_source = NULL;
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
2169
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2170 /* Now get the value inside */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2171 switch (dictdata.avp_basetype) {
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2172 case AVP_TYPE_GROUPED: {
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2173 int ret;
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2174
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2175 /* This is a grouped AVP, so let's parse the list of AVPs inside */
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
2176 CHECK_FCT_DO( ret = parsebuf_list(source, avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags ), &avp->avp_chain.children),
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2177 {
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2178 if ((ret == EBADMSG) && (error_info)) {
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2179 error_info->pei_errcode = "DIAMETER_INVALID_AVP_VALUE";
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2180 error_info->pei_avp = avp;
889
4a299daed8b2 Add information about parsing errors
Sebastien Decugis <sdecugis@freediameter.net>
parents: 871
diff changeset
2181 snprintf(error_message, sizeof(error_message), "I cannot parse this AVP as a Grouped AVP");
4a299daed8b2 Add information about parsing errors
Sebastien Decugis <sdecugis@freediameter.net>
parents: 871
diff changeset
2182 error_info->pei_message = error_message;
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2183 }
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
2184 avp->avp_source = source;
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2185 return ret;
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2186 } );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2187
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2188 return parsedict_do_chain(dict, &avp->avp_chain.children, mandatory && (avp->avp_public.avp_flags & AVP_FLAG_MANDATORY), error_info);
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2189 }
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2190
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2191 case AVP_TYPE_OCTETSTRING:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2192 /* We just have to copy the string into the storage area */
387
743195485eec Additional fixes for empty octet string AVPs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 386
diff changeset
2193 CHECK_PARAMS_DO( avp->avp_public.avp_len >= GETAVPHDRSZ( avp->avp_public.avp_flags ),
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2194 {
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2195 if (error_info) {
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2196 error_info->pei_errcode = "DIAMETER_INVALID_AVP_LENGTH";
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2197 error_info->pei_avp = avp;
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2198 }
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
2199 avp->avp_source = source;
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2200 return EBADMSG;
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2201 } );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2202 avp->avp_storage.os.len = avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags );
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
2203 CHECK_MALLOC( avp->avp_storage.os.data = os0dup(source, avp->avp_storage.os.len) );
752
9e9840ccf059 Attempt to handle more gracefully (invalid) AVPs that contain an empty octetstring
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
2204 avp->avp_mustfreeos = 1;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2205 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2206
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2207 case AVP_TYPE_INTEGER32:
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
2208 avp->avp_storage.i32 = (int32_t)ntohl(*(uint32_t *)source);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2209 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2210
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2211 case AVP_TYPE_INTEGER64:
791
42fa209a8cc4 Attempt at fixing unaligned 64b direct memory access (sigbus on sparc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 765
diff changeset
2212 /* the storage might not be aligned on 64b boundary, so no direct indirection here is possible */
42fa209a8cc4 Attempt at fixing unaligned 64b direct memory access (sigbus on sparc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 765
diff changeset
2213 {
42fa209a8cc4 Attempt at fixing unaligned 64b direct memory access (sigbus on sparc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 765
diff changeset
2214 uint64_t __stor;
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
2215 memcpy(&__stor, source, sizeof(__stor));
791
42fa209a8cc4 Attempt at fixing unaligned 64b direct memory access (sigbus on sparc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 765
diff changeset
2216 avp->avp_storage.i64 = (int64_t)ntohll(__stor);
42fa209a8cc4 Attempt at fixing unaligned 64b direct memory access (sigbus on sparc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 765
diff changeset
2217 }
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2218 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2219
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2220 case AVP_TYPE_UNSIGNED32:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2221 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 */
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
2222 avp->avp_storage.u32 = (uint32_t)ntohl(*(uint32_t *)source);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2223 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2224
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2225 case AVP_TYPE_UNSIGNED64:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2226 case AVP_TYPE_FLOAT64: /* same as 32 bits */
791
42fa209a8cc4 Attempt at fixing unaligned 64b direct memory access (sigbus on sparc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 765
diff changeset
2227 {
42fa209a8cc4 Attempt at fixing unaligned 64b direct memory access (sigbus on sparc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 765
diff changeset
2228 uint64_t __stor;
1001
d03f7e3805ad Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req
Sebastien Decugis <sdecugis@freediameter.net>
parents: 995
diff changeset
2229 memcpy(&__stor, source, sizeof(__stor));
791
42fa209a8cc4 Attempt at fixing unaligned 64b direct memory access (sigbus on sparc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 765
diff changeset
2230 avp->avp_storage.u64 = (uint64_t)ntohll(__stor);
42fa209a8cc4 Attempt at fixing unaligned 64b direct memory access (sigbus on sparc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 765
diff changeset
2231 }
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2232 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2233
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2234 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2235
1300
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2236 /* Is there a derived type check function ? */
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2237 CHECK_FCT ( fd_dict_search ( dict, DICT_TYPE, TYPE_OF_AVP, avp->avp_model, &avp_derived_type, 0) );
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2238 if (avp_derived_type) {
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2239 CHECK_FCT( fd_dict_getval(avp_derived_type, &derivedtypedata) );
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2240 if (derivedtypedata.type_check != NULL) {
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2241 char * err;
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2242 int ret = (*derivedtypedata.type_check)( derivedtypedata.type_check_param, &avp->avp_storage, &err );
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2243
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2244 if (ret != 0) {
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2245 TRACE_DEBUG(INFO, "The AVP failed to pass the dictionary validation");
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2246 if (error_info) {
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2247 error_info->pei_errcode = "DIAMETER_INVALID_AVP_VALUE";
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2248 error_info->pei_avp = avp;
1442
915450ee91c7 fix gcc 9.1.1 compile warnings
Luke Mewburn <luke@mewburn.net>
parents: 1423
diff changeset
2249 snprintf(error_message, sizeof(error_message), "%s", err);
1300
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2250 error_info->pei_message = error_message;
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2251 } else {
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2252 char * buf = NULL;
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2253 size_t buflen;
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2254 CHECK_MALLOC(fd_msg_dump_treeview(&buf, &buflen, NULL, avp, NULL, 0, 0));
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2255 LOG_E("Invalid AVP: %s", buf);
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2256 free(buf);
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2257 }
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2258 return ret; /* should we just return EBADMSG? */
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2259 }
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2260 }
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2261 }
3f1e79e1273e Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1298
diff changeset
2262
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2263 /* The value is now set, so set the data pointer and return 0 */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2264 avp->avp_public.avp_value = &avp->avp_storage;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2265 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2266 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2267
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2268 /* Process a list of AVPs */
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2269 static int parsedict_do_chain(struct dictionary * dict, struct fd_list * head, int mandatory, struct fd_pei *error_info)
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2270 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2271 struct fd_list * avpch;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2272
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2273 TRACE_ENTRY("%p %p %d %p", dict, head, mandatory, error_info);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2274
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2275 /* Sanity check */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2276 ASSERT ( head == head->head );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2277
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2278 /* Now process the list */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2279 for (avpch=head->next; avpch != head; avpch = avpch->next) {
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2280 CHECK_FCT( parsedict_do_avp(dict, _A(avpch->o), mandatory, error_info) );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2281 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2282
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2283 /* Done */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2284 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2285 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2286
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2287 /* Process a msg header. */
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2288 static int parsedict_do_msg(struct dictionary * dict, struct msg * msg, int only_hdr, struct fd_pei *error_info)
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2289 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2290 int ret = 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2291
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2292 TRACE_ENTRY("%p %p %d %p", dict, msg, only_hdr, error_info);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2293
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2294 CHECK_PARAMS( CHECK_MSG(msg) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2295
1092
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2296 /* First, check if we already have a model. */
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2297 if (msg->msg_model != NULL) {
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2298 /* Check if this model is still valid for the message data */
1539
d25ce064c667 Correctly fix compiler warnings
Luke Mewburn <luke@mewburn.net>
parents: 1442
diff changeset
2299 #ifndef NDEBUG
1092
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2300 enum dict_object_type dicttype;
1405
3cbe458fbfa9 Fix compiler warnings
Luke Mewburn <luke@mewburn.net>
parents: 1327
diff changeset
2301 #endif
1092
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2302 struct dict_cmd_data data;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2303 ASSERT(((fd_dict_gettype(msg->msg_model, &dicttype) == 0) && (dicttype == DICT_COMMAND)));
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2304 (void)fd_dict_getval( msg->msg_model, &data);
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2305 if ((data.cmd_code != msg->msg_public.msg_code)
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2306 || ((data.cmd_flag_val & data.cmd_flag_mask) != (msg->msg_public.msg_flags && data.cmd_flag_mask))) {
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2307 msg->msg_model = NULL;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2308 } else {
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2309 goto chain;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2310 }
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2311 }
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2312
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2313 /* Check if we already searched for this model without success */
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2314 if ((msg->msg_model_not_found.mnf_code == msg->msg_public.msg_code)
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2315 && (msg->msg_model_not_found.mnf_flags == msg->msg_public.msg_flags)) {
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2316 goto no_model;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2317 } else {
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2318 msg->msg_model_not_found.mnf_code = 0;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2319 }
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2320
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2321 /* Look for the model from the header */
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2322 CHECK_FCT_DO( ret = fd_dict_search ( dict, DICT_COMMAND,
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2323 (msg->msg_public.msg_flags & CMD_FLAG_REQUEST) ? CMD_BY_CODE_R : CMD_BY_CODE_A,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2324 &msg->msg_public.msg_code,
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2325 &msg->msg_model, ENOTSUP),
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2326 {
1092
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2327 if (ret == ENOTSUP) {
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2328 /* update the model not found info */
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2329 msg->msg_model_not_found.mnf_code = msg->msg_public.msg_code;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2330 msg->msg_model_not_found.mnf_flags = msg->msg_public.msg_flags;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2331 goto no_model;
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2332 }
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2333 return ret;
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2334 } );
1092
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2335 chain:
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2336 if (!only_hdr) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2337 /* Then process the children */
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2338 ret = parsedict_do_chain(dict, &msg->msg_chain.children, 1, error_info);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2339
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2340 /* Free the raw buffer if any */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2341 if ((ret == 0) && (msg->msg_rawbuffer != NULL)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2342 free(msg->msg_rawbuffer);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2343 msg->msg_rawbuffer=NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2344 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2345 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2346
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2347 return ret;
1092
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2348 no_model:
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2349 if (error_info) {
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2350 error_info->pei_errcode = "DIAMETER_COMMAND_UNSUPPORTED";
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2351 error_info->pei_protoerr = 1;
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2352 }
e40374ddfeef Optimization: do not attempt resolving dictionary objects again when it already failed during message parsing
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
2353 return ENOTSUP;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2354 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2355
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2356 int fd_msg_parse_dict ( msg_or_avp * object, struct dictionary * dict, struct fd_pei *error_info )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2357 {
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2358 TRACE_ENTRY("%p %p %p", dict, object, error_info);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2359
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2360 CHECK_PARAMS( VALIDATE_OBJ(object) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2361
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2362 if (error_info)
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2363 memset(error_info, 0, sizeof(struct fd_pei));
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2364
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2365 switch (_C(object)->type) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2366 case MSG_MSG:
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2367 return parsedict_do_msg(dict, _M(object), 0, error_info);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2368
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2369 case MSG_AVP:
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2370 return parsedict_do_avp(dict, _A(object), 0, error_info);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2371
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2372 default:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2373 ASSERT(0);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2374 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2375 return EINVAL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2376 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2377
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2378 /***************************************************************************************************************/
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2379 /* Parsing messages and AVP for rules (ABNF) compliance */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2380
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2381 /* This function is used to get stats (first occurence position, last occurence position, number of occurences)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2382 of AVP instances of a given model in a chain of AVP */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2383 static void parserules_stat_avps( struct dict_object * model_avp, struct fd_list *list, int * count, int * firstpos, int * lastpos)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2384 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2385 struct fd_list * li;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2386 int curpos = 0; /* The current position in the list */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2387
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2388 TRACE_ENTRY("%p %p %p %p %p", model_avp, list, count, firstpos, lastpos);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2389
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2390 *count = 0; /* number of instances found */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2391 *firstpos = 0; /* position of the first instance */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2392 *lastpos = 0; /* position of the last instance, starting from the end */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2393
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2394 for (li = list->next; li != list; li = li->next) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2395 /* Increment the current position counter */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2396 curpos++;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2397
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2398 /* If we previously saved a "lastpos" information, increment it */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2399 if (*lastpos != 0)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2400 (*lastpos)++;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2401
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2402 /* Check the type of the next AVP. We can compare the references directly, it is safe. */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2403 if (_A(li->o)->avp_model == model_avp) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2404
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2405 /* This AVP is of the type we are searching */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2406 (*count)++;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2407
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2408 /* If we don't have yet a "firstpos", save it */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2409 if (*firstpos == 0)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2410 *firstpos = curpos;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2411
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2412 /* Reset the lastpos */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2413 (*lastpos) = 1;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2414 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2415 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2416 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2417
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2418 /* We use this structure as parameter for the next function */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2419 struct parserules_data {
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2420 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
2421 struct fd_pei * pei; /* If the rule conflicts, save the error here */
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2422 };
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2423
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2424 /* 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
2425 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
2426 {
35
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2427 struct avp * avp = NULL;
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2428 struct dict_avp_data avp_info;
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2429 union avp_value val;
400
bb8a4fa301b3 Fix compilation warning
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 387
diff changeset
2430 unsigned char os[1] = { '\0' };
35
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2431
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2432 /* Create an instance */
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2433 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
2434
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2435 /* Type of the AVP */
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2436 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
2437
1230
e72c9dad62ac Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1229
diff changeset
2438 /* Set an initial size */
e72c9dad62ac Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1229
diff changeset
2439 avp->avp_public.avp_len = GETAVPHDRSZ( avp->avp_public.avp_flags ) + avp_value_sizes[avp_info.avp_basetype];
e72c9dad62ac Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1229
diff changeset
2440
35
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2441 /* Prepare the empty value */
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2442 memset(&val, 0, sizeof(val));
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2443 switch (avp_info.avp_basetype) {
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2444 case AVP_TYPE_OCTETSTRING:
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2445 val.os.data = os;
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2446 val.os.len = sizeof(os);
1230
e72c9dad62ac Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1229
diff changeset
2447 avp->avp_public.avp_len += val.os.len;
35
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2448 case AVP_TYPE_INTEGER32:
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2449 case AVP_TYPE_INTEGER64:
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2450 case AVP_TYPE_UNSIGNED32:
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2451 case AVP_TYPE_UNSIGNED64:
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2452 case AVP_TYPE_FLOAT32:
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2453 case AVP_TYPE_FLOAT64:
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2454 CHECK_FCT_DO( fd_msg_avp_setvalue(avp, &val), return NULL );
400
bb8a4fa301b3 Fix compilation warning
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 387
diff changeset
2455 case AVP_TYPE_GROUPED:
bb8a4fa301b3 Fix compilation warning
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 387
diff changeset
2456 /* For AVP_TYPE_GROUPED we don't do anything */
bb8a4fa301b3 Fix compilation warning
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 387
diff changeset
2457 break;
bb8a4fa301b3 Fix compilation warning
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 387
diff changeset
2458 default:
bb8a4fa301b3 Fix compilation warning
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 387
diff changeset
2459 ASSERT(0); /* not handled */
35
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2460 }
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2461
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2462 return avp;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2463 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2464
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2465 /* Check that a list of AVPs is compliant with a given rule -- will be iterated on the list of rules */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2466 static int parserules_check_one_rule(void * data, struct dict_rule_data *rule)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2467 {
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2468 int count, first, last, min;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2469 struct parserules_data * pr_data = data;
280
3019f6220122 Provide more useful debug information for non-ABNF-compliant messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
2470 char * avp_name = "<unresolved name>";
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2471
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2472 TRACE_ENTRY("%p %p", data, rule);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2473
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2474 /* Get statistics of the AVP concerned by this rule in the parent instance */
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2475 parserules_stat_avps( rule->rule_avp, pr_data->sentinel, &count, &first, &last);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2476
280
3019f6220122 Provide more useful debug information for non-ABNF-compliant messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
2477 if (TRACE_BOOL(INFO))
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2478 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2479 struct dict_avp_data avpdata;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2480 int ret;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2481 ret = fd_dict_getval(rule->rule_avp, &avpdata);
280
3019f6220122 Provide more useful debug information for non-ABNF-compliant messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
2482 if (ret == 0)
3019f6220122 Provide more useful debug information for non-ABNF-compliant messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
2483 avp_name = avpdata.avp_name;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2484
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2485 TRACE_DEBUG(ANNOYING, "Checking rule: p:%d(%d) m/M:%2d/%2d. Counted %d (first: %d, last:%d) of AVP '%s'",
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2486 rule->rule_position,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2487 rule->rule_order,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2488 rule->rule_min,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2489 rule->rule_max,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2490 count,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2491 first,
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2492 last,
280
3019f6220122 Provide more useful debug information for non-ABNF-compliant messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
2493 avp_name
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2494 );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2495 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2496
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2497 /* Now check the rule is not conflicting */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2498
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2499 /* Check the "min" value */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2500 if ((min = rule->rule_min) == -1) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2501 if (rule->rule_position == RULE_OPTIONAL)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2502 min = 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2503 else
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2504 min = 1;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2505 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2506 if (count < min) {
1062
56bf0377e2ff Raise "Conflicting rules" to error level since it causes validation
Thomas Klausner <tk@giga.or.at>
parents: 1036
diff changeset
2507 fd_log_error("Conflicting rule: the number of occurences (%d) is < the rule min (%d) for '%s'.", count, min, avp_name);
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2508 if (pr_data->pei) {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2509 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
2510 pr_data->pei->pei_avp = empty_avp(rule->rule_avp);
1230
e72c9dad62ac Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1229
diff changeset
2511 pr_data->pei->pei_avp_free = 1;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2512 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2513 return EBADMSG;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2514 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2515
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2516 /* Check the "max" value */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2517 if ((rule->rule_max != -1) && (count > rule->rule_max)) {
1062
56bf0377e2ff Raise "Conflicting rules" to error level since it causes validation
Thomas Klausner <tk@giga.or.at>
parents: 1036
diff changeset
2518 fd_log_error("Conflicting rule: the number of occurences (%d) is > the rule max (%d) for '%s'.", count, rule->rule_max, avp_name);
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2519 if (pr_data->pei) {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2520 if (rule->rule_max == 0)
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2521 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
2522 else
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2523 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
2524 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...");
1230
e72c9dad62ac Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1229
diff changeset
2525 pr_data->pei->pei_avp_free = 1;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2526 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2527 return EBADMSG;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2528 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2529
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2530 /* Check the position and order (if relevant) */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2531 switch (rule->rule_position) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2532 case RULE_OPTIONAL:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2533 case RULE_REQUIRED:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2534 /* No special position constraints */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2535 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2536
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2537 case RULE_FIXED_HEAD:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2538 /* Since "0*1<fixed>" is a valid rule specifier, we only reject cases where the AVP appears *after* its fixed position */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2539 if (first > rule->rule_order) {
1062
56bf0377e2ff Raise "Conflicting rules" to error level since it causes validation
Thomas Klausner <tk@giga.or.at>
parents: 1036
diff changeset
2540 fd_log_error("Conflicting rule: the FIXED_HEAD AVP appears first in (%d) position, the rule requires (%d) for '%s'.", first, rule->rule_order, avp_name);
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2541 if (pr_data->pei) {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2542 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
2543 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
2544 pr_data->pei->pei_avp = empty_avp(rule->rule_avp);
1230
e72c9dad62ac Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1229
diff changeset
2545 pr_data->pei->pei_avp_free = 1;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2546 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2547 return EBADMSG;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2548 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2549 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2550
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2551 case RULE_FIXED_TAIL:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2552 /* Since "0*1<fixed>" is a valid rule specifier, we only reject cases where the AVP appears *before* its fixed position */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2553 if (last > rule->rule_order) { /* We have a ">" here because we count in reverse order (i.e. from the end) */
1062
56bf0377e2ff Raise "Conflicting rules" to error level since it causes validation
Thomas Klausner <tk@giga.or.at>
parents: 1036
diff changeset
2554 fd_log_error("Conflicting rule: the FIXED_TAIL AVP appears last in (%d) position, the rule requires (%d) for '%s'.", last, rule->rule_order, avp_name);
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2555 if (pr_data->pei) {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2556 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
2557 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
2558 pr_data->pei->pei_avp = empty_avp(rule->rule_avp);
1230
e72c9dad62ac Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1229
diff changeset
2559 pr_data->pei->pei_avp_free = 1;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2560 }
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2561 return EBADMSG;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2562 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2563 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2564
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2565 default:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2566 /* What is this position ??? */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2567 ASSERT(0);
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2568 return ENOTSUP;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2569 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2570
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2571 /* 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
2572 return 0;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2573 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2574
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2575 /* Check the rules recursively */
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2576 static int parserules_do ( struct dictionary * dict, msg_or_avp * object, struct fd_pei *error_info, int mandatory)
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2577 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2578 struct parserules_data data;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2579 struct dict_object * model = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2580
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2581 TRACE_ENTRY("%p %p %p %d", dict, object, error_info, mandatory);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2582
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2583 /* object has already been checked and dict-parsed when we are called. */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2584
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2585 /* First, handle the cases where there is no model */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2586 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2587 if (CHECK_MSG(object)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2588 if ( _M(object)->msg_public.msg_flags & CMD_FLAG_ERROR ) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2589 /* The case of error messages: the ABNF is different */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2590 CHECK_FCT( fd_dict_get_error_cmd(dict, &model) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2591 } else {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2592 model = _M(object)->msg_model;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2593 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2594 /* Commands MUST be supported in the dictionary */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2595 if (model == NULL) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2596 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
2597 if (error_info) {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2598 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
2599 error_info->pei_protoerr = 1;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2600 }
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2601 return EBADMSG;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2602 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2603 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2604
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2605 /* AVP with the 'M' flag must also be recognized in the dictionary -- except inside an optional grouped AVP */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2606 if (CHECK_AVP(object) && ((model = _A(object)->avp_model) == NULL)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2607 if ( mandatory && (_A(object)->avp_public.avp_flags & AVP_FLAG_MANDATORY)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2608 /* Return an error in this case */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2609 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
2610 if (error_info) {
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2611 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
2612 error_info->pei_avp = object;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2613 }
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2614 return EBADMSG;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2615 } else {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2616 /* We don't know any rule for this object, so assume OK */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2617 TRACE_DEBUG(FULL, "Unknown informational AVP, ignoring...");
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2618 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2619 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2620 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2621 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2622
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2623 /* At this point we know "model" is set and points to the object's model */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2624
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2625 /* If we are an AVP with no children, just return OK */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2626 if (CHECK_AVP(object)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2627 struct dict_avp_data dictdata;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2628 CHECK_FCT( fd_dict_getval(model, &dictdata) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2629 if (dictdata.avp_basetype != AVP_TYPE_GROUPED) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2630 /* This object has no children and no rules */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2631 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2632 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2633 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2634
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2635 /* If this object has children, first check the rules for all its children */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2636 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2637 int is_child_mand = 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2638 struct fd_list * ch = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2639 if ( CHECK_MSG(object)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2640 || (mandatory && (_A(object)->avp_public.avp_flags & AVP_FLAG_MANDATORY)) )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2641 is_child_mand = 1;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2642 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
2643 CHECK_FCT( parserules_do ( dict, _C(ch->o), error_info, is_child_mand ) );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2644 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2645 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2646
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2647 /* Now check all rules of this object */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2648 data.sentinel = &_C(object)->children;
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2649 data.pei = error_info;
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2650 CHECK_FCT( fd_dict_iterate_rules ( model, &data, parserules_check_one_rule ) );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2651
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2652 return 0;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2653 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2654
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2655 int fd_msg_parse_rules ( msg_or_avp * object, struct dictionary * dict, struct fd_pei *error_info)
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2656 {
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2657 TRACE_ENTRY("%p %p %p", object, dict, error_info);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2658
35
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2659 if (error_info)
6486e97f56ae Added test for modified message parsing
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 34
diff changeset
2660 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
2661
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2662 /* Resolve the dictionary objects when missing. This also validates the object. */
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 112
diff changeset
2663 CHECK_FCT( fd_msg_parse_dict ( object, dict, error_info ) );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2664
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2665 /* Call the recursive function */
34
0e2b57789361 Backup for the WE, some warnings remaining
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
2666 return parserules_do ( dict, object, error_info, 1 ) ;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2667 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2668
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2669 /***************************************************************************************************************/
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2670
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2671 /* Compute the lengh of an object and its subtree. */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2672 int fd_msg_update_length ( msg_or_avp * object )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2673 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2674 size_t sz = 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2675 struct dict_object * model;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2676 union {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2677 struct dict_cmd_data cmddata;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2678 struct dict_avp_data avpdata;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2679 } dictdata;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2680
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2681 TRACE_ENTRY("%p", object);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2682
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2683 /* Get the model of the object. This also validates the object */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2684 CHECK_FCT( fd_msg_model ( object, &model ) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2685
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2686 /* Get the information of the model */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2687 if (model) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2688 CHECK_FCT( fd_dict_getval(model, &dictdata) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2689 } else {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2690 /* For unknown AVP, just don't change the size */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2691 if (_C(object)->type == MSG_AVP)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2692 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2693 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2694
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2695 /* Deal with easy cases: AVPs without children */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2696 if ((_C(object)->type == MSG_AVP) && (dictdata.avpdata.avp_basetype != AVP_TYPE_GROUPED)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2697 /* Sanity check */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2698 ASSERT(FD_IS_LIST_EMPTY(&_A(object)->avp_chain.children));
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2699
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2700 /* Now check that the data is set in the AVP */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2701 CHECK_PARAMS( _A(object)->avp_public.avp_value );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2702
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2703 sz = GETAVPHDRSZ( _A(object)->avp_public.avp_flags );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2704
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2705 switch (dictdata.avpdata.avp_basetype) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2706 case AVP_TYPE_OCTETSTRING:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2707 sz += _A(object)->avp_public.avp_value->os.len;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2708 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2709
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2710 case AVP_TYPE_INTEGER32:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2711 case AVP_TYPE_INTEGER64:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2712 case AVP_TYPE_UNSIGNED32:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2713 case AVP_TYPE_UNSIGNED64:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2714 case AVP_TYPE_FLOAT32:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2715 case AVP_TYPE_FLOAT64:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2716 sz += avp_value_sizes[dictdata.avpdata.avp_basetype];
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2717 break;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2718
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2719 default:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2720 /* Something went wrong... */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2721 ASSERT(0);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2722 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2723 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2724 else /* message or grouped AVP */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2725 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2726 struct fd_list * ch = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2727
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2728 /* First, compute the header size */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2729 if (_C(object)->type == MSG_AVP) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2730 sz = GETAVPHDRSZ( _A(object)->avp_public.avp_flags );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2731 } else {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2732 sz = GETMSGHDRSZ( );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2733 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2734
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2735 /* Recurse in all children and update the sz information */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2736 for (ch = _C(object)->children.next; ch != &_C(object)->children; ch = ch->next) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2737 CHECK_FCT( fd_msg_update_length ( ch->o ) );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2738
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2739 /* Add the padded size to the parent */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2740 sz += PAD4( _A(ch->o)->avp_public.avp_len );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2741 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2742 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2743
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2744 /* When we arrive here, the "sz" variable contains the size to write in the object */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2745 if (_C(object)->type == MSG_AVP)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2746 _A(object)->avp_public.avp_len = sz;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2747 else
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2748 _M(object)->msg_public.msg_length = sz;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2749
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2750 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2751 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2752
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2753 /***************************************************************************************************************/
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2754 /* 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
2755 #define TEST_ACTION_STOP() \
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2756 if ((*msg == NULL) || (*action != DISP_ACT_CONT)) \
690
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2757 goto out;
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2758
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2759 /* Call all dispatch callbacks for a given message */
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
2760 int fd_msg_dispatch ( struct msg ** msg, struct session * session, enum disp_action *action, char ** error_code, char ** drop_reason, struct msg ** drop_msg)
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2761 {
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2762 struct dictionary * dict;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2763 struct dict_object * app;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2764 struct dict_object * cmd;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2765 struct avp * avp;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2766 struct fd_list * cb_list;
690
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2767 int ret = 0, r2;
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2768
90
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
2769 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
2770 CHECK_PARAMS( msg && CHECK_MSG(*msg) && action);
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2771
90
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
2772 if (error_code)
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
2773 *error_code = NULL;
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
2774 if (drop_reason)
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
2775 *drop_reason = NULL;
132
4e49c086d2c4 Initialize var
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 114
diff changeset
2776 *action = DISP_ACT_CONT;
90
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
2777
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2778 /* Take the dispatch lock */
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2779 CHECK_FCT( pthread_rwlock_rdlock(&fd_disp_lock) );
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2780 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
2781
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2782 /* First, call the DISP_HOW_ANY callbacks */
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
2783 CHECK_FCT_DO( ret = fd_disp_call_cb_int( NULL, msg, NULL, session, action, NULL, NULL, NULL, NULL, drop_reason, drop_msg ), goto out );
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2784
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2785 TEST_ACTION_STOP();
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2786
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2787 /* 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 */
690
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2788 CHECK_PARAMS_DO(cmd = (*msg)->msg_model, { ret = EINVAL; goto out; } );
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2789
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2790 /* Now resolve message application */
690
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2791 CHECK_FCT_DO( ret = fd_dict_getdict( cmd, &dict ), goto out );
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2792 CHECK_FCT_DO( ret = fd_dict_search( dict, DICT_APPLICATION, APPLICATION_BY_ID, &(*msg)->msg_public.msg_appl, &app, 0 ), goto out );
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2793
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2794 if (app == NULL) {
90
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
2795 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
2796 if (error_code)
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
2797 *error_code = "DIAMETER_APPLICATION_UNSUPPORTED";
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
2798 *action = DISP_ACT_ERROR;
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
2799 } else {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
2800 *drop_reason = "Internal error: Received this answer to a local query with an unsupported application";
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
2801 *drop_msg = *msg;
90
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
2802 *msg = NULL;
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
2803 }
690
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2804 goto out;
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2805 }
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2806
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2807 /* So start browsing the message */
690
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2808 CHECK_FCT_DO( ret = fd_msg_browse( *msg, MSG_BRW_FIRST_CHILD, &avp, NULL ), goto out );
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2809 while (avp != NULL) {
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2810 /* 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
2811 if (avp->avp_model) {
330
e283e18b2673 Removed incorrect ASSERT -- thanks to Alexandre for the bug finding.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 291
diff changeset
2812 struct dict_object * enumval = NULL;
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2813
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2814 /* Get the list of callback for this AVP */
690
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2815 CHECK_FCT_DO( ret = fd_dict_disp_cb(DICT_AVP, avp->avp_model, &cb_list), goto out );
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2816
330
e283e18b2673 Removed incorrect ASSERT -- thanks to Alexandre for the bug finding.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 291
diff changeset
2817 /* We search enumerated values only in case of non-grouped AVP */
e283e18b2673 Removed incorrect ASSERT -- thanks to Alexandre for the bug finding.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 291
diff changeset
2818 if ( avp->avp_public.avp_value ) {
e283e18b2673 Removed incorrect ASSERT -- thanks to Alexandre for the bug finding.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 291
diff changeset
2819 struct dict_object * type;
e283e18b2673 Removed incorrect ASSERT -- thanks to Alexandre for the bug finding.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 291
diff changeset
2820 /* Check if the AVP has a constant value */
690
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2821 CHECK_FCT_DO( ret = fd_dict_search(dict, DICT_TYPE, TYPE_OF_AVP, avp->avp_model, &type, 0), goto out );
330
e283e18b2673 Removed incorrect ASSERT -- thanks to Alexandre for the bug finding.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 291
diff changeset
2822 if (type) {
e283e18b2673 Removed incorrect ASSERT -- thanks to Alexandre for the bug finding.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 291
diff changeset
2823 struct dict_enumval_request req;
e283e18b2673 Removed incorrect ASSERT -- thanks to Alexandre for the bug finding.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 291
diff changeset
2824 memset(&req, 0, sizeof(struct dict_enumval_request));
e283e18b2673 Removed incorrect ASSERT -- thanks to Alexandre for the bug finding.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 291
diff changeset
2825 req.type_obj = type;
e283e18b2673 Removed incorrect ASSERT -- thanks to Alexandre for the bug finding.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 291
diff changeset
2826 memcpy( &req.search.enum_value, avp->avp_public.avp_value, sizeof(union avp_value) );
690
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2827 CHECK_FCT_DO( ret = fd_dict_search(dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &req, &enumval, 0), goto out );
330
e283e18b2673 Removed incorrect ASSERT -- thanks to Alexandre for the bug finding.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 291
diff changeset
2828 }
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2829 }
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2830
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2831 /* Call the callbacks */
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
2832 CHECK_FCT_DO( ret = fd_disp_call_cb_int( cb_list, msg, avp, session, action, app, cmd, avp->avp_model, enumval, drop_reason, drop_msg ), goto out );
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2833 TEST_ACTION_STOP();
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2834 }
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2835 /* Go to next AVP */
690
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2836 CHECK_FCT_DO( ret = fd_msg_browse( avp, MSG_BRW_WALK, &avp, NULL ), goto out );
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2837 }
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2838
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2839 /* Now call command and application callbacks */
690
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2840 CHECK_FCT_DO( ret = fd_dict_disp_cb(DICT_COMMAND, cmd, &cb_list), goto out );
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
2841 CHECK_FCT_DO( ret = fd_disp_call_cb_int( cb_list, msg, NULL, session, action, app, cmd, NULL, NULL, drop_reason, drop_msg ), goto out );
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2842 TEST_ACTION_STOP();
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2843
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2844 if (app) {
690
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2845 CHECK_FCT_DO( ret = fd_dict_disp_cb(DICT_APPLICATION, app, &cb_list), goto out );
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
2846 CHECK_FCT_DO( ret = fd_disp_call_cb_int( cb_list, msg, NULL, session, action, app, cmd, NULL, NULL, drop_reason, drop_msg ), goto out );
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2847 TEST_ACTION_STOP();
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2848 }
690
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2849 out:
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2850 ; /* some systems would complain without this */
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2851 pthread_cleanup_pop(0);
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2852
690
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2853 CHECK_POSIX_DO(r2 = pthread_rwlock_unlock(&fd_disp_lock), /* ignore */ );
a29e4201d511 It seems FreeBSD does not unstack cancelation cleanups if we skip the pthread_cleanup_pop call
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
2854 return ret ?: r2;
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 4
diff changeset
2855 }
687
026802543f57 Prepare for new message log facility
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 686
diff changeset
2856
026802543f57 Prepare for new message log facility
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 686
diff changeset
2857
"Welcome to our mercurial repository"