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