Ring Daemon
Loading...
Searching...
No Matches
datatransfer.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2026 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 "jamidht/jamiaccount.h"
22
23namespace libjami {
24
25void
26registerDataXferHandlers(const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>& handlers)
27{
28 registerSignalHandlers(handlers);
29}
30
31void
32sendFile(const std::string& accountId,
33 const std::string& conversationId,
34 const std::string& path,
35 const std::string& displayName,
36 const std::string& replyTo) noexcept
37{
38 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
39 acc->sendFile(conversationId, path, displayName, replyTo);
40 }
41}
42
43bool
44downloadFile(const std::string& accountId,
45 const std::string& conversationId,
46 const std::string& interactionId,
47 const std::string& fileId,
48 const std::string& path) noexcept
49{
50 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
51 if (auto* convModule = acc->convModule(true))
52 return convModule->downloadFile(conversationId, interactionId, fileId, path);
53 return {};
54}
55
57cancelDataTransfer(const std::string& accountId, const std::string& conversationId, const std::string& fileId) noexcept
58{
59 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
60 if (auto dt = acc->dataTransfer(conversationId))
61 return dt->cancel(fileId) ? libjami::DataTransferError::success
62 : libjami::DataTransferError::invalid_argument;
63 }
64 return libjami::DataTransferError::invalid_argument;
65}
66
68fileTransferInfo(const std::string& accountId,
69 const std::string& conversationId,
70 const std::string& fileId,
71 std::string& path,
72 int64_t& total,
73 int64_t& progress) noexcept
74{
75 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
76 if (auto dt = acc->dataTransfer(conversationId))
77 return dt->info(fileId, path, total, progress) ? libjami::DataTransferError::success
78 : libjami::DataTransferError::invalid_argument;
79 }
80 return libjami::DataTransferError::invalid_argument;
81}
82
83} // namespace libjami
static LIBJAMI_TEST_EXPORT Manager & instance()
Definition manager.cpp:694
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)