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