2#ifndef _CRYPTOX_DATA_CONNECTION_PROXY_CONFIG_HPP_INCLUDED
3#define _CRYPTOX_DATA_CONNECTION_PROXY_CONFIG_HPP_INCLUDED
26 ProxyConfig(std::string server, std::string auth, ProxyType type)
33 void set_proxy(
const std::string& ip,
int port, ProxyType type) {
45 const std::string& ip,
47 const std::string& username,
48 const std::string& password,
49 ProxyType type = ProxyType::HTTP) {
58 void set_proxy_auth(
const std::string& username,
const std::string& password) {
66 if (pos == std::string::npos)
return {};
74 if (pos == std::string::npos)
return 0;
86 if (pos == std::string::npos)
return {};
94 if (pos == std::string::npos || pos + 1 >=
proxy_auth.size())
return {};
101 return !
proxy_server.empty() && !proxy.get_ip().empty() && proxy.get_port() != 0;
117 if (j.contains(
"proxy_server")) config.
proxy_server = j.at(
"proxy_server").get<std::string>();
118 if (j.contains(
"proxy_auth")) config.
proxy_auth = j.at(
"proxy_auth").get<std::string>();
119 if (j.contains(
"proxy_type")) config.
proxy_type = j.at(
"proxy_type").get<ProxyType>();
120 if (j.contains(
"use")) config.
use = j.at(
"use").get<
bool>();
void to_json(nlohmann::json &j, const ProxyConfig &config)
Serializes ProxyConfig to JSON.
void from_json(const nlohmann::json &j, ProxyConfig &config)
Deserializes ProxyConfig from JSON.
Enables use of ClientError with std::error_code.
Configuration structure for connecting through a proxy server.
std::string get_username() const
Returns the proxy username.
std::string proxy_auth
Proxy authentication in <username:password> format.
int get_port() const
Returns the proxy port.
std::string get_password() const
Returns the proxy password.
ProxyConfig(std::string server, std::string auth, ProxyType type)
Constructs ProxyConfig with server and authentication.
ProxyType proxy_type
Proxy type (e.g., HTTP, SOCKS5).
bool use
Whether to use proxy for connection.
ProxyConfig()
Default constructor.
void set_proxy_auth(const std::string &username, const std::string &password)
Sets proxy authentication credentials.
std::string proxy_server
Proxy address in <ip:port> format.
std::string get_ip() const
Returns the proxy IP address (host part).
bool is_valid() const
Checks if the proxy configuration is valid (server field must not be empty).
void set_proxy(const std::string &ip, int port, ProxyType type)
Sets the proxy server address.
void set_proxy(const std::string &ip, int port, const std::string &username, const std::string &password, ProxyType type=ProxyType::HTTP)
Sets the proxy server address with authentication details and proxy type.