19#ifndef HEADER_HTTP_REQUEST_HPP
20#define HEADER_HTTP_REQUEST_HPP
22#include "online/request.hpp"
23#include "utils/cpp2011.hpp"
24#include "utils/string_utils.hpp"
34#if defined(CURLOPT_XFERINFODATA)
35#define PROGRESSDATA CURLOPT_XFERINFODATA
36#define PROGRESSFUNCTION CURLOPT_XFERINFOFUNCTION
37typedef curl_off_t progress_t;
39#define PROGRESSDATA CURLOPT_PROGRESSDATA
40#define PROGRESSFUNCTION CURLOPT_PROGRESSFUNCTION
41typedef double progress_t;
49 static const std::string USER_PATH;
50 static const std::string SERVER_PATH;
64 std::atomic<double> m_total_size;
82 struct curl_slist* m_http_header = NULL;
88 bool m_disable_sending_log;
91 bool m_download_assets_request =
false;
98 progress_t dlnow, progress_t ultotal,
102 size_t nmemb,
void *userp);
107 HTTPRequest(const std::
string &filename,
int priority = 1);
108 HTTPRequest(const
char * const filename,
int priority = 1);
112 curl_slist_free_all(m_http_header);
120 void setApiURL(const std::
string& url, const std::
string &action);
127 void setDownloadAssetsRequest(
bool val)
128 { m_download_assets_request = val; }
161 const irr::core::stringw &value)
163 std::string s = StringUtils::wideToUtf8(value);
171 template <
typename T>
175 std::string s = StringUtils::toString(value);
177 char *s1 = curl_easy_escape(
m_curl_session, name.c_str(), (
int)name.size());
178 char *s2 = curl_easy_escape(
m_curl_session, s.c_str(), (
int)s.size());
193 const std::string & getURL()
const { assert(
isBusy());
return m_url;}
203 const std::string& getFileName()
const {
return m_filename; }
205 double getTotalSize()
const {
return m_total_size.load(); }
207 void setTotalSize(
double d) { m_total_size.store(d); }
Definition: http_request.hpp:47
A http request.
Definition: http_request.hpp:56
std::string m_string_buffer
String to store the received data in.
Definition: http_request.hpp:80
void addParameter(const std::string &name, const T &value)
Sets a parameter to 'value' (arbitrary types).
Definition: http_request.hpp:172
float getProgress() const
Returns the current progress.
Definition: http_request.hpp:186
std::atomic< float > m_progress
The progress indicator.
Definition: http_request.hpp:62
CURL * m_curl_session
Pointer to the curl data structure for this request.
Definition: http_request.hpp:74
void setProgress(float f)
Sets the current progress.
Definition: http_request.hpp:190
virtual bool isAllowedToAdd() const OVERRIDE
Checks the request if it has enough (correct) information to be executed (and thus allowed to add to ...
Definition: http_request.cpp:145
CURLcode m_curl_code
curl return code.
Definition: http_request.hpp:77
void init()
Initialises all member variables.
Definition: http_request.cpp:86
void setAddonsURL(const std::string &path)
A handy shortcut that appends the given path to the URL of the addons server.
Definition: http_request.cpp:136
virtual void operation() OVERRIDE
The actual curl download happens here.
Definition: http_request.cpp:196
virtual void prepareOperation() OVERRIDE
Sets up the curl data structures.
Definition: http_request.cpp:153
static size_t writeCallback(void *contents, size_t size, size_t nmemb, void *userp)
Callback from curl.
Definition: http_request.cpp:337
std::string m_filename
Contains a filename if the data should be saved into a file instead of being kept in in memory.
Definition: http_request.hpp:86
std::string m_parameters
The POST parameters that will be send with the request.
Definition: http_request.hpp:70
const char * getDownloadErrorMessage() const
Returns the curl error message if an error has occurred.
Definition: http_request.hpp:133
const std::string & getData() const
Returns the downloaded string.
Definition: http_request.hpp:144
void addParameter(const std::string &name, const irr::core::stringw &value)
Sets a parameter to 'value' (stringw).
Definition: http_request.hpp:160
void setApiURL(const std::string &url, const std::string &action)
A handy shortcut that appends the given path to the URL of the mutiplayer server.
Definition: http_request.cpp:105
virtual void afterOperation() OVERRIDE
Cleanup once the download is finished.
Definition: http_request.cpp:309
void addParameter(const std::string &name, const std::string &value)
Sets a parameter to 'value' (std::string).
Definition: http_request.hpp:152
virtual bool hadDownloadError() const
Returns true if there was an error downloading the file.
Definition: http_request.hpp:125
static int progressDownload(void *clientp, progress_t dltotal, progress_t dlnow, progress_t ultotal, progress_t ulnow)
Callback function from curl: inform about progress.
Definition: http_request.cpp:354
void setURL(const std::string &url)
Sets the URL for this request.
Definition: http_request.hpp:197
std::string m_url
The url to download.
Definition: http_request.hpp:67
Stores a request for the HTTP Manager.
Definition: request.hpp:62
bool isPreparing() const
Returns if this request is being prepared.
Definition: request.hpp:191
bool hasBeenExecuted() const
Checks if the request has completed or done (i.e.
Definition: request.hpp:201
bool isBusy() const
Returns if this request is busy.
Definition: request.hpp:195