aboutsummaryrefslogtreecommitdiff
path: root/src/util/util.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-01-14 23:54:43 +0100
committerChristian Grothoff <christian@grothoff.org>2020-01-14 23:54:43 +0100
commit1d9049ab9963b69a6716943109ec0a7458135d1a (patch)
tree086df02d8bf9fa707f0cd5c36b22c094c84ce5f7 /src/util/util.c
parent2edee5ac4a4886e71db6e28314334cd24c6d3a55 (diff)
add payto URL test, fix payto parser implementation
Diffstat (limited to 'src/util/util.c')
-rw-r--r--src/util/util.c89
1 files changed, 70 insertions, 19 deletions
diff --git a/src/util/util.c b/src/util/util.c
index 62f733a17..5a06a1229 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -789,16 +789,38 @@ TALER_payto_xtalerbank_make (const char *bank_url,
const char *account_name)
{
char *payto;
- int ends_slash;
+ int plaintext;
+ const char *port;
+ size_t slen;
- if (0 < strlen (bank_url))
- ends_slash = '/' == bank_url[strlen (bank_url) - 1];
+ if (0 == strncasecmp ("https://",
+ bank_url,
+ strlen ("https://")))
+ {
+ bank_url += strlen ("https://");
+ plaintext = GNUNET_NO;
+ }
+ else if (0 == strncasecmp ("http://",
+ bank_url,
+ strlen ("http://")))
+ {
+ bank_url += strlen ("http://");
+ plaintext = GNUNET_YES;
+ }
else
- ends_slash = 0;
+ return NULL;
+ slen = strlen (bank_url);
+ port = memchr (bank_url,
+ ':',
+ slen);
+ if ( (0 < slen) &&
+ ('/' == bank_url[slen - 1]) )
+ slen--;
GNUNET_asprintf (&payto,
- (ends_slash)
- ? "payto://x-taler-bank/%s%s"
- : "payto://x-taler-bank/%s/%s",
+ ( (NULL == port) && (GNUNET_YES == plaintext) )
+ ? "payto://x-taler-bank/%.*s:80/%s"
+ : "payto://x-taler-bank/%.*s/%s",
+ (int) slen,
bank_url,
account_name);
return payto;
@@ -817,20 +839,35 @@ TALER_xtalerbank_base_url_from_payto (const char *payto)
{
const char *start;
const char *end;
+ char *ret;
+ int https;
+ const char *colon;
+ unsigned int port;
if (0 != strncasecmp (payto,
"payto://x-taler-bank/",
strlen ("payto://x-taler-bank/")))
- {
return NULL;
- }
- start = &payto [strlen ("payto://x-taler-bank/")];
+ start = &payto[strlen ("payto://x-taler-bank/")];
end = strchr (start,
- (unsigned char) '/');
+ '/');
if (NULL == end)
end = &start[strlen (start)];
- return GNUNET_strndup (start,
- end - start);
+ colon = strrchr (start,
+ ':');
+ https = GNUNET_YES;
+ if ( (NULL != colon) &&
+ (1 == sscanf (colon + 1,
+ "%u",
+ &port)) &&
+ (443 != port) )
+ https = GNUNET_NO;
+ GNUNET_asprintf (&ret,
+ "%s://%.*s/",
+ (https ? "https" : "http"),
+ (int) (end - start),
+ start);
+ return ret;
}
@@ -846,20 +883,34 @@ TALER_xtalerbank_account_url_from_payto (const char *payto)
{
const char *start;
const char *end;
+ char *ret;
+ int https;
+ const char *colon;
+ unsigned int port;
if (0 != strncasecmp (payto,
"payto://x-taler-bank/",
strlen ("payto://x-taler-bank/")))
- {
return NULL;
- }
- start = &payto [strlen ("payto://x-taler-bank/")];
+ start = &payto[strlen ("payto://x-taler-bank/")];
end = strchr (start,
- (unsigned char) '?');
+ '/');
if (NULL == end)
end = &start[strlen (start)];
- return GNUNET_strndup (start,
- end - start);
+ colon = strrchr (start,
+ ':');
+ https = GNUNET_YES;
+ if ( (NULL != colon) &&
+ (1 == sscanf (colon + 1,
+ "%u",
+ &port)) &&
+ (443 != port) )
+ https = GNUNET_NO;
+ GNUNET_asprintf (&ret,
+ "%s://%s",
+ (https ? "https" : "http"),
+ start);
+ return ret;
}