aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-07-15 17:43:41 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-07-15 17:43:41 +0200
commite2ae8c8ab4f61afacdb98587dd1dbedc00cd63ee (patch)
tree6823773547d5281fe559e6a9e3ecd934f43ccd07
parent2b4d53b03d3e6574a30fa8033eea5ac1ca851dc5 (diff)
downloadgnunet-e2ae8c8ab4f61afacdb98587dd1dbedc00cd63ee.tar.gz
gnunet-e2ae8c8ab4f61afacdb98587dd1dbedc00cd63ee.zip
try fix lock #3
-rw-r--r--src/rest/gnunet-rest-server.c116
1 files changed, 58 insertions, 58 deletions
diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c
index c91ef2d69..30acc1125 100644
--- a/src/rest/gnunet-rest-server.c
+++ b/src/rest/gnunet-rest-server.c
@@ -434,81 +434,80 @@ create_response (void *cls,
434 } 434 }
435 MHD_destroy_post_processor (con_handle->pp); 435 MHD_destroy_post_processor (con_handle->pp);
436 436
437 //Suspend connection until plugin is done
438 MHD_suspend_connection (con_handle->con);
439 con_handle->state = GN_REST_STATE_PROCESSING; 437 con_handle->state = GN_REST_STATE_PROCESSING;
440 con_handle->plugin->process_request (rest_conndata_handle, 438 con_handle->plugin->process_request (rest_conndata_handle,
441 &plugin_callback, 439 &plugin_callback,
442 con_handle); 440 con_handle);
443 *upload_data_size = 0; 441 *upload_data_size = 0;
442 run_mhd_now ();
444 return MHD_YES; 443 return MHD_YES;
445 } 444 }
446 if (NULL != con_handle->response) 445 if (NULL == con_handle->response)
447 { 446 {
448 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 447 //Suspend connection until plugin is done
449 "Queueing response from plugin with MHD\n"); 448 MHD_suspend_connection (con_handle->con);
450 //Handle Preflights for extensions 449 return MHD_YES;
451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking origin\n"); 450 }
452 GNUNET_CRYPTO_hash ("origin", strlen ("origin"), &key); 451 MHD_resume_connection (con_handle->con);
453 origin = GNUNET_CONTAINER_multihashmap_get (con_handle->data_handle 452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
454 ->header_param_map, 453 "Queueing response from plugin with MHD\n");
455 &key); 454 //Handle Preflights for extensions
456 if (NULL != origin) 455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking origin\n");
456 GNUNET_CRYPTO_hash ("origin", strlen ("origin"), &key);
457 origin = GNUNET_CONTAINER_multihashmap_get (con_handle->data_handle
458 ->header_param_map,
459 &key);
460 if (NULL != origin)
461 {
462 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Origin: %s\n", origin);
463 //Only echo for browser plugins
464 if (GNUNET_YES == echo_origin)
457 { 465 {
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Origin: %s\n", origin); 466 if ((0 ==
459 //Only echo for browser plugins 467 strncmp ("moz-extension://", origin, strlen ("moz-extension://"))) ||
460 if (GNUNET_YES == echo_origin) 468 (0 == strncmp ("chrome-extension://",
469 origin,
470 strlen ("chrome-extension://"))))
461 { 471 {
462 if ((0 == strncmp ("moz-extension://", 472 MHD_add_response_header (con_handle->response,
463 origin, 473 MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
464 strlen ("moz-extension://"))) || 474 origin);
465 (0 == strncmp ("chrome-extension://",
466 origin,
467 strlen ("chrome-extension://"))))
468 {
469 MHD_add_response_header (con_handle->response,
470 MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
471 origin);
472 }
473 } 475 }
474 if (NULL != allow_origins) 476 }
477 if (NULL != allow_origins)
478 {
479 char *tmp = GNUNET_strdup (allow_origins);
480 char *allow_origin = strtok (tmp, ",");
481 while (NULL != allow_origin)
475 { 482 {
476 char *tmp = GNUNET_strdup (allow_origins); 483 if (0 == strncmp (allow_origin, origin, strlen (allow_origin)))
477 char *allow_origin = strtok (tmp, ",");
478 while (NULL != allow_origin)
479 { 484 {
480 if (0 == strncmp (allow_origin, origin, strlen (allow_origin))) 485 MHD_add_response_header (con_handle->response,
481 { 486 MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
482 MHD_add_response_header (con_handle->response, 487 allow_origin);
483 MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, 488 break;
484 allow_origin);
485 break;
486 }
487 allow_origin = strtok (NULL, ",");
488 } 489 }
489 GNUNET_free (tmp); 490 allow_origin = strtok (NULL, ",");
490 } 491 }
492 GNUNET_free (tmp);
491 } 493 }
492 if (NULL != allow_credentials) 494 }
493 { 495 if (NULL != allow_credentials)
494 MHD_add_response_header (con_handle->response, 496 {
495 "Access-Control-Allow-Credentials", 497 MHD_add_response_header (con_handle->response,
496 allow_credentials); 498 "Access-Control-Allow-Credentials",
497 } 499 allow_credentials);
498 if (NULL != allow_headers) 500 }
499 { 501 if (NULL != allow_headers)
500 MHD_add_response_header (con_handle->response, 502 {
501 "Access-Control-Allow-Headers", 503 MHD_add_response_header (con_handle->response,
502 allow_headers); 504 "Access-Control-Allow-Headers",
503 } 505 allow_headers);
504 run_mhd_now ();
505 int ret =
506 MHD_queue_response (con, con_handle->status, con_handle->response);
507 cleanup_handle (con_handle);
508 return ret;
509 } 506 }
510 run_mhd_now (); 507 run_mhd_now ();
511 return MHD_YES; 508 int ret = MHD_queue_response (con, con_handle->status, con_handle->response);
509 cleanup_handle (con_handle);
510 return ret;
512} 511}
513 512
514 513
@@ -985,7 +984,8 @@ run (void *cls,
985 return; 984 return;
986 } 985 }
987 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service listens on port %llu\n", port); 986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service listens on port %llu\n", port);
988 httpd = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_NO_LISTEN_SOCKET | MHD_ALLOW_SUSPEND_RESUME, 987 httpd = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_NO_LISTEN_SOCKET |
988 MHD_ALLOW_SUSPEND_RESUME,
989 0, 989 0,
990 NULL, 990 NULL,
991 NULL, 991 NULL,