diff --git a/src/account_schema.h b/src/account_schema.h index 495b617073e9b1a517a0ab4b189134d04297dea5..7222c1687250c0fcbafcfa415cb7e1f2dce2af4a 100644 --- a/src/account_schema.h +++ b/src/account_schema.h @@ -79,6 +79,8 @@ static const char *const CONFIG_UPNP_ENABLED = "Account.upnpE // SIP specific parameters static const char *const CONFIG_STUN_SERVER = "STUN.server"; static const char *const CONFIG_STUN_ENABLE = "STUN.enable"; +static const char *const CONFIG_TURN_SERVER = "TURN.server"; +static const char *const CONFIG_TURN_ENABLE = "TURN.enable"; // SRTP specific parameters static const char *const CONFIG_SRTP_ENABLE = "SRTP.enable"; diff --git a/src/sip/sipaccount.cpp b/src/sip/sipaccount.cpp index d73f5f5143bec61cfc120c9e003a19211e82074c..16d9904ac2ae596b3bc61eb91c4ac7a0808a3780 100644 --- a/src/sip/sipaccount.cpp +++ b/src/sip/sipaccount.cpp @@ -432,9 +432,6 @@ void SIPAccount::serialize(YAML::Emitter &out) out << YAML::Key << Preferences::REGISTRATION_EXPIRE_KEY << YAML::Value << registrationExpire_; out << YAML::Key << Conf::SERVICE_ROUTE_KEY << YAML::Value << serviceRoute_; - out << YAML::Key << Conf::STUN_ENABLED_KEY << YAML::Value << stunEnabled_; - out << YAML::Key << Conf::STUN_SERVER_KEY << YAML::Value << stunServer_; - // tls submap out << YAML::Key << Conf::TLS_KEY << YAML::Value << YAML::BeginMap; SIPAccountBase::serializeTls(out); @@ -520,10 +517,6 @@ void SIPAccount::unserialize(const YAML::Node &node) if (not isIP2IP()) parseValue(node, Conf::SERVICE_ROUTE_KEY, serviceRoute_); - // stun enabled - if (not isIP2IP()) parseValue(node, Conf::STUN_ENABLED_KEY, stunEnabled_); - if (not isIP2IP()) parseValue(node, Conf::STUN_SERVER_KEY, stunServer_); - // Init stun server name with default server name stunServerName_ = pj_str((char*) stunServer_.data()); @@ -592,8 +585,6 @@ void SIPAccount::setAccountDetails(const std::map<std::string, std::string> &det if (not publishedSameasLocal_) usePublishedAddressPortInVIA(); - parseString(details, Conf::CONFIG_STUN_SERVER, stunServer_); - parseBool(details, Conf::CONFIG_STUN_ENABLE, stunEnabled_); parseInt(details, Conf::CONFIG_ACCOUNT_REGISTRATION_EXPIRE, registrationExpire_); if (registrationExpire_ < MIN_REGISTRATION_TIME) @@ -663,8 +654,6 @@ SIPAccount::getAccountDetails() const a.emplace(Conf::CONFIG_LOCAL_PORT, ring::to_string(localPort_)); a.emplace(Conf::CONFIG_ACCOUNT_ROUTESET, serviceRoute_); a.emplace(Conf::CONFIG_ACCOUNT_REGISTRATION_EXPIRE, ring::to_string(registrationExpire_)); - a.emplace(Conf::CONFIG_STUN_ENABLE, stunEnabled_ ? TRUE_STR : FALSE_STR); - a.emplace(Conf::CONFIG_STUN_SERVER, stunServer_); a.emplace(Conf::CONFIG_KEEP_ALIVE_ENABLED, keepAliveEnabled_ ? TRUE_STR : FALSE_STR); a.emplace(Conf::CONFIG_PRESENCE_ENABLED, presence_ and presence_->isEnabled()? TRUE_STR : FALSE_STR); diff --git a/src/sip/sipaccount.h b/src/sip/sipaccount.h index 1d0a208f71b3ba7f032e599c7f84f1bafac8e8dc..f6d81a960c976b6a484f0be90b18f8e00518fb93 100644 --- a/src/sip/sipaccount.h +++ b/src/sip/sipaccount.h @@ -326,18 +326,6 @@ class SIPAccount : public SIPAccountBase { return tlsListenerPort_; } - /** - * @return pj_str_t , filled from the configuration - * file, that can be used directly by PJSIP to initialize - * an alternate UDP transport. - */ - std::string getStunServer() const { - return stunServer_; - } - void setStunServer(const std::string &srv) { - stunServer_ = srv; - } - pj_str_t getStunServerName() const { return stunServerName_; } @@ -684,18 +672,6 @@ class SIPAccount : public SIPAccountBase { */ CipherArray ciphers_; - /** - * Determine if STUN public address resolution is required to register this account. In this case a - * STUN server hostname must be specified. - */ - bool stunEnabled_ {false}; - - /** - * The stun server hostname (optional), used to provide the public IP address in case the softphone - * stay behind a NAT. - */ - std::string stunServer_ {}; - /** * The STUN server name (hostname) */ diff --git a/src/sip/sipaccountbase.cpp b/src/sip/sipaccountbase.cpp index c94874da2e87024c85676b5aa3fb459506c9c848..798957761b21710d42e8c2fd072a3f1ef5b9a243 100644 --- a/src/sip/sipaccountbase.cpp +++ b/src/sip/sipaccountbase.cpp @@ -123,6 +123,11 @@ void SIPAccountBase::serialize(YAML::Emitter &out) out << YAML::Key << VIDEO_ENABLED_KEY << YAML::Value << videoEnabled_; out << YAML::Key << Conf::VIDEO_PORT_MAX_KEY << YAML::Value << videoPortRange_.second; out << YAML::Key << Conf::VIDEO_PORT_MIN_KEY << YAML::Value << videoPortRange_.first; + + out << YAML::Key << Conf::STUN_ENABLED_KEY << YAML::Value << stunEnabled_; + out << YAML::Key << Conf::STUN_SERVER_KEY << YAML::Value << stunServer_; + out << YAML::Key << Conf::TURN_ENABLED_KEY << YAML::Value << turnEnabled_; + out << YAML::Key << Conf::TURN_SERVER_KEY << YAML::Value << turnServer_; } void SIPAccountBase::serializeTls(YAML::Emitter &out) @@ -165,6 +170,14 @@ void SIPAccountBase::unserialize(const YAML::Node &node) unserializeRange(node, Conf::AUDIO_PORT_MIN_KEY, Conf::AUDIO_PORT_MAX_KEY, audioPortRange_); unserializeRange(node, Conf::VIDEO_PORT_MIN_KEY, Conf::VIDEO_PORT_MAX_KEY, videoPortRange_); + + // ICE - STUN/TURN + if (not isIP2IP()) { + parseValue(node, Conf::STUN_ENABLED_KEY, stunEnabled_); + parseValue(node, Conf::STUN_SERVER_KEY, stunServer_); + parseValue(node, Conf::TURN_ENABLED_KEY, turnEnabled_); + parseValue(node, Conf::TURN_SERVER_KEY, turnServer_); + } } void SIPAccountBase::setAccountDetails(const std::map<std::string, std::string> &details) @@ -199,6 +212,12 @@ void SIPAccountBase::setAccountDetails(const std::map<std::string, std::string> parseString(details, Conf::CONFIG_TLS_CERTIFICATE_FILE, tlsCertificateFile_); parseString(details, Conf::CONFIG_TLS_PRIVATE_KEY_FILE, tlsPrivateKeyFile_); parseString(details, Conf::CONFIG_TLS_PASSWORD, tlsPassword_); + + // ICE - STUN/TURN + parseString(details, Conf::CONFIG_STUN_SERVER, stunServer_); + parseBool(details, Conf::CONFIG_STUN_ENABLE, stunEnabled_); + parseString(details, Conf::CONFIG_TURN_SERVER, turnServer_); + parseBool(details, Conf::CONFIG_TURN_ENABLE, turnEnabled_); } std::map<std::string, std::string> @@ -218,10 +237,16 @@ SIPAccountBase::getAccountDetails() const a.emplace(Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal_ ? TRUE_STR : FALSE_STR); a.emplace(Conf::CONFIG_PUBLISHED_ADDRESS, publishedIpAddress_); + a.emplace(Conf::CONFIG_STUN_ENABLE, stunEnabled_ ? TRUE_STR : FALSE_STR); + a.emplace(Conf::CONFIG_STUN_SERVER, stunServer_); + a.emplace(Conf::CONFIG_TURN_ENABLE, turnEnabled_ ? TRUE_STR : FALSE_STR); + a.emplace(Conf::CONFIG_TURN_SERVER, turnServer_); + a.emplace(Conf::CONFIG_TLS_CA_LIST_FILE, tlsCaListFile_); a.emplace(Conf::CONFIG_TLS_CERTIFICATE_FILE, tlsCertificateFile_); a.emplace(Conf::CONFIG_TLS_PRIVATE_KEY_FILE, tlsPrivateKeyFile_); a.emplace(Conf::CONFIG_TLS_PASSWORD, tlsPassword_); + return a; } diff --git a/src/sip/sipaccountbase.h b/src/sip/sipaccountbase.h index 751d86fb34929dbad36445bc96e1b22cd2783155..0a837e9e10b721aa4a4b0e7ea58bed5869067464 100644 --- a/src/sip/sipaccountbase.h +++ b/src/sip/sipaccountbase.h @@ -86,6 +86,8 @@ namespace Conf { const char *const STUN_ENABLED_KEY = "stunEnabled"; const char *const STUN_SERVER_KEY = "stunServer"; + const char *const TURN_ENABLED_KEY = "turnEnabled"; + const char *const TURN_SERVER_KEY = "turnServer"; const char *const CRED_KEY = "credential"; const char *const AUDIO_PORT_MIN_KEY = "audioPortMin"; const char *const AUDIO_PORT_MAX_KEY = "audioPortMax"; @@ -227,6 +229,19 @@ public: #endif static void releasePort(uint16_t port) noexcept; + /** + * @return pj_str_t , filled from the configuration + * file, that can be used directly by PJSIP to initialize + * an alternate UDP transport. + */ + std::string getStunServer() const { + return stunServer_; + } + + void setStunServer(const std::string &srv) { + stunServer_ = srv; + } + protected: virtual void serialize(YAML::Emitter &out); virtual void serializeTls(YAML::Emitter &out); @@ -271,6 +286,30 @@ protected: */ pj_uint16_t publishedPort_ {sip_utils::DEFAULT_SIP_PORT}; + /** + * Determine if STUN public address resolution is required to register this account. In this case a + * STUN server hostname must be specified. + */ + bool stunEnabled_ {false}; + + /** + * The STUN server hostname (optional), used to provide the public IP address in case the softphone + * stay behind a NAT. + */ + std::string stunServer_ {}; + + /** + * Determine if TURN public address resolution is required to register this account. In this case a + * TURN server hostname must be specified. + */ + bool turnEnabled_ {false}; + + /** + * The TURN server hostname (optional), used to provide the public IP address in case the softphone + * stay behind a NAT. + */ + std::string turnServer_ {}; + std::string tlsCaListFile_; std::string tlsCertificateFile_; std::string tlsPrivateKeyFile_;