diff --git a/sflphone-common/src/dbus/configurationmanager.cpp b/sflphone-common/src/dbus/configurationmanager.cpp index 4f5e23df4759b2fd7752b6bffc5f6fd0dd6f164d..beca00b58e818ac08ced9e849832b838a16652d7 100644 --- a/sflphone-common/src/dbus/configurationmanager.cpp +++ b/sflphone-common/src/dbus/configurationmanager.cpp @@ -715,7 +715,7 @@ ConfigurationManager::getMailNotify (void) int ConfigurationManager::getSipAddress (void) { - return Manager::instance().getSipAddress(); + return Manager::instance().getLocalIp2IpPort(); // return "ok"; } @@ -724,7 +724,7 @@ void ConfigurationManager::setSipAddress (const std::string& address) { _debug ("Manager received setSipAddress: %s\n", address.c_str()); - Manager::instance().setSipAddress (address); + Manager::instance().setLocalIp2IpInfo(address); } std::map<std::string, int32_t> ConfigurationManager::getAddressbookSettings (void) diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index e8df4d0c8dc363ce372fcacde3bbb9b2a0c88cc9..76659fa7e9d62138ee5a7b59ecb2670657be7efa 100644 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -3235,9 +3235,11 @@ void ManagerImpl::setMicVolume (unsigned short mic_vol) } -void ManagerImpl::setSipAddress (const std::string& address) + + + +void ManagerImpl::setLocalIp2IpInfo(const std::string& address) { - _debug ("Setting new ip to ip address %s\n", address.c_str()); std::string ip_address = std::string(address); @@ -3245,25 +3247,40 @@ void ManagerImpl::setSipAddress (const std::string& address) std::string local_address = ip_address.substr(0,index); std::string local_port = ip_address.substr(index+1); + int newPort = atoi(local_port.c_str()); - _debug ("Setting new ip to ip address %s and port %s\n", local_address.c_str(), local_port.c_str()); + _debug ("Setting new address %s and port %s for default account (ip to ip calls)\n", local_address.c_str(), local_port.c_str()); int prevPort = getConfigInt (IP2IP_PROFILE, LOCAL_PORT); std::string prevAddress = getConfigString(IP2IP_PROFILE, LOCAL_ADDRESS); - if (prevPort != atoi(local_port.c_str()) || (prevAddress.compare(local_address) != 0)) { + if ((prevPort != newPort) || (prevAddress.compare(local_address) != 0)) { + + + if(_directIpAccount) { + + SIPAccount* account = dynamic_cast<SIPAccount*>(_directIpAccount); + + account->setLocalPort(newPort); + account->setLocalAddress(local_address); + } + setConfig (IP2IP_PROFILE, LOCAL_ADDRESS, local_address); - setConfig (IP2IP_PROFILE, LOCAL_PORT, atoi(local_port.c_str())); + setConfig (IP2IP_PROFILE, LOCAL_PORT, newPort); + + SIPVoIPLink* siplink = SIPVoIPLink::instance (""); + // if(siplink) + siplink->updateAccountInfo(_directIpAccount->getAccountID()); // this->restartPJSIP (); } } -int ManagerImpl::getSipAddress (void) +int ManagerImpl::getLocalIp2IpPort (void) { - // return getConfigInt (PREFERENCES , CONFIG_SIP_PORT); - /* The 'global' SIP port is set throug the IP profile */ - _debug("-----------------------------------------getSipAddress %i\n", getConfigInt (IP2IP_PROFILE, LOCAL_PORT)); + + /* The SIP port used for default account (IP to IP) calls */ + _debug("Default account port %i\n", getConfigInt (IP2IP_PROFILE, LOCAL_PORT)); return getConfigInt (IP2IP_PROFILE, LOCAL_PORT); @@ -4178,6 +4195,8 @@ short ManagerImpl::loadAccountMap() { + _debug("ManagerImpl::loadAccountMap\n"); + short nbAccount = 0; TokenList sections = _config.getSections(); std::string accountType; @@ -4186,7 +4205,7 @@ ManagerImpl::loadAccountMap() TokenList::iterator iter = sections.begin(); - // Those calls that are placed to an uri that cannot be + // Those calls that are placed to an uri that cannot be // associated to an account are using that special account. // An account, that is not account, in the sense of // registration. This is useful since the Account object @@ -4194,6 +4213,17 @@ ManagerImpl::loadAccountMap() // and loading of various settings. _directIpAccount = AccountCreator::createAccount (AccountCreator::SIP_DIRECT_IP_ACCOUNT, ""); + if (_directIpAccount == NULL) { + _debug ("Failed to create direct ip calls \"account\"\n"); + } else { + // Force the options to be loaded + // No registration in the sense of + // the REGISTER method is performed. + _debug ("Succeed to create direct ip calls \"account\"\n"); + _accountMap[IP2IP_PROFILE] = _directIpAccount; + _directIpAccount->registerVoIPLink(); + } + while (iter != sections.end()) { // Check if it starts with "Account:" (SIP and IAX pour le moment) if ( (int) (iter->find ("Account:")) != 0) { @@ -4223,7 +4253,7 @@ ManagerImpl::loadAccountMap() iter++; } - + /* if (_directIpAccount == NULL) { _debug ("Failed to create direct ip calls \"account\"\n"); } else { @@ -4232,9 +4262,10 @@ ManagerImpl::loadAccountMap() // the REGISTER method is performed. _debug ("Succeed to create direct ip calls \"account\"\n"); _directIpAccount->registerVoIPLink(); + _accountMap[IP2IP_PROFILE] = _directIpAccount; } - - _debug ("nbAccount loaded %i \n",nbAccount); + */ + _debug ("nbAccount loaded %i \n", nbAccount); return nbAccount; } @@ -4338,18 +4369,27 @@ ManagerImpl::getAccountIdFromNameAndServer (const std::string& userName, const s void ManagerImpl::restartPJSIP (void) { - SIPVoIPLink *siplink; - siplink = dynamic_cast<SIPVoIPLink*> (getSIPAccountLink ()); + _debug("ManagerImpl::restartPJSIP\n"); + VoIPLink *link = getSIPAccountLink(); + SIPVoIPLink *siplink = NULL; + + if(link) { + siplink = dynamic_cast<SIPVoIPLink*> (getSIPAccountLink ()); + } + _debug("ManagerImpl::unregister sip account\n"); this->unregisterCurSIPAccounts(); /* Terminate and initialize the PJSIP library */ if (siplink) { + _debug("ManagerImpl::Terminate sip\n"); siplink->terminate (); siplink = SIPVoIPLink::instance (""); + _debug("ManagerImpl::Init new sip\n"); siplink->init (); } + _debug("ManagerImpl::register sip account\n"); /* Then register all enabled SIP accounts */ this->registerCurSIPAccounts (siplink); } @@ -4372,14 +4412,17 @@ VoIPLink* ManagerImpl::getSIPAccountLink() { /* We are looking for the first SIP account we met because all the SIP accounts have the same voiplink */ Account *account; - AccountMap::iterator iter; + AccountMap::iterator iter = _accountMap.begin(); + + while(iter != _accountMap.end()) { - for (iter = _accountMap.begin(); iter != _accountMap.end(); ++iter) { account = iter->second; if (account->getType() == "sip") { return account->getVoIPLink(); } + + ++iter; } return NULL; diff --git a/sflphone-common/src/managerimpl.h b/sflphone-common/src/managerimpl.h index 997656a03ede1e0a47cb12e7d02191c067f0ae8d..032e5169dea69f3c3763256095c2e889b95adace 100644 --- a/sflphone-common/src/managerimpl.h +++ b/sflphone-common/src/managerimpl.h @@ -1307,9 +1307,9 @@ class ManagerImpl { AccountID getAccountIdFromNameAndServer(const std::string& userName, const std::string& server); - int getSipAddress(); + int getLocalIp2IpPort(); - void setSipAddress( const std::string& address ); + void setLocalIp2IpInfo( const std::string& address ); std::string getStunServer (void); void setStunServer (const std::string &server); diff --git a/sflphone-common/src/sip/sipaccount.cpp b/sflphone-common/src/sip/sipaccount.cpp index a28461dea4f53e0c60737f017b0a9abf47eca6c7..580d6bba5eb1592e47f8b4605ec8a02a6a422fd3 100644 --- a/sflphone-common/src/sip/sipaccount.cpp +++ b/sflphone-common/src/sip/sipaccount.cpp @@ -35,6 +35,7 @@ SIPAccount::SIPAccount (const AccountID& accountID) , _localPort (atoi (DEFAULT_SIP_PORT)) , _publishedPort (atoi (DEFAULT_SIP_PORT)) , _transportType (PJSIP_TRANSPORT_UNSPECIFIED) + , _transport(NULL) , _resolveOnce (false) , _credentialCount (0) , _cred (NULL) @@ -341,7 +342,6 @@ void SIPAccount::loadConfig() bool tlsEnabled = Manager::instance().getConfigBool (_accountID, TLS_ENABLE); if (tlsEnabled) { - _debug ("---------------------------- TLS Enabled\n"); initTlsConfiguration(); _transportType = PJSIP_TRANSPORT_TLS; } else { diff --git a/sflphone-common/src/sip/sipaccount.h b/sflphone-common/src/sip/sipaccount.h index 0b304bb326afa46752317aab13f14ac5ea4fedc7..7a3a17d887a4551938d2229a3b96e23b3eaf1757 100644 --- a/sflphone-common/src/sip/sipaccount.h +++ b/sflphone-common/src/sip/sipaccount.h @@ -331,7 +331,7 @@ class SIPAccount : public Account pjsip_transport_type_e _transportType; - pjsip_transport* _transport; + pjsip_transport* _transport; // Special hack that is not here to stay // See #1852 diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index d4db910d82bbdbf03f709faea25351ecdb0dbdc3..0a7a9fe29c695af9039ab61b68c6c90e23bd8060 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -246,7 +246,7 @@ SIPVoIPLink* SIPVoIPLink::instance (const AccountID& id) { if (!_instance) { - _debug ("Create new SIPVoIPLink instance\n"); + _debug ("Create new SIPVoIPLink instance\n"); _instance = new SIPVoIPLink (id); } @@ -270,7 +270,7 @@ bool SIPVoIPLink::init() // TODO This port should be the one configured for the IP profile // and not the global one - _regPort = Manager::instance().getSipAddress(); + _regPort = Manager::instance().getLocalIp2IpPort(); /* Instanciate the C++ thread */ _evThread = new EventThread (this); @@ -286,14 +286,21 @@ bool SIPVoIPLink::init() void SIPVoIPLink::terminate() { + _debug("SIPVoIPLink::terminate"); + + + if (_evThread) { + _debug("SIPVoIPLink:: delete eventThread"); delete _evThread; _evThread = NULL; } + /* Clean shutdown of pjsip library */ if (initDone()) { + _debug("pjsip_shutdown\n"); pjsip_shutdown(); } @@ -472,7 +479,7 @@ int SIPVoIPLink::sendRegister (AccountID id) status = createUDPServer (id); if (status != PJ_SUCCESS) { - _debug ("Use the local UDP transport", id.c_str()); + _debug ("Use the local UDP transport"); account->setAccountTransport (_localUDPTransport); } } @@ -1438,7 +1445,8 @@ bool SIPVoIPLink::new_ip_to_ip_call (const CallID& id, const std::string& to) AccountID accountId = Manager::instance().getAccountFromCall (id); SIPAccount * account = NULL; - account = dynamic_cast<SIPAccount *> (Manager::instance().getAccount (accountId)); + + account = dynamic_cast<SIPAccount *> (Manager::instance().getAccount (IP2IP_PROFILE)); if (account == NULL) { _debug ("Account is null. Returning\n"); @@ -1447,6 +1455,7 @@ bool SIPVoIPLink::new_ip_to_ip_call (const CallID& id, const std::string& to) // Set SDP parameters localAddress = account->getLocalAddress (); + _debug("new_ip_to_ip_call localAddress: %s\n", localAddress.c_str()); if (localAddress == "0.0.0.0"){ _debug ("Here is the local address: %s\n", localAddress.c_str ()); loadSIPLocalIP (&localAddress); @@ -1468,6 +1477,15 @@ bool SIPVoIPLink::new_ip_to_ip_call (const CallID& id, const std::string& to) _debug ("! SIP Failure: Unable to create RTP Session in SIPVoIPLink::new_ip_to_ip_call (%s:%d)\n", __FILE__, __LINE__); } + // If no account already set, use the default one created at pjsip initialization + if(account->getAccountTransport() == NULL) { + _debug("No transport for this account, using the default one\n"); + account->setAccountTransport(_localUDPTransport); + } + + _debug("IptoIP local port %i\n", account->getLocalPort()); + _debug("IptoIP local address %s\n", account->getLocalAddress().c_str()); + // Create URI std::string fromUri; @@ -1475,9 +1493,9 @@ bool SIPVoIPLink::new_ip_to_ip_call (const CallID& id, const std::string& to) fromUri = account->getFromUri(); - std::string address = findLocalAddressFromUri (toUri, _localUDPTransport); + std::string address = findLocalAddressFromUri (toUri, account->getAccountTransport()); - int port = findLocalPortFromUri (toUri, _localUDPTransport); + int port = findLocalPortFromUri (toUri, account->getAccountTransport()); std::stringstream ss; @@ -1520,7 +1538,7 @@ bool SIPVoIPLink::new_ip_to_ip_call (const CallID& id, const std::string& to) // Set the appropriate transport pjsip_tpselector *tp; - init_transport_selector (_localUDPTransport, &tp); + init_transport_selector (account->getAccountTransport(), &tp); status = pjsip_dlg_set_transport (dialog, tp); @@ -1657,6 +1675,8 @@ bool SIPVoIPLink::pjsip_init() name_mod = "sflphone"; + _debug("pjsip_init\n"); + // Init PJLIB: must be called before any call to the pjsip library status = pj_init(); // Use pjsip macros for sanity check @@ -1703,10 +1723,10 @@ bool SIPVoIPLink::pjsip_init() if (account == NULL) { _debug ("Account is null in pjsip init\n"); - port = _regPort; + port = _regPort; } else { directIpCallsTlsEnabled = account->isTlsEnabled(); - port = account->getLocalPort (); + port = account->getLocalPort (); } // Create a UDP listener meant for all accounts @@ -1729,6 +1749,9 @@ bool SIPVoIPLink::pjsip_init() } } + // Bind the newly created transport to the ip to ip account + // setAccountTransport + _debug ("pjsip_init -- listening on port %d\n", port); // Create a TLS listener meant for Direct IP calls @@ -1900,13 +1923,14 @@ int SIPVoIPLink::createUDPServer (AccountID id) pjsip_host_port a_name; char tmpIP[32]; pjsip_transport *transport; - std::string listeningAddress = "127.0.0.1"; - int listeningPort = _regPort; + std::string listeningAddress = "127.0.0.1"; + int listeningPort = _regPort; - /* Use my local address as default value */ - if (!loadSIPLocalIP (&listeningAddress)) - return !PJ_SUCCESS; + /* Use my local address as default value */ + if (!loadSIPLocalIP (&listeningAddress)) + return !PJ_SUCCESS; + _debug("SIPVoIPLink::createUDPServer\n"); /* * Retrieve the account information */ @@ -1916,7 +1940,8 @@ int SIPVoIPLink::createUDPServer (AccountID id) // Set information to the local address and port if (account == NULL) { - _debug ("Account is null in createUDPServer.\n"); + _debug ("Account with id \"%s\" is null in createUDPServer.\n", id.c_str()); + // account = Manager::instance()->getAccount(IP2IP_PROFILE); } else { // We are trying to initialize a UDP transport available for all local accounts and direct IP calls if (account->getLocalAddress () != "0.0.0.0"){ @@ -2266,7 +2291,7 @@ pj_status_t SIPVoIPLink::createAlternateUdpTransport (AccountID id) listeningPort = (int) a_name.port; // Set the address to be used in SDP - account->setPublishedAddress (listeningAddress); + account->setPublishedAddress (listeningAddress); account->setPublishedPort (listeningPort); // Create the UDP transport @@ -2360,6 +2385,15 @@ pj_status_t SIPVoIPLink::createTlsTransport (AccountID id) return PJ_SUCCESS; } + +void SIPVoIPLink::updateAccountInfo(const AccountID& accountID) +{ + + createUDPServer(accountID); + +} + + bool SIPVoIPLink::loadSIPLocalIP (std::string *addr) { @@ -2382,6 +2416,8 @@ bool SIPVoIPLink::loadSIPLocalIP (std::string *addr) void SIPVoIPLink::busy_sleep (unsigned msec) { + + _debug("SIPVoIPLink::busy_sleep\n"); #if defined(PJ_SYMBIAN) && PJ_SYMBIAN != 0 /* Ideally we shouldn't call pj_thread_sleep() and rather * CActiveScheduler::WaitForAnyRequest() here, but that will @@ -2400,6 +2436,7 @@ void SIPVoIPLink::busy_sleep (unsigned msec) pj_time_val_normalize (&tv); do { + _debug("tourne en rond\n"); pjsip_endpt_handle_events (_endpt, &tv); pj_gettimeofday (&now); } while (PJ_TIME_VAL_LT (now, timeout)); @@ -2436,6 +2473,8 @@ bool SIPVoIPLink::pjsip_shutdown (void) /* Shutdown PJLIB */ pj_shutdown(); + _debug ("UserAgent: Shutted down succesfully\n"); + /* Done. */ return true; } @@ -2911,8 +2950,6 @@ mod_on_rx_request (pjsip_rx_data *rdata) char* from_header = strstr (rdata->msg_info.msg_buf, "From: "); - // _debug("------------------------------ thefromheader: %s\n", from_header); - if (from_header) { std::string temp (from_header); diff --git a/sflphone-common/src/sip/sipvoiplink.h b/sflphone-common/src/sip/sipvoiplink.h index 87729d84a5d3b65bf167e2333e860fab774032ed..7b28b1761b1acb4a1869d8d8c02586faefe2e4b2 100644 --- a/sflphone-common/src/sip/sipvoiplink.h +++ b/sflphone-common/src/sip/sipvoiplink.h @@ -187,7 +187,7 @@ class SIPVoIPLink : public VoIPLink /** * Terminate only one call */ - void terminateOneCall(const CallID& id); + void terminateOneCall(const CallID& id); /** * Send an outgoing call invite @@ -297,6 +297,11 @@ class SIPVoIPLink : public VoIPLink bool loadSIPLocalIP (std::string *addr); + /** + * This method is used to create a new transport and attach it to the appropriate account + */ + void updateAccountInfo(const AccountID& accountID); + private: /** * Constructor