From 27d9dfac0cf5389a2b6f2bc8b15b606096c1e4db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Wed, 11 Mar 2015 14:28:15 -0400
Subject: [PATCH] sip: move account transport to SIPAccount (2)

Refs #68179

Change-Id: Ica10e74d7c70fd4d8ff5a7a5089271f3decb9214
Signed-off-by: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
---
 daemon/src/client/configurationmanager.cpp |  2 +-
 daemon/src/preferences.cpp                 |  2 +-
 daemon/src/ringdht/ringaccount.cpp         | 10 +--
 daemon/src/ringdht/ringaccount.h           | 15 +---
 daemon/src/sip/sip_utils.h                 | 45 ++++++-----
 daemon/src/sip/sipaccount.cpp              | 30 ++++---
 daemon/src/sip/sipaccount.h                | 49 ++++++++++-
 daemon/src/sip/sipaccountbase.cpp          | 31 +++----
 daemon/src/sip/sipaccountbase.h            | 94 ++++------------------
 daemon/src/sip/siptransport.h              |  8 +-
 daemon/src/sip/sipvoiplink.cpp             |  9 ++-
 11 files changed, 135 insertions(+), 160 deletions(-)

diff --git a/daemon/src/client/configurationmanager.cpp b/daemon/src/client/configurationmanager.cpp
index 3a1c46a82a..792b9c96fc 100644
--- a/daemon/src/client/configurationmanager.cpp
+++ b/daemon/src/client/configurationmanager.cpp
@@ -108,7 +108,7 @@ std::map<std::string, std::string>
 getTlsDefaultSettings()
 {
     std::stringstream portstr;
-    portstr << DEFAULT_SIP_TLS_PORT;
+    portstr << ring::sip_utils::DEFAULT_SIP_TLS_PORT;
 
     return {
         {ring::Conf::CONFIG_TLS_LISTENER_PORT, portstr.str()},
diff --git a/daemon/src/preferences.cpp b/daemon/src/preferences.cpp
index 504c34fbc3..ef906a2a4c 100644
--- a/daemon/src/preferences.cpp
+++ b/daemon/src/preferences.cpp
@@ -134,7 +134,7 @@ Preferences::Preferences() :
     , historyMaxCalls_(20)
     , zoneToneChoice_(DFT_ZONE) // DFT_ZONE
     , registrationExpire_(180)
-    , portNum_(5060)
+    , portNum_(sip_utils::DEFAULT_SIP_PORT)
     , searchBarDisplay_(true)
     , md5Hash_(false)
 {}
diff --git a/daemon/src/ringdht/ringaccount.cpp b/daemon/src/ringdht/ringaccount.cpp
index 192a83da1a..446ca27b9d 100644
--- a/daemon/src/ringdht/ringaccount.cpp
+++ b/daemon/src/ringdht/ringaccount.cpp
@@ -1066,7 +1066,6 @@ void RingAccount::loadConfig()
 {
     RING_WARN("RingAccount::loadConfig()");
     initTlsConfiguration();
-    transportType_ = PJSIP_TRANSPORT_TLS;
 }
 
 MatchRank
@@ -1089,9 +1088,7 @@ std::string RingAccount::getFromUri() const
 
 std::string RingAccount::getToUri(const std::string& to) const
 {
-    const std::string transport {pjsip_transport_get_type_name(transportType_)};
-    //return "<sip:" + to + ">";
-    return "<sips:" + to + ";transport=" + transport + ">";
+    return "<sips:" + to + ";transport=tls>";
 }
 
 pj_str_t
@@ -1109,11 +1106,10 @@ RingAccount::getContactHeader(pjsip_transport* t)
     auto tlsTr = reinterpret_cast<tls::SipsIceTransport::TransportData*>(t)->self;
     auto address = tlsTr->getLocalAddress();
     contact_.slen = pj_ansi_snprintf(contact_.ptr, PJSIP_MAX_URL_SIZE,
-                                     "<sips:%s%s%s;transport=%s>",
+                                     "<sips:%s%s%s;transport=tls>",
                                      username_.c_str(),
                                      (username_.empty() ? "" : "@"),
-                                     address.toString(true).c_str(),
-                                     pjsip_transport_get_type_name(transportType_));
+                                     address.toString(true).c_str());
     return contact_;
 }
 
diff --git a/daemon/src/ringdht/ringaccount.h b/daemon/src/ringdht/ringaccount.h
index 123c76111d..ef5253a234 100644
--- a/daemon/src/ringdht/ringaccount.h
+++ b/daemon/src/ringdht/ringaccount.h
@@ -37,6 +37,7 @@
 #endif
 
 #include "sip/sipaccountbase.h"
+
 #include "noncopyable.h"
 #include "ip_utils.h"
 #include "ring_types.h" // enable_if_base_of
@@ -71,6 +72,8 @@ namespace tls {
 class GnuTlsGlobalInit;
 } // namespace tls
 
+class IceTransport;
+
 class RingAccount : public SIPAccountBase {
     public:
         constexpr static const char * const ACCOUNT_TYPE = "RING";
@@ -175,18 +178,6 @@ class RingAccount : public SIPAccountBase {
             return &via_addr_;
         }
 
-        int getRPort() const {
-            if (rPort_ == -1)
-                return localPort_;
-            else
-                return rPort_;
-        }
-
-        void setRPort(int rPort) {
-            rPort_ = rPort;
-            via_addr_.port = rPort;
-        }
-
         /* Returns true if the username and/or hostname match this account */
         MatchRank matches(const std::string &username, const std::string &hostname) const;
 
diff --git a/daemon/src/sip/sip_utils.h b/daemon/src/sip/sip_utils.h
index d100d05573..2e70cf5aa2 100644
--- a/daemon/src/sip/sip_utils.h
+++ b/daemon/src/sip/sip_utils.h
@@ -45,36 +45,39 @@
 
 struct pjsip_msg;
 
-namespace ring {namespace sip_utils {
+namespace ring { namespace sip_utils {
 
-    enum class KeyExchangeProtocol { NONE, SDES, ZRTP };
+static constexpr int DEFAULT_SIP_PORT {5060};
+static constexpr int DEFAULT_SIP_TLS_PORT {5061};
 
-    constexpr const char* getKeyExchangeName(KeyExchangeProtocol kx) {
-        return kx == KeyExchangeProtocol::SDES ? "sdes" : (
-               kx == KeyExchangeProtocol::ZRTP ? "zrtp" : "");
-    }
-    constexpr KeyExchangeProtocol getKeyExchangeProtocol(const char* name) {
-        return !strcmp("sdes", name) ? KeyExchangeProtocol::SDES : KeyExchangeProtocol::NONE;
-    }
+enum class KeyExchangeProtocol { NONE, SDES, ZRTP };
 
-    /**
-     * Helper function to parser header from incoming sip messages
-     * @return Header from SIP message
-     */
-    std::string fetchHeaderValue(pjsip_msg *msg, const std::string &field);
+constexpr const char* getKeyExchangeName(KeyExchangeProtocol kx) {
+    return kx == KeyExchangeProtocol::SDES ? "sdes" : (
+        kx == KeyExchangeProtocol::ZRTP ? "zrtp" : "");
+}
+constexpr KeyExchangeProtocol getKeyExchangeProtocol(const char* name) {
+    return !strcmp("sdes", name) ? KeyExchangeProtocol::SDES : KeyExchangeProtocol::NONE;
+}
 
-    pjsip_route_hdr *
-    createRouteSet(const std::string &route, pj_pool_t *hdr_pool);
+/**
+ * Helper function to parser header from incoming sip messages
+ * @return Header from SIP message
+ */
+std::string fetchHeaderValue(pjsip_msg *msg, const std::string &field);
+
+pjsip_route_hdr *
+createRouteSet(const std::string &route, pj_pool_t *hdr_pool);
 
-    void stripSipUriPrefix(std::string& sipUri);
+void stripSipUriPrefix(std::string& sipUri);
 
-    std::string parseDisplayName(const char * buffer);
+std::string parseDisplayName(const char * buffer);
 
-    std::string getHostFromUri(const std::string& sipUri);
+std::string getHostFromUri(const std::string& sipUri);
 
-    void addContactHeader(const pj_str_t *contactStr, pjsip_tx_data *tdata);
+void addContactHeader(const pj_str_t *contactStr, pjsip_tx_data *tdata);
 
-    void sip_strerror(pj_status_t code);
+void sip_strerror(pj_status_t code);
 
 }} // namespace ring::sip_utils
 
diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp
index c6653e3d52..3c13cd1ffa 100644
--- a/daemon/src/sip/sipaccount.cpp
+++ b/daemon/src/sip/sipaccount.cpp
@@ -63,6 +63,10 @@
 
 #include "system_codec_container.h"
 
+#include "upnp/upnp_control.h"
+#include "ip_utils.h"
+#include "string_utils.h"
+
 #include <unistd.h>
 #include <pwd.h>
 
@@ -72,9 +76,6 @@
 #include <sstream>
 #include <cstdlib>
 
-#include "upnp/upnp_control.h"
-#include "ip_utils.h"
-
 namespace ring {
 
 using yaml_utils::parseValue;
@@ -430,6 +431,8 @@ void SIPAccount::serialize(YAML::Emitter &out)
     out << YAML::BeginMap;
     SIPAccountBase::serialize(out);
 
+    out << YAML::Key << Conf::PORT_KEY << YAML::Value << localPort_;
+
     // each credential is a map, and we can have multiple credentials
     out << YAML::Key << Conf::CRED_KEY << YAML::Value << credentials_;
     out << YAML::Key << Conf::KEEP_ALIVE_ENABLED << YAML::Value << keepAliveEnabled_;
@@ -448,6 +451,7 @@ void SIPAccount::serialize(YAML::Emitter &out)
     out << YAML::Key << Conf::TLS_KEY << YAML::Value << YAML::BeginMap;
     SIPAccountBase::serializeTls(out);
     out << YAML::Key << Conf::TLS_ENABLE_KEY << YAML::Value << tlsEnable_;
+    out << YAML::Key << Conf::TLS_PORT_KEY << YAML::Value << tlsListenerPort_;
     out << YAML::Key << Conf::VERIFY_CLIENT_KEY << YAML::Value << tlsVerifyClient_;
     out << YAML::Key << Conf::VERIFY_SERVER_KEY << YAML::Value << tlsVerifyServer_;
     out << YAML::Key << Conf::REQUIRE_CERTIF_KEY << YAML::Value << tlsRequireClientCertificate_;
@@ -506,6 +510,10 @@ void SIPAccount::unserialize(const YAML::Node &node)
     if (not publishedSameasLocal_)
         usePublishedAddressPortInVIA();
 
+    int port = sip_utils::DEFAULT_SIP_PORT;
+    parseValue(node, Conf::PORT_KEY, port);
+    localPort_ = port;
+
     if (not isIP2IP()) parseValue(node, Preferences::REGISTRATION_EXPIRE_KEY, registrationExpire_);
 
     if (not isIP2IP()) parseValue(node, Conf::KEEP_ALIVE_ENABLED, keepAliveEnabled_);
@@ -548,6 +556,7 @@ void SIPAccount::unserialize(const YAML::Node &node)
     const auto &tlsMap = node[Conf::TLS_KEY];
 
     parseValue(tlsMap, Conf::TLS_ENABLE_KEY, tlsEnable_);
+    parseValue(tlsMap, Conf::TLS_PORT_KEY, tlsListenerPort_);
     parseValue(tlsMap, Conf::CIPHERS_KEY, tlsCiphers_);
 
     std::string tmpMethod(tlsMethod_);
@@ -585,6 +594,8 @@ void SIPAccount::setAccountDetails(const std::map<std::string, std::string> &det
 {
     SIPAccountBase::setAccountDetails(details);
 
+    parseInt(details, Conf::CONFIG_LOCAL_PORT, localPort_);
+
     // SIP specific account settings
     parseString(details, Conf::CONFIG_ACCOUNT_ROUTESET, serviceRoute_);
 
@@ -611,6 +622,7 @@ void SIPAccount::setAccountDetails(const std::map<std::string, std::string> &det
 
     // TLS settings
     parseBool(details, Conf::CONFIG_TLS_ENABLE, tlsEnable_);
+    parseInt(details, Conf::CONFIG_TLS_LISTENER_PORT, tlsListenerPort_);
     auto iter = details.find(Conf::CONFIG_TLS_METHOD);
     if (iter != details.end())
         validate(tlsMethod_, iter->second, VALID_TLS_METHODS);
@@ -690,6 +702,8 @@ std::map<std::string, std::string> SIPAccount::getAccountDetails() const
     a[Conf::CONFIG_ACCOUNT_REGISTRATION_STATE_CODE] = registrationStateCode;
     a[Conf::CONFIG_ACCOUNT_REGISTRATION_STATE_DESC] = registrationStateDescription;
 
+    a[Conf::CONFIG_LOCAL_PORT] = ring::to_string(localPort_);
+
     a[Conf::CONFIG_PRESENCE_ENABLED] = presence_ and presence_->isEnabled()? TRUE_STR : FALSE_STR;
     a[Conf::CONFIG_PRESENCE_PUBLISH_SUPPORTED] = presence_ and presence_->isSupported(PRESENCE_FUNCTION_PUBLISH)? TRUE_STR : FALSE_STR;
     a[Conf::CONFIG_PRESENCE_SUBSCRIBE_SUPPORTED] = presence_ and presence_->isSupported(PRESENCE_FUNCTION_SUBSCRIBE)? TRUE_STR : FALSE_STR;
@@ -710,6 +724,7 @@ std::map<std::string, std::string> SIPAccount::getAccountDetails() const
 
     // TLS listener is unique and parameters are modified through IP2IP_PROFILE
     a[Conf::CONFIG_TLS_ENABLE] = tlsEnable_ ? TRUE_STR : FALSE_STR;
+    a[Conf::CONFIG_TLS_LISTENER_PORT] = ring::to_string(tlsListenerPort_);
     a[Conf::CONFIG_TLS_METHOD] = tlsMethod_;
     a[Conf::CONFIG_TLS_CIPHERS] = tlsCiphers_;
     a[Conf::CONFIG_TLS_SERVER_NAME] = tlsServerName_;
@@ -1737,10 +1752,7 @@ std::map<std::string, std::string> SIPAccount::getIp2IpDetails() const
     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_INTERFACE] = interface_;
-    std::stringstream portstr;
-    portstr << localPort_;
-    ip2ipAccountDetails[Conf::CONFIG_LOCAL_PORT] = portstr.str();
+    ip2ipAccountDetails[Conf::CONFIG_LOCAL_PORT] = ring::to_string(localPort_);
 
     std::map<std::string, std::string> tlsSettings(getTlsSettings());
     std::copy(tlsSettings.begin(), tlsSettings.end(), std::inserter(
@@ -1754,9 +1766,7 @@ std::map<std::string, std::string> SIPAccount::getTlsSettings() const
     assert(isIP2IP());
     std::map<std::string, std::string> tlsSettings;
 
-    std::stringstream portstr;
-    portstr << tlsListenerPort_;
-    tlsSettings[Conf::CONFIG_TLS_LISTENER_PORT] = portstr.str();
+    tlsSettings[Conf::CONFIG_TLS_LISTENER_PORT] = ring::to_string(tlsListenerPort_);
     tlsSettings[Conf::CONFIG_TLS_ENABLE] = tlsEnable_ ? TRUE_STR : FALSE_STR;
     tlsSettings[Conf::CONFIG_TLS_CA_LIST_FILE] = tlsCaListFile_;
     tlsSettings[Conf::CONFIG_TLS_CERTIFICATE_FILE] = tlsCertificateFile_;
diff --git a/daemon/src/sip/sipaccount.h b/daemon/src/sip/sipaccount.h
index c892896023..b88f644148 100644
--- a/daemon/src/sip/sipaccount.h
+++ b/daemon/src/sip/sipaccount.h
@@ -290,6 +290,23 @@ class SIPAccount : public SIPAccountBase {
 
         void destroyRegistrationInfo();
 
+        /**
+         * Get the port on which the transport/listener should use, or is
+         * actually using.
+         * @return pj_uint16 The port used for that account
+         */
+        pj_uint16_t getLocalPort() const {
+            return localPort_;
+        }
+
+        /**
+         * Set the new port on which this account is running over.
+         * @pram port The port used by this account.
+         */
+        void setLocalPort(pj_uint16_t port) {
+            localPort_ = port;
+        }
+
         /**
          * @return pjsip_tls_setting structure, filled from the configuration
          * file, that can be used directly by PJSIP to initialize
@@ -299,6 +316,14 @@ class SIPAccount : public SIPAccountBase {
             return &tlsSetting_;
         }
 
+        /**
+         * Get the local port for TLS listener.
+         * @return pj_uint16 The port used for that account
+         */
+        pj_uint16_t getTlsListenerPort() const {
+            return tlsListenerPort_;
+        }
+
         /**
          * @return pj_str_t , filled from the configuration
          * file, that can be used directly by PJSIP to initialize
@@ -553,6 +578,18 @@ class SIPAccount : public SIPAccountBase {
          */
         std::vector< std::map<std::string, std::string > > credentials_;
 
+        std::shared_ptr<SipTransport> transport_ {};
+
+        std::shared_ptr<TlsListener> tlsListener_ {};
+
+        /**
+         * Transport type used for this sip account. Currently supported types:
+         *    PJSIP_TRANSPORT_UNSPECIFIED
+         *    PJSIP_TRANSPORT_UDP
+         *    PJSIP_TRANSPORT_TLS
+         */
+        pjsip_transport_type_e transportType_ {PJSIP_TRANSPORT_UNSPECIFIED};
+
 #if HAVE_TLS
 
         static const CipherArray TLSv1_DEFAULT_CIPHER_LIST;
@@ -661,6 +698,16 @@ class SIPAccount : public SIPAccountBase {
          */
         pj_uint16_t stunPort_ {PJ_STUN_PORT};
 
+        /**
+         * Local port to whih this account is bound
+         */
+        pj_uint16_t localPort_ {sip_utils::DEFAULT_SIP_PORT};
+
+        /**
+         * The TLS listener port
+         */
+        pj_uint16_t tlsListenerPort_ {sip_utils::DEFAULT_SIP_TLS_PORT};
+
         bool tlsEnable_ {false};
         std::string tlsMethod_;
         std::string tlsCiphers_;
@@ -757,7 +804,7 @@ class SIPAccount : public SIPAccountBase {
          * selected in the configuration in the case that UPnP is used and the
          * configured port is already used by another client
          */
-        pj_uint16_t publishedPortUsed_ {DEFAULT_SIP_PORT};
+        pj_uint16_t publishedPortUsed_ {sip_utils::DEFAULT_SIP_PORT};
 };
 
 } // namespace ring
diff --git a/daemon/src/sip/sipaccountbase.cpp b/daemon/src/sip/sipaccountbase.cpp
index ae0d93548d..49ebc637a4 100644
--- a/daemon/src/sip/sipaccountbase.cpp
+++ b/daemon/src/sip/sipaccountbase.cpp
@@ -44,6 +44,7 @@
 #include <yaml-cpp/yaml.h>
 
 #include "client/signal.h"
+#include "string_utils.h"
 
 #include <type_traits>
 
@@ -86,6 +87,15 @@ unserializeRange(const YAML::Node &node, const char *minKey, const char *maxKey,
     updateRange(tmpMin, tmpMax, range);
 }
 
+static void
+addRangeToDetails(std::map<std::string, std::string> &a, const char *minKey,
+                  const char *maxKey,
+                  const std::pair<uint16_t, uint16_t> &range)
+{
+    a.emplace(minKey, ring::to_string(range.first));
+    a.emplace(maxKey, ring::to_string(range.second));
+}
+
 template <typename T>
 static void
 parseInt(const std::map<std::string, std::string> &details, const char *key, T &i)
@@ -106,7 +116,6 @@ void SIPAccountBase::serialize(YAML::Emitter &out)
     out << YAML::Key << Conf::AUDIO_PORT_MIN_KEY << YAML::Value << audioPortRange_.first;
     out << YAML::Key << Conf::DTMF_TYPE_KEY << YAML::Value << dtmfType_;
     out << YAML::Key << Conf::INTERFACE_KEY << YAML::Value << interface_;
-    out << YAML::Key << Conf::PORT_KEY << YAML::Value << localPort_;
     out << YAML::Key << Conf::PUBLISH_ADDR_KEY << YAML::Value << publishedIpAddress_;
     out << YAML::Key << Conf::PUBLISH_PORT_KEY << YAML::Value << publishedPort_;
     out << YAML::Key << Conf::SAME_AS_LOCAL_KEY << YAML::Value << publishedSameasLocal_;
@@ -118,7 +127,6 @@ void SIPAccountBase::serialize(YAML::Emitter &out)
 
 void SIPAccountBase::serializeTls(YAML::Emitter &out)
 {
-    out << YAML::Key << Conf::TLS_PORT_KEY << YAML::Value << tlsListenerPort_;
     out << YAML::Key << Conf::CALIST_KEY << YAML::Value << tlsCaListFile_;
     out << YAML::Key << Conf::CERTIFICATE_KEY << YAML::Value << tlsCertificateFile_;
     out << YAML::Key << Conf::TLS_PASSWORD_KEY << YAML::Value << tlsPassword_;
@@ -135,10 +143,6 @@ void SIPAccountBase::unserialize(const YAML::Node &node)
     parseValue(node, VIDEO_ENABLED_KEY, videoEnabled_);
 
     parseValue(node, Conf::INTERFACE_KEY, interface_);
-    int port = DEFAULT_SIP_PORT;
-    parseValue(node, Conf::PORT_KEY, port);
-    localPort_ = port;
-
     parseValue(node, Conf::SAME_AS_LOCAL_KEY, publishedSameasLocal_);
     std::string publishedIpAddress;
     parseValue(node, Conf::PUBLISH_ADDR_KEY, publishedIpAddress);
@@ -146,6 +150,7 @@ void SIPAccountBase::unserialize(const YAML::Node &node)
     if (publishedIp and not publishedSameasLocal_)
         setPublishedAddress(publishedIp);
 
+    int port = sip_utils::DEFAULT_SIP_PORT;
     parseValue(node, Conf::PUBLISH_PORT_KEY, port);
     publishedPort_ = port;
 
@@ -153,7 +158,6 @@ void SIPAccountBase::unserialize(const YAML::Node &node)
 
     // get tls submap
     const auto &tlsMap = node[Conf::TLS_KEY];
-    parseValue(tlsMap, Conf::TLS_PORT_KEY, tlsListenerPort_);
     parseValue(tlsMap, Conf::CERTIFICATE_KEY, tlsCertificateFile_);
     parseValue(tlsMap, Conf::CALIST_KEY, tlsCaListFile_);
     parseValue(tlsMap, Conf::TLS_PASSWORD_KEY, tlsPassword_);
@@ -174,7 +178,6 @@ void SIPAccountBase::setAccountDetails(const std::map<std::string, std::string>
     parseString(details, Conf::CONFIG_LOCAL_INTERFACE, interface_);
     parseBool(details, Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal_);
     parseString(details, Conf::CONFIG_PUBLISHED_ADDRESS, publishedIpAddress_);
-    parseInt(details, Conf::CONFIG_LOCAL_PORT, localPort_);
     parseInt(details, Conf::CONFIG_PUBLISHED_PORT, publishedPort_);
 
     parseString(details, Conf::CONFIG_ACCOUNT_DTMF_TYPE, dtmfType_);
@@ -193,7 +196,6 @@ void SIPAccountBase::setAccountDetails(const std::map<std::string, std::string>
 #endif
 
     // TLS
-    parseInt(details, Conf::CONFIG_TLS_LISTENER_PORT, tlsListenerPort_);
     parseString(details, Conf::CONFIG_TLS_CA_LIST_FILE, tlsCaListFile_);
     parseString(details, Conf::CONFIG_TLS_CERTIFICATE_FILE, tlsCertificateFile_);
     parseString(details, Conf::CONFIG_TLS_PRIVATE_KEY_FILE, tlsPrivateKeyFile_);
@@ -218,19 +220,10 @@ SIPAccountBase::getAccountDetails() const
 
     a[Conf::CONFIG_ACCOUNT_DTMF_TYPE] = dtmfType_;
     a[Conf::CONFIG_LOCAL_INTERFACE] = interface_;
+    a[Conf::CONFIG_PUBLISHED_PORT] = ring::to_string(publishedPort_);
     a[Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL] = publishedSameasLocal_ ? TRUE_STR : FALSE_STR;
     a[Conf::CONFIG_PUBLISHED_ADDRESS] = publishedIpAddress_;
 
-    std::stringstream localport;
-    localport << localPort_;
-    a[Conf::CONFIG_LOCAL_PORT] = localport.str();
-    std::stringstream publishedport;
-    publishedport << publishedPort_;
-    a[Conf::CONFIG_PUBLISHED_PORT] = publishedport.str();
-
-    std::stringstream tlslistenerport;
-    tlslistenerport << tlsListenerPort_;
-    a[Conf::CONFIG_TLS_LISTENER_PORT] = tlslistenerport.str();
     a[Conf::CONFIG_TLS_CA_LIST_FILE] = tlsCaListFile_;
     a[Conf::CONFIG_TLS_CERTIFICATE_FILE] = tlsCertificateFile_;
     a[Conf::CONFIG_TLS_PRIVATE_KEY_FILE] = tlsPrivateKeyFile_;
diff --git a/daemon/src/sip/sipaccountbase.h b/daemon/src/sip/sipaccountbase.h
index 752cb80271..6f6976d59e 100644
--- a/daemon/src/sip/sipaccountbase.h
+++ b/daemon/src/sip/sipaccountbase.h
@@ -36,7 +36,6 @@
 #include "config.h"
 #endif
 
-#include "siptransport.h"
 #include "sip_utils.h"
 
 #include "account.h"
@@ -48,7 +47,6 @@
 #include <array>
 #include <vector>
 #include <map>
-#include <sstream>
 #include <memory>
 
 namespace ring {
@@ -150,16 +148,11 @@ public:
         return false;
     }
 
-    virtual pjsip_tls_setting * getTlsSetting() {
-        return nullptr;
-    }
-
     /**
-     * Get the local port for TLS listener.
-     * @return pj_uint16 The port used for that account
+     * Get the local interface name on which this account is bound.
      */
-    pj_uint16_t getTlsListenerPort() const {
-        return tlsListenerPort_;
+    const std::string& getLocalInterface() const {
+        return interface_;
     }
 
     /**
@@ -181,39 +174,6 @@ public:
         publishedIpAddress_ = ip_addr.toString();
     }
 
-    /**
-     * Get the local interface name on which this account is bound.
-     */
-    const std::string& getLocalInterface() const {
-        return interface_;
-    }
-
-    /**
-     * Get a flag which determine the usage in sip headers of either the local
-     * IP address and port (_localAddress and localPort_) or to an address set
-     * manually (_publishedAddress and publishedPort_).
-     */
-    bool getPublishedSameasLocal() const {
-        return publishedSameasLocal_;
-    }
-
-    /**
-     * Get the port on which the transport/listener should use, or is
-     * actually using.
-     * @return pj_uint16 The port used for that account
-     */
-    pj_uint16_t getLocalPort() const {
-        return localPort_;
-    }
-
-    /**
-     * Set the new port on which this account is running over.
-     * @pram port The port used by this account.
-     */
-    void setLocalPort(pj_uint16_t port) {
-        localPort_ = port;
-    }
-
     /**
      * Get the published port, which is the port to be advertised as the port
      * for the chosen SIP transport.
@@ -232,6 +192,15 @@ public:
         publishedPort_ = port;
     }
 
+    /**
+     * Get a flag which determine the usage in sip headers of either the local
+     * IP address and port (_localAddress and localPort_) or to an address set
+     * manually (_publishedAddress and publishedPort_).
+     */
+    bool getPublishedSameasLocal() const {
+        return publishedSameasLocal_;
+    }
+
     virtual sip_utils::KeyExchangeProtocol getSrtpKeyExchange() const = 0;
 
     virtual bool getSrtpFallback() const = 0;
@@ -244,10 +213,6 @@ public:
 
     virtual std::string getToUri(const std::string& username) const = 0;
 
-    virtual inline std::shared_ptr<SipTransport> getTransport() {
-        return nullptr;
-    }
-
     /**
      * Socket port generators for media
      * Note: given ports are application wide, a port cannot be given again
@@ -280,18 +245,6 @@ protected:
      */
     std::shared_ptr<SIPVoIPLink> link_;
 
-    std::shared_ptr<SipTransport> transport_ {};
-
-    std::shared_ptr<TlsListener> tlsListener_ {};
-
-    /**
-     * Transport type used for this sip account. Currently supported types:
-     *    PJSIP_TRANSPORT_UNSPECIFIED
-     *    PJSIP_TRANSPORT_UDP
-     *    PJSIP_TRANSPORT_TLS
-     */
-    pjsip_transport_type_e transportType_ {PJSIP_TRANSPORT_UNSPECIFIED};
-
     /**
      * interface name on which this account is bound
      */
@@ -308,22 +261,14 @@ protected:
      * configuration
      */
     IpAddr publishedIp_ {};
-    std::string publishedIpAddress_ {};
 
-    /**
-     * Local port to whih this account is bound
-     */
-    pj_uint16_t localPort_ {DEFAULT_SIP_PORT};
+    std::string publishedIpAddress_ {};
 
     /**
      * Published port, used only if defined by the user
      */
-    pj_uint16_t publishedPort_ {DEFAULT_SIP_PORT};
+    pj_uint16_t publishedPort_ {sip_utils::DEFAULT_SIP_PORT};
 
-    /**
-     * The TLS listener port
-     */
-    pj_uint16_t tlsListenerPort_ {DEFAULT_SIP_TLS_PORT};
     std::string tlsCaListFile_;
     std::string tlsCertificateFile_;
     std::string tlsPrivateKeyFile_;
@@ -350,17 +295,6 @@ protected:
     static std::array<bool, HALF_MAX_PORT>& getPortsReservation() noexcept;
     uint16_t acquireRandomEvenPort(const std::pair<uint16_t, uint16_t>& range) const;
 
-    static void
-    addRangeToDetails(std::map<std::string, std::string> &a, const char *minKey, const char *maxKey, const std::pair<uint16_t, uint16_t> &range)
-    {
-        std::ostringstream os;
-        os << range.first;
-        a[minKey] = os.str();
-        os.str("");
-        os << range.second;
-        a[maxKey] = os.str();
-    }
-
 private:
     NON_COPYABLE(SIPAccountBase);
 
diff --git a/daemon/src/sip/siptransport.h b/daemon/src/sip/siptransport.h
index e79c6f706d..07e0999489 100644
--- a/daemon/src/sip/siptransport.h
+++ b/daemon/src/sip/siptransport.h
@@ -36,6 +36,9 @@
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
+
+#include "sip_utils.h"
+
 #include "noncopyable.h"
 #include "logger.h"
 
@@ -53,9 +56,6 @@
 #include <list>
 #include <memory>
 
-#define DEFAULT_SIP_PORT    5060
-#define DEFAULT_SIP_TLS_PORT 5061
-
 namespace ring {
 
 struct SipTransportDescr
@@ -85,7 +85,7 @@ struct SipTransportDescr
     std::string toString() const;
 
     pjsip_transport_type_e type {PJSIP_TRANSPORT_UNSPECIFIED};
-    pj_uint16_t listenerPort {DEFAULT_SIP_PORT};
+    pj_uint16_t listenerPort {sip_utils::DEFAULT_SIP_PORT};
     std::string interface {"default"};
 };
 
diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp
index b80c5d3d94..0fd43e6339 100644
--- a/daemon/src/sip/sipvoiplink.cpp
+++ b/daemon/src/sip/sipvoiplink.cpp
@@ -305,12 +305,13 @@ 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) {
-        transport = account->getTransport();
+        if (account->getAccountType() == SIPAccount::ACCOUNT_TYPE) {
+            RING_WARN("Using transport from account.");
+            transport = std::static_pointer_cast<SIPAccount>(account)->getTransport();
+        }
         if (!transport) {
             RING_ERR("No suitable transport to answer this call.");
             return PJ_FALSE;
-        } else {
-            RING_WARN("Using transport from account.");
         }
     }
     call->setTransport(transport);
@@ -1336,7 +1337,7 @@ SIPVoIPLink::findLocalAddressFromSTUN(pjsip_transport* transport,
                                       pj_uint16_t& port) const
 {
     // Initialize the sip port with the default SIP port
-    port = DEFAULT_SIP_PORT;
+    port = sip_utils::DEFAULT_SIP_PORT;
 
     // Initialize the sip address with the hostname
     const pj_str_t* pjMachineName = pj_gethostname();
-- 
GitLab