From f1b59814f8da2f3e235d47adfb332edf8a093b31 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Fri, 26 Dec 2003 00:17:55 +0000 Subject: [project @ 2003-12-26 00:17:55 by bursa] New url_join using liburi, . svn path=/import/netsurf/; revision=441 --- utils/utils.c | 136 +++++++++++++++++++++------------------------------------- 1 file changed, 49 insertions(+), 87 deletions(-) (limited to 'utils/utils.c') diff --git a/utils/utils.c b/utils/utils.c index 004fa3fa7..1487ac1c7 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "libxml/encoding.h" #include "libxml/uri.h" #include "netsurf/utils/log.h" @@ -165,98 +166,59 @@ char *squash_tolat1(xmlChar *s) return squash; } -char *url_join(const char* new, const char* base) + +/** + * Calculate a URL from a relative and base URL. + * + * base may be 0 for a new URL, in which case the URL is cannonicalized and + * returned. Returns 0 in case of error. + */ + +char *url_join(char *rel_url, char *base_url) { - char* ret, *nn; - int i,j,k; - - LOG(("new = %s, base = %s", new, base)); - - /* deal with spaces and quotation marks in URLs etc. - also removes spaces from end of links. - There's definitely a better way to do this */ - nn = xcalloc(strlen(new) * 3 + 40, sizeof(char)); - j=0; - for(i=0;i http://www.example.com/ */ - if (ret[i] == 0) - { - ret[i] = '/'; - ret[i+1] = 0; - } - } - else - { - /* relative url */ - ret = xmlBuildURI(new, base); - } + base = uri_alloc(base_url, strlen(base_url)); + rel = uri_alloc(rel_url, strlen(rel_url)); + if (!base || !rel) + goto fail; + if (!base->scheme) + goto fail; - LOG(("ret = %s", ret)); - if (ret == NULL) - { - ret = xcalloc(strlen(new) + 10, sizeof(char)); - strcpy(ret, new); - } + abs = uri_abs_1(base, rel); + + res = xstrdup(uri_uri(abs)); + + uri_free(base); + uri_free(rel); + + LOG(("res = %s", res)); + return res; + +fail: + if (base) + uri_free(base); + if (rel) + uri_free(rel); + + LOG(("error")); - xfree(nn); - return ret; + return 0; } + + char *get_host_from_url (char *url) { -- cgit v1.2.3