Deindent HTTPFetchRequest::HTTPFetchRequest()
[oweals/minetest.git] / src / httpfetch.cpp
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "socket.h" // for select()
21 #include "porting.h" // for sleep_ms()
22 #include "httpfetch.h"
23 #include <iostream>
24 #include <sstream>
25 #include <list>
26 #include <map>
27 #include <errno.h>
28 #ifndef _WIN32
29 #include <sys/utsname.h>
30 #endif
31 #include "jthread/jevent.h"
32 #include "config.h"
33 #include "exceptions.h"
34 #include "debug.h"
35 #include "log.h"
36 #include "util/container.h"
37 #include "util/thread.h"
38 #include "version.h"
39 #include "main.h"
40 #include "settings.h"
41
42 JMutex g_httpfetch_mutex;
43 std::map<unsigned long, std::list<HTTPFetchResult> > g_httpfetch_results;
44
45 HTTPFetchRequest::HTTPFetchRequest()
46 {
47         url = "";
48         caller = HTTPFETCH_DISCARD;
49         request_id = 0;
50         timeout = g_settings->getS32("curl_timeout");
51         connect_timeout = timeout * 5;
52         
53         useragent = std::string("Minetest/") + minetest_version_hash + " ";
54 #ifdef _WIN32
55         useragent += "(Windows)";
56 #else
57         struct utsname osinfo;
58         uname(&osinfo);
59         useragent += std::string("(") + osinfo.sysname + "/"
60                         + osinfo.release + " " + osinfo.machine + ")";
61 #endif
62 }
63
64
65 static void httpfetch_deliver_result(const HTTPFetchResult &fetchresult)
66 {
67         unsigned long caller = fetchresult.caller;
68         if (caller != HTTPFETCH_DISCARD) {
69                 JMutexAutoLock lock(g_httpfetch_mutex);
70                 g_httpfetch_results[caller].push_back(fetchresult);
71         }
72 }
73
74 static void httpfetch_request_clear(unsigned long caller);
75
76 unsigned long httpfetch_caller_alloc()
77 {
78         JMutexAutoLock lock(g_httpfetch_mutex);
79
80         // Check each caller ID except HTTPFETCH_DISCARD
81         const unsigned long discard = HTTPFETCH_DISCARD;
82         for (unsigned long caller = discard + 1; caller != discard; ++caller) {
83                 std::map<unsigned long, std::list<HTTPFetchResult> >::iterator
84                         it = g_httpfetch_results.find(caller);
85                 if (it == g_httpfetch_results.end()) {
86                         verbosestream<<"httpfetch_caller_alloc: allocating "
87                                         <<caller<<std::endl;
88                         // Access element to create it
89                         g_httpfetch_results[caller];
90                         return caller;
91                 }
92         }
93
94         assert("httpfetch_caller_alloc: ran out of caller IDs" == 0);
95         return discard;
96 }
97
98 void httpfetch_caller_free(unsigned long caller)
99 {
100         verbosestream<<"httpfetch_caller_free: freeing "
101                         <<caller<<std::endl;
102
103         httpfetch_request_clear(caller);
104         if (caller != HTTPFETCH_DISCARD) {
105                 JMutexAutoLock lock(g_httpfetch_mutex);
106                 g_httpfetch_results.erase(caller);
107         }
108 }
109
110 bool httpfetch_async_get(unsigned long caller, HTTPFetchResult &fetchresult)
111 {
112         JMutexAutoLock lock(g_httpfetch_mutex);
113
114         // Check that caller exists
115         std::map<unsigned long, std::list<HTTPFetchResult> >::iterator
116                 it = g_httpfetch_results.find(caller);
117         if (it == g_httpfetch_results.end())
118                 return false;
119
120         // Check that result queue is nonempty
121         std::list<HTTPFetchResult> &callerresults = it->second;
122         if (callerresults.empty())
123                 return false;
124
125         // Pop first result
126         fetchresult = callerresults.front();
127         callerresults.pop_front();
128         return true;
129 }
130
131 #if USE_CURL
132 #include <curl/curl.h>
133
134 /*
135         USE_CURL is on: use cURL based httpfetch implementation
136 */
137
138 static size_t httpfetch_writefunction(
139                 char *ptr, size_t size, size_t nmemb, void *userdata)
140 {
141         std::ostringstream *stream = (std::ostringstream*)userdata;
142         size_t count = size * nmemb;
143         stream->write(ptr, count);
144         return count;
145 }
146
147 static size_t httpfetch_discardfunction(
148                 char *ptr, size_t size, size_t nmemb, void *userdata)
149 {
150         return size * nmemb;
151 }
152
153 class CurlHandlePool
154 {
155         std::list<CURL*> handles;
156
157 public:
158         CurlHandlePool() {}
159         ~CurlHandlePool()
160         {
161                 for (std::list<CURL*>::iterator it = handles.begin();
162                                 it != handles.end(); ++it) {
163                         curl_easy_cleanup(*it);
164                 }
165         }
166         CURL * alloc()
167         {
168                 CURL *curl;
169                 if (handles.empty()) {
170                         curl = curl_easy_init();
171                         if (curl == NULL) {
172                                 errorstream<<"curl_easy_init returned NULL"<<std::endl;
173                         }
174                 }
175                 else {
176                         curl = handles.front();
177                         handles.pop_front();
178                 }
179                 return curl;
180         }
181         void free(CURL *handle)
182         {
183                 if (handle)
184                         handles.push_back(handle);
185         }
186 };
187
188 struct HTTPFetchOngoing
189 {
190         CurlHandlePool *pool;
191         CURL *curl;
192         CURLM *multi;
193         HTTPFetchRequest request;
194         HTTPFetchResult result;
195         std::ostringstream oss;
196         char *post_fields;
197         struct curl_slist *httpheader;
198
199         HTTPFetchOngoing(HTTPFetchRequest request_, CurlHandlePool *pool_):
200                 pool(pool_),
201                 curl(NULL),
202                 multi(NULL),
203                 request(request_),
204                 result(request_),
205                 oss(std::ios::binary),
206                 httpheader(NULL)
207         {
208                 curl = pool->alloc();
209                 if (curl != NULL) {
210                         // Set static cURL options
211                         curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
212                         curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
213                         curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
214                         curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 1);
215
216 #if LIBCURL_VERSION_NUM >= 0x071304
217                         // Restrict protocols so that curl vulnerabilities in
218                         // other protocols don't affect us.
219                         // These settings were introduced in curl 7.19.4.
220                         long protocols =
221                                 CURLPROTO_HTTP |
222                                 CURLPROTO_HTTPS |
223                                 CURLPROTO_FTP |
224                                 CURLPROTO_FTPS;
225                         curl_easy_setopt(curl, CURLOPT_PROTOCOLS, protocols);
226                         curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, protocols);
227 #endif
228
229                         // Set cURL options based on HTTPFetchRequest
230                         curl_easy_setopt(curl, CURLOPT_URL,
231                                         request.url.c_str());
232                         curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS,
233                                         request.timeout);
234                         curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS,
235                                         request.connect_timeout);
236
237                         if (request.useragent != "")
238                                 curl_easy_setopt(curl, CURLOPT_USERAGENT, request.useragent.c_str());
239
240                         // Set up a write callback that writes to the
241                         // ostringstream ongoing->oss, unless the data
242                         // is to be discarded
243                         if (request.caller == HTTPFETCH_DISCARD) {
244                                 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
245                                                 httpfetch_discardfunction);
246                                 curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);
247                         }
248                         else {
249                                 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
250                                                 httpfetch_writefunction);
251                                 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &oss);
252                         }
253                         // Set POST (or GET) data
254                         if (request.post_fields.empty()) {
255                                 curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
256                         }
257                         else {
258                                 curl_easy_setopt(curl, CURLOPT_POST, 1);
259                                 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE,
260                                                 request.post_fields.size());
261                                 curl_easy_setopt(curl, CURLOPT_POSTFIELDS,
262                                                 request.post_fields.c_str());
263                                 // request.post_fields must now *never* be
264                                 // modified until CURLOPT_POSTFIELDS is cleared
265                         }
266                         // Set additional HTTP headers
267                         for (size_t i = 0; i < request.extra_headers.size(); ++i) {
268                                 httpheader = curl_slist_append(
269                                         httpheader,
270                                         request.extra_headers[i].c_str());
271                         }
272                         curl_easy_setopt(curl, CURLOPT_HTTPHEADER, httpheader);
273                 }
274         }
275
276         CURLcode start(CURLM *multi_)
277         {
278                 if (curl == NULL)
279                         return CURLE_FAILED_INIT;
280
281                 if (multi_) {
282                         // Multi interface (async)
283                         CURLMcode mres = curl_multi_add_handle(multi_, curl);
284                         if (mres != CURLM_OK) {
285                                 errorstream<<"curl_multi_add_handle"
286                                         <<" returned error code "<<mres
287                                         <<std::endl;
288                                 return CURLE_FAILED_INIT;
289                         }
290                         multi = multi_; // store for curl_multi_remove_handle
291                         return CURLE_OK;
292                 }
293                 else {
294                         // Easy interface (sync)
295                         return curl_easy_perform(curl);
296                 }
297         }
298
299         void complete(CURLcode res)
300         {
301                 result.succeeded = (res == CURLE_OK);
302                 result.timeout = (res == CURLE_OPERATION_TIMEDOUT);
303                 result.data = oss.str();
304
305                 // Get HTTP/FTP response code
306                 result.response_code = 0;
307                 if (curl != NULL) {
308                         if (curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE,
309                                         &result.response_code) != CURLE_OK) {
310                                 //we failed to get a return code make sure it is still 0
311                                 result.response_code = 0;
312                         }
313                 }
314
315                 if (res != CURLE_OK) {
316                         infostream<<request.url<<" not found ("
317                                 <<curl_easy_strerror(res)<<")"
318                                 <<" (response code "<<result.response_code<<")"
319                                 <<std::endl;
320                 }
321         }
322
323         ~HTTPFetchOngoing()
324         {
325                 if (multi != NULL) {
326                         CURLMcode mres = curl_multi_remove_handle(multi, curl);
327                         if (mres != CURLM_OK) {
328                                 errorstream<<"curl_multi_remove_handle"
329                                         <<" returned error code "<<mres
330                                         <<std::endl;
331                         }
332                 }
333
334                 // Set safe options for the reusable cURL handle
335                 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
336                                 httpfetch_discardfunction);
337                 curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);
338                 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL);
339                 if (httpheader != NULL) {
340                         curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL);
341                         curl_slist_free_all(httpheader);
342                 }
343
344                 // Store the cURL handle for reuse
345                 pool->free(curl);
346         }
347 };
348
349 class CurlFetchThread : public JThread
350 {
351 protected:
352         enum RequestType {
353                 RT_FETCH,
354                 RT_CLEAR,
355                 RT_WAKEUP,
356         };
357
358         struct Request {
359                 RequestType type;
360                 HTTPFetchRequest fetchrequest;
361                 Event *event;
362         };
363
364         CURLM *m_multi;
365         MutexedQueue<Request> m_requests;
366         size_t m_parallel_limit;
367
368         // Variables exclusively used within thread
369         std::vector<HTTPFetchOngoing*> m_all_ongoing;
370         std::list<HTTPFetchRequest> m_queued_fetches;
371
372 public:
373         CurlFetchThread(int parallel_limit)
374         {
375                 if (parallel_limit >= 1)
376                         m_parallel_limit = parallel_limit;
377                 else
378                         m_parallel_limit = 1;
379         }
380
381         void requestFetch(const HTTPFetchRequest &fetchrequest)
382         {
383                 Request req;
384                 req.type = RT_FETCH;
385                 req.fetchrequest = fetchrequest;
386                 req.event = NULL;
387                 m_requests.push_back(req);
388         }
389
390         void requestClear(unsigned long caller, Event *event)
391         {
392                 Request req;
393                 req.type = RT_CLEAR;
394                 req.fetchrequest.caller = caller;
395                 req.event = event;
396                 m_requests.push_back(req);
397         }
398
399         void requestWakeUp()
400         {
401                 Request req;
402                 req.type = RT_WAKEUP;
403                 req.event = NULL;
404                 m_requests.push_back(req);
405         }
406
407 protected:
408         // Handle a request from some other thread
409         // E.g. new fetch; clear fetches for one caller; wake up
410         void processRequest(const Request &req)
411         {
412                 if (req.type == RT_FETCH) {
413                         // New fetch, queue until there are less
414                         // than m_parallel_limit ongoing fetches
415                         m_queued_fetches.push_back(req.fetchrequest);
416
417                         // see processQueued() for what happens next
418
419                 }
420                 else if (req.type == RT_CLEAR) {
421                         unsigned long caller = req.fetchrequest.caller;
422
423                         // Abort all ongoing fetches for the caller
424                         for (std::vector<HTTPFetchOngoing*>::iterator
425                                         it = m_all_ongoing.begin();
426                                         it != m_all_ongoing.end();) {
427                                 if ((*it)->request.caller == caller) {
428                                         delete (*it);
429                                         it = m_all_ongoing.erase(it);
430                                 }
431                                 else
432                                         ++it;
433                         }
434
435                         // Also abort all queued fetches for the caller
436                         for (std::list<HTTPFetchRequest>::iterator
437                                         it = m_queued_fetches.begin();
438                                         it != m_queued_fetches.end();) {
439                                 if ((*it).caller == caller)
440                                         it = m_queued_fetches.erase(it);
441                                 else
442                                         ++it;
443                         }
444                 }
445                 else if (req.type == RT_WAKEUP) {
446                         // Wakeup: Nothing to do, thread is awake at this point
447                 }
448
449                 if (req.event != NULL)
450                         req.event->signal();
451         }
452
453         // Start new ongoing fetches if m_parallel_limit allows
454         void processQueued(CurlHandlePool *pool)
455         {
456                 while (m_all_ongoing.size() < m_parallel_limit &&
457                                 !m_queued_fetches.empty()) {
458                         HTTPFetchRequest request = m_queued_fetches.front();
459                         m_queued_fetches.pop_front();
460
461                         // Create ongoing fetch data and make a cURL handle
462                         // Set cURL options based on HTTPFetchRequest
463                         HTTPFetchOngoing *ongoing =
464                                 new HTTPFetchOngoing(request, pool);
465
466                         // Initiate the connection (curl_multi_add_handle)
467                         CURLcode res = ongoing->start(m_multi);
468                         if (res == CURLE_OK) {
469                                 m_all_ongoing.push_back(ongoing);
470                         }
471                         else {
472                                 ongoing->complete(res);
473                                 httpfetch_deliver_result(ongoing->result);
474                                 delete ongoing;
475                         }
476                 }
477         }
478
479         // Process CURLMsg (indicates completion of a fetch)
480         void processCurlMessage(CURLMsg *msg)
481         {
482                 // Determine which ongoing fetch the message pertains to
483                 size_t i = 0;
484                 bool found = false;
485                 for (i = 0; i < m_all_ongoing.size(); ++i) {
486                         if (m_all_ongoing[i]->curl == msg->easy_handle) {
487                                 found = true;
488                                 break;
489                         }
490                 }
491                 if (msg->msg == CURLMSG_DONE && found) {
492                         // m_all_ongoing[i] succeeded or failed.
493                         HTTPFetchOngoing *ongoing = m_all_ongoing[i];
494                         ongoing->complete(msg->data.result);
495                         httpfetch_deliver_result(ongoing->result);
496                         delete ongoing;
497                         m_all_ongoing.erase(m_all_ongoing.begin() + i);
498                 }
499         }
500
501         // Wait for a request from another thread, or timeout elapses
502         void waitForRequest(long timeout)
503         {
504                 if (m_queued_fetches.empty()) {
505                         try {
506                                 Request req = m_requests.pop_front(timeout);
507                                 processRequest(req);
508                         }
509                         catch (ItemNotFoundException &e) {}
510                 }
511         }
512
513         // Wait until some IO happens, or timeout elapses
514         void waitForIO(long timeout)
515         {
516                 fd_set read_fd_set;
517                 fd_set write_fd_set;
518                 fd_set exc_fd_set;
519                 int max_fd;
520                 long select_timeout = -1;
521                 struct timeval select_tv;
522                 CURLMcode mres;
523
524                 FD_ZERO(&read_fd_set);
525                 FD_ZERO(&write_fd_set);
526                 FD_ZERO(&exc_fd_set);
527
528                 mres = curl_multi_fdset(m_multi, &read_fd_set,
529                                 &write_fd_set, &exc_fd_set, &max_fd);
530                 if (mres != CURLM_OK) {
531                         errorstream<<"curl_multi_fdset"
532                                 <<" returned error code "<<mres
533                                 <<std::endl;
534                         select_timeout = 0;
535                 }
536
537                 mres = curl_multi_timeout(m_multi, &select_timeout);
538                 if (mres != CURLM_OK) {
539                         errorstream<<"curl_multi_timeout"
540                                 <<" returned error code "<<mres
541                                 <<std::endl;
542                         select_timeout = 0;
543                 }
544
545                 // Limit timeout so new requests get through
546                 if (select_timeout < 0 || select_timeout > timeout)
547                         select_timeout = timeout;
548
549                 if (select_timeout > 0) {
550                         // in Winsock it is forbidden to pass three empty
551                         // fd_sets to select(), so in that case use sleep_ms
552                         if (max_fd != -1) {
553                                 select_tv.tv_sec = select_timeout / 1000;
554                                 select_tv.tv_usec = (select_timeout % 1000) * 1000;
555                                 int retval = select(max_fd + 1, &read_fd_set,
556                                                 &write_fd_set, &exc_fd_set,
557                                                 &select_tv);
558                                 if (retval == -1) {
559                                         #ifdef _WIN32
560                                         errorstream<<"select returned error code "
561                                                 <<WSAGetLastError()<<std::endl;
562                                         #else
563                                         errorstream<<"select returned error code "
564                                                 <<errno<<std::endl;
565                                         #endif
566                                 }
567                         }
568                         else {
569                                 sleep_ms(select_timeout);
570                         }
571                 }
572         }
573
574         void * Thread()
575         {
576                 ThreadStarted();
577                 log_register_thread("CurlFetchThread");
578                 DSTACK(__FUNCTION_NAME);
579
580                 CurlHandlePool pool;
581
582                 m_multi = curl_multi_init();
583                 if (m_multi == NULL) {
584                         errorstream<<"curl_multi_init returned NULL\n";
585                         return NULL;
586                 }
587
588                 assert(m_all_ongoing.empty());
589
590                 while (!StopRequested()) {
591                         BEGIN_DEBUG_EXCEPTION_HANDLER
592
593                         /*
594                                 Handle new async requests
595                         */
596
597                         while (!m_requests.empty()) {
598                                 Request req = m_requests.pop_frontNoEx();
599                                 processRequest(req);
600                         }
601                         processQueued(&pool);
602
603                         /*
604                                 Handle ongoing async requests
605                         */
606
607                         int still_ongoing = 0;
608                         while (curl_multi_perform(m_multi, &still_ongoing) ==
609                                         CURLM_CALL_MULTI_PERFORM)
610                                 /* noop */;
611
612                         /*
613                                 Handle completed async requests
614                         */
615                         if (still_ongoing < (int) m_all_ongoing.size()) {
616                                 CURLMsg *msg;
617                                 int msgs_in_queue;
618                                 msg = curl_multi_info_read(m_multi, &msgs_in_queue);
619                                 while (msg != NULL) {
620                                         processCurlMessage(msg);
621                                         msg = curl_multi_info_read(m_multi, &msgs_in_queue);
622                                 }
623                         }
624
625                         /*
626                                 If there are ongoing requests, wait for data
627                                 (with a timeout of 100ms so that new requests
628                                 can be processed).
629
630                                 If no ongoing requests, wait for a new request.
631                                 (Possibly an empty request that signals
632                                 that the thread should be stopped.)
633                         */
634                         if (m_all_ongoing.empty())
635                                 waitForRequest(100000000);
636                         else
637                                 waitForIO(100);
638
639                         END_DEBUG_EXCEPTION_HANDLER(errorstream)
640                 }
641
642                 // Call curl_multi_remove_handle and cleanup easy handles
643                 for (size_t i = 0; i < m_all_ongoing.size(); ++i) {
644                         delete m_all_ongoing[i];
645                 }
646                 m_all_ongoing.clear();
647
648                 m_queued_fetches.clear();
649
650                 CURLMcode mres = curl_multi_cleanup(m_multi);
651                 if (mres != CURLM_OK) {
652                         errorstream<<"curl_multi_cleanup"
653                                 <<" returned error code "<<mres
654                                 <<std::endl;
655                 }
656
657                 return NULL;
658         }
659 };
660
661 CurlFetchThread *g_httpfetch_thread = NULL;
662
663 void httpfetch_init(int parallel_limit)
664 {
665         verbosestream<<"httpfetch_init: parallel_limit="<<parallel_limit
666                         <<std::endl;
667
668         CURLcode res = curl_global_init(CURL_GLOBAL_DEFAULT);
669         assert(res == CURLE_OK);
670
671         g_httpfetch_thread = new CurlFetchThread(parallel_limit);
672 }
673
674 void httpfetch_cleanup()
675 {
676         verbosestream<<"httpfetch_cleanup: cleaning up"<<std::endl;
677
678         g_httpfetch_thread->Stop();
679         g_httpfetch_thread->requestWakeUp();
680         g_httpfetch_thread->Wait();
681         delete g_httpfetch_thread;
682
683         curl_global_cleanup();
684 }
685
686 void httpfetch_async(const HTTPFetchRequest &fetchrequest)
687 {
688         g_httpfetch_thread->requestFetch(fetchrequest);
689         if (!g_httpfetch_thread->IsRunning())
690                 g_httpfetch_thread->Start();
691 }
692
693 static void httpfetch_request_clear(unsigned long caller)
694 {
695         if (g_httpfetch_thread->IsRunning()) {
696                 Event event;
697                 g_httpfetch_thread->requestClear(caller, &event);
698                 event.wait();
699         }
700         else {
701                 g_httpfetch_thread->requestClear(caller, NULL);
702         }
703 }
704
705 void httpfetch_sync(const HTTPFetchRequest &fetchrequest,
706                 HTTPFetchResult &fetchresult)
707 {
708         // Create ongoing fetch data and make a cURL handle
709         // Set cURL options based on HTTPFetchRequest
710         CurlHandlePool pool;
711         HTTPFetchOngoing ongoing(fetchrequest, &pool);
712         // Do the fetch (curl_easy_perform)
713         CURLcode res = ongoing.start(NULL);
714         // Update fetchresult
715         ongoing.complete(res);
716         fetchresult = ongoing.result;
717 }
718
719 #else  // USE_CURL
720
721 /*
722         USE_CURL is off:
723
724         Dummy httpfetch implementation that always returns an error.
725 */
726
727 void httpfetch_init(int parallel_limit)
728 {
729 }
730
731 void httpfetch_cleanup()
732 {
733 }
734
735 void httpfetch_async(const HTTPFetchRequest &fetchrequest)
736 {
737         errorstream<<"httpfetch_async: unable to fetch "<<fetchrequest.url
738                         <<" because USE_CURL=0"<<std::endl;
739
740         HTTPFetchResult fetchresult(fetchrequest); // sets succeeded = false etc.
741         httpfetch_deliver_result(fetchresult);
742 }
743
744 static void httpfetch_request_clear(unsigned long caller)
745 {
746 }
747
748 void httpfetch_sync(const HTTPFetchRequest &fetchrequest,
749                 HTTPFetchResult &fetchresult)
750 {
751         errorstream<<"httpfetch_sync: unable to fetch "<<fetchrequest.url
752                         <<" because USE_CURL=0"<<std::endl;
753
754         fetchresult = HTTPFetchResult(fetchrequest); // sets succeeded = false etc.
755 }
756
757 #endif  // USE_CURL