From c9bd6fa9fce386526ea1327adea56128648f3355 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Mon, 9 Aug 2004 16:11:58 +0000 Subject: [project @ 2004-08-09 16:11:58 by jmb] Rework the interface of the URL handing module to allow for multiple error types. Modify save_complete URL rewriting appropriately. svn path=/import/netsurf/; revision=1206 --- riscos/401login.c | 5 ++-- riscos/download.c | 3 ++- riscos/hotlist.c | 10 +++++--- riscos/save.c | 3 ++- riscos/save_complete.c | 66 ++++++++++++++++++++++++++++++-------------------- riscos/window.c | 5 ++-- 6 files changed, 57 insertions(+), 35 deletions(-) (limited to 'riscos') diff --git a/riscos/401login.c b/riscos/401login.c index 8beaac9be..9edef15a8 100644 --- a/riscos/401login.c +++ b/riscos/401login.c @@ -46,10 +46,11 @@ void ro_gui_401login_init(void) void gui_401login_open(struct browser_window *bw, struct content *c, char *realm) { char *murl, *host; + url_func_result res; murl = c->url; - host = url_host(murl); - assert(host); + res = url_host(murl, &host); + assert(res == URL_FUNC_OK); bwin = bw; ro_gui_401login_open(bw->window->window, host, realm, murl); diff --git a/riscos/download.c b/riscos/download.c index 2a6d8d583..77aa9a217 100644 --- a/riscos/download.c +++ b/riscos/download.c @@ -128,6 +128,7 @@ struct gui_download_window *gui_download_window_create(const char *url, char temp_name[40]; struct gui_download_window *dw; os_error *error; + url_func_result res; dw = malloc(sizeof *dw); if (!dw) { @@ -188,7 +189,7 @@ struct gui_download_window *gui_download_window_create(const char *url, (osspriteop_id) dw->sprite_name; strcpy(dw->path, messages_get("SaveObject")); - if ((nice = url_nice(url))) { + if ((res = url_nice(url, &nice)) == URL_FUNC_OK) { strcpy(dw->path, nice); free(nice); } diff --git a/riscos/hotlist.c b/riscos/hotlist.c index 8a2a57100..de91fbad7 100644 --- a/riscos/hotlist.c +++ b/riscos/hotlist.c @@ -906,6 +906,7 @@ struct hotlist_entry *ro_gui_hotlist_create_entry(const char *title, const char *url, int filetype, struct hotlist_entry *folder) { struct hotlist_entry *entry; + url_func_result res; /* Check we have a title or a URL */ @@ -923,7 +924,8 @@ struct hotlist_entry *ro_gui_hotlist_create_entry(const char *title, use the URL instead */ entry->url = 0; - if ((url) && ((entry->url = url_normalize(url)) == 0)) { + if ((url) && ((res = url_normalize(url, &entry->url)) != URL_FUNC_OK)) { + /** \todo use correct error message */ warn_user("NoMemory", 0); free(entry->url); free(entry); @@ -2443,6 +2445,7 @@ void ro_gui_hotlist_dialog_click(wimp_pointer *pointer) { int close_icon, ok_icon; bool folder; bool add; + url_func_result res; /* Get our data */ @@ -2502,8 +2505,9 @@ void ro_gui_hotlist_dialog_click(wimp_pointer *pointer) { if (entry == NULL) return; if (url) { old_value = entry->url; - entry->url = url_normalize(url); - if (!entry->url) { + res = url_normalize(url, &entry->url); + if (res != URL_FUNC_OK) { + /** \todo use correct error message */ warn_user("NoMemory", 0); entry->url = old_value; return; diff --git a/riscos/save.c b/riscos/save.c index 14564f727..b73f57a8d 100644 --- a/riscos/save.c +++ b/riscos/save.c @@ -84,6 +84,7 @@ void ro_gui_save_open(gui_save_type save_type, struct content *c, const char *name = ""; const char *nice; os_error *error; + url_func_result res; assert(save_type == GUI_SAVE_HOTLIST_EXPORT_HTML || c); @@ -102,7 +103,7 @@ void ro_gui_save_open(gui_save_type save_type, struct content *c, /* filename */ name = gui_save_table[save_type].name; if (c) { - if ((nice = url_nice(c->url))) + if ((res = url_nice(c->url, &nice)) == URL_FUNC_OK) name = nice; } ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_PATH, name); diff --git a/riscos/save_complete.c b/riscos/save_complete.c index fad990c20..519181188 100644 --- a/riscos/save_complete.c +++ b/riscos/save_complete.c @@ -342,6 +342,7 @@ char * rewrite_stylesheet_urls(const char *source, unsigned int size, unsigned int i; unsigned int imports = 0; regmatch_t match[11]; + url_func_result result; /* count number occurences of @import to (over)estimate result size */ /* can't use strstr because source is not 0-terminated string */ @@ -399,9 +400,9 @@ char * rewrite_stylesheet_urls(const char *source, unsigned int size, free(res); return 0; } - url = url_join(url2, base); + result = url_join(url2, base, (char**)&url); free(url2); - if (!url) { + if (result == URL_FUNC_NOMEM) { free(res); return 0; } @@ -410,17 +411,25 @@ char * rewrite_stylesheet_urls(const char *source, unsigned int size, memcpy(res + *osize, source + offset, match[0].rm_so); *osize += match[0].rm_so; - content = save_complete_list_find(url); - if (content) { - /* replace import */ - snprintf(buf, sizeof buf, "@import '%x'", - (unsigned int) content); - memcpy(res + *osize, buf, strlen(buf)); - *osize += strlen(buf); - } else { + if (result == URL_FUNC_OK) { + content = save_complete_list_find(url); + if (content) { + /* replace import */ + snprintf(buf, sizeof buf, "@import '%x'", + (unsigned int) content); + memcpy(res + *osize, buf, strlen(buf)); + *osize += strlen(buf); + } else { + /* copy import */ + memcpy(res + *osize, source + offset + match[0].rm_so, + match[0].rm_eo - match[0].rm_so); + *osize += match[0].rm_eo - match[0].rm_so; + } + } + else { /* copy import */ memcpy(res + *osize, source + offset + match[0].rm_so, - match[0].rm_eo - match[0].rm_so); + match[0].rm_eo - match[0].rm_so); *osize += match[0].rm_eo - match[0].rm_so; } @@ -570,6 +579,7 @@ bool rewrite_url(xmlNode *n, const char *attr, const char *base) char *url, *data; char rel[20]; struct content *content; + url_func_result res; if (!xmlHasProp(n, (const xmlChar *) attr)) return true; @@ -578,25 +588,29 @@ bool rewrite_url(xmlNode *n, const char *attr, const char *base) if (!data) return false; - url = url_join(data, base); + res = url_join(data, base, &url); xmlFree(data); - if (!url) + if (res == URL_FUNC_NOMEM) return false; - - content = save_complete_list_find(url); - if (content) { - /* found a match */ - free(url); - snprintf(rel, sizeof rel, "%x", (unsigned int) content); - if (!xmlSetProp(n, (const xmlChar *) attr, (xmlChar *) rel)) - return false; - } else { - /* no match found */ - if (!xmlSetProp(n, (const xmlChar *) attr, (xmlChar *) url)) { + else if (res == URL_FUNC_OK) { + content = save_complete_list_find(url); + if (content) { + /* found a match */ + free(url); + snprintf(rel, sizeof rel, "%x", + (unsigned int) content); + if (!xmlSetProp(n, (const xmlChar *) attr, + (xmlChar *) rel)) + return false; + } else { + /* no match found */ + if (!xmlSetProp(n, (const xmlChar *) attr, + (xmlChar *) url)) { + free(url); + return false; + } free(url); - return false; } - free(url); } return true; diff --git a/riscos/window.c b/riscos/window.c index ab945cb0d..a0715738d 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -1235,6 +1235,7 @@ bool ro_gui_window_keypress(struct gui_window *g, int key, bool toolbar) char *url; os_error *error; wimp_pointer pointer; + url_func_result res; error = xwimp_get_pointer_info(&pointer); if (error) { @@ -1361,8 +1362,8 @@ bool ro_gui_window_keypress(struct gui_window *g, int key, bool toolbar) case wimp_KEY_RETURN: if (!toolbar) break; - url = url_normalize(g->url); - if (url) { + res = url_normalize(g->url, &url); + if (res == URL_FUNC_OK) { gui_window_set_url(g, url); browser_window_go(g->bw, url); free(url); -- cgit v1.2.3