eec8939c7b70a2d35556afd84d9c0dfafa155062
[oweals/gnunet.git] / src / transport / plugin_transport_http_server.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.c
23  * @brief http transport service plugin
24  * @author Matthias Wachs
25  */
26
27 #include "plugin_transport_http.h"
28
29 #define HTTP_ERROR_RESPONSE "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD><BODY><H1>Not Found</H1>The requested URL was not found on this server.<P><HR><ADDRESS></ADDRESS></BODY></HTML>"
30 #define _RECEIVE 0
31 #define _SEND 1
32
33 static void
34 server_log (void *arg, const char *fmt, va_list ap)
35 {
36   char text[1024];
37
38   vsnprintf (text, sizeof (text), fmt, ap);
39   va_end (ap);
40   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "server: %s\n", text);
41 }
42
43 /**
44  * Check if incoming connection is accepted.
45  * NOTE: Here every connection is accepted
46  * @param cls plugin as closure
47  * @param addr address of incoming connection
48  * @param addr_len address length of incoming connection
49  * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected
50  *
51  */
52 static int
53 server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len)
54 {
55   struct Plugin * plugin = cls;
56
57   if (plugin->cur_connections <= plugin->max_connections)
58     return MHD_YES;
59   else
60   {
61     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "server: Cannot accept new connections\n");
62     return MHD_NO;
63   }
64 }
65
66
67 /**
68  * Callback called by MHD when it needs data to send
69  * @param cls current session
70  * @param pos position in buffer
71  * @param buf the buffer to write data to
72  * @param max max number of bytes available in buffer
73  * @return bytes written to buffer
74  */
75 #if 0
76 static ssize_t
77 server_send_cb (void *cls, uint64_t pos, char *buf, size_t max)
78 {
79
80   return 0;
81 }
82 #endif
83
84
85 #if BUILD_HTTPS
86 static char *
87 server_load_file (const char *file)
88 {
89   struct GNUNET_DISK_FileHandle *gn_file;
90   struct stat fstat;
91   char *text = NULL;
92
93   if (0 != STAT (file, &fstat))
94     return NULL;
95   text = GNUNET_malloc (fstat.st_size + 1);
96   gn_file =
97       GNUNET_DISK_file_open (file, GNUNET_DISK_OPEN_READ,
98                              GNUNET_DISK_PERM_USER_READ);
99   if (gn_file == NULL)
100   {
101     GNUNET_free (text);
102     return NULL;
103   }
104   if (GNUNET_SYSERR == GNUNET_DISK_file_read (gn_file, text, fstat.st_size))
105   {
106     GNUNET_free (text);
107     GNUNET_DISK_file_close (gn_file);
108     return NULL;
109   }
110   text[fstat.st_size] = '\0';
111   GNUNET_DISK_file_close (gn_file);
112   return text;
113 }
114 #endif
115
116
117 #if BUILD_HTTPS
118
119 static int
120 server_load_certificate (struct Plugin *plugin)
121 {
122   int res = GNUNET_OK;
123
124   char *key_file;
125   char *cert_file;
126
127   /* Get crypto init string from config
128    * If not present just use default values */
129   GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
130                                          "CRYPTO_INIT", &plugin->crypto_init);
131
132   if (GNUNET_OK !=
133       GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name,
134                                                "KEY_FILE", &key_file))
135   {
136     key_file = "https_key.key";
137   }
138
139   if (GNUNET_OK !=
140       GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name,
141                                                "CERT_FILE", &cert_file))
142   {
143     cert_file = "https_cert.crt";
144   }
145
146   /* read key & certificates from file */
147 #if VERBOSE_SERVER
148   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
149               "Loading TLS certificate from key-file `%s' cert-file`%s'\n",
150               key_file, cert_file);
151 #endif
152
153   plugin->key = server_load_file (key_file);
154   plugin->cert = server_load_file (cert_file);
155
156   if ((plugin->key == NULL) || (plugin->cert == NULL))
157   {
158     struct GNUNET_OS_Process *cert_creation;
159
160     GNUNET_free_non_null (plugin->key);
161     plugin->key = NULL;
162     GNUNET_free_non_null (plugin->cert);
163     plugin->cert = NULL;
164
165 #if VERBOSE_SERVER
166     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
167                 "No usable TLS certificate found, creating certificate\n");
168 #endif
169     errno = 0;
170     cert_creation =
171         GNUNET_OS_start_process (NULL, NULL,
172                                  "gnunet-transport-certificate-creation",
173                                  "gnunet-transport-certificate-creation",
174                                  key_file, cert_file, NULL);
175     if (cert_creation == NULL)
176     {
177       GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
178                        _
179                        ("Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n"));
180       GNUNET_free (key_file);
181       GNUNET_free (cert_file);
182
183       GNUNET_free_non_null (plugin->key);
184       GNUNET_free_non_null (plugin->cert);
185       GNUNET_free_non_null (plugin->crypto_init);
186
187       return GNUNET_SYSERR;
188     }
189     GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (cert_creation));
190     GNUNET_OS_process_close (cert_creation);
191
192     plugin->key = server_load_file (key_file);
193     plugin->cert = server_load_file (cert_file);
194   }
195
196   if ((plugin->key == NULL) || (plugin->cert == NULL))
197   {
198     GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
199                      _
200                      ("No usable TLS certificate found and creating one failed!\n"),
201                      "transport-https");
202     GNUNET_free (key_file);
203     GNUNET_free (cert_file);
204
205     GNUNET_free_non_null (plugin->key);
206     GNUNET_free_non_null (plugin->cert);
207     GNUNET_free_non_null (plugin->crypto_init);
208
209     return GNUNET_SYSERR;
210   }
211   GNUNET_free (key_file);
212   GNUNET_free (cert_file);
213 #if DEBUG_HTTP
214   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TLS certificate loaded\n");
215 #endif
216
217   return res;
218 }
219 #endif
220
221
222 /**
223  * Process GET or PUT request received via MHD.  For
224  * GET, queue response that will send back our pending
225  * messages.  For PUT, process incoming data and send
226  * to GNUnet core.  In either case, check if a session
227  * already exists and create a new one if not.
228  */
229 static int
230 server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
231                   const char *url, const char *method, const char *version,
232                   const char *upload_data, size_t * upload_data_size,
233                   void **httpSessionCache)
234 {
235   struct Plugin *plugin = cls;
236   struct Session *s = *httpSessionCache;
237   int res = MHD_YES;
238   struct MHD_Response *response;
239
240   GNUNET_assert (cls != NULL);
241   /* new connection */
242   if (s == NULL)
243   {
244
245     uint32_t tag;
246     const union MHD_ConnectionInfo *conn_info;
247     size_t addrlen;
248     struct GNUNET_PeerIdentity target;
249     int check = GNUNET_NO;
250     struct Session * t;
251     int direction;
252
253     conn_info = MHD_get_connection_info (mhd_connection, MHD_CONNECTION_INFO_CLIENT_ADDRESS);
254     if (conn_info->client_addr->sa_family == AF_INET)
255       addrlen = sizeof (struct sockaddr_in);
256     else if (conn_info->client_addr->sa_family == AF_INET6)
257       addrlen = sizeof (struct sockaddr_in6);
258     else
259       return MHD_NO;
260
261     if ((strlen(&url[1]) >= 105)  && (url[104] == ';'))
262     {
263       char hash[104];
264       char * tagc = (char *) &url[105];
265       memcpy(&hash, &url[1], 103);
266       hash [103] = '\0';
267       if (GNUNET_OK == GNUNET_CRYPTO_hash_from_string ((const char *) &hash, &(target.hashPubKey)))
268       {
269         tag = strtoul (tagc, NULL, 10);
270         if (tagc > 0)
271           check = GNUNET_YES;
272       }
273     }
274
275     if (0 == strcmp (MHD_HTTP_METHOD_PUT, method))
276       direction = _RECEIVE;
277     if (0 == strcmp (MHD_HTTP_METHOD_GET, method))
278       direction = _SEND;
279
280     if (check == GNUNET_NO)
281       goto error;
282 #if VERBOSE_SERVER
283     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: New inbound connection from %s with tag %u\n", GNUNET_h2s_full(&(target.hashPubKey)), tag);
284 #endif
285     /* find duplicate session */
286
287     t = plugin->head;
288
289     while (t != NULL)
290     {
291       if ((t->inbound) && (0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity))) &&
292           /* FIXME add source address comparison */
293           (t->tag == tag))
294       break;
295       t = t->next;
296     }
297     if (t != NULL)
298     {
299 #if VERBOSE_SERVER
300       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Duplicate session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target));
301 #endif
302       goto error;
303     }
304
305     /* find semi-session */
306     t = plugin->server_semi_head;
307
308     while (t != NULL)
309     {
310       /* FIXME add source address comparison */
311       if ((0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity))) &&
312           (t->tag == tag))
313       {
314         break;
315       }
316       t = t->next;
317     }
318
319     if (t == NULL)
320       goto create;
321
322     if ((direction == _SEND) && (t->server_get != NULL))
323     {
324 #if VERBOSE_SERVER
325       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Duplicate GET session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target));
326 #endif
327       goto error;
328     }
329     else
330     {
331       s = t;
332       s->server_get = s;
333       GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s);
334       GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s);
335 #if VERBOSE_SERVER
336       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target));
337 #endif
338
339       goto found;
340     }
341     if ((direction == _RECEIVE) && (t->server_put != NULL))
342     {
343 #if VERBOSE_SERVER
344       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Duplicate PUT session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target));
345 #endif
346       goto error;
347     }
348     else
349     {
350       s = t;
351       s->server_put = s;
352       GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s);
353       GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s);
354 #if VERBOSE_SERVER
355       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target));
356 #endif
357       goto found;
358     }
359
360 create:
361 /* create new session */
362 #if VERBOSE_SERVER
363       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Creating new session for peer `%s' \n", GNUNET_i2s (&target));
364 #endif
365
366     s = create_session(plugin,
367                         &target,
368                         conn_info->client_addr,
369                         addrlen,
370                         NULL,
371                         NULL);
372
373     s->inbound = GNUNET_YES;
374     s->tag= tag;
375     if (0 == strcmp (MHD_HTTP_METHOD_PUT, method))
376       s->server_put = s;
377     if (0 == strcmp (MHD_HTTP_METHOD_GET, method))
378       s->server_get = s;
379     GNUNET_CONTAINER_DLL_insert (plugin->server_semi_head, plugin->server_semi_tail, s);
380
381     goto found;
382 error:
383         GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "server: Invalid connection request\n");
384         response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO);
385         res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response);
386         MHD_destroy_response (response);
387         return res;
388
389
390 found:
391     (*httpSessionCache) = s;
392     return MHD_YES;
393
394   }
395
396
397   return res;
398 }
399
400 static void
401 server_disconnect_cb (void *cls, struct MHD_Connection *connection,
402                       void **httpSessionCache)
403 {
404   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "server: server_disconnect_cb\n");
405   /*
406   struct Session *s = *httpSessionCache;
407
408   if (s != NULL)
409   {
410     notify_session_end(s->plugin, &s->target, s);
411   }
412 */
413 }
414
415 int
416 server_disconnect (struct Session *s)
417 {
418   return GNUNET_OK;
419 }
420
421 int
422 server_send (struct Session *s, const char *msgbuf, size_t msgbuf_size)
423 {
424   return GNUNET_OK;
425 }
426
427 /**
428  * Function that queries MHD's select sets and
429  * starts the task waiting for them.
430  * @param plugin plugin
431  * @param daemon_handle the MHD daemon handle
432  * @return gnunet task identifier
433  */
434 static GNUNET_SCHEDULER_TaskIdentifier
435 server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle);
436
437 /**
438  * Call MHD IPv4 to process pending requests and then go back
439  * and schedule the next run.
440  * @param cls plugin as closure
441  * @param tc task context
442  */
443 static void
444 server_v4_run (void *cls,
445                            const struct GNUNET_SCHEDULER_TaskContext *tc)
446 {
447   struct Plugin *plugin = cls;
448   GNUNET_assert (cls != NULL);
449
450   plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
451
452   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
453     return;
454
455   GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4));
456   plugin->server_v4_task = server_schedule (plugin, plugin->server_v4);
457 }
458
459
460 /**
461  * Call MHD IPv6 to process pending requests and then go back
462  * and schedule the next run.
463  * @param cls plugin as closure
464  * @param tc task context
465  */
466 static void
467 server_v6_run (void *cls,
468                            const struct GNUNET_SCHEDULER_TaskContext *tc)
469 {
470   struct Plugin *plugin = cls;
471   GNUNET_assert (cls != NULL);
472
473   plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
474
475   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
476     return;
477
478   GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6));
479   plugin->server_v6_task = server_schedule (plugin, plugin->server_v6);
480 }
481
482 /**
483  * Function that queries MHD's select sets and
484  * starts the task waiting for them.
485  * @param plugin plugin
486  * @param daemon_handle the MHD daemon handle
487  * @return gnunet task identifier
488  */
489 static GNUNET_SCHEDULER_TaskIdentifier
490 server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle)
491 {
492   GNUNET_SCHEDULER_TaskIdentifier ret;
493   fd_set rs;
494   fd_set ws;
495   fd_set es;
496   struct GNUNET_NETWORK_FDSet *wrs;
497   struct GNUNET_NETWORK_FDSet *wws;
498   struct GNUNET_NETWORK_FDSet *wes;
499   int max;
500   unsigned long long timeout;
501   int haveto;
502   struct GNUNET_TIME_Relative tv;
503
504   ret = GNUNET_SCHEDULER_NO_TASK;
505   FD_ZERO (&rs);
506   FD_ZERO (&ws);
507   FD_ZERO (&es);
508   wrs = GNUNET_NETWORK_fdset_create ();
509   wes = GNUNET_NETWORK_fdset_create ();
510   wws = GNUNET_NETWORK_fdset_create ();
511   max = -1;
512   GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
513   haveto = MHD_get_timeout (daemon_handle, &timeout);
514   if (haveto == MHD_YES)
515     tv.rel_value = (uint64_t) timeout;
516   else
517     tv = GNUNET_TIME_UNIT_SECONDS;
518   GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
519   GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
520   GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1);
521   if (daemon_handle == plugin->server_v4)
522   {
523     if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK)
524     {
525       GNUNET_SCHEDULER_cancel (plugin->server_v4_task);
526       plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
527     }
528
529     ret =
530         GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
531                                      GNUNET_SCHEDULER_NO_TASK, tv, wrs, wws,
532                                      &server_v4_run, plugin);
533   }
534   if (daemon_handle == plugin->server_v6)
535   {
536     if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK)
537     {
538       GNUNET_SCHEDULER_cancel (plugin->server_v6_task);
539       plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
540     }
541
542     ret =
543         GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
544                                      GNUNET_SCHEDULER_NO_TASK, tv, wrs, wws,
545                                      &server_v6_run, plugin);
546   }
547   GNUNET_NETWORK_fdset_destroy (wrs);
548   GNUNET_NETWORK_fdset_destroy (wws);
549   GNUNET_NETWORK_fdset_destroy (wes);
550   return ret;
551 }
552
553 int
554 server_start (struct Plugin *plugin)
555 {
556   int res = GNUNET_OK;
557
558 #if BUILD_HTTPS
559   res = server_load_certificate (plugin);
560   if (res == GNUNET_SYSERR)
561   {
562     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TABORT\n");
563     return res;
564   }
565 #endif
566
567   plugin->server_v4 = NULL;
568   if (plugin->ipv4 == GNUNET_YES)
569   {
570     plugin->server_v4 = MHD_start_daemon (
571 #if VERBOSE_SERVER
572                                            MHD_USE_DEBUG |
573 #endif
574 #if BUILD_HTTPS
575                                            MHD_USE_SSL |
576 #endif
577                                            MHD_NO_FLAG, plugin->port,
578                                            &server_accept_cb, plugin,
579                                            &server_access_cb, plugin,
580                                            //MHD_OPTION_SOCK_ADDR,
581                                            //(struct sockaddr_in *)
582                                            //plugin->bind4_address,
583                                            MHD_OPTION_CONNECTION_LIMIT,
584                                            (unsigned int)
585                                            plugin->max_connections,
586 #if BUILD_HTTPS
587                                            MHD_OPTION_HTTPS_PRIORITIES,
588                                            plugin->crypto_init,
589                                            MHD_OPTION_HTTPS_MEM_KEY,
590                                            plugin->key,
591                                            MHD_OPTION_HTTPS_MEM_CERT,
592                                            plugin->cert,
593 #endif
594                                            MHD_OPTION_CONNECTION_TIMEOUT,
595                                            (unsigned int) 3,
596                                            MHD_OPTION_CONNECTION_MEMORY_LIMIT,
597                                            (size_t) (2 *
598                                                      GNUNET_SERVER_MAX_MESSAGE_SIZE),
599                                            MHD_OPTION_NOTIFY_COMPLETED,
600                                            &server_disconnect_cb, plugin,
601                                            MHD_OPTION_EXTERNAL_LOGGER,
602                                            server_log, NULL, MHD_OPTION_END);
603     if (plugin->server_v4 == NULL)
604       res = GNUNET_SYSERR;
605   }
606   plugin->server_v6 = NULL;
607   if (plugin->ipv6 == GNUNET_YES)
608   {
609     plugin->server_v6 = MHD_start_daemon (
610 #if VERBOSE_SERVER
611                                            MHD_USE_DEBUG |
612 #endif
613 #if BUILD_HTTPS
614                                            MHD_USE_SSL |
615 #endif
616                                            MHD_USE_IPv6, plugin->port,
617                                            &server_accept_cb, plugin,
618                                            &server_access_cb, plugin,
619                                            //MHD_OPTION_SOCK_ADDR,
620                                            //tmp,
621                                            MHD_OPTION_CONNECTION_LIMIT,
622                                            (unsigned int)
623                                            plugin->max_connections,
624 #if BUILD_HTTPS
625                                            MHD_OPTION_HTTPS_PRIORITIES,
626                                            plugin->crypto_init,
627                                            MHD_OPTION_HTTPS_MEM_KEY,
628                                            plugin->key,
629                                            MHD_OPTION_HTTPS_MEM_CERT,
630                                            plugin->cert,
631 #endif
632                                            MHD_OPTION_CONNECTION_TIMEOUT,
633                                            (unsigned int) 3,
634                                            MHD_OPTION_CONNECTION_MEMORY_LIMIT,
635                                            (size_t) (2 *
636                                                      GNUNET_SERVER_MAX_MESSAGE_SIZE),
637                                            MHD_OPTION_NOTIFY_COMPLETED,
638                                            &server_disconnect_cb, plugin,
639                                            MHD_OPTION_EXTERNAL_LOGGER,
640                                            server_log, NULL, MHD_OPTION_END);
641
642     if (plugin->server_v6 == NULL)
643       res = GNUNET_SYSERR;
644   }
645
646   if (plugin->server_v4 != NULL)
647     plugin->server_v4_task = server_schedule (plugin, plugin->server_v4);
648   if (plugin->server_v6 != NULL)
649     plugin->server_v6_task = server_schedule (plugin, plugin->server_v6);
650
651 #if DEBUG_HTTP
652   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
653                    "%s server component started on port %u\n", plugin->name,
654                    plugin->port);
655 #endif
656   return res;
657 }
658
659 void
660 server_stop (struct Plugin *plugin)
661 {
662   if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK)
663   {
664     GNUNET_SCHEDULER_cancel (plugin->server_v4_task);
665     plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
666   }
667
668   if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK)
669   {
670     GNUNET_SCHEDULER_cancel (plugin->server_v6_task);
671     plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
672   }
673
674   if (plugin->server_v4 != NULL)
675   {
676     MHD_stop_daemon (plugin->server_v4);
677     plugin->server_v4 = NULL;
678   }
679   if (plugin->server_v6 != NULL)
680   {
681     MHD_stop_daemon (plugin->server_v6);
682     plugin->server_v6 = NULL;
683   }
684
685 #if BUILD_HTTPS
686   GNUNET_free_non_null (plugin->crypto_init);
687   GNUNET_free_non_null (plugin->cert);
688   GNUNET_free_non_null (plugin->key);
689 #endif
690
691 #if DEBUG_HTTP
692   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
693                    "%s server component stopped\n", plugin->name);
694 #endif
695 }
696
697
698
699 /* end of plugin_transport_http.c */