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