summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2006-09-17 23:10:42 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2006-09-17 23:10:42 +0000
commit09d2b99973cb4fe93bebaa1b3fa6a30258861eff (patch)
tree7de185c40af62fd257f00ad14d71cf77344cc39c /content
parentbd0dff90984c0ee2c909f35369382fbf1213c7bc (diff)
downloadnetsurf-09d2b99973cb4fe93bebaa1b3fa6a30258861eff.tar.gz
netsurf-09d2b99973cb4fe93bebaa1b3fa6a30258861eff.tar.bz2
Ensure urldb_add_path always has a path.
Extract hostname from url authority returned by url_get_components. svn path=/trunk/netsurf/; revision=2958
Diffstat (limited to 'content')
-rw-r--r--content/urldb.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/content/urldb.c b/content/urldb.c
index 635e2a97a..89580d1c9 100644
--- a/content/urldb.c
+++ b/content/urldb.c
@@ -120,7 +120,7 @@ struct auth_data {
};
struct cache_internal_data {
- char filename[12]; /**< Cached filename, or first byte 0 for none */
+ char filename[12]; /**< Cached filename, or first byte 0 for none */
};
struct url_internal_data {
@@ -425,7 +425,7 @@ void urldb_load(const char *filename)
(port ? ports : ""),
s);
- p = urldb_add_path(scheme, port, h, s, NULL, NULL,
+ p = urldb_add_path(scheme, port, h, s, NULL, NULL,
url);
if (!p) {
LOG(("Failed inserting '%s'", url));
@@ -710,6 +710,7 @@ bool urldb_add_url(const char *url)
struct host_part *h;
struct path_data *p;
char *colon;
+ const char *host;
unsigned short port;
url_func_result ret;
struct url_components components;
@@ -721,8 +722,15 @@ bool urldb_add_url(const char *url)
if (ret != URL_FUNC_OK)
return false;
+ /* Extract host part from authority */
+ host = strchr(components.authority, '@');
+ if (!host)
+ host = components.authority;
+ else
+ host++;
+
/* get port and remove from authority */
- colon = strrchr(components.authority, ':');
+ colon = strrchr(host, ':');
if (!colon) {
port = 0;
} else {
@@ -734,21 +742,22 @@ bool urldb_add_url(const char *url)
if (strcasecmp(components.scheme, "file") == 0)
h = urldb_add_host("localhost");
else
- h = urldb_add_host(components.authority);
+ h = urldb_add_host(host);
if (!h) {
url_destroy_components(&components);
return false;
}
/* Get path entry */
- p = urldb_add_path(components.scheme, port, h, components.path,
+ p = urldb_add_path(components.scheme, port, h,
+ components.path ? components.path : "",
components.query, components.fragment, url);
if (!p) {
return false;
}
url_destroy_components(&components);
-
+
return true;
}
@@ -1578,8 +1587,8 @@ struct path_data *urldb_add_path_node(const char *scheme, unsigned int port,
* \return Pointer to leaf node, or NULL on memory exhaustion
*/
struct path_data *urldb_add_path(const char *scheme, unsigned int port,
- const struct host_part *host, const char *path, const char *query,
- const char *fragment, const char *url)
+ const struct host_part *host, const char *path,
+ const char *query, const char *fragment, const char *url)
{
struct path_data *d, *e;
char *buf, *copy;
@@ -1605,10 +1614,10 @@ struct path_data *urldb_add_path(const char *scheme, unsigned int port,
copy += strlen(path);
}
if (query) {
- *copy++ = '?';
- strcpy(copy, query);
+ *copy++ = '?';
+ strcpy(copy, query);
}
-
+
/* skip leading '/' */
segment = buf;
if (*segment == '/')
@@ -3364,7 +3373,7 @@ bool urldb_set_cache_data(const char *url, const struct content *content) {
p = urldb_find_url(url);
if (!p)
return false;
-
+
/* new filename needed */
if (p->cache.filename[0] == 0) {
filename = filename_request();
@@ -3372,7 +3381,7 @@ bool urldb_set_cache_data(const char *url, const struct content *content) {
return false;
sprintf(p->cache.filename, filename);
}
-
+
/* todo: save content, set cache data etc */
return true;
}
@@ -3392,7 +3401,7 @@ char *urldb_get_cache_data(const char *url) {
p = urldb_find_url(url);
if (!p)
return NULL;
-
+
/* no file cache */
if (p->cache.filename[0] == 0)
return NULL;