diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-05 16:12:20 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-05 16:12:20 +0000 |
commit | 59a5fb24a1da9f89384eb9f279019cf1b5782697 (patch) | |
tree | 015f53daeaaa02548a026ed8c95bb3a8a9790144 /src/gns/gnunet-gns-proxy.c | |
parent | dfb16cb188e82a9f48af6390694c872be2765049 (diff) | |
download | gnunet-59a5fb24a1da9f89384eb9f279019cf1b5782697.tar.gz gnunet-59a5fb24a1da9f89384eb9f279019cf1b5782697.zip |
-fix cleanup
Diffstat (limited to 'src/gns/gnunet-gns-proxy.c')
-rw-r--r-- | src/gns/gnunet-gns-proxy.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c index a0157ecbe..7cea347e2 100644 --- a/src/gns/gnunet-gns-proxy.c +++ b/src/gns/gnunet-gns-proxy.c | |||
@@ -168,7 +168,7 @@ struct ProxyCurlTask | |||
168 | char host[256]; | 168 | char host[256]; |
169 | 169 | ||
170 | /* The associated daemon list entry */ | 170 | /* The associated daemon list entry */ |
171 | struct MhdHttpList *daemon; | 171 | struct MhdHttpList *mhd; |
172 | 172 | ||
173 | }; | 173 | }; |
174 | 174 | ||
@@ -187,9 +187,6 @@ GNUNET_SCHEDULER_TaskIdentifier curl_download_task; | |||
187 | /* The non SSL httpd daemon handle */ | 187 | /* The non SSL httpd daemon handle */ |
188 | static struct MHD_Daemon *httpd; | 188 | static struct MHD_Daemon *httpd; |
189 | 189 | ||
190 | /* The http task ID */ | ||
191 | static GNUNET_SCHEDULER_TaskIdentifier httpd_task; | ||
192 | |||
193 | /* The cURL multi handle */ | 190 | /* The cURL multi handle */ |
194 | static CURLM *curl_multi; | 191 | static CURLM *curl_multi; |
195 | 192 | ||
@@ -211,6 +208,7 @@ static struct MhdHttpList *mhd_httpd_tail; | |||
211 | /* Handle to the regex for dotplus (.+) replacement in HTML */ | 208 | /* Handle to the regex for dotplus (.+) replacement in HTML */ |
212 | static regex_t re_dotplus; | 209 | static regex_t re_dotplus; |
213 | 210 | ||
211 | |||
214 | /** | 212 | /** |
215 | * Checks if name is in tld | 213 | * Checks if name is in tld |
216 | * | 214 | * |
@@ -322,9 +320,9 @@ static void | |||
322 | run_mhd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 320 | run_mhd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
323 | { | 321 | { |
324 | 322 | ||
325 | struct MhdHttpList *hd; | 323 | struct MhdHttpList *hd = cls; |
326 | 324 | ||
327 | for (hd=mhd_httpd_head; hd != NULL; hd = hd->next) | 325 | //for (hd=mhd_httpd_head; hd != NULL; hd = hd->next) |
328 | MHD_run (hd->daemon); | 326 | MHD_run (hd->daemon); |
329 | } | 327 | } |
330 | 328 | ||
@@ -380,7 +378,8 @@ callback_download (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
380 | 378 | ||
381 | //GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 379 | //GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
382 | // "cURL chunk:\n%s\n", (char*)ctask->buffer); | 380 | // "cURL chunk:\n%s\n", (char*)ctask->buffer); |
383 | run_mhd (NULL, NULL); | 381 | //run_mhd (NULL, NULL); |
382 | GNUNET_SCHEDULER_add_now (&run_mhd, ctask->mhd); | ||
384 | return total; | 383 | return total; |
385 | } | 384 | } |
386 | 385 | ||
@@ -404,9 +403,6 @@ mhd_content_free (void *cls) | |||
404 | } | 403 | } |
405 | 404 | ||
406 | 405 | ||
407 | |||
408 | |||
409 | |||
410 | /** | 406 | /** |
411 | * Shorten result callback | 407 | * Shorten result callback |
412 | * | 408 | * |
@@ -438,7 +434,7 @@ process_shorten (void* cls, const char* short_name) | |||
438 | 434 | ||
439 | ctask->pp_finished = GNUNET_YES; | 435 | ctask->pp_finished = GNUNET_YES; |
440 | 436 | ||
441 | GNUNET_SCHEDULER_add_now (&run_mhd, NULL); | 437 | GNUNET_SCHEDULER_add_now (&run_mhd, ctask->mhd); |
442 | } | 438 | } |
443 | 439 | ||
444 | 440 | ||
@@ -495,7 +491,7 @@ mhd_content_cb (void *cls, | |||
495 | ctask->download_in_progress = GNUNET_NO; | 491 | ctask->download_in_progress = GNUNET_NO; |
496 | curl_multi_remove_handle (curl_multi, ctask->curl); | 492 | curl_multi_remove_handle (curl_multi, ctask->curl); |
497 | curl_easy_cleanup (ctask->curl); | 493 | curl_easy_cleanup (ctask->curl); |
498 | GNUNET_SCHEDULER_add_now (&run_mhd, NULL); | 494 | GNUNET_SCHEDULER_add_now (&run_mhd, ctask->mhd); |
499 | return MHD_CONTENT_READER_END_OF_STREAM; | 495 | return MHD_CONTENT_READER_END_OF_STREAM; |
500 | } | 496 | } |
501 | 497 | ||
@@ -507,7 +503,7 @@ mhd_content_cb (void *cls, | |||
507 | ctask->download_in_progress = GNUNET_NO; | 503 | ctask->download_in_progress = GNUNET_NO; |
508 | curl_multi_remove_handle (curl_multi, ctask->curl); | 504 | curl_multi_remove_handle (curl_multi, ctask->curl); |
509 | curl_easy_cleanup (ctask->curl); | 505 | curl_easy_cleanup (ctask->curl); |
510 | GNUNET_SCHEDULER_add_now (&run_mhd, NULL); | 506 | GNUNET_SCHEDULER_add_now (&run_mhd, ctask->mhd); |
511 | return MHD_CONTENT_READER_END_WITH_ERROR; | 507 | return MHD_CONTENT_READER_END_WITH_ERROR; |
512 | } | 508 | } |
513 | 509 | ||
@@ -561,7 +557,7 @@ mhd_content_cb (void *cls, | |||
561 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 557 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
562 | "Skipping next %d bytes in buffer\n", m[0].rm_eo); | 558 | "Skipping next %d bytes in buffer\n", m[0].rm_eo); |
563 | 559 | ||
564 | GNUNET_SCHEDULER_add_now (&run_mhd, NULL); | 560 | GNUNET_SCHEDULER_add_now (&run_mhd, ctask->mhd); |
565 | 561 | ||
566 | if ( strlen (ctask->pp_buf) <= max ) | 562 | if ( strlen (ctask->pp_buf) <= max ) |
567 | { | 563 | { |
@@ -620,11 +616,11 @@ mhd_content_cb (void *cls, | |||
620 | ctask->buf_status = BUF_WAIT_FOR_CURL; | 616 | ctask->buf_status = BUF_WAIT_FOR_CURL; |
621 | ctask->buffer_ptr = ctask->buffer; | 617 | ctask->buffer_ptr = ctask->buffer; |
622 | curl_easy_pause (ctask->curl, CURLPAUSE_CONT); | 618 | curl_easy_pause (ctask->curl, CURLPAUSE_CONT); |
623 | GNUNET_SCHEDULER_add_now (&run_mhd, NULL); | 619 | GNUNET_SCHEDULER_add_now (&run_mhd, ctask->mhd); |
624 | } | 620 | } |
625 | } | 621 | } |
626 | 622 | ||
627 | GNUNET_SCHEDULER_add_now (&run_mhd, NULL); | 623 | GNUNET_SCHEDULER_add_now (&run_mhd, ctask->mhd); |
628 | 624 | ||
629 | return copied; | 625 | return copied; |
630 | } | 626 | } |
@@ -908,6 +904,7 @@ create_response (void *cls, | |||
908 | void **con_cls) | 904 | void **con_cls) |
909 | { | 905 | { |
910 | static int dummy; | 906 | static int dummy; |
907 | struct MhdHttpList* hd = cls; | ||
911 | const char* page = "<html><head><title>gnoxy</title>"\ | 908 | const char* page = "<html><head><title>gnoxy</title>"\ |
912 | "</head><body>cURL fail</body></html>"; | 909 | "</head><body>cURL fail</body></html>"; |
913 | struct MHD_Response *response; | 910 | struct MHD_Response *response; |
@@ -941,6 +938,7 @@ create_response (void *cls, | |||
941 | 938 | ||
942 | /* Do cURL */ | 939 | /* Do cURL */ |
943 | ctask = GNUNET_malloc (sizeof (struct ProxyCurlTask)); | 940 | ctask = GNUNET_malloc (sizeof (struct ProxyCurlTask)); |
941 | ctask->mhd = hd; | ||
944 | ctask->curl = curl_easy_init(); | 942 | ctask->curl = curl_easy_init(); |
945 | 943 | ||
946 | if (curl_multi == NULL) | 944 | if (curl_multi == NULL) |
@@ -1089,7 +1087,7 @@ run_httpd (struct MhdHttpList *hd) | |||
1089 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); | 1087 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); |
1090 | GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1); | 1088 | GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1); |
1091 | 1089 | ||
1092 | if (httpd_task != GNUNET_SCHEDULER_NO_TASK) | 1090 | if (hd->httpd_task != GNUNET_SCHEDULER_NO_TASK) |
1093 | GNUNET_SCHEDULER_cancel (hd->httpd_task); | 1091 | GNUNET_SCHEDULER_cancel (hd->httpd_task); |
1094 | hd->httpd_task = | 1092 | hd->httpd_task = |
1095 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, | 1093 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, |
@@ -1397,7 +1395,7 @@ add_handle_to_ssl_mhd (struct GNUNET_NETWORK_Handle *h, char* domain) | |||
1397 | strcpy (hd->domain, domain); | 1395 | strcpy (hd->domain, domain); |
1398 | hd->daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL, http_port++, | 1396 | hd->daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL, http_port++, |
1399 | NULL, NULL, | 1397 | NULL, NULL, |
1400 | &create_response, NULL, | 1398 | &create_response, hd, |
1401 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 128, | 1399 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 128, |
1402 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, | 1400 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, |
1403 | MHD_OPTION_NOTIFY_COMPLETED, | 1401 | MHD_OPTION_NOTIFY_COMPLETED, |
@@ -1763,8 +1761,14 @@ do_shutdown (void *cls, | |||
1763 | { | 1761 | { |
1764 | tmp_hd = hd->next; | 1762 | tmp_hd = hd->next; |
1765 | 1763 | ||
1764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1765 | "Stopping daemon\n"); | ||
1766 | |||
1766 | if (GNUNET_SCHEDULER_NO_TASK != hd->httpd_task) | 1767 | if (GNUNET_SCHEDULER_NO_TASK != hd->httpd_task) |
1767 | { | 1768 | { |
1769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1770 | "Stopping select task %d\n", | ||
1771 | hd->httpd_task); | ||
1768 | GNUNET_SCHEDULER_cancel (hd->httpd_task); | 1772 | GNUNET_SCHEDULER_cancel (hd->httpd_task); |
1769 | hd->httpd_task = GNUNET_SCHEDULER_NO_TASK; | 1773 | hd->httpd_task = GNUNET_SCHEDULER_NO_TASK; |
1770 | } | 1774 | } |
@@ -1777,6 +1781,8 @@ do_shutdown (void *cls, | |||
1777 | 1781 | ||
1778 | GNUNET_free (hd); | 1782 | GNUNET_free (hd); |
1779 | } | 1783 | } |
1784 | |||
1785 | GNUNET_GNS_disconnect (gns_handle); | ||
1780 | } | 1786 | } |
1781 | 1787 | ||
1782 | 1788 | ||
@@ -1888,7 +1894,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
1888 | strcpy (hd->domain, ""); | 1894 | strcpy (hd->domain, ""); |
1889 | httpd = MHD_start_daemon (MHD_USE_DEBUG, http_port++, | 1895 | httpd = MHD_start_daemon (MHD_USE_DEBUG, http_port++, |
1890 | NULL, NULL, | 1896 | NULL, NULL, |
1891 | &create_response, NULL, | 1897 | &create_response, hd, |
1892 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 128, | 1898 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 128, |
1893 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, | 1899 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, |
1894 | MHD_OPTION_NOTIFY_COMPLETED, | 1900 | MHD_OPTION_NOTIFY_COMPLETED, |