changeset 432:533188d2e6cc

Corrected bugs on SAR/SAA; added SQL files
author Alexandre Westfahl <awestfahl@freediameter.net>
date Wed, 28 Jul 2010 03:14:11 +0900
parents 1bb1bc417efe
children 0d08a9ab2212
files doc/app_sip.conf.sample doc/app_sip.sql doc/app_sip_SL.sql extensions/app_sip/README extensions/app_sip/diamsip.h extensions/app_sip/libdiamsip.c extensions/app_sip/rtrsipaor extensions/app_sip/rtrsipaor.c extensions/app_sip/serverassignment.c extensions/app_sip/tools/rtrsipaor extensions/app_sip/tools/rtrsipaor.c extensions/test_sip/serverassignment.c
diffstat 12 files changed, 682 insertions(+), 487 deletions(-) [+]
line wrap: on
line diff
--- a/doc/app_sip.conf.sample	Tue Jul 27 15:33:20 2010 +0900
+++ b/doc/app_sip.conf.sample	Wed Jul 28 03:14:11 2010 +0900
@@ -1,7 +1,12 @@
 
 # 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;
 
@@ -10,4 +15,9 @@
 mysql_password = "password";
 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";
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/app_sip.sql	Wed Jul 28 03:14:11 2010 +0900
@@ -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 ;
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/app_sip_SL.sql	Wed Jul 28 03:14:11 2010 +0900
@@ -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 ;
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/app_sip/README	Wed Jul 28 03:14:11 2010 +0900
@@ -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.
+
--- a/extensions/app_sip/diamsip.h	Tue Jul 27 15:33:20 2010 +0900
+++ b/extensions/app_sip/diamsip.h	Wed Jul 28 03:14:11 2010 +0900
@@ -91,7 +91,7 @@
 int get_sipserver_cap(const unsigned char *sip_aor, const size_t sipaorlen, struct avp **capabilities);
 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);
 int set_real_sipserver_uri(const unsigned char  *username, const size_t usernamelen, const unsigned char *sipserver_uri,const size_t sipserverurilen);
@@ -100,8 +100,7 @@
 int allow_roaming(const unsigned char  *username, const size_t usernamelen, const char * network,const size_t networklen);
 
 //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);
 
 
 void DigestCalcHA1(char * pszAlg,char * pszUserName,char * pszRealm,char * pszPassword,char * pszNonce,char * pszCNonce,HASHHEX SessionKey);
@@ -163,18 +162,18 @@
 #define SQL_GETSIPURI_LEN 60
 
 //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
 #define SQL_GETSIPSERCAP  "SELECT `compulsory`,`id_service` FROM ds_user_services, ds_sip_aor WHERE `sip_aor` ='%s' AND `ds_sip_aor`.`id_user` = `ds_user_services`.`id_user`"
 #define SQL_GETSIPSERCAP_LEN 144
 
 //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_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 sl_sip_aor_map WHERE `sip_aor` ='%s'"
+#define SQL_GETDIAMURI "SELECT `diameter_uri` FROM ds_sip_aor_map WHERE `sip_aor` ='%s'"
 #define SQL_GETDIAMURI_LEN 61
 
 //networks for this user
@@ -206,7 +205,9 @@
 
 extern struct session_handler * ds_sess_hdl;
 
-
+//AVP code
+#define CODE_SIP_USER_DATA_TYPE	388
+#define CODE_SIP_AOR	122
 
 struct ds_nonce
 {
--- a/extensions/app_sip/libdiamsip.c	Tue Jul 27 15:33:20 2010 +0900
+++ b/extensions/app_sip/libdiamsip.c	Wed Jul 28 03:14:11 2010 +0900
@@ -583,19 +583,20 @@
 
 
 //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)
+int add_user_datatype(const unsigned char  *sip_aor, const size_t sipaorlen,struct msg *message)
 {
-	CHECK_PARAMS(table_supported && num_elements && username && usernamelen && groupedavp);
+	CHECK_PARAMS(sip_aor && sipaorlen && message );
 	
-	
-	int counter=0, not_found=1;
+	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;
+	unsigned long *length;
 	
-	if(num_elements<1)
-		return 1;
+	//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
 	switch(as_conf->datasource)
@@ -603,17 +604,17 @@
 		//MySQL
 		case ASMYSQL:
 			
-			querylen=SQL_GETUSEDATA_LEN + usernamelen;
+			querylen=SQL_GETSIPDATA_LEN + sipaorlen;
 			
 			
-			//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);
+			//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+usernamelen+ 2);
-			snprintf(query, querylen+1, SQL_GETUSEDATA, username_pure);
+			query = malloc(querylen+sipaorpurelen+ 2);
+			snprintf(query, querylen+1, SQL_GETSIPDATA, sipaor_pure);
 			
 			MYSQL_RES *res;
 			MYSQL_ROW row;
@@ -627,48 +628,40 @@
 				return 2;
 			}
 			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;
 			
 			default:
@@ -683,6 +676,8 @@
 	//0 if it was found
 	return not_found;
 	
+	
+	
 }
 
 int set_pending_flag(const unsigned char  *username, const size_t usernamelen)
@@ -951,7 +946,8 @@
 	
 }
 
-int count_sipaor(const struct msg * message)
+
+int count_avp(struct msg * message, int code, int vendor)
 {
 	CHECK_PARAMS(message);
 	
@@ -959,43 +955,19 @@
 	struct avp *avp;
 	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)
 	{
 		
 		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;
 }
Binary file extensions/app_sip/rtrsipaor has changed
--- a/extensions/app_sip/rtrsipaor.c	Tue Jul 27 15:33:20 2010 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,290 +0,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;
-}
-
-
-
-
-
-
--- a/extensions/app_sip/serverassignment.c	Tue Jul 27 15:33:20 2010 +0900
+++ b/extensions/app_sip/serverassignment.c	Wed Jul 28 03:14:11 2010 +0900
@@ -41,10 +41,10 @@
 	TRACE_ENTRY("%p %p %p %p", msg, paramavp, sess, act);
 	
 	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;
 	
 	
 	struct listdatatype
@@ -175,84 +175,9 @@
 		assignment_type=avphdr->avp_value->i32;
 	}
 	
-	//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
 	{
@@ -262,14 +187,28 @@
 	
 	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
-				if(got_datatype==1)
+				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)
 				{
-					//We provide User Data
-					CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, groupedavp) );
+					//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");
@@ -285,14 +224,30 @@
 	{//Unregistered user
 		
 		//TODO:place user unknown here!
-		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
 				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;
+					}
 				}
 			}
 			strcpy(result,"DIAMETER_SUCCESS");
@@ -308,8 +263,24 @@
 		{//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;
+				}
 			}
 		}
 		
@@ -337,12 +308,24 @@
 			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 ) );
+				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;
+				}
 			}
 		}
 		
@@ -398,25 +381,65 @@
 		CHECK_FCT( fd_msg_search_avp ( qry, sip_dict.SIP_Server_URI, &avp) );
 		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
+			unsigned char * sipserver_uri;
+			size_t sipserverurilen;
+			
+			
 			
 			
-			CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr ));
+			ret=get_sipserver_uri(sipaorhdr->avp_value->os.data, sipaorhdr->avp_value->os.len, &sipserver_uri, &sipserverurilen);
 			
-			if(got_datatype==1)
-			{
-				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) );
+			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
-				{
-					CHECK_FCT( fd_msg_free( groupedavp ) );
+				{//error
+					TRACE_DEBUG(FULL,"SIP_Server_URI is different from the one in database");
+					strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
+					goto out;
 				}
 			}
+			else
+			{
+				TRACE_DEBUG(FULL,"SIP_Server_URI is different from the one in database");
+				strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
+				goto out;
+			}
+			
+			
+			
 			
 			
 			
@@ -427,14 +450,14 @@
 		}
 		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;
 		}
 	}
 	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
 			//TODO: unregister it
Binary file extensions/app_sip/tools/rtrsipaor has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/app_sip/tools/rtrsipaor.c	Wed Jul 28 03:14:11 2010 +0900
@@ -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;
+}
+
+
+
+
+
+
--- a/extensions/test_sip/serverassignment.c	Tue Jul 27 15:33:20 2010 +0900
+++ b/extensions/test_sip/serverassignment.c	Wed Jul 28 03:14:11 2010 +0900
@@ -45,14 +45,16 @@
 	union avp_value value;
 	
 	//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);
 	//int registrationtype = 2;
@@ -148,6 +150,16 @@
 		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 ) );
+		
+	}
 	
 	fd_msg_dump_walk(INFO,message);
 	CHECK_FCT( fd_msg_send( &message, NULL, NULL ));
"Welcome to our mercurial repository"