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