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