From 4547bfb318bfad96b12694dd93a50f50717478b6 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 15 Jan 2020 11:48:41 +0100 Subject: fix fakebank account vs. full payto confusion --- src/util/test_payto.c | 8 ++++++++ src/util/util.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) (limited to 'src/util') diff --git a/src/util/test_payto.c b/src/util/test_payto.c index 0a570ee5a..f0247f19b 100644 --- a/src/util/test_payto.c +++ b/src/util/test_payto.c @@ -78,6 +78,14 @@ main (int argc, "payto://x-taler-bank/localhost:1080/alice"); CHECK ("http://localhost:1080/alice", r); + r = TALER_xtalerbank_account_from_payto ( + "payto://x-taler-bank/localhost:1080/alice"); + CHECK ("alice", + r); + r = TALER_xtalerbank_account_from_payto ( + "payto://x-taler-bank/localhost:1080/alice?subject=hello&amount=EUR:1"); + CHECK ("alice", + r); return 0; } diff --git a/src/util/util.c b/src/util/util.c index 531bd27f5..7f5e60e4d 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -710,4 +710,35 @@ TALER_xtalerbank_account_url_from_payto (const char *payto) } +/** + * Obtain the account name from a payto URL. + * + * @param payto an x-taler-bank payto URL + * @return only the account name from the @a payto URL, NULL if not an x-taler-bank + * payto URL + */ +char * +TALER_xtalerbank_account_from_payto (const char *payto) +{ + const char *beg; + const char *end; + + if (0 != strncasecmp (payto, + "payto://x-taler-bank/", + strlen ("payto://x-taler-bank/"))) + return NULL; + beg = strchr (&payto[strlen ("payto://x-taler-bank/")], + '/'); + if (NULL == beg) + return NULL; + beg++; + end = strchr (beg, + '?'); + if (NULL == end) + return GNUNET_strdup (beg); + return GNUNET_strndup (beg, + end - beg); +} + + /* end of util.c */ -- cgit v1.2.3