From 668dfb4884f2e50b28b3f91629933cb108936214 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Wed, 25 Dec 2002 21:38:45 +0000 Subject: [project @ 2002-12-25 21:36:29 by bursa] Changes to url handling. svn path=/import/netsurf/; revision=55 --- desktop/browser.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- desktop/fetch.c | 38 ++++++-------------------------------- 2 files changed, 58 insertions(+), 33 deletions(-) (limited to 'desktop') diff --git a/desktop/browser.c b/desktop/browser.c index 8ff634fae..1a507d65a 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -1,5 +1,5 @@ /** - * $Id: browser.c,v 1.11 2002/12/25 20:17:18 bursa Exp $ + * $Id: browser.c,v 1.13 2002/12/25 21:38:45 bursa Exp $ */ #include "netsurf/riscos/font.h" @@ -10,11 +10,13 @@ #include "netsurf/render/utils.h" #include "netsurf/desktop/cache.h" #include "netsurf/utils/log.h" +#include "libxml/uri.h" #include #include #include #include #include +#include struct box_selection { @@ -440,6 +442,7 @@ void browser_window_open_location(struct browser_window* bw, char* url) { LOG(("bw = %p, url = %s", bw, url)); assert(bw != 0 && url != 0); + url = url_join(url, bw->url); browser_window_open_location_historical(bw, url); if (bw->history == NULL) bw->history = history_create(NULL, url); @@ -448,6 +451,7 @@ void browser_window_open_location(struct browser_window* bw, char* url) history_remember(bw->history, NULL, url); bw->history = bw->history->later; } + xfree(url); LOG(("end")); } @@ -938,3 +942,50 @@ void browser_window_redraw_boxes(struct browser_window* bw, struct box_position* gui_window_redraw(bw->window, redraw_min_x, redraw_min_y, redraw_max_x, redraw_max_y); } + +char *url_join(const char* new, const char* base) +{ + xmlURI* uri; + char* ret; + int i; + + LOG(("new = %s, base = %s", new, base)); + + if (base == 0) + { + /* no base, so make an absolute URL */ + uri = xmlParseURI(new); + assert(uri != 0); + + if (uri->scheme == 0) + uri->scheme = "http"; + + if (uri->server == 0) { + uri->server = uri->path; + uri->path = 0; + } + } + else + { + /* relative url */ + char* uri_string = xmlBuildURI(new, base); + uri = xmlParseURI(uri_string); + xfree(uri_string); + assert(uri != 0); + } + + /* make server name lower case */ + assert(uri->scheme != 0 && uri->server != 0); + for (i = 0; i < strlen(uri->server); i++) + uri->server[i] = tolower(uri->server[i]); + + /* http://www.example.com -> http://www.example.com/ */ + if (uri->path == 0) + uri->path = "/"; + + ret = xmlSaveUri(uri); + xmlFreeURI(uri); + + LOG(("ret = %s", ret)); + return ret; +} diff --git a/desktop/fetch.c b/desktop/fetch.c index 4eabeb653..1b474868e 100644 --- a/desktop/fetch.c +++ b/desktop/fetch.c @@ -1,5 +1,5 @@ /** - * $Id: fetch.c,v 1.3 2002/12/25 20:17:18 bursa Exp $ + * $Id: fetch.c,v 1.5 2002/12/25 21:38:45 bursa Exp $ */ #include "libxml/HTMLparser.h" @@ -10,48 +10,22 @@ #include "netsurf/desktop/fetch.h" #include "netsurf/render/utils.h" #include "curl/curl.h" -#include "libxml/uri.h" #include #include #include void fetch_identify_location(struct fetch* f, char* location, char* previous) { -/* FILE* ff = fopen("identify", "a"); - fprintf(ff, "identify: '%s' '%s'", location, previous); - if (f->location != NULL) - fprintf(ff, " '%s'\n", f->location); - else - fprintf(ff, "\n"); - fclose(ff);*/ - if (f->location != NULL) xfree(f->location); - if (strspn(location, "http://") == strlen("http://")) - { - f->location = xstrdup(location); - f->type = fetch_CURL; - return; - } - else if (strspn(location, "file:/") == strlen("file:/")) - { - f->location = xstrdup(location); + f->location = xstrdup(location); + + if (strspn(location, "file:/") == strlen("file:/")) f->type = fetch_FILE; - return; - } - else if (previous != NULL) - { - f->location = xmlBuildURI(location, previous); - assert(f->location != NULL); + else + /* throw everything else at curl, since it can fetch lots of protocols */ f->type = fetch_CURL; - return; - } - - f->location = xcalloc(strlen(location) + strlen("http://") + 1, sizeof(char)); - sprintf(f->location, "http://%s", location); - f->type = fetch_CURL; - return; } struct fetch* create_fetch(char* location, char* previous, fetch_flags f, struct fetch_request* r) -- cgit v1.2.3