summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2015-08-22 16:18:10 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2015-08-22 16:18:10 +0200
commit6d02ae93a30afe8492b176907c5cf11d0e639420 (patch)
tree4e17a77bf21964f1183a43e0b0518081fa1d64f3
parent6599b96752ddce0ce13b608faf64584109b0851c (diff)
util: absuri: simplify + fix port in url with prefix "//"
use the port specified in the link for urls starting with "//" (use protocol).
-rw-r--r--util.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/util.c b/util.c
index 5c86dd5..3253f64 100644
--- a/util.c
+++ b/util.c
@@ -105,30 +105,28 @@ int
absuri(const char *link, const char *base, char *buf, size_t bufsiz)
{
struct uri ulink, ubase;
- char tmp[4096] = "", *p, *port;
+ char tmp[4096], *host, *p, *port;
int r = -1, c;
size_t i;
buf[0] = '\0';
if (parseuri(base, &ubase, 0) == -1 ||
- parseuri(link, &ulink, 1) == -1)
+ parseuri(link, &ulink, 1) == -1 ||
+ (!ulink.host[0] && !ubase.host[0]))
return -1;
- if (!ulink.host[0] && !ubase.host[0])
- return -1;
-
- if (!strncmp(link, "//", 2))
- port = "";
- else
- port = ulink.port[0] ? ulink.port : ubase.port[0] ? ubase.port : "";
-
+ if (!strncmp(link, "//", 2)) {
+ host = ulink.host;
+ port = ulink.port;
+ } else {
+ host = ulink.host[0] ? ulink.host : ubase.host;
+ port = ulink.port[0] ? ulink.port : ubase.port;
+ }
r = snprintf(tmp, sizeof(tmp), "%s://%s%s%s",
ulink.proto[0] ?
ulink.proto :
(ubase.proto[0] ? ubase.proto : "http"),
- !strncmp(link, "//", 2) ?
- ulink.host :
- (ulink.host[0] ? ulink.host : ubase.host),
+ host,
port[0] ? ":" : "",
port);
if (r == -1 || (size_t)r >= sizeof(tmp))