2013-08-29 05:04:56 +02:00
|
|
|
/*
|
|
|
|
Minetest
|
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "httpfetch.h"
|
2017-08-24 08:28:54 +02:00
|
|
|
#include "porting.h" // for sleep_ms(), get_sysinfo(), secure_rand_fill_buf()
|
2013-08-29 05:04:56 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <list>
|
2021-04-02 00:19:39 +02:00
|
|
|
#include <unordered_map>
|
2017-08-20 19:37:29 +02:00
|
|
|
#include <cerrno>
|
2017-06-06 16:29:28 +02:00
|
|
|
#include <mutex>
|
2017-08-24 08:28:54 +02:00
|
|
|
#include "network/socket.h" // for select()
|
2015-04-07 12:13:12 +02:00
|
|
|
#include "threading/event.h"
|
2013-08-29 05:04:56 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "exceptions.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "util/container.h"
|
|
|
|
#include "util/thread.h"
|
2014-01-06 23:50:45 +01:00
|
|
|
#include "version.h"
|
|
|
|
#include "settings.h"
|
2016-02-18 11:38:47 +01:00
|
|
|
#include "noise.h"
|
2013-08-29 05:04:56 +02:00
|
|
|
|
2021-04-02 00:19:39 +02:00
|
|
|
static std::mutex g_httpfetch_mutex;
|
2022-01-01 22:44:56 +01:00
|
|
|
static std::unordered_map<u64, std::queue<HTTPFetchResult>>
|
2021-04-02 00:19:39 +02:00
|
|
|
g_httpfetch_results;
|
|
|
|
static PcgRandom g_callerid_randomness;
|
2013-08-29 05:04:56 +02:00
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
HTTPFetchRequest::HTTPFetchRequest() :
|
|
|
|
timeout(g_settings->getS32("curl_timeout")),
|
2021-04-02 00:19:39 +02:00
|
|
|
connect_timeout(10 * 1000),
|
2017-04-20 00:12:52 +02:00
|
|
|
useragent(std::string(PROJECT_NAME_C "/") + g_version_hash + " (" + porting::get_sysinfo() + ")")
|
2014-01-17 01:33:02 +01:00
|
|
|
{
|
2023-09-26 16:00:16 +02:00
|
|
|
timeout = std::max(timeout, MIN_HTTPFETCH_TIMEOUT_INTERACTIVE);
|
2014-01-17 01:33:02 +01:00
|
|
|
}
|
2014-01-06 23:50:45 +01:00
|
|
|
|
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
static void httpfetch_deliver_result(const HTTPFetchResult &fetch_result)
|
2013-08-29 05:04:56 +02:00
|
|
|
{
|
2022-01-01 22:44:56 +01:00
|
|
|
u64 caller = fetch_result.caller;
|
2013-08-29 05:04:56 +02:00
|
|
|
if (caller != HTTPFETCH_DISCARD) {
|
2015-04-07 12:13:12 +02:00
|
|
|
MutexAutoLock lock(g_httpfetch_mutex);
|
2021-04-02 00:19:39 +02:00
|
|
|
g_httpfetch_results[caller].emplace(fetch_result);
|
2013-08-29 05:04:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-01 22:44:56 +01:00
|
|
|
static void httpfetch_request_clear(u64 caller);
|
2013-08-29 05:04:56 +02:00
|
|
|
|
2022-01-01 22:44:56 +01:00
|
|
|
u64 httpfetch_caller_alloc()
|
2013-08-29 05:04:56 +02:00
|
|
|
{
|
2015-04-07 12:13:12 +02:00
|
|
|
MutexAutoLock lock(g_httpfetch_mutex);
|
2013-08-29 05:04:56 +02:00
|
|
|
|
2022-01-01 22:44:56 +01:00
|
|
|
// Check each caller ID except reserved ones
|
|
|
|
for (u64 caller = HTTPFETCH_CID_START; caller != 0; ++caller) {
|
2021-04-02 00:19:39 +02:00
|
|
|
auto it = g_httpfetch_results.find(caller);
|
2013-08-29 05:04:56 +02:00
|
|
|
if (it == g_httpfetch_results.end()) {
|
2015-03-05 16:20:56 +01:00
|
|
|
verbosestream << "httpfetch_caller_alloc: allocating "
|
|
|
|
<< caller << std::endl;
|
2013-08-29 05:04:56 +02:00
|
|
|
// Access element to create it
|
|
|
|
g_httpfetch_results[caller];
|
|
|
|
return caller;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-06 11:21:51 +01:00
|
|
|
FATAL_ERROR("httpfetch_caller_alloc: ran out of caller IDs");
|
2013-08-29 05:04:56 +02:00
|
|
|
}
|
|
|
|
|
2022-01-01 22:44:56 +01:00
|
|
|
u64 httpfetch_caller_alloc_secure()
|
2016-02-18 11:38:47 +01:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(g_httpfetch_mutex);
|
|
|
|
|
|
|
|
// Generate random caller IDs and make sure they're not
|
2022-01-01 22:44:56 +01:00
|
|
|
// already used or reserved.
|
2016-02-18 11:38:47 +01:00
|
|
|
// Give up after 100 tries to prevent infinite loop
|
2022-01-01 22:44:56 +01:00
|
|
|
size_t tries = 100;
|
|
|
|
u64 caller;
|
2016-02-18 11:38:47 +01:00
|
|
|
|
|
|
|
do {
|
|
|
|
caller = (((u64) g_callerid_randomness.next()) << 32) |
|
|
|
|
g_callerid_randomness.next();
|
|
|
|
|
|
|
|
if (--tries < 1) {
|
|
|
|
FATAL_ERROR("httpfetch_caller_alloc_secure: ran out of caller IDs");
|
|
|
|
return HTTPFETCH_DISCARD;
|
|
|
|
}
|
2022-01-01 22:44:56 +01:00
|
|
|
} while (caller >= HTTPFETCH_CID_START &&
|
|
|
|
g_httpfetch_results.find(caller) != g_httpfetch_results.end());
|
2016-02-18 11:38:47 +01:00
|
|
|
|
|
|
|
verbosestream << "httpfetch_caller_alloc_secure: allocating "
|
|
|
|
<< caller << std::endl;
|
|
|
|
|
|
|
|
// Access element to create it
|
|
|
|
g_httpfetch_results[caller];
|
|
|
|
return caller;
|
|
|
|
}
|
|
|
|
|
2022-01-01 22:44:56 +01:00
|
|
|
void httpfetch_caller_free(u64 caller)
|
2013-08-29 05:04:56 +02:00
|
|
|
{
|
|
|
|
verbosestream<<"httpfetch_caller_free: freeing "
|
|
|
|
<<caller<<std::endl;
|
|
|
|
|
|
|
|
httpfetch_request_clear(caller);
|
|
|
|
if (caller != HTTPFETCH_DISCARD) {
|
2015-04-07 12:13:12 +02:00
|
|
|
MutexAutoLock lock(g_httpfetch_mutex);
|
2013-08-29 05:04:56 +02:00
|
|
|
g_httpfetch_results.erase(caller);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-01 22:44:56 +01:00
|
|
|
bool httpfetch_async_get(u64 caller, HTTPFetchResult &fetch_result)
|
2013-08-29 05:04:56 +02:00
|
|
|
{
|
2015-04-07 12:13:12 +02:00
|
|
|
MutexAutoLock lock(g_httpfetch_mutex);
|
2013-08-29 05:04:56 +02:00
|
|
|
|
|
|
|
// Check that caller exists
|
2021-04-02 00:19:39 +02:00
|
|
|
auto it = g_httpfetch_results.find(caller);
|
2013-08-29 05:04:56 +02:00
|
|
|
if (it == g_httpfetch_results.end())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check that result queue is nonempty
|
2015-03-05 16:20:56 +01:00
|
|
|
std::queue<HTTPFetchResult> &caller_results = it->second;
|
2014-09-15 02:46:45 +02:00
|
|
|
if (caller_results.empty())
|
2013-08-29 05:04:56 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Pop first result
|
2021-04-02 00:19:39 +02:00
|
|
|
fetch_result = std::move(caller_results.front());
|
2015-03-05 16:20:56 +01:00
|
|
|
caller_results.pop();
|
2013-08-29 05:04:56 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if USE_CURL
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
USE_CURL is on: use cURL based httpfetch implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
static size_t httpfetch_writefunction(
|
|
|
|
char *ptr, size_t size, size_t nmemb, void *userdata)
|
|
|
|
{
|
|
|
|
std::ostringstream *stream = (std::ostringstream*)userdata;
|
|
|
|
size_t count = size * nmemb;
|
|
|
|
stream->write(ptr, count);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t httpfetch_discardfunction(
|
|
|
|
char *ptr, size_t size, size_t nmemb, void *userdata)
|
|
|
|
{
|
|
|
|
return size * nmemb;
|
|
|
|
}
|
|
|
|
|
|
|
|
class CurlHandlePool
|
|
|
|
{
|
|
|
|
std::list<CURL*> handles;
|
|
|
|
|
|
|
|
public:
|
2017-08-20 19:37:29 +02:00
|
|
|
CurlHandlePool() = default;
|
|
|
|
|
2013-08-29 05:04:56 +02:00
|
|
|
~CurlHandlePool()
|
|
|
|
{
|
|
|
|
for (std::list<CURL*>::iterator it = handles.begin();
|
|
|
|
it != handles.end(); ++it) {
|
|
|
|
curl_easy_cleanup(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CURL * alloc()
|
|
|
|
{
|
|
|
|
CURL *curl;
|
|
|
|
if (handles.empty()) {
|
|
|
|
curl = curl_easy_init();
|
|
|
|
if (curl == NULL) {
|
|
|
|
errorstream<<"curl_easy_init returned NULL"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
curl = handles.front();
|
|
|
|
handles.pop_front();
|
|
|
|
}
|
|
|
|
return curl;
|
|
|
|
}
|
|
|
|
void free(CURL *handle)
|
|
|
|
{
|
|
|
|
if (handle)
|
|
|
|
handles.push_back(handle);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
class HTTPFetchOngoing
|
2013-08-29 05:04:56 +02:00
|
|
|
{
|
2014-09-15 02:46:45 +02:00
|
|
|
public:
|
2017-04-19 23:02:07 +02:00
|
|
|
HTTPFetchOngoing(const HTTPFetchRequest &request, CurlHandlePool *pool);
|
2014-09-15 02:46:45 +02:00
|
|
|
~HTTPFetchOngoing();
|
|
|
|
|
|
|
|
CURLcode start(CURLM *multi);
|
|
|
|
const HTTPFetchResult * complete(CURLcode res);
|
|
|
|
|
|
|
|
const HTTPFetchRequest &getRequest() const { return request; };
|
|
|
|
const CURL *getEasyHandle() const { return curl; };
|
|
|
|
|
|
|
|
private:
|
2013-08-29 05:04:56 +02:00
|
|
|
CurlHandlePool *pool;
|
2023-06-05 17:37:18 +02:00
|
|
|
CURL *curl = nullptr;
|
|
|
|
CURLM *multi = nullptr;
|
2013-08-29 05:04:56 +02:00
|
|
|
HTTPFetchRequest request;
|
|
|
|
HTTPFetchResult result;
|
|
|
|
std::ostringstream oss;
|
2023-06-05 17:37:18 +02:00
|
|
|
struct curl_slist *http_header = nullptr;
|
|
|
|
curl_mime *multipart_mime = nullptr;
|
2014-09-15 02:46:45 +02:00
|
|
|
};
|
2013-08-29 05:04:56 +02:00
|
|
|
|
|
|
|
|
2017-04-19 23:02:07 +02:00
|
|
|
HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_,
|
|
|
|
CurlHandlePool *pool_):
|
2014-09-15 02:46:45 +02:00
|
|
|
pool(pool_),
|
|
|
|
request(request_),
|
|
|
|
result(request_),
|
2023-06-05 17:37:18 +02:00
|
|
|
oss(std::ios::binary)
|
2014-09-15 02:46:45 +02:00
|
|
|
{
|
|
|
|
curl = pool->alloc();
|
|
|
|
if (curl == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2013-08-29 05:04:56 +02:00
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
// Set static cURL options
|
|
|
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
|
2018-04-17 15:54:50 +02:00
|
|
|
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3);
|
2017-11-04 22:19:27 +01:00
|
|
|
curl_easy_setopt(curl, CURLOPT_ENCODING, "gzip");
|
2014-06-19 22:00:22 +02:00
|
|
|
|
2014-09-15 02:58:21 +02:00
|
|
|
std::string bind_address = g_settings->get("bind_address");
|
|
|
|
if (!bind_address.empty()) {
|
|
|
|
curl_easy_setopt(curl, CURLOPT_INTERFACE, bind_address.c_str());
|
|
|
|
}
|
|
|
|
|
2019-03-18 15:06:27 +01:00
|
|
|
if (!g_settings->getBool("enable_ipv6")) {
|
|
|
|
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
|
|
|
}
|
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
// Restrict protocols so that curl vulnerabilities in
|
|
|
|
// other protocols don't affect us.
|
2023-06-05 17:37:18 +02:00
|
|
|
#if LIBCURL_VERSION_NUM >= 0x075500
|
|
|
|
// These settings were introduced in curl 7.85.0.
|
|
|
|
const char *protocols = "HTTP,HTTPS,FTP,FTPS";
|
|
|
|
curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, protocols);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS_STR, protocols);
|
|
|
|
#elif LIBCURL_VERSION_NUM >= 0x071304
|
|
|
|
// These settings were introduced in curl 7.19.4, and later deprecated.
|
2014-09-15 02:46:45 +02:00
|
|
|
long protocols =
|
|
|
|
CURLPROTO_HTTP |
|
|
|
|
CURLPROTO_HTTPS |
|
|
|
|
CURLPROTO_FTP |
|
|
|
|
CURLPROTO_FTPS;
|
|
|
|
curl_easy_setopt(curl, CURLOPT_PROTOCOLS, protocols);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, protocols);
|
|
|
|
#endif
|
2014-04-21 14:10:59 +02:00
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
// Set cURL options based on HTTPFetchRequest
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL,
|
|
|
|
request.url.c_str());
|
|
|
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS,
|
|
|
|
request.timeout);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS,
|
|
|
|
request.connect_timeout);
|
|
|
|
|
2017-08-20 19:37:29 +02:00
|
|
|
if (!request.useragent.empty())
|
2014-09-15 02:46:45 +02:00
|
|
|
curl_easy_setopt(curl, CURLOPT_USERAGENT, request.useragent.c_str());
|
|
|
|
|
|
|
|
// Set up a write callback that writes to the
|
|
|
|
// ostringstream ongoing->oss, unless the data
|
|
|
|
// is to be discarded
|
|
|
|
if (request.caller == HTTPFETCH_DISCARD) {
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
|
|
|
|
httpfetch_discardfunction);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);
|
|
|
|
} else {
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
|
|
|
|
httpfetch_writefunction);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &oss);
|
2013-08-29 05:04:56 +02:00
|
|
|
}
|
|
|
|
|
2020-07-29 23:16:21 +02:00
|
|
|
// Set data from fields or raw_data
|
|
|
|
if (request.multipart) {
|
2023-06-05 17:37:18 +02:00
|
|
|
multipart_mime = curl_mime_init(curl);
|
|
|
|
for (auto &it : request.fields) {
|
|
|
|
curl_mimepart *part = curl_mime_addpart(multipart_mime);
|
|
|
|
curl_mime_name(part, it.first.c_str());
|
|
|
|
curl_mime_data(part, it.second.c_str(), it.second.size());
|
2013-08-29 05:04:56 +02:00
|
|
|
}
|
2023-06-05 17:37:18 +02:00
|
|
|
curl_easy_setopt(curl, CURLOPT_MIMEPOST, multipart_mime);
|
2014-09-15 02:46:45 +02:00
|
|
|
} else {
|
2020-07-29 23:16:21 +02:00
|
|
|
switch (request.method) {
|
|
|
|
case HTTP_GET:
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
|
|
|
|
break;
|
|
|
|
case HTTP_POST:
|
|
|
|
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
|
|
|
break;
|
|
|
|
case HTTP_PUT:
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
|
|
|
break;
|
|
|
|
case HTTP_DELETE:
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (request.method != HTTP_GET) {
|
|
|
|
if (!request.raw_data.empty()) {
|
|
|
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE,
|
|
|
|
request.raw_data.size());
|
|
|
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS,
|
|
|
|
request.raw_data.c_str());
|
|
|
|
} else if (!request.fields.empty()) {
|
|
|
|
std::string str;
|
|
|
|
for (auto &field : request.fields) {
|
|
|
|
if (!str.empty())
|
|
|
|
str += "&";
|
|
|
|
str += urlencode(field.first);
|
|
|
|
str += "=";
|
|
|
|
str += urlencode(field.second);
|
|
|
|
}
|
|
|
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE,
|
|
|
|
str.size());
|
|
|
|
curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS,
|
|
|
|
str.c_str());
|
|
|
|
}
|
|
|
|
}
|
2014-09-15 02:46:45 +02:00
|
|
|
}
|
|
|
|
// Set additional HTTP headers
|
2017-08-20 19:37:29 +02:00
|
|
|
for (const std::string &extra_header : request.extra_headers) {
|
|
|
|
http_header = curl_slist_append(http_header, extra_header.c_str());
|
2013-08-29 05:04:56 +02:00
|
|
|
}
|
2014-09-15 02:46:45 +02:00
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_header);
|
2013-08-29 05:04:56 +02:00
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
if (!g_settings->getBool("curl_verify_cert")) {
|
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CURLcode HTTPFetchOngoing::start(CURLM *multi_)
|
|
|
|
{
|
|
|
|
if (!curl)
|
|
|
|
return CURLE_FAILED_INIT;
|
|
|
|
|
|
|
|
if (!multi_) {
|
|
|
|
// Easy interface (sync)
|
|
|
|
return curl_easy_perform(curl);
|
|
|
|
}
|
2013-08-29 05:04:56 +02:00
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
// Multi interface (async)
|
|
|
|
CURLMcode mres = curl_multi_add_handle(multi_, curl);
|
|
|
|
if (mres != CURLM_OK) {
|
|
|
|
errorstream << "curl_multi_add_handle"
|
|
|
|
<< " returned error code " << mres
|
|
|
|
<< std::endl;
|
|
|
|
return CURLE_FAILED_INIT;
|
|
|
|
}
|
|
|
|
multi = multi_; // store for curl_multi_remove_handle
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
const HTTPFetchResult * HTTPFetchOngoing::complete(CURLcode res)
|
|
|
|
{
|
|
|
|
result.succeeded = (res == CURLE_OK);
|
|
|
|
result.timeout = (res == CURLE_OPERATION_TIMEDOUT);
|
|
|
|
result.data = oss.str();
|
|
|
|
|
|
|
|
// Get HTTP/FTP response code
|
|
|
|
result.response_code = 0;
|
|
|
|
if (curl && (curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE,
|
|
|
|
&result.response_code) != CURLE_OK)) {
|
|
|
|
// We failed to get a return code, make sure it is still 0
|
2013-08-29 05:04:56 +02:00
|
|
|
result.response_code = 0;
|
2014-09-15 02:46:45 +02:00
|
|
|
}
|
2013-08-29 05:04:56 +02:00
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
if (res != CURLE_OK) {
|
2023-09-26 16:09:24 +02:00
|
|
|
errorstream << "HTTPFetch for " << request.url << " failed: "
|
|
|
|
<< curl_easy_strerror(res);
|
|
|
|
if (result.timeout)
|
|
|
|
errorstream << " (timeout = " << request.timeout << "ms)" << std::endl;
|
|
|
|
errorstream << std::endl;
|
2022-01-01 22:44:56 +01:00
|
|
|
} else if (result.response_code >= 400) {
|
|
|
|
errorstream << "HTTPFetch for " << request.url
|
|
|
|
<< " returned response code " << result.response_code
|
2014-09-15 02:46:45 +02:00
|
|
|
<< std::endl;
|
2022-01-01 22:44:56 +01:00
|
|
|
if (result.caller == HTTPFETCH_PRINT_ERR && !result.data.empty()) {
|
|
|
|
errorstream << "Response body:" << std::endl;
|
|
|
|
safe_print_string(errorstream, result.data);
|
|
|
|
errorstream << std::endl;
|
|
|
|
}
|
2013-08-29 05:04:56 +02:00
|
|
|
}
|
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
return &result;
|
|
|
|
}
|
2013-08-29 05:04:56 +02:00
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
HTTPFetchOngoing::~HTTPFetchOngoing()
|
|
|
|
{
|
|
|
|
if (multi) {
|
|
|
|
CURLMcode mres = curl_multi_remove_handle(multi, curl);
|
|
|
|
if (mres != CURLM_OK) {
|
|
|
|
errorstream << "curl_multi_remove_handle"
|
|
|
|
<< " returned error code " << mres
|
|
|
|
<< std::endl;
|
2014-06-19 22:00:22 +02:00
|
|
|
}
|
2014-09-15 02:46:45 +02:00
|
|
|
}
|
2013-08-29 05:04:56 +02:00
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
// Set safe options for the reusable cURL handle
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
|
|
|
|
httpfetch_discardfunction);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL);
|
|
|
|
if (http_header) {
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL);
|
|
|
|
curl_slist_free_all(http_header);
|
2013-08-29 05:04:56 +02:00
|
|
|
}
|
2023-06-05 17:37:18 +02:00
|
|
|
if (multipart_mime) {
|
|
|
|
curl_easy_setopt(curl, CURLOPT_MIMEPOST, nullptr);
|
|
|
|
curl_mime_free(multipart_mime);
|
2014-09-15 02:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Store the cURL handle for reuse
|
|
|
|
pool->free(curl);
|
|
|
|
}
|
|
|
|
|
2013-08-29 05:04:56 +02:00
|
|
|
|
2015-04-07 12:13:12 +02:00
|
|
|
class CurlFetchThread : public Thread
|
2013-08-29 05:04:56 +02:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
enum RequestType {
|
|
|
|
RT_FETCH,
|
|
|
|
RT_CLEAR,
|
|
|
|
RT_WAKEUP,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Request {
|
|
|
|
RequestType type;
|
2014-09-15 02:46:45 +02:00
|
|
|
HTTPFetchRequest fetch_request;
|
2013-08-29 05:04:56 +02:00
|
|
|
Event *event;
|
|
|
|
};
|
|
|
|
|
|
|
|
CURLM *m_multi;
|
|
|
|
MutexedQueue<Request> m_requests;
|
|
|
|
size_t m_parallel_limit;
|
|
|
|
|
|
|
|
// Variables exclusively used within thread
|
2023-03-03 15:00:43 +01:00
|
|
|
std::vector<std::unique_ptr<HTTPFetchOngoing>> m_all_ongoing;
|
2013-08-29 05:04:56 +02:00
|
|
|
std::list<HTTPFetchRequest> m_queued_fetches;
|
|
|
|
|
|
|
|
public:
|
2015-04-07 12:13:12 +02:00
|
|
|
CurlFetchThread(int parallel_limit) :
|
|
|
|
Thread("CurlFetch")
|
2013-08-29 05:04:56 +02:00
|
|
|
{
|
|
|
|
if (parallel_limit >= 1)
|
|
|
|
m_parallel_limit = parallel_limit;
|
|
|
|
else
|
|
|
|
m_parallel_limit = 1;
|
|
|
|
}
|
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
void requestFetch(const HTTPFetchRequest &fetch_request)
|
2013-08-29 05:04:56 +02:00
|
|
|
{
|
|
|
|
Request req;
|
|
|
|
req.type = RT_FETCH;
|
2014-09-15 02:46:45 +02:00
|
|
|
req.fetch_request = fetch_request;
|
2013-08-29 05:04:56 +02:00
|
|
|
req.event = NULL;
|
|
|
|
m_requests.push_back(req);
|
|
|
|
}
|
|
|
|
|
2022-01-01 22:44:56 +01:00
|
|
|
void requestClear(u64 caller, Event *event)
|
2013-08-29 05:04:56 +02:00
|
|
|
{
|
|
|
|
Request req;
|
|
|
|
req.type = RT_CLEAR;
|
2014-09-15 02:46:45 +02:00
|
|
|
req.fetch_request.caller = caller;
|
2013-08-29 05:04:56 +02:00
|
|
|
req.event = event;
|
|
|
|
m_requests.push_back(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
void requestWakeUp()
|
|
|
|
{
|
|
|
|
Request req;
|
|
|
|
req.type = RT_WAKEUP;
|
|
|
|
req.event = NULL;
|
|
|
|
m_requests.push_back(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Handle a request from some other thread
|
|
|
|
// E.g. new fetch; clear fetches for one caller; wake up
|
|
|
|
void processRequest(const Request &req)
|
|
|
|
{
|
|
|
|
if (req.type == RT_FETCH) {
|
|
|
|
// New fetch, queue until there are less
|
|
|
|
// than m_parallel_limit ongoing fetches
|
2014-09-15 02:46:45 +02:00
|
|
|
m_queued_fetches.push_back(req.fetch_request);
|
2013-08-29 05:04:56 +02:00
|
|
|
|
|
|
|
// see processQueued() for what happens next
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (req.type == RT_CLEAR) {
|
2022-01-01 22:44:56 +01:00
|
|
|
u64 caller = req.fetch_request.caller;
|
2013-08-29 05:04:56 +02:00
|
|
|
|
|
|
|
// Abort all ongoing fetches for the caller
|
2023-03-03 15:00:43 +01:00
|
|
|
for (auto it = m_all_ongoing.begin(); it != m_all_ongoing.end();) {
|
2014-09-15 02:46:45 +02:00
|
|
|
if ((*it)->getRequest().caller == caller) {
|
2013-08-29 05:04:56 +02:00
|
|
|
it = m_all_ongoing.erase(it);
|
2014-09-15 02:46:45 +02:00
|
|
|
} else {
|
2013-08-29 05:04:56 +02:00
|
|
|
++it;
|
2014-09-15 02:46:45 +02:00
|
|
|
}
|
2013-08-29 05:04:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Also abort all queued fetches for the caller
|
|
|
|
for (std::list<HTTPFetchRequest>::iterator
|
|
|
|
it = m_queued_fetches.begin();
|
|
|
|
it != m_queued_fetches.end();) {
|
|
|
|
if ((*it).caller == caller)
|
|
|
|
it = m_queued_fetches.erase(it);
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (req.type == RT_WAKEUP) {
|
|
|
|
// Wakeup: Nothing to do, thread is awake at this point
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req.event != NULL)
|
|
|
|
req.event->signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start new ongoing fetches if m_parallel_limit allows
|
|
|
|
void processQueued(CurlHandlePool *pool)
|
|
|
|
{
|
|
|
|
while (m_all_ongoing.size() < m_parallel_limit &&
|
|
|
|
!m_queued_fetches.empty()) {
|
|
|
|
HTTPFetchRequest request = m_queued_fetches.front();
|
|
|
|
m_queued_fetches.pop_front();
|
|
|
|
|
|
|
|
// Create ongoing fetch data and make a cURL handle
|
|
|
|
// Set cURL options based on HTTPFetchRequest
|
2023-03-03 15:00:43 +01:00
|
|
|
auto ongoing = std::make_unique<HTTPFetchOngoing>(request, pool);
|
2013-08-29 05:04:56 +02:00
|
|
|
|
|
|
|
// Initiate the connection (curl_multi_add_handle)
|
|
|
|
CURLcode res = ongoing->start(m_multi);
|
|
|
|
if (res == CURLE_OK) {
|
2023-03-03 15:00:43 +01:00
|
|
|
m_all_ongoing.push_back(std::move(ongoing));
|
|
|
|
} else {
|
2014-09-15 02:46:45 +02:00
|
|
|
httpfetch_deliver_result(*ongoing->complete(res));
|
2013-08-29 05:04:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process CURLMsg (indicates completion of a fetch)
|
|
|
|
void processCurlMessage(CURLMsg *msg)
|
|
|
|
{
|
|
|
|
// Determine which ongoing fetch the message pertains to
|
|
|
|
size_t i = 0;
|
|
|
|
bool found = false;
|
|
|
|
for (i = 0; i < m_all_ongoing.size(); ++i) {
|
2014-09-15 02:46:45 +02:00
|
|
|
if (m_all_ongoing[i]->getEasyHandle() == msg->easy_handle) {
|
2013-08-29 05:04:56 +02:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (msg->msg == CURLMSG_DONE && found) {
|
|
|
|
// m_all_ongoing[i] succeeded or failed.
|
2023-03-03 15:00:43 +01:00
|
|
|
HTTPFetchOngoing &ongoing = *m_all_ongoing[i];
|
|
|
|
httpfetch_deliver_result(*ongoing.complete(msg->data.result));
|
2013-08-29 05:04:56 +02:00
|
|
|
m_all_ongoing.erase(m_all_ongoing.begin() + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for a request from another thread, or timeout elapses
|
|
|
|
void waitForRequest(long timeout)
|
|
|
|
{
|
|
|
|
if (m_queued_fetches.empty()) {
|
|
|
|
try {
|
|
|
|
Request req = m_requests.pop_front(timeout);
|
|
|
|
processRequest(req);
|
|
|
|
}
|
|
|
|
catch (ItemNotFoundException &e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait until some IO happens, or timeout elapses
|
|
|
|
void waitForIO(long timeout)
|
|
|
|
{
|
|
|
|
fd_set read_fd_set;
|
|
|
|
fd_set write_fd_set;
|
|
|
|
fd_set exc_fd_set;
|
|
|
|
int max_fd;
|
|
|
|
long select_timeout = -1;
|
|
|
|
struct timeval select_tv;
|
|
|
|
CURLMcode mres;
|
|
|
|
|
|
|
|
FD_ZERO(&read_fd_set);
|
|
|
|
FD_ZERO(&write_fd_set);
|
|
|
|
FD_ZERO(&exc_fd_set);
|
|
|
|
|
|
|
|
mres = curl_multi_fdset(m_multi, &read_fd_set,
|
|
|
|
&write_fd_set, &exc_fd_set, &max_fd);
|
|
|
|
if (mres != CURLM_OK) {
|
|
|
|
errorstream<<"curl_multi_fdset"
|
|
|
|
<<" returned error code "<<mres
|
|
|
|
<<std::endl;
|
|
|
|
select_timeout = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mres = curl_multi_timeout(m_multi, &select_timeout);
|
|
|
|
if (mres != CURLM_OK) {
|
|
|
|
errorstream<<"curl_multi_timeout"
|
|
|
|
<<" returned error code "<<mres
|
|
|
|
<<std::endl;
|
|
|
|
select_timeout = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Limit timeout so new requests get through
|
|
|
|
if (select_timeout < 0 || select_timeout > timeout)
|
|
|
|
select_timeout = timeout;
|
|
|
|
|
|
|
|
if (select_timeout > 0) {
|
2013-12-24 19:28:09 +01:00
|
|
|
// in Winsock it is forbidden to pass three empty
|
|
|
|
// fd_sets to select(), so in that case use sleep_ms
|
2014-01-10 19:19:16 +01:00
|
|
|
if (max_fd != -1) {
|
2013-12-24 19:28:09 +01:00
|
|
|
select_tv.tv_sec = select_timeout / 1000;
|
|
|
|
select_tv.tv_usec = (select_timeout % 1000) * 1000;
|
|
|
|
int retval = select(max_fd + 1, &read_fd_set,
|
|
|
|
&write_fd_set, &exc_fd_set,
|
|
|
|
&select_tv);
|
|
|
|
if (retval == -1) {
|
|
|
|
#ifdef _WIN32
|
|
|
|
errorstream<<"select returned error code "
|
|
|
|
<<WSAGetLastError()<<std::endl;
|
|
|
|
#else
|
|
|
|
errorstream<<"select returned error code "
|
|
|
|
<<errno<<std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sleep_ms(select_timeout);
|
2013-08-29 05:04:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-07 12:13:12 +02:00
|
|
|
void *run()
|
2013-08-29 05:04:56 +02:00
|
|
|
{
|
|
|
|
CurlHandlePool pool;
|
|
|
|
|
|
|
|
m_multi = curl_multi_init();
|
|
|
|
if (m_multi == NULL) {
|
|
|
|
errorstream<<"curl_multi_init returned NULL\n";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-03-06 11:21:51 +01:00
|
|
|
FATAL_ERROR_IF(!m_all_ongoing.empty(), "Expected empty");
|
2013-08-29 05:04:56 +02:00
|
|
|
|
2015-04-07 12:13:12 +02:00
|
|
|
while (!stopRequested()) {
|
2013-08-29 05:04:56 +02:00
|
|
|
BEGIN_DEBUG_EXCEPTION_HANDLER
|
|
|
|
|
|
|
|
/*
|
|
|
|
Handle new async requests
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (!m_requests.empty()) {
|
2014-01-06 12:45:42 +01:00
|
|
|
Request req = m_requests.pop_frontNoEx();
|
2013-08-29 05:04:56 +02:00
|
|
|
processRequest(req);
|
|
|
|
}
|
|
|
|
processQueued(&pool);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Handle ongoing async requests
|
|
|
|
*/
|
|
|
|
|
|
|
|
int still_ongoing = 0;
|
|
|
|
while (curl_multi_perform(m_multi, &still_ongoing) ==
|
|
|
|
CURLM_CALL_MULTI_PERFORM)
|
|
|
|
/* noop */;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Handle completed async requests
|
|
|
|
*/
|
|
|
|
if (still_ongoing < (int) m_all_ongoing.size()) {
|
|
|
|
CURLMsg *msg;
|
|
|
|
int msgs_in_queue;
|
|
|
|
msg = curl_multi_info_read(m_multi, &msgs_in_queue);
|
|
|
|
while (msg != NULL) {
|
|
|
|
processCurlMessage(msg);
|
|
|
|
msg = curl_multi_info_read(m_multi, &msgs_in_queue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
If there are ongoing requests, wait for data
|
|
|
|
(with a timeout of 100ms so that new requests
|
|
|
|
can be processed).
|
|
|
|
|
|
|
|
If no ongoing requests, wait for a new request.
|
|
|
|
(Possibly an empty request that signals
|
|
|
|
that the thread should be stopped.)
|
|
|
|
*/
|
|
|
|
if (m_all_ongoing.empty())
|
|
|
|
waitForRequest(100000000);
|
|
|
|
else
|
|
|
|
waitForIO(100);
|
|
|
|
|
2015-10-14 08:33:04 +02:00
|
|
|
END_DEBUG_EXCEPTION_HANDLER
|
2013-08-29 05:04:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call curl_multi_remove_handle and cleanup easy handles
|
|
|
|
m_all_ongoing.clear();
|
|
|
|
|
|
|
|
m_queued_fetches.clear();
|
|
|
|
|
|
|
|
CURLMcode mres = curl_multi_cleanup(m_multi);
|
|
|
|
if (mres != CURLM_OK) {
|
|
|
|
errorstream<<"curl_multi_cleanup"
|
|
|
|
<<" returned error code "<<mres
|
|
|
|
<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-03-03 15:03:19 +01:00
|
|
|
std::unique_ptr<CurlFetchThread> g_httpfetch_thread = nullptr;
|
2013-08-29 05:04:56 +02:00
|
|
|
|
|
|
|
void httpfetch_init(int parallel_limit)
|
|
|
|
{
|
|
|
|
verbosestream<<"httpfetch_init: parallel_limit="<<parallel_limit
|
|
|
|
<<std::endl;
|
|
|
|
|
|
|
|
CURLcode res = curl_global_init(CURL_GLOBAL_DEFAULT);
|
2015-03-06 11:21:51 +01:00
|
|
|
FATAL_ERROR_IF(res != CURLE_OK, "CURL init failed");
|
2013-08-29 05:04:56 +02:00
|
|
|
|
2023-03-03 15:03:19 +01:00
|
|
|
g_httpfetch_thread = std::make_unique<CurlFetchThread>(parallel_limit);
|
2016-02-18 11:38:47 +01:00
|
|
|
|
|
|
|
// Initialize g_callerid_randomness for httpfetch_caller_alloc_secure
|
|
|
|
u64 randbuf[2];
|
|
|
|
porting::secure_rand_fill_buf(randbuf, sizeof(u64) * 2);
|
|
|
|
g_callerid_randomness = PcgRandom(randbuf[0], randbuf[1]);
|
2013-08-29 05:04:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void httpfetch_cleanup()
|
|
|
|
{
|
|
|
|
verbosestream<<"httpfetch_cleanup: cleaning up"<<std::endl;
|
|
|
|
|
2021-06-23 15:22:31 +02:00
|
|
|
if (g_httpfetch_thread) {
|
|
|
|
g_httpfetch_thread->stop();
|
|
|
|
g_httpfetch_thread->requestWakeUp();
|
|
|
|
g_httpfetch_thread->wait();
|
2023-03-03 15:03:19 +01:00
|
|
|
g_httpfetch_thread.reset();
|
2021-06-23 15:22:31 +02:00
|
|
|
}
|
2013-08-29 05:04:56 +02:00
|
|
|
|
|
|
|
curl_global_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
void httpfetch_async(const HTTPFetchRequest &fetch_request)
|
2013-08-29 05:04:56 +02:00
|
|
|
{
|
2014-09-15 02:46:45 +02:00
|
|
|
g_httpfetch_thread->requestFetch(fetch_request);
|
2015-04-07 12:13:12 +02:00
|
|
|
if (!g_httpfetch_thread->isRunning())
|
|
|
|
g_httpfetch_thread->start();
|
2013-08-29 05:04:56 +02:00
|
|
|
}
|
|
|
|
|
2022-01-01 22:44:56 +01:00
|
|
|
static void httpfetch_request_clear(u64 caller)
|
2013-08-29 05:04:56 +02:00
|
|
|
{
|
2015-04-07 12:13:12 +02:00
|
|
|
if (g_httpfetch_thread->isRunning()) {
|
2013-08-29 05:04:56 +02:00
|
|
|
Event event;
|
|
|
|
g_httpfetch_thread->requestClear(caller, &event);
|
|
|
|
event.wait();
|
2015-04-07 12:13:12 +02:00
|
|
|
} else {
|
2013-08-29 05:04:56 +02:00
|
|
|
g_httpfetch_thread->requestClear(caller, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
void httpfetch_sync(const HTTPFetchRequest &fetch_request,
|
|
|
|
HTTPFetchResult &fetch_result)
|
2013-08-29 05:04:56 +02:00
|
|
|
{
|
|
|
|
// Create ongoing fetch data and make a cURL handle
|
|
|
|
// Set cURL options based on HTTPFetchRequest
|
|
|
|
CurlHandlePool pool;
|
2014-09-15 02:46:45 +02:00
|
|
|
HTTPFetchOngoing ongoing(fetch_request, &pool);
|
2013-08-29 05:04:56 +02:00
|
|
|
// Do the fetch (curl_easy_perform)
|
|
|
|
CURLcode res = ongoing.start(NULL);
|
2014-09-15 02:46:45 +02:00
|
|
|
// Update fetch result
|
|
|
|
fetch_result = *ongoing.complete(res);
|
2013-08-29 05:04:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#else // USE_CURL
|
|
|
|
|
|
|
|
/*
|
|
|
|
USE_CURL is off:
|
|
|
|
|
|
|
|
Dummy httpfetch implementation that always returns an error.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void httpfetch_init(int parallel_limit)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void httpfetch_cleanup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
void httpfetch_async(const HTTPFetchRequest &fetch_request)
|
2013-08-29 05:04:56 +02:00
|
|
|
{
|
2014-09-15 02:46:45 +02:00
|
|
|
errorstream << "httpfetch_async: unable to fetch " << fetch_request.url
|
|
|
|
<< " because USE_CURL=0" << std::endl;
|
2013-08-29 05:04:56 +02:00
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
HTTPFetchResult fetch_result(fetch_request); // sets succeeded = false etc.
|
|
|
|
httpfetch_deliver_result(fetch_result);
|
2013-08-29 05:04:56 +02:00
|
|
|
}
|
|
|
|
|
2022-01-01 22:44:56 +01:00
|
|
|
static void httpfetch_request_clear(u64 caller)
|
2013-08-29 05:04:56 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
void httpfetch_sync(const HTTPFetchRequest &fetch_request,
|
|
|
|
HTTPFetchResult &fetch_result)
|
2013-08-29 05:04:56 +02:00
|
|
|
{
|
2014-09-15 02:46:45 +02:00
|
|
|
errorstream << "httpfetch_sync: unable to fetch " << fetch_request.url
|
|
|
|
<< " because USE_CURL=0" << std::endl;
|
2013-08-29 05:04:56 +02:00
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
fetch_result = HTTPFetchResult(fetch_request); // sets succeeded = false etc.
|
2013-08-29 05:04:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_CURL
|