Mercurial > hg > freeDiameter
changeset 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 | 3b6174b6b35b |
children | 2cf9f62cdcc7 |
files | extensions/app_test/atst_serv.c freeDiameter/dispatch.c freeDiameter/p_dp.c include/freeDiameter/libfreeDiameter.h libfreeDiameter/messages.c |
diffstat | 5 files changed, 26 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/extensions/app_test/atst_serv.c Tue Dec 08 14:53:26 2009 +0900 +++ b/extensions/app_test/atst_serv.c Tue Dec 08 15:24:34 2009 +0900 @@ -67,17 +67,6 @@ CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, msg, 0 ) ); ans = *msg; - /* Set the Session-Id AVP */ - { - char * sid; - CHECK_FCT( fd_sess_getsid ( sess, &sid ) ); - CHECK_FCT( fd_msg_avp_new ( atst_sess_id, 0, &avp ) ); - val.os.data = sid; - val.os.len = strlen(sid); - CHECK_FCT( fd_msg_avp_setvalue( avp, &val ) ); - CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_FIRST_CHILD, avp ) ); - - } /* Set the Test-AVP AVP */ { struct avp * src = NULL;
--- a/freeDiameter/dispatch.c Tue Dec 08 14:53:26 2009 +0900 +++ b/freeDiameter/dispatch.c Tue Dec 08 15:24:34 2009 +0900 @@ -191,7 +191,7 @@ } /* Create an answer with the error code and message */ - CHECK_FCT_DO( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, &msg, MSGFL_ANSW_ERROR ), goto fatal_error ); + CHECK_FCT_DO( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, &msg, 0 ), goto fatal_error ); CHECK_FCT_DO( fd_msg_rescode_set(msg, (char *)ec, (char *)em, NULL, 1 ), goto fatal_error ); case DISP_ACT_SEND:
--- a/freeDiameter/p_dp.c Tue Dec 08 14:53:26 2009 +0900 +++ b/freeDiameter/p_dp.c Tue Dec 08 15:24:34 2009 +0900 @@ -97,8 +97,7 @@ /* Now reply with a DPA */ CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, msg, 0 ) ); - CHECK_FCT( fd_msg_rescode_set( *msg, "DIAMETER_SUCCESS", NULL, NULL, 0 ) ); - CHECK_FCT( fd_msg_add_origin ( *msg, 0 ) ); + CHECK_FCT( fd_msg_rescode_set( *msg, "DIAMETER_SUCCESS", NULL, NULL, 1 ) ); /* Move to CLOSING state to failover outgoing messages (and avoid failing the DPA...) */ CHECK_FCT( fd_psm_change_state(peer, STATE_CLOSING) );
--- a/include/freeDiameter/libfreeDiameter.h Tue Dec 08 14:53:26 2009 +0900 +++ b/include/freeDiameter/libfreeDiameter.h Tue Dec 08 15:24:34 2009 +0900 @@ -1722,7 +1722,8 @@ /* Some flags used in the functions bellow */ #define MSGFL_ALLOC_ETEID 0x01 /* When creating a message, a new end-to-end ID is allocated and set in the message */ #define MSGFL_ANSW_ERROR 0x02 /* When creating an answer message, set the 'E' bit and use the generic error ABNF instead of command-specific ABNF */ -#define MSGFL_MAX MSGFL_ANSW_ERROR /* The biggest valid flag value */ +#define MSGFL_ANSW_NOSID 0x04 /* When creating an answer message, do not add the Session-Id even if present in request */ +#define MSGFL_MAX MSGFL_ANSW_NOSID /* The biggest valid flag value */ /**************************************************/ /* Message creation, manipulation, disposal */
--- a/libfreeDiameter/messages.c Tue Dec 08 14:53:26 2009 +0900 +++ b/libfreeDiameter/messages.c Tue Dec 08 15:24:34 2009 +0900 @@ -286,6 +286,7 @@ { struct dict_object * model = NULL; struct msg *qry, *ans; + struct session * sess = NULL; TRACE_ENTRY("%p %x", msg, flags); @@ -294,6 +295,11 @@ qry = *msg; CHECK_PARAMS( CHECK_MSG(qry) && (qry->msg_public.msg_flags & CMD_FLAG_REQUEST) ); + if (! (flags & MSGFL_ANSW_NOSID)) { + /* Get the session of the message */ + CHECK_FCT_DO( fd_msg_sess_get(dict, qry, &sess, NULL), /* ignore an error */ ); + } + /* Find the model for the answer */ if (flags & MSGFL_ANSW_ERROR) { /* The model is the generic error format */ @@ -315,8 +321,23 @@ ans->msg_public.msg_eteid = qry->msg_public.msg_eteid; ans->msg_public.msg_hbhid = qry->msg_public.msg_hbhid; + /* Add the Session-Id AVP if session is known */ + if (sess && dict) { + struct dict_object * sess_id_avp; + char * sid; + struct avp * avp; + union avp_value val; + + CHECK_FCT( fd_dict_search( dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &sess_id_avp, ENOENT) ); + CHECK_FCT( fd_sess_getsid ( sess, &sid ) ); + CHECK_FCT( fd_msg_avp_new ( sess_id_avp, 0, &avp ) ); + val.os.data = sid; + val.os.len = strlen(sid); + CHECK_FCT( fd_msg_avp_setvalue( avp, &val ) ); + CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_FIRST_CHILD, avp ) ); + } + /* associate with query */ - /* may do CHECK_FCT( msg_answ_associate( *msg, (msg_t *)qry ) ); but this is quicker */ ans->msg_query = qry; /* Done */