From aea5c49b1468b3a7f9999fec0c95b93c4092c0c8 Mon Sep 17 00:00:00 2001 From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> Date: Mon, 2 Feb 2015 23:35:59 -0500 Subject: [PATCH] sip: limit SIPVoIPLink respawn to 1 Also requires to check getSIPVoIPLink return everywhere. Refs #64903 Change-Id: I8f62a38fd5e26efeb5d64a6a178352b4798dcbfa --- daemon/src/sip/sipcall.cpp | 8 +++++++- daemon/src/sip/sipvoiplink.cpp | 32 +++++++++++++++++++------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/daemon/src/sip/sipcall.cpp b/daemon/src/sip/sipcall.cpp index 3c17f4c12d..c87fee60fa 100644 --- a/daemon/src/sip/sipcall.cpp +++ b/daemon/src/sip/sipcall.cpp @@ -374,7 +374,13 @@ SIPCall::refuse() static void transfer_client_cb(pjsip_evsub *sub, pjsip_event *event) { - auto mod_ua_id = getSIPVoIPLink()->getModId(); + auto link = getSIPVoIPLink(); + if (not link) { + RING_ERR("no more VoIP link"); + return; + } + + auto mod_ua_id = link->getModId(); switch (pjsip_evsub_get_state(sub)) { case PJSIP_EVSUB_STATE_ACCEPTED: diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index c544b930eb..ebf0954dbc 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -106,7 +106,7 @@ static void transaction_state_changed_cb(pjsip_inv_session *inv, pjsip_transacti pj_caching_pool* SIPVoIPLink::cp_ = &pool_cache; -decltype(getGlobalInstance<SIPVoIPLink>)& getSIPVoIPLink = getGlobalInstance<SIPVoIPLink>; +decltype(getGlobalInstance<SIPVoIPLink>)& getSIPVoIPLink = getGlobalInstance<SIPVoIPLink, 1>; /** * Helper function to process refer function on call transfer @@ -226,6 +226,10 @@ transaction_request_cb(pjsip_rx_data *rdata) const std::string remote_hostname(sip_from_uri->host.ptr, sip_from_uri->host.slen); auto link = getSIPVoIPLink(); + if (not link) { + RING_ERR("no more VoIP link"); + return PJ_FALSE; + } auto account(link->guessAccount(toUsername, viaHostname, remote_hostname)); if (!account) { @@ -568,7 +572,8 @@ SIPVoIPLink::SIPVoIPLink() // ready to handle events // Implementation note: we don't use std::bind(xxx, this) here // as handleEvents needs a valid instance to be called. - Manager::instance().registerEventHandler((uintptr_t)this, []() { getSIPVoIPLink()->handleEvents(); }); + Manager::instance().registerEventHandler((uintptr_t)this, + [this]{ handleEvents(); }); } SIPVoIPLink::~SIPVoIPLink() @@ -708,9 +713,11 @@ void SIPVoIPLink::cancelKeepAliveTimer(pj_timer_entry& timer) void SIPVoIPLink::enqueueKeyframeRequest(const std::string &id) { - auto link = getSIPVoIPLink(); - std::lock_guard<std::mutex> lock(link->keyframeRequestsMutex_); - link->keyframeRequests_.push(id); + if (auto link = getSIPVoIPLink()) { + std::lock_guard<std::mutex> lock(link->keyframeRequestsMutex_); + link->keyframeRequests_.push(id); + } else + RING_ERR("no more VoIP link"); } // Called from SIP event thread @@ -1236,16 +1243,15 @@ SIPVoIPLink::resolveSrvName(const std::string &name, pjsip_transport_type_e type void SIPVoIPLink::resolver_callback(pj_status_t status, void *token, const struct pjsip_server_addresses *addr) { - auto sthis_ = getSIPVoIPLink(); - auto& this_ = *sthis_; - { - std::lock_guard<std::mutex> lock(this_.resolveMutex_); - auto it = this_.resolveCallbacks_.find((uintptr_t)token); - if (it != this_.resolveCallbacks_.end()) { + if (auto link = getSIPVoIPLink()) { + std::lock_guard<std::mutex> lock(link->resolveMutex_); + auto it = link->resolveCallbacks_.find((uintptr_t)token); + if (it != link->resolveCallbacks_.end()) { it->second(status, addr); - this_.resolveCallbacks_.erase(it); + link->resolveCallbacks_.erase(it); } - } + } else + RING_ERR("no more VoIP link"); } #define RETURN_IF_NULL(A, M, ...) \ -- GitLab