Ring Daemon 16.0.0
Loading...
Searching...
No Matches
datatransfer.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
19
20#include "manager.h"
21#include "data_transfer.h"
22#include "client/ring_signal.h"
23#include "jamidht/jamiaccount.h"
24
25namespace libjami {
26
27void
28registerDataXferHandlers(const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>& handlers)
29{
30 registerSignalHandlers(handlers);
31}
32
33void
34sendFile(const std::string& accountId,
35 const std::string& conversationId,
36 const std::string& path,
37 const std::string& displayName,
38 const std::string& replyTo) noexcept
39{
40 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
41 acc->sendFile(conversationId, path, displayName, replyTo);
42 }
43}
44
45bool
46downloadFile(const std::string& accountId,
47 const std::string& conversationId,
48 const std::string& interactionId,
49 const std::string& fileId,
50 const std::string& path) noexcept
51{
52 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
53 if (auto convModule = acc->convModule(true))
54 return convModule->downloadFile(conversationId, interactionId, fileId, path);
55 return {};
56}
57
59cancelDataTransfer(const std::string& accountId,
60 const std::string& conversationId,
61 const std::string& fileId) noexcept
62{
63 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
64 if (auto dt = acc->dataTransfer(conversationId))
65 return dt->cancel(fileId) ? libjami::DataTransferError::success
66 : libjami::DataTransferError::invalid_argument;
67 }
68 return libjami::DataTransferError::invalid_argument;
69}
70
72fileTransferInfo(const std::string& accountId,
73 const std::string& conversationId,
74 const std::string& fileId,
75 std::string& path,
76 int64_t& total,
77 int64_t& progress) noexcept
78{
79 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
80 if (auto dt = acc->dataTransfer(conversationId))
81 return dt->info(fileId, path, total, progress)
82 ? libjami::DataTransferError::success
83 : libjami::DataTransferError::invalid_argument;
84 }
85 return libjami::DataTransferError::invalid_argument;
86}
87
88} // namespace libjami
static LIBJAMI_TEST_EXPORT Manager & instance()
Definition manager.cpp:676
enum LIBJAMI_PUBLIC enum LIBJAMI_PUBLIC DataTransferError
DataTransferError cancelDataTransfer(const std::string &accountId, const std::string &conversationId, const std::string &fileId) noexcept
Refuse or abort an outgoing or an incoming file transfer.
DataTransferError fileTransferInfo(const std::string &accountId, const std::string &conversationId, const std::string &fileId, std::string &path, int64_t &total, int64_t &progress) noexcept
Return the amount of sent/received bytes of an existing data transfer.
void sendFile(const std::string &accountId, const std::string &conversationId, const std::string &path, const std::string &displayName, const std::string &replyTo) noexcept
Asynchronously send a file to a peer using given account connection.
bool downloadFile(const std::string &accountId, const std::string &conversationId, const std::string &interactionId, const std::string &fileId, const std::string &path) noexcept
Asks for retransferring a file.
void registerSignalHandlers(const std::map< std::string, std::shared_ptr< CallbackWrapperBase > > &handlers)
void registerDataXferHandlers(const std::map< std::string, std::shared_ptr< CallbackWrapperBase > > &handlers)