2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © Mnemosyne LLC.
|
2022-08-08 18:05:39 +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.
|
2021-11-10 02:42:18 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-06-30 04:51:55 +00:00
|
|
|
#include <cstddef> // size_t
|
2021-11-10 02:42:18 +00:00
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-07-08 15:24:03 +00:00
|
|
|
#include "libtransmission/announce-list.h"
|
|
|
|
#include "libtransmission/crypto-utils.h"
|
|
|
|
#include "libtransmission/tr-macros.h" // TR_CONSTEXPR20, tr_sha1_digest_t
|
|
|
|
#include "libtransmission/utils.h" // tr_strv_convert_utf8()
|
2021-11-10 02:42:18 +00:00
|
|
|
|
2021-12-15 21:25:42 +00:00
|
|
|
struct tr_error;
|
2021-11-18 00:17:09 +00:00
|
|
|
|
2021-12-25 21:21:13 +00:00
|
|
|
class tr_magnet_metainfo
|
2021-11-10 02:42:18 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
friend struct MetainfoHandler;
|
|
|
|
|
2021-12-25 21:21:13 +00:00
|
|
|
public:
|
2023-11-04 16:39:41 +00:00
|
|
|
bool parseMagnet(std::string_view magnet_link, tr_error* error = nullptr);
|
2022-02-13 04:16:55 +00:00
|
|
|
|
2023-08-30 02:58:31 +00:00
|
|
|
[[nodiscard]] std::string magnet() const;
|
2021-12-25 21:21:13 +00:00
|
|
|
|
2023-04-23 01:25:55 +00:00
|
|
|
[[nodiscard]] constexpr auto const& info_hash() const noexcept
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
|
|
|
return info_hash_;
|
|
|
|
}
|
2022-02-24 21:52:29 +00:00
|
|
|
|
2022-04-02 00:48:09 +00:00
|
|
|
[[nodiscard]] constexpr auto const& name() const noexcept
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
|
|
|
return name_;
|
|
|
|
}
|
2022-01-09 16:55:09 +00:00
|
|
|
|
2023-04-23 01:25:55 +00:00
|
|
|
[[nodiscard]] TR_CONSTEXPR20 auto webseed_count() const noexcept
|
2022-01-09 16:55:09 +00:00
|
|
|
{
|
|
|
|
return std::size(webseed_urls_);
|
|
|
|
}
|
|
|
|
|
2022-12-23 21:21:40 +00:00
|
|
|
[[nodiscard]] TR_CONSTEXPR20 auto const& webseed(size_t i) const
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-12-23 21:21:40 +00:00
|
|
|
return webseed_urls_.at(i);
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
2021-11-10 02:42:18 +00:00
|
|
|
|
2023-04-23 01:25:55 +00:00
|
|
|
[[nodiscard]] constexpr auto& announce_list() noexcept
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
|
|
|
return announce_list_;
|
|
|
|
}
|
2021-11-10 02:42:18 +00:00
|
|
|
|
2023-04-23 01:25:55 +00:00
|
|
|
[[nodiscard]] constexpr auto const& announce_list() const noexcept
|
2021-11-10 02:42:18 +00:00
|
|
|
{
|
2021-12-25 21:21:13 +00:00
|
|
|
return announce_list_;
|
2021-11-10 02:42:18 +00:00
|
|
|
}
|
|
|
|
|
2023-07-04 18:04:03 +00:00
|
|
|
[[nodiscard]] constexpr auto const& info_hash_string() const noexcept
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
|
|
|
return info_hash_str_;
|
|
|
|
}
|
2021-11-10 02:42:18 +00:00
|
|
|
|
2023-07-04 18:04:03 +00:00
|
|
|
[[nodiscard]] constexpr auto const& info_hash2_string() const noexcept
|
2022-07-01 14:49:33 +00:00
|
|
|
{
|
|
|
|
return info_hash2_str_;
|
|
|
|
}
|
|
|
|
|
2023-04-23 01:25:55 +00:00
|
|
|
void set_name(std::string_view name)
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2023-03-19 15:36:16 +00:00
|
|
|
name_ = tr_strv_convert_utf8(name);
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
2021-11-10 02:42:18 +00:00
|
|
|
|
2023-04-23 01:25:55 +00:00
|
|
|
void add_webseed(std::string_view webseed);
|
2022-05-24 04:05:16 +00:00
|
|
|
|
2021-12-25 21:21:13 +00:00
|
|
|
protected:
|
|
|
|
tr_announce_list announce_list_;
|
|
|
|
std::vector<std::string> webseed_urls_;
|
2022-04-02 14:06:02 +00:00
|
|
|
tr_sha1_digest_t info_hash_ = {};
|
2022-07-01 14:49:33 +00:00
|
|
|
tr_sha256_digest_t info_hash2_ = {};
|
2023-07-04 18:04:03 +00:00
|
|
|
tr_sha1_string info_hash_str_;
|
|
|
|
tr_sha256_string info_hash2_str_;
|
2021-12-25 21:21:13 +00:00
|
|
|
std::string name_;
|
2021-11-10 02:42:18 +00:00
|
|
|
};
|