aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/plugin_rest_openid_connect.c
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/plugin_rest_openid_connect.c
parent19fe8e8ff74a9639fc075f5d974a01a977e1196a (diff)
downloadgnunet-7648cde6cfb181f03df9e145a576430220234f5f.tar.gz
gnunet-7648cde6cfb181f03df9e145a576430220234f5f.zip
-improve request cleanup handling
Diffstat (limited to 'src/reclaim/plugin_rest_openid_connect.c')
-rw-r--r--src/reclaim/plugin_rest_openid_connect.c58
1 files changed, 38 insertions, 20 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,