From 9d90ebbc9745494e11355359d9c66d03f37d5d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9ven=20Car?= Date: Thu, 28 Nov 2024 11:18:10 +0100 Subject: [PATCH] Correct net::parseUri variable naming MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Méven Car Change-Id: Iec830ae76f4694331b837f31271c0ebcf042ae34 --- net/NetUtil.cpp | 6 +-- net/NetUtil.hpp | 2 +- wsd/ClientRequestDispatcher.cpp | 68 +++++++++++---------------------- 3 files changed, 27 insertions(+), 49 deletions(-) diff --git a/net/NetUtil.cpp b/net/NetUtil.cpp index 694b029b87c0..ffa0e5444fdf 100644 --- a/net/NetUtil.cpp +++ b/net/NetUtil.cpp @@ -577,7 +577,7 @@ connect(std::string uri, const std::shared_ptr& protoc } bool parseUri(std::string uri, std::string& scheme, std::string& host, std::string& port, - std::string& path) + std::string& pathAndQuery) { const auto itScheme = uri.find("://"); if (itScheme != uri.npos) @@ -594,12 +594,12 @@ bool parseUri(std::string uri, std::string& scheme, std::string& host, std::stri const auto itUrl = uri.find('/'); if (itUrl != uri.npos) { - path = uri.substr(itUrl); // Including the first foreslash. + pathAndQuery = uri.substr(itUrl); // Including the first foreslash. uri = uri.substr(0, itUrl); } else { - path.clear(); + pathAndQuery.clear(); } const auto itPort = uri.find(':'); diff --git a/net/NetUtil.hpp b/net/NetUtil.hpp index 778b7f93d694..f4da1afadc0f 100644 --- a/net/NetUtil.hpp +++ b/net/NetUtil.hpp @@ -112,7 +112,7 @@ connect(std::string uri, const std::shared_ptr& protoc /// Decomposes a URI into its components. /// Returns true if parsing was successful. bool parseUri(std::string uri, std::string& scheme, std::string& host, std::string& port, - std::string& url); + std::string& pathAndQuery); /// Decomposes a URI into its components. /// Returns true if parsing was successful. diff --git a/wsd/ClientRequestDispatcher.cpp b/wsd/ClientRequestDispatcher.cpp index 468ceeddf4f1..8a70456e92b1 100644 --- a/wsd/ClientRequestDispatcher.cpp +++ b/wsd/ClientRequestDispatcher.cpp @@ -16,6 +16,7 @@ #endif #include +#include #include #include #include @@ -1093,6 +1094,23 @@ bool ClientRequestDispatcher::handleWopiDiscoveryRequest( return true; } +STATE_ENUM(CheckStatus, + Ok, + NotHttpSucess, + HostNotFound, + HostUnReachable, + UnspecifiedError, + ConnectionAborted, + ConnectionRefused, + InvalidCertificate, + CertificateValidation, + SSLHandshakeFail, + MissingSsl, + NotHttps, + NoScheme, + Timeout, +); + bool ClientRequestDispatcher::handleWopiAccessCheckRequest(const Poco::Net::HTTPRequest& request, Poco::MemoryInputStream& message, const std::shared_ptr& socket) @@ -1143,8 +1161,8 @@ bool ClientRequestDispatcher::handleWopiAccessCheckRequest(const Poco::Net::HTTP LOG_DBG("Wopi Access Check request callbackUrlStr: " << callbackUrlStr); - std::string scheme, host, portStr, url; - if (!net::parseUri(callbackUrlStr, scheme, host, portStr, url)) { + std::string scheme, host, portStr, pathAndQuery; + if (!net::parseUri(callbackUrlStr, scheme, host, portStr, pathAndQuery)) { HttpHelper::sendErrorAndShutdown(http::StatusCode::BadRequest, socket); return false; } @@ -1186,51 +1204,11 @@ bool ClientRequestDispatcher::handleWopiAccessCheckRequest(const Poco::Net::HTTP LOG_DBG("Wopi Access Check request scheme: " << scheme << port << portStr); - enum class CheckStatus - { - Ok = 0, - NotHttpSucess, - HostNotFound, - HostUnReachable, - UnspecifiedError, - ConnectionAborted, - ConnectionRefused, - InvalidCertificate, - CertificateValidation, - SSLHandshakeFail, - MissingSsl, - NotHttps, - NoScheme, - Timeout, - }; - - const std::map checkStatusNames = { - { CheckStatus::Ok, "Ok" }, - { CheckStatus::NotHttpSucess, "NOT_HTTP_SUCESS" }, - { CheckStatus::HostNotFound, "HOST_NOT_FOUND" }, - { CheckStatus::HostUnReachable, "HOST_UNREACHABLE" }, - { CheckStatus::UnspecifiedError, "UNSPECIFIED_ERROR" }, - { CheckStatus::ConnectionAborted, "CONNECTION_ABORTED" }, - { CheckStatus::ConnectionRefused, "CONNECTION_REFUSED" }, - { CheckStatus::InvalidCertificate, "INVALID_CERTIFICATE" }, - { CheckStatus::CertificateValidation, "CERTIFICATE_VALIDATION" }, - { CheckStatus::SSLHandshakeFail, "SSL_HANDSHAKE_FAIL" }, - { CheckStatus::MissingSsl, "MISSING_SSL" }, - { CheckStatus::NotHttps, "NOT_HTTPS" }, - { CheckStatus::NoScheme, "NO_SCHEME" }, - { CheckStatus::Timeout, "TIMEOUT" } - // TODO allowed host check - }; - - auto sendResult = [this, checkStatusNames, socket](CheckStatus result) + auto sendResult = [this, socket](CheckStatus result) { Poco::JSON::Object::Ptr status = new Poco::JSON::Object; status->set("status", (int)result); - if (checkStatusNames.contains(result)) { - status->set("details", checkStatusNames.at(result)); - } else { - LOG_DBG("wopiAccessCheck: Missing details for status:" << (int)result); - } + status->set("details", name(result)); std::ostringstream ostrJSON; status->stringify(ostrJSON); @@ -1259,7 +1237,7 @@ bool ClientRequestDispatcher::handleWopiAccessCheckRequest(const Poco::Net::HTTP LOG_DBG("Wopi Access Check about to prepare http session"); - http::Request httpRequest(url); + http::Request httpRequest(pathAndQuery.empty() ? "/" : pathAndQuery); auto httpProbeSession = http::Session::create(host, protocol, port); httpProbeSession->setTimeout(std::chrono::seconds(2));