diff options
-rw-r--r-- | content/fetch.c | 3 | ||||
-rw-r--r-- | content/fetchcache.c | 31 | ||||
-rw-r--r-- | content/urldb.c | 79 | ||||
-rw-r--r-- | debug/netsurfd.c | 4 | ||||
-rw-r--r-- | riscos/gui.c | 27 | ||||
-rw-r--r-- | riscos/menus.c | 4 |
6 files changed, 109 insertions, 39 deletions
diff --git a/content/fetch.c b/content/fetch.c index bfbf715a0..6bcac69a6 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -1242,9 +1242,6 @@ bool fetch_process_headers(struct fetch *f) if (strncmp(f->url, "file:///", 8) == 0) url_path = curl_unescape(f->url + 7, (int) strlen(f->url) - 7); - else if (strncmp(f->url, "file:/", 6) == 0) - url_path = curl_unescape(f->url + 5, - (int) strlen(f->url) - 5); if (url_path && stat(url_path, &s) == 0) { /* file: URL and file exists */ diff --git a/content/fetchcache.c b/content/fetchcache.c index bc8907f14..eb47f332a 100644 --- a/content/fetchcache.c +++ b/content/fetchcache.c @@ -82,8 +82,35 @@ struct content * fetchcache(const char *url, char *etag = 0; time_t date = 0; - if ((url1 = strdup(url)) == NULL) - return NULL; + if (strncasecmp(url, "file:///", 8) && + strncasecmp(url, "file:/", 6) == 0) { + /* Manipulate file URLs into correct format */ + if (strncasecmp(url, "file://", 7) == 0) { + /* file://host/... */ + char *slash = 0; + + url1 = malloc(7 + strlen(url)); + if (!url1) + return NULL; + + strcpy(url1, "file://"); + slash = strchr(url + 7, '/'); + if (slash) + strcat(url1 + 7, slash); + } else { + /* file:/... */ + url1 = malloc(7 + strlen(url)); + if (!url1) + return NULL; + + strcpy(url1, "file://"); + strcat(url1 + 7, url + 5); + } + } else { + /* simply duplicate the URL */ + if ((url1 = strdup(url)) == NULL) + return NULL; + } /* strip fragment identifier */ if ((hash = strchr(url1, '#')) != NULL) diff --git a/content/urldb.c b/content/urldb.c index bd5406754..8782c0e89 100644 --- a/content/urldb.c +++ b/content/urldb.c @@ -300,6 +300,18 @@ void urldb_load(const char *filename) continue; } + if (version == 105) { + /* file:/ -> localhost */ + if (strcasecmp(host, "file:/") == 0) + snprintf(host, sizeof host, "localhost"); + else { + /* strip any port number */ + char *colon = strrchr(host, ':'); + if (colon) + *colon = '\0'; + } + } + h = urldb_add_host(host); if (!h) die("Memory exhausted whilst loading URL file"); @@ -318,14 +330,34 @@ void urldb_load(const char *filename) length = strlen(s) - 1; s[length] = '\0'; - if (!urldb_add_url(s)) { - LOG(("Failed inserting '%s'", s)); + if (strncasecmp(s, "file:", 5) == 0) { + /* local file, so fudge insertion */ + char url[7 + 4096]; + + snprintf(url, sizeof url, + "file://%s", s + 5); + + p = urldb_add_path("file", 0, h, + s + 5, NULL, url); + if (!p) { + LOG(("Failed inserting '%s'", + url)); + die("Memory exhausted " + "whilst loading " + "URL file"); + } + } else { + if (!urldb_add_url(s)) { + LOG(("Failed inserting '%s'", + s)); + } + p = urldb_find_url(s); } - p = urldb_find_url(s); } else { char scheme[64], ports[6]; char url[64 + 3 + 256 + 6 + 4096 + 1]; unsigned int port; + bool is_file = false; if (!fgets(scheme, sizeof scheme, fp)) break; @@ -343,7 +375,14 @@ void urldb_load(const char *filename) length = strlen(s) - 1; s[length] = '\0'; - sprintf(url, "%s://%s%s%s%s", scheme, host, + if (!strcasecmp(host, "localhost") && + !strcasecmp(scheme, "file")) + is_file = true; + + snprintf(url, sizeof url, "%s://%s%s%s%s", + scheme, + /* file URLs have no host */ + (is_file ? "" : host), (port ? ":" : ""), (port ? ports : ""), s); @@ -598,7 +637,7 @@ void urldb_write_paths(const struct path_data *parent, const char *host, /** * Insert an URL into the database * - * \param url URL to insert + * \param url Absolute URL to insert * \return true on success, false otherwise */ bool urldb_add_url(const char *url) @@ -611,8 +650,6 @@ bool urldb_add_url(const char *url) assert(url); - /** \todo consider file: URLs */ - urlt = strdup(url); if (!urlt) return false; @@ -663,7 +700,10 @@ bool urldb_add_url(const char *url) } /* Get host entry */ - h = urldb_add_host(host); + if (strcasecmp(scheme, "file") == 0) + h = urldb_add_host("localhost"); + else + h = urldb_add_host(host); if (!h) { free(scheme); free(plq); @@ -1203,6 +1243,10 @@ bool urldb_iterate_entries_path(const struct path_data *parent, if (!parent->children) { /* leaf node */ + /* All leaf nodes in the path tree should have an URL + * attached to them. If this is not the case, it indicates + * that there's a bug in the file loader/URL insertion code. + * Therefore, assert this here. */ assert(parent->url); /** \todo handle fragments? */ @@ -1553,7 +1597,7 @@ struct path_data *urldb_add_path_fragment(struct path_data *segment, /** * Find an URL in the database * - * \param url The URL to find + * \param url Absolute URL to find * \return Pointer to path data, or NULL if not found */ struct path_data *urldb_find_url(const char *url) @@ -1562,13 +1606,12 @@ struct path_data *urldb_find_url(const char *url) struct path_data *p; struct search_node *tree; char *host, *plq, *scheme, *colon; + const char *domain; unsigned short port; url_func_result ret; assert(url); - /** \todo consider file: URLs */ - /* extract host */ ret = url_host(url, &host); if (ret != URL_FUNC_OK) @@ -1597,10 +1640,16 @@ struct path_data *urldb_find_url(const char *url) port = atoi(colon + 1); } - if (*host >= '0' && *host <= '9') + /* file urls have no host, so manufacture one */ + if (strcasecmp(scheme, "file") == 0) + domain = "localhost"; + else + domain = host; + + if (*domain >= '0' && *domain <= '9') tree = search_trees[ST_IP]; - else if (isalpha(*host)) - tree = search_trees[ST_DN + tolower(*host) - 'a']; + else if (isalpha(*domain)) + tree = search_trees[ST_DN + tolower(*domain) - 'a']; else { free(plq); free(host); @@ -1608,7 +1657,7 @@ struct path_data *urldb_find_url(const char *url) return NULL; } - h = urldb_search_find(tree, host); + h = urldb_search_find(tree, domain); if (!h) { free(plq); free(host); diff --git a/debug/netsurfd.c b/debug/netsurfd.c index e3bca4783..8f6fdd852 100644 --- a/debug/netsurfd.c +++ b/debug/netsurfd.c @@ -43,8 +43,8 @@ void *plot = 0; #ifdef riscos void *ro_gui_current_redraw_gui = 0; const char *NETSURF_DIR = "<NetSurf$Dir>"; -char *default_stylesheet_url = "file:/<NetSurf$Dir>/Resources/CSS"; -char *adblock_stylesheet_url = "file:/<NetSurf$Dir>/Resources/AdBlock"; +char *default_stylesheet_url = "file:///<NetSurf$Dir>/Resources/CSS"; +char *adblock_stylesheet_url = "file:///<NetSurf$Dir>/Resources/AdBlock"; #endif static void callback(content_msg msg, struct content *c, void *p1, diff --git a/riscos/gui.c b/riscos/gui.c index 26cadd79f..826861789 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -382,8 +382,8 @@ void gui_init(int argc, char** argv) messages_load(path); messages_load("NetSurf:Resources.LangNames"); - default_stylesheet_url = strdup("file:/NetSurf:/Resources/CSS"); - adblock_stylesheet_url = strdup("file:/NetSurf:/Resources/AdBlock"); + default_stylesheet_url = strdup("file:///NetSurf:/Resources/CSS"); + adblock_stylesheet_url = strdup("file:///NetSurf:/Resources/AdBlock"); if (!default_stylesheet_url || !adblock_stylesheet_url) die("Failed initialising string constants."); @@ -695,7 +695,7 @@ void gui_init2(int argc, char** argv) LOG(("malloc failed")); die("Insufficient memory for URL"); } - snprintf(url, 80, "file:/<NetSurf$Dir>/Docs/intro_%s", + snprintf(url, 80, "file:///<NetSurf$Dir>/Docs/intro_%s", option_language); } @@ -1199,7 +1199,7 @@ bool ro_gui_icon_bar_click(wimp_pointer *pointer) browser_window_create(option_homepage_url, NULL, 0); } else { snprintf(url, sizeof url, - "file:/<NetSurf$Dir>/Docs/intro_%s", + "file:///<NetSurf$Dir>/Docs/intro_%s", option_language); browser_window_create(url, NULL, 0); } @@ -1877,7 +1877,7 @@ void ro_msg_dataopen(wimp_message *message) url = malloc(80); if (url) snprintf(url, 80, - "file:/<NetSurf$Dir>/Docs/intro_%s", + "file:///<NetSurf$Dir>/Docs/intro_%s", option_language); } if (!url) @@ -2028,9 +2028,9 @@ char *path_to_url(const char *path) return 0; } - strcpy(url, "file:"); - __unixify(buffer, __RISCOSIFY_NO_REVERSE_SUFFIX, url + 5, - 1 - spare + 5, 0); + strcpy(url, "file://"); + __unixify(buffer, __RISCOSIFY_NO_REVERSE_SUFFIX, url + 7, + 1 - spare + 3 /* 10 - "file://" */, 0); free(buffer); return url; } @@ -2048,13 +2048,10 @@ char *url_to_path(const char *url) char *temp_name, *r; char *filename; - if (strncmp(url, "file:/", 5)) + if (strncmp(url, "file:///", 8)) return NULL; - if (!strncmp(url, "file:///", 8)) - temp_name = curl_unescape(url + 7, strlen(url) - 7); - else - temp_name = curl_unescape(url + 5, strlen(url) - 5); + temp_name = curl_unescape(url + 7, strlen(url) - 7); if (!temp_name) { warn_user("NoMemory", 0); @@ -2063,7 +2060,7 @@ char *url_to_path(const char *url) filename = malloc(strlen(temp_name) + 100); if (!filename) { - curl_free(temp_name); + curl_free(temp_name); warn_user("NoMemory", 0); return NULL; } @@ -2128,7 +2125,7 @@ void ro_gui_open_help_page(const char *page) int length; if ((length = snprintf(url, sizeof url, - "file:/<NetSurf$Dir>/Docs/%s_%s", + "file:///<NetSurf$Dir>/Docs/%s_%s", page, option_language)) >= 0 && length < (int)sizeof(url)) browser_window_create(url, NULL, 0); } diff --git a/riscos/menus.c b/riscos/menus.c index f44f88a27..f3d247d95 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -1387,7 +1387,7 @@ bool ro_gui_menu_handle_action(wimp_w owner, menu_action action, return true; case HELP_OPEN_ABOUT: browser_window_create( - "file:/<NetSurf$Dir>/Docs/about", + "file:///<NetSurf$Dir>/Docs/about", 0, 0); return true; case HELP_LAUNCH_INTERACTIVE: @@ -1503,7 +1503,7 @@ bool ro_gui_menu_handle_action(wimp_w owner, menu_action action, option_homepage_url, 0); } else { snprintf(url, sizeof url, - "file:/<NetSurf$Dir>/Docs/intro_%s", + "file:///<NetSurf$Dir>/Docs/intro_%s", option_language); browser_window_go(g->bw, url, 0); } |