From 8b454e2535bd27a45219d0b3a0ad1ce1a355d4d8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Sat, 12 Apr 2014 22:31:16 -0400
Subject: [PATCH] sipaccount: add getTransportType method

---
 daemon/src/sip/sipaccount.cpp | 24 +++++++++++++++++-------
 daemon/src/sip/sipaccount.h   |  5 ++++-
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp
index 5851d52738..b9aabf928d 100644
--- a/daemon/src/sip/sipaccount.cpp
+++ b/daemon/src/sip/sipaccount.cpp
@@ -88,8 +88,8 @@ SIPAccount::SIPAccount(const std::string& accountID, bool presenceEnabled)
     , registrationExpire_(MIN_REGISTRATION_TIME)
     , interface_("default")
     , publishedSameasLocal_(true)
-    , publishedIpAddress_()
     , publishedIp_()
+    , publishedIpAddress_()
     , localPort_(DEFAULT_SIP_PORT)
     , publishedPort_(DEFAULT_SIP_PORT)
     , serviceRoute_()
@@ -890,10 +890,13 @@ void SIPAccount::registerVoIPLink()
     if (hostname_.length() >= PJ_MAX_HOSTNAME)
         return;
 
-    DEBUG("SIPAccount::registerVoIPLink");
+    DEBUG("SIPAccount::registerVoIPLink %s ", hostname_.c_str());
 
-#if HAVE_TLS
+    auto IPs = ip_utils::getAddrList(hostname_);
+    for (const auto& ip : IPs)
+        DEBUG("--- %s ", ip_utils::addrToStr(ip).c_str());
 
+#if HAVE_TLS
     // Init TLS settings if the user wants to use TLS
     if (tlsEnable_) {
         DEBUG("TLS is enabled for account %s", accountID_.c_str());
@@ -905,11 +908,18 @@ void SIPAccount::registerVoIPLink()
         // PJSIP does not currently support TLS over IPv6
         transportType_ = PJSIP_TRANSPORT_TLS;
         initTlsConfiguration();
-    } else {
-        transportType_ = PJSIP_TRANSPORT_UDP;
-    }
-
+    } else
 #endif
+    {
+        bool IPv6 = false;
+        if (isIP2IP()) {
+            DEBUG("SIPAccount::registerVoIPLink isIP2IP.");
+            //IPv6 = SipTransport::getInterfaceAddr(interface_).addr.sa_family == pj_AF_INET6();
+        } else if (!IPs.empty())
+            IPv6 = IPs[0].addr.sa_family == pj_AF_INET6();
+
+        transportType_ = IPv6 ? PJSIP_TRANSPORT_UDP6  : PJSIP_TRANSPORT_UDP;
+    }
 
     // Init STUN settings for this account if the user selected it
     if (stunEnabled_) {
diff --git a/daemon/src/sip/sipaccount.h b/daemon/src/sip/sipaccount.h
index 568247292d..731cbca487 100644
--- a/daemon/src/sip/sipaccount.h
+++ b/daemon/src/sip/sipaccount.h
@@ -398,7 +398,6 @@ class SIPAccount : public Account {
 
         /**
          * Get the contact header for
-         * @param prefer_ipv6 If we are dual-stack, use IPv6 contact header.
          * @return pj_str_t The contact header based on account information
          */
         pj_str_t getContactHeader();
@@ -549,6 +548,10 @@ class SIPAccount : public Account {
          */
         pjsip_transport* transport_;
 
+        pjsip_transport_type_e getTransportType() const {
+            return transportType_;
+        }
+
         /* Returns true if the username and/or hostname match this account */
         MatchRank matches(const std::string &username, const std::string &hostname, pjsip_endpoint *endpt, pj_pool_t *pool) const;
 
-- 
GitLab