From 20b3c408167b2093f1d2d68792550ff6ec44aabd Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 5 Mar 2014 15:10:02 +0000 Subject: [PATCH] make nsurl_defragment() API more obvious and remove duplicated parameter checking --- content/llcache.c | 10 +++------- content/urldb.c | 19 +++++-------------- utils/nsurl.c | 9 +++++++++ 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/content/llcache.c b/content/llcache.c index bd7ae937e..a6e46bf29 100644 --- a/content/llcache.c +++ b/content/llcache.c @@ -1098,13 +1098,9 @@ static nserror llcache_object_retrieve(nsurl *url, uint32_t flags, has_query = nsurl_has_component(url, NSURL_QUERY); /* Get rid of any url fragment */ - if (nsurl_has_component(url, NSURL_FRAGMENT)) { - error = nsurl_defragment(url, &defragmented_url); - if (error != NSERROR_OK) - return error; - } else { - defragmented_url = nsurl_ref(url); - } + error = nsurl_defragment(url, &defragmented_url); + if (error != NSERROR_OK) + return error; if (flags & LLCACHE_RETRIEVE_FORCE_FETCH || post != NULL) { /* Create new object */ diff --git a/content/urldb.c b/content/urldb.c index f55a1c291..1e17ac575 100644 --- a/content/urldb.c +++ b/content/urldb.c @@ -1806,14 +1806,9 @@ struct path_data *urldb_add_path(lwc_string *scheme, unsigned int port, free(path_query); if (d && !d->url) { - /* Insert URL */ - if (nsurl_has_component(url, NSURL_FRAGMENT)) { - nserror err = nsurl_defragment(url, &d->url); - if (err != NSERROR_OK) - return NULL; - } else { - d->url = nsurl_ref(url); - } + /* Insert defragmented URL */ + if (nsurl_defragment(url, &d->url) != NSERROR_OK) + return NULL; } return d; @@ -2728,12 +2723,8 @@ bool urldb_set_cookie(const char *header, nsurl *url, nsurl *referer) assert(url && header); /* Get defragmented URL, as 'urlt' */ - if (nsurl_has_component(url, NSURL_FRAGMENT)) { - if (nsurl_defragment(url, &urlt) != NSERROR_OK) - return NULL; - } else { - urlt = nsurl_ref(url); - } + if (nsurl_defragment(url, &urlt) != NSERROR_OK) + return NULL; scheme = nsurl_get_component(url, NSURL_SCHEME); if (scheme == NULL) { diff --git a/utils/nsurl.c b/utils/nsurl.c index ae0c4829b..c99b0d34a 100644 --- a/utils/nsurl.c +++ b/utils/nsurl.c @@ -1911,6 +1911,15 @@ nserror nsurl_defragment(const nsurl *url, nsurl **no_frag) size_t length; char *pos; + /* check for source url having no fragment already */ + if (url->components.fragment == NULL) { + *no_frag = (nsurl *)url; + + (*no_frag)->count++; + + return NSERROR_OK; + } + /* Find the change in length from url to new_url */ length = url->length; if (url->components.fragment != NULL) {