aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2020-08-06 23:06:16 +0200
committerMartin Schanzenbach <mschanzenbach@posteo.de>2020-08-06 23:06:16 +0200
commit7648cde6cfb181f03df9e145a576430220234f5f (patch)
tree987badd6024e09608b47e72f56052cf79f67b405 /src/reclaim
parent19fe8e8ff74a9639fc075f5d974a01a977e1196a (diff)
downloadgnunet-7648cde6cfb181f03df9e145a576430220234f5f.tar.gz
gnunet-7648cde6cfb181f03df9e145a576430220234f5f.zip
-improve request cleanup handling
Diffstat (limited to 'src/reclaim')
-rw-r--r--src/reclaim/plugin_rest_openid_connect.c58
-rw-r--r--src/reclaim/plugin_rest_reclaim.c35
2 files changed, 70 insertions, 23 deletions
diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c
index 0a6ed3b7f..6db494433 100644
--- a/src/reclaim/plugin_rest_openid_connect.c
+++ b/src/reclaim/plugin_rest_openid_connect.c
@@ -393,6 +393,15 @@ struct EgoEntry
393 393
394struct RequestHandle 394struct RequestHandle
395{ 395{
396 /**
397 * DLL
398 */
399 struct RequestHandle *next;
400
401 /**
402 * DLL
403 */
404 struct RequestHandle *prev;
396 405
397 /** 406 /**
398 * Selected ego 407 * Selected ego
@@ -528,6 +537,16 @@ struct RequestHandle
528 int public_client; 537 int public_client;
529}; 538};
530 539
540/**
541 * DLL
542 */
543static struct RequestHandle *requests_head;
544
545/**
546 * DLL
547 */
548static struct RequestHandle *requests_tail;
549
531 550
532/** 551/**
533 * Cleanup lookup handle 552 * Cleanup lookup handle
@@ -573,18 +592,13 @@ cleanup_handle (struct RequestHandle *handle)
573 GNUNET_RECLAIM_attribute_list_destroy (handle->attr_userinfo_list); 592 GNUNET_RECLAIM_attribute_list_destroy (handle->attr_userinfo_list);
574 if (NULL!=handle->attests_list) 593 if (NULL!=handle->attests_list)
575 GNUNET_RECLAIM_attestation_list_destroy (handle->attests_list); 594 GNUNET_RECLAIM_attestation_list_destroy (handle->attests_list);
576 595 GNUNET_CONTAINER_DLL_remove (requests_head,
596 requests_tail,
597 handle);
577 GNUNET_free (handle); 598 GNUNET_free (handle);
578} 599}
579 600
580 601
581static void
582cleanup_handle_delayed (void *cls)
583{
584 cleanup_handle (cls);
585}
586
587
588/** 602/**
589 * Task run on error, sends error message. Cleans up everything. 603 * Task run on error, sends error message. Cleans up everything.
590 * 604 *
@@ -613,7 +627,7 @@ do_error (void *cls)
613 MHD_HTTP_HEADER_CONTENT_TYPE, 627 MHD_HTTP_HEADER_CONTENT_TYPE,
614 "application/json"); 628 "application/json");
615 handle->proc (handle->proc_cls, resp, handle->response_code); 629 handle->proc (handle->proc_cls, resp, handle->response_code);
616 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 630 cleanup_handle (handle);
617 GNUNET_free (json_error); 631 GNUNET_free (json_error);
618} 632}
619 633
@@ -640,7 +654,7 @@ do_userinfo_error (void *cls)
640 resp = GNUNET_REST_create_response (""); 654 resp = GNUNET_REST_create_response ("");
641 MHD_add_response_header (resp, MHD_HTTP_HEADER_WWW_AUTHENTICATE, "Bearer"); 655 MHD_add_response_header (resp, MHD_HTTP_HEADER_WWW_AUTHENTICATE, "Bearer");
642 handle->proc (handle->proc_cls, resp, handle->response_code); 656 handle->proc (handle->proc_cls, resp, handle->response_code);
643 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 657 cleanup_handle (handle);
644 GNUNET_free (error); 658 GNUNET_free (error);
645} 659}
646 660
@@ -667,7 +681,7 @@ do_redirect_error (void *cls)
667 resp = GNUNET_REST_create_response (""); 681 resp = GNUNET_REST_create_response ("");
668 MHD_add_response_header (resp, "Location", redirect); 682 MHD_add_response_header (resp, "Location", redirect);
669 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND); 683 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
670 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 684 cleanup_handle (handle);
671 GNUNET_free (redirect); 685 GNUNET_free (redirect);
672} 686}
673 687
@@ -897,7 +911,7 @@ login_redirect (void *cls)
897 } 911 }
898 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND); 912 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
899 GNUNET_free (new_redirect); 913 GNUNET_free (new_redirect);
900 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 914 cleanup_handle (handle);
901} 915}
902 916
903 917
@@ -974,7 +988,7 @@ oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
974 resp = GNUNET_REST_create_response (""); 988 resp = GNUNET_REST_create_response ("");
975 MHD_add_response_header (resp, "Location", redirect_uri); 989 MHD_add_response_header (resp, "Location", redirect_uri);
976 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND); 990 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
977 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 991 cleanup_handle (handle);
978 GNUNET_free (redirect_uri); 992 GNUNET_free (redirect_uri);
979 GNUNET_free (ticket_str); 993 GNUNET_free (ticket_str);
980 GNUNET_free (code_string); 994 GNUNET_free (code_string);
@@ -1337,7 +1351,7 @@ build_redirect (void *cls)
1337 resp = GNUNET_REST_create_response (""); 1351 resp = GNUNET_REST_create_response ("");
1338 MHD_add_response_header (resp, "Location", redirect_uri); 1352 MHD_add_response_header (resp, "Location", redirect_uri);
1339 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND); 1353 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
1340 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 1354 cleanup_handle (handle);
1341 GNUNET_free (redirect_uri); 1355 GNUNET_free (redirect_uri);
1342 return; 1356 return;
1343 } 1357 }
@@ -1714,7 +1728,7 @@ login_cont (struct GNUNET_REST_RequestHandle *con_handle,
1714 term_data); 1728 term_data);
1715 handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST); 1729 handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
1716 json_decref (root); 1730 json_decref (root);
1717 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 1731 cleanup_handle (handle);
1718 return; 1732 return;
1719 } 1733 }
1720 GNUNET_asprintf (&cookie, "Identity=%s", json_string_value (identity)); 1734 GNUNET_asprintf (&cookie, "Identity=%s", json_string_value (identity));
@@ -1744,7 +1758,7 @@ login_cont (struct GNUNET_REST_RequestHandle *con_handle,
1744 GNUNET_free (cookie); 1758 GNUNET_free (cookie);
1745 GNUNET_free (header_val); 1759 GNUNET_free (header_val);
1746 json_decref (root); 1760 json_decref (root);
1747 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 1761 cleanup_handle (handle);
1748} 1762}
1749 1763
1750 1764
@@ -2114,7 +2128,7 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2114 GNUNET_free (access_token); 2128 GNUNET_free (access_token);
2115 GNUNET_free (json_response); 2129 GNUNET_free (json_response);
2116 GNUNET_free (id_token); 2130 GNUNET_free (id_token);
2117 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 2131 cleanup_handle (handle);
2118} 2132}
2119 2133
2120 2134
@@ -2543,14 +2557,17 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
2543 handle->proc = proc; 2557 handle->proc = proc;
2544 handle->rest_handle = rest_handle; 2558 handle->rest_handle = rest_handle;
2545 handle->url = GNUNET_strdup (rest_handle->url); 2559 handle->url = GNUNET_strdup (rest_handle->url);
2560 handle->timeout_task =
2561 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);
2562 GNUNET_CONTAINER_DLL_insert (requests_head,
2563 requests_tail,
2564 handle);
2546 if (handle->url[strlen (handle->url) - 1] == '/') 2565 if (handle->url[strlen (handle->url) - 1] == '/')
2547 handle->url[strlen (handle->url) - 1] = '\0'; 2566 handle->url[strlen (handle->url) - 1] = '\0';
2548 if (GNUNET_NO == 2567 if (GNUNET_NO ==
2549 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) 2568 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
2550 return GNUNET_NO; 2569 return GNUNET_NO;
2551 2570
2552 handle->timeout_task =
2553 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);
2554 return GNUNET_YES; 2571 return GNUNET_YES;
2555} 2572}
2556 2573
@@ -2615,7 +2632,8 @@ libgnunet_plugin_rest_openid_connect_done (void *cls)
2615 struct EgoEntry *ego_entry; 2632 struct EgoEntry *ego_entry;
2616 2633
2617 plugin->cfg = NULL; 2634 plugin->cfg = NULL;
2618 2635 while (NULL != requests_head)
2636 cleanup_handle (requests_head);
2619 if (NULL != OIDC_cookie_jar_map) 2637 if (NULL != OIDC_cookie_jar_map)
2620 { 2638 {
2621 GNUNET_CONTAINER_multihashmap_iterate (OIDC_cookie_jar_map, 2639 GNUNET_CONTAINER_multihashmap_iterate (OIDC_cookie_jar_map,
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c
index 0aeb0647a..870baa7f3 100644
--- a/src/reclaim/plugin_rest_reclaim.c
+++ b/src/reclaim/plugin_rest_reclaim.c
@@ -154,6 +154,15 @@ struct EgoEntry
154 154
155struct RequestHandle 155struct RequestHandle
156{ 156{
157 /**
158 * DLL
159 */
160 struct RequestHandle *next;
161
162 /**
163 * DLL
164 */
165 struct RequestHandle *prev;
157 166
158 /** 167 /**
159 * Selected ego 168 * Selected ego
@@ -247,6 +256,17 @@ struct RequestHandle
247}; 256};
248 257
249/** 258/**
259 * DLL
260 */
261static struct RequestHandle *requests_head;
262
263/**
264 * DLL
265 */
266static struct RequestHandle *requests_tail;
267
268
269/**
250 * Cleanup lookup handle 270 * Cleanup lookup handle
251 * @param handle Handle to clean up 271 * @param handle Handle to clean up
252 */ 272 */
@@ -272,6 +292,9 @@ cleanup_handle (void *cls)
272 GNUNET_free (handle->emsg); 292 GNUNET_free (handle->emsg);
273 if (NULL != handle->attr_list) 293 if (NULL != handle->attr_list)
274 GNUNET_RECLAIM_attribute_list_destroy (handle->attr_list); 294 GNUNET_RECLAIM_attribute_list_destroy (handle->attr_list);
295 GNUNET_CONTAINER_DLL_remove (requests_head,
296 requests_tail,
297 handle);
275 GNUNET_free (handle); 298 GNUNET_free (handle);
276} 299}
277 300
@@ -296,7 +319,7 @@ do_error (void *cls)
296 resp = GNUNET_REST_create_response (json_error); 319 resp = GNUNET_REST_create_response (json_error);
297 MHD_add_response_header (resp, "Content-Type", "application/json"); 320 MHD_add_response_header (resp, "Content-Type", "application/json");
298 handle->proc (handle->proc_cls, resp, handle->response_code); 321 handle->proc (handle->proc_cls, resp, handle->response_code);
299 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); 322 cleanup_handle (handle);
300 GNUNET_free (json_error); 323 GNUNET_free (json_error);
301} 324}
302 325
@@ -319,7 +342,7 @@ do_timeout (void *cls)
319static void 342static void
320collect_error_cb (void *cls) 343collect_error_cb (void *cls)
321{ 344{
322 do_error (cls); 345 GNUNET_SCHEDULER_add_now (&do_error, cls);
323} 346}
324 347
325 348
@@ -329,6 +352,7 @@ finished_cont (void *cls, int32_t success, const char *emsg)
329 struct RequestHandle *handle = cls; 352 struct RequestHandle *handle = cls;
330 struct MHD_Response *resp; 353 struct MHD_Response *resp;
331 354
355 handle->idp_op = NULL;
332 resp = GNUNET_REST_create_response (emsg); 356 resp = GNUNET_REST_create_response (emsg);
333 MHD_add_response_header (resp, "Content-Type", "application/json"); 357 MHD_add_response_header (resp, "Content-Type", "application/json");
334 MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); 358 MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
@@ -1429,7 +1453,9 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
1429 handle->url[strlen (handle->url) - 1] = '\0'; 1453 handle->url[strlen (handle->url) - 1] = '\0';
1430 handle->timeout_task = 1454 handle->timeout_task =
1431 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); 1455 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);
1432 1456 GNUNET_CONTAINER_DLL_insert (requests_head,
1457 requests_tail,
1458 handle);
1433 if (GNUNET_NO == 1459 if (GNUNET_NO ==
1434 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) 1460 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
1435 { 1461 {
@@ -1489,10 +1515,13 @@ libgnunet_plugin_rest_reclaim_done (void *cls)
1489{ 1515{
1490 struct GNUNET_REST_Plugin *api = cls; 1516 struct GNUNET_REST_Plugin *api = cls;
1491 struct Plugin *plugin = api->cls; 1517 struct Plugin *plugin = api->cls;
1518 struct RequestHandle *request;
1492 struct EgoEntry *ego_entry; 1519 struct EgoEntry *ego_entry;
1493 struct EgoEntry *ego_tmp; 1520 struct EgoEntry *ego_tmp;
1494 1521
1495 plugin->cfg = NULL; 1522 plugin->cfg = NULL;
1523 while (NULL != (request = requests_head))
1524 do_error (request);
1496 if (NULL != idp) 1525 if (NULL != idp)
1497 GNUNET_RECLAIM_disconnect (idp); 1526 GNUNET_RECLAIM_disconnect (idp);
1498 if (NULL != identity_handle) 1527 if (NULL != identity_handle)