diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-07-09 00:11:41 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-07-09 00:11:41 +0000 |
commit | bf05f753b6891579359dacc18e8c8597d38cffb6 (patch) | |
tree | 0891b5fd47b0c972e1b6c625ee90d7a983dad8dc /src/gns/gnunet-gns-proxy.c | |
parent | 4735aee3267f34b3066e7e0b0c1e5b6108c6073e (diff) | |
download | gnunet-bf05f753b6891579359dacc18e8c8597d38cffb6.tar.gz gnunet-bf05f753b6891579359dacc18e8c8597d38cffb6.zip |
-fix request handling
Diffstat (limited to 'src/gns/gnunet-gns-proxy.c')
-rw-r--r-- | src/gns/gnunet-gns-proxy.c | 167 |
1 files changed, 91 insertions, 76 deletions
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c index b8b4247dc..d45ce9e8a 100644 --- a/src/gns/gnunet-gns-proxy.c +++ b/src/gns/gnunet-gns-proxy.c | |||
@@ -252,7 +252,10 @@ struct ProxyCurlTask | |||
252 | struct ProxySetCookieHeader *set_cookies_tail; | 252 | struct ProxySetCookieHeader *set_cookies_tail; |
253 | 253 | ||
254 | /* connection status */ | 254 | /* connection status */ |
255 | int con_status; | 255 | int ready_to_queue; |
256 | |||
257 | /* are we done */ | ||
258 | int fin; | ||
256 | 259 | ||
257 | /* connection */ | 260 | /* connection */ |
258 | struct MHD_Connection *connection; | 261 | struct MHD_Connection *connection; |
@@ -589,13 +592,14 @@ callback_download (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
589 | struct ProxyCurlTask *ctask = ctx; | 592 | struct ProxyCurlTask *ctask = ctx; |
590 | 593 | ||
591 | //MHD_run (httpd); | 594 | //MHD_run (httpd); |
592 | if (ctask->con_status == MHD_NO) | 595 | ctask->ready_to_queue = GNUNET_YES; |
596 | /*if (ctask->con_status == MHD_NO) | ||
593 | { | 597 | { |
594 | MHD_queue_response (ctask->connection, | 598 | MHD_queue_response (ctask->connection, |
595 | MHD_HTTP_OK, | 599 | MHD_HTTP_OK, |
596 | ctask->response); | 600 | ctask->response); |
597 | ctask->con_status = MHD_YES; | 601 | ctask->con_status = MHD_YES; |
598 | } | 602 | }*/ |
599 | total = size*nmemb; | 603 | total = size*nmemb; |
600 | 604 | ||
601 | if (total == 0) | 605 | if (total == 0) |
@@ -1305,7 +1309,6 @@ create_response (void *cls, | |||
1305 | size_t *upload_data_size, | 1309 | size_t *upload_data_size, |
1306 | void **con_cls) | 1310 | void **con_cls) |
1307 | { | 1311 | { |
1308 | static int dummy; | ||
1309 | struct MhdHttpList* hd = cls; | 1312 | struct MhdHttpList* hd = cls; |
1310 | const char* page = "<html><head><title>gnoxy</title>"\ | 1313 | const char* page = "<html><head><title>gnoxy</title>"\ |
1311 | "</head><body>cURL fail</body></html>"; | 1314 | "</head><body>cURL fail</body></html>"; |
@@ -1316,19 +1319,13 @@ create_response (void *cls, | |||
1316 | 1319 | ||
1317 | struct ProxyCurlTask *ctask; | 1320 | struct ProxyCurlTask *ctask; |
1318 | 1321 | ||
1322 | //FIXME handle | ||
1319 | if (0 != strcmp (meth, "GET")) | 1323 | if (0 != strcmp (meth, "GET")) |
1320 | return MHD_NO; | 1324 | return MHD_NO; |
1321 | if (&dummy != *con_cls) | ||
1322 | { | ||
1323 | *con_cls = &dummy; | ||
1324 | return MHD_YES; | ||
1325 | } | ||
1326 | 1325 | ||
1327 | if (0 != *upload_data_size) | 1326 | if (0 != *upload_data_size) |
1328 | return MHD_NO; | 1327 | return MHD_NO; |
1329 | 1328 | ||
1330 | *con_cls = NULL; | ||
1331 | |||
1332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1333 | "url %s\n", url); | 1330 | "url %s\n", url); |
1334 | 1331 | ||
@@ -1336,77 +1333,95 @@ create_response (void *cls, | |||
1336 | MHD_HEADER_KIND, | 1333 | MHD_HEADER_KIND, |
1337 | &con_val_iter, host); | 1334 | &con_val_iter, host); |
1338 | 1335 | ||
1339 | 1336 | if (NULL == *con_cls) | |
1340 | /* Do cURL */ | 1337 | { |
1341 | ctask = GNUNET_malloc (sizeof (struct ProxyCurlTask)); | 1338 | ctask = GNUNET_malloc (sizeof (struct ProxyCurlTask)); |
1342 | ctask->mhd = hd; | 1339 | ctask->mhd = hd; |
1343 | 1340 | *con_cls = ctask; | |
1344 | if (curl_multi == NULL) | 1341 | |
1342 | if (curl_multi == NULL) | ||
1345 | curl_multi = curl_multi_init (); | 1343 | curl_multi = curl_multi_init (); |
1346 | 1344 | ||
1347 | ctask->curl = curl_easy_init(); | 1345 | ctask->curl = curl_easy_init(); |
1348 | 1346 | ||
1349 | if ((ctask->curl == NULL) || (curl_multi == NULL)) | 1347 | if ((ctask->curl == NULL) || (curl_multi == NULL)) |
1350 | { | 1348 | { |
1351 | ctask->response = MHD_create_response_from_buffer (strlen (page), | 1349 | ctask->response = MHD_create_response_from_buffer (strlen (page), |
1352 | (void*)page, | 1350 | (void*)page, |
1353 | MHD_RESPMEM_PERSISTENT); | 1351 | MHD_RESPMEM_PERSISTENT); |
1354 | ret = MHD_queue_response (con, | 1352 | ret = MHD_queue_response (con, |
1355 | MHD_HTTP_OK, | 1353 | MHD_HTTP_OK, |
1356 | ctask->response); | 1354 | ctask->response); |
1357 | MHD_destroy_response (ctask->response); | 1355 | MHD_destroy_response (ctask->response); |
1358 | GNUNET_free (ctask); | 1356 | GNUNET_free (ctask); |
1359 | return ret; | 1357 | return ret; |
1360 | } | 1358 | } |
1361 | 1359 | ||
1362 | ctask->prev = NULL; | 1360 | ctask->prev = NULL; |
1363 | ctask->next = NULL; | 1361 | ctask->next = NULL; |
1364 | ctask->headers = NULL; | 1362 | ctask->headers = NULL; |
1365 | ctask->resolver = NULL; | 1363 | ctask->resolver = NULL; |
1366 | ctask->buffer_ptr = NULL; | 1364 | ctask->buffer_ptr = NULL; |
1367 | ctask->download_in_progress = GNUNET_YES; | 1365 | ctask->download_in_progress = GNUNET_YES; |
1368 | ctask->download_successful = GNUNET_NO; | 1366 | ctask->download_successful = GNUNET_NO; |
1369 | ctask->buf_status = BUF_WAIT_FOR_CURL; | 1367 | ctask->buf_status = BUF_WAIT_FOR_CURL; |
1370 | ctask->bytes_in_buffer = 0; | 1368 | ctask->bytes_in_buffer = 0; |
1371 | ctask->parse_content = GNUNET_NO; | 1369 | ctask->parse_content = GNUNET_NO; |
1372 | ctask->connection = con; | 1370 | ctask->connection = con; |
1373 | ctask->con_status = MHD_NO; | 1371 | ctask->ready_to_queue = MHD_NO; |
1374 | 1372 | ctask->fin = GNUNET_NO; | |
1375 | curl_easy_setopt (ctask->curl, CURLOPT_HEADERFUNCTION, &curl_check_hdr); | 1373 | |
1376 | curl_easy_setopt (ctask->curl, CURLOPT_HEADERDATA, ctask); | 1374 | curl_easy_setopt (ctask->curl, CURLOPT_HEADERFUNCTION, &curl_check_hdr); |
1377 | curl_easy_setopt (ctask->curl, CURLOPT_WRITEFUNCTION, &callback_download); | 1375 | curl_easy_setopt (ctask->curl, CURLOPT_HEADERDATA, ctask); |
1378 | curl_easy_setopt (ctask->curl, CURLOPT_WRITEDATA, ctask); | 1376 | curl_easy_setopt (ctask->curl, CURLOPT_WRITEFUNCTION, &callback_download); |
1379 | curl_easy_setopt (ctask->curl, CURLOPT_FOLLOWLOCATION, 1); | 1377 | curl_easy_setopt (ctask->curl, CURLOPT_WRITEDATA, ctask); |
1380 | curl_easy_setopt (ctask->curl, CURLOPT_MAXREDIRS, 4); | 1378 | curl_easy_setopt (ctask->curl, CURLOPT_FOLLOWLOCATION, 1); |
1381 | /* no need to abort if the above failed */ | 1379 | curl_easy_setopt (ctask->curl, CURLOPT_MAXREDIRS, 4); |
1382 | if (GNUNET_NO == ctask->mhd->is_ssl) | 1380 | /* no need to abort if the above failed */ |
1383 | { | 1381 | if (GNUNET_NO == ctask->mhd->is_ssl) |
1384 | sprintf (curlurl, "http://%s%s", host, url); | 1382 | { |
1385 | curl_easy_setopt (ctask->curl, CURLOPT_URL, curlurl); | 1383 | sprintf (curlurl, "http://%s%s", host, url); |
1386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1384 | curl_easy_setopt (ctask->curl, CURLOPT_URL, curlurl); |
1387 | "Adding new curl task for %s\n", curlurl); | 1385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1386 | "Adding new curl task for %s\n", curlurl); | ||
1387 | } | ||
1388 | strcpy (ctask->host, host); | ||
1389 | strcpy (ctask->url, url); | ||
1390 | |||
1391 | //curl_easy_setopt (ctask->curl, CURLOPT_URL, curlurl); | ||
1392 | curl_easy_setopt (ctask->curl, CURLOPT_FAILONERROR, 1); | ||
1393 | curl_easy_setopt (ctask->curl, CURLOPT_CONNECTTIMEOUT, 600L); | ||
1394 | curl_easy_setopt (ctask->curl, CURLOPT_TIMEOUT, 600L); | ||
1395 | |||
1396 | GNUNET_GNS_get_authority (gns_handle, | ||
1397 | ctask->host, | ||
1398 | &process_get_authority, | ||
1399 | ctask); | ||
1400 | |||
1401 | ctask->response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, | ||
1402 | 20, | ||
1403 | &mhd_content_cb, | ||
1404 | ctask, | ||
1405 | NULL); | ||
1406 | |||
1407 | ctask->ready_to_queue = GNUNET_NO; | ||
1408 | ctask->fin = GNUNET_NO; | ||
1409 | return MHD_YES; | ||
1388 | } | 1410 | } |
1389 | strcpy (ctask->host, host); | 1411 | |
1390 | strcpy (ctask->url, url); | 1412 | ctask = (struct ProxyCurlTask *) *con_cls; |
1413 | |||
1414 | if (ctask->fin == GNUNET_YES) | ||
1415 | return MHD_YES; | ||
1416 | |||
1417 | if (ctask->ready_to_queue == GNUNET_YES) | ||
1418 | { | ||
1419 | ctask->fin = GNUNET_YES; | ||
1420 | return MHD_queue_response (con, MHD_HTTP_OK, ctask->response); | ||
1421 | } | ||
1422 | |||
1423 | |||
1391 | 1424 | ||
1392 | //curl_easy_setopt (ctask->curl, CURLOPT_URL, curlurl); | ||
1393 | curl_easy_setopt (ctask->curl, CURLOPT_FAILONERROR, 1); | ||
1394 | curl_easy_setopt (ctask->curl, CURLOPT_CONNECTTIMEOUT, 600L); | ||
1395 | curl_easy_setopt (ctask->curl, CURLOPT_TIMEOUT, 600L); | ||
1396 | |||
1397 | GNUNET_GNS_get_authority (gns_handle, | ||
1398 | ctask->host, | ||
1399 | &process_get_authority, | ||
1400 | ctask); | ||
1401 | //download_prepare (ctask); | ||
1402 | //curl_download_prepare (); | ||
1403 | |||
1404 | ctask->response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, | ||
1405 | 20, | ||
1406 | &mhd_content_cb, | ||
1407 | ctask, | ||
1408 | NULL); | ||
1409 | //ret = MHD_queue_response (con, MHD_HTTP_OK, ctask->response); | ||
1410 | 1425 | ||
1411 | //MHD_destroy_response (response); | 1426 | //MHD_destroy_response (response); |
1412 | 1427 | ||