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