diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-12 13:33:24 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-12 13:33:24 +0000 |
commit | 818289edf46125a64fa8417f7ff348d3aa5ab2ab (patch) | |
tree | 43e470b1473a8765270aa8dc3938ee823d93c61d /src/gns/gnunet-gns-proxy.c | |
parent | 7ffd0a61175c047fdd525f7b4e9079441e7e95da (diff) | |
download | gnunet-818289edf46125a64fa8417f7ff348d3aa5ab2ab.tar.gz gnunet-818289edf46125a64fa8417f7ff348d3aa5ab2ab.zip |
-fixes
Diffstat (limited to 'src/gns/gnunet-gns-proxy.c')
-rw-r--r-- | src/gns/gnunet-gns-proxy.c | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c index d6e5ba3d1..243e94c08 100644 --- a/src/gns/gnunet-gns-proxy.c +++ b/src/gns/gnunet-gns-proxy.c | |||
@@ -564,7 +564,7 @@ mhd_content_cb (void *cls, | |||
564 | if (ctask->download_successful && | 564 | if (ctask->download_successful && |
565 | (ctask->buf_status == BUF_WAIT_FOR_CURL)) | 565 | (ctask->buf_status == BUF_WAIT_FOR_CURL)) |
566 | { | 566 | { |
567 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 567 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
568 | "MHD: sending response for %s\n", ctask->url); | 568 | "MHD: sending response for %s\n", ctask->url); |
569 | ctask->download_in_progress = GNUNET_NO; | 569 | ctask->download_in_progress = GNUNET_NO; |
570 | curl_multi_remove_handle (curl_multi, ctask->curl); | 570 | curl_multi_remove_handle (curl_multi, ctask->curl); |
@@ -577,7 +577,7 @@ mhd_content_cb (void *cls, | |||
577 | if (ctask->download_error && | 577 | if (ctask->download_error && |
578 | (ctask->buf_status == BUF_WAIT_FOR_CURL)) | 578 | (ctask->buf_status == BUF_WAIT_FOR_CURL)) |
579 | { | 579 | { |
580 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 580 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
581 | "MHD: sending error response\n"); | 581 | "MHD: sending error response\n"); |
582 | ctask->download_in_progress = GNUNET_NO; | 582 | ctask->download_in_progress = GNUNET_NO; |
583 | curl_multi_remove_handle (curl_multi, ctask->curl); | 583 | curl_multi_remove_handle (curl_multi, ctask->curl); |
@@ -1017,6 +1017,8 @@ process_leho_lookup (void *cls, | |||
1017 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1017 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1018 | "SSL target server: %s\n", ssl_ip); | 1018 | "SSL target server: %s\n", ssl_ip); |
1019 | sprintf (resolvename, "%s:%d:%s", ctask->leho, HTTPS_PORT, ssl_ip); | 1019 | sprintf (resolvename, "%s:%d:%s", ctask->leho, HTTPS_PORT, ssl_ip); |
1020 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1021 | "Curl resolve: %s\n", resolvename); | ||
1020 | ctask->resolver = curl_slist_append ( ctask->resolver, resolvename); | 1022 | ctask->resolver = curl_slist_append ( ctask->resolver, resolvename); |
1021 | curl_easy_setopt (ctask->curl, CURLOPT_RESOLVE, ctask->resolver); | 1023 | curl_easy_setopt (ctask->curl, CURLOPT_RESOLVE, ctask->resolver); |
1022 | sprintf (curlurl, "https://%s%s", ctask->leho, ctask->url); | 1024 | sprintf (curlurl, "https://%s%s", ctask->leho, ctask->url); |
@@ -1121,7 +1123,7 @@ create_response (void *cls, | |||
1121 | struct MhdHttpList* hd = cls; | 1123 | struct MhdHttpList* hd = cls; |
1122 | const char* page = "<html><head><title>gnoxy</title>"\ | 1124 | const char* page = "<html><head><title>gnoxy</title>"\ |
1123 | "</head><body>cURL fail</body></html>"; | 1125 | "</head><body>cURL fail</body></html>"; |
1124 | struct MHD_Response *response; | 1126 | struct MHD_Response *response = NULL; |
1125 | char host[265]; | 1127 | char host[265]; |
1126 | char curlurl[512]; | 1128 | char curlurl[512]; |
1127 | int ret = MHD_YES; | 1129 | int ret = MHD_YES; |
@@ -1152,10 +1154,11 @@ create_response (void *cls, | |||
1152 | /* Do cURL */ | 1154 | /* Do cURL */ |
1153 | ctask = GNUNET_malloc (sizeof (struct ProxyCurlTask)); | 1155 | ctask = GNUNET_malloc (sizeof (struct ProxyCurlTask)); |
1154 | ctask->mhd = hd; | 1156 | ctask->mhd = hd; |
1155 | ctask->curl = curl_easy_init(); | ||
1156 | 1157 | ||
1157 | if (curl_multi == NULL) | 1158 | if (curl_multi == NULL) |
1158 | curl_multi = curl_multi_init (); | 1159 | curl_multi = curl_multi_init (); |
1160 | |||
1161 | ctask->curl = curl_easy_init(); | ||
1159 | 1162 | ||
1160 | if ((ctask->curl == NULL) || (curl_multi == NULL)) | 1163 | if ((ctask->curl == NULL) || (curl_multi == NULL)) |
1161 | { | 1164 | { |
@@ -1169,7 +1172,12 @@ create_response (void *cls, | |||
1169 | GNUNET_free (ctask); | 1172 | GNUNET_free (ctask); |
1170 | return ret; | 1173 | return ret; |
1171 | } | 1174 | } |
1172 | 1175 | ||
1176 | ctask->prev = NULL; | ||
1177 | ctask->next = NULL; | ||
1178 | ctask->headers = NULL; | ||
1179 | ctask->resolver = NULL; | ||
1180 | ctask->buffer_ptr = NULL; | ||
1173 | ctask->download_in_progress = GNUNET_YES; | 1181 | ctask->download_in_progress = GNUNET_YES; |
1174 | ctask->download_successful = GNUNET_NO; | 1182 | ctask->download_successful = GNUNET_NO; |
1175 | ctask->buf_status = BUF_WAIT_FOR_CURL; | 1183 | ctask->buf_status = BUF_WAIT_FOR_CURL; |
@@ -1184,13 +1192,16 @@ create_response (void *cls, | |||
1184 | curl_easy_setopt (ctask->curl, CURLOPT_MAXREDIRS, 4); | 1192 | curl_easy_setopt (ctask->curl, CURLOPT_MAXREDIRS, 4); |
1185 | /* no need to abort if the above failed */ | 1193 | /* no need to abort if the above failed */ |
1186 | if (GNUNET_NO == ctask->mhd->is_ssl) | 1194 | if (GNUNET_NO == ctask->mhd->is_ssl) |
1195 | { | ||
1187 | sprintf (curlurl, "http://%s%s", host, url); | 1196 | sprintf (curlurl, "http://%s%s", host, url); |
1197 | curl_easy_setopt (ctask->curl, CURLOPT_URL, curlurl); | ||
1198 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1199 | "Adding new curl task for %s\n", curlurl); | ||
1200 | } | ||
1188 | strcpy (ctask->host, host); | 1201 | strcpy (ctask->host, host); |
1189 | strcpy (ctask->url, url); | 1202 | strcpy (ctask->url, url); |
1190 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1191 | "Adding new curl task for %s\n", curlurl); | ||
1192 | 1203 | ||
1193 | curl_easy_setopt (ctask->curl, CURLOPT_URL, curlurl); | 1204 | //curl_easy_setopt (ctask->curl, CURLOPT_URL, curlurl); |
1194 | curl_easy_setopt (ctask->curl, CURLOPT_FAILONERROR, 1); | 1205 | curl_easy_setopt (ctask->curl, CURLOPT_FAILONERROR, 1); |
1195 | curl_easy_setopt (ctask->curl, CURLOPT_CONNECTTIMEOUT, 600L); | 1206 | curl_easy_setopt (ctask->curl, CURLOPT_CONNECTTIMEOUT, 600L); |
1196 | curl_easy_setopt (ctask->curl, CURLOPT_TIMEOUT, 600L); | 1207 | curl_easy_setopt (ctask->curl, CURLOPT_TIMEOUT, 600L); |
@@ -1202,7 +1213,8 @@ create_response (void *cls, | |||
1202 | //download_prepare (ctask); | 1213 | //download_prepare (ctask); |
1203 | //curl_download_prepare (); | 1214 | //curl_download_prepare (); |
1204 | 1215 | ||
1205 | response = MHD_create_response_from_callback (-1, -1, | 1216 | response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, |
1217 | MHD_SIZE_UNKNOWN, | ||
1206 | &mhd_content_cb, | 1218 | &mhd_content_cb, |
1207 | ctask, | 1219 | ctask, |
1208 | &mhd_content_free); | 1220 | &mhd_content_free); |
@@ -1542,28 +1554,27 @@ get_file_size (const char* filename) | |||
1542 | * @return data | 1554 | * @return data |
1543 | */ | 1555 | */ |
1544 | static char* | 1556 | static char* |
1545 | load_file (const char* filename) | 1557 | load_file (const char* filename, unsigned int* size) |
1546 | { | 1558 | { |
1547 | FILE *fp; | 1559 | FILE *fp; |
1548 | char *buffer; | 1560 | char *buffer; |
1549 | long size; | ||
1550 | 1561 | ||
1551 | size = get_file_size (filename); | 1562 | *size = get_file_size (filename); |
1552 | if (size == 0) | 1563 | if (*size == 0) |
1553 | return NULL; | 1564 | return NULL; |
1554 | 1565 | ||
1555 | fp = fopen (filename, "rb"); | 1566 | fp = fopen (filename, "rb"); |
1556 | if (!fp) | 1567 | if (!fp) |
1557 | return NULL; | 1568 | return NULL; |
1558 | 1569 | ||
1559 | buffer = GNUNET_malloc (size); | 1570 | buffer = GNUNET_malloc (*size); |
1560 | if (!buffer) | 1571 | if (!buffer) |
1561 | { | 1572 | { |
1562 | fclose (fp); | 1573 | fclose (fp); |
1563 | return NULL; | 1574 | return NULL; |
1564 | } | 1575 | } |
1565 | 1576 | ||
1566 | if (size != fread (buffer, 1, size, fp)) | 1577 | if (*size != fread (buffer, 1, *size, fp)) |
1567 | { | 1578 | { |
1568 | GNUNET_free (buffer); | 1579 | GNUNET_free (buffer); |
1569 | buffer = NULL; | 1580 | buffer = NULL; |
@@ -1585,10 +1596,10 @@ static void | |||
1585 | load_key_from_file (gnutls_x509_privkey_t key, char* keyfile) | 1596 | load_key_from_file (gnutls_x509_privkey_t key, char* keyfile) |
1586 | { | 1597 | { |
1587 | gnutls_datum_t key_data; | 1598 | gnutls_datum_t key_data; |
1599 | key_data.data = NULL; | ||
1588 | int ret; | 1600 | int ret; |
1589 | 1601 | ||
1590 | key_data.data = (unsigned char*)load_file (keyfile); | 1602 | key_data.data = (unsigned char*)load_file (keyfile, &key_data.size); |
1591 | key_data.size = strlen ((char*)key_data.data); | ||
1592 | 1603 | ||
1593 | ret = gnutls_x509_privkey_import (key, &key_data, | 1604 | ret = gnutls_x509_privkey_import (key, &key_data, |
1594 | GNUTLS_X509_FMT_PEM); | 1605 | GNUTLS_X509_FMT_PEM); |
@@ -1613,10 +1624,10 @@ static void | |||
1613 | load_cert_from_file (gnutls_x509_crt_t crt, char* certfile) | 1624 | load_cert_from_file (gnutls_x509_crt_t crt, char* certfile) |
1614 | { | 1625 | { |
1615 | gnutls_datum_t cert_data; | 1626 | gnutls_datum_t cert_data; |
1627 | cert_data.data = NULL; | ||
1616 | int ret; | 1628 | int ret; |
1617 | 1629 | ||
1618 | cert_data.data = (unsigned char*)load_file (certfile); | 1630 | cert_data.data = (unsigned char*)load_file (certfile, &cert_data.size); |
1619 | cert_data.size = strlen ((char*)cert_data.data); | ||
1620 | 1631 | ||
1621 | ret = gnutls_x509_crt_import (crt, &cert_data, | 1632 | ret = gnutls_x509_crt_import (crt, &cert_data, |
1622 | GNUTLS_X509_FMT_PEM); | 1633 | GNUTLS_X509_FMT_PEM); |
@@ -2152,6 +2163,8 @@ do_shutdown (void *cls, | |||
2152 | struct ProxyCurlTask *ctask; | 2163 | struct ProxyCurlTask *ctask; |
2153 | struct ProxyCurlTask *ctask_tmp; | 2164 | struct ProxyCurlTask *ctask_tmp; |
2154 | 2165 | ||
2166 | gnutls_global_deinit (); | ||
2167 | |||
2155 | if (GNUNET_SCHEDULER_NO_TASK != curl_download_task) | 2168 | if (GNUNET_SCHEDULER_NO_TASK != curl_download_task) |
2156 | { | 2169 | { |
2157 | GNUNET_SCHEDULER_cancel (curl_download_task); | 2170 | GNUNET_SCHEDULER_cancel (curl_download_task); |
@@ -2352,6 +2365,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
2352 | char* cafile_cfg = NULL; | 2365 | char* cafile_cfg = NULL; |
2353 | char* cafile; | 2366 | char* cafile; |
2354 | 2367 | ||
2368 | curl_multi = NULL; | ||
2369 | |||
2355 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2370 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
2356 | "Loading CA\n"); | 2371 | "Loading CA\n"); |
2357 | 2372 | ||