From 2253e38be8cbcf4243e43fc0d317cfda08bffeb2 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Sat, 5 Apr 2003 21:38:06 +0000 Subject: [project @ 2003-04-05 21:38:06 by bursa] External stylesheets. svn path=/import/netsurf/; revision=115 --- utils/utils.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- utils/utils.h | 3 ++- 2 files changed, 59 insertions(+), 2 deletions(-) (limited to 'utils') diff --git a/utils/utils.c b/utils/utils.c index 8604d9ed4..47c90a4c0 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -1,11 +1,13 @@ /** - * $Id: utils.c,v 1.6 2003/02/09 12:58:15 bursa Exp $ + * $Id: utils.c,v 1.7 2003/04/05 21:38:06 bursa Exp $ */ #include #include #include #include +#include "libxml/uri.h" +#include "netsurf/utils/log.h" #include "netsurf/utils/utils.h" void die(const char * const error) @@ -96,3 +98,57 @@ char * squash_whitespace(const char * s) return c; } +char *url_join(const char* new, const char* base) +{ + char* ret; + int i; + + LOG(("new = %s, base = %s", new, base)); + + if (base == 0) + { + /* no base, so make an absolute URL */ + ret = xcalloc(strlen(new) + 10, sizeof(char)); + + /* check if a scheme is present */ + i = strspn(new, "abcdefghijklmnopqrstuvwxyz"); + if (new[i] == ':') + { + strcpy(ret, new); + i += 3; + } + else + { + strcpy(ret, "http://"); + strcat(ret, new); + i = 7; + } + + /* make server name lower case */ + for (; ret[i] != 0 && ret[i] != '/'; i++) + ret[i] = tolower(ret[i]); + + xmlNormalizeURIPath(ret + i); + + /* http://www.example.com -> http://www.example.com/ */ + if (ret[i] == 0) + { + ret[i] = '/'; + ret[i+1] = 0; + } + } + else + { + /* relative url */ + ret = xmlBuildURI(new, base); + } + + LOG(("ret = %s", ret)); + if (ret == NULL) + { + ret = xcalloc(strlen(new) + 10, sizeof(char)); + strcpy(ret, new); + } + return ret; +} + diff --git a/utils/utils.h b/utils/utils.h index 5ae167eb9..c55ab5b69 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -1,5 +1,5 @@ /** - * $Id: utils.h,v 1.5 2003/02/09 12:58:15 bursa Exp $ + * $Id: utils.h,v 1.6 2003/04/05 21:38:06 bursa Exp $ */ #ifndef _NETSURF_UTILS_UTILS_H_ @@ -16,5 +16,6 @@ void xfree(void* p); char * xstrdup(const char * const s); char * load(const char * const path); char * squash_whitespace(const char * s); +char *url_join(const char* new, const char* base); #endif -- cgit v1.2.3