From c80eee722ed94e9c40f042f6e6404af059347f97 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 27 Aug 2021 18:18:32 +0200 Subject: -fix IBAN notification logic --- .../anastasis-helper-authorization-iban.c | 89 ++++++++++++---------- .../anastasis_authorization_plugin_iban.c | 4 + src/backend/anastasis-httpd_truth.c | 11 ++- 3 files changed, 59 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/authorization/anastasis-helper-authorization-iban.c b/src/authorization/anastasis-helper-authorization-iban.c index 012780d..04dfa03 100644 --- a/src/authorization/anastasis-helper-authorization-iban.c +++ b/src/authorization/anastasis-helper-authorization-iban.c @@ -104,6 +104,44 @@ static int test_mode; static struct GNUNET_SCHEDULER_Task *task; +#include "iban.c" + +/** + * Extract IBAN from a payto URI. + * + * @return NULL on error + */ +static char * +payto_get_iban (const char *payto_uri) +{ + const char *start; + const char *q; + const char *bic_end; + + if (0 != + strncasecmp (payto_uri, + "payto://iban/", + strlen ("payto://iban/"))) + return NULL; + start = &payto_uri[strlen ("payto://iban/")]; + q = strchr (start, + '?'); + bic_end = strchr (start, + '/'); + if ( (NULL != q) && + (NULL != bic_end) && + (bic_end < q) ) + start = bic_end + 1; + if ( (NULL == q) && + (NULL != bic_end) ) + start = bic_end + 1; + if (NULL == q) + return GNUNET_strdup (start); + return GNUNET_strndup (start, + q - start); +} + + /** * Notify anastasis-http that we received @a amount * from @a sender_account_uri with @a code. @@ -123,10 +161,17 @@ notify (const char *sender_account_uri, .code = GNUNET_htonll (code) }; const char *as; - - GNUNET_CRYPTO_hash (sender_account_uri, - strlen (sender_account_uri), + char *iban; + + iban = payto_get_iban (sender_account_uri); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Generating events for code %llu from %s\n", + (unsigned long long) code, + iban); + GNUNET_CRYPTO_hash (iban, + strlen (iban), &ev.debit_iban_hash); + GNUNET_free (iban); as = TALER_amount2s (amount); db_plugin->event_notify (db_plugin->cls, &ev.header, @@ -180,44 +225,6 @@ static void find_transfers (void *cls); -#include "iban.c" - -/** - * Extract IBAN from a payto URI. - * - * @return NULL on error - */ -static char * -payto_get_iban (const char *payto_uri) -{ - const char *start; - const char *q; - const char *bic_end; - - if (0 != - strncasecmp (payto_uri, - "payto://iban/", - strlen ("payto://iban/"))) - return NULL; - start = &payto_uri[strlen ("payto://iban/")]; - q = strchr (start, - '?'); - bic_end = strchr (start, - '/'); - if ( (NULL != q) && - (NULL != bic_end) && - (bic_end < q) ) - start = bic_end + 1; - if ( (NULL == q) && - (NULL != bic_end) ) - start = bic_end + 1; - if (NULL == q) - return GNUNET_strdup (start); - return GNUNET_strndup (start, - q - start); -} - - /** * Callbacks of this type are used to serve the result of asking * the bank for the transaction history. diff --git a/src/authorization/anastasis_authorization_plugin_iban.c b/src/authorization/anastasis_authorization_plugin_iban.c index cdd51a7..7717770 100644 --- a/src/authorization/anastasis_authorization_plugin_iban.c +++ b/src/authorization/anastasis_authorization_plugin_iban.c @@ -530,6 +530,10 @@ iban_process (struct ANASTASIS_AUTHORIZATION_State *as, .code = GNUNET_htonll (as->code) }; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Subscribing to events for code %llu from %s\n", + (unsigned long long) as->code, + as->iban_number); GNUNET_CRYPTO_hash (as->iban_number, strlen (as->iban_number), &espec.debit_iban_hash); diff --git a/src/backend/anastasis-httpd_truth.c b/src/backend/anastasis-httpd_truth.c index 613e27f..4853e15 100644 --- a/src/backend/anastasis-httpd_truth.c +++ b/src/backend/anastasis-httpd_truth.c @@ -316,8 +316,8 @@ AH_truth_shutdown (void) } if (gc->suspended) { - MHD_resume_connection (gc->connection); gc->suspended = false; + MHD_resume_connection (gc->connection); } if (NULL != gc->as) { @@ -576,8 +576,8 @@ proposal_cb (void *cls, gc); gc->in_list = false; GNUNET_assert (gc->suspended); - MHD_resume_connection (gc->connection); gc->suspended = false; + MHD_resume_connection (gc->connection); AH_trigger_daemon (NULL); if (MHD_HTTP_OK != por->hr.http_status) { @@ -641,8 +641,8 @@ check_payment_cb (void *cls, gc); gc->in_list = false; GNUNET_assert (gc->suspended); - MHD_resume_connection (gc->connection); gc->suspended = false; + MHD_resume_connection (gc->connection); AH_trigger_daemon (NULL); switch (hr->http_status) @@ -895,6 +895,7 @@ run_authorization_process (struct MHD_Connection *connection, enum ANASTASIS_AUTHORIZATION_Result ret; enum GNUNET_DB_QueryStatus qs; + GNUNET_assert (! gc->suspended); ret = gc->authorization->process (gc->as, gc->timeout, connection); @@ -922,13 +923,13 @@ run_authorization_process (struct MHD_Connection *connection, return MHD_YES; case ANASTASIS_AUTHORIZATION_RES_SUSPENDED: /* connection was suspended */ + gc->suspended = true; if (NULL == AH_to_heap) AH_to_heap = GNUNET_CONTAINER_heap_create ( GNUNET_CONTAINER_HEAP_ORDER_MIN); gc->hn = GNUNET_CONTAINER_heap_insert (AH_to_heap, gc, gc->timeout.abs_value_us); - gc->suspended = true; if (NULL != to_task) { GNUNET_SCHEDULER_cancel (to_task); @@ -1135,6 +1136,7 @@ AH_handler_truth_get ( GNUNET_assert (NULL != gc->authorization); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Continuing with running the authorization process\n"); + GNUNET_assert (! gc->suspended); return run_authorization_process (connection, gc); @@ -1547,6 +1549,7 @@ AH_handler_truth_get ( GNUNET_CONTAINER_DLL_insert (gc_head, gc_tail, gc); + GNUNET_assert (! gc->suspended); return run_authorization_process (connection, gc); } -- cgit v1.2.3