diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-06-23 13:58:16 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-06-23 13:58:16 +0000 |
commit | c0d4d588c68154a68d5489deb2c67577eb1848c8 (patch) | |
tree | ed1a573e25c3ea6399993452717e43bd904c7044 /src | |
parent | 544e880ab3dd3292e2aac3877aa616d9efb53496 (diff) | |
download | gnunet-c0d4d588c68154a68d5489deb2c67577eb1848c8.tar.gz gnunet-c0d4d588c68154a68d5489deb2c67577eb1848c8.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/plugin_transport_http.c | 166 |
1 files changed, 77 insertions, 89 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index dabb57a8e..8b565517e 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -69,12 +69,6 @@ | |||
69 | #define HTTP_CONNECT_TIMEOUT 30 | 69 | #define HTTP_CONNECT_TIMEOUT 30 |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * Timeout for a http connect | ||
73 | */ | ||
74 | #define HTTP_MESSAGE_INITIAL_BUFFERSIZE GNUNET_SERVER_MAX_MESSAGE_SIZE | ||
75 | |||
76 | |||
77 | /** | ||
78 | * Network format for IPv4 addresses. | 72 | * Network format for IPv4 addresses. |
79 | */ | 73 | */ |
80 | struct IPv4HttpAddress | 74 | struct IPv4HttpAddress |
@@ -109,7 +103,13 @@ struct IPv6HttpAddress | |||
109 | 103 | ||
110 | }; | 104 | }; |
111 | 105 | ||
112 | 106 | struct HTTP_inbound_transmission | |
107 | { | ||
108 | /** | ||
109 | * bytes received | ||
110 | */ | ||
111 | size_t bytes_recv; | ||
112 | }; | ||
113 | 113 | ||
114 | /** | 114 | /** |
115 | * Message to send using http | 115 | * Message to send using http |
@@ -139,7 +139,7 @@ struct HTTP_Message | |||
139 | /** | 139 | /** |
140 | * buffer length | 140 | * buffer length |
141 | */ | 141 | */ |
142 | size_t len; | 142 | size_t size; |
143 | 143 | ||
144 | char * dest_url; | 144 | char * dest_url; |
145 | 145 | ||
@@ -250,7 +250,7 @@ struct Session | |||
250 | /** | 250 | /** |
251 | * Incoming message | 251 | * Incoming message |
252 | */ | 252 | */ |
253 | struct HTTP_Message * pending_inbound_msg; | 253 | struct HTTP_inbound_transmission pending_inbound_msg; |
254 | 254 | ||
255 | /** | 255 | /** |
256 | * curl handle for outbound transmissions | 256 | * curl handle for outbound transmissions |
@@ -283,27 +283,27 @@ struct Plugin | |||
283 | /** | 283 | /** |
284 | * Daemon for listening for new IPv4 connections. | 284 | * Daemon for listening for new IPv4 connections. |
285 | */ | 285 | */ |
286 | struct MHD_Daemon *http_daemon_v4; | 286 | struct MHD_Daemon *http_server_daemon_v4; |
287 | 287 | ||
288 | /** | 288 | /** |
289 | * Daemon for listening for new IPv6connections. | 289 | * Daemon for listening for new IPv6connections. |
290 | */ | 290 | */ |
291 | struct MHD_Daemon *http_daemon_v6; | 291 | struct MHD_Daemon *http_server_daemon_v6; |
292 | 292 | ||
293 | /** | 293 | /** |
294 | * Our primary task for http daemon handling IPv4 connections | 294 | * Our primary task for http daemon handling IPv4 connections |
295 | */ | 295 | */ |
296 | GNUNET_SCHEDULER_TaskIdentifier http_task_v4; | 296 | GNUNET_SCHEDULER_TaskIdentifier http_server_task_v4; |
297 | 297 | ||
298 | /** | 298 | /** |
299 | * Our primary task for http daemon handling IPv6 connections | 299 | * Our primary task for http daemon handling IPv6 connections |
300 | */ | 300 | */ |
301 | GNUNET_SCHEDULER_TaskIdentifier http_task_v6; | 301 | GNUNET_SCHEDULER_TaskIdentifier http_server_task_v6; |
302 | 302 | ||
303 | /** | 303 | /** |
304 | * The task sending data | 304 | * The task sending data |
305 | */ | 305 | */ |
306 | GNUNET_SCHEDULER_TaskIdentifier http_task_send; | 306 | GNUNET_SCHEDULER_TaskIdentifier http_server_task_send; |
307 | 307 | ||
308 | /** | 308 | /** |
309 | * cURL Multihandle | 309 | * cURL Multihandle |
@@ -348,10 +348,7 @@ static struct Session * create_session (void * cls, char * addr_in, size_t addrl | |||
348 | memcpy(&ses->partner, peer, sizeof (struct GNUNET_PeerIdentity)); | 348 | memcpy(&ses->partner, peer, sizeof (struct GNUNET_PeerIdentity)); |
349 | GNUNET_CRYPTO_hash_to_enc(&ses->partner.hashPubKey,&(ses->hash)); | 349 | GNUNET_CRYPTO_hash_to_enc(&ses->partner.hashPubKey,&(ses->hash)); |
350 | ses->is_active = GNUNET_NO; | 350 | ses->is_active = GNUNET_NO; |
351 | ses->pending_inbound_msg = GNUNET_malloc( sizeof (struct HTTP_Message)); | 351 | ses->pending_inbound_msg.bytes_recv = 0; |
352 | ses->pending_inbound_msg->buf = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE); | ||
353 | ses->pending_inbound_msg->len = GNUNET_SERVER_MAX_MESSAGE_SIZE; | ||
354 | ses->pending_inbound_msg->pos = 0; | ||
355 | ses->msgtok = NULL; | 352 | ses->msgtok = NULL; |
356 | return ses; | 353 | return ses; |
357 | } | 354 | } |
@@ -430,13 +427,11 @@ accessHandlerCallback (void *cls, | |||
430 | char address[INET6_ADDRSTRLEN+14]; | 427 | char address[INET6_ADDRSTRLEN+14]; |
431 | struct GNUNET_PeerIdentity pi_in; | 428 | struct GNUNET_PeerIdentity pi_in; |
432 | int res = GNUNET_NO; | 429 | int res = GNUNET_NO; |
433 | struct GNUNET_MessageHeader *cur_msg; | ||
434 | int send_error_to_client; | 430 | int send_error_to_client; |
435 | struct IPv4HttpAddress ipv4addr; | 431 | struct IPv4HttpAddress ipv4addr; |
436 | struct IPv6HttpAddress ipv6addr; | 432 | struct IPv6HttpAddress ipv6addr; |
437 | 433 | ||
438 | GNUNET_assert(cls !=NULL); | 434 | GNUNET_assert(cls !=NULL); |
439 | cur_msg = NULL; | ||
440 | send_error_to_client = GNUNET_NO; | 435 | send_error_to_client = GNUNET_NO; |
441 | 436 | ||
442 | if ( NULL == *httpSessionCache) | 437 | if ( NULL == *httpSessionCache) |
@@ -525,12 +520,12 @@ accessHandlerCallback (void *cls, | |||
525 | /* New */ | 520 | /* New */ |
526 | if ((*upload_data_size == 0) && (cs->is_put_in_progress == GNUNET_NO)) | 521 | if ((*upload_data_size == 0) && (cs->is_put_in_progress == GNUNET_NO)) |
527 | { | 522 | { |
528 | if (cs->pending_inbound_msg->pos !=0 ) | 523 | if (cs->pending_inbound_msg.bytes_recv !=0 ) |
529 | { | 524 | { |
530 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 525 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
531 | _("Incoming message from peer `%s', while existing message with %u bytes was not forwarded to transport'\n"), | 526 | _("Incoming message from peer `%s', while existing message with %u bytes was not forwarded to transport'\n"), |
532 | GNUNET_i2s(&cs->partner), cs->pending_inbound_msg->pos); | 527 | GNUNET_i2s(&cs->partner), cs->pending_inbound_msg.bytes_recv); |
533 | cs->pending_inbound_msg->pos = 0; | 528 | cs->pending_inbound_msg.bytes_recv = 0; |
534 | } | 529 | } |
535 | /* not yet ready */ | 530 | /* not yet ready */ |
536 | cs->is_put_in_progress = GNUNET_YES; | 531 | cs->is_put_in_progress = GNUNET_YES; |
@@ -541,19 +536,19 @@ accessHandlerCallback (void *cls, | |||
541 | 536 | ||
542 | if ((*upload_data_size > 0) && (cs->is_bad_request != GNUNET_YES)) | 537 | if ((*upload_data_size > 0) && (cs->is_bad_request != GNUNET_YES)) |
543 | { | 538 | { |
544 | if ((*upload_data_size + cs->pending_inbound_msg->pos < cs->pending_inbound_msg->len) && (*upload_data_size + cs->pending_inbound_msg->pos <= GNUNET_SERVER_MAX_MESSAGE_SIZE)) | 539 | if (*upload_data_size + cs->pending_inbound_msg.bytes_recv <= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
545 | { | 540 | { |
546 | /* copy uploaded data to buffer */ | 541 | /* copy uploaded data to buffer */ |
547 | 542 | ||
548 | res = GNUNET_SERVER_mst_receive(cs->msgtok, cs, upload_data,*upload_data_size, GNUNET_YES, GNUNET_NO); | 543 | res = GNUNET_SERVER_mst_receive(cs->msgtok, cs, upload_data,*upload_data_size, GNUNET_YES, GNUNET_NO); |
549 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"%u bytes forwarded to MST: result: %u\n",*upload_data_size, res); | 544 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"%u bytes forwarded to MST: result: %u\n",*upload_data_size, res); |
550 | cs->pending_inbound_msg->pos += *upload_data_size; | 545 | cs->pending_inbound_msg.bytes_recv += *upload_data_size; |
551 | *upload_data_size = 0; | 546 | *upload_data_size = 0; |
552 | return MHD_YES; | 547 | return MHD_YES; |
553 | } | 548 | } |
554 | else | 549 | else |
555 | { | 550 | { |
556 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"%u bytes not added to message of %u bytes, message to big\n",*upload_data_size, cs->pending_inbound_msg->pos); | 551 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"%u bytes not added to message of %u bytes, message to big\n",*upload_data_size, cs->pending_inbound_msg.bytes_recv); |
557 | cs->is_bad_request = GNUNET_YES; | 552 | cs->is_bad_request = GNUNET_YES; |
558 | /* (*upload_data_size) bytes not processed */ | 553 | /* (*upload_data_size) bytes not processed */ |
559 | return MHD_YES; | 554 | return MHD_YES; |
@@ -570,7 +565,7 @@ accessHandlerCallback (void *cls, | |||
570 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 413 Request Entity Too Large as PUT Response\n"); | 565 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 413 Request Entity Too Large as PUT Response\n"); |
571 | cs->is_bad_request = GNUNET_NO; | 566 | cs->is_bad_request = GNUNET_NO; |
572 | cs->is_put_in_progress =GNUNET_NO; | 567 | cs->is_put_in_progress =GNUNET_NO; |
573 | cs->pending_inbound_msg->pos = 0; | 568 | cs->pending_inbound_msg.bytes_recv = 0; |
574 | } | 569 | } |
575 | MHD_destroy_response (response); | 570 | MHD_destroy_response (response); |
576 | return MHD_YES; | 571 | return MHD_YES; |
@@ -580,11 +575,9 @@ accessHandlerCallback (void *cls, | |||
580 | if ((*upload_data_size == 0) && (cs->is_put_in_progress == GNUNET_YES) && (cs->is_bad_request == GNUNET_NO)) | 575 | if ((*upload_data_size == 0) && (cs->is_put_in_progress == GNUNET_YES) && (cs->is_bad_request == GNUNET_NO)) |
581 | { | 576 | { |
582 | send_error_to_client = GNUNET_YES; | 577 | send_error_to_client = GNUNET_YES; |
583 | cur_msg = NULL; | 578 | if (cs->pending_inbound_msg.bytes_recv >= sizeof (struct GNUNET_MessageHeader)) |
584 | if (cs->pending_inbound_msg->pos >= sizeof (struct GNUNET_MessageHeader)) | ||
585 | { | 579 | { |
586 | cur_msg = (struct GNUNET_MessageHeader *) cs->pending_inbound_msg->buf; | 580 | //res = GNUNET_SERVER_mst_receive(cs->msgtok, cs, cs->pending_inbound_msg->buf,cs->pending_inbound_msg.bytes_recv, GNUNET_YES, GNUNET_NO); |
587 | //res = GNUNET_SERVER_mst_receive(cs->msgtok, cs, cs->pending_inbound_msg->buf,cs->pending_inbound_msg->pos, GNUNET_YES, GNUNET_NO); | ||
588 | res = GNUNET_OK; | 581 | res = GNUNET_OK; |
589 | if ((res != GNUNET_SYSERR) && (res != GNUNET_NO)) | 582 | if ((res != GNUNET_SYSERR) && (res != GNUNET_NO)) |
590 | send_error_to_client = GNUNET_NO; | 583 | send_error_to_client = GNUNET_NO; |
@@ -605,7 +598,7 @@ accessHandlerCallback (void *cls, | |||
605 | } | 598 | } |
606 | cs->is_put_in_progress = GNUNET_NO; | 599 | cs->is_put_in_progress = GNUNET_NO; |
607 | cs->is_bad_request = GNUNET_NO; | 600 | cs->is_bad_request = GNUNET_NO; |
608 | cs->pending_inbound_msg->pos = 0; | 601 | cs->pending_inbound_msg.bytes_recv = 0; |
609 | return res; | 602 | return res; |
610 | } | 603 | } |
611 | } | 604 | } |
@@ -626,19 +619,19 @@ accessHandlerCallback (void *cls, | |||
626 | * Call MHD to process pending ipv4 requests and then go back | 619 | * Call MHD to process pending ipv4 requests and then go back |
627 | * and schedule the next run. | 620 | * and schedule the next run. |
628 | */ | 621 | */ |
629 | static void http_daemon_v4_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 622 | static void http_server_daemon_v4_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
630 | /** | 623 | /** |
631 | * Call MHD to process pending ipv6 requests and then go back | 624 | * Call MHD to process pending ipv6 requests and then go back |
632 | * and schedule the next run. | 625 | * and schedule the next run. |
633 | */ | 626 | */ |
634 | static void http_daemon_v6_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 627 | static void http_server_daemon_v6_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
635 | 628 | ||
636 | /** | 629 | /** |
637 | * Function that queries MHD's select sets and | 630 | * Function that queries MHD's select sets and |
638 | * starts the task waiting for them. | 631 | * starts the task waiting for them. |
639 | */ | 632 | */ |
640 | static GNUNET_SCHEDULER_TaskIdentifier | 633 | static GNUNET_SCHEDULER_TaskIdentifier |
641 | http_daemon_prepare (void * cls, struct MHD_Daemon *daemon_handle) | 634 | http_server_daemon_prepare (void * cls, struct MHD_Daemon *daemon_handle) |
642 | { | 635 | { |
643 | struct Plugin *plugin = cls; | 636 | struct Plugin *plugin = cls; |
644 | GNUNET_SCHEDULER_TaskIdentifier ret; | 637 | GNUNET_SCHEDULER_TaskIdentifier ret; |
@@ -675,7 +668,7 @@ http_daemon_prepare (void * cls, struct MHD_Daemon *daemon_handle) | |||
675 | GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max); | 668 | GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max); |
676 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max); | 669 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max); |
677 | GNUNET_NETWORK_fdset_copy_native (wes, &es, max); | 670 | GNUNET_NETWORK_fdset_copy_native (wes, &es, max); |
678 | if (daemon_handle == plugin->http_daemon_v4) | 671 | if (daemon_handle == plugin->http_server_daemon_v4) |
679 | { | 672 | { |
680 | ret = GNUNET_SCHEDULER_add_select (plugin->env->sched, | 673 | ret = GNUNET_SCHEDULER_add_select (plugin->env->sched, |
681 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 674 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
@@ -683,10 +676,10 @@ http_daemon_prepare (void * cls, struct MHD_Daemon *daemon_handle) | |||
683 | tv, | 676 | tv, |
684 | wrs, | 677 | wrs, |
685 | wws, | 678 | wws, |
686 | &http_daemon_v4_run, | 679 | &http_server_daemon_v4_run, |
687 | plugin); | 680 | plugin); |
688 | } | 681 | } |
689 | if (daemon_handle == plugin->http_daemon_v6) | 682 | if (daemon_handle == plugin->http_server_daemon_v6) |
690 | { | 683 | { |
691 | ret = GNUNET_SCHEDULER_add_select (plugin->env->sched, | 684 | ret = GNUNET_SCHEDULER_add_select (plugin->env->sched, |
692 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 685 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
@@ -694,7 +687,7 @@ http_daemon_prepare (void * cls, struct MHD_Daemon *daemon_handle) | |||
694 | tv, | 687 | tv, |
695 | wrs, | 688 | wrs, |
696 | wws, | 689 | wws, |
697 | &http_daemon_v6_run, | 690 | &http_server_daemon_v6_run, |
698 | plugin); | 691 | plugin); |
699 | } | 692 | } |
700 | GNUNET_NETWORK_fdset_destroy (wrs); | 693 | GNUNET_NETWORK_fdset_destroy (wrs); |
@@ -707,20 +700,20 @@ http_daemon_prepare (void * cls, struct MHD_Daemon *daemon_handle) | |||
707 | * Call MHD to process pending requests and then go back | 700 | * Call MHD to process pending requests and then go back |
708 | * and schedule the next run. | 701 | * and schedule the next run. |
709 | */ | 702 | */ |
710 | static void http_daemon_v4_run (void *cls, | 703 | static void http_server_daemon_v4_run (void *cls, |
711 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 704 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
712 | { | 705 | { |
713 | struct Plugin *plugin = cls; | 706 | struct Plugin *plugin = cls; |
714 | 707 | ||
715 | GNUNET_assert(cls !=NULL); | 708 | GNUNET_assert(cls !=NULL); |
716 | if (plugin->http_task_v4 != GNUNET_SCHEDULER_NO_TASK) | 709 | if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK) |
717 | plugin->http_task_v4 = GNUNET_SCHEDULER_NO_TASK; | 710 | plugin->http_server_task_v4 = GNUNET_SCHEDULER_NO_TASK; |
718 | 711 | ||
719 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 712 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
720 | return; | 713 | return; |
721 | 714 | ||
722 | GNUNET_assert (MHD_YES == MHD_run (plugin->http_daemon_v4)); | 715 | GNUNET_assert (MHD_YES == MHD_run (plugin->http_server_daemon_v4)); |
723 | plugin->http_task_v4 = http_daemon_prepare (plugin, plugin->http_daemon_v4); | 716 | plugin->http_server_task_v4 = http_server_daemon_prepare (plugin, plugin->http_server_daemon_v4); |
724 | return; | 717 | return; |
725 | } | 718 | } |
726 | 719 | ||
@@ -729,20 +722,20 @@ static void http_daemon_v4_run (void *cls, | |||
729 | * Call MHD to process pending requests and then go back | 722 | * Call MHD to process pending requests and then go back |
730 | * and schedule the next run. | 723 | * and schedule the next run. |
731 | */ | 724 | */ |
732 | static void http_daemon_v6_run (void *cls, | 725 | static void http_server_daemon_v6_run (void *cls, |
733 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 726 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
734 | { | 727 | { |
735 | struct Plugin *plugin = cls; | 728 | struct Plugin *plugin = cls; |
736 | 729 | ||
737 | GNUNET_assert(cls !=NULL); | 730 | GNUNET_assert(cls !=NULL); |
738 | if (plugin->http_task_v6 != GNUNET_SCHEDULER_NO_TASK) | 731 | if (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) |
739 | plugin->http_task_v6 = GNUNET_SCHEDULER_NO_TASK; | 732 | plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK; |
740 | 733 | ||
741 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 734 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
742 | return; | 735 | return; |
743 | 736 | ||
744 | GNUNET_assert (MHD_YES == MHD_run (plugin->http_daemon_v6)); | 737 | GNUNET_assert (MHD_YES == MHD_run (plugin->http_server_daemon_v6)); |
745 | plugin->http_task_v6 = http_daemon_prepare (plugin, plugin->http_daemon_v6); | 738 | plugin->http_server_task_v6 = http_server_daemon_prepare (plugin, plugin->http_server_daemon_v6); |
746 | return; | 739 | return; |
747 | } | 740 | } |
748 | 741 | ||
@@ -755,10 +748,9 @@ static void http_daemon_v6_run (void *cls, | |||
755 | 748 | ||
756 | static int remove_http_message(struct Session * ses, struct HTTP_Message * msg) | 749 | static int remove_http_message(struct Session * ses, struct HTTP_Message * msg) |
757 | { | 750 | { |
758 | GNUNET_free (msg->buf); | ||
759 | GNUNET_free (msg->dest_url); | ||
760 | |||
761 | GNUNET_CONTAINER_DLL_remove(ses->pending_outbound_msg_head,ses->pending_outbound_msg_tail,msg); | 751 | GNUNET_CONTAINER_DLL_remove(ses->pending_outbound_msg_head,ses->pending_outbound_msg_tail,msg); |
752 | GNUNET_free (msg->dest_url); | ||
753 | GNUNET_free(msg); | ||
762 | return GNUNET_OK; | 754 | return GNUNET_OK; |
763 | } | 755 | } |
764 | 756 | ||
@@ -807,12 +799,12 @@ static size_t send_read_callback(void *stream, size_t size, size_t nmemb, void * | |||
807 | size_t len; | 799 | size_t len; |
808 | 800 | ||
809 | /* data to send */ | 801 | /* data to send */ |
810 | if (( msg->pos < msg->len)) | 802 | if (( msg->pos < msg->size)) |
811 | { | 803 | { |
812 | /* data fit in buffer */ | 804 | /* data fit in buffer */ |
813 | if ((msg->len - msg->pos) <= (size * nmemb)) | 805 | if ((msg->size - msg->pos) <= (size * nmemb)) |
814 | { | 806 | { |
815 | len = (msg->len - msg->pos); | 807 | len = (msg->size - msg->pos); |
816 | memcpy(stream, &msg->buf[msg->pos], len); | 808 | memcpy(stream, &msg->buf[msg->pos], len); |
817 | msg->pos += len; | 809 | msg->pos += len; |
818 | bytes_sent = len; | 810 | bytes_sent = len; |
@@ -899,7 +891,7 @@ static ssize_t send_select_init (void *cls, struct Session* ses ) | |||
899 | curl_easy_setopt(ses->curl_handle, CURLOPT_READDATA, ses); | 891 | curl_easy_setopt(ses->curl_handle, CURLOPT_READDATA, ses); |
900 | curl_easy_setopt(ses->curl_handle, CURLOPT_WRITEFUNCTION, send_write_callback); | 892 | curl_easy_setopt(ses->curl_handle, CURLOPT_WRITEFUNCTION, send_write_callback); |
901 | curl_easy_setopt(ses->curl_handle, CURLOPT_READDATA, ses); | 893 | curl_easy_setopt(ses->curl_handle, CURLOPT_READDATA, ses); |
902 | curl_easy_setopt(ses->curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) msg->len); | 894 | curl_easy_setopt(ses->curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) msg->size); |
903 | curl_easy_setopt(ses->curl_handle, CURLOPT_TIMEOUT, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 895 | curl_easy_setopt(ses->curl_handle, CURLOPT_TIMEOUT, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
904 | GNUNET_assert (CURLE_OK == curl_easy_setopt(ses->curl_handle, CURLOPT_PRIVATE, ses)); | 896 | GNUNET_assert (CURLE_OK == curl_easy_setopt(ses->curl_handle, CURLOPT_PRIVATE, ses)); |
905 | curl_easy_setopt(ses->curl_handle, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT); | 897 | curl_easy_setopt(ses->curl_handle, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT); |
@@ -930,7 +922,7 @@ static void send_execute (void *cls, | |||
930 | long http_result; | 922 | long http_result; |
931 | 923 | ||
932 | GNUNET_assert(cls !=NULL); | 924 | GNUNET_assert(cls !=NULL); |
933 | plugin->http_task_send = GNUNET_SCHEDULER_NO_TASK; | 925 | plugin->http_server_task_send = GNUNET_SCHEDULER_NO_TASK; |
934 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 926 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
935 | return; | 927 | return; |
936 | 928 | ||
@@ -1061,7 +1053,7 @@ static size_t send_prepare(void *cls, struct Session* ses ) | |||
1061 | gws = GNUNET_NETWORK_fdset_create (); | 1053 | gws = GNUNET_NETWORK_fdset_create (); |
1062 | GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); | 1054 | GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); |
1063 | GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); | 1055 | GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); |
1064 | plugin->http_task_send = GNUNET_SCHEDULER_add_select (plugin->env->sched, | 1056 | plugin->http_server_task_send = GNUNET_SCHEDULER_add_select (plugin->env->sched, |
1065 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 1057 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
1066 | GNUNET_SCHEDULER_NO_TASK, | 1058 | GNUNET_SCHEDULER_NO_TASK, |
1067 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 0), | 1059 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 0), |
@@ -1169,11 +1161,11 @@ http_plugin_send (void *cls, | |||
1169 | } | 1161 | } |
1170 | 1162 | ||
1171 | /* setting up message */ | 1163 | /* setting up message */ |
1172 | msg = GNUNET_malloc (sizeof (struct HTTP_Message)); | 1164 | msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size); |
1173 | msg->next = NULL; | 1165 | msg->next = NULL; |
1174 | msg->len = msgbuf_size; | 1166 | msg->size = msgbuf_size; |
1175 | msg->pos = 0; | 1167 | msg->pos = 0; |
1176 | msg->buf = GNUNET_malloc (msgbuf_size); | 1168 | msg->buf = (char *) &msg[1]; |
1177 | msg->dest_url = url; | 1169 | msg->dest_url = url; |
1178 | msg->transmit_cont = cont; | 1170 | msg->transmit_cont = cont; |
1179 | msg->transmit_cont_cls = cont_cls; | 1171 | msg->transmit_cont_cls = cont_cls; |
@@ -1469,17 +1461,13 @@ int hashMapFreeIterator (void *cls, const GNUNET_HashCode *key, void *value) | |||
1469 | { | 1461 | { |
1470 | tmp = cur->next; | 1462 | tmp = cur->next; |
1471 | GNUNET_free_non_null(cur->dest_url); | 1463 | GNUNET_free_non_null(cur->dest_url); |
1472 | GNUNET_free_non_null (cur->buf); | ||
1473 | GNUNET_free (cur); | 1464 | GNUNET_free (cur); |
1474 | cur = tmp; | 1465 | cur = tmp; |
1475 | } | 1466 | } |
1476 | GNUNET_SERVER_mst_destroy (cs->msgtok); | 1467 | GNUNET_SERVER_mst_destroy (cs->msgtok); |
1477 | GNUNET_free (cs->pending_inbound_msg->buf); | ||
1478 | GNUNET_free (cs->pending_inbound_msg); | ||
1479 | GNUNET_free_non_null (cs->addr_in); | 1468 | GNUNET_free_non_null (cs->addr_in); |
1480 | GNUNET_free_non_null (cs->addr_out); | 1469 | GNUNET_free_non_null (cs->addr_out); |
1481 | GNUNET_free (cs); | 1470 | GNUNET_free (cs); |
1482 | |||
1483 | return GNUNET_YES; | 1471 | return GNUNET_YES; |
1484 | } | 1472 | } |
1485 | 1473 | ||
@@ -1496,33 +1484,33 @@ libgnunet_plugin_transport_http_done (void *cls) | |||
1496 | GNUNET_assert(cls !=NULL); | 1484 | GNUNET_assert(cls !=NULL); |
1497 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Unloading http plugin...\n"); | 1485 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Unloading http plugin...\n"); |
1498 | 1486 | ||
1499 | if ( plugin->http_task_v4 != GNUNET_SCHEDULER_NO_TASK) | 1487 | if ( plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK) |
1500 | { | 1488 | { |
1501 | GNUNET_SCHEDULER_cancel(plugin->env->sched, plugin->http_task_v4); | 1489 | GNUNET_SCHEDULER_cancel(plugin->env->sched, plugin->http_server_task_v4); |
1502 | plugin->http_task_v4 = GNUNET_SCHEDULER_NO_TASK; | 1490 | plugin->http_server_task_v4 = GNUNET_SCHEDULER_NO_TASK; |
1503 | } | 1491 | } |
1504 | 1492 | ||
1505 | if ( plugin->http_task_v6 != GNUNET_SCHEDULER_NO_TASK) | 1493 | if ( plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) |
1506 | { | 1494 | { |
1507 | GNUNET_SCHEDULER_cancel(plugin->env->sched, plugin->http_task_v6); | 1495 | GNUNET_SCHEDULER_cancel(plugin->env->sched, plugin->http_server_task_v6); |
1508 | plugin->http_task_v6 = GNUNET_SCHEDULER_NO_TASK; | 1496 | plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK; |
1509 | } | 1497 | } |
1510 | 1498 | ||
1511 | if ( plugin->http_task_send != GNUNET_SCHEDULER_NO_TASK) | 1499 | if ( plugin->http_server_task_send != GNUNET_SCHEDULER_NO_TASK) |
1512 | { | 1500 | { |
1513 | GNUNET_SCHEDULER_cancel(plugin->env->sched, plugin->http_task_send); | 1501 | GNUNET_SCHEDULER_cancel(plugin->env->sched, plugin->http_server_task_send); |
1514 | plugin->http_task_send = GNUNET_SCHEDULER_NO_TASK; | 1502 | plugin->http_server_task_send = GNUNET_SCHEDULER_NO_TASK; |
1515 | } | 1503 | } |
1516 | 1504 | ||
1517 | if (plugin->http_daemon_v4 != NULL) | 1505 | if (plugin->http_server_daemon_v4 != NULL) |
1518 | { | 1506 | { |
1519 | MHD_stop_daemon (plugin->http_daemon_v4); | 1507 | MHD_stop_daemon (plugin->http_server_daemon_v4); |
1520 | plugin->http_daemon_v4 = NULL; | 1508 | plugin->http_server_daemon_v4 = NULL; |
1521 | } | 1509 | } |
1522 | if (plugin->http_daemon_v6 != NULL) | 1510 | if (plugin->http_server_daemon_v6 != NULL) |
1523 | { | 1511 | { |
1524 | MHD_stop_daemon (plugin->http_daemon_v6); | 1512 | MHD_stop_daemon (plugin->http_server_daemon_v6); |
1525 | plugin->http_daemon_v6 = NULL; | 1513 | plugin->http_server_daemon_v6 = NULL; |
1526 | } | 1514 | } |
1527 | 1515 | ||
1528 | /* free all sessions */ | 1516 | /* free all sessions */ |
@@ -1590,9 +1578,9 @@ libgnunet_plugin_transport_http_init (void *cls) | |||
1590 | GNUNET_assert ((port > 0) && (port <= 65535)); | 1578 | GNUNET_assert ((port > 0) && (port <= 65535)); |
1591 | plugin->port_inbound = port; | 1579 | plugin->port_inbound = port; |
1592 | gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; | 1580 | gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; |
1593 | if ((plugin->http_daemon_v4 == NULL) && (plugin->http_daemon_v6 == NULL) && (port != 0)) | 1581 | if ((plugin->http_server_daemon_v4 == NULL) && (plugin->http_server_daemon_v6 == NULL) && (port != 0)) |
1594 | { | 1582 | { |
1595 | plugin->http_daemon_v6 = MHD_start_daemon (MHD_USE_IPv6, | 1583 | plugin->http_server_daemon_v6 = MHD_start_daemon (MHD_USE_IPv6, |
1596 | port, | 1584 | port, |
1597 | &acceptPolicyCallback, | 1585 | &acceptPolicyCallback, |
1598 | plugin , &accessHandlerCallback, plugin, | 1586 | plugin , &accessHandlerCallback, plugin, |
@@ -1602,7 +1590,7 @@ libgnunet_plugin_transport_http_init (void *cls) | |||
1602 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (16 * 1024), | 1590 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (16 * 1024), |
1603 | MHD_OPTION_NOTIFY_COMPLETED, &requestCompletedCallback, NULL, | 1591 | MHD_OPTION_NOTIFY_COMPLETED, &requestCompletedCallback, NULL, |
1604 | MHD_OPTION_END); | 1592 | MHD_OPTION_END); |
1605 | plugin->http_daemon_v4 = MHD_start_daemon (MHD_NO_FLAG, | 1593 | plugin->http_server_daemon_v4 = MHD_start_daemon (MHD_NO_FLAG, |
1606 | port, | 1594 | port, |
1607 | &acceptPolicyCallback, | 1595 | &acceptPolicyCallback, |
1608 | plugin , &accessHandlerCallback, plugin, | 1596 | plugin , &accessHandlerCallback, plugin, |
@@ -1613,14 +1601,14 @@ libgnunet_plugin_transport_http_init (void *cls) | |||
1613 | MHD_OPTION_NOTIFY_COMPLETED, &requestCompletedCallback, NULL, | 1601 | MHD_OPTION_NOTIFY_COMPLETED, &requestCompletedCallback, NULL, |
1614 | MHD_OPTION_END); | 1602 | MHD_OPTION_END); |
1615 | } | 1603 | } |
1616 | if (plugin->http_daemon_v4 != NULL) | 1604 | if (plugin->http_server_daemon_v4 != NULL) |
1617 | plugin->http_task_v4 = http_daemon_prepare (plugin, plugin->http_daemon_v4); | 1605 | plugin->http_server_task_v4 = http_server_daemon_prepare (plugin, plugin->http_server_daemon_v4); |
1618 | if (plugin->http_daemon_v6 != NULL) | 1606 | if (plugin->http_server_daemon_v6 != NULL) |
1619 | plugin->http_task_v6 = http_daemon_prepare (plugin, plugin->http_daemon_v6); | 1607 | plugin->http_server_task_v6 = http_server_daemon_prepare (plugin, plugin->http_server_daemon_v6); |
1620 | 1608 | ||
1621 | if (plugin->http_task_v4 != GNUNET_SCHEDULER_NO_TASK) | 1609 | if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK) |
1622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 on port %u\n",port); | 1610 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 on port %u\n",port); |
1623 | else if (plugin->http_task_v6 != GNUNET_SCHEDULER_NO_TASK) | 1611 | else if (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) |
1624 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 and IPv6 on port %u\n",port); | 1612 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 and IPv6 on port %u\n",port); |
1625 | else | 1613 | else |
1626 | { | 1614 | { |