diff --git a/sflphone-common/src/dbus/configurationmanager-introspec.xml b/sflphone-common/src/dbus/configurationmanager-introspec.xml index 944cf9f685ca044a59e91543d4da3fbc7a1d1b8d..c2bab075612d65ce262308c927aa3f9af16759cd 100644 --- a/sflphone-common/src/dbus/configurationmanager-introspec.xml +++ b/sflphone-common/src/dbus/configurationmanager-introspec.xml @@ -162,6 +162,8 @@ <method name="addAccount"> <!--* Add a new account to the SFLphone-daemon list. If no details are specified, default parameters are used. + A REGISTER is automatically sent and configuration is + saved if account created successfully. @param[in] input details @param[out] output accountID diff --git a/tools/pysflphone/pysflphone.py b/tools/pysflphone/pysflphone.py index d100b6b8167eed92decf0b40e0c0c10b3b218d3b..61fde183b0134ae237fdd4126d1fd1edf01f9462 100644 --- a/tools/pysflphone/pysflphone.py +++ b/tools/pysflphone/pysflphone.py @@ -61,7 +61,8 @@ def printHelp(): --gaia Get all IAX accounts. \n\ --gcc Get current callid. \n\ --gacl Get active codec list. \n\ - \n\ + --sac Set accout for next call \n\ + \n\ --gad <account> Get account details . \n\ --enable <account> Enable the account. \n\ --disable <account> Disable the account. \n\ @@ -83,9 +84,12 @@ def printHelp(): # Option definition try: - opts, args = getopt.getopt(sys.argv[1:],"", [ "help", "gaa", "gal", "gara", "gaea", "gasa", "gaia", "gacl", "gac", "gcc", - "hangup=", "refuse=", "hold", "unhold=", "transfer=","dtmf=", "accept=", - "gcd=", "gad=", "register=", "unregister=", "enable=", "disable=", "call=" ]) + opts, args = getopt.getopt(sys.argv[1:],"", + [ "help", "gaa", "gal", "gara", "gaea", "gasa", "gaia", + "gacl", "gac", "gcc", "hangup=", "refuse=", "hold", + "unhold=", "transfer=","dtmf=", "accept=", "gcd=", + "gad=", "register=", "unregister=", "enable=", "disable=", + "call=", "sac=" ]) except getopt.GetoptError,err: print str(err) sys.exit(2) @@ -166,6 +170,12 @@ else: print "Account: " + details['ACCOUNTID'] print "Peer: " + details['PEER_NAME'] + "<" + details['PEER_NUMBER'] + ">" + elif opt == "--sac": + if arg is "": + print "Must specifies the accout to be set" + else: + sflphone.setAccount(arg) + # # call options diff --git a/tools/pysflphone/pysflphone_testdbus.py b/tools/pysflphone/pysflphone_testdbus.py index 52f58ba132bc940815836cc344ea286132d55d4d..7ff1383f8b0ad72f3cb12a47f6a0010c6e86aaa7 100644 --- a/tools/pysflphone/pysflphone_testdbus.py +++ b/tools/pysflphone/pysflphone_testdbus.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import time from sflphonectrlsimple import SflPhoneCtrlSimple @@ -7,40 +8,76 @@ class SflPhoneTests(SflPhoneCtrlSimple): def test_get_allaccounts_methods(self): - print "--- getAllAccounts() ---" for account in self.getAllAccounts(): print " " + account - print "\n" - - print "--- getAllRegisteredAccounts() ---" + for account in self.getAllRegisteredAccounts(): print " " + account - print "\n" - print "--- getAllSipAccounts() ---" for account in self.getAllSipAccounts(): print " " + account - print "\n" - print "--- getAllIaxAccounts() ---" for account in self.getAllIaxAccounts(): print " " + account - print "\n" - # def test_codecs_methods(self): + def test_make_iptoip_call(self): + """Make a call to a server (sipp) on port 5062""" + i = 0 + while(i < 50): + + callid = self.Call("sip:test@127.0.0.1:5062") + time.sleep(0.4) + + self.HangUp(callid) + time.sleep(0.4) + + i = i+1 + + def test_make_account_call(self): + """Register an account on a remote server and make several calls""" + + self.setAccount("Account:1258495784"); + time.sleep(3) + + i = 0 + while(i < 50): + + callid = self.Call("5000") + time.sleep(0.4) + + self.HangUp(callid) + time.sleep(0.4) + + i = i+1 + + + def test_create_account(self): + """Create a new sip fake account and remove it""" + + CONFIG_ACCOUNT_TYPE = "Account.type" + CONFIG_ACCOUNT_ALIAS = "Account.alias" + HOSTNAME = "hostname" + USERNAME = "username" + PASSWORD = "password" + + accDetails = {CONFIG_ACCOUNT_TYPE:"SIP", CONFIG_ACCOUNT_ALIAS:"myNewAccount", + HOSTNAME:"192.168.50.3", USERNAME:"431", + PASSWORD:"alexandre"} -# print "--- getCodecList() ---" -# for codec int self.getCodecList(): -# print " " + codec -# print "\n" + accountID = self.addAccount(accDetails) + print "New Account ID " + accountID + time.sleep(3) -sfl = SflPhoneTests() + self.removeAccount(accountID) + print "Account with ID " + accountID + " removed" -sfl.test_get_allaccounts_methods() +sflphone = SflPhoneTests() +sflphone.test_get_allaccounts_methods() +sflphone.test_make_iptoip_call() +sflphone.test_make_account_call() - - +sflphone.test_create_account() diff --git a/tools/pysflphone/sflphonectrlsimple.py b/tools/pysflphone/sflphonectrlsimple.py index bf5ffb75add40dfdd83b0a9fcaa8a548b4efbb6e..6ed51344a78ad3f64ad4edfcd864cb8620a6c5fd 100755 --- a/tools/pysflphone/sflphonectrlsimple.py +++ b/tools/pysflphone/sflphonectrlsimple.py @@ -170,13 +170,40 @@ class SflPhoneCtrlSimple(object): # # Account management # + def addAccount(self, details=None): + """Add a new account account + + Add a new account to the SFLphone-daemon. Default parameters are \ + used for missing account configuration field. + + Required parameters are type, alias, hostname, username and password + + input details + + """ + + if details is None: + raise SPaccountError("Must specifies type, alias, hostname, \ + username and password in \ + order to create a new account") + + return self.configurationmanager.addAccount(details) + + def removeAccount(self, accountID=None): + """Remove an account from internal list""" + + if accountID is None: + raise SPaccountError("Account ID must be specified") + + self.configurationmanager.removeAccount(accountID) + def getAllAccounts(self): - """ Return a list with all accounts""" + """Return a list with all accounts""" return self.configurationmanager.getAccountList() def getAllEnabledAccounts(self): - """ Return a list with all enabled accounts""" + """Return a list with all enabled accounts""" accounts = self.getAllAccounts() activeaccounts = [] for testedaccount in accounts: @@ -222,11 +249,15 @@ class SflPhoneCtrlSimple(object): raise SPaccountError("No account matched with alias") def setAccount(self, account): - """Define the active account""" + """Define the active account + + The active account will be used when sending a new call + """ if account in self.getAllAccounts(): self.account = account else: + print account raise SflPhoneError("Not a valid account") def setFirstRegisteredAccount(self): @@ -315,7 +346,6 @@ class SflPhoneCtrlSimple(object): def getAllSipAccounts(self): """Return a list of SIP accounts""" - sipAccountsList = [] for accountName in self.getAllAccounts(): if self.getAccountDetails(accountName)['Account.type'] == "SIP": @@ -395,25 +425,36 @@ class SflPhoneCtrlSimple(object): # Action # def Call(self, dest): - """Start a call and return a CallID""" - if not self.account: - self.setFirstRegisteredAccount() + """Start a call and return a CallID - if not self.isAccountRegistered(): - raise SflPhoneError("Can't place a call without a registered account") + Use the current account previously set using setAccount(). + If no account specified, first registered one in account list is used. + + For phone number prefixed using SIP scheme (i.e. sip: or sips:), + IP2IP profile is automatically selected and set as the default account + + return callID Newly generated callidentifier for this call + """ - if dest is None or dest == "": + if dest is None or dest == "": raise SflPhoneError("Invalid call destination") + + # Set the account to be used for this call + if dest.find('sip:') is 0 or dest.find('sips:') is 0: + print "Ip 2 IP call" + self.setAccount("IP2IP") + elif not self.account: + self.setFirstRegisteredAccount() - # Generate a call ID for this - m = hashlib.md5() - t = long( time.time() * 1000 ) - r = long( random.random()*100000000000000000L ) - m.update(str(t) + str(r)) - callid = m.hexdigest() + if self.account is "IP2IP" and self.isAccountRegistered(): + raise SflPhoneError("Can't place a call without a registered account") + + # Generate a call ID for this call + callid = self.GenerateCallID() # Add the call to the list of active calls and set status to SENT self.activeCalls[callid] = {'Account': self.account, 'To': dest, 'State': 'SENT' } + # Send the request to the CallManager self.callmanager.placeCall(self.account, callid, dest) @@ -425,14 +466,14 @@ class SflPhoneCtrlSimple(object): if not self.account: self.setFirstRegisteredAccount() - if not self.isAccountRegistered(): - raise SflPhoneError("Can't hangup a call without a registered account") + # if not self.isAccountRegistered() and self.accout is not "IP2IP": + # raise SflPhoneError("Can't hangup a call without a registered account") if callid is None or callid == "": pass # just to see #raise SflPhoneError("Invalid callID") - self.callmanager.hangUp(callid) + self.callmanager.hangUp(callid) def Transfert(self, callid, to): @@ -510,4 +551,11 @@ class SflPhoneCtrlSimple(object): self.callmanager.playDTMF(key) - + def GenerateCallID(self): + """Generate Call ID""" + m = hashlib.md5() + t = long( time.time() * 1000 ) + r = long( random.random()*100000000000000000L ) + m.update(str(t) + str(r)) + callid = m.hexdigest() + return callid