Follow redirects and fix save loading by ptsave parameter

This commit is contained in:
Tamás Bálint Misius 2019-03-15 10:54:23 +01:00 committed by jacob1
parent 341e75cdfe
commit 296b758193
4 changed files with 12 additions and 24 deletions

View File

@ -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<unsigned char> 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<unsigned char>(data.begin(), data.end());
}
return NULL;
}
std::vector<unsigned char> Client::GetSaveData(int saveID, int saveDate)
{
int dataSize;
unsigned char * data = GetSaveData(saveID, saveDate, dataSize);
if (!data)
return std::vector<unsigned char>();
std::vector<unsigned char> saveData(data, data+dataSize);
delete[] data;
return saveData;
return std::vector<unsigned char>();
}
LoginStatus Client::Login(ByteString username, ByteString password, User & user)

View File

@ -144,7 +144,6 @@ public:
RequestStatus AddComment(int saveID, String comment);
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
std::vector<unsigned char> GetSaveData(int saveID, int saveDate);
LoginStatus Login(ByteString username, ByteString password, User & user);

View File

@ -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";
}
}

View File

@ -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: