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