changeset 109:7fe2dff0424e

Fix computing of size for groups of AVP
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 29 Jul 2008 13:54:08 +0900
parents 219c6d78480f
children 2fb02c5fdf16
files waaad/message.c waaad/tests/testmesg.c
diffstat 2 files changed, 22 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/waaad/message.c	Mon Jul 28 18:32:55 2008 +0900
+++ b/waaad/message.c	Tue Jul 29 13:54:08 2008 +0900
@@ -738,7 +738,7 @@
 		
 		case AVP_TYPE_OCTETSTRING:
 			memcpy(&buffer[*offset], avp->avp_public.avp_data->os.data, avp->avp_public.avp_data->os.len);
-			*offset += avp->avp_public.avp_data->os.len;
+			*offset += PAD4(avp->avp_public.avp_data->os.len);
 			break;
 		
 		case AVP_TYPE_INTEGER32:
@@ -786,9 +786,6 @@
 	TRACE_ENTRY("%p %d %p %p", buffer, buflen, offset, list);
 	
 	for (avpch = list->next; avpch != list; avpch = avpch->next) {
-		/* Re-align the offset if needed */
-		*offset = PAD4(*offset);
-		
 		/* Bufferize the AVP */
 		ret = _msg_buf_avp(buffer, buflen, offset, _A(avpch->top));
 		if (ret != 0) {
@@ -1978,7 +1975,7 @@
 	{
 		_msg_list_t * ch = NULL;
 		
-		/* Compute the header size first */
+		/* First, compute the header size */
 		if (_C(object)->type == _MSG_AVP) 
 			sz = GETAVPHDRSZ( _A(object)->avp_public.avp_flags );
 		else
@@ -1992,8 +1989,8 @@
 				return ret;
 			}
 			
-			/* Pad any previous size to 32b boundary, and add the child length */
-			sz = PAD4( sz ) + _A(ch->top)->avp_public.avp_len;
+			/* Add the padded size to the parent */
+			sz += PAD4( _A(ch->top)->avp_public.avp_len );
 		}
 	}
 	
--- a/waaad/tests/testmesg.c	Mon Jul 28 18:32:55 2008 +0900
+++ b/waaad/tests/testmesg.c	Tue Jul 29 13:54:08 2008 +0900
@@ -452,9 +452,9 @@
 				CHECK( 'T', avpdata->avp_data->os.data[0] );
 			}
 
-			/* Check the size of the message is 20 (header) + 12 + 20 + 16 * 3 + 101 = 201 */
+			/* Check the size of the message is 20 (header) + 12 + 20 + 16 * 3 + 101 + 3 (padding) = 204 */
 			CHECK( 0, msg_update_length ( msg ) );
-			CHECK( 201, msgdata->msg_length );
+			CHECK( 204, msgdata->msg_length );
 			
 			/* Add an octetstring from an enumerated constant */
 			ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - enumos" );
@@ -507,9 +507,9 @@
 			}
 				
 
-			/* Check the size of the message is 20 (header) + 12 + 20 + 16 * 3 + (101 + 3) + (17 + 3) + 15 = 239 */
+			/* Check the size of the message is 20 (header) + 12 + 20 + 16 * 3 + (101 + 3) + (17 + 3) + (15 + 1) = 240 */
 			CHECK( 0, msg_update_length ( msg ) );
-			CHECK( 239, msgdata->msg_length );
+			CHECK( 240, msgdata->msg_length );
 			
 			/* Now test the grouped AVPs */	
 			ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - grouped" );
@@ -537,10 +537,10 @@
 				#endif
 			  }
 			
-			/* Check the size is updated recursively: (gavp hdr: 12) + (avp1: 20) + (avp2: 21) = 53 */
+			/* Check the size is updated recursively: (gavp hdr: 12) + (avp1: 20) + (avp2: 21 + 3) = 56 */
 			CHECK( 0, msg_update_length ( avpi ) );
 			CHECK( 0, msg_avp_data ( avpi, &avpdata ) );
-			CHECK( 53, avpdata->avp_len );
+			CHECK( 56, avpdata->avp_len );
 			
 			/* Add another similar grouped AVP, to have lot of padding */
 			ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - grouped" );
@@ -559,15 +559,15 @@
 			
 			/* Now check the global size of the message, if padding is correctly handled */
 			/* size = 20 (header) + 12 + 20 + 16 * 3 + (101 + 3) + (17 + 3) + (15 + 1) 
-			 *        + ( 12 + ( 20 + 21) + 3 )     # padding for the grouped AVP = 3
-			 *        + ( 12 + ( (13 + 3) + 19 ) )  # The first inner AVP is padded, but not the gavp since no AVP follow  
-			 * size = 240 + 56 + 47 = 343
+			 *        + ( 12 + ( 20 + 21) + 3 )         # padding for the grouped AVP = 3
+			 *        + ( 12 + ( (13 + 3) + 19 ) + 1 )  # and 1 for this one
+			 * size = 240 + 56 + 48 = 344
 			 */
 			CHECK( 0, msg_update_length ( msg ) );
 			#if 0
 			msg_dump_walk(msg);
 			#endif
-			CHECK( 343, msgdata->msg_length );
+			CHECK( 344, msgdata->msg_length );
 			
 			/* Set the application to the test application: 73566 */
 			msgdata->msg_appl = 73566;
@@ -585,9 +585,9 @@
 			
 			/* Test the first bytes */
 			CHECK( 0x01, buf[0] ); /* Version */
-			CHECK( 0x00, buf[1] ); /* Length: 343 = 0x000157 */
+			CHECK( 0x00, buf[1] ); /* Length: 344 = 0x000158 */
 			CHECK( 0x01, buf[2] );
-			CHECK( 0x57, buf[3] );
+			CHECK( 0x58, buf[3] );
 			CHECK( 0x80, buf[4] ); /* flags: only "R" is set. */
 			CHECK( 0x01, buf[5] ); /* Command code: 73573 = 0x011F65 */
 			CHECK( 0x1F, buf[6] );
@@ -633,7 +633,7 @@
 		/* Test the msg_parse_buffer function */
 		{
 			CHECK( EBADMSG, msg_parse_buffer( buf, 340, &msg) );
-			CHECK( 0, msg_parse_buffer( buf, 343, &msg) );
+			CHECK( 0, msg_parse_buffer( buf, 344, &msg) );
 			#if 0
 			msg_dump_walk(msg);
 			#endif
@@ -648,7 +648,7 @@
 				
 				/* Change the command-code */
 				buf[5] = 0x11;
-				CHECK( 0, msg_parse_buffer( buf, 343, &msg) );
+				CHECK( 0, msg_parse_buffer( buf, 344, &msg) );
 				CHECK( ENOTSUP, msg_parse_dict( msg ) );
 				
 				/* reset */
@@ -662,7 +662,7 @@
 				buf[24] = 0x40; /* Add the 'M' flag */
 				
 				/* Check that we cannot support this message now */
-				CHECK( 0, msg_parse_buffer( buf, 343, &msg) );
+				CHECK( 0, msg_parse_buffer( buf, 344, &msg) );
 				CHECK( ENOTSUP, msg_parse_dict( msg ) );
 				
 				/* reset */
@@ -676,7 +676,7 @@
 				buf[20] = 0x11;	/* New AVP code = 0x11011F5F, undefined */
 				
 				/* Check that we can support this message now */
-				CHECK( 0, msg_parse_buffer( buf, 343, &msg) );
+				CHECK( 0, msg_parse_buffer( buf, 344, &msg) );
 				CHECK( 0, msg_parse_dict( msg ) );
 				
 				#if 0
@@ -701,14 +701,14 @@
 				buf[20] = 0x00;
 			}
 			
-			CHECK( 0, msg_parse_buffer( buf, 343, &msg) );
+			CHECK( 0, msg_parse_buffer( buf, 344, &msg) );
 			CHECK( 0, msg_parse_dict( msg ) );
 			#if 0
 			msg_dump_walk(msg);
 			#endif
 			
 			/* Now we can free the buffer. */
-			memset(buf, 0, 343);
+			memset(buf, 0, 344);
 			free(buf);
 		}
 		
"Welcome to our mercurial repository"