From 30c7f6ded7b6d54e797cf48b9257149ed914bc6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Thu, 7 Mar 2019 14:33:19 +0100 Subject: [PATCH] Rename Download* to Request* and move HTTP stuff inside src/client/http --- src/PowderToySDL.cpp | 2 - src/client/Client.cpp | 48 ++++++------- src/client/Client.h | 8 +-- src/client/{ => http}/APIRequest.cpp | 4 +- src/client/{ => http}/APIRequest.h | 4 +- src/client/{ => http}/AvatarRequest.cpp | 0 src/client/{ => http}/AvatarRequest.h | 0 src/client/{ => http}/GetUserInfoRequest.cpp | 0 src/client/{ => http}/GetUserInfoRequest.h | 4 +- src/client/{ => http}/HTTP.cpp | 4 +- src/client/{ => http}/HTTP.h | 0 src/client/{ => http}/ImageRequest.cpp | 4 +- src/client/{ => http}/ImageRequest.h | 4 +- src/client/{Download.cpp => http/Request.cpp} | 68 +++++++++---------- src/client/{Download.h => http/Request.h} | 10 +-- .../RequestManager.cpp} | 40 +++++------ .../RequestManager.h} | 14 ++-- src/client/{ => http}/RequestMonitor.h | 0 src/client/{ => http}/SaveUserInfoRequest.cpp | 0 src/client/{ => http}/SaveUserInfoRequest.h | 4 +- src/client/{ => http}/ThumbnailRequest.cpp | 0 src/client/{ => http}/ThumbnailRequest.h | 0 src/gui/interface/AvatarButton.h | 4 +- src/gui/interface/SaveButton.h | 4 +- src/gui/preview/PreviewModel.cpp | 10 +-- src/gui/preview/PreviewModel.h | 8 +-- src/gui/profile/ProfileActivity.h | 6 +- src/gui/update/UpdateActivity.cpp | 6 +- src/lua/LegacyLuaAPI.cpp | 4 +- src/lua/LuaScriptInterface.cpp | 1 - 30 files changed, 129 insertions(+), 132 deletions(-) rename src/client/{ => http}/APIRequest.cpp (85%) rename src/client/{ => http}/APIRequest.h (85%) rename src/client/{ => http}/AvatarRequest.cpp (100%) rename src/client/{ => http}/AvatarRequest.h (100%) rename src/client/{ => http}/GetUserInfoRequest.cpp (100%) rename src/client/{ => http}/GetUserInfoRequest.h (88%) rename src/client/{ => http}/HTTP.cpp (99%) rename src/client/{ => http}/HTTP.h (100%) rename src/client/{ => http}/ImageRequest.cpp (92%) rename src/client/{ => http}/ImageRequest.h (84%) rename src/client/{Download.cpp => http/Request.cpp} (64%) rename src/client/{Download.h => http/Request.h} (88%) rename src/client/{DownloadManager.cpp => http/RequestManager.cpp} (76%) rename src/client/{DownloadManager.h => http/RequestManager.h} (73%) rename src/client/{ => http}/RequestMonitor.h (100%) rename src/client/{ => http}/SaveUserInfoRequest.cpp (100%) rename src/client/{ => http}/SaveUserInfoRequest.h (87%) rename src/client/{ => http}/ThumbnailRequest.cpp (100%) rename src/client/{ => http}/ThumbnailRequest.h (100%) diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index 3191588a09..963c2783fa 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -51,8 +51,6 @@ #include "gui/interface/Keys.h" #include "gui/Style.h" -#include "client/HTTP.h" - using namespace std; #define INCLUDE_SYSWM diff --git a/src/client/Client.cpp b/src/client/Client.cpp index b7239b390e..37f68dbced 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -43,8 +43,8 @@ #include "client/UserInfo.h" #include "gui/preview/Comment.h" #include "ClientListener.h" -#include "client/Download.h" -#include "client/DownloadManager.h" +#include "client/http/Request.h" +#include "client/http/RequestManager.h" #include "json/json.h" @@ -111,7 +111,7 @@ void Client::Initialise(ByteString proxyString) update_finish(); } - http::DownloadManager::Ref().Initialise(proxyString); + http::RequestManager::Ref().Initialise(proxyString); //Read stamps library std::ifstream stampsLib; @@ -128,7 +128,7 @@ void Client::Initialise(ByteString proxyString) stampsLib.close(); //Begin version check - versionCheckRequest = new http::Download("http://" SERVER "/Startup.json"); + versionCheckRequest = new http::Request("http://" SERVER "/Startup.json"); if (authUser.UserID) { @@ -138,7 +138,7 @@ void Client::Initialise(ByteString proxyString) #ifdef UPDATESERVER // use an alternate update server - alternateVersionCheckRequest = new http::Download("http://" UPDATESERVER "/Startup.json"); + alternateVersionCheckRequest = new http::Request("http://" UPDATESERVER "/Startup.json"); usingAltUpdateServer = true; if (authUser.UserID) { @@ -718,7 +718,7 @@ void Client::Tick() } } -bool Client::CheckUpdate(http::Download *updateRequest, bool checkSession) +bool Client::CheckUpdate(http::Request *updateRequest, bool checkSession) { //Check status on version check request if (updateRequest->CheckDone()) @@ -913,7 +913,7 @@ void Client::WritePrefs() void Client::Shutdown() { - http::DownloadManager::Ref().Shutdown(); + http::RequestManager::Ref().Shutdown(); //Save config WritePrefs(); @@ -976,7 +976,7 @@ RequestStatus Client::UploadSave(SaveInfo & save) } #endif - data = http::Download::SimpleAuth("http://" SERVER "/Save.api", &dataStatus, userID, authUser.SessionID, { + data = http::Request::SimpleAuth("http://" SERVER "/Save.api", &dataStatus, userID, authUser.SessionID, { { "Name", save.GetName().ToUtf8() }, { "Description", save.GetDescription().ToUtf8() }, { "Data:save.bin", ByteString(gameData, gameData + gameDataLength) }, @@ -1172,7 +1172,7 @@ RequestStatus Client::ExecVote(int saveID, int direction) { ByteString saveIDText = ByteString::Build(saveID); ByteString userIDText = ByteString::Build(authUser.UserID); - data = http::Download::SimpleAuth("http://" SERVER "/Vote.api", &dataStatus, userIDText, authUser.SessionID, { + data = http::Request::SimpleAuth("http://" SERVER "/Vote.api", &dataStatus, userIDText, authUser.SessionID, { { "ID", saveIDText }, { "Action", direction == 1 ? "Up" : "Down" }, }); @@ -1198,7 +1198,7 @@ unsigned char * Client::GetSaveData(int saveID, int saveDate, int & dataLength) else urlStr = ByteString::Build("http://", STATICSERVER, "/", saveID, ".cps"); - data = http::Download::Simple(urlStr, &dataStatus); + data = http::Request::Simple(urlStr, &dataStatus); // will always return failure ParseServerReturn(data, dataStatus, false); @@ -1244,7 +1244,7 @@ LoginStatus Client::Login(ByteString username, ByteString password, User & user) ByteString data; int dataStatus; - data = http::Download::Simple("http://" SERVER "/Login.json", &dataStatus, { + data = http::Request::Simple("http://" SERVER "/Login.json", &dataStatus, { { "Username", username }, { "Hash", totalHash }, }); @@ -1304,7 +1304,7 @@ RequestStatus Client::DeleteSave(int saveID) if(authUser.UserID) { ByteString userID = ByteString::Build(authUser.UserID); - data = http::Download::SimpleAuth(url, &dataStatus, userID, authUser.SessionID); + data = http::Request::SimpleAuth(url, &dataStatus, userID, authUser.SessionID); } else { @@ -1324,7 +1324,7 @@ RequestStatus Client::AddComment(int saveID, String comment) if(authUser.UserID) { ByteString userID = ByteString::Build(authUser.UserID); - data = http::Download::SimpleAuth(url, &dataStatus, userID, authUser.SessionID, { + data = http::Request::SimpleAuth(url, &dataStatus, userID, authUser.SessionID, { { "Comment", comment.ToUtf8() }, }); } @@ -1349,7 +1349,7 @@ RequestStatus Client::FavouriteSave(int saveID, bool favourite) if(authUser.UserID) { ByteString userID = ByteString::Build(authUser.UserID); - data = http::Download::SimpleAuth(urlStream.Build(), &dataStatus, userID, authUser.SessionID); + data = http::Request::SimpleAuth(urlStream.Build(), &dataStatus, userID, authUser.SessionID); } else { @@ -1369,7 +1369,7 @@ RequestStatus Client::ReportSave(int saveID, String message) if(authUser.UserID) { ByteString userID = ByteString::Build(authUser.UserID); - data = http::Download::SimpleAuth(url, &dataStatus, userID, authUser.SessionID, { + data = http::Request::SimpleAuth(url, &dataStatus, userID, authUser.SessionID, { { "Reason", message.ToUtf8() }, }); } @@ -1391,7 +1391,7 @@ RequestStatus Client::UnpublishSave(int saveID) if(authUser.UserID) { ByteString userID = ByteString::Build(authUser.UserID); - data = http::Download::SimpleAuth(url, &dataStatus, userID, authUser.SessionID); + data = http::Request::SimpleAuth(url, &dataStatus, userID, authUser.SessionID); } else { @@ -1411,7 +1411,7 @@ RequestStatus Client::PublishSave(int saveID) if (authUser.UserID) { ByteString userID = ByteString::Build(authUser.UserID); - data = http::Download::SimpleAuth(url, &dataStatus, userID, authUser.SessionID, { + data = http::Request::SimpleAuth(url, &dataStatus, userID, authUser.SessionID, { { "ActionPublish", "bagels" }, }); } @@ -1439,11 +1439,11 @@ SaveInfo * Client::GetSave(int saveID, int saveDate) { ByteString userID = ByteString::Build(authUser.UserID); - data = http::Download::SimpleAuth(urlStream.Build(), &dataStatus, userID, authUser.SessionID); + data = http::Request::SimpleAuth(urlStream.Build(), &dataStatus, userID, authUser.SessionID); } else { - data = http::Download::Simple(urlStream.Build(), &dataStatus); + data = http::Request::Simple(urlStream.Build(), &dataStatus); } if(dataStatus == 200 && data.size()) { @@ -1511,7 +1511,7 @@ std::vector > * Client::GetTags(int start, int count, urlStream << format::URLEncode(query.ToUtf8()); } - data = http::Download::Simple(urlStream.Build(), &dataStatus); + data = http::Request::Simple(urlStream.Build(), &dataStatus); if(dataStatus == 200 && data.size()) { try @@ -1569,11 +1569,11 @@ std::vector * Client::SearchSaves(int start, int count, String query, if(authUser.UserID) { ByteString userID = ByteString::Build(authUser.UserID); - data = http::Download::SimpleAuth(urlStream.Build(), &dataStatus, userID, authUser.SessionID); + data = http::Request::SimpleAuth(urlStream.Build(), &dataStatus, userID, authUser.SessionID); } else { - data = http::Download::Simple(urlStream.Build(), &dataStatus); + data = http::Request::Simple(urlStream.Build(), &dataStatus); } ParseServerReturn(data, dataStatus, true); if (dataStatus == 200 && data.size()) @@ -1621,7 +1621,7 @@ std::list * Client::RemoveTag(int saveID, ByteString tag) if(authUser.UserID) { ByteString userID = ByteString::Build(authUser.UserID); - data = http::Download::SimpleAuth(url, &dataStatus, userID, authUser.SessionID); + data = http::Request::SimpleAuth(url, &dataStatus, userID, authUser.SessionID); } else { @@ -1660,7 +1660,7 @@ std::list * Client::AddTag(int saveID, ByteString tag) if(authUser.UserID) { ByteString userID = ByteString::Build(authUser.UserID); - data = http::Download::SimpleAuth(url, &dataStatus, userID, authUser.SessionID); + data = http::Request::SimpleAuth(url, &dataStatus, userID, authUser.SessionID); } else { diff --git a/src/client/Client.h b/src/client/Client.h index 1cc5764ab9..7eecf474ed 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -48,15 +48,15 @@ class RequestListener; class ClientListener; namespace http { - class Download; + class Request; } class Client: public Singleton { private: String messageOfTheDay; std::vector > serverNotifications; - http::Download *versionCheckRequest; - http::Download *alternateVersionCheckRequest; + http::Request *versionCheckRequest; + http::Request *alternateVersionCheckRequest; bool usingAltUpdateServer; bool updateAvailable; UpdateInfo updateInfo; @@ -167,7 +167,7 @@ class Client: public Singleton { } RequestStatus ParseServerReturn(ByteString &result, int status, bool json); void Tick(); - bool CheckUpdate(http::Download *updateRequest, bool checkSession); + bool CheckUpdate(http::Request *updateRequest, bool checkSession); void Shutdown(); // preferences functions diff --git a/src/client/APIRequest.cpp b/src/client/http/APIRequest.cpp similarity index 85% rename from src/client/APIRequest.cpp rename to src/client/http/APIRequest.cpp index 6b8d2c340a..bfc5b7e03f 100644 --- a/src/client/APIRequest.cpp +++ b/src/client/http/APIRequest.cpp @@ -4,7 +4,7 @@ namespace http { - APIRequest::APIRequest(ByteString url) : Download(url) + APIRequest::APIRequest(ByteString url) : Request(url) { User user = Client::Ref().GetAuthUser(); AuthHeaders(ByteString::Build(user.UserID), user.SessionID); @@ -19,7 +19,7 @@ namespace http Result result; try { - ByteString data = Download::Finish(&result.status); + ByteString data = Request::Finish(&result.status); Client::Ref().ParseServerReturn(data, result.status, true); if (result.status == 200 && data.size()) { diff --git a/src/client/APIRequest.h b/src/client/http/APIRequest.h similarity index 85% rename from src/client/APIRequest.h rename to src/client/http/APIRequest.h index 2863f58edb..10ee36d414 100644 --- a/src/client/APIRequest.h +++ b/src/client/http/APIRequest.h @@ -1,7 +1,7 @@ #ifndef APIREQUEST2_H #define APIREQUEST2_H -#include "Download.h" +#include "Request.h" #include "common/String.h" #include "json/json.h" @@ -10,7 +10,7 @@ namespace http { - class APIRequest : public Download + class APIRequest : public Request { public: struct Result diff --git a/src/client/AvatarRequest.cpp b/src/client/http/AvatarRequest.cpp similarity index 100% rename from src/client/AvatarRequest.cpp rename to src/client/http/AvatarRequest.cpp diff --git a/src/client/AvatarRequest.h b/src/client/http/AvatarRequest.h similarity index 100% rename from src/client/AvatarRequest.h rename to src/client/http/AvatarRequest.h diff --git a/src/client/GetUserInfoRequest.cpp b/src/client/http/GetUserInfoRequest.cpp similarity index 100% rename from src/client/GetUserInfoRequest.cpp rename to src/client/http/GetUserInfoRequest.cpp diff --git a/src/client/GetUserInfoRequest.h b/src/client/http/GetUserInfoRequest.h similarity index 88% rename from src/client/GetUserInfoRequest.h rename to src/client/http/GetUserInfoRequest.h index 65dfa4cf6e..03be3de633 100644 --- a/src/client/GetUserInfoRequest.h +++ b/src/client/http/GetUserInfoRequest.h @@ -1,11 +1,11 @@ #ifndef GETUSERINFOREQUEST2_H #define GETUSERINFOREQUEST2_H -#include "Download.h" +#include "Request.h" #include "common/String.h" #include "json/json.h" #include "client/Client.h" -#include "client/APIRequest.h" +#include "APIRequest.h" #include #include diff --git a/src/client/HTTP.cpp b/src/client/http/HTTP.cpp similarity index 99% rename from src/client/HTTP.cpp rename to src/client/http/HTTP.cpp index b7158dcd5a..15fa2a5f44 100644 --- a/src/client/HTTP.cpp +++ b/src/client/http/HTTP.cpp @@ -51,7 +51,7 @@ #include "Config.h" #include "Misc.h" #include "HTTP.h" -#include "MD5.h" +#include "../MD5.h" #include "Platform.h" #ifdef WIN @@ -979,7 +979,7 @@ ByteString FindBoundary(std::map parts, ByteString bound // Generates a MIME multipart message to be used in POST requests // see https://en.wikipedia.org/wiki/MIME#Multipart_messages -// this function used in Download class, and eventually all http requests +// this function used in Request class, and eventually all http requests ByteString GetMultipartMessage(std::map parts, ByteString boundary) { ByteStringBuilder data; diff --git a/src/client/HTTP.h b/src/client/http/HTTP.h similarity index 100% rename from src/client/HTTP.h rename to src/client/http/HTTP.h diff --git a/src/client/ImageRequest.cpp b/src/client/http/ImageRequest.cpp similarity index 92% rename from src/client/ImageRequest.cpp rename to src/client/http/ImageRequest.cpp index c338851ed4..d7fd49de89 100644 --- a/src/client/ImageRequest.cpp +++ b/src/client/http/ImageRequest.cpp @@ -7,7 +7,7 @@ namespace http { ImageRequest::ImageRequest(ByteString url, int width, int height) : - Download(url), + Request(url), Width(width), Height(height) { @@ -19,7 +19,7 @@ namespace http std::unique_ptr ImageRequest::Finish() { - ByteString data = Download::Finish(nullptr); + ByteString data = Request::Finish(nullptr); std::unique_ptr vb; if (data.size()) { diff --git a/src/client/ImageRequest.h b/src/client/http/ImageRequest.h similarity index 84% rename from src/client/ImageRequest.h rename to src/client/http/ImageRequest.h index 606f32320a..92c5400e89 100644 --- a/src/client/ImageRequest.h +++ b/src/client/http/ImageRequest.h @@ -1,7 +1,7 @@ #ifndef IMAGEREQUEST2_H #define IMAGEREQUEST2_H -#include "Download.h" +#include "Request.h" #include "common/String.h" #include @@ -9,7 +9,7 @@ class VideoBuffer; namespace http { - class ImageRequest : public Download + class ImageRequest : public Request { int Width, Height; diff --git a/src/client/Download.cpp b/src/client/http/Request.cpp similarity index 64% rename from src/client/Download.cpp rename to src/client/http/Request.cpp index e1c71e9620..0277059542 100644 --- a/src/client/Download.cpp +++ b/src/client/http/Request.cpp @@ -1,12 +1,12 @@ #include -#include "Download.h" -#include "DownloadManager.h" +#include "Request.h" +#include "RequestManager.h" #include "HTTP.h" #include "Platform.h" namespace http { -Download::Download(ByteString uri_, bool keepAlive): +Request::Request(ByteString uri_, bool keepAlive): http(NULL), keepAlive(keepAlive), downloadData(NULL), @@ -21,11 +21,11 @@ Download::Download(ByteString uri_, bool keepAlive): downloadStarted(false) { uri = ByteString(uri_); - DownloadManager::Ref().AddDownload(this); + RequestManager::Ref().AddDownload(this); } // called by download thread itself if download was canceled -Download::~Download() +Request::~Request() { if (http && (keepAlive || downloadCanceled)) http_async_req_close(http); @@ -34,12 +34,12 @@ Download::~Download() } // add post data to a request -void Download::AddPostData(std::map data) +void Request::AddPostData(std::map data) { postDataBoundary = FindBoundary(data, ""); postData = GetMultipartMessage(data, postDataBoundary); } -void Download::AddPostData(std::pair data) +void Request::AddPostData(std::pair data) { std::map postData; postData.insert(data); @@ -47,7 +47,7 @@ void Download::AddPostData(std::pair data) } // add userID and sessionID headers to the download. Must be done after download starts for some reason -void Download::AuthHeaders(ByteString ID, ByteString session) +void Request::AuthHeaders(ByteString ID, ByteString session) { if (ID != "0") userID = ID; @@ -55,7 +55,7 @@ void Download::AuthHeaders(ByteString ID, ByteString session) } // start the download thread -void Download::Start() +void Request::Start() { if (CheckStarted() || CheckDone()) return; @@ -65,19 +65,19 @@ void Download::Start() http_auth_headers(http, userID.c_str(), NULL, userSession.c_str()); if (postDataBoundary.length()) http_add_multipart_header(http, postDataBoundary); - DownloadManager::Ref().Lock(); + RequestManager::Ref().Lock(); downloadStarted = true; - DownloadManager::Ref().Unlock(); + RequestManager::Ref().Unlock(); } // finish the download (if called before the download is done, this will block) -ByteString Download::Finish(int *status) +ByteString Request::Finish(int *status) { if (CheckCanceled()) return ""; // shouldn't happen but just in case while (!CheckDone()); // block - DownloadManager::Ref().Lock(); + RequestManager::Ref().Lock(); downloadStarted = false; if (status) *status = downloadStatus; @@ -90,60 +90,60 @@ ByteString Download::Finish(int *status) downloadData = NULL; if (!keepAlive) downloadCanceled = true; - DownloadManager::Ref().Unlock(); + RequestManager::Ref().Unlock(); return ret; } // returns the download size and progress (if the download has the correct length headers) -void Download::CheckProgress(int *total, int *done) +void Request::CheckProgress(int *total, int *done) { - DownloadManager::Ref().Lock(); + RequestManager::Ref().Lock(); if (!downloadFinished && http) http_async_get_length(http, total, done); else *total = *done = 0; - DownloadManager::Ref().Unlock(); + RequestManager::Ref().Unlock(); } // returns true if the download has finished -bool Download::CheckDone() +bool Request::CheckDone() { - DownloadManager::Ref().Lock(); + RequestManager::Ref().Lock(); bool ret = downloadFinished; - DownloadManager::Ref().Unlock(); + RequestManager::Ref().Unlock(); return ret; } // returns true if the download was canceled -bool Download::CheckCanceled() +bool Request::CheckCanceled() { - DownloadManager::Ref().Lock(); + RequestManager::Ref().Lock(); bool ret = downloadCanceled; - DownloadManager::Ref().Unlock(); + RequestManager::Ref().Unlock(); return ret; } // returns true if the download is running -bool Download::CheckStarted() +bool Request::CheckStarted() { - DownloadManager::Ref().Lock(); + RequestManager::Ref().Lock(); bool ret = downloadStarted; - DownloadManager::Ref().Unlock(); + RequestManager::Ref().Unlock(); return ret; } -// cancels the download, the download thread will delete the Download* when it finishes (do not use Download in any way after canceling) -void Download::Cancel() +// cancels the download, the download thread will delete the Request* when it finishes (do not use Request in any way after canceling) +void Request::Cancel() { - DownloadManager::Ref().Lock(); + RequestManager::Ref().Lock(); downloadCanceled = true; - DownloadManager::Ref().Unlock(); + RequestManager::Ref().Unlock(); } -ByteString Download::Simple(ByteString uri, int *status, std::map post_data) +ByteString Request::Simple(ByteString uri, int *status, std::map post_data) { - Download *request = new Download(uri); + Request *request = new Request(uri); request->AddPostData(post_data); request->Start(); while(!request->CheckDone()) @@ -153,9 +153,9 @@ ByteString Download::Simple(ByteString uri, int *status, std::mapFinish(status); } -ByteString Download::SimpleAuth(ByteString uri, int *status, ByteString ID, ByteString session, std::map post_data) +ByteString Request::SimpleAuth(ByteString uri, int *status, ByteString ID, ByteString session, std::map post_data) { - Download *request = new Download(uri); + Request *request = new Request(uri); request->AddPostData(post_data); request->AuthHeaders(ID, session); request->Start(); diff --git a/src/client/Download.h b/src/client/http/Request.h similarity index 88% rename from src/client/Download.h rename to src/client/http/Request.h index f507202780..da7827a159 100644 --- a/src/client/Download.h +++ b/src/client/http/Request.h @@ -5,8 +5,8 @@ namespace http { -class DownloadManager; -class Download +class RequestManager; +class Request { ByteString uri; void *http; @@ -27,8 +27,8 @@ class Download volatile bool downloadStarted; public: - Download(ByteString uri, bool keepAlive = false); - virtual ~Download(); + Request(ByteString uri, bool keepAlive = false); + virtual ~Request(); void AddPostData(std::map data); void AddPostData(std::pair data); @@ -42,7 +42,7 @@ class Download bool CheckCanceled(); bool CheckStarted(); - friend class DownloadManager; + friend class RequestManager; static ByteString Simple(ByteString uri, int *status, std::map post_data = {}); static ByteString SimpleAuth(ByteString uri, int *status, ByteString ID, ByteString session, std::map post_data = {}); diff --git a/src/client/DownloadManager.cpp b/src/client/http/RequestManager.cpp similarity index 76% rename from src/client/DownloadManager.cpp rename to src/client/http/RequestManager.cpp index 777aa0ddb1..93ab9209e4 100644 --- a/src/client/DownloadManager.cpp +++ b/src/client/http/RequestManager.cpp @@ -1,35 +1,35 @@ -#include "DownloadManager.h" -#include "Download.h" +#include "RequestManager.h" +#include "Request.h" #include "HTTP.h" #include "Config.h" #include "Platform.h" namespace http { -DownloadManager::DownloadManager(): +RequestManager::RequestManager(): threadStarted(false), lastUsed(time(NULL)), managerRunning(false), managerShutdown(false), - downloads(std::vector()), - downloadsAddQueue(std::vector()) + downloads(std::vector()), + downloadsAddQueue(std::vector()) { pthread_mutex_init(&downloadLock, NULL); pthread_mutex_init(&downloadAddLock, NULL); } -DownloadManager::~DownloadManager() +RequestManager::~RequestManager() { } -void DownloadManager::Shutdown() +void RequestManager::Shutdown() { pthread_mutex_lock(&downloadLock); pthread_mutex_lock(&downloadAddLock); - for (std::vector::iterator iter = downloads.begin(); iter != downloads.end(); ++iter) + for (std::vector::iterator iter = downloads.begin(); iter != downloads.end(); ++iter) { - Download *download = (*iter); + Request *download = (*iter); if (download->http) http_force_close(download->http); download->downloadCanceled = true; @@ -47,14 +47,14 @@ void DownloadManager::Shutdown() } //helper function for download -TH_ENTRY_POINT void* DownloadManagerHelper(void* obj) +TH_ENTRY_POINT void* RequestManagerHelper(void* obj) { - DownloadManager *temp = (DownloadManager*)obj; + RequestManager *temp = (RequestManager*)obj; temp->Update(); return NULL; } -void DownloadManager::Initialise(ByteString Proxy) +void RequestManager::Initialise(ByteString Proxy) { proxy = Proxy; if (proxy.length()) @@ -67,14 +67,14 @@ void DownloadManager::Initialise(ByteString Proxy) } } -void DownloadManager::Start() +void RequestManager::Start() { managerRunning = true; lastUsed = time(NULL); - pthread_create(&downloadThread, NULL, &DownloadManagerHelper, this); + pthread_create(&downloadThread, NULL, &RequestManagerHelper, this); } -void DownloadManager::Update() +void RequestManager::Update() { unsigned int numActiveDownloads = 0; while (!managerShutdown) @@ -95,7 +95,7 @@ void DownloadManager::Update() pthread_mutex_lock(&downloadLock); for (size_t i = 0; i < downloads.size(); i++) { - Download *download = downloads[i]; + Request *download = downloads[i]; if (download->downloadCanceled) { if (download->http && download->downloadStarted) @@ -130,7 +130,7 @@ void DownloadManager::Update() } } -void DownloadManager::EnsureRunning() +void RequestManager::EnsureRunning() { pthread_mutex_lock(&downloadLock); if (!managerRunning) @@ -144,7 +144,7 @@ void DownloadManager::EnsureRunning() pthread_mutex_unlock(&downloadLock); } -void DownloadManager::AddDownload(Download *download) +void RequestManager::AddDownload(Request *download) { pthread_mutex_lock(&downloadAddLock); downloadsAddQueue.push_back(download); @@ -152,12 +152,12 @@ void DownloadManager::AddDownload(Download *download) EnsureRunning(); } -void DownloadManager::Lock() +void RequestManager::Lock() { pthread_mutex_lock(&downloadAddLock); } -void DownloadManager::Unlock() +void RequestManager::Unlock() { pthread_mutex_unlock(&downloadAddLock); } diff --git a/src/client/DownloadManager.h b/src/client/http/RequestManager.h similarity index 73% rename from src/client/DownloadManager.h rename to src/client/http/RequestManager.h index 89c6bd3bb3..36aa3bd01e 100644 --- a/src/client/DownloadManager.h +++ b/src/client/http/RequestManager.h @@ -8,8 +8,8 @@ namespace http { -class Download; -class DownloadManager : public Singleton +class Request; +class RequestManager : public Singleton { private: pthread_t downloadThread; @@ -21,13 +21,13 @@ class DownloadManager : public Singleton int lastUsed; volatile bool managerRunning; volatile bool managerShutdown; - std::vector downloads; - std::vector downloadsAddQueue; + std::vector downloads; + std::vector downloadsAddQueue; void Start(); public: - DownloadManager(); - ~DownloadManager(); + RequestManager(); + ~RequestManager(); void Initialise(ByteString proxy); @@ -35,7 +35,7 @@ class DownloadManager : public Singleton void Update(); void EnsureRunning(); - void AddDownload(Download *download); + void AddDownload(Request *download); void RemoveDownload(int id); void Lock(); diff --git a/src/client/RequestMonitor.h b/src/client/http/RequestMonitor.h similarity index 100% rename from src/client/RequestMonitor.h rename to src/client/http/RequestMonitor.h diff --git a/src/client/SaveUserInfoRequest.cpp b/src/client/http/SaveUserInfoRequest.cpp similarity index 100% rename from src/client/SaveUserInfoRequest.cpp rename to src/client/http/SaveUserInfoRequest.cpp diff --git a/src/client/SaveUserInfoRequest.h b/src/client/http/SaveUserInfoRequest.h similarity index 87% rename from src/client/SaveUserInfoRequest.h rename to src/client/http/SaveUserInfoRequest.h index ac4852a705..48ef7ba9fb 100644 --- a/src/client/SaveUserInfoRequest.h +++ b/src/client/http/SaveUserInfoRequest.h @@ -1,11 +1,11 @@ #ifndef SAVEUSERINFOREQUEST2_H #define SAVEUSERINFOREQUEST2_H -#include "Download.h" +#include "Request.h" #include "common/String.h" #include "json/json.h" #include "client/Client.h" -#include "client/APIRequest.h" +#include "APIRequest.h" #include #include diff --git a/src/client/ThumbnailRequest.cpp b/src/client/http/ThumbnailRequest.cpp similarity index 100% rename from src/client/ThumbnailRequest.cpp rename to src/client/http/ThumbnailRequest.cpp diff --git a/src/client/ThumbnailRequest.h b/src/client/http/ThumbnailRequest.h similarity index 100% rename from src/client/ThumbnailRequest.h rename to src/client/http/ThumbnailRequest.h diff --git a/src/gui/interface/AvatarButton.h b/src/gui/interface/AvatarButton.h index ac65ecb2df..3b33a0b0b9 100644 --- a/src/gui/interface/AvatarButton.h +++ b/src/gui/interface/AvatarButton.h @@ -6,8 +6,8 @@ #include "Component.h" #include "graphics/Graphics.h" #include "gui/interface/Colour.h" -#include "client/AvatarRequest.h" -#include "client/RequestMonitor.h" +#include "client/http/AvatarRequest.h" +#include "client/http/RequestMonitor.h" #include diff --git a/src/gui/interface/SaveButton.h b/src/gui/interface/SaveButton.h index ac900f983d..bf7aba9b8a 100644 --- a/src/gui/interface/SaveButton.h +++ b/src/gui/interface/SaveButton.h @@ -8,8 +8,8 @@ #include "client/SaveInfo.h" #include "graphics/Graphics.h" #include "gui/interface/Colour.h" -#include "client/ThumbnailRequest.h" -#include "client/RequestMonitor.h" +#include "client/http/ThumbnailRequest.h" +#include "client/http/RequestMonitor.h" #include "graphics/Graphics.h" #include diff --git a/src/gui/preview/PreviewModel.cpp b/src/gui/preview/PreviewModel.cpp index fcada6b7ee..2537f0a541 100644 --- a/src/gui/preview/PreviewModel.cpp +++ b/src/gui/preview/PreviewModel.cpp @@ -75,13 +75,13 @@ void PreviewModel::UpdateSave(int saveID, int saveDate) url = ByteString::Build("http://", STATICSERVER, "/", saveID, "_", saveDate, ".cps"); else url = ByteString::Build("http://", STATICSERVER, "/", saveID, ".cps"); - saveDataDownload = new http::Download(url); + saveDataDownload = new http::Request(url); saveDataDownload->Start(); url = ByteString::Build("http://", SERVER , "/Browse/View.json?ID=", saveID); if (saveDate) url += ByteString::Build("&Date=", saveDate); - saveInfoDownload = new http::Download(url); + saveInfoDownload = new http::Request(url); saveInfoDownload->AuthHeaders(ByteString::Build(Client::Ref().GetAuthUser().UserID), Client::Ref().GetAuthUser().SessionID); saveInfoDownload->Start(); @@ -90,7 +90,7 @@ void PreviewModel::UpdateSave(int saveID, int saveDate) commentsLoaded = false; url = ByteString::Build("http://", SERVER, "/Browse/Comments.json?ID=", saveID, "&Start=", (commentsPageNumber-1)*20, "&Count=20"); - commentsDownload = new http::Download(url); + commentsDownload = new http::Request(url); commentsDownload->AuthHeaders(ByteString::Build(Client::Ref().GetAuthUser().UserID), Client::Ref().GetAuthUser().SessionID); commentsDownload->Start(); } @@ -142,7 +142,7 @@ void PreviewModel::UpdateComments(int pageNumber) if (!GetDoOpen()) { ByteString url = ByteString::Build("http://", SERVER, "/Browse/Comments.json?ID=", saveID, "&Start=", (commentsPageNumber-1)*20, "&Count=20"); - commentsDownload = new http::Download(url); + commentsDownload = new http::Request(url); commentsDownload->AuthHeaders(ByteString::Build(Client::Ref().GetAuthUser().UserID), Client::Ref().GetAuthUser().SessionID); commentsDownload->Start(); } @@ -239,7 +239,7 @@ bool PreviewModel::ParseSaveInfo(ByteString &saveInfoResponse) saveDataDownload->Cancel(); delete saveData; saveData = NULL; - saveDataDownload = new http::Download(ByteString::Build("http://", STATICSERVER, "/2157797.cps")); + saveDataDownload = new http::Request(ByteString::Build("http://", STATICSERVER, "/2157797.cps")); saveDataDownload->Start(); } return true; diff --git a/src/gui/preview/PreviewModel.h b/src/gui/preview/PreviewModel.h index 1c10682f89..8ad3f666b9 100644 --- a/src/gui/preview/PreviewModel.h +++ b/src/gui/preview/PreviewModel.h @@ -6,7 +6,7 @@ #include "PreviewView.h" #include "client/SaveInfo.h" #include "gui/preview/Comment.h" -#include "client/Download.h" +#include "client/http/Request.h" using namespace std; @@ -23,9 +23,9 @@ class PreviewModel { void notifyCommentsPageChanged(); void notifyCommentBoxEnabledChanged(); - http::Download * saveDataDownload; - http::Download * saveInfoDownload; - http::Download * commentsDownload; + http::Request * saveDataDownload; + http::Request * saveInfoDownload; + http::Request * commentsDownload; int saveID; int saveDate; diff --git a/src/gui/profile/ProfileActivity.h b/src/gui/profile/ProfileActivity.h index 7e886c16df..a1d897a638 100644 --- a/src/gui/profile/ProfileActivity.h +++ b/src/gui/profile/ProfileActivity.h @@ -5,9 +5,9 @@ #include "Activity.h" #include "client/UserInfo.h" #include "gui/interface/Window.h" -#include "client/SaveUserInfoRequest.h" -#include "client/GetUserInfoRequest.h" -#include "client/RequestMonitor.h" +#include "client/http/SaveUserInfoRequest.h" +#include "client/http/GetUserInfoRequest.h" +#include "client/http/RequestMonitor.h" namespace ui { diff --git a/src/gui/update/UpdateActivity.cpp b/src/gui/update/UpdateActivity.cpp index 222ed237cf..a4bbd47aab 100644 --- a/src/gui/update/UpdateActivity.cpp +++ b/src/gui/update/UpdateActivity.cpp @@ -5,7 +5,7 @@ #include "tasks/Task.h" #include "client/Client.h" #include "Update.h" -#include "client/Download.h" +#include "client/http/Request.h" #include "Platform.h" @@ -26,7 +26,7 @@ class UpdateDownloadTask : public Task virtual bool doWork() { String error; - http::Download *request = new http::Download(updateName); + http::Request *request = new http::Request(updateName); request->Start(); notifyStatus("Downloading update"); notifyProgress(-1); @@ -149,7 +149,7 @@ void UpdateActivity::NotifyError(Task * sender) if (result == ConfirmPrompt::ResultOkay) { #ifndef UPDATESERVER - Platform::OpenURI("http://powdertoy.co.uk/Download.html"); + Platform::OpenURI("http://powdertoy.co.uk/http/Request.html"); #endif } a->Exit(); diff --git a/src/lua/LegacyLuaAPI.cpp b/src/lua/LegacyLuaAPI.cpp index e46be7f954..c0ac854b74 100644 --- a/src/lua/LegacyLuaAPI.cpp +++ b/src/lua/LegacyLuaAPI.cpp @@ -4,7 +4,7 @@ #include #include -#include "client/Download.h" +#include "client/http/Request.h" #include "Format.h" #include "LuaScriptInterface.h" #include "LuaScriptHelper.h" @@ -1355,7 +1355,7 @@ int luatpt_getscript(lua_State* l) return 0; int ret; - ByteString scriptData = http::Download::Simple(url, &ret); + ByteString scriptData = http::Request::Simple(url, &ret); if (!scriptData.size() || !filename) { return luaL_error(l, "Server did not return data"); diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 83f2fdca6c..47a7bee18c 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -20,7 +20,6 @@ #include "gui/game/GameModel.h" #include "gui/game/Tool.h" #include "LuaScriptHelper.h" -#include "client/HTTP.h" #include "client/GameSave.h" #include "client/SaveFile.h" #include "Misc.h"