Index: include/freeDiameter/libfdproto.h
===================================================================
--- include/freeDiameter/libfdproto.h	(revision 992)
+++ include/freeDiameter/libfdproto.h	(revision 998)
@@ -312,5 +312,5 @@
 
 /* Helper for tracing the CHECK_* macros below -- very very verbose code execution! */
-#define TRACE_DEBUG_ALL( str ) 	\
+#define TRACE_DEBUG_ALL( str... ) 	\
 	TRACE_DEBUG(CALL, str );
 
@@ -479,9 +479,9 @@
 #define CHECK_SYS_DO( __call__, __fallback__  ) { 					\
 	int __ret__;									\
-	TRACE_DEBUG_ALL( "Check SYS: " #__call__ );					\
+	TRACE_DEBUG_ALL( "Check SYS: %s", #__call__ );					\
 	__ret__ = (__call__);								\
 	if (__ret__ < 0) {								\
 		int __err__ = errno;	/* We may handle EINTR here */			\
-		TRACE_ERROR("ERROR: in '" #__call__ "' :\t%s", strerror(__err__));\
+		TRACE_ERROR("ERROR: in '%s' :\t%s",  #__call__ , strerror(__err__));    \
 		__fallback__;								\
 	}										\
@@ -490,9 +490,9 @@
 #define CHECK_SYS( __call__  ) { 							\
 	int __ret__;									\
-	TRACE_DEBUG_ALL( "Check SYS: " #__call__ );					\
+	TRACE_DEBUG_ALL( "Check SYS: %s", #__call__ );					\
 	__ret__ = (__call__);								\
 	if (__ret__ < 0) {								\
 		int __err__ = errno;	/* We may handle EINTR here */			\
-		TRACE_ERROR("ERROR: in '" #__call__ "' :\t%s", strerror(__err__));\
+		TRACE_ERROR("ERROR: in '%s' :\t%s", #__call__ , strerror(__err__));     \
 		return __err__;								\
 	}										\
@@ -502,5 +502,5 @@
 #define CHECK_POSIX_DO2( __call__, __speval__, __fallback1__, __fallback2__ ) {			\
 	int __ret__;										\
-	TRACE_DEBUG_ALL( "Check POSIX: " #__call__ );						\
+	TRACE_DEBUG_ALL( "Check POSIX: %s", #__call__ );					\
 	__ret__ = (__call__);									\
 	if (__ret__ != 0) {									\
@@ -508,5 +508,5 @@
 			__fallback1__;								\
 		} else {									\
-			TRACE_ERROR("ERROR: in '" #__call__ "':\t%s", strerror(__ret__));	\
+			TRACE_ERROR("ERROR: in '%s':\t%s", #__call__, strerror(__ret__));	\
 			__fallback2__;								\
 		}										\
@@ -527,9 +527,9 @@
 #define CHECK_MALLOC_DO( __call__, __fallback__ ) { 					\
 	void *  __ret__;								\
-	TRACE_DEBUG_ALL( "Check MALLOC: " #__call__ );					\
+	TRACE_DEBUG_ALL( "Check MALLOC: %s", #__call__ );				\
 	__ret__ = (void *)( __call__ );							\
 	if (__ret__ == NULL) {								\
 		int __err__ = errno;							\
-		TRACE_ERROR("ERROR: in '" #__call__ "':\t%s", strerror(__err__));	\
+		TRACE_ERROR("ERROR: in '%s':\t%s", #__call__, strerror(__err__));	\
 		__fallback__;								\
 	}										\
@@ -543,7 +543,7 @@
 /* Check parameters at function entry, execute fallback on error */
 #define CHECK_PARAMS_DO( __bool__, __fallback__ )						\
-	TRACE_DEBUG_ALL( "Check PARAMS: " #__bool__ );						\
+	TRACE_DEBUG_ALL( "Check PARAMS: %s", #__bool__ );					\
 	if ( ! (__bool__) ) {									\
-		TRACE_ERROR("Warning: Invalid parameter received in '" #__bool__ "'");	\
+		TRACE_ERROR("Warning: Invalid parameter received in '%s'", #__bool__);		\
 		__fallback__;									\
 	}
@@ -555,8 +555,8 @@
 #define CHECK_FCT_DO( __call__, __fallback__ ) {					\
 	int __ret__;									\
-	TRACE_DEBUG_ALL( "Check FCT: " #__call__ );					\
+	TRACE_DEBUG_ALL( "Check FCT: %s", #__call__ );					\
 	__ret__ = (__call__);								\
 	if (__ret__ != 0) {								\
-		TRACE_ERROR("ERROR: in '" #__call__ "':\t%s", strerror(__ret__));	\
+		TRACE_ERROR("ERROR: in '%s':\t%s", #__call__, strerror(__ret__));	\
 		__fallback__;								\
 	}										\
Index: libfdcore/cnxctx.c
===================================================================
--- libfdcore/cnxctx.c	(revision 982)
+++ libfdcore/cnxctx.c	(revision 999)
@@ -1208,5 +1208,5 @@
 				snprintf(buf, sizeof(buf), "\t - Certificate serial number: ");
 				for (j = 0; j < size; j++) {
-					snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "%02.2hhx", serial[j]);
+					snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "%02hhx", serial[j]);
 				}
 				fd_log_debug(buf);
Index: libfdproto/lists.c
===================================================================
--- libfdproto/lists.c	(revision 740)
+++ libfdproto/lists.c	(revision 1001)
@@ -75,4 +75,5 @@
 void fd_list_move_end(struct fd_list * ref, struct fd_list * senti)
 {
+	struct fd_list * li;
 	ASSERT(ref->head == ref);
 	ASSERT(senti->head == senti);
@@ -80,4 +81,7 @@
 	if (senti->next == senti)
 		return;
+	
+	for (li = senti->next; li != senti; li = li->next)
+		li->head = ref;
 	
 	senti->next->prev = ref->prev;
Index: libfdproto/messages.c
===================================================================
--- libfdproto/messages.c	(revision 995)
+++ libfdproto/messages.c	(revision 1001)
@@ -303,4 +303,6 @@
 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);
+static int parsedict_do_chain(struct dictionary * dict, struct fd_list * head, int mandatory, struct fd_pei *error_info);
+
 
 /* Create answer from a request */
@@ -366,4 +368,7 @@
 	if (! (flags & MSGFL_ANSW_NOPROXYINFO)) {
 		struct avp * avp;
+		struct fd_pei pei;
+		struct fd_list avpcpylist = FD_LIST_INITIALIZER(avpcpylist);
+		
 		CHECK_FCT(  fd_msg_browse(qry, MSG_BRW_FIRST_CHILD, &avp, NULL)  );
 		while (avp) {
@@ -376,18 +381,24 @@
 				size_t offset = 0;
 
+				/* Create a buffer with the content of the AVP. This is easier than going through the list */
 				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) );
+				/* Now we parse this buffer to create a copy AVP */
+				CHECK_FCT( parsebuf_list(buf, avp->avp_public.avp_len, &avpcpylist) );
+				
+				/* Parse dictionary objects now to remove the dependency on the buffer */
+				CHECK_FCT( parsedict_do_chain(dict, &avpcpylist, 0, &pei) );
 
 				/* Done for this AVP */
 				free(buf);
+
+				/* We move this AVP now so that we do not parse again in next loop */
+				fd_list_move_end(&ans->msg_chain.children, &avpcpylist);
 			}
 			/* 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) );
 		}
-		CHECK_FCT( fd_msg_parse_dict( ans, dict, NULL ) );
 	}
 
@@ -1558,13 +1569,13 @@
 		CHECK_PARAMS( avp->avp_source || avp->avp_rawdata );
 		
-		if ( avp->avp_source != NULL ) {
+		if ( avp->avp_rawdata != NULL ) {
+			/* the content was stored in rawdata */
+			memcpy(&buffer[*offset], avp->avp_rawdata, avp->avp_rawlen);
+			*offset += PAD4(avp->avp_rawlen);
+		} else {
 			/* the message was not parsed completely */
 			size_t datalen = avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags);
 			memcpy(&buffer[*offset], avp->avp_source, datalen);
 			*offset += PAD4(datalen);
-		} else {
-			/* the content was stored in rawdata */
-			memcpy(&buffer[*offset], avp->avp_rawdata, avp->avp_rawlen);
-			*offset += PAD4(avp->avp_rawlen);
 		}
 		
@@ -1813,6 +1824,4 @@
  */
 
-static int parsedict_do_chain(struct dictionary * dict, struct fd_list * head, int mandatory, struct fd_pei *error_info);
-
 static char error_message[256];
 
@@ -1821,4 +1830,5 @@
 {
 	struct dict_avp_data dictdata;
+	uint8_t * source;
 	
 	TRACE_ENTRY("%p %p %d %p", dict, avp, mandatory, error_info);
@@ -1913,4 +1923,7 @@
 	}
 	
+	source = avp->avp_source;
+	avp->avp_source = NULL;
+
 	/* Now get the value inside */
 	switch (dictdata.avp_basetype) {
@@ -1919,5 +1932,5 @@
 			
 			/* This is a grouped AVP, so let's parse the list of AVPs inside */
-			CHECK_FCT_DO(  ret = parsebuf_list(avp->avp_source, avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags ), &avp->avp_chain.children),
+			CHECK_FCT_DO(  ret = parsebuf_list(source, avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags ), &avp->avp_chain.children),
 				{
 					if ((ret == EBADMSG) && (error_info)) {
@@ -1927,4 +1940,5 @@
 						error_info->pei_message = error_message;
 					}
+					avp->avp_source = source;
 					return ret;
 				}  );
@@ -1941,13 +1955,14 @@
 						error_info->pei_avp = avp;
 					}
+					avp->avp_source = source;
 					return EBADMSG;
 				} );
 			avp->avp_storage.os.len = avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags );
-			CHECK_MALLOC(  avp->avp_storage.os.data = os0dup(avp->avp_source, avp->avp_storage.os.len)  );
+			CHECK_MALLOC(  avp->avp_storage.os.data = os0dup(source, avp->avp_storage.os.len)  );
 			avp->avp_mustfreeos = 1;
 			break;
 		
 		case AVP_TYPE_INTEGER32:
-			avp->avp_storage.i32 = (int32_t)ntohl(*(uint32_t *)avp->avp_source);
+			avp->avp_storage.i32 = (int32_t)ntohl(*(uint32_t *)source);
 			break;
 	
@@ -1956,5 +1971,5 @@
 			{
 				uint64_t __stor;
-				memcpy(&__stor, avp->avp_source, sizeof(__stor));
+				memcpy(&__stor, source, sizeof(__stor));
 				avp->avp_storage.i64 = (int64_t)ntohll(__stor);
 			}
@@ -1963,5 +1978,5 @@
 		case AVP_TYPE_UNSIGNED32:
 		case AVP_TYPE_FLOAT32: /* For float, we must not cast, or the value is changed. Instead we use implicit cast by changing the member of the union */
-			avp->avp_storage.u32 = (uint32_t)ntohl(*(uint32_t *)avp->avp_source);
+			avp->avp_storage.u32 = (uint32_t)ntohl(*(uint32_t *)source);
 			break;
 	
@@ -1970,5 +1985,5 @@
 			{
 				uint64_t __stor;
-				memcpy(&__stor, avp->avp_source, sizeof(__stor));
+				memcpy(&__stor, source, sizeof(__stor));
 				avp->avp_storage.u64 = (uint64_t)ntohll(__stor);
 			}
Index: tests/tests.h
===================================================================
--- tests/tests.h	(revision 995)
+++ tests/tests.h	(revision 1000)
@@ -69,5 +69,5 @@
 #define FAILTEST( message... ){				\
 	TRACE_ERROR(message);				\
-	TRACE_NOTICE("Test %s failed", __FILE__);	\
+	TRACE_ERROR("FAILED: %s ", __STRIPPED_FILE__);	\
 	exit(FAIL);					\
 }
@@ -75,5 +75,5 @@
 /* Define the macro to pass a test */
 #define PASSTEST( ){					\
-	TRACE_NOTICE("Test %s passed", __FILE__);	\
+	TRACE_NOTICE("PASS: %s", __STRIPPED_FILE__);	\
 	(void)fd_core_shutdown();			\
 	(void)fd_core_wait_shutdown_complete();		\
@@ -89,14 +89,12 @@
 #define CHECK( _val, _assert ){				\
 	if (test_verbo > 0) {				\
-		TRACE_DEBUG(INFO,			\
-			"%s:%-4d: CHECK( " #_assert " == "\
-				#_val " )",		\
-			__FILE__, 			\
-			__LINE__);			\
+		TRACE_NOTICE("CHECK( %s == %s )",	\
+				#_assert,		\
+				#_val);			\
 	}{						\
 	__typeof__ (_val) __ret = (_assert);		\
 	if (__ret != (_val)) {				\
 		FAILTEST( "%s:%d: CHECK FAILED : %s == %lx != %lx",	\
-			__FILE__,			\
+			__STRIPPED_FILE__,		\
 			__LINE__,			\
 			#_assert,			\
@@ -199,5 +197,5 @@
 	CHECK( 0, fd_libproto_init() );
 	
-	fd_log_threadname(basename(fname));
+	fd_log_threadname(fname);
 	
 	/* Parse the command line */
@@ -229,5 +227,5 @@
 	return;
 }
-#define INIT_FD()  test_init(argc, argv, __FILE__);
+#define INIT_FD()  test_init(argc, argv, __STRIPPED_FILE__)
 
 #endif /* _TESTS_H */
