2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2009-2023 Mnemosyne LLC.
|
2022-02-07 16:25:02 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2007-12-21 16:51:42 +00:00
|
|
|
|
2021-12-26 16:25:07 +00:00
|
|
|
#include <cerrno> // EINVAL
|
2023-07-08 15:24:03 +00:00
|
|
|
#include <cstddef> // size_t
|
|
|
|
#include <cstdint> //uint16_t
|
2021-11-05 03:08:38 +00:00
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
2022-01-13 02:13:58 +00:00
|
|
|
#include <string_view>
|
2022-08-17 16:08:36 +00:00
|
|
|
#include <utility>
|
2021-11-05 03:08:38 +00:00
|
|
|
#include <vector>
|
2014-07-08 00:08:43 +00:00
|
|
|
|
2023-04-14 19:33:23 +00:00
|
|
|
#include "libtransmission/transmission.h"
|
|
|
|
|
|
|
|
#include "libtransmission/error.h"
|
2023-07-08 15:24:03 +00:00
|
|
|
#include "libtransmission/quark.h"
|
2023-04-14 19:33:23 +00:00
|
|
|
#include "libtransmission/session.h"
|
|
|
|
#include "libtransmission/torrent-metainfo.h"
|
|
|
|
#include "libtransmission/torrent.h"
|
|
|
|
#include "libtransmission/tr-assert.h"
|
|
|
|
#include "libtransmission/utils.h"
|
2007-12-21 16:51:42 +00:00
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
using namespace std::literals;
|
|
|
|
|
2023-01-27 20:25:08 +00:00
|
|
|
namespace
|
|
|
|
{
|
2007-12-21 16:51:42 +00:00
|
|
|
struct optional_args
|
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
std::optional<bool> paused;
|
|
|
|
std::optional<uint16_t> peer_limit;
|
|
|
|
std::string download_dir;
|
2007-12-21 16:51:42 +00:00
|
|
|
};
|
2023-01-27 20:25:08 +00:00
|
|
|
} // namespace
|
2007-12-21 16:51:42 +00:00
|
|
|
|
2008-05-23 20:04:41 +00:00
|
|
|
/** Opaque class used when instantiating torrents.
|
2008-09-23 19:11:04 +00:00
|
|
|
* @ingroup tr_ctor */
|
2007-12-21 16:51:42 +00:00
|
|
|
struct tr_ctor
|
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
tr_session const* const session;
|
|
|
|
std::optional<bool> delete_source;
|
|
|
|
|
2021-12-26 16:25:07 +00:00
|
|
|
tr_torrent_metainfo metainfo = {};
|
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
tr_priority_t priority = TR_PRI_NORMAL;
|
|
|
|
|
2022-08-25 01:19:21 +00:00
|
|
|
tr_torrent::labels_t labels{};
|
2022-02-03 06:02:30 +00:00
|
|
|
|
2022-08-25 01:19:21 +00:00
|
|
|
std::array<struct optional_args, 2> optional_args{};
|
2021-11-05 03:08:38 +00:00
|
|
|
|
|
|
|
std::string incomplete_dir;
|
2021-12-26 16:25:07 +00:00
|
|
|
std::string torrent_filename;
|
2021-11-05 03:08:38 +00:00
|
|
|
|
2021-11-29 01:12:54 +00:00
|
|
|
std::vector<tr_file_index_t> wanted;
|
|
|
|
std::vector<tr_file_index_t> unwanted;
|
2021-11-05 03:08:38 +00:00
|
|
|
std::vector<tr_file_index_t> low;
|
|
|
|
std::vector<tr_file_index_t> normal;
|
|
|
|
std::vector<tr_file_index_t> high;
|
|
|
|
|
2021-11-16 06:15:13 +00:00
|
|
|
std::vector<char> contents;
|
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
explicit tr_ctor(tr_session const* session_in)
|
|
|
|
: session{ session_in }
|
|
|
|
{
|
|
|
|
}
|
2007-12-21 16:51:42 +00:00
|
|
|
};
|
|
|
|
|
2023-01-07 22:55:00 +00:00
|
|
|
// ---
|
2007-12-21 16:51:42 +00:00
|
|
|
|
2022-05-31 15:53:46 +00:00
|
|
|
bool tr_ctorSetMetainfoFromFile(tr_ctor* ctor, std::string_view filename, tr_error** error)
|
2008-02-13 02:24:12 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
if (std::empty(filename))
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2021-12-28 02:32:22 +00:00
|
|
|
tr_error_set(error, EINVAL, "no filename specified"sv);
|
2021-12-26 16:25:07 +00:00
|
|
|
return false;
|
2007-12-21 16:51:42 +00:00
|
|
|
}
|
2008-02-13 02:24:12 +00:00
|
|
|
|
2023-06-30 14:49:58 +00:00
|
|
|
if (!tr_file_read(filename, ctor->contents, error))
|
2021-12-26 16:25:07 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2007-12-21 16:51:42 +00:00
|
|
|
|
2022-01-18 05:14:00 +00:00
|
|
|
ctor->torrent_filename = filename;
|
2021-12-26 16:25:07 +00:00
|
|
|
auto const contents_sv = std::string_view{ std::data(ctor->contents), std::size(ctor->contents) };
|
2023-04-23 01:25:55 +00:00
|
|
|
return ctor->metainfo.parse_benc(contents_sv, error);
|
2021-11-18 05:37:35 +00:00
|
|
|
}
|
|
|
|
|
2022-01-15 19:33:57 +00:00
|
|
|
bool tr_ctorSetMetainfoFromFile(tr_ctor* ctor, char const* filename, tr_error** error)
|
|
|
|
{
|
2022-08-20 20:57:32 +00:00
|
|
|
return tr_ctorSetMetainfoFromFile(ctor, std::string_view{ filename != nullptr ? filename : "" }, error);
|
2022-01-15 19:33:57 +00:00
|
|
|
}
|
|
|
|
|
2021-12-26 16:25:07 +00:00
|
|
|
bool tr_ctorSetMetainfo(tr_ctor* ctor, char const* metainfo, size_t len, tr_error** error)
|
2007-12-21 16:51:42 +00:00
|
|
|
{
|
2022-01-18 05:14:00 +00:00
|
|
|
ctor->torrent_filename.clear();
|
2021-12-05 01:32:35 +00:00
|
|
|
ctor->contents.assign(metainfo, metainfo + len);
|
2021-12-26 16:25:07 +00:00
|
|
|
auto const contents_sv = std::string_view{ std::data(ctor->contents), std::size(ctor->contents) };
|
2023-04-23 01:25:55 +00:00
|
|
|
return ctor->metainfo.parse_benc(contents_sv, error);
|
2007-12-21 16:51:42 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 15:53:46 +00:00
|
|
|
bool tr_ctorSetMetainfoFromMagnetLink(tr_ctor* ctor, std::string_view magnet_link, tr_error** error)
|
2008-02-13 02:24:12 +00:00
|
|
|
{
|
2022-01-18 05:14:00 +00:00
|
|
|
ctor->torrent_filename.clear();
|
2022-04-01 20:28:55 +00:00
|
|
|
ctor->metainfo = {};
|
2022-05-31 15:53:46 +00:00
|
|
|
return ctor->metainfo.parseMagnet(magnet_link, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool tr_ctorSetMetainfoFromMagnetLink(tr_ctor* ctor, char const* magnet_link, tr_error** error)
|
|
|
|
{
|
|
|
|
return tr_ctorSetMetainfoFromMagnetLink(ctor, std::string_view{ magnet_link != nullptr ? magnet_link : "" }, error);
|
2008-02-13 02:24:12 +00:00
|
|
|
}
|
|
|
|
|
2021-12-26 16:25:07 +00:00
|
|
|
char const* tr_ctorGetSourceFile(tr_ctor const* ctor)
|
2007-12-21 16:51:42 +00:00
|
|
|
{
|
2022-01-18 05:14:00 +00:00
|
|
|
return ctor->torrent_filename.c_str();
|
2007-12-21 16:51:42 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 22:13:32 +00:00
|
|
|
bool tr_ctorSaveContents(tr_ctor const* ctor, std::string_view filename, tr_error** error)
|
2021-12-05 01:32:35 +00:00
|
|
|
{
|
|
|
|
TR_ASSERT(ctor != nullptr);
|
2021-12-24 19:37:34 +00:00
|
|
|
TR_ASSERT(!std::empty(filename));
|
2021-12-05 01:32:35 +00:00
|
|
|
|
|
|
|
if (std::empty(ctor->contents))
|
|
|
|
{
|
2021-12-28 02:32:22 +00:00
|
|
|
tr_error_set(error, EINVAL, "torrent ctor has no contents to save"sv);
|
2021-12-05 01:32:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-30 14:49:58 +00:00
|
|
|
return tr_file_save(filename, ctor->contents, error);
|
2021-12-05 01:32:35 +00:00
|
|
|
}
|
|
|
|
|
2023-01-07 22:55:00 +00:00
|
|
|
// ---
|
2007-12-21 16:51:42 +00:00
|
|
|
|
2022-09-07 16:04:28 +00:00
|
|
|
void tr_ctorSetFilePriorities(tr_ctor* ctor, tr_file_index_t const* files, tr_file_index_t file_count, tr_priority_t priority)
|
2009-04-02 20:43:42 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
switch (priority)
|
|
|
|
{
|
|
|
|
case TR_PRI_LOW:
|
2022-09-07 16:04:28 +00:00
|
|
|
ctor->low.assign(files, files + file_count);
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_PRI_HIGH:
|
2022-09-07 16:04:28 +00:00
|
|
|
ctor->high.assign(files, files + file_count);
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
default: // TR_PRI_NORMAL
|
2022-09-07 16:04:28 +00:00
|
|
|
ctor->normal.assign(files, files + file_count);
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
2009-04-02 20:43:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_ctorInitTorrentPriorities(tr_ctor const* ctor, tr_torrent* tor)
|
2009-04-02 20:43:42 +00:00
|
|
|
{
|
2023-04-23 01:25:55 +00:00
|
|
|
tor->set_file_priorities(std::data(ctor->low), std::size(ctor->low), TR_PRI_LOW);
|
|
|
|
tor->set_file_priorities(std::data(ctor->normal), std::size(ctor->normal), TR_PRI_NORMAL);
|
|
|
|
tor->set_file_priorities(std::data(ctor->high), std::size(ctor->high), TR_PRI_HIGH);
|
2009-04-02 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 16:04:28 +00:00
|
|
|
void tr_ctorSetFilesWanted(tr_ctor* ctor, tr_file_index_t const* files, tr_file_index_t file_count, bool wanted)
|
2009-04-02 20:43:42 +00:00
|
|
|
{
|
2021-11-29 01:12:54 +00:00
|
|
|
auto& indices = wanted ? ctor->wanted : ctor->unwanted;
|
2022-09-07 16:04:28 +00:00
|
|
|
indices.assign(files, files + file_count);
|
2009-04-02 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_ctorInitTorrentWanted(tr_ctor const* ctor, tr_torrent* tor)
|
2009-04-02 20:43:42 +00:00
|
|
|
{
|
2023-04-23 01:25:55 +00:00
|
|
|
tor->init_files_wanted(std::data(ctor->unwanted), std::size(ctor->unwanted), false);
|
|
|
|
tor->init_files_wanted(std::data(ctor->wanted), std::size(ctor->wanted), true);
|
2009-04-02 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
2023-01-07 22:55:00 +00:00
|
|
|
// ---
|
2009-04-02 20:43:42 +00:00
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
void tr_ctorSetDeleteSource(tr_ctor* ctor, bool delete_source)
|
2008-02-13 02:24:12 +00:00
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
ctor->delete_source = delete_source;
|
2008-02-13 02:24:12 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool tr_ctorGetDeleteSource(tr_ctor const* ctor, bool* setme)
|
2008-02-13 02:24:12 +00:00
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
auto const& delete_source = ctor->delete_source;
|
|
|
|
if (!delete_source)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
return false;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2008-02-13 02:24:12 +00:00
|
|
|
|
2021-11-07 23:35:32 +00:00
|
|
|
if (setme != nullptr)
|
|
|
|
{
|
|
|
|
*setme = *delete_source;
|
|
|
|
}
|
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
return true;
|
2008-02-13 02:24:12 +00:00
|
|
|
}
|
|
|
|
|
2023-01-07 22:55:00 +00:00
|
|
|
// ---
|
2008-02-13 02:24:12 +00:00
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
void tr_ctorSetPaused(tr_ctor* ctor, tr_ctorMode mode, bool paused)
|
2007-12-21 16:51:42 +00:00
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
TR_ASSERT(ctor != nullptr);
|
2017-06-08 07:24:12 +00:00
|
|
|
TR_ASSERT(mode == TR_FALLBACK || mode == TR_FORCE);
|
2013-08-24 18:08:38 +00:00
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
ctor->optional_args[mode].paused = paused;
|
2007-12-21 16:51:42 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
void tr_ctorSetPeerLimit(tr_ctor* ctor, tr_ctorMode mode, uint16_t peer_limit)
|
2007-12-21 16:51:42 +00:00
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
TR_ASSERT(ctor != nullptr);
|
2017-06-08 07:24:12 +00:00
|
|
|
TR_ASSERT(mode == TR_FALLBACK || mode == TR_FORCE);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
ctor->optional_args[mode].peer_limit = peer_limit;
|
2007-12-21 16:51:42 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_ctorSetDownloadDir(tr_ctor* ctor, tr_ctorMode mode, char const* directory)
|
2007-12-21 16:51:42 +00:00
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
TR_ASSERT(ctor != nullptr);
|
2017-06-08 07:24:12 +00:00
|
|
|
TR_ASSERT(mode == TR_FALLBACK || mode == TR_FORCE);
|
2013-08-24 18:08:38 +00:00
|
|
|
|
2022-02-07 04:28:36 +00:00
|
|
|
ctor->optional_args[mode].download_dir.assign(directory != nullptr ? directory : "");
|
2007-12-21 16:51:42 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_ctorSetIncompleteDir(tr_ctor* ctor, char const* directory)
|
2009-10-21 05:03:10 +00:00
|
|
|
{
|
2022-02-07 04:28:36 +00:00
|
|
|
ctor->incomplete_dir.assign(directory != nullptr ? directory : "");
|
2009-10-21 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
bool tr_ctorGetPeerLimit(tr_ctor const* ctor, tr_ctorMode mode, uint16_t* setme)
|
2007-12-21 16:51:42 +00:00
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
auto const& peer_limit = ctor->optional_args[mode].peer_limit;
|
|
|
|
if (!peer_limit)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
return false;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2007-12-21 22:18:40 +00:00
|
|
|
|
2021-11-07 23:35:32 +00:00
|
|
|
if (setme != nullptr)
|
|
|
|
{
|
|
|
|
*setme = *peer_limit;
|
|
|
|
}
|
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
return true;
|
2007-12-21 16:51:42 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
bool tr_ctorGetPaused(tr_ctor const* ctor, tr_ctorMode mode, bool* setme)
|
2007-12-21 16:51:42 +00:00
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
auto const& paused = ctor->optional_args[mode].paused;
|
|
|
|
if (!paused)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
return false;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2007-12-21 22:18:40 +00:00
|
|
|
|
2021-11-07 23:35:32 +00:00
|
|
|
if (setme != nullptr)
|
|
|
|
{
|
|
|
|
*setme = *paused;
|
|
|
|
}
|
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
return true;
|
2007-12-21 16:51:42 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
bool tr_ctorGetDownloadDir(tr_ctor const* ctor, tr_ctorMode mode, char const** setme)
|
2007-12-21 16:51:42 +00:00
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
auto const& str = ctor->optional_args[mode].download_dir;
|
|
|
|
if (std::empty(str))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
return false;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2007-12-21 22:18:40 +00:00
|
|
|
|
2021-11-07 23:35:32 +00:00
|
|
|
if (setme != nullptr)
|
|
|
|
{
|
|
|
|
*setme = str.c_str();
|
|
|
|
}
|
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
return true;
|
2007-12-21 16:51:42 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
bool tr_ctorGetIncompleteDir(tr_ctor const* ctor, char const** setme)
|
2009-10-21 05:03:10 +00:00
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
auto const& str = ctor->incomplete_dir;
|
|
|
|
if (std::empty(str))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
return false;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-10-21 05:03:10 +00:00
|
|
|
|
2021-11-07 23:35:32 +00:00
|
|
|
if (setme != nullptr)
|
|
|
|
{
|
|
|
|
*setme = str.c_str();
|
|
|
|
}
|
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
return true;
|
2009-10-21 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
2022-04-01 20:28:55 +00:00
|
|
|
tr_torrent_metainfo tr_ctorStealMetainfo(tr_ctor* ctor)
|
2022-01-15 19:33:57 +00:00
|
|
|
{
|
2022-04-01 20:28:55 +00:00
|
|
|
auto metainfo = tr_torrent_metainfo{};
|
|
|
|
std::swap(ctor->metainfo, metainfo);
|
|
|
|
return metainfo;
|
2022-01-15 19:33:57 +00:00
|
|
|
}
|
|
|
|
|
2021-12-26 16:25:07 +00:00
|
|
|
tr_torrent_metainfo const* tr_ctorGetMetainfo(tr_ctor const* ctor)
|
2007-12-21 16:51:42 +00:00
|
|
|
{
|
2023-04-23 01:25:55 +00:00
|
|
|
return !std::empty(ctor->metainfo.info_hash_string()) ? &ctor->metainfo : nullptr;
|
2007-12-21 22:18:40 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_session* tr_ctorGetSession(tr_ctor const* ctor)
|
2009-04-02 17:30:29 +00:00
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
return const_cast<tr_session*>(ctor->session);
|
2009-04-02 17:30:29 +00:00
|
|
|
}
|
|
|
|
|
2023-01-07 22:55:00 +00:00
|
|
|
// ---
|
2010-02-02 07:48:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_ctorSetBandwidthPriority(tr_ctor* ctor, tr_priority_t priority)
|
2010-02-02 07:48:03 +00:00
|
|
|
{
|
2023-01-07 22:55:00 +00:00
|
|
|
if (priority != TR_PRI_LOW && priority != TR_PRI_NORMAL && priority != TR_PRI_HIGH)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2023-01-07 22:55:00 +00:00
|
|
|
return;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2023-01-07 22:55:00 +00:00
|
|
|
|
|
|
|
ctor->priority = priority;
|
2010-02-02 07:48:03 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_priority_t tr_ctorGetBandwidthPriority(tr_ctor const* ctor)
|
2010-02-02 07:48:03 +00:00
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
return ctor->priority;
|
2010-02-02 07:48:03 +00:00
|
|
|
}
|
|
|
|
|
2023-01-07 22:55:00 +00:00
|
|
|
// ---
|
2010-02-02 07:48:03 +00:00
|
|
|
|
2022-04-18 05:53:48 +00:00
|
|
|
void tr_ctorSetLabels(tr_ctor* ctor, tr_quark const* labels, size_t n_labels)
|
2022-02-03 06:02:30 +00:00
|
|
|
{
|
2022-04-18 05:53:48 +00:00
|
|
|
ctor->labels = { labels, labels + n_labels };
|
2022-02-03 06:02:30 +00:00
|
|
|
}
|
|
|
|
|
2022-04-18 05:53:48 +00:00
|
|
|
tr_torrent::labels_t const& tr_ctorGetLabels(tr_ctor const* ctor)
|
2022-02-03 06:02:30 +00:00
|
|
|
{
|
|
|
|
return ctor->labels;
|
|
|
|
}
|
|
|
|
|
2023-01-07 22:55:00 +00:00
|
|
|
// ---
|
2022-02-03 06:02:30 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_ctor* tr_ctorNew(tr_session const* session)
|
2007-12-21 22:18:40 +00:00
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
auto* const ctor = new tr_ctor{ session };
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-08-14 01:04:36 +00:00
|
|
|
tr_ctorSetDeleteSource(ctor, session->shouldDeleteSource());
|
|
|
|
tr_ctorSetPaused(ctor, TR_FALLBACK, session->shouldPauseAddedTorrents());
|
2022-08-13 22:41:42 +00:00
|
|
|
tr_ctorSetPeerLimit(ctor, TR_FALLBACK, session->peerLimitPerTorrent());
|
2021-12-26 16:25:07 +00:00
|
|
|
tr_ctorSetDownloadDir(ctor, TR_FALLBACK, tr_sessionGetDownloadDir(session));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2007-12-21 22:18:40 +00:00
|
|
|
return ctor;
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_ctorFree(tr_ctor* ctor)
|
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
delete ctor;
|
2007-12-21 16:51:42 +00:00
|
|
|
}
|