2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2009-2022 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
|
2021-11-05 03:08:38 +00:00
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
2022-01-13 02:13:58 +00:00
|
|
|
#include <string_view>
|
2021-11-05 03:08:38 +00:00
|
|
|
#include <vector>
|
2014-07-08 00:08:43 +00:00
|
|
|
|
2007-12-21 16:51:42 +00:00
|
|
|
#include "transmission.h"
|
2021-12-05 01:32:35 +00:00
|
|
|
|
|
|
|
#include "error.h"
|
2021-12-26 16:25:07 +00:00
|
|
|
#include "error-types.h"
|
2021-11-10 02:42:18 +00:00
|
|
|
#include "magnet-metainfo.h"
|
2021-11-08 02:04:07 +00:00
|
|
|
#include "session.h"
|
2021-12-26 16:25:07 +00:00
|
|
|
#include "torrent-metainfo.h"
|
|
|
|
#include "torrent.h"
|
2017-06-08 07:24:12 +00:00
|
|
|
#include "tr-assert.h"
|
2021-12-26 16:25:07 +00:00
|
|
|
#include "utils.h"
|
2012-12-14 04:34:42 +00:00
|
|
|
#include "variant.h"
|
2007-12-21 16:51:42 +00:00
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
using namespace std::literals;
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
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-02-03 06:02:30 +00:00
|
|
|
tr_labels_t labels = {};
|
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
struct optional_args optional_args[2];
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2007-12-21 22:18:40 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
2007-12-21 16:51:42 +00:00
|
|
|
|
2022-01-15 19:33:57 +00:00
|
|
|
bool tr_ctorSetMetainfoFromFile(tr_ctor* ctor, std::string const& 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
|
|
|
|
2021-12-26 16:25:07 +00:00
|
|
|
if (!tr_loadFile(ctor->contents, filename, error))
|
|
|
|
{
|
|
|
|
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) };
|
|
|
|
return ctor->metainfo.parseBenc(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-02-07 04:28:36 +00:00
|
|
|
return tr_ctorSetMetainfoFromFile(ctor, std::string{ 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) };
|
|
|
|
return ctor->metainfo.parseBenc(contents_sv, error);
|
2007-12-21 16:51:42 +00:00
|
|
|
}
|
|
|
|
|
2021-12-26 16:25:07 +00:00
|
|
|
bool tr_ctorSetMetainfoFromMagnetLink(tr_ctor* ctor, char const* 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-02-07 04:28:36 +00:00
|
|
|
return ctor->metainfo.parseMagnet(magnet_link != nullptr ? magnet_link : "", error);
|
2008-02-13 02:24:12 +00:00
|
|
|
}
|
|
|
|
|
2021-12-26 16:25:07 +00:00
|
|
|
std::string_view tr_ctorGetContents(tr_ctor const* ctor)
|
2009-11-24 02:16:31 +00:00
|
|
|
{
|
2021-12-26 16:25:07 +00:00
|
|
|
return std::string_view{ std::data(ctor->contents), std::size(ctor->contents) };
|
2009-11-24 02:16:31 +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-01-15 19:33:57 +00:00
|
|
|
bool tr_ctorSaveContents(tr_ctor const* ctor, std::string const& 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tr_saveFile(filename, { std::data(ctor->contents), std::size(ctor->contents) }, error);
|
|
|
|
}
|
|
|
|
|
2007-12-21 16:51:42 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_ctorSetFilePriorities(tr_ctor* ctor, tr_file_index_t const* files, tr_file_index_t fileCount, 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:
|
2021-11-05 03:08:38 +00:00
|
|
|
ctor->low.assign(files, files + fileCount);
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_PRI_HIGH:
|
2021-11-05 03:08:38 +00:00
|
|
|
ctor->high.assign(files, files + fileCount);
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
|
|
|
|
2021-11-05 03:08:38 +00:00
|
|
|
default: // TR_PRI_NORMAL
|
|
|
|
ctor->normal.assign(files, files + fileCount);
|
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
|
|
|
{
|
2021-11-29 01:12:54 +00:00
|
|
|
tor->setFilePriorities(std::data(ctor->low), std::size(ctor->low), TR_PRI_LOW);
|
|
|
|
tor->setFilePriorities(std::data(ctor->normal), std::size(ctor->normal), TR_PRI_NORMAL);
|
|
|
|
tor->setFilePriorities(std::data(ctor->high), std::size(ctor->high), TR_PRI_HIGH);
|
2009-04-02 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_ctorSetFilesWanted(tr_ctor* ctor, tr_file_index_t const* files, tr_file_index_t fileCount, 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;
|
2021-11-05 03:08:38 +00:00
|
|
|
indices.assign(files, files + fileCount);
|
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
|
|
|
{
|
2021-11-29 01:12:54 +00:00
|
|
|
tor->initFilesWanted(std::data(ctor->unwanted), std::size(ctor->unwanted), false);
|
|
|
|
tor->initFilesWanted(std::data(ctor->wanted), std::size(ctor->wanted), true);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
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-01-15 19:33:57 +00:00
|
|
|
tr_torrent_metainfo&& tr_ctorStealMetainfo(tr_ctor* ctor)
|
|
|
|
{
|
|
|
|
return std::move(ctor->metainfo);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2022-01-11 14:28:14 +00:00
|
|
|
return !std::empty(ctor->metainfo.infoHashString()) ? &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
|
|
|
}
|
|
|
|
|
2007-12-21 22:18:40 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static bool isPriority(int i)
|
2010-02-02 07:48:03 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
return i == TR_PRI_LOW || i == TR_PRI_NORMAL || i == TR_PRI_HIGH;
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (isPriority(priority))
|
|
|
|
{
|
2021-11-05 03:08:38 +00:00
|
|
|
ctor->priority = priority;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2022-02-03 06:02:30 +00:00
|
|
|
void tr_ctorSetLabels(tr_ctor* ctor, char const** labels, size_t len)
|
|
|
|
{
|
|
|
|
auto labels_set = tr_labels_t{};
|
|
|
|
for (size_t i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
labels_set.emplace(labels[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_ctorSetLabels(ctor, std::move(labels_set));
|
|
|
|
}
|
|
|
|
|
|
|
|
void tr_ctorSetLabels(tr_ctor* ctor, tr_labels_t&& labels)
|
|
|
|
{
|
|
|
|
ctor->labels = std::move(labels);
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_labels_t tr_ctorGetLabels(tr_ctor const* ctor)
|
|
|
|
{
|
|
|
|
return ctor->labels;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
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
|
|
|
|
2021-12-26 16:25:07 +00:00
|
|
|
tr_ctorSetDeleteSource(ctor, tr_sessionGetDeleteSource(session));
|
|
|
|
tr_ctorSetPaused(ctor, TR_FALLBACK, tr_sessionGetPaused(session));
|
|
|
|
tr_ctorSetPeerLimit(ctor, TR_FALLBACK, session->peerLimitPerTorrent);
|
|
|
|
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
|
|
|
}
|