From 293662a71064440d0a4ebd912084fafbad465174 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Tue, 5 Jul 2022 12:16:22 -0400
Subject: [PATCH] proxyserver: cleanup, avoid ref-to-temporary

---
 include/opendht/dht_proxy_server.h |  2 +-
 src/dht_proxy_server.cpp           | 31 +++++++++++-------------------
 2 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/include/opendht/dht_proxy_server.h b/include/opendht/dht_proxy_server.h
index a68611e5..8615f816 100644
--- a/include/opendht/dht_proxy_server.h
+++ b/include/opendht/dht_proxy_server.h
@@ -276,7 +276,7 @@ private:
 
 #ifdef OPENDHT_PUSH_NOTIFICATIONS
     PushType getTypeFromString(const std::string& type);
-    const std::string& getDefaultTopic(PushType type);
+    std::string getDefaultTopic(PushType type);
     /**
      * Subscribe to push notifications for an iOS or Android device.
      * Method: SUBSCRIBE "/{InfoHash: .*}"
diff --git a/src/dht_proxy_server.cpp b/src/dht_proxy_server.cpp
index d20f49c7..fcab0b22 100644
--- a/src/dht_proxy_server.cpp
+++ b/src/dht_proxy_server.cpp
@@ -748,30 +748,23 @@ DhtProxyServer::listen(restinio::request_handle_t request,
 
 PushType
 DhtProxyServer::getTypeFromString(const std::string& type) {
-    if (type == "android") {
+    if (type == "android")
         return PushType::Android;
-    }
-    if (type == "apple") {
-        // proxy_client is not updated or using ios < 14.5
-        return PushType::iOSLegacy;
-    }
-    if (type == "ios") {
+    else if (type == "ios")
         return PushType::iOS;
-    }
+    else if (type == "apple")
+        return PushType::iOSLegacy; // proxy_client is not updated or using ios < 14.5
     return PushType::None;
 }
 
-const std::string&
+std::string
 DhtProxyServer::getDefaultTopic(PushType type) {
-    if (bundleId_.empty()) {
+    if (bundleId_.empty())
         return {};
-    }
-    if (type == PushType::iOSLegacy) {
-        return bundleId_  + ".voip";
-    }
-    if (type == PushType::iOS) {
+    if (type == PushType::iOS)
         return bundleId_;
-    }
+    else if (type == PushType::iOSLegacy)
+        return bundleId_  + ".voip";
     return {};
 }
 
@@ -1201,14 +1194,12 @@ DhtProxyServer::put(restinio::request_handle_t request,
                     // cancel permanent put
                     pput.expireTimer = std::make_unique<asio::steady_timer>(ctx, timeout);
 #ifdef OPENDHT_PUSH_NOTIFICATIONS
-                    if (not pushToken.empty()){
-                        bool isAndroid = platform == "android";
+                    if (not pushToken.empty()) {
                         pput.pushToken = pushToken;
                         pput.clientId = clientId;
                         pput.type = getTypeFromString(platform);
-                        if (topic.empty()) {
+                        if (topic.empty())
                             topic = getDefaultTopic(pput.type);
-                        }
                         pput.topic = topic;
                         pput.sessionCtx = std::make_shared<PushSessionContext>(sessionId);
                         // notify push listen expire
-- 
GitLab