diff --git a/daemon/src/iax/iaxvoiplink.h b/daemon/src/iax/iaxvoiplink.h index 726b0e80603423bf58487729eb4718bdce118e6f..325c2459e4026753dd94ab7b265be6d7082fea9f 100644 --- a/daemon/src/iax/iaxvoiplink.h +++ b/daemon/src/iax/iaxvoiplink.h @@ -74,7 +74,7 @@ class IAXVoIPLink : public VoIPLink { /** * Return the internal account map for this VOIP link */ - static AccountMap &getInternalAccountMap() { return iaxAccountMap_; } + static AccountMap &getAccounts() { return iaxAccountMap_; } /** * Init the voip link diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index dd7c970978fefbb70a7ad0510ef138cd4741bd3b..ddd7943346de9d89e3fc74c3c2ca537cd0338d2d 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -377,7 +377,7 @@ void ManagerImpl::hangupCall(const std::string& callId) if (isIPToIP(callId)) { /* Direct IP to IP call */ try { - Call * call = SIPVoIPLink::getSipCall(callId); + Call * call = SIPVoIPLink::instance()->getSipCall(callId); if (call) { history_.addCall(call, preferences.getHistoryLimit()); SIPVoIPLink::instance()->hangup(callId); @@ -871,7 +871,7 @@ ManagerImpl::getCallFromCallID(const std::string &callID) { Call *call = NULL; - call = SIPVoIPLink::getSipCall(callID); + call = SIPVoIPLink::instance()->getSipCall(callID); #if HAVE_IAX if(call != NULL) return call; @@ -1256,12 +1256,12 @@ void ManagerImpl::saveConfig() try { Conf::YamlEmitter emitter(path_.c_str()); - for (AccountMap::iterator iter = SIPVoIPLink::getInternalAccountMap().begin(); - iter != SIPVoIPLink::getInternalAccountMap().end(); ++iter) + for (AccountMap::iterator iter = SIPVoIPLink::instance()->getAccounts().begin(); + iter != SIPVoIPLink::instance()->getAccounts().end(); ++iter) iter->second->serialize(emitter); #if HAVE_IAX - for (AccountMap::iterator iter = IAXVoIPLink::getInternalAccountMap().begin(); iter != IAXVoIPLink::getInternalAccountMap().end(); ++iter) + for (AccountMap::iterator iter = IAXVoIPLink::getAccounts().begin(); iter != IAXVoIPLink::getAccounts().end(); ++iter) iter->second->serialize(emitter); #endif @@ -1563,7 +1563,7 @@ void ManagerImpl::peerHungupCall(const std::string& call_id) /* Direct IP to IP call */ if (isIPToIP(call_id)) { - Call * call = SIPVoIPLink::getSipCall(call_id); + Call * call = SIPVoIPLink::instance()->getSipCall(call_id); history_.addCall(call, preferences.getHistoryLimit()); SIPVoIPLink::instance()->hangup(call_id); saveHistory(); @@ -2400,12 +2400,12 @@ ManagerImpl::addAccount(const std::map<std::string, std::string>& details) if (accountType == "SIP") { newAccount = new SIPAccount(newAccountID); - SIPVoIPLink::getInternalAccountMap()[newAccountID] = newAccount; + SIPVoIPLink::instance()->getAccounts()[newAccountID] = newAccount; } #if HAVE_IAX else if (accountType == "IAX") { newAccount = new IAXAccount(newAccountID); - IAXVoIPLink::getInternalAccountMap()[newAccountID] = newAccount; + IAXVoIPLink::getAccounts()[newAccountID] = newAccount; } #endif else { @@ -2447,9 +2447,9 @@ void ManagerImpl::removeAccount(const std::string& accountID) if (remAccount != NULL) { remAccount->unregisterVoIPLink(); - SIPVoIPLink::getInternalAccountMap().erase(accountID); + SIPVoIPLink::instance()->getAccounts().erase(accountID); #if HAVE_IAX - IAXVoIPLink::getInternalAccountMap().erase(accountID); + IAXVoIPLink::getAccounts().erase(accountID); #endif // http://projects.savoirfairelinux.net/issues/show/2355 // delete remAccount; @@ -2607,34 +2607,32 @@ namespace { void ManagerImpl::loadDefaultAccountMap() { // build a default IP2IP account with default parameters only if does not exist - AccountMap::const_iterator iter = SIPVoIPLink::getInternalAccountMap().find(SIPAccount::IP2IP_PROFILE); - if(iter == SIPVoIPLink::getInternalAccountMap().end()) { - SIPVoIPLink::getInternalAccountMap()[SIPAccount::IP2IP_PROFILE] = createIP2IPAccount(); - } + AccountMap::const_iterator iter = SIPVoIPLink::instance()->getAccounts().find(SIPAccount::IP2IP_PROFILE); + if (iter == SIPVoIPLink::instance()->getAccounts().end()) + SIPVoIPLink::instance()->getAccounts()[SIPAccount::IP2IP_PROFILE] = createIP2IPAccount(); - SIPVoIPLink::getInternalAccountMap()[SIPAccount::IP2IP_PROFILE]->registerVoIPLink(); + SIPVoIPLink::instance()->getAccounts()[SIPAccount::IP2IP_PROFILE]->registerVoIPLink(); } void ManagerImpl::loadAccountMap(Conf::YamlParser &parser) { using namespace Conf; // build a default IP2IP account with default parameters - AccountMap::const_iterator iter = SIPVoIPLink::getInternalAccountMap().find(SIPAccount::IP2IP_PROFILE); - if(iter == SIPVoIPLink::getInternalAccountMap().end()) { - SIPVoIPLink::getInternalAccountMap()[SIPAccount::IP2IP_PROFILE] = createIP2IPAccount(); - } + AccountMap::const_iterator iter = SIPVoIPLink::instance()->getAccounts().find(SIPAccount::IP2IP_PROFILE); + if (iter == SIPVoIPLink::instance()->getAccounts().end()) + SIPVoIPLink::instance()->getAccounts()[SIPAccount::IP2IP_PROFILE] = createIP2IPAccount(); // load saved preferences for IP2IP account from configuration file Sequence *seq = parser.getAccountSequence()->getSequence(); Sequence::const_iterator ip2ip = std::find_if(seq->begin(), seq->end(), isIP2IP); if (ip2ip != seq->end()) { - SIPVoIPLink::getInternalAccountMap()[SIPAccount::IP2IP_PROFILE]->unserialize(**ip2ip); + SIPVoIPLink::instance()->getAccounts()[SIPAccount::IP2IP_PROFILE]->unserialize(**ip2ip); } // Force IP2IP settings to be loaded // No registration in the sense of the REGISTER method is performed. - SIPVoIPLink::getInternalAccountMap()[SIPAccount::IP2IP_PROFILE]->registerVoIPLink(); + SIPVoIPLink::instance()->getAccounts()[SIPAccount::IP2IP_PROFILE]->registerVoIPLink(); // build preferences preferences.unserialize(*parser.getPreferenceNode()); @@ -2660,37 +2658,37 @@ void ManagerImpl::loadAccountMap(Conf::YamlParser &parser) // std::tr1::bind(loadAccount, _1, std::tr1::ref(accountMap_))); #if HAVE_IAX std::for_each(seq->begin(), seq->end(), - std::tr1::bind(loadAccount, _1, std::tr1::ref(SIPVoIPLink::getInternalAccountMap()), std::tr1::ref(IAXVoIPLink::getInternalAccountMap()))); + std::tr1::bind(loadAccount, _1, std::tr1::ref(SIPVoIPLink::instance()->getAccounts()), std::tr1::ref(IAXVoIPLink::getAccounts()))); #else std::for_each(seq->begin(), seq->end(), - std::tr1::bind(loadAccount, _1, std::tr1::ref(SIPVoIPLink::getInternalAccountMap()))); + std::tr1::bind(loadAccount, _1, std::tr1::ref(SIPVoIPLink::instance()->getAccounts()))); #endif } void ManagerImpl::registerAllAccounts() { - std::for_each(SIPVoIPLink::getInternalAccountMap().begin(), SIPVoIPLink::getInternalAccountMap().end(), registerAccount); + std::for_each(SIPVoIPLink::instance()->getAccounts().begin(), SIPVoIPLink::instance()->getAccounts().end(), registerAccount); #if HAVE_IAX - std::for_each(IAXVoIPLink::getInternalAccountMap().begin(), IAXVoIPLink::getInternalAccountMap().end(), registerAccount); + std::for_each(IAXVoIPLink::getAccounts().begin(), IAXVoIPLink::getAccounts().end(), registerAccount); #endif } void ManagerImpl::unregisterAllAccounts() { - std::for_each(SIPVoIPLink::getInternalAccountMap().begin(), SIPVoIPLink::getInternalAccountMap().end(), unregisterAccount); + std::for_each(SIPVoIPLink::instance()->getAccounts().begin(), SIPVoIPLink::instance()->getAccounts().end(), unregisterAccount); #if HAVE_IAX - std::for_each(IAXVoIPLink::getInternalAccountMap().begin(), IAXVoIPLink::getInternalAccountMap().end(), unregisterAccount); + std::for_each(IAXVoIPLink::getAccounts().begin(), IAXVoIPLink::getAccounts().end(), unregisterAccount); #endif } void ManagerImpl::unloadAccountMap() { - std::for_each(SIPVoIPLink::getInternalAccountMap().begin(), SIPVoIPLink::getInternalAccountMap().end(), unloadAccount); - SIPVoIPLink::getInternalAccountMap().clear(); + std::for_each(SIPVoIPLink::instance()->getAccounts().begin(), SIPVoIPLink::instance()->getAccounts().end(), unloadAccount); + SIPVoIPLink::instance()->getAccounts().clear(); #if HAVE_IAX - std::for_each(IAXVoIPLink::getInternalAccountMap().begin(), IAXVoIPLink::getInternalAccountMap().end(), unloadAccount); - IAXVoIPLink::getInternalAccountMap().clear(); + std::for_each(IAXVoIPLink::getAccounts().begin(), IAXVoIPLink::getAccounts().end(), unloadAccount); + IAXVoIPLink::getAccounts().clear(); #endif } @@ -2698,12 +2696,12 @@ bool ManagerImpl::accountExists(const std::string &accountID) { bool ret = false; - ret = SIPVoIPLink::getInternalAccountMap().find(accountID) != SIPVoIPLink::getInternalAccountMap().end(); + ret = SIPVoIPLink::instance()->getAccounts().find(accountID) != SIPVoIPLink::instance()->getAccounts().end(); #if HAVE_IAX if(ret) return ret; - ret = IAXVoIPLink::getInternalAccountMap().find(accountID) != IAXVoIPLink::getInternalAccountMap().end(); + ret = IAXVoIPLink::getAccounts().find(accountID) != IAXVoIPLink::getAccounts().end(); #endif return ret; @@ -2712,8 +2710,8 @@ bool ManagerImpl::accountExists(const std::string &accountID) SIPAccount* ManagerImpl::getIP2IPAccount() const { - AccountMap::const_iterator iter = SIPVoIPLink::getInternalAccountMap().find(SIPAccount::IP2IP_PROFILE); - if(iter == SIPVoIPLink::getInternalAccountMap().end()) + AccountMap::const_iterator iter = SIPVoIPLink::instance()->getAccounts().find(SIPAccount::IP2IP_PROFILE); + if(iter == SIPVoIPLink::instance()->getAccounts().end()) return NULL; return static_cast<SIPAccount *>(iter->second); @@ -2740,8 +2738,8 @@ ManagerImpl::getAccount(const std::string& accountID) const SIPAccount * ManagerImpl::getSipAccount(const std::string& accountID) const { - AccountMap::const_iterator iter = SIPVoIPLink::getInternalAccountMap().find(accountID); - if(iter != SIPVoIPLink::getInternalAccountMap().end()) + AccountMap::const_iterator iter = SIPVoIPLink::instance()->getAccounts().find(accountID); + if(iter != SIPVoIPLink::instance()->getAccounts().end()) return static_cast<SIPAccount *>(iter->second); return NULL; @@ -2751,8 +2749,8 @@ ManagerImpl::getSipAccount(const std::string& accountID) const IAXAccount * ManagerImpl::getIaxAccount(const std::string& accountID) const { - AccountMap::const_iterator iter = IAXVoIPLink::getInternalAccountMap().find(accountID); - if(iter != IAXVoIPLink::getInternalAccountMap().end()) + AccountMap::const_iterator iter = IAXVoIPLink::getAccounts().find(accountID); + if(iter != IAXVoIPLink::getAccounts().end()) return static_cast<IAXAccount *>(iter->second); return NULL; @@ -2760,10 +2758,11 @@ ManagerImpl::getIaxAccount(const std::string& accountID) const #endif void -ManagerImpl::fillConcatAccountMap(AccountMap &concatMap) const{ - concatMap.insert(SIPVoIPLink::getInternalAccountMap().begin(), SIPVoIPLink::getInternalAccountMap().end()); +ManagerImpl::fillConcatAccountMap(AccountMap &concatMap) const +{ + concatMap.insert(SIPVoIPLink::instance()->getAccounts().begin(), SIPVoIPLink::instance()->getAccounts().end()); #if HAVE_IAX - concatMap.insert(IAXVoIPLink::getInternalAccountMap().begin(), IAXVoIPLink::getInternalAccountMap().end()); + concatMap.insert(IAXVoIPLink::getAccounts().begin(), IAXVoIPLink::getAccounts().end()); #endif } diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 960c31992987f7e955ab9c3520f368f34bd823ba..cb4cf0ed41e1a202965b74c8837005bd3ec17c4e 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -82,10 +82,6 @@ using namespace sfl; SIPVoIPLink *SIPVoIPLink::instance_ = 0; bool SIPVoIPLink::destroyed_ = false; -AccountMap SIPVoIPLink::sipAccountMap_; -SipCallMap SIPVoIPLink::sipCallMap_; -ost::Mutex SIPVoIPLink::sipCallMapMutex_; - namespace { /** Environment variable used to set pjsip's logging level */ @@ -408,7 +404,7 @@ pj_bool_t transaction_request_cb(pjsip_rx_data *rdata) call->setConnectionState(Call::RINGING); Manager::instance().incomingCall(*call, account_id); - SIPVoIPLink::addSipCall(call); + SIPVoIPLink::instance()->addSipCall(call); } return PJ_FALSE; @@ -417,8 +413,8 @@ pj_bool_t transaction_request_cb(pjsip_rx_data *rdata) /*************************************************************************************************/ -SIPVoIPLink::SIPVoIPLink() : sipTransport(endpt_, cp_, pool_) - , evThread_(this) +SIPVoIPLink::SIPVoIPLink() : sipTransport(endpt_, cp_, pool_), sipAccountMap_(), + sipCallMapMutex_(), sipCallMap_(), evThread_(this) { #define TRY(ret) do { \ if (ret != PJ_SUCCESS) \ @@ -1285,7 +1281,10 @@ dtmfSend(SIPCall &call, char code, const std::string &dtmf) void SIPVoIPLink::requestFastPictureUpdate(const std::string &callID) { - SIPCall *call = SIPVoIPLink::tryGetSipCall(callID); + SIPCall *call = 0; + const int tries = 10; + for (int i = 0; !call and i < tries; ++i) + call = SIPVoIPLink::instance()->tryGetSipCall(callID); if (!call) return; @@ -1371,8 +1370,8 @@ SIPVoIPLink::SIPStartCall(SIPCall *call) pjsip_tpselector *tp_sel = sipTransport.createTransportSelector(account->transport_, call->inv->pool); - if (pjsip_dlg_set_transport(dialog, tp_sel) != PJ_SUCCESS) { - ERROR("Unable to associate transport fir invite session dialog"); + if (!dialog or !tp_sel or pjsip_dlg_set_transport(dialog, tp_sel) != PJ_SUCCESS) { + ERROR("Unable to associate transport for invite session dialog"); return false; } @@ -2085,7 +2084,7 @@ void transfer_client_cb(pjsip_evsub *sub, pjsip_event *event) if (r_data->msg_info.cid) return; std::string transferID(r_data->msg_info.cid->id.ptr, r_data->msg_info.cid->id.slen); - SIPCall *call = SIPVoIPLink::getSipCall(transferCallID[transferID]); + SIPCall *call = SIPVoIPLink::instance()->getSipCall(transferCallID[transferID]); if (!call) return; diff --git a/daemon/src/sip/sipvoiplink.h b/daemon/src/sip/sipvoiplink.h index ca7b14eb1053f94e54e8844521346c303d2380ce..924915be9ed558784d7bf98040bb62b870b400f5 100644 --- a/daemon/src/sip/sipvoiplink.h +++ b/daemon/src/sip/sipvoiplink.h @@ -94,7 +94,7 @@ class SIPVoIPLink : public VoIPLink { /** * Return the internal account map for this VOIP link */ - static AccountMap &getInternalAccountMap() { return sipAccountMap_; } + AccountMap &getAccounts() { return sipAccountMap_; } /** * Build and send SIP registration request @@ -266,11 +266,11 @@ class SIPVoIPLink : public VoIPLink { const std::string& message, const std::string& from); #endif - static void clearSipCallMap(); - static void addSipCall(SIPCall* call); - static SIPCall* getSipCall(const std::string& id); - static SIPCall* tryGetSipCall(const std::string& id); - static void removeSipCall(const std::string &id); + void clearSipCallMap(); + void addSipCall(SIPCall* call); + SIPCall* getSipCall(const std::string& id); + SIPCall* tryGetSipCall(const std::string& id); + void removeSipCall(const std::string &id); /** * Create the default UDP transport according ot Ip2Ip profile settings @@ -296,10 +296,10 @@ class SIPVoIPLink : public VoIPLink { /** * Contains a list of all SIP account */ - static AccountMap sipAccountMap_; + AccountMap sipAccountMap_; - static ost::Mutex sipCallMapMutex_; - static SipCallMap sipCallMap_; + ost::Mutex sipCallMapMutex_; + SipCallMap sipCallMap_; /** * Start a SIP Call