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