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