server side connection accepting and merging
[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 #if 0
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' `%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' `%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 #endif
395   }
396
397
398   return res;
399 }
400
401 static void
402 server_disconnect_cb (void *cls, struct MHD_Connection *connection,
403                       void **httpSessionCache)
404 {
405   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "server: server_disconnect_cb\n");
406   /*
407   struct Session *s = *httpSessionCache;
408
409   if (s != NULL)
410   {
411     notify_session_end(s->plugin, &s->target, s);
412   }
413 */
414 }
415
416 int
417 server_disconnect (struct Session *s)
418 {
419   return GNUNET_OK;
420 }
421
422 int
423 server_send (struct Session *s, const char *msgbuf, size_t msgbuf_size)
424 {
425   return GNUNET_OK;
426 }
427
428 /**
429  * Function that queries MHD's select sets and
430  * starts the task waiting for them.
431  * @param plugin plugin
432  * @param daemon_handle the MHD daemon handle
433  * @return gnunet task identifier
434  */
435 static GNUNET_SCHEDULER_TaskIdentifier
436 server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle);
437
438 /**
439  * Call MHD IPv4 to process pending requests and then go back
440  * and schedule the next run.
441  * @param cls plugin as closure
442  * @param tc task context
443  */
444 static void
445 server_v4_run (void *cls,
446                            const struct GNUNET_SCHEDULER_TaskContext *tc)
447 {
448   struct Plugin *plugin = cls;
449   GNUNET_assert (cls != NULL);
450
451   plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
452
453   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
454     return;
455
456   GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4));
457   plugin->server_v4_task = server_schedule (plugin, plugin->server_v4);
458 }
459
460
461 /**
462  * Call MHD IPv6 to process pending requests and then go back
463  * and schedule the next run.
464  * @param cls plugin as closure
465  * @param tc task context
466  */
467 static void
468 server_v6_run (void *cls,
469                            const struct GNUNET_SCHEDULER_TaskContext *tc)
470 {
471   struct Plugin *plugin = cls;
472   GNUNET_assert (cls != NULL);
473
474   plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
475
476   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
477     return;
478
479   GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6));
480   plugin->server_v6_task = server_schedule (plugin, plugin->server_v6);
481 }
482
483 /**
484  * Function that queries MHD's select sets and
485  * starts the task waiting for them.
486  * @param plugin plugin
487  * @param daemon_handle the MHD daemon handle
488  * @return gnunet task identifier
489  */
490 static GNUNET_SCHEDULER_TaskIdentifier
491 server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle)
492 {
493   GNUNET_SCHEDULER_TaskIdentifier ret;
494   fd_set rs;
495   fd_set ws;
496   fd_set es;
497   struct GNUNET_NETWORK_FDSet *wrs;
498   struct GNUNET_NETWORK_FDSet *wws;
499   struct GNUNET_NETWORK_FDSet *wes;
500   int max;
501   unsigned long long timeout;
502   int haveto;
503   struct GNUNET_TIME_Relative tv;
504
505   ret = GNUNET_SCHEDULER_NO_TASK;
506   FD_ZERO (&rs);
507   FD_ZERO (&ws);
508   FD_ZERO (&es);
509   wrs = GNUNET_NETWORK_fdset_create ();
510   wes = GNUNET_NETWORK_fdset_create ();
511   wws = GNUNET_NETWORK_fdset_create ();
512   max = -1;
513   GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
514   haveto = MHD_get_timeout (daemon_handle, &timeout);
515   if (haveto == MHD_YES)
516     tv.rel_value = (uint64_t) timeout;
517   else
518     tv = GNUNET_TIME_UNIT_SECONDS;
519   GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
520   GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
521   GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1);
522   if (daemon_handle == plugin->server_v4)
523   {
524     if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK)
525     {
526       GNUNET_SCHEDULER_cancel (plugin->server_v4_task);
527       plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
528     }
529
530     ret =
531         GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
532                                      GNUNET_SCHEDULER_NO_TASK, tv, wrs, wws,
533                                      &server_v4_run, plugin);
534   }
535   if (daemon_handle == plugin->server_v6)
536   {
537     if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK)
538     {
539       GNUNET_SCHEDULER_cancel (plugin->server_v6_task);
540       plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
541     }
542
543     ret =
544         GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
545                                      GNUNET_SCHEDULER_NO_TASK, tv, wrs, wws,
546                                      &server_v6_run, plugin);
547   }
548   GNUNET_NETWORK_fdset_destroy (wrs);
549   GNUNET_NETWORK_fdset_destroy (wws);
550   GNUNET_NETWORK_fdset_destroy (wes);
551   return ret;
552 }
553
554 int
555 server_start (struct Plugin *plugin)
556 {
557   int res = GNUNET_OK;
558
559 #if BUILD_HTTPS
560   res = server_load_certificate (plugin);
561   if (res == GNUNET_SYSERR)
562   {
563     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TABORT\n");
564     return res;
565   }
566 #endif
567
568   plugin->server_v4 = NULL;
569   if (plugin->ipv4 == GNUNET_YES)
570   {
571     plugin->server_v4 = MHD_start_daemon (
572 #if VERBOSE_SERVER
573                                            MHD_USE_DEBUG |
574 #endif
575 #if BUILD_HTTPS
576                                            MHD_USE_SSL |
577 #endif
578                                            MHD_NO_FLAG, plugin->port,
579                                            &server_accept_cb, plugin,
580                                            &server_access_cb, plugin,
581                                            //MHD_OPTION_SOCK_ADDR,
582                                            //(struct sockaddr_in *)
583                                            //plugin->bind4_address,
584                                            MHD_OPTION_CONNECTION_LIMIT,
585                                            (unsigned int)
586                                            plugin->max_connections,
587 #if BUILD_HTTPS
588                                            MHD_OPTION_HTTPS_PRIORITIES,
589                                            plugin->crypto_init,
590                                            MHD_OPTION_HTTPS_MEM_KEY,
591                                            plugin->key,
592                                            MHD_OPTION_HTTPS_MEM_CERT,
593                                            plugin->cert,
594 #endif
595                                            MHD_OPTION_CONNECTION_TIMEOUT,
596                                            (unsigned int) 3,
597                                            MHD_OPTION_CONNECTION_MEMORY_LIMIT,
598                                            (size_t) (2 *
599                                                      GNUNET_SERVER_MAX_MESSAGE_SIZE),
600                                            MHD_OPTION_NOTIFY_COMPLETED,
601                                            &server_disconnect_cb, plugin,
602                                            MHD_OPTION_EXTERNAL_LOGGER,
603                                            server_log, NULL, MHD_OPTION_END);
604     if (plugin->server_v4 == NULL)
605       res = GNUNET_SYSERR;
606   }
607   plugin->server_v6 = NULL;
608   if (plugin->ipv6 == GNUNET_YES)
609   {
610     plugin->server_v6 = MHD_start_daemon (
611 #if VERBOSE_SERVER
612                                            MHD_USE_DEBUG |
613 #endif
614 #if BUILD_HTTPS
615                                            MHD_USE_SSL |
616 #endif
617                                            MHD_USE_IPv6, plugin->port,
618                                            &server_accept_cb, plugin,
619                                            &server_access_cb, plugin,
620                                            //MHD_OPTION_SOCK_ADDR,
621                                            //tmp,
622                                            MHD_OPTION_CONNECTION_LIMIT,
623                                            (unsigned int)
624                                            plugin->max_connections,
625 #if BUILD_HTTPS
626                                            MHD_OPTION_HTTPS_PRIORITIES,
627                                            plugin->crypto_init,
628                                            MHD_OPTION_HTTPS_MEM_KEY,
629                                            plugin->key,
630                                            MHD_OPTION_HTTPS_MEM_CERT,
631                                            plugin->cert,
632 #endif
633                                            MHD_OPTION_CONNECTION_TIMEOUT,
634                                            (unsigned int) 3,
635                                            MHD_OPTION_CONNECTION_MEMORY_LIMIT,
636                                            (size_t) (2 *
637                                                      GNUNET_SERVER_MAX_MESSAGE_SIZE),
638                                            MHD_OPTION_NOTIFY_COMPLETED,
639                                            &server_disconnect_cb, plugin,
640                                            MHD_OPTION_EXTERNAL_LOGGER,
641                                            server_log, NULL, MHD_OPTION_END);
642
643     if (plugin->server_v6 == NULL)
644       res = GNUNET_SYSERR;
645   }
646
647   if (plugin->server_v4 != NULL)
648     plugin->server_v4_task = server_schedule (plugin, plugin->server_v4);
649   if (plugin->server_v6 != NULL)
650     plugin->server_v6_task = server_schedule (plugin, plugin->server_v6);
651
652 #if DEBUG_HTTP
653   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
654                    "%s server component started on port %u\n", plugin->name,
655                    plugin->port);
656 #endif
657   return res;
658 }
659
660 void
661 server_stop (struct Plugin *plugin)
662 {
663   if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK)
664   {
665     GNUNET_SCHEDULER_cancel (plugin->server_v4_task);
666     plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
667   }
668
669   if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK)
670   {
671     GNUNET_SCHEDULER_cancel (plugin->server_v6_task);
672     plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
673   }
674
675   if (plugin->server_v4 != NULL)
676   {
677     MHD_stop_daemon (plugin->server_v4);
678     plugin->server_v4 = NULL;
679   }
680   if (plugin->server_v6 != NULL)
681   {
682     MHD_stop_daemon (plugin->server_v6);
683     plugin->server_v6 = NULL;
684   }
685
686 #if BUILD_HTTPS
687   GNUNET_free_non_null (plugin->crypto_init);
688   GNUNET_free_non_null (plugin->cert);
689   GNUNET_free_non_null (plugin->key);
690 #endif
691
692 #if DEBUG_HTTP
693   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
694                    "%s server component stopped\n", plugin->name);
695 #endif
696 }
697
698
699
700 /* end of plugin_transport_http.c */