Index: doc/app_sip.conf.sample
===================================================================
--- doc/app_sip.conf.sample	(revision 392)
+++ doc/app_sip.conf.sample	(revision 432)
@@ -1,6 +1,11 @@
 
 # MODE Diameter-SIP server (DSSERVER) or Subscriber Locator (SL)
+#You must have at least in your network a Diameter SIP server and a Subscriber Locator (on different nodes)
 mode = DSSERVER;
 
+
+#******************#
+#*****DATABASE*****#
+#******************#
 # DATASOURCE: MYSQL
 datasource = MYSQL;
@@ -11,3 +16,8 @@
 mysql_database = "db";
 mysql_server = "server.fr";
+
+#If value=0, default port for mysql will be set
 mysql_port = 0;
+
+#Prefix for tables (default is "ds")
+mysql_prefix = "ds";
Index: doc/app_sip.sql
===================================================================
--- doc/app_sip.sql	(revision 432)
+++ doc/app_sip.sql	(revision 432)
@@ -0,0 +1,117 @@
+--Can be used in phpMyAdmin
+
+SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
+
+--
+-- DIAMETER SERVER DATABASE
+--
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `ds_data_types`
+--
+
+CREATE TABLE IF NOT EXISTS `ds_data_types` (
+  `id_data_type` int(11) NOT NULL AUTO_INCREMENT,
+  `label_type` varchar(255) NOT NULL,
+  PRIMARY KEY (`id_data_type`)
+) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `ds_networks`
+--
+
+CREATE TABLE IF NOT EXISTS `ds_networks` (
+  `id_network` int(11) NOT NULL AUTO_INCREMENT,
+  `label_network` varchar(255) NOT NULL,
+  PRIMARY KEY (`id_network`)
+) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `ds_sip_aor`
+--
+
+CREATE TABLE IF NOT EXISTS `ds_sip_aor` (
+  `id_sip_aor` int(11) NOT NULL AUTO_INCREMENT,
+  `id_user` int(11) NOT NULL,
+  `sip_aor` varchar(255) NOT NULL,
+  `sip_server_uri` varchar(255) DEFAULT NULL,
+  `registered` tinyint(1) NOT NULL DEFAULT '0',
+  PRIMARY KEY (`id_sip_aor`,`id_user`)
+) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `ds_sip_services`
+--
+
+CREATE TABLE IF NOT EXISTS `ds_sip_services` (
+  `id_service` int(11) NOT NULL AUTO_INCREMENT,
+  `label_service` varchar(255) NOT NULL,
+  PRIMARY KEY (`id_service`)
+) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `ds_users`
+--
+
+CREATE TABLE IF NOT EXISTS `ds_users` (
+  `id_user` int(11) NOT NULL AUTO_INCREMENT,
+  `username` varchar(50) NOT NULL,
+  `password` varchar(50) NOT NULL,
+  `SIP_Server_URI` varchar(255) DEFAULT NULL,
+  `temp_SIP_Server_URI` varchar(255) DEFAULT NULL,
+  `authentication_pending` tinyint(1) NOT NULL DEFAULT '0',
+  `registrated` tinyint(1) NOT NULL DEFAULT '0',
+  PRIMARY KEY (`id_user`)
+) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `ds_user_data`
+--
+
+CREATE TABLE IF NOT EXISTS `ds_user_data` (
+  `id_user_data` int(11) NOT NULL AUTO_INCREMENT,
+  `id_sip_aor` int(11) NOT NULL,
+  `id_data_type` int(11) NOT NULL,
+  `data` longblob NOT NULL,
+  PRIMARY KEY (`id_user_data`,`id_sip_aor`,`id_data_type`)
+) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `ds_user_networks`
+--
+
+CREATE TABLE IF NOT EXISTS `ds_user_networks` (
+  `id_user_network` int(11) NOT NULL AUTO_INCREMENT,
+  `id_user` int(11) NOT NULL,
+  `id_network` int(11) NOT NULL,
+  PRIMARY KEY (`id_user_network`,`id_user`)
+) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `ds_user_services`
+--
+
+CREATE TABLE IF NOT EXISTS `ds_user_services` (
+  `id_user_service` int(11) NOT NULL AUTO_INCREMENT,
+  `id_user` int(11) NOT NULL,
+  `id_service` int(11) NOT NULL,
+  `compulsory` tinyint(1) NOT NULL DEFAULT '0',
+  PRIMARY KEY (`id_user_service`,`id_user`)
+) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
+
Index: doc/app_sip_SL.sql
===================================================================
--- doc/app_sip_SL.sql	(revision 432)
+++ doc/app_sip_SL.sql	(revision 432)
@@ -0,0 +1,21 @@
+
+
+SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
+
+--
+-- SUBSCRIBER LOCATOR DATABASE
+--
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `ds_sip_aor_map`
+--
+
+CREATE TABLE IF NOT EXISTS `ds_sip_aor_map` (
+  `id_map` int(11) NOT NULL AUTO_INCREMENT,
+  `sip_aor` varchar(255) NOT NULL,
+  `diameter_uri` varchar(255) NOT NULL,
+  PRIMARY KEY (`id_map`)
+) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
+
Index: extensions/app_sip/README
===================================================================
--- extensions/app_sip/README	(revision 432)
+++ extensions/app_sip/README	(revision 432)
@@ -0,0 +1,39 @@
+/*********************************************************************************************************
+* 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.								 *
+*********************************************************************************************************/
+
+
+Diameter-SIP Application will be fully compliant with RFC4740 (server part). However, there is still some work to do so it should be considered as experimental for now.
+
Index: extensions/app_sip/diamsip.h
===================================================================
--- extensions/app_sip/diamsip.h	(revision 430)
+++ extensions/app_sip/diamsip.h	(revision 432)
@@ -92,5 +92,5 @@
 int get_password(const unsigned char *username, const size_t usernamelen, char *password);
 int check_sipaor(const unsigned char  *username, const size_t usernamelen, const char * sip_aor,const size_t sipaorlen);
-int get_user_datatype(const unsigned char  *username, const size_t usernamelen,char **table_supported, const int num_elements, struct avp **groupedavp);
+int add_user_datatype(const unsigned char  *sip_aor, const size_t sipaorlen,struct msg *message);
 int set_pending_flag(const unsigned char  *username, const size_t usernamelen);
 int clear_pending_flag(const unsigned char  *username, const size_t usernamelen);
@@ -101,6 +101,5 @@
 
 //count functions
-int count_supporteddatatype(const struct msg * message);
-int count_sipaor(const struct msg * message);
+int count_avp(struct msg * message, int code, int vendor);
 
 
@@ -164,6 +163,6 @@
 
 //sip server uri by SIP-AOR
-#define SQL_GETSIPSERURI  "SELECT `sip_server_uri` FROM ds_users, ds_sip_aor WHERE `sip_aor` ='%s' AND `ds_sip_aor`.`id_user` = `ds_users`.`id_user`"
-#define SQL_GETSIPSERURI_LEN 119
+#define SQL_GETSIPSERURI  "SELECT `ds_sip_aor`.`sip_server_uri` FROM ds_users, ds_sip_aor WHERE `sip_aor` ='%s' AND `ds_sip_aor`.`id_user` = `ds_users`.`id_user`"
+#define SQL_GETSIPSERURI_LEN 132
 
 //sip capabilities for a SIP-AOR
@@ -172,8 +171,8 @@
 
 //user data for a user data supported
-#define SQL_GETUSEDATA  "SELECT `data_type`,`data` FROM ds_users, ds_user_data, ds_data_types WHERE `username` ='%s' AND `ds_users`.`id_user` = `ds_user_data`.`id_user` AND `ds_data_types`.`id_data_type`=`ds_user_data`.`id_data_type`"
-#define SQL_GETUSEDATA_LEN 206
-
-#define SQL_GETDIAMURI "SELECT `diameter_uri` FROM sl_sip_aor_map WHERE `sip_aor` ='%s'"
+#define SQL_GETSIPDATA  "SELECT `label_type`,`data` FROM ds_sip_aor, ds_user_data, ds_data_types WHERE `sip_aor` ='%s' AND `ds_sip_aor`.`id_sip_aor` = `ds_user_data`.`id_sip_aor` AND `ds_data_types`.`id_data_type`=`ds_user_data`.`id_data_type`"
+#define SQL_GETSIPDATA_LEN 216
+
+#define SQL_GETDIAMURI "SELECT `diameter_uri` FROM ds_sip_aor_map WHERE `sip_aor` ='%s'"
 #define SQL_GETDIAMURI_LEN 61
 
@@ -207,5 +206,7 @@
 extern struct session_handler * ds_sess_hdl;
 
-
+//AVP code
+#define CODE_SIP_USER_DATA_TYPE	388
+#define CODE_SIP_AOR	122
 
 struct ds_nonce
Index: extensions/app_sip/libdiamsip.c
===================================================================
--- extensions/app_sip/libdiamsip.c	(revision 430)
+++ extensions/app_sip/libdiamsip.c	(revision 432)
@@ -584,17 +584,18 @@
 
 //We retrieve datatype
-int get_user_datatype(const unsigned char  *username, const size_t usernamelen, char **table_supported, const int num_elements, struct avp **groupedavp)
-{
-	CHECK_PARAMS(table_supported && num_elements && username && usernamelen && groupedavp);
-	
-	
-	int counter=0, not_found=1;
+int add_user_datatype(const unsigned char  *sip_aor, const size_t sipaorlen,struct msg *message)
+{
+	CHECK_PARAMS(sip_aor && sipaorlen && message );
+	
+	size_t querylen, sipaorpurelen;
+	char *query, *sipaor_pure;
+	int not_found=2;
 	union avp_value value;
 	struct avp *avp, *rootavp;
-	size_t querylen, usernamepurelen;
-	char *query, *username_pure;
-	
-	if(num_elements<1)
-		return 1;
+	unsigned long *length;
+	
+	//a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars
+	if(sipaorlen<5)
+		return 2;
 	
 	//NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security
@@ -604,15 +605,15 @@
 		case ASMYSQL:
 			
-			querylen=SQL_GETUSEDATA_LEN + usernamelen;
-			
-			
-			//We allocate the double size of username because at worst it can be all quotes
-			username_pure=malloc(usernamelen*2+1);
-			//We purify username not to have forbidden characters
-			usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen);
-			
-			
-			query = malloc(querylen+usernamelen+ 2);
-			snprintf(query, querylen+1, SQL_GETUSEDATA, username_pure);
+			querylen=SQL_GETSIPDATA_LEN + sipaorlen;
+			
+			
+			//We allocate the double size of SIP-URI because at worst it can be all quotes
+			CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1));
+			//We purify SIP-URI not to have forbidden characters
+			sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen);
+			
+			
+			query = malloc(querylen+sipaorpurelen+ 2);
+			snprintf(query, querylen+1, SQL_GETSIPDATA, sipaor_pure);
 			
 			MYSQL_RES *res;
@@ -628,46 +629,38 @@
 			}
 			not_found=1;
-			
-			counter=0;
-			unsigned long *length=0;
-			
-			//int index=0;//current field number
-			
 			while ((row = mysql_fetch_row(res)) != NULL)
 			{
 				length=mysql_fetch_lengths(res);
 				
-				for(counter=0;counter<num_elements; counter++)
+				if(strlen(row[0])>1)
 				{
-					//TODO: check length
-					if(strcmp(table_supported[counter],row[0]))
-					{
-						CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data, 0, &rootavp ) );
-						
-						CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data_Type, 0, &avp ) );
-						value.os.data=(unsigned char *)table_supported[counter];
-						value.os.len=strlen(table_supported[counter]);
-						CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
-						CHECK_FCT( fd_msg_avp_add ( rootavp, MSG_BRW_LAST_CHILD, avp) );
-						//This was used
-						table_supported[counter]=NULL;
-						
-						CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data_Contents, 0, &avp ) );
-						CHECK_MALLOC(value.os.data=malloc((length[1])*sizeof(unsigned char)));
-						memcpy(value.os.data,row[1],length[1]);
-						value.os.len=(size_t)(length[1]*sizeof(unsigned char));
-						CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
-						CHECK_FCT( fd_msg_avp_add ( rootavp, MSG_BRW_LAST_CHILD, avp) );
-						
-						CHECK_FCT( fd_msg_avp_add ( *groupedavp, MSG_BRW_LAST_CHILD, rootavp) );
-						not_found=0;
-					}
+					CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data, 0, &rootavp ) );
+					
+					CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data_Type, 0, &avp ) );
+					CHECK_MALLOC(value.os.data=malloc(length[0]*sizeof(unsigned char)));
+					strncpy((char *)value.os.data,(char *)row[0],length[0]);
+					value.os.len=(size_t)length[0];
+					CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
+					CHECK_FCT( fd_msg_avp_add ( rootavp, MSG_BRW_LAST_CHILD, avp) );
+					
+					
+					
+					CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data_Contents, 0, &avp ) );
+					CHECK_MALLOC(value.os.data=malloc(length[1]*sizeof(unsigned char)));
+					memcpy(value.os.data,row[1],length[1]);
+					value.os.len=(size_t)length[1];
+					CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
+					CHECK_FCT( fd_msg_avp_add ( rootavp, MSG_BRW_LAST_CHILD, avp) );
+					
+					//We add SIP_User_Data to message
+					CHECK_FCT( fd_msg_avp_add ( message, MSG_BRW_LAST_CHILD, rootavp) );
+					not_found=0;
 				}
-				//index++;
+				
 			}
 			
 			mysql_free_result(res);
 			free(query);
-			free(username_pure);
+			free(sipaor_pure);
 			break;
 			
@@ -683,4 +676,6 @@
 	//0 if it was found
 	return not_found;
+	
+	
 	
 }
@@ -952,5 +947,6 @@
 }
 
-int count_sipaor(const struct msg * message)
+
+int count_avp(struct msg * message, int code, int vendor)
 {
 	CHECK_PARAMS(message);
@@ -960,5 +956,5 @@
 	int counter=0;
 	
-	CHECK_FCT(fd_msg_browse ( &message, MSG_BRW_WALK, &avp, NULL));
+	CHECK_FCT(fd_msg_browse (message, MSG_BRW_WALK, &avp, NULL));
 	
 	while(avp!=NULL)
@@ -967,34 +963,10 @@
 		CHECK_FCT( fd_msg_avp_hdr( avp,&temphdr ));
 		
-		if(temphdr->avp_code==122 && temphdr->avp_vendor==0)
+		if(temphdr->avp_code==code && temphdr->avp_vendor==vendor)
 		{
 			counter++;
 		}
 		
-		CHECK_FCT(fd_msg_browse ( &message, MSG_BRW_WALK, &avp, NULL));
-	}
-	return counter;
-}
-int count_supporteddatatype(const struct msg * message)
-{
-	CHECK_PARAMS(message);
-	
-	struct avp_hdr *temphdr;
-	struct avp *avp;
-	int counter=0;
-	
-	CHECK_FCT(fd_msg_browse ( &message, MSG_BRW_WALK, &avp, NULL));
-	
-	while(avp!=NULL)
-	{
-		
-		CHECK_FCT( fd_msg_avp_hdr( avp,&temphdr ));
-		
-		if(temphdr->avp_code==388 && temphdr->avp_vendor==0)
-		{
-			counter++;
-		}
-		
-		CHECK_FCT(fd_msg_browse ( &message, MSG_BRW_WALK, &avp, NULL));
+		CHECK_FCT(fd_msg_browse (avp, MSG_BRW_WALK, &avp, NULL));
 	}
 	return counter;
Index: tensions/app_sip/rtrsipaor.c
===================================================================
--- extensions/app_sip/rtrsipaor.c	(revision 419)
+++ 	(revision )
@@ -1,290 +1,0 @@
-/*********************************************************************************************************
-* 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.								 *
-*********************************************************************************************************/
-
-
-// This file is separated from the source code because it is a separate command which will call registration termination function in Diameter-SIP
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <unistd.h>
-typedef int SOCKET;
-typedef struct sockaddr_in SOCKADDR_IN;
-typedef struct sockaddr SOCKADDR;
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#define PORT 666
-#include <errno.h>
-
-struct rtrsipaor
-{
-	char username[200];
-	char sip_aor1[200];
-	char sip_aor2[200];
-	char sip_aor3[200];
-	char strreason[200];
-	char desthost[200];
-	int reason;
-};
-
-int main (int argc, char **argv)
-{
-	SOCKET sock;
-    SOCKADDR_IN sin;
-    struct rtrsipaor rtrsip;
-    int numaor=0,i=0;
-    
-	sock = socket(AF_INET, SOCK_STREAM, 0);
-	sin.sin_addr.s_addr = inet_addr("127.0.0.1");
-    sin.sin_family = AF_INET;
-    sin.sin_port = htons(PORT);
-    
-    //We initialize the structure
-    rtrsip.username[0]='\0';
-    rtrsip.sip_aor1[0]='\0';
-    rtrsip.sip_aor2[0]='\0';
-    rtrsip.sip_aor3[0]='\0';
-    rtrsip.strreason[0]='\0';
-    rtrsip.desthost[0]='\0';
-    rtrsip.reason=-1;
-    
-    
-	//Start of arguments check
-	if(argc<3)
-	{
-		fprintf(stderr,"Missing arguments! You must at least provide a username.\n");
-		return 1;
-	}
-	
-	
-	for (i=1;i<argc;i++)
-	{
-		//We must check if it is a value or the name
-		if(strncmp(argv[i],"-",1)==0)
-		{
-			if(strcmp(argv[i],"-u")==0)
-			{
-				//Username
-				if(strlen(argv[i+1])<199)
-				{
-					strcpy(rtrsip.username,argv[i+1]);
-					//We must not check the value
-					i++;
-				}
-				else
-				{
-					fprintf(stderr,"Username is too long!\n");
-				}
-			}
-			else if(strcmp(argv[i],"-a")==0)
-			{
-				i++;
-				int j=i;
-			
-				for(j=i;j<argc;j++)
-				{
-					
-					if(strncmp(argv[i],"-",1)!=0)
-					{
-						if(strlen(argv[i])>199)
-						{
-							fprintf(stderr,"SIP-AOR is too long!\n");
-						}
-						else if(strncmp(argv[i],"sip",3)!=0)
-						{
-							//Bad format of SIP-AOR
-							fprintf(stderr,"A SIP-AOR must start by 'sip:' or 'sips:'. Aborting...\n");
-							return 1;
-						}
-						else
-						{
-							if(numaor<3)
-							{
-								switch(numaor)
-								{
-									case 0:
-										strcpy(rtrsip.sip_aor1,argv[i]);
-									break;
-									case 1:
-										strcpy(rtrsip.sip_aor2,argv[i]);
-									break;
-									case 2:
-										strcpy(rtrsip.sip_aor3,argv[i]);
-									break;
-								}
-								numaor++;
-							}
-							else
-							{
-								fprintf(stderr,"You can not provide more than 3 SIP-AOR at the same time!\n");
-								break;
-							}
-						}
-						i=j+1;
-					}
-					else
-					{
-						//We have a new argument
-						i--;
-						break;
-					}
-				}
-			}
-			else if(strcmp(argv[i],"-r")==0)
-			{
-				
-				if(strlen(argv[i+1])>199)
-				{
-					fprintf(stderr,"Deregistration reason is too long!\n");
-				}
-				else
-				{
-					strcpy(rtrsip.strreason,argv[i+1]);
-				}
-				i++;
-			}
-			else if(strcmp(argv[i],"-h")==0)
-			{
-				//Remote SIP Server
-				if(strlen(argv[i+1])>199)
-				{
-					fprintf(stderr,"Host is too long!\n");
-				}
-				else if(strlen(argv[i+1])<5)
-				{
-					fprintf(stderr,"Host is too short!\n");
-				}
-				else
-				{
-					strcpy(rtrsip.desthost,argv[i+1]);
-				}
-				i++;
-			}
-			else if(strcmp(argv[i],"-pt")==0)
-			{
-				//Permanent Termination
-				rtrsip.reason=0;
-			}
-			else if(strcmp(argv[i],"-nssa")==0)
-			{
-				//New SIP Server Assigned
-				rtrsip.reason=1;
-			}
-			else if(strcmp(argv[i],"-ssc")==0)
-			{
-				//SIP Server Change
-				rtrsip.reason=2;
-			}
-			else if(strcmp(argv[i],"-rss")==0)
-			{
-				//Remote SIP Server
-				rtrsip.reason=3;
-			}
-			else
-			{
-				fprintf(stderr,"Unknown argument: %s\n",argv[i]);
-			}
-		}
-		else
-		{
-			fprintf(stderr,"Unknown argument: %s\n",argv[i]);
-			i++;
-		}
-			
-	}
-	
-	//If no SIP-AOR provided, we remove all
-	if(numaor<1)
-	{
-		fprintf(stderr,"All SIP-AOR of %s will be deregistrated.\n",rtrsip.username);
-	}
-	
-	//We want a username
-	if(strlen(rtrsip.username)==0)
-	{
-		fprintf(stderr,"You must provide a username!\n");
-		return 1;
-	}
-	
-	if(rtrsip.desthost[0]=='\0')
-	{
-		fprintf(stderr,"You must provide the hostname of SIP-Server!\n");
-		return 1;
-	}
-    
-    
-   
-    
-    /*
-    fprintf(stderr,"*%s*\n",rtrsip.username);
-	fprintf(stderr,"*%s*\n",rtrsip.sip_aor1);
-	fprintf(stderr,"*%s*\n",rtrsip.sip_aor2);
-	fprintf(stderr,"*%s*\n",rtrsip.sip_aor3);
-	fprintf(stderr,"*%d*\n",rtrsip.reason);
-	fprintf(stderr,"*%s*\n",rtrsip.strreason);
-	
-	//return 0;
-	*/
-	
-	
-	//TODO: check args
-	if(!connect(sock, (SOCKADDR*)&sin, sizeof(sin)))
-    {
-       fprintf(stderr,"Connexion succeed!\n");
-        
- 
-        if(send(sock, &rtrsip, sizeof(struct rtrsipaor), 0))
-			fprintf(stderr,"sent OK!\n");
-		else
-			fprintf(stderr,"not sent\n");
-        
-    }
-    else
-    {
-        fprintf(stderr,"Unable to connect\n");
-    }
- 
-    close(sock);
-
-	return 0;
-}
-
-
-
-
-
-
Index: extensions/app_sip/serverassignment.c
===================================================================
--- extensions/app_sip/serverassignment.c	(revision 430)
+++ extensions/app_sip/serverassignment.c	(revision 432)
@@ -42,8 +42,8 @@
 	
 	struct msg *ans, *qry;
-	struct avp *avp, *groupedavp=NULL;
+	struct avp *avp;
 	struct avp_hdr *avphdr, *sipaorhdr, *usernamehdr, *sipuserdataalreadyavailable;
 	union avp_value value;
-	int ret=0, assignment_type=0, supported_datatype=0, got_datatype=0;
+	int ret=0, assignment_type=0, got_datatype=1;
 	
 	
@@ -176,82 +176,7 @@
 	}
 	
-	//TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO : check which assignment need data type
-	//We check if we have SIP_Supported_User_Data_Type and we make a table with all of them
-	{
-		supported_datatype=count_supporteddatatype(qry);
-		
-		if(supported_datatype>0)
-		{
-			char ** table_supporteddatatype=NULL;
-			
-			//TODO: maybe table doesn't work'
-			//We make a table of char * to store all supported datatypes
-			CHECK_MALLOC(table_supporteddatatype=(char**)realloc(table_supporteddatatype,supported_datatype*sizeof(char *)));
-			
-			
-			CHECK_FCT(fd_msg_browse ( qry, MSG_BRW_WALK, &avp, NULL));
-			int counter=0;
-			
-			while(avp!=NULL)
-			{
-				
-				CHECK_FCT( fd_msg_avp_hdr( avp,&avphdr ));
-				
-				//TODO: check if counter is good!
-				if(avphdr->avp_code==388 && avphdr->avp_vendor==0 && counter<supported_datatype)
-				{
-					
-					CHECK_MALLOC(table_supporteddatatype[counter]=malloc(avphdr->avp_value->os.len+1));
-					strncpy(table_supporteddatatype[counter],(const char *)avphdr->avp_value->os.data,avphdr->avp_value->os.len);
-					table_supporteddatatype[counter][avphdr->avp_value->os.len+1]='\0';
-					
-					counter++;
-				}
-				
-				CHECK_FCT(fd_msg_browse ( qry, MSG_BRW_WALK, &avp, NULL));
-			}
-			
-			if(usernamehdr!=NULL)
-			{
-				ret=get_user_datatype(usernamehdr->avp_value->os.data, usernamehdr->avp_value->os.len,(char **)table_supporteddatatype, counter, &groupedavp);
-				
-				//We free all unused datatypes
-				int i=0;
-				for(i=0;i<counter;i++)
-				{
-					if(table_supporteddatatype[counter]!=NULL)
-						free(table_supporteddatatype[counter]);
-				}
-				
-				if(ret==0)
-				{
-					got_datatype=1;
-					
-				}
-				else if(ret==1)
-				{
-					TRACE_DEBUG(INFO,"There was no link between supported and transmisted SIP-User-Data AVPs");
-				}
-				else
-				{
-					strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
-					goto out;
-				}
-				
-			}
-			else
-			{
-				strcpy(result,"DIAMETER_USER_NAME_REQUIRED");
-				int i=0;
-				for(i=0;i<counter;i++)
-				{
-					if(table_supporteddatatype[counter]!=NULL)
-						free(table_supporteddatatype[counter]);
-				}
-				goto out;
-			}
-			
-		}
-	}
+	
+	
+	
 	
 	//We get SIP_User_Data_Already_Available AVP
@@ -263,5 +188,42 @@
 	if(assignment_type==1 || assignment_type==2)
 	{//registration & re-registration
-		if(count_sipaor(qry)==1)
+		if(count_avp(qry,CODE_SIP_AOR,0)==1)
+		{
+			
+			if(sipuserdataalreadyavailable->avp_value->i32==0)
+			{//Data not available, we must provide it
+				ret=add_user_datatype(sipaorhdr->avp_value->os.data, sipaorhdr->avp_value->os.len,ans);
+				
+				if(ret==0)
+				{
+					//We found and added datatype
+					got_datatype=1;
+				}
+				else if(ret==1)
+				{
+					//No data type was found
+					got_datatype=0;
+				}
+				else
+				{//error
+				//We couldn't make the request, we must stop process!
+				strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
+				goto out;
+				}
+			}
+			strcpy(result,"DIAMETER_SUCCESS");
+			goto out;
+		}
+		else
+		{//There is more than 1 SIP-AOR AVP
+			strcpy(result,"DIAMETER_AVP_OCCURS_TOO_MANY_TIMES");
+			goto out;
+		}
+	}
+	else if(assignment_type==3)
+	{//Unregistered user
+		
+		//TODO:place user unknown here!
+		if(count_avp(qry,CODE_SIP_AOR,0)==1)
 		{
 			if(sipuserdataalreadyavailable->avp_value->i32==0)
@@ -269,29 +231,22 @@
 				if(got_datatype==1)
 				{
-					//We provide User Data
-					CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, groupedavp) );
-				}
-			}
-			strcpy(result,"DIAMETER_SUCCESS");
-			goto out;
-		}
-		else
-		{//There is more than 1 SIP-AOR AVP
-			strcpy(result,"DIAMETER_AVP_OCCURS_TOO_MANY_TIMES");
-			goto out;
-		}
-	}
-	else if(assignment_type==3)
-	{//Unregistered user
-		
-		//TODO:place user unknown here!
-		if(count_sipaor(qry)==1)
-		{
-			if(sipuserdataalreadyavailable->avp_value->i32==0)
-			{//Data not available, we must provide it
-				if(got_datatype==1)
-				{
-					//We provide User Data
-					CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, groupedavp) );
+					ret=add_user_datatype(sipaorhdr->avp_value->os.data, sipaorhdr->avp_value->os.len,ans);
+					
+					if(ret==0)
+					{
+						//We found and added datatype
+						got_datatype=1;
+					}
+					else if(ret==1)
+					{
+						//No data type was found
+						got_datatype=0;
+					}
+					else
+					{//error
+						//We couldn't make the request, we must stop process!
+						strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
+						goto out;
+					}
 				}
 			}
@@ -309,6 +264,22 @@
 			if(got_datatype==1)
 			{
-				//We provide User Data
-				CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, groupedavp) );
+				ret=add_user_datatype(sipaorhdr->avp_value->os.data, sipaorhdr->avp_value->os.len,ans);
+				
+				if(ret==0)
+				{
+					//We found and added datatype
+					got_datatype=1;
+				}
+				else if(ret==1)
+				{
+					//No data type was found
+					got_datatype=0;
+				}
+				else
+				{//error
+					//We couldn't make the request, we must stop process!
+					strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
+					goto out;
+				}
 			}
 		}
@@ -338,10 +309,22 @@
 			{//Data not available, we must provide it
 				
-				//We provide User Data
-				CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, groupedavp) );
-			}
-			else
-			{
-				CHECK_FCT( fd_msg_free( groupedavp ) );
+				ret=add_user_datatype(sipaorhdr->avp_value->os.data, sipaorhdr->avp_value->os.len,ans);
+				
+				if(ret==0)
+				{
+					//We found and added datatype
+					got_datatype=1;
+				}
+				else if(ret==1)
+				{
+					//No data type was found
+					got_datatype=0;
+				}
+				else
+				{//error
+					//We couldn't make the request, we must stop process!
+					strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
+					goto out;
+				}
 			}
 		}
@@ -399,23 +382,63 @@
 		if(avp!=NULL)
 		{
-			//TODO: check that SIP-server_URI provided is the same as associated and answer unable to comply if so
-			//TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO here
-			
-			
-			CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr ));
-			
-			if(got_datatype==1)
+			unsigned char * sipserver_uri;
+			size_t sipserverurilen;
+			
+			
+			
+			
+			ret=get_sipserver_uri(sipaorhdr->avp_value->os.data, sipaorhdr->avp_value->os.len, &sipserver_uri, &sipserverurilen);
+			
+			if(ret==0)
+			{//found
+				CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr ));
+				
+				
+				
+				
+				if(strncmp((char *)avphdr->avp_value->os.data,(char *)sipserver_uri,sipserverurilen))
+				{
+					if(got_datatype==1)
+					{
+						if(sipuserdataalreadyavailable->avp_value->i32==0)
+						{//Data not available, we must provide it
+							
+							ret=add_user_datatype(sipaorhdr->avp_value->os.data, sipaorhdr->avp_value->os.len,ans);
+							
+							if(ret==0)
+							{
+								//We found and added datatype
+								got_datatype=1;
+							}
+							else if(ret==1)
+							{
+								//No data type was found
+								got_datatype=0;
+							}
+							else
+							{//error
+								//We couldn't make the request, we must stop process!
+								strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
+								goto out;
+							}
+						}
+					}
+				}
+				else
+				{//error
+					TRACE_DEBUG(FULL,"SIP_Server_URI is different from the one in database");
+					strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
+					goto out;
+				}
+			}
+			else
 			{
-				if(sipuserdataalreadyavailable->avp_value->i32==0)
-				{//Data not available, we must provide it
-					
-					//We provide User Data
-					CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, groupedavp) );
-				}
-				else
-				{
-					CHECK_FCT( fd_msg_free( groupedavp ) );
-				}
-			}
+				TRACE_DEBUG(FULL,"SIP_Server_URI is different from the one in database");
+				strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
+				goto out;
+			}
+			
+			
+			
 			
 			
@@ -428,5 +451,5 @@
 		else
 		{
-			TRACE_DEBUG(INFO, "There was no SIP-AOR in this request, we can't proceed request!'");
+			TRACE_DEBUG(INFO, "There was no SIP_Server_URI in this request, we can't proceed request!'");
 			strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
 			goto out;
@@ -435,5 +458,5 @@
 	else if(assignment_type==9 || assignment_type==10)
 	{
-		if(count_sipaor(qry)==1)
+		if(count_avp(qry, CODE_SIP_AOR,0)==1)
 		{
 			//TODO: remove SIP-server URI for sip_aor
Index: extensions/app_sip/tools/rtrsipaor.c
===================================================================
--- extensions/app_sip/tools/rtrsipaor.c	(revision 432)
+++ extensions/app_sip/tools/rtrsipaor.c	(revision 432)
@@ -0,0 +1,290 @@
+/*********************************************************************************************************
+* 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.								 *
+*********************************************************************************************************/
+
+
+// This file is separated from the source code because it is a separate command which will call registration termination function in Diameter-SIP
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+typedef int SOCKET;
+typedef struct sockaddr_in SOCKADDR_IN;
+typedef struct sockaddr SOCKADDR;
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#define PORT 666
+#include <errno.h>
+
+struct rtrsipaor
+{
+	char username[200];
+	char sip_aor1[200];
+	char sip_aor2[200];
+	char sip_aor3[200];
+	char strreason[200];
+	char desthost[200];
+	int reason;
+};
+
+int main (int argc, char **argv)
+{
+	SOCKET sock;
+    SOCKADDR_IN sin;
+    struct rtrsipaor rtrsip;
+    int numaor=0,i=0;
+    
+	sock = socket(AF_INET, SOCK_STREAM, 0);
+	sin.sin_addr.s_addr = inet_addr("127.0.0.1");
+    sin.sin_family = AF_INET;
+    sin.sin_port = htons(PORT);
+    
+    //We initialize the structure
+    rtrsip.username[0]='\0';
+    rtrsip.sip_aor1[0]='\0';
+    rtrsip.sip_aor2[0]='\0';
+    rtrsip.sip_aor3[0]='\0';
+    rtrsip.strreason[0]='\0';
+    rtrsip.desthost[0]='\0';
+    rtrsip.reason=-1;
+    
+    
+	//Start of arguments check
+	if(argc<3)
+	{
+		fprintf(stderr,"Missing arguments! You must at least provide a username.\n");
+		return 1;
+	}
+	
+	
+	for (i=1;i<argc;i++)
+	{
+		//We must check if it is a value or the name
+		if(strncmp(argv[i],"-",1)==0)
+		{
+			if(strcmp(argv[i],"-u")==0)
+			{
+				//Username
+				if(strlen(argv[i+1])<199)
+				{
+					strcpy(rtrsip.username,argv[i+1]);
+					//We must not check the value
+					i++;
+				}
+				else
+				{
+					fprintf(stderr,"Username is too long!\n");
+				}
+			}
+			else if(strcmp(argv[i],"-a")==0)
+			{
+				i++;
+				int j=i;
+			
+				for(j=i;j<argc;j++)
+				{
+					
+					if(strncmp(argv[i],"-",1)!=0)
+					{
+						if(strlen(argv[i])>199)
+						{
+							fprintf(stderr,"SIP-AOR is too long!\n");
+						}
+						else if(strncmp(argv[i],"sip",3)!=0)
+						{
+							//Bad format of SIP-AOR
+							fprintf(stderr,"A SIP-AOR must start by 'sip:' or 'sips:'. Aborting...\n");
+							return 1;
+						}
+						else
+						{
+							if(numaor<3)
+							{
+								switch(numaor)
+								{
+									case 0:
+										strcpy(rtrsip.sip_aor1,argv[i]);
+									break;
+									case 1:
+										strcpy(rtrsip.sip_aor2,argv[i]);
+									break;
+									case 2:
+										strcpy(rtrsip.sip_aor3,argv[i]);
+									break;
+								}
+								numaor++;
+							}
+							else
+							{
+								fprintf(stderr,"You can not provide more than 3 SIP-AOR at the same time!\n");
+								break;
+							}
+						}
+						i=j+1;
+					}
+					else
+					{
+						//We have a new argument
+						i--;
+						break;
+					}
+				}
+			}
+			else if(strcmp(argv[i],"-r")==0)
+			{
+				
+				if(strlen(argv[i+1])>199)
+				{
+					fprintf(stderr,"Deregistration reason is too long!\n");
+				}
+				else
+				{
+					strcpy(rtrsip.strreason,argv[i+1]);
+				}
+				i++;
+			}
+			else if(strcmp(argv[i],"-h")==0)
+			{
+				//Remote SIP Server
+				if(strlen(argv[i+1])>199)
+				{
+					fprintf(stderr,"Host is too long!\n");
+				}
+				else if(strlen(argv[i+1])<5)
+				{
+					fprintf(stderr,"Host is too short!\n");
+				}
+				else
+				{
+					strcpy(rtrsip.desthost,argv[i+1]);
+				}
+				i++;
+			}
+			else if(strcmp(argv[i],"-pt")==0)
+			{
+				//Permanent Termination
+				rtrsip.reason=0;
+			}
+			else if(strcmp(argv[i],"-nssa")==0)
+			{
+				//New SIP Server Assigned
+				rtrsip.reason=1;
+			}
+			else if(strcmp(argv[i],"-ssc")==0)
+			{
+				//SIP Server Change
+				rtrsip.reason=2;
+			}
+			else if(strcmp(argv[i],"-rss")==0)
+			{
+				//Remote SIP Server
+				rtrsip.reason=3;
+			}
+			else
+			{
+				fprintf(stderr,"Unknown argument: %s\n",argv[i]);
+			}
+		}
+		else
+		{
+			fprintf(stderr,"Unknown argument: %s\n",argv[i]);
+			i++;
+		}
+			
+	}
+	
+	//If no SIP-AOR provided, we remove all
+	if(numaor<1)
+	{
+		fprintf(stderr,"All SIP-AOR of %s will be deregistrated.\n",rtrsip.username);
+	}
+	
+	//We want a username
+	if(strlen(rtrsip.username)==0)
+	{
+		fprintf(stderr,"You must provide a username!\n");
+		return 1;
+	}
+	
+	if(rtrsip.desthost[0]=='\0')
+	{
+		fprintf(stderr,"You must provide the hostname of SIP-Server!\n");
+		return 1;
+	}
+    
+    
+   
+    
+    /*
+    fprintf(stderr,"*%s*\n",rtrsip.username);
+	fprintf(stderr,"*%s*\n",rtrsip.sip_aor1);
+	fprintf(stderr,"*%s*\n",rtrsip.sip_aor2);
+	fprintf(stderr,"*%s*\n",rtrsip.sip_aor3);
+	fprintf(stderr,"*%d*\n",rtrsip.reason);
+	fprintf(stderr,"*%s*\n",rtrsip.strreason);
+	
+	//return 0;
+	*/
+	
+	
+	//TODO: check args
+	if(!connect(sock, (SOCKADDR*)&sin, sizeof(sin)))
+    {
+       fprintf(stderr,"Connexion succeed!\n");
+        
+ 
+        if(send(sock, &rtrsip, sizeof(struct rtrsipaor), 0))
+			fprintf(stderr,"sent OK!\n");
+		else
+			fprintf(stderr,"not sent\n");
+        
+    }
+    else
+    {
+        fprintf(stderr,"Unable to connect\n");
+    }
+ 
+    close(sock);
+
+	return 0;
+}
+
+
+
+
+
+
Index: extensions/test_sip/serverassignment.c
===================================================================
--- extensions/test_sip/serverassignment.c	(revision 430)
+++ extensions/test_sip/serverassignment.c	(revision 432)
@@ -46,12 +46,14 @@
 	
 	//Fake values START
-	 char *sip_aor="sip:aw-lappy@tera.ics.keio.ac.jp";
+	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";
+	char *destination_realm="tera.ics.keio.ac.jp";
 	size_t destination_realmlen=strlen(destination_realm);
-	 char *destination_host="suika.tera.ics.keio.ac.jp";
+	char *destination_host="suika.tera.ics.keio.ac.jp";
 	size_t destination_hostlen=strlen(destination_host);
-	 char *username="aw-lappy";
+	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);
@@ -149,4 +151,14 @@
 		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 ) );
+		
+	}
 	
 	fd_msg_dump_walk(INFO,message);
