diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 4456d7ace..d81127ce1 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -1187,12 +1187,11 @@ RequestStatus Client::ExecVote(int saveID, int direction) return ret; } -unsigned char * Client::GetSaveData(int saveID, int saveDate, int & dataLength) +std::vector Client::GetSaveData(int saveID, int saveDate) { lastError = ""; int dataStatus; ByteString data; - dataLength = 0; ByteString urlStr; if (saveDate) urlStr = ByteString::Build(STATICSCHEME, STATICSERVER, "/", saveID, "_", saveDate, ".cps"); @@ -1205,24 +1204,9 @@ unsigned char * Client::GetSaveData(int saveID, int saveDate, int & dataLength) ParseServerReturn(data, dataStatus, false); if (data.size() && dataStatus == 200) { - unsigned char *data_out = (unsigned char *)malloc(data.size()); - std::copy(data_out, data_out + data.size(), data.begin()); - dataLength = (int)data.size(); - return data_out; + return std::vector(data.begin(), data.end()); } - return NULL; -} - -std::vector Client::GetSaveData(int saveID, int saveDate) -{ - int dataSize; - unsigned char * data = GetSaveData(saveID, saveDate, dataSize); - if (!data) - return std::vector(); - - std::vector saveData(data, data+dataSize); - delete[] data; - return saveData; + return std::vector(); } LoginStatus Client::Login(ByteString username, ByteString password, User & user) diff --git a/src/client/Client.h b/src/client/Client.h index 7eecf474e..eb0d7a976 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -144,7 +144,6 @@ public: RequestStatus AddComment(int saveID, String comment); - unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength); std::vector GetSaveData(int saveID, int saveDate); LoginStatus Login(ByteString username, ByteString password, User & user); diff --git a/src/client/http/Request.cpp b/src/client/http/Request.cpp index 52dcf0703..9125bb7b3 100644 --- a/src/client/http/Request.cpp +++ b/src/client/http/Request.cpp @@ -101,9 +101,12 @@ namespace http } else { - curl_easy_setopt(easy, CURLOPT_HTTPGET, 1); + curl_easy_setopt(easy, CURLOPT_HTTPGET, 1L); } + curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L); + curl_easy_setopt(easy, CURLOPT_MAXREDIRS, 10L); + curl_easy_setopt(easy, CURLOPT_TIMEOUT, timeout); curl_easy_setopt(easy, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(easy, CURLOPT_URL, uri.c_str()); @@ -113,11 +116,11 @@ namespace http curl_easy_setopt(easy, CURLOPT_PROXY, proxy.c_str()); } - curl_easy_setopt(easy, CURLOPT_PRIVATE, this); + curl_easy_setopt(easy, CURLOPT_PRIVATE, (void *)this); curl_easy_setopt(easy, CURLOPT_USERAGENT, user_agent.c_str()); - curl_easy_setopt(easy, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(easy, CURLOPT_NOSIGNAL, 1L); - curl_easy_setopt(easy, CURLOPT_WRITEDATA, this); + curl_easy_setopt(easy, CURLOPT_WRITEDATA, (void *)this); curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, (size_t (*)(char *ptr, size_t size, size_t count, void *userdata))([](char *ptr, size_t size, size_t count, void *userdata) -> size_t { Request *req = (Request *)userdata; auto actual_size = size * count; @@ -296,6 +299,7 @@ namespace http case 608: return "Proxy Server Not Found"; case 609: return "SSL Failure"; case 610: return "Cancelled by Shutdown"; + case 611: return "Too Many Redirects"; default: return "Unknown Status Code"; } } diff --git a/src/client/http/RequestManager.cpp b/src/client/http/RequestManager.cpp index bb22c86a9..b8cc5a841 100644 --- a/src/client/http/RequestManager.cpp +++ b/src/client/http/RequestManager.cpp @@ -119,6 +119,7 @@ namespace http case CURLE_URL_MALFORMAT: finish_with = 606; break; case CURLE_COULDNT_CONNECT: finish_with = 607; break; case CURLE_COULDNT_RESOLVE_PROXY: finish_with = 608; break; + case CURLE_TOO_MANY_REDIRECTS: finish_with = 611; break; case CURLE_SSL_CONNECT_ERROR: case CURLE_SSL_ENGINE_NOTFOUND: