diff options
Diffstat (limited to 'src/gns/gnunet-gns-proxy.c')
-rw-r--r-- | src/gns/gnunet-gns-proxy.c | 4108 |
1 files changed, 2060 insertions, 2048 deletions
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c index eb8115026..6285a8fcd 100644 --- a/src/gns/gnunet-gns-proxy.c +++ b/src/gns/gnunet-gns-proxy.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @author Martin Schanzenbach | 21 | * @author Martin Schanzenbach |
22 | * @author Christian Grothoff | 22 | * @author Christian Grothoff |
@@ -94,13 +94,13 @@ | |||
94 | /** | 94 | /** |
95 | * After how long do we clean up unused MHD TLS instances? | 95 | * After how long do we clean up unused MHD TLS instances? |
96 | */ | 96 | */ |
97 | #define MHD_CACHE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) | 97 | #define MHD_CACHE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) |
98 | 98 | ||
99 | /** | 99 | /** |
100 | * After how long do we clean up Socks5 handles that failed to show any activity | 100 | * After how long do we clean up Socks5 handles that failed to show any activity |
101 | * with their respective MHD instance? | 101 | * with their respective MHD instance? |
102 | */ | 102 | */ |
103 | #define HTTP_HANDSHAKE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 103 | #define HTTP_HANDSHAKE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) |
104 | 104 | ||
105 | 105 | ||
106 | /** | 106 | /** |
@@ -110,13 +110,13 @@ | |||
110 | * @param fun name of curl_easy-function that gave the error | 110 | * @param fun name of curl_easy-function that gave the error |
111 | * @param rc return code from curl | 111 | * @param rc return code from curl |
112 | */ | 112 | */ |
113 | #define LOG_CURL_EASY(level,fun,rc) \ | 113 | #define LOG_CURL_EASY(level, fun, rc) \ |
114 | GNUNET_log (level, \ | 114 | GNUNET_log(level, \ |
115 | _("%s failed at %s:%d: `%s'\n"), \ | 115 | _("%s failed at %s:%d: `%s'\n"), \ |
116 | fun, \ | 116 | fun, \ |
117 | __FILE__, \ | 117 | __FILE__, \ |
118 | __LINE__, \ | 118 | __LINE__, \ |
119 | curl_easy_strerror (rc)) | 119 | curl_easy_strerror(rc)) |
120 | 120 | ||
121 | 121 | ||
122 | /* *************** Socks protocol definitions (move to TUN?) ****************** */ | 122 | /* *************** Socks protocol definitions (move to TUN?) ****************** */ |
@@ -135,8 +135,7 @@ | |||
135 | /** | 135 | /** |
136 | * Commands in Socks5. | 136 | * Commands in Socks5. |
137 | */ | 137 | */ |
138 | enum Socks5Commands | 138 | enum Socks5Commands { |
139 | { | ||
140 | /** | 139 | /** |
141 | * Establish TCP/IP stream. | 140 | * Establish TCP/IP stream. |
142 | */ | 141 | */ |
@@ -157,8 +156,7 @@ enum Socks5Commands | |||
157 | /** | 156 | /** |
158 | * Address types in Socks5. | 157 | * Address types in Socks5. |
159 | */ | 158 | */ |
160 | enum Socks5AddressType | 159 | enum Socks5AddressType { |
161 | { | ||
162 | /** | 160 | /** |
163 | * IPv4 address. | 161 | * IPv4 address. |
164 | */ | 162 | */ |
@@ -173,15 +171,13 @@ enum Socks5AddressType | |||
173 | * IPv6 address. | 171 | * IPv6 address. |
174 | */ | 172 | */ |
175 | SOCKS5_AT_IPV6 = 4 | 173 | SOCKS5_AT_IPV6 = 4 |
176 | |||
177 | }; | 174 | }; |
178 | 175 | ||
179 | 176 | ||
180 | /** | 177 | /** |
181 | * Status codes in Socks5 response. | 178 | * Status codes in Socks5 response. |
182 | */ | 179 | */ |
183 | enum Socks5StatusCode | 180 | enum Socks5StatusCode { |
184 | { | ||
185 | SOCKS5_STATUS_REQUEST_GRANTED = 0, | 181 | SOCKS5_STATUS_REQUEST_GRANTED = 0, |
186 | SOCKS5_STATUS_GENERAL_FAILURE = 1, | 182 | SOCKS5_STATUS_GENERAL_FAILURE = 1, |
187 | SOCKS5_STATUS_CONNECTION_NOT_ALLOWED_BY_RULE = 2, | 183 | SOCKS5_STATUS_CONNECTION_NOT_ALLOWED_BY_RULE = 2, |
@@ -197,8 +193,7 @@ enum Socks5StatusCode | |||
197 | /** | 193 | /** |
198 | * Client hello in Socks5 protocol. | 194 | * Client hello in Socks5 protocol. |
199 | */ | 195 | */ |
200 | struct Socks5ClientHelloMessage | 196 | struct Socks5ClientHelloMessage { |
201 | { | ||
202 | /** | 197 | /** |
203 | * Should be #SOCKS_VERSION_5. | 198 | * Should be #SOCKS_VERSION_5. |
204 | */ | 199 | */ |
@@ -210,15 +205,13 @@ struct Socks5ClientHelloMessage | |||
210 | uint8_t num_auth_methods; | 205 | uint8_t num_auth_methods; |
211 | 206 | ||
212 | /* followed by supported authentication methods, 1 byte per method */ | 207 | /* followed by supported authentication methods, 1 byte per method */ |
213 | |||
214 | }; | 208 | }; |
215 | 209 | ||
216 | 210 | ||
217 | /** | 211 | /** |
218 | * Server hello in Socks5 protocol. | 212 | * Server hello in Socks5 protocol. |
219 | */ | 213 | */ |
220 | struct Socks5ServerHelloMessage | 214 | struct Socks5ServerHelloMessage { |
221 | { | ||
222 | /** | 215 | /** |
223 | * Should be #SOCKS_VERSION_5. | 216 | * Should be #SOCKS_VERSION_5. |
224 | */ | 217 | */ |
@@ -235,8 +228,7 @@ struct Socks5ServerHelloMessage | |||
235 | /** | 228 | /** |
236 | * Client socks request in Socks5 protocol. | 229 | * Client socks request in Socks5 protocol. |
237 | */ | 230 | */ |
238 | struct Socks5ClientRequestMessage | 231 | struct Socks5ClientRequestMessage { |
239 | { | ||
240 | /** | 232 | /** |
241 | * Should be #SOCKS_VERSION_5. | 233 | * Should be #SOCKS_VERSION_5. |
242 | */ | 234 | */ |
@@ -268,8 +260,7 @@ struct Socks5ClientRequestMessage | |||
268 | /** | 260 | /** |
269 | * Server response to client requests in Socks5 protocol. | 261 | * Server response to client requests in Socks5 protocol. |
270 | */ | 262 | */ |
271 | struct Socks5ServerResponseMessage | 263 | struct Socks5ServerResponseMessage { |
272 | { | ||
273 | /** | 264 | /** |
274 | * Should be #SOCKS_VERSION_5. | 265 | * Should be #SOCKS_VERSION_5. |
275 | */ | 266 | */ |
@@ -295,7 +286,6 @@ struct Socks5ServerResponseMessage | |||
295 | * length field (uint8_t) in front (depending on @e addr_type). | 286 | * length field (uint8_t) in front (depending on @e addr_type). |
296 | * followed by port number in network byte order (uint16_t). | 287 | * followed by port number in network byte order (uint16_t). |
297 | */ | 288 | */ |
298 | |||
299 | }; | 289 | }; |
300 | 290 | ||
301 | 291 | ||
@@ -305,8 +295,7 @@ struct Socks5ServerResponseMessage | |||
305 | /** | 295 | /** |
306 | * A structure for CA cert/key | 296 | * A structure for CA cert/key |
307 | */ | 297 | */ |
308 | struct ProxyCA | 298 | struct ProxyCA { |
309 | { | ||
310 | /** | 299 | /** |
311 | * The certificate | 300 | * The certificate |
312 | */ | 301 | */ |
@@ -322,8 +311,7 @@ struct ProxyCA | |||
322 | /** | 311 | /** |
323 | * Structure for GNS certificates | 312 | * Structure for GNS certificates |
324 | */ | 313 | */ |
325 | struct ProxyGNSCertificate | 314 | struct ProxyGNSCertificate { |
326 | { | ||
327 | /** | 315 | /** |
328 | * The certificate as PEM | 316 | * The certificate as PEM |
329 | */ | 317 | */ |
@@ -340,8 +328,7 @@ struct ProxyGNSCertificate | |||
340 | /** | 328 | /** |
341 | * A structure for all running Httpds | 329 | * A structure for all running Httpds |
342 | */ | 330 | */ |
343 | struct MhdHttpList | 331 | struct MhdHttpList { |
344 | { | ||
345 | /** | 332 | /** |
346 | * DLL for httpds | 333 | * DLL for httpds |
347 | */ | 334 | */ |
@@ -376,7 +363,6 @@ struct MhdHttpList | |||
376 | * is this an ssl daemon? | 363 | * is this an ssl daemon? |
377 | */ | 364 | */ |
378 | int is_ssl; | 365 | int is_ssl; |
379 | |||
380 | }; | 366 | }; |
381 | 367 | ||
382 | 368 | ||
@@ -386,8 +372,7 @@ struct MhdHttpList | |||
386 | /** | 372 | /** |
387 | * The socks phases. | 373 | * The socks phases. |
388 | */ | 374 | */ |
389 | enum SocksPhase | 375 | enum SocksPhase { |
390 | { | ||
391 | /** | 376 | /** |
392 | * We're waiting to get the client hello. | 377 | * We're waiting to get the client hello. |
393 | */ | 378 | */ |
@@ -443,8 +428,7 @@ enum SocksPhase | |||
443 | /** | 428 | /** |
444 | * A header list | 429 | * A header list |
445 | */ | 430 | */ |
446 | struct HttpResponseHeader | 431 | struct HttpResponseHeader { |
447 | { | ||
448 | /** | 432 | /** |
449 | * DLL | 433 | * DLL |
450 | */ | 434 | */ |
@@ -469,9 +453,7 @@ struct HttpResponseHeader | |||
469 | /** | 453 | /** |
470 | * A structure for socks requests | 454 | * A structure for socks requests |
471 | */ | 455 | */ |
472 | struct Socks5Request | 456 | struct Socks5Request { |
473 | { | ||
474 | |||
475 | /** | 457 | /** |
476 | * DLL. | 458 | * DLL. |
477 | */ | 459 | */ |
@@ -769,7 +751,7 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
769 | * @param hd the daemon to run now. | 751 | * @param hd the daemon to run now. |
770 | */ | 752 | */ |
771 | static void | 753 | static void |
772 | run_mhd_now (struct MhdHttpList *hd); | 754 | run_mhd_now(struct MhdHttpList *hd); |
773 | 755 | ||
774 | 756 | ||
775 | /** | 757 | /** |
@@ -778,79 +760,79 @@ run_mhd_now (struct MhdHttpList *hd); | |||
778 | * @param s5r the handle to destroy | 760 | * @param s5r the handle to destroy |
779 | */ | 761 | */ |
780 | static void | 762 | static void |
781 | cleanup_s5r (struct Socks5Request *s5r) | 763 | cleanup_s5r(struct Socks5Request *s5r) |
782 | { | 764 | { |
783 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 765 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
784 | "Cleaning up socks request\n"); | 766 | "Cleaning up socks request\n"); |
785 | if (NULL != s5r->curl) | 767 | if (NULL != s5r->curl) |
786 | { | 768 | { |
787 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 769 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
788 | "Cleaning up cURL handle\n"); | 770 | "Cleaning up cURL handle\n"); |
789 | curl_multi_remove_handle (curl_multi, | 771 | curl_multi_remove_handle(curl_multi, |
790 | s5r->curl); | 772 | s5r->curl); |
791 | curl_easy_cleanup (s5r->curl); | 773 | curl_easy_cleanup(s5r->curl); |
792 | s5r->curl = NULL; | 774 | s5r->curl = NULL; |
793 | } | 775 | } |
794 | if (s5r->suspended) | 776 | if (s5r->suspended) |
795 | { | 777 | { |
796 | s5r->suspended = GNUNET_NO; | 778 | s5r->suspended = GNUNET_NO; |
797 | MHD_resume_connection (s5r->con); | 779 | MHD_resume_connection(s5r->con); |
798 | } | 780 | } |
799 | curl_slist_free_all (s5r->headers); | 781 | curl_slist_free_all(s5r->headers); |
800 | if (NULL != s5r->hosts) | 782 | if (NULL != s5r->hosts) |
801 | { | 783 | { |
802 | curl_slist_free_all (s5r->hosts); | 784 | curl_slist_free_all(s5r->hosts); |
803 | } | 785 | } |
804 | if ( (NULL != s5r->response) && | 786 | if ((NULL != s5r->response) && |
805 | (curl_failure_response != s5r->response) ) | 787 | (curl_failure_response != s5r->response)) |
806 | { | 788 | { |
807 | MHD_destroy_response (s5r->response); | 789 | MHD_destroy_response(s5r->response); |
808 | s5r->response = NULL; | 790 | s5r->response = NULL; |
809 | } | 791 | } |
810 | if (NULL != s5r->rtask) | 792 | if (NULL != s5r->rtask) |
811 | { | 793 | { |
812 | GNUNET_SCHEDULER_cancel (s5r->rtask); | 794 | GNUNET_SCHEDULER_cancel(s5r->rtask); |
813 | s5r->rtask = NULL; | 795 | s5r->rtask = NULL; |
814 | } | 796 | } |
815 | if (NULL != s5r->timeout_task) | 797 | if (NULL != s5r->timeout_task) |
816 | { | 798 | { |
817 | GNUNET_SCHEDULER_cancel (s5r->timeout_task); | 799 | GNUNET_SCHEDULER_cancel(s5r->timeout_task); |
818 | s5r->timeout_task = NULL; | 800 | s5r->timeout_task = NULL; |
819 | } | 801 | } |
820 | if (NULL != s5r->wtask) | 802 | if (NULL != s5r->wtask) |
821 | { | 803 | { |
822 | GNUNET_SCHEDULER_cancel (s5r->wtask); | 804 | GNUNET_SCHEDULER_cancel(s5r->wtask); |
823 | s5r->wtask = NULL; | 805 | s5r->wtask = NULL; |
824 | } | 806 | } |
825 | if (NULL != s5r->gns_lookup) | 807 | if (NULL != s5r->gns_lookup) |
826 | { | 808 | { |
827 | GNUNET_GNS_lookup_with_tld_cancel (s5r->gns_lookup); | 809 | GNUNET_GNS_lookup_with_tld_cancel(s5r->gns_lookup); |
828 | s5r->gns_lookup = NULL; | 810 | s5r->gns_lookup = NULL; |
829 | } | 811 | } |
830 | if (NULL != s5r->sock) | 812 | if (NULL != s5r->sock) |
831 | { | 813 | { |
832 | if (SOCKS5_SOCKET_WITH_MHD <= s5r->state) | 814 | if (SOCKS5_SOCKET_WITH_MHD <= s5r->state) |
833 | GNUNET_NETWORK_socket_free_memory_only_ (s5r->sock); | 815 | GNUNET_NETWORK_socket_free_memory_only_(s5r->sock); |
834 | else | 816 | else |
835 | GNUNET_NETWORK_socket_close (s5r->sock); | 817 | GNUNET_NETWORK_socket_close(s5r->sock); |
836 | s5r->sock = NULL; | 818 | s5r->sock = NULL; |
837 | } | 819 | } |
838 | GNUNET_CONTAINER_DLL_remove (s5r_head, | 820 | GNUNET_CONTAINER_DLL_remove(s5r_head, |
839 | s5r_tail, | 821 | s5r_tail, |
840 | s5r); | 822 | s5r); |
841 | GNUNET_free_non_null (s5r->domain); | 823 | GNUNET_free_non_null(s5r->domain); |
842 | GNUNET_free_non_null (s5r->leho); | 824 | GNUNET_free_non_null(s5r->leho); |
843 | GNUNET_free_non_null (s5r->url); | 825 | GNUNET_free_non_null(s5r->url); |
844 | for (unsigned int i=0;i<s5r->num_danes;i++) | 826 | for (unsigned int i = 0; i < s5r->num_danes; i++) |
845 | GNUNET_free (s5r->dane_data[i]); | 827 | GNUNET_free(s5r->dane_data[i]); |
846 | GNUNET_free (s5r); | 828 | GNUNET_free(s5r); |
847 | } | 829 | } |
848 | 830 | ||
849 | 831 | ||
850 | /* ************************* HTTP handling with cURL *********************** */ | 832 | /* ************************* HTTP handling with cURL *********************** */ |
851 | 833 | ||
852 | static void | 834 | static void |
853 | curl_download_prepare (); | 835 | curl_download_prepare(); |
854 | 836 | ||
855 | 837 | ||
856 | /** | 838 | /** |
@@ -865,89 +847,89 @@ curl_download_prepare (); | |||
865 | * @return number of bytes written to @a buf | 847 | * @return number of bytes written to @a buf |
866 | */ | 848 | */ |
867 | static ssize_t | 849 | static ssize_t |
868 | mhd_content_cb (void *cls, | 850 | mhd_content_cb(void *cls, |
869 | uint64_t pos, | 851 | uint64_t pos, |
870 | char* buf, | 852 | char* buf, |
871 | size_t max) | 853 | size_t max) |
872 | { | 854 | { |
873 | struct Socks5Request *s5r = cls; | 855 | struct Socks5Request *s5r = cls; |
874 | size_t bytes_to_copy; | 856 | size_t bytes_to_copy; |
875 | 857 | ||
876 | if ( (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) || | 858 | if ((SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) || |
877 | (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) ) | 859 | (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state)) |
878 | { | 860 | { |
879 | /* we're still not done with the upload, do not yet | 861 | /* we're still not done with the upload, do not yet |
880 | start the download, the IO buffer is still full | 862 | start the download, the IO buffer is still full |
881 | with upload data. */ | 863 | with upload data. */ |
882 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 864 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
883 | "Pausing MHD download %s%s, not yet ready for download\n", | 865 | "Pausing MHD download %s%s, not yet ready for download\n", |
884 | s5r->domain, | 866 | s5r->domain, |
885 | s5r->url); | 867 | s5r->url); |
886 | return 0; /* not yet ready for data download */ | 868 | return 0; /* not yet ready for data download */ |
887 | } | ||
888 | bytes_to_copy = GNUNET_MIN (max, | ||
889 | s5r->io_len); | ||
890 | if ( (0 == bytes_to_copy) && | ||
891 | (SOCKS5_SOCKET_DOWNLOAD_DONE != s5r->state) ) | ||
892 | { | ||
893 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
894 | "Pausing MHD download %s%s, no data available\n", | ||
895 | s5r->domain, | ||
896 | s5r->url); | ||
897 | if (NULL != s5r->curl) | ||
898 | { | ||
899 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
900 | "Continuing CURL interaction for %s%s\n", | ||
901 | s5r->domain, | ||
902 | s5r->url); | ||
903 | if (GNUNET_YES == s5r->curl_paused) | ||
904 | { | ||
905 | s5r->curl_paused = GNUNET_NO; | ||
906 | curl_easy_pause (s5r->curl, | ||
907 | CURLPAUSE_CONT); | ||
908 | } | ||
909 | curl_download_prepare (); | ||
910 | } | 869 | } |
911 | if (GNUNET_NO == s5r->suspended) | 870 | bytes_to_copy = GNUNET_MIN(max, |
871 | s5r->io_len); | ||
872 | if ((0 == bytes_to_copy) && | ||
873 | (SOCKS5_SOCKET_DOWNLOAD_DONE != s5r->state)) | ||
912 | { | 874 | { |
913 | MHD_suspend_connection (s5r->con); | 875 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
914 | s5r->suspended = GNUNET_YES; | 876 | "Pausing MHD download %s%s, no data available\n", |
877 | s5r->domain, | ||
878 | s5r->url); | ||
879 | if (NULL != s5r->curl) | ||
880 | { | ||
881 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
882 | "Continuing CURL interaction for %s%s\n", | ||
883 | s5r->domain, | ||
884 | s5r->url); | ||
885 | if (GNUNET_YES == s5r->curl_paused) | ||
886 | { | ||
887 | s5r->curl_paused = GNUNET_NO; | ||
888 | curl_easy_pause(s5r->curl, | ||
889 | CURLPAUSE_CONT); | ||
890 | } | ||
891 | curl_download_prepare(); | ||
892 | } | ||
893 | if (GNUNET_NO == s5r->suspended) | ||
894 | { | ||
895 | MHD_suspend_connection(s5r->con); | ||
896 | s5r->suspended = GNUNET_YES; | ||
897 | } | ||
898 | return 0; /* more data later */ | ||
915 | } | 899 | } |
916 | return 0; /* more data later */ | 900 | if ((0 == bytes_to_copy) && |
917 | } | 901 | (SOCKS5_SOCKET_DOWNLOAD_DONE == s5r->state)) |
918 | if ( (0 == bytes_to_copy) && | 902 | { |
919 | (SOCKS5_SOCKET_DOWNLOAD_DONE == s5r->state) ) | 903 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
920 | { | 904 | "Completed MHD download %s%s\n", |
921 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 905 | s5r->domain, |
922 | "Completed MHD download %s%s\n", | 906 | s5r->url); |
923 | s5r->domain, | 907 | return MHD_CONTENT_READER_END_OF_STREAM; |
924 | s5r->url); | 908 | } |
925 | return MHD_CONTENT_READER_END_OF_STREAM; | 909 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
926 | } | 910 | "Writing %llu/%llu bytes to %s%s\n", |
927 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 911 | (unsigned long long)bytes_to_copy, |
928 | "Writing %llu/%llu bytes to %s%s\n", | 912 | (unsigned long long)s5r->io_len, |
929 | (unsigned long long) bytes_to_copy, | 913 | s5r->domain, |
930 | (unsigned long long) s5r->io_len, | 914 | s5r->url); |
931 | s5r->domain, | 915 | GNUNET_memcpy(buf, |
932 | s5r->url); | 916 | s5r->io_buf, |
933 | GNUNET_memcpy (buf, | 917 | bytes_to_copy); |
934 | s5r->io_buf, | 918 | memmove(s5r->io_buf, |
935 | bytes_to_copy); | 919 | &s5r->io_buf[bytes_to_copy], |
936 | memmove (s5r->io_buf, | 920 | s5r->io_len - bytes_to_copy); |
937 | &s5r->io_buf[bytes_to_copy], | ||
938 | s5r->io_len - bytes_to_copy); | ||
939 | s5r->io_len -= bytes_to_copy; | 921 | s5r->io_len -= bytes_to_copy; |
940 | if ( (NULL != s5r->curl) && | 922 | if ((NULL != s5r->curl) && |
941 | (GNUNET_YES == s5r->curl_paused) ) | 923 | (GNUNET_YES == s5r->curl_paused)) |
942 | { | 924 | { |
943 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 925 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
944 | "Continuing CURL interaction for %s%s\n", | 926 | "Continuing CURL interaction for %s%s\n", |
945 | s5r->domain, | 927 | s5r->domain, |
946 | s5r->url); | 928 | s5r->url); |
947 | s5r->curl_paused = GNUNET_NO; | 929 | s5r->curl_paused = GNUNET_NO; |
948 | curl_easy_pause (s5r->curl, | 930 | curl_easy_pause(s5r->curl, |
949 | CURLPAUSE_CONT); | 931 | CURLPAUSE_CONT); |
950 | } | 932 | } |
951 | return bytes_to_copy; | 933 | return bytes_to_copy; |
952 | } | 934 | } |
953 | 935 | ||
@@ -961,7 +943,7 @@ mhd_content_cb (void *cls, | |||
961 | * @return #GNUNET_OK if the certificate is valid | 943 | * @return #GNUNET_OK if the certificate is valid |
962 | */ | 944 | */ |
963 | static int | 945 | static int |
964 | check_ssl_certificate (struct Socks5Request *s5r) | 946 | check_ssl_certificate(struct Socks5Request *s5r) |
965 | { | 947 | { |
966 | unsigned int cert_list_size; | 948 | unsigned int cert_list_size; |
967 | const gnutls_datum_t *chainp; | 949 | const gnutls_datum_t *chainp; |
@@ -973,113 +955,113 @@ check_ssl_certificate (struct Socks5Request *s5r) | |||
973 | const char *name; | 955 | const char *name; |
974 | 956 | ||
975 | s5r->ssl_checked = GNUNET_YES; | 957 | s5r->ssl_checked = GNUNET_YES; |
976 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 958 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
977 | "Checking X.509 certificate\n"); | 959 | "Checking X.509 certificate\n"); |
978 | if (CURLE_OK != | 960 | if (CURLE_OK != |
979 | curl_easy_getinfo (s5r->curl, | 961 | curl_easy_getinfo(s5r->curl, |
980 | CURLINFO_TLS_SESSION, | 962 | CURLINFO_TLS_SESSION, |
981 | &tlsinfo)) | 963 | &tlsinfo)) |
982 | return GNUNET_SYSERR; | 964 | return GNUNET_SYSERR; |
983 | if (CURLSSLBACKEND_GNUTLS != tlsinfo->backend) | 965 | if (CURLSSLBACKEND_GNUTLS != tlsinfo->backend) |
984 | { | 966 | { |
985 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 967 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
986 | _("Unsupported CURL TLS backend %d\n"), | 968 | _("Unsupported CURL TLS backend %d\n"), |
987 | tlsinfo->backend); | 969 | tlsinfo->backend); |
988 | return GNUNET_SYSERR; | 970 | return GNUNET_SYSERR; |
989 | } | 971 | } |
990 | chainp = gnutls_certificate_get_peers (tlsinfo->internals, | 972 | chainp = gnutls_certificate_get_peers(tlsinfo->internals, |
991 | &cert_list_size); | 973 | &cert_list_size); |
992 | if ( (! chainp) || | 974 | if ((!chainp) || |
993 | (0 == cert_list_size) ) | 975 | (0 == cert_list_size)) |
994 | return GNUNET_SYSERR; | 976 | return GNUNET_SYSERR; |
995 | 977 | ||
996 | size = sizeof (certdn); | 978 | size = sizeof(certdn); |
997 | /* initialize an X.509 certificate structure. */ | 979 | /* initialize an X.509 certificate structure. */ |
998 | gnutls_x509_crt_init (&x509_cert); | 980 | gnutls_x509_crt_init(&x509_cert); |
999 | gnutls_x509_crt_import (x509_cert, | 981 | gnutls_x509_crt_import(x509_cert, |
1000 | chainp, | 982 | chainp, |
1001 | GNUTLS_X509_FMT_DER); | 983 | GNUTLS_X509_FMT_DER); |
1002 | 984 | ||
1003 | if (0 != (rc = gnutls_x509_crt_get_dn_by_oid (x509_cert, | 985 | if (0 != (rc = gnutls_x509_crt_get_dn_by_oid(x509_cert, |
1004 | GNUTLS_OID_X520_COMMON_NAME, | 986 | GNUTLS_OID_X520_COMMON_NAME, |
1005 | 0, /* the first and only one */ | 987 | 0, /* the first and only one */ |
1006 | 0 /* no DER encoding */, | 988 | 0 /* no DER encoding */, |
1007 | certdn, | 989 | certdn, |
1008 | &size))) | 990 | &size))) |
1009 | { | 991 | { |
1010 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 992 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1011 | _("Failed to fetch CN from cert: %s\n"), | 993 | _("Failed to fetch CN from cert: %s\n"), |
1012 | gnutls_strerror(rc)); | 994 | gnutls_strerror(rc)); |
1013 | gnutls_x509_crt_deinit (x509_cert); | 995 | gnutls_x509_crt_deinit(x509_cert); |
1014 | return GNUNET_SYSERR; | 996 | return GNUNET_SYSERR; |
1015 | } | 997 | } |
1016 | /* check for TLSA/DANE records */ | 998 | /* check for TLSA/DANE records */ |
1017 | #if HAVE_GNUTLS_DANE | 999 | #if HAVE_GNUTLS_DANE |
1018 | if (0 != s5r->num_danes) | 1000 | if (0 != s5r->num_danes) |
1019 | { | 1001 | { |
1020 | dane_state_t dane_state; | 1002 | dane_state_t dane_state; |
1021 | dane_query_t dane_query; | 1003 | dane_query_t dane_query; |
1022 | unsigned int verify; | 1004 | unsigned int verify; |
1023 | 1005 | ||
1024 | /* FIXME: add flags to gnutls to NOT read UNBOUND_ROOT_KEY_FILE here! */ | 1006 | /* FIXME: add flags to gnutls to NOT read UNBOUND_ROOT_KEY_FILE here! */ |
1025 | if (0 != (rc = dane_state_init (&dane_state, | 1007 | if (0 != (rc = dane_state_init(&dane_state, |
1026 | #ifdef DANE_F_IGNORE_DNSSEC | 1008 | #ifdef DANE_F_IGNORE_DNSSEC |
1027 | DANE_F_IGNORE_DNSSEC | | 1009 | DANE_F_IGNORE_DNSSEC | |
1028 | #endif | 1010 | #endif |
1029 | DANE_F_IGNORE_LOCAL_RESOLVER))) | 1011 | DANE_F_IGNORE_LOCAL_RESOLVER))) |
1030 | { | 1012 | { |
1031 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1013 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1032 | _("Failed to initialize DANE: %s\n"), | 1014 | _("Failed to initialize DANE: %s\n"), |
1033 | dane_strerror(rc)); | 1015 | dane_strerror(rc)); |
1034 | gnutls_x509_crt_deinit (x509_cert); | 1016 | gnutls_x509_crt_deinit(x509_cert); |
1035 | return GNUNET_SYSERR; | 1017 | return GNUNET_SYSERR; |
1036 | } | 1018 | } |
1037 | s5r->dane_data[s5r->num_danes] = NULL; | 1019 | s5r->dane_data[s5r->num_danes] = NULL; |
1038 | s5r->dane_data_len[s5r->num_danes] = 0; | 1020 | s5r->dane_data_len[s5r->num_danes] = 0; |
1039 | if (0 != (rc = dane_raw_tlsa (dane_state, | 1021 | if (0 != (rc = dane_raw_tlsa(dane_state, |
1040 | &dane_query, | 1022 | &dane_query, |
1041 | s5r->dane_data, | 1023 | s5r->dane_data, |
1042 | s5r->dane_data_len, | 1024 | s5r->dane_data_len, |
1043 | GNUNET_YES, | 1025 | GNUNET_YES, |
1044 | GNUNET_NO))) | 1026 | GNUNET_NO))) |
1045 | { | 1027 | { |
1046 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1028 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1047 | _("Failed to parse DANE record: %s\n"), | 1029 | _("Failed to parse DANE record: %s\n"), |
1048 | dane_strerror(rc)); | 1030 | dane_strerror(rc)); |
1049 | dane_state_deinit (dane_state); | 1031 | dane_state_deinit(dane_state); |
1050 | gnutls_x509_crt_deinit (x509_cert); | 1032 | gnutls_x509_crt_deinit(x509_cert); |
1051 | return GNUNET_SYSERR; | 1033 | return GNUNET_SYSERR; |
1052 | } | 1034 | } |
1053 | if (0 != (rc = dane_verify_crt_raw (dane_state, | 1035 | if (0 != (rc = dane_verify_crt_raw(dane_state, |
1054 | chainp, | 1036 | chainp, |
1055 | cert_list_size, | 1037 | cert_list_size, |
1056 | gnutls_certificate_type_get (tlsinfo->internals), | 1038 | gnutls_certificate_type_get(tlsinfo->internals), |
1057 | dane_query, | 1039 | dane_query, |
1058 | 0, 0, | 1040 | 0, 0, |
1059 | &verify))) | 1041 | &verify))) |
1060 | { | 1042 | { |
1061 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1043 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1062 | _("Failed to verify TLS connection using DANE: %s\n"), | 1044 | _("Failed to verify TLS connection using DANE: %s\n"), |
1063 | dane_strerror(rc)); | 1045 | dane_strerror(rc)); |
1064 | dane_query_deinit (dane_query); | 1046 | dane_query_deinit(dane_query); |
1065 | dane_state_deinit (dane_state); | 1047 | dane_state_deinit(dane_state); |
1066 | gnutls_x509_crt_deinit (x509_cert); | 1048 | gnutls_x509_crt_deinit(x509_cert); |
1067 | return GNUNET_SYSERR; | 1049 | return GNUNET_SYSERR; |
1068 | } | 1050 | } |
1069 | if (0 != verify) | 1051 | if (0 != verify) |
1070 | { | 1052 | { |
1071 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1053 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1072 | _("Failed DANE verification failed with GnuTLS verify status code: %u\n"), | 1054 | _("Failed DANE verification failed with GnuTLS verify status code: %u\n"), |
1073 | verify); | 1055 | verify); |
1074 | dane_query_deinit (dane_query); | 1056 | dane_query_deinit(dane_query); |
1075 | dane_state_deinit (dane_state); | 1057 | dane_state_deinit(dane_state); |
1076 | gnutls_x509_crt_deinit (x509_cert); | 1058 | gnutls_x509_crt_deinit(x509_cert); |
1077 | return GNUNET_SYSERR; | 1059 | return GNUNET_SYSERR; |
1060 | } | ||
1061 | dane_query_deinit(dane_query); | ||
1062 | dane_state_deinit(dane_state); | ||
1063 | /* success! */ | ||
1078 | } | 1064 | } |
1079 | dane_query_deinit (dane_query); | ||
1080 | dane_state_deinit (dane_state); | ||
1081 | /* success! */ | ||
1082 | } | ||
1083 | else | 1065 | else |
1084 | #endif | 1066 | #endif |
1085 | { | 1067 | { |
@@ -1088,27 +1070,27 @@ check_ssl_certificate (struct Socks5Request *s5r) | |||
1088 | if (NULL != s5r->leho) | 1070 | if (NULL != s5r->leho) |
1089 | name = s5r->leho; | 1071 | name = s5r->leho; |
1090 | if (NULL != name) | 1072 | if (NULL != name) |
1091 | { | ||
1092 | if (0 == (rc = gnutls_x509_crt_check_hostname (x509_cert, | ||
1093 | name))) | ||
1094 | { | 1073 | { |
1095 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1074 | if (0 == (rc = gnutls_x509_crt_check_hostname(x509_cert, |
1096 | _("TLS certificate subject name (%s) does not match `%s': %d\n"), | 1075 | name))) |
1097 | certdn, | 1076 | { |
1098 | name, | 1077 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1099 | rc); | 1078 | _("TLS certificate subject name (%s) does not match `%s': %d\n"), |
1100 | gnutls_x509_crt_deinit (x509_cert); | 1079 | certdn, |
1101 | return GNUNET_SYSERR; | 1080 | name, |
1081 | rc); | ||
1082 | gnutls_x509_crt_deinit(x509_cert); | ||
1083 | return GNUNET_SYSERR; | ||
1084 | } | ||
1102 | } | 1085 | } |
1103 | } | ||
1104 | else | 1086 | else |
1105 | { | 1087 | { |
1106 | /* we did not even have the domain name!? */ | 1088 | /* we did not even have the domain name!? */ |
1107 | GNUNET_break (0); | 1089 | GNUNET_break(0); |
1108 | return GNUNET_SYSERR; | 1090 | return GNUNET_SYSERR; |
1109 | } | 1091 | } |
1110 | } | 1092 | } |
1111 | gnutls_x509_crt_deinit (x509_cert); | 1093 | gnutls_x509_crt_deinit(x509_cert); |
1112 | return GNUNET_OK; | 1094 | return GNUNET_OK; |
1113 | } | 1095 | } |
1114 | 1096 | ||
@@ -1126,10 +1108,10 @@ check_ssl_certificate (struct Socks5Request *s5r) | |||
1126 | * @return size of processed bytes | 1108 | * @return size of processed bytes |
1127 | */ | 1109 | */ |
1128 | static size_t | 1110 | static size_t |
1129 | curl_check_hdr (void *buffer, | 1111 | curl_check_hdr(void *buffer, |
1130 | size_t size, | 1112 | size_t size, |
1131 | size_t nmemb, | 1113 | size_t nmemb, |
1132 | void *cls) | 1114 | void *cls) |
1133 | { | 1115 | { |
1134 | struct Socks5Request *s5r = cls; | 1116 | struct Socks5Request *s5r = cls; |
1135 | struct HttpResponseHeader *header; | 1117 | struct HttpResponseHeader *header; |
@@ -1145,178 +1127,178 @@ curl_check_hdr (void *buffer, | |||
1145 | int domain_matched; | 1127 | int domain_matched; |
1146 | char *tok; | 1128 | char *tok; |
1147 | 1129 | ||
1148 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1130 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1149 | "Receiving HTTP response header from CURL\n"); | 1131 | "Receiving HTTP response header from CURL\n"); |
1150 | /* first, check TLS certificate */ | 1132 | /* first, check TLS certificate */ |
1151 | if ( (GNUNET_YES != s5r->ssl_checked) && | 1133 | if ((GNUNET_YES != s5r->ssl_checked) && |
1152 | (GNUNET_YES == s5r->is_tls)) | 1134 | (GNUNET_YES == s5r->is_tls)) |
1153 | //(HTTPS_PORT == s5r->port)) | 1135 | //(HTTPS_PORT == s5r->port)) |
1154 | { | 1136 | { |
1155 | if (GNUNET_OK != check_ssl_certificate (s5r)) | 1137 | if (GNUNET_OK != check_ssl_certificate(s5r)) |
1156 | return 0; | 1138 | return 0; |
1157 | } | 1139 | } |
1158 | ndup = GNUNET_strndup (buffer, | 1140 | ndup = GNUNET_strndup(buffer, |
1159 | bytes); | 1141 | bytes); |
1160 | hdr_type = strtok (ndup, | 1142 | hdr_type = strtok(ndup, |
1161 | ":"); | 1143 | ":"); |
1162 | if (NULL == hdr_type) | 1144 | if (NULL == hdr_type) |
1163 | { | 1145 | { |
1164 | GNUNET_free (ndup); | 1146 | GNUNET_free(ndup); |
1165 | return bytes; | 1147 | return bytes; |
1166 | } | 1148 | } |
1167 | hdr_val = strtok (NULL, | 1149 | hdr_val = strtok(NULL, |
1168 | ""); | 1150 | ""); |
1169 | if (NULL == hdr_val) | 1151 | if (NULL == hdr_val) |
1170 | { | 1152 | { |
1171 | GNUNET_free (ndup); | 1153 | GNUNET_free(ndup); |
1172 | return bytes; | 1154 | return bytes; |
1173 | } | 1155 | } |
1174 | if (' ' == *hdr_val) | 1156 | if (' ' == *hdr_val) |
1175 | hdr_val++; | 1157 | hdr_val++; |
1176 | 1158 | ||
1177 | /* custom logic for certain header types */ | 1159 | /* custom logic for certain header types */ |
1178 | new_cookie_hdr = NULL; | 1160 | new_cookie_hdr = NULL; |
1179 | if ( (NULL != s5r->leho) && | 1161 | if ((NULL != s5r->leho) && |
1180 | (0 == strcasecmp (hdr_type, | 1162 | (0 == strcasecmp(hdr_type, |
1181 | MHD_HTTP_HEADER_SET_COOKIE)) ) | 1163 | MHD_HTTP_HEADER_SET_COOKIE))) |
1182 | 1164 | ||
1183 | { | 1165 | { |
1184 | new_cookie_hdr = GNUNET_malloc (strlen (hdr_val) + | 1166 | new_cookie_hdr = GNUNET_malloc(strlen(hdr_val) + |
1185 | strlen (s5r->domain) + 1); | 1167 | strlen(s5r->domain) + 1); |
1186 | offset = 0; | 1168 | offset = 0; |
1187 | domain_matched = GNUNET_NO; /* make sure we match domain at most once */ | 1169 | domain_matched = GNUNET_NO; /* make sure we match domain at most once */ |
1188 | for (tok = strtok (hdr_val, ";"); NULL != tok; tok = strtok (NULL, ";")) | 1170 | for (tok = strtok(hdr_val, ";"); NULL != tok; tok = strtok(NULL, ";")) |
1189 | { | ||
1190 | if ( (0 == strncasecmp (tok, | ||
1191 | " domain", | ||
1192 | strlen (" domain"))) && | ||
1193 | (GNUNET_NO == domain_matched) ) | ||
1194 | { | ||
1195 | domain_matched = GNUNET_YES; | ||
1196 | cookie_domain = tok + strlen (" domain") + 1; | ||
1197 | if (strlen (cookie_domain) < strlen (s5r->leho)) | ||
1198 | { | 1171 | { |
1199 | delta_cdomain = strlen (s5r->leho) - strlen (cookie_domain); | 1172 | if ((0 == strncasecmp(tok, |
1200 | if (0 == strcasecmp (cookie_domain, | 1173 | " domain", |
1201 | s5r->leho + delta_cdomain)) | 1174 | strlen(" domain"))) && |
1202 | { | 1175 | (GNUNET_NO == domain_matched)) |
1203 | offset += sprintf (new_cookie_hdr + offset, | 1176 | { |
1204 | " domain=%s;", | 1177 | domain_matched = GNUNET_YES; |
1205 | s5r->domain); | 1178 | cookie_domain = tok + strlen(" domain") + 1; |
1206 | continue; | 1179 | if (strlen(cookie_domain) < strlen(s5r->leho)) |
1207 | } | 1180 | { |
1181 | delta_cdomain = strlen(s5r->leho) - strlen(cookie_domain); | ||
1182 | if (0 == strcasecmp(cookie_domain, | ||
1183 | s5r->leho + delta_cdomain)) | ||
1184 | { | ||
1185 | offset += sprintf(new_cookie_hdr + offset, | ||
1186 | " domain=%s;", | ||
1187 | s5r->domain); | ||
1188 | continue; | ||
1189 | } | ||
1190 | } | ||
1191 | else if (0 == strcmp(cookie_domain, | ||
1192 | s5r->leho)) | ||
1193 | { | ||
1194 | offset += sprintf(new_cookie_hdr + offset, | ||
1195 | " domain=%s;", | ||
1196 | s5r->domain); | ||
1197 | continue; | ||
1198 | } | ||
1199 | else if (('.' == cookie_domain[0]) && | ||
1200 | (0 == strcmp(&cookie_domain[1], | ||
1201 | s5r->leho))) | ||
1202 | { | ||
1203 | offset += sprintf(new_cookie_hdr + offset, | ||
1204 | " domain=.%s;", | ||
1205 | s5r->domain); | ||
1206 | continue; | ||
1207 | } | ||
1208 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
1209 | _("Cookie domain `%s' supplied by server is invalid\n"), | ||
1210 | tok); | ||
1211 | } | ||
1212 | GNUNET_memcpy(new_cookie_hdr + offset, | ||
1213 | tok, | ||
1214 | strlen(tok)); | ||
1215 | offset += strlen(tok); | ||
1216 | new_cookie_hdr[offset++] = ';'; | ||
1208 | } | 1217 | } |
1209 | else if (0 == strcmp (cookie_domain, | 1218 | hdr_val = new_cookie_hdr; |
1210 | s5r->leho)) | 1219 | } |
1220 | |||
1221 | new_location = NULL; | ||
1222 | if (0 == strcasecmp(MHD_HTTP_HEADER_TRANSFER_ENCODING, | ||
1223 | hdr_type)) | ||
1224 | { | ||
1225 | /* Ignore transfer encoding, set automatically by MHD if required */ | ||
1226 | goto cleanup; | ||
1227 | } | ||
1228 | if ((0 == strcasecmp(MHD_HTTP_HEADER_LOCATION, | ||
1229 | hdr_type))) | ||
1230 | { | ||
1231 | char *leho_host; | ||
1232 | |||
1233 | GNUNET_asprintf(&leho_host, | ||
1234 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) | ||
1235 | ? "http://%s" | ||
1236 | : "https://%s", | ||
1237 | s5r->leho); | ||
1238 | if (0 == strncmp(leho_host, | ||
1239 | hdr_val, | ||
1240 | strlen(leho_host))) | ||
1211 | { | 1241 | { |
1212 | offset += sprintf (new_cookie_hdr + offset, | 1242 | GNUNET_asprintf(&new_location, |
1213 | " domain=%s;", | 1243 | "%s%s%s", |
1214 | s5r->domain); | 1244 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) |
1215 | continue; | 1245 | ? "http://" |
1246 | : "https://", | ||
1247 | s5r->domain, | ||
1248 | hdr_val + strlen(leho_host)); | ||
1249 | hdr_val = new_location; | ||
1216 | } | 1250 | } |
1217 | else if ( ('.' == cookie_domain[0]) && | 1251 | GNUNET_free(leho_host); |
1218 | (0 == strcmp (&cookie_domain[1], | 1252 | } |
1219 | s5r->leho)) ) | 1253 | if (0 == strcasecmp(MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, |
1254 | hdr_type)) | ||
1255 | { | ||
1256 | char *leho_host; | ||
1257 | |||
1258 | GNUNET_asprintf(&leho_host, | ||
1259 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) | ||
1260 | ? "http://%s" | ||
1261 | : "https://%s", | ||
1262 | s5r->leho); | ||
1263 | if (0 == strncmp(leho_host, | ||
1264 | hdr_val, | ||
1265 | strlen(leho_host))) | ||
1220 | { | 1266 | { |
1221 | offset += sprintf (new_cookie_hdr + offset, | 1267 | GNUNET_asprintf(&new_location, |
1222 | " domain=.%s;", | 1268 | "%s%s", |
1223 | s5r->domain); | 1269 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) |
1224 | continue; | 1270 | ? "http://" |
1271 | : "https://", | ||
1272 | s5r->domain); | ||
1273 | hdr_val = new_location; | ||
1225 | } | 1274 | } |
1226 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1275 | GNUNET_free(leho_host); |
1227 | _("Cookie domain `%s' supplied by server is invalid\n"), | ||
1228 | tok); | ||
1229 | } | ||
1230 | GNUNET_memcpy (new_cookie_hdr + offset, | ||
1231 | tok, | ||
1232 | strlen (tok)); | ||
1233 | offset += strlen (tok); | ||
1234 | new_cookie_hdr[offset++] = ';'; | ||
1235 | } | 1276 | } |
1236 | hdr_val = new_cookie_hdr; | ||
1237 | } | ||
1238 | |||
1239 | new_location = NULL; | ||
1240 | if (0 == strcasecmp (MHD_HTTP_HEADER_TRANSFER_ENCODING, | ||
1241 | hdr_type)) | ||
1242 | { | ||
1243 | /* Ignore transfer encoding, set automatically by MHD if required */ | ||
1244 | goto cleanup; | ||
1245 | } | ||
1246 | if ((0 == strcasecmp (MHD_HTTP_HEADER_LOCATION, | ||
1247 | hdr_type))) | ||
1248 | { | ||
1249 | char *leho_host; | ||
1250 | |||
1251 | GNUNET_asprintf (&leho_host, | ||
1252 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) | ||
1253 | ? "http://%s" | ||
1254 | : "https://%s", | ||
1255 | s5r->leho); | ||
1256 | if (0 == strncmp (leho_host, | ||
1257 | hdr_val, | ||
1258 | strlen (leho_host))) | ||
1259 | { | ||
1260 | GNUNET_asprintf (&new_location, | ||
1261 | "%s%s%s", | ||
1262 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) | ||
1263 | ? "http://" | ||
1264 | : "https://", | ||
1265 | s5r->domain, | ||
1266 | hdr_val + strlen (leho_host)); | ||
1267 | hdr_val = new_location; | ||
1268 | } | ||
1269 | GNUNET_free (leho_host); | ||
1270 | } | ||
1271 | if (0 == strcasecmp (MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, | ||
1272 | hdr_type)) | ||
1273 | { | ||
1274 | char *leho_host; | ||
1275 | |||
1276 | GNUNET_asprintf (&leho_host, | ||
1277 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) | ||
1278 | ? "http://%s" | ||
1279 | : "https://%s", | ||
1280 | s5r->leho); | ||
1281 | if (0 == strncmp (leho_host, | ||
1282 | hdr_val, | ||
1283 | strlen (leho_host))) | ||
1284 | { | ||
1285 | GNUNET_asprintf (&new_location, | ||
1286 | "%s%s", | ||
1287 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) | ||
1288 | ? "http://" | ||
1289 | : "https://", | ||
1290 | s5r->domain); | ||
1291 | hdr_val = new_location; | ||
1292 | } | ||
1293 | GNUNET_free (leho_host); | ||
1294 | } | ||
1295 | 1277 | ||
1296 | /* MHD does not allow certain characters in values, remove those */ | 1278 | /* MHD does not allow certain characters in values, remove those */ |
1297 | if (NULL != (tok = strchr (hdr_val, '\n'))) | 1279 | if (NULL != (tok = strchr(hdr_val, '\n'))) |
1298 | *tok = '\0'; | 1280 | *tok = '\0'; |
1299 | if (NULL != (tok = strchr (hdr_val, '\r'))) | 1281 | if (NULL != (tok = strchr(hdr_val, '\r'))) |
1300 | *tok = '\0'; | 1282 | *tok = '\0'; |
1301 | if (NULL != (tok = strchr (hdr_val, '\t'))) | 1283 | if (NULL != (tok = strchr(hdr_val, '\t'))) |
1302 | *tok = '\0'; | 1284 | *tok = '\0'; |
1303 | if (0 != strlen (hdr_val)) /* Rely in MHD to set those */ | 1285 | if (0 != strlen(hdr_val)) /* Rely in MHD to set those */ |
1304 | { | 1286 | { |
1305 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1287 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1306 | "Adding header %s: %s to MHD response\n", | 1288 | "Adding header %s: %s to MHD response\n", |
1307 | hdr_type, | 1289 | hdr_type, |
1308 | hdr_val); | 1290 | hdr_val); |
1309 | header = GNUNET_new (struct HttpResponseHeader); | 1291 | header = GNUNET_new(struct HttpResponseHeader); |
1310 | header->type = GNUNET_strdup (hdr_type); | 1292 | header->type = GNUNET_strdup(hdr_type); |
1311 | header->value = GNUNET_strdup (hdr_val); | 1293 | header->value = GNUNET_strdup(hdr_val); |
1312 | GNUNET_CONTAINER_DLL_insert (s5r->header_head, | 1294 | GNUNET_CONTAINER_DLL_insert(s5r->header_head, |
1313 | s5r->header_tail, | 1295 | s5r->header_tail, |
1314 | header); | 1296 | header); |
1315 | } | 1297 | } |
1316 | cleanup: | 1298 | cleanup: |
1317 | GNUNET_free (ndup); | 1299 | GNUNET_free(ndup); |
1318 | GNUNET_free_non_null (new_cookie_hdr); | 1300 | GNUNET_free_non_null(new_cookie_hdr); |
1319 | GNUNET_free_non_null (new_location); | 1301 | GNUNET_free_non_null(new_location); |
1320 | return bytes; | 1302 | return bytes; |
1321 | } | 1303 | } |
1322 | 1304 | ||
@@ -1330,73 +1312,73 @@ curl_check_hdr (void *buffer, | |||
1330 | * already initialized before | 1312 | * already initialized before |
1331 | */ | 1313 | */ |
1332 | static int | 1314 | static int |
1333 | create_mhd_response_from_s5r (struct Socks5Request *s5r) | 1315 | create_mhd_response_from_s5r(struct Socks5Request *s5r) |
1334 | { | 1316 | { |
1335 | long resp_code; | 1317 | long resp_code; |
1336 | double content_length; | 1318 | double content_length; |
1337 | 1319 | ||
1338 | if (NULL != s5r->response) | 1320 | if (NULL != s5r->response) |
1339 | { | 1321 | { |
1340 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1322 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1341 | "Response already set!\n"); | 1323 | "Response already set!\n"); |
1342 | return GNUNET_SYSERR; | 1324 | return GNUNET_SYSERR; |
1343 | } | 1325 | } |
1344 | 1326 | ||
1345 | GNUNET_break (CURLE_OK == | 1327 | GNUNET_break(CURLE_OK == |
1346 | curl_easy_getinfo (s5r->curl, | 1328 | curl_easy_getinfo(s5r->curl, |
1347 | CURLINFO_RESPONSE_CODE, | 1329 | CURLINFO_RESPONSE_CODE, |
1348 | &resp_code)); | 1330 | &resp_code)); |
1349 | GNUNET_break (CURLE_OK == | 1331 | GNUNET_break(CURLE_OK == |
1350 | curl_easy_getinfo (s5r->curl, | 1332 | curl_easy_getinfo(s5r->curl, |
1351 | CURLINFO_CONTENT_LENGTH_DOWNLOAD, | 1333 | CURLINFO_CONTENT_LENGTH_DOWNLOAD, |
1352 | &content_length)); | 1334 | &content_length)); |
1353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1335 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1354 | "Creating MHD response with code %d and size %d for %s%s\n", | 1336 | "Creating MHD response with code %d and size %d for %s%s\n", |
1355 | (int) resp_code, | 1337 | (int)resp_code, |
1356 | (int) content_length, | 1338 | (int)content_length, |
1357 | s5r->domain, | 1339 | s5r->domain, |
1358 | s5r->url); | 1340 | s5r->url); |
1359 | s5r->response_code = resp_code; | 1341 | s5r->response_code = resp_code; |
1360 | s5r->response = MHD_create_response_from_callback ((-1 == content_length) | 1342 | s5r->response = MHD_create_response_from_callback((-1 == content_length) |
1361 | ? MHD_SIZE_UNKNOWN | 1343 | ? MHD_SIZE_UNKNOWN |
1362 | : content_length, | 1344 | : content_length, |
1363 | IO_BUFFERSIZE, | 1345 | IO_BUFFERSIZE, |
1364 | &mhd_content_cb, | 1346 | &mhd_content_cb, |
1365 | s5r, | 1347 | s5r, |
1366 | NULL); | 1348 | NULL); |
1367 | for (struct HttpResponseHeader *header = s5r->header_head; | 1349 | for (struct HttpResponseHeader *header = s5r->header_head; |
1368 | NULL != header; | 1350 | NULL != header; |
1369 | header = header->next) | 1351 | header = header->next) |
1370 | { | 1352 | { |
1371 | if (0 == strcasecmp (header->type, | 1353 | if (0 == strcasecmp(header->type, |
1372 | MHD_HTTP_HEADER_CONTENT_LENGTH)) | 1354 | MHD_HTTP_HEADER_CONTENT_LENGTH)) |
1373 | continue; /* MHD won't let us mess with those, for good reason */ | 1355 | continue; /* MHD won't let us mess with those, for good reason */ |
1374 | if ( (0 == strcasecmp (header->type, | 1356 | if ((0 == strcasecmp(header->type, |
1375 | MHD_HTTP_HEADER_TRANSFER_ENCODING)) && | 1357 | MHD_HTTP_HEADER_TRANSFER_ENCODING)) && |
1376 | ( (0 == strcasecmp (header->value, | 1358 | ((0 == strcasecmp(header->value, |
1377 | "identity")) || | 1359 | "identity")) || |
1378 | (0 == strcasecmp (header->value, | 1360 | (0 == strcasecmp(header->value, |
1379 | "chunked")) ) ) | 1361 | "chunked")))) |
1380 | continue; /* MHD won't let us mess with those, for good reason */ | 1362 | continue; /* MHD won't let us mess with those, for good reason */ |
1381 | if (MHD_YES != | 1363 | if (MHD_YES != |
1382 | MHD_add_response_header (s5r->response, | 1364 | MHD_add_response_header(s5r->response, |
1383 | header->type, | 1365 | header->type, |
1384 | header->value)) | 1366 | header->value)) |
1385 | { | 1367 | { |
1386 | GNUNET_break (0); | 1368 | GNUNET_break(0); |
1387 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1369 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1388 | "Failed to add header `%s:%s'\n", | 1370 | "Failed to add header `%s:%s'\n", |
1389 | header->type, | 1371 | header->type, |
1390 | header->value); | 1372 | header->value); |
1373 | } | ||
1391 | } | 1374 | } |
1392 | } | ||
1393 | /* force connection to be closed after each request, as we | 1375 | /* force connection to be closed after each request, as we |
1394 | do not support HTTP pipelining (yet, FIXME!) */ | 1376 | do not support HTTP pipelining (yet, FIXME!) */ |
1395 | /*GNUNET_break (MHD_YES == | 1377 | /*GNUNET_break (MHD_YES == |
1396 | MHD_add_response_header (s5r->response, | 1378 | MHD_add_response_header (s5r->response, |
1397 | MHD_HTTP_HEADER_CONNECTION, | 1379 | MHD_HTTP_HEADER_CONNECTION, |
1398 | "close"));*/ | 1380 | "close"));*/ |
1399 | MHD_resume_connection (s5r->con); | 1381 | MHD_resume_connection(s5r->con); |
1400 | s5r->suspended = GNUNET_NO; | 1382 | s5r->suspended = GNUNET_NO; |
1401 | return GNUNET_OK; | 1383 | return GNUNET_OK; |
1402 | } | 1384 | } |
@@ -1413,70 +1395,70 @@ create_mhd_response_from_s5r (struct Socks5Request *s5r) | |||
1413 | * @return number of bytes handled | 1395 | * @return number of bytes handled |
1414 | */ | 1396 | */ |
1415 | static size_t | 1397 | static size_t |
1416 | curl_download_cb (void *ptr, | 1398 | curl_download_cb(void *ptr, |
1417 | size_t size, | 1399 | size_t size, |
1418 | size_t nmemb, | 1400 | size_t nmemb, |
1419 | void* ctx) | 1401 | void* ctx) |
1420 | { | 1402 | { |
1421 | struct Socks5Request *s5r = ctx; | 1403 | struct Socks5Request *s5r = ctx; |
1422 | size_t total = size * nmemb; | 1404 | size_t total = size * nmemb; |
1423 | 1405 | ||
1424 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1406 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1425 | "Receiving %ux%u bytes for `%s%s' from cURL to download\n", | 1407 | "Receiving %ux%u bytes for `%s%s' from cURL to download\n", |
1426 | (unsigned int) size, | 1408 | (unsigned int)size, |
1427 | (unsigned int) nmemb, | 1409 | (unsigned int)nmemb, |
1428 | s5r->domain, | 1410 | s5r->domain, |
1429 | s5r->url); | 1411 | s5r->url); |
1430 | if (NULL == s5r->response) | 1412 | if (NULL == s5r->response) |
1431 | GNUNET_assert (GNUNET_OK == | 1413 | GNUNET_assert(GNUNET_OK == |
1432 | create_mhd_response_from_s5r (s5r)); | 1414 | create_mhd_response_from_s5r(s5r)); |
1433 | if ( (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) && | 1415 | if ((SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) && |
1434 | (0 == s5r->io_len)) | 1416 | (0 == s5r->io_len)) |
1435 | { | 1417 | { |
1436 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1418 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1437 | "Previous upload finished... starting DOWNLOAD.\n"); | 1419 | "Previous upload finished... starting DOWNLOAD.\n"); |
1438 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | 1420 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; |
1439 | } | 1421 | } |
1440 | if ( (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) || | 1422 | if ((SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) || |
1441 | (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) ) | 1423 | (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state)) |
1442 | { | 1424 | { |
1443 | /* we're still not done with the upload, do not yet | 1425 | /* we're still not done with the upload, do not yet |
1444 | start the download, the IO buffer is still full | 1426 | start the download, the IO buffer is still full |
1445 | with upload data. */ | 1427 | with upload data. */ |
1446 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1428 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1447 | "Pausing CURL download `%s%s', waiting for UPLOAD to finish\n", | 1429 | "Pausing CURL download `%s%s', waiting for UPLOAD to finish\n", |
1448 | s5r->domain, | 1430 | s5r->domain, |
1449 | s5r->url); | 1431 | s5r->url); |
1450 | s5r->curl_paused = GNUNET_YES; | 1432 | s5r->curl_paused = GNUNET_YES; |
1451 | return CURL_WRITEFUNC_PAUSE; /* not yet ready for data download */ | 1433 | return CURL_WRITEFUNC_PAUSE; /* not yet ready for data download */ |
1452 | } | 1434 | } |
1453 | if (sizeof (s5r->io_buf) - s5r->io_len < total) | 1435 | if (sizeof(s5r->io_buf) - s5r->io_len < total) |
1454 | { | 1436 | { |
1455 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1437 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1456 | "Pausing CURL `%s%s' download, not enough space %llu %llu %llu\n", | 1438 | "Pausing CURL `%s%s' download, not enough space %llu %llu %llu\n", |
1457 | s5r->domain, | 1439 | s5r->domain, |
1458 | s5r->url, | 1440 | s5r->url, |
1459 | (unsigned long long) sizeof (s5r->io_buf), | 1441 | (unsigned long long)sizeof(s5r->io_buf), |
1460 | (unsigned long long) s5r->io_len, | 1442 | (unsigned long long)s5r->io_len, |
1461 | (unsigned long long) total); | 1443 | (unsigned long long)total); |
1462 | s5r->curl_paused = GNUNET_YES; | 1444 | s5r->curl_paused = GNUNET_YES; |
1463 | return CURL_WRITEFUNC_PAUSE; /* not enough space */ | 1445 | return CURL_WRITEFUNC_PAUSE; /* not enough space */ |
1464 | } | 1446 | } |
1465 | GNUNET_memcpy (&s5r->io_buf[s5r->io_len], | 1447 | GNUNET_memcpy(&s5r->io_buf[s5r->io_len], |
1466 | ptr, | 1448 | ptr, |
1467 | total); | 1449 | total); |
1468 | s5r->io_len += total; | 1450 | s5r->io_len += total; |
1469 | if (GNUNET_YES == s5r->suspended) | 1451 | if (GNUNET_YES == s5r->suspended) |
1470 | { | 1452 | { |
1471 | MHD_resume_connection (s5r->con); | 1453 | MHD_resume_connection(s5r->con); |
1472 | s5r->suspended = GNUNET_NO; | 1454 | s5r->suspended = GNUNET_NO; |
1473 | } | 1455 | } |
1474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1456 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1475 | "Received %llu bytes of payload via cURL from %s\n", | 1457 | "Received %llu bytes of payload via cURL from %s\n", |
1476 | (unsigned long long) total, | 1458 | (unsigned long long)total, |
1477 | s5r->domain); | 1459 | s5r->domain); |
1478 | if (s5r->io_len == total) | 1460 | if (s5r->io_len == total) |
1479 | run_mhd_now (s5r->hd); | 1461 | run_mhd_now(s5r->hd); |
1480 | return total; | 1462 | return total; |
1481 | } | 1463 | } |
1482 | 1464 | ||
@@ -1492,64 +1474,64 @@ curl_download_cb (void *ptr, | |||
1492 | * @return number of bytes copied to @a buf | 1474 | * @return number of bytes copied to @a buf |
1493 | */ | 1475 | */ |
1494 | static size_t | 1476 | static size_t |
1495 | curl_upload_cb (void *buf, | 1477 | curl_upload_cb(void *buf, |
1496 | size_t size, | 1478 | size_t size, |
1497 | size_t nmemb, | 1479 | size_t nmemb, |
1498 | void *cls) | 1480 | void *cls) |
1499 | { | 1481 | { |
1500 | struct Socks5Request *s5r = cls; | 1482 | struct Socks5Request *s5r = cls; |
1501 | size_t len = size * nmemb; | 1483 | size_t len = size * nmemb; |
1502 | size_t to_copy; | 1484 | size_t to_copy; |
1503 | 1485 | ||
1504 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1486 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1505 | "Receiving %ux%u bytes for `%s%s' from cURL to upload\n", | 1487 | "Receiving %ux%u bytes for `%s%s' from cURL to upload\n", |
1506 | (unsigned int) size, | 1488 | (unsigned int)size, |
1507 | (unsigned int) nmemb, | 1489 | (unsigned int)nmemb, |
1508 | s5r->domain, | 1490 | s5r->domain, |
1509 | s5r->url); | 1491 | s5r->url); |
1510 | 1492 | ||
1511 | if ( (0 == s5r->io_len) && | 1493 | if ((0 == s5r->io_len) && |
1512 | (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state) ) | 1494 | (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state)) |
1513 | { | ||
1514 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1515 | "Pausing CURL UPLOAD %s%s, need more data\n", | ||
1516 | s5r->domain, | ||
1517 | s5r->url); | ||
1518 | return CURL_READFUNC_PAUSE; | ||
1519 | } | ||
1520 | if ( (0 == s5r->io_len) && | ||
1521 | (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) ) | ||
1522 | { | ||
1523 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | ||
1524 | if (GNUNET_YES == s5r->curl_paused) | ||
1525 | { | 1495 | { |
1526 | s5r->curl_paused = GNUNET_NO; | 1496 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1527 | curl_easy_pause (s5r->curl, | 1497 | "Pausing CURL UPLOAD %s%s, need more data\n", |
1528 | CURLPAUSE_CONT); | 1498 | s5r->domain, |
1529 | } | 1499 | s5r->url); |
1530 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1500 | return CURL_READFUNC_PAUSE; |
1531 | "Completed CURL UPLOAD %s%s\n", | 1501 | } |
1532 | s5r->domain, | 1502 | if ((0 == s5r->io_len) && |
1533 | s5r->url); | 1503 | (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state)) |
1534 | return 0; /* upload finished, can now download */ | 1504 | { |
1535 | } | 1505 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; |
1536 | if ( (SOCKS5_SOCKET_UPLOAD_STARTED != s5r->state) && | 1506 | if (GNUNET_YES == s5r->curl_paused) |
1537 | (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state) ) | 1507 | { |
1538 | { | 1508 | s5r->curl_paused = GNUNET_NO; |
1539 | GNUNET_break (0); | 1509 | curl_easy_pause(s5r->curl, |
1540 | return CURL_READFUNC_ABORT; | 1510 | CURLPAUSE_CONT); |
1541 | } | 1511 | } |
1542 | to_copy = GNUNET_MIN (s5r->io_len, | 1512 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1543 | len); | 1513 | "Completed CURL UPLOAD %s%s\n", |
1544 | GNUNET_memcpy (buf, | 1514 | s5r->domain, |
1545 | s5r->io_buf, | 1515 | s5r->url); |
1546 | to_copy); | 1516 | return 0; /* upload finished, can now download */ |
1547 | memmove (s5r->io_buf, | 1517 | } |
1548 | &s5r->io_buf[to_copy], | 1518 | if ((SOCKS5_SOCKET_UPLOAD_STARTED != s5r->state) && |
1549 | s5r->io_len - to_copy); | 1519 | (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state)) |
1520 | { | ||
1521 | GNUNET_break(0); | ||
1522 | return CURL_READFUNC_ABORT; | ||
1523 | } | ||
1524 | to_copy = GNUNET_MIN(s5r->io_len, | ||
1525 | len); | ||
1526 | GNUNET_memcpy(buf, | ||
1527 | s5r->io_buf, | ||
1528 | to_copy); | ||
1529 | memmove(s5r->io_buf, | ||
1530 | &s5r->io_buf[to_copy], | ||
1531 | s5r->io_len - to_copy); | ||
1550 | s5r->io_len -= to_copy; | 1532 | s5r->io_len -= to_copy; |
1551 | if (s5r->io_len + to_copy == sizeof (s5r->io_buf)) | 1533 | if (s5r->io_len + to_copy == sizeof(s5r->io_buf)) |
1552 | run_mhd_now (s5r->hd); /* got more space for upload now */ | 1534 | run_mhd_now(s5r->hd); /* got more space for upload now */ |
1553 | return to_copy; | 1535 | return to_copy; |
1554 | } | 1536 | } |
1555 | 1537 | ||
@@ -1564,14 +1546,14 @@ curl_upload_cb (void *buf, | |||
1564 | * @param cls closure | 1546 | * @param cls closure |
1565 | */ | 1547 | */ |
1566 | static void | 1548 | static void |
1567 | curl_task_download (void *cls); | 1549 | curl_task_download(void *cls); |
1568 | 1550 | ||
1569 | 1551 | ||
1570 | /** | 1552 | /** |
1571 | * Ask cURL for the select() sets and schedule cURL operations. | 1553 | * Ask cURL for the select() sets and schedule cURL operations. |
1572 | */ | 1554 | */ |
1573 | static void | 1555 | static void |
1574 | curl_download_prepare () | 1556 | curl_download_prepare() |
1575 | { | 1557 | { |
1576 | CURLMcode mret; | 1558 | CURLMcode mret; |
1577 | fd_set rs; | 1559 | fd_set rs; |
@@ -1583,63 +1565,63 @@ curl_download_prepare () | |||
1583 | long to; | 1565 | long to; |
1584 | struct GNUNET_TIME_Relative rtime; | 1566 | struct GNUNET_TIME_Relative rtime; |
1585 | 1567 | ||
1586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1568 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1587 | "Scheduling CURL interaction\n"); | 1569 | "Scheduling CURL interaction\n"); |
1588 | if (NULL != curl_download_task) | 1570 | if (NULL != curl_download_task) |
1589 | { | 1571 | { |
1590 | GNUNET_SCHEDULER_cancel (curl_download_task); | 1572 | GNUNET_SCHEDULER_cancel(curl_download_task); |
1591 | curl_download_task = NULL; | 1573 | curl_download_task = NULL; |
1592 | } | 1574 | } |
1593 | max = -1; | 1575 | max = -1; |
1594 | FD_ZERO (&rs); | 1576 | FD_ZERO(&rs); |
1595 | FD_ZERO (&ws); | 1577 | FD_ZERO(&ws); |
1596 | FD_ZERO (&es); | 1578 | FD_ZERO(&es); |
1597 | if (CURLM_OK != (mret = curl_multi_fdset (curl_multi, | 1579 | if (CURLM_OK != (mret = curl_multi_fdset(curl_multi, |
1598 | &rs, | 1580 | &rs, |
1599 | &ws, | 1581 | &ws, |
1600 | &es, | 1582 | &es, |
1601 | &max))) | 1583 | &max))) |
1602 | { | 1584 | { |
1603 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1585 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1604 | "%s failed at %s:%d: `%s'\n", | 1586 | "%s failed at %s:%d: `%s'\n", |
1605 | "curl_multi_fdset", __FILE__, __LINE__, | 1587 | "curl_multi_fdset", __FILE__, __LINE__, |
1606 | curl_multi_strerror (mret)); | 1588 | curl_multi_strerror(mret)); |
1607 | return; | 1589 | return; |
1608 | } | 1590 | } |
1609 | to = -1; | 1591 | to = -1; |
1610 | GNUNET_break (CURLM_OK == | 1592 | GNUNET_break(CURLM_OK == |
1611 | curl_multi_timeout (curl_multi, | 1593 | curl_multi_timeout(curl_multi, |
1612 | &to)); | 1594 | &to)); |
1613 | if (-1 == to) | 1595 | if (-1 == to) |
1614 | rtime = GNUNET_TIME_UNIT_FOREVER_REL; | 1596 | rtime = GNUNET_TIME_UNIT_FOREVER_REL; |
1615 | else | 1597 | else |
1616 | rtime = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 1598 | rtime = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, |
1617 | to); | 1599 | to); |
1618 | if (-1 != max) | 1600 | if (-1 != max) |
1619 | { | 1601 | { |
1620 | grs = GNUNET_NETWORK_fdset_create (); | 1602 | grs = GNUNET_NETWORK_fdset_create(); |
1621 | gws = GNUNET_NETWORK_fdset_create (); | 1603 | gws = GNUNET_NETWORK_fdset_create(); |
1622 | GNUNET_NETWORK_fdset_copy_native (grs, | 1604 | GNUNET_NETWORK_fdset_copy_native(grs, |
1623 | &rs, | 1605 | &rs, |
1624 | max + 1); | 1606 | max + 1); |
1625 | GNUNET_NETWORK_fdset_copy_native (gws, | 1607 | GNUNET_NETWORK_fdset_copy_native(gws, |
1626 | &ws, | 1608 | &ws, |
1627 | max + 1); | 1609 | max + 1); |
1628 | curl_download_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 1610 | curl_download_task = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
1629 | rtime, | 1611 | rtime, |
1630 | grs, | 1612 | grs, |
1631 | gws, | 1613 | gws, |
1632 | &curl_task_download, | ||
1633 | curl_multi); | ||
1634 | GNUNET_NETWORK_fdset_destroy (gws); | ||
1635 | GNUNET_NETWORK_fdset_destroy (grs); | ||
1636 | } | ||
1637 | else | ||
1638 | { | ||
1639 | curl_download_task = GNUNET_SCHEDULER_add_delayed (rtime, | ||
1640 | &curl_task_download, | 1614 | &curl_task_download, |
1641 | curl_multi); | 1615 | curl_multi); |
1642 | } | 1616 | GNUNET_NETWORK_fdset_destroy(gws); |
1617 | GNUNET_NETWORK_fdset_destroy(grs); | ||
1618 | } | ||
1619 | else | ||
1620 | { | ||
1621 | curl_download_task = GNUNET_SCHEDULER_add_delayed(rtime, | ||
1622 | &curl_task_download, | ||
1623 | curl_multi); | ||
1624 | } | ||
1643 | } | 1625 | } |
1644 | 1626 | ||
1645 | 1627 | ||
@@ -1649,7 +1631,7 @@ curl_download_prepare () | |||
1649 | * @param cls closure, NULL | 1631 | * @param cls closure, NULL |
1650 | */ | 1632 | */ |
1651 | static void | 1633 | static void |
1652 | curl_task_download (void *cls) | 1634 | curl_task_download(void *cls) |
1653 | { | 1635 | { |
1654 | int running; | 1636 | int running; |
1655 | int msgnum; | 1637 | int msgnum; |
@@ -1658,103 +1640,109 @@ curl_task_download (void *cls) | |||
1658 | struct Socks5Request *s5r; | 1640 | struct Socks5Request *s5r; |
1659 | 1641 | ||
1660 | curl_download_task = NULL; | 1642 | curl_download_task = NULL; |
1661 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1643 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1662 | "Running CURL interaction\n"); | 1644 | "Running CURL interaction\n"); |
1663 | do | 1645 | do |
1664 | { | 1646 | { |
1665 | running = 0; | 1647 | running = 0; |
1666 | mret = curl_multi_perform (curl_multi, | 1648 | mret = curl_multi_perform(curl_multi, |
1667 | &running); | 1649 | &running); |
1668 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1650 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1669 | "Checking CURL multi status: %d\n", | 1651 | "Checking CURL multi status: %d\n", |
1670 | mret); | 1652 | mret); |
1671 | while (NULL != (msg = curl_multi_info_read (curl_multi, | 1653 | while (NULL != (msg = curl_multi_info_read(curl_multi, |
1672 | &msgnum))) | 1654 | &msgnum))) |
1673 | { | 1655 | { |
1674 | GNUNET_break (CURLE_OK == | 1656 | GNUNET_break(CURLE_OK == |
1675 | curl_easy_getinfo (msg->easy_handle, | 1657 | curl_easy_getinfo(msg->easy_handle, |
1676 | CURLINFO_PRIVATE, | 1658 | CURLINFO_PRIVATE, |
1677 | (char **) &s5r )); | 1659 | (char **)&s5r)); |
1678 | if (NULL == s5r) | 1660 | if (NULL == s5r) |
1679 | { | 1661 | { |
1680 | GNUNET_break (0); | 1662 | GNUNET_break(0); |
1681 | continue; | 1663 | continue; |
1682 | } | 1664 | } |
1683 | switch (msg->msg) | 1665 | switch (msg->msg) |
1684 | { | 1666 | { |
1685 | case CURLMSG_NONE: | 1667 | case CURLMSG_NONE: |
1686 | /* documentation says this is not used */ | 1668 | /* documentation says this is not used */ |
1687 | GNUNET_break (0); | 1669 | GNUNET_break(0); |
1688 | break; | 1670 | break; |
1689 | case CURLMSG_DONE: | 1671 | |
1690 | switch (msg->data.result) | 1672 | case CURLMSG_DONE: |
1691 | { | 1673 | switch (msg->data.result) |
1692 | case CURLE_OK: | 1674 | { |
1693 | case CURLE_GOT_NOTHING: | 1675 | case CURLE_OK: |
1694 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1676 | case CURLE_GOT_NOTHING: |
1695 | "CURL download %s%s completed.\n", | 1677 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1696 | s5r->domain, | 1678 | "CURL download %s%s completed.\n", |
1697 | s5r->url); | 1679 | s5r->domain, |
1680 | s5r->url); | ||
1681 | if (NULL == s5r->response) | ||
1682 | { | ||
1683 | GNUNET_assert(GNUNET_OK == | ||
1684 | create_mhd_response_from_s5r(s5r)); | ||
1685 | } | ||
1686 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE; | ||
1687 | if (GNUNET_YES == s5r->suspended) | ||
1688 | { | ||
1689 | MHD_resume_connection(s5r->con); | ||
1690 | s5r->suspended = GNUNET_NO; | ||
1691 | } | ||
1692 | run_mhd_now(s5r->hd); | ||
1693 | break; | ||
1694 | |||
1695 | default: | ||
1696 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1697 | "Download curl %s%s failed: %s\n", | ||
1698 | s5r->domain, | ||
1699 | s5r->url, | ||
1700 | curl_easy_strerror(msg->data.result)); | ||
1701 | /* FIXME: indicate error somehow? close MHD connection badly as well? */ | ||
1702 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE; | ||
1703 | if (GNUNET_YES == s5r->suspended) | ||
1704 | { | ||
1705 | MHD_resume_connection(s5r->con); | ||
1706 | s5r->suspended = GNUNET_NO; | ||
1707 | } | ||
1708 | run_mhd_now(s5r->hd); | ||
1709 | break; | ||
1710 | } | ||
1698 | if (NULL == s5r->response) | 1711 | if (NULL == s5r->response) |
1699 | { | 1712 | s5r->response = curl_failure_response; |
1700 | GNUNET_assert (GNUNET_OK == | ||
1701 | create_mhd_response_from_s5r (s5r)); | ||
1702 | } | ||
1703 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE; | ||
1704 | if (GNUNET_YES == s5r->suspended) | ||
1705 | { | ||
1706 | MHD_resume_connection (s5r->con); | ||
1707 | s5r->suspended = GNUNET_NO; | ||
1708 | } | ||
1709 | run_mhd_now (s5r->hd); | ||
1710 | break; | 1713 | break; |
1714 | |||
1715 | case CURLMSG_LAST: | ||
1716 | /* documentation says this is not used */ | ||
1717 | GNUNET_break(0); | ||
1718 | break; | ||
1719 | |||
1711 | default: | 1720 | default: |
1712 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1721 | /* unexpected status code */ |
1713 | "Download curl %s%s failed: %s\n", | 1722 | GNUNET_break(0); |
1714 | s5r->domain, | ||
1715 | s5r->url, | ||
1716 | curl_easy_strerror (msg->data.result)); | ||
1717 | /* FIXME: indicate error somehow? close MHD connection badly as well? */ | ||
1718 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE; | ||
1719 | if (GNUNET_YES == s5r->suspended) | ||
1720 | { | ||
1721 | MHD_resume_connection (s5r->con); | ||
1722 | s5r->suspended = GNUNET_NO; | ||
1723 | } | ||
1724 | run_mhd_now (s5r->hd); | ||
1725 | break; | 1723 | break; |
1726 | } | 1724 | } |
1727 | if (NULL == s5r->response) | 1725 | } |
1728 | s5r->response = curl_failure_response; | 1726 | ; |
1729 | break; | 1727 | } |
1730 | case CURLMSG_LAST: | 1728 | while (mret == CURLM_CALL_MULTI_PERFORM); |
1731 | /* documentation says this is not used */ | ||
1732 | GNUNET_break (0); | ||
1733 | break; | ||
1734 | default: | ||
1735 | /* unexpected status code */ | ||
1736 | GNUNET_break (0); | ||
1737 | break; | ||
1738 | } | ||
1739 | }; | ||
1740 | } while (mret == CURLM_CALL_MULTI_PERFORM); | ||
1741 | if (CURLM_OK != mret) | 1729 | if (CURLM_OK != mret) |
1742 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1730 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1743 | "%s failed at %s:%d: `%s'\n", | 1731 | "%s failed at %s:%d: `%s'\n", |
1744 | "curl_multi_perform", __FILE__, __LINE__, | 1732 | "curl_multi_perform", __FILE__, __LINE__, |
1745 | curl_multi_strerror (mret)); | 1733 | curl_multi_strerror(mret)); |
1746 | if (0 == running) | 1734 | if (0 == running) |
1747 | { | ||
1748 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1749 | "Suspending cURL multi loop, no more events pending\n"); | ||
1750 | if (NULL != curl_download_task) | ||
1751 | { | 1735 | { |
1752 | GNUNET_SCHEDULER_cancel (curl_download_task); | 1736 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1753 | curl_download_task = NULL; | 1737 | "Suspending cURL multi loop, no more events pending\n"); |
1738 | if (NULL != curl_download_task) | ||
1739 | { | ||
1740 | GNUNET_SCHEDULER_cancel(curl_download_task); | ||
1741 | curl_download_task = NULL; | ||
1742 | } | ||
1743 | return; /* nothing more in progress */ | ||
1754 | } | 1744 | } |
1755 | return; /* nothing more in progress */ | 1745 | curl_download_prepare(); |
1756 | } | ||
1757 | curl_download_prepare (); | ||
1758 | } | 1746 | } |
1759 | 1747 | ||
1760 | 1748 | ||
@@ -1775,28 +1763,28 @@ curl_task_download (void *cls) | |||
1775 | * @return #MHD_YES to continue to iterate | 1763 | * @return #MHD_YES to continue to iterate |
1776 | */ | 1764 | */ |
1777 | static int | 1765 | static int |
1778 | con_val_iter (void *cls, | 1766 | con_val_iter(void *cls, |
1779 | enum MHD_ValueKind kind, | 1767 | enum MHD_ValueKind kind, |
1780 | const char *key, | 1768 | const char *key, |
1781 | const char *value) | 1769 | const char *value) |
1782 | { | 1770 | { |
1783 | struct Socks5Request *s5r = cls; | 1771 | struct Socks5Request *s5r = cls; |
1784 | char *hdr; | 1772 | char *hdr; |
1785 | 1773 | ||
1786 | if ( (0 == strcasecmp (MHD_HTTP_HEADER_HOST, | 1774 | if ((0 == strcasecmp(MHD_HTTP_HEADER_HOST, |
1787 | key)) && | 1775 | key)) && |
1788 | (NULL != s5r->leho) ) | 1776 | (NULL != s5r->leho)) |
1789 | value = s5r->leho; | 1777 | value = s5r->leho; |
1790 | GNUNET_asprintf (&hdr, | 1778 | GNUNET_asprintf(&hdr, |
1791 | "%s: %s", | 1779 | "%s: %s", |
1792 | key, | 1780 | key, |
1793 | value); | 1781 | value); |
1794 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1782 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1795 | "Adding HEADER `%s' to HTTP request\n", | 1783 | "Adding HEADER `%s' to HTTP request\n", |
1796 | hdr); | 1784 | hdr); |
1797 | s5r->headers = curl_slist_append (s5r->headers, | 1785 | s5r->headers = curl_slist_append(s5r->headers, |
1798 | hdr); | 1786 | hdr); |
1799 | GNUNET_free (hdr); | 1787 | GNUNET_free(hdr); |
1800 | return MHD_YES; | 1788 | return MHD_YES; |
1801 | } | 1789 | } |
1802 | 1790 | ||
@@ -1825,14 +1813,14 @@ con_val_iter (void *cls, | |||
1825 | * error while handling the request | 1813 | * error while handling the request |
1826 | */ | 1814 | */ |
1827 | static int | 1815 | static int |
1828 | create_response (void *cls, | 1816 | create_response(void *cls, |
1829 | struct MHD_Connection *con, | 1817 | struct MHD_Connection *con, |
1830 | const char *url, | 1818 | const char *url, |
1831 | const char *meth, | 1819 | const char *meth, |
1832 | const char *ver, | 1820 | const char *ver, |
1833 | const char *upload_data, | 1821 | const char *upload_data, |
1834 | size_t *upload_data_size, | 1822 | size_t *upload_data_size, |
1835 | void **con_cls) | 1823 | void **con_cls) |
1836 | { | 1824 | { |
1837 | struct Socks5Request *s5r = *con_cls; | 1825 | struct Socks5Request *s5r = *con_cls; |
1838 | char *curlurl; | 1826 | char *curlurl; |
@@ -1845,412 +1833,415 @@ create_response (void *cls, | |||
1845 | size_t left; | 1833 | size_t left; |
1846 | 1834 | ||
1847 | if (NULL == s5r) | 1835 | if (NULL == s5r) |
1848 | { | 1836 | { |
1849 | GNUNET_break (0); | 1837 | GNUNET_break(0); |
1850 | return MHD_NO; | 1838 | return MHD_NO; |
1851 | } | 1839 | } |
1852 | s5r->con = con; | 1840 | s5r->con = con; |
1853 | /* Fresh connection. */ | 1841 | /* Fresh connection. */ |
1854 | if (SOCKS5_SOCKET_WITH_MHD == s5r->state) | 1842 | if (SOCKS5_SOCKET_WITH_MHD == s5r->state) |
1855 | { | ||
1856 | /* first time here, initialize curl handle */ | ||
1857 | if (s5r->is_gns) | ||
1858 | { | 1843 | { |
1859 | sa = (const struct sockaddr *) &s5r->destination_address; | 1844 | /* first time here, initialize curl handle */ |
1860 | switch (sa->sa_family) | 1845 | if (s5r->is_gns) |
1861 | { | ||
1862 | case AF_INET: | ||
1863 | s4 = (const struct sockaddr_in *) &s5r->destination_address; | ||
1864 | if (NULL == inet_ntop (AF_INET, | ||
1865 | &s4->sin_addr, | ||
1866 | ipstring, | ||
1867 | sizeof (ipstring))) | ||
1868 | { | 1846 | { |
1869 | GNUNET_break (0); | 1847 | sa = (const struct sockaddr *)&s5r->destination_address; |
1870 | return MHD_NO; | 1848 | switch (sa->sa_family) |
1849 | { | ||
1850 | case AF_INET: | ||
1851 | s4 = (const struct sockaddr_in *)&s5r->destination_address; | ||
1852 | if (NULL == inet_ntop(AF_INET, | ||
1853 | &s4->sin_addr, | ||
1854 | ipstring, | ||
1855 | sizeof(ipstring))) | ||
1856 | { | ||
1857 | GNUNET_break(0); | ||
1858 | return MHD_NO; | ||
1859 | } | ||
1860 | GNUNET_snprintf(ipaddr, | ||
1861 | sizeof(ipaddr), | ||
1862 | "%s", | ||
1863 | ipstring); | ||
1864 | port = ntohs(s4->sin_port); | ||
1865 | break; | ||
1866 | |||
1867 | case AF_INET6: | ||
1868 | s6 = (const struct sockaddr_in6 *)&s5r->destination_address; | ||
1869 | if (NULL == inet_ntop(AF_INET6, | ||
1870 | &s6->sin6_addr, | ||
1871 | ipstring, | ||
1872 | sizeof(ipstring))) | ||
1873 | { | ||
1874 | GNUNET_break(0); | ||
1875 | return MHD_NO; | ||
1876 | } | ||
1877 | GNUNET_snprintf(ipaddr, | ||
1878 | sizeof(ipaddr), | ||
1879 | "%s", | ||
1880 | ipstring); | ||
1881 | port = ntohs(s6->sin6_port); | ||
1882 | break; | ||
1883 | |||
1884 | default: | ||
1885 | GNUNET_break(0); | ||
1886 | return MHD_NO; | ||
1887 | } | ||
1871 | } | 1888 | } |
1872 | GNUNET_snprintf (ipaddr, | 1889 | else |
1873 | sizeof (ipaddr), | ||
1874 | "%s", | ||
1875 | ipstring); | ||
1876 | port = ntohs (s4->sin_port); | ||
1877 | break; | ||
1878 | case AF_INET6: | ||
1879 | s6 = (const struct sockaddr_in6 *) &s5r->destination_address; | ||
1880 | if (NULL == inet_ntop (AF_INET6, | ||
1881 | &s6->sin6_addr, | ||
1882 | ipstring, | ||
1883 | sizeof (ipstring))) | ||
1884 | { | 1890 | { |
1885 | GNUNET_break (0); | 1891 | port = s5r->port; |
1886 | return MHD_NO; | ||
1887 | } | 1892 | } |
1888 | GNUNET_snprintf (ipaddr, | 1893 | if (NULL == s5r->curl) |
1889 | sizeof (ipaddr), | 1894 | s5r->curl = curl_easy_init(); |
1890 | "%s", | 1895 | if (NULL == s5r->curl) |
1891 | ipstring); | 1896 | return MHD_queue_response(con, |
1892 | port = ntohs (s6->sin6_port); | 1897 | MHD_HTTP_INTERNAL_SERVER_ERROR, |
1893 | break; | 1898 | curl_failure_response); |
1894 | default: | 1899 | curl_easy_setopt(s5r->curl, |
1895 | GNUNET_break (0); | 1900 | CURLOPT_HEADERFUNCTION, |
1896 | return MHD_NO; | 1901 | &curl_check_hdr); |
1897 | } | 1902 | curl_easy_setopt(s5r->curl, |
1898 | } | 1903 | CURLOPT_HEADERDATA, |
1899 | else | 1904 | s5r); |
1900 | { | 1905 | curl_easy_setopt(s5r->curl, |
1901 | port = s5r->port; | 1906 | CURLOPT_FOLLOWLOCATION, |
1902 | } | 1907 | 0); |
1903 | if (NULL == s5r->curl) | 1908 | if (s5r->is_gns) |
1904 | s5r->curl = curl_easy_init (); | 1909 | curl_easy_setopt(s5r->curl, |
1905 | if (NULL == s5r->curl) | 1910 | CURLOPT_IPRESOLVE, |
1906 | return MHD_queue_response (con, | 1911 | CURL_IPRESOLVE_V4); |
1907 | MHD_HTTP_INTERNAL_SERVER_ERROR, | 1912 | curl_easy_setopt(s5r->curl, |
1908 | curl_failure_response); | 1913 | CURLOPT_CONNECTTIMEOUT, |
1909 | curl_easy_setopt (s5r->curl, | 1914 | 600L); |
1910 | CURLOPT_HEADERFUNCTION, | 1915 | curl_easy_setopt(s5r->curl, |
1911 | &curl_check_hdr); | 1916 | CURLOPT_TIMEOUT, |
1912 | curl_easy_setopt (s5r->curl, | 1917 | 600L); |
1913 | CURLOPT_HEADERDATA, | 1918 | curl_easy_setopt(s5r->curl, |
1914 | s5r); | 1919 | CURLOPT_NOSIGNAL, |
1915 | curl_easy_setopt (s5r->curl, | 1920 | 1L); |
1916 | CURLOPT_FOLLOWLOCATION, | 1921 | curl_easy_setopt(s5r->curl, |
1917 | 0); | 1922 | CURLOPT_HTTP_CONTENT_DECODING, |
1918 | if (s5r->is_gns) | 1923 | 0); |
1919 | curl_easy_setopt (s5r->curl, | 1924 | curl_easy_setopt(s5r->curl, |
1920 | CURLOPT_IPRESOLVE, | 1925 | CURLOPT_NOSIGNAL, |
1921 | CURL_IPRESOLVE_V4); | 1926 | 1L); |
1922 | curl_easy_setopt (s5r->curl, | 1927 | curl_easy_setopt(s5r->curl, |
1923 | CURLOPT_CONNECTTIMEOUT, | 1928 | CURLOPT_PRIVATE, |
1924 | 600L); | 1929 | s5r); |
1925 | curl_easy_setopt (s5r->curl, | 1930 | curl_easy_setopt(s5r->curl, |
1926 | CURLOPT_TIMEOUT, | 1931 | CURLOPT_VERBOSE, |
1927 | 600L); | 1932 | 0L); |
1928 | curl_easy_setopt (s5r->curl, | 1933 | /** |
1929 | CURLOPT_NOSIGNAL, | 1934 | * Pre-populate cache to resolve Hostname. |
1930 | 1L); | 1935 | * This is necessary as the DNS name in the CURLOPT_URL is used |
1931 | curl_easy_setopt (s5r->curl, | 1936 | * for SNI http://de.wikipedia.org/wiki/Server_Name_Indication |
1932 | CURLOPT_HTTP_CONTENT_DECODING, | 1937 | */ |
1933 | 0); | 1938 | if (NULL != s5r->leho) |
1934 | curl_easy_setopt (s5r->curl, | ||
1935 | CURLOPT_NOSIGNAL, | ||
1936 | 1L); | ||
1937 | curl_easy_setopt (s5r->curl, | ||
1938 | CURLOPT_PRIVATE, | ||
1939 | s5r); | ||
1940 | curl_easy_setopt (s5r->curl, | ||
1941 | CURLOPT_VERBOSE, | ||
1942 | 0L); | ||
1943 | /** | ||
1944 | * Pre-populate cache to resolve Hostname. | ||
1945 | * This is necessary as the DNS name in the CURLOPT_URL is used | ||
1946 | * for SNI http://de.wikipedia.org/wiki/Server_Name_Indication | ||
1947 | */ | ||
1948 | if (NULL != s5r->leho) | ||
1949 | { | ||
1950 | char *curl_hosts; | ||
1951 | |||
1952 | GNUNET_asprintf (&curl_hosts, | ||
1953 | "%s:%d:%s", | ||
1954 | s5r->leho, | ||
1955 | port, | ||
1956 | ipaddr); | ||
1957 | s5r->hosts = curl_slist_append (NULL, | ||
1958 | curl_hosts); | ||
1959 | curl_easy_setopt (s5r->curl, | ||
1960 | CURLOPT_RESOLVE, | ||
1961 | s5r->hosts); | ||
1962 | GNUNET_free (curl_hosts); | ||
1963 | } | ||
1964 | if (s5r->is_gns) | ||
1965 | { | ||
1966 | GNUNET_asprintf (&curlurl, | ||
1967 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) | ||
1968 | ? "http://%s:%d%s" | ||
1969 | : "https://%s:%d%s", | ||
1970 | (NULL != s5r->leho) | ||
1971 | ? s5r->leho | ||
1972 | : ipaddr, | ||
1973 | port, | ||
1974 | s5r->url); | ||
1975 | } | ||
1976 | else | ||
1977 | { | ||
1978 | GNUNET_asprintf (&curlurl, | ||
1979 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) | ||
1980 | ? "http://%s:%d%s" | ||
1981 | : "https://%s:%d%s", | ||
1982 | s5r->domain, | ||
1983 | port, | ||
1984 | s5r->url); | ||
1985 | } | ||
1986 | curl_easy_setopt (s5r->curl, | ||
1987 | CURLOPT_URL, | ||
1988 | curlurl); | ||
1989 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1990 | "Launching %s CURL interaction, fetching `%s'\n", | ||
1991 | (s5r->is_gns) ? "GNS" : "DNS", | ||
1992 | curlurl); | ||
1993 | GNUNET_free (curlurl); | ||
1994 | if (0 == strcasecmp (meth, | ||
1995 | MHD_HTTP_METHOD_PUT)) | ||
1996 | { | ||
1997 | s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED; | ||
1998 | curl_easy_setopt (s5r->curl, | ||
1999 | CURLOPT_UPLOAD, | ||
2000 | 1L); | ||
2001 | curl_easy_setopt (s5r->curl, | ||
2002 | CURLOPT_WRITEFUNCTION, | ||
2003 | &curl_download_cb); | ||
2004 | curl_easy_setopt (s5r->curl, | ||
2005 | CURLOPT_WRITEDATA, | ||
2006 | s5r); | ||
2007 | GNUNET_assert (CURLE_OK == | ||
2008 | curl_easy_setopt (s5r->curl, | ||
2009 | CURLOPT_READFUNCTION, | ||
2010 | &curl_upload_cb)); | ||
2011 | curl_easy_setopt (s5r->curl, | ||
2012 | CURLOPT_READDATA, | ||
2013 | s5r); | ||
2014 | { | ||
2015 | const char *us; | ||
2016 | long upload_size = 0; | ||
2017 | |||
2018 | us = MHD_lookup_connection_value (con, | ||
2019 | MHD_HEADER_KIND, | ||
2020 | MHD_HTTP_HEADER_CONTENT_LENGTH); | ||
2021 | if ( (1 == sscanf (us, | ||
2022 | "%ld", | ||
2023 | &upload_size)) && | ||
2024 | (upload_size >= 0) ) | ||
2025 | { | 1939 | { |
2026 | curl_easy_setopt (s5r->curl, | 1940 | char *curl_hosts; |
2027 | CURLOPT_INFILESIZE, | 1941 | |
2028 | upload_size); | 1942 | GNUNET_asprintf(&curl_hosts, |
1943 | "%s:%d:%s", | ||
1944 | s5r->leho, | ||
1945 | port, | ||
1946 | ipaddr); | ||
1947 | s5r->hosts = curl_slist_append(NULL, | ||
1948 | curl_hosts); | ||
1949 | curl_easy_setopt(s5r->curl, | ||
1950 | CURLOPT_RESOLVE, | ||
1951 | s5r->hosts); | ||
1952 | GNUNET_free(curl_hosts); | ||
2029 | } | 1953 | } |
2030 | } | 1954 | if (s5r->is_gns) |
2031 | } | ||
2032 | else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_POST)) | ||
2033 | { | ||
2034 | s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED; | ||
2035 | curl_easy_setopt (s5r->curl, | ||
2036 | CURLOPT_POST, | ||
2037 | 1L); | ||
2038 | curl_easy_setopt (s5r->curl, | ||
2039 | CURLOPT_WRITEFUNCTION, | ||
2040 | &curl_download_cb); | ||
2041 | curl_easy_setopt (s5r->curl, | ||
2042 | CURLOPT_WRITEDATA, | ||
2043 | s5r); | ||
2044 | curl_easy_setopt (s5r->curl, | ||
2045 | CURLOPT_READFUNCTION, | ||
2046 | &curl_upload_cb); | ||
2047 | curl_easy_setopt (s5r->curl, | ||
2048 | CURLOPT_READDATA, | ||
2049 | s5r); | ||
2050 | { | ||
2051 | const char *us; | ||
2052 | long upload_size; | ||
2053 | |||
2054 | upload_size = 0; | ||
2055 | us = MHD_lookup_connection_value (con, | ||
2056 | MHD_HEADER_KIND, | ||
2057 | MHD_HTTP_HEADER_CONTENT_LENGTH); | ||
2058 | if ( (NULL != us) && | ||
2059 | (1 == sscanf (us, | ||
2060 | "%ld", | ||
2061 | &upload_size)) && | ||
2062 | (upload_size >= 0) ) | ||
2063 | { | 1955 | { |
2064 | curl_easy_setopt (s5r->curl, | 1956 | GNUNET_asprintf(&curlurl, |
2065 | CURLOPT_INFILESIZE, | 1957 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) |
2066 | upload_size); | 1958 | ? "http://%s:%d%s" |
2067 | } else { | 1959 | : "https://%s:%d%s", |
2068 | curl_easy_setopt (s5r->curl, | 1960 | (NULL != s5r->leho) |
2069 | CURLOPT_INFILESIZE, | 1961 | ? s5r->leho |
2070 | upload_size); | 1962 | : ipaddr, |
1963 | port, | ||
1964 | s5r->url); | ||
1965 | } | ||
1966 | else | ||
1967 | { | ||
1968 | GNUNET_asprintf(&curlurl, | ||
1969 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) | ||
1970 | ? "http://%s:%d%s" | ||
1971 | : "https://%s:%d%s", | ||
1972 | s5r->domain, | ||
1973 | port, | ||
1974 | s5r->url); | ||
1975 | } | ||
1976 | curl_easy_setopt(s5r->curl, | ||
1977 | CURLOPT_URL, | ||
1978 | curlurl); | ||
1979 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1980 | "Launching %s CURL interaction, fetching `%s'\n", | ||
1981 | (s5r->is_gns) ? "GNS" : "DNS", | ||
1982 | curlurl); | ||
1983 | GNUNET_free(curlurl); | ||
1984 | if (0 == strcasecmp(meth, | ||
1985 | MHD_HTTP_METHOD_PUT)) | ||
1986 | { | ||
1987 | s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED; | ||
1988 | curl_easy_setopt(s5r->curl, | ||
1989 | CURLOPT_UPLOAD, | ||
1990 | 1L); | ||
1991 | curl_easy_setopt(s5r->curl, | ||
1992 | CURLOPT_WRITEFUNCTION, | ||
1993 | &curl_download_cb); | ||
1994 | curl_easy_setopt(s5r->curl, | ||
1995 | CURLOPT_WRITEDATA, | ||
1996 | s5r); | ||
1997 | GNUNET_assert(CURLE_OK == | ||
1998 | curl_easy_setopt(s5r->curl, | ||
1999 | CURLOPT_READFUNCTION, | ||
2000 | &curl_upload_cb)); | ||
2001 | curl_easy_setopt(s5r->curl, | ||
2002 | CURLOPT_READDATA, | ||
2003 | s5r); | ||
2004 | { | ||
2005 | const char *us; | ||
2006 | long upload_size = 0; | ||
2007 | |||
2008 | us = MHD_lookup_connection_value(con, | ||
2009 | MHD_HEADER_KIND, | ||
2010 | MHD_HTTP_HEADER_CONTENT_LENGTH); | ||
2011 | if ((1 == sscanf(us, | ||
2012 | "%ld", | ||
2013 | &upload_size)) && | ||
2014 | (upload_size >= 0)) | ||
2015 | { | ||
2016 | curl_easy_setopt(s5r->curl, | ||
2017 | CURLOPT_INFILESIZE, | ||
2018 | upload_size); | ||
2019 | } | ||
2020 | } | ||
2021 | } | ||
2022 | else if (0 == strcasecmp(meth, MHD_HTTP_METHOD_POST)) | ||
2023 | { | ||
2024 | s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED; | ||
2025 | curl_easy_setopt(s5r->curl, | ||
2026 | CURLOPT_POST, | ||
2027 | 1L); | ||
2028 | curl_easy_setopt(s5r->curl, | ||
2029 | CURLOPT_WRITEFUNCTION, | ||
2030 | &curl_download_cb); | ||
2031 | curl_easy_setopt(s5r->curl, | ||
2032 | CURLOPT_WRITEDATA, | ||
2033 | s5r); | ||
2034 | curl_easy_setopt(s5r->curl, | ||
2035 | CURLOPT_READFUNCTION, | ||
2036 | &curl_upload_cb); | ||
2037 | curl_easy_setopt(s5r->curl, | ||
2038 | CURLOPT_READDATA, | ||
2039 | s5r); | ||
2040 | { | ||
2041 | const char *us; | ||
2042 | long upload_size; | ||
2043 | |||
2044 | upload_size = 0; | ||
2045 | us = MHD_lookup_connection_value(con, | ||
2046 | MHD_HEADER_KIND, | ||
2047 | MHD_HTTP_HEADER_CONTENT_LENGTH); | ||
2048 | if ((NULL != us) && | ||
2049 | (1 == sscanf(us, | ||
2050 | "%ld", | ||
2051 | &upload_size)) && | ||
2052 | (upload_size >= 0)) | ||
2053 | { | ||
2054 | curl_easy_setopt(s5r->curl, | ||
2055 | CURLOPT_INFILESIZE, | ||
2056 | upload_size); | ||
2057 | } | ||
2058 | else | ||
2059 | { | ||
2060 | curl_easy_setopt(s5r->curl, | ||
2061 | CURLOPT_INFILESIZE, | ||
2062 | upload_size); | ||
2063 | } | ||
2064 | } | ||
2065 | } | ||
2066 | else if (0 == strcasecmp(meth, | ||
2067 | MHD_HTTP_METHOD_HEAD)) | ||
2068 | { | ||
2069 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | ||
2070 | curl_easy_setopt(s5r->curl, | ||
2071 | CURLOPT_NOBODY, | ||
2072 | 1L); | ||
2073 | } | ||
2074 | else if (0 == strcasecmp(meth, | ||
2075 | MHD_HTTP_METHOD_OPTIONS)) | ||
2076 | { | ||
2077 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | ||
2078 | curl_easy_setopt(s5r->curl, | ||
2079 | CURLOPT_CUSTOMREQUEST, | ||
2080 | "OPTIONS"); | ||
2081 | curl_easy_setopt(s5r->curl, | ||
2082 | CURLOPT_WRITEFUNCTION, | ||
2083 | &curl_download_cb); | ||
2084 | curl_easy_setopt(s5r->curl, | ||
2085 | CURLOPT_WRITEDATA, | ||
2086 | s5r); | ||
2087 | } | ||
2088 | else if (0 == strcasecmp(meth, | ||
2089 | MHD_HTTP_METHOD_GET)) | ||
2090 | { | ||
2091 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | ||
2092 | curl_easy_setopt(s5r->curl, | ||
2093 | CURLOPT_HTTPGET, | ||
2094 | 1L); | ||
2095 | curl_easy_setopt(s5r->curl, | ||
2096 | CURLOPT_WRITEFUNCTION, | ||
2097 | &curl_download_cb); | ||
2098 | curl_easy_setopt(s5r->curl, | ||
2099 | CURLOPT_WRITEDATA, | ||
2100 | s5r); | ||
2101 | } | ||
2102 | else if (0 == strcasecmp(meth, | ||
2103 | MHD_HTTP_METHOD_DELETE)) | ||
2104 | { | ||
2105 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | ||
2106 | curl_easy_setopt(s5r->curl, | ||
2107 | CURLOPT_CUSTOMREQUEST, | ||
2108 | "DELETE"); | ||
2109 | curl_easy_setopt(s5r->curl, | ||
2110 | CURLOPT_WRITEFUNCTION, | ||
2111 | &curl_download_cb); | ||
2112 | curl_easy_setopt(s5r->curl, | ||
2113 | CURLOPT_WRITEDATA, | ||
2114 | s5r); | ||
2115 | } | ||
2116 | else | ||
2117 | { | ||
2118 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
2119 | _("Unsupported HTTP method `%s'\n"), | ||
2120 | meth); | ||
2121 | curl_easy_cleanup(s5r->curl); | ||
2122 | s5r->curl = NULL; | ||
2123 | return MHD_NO; | ||
2071 | } | 2124 | } |
2072 | } | ||
2073 | } | ||
2074 | else if (0 == strcasecmp (meth, | ||
2075 | MHD_HTTP_METHOD_HEAD)) | ||
2076 | { | ||
2077 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | ||
2078 | curl_easy_setopt (s5r->curl, | ||
2079 | CURLOPT_NOBODY, | ||
2080 | 1L); | ||
2081 | } | ||
2082 | else if (0 == strcasecmp (meth, | ||
2083 | MHD_HTTP_METHOD_OPTIONS)) | ||
2084 | { | ||
2085 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | ||
2086 | curl_easy_setopt (s5r->curl, | ||
2087 | CURLOPT_CUSTOMREQUEST, | ||
2088 | "OPTIONS"); | ||
2089 | curl_easy_setopt (s5r->curl, | ||
2090 | CURLOPT_WRITEFUNCTION, | ||
2091 | &curl_download_cb); | ||
2092 | curl_easy_setopt (s5r->curl, | ||
2093 | CURLOPT_WRITEDATA, | ||
2094 | s5r); | ||
2095 | |||
2096 | } | ||
2097 | else if (0 == strcasecmp (meth, | ||
2098 | MHD_HTTP_METHOD_GET)) | ||
2099 | { | ||
2100 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | ||
2101 | curl_easy_setopt (s5r->curl, | ||
2102 | CURLOPT_HTTPGET, | ||
2103 | 1L); | ||
2104 | curl_easy_setopt (s5r->curl, | ||
2105 | CURLOPT_WRITEFUNCTION, | ||
2106 | &curl_download_cb); | ||
2107 | curl_easy_setopt (s5r->curl, | ||
2108 | CURLOPT_WRITEDATA, | ||
2109 | s5r); | ||
2110 | } | ||
2111 | else if (0 == strcasecmp (meth, | ||
2112 | MHD_HTTP_METHOD_DELETE)) | ||
2113 | { | ||
2114 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | ||
2115 | curl_easy_setopt (s5r->curl, | ||
2116 | CURLOPT_CUSTOMREQUEST, | ||
2117 | "DELETE"); | ||
2118 | curl_easy_setopt (s5r->curl, | ||
2119 | CURLOPT_WRITEFUNCTION, | ||
2120 | &curl_download_cb); | ||
2121 | curl_easy_setopt (s5r->curl, | ||
2122 | CURLOPT_WRITEDATA, | ||
2123 | s5r); | ||
2124 | } | ||
2125 | else | ||
2126 | { | ||
2127 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2128 | _("Unsupported HTTP method `%s'\n"), | ||
2129 | meth); | ||
2130 | curl_easy_cleanup (s5r->curl); | ||
2131 | s5r->curl = NULL; | ||
2132 | return MHD_NO; | ||
2133 | } | ||
2134 | 2125 | ||
2135 | if (0 == strcasecmp (ver, MHD_HTTP_VERSION_1_0)) | 2126 | if (0 == strcasecmp(ver, MHD_HTTP_VERSION_1_0)) |
2136 | { | 2127 | { |
2137 | curl_easy_setopt (s5r->curl, | 2128 | curl_easy_setopt(s5r->curl, |
2138 | CURLOPT_HTTP_VERSION, | 2129 | CURLOPT_HTTP_VERSION, |
2139 | CURL_HTTP_VERSION_1_0); | 2130 | CURL_HTTP_VERSION_1_0); |
2140 | } | 2131 | } |
2141 | else if (0 == strcasecmp (ver, MHD_HTTP_VERSION_1_1)) | 2132 | else if (0 == strcasecmp(ver, MHD_HTTP_VERSION_1_1)) |
2142 | { | 2133 | { |
2143 | curl_easy_setopt (s5r->curl, | 2134 | curl_easy_setopt(s5r->curl, |
2144 | CURLOPT_HTTP_VERSION, | 2135 | CURLOPT_HTTP_VERSION, |
2145 | CURL_HTTP_VERSION_1_1); | 2136 | CURL_HTTP_VERSION_1_1); |
2146 | } | 2137 | } |
2147 | else | 2138 | else |
2148 | { | 2139 | { |
2149 | curl_easy_setopt (s5r->curl, | 2140 | curl_easy_setopt(s5r->curl, |
2150 | CURLOPT_HTTP_VERSION, | 2141 | CURLOPT_HTTP_VERSION, |
2151 | CURL_HTTP_VERSION_NONE); | 2142 | CURL_HTTP_VERSION_NONE); |
2152 | } | 2143 | } |
2153 | 2144 | ||
2154 | if (GNUNET_YES == s5r->is_tls) //(HTTPS_PORT == s5r->port) | 2145 | if (GNUNET_YES == s5r->is_tls) //(HTTPS_PORT == s5r->port) |
2155 | { | 2146 | { |
2156 | curl_easy_setopt (s5r->curl, | 2147 | curl_easy_setopt(s5r->curl, |
2157 | CURLOPT_USE_SSL, | 2148 | CURLOPT_USE_SSL, |
2158 | CURLUSESSL_ALL); | 2149 | CURLUSESSL_ALL); |
2159 | if (0 < s5r->num_danes) | 2150 | if (0 < s5r->num_danes) |
2160 | curl_easy_setopt (s5r->curl, | 2151 | curl_easy_setopt(s5r->curl, |
2161 | CURLOPT_SSL_VERIFYPEER, | 2152 | CURLOPT_SSL_VERIFYPEER, |
2162 | 0L); | 2153 | 0L); |
2154 | else | ||
2155 | curl_easy_setopt(s5r->curl, | ||
2156 | CURLOPT_SSL_VERIFYPEER, | ||
2157 | 1L); | ||
2158 | /* Disable cURL checking the hostname, as we will check ourselves | ||
2159 | as only we have the domain name or the LEHO or the DANE record */ | ||
2160 | curl_easy_setopt(s5r->curl, | ||
2161 | CURLOPT_SSL_VERIFYHOST, | ||
2162 | 0L); | ||
2163 | } | ||
2163 | else | 2164 | else |
2164 | curl_easy_setopt (s5r->curl, | 2165 | { |
2165 | CURLOPT_SSL_VERIFYPEER, | 2166 | curl_easy_setopt(s5r->curl, |
2166 | 1L); | 2167 | CURLOPT_USE_SSL, |
2167 | /* Disable cURL checking the hostname, as we will check ourselves | 2168 | CURLUSESSL_NONE); |
2168 | as only we have the domain name or the LEHO or the DANE record */ | 2169 | } |
2169 | curl_easy_setopt (s5r->curl, | ||
2170 | CURLOPT_SSL_VERIFYHOST, | ||
2171 | 0L); | ||
2172 | } | ||
2173 | else | ||
2174 | { | ||
2175 | curl_easy_setopt (s5r->curl, | ||
2176 | CURLOPT_USE_SSL, | ||
2177 | CURLUSESSL_NONE); | ||
2178 | } | ||
2179 | 2170 | ||
2180 | if (CURLM_OK != | 2171 | if (CURLM_OK != |
2181 | curl_multi_add_handle (curl_multi, | 2172 | curl_multi_add_handle(curl_multi, |
2182 | s5r->curl)) | 2173 | s5r->curl)) |
2183 | { | 2174 | { |
2184 | GNUNET_break (0); | 2175 | GNUNET_break(0); |
2185 | curl_easy_cleanup (s5r->curl); | 2176 | curl_easy_cleanup(s5r->curl); |
2186 | s5r->curl = NULL; | 2177 | s5r->curl = NULL; |
2187 | return MHD_NO; | 2178 | return MHD_NO; |
2179 | } | ||
2180 | MHD_get_connection_values(con, | ||
2181 | MHD_HEADER_KIND, | ||
2182 | (MHD_KeyValueIterator) & con_val_iter, | ||
2183 | s5r); | ||
2184 | curl_easy_setopt(s5r->curl, | ||
2185 | CURLOPT_HTTPHEADER, | ||
2186 | s5r->headers); | ||
2187 | curl_download_prepare(); | ||
2188 | return MHD_YES; | ||
2188 | } | 2189 | } |
2189 | MHD_get_connection_values (con, | ||
2190 | MHD_HEADER_KIND, | ||
2191 | (MHD_KeyValueIterator) &con_val_iter, | ||
2192 | s5r); | ||
2193 | curl_easy_setopt (s5r->curl, | ||
2194 | CURLOPT_HTTPHEADER, | ||
2195 | s5r->headers); | ||
2196 | curl_download_prepare (); | ||
2197 | return MHD_YES; | ||
2198 | } | ||
2199 | 2190 | ||
2200 | /* continuing to process request */ | 2191 | /* continuing to process request */ |
2201 | if (0 != *upload_data_size) | 2192 | if (0 != *upload_data_size) |
2202 | { | ||
2203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2204 | "Processing %u bytes UPLOAD\n", | ||
2205 | (unsigned int) *upload_data_size); | ||
2206 | |||
2207 | /* FIXME: This must be set or a header with Transfer-Encoding: chunked. Else | ||
2208 | * upload callback is not called! | ||
2209 | */ | ||
2210 | curl_easy_setopt (s5r->curl, | ||
2211 | CURLOPT_POSTFIELDSIZE, | ||
2212 | *upload_data_size); | ||
2213 | |||
2214 | left = GNUNET_MIN (*upload_data_size, | ||
2215 | sizeof (s5r->io_buf) - s5r->io_len); | ||
2216 | GNUNET_memcpy (&s5r->io_buf[s5r->io_len], | ||
2217 | upload_data, | ||
2218 | left); | ||
2219 | s5r->io_len += left; | ||
2220 | *upload_data_size -= left; | ||
2221 | GNUNET_assert (NULL != s5r->curl); | ||
2222 | if (GNUNET_YES == s5r->curl_paused) | ||
2223 | { | 2193 | { |
2224 | s5r->curl_paused = GNUNET_NO; | 2194 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2225 | curl_easy_pause (s5r->curl, | 2195 | "Processing %u bytes UPLOAD\n", |
2226 | CURLPAUSE_CONT); | 2196 | (unsigned int)*upload_data_size); |
2197 | |||
2198 | /* FIXME: This must be set or a header with Transfer-Encoding: chunked. Else | ||
2199 | * upload callback is not called! | ||
2200 | */ | ||
2201 | curl_easy_setopt(s5r->curl, | ||
2202 | CURLOPT_POSTFIELDSIZE, | ||
2203 | *upload_data_size); | ||
2204 | |||
2205 | left = GNUNET_MIN(*upload_data_size, | ||
2206 | sizeof(s5r->io_buf) - s5r->io_len); | ||
2207 | GNUNET_memcpy(&s5r->io_buf[s5r->io_len], | ||
2208 | upload_data, | ||
2209 | left); | ||
2210 | s5r->io_len += left; | ||
2211 | *upload_data_size -= left; | ||
2212 | GNUNET_assert(NULL != s5r->curl); | ||
2213 | if (GNUNET_YES == s5r->curl_paused) | ||
2214 | { | ||
2215 | s5r->curl_paused = GNUNET_NO; | ||
2216 | curl_easy_pause(s5r->curl, | ||
2217 | CURLPAUSE_CONT); | ||
2218 | } | ||
2219 | return MHD_YES; | ||
2227 | } | 2220 | } |
2228 | return MHD_YES; | ||
2229 | } | ||
2230 | if (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) | 2221 | if (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) |
2231 | { | 2222 | { |
2232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2223 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2233 | "Finished processing UPLOAD\n"); | 2224 | "Finished processing UPLOAD\n"); |
2234 | s5r->state = SOCKS5_SOCKET_UPLOAD_DONE; | 2225 | s5r->state = SOCKS5_SOCKET_UPLOAD_DONE; |
2235 | } | 2226 | } |
2236 | if (NULL == s5r->response) | 2227 | if (NULL == s5r->response) |
2237 | { | 2228 | { |
2238 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2229 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2239 | "Waiting for HTTP response for %s%s...\n", | 2230 | "Waiting for HTTP response for %s%s...\n", |
2240 | s5r->domain, | 2231 | s5r->domain, |
2241 | s5r->url); | 2232 | s5r->url); |
2242 | MHD_suspend_connection (con); | 2233 | MHD_suspend_connection(con); |
2243 | s5r->suspended = GNUNET_YES; | 2234 | s5r->suspended = GNUNET_YES; |
2244 | return MHD_YES; | 2235 | return MHD_YES; |
2245 | } | 2236 | } |
2246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2237 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2247 | "Queueing response for %s%s with MHD\n", | 2238 | "Queueing response for %s%s with MHD\n", |
2248 | s5r->domain, | 2239 | s5r->domain, |
2249 | s5r->url); | 2240 | s5r->url); |
2250 | run_mhd_now (s5r->hd); | 2241 | run_mhd_now(s5r->hd); |
2251 | return MHD_queue_response (con, | 2242 | return MHD_queue_response(con, |
2252 | s5r->response_code, | 2243 | s5r->response_code, |
2253 | s5r->response); | 2244 | s5r->response); |
2254 | } | 2245 | } |
2255 | 2246 | ||
2256 | 2247 | ||
@@ -2267,51 +2258,51 @@ create_response (void *cls, | |||
2267 | * @param toe reason for request termination (ignored) | 2258 | * @param toe reason for request termination (ignored) |
2268 | */ | 2259 | */ |
2269 | static void | 2260 | static void |
2270 | mhd_completed_cb (void *cls, | 2261 | mhd_completed_cb(void *cls, |
2271 | struct MHD_Connection *connection, | 2262 | struct MHD_Connection *connection, |
2272 | void **con_cls, | 2263 | void **con_cls, |
2273 | enum MHD_RequestTerminationCode toe) | 2264 | enum MHD_RequestTerminationCode toe) |
2274 | { | 2265 | { |
2275 | struct Socks5Request *s5r = *con_cls; | 2266 | struct Socks5Request *s5r = *con_cls; |
2276 | 2267 | ||
2277 | if (NULL == s5r) | 2268 | if (NULL == s5r) |
2278 | return; | 2269 | return; |
2279 | if (MHD_REQUEST_TERMINATED_COMPLETED_OK != toe) | 2270 | if (MHD_REQUEST_TERMINATED_COMPLETED_OK != toe) |
2280 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2271 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2281 | "MHD encountered error handling request: %d\n", | 2272 | "MHD encountered error handling request: %d\n", |
2282 | toe); | 2273 | toe); |
2283 | if (NULL != s5r->curl) | 2274 | if (NULL != s5r->curl) |
2284 | { | 2275 | { |
2285 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2276 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2286 | "Removing cURL handle (MHD interaction complete)\n"); | 2277 | "Removing cURL handle (MHD interaction complete)\n"); |
2287 | curl_multi_remove_handle (curl_multi, | 2278 | curl_multi_remove_handle(curl_multi, |
2288 | s5r->curl); | 2279 | s5r->curl); |
2289 | curl_slist_free_all (s5r->headers); | 2280 | curl_slist_free_all(s5r->headers); |
2290 | s5r->headers = NULL; | 2281 | s5r->headers = NULL; |
2291 | curl_easy_reset (s5r->curl); | 2282 | curl_easy_reset(s5r->curl); |
2292 | s5r->rbuf_len = 0; | 2283 | s5r->rbuf_len = 0; |
2293 | s5r->wbuf_len = 0; | 2284 | s5r->wbuf_len = 0; |
2294 | s5r->io_len = 0; | 2285 | s5r->io_len = 0; |
2295 | curl_download_prepare (); | 2286 | curl_download_prepare(); |
2296 | } | 2287 | } |
2297 | if ( (NULL != s5r->response) && | 2288 | if ((NULL != s5r->response) && |
2298 | (curl_failure_response != s5r->response) ) | 2289 | (curl_failure_response != s5r->response)) |
2299 | MHD_destroy_response (s5r->response); | 2290 | MHD_destroy_response(s5r->response); |
2300 | for (struct HttpResponseHeader *header = s5r->header_head; | 2291 | for (struct HttpResponseHeader *header = s5r->header_head; |
2301 | NULL != header; | 2292 | NULL != header; |
2302 | header = s5r->header_head) | 2293 | header = s5r->header_head) |
2303 | { | 2294 | { |
2304 | GNUNET_CONTAINER_DLL_remove (s5r->header_head, | 2295 | GNUNET_CONTAINER_DLL_remove(s5r->header_head, |
2305 | s5r->header_tail, | 2296 | s5r->header_tail, |
2306 | header); | 2297 | header); |
2307 | GNUNET_free (header->type); | 2298 | GNUNET_free(header->type); |
2308 | GNUNET_free (header->value); | 2299 | GNUNET_free(header->value); |
2309 | GNUNET_free (header); | 2300 | GNUNET_free(header); |
2310 | } | 2301 | } |
2311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2302 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2312 | "Finished request for %s\n", | 2303 | "Finished request for %s\n", |
2313 | s5r->url); | 2304 | s5r->url); |
2314 | GNUNET_free (s5r->url); | 2305 | GNUNET_free(s5r->url); |
2315 | s5r->state = SOCKS5_SOCKET_WITH_MHD; | 2306 | s5r->state = SOCKS5_SOCKET_WITH_MHD; |
2316 | s5r->url = NULL; | 2307 | s5r->url = NULL; |
2317 | s5r->response = NULL; | 2308 | s5r->response = NULL; |
@@ -2329,56 +2320,58 @@ mhd_completed_cb (void *cls, | |||
2329 | * @param toe connection notification type | 2320 | * @param toe connection notification type |
2330 | */ | 2321 | */ |
2331 | static void | 2322 | static void |
2332 | mhd_connection_cb (void *cls, | 2323 | mhd_connection_cb(void *cls, |
2333 | struct MHD_Connection *connection, | 2324 | struct MHD_Connection *connection, |
2334 | void **con_cls, | 2325 | void **con_cls, |
2335 | enum MHD_ConnectionNotificationCode cnc) | 2326 | enum MHD_ConnectionNotificationCode cnc) |
2336 | { | 2327 | { |
2337 | struct Socks5Request *s5r; | 2328 | struct Socks5Request *s5r; |
2338 | const union MHD_ConnectionInfo *ci; | 2329 | const union MHD_ConnectionInfo *ci; |
2339 | int sock; | 2330 | int sock; |
2340 | 2331 | ||
2341 | switch (cnc) | 2332 | switch (cnc) |
2342 | { | 2333 | { |
2343 | case MHD_CONNECTION_NOTIFY_STARTED: | 2334 | case MHD_CONNECTION_NOTIFY_STARTED: |
2344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection started...\n"); | 2335 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connection started...\n"); |
2345 | ci = MHD_get_connection_info (connection, | 2336 | ci = MHD_get_connection_info(connection, |
2346 | MHD_CONNECTION_INFO_CONNECTION_FD); | 2337 | MHD_CONNECTION_INFO_CONNECTION_FD); |
2347 | if (NULL == ci) | 2338 | if (NULL == ci) |
2348 | { | 2339 | { |
2349 | GNUNET_break (0); | 2340 | GNUNET_break(0); |
2350 | return; | 2341 | return; |
2351 | } | 2342 | } |
2352 | sock = ci->connect_fd; | 2343 | sock = ci->connect_fd; |
2353 | for (s5r = s5r_head; NULL != s5r; s5r = s5r->next) | 2344 | for (s5r = s5r_head; NULL != s5r; s5r = s5r->next) |
2354 | { | ||
2355 | if (GNUNET_NETWORK_get_fd (s5r->sock) == sock) | ||
2356 | { | 2345 | { |
2357 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2346 | if (GNUNET_NETWORK_get_fd(s5r->sock) == sock) |
2358 | "Context set...\n"); | 2347 | { |
2359 | s5r->ssl_checked = GNUNET_NO; | 2348 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2360 | *con_cls = s5r; | 2349 | "Context set...\n"); |
2361 | break; | 2350 | s5r->ssl_checked = GNUNET_NO; |
2351 | *con_cls = s5r; | ||
2352 | break; | ||
2353 | } | ||
2362 | } | 2354 | } |
2363 | } | ||
2364 | break; | 2355 | break; |
2356 | |||
2365 | case MHD_CONNECTION_NOTIFY_CLOSED: | 2357 | case MHD_CONNECTION_NOTIFY_CLOSED: |
2366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2358 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2367 | "Connection closed... cleaning up\n"); | 2359 | "Connection closed... cleaning up\n"); |
2368 | s5r = *con_cls; | 2360 | s5r = *con_cls; |
2369 | if (NULL == s5r) | 2361 | if (NULL == s5r) |
2370 | { | 2362 | { |
2371 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2363 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2372 | "Connection stale!\n"); | 2364 | "Connection stale!\n"); |
2373 | return; | 2365 | return; |
2374 | } | 2366 | } |
2375 | cleanup_s5r (s5r); | 2367 | cleanup_s5r(s5r); |
2376 | curl_download_prepare (); | 2368 | curl_download_prepare(); |
2377 | *con_cls = NULL; | 2369 | *con_cls = NULL; |
2378 | break; | 2370 | break; |
2371 | |||
2379 | default: | 2372 | default: |
2380 | GNUNET_break (0); | 2373 | GNUNET_break(0); |
2381 | } | 2374 | } |
2382 | } | 2375 | } |
2383 | 2376 | ||
2384 | /** | 2377 | /** |
@@ -2395,34 +2388,34 @@ mhd_connection_cb (void *cls, | |||
2395 | * @return the `struct Socks5Request` that this @a connection is for | 2388 | * @return the `struct Socks5Request` that this @a connection is for |
2396 | */ | 2389 | */ |
2397 | static void * | 2390 | static void * |
2398 | mhd_log_callback (void *cls, | 2391 | mhd_log_callback(void *cls, |
2399 | const char *url, | 2392 | const char *url, |
2400 | struct MHD_Connection *connection) | 2393 | struct MHD_Connection *connection) |
2401 | { | 2394 | { |
2402 | struct Socks5Request *s5r; | 2395 | struct Socks5Request *s5r; |
2403 | const union MHD_ConnectionInfo *ci; | 2396 | const union MHD_ConnectionInfo *ci; |
2404 | 2397 | ||
2405 | ci = MHD_get_connection_info (connection, | 2398 | ci = MHD_get_connection_info(connection, |
2406 | MHD_CONNECTION_INFO_SOCKET_CONTEXT); | 2399 | MHD_CONNECTION_INFO_SOCKET_CONTEXT); |
2407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing %s\n", url); | 2400 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing %s\n", url); |
2408 | if (NULL == ci) | 2401 | if (NULL == ci) |
2409 | { | 2402 | { |
2410 | GNUNET_break (0); | 2403 | GNUNET_break(0); |
2411 | return NULL; | 2404 | return NULL; |
2412 | } | 2405 | } |
2413 | s5r = ci->socket_context; | 2406 | s5r = ci->socket_context; |
2414 | if (NULL != s5r->url) | 2407 | if (NULL != s5r->url) |
2415 | { | 2408 | { |
2416 | GNUNET_break (0); | 2409 | GNUNET_break(0); |
2417 | return NULL; | 2410 | return NULL; |
2418 | } | 2411 | } |
2419 | s5r->url = GNUNET_strdup (url); | 2412 | s5r->url = GNUNET_strdup(url); |
2420 | if (NULL != s5r->timeout_task) | 2413 | if (NULL != s5r->timeout_task) |
2421 | { | 2414 | { |
2422 | GNUNET_SCHEDULER_cancel (s5r->timeout_task); | 2415 | GNUNET_SCHEDULER_cancel(s5r->timeout_task); |
2423 | s5r->timeout_task = NULL; | 2416 | s5r->timeout_task = NULL; |
2424 | } | 2417 | } |
2425 | GNUNET_assert (s5r->state == SOCKS5_SOCKET_WITH_MHD); | 2418 | GNUNET_assert(s5r->state == SOCKS5_SOCKET_WITH_MHD); |
2426 | return s5r; | 2419 | return s5r; |
2427 | } | 2420 | } |
2428 | 2421 | ||
@@ -2433,22 +2426,22 @@ mhd_log_callback (void *cls, | |||
2433 | * @param hd daemon to stop | 2426 | * @param hd daemon to stop |
2434 | */ | 2427 | */ |
2435 | static void | 2428 | static void |
2436 | kill_httpd (struct MhdHttpList *hd) | 2429 | kill_httpd(struct MhdHttpList *hd) |
2437 | { | 2430 | { |
2438 | GNUNET_CONTAINER_DLL_remove (mhd_httpd_head, | 2431 | GNUNET_CONTAINER_DLL_remove(mhd_httpd_head, |
2439 | mhd_httpd_tail, | 2432 | mhd_httpd_tail, |
2440 | hd); | 2433 | hd); |
2441 | GNUNET_free_non_null (hd->domain); | 2434 | GNUNET_free_non_null(hd->domain); |
2442 | MHD_stop_daemon (hd->daemon); | 2435 | MHD_stop_daemon(hd->daemon); |
2443 | if (NULL != hd->httpd_task) | 2436 | if (NULL != hd->httpd_task) |
2444 | { | 2437 | { |
2445 | GNUNET_SCHEDULER_cancel (hd->httpd_task); | 2438 | GNUNET_SCHEDULER_cancel(hd->httpd_task); |
2446 | hd->httpd_task = NULL; | 2439 | hd->httpd_task = NULL; |
2447 | } | 2440 | } |
2448 | GNUNET_free_non_null (hd->proxy_cert); | 2441 | GNUNET_free_non_null(hd->proxy_cert); |
2449 | if (hd == httpd) | 2442 | if (hd == httpd) |
2450 | httpd = NULL; | 2443 | httpd = NULL; |
2451 | GNUNET_free (hd); | 2444 | GNUNET_free(hd); |
2452 | } | 2445 | } |
2453 | 2446 | ||
2454 | 2447 | ||
@@ -2458,12 +2451,12 @@ kill_httpd (struct MhdHttpList *hd) | |||
2458 | * @param cls the `struct MhdHttpList *` | 2451 | * @param cls the `struct MhdHttpList *` |
2459 | */ | 2452 | */ |
2460 | static void | 2453 | static void |
2461 | kill_httpd_task (void *cls) | 2454 | kill_httpd_task(void *cls) |
2462 | { | 2455 | { |
2463 | struct MhdHttpList *hd = cls; | 2456 | struct MhdHttpList *hd = cls; |
2464 | 2457 | ||
2465 | hd->httpd_task = NULL; | 2458 | hd->httpd_task = NULL; |
2466 | kill_httpd (hd); | 2459 | kill_httpd(hd); |
2467 | } | 2460 | } |
2468 | 2461 | ||
2469 | 2462 | ||
@@ -2473,7 +2466,7 @@ kill_httpd_task (void *cls) | |||
2473 | * @param cls the `struct MhdHttpList *` of the daemon that is being run | 2466 | * @param cls the `struct MhdHttpList *` of the daemon that is being run |
2474 | */ | 2467 | */ |
2475 | static void | 2468 | static void |
2476 | do_httpd (void *cls); | 2469 | do_httpd(void *cls); |
2477 | 2470 | ||
2478 | 2471 | ||
2479 | /** | 2472 | /** |
@@ -2484,7 +2477,7 @@ do_httpd (void *cls); | |||
2484 | * @param hd the daemon to schedule | 2477 | * @param hd the daemon to schedule |
2485 | */ | 2478 | */ |
2486 | static void | 2479 | static void |
2487 | schedule_httpd (struct MhdHttpList *hd) | 2480 | schedule_httpd(struct MhdHttpList *hd) |
2488 | { | 2481 | { |
2489 | fd_set rs; | 2482 | fd_set rs; |
2490 | fd_set ws; | 2483 | fd_set ws; |
@@ -2496,63 +2489,63 @@ schedule_httpd (struct MhdHttpList *hd) | |||
2496 | MHD_UNSIGNED_LONG_LONG timeout; | 2489 | MHD_UNSIGNED_LONG_LONG timeout; |
2497 | struct GNUNET_TIME_Relative tv; | 2490 | struct GNUNET_TIME_Relative tv; |
2498 | 2491 | ||
2499 | FD_ZERO (&rs); | 2492 | FD_ZERO(&rs); |
2500 | FD_ZERO (&ws); | 2493 | FD_ZERO(&ws); |
2501 | FD_ZERO (&es); | 2494 | FD_ZERO(&es); |
2502 | max = -1; | 2495 | max = -1; |
2503 | if (MHD_YES != | 2496 | if (MHD_YES != |
2504 | MHD_get_fdset (hd->daemon, | 2497 | MHD_get_fdset(hd->daemon, |
2505 | &rs, | 2498 | &rs, |
2506 | &ws, | 2499 | &ws, |
2507 | &es, | 2500 | &es, |
2508 | &max)) | 2501 | &max)) |
2509 | { | 2502 | { |
2510 | kill_httpd (hd); | 2503 | kill_httpd(hd); |
2511 | return; | 2504 | return; |
2512 | } | 2505 | } |
2513 | haveto = MHD_get_timeout (hd->daemon, | 2506 | haveto = MHD_get_timeout(hd->daemon, |
2514 | &timeout); | 2507 | &timeout); |
2515 | if (MHD_YES == haveto) | 2508 | if (MHD_YES == haveto) |
2516 | tv.rel_value_us = (uint64_t) timeout * 1000LL; | 2509 | tv.rel_value_us = (uint64_t)timeout * 1000LL; |
2517 | else | 2510 | else |
2518 | tv = GNUNET_TIME_UNIT_FOREVER_REL; | 2511 | tv = GNUNET_TIME_UNIT_FOREVER_REL; |
2519 | if (-1 != max) | 2512 | if (-1 != max) |
2520 | { | 2513 | { |
2521 | wrs = GNUNET_NETWORK_fdset_create (); | 2514 | wrs = GNUNET_NETWORK_fdset_create(); |
2522 | wws = GNUNET_NETWORK_fdset_create (); | 2515 | wws = GNUNET_NETWORK_fdset_create(); |
2523 | GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); | 2516 | GNUNET_NETWORK_fdset_copy_native(wrs, &rs, max + 1); |
2524 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); | 2517 | GNUNET_NETWORK_fdset_copy_native(wws, &ws, max + 1); |
2525 | } | 2518 | } |
2526 | else | 2519 | else |
2527 | { | 2520 | { |
2528 | wrs = NULL; | 2521 | wrs = NULL; |
2529 | wws = NULL; | 2522 | wws = NULL; |
2530 | } | 2523 | } |
2531 | if (NULL != hd->httpd_task) | 2524 | if (NULL != hd->httpd_task) |
2532 | { | 2525 | { |
2533 | GNUNET_SCHEDULER_cancel (hd->httpd_task); | 2526 | GNUNET_SCHEDULER_cancel(hd->httpd_task); |
2534 | hd->httpd_task = NULL; | 2527 | hd->httpd_task = NULL; |
2535 | } | 2528 | } |
2536 | if ( (MHD_YES != haveto) && | 2529 | if ((MHD_YES != haveto) && |
2537 | (-1 == max) && | 2530 | (-1 == max) && |
2538 | (hd != httpd) ) | 2531 | (hd != httpd)) |
2539 | { | 2532 | { |
2540 | /* daemon is idle, kill after timeout */ | 2533 | /* daemon is idle, kill after timeout */ |
2541 | hd->httpd_task = GNUNET_SCHEDULER_add_delayed (MHD_CACHE_TIMEOUT, | 2534 | hd->httpd_task = GNUNET_SCHEDULER_add_delayed(MHD_CACHE_TIMEOUT, |
2542 | &kill_httpd_task, | 2535 | &kill_httpd_task, |
2543 | hd); | 2536 | hd); |
2544 | } | 2537 | } |
2545 | else | 2538 | else |
2546 | { | 2539 | { |
2547 | hd->httpd_task = | 2540 | hd->httpd_task = |
2548 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 2541 | GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
2549 | tv, wrs, wws, | 2542 | tv, wrs, wws, |
2550 | &do_httpd, hd); | 2543 | &do_httpd, hd); |
2551 | } | 2544 | } |
2552 | if (NULL != wrs) | 2545 | if (NULL != wrs) |
2553 | GNUNET_NETWORK_fdset_destroy (wrs); | 2546 | GNUNET_NETWORK_fdset_destroy(wrs); |
2554 | if (NULL != wws) | 2547 | if (NULL != wws) |
2555 | GNUNET_NETWORK_fdset_destroy (wws); | 2548 | GNUNET_NETWORK_fdset_destroy(wws); |
2556 | } | 2549 | } |
2557 | 2550 | ||
2558 | 2551 | ||
@@ -2562,13 +2555,13 @@ schedule_httpd (struct MhdHttpList *hd) | |||
2562 | * @param cls the `struct MhdHttpList` of the daemon that is being run | 2555 | * @param cls the `struct MhdHttpList` of the daemon that is being run |
2563 | */ | 2556 | */ |
2564 | static void | 2557 | static void |
2565 | do_httpd (void *cls) | 2558 | do_httpd(void *cls) |
2566 | { | 2559 | { |
2567 | struct MhdHttpList *hd = cls; | 2560 | struct MhdHttpList *hd = cls; |
2568 | 2561 | ||
2569 | hd->httpd_task = NULL; | 2562 | hd->httpd_task = NULL; |
2570 | MHD_run (hd->daemon); | 2563 | MHD_run(hd->daemon); |
2571 | schedule_httpd (hd); | 2564 | schedule_httpd(hd); |
2572 | } | 2565 | } |
2573 | 2566 | ||
2574 | 2567 | ||
@@ -2578,12 +2571,12 @@ do_httpd (void *cls) | |||
2578 | * @param hd the daemon to run now. | 2571 | * @param hd the daemon to run now. |
2579 | */ | 2572 | */ |
2580 | static void | 2573 | static void |
2581 | run_mhd_now (struct MhdHttpList *hd) | 2574 | run_mhd_now(struct MhdHttpList *hd) |
2582 | { | 2575 | { |
2583 | if (NULL != hd->httpd_task) | 2576 | if (NULL != hd->httpd_task) |
2584 | GNUNET_SCHEDULER_cancel (hd->httpd_task); | 2577 | GNUNET_SCHEDULER_cancel(hd->httpd_task); |
2585 | hd->httpd_task = GNUNET_SCHEDULER_add_now (&do_httpd, | 2578 | hd->httpd_task = GNUNET_SCHEDULER_add_now(&do_httpd, |
2586 | hd); | 2579 | hd); |
2587 | } | 2580 | } |
2588 | 2581 | ||
2589 | 2582 | ||
@@ -2595,30 +2588,30 @@ run_mhd_now (struct MhdHttpList *hd) | |||
2595 | * @return NULL on error | 2588 | * @return NULL on error |
2596 | */ | 2589 | */ |
2597 | static void* | 2590 | static void* |
2598 | load_file (const char* filename, | 2591 | load_file(const char* filename, |
2599 | unsigned int* size) | 2592 | unsigned int* size) |
2600 | { | 2593 | { |
2601 | void *buffer; | 2594 | void *buffer; |
2602 | uint64_t fsize; | 2595 | uint64_t fsize; |
2603 | 2596 | ||
2604 | if (GNUNET_OK != | 2597 | if (GNUNET_OK != |
2605 | GNUNET_DISK_file_size (filename, | 2598 | GNUNET_DISK_file_size(filename, |
2606 | &fsize, | 2599 | &fsize, |
2607 | GNUNET_YES, | 2600 | GNUNET_YES, |
2608 | GNUNET_YES)) | 2601 | GNUNET_YES)) |
2609 | return NULL; | 2602 | return NULL; |
2610 | if (fsize > MAX_PEM_SIZE) | 2603 | if (fsize > MAX_PEM_SIZE) |
2611 | return NULL; | 2604 | return NULL; |
2612 | *size = (unsigned int) fsize; | 2605 | *size = (unsigned int)fsize; |
2613 | buffer = GNUNET_malloc (*size); | 2606 | buffer = GNUNET_malloc(*size); |
2614 | if (fsize != | 2607 | if (fsize != |
2615 | GNUNET_DISK_fn_read (filename, | 2608 | GNUNET_DISK_fn_read(filename, |
2616 | buffer, | 2609 | buffer, |
2617 | (size_t) fsize)) | 2610 | (size_t)fsize)) |
2618 | { | 2611 | { |
2619 | GNUNET_free (buffer); | 2612 | GNUNET_free(buffer); |
2620 | return NULL; | 2613 | return NULL; |
2621 | } | 2614 | } |
2622 | return buffer; | 2615 | return buffer; |
2623 | } | 2616 | } |
2624 | 2617 | ||
@@ -2631,25 +2624,25 @@ load_file (const char* filename, | |||
2631 | * @return #GNUNET_OK on success | 2624 | * @return #GNUNET_OK on success |
2632 | */ | 2625 | */ |
2633 | static int | 2626 | static int |
2634 | load_key_from_file (gnutls_x509_privkey_t key, | 2627 | load_key_from_file(gnutls_x509_privkey_t key, |
2635 | const char* keyfile) | 2628 | const char* keyfile) |
2636 | { | 2629 | { |
2637 | gnutls_datum_t key_data; | 2630 | gnutls_datum_t key_data; |
2638 | int ret; | 2631 | int ret; |
2639 | 2632 | ||
2640 | key_data.data = load_file (keyfile, | 2633 | key_data.data = load_file(keyfile, |
2641 | &key_data.size); | 2634 | &key_data.size); |
2642 | if (NULL == key_data.data) | 2635 | if (NULL == key_data.data) |
2643 | return GNUNET_SYSERR; | 2636 | return GNUNET_SYSERR; |
2644 | ret = gnutls_x509_privkey_import (key, &key_data, | 2637 | ret = gnutls_x509_privkey_import(key, &key_data, |
2645 | GNUTLS_X509_FMT_PEM); | 2638 | GNUTLS_X509_FMT_PEM); |
2646 | if (GNUTLS_E_SUCCESS != ret) | 2639 | if (GNUTLS_E_SUCCESS != ret) |
2647 | { | 2640 | { |
2648 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2641 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2649 | _("Unable to import private key from file `%s'\n"), | 2642 | _("Unable to import private key from file `%s'\n"), |
2650 | keyfile); | 2643 | keyfile); |
2651 | } | 2644 | } |
2652 | GNUNET_free_non_null (key_data.data); | 2645 | GNUNET_free_non_null(key_data.data); |
2653 | return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; | 2646 | return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; |
2654 | } | 2647 | } |
2655 | 2648 | ||
@@ -2662,26 +2655,26 @@ load_key_from_file (gnutls_x509_privkey_t key, | |||
2662 | * @return #GNUNET_OK on success | 2655 | * @return #GNUNET_OK on success |
2663 | */ | 2656 | */ |
2664 | static int | 2657 | static int |
2665 | load_cert_from_file (gnutls_x509_crt_t crt, | 2658 | load_cert_from_file(gnutls_x509_crt_t crt, |
2666 | const char* certfile) | 2659 | const char* certfile) |
2667 | { | 2660 | { |
2668 | gnutls_datum_t cert_data; | 2661 | gnutls_datum_t cert_data; |
2669 | int ret; | 2662 | int ret; |
2670 | 2663 | ||
2671 | cert_data.data = load_file (certfile, | 2664 | cert_data.data = load_file(certfile, |
2672 | &cert_data.size); | 2665 | &cert_data.size); |
2673 | if (NULL == cert_data.data) | 2666 | if (NULL == cert_data.data) |
2674 | return GNUNET_SYSERR; | 2667 | return GNUNET_SYSERR; |
2675 | ret = gnutls_x509_crt_import (crt, | 2668 | ret = gnutls_x509_crt_import(crt, |
2676 | &cert_data, | 2669 | &cert_data, |
2677 | GNUTLS_X509_FMT_PEM); | 2670 | GNUTLS_X509_FMT_PEM); |
2678 | if (GNUTLS_E_SUCCESS != ret) | 2671 | if (GNUTLS_E_SUCCESS != ret) |
2679 | { | 2672 | { |
2680 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2673 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2681 | _("Unable to import certificate from `%s'\n"), | 2674 | _("Unable to import certificate from `%s'\n"), |
2682 | certfile); | 2675 | certfile); |
2683 | } | 2676 | } |
2684 | GNUNET_free_non_null (cert_data.data); | 2677 | GNUNET_free_non_null(cert_data.data); |
2685 | return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; | 2678 | return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; |
2686 | } | 2679 | } |
2687 | 2680 | ||
@@ -2693,7 +2686,7 @@ load_cert_from_file (gnutls_x509_crt_t crt, | |||
2693 | * @return a struct holding the PEM data, NULL on error | 2686 | * @return a struct holding the PEM data, NULL on error |
2694 | */ | 2687 | */ |
2695 | static struct ProxyGNSCertificate * | 2688 | static struct ProxyGNSCertificate * |
2696 | generate_gns_certificate (const char *name) | 2689 | generate_gns_certificate(const char *name) |
2697 | { | 2690 | { |
2698 | unsigned int serial; | 2691 | unsigned int serial; |
2699 | size_t key_buf_size; | 2692 | size_t key_buf_size; |
@@ -2703,65 +2696,65 @@ generate_gns_certificate (const char *name) | |||
2703 | struct tm *tm_data; | 2696 | struct tm *tm_data; |
2704 | struct ProxyGNSCertificate *pgc; | 2697 | struct ProxyGNSCertificate *pgc; |
2705 | 2698 | ||
2706 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2699 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2707 | "Generating x.509 certificate for `%s'\n", | 2700 | "Generating x.509 certificate for `%s'\n", |
2708 | name); | 2701 | name); |
2709 | GNUNET_break (GNUTLS_E_SUCCESS == gnutls_x509_crt_init (&request)); | 2702 | GNUNET_break(GNUTLS_E_SUCCESS == gnutls_x509_crt_init(&request)); |
2710 | GNUNET_break (GNUTLS_E_SUCCESS == gnutls_x509_crt_set_key (request, proxy_ca.key)); | 2703 | GNUNET_break(GNUTLS_E_SUCCESS == gnutls_x509_crt_set_key(request, proxy_ca.key)); |
2711 | pgc = GNUNET_new (struct ProxyGNSCertificate); | 2704 | pgc = GNUNET_new(struct ProxyGNSCertificate); |
2712 | gnutls_x509_crt_set_dn_by_oid (request, | 2705 | gnutls_x509_crt_set_dn_by_oid(request, |
2713 | GNUTLS_OID_X520_COUNTRY_NAME, | 2706 | GNUTLS_OID_X520_COUNTRY_NAME, |
2714 | 0, | 2707 | 0, |
2715 | "ZZ", | 2708 | "ZZ", |
2716 | strlen ("ZZ")); | 2709 | strlen("ZZ")); |
2717 | gnutls_x509_crt_set_dn_by_oid (request, | 2710 | gnutls_x509_crt_set_dn_by_oid(request, |
2718 | GNUTLS_OID_X520_ORGANIZATION_NAME, | 2711 | GNUTLS_OID_X520_ORGANIZATION_NAME, |
2719 | 0, | 2712 | 0, |
2720 | "GNU Name System", | 2713 | "GNU Name System", |
2721 | strlen ("GNU Name System")); | 2714 | strlen("GNU Name System")); |
2722 | gnutls_x509_crt_set_dn_by_oid (request, | 2715 | gnutls_x509_crt_set_dn_by_oid(request, |
2723 | GNUTLS_OID_X520_COMMON_NAME, | 2716 | GNUTLS_OID_X520_COMMON_NAME, |
2724 | 0, | 2717 | 0, |
2725 | name, | 2718 | name, |
2726 | strlen (name)); | 2719 | strlen(name)); |
2727 | gnutls_x509_crt_set_subject_alternative_name (request, | 2720 | gnutls_x509_crt_set_subject_alternative_name(request, |
2728 | GNUTLS_SAN_DNSNAME, | 2721 | GNUTLS_SAN_DNSNAME, |
2729 | name); | 2722 | name); |
2730 | GNUNET_break (GNUTLS_E_SUCCESS == | 2723 | GNUNET_break(GNUTLS_E_SUCCESS == |
2731 | gnutls_x509_crt_set_version (request, | 2724 | gnutls_x509_crt_set_version(request, |
2732 | 3)); | 2725 | 3)); |
2733 | gnutls_rnd (GNUTLS_RND_NONCE, | 2726 | gnutls_rnd(GNUTLS_RND_NONCE, |
2734 | &serial, | 2727 | &serial, |
2735 | sizeof (serial)); | 2728 | sizeof(serial)); |
2736 | gnutls_x509_crt_set_serial (request, | 2729 | gnutls_x509_crt_set_serial(request, |
2737 | &serial, | 2730 | &serial, |
2738 | sizeof (serial)); | 2731 | sizeof(serial)); |
2739 | etime = time (NULL); | 2732 | etime = time(NULL); |
2740 | tm_data = localtime (&etime); | 2733 | tm_data = localtime(&etime); |
2741 | tm_data->tm_hour--; | 2734 | tm_data->tm_hour--; |
2742 | etime = mktime(tm_data); | 2735 | etime = mktime(tm_data); |
2743 | gnutls_x509_crt_set_activation_time (request, | 2736 | gnutls_x509_crt_set_activation_time(request, |
2744 | etime); | 2737 | etime); |
2745 | tm_data->tm_year++; | 2738 | tm_data->tm_year++; |
2746 | etime = mktime (tm_data); | 2739 | etime = mktime(tm_data); |
2747 | gnutls_x509_crt_set_expiration_time (request, | 2740 | gnutls_x509_crt_set_expiration_time(request, |
2748 | etime); | 2741 | etime); |
2749 | gnutls_x509_crt_sign2 (request, | 2742 | gnutls_x509_crt_sign2(request, |
2750 | proxy_ca.cert, | 2743 | proxy_ca.cert, |
2751 | proxy_ca.key, | 2744 | proxy_ca.key, |
2752 | GNUTLS_DIG_SHA512, | 2745 | GNUTLS_DIG_SHA512, |
2753 | 0); | 2746 | 0); |
2754 | key_buf_size = sizeof (pgc->key); | 2747 | key_buf_size = sizeof(pgc->key); |
2755 | cert_buf_size = sizeof (pgc->cert); | 2748 | cert_buf_size = sizeof(pgc->cert); |
2756 | gnutls_x509_crt_export (request, | 2749 | gnutls_x509_crt_export(request, |
2757 | GNUTLS_X509_FMT_PEM, | 2750 | GNUTLS_X509_FMT_PEM, |
2758 | pgc->cert, | 2751 | pgc->cert, |
2759 | &cert_buf_size); | 2752 | &cert_buf_size); |
2760 | gnutls_x509_privkey_export (proxy_ca.key, | 2753 | gnutls_x509_privkey_export(proxy_ca.key, |
2761 | GNUTLS_X509_FMT_PEM, | 2754 | GNUTLS_X509_FMT_PEM, |
2762 | pgc->key, | 2755 | pgc->key, |
2763 | &key_buf_size); | 2756 | &key_buf_size); |
2764 | gnutls_x509_crt_deinit (request); | 2757 | gnutls_x509_crt_deinit(request); |
2765 | return pgc; | 2758 | return pgc; |
2766 | } | 2759 | } |
2767 | 2760 | ||
@@ -2774,9 +2767,9 @@ generate_gns_certificate (const char *name) | |||
2774 | * @param ap arguments to @a fm | 2767 | * @param ap arguments to @a fm |
2775 | */ | 2768 | */ |
2776 | static void | 2769 | static void |
2777 | mhd_error_log_callback (void *cls, | 2770 | mhd_error_log_callback(void *cls, |
2778 | const char *fm, | 2771 | const char *fm, |
2779 | va_list ap) | 2772 | va_list ap) |
2780 | { | 2773 | { |
2781 | /* do nothing */ | 2774 | /* do nothing */ |
2782 | } | 2775 | } |
@@ -2789,49 +2782,49 @@ mhd_error_log_callback (void *cls, | |||
2789 | * @return NULL on error | 2782 | * @return NULL on error |
2790 | */ | 2783 | */ |
2791 | static struct MhdHttpList * | 2784 | static struct MhdHttpList * |
2792 | lookup_ssl_httpd (const char* domain) | 2785 | lookup_ssl_httpd(const char* domain) |
2793 | { | 2786 | { |
2794 | struct MhdHttpList *hd; | 2787 | struct MhdHttpList *hd; |
2795 | struct ProxyGNSCertificate *pgc; | 2788 | struct ProxyGNSCertificate *pgc; |
2796 | 2789 | ||
2797 | if (NULL == domain) | 2790 | if (NULL == domain) |
2798 | { | 2791 | { |
2799 | GNUNET_break (0); | 2792 | GNUNET_break(0); |
2800 | return NULL; | 2793 | return NULL; |
2801 | } | 2794 | } |
2802 | for (hd = mhd_httpd_head; NULL != hd; hd = hd->next) | 2795 | for (hd = mhd_httpd_head; NULL != hd; hd = hd->next) |
2803 | if ( (NULL != hd->domain) && | 2796 | if ((NULL != hd->domain) && |
2804 | (0 == strcmp (hd->domain, domain)) ) | 2797 | (0 == strcmp(hd->domain, domain))) |
2805 | return hd; | 2798 | return hd; |
2806 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2799 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2807 | "Starting fresh MHD HTTPS instance for domain `%s'\n", | 2800 | "Starting fresh MHD HTTPS instance for domain `%s'\n", |
2808 | domain); | 2801 | domain); |
2809 | pgc = generate_gns_certificate (domain); | 2802 | pgc = generate_gns_certificate(domain); |
2810 | hd = GNUNET_new (struct MhdHttpList); | 2803 | hd = GNUNET_new(struct MhdHttpList); |
2811 | hd->is_ssl = GNUNET_YES; | 2804 | hd->is_ssl = GNUNET_YES; |
2812 | hd->domain = GNUNET_strdup (domain); | 2805 | hd->domain = GNUNET_strdup(domain); |
2813 | hd->proxy_cert = pgc; | 2806 | hd->proxy_cert = pgc; |
2814 | hd->daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL | MHD_USE_NO_LISTEN_SOCKET | MHD_ALLOW_SUSPEND_RESUME, | 2807 | hd->daemon = MHD_start_daemon(MHD_USE_DEBUG | MHD_USE_SSL | MHD_USE_NO_LISTEN_SOCKET | MHD_ALLOW_SUSPEND_RESUME, |
2815 | 0, | 2808 | 0, |
2816 | NULL, NULL, | 2809 | NULL, NULL, |
2817 | &create_response, hd, | 2810 | &create_response, hd, |
2818 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, | 2811 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int)16, |
2819 | MHD_OPTION_NOTIFY_COMPLETED, &mhd_completed_cb, NULL, | 2812 | MHD_OPTION_NOTIFY_COMPLETED, &mhd_completed_cb, NULL, |
2820 | MHD_OPTION_NOTIFY_CONNECTION, &mhd_connection_cb, NULL, | 2813 | MHD_OPTION_NOTIFY_CONNECTION, &mhd_connection_cb, NULL, |
2821 | MHD_OPTION_URI_LOG_CALLBACK, &mhd_log_callback, NULL, | 2814 | MHD_OPTION_URI_LOG_CALLBACK, &mhd_log_callback, NULL, |
2822 | MHD_OPTION_EXTERNAL_LOGGER, &mhd_error_log_callback, NULL, | 2815 | MHD_OPTION_EXTERNAL_LOGGER, &mhd_error_log_callback, NULL, |
2823 | MHD_OPTION_HTTPS_MEM_KEY, pgc->key, | 2816 | MHD_OPTION_HTTPS_MEM_KEY, pgc->key, |
2824 | MHD_OPTION_HTTPS_MEM_CERT, pgc->cert, | 2817 | MHD_OPTION_HTTPS_MEM_CERT, pgc->cert, |
2825 | MHD_OPTION_END); | 2818 | MHD_OPTION_END); |
2826 | if (NULL == hd->daemon) | 2819 | if (NULL == hd->daemon) |
2827 | { | 2820 | { |
2828 | GNUNET_free (pgc); | 2821 | GNUNET_free(pgc); |
2829 | GNUNET_free (hd); | 2822 | GNUNET_free(hd); |
2830 | return NULL; | 2823 | return NULL; |
2831 | } | 2824 | } |
2832 | GNUNET_CONTAINER_DLL_insert (mhd_httpd_head, | 2825 | GNUNET_CONTAINER_DLL_insert(mhd_httpd_head, |
2833 | mhd_httpd_tail, | 2826 | mhd_httpd_tail, |
2834 | hd); | 2827 | hd); |
2835 | return hd; | 2828 | return hd; |
2836 | } | 2829 | } |
2837 | 2830 | ||
@@ -2844,12 +2837,12 @@ lookup_ssl_httpd (const char* domain) | |||
2844 | * @param cls the `struct Socks5Request *` | 2837 | * @param cls the `struct Socks5Request *` |
2845 | */ | 2838 | */ |
2846 | static void | 2839 | static void |
2847 | timeout_s5r_handshake (void *cls) | 2840 | timeout_s5r_handshake(void *cls) |
2848 | { | 2841 | { |
2849 | struct Socks5Request *s5r = cls; | 2842 | struct Socks5Request *s5r = cls; |
2850 | 2843 | ||
2851 | s5r->timeout_task = NULL; | 2844 | s5r->timeout_task = NULL; |
2852 | cleanup_s5r (s5r); | 2845 | cleanup_s5r(s5r); |
2853 | } | 2846 | } |
2854 | 2847 | ||
2855 | 2848 | ||
@@ -2862,7 +2855,7 @@ timeout_s5r_handshake (void *cls) | |||
2862 | * @param s5r socks request that has reached the final stage | 2855 | * @param s5r socks request that has reached the final stage |
2863 | */ | 2856 | */ |
2864 | static void | 2857 | static void |
2865 | setup_data_transfer (struct Socks5Request *s5r) | 2858 | setup_data_transfer(struct Socks5Request *s5r) |
2866 | { | 2859 | { |
2867 | struct MhdHttpList *hd; | 2860 | struct MhdHttpList *hd; |
2868 | int fd; | 2861 | int fd; |
@@ -2871,47 +2864,49 @@ setup_data_transfer (struct Socks5Request *s5r) | |||
2871 | char *domain; | 2864 | char *domain; |
2872 | 2865 | ||
2873 | if (GNUNET_YES == s5r->is_tls) | 2866 | if (GNUNET_YES == s5r->is_tls) |
2874 | { | 2867 | { |
2875 | GNUNET_asprintf (&domain, | 2868 | GNUNET_asprintf(&domain, |
2876 | "%s", | 2869 | "%s", |
2870 | s5r->domain); | ||
2871 | hd = lookup_ssl_httpd(domain); | ||
2872 | if (NULL == hd) | ||
2873 | { | ||
2874 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
2875 | _("Failed to start HTTPS server for `%s'\n"), | ||
2877 | s5r->domain); | 2876 | s5r->domain); |
2878 | hd = lookup_ssl_httpd (domain); | 2877 | cleanup_s5r(s5r); |
2879 | if (NULL == hd) | 2878 | GNUNET_free(domain); |
2880 | { | 2879 | return; |
2881 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2880 | } |
2882 | _("Failed to start HTTPS server for `%s'\n"), | ||
2883 | s5r->domain); | ||
2884 | cleanup_s5r (s5r); | ||
2885 | GNUNET_free (domain); | ||
2886 | return; | ||
2887 | } | 2881 | } |
2888 | } else { | 2882 | else |
2883 | { | ||
2889 | domain = NULL; | 2884 | domain = NULL; |
2890 | GNUNET_assert (NULL != httpd); | 2885 | GNUNET_assert(NULL != httpd); |
2891 | hd = httpd; | 2886 | hd = httpd; |
2892 | } | 2887 | } |
2893 | fd = GNUNET_NETWORK_get_fd (s5r->sock); | 2888 | fd = GNUNET_NETWORK_get_fd(s5r->sock); |
2894 | addr = GNUNET_NETWORK_get_addr (s5r->sock); | 2889 | addr = GNUNET_NETWORK_get_addr(s5r->sock); |
2895 | len = GNUNET_NETWORK_get_addrlen (s5r->sock); | 2890 | len = GNUNET_NETWORK_get_addrlen(s5r->sock); |
2896 | s5r->state = SOCKS5_SOCKET_WITH_MHD; | 2891 | s5r->state = SOCKS5_SOCKET_WITH_MHD; |
2897 | if (MHD_YES != | 2892 | if (MHD_YES != |
2898 | MHD_add_connection (hd->daemon, | 2893 | MHD_add_connection(hd->daemon, |
2899 | fd, | 2894 | fd, |
2900 | addr, | 2895 | addr, |
2901 | len)) | 2896 | len)) |
2902 | { | 2897 | { |
2903 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2898 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2904 | _("Failed to pass client to MHD\n")); | 2899 | _("Failed to pass client to MHD\n")); |
2905 | cleanup_s5r (s5r); | 2900 | cleanup_s5r(s5r); |
2906 | GNUNET_free_non_null (domain); | 2901 | GNUNET_free_non_null(domain); |
2907 | return; | 2902 | return; |
2908 | } | 2903 | } |
2909 | s5r->hd = hd; | 2904 | s5r->hd = hd; |
2910 | schedule_httpd (hd); | 2905 | schedule_httpd(hd); |
2911 | s5r->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_HANDSHAKE_TIMEOUT, | 2906 | s5r->timeout_task = GNUNET_SCHEDULER_add_delayed(HTTP_HANDSHAKE_TIMEOUT, |
2912 | &timeout_s5r_handshake, | 2907 | &timeout_s5r_handshake, |
2913 | s5r); | 2908 | s5r); |
2914 | GNUNET_free_non_null (domain); | 2909 | GNUNET_free_non_null(domain); |
2915 | } | 2910 | } |
2916 | 2911 | ||
2917 | 2912 | ||
@@ -2924,57 +2919,61 @@ setup_data_transfer (struct Socks5Request *s5r) | |||
2924 | * @param cls the closure with the `struct Socks5Request` | 2919 | * @param cls the closure with the `struct Socks5Request` |
2925 | */ | 2920 | */ |
2926 | static void | 2921 | static void |
2927 | do_write (void *cls) | 2922 | do_write(void *cls) |
2928 | { | 2923 | { |
2929 | struct Socks5Request *s5r = cls; | 2924 | struct Socks5Request *s5r = cls; |
2930 | ssize_t len; | 2925 | ssize_t len; |
2931 | 2926 | ||
2932 | s5r->wtask = NULL; | 2927 | s5r->wtask = NULL; |
2933 | len = GNUNET_NETWORK_socket_send (s5r->sock, | 2928 | len = GNUNET_NETWORK_socket_send(s5r->sock, |
2934 | s5r->wbuf, | 2929 | s5r->wbuf, |
2935 | s5r->wbuf_len); | 2930 | s5r->wbuf_len); |
2936 | if (len <= 0) | 2931 | if (len <= 0) |
2937 | { | 2932 | { |
2938 | /* write error: connection closed, shutdown, etc.; just clean up */ | 2933 | /* write error: connection closed, shutdown, etc.; just clean up */ |
2939 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2934 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2940 | "Write Error\n"); | 2935 | "Write Error\n"); |
2941 | cleanup_s5r (s5r); | 2936 | cleanup_s5r(s5r); |
2942 | return; | 2937 | return; |
2943 | } | 2938 | } |
2944 | memmove (s5r->wbuf, | 2939 | memmove(s5r->wbuf, |
2945 | &s5r->wbuf[len], | 2940 | &s5r->wbuf[len], |
2946 | s5r->wbuf_len - len); | 2941 | s5r->wbuf_len - len); |
2947 | s5r->wbuf_len -= len; | 2942 | s5r->wbuf_len -= len; |
2948 | if (s5r->wbuf_len > 0) | 2943 | if (s5r->wbuf_len > 0) |
2949 | { | 2944 | { |
2950 | /* not done writing */ | 2945 | /* not done writing */ |
2951 | s5r->wtask = | 2946 | s5r->wtask = |
2952 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 2947 | GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, |
2953 | s5r->sock, | 2948 | s5r->sock, |
2954 | &do_write, s5r); | 2949 | &do_write, s5r); |
2955 | return; | 2950 | return; |
2956 | } | 2951 | } |
2957 | 2952 | ||
2958 | /* we're done writing, continue with state machine! */ | 2953 | /* we're done writing, continue with state machine! */ |
2959 | 2954 | ||
2960 | switch (s5r->state) | 2955 | switch (s5r->state) |
2961 | { | 2956 | { |
2962 | case SOCKS5_INIT: | 2957 | case SOCKS5_INIT: |
2963 | GNUNET_assert (0); | 2958 | GNUNET_assert(0); |
2964 | break; | 2959 | break; |
2960 | |||
2965 | case SOCKS5_REQUEST: | 2961 | case SOCKS5_REQUEST: |
2966 | GNUNET_assert (NULL != s5r->rtask); | 2962 | GNUNET_assert(NULL != s5r->rtask); |
2967 | break; | 2963 | break; |
2964 | |||
2968 | case SOCKS5_DATA_TRANSFER: | 2965 | case SOCKS5_DATA_TRANSFER: |
2969 | setup_data_transfer (s5r); | 2966 | setup_data_transfer(s5r); |
2970 | return; | 2967 | return; |
2968 | |||
2971 | case SOCKS5_WRITE_THEN_CLEANUP: | 2969 | case SOCKS5_WRITE_THEN_CLEANUP: |
2972 | cleanup_s5r (s5r); | 2970 | cleanup_s5r(s5r); |
2973 | return; | 2971 | return; |
2972 | |||
2974 | default: | 2973 | default: |
2975 | GNUNET_break (0); | 2974 | GNUNET_break(0); |
2976 | break; | 2975 | break; |
2977 | } | 2976 | } |
2978 | } | 2977 | } |
2979 | 2978 | ||
2980 | 2979 | ||
@@ -2985,21 +2984,21 @@ do_write (void *cls) | |||
2985 | * @param sc status code to return | 2984 | * @param sc status code to return |
2986 | */ | 2985 | */ |
2987 | static void | 2986 | static void |
2988 | signal_socks_failure (struct Socks5Request *s5r, | 2987 | signal_socks_failure(struct Socks5Request *s5r, |
2989 | enum Socks5StatusCode sc) | 2988 | enum Socks5StatusCode sc) |
2990 | { | 2989 | { |
2991 | struct Socks5ServerResponseMessage *s_resp; | 2990 | struct Socks5ServerResponseMessage *s_resp; |
2992 | 2991 | ||
2993 | s_resp = (struct Socks5ServerResponseMessage *) &s5r->wbuf[s5r->wbuf_len]; | 2992 | s_resp = (struct Socks5ServerResponseMessage *)&s5r->wbuf[s5r->wbuf_len]; |
2994 | memset (s_resp, 0, sizeof (struct Socks5ServerResponseMessage)); | 2993 | memset(s_resp, 0, sizeof(struct Socks5ServerResponseMessage)); |
2995 | s_resp->version = SOCKS_VERSION_5; | 2994 | s_resp->version = SOCKS_VERSION_5; |
2996 | s_resp->reply = sc; | 2995 | s_resp->reply = sc; |
2997 | s5r->state = SOCKS5_WRITE_THEN_CLEANUP; | 2996 | s5r->state = SOCKS5_WRITE_THEN_CLEANUP; |
2998 | if (NULL != s5r->wtask) | 2997 | if (NULL != s5r->wtask) |
2999 | s5r->wtask = | 2998 | s5r->wtask = |
3000 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 2999 | GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, |
3001 | s5r->sock, | 3000 | s5r->sock, |
3002 | &do_write, s5r); | 3001 | &do_write, s5r); |
3003 | } | 3002 | } |
3004 | 3003 | ||
3005 | 3004 | ||
@@ -3009,26 +3008,26 @@ signal_socks_failure (struct Socks5Request *s5r, | |||
3009 | * @param s5r request to return success status message for | 3008 | * @param s5r request to return success status message for |
3010 | */ | 3009 | */ |
3011 | static void | 3010 | static void |
3012 | signal_socks_success (struct Socks5Request *s5r) | 3011 | signal_socks_success(struct Socks5Request *s5r) |
3013 | { | 3012 | { |
3014 | struct Socks5ServerResponseMessage *s_resp; | 3013 | struct Socks5ServerResponseMessage *s_resp; |
3015 | 3014 | ||
3016 | s_resp = (struct Socks5ServerResponseMessage *) &s5r->wbuf[s5r->wbuf_len]; | 3015 | s_resp = (struct Socks5ServerResponseMessage *)&s5r->wbuf[s5r->wbuf_len]; |
3017 | s_resp->version = SOCKS_VERSION_5; | 3016 | s_resp->version = SOCKS_VERSION_5; |
3018 | s_resp->reply = SOCKS5_STATUS_REQUEST_GRANTED; | 3017 | s_resp->reply = SOCKS5_STATUS_REQUEST_GRANTED; |
3019 | s_resp->reserved = 0; | 3018 | s_resp->reserved = 0; |
3020 | s_resp->addr_type = SOCKS5_AT_IPV4; | 3019 | s_resp->addr_type = SOCKS5_AT_IPV4; |
3021 | /* zero out IPv4 address and port */ | 3020 | /* zero out IPv4 address and port */ |
3022 | memset (&s_resp[1], | 3021 | memset(&s_resp[1], |
3023 | 0, | 3022 | 0, |
3024 | sizeof (struct in_addr) + sizeof (uint16_t)); | 3023 | sizeof(struct in_addr) + sizeof(uint16_t)); |
3025 | s5r->wbuf_len += sizeof (struct Socks5ServerResponseMessage) + | 3024 | s5r->wbuf_len += sizeof(struct Socks5ServerResponseMessage) + |
3026 | sizeof (struct in_addr) + sizeof (uint16_t); | 3025 | sizeof(struct in_addr) + sizeof(uint16_t); |
3027 | if (NULL == s5r->wtask) | 3026 | if (NULL == s5r->wtask) |
3028 | s5r->wtask = | 3027 | s5r->wtask = |
3029 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3028 | GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, |
3030 | s5r->sock, | 3029 | s5r->sock, |
3031 | &do_write, s5r); | 3030 | &do_write, s5r); |
3032 | } | 3031 | } |
3033 | 3032 | ||
3034 | 3033 | ||
@@ -3041,10 +3040,10 @@ signal_socks_success (struct Socks5Request *s5r) | |||
3041 | * @param rd record data | 3040 | * @param rd record data |
3042 | */ | 3041 | */ |
3043 | static void | 3042 | static void |
3044 | handle_gns_result (void *cls, | 3043 | handle_gns_result(void *cls, |
3045 | int tld, | 3044 | int tld, |
3046 | uint32_t rd_count, | 3045 | uint32_t rd_count, |
3047 | const struct GNUNET_GNSRECORD_Data *rd) | 3046 | const struct GNUNET_GNSRECORD_Data *rd) |
3048 | { | 3047 | { |
3049 | struct Socks5Request *s5r = cls; | 3048 | struct Socks5Request *s5r = cls; |
3050 | const struct GNUNET_GNSRECORD_Data *r; | 3049 | const struct GNUNET_GNSRECORD_Data *r; |
@@ -3053,118 +3052,123 @@ handle_gns_result (void *cls, | |||
3053 | s5r->gns_lookup = NULL; | 3052 | s5r->gns_lookup = NULL; |
3054 | s5r->is_gns = tld; | 3053 | s5r->is_gns = tld; |
3055 | got_ip = GNUNET_NO; | 3054 | got_ip = GNUNET_NO; |
3056 | for (uint32_t i=0;i<rd_count;i++) | 3055 | for (uint32_t i = 0; i < rd_count; i++) |
3057 | { | ||
3058 | r = &rd[i]; | ||
3059 | switch (r->record_type) | ||
3060 | { | 3056 | { |
3061 | case GNUNET_DNSPARSER_TYPE_A: | 3057 | r = &rd[i]; |
3058 | switch (r->record_type) | ||
3059 | { | ||
3060 | case GNUNET_DNSPARSER_TYPE_A: | ||
3062 | { | 3061 | { |
3063 | struct sockaddr_in *in; | 3062 | struct sockaddr_in *in; |
3064 | 3063 | ||
3065 | if (sizeof (struct in_addr) != r->data_size) | 3064 | if (sizeof(struct in_addr) != r->data_size) |
3066 | { | 3065 | { |
3067 | GNUNET_break_op (0); | 3066 | GNUNET_break_op(0); |
3068 | break; | 3067 | break; |
3069 | } | 3068 | } |
3070 | if (GNUNET_YES == got_ip) | 3069 | if (GNUNET_YES == got_ip) |
3071 | break; | 3070 | break; |
3072 | if (GNUNET_OK != | 3071 | if (GNUNET_OK != |
3073 | GNUNET_NETWORK_test_pf (PF_INET)) | 3072 | GNUNET_NETWORK_test_pf(PF_INET)) |
3074 | break; | 3073 | break; |
3075 | got_ip = GNUNET_YES; | 3074 | got_ip = GNUNET_YES; |
3076 | in = (struct sockaddr_in *) &s5r->destination_address; | 3075 | in = (struct sockaddr_in *)&s5r->destination_address; |
3077 | in->sin_family = AF_INET; | 3076 | in->sin_family = AF_INET; |
3078 | GNUNET_memcpy (&in->sin_addr, | 3077 | GNUNET_memcpy(&in->sin_addr, |
3079 | r->data, | 3078 | r->data, |
3080 | r->data_size); | 3079 | r->data_size); |
3081 | in->sin_port = htons (s5r->port); | 3080 | in->sin_port = htons(s5r->port); |
3082 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3081 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3083 | in->sin_len = sizeof (*in); | 3082 | in->sin_len = sizeof(*in); |
3084 | #endif | 3083 | #endif |
3085 | } | 3084 | } |
3086 | break; | 3085 | break; |
3087 | case GNUNET_DNSPARSER_TYPE_AAAA: | 3086 | |
3087 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
3088 | { | 3088 | { |
3089 | struct sockaddr_in6 *in; | 3089 | struct sockaddr_in6 *in; |
3090 | 3090 | ||
3091 | if (sizeof (struct in6_addr) != r->data_size) | 3091 | if (sizeof(struct in6_addr) != r->data_size) |
3092 | { | 3092 | { |
3093 | GNUNET_break_op (0); | 3093 | GNUNET_break_op(0); |
3094 | break; | 3094 | break; |
3095 | } | 3095 | } |
3096 | if (GNUNET_YES == got_ip) | 3096 | if (GNUNET_YES == got_ip) |
3097 | break; | 3097 | break; |
3098 | if (GNUNET_YES == disable_v6) | 3098 | if (GNUNET_YES == disable_v6) |
3099 | break; | 3099 | break; |
3100 | if (GNUNET_OK != | 3100 | if (GNUNET_OK != |
3101 | GNUNET_NETWORK_test_pf (PF_INET6)) | 3101 | GNUNET_NETWORK_test_pf(PF_INET6)) |
3102 | break; | 3102 | break; |
3103 | /* FIXME: allow user to disable IPv6 per configuration option... */ | 3103 | /* FIXME: allow user to disable IPv6 per configuration option... */ |
3104 | got_ip = GNUNET_YES; | 3104 | got_ip = GNUNET_YES; |
3105 | in = (struct sockaddr_in6 *) &s5r->destination_address; | 3105 | in = (struct sockaddr_in6 *)&s5r->destination_address; |
3106 | in->sin6_family = AF_INET6; | 3106 | in->sin6_family = AF_INET6; |
3107 | GNUNET_memcpy (&in->sin6_addr, | 3107 | GNUNET_memcpy(&in->sin6_addr, |
3108 | r->data, | 3108 | r->data, |
3109 | r->data_size); | 3109 | r->data_size); |
3110 | in->sin6_port = htons (s5r->port); | 3110 | in->sin6_port = htons(s5r->port); |
3111 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3111 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3112 | in->sin6_len = sizeof (*in); | 3112 | in->sin6_len = sizeof(*in); |
3113 | #endif | 3113 | #endif |
3114 | } | 3114 | } |
3115 | break; | 3115 | break; |
3116 | case GNUNET_GNSRECORD_TYPE_VPN: | 3116 | |
3117 | GNUNET_break (0); /* should have been translated within GNS */ | 3117 | case GNUNET_GNSRECORD_TYPE_VPN: |
3118 | break; | 3118 | GNUNET_break(0); /* should have been translated within GNS */ |
3119 | case GNUNET_GNSRECORD_TYPE_LEHO: | 3119 | break; |
3120 | GNUNET_free_non_null (s5r->leho); | 3120 | |
3121 | s5r->leho = GNUNET_strndup (r->data, | 3121 | case GNUNET_GNSRECORD_TYPE_LEHO: |
3122 | r->data_size); | 3122 | GNUNET_free_non_null(s5r->leho); |
3123 | break; | 3123 | s5r->leho = GNUNET_strndup(r->data, |
3124 | case GNUNET_GNSRECORD_TYPE_BOX: | 3124 | r->data_size); |
3125 | break; | ||
3126 | |||
3127 | case GNUNET_GNSRECORD_TYPE_BOX: | ||
3125 | { | 3128 | { |
3126 | const struct GNUNET_GNSRECORD_BoxRecord *box; | 3129 | const struct GNUNET_GNSRECORD_BoxRecord *box; |
3127 | 3130 | ||
3128 | if (r->data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord)) | 3131 | if (r->data_size < sizeof(struct GNUNET_GNSRECORD_BoxRecord)) |
3129 | { | 3132 | { |
3130 | GNUNET_break_op (0); | 3133 | GNUNET_break_op(0); |
3131 | break; | 3134 | break; |
3132 | } | 3135 | } |
3133 | box = r->data; | 3136 | box = r->data; |
3134 | if ( (ntohl (box->record_type) != GNUNET_DNSPARSER_TYPE_TLSA) || | 3137 | if ((ntohl(box->record_type) != GNUNET_DNSPARSER_TYPE_TLSA) || |
3135 | (ntohs (box->protocol) != IPPROTO_TCP) || | 3138 | (ntohs(box->protocol) != IPPROTO_TCP) || |
3136 | (ntohs (box->service) != s5r->port) ) | 3139 | (ntohs(box->service) != s5r->port)) |
3137 | break; /* BOX record does not apply */ | 3140 | break; /* BOX record does not apply */ |
3138 | if (s5r->num_danes >= MAX_DANES) | 3141 | if (s5r->num_danes >= MAX_DANES) |
3139 | { | 3142 | { |
3140 | GNUNET_break (0); /* MAX_DANES too small */ | 3143 | GNUNET_break(0); /* MAX_DANES too small */ |
3141 | break; | 3144 | break; |
3142 | } | 3145 | } |
3143 | s5r->is_tls = GNUNET_YES; /* This should be TLS */ | 3146 | s5r->is_tls = GNUNET_YES; /* This should be TLS */ |
3144 | s5r->dane_data_len[s5r->num_danes] | 3147 | s5r->dane_data_len[s5r->num_danes] |
3145 | = r->data_size - sizeof (struct GNUNET_GNSRECORD_BoxRecord); | 3148 | = r->data_size - sizeof(struct GNUNET_GNSRECORD_BoxRecord); |
3146 | s5r->dane_data[s5r->num_danes] | 3149 | s5r->dane_data[s5r->num_danes] |
3147 | = GNUNET_memdup (&box[1], | 3150 | = GNUNET_memdup(&box[1], |
3148 | s5r->dane_data_len[s5r->num_danes]); | 3151 | s5r->dane_data_len[s5r->num_danes]); |
3149 | s5r->num_danes++; | 3152 | s5r->num_danes++; |
3153 | break; | ||
3154 | } | ||
3155 | |||
3156 | default: | ||
3157 | /* don't care */ | ||
3150 | break; | 3158 | break; |
3151 | } | 3159 | } |
3152 | default: | ||
3153 | /* don't care */ | ||
3154 | break; | ||
3155 | } | 3160 | } |
3156 | } | 3161 | if ((GNUNET_YES != got_ip) && |
3157 | if ( (GNUNET_YES != got_ip) && | 3162 | (GNUNET_YES == tld)) |
3158 | (GNUNET_YES == tld) ) | 3163 | { |
3159 | { | 3164 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3165 | "Name resolution failed to yield useful IP address.\n"); |
3161 | "Name resolution failed to yield useful IP address.\n"); | 3166 | signal_socks_failure(s5r, |
3162 | signal_socks_failure (s5r, | 3167 | SOCKS5_STATUS_GENERAL_FAILURE); |
3163 | SOCKS5_STATUS_GENERAL_FAILURE); | 3168 | return; |
3164 | return; | 3169 | } |
3165 | } | ||
3166 | s5r->state = SOCKS5_DATA_TRANSFER; | 3170 | s5r->state = SOCKS5_DATA_TRANSFER; |
3167 | signal_socks_success (s5r); | 3171 | signal_socks_success(s5r); |
3168 | } | 3172 | } |
3169 | 3173 | ||
3170 | 3174 | ||
@@ -3175,13 +3179,13 @@ handle_gns_result (void *cls, | |||
3175 | * @param len number of bytes in read buffer to advance | 3179 | * @param len number of bytes in read buffer to advance |
3176 | */ | 3180 | */ |
3177 | static void | 3181 | static void |
3178 | clear_from_s5r_rbuf (struct Socks5Request *s5r, | 3182 | clear_from_s5r_rbuf(struct Socks5Request *s5r, |
3179 | size_t len) | 3183 | size_t len) |
3180 | { | 3184 | { |
3181 | GNUNET_assert (len <= s5r->rbuf_len); | 3185 | GNUNET_assert(len <= s5r->rbuf_len); |
3182 | memmove (s5r->rbuf, | 3186 | memmove(s5r->rbuf, |
3183 | &s5r->rbuf[len], | 3187 | &s5r->rbuf[len], |
3184 | s5r->rbuf_len - len); | 3188 | s5r->rbuf_len - len); |
3185 | s5r->rbuf_len -= len; | 3189 | s5r->rbuf_len -= len; |
3186 | } | 3190 | } |
3187 | 3191 | ||
@@ -3192,7 +3196,7 @@ clear_from_s5r_rbuf (struct Socks5Request *s5r, | |||
3192 | * @param cls the closure with the `struct Socks5Request` | 3196 | * @param cls the closure with the `struct Socks5Request` |
3193 | */ | 3197 | */ |
3194 | static void | 3198 | static void |
3195 | do_s5r_read (void *cls) | 3199 | do_s5r_read(void *cls) |
3196 | { | 3200 | { |
3197 | struct Socks5Request *s5r = cls; | 3201 | struct Socks5Request *s5r = cls; |
3198 | const struct Socks5ClientHelloMessage *c_hello; | 3202 | const struct Socks5ClientHelloMessage *c_hello; |
@@ -3203,188 +3207,196 @@ do_s5r_read (void *cls) | |||
3203 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 3207 | const struct GNUNET_SCHEDULER_TaskContext *tc; |
3204 | 3208 | ||
3205 | s5r->rtask = NULL; | 3209 | s5r->rtask = NULL; |
3206 | tc = GNUNET_SCHEDULER_get_task_context (); | 3210 | tc = GNUNET_SCHEDULER_get_task_context(); |
3207 | if ( (NULL != tc->read_ready) && | 3211 | if ((NULL != tc->read_ready) && |
3208 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, | 3212 | (GNUNET_NETWORK_fdset_isset(tc->read_ready, |
3209 | s5r->sock)) ) | 3213 | s5r->sock))) |
3210 | { | 3214 | { |
3211 | rlen = GNUNET_NETWORK_socket_recv (s5r->sock, | 3215 | rlen = GNUNET_NETWORK_socket_recv(s5r->sock, |
3212 | &s5r->rbuf[s5r->rbuf_len], | 3216 | &s5r->rbuf[s5r->rbuf_len], |
3213 | sizeof (s5r->rbuf) - s5r->rbuf_len); | 3217 | sizeof(s5r->rbuf) - s5r->rbuf_len); |
3214 | if (rlen <= 0) | 3218 | if (rlen <= 0) |
3215 | { | 3219 | { |
3216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3220 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3217 | "socks5 client disconnected.\n"); | 3221 | "socks5 client disconnected.\n"); |
3218 | cleanup_s5r (s5r); | 3222 | cleanup_s5r(s5r); |
3219 | return; | 3223 | return; |
3224 | } | ||
3225 | s5r->rbuf_len += rlen; | ||
3220 | } | 3226 | } |
3221 | s5r->rbuf_len += rlen; | 3227 | s5r->rtask = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, |
3222 | } | 3228 | s5r->sock, |
3223 | s5r->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3229 | &do_s5r_read, s5r); |
3224 | s5r->sock, | 3230 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3225 | &do_s5r_read, s5r); | 3231 | "Processing %zu bytes of socks data in state %d\n", |
3226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3232 | s5r->rbuf_len, |
3227 | "Processing %zu bytes of socks data in state %d\n", | 3233 | s5r->state); |
3228 | s5r->rbuf_len, | ||
3229 | s5r->state); | ||
3230 | switch (s5r->state) | 3234 | switch (s5r->state) |
3231 | { | 3235 | { |
3232 | case SOCKS5_INIT: | 3236 | case SOCKS5_INIT: |
3233 | c_hello = (const struct Socks5ClientHelloMessage*) &s5r->rbuf; | 3237 | c_hello = (const struct Socks5ClientHelloMessage*)&s5r->rbuf; |
3234 | if ( (s5r->rbuf_len < sizeof (struct Socks5ClientHelloMessage)) || | 3238 | if ((s5r->rbuf_len < sizeof(struct Socks5ClientHelloMessage)) || |
3235 | (s5r->rbuf_len < sizeof (struct Socks5ClientHelloMessage) + c_hello->num_auth_methods) ) | 3239 | (s5r->rbuf_len < sizeof(struct Socks5ClientHelloMessage) + c_hello->num_auth_methods)) |
3236 | return; /* need more data */ | 3240 | return; /* need more data */ |
3237 | if (SOCKS_VERSION_5 != c_hello->version) | 3241 | if (SOCKS_VERSION_5 != c_hello->version) |
3238 | { | 3242 | { |
3239 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3243 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3240 | _("Unsupported socks version %d\n"), | 3244 | _("Unsupported socks version %d\n"), |
3241 | (int) c_hello->version); | 3245 | (int)c_hello->version); |
3242 | cleanup_s5r (s5r); | 3246 | cleanup_s5r(s5r); |
3243 | return; | 3247 | return; |
3244 | } | 3248 | } |
3245 | clear_from_s5r_rbuf (s5r, | 3249 | clear_from_s5r_rbuf(s5r, |
3246 | sizeof (struct Socks5ClientHelloMessage) + c_hello->num_auth_methods); | 3250 | sizeof(struct Socks5ClientHelloMessage) + c_hello->num_auth_methods); |
3247 | GNUNET_assert (0 == s5r->wbuf_len); | 3251 | GNUNET_assert(0 == s5r->wbuf_len); |
3248 | s_hello = (struct Socks5ServerHelloMessage *) &s5r->wbuf; | 3252 | s_hello = (struct Socks5ServerHelloMessage *)&s5r->wbuf; |
3249 | s5r->wbuf_len = sizeof (struct Socks5ServerHelloMessage); | 3253 | s5r->wbuf_len = sizeof(struct Socks5ServerHelloMessage); |
3250 | s_hello->version = SOCKS_VERSION_5; | 3254 | s_hello->version = SOCKS_VERSION_5; |
3251 | s_hello->auth_method = SOCKS_AUTH_NONE; | 3255 | s_hello->auth_method = SOCKS_AUTH_NONE; |
3252 | GNUNET_assert (NULL == s5r->wtask); | 3256 | GNUNET_assert(NULL == s5r->wtask); |
3253 | s5r->wtask = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3257 | s5r->wtask = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, |
3254 | s5r->sock, | 3258 | s5r->sock, |
3255 | &do_write, s5r); | 3259 | &do_write, s5r); |
3256 | s5r->state = SOCKS5_REQUEST; | 3260 | s5r->state = SOCKS5_REQUEST; |
3257 | return; | 3261 | return; |
3262 | |||
3258 | case SOCKS5_REQUEST: | 3263 | case SOCKS5_REQUEST: |
3259 | c_req = (const struct Socks5ClientRequestMessage *) &s5r->rbuf; | 3264 | c_req = (const struct Socks5ClientRequestMessage *)&s5r->rbuf; |
3260 | if (s5r->rbuf_len < sizeof (struct Socks5ClientRequestMessage)) | 3265 | if (s5r->rbuf_len < sizeof(struct Socks5ClientRequestMessage)) |
3261 | return; | 3266 | return; |
3262 | switch (c_req->command) | 3267 | switch (c_req->command) |
3263 | { | 3268 | { |
3264 | case SOCKS5_CMD_TCP_STREAM: | 3269 | case SOCKS5_CMD_TCP_STREAM: |
3265 | /* handled below */ | 3270 | /* handled below */ |
3266 | break; | 3271 | break; |
3272 | |||
3267 | default: | 3273 | default: |
3268 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3274 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3269 | _("Unsupported socks command %d\n"), | 3275 | _("Unsupported socks command %d\n"), |
3270 | (int) c_req->command); | 3276 | (int)c_req->command); |
3271 | signal_socks_failure (s5r, | 3277 | signal_socks_failure(s5r, |
3272 | SOCKS5_STATUS_COMMAND_NOT_SUPPORTED); | 3278 | SOCKS5_STATUS_COMMAND_NOT_SUPPORTED); |
3273 | return; | 3279 | return; |
3274 | } | 3280 | } |
3275 | switch (c_req->addr_type) | 3281 | switch (c_req->addr_type) |
3276 | { | 3282 | { |
3277 | case SOCKS5_AT_IPV4: | 3283 | case SOCKS5_AT_IPV4: |
3278 | { | 3284 | { |
3279 | const struct in_addr *v4 = (const struct in_addr *) &c_req[1]; | 3285 | const struct in_addr *v4 = (const struct in_addr *)&c_req[1]; |
3280 | const uint16_t *port = (const uint16_t *) &v4[1]; | 3286 | const uint16_t *port = (const uint16_t *)&v4[1]; |
3281 | struct sockaddr_in *in; | 3287 | struct sockaddr_in *in; |
3282 | 3288 | ||
3283 | s5r->port = ntohs (*port); | 3289 | s5r->port = ntohs(*port); |
3284 | alen = sizeof (struct in_addr); | 3290 | alen = sizeof(struct in_addr); |
3285 | if (s5r->rbuf_len < sizeof (struct Socks5ClientRequestMessage) + | 3291 | if (s5r->rbuf_len < sizeof(struct Socks5ClientRequestMessage) + |
3286 | alen + sizeof (uint16_t)) | 3292 | alen + sizeof(uint16_t)) |
3287 | return; /* need more data */ | 3293 | return; /* need more data */ |
3288 | in = (struct sockaddr_in *) &s5r->destination_address; | 3294 | in = (struct sockaddr_in *)&s5r->destination_address; |
3289 | in->sin_family = AF_INET; | 3295 | in->sin_family = AF_INET; |
3290 | in->sin_addr = *v4; | 3296 | in->sin_addr = *v4; |
3291 | in->sin_port = *port; | 3297 | in->sin_port = *port; |
3292 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3298 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3293 | in->sin_len = sizeof (*in); | 3299 | in->sin_len = sizeof(*in); |
3294 | #endif | 3300 | #endif |
3295 | s5r->state = SOCKS5_DATA_TRANSFER; | 3301 | s5r->state = SOCKS5_DATA_TRANSFER; |
3296 | } | 3302 | } |
3297 | break; | 3303 | break; |
3304 | |||
3298 | case SOCKS5_AT_IPV6: | 3305 | case SOCKS5_AT_IPV6: |
3299 | { | 3306 | { |
3300 | const struct in6_addr *v6 = (const struct in6_addr *) &c_req[1]; | 3307 | const struct in6_addr *v6 = (const struct in6_addr *)&c_req[1]; |
3301 | const uint16_t *port = (const uint16_t *) &v6[1]; | 3308 | const uint16_t *port = (const uint16_t *)&v6[1]; |
3302 | struct sockaddr_in6 *in; | 3309 | struct sockaddr_in6 *in; |
3303 | 3310 | ||
3304 | s5r->port = ntohs (*port); | 3311 | s5r->port = ntohs(*port); |
3305 | alen = sizeof (struct in6_addr); | 3312 | alen = sizeof(struct in6_addr); |
3306 | if (s5r->rbuf_len < sizeof (struct Socks5ClientRequestMessage) + | 3313 | if (s5r->rbuf_len < sizeof(struct Socks5ClientRequestMessage) + |
3307 | alen + sizeof (uint16_t)) | 3314 | alen + sizeof(uint16_t)) |
3308 | return; /* need more data */ | 3315 | return; /* need more data */ |
3309 | in = (struct sockaddr_in6 *) &s5r->destination_address; | 3316 | in = (struct sockaddr_in6 *)&s5r->destination_address; |
3310 | in->sin6_family = AF_INET6; | 3317 | in->sin6_family = AF_INET6; |
3311 | in->sin6_addr = *v6; | 3318 | in->sin6_addr = *v6; |
3312 | in->sin6_port = *port; | 3319 | in->sin6_port = *port; |
3313 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3320 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3314 | in->sin6_len = sizeof (*in); | 3321 | in->sin6_len = sizeof(*in); |
3315 | #endif | 3322 | #endif |
3316 | s5r->state = SOCKS5_DATA_TRANSFER; | 3323 | s5r->state = SOCKS5_DATA_TRANSFER; |
3317 | } | 3324 | } |
3318 | break; | 3325 | break; |
3326 | |||
3319 | case SOCKS5_AT_DOMAINNAME: | 3327 | case SOCKS5_AT_DOMAINNAME: |
3320 | { | 3328 | { |
3321 | const uint8_t *dom_len; | 3329 | const uint8_t *dom_len; |
3322 | const char *dom_name; | 3330 | const char *dom_name; |
3323 | const uint16_t *port; | 3331 | const uint16_t *port; |
3324 | 3332 | ||
3325 | dom_len = (const uint8_t *) &c_req[1]; | 3333 | dom_len = (const uint8_t *)&c_req[1]; |
3326 | alen = *dom_len + 1; | 3334 | alen = *dom_len + 1; |
3327 | if (s5r->rbuf_len < sizeof (struct Socks5ClientRequestMessage) + | 3335 | if (s5r->rbuf_len < sizeof(struct Socks5ClientRequestMessage) + |
3328 | alen + sizeof (uint16_t)) | 3336 | alen + sizeof(uint16_t)) |
3329 | return; /* need more data */ | 3337 | return; /* need more data */ |
3330 | dom_name = (const char *) &dom_len[1]; | 3338 | dom_name = (const char *)&dom_len[1]; |
3331 | port = (const uint16_t*) &dom_name[*dom_len]; | 3339 | port = (const uint16_t*)&dom_name[*dom_len]; |
3332 | s5r->domain = GNUNET_strndup (dom_name, | 3340 | s5r->domain = GNUNET_strndup(dom_name, |
3333 | *dom_len); | 3341 | *dom_len); |
3334 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3342 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3335 | "Requested connection is to %s:%d\n", | 3343 | "Requested connection is to %s:%d\n", |
3336 | //(HTTPS_PORT == s5r->port) ? "s" : "", | 3344 | //(HTTPS_PORT == s5r->port) ? "s" : "", |
3337 | s5r->domain, | 3345 | s5r->domain, |
3338 | ntohs (*port)); | 3346 | ntohs(*port)); |
3339 | s5r->state = SOCKS5_RESOLVING; | 3347 | s5r->state = SOCKS5_RESOLVING; |
3340 | s5r->port = ntohs (*port); | 3348 | s5r->port = ntohs(*port); |
3341 | s5r->is_tls = (HTTPS_PORT == s5r->port) ? GNUNET_YES : GNUNET_NO; | 3349 | s5r->is_tls = (HTTPS_PORT == s5r->port) ? GNUNET_YES : GNUNET_NO; |
3342 | s5r->gns_lookup = GNUNET_GNS_lookup_with_tld (gns_handle, | 3350 | s5r->gns_lookup = GNUNET_GNS_lookup_with_tld(gns_handle, |
3343 | s5r->domain, | 3351 | s5r->domain, |
3344 | GNUNET_DNSPARSER_TYPE_A, | 3352 | GNUNET_DNSPARSER_TYPE_A, |
3345 | GNUNET_NO /* only cached */, | 3353 | GNUNET_NO /* only cached */, |
3346 | &handle_gns_result, | 3354 | &handle_gns_result, |
3347 | s5r); | 3355 | s5r); |
3348 | break; | 3356 | break; |
3349 | } | 3357 | } |
3358 | |||
3350 | default: | 3359 | default: |
3351 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3360 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3352 | _("Unsupported socks address type %d\n"), | 3361 | _("Unsupported socks address type %d\n"), |
3353 | (int) c_req->addr_type); | 3362 | (int)c_req->addr_type); |
3354 | signal_socks_failure (s5r, | 3363 | signal_socks_failure(s5r, |
3355 | SOCKS5_STATUS_ADDRESS_TYPE_NOT_SUPPORTED); | 3364 | SOCKS5_STATUS_ADDRESS_TYPE_NOT_SUPPORTED); |
3356 | return; | 3365 | return; |
3357 | } | 3366 | } |
3358 | clear_from_s5r_rbuf (s5r, | 3367 | clear_from_s5r_rbuf(s5r, |
3359 | sizeof (struct Socks5ClientRequestMessage) + | 3368 | sizeof(struct Socks5ClientRequestMessage) + |
3360 | alen + sizeof (uint16_t)); | 3369 | alen + sizeof(uint16_t)); |
3361 | if (0 != s5r->rbuf_len) | 3370 | if (0 != s5r->rbuf_len) |
3362 | { | 3371 | { |
3363 | /* read more bytes than healthy, why did the client send more!? */ | 3372 | /* read more bytes than healthy, why did the client send more!? */ |
3364 | GNUNET_break_op (0); | 3373 | GNUNET_break_op(0); |
3365 | signal_socks_failure (s5r, | 3374 | signal_socks_failure(s5r, |
3366 | SOCKS5_STATUS_GENERAL_FAILURE); | 3375 | SOCKS5_STATUS_GENERAL_FAILURE); |
3367 | return; | 3376 | return; |
3368 | } | 3377 | } |
3369 | if (SOCKS5_DATA_TRANSFER == s5r->state) | 3378 | if (SOCKS5_DATA_TRANSFER == s5r->state) |
3370 | { | 3379 | { |
3371 | /* if we are not waiting for GNS resolution, signal success */ | 3380 | /* if we are not waiting for GNS resolution, signal success */ |
3372 | signal_socks_success (s5r); | 3381 | signal_socks_success(s5r); |
3373 | } | 3382 | } |
3374 | /* We are done reading right now */ | 3383 | /* We are done reading right now */ |
3375 | GNUNET_SCHEDULER_cancel (s5r->rtask); | 3384 | GNUNET_SCHEDULER_cancel(s5r->rtask); |
3376 | s5r->rtask = NULL; | 3385 | s5r->rtask = NULL; |
3377 | return; | 3386 | return; |
3387 | |||
3378 | case SOCKS5_RESOLVING: | 3388 | case SOCKS5_RESOLVING: |
3379 | GNUNET_assert (0); | 3389 | GNUNET_assert(0); |
3380 | return; | 3390 | return; |
3391 | |||
3381 | case SOCKS5_DATA_TRANSFER: | 3392 | case SOCKS5_DATA_TRANSFER: |
3382 | GNUNET_assert (0); | 3393 | GNUNET_assert(0); |
3383 | return; | 3394 | return; |
3395 | |||
3384 | default: | 3396 | default: |
3385 | GNUNET_assert (0); | 3397 | GNUNET_assert(0); |
3386 | return; | 3398 | return; |
3387 | } | 3399 | } |
3388 | } | 3400 | } |
3389 | 3401 | ||
3390 | 3402 | ||
@@ -3395,46 +3407,46 @@ do_s5r_read (void *cls) | |||
3395 | * @param tc the scheduler context | 3407 | * @param tc the scheduler context |
3396 | */ | 3408 | */ |
3397 | static void | 3409 | static void |
3398 | do_accept (void *cls) | 3410 | do_accept(void *cls) |
3399 | { | 3411 | { |
3400 | struct GNUNET_NETWORK_Handle *lsock = cls; | 3412 | struct GNUNET_NETWORK_Handle *lsock = cls; |
3401 | struct GNUNET_NETWORK_Handle *s; | 3413 | struct GNUNET_NETWORK_Handle *s; |
3402 | struct Socks5Request *s5r; | 3414 | struct Socks5Request *s5r; |
3403 | 3415 | ||
3404 | GNUNET_assert (NULL != lsock); | 3416 | GNUNET_assert(NULL != lsock); |
3405 | if (lsock == lsock4) | 3417 | if (lsock == lsock4) |
3406 | ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3418 | ltask4 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, |
3407 | lsock, | 3419 | lsock, |
3408 | &do_accept, | 3420 | &do_accept, |
3409 | lsock); | 3421 | lsock); |
3410 | else if (lsock == lsock6) | 3422 | else if (lsock == lsock6) |
3411 | ltask6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3423 | ltask6 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, |
3412 | lsock, | 3424 | lsock, |
3413 | &do_accept, | 3425 | &do_accept, |
3414 | lsock); | 3426 | lsock); |
3415 | else | 3427 | else |
3416 | GNUNET_assert (0); | 3428 | GNUNET_assert(0); |
3417 | s = GNUNET_NETWORK_socket_accept (lsock, | 3429 | s = GNUNET_NETWORK_socket_accept(lsock, |
3418 | NULL, | 3430 | NULL, |
3419 | NULL); | 3431 | NULL); |
3420 | if (NULL == s) | 3432 | if (NULL == s) |
3421 | { | 3433 | { |
3422 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 3434 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, |
3423 | "accept"); | 3435 | "accept"); |
3424 | return; | 3436 | return; |
3425 | } | 3437 | } |
3426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3438 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3427 | "Got an inbound connection, waiting for data\n"); | 3439 | "Got an inbound connection, waiting for data\n"); |
3428 | s5r = GNUNET_new (struct Socks5Request); | 3440 | s5r = GNUNET_new(struct Socks5Request); |
3429 | GNUNET_CONTAINER_DLL_insert (s5r_head, | 3441 | GNUNET_CONTAINER_DLL_insert(s5r_head, |
3430 | s5r_tail, | 3442 | s5r_tail, |
3431 | s5r); | 3443 | s5r); |
3432 | s5r->sock = s; | 3444 | s5r->sock = s; |
3433 | s5r->state = SOCKS5_INIT; | 3445 | s5r->state = SOCKS5_INIT; |
3434 | s5r->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3446 | s5r->rtask = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, |
3435 | s5r->sock, | 3447 | s5r->sock, |
3436 | &do_s5r_read, | 3448 | &do_s5r_read, |
3437 | s5r); | 3449 | s5r); |
3438 | } | 3450 | } |
3439 | 3451 | ||
3440 | 3452 | ||
@@ -3447,63 +3459,63 @@ do_accept (void *cls) | |||
3447 | * @param cls closure | 3459 | * @param cls closure |
3448 | */ | 3460 | */ |
3449 | static void | 3461 | static void |
3450 | do_shutdown (void *cls) | 3462 | do_shutdown(void *cls) |
3451 | { | 3463 | { |
3452 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 3464 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
3453 | "Shutting down...\n"); | 3465 | "Shutting down...\n"); |
3454 | /* MHD requires resuming before destroying the daemons */ | 3466 | /* MHD requires resuming before destroying the daemons */ |
3455 | for (struct Socks5Request *s5r = s5r_head; | 3467 | for (struct Socks5Request *s5r = s5r_head; |
3456 | NULL != s5r; | 3468 | NULL != s5r; |
3457 | s5r = s5r->next) | 3469 | s5r = s5r->next) |
3458 | { | ||
3459 | if (s5r->suspended) | ||
3460 | { | 3470 | { |
3461 | s5r->suspended = GNUNET_NO; | 3471 | if (s5r->suspended) |
3462 | MHD_resume_connection (s5r->con); | 3472 | { |
3473 | s5r->suspended = GNUNET_NO; | ||
3474 | MHD_resume_connection(s5r->con); | ||
3475 | } | ||
3463 | } | 3476 | } |
3464 | } | ||
3465 | while (NULL != mhd_httpd_head) | 3477 | while (NULL != mhd_httpd_head) |
3466 | kill_httpd (mhd_httpd_head); | 3478 | kill_httpd(mhd_httpd_head); |
3467 | while (NULL != s5r_head) | 3479 | while (NULL != s5r_head) |
3468 | cleanup_s5r (s5r_head); | 3480 | cleanup_s5r(s5r_head); |
3469 | if (NULL != lsock4) | 3481 | if (NULL != lsock4) |
3470 | { | 3482 | { |
3471 | GNUNET_NETWORK_socket_close (lsock4); | 3483 | GNUNET_NETWORK_socket_close(lsock4); |
3472 | lsock4 = NULL; | 3484 | lsock4 = NULL; |
3473 | } | 3485 | } |
3474 | if (NULL != lsock6) | 3486 | if (NULL != lsock6) |
3475 | { | 3487 | { |
3476 | GNUNET_NETWORK_socket_close (lsock6); | 3488 | GNUNET_NETWORK_socket_close(lsock6); |
3477 | lsock6 = NULL; | 3489 | lsock6 = NULL; |
3478 | } | 3490 | } |
3479 | if (NULL != curl_multi) | 3491 | if (NULL != curl_multi) |
3480 | { | 3492 | { |
3481 | curl_multi_cleanup (curl_multi); | 3493 | curl_multi_cleanup(curl_multi); |
3482 | curl_multi = NULL; | 3494 | curl_multi = NULL; |
3483 | } | 3495 | } |
3484 | if (NULL != gns_handle) | 3496 | if (NULL != gns_handle) |
3485 | { | 3497 | { |
3486 | GNUNET_GNS_disconnect (gns_handle); | 3498 | GNUNET_GNS_disconnect(gns_handle); |
3487 | gns_handle = NULL; | 3499 | gns_handle = NULL; |
3488 | } | 3500 | } |
3489 | if (NULL != curl_download_task) | 3501 | if (NULL != curl_download_task) |
3490 | { | 3502 | { |
3491 | GNUNET_SCHEDULER_cancel (curl_download_task); | 3503 | GNUNET_SCHEDULER_cancel(curl_download_task); |
3492 | curl_download_task = NULL; | 3504 | curl_download_task = NULL; |
3493 | } | 3505 | } |
3494 | if (NULL != ltask4) | 3506 | if (NULL != ltask4) |
3495 | { | 3507 | { |
3496 | GNUNET_SCHEDULER_cancel (ltask4); | 3508 | GNUNET_SCHEDULER_cancel(ltask4); |
3497 | ltask4 = NULL; | 3509 | ltask4 = NULL; |
3498 | } | 3510 | } |
3499 | if (NULL != ltask6) | 3511 | if (NULL != ltask6) |
3500 | { | 3512 | { |
3501 | GNUNET_SCHEDULER_cancel (ltask6); | 3513 | GNUNET_SCHEDULER_cancel(ltask6); |
3502 | ltask6 = NULL; | 3514 | ltask6 = NULL; |
3503 | } | 3515 | } |
3504 | gnutls_x509_crt_deinit (proxy_ca.cert); | 3516 | gnutls_x509_crt_deinit(proxy_ca.cert); |
3505 | gnutls_x509_privkey_deinit (proxy_ca.key); | 3517 | gnutls_x509_privkey_deinit(proxy_ca.key); |
3506 | gnutls_global_deinit (); | 3518 | gnutls_global_deinit(); |
3507 | } | 3519 | } |
3508 | 3520 | ||
3509 | 3521 | ||
@@ -3513,34 +3525,34 @@ do_shutdown (void *cls) | |||
3513 | * @return NULL on error | 3525 | * @return NULL on error |
3514 | */ | 3526 | */ |
3515 | static struct GNUNET_NETWORK_Handle * | 3527 | static struct GNUNET_NETWORK_Handle * |
3516 | bind_v4 () | 3528 | bind_v4() |
3517 | { | 3529 | { |
3518 | struct GNUNET_NETWORK_Handle *ls; | 3530 | struct GNUNET_NETWORK_Handle *ls; |
3519 | struct sockaddr_in sa4; | 3531 | struct sockaddr_in sa4; |
3520 | int eno; | 3532 | int eno; |
3521 | 3533 | ||
3522 | memset (&sa4, 0, sizeof (sa4)); | 3534 | memset(&sa4, 0, sizeof(sa4)); |
3523 | sa4.sin_family = AF_INET; | 3535 | sa4.sin_family = AF_INET; |
3524 | sa4.sin_port = htons (port); | 3536 | sa4.sin_port = htons(port); |
3525 | sa4.sin_addr.s_addr = address; | 3537 | sa4.sin_addr.s_addr = address; |
3526 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3538 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3527 | sa4.sin_len = sizeof (sa4); | 3539 | sa4.sin_len = sizeof(sa4); |
3528 | #endif | 3540 | #endif |
3529 | ls = GNUNET_NETWORK_socket_create (AF_INET, | 3541 | ls = GNUNET_NETWORK_socket_create(AF_INET, |
3530 | SOCK_STREAM, | 3542 | SOCK_STREAM, |
3531 | 0); | 3543 | 0); |
3532 | if (NULL == ls) | 3544 | if (NULL == ls) |
3533 | return NULL; | 3545 | return NULL; |
3534 | if (GNUNET_OK != | 3546 | if (GNUNET_OK != |
3535 | GNUNET_NETWORK_socket_bind (ls, | 3547 | GNUNET_NETWORK_socket_bind(ls, |
3536 | (const struct sockaddr *) &sa4, | 3548 | (const struct sockaddr *)&sa4, |
3537 | sizeof (sa4))) | 3549 | sizeof(sa4))) |
3538 | { | 3550 | { |
3539 | eno = errno; | 3551 | eno = errno; |
3540 | GNUNET_NETWORK_socket_close (ls); | 3552 | GNUNET_NETWORK_socket_close(ls); |
3541 | errno = eno; | 3553 | errno = eno; |
3542 | return NULL; | 3554 | return NULL; |
3543 | } | 3555 | } |
3544 | return ls; | 3556 | return ls; |
3545 | } | 3557 | } |
3546 | 3558 | ||
@@ -3551,34 +3563,34 @@ bind_v4 () | |||
3551 | * @return NULL on error | 3563 | * @return NULL on error |
3552 | */ | 3564 | */ |
3553 | static struct GNUNET_NETWORK_Handle * | 3565 | static struct GNUNET_NETWORK_Handle * |
3554 | bind_v6 () | 3566 | bind_v6() |
3555 | { | 3567 | { |
3556 | struct GNUNET_NETWORK_Handle *ls; | 3568 | struct GNUNET_NETWORK_Handle *ls; |
3557 | struct sockaddr_in6 sa6; | 3569 | struct sockaddr_in6 sa6; |
3558 | int eno; | 3570 | int eno; |
3559 | 3571 | ||
3560 | memset (&sa6, 0, sizeof (sa6)); | 3572 | memset(&sa6, 0, sizeof(sa6)); |
3561 | sa6.sin6_family = AF_INET6; | 3573 | sa6.sin6_family = AF_INET6; |
3562 | sa6.sin6_port = htons (port); | 3574 | sa6.sin6_port = htons(port); |
3563 | sa6.sin6_addr = address6; | 3575 | sa6.sin6_addr = address6; |
3564 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3576 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3565 | sa6.sin6_len = sizeof (sa6); | 3577 | sa6.sin6_len = sizeof(sa6); |
3566 | #endif | 3578 | #endif |
3567 | ls = GNUNET_NETWORK_socket_create (AF_INET6, | 3579 | ls = GNUNET_NETWORK_socket_create(AF_INET6, |
3568 | SOCK_STREAM, | 3580 | SOCK_STREAM, |
3569 | 0); | 3581 | 0); |
3570 | if (NULL == ls) | 3582 | if (NULL == ls) |
3571 | return NULL; | 3583 | return NULL; |
3572 | if (GNUNET_OK != | 3584 | if (GNUNET_OK != |
3573 | GNUNET_NETWORK_socket_bind (ls, | 3585 | GNUNET_NETWORK_socket_bind(ls, |
3574 | (const struct sockaddr *) &sa6, | 3586 | (const struct sockaddr *)&sa6, |
3575 | sizeof (sa6))) | 3587 | sizeof(sa6))) |
3576 | { | 3588 | { |
3577 | eno = errno; | 3589 | eno = errno; |
3578 | GNUNET_NETWORK_socket_close (ls); | 3590 | GNUNET_NETWORK_socket_close(ls); |
3579 | errno = eno; | 3591 | errno = eno; |
3580 | return NULL; | 3592 | return NULL; |
3581 | } | 3593 | } |
3582 | return ls; | 3594 | return ls; |
3583 | } | 3595 | } |
3584 | 3596 | ||
@@ -3592,10 +3604,10 @@ bind_v6 () | |||
3592 | * @param c configuration | 3604 | * @param c configuration |
3593 | */ | 3605 | */ |
3594 | static void | 3606 | static void |
3595 | run (void *cls, | 3607 | run(void *cls, |
3596 | char *const *args, | 3608 | char *const *args, |
3597 | const char *cfgfile, | 3609 | const char *cfgfile, |
3598 | const struct GNUNET_CONFIGURATION_Handle *c) | 3610 | const struct GNUNET_CONFIGURATION_Handle *c) |
3599 | { | 3611 | { |
3600 | char* cafile_cfg = NULL; | 3612 | char* cafile_cfg = NULL; |
3601 | char* cafile; | 3613 | char* cafile; |
@@ -3605,198 +3617,198 @@ run (void *cls, | |||
3605 | cfg = c; | 3617 | cfg = c; |
3606 | 3618 | ||
3607 | /* Get address to bind to */ | 3619 | /* Get address to bind to */ |
3608 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "gns-proxy", | 3620 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "gns-proxy", |
3609 | "BIND_TO", | 3621 | "BIND_TO", |
3610 | &addr_str)) | 3622 | &addr_str)) |
3611 | { | 3623 | { |
3612 | //No address specified | 3624 | //No address specified |
3613 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3625 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3614 | "Don't know what to bind to...\n"); | 3626 | "Don't know what to bind to...\n"); |
3615 | GNUNET_free (addr_str); | 3627 | GNUNET_free(addr_str); |
3616 | GNUNET_SCHEDULER_shutdown (); | 3628 | GNUNET_SCHEDULER_shutdown(); |
3617 | return; | 3629 | return; |
3618 | } | 3630 | } |
3619 | if (1 != inet_pton (AF_INET, addr_str, &address)) | 3631 | if (1 != inet_pton(AF_INET, addr_str, &address)) |
3620 | { | 3632 | { |
3621 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3633 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3622 | "Unable to parse address %s\n", | 3634 | "Unable to parse address %s\n", |
3623 | addr_str); | 3635 | addr_str); |
3624 | GNUNET_free (addr_str); | 3636 | GNUNET_free(addr_str); |
3625 | GNUNET_SCHEDULER_shutdown (); | 3637 | GNUNET_SCHEDULER_shutdown(); |
3626 | return; | 3638 | return; |
3627 | } | 3639 | } |
3628 | GNUNET_free (addr_str); | 3640 | GNUNET_free(addr_str); |
3629 | /* Get address to bind to */ | 3641 | /* Get address to bind to */ |
3630 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "gns-proxy", | 3642 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "gns-proxy", |
3631 | "BIND_TO6", | 3643 | "BIND_TO6", |
3632 | &addr_str)) | 3644 | &addr_str)) |
3633 | { | 3645 | { |
3634 | //No address specified | 3646 | //No address specified |
3635 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3647 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3636 | "Don't know what to bind6 to...\n"); | 3648 | "Don't know what to bind6 to...\n"); |
3637 | GNUNET_free (addr_str); | 3649 | GNUNET_free(addr_str); |
3638 | GNUNET_SCHEDULER_shutdown (); | 3650 | GNUNET_SCHEDULER_shutdown(); |
3639 | return; | 3651 | return; |
3640 | } | 3652 | } |
3641 | if (1 != inet_pton (AF_INET6, addr_str, &address6)) | 3653 | if (1 != inet_pton(AF_INET6, addr_str, &address6)) |
3642 | { | 3654 | { |
3643 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3655 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3644 | "Unable to parse IPv6 address %s\n", | 3656 | "Unable to parse IPv6 address %s\n", |
3645 | addr_str); | 3657 | addr_str); |
3646 | GNUNET_free (addr_str); | 3658 | GNUNET_free(addr_str); |
3647 | GNUNET_SCHEDULER_shutdown (); | 3659 | GNUNET_SCHEDULER_shutdown(); |
3648 | return; | 3660 | return; |
3649 | } | 3661 | } |
3650 | GNUNET_free (addr_str); | 3662 | GNUNET_free(addr_str); |
3651 | 3663 | ||
3652 | if (NULL == (curl_multi = curl_multi_init ())) | 3664 | if (NULL == (curl_multi = curl_multi_init())) |
3653 | { | 3665 | { |
3654 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3666 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3655 | "Failed to create cURL multi handle!\n"); | 3667 | "Failed to create cURL multi handle!\n"); |
3656 | return; | 3668 | return; |
3657 | } | 3669 | } |
3658 | cafile = cafile_opt; | 3670 | cafile = cafile_opt; |
3659 | if (NULL == cafile) | 3671 | if (NULL == cafile) |
3660 | { | 3672 | { |
3661 | if (GNUNET_OK != | 3673 | if (GNUNET_OK != |
3662 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 3674 | GNUNET_CONFIGURATION_get_value_filename(cfg, |
3663 | "gns-proxy", | 3675 | "gns-proxy", |
3664 | "PROXY_CACERT", | 3676 | "PROXY_CACERT", |
3665 | &cafile_cfg)) | 3677 | &cafile_cfg)) |
3666 | { | 3678 | { |
3667 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 3679 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
3668 | "gns-proxy", | 3680 | "gns-proxy", |
3669 | "PROXY_CACERT"); | 3681 | "PROXY_CACERT"); |
3682 | return; | ||
3683 | } | ||
3684 | cafile = cafile_cfg; | ||
3685 | } | ||
3686 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
3687 | "Using `%s' as CA\n", | ||
3688 | cafile); | ||
3689 | |||
3690 | gnutls_global_init(); | ||
3691 | gnutls_x509_crt_init(&proxy_ca.cert); | ||
3692 | gnutls_x509_privkey_init(&proxy_ca.key); | ||
3693 | |||
3694 | if ((GNUNET_OK != | ||
3695 | load_cert_from_file(proxy_ca.cert, | ||
3696 | cafile)) || | ||
3697 | (GNUNET_OK != | ||
3698 | load_key_from_file(proxy_ca.key, | ||
3699 | cafile))) | ||
3700 | { | ||
3701 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
3702 | _("Failed to load X.509 key and certificate from `%s'\n"), | ||
3703 | cafile); | ||
3704 | gnutls_x509_crt_deinit(proxy_ca.cert); | ||
3705 | gnutls_x509_privkey_deinit(proxy_ca.key); | ||
3706 | gnutls_global_deinit(); | ||
3707 | GNUNET_free_non_null(cafile_cfg); | ||
3670 | return; | 3708 | return; |
3671 | } | 3709 | } |
3672 | cafile = cafile_cfg; | 3710 | GNUNET_free_non_null(cafile_cfg); |
3673 | } | 3711 | if (NULL == (gns_handle = GNUNET_GNS_connect(cfg))) |
3674 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3712 | { |
3675 | "Using `%s' as CA\n", | 3713 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3676 | cafile); | 3714 | "Unable to connect to GNS!\n"); |
3677 | 3715 | gnutls_x509_crt_deinit(proxy_ca.cert); | |
3678 | gnutls_global_init (); | 3716 | gnutls_x509_privkey_deinit(proxy_ca.key); |
3679 | gnutls_x509_crt_init (&proxy_ca.cert); | 3717 | gnutls_global_deinit(); |
3680 | gnutls_x509_privkey_init (&proxy_ca.key); | 3718 | return; |
3681 | 3719 | } | |
3682 | if ( (GNUNET_OK != | 3720 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
3683 | load_cert_from_file (proxy_ca.cert, | 3721 | NULL); |
3684 | cafile)) || | ||
3685 | (GNUNET_OK != | ||
3686 | load_key_from_file (proxy_ca.key, | ||
3687 | cafile)) ) | ||
3688 | { | ||
3689 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
3690 | _("Failed to load X.509 key and certificate from `%s'\n"), | ||
3691 | cafile); | ||
3692 | gnutls_x509_crt_deinit (proxy_ca.cert); | ||
3693 | gnutls_x509_privkey_deinit (proxy_ca.key); | ||
3694 | gnutls_global_deinit (); | ||
3695 | GNUNET_free_non_null (cafile_cfg); | ||
3696 | return; | ||
3697 | } | ||
3698 | GNUNET_free_non_null (cafile_cfg); | ||
3699 | if (NULL == (gns_handle = GNUNET_GNS_connect (cfg))) | ||
3700 | { | ||
3701 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
3702 | "Unable to connect to GNS!\n"); | ||
3703 | gnutls_x509_crt_deinit (proxy_ca.cert); | ||
3704 | gnutls_x509_privkey_deinit (proxy_ca.key); | ||
3705 | gnutls_global_deinit (); | ||
3706 | return; | ||
3707 | } | ||
3708 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
3709 | NULL); | ||
3710 | 3722 | ||
3711 | /* Open listen socket for socks proxy */ | 3723 | /* Open listen socket for socks proxy */ |
3712 | lsock6 = bind_v6 (); | 3724 | lsock6 = bind_v6(); |
3713 | if (NULL == lsock6) | 3725 | if (NULL == lsock6) |
3714 | { | ||
3715 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
3716 | "bind"); | ||
3717 | } | ||
3718 | else | ||
3719 | { | ||
3720 | if (GNUNET_OK != | ||
3721 | GNUNET_NETWORK_socket_listen (lsock6, | ||
3722 | 5)) | ||
3723 | { | 3726 | { |
3724 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 3727 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, |
3725 | "listen"); | 3728 | "bind"); |
3726 | GNUNET_NETWORK_socket_close (lsock6); | ||
3727 | lsock6 = NULL; | ||
3728 | } | 3729 | } |
3729 | else | 3730 | else |
3730 | { | 3731 | { |
3731 | ltask6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3732 | if (GNUNET_OK != |
3732 | lsock6, | 3733 | GNUNET_NETWORK_socket_listen(lsock6, |
3733 | &do_accept, | 3734 | 5)) |
3734 | lsock6); | 3735 | { |
3736 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, | ||
3737 | "listen"); | ||
3738 | GNUNET_NETWORK_socket_close(lsock6); | ||
3739 | lsock6 = NULL; | ||
3740 | } | ||
3741 | else | ||
3742 | { | ||
3743 | ltask6 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, | ||
3744 | lsock6, | ||
3745 | &do_accept, | ||
3746 | lsock6); | ||
3747 | } | ||
3735 | } | 3748 | } |
3736 | } | 3749 | lsock4 = bind_v4(); |
3737 | lsock4 = bind_v4 (); | ||
3738 | if (NULL == lsock4) | 3750 | if (NULL == lsock4) |
3739 | { | 3751 | { |
3740 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 3752 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, |
3741 | "bind"); | 3753 | "bind"); |
3742 | } | 3754 | } |
3743 | else | 3755 | else |
3744 | { | ||
3745 | if (GNUNET_OK != | ||
3746 | GNUNET_NETWORK_socket_listen (lsock4, | ||
3747 | 5)) | ||
3748 | { | 3756 | { |
3749 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 3757 | if (GNUNET_OK != |
3750 | "listen"); | 3758 | GNUNET_NETWORK_socket_listen(lsock4, |
3751 | GNUNET_NETWORK_socket_close (lsock4); | 3759 | 5)) |
3752 | lsock4 = NULL; | 3760 | { |
3761 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, | ||
3762 | "listen"); | ||
3763 | GNUNET_NETWORK_socket_close(lsock4); | ||
3764 | lsock4 = NULL; | ||
3765 | } | ||
3766 | else | ||
3767 | { | ||
3768 | ltask4 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, | ||
3769 | lsock4, | ||
3770 | &do_accept, | ||
3771 | lsock4); | ||
3772 | } | ||
3753 | } | 3773 | } |
3754 | else | 3774 | if ((NULL == lsock4) && |
3775 | (NULL == lsock6)) | ||
3755 | { | 3776 | { |
3756 | ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3777 | GNUNET_SCHEDULER_shutdown(); |
3757 | lsock4, | 3778 | return; |
3758 | &do_accept, | ||
3759 | lsock4); | ||
3760 | } | 3779 | } |
3761 | } | 3780 | if (0 != curl_global_init(CURL_GLOBAL_WIN32)) |
3762 | if ( (NULL == lsock4) && | 3781 | { |
3763 | (NULL == lsock6) ) | 3782 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3764 | { | 3783 | "cURL global init failed!\n"); |
3765 | GNUNET_SCHEDULER_shutdown (); | 3784 | GNUNET_SCHEDULER_shutdown(); |
3766 | return; | 3785 | return; |
3767 | } | 3786 | } |
3768 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 3787 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3769 | { | 3788 | "Proxy listens on port %u\n", |
3770 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3789 | (unsigned int)port); |
3771 | "cURL global init failed!\n"); | ||
3772 | GNUNET_SCHEDULER_shutdown (); | ||
3773 | return; | ||
3774 | } | ||
3775 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3776 | "Proxy listens on port %u\n", | ||
3777 | (unsigned int) port); | ||
3778 | 3790 | ||
3779 | /* start MHD daemon for HTTP */ | 3791 | /* start MHD daemon for HTTP */ |
3780 | hd = GNUNET_new (struct MhdHttpList); | 3792 | hd = GNUNET_new(struct MhdHttpList); |
3781 | hd->daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_NO_LISTEN_SOCKET | MHD_ALLOW_SUSPEND_RESUME, | 3793 | hd->daemon = MHD_start_daemon(MHD_USE_DEBUG | MHD_USE_NO_LISTEN_SOCKET | MHD_ALLOW_SUSPEND_RESUME, |
3782 | 0, | 3794 | 0, |
3783 | NULL, NULL, | 3795 | NULL, NULL, |
3784 | &create_response, hd, | 3796 | &create_response, hd, |
3785 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, | 3797 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int)16, |
3786 | MHD_OPTION_NOTIFY_COMPLETED, &mhd_completed_cb, NULL, | 3798 | MHD_OPTION_NOTIFY_COMPLETED, &mhd_completed_cb, NULL, |
3787 | MHD_OPTION_NOTIFY_CONNECTION, &mhd_connection_cb, NULL, | 3799 | MHD_OPTION_NOTIFY_CONNECTION, &mhd_connection_cb, NULL, |
3788 | MHD_OPTION_URI_LOG_CALLBACK, &mhd_log_callback, NULL, | 3800 | MHD_OPTION_URI_LOG_CALLBACK, &mhd_log_callback, NULL, |
3789 | MHD_OPTION_END); | 3801 | MHD_OPTION_END); |
3790 | if (NULL == hd->daemon) | 3802 | if (NULL == hd->daemon) |
3791 | { | 3803 | { |
3792 | GNUNET_free (hd); | 3804 | GNUNET_free(hd); |
3793 | GNUNET_SCHEDULER_shutdown (); | 3805 | GNUNET_SCHEDULER_shutdown(); |
3794 | return; | 3806 | return; |
3795 | } | 3807 | } |
3796 | httpd = hd; | 3808 | httpd = hd; |
3797 | GNUNET_CONTAINER_DLL_insert (mhd_httpd_head, | 3809 | GNUNET_CONTAINER_DLL_insert(mhd_httpd_head, |
3798 | mhd_httpd_tail, | 3810 | mhd_httpd_tail, |
3799 | hd); | 3811 | hd); |
3800 | } | 3812 | } |
3801 | 3813 | ||
3802 | 3814 | ||
@@ -3808,24 +3820,24 @@ run (void *cls, | |||
3808 | * @return 0 ok, 1 on error | 3820 | * @return 0 ok, 1 on error |
3809 | */ | 3821 | */ |
3810 | int | 3822 | int |
3811 | main (int argc, | 3823 | main(int argc, |
3812 | char *const *argv) | 3824 | char *const *argv) |
3813 | { | 3825 | { |
3814 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 3826 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
3815 | GNUNET_GETOPT_option_uint16 ('p', | 3827 | GNUNET_GETOPT_option_uint16('p', |
3816 | "port", | 3828 | "port", |
3817 | NULL, | 3829 | NULL, |
3818 | gettext_noop ("listen on specified port (default: 7777)"), | 3830 | gettext_noop("listen on specified port (default: 7777)"), |
3819 | &port), | 3831 | &port), |
3820 | GNUNET_GETOPT_option_string ('a', | 3832 | GNUNET_GETOPT_option_string('a', |
3821 | "authority", | 3833 | "authority", |
3822 | NULL, | 3834 | NULL, |
3823 | gettext_noop ("pem file to use as CA"), | 3835 | gettext_noop("pem file to use as CA"), |
3824 | &cafile_opt), | 3836 | &cafile_opt), |
3825 | GNUNET_GETOPT_option_flag ('6', | 3837 | GNUNET_GETOPT_option_flag('6', |
3826 | "disable-ivp6", | 3838 | "disable-ivp6", |
3827 | gettext_noop ("disable use of IPv6"), | 3839 | gettext_noop("disable use of IPv6"), |
3828 | &disable_v6), | 3840 | &disable_v6), |
3829 | 3841 | ||
3830 | GNUNET_GETOPT_OPTION_END | 3842 | GNUNET_GETOPT_OPTION_END |
3831 | }; | 3843 | }; |
@@ -3835,26 +3847,26 @@ main (int argc, | |||
3835 | int ret; | 3847 | int ret; |
3836 | 3848 | ||
3837 | if (GNUNET_OK != | 3849 | if (GNUNET_OK != |
3838 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 3850 | GNUNET_STRINGS_get_utf8_args(argc, argv, |
3839 | &argc, &argv)) | 3851 | &argc, &argv)) |
3840 | return 2; | 3852 | return 2; |
3841 | GNUNET_log_setup ("gnunet-gns-proxy", | 3853 | GNUNET_log_setup("gnunet-gns-proxy", |
3842 | "WARNING", | 3854 | "WARNING", |
3843 | NULL); | 3855 | NULL); |
3844 | curl_failure_response | 3856 | curl_failure_response |
3845 | = MHD_create_response_from_buffer (strlen (page), | 3857 | = MHD_create_response_from_buffer(strlen(page), |
3846 | (void *) page, | 3858 | (void *)page, |
3847 | MHD_RESPMEM_PERSISTENT); | 3859 | MHD_RESPMEM_PERSISTENT); |
3848 | 3860 | ||
3849 | ret = | 3861 | ret = |
3850 | (GNUNET_OK == | 3862 | (GNUNET_OK == |
3851 | GNUNET_PROGRAM_run (argc, argv, | 3863 | GNUNET_PROGRAM_run(argc, argv, |
3852 | "gnunet-gns-proxy", | 3864 | "gnunet-gns-proxy", |
3853 | _("GNUnet GNS proxy"), | 3865 | _("GNUnet GNS proxy"), |
3854 | options, | 3866 | options, |
3855 | &run, NULL)) ? 0 : 1; | 3867 | &run, NULL)) ? 0 : 1; |
3856 | MHD_destroy_response (curl_failure_response); | 3868 | MHD_destroy_response(curl_failure_response); |
3857 | GNUNET_free_non_null ((char *) argv); | 3869 | GNUNET_free_non_null((char *)argv); |
3858 | return ret; | 3870 | return ret; |
3859 | } | 3871 | } |
3860 | 3872 | ||