From a944050e45a0798ea66d44165b8d58f073256544 Mon Sep 17 00:00:00 2001 From: Ming Rui Zhang <mingrui.zhang@savoirfairelinux.com> Date: Fri, 26 Feb 2021 16:18:30 -0500 Subject: [PATCH] sip: expose allowViaRewrite option and make it false by default Gitlab: #456 Change-Id: Ic44c9ce0b682bf8352b15ad9eaf8d51a15c4c657 --- src/account_schema.h | 3 ++- src/sip/sipaccount.cpp | 8 +++++++- src/sip/sipaccountbase.h | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/account_schema.h b/src/account_schema.h index 820463a80d..f5a187fcf9 100644 --- a/src/account_schema.h +++ b/src/account_schema.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2004-2021 Savoir-faire Linux Inc. * * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> @@ -53,6 +53,7 @@ static const char* const CONFIG_PRESENCE_NOTE = "Account.presenceNote"; static const char* const CONFIG_ACCOUNT_HOSTNAME = "Account.hostname"; static const char* const CONFIG_ACCOUNT_USERNAME = "Account.username"; static const char* const CONFIG_ACCOUNT_ROUTESET = "Account.routeset"; +static const char* const CONFIG_ACCOUNT_IP_REWRITE = "Account.allowViaRewrite"; static const char* const CONFIG_ACCOUNT_PASSWORD = "Account.password"; static const char* const CONFIG_ACCOUNT_REALM = "Account.realm"; static const char* const CONFIG_ACCOUNT_USERAGENT = "Account.useragent"; diff --git a/src/sip/sipaccount.cpp b/src/sip/sipaccount.cpp index f61181d388..5657dc7264 100644 --- a/src/sip/sipaccount.cpp +++ b/src/sip/sipaccount.cpp @@ -84,6 +84,7 @@ namespace jami { using yaml_utils::parseValue; +using yaml_utils::parseValueOptional; using yaml_utils::parseVectorMap; using sip_utils::CONST_PJ_STR; @@ -152,7 +153,7 @@ SIPAccount::SIPAccount(const std::string& accountID, bool presenceEnabled) , contactBuffer_() , contact_ {contactBuffer_, 0} , contactRewriteMethod_(2) - , allowViaRewrite_(true) + , allowViaRewrite_(false) , allowContactRewrite_(1) , contactOverwritten_(false) , via_tp_(nullptr) @@ -456,6 +457,7 @@ SIPAccount::serialize(YAML::Emitter& out) const out << YAML::Key << Preferences::REGISTRATION_EXPIRE_KEY << YAML::Value << registrationExpire_; out << YAML::Key << Conf::SERVICE_ROUTE_KEY << YAML::Value << serviceRoute_; + out << YAML::Key << Conf::ALLOW_VIA_REWRITE << YAML::Value << allowViaRewrite_; // tls submap out << YAML::Key << Conf::TLS_KEY << YAML::Value << YAML::BeginMap; @@ -532,6 +534,8 @@ SIPAccount::unserialize(const YAML::Node& node) parseValue(node, Preferences::REGISTRATION_EXPIRE_KEY, registrationExpire_); parseValue(node, Conf::KEEP_ALIVE_ENABLED, keepAliveEnabled_); parseValue(node, Conf::SERVICE_ROUTE_KEY, serviceRoute_); + parseValueOptional(node, Conf::ALLOW_VIA_REWRITE, allowViaRewrite_); + const auto& credsNode = node[Conf::CRED_KEY]; setCredentials(parseVectorMap(credsNode, {Conf::CONFIG_ACCOUNT_REALM, @@ -608,6 +612,7 @@ SIPAccount::setAccountDetails(const std::map<std::string, std::string>& details) // SIP specific account settings parseString(details, Conf::CONFIG_BIND_ADDRESS, bindAddress_); parseString(details, Conf::CONFIG_ACCOUNT_ROUTESET, serviceRoute_); + parseBool(details, Conf::CONFIG_ACCOUNT_IP_REWRITE, allowViaRewrite_); if (not publishedSameasLocal_) usePublishedAddressPortInVIA(); @@ -685,6 +690,7 @@ SIPAccount::getAccountDetails() const a.emplace(Conf::CONFIG_BIND_ADDRESS, bindAddress_); a.emplace(Conf::CONFIG_LOCAL_PORT, std::to_string(localPort_)); a.emplace(Conf::CONFIG_ACCOUNT_ROUTESET, serviceRoute_); + a.emplace(Conf::CONFIG_ACCOUNT_IP_REWRITE, allowViaRewrite_ ? TRUE_STR : FALSE_STR); a.emplace(Conf::CONFIG_ACCOUNT_REGISTRATION_EXPIRE, std::to_string(registrationExpire_)); a.emplace(Conf::CONFIG_KEEP_ALIVE_ENABLED, keepAliveEnabled_ ? TRUE_STR : FALSE_STR); diff --git a/src/sip/sipaccountbase.h b/src/sip/sipaccountbase.h index 8472a65aca..6fb154c6e9 100644 --- a/src/sip/sipaccountbase.h +++ b/src/sip/sipaccountbase.h @@ -66,6 +66,7 @@ const char* const PUBLISH_PORT_KEY = "publishPort"; const char* const SAME_AS_LOCAL_KEY = "sameasLocal"; const char* const DTMF_TYPE_KEY = "dtmfType"; const char* const SERVICE_ROUTE_KEY = "serviceRoute"; +const char* const ALLOW_VIA_REWRITE = "allowViaRewrite"; const char* const PRESENCE_ENABLED_KEY = "presenceEnabled"; const char* const PRESENCE_PUBLISH_SUPPORTED_KEY = "presencePublishSupported"; const char* const PRESENCE_SUBSCRIBE_SUPPORTED_KEY = "presenceSubscribeSupported"; -- GitLab