diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2013-05-02 17:46:56 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2013-05-15 14:50:45 +0800 |
commit | d9a54dc81723f83a21e24aa362a7a356d266e942 (patch) | |
tree | b6c2130bd40d83d5d5eec22c18e7878d081b72ed | |
parent | 198c4e575e177ae5458238e7b474361506a6f302 (diff) | |
download | talos-petitboot-d9a54dc81723f83a21e24aa362a7a356d266e942.tar.gz talos-petitboot-d9a54dc81723f83a21e24aa362a7a356d266e942.zip |
lib/url: Add pb_url_to_string
Add a function to unparse a URL, to make comparisons in tests easy.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rw-r--r-- | lib/url/url.c | 13 | ||||
-rw-r--r-- | lib/url/url.h | 1 |
2 files changed, 9 insertions, 5 deletions
diff --git a/lib/url/url.c b/lib/url/url.c index 1e69774..42bd4a1 100644 --- a/lib/url/url.c +++ b/lib/url/url.c @@ -242,18 +242,21 @@ static bool is_url(const char *str) return strstr(str, "://") != NULL; } -static void pb_url_update_full(struct pb_url *url) +char *pb_url_to_string(struct pb_url *url) { const struct pb_scheme_info *scheme = pb_url_scheme_info(url->scheme); - assert(scheme); - talloc_free(url->full); - - url->full = talloc_asprintf(url, "%s://%s%s", scheme->str, + return talloc_asprintf(url, "%s://%s%s", scheme->str, scheme->has_host ? url->host : "", url->path); } +static void pb_url_update_full(struct pb_url *url) +{ + talloc_free(url->full); + url->full = pb_url_to_string(url); +} + static struct pb_url *pb_url_copy(void *ctx, const struct pb_url *url) { struct pb_url *new_url; diff --git a/lib/url/url.h b/lib/url/url.h index 40c1164..997cdcb 100644 --- a/lib/url/url.h +++ b/lib/url/url.h @@ -60,6 +60,7 @@ struct pb_url { struct pb_url *pb_url_parse(void *ctx, const char *url_str); struct pb_url *pb_url_join(void *ctx, const struct pb_url *url, const char *s); +char *pb_url_to_string(struct pb_url *url); const char *pb_url_scheme_name(enum pb_url_scheme scheme); |