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