Commit 2e9bcc05 authored by Guillaume Roguez's avatar Guillaume Roguez Committed by Stepan Salenikovich

sipaccountbase: STUN/TURN server details support

Move STUN sever related details to sipaccountbase.
Add TURN server enable and url to account details.
Add it to YAML serialization.

Refs #72663

Change-Id: If7120b9b632c0a45693a462b715bbd51d4bb2bcb
parent c3a24f70
......@@ -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";
......
......@@ -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);
......
......@@ -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)
*/
......
......@@ -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;
}
......
......@@ -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_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment