commit 3e8115c5e4a2c9a7f37202c63f107230d8087c42
parent ab267651d6dd065b16f2d38fb6651e9db368a9e9
Author: Christian Grothoff <christian@grothoff.org>
Date: Wed, 12 Apr 2023 15:58:55 +0200
implement wire subject parser
Diffstat:
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/src/backend/taler-merchant-wirewatch.c b/src/backend/taler-merchant-wirewatch.c
@@ -178,7 +178,8 @@ shutdown_task (void *cls)
/**
* Parse @a subject from wire transfer into @a wtid and @a exchange_url.
*
- * @param subject wire transfer subject to parse
+ * @param subject wire transfer subject to parse;
+ * format is "$WTID $URL"
* @param[out] wtid wire transfer ID to extract
* @param[out] exchange_url set to exchange URL
* @return #GNUNET_OK on success
@@ -188,8 +189,29 @@ parse_subject (const char *subject,
struct TALER_WireTransferIdentifierRawP *wtid,
char **exchange_url)
{
- *exchange_url = NULL;
- return GNUNET_SYSERR;
+ const char *space;
+
+ space = strchr (subject, ' ');
+ if (NULL == space)
+ return GNUNET_NO;
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (subject,
+ space - subject,
+ wtid,
+ sizeof (*wtid)))
+ return GNUNET_NO;
+ space++;
+ if (! TALER_url_valid_charset (space))
+ return GNUNET_NO;
+ if ( (0 != strncasecmp ("http://",
+ space,
+ strlen ("http://"))) &&
+ (0 != strncasecmp ("https://",
+ space,
+ strlen ("https://"))) )
+ return GNUNET_NO;
+ *exchange_url = GNUNET_strdup (space);
+ return GNUNET_OK;
}