bwi/v2.3.0 #29

Merged
bartoszek merged 38 commits from bwi/v2.3.0 into main 2025-09-11 08:32:43 +00:00
4 changed files with 35 additions and 22 deletions
Showing only changes of commit 5fd06e2875 - Show all commits

View File

@ -201,9 +201,9 @@ class Status {
updateRublonConfigParameter("nonInteractiveMode", config.nonInteractiveMode); updateRublonConfigParameter("nonInteractiveMode", config.nonInteractiveMode);
updateRublonConfigParameter("proxyType", config.proxyType); updateRublonConfigParameter("proxyType", config.proxyType);
updateRublonConfigParameter("proxyServer", config.proxyServer); updateRublonConfigParameter("proxyHost", config.proxyHost);
updateRublonConfigParameter("proxyUsername", config.proxyUsername); updateRublonConfigParameter("proxyUsername", config.proxyUsername);
updateRublonConfigParameter("proxyPass", config.proxyPass); updateRublonConfigParameter("proxyPassword", config.proxyPass);
updateRublonConfigParameter("proxyPort", config.proxyPort); updateRublonConfigParameter("proxyPort", config.proxyPort);
updateRublonConfigParameter("proxyAuthRequired", config.proxyAuthRequired); updateRublonConfigParameter("proxyAuthRequired", config.proxyAuthRequired);

View File

@ -33,7 +33,7 @@ class Configuration {
bool nonInteractiveMode{}; bool nonInteractiveMode{};
std::optional< std::pmr::string > proxyType{memoryResource}; std::optional< std::pmr::string > proxyType{memoryResource};
std::optional< std::pmr::string > proxyServer{memoryResource}; std::optional< std::pmr::string > proxyHost{memoryResource};
std::optional< std::pmr::string > proxyUsername{memoryResource}; std::optional< std::pmr::string > proxyUsername{memoryResource};
std::optional< std::pmr::string > proxyPass{memoryResource}; std::optional< std::pmr::string > proxyPass{memoryResource};
std::optional< int > proxyPort{}; std::optional< int > proxyPort{};
@ -108,7 +108,7 @@ class ConfigurationReader {
}; };
auto getBool = [&](const string & key) -> std::optional< bool > { auto getBool = [&](const string & key) -> std::optional< bool > {
memory::MonotonicStackResource< 64 > memoryResource; memory::MonotonicStackResource< 32 > memoryResource;
auto it = keyValues.find(key); auto it = keyValues.find(key);
if(it == keyValues.end()) if(it == keyValues.end())
return std::nullopt; return std::nullopt;
@ -142,10 +142,8 @@ class ConfigurationReader {
return std::nullopt; return std::nullopt;
}; };
auto parseProxyURL = [&](const char * envValue) -> bool { auto parseProxyURL = [&](std::string_view url) -> bool {
// Very simple parser: scheme://[user[:pass]@]host[:port] // Very simple parser: scheme://[user[:pass]@]host[:port]
std::string_view url = envValue;
std::string_view scheme{}; std::string_view scheme{};
std::string_view auth{}; std::string_view auth{};
std::string_view hostport{}; std::string_view hostport{};
@ -176,7 +174,7 @@ class ConfigurationReader {
config.proxyEnabled = true; config.proxyEnabled = true;
config.proxyType = scheme; config.proxyType = scheme;
config.proxyServer = host; config.proxyHost = host;
if(!port_str.empty()) { if(!port_str.empty()) {
config.proxyPort = conv::to_uint32opt(port_str); config.proxyPort = conv::to_uint32opt(port_str);
@ -241,17 +239,16 @@ class ConfigurationReader {
// reading proxy configuration // reading proxy configuration
config.proxyEnabled = getBool("proxyEnabled").value_or(false); config.proxyEnabled = getBool("proxyEnabled").value_or(false);
config.proxyType = getStringOpt("proxyType"); config.proxyType = getStringOpt("proxyType");
config.proxyServer = getStringOpt("proxyServer"); config.proxyHost = getStringOpt("proxyHost");
// Apply fallback if no config is set // Apply fallback if no config is set
if(config.proxyEnabled && (!config.proxyType || config.proxyType->empty()) && if(config.proxyEnabled && (!config.proxyType || config.proxyType->empty()) && (!config.proxyHost || config.proxyHost->empty())) {
(!config.proxyServer || config.proxyServer->empty())) {
log(LogLevel::Info, "Proxy is enabled but no configuration for it is provided, trying to read from env"); log(LogLevel::Info, "Proxy is enabled but no configuration for it is provided, trying to read from env");
if(const char * https_proxy = std::getenv("https_proxy"); https_proxy && *https_proxy) { if(auto https_proxy = std::getenv("https_proxy"); https_proxy && *https_proxy) {
if(parseProxyURL(https_proxy)) { if(parseProxyURL(https_proxy)) {
log(LogLevel::Info, "Loaded proxy config from HTTPS_PROXY"); log(LogLevel::Info, "Loaded proxy config from HTTPS_PROXY");
} }
} else if(const char * http_proxy = std::getenv("http_proxy"); http_proxy && *http_proxy) { } else if(auto http_proxy = std::getenv("http_proxy"); http_proxy && *http_proxy) {
if(parseProxyURL(http_proxy)) { if(parseProxyURL(http_proxy)) {
log(LogLevel::Info, "Loaded proxy config from HTTP_PROXY"); log(LogLevel::Info, "Loaded proxy config from HTTP_PROXY");
} }
@ -263,14 +260,14 @@ class ConfigurationReader {
log(LogLevel::Error, "Proxy is enabled but proxy type is not present or empty"); log(LogLevel::Error, "Proxy is enabled but proxy type is not present or empty");
return tl::unexpected{ConfigurationError::ErrorClass::BadConfiguration}; return tl::unexpected{ConfigurationError::ErrorClass::BadConfiguration};
} }
if(not config.proxyServer or config.proxyServer->empty()) { if(not config.proxyHost or config.proxyHost->empty()) {
log(LogLevel::Error, "Proxy is enabled but proxy server is not present or empty"); log(LogLevel::Error, "Proxy is enabled but proxy server is not present or empty");
return tl::unexpected{ConfigurationError::ErrorClass::BadConfiguration}; return tl::unexpected{ConfigurationError::ErrorClass::BadConfiguration};
} }
} }
config.proxyAuthRequired = getBool("proxyAuthRequired").value_or(false); config.proxyAuthRequired = getBool("proxyAuthRequired").value_or(false);
config.proxyUsername = getStringOpt("proxyUsername"); config.proxyUsername = getStringOpt("proxyUsername");
config.proxyPass = getStringOpt("proxyPass"); config.proxyPass = getStringOpt("proxyPassword");
if(config.proxyAuthRequired) { if(config.proxyAuthRequired) {
if(not config.proxyUsername or config.proxyUsername->empty()) { if(not config.proxyUsername or config.proxyUsername->empty()) {
log(LogLevel::Error, "Proxy auth is required but proxy proxy username is not present or empty"); log(LogLevel::Error, "Proxy auth is required but proxy proxy username is not present or empty");
@ -284,7 +281,23 @@ class ConfigurationReader {
} }
} }
config.proxyPort = getInt("proxyPort").value_or(8080); auto defaultProxyPort = [&]() -> int {
memory::MonotonicStackResource< 32 > memoryResource;
if(config.proxyType) {
std::pmr::string val{*config.proxyType, &memoryResource};
std::transform(val.begin(), val.end(), val.begin(), [](unsigned char c) { return static_cast< char >(std::tolower(c)); });
if(val == "socks") {
return 1080;
}
}
return 8080;
};
if(config.proxyEnabled and not config.proxyPort) {
config.proxyPort = getInt("proxyPort").value_or(defaultProxyPort());
}
return true; return true;
} }

View File

@ -86,16 +86,16 @@ class CURL {
if(conf().proxyEnabled) { if(conf().proxyEnabled) {
// configuration reader check if proxy has needed fields // configuration reader check if proxy has needed fields
assert(conf().proxyType.has_value()); assert(conf().proxyType.has_value());
assert(conf().proxyServer.has_value()); assert(conf().proxyHost.has_value());
log(LogLevel::Debug, "CURL using proxy"); log(LogLevel::Debug, "CURL using proxy");
std::pmr::string proxyUrl{&memoryResource}; std::pmr::string proxyUrl{&memoryResource};
proxyUrl.reserve(conservative_estimate(conf().proxyType, conf().proxyServer, conf().proxyPort) + 10); proxyUrl.reserve(conservative_estimate(conf().proxyType, conf().proxyHost, conf().proxyPort) + 10);
if(conf().proxyType == "http" || conf().proxyType == "https" || conf().proxyType == "socks4" || conf().proxyType == "socks5") { if(conf().proxyType == "http" || conf().proxyType == "https" || conf().proxyType == "socks4" || conf().proxyType == "socks5") {
proxyUrl = *conf().proxyType; proxyUrl = *conf().proxyType;
proxyUrl += "://"; proxyUrl += "://";
proxyUrl += *conf().proxyServer; proxyUrl += *conf().proxyHost;
if(conf().proxyPort.value_or(0) > 0) { if(conf().proxyPort.value_or(0) > 0) {
proxyUrl += ":"; proxyUrl += ":";
proxyUrl += std::to_string(*conf().proxyPort); proxyUrl += std::to_string(*conf().proxyPort);

View File

@ -75,12 +75,12 @@ class WebSocket {
if(cfg.proxyEnabled && (cfg.proxyType == "http" || cfg.proxyType == "https")) { if(cfg.proxyEnabled && (cfg.proxyType == "http" || cfg.proxyType == "https")) {
assert(cfg.proxyType.has_value()); assert(cfg.proxyType.has_value());
assert(cfg.proxyServer.has_value()); assert(cfg.proxyHost.has_value());
log(LogLevel::Debug, "WebSocket using proxy"); log(LogLevel::Debug, "WebSocket using proxy");
memory::Monotonic_8k_Resource memoryResource; memory::Monotonic_8k_Resource memoryResource;
std::pmr::string proxyUrl{&memoryResource}; std::pmr::string proxyUrl{&memoryResource};
proxyUrl.reserve(conservative_estimate(cfg.proxyUsername, cfg.proxyPass, cfg.proxyServer, cfg.proxyPort) + 10); proxyUrl.reserve(conservative_estimate(cfg.proxyUsername, cfg.proxyPass, cfg.proxyHost, cfg.proxyPort) + 10);
proxyUrl += cfg.proxyType->data(); proxyUrl += cfg.proxyType->data();
proxyUrl += "://"; proxyUrl += "://";
@ -92,7 +92,7 @@ class WebSocket {
proxyUrl += "@"; proxyUrl += "@";
} }
proxyUrl += *cfg.proxyServer; proxyUrl += *cfg.proxyHost;
if(cfg.proxyPort.value_or(0) > 0) { if(cfg.proxyPort.value_or(0) > 0) {
proxyUrl += ":"; proxyUrl += ":";
proxyUrl += std::to_string(*cfg.proxyPort); proxyUrl += std::to_string(*cfg.proxyPort);