From 39c8d18feba8eafcd43fbb55e73ae150a1947aad Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 13 Oct 2020 08:10:50 -0400 Subject: core/CMakeLists: Make some warnings errors Makes our error coverage a little more consistent across the board by applying it to Linux side of things as well. This also makes it more consistent with the warning settings in other libraries in the project. This also updates httplib to 0.7.9, as there are several warning cleanups made that allow us to enable several warnings as errors. --- src/web_service/web_backend.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/web_service/web_backend.cpp') diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp index 74e287045..534960d09 100644 --- a/src/web_service/web_backend.cpp +++ b/src/web_service/web_backend.cpp @@ -67,28 +67,25 @@ struct Client::Impl { const std::string& jwt = "", const std::string& username = "", const std::string& token = "") { if (cli == nullptr) { - auto parsedUrl = LUrlParser::clParseURL::ParseURL(host); - int port; + const auto parsedUrl = LUrlParser::clParseURL::ParseURL(host); + int port{}; if (parsedUrl.m_Scheme == "http") { if (!parsedUrl.GetPort(&port)) { port = HTTP_PORT; } - cli = std::make_unique(parsedUrl.m_Host.c_str(), port); } else if (parsedUrl.m_Scheme == "https") { if (!parsedUrl.GetPort(&port)) { port = HTTPS_PORT; } - cli = std::make_unique(parsedUrl.m_Host.c_str(), port); } else { LOG_ERROR(WebService, "Bad URL scheme {}", parsedUrl.m_Scheme); return WebResult{WebResult::Code::InvalidURL, "Bad URL scheme", ""}; } + cli = std::make_unique(parsedUrl.m_Host.c_str(), port); } - if (cli == nullptr) { - LOG_ERROR(WebService, "Invalid URL {}", host + path); - return WebResult{WebResult::Code::InvalidURL, "Invalid URL", ""}; - } - cli->set_timeout_sec(TIMEOUT_SECONDS); + cli->set_connection_timeout(TIMEOUT_SECONDS); + cli->set_read_timeout(TIMEOUT_SECONDS); + cli->set_write_timeout(TIMEOUT_SECONDS); httplib::Headers params; if (!jwt.empty()) { -- cgit v1.2.3 From 8e673cbb08615865044ed546a133259ff2756128 Mon Sep 17 00:00:00 2001 From: liushuyu Date: Mon, 19 Oct 2020 18:14:41 -0600 Subject: web_backend: fix a regression introduced in 39c8d18 * A regression was in 39c8d18 and token verification function was broken. * The reason being `httplib` now requires OpenSSL 1.1+ API while LibreSSL 2.x provided OpenSSL 1.0 compatible API. * The bundled LibreSSL has been updated to 3.2.2 so it now provides OpenSSL 1.1 compatible API now. * Also the path hint has been added so that it will find the correct path to the CA certs on *nix systems. * An option is provided so that *nix system distributions/providers can use their own SSL implementations when compiling Yuzu/Citra to (hopefully) complies with their maintenance guidelines. * LURLParse is also removed since `httplib` can handle `scheme:host:port` string itself now. --- src/web_service/web_backend.cpp | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'src/web_service/web_backend.cpp') diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp index 534960d09..c56cd7c71 100644 --- a/src/web_service/web_backend.cpp +++ b/src/web_service/web_backend.cpp @@ -7,7 +7,6 @@ #include #include -#include #include #include @@ -19,9 +18,6 @@ namespace WebService { constexpr std::array API_VERSION{'1'}; -constexpr int HTTP_PORT = 80; -constexpr int HTTPS_PORT = 443; - constexpr std::size_t TIMEOUT_SECONDS = 30; struct Client::Impl { @@ -67,21 +63,7 @@ struct Client::Impl { const std::string& jwt = "", const std::string& username = "", const std::string& token = "") { if (cli == nullptr) { - const auto parsedUrl = LUrlParser::clParseURL::ParseURL(host); - int port{}; - if (parsedUrl.m_Scheme == "http") { - if (!parsedUrl.GetPort(&port)) { - port = HTTP_PORT; - } - } else if (parsedUrl.m_Scheme == "https") { - if (!parsedUrl.GetPort(&port)) { - port = HTTPS_PORT; - } - } else { - LOG_ERROR(WebService, "Bad URL scheme {}", parsedUrl.m_Scheme); - return WebResult{WebResult::Code::InvalidURL, "Bad URL scheme", ""}; - } - cli = std::make_unique(parsedUrl.m_Host.c_str(), port); + cli = std::make_unique(host.c_str()); } cli->set_connection_timeout(TIMEOUT_SECONDS); cli->set_read_timeout(TIMEOUT_SECONDS); -- cgit v1.2.3 From 156556ddd2128e8e9a73a7166985639228015bcf Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 28 Oct 2020 17:18:33 -0700 Subject: web_service: web_backend: Handle socket errors with GenericRequest. - Fixes a shutdown crash when we try to submit telemetry if there is a service issue. --- src/web_service/web_backend.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/web_service/web_backend.cpp') diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp index c56cd7c71..f264b98a0 100644 --- a/src/web_service/web_backend.cpp +++ b/src/web_service/web_backend.cpp @@ -65,6 +65,17 @@ struct Client::Impl { if (cli == nullptr) { cli = std::make_unique(host.c_str()); } + + if (!cli->is_valid()) { + LOG_ERROR(WebService, "Client is invalid, skipping request!"); + return {}; + } + + if (!cli->is_socket_open()) { + LOG_ERROR(WebService, "Failed to open socket, skipping request!"); + return {}; + } + cli->set_connection_timeout(TIMEOUT_SECONDS); cli->set_read_timeout(TIMEOUT_SECONDS); cli->set_write_timeout(TIMEOUT_SECONDS); -- cgit v1.2.3 From cf63eacc1a34924a01e7d8586fccb7d7561d2250 Mon Sep 17 00:00:00 2001 From: liushuyu Date: Wed, 28 Oct 2020 23:06:26 -0600 Subject: web_service: follow-up fix to #4842 ... * The web_service http request is now fixed on Windows (R) platform. * The issue is due to a complicated race-condition in `httplib`, a detailed explanation is available at https://github.com/yhirose/cpp-httplib/pull/701 * A pending Pull Request on `httplib` has been applied to remedy the said race-condition. * The socket availability check is removed due to a behavioral chice of `httplib` that a socket will not be created before any actual request is sent. --- src/web_service/web_backend.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/web_service/web_backend.cpp') diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp index f264b98a0..67183e64c 100644 --- a/src/web_service/web_backend.cpp +++ b/src/web_service/web_backend.cpp @@ -71,11 +71,6 @@ struct Client::Impl { return {}; } - if (!cli->is_socket_open()) { - LOG_ERROR(WebService, "Failed to open socket, skipping request!"); - return {}; - } - cli->set_connection_timeout(TIMEOUT_SECONDS); cli->set_read_timeout(TIMEOUT_SECONDS); cli->set_write_timeout(TIMEOUT_SECONDS); -- cgit v1.2.3