diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-09-20 12:13:43 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-09-20 12:13:43 +0000 |
commit | 1dc6fd8caf5b64a46bcb0616686779232ed80230 (patch) | |
tree | 405695d155cf345bf0a4b1f03d7efd5715d7cfb5 | |
parent | 0d69b14df5a0d6ac92829d110b5019d3b30d7c93 (diff) | |
download | gnunet-1dc6fd8caf5b64a46bcb0616686779232ed80230.tar.gz gnunet-1dc6fd8caf5b64a46bcb0616686779232ed80230.zip |
-code review
-rw-r--r-- | src/gns/gnunet-gns-proxy.c | 274 |
1 files changed, 128 insertions, 146 deletions
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c index 23427d3f1..2017018c3 100644 --- a/src/gns/gnunet-gns-proxy.c +++ b/src/gns/gnunet-gns-proxy.c | |||
@@ -38,9 +38,13 @@ | |||
38 | #define POSTBUFFERSIZE 4096 | 38 | #define POSTBUFFERSIZE 4096 |
39 | 39 | ||
40 | /* MHD/cURL defines */ | 40 | /* MHD/cURL defines */ |
41 | #define BUF_WAIT_FOR_CURL 0 | 41 | enum BufferStatus |
42 | #define BUF_WAIT_FOR_MHD 1 | 42 | { |
43 | #define BUF_WAIT_FOR_PP 2 | 43 | BUF_WAIT_FOR_CURL, |
44 | BUF_WAIT_FOR_MHD, | ||
45 | BUF_WAIT_FOR_PP | ||
46 | }; | ||
47 | |||
44 | #define HTML_HDR_CONTENT "Content-Type: text/html" | 48 | #define HTML_HDR_CONTENT "Content-Type: text/html" |
45 | 49 | ||
46 | /* buffer padding for proper RE matching */ | 50 | /* buffer padding for proper RE matching */ |
@@ -187,15 +191,9 @@ struct ProxyCurlTask | |||
187 | /* DLL for tasks */ | 191 | /* DLL for tasks */ |
188 | struct ProxyCurlTask *next; | 192 | struct ProxyCurlTask *next; |
189 | 193 | ||
190 | /* Already accepted */ | ||
191 | int accepted; | ||
192 | |||
193 | /* Handle to cURL */ | 194 | /* Handle to cURL */ |
194 | CURL *curl; | 195 | CURL *curl; |
195 | 196 | ||
196 | /* is curl running? */ | ||
197 | int curl_running; | ||
198 | |||
199 | /* Optional header replacements for curl (LEHO) */ | 197 | /* Optional header replacements for curl (LEHO) */ |
200 | struct curl_slist *headers; | 198 | struct curl_slist *headers; |
201 | 199 | ||
@@ -217,29 +215,29 @@ struct ProxyCurlTask | |||
217 | /* Write pos in the buffer */ | 215 | /* Write pos in the buffer */ |
218 | char *buffer_write_ptr; | 216 | char *buffer_write_ptr; |
219 | 217 | ||
220 | /* The buffer status (BUF_WAIT_FOR_CURL or BUF_WAIT_FOR_MHD) */ | 218 | /* connection */ |
221 | int buf_status; | 219 | struct MHD_Connection *connection; |
222 | 220 | ||
223 | /* Number of bytes in buffer */ | 221 | /*put*/ |
224 | unsigned int bytes_in_buffer; | 222 | size_t put_read_offset; |
223 | size_t put_read_size; | ||
225 | 224 | ||
226 | /* Indicates wheather the download is in progress */ | 225 | /*post*/ |
227 | int download_in_progress; | 226 | struct MHD_PostProcessor *post_handler; |
228 | 227 | ||
229 | /* Indicates wheather the download was successful */ | 228 | /* post data */ |
230 | int download_is_finished; | 229 | struct ProxyUploadData *upload_data_head; |
230 | struct ProxyUploadData *upload_data_tail; | ||
231 | 231 | ||
232 | /* Indicates wheather the download failed */ | 232 | /* the type of POST encoding */ |
233 | int download_error; | 233 | char* post_type; |
234 | 234 | ||
235 | /* Indicates wheather we need to parse HTML */ | 235 | struct curl_httppost *httppost; |
236 | int parse_content; | ||
237 | 236 | ||
238 | /* Indicates wheather we are postprocessing the HTML right now */ | 237 | struct curl_httppost *httppost_last; |
239 | int is_postprocessing; | ||
240 | 238 | ||
241 | /* Indicates wheather postprocessing has finished */ | 239 | /* Number of bytes in buffer */ |
242 | int pp_finished; | 240 | unsigned int bytes_in_buffer; |
243 | 241 | ||
244 | /* PP task */ | 242 | /* PP task */ |
245 | GNUNET_SCHEDULER_TaskIdentifier pp_task; | 243 | GNUNET_SCHEDULER_TaskIdentifier pp_task; |
@@ -250,18 +248,6 @@ struct ProxyCurlTask | |||
250 | /* PP match list */ | 248 | /* PP match list */ |
251 | struct ProxyREMatch *pp_match_tail; | 249 | struct ProxyREMatch *pp_match_tail; |
252 | 250 | ||
253 | /* The authority of the corresponding host (site of origin) */ | ||
254 | char authority[256]; | ||
255 | |||
256 | /* The hostname (Host header field) */ | ||
257 | char host[256]; | ||
258 | |||
259 | /* The port */ | ||
260 | uint16_t port; | ||
261 | |||
262 | /* The LEgacy HOstname (can be empty) */ | ||
263 | char leho[256]; | ||
264 | |||
265 | /* The associated daemon list entry */ | 251 | /* The associated daemon list entry */ |
266 | struct MhdHttpList *mhd; | 252 | struct MhdHttpList *mhd; |
267 | 253 | ||
@@ -274,34 +260,52 @@ struct ProxyCurlTask | |||
274 | /* Cookies to set */ | 260 | /* Cookies to set */ |
275 | struct ProxySetCookieHeader *set_cookies_tail; | 261 | struct ProxySetCookieHeader *set_cookies_tail; |
276 | 262 | ||
263 | /* The authority of the corresponding host (site of origin) */ | ||
264 | char authority[256]; | ||
265 | |||
266 | /* The hostname (Host header field) */ | ||
267 | char host[256]; | ||
268 | |||
269 | /* The LEgacy HOstname (can be empty) */ | ||
270 | char leho[256]; | ||
271 | |||
272 | /* The port */ | ||
273 | uint16_t port; | ||
274 | |||
275 | /* The buffer status (BUF_WAIT_FOR_CURL or BUF_WAIT_FOR_MHD) */ | ||
276 | enum BufferStatus buf_status; | ||
277 | |||
277 | /* connection status */ | 278 | /* connection status */ |
278 | int ready_to_queue; | 279 | int ready_to_queue; |
280 | |||
281 | /* is curl running? */ | ||
282 | int curl_running; | ||
279 | 283 | ||
280 | /* are we done */ | 284 | /* are we done */ |
281 | int fin; | 285 | int fin; |
282 | 286 | ||
283 | /* connection */ | 287 | /* Already accepted */ |
284 | struct MHD_Connection *connection; | 288 | int accepted; |
285 | 289 | ||
286 | /*put*/ | 290 | /* Indicates wheather the download is in progress */ |
287 | size_t put_read_offset; | 291 | int download_in_progress; |
288 | size_t put_read_size; | ||
289 | 292 | ||
290 | /*post*/ | 293 | /* Indicates wheather the download was successful */ |
291 | struct MHD_PostProcessor *post_handler; | 294 | int download_is_finished; |
292 | 295 | ||
293 | /* post data */ | 296 | /* Indicates wheather the download failed */ |
294 | struct ProxyUploadData *upload_data_head; | 297 | int download_error; |
295 | struct ProxyUploadData *upload_data_tail; | ||
296 | 298 | ||
297 | int post_done; | 299 | /* Indicates wheather we need to parse HTML */ |
300 | int parse_content; | ||
298 | 301 | ||
299 | /* the type of POST encoding */ | 302 | /* Indicates wheather we are postprocessing the HTML right now */ |
300 | char* post_type; | 303 | int is_postprocessing; |
301 | 304 | ||
302 | struct curl_httppost *httppost; | 305 | /* Indicates wheather postprocessing has finished */ |
306 | int pp_finished; | ||
303 | 307 | ||
304 | struct curl_httppost *httppost_last; | 308 | int post_done; |
305 | 309 | ||
306 | int is_httppost; | 310 | int is_httppost; |
307 | 311 | ||
@@ -318,8 +322,14 @@ struct ProxyREMatch | |||
318 | /* DLL */ | 322 | /* DLL */ |
319 | struct ProxyREMatch *prev; | 323 | struct ProxyREMatch *prev; |
320 | 324 | ||
321 | /* is SSL */ | 325 | /* start of match in buffer */ |
322 | int is_ssl; | 326 | char* start; |
327 | |||
328 | /* end of match in buffer */ | ||
329 | char* end; | ||
330 | |||
331 | /* associated proxycurltask */ | ||
332 | struct ProxyCurlTask *ctask; | ||
323 | 333 | ||
324 | /* hostname found */ | 334 | /* hostname found */ |
325 | char hostname[255]; | 335 | char hostname[255]; |
@@ -333,14 +343,9 @@ struct ProxyREMatch | |||
333 | /* are we done */ | 343 | /* are we done */ |
334 | int done; | 344 | int done; |
335 | 345 | ||
336 | /* start of match in buffer */ | 346 | /* is SSL */ |
337 | char* start; | 347 | int is_ssl; |
338 | |||
339 | /* end of match in buffer */ | ||
340 | char* end; | ||
341 | 348 | ||
342 | /* associated proxycurltask */ | ||
343 | struct ProxyCurlTask *ctask; | ||
344 | }; | 349 | }; |
345 | 350 | ||
346 | /** | 351 | /** |
@@ -398,10 +403,10 @@ static char* cafile_opt; | |||
398 | static struct GNUNET_NETWORK_Handle *lsock; | 403 | static struct GNUNET_NETWORK_Handle *lsock; |
399 | 404 | ||
400 | /* The listen task ID */ | 405 | /* The listen task ID */ |
401 | GNUNET_SCHEDULER_TaskIdentifier ltask; | 406 | static GNUNET_SCHEDULER_TaskIdentifier ltask; |
402 | 407 | ||
403 | /* The cURL download task */ | 408 | /* The cURL download task */ |
404 | GNUNET_SCHEDULER_TaskIdentifier curl_download_task; | 409 | static GNUNET_SCHEDULER_TaskIdentifier curl_download_task; |
405 | 410 | ||
406 | /* The non SSL httpd daemon handle */ | 411 | /* The non SSL httpd daemon handle */ |
407 | static struct MHD_Daemon *httpd; | 412 | static struct MHD_Daemon *httpd; |
@@ -443,51 +448,54 @@ static struct GNUNET_CRYPTO_ShortHashCode *local_shorten_zone; | |||
443 | static struct ProxyCA proxy_ca; | 448 | static struct ProxyCA proxy_ca; |
444 | 449 | ||
445 | /* UNIX domain socket for mhd */ | 450 | /* UNIX domain socket for mhd */ |
446 | struct GNUNET_NETWORK_Handle *mhd_unix_socket; | 451 | #if !HAVE_MHD_NO_LISTEN_SOCKET |
452 | static struct GNUNET_NETWORK_Handle *mhd_unix_socket; | ||
453 | #endif | ||
447 | 454 | ||
448 | /* Shorten zone private key */ | 455 | /* Shorten zone private key */ |
449 | struct GNUNET_CRYPTO_RsaPrivateKey *shorten_zonekey; | 456 | static struct GNUNET_CRYPTO_RsaPrivateKey *shorten_zonekey; |
457 | |||
450 | 458 | ||
451 | /** | 459 | /** |
452 | * Checks if name is in tld | 460 | * Checks if name is in tld |
453 | * | 461 | * |
454 | * @param name the name to check | 462 | * @param name the name to check |
455 | * @param tld the TLD to check for | 463 | * @param tld the TLD to check for (must NOT begin with ".") |
456 | * @return GNUNET_YES or GNUNET_NO | 464 | * @return GNUNET_YES or GNUNET_NO |
457 | */ | 465 | */ |
458 | int | 466 | static int |
459 | is_tld(const char* name, const char* tld) | 467 | is_tld (const char* name, const char* tld) |
460 | { | 468 | { |
461 | size_t offset; | 469 | size_t name_len = strlen (name); |
462 | 470 | size_t tld_len = strlen (tld); | |
463 | if (strlen(name) <= strlen(tld)) | 471 | |
464 | return GNUNET_NO; | 472 | GNUNET_break ('.' != tld[0]); |
465 | 473 | return ( (tld_len < name_len) && | |
466 | offset = strlen(name) - strlen(tld); | 474 | ( ('.' == name[name_len - tld_len - 1]) || (name_len == tld_len) ) && |
467 | if (0 != strcmp (name+offset, tld)) | 475 | (0 == memcmp (tld, |
468 | { | 476 | name + (name_len - tld_len), |
469 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 477 | tld_len)) ); |
470 | "%s is not in .%s TLD\n", name, tld); | ||
471 | return GNUNET_NO; | ||
472 | } | ||
473 | |||
474 | return GNUNET_YES; | ||
475 | } | 478 | } |
476 | 479 | ||
480 | |||
477 | /** | 481 | /** |
478 | * convert integer to string representation | 482 | * convert integer to string representation |
479 | * | 483 | * |
480 | * @param i integer | 484 | * @param i integer |
481 | * @return the character | 485 | * @return the character |
482 | */ | 486 | */ |
483 | char i_to_hexchar (char i) | 487 | static char |
488 | i_to_hexchar (unsigned char i) | ||
484 | { | 489 | { |
485 | static char hexmap[] = "0123456789abcdef"; | 490 | static char hexmap[] = "0123456789abcdef"; |
491 | |||
486 | GNUNET_assert (sizeof (hexmap) > (i & 15)); | 492 | GNUNET_assert (sizeof (hexmap) > (i & 15)); |
487 | return hexmap[i & 15]; | 493 | return hexmap[i & 15]; |
488 | } | 494 | } |
489 | 495 | ||
496 | |||
490 | /** | 497 | /** |
498 | // FIXME: use cURL API | ||
491 | * Escape given 0-terminated string | 499 | * Escape given 0-terminated string |
492 | * | 500 | * |
493 | * @param to_esc string to escapse | 501 | * @param to_esc string to escapse |
@@ -520,6 +528,7 @@ escape_to_urlenc (const char *to_esc) | |||
520 | return res; | 528 | return res; |
521 | } | 529 | } |
522 | 530 | ||
531 | |||
523 | static int | 532 | static int |
524 | con_post_data_iter (void *cls, | 533 | con_post_data_iter (void *cls, |
525 | enum MHD_ValueKind kind, | 534 | enum MHD_ValueKind kind, |
@@ -537,9 +546,11 @@ con_post_data_iter (void *cls, | |||
537 | char* new_value; | 546 | char* new_value; |
538 | 547 | ||
539 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 548 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
540 | "Got POST data: '%s : %s' at offset %llu size %lld\n", | 549 | "Got POST data (file: %s, content type: %s): '%s=%.*s' at offset %llu size %llu\n", |
541 | key, data, off, size); | 550 | filename, content_type, |
542 | 551 | key, (int) size, data, | |
552 | (unsigned long long) off, | ||
553 | (unsigned long long) size); | ||
543 | GNUNET_assert (NULL != ctask->post_type); | 554 | GNUNET_assert (NULL != ctask->post_type); |
544 | 555 | ||
545 | if (0 == strcasecmp (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, | 556 | if (0 == strcasecmp (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, |
@@ -550,25 +561,12 @@ con_post_data_iter (void *cls, | |||
550 | if (0 == off) | 561 | if (0 == off) |
551 | { | 562 | { |
552 | pdata = GNUNET_malloc (sizeof (struct ProxyUploadData)); | 563 | pdata = GNUNET_malloc (sizeof (struct ProxyUploadData)); |
553 | pdata->key = strdup (key); | 564 | pdata->key = GNUNET_strdup (key); |
554 | |||
555 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
556 | "Copied %lld\n"); | ||
557 | 565 | ||
558 | if (NULL != filename) | 566 | if (NULL != filename) |
559 | { | 567 | pdata->filename = GNUNET_strdup (filename); |
560 | pdata->filename = strdup (filename); | ||
561 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
562 | "Filename %s\n", filename); | ||
563 | } | ||
564 | |||
565 | if (NULL != content_type) | 568 | if (NULL != content_type) |
566 | { | 569 | pdata->content_type = GNUNET_strdup (content_type); |
567 | pdata->content_type = strdup (content_type); | ||
568 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
569 | "Content-Type %s\n", content_type); | ||
570 | } | ||
571 | |||
572 | pdata->value = GNUNET_malloc (size); | 570 | pdata->value = GNUNET_malloc (size); |
573 | pdata->total_bytes = size; | 571 | pdata->total_bytes = size; |
574 | memcpy (pdata->value, data, size); | 572 | memcpy (pdata->value, data, size); |
@@ -577,7 +575,8 @@ con_post_data_iter (void *cls, | |||
577 | pdata); | 575 | pdata); |
578 | 576 | ||
579 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 577 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
580 | "Copied %lld bytes of POST Data\n", size); | 578 | "Copied %llu bytes of POST Data\n", |
579 | (unsigned long long) size); | ||
581 | return MHD_YES; | 580 | return MHD_YES; |
582 | } | 581 | } |
583 | 582 | ||
@@ -590,7 +589,6 @@ con_post_data_iter (void *cls, | |||
590 | pdata->total_bytes += size; | 589 | pdata->total_bytes += size; |
591 | 590 | ||
592 | return MHD_YES; | 591 | return MHD_YES; |
593 | |||
594 | } | 592 | } |
595 | 593 | ||
596 | if (0 != strcasecmp (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, | 594 | if (0 != strcasecmp (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, |
@@ -675,7 +673,7 @@ con_val_iter (void *cls, | |||
675 | 673 | ||
676 | if (0 == strcmp ("Host", key)) | 674 | if (0 == strcmp ("Host", key)) |
677 | { | 675 | { |
678 | port = strstr (value, ":"); | 676 | port = strchr (value, ':'); |
679 | if (NULL != port) | 677 | if (NULL != port) |
680 | { | 678 | { |
681 | strncpy (buf, value, port-value); | 679 | strncpy (buf, value, port-value); |
@@ -693,7 +691,7 @@ con_val_iter (void *cls, | |||
693 | return MHD_YES; | 691 | return MHD_YES; |
694 | } | 692 | } |
695 | 693 | ||
696 | if (0 == strcmp ("Accept-Encoding", key)) | 694 | if (0 == strcmp (MHD_HTTP_HEADER_ACCEPT_ENCODING, key)) |
697 | hdr_val = ""; | 695 | hdr_val = ""; |
698 | else | 696 | else |
699 | hdr_val = value; | 697 | hdr_val = value; |
@@ -1012,7 +1010,7 @@ run_mhd_now (struct MhdHttpList *hd) | |||
1012 | * Ask cURL for the select sets and schedule download | 1010 | * Ask cURL for the select sets and schedule download |
1013 | */ | 1011 | */ |
1014 | static void | 1012 | static void |
1015 | curl_download_prepare (); | 1013 | curl_download_prepare (void); |
1016 | 1014 | ||
1017 | /** | 1015 | /** |
1018 | * Callback to free content | 1016 | * Callback to free content |
@@ -1085,8 +1083,7 @@ mhd_content_cb (void *cls, | |||
1085 | 1083 | ||
1086 | if ((GNUNET_YES == ctask->download_is_finished) && | 1084 | if ((GNUNET_YES == ctask->download_is_finished) && |
1087 | (GNUNET_NO == ctask->download_error) && | 1085 | (GNUNET_NO == ctask->download_error) && |
1088 | (0 == bytes_to_copy)) /* && | 1086 | (0 == bytes_to_copy)) |
1089 | (BUF_WAIT_FOR_CURL == ctask->buf_status))*/ | ||
1090 | { | 1087 | { |
1091 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1088 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1092 | "MHD: sending response for %s\n", ctask->url); | 1089 | "MHD: sending response for %s\n", ctask->url); |
@@ -1099,8 +1096,7 @@ mhd_content_cb (void *cls, | |||
1099 | 1096 | ||
1100 | if ((GNUNET_YES == ctask->download_error) && | 1097 | if ((GNUNET_YES == ctask->download_error) && |
1101 | (GNUNET_YES == ctask->download_is_finished) && | 1098 | (GNUNET_YES == ctask->download_is_finished) && |
1102 | (0 == bytes_to_copy)) /* && | 1099 | (0 == bytes_to_copy)) |
1103 | (BUF_WAIT_FOR_CURL == ctask->buf_status))*/ | ||
1104 | { | 1100 | { |
1105 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1101 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1106 | "MHD: sending error response\n"); | 1102 | "MHD: sending error response\n"); |
@@ -1134,7 +1130,7 @@ mhd_content_cb (void *cls, | |||
1134 | ctask->buffer_read_ptr += max-copied; | 1130 | ctask->buffer_read_ptr += max-copied; |
1135 | copied = max; | 1131 | copied = max; |
1136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1137 | "MHD: copied %d bytes\n", copied); | 1133 | "MHD: copied %d bytes\n", (int) copied); |
1138 | return copied; | 1134 | return copied; |
1139 | } | 1135 | } |
1140 | 1136 | ||
@@ -1149,7 +1145,7 @@ mhd_content_cb (void *cls, | |||
1149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1150 | "MHD: Waiting for PP of %s\n", re_match->hostname); | 1146 | "MHD: Waiting for PP of %s\n", re_match->hostname); |
1151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1147 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1152 | "MHD: copied %d bytes\n", copied); | 1148 | "MHD: copied %d bytes\n", (int) copied); |
1153 | ctask->buffer_read_ptr += bytes_to_copy; | 1149 | ctask->buffer_read_ptr += bytes_to_copy; |
1154 | return copied; | 1150 | return copied; |
1155 | } | 1151 | } |
@@ -1162,7 +1158,7 @@ mhd_content_cb (void *cls, | |||
1162 | re_match->result, | 1158 | re_match->result, |
1163 | ctask->url); | 1159 | ctask->url); |
1164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1165 | "MHD: copied %d bytes\n", copied); | 1161 | "MHD: copied %d bytes\n", (int) copied); |
1166 | ctask->buffer_read_ptr += bytes_to_copy; | 1162 | ctask->buffer_read_ptr += bytes_to_copy; |
1167 | return copied; | 1163 | return copied; |
1168 | } | 1164 | } |
@@ -1170,7 +1166,7 @@ mhd_content_cb (void *cls, | |||
1170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1166 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1171 | "MHD: Adding PP result %s to buffer\n", | 1167 | "MHD: Adding PP result %s to buffer\n", |
1172 | re_match->result); | 1168 | re_match->result); |
1173 | memcpy (buf+copied, re_match->result, strlen (re_match->result)); | 1169 | memcpy (buf + copied, re_match->result, strlen (re_match->result)); |
1174 | copied += strlen (re_match->result); | 1170 | copied += strlen (re_match->result); |
1175 | ctask->buffer_read_ptr = re_match->end; | 1171 | ctask->buffer_read_ptr = re_match->end; |
1176 | GNUNET_CONTAINER_DLL_remove (ctask->pp_match_head, | 1172 | GNUNET_CONTAINER_DLL_remove (ctask->pp_match_head, |
@@ -1184,7 +1180,7 @@ mhd_content_cb (void *cls, | |||
1184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1185 | "MHD: copied: %d left: %d, space left in buf: %d\n", | 1181 | "MHD: copied: %d left: %d, space left in buf: %d\n", |
1186 | copied, | 1182 | copied, |
1187 | bytes_to_copy, max-copied); | 1183 | bytes_to_copy, (int) (max - copied)); |
1188 | 1184 | ||
1189 | GNUNET_assert (0 <= bytes_to_copy); | 1185 | GNUNET_assert (0 <= bytes_to_copy); |
1190 | 1186 | ||
@@ -1198,7 +1194,7 @@ mhd_content_cb (void *cls, | |||
1198 | ctask->buffer[bytes_to_copy] = '\0'; | 1194 | ctask->buffer[bytes_to_copy] = '\0'; |
1199 | } | 1195 | } |
1200 | 1196 | ||
1201 | if (bytes_to_copy+copied > max) | 1197 | if (bytes_to_copy + copied > max) |
1202 | bytes_to_copy = max-copied; | 1198 | bytes_to_copy = max-copied; |
1203 | 1199 | ||
1204 | if (0 > bytes_to_copy) | 1200 | if (0 > bytes_to_copy) |
@@ -1213,7 +1209,7 @@ mhd_content_cb (void *cls, | |||
1213 | curl_easy_pause (ctask->curl, CURLPAUSE_CONT); | 1209 | curl_easy_pause (ctask->curl, CURLPAUSE_CONT); |
1214 | 1210 | ||
1215 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1216 | "MHD: copied %d bytes\n", copied); | 1212 | "MHD: copied %d bytes\n", (int) copied); |
1217 | run_mhd_now (ctask->mhd); | 1213 | run_mhd_now (ctask->mhd); |
1218 | return copied; | 1214 | return copied; |
1219 | } | 1215 | } |
@@ -1747,10 +1743,8 @@ curl_task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1747 | } | 1743 | } |
1748 | 1744 | ||
1749 | num_ctasks=0; | 1745 | num_ctasks=0; |
1750 | for (ctask=ctasks_head; NULL != ctask; ctask = ctask->next) | 1746 | for (ctask=ctasks_head; NULL != ctask; ctask = ctask->next) |
1751 | { | 1747 | num_ctasks++; |
1752 | num_ctasks++; | ||
1753 | } | ||
1754 | 1748 | ||
1755 | if (num_ctasks != running) | 1749 | if (num_ctasks != running) |
1756 | { | 1750 | { |
@@ -1913,10 +1907,10 @@ mhd_log_callback (void* cls, const char* url) | |||
1913 | 1907 | ||
1914 | ctask = GNUNET_malloc (sizeof (struct ProxyCurlTask)); | 1908 | ctask = GNUNET_malloc (sizeof (struct ProxyCurlTask)); |
1915 | strcpy (ctask->url, url); | 1909 | strcpy (ctask->url, url); |
1916 | ctask->accepted = GNUNET_NO; | ||
1917 | return ctask; | 1910 | return ctask; |
1918 | } | 1911 | } |
1919 | 1912 | ||
1913 | |||
1920 | /** | 1914 | /** |
1921 | * Main MHD callback for handling requests. | 1915 | * Main MHD callback for handling requests. |
1922 | * | 1916 | * |
@@ -1951,13 +1945,12 @@ create_response (void *cls, | |||
1951 | void **con_cls) | 1945 | void **con_cls) |
1952 | { | 1946 | { |
1953 | struct MhdHttpList* hd = cls; | 1947 | struct MhdHttpList* hd = cls; |
1954 | const char* page = "<html><head><title>gnoxy</title>"\ | 1948 | const char* page = "<html><head><title>gnunet-gns-proxy</title>"\ |
1955 | "</head><body>cURL fail</body></html>"; | 1949 | "</head><body>cURL fail</body></html>"; |
1956 | 1950 | ||
1957 | char curlurl[MAX_HTTP_URI_LENGTH]; // buffer overflow! | 1951 | char curlurl[MAX_HTTP_URI_LENGTH]; // buffer overflow! |
1958 | int ret = MHD_YES; | 1952 | int ret = MHD_YES; |
1959 | int i; | 1953 | int i; |
1960 | |||
1961 | struct ProxyCurlTask *ctask = *con_cls; | 1954 | struct ProxyCurlTask *ctask = *con_cls; |
1962 | struct ProxyUploadData *fin_post; | 1955 | struct ProxyUploadData *fin_post; |
1963 | struct curl_forms forms[5]; | 1956 | struct curl_forms forms[5]; |
@@ -2362,8 +2355,7 @@ cleanup_s5r (struct Socks5Request *s5r) | |||
2362 | if (GNUNET_SCHEDULER_NO_TASK != s5r->fwdwtask) | 2355 | if (GNUNET_SCHEDULER_NO_TASK != s5r->fwdwtask) |
2363 | GNUNET_SCHEDULER_cancel (s5r->fwdwtask); | 2356 | GNUNET_SCHEDULER_cancel (s5r->fwdwtask); |
2364 | if (GNUNET_SCHEDULER_NO_TASK != s5r->fwdrtask) | 2357 | if (GNUNET_SCHEDULER_NO_TASK != s5r->fwdrtask) |
2365 | GNUNET_SCHEDULER_cancel (s5r->fwdrtask); | 2358 | GNUNET_SCHEDULER_cancel (s5r->fwdrtask); |
2366 | |||
2367 | if (NULL != s5r->remote_sock) | 2359 | if (NULL != s5r->remote_sock) |
2368 | GNUNET_NETWORK_socket_close (s5r->remote_sock); | 2360 | GNUNET_NETWORK_socket_close (s5r->remote_sock); |
2369 | if ((NULL != s5r->sock) && (s5r->cleanup_sock == GNUNET_YES)) | 2361 | if ((NULL != s5r->sock) && (s5r->cleanup_sock == GNUNET_YES)) |
@@ -2494,13 +2486,13 @@ add_handle_to_mhd (struct GNUNET_NETWORK_Handle *h, struct MHD_Daemon *daemon) | |||
2494 | * | 2486 | * |
2495 | * @param filename file to read | 2487 | * @param filename file to read |
2496 | * @param size pointer where filesize is stored | 2488 | * @param size pointer where filesize is stored |
2497 | * @return data | 2489 | * @return NULL on error |
2498 | */ | 2490 | */ |
2499 | static char* | 2491 | static void* |
2500 | load_file (const char* filename, | 2492 | load_file (const char* filename, |
2501 | unsigned int* size) | 2493 | unsigned int* size) |
2502 | { | 2494 | { |
2503 | char *buffer; | 2495 | void *buffer; |
2504 | uint64_t fsize; | 2496 | uint64_t fsize; |
2505 | 2497 | ||
2506 | if (GNUNET_OK != | 2498 | if (GNUNET_OK != |
@@ -2533,7 +2525,7 @@ load_key_from_file (gnutls_x509_privkey_t key, const char* keyfile) | |||
2533 | gnutls_datum_t key_data; | 2525 | gnutls_datum_t key_data; |
2534 | int ret; | 2526 | int ret; |
2535 | 2527 | ||
2536 | key_data.data = (unsigned char*) load_file (keyfile, &key_data.size); | 2528 | key_data.data = load_file (keyfile, &key_data.size); |
2537 | ret = gnutls_x509_privkey_import (key, &key_data, | 2529 | ret = gnutls_x509_privkey_import (key, &key_data, |
2538 | GNUTLS_X509_FMT_PEM); | 2530 | GNUTLS_X509_FMT_PEM); |
2539 | if (GNUTLS_E_SUCCESS != ret) | 2531 | if (GNUTLS_E_SUCCESS != ret) |
@@ -2559,10 +2551,9 @@ static int | |||
2559 | load_cert_from_file (gnutls_x509_crt_t crt, char* certfile) | 2551 | load_cert_from_file (gnutls_x509_crt_t crt, char* certfile) |
2560 | { | 2552 | { |
2561 | gnutls_datum_t cert_data; | 2553 | gnutls_datum_t cert_data; |
2562 | cert_data.data = NULL; | ||
2563 | int ret; | 2554 | int ret; |
2564 | 2555 | ||
2565 | cert_data.data = (unsigned char*) load_file (certfile, &cert_data.size); | 2556 | cert_data.data = load_file (certfile, &cert_data.size); |
2566 | ret = gnutls_x509_crt_import (crt, &cert_data, | 2557 | ret = gnutls_x509_crt_import (crt, &cert_data, |
2567 | GNUTLS_X509_FMT_PEM); | 2558 | GNUTLS_X509_FMT_PEM); |
2568 | if (GNUTLS_E_SUCCESS != ret) | 2559 | if (GNUTLS_E_SUCCESS != ret) |
@@ -2585,7 +2576,6 @@ load_cert_from_file (gnutls_x509_crt_t crt, char* certfile) | |||
2585 | static struct ProxyGNSCertificate * | 2576 | static struct ProxyGNSCertificate * |
2586 | generate_gns_certificate (const char *name) | 2577 | generate_gns_certificate (const char *name) |
2587 | { | 2578 | { |
2588 | |||
2589 | int ret; | 2579 | int ret; |
2590 | unsigned int serial; | 2580 | unsigned int serial; |
2591 | size_t key_buf_size; | 2581 | size_t key_buf_size; |
@@ -2601,12 +2591,7 @@ generate_gns_certificate (const char *name) | |||
2601 | GNUNET_break (0); | 2591 | GNUNET_break (0); |
2602 | } | 2592 | } |
2603 | 2593 | ||
2604 | ret = gnutls_x509_crt_set_key (request, proxy_ca.key); | 2594 | GNUNET_break (GNUTLS_E_SUCCESS == gnutls_x509_crt_set_key (request, proxy_ca.key)); |
2605 | |||
2606 | if (GNUTLS_E_SUCCESS != ret) | ||
2607 | { | ||
2608 | GNUNET_break (0); | ||
2609 | } | ||
2610 | 2595 | ||
2611 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generating cert\n"); | 2596 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generating cert\n"); |
2612 | 2597 | ||
@@ -2617,14 +2602,11 @@ generate_gns_certificate (const char *name) | |||
2617 | 2602 | ||
2618 | gnutls_x509_crt_set_dn_by_oid (request, GNUTLS_OID_X520_COUNTRY_NAME, | 2603 | gnutls_x509_crt_set_dn_by_oid (request, GNUTLS_OID_X520_COUNTRY_NAME, |
2619 | 0, "DE", 2); | 2604 | 0, "DE", 2); |
2620 | |||
2621 | gnutls_x509_crt_set_dn_by_oid (request, GNUTLS_OID_X520_ORGANIZATION_NAME, | 2605 | gnutls_x509_crt_set_dn_by_oid (request, GNUTLS_OID_X520_ORGANIZATION_NAME, |
2622 | 0, "GADS", 4); | 2606 | 0, "GADS", 4); |
2623 | |||
2624 | gnutls_x509_crt_set_dn_by_oid (request, GNUTLS_OID_X520_COMMON_NAME, | 2607 | gnutls_x509_crt_set_dn_by_oid (request, GNUTLS_OID_X520_COMMON_NAME, |
2625 | 0, name, strlen (name)); | 2608 | 0, name, strlen (name)); |
2626 | 2609 | GNUNET_break (GNUTLS_E_SUCCESS == gnutls_x509_crt_set_version (request, 3)); | |
2627 | ret = gnutls_x509_crt_set_version (request, 3); | ||
2628 | 2610 | ||
2629 | ret = gnutls_rnd (GNUTLS_RND_NONCE, &serial, sizeof (serial)); | 2611 | ret = gnutls_rnd (GNUTLS_RND_NONCE, &serial, sizeof (serial)); |
2630 | 2612 | ||
@@ -3484,7 +3466,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
3484 | mhd_httpd_head = NULL; | 3466 | mhd_httpd_head = NULL; |
3485 | mhd_httpd_tail = NULL; | 3467 | mhd_httpd_tail = NULL; |
3486 | total_mhd_connections = 0; | 3468 | total_mhd_connections = 0; |
3487 | #ifndef HAVE_MHD_NO_LISTEN_SOCKET | 3469 | #if ! HAVE_MHD_NO_LISTEN_SOCKET |
3488 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns-proxy", | 3470 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns-proxy", |
3489 | "PROXY_UNIXPATH", | 3471 | "PROXY_UNIXPATH", |
3490 | &proxy_sockfile)) | 3472 | &proxy_sockfile)) |