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