From 319688066e844bf89ff8d18a9b6783d7b728f26f Mon Sep 17 00:00:00 2001
From: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
Date: Thu, 15 Aug 2013 17:19:12 -0400
Subject: [PATCH] * #28529: sip: RTP ports now controllable via D-Bus

---
 daemon/src/account_schema.h   |  4 ++++
 daemon/src/sip/sipaccount.cpp | 31 +++++++++++++++++++++++++++++++
 gnome/src/account_schema.h    |  7 ++++++-
 3 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/daemon/src/account_schema.h b/daemon/src/account_schema.h
index 91359c1d3f..5e72f5f39b 100644
--- a/daemon/src/account_schema.h
+++ b/daemon/src/account_schema.h
@@ -67,6 +67,10 @@ static const char *const CONFIG_ACCOUNT_PASSWORD                = "Account.passw
 static const char *const CONFIG_ACCOUNT_REALM                   = "Account.realm";
 static const char *const CONFIG_ACCOUNT_DEFAULT_REALM           = "*";
 static const char *const CONFIG_ACCOUNT_USERAGENT               = "Account.useragent";
+static const char *const CONFIG_ACCOUNT_AUDIO_PORT_MIN          = "Account.audioPortMin";
+static const char *const CONFIG_ACCOUNT_AUDIO_PORT_MAX          = "Account.audioPortMax";
+static const char *const CONFIG_ACCOUNT_VIDEO_PORT_MIN          = "Account.videoPortMin";
+static const char *const CONFIG_ACCOUNT_VIDEO_PORT_MAX          = "Account.videoPortMax";
 
 static const char *const CONFIG_LOCAL_INTERFACE                 = "Account.localInterface";
 static const char *const CONFIG_INTERFACE                       = "Account.interface";
diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp
index 1beb715ecd..44a7aca2f2 100644
--- a/daemon/src/sip/sipaccount.cpp
+++ b/daemon/src/sip/sipaccount.cpp
@@ -577,6 +577,21 @@ void SIPAccount::setAccountDetails(std::map<std::string, std::string> details)
     userAgent_ = details[CONFIG_ACCOUNT_USERAGENT];
     keepAliveEnabled_ = details[CONFIG_KEEP_ALIVE_ENABLED] == TRUE_STR;
 
+    int tmp = atoi(details[CONFIG_ACCOUNT_AUDIO_PORT_MIN].c_str());
+    if (tmp > 0)
+        audioPortRange_.first = tmp;
+    tmp = atoi(details[CONFIG_ACCOUNT_AUDIO_PORT_MAX].c_str());
+    if (tmp > 0)
+        audioPortRange_.second = tmp;
+#ifdef SFL_VIDEO
+    tmp = atoi(details[CONFIG_ACCOUNT_VIDEO_PORT_MIN].c_str());
+    if (tmp > 0)
+        videoPortRange_.first = tmp;
+    tmp = atoi(details[CONFIG_ACCOUNT_VIDEO_PORT_MAX].c_str());
+    if (tmp > 0)
+        videoPortRange_.second = tmp;
+#endif
+
     // srtp settings
     srtpEnabled_ = details[CONFIG_SRTP_ENABLE] == TRUE_STR;
     srtpFallback_ = details[CONFIG_SRTP_RTP_FALLBACK] == TRUE_STR;
@@ -632,6 +647,17 @@ static std::string retrievePassword(const std::map<std::string, std::string>& ma
     return "";
 }
 
+void
+addRangeToDetails(std::map<std::string, std::string> &a, const char *minKey, const char *maxKey, const std::pair<uint16_t, uint16_t> &range)
+{
+    std::ostringstream os;
+    os << range.first;
+    a[minKey] = os.str();
+    os.str("");
+    os << range.second;
+    a[maxKey] = os.str();
+}
+
 std::map<std::string, std::string> SIPAccount::getAccountDetails() const
 {
     std::map<std::string, std::string> a;
@@ -685,6 +711,11 @@ std::map<std::string, std::string> SIPAccount::getAccountDetails() const
     a[CONFIG_ACCOUNT_ROUTESET] = serviceRoute_;
     a[CONFIG_ACCOUNT_USERAGENT] = userAgent_;
 
+    addRangeToDetails(a, CONFIG_ACCOUNT_AUDIO_PORT_MIN, CONFIG_ACCOUNT_AUDIO_PORT_MAX, audioPortRange_);
+#ifdef SFL_VIDEO
+    addRangeToDetails(a, CONFIG_ACCOUNT_VIDEO_PORT_MIN, CONFIG_ACCOUNT_VIDEO_PORT_MAX, videoPortRange_);
+#endif
+
     std::stringstream registrationExpireStr;
     registrationExpireStr << registrationExpire_;
     a[CONFIG_ACCOUNT_REGISTRATION_EXPIRE] = registrationExpireStr.str();
diff --git a/gnome/src/account_schema.h b/gnome/src/account_schema.h
index 008c577612..5e72f5f39b 100644
--- a/gnome/src/account_schema.h
+++ b/gnome/src/account_schema.h
@@ -45,6 +45,7 @@ static const char *const CONFIG_ACCOUNT_TYPE                    = "Account.type"
 static const char *const CONFIG_ACCOUNT_ALIAS                   = "Account.alias";
 static const char *const CONFIG_ACCOUNT_MAILBOX                 = "Account.mailbox";
 static const char *const CONFIG_ACCOUNT_ENABLE                  = "Account.enable";
+static const char *const CONFIG_ACCOUNT_AUTOANSWER              = "Account.autoAnswer";
 static const char *const CONFIG_ACCOUNT_REGISTRATION_EXPIRE     = "Account.registrationExpire";
 static const char *const CONFIG_ACCOUNT_REGISTRATION_STATUS     = "Account.registrationStatus";
 static const char *const CONFIG_ACCOUNT_REGISTRATION_STATE_CODE = "Account.registrationCode";
@@ -57,6 +58,7 @@ static const char *const CONFIG_KEEP_ALIVE_ENABLED              = "Account.keepA
 
 
 static const char *const CONFIG_DEFAULT_REGISTRATION_EXPIRE     = "60";
+static const char *const CONFIG_DEFAULT_RINGTONE_ENABLED        = "true";
 
 static const char *const CONFIG_ACCOUNT_HOSTNAME                = "Account.hostname";
 static const char *const CONFIG_ACCOUNT_USERNAME                = "Account.username";
@@ -65,7 +67,10 @@ static const char *const CONFIG_ACCOUNT_PASSWORD                = "Account.passw
 static const char *const CONFIG_ACCOUNT_REALM                   = "Account.realm";
 static const char *const CONFIG_ACCOUNT_DEFAULT_REALM           = "*";
 static const char *const CONFIG_ACCOUNT_USERAGENT               = "Account.useragent";
-static const char *const CONFIG_ACCOUNT_AUTOANSWER              = "Account.autoAnswer";
+static const char *const CONFIG_ACCOUNT_AUDIO_PORT_MIN          = "Account.audioPortMin";
+static const char *const CONFIG_ACCOUNT_AUDIO_PORT_MAX          = "Account.audioPortMax";
+static const char *const CONFIG_ACCOUNT_VIDEO_PORT_MIN          = "Account.videoPortMin";
+static const char *const CONFIG_ACCOUNT_VIDEO_PORT_MAX          = "Account.videoPortMax";
 
 static const char *const CONFIG_LOCAL_INTERFACE                 = "Account.localInterface";
 static const char *const CONFIG_INTERFACE                       = "Account.interface";
-- 
GitLab