Initial commit

Change-Id: I6a4444e3c193dae437cd7929f4c39aba7b749efa
diff --git a/extensions/test_sip/CMakeLists.txt b/extensions/test_sip/CMakeLists.txt
new file mode 100644
index 0000000..2b2c9e9
--- /dev/null
+++ b/extensions/test_sip/CMakeLists.txt
@@ -0,0 +1,30 @@
+# The test_sip extension
+PROJECT("Diameter-SIP client Test Application (RFC4740)" C)
+
+FIND_PACKAGE(MySQL REQUIRED)
+INCLUDE_DIRECTORIES(${MySQL_INCLUDE_DIR}) 
+
+# List of source files
+SET( TEST_SIP_SRC
+	test_sip.c
+	test_sip.h
+	multimediaauth.c
+	locationinfo.c
+	locationinfosl.c
+	registrationtermination.c
+	userauthorization.c
+	serverassignment.c
+)
+
+# Compile as a module
+FD_ADD_EXTENSION(test_sip ${TEST_SIP_SRC})
+
+TARGET_LINK_LIBRARIES(test_sip ${MySQL_LIBRARIES})
+
+
+####
+## INSTALL section ##
+
+INSTALL(TARGETS test_sip
+	LIBRARY DESTINATION ${INSTALL_EXTENSIONS_SUFFIX}
+	COMPONENT freeDiameter-debug-tools)
diff --git a/extensions/test_sip/locationinfo.c b/extensions/test_sip/locationinfo.c
new file mode 100644
index 0000000..98e89f9
--- /dev/null
+++ b/extensions/test_sip/locationinfo.c
@@ -0,0 +1,122 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Alexandre Westfahl <awestfahl@freediameter.net>						 *
+*													 *
+* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. 	 *		
+*													 *
+* All rights reserved.											 *
+* 													 *
+* Redistribution and use of this software in source and binary forms, with or without modification, are  *
+* permitted provided that the following conditions are met:						 *
+* 													 *
+* * Redistributions of source code must retain the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer.										 *
+*    													 *
+* * Redistributions in binary form must reproduce the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer in the documentation and/or other						 *
+*   materials provided with the distribution.								 *
+* 													 *
+* * Neither the name of the Teraoka Laboratory nor the 							 *
+*   names of its contributors may be used to endorse or 						 *
+*   promote products derived from this software without 						 *
+*   specific prior written permission of Teraoka Laboratory 						 *
+*   													 *
+* 													 *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
+*********************************************************************************************************/
+#include "test_sip.h"
+
+//Called to send a LIR
+int test_sip_LIR_cb()
+{
+	struct dict_object * lir_model=NULL;
+	struct msg * message=NULL;
+	struct avp *avp=NULL;
+	union avp_value value;
+	
+	//Fake values START
+	char *sip_aor="sip:aw-lappy@tera.ics.keio.ac.jp";
+	size_t aor_len=strlen(sip_aor); 
+	char *destination_realm="tera.ics.keio.ac.jp";
+	size_t destination_realmlen=strlen(destination_realm);
+	char *destination_host="suika.tera.ics.keio.ac.jp";
+	size_t destination_hostlen=strlen(destination_host);
+	//Fake values STOP
+	
+	//Create the base message for an RTR
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Location-Info-Request", &lir_model, ENOENT) );
+	CHECK_FCT( fd_msg_new (lir_model, 0, &message));
+	
+	
+		
+	// Create a new session 
+	{
+		CHECK_FCT( fd_msg_new_session( message, (os0_t)"appsip", CONSTSTRLEN("appsip") ) );
+	}
+	
+	//Add the Auth-Application-Id 
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Application_Id, 0, &avp ) );
+		value.i32 = 6;
+		CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add ( message, MSG_BRW_LAST_CHILD, avp) );
+	}
+	
+	//Auth_Session_State
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Session_State, 0, &avp ) );
+		value.i32=1;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+	}
+	
+	//Origin_Host & Origin_Realm
+	CHECK_FCT( fd_msg_add_origin ( message, 0 ));
+	
+	//Destination_Host
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Destination_Host, 0, &avp ) );
+		value.os.data=(unsigned char *)destination_host;
+		value.os.len=destination_hostlen;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+	}
+	//Destination_Realm
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Destination_Realm, 0, &avp ) );
+		value.os.data=(unsigned char *)destination_realm;
+		value.os.len=destination_realmlen;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+	}
+	
+	//SIP_AOR
+	{
+		
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_AOR, 0, &avp ) );
+		value.os.data=(unsigned char *)sip_aor;
+		value.os.len=aor_len;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+			
+	}
+	
+	CHECK_FCT( fd_msg_send( &message, NULL, NULL ));
+	
+	return 0;
+}
+
+int test_sip_LIA_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act)
+{
+	
+	return 0;
+}
diff --git a/extensions/test_sip/locationinfosl.c b/extensions/test_sip/locationinfosl.c
new file mode 100644
index 0000000..53c8494
--- /dev/null
+++ b/extensions/test_sip/locationinfosl.c
@@ -0,0 +1,124 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Alexandre Westfahl <awestfahl@freediameter.net>						 *
+*													 *
+* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. 	 *		
+*													 *
+* All rights reserved.											 *
+* 													 *
+* Redistribution and use of this software in source and binary forms, with or without modification, are  *
+* permitted provided that the following conditions are met:						 *
+* 													 *
+* * Redistributions of source code must retain the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer.										 *
+*    													 *
+* * Redistributions in binary form must reproduce the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer in the documentation and/or other						 *
+*   materials provided with the distribution.								 *
+* 													 *
+* * Neither the name of the Teraoka Laboratory nor the 							 *
+*   names of its contributors may be used to endorse or 						 *
+*   promote products derived from this software without 						 *
+*   specific prior written permission of Teraoka Laboratory 						 *
+*   													 *
+* 													 *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
+*********************************************************************************************************/
+#include "test_sip.h"
+
+//Called to send a LIR
+int test_sipSL_LIR_cb()
+{
+	struct dict_object * lir_model=NULL;
+	struct msg * message=NULL;
+	struct avp *avp=NULL;
+	union avp_value value;
+	
+	//Fake values START
+	char *sip_aor="sip:aw-lappy@tera.ics.keio.ac.jp";
+	size_t aor_len=strlen(sip_aor); 
+	char *destination_realm="tera.ics.keio.ac.jp";
+	size_t destination_realmlen=strlen(destination_realm);
+	char *destination_host="biwa.tera.ics.keio.ac.jp";
+	size_t destination_hostlen=strlen(destination_host);
+	//Fake values STOP
+	
+	//Create the base message for an RTR
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Location-Info-Request", &lir_model, ENOENT) );
+	CHECK_FCT( fd_msg_new (lir_model, 0, &message));
+	
+	
+		
+	// Create a new session 
+	{
+		CHECK_FCT( fd_msg_new_session( message, (os0_t)"appsip", CONSTSTRLEN("appsip") ) );
+	}
+	
+	//Add the Auth-Application-Id 
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Application_Id, 0, &avp ) );
+		value.i32 = 6;
+		CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add ( message, MSG_BRW_LAST_CHILD, avp) );
+	}
+	
+	//Auth_Session_State
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Session_State, 0, &avp ) );
+		value.i32=1;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+	}
+	
+	//Origin_Host & Origin_Realm
+	CHECK_FCT( fd_msg_add_origin ( message, 0 ));
+	
+	//Destination_Host
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Destination_Host, 0, &avp ) );
+		value.os.data=(unsigned char *)destination_host;
+		value.os.len=destination_hostlen;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+	}
+	//Destination_Realm
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Destination_Realm, 0, &avp ) );
+		value.os.data=(unsigned char *)destination_realm;
+		value.os.len=destination_realmlen;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+	}
+	
+	
+	
+	//SIP_AOR
+	{
+		
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_AOR, 0, &avp ) );
+		value.os.data=(unsigned char *)sip_aor;
+		value.os.len=aor_len;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+			
+	}
+	
+	CHECK_FCT( fd_msg_send( &message, NULL, NULL ));
+	
+	return 0;
+}
+
+int test_sipSL_LIA_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act)
+{
+	
+	return 0;
+}
diff --git a/extensions/test_sip/multimediaauth.c b/extensions/test_sip/multimediaauth.c
new file mode 100644
index 0000000..b1edb8d
--- /dev/null
+++ b/extensions/test_sip/multimediaauth.c
@@ -0,0 +1,786 @@
+/********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Alexandre Westfahl <awestfahl@freediameter.net>						 *
+*													 *
+* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. 	 *		
+*													 *
+* All rights reserved.											 *
+* 													 *
+* Redistribution and use of this software in source and binary forms, with or without modification, are  *
+* permitted provided that the following conditions are met:						 *
+* 													 *
+* * Redistributions of source code must retain the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer.										 *
+*    													 *
+* * Redistributions in binary form must reproduce the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer in the documentation and/or other						 *
+*   materials provided with the distribution.								 *
+* 													 *
+* * Neither the name of the Teraoka Laboratory nor the 							 *
+*   names of its contributors may be used to endorse or 						 *
+*   promote products derived from this software without 						 *
+*   specific prior written permission of Teraoka Laboratory 						 *
+*   													 *
+* 													 *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
+********************************************************************************************************/
+#include "test_sip.h"
+
+
+int test_sip_MAA_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act)
+{
+/*
+	struct msg *ans, *qry;
+	struct avp *avp, *a2, *authdataitem;
+	struct msg_hdr * header = NULL;
+	struct avp_hdr * avphdr=NULL, *avpheader=NULL, *avpheader_auth=NULL,*digestheader=NULL;
+	union avp_value val;
+	int found_cnonce=0;
+	struct avp * tempavp=NULL,*sipAuthentication=NULL,*sipAuthenticate=NULL;
+	char * result;
+	char password[51];
+	int idx=0, idx2=0, number_of_auth_items=0,i=0;
+	//Flags and variables for Database
+	int sipurinotstored=0, authenticationpending=0, querylen=0, usernamelen=0;
+	char *query=NULL,*username=NULL;
+	
+	//The nonce we will store and retrieve in session
+	struct ds_nonce *storednonce=NULL;
+	
+	
+	TRACE_ENTRY("%p %p %p %p", msg, avp, sess, act);
+	
+	if (msg == NULL)
+		return EINVAL;
+
+	
+	// Create answer header 
+	qry = *msg;
+	CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, msg, 0 ) );
+	ans = *msg;
+	
+
+
+	// Add the appropriate command code & Auth-Application-Id 
+	{
+		
+		CHECK_FCT( fd_msg_hdr ( *msg, &header ) );
+		header->msg_flags = CMD_FLAG_PROXIABLE;
+		header->msg_code = 286;
+		header->msg_appl = 6;
+		
+		
+		// Add the Auth-Application-Id 
+		{
+			CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Application_Id, 0, &avp ) );
+			ASSERT(avp);
+			val.i32 = header->msg_appl;
+			CHECK_FCT( fd_msg_avp_setvalue ( avp, &val ) );
+			CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, avp) );
+		}
+	}
+	
+	
+	// Add the Auth-Session-State AVP 
+	{
+		
+		CHECK_FCT( fd_msg_search_avp ( qry, sip_dict.Auth_Session_State, &avp) );
+		CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr )  );
+		
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Session_State, 0, &avp ) );
+		CHECK_FCT( fd_msg_avp_setvalue( avp, avphdr->avp_value ) );
+		CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_LAST_CHILD, avp ) );
+	}
+
+	
+	
+	// Check if method is REGISTER then User-Name must be present 
+	{
+		
+		CHECK_FCT( fd_msg_search_avp ( qry, sip_dict.SIP_Method, &avp) );
+		CHECK_FCT( fd_msg_avp_hdr( avp, &avpheader ));
+		
+
+		char *method=NULL;
+		
+		CHECK_FCT( fd_msg_search_avp ( qry, sip_dict.User_Name, &avp) );
+		if(avp!=NULL)
+		{
+			
+			int not_found=1;
+			MYSQL_RES *res=NULL;
+			MYSQL_ROW row;
+			
+			CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr )  );
+			
+			//We allocate the double size of username because at worst it can be all quotes
+			username=malloc(avphdr->avp_value->os.len*2+1);
+			//We purify username not to have forbidden characters
+			usernamelen=mysql_real_escape_string(conn, username, avphdr->avp_value->os.data, avphdr->avp_value->os.len);
+			
+			
+			if((strncmp(avpheader->avp_value->os.data,"REGISTER",avpheader->avp_value->os.len)==0))
+			{
+				not_found=1;
+				
+				//We copy username in query
+				querylen=SQL_GETPASSWORD_LEN + usernamelen;
+				query = malloc(querylen+2);
+				snprintf(query, querylen+1, SQL_GETPASSWORD, username);
+				
+				
+				
+				//We make the query	
+				request_mysql(query);
+				res=mysql_use_result(conn);
+				if(res==NULL)
+				{
+					//We couldn't make the request
+					result="DIAMETER_UNABLE_TO_COMPLY";
+					goto out;
+				}
+			
+			
+			
+				while ((row = mysql_fetch_row(res)) != NULL)
+      				{
+      					if(row[0]!="")
+      					{
+      						strcpy(password,row[0]);
+      						not_found=0;
+      						break;
+      					}
+      				}
+      				mysql_free_result(res);
+      				free(query);
+      				
+      				if(not_found)
+				{
+					TRACE_DEBUG(FULL,"The user %s doesn't exist!",username);
+					result="DIAMETER_ERROR_USER_UNKNOWN";
+					free(username);	
+					goto out;
+				}
+			
+			
+			
+				//Now that we know the user exist, we get the list of AOR owned by this user
+				querylen=SQL_GETSIPAOR_LEN + usernamelen;
+				query = malloc(querylen+2);
+				snprintf(query, querylen+1, SQL_GETSIPAOR, username);
+			
+				//We make the query
+				request_mysql(query);
+				res=mysql_use_result(conn);
+				if(res==NULL)
+				{
+					//We couldn't make the request
+					result="DIAMETER_UNABLE_TO_COMPLY";
+					goto out;
+				}
+			
+				//We retrieve the SIP-AOR from AVP to check if the user can us it
+				CHECK_FCT( fd_msg_search_avp ( qry, sip_dict.SIP_AOR, &avp) );
+				CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr )  );
+			
+				not_found=1;
+				while ((row = mysql_fetch_row(res)) != NULL)
+      				{
+      					if(strncmp(avphdr->avp_value->os.data,row[0],avphdr->avp_value->os.len)==0)
+      					{
+      						not_found=0;
+      						break;
+      					}
+      				}
+      				mysql_free_result(res);
+      				free(query);
+      				
+      				if(not_found)
+				{
+					TRACE_DEBUG(FULL,"The user %s can't use this SIP-AOR!",username);
+					result="DIAMETER_ERROR_IDENTITIES_DONT_MATCH";
+					free(username);	
+					goto out;
+				}
+				
+			}
+
+			CHECK_FCT( fd_msg_search_avp ( qry, sip_dict.SIP_Server_URI, &avp) );
+			CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr ));
+			
+			if(avphdr!=NULL)
+			{
+				char *sipuri=NULL;
+				int sipurilen=0;
+
+				//We allocate the double size of SIP-URI because at worst it can be all quotes
+				sipuri=malloc(avphdr->avp_value->os.len*2+1);
+				//We purify SIP-URI not to have forbidden characters
+				sipurilen=mysql_real_escape_string(conn, sipuri, avphdr->avp_value->os.data, avphdr->avp_value->os.len);
+				
+				
+				//We get the SIP-URI assignated to the user
+				querylen=SQL_GETSIPURI_LEN + usernamelen;
+				query = malloc(querylen+2);
+				snprintf(query, querylen+1, SQL_GETSIPURI, username);
+
+				//We make the query
+				request_mysql(query);
+				res=mysql_use_result(conn);
+				if(res==NULL)
+				{
+					//We couldn't make the request
+					result="DIAMETER_UNABLE_TO_COMPLY";
+					goto out;
+				}
+				not_found=1;
+				while ((row = mysql_fetch_row(res)) != NULL)
+      				{
+      					if(strncmp(avphdr->avp_value->os.data,row[0],avphdr->avp_value->os.len)==0)
+      					{
+      						not_found=0;
+      						break;
+      					}
+      				}
+      				mysql_free_result(res);
+      				free(query);
+
+      				if(not_found)
+				{
+					//We update the SIP_URI for the user and we flag "authentication in progress"
+					querylen=SQL_SETSIPURI_LEN + usernamelen + sipurilen;
+					query = malloc(querylen+2);
+					snprintf(query, querylen+1, SQL_SETSIPURI, sipuri, username);
+			
+					//We make the query
+					request_mysql(query);
+					
+	      				free(query);
+	      				authenticationpending=1;
+				}
+      				free(sipuri);
+				
+			}
+			else
+				sipurinotstored=1;
+
+		}
+		else
+		{
+			result="DIAMETER_USER_NAME_REQUIRED";
+			goto out;
+		}
+
+			
+		free(method);
+
+	}
+
+	
+	//TODO: remove loop for authdataitem because RFC say only one (wait for answer from Garcia)
+	// How many Auth Data Items?
+	CHECK_FCT( fd_msg_search_avp ( qry, sip_dict.SIP_Number_Auth_Items, &avp) );
+	CHECK_FCT( fd_msg_avp_hdr( avp, &avpheader )  );
+	
+	
+	if(avp!=NULL)
+	{
+		CHECK_FCT(fd_msg_search_avp ( qry, sip_dict.SIP_Auth_Data_Item, &avp));
+		CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr )  );
+		
+		if(avp!=NULL)
+		{
+			//First is Authentication Scheme
+			CHECK_FCT(fd_msg_browse ( avp, MSG_BRW_FIRST_CHILD, &avp, NULL) );
+			CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr )  );
+			
+			//Digest-Authentication?
+			if(avphdr->avp_value->i32==0)
+			{
+				
+				for(idx=0;idx<avpheader->avp_value->i32;idx++)
+				{
+					//We look for SIP Auth items
+					CHECK_FCT(fd_msg_browse ( avp, MSG_BRW_WALK, &avp, NULL) );
+					
+					if(avp!=NULL)
+					{
+						
+						CHECK_FCT( fd_msg_avp_hdr( avp,&avphdr ));
+		
+						if(avphdr->avp_code==380) //We only create Auth-Data-Item to answer Auth-Data-Item
+						{
+							// Add the Auth-Data-Item AVP 
+							CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Auth_Data_Item, 0, &authdataitem ) );
+					
+							// Add the Authentication Scheme AVP 
+							{
+								CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Authentication_Scheme, 0, &a2 ) );
+								val.i32=0; //We only know Digest Authentication
+								CHECK_FCT( fd_msg_avp_setvalue( a2, &val ) );
+								CHECK_FCT( fd_msg_avp_add( authdataitem, MSG_BRW_LAST_CHILD, a2 ) );
+							}
+							
+							//We need to know if there is a Cnonce attribute (only in the second MAR request)
+							
+							//CHECK_FCT(fd_msg_browse ( avp, MSG_BRW_WALK, &avp, NULL) );
+							
+							
+							CHECK_FCT(fd_avp_search_avp (avp, sip_dict.Digest_CNonce, &a2 ));
+							
+							if(a2!=NULL)
+								found_cnonce=1;
+							else
+								found_cnonce=0;
+								
+							if(!found_cnonce)
+							{
+								//
+								We are in the case of first access request so we need to challenge the user.
+								
+								TRACE_DEBUG(FULL,"First Authorization in progress...");
+
+								// Create a new session  //this create a new session Id !!!
+								//CHECK_FCT_DO( fd_sess_new( &sess, fd_g_config->cnf_diamid, "test_sip", 7), goto out );
+								
+
+								// Create the SIP-Authenticate AVP 
+								{
+									CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Authenticate, 0, &sipAuthenticate ) );
+								}						
+
+								// Add the Digest QOP AVP 
+								{
+									CHECK_FCT( fd_msg_avp_new ( sip_dict.Digest_QOP, 0, &a2 ) );
+									val.os.data="auth";
+									val.os.len=strlen(val.os.data);
+									CHECK_FCT( fd_msg_avp_setvalue( a2, &val ) );
+									CHECK_FCT( fd_msg_avp_add( sipAuthenticate, MSG_BRW_LAST_CHILD, a2 ) );
+								}
+								// Add the Digest Nonce AVP 
+								{
+									uint8_t buffer[NONCE_SIZE];
+									char nonce[NONCE_SIZE * 2 + 1];
+							
+								
+									gcry_create_nonce ((uint8_t *)buffer, sizeof(buffer));
+							
+									for(i=0;i<NONCE_SIZE;i++)
+										sprintf(&nonce[2 * i], "%2.2hhx", buffer[i]);
+								
+									CHECK_FCT( fd_msg_avp_new ( sip_dict.Digest_Nonce, 0, &a2 ) );
+									
+									
+									//We store the nonce (storednonce structure) inside the session
+									storednonce=malloc(sizeof(struct ds_nonce));
+									memset(storednonce,0,sizeof(struct ds_nonce));
+									CHECK_MALLOC(storednonce->nonce=malloc(NONCE_SIZE*2+1));
+									memcpy(storednonce->nonce,(char *)nonce,NONCE_SIZE*2+1);
+									CHECK_FCT( fd_sess_state_store ( ds_sess_hdl, sess, &storednonce ));  
+									
+									val.os.data=nonce;
+									val.os.len=NONCE_SIZE * 2;
+									
+									CHECK_FCT( fd_msg_avp_setvalue( a2, &val ) );
+									CHECK_FCT( fd_msg_avp_add( sipAuthenticate, MSG_BRW_LAST_CHILD, a2 ) );
+								}
+								// Add the Digest Algorithm AVP 
+								{
+									CHECK_FCT( fd_msg_avp_new ( sip_dict.Digest_Algorithm, 0, &a2 ) );
+									val.os.data="MD5";
+									val.os.len=strlen(val.os.data);
+									CHECK_FCT( fd_msg_avp_setvalue( a2, &val ) );
+									CHECK_FCT( fd_msg_avp_add( sipAuthenticate, MSG_BRW_LAST_CHILD, a2 ) );
+							
+								}
+								// Add the Digest Realm AVP 
+								{
+									tempavp=avp;
+								
+									avpheader_auth=walk_digest(tempavp, 104);
+									if(avpheader_auth!=NULL)
+									{
+										CHECK_FCT( fd_msg_avp_new ( sip_dict.Digest_Realm, 0, &a2 ) );
+										CHECK_FCT( fd_msg_avp_setvalue( a2, avpheader_auth->avp_value ) );
+										CHECK_FCT( fd_msg_avp_add( sipAuthenticate, MSG_BRW_LAST_CHILD, a2 ) );
+								
+									}
+								}
+						
+						
+								//We add SIP Authenticate to Auth Data Item
+								CHECK_FCT( fd_msg_avp_add( authdataitem, MSG_BRW_LAST_CHILD, sipAuthenticate ) );
+								//We add Auth Data Item to Answer
+								CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_LAST_CHILD, authdataitem ) );
+						
+								number_of_auth_items++;
+								if(sipurinotstored)
+									result="DIAMETER_SUCCESS_AUTH_SENT_SERVER_NOT_STORED";
+								else
+									result="DIAMETER_MULTI_ROUND_AUTH";
+								found_cnonce=0;
+							}
+							else
+							{
+								//
+								We are in the case of access request after challenge so we need to check credentials.
+								
+								TRACE_DEBUG(FULL,"Authentication after challenge");
+								
+								// Search the session, retrieve its data 
+								{
+									//int new=0;
+									
+									//TRACE_DEBUG(FULL,"new: *%d*",new);
+									//ASSERT( new == 0 );
+									CHECK_FCT( fd_sess_state_retrieve( ds_sess_hdl, sess, &storednonce ));
+									if(storednonce ==NULL)
+									{
+										result="DIAMETER_UNABLE_TO_COMPLY";
+												
+										if(username!=NULL)
+											free(username);
+										goto out;
+									}
+								}
+								
+								// Create the SIP-Authentication-Info AVP 
+								{
+									CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Authentication_Info, 0, &sipAuthentication ) );
+								}
+								
+								
+							
+								// Add the Digest response Auth AVP 
+								{
+									//uint8_t bufferresp[DIGEST_LEN];
+									//char response[DIGEST_LEN*2+1];
+									int i=0;
+									
+									//We extract all the data we need
+									tempavp=avp;
+									
+									char * digest_username=NULL, *digest_uri=NULL, *digest_response=NULL, *digest_realm=NULL, *digest_nonce=NULL, *digest_method=NULL, *digest_qop=NULL, *digest_algorithm=NULL, *digest_cnonce=NULL, *digest_noncecount=NULL;
+									
+									
+									CHECK_FCT(fd_avp_search_avp (avp, sip_dict.Digest_Nonce, &a2 ));
+									if(a2!=NULL)
+									{
+										CHECK_FCT( fd_msg_avp_hdr( a2, &digestheader )  );
+										if(digestheader!=NULL)
+										{
+											
+											digest_nonce = malloc(digestheader->avp_value->os.len + 1);
+											memcpy(digest_nonce, digestheader->avp_value->os.data,
+											digestheader->avp_value->os.len);
+											digest_nonce[digestheader->avp_value->os.len]='\0';
+											TRACE_DEBUG(FULL,"Element:*%s*",digest_nonce);	
+											TRACE_DEBUG(FULL,"Stored Nonce:*%s*",storednonce->nonce);
+											
+											if(strcmp(digest_nonce,storednonce->nonce)!=0)
+											{
+												free(digest_nonce);
+												free(storednonce->nonce);
+												free(storednonce);
+												result="DIAMETER_UNABLE_TO_COMPLY";
+												
+												if(username!=NULL)
+													free(username);
+												goto out;
+											}
+											
+										}
+											
+									}
+									CHECK_FCT(fd_avp_search_avp (avp, sip_dict.Digest_Response, &a2 ));
+									if(a2!=NULL)
+									{
+										CHECK_FCT( fd_msg_avp_hdr( a2, &digestheader )  );
+										if(digestheader!=NULL)
+										{
+											digest_response = malloc(digestheader->avp_value->os.len + 1);
+											memcpy(digest_response, digestheader->avp_value->os.data,
+											digestheader->avp_value->os.len);
+											digest_response[digestheader->avp_value->os.len]='\0';
+											TRACE_DEBUG(FULL,"Element:*%s*",digest_response);	
+										}
+										
+									}
+									CHECK_FCT(fd_avp_search_avp (avp, sip_dict.Digest_Realm, &a2 ));
+									if(a2!=NULL)
+									{
+										CHECK_FCT( fd_msg_avp_hdr( a2, &digestheader )  );
+										if(digestheader!=NULL)
+										{
+											digest_realm = malloc(digestheader->avp_value->os.len + 1);
+											memcpy(digest_realm, digestheader->avp_value->os.data,
+											digestheader->avp_value->os.len);
+											digest_realm[digestheader->avp_value->os.len]='\0';
+											TRACE_DEBUG(FULL,"Element:*%s*",digest_realm);	
+										}
+									}
+									
+									CHECK_FCT(fd_avp_search_avp (avp, sip_dict.Digest_Method, &a2 ));
+									if(a2!=NULL)
+									{
+										CHECK_FCT( fd_msg_avp_hdr( a2, &digestheader )  );
+										if(digestheader!=NULL)
+										{
+											digest_method = malloc(digestheader->avp_value->os.len + 1);
+											memcpy(digest_method, digestheader->avp_value->os.data,
+											digestheader->avp_value->os.len);
+											digest_method[digestheader->avp_value->os.len]='\0';
+											TRACE_DEBUG(FULL,"Element:*%s*",digest_method);	
+										}
+									}
+									else
+										digest_method="";
+									
+									CHECK_FCT(fd_avp_search_avp (avp, sip_dict.Digest_URI, &a2 ));
+									if(a2!=NULL)
+									{
+										CHECK_FCT( fd_msg_avp_hdr( a2, &digestheader )  );
+										if(digestheader!=NULL)
+										{
+											digest_uri = malloc(digestheader->avp_value->os.len + 1);
+											memcpy(digest_uri, digestheader->avp_value->os.data,
+											digestheader->avp_value->os.len);
+											digest_uri[digestheader->avp_value->os.len]='\0';
+											TRACE_DEBUG(FULL,"Element:*%s*",digest_uri);	
+										}
+									}
+									
+									CHECK_FCT(fd_avp_search_avp (avp, sip_dict.Digest_QOP, &a2 ));
+									if(a2!=NULL)
+									{
+										CHECK_FCT( fd_msg_avp_hdr( a2, &digestheader )  );
+										if(digestheader!=NULL)
+										{
+											digest_qop = malloc(digestheader->avp_value->os.len + 1);
+											memcpy(digest_qop, digestheader->avp_value->os.data,
+											digestheader->avp_value->os.len);
+											digest_qop[digestheader->avp_value->os.len]='\0';
+											TRACE_DEBUG(FULL,"Element:*%s*",digest_qop);	
+										}
+									}
+									else
+										digest_qop=NULL;
+									CHECK_FCT(fd_avp_search_avp (avp, sip_dict.Digest_Algorithm, &a2 ));
+									if(a2!=NULL)
+									{
+										CHECK_FCT( fd_msg_avp_hdr( a2, &digestheader )  );
+										if(digestheader!=NULL)
+										{
+											digest_algorithm = malloc(digestheader->avp_value->os.len + 1);
+											memcpy(digest_algorithm, digestheader->avp_value->os.data,
+											digestheader->avp_value->os.len);
+											digest_algorithm[digestheader->avp_value->os.len]='\0';
+											TRACE_DEBUG(FULL,"Element:*%s*",digest_algorithm);	
+										}
+									}
+									else
+										digest_algorithm=NULL;
+									CHECK_FCT(fd_avp_search_avp (avp, sip_dict.Digest_CNonce, &a2 ));
+									if(a2!=NULL)
+									{
+										CHECK_FCT( fd_msg_avp_hdr( a2, &digestheader )  );
+										if(digestheader!=NULL)
+										{
+											digest_cnonce = malloc(digestheader->avp_value->os.len + 1);
+											memcpy(digest_cnonce, digestheader->avp_value->os.data,
+											digestheader->avp_value->os.len);
+											digest_cnonce[digestheader->avp_value->os.len]='\0';
+											TRACE_DEBUG(FULL,"Element:*%s*",digest_cnonce);	
+										}
+									}
+									else
+										digest_cnonce="";
+									CHECK_FCT(fd_avp_search_avp (avp, sip_dict.Digest_Nonce_Count, &a2 ));
+									if(a2!=NULL)
+									{
+										CHECK_FCT( fd_msg_avp_hdr( a2, &digestheader )  );
+										if(digestheader!=NULL)
+										{
+											digest_noncecount = malloc(digestheader->avp_value->os.len + 1);
+											memcpy(digest_noncecount, digestheader->avp_value->os.data,
+											digestheader->avp_value->os.len);
+											digest_noncecount[digestheader->avp_value->os.len]='\0';
+											TRACE_DEBUG(FULL,"Element:*%s*",digest_noncecount);	
+										}
+									}
+									else
+										digest_noncecount="";
+									CHECK_FCT(fd_avp_search_avp (avp, sip_dict.Digest_Username, &a2 ));
+									if(a2!=NULL)
+									{
+										CHECK_FCT( fd_msg_avp_hdr( a2, &digestheader )  );
+										if(digestheader!=NULL)
+										{
+											digest_username = malloc(digestheader->avp_value->os.len + 1);
+											memcpy(digest_username, digestheader->avp_value->os.data,
+											digestheader->avp_value->os.len);
+											digest_username[digestheader->avp_value->os.len]='\0';
+											TRACE_DEBUG(FULL,"Element:*%s*",digest_username);	
+										}
+									}
+									//TODO: replace by authentication function
+									
+									HASHHEX HA1;
+									HASHHEX HA2 = "";
+									HASHHEX response, responseauth;
+
+									
+									DigestCalcHA1(digest_algorithm, digest_username, digest_realm, password, digest_nonce,digest_cnonce, HA1);
+									
+      							DigestCalcResponse(HA1, digest_nonce, digest_noncecount, digest_cnonce, digest_qop,digest_method, digest_uri, HA2, response);
+      									
+		
+									// We check that the Digest-Response is the same (UA, Diameter)
+									if(strcmp(response,digest_response)!=0)
+									{
+										TRACE_DEBUG(FULL,"Response calculated by Diameter server:%s",response);
+										TRACE_DEBUG(FULL,"Response calculated by UA:%s",digest_response);
+										TRACE_DEBUG(INFO,"Digest-Response does not match!");
+										result="DIAMETER_UNABLE_TO_COMPLY";
+										free(digest_algorithm);
+										free(digest_cnonce);
+										free(digest_nonce);
+										free(digest_noncecount);
+										free(digest_method);
+										free(digest_username);
+										free(digest_uri);
+										free(digest_qop);
+										free(digest_response);
+										free(digest_realm);
+										free(storednonce->nonce);
+										free(storednonce);
+										if(username!=NULL)
+											free(username);
+										goto out;
+										
+									}
+									//We calculate Digest_Response_Auth
+									DigestCalcResponseAuth(HA1, digest_nonce, digest_noncecount, digest_cnonce, digest_qop,digest_method, digest_uri, HA2, responseauth);
+									
+									TRACE_DEBUG(FULL,"Response calculated by Diameter server:%s",response);
+										TRACE_DEBUG(FULL,"Response calculated by UA:%s",digest_response);
+									if(strcmp(digest_qop,"auth-int")==0)
+									{
+										//Digest-HA1 MUST be used instead of Digest-Response-Auth if Digest-Qop is 'auth-int'.
+										CHECK_FCT( fd_msg_avp_new ( sip_dict.Digest_HA1, 0, &a2 ) );
+										val.os.data=HA1;
+										val.os.len=HASHHEXLEN+1;
+										CHECK_FCT( fd_msg_avp_setvalue( a2, &val ) );
+										CHECK_FCT( fd_msg_avp_add( sipAuthentication, MSG_BRW_LAST_CHILD, a2 ) );
+									}
+									else
+									{
+										//Digest-Response-Auth MUST be used instead of Digest-HA1 if Digest-Qop is 'auth'.
+										CHECK_FCT( fd_msg_avp_new ( sip_dict.Digest_Response_Auth, 0, &a2 ) );
+										val.os.data=responseauth;
+										val.os.len=DIGEST_LEN*2;
+										CHECK_FCT( fd_msg_avp_setvalue( a2, &val ) );
+										CHECK_FCT( fd_msg_avp_add( sipAuthentication, MSG_BRW_LAST_CHILD, a2 ) );
+									}
+									free(digest_algorithm);
+									free(digest_cnonce);
+									free(digest_nonce);
+									free(digest_noncecount);
+									free(digest_method);
+									free(digest_username);
+									free(digest_uri);
+									free(digest_qop);
+									free(digest_response);
+									free(digest_realm);
+									free(storednonce->nonce);
+									free(storednonce);
+								
+									number_of_auth_items++;
+								}	
+								
+								
+								//We add SIP Authentication-Info to Auth Data Item
+								CHECK_FCT( fd_msg_avp_add( authdataitem, MSG_BRW_LAST_CHILD, sipAuthentication ) );
+								//We add Auth Data Item to Answer
+								CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_LAST_CHILD, authdataitem ) );
+								
+								
+								if(username!=NULL && authenticationpending)
+								{
+									//We clear the flag "authentication pending"
+									querylen=SQL_CLEARFLAG_LEN + usernamelen;
+									query = malloc(querylen+2);
+									snprintf(query, querylen+1, SQL_CLEARFLAG, username);
+		
+									//We make the query
+									request_mysql(query);
+				
+					      				free(query);
+								}
+								
+								if(sipurinotstored)
+									result="DIAMETER_SUCCESS_SERVER_NAME_NOT_STORED";
+								else
+									result="DIAMETER_SUCCESS";
+								found_cnonce=0;
+							}
+						}
+					}
+					else
+						TRACE_DEBUG(INFO,"No auth data items!");
+				}
+				//Add SIP_Number_Auth_Items  AVP 
+				{
+					CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Number_Auth_Items, 0, &avp ) );
+					val.i32 = number_of_auth_items;
+					CHECK_FCT( fd_msg_avp_setvalue ( avp, &val ) );
+					CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, avp) );
+				}
+				
+				
+			}
+			else
+			{
+				TRACE_DEBUG(INFO,"We only support DIGEST for now, unable to comply");
+				result="DIAMETER_ERROR_AUTH_SCHEME_NOT_SUPPORTED";
+				if(username!=NULL)
+					free(username);
+				goto out;
+			}
+		}
+	}
+	else
+	{
+		//TODO: remove this because Number_Auth_Items is not compulsory
+		TRACE_DEBUG(FULL,"Number-Auth-Items is not included.");
+		result="DIAMETER_UNABLE_TO_COMPLY";
+		if(username!=NULL)
+			free(username);
+		goto out;
+	}
+	
+	if(username!=NULL)
+		free(username);
+	
+
+out:
+	// Set the Origin-Host, Origin-Realm, Result-Code AVPs 
+	CHECK_FCT( fd_msg_rescode_set( ans, result, NULL, NULL, 1 ) );
+	
+	
+	// Send the answer 
+	CHECK_FCT( fd_msg_send( msg, NULL, NULL ) );
+	
+*/	
+	return 0;
+}
+
diff --git a/extensions/test_sip/registrationtermination.c b/extensions/test_sip/registrationtermination.c
new file mode 100644
index 0000000..5286e73
--- /dev/null
+++ b/extensions/test_sip/registrationtermination.c
@@ -0,0 +1,43 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Alexandre Westfahl <awestfahl@freediameter.net>						 *
+*													 *
+* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. 	 *		
+*													 *
+* All rights reserved.											 *
+* 													 *
+* Redistribution and use of this software in source and binary forms, with or without modification, are  *
+* permitted provided that the following conditions are met:						 *
+* 													 *
+* * Redistributions of source code must retain the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer.										 *
+*    													 *
+* * Redistributions in binary form must reproduce the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer in the documentation and/or other						 *
+*   materials provided with the distribution.								 *
+* 													 *
+* * Neither the name of the Teraoka Laboratory nor the 							 *
+*   names of its contributors may be used to endorse or 						 *
+*   promote products derived from this software without 						 *
+*   specific prior written permission of Teraoka Laboratory 						 *
+*   													 *
+* 													 *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
+*********************************************************************************************************/
+#include "test_sip.h"
+
+
+int test_sip_RTR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act)
+{
+	
+	return 0;
+}
diff --git a/extensions/test_sip/serverassignment.c b/extensions/test_sip/serverassignment.c
new file mode 100644
index 0000000..887ed28
--- /dev/null
+++ b/extensions/test_sip/serverassignment.c
@@ -0,0 +1,165 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Alexandre Westfahl <awestfahl@freediameter.net>						 *
+*													 *
+* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. 	 *		
+*													 *
+* All rights reserved.											 *
+* 													 *
+* Redistribution and use of this software in source and binary forms, with or without modification, are  *
+* permitted provided that the following conditions are met:						 *
+* 													 *
+* * Redistributions of source code must retain the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer.										 *
+*    													 *
+* * Redistributions in binary form must reproduce the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer in the documentation and/or other						 *
+*   materials provided with the distribution.								 *
+* 													 *
+* * Neither the name of the Teraoka Laboratory nor the 							 *
+*   names of its contributors may be used to endorse or 						 *
+*   promote products derived from this software without 						 *
+*   specific prior written permission of Teraoka Laboratory 						 *
+*   													 *
+* 													 *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
+*********************************************************************************************************/
+#include "test_sip.h"
+
+//Called to send a UAR
+int test_sip_SAR_cb()
+{
+	struct dict_object * sar_model=NULL;
+	struct msg * message=NULL;
+	struct avp *avp=NULL;
+	union avp_value value;
+	
+	//Fake values START
+	char *sip_aor="sip:aw-lappy@tera.ics.keio.ac.jp";
+	size_t aor_len=strlen(sip_aor); 
+	char *destination_realm="tera.ics.keio.ac.jp";
+	size_t destination_realmlen=strlen(destination_realm);
+	char *destination_host="suika.tera.ics.keio.ac.jp";
+	size_t destination_hostlen=strlen(destination_host);
+	char *username="aw-lappy";
+	size_t usernamelen=strlen(username);
+	char *sipserveruri="sip:ichigo@tera.ics.keio.ac.jp";
+	size_t sipserverurilen=strlen(sipserveruri);
+	// char *visitednetwork="Pink";
+	//size_t visitednetworklen=strlen(visitednetwork);
+	//int registrationtype = 2;
+	int data_already_available=0;
+	int assignment_type=0;
+	//Fake values STOP
+	
+	//Create the base message for an RTR
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Server-Assignment-Request", &sar_model, ENOENT) );
+	CHECK_FCT( fd_msg_new (sar_model, 0, &message));
+	
+	
+	
+	// Create a new session 
+	{
+		CHECK_FCT( fd_msg_new_session( message, (os0_t)"appsip", CONSTSTRLEN("appsip") ) );
+	}
+	
+	//Add the Auth-Application-Id 
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Application_Id, 0, &avp ) );
+		value.i32 = 6;
+		CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add ( message, MSG_BRW_LAST_CHILD, avp) );
+	}	
+	//Auth_Session_State
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Session_State, 0, &avp ) );
+		value.i32=1;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+	}
+	
+	//Origin_Host & Origin_Realm
+	CHECK_FCT( fd_msg_add_origin ( message, 0 ));
+	
+	//Destination_Host
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Destination_Host, 0, &avp ) );
+		value.os.data=(unsigned char *)destination_host;
+		value.os.len=destination_hostlen;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+	}
+	//Destination_Realm
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Destination_Realm, 0, &avp ) );
+		value.os.data=(unsigned char *)destination_realm;
+		value.os.len=destination_realmlen;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+	}
+	
+	//SIP_AOR
+	{
+		
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_AOR, 0, &avp ) );
+		value.os.data=(unsigned char *)sip_aor;
+		value.os.len=aor_len;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+		
+	}
+	//Username
+	{
+		
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.User_Name, 0, &avp ) );
+		value.os.data=(unsigned char *)username;
+		value.os.len=usernamelen;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+		
+	}
+	//SIP_User_Data_Already_Available
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data_Already_Available, 0, &avp ) );
+		value.i32=data_already_available;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+	}
+	
+	//SIP_Server_Assignment_Type;
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Server_Assignment_Type, 0, &avp ) );
+		value.i32=assignment_type;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+	}
+	//SIP_server_uri
+	{
+		
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Server_URI, 0, &avp ) );
+		value.os.data=(unsigned char *)sipserveruri;
+		value.os.len=sipserverurilen;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+		
+	}
+	
+	CHECK_FCT( fd_msg_send( &message, NULL, NULL ));
+	
+	return 0;
+}
+
+int test_sip_SAA_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act)
+{
+	
+	return 0;
+}
diff --git a/extensions/test_sip/test_sip.c b/extensions/test_sip/test_sip.c
new file mode 100644
index 0000000..463fcd9
--- /dev/null
+++ b/extensions/test_sip/test_sip.c
@@ -0,0 +1,241 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Alexandre Westfahl <awestfahl@freediameter.net>						 *
+*													 *
+* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. 	 *		
+*													 *
+* All rights reserved.											 *
+* 													 *
+* Redistribution and use of this software in source and binary forms, with or without modification, are  *
+* permitted provided that the following conditions are met:						 *
+* 													 *
+* * Redistributions of source code must retain the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer.										 *
+*    													 *
+* * Redistributions in binary form must reproduce the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer in the documentation and/or other						 *
+*   materials provided with the distribution.								 *
+* 													 *
+* * Neither the name of the Teraoka Laboratory nor the 							 *
+*   names of its contributors may be used to endorse or 						 *
+*   promote products derived from this software without 						 *
+*   specific prior written permission of Teraoka Laboratory 						 *
+*   													 *
+* 													 *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
+*********************************************************************************************************/
+
+
+#include"test_sip.h"
+
+struct disp_hdl * test_sip_MAR_hdl=NULL;
+struct disp_hdl * test_sip_LIR_hdl=NULL;
+struct disp_hdl * test_sip_UAR_hdl=NULL;
+struct disp_hdl * test_sip_SAR_hdl=NULL;
+struct disp_hdl * test_sip_PPA_hdl=NULL;
+struct disp_hdl * test_sip_RTA_hdl=NULL;
+
+struct disp_hdl * test_sip_MAA_hdl=NULL;
+struct disp_hdl * test_sip_LIA_hdl=NULL;
+struct disp_hdl * test_sip_UAA_hdl=NULL;
+struct disp_hdl * test_sip_SAA_hdl=NULL;
+struct disp_hdl * test_sip_PPR_hdl=NULL;
+struct disp_hdl * test_sip_RTR_hdl=NULL;
+
+
+struct disp_hdl * test_sip_default_hdl=NULL;
+
+//configuration stucture
+struct ts_conf * ts_conf=NULL;
+static struct ts_conf test_sip_conf;
+
+
+//dictionary of SIP
+struct sip_dict sip_dict;
+
+int test_sip_default_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act)
+{
+	TRACE_ENTRY("%p %p %p %p", msg, avp, sess, act);
+	
+	return 0;
+}
+
+
+/*
+void dump_config()
+{
+	TRACE_DEBUG(FULL,"***Configuration of TEST Diameter-SIP extension***");
+	TRACE_DEBUG(FULL,"# username: *%s*",ts_conf->username);
+	TRACE_DEBUG(FULL,"# password: *%s*",ts_conf->password);
+	TRACE_DEBUG(FULL,"# sip_aor: *%s*",ts_conf->sip_aor);
+	TRACE_DEBUG(FULL,"# destination_realm: *%s*",ts_conf->destination_realm);
+	TRACE_DEBUG(FULL,"# destination_sip: *%s*",ts_conf->destination_sip);
+	TRACE_DEBUG(FULL,"***End of TEST Diameter-SIP configuration extension***");
+}
+*/
+static int ts_conf_init(void)
+{
+	ts_conf=&test_sip_conf;
+	//memset(app_sip_conf, 0, sizeof(struct ts_conf));
+	
+
+	return 0;
+}
+
+/* entry point */
+int ts_entry(char * conffile)
+{
+	TRACE_ENTRY("%p", conffile);
+	
+	struct dict_object * app=NULL;
+	struct disp_when data;
+	
+	
+	//TODO: activate again configuration file
+	CHECK_FCT( ts_conf_init() );
+	/* Initialize configuration 
+	//CHECK_FCT( ts_conf_init() );
+	
+	
+	//We parse the configuration file
+	if (conffile != NULL) {
+		CHECK_FCT( ts_conf_handle(conffile) );
+	}
+	else
+	{
+		TRACE_DEBUG(INFO, "We need a configuration file for Diameter-SIP extension. See doc/ for an example.");
+	}
+	
+	//We can dump the configuration extracted from app_sip.conf
+	dump_config();
+	*/
+	
+	
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Diameter Session Initiation Protocol (SIP) Application", &app, ENOENT) );
+	CHECK_FCT( fd_disp_app_support ( app, NULL, 1, 0 ) );
+	
+	
+	
+	//We set useful AVPs 
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Session-State", &sip_dict.Auth_Session_State, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Application-Id", &sip_dict.Auth_Application_Id, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Host", &sip_dict.Destination_Host, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Realm", &sip_dict.Destination_Realm, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &sip_dict.Session_Id, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Redirect-Host", &sip_dict.Redirect_Host, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Redirect-Host-Usage", &sip_dict.Redirect_Host_Usage, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Auth-Data-Item", &sip_dict.SIP_Auth_Data_Item, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authorization", &sip_dict.SIP_Authorization, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authenticate", &sip_dict.SIP_Authenticate, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Number-Auth-Items", &sip_dict.SIP_Number_Auth_Items, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authentication-Scheme", &sip_dict.SIP_Authentication_Scheme, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authentication-Info", &sip_dict.SIP_Authentication_Info, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Server-URI", &sip_dict.SIP_Server_URI, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Server-Capabilities", &sip_dict.SIP_Server_Capabilities, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Mandatory-Capability", &sip_dict.SIP_Mandatory_Capability, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Optional-Capability", &sip_dict.SIP_Optional_Capability, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Method", &sip_dict.SIP_Method, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-AOR", &sip_dict.SIP_AOR, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Deregistration-Reason", &sip_dict.SIP_Deregistration_Reason, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Reason-Code", &sip_dict.SIP_Reason_Code, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Reason-Info", &sip_dict.SIP_Reason_Info, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Accounting-Information", &sip_dict.SIP_Accounting_Information, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Accounting-Server-URI", &sip_dict.SIP_Accounting_Server_URI, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Credit-Control-Server-URI", &sip_dict.SIP_Credit_Control_Server_URI, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Server-Assignment-Type", &sip_dict.SIP_Server_Assignment_Type, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Item-Number", &sip_dict.SIP_Item_Number, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Authorization-Type", &sip_dict.SIP_User_Authorization_Type, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Supported-User-Data-Type", &sip_dict.SIP_Supported_User_Data_Type, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Data", &sip_dict.SIP_User_Data, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Data-Type", &sip_dict.SIP_User_Data_Type, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Data-Contents", &sip_dict.SIP_User_Data_Contents, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Data-Already-Available", &sip_dict.SIP_User_Data_Already_Available, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Visited-Network-Id", &sip_dict.SIP_Visited_Network_Id, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Realm", &sip_dict.Digest_Realm, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-URI", &sip_dict.Digest_URI, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Nonce", &sip_dict.Digest_Nonce, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-CNonce", &sip_dict.Digest_CNonce, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Method", &sip_dict.Digest_Method, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Nonce-Count", &sip_dict.Digest_Nonce_Count, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Realm", &sip_dict.Digest_Realm, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Response", &sip_dict.Digest_Response, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Response-Auth", &sip_dict.Digest_Response_Auth, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Username", &sip_dict.Digest_Username, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Algorithm", &sip_dict.Digest_Algorithm, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-QoP", &sip_dict.Digest_QOP, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "User-Name", &sip_dict.User_Name, ENOENT) );
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-HA1", &sip_dict.Digest_HA1, ENOENT) );
+	
+	
+	//Register Application
+	memset(&data, 0, sizeof(data));
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Diameter Session Initiation Protocol (SIP) Application", &data.app, ENOENT) );
+	
+	
+	//**Command Codes
+	/**/
+	//MAA
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Multimedia-Auth-Answer", &data.command, ENOENT) );
+	CHECK_FCT( fd_disp_register( test_sip_MAA_cb, DISP_HOW_CC, &data, NULL, &test_sip_MAA_hdl ) );
+	
+	//UAA
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "User-Authorization-Answer", &data.command, ENOENT) );
+	CHECK_FCT( fd_disp_register( test_sip_UAA_cb, DISP_HOW_CC, &data, NULL, &test_sip_UAA_hdl ) );
+	
+	//RTR
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Registration-Termination-Request", &data.command, ENOENT) );
+	CHECK_FCT( fd_disp_register( test_sip_RTR_cb, DISP_HOW_CC, &data, NULL, &test_sip_RTR_hdl ) );
+	
+	//LIA
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Location-Info-Answer", &data.command, ENOENT) );
+	CHECK_FCT( fd_disp_register( test_sip_LIA_cb, DISP_HOW_CC, &data, NULL, &test_sip_LIA_hdl ) );
+	
+	//LIA
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Server-Assignment-Answer", &data.command, ENOENT) );
+	CHECK_FCT( fd_disp_register( test_sip_SAA_cb, DISP_HOW_CC, &data, NULL, &test_sip_SAA_hdl ) );
+	
+	//Callback for unexpected messages
+	CHECK_FCT( fd_disp_register( test_sip_default_cb, DISP_HOW_APPID, &data, NULL, &test_sip_default_hdl ) );
+	
+	/*
+	//We start database connection
+	if(start_mysql_connection())
+		return 1;
+	*/
+	
+	//CHECK_FCT( fd_event_trig_regcb(30, "test_sip", (void *)test_sipSL_LIR_cb ) );
+	CHECK_FCT( fd_event_trig_regcb(30, "test_sip", (void *)test_sip_SAR_cb ) );
+	CHECK_FCT( fd_event_trig_regcb(31, "test_sip", (void *)test_sip_LIR_cb ) );
+	
+	return 0;
+}
+
+//Cleanup callback
+void fd_ext_fini(void)
+{
+	/*
+	if (test_sip_MAR_cb) {
+		(void) fd_disp_unregister(&test_sip_MAR_hdl);
+		CHECK_FCT_DO( fd_sess_handler_destroy(&ts_sess_hdl),return);
+	}
+	*/
+	//We close database connection
+	//close_mysql_connection();
+	
+
+	
+	TRACE_ENTRY();
+	return ;
+}
+
+EXTENSION_ENTRY("test_sip", ts_entry, "dict_sip");
+
diff --git a/extensions/test_sip/test_sip.h b/extensions/test_sip/test_sip.h
new file mode 100644
index 0000000..e2ebf21
--- /dev/null
+++ b/extensions/test_sip/test_sip.h
@@ -0,0 +1,125 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Alexandre Westfahl <awestfahl@freediameter.net>						 *
+*													 *
+* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. 	 *		
+*													 *
+* All rights reserved.											 *
+* 													 *
+* Redistribution and use of this software in source and binary forms, with or without modification, are  *
+* permitted provided that the following conditions are met:						 *
+* 													 *
+* * Redistributions of source code must retain the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer.										 *
+*    													 *
+* * Redistributions in binary form must reproduce the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer in the documentation and/or other						 *
+*   materials provided with the distribution.								 *
+* 													 *
+* * Neither the name of the Teraoka Laboratory nor the 							 *
+*   names of its contributors may be used to endorse or 						 *
+*   promote products derived from this software without 						 *
+*   specific prior written permission of Teraoka Laboratory 						 *
+*   													 *
+* 													 *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
+*********************************************************************************************************/
+#include <freeDiameter/extension.h>
+#include <sys/time.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+GCC_DIAG_OFF("-Wdeprecated-declarations")
+#include <gcrypt.h>
+GCC_DIAG_ON("-Wdeprecated-declarations")
+#include <string.h>
+#include <mysql.h>
+
+/* The module configuration */
+struct ts_conf {
+	char * destination_sip; 
+	char * destination_realm;
+	char * username;
+	char * password;
+	char * sip_aor;
+};
+extern struct ts_conf * ts_conf;
+
+//Storage for some useful AVPs
+struct sip_dict{
+	struct dict_object * Auth_Session_State;
+	struct dict_object * Auth_Application_Id;
+	struct dict_object * Destination_Host;
+	struct dict_object * User_Name;
+	struct dict_object * Session_Id;
+	struct dict_object * Redirect_Host;
+	struct dict_object * Redirect_Host_Usage;
+	struct dict_object * SIP_Auth_Data_Item;
+	struct dict_object * SIP_Accounting_Information;
+	struct dict_object * SIP_Accounting_Server_URI;
+	struct dict_object * SIP_Credit_Control_Server_URI;
+	struct dict_object * SIP_Server_Assignment_Type;
+	struct dict_object * SIP_Item_Number;
+	struct dict_object * SIP_User_Authorization_Type;
+	struct dict_object * SIP_Supported_User_Data_Type;
+	struct dict_object * SIP_User_Data;
+	struct dict_object * SIP_User_Data_Type;
+	struct dict_object * SIP_User_Data_Contents;
+	struct dict_object * SIP_User_Data_Already_Available;
+	struct dict_object * SIP_Visited_Network_Id;
+	struct dict_object * SIP_Authorization;
+	struct dict_object * SIP_Authenticate;
+	struct dict_object * SIP_Number_Auth_Items;	
+	struct dict_object * SIP_Authentication_Scheme;
+	struct dict_object * SIP_Authentication_Info;	
+	struct dict_object * SIP_Server_URI;
+	struct dict_object * SIP_Server_Capabilities;
+	struct dict_object * SIP_Mandatory_Capability;
+	struct dict_object * SIP_Optional_Capability;
+	struct dict_object * SIP_Method;
+	struct dict_object * SIP_AOR;
+	struct dict_object * SIP_Deregistration_Reason;
+	struct dict_object * SIP_Reason_Code;
+	struct dict_object * SIP_Reason_Info;
+	struct dict_object * Digest_URI;		
+	struct dict_object * Digest_Nonce;
+	struct dict_object * Digest_Nonce_Count;
+	struct dict_object * Digest_CNonce;		
+	struct dict_object * Digest_Realm;		
+	struct dict_object * Digest_Response;	
+	struct dict_object * Digest_Response_Auth;	
+	struct dict_object * Digest_Username;	
+	struct dict_object * Digest_Method;
+	struct dict_object * Digest_QOP;	
+	struct dict_object * Digest_Algorithm;
+	struct dict_object * Digest_HA1;
+	struct dict_object * Destination_Realm;
+};
+
+extern  struct sip_dict  sip_dict;
+extern struct session_handler * ts_sess_hdl;
+
+int ts_entry();
+void fd_ext_fini(void);
+
+int test_sip_LIR_cb();
+int test_sip_UAR_cb();
+int test_sip_SAR_cb();
+int test_sipSL_LIR_cb();
+
+int test_sip_default_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act);
+int test_sip_MAA_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act);
+int test_sip_RTR_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act);
+int test_sip_UAA_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act);
+int test_sip_LIA_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act);
+int test_sip_SAA_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act);
+int test_sipSL_LIA_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act);
diff --git a/extensions/test_sip/test_sip.l b/extensions/test_sip/test_sip.l
new file mode 100644
index 0000000..668591d
--- /dev/null
+++ b/extensions/test_sip/test_sip.l
@@ -0,0 +1,137 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Alexandre Westfahl <awestfahl@freediameter.net>						 *
+*													 *
+* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. 	 *		
+*													 *
+* All rights reserved.											 *
+* Based on ta_conf.l (Sebastien Decugis <sdecugis@freediameter.net>)					 *
+* 													 *
+* Redistribution and use of this software in source and binary forms, with or without modification, are  *
+* permitted provided that the following conditions are met:						 *
+* 													 *
+* * Redistributions of source code must retain the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer.										 *
+*    													 *
+* * Redistributions in binary form must reproduce the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer in the documentation and/or other						 *
+*   materials provided with the distribution.								 *
+* 													 *
+* * Neither the name of the Teraoka Laboratory nor the 							 *
+*   names of its contributors may be used to endorse or 						 *
+*   promote products derived from this software without 						 *
+*   specific prior written permission of Teraoka Laboratory 						 *
+*   													 *
+* 													 *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
+*********************************************************************************************************/
+
+
+
+%{
+#include "test_sip.h"
+/* Include yacc tokens definitions */
+#include "test_sip.tab.h"
+
+/* Update the column information */
+#define YY_USER_ACTION { 						\
+	yylloc->first_column = yylloc->last_column + 1; 		\
+	yylloc->last_column = yylloc->first_column + yyleng - 1;	\
+}
+
+/* Avoid warning with newer flex */
+#define YY_NO_INPUT
+
+%}
+
+%option bison-bridge bison-locations
+%option noyywrap
+%option nounput
+
+%%
+
+	/* Update the line count */
+\n			{
+				yylloc->first_line++; 
+				yylloc->last_line++; 
+				yylloc->last_column=0; 
+			}
+	 
+	/* Eat all spaces but not new lines */
+([[:space:]]{-}[\n])+	;
+	/* Eat all comments */
+#.*$			;
+
+	/* Recognize any integer */
+[-]?[[:digit:]]+		{
+				/* Convert this to an integer value */
+				int ret=0;
+				ret = sscanf(yytext, "%i", &yylval->integer);
+				if (ret != 1) {
+					/* No matching: an error occurred */
+					fd_log_debug("Unable to convert the value '%s' to a valid number: %s", yytext, strerror(errno));
+					return LEX_ERROR; /* trig an error in yacc parser */
+					/* Maybe we could REJECT instead of failing here? */
+				}
+				return INTEGER;
+			}
+
+	/* Recognize quoted strings -- we do not support escaped \" in the string currently. */
+\"[^\"]+\"		{
+				/* Match a quoted string. Let's be very permissive. */
+				yylval->string = strdup(yytext+1);
+				if (!yylval->string) {
+					fd_log_debug("Unable to copy the string '%s': %s", yytext, strerror(errno));
+					TRACE_DEBUG(INFO, "strdup failed");
+					return LEX_ERROR; /* trig an error in yacc parser */
+				}
+				yylval->string[strlen(yytext) - 2] = '\0';
+				return QSTRING;
+			}
+
+
+
+
+	/* Recognize the tokens */	
+(?i:"username")	{
+				return TESTSIP_USERNAME;
+			}
+
+(?i:"password")		{
+				return TESTSIP_PASSWORD;
+			}
+
+(?i:"sip_aor")		{
+				return TESTSIP_SIPAOR;
+			}
+
+(?i:"destination_realm")		{
+				return TESTSIP_DESTREALM;
+			}
+
+(?i:"destination_sip")		{
+				return TESTSIP_DESTSIP;
+			}
+			
+
+
+			
+	/* Valid single characters for yyparse */
+[=;]			{ return yytext[0]; }
+
+	/* Unrecognized sequence, if it did not match any previous pattern */
+[^[:space:]"*=>;\n]+	{ 
+				fd_log_debug("Unrecognized text on line %d col %d: '%s'.", yylloc->first_line, yylloc->first_column, yytext);
+			 	return LEX_ERROR; 
+			}
+
+%%
diff --git a/extensions/test_sip/test_sip.y b/extensions/test_sip/test_sip.y
new file mode 100644
index 0000000..e699c28
--- /dev/null
+++ b/extensions/test_sip/test_sip.y
@@ -0,0 +1,175 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Alexandre Westfahl <awestfahl@freediameter.net>						 *
+*													 *
+* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. 	 *		
+*													 *
+* All rights reserved.											 *
+* Based on ta_conf.y (Sebastien Decugis <sdecugis@freediameter.net>)					 *
+* 													 *
+* Redistribution and use of this software in source and binary forms, with or without modification, are  *
+* permitted provided that the following conditions are met:						 *
+* 													 *
+* * Redistributions of source code must retain the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer.										 *
+*    													 *
+* * Redistributions in binary form must reproduce the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer in the documentation and/or other						 *
+*   materials provided with the distribution.								 *
+* 													 *
+* * Neither the name of the Teraoka Laboratory nor the 							 *
+*   names of its contributors may be used to endorse or 						 *
+*   promote products derived from this software without 						 *
+*   specific prior written permission of Teraoka Laboratory 						 *
+*   													 *
+* 													 *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
+*********************************************************************************************************/
+
+/* For development only : */
+%debug 
+%error-verbose
+
+/* The parser receives the configuration file filename as parameter */
+%parse-param {char * conffile}
+
+/* Keep track of location */
+%locations 
+%pure-parser
+
+%{
+#include "test_sip.h"
+#include "test_sip.tab.h"	/* bison is not smart enough to define the YYLTYPE before including this code, so... */
+
+#include <string.h>
+#include <errno.h>
+
+/* Forward declaration */
+int yyparse(char * conffile);
+
+/* Parse the configuration file */
+int ts_conf_handle(char * conffile)
+{
+	extern FILE * test_sipin;
+	int ret;
+	
+	TRACE_ENTRY("%p", conffile);
+	
+	TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile);
+	
+	test_sipin = fopen(conffile, "r");
+	if (test_sipin == NULL) {
+		ret = errno;
+		fd_log_debug("Unable to open extension configuration file %s for reading: %s", conffile, strerror(ret));
+		TRACE_DEBUG (INFO, "Error occurred, message logged -- configuration file.");
+		return ret;
+	}
+
+	ret = yyparse(conffile);
+
+	fclose(test_sipin);
+
+	if (ret != 0) {
+		TRACE_DEBUG (INFO, "Unable to parse the configuration file.");
+		return EINVAL;
+	}
+	
+	return 0;
+}
+
+/* The Lex parser prototype */
+int test_sipflex(YYSTYPE *lvalp, YYLTYPE *llocp);
+
+/* Function to report the errors */
+void yyerror (YYLTYPE *ploc, char * conffile, char const *s)
+{
+	TRACE_DEBUG(INFO, "Error in configuration parsing");
+	
+	if (ploc->first_line != ploc->last_line)
+		fd_log_debug("%s:%d.%d-%d.%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s);
+	else if (ploc->first_column != ploc->last_column)
+		fd_log_debug("%s:%d.%d-%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s);
+	else
+		fd_log_debug("%s:%d.%d : %s", conffile, ploc->first_line, ploc->first_column, s);
+}
+
+%}
+
+/* Values returned by lex for token */
+%union {
+	char 		*string;	/* The string is allocated by strdup in lex.*/
+	int		 integer;		/* Store integer values */
+}
+
+/* In case of error in the lexical analysis */
+%token 		LEX_ERROR
+
+/* Key words */
+%token 		TESTSIP_DESTREALM
+%token 		TESTSIP_DESTSIP
+%token 		TESTSIP_PASSWORD
+%token 		TESTSIP_SIPAOR
+%token 		TESTSIP_USERNAME
+
+/* Tokens and types for routing table definition */
+/* A (de)quoted string (malloc'd in lex parser; it must be freed after use) */
+%token <string>	QSTRING
+
+/* An integer value */
+%token <integer> INTEGER
+
+/* -------------------------------------- */
+%%
+
+	/* The grammar definition */
+conffile:		/* empty grammar is OK */
+			| conffile destination_realm
+			| conffile destination_sip
+			| conffile username
+			| conffile password
+			| conffile sip_aor
+			;
+
+destination_realm:			TESTSIP_DESTREALM '=' QSTRING ';'
+			{
+				free(ts_conf->destination_realm);
+				ts_conf->destination_realm = $3;
+			}
+			;
+
+destination_sip:			TESTSIP_DESTSIP '=' QSTRING ';'
+			{
+				free(ts_conf->destination_sip);
+				ts_conf->destination_sip = $3;
+			}
+			;
+
+username:			TESTSIP_USERNAME '=' QSTRING ';'
+			{
+				free(ts_conf->username);
+				ts_conf->username = $3;
+			}
+			;
+
+password:			TESTSIP_PASSWORD '=' QSTRING ';'
+			{
+				free(ts_conf->password);
+				ts_conf->password = $3;
+			}
+			;
+
+sip_aor:			TESTSIP_SIPAOR '=' QSTRING ';'
+			{
+				free(ts_conf->sip_aor);
+				ts_conf->sip_aor = $3;
+			}
+			;
diff --git a/extensions/test_sip/userauthorization.c b/extensions/test_sip/userauthorization.c
new file mode 100644
index 0000000..e07a5ad
--- /dev/null
+++ b/extensions/test_sip/userauthorization.c
@@ -0,0 +1,156 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Alexandre Westfahl <awestfahl@freediameter.net>						 *
+*													 *
+* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. 	 *		
+*													 *
+* All rights reserved.											 *
+* 													 *
+* Redistribution and use of this software in source and binary forms, with or without modification, are  *
+* permitted provided that the following conditions are met:						 *
+* 													 *
+* * Redistributions of source code must retain the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer.										 *
+*    													 *
+* * Redistributions in binary form must reproduce the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer in the documentation and/or other						 *
+*   materials provided with the distribution.								 *
+* 													 *
+* * Neither the name of the Teraoka Laboratory nor the 							 *
+*   names of its contributors may be used to endorse or 						 *
+*   promote products derived from this software without 						 *
+*   specific prior written permission of Teraoka Laboratory 						 *
+*   													 *
+* 													 *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
+*********************************************************************************************************/
+#include "test_sip.h"
+
+//Called to send a UAR
+int test_sip_UAR_cb()
+{
+	struct dict_object * uar_model=NULL;
+	struct msg * message=NULL;
+	struct avp *avp=NULL;
+	union avp_value value;
+	
+	//Fake values START
+	char *sip_aor="sip:aw-lappy@tera.ics.keio.ac.jp";
+	size_t aor_len=strlen(sip_aor); 
+	 char *destination_realm="tera.ics.keio.ac.jp";
+	size_t destination_realmlen=strlen(destination_realm);
+	 char *destination_host="suika.tera.ics.keio.ac.jp";
+	size_t destination_hostlen=strlen(destination_host);
+	 char *username="aw-lappy";
+	size_t usernamelen=strlen(username);
+	 char *visitednetwork="Pink";
+	size_t visitednetworklen=strlen(visitednetwork);
+	int registrationtype = 2;
+	//Fake values STOP
+	
+	//Create the base message for an RTR
+	CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "User-Authorization-Request", &uar_model, ENOENT) );
+	CHECK_FCT( fd_msg_new (uar_model, 0, &message));
+	
+	
+	
+	// Create a new session 
+	{
+		CHECK_FCT( fd_msg_new_session( message, (os0_t)"appsip", CONSTSTRLEN("appsip") ) );
+	}
+	
+	//Add the Auth-Application-Id 
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Application_Id, 0, &avp ) );
+		value.i32 = 6;
+		CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add ( message, MSG_BRW_LAST_CHILD, avp) );
+	}
+	
+	//Auth_Session_State
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Session_State, 0, &avp ) );
+		value.i32=1;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+	}
+	
+	//Origin_Host & Origin_Realm
+	CHECK_FCT( fd_msg_add_origin ( message, 0 ));
+	
+	//Destination_Host
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Destination_Host, 0, &avp ) );
+		value.os.data=(unsigned char *)destination_host;
+		value.os.len=destination_hostlen;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+	}
+	//Destination_Realm
+	{
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.Destination_Realm, 0, &avp ) );
+		value.os.data=(unsigned char *)destination_realm;
+		value.os.len=destination_realmlen;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+	}
+	
+	//SIP_AOR
+	{
+		
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_AOR, 0, &avp ) );
+		value.os.data=(unsigned char *)sip_aor;
+		value.os.len=aor_len;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+		
+	}
+	//Username
+	{
+		
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.User_Name, 0, &avp ) );
+		value.os.data=(unsigned char *)username;
+		value.os.len=usernamelen;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+		
+	}
+	//Visited Network
+	{
+		
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Visited_Network_Id, 0, &avp ) );
+		value.os.data=(unsigned char *)visitednetwork;
+		value.os.len=visitednetworklen;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+		
+	}
+	//Authorization Type
+	{
+		
+		CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Authorization_Type, 0, &avp ) );
+		value.i32=registrationtype;
+		CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
+		CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
+		
+	}
+	
+	CHECK_FCT( fd_msg_send( &message, NULL, NULL ));
+	
+	return 0;
+}
+
+int test_sip_UAA_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act)
+{
+	
+	return 0;
+}