summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2015-08-22 14:58:44 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2015-08-22 14:58:44 +0200
commit5c243a8c506ba3cf21d8258cc56f5cd8e00c710f (patch)
tree2f55ee30a3ec05a35638d57d1d84a75d3e235f45
parent7dc9d08969c61ea0e187f54bba58f3d98af63135 (diff)
util: absuri handle port separately
-rw-r--r--util.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/util.c b/util.c
index ab01132..5c86dd5 100644
--- a/util.c
+++ b/util.c
@@ -105,7 +105,7 @@ int
absuri(const char *link, const char *base, char *buf, size_t bufsiz)
{
struct uri ulink, ubase;
- char tmp[4096] = "", *p;
+ char tmp[4096] = "", *p, *port;
int r = -1, c;
size_t i;
@@ -117,13 +117,20 @@ absuri(const char *link, const char *base, char *buf, size_t bufsiz)
if (!ulink.host[0] && !ubase.host[0])
return -1;
- r = snprintf(tmp, sizeof(tmp), "%s://%s",
+ if (!strncmp(link, "//", 2))
+ port = "";
+ else
+ port = ulink.port[0] ? ulink.port : ubase.port[0] ? 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));
+ (ulink.host[0] ? ulink.host : ubase.host),
+ port[0] ? ":" : "",
+ port);
if (r == -1 || (size_t)r >= sizeof(tmp))
return -1;