Mercurial > hg > freeDiameter
changeset 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.
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Sun, 17 Mar 2013 16:22:32 +0100 |
parents | 9c7d6b3cb90e |
children | eeb1a46c0e7d |
files | include/freeDiameter/libfdproto.h libfdproto/messages.c |
diffstat | 2 files changed, 37 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/include/freeDiameter/libfdproto.h Sun Mar 17 14:53:24 2013 +0100 +++ b/include/freeDiameter/libfdproto.h Sun Mar 17 16:22:32 2013 +0100 @@ -2142,7 +2142,8 @@ #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_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 */ +#define MSGFL_ANSW_NOPROXYINFO 0x08 /* When creating an answer message, do not add the Proxy-Info AVPs presents in request */ +#define MSGFL_MAX MSGFL_ANSW_NOPROXYINFO /* The biggest valid flag value */ /**************************************************/ /* Message creation, manipulation, disposal */ @@ -2151,9 +2152,9 @@ * FUNCTION: fd_msg_avp_new * * PARAMETERS: - * model : Pointer to a DICT_AVP dictionary object describing the avp to create, or NULL. - * flags : Flags to use in creation (AVPFL_*). - * avp : Upon success, pointer to the new avp is stored here. + * model : Pointer to a DICT_AVP dictionary object describing the avp to create, or NULL if flags are used. + * flags : Flags to use in creation (AVPFL_*, see above). + * avp : Upon success, pointer to the new avp is stored here. It points to reference AVP upon function call when flags are used. * * DESCRIPTION: * Create a new AVP instance. @@ -2192,6 +2193,7 @@ * dict : Pointer to the dictionary containing the model of the query. * msg : The location of the query on function call. Updated by the location of answer message on return. * flag : Pass MSGFL_ANSW_ERROR to indicate if the answer is an error message (will set the 'E' bit) + * : See other MSGFL_ANSW_* definition above for other flags. * * DESCRIPTION: * This function creates the empty answer message corresponding to a request.
--- a/libfdproto/messages.c Sun Mar 17 14:53:24 2013 +0100 +++ b/libfdproto/messages.c Sun Mar 17 16:22:32 2013 +0100 @@ -300,6 +300,9 @@ return 0; } +static int bufferize_avp(unsigned char * buffer, size_t buflen, size_t * offset, struct avp * avp); +static int parsebuf_list(unsigned char * buf, size_t buflen, struct fd_list * head); + /* Create answer from a request */ int fd_msg_new_answer_from_req ( struct dictionary * dict, struct msg ** msg, int flags ) { @@ -359,6 +362,34 @@ CHECK_FCT( fd_sess_ref_msg(sess) ); } + /* Add all Proxy-Info AVPs from the query if any */ + if (! (flags & MSGFL_ANSW_NOPROXYINFO)) { + struct avp * avp; + CHECK_FCT( fd_msg_browse(qry, MSG_BRW_FIRST_CHILD, &avp, NULL) ); + while (avp) { + if ( (avp->avp_public.avp_code == AC_PROXY_INFO) + && (avp->avp_public.avp_vendor == 0) ) { + /* We found a Proxy-Info, need to duplicate it in the answer */ + + /* In order to avoid dealing with all different possibilities of states, we just create a buffer then parse it */ + unsigned char * buf = NULL; + size_t offset = 0; + + CHECK_FCT( fd_msg_update_length(avp) ); + CHECK_MALLOC( buf = malloc(avp->avp_public.avp_len) ); + CHECK_FCT( bufferize_avp(buf, avp->avp_public.avp_len, &offset, avp) ); + + /* Now we directly parse this buffer into the new message list */ + CHECK_FCT( parsebuf_list(buf, avp->avp_public.avp_len, &ans->msg_chain.children) ); + + /* Done for this AVP */ + free(buf); + } + /* move to next AVP in the message, we can have several Proxy-Info instances */ + CHECK_FCT( fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL) ); + } + } + /* associate with query */ ans->msg_query = qry; qry->msg_associated = 1;