1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 09:37:56 +00:00
transmission/libtransmission/rpc-server.h
LaserEyess 3bc21fe8a6
fixup: unix socket implementation changes (#2707)
* Use std::unique_ptr for bindAddress

* fixup: unix socket implementation changes

Assortment of changes and comments from #2574

- actually assign variables in the tr_rpc_address union for ipv4 and
  ipv6
- use std::size() instead of std::string.length()
- add [[maybe_unused]] to bindUnixSocket() args for Windows
- fix error log for windows to to actually print a string instead of
  an enum int
- use C++ style cast for ecvonnlistener_new_bind()
- refactor rpc URL log line to only substitute a single string
- remove redundant tr_rpc+address_is_valid() check

* change TrUnixSocketPrefix to std::string_view

This allows for removing runtime overhead of strlen() in a few places.

Co-authored-by: WeebDataHoarder <57538841+WeebDataHoarder@users.noreply.github.com>
Co-authored-by: LaserEyess <LaserEyess@users.noreply.github.com>
2022-02-27 14:05:08 -08:00

112 lines
3.2 KiB
C++

// 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.
#pragma once
#ifndef __TRANSMISSION__
#error only libtransmission should #include this header.
#endif
#include <list>
#include <memory>
#include <string>
#include <string_view>
#include "transmission.h"
#include "net.h"
struct event;
struct evhttp;
struct tr_variant;
struct tr_rpc_address;
struct libdeflate_compressor;
class tr_rpc_server
{
public:
tr_rpc_server(tr_session* session, tr_variant* settings);
~tr_rpc_server();
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;
std::shared_ptr<libdeflate_compressor> compressor;
std::list<std::string> hostWhitelist;
std::list<std::string> whitelist;
std::string salted_password;
std::string username;
std::string whitelistStr;
std::string url;
std::unique_ptr<struct tr_rpc_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;
static int constexpr DefaultRpcSocketMode = 0750;
int rpc_socket_mode = DefaultRpcSocketMode;
tr_port port = 0;
bool isAntiBruteForceEnabled = false;
bool isEnabled = false;
bool isHostWhitelistEnabled = false;
bool isPasswordEnabled = false;
bool isWhitelistEnabled = false;
};
void tr_rpcSetEnabled(tr_rpc_server* server, bool isEnabled);
bool tr_rpcIsEnabled(tr_rpc_server const* server);
void tr_rpcSetPort(tr_rpc_server* server, tr_port port);
tr_port tr_rpcGetPort(tr_rpc_server const* server);
void tr_rpcSetUrl(tr_rpc_server* server, std::string_view url);
std::string const& tr_rpcGetUrl(tr_rpc_server const* server);
int tr_rpcSetTest(tr_rpc_server const* server, char const* whitelist, char** allocme_errmsg);
void tr_rpcSetWhitelistEnabled(tr_rpc_server* server, bool isEnabled);
bool tr_rpcGetWhitelistEnabled(tr_rpc_server const* server);
void tr_rpcSetWhitelist(tr_rpc_server* server, std::string_view whitelist);
int tr_rpcGetRPCSocketMode(tr_rpc_server const* server);
std::string const& tr_rpcGetWhitelist(tr_rpc_server const* server);
void tr_rpcSetPassword(tr_rpc_server* server, std::string_view password);
std::string const& tr_rpcGetPassword(tr_rpc_server const* server);
void tr_rpcSetUsername(tr_rpc_server* server, std::string_view username);
std::string const& tr_rpcGetUsername(tr_rpc_server const* server);
void tr_rpcSetPasswordEnabled(tr_rpc_server* server, bool isEnabled);
bool tr_rpcIsPasswordEnabled(tr_rpc_server const* session);
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);
char const* tr_rpcGetBindAddress(tr_rpc_server const* server);