comparison libfreeDiameter/messages.c @ 112:6a294d977878

Default to add Session-Id in answers
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 08 Dec 2009 15:24:34 +0900
parents 05ea77b86f53
children 5b3868944e2b
comparison
equal deleted inserted replaced
111:3b6174b6b35b 112:6a294d977878
284 /* Create answer from a request */ 284 /* Create answer from a request */
285 int fd_msg_new_answer_from_req ( struct dictionary * dict, struct msg ** msg, int flags ) 285 int fd_msg_new_answer_from_req ( struct dictionary * dict, struct msg ** msg, int flags )
286 { 286 {
287 struct dict_object * model = NULL; 287 struct dict_object * model = NULL;
288 struct msg *qry, *ans; 288 struct msg *qry, *ans;
289 struct session * sess = NULL;
289 290
290 TRACE_ENTRY("%p %x", msg, flags); 291 TRACE_ENTRY("%p %x", msg, flags);
291 292
292 /* Check the parameters */ 293 /* Check the parameters */
293 CHECK_PARAMS( msg ); 294 CHECK_PARAMS( msg );
294 qry = *msg; 295 qry = *msg;
295 CHECK_PARAMS( CHECK_MSG(qry) && (qry->msg_public.msg_flags & CMD_FLAG_REQUEST) ); 296 CHECK_PARAMS( CHECK_MSG(qry) && (qry->msg_public.msg_flags & CMD_FLAG_REQUEST) );
297
298 if (! (flags & MSGFL_ANSW_NOSID)) {
299 /* Get the session of the message */
300 CHECK_FCT_DO( fd_msg_sess_get(dict, qry, &sess, NULL), /* ignore an error */ );
301 }
296 302
297 /* Find the model for the answer */ 303 /* Find the model for the answer */
298 if (flags & MSGFL_ANSW_ERROR) { 304 if (flags & MSGFL_ANSW_ERROR) {
299 /* The model is the generic error format */ 305 /* The model is the generic error format */
300 CHECK_FCT( fd_dict_get_error_cmd(dict, &model) ); 306 CHECK_FCT( fd_dict_get_error_cmd(dict, &model) );
313 ans->msg_public.msg_code = qry->msg_public.msg_code; /* useful for MSGFL_ANSW_ERROR */ 319 ans->msg_public.msg_code = qry->msg_public.msg_code; /* useful for MSGFL_ANSW_ERROR */
314 ans->msg_public.msg_appl = qry->msg_public.msg_appl; 320 ans->msg_public.msg_appl = qry->msg_public.msg_appl;
315 ans->msg_public.msg_eteid = qry->msg_public.msg_eteid; 321 ans->msg_public.msg_eteid = qry->msg_public.msg_eteid;
316 ans->msg_public.msg_hbhid = qry->msg_public.msg_hbhid; 322 ans->msg_public.msg_hbhid = qry->msg_public.msg_hbhid;
317 323
324 /* Add the Session-Id AVP if session is known */
325 if (sess && dict) {
326 struct dict_object * sess_id_avp;
327 char * sid;
328 struct avp * avp;
329 union avp_value val;
330
331 CHECK_FCT( fd_dict_search( dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &sess_id_avp, ENOENT) );
332 CHECK_FCT( fd_sess_getsid ( sess, &sid ) );
333 CHECK_FCT( fd_msg_avp_new ( sess_id_avp, 0, &avp ) );
334 val.os.data = sid;
335 val.os.len = strlen(sid);
336 CHECK_FCT( fd_msg_avp_setvalue( avp, &val ) );
337 CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_FIRST_CHILD, avp ) );
338 }
339
318 /* associate with query */ 340 /* associate with query */
319 /* may do CHECK_FCT( msg_answ_associate( *msg, (msg_t *)qry ) ); but this is quicker */
320 ans->msg_query = qry; 341 ans->msg_query = qry;
321 342
322 /* Done */ 343 /* Done */
323 *msg = ans; 344 *msg = ans;
324 return 0; 345 return 0;
"Welcome to our mercurial repository"