2008-05-18 16:44:30 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2008-2014 Mnemosyne LLC
|
2008-05-18 16:44:30 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
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>
|
|
|
|
#include <string>
|
2021-11-14 06:02:45 +00:00
|
|
|
#include <string_view>
|
|
|
|
|
2021-11-14 21:14:37 +00:00
|
|
|
#include <zlib.h>
|
|
|
|
|
|
|
|
#include <event2/buffer.h>
|
|
|
|
#include <event2/event.h>
|
|
|
|
#include <event2/http.h>
|
|
|
|
#include <event2/http_struct.h> /* TODO: eventually remove this */
|
|
|
|
|
2021-11-14 06:02:45 +00:00
|
|
|
#include "transmission.h"
|
|
|
|
|
|
|
|
#include "net.h"
|
|
|
|
|
2021-11-09 03:30:03 +00:00
|
|
|
struct tr_variant;
|
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;
|
|
|
|
|
2021-11-14 21:14:37 +00:00
|
|
|
z_stream stream = {};
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
struct tr_address bindAddress;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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 isStreamInitialized = 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
|
|
|
|
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);
|