From e3c54bf015f9fe2ea8db26ad2fb9f08276f784c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Mon, 7 Mar 2016 13:57:13 -0500 Subject: [PATCH] dring: remove IP2IP accounts The API and internals forced a single, activated IP2IP account. This design prevented to disable the IP2IP account or to have multiple IP2IP accounts (eg. on different ports, IPv4 and IPv6 etc.) This patch completly removes the "IP2IP" account concept from the daemon. An SIP account is now considered "IP2IP" if it has no hostname. Change-Id: I483dbbb9e5546f7c54fbf2d2910a93200ef3b82c Tuleap: #448 Signed-off-by: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> --- bin/dbus/configurationmanager-introspec.xml | 36 ------------ bin/dbus/dbusconfigurationmanager.cpp | 6 -- bin/dbus/dbusconfigurationmanager.h | 1 - src/account_factory.cpp | 15 ----- src/account_factory.h | 5 -- src/client/configurationmanager.cpp | 10 ---- src/client/presencemanager.cpp | 7 ++- src/dring/configurationmanager_interface.h | 2 - src/manager.cpp | 61 ++++----------------- src/manager.h | 6 -- src/sip/pres_sub_server.cpp | 17 +++++- src/sip/sipaccount.cpp | 27 +-------- src/sip/sipaccount.h | 6 -- src/sip/sipvoiplink.cpp | 2 +- 14 files changed, 34 insertions(+), 167 deletions(-) diff --git a/bin/dbus/configurationmanager-introspec.xml b/bin/dbus/configurationmanager-introspec.xml index fc055d5267..3cf3e73d4c 100644 --- a/bin/dbus/configurationmanager-introspec.xml +++ b/bin/dbus/configurationmanager-introspec.xml @@ -131,42 +131,6 @@ </arg> </method> - <method name="getIp2IpDetails" tp:name-for-bindings="getIp2IpDetails"> - <tp:docstring> - Get configuration settings of the IP2IP_PROFILE. They are sligthly different from account settings since no VoIP accounts are involved. - </tp:docstring> - <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="MapStringString"/> - <arg type="a{ss}" name="details" direction="out" tp:type="String_String_Map"> - <tp:docstring> - Available parameters are: - <ul> - <li>ACCOUNT_ID</li> - <li>SRTP_KEY_EXCHANGE</li> - <li>SRTP_ENABLE</li> - <li>SRTP_RTP_FALLBACK</li> - <li>ZRTP_DISPLAY_SAS</li> - <li>ZRTP_HELLO_HASH</li> - <li>ZRTP_NOT_SUPP_WARNING</li> - <li>ZRTP_DISPLAY_SAS_ONCE</li> - <li>LOCAL_INTERFACE</li> - <li>LOCAL_PORT</li> - <li>TLS_LISTENER_PORT</li> - <li>TLS_CA_LIST_FILE</li> - <li>TLS_CERTIFICATE_FILE</li> - <li>TLS_PRIVATE_KEY_FILE</li> - <li>TLS_PASSWORD</li> - <li>TLS_METHOD</li> - <li>TLS_CIPHERS</li> - <li>TLS_SERVER_NAME</li> - <li>TLS_VERIFY_SERVER</li> - <li>TLS_VERIFY_CLIENT</li> - <li>TLS_REQUIRE_CLIENT_CERTIFICATE</li> - <li>TLS_NEGOTIATION_TIMEOUT_SEC</li> - </ul> - </tp:docstring> - </arg> - </method> - <method name="getCredentials" tp:name-for-bindings="getCredentials"> <arg type="s" name="accountID" direction="in"> </arg> diff --git a/bin/dbus/dbusconfigurationmanager.cpp b/bin/dbus/dbusconfigurationmanager.cpp index b16d1f8db3..5bd6cf6681 100644 --- a/bin/dbus/dbusconfigurationmanager.cpp +++ b/bin/dbus/dbusconfigurationmanager.cpp @@ -468,12 +468,6 @@ DBusConfigurationManager::sendTrustRequest(const std::string& accountId, const s DRing::sendTrustRequest(accountId, to, payload); } -auto -DBusConfigurationManager::getIp2IpDetails() -> decltype(DRing::getIp2IpDetails()) -{ - return DRing::getIp2IpDetails(); -} - auto DBusConfigurationManager::getCredentials(const std::string& accountID) -> decltype(DRing::getCredentials(accountID)) { diff --git a/bin/dbus/dbusconfigurationmanager.h b/bin/dbus/dbusconfigurationmanager.h index bd889f899c..04e3b25735 100644 --- a/bin/dbus/dbusconfigurationmanager.h +++ b/bin/dbus/dbusconfigurationmanager.h @@ -111,7 +111,6 @@ class DBusConfigurationManager : void setAccountsOrder(const std::string& order); std::map<std::string, std::string> getHookSettings(); void setHookSettings(const std::map<std::string, std::string>& settings); - std::map<std::string, std::string> getIp2IpDetails(); std::vector<std::map<std::string, std::string>> getCredentials(const std::string& accountID); void setCredentials(const std::string& accountID, const std::vector<std::map<std::string, std::string>>& details); std::string getAddrFromInterfaceName(const std::string& interface); diff --git a/src/account_factory.cpp b/src/account_factory.cpp index 59040cfa8a..75949ff5de 100644 --- a/src/account_factory.cpp +++ b/src/account_factory.cpp @@ -32,8 +32,6 @@ #include "ringdht/ringaccount.h" #endif -#include "sip/sipvoiplink.h" // for SIPVoIPLink::loadIP2IPSettings - #include <stdexcept> namespace ring { @@ -193,17 +191,4 @@ AccountFactory::accountCount() const return count; } -std::shared_ptr<Account> -AccountFactory::getIP2IPAccount() const -{ - return ip2ip_account_.lock(); -} - -void AccountFactory::initIP2IPAccount() -{ - // cache this often used account using a weak_ptr - ip2ip_account_ = createAccount(SIPAccount::ACCOUNT_TYPE, - SIPAccount::IP2IP_PROFILE); -} - } // namespace ring diff --git a/src/account_factory.h b/src/account_factory.h index 1fd1f807e0..576873aad3 100644 --- a/src/account_factory.h +++ b/src/account_factory.h @@ -116,15 +116,10 @@ class AccountFactory { return v; } - std::shared_ptr<Account> getIP2IPAccount() const; - - void initIP2IPAccount(); - private: mutable std::recursive_mutex mutex_ = {}; std::map<std::string, std::function<std::shared_ptr<Account>(const std::string&)> > generators_ = {}; std::map<std::string, AccountMap<Account> > accountMaps_ = {}; - std::weak_ptr<Account> ip2ip_account_ = {}; //! cached pointer on IP2IP account template <class T> const AccountMap<Account>* getMap_() const { diff --git a/src/client/configurationmanager.cpp b/src/client/configurationmanager.cpp index 374078e531..0a83ed1209 100644 --- a/src/client/configurationmanager.cpp +++ b/src/client/configurationmanager.cpp @@ -77,16 +77,6 @@ registerConfHandlers(const std::map<std::string, } } -std::map<std::string, std::string> -getIp2IpDetails() -{ - auto account = ring::Manager::instance().getIP2IPAccount(); - if (auto sipaccount = static_cast<SIPAccount*>(account.get())) - return sipaccount->getIp2IpDetails(); - RING_ERR("Could not find IP2IP account"); - return std::map<std::string, std::string>(); -} - std::map<std::string, std::string> getAccountDetails(const std::string& accountID) { diff --git a/src/client/presencemanager.cpp b/src/client/presencemanager.cpp index c2d6d10ee9..18f5856a5f 100644 --- a/src/client/presencemanager.cpp +++ b/src/client/presencemanager.cpp @@ -35,6 +35,7 @@ #include "sip/sippresence.h" #include "sip/pres_sub_client.h" #include "client/ring_signal.h" +#include "intrin.h" namespace DRing { @@ -100,8 +101,9 @@ publish(const std::string& accountID, bool status, const std::string& note) * Accept or not a PresSubServer request for IP2IP account */ void -answerServerRequest(const std::string& uri, bool flag) +answerServerRequest(UNUSED const std::string& uri, UNUSED bool flag) { +#if 0 // DISABLED: removed IP2IP support, tuleap: #448 auto account = ring::Manager::instance().getIP2IPAccount(); if (auto sipaccount = static_cast<SIPAccount *>(account.get())) { RING_DBG("Approve presence (acc:IP2IP, serv:%s, flag:%s)", uri.c_str(), @@ -113,6 +115,9 @@ answerServerRequest(const std::string& uri, bool flag) RING_ERR("Presence not initialized"); } else RING_ERR("Could not find account IP2IP"); +#else + RING_ERR("answerServerRequest() is deprecated and does nothing"); +#endif } /** diff --git a/src/dring/configurationmanager_interface.h b/src/dring/configurationmanager_interface.h index 5f8d81b4a3..7789041b43 100644 --- a/src/dring/configurationmanager_interface.h +++ b/src/dring/configurationmanager_interface.h @@ -106,8 +106,6 @@ void setAccountsOrder(const std::string& order); std::map<std::string, std::string> getHookSettings(); void setHookSettings(const std::map<std::string, std::string>& settings); -std::map<std::string, std::string> getIp2IpDetails(); - std::vector<std::map<std::string, std::string>> getCredentials(const std::string& accountID); void setCredentials(const std::string& accountID, const std::vector<std::map<std::string, std::string>>& details); diff --git a/src/manager.cpp b/src/manager.cpp index 3a10828712..17b0e9a9e2 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -9,6 +9,7 @@ * Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com> * Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com> * Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> + * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -85,8 +86,6 @@ using random_device = std::random_device; #include <iostream> #include <fstream> #include <sstream> -#include <sys/types.h> // mkdir(2) -#include <sys/stat.h> // mkdir(2) #include <memory> #include <mutex> @@ -201,12 +200,6 @@ Manager::setAutoAnswer(bool enable) autoAnswer_ = enable; } -void -Manager::loadDefaultAccountMap() -{ - accountFactory_.initIP2IPAccount(); -} - Manager::Manager() : pluginManager_(new PluginManager) , preferences(), voipPreferences(), @@ -250,8 +243,7 @@ Manager::parseConfiguration() result = false; } } catch (const YAML::BadFile &e) { - RING_WARN("Could not open config file: creating default account map"); - loadDefaultAccountMap(); + RING_WARN("Could not open configuration file"); } return result; @@ -319,8 +311,7 @@ Manager::init(const std::string &config_file) parseConfiguration(); } catch (const YAML::Exception &e) { RING_ERR("%s", e.what()); - RING_WARN("Restoring backup failed, creating default account map"); - loadDefaultAccountMap(); + RING_WARN("Restoring backup failed"); } } @@ -2329,44 +2320,24 @@ Manager::setAccountsOrder(const std::string& order) std::vector<std::string> Manager::getAccountList() const { - // TODO: this code looks weird. need further investigation! - - using std::vector; - using std::string; - const vector<string> account_order(loadAccountOrder()); - - // The IP2IP profile should always be available, and first in the list; - // however, it is possible that it was deleted by removeAccounts() - - vector<string> v; + auto account_order = loadAccountOrder(); // Concatenate all account pointers in a single map const auto& allAccounts = accountFactory_.getAllAccounts(); + std::vector<std::string> v; + v.reserve(allAccounts.size()); // If no order has been set, load the default one ie according to the creation date. if (account_order.empty()) { - for (const auto &account : allAccounts) { - if (account->isIP2IP()) - continue; - v.push_back(account->getAccountID()); - } + for (const auto &account : allAccounts) + v.emplace_back(account->getAccountID()); } else { - const auto& ip2ipAccountID = getIP2IPAccount() ? - getIP2IPAccount()->getAccountID() : std::string(); for (const auto& id : account_order) { - if (id.empty() or id == ip2ipAccountID) - continue; - if (accountFactory_.hasAccount(id)) v.push_back(id); } } - if (const auto& account = getIP2IPAccount()) - v.push_back(account->getAccountID()); - else - RING_ERR("could not find IP2IP profile in getAccount list"); - return v; } @@ -2550,18 +2521,10 @@ Manager::loadAccount(const YAML::Node &node, int &errorCount, }; if (!accountid.empty() and !accountAlias.empty()) { - const auto& ip2ipAccountID = getIP2IPAccount() ? - getIP2IPAccount()->getAccountID() : std::string(); - - if (not inAccountOrder(accountid) and accountid != ip2ipAccountID) { + if (not inAccountOrder(accountid)) { RING_WARN("Dropping account %s, which is not in account order", accountid.c_str()); } else if (accountFactory_.isSupportedType(accountType.c_str())) { - std::shared_ptr<Account> a; - if (accountid != ip2ipAccountID) - a = accountFactory_.createAccount(accountType.c_str(), accountid); - else - a = accountFactory_.getIP2IPAccount(); - if (a) { + if (auto a = accountFactory_.createAccount(accountType.c_str(), accountid)) { a->unserialize(node); } else { RING_ERR("Failed to create account type \"%s\"", accountType.c_str()); @@ -2576,8 +2539,6 @@ Manager::loadAccount(const YAML::Node &node, int &errorCount, int Manager::loadAccountMap(const YAML::Node &node) { - accountFactory_.initIP2IPAccount(); - // build preferences preferences.unserialize(node); voipPreferences.unserialize(node); @@ -2783,7 +2744,7 @@ std::shared_ptr<Call> Manager::newOutgoingCall(const std::string& toUrl, const std::string& preferredAccountId) { - auto account = Manager::instance().getIP2IPAccount(); + std::shared_ptr<Account> account {}; auto preferred = getAccount(preferredAccountId); std::string finalToUrl = toUrl; diff --git a/src/manager.h b/src/manager.h index 2f0b9b0a76..1e2e8014aa 100644 --- a/src/manager.h +++ b/src/manager.h @@ -904,10 +904,6 @@ class Manager { return accountFactory_.accountCount<T>(); } - std::shared_ptr<Account> getIP2IPAccount() const { - return accountFactory_.getIP2IPAccount(); - } - // only used by test framework bool hasAccount(const std::string& accountID) { return accountFactory_.hasAccount(accountID); @@ -1000,8 +996,6 @@ class Manager { std::mt19937_64 rand_; - void loadDefaultAccountMap(); - void loadAccount(const YAML::Node &item, int &errorCount, const std::string &accountOrder); diff --git a/src/sip/pres_sub_server.cpp b/src/sip/pres_sub_server.cpp index 48d3ba2eaf..43d85dacb9 100644 --- a/src/sip/pres_sub_server.cpp +++ b/src/sip/pres_sub_server.cpp @@ -29,6 +29,7 @@ #include "pres_sub_server.h" #include "client/ring_signal.h" #include "sip_utils.h" +#include "intrin.h" namespace ring { @@ -36,8 +37,12 @@ using sip_utils::CONST_PJ_STR; /* Callback called when *server* subscription state has changed. */ void -PresSubServer::pres_evsub_on_srv_state(pjsip_evsub *sub, pjsip_event *event) +PresSubServer::pres_evsub_on_srv_state(UNUSED pjsip_evsub *sub, UNUSED pjsip_event *event) { + RING_ERR("PresSubServer::pres_evsub_on_srv_state() is deprecated and does nothing"); + return; + +#if 0 // DISABLED: removed IP2IP support, tuleap: #448 pjsip_rx_data *rdata = event->body.rx_msg.rdata; if (!rdata) { @@ -47,7 +52,6 @@ PresSubServer::pres_evsub_on_srv_state(pjsip_evsub *sub, pjsip_event *event) auto account = Manager::instance().getIP2IPAccount(); auto sipaccount = static_cast<SIPAccount *>(account.get()); - if (!sipaccount) { RING_ERR("Could not find account IP2IP"); return; @@ -79,6 +83,7 @@ PresSubServer::pres_evsub_on_srv_state(pjsip_evsub *sub, pjsip_event *event) } pres->unlock(); +#endif } pj_bool_t @@ -89,6 +94,7 @@ PresSubServer::pres_on_rx_subscribe_request(pjsip_rx_data *rdata) pj_str_t *str = &method->name; std::string request(str->ptr, str->slen); // pj_str_t contact; +#if 0 // DISABLED: removed IP2IP support, tuleap: #448 pj_status_t status; pjsip_dialog *dlg; pjsip_evsub *sub; @@ -98,13 +104,17 @@ PresSubServer::pres_on_rx_subscribe_request(pjsip_rx_data *rdata) pj_str_t reason; pres_msg_data msg_data; pjsip_evsub_state ev_state; - +#endif /* Only hande incoming subscribe messages should be processed here. * Otherwise we return FALSE to let other modules handle it */ if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, pjsip_get_subscribe_method()) != 0) return PJ_FALSE; + RING_ERR("PresSubServer::pres_evsub_on_srv_state() is deprecated and does nothing"); + return PJ_FALSE; + +#if 0 // DISABLED: removed IP2IP support, tuleap: #448 /* debug msg */ std::string name(rdata->msg_info.to->name.ptr, rdata->msg_info.to->name.slen); std::string server(rdata->msg_info.from->name.ptr, rdata->msg_info.from->name.slen); @@ -255,6 +265,7 @@ PresSubServer::pres_on_rx_subscribe_request(pjsip_rx_data *rdata) pres->unlock(); return PJ_TRUE; +#endif } pjsip_module PresSubServer::mod_presence_server = { diff --git a/src/sip/sipaccount.cpp b/src/sip/sipaccount.cpp index 2dd9485909..cd9009a7ee 100644 --- a/src/sip/sipaccount.cpp +++ b/src/sip/sipaccount.cpp @@ -148,9 +148,6 @@ SIPAccount::SIPAccount(const std::string& accountID, bool presenceEnabled) via_addr_.host.ptr = 0; via_addr_.host.slen = 0; via_addr_.port = 0; - - if (isIP2IP()) - alias_ = IP2IP_PROFILE; } SIPAccount::~SIPAccount() @@ -757,7 +754,7 @@ void SIPAccount::doRegister() void SIPAccount::doRegister1_() { - if (hostname_.empty() || isIP2IP()) { + if (isIP2IP()) { doRegister2_(); return; } @@ -1671,26 +1668,6 @@ std::string SIPAccount::getUserAgentName() const return userAgent_; } -std::map<std::string, std::string> SIPAccount::getIp2IpDetails() const -{ - assert(isIP2IP()); - std::map<std::string, std::string> ip2ipAccountDetails; - ip2ipAccountDetails[Conf::CONFIG_SRTP_KEY_EXCHANGE] = sip_utils::getKeyExchangeName(srtpKeyExchange_); - ip2ipAccountDetails[Conf::CONFIG_SRTP_ENABLE] = isSrtpEnabled() ? TRUE_STR : FALSE_STR; - ip2ipAccountDetails[Conf::CONFIG_SRTP_RTP_FALLBACK] = srtpFallback_ ? TRUE_STR : FALSE_STR; - ip2ipAccountDetails[Conf::CONFIG_ZRTP_DISPLAY_SAS] = zrtpDisplaySas_ ? TRUE_STR : FALSE_STR; - ip2ipAccountDetails[Conf::CONFIG_ZRTP_HELLO_HASH] = zrtpHelloHash_ ? TRUE_STR : FALSE_STR; - ip2ipAccountDetails[Conf::CONFIG_ZRTP_NOT_SUPP_WARNING] = zrtpNotSuppWarning_ ? TRUE_STR : FALSE_STR; - ip2ipAccountDetails[Conf::CONFIG_ZRTP_DISPLAY_SAS_ONCE] = zrtpDisplaySasOnce_ ? TRUE_STR : FALSE_STR; - ip2ipAccountDetails[Conf::CONFIG_LOCAL_PORT] = ring::to_string(localPort_); - - auto tlsSettings(getTlsSettings()); - std::copy(tlsSettings.begin(), tlsSettings.end(), - std::inserter(ip2ipAccountDetails, ip2ipAccountDetails.end())); - - return ip2ipAccountDetails; -} - std::map<std::string, std::string> SIPAccount::getTlsSettings() const { @@ -1713,7 +1690,7 @@ SIPAccount::getTlsSettings() const bool SIPAccount::isIP2IP() const { - return accountID_ == IP2IP_PROFILE; + return hostname_.empty(); } SIPPresence * SIPAccount::getPresence() const diff --git a/src/sip/sipaccount.h b/src/sip/sipaccount.h index ff38140cb5..837b928bb0 100644 --- a/src/sip/sipaccount.h +++ b/src/sip/sipaccount.h @@ -75,7 +75,6 @@ class SIPCall; */ class SIPAccount : public SIPAccountBase { public: - constexpr static const char * const IP2IP_PROFILE = "IP2IP"; constexpr static const char * const ACCOUNT_TYPE = "SIP"; /** @@ -132,11 +131,6 @@ class SIPAccount : public SIPAccountBase { */ virtual std::map<std::string, std::string> getVolatileAccountDetails() const override; - /** - * Return the information for the default IP to IP account - */ - std::map<std::string, std::string> getIp2IpDetails() const; - /** * Return the TLS settings, mainly used to return security information to * a client application diff --git a/src/sip/sipvoiplink.cpp b/src/sip/sipvoiplink.cpp index 17f513cad9..eba045e38a 100644 --- a/src/sip/sipvoiplink.cpp +++ b/src/sip/sipvoiplink.cpp @@ -633,7 +633,7 @@ SIPVoIPLink::guessAccount(const std::string& userName, RING_DBG("username = %s, server = %s, from = %s", userName.c_str(), server.c_str(), fromUri.c_str()); // Try to find the account id from username and server name by full match - auto result = std::static_pointer_cast<SIPAccountBase>(Manager::instance().getIP2IPAccount()); // default result + std::shared_ptr<SIPAccountBase> result {}; MatchRank best = MatchRank::NONE; #if HAVE_DHT -- GitLab