diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-07-02 12:07:23 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-07-02 12:07:23 +0000 |
commit | 241ddc96d9d74aeb1dae8e263661490cba0510c8 (patch) | |
tree | 6f85d0df0c048dc8725f2e6aee3289b5a3191c24 /src/transport/plugin_transport_http.c | |
parent | e3cfaa841943326b1527afcc9dacf263fcf77f73 (diff) | |
download | gnunet-241ddc96d9d74aeb1dae8e263661490cba0510c8.tar.gz gnunet-241ddc96d9d74aeb1dae8e263661490cba0510c8.zip |
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r-- | src/transport/plugin_transport_http.c | 262 |
1 files changed, 150 insertions, 112 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index baf063ea6..934432abe 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -149,11 +149,11 @@ struct HTTP_Message | |||
149 | }; | 149 | }; |
150 | 150 | ||
151 | 151 | ||
152 | struct HTTP_Connection_out | 152 | struct HTTP_Connection |
153 | { | 153 | { |
154 | struct HTTP_Connection_out * next; | 154 | struct HTTP_Connection * next; |
155 | 155 | ||
156 | struct HTTP_Connection_out * prev; | 156 | struct HTTP_Connection * prev; |
157 | 157 | ||
158 | void * addr; | 158 | void * addr; |
159 | size_t addrlen; | 159 | size_t addrlen; |
@@ -209,7 +209,6 @@ struct HTTP_Connection_in | |||
209 | int is_bad_request; | 209 | int is_bad_request; |
210 | }; | 210 | }; |
211 | 211 | ||
212 | |||
213 | /** | 212 | /** |
214 | * Session handle for connections. | 213 | * Session handle for connections. |
215 | */ | 214 | */ |
@@ -285,8 +284,8 @@ struct Session | |||
285 | */ | 284 | */ |
286 | //struct GNUNET_SERVER_MessageStreamTokenizer * msgtok; | 285 | //struct GNUNET_SERVER_MessageStreamTokenizer * msgtok; |
287 | 286 | ||
288 | struct HTTP_Connection_out *outbound_connections_head; | 287 | struct HTTP_Connection *outbound_connections_head; |
289 | struct HTTP_Connection_out *outbound_connections_tail; | 288 | struct HTTP_Connection *outbound_connections_tail; |
290 | 289 | ||
291 | struct HTTP_Connection_in *inbound_connections_head; | 290 | struct HTTP_Connection_in *inbound_connections_head; |
292 | struct HTTP_Connection_in *inbound_connections_tail; | 291 | struct HTTP_Connection_in *inbound_connections_tail; |
@@ -456,11 +455,11 @@ static char * create_url(void * cls, const void * addr, size_t addrlen) | |||
456 | * @param addr_len address length | 455 | * @param addr_len address length |
457 | * @return the found or created address | 456 | * @return the found or created address |
458 | */ | 457 | */ |
459 | static struct HTTP_Connection_out * session_check_outbound_address (void * cls, struct Session *cs, const void * addr, size_t addr_len) | 458 | static struct HTTP_Connection * session_check_outbound_address (void * cls, struct Session *cs, const void * addr, size_t addr_len) |
460 | { | 459 | { |
461 | struct Plugin *plugin = cls; | 460 | struct Plugin *plugin = cls; |
462 | struct HTTP_Connection_out * cc = cs->outbound_connections_head; | 461 | struct HTTP_Connection * cc = cs->outbound_connections_head; |
463 | struct HTTP_Connection_out * con = NULL; | 462 | struct HTTP_Connection * con = NULL; |
464 | 463 | ||
465 | GNUNET_assert((addr_len == sizeof (struct IPv4HttpAddress)) || (addr_len == sizeof (struct IPv6HttpAddress))); | 464 | GNUNET_assert((addr_len == sizeof (struct IPv4HttpAddress)) || (addr_len == sizeof (struct IPv6HttpAddress))); |
466 | 465 | ||
@@ -479,7 +478,7 @@ static struct HTTP_Connection_out * session_check_outbound_address (void * cls, | |||
479 | 478 | ||
480 | if (con==NULL) | 479 | if (con==NULL) |
481 | { | 480 | { |
482 | con = GNUNET_malloc(sizeof(struct HTTP_Connection_out) + addr_len); | 481 | con = GNUNET_malloc(sizeof(struct HTTP_Connection) + addr_len); |
483 | con->addrlen = addr_len; | 482 | con->addrlen = addr_len; |
484 | con->addr=&con[1]; | 483 | con->addr=&con[1]; |
485 | con->url=create_url(plugin, addr, addr_len); | 484 | con->url=create_url(plugin, addr, addr_len); |
@@ -597,8 +596,17 @@ acceptPolicyCallback (void *cls, | |||
597 | 596 | ||
598 | int server_read_callback (void *cls, uint64_t pos, char *buf, int max) | 597 | int server_read_callback (void *cls, uint64_t pos, char *buf, int max) |
599 | { | 598 | { |
599 | static int i = 0; | ||
600 | |||
601 | char * test ="Hello World!"; | ||
600 | int bytes_read = -1; | 602 | int bytes_read = -1; |
601 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server_read_callback\n"); | 603 | if (i==0) |
604 | { | ||
605 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server_read_callback\n"); | ||
606 | memcpy(buf,test,strlen(test)); | ||
607 | bytes_read = strlen(test); | ||
608 | i++; | ||
609 | } | ||
602 | return bytes_read; | 610 | return bytes_read; |
603 | } | 611 | } |
604 | 612 | ||
@@ -695,8 +703,6 @@ accessHandlerCallback (void *cls, | |||
695 | /* Is it a PUT or a GET request */ | 703 | /* Is it a PUT or a GET request */ |
696 | if (0 == strcmp (MHD_HTTP_METHOD_PUT, method)) | 704 | if (0 == strcmp (MHD_HTTP_METHOD_PUT, method)) |
697 | { | 705 | { |
698 | |||
699 | |||
700 | if ((*upload_data_size == 0) && (con->is_put_in_progress==GNUNET_NO)) | 706 | if ((*upload_data_size == 0) && (con->is_put_in_progress==GNUNET_NO)) |
701 | { | 707 | { |
702 | con->is_put_in_progress = GNUNET_YES; | 708 | con->is_put_in_progress = GNUNET_YES; |
@@ -729,26 +735,8 @@ accessHandlerCallback (void *cls, | |||
729 | } | 735 | } |
730 | if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) ) | 736 | if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) ) |
731 | { | 737 | { |
732 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Got GET Request\n"); | ||
733 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"URL: `%s'\n",url); | ||
734 | |||
735 | /* check url for peer identity , if invalid send HTTP 404*/ | ||
736 | res = GNUNET_CRYPTO_hash_from_string ( &url[1], &(pi_in.hashPubKey)); | ||
737 | |||
738 | if ( GNUNET_SYSERR == res ) | ||
739 | { | ||
740 | response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO); | ||
741 | res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response); | ||
742 | MHD_destroy_response (response); | ||
743 | if (res == MHD_YES) | ||
744 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer has no valid ident, sent HTTP 1.1/404\n"); | ||
745 | else | ||
746 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer has no valid ident, could not send error\n"); | ||
747 | return res; | ||
748 | } | ||
749 | |||
750 | response = MHD_create_response_from_callback(-1,32 * 1024, &server_read_callback, cs, NULL); | 738 | response = MHD_create_response_from_callback(-1,32 * 1024, &server_read_callback, cs, NULL); |
751 | res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response); | 739 | res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); |
752 | MHD_destroy_response (response); | 740 | MHD_destroy_response (response); |
753 | 741 | ||
754 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has new an incoming `%s' request from peer `%s' (`%s')\n", | 742 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has new an incoming `%s' request from peer `%s' (`%s')\n", |
@@ -756,6 +744,7 @@ accessHandlerCallback (void *cls, | |||
756 | GNUNET_i2s(&cs->identity), | 744 | GNUNET_i2s(&cs->identity), |
757 | http_plugin_address_to_string(NULL, con->addr, con->addrlen)); | 745 | http_plugin_address_to_string(NULL, con->addr, con->addrlen)); |
758 | 746 | ||
747 | |||
759 | return res; | 748 | return res; |
760 | 749 | ||
761 | } | 750 | } |
@@ -895,7 +884,7 @@ static void http_server_daemon_v6_run (void *cls, | |||
895 | * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success | 884 | * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success |
896 | */ | 885 | */ |
897 | 886 | ||
898 | static int remove_http_message(struct HTTP_Connection_out * con, struct HTTP_Message * msg) | 887 | static int remove_http_message(struct HTTP_Connection * con, struct HTTP_Message * msg) |
899 | { | 888 | { |
900 | GNUNET_CONTAINER_DLL_remove(con->pending_msgs_head,con->pending_msgs_tail,msg); | 889 | GNUNET_CONTAINER_DLL_remove(con->pending_msgs_head,con->pending_msgs_tail,msg); |
901 | GNUNET_free(msg); | 890 | GNUNET_free(msg); |
@@ -905,8 +894,27 @@ static int remove_http_message(struct HTTP_Connection_out * con, struct HTTP_Mes | |||
905 | 894 | ||
906 | static size_t header_function( void *ptr, size_t size, size_t nmemb, void *stream) | 895 | static size_t header_function( void *ptr, size_t size, size_t nmemb, void *stream) |
907 | { | 896 | { |
897 | struct HTTP_Connection * con = stream; | ||
898 | |||
908 | char * tmp; | 899 | char * tmp; |
909 | size_t len = size * nmemb; | 900 | size_t len = size * nmemb; |
901 | int http_result; | ||
902 | |||
903 | /* Getting last http result code */ | ||
904 | if (CURLE_OK == curl_easy_getinfo(con->get_curl_handle, CURLINFO_RESPONSE_CODE, &http_result)) | ||
905 | { | ||
906 | if (http_result == 200) | ||
907 | { | ||
908 | con->get_connected = GNUNET_YES; | ||
909 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: inbound connected\n",con); | ||
910 | } | ||
911 | else | ||
912 | { | ||
913 | con->get_connected = GNUNET_NO; | ||
914 | //GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: inbound connected\n",con); | ||
915 | } | ||
916 | } | ||
917 | |||
910 | 918 | ||
911 | tmp = NULL; | 919 | tmp = NULL; |
912 | if ((size * nmemb) < SIZE_MAX) | 920 | if ((size * nmemb) < SIZE_MAX) |
@@ -921,7 +929,7 @@ static size_t header_function( void *ptr, size_t size, size_t nmemb, void *strea | |||
921 | tmp[len-2]= '\0'; | 929 | tmp[len-2]= '\0'; |
922 | } | 930 | } |
923 | #if DEBUG_HTTP | 931 | #if DEBUG_HTTP |
924 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s'\n",tmp); | 932 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s' %u \n",tmp, http_result); |
925 | #endif | 933 | #endif |
926 | } | 934 | } |
927 | if (NULL != tmp) | 935 | if (NULL != tmp) |
@@ -941,7 +949,7 @@ static size_t header_function( void *ptr, size_t size, size_t nmemb, void *strea | |||
941 | */ | 949 | */ |
942 | static size_t send_read_callback(void *stream, size_t size, size_t nmemb, void *ptr) | 950 | static size_t send_read_callback(void *stream, size_t size, size_t nmemb, void *ptr) |
943 | { | 951 | { |
944 | struct HTTP_Connection_out * con = ptr; | 952 | struct HTTP_Connection * con = ptr; |
945 | struct HTTP_Message * msg = con->pending_msgs_tail; | 953 | struct HTTP_Message * msg = con->pending_msgs_tail; |
946 | size_t bytes_sent; | 954 | size_t bytes_sent; |
947 | size_t len; | 955 | size_t len; |
@@ -999,16 +1007,17 @@ static size_t send_read_callback(void *stream, size_t size, size_t nmemb, void * | |||
999 | * @param ptr destination pointer, passed to the libcurl handle | 1007 | * @param ptr destination pointer, passed to the libcurl handle |
1000 | * @return bytes read from stream | 1008 | * @return bytes read from stream |
1001 | */ | 1009 | */ |
1002 | static size_t send_write_callback( void *stream, size_t size, size_t nmemb, void *ptr) | 1010 | static size_t send_curl_write_callback( void *stream, size_t size, size_t nmemb, void *ptr) |
1003 | { | 1011 | { |
1012 | struct HTTP_Connection * con = ptr; | ||
1004 | char * data = NULL; | 1013 | char * data = NULL; |
1005 | 1014 | ||
1006 | if ((size * nmemb) < SIZE_MAX) | 1015 | data = GNUNET_malloc(size*nmemb +1); |
1007 | data = GNUNET_malloc(size*nmemb +1); | ||
1008 | if (data != NULL) | 1016 | if (data != NULL) |
1009 | { | 1017 | { |
1010 | memcpy( data, stream, size*nmemb); | 1018 | memcpy( data, stream, size*nmemb); |
1011 | data[size*nmemb] = '\0'; | 1019 | data[size*nmemb] = '\0'; |
1020 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: recieved %s\n",con,data); | ||
1012 | free (data); | 1021 | free (data); |
1013 | } | 1022 | } |
1014 | return (size * nmemb); | 1023 | return (size * nmemb); |
@@ -1032,7 +1041,7 @@ static size_t send_schedule(void *cls, struct Session* ses ); | |||
1032 | * @param con connection | 1041 | * @param con connection |
1033 | * @return bytes sent to peer | 1042 | * @return bytes sent to peer |
1034 | */ | 1043 | */ |
1035 | static ssize_t send_initiate (void *cls, struct Session* ses , struct HTTP_Connection_out *con) | 1044 | static ssize_t send_check_connections (void *cls, struct Session* ses , struct HTTP_Connection *con) |
1036 | { | 1045 | { |
1037 | struct Plugin *plugin = cls; | 1046 | struct Plugin *plugin = cls; |
1038 | int bytes_sent = 0; | 1047 | int bytes_sent = 0; |
@@ -1042,41 +1051,39 @@ static ssize_t send_initiate (void *cls, struct Session* ses , struct HTTP_Conne | |||
1042 | 1051 | ||
1043 | GNUNET_assert(cls !=NULL); | 1052 | GNUNET_assert(cls !=NULL); |
1044 | 1053 | ||
1045 | #if 0 | ||
1046 | if (con->get_connected == GNUNET_NO) | 1054 | if (con->get_connected == GNUNET_NO) |
1047 | { | 1055 | { |
1048 | if (con->get_curl_handle == NULL) | 1056 | if (con->get_curl_handle == NULL) |
1049 | con->get_curl_handle = curl_easy_init(); | 1057 | { |
1050 | 1058 | con->get_curl_handle = curl_easy_init(); | |
1051 | #if DEBUG_CURL | 1059 | #if DEBUG_CURL |
1052 | curl_easy_setopt(con->get_curl_handle, CURLOPT_VERBOSE, 1L); | 1060 | curl_easy_setopt(con->get_curl_handle, CURLOPT_VERBOSE, 1L); |
1053 | #endif | 1061 | #endif |
1054 | curl_easy_setopt(con->get_curl_handle, CURLOPT_URL, con->url); | 1062 | curl_easy_setopt(con->get_curl_handle, CURLOPT_URL, con->url); |
1055 | //curl_easy_setopt(con->put_curl_handle, CURLOPT_PUT, 1L); | 1063 | //curl_easy_setopt(con->put_curl_handle, CURLOPT_PUT, 1L); |
1056 | curl_easy_setopt(con->get_curl_handle, CURLOPT_HEADERFUNCTION, &header_function); | 1064 | curl_easy_setopt(con->get_curl_handle, CURLOPT_HEADERFUNCTION, &header_function); |
1057 | curl_easy_setopt(con->get_curl_handle, CURLOPT_WRITEHEADER, con); | 1065 | curl_easy_setopt(con->get_curl_handle, CURLOPT_WRITEHEADER, con->get_curl_handle); |
1058 | curl_easy_setopt(con->get_curl_handle, CURLOPT_READFUNCTION, send_read_callback); | 1066 | curl_easy_setopt(con->get_curl_handle, CURLOPT_READFUNCTION, send_read_callback); |
1059 | curl_easy_setopt(con->get_curl_handle, CURLOPT_READDATA, con); | 1067 | curl_easy_setopt(con->get_curl_handle, CURLOPT_READDATA, con); |
1060 | curl_easy_setopt(con->get_curl_handle, CURLOPT_WRITEFUNCTION, send_write_callback); | 1068 | curl_easy_setopt(con->get_curl_handle, CURLOPT_WRITEFUNCTION, send_curl_write_callback); |
1061 | curl_easy_setopt(con->get_curl_handle, CURLOPT_READDATA, con); | 1069 | curl_easy_setopt(con->get_curl_handle, CURLOPT_WRITEDATA, con); |
1062 | curl_easy_setopt(con->get_curl_handle, CURLOPT_TIMEOUT, (long) timeout.value); | 1070 | curl_easy_setopt(con->get_curl_handle, CURLOPT_TIMEOUT, (long) timeout.value); |
1063 | curl_easy_setopt(con->get_curl_handle, CURLOPT_PRIVATE, con); | 1071 | curl_easy_setopt(con->get_curl_handle, CURLOPT_PRIVATE, con); |
1064 | curl_easy_setopt(con->get_curl_handle, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT_DBG); | 1072 | curl_easy_setopt(con->get_curl_handle, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT_DBG); |
1065 | curl_easy_setopt(con->get_curl_handle, CURLOPT_BUFFERSIZE, GNUNET_SERVER_MAX_MESSAGE_SIZE); | 1073 | curl_easy_setopt(con->get_curl_handle, CURLOPT_BUFFERSIZE, GNUNET_SERVER_MAX_MESSAGE_SIZE); |
1066 | 1074 | ||
1067 | mret = curl_multi_add_handle(plugin->multi_handle, con->get_curl_handle); | 1075 | mret = curl_multi_add_handle(plugin->multi_handle, con->get_curl_handle); |
1068 | if (mret != CURLM_OK) | 1076 | if (mret != CURLM_OK) |
1069 | { | 1077 | { |
1070 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1078 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1071 | _("%s failed at %s:%d: `%s'\n"), | 1079 | _("%s failed at %s:%d: `%s'\n"), |
1072 | "curl_multi_add_handle", __FILE__, __LINE__, | 1080 | "curl_multi_add_handle", __FILE__, __LINE__, |
1073 | curl_multi_strerror (mret)); | 1081 | curl_multi_strerror (mret)); |
1074 | return -1; | 1082 | return -1; |
1083 | } | ||
1084 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: inbound not connected, initiating connection\n",con); | ||
1075 | } | 1085 | } |
1076 | |||
1077 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: inbound not connected, initiating connection\n",con); | ||
1078 | } | 1086 | } |
1079 | #endif | ||
1080 | 1087 | ||
1081 | /* PUT already connected, no need to initiate connection */ | 1088 | /* PUT already connected, no need to initiate connection */ |
1082 | if ((con->put_connected == GNUNET_YES) && (con->put_curl_handle != NULL)) | 1089 | if ((con->put_connected == GNUNET_YES) && (con->put_curl_handle != NULL)) |
@@ -1095,7 +1102,6 @@ static ssize_t send_initiate (void *cls, struct Session* ses , struct HTTP_Conne | |||
1095 | } | 1102 | } |
1096 | } | 1103 | } |
1097 | 1104 | ||
1098 | |||
1099 | /* not connected, initiate connection */ | 1105 | /* not connected, initiate connection */ |
1100 | if ( NULL == con->put_curl_handle) | 1106 | if ( NULL == con->put_curl_handle) |
1101 | con->put_curl_handle = curl_easy_init(); | 1107 | con->put_curl_handle = curl_easy_init(); |
@@ -1110,11 +1116,9 @@ static ssize_t send_initiate (void *cls, struct Session* ses , struct HTTP_Conne | |||
1110 | #endif | 1116 | #endif |
1111 | curl_easy_setopt(con->put_curl_handle, CURLOPT_URL, con->url); | 1117 | curl_easy_setopt(con->put_curl_handle, CURLOPT_URL, con->url); |
1112 | curl_easy_setopt(con->put_curl_handle, CURLOPT_PUT, 1L); | 1118 | curl_easy_setopt(con->put_curl_handle, CURLOPT_PUT, 1L); |
1113 | curl_easy_setopt(con->put_curl_handle, CURLOPT_HEADERFUNCTION, &header_function); | ||
1114 | curl_easy_setopt(con->put_curl_handle, CURLOPT_WRITEHEADER, con); | ||
1115 | curl_easy_setopt(con->put_curl_handle, CURLOPT_READFUNCTION, send_read_callback); | 1119 | curl_easy_setopt(con->put_curl_handle, CURLOPT_READFUNCTION, send_read_callback); |
1116 | curl_easy_setopt(con->put_curl_handle, CURLOPT_READDATA, con); | 1120 | curl_easy_setopt(con->put_curl_handle, CURLOPT_READDATA, con); |
1117 | curl_easy_setopt(con->put_curl_handle, CURLOPT_WRITEFUNCTION, send_write_callback); | 1121 | curl_easy_setopt(con->put_curl_handle, CURLOPT_WRITEFUNCTION, send_curl_write_callback); |
1118 | curl_easy_setopt(con->put_curl_handle, CURLOPT_READDATA, con); | 1122 | curl_easy_setopt(con->put_curl_handle, CURLOPT_READDATA, con); |
1119 | curl_easy_setopt(con->put_curl_handle, CURLOPT_TIMEOUT, (long) timeout.value); | 1123 | curl_easy_setopt(con->put_curl_handle, CURLOPT_TIMEOUT, (long) timeout.value); |
1120 | curl_easy_setopt(con->put_curl_handle, CURLOPT_PRIVATE, con); | 1124 | curl_easy_setopt(con->put_curl_handle, CURLOPT_PRIVATE, con); |
@@ -1143,7 +1147,7 @@ static void send_execute (void *cls, | |||
1143 | int running; | 1147 | int running; |
1144 | struct CURLMsg *msg; | 1148 | struct CURLMsg *msg; |
1145 | CURLMcode mret; | 1149 | CURLMcode mret; |
1146 | struct HTTP_Connection_out * con = NULL; | 1150 | struct HTTP_Connection * con = NULL; |
1147 | struct Session * cs = NULL; | 1151 | struct Session * cs = NULL; |
1148 | long http_result; | 1152 | long http_result; |
1149 | 1153 | ||
@@ -1177,45 +1181,79 @@ static void send_execute (void *cls, | |||
1177 | if ( (msg->data.result != CURLE_OK) && | 1181 | if ( (msg->data.result != CURLE_OK) && |
1178 | (msg->data.result != CURLE_GOT_NOTHING) ) | 1182 | (msg->data.result != CURLE_GOT_NOTHING) ) |
1179 | { | 1183 | { |
1180 | |||
1181 | |||
1182 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1183 | _("Connection %X to peer `%s' (`%s') failed: `%s' `%s'\n"), | ||
1184 | con, | ||
1185 | GNUNET_i2s(&cs->identity), | ||
1186 | http_plugin_address_to_string(NULL, con->addr, con->addrlen), | ||
1187 | "curl_multi_perform", | ||
1188 | curl_easy_strerror (msg->data.result)); | ||
1189 | /* sending msg failed*/ | 1184 | /* sending msg failed*/ |
1190 | con->put_connected = GNUNET_NO; | 1185 | if (msg->easy_handle == con->put_curl_handle) |
1191 | curl_easy_cleanup(con->put_curl_handle); | 1186 | { |
1192 | con->put_curl_handle=NULL; | 1187 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1193 | if (( NULL != con->pending_msgs_tail) && ( NULL != con->pending_msgs_tail->transmit_cont)) | 1188 | _("Connection %X: HTTP PUT to peer `%s' (`%s') failed: `%s' `%s'\n"), |
1194 | con->pending_msgs_tail->transmit_cont (con->pending_msgs_tail->transmit_cont_cls,&con->session->identity,GNUNET_SYSERR); | 1189 | con, |
1195 | 1190 | GNUNET_i2s(&cs->identity), | |
1191 | http_plugin_address_to_string(NULL, con->addr, con->addrlen), | ||
1192 | "curl_multi_perform", | ||
1193 | curl_easy_strerror (msg->data.result)); | ||
1194 | |||
1195 | con->put_connected = GNUNET_NO; | ||
1196 | curl_easy_cleanup(con->put_curl_handle); | ||
1197 | con->put_curl_handle=NULL; | ||
1198 | if (( NULL != con->pending_msgs_tail) && ( NULL != con->pending_msgs_tail->transmit_cont)) | ||
1199 | con->pending_msgs_tail->transmit_cont (con->pending_msgs_tail->transmit_cont_cls,&con->session->identity,GNUNET_SYSERR); | ||
1200 | } | ||
1201 | /* GET connection failed */ | ||
1202 | if (msg->easy_handle == con->get_curl_handle) | ||
1203 | { | ||
1204 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1205 | _("Connection %X: HTTP GET to peer `%s' (`%s') failed: `%s' `%s'\n"), | ||
1206 | con, | ||
1207 | GNUNET_i2s(&cs->identity), | ||
1208 | http_plugin_address_to_string(NULL, con->addr, con->addrlen), | ||
1209 | "curl_multi_perform", | ||
1210 | curl_easy_strerror (msg->data.result)); | ||
1211 | con->get_connected = GNUNET_NO; | ||
1212 | curl_easy_cleanup(con->get_curl_handle); | ||
1213 | con->get_curl_handle=NULL; | ||
1214 | } | ||
1196 | } | 1215 | } |
1197 | else | 1216 | else |
1198 | { | 1217 | { |
1199 | GNUNET_assert (CURLE_OK == curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &http_result)); | 1218 | if (msg->easy_handle == con->put_curl_handle) |
1200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1219 | { |
1201 | "Send to peer `%s' completed with code %u\n", GNUNET_i2s(&cs->identity), http_result ); | 1220 | GNUNET_assert (CURLE_OK == curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &http_result)); |
1202 | 1221 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | |
1203 | curl_easy_cleanup(con->put_curl_handle); | 1222 | "Connection %X: HTTP PUT connection to peer `%s' (`%s') was closed with HTTP code %u\n", |
1204 | con->put_connected = GNUNET_NO; | 1223 | con, |
1205 | con->put_curl_handle=NULL; | 1224 | GNUNET_i2s(&cs->identity), |
1206 | 1225 | http_plugin_address_to_string(NULL, con->addr, con->addrlen), | |
1207 | /* Calling transmit continuation */ | 1226 | http_result); |
1208 | if (( NULL != con->pending_msgs_tail) && (NULL != con->pending_msgs_tail->transmit_cont)) | 1227 | |
1228 | /* Calling transmit continuation */ | ||
1229 | if (( NULL != con->pending_msgs_tail) && (NULL != con->pending_msgs_tail->transmit_cont)) | ||
1230 | { | ||
1231 | /* HTTP 1xx : Last message before here was informational */ | ||
1232 | if ((http_result >=100) && (http_result < 200)) | ||
1233 | con->pending_msgs_tail->transmit_cont (con->pending_msgs_tail->transmit_cont_cls,&cs->identity,GNUNET_OK); | ||
1234 | /* HTTP 2xx: successful operations */ | ||
1235 | if ((http_result >=200) && (http_result < 300)) | ||
1236 | con->pending_msgs_tail->transmit_cont (con->pending_msgs_tail->transmit_cont_cls,&cs->identity,GNUNET_OK); | ||
1237 | /* HTTP 3xx..5xx: error */ | ||
1238 | if ((http_result >=300) && (http_result < 600)) | ||
1239 | con->pending_msgs_tail->transmit_cont (con->pending_msgs_tail->transmit_cont_cls,&cs->identity,GNUNET_SYSERR); | ||
1240 | } | ||
1241 | curl_easy_cleanup(con->put_curl_handle); | ||
1242 | con->put_connected = GNUNET_NO; | ||
1243 | con->put_curl_handle=NULL; | ||
1244 | } | ||
1245 | if (msg->easy_handle == con->get_curl_handle) | ||
1209 | { | 1246 | { |
1210 | /* HTTP 1xx : Last message before here was informational */ | 1247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1211 | if ((http_result >=100) && (http_result < 200)) | 1248 | "Connection %X: HTTP GET connection to peer `%s' (`%s') was closed with HTTP code %u\n", |
1212 | con->pending_msgs_tail->transmit_cont (con->pending_msgs_tail->transmit_cont_cls,&cs->identity,GNUNET_OK); | 1249 | con, |
1213 | /* HTTP 2xx: successful operations */ | 1250 | GNUNET_i2s(&cs->identity), |
1214 | if ((http_result >=200) && (http_result < 300)) | 1251 | http_plugin_address_to_string(NULL, con->addr, con->addrlen), |
1215 | con->pending_msgs_tail->transmit_cont (con->pending_msgs_tail->transmit_cont_cls,&cs->identity,GNUNET_OK); | 1252 | http_result); |
1216 | /* HTTP 3xx..5xx: error */ | 1253 | |
1217 | if ((http_result >=300) && (http_result < 600)) | 1254 | con->get_connected = GNUNET_NO; |
1218 | con->pending_msgs_tail->transmit_cont (con->pending_msgs_tail->transmit_cont_cls,&cs->identity,GNUNET_SYSERR); | 1255 | curl_easy_cleanup(con->get_curl_handle); |
1256 | con->get_curl_handle=NULL; | ||
1219 | } | 1257 | } |
1220 | } | 1258 | } |
1221 | if (con->pending_msgs_tail != NULL) | 1259 | if (con->pending_msgs_tail != NULL) |
@@ -1353,7 +1391,7 @@ http_plugin_send (void *cls, | |||
1353 | struct Plugin *plugin = cls; | 1391 | struct Plugin *plugin = cls; |
1354 | struct Session *cs; | 1392 | struct Session *cs; |
1355 | struct HTTP_Message *msg; | 1393 | struct HTTP_Message *msg; |
1356 | struct HTTP_Connection_out *con; | 1394 | struct HTTP_Connection *con; |
1357 | //unsigned int ret; | 1395 | //unsigned int ret; |
1358 | 1396 | ||
1359 | GNUNET_assert(cls !=NULL); | 1397 | GNUNET_assert(cls !=NULL); |
@@ -1401,7 +1439,7 @@ http_plugin_send (void *cls, | |||
1401 | /* enqueue in connection message queue */ | 1439 | /* enqueue in connection message queue */ |
1402 | GNUNET_CONTAINER_DLL_insert(con->pending_msgs_head,con->pending_msgs_tail,msg); | 1440 | GNUNET_CONTAINER_DLL_insert(con->pending_msgs_head,con->pending_msgs_tail,msg); |
1403 | } | 1441 | } |
1404 | return send_initiate (plugin, cs, con); | 1442 | return send_check_connections (plugin, cs, con); |
1405 | } | 1443 | } |
1406 | 1444 | ||
1407 | 1445 | ||
@@ -1419,7 +1457,7 @@ http_plugin_disconnect (void *cls, | |||
1419 | const struct GNUNET_PeerIdentity *target) | 1457 | const struct GNUNET_PeerIdentity *target) |
1420 | { | 1458 | { |
1421 | struct Plugin *plugin = cls; | 1459 | struct Plugin *plugin = cls; |
1422 | struct HTTP_Connection_out *con; | 1460 | struct HTTP_Connection *con; |
1423 | struct Session *cs; | 1461 | struct Session *cs; |
1424 | 1462 | ||
1425 | /* get session from hashmap */ | 1463 | /* get session from hashmap */ |
@@ -1677,8 +1715,8 @@ process_interfaces (void *cls, | |||
1677 | int hashMapFreeIterator (void *cls, const GNUNET_HashCode *key, void *value) | 1715 | int hashMapFreeIterator (void *cls, const GNUNET_HashCode *key, void *value) |
1678 | { | 1716 | { |
1679 | struct Session * cs = value; | 1717 | struct Session * cs = value; |
1680 | struct HTTP_Connection_out * con = cs->outbound_connections_head; | 1718 | struct HTTP_Connection * con = cs->outbound_connections_head; |
1681 | struct HTTP_Connection_out * tmp_con = cs->outbound_connections_head; | 1719 | struct HTTP_Connection * tmp_con = cs->outbound_connections_head; |
1682 | struct HTTP_Message * msg = NULL; | 1720 | struct HTTP_Message * msg = NULL; |
1683 | struct HTTP_Message * tmp_msg = NULL; | 1721 | struct HTTP_Message * tmp_msg = NULL; |
1684 | 1722 | ||