From d9a54dc81723f83a21e24aa362a7a356d266e942 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Thu, 2 May 2013 17:46:56 +0800 Subject: [PATCH] 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 --- lib/url/url.c | 13 ++++++++----- 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); -- 2.39.2