lib/url: Include port in pb_url_to_string()
[petitboot] / lib / url / url.c
index 44e9ac403b7daa4c9e04ad549b4f45b4cc3e661b..b74018ddd0f300f4d8ca7d2efffa3fc3451e85fe 100644 (file)
@@ -265,14 +265,21 @@ int addr_scheme(const char *address)
 char *pb_url_to_string(struct pb_url *url)
 {
        const struct pb_scheme_info *scheme = pb_url_scheme_info(url->scheme);
+       char *str, *port;
        assert(scheme);
 
+       port = url->port ? talloc_asprintf(url, ":%s", url->port) : NULL;
+
        if (scheme->has_host && addr_scheme(url->host) == AF_INET6)
-               return talloc_asprintf(url, "%s://[%s]%s", scheme->str,
-                               url->host, url->path);
+               str = talloc_asprintf(url, "%s://[%s]%s%s", scheme->str,
+                               url->host, port ?: "", url->path);
        else
-               return talloc_asprintf(url, "%s://%s%s", scheme->str,
-                               scheme->has_host ? url->host : "", url->path);
+               str = talloc_asprintf(url, "%s://%s%s%s", scheme->str,
+                               scheme->has_host ? url->host : "",
+                               port ?: "", url->path);
+
+       talloc_free(port);
+       return str;
 }
 
 static void pb_url_update_full(struct pb_url *url)