Mercurial > hg > freeDiameter
changeset 892:b2e8f1a3ef76
Allow the content of the Failed-AVP to be parseable to bufferize the message. The content is only padded currently
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Mon, 19 Nov 2012 08:58:40 +0100 |
parents | 9432ac55823c |
children | 8187364e39ea |
files | include/freeDiameter/libfdproto.h libfdcore/messages.c libfdproto/messages.c tests/testmesg.c |
diffstat | 4 files changed, 19 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/include/freeDiameter/libfdproto.h Sat Nov 17 23:28:50 2012 +0100 +++ b/include/freeDiameter/libfdproto.h Mon Nov 19 08:58:40 2012 +0100 @@ -2024,8 +2024,9 @@ }; /* Some flags used in the functions bellow */ -#define AVPFL_SET_BLANK_VALUE 0x01 /* When creating an AVP, initialize its value to a blank area */ -#define AVPFL_MAX AVPFL_SET_BLANK_VALUE /* The biggest valid flag value */ +#define AVPFL_SET_BLANK_VALUE 0x01 /* When creating an AVP, initialize its value to a blank area */ +#define AVPFL_SET_RAWDATA_FROM_AVP 0x02 /* When creating an AVP, initialize its rawdata area from an existing AVP -- it is only blank padding (for error reporting) */ +#define AVPFL_MAX AVPFL_SET_RAWDATA_FROM_AVP /* The biggest valid flag value */ #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 */
--- a/libfdcore/messages.c Sat Nov 17 23:28:50 2012 +0100 +++ b/libfdcore/messages.c Mon Nov 19 08:58:40 2012 +0100 @@ -240,7 +240,8 @@ CHECK_FCT( fd_msg_avp_new( dict_avp_FAVP, 0, &avp_FAVP ) ); /* Create a new AVP with a copy of the data of the invalid or missing AVP */ - CHECK_FCT( fd_msg_avp_new( NULL, AVPFL_SET_BLANK_VALUE, &optavp_cpy) ); + optavp_cpy = optavp; + CHECK_FCT( fd_msg_avp_new( NULL, AVPFL_SET_BLANK_VALUE | AVPFL_SET_RAWDATA_FROM_AVP, &optavp_cpy) ); CHECK_FCT( fd_msg_avp_hdr(optavp, &opt_hdr) ); CHECK_FCT( fd_msg_avp_hdr(optavp_cpy, &optcpy_hdr) );
--- a/libfdproto/messages.c Sat Nov 17 23:28:50 2012 +0100 +++ b/libfdproto/messages.c Mon Nov 19 08:58:40 2012 +0100 @@ -231,6 +231,14 @@ new->avp_public.avp_value = &new->avp_storage; } + if (flags & AVPFL_SET_RAWDATA_FROM_AVP) { + new->avp_rawlen = (*avp)->avp_public.avp_len - GETAVPHDRSZ( (*avp)->avp_public.avp_flags ); + if (new->avp_rawlen) { + CHECK_MALLOC( new->avp_rawdata = malloc(new->avp_rawlen) ); + memset(new->avp_rawdata, 0xFF, new->avp_rawlen); + } + } + /* The new object is ready, return */ *avp = new; return 0;
--- a/tests/testmesg.c Sat Nov 17 23:28:50 2012 +0100 +++ b/tests/testmesg.c Mon Nov 19 08:58:40 2012 +0100 @@ -756,6 +756,7 @@ #if 1 { + unsigned char * buftmp = NULL; /* Check the parse or error works as expected */ CPYBUF(); @@ -766,12 +767,16 @@ CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); CHECK( EBADMSG, fd_msg_parse_or_error( &msg ) ); - TODO("Check the Failed-AVP is as expected"); + CHECK( 0, fd_msg_bufferize( msg, &buftmp, NULL ) ); fd_msg_dump_walk(0, msg); + TODO("Check the Failed-AVP is as expected"); + + /* reset */ CHECK( 0, fd_msg_free ( msg ) ); + free(buftmp); } #endif