Skip to content

Commit

Permalink
Correct net::parseUri variable naming
Browse files Browse the repository at this point in the history
Signed-off-by: Méven Car <meven.car@collabora.com>
Change-Id: Iec830ae76f4694331b837f31271c0ebcf042ae34
  • Loading branch information
meven committed Nov 28, 2024
1 parent 38b6c57 commit 9d90ebb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 49 deletions.
6 changes: 3 additions & 3 deletions net/NetUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ connect(std::string uri, const std::shared_ptr<ProtocolHandlerInterface>& 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)
Expand All @@ -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(':');
Expand Down
2 changes: 1 addition & 1 deletion net/NetUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ connect(std::string uri, const std::shared_ptr<ProtocolHandlerInterface>& 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.
Expand Down
68 changes: 23 additions & 45 deletions wsd/ClientRequestDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#endif

#include <common/Anonymizer.hpp>
#include <common/StateEnum.hpp>
#include <Admin.hpp>
#include <COOLWSD.hpp>
#include <ClientSession.hpp>
Expand Down Expand Up @@ -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,
);

Check notice

Code scanning / CodeQL

Unused static function Note

Static function toString is unreachable
Static function toStringShort is unreachable
Static function nameShort is unreachable (
toStringShort
must be removed at the same time)

Check notice

Code scanning / CodeQL

Unused static variable Note

Static variable CheckStatusMax is never read.

bool ClientRequestDispatcher::handleWopiAccessCheckRequest(const Poco::Net::HTTPRequest& request,
Poco::MemoryInputStream& message,
const std::shared_ptr<StreamSocket>& socket)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<CheckStatus, std::string> 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);
Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit 9d90ebb

Please sign in to comment.