diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-07-06 21:33:21 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-07-06 21:33:21 +0000 |
commit | df67704ea60f22e705588dd2188c91e16ebc5633 (patch) | |
tree | ea46f424488e253e532b86904cebce610dcec307 /src/gns/gnunet-gns-proxy.c | |
parent | ddb09c4360b6548ea7f7f5bfa78c565d5955fe6b (diff) | |
download | gnunet-df67704ea60f22e705588dd2188c91e16ebc5633.tar.gz gnunet-df67704ea60f22e705588dd2188c91e16ebc5633.zip |
-fix resover memleak, more proxy cookies
Diffstat (limited to 'src/gns/gnunet-gns-proxy.c')
-rw-r--r-- | src/gns/gnunet-gns-proxy.c | 123 |
1 files changed, 77 insertions, 46 deletions
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c index bb67b7b26..4445245b3 100644 --- a/src/gns/gnunet-gns-proxy.c +++ b/src/gns/gnunet-gns-proxy.c | |||
@@ -250,6 +250,12 @@ struct ProxyCurlTask | |||
250 | 250 | ||
251 | /* Cookies to set */ | 251 | /* Cookies to set */ |
252 | struct ProxySetCookieHeader *set_cookies_tail; | 252 | struct ProxySetCookieHeader *set_cookies_tail; |
253 | |||
254 | /* connection status */ | ||
255 | int con_status; | ||
256 | |||
257 | /* connection */ | ||
258 | struct MHD_Connection *connection; | ||
253 | 259 | ||
254 | }; | 260 | }; |
255 | 261 | ||
@@ -400,11 +406,11 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls) | |||
400 | int html_mime_len = strlen (HTML_HDR_CONTENT); | 406 | int html_mime_len = strlen (HTML_HDR_CONTENT); |
401 | int cookie_hdr_len = strlen (MHD_HTTP_HEADER_SET_COOKIE); | 407 | int cookie_hdr_len = strlen (MHD_HTTP_HEADER_SET_COOKIE); |
402 | char hdr_mime[html_mime_len+1]; | 408 | char hdr_mime[html_mime_len+1]; |
403 | char hdr_cookie[size+1]; | 409 | char hdr_cookie[bytes+1]; |
404 | struct ProxySetCookieHeader *pch; | 410 | //char hdr_cookie_gns[bytes+strlen (ctask->leho)+1]; |
405 | size_t len; | 411 | //char* ndup; |
406 | 412 | ||
407 | if (html_mime_len <= size) | 413 | if (html_mime_len <= bytes) |
408 | { | 414 | { |
409 | memcpy (hdr_mime, buffer, html_mime_len); | 415 | memcpy (hdr_mime, buffer, html_mime_len); |
410 | hdr_mime[html_mime_len] = '\0'; | 416 | hdr_mime[html_mime_len] = '\0'; |
@@ -417,26 +423,62 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls) | |||
417 | } | 423 | } |
418 | } | 424 | } |
419 | 425 | ||
420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 426 | if (cookie_hdr_len > bytes) |
421 | "Got header %s\n", buffer); | 427 | return bytes; |
422 | 428 | ||
423 | if (cookie_hdr_len <= size) | 429 | memcpy (hdr_cookie, buffer, bytes); |
430 | hdr_cookie[bytes] = '\0'; | ||
431 | /*remove crlf*/ | ||
432 | if (hdr_cookie[bytes-1] == '\n') | ||
433 | hdr_cookie[bytes-1] = '\0'; | ||
434 | |||
435 | if (hdr_cookie[bytes-2] == '\r') | ||
436 | hdr_cookie[bytes-2] = '\0'; | ||
437 | |||
438 | if (0 == memcmp (hdr_cookie, | ||
439 | MHD_HTTP_HEADER_SET_COOKIE, | ||
440 | cookie_hdr_len)) | ||
424 | { | 441 | { |
425 | memcpy (hdr_cookie, buffer, size); | 442 | //ndup = GNUNET_strdup (hdr_cookie); |
426 | hdr_cookie[size] = '\0'; | 443 | //tok = strtok (ndup, ";"); |
427 | 444 | ||
428 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 445 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
429 | "Got Set-Cookie HTTP header %s\n", hdr_cookie); | 446 | "Got Set-Cookie HTTP header %s\n", hdr_cookie); |
430 | GNUNET_assert (0); | 447 | //pch = GNUNET_malloc (sizeof (struct ProxySetCookieHeader)); |
448 | //len = strlen (hdr_cookie) - cookie_hdr_len - 1; | ||
449 | //pch->cookie = GNUNET_malloc (len + 1); | ||
450 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
451 | "Copying Set-Cookie data %s:\n", hdr_cookie+cookie_hdr_len+1); | ||
452 | //memset (pch->cookie, 0, len + 1); | ||
453 | //memcpy (pch->cookie, hdr_cookie+cookie_hdr_len+1, len); | ||
454 | //GNUNET_CONTAINER_DLL_insert (ctask->set_cookies_head, | ||
455 | // ctask->set_cookies_tail, | ||
456 | // pch); | ||
457 | //pch = ctask->set_cookies_head; | ||
458 | //while (pch != NULL) | ||
459 | //{ | ||
460 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
461 | "MHD: adding cookie: %s\n", | ||
462 | hdr_cookie+cookie_hdr_len+1); | ||
431 | 463 | ||
432 | pch = GNUNET_malloc (sizeof (struct ProxySetCookieHeader)); | 464 | if (GNUNET_NO == MHD_add_response_header (ctask->response, |
433 | len = strlen (hdr_cookie) - strlen (MHD_HTTP_HEADER_SET_COOKIE); | 465 | MHD_HTTP_HEADER_SET_COOKIE, |
434 | pch->cookie = GNUNET_malloc (len + 1); | 466 | hdr_cookie+cookie_hdr_len+1)) |
435 | memset (pch->cookie, 0, len + 1); | 467 | { |
436 | memcpy (pch->cookie, hdr_cookie+strlen (MHD_HTTP_HEADER_SET_COOKIE), len); | 468 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
437 | GNUNET_CONTAINER_DLL_insert (ctask->set_cookies_head, | 469 | "MHD: Error adding set-cookie header field %s\n", |
438 | ctask->set_cookies_tail, | 470 | hdr_cookie+cookie_hdr_len+1); |
439 | pch); | 471 | } |
472 | MHD_add_response_header (ctask->response, | ||
473 | MHD_HTTP_HEADER_SET_COOKIE, | ||
474 | "test=test; domain=homepage.gnunet; secure"); | ||
475 | //GNUNET_free (pch->cookie); | ||
476 | //GNUNET_CONTAINER_DLL_remove (ctask->set_cookies_head, | ||
477 | // ctask->set_cookies_tail, | ||
478 | // pch); | ||
479 | //GNUNET_free (pch); | ||
480 | //pch = ctask->set_cookies_head; | ||
481 | //} | ||
440 | } | 482 | } |
441 | 483 | ||
442 | return bytes; | 484 | return bytes; |
@@ -493,7 +535,13 @@ callback_download (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
493 | struct ProxyCurlTask *ctask = ctx; | 535 | struct ProxyCurlTask *ctask = ctx; |
494 | 536 | ||
495 | //MHD_run (httpd); | 537 | //MHD_run (httpd); |
496 | 538 | if (ctask->con_status == MHD_NO) | |
539 | { | ||
540 | MHD_queue_response (ctask->connection, | ||
541 | MHD_HTTP_OK, | ||
542 | ctask->response); | ||
543 | ctask->con_status = MHD_YES; | ||
544 | } | ||
497 | total = size*nmemb; | 545 | total = size*nmemb; |
498 | 546 | ||
499 | if (total == 0) | 547 | if (total == 0) |
@@ -619,33 +667,14 @@ mhd_content_cb (void *cls, | |||
619 | int nomatch; | 667 | int nomatch; |
620 | char *hostptr; | 668 | char *hostptr; |
621 | regmatch_t m[RE_N_MATCHES]; | 669 | regmatch_t m[RE_N_MATCHES]; |
622 | struct ProxySetCookieHeader *pch; | ||
623 | 670 | ||
624 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 671 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
625 | "MHD: content cb %s\n", ctask->url); | 672 | "MHD: content cb %s\n", ctask->url); |
626 | |||
627 | pch = ctask->set_cookies_head; | ||
628 | while (pch != NULL) | ||
629 | { | ||
630 | if (GNUNET_NO == MHD_add_response_header (ctask->response, | ||
631 | MHD_HTTP_HEADER_SET_COOKIE, | ||
632 | pch->cookie)) | ||
633 | { | ||
634 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
635 | "MHD: Error adding set-cookie header field %s\n", | ||
636 | pch->cookie); | ||
637 | } | ||
638 | GNUNET_free (pch->cookie); | ||
639 | GNUNET_CONTAINER_DLL_remove (ctask->set_cookies_head, | ||
640 | ctask->set_cookies_tail, | ||
641 | pch); | ||
642 | pch = ctask->set_cookies_head; | ||
643 | } | ||
644 | 673 | ||
645 | if (ctask->download_successful && | 674 | if (ctask->download_successful && |
646 | (ctask->buf_status == BUF_WAIT_FOR_CURL)) | 675 | (ctask->buf_status == BUF_WAIT_FOR_CURL)) |
647 | { | 676 | { |
648 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 677 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
649 | "MHD: sending response for %s\n", ctask->url); | 678 | "MHD: sending response for %s\n", ctask->url); |
650 | ctask->download_in_progress = GNUNET_NO; | 679 | ctask->download_in_progress = GNUNET_NO; |
651 | GNUNET_SCHEDULER_add_now (&mhd_content_free, ctask); | 680 | GNUNET_SCHEDULER_add_now (&mhd_content_free, ctask); |
@@ -657,7 +686,7 @@ mhd_content_cb (void *cls, | |||
657 | if (ctask->download_error && | 686 | if (ctask->download_error && |
658 | (ctask->buf_status == BUF_WAIT_FOR_CURL)) | 687 | (ctask->buf_status == BUF_WAIT_FOR_CURL)) |
659 | { | 688 | { |
660 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 689 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
661 | "MHD: sending error response\n"); | 690 | "MHD: sending error response\n"); |
662 | ctask->download_in_progress = GNUNET_NO; | 691 | ctask->download_in_progress = GNUNET_NO; |
663 | GNUNET_SCHEDULER_add_now (&mhd_content_free, ctask); | 692 | GNUNET_SCHEDULER_add_now (&mhd_content_free, ctask); |
@@ -1286,6 +1315,8 @@ create_response (void *cls, | |||
1286 | ctask->buf_status = BUF_WAIT_FOR_CURL; | 1315 | ctask->buf_status = BUF_WAIT_FOR_CURL; |
1287 | ctask->bytes_in_buffer = 0; | 1316 | ctask->bytes_in_buffer = 0; |
1288 | ctask->parse_content = GNUNET_NO; | 1317 | ctask->parse_content = GNUNET_NO; |
1318 | ctask->connection = con; | ||
1319 | ctask->con_status = MHD_NO; | ||
1289 | 1320 | ||
1290 | curl_easy_setopt (ctask->curl, CURLOPT_HEADERFUNCTION, &curl_check_hdr); | 1321 | curl_easy_setopt (ctask->curl, CURLOPT_HEADERFUNCTION, &curl_check_hdr); |
1291 | curl_easy_setopt (ctask->curl, CURLOPT_HEADERDATA, ctask); | 1322 | curl_easy_setopt (ctask->curl, CURLOPT_HEADERDATA, ctask); |
@@ -1298,7 +1329,7 @@ create_response (void *cls, | |||
1298 | { | 1329 | { |
1299 | sprintf (curlurl, "http://%s%s", host, url); | 1330 | sprintf (curlurl, "http://%s%s", host, url); |
1300 | curl_easy_setopt (ctask->curl, CURLOPT_URL, curlurl); | 1331 | curl_easy_setopt (ctask->curl, CURLOPT_URL, curlurl); |
1301 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1302 | "Adding new curl task for %s\n", curlurl); | 1333 | "Adding new curl task for %s\n", curlurl); |
1303 | } | 1334 | } |
1304 | strcpy (ctask->host, host); | 1335 | strcpy (ctask->host, host); |
@@ -1321,12 +1352,12 @@ create_response (void *cls, | |||
1321 | &mhd_content_cb, | 1352 | &mhd_content_cb, |
1322 | ctask, | 1353 | ctask, |
1323 | NULL); | 1354 | NULL); |
1324 | 1355 | //ret = MHD_queue_response (con, MHD_HTTP_OK, ctask->response); | |
1325 | ret = MHD_queue_response (con, MHD_HTTP_OK, ctask->response); | ||
1326 | 1356 | ||
1327 | //MHD_destroy_response (response); | 1357 | //MHD_destroy_response (response); |
1328 | 1358 | ||
1329 | return ret; | 1359 | //return ret; |
1360 | return MHD_YES; | ||
1330 | } | 1361 | } |
1331 | 1362 | ||
1332 | /** | 1363 | /** |
@@ -2251,7 +2282,7 @@ do_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2251 | 2282 | ||
2252 | if (NULL == s) | 2283 | if (NULL == s) |
2253 | { | 2284 | { |
2254 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "accept"); | 2285 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "accept"); |
2255 | return; | 2286 | return; |
2256 | } | 2287 | } |
2257 | 2288 | ||