Skip to content
Snippets Groups Projects
Commit aea5c49b authored by Guillaume Roguez's avatar Guillaume Roguez
Browse files

sip: limit SIPVoIPLink respawn to 1

Also requires to check getSIPVoIPLink return everywhere.

Refs #64903

Change-Id: I8f62a38fd5e26efeb5d64a6a178352b4798dcbfa
parent 17846567
No related branches found
No related tags found
No related merge requests found
...@@ -374,7 +374,13 @@ SIPCall::refuse() ...@@ -374,7 +374,13 @@ SIPCall::refuse()
static void static void
transfer_client_cb(pjsip_evsub *sub, pjsip_event *event) 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)) { switch (pjsip_evsub_get_state(sub)) {
case PJSIP_EVSUB_STATE_ACCEPTED: case PJSIP_EVSUB_STATE_ACCEPTED:
......
...@@ -106,7 +106,7 @@ static void transaction_state_changed_cb(pjsip_inv_session *inv, pjsip_transacti ...@@ -106,7 +106,7 @@ static void transaction_state_changed_cb(pjsip_inv_session *inv, pjsip_transacti
pj_caching_pool* SIPVoIPLink::cp_ = &pool_cache; 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 * Helper function to process refer function on call transfer
...@@ -226,6 +226,10 @@ transaction_request_cb(pjsip_rx_data *rdata) ...@@ -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); const std::string remote_hostname(sip_from_uri->host.ptr, sip_from_uri->host.slen);
auto link = getSIPVoIPLink(); auto link = getSIPVoIPLink();
if (not link) {
RING_ERR("no more VoIP link");
return PJ_FALSE;
}
auto account(link->guessAccount(toUsername, viaHostname, remote_hostname)); auto account(link->guessAccount(toUsername, viaHostname, remote_hostname));
if (!account) { if (!account) {
...@@ -568,7 +572,8 @@ SIPVoIPLink::SIPVoIPLink() ...@@ -568,7 +572,8 @@ SIPVoIPLink::SIPVoIPLink()
// ready to handle events // ready to handle events
// Implementation note: we don't use std::bind(xxx, this) here // Implementation note: we don't use std::bind(xxx, this) here
// as handleEvents needs a valid instance to be called. // 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() SIPVoIPLink::~SIPVoIPLink()
...@@ -708,9 +713,11 @@ void SIPVoIPLink::cancelKeepAliveTimer(pj_timer_entry& timer) ...@@ -708,9 +713,11 @@ void SIPVoIPLink::cancelKeepAliveTimer(pj_timer_entry& timer)
void void
SIPVoIPLink::enqueueKeyframeRequest(const std::string &id) SIPVoIPLink::enqueueKeyframeRequest(const std::string &id)
{ {
auto link = getSIPVoIPLink(); if (auto link = getSIPVoIPLink()) {
std::lock_guard<std::mutex> lock(link->keyframeRequestsMutex_); std::lock_guard<std::mutex> lock(link->keyframeRequestsMutex_);
link->keyframeRequests_.push(id); link->keyframeRequests_.push(id);
} else
RING_ERR("no more VoIP link");
} }
// Called from SIP event thread // Called from SIP event thread
...@@ -1236,16 +1243,15 @@ SIPVoIPLink::resolveSrvName(const std::string &name, pjsip_transport_type_e type ...@@ -1236,16 +1243,15 @@ SIPVoIPLink::resolveSrvName(const std::string &name, pjsip_transport_type_e type
void void
SIPVoIPLink::resolver_callback(pj_status_t status, void *token, const struct pjsip_server_addresses *addr) SIPVoIPLink::resolver_callback(pj_status_t status, void *token, const struct pjsip_server_addresses *addr)
{ {
auto sthis_ = getSIPVoIPLink(); if (auto link = getSIPVoIPLink()) {
auto& this_ = *sthis_; std::lock_guard<std::mutex> lock(link->resolveMutex_);
{ auto it = link->resolveCallbacks_.find((uintptr_t)token);
std::lock_guard<std::mutex> lock(this_.resolveMutex_); if (it != link->resolveCallbacks_.end()) {
auto it = this_.resolveCallbacks_.find((uintptr_t)token);
if (it != this_.resolveCallbacks_.end()) {
it->second(status, addr); 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, ...) \ #define RETURN_IF_NULL(A, M, ...) \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment