From 865e5c2d9275ca56d57374e269d688652ca1b9c6 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 8 Feb 2024 20:31:39 +0100 Subject: implement TALER_payto_normalize for #8348 --- src/include/taler_util.h | 14 +++ src/util/payto.c | 236 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 250 insertions(+) (limited to 'src') diff --git a/src/include/taler_util.h b/src/include/taler_util.h index fc2316705..c2cfab606 100644 --- a/src/include/taler_util.h +++ b/src/include/taler_util.h @@ -499,6 +499,20 @@ char * TALER_payto_get_method (const char *payto_uri); +/** + * Normalize payto://-URI to make "strcmp()" sufficient + * to check if two payto-URIs refer to the same bank + * account. Removes optional arguments (everything after + * "?") and applies method-specific normalizations to + * the main part of the URI. + * + * @param input a payto://-URI + * @return normalized URI, or NULL if @a input was not well-formed + */ +char * +TALER_payto_normalize (const char *input); + + /** * Obtain the account name from a payto URL. * diff --git a/src/util/payto.c b/src/util/payto.c index 6b22a0092..21889377b 100644 --- a/src/util/payto.c +++ b/src/util/payto.c @@ -256,6 +256,242 @@ TALER_payto_get_receiver_name (const char *payto) } +/** + * Normalize "payto://x-taler-bank/$HOSTNAME/$USERNAME" + * URI in @a input. + * + * Converts to lower-case, except for $USERNAME which + * is case-sensitive. + * + * @param len number of bytes in @a input + * @param input input URL + * @return NULL on error, otherwise 0-terminated canonicalized URI. + */ +static char * +normalize_payto_x_taler_bank (size_t len, + const char input[static len]) +{ + char *res = GNUNET_malloc (len + 1); + unsigned int sc = 0; + + for (unsigned int i = 0; i 4) || + (sc < 3) ) + { + GNUNET_break (0); + return NULL; + } + have_bic = (4 == sc); + res = GNUNET_malloc (len + 1); + sc = 0; + for (unsigned int i = 0; i