From 7c2de4c5e6b7b1184d059057e1d412d6f0133816 Mon Sep 17 00:00:00 2001 From: MS Date: Mon, 27 Jul 2020 12:48:48 +0200 Subject: payto parser: extract 'subject' parameter. --- src/util/payto.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/util/payto.c') diff --git a/src/util/payto.c b/src/util/payto.c index 3540052c1..4b2bbf4e3 100644 --- a/src/util/payto.c +++ b/src/util/payto.c @@ -28,6 +28,45 @@ #define PAYTO "payto://" +/** + * Extract the subject value from the URI parameters. + * + * @param payto_uri the URL to parse + * @return NULL if the subject parameter is not found. + * The caller should free the returned value. + */ +char * +TALER_payto_get_subject (const char *payto_uri) +{ + const char *key; + const char *value_start; + const char *value_end; + + key = strchr (payto_uri, + (unsigned char) '?'); + if (NULL == key) + return NULL; + + do { + if (0 == strncasecmp (++key, + "subject", + strlen ("subject"))) + { + value_start = strchr (key, + (unsigned char) '='); + if (NULL == value_start) + return NULL; + value_end = strchrnul (value_start, + (unsigned char) '&'); + + return GNUNET_strndup (value_start + 1, + value_end - value_start - 1); + } + } while ( (key = strchr (key, + (unsigned char) '&')) ); + return NULL; +} + /** * Obtain the payment method from a @a payto_uri. The * format of a payto URI is 'payto://$METHOD/$SOMETHING'. -- cgit v1.2.3