changeset 891:9432ac55823c

Tentative fix for the parse_or_error function
author Sebastien Decugis <sdecugis@freediameter.net>
date Sat, 17 Nov 2012 23:28:50 +0100
parents 19a261c9a2e1
children b2e8f1a3ef76
files include/freeDiameter/libfdproto.h libfdcore/messages.c libfdproto/messages.c tests/testmesg.c
diffstat 4 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/include/freeDiameter/libfdproto.h	Sat Nov 17 22:54:24 2012 +0100
+++ b/include/freeDiameter/libfdproto.h	Sat Nov 17 23:28:50 2012 +0100
@@ -2523,7 +2523,7 @@
 /* Parsing Error Information structure */
 struct fd_pei {
 	char *		pei_errcode;	/* name of the error code to use */
-	struct avp *	pei_avp;	/* pointer to invalid or missing AVP (to be freed) */
+	struct avp *	pei_avp;	/* pointer to invalid (in original message) or missing AVP (to be freed) */
 	char *		pei_message;	/* Overwrite default message if needed */
 	int		pei_protoerr; 	/* do we set the 'E' bit in the error message ? */
 };
--- a/libfdcore/messages.c	Sat Nov 17 22:54:24 2012 +0100
+++ b/libfdcore/messages.c	Sat Nov 17 23:28:50 2012 +0100
@@ -233,11 +233,21 @@
 	
 	/* Now add the optavp in a FailedAVP if provided */
 	if (optavp) {
+		struct avp * optavp_cpy = NULL;
+		struct avp_hdr *opt_hdr, *optcpy_hdr;
+		
 		/* Create the Failed-AVP AVP */
 		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) );
+		
+		CHECK_FCT( fd_msg_avp_hdr(optavp, &opt_hdr) );
+		CHECK_FCT( fd_msg_avp_hdr(optavp_cpy, &optcpy_hdr) );
+		memcpy(optcpy_hdr, opt_hdr, sizeof(struct avp_hdr));
+		
 		/* Add the passed AVP inside it */
-		CHECK_FCT( fd_msg_avp_add( avp_FAVP, MSG_BRW_LAST_CHILD, optavp ) );
+		CHECK_FCT( fd_msg_avp_add( avp_FAVP, MSG_BRW_LAST_CHILD, optavp_cpy ) );
 		
 		/* And add to the message */
 		CHECK_FCT( fd_msg_avp_add( msg, MSG_BRW_LAST_CHILD, avp_FAVP ) );
--- a/libfdproto/messages.c	Sat Nov 17 22:54:24 2012 +0100
+++ b/libfdproto/messages.c	Sat Nov 17 23:28:50 2012 +0100
@@ -1778,6 +1778,7 @@
 			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]);
 			error_info->pei_message = error_message;
 		}
+		avp->avp_model = NULL;
 		return EBADMSG;
 	}
 	
--- a/tests/testmesg.c	Sat Nov 17 22:54:24 2012 +0100
+++ b/tests/testmesg.c	Sat Nov 17 23:28:50 2012 +0100
@@ -766,14 +766,12 @@
 				CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) );
 				CHECK( EBADMSG, fd_msg_parse_or_error( &msg ) );
 				
-				/* Check the Failed-AVP is as expected */
+				TODO("Check the Failed-AVP is as expected");
 				
 				fd_msg_dump_walk(0, msg);
 				
 				/* reset */
 				CHECK( 0, fd_msg_free ( msg ) );
-				
-				ASSERT(0);
 			}
 #endif			
 			
"Welcome to our mercurial repository"