diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index c4f9a84640e0b487635d24a26e09bf8c354a5c87..1beb715ecd2a00f9eb7417cbf2268db1fd517787 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -117,9 +117,9 @@ SIPAccount::SIPAccount(const std::string& accountID) , receivedParameter_("") , rPort_(-1) , via_addr_() - , audioPortRange_(16384, 32766) + , audioPortRange_({16384, 32766}) #ifdef SFL_VIDEO - , videoPortRange_(49152, 65534) + , videoPortRange_({49152, UINT16_MAX - 2}) #endif { via_addr_.host.ptr = 0; @@ -130,6 +130,44 @@ SIPAccount::SIPAccount(const std::string& accountID) alias_ = IP2IP_PROFILE; } +namespace { +std::array<std::unique_ptr<Conf::ScalarNode>, 2> +serializeRange(Conf::MappingNode &accountMap, const char *minKey, const char *maxKey, const std::pair<uint16_t, uint16_t> &range) +{ + using namespace Conf; + std::array<std::unique_ptr<ScalarNode>, 2> result; + + std::ostringstream os; + os << range.first; + result[0].reset(new ScalarNode(os.str())); + os.str(""); + accountMap.setKeyValue(minKey, result[0].get()); + + os << range.second; + ScalarNode portMax(os.str()); + result[1].reset(new ScalarNode(os.str())); + accountMap.setKeyValue(maxKey, result[1].get()); + return result; +} + +void +unserializeRange(const Conf::YamlNode &mapNode, const char *minKey, const char *maxKey, std::pair<uint16_t, uint16_t> &range) +{ + std::stringstream ss; + ss << mapNode.getValue(minKey); + uint16_t tmp; + ss >> tmp; + if (tmp) + range.first = tmp; + ss.str(""); + ss << mapNode.getValue(maxKey); + ss >> tmp; + if (tmp) + range.second = tmp; +} +} + + void SIPAccount::serialize(Conf::YamlEmitter &emitter) { using namespace Conf; @@ -283,6 +321,11 @@ void SIPAccount::serialize(Conf::YamlEmitter &emitter) ScalarNode userAgent(userAgent_); accountmap.setKeyValue(USER_AGENT_KEY, &userAgent); + std::array<std::unique_ptr<ScalarNode>, 2> audioPortNodes(serializeRange(accountmap, AUDIO_PORT_MIN_KEY, AUDIO_PORT_MAX_KEY, audioPortRange_)); +#ifdef SFL_VIDEO + std::array<std::unique_ptr<ScalarNode>, 2> videoPortNodes(serializeRange(accountmap, VIDEO_PORT_MIN_KEY, VIDEO_PORT_MAX_KEY, videoPortRange_)); +#endif + try { emitter.serializeAccount(&accountmap); } catch (const YamlEmitterException &e) { @@ -488,6 +531,11 @@ void SIPAccount::unserialize(const Conf::YamlNode &mapNode) tlsMap->getValue(TIMEOUT_KEY, &tlsNegotiationTimeoutMsec_); } mapNode.getValue(USER_AGENT_KEY, &userAgent_); + + unserializeRange(mapNode, AUDIO_PORT_MIN_KEY, AUDIO_PORT_MAX_KEY, audioPortRange_); +#ifdef SFL_VIDEO + unserializeRange(mapNode, VIDEO_PORT_MIN_KEY, VIDEO_PORT_MAX_KEY, videoPortRange_); +#endif } void SIPAccount::setAccountDetails(std::map<std::string, std::string> details) diff --git a/daemon/src/sip/sipaccount.h b/daemon/src/sip/sipaccount.h index 29c92eeaf29406e68dac641738deb26cc5471a09..e48322ebb75280fbbaa4cbc4ca6c055fd7a1804c 100644 --- a/daemon/src/sip/sipaccount.h +++ b/daemon/src/sip/sipaccount.h @@ -36,7 +36,6 @@ #define SIPACCOUNT_H #include <vector> -#include <set> #include <map> #include "account.h" #include "pjsip/sip_transport_tls.h" @@ -91,6 +90,12 @@ namespace Conf { const char *const STUN_ENABLED_KEY = "stunEnabled"; const char *const STUN_SERVER_KEY = "stunServer"; const char *const CRED_KEY = "credential"; + const char *const AUDIO_PORT_MIN_KEY = "audioPortMin"; + const char *const AUDIO_PORT_MAX_KEY = "audioPortMax"; +#ifdef SFL_VIDEO + const char *const VIDEO_PORT_MIN_KEY = "videoPortMin"; + const char *const VIDEO_PORT_MAX_KEY = "videoPortMax"; +#endif } class SIPVoIPLink;