diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-06-07 15:58:54 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-06-07 15:58:54 +0000 |
commit | 15bf78afec112f09430c05140e246b77cb4533a8 (patch) | |
tree | acdf9a70bc156c196a2db909b6482de78ee68a33 | |
parent | bab5ef979f84c0d1b8edb9d67210f379783263aa (diff) | |
download | gnunet-15bf78afec112f09430c05140e246b77cb4533a8.tar.gz gnunet-15bf78afec112f09430c05140e246b77cb4533a8.zip |
-rw-r--r-- | src/transport/plugin_transport_http.c | 50 | ||||
-rw-r--r-- | src/transport/test_plugin_transport_http.c | 86 |
2 files changed, 105 insertions, 31 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 7e11cbae1..4c367dd17 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -216,6 +216,11 @@ struct Session | |||
216 | unsigned int is_put_in_progress; | 216 | unsigned int is_put_in_progress; |
217 | 217 | ||
218 | /** | 218 | /** |
219 | * Is there a HTTP/PUT in progress? | ||
220 | */ | ||
221 | unsigned int is_bad_request; | ||
222 | |||
223 | /** | ||
219 | * Encoded hash | 224 | * Encoded hash |
220 | */ | 225 | */ |
221 | struct GNUNET_CRYPTO_HashAsciiEncoded hash; | 226 | struct GNUNET_CRYPTO_HashAsciiEncoded hash; |
@@ -415,6 +420,8 @@ acceptPolicyCallback (void *cls, | |||
415 | } | 420 | } |
416 | 421 | ||
417 | 422 | ||
423 | int serror; | ||
424 | |||
418 | /** | 425 | /** |
419 | * Process GET or PUT request received via MHD. For | 426 | * Process GET or PUT request received via MHD. For |
420 | * GET, queue response that will send back our pending | 427 | * GET, queue response that will send back our pending |
@@ -446,6 +453,7 @@ accessHandlerCallback (void *cls, | |||
446 | 453 | ||
447 | gn_msg = NULL; | 454 | gn_msg = NULL; |
448 | send_error_to_client = GNUNET_NO; | 455 | send_error_to_client = GNUNET_NO; |
456 | |||
449 | if ( NULL == *httpSessionCache) | 457 | if ( NULL == *httpSessionCache) |
450 | { | 458 | { |
451 | /* check url for peer identity */ | 459 | /* check url for peer identity */ |
@@ -546,11 +554,30 @@ accessHandlerCallback (void *cls, | |||
546 | cs->is_active = GNUNET_YES; | 554 | cs->is_active = GNUNET_YES; |
547 | return MHD_YES; | 555 | return MHD_YES; |
548 | } | 556 | } |
557 | |||
558 | if (cs->is_bad_request == GNUNET_YES) | ||
559 | { | ||
560 | *upload_data_size = 0; | ||
561 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Info: size: %u method: %s \n",*upload_data_size,method); | ||
562 | response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO); | ||
563 | if (response == NULL) | ||
564 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"response NULL\n"); | ||
565 | res = MHD_queue_response (session, MHD_HTTP_BAD_REQUEST, response); | ||
566 | if (res == MHD_YES) | ||
567 | { | ||
568 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 400 BAD REQUEST as PUT Response\n"); | ||
569 | cs->is_bad_request = GNUNET_NO; | ||
570 | cs->is_put_in_progress =GNUNET_NO; | ||
571 | } | ||
572 | else | ||
573 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 400 BAD REQUEST as PUT Response not sent\n"); | ||
574 | MHD_destroy_response (response); | ||
575 | return MHD_YES; | ||
576 | } | ||
577 | |||
549 | if ( *upload_data_size > 0 ) | 578 | if ( *upload_data_size > 0 ) |
550 | { | 579 | { |
551 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"PUT URL: `%s'\n",url); | 580 | |
552 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"PUT Request: %lu bytes: `%s' \n", (*upload_data_size), upload_data); | ||
553 | /* No data left */ | ||
554 | bytes_recv = *upload_data_size ; | 581 | bytes_recv = *upload_data_size ; |
555 | *upload_data_size = 0; | 582 | *upload_data_size = 0; |
556 | 583 | ||
@@ -572,25 +599,26 @@ accessHandlerCallback (void *cls, | |||
572 | 599 | ||
573 | if ( ntohs(gn_msg->size) != bytes_recv ) | 600 | if ( ntohs(gn_msg->size) != bytes_recv ) |
574 | { | 601 | { |
575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Message has incorrect size, is %u bytes vs %u recieved'\n",ntohs(gn_msg->size) , bytes_recv); | 602 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Malformed GNUnet: message has incorrect size, is %u bytes in header vs %u recieved\n",ntohs(gn_msg->size) , bytes_recv); |
576 | send_error_to_client = GNUNET_YES; | 603 | send_error_to_client = GNUNET_YES; |
577 | } | 604 | } |
578 | 605 | ||
579 | if ( GNUNET_YES == send_error_to_client) | 606 | if (send_error_to_client == GNUNET_YES) |
580 | { | 607 | { |
581 | response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO); | 608 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Malformed GNUnet, should send error\n"); |
582 | res = MHD_queue_response (session, MHD_HTTP_BAD_REQUEST, response); | 609 | cs->is_bad_request = GNUNET_YES; |
583 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 400 BAD REQUEST as PUT Response\n",HTTP_PUT_RESPONSE, strlen (HTTP_PUT_RESPONSE), res ); | 610 | return MHD_YES; |
584 | MHD_destroy_response (response); | ||
585 | GNUNET_free (gn_msg); | ||
586 | return MHD_NO; | ||
587 | } | 611 | } |
612 | |||
588 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Recieved GNUnet message type %u size %u and payload %u \n",ntohs (gn_msg->type), ntohs (gn_msg->size), ntohs (gn_msg->size)-sizeof(struct GNUNET_MessageHeader)); | 613 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Recieved GNUnet message type %u size %u and payload %u \n",ntohs (gn_msg->type), ntohs (gn_msg->size), ntohs (gn_msg->size)-sizeof(struct GNUNET_MessageHeader)); |
589 | 614 | ||
590 | /* forwarding message to transport */ | 615 | /* forwarding message to transport */ |
591 | plugin->env->receive(plugin->env, &(cs->sender), gn_msg, 1, cs , cs->ip, strlen(cs->ip) ); | 616 | plugin->env->receive(plugin->env, &(cs->sender), gn_msg, 1, cs , cs->ip, strlen(cs->ip) ); |
617 | GNUNET_free (gn_msg); | ||
592 | return MHD_YES; | 618 | return MHD_YES; |
593 | } | 619 | } |
620 | |||
621 | |||
594 | if ((*upload_data_size == 0) && (cs->is_put_in_progress == GNUNET_YES)) | 622 | if ((*upload_data_size == 0) && (cs->is_put_in_progress == GNUNET_YES)) |
595 | { | 623 | { |
596 | cs->is_put_in_progress = GNUNET_NO; | 624 | cs->is_put_in_progress = GNUNET_NO; |
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c index 5772fd118..047978343 100644 --- a/src/transport/test_plugin_transport_http.c +++ b/src/transport/test_plugin_transport_http.c | |||
@@ -42,9 +42,9 @@ | |||
42 | #include "transport.h" | 42 | #include "transport.h" |
43 | #include <curl/curl.h> | 43 | #include <curl/curl.h> |
44 | 44 | ||
45 | #define VERBOSE GNUNET_NO | 45 | #define VERBOSE GNUNET_YES |
46 | #define DEBUG GNUNET_NO | 46 | #define DEBUG GNUNET_YES |
47 | #define DEBUG_CURL GNUNET_NO | 47 | #define DEBUG_CURL GNUNET_YES |
48 | #define HTTP_BUFFER_SIZE 2048 | 48 | #define HTTP_BUFFER_SIZE 2048 |
49 | 49 | ||
50 | #define PLUGIN libgnunet_plugin_transport_template | 50 | #define PLUGIN libgnunet_plugin_transport_template |
@@ -95,7 +95,7 @@ struct HTTP_Message | |||
95 | /** | 95 | /** |
96 | * buffer | 96 | * buffer |
97 | */ | 97 | */ |
98 | char *buf; | 98 | unsigned char buf[HTTP_BUFFER_SIZE]; |
99 | 99 | ||
100 | /** | 100 | /** |
101 | * current position in buffer | 101 | * current position in buffer |
@@ -127,7 +127,7 @@ struct HTTP_Transfer | |||
127 | /** | 127 | /** |
128 | * buffer for http transfers | 128 | * buffer for http transfers |
129 | */ | 129 | */ |
130 | unsigned char buf[2048]; | 130 | unsigned char buf[HTTP_BUFFER_SIZE]; |
131 | 131 | ||
132 | /** | 132 | /** |
133 | * buffer size this transfer | 133 | * buffer size this transfer |
@@ -309,6 +309,20 @@ static struct HTTP_Transfer test_too_short_ident; | |||
309 | */ | 309 | */ |
310 | static struct HTTP_Transfer test_too_long_ident; | 310 | static struct HTTP_Transfer test_too_long_ident; |
311 | 311 | ||
312 | /** | ||
313 | * Test: connect to peer and send message bigger then content length | ||
314 | */ | ||
315 | static struct HTTP_Transfer test_msg_too_big; | ||
316 | |||
317 | /** | ||
318 | * Test: connect to peer and send message bigger GNUNET_SERVER_MAX_MESSAGE_SIZE | ||
319 | */ | ||
320 | //static struct HTTP_Transfer test_msg_bigger_max; | ||
321 | |||
322 | /** | ||
323 | * Test: connect to peer and send message smaller then content length | ||
324 | */ | ||
325 | //static struct HTTP_Transfer test_msg_too_small; | ||
312 | 326 | ||
313 | /** | 327 | /** |
314 | * Test: connect to peer with valid peer identification | 328 | * Test: connect to peer with valid peer identification |
@@ -386,9 +400,6 @@ shutdown_clean () | |||
386 | 400 | ||
387 | GNUNET_SCHEDULER_shutdown(sched); | 401 | GNUNET_SCHEDULER_shutdown(sched); |
388 | 402 | ||
389 | GNUNET_free (buffer_in.buf); | ||
390 | GNUNET_free (buffer_out.buf); | ||
391 | |||
392 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting testcase\n"); | 403 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting testcase\n"); |
393 | exit(fail); | 404 | exit(fail); |
394 | return; | 405 | return; |
@@ -459,14 +470,24 @@ receive (void *cls, | |||
459 | static size_t send_function (void *stream, size_t size, size_t nmemb, void *ptr) | 470 | static size_t send_function (void *stream, size_t size, size_t nmemb, void *ptr) |
460 | { | 471 | { |
461 | unsigned int len; | 472 | unsigned int len; |
462 | struct HTTP_Message * cbc = ptr; | 473 | struct HTTP_Transfer * test = (struct HTTP_Transfer *) ptr; |
463 | 474 | ||
464 | len = cbc->len; | 475 | len = buffer_out.len; |
465 | 476 | ||
466 | if (( cbc->pos == len) && (len < (size * nmemb))) | 477 | if (test == &test_msg_too_big) |
478 | { | ||
479 | if (buffer_out.pos > len) | ||
480 | return 0; | ||
481 | if ( (2*len) < (size * nmemb)) | ||
482 | memcpy(stream, buffer_out.buf, 2* len); | ||
483 | buffer_out.pos = 2* len; | ||
484 | return 2* len; | ||
485 | } | ||
486 | |||
487 | if (( buffer_out.pos == len) || (len > (size * nmemb))) | ||
467 | return 0; | 488 | return 0; |
468 | memcpy(stream, cbc->buf, len); | 489 | memcpy(stream, buffer_out.buf, len); |
469 | cbc->pos = len; | 490 | buffer_out.pos = len; |
470 | return len; | 491 | return len; |
471 | } | 492 | } |
472 | 493 | ||
@@ -494,6 +515,7 @@ static size_t header_function( void *ptr, size_t size, size_t nmemb, void *strea | |||
494 | memcpy(tmp,ptr,len); | 515 | memcpy(tmp,ptr,len); |
495 | if (tmp[len-2] == 13) | 516 | if (tmp[len-2] == 13) |
496 | tmp[len-2]= '\0'; | 517 | tmp[len-2]= '\0'; |
518 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Header: `%s'\n"),tmp); | ||
497 | if (0==strcmp (tmp,"HTTP/1.1 100 Continue")) | 519 | if (0==strcmp (tmp,"HTTP/1.1 100 Continue")) |
498 | { | 520 | { |
499 | res->http_result_code=100; | 521 | res->http_result_code=100; |
@@ -698,7 +720,7 @@ static int send_data( struct HTTP_Transfer * result, char * url) | |||
698 | curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &recv_function); | 720 | curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &recv_function); |
699 | curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result); | 721 | curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result); |
700 | curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &send_function); | 722 | curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &send_function); |
701 | curl_easy_setopt (curl_handle, CURLOPT_READDATA, &buffer_out); | 723 | curl_easy_setopt (curl_handle, CURLOPT_READDATA, result); |
702 | curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) buffer_out.len); | 724 | curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) buffer_out.len); |
703 | curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 30); | 725 | curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 30); |
704 | curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 20); | 726 | curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 20); |
@@ -833,7 +855,7 @@ static void run_connection_tests( void ) | |||
833 | /* Connecting to peer without identification */ | 855 | /* Connecting to peer without identification */ |
834 | host_str = GNUNET_malloc (strlen ("http://localhost:12389/")+1); | 856 | host_str = GNUNET_malloc (strlen ("http://localhost:12389/")+1); |
835 | GNUNET_asprintf (&host_str, "http://localhost:%u/",port); | 857 | GNUNET_asprintf (&host_str, "http://localhost:%u/",port); |
836 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer identification.\n"), host_str); | 858 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer identification.\n")); |
837 | test_no_ident.test_executed = GNUNET_YES; | 859 | test_no_ident.test_executed = GNUNET_YES; |
838 | send_data ( &test_no_ident, host_str); | 860 | send_data ( &test_no_ident, host_str); |
839 | GNUNET_free (host_str); | 861 | GNUNET_free (host_str); |
@@ -847,7 +869,7 @@ static void run_connection_tests( void ) | |||
847 | /* Connecting to peer with too short identification */ | 869 | /* Connecting to peer with too short identification */ |
848 | host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen (ident)); | 870 | host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen (ident)); |
849 | GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,ident); | 871 | GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,ident); |
850 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too short peer identification.\n"), host_str); | 872 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too short peer identification.\n")); |
851 | test_too_short_ident.test_executed = GNUNET_YES; | 873 | test_too_short_ident.test_executed = GNUNET_YES; |
852 | send_data ( &test_too_short_ident, host_str); | 874 | send_data ( &test_too_short_ident, host_str); |
853 | GNUNET_free (host_str); | 875 | GNUNET_free (host_str); |
@@ -863,7 +885,7 @@ static void run_connection_tests( void ) | |||
863 | host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen (ident)); | 885 | host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen (ident)); |
864 | GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,ident); | 886 | GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,ident); |
865 | 887 | ||
866 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification.\n"), host_str); | 888 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification.\n")); |
867 | test_too_long_ident.test_executed = GNUNET_YES; | 889 | test_too_long_ident.test_executed = GNUNET_YES; |
868 | send_data ( &test_too_long_ident, host_str); | 890 | send_data ( &test_too_long_ident, host_str); |
869 | GNUNET_free (host_str); | 891 | GNUNET_free (host_str); |
@@ -878,14 +900,36 @@ static void run_connection_tests( void ) | |||
878 | host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen ((const char *) &result)); | 900 | host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen ((const char *) &result)); |
879 | GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,(char *) &result); | 901 | GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,(char *) &result); |
880 | 902 | ||
881 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with valid peer identification.\n"), host_str); | 903 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with valid peer identification.\n")); |
882 | test_valid_ident.test_executed = GNUNET_YES; | 904 | test_valid_ident.test_executed = GNUNET_YES; |
883 | send_data ( &test_valid_ident, host_str); | 905 | send_data ( &test_valid_ident, host_str); |
884 | GNUNET_free (host_str); | 906 | GNUNET_free (host_str); |
885 | 907 | ||
886 | return; | 908 | return; |
887 | } | 909 | } |
910 | /* | ||
911 | if (test_msg_too_big.test_executed == GNUNET_NO) | ||
912 | { | ||
913 | struct GNUNET_CRYPTO_HashAsciiEncoded result; | ||
914 | unsigned int c; | ||
888 | 915 | ||
916 | GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&result); | ||
917 | host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen ((const char *) &result)); | ||
918 | GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,(char *) &result); | ||
919 | |||
920 | buffer_out.len = 50; | ||
921 | c = 0; | ||
922 | for (c=0; c<100; c++) | ||
923 | buffer_out.buf[c] = 'A'; | ||
924 | |||
925 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with message bigger content length.\n")); | ||
926 | test_msg_too_big.test_executed = GNUNET_YES; | ||
927 | send_data ( &test_msg_too_big, host_str); | ||
928 | GNUNET_free (host_str); | ||
929 | |||
930 | return; | ||
931 | } | ||
932 | */ | ||
889 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n"); | 933 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n"); |
890 | shutdown_clean(); | 934 | shutdown_clean(); |
891 | } | 935 | } |
@@ -1039,12 +1083,10 @@ run (void *cls, | |||
1039 | 1083 | ||
1040 | /* Setting up buffers */ | 1084 | /* Setting up buffers */ |
1041 | buffer_in.size = HTTP_BUFFER_SIZE; | 1085 | buffer_in.size = HTTP_BUFFER_SIZE; |
1042 | buffer_in.buf = GNUNET_malloc (HTTP_BUFFER_SIZE); | ||
1043 | buffer_in.pos = 0; | 1086 | buffer_in.pos = 0; |
1044 | buffer_in.len = 0; | 1087 | buffer_in.len = 0; |
1045 | 1088 | ||
1046 | buffer_out.size = HTTP_BUFFER_SIZE; | 1089 | buffer_out.size = HTTP_BUFFER_SIZE; |
1047 | buffer_out.buf = GNUNET_malloc (HTTP_BUFFER_SIZE); | ||
1048 | buffer_out.pos = 0; | 1090 | buffer_out.pos = 0; |
1049 | buffer_out.len = 0; | 1091 | buffer_out.len = 0; |
1050 | 1092 | ||
@@ -1066,6 +1108,10 @@ run (void *cls, | |||
1066 | test_valid_ident.test_executed = GNUNET_NO; | 1108 | test_valid_ident.test_executed = GNUNET_NO; |
1067 | test_valid_ident.test_failed = GNUNET_YES; | 1109 | test_valid_ident.test_failed = GNUNET_YES; |
1068 | 1110 | ||
1111 | /* Test: connecting with valid identification */ | ||
1112 | test_msg_too_big.test_executed = GNUNET_NO; | ||
1113 | test_msg_too_big.test_failed = GNUNET_YES; | ||
1114 | |||
1069 | run_connection_tests(); | 1115 | run_connection_tests(); |
1070 | 1116 | ||
1071 | /* testing finished */ | 1117 | /* testing finished */ |