From 2a20afcfbeec4cf2ad5bb05d67aaa1beec0c9d5a Mon Sep 17 00:00:00 2001
From: philippegorley <philippe.gorley@savoirfairelinux.com>
Date: Mon, 11 Jun 2018 17:40:01 -0400
Subject: [PATCH] sipcall: add peer uri

For SIP accounts, peer uri contains a well formed sip uri. For Ring
accounts, contains "ring:username" if a registered name is found, else
"ring:ringid".

Change-Id: I55bc46e905adf4cf8fe8ea955a2f9cb13438de7e
---
 src/ringdht/ringaccount.cpp | 10 ++++++++--
 src/sip/sipaccount.cpp      |  1 +
 src/sip/sipcall.cpp         |  3 +--
 src/sip/sipcall.h           |  4 ++++
 src/sip/sipvoiplink.cpp     |  3 ++-
 5 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp
index de3da55e40..cb27592580 100644
--- a/src/ringdht/ringaccount.cpp
+++ b/src/ringdht/ringaccount.cpp
@@ -390,14 +390,17 @@ RingAccount::startOutgoingCall(const std::shared_ptr<SIPCall>& call, const std::
     setCertificateStatus(toUri, tls::TrustStore::PermissionStatus::ALLOWED);
 
     call->setPeerNumber(toUri + "@ring.dht");
+    call->setPeerUri(RING_URI_PREFIX + toUri);
     call->setState(Call::ConnectionState::TRYING);
     std::weak_ptr<SIPCall> wCall = call;
 
 #if HAVE_RINGNS
     nameDir_.get().lookupAddress(toUri, [wCall](const std::string& result, const NameDirectory::Response& response){
         if (response == NameDirectory::Response::found)
-            if (auto call = wCall.lock())
+            if (auto call = wCall.lock()) {
                 call->setPeerRegistredName(result);
+                call->setPeerUri(RING_URI_PREFIX + result);
+            }
     });
 #endif
 
@@ -2456,12 +2459,15 @@ RingAccount::replyToIncomingIceMsg(const std::shared_ptr<SIPCall>& call,
                                    const dht::InfoHash& from_id)
 {
     auto from = from_id.toString();
+    call->setPeerUri(RING_URI_PREFIX + from);
     std::weak_ptr<SIPCall> wcall = call;
 #if HAVE_RINGNS
     nameDir_.get().lookupAddress(from, [wcall](const std::string& result, const NameDirectory::Response& response){
         if (response == NameDirectory::Response::found)
-            if (auto call = wcall.lock())
+            if (auto call = wcall.lock()) {
                 call->setPeerRegistredName(result);
+                call->setPeerUri(RING_URI_PREFIX + result);
+            }
     });
 #endif
 
diff --git a/src/sip/sipaccount.cpp b/src/sip/sipaccount.cpp
index 7f94a6c8d5..217e714252 100644
--- a/src/sip/sipaccount.cpp
+++ b/src/sip/sipaccount.cpp
@@ -214,6 +214,7 @@ SIPAccount::newOutgoingCall(const std::string& toUrl,
     call->initIceMediaTransport(true);
     call->setIPToIP(isIP2IP());
     call->setPeerNumber(toUri);
+    call->setPeerUri(toUri);
     call->initRecFilename(to);
 
     const auto localAddress = ip_utils::getInterfaceAddr(getLocalInterface(), family);
diff --git a/src/sip/sipcall.cpp b/src/sip/sipcall.cpp
index 3c7e6e0b44..848536ad0b 100644
--- a/src/sip/sipcall.cpp
+++ b/src/sip/sipcall.cpp
@@ -1155,8 +1155,7 @@ SIPCall::toggleRecording()
     const bool startRecording = Call::toggleRecording();
     if (startRecording) {
         std::stringstream ss;
-        ss << "Ring call between " << getSIPAccount().getUserUri() << " and "
-            << (!peerRegistredName_.empty() ? peerRegistredName_ : getPeerNumber());
+        ss << "Ring call between " << getSIPAccount().getUserUri() << " and " << peerUri_;
         recorder_->setMetadata(ss.str(), ""); // use default description
         if (avformatrtp_)
             avformatrtp_->startRecorder(recorder_);
diff --git a/src/sip/sipcall.h b/src/sip/sipcall.h
index 01e2a04735..b40faf4ad3 100644
--- a/src/sip/sipcall.h
+++ b/src/sip/sipcall.h
@@ -209,6 +209,8 @@ public: // NOT SIP RELATED (good candidates to be moved elsewhere)
         peerRegistredName_ = name;
     }
 
+    void setPeerUri(const std::string peerUri) { peerUri_ = peerUri; }
+
     bool initIceMediaTransport(bool master, unsigned channel_num=4);
 
     bool isIceRunning() const;
@@ -294,6 +296,8 @@ private:
 
     ///< Temporary transport for media. Replace mediaTransport_ when connected with success
     std::shared_ptr<IceTransport> tmpMediaTransport_;
+
+    std::string peerUri_{};
 };
 
 // Helpers
diff --git a/src/sip/sipvoiplink.cpp b/src/sip/sipvoiplink.cpp
index 61997d8605..1a04416e8a 100644
--- a/src/sip/sipvoiplink.cpp
+++ b/src/sip/sipvoiplink.cpp
@@ -331,9 +331,10 @@ transaction_request_cb(pjsip_rx_data *rdata)
         }
     }
 
-    call->setState(Call::ConnectionState::PROGRESSING);
     call->setPeerNumber(peerNumber);
+    call->setPeerUri(account->getToUri(peerNumber));
     call->setPeerDisplayName(peerDisplayName);
+    call->setState(Call::ConnectionState::PROGRESSING);
     call->initRecFilename(peerNumber);
     call->getSDP().setPublishedIP(addrSdp);
 
-- 
GitLab