diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp index 015f54959f9b9dfcba8a21bb79e02e486a26b6ea..e91d613e27e84beaf09623a1c9ba307788c58017 100644 --- a/src/jamidht/jamiaccount.cpp +++ b/src/jamidht/jamiaccount.cpp @@ -108,9 +108,6 @@ constexpr pj_str_t STR_MESSAGE_ID = jami::sip_utils::CONST_PJ_STR("Message-ID"); static constexpr const char MIME_TYPE_IMDN[] {"message/imdn+xml"}; static constexpr const char MIME_TYPE_IM_COMPOSING[] {"application/im-iscomposing+xml"}; static constexpr const char MIME_TYPE_INVITE_JSON[] {"application/invite+json"}; -static constexpr const char FILE_URI[] {"file://"}; -static constexpr const char VCARD_URI[] {"vcard://"}; -static constexpr const char DATA_TRANSFER_URI[] {"data-transfer://"}; static constexpr const char DEVICE_ID_PATH[] {"ring_device"}; static constexpr std::chrono::steady_clock::duration COMPOSING_TIMEOUT {std::chrono::seconds(12)}; static constexpr auto TREATED_PATH = "treatedImMessages"; @@ -3693,9 +3690,10 @@ JamiAccount::sendProfile(const std::string& convId, const std::string& peerUri, const std::string& deviceId) { - if (not std::filesystem::is_regular_file(profilePath())) + auto accProfilePath = profilePath(); + if (not std::filesystem::is_regular_file(accProfilePath)) return; - auto currentSha3 = fileutils::sha3File(profilePath()); + auto currentSha3 = fileutils::sha3File(accProfilePath); // VCard sync for peerUri if (not needToSendProfile(peerUri, deviceId, currentSha3)) { JAMI_DEBUG("Peer {} already got an up-to-date vcard", peerUri); @@ -3703,14 +3701,14 @@ JamiAccount::sendProfile(const std::string& convId, } // We need a new channel transferFile(convId, - profilePath().string(), + accProfilePath.string(), deviceId, "profile.vcf", "", 0, 0, currentSha3, - fileutils::lastWriteTimeInSeconds(profilePath()), + fileutils::lastWriteTimeInSeconds(accProfilePath), [accId = getAccountID(), peerUri, deviceId]() { // Mark the VCard as sent auto sendDir = fileutils::get_cache_dir() / accId / "vcard" / peerUri; @@ -4082,8 +4080,8 @@ JamiAccount::transferFile(const std::string& conversationId, fmt::format("profile.vcf?sha3={}{}", sha3Sum, modified) : fileId; auto channelName = conversationId.empty() - ? fmt::format("{}profile.vcf?sha3={}{}", DATA_TRANSFER_URI, sha3Sum, modified) - : fmt::format("{}{}/{}/{}", DATA_TRANSFER_URI, conversationId, currentDeviceId(), fid); + ? fmt::format("{}profile.vcf?sha3={}{}", DATA_TRANSFER_SCHEME, sha3Sum, modified) + : fmt::format("{}{}/{}/{}", DATA_TRANSFER_SCHEME, conversationId, currentDeviceId(), fid); std::lock_guard<std::mutex> lkCM(connManagerMtx_); if (!connectionManager_) return; @@ -4137,7 +4135,7 @@ JamiAccount::askForFileChannel(const std::string& conversationId, return; auto channelName = fmt::format("{}{}/{}/{}", - DATA_TRANSFER_URI, + DATA_TRANSFER_SCHEME, conversationId, currentDeviceId(), fileId); @@ -4196,7 +4194,7 @@ JamiAccount::askForProfile(const std::string& conversationId, return; auto channelName = fmt::format("{}{}/profile/{}.vcf", - DATA_TRANSFER_URI, + DATA_TRANSFER_SCHEME, conversationId, memberUri); // We can avoid to negotiate new sessions, as the file notif diff --git a/src/jamidht/transfer_channel_handler.cpp b/src/jamidht/transfer_channel_handler.cpp index bb5373d1eb78702c69756a3cbe6c362b15e87b7b..172fd47cfd1ddf5889312b3408ec3e926a0f926e 100644 --- a/src/jamidht/transfer_channel_handler.cpp +++ b/src/jamidht/transfer_channel_handler.cpp @@ -53,7 +53,7 @@ TransferChannelHandler::onRequest(const std::shared_ptr<dht::crypto::Certificate return false; auto uri = cert->issuer->getId().toString(); // Else, check if it's a profile or file in a conversation. - auto idstr = std::string_view(name).substr(16); + auto idstr = std::string_view(name).substr(DATA_TRANSFER_SCHEME.size()); // Remove arguments for now auto sep = idstr.find_last_of('?'); idstr = idstr.substr(0, sep); @@ -95,7 +95,8 @@ TransferChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>& if (!acc) return; - auto idstr = name.substr(16); + // Remove scheme + auto idstr = name.substr(DATA_TRANSFER_SCHEME.size()); // Parse arguments auto sep = idstr.find_last_of('?'); std::string arguments; diff --git a/src/uri.cpp b/src/uri.cpp index 2b2a4077a48ff10f32ee57267e912fcc6a1778e8..eb98d5966bc6965245980ab3fd1a3fc035b0bf09 100644 --- a/src/uri.cpp +++ b/src/uri.cpp @@ -21,7 +21,7 @@ namespace jami { -Uri::Uri(const std::string_view& uri) +Uri::Uri(std::string_view uri) { // TODO better handling of Uri, for now it's only used for // setMessageDisplayed to differentiate swarm:xxx diff --git a/src/uri.h b/src/uri.h index 118b952d7ea881056137c65c78080128832a6d43..3027210ed812964801e9e44523086156dc9fd8e2 100644 --- a/src/uri.h +++ b/src/uri.h @@ -24,6 +24,10 @@ namespace jami { +using namespace std::string_view_literals; + +static constexpr std::string_view DATA_TRANSFER_SCHEME = "data-transfer://"sv; + class Uri { public: @@ -38,7 +42,7 @@ public: UNRECOGNIZED // Anything that doesn't fit in other categories }; - Uri(const std::string_view& uri); + Uri(std::string_view uri); const std::string& authority() const; Scheme scheme() const;