From 8a708851da048ac01810ebc8bb1dc6f3ab9f6cc2 Mon Sep 17 00:00:00 2001 From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> Date: Mon, 18 Dec 2017 13:30:20 -0500 Subject: [PATCH] fix account type checkings Account::getAccountType() returns a raw pointer on char, but we use it with simple operators like == or != to check the semantic behind. This results to pointer comparaison and not "string" comparaison, causing many bugs. Fixed by changing the comparaison operators by "strcmp" function. Change-Id: I74baba083af0159d445c1505ddd5df55e6ca4fa7 Tuleap: #1575 Reviewed-by: Philippe Gorley <philippe.gorley@savoirfairelinux.com> --- src/account_factory.cpp | 4 ++-- src/manager.cpp | 10 +++++----- src/sip/sipvoiplink.cpp | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/account_factory.cpp b/src/account_factory.cpp index f4e08b029e..0f1c1850ff 100644 --- a/src/account_factory.cpp +++ b/src/account_factory.cpp @@ -76,12 +76,12 @@ AccountFactory::isSupportedType(const char* const name) const void AccountFactory::removeAccount(Account& account) { - const auto account_type = account.getAccountType(); + const auto* account_type = account.getAccountType(); std::lock_guard<std::recursive_mutex> lock(mutex_); const auto& id = account.getAccountID(); RING_DBG("Removing account %s", id.c_str()); - auto& map = accountMaps_.at(account.getAccountType()); + auto& map = accountMaps_.at(account_type); map.erase(id); RING_DBG("Remaining %zu %s account(s)", map.size(), account_type); } diff --git a/src/manager.cpp b/src/manager.cpp index 618c2228ef..33a131f985 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -3023,12 +3023,12 @@ Manager::newOutgoingCall(const std::string& toUrl, // If no prefered or not suitable account given, // find first usable account depending on url scheme. if (toUrl.find("ring:") != std::string::npos) { - if (!account or account->getAccountType() != RingAccount::ACCOUNT_TYPE) { - account = findAccount<RingAccount>([](const std::shared_ptr<RingAccount>& acc){ - return acc->isUsable(); - }); + if (!account or ::strcmp(account->getAccountType(), RingAccount::ACCOUNT_TYPE)) { + account = findAccount<RingAccount>([] (const std::shared_ptr<RingAccount>& acc) { + return acc->isUsable(); + }); } - } else if (!account or account->getAccountType() != SIPAccount::ACCOUNT_TYPE) { + } else if (!account or ::strcmp(account->getAccountType(), SIPAccount::ACCOUNT_TYPE)) { // For IP url restricts results on IP2IP accounts auto strippedToUrl = toUrl; sip_utils::stripSipUriPrefix(strippedToUrl); diff --git a/src/sip/sipvoiplink.cpp b/src/sip/sipvoiplink.cpp index d25b3a7627..d6e4a95bed 100644 --- a/src/sip/sipvoiplink.cpp +++ b/src/sip/sipvoiplink.cpp @@ -294,7 +294,7 @@ transaction_request_cb(pjsip_rx_data *rdata) // Append PJSIP transport to the broker's SipTransport list auto transport = link->sipTransportBroker->addTransport(rdata->tp_info.transport); if (!transport) { - if (account->getAccountType() == SIPAccount::ACCOUNT_TYPE) { + if (::strcmp(account->getAccountType(), SIPAccount::ACCOUNT_TYPE)) { RING_WARN("Using transport from account."); transport = std::static_pointer_cast<SIPAccount>(account)->getTransport(); } -- GitLab