diff --git a/Common/Net/HTTPClient.cpp b/Common/Net/HTTPClient.cpp index 9fc37de082..7c810ec975 100644 --- a/Common/Net/HTTPClient.cpp +++ b/Common/Net/HTTPClient.cpp @@ -444,21 +444,21 @@ int Client::ReadResponseEntity(net::Buffer *readbuf, const std::vector RequestManager::StartDownload(const std::string &url, const Path &outfile, ProgressBarMode mode, const char *acceptMime) { - std::shared_ptr dl; +std::shared_ptr RequestManager::StartDownload(const std::string &url, const Path &outfile, ProgressBarMode mode, const char *acceptMime) { + std::shared_ptr dl; if (IsHttpsUrl(url)) { #ifndef HTTPS_NOT_AVAILABLE - dl.reset(new HTTPSDownload(RequestMethod::GET, url, "", "", outfile, mode)); + dl.reset(new HTTPSRequest(RequestMethod::GET, url, "", "", outfile, mode)); #else - return std::shared_ptr(); + return std::shared_ptr(); #endif } else { - dl.reset(new HTTPDownload(RequestMethod::GET, url, "", "", outfile, mode)); + dl.reset(new HTTPRequest(RequestMethod::GET, url, "", "", outfile, mode)); } if (!userAgent_.empty()) @@ -56,22 +56,22 @@ std::shared_ptr RequestManager::StartDownload(const std::string &url, return dl; } -std::shared_ptr RequestManager::StartDownloadWithCallback( +std::shared_ptr RequestManager::StartDownloadWithCallback( const std::string &url, const Path &outfile, ProgressBarMode mode, - std::function callback, + std::function callback, const std::string &name, const char *acceptMime) { - std::shared_ptr dl; + std::shared_ptr dl; if (IsHttpsUrl(url)) { #ifndef HTTPS_NOT_AVAILABLE - dl.reset(new HTTPSDownload(RequestMethod::GET, url, "", "", outfile, mode, name)); + dl.reset(new HTTPSRequest(RequestMethod::GET, url, "", "", outfile, mode, name)); #else - return std::shared_ptr(); + return std::shared_ptr(); #endif } else { - dl.reset(new HTTPDownload(RequestMethod::GET, url, "", "", outfile, mode, name)); + dl.reset(new HTTPRequest(RequestMethod::GET, url, "", "", outfile, mode, name)); } if (!userAgent_.empty()) dl->SetUserAgent(userAgent_); @@ -83,22 +83,22 @@ std::shared_ptr RequestManager::StartDownloadWithCallback( return dl; } -std::shared_ptr RequestManager::AsyncPostWithCallback( +std::shared_ptr RequestManager::AsyncPostWithCallback( const std::string &url, const std::string &postData, const std::string &postMime, ProgressBarMode mode, - std::function callback, + std::function callback, const std::string &name) { - std::shared_ptr dl; + std::shared_ptr dl; if (IsHttpsUrl(url)) { #ifndef HTTPS_NOT_AVAILABLE - dl.reset(new HTTPSDownload(RequestMethod::POST, url, postData, postMime, Path(), mode, name)); + dl.reset(new HTTPSRequest(RequestMethod::POST, url, postData, postMime, Path(), mode, name)); #else - return std::shared_ptr(); + return std::shared_ptr(); #endif } else { - dl.reset(new HTTPDownload(RequestMethod::POST, url, postData, postMime, Path(), mode, name)); + dl.reset(new HTTPRequest(RequestMethod::POST, url, postData, postMime, Path(), mode, name)); } if (!userAgent_.empty()) dl->SetUserAgent(userAgent_); diff --git a/Common/Net/HTTPRequest.h b/Common/Net/HTTPRequest.h index 0e7686009b..b04b04d87c 100644 --- a/Common/Net/HTTPRequest.h +++ b/Common/Net/HTTPRequest.h @@ -21,10 +21,10 @@ enum class ProgressBarMode { }; // Abstract request. -class Download { +class Request { public: - Download(RequestMethod method, const std::string &url, const std::string &name, bool *cancelled, ProgressBarMode mode); - virtual ~Download() {} + Request(RequestMethod method, const std::string &url, const std::string &name, bool *cancelled, ProgressBarMode mode); + virtual ~Request() {} void SetAccept(const char *mime) { acceptMime_ = mime; @@ -36,7 +36,7 @@ public: // NOTE: Completion callbacks (which these are) are deferred until RunCallback is called. This is so that // the call will end up on the thread that calls g_DownloadManager.Update(). - void SetCallback(std::function callback) { + void SetCallback(std::function callback) { callback_ = callback; } void RunCallback() { @@ -67,7 +67,7 @@ public: virtual const Buffer &buffer() const = 0; protected: - std::function callback_; + std::function callback_; RequestMethod method_; std::string url_; std::string name_; @@ -76,8 +76,6 @@ protected: net::RequestProgress progress_; ProgressBarMode progressBarMode_; - -private: }; using std::shared_ptr; @@ -88,22 +86,22 @@ public: CancelAll(); } - std::shared_ptr StartDownload(const std::string &url, const Path &outfile, ProgressBarMode mode, const char *acceptMime = nullptr); + std::shared_ptr StartDownload(const std::string &url, const Path &outfile, ProgressBarMode mode, const char *acceptMime = nullptr); - std::shared_ptr StartDownloadWithCallback( + std::shared_ptr StartDownloadWithCallback( const std::string &url, const Path &outfile, ProgressBarMode mode, - std::function callback, + std::function callback, const std::string &name = "", const char *acceptMime = nullptr); - std::shared_ptr AsyncPostWithCallback( + std::shared_ptr AsyncPostWithCallback( const std::string &url, const std::string &postData, const std::string &postMime, // Use postMime = "application/x-www-form-urlencoded" for standard form-style posts, such as used by retroachievements. For encoding form data manually we have MultipartFormDataEncoder. ProgressBarMode mode, - std::function callback, + std::function callback, const std::string &name = ""); // Drops finished downloads from the list. @@ -118,10 +116,10 @@ public: private: bool IsHttpsUrl(const std::string &url); - std::vector> downloads_; + std::vector> downloads_; // These get copied to downloads_ in Update(). It's so that callbacks can add new downloads // while running. - std::vector> newDownloads_; + std::vector> newDownloads_; std::string userAgent_; }; diff --git a/Common/Net/HTTPServer.cpp b/Common/Net/HTTPServer.cpp index e1fa53bc6e..3822083b79 100644 --- a/Common/Net/HTTPServer.cpp +++ b/Common/Net/HTTPServer.cpp @@ -60,7 +60,7 @@ namespace http { // Note: charset here helps prevent XSS. const char *const DEFAULT_MIME_TYPE = "text/html; charset=utf-8"; -Request::Request(int fd) +ServerRequest::ServerRequest(int fd) : fd_(fd) { in_ = new net::InputSink(fd); out_ = new net::OutputSink(fd); @@ -73,7 +73,7 @@ Request::Request(int fd) } } -Request::~Request() { +ServerRequest::~ServerRequest() { Close(); if (!in_->Empty()) { @@ -86,7 +86,7 @@ Request::~Request() { delete out_; } -void Request::WriteHttpResponseHeader(const char *ver, int status, int64_t size, const char *mimeType, const char *otherHeaders) const { +void ServerRequest::WriteHttpResponseHeader(const char *ver, int status, int64_t size, const char *mimeType, const char *otherHeaders) const { const char *statusStr; switch (status) { case 200: statusStr = "OK"; break; @@ -123,18 +123,18 @@ void Request::WriteHttpResponseHeader(const char *ver, int status, int64_t size, buffer->Push("\r\n"); } -void Request::WritePartial() const { +void ServerRequest::WritePartial() const { _assert_(fd_); out_->Flush(); } -void Request::Write() { +void ServerRequest::Write() { _assert_(fd_); WritePartial(); Close(); } -void Request::Close() { +void ServerRequest::Close() { if (fd_) { closesocket(fd_); fd_ = 0; @@ -317,7 +317,7 @@ void Server::Stop() { } void Server::HandleConnection(int conn_fd) { - Request request(conn_fd); + ServerRequest request(conn_fd); if (!request.IsOK()) { WARN_LOG(IO, "Bad request, ignoring."); return; @@ -331,11 +331,11 @@ void Server::HandleConnection(int conn_fd) { request.Write(); } -void Server::HandleRequest(const Request &request) { +void Server::HandleRequest(const ServerRequest &request) { HandleRequestDefault(request); } -void Server::HandleRequestDefault(const Request &request) { +void Server::HandleRequestDefault(const ServerRequest &request) { if (request.resource() == nullptr) { fallback_(request); return; @@ -350,14 +350,14 @@ void Server::HandleRequestDefault(const Request &request) { } } -void Server::Handle404(const Request &request) { +void Server::Handle404(const ServerRequest &request) { INFO_LOG(IO, "No handler for '%s', falling back to 404.", request.resource()); const char *payload = "404 not found\r\n"; request.WriteHttpResponseHeader("1.0", 404, (int)strlen(payload)); request.Out()->Push(payload); } -void Server::HandleListing(const Request &request) { +void Server::HandleListing(const ServerRequest &request) { request.WriteHttpResponseHeader("1.0", 200, -1, "text/plain"); for (auto iter = handlers_.begin(); iter != handlers_.end(); ++iter) { request.Out()->Printf("%s\n", iter->first.c_str()); diff --git a/Common/Net/HTTPServer.h b/Common/Net/HTTPServer.h index 40e336bb5a..c9051226a6 100644 --- a/Common/Net/HTTPServer.h +++ b/Common/Net/HTTPServer.h @@ -25,10 +25,10 @@ class OutputSink; namespace http { -class Request { +class ServerRequest { public: - Request(int fd); - ~Request(); + ServerRequest(int fd); + ~ServerRequest(); const char *resource() const { return header_.resource; @@ -75,7 +75,7 @@ public: Server(NewThreadExecutor *executor); virtual ~Server(); - typedef std::function UrlHandlerFunc; + typedef std::function UrlHandlerFunc; typedef std::map UrlHandlerMap; // Runs forever, serving request. If you want to do something else than serve pages, @@ -94,7 +94,7 @@ public: // If you want to customize things at a lower level than just a simple path handler, // then inherit and override this. Implementations should forward to HandleRequestDefault // if they don't recognize the url. - virtual void HandleRequest(const Request &request); + virtual void HandleRequest(const ServerRequest &request); int Port() { return port_; @@ -107,11 +107,11 @@ private: void HandleConnection(int conn_fd); // Things like default 404, etc. - void HandleRequestDefault(const Request &request); + void HandleRequestDefault(const ServerRequest &request); // Neat built-in handlers that are tied to the server. - void HandleListing(const Request &request); - void Handle404(const Request &request); + void HandleListing(const ServerRequest &request); + void Handle404(const ServerRequest &request); int listener_; int port_ = 0; diff --git a/Common/Net/WebsocketServer.cpp b/Common/Net/WebsocketServer.cpp index 3b6f98ed27..e55c0644f7 100644 --- a/Common/Net/WebsocketServer.cpp +++ b/Common/Net/WebsocketServer.cpp @@ -69,7 +69,7 @@ static bool ListContainsNoCase(const std::string &list, const std::string value) return false; } -WebSocketServer *WebSocketServer::CreateAsUpgrade(const http::Request &request, const std::string &protocol) { +WebSocketServer *WebSocketServer::CreateAsUpgrade(const http::ServerRequest &request, const std::string &protocol) { auto requireHeader = [&](const char *name, const char *expected) { std::string val; if (!request.GetHeader(name, &val)) { diff --git a/Common/Net/WebsocketServer.h b/Common/Net/WebsocketServer.h index 7a05b0f03a..591e800e94 100644 --- a/Common/Net/WebsocketServer.h +++ b/Common/Net/WebsocketServer.h @@ -29,7 +29,7 @@ enum class WebSocketClose : uint16_t { // RFC 6455 class WebSocketServer { public: - static WebSocketServer *CreateAsUpgrade(const http::Request &request, const std::string &protocol = ""); + static WebSocketServer *CreateAsUpgrade(const http::ServerRequest &request, const std::string &protocol = ""); void Send(const std::string &str); void Send(const std::vector &payload); diff --git a/Core/Config.cpp b/Core/Config.cpp index 70eb254f2e..820cf0e8c6 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1363,7 +1363,7 @@ void Config::NotifyUpdatedCpuCore() { #define PPSSPP_GIT_VERSION "v0.0.1-gaaaaaaaaa" #endif -void Config::DownloadCompletedCallback(http::Download &download) { +void Config::DownloadCompletedCallback(http::Request &download) { if (download.ResultCode() != 200) { ERROR_LOG(LOADER, "Failed to download %s: %d", download.url().c_str(), download.ResultCode()); return; diff --git a/Core/Config.h b/Core/Config.h index 98edbd35b5..d62d846a0f 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -41,7 +41,7 @@ enum ChatPositions { }; namespace http { - class Download; + class Request; class RequestManager; } @@ -543,7 +543,7 @@ public: void RemoveRecent(const std::string &file); void CleanRecent(); - static void DownloadCompletedCallback(http::Download &download); + static void DownloadCompletedCallback(http::Request &download); void DismissUpgrade(); void ResetControlLayout(); diff --git a/Core/Debugger/WebSocket.cpp b/Core/Debugger/WebSocket.cpp index e704a5c00e..1ba39ad0ec 100644 --- a/Core/Debugger/WebSocket.cpp +++ b/Core/Debugger/WebSocket.cpp @@ -131,7 +131,7 @@ static void SetupDebuggerLock() { } } -void HandleDebuggerRequest(const http::Request &request) { +void HandleDebuggerRequest(const http::ServerRequest &request) { net::WebSocketServer *ws = net::WebSocketServer::CreateAsUpgrade(request, "debugger.ppsspp.org"); if (!ws) return; diff --git a/Core/Debugger/WebSocket.h b/Core/Debugger/WebSocket.h index 0151ca686a..f05856db20 100644 --- a/Core/Debugger/WebSocket.h +++ b/Core/Debugger/WebSocket.h @@ -18,9 +18,9 @@ #pragma once namespace http { -class Request; +class ServerRequest; } -void HandleDebuggerRequest(const http::Request &request); +void HandleDebuggerRequest(const http::ServerRequest &request); // Note: blocks. void StopAllDebuggers(); diff --git a/Core/RetroAchievements.cpp b/Core/RetroAchievements.cpp index 3821470ada..9bac7b9c5e 100644 --- a/Core/RetroAchievements.cpp +++ b/Core/RetroAchievements.cpp @@ -177,7 +177,7 @@ static void server_call_callback(const rc_api_request_t *request, // If post data is provided, we need to make a POST request, otherwise, a GET request will suffice. auto ac = GetI18NCategory(I18NCat::ACHIEVEMENTS); if (request->post_data) { - std::shared_ptr download = g_DownloadManager.AsyncPostWithCallback(std::string(request->url), std::string(request->post_data), "application/x-www-form-urlencoded", http::ProgressBarMode::DELAYED, [=](http::Download &download) { + std::shared_ptr download = g_DownloadManager.AsyncPostWithCallback(std::string(request->url), std::string(request->post_data), "application/x-www-form-urlencoded", http::ProgressBarMode::DELAYED, [=](http::Request &download) { std::string buffer; download.buffer().TakeAll(&buffer); rc_api_server_response_t response{}; @@ -187,7 +187,7 @@ static void server_call_callback(const rc_api_request_t *request, callback(&response, callback_data); }, ac->T("Contacting RetroAchievements server...")); } else { - std::shared_ptr download = g_DownloadManager.StartDownloadWithCallback(std::string(request->url), Path(), http::ProgressBarMode::DELAYED, [=](http::Download &download) { + std::shared_ptr download = g_DownloadManager.StartDownloadWithCallback(std::string(request->url), Path(), http::ProgressBarMode::DELAYED, [=](http::Request &download) { std::string buffer; download.buffer().TakeAll(&buffer); rc_api_server_response_t response{}; @@ -543,7 +543,7 @@ bool HasAchievementsOrLeaderboards() { void DownloadImageIfMissing(const std::string &cache_key, std::string &&url) { if (g_iconCache.MarkPending(cache_key)) { INFO_LOG(ACHIEVEMENTS, "Downloading image: %s (%s)", url.c_str(), cache_key.c_str()); - g_DownloadManager.StartDownloadWithCallback(url, Path(), http::ProgressBarMode::NONE, [cache_key](http::Download &download) { + g_DownloadManager.StartDownloadWithCallback(url, Path(), http::ProgressBarMode::NONE, [cache_key](http::Request &download) { if (download.ResultCode() != 200) return; std::string data; diff --git a/Core/Util/GameManager.h b/Core/Util/GameManager.h index 336a38908f..8aff30da05 100644 --- a/Core/Util/GameManager.h +++ b/Core/Util/GameManager.h @@ -91,7 +91,7 @@ private: std::string GetGameID(const Path &path) const; std::string GetPBPGameID(FileLoader *loader) const; std::string GetISOGameID(FileLoader *loader) const; - std::shared_ptr curDownload_; + std::shared_ptr curDownload_; std::shared_ptr installThread_; bool installInProgress_ = false; bool installDonePending_ = false; diff --git a/Core/WebServer.cpp b/Core/WebServer.cpp index c530fdb83d..83a6f86574 100644 --- a/Core/WebServer.cpp +++ b/Core/WebServer.cpp @@ -159,7 +159,7 @@ static Path LocalFromRemotePath(const std::string &path) { return Path(); } -static void DiscHandler(const http::Request &request, const Path &filename) { +static void DiscHandler(const http::ServerRequest &request, const Path &filename) { s64 sz = File::GetFileSize(filename); std::string range; @@ -211,7 +211,7 @@ static void DiscHandler(const http::Request &request, const Path &filename) { } } -static void HandleListing(const http::Request &request) { +static void HandleListing(const http::ServerRequest &request) { AndroidJNIThreadContext jniContext; request.WriteHttpResponseHeader("1.0", 200, -1, "text/plain"); @@ -230,7 +230,7 @@ static void HandleListing(const http::Request &request) { } } -static bool ServeDebuggerFile(const http::Request &request) { +static bool ServeDebuggerFile(const http::ServerRequest &request) { // Skip the slash at the start of the resource path. const char *filename = request.resource() + 1; if (strstr(filename, "..") != nullptr) @@ -264,13 +264,13 @@ static bool ServeDebuggerFile(const http::Request &request) { return true; } -static void RedirectToDebugger(const http::Request &request) { +static void RedirectToDebugger(const http::ServerRequest &request) { static const std::string payload = "Redirecting to debugger UI...\r\n"; request.WriteHttpResponseHeader("1.0", 301, (int)payload.size(), "text/plain", "Location: /debugger/index.html\r\n"); request.Out()->Push(payload); } -static void HandleFallback(const http::Request &request) { +static void HandleFallback(const http::ServerRequest &request) { AndroidJNIThreadContext jniContext; if (serverFlags & (int)WebServerFlags::DISCS) { @@ -296,7 +296,7 @@ static void HandleFallback(const http::Request &request) { request.Out()->Push(payload); } -static void ForwardDebuggerRequest(const http::Request &request) { +static void ForwardDebuggerRequest(const http::ServerRequest &request) { AndroidJNIThreadContext jniContext; if (serverFlags & (int)WebServerFlags::DEBUGGER) { diff --git a/UI/DevScreens.h b/UI/DevScreens.h index 776c6bb8e8..743b83af08 100644 --- a/UI/DevScreens.h +++ b/UI/DevScreens.h @@ -218,8 +218,8 @@ private: UI::EventReturn OnLoadDump(UI::EventParams &e); std::vector files_; - std::shared_ptr listing_; - std::shared_ptr dumpDownload_; + std::shared_ptr listing_; + std::shared_ptr dumpDownload_; }; void DrawProfile(UIContext &ui); diff --git a/UI/Store.cpp b/UI/Store.cpp index dbe14d46dd..7a7f91a09a 100644 --- a/UI/Store.cpp +++ b/UI/Store.cpp @@ -63,7 +63,7 @@ public: if (useIconCache && g_iconCache.MarkPending(path_)) { const char *acceptMime = "image/png, image/jpeg, image/*; q=0.9, */*; q=0.8"; - requestManager_->StartDownloadWithCallback(path_, Path(), http::ProgressBarMode::DELAYED, [&](http::Download &download) { + requestManager_->StartDownloadWithCallback(path_, Path(), http::ProgressBarMode::DELAYED, [&](http::Request &download) { if (download.ResultCode() == 200) { std::string data; download.buffer().TakeAll(&data); @@ -98,7 +98,7 @@ public: const std::string &GetFilename() const { return path_; } private: - void DownloadCompletedCallback(http::Download &download); + void DownloadCompletedCallback(http::Request &download); bool canFocus_ = false; bool useIconCache_ = false; @@ -106,7 +106,7 @@ private: uint32_t color_ = 0xFFFFFFFF; UI::ImageSizeMode sizeMode_; http::RequestManager *requestManager_; - std::shared_ptr download_; + std::shared_ptr download_; std::string textureData_; std::unique_ptr texture_; @@ -155,7 +155,7 @@ void HttpImageFileView::SetFilename(std::string filename) { } } -void HttpImageFileView::DownloadCompletedCallback(http::Download &download) { +void HttpImageFileView::DownloadCompletedCallback(http::Request &download) { if (download.IsCancelled()) { // We were probably destroyed. Can't touch "this" (heh). return; diff --git a/UI/Store.h b/UI/Store.h index 0c4677d511..3c0be4668d 100644 --- a/UI/Store.h +++ b/UI/Store.h @@ -78,8 +78,8 @@ private: std::string GetTranslatedString(const json::JsonGet json, std::string key, const char *fallback = nullptr) const; - std::shared_ptr listing_; - std::shared_ptr image_; + std::shared_ptr listing_; + std::shared_ptr image_; // TODO: Replace with a PathBrowser or similar. Though that one only supports // local filesystems at the moment.