diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2006-04-12 08:09:27 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2006-04-12 08:09:27 +0000 |
commit | ef301b861982818e140b1f17b8ec5f71ce5b4f64 (patch) | |
tree | 903742a91a427166138502d387c84cd4e12ca7d6 /content | |
parent | 4ecbfb483c96ea6f994dfc0aaab6e82aec8e7aa4 (diff) | |
download | netsurf-ef301b861982818e140b1f17b8ec5f71ce5b4f64.tar.gz netsurf-ef301b861982818e140b1f17b8ec5f71ce5b4f64.tar.bz2 |
Fix URL file loading and add support for file:/// URLs to urldb
Convert file:/... to file:///... (the former isn't a valid URL)
svn path=/trunk/netsurf/; revision=2524
Diffstat (limited to 'content')
-rw-r--r-- | content/fetch.c | 3 | ||||
-rw-r--r-- | content/fetchcache.c | 31 | ||||
-rw-r--r-- | content/urldb.c | 79 |
3 files changed, 93 insertions, 20 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); |