2022-01-20 12:27:56 -06:00
|
|
|
// This file Copyright 2021-2022 Mnemosyne LLC.
|
2022-08-08 13:05:39 -05:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 12:27:56 -06:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2021-11-09 20:42:18 -06:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-04-24 20:49:52 -05:00
|
|
|
#include <cstddef>
|
2021-11-09 20:42:18 -06:00
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "transmission.h"
|
|
|
|
|
2021-12-14 14:59:40 -06:00
|
|
|
#include "announce-list.h"
|
2022-03-28 17:13:32 -05:00
|
|
|
#include "tr-strbuf.h" // tr_urlbuf
|
2021-11-09 20:42:18 -06:00
|
|
|
|
2021-12-15 15:25:42 -06:00
|
|
|
struct tr_error;
|
2021-11-17 18:17:09 -06:00
|
|
|
struct tr_variant;
|
|
|
|
|
2021-12-25 15:21:13 -06:00
|
|
|
class tr_magnet_metainfo
|
2021-11-09 20:42:18 -06:00
|
|
|
{
|
2022-05-23 23:05:16 -05:00
|
|
|
friend struct MetainfoHandler;
|
|
|
|
|
2021-12-25 15:21:13 -06:00
|
|
|
public:
|
2021-11-09 20:42:18 -06:00
|
|
|
bool parseMagnet(std::string_view magnet_link, tr_error** error = nullptr);
|
2022-02-12 22:16:55 -06:00
|
|
|
|
2022-03-28 17:13:32 -05:00
|
|
|
[[nodiscard]] tr_urlbuf magnet() const;
|
2021-12-25 15:21:13 -06:00
|
|
|
|
2022-04-01 19:48:09 -05:00
|
|
|
[[nodiscard]] constexpr auto const& infoHash() const noexcept
|
2021-12-25 15:21:13 -06:00
|
|
|
{
|
|
|
|
return info_hash_;
|
|
|
|
}
|
2022-02-24 22:52:29 +01:00
|
|
|
|
2022-04-01 19:48:09 -05:00
|
|
|
[[nodiscard]] constexpr auto const& name() const noexcept
|
2021-12-25 15:21:13 -06:00
|
|
|
{
|
|
|
|
return name_;
|
|
|
|
}
|
2022-01-09 10:55:09 -06:00
|
|
|
|
2022-04-01 19:48:09 -05:00
|
|
|
[[nodiscard]] constexpr auto webseedCount() const noexcept
|
2022-01-09 10:55:09 -06:00
|
|
|
{
|
|
|
|
return std::size(webseed_urls_);
|
|
|
|
}
|
|
|
|
|
2022-04-01 19:48:09 -05:00
|
|
|
[[nodiscard]] auto const& webseed(size_t i) const
|
2021-12-25 15:21:13 -06:00
|
|
|
{
|
2022-01-09 10:55:09 -06:00
|
|
|
return webseed_urls_[i];
|
2021-12-25 15:21:13 -06:00
|
|
|
}
|
2021-11-09 20:42:18 -06:00
|
|
|
|
2022-04-01 19:48:09 -05:00
|
|
|
[[nodiscard]] constexpr auto& announceList() noexcept
|
2021-12-25 15:21:13 -06:00
|
|
|
{
|
|
|
|
return announce_list_;
|
|
|
|
}
|
2021-11-09 20:42:18 -06:00
|
|
|
|
2022-04-01 19:48:09 -05:00
|
|
|
[[nodiscard]] constexpr auto const& announceList() const noexcept
|
2021-11-09 20:42:18 -06:00
|
|
|
{
|
2021-12-25 15:21:13 -06:00
|
|
|
return announce_list_;
|
2021-11-09 20:42:18 -06:00
|
|
|
}
|
|
|
|
|
2022-04-01 19:48:09 -05:00
|
|
|
[[nodiscard]] constexpr std::string const& infoHashString() const noexcept
|
2021-12-25 15:21:13 -06:00
|
|
|
{
|
|
|
|
return info_hash_str_;
|
|
|
|
}
|
2021-11-09 20:42:18 -06:00
|
|
|
|
2022-07-01 07:49:33 -07:00
|
|
|
[[nodiscard]] constexpr std::string const& infoHash2String() const noexcept
|
|
|
|
{
|
|
|
|
return info_hash2_str_;
|
|
|
|
}
|
|
|
|
|
2021-12-25 15:21:13 -06:00
|
|
|
void setName(std::string_view name)
|
|
|
|
{
|
|
|
|
name_ = name;
|
|
|
|
}
|
2021-11-09 20:42:18 -06:00
|
|
|
|
2022-05-23 23:05:16 -05:00
|
|
|
void addWebseed(std::string_view webseed);
|
|
|
|
|
2021-12-25 15:21:13 -06:00
|
|
|
protected:
|
|
|
|
tr_announce_list announce_list_;
|
|
|
|
std::vector<std::string> webseed_urls_;
|
2022-04-02 09:06:02 -05:00
|
|
|
tr_sha1_digest_t info_hash_ = {};
|
2022-07-01 07:49:33 -07:00
|
|
|
tr_sha256_digest_t info_hash2_ = {};
|
2021-12-25 15:21:13 -06:00
|
|
|
std::string info_hash_str_;
|
2022-07-01 07:49:33 -07:00
|
|
|
std::string info_hash2_str_;
|
2021-12-25 15:21:13 -06:00
|
|
|
std::string name_;
|
2021-11-09 20:42:18 -06:00
|
|
|
};
|