X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fgns%2Fgnunet-gns-proxy.c;h=cdc18e3f6b156ca8bfab88ffcf423f4ce292c10a;hb=bcbd694ad35e182e5a1486b545ea0706082ee94a;hp=2453cd9d3def945a6ad7e72c2efee7565e05210e;hpb=5348ed91bc946c5d4c01438c320f5af23c71d7b2;p=oweals%2Fgnunet.git diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c index 2453cd9d3..cdc18e3f6 100644 --- a/src/gns/gnunet-gns-proxy.c +++ b/src/gns/gnunet-gns-proxy.c @@ -587,6 +587,7 @@ con_post_data_iter (void *cls, memcpy (new_value, pdata->value, pdata->total_bytes); memcpy (new_value+off, data, size); GNUNET_free (pdata->value); + pdata->value = new_value; pdata->total_bytes += size; return MHD_YES; @@ -772,6 +773,7 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls) char* hdr_val; int delta_cdomain; size_t offset = 0; + char cors_hdr[strlen (ctask->leho) + strlen ("https://")]; if (NULL == ctask->response) { @@ -783,8 +785,30 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls) &mhd_content_cb, ctask, NULL); + + /* if we have a leho add a CORS header */ + if (0 != strcmp ("", ctask->leho)) + { + /* We could also allow ssl and http here */ + if (ctask->mhd->is_ssl) + sprintf (cors_hdr, "https://%s", ctask->leho); + else + sprintf (cors_hdr, "http://%s", ctask->leho); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "MHD: Adding CORS header field %s\n", + cors_hdr); + + if (GNUNET_NO == MHD_add_response_header (ctask->response, + "Access-Control-Allow-Origin", + cors_hdr)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "MHD: Error adding CORS header field %s\n", + cors_hdr); + } + } ctask->ready_to_queue = GNUNET_YES; - } if (html_mime_len <= bytes) @@ -1002,9 +1026,9 @@ mhd_content_free (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct ProxyCurlTask *ctask = cls; - struct ProxyUploadData *pdata = ctask->upload_data_head; - GNUNET_assert (NULL == ctask->pp_match_head); + struct ProxyUploadData *pdata; + GNUNET_assert (NULL == ctask->pp_match_head); if (NULL != ctask->headers) curl_slist_free_all (ctask->headers); @@ -1017,7 +1041,7 @@ mhd_content_free (void *cls, if (NULL != ctask->post_handler) MHD_destroy_post_processor (ctask->post_handler); - for (; pdata != NULL; pdata = ctask->upload_data_head) + for (pdata = ctask->upload_data_head; NULL != pdata; pdata = ctask->upload_data_head) { GNUNET_CONTAINER_DLL_remove (ctask->upload_data_head, ctask->upload_data_tail, @@ -1028,8 +1052,6 @@ mhd_content_free (void *cls, GNUNET_free_non_null (pdata->value); GNUNET_free (pdata); } - - GNUNET_free (ctask); } @@ -1050,7 +1072,7 @@ mhd_content_cb (void *cls, size_t max) { struct ProxyCurlTask *ctask = cls; - struct ProxyREMatch *re_match = ctask->pp_match_head; + struct ProxyREMatch *re_match; ssize_t copied = 0; long long int bytes_to_copy = ctask->buffer_write_ptr - ctask->buffer_read_ptr; @@ -1091,7 +1113,7 @@ mhd_content_cb (void *cls, return 0; copied = 0; - for (; NULL != re_match; re_match = ctask->pp_match_head) + for (re_match = ctask->pp_match_head; NULL != re_match; re_match = ctask->pp_match_head) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MHD: Processing PP %s\n", @@ -1194,6 +1216,7 @@ mhd_content_cb (void *cls, return copied; } + /** * Shorten result callback * @@ -1594,8 +1617,7 @@ curl_task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running curl tasks: %d\n", running); - ctask = ctasks_head; - for (; ctask != NULL; ctask = ctask->next) + for (ctask = ctasks_head; NULL != ctask; ctask = ctask->next) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CTask: %s\n", ctask->url); @@ -1610,7 +1632,7 @@ curl_task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) do { - ctask = ctasks_head; + msg = curl_multi_info_read (curl_multi, &msgnum); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Messages left: %d\n", msgnum); @@ -1626,7 +1648,7 @@ curl_task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Download curl failed"); - for (; ctask != NULL; ctask = ctask->next) + for (ctask = ctasks_head; NULL != ctask; ctask = ctask->next) { if (NULL == ctask->curl) continue; @@ -1660,7 +1682,7 @@ curl_task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CURL: download completed.\n"); - for (; ctask != NULL; ctask = ctask->next) + for (ctask = ctasks_head; NULL != ctask; ctask = ctask->next) { if (NULL == ctask->curl) continue; @@ -1706,7 +1728,7 @@ curl_task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } } while (msgnum > 0); - for (ctask=clean_head; ctask != NULL; ctask = ctask->next) + for (ctask=clean_head; NULL != ctask; ctask = ctask->next) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CURL: Removing task %s.\n", ctask->url); @@ -1716,7 +1738,7 @@ curl_task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } num_ctasks=0; - for (ctask=ctasks_head; ctask != NULL; ctask = ctask->next) + for (ctask=ctasks_head; NULL != ctask; ctask = ctask->next) { num_ctasks++; } @@ -1740,6 +1762,7 @@ curl_task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) curl_download_prepare(); } + /** * Process LEHO lookup * @@ -1992,8 +2015,8 @@ create_response (void *cls, curl_easy_setopt (ctask->curl, CURLOPT_TIMEOUT, 600L); /* Add GNS header */ - //ctask->headers = curl_slist_append (ctask->headers, - // "GNS: YES"); + ctask->headers = curl_slist_append (ctask->headers, + "GNS: YES"); ctask->accepted = GNUNET_YES; ctask->download_in_progress = GNUNET_YES; ctask->buf_status = BUF_WAIT_FOR_CURL; @@ -2087,11 +2110,11 @@ create_response (void *cls, { if (GNUNET_YES == ctask->is_httppost) { - i = 0; for (upload_data_iter = ctask->upload_data_head; NULL != upload_data_iter; upload_data_iter = upload_data_iter->next) { + i = 0; if (NULL != upload_data_iter->filename) { forms[i].option = CURLFORM_FILENAME;