2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright 2021-2022 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
|
|
|
|
|
2022-04-25 01:49:52 +00:00
|
|
|
#include <cstddef>
|
2021-11-10 02:42:18 +00:00
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "transmission.h"
|
|
|
|
|
2021-12-14 20:59:40 +00:00
|
|
|
#include "announce-list.h"
|
2022-03-28 22:13:32 +00:00
|
|
|
#include "tr-strbuf.h" // tr_urlbuf
|
2023-03-19 15:36:16 +00:00
|
|
|
#include "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
|
|
|
struct tr_variant;
|
|
|
|
|
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:
|
2021-11-10 02:42:18 +00:00
|
|
|
bool parseMagnet(std::string_view magnet_link, tr_error** error = nullptr);
|
2022-02-13 04:16:55 +00:00
|
|
|
|
2022-03-28 22:13:32 +00:00
|
|
|
[[nodiscard]] tr_urlbuf 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-04-23 01:25:55 +00:00
|
|
|
[[nodiscard]] constexpr std::string 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-04-23 01:25:55 +00:00
|
|
|
[[nodiscard]] constexpr std::string 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_ = {};
|
2021-12-25 21:21:13 +00:00
|
|
|
std::string info_hash_str_;
|
2022-07-01 14:49:33 +00:00
|
|
|
std::string info_hash2_str_;
|
2021-12-25 21:21:13 +00:00
|
|
|
std::string name_;
|
2021-11-10 02:42:18 +00:00
|
|
|
};
|