Skip to content
Permalink
Browse files

More renaming, remove a few useless .c_str()s and fix a URL that had …

…previously contained Download and thus fell victim to my mindless text replacement tricks
  • Loading branch information...
LBPHacker authored and jacob1 committed Mar 7, 2019
1 parent d958adf commit 7fb0b52d7911420666fa5d677a5f85aff268ba5e
@@ -662,7 +662,7 @@ RequestStatus Client::ParseServerReturn(ByteString &result, int status, bool jso

if (json)
{
std::istringstream datastream(result.c_str());
std::istringstream datastream(result);
Json::Value root;

try
@@ -1449,7 +1449,7 @@ SaveInfo * Client::GetSave(int saveID, int saveDate)
{
try
{
std::istringstream dataStream(data.c_str());
std::istringstream dataStream(data);
Json::Value objDocument;
dataStream >> objDocument;

@@ -1516,7 +1516,7 @@ std::vector<std::pair<ByteString, int> > * Client::GetTags(int start, int count,
{
try
{
std::istringstream dataStream(data.c_str());
std::istringstream dataStream(data);
Json::Value objDocument;
dataStream >> objDocument;

@@ -1580,7 +1580,7 @@ std::vector<SaveInfo*> * Client::SearchSaves(int start, int count, String query,
{
try
{
std::istringstream dataStream(data.c_str());
std::istringstream dataStream(data);
Json::Value objDocument;
dataStream >> objDocument;

@@ -1633,7 +1633,7 @@ std::list<ByteString> * Client::RemoveTag(int saveID, ByteString tag)
{
try
{
std::istringstream dataStream(data.c_str());
std::istringstream dataStream(data);
Json::Value responseObject;
dataStream >> responseObject;

@@ -1672,7 +1672,7 @@ std::list<ByteString> * Client::AddTag(int saveID, ByteString tag)
{
try
{
std::istringstream dataStream(data.c_str());
std::istringstream dataStream(data);
Json::Value responseObject;
dataStream >> responseObject;

@@ -9,28 +9,28 @@ namespace http
Request::Request(ByteString uri_, bool keepAlive):
http(NULL),
keepAlive(keepAlive),
downloadData(NULL),
downloadSize(0),
downloadStatus(0),
requestData(NULL),
requestSize(0),
requestStatus(0),
postData(""),
postDataBoundary(""),
userID(""),
userSession(""),
downloadFinished(false),
downloadCanceled(false),
downloadStarted(false)
requestFinished(false),
requestCanceled(false),
requestStarted(false)
{
uri = ByteString(uri_);
RequestManager::Ref().AddDownload(this);
RequestManager::Ref().AddRequest(this);
}

// called by download thread itself if download was canceled
// called by request thread itself if request was canceled
Request::~Request()
{
if (http && (keepAlive || downloadCanceled))
if (http && (keepAlive || requestCanceled))
http_async_req_close(http);
if (downloadData)
free(downloadData);
if (requestData)
free(requestData);
}

// add post data to a request
@@ -46,15 +46,15 @@ void Request::AddPostData(std::pair<ByteString, ByteString> data)
AddPostData(postData);
}

// add userID and sessionID headers to the download. Must be done after download starts for some reason
// add userID and sessionID headers to the request. Must be done after request starts for some reason
void Request::AuthHeaders(ByteString ID, ByteString session)
{
if (ID != "0")
userID = ID;
userSession = session;
}

// start the download thread
// start the request thread
void Request::Start()
{
if (CheckStarted() || CheckDone())
@@ -66,78 +66,78 @@ void Request::Start()
if (postDataBoundary.length())
http_add_multipart_header(http, postDataBoundary);
RequestManager::Ref().Lock();
downloadStarted = true;
requestStarted = true;
RequestManager::Ref().Unlock();
}


// finish the download (if called before the download is done, this will block)
// finish the request (if called before the request is done, this will block)
ByteString Request::Finish(int *status)
{
if (CheckCanceled())
return ""; // shouldn't happen but just in case
while (!CheckDone()); // block
RequestManager::Ref().Lock();
downloadStarted = false;
requestStarted = false;
if (status)
*status = downloadStatus;
*status = requestStatus;
ByteString ret;
if (downloadData)
if (requestData)
{
ret = ByteString(downloadData, downloadData + downloadSize);
free(downloadData);
ret = ByteString(requestData, requestData + requestSize);
free(requestData);
}
downloadData = NULL;
requestData = NULL;
if (!keepAlive)
downloadCanceled = true;
requestCanceled = true;
RequestManager::Ref().Unlock();
return ret;
}

// returns the download size and progress (if the download has the correct length headers)
// returns the request size and progress (if the request has the correct length headers)
void Request::CheckProgress(int *total, int *done)
{
RequestManager::Ref().Lock();
if (!downloadFinished && http)
if (!requestFinished && http)
http_async_get_length(http, total, done);
else
*total = *done = 0;
RequestManager::Ref().Unlock();
}

// returns true if the download has finished
// returns true if the request has finished
bool Request::CheckDone()
{
RequestManager::Ref().Lock();
bool ret = downloadFinished;
bool ret = requestFinished;
RequestManager::Ref().Unlock();
return ret;
}

// returns true if the download was canceled
// returns true if the request was canceled
bool Request::CheckCanceled()
{
RequestManager::Ref().Lock();
bool ret = downloadCanceled;
bool ret = requestCanceled;
RequestManager::Ref().Unlock();
return ret;
}

// returns true if the download is running
// returns true if the request is running
bool Request::CheckStarted()
{
RequestManager::Ref().Lock();
bool ret = downloadStarted;
bool ret = requestStarted;
RequestManager::Ref().Unlock();
return ret;

}

// cancels the download, the download thread will delete the Request* when it finishes (do not use Request in any way after canceling)
// cancels the request, the request thread will delete the Request* when it finishes (do not use Request in any way after canceling)
void Request::Cancel()
{
RequestManager::Ref().Lock();
downloadCanceled = true;
requestCanceled = true;
RequestManager::Ref().Unlock();
}

@@ -1,5 +1,5 @@
#ifndef DOWNLOAD_H
#define DOWNLOAD_H
#ifndef REQUEST_H
#define REQUEST_H
#include <map>
#include "common/String.h"

@@ -12,19 +12,19 @@ class Request
void *http;
bool keepAlive;

char *downloadData;
int downloadSize;
int downloadStatus;
char *requestData;
int requestSize;
int requestStatus;

ByteString postData;
ByteString postDataBoundary;

ByteString userID;
ByteString userSession;

volatile bool downloadFinished;
volatile bool downloadCanceled;
volatile bool downloadStarted;
volatile bool requestFinished;
volatile bool requestCanceled;
volatile bool requestStarted;

public:
Request(ByteString uri, bool keepAlive = false);
Oops, something went wrong.

0 comments on commit 7fb0b52

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.