From b2289be374fac2920f7fd8ca041f3d4b79bf989d Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
Date: Mon, 16 Apr 2012 12:40:27 -0400
Subject: [PATCH] #9831: Fix sip transport port number

---
 daemon/src/sip/siptransport.cpp | 12 +++++++++--
 daemon/src/sip/sipvoiplink.cpp  | 36 ---------------------------------
 2 files changed, 10 insertions(+), 38 deletions(-)

diff --git a/daemon/src/sip/siptransport.cpp b/daemon/src/sip/siptransport.cpp
index 38a908656b..e3340f4c2b 100644
--- a/daemon/src/sip/siptransport.cpp
+++ b/daemon/src/sip/siptransport.cpp
@@ -330,7 +330,11 @@ void SipTransport::createSipTransport(SIPAccount *account)
         account->transport_ = transport;
     }
 
+
+
     if (!account->transport_) {
+        DEBUG("SipTransport: Looking into previously created transport map for %s:%d",
+                              account->getLocalInterface().c_str(), account->getLocalPort());
         // Could not create new transport, this transport may already exists
         account->transport_ = transportMap_[account->getLocalPort()];
 
@@ -341,6 +345,10 @@ void SipTransport::createSipTransport(SIPAccount *account)
             account->setLocalPort(localUDPTransport_->local_name.port);
         }
     }
+
+    if(account->transport_ == NULL)
+        ERROR("SipTransport: Could not create transport on %s:%d",
+                              account->getLocalInterface().c_str(), account->getLocalPort());
 }
 
 void SipTransport::createDefaultSipUdpTransport()
@@ -408,15 +416,15 @@ SipTransport::createUdpTransport(const std::string &interface, unsigned int port
     pj_status_t status;
     pjsip_transport *transport = NULL;
     if (boundAddr.addr.sa_family == pj_AF_INET()) {
+        boundAddr.ipv4.sin_port = listeningPort;
         status = pjsip_udp_transport_start(endpt_, &boundAddr.ipv4, NULL, 1, &transport);
         if (status != PJ_SUCCESS) {
-            ERROR("Failed to create IPv4 UDP transport");
             return NULL;
         }
     } else if (boundAddr.addr.sa_family == pj_AF_INET6()) {
+        boundAddr.ipv6.sin6_port = listeningPort;
         status = pjsip_udp_transport_start6(endpt_, &boundAddr.ipv6, NULL, 1, &transport);
         if (status != PJ_SUCCESS) {
-            ERROR("Failed to create IPv6 UDP transport");
             return NULL;
         }
     }
diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp
index fcf77f5d1f..1a934665ef 100644
--- a/daemon/src/sip/sipvoiplink.cpp
+++ b/daemon/src/sip/sipvoiplink.cpp
@@ -195,42 +195,6 @@ pj_bool_t transaction_response_cb(pjsip_rx_data *rdata)
     return PJ_SUCCESS;
 }
 
-/*
-std::string parseDisplayName(const char * buffer)
-{
-    const char* from_header = strstr(buffer, "From: ");
-
-    if (!from_header)
-        return "";
-
-    std::string temp(from_header);
-    size_t begin_displayName = temp.find("\"") + 1;
-    size_t end_displayName = temp.rfind("\"");
-    std::string displayName(temp.substr(begin_displayName, end_displayName - begin_displayName));
-
-    static const size_t MAX_DISPLAY_NAME_SIZE = 25;
-    if (displayName.size() > MAX_DISPLAY_NAME_SIZE)
-        return "";
-
-    return displayName;
-}
-
-void stripSipUriPrefix(std::string& sipUri)
-{
-    // Remove sip: prefix
-    static const char SIP_PREFIX[] = "sip:";
-    size_t found = sipUri.find(SIP_PREFIX);
-
-    if (found != std::string::npos)
-        sipUri.erase(found, found + (sizeof SIP_PREFIX) - 1);
-
-    found = sipUri.find("@");
-
-    if (found != std::string::npos)
-        sipUri.erase(found);
-}
-*/
-
 pj_bool_t transaction_request_cb(pjsip_rx_data *rdata)
 {
     pjsip_method *method = &rdata->msg_info.msg->line.req.method;
-- 
GitLab