changeset 995:2016a0c46bda

Fixed Proxy-Info duplication, added a test case for this
author Sebastien Decugis <sdecugis@freediameter.net>
date Mon, 18 Mar 2013 16:19:47 +0100
parents 1e1d6f94cd94
children cf09fde3d7f5
files libfdproto/messages.c tests/testmesg.c tests/tests.h
diffstat 3 files changed, 101 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libfdproto/messages.c	Mon Mar 18 13:22:07 2013 +0100
+++ b/libfdproto/messages.c	Mon Mar 18 16:19:47 2013 +0100
@@ -388,6 +388,7 @@
 			/* 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 ) );
 	}
 
 	/* associate with query */
@@ -762,7 +763,7 @@
 		msg->msg_public.msg_hbhid,
 		msg->msg_public.msg_eteid
 		) );
-	CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "intern: rwb:%p rt:%d cb:%p(%p) qry:%p asso:%d sess:%p src:%s(%zd)|", 
+	CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "intern: rwb:%p rt:%d cb:%p(%p) qry:%p asso:%d sess:%p src:%s(%zd)|\n", 
 			INOBJHDRVAL, msg->msg_rawbuffer, msg->msg_routable, msg->msg_cb.fct, msg->msg_cb.data, msg->msg_query, msg->msg_associated, msg->msg_sess, msg->msg_src_id?:"(nil)", msg->msg_src_id_len) );
 	return 0;
 }
@@ -819,7 +820,7 @@
 		}
 	}
 
-	CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "intern: src:%p mf:%d raw:%p(%d)|", INOBJHDRVAL, avp->avp_source, avp->avp_mustfreeos, avp->avp_rawdata, avp->avp_rawlen) );
+	CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "intern: src:%p mf:%d raw:%p(%d)|\n", INOBJHDRVAL, avp->avp_source, avp->avp_mustfreeos, avp->avp_rawdata, avp->avp_rawlen) );
 	return 0;
 }
 
--- a/tests/testmesg.c	Mon Mar 18 13:22:07 2013 +0100
+++ b/tests/testmesg.c	Mon Mar 18 16:19:47 2013 +0100
@@ -754,7 +754,6 @@
 				CHECK( 0, fd_msg_free ( msg ) );
 			}
 			
-#if 1
 			{
 				unsigned char * buftmp = NULL;
 				/* Check the parse or error works as expected */
@@ -778,7 +777,6 @@
 				CHECK( 0, fd_msg_free ( msg ) );
 				free(buftmp);
 			}
-#endif			
 			
 			
 			CHECK( 0, fd_msg_parse_buffer( &buf, 344, &msg) );
@@ -920,6 +918,102 @@
 				}
 			}
 		}
+		
+		/* Test the fd_msg_new_answer_from_req function */
+		{
+			struct dict_object * cmd_model = NULL;
+			struct msg         * msg = NULL;
+			struct avp * pi1, *pi2, *avp;
+			char * host1="host1", * host2="host2";
+			union avp_value      value;
+			struct msg_hdr * msgdata = NULL;
+			
+			CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Test-Command-Request", &cmd_model, ENOENT ) );
+			
+			/* Test default behavior without flags */
+			{ 
+				/* Create a message with some AVPs inside */
+				CHECK( 0, fd_msg_new ( cmd_model, 0, &msg ) );
+				CHECK( 0, fd_msg_hdr ( msg, &msgdata ) );
+				
+				/* Add a session id */
+				CHECK( 0, fd_msg_new_session( msg, "testmsg", strlen("testmsg") ) );
+				
+				/* Create two instances of Proxy-Info */
+				ADD_AVP( msg, MSG_BRW_LAST_CHILD, pi1, 0, "Proxy-Info");
+				ADD_AVP( msg, MSG_BRW_LAST_CHILD, pi2, 0, "Proxy-Info");
+
+				ADD_AVP( pi1, MSG_BRW_LAST_CHILD, avp, 0, "Proxy-State");
+				value.os.data = "ps_pi1";
+				value.os.len = strlen(value.os.data);
+				CHECK( 0, fd_msg_avp_setvalue ( avp, &value ) );
+				
+				ADD_AVP( pi2, MSG_BRW_LAST_CHILD, avp, 0, "Proxy-State");
+				value.os.data = "pi2_state";
+				value.os.len = strlen(value.os.data);
+				CHECK( 0, fd_msg_avp_setvalue ( avp, &value ) );
+				
+				ADD_AVP( pi1, MSG_BRW_FIRST_CHILD, avp, 0, "Proxy-Host");
+				value.os.data = host1;
+				value.os.len = strlen(host1);
+				CHECK( 0, fd_msg_avp_setvalue ( avp, &value ) );
+				
+				ADD_AVP( pi2, MSG_BRW_LAST_CHILD, avp, 0, "Proxy-Host");
+				value.os.data = host2;
+				value.os.len = strlen(host2);
+				CHECK( 0, fd_msg_avp_setvalue ( avp, &value ) );
+				
+				ADD_AVP( pi2, MSG_BRW_LAST_CHILD, avp, 73565, "AVP Test - i64");
+				value.i64 = 0x123456789abcdeLL;
+				CHECK( 0, fd_msg_avp_setvalue ( avp, &value ) );
+				
+				
+				/* Now call the fd_msg_new_answer_from_req function */
+				CHECK( 0, fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, &msg, 0 ) );
+				
+				/* Check there is a Session-Id AVP */
+				{
+					struct session * sess;
+					int new;
+					CHECK( 0, fd_msg_sess_get(fd_g_config->cnf_dict, msg, &sess, &new) );
+					CHECK( 1, sess == NULL ? 0 : 1 );
+					CHECK( 0, new ? 1 : 0 );
+				}
+				
+				/* Check there are two Proxy-Info with the two hosts */
+				{
+					int got_h1 = 0, got_h2=0;
+					struct dict_object * ph_model;
+					CHECK( 0, fd_msg_browse ( msg, MSG_BRW_FIRST_CHILD, &avp, NULL) );
+					while(avp) {
+						struct avp_hdr * avpdata = NULL;
+						CHECK( 0, fd_msg_avp_hdr ( avp, &avpdata ) );
+						if (avpdata->avp_code == AC_PROXY_INFO) {
+							struct avp * iavp;
+							CHECK( 0, fd_msg_browse ( avp, MSG_BRW_FIRST_CHILD, &iavp, NULL) );
+							while(iavp) {
+								struct avp_hdr * iavpdata = NULL;
+								CHECK( 0, fd_msg_avp_hdr ( iavp, &iavpdata ) );
+								if (iavpdata->avp_code == AC_PROXY_HOST) {
+									if (!memcmp(host1, iavpdata->avp_value->os.data, strlen(host1)))
+										got_h1++;
+									if (!memcmp(host2, iavpdata->avp_value->os.data, strlen(host2)))
+										got_h2++;
+								}
+								CHECK( 0, fd_msg_browse ( iavp, MSG_BRW_NEXT, &iavp, NULL) );
+							}
+						}
+						
+						CHECK( 0, fd_msg_browse ( avp, MSG_BRW_NEXT, &avp, NULL) );
+					}
+					
+					CHECK(1, got_h1);
+					CHECK(1, got_h2);
+				}
+				
+			}
+			
+		}
 	}
 	
 	/* Test the msg_avp_value_interpret and msg_avp_value_encode functions. use the Address type and Host-IP-Address AVPs */
--- a/tests/tests.h	Mon Mar 18 13:22:07 2013 +0100
+++ b/tests/tests.h	Mon Mar 18 16:19:47 2013 +0100
@@ -68,14 +68,13 @@
 /* Define the macro to fail a test with a message */
 #define FAILTEST( message... ){				\
 	TRACE_ERROR(message);				\
-	TRACE_DEBUG(INFO, "Test failed");		\
+	TRACE_NOTICE("Test %s failed", __FILE__);	\
 	exit(FAIL);					\
 }
 
 /* Define the macro to pass a test */
 #define PASSTEST( ){					\
 	TRACE_NOTICE("Test %s passed", __FILE__);	\
-	TRACE_DEBUG(INFO, "Test passed");		\
 	(void)fd_core_shutdown();			\
 	(void)fd_core_wait_shutdown_complete();		\
 	(void)fd_thr_term(&signal_thr);			\
@@ -89,7 +88,7 @@
 /* Define the standard check routines */
 #define CHECK( _val, _assert ){				\
 	if (test_verbo > 0) {				\
-		TRACE_ERROR(				\
+		TRACE_DEBUG(INFO,			\
 			"%s:%-4d: CHECK( " #_assert " == "\
 				#_val " )",		\
 			__FILE__, 			\
"Welcome to our mercurial repository"