diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-07-02 14:29:34 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-07-02 14:29:34 +0000 |
commit | 48a0d4e417159e92ae9396595ae42dac27f9dd47 (patch) | |
tree | 41f62687c0d90f04fa2860eb24c98add540892e8 /src/transport/plugin_transport_http.c | |
parent | 2bb0569cbeba81e8742a6852acd68b07e3e4a41b (diff) | |
download | gnunet-48a0d4e417159e92ae9396595ae42dac27f9dd47.tar.gz gnunet-48a0d4e417159e92ae9396595ae42dac27f9dd47.zip |
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r-- | src/transport/plugin_transport_http.c | 85 |
1 files changed, 49 insertions, 36 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 19205f8bd..5a9bde0bc 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -42,7 +42,7 @@ | |||
42 | 42 | ||
43 | 43 | ||
44 | #define DEBUG_CURL GNUNET_YES | 44 | #define DEBUG_CURL GNUNET_YES |
45 | #define DEBUG_HTTP GNUNET_YES | 45 | #define DEBUG_HTTP GNUNET_NO |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Text of the response sent back after the last bytes of a PUT | 48 | * Text of the response sent back after the last bytes of a PUT |
@@ -448,6 +448,20 @@ static char * create_url(void * cls, const void * addr, size_t addrlen) | |||
448 | } | 448 | } |
449 | 449 | ||
450 | /** | 450 | /** |
451 | * Removes a message from the linked list of messages | ||
452 | * @param con connection to remove message from | ||
453 | * @param msg message to remove | ||
454 | * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success | ||
455 | */ | ||
456 | |||
457 | static int remove_http_message(struct HTTP_Connection * con, struct HTTP_Message * msg) | ||
458 | { | ||
459 | GNUNET_CONTAINER_DLL_remove(con->pending_msgs_head,con->pending_msgs_tail,msg); | ||
460 | GNUNET_free(msg); | ||
461 | return GNUNET_OK; | ||
462 | } | ||
463 | |||
464 | /** | ||
451 | * Check if session already knows this address for a outbound connection to this peer | 465 | * Check if session already knows this address for a outbound connection to this peer |
452 | * If address not in session, add it to the session | 466 | * If address not in session, add it to the session |
453 | * @param cls the plugin used | 467 | * @param cls the plugin used |
@@ -597,16 +611,32 @@ acceptPolicyCallback (void *cls, | |||
597 | 611 | ||
598 | int server_read_callback (void *cls, uint64_t pos, char *buf, int max) | 612 | int server_read_callback (void *cls, uint64_t pos, char *buf, int max) |
599 | { | 613 | { |
600 | static int i = 0; | 614 | int bytes_read = 0; |
615 | |||
616 | struct HTTP_Connection * con = cls; | ||
617 | struct HTTP_Message * msg; | ||
618 | int res; | ||
601 | 619 | ||
602 | char * test ="Hello World!"; | 620 | if (con->pending_msgs_tail!=NULL) |
603 | int bytes_read = -1; | ||
604 | if (i<10) | ||
605 | { | 621 | { |
606 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server_read_callback\n"); | 622 | msg=con->pending_msgs_tail; |
607 | memcpy(buf,test,strlen(test)); | 623 | /* |
608 | bytes_read = strlen(test); | 624 | if ((msg->size-msg->pos) <= max) |
609 | i++; | 625 | { |
626 | memcpy(buf,&msg->buf[pos],(msg->size-msg->pos)); | ||
627 | pos+=(msg->size-msg->pos); | ||
628 | } | ||
629 | else | ||
630 | { | ||
631 | memcpy(buf,&msg->buf[pos],max); | ||
632 | pos+=max; | ||
633 | }*/ | ||
634 | if (msg->pos==msg->size) | ||
635 | { | ||
636 | if (NULL != con->pending_msgs_tail->transmit_cont) | ||
637 | msg->transmit_cont (msg->transmit_cont_cls,&con->session->identity,GNUNET_SYSERR); | ||
638 | res = remove_http_message(con,msg); | ||
639 | } | ||
610 | } | 640 | } |
611 | return bytes_read; | 641 | return bytes_read; |
612 | } | 642 | } |
@@ -736,7 +766,7 @@ accessHandlerCallback (void *cls, | |||
736 | } | 766 | } |
737 | if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) ) | 767 | if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) ) |
738 | { | 768 | { |
739 | response = MHD_create_response_from_callback(-1,32 * 1024, &server_read_callback, cs, NULL); | 769 | response = MHD_create_response_from_callback(-1,32 * 1024, &server_read_callback, con, NULL); |
740 | res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); | 770 | res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); |
741 | MHD_destroy_response (response); | 771 | MHD_destroy_response (response); |
742 | 772 | ||
@@ -878,20 +908,6 @@ static void http_server_daemon_v6_run (void *cls, | |||
878 | return; | 908 | return; |
879 | } | 909 | } |
880 | 910 | ||
881 | /** | ||
882 | * Removes a message from the linked list of messages | ||
883 | * @param con connection to remove message from | ||
884 | * @param msg message to remove | ||
885 | * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success | ||
886 | */ | ||
887 | |||
888 | static int remove_http_message(struct HTTP_Connection * con, struct HTTP_Message * msg) | ||
889 | { | ||
890 | GNUNET_CONTAINER_DLL_remove(con->pending_msgs_head,con->pending_msgs_tail,msg); | ||
891 | GNUNET_free(msg); | ||
892 | return GNUNET_OK; | ||
893 | } | ||
894 | |||
895 | 911 | ||
896 | static size_t curl_header_function( void *ptr, size_t size, size_t nmemb, void *stream) | 912 | static size_t curl_header_function( void *ptr, size_t size, size_t nmemb, void *stream) |
897 | { | 913 | { |
@@ -903,20 +919,17 @@ static size_t curl_header_function( void *ptr, size_t size, size_t nmemb, void * | |||
903 | int res; | 919 | int res; |
904 | 920 | ||
905 | /* Getting last http result code */ | 921 | /* Getting last http result code */ |
906 | GNUNET_assert(NULL!=con); | 922 | if (con->get_connected==GNUNET_NO) |
907 | res = curl_easy_getinfo(con->get_curl_handle, CURLINFO_RESPONSE_CODE, &http_result); | ||
908 | |||
909 | if ((CURLE_OK == res) && (con->get_connected==GNUNET_NO)) | ||
910 | { | 923 | { |
911 | if (http_result == 200) | 924 | GNUNET_assert(NULL!=con); |
925 | res = curl_easy_getinfo(con->get_curl_handle, CURLINFO_RESPONSE_CODE, &http_result); | ||
926 | if (CURLE_OK == res) | ||
912 | { | 927 | { |
913 | con->get_connected = GNUNET_YES; | 928 | if (http_result == 200) |
914 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: inbound connected\n",con); | 929 | { |
915 | } | 930 | con->get_connected = GNUNET_YES; |
916 | else | 931 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: inbound connected\n",con); |
917 | { | 932 | } |
918 | con->get_connected = GNUNET_NO; | ||
919 | //GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: inbound connected\n",con); | ||
920 | } | 933 | } |
921 | } | 934 | } |
922 | 935 | ||