indentation
[oweals/gnunet.git] / src / transport / test_plugin_transport_http.c
1 /*
2      This file is part of GNUnet.
3      (C) 2010 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  * @file transport/test_plugin_transport_http.c
22  * @brief testcase for plugin_transport_http.c
23  * @author Matthias Wachs
24  */
25
26 #include "platform.h"
27 #include "gnunet_constants.h"
28 #include "gnunet_common.h"
29 #include "gnunet_getopt_lib.h"
30 #include "gnunet_hello_lib.h"
31 #include "gnunet_os_lib.h"
32 #include "gnunet_peerinfo_service.h"
33 #include "gnunet_plugin_lib.h"
34 #include "gnunet_protocols.h"
35 #include "gnunet_program_lib.h"
36 #include "gnunet_signatures.h"
37 #include "gnunet_service_lib.h"
38 #include "gnunet_crypto_lib.h"
39
40 #include "gnunet_transport_plugin.h"
41 #include "gnunet_statistics_service.h"
42 #include "transport.h"
43 #include <curl/curl.h>
44
45 #define VERBOSE GNUNET_NO
46 #define DEBUG_CURL GNUNET_NO
47 #define HTTP_BUFFER_SIZE 2048
48
49 #define PROTOCOL_PREFIX "http"
50
51 #define PLUGIN libgnunet_plugin_transport_template
52
53 /**
54  * How long until we give up on transmitting the message?
55  */
56 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
57
58 /**
59  * Testcase timeout
60  */
61 #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
62
63 /**
64  * How long between recieve and send?
65  */
66 #define WAIT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
67
68
69
70 /**
71  *  Struct for plugin addresses
72  */
73 struct Plugin_Address
74 {
75   /**
76    * Next field for linked list
77    */
78   struct Plugin_Address *next;
79
80   /**
81    * buffer containing data to send
82    */
83   void *addr;
84
85   /**
86    * amount of data to sent
87    */
88   size_t addrlen;
89 };
90
91 /**
92  *  Message to send using http
93  */
94 struct HTTP_Message
95 {
96   /**
97    * buffer
98    */
99   unsigned char buf[HTTP_BUFFER_SIZE];
100
101   /**
102    * current position in buffer
103    */
104   size_t pos;
105
106   /**
107    * buffer size
108    */
109   size_t size;
110
111   /**
112    * data size
113    */
114   size_t len;
115 };
116
117
118 /**
119  *  Struct for plugin addresses
120  */
121 struct HTTP_Transfer
122 {
123   /**
124    * amount of bytes we recieved
125    */
126   size_t data_size;
127
128   /**
129    * buffer for http transfers
130    */
131   unsigned char buf[HTTP_BUFFER_SIZE];
132
133   /**
134    * buffer size this transfer
135    */
136   size_t size;
137
138   /**
139    * amount of bytes we recieved
140    */
141   size_t pos;
142
143   /**
144    * HTTP Header result for transfer
145    */
146   unsigned int http_result_code;
147
148   /**
149    * did the test fail?
150    */
151   unsigned int test_failed;
152
153   /**
154    * was this test already executed?
155    */
156   unsigned int test_executed;
157 };
158
159
160 /**
161  * Network format for IPv4 addresses.
162  */
163 struct IPv4HttpAddress
164 {
165   struct IPv4HttpAddress *next;
166
167   struct IPv4HttpAddress *prev;
168
169   /**
170    * IPv4 address, in network byte order.
171    */
172   uint32_t ipv4_addr GNUNET_PACKED;
173
174   /**
175    * Port number, in network byte order.
176    */
177   uint16_t u_port GNUNET_PACKED;
178
179 };
180
181
182 /**
183  * Network format for IPv6 addresses.
184  */
185 struct IPv6HttpAddress
186 {
187   struct IPv6HttpAddress *next;
188
189   struct IPv6HttpAddress *prev;
190
191   /**
192    * IPv6 address.
193    */
194   struct in6_addr ipv6_addr GNUNET_PACKED;
195
196   /**
197    * Port number, in network byte order.
198    */
199   uint16_t u6_port GNUNET_PACKED;
200
201 };
202
203
204 /**
205  * Our public key.
206  */
207 /* static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; */
208
209 /**
210  * Our public key.
211  */
212 static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
213
214 /**
215  * Our identity.
216  */
217 static struct GNUNET_PeerIdentity my_identity;
218
219 /**
220  * Our private key.
221  */
222 static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
223
224 /**
225  * Peer's port
226  */
227 static long long unsigned int port;
228
229 /**
230  * Peer's addr
231  */
232 static char *test_addr;
233
234 /**
235  * Our statistics handle.
236  */
237 struct GNUNET_STATISTICS_Handle *stats;
238
239
240 /**
241  * Our configuration.
242  */
243 const struct GNUNET_CONFIGURATION_Handle *cfg;
244
245 /**
246  * Number of neighbours we'd like to have.
247  */
248 static uint32_t max_connect_per_transport;
249
250 /**
251  * Environment for this plugin.
252  */
253 static struct GNUNET_TRANSPORT_PluginEnvironment env;
254
255 /**
256  *handle for the api provided by this plugin
257  */
258 static struct GNUNET_TRANSPORT_PluginFunctions *api;
259
260 /**
261  * ID of the task controlling the testcase timeout
262  */
263 static GNUNET_SCHEDULER_TaskIdentifier ti_timeout;
264
265 static GNUNET_SCHEDULER_TaskIdentifier ti_send;
266
267 //const struct GNUNET_PeerIdentity * p;
268
269 /**
270  * buffer for data to send
271  */
272 static struct HTTP_Message buffer_out;
273
274 /**
275  * buffer for data to recieve
276  */
277 static struct HTTP_Message buffer_in;
278
279
280 struct Plugin_Address *addr_head;
281
282 /**
283  * Did the test pass or fail?
284  */
285 static int fail_notify_address;
286
287 /**
288  * Did the test pass or fail?
289  */
290 static int fail_notify_address_count;
291
292 /**
293  * Did the test pass or fail?
294  */
295 static int fail_pretty_printer;
296
297 /**
298  * Did the test pass or fail?
299  */
300 static int fail_pretty_printer_count;
301
302 /**
303  * Did the test pass or fail?
304  */
305 static int fail_addr_to_str;
306
307 /**
308  * No. of msgs transmitted successfully to local addresses
309  */
310 static int fail_msgs_transmited_to_local_addrs;
311
312 /**
313  * Test: transmit msg of max. size
314  */
315 static int fail_msg_transmited_bigger_max_size;
316
317 /**
318  * Test: transmit msg of max. size
319  */
320 static int fail_msg_transmited_max_size;
321
322 /**
323  * Test: transmit 2 msgs. in in send operation
324  */
325 static int fail_multiple_msgs_in_transmission;
326
327 /**
328  * Test: connect to peer without peer identification
329  */
330 static struct HTTP_Transfer test_no_ident;
331
332 /**
333  * Test: connect to peer without peer identification
334  */
335 static struct HTTP_Transfer test_too_short_ident;
336
337 /**
338  * Test: connect to peer without peer identification
339  */
340 static struct HTTP_Transfer test_too_long_ident;
341
342 /**
343  * Test: connect to peer with valid peer identification
344  */
345 static struct HTTP_Transfer test_valid_ident;
346
347 /**
348  * Test: session selection, use any existing
349  */
350 static int fail_session_selection_any;
351
352 /**
353  * Test: session selection, use existing inbound session
354  */
355 static int fail_session_selection_session;
356
357 /**
358  * Test: session selection, use existing inbound session
359  * max message, not fitting in send & recv buffers at one time
360  */
361 static int fail_session_selection_session_big;
362
363 /**
364 * Test: session selection, use reliable existing
365  */
366 static int fail_session_selection_reliable;
367
368 /**
369  * Did the test pass or fail?
370  */
371 static int fail;
372
373 /**
374  * Number of local addresses
375  */
376 static unsigned int count_str_addr;
377
378 CURL *curl_handle;
379
380 /**
381  * cURL Multihandle
382  */
383 static CURLM *multi_handle;
384
385 /**
386  * The task sending data
387  */
388 static GNUNET_SCHEDULER_TaskIdentifier http_task_send;
389
390 static char *servicehome;
391
392 /**
393  * Shutdown testcase
394  */
395 static void
396 shutdown_clean ()
397 {
398   struct Plugin_Address *tmp;
399
400   /* Evaluate results  */
401   fail = 0;
402   if ((fail_notify_address == GNUNET_YES) ||
403       (fail_pretty_printer == GNUNET_YES) || (fail_addr_to_str == GNUNET_YES))
404   {
405     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
406                 "Phase 0: Test plugin functions failed\n");
407     fail = 1;
408   }
409   if ((test_no_ident.test_failed == GNUNET_YES) ||
410       (test_too_short_ident.test_failed == GNUNET_YES) ||
411       (test_too_long_ident.test_failed == GNUNET_YES) ||
412       (test_valid_ident.test_failed == GNUNET_YES))
413   {
414     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
415                 "Phase 1: Test connect with wrong data failed\n");
416     fail = 1;
417   }
418   if ((fail_session_selection_any != GNUNET_NO) ||
419       (fail_session_selection_reliable != GNUNET_NO) ||
420       (fail_session_selection_session != GNUNET_NO) ||
421       (fail_session_selection_session_big != GNUNET_NO))
422   {
423     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
424                 "Phase 2: Test session selection failed\n");
425     fail = 1;
426   }
427   if ((fail_msgs_transmited_to_local_addrs != count_str_addr) ||
428       (fail_multiple_msgs_in_transmission != 2) ||
429       (fail_msg_transmited_max_size == GNUNET_YES))
430   {
431     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
432                 "Phase 3: Test sending with plugin failed\n");
433     fail = 1;
434   }
435   if (fail != 1)
436   {
437     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All tests successful\n");
438   }
439
440   api->disconnect (api->cls, &my_identity);
441
442   curl_multi_cleanup (multi_handle);
443
444   if (NULL != curl_handle)
445     curl_easy_cleanup (curl_handle);
446
447   /* cleaning addresses */
448   while (addr_head != NULL)
449   {
450     tmp = addr_head->next;
451     GNUNET_free (addr_head->addr);
452     GNUNET_free (addr_head);
453     addr_head = tmp;
454   }
455
456   if (ti_send != GNUNET_SCHEDULER_NO_TASK)
457   {
458     GNUNET_SCHEDULER_cancel (ti_send);
459     ti_send = GNUNET_SCHEDULER_NO_TASK;
460   }
461
462   if (http_task_send != GNUNET_SCHEDULER_NO_TASK)
463   {
464     GNUNET_SCHEDULER_cancel (http_task_send);
465     http_task_send = GNUNET_SCHEDULER_NO_TASK;
466   }
467
468   if (ti_timeout != GNUNET_SCHEDULER_NO_TASK)
469   {
470     GNUNET_SCHEDULER_cancel (ti_timeout);
471     ti_timeout = GNUNET_SCHEDULER_NO_TASK;
472   }
473
474   GNUNET_free (test_addr);
475   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading http plugin\n");
476   GNUNET_assert (NULL ==
477                  GNUNET_PLUGIN_unload ("libgnunet_gnunet_transport_plugin_http",
478                                        api));
479
480   GNUNET_SCHEDULER_shutdown ();
481   GNUNET_DISK_directory_remove ("/tmp/test_gnunet_transport_plugin_http");
482
483   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting testcase\n");
484
485   if (servicehome != NULL)
486   {
487     GNUNET_DISK_directory_remove (servicehome);
488     GNUNET_free (servicehome);
489   }
490
491   exit (fail);
492   return;
493 }
494
495
496 /**
497  * Continuation called after plugin send message
498  * @cls closure
499  * @target target
500  * @result GNUNET_OK or GNUNET_SYSERR
501  */
502
503 static void
504 task_send_cont (void *cls, const struct GNUNET_PeerIdentity *target, int result)
505 {
506   if ((cls == &fail_msg_transmited_bigger_max_size) &&
507       (result == GNUNET_SYSERR))
508   {
509     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
510                 "Message bigger max msg size was not sent!\n");
511     fail_msg_transmited_bigger_max_size = GNUNET_NO;
512     return;
513   }
514
515   if ((cls == &fail_msg_transmited_max_size) && (result == GNUNET_OK))
516   {
517     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
518                 "Message with max msg size succesfully sent!\n",
519                 fail_msgs_transmited_to_local_addrs);
520     fail_msg_transmited_max_size = GNUNET_NO;
521   }
522 }
523
524
525 static void run_connection_tests (int phase, void *cls);
526
527 /**
528  * Recieves messages from plugin, in real world transport
529  */
530 static struct GNUNET_TIME_Relative
531 receive (void *cls, const struct GNUNET_PeerIdentity *peer,
532          const struct GNUNET_MessageHeader *message,
533          const struct GNUNET_TRANSPORT_ATS_Information *ats,
534          uint32_t ats_count,
535          struct Session *session,
536          const char *sender_address, uint16_t sender_address_len)
537 {
538   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
539               "Testcase recieved new message from peer `%s' with type %u and length %u, session %X\n",
540               GNUNET_i2s (peer),
541               ntohs (message->type), ntohs (message->size), session);
542
543   if ((ntohs (message->type) >= 10) && (ntohs (message->type) < 20))
544   {
545     fail_msgs_transmited_to_local_addrs++;
546     if (fail_msgs_transmited_to_local_addrs == count_str_addr)
547       run_connection_tests (2, session);
548   }
549   if ((ntohs (message->type) == 20))
550   {
551     fail_session_selection_reliable = GNUNET_NO;
552   }
553   if ((ntohs (message->type) == 21))
554   {
555     fail_session_selection_any = GNUNET_NO;
556   }
557   if ((ntohs (message->type) == 22))
558   {
559     fail_session_selection_session = GNUNET_NO;
560   }
561   if ((ntohs (message->type) == 23))
562   {
563     fail_session_selection_session_big = GNUNET_NO;
564     run_connection_tests (3, NULL);
565   }
566   if ((ntohs (message->type) == 30) || (ntohs (message->type) == 31))
567   {
568     fail_multiple_msgs_in_transmission++;
569   }
570   if ((ntohs (message->type) == 32) &&
571       (ntohs (message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE - 1))
572   {
573     fail_msg_transmited_max_size = GNUNET_NO;
574     shutdown_clean ();
575   }
576   return GNUNET_TIME_UNIT_ZERO;
577 }
578
579
580 static size_t
581 send_function (void *stream, size_t size, size_t nmemb, void *ptr)
582 {
583   unsigned int len;
584
585   len = buffer_out.len;
586
587   if ((buffer_out.pos == len) || (len > (size * nmemb)))
588     return 0;
589   memcpy (stream, buffer_out.buf, len);
590   buffer_out.pos = len;
591   return len;
592
593 }
594
595 static size_t
596 recv_function (void *ptr, size_t size, size_t nmemb, void *ctx)
597 {
598
599   if (buffer_in.pos + size * nmemb > buffer_in.size)
600     return 0;                   /* overflow */
601
602   buffer_in.len = size * nmemb;
603   memcpy (&buffer_in.buf[buffer_in.pos], ptr, size * nmemb);
604   buffer_in.pos += size * nmemb;
605   buffer_in.len = buffer_in.pos;
606   buffer_in.buf[buffer_in.pos] = '\0';
607   return buffer_in.pos;
608 }
609
610 static size_t
611 header_function (void *ptr, size_t size, size_t nmemb, void *stream)
612 {
613   struct HTTP_Transfer *res = stream;
614   char *tmp;
615   unsigned int len = size * nmemb;
616
617   tmp = GNUNET_malloc (len + 1);
618   memcpy (tmp, ptr, len);
619   if (tmp[len - 2] == 13)
620     tmp[len - 2] = '\0';
621 #if DEBUG_CURL
622   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s'\n", tmp);
623 #endif
624   if (0 == strcmp (tmp, "HTTP/1.1 100 Continue"))
625   {
626     res->http_result_code = 100;
627   }
628   if (0 == strcmp (tmp, "HTTP/1.1 200 OK"))
629   {
630     res->http_result_code = 200;
631   }
632   if (0 == strcmp (tmp, "HTTP/1.1 400 Bad Request"))
633   {
634     res->http_result_code = 400;
635   }
636   if (0 == strcmp (tmp, "HTTP/1.1 404 Not Found"))
637   {
638     res->http_result_code = 404;
639   }
640   if (0 == strcmp (tmp, "HTTP/1.1 413 Request entity too large"))
641   {
642     res->http_result_code = 413;
643   }
644
645   GNUNET_free (tmp);
646   return size * nmemb;
647 }
648
649
650 static size_t send_prepare (struct HTTP_Transfer *result);
651
652
653 static void
654 send_execute (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
655 {
656   struct HTTP_Transfer *res;
657
658   int running;
659   struct CURLMsg *msg;
660   CURLMcode mret;
661
662   res = (struct HTTP_Transfer *) cls;
663   http_task_send = GNUNET_SCHEDULER_NO_TASK;
664   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
665     return;
666
667   do
668   {
669     running = 0;
670     mret = curl_multi_perform (multi_handle, &running);
671     if (running == 0)
672     {
673       do
674       {
675
676         msg = curl_multi_info_read (multi_handle, &running);
677         if (msg == NULL)
678           break;
679         /* get session for affected curl handle */
680         //cs = find_session_by_curlhandle (msg->easy_handle);
681         //GNUNET_assert ( cs != NULL );
682         switch (msg->msg)
683         {
684
685         case CURLMSG_DONE:
686           if ((msg->data.result != CURLE_OK) &&
687               (msg->data.result != CURLE_GOT_NOTHING))
688           {
689
690             GNUNET_log (GNUNET_ERROR_TYPE_INFO,
691                         _("curl failed for `%s' at %s:%d: `%s'\n"),
692                         "curl_multi_perform",
693                         __FILE__,
694                         __LINE__, curl_easy_strerror (msg->data.result));
695             /* sending msg failed */
696             curl_easy_cleanup (curl_handle);
697             curl_handle = NULL;
698
699             run_connection_tests (0, NULL);
700           }
701           if (res == &test_no_ident)
702           {
703             if ((res->http_result_code == 404) && (buffer_in.len == 208))
704             {
705               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
706                           "Connecting to peer without any peer identification: test passed\n");
707               res->test_failed = GNUNET_NO;
708             }
709             else
710               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
711                           _
712                           ("Connecting to peer without any peer identification: test failed\n"));
713           }
714           if (res == &test_too_short_ident)
715           {
716             if ((res->http_result_code == 404) && (buffer_in.len == 208))
717             {
718               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
719                           "Connecting to peer with too short peer identification: test passed\n");
720               res->test_failed = GNUNET_NO;
721             }
722             else
723               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
724                           _
725                           ("Connecting to peer with too short peer identification: test failed\n"));
726           }
727           if (res == &test_too_long_ident)
728           {
729             if ((res->http_result_code == 404) && (buffer_in.len == 208))
730             {
731               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
732                           "Connecting to peer with too long peer identification: test passed\n");
733               res->test_failed = GNUNET_NO;
734             }
735             else
736               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
737                           _
738                           ("Connecting to peer with too long peer identification: test failed\n"));
739           }
740           if (res == &test_valid_ident)
741           {
742             if ((res->http_result_code == 200))
743             {
744               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
745                           "Connecting to peer with valid peer identification: test passed\n");
746               res->test_failed = GNUNET_NO;
747             }
748             else
749               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
750                           "Connecting to peer with valid peer identification: test failed\n");
751           }
752           curl_easy_cleanup (curl_handle);
753           curl_handle = NULL;
754           if ((res == &test_valid_ident) && (res->test_failed == GNUNET_NO))
755             run_connection_tests (1, NULL);
756           run_connection_tests (0, NULL);
757           return;
758         default:
759           break;
760         }
761
762       }
763       while ((running > 0));
764     }
765   }
766   while (mret == CURLM_CALL_MULTI_PERFORM);
767   send_prepare (cls);
768 }
769
770
771 /**
772  * Function setting up file descriptors and scheduling task to run
773  * @param ses session to send data to
774  * @return bytes sent to peer
775  */
776 static size_t
777 send_prepare (struct HTTP_Transfer *result)
778 {
779   fd_set rs;
780   fd_set ws;
781   fd_set es;
782   int max;
783   struct GNUNET_NETWORK_FDSet *grs;
784   struct GNUNET_NETWORK_FDSet *gws;
785   long to;
786   CURLMcode mret;
787
788   max = -1;
789   FD_ZERO (&rs);
790   FD_ZERO (&ws);
791   FD_ZERO (&es);
792   mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max);
793   if (mret != CURLM_OK)
794   {
795     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
796                 _("%s failed at %s:%d: `%s'\n"),
797                 "curl_multi_fdset", __FILE__, __LINE__,
798                 curl_multi_strerror (mret));
799     return -1;
800   }
801   mret = curl_multi_timeout (multi_handle, &to);
802   if (mret != CURLM_OK)
803   {
804     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
805                 _("%s failed at %s:%d: `%s'\n"),
806                 "curl_multi_timeout", __FILE__, __LINE__,
807                 curl_multi_strerror (mret));
808     return -1;
809   }
810
811   grs = GNUNET_NETWORK_fdset_create ();
812   gws = GNUNET_NETWORK_fdset_create ();
813   GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
814   GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
815   http_task_send =
816       GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
817                                    GNUNET_SCHEDULER_NO_TASK,
818                                    GNUNET_TIME_relative_multiply
819                                    (GNUNET_TIME_UNIT_SECONDS, 0), grs, gws,
820                                    &send_execute, result);
821   GNUNET_NETWORK_fdset_destroy (gws);
822   GNUNET_NETWORK_fdset_destroy (grs);
823
824   /* FIXME: return bytes REALLY sent */
825   return 0;
826 }
827
828 /**
829  * function to send data to server
830  */
831 static int
832 send_data (struct HTTP_Transfer *result, char *url)
833 {
834
835   curl_handle = curl_easy_init ();
836   if (NULL == curl_handle)
837   {
838     printf ("easy_init failed \n");
839     return GNUNET_SYSERR;
840   }
841 #if DEBUG_CURL
842   curl_easy_setopt (curl_handle, CURLOPT_VERBOSE, 1L);
843 #endif
844   curl_easy_setopt (curl_handle, CURLOPT_URL, url);
845   curl_easy_setopt (curl_handle, CURLOPT_PUT, 1L);
846   curl_easy_setopt (curl_handle, CURLOPT_HEADERFUNCTION, &header_function);
847   curl_easy_setopt (curl_handle, CURLOPT_WRITEHEADER, result);
848   curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &recv_function);
849   curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result);
850   curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &send_function);
851   curl_easy_setopt (curl_handle, CURLOPT_READDATA, result);
852   curl_easy_setopt (curl_handle, CURLOPT_INFILESIZE_LARGE,
853                     (curl_off_t) buffer_out.len);
854   curl_easy_setopt (curl_handle, CURLOPT_TIMEOUT, 30);
855   curl_easy_setopt (curl_handle, CURLOPT_CONNECTTIMEOUT, 20);
856
857   curl_multi_add_handle (multi_handle, curl_handle);
858
859   send_prepare (result);
860
861   return GNUNET_OK;
862 }
863
864 /**
865  * Plugin notifies transport (aka testcase) about its addresses
866  */
867 static void
868 notify_address (void *cls, int add_remove, const void *addr, size_t addrlen)
869 {
870   char address[INET6_ADDRSTRLEN];
871   unsigned int port;
872   struct Plugin_Address *pl_addr;
873   struct Plugin_Address *cur;
874
875   if (addrlen == (sizeof (struct IPv4HttpAddress)))
876   {
877     inet_ntop (AF_INET, (struct in_addr *) addr, address, INET_ADDRSTRLEN);
878     port = ntohs (((struct IPv4HttpAddress *) addr)->u_port);
879   }
880   else if (addrlen == (sizeof (struct IPv6HttpAddress)))
881   {
882     inet_ntop (AF_INET6, (struct in6_addr *) addr, address, INET6_ADDRSTRLEN);
883     port = ntohs (((struct IPv6HttpAddress *) addr)->u6_port);
884   }
885   else
886   {
887     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
888                 _
889                 ("Unknown address size: ipv6 has %u ipv4 has %u but this has %u\n"),
890                 sizeof (struct IPv6HttpAddress),
891                 sizeof (struct IPv4HttpAddress), addrlen);
892     return;
893   }
894   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
895               _("Transport plugin notification for address: `%s':%u\n"),
896               address, port);
897   pl_addr = GNUNET_malloc (sizeof (struct Plugin_Address));
898   pl_addr->addrlen = addrlen;
899   pl_addr->addr = GNUNET_malloc (addrlen);
900   memcpy (pl_addr->addr, addr, addrlen);
901   pl_addr->next = NULL;
902
903   if (NULL == addr_head)
904   {
905     addr_head = pl_addr;
906   }
907   else
908   {
909     cur = addr_head;
910     while (NULL != cur->next)
911     {
912       cur = cur->next;
913     }
914     cur->next = pl_addr;
915   }
916   fail_notify_address_count++;
917   fail_notify_address = GNUNET_NO;
918 }
919
920 static void
921 plugin_env_session_end (void *cls,
922                         const struct GNUNET_PeerIdentity *peer,
923                         struct Session *session)
924 {
925   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
926               "Pluging tells me: session %X to peer `%s' ended\n",
927               session, GNUNET_i2s (peer));
928 }
929
930
931 /**
932  * Setup plugin environment
933  */
934 static void
935 setup_plugin_environment ()
936 {
937   env.cfg = cfg;
938   env.stats = stats;
939   env.my_identity = &my_identity;
940   env.cls = &env;
941   env.receive = &receive;
942   env.notify_address = &notify_address;
943   env.max_connections = max_connect_per_transport;
944   env.session_end = &plugin_env_session_end;
945 }
946
947
948 /**
949  * Task shutting down testcase if it a timeout occurs
950  */
951 static void
952 task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
953 {
954   ti_timeout = GNUNET_SCHEDULER_NO_TASK;
955   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
956     return;
957
958   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n");
959   fail = GNUNET_YES;
960   shutdown_clean ();
961   return;
962 }
963
964
965 static void
966 pretty_printer_cb (void *cls, const char *address)
967 {
968   if (NULL == address)
969     return;
970   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
971               "Plugin returned pretty address: `%s'\n", address);
972   fail_pretty_printer_count++;
973 }
974
975 /**
976  * Runs every single test to test the plugin
977  */
978 static void
979 run_connection_tests (int phase, void *cls)
980 {
981   struct GNUNET_MessageHeader *msg;
982   unsigned int size;
983
984   if (phase == 0)
985   {
986     char *host_str = NULL;
987
988     /* resetting buffers */
989     buffer_in.size = HTTP_BUFFER_SIZE;
990     buffer_in.pos = 0;
991     buffer_in.len = 0;
992
993     buffer_out.size = HTTP_BUFFER_SIZE;
994     buffer_out.pos = 0;
995     buffer_out.len = 0;
996
997     if (test_no_ident.test_executed == GNUNET_NO)
998     {
999       /* Connecting to peer without identification */
1000       const char *ident = "";
1001
1002       GNUNET_asprintf (&host_str,
1003                        "%s://%s/%s", PROTOCOL_PREFIX, test_addr, ident);
1004       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1005                   _("Connecting to peer without any peer identification.\n"));
1006       test_no_ident.test_executed = GNUNET_YES;
1007       send_data (&test_no_ident, host_str);
1008       GNUNET_free (host_str);
1009       return;
1010     }
1011     if (test_too_short_ident.test_executed == GNUNET_NO)
1012     {
1013       const char *ident = "AAAAAAAAAA";
1014
1015       /* Connecting to peer with too short identification */
1016       GNUNET_asprintf (&host_str,
1017                        "%s://%s/%s", PROTOCOL_PREFIX, test_addr, ident);
1018       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1019                   _
1020                   ("Connecting to peer with too short peer identification.\n"));
1021       test_too_short_ident.test_executed = GNUNET_YES;
1022       send_data (&test_too_short_ident, host_str);
1023       GNUNET_free (host_str);
1024       return;
1025     }
1026
1027     if (test_too_long_ident.test_executed == GNUNET_NO)
1028     {
1029       const char *ident =
1030           "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1031
1032       /* Connecting to peer with too long identification */
1033       GNUNET_asprintf (&host_str, "%s://%s/%s", PROTOCOL_PREFIX, test_addr,
1034                        ident);
1035       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1036                   _("Connecting to peer with too long peer identification.\n"));
1037       test_too_long_ident.test_executed = GNUNET_YES;
1038       send_data (&test_too_long_ident, host_str);
1039       GNUNET_free (host_str);
1040       return;
1041     }
1042     if (test_valid_ident.test_executed == GNUNET_NO)
1043     {
1044       struct GNUNET_CRYPTO_HashAsciiEncoded ident;
1045
1046       GNUNET_CRYPTO_hash_to_enc (&my_identity.hashPubKey, &ident);
1047       GNUNET_asprintf (&host_str,
1048                        "%s://%s/%s%s",
1049                        PROTOCOL_PREFIX, test_addr, (char *) &ident, ";0");
1050       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1051                   _("Connecting to peer with valid peer identification.\n"));
1052       test_valid_ident.test_executed = GNUNET_YES;
1053       send_data (&test_valid_ident, host_str);
1054       GNUNET_free (host_str);
1055       return;
1056     }
1057   }
1058   if (phase == 1)
1059   {
1060     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1061                 "\nPhase 1: transmit data to all suggested addresses\n\n");
1062     /* Using one of the addresses the plugin proposed */
1063     GNUNET_assert (addr_head->addr != NULL);
1064
1065     struct Plugin_Address *tmp_addr;
1066     struct GNUNET_MessageHeader msg;
1067     char *tmp = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
1068     char address[INET6_ADDRSTRLEN];
1069     unsigned int port;
1070     unsigned int type = 10;
1071
1072     msg.size = htons (sizeof (struct GNUNET_MessageHeader));
1073     tmp_addr = addr_head;
1074     /* send a message to all addresses advertised by plugin */
1075
1076     int count = 0;
1077
1078     while (tmp_addr != NULL)
1079     {
1080       if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress)))
1081       {
1082         inet_ntop (AF_INET, (struct in_addr *) tmp_addr->addr, address,
1083                    INET_ADDRSTRLEN);
1084         port = ntohs (((struct IPv4HttpAddress *) tmp_addr->addr)->u_port);
1085         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1086                     "Sending message to addres no. %u: `%s':%u\n",
1087                     count, address, port);
1088       }
1089       if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress)))
1090       {
1091         inet_ntop (AF_INET6, (struct in6_addr *) tmp_addr->addr, address,
1092                    INET6_ADDRSTRLEN);
1093         port = ntohs (((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port);
1094         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1095                     "Sending message to addres no. %u: `%s':%u\n",
1096                     count, address, port);
1097       }
1098       msg.type = htons (type);
1099       memcpy (tmp, &msg, sizeof (struct GNUNET_MessageHeader));
1100       api->send (api->cls,
1101                  &my_identity,
1102                  tmp, sizeof (struct GNUNET_MessageHeader),
1103                  0, TIMEOUT,
1104                  NULL,
1105                  tmp_addr->addr, tmp_addr->addrlen,
1106                  GNUNET_YES,
1107                  &task_send_cont, &fail_msgs_transmited_to_local_addrs);
1108       tmp_addr = tmp_addr->next;
1109       count++;
1110       type++;
1111     }
1112     GNUNET_free (tmp);
1113     return;
1114   }
1115
1116   if (phase == 2)
1117   {
1118     struct Session *session = cls;
1119
1120     msg = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
1121
1122     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 2: session selection\n\n");
1123     size = sizeof (struct GNUNET_MessageHeader);
1124     msg->size = htons (size);
1125     msg->type = htons (20);
1126     api->send (api->cls,
1127                &my_identity,
1128                (const char *) msg, size,
1129                0, TIMEOUT, NULL, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1130
1131     msg->type = htons (21);
1132     api->send (api->cls,
1133                &my_identity,
1134                (const char *) msg, size,
1135                0, TIMEOUT, NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
1136
1137     /* answer on session */
1138     size = sizeof (struct GNUNET_MessageHeader);
1139     msg->size = htons (size);
1140     msg->type = htons (22);
1141     api->send (api->cls,
1142                &my_identity,
1143                (const char *) msg, size,
1144                0, TIMEOUT, session, NULL, 0, GNUNET_SYSERR,
1145                &task_send_cont, NULL);
1146     GNUNET_free (msg);
1147
1148     /* answer on session with big message not fitting in mhd send buffer */
1149     size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
1150     msg = GNUNET_malloc (size);
1151     msg->size = htons (size);
1152     msg->type = htons (23);
1153     api->send (api->cls,
1154                &my_identity,
1155                (const char *) msg, size,
1156                0, TIMEOUT, session, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1157     GNUNET_free (msg);
1158     return;
1159   }
1160
1161   if (phase == 3)
1162   {
1163
1164     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1165                 "Phase 3: send multiple or big messages after disconnect\n\n");
1166     /* disconnect from peer, so new connections are created */
1167     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect from peer: `%s'\n",
1168                 GNUNET_i2s (&my_identity));
1169     api->disconnect (api->cls, &my_identity);
1170
1171     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 3: sending messages\n");
1172     /* send a multiple GNUNET_messages at a time */
1173     size = 2 * sizeof (struct GNUNET_MessageHeader);
1174     msg = GNUNET_malloc (2 * size);
1175     msg->size = htons (size);
1176     msg->type = htons (30);
1177     struct GNUNET_MessageHeader *msg2 = &msg[2];
1178
1179     msg2->size = htons (2 * sizeof (struct GNUNET_MessageHeader));
1180     msg2->type = htons (31);
1181     api->send (api->cls,
1182                &my_identity,
1183                (const char *) msg, 4 * sizeof (struct GNUNET_MessageHeader),
1184                0, TIMEOUT, NULL,
1185                addr_head->addr, addr_head->addrlen,
1186                GNUNET_NO, &task_send_cont, &fail_multiple_msgs_in_transmission);
1187     GNUNET_free (msg);
1188     /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1  */
1189
1190     size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
1191     msg = GNUNET_malloc (size);
1192     msg->size = htons (size);
1193     msg->type = htons (32);
1194     api->send (api->cls,
1195                &my_identity,
1196                (const char *) msg, size,
1197                0, TIMEOUT, NULL,
1198                addr_head->addr, addr_head->addrlen,
1199                GNUNET_NO, &task_send_cont, &fail_msg_transmited_max_size);
1200     GNUNET_free (msg);
1201     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more tests to run\n");
1202   }
1203 }
1204
1205
1206 /**
1207  * Runs the test.
1208  *
1209  * @param cls closure
1210  * @param c configuration to use
1211  */
1212 static void
1213 run (void *cls,
1214      char *const *args,
1215      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
1216 {
1217   char *libname;
1218
1219   cfg = c;
1220   char *keyfile;
1221   unsigned long long tneigh;
1222   struct Plugin_Address *cur;
1223   const char *addr_str;
1224
1225
1226   unsigned int suggest_res;
1227
1228   fail_pretty_printer = GNUNET_YES;
1229   fail_notify_address = GNUNET_YES;
1230   fail_addr_to_str = GNUNET_YES;
1231   fail_msgs_transmited_to_local_addrs = 0;
1232   fail_msg_transmited_max_size = GNUNET_YES;
1233   fail_multiple_msgs_in_transmission = 0;
1234   fail_session_selection_reliable = GNUNET_YES;
1235   fail_session_selection_reliable = GNUNET_YES;
1236   fail_session_selection_session = GNUNET_YES;
1237   fail_session_selection_session_big = GNUNET_YES;
1238
1239   addr_head = NULL;
1240   count_str_addr = 0;
1241   /* parse configuration */
1242   if (GNUNET_CONFIGURATION_have_value (c, "PATHS", "SERVICEHOME"))
1243     GNUNET_CONFIGURATION_get_value_string (c, "PATHS", "SERVICEHOME",
1244                                            &servicehome);
1245
1246   if ((GNUNET_OK !=
1247        GNUNET_CONFIGURATION_get_value_number (c,
1248                                               "TRANSPORT",
1249                                               "NEIGHBOUR_LIMIT",
1250                                               &tneigh)) ||
1251       (GNUNET_OK !=
1252        GNUNET_CONFIGURATION_get_value_filename (c,
1253                                                 "GNUNETD",
1254                                                 "HOSTKEY", &keyfile)))
1255   {
1256     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1257                 _
1258                 ("Transport service is lacking key configuration settings.  Exiting.\n"));
1259     GNUNET_SCHEDULER_shutdown ();
1260     fail = 1;
1261     return;
1262   }
1263
1264   if ((GNUNET_OK !=
1265        GNUNET_CONFIGURATION_get_value_number (cfg,
1266                                               "transport-http",
1267                                               "PORT",
1268                                               &port)) ||
1269       (port > 65535) || (port == 0))
1270   {
1271     GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
1272                      "http",
1273                      _
1274                      ("Require valid port number for transport plugin `%s' in configuration!\n"),
1275                      "transport-http");
1276   }
1277
1278   max_connect_per_transport = (uint32_t) tneigh;
1279   my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
1280   GNUNET_free (keyfile);
1281   if (my_private_key == NULL)
1282   {
1283     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1284                 _("Transport service could not access hostkey.  Exiting.\n"));
1285     GNUNET_SCHEDULER_shutdown ();
1286     fail = 1;
1287     return;
1288   }
1289
1290   GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
1291   GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
1292                       &my_identity.hashPubKey);
1293
1294   /* assertions before start */
1295   GNUNET_assert ((port > 0) && (port <= 65535));
1296
1297   /* load plugins... */
1298   setup_plugin_environment ();
1299   GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http");
1300   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1301               _("Loading HTTP transport plugin `%s'\n"), libname);
1302   api = GNUNET_PLUGIN_load (libname, &env);
1303   GNUNET_free (libname);
1304   if (api == NULL)
1305   {
1306     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1307                 _("Failed to load transport plugin for http\n"));
1308     fail = 1;
1309     return;
1310   }
1311
1312
1313   ti_timeout = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &task_timeout, NULL);
1314
1315   /* testing plugin functionality */
1316   GNUNET_assert (0 != fail_notify_address_count);
1317   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1318               "Transport plugin returned %u addresses to connect to\n",
1319               fail_notify_address_count);
1320
1321   /* testing pretty printer with all addresses obtained from the plugin */
1322   cur = addr_head;
1323   while (cur != NULL)
1324   {
1325     api->address_pretty_printer (api->cls, "http",
1326                                  cur->addr, cur->addrlen, GNUNET_NO,
1327                                  TEST_TIMEOUT, &pretty_printer_cb, NULL);
1328     addr_str = api->address_to_string (api->cls, cur->addr, cur->addrlen);
1329     suggest_res = api->check_address (api->cls, cur->addr, cur->addrlen);
1330
1331     GNUNET_assert (GNUNET_OK == suggest_res);
1332     GNUNET_assert (NULL != addr_str);
1333     count_str_addr++;
1334     GNUNET_free ((char *) addr_str);
1335     cur = cur->next;
1336   }
1337   GNUNET_assert (fail_pretty_printer_count > 0);
1338   GNUNET_assert (fail_pretty_printer_count == fail_notify_address_count);
1339   GNUNET_assert (fail_pretty_printer_count == count_str_addr);
1340   fail_pretty_printer = GNUNET_NO;
1341   fail_addr_to_str = GNUNET_NO;
1342
1343   struct IPv4HttpAddress failing_addr;
1344
1345   /* Suggesting addresses with wrong size */
1346   failing_addr.ipv4_addr = htonl (INADDR_LOOPBACK);
1347   failing_addr.u_port = htons (0);
1348   suggest_res =
1349       api->check_address (api->cls, &failing_addr,
1350                           sizeof (struct IPv6HttpAddress));
1351   GNUNET_assert (GNUNET_SYSERR == suggest_res);
1352
1353   /* Suggesting addresses with wrong address */
1354   failing_addr.ipv4_addr = htonl (0xffc00000);
1355   failing_addr.u_port = htons (12389);
1356   suggest_res = api->check_address (api->cls, &failing_addr, 100);
1357   GNUNET_assert (GNUNET_SYSERR == suggest_res);
1358
1359   /* test sending to client */
1360   multi_handle = curl_multi_init ();
1361
1362   /* Setting up buffers */
1363   buffer_in.size = HTTP_BUFFER_SIZE;
1364   buffer_in.pos = 0;
1365   buffer_in.len = 0;
1366
1367   buffer_out.size = HTTP_BUFFER_SIZE;
1368   buffer_out.pos = 0;
1369   buffer_out.len = 0;
1370
1371   /* Setting up connection tests */
1372
1373   /* Test: connecting without a peer identification */
1374   test_no_ident.test_executed = GNUNET_NO;
1375   test_no_ident.test_failed = GNUNET_YES;
1376
1377   /* Test: connecting with too short peer identification */
1378   test_too_short_ident.test_executed = GNUNET_NO;
1379   test_too_short_ident.test_failed = GNUNET_YES;
1380
1381   /* Test: connecting with too long peer identification */
1382   test_too_long_ident.test_executed = GNUNET_NO;
1383   test_too_long_ident.test_failed = GNUNET_YES;
1384
1385   /* Test: connecting with valid identification */
1386   test_valid_ident.test_executed = GNUNET_NO;
1387   test_valid_ident.test_failed = GNUNET_YES;
1388
1389   test_addr =
1390       (char *) api->address_to_string (api->cls, addr_head->addr,
1391                                        addr_head->addrlen);
1392
1393   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Phase 0\n\n"));
1394   run_connection_tests (0, NULL);
1395   /* testing finished */
1396 }
1397
1398
1399 /**
1400  * The main function for the transport service.
1401  *
1402  * @param argc number of arguments from the command line
1403  * @param argv command line arguments
1404  * @return 0 ok, 1 on error
1405  */
1406 int
1407 main (int argc, char *const *argv)
1408 {
1409   static struct GNUNET_GETOPT_CommandLineOption options[] = {
1410     GNUNET_GETOPT_OPTION_END
1411   };
1412   int ret;
1413
1414   char *const argv_prog[] = {
1415     "test_gnunet_transport_plugin_http",
1416     "-c",
1417     "test_plugin_transport_data_http.conf",
1418     "-L",
1419 #if VERBOSE
1420     "DEBUG",
1421 #else
1422     "WARNING",
1423 #endif
1424     NULL
1425   };
1426   GNUNET_log_setup ("test_gnunet_transport_plugin_http",
1427 #if VERBOSE
1428                     "DEBUG",
1429 #else
1430                     "WARNING",
1431 #endif
1432                     NULL);
1433
1434   struct GNUNET_CONFIGURATION_Handle *cfg;
1435
1436   cfg = GNUNET_CONFIGURATION_create ();
1437
1438   GNUNET_assert (GNUNET_OK ==
1439                  GNUNET_CONFIGURATION_load (cfg,
1440                                             "test_plugin_transport_data_http.conf"));
1441   if (GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "SERVICEHOME"))
1442     GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME",
1443                                            &servicehome);
1444   GNUNET_DISK_directory_remove (servicehome);
1445   GNUNET_CONFIGURATION_destroy (cfg);
1446
1447   ret = (GNUNET_OK ==
1448          GNUNET_PROGRAM_run (5,
1449                              argv_prog,
1450                              "test_gnunet_transport_plugin_http",
1451                              "testcase", options, &run,
1452                              NULL)) ? GNUNET_NO : GNUNET_YES;
1453
1454   if (servicehome != NULL)
1455   {
1456     GNUNET_DISK_directory_remove (servicehome);
1457     GNUNET_free (servicehome);
1458   }
1459   if (ret != GNUNET_OK)
1460     return 1;
1461   return fail;
1462 }
1463
1464 /* end of test_gnunet_transport_plugin_http.c */