2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2008-2022 Mnemosyne LLC.
|
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0), GPLv3 (SPDX: GPL-3.0),
|
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2017-11-14 20:21:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
2008-11-24 20:17:36 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
2017-04-19 12:04:45 +00:00
|
|
|
#error only libtransmission should #include this header.
|
2008-11-24 20:17:36 +00:00
|
|
|
#endif
|
|
|
|
|
2021-11-14 21:14:37 +00:00
|
|
|
#include <list>
|
2022-01-17 16:20:12 +00:00
|
|
|
#include <memory>
|
2021-11-14 21:14:37 +00:00
|
|
|
#include <string>
|
2021-11-14 06:02:45 +00:00
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
#include "transmission.h"
|
|
|
|
|
|
|
|
#include "net.h"
|
|
|
|
|
2022-01-17 16:20:12 +00:00
|
|
|
struct event;
|
|
|
|
struct evhttp;
|
2021-11-09 03:30:03 +00:00
|
|
|
struct tr_variant;
|
2022-02-23 21:09:54 +00:00
|
|
|
struct tr_rpc_address;
|
2022-01-17 16:20:12 +00:00
|
|
|
struct libdeflate_compressor;
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2021-11-14 21:14:37 +00:00
|
|
|
class tr_rpc_server
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
tr_rpc_server(tr_session* session, tr_variant* settings);
|
|
|
|
~tr_rpc_server();
|
|
|
|
|
2021-11-18 00:17:09 +00:00
|
|
|
tr_rpc_server(tr_rpc_server&) = delete;
|
|
|
|
tr_rpc_server(tr_rpc_server&&) = delete;
|
|
|
|
tr_rpc_server& operator=(tr_rpc_server&) = delete;
|
|
|
|
tr_rpc_server& operator=(tr_rpc_server&&) = delete;
|
|
|
|
|
2022-01-17 16:20:12 +00:00
|
|
|
std::shared_ptr<libdeflate_compressor> compressor;
|
2021-11-14 21:14:37 +00:00
|
|
|
|
|
|
|
std::list<std::string> hostWhitelist;
|
|
|
|
std::list<std::string> whitelist;
|
2021-11-15 03:54:48 +00:00
|
|
|
std::string salted_password;
|
2021-11-14 21:14:37 +00:00
|
|
|
std::string username;
|
|
|
|
std::string whitelistStr;
|
|
|
|
std::string url;
|
|
|
|
|
2022-02-27 22:05:08 +00:00
|
|
|
std::unique_ptr<struct tr_rpc_address> bindAddress;
|
2021-11-14 21:14:37 +00:00
|
|
|
|
|
|
|
struct event* start_retry_timer = nullptr;
|
|
|
|
struct evhttp* httpd = nullptr;
|
|
|
|
tr_session* const session;
|
|
|
|
|
|
|
|
int antiBruteForceThreshold = 0;
|
|
|
|
int loginattempts = 0;
|
|
|
|
int start_retry_counter = 0;
|
2022-02-23 21:09:54 +00:00
|
|
|
static int constexpr DefaultRpcSocketMode = 0750;
|
|
|
|
int rpc_socket_mode = DefaultRpcSocketMode;
|
2021-11-14 21:14:37 +00:00
|
|
|
|
|
|
|
tr_port port = 0;
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2021-11-14 21:14:37 +00:00
|
|
|
bool isAntiBruteForceEnabled = false;
|
|
|
|
bool isEnabled = false;
|
|
|
|
bool isHostWhitelistEnabled = false;
|
|
|
|
bool isPasswordEnabled = false;
|
|
|
|
bool isWhitelistEnabled = false;
|
|
|
|
};
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_rpcSetEnabled(tr_rpc_server* server, bool isEnabled);
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool tr_rpcIsEnabled(tr_rpc_server const* server);
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_rpcSetPort(tr_rpc_server* server, tr_port port);
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_port tr_rpcGetPort(tr_rpc_server const* server);
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2021-11-14 21:14:37 +00:00
|
|
|
void tr_rpcSetUrl(tr_rpc_server* server, std::string_view url);
|
2010-12-12 18:22:11 +00:00
|
|
|
|
2021-11-14 21:14:37 +00:00
|
|
|
std::string const& tr_rpcGetUrl(tr_rpc_server const* server);
|
2010-12-12 18:22:11 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
int tr_rpcSetTest(tr_rpc_server const* server, char const* whitelist, char** allocme_errmsg);
|
2008-06-04 17:14:58 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_rpcSetWhitelistEnabled(tr_rpc_server* server, bool isEnabled);
|
2008-10-01 22:59:29 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool tr_rpcGetWhitelistEnabled(tr_rpc_server const* server);
|
2008-10-01 22:59:29 +00:00
|
|
|
|
2021-11-14 06:02:45 +00:00
|
|
|
void tr_rpcSetWhitelist(tr_rpc_server* server, std::string_view whitelist);
|
2018-01-11 18:00:41 +00:00
|
|
|
|
2022-02-23 21:09:54 +00:00
|
|
|
int tr_rpcGetRPCSocketMode(tr_rpc_server const* server);
|
|
|
|
|
2021-11-14 06:02:45 +00:00
|
|
|
std::string const& tr_rpcGetWhitelist(tr_rpc_server const* server);
|
2018-01-11 18:00:41 +00:00
|
|
|
|
2021-11-14 21:14:37 +00:00
|
|
|
void tr_rpcSetPassword(tr_rpc_server* server, std::string_view password);
|
2008-06-05 16:23:03 +00:00
|
|
|
|
2021-11-14 21:14:37 +00:00
|
|
|
std::string const& tr_rpcGetPassword(tr_rpc_server const* server);
|
2008-06-05 16:23:03 +00:00
|
|
|
|
2021-11-14 21:14:37 +00:00
|
|
|
void tr_rpcSetUsername(tr_rpc_server* server, std::string_view username);
|
2008-06-05 16:23:03 +00:00
|
|
|
|
2021-11-14 21:14:37 +00:00
|
|
|
std::string const& tr_rpcGetUsername(tr_rpc_server const* server);
|
2008-06-05 16:23:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_rpcSetPasswordEnabled(tr_rpc_server* server, bool isEnabled);
|
2008-06-05 16:23:03 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool tr_rpcIsPasswordEnabled(tr_rpc_server const* session);
|
2008-08-15 20:28:43 +00:00
|
|
|
|
2020-11-14 18:43:42 +00:00
|
|
|
bool tr_rpcGetAntiBruteForceEnabled(tr_rpc_server const* server);
|
|
|
|
|
|
|
|
void tr_rpcSetAntiBruteForceEnabled(tr_rpc_server* server, bool is_enabled);
|
|
|
|
|
|
|
|
int tr_rpcGetAntiBruteForceThreshold(tr_rpc_server const* server);
|
|
|
|
|
|
|
|
void tr_rpcSetAntiBruteForceThreshold(tr_rpc_server* server, int badRequests);
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* tr_rpcGetBindAddress(tr_rpc_server const* server);
|