aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-01-15 14:57:58 +0100
committerChristian Grothoff <christian@grothoff.org>2020-01-15 14:58:10 +0100
commitb37fff0d5b08926169633ce8822de7ac616ae169 (patch)
tree88be0f24a260f2e7037cabd60227584a5c7f6749 /src/util
parentd822035216d9ad33665a2f8274432918ca7d42be (diff)
ftbfs
Diffstat (limited to 'src/util')
-rw-r--r--src/util/test_payto.c7
-rw-r--r--src/util/util.c54
2 files changed, 61 insertions, 0 deletions
diff --git a/src/util/test_payto.c b/src/util/test_payto.c
index f0247f19b..28caac1ad 100644
--- a/src/util/test_payto.c
+++ b/src/util/test_payto.c
@@ -50,6 +50,9 @@ main (int argc,
"account");
CHECK ("payto://x-taler-bank/localhost/account",
r);
+ r = TALER_payto_xtalerbank_make2 ("https://localhost/account");
+ CHECK ("payto://x-taler-bank/localhost/account",
+ r);
r = TALER_payto_xtalerbank_make ("http://localhost:80/",
"account");
CHECK ("payto://x-taler-bank/localhost:80/account",
@@ -60,6 +63,10 @@ main (int argc,
r);
r = TALER_payto_xtalerbank_make ("http://localhost/",
"account");
+ r = TALER_payto_xtalerbank_make2 ("http://localhost:80/account");
+ CHECK ("payto://x-taler-bank/localhost:80/account",
+ r);
+ r = TALER_payto_xtalerbank_make2 ("http://localhost/account");
CHECK ("payto://x-taler-bank/localhost:80/account",
r);
r = TALER_xtalerbank_base_url_from_payto (
diff --git a/src/util/util.c b/src/util/util.c
index 7f5e60e4d..761aa98dd 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -624,6 +624,60 @@ TALER_payto_xtalerbank_make (const char *bank_url,
/**
+ * Create an x-taler-bank payto:// URL from an @a account_url.
+ *
+ * @param account_url the bank URL
+ * @param account_name the account name
+ * @return payto:// URL
+ */
+char *
+TALER_payto_xtalerbank_make2 (const char *account_url)
+{
+ char *payto;
+ int plaintext;
+ const char *port;
+ size_t slen;
+ const char *account;
+
+ if (0 == strncasecmp ("https://",
+ account_url,
+ strlen ("https://")))
+ {
+ account_url += strlen ("https://");
+ plaintext = GNUNET_NO;
+ }
+ else if (0 == strncasecmp ("http://",
+ account_url,
+ strlen ("http://")))
+ {
+ account_url += strlen ("http://");
+ plaintext = GNUNET_YES;
+ }
+ else
+ return NULL;
+ account = strchr (account_url,
+ '/');
+ if (NULL == account)
+ return NULL;
+ slen = account - account_url;
+ port = memchr (account_url,
+ ':',
+ slen);
+ if ( (0 < slen) &&
+ ('/' == account_url[slen - 1]) )
+ slen--;
+ GNUNET_asprintf (&payto,
+ ( (NULL == port) && (GNUNET_YES == plaintext) )
+ ? "payto://x-taler-bank/%.*s:80/%s"
+ : "payto://x-taler-bank/%.*s/%s",
+ (int) slen,
+ account_url,
+ account + 1);
+ return payto;
+}
+
+
+/**
* Given an x-taler-bank payto:// URL, compute
* the HTTP(S) base URL of the account.
*