diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2017-01-22 16:11:24 +0000 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2017-02-08 17:27:13 +0000 |
commit | 3f5d8d1a2e844c8833eeb046fd7a84b72a3d3a1f (patch) | |
tree | 1b4908b8124fee0b70c22ed5102040ac438ea2b9 /utils/nsurl | |
parent | 5c8f4c9c8c98c0af71dfb2e41d8947a6edf09f47 (diff) | |
download | netsurf-3f5d8d1a2e844c8833eeb046fd7a84b72a3d3a1f.tar.gz netsurf-3f5d8d1a2e844c8833eeb046fd7a84b72a3d3a1f.tar.bz2 |
nsurl: Tidy up shared components code.
Diffstat (limited to 'utils/nsurl')
-rw-r--r-- | utils/nsurl/nsurl.c | 38 | ||||
-rw-r--r-- | utils/nsurl/parse.c | 43 | ||||
-rw-r--r-- | utils/nsurl/private.h | 37 |
3 files changed, 44 insertions, 74 deletions
diff --git a/utils/nsurl/nsurl.c b/utils/nsurl/nsurl.c index 68188fbdb..7166a2707 100644 --- a/utils/nsurl/nsurl.c +++ b/utils/nsurl/nsurl.c @@ -63,39 +63,6 @@ } -/** - * Destroy components - * - * \param c url components - */ -static void nsurl_destroy_components(struct nsurl_components *c) -{ - if (c->scheme) - lwc_string_unref(c->scheme); - - if (c->username) - lwc_string_unref(c->username); - - if (c->password) - lwc_string_unref(c->password); - - if (c->host) - lwc_string_unref(c->host); - - if (c->port) - lwc_string_unref(c->port); - - if (c->path) - lwc_string_unref(c->path); - - if (c->query) - lwc_string_unref(c->query); - - if (c->fragment) - lwc_string_unref(c->fragment); -} - - /****************************************************************************** * NetSurf URL Public API * @@ -126,7 +93,7 @@ void nsurl_unref(nsurl *url) #endif /* Release lwc strings */ - nsurl_destroy_components(&url->components); + nsurl__components_destroy(&url->components); /* Free the NetSurf URL */ free(url); @@ -219,7 +186,8 @@ nserror nsurl_get(const nsurl *url, nsurl_component parts, { assert(url != NULL); - return nsurl__string(&(url->components), parts, 0, url_s, url_l); + return nsurl__components_to_string(&(url->components), parts, 0, + url_s, url_l); } diff --git a/utils/nsurl/parse.c b/utils/nsurl/parse.c index 6ec02fc1e..89a10d244 100644 --- a/utils/nsurl/parse.c +++ b/utils/nsurl/parse.c @@ -1169,7 +1169,7 @@ static void nsurl__get_string(const struct nsurl_components *url, char *url_s, /* exported interface, documented in nsurl.h */ -nserror nsurl__string( +nserror nsurl__components_to_string( const struct nsurl_components *components, nsurl_component parts, size_t pre_padding, char **url_s_out, size_t *url_l_out) @@ -1239,39 +1239,6 @@ void nsurl__calc_hash(nsurl *url) } -/** - * Destroy components - * - * \param c url components - */ -static void nsurl_destroy_components(struct nsurl_components *c) -{ - if (c->scheme) - lwc_string_unref(c->scheme); - - if (c->username) - lwc_string_unref(c->username); - - if (c->password) - lwc_string_unref(c->password); - - if (c->host) - lwc_string_unref(c->host); - - if (c->port) - lwc_string_unref(c->port); - - if (c->path) - lwc_string_unref(c->path); - - if (c->query) - lwc_string_unref(c->query); - - if (c->fragment) - lwc_string_unref(c->fragment); -} - - /****************************************************************************** * NetSurf URL Public API * ******************************************************************************/ @@ -1314,7 +1281,7 @@ nserror nsurl_create(const char * const url_s, nsurl **url) free(buff); if (e != NSERROR_OK) { - nsurl_destroy_components(&c); + nsurl__components_destroy(&c); return NSERROR_NOMEM; } @@ -1325,12 +1292,12 @@ nserror nsurl_create(const char * const url_s, nsurl **url) &match) == lwc_error_ok && match == true)) { /* http, https must have host */ if (c.host == NULL) { - nsurl_destroy_components(&c); + nsurl__components_destroy(&c); return NSERROR_BAD_URL; } } - e = nsurl__string(&c, NSURL_WITH_FRAGMENT, + e = nsurl__components_to_string(&c, NSURL_WITH_FRAGMENT, sizeof(nsurl), (char **)url, &length); if (e != NSERROR_OK) { return e; @@ -1568,7 +1535,7 @@ nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined) return error; } - error = nsurl__string(&c, NSURL_WITH_FRAGMENT, + error = nsurl__components_to_string(&c, NSURL_WITH_FRAGMENT, sizeof(nsurl), (char **)joined, &length); if (error != NSERROR_OK) { return error; diff --git a/utils/nsurl/private.h b/utils/nsurl/private.h index 67945e2e7..e78f83042 100644 --- a/utils/nsurl/private.h +++ b/utils/nsurl/private.h @@ -128,7 +128,7 @@ enum nsurl_string_flags { * \param[out] url_l_out Returns byte length of string, excluding pre_padding. * \return NSERROR_OK on success, appropriate error otherwise. */ -nserror nsurl__string( +nserror nsurl__components_to_string( const struct nsurl_components *components, nsurl_component parts, size_t pre_padding, char **url_s_out, size_t *url_l_out); @@ -142,6 +142,41 @@ void nsurl__calc_hash(nsurl *url); + +/** + * Destroy components + * + * \param c url components + */ +static inline void nsurl__components_destroy(struct nsurl_components *c) +{ + if (c->scheme) + lwc_string_unref(c->scheme); + + if (c->username) + lwc_string_unref(c->username); + + if (c->password) + lwc_string_unref(c->password); + + if (c->host) + lwc_string_unref(c->host); + + if (c->port) + lwc_string_unref(c->port); + + if (c->path) + lwc_string_unref(c->path); + + if (c->query) + lwc_string_unref(c->query); + + if (c->fragment) + lwc_string_unref(c->fragment); +} + + + #ifdef NSURL_DEBUG /** * Dump a NetSurf URL's internal components |