summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-07-27 14:14:07 +0200
committerChristian Grothoff <christian@grothoff.org>2020-07-27 14:14:40 +0200
commit022fba51d569826a376f517e5ee3302222e7470c (patch)
tree68f207fa39a6d9c9681768be3d460a1cc2202762
parentccdbc2a4526c5f8750cdce2180b4d5f481d264b4 (diff)
parent6fd44ff2ea8f86655ac6450efd88da85b48211cf (diff)
downloadexchange-022fba51d569826a376f517e5ee3302222e7470c.tar.gz
exchange-022fba51d569826a376f517e5ee3302222e7470c.tar.bz2
exchange-022fba51d569826a376f517e5ee3302222e7470c.zip
better fix
-rw-r--r--src/bank-lib/taler-bank-transfer.c4
-rw-r--r--src/include/taler_util.h9
-rw-r--r--src/util/payto.c39
-rw-r--r--src/util/test_payto.c11
4 files changed, 63 insertions, 0 deletions
diff --git a/src/bank-lib/taler-bank-transfer.c b/src/bank-lib/taler-bank-transfer.c
index aa501181..2793e532 100644
--- a/src/bank-lib/taler-bank-transfer.c
+++ b/src/bank-lib/taler-bank-transfer.c
@@ -409,6 +409,10 @@ execute_wire_transfer ()
GNUNET_SCHEDULER_shutdown ();
return;
}
+
+ // See if subject was given as a payto-parameter.
+ if (NULL == subject)
+ subject = TALER_payto_get_subject (credit_account);
if (NULL != subject)
{
if (GNUNET_OK !=
diff --git a/src/include/taler_util.h b/src/include/taler_util.h
index 22d7f7f2..1d1c01ea 100644
--- a/src/include/taler_util.h
+++ b/src/include/taler_util.h
@@ -297,6 +297,15 @@ TALER_payto_get_method (const char *payto_uri);
char *
TALER_xtalerbank_account_from_payto (const char *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);
/**
* Possible values for a binary filter.
diff --git a/src/util/payto.c b/src/util/payto.c
index 3540052c..4b2bbf4e 100644
--- a/src/util/payto.c
+++ b/src/util/payto.c
@@ -29,6 +29,45 @@
/**
+ * 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'.
* We return $METHOD.
diff --git a/src/util/test_payto.c b/src/util/test_payto.c
index 7dc2eb14..c809a039 100644
--- a/src/util/test_payto.c
+++ b/src/util/test_payto.c
@@ -22,6 +22,8 @@
#include "taler_util.h"
#define CHECK(a,b) do { \
+ GNUNET_assert (a != NULL); \
+ GNUNET_assert (b != NULL); \
if (0 != strcmp (a,b)) { \
GNUNET_break (0); \
fprintf (stderr, "Got %s, wanted %s\n", b, a); \
@@ -52,6 +54,15 @@ main (int argc,
"payto://x-taler-bank/localhost:1080/alice?subject=hello&amount=EUR:1");
CHECK ("alice",
r);
+
+ r = TALER_payto_get_subject (
+ "payto://x-taler-bank/localhost:1080/alice?subject=hello&amount=EUR:1");
+ CHECK ("hello",
+ r);
+
+ r = TALER_payto_get_subject (
+ "payto://x-taler-bank/localhost:1080/alice");
+ GNUNET_assert (r == NULL);
return 0;
}