make nsurl_defragment() API more obvious and remove duplicated parameter checking

This commit is contained in:
Vincent Sanders 2014-03-05 15:10:02 +00:00 committed by Vincent Sanders
parent 5c6a0eda3b
commit 20b3c40816
3 changed files with 17 additions and 21 deletions

View File

@ -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);
}
if (flags & LLCACHE_RETRIEVE_FORCE_FETCH || post != NULL) {
/* Create new object */

View File

@ -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)
/* Insert defragmented URL */
if (nsurl_defragment(url, &d->url) != NSERROR_OK)
return NULL;
} else {
d->url = nsurl_ref(url);
}
}
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);
}
scheme = nsurl_get_component(url, NSURL_SCHEME);
if (scheme == NULL) {

View File

@ -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) {