X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=lib%2Furl%2Furl.c;h=a2ca3a58d4a4273016012b351d228b18154208a3;hb=47038255f6ec971e8273c441066f8b1cba3380b7;hp=1e69774efb4e2a230d8cf24ca0dcd1973b699dcf;hpb=a8f70e4bb930253065a0596a3b1f4d7894b074a9;p=petitboot diff --git a/lib/url/url.c b/lib/url/url.c index 1e69774..a2ca3a5 100644 --- a/lib/url/url.c +++ b/lib/url/url.c @@ -20,9 +20,7 @@ #include "config.h" #endif -#define _GNU_SOURCE #include -#include #include #include "log/log.h" @@ -162,8 +160,6 @@ struct pb_url *pb_url_parse(void *ctx, const char *url_str) struct pb_url *url; const char *p; - pb_log("%s: '%s'\n", __func__, url_str); - if (!url_str || !*url_str) { assert(0 && "bad url"); return NULL; @@ -223,13 +219,6 @@ struct pb_url *pb_url_parse(void *ctx, const char *url_str) pb_url_parse_path(url); - pb_log(" scheme %d\n", url->scheme); - pb_log(" host '%s'\n", url->host); - pb_log(" port '%s'\n", url->port); - pb_log(" path '%s'\n", url->path); - pb_log(" dir '%s'\n", url->dir); - pb_log(" file '%s'\n", url->file); - return url; fail: @@ -237,36 +226,46 @@ fail: return NULL; } -static bool is_url(const char *str) +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); - + char *str, *port; assert(scheme); - talloc_free(url->full); + port = url->port ? talloc_asprintf(url, ":%s", url->port) : NULL; + + str = talloc_asprintf(url, "%s://%s%s%s", scheme->str, + scheme->has_host ? url->host : "", + port ?: "", url->path); - url->full = talloc_asprintf(url, "%s://%s%s", scheme->str, - scheme->has_host ? url->host : "", url->path); + talloc_free(port); + return str; +} + +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 *pb_url_copy(void *ctx, const struct pb_url *url) { struct pb_url *new_url; new_url = talloc(ctx, struct pb_url); new_url->scheme = url->scheme; - new_url->full = talloc_strdup(url, url->full); + new_url->full = talloc_strdup(new_url, url->full); - new_url->host = url->host ? talloc_strdup(url, url->host) : NULL; - new_url->port = url->port ? talloc_strdup(url, url->port) : NULL; - new_url->path = url->path ? talloc_strdup(url, url->path) : NULL; - new_url->dir = url->dir ? talloc_strdup(url, url->dir) : NULL; - new_url->file = url->file ? talloc_strdup(url, url->file) : NULL; + new_url->host = url->host ? talloc_strdup(new_url, url->host) : NULL; + new_url->port = url->port ? talloc_strdup(new_url, url->port) : NULL; + new_url->path = url->path ? talloc_strdup(new_url, url->path) : NULL; + new_url->dir = url->dir ? talloc_strdup(new_url, url->dir) : NULL; + new_url->file = url->file ? talloc_strdup(new_url, url->file) : NULL; return new_url; }