diff --git a/daemon/src/iax/iaxvoiplink.cpp b/daemon/src/iax/iaxvoiplink.cpp index d514a6a2e775728c00848e2fb9e968aca40c9982..f152c7b3ff638dedd1b934586f15ff3a545771b1 100644 --- a/daemon/src/iax/iaxvoiplink.cpp +++ b/daemon/src/iax/iaxvoiplink.cpp @@ -43,6 +43,8 @@ #include <cmath> #include <dlfcn.h> +AccountMap IAXVoIPLink::iaxAccountMap_ = AccountMap(); + IAXVoIPLink::IAXVoIPLink(const std::string& accountID) : regSession_(NULL) , nextRefreshStamp_(0) diff --git a/daemon/src/iax/iaxvoiplink.h b/daemon/src/iax/iaxvoiplink.h index 65ba6c8437c9aa7062f6d8b666678bfdbdd12f66..8aab3ba509c76d56a2a553b7b3bbba1765938c61 100644 --- a/daemon/src/iax/iaxvoiplink.h +++ b/daemon/src/iax/iaxvoiplink.h @@ -36,6 +36,7 @@ #include "config.h" #endif +#include "account.h" #include "voiplink.h" #include "audio/codecs/audiocodec.h" // for DEC_BUFFER_SIZE #include "sfl_types.h" @@ -66,7 +67,12 @@ class IAXVoIPLink : public VoIPLink { /** * Listen to events sent by the call manager ( asterisk, etc .. ) */ - bool getEvent(); + virtual bool getEvent(); + + /** + * Return the internal account map for this VOIP link + */ + static AccountMap &getInternalAccountMap() { return iaxAccountMap_; } /** * Init the voip link @@ -180,6 +186,12 @@ class IAXVoIPLink : public VoIPLink { private: NON_COPYABLE(IAXVoIPLink); + + /** + * Contains a list of all IAX account + */ + static AccountMap iaxAccountMap_; + /* * Decode the message count IAX send. * Returns only the new messages number diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 14cc4cb1f2b4c8acaaec25ea61cfa0323d7c69bb..b8d6b47753e9a19feda2f0a8d38c35485ee42dba 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -84,8 +84,8 @@ ManagerImpl::ManagerImpl() : currentCallId_(), currentCallMutex_(), audiodriver_(0), dtmfKey_(), toneMutex_(), telephoneTone_(), audiofile_(), audioLayerMutex_(), waitingCall_(), waitingCallMutex_(), nbIncomingWaitingCall_(0), path_(), - callAccountMap_(), callAccountMapMutex_(), IPToIPMap_(), sipAccountMap_(), - iaxAccountMap_(), mainBuffer_(), conferenceMap_(), history_(), finished_(false) + callAccountMap_(), callAccountMapMutex_(), IPToIPMap_(), + mainBuffer_(), conferenceMap_(), history_(), finished_(false) { // initialize random generator for call id srand(time(NULL)); @@ -1248,10 +1248,11 @@ void ManagerImpl::saveConfig() try { Conf::YamlEmitter emitter(path_.c_str()); - for (AccountMap::iterator iter = sipAccountMap_.begin(); iter != sipAccountMap_.end(); ++iter) + for (AccountMap::iterator iter = SIPVoIPLink::getInternalAccountMap().begin(); + iter != SIPVoIPLink::getInternalAccountMap().end(); ++iter) iter->second->serialize(emitter); - for (AccountMap::iterator iter = iaxAccountMap_.begin(); iter != iaxAccountMap_.end(); ++iter) + for (AccountMap::iterator iter = IAXVoIPLink::getInternalAccountMap().begin(); iter != IAXVoIPLink::getInternalAccountMap().end(); ++iter) iter->second->serialize(emitter); preferences.serialize(emitter); @@ -2390,12 +2391,12 @@ ManagerImpl::addAccount(const std::map<std::string, std::string>& details) if (accountType == "SIP") { newAccount = new SIPAccount(newAccountID); - sipAccountMap_[newAccountID] = newAccount; + SIPVoIPLink::getInternalAccountMap()[newAccountID] = newAccount; } #if HAVE_IAX else if (accountType == "IAX") { newAccount = new IAXAccount(newAccountID); - iaxAccountMap_[newAccountID] = newAccount; + IAXVoIPLink::getInternalAccountMap()[newAccountID] = newAccount; } #endif else { @@ -2437,8 +2438,8 @@ void ManagerImpl::removeAccount(const std::string& accountID) if (remAccount != NULL) { remAccount->unregisterVoIPLink(); - sipAccountMap_.erase(accountID); - iaxAccountMap_.erase(accountID); + SIPVoIPLink::getInternalAccountMap().erase(accountID); + IAXVoIPLink::getInternalAccountMap().erase(accountID); // http://projects.savoirfairelinux.net/issues/show/2355 // delete remAccount; } @@ -2592,21 +2593,21 @@ namespace { void ManagerImpl::loadDefaultAccountMap() { // build a default IP2IP account with default parameters only if does not exist - AccountMap::const_iterator iter = sipAccountMap_.find(SIPAccount::IP2IP_PROFILE); - if(iter == sipAccountMap_.end()) { - sipAccountMap_[SIPAccount::IP2IP_PROFILE] = createIP2IPAccount(); + AccountMap::const_iterator iter = SIPVoIPLink::getInternalAccountMap().find(SIPAccount::IP2IP_PROFILE); + if(iter == SIPVoIPLink::getInternalAccountMap().end()) { + SIPVoIPLink::getInternalAccountMap()[SIPAccount::IP2IP_PROFILE] = createIP2IPAccount(); } - sipAccountMap_[SIPAccount::IP2IP_PROFILE]->registerVoIPLink(); + SIPVoIPLink::getInternalAccountMap()[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 = sipAccountMap_.find(SIPAccount::IP2IP_PROFILE); - if(iter == sipAccountMap_.end()) { - sipAccountMap_[SIPAccount::IP2IP_PROFILE] = createIP2IPAccount(); + AccountMap::const_iterator iter = SIPVoIPLink::getInternalAccountMap().find(SIPAccount::IP2IP_PROFILE); + if(iter == SIPVoIPLink::getInternalAccountMap().end()) { + SIPVoIPLink::getInternalAccountMap()[SIPAccount::IP2IP_PROFILE] = createIP2IPAccount(); } // load saved preferences for IP2IP account from configuration file @@ -2616,12 +2617,12 @@ void ManagerImpl::loadAccountMap(Conf::YamlParser &parser) if (ip2ip != seq->end()) { MappingNode *node = dynamic_cast<MappingNode*>(*ip2ip); if (node) - sipAccountMap_[SIPAccount::IP2IP_PROFILE]->unserialize(*node); + SIPVoIPLink::getInternalAccountMap()[SIPAccount::IP2IP_PROFILE]->unserialize(*node); } // Force IP2IP settings to be loaded // No registration in the sense of the REGISTER method is performed. - sipAccountMap_[SIPAccount::IP2IP_PROFILE]->registerVoIPLink(); + SIPVoIPLink::getInternalAccountMap()[SIPAccount::IP2IP_PROFILE]->registerVoIPLink(); // build preferences preferences.unserialize(*parser.getPreferenceNode()); @@ -2646,46 +2647,46 @@ void ManagerImpl::loadAccountMap(Conf::YamlParser &parser) // std::for_each(seq->begin(), seq->end(), // std::tr1::bind(loadAccount, _1, std::tr1::ref(accountMap_))); std::for_each(seq->begin(), seq->end(), - std::tr1::bind(loadAccount, _1, std::tr1::ref(sipAccountMap_), std::tr1::ref(iaxAccountMap_))); + std::tr1::bind(loadAccount, _1, std::tr1::ref(SIPVoIPLink::getInternalAccountMap()), std::tr1::ref(IAXVoIPLink::getInternalAccountMap()))); } void ManagerImpl::registerAllAccounts() { - std::for_each(sipAccountMap_.begin(), sipAccountMap_.end(), registerAccount); - std::for_each(iaxAccountMap_.begin(), iaxAccountMap_.end(), registerAccount); + std::for_each(SIPVoIPLink::getInternalAccountMap().begin(), SIPVoIPLink::getInternalAccountMap().end(), registerAccount); + std::for_each(IAXVoIPLink::getInternalAccountMap().begin(), IAXVoIPLink::getInternalAccountMap().end(), registerAccount); } void ManagerImpl::unregisterAllAccounts() { - std::for_each(sipAccountMap_.begin(), sipAccountMap_.end(), unregisterAccount); - std::for_each(iaxAccountMap_.begin(), iaxAccountMap_.end(), unregisterAccount); + std::for_each(SIPVoIPLink::getInternalAccountMap().begin(), SIPVoIPLink::getInternalAccountMap().end(), unregisterAccount); + std::for_each(IAXVoIPLink::getInternalAccountMap().begin(), IAXVoIPLink::getInternalAccountMap().end(), unregisterAccount); } void ManagerImpl::unloadAccountMap() { - std::for_each(sipAccountMap_.begin(), sipAccountMap_.end(), unloadAccount); - sipAccountMap_.clear(); + std::for_each(SIPVoIPLink::getInternalAccountMap().begin(), SIPVoIPLink::getInternalAccountMap().end(), unloadAccount); + SIPVoIPLink::getInternalAccountMap().clear(); - std::for_each(iaxAccountMap_.begin(), iaxAccountMap_.end(), unloadAccount); - iaxAccountMap_.clear(); + std::for_each(IAXVoIPLink::getInternalAccountMap().begin(), IAXVoIPLink::getInternalAccountMap().end(), unloadAccount); + IAXVoIPLink::getInternalAccountMap().clear(); } bool ManagerImpl::accountExists(const std::string &accountID) { bool ret = false; - ret = sipAccountMap_.find(accountID) != sipAccountMap_.end(); + ret = SIPVoIPLink::getInternalAccountMap().find(accountID) != SIPVoIPLink::getInternalAccountMap().end(); if(ret) return ret; - return iaxAccountMap_.find(accountID) != iaxAccountMap_.end(); + return IAXVoIPLink::getInternalAccountMap().find(accountID) != IAXVoIPLink::getInternalAccountMap().end(); } SIPAccount* ManagerImpl::getIP2IPAccount() const { - AccountMap::const_iterator iter = sipAccountMap_.find(SIPAccount::IP2IP_PROFILE); - if(iter == sipAccountMap_.end()) + AccountMap::const_iterator iter = SIPVoIPLink::getInternalAccountMap().find(SIPAccount::IP2IP_PROFILE); + if(iter == SIPVoIPLink::getInternalAccountMap().end()) return NULL; return static_cast<SIPAccount *>(iter->second); @@ -2710,8 +2711,8 @@ ManagerImpl::getAccount(const std::string& accountID) const SIPAccount * ManagerImpl::getSipAccount(const std::string& accountID) const { - AccountMap::const_iterator iter = sipAccountMap_.find(accountID); - if(iter != sipAccountMap_.end()) + AccountMap::const_iterator iter = SIPVoIPLink::getInternalAccountMap().find(accountID); + if(iter != SIPVoIPLink::getInternalAccountMap().end()) return static_cast<SIPAccount *>(iter->second); return NULL; @@ -2720,8 +2721,8 @@ ManagerImpl::getSipAccount(const std::string& accountID) const IAXAccount * ManagerImpl::getIaxAccount(const std::string& accountID) const { - AccountMap::const_iterator iter = iaxAccountMap_.find(accountID); - if(iter != iaxAccountMap_.end()) + AccountMap::const_iterator iter = IAXVoIPLink::getInternalAccountMap().find(accountID); + if(iter != IAXVoIPLink::getInternalAccountMap().end()) return static_cast<IAXAccount *>(iter->second); return NULL; @@ -2729,8 +2730,8 @@ ManagerImpl::getIaxAccount(const std::string& accountID) const void ManagerImpl::fillConcatAccountMap(AccountMap &concatMap) const{ - concatMap.insert(sipAccountMap_.begin(), sipAccountMap_.end()); - concatMap.insert(iaxAccountMap_.begin(), iaxAccountMap_.end()); + concatMap.insert(SIPVoIPLink::getInternalAccountMap().begin(), SIPVoIPLink::getInternalAccountMap().end()); + concatMap.insert(IAXVoIPLink::getInternalAccountMap().begin(), IAXVoIPLink::getInternalAccountMap().end()); } std::string diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index f26f27e0fcaa8cc7b79c790ed3e82f6971e98f46..32bcdee45f60d6f2a170184c2d5dfbd1ce28f902 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -983,19 +983,8 @@ class ManagerImpl { std::map<std::string, bool> IPToIPMap_; - bool isIPToIP(const std::string& callID) const; - /** - * Contains a list of all SIP account - */ - AccountMap sipAccountMap_; - - /** - * Contains a list of all IAX account - */ - AccountMap iaxAccountMap_; - /** * Load the account map from configuration */ diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 32840a3e67870478e69b9039716e3ad799d98c51..01bd002e126daa1703c5099ced6d6654de4f0e7c 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -44,7 +44,6 @@ #include "sip/sdp.h" #include "sipcall.h" -#include "sipaccount.h" #include "eventthread.h" #if HAVE_SDES #include "sdes_negotiator.h" @@ -82,6 +81,7 @@ using namespace sfl; SIPVoIPLink *SIPVoIPLink::instance_ = 0; bool SIPVoIPLink::destroyed_ = false; +AccountMap SIPVoIPLink::sipAccountMap_ = AccountMap(); namespace { @@ -101,6 +101,7 @@ static std::map<std::string, std::string> transferCallID; */ void setCallMediaLocal(SIPCall* call, const std::string &localIP); + static pj_caching_pool pool_cache, *cp_ = &pool_cache; static pj_pool_t *pool_; static pjsip_endpoint *endpt_; @@ -413,7 +414,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_) + , evThread_(this) { #define TRY(ret) do { \ if (ret != PJ_SUCCESS) \ diff --git a/daemon/src/sip/sipvoiplink.h b/daemon/src/sip/sipvoiplink.h index 4c00020242e514c6b532519e928233ef595ecf7e..f0f57dd217c1d5191386e32744c6b79b864ae1af 100644 --- a/daemon/src/sip/sipvoiplink.h +++ b/daemon/src/sip/sipvoiplink.h @@ -90,6 +90,11 @@ class SIPVoIPLink : public VoIPLink { */ virtual bool getEvent(); + /** + * Return the internal account map for this VOIP link + */ + static AccountMap &getInternalAccountMap() { return sipAccountMap_; } + /** * Build and send SIP registration request */ @@ -273,6 +278,11 @@ class SIPVoIPLink : public VoIPLink { SIPVoIPLink(); ~SIPVoIPLink(); + /** + * Contains a list of all SIP account + */ + static AccountMap sipAccountMap_; + /** * Start a SIP Call * @param call The current call diff --git a/daemon/src/voiplink.h b/daemon/src/voiplink.h index ad3e521e9165ba513fcc9b39a0ce1b3fb8139bf8..765befd39b05d423f04345dd51cdd3adec67747a 100644 --- a/daemon/src/voiplink.h +++ b/daemon/src/voiplink.h @@ -36,7 +36,9 @@ #include <stdexcept> #include <map> + #include "cc_thread.h" // for ost::Mutex +#include "account.h" class Call; class Account;