From f00d029affb0a1e27fb6c0d0aae279bc165c2bf4 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 24 Aug 2021 22:29:30 +0200 Subject: IBAN test passes --- .../anastasis-helper-authorization-iban.c | 121 +++++++++++---------- 1 file changed, 64 insertions(+), 57 deletions(-) (limited to 'src/authorization/anastasis-helper-authorization-iban.c') diff --git a/src/authorization/anastasis-helper-authorization-iban.c b/src/authorization/anastasis-helper-authorization-iban.c index 4a14d05..012780d 100644 --- a/src/authorization/anastasis-helper-authorization-iban.c +++ b/src/authorization/anastasis-helper-authorization-iban.c @@ -46,9 +46,9 @@ static struct ANASTASIS_EUFIN_AuthenticationData auth; /** - * Bank account payto://-URI this process is monitoring. + * Bank account IBAN this process is monitoring. */ -static char *credit_account_uri; +static char *iban; /** * Active request for history. @@ -182,6 +182,41 @@ 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 @@ -240,13 +275,20 @@ history_cb (void *cls, "Adding wire transfer over %s with (hashed) subject `%s'\n", TALER_amount2s (&details->amount), details->wire_subject); - qs = db_plugin->record_auth_iban_payment (db_plugin->cls, - serial_id, - details->wire_subject, - &details->amount, - details->debit_account_uri, - credit_account_uri, - details->execution_date); + { + char *dcanon = payto_get_iban (details->debit_account_uri); + char *ccanon = payto_get_iban (details->credit_account_uri); + + qs = db_plugin->record_auth_iban_payment (db_plugin->cls, + serial_id, + details->wire_subject, + &details->amount, + dcanon, + ccanon, + details->execution_date); + GNUNET_free (ccanon); + GNUNET_free (dcanon); + } switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -340,54 +382,19 @@ run (void *cls, global_ret = EXIT_NOTCONFIGURED; return; } + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + "authorization-iban", + "CREDIT_IBAN", + &iban)) { - char *iban; - char *receiver_name; - - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, - "authorization-iban", - "CREDIT_IBAN", - &iban)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "authorization-iban", - "CREDIT_IBAN"); - global_ret = EXIT_NOTCONFIGURED; - ANASTASIS_DB_plugin_unload (db_plugin); - db_plugin = NULL; - return; - } - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, - "authorization-iban", - "BUSINESS_NAME", - &receiver_name)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "authorization-iban", - "BUSINESS_NAME"); - global_ret = EXIT_NOTCONFIGURED; - ANASTASIS_DB_plugin_unload (db_plugin); - db_plugin = NULL; - return; - } - { - size_t len; - char *uri_receiver_name; - - len = GNUNET_STRINGS_urlencode (receiver_name, - strlen (receiver_name), - &uri_receiver_name); - GNUNET_assert (uri_receiver_name[len] == '\0'); - GNUNET_asprintf (&credit_account_uri, - "payto://iban/%s?receiver-name=%s", - iban, - uri_receiver_name); - GNUNET_free (uri_receiver_name); - } - GNUNET_free (iban); - GNUNET_free (receiver_name); + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "authorization-iban", + "CREDIT_IBAN"); + global_ret = EXIT_NOTCONFIGURED; + ANASTASIS_DB_plugin_unload (db_plugin); + db_plugin = NULL; + return; } if (GNUNET_OK != @@ -406,7 +413,7 @@ run (void *cls, enum GNUNET_DB_QueryStatus qs; qs = db_plugin->get_last_auth_iban_payment_row (db_plugin->cls, - credit_account_uri, + iban, &latest_row_off); if (qs < 0) { -- cgit v1.2.3