From 2160abb5ec6d7d9cc5a0cb4e5172736038a7bc45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 29 Dec 2023 00:58:08 +0100 Subject: [PATCH 1/3] Web server: Send 404 as appropriate --- Common/Net/HTTPClient.cpp | 2 ++ Core/WebServer.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/Common/Net/HTTPClient.cpp b/Common/Net/HTTPClient.cpp index c6366af8262d..2888ed50129a 100644 --- a/Common/Net/HTTPClient.cpp +++ b/Common/Net/HTTPClient.cpp @@ -178,6 +178,7 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) { selectResult = select(maxfd, nullptr, &fds, nullptr, &tv); if (cancelConnect && *cancelConnect) { + WARN_LOG(HTTP, "connect(%d): cancelled (1)", sock); break; } } @@ -196,6 +197,7 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) { } if (cancelConnect && *cancelConnect) { + WARN_LOG(HTTP, "connect(%d): cancelled (2)", sock); break; } diff --git a/Core/WebServer.cpp b/Core/WebServer.cpp index 31bed62f26d8..abb03555b9ff 100644 --- a/Core/WebServer.cpp +++ b/Core/WebServer.cpp @@ -162,6 +162,12 @@ static Path LocalFromRemotePath(const std::string &path) { static void DiscHandler(const http::ServerRequest &request, const Path &filename) { s64 sz = File::GetFileSize(filename); + if (sz == 0) { + // Probably failed + request.WriteHttpResponseHeader("1.0", 404, -1, "text/plain"); + request.Out()->Push("File not found."); + return; + } std::string range; if (request.Method() == http::RequestHeader::HEAD) { From e6bc3d83f8c85bbd0d6005f306f36793d00cbb24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 29 Dec 2023 11:13:16 +0100 Subject: [PATCH 2/3] Logging improvement --- Common/Net/HTTPClient.cpp | 4 ++-- Common/Net/HTTPHeaders.h | 2 +- Common/Net/HTTPServer.cpp | 2 +- Common/Net/Sinks.cpp | 10 +++++++--- Common/Net/Sinks.h | 7 ++++--- UI/RemoteISOScreen.cpp | 1 + 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Common/Net/HTTPClient.cpp b/Common/Net/HTTPClient.cpp index 2888ed50129a..2b7ec91b4116 100644 --- a/Common/Net/HTTPClient.cpp +++ b/Common/Net/HTTPClient.cpp @@ -178,7 +178,7 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) { selectResult = select(maxfd, nullptr, &fds, nullptr, &tv); if (cancelConnect && *cancelConnect) { - WARN_LOG(HTTP, "connect(%d): cancelled (1)", sock); + WARN_LOG(HTTP, "connect: cancelled (1)"); break; } } @@ -197,7 +197,7 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) { } if (cancelConnect && *cancelConnect) { - WARN_LOG(HTTP, "connect(%d): cancelled (2)", sock); + WARN_LOG(HTTP, "connect: cancelled (2)"); break; } diff --git a/Common/Net/HTTPHeaders.h b/Common/Net/HTTPHeaders.h index b91b376411ee..4b112ab575ba 100644 --- a/Common/Net/HTTPHeaders.h +++ b/Common/Net/HTTPHeaders.h @@ -29,7 +29,7 @@ class RequestHeader { enum RequestType { SIMPLE, FULL, }; - RequestType type; + RequestType type = SIMPLE; enum Method { GET, HEAD, diff --git a/Common/Net/HTTPServer.cpp b/Common/Net/HTTPServer.cpp index f8bb76050373..36f5b665bd5e 100644 --- a/Common/Net/HTTPServer.cpp +++ b/Common/Net/HTTPServer.cpp @@ -81,7 +81,7 @@ ServerRequest::~ServerRequest() { } delete in_; if (!out_->Empty()) { - ERROR_LOG(IO, "Output not empty - connection abort? (%s)", this->header_.resource); + WARN_LOG(IO, "Output not empty - connection abort? (%s) (%d bytes)", this->header_.resource, out_->BytesRemaining()); } delete out_; } diff --git a/Common/Net/Sinks.cpp b/Common/Net/Sinks.cpp index 86f3841e2695..b6453bcf85f6 100644 --- a/Common/Net/Sinks.cpp +++ b/Common/Net/Sinks.cpp @@ -220,7 +220,7 @@ void InputSink::AccountDrain(size_t bytes) { } } -bool InputSink::Empty() { +bool InputSink::Empty() const { return valid_ == 0; } @@ -418,8 +418,12 @@ void OutputSink::AccountDrain(int bytes) { } } -bool OutputSink::Empty() { +bool OutputSink::Empty() const { return valid_ == 0; } -}; +int OutputSink::BytesRemaining() const { + return valid_; +} + +} // namespace net diff --git a/Common/Net/Sinks.h b/Common/Net/Sinks.h index e49630f57f11..b997abf34203 100644 --- a/Common/Net/Sinks.h +++ b/Common/Net/Sinks.h @@ -21,7 +21,7 @@ class InputSink { bool Skip(size_t bytes); void Discard(); - bool Empty(); + bool Empty() const; bool TryFill(); private: @@ -54,7 +54,8 @@ class OutputSink { bool Flush(bool allowBlock = true); void Discard(); - bool Empty(); + bool Empty() const; + int BytesRemaining() const; private: void Drain(); @@ -72,4 +73,4 @@ class OutputSink { size_t valid_; }; -}; +} // namespace net diff --git a/UI/RemoteISOScreen.cpp b/UI/RemoteISOScreen.cpp index 53266234dbb2..11f4653a7f97 100644 --- a/UI/RemoteISOScreen.cpp +++ b/UI/RemoteISOScreen.cpp @@ -118,6 +118,7 @@ bool RemoteISOConnectScreen::FindServer(std::string &resultHost, int &resultPort std::lock_guard guard(statusLock_); statusMessage_ = formatted; + INFO_LOG(SYSTEM, "Remote: %s", formatted.c_str()); }; http.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION)); From 74a33ab98d674e50b81932bf6e594f67b2007103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 29 Dec 2023 01:13:37 +0100 Subject: [PATCH 3/3] Add new FolderChooserChoice --- Common/UI/PopupScreens.cpp | 24 ++++++++++++++++++++++++ Common/UI/PopupScreens.h | 13 +++++++++++++ 2 files changed, 37 insertions(+) diff --git a/Common/UI/PopupScreens.cpp b/Common/UI/PopupScreens.cpp index d1b1f1abbe8f..4e056573a22d 100644 --- a/Common/UI/PopupScreens.cpp +++ b/Common/UI/PopupScreens.cpp @@ -692,4 +692,28 @@ std::string FileChooserChoice::ValueText() const { return path.GetFilename(); } +FolderChooserChoice::FolderChooserChoice(std::string *value, const std::string &text, LayoutParams *layoutParams) + : AbstractChoiceWithValueDisplay(text, layoutParams), value_(value) { + OnClick.Add([=](UI::EventParams &) { + System_BrowseForFolder(text_, [=](const std::string &returnValue, int) { + if (*value_ != returnValue) { + *value = returnValue; + UI::EventParams e{}; + e.s = *value; + OnChange.Trigger(e); + } + }); + return UI::EVENT_DONE; + }); +} + +std::string FolderChooserChoice::ValueText() const { + if (value_->empty()) { + auto di = GetI18NCategory(I18NCat::DIALOG); + return di->T("Default"); + } + Path path(*value_); + return path.GetFilename(); +} + } // namespace diff --git a/Common/UI/PopupScreens.h b/Common/UI/PopupScreens.h index 5acfad8d73c2..8e237bca2329 100644 --- a/Common/UI/PopupScreens.h +++ b/Common/UI/PopupScreens.h @@ -436,4 +436,17 @@ class FileChooserChoice : public AbstractChoiceWithValueDisplay { BrowseFileType fileType_; }; +class FolderChooserChoice : public AbstractChoiceWithValueDisplay { +public: + FolderChooserChoice(std::string *value, const std::string &title, LayoutParams *layoutParams = nullptr); + std::string ValueText() const override; + + Event OnChange; + +private: + std::string *value_; + BrowseFileType fileType_; +}; + + } // namespace UI