From 9a6e22e6fadae06f425f36b15a24669f2ecb7d36 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Tue, 23 May 2023 09:41:39 -0400
Subject: [PATCH] misc: cleanup some unused code and code smells

Change-Id: I157118c875868aa1cae7d0b0ea02644175d33b70
---
 src/client/configurationmanager.cpp     |  1 -
 src/connectivity/ice_transport.cpp      | 37 -------------------------
 src/connectivity/ice_transport.h        |  7 -----
 src/connectivity/security/certstore.cpp |  6 ++--
 src/jamidht/swarm/routing_table.cpp     |  4 +--
 src/jamidht/swarm/routing_table.h       |  4 +--
 src/media/media_attribute.cpp           |  2 +-
 src/sip/sipaccount.cpp                  | 10 ++++---
 8 files changed, 14 insertions(+), 57 deletions(-)

diff --git a/src/client/configurationmanager.cpp b/src/client/configurationmanager.cpp
index a5fc3afba3..75fe81c85d 100644
--- a/src/client/configurationmanager.cpp
+++ b/src/client/configurationmanager.cpp
@@ -71,7 +71,6 @@ constexpr unsigned CODECS_NOT_LOADED = 0x1000; /** Codecs not found */
 using jami::SIPAccount;
 using jami::JamiAccount;
 using jami::tls::TlsValidator;
-using jami::tls::CertificateStore;
 using jami::AudioDeviceType;
 
 void
diff --git a/src/connectivity/ice_transport.cpp b/src/connectivity/ice_transport.cpp
index ecd0ae1fb8..4fb2863009 100644
--- a/src/connectivity/ice_transport.cpp
+++ b/src/connectivity/ice_transport.cpp
@@ -1712,43 +1712,6 @@ IceTransport::waitForData(unsigned compId, std::chrono::milliseconds timeout, st
     return pimpl_->peerChannels_.at(compId - 1).wait(timeout, ec);
 }
 
-std::vector<SDP>
-IceTransport::parseSDPList(const std::vector<uint8_t>& msg)
-{
-    std::vector<SDP> sdp_list;
-
-    try {
-        size_t off = 0;
-        while (off != msg.size()) {
-            msgpack::unpacked result;
-            msgpack::unpack(result, (const char*) msg.data(), msg.size(), off);
-            SDP sdp;
-            if (result.get().type == msgpack::type::POSITIVE_INTEGER) {
-                // Version 1
-                msgpack::unpack(result, (const char*) msg.data(), msg.size(), off);
-                std::tie(sdp.ufrag, sdp.pwd) = result.get().as<std::pair<std::string, std::string>>();
-                msgpack::unpack(result, (const char*) msg.data(), msg.size(), off);
-                auto comp_cnt = result.get().as<uint8_t>();
-                while (comp_cnt-- > 0) {
-                    msgpack::unpack(result, (const char*) msg.data(), msg.size(), off);
-                    auto candidates = result.get().as<std::vector<std::string>>();
-                    sdp.candidates.reserve(sdp.candidates.size() + candidates.size());
-                    sdp.candidates.insert(sdp.candidates.end(),
-                                          candidates.begin(),
-                                          candidates.end());
-                }
-            } else {
-                result.get().convert(sdp);
-            }
-            sdp_list.emplace_back(std::move(sdp));
-        }
-    } catch (const msgpack::unpack_error& e) {
-        JAMI_WARN("Error parsing sdp: %s", e.what());
-    }
-
-    return sdp_list;
-}
-
 bool
 IceTransport::isTCPEnabled()
 {
diff --git a/src/connectivity/ice_transport.h b/src/connectivity/ice_transport.h
index ad5be7d42d..764b13751c 100644
--- a/src/connectivity/ice_transport.h
+++ b/src/connectivity/ice_transport.h
@@ -229,13 +229,6 @@ public:
     bool setSlaveSession();
     bool setInitiatorSession();
 
-    /**
-     * Get SDP messages list
-     * @param msg     The payload to parse
-     * @return the list of SDP messages
-     */
-    static std::vector<SDP> parseSDPList(const std::vector<uint8_t>& msg);
-
     bool isTCPEnabled();
 
     ICESDP parseIceCandidates(std::string_view sdp_msg);
diff --git a/src/connectivity/security/certstore.cpp b/src/connectivity/security/certstore.cpp
index 32762ea3ef..9aa8f6bd58 100644
--- a/src/connectivity/security/certstore.cpp
+++ b/src/connectivity/security/certstore.cpp
@@ -87,7 +87,7 @@ CertificateStore::loadRevocations(crypto::Certificate& crt) const
     for (const auto& crl : fileutils::readDirectory(dir)) {
         try {
             crt.addRevocationList(std::make_shared<crypto::RevocationList>(
-                fileutils::loadFile(dir + DIR_SEPARATOR_CH + crl)));
+                fileutils::loadFile(fmt::format("{}/{}", dir, crl))));
         } catch (const std::exception& e) {
             JAMI_WARN("Can't load revocation list: %s", e.what());
         }
@@ -95,7 +95,7 @@ CertificateStore::loadRevocations(crypto::Certificate& crt) const
     auto ocsp_dir = ocspPath_ + DIR_SEPARATOR_CH + crt.getId().toString();
     for (const auto& ocsp : fileutils::readDirectory(ocsp_dir)) {
         try {
-            std::string ocsp_filepath = ocsp_dir + DIR_SEPARATOR_CH + ocsp;
+            auto ocsp_filepath = fmt::format("{}/{}", ocsp_dir, ocsp);
             JAMI_DEBUG("Found {:s}", ocsp_filepath);
             auto serial = crt.getSerialNumber();
             if (dht::toHex(serial.data(), serial.size()) != ocsp)
@@ -236,7 +236,7 @@ readCertificates(const std::string& path, const std::string& crl_path)
     if (fileutils::isDirectory(path)) {
         auto files = fileutils::readDirectory(path);
         for (const auto& file : files) {
-            auto certs = readCertificates(path + DIR_SEPARATOR_CH + file, crl_path);
+            auto certs = readCertificates(fmt::format("{}/{}", path, file), crl_path);
             ret.insert(std::end(ret),
                        std::make_move_iterator(std::begin(certs)),
                        std::make_move_iterator(std::end(certs)));
diff --git a/src/jamidht/swarm/routing_table.cpp b/src/jamidht/swarm/routing_table.cpp
index 7211972a01..2082f3bedb 100644
--- a/src/jamidht/swarm/routing_table.cpp
+++ b/src/jamidht/swarm/routing_table.cpp
@@ -252,14 +252,14 @@ RoutingTable::RoutingTable()
 }
 
 bool
-RoutingTable::addNode(std::shared_ptr<ChannelSocketInterface> socket)
+RoutingTable::addNode(const std::shared_ptr<ChannelSocketInterface>& socket)
 {
     auto bucket = findBucket(socket->deviceId());
     return addNode(socket, bucket);
 }
 
 bool
-RoutingTable::addNode(std::shared_ptr<ChannelSocketInterface> channel,
+RoutingTable::addNode(const std::shared_ptr<ChannelSocketInterface>& channel,
                       std::list<Bucket>::iterator& bucket)
 {
     NodeId nodeId = channel->deviceId();
diff --git a/src/jamidht/swarm/routing_table.h b/src/jamidht/swarm/routing_table.h
index 3265b050d4..03f1ce36a1 100644
--- a/src/jamidht/swarm/routing_table.h
+++ b/src/jamidht/swarm/routing_table.h
@@ -315,7 +315,7 @@ public:
      * @param socket
      * @return true if socket was added, false if not
      */
-    bool addNode(std::shared_ptr<ChannelSocketInterface> socket);
+    bool addNode(const std::shared_ptr<ChannelSocketInterface>& socket);
 
     /**
      * Add socket to specific bucket
@@ -323,7 +323,7 @@ public:
      * @param bucket
      * @return true if socket was added to bucket, false if not
      */
-    bool addNode(std::shared_ptr<ChannelSocketInterface> channel,
+    bool addNode(const std::shared_ptr<ChannelSocketInterface>& channel,
                  std::list<Bucket>::iterator& bucket);
 
     /**
diff --git a/src/media/media_attribute.cpp b/src/media/media_attribute.cpp
index 2292d234d9..9a468fd86a 100644
--- a/src/media/media_attribute.cpp
+++ b/src/media/media_attribute.cpp
@@ -171,7 +171,7 @@ std::vector<libjami::MediaMap>
 MediaAttribute::mediaAttributesToMediaMaps(std::vector<MediaAttribute> mediaAttrList)
 {
     std::vector<libjami::MediaMap> mediaList;
-    mediaAttrList.reserve(mediaAttrList.size());
+    mediaList.reserve(mediaAttrList.size());
     for (auto const& media : mediaAttrList) {
         mediaList.emplace_back(toMediaMap(media));
     }
diff --git a/src/sip/sipaccount.cpp b/src/sip/sipaccount.cpp
index 08c005b892..ce3e95ed16 100644
--- a/src/sip/sipaccount.cpp
+++ b/src/sip/sipaccount.cpp
@@ -83,8 +83,6 @@
 
 namespace jami {
 
-using yaml_utils::parseValue;
-using yaml_utils::parseValueOptional;
 using sip_utils::CONST_PJ_STR;
 
 static constexpr unsigned REGISTRATION_FIRST_RETRY_INTERVAL = 60; // seconds
@@ -137,8 +135,12 @@ SIPAccount::SIPAccount(const std::string& accountID, bool presenceEnabled)
 SIPAccount::~SIPAccount() noexcept
 {
     // ensure that no registration callbacks survive past this point
-    destroyRegistrationInfo();
-    setTransport();
+    try {
+        destroyRegistrationInfo();
+        setTransport();
+    } catch (...) {
+        JAMI_ERR("Exception in SIPAccount destructor");
+    }
 
     delete presence_;
 }
-- 
GitLab