Commit 27d9dfac authored by Adrien Béraud's avatar Adrien Béraud Committed by Guillaume Roguez

sip: move account transport to SIPAccount (2)

Refs #68179

Change-Id: Ica10e74d7c70fd4d8ff5a7a5089271f3decb9214
Signed-off-by: Guillaume Roguez's avatarGuillaume Roguez <guillaume.roguez@savoirfairelinux.com>
parent 8cdc7c66
...@@ -108,7 +108,7 @@ std::map<std::string, std::string> ...@@ -108,7 +108,7 @@ std::map<std::string, std::string>
getTlsDefaultSettings() getTlsDefaultSettings()
{ {
std::stringstream portstr; std::stringstream portstr;
portstr << DEFAULT_SIP_TLS_PORT; portstr << ring::sip_utils::DEFAULT_SIP_TLS_PORT;
return { return {
{ring::Conf::CONFIG_TLS_LISTENER_PORT, portstr.str()}, {ring::Conf::CONFIG_TLS_LISTENER_PORT, portstr.str()},
......
...@@ -134,7 +134,7 @@ Preferences::Preferences() : ...@@ -134,7 +134,7 @@ Preferences::Preferences() :
, historyMaxCalls_(20) , historyMaxCalls_(20)
, zoneToneChoice_(DFT_ZONE) // DFT_ZONE , zoneToneChoice_(DFT_ZONE) // DFT_ZONE
, registrationExpire_(180) , registrationExpire_(180)
, portNum_(5060) , portNum_(sip_utils::DEFAULT_SIP_PORT)
, searchBarDisplay_(true) , searchBarDisplay_(true)
, md5Hash_(false) , md5Hash_(false)
{} {}
......
...@@ -1066,7 +1066,6 @@ void RingAccount::loadConfig() ...@@ -1066,7 +1066,6 @@ void RingAccount::loadConfig()
{ {
RING_WARN("RingAccount::loadConfig()"); RING_WARN("RingAccount::loadConfig()");
initTlsConfiguration(); initTlsConfiguration();
transportType_ = PJSIP_TRANSPORT_TLS;
} }
MatchRank MatchRank
...@@ -1089,9 +1088,7 @@ std::string RingAccount::getFromUri() const ...@@ -1089,9 +1088,7 @@ std::string RingAccount::getFromUri() const
std::string RingAccount::getToUri(const std::string& to) const std::string RingAccount::getToUri(const std::string& to) const
{ {
const std::string transport {pjsip_transport_get_type_name(transportType_)}; return "<sips:" + to + ";transport=tls>";
//return "<sip:" + to + ">";
return "<sips:" + to + ";transport=" + transport + ">";
} }
pj_str_t pj_str_t
...@@ -1109,11 +1106,10 @@ RingAccount::getContactHeader(pjsip_transport* t) ...@@ -1109,11 +1106,10 @@ RingAccount::getContactHeader(pjsip_transport* t)
auto tlsTr = reinterpret_cast<tls::SipsIceTransport::TransportData*>(t)->self; auto tlsTr = reinterpret_cast<tls::SipsIceTransport::TransportData*>(t)->self;
auto address = tlsTr->getLocalAddress(); auto address = tlsTr->getLocalAddress();
contact_.slen = pj_ansi_snprintf(contact_.ptr, PJSIP_MAX_URL_SIZE, 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_.c_str(),
(username_.empty() ? "" : "@"), (username_.empty() ? "" : "@"),
address.toString(true).c_str(), address.toString(true).c_str());
pjsip_transport_get_type_name(transportType_));
return contact_; return contact_;
} }
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#endif #endif
#include "sip/sipaccountbase.h" #include "sip/sipaccountbase.h"
#include "noncopyable.h" #include "noncopyable.h"
#include "ip_utils.h" #include "ip_utils.h"
#include "ring_types.h" // enable_if_base_of #include "ring_types.h" // enable_if_base_of
...@@ -71,6 +72,8 @@ namespace tls { ...@@ -71,6 +72,8 @@ namespace tls {
class GnuTlsGlobalInit; class GnuTlsGlobalInit;
} // namespace tls } // namespace tls
class IceTransport;
class RingAccount : public SIPAccountBase { class RingAccount : public SIPAccountBase {
public: public:
constexpr static const char * const ACCOUNT_TYPE = "RING"; constexpr static const char * const ACCOUNT_TYPE = "RING";
...@@ -175,18 +178,6 @@ class RingAccount : public SIPAccountBase { ...@@ -175,18 +178,6 @@ class RingAccount : public SIPAccountBase {
return &via_addr_; 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 */ /* Returns true if the username and/or hostname match this account */
MatchRank matches(const std::string &username, const std::string &hostname) const; MatchRank matches(const std::string &username, const std::string &hostname) const;
......
...@@ -45,36 +45,39 @@ ...@@ -45,36 +45,39 @@
struct pjsip_msg; 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) { enum class KeyExchangeProtocol { NONE, SDES, ZRTP };
return kx == KeyExchangeProtocol::SDES ? "sdes" : (
kx == KeyExchangeProtocol::ZRTP ? "zrtp" : "");
}
constexpr KeyExchangeProtocol getKeyExchangeProtocol(const char* name) {
return !strcmp("sdes", name) ? KeyExchangeProtocol::SDES : KeyExchangeProtocol::NONE;
}
/** constexpr const char* getKeyExchangeName(KeyExchangeProtocol kx) {
* Helper function to parser header from incoming sip messages return kx == KeyExchangeProtocol::SDES ? "sdes" : (
* @return Header from SIP message kx == KeyExchangeProtocol::ZRTP ? "zrtp" : "");
*/ }
std::string fetchHeaderValue(pjsip_msg *msg, const std::string &field); 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 }} // namespace ring::sip_utils
......
...@@ -63,6 +63,10 @@ ...@@ -63,6 +63,10 @@
#include "system_codec_container.h" #include "system_codec_container.h"
#include "upnp/upnp_control.h"
#include "ip_utils.h"
#include "string_utils.h"
#include <unistd.h> #include <unistd.h>
#include <pwd.h> #include <pwd.h>
...@@ -72,9 +76,6 @@ ...@@ -72,9 +76,6 @@
#include <sstream> #include <sstream>
#include <cstdlib> #include <cstdlib>
#include "upnp/upnp_control.h"
#include "ip_utils.h"
namespace ring { namespace ring {
using yaml_utils::parseValue; using yaml_utils::parseValue;
...@@ -430,6 +431,8 @@ void SIPAccount::serialize(YAML::Emitter &out) ...@@ -430,6 +431,8 @@ void SIPAccount::serialize(YAML::Emitter &out)
out << YAML::BeginMap; out << YAML::BeginMap;
SIPAccountBase::serialize(out); SIPAccountBase::serialize(out);
out << YAML::Key << Conf::PORT_KEY << YAML::Value << localPort_;
// each credential is a map, and we can have multiple credentials // each credential is a map, and we can have multiple credentials
out << YAML::Key << Conf::CRED_KEY << YAML::Value << credentials_; out << YAML::Key << Conf::CRED_KEY << YAML::Value << credentials_;
out << YAML::Key << Conf::KEEP_ALIVE_ENABLED << YAML::Value << keepAliveEnabled_; out << YAML::Key << Conf::KEEP_ALIVE_ENABLED << YAML::Value << keepAliveEnabled_;
...@@ -448,6 +451,7 @@ void SIPAccount::serialize(YAML::Emitter &out) ...@@ -448,6 +451,7 @@ void SIPAccount::serialize(YAML::Emitter &out)
out << YAML::Key << Conf::TLS_KEY << YAML::Value << YAML::BeginMap; out << YAML::Key << Conf::TLS_KEY << YAML::Value << YAML::BeginMap;
SIPAccountBase::serializeTls(out); SIPAccountBase::serializeTls(out);
out << YAML::Key << Conf::TLS_ENABLE_KEY << YAML::Value << tlsEnable_; 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_CLIENT_KEY << YAML::Value << tlsVerifyClient_;
out << YAML::Key << Conf::VERIFY_SERVER_KEY << YAML::Value << tlsVerifyServer_; out << YAML::Key << Conf::VERIFY_SERVER_KEY << YAML::Value << tlsVerifyServer_;
out << YAML::Key << Conf::REQUIRE_CERTIF_KEY << YAML::Value << tlsRequireClientCertificate_; out << YAML::Key << Conf::REQUIRE_CERTIF_KEY << YAML::Value << tlsRequireClientCertificate_;
...@@ -506,6 +510,10 @@ void SIPAccount::unserialize(const YAML::Node &node) ...@@ -506,6 +510,10 @@ void SIPAccount::unserialize(const YAML::Node &node)
if (not publishedSameasLocal_) if (not publishedSameasLocal_)
usePublishedAddressPortInVIA(); 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, Preferences::REGISTRATION_EXPIRE_KEY, registrationExpire_);
if (not isIP2IP()) parseValue(node, Conf::KEEP_ALIVE_ENABLED, keepAliveEnabled_); if (not isIP2IP()) parseValue(node, Conf::KEEP_ALIVE_ENABLED, keepAliveEnabled_);
...@@ -548,6 +556,7 @@ void SIPAccount::unserialize(const YAML::Node &node) ...@@ -548,6 +556,7 @@ void SIPAccount::unserialize(const YAML::Node &node)
const auto &tlsMap = node[Conf::TLS_KEY]; const auto &tlsMap = node[Conf::TLS_KEY];
parseValue(tlsMap, Conf::TLS_ENABLE_KEY, tlsEnable_); parseValue(tlsMap, Conf::TLS_ENABLE_KEY, tlsEnable_);
parseValue(tlsMap, Conf::TLS_PORT_KEY, tlsListenerPort_);
parseValue(tlsMap, Conf::CIPHERS_KEY, tlsCiphers_); parseValue(tlsMap, Conf::CIPHERS_KEY, tlsCiphers_);
std::string tmpMethod(tlsMethod_); std::string tmpMethod(tlsMethod_);
...@@ -585,6 +594,8 @@ void SIPAccount::setAccountDetails(const std::map<std::string, std::string> &det ...@@ -585,6 +594,8 @@ void SIPAccount::setAccountDetails(const std::map<std::string, std::string> &det
{ {
SIPAccountBase::setAccountDetails(details); SIPAccountBase::setAccountDetails(details);
parseInt(details, Conf::CONFIG_LOCAL_PORT, localPort_);
// SIP specific account settings // SIP specific account settings
parseString(details, Conf::CONFIG_ACCOUNT_ROUTESET, serviceRoute_); parseString(details, Conf::CONFIG_ACCOUNT_ROUTESET, serviceRoute_);
...@@ -611,6 +622,7 @@ void SIPAccount::setAccountDetails(const std::map<std::string, std::string> &det ...@@ -611,6 +622,7 @@ void SIPAccount::setAccountDetails(const std::map<std::string, std::string> &det
// TLS settings // TLS settings
parseBool(details, Conf::CONFIG_TLS_ENABLE, tlsEnable_); parseBool(details, Conf::CONFIG_TLS_ENABLE, tlsEnable_);
parseInt(details, Conf::CONFIG_TLS_LISTENER_PORT, tlsListenerPort_);
auto iter = details.find(Conf::CONFIG_TLS_METHOD); auto iter = details.find(Conf::CONFIG_TLS_METHOD);
if (iter != details.end()) if (iter != details.end())
validate(tlsMethod_, iter->second, VALID_TLS_METHODS); validate(tlsMethod_, iter->second, VALID_TLS_METHODS);
...@@ -690,6 +702,8 @@ std::map<std::string, std::string> SIPAccount::getAccountDetails() const ...@@ -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_CODE] = registrationStateCode;
a[Conf::CONFIG_ACCOUNT_REGISTRATION_STATE_DESC] = registrationStateDescription; 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_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_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; 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 ...@@ -710,6 +724,7 @@ std::map<std::string, std::string> SIPAccount::getAccountDetails() const
// TLS listener is unique and parameters are modified through IP2IP_PROFILE // 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_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_METHOD] = tlsMethod_;
a[Conf::CONFIG_TLS_CIPHERS] = tlsCiphers_; a[Conf::CONFIG_TLS_CIPHERS] = tlsCiphers_;
a[Conf::CONFIG_TLS_SERVER_NAME] = tlsServerName_; a[Conf::CONFIG_TLS_SERVER_NAME] = tlsServerName_;
...@@ -1737,10 +1752,7 @@ std::map<std::string, std::string> SIPAccount::getIp2IpDetails() const ...@@ -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_HELLO_HASH] = zrtpHelloHash_ ? TRUE_STR : FALSE_STR;
ip2ipAccountDetails[Conf::CONFIG_ZRTP_NOT_SUPP_WARNING] = zrtpNotSuppWarning_ ? 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_ZRTP_DISPLAY_SAS_ONCE] = zrtpDisplaySasOnce_ ? TRUE_STR : FALSE_STR;
ip2ipAccountDetails[Conf::CONFIG_LOCAL_INTERFACE] = interface_; ip2ipAccountDetails[Conf::CONFIG_LOCAL_PORT] = ring::to_string(localPort_);
std::stringstream portstr;
portstr << localPort_;
ip2ipAccountDetails[Conf::CONFIG_LOCAL_PORT] = portstr.str();
std::map<std::string, std::string> tlsSettings(getTlsSettings()); std::map<std::string, std::string> tlsSettings(getTlsSettings());
std::copy(tlsSettings.begin(), tlsSettings.end(), std::inserter( std::copy(tlsSettings.begin(), tlsSettings.end(), std::inserter(
...@@ -1754,9 +1766,7 @@ std::map<std::string, std::string> SIPAccount::getTlsSettings() const ...@@ -1754,9 +1766,7 @@ std::map<std::string, std::string> SIPAccount::getTlsSettings() const
assert(isIP2IP()); assert(isIP2IP());
std::map<std::string, std::string> tlsSettings; std::map<std::string, std::string> tlsSettings;
std::stringstream portstr; tlsSettings[Conf::CONFIG_TLS_LISTENER_PORT] = ring::to_string(tlsListenerPort_);
portstr << tlsListenerPort_;
tlsSettings[Conf::CONFIG_TLS_LISTENER_PORT] = portstr.str();
tlsSettings[Conf::CONFIG_TLS_ENABLE] = tlsEnable_ ? TRUE_STR : FALSE_STR; tlsSettings[Conf::CONFIG_TLS_ENABLE] = tlsEnable_ ? TRUE_STR : FALSE_STR;
tlsSettings[Conf::CONFIG_TLS_CA_LIST_FILE] = tlsCaListFile_; tlsSettings[Conf::CONFIG_TLS_CA_LIST_FILE] = tlsCaListFile_;
tlsSettings[Conf::CONFIG_TLS_CERTIFICATE_FILE] = tlsCertificateFile_; tlsSettings[Conf::CONFIG_TLS_CERTIFICATE_FILE] = tlsCertificateFile_;
......
...@@ -290,6 +290,23 @@ class SIPAccount : public SIPAccountBase { ...@@ -290,6 +290,23 @@ class SIPAccount : public SIPAccountBase {
void destroyRegistrationInfo(); 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 * @return pjsip_tls_setting structure, filled from the configuration
* file, that can be used directly by PJSIP to initialize * file, that can be used directly by PJSIP to initialize
...@@ -299,6 +316,14 @@ class SIPAccount : public SIPAccountBase { ...@@ -299,6 +316,14 @@ class SIPAccount : public SIPAccountBase {
return &tlsSetting_; 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 * @return pj_str_t , filled from the configuration
* file, that can be used directly by PJSIP to initialize * file, that can be used directly by PJSIP to initialize
...@@ -553,6 +578,18 @@ class SIPAccount : public SIPAccountBase { ...@@ -553,6 +578,18 @@ class SIPAccount : public SIPAccountBase {
*/ */
std::vector< std::map<std::string, std::string > > credentials_; 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 #if HAVE_TLS
static const CipherArray TLSv1_DEFAULT_CIPHER_LIST; static const CipherArray TLSv1_DEFAULT_CIPHER_LIST;
...@@ -661,6 +698,16 @@ class SIPAccount : public SIPAccountBase { ...@@ -661,6 +698,16 @@ class SIPAccount : public SIPAccountBase {
*/ */
pj_uint16_t stunPort_ {PJ_STUN_PORT}; 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}; bool tlsEnable_ {false};
std::string tlsMethod_; std::string tlsMethod_;
std::string tlsCiphers_; std::string tlsCiphers_;
...@@ -757,7 +804,7 @@ class SIPAccount : public SIPAccountBase { ...@@ -757,7 +804,7 @@ class SIPAccount : public SIPAccountBase {
* selected in the configuration in the case that UPnP is used and the * selected in the configuration in the case that UPnP is used and the
* configured port is already used by another client * 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 } // namespace ring
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include <yaml-cpp/yaml.h> #include <yaml-cpp/yaml.h>
#include "client/signal.h" #include "client/signal.h"
#include "string_utils.h"
#include <type_traits> #include <type_traits>
...@@ -86,6 +87,15 @@ unserializeRange(const YAML::Node &node, const char *minKey, const char *maxKey, ...@@ -86,6 +87,15 @@ unserializeRange(const YAML::Node &node, const char *minKey, const char *maxKey,
updateRange(tmpMin, tmpMax, range); 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> template <typename T>
static void static void
parseInt(const std::map<std::string, std::string> &details, const char *key, T &i) parseInt(const std::map<std::string, std::string> &details, const char *key, T &i)
...@@ -106,7 +116,6 @@ void SIPAccountBase::serialize(YAML::Emitter &out) ...@@ -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::AUDIO_PORT_MIN_KEY << YAML::Value << audioPortRange_.first;
out << YAML::Key << Conf::DTMF_TYPE_KEY << YAML::Value << dtmfType_; out << YAML::Key << Conf::DTMF_TYPE_KEY << YAML::Value << dtmfType_;
out << YAML::Key << Conf::INTERFACE_KEY << YAML::Value << interface_; 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_ADDR_KEY << YAML::Value << publishedIpAddress_;
out << YAML::Key << Conf::PUBLISH_PORT_KEY << YAML::Value << publishedPort_; out << YAML::Key << Conf::PUBLISH_PORT_KEY << YAML::Value << publishedPort_;
out << YAML::Key << Conf::SAME_AS_LOCAL_KEY << YAML::Value << publishedSameasLocal_; out << YAML::Key << Conf::SAME_AS_LOCAL_KEY << YAML::Value << publishedSameasLocal_;
...@@ -118,7 +127,6 @@ void SIPAccountBase::serialize(YAML::Emitter &out) ...@@ -118,7 +127,6 @@ void SIPAccountBase::serialize(YAML::Emitter &out)
void SIPAccountBase::serializeTls(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::CALIST_KEY << YAML::Value << tlsCaListFile_;
out << YAML::Key << Conf::CERTIFICATE_KEY << YAML::Value << tlsCertificateFile_; out << YAML::Key << Conf::CERTIFICATE_KEY << YAML::Value << tlsCertificateFile_;
out << YAML::Key << Conf::TLS_PASSWORD_KEY << YAML::Value << tlsPassword_; out << YAML::Key << Conf::TLS_PASSWORD_KEY << YAML::Value << tlsPassword_;
...@@ -135,10 +143,6 @@ void SIPAccountBase::unserialize(const YAML::Node &node) ...@@ -135,10 +143,6 @@ void SIPAccountBase::unserialize(const YAML::Node &node)
parseValue(node, VIDEO_ENABLED_KEY, videoEnabled_); parseValue(node, VIDEO_ENABLED_KEY, videoEnabled_);
parseValue(node, Conf::INTERFACE_KEY, interface_); 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_); parseValue(node, Conf::SAME_AS_LOCAL_KEY, publishedSameasLocal_);
std::string publishedIpAddress; std::string publishedIpAddress;
parseValue(node, Conf::PUBLISH_ADDR_KEY, publishedIpAddress); parseValue(node, Conf::PUBLISH_ADDR_KEY, publishedIpAddress);
...@@ -146,6 +150,7 @@ void SIPAccountBase::unserialize(const YAML::Node &node) ...@@ -146,6 +150,7 @@ void SIPAccountBase::unserialize(const YAML::Node &node)
if (publishedIp and not publishedSameasLocal_) if (publishedIp and not publishedSameasLocal_)
setPublishedAddress(publishedIp); setPublishedAddress(publishedIp);
int port = sip_utils::DEFAULT_SIP_PORT;
parseValue(node, Conf::PUBLISH_PORT_KEY, port); parseValue(node, Conf::PUBLISH_PORT_KEY, port);
publishedPort_ = port; publishedPort_ = port;
...@@ -153,7 +158,6 @@ void SIPAccountBase::unserialize(const YAML::Node &node) ...@@ -153,7 +158,6 @@ void SIPAccountBase::unserialize(const YAML::Node &node)
// get tls submap // get tls submap
const auto &tlsMap = node[Conf::TLS_KEY]; const auto &tlsMap = node[Conf::TLS_KEY];
parseValue(tlsMap, Conf::TLS_PORT_KEY, tlsListenerPort_);
parseValue(tlsMap, Conf::CERTIFICATE_KEY, tlsCertificateFile_); parseValue(tlsMap, Conf::CERTIFICATE_KEY, tlsCertificateFile_);
parseValue(tlsMap, Conf::CALIST_KEY, tlsCaListFile_); parseValue(tlsMap, Conf::CALIST_KEY, tlsCaListFile_);
parseValue(tlsMap, Conf::TLS_PASSWORD_KEY, tlsPassword_); parseValue(tlsMap, Conf::TLS_PASSWORD_KEY, tlsPassword_);
...@@ -174,7 +178,6 @@ void SIPAccountBase::setAccountDetails(const std::map<std::string, std::string> ...@@ -174,7 +178,6 @@ void SIPAccountBase::setAccountDetails(const std::map<std::string, std::string>
parseString(details, Conf::CONFIG_LOCAL_INTERFACE, interface_); parseString(details, Conf::CONFIG_LOCAL_INTERFACE, interface_);
parseBool(details, Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal_); parseBool(details, Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal_);
parseString(details, Conf::CONFIG_PUBLISHED_ADDRESS, publishedIpAddress_); parseString(details, Conf::CONFIG_PUBLISHED_ADDRESS, publishedIpAddress_);
parseInt(details, Conf::CONFIG_LOCAL_PORT, localPort_);
parseInt(details, Conf::CONFIG_PUBLISHED_PORT, publishedPort_); parseInt(details, Conf::CONFIG_PUBLISHED_PORT, publishedPort_);
parseString(details, Conf::CONFIG_ACCOUNT_DTMF_TYPE, dtmfType_); parseString(details, Conf::CONFIG_ACCOUNT_DTMF_TYPE, dtmfType_);
...@@ -193,7 +196,6 @@ void SIPAccountBase::setAccountDetails(const std::map<std::string, std::string> ...@@ -193,7 +196,6 @@ void SIPAccountBase::setAccountDetails(const std::map<std::string, std::string>
#endif #endif
// TLS // TLS
parseInt(details, Conf::CONFIG_TLS_LISTENER_PORT, tlsListenerPort_);
parseString(details, Conf::CONFIG_TLS_CA_LIST_FILE, tlsCaListFile_); parseString(details, Conf::CONFIG_TLS_CA_LIST_FILE, tlsCaListFile_);
parseString(details, Conf::CONFIG_TLS_CERTIFICATE_FILE, tlsCertificateFile_); parseString(details, Conf::CONFIG_TLS_CERTIFICATE_FILE, tlsCertificateFile_);
parseString(details, Conf::CONFIG_TLS_PRIVATE_KEY_FILE, tlsPrivateKeyFile_); parseString(details, Conf::CONFIG_TLS_PRIVATE_KEY_FILE, tlsPrivateKeyFile_);
...@@ -218,19 +220,10 @@ SIPAccountBase::getAccountDetails() const ...@@ -218,19 +220,10 @@ SIPAccountBase::getAccountDetails() const
a[Conf::CONFIG_ACCOUNT_DTMF_TYPE] = dtmfType_; a[Conf::CONFIG_ACCOUNT_DTMF_TYPE] = dtmfType_;
a[Conf::CONFIG_LOCAL_INTERFACE] = interface_; 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_SAMEAS_LOCAL] = publishedSameasLocal_ ? TRUE_STR : FALSE_STR;
a[Conf::CONFIG_PUBLISHED_ADDRESS] = publishedIpAddress_; 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_CA_LIST_FILE] = tlsCaListFile_;
a[Conf::CONFIG_TLS_CERTIFICATE_FILE] = tlsCertificateFile_; a[Conf::CONFIG_TLS_CERTIFICATE_FILE] = tlsCertificateFile_;
a[Conf::CONFIG_TLS_PRIVATE_KEY_FILE] = tlsPrivateKeyFile_; a[Conf::CONFIG_TLS_PRIVATE_KEY_FILE] = tlsPrivateKeyFile_;
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include "config.h" #include "config.h"
#endif #endif
#include "siptransport.h"
#include "sip_utils.h" #include "sip_utils.h"
#include "account.h" #include "account.h"
...@@ -48,7 +47,6 @@ ...@@ -48,7 +47,6 @@
#include <array> #include <array>
#include <vector> #include <vector>
#include <map> #include <map>
#include <sstream>
#include <memory> #include <memory>
namespace ring { namespace ring {
...@@ -150,16 +148,11 @@ public: ...@@ -150,16 +148,11 @@ public:
return false; return false;
} }
virtual pjsip_tls_setting * getTlsSetting() {
return nullptr;
}
/** /**
* Get the local port for TLS listener. * Get the local interface name on which this account is bound.
* @return pj_uint16 The port used for that account
*/ */
pj_uint16_t getTlsListenerPort() const { const std::string& getLocalInterface() const {
return tlsListenerPort_; return interface_;
} }
/** /**
...@@ -181,39 +174,6 @@ public: ...@@ -181,39 +174,6 @@ public:
publishedIpAddress_ = ip_addr.toString(); 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 * Get the published port, which is the port to be advertised as the port
* for the chosen SIP transport. * for the chosen SIP transport.
...@@ -232,6 +192,15 @@ public: ...@@ -232,6 +192,15 @@ public:
publishedPort_ = port; publishedPort_ = port;
} }
/**