dns hijacker code review
[oweals/gnunet.git] / src / transport / plugin_transport_http_client.c
1 /*
2      This file is part of GNUnet
3      (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file transport/plugin_transport_http_client.c
23  * @brief http transport service plugin
24  * @author Matthias Wachs
25  */
26
27 #include "plugin_transport_http.h"
28
29 #if VERBOSE_CURL
30 /**
31  * Function to log curl debug messages with GNUNET_log
32  * @param curl handle
33  * @param type curl_infotype
34  * @param data data
35  * @param size size
36  * @param cls  closure
37  * @return 0
38  */
39 static int
40 client_log (CURL * curl, curl_infotype type, char *data, size_t size, void *cls)
41 {
42   if (type == CURLINFO_TEXT)
43   {
44     char text[size + 2];
45
46     memcpy (text, data, size);
47     if (text[size - 1] == '\n')
48       text[size] = '\0';
49     else
50     {
51       text[size] = '\n';
52       text[size + 1] = '\0';
53     }
54 #if BUILD_HTTPS
55     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-https",
56                      "Client: %X - %s", cls, text);
57 #else
58     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-http",
59                      "Client: %X - %s", cls, text);
60 #endif
61   }
62   return 0;
63 }
64 #endif
65
66 /**
67  * Task performing curl operations
68  * @param cls plugin as closure
69  * @param tc gnunet scheduler task context
70  */
71 static void
72 client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
73
74 /**
75  * Function setting up file descriptors and scheduling task to run
76  *
77  * @param  plugin plugin as closure
78  * @param now schedule task in 1ms, regardless of what curl may say
79  * @return GNUNET_SYSERR for hard failure, GNUNET_OK for ok
80  */
81 static int
82 client_schedule (struct Plugin *plugin, int now)
83 {
84   fd_set rs;
85   fd_set ws;
86   fd_set es;
87   int max;
88   struct GNUNET_NETWORK_FDSet *grs;
89   struct GNUNET_NETWORK_FDSet *gws;
90   long to;
91   CURLMcode mret;
92   struct GNUNET_TIME_Relative timeout;
93
94   /* Cancel previous scheduled task */
95   if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK)
96   {
97     GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
98     plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
99   }
100
101   max = -1;
102   FD_ZERO (&rs);
103   FD_ZERO (&ws);
104   FD_ZERO (&es);
105   mret = curl_multi_fdset (plugin->client_mh, &rs, &ws, &es, &max);
106   if (mret != CURLM_OK)
107   {
108     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
109                 "curl_multi_fdset", __FILE__, __LINE__,
110                 curl_multi_strerror (mret));
111     return GNUNET_SYSERR;
112   }
113   mret = curl_multi_timeout (plugin->client_mh, &to);
114   if (to == -1)
115     timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1);
116   else
117     timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, to);
118   if (now == GNUNET_YES)
119     timeout = GNUNET_TIME_UNIT_MILLISECONDS;
120
121   if (mret != CURLM_OK)
122   {
123     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
124                 "curl_multi_timeout", __FILE__, __LINE__,
125                 curl_multi_strerror (mret));
126     return GNUNET_SYSERR;
127   }
128
129   grs = GNUNET_NETWORK_fdset_create ();
130   gws = GNUNET_NETWORK_fdset_create ();
131   GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
132   GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
133
134   plugin->client_perform_task =
135       GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
136                                    GNUNET_SCHEDULER_NO_TASK, timeout, grs, gws,
137                                    &client_run, plugin);
138   GNUNET_NETWORK_fdset_destroy (gws);
139   GNUNET_NETWORK_fdset_destroy (grs);
140   return GNUNET_OK;
141 }
142
143
144 int
145 client_send (struct Session *s, struct HTTP_Message *msg)
146 {
147   GNUNET_CONTAINER_DLL_insert (s->msg_head, s->msg_tail, msg);
148
149   if ((s != NULL) && (s->client_put_paused == GNUNET_YES))
150   {
151 #if VERBOSE_CLIENT
152     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
153                      "Client: %X was suspended, unpausing\n", s->client_put);
154 #endif
155     s->client_put_paused = GNUNET_NO;
156     curl_easy_pause (s->client_put, CURLPAUSE_CONT);
157   }
158
159   client_schedule (s->plugin, GNUNET_YES);
160
161   return GNUNET_OK;
162 }
163
164
165
166 /**
167  * Task performing curl operations
168  * @param cls plugin as closure
169  * @param tc gnunet scheduler task context
170  */
171 static void
172 client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
173 {
174   struct Plugin *plugin = cls;
175   int running;
176   CURLMcode mret;
177
178   GNUNET_assert (cls != NULL);
179
180   plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
181   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
182     return;
183
184   do
185   {
186     running = 0;
187     mret = curl_multi_perform (plugin->client_mh, &running);
188
189     CURLMsg *msg;
190     int msgs_left;
191
192     while ((msg = curl_multi_info_read (plugin->client_mh, &msgs_left)))
193     {
194       CURL *easy_h = msg->easy_handle;
195       struct Session *s = NULL;
196       char *d = (char *) s;
197
198
199       //GNUNET_assert (easy_h != NULL);
200       if (easy_h == NULL)
201       {
202         GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
203                          "Client: connection to ended with reason %i: `%s', %i handles running\n",
204                          msg->data.result,
205                          curl_easy_strerror (msg->data.result), running);
206         continue;
207       }
208
209       GNUNET_assert (CURLE_OK ==
210                      curl_easy_getinfo (easy_h, CURLINFO_PRIVATE, &d));
211       s = (struct Session *) d;
212       GNUNET_assert (s != NULL);
213
214       if (msg->msg == CURLMSG_DONE)
215       {
216         GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
217                          "Client: %X connection to '%s'  %s ended with reason %i: `%s'\n",
218                          msg->easy_handle, GNUNET_i2s (&s->target),
219                          http_plugin_address_to_string (NULL, s->addr,
220                                                         s->addrlen),
221                          msg->data.result,
222                          curl_easy_strerror (msg->data.result));
223
224         client_disconnect (s);
225         //GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,"Notifying about ended session to peer `%s' `%s'\n", GNUNET_i2s (&s->target), http_plugin_address_to_string (plugin, s->addr, s->addrlen));
226         notify_session_end (plugin, &s->target, s);
227       }
228     }
229   }
230   while (mret == CURLM_CALL_MULTI_PERFORM);
231   client_schedule (plugin, GNUNET_NO);
232 }
233
234 int
235 client_disconnect (struct Session *s)
236 {
237   int res = GNUNET_OK;
238   CURLMcode mret;
239   struct Plugin *plugin = s->plugin;
240   struct HTTP_Message *msg;
241   struct HTTP_Message *t;
242
243
244
245   if (s->client_put != NULL)
246   {
247 #if DEBUG_HTTP
248     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
249                      "Client: %X Deleting outbound PUT session to peer `%s'\n",
250                      s->client_put, GNUNET_i2s (&s->target));
251 #endif
252
253     mret = curl_multi_remove_handle (plugin->client_mh, s->client_put);
254     if (mret != CURLM_OK)
255     {
256       curl_easy_cleanup (s->client_put);
257       res = GNUNET_SYSERR;
258       GNUNET_break (0);
259     }
260     curl_easy_cleanup (s->client_put);
261     s->client_put = NULL;
262   }
263
264
265   if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK)
266   {
267     GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
268     s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
269   }
270
271   if (s->client_get != NULL)
272   {
273 #if DEBUG_HTTP
274     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
275                      "Client: %X Deleting outbound GET session to peer `%s'\n",
276                      s->client_get, GNUNET_i2s (&s->target));
277 #endif
278
279     mret = curl_multi_remove_handle (plugin->client_mh, s->client_get);
280     if (mret != CURLM_OK)
281     {
282       curl_easy_cleanup (s->client_get);
283       res = GNUNET_SYSERR;
284       GNUNET_break (0);
285     }
286     curl_easy_cleanup (s->client_get);
287     s->client_get = NULL;
288   }
289
290   msg = s->msg_head;
291   while (msg != NULL)
292   {
293     t = msg->next;
294     if (NULL != msg->transmit_cont)
295       msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR);
296     GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
297     GNUNET_free (msg);
298     msg = t;
299   }
300
301   plugin->cur_connections -= 2;
302   /* Re-schedule since handles have changed */
303   if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK)
304   {
305     GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
306     plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
307   }
308
309   client_schedule (plugin, GNUNET_YES);
310
311   return res;
312 }
313
314 static void
315 client_receive_mst_cb (void *cls, void *client,
316                        const struct GNUNET_MessageHeader *message)
317 {
318   struct Session *s = cls;
319   struct GNUNET_TIME_Relative delay;
320
321   delay = http_plugin_receive (s, &s->target, message, s, s->addr, s->addrlen);
322   s->next_receive =
323       GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay);
324
325   if (GNUNET_TIME_absolute_get ().abs_value < s->next_receive.abs_value)
326   {
327 #if VERBOSE_CLIENT
328     struct Plugin *plugin = s->plugin;
329
330     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
331                      "Client: peer `%s' address `%s' next read delayed for %llu ms\n",
332                      GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen),
333                      delay);
334 #endif
335   }
336 }
337
338 static void
339 client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
340 {
341   struct Session *s = cls;
342
343   s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
344
345   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
346     return;
347
348   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
349                    "Client: %X Waking up receive handle\n", s->client_get);
350
351   if (s->client_get != NULL)
352     curl_easy_pause (s->client_get, CURLPAUSE_CONT);
353
354 }
355
356 /**
357 * Callback method used with libcurl
358 * Method is called when libcurl needs to write data during sending
359 * @param stream pointer where to write data
360 * @param size size of an individual element
361 * @param nmemb count of elements that can be written to the buffer
362 * @param cls destination pointer, passed to the libcurl handle
363 * @return bytes read from stream
364 */
365 static size_t
366 client_receive (void *stream, size_t size, size_t nmemb, void *cls)
367 {
368   struct Session *s = cls;
369   struct GNUNET_TIME_Absolute now;
370   size_t len = size * nmemb;
371
372
373 #if VERBOSE_CLIENT
374   struct Plugin *plugin = s->plugin;
375
376   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
377                    "Client: Received %Zu bytes from peer `%s'\n", len,
378                    GNUNET_i2s (&s->target));
379 #endif
380
381   now = GNUNET_TIME_absolute_get ();
382   if (now.abs_value < s->next_receive.abs_value)
383   {
384     struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
385     struct GNUNET_TIME_Relative delta =
386         GNUNET_TIME_absolute_get_difference (now, s->next_receive);
387 #if DEBUG_CLIENT
388     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
389                      "Client: %X No inbound bandwidth available! Next read was delayed for %llu ms\n",
390                      s->client_get, delta.rel_value);
391 #endif
392     if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK)
393     {
394       GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
395       s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
396     }
397     s->recv_wakeup_task =
398         GNUNET_SCHEDULER_add_delayed (delta, &client_wake_up, s);
399     return CURLPAUSE_ALL;
400   }
401
402
403   if (s->msg_tk == NULL)
404     s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s);
405
406   GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO, GNUNET_NO);
407
408   return len;
409 }
410
411 /**
412  * Callback method used with libcurl
413  * Method is called when libcurl needs to read data during sending
414  * @param stream pointer where to write data
415  * @param size size of an individual element
416  * @param nmemb count of elements that can be written to the buffer
417  * @param cls source pointer, passed to the libcurl handle
418  * @return bytes written to stream, returning 0 will terminate connection!
419  */
420 static size_t
421 client_send_cb (void *stream, size_t size, size_t nmemb, void *cls)
422 {
423   struct Session *s = cls;
424
425 #if VERBOSE_CLIENT
426   struct Plugin *plugin = s->plugin;
427 #endif
428   size_t bytes_sent = 0;
429   size_t len;
430
431   struct HTTP_Message *msg = s->msg_head;
432
433   if (msg == NULL)
434   {
435 #if VERBOSE_CLIENT
436     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
437                      "Client: %X Nothing to send! Suspending PUT handle!\n",
438                      s->client_put);
439 #endif
440     s->client_put_paused = GNUNET_YES;
441     return CURL_READFUNC_PAUSE;
442   }
443
444   GNUNET_assert (msg != NULL);
445   /* data to send */
446   if (msg->pos < msg->size)
447   {
448     /* data fit in buffer */
449     if ((msg->size - msg->pos) <= (size * nmemb))
450     {
451       len = (msg->size - msg->pos);
452       memcpy (stream, &msg->buf[msg->pos], len);
453       msg->pos += len;
454       bytes_sent = len;
455     }
456     else
457     {
458       len = size * nmemb;
459       memcpy (stream, &msg->buf[msg->pos], len);
460       msg->pos += len;
461       bytes_sent = len;
462     }
463   }
464   /* no data to send */
465   else
466   {
467     GNUNET_assert (0);
468     bytes_sent = 0;
469   }
470
471   if (msg->pos == msg->size)
472   {
473 #if VERBOSE_CLIENT
474     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
475                      "Client: %X Message with %u bytes sent, removing message from queue\n",
476                      s->client_put, msg->size, msg->pos);
477 #endif
478     /* Calling transmit continuation  */
479     if (NULL != msg->transmit_cont)
480       msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK);
481     GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
482     GNUNET_free (msg);
483   }
484   return bytes_sent;
485 }
486
487 int
488 client_connect (struct Session *s)
489 {
490   struct Plugin *plugin = s->plugin;
491   int res = GNUNET_OK;
492   char *url;
493   CURLMcode mret;
494
495 #if VERBOSE_CLIENT
496 #endif
497   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
498                    "Initiating outbound session peer `%s'\n",
499                    GNUNET_i2s (&s->target));
500
501
502   s->inbound = GNUNET_NO;
503
504   plugin->last_tag++;
505   /* create url */
506   GNUNET_asprintf (&url, "%s%s;%u",
507                    http_plugin_address_to_string (plugin, s->addr, s->addrlen),
508                    GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey),
509                    plugin->last_tag);
510 #if 0
511   GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, "URL `%s'\n", url);
512 #endif
513   /* create get connection */
514   s->client_get = curl_easy_init ();
515 #if VERBOSE_CURL
516   curl_easy_setopt (s->client_get, CURLOPT_VERBOSE, 1L);
517   curl_easy_setopt (s->client_get, CURLOPT_DEBUGFUNCTION, &client_log);
518   curl_easy_setopt (s->client_get, CURLOPT_DEBUGDATA, s->client_get);
519 #endif
520 #if BUILD_HTTPS
521   curl_easy_setopt (s->client_get, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
522   curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 0);
523   curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 0);
524 #endif
525   curl_easy_setopt (s->client_get, CURLOPT_URL, url);
526   //curl_easy_setopt (s->client_get, CURLOPT_HEADERFUNCTION, &curl_get_header_cb);
527   //curl_easy_setopt (s->client_get, CURLOPT_WRITEHEADER, ps);
528   curl_easy_setopt (s->client_get, CURLOPT_READFUNCTION, client_send_cb);
529   curl_easy_setopt (s->client_get, CURLOPT_READDATA, s);
530   curl_easy_setopt (s->client_get, CURLOPT_WRITEFUNCTION, client_receive);
531   curl_easy_setopt (s->client_get, CURLOPT_WRITEDATA, s);
532   curl_easy_setopt (s->client_get, CURLOPT_TIMEOUT_MS,
533                     (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
534   curl_easy_setopt (s->client_get, CURLOPT_PRIVATE, s);
535   curl_easy_setopt (s->client_get, CURLOPT_CONNECTTIMEOUT_MS,
536                     (long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value);
537   curl_easy_setopt (s->client_get, CURLOPT_BUFFERSIZE,
538                     2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
539 #if CURL_TCP_NODELAY
540   curl_easy_setopt (ps->recv_endpoint, CURLOPT_TCP_NODELAY, 1);
541 #endif
542
543   /* create put connection */
544   s->client_put = curl_easy_init ();
545 #if VERBOSE_CURL
546   curl_easy_setopt (s->client_put, CURLOPT_VERBOSE, 1L);
547   curl_easy_setopt (s->client_put, CURLOPT_DEBUGFUNCTION, &client_log);
548   curl_easy_setopt (s->client_put, CURLOPT_DEBUGDATA, s->client_put);
549 #endif
550 #if BUILD_HTTPS
551   curl_easy_setopt (s->client_put, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
552   curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 0);
553   curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 0);
554 #endif
555   curl_easy_setopt (s->client_put, CURLOPT_URL, url);
556   curl_easy_setopt (s->client_put, CURLOPT_PUT, 1L);
557   //curl_easy_setopt (s->client_put, CURLOPT_HEADERFUNCTION, &curl_put_header_cb);
558   //curl_easy_setopt (s->client_put, CURLOPT_WRITEHEADER, ps);
559   curl_easy_setopt (s->client_put, CURLOPT_READFUNCTION, client_send_cb);
560   curl_easy_setopt (s->client_put, CURLOPT_READDATA, s);
561   curl_easy_setopt (s->client_put, CURLOPT_WRITEFUNCTION, client_receive);
562   curl_easy_setopt (s->client_put, CURLOPT_WRITEDATA, s);
563   curl_easy_setopt (s->client_put, CURLOPT_TIMEOUT_MS,
564                     (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
565   curl_easy_setopt (s->client_put, CURLOPT_PRIVATE, s);
566   curl_easy_setopt (s->client_put, CURLOPT_CONNECTTIMEOUT_MS,
567                     (long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value);
568   curl_easy_setopt (s->client_put, CURLOPT_BUFFERSIZE,
569                     2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
570 #if CURL_TCP_NODELAY
571   curl_easy_setopt (s->client_put, CURLOPT_TCP_NODELAY, 1);
572 #endif
573
574   GNUNET_free (url);
575
576   mret = curl_multi_add_handle (plugin->client_mh, s->client_get);
577   if (mret != CURLM_OK)
578   {
579     curl_easy_cleanup (s->client_get);
580     res = GNUNET_SYSERR;
581     GNUNET_break (0);
582   }
583
584   mret = curl_multi_add_handle (plugin->client_mh, s->client_put);
585   if (mret != CURLM_OK)
586   {
587     curl_multi_remove_handle (plugin->client_mh, s->client_get);
588     curl_easy_cleanup (s->client_get);
589     curl_easy_cleanup (s->client_put);
590     res = GNUNET_SYSERR;
591     GNUNET_break (0);
592   }
593
594   /* Perform connect */
595   plugin->cur_connections += 2;
596
597   /* Re-schedule since handles have changed */
598   if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK)
599   {
600     GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
601     plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
602   }
603   plugin->client_perform_task = GNUNET_SCHEDULER_add_now (client_run, plugin);
604
605   return res;
606 }
607
608 int
609 client_start (struct Plugin *plugin)
610 {
611   int res = GNUNET_OK;
612
613   curl_global_init (CURL_GLOBAL_ALL);
614   plugin->client_mh = curl_multi_init ();
615
616   if (NULL == plugin->client_mh)
617   {
618     GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
619                      _
620                      ("Could not initialize curl multi handle, failed to start %s plugin!\n"),
621                      plugin->name);
622     res = GNUNET_SYSERR;
623   }
624   return res;
625 }
626
627 void
628 client_stop (struct Plugin *plugin)
629 {
630   if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK)
631   {
632     GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
633     plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
634   }
635
636   curl_multi_cleanup (plugin->client_mh);
637   curl_global_cleanup ();
638 }
639
640
641
642 /* end of plugin_transport_http_client.c */