mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-09 04:22:12 +03:00
Lower overhead of urldb calls by using url component calls.
svn path=/trunk/netsurf/; revision=2908
This commit is contained in:
parent
b0851c9dde
commit
1086d53b89
188
content/urldb.c
188
content/urldb.c
@ -209,8 +209,8 @@ static struct path_data *urldb_add_path_node(const char *scheme,
|
|||||||
struct path_data *parent);
|
struct path_data *parent);
|
||||||
static struct path_data *urldb_add_path(const char *scheme,
|
static struct path_data *urldb_add_path(const char *scheme,
|
||||||
unsigned int port, const struct host_part *host,
|
unsigned int port, const struct host_part *host,
|
||||||
const char *path, const char *fragment,
|
const char *path, const char *query, const char *fragment,
|
||||||
const char *url_no_frag);
|
const char *url);
|
||||||
static int urldb_add_path_fragment_cmp(const void *a, const void *b);
|
static int urldb_add_path_fragment_cmp(const void *a, const void *b);
|
||||||
static struct path_data *urldb_add_path_fragment(struct path_data *segment,
|
static struct path_data *urldb_add_path_fragment(struct path_data *segment,
|
||||||
const char *fragment);
|
const char *fragment);
|
||||||
@ -376,7 +376,7 @@ void urldb_load(const char *filename)
|
|||||||
"file://%s", s + 5);
|
"file://%s", s + 5);
|
||||||
|
|
||||||
p = urldb_add_path("file", 0, h,
|
p = urldb_add_path("file", 0, h,
|
||||||
s + 5, NULL, url);
|
s + 5, NULL, NULL, url);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
LOG(("Failed inserting '%s'",
|
LOG(("Failed inserting '%s'",
|
||||||
url));
|
url));
|
||||||
@ -425,7 +425,7 @@ void urldb_load(const char *filename)
|
|||||||
(port ? ports : ""),
|
(port ? ports : ""),
|
||||||
s);
|
s);
|
||||||
|
|
||||||
p = urldb_add_path(scheme, port, h, s, NULL,
|
p = urldb_add_path(scheme, port, h, s, NULL, NULL,
|
||||||
url);
|
url);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
LOG(("Failed inserting '%s'", url));
|
LOG(("Failed inserting '%s'", url));
|
||||||
@ -709,54 +709,20 @@ bool urldb_add_url(const char *url)
|
|||||||
{
|
{
|
||||||
struct host_part *h;
|
struct host_part *h;
|
||||||
struct path_data *p;
|
struct path_data *p;
|
||||||
char *fragment = NULL, *host, *plq, *scheme, *colon, *urlt;
|
char *colon;
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
url_func_result ret;
|
url_func_result ret;
|
||||||
|
struct url_components components;
|
||||||
|
|
||||||
assert(url);
|
assert(url);
|
||||||
|
|
||||||
urlt = strdup(url);
|
/* extract url components */
|
||||||
if (!urlt)
|
ret = url_get_components(url, &components);
|
||||||
|
if (ret != URL_FUNC_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
host = strchr(urlt, '#');
|
/* get port and remove from authority */
|
||||||
if (host) {
|
colon = strrchr(components.authority, ':');
|
||||||
*host = '\0';
|
|
||||||
fragment = strdup(host+1);
|
|
||||||
if (!fragment) {
|
|
||||||
free(urlt);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* extract host */
|
|
||||||
ret = url_host(url, &host);
|
|
||||||
if (ret != URL_FUNC_OK) {
|
|
||||||
free(fragment);
|
|
||||||
free(urlt);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* extract path, leafname, query */
|
|
||||||
ret = url_plq(url, &plq);
|
|
||||||
if (ret != URL_FUNC_OK) {
|
|
||||||
free(host);
|
|
||||||
free(fragment);
|
|
||||||
free(urlt);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* extract scheme */
|
|
||||||
ret = url_scheme(url, &scheme);
|
|
||||||
if (ret != URL_FUNC_OK) {
|
|
||||||
free(plq);
|
|
||||||
free(host);
|
|
||||||
free(fragment);
|
|
||||||
free(urlt);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
colon = strrchr(host, ':');
|
|
||||||
if (!colon) {
|
if (!colon) {
|
||||||
port = 0;
|
port = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -765,31 +731,24 @@ bool urldb_add_url(const char *url)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get host entry */
|
/* Get host entry */
|
||||||
if (strcasecmp(scheme, "file") == 0)
|
if (strcasecmp(components.scheme, "file") == 0)
|
||||||
h = urldb_add_host("localhost");
|
h = urldb_add_host("localhost");
|
||||||
else
|
else
|
||||||
h = urldb_add_host(host);
|
h = urldb_add_host(components.authority);
|
||||||
if (!h) {
|
if (!h) {
|
||||||
free(scheme);
|
url_destroy_components(&components);
|
||||||
free(plq);
|
|
||||||
free(host);
|
|
||||||
free(fragment);
|
|
||||||
free(urlt);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get path entry */
|
/* Get path entry */
|
||||||
p = urldb_add_path(scheme, port, h, plq, fragment, urlt);
|
p = urldb_add_path(components.scheme, port, h, components.path,
|
||||||
|
components.query, components.fragment, url);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(scheme);
|
url_destroy_components(&components);
|
||||||
free(plq);
|
|
||||||
free(host);
|
|
||||||
free(fragment);
|
|
||||||
free(urlt);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1613,31 +1572,47 @@ struct path_data *urldb_add_path_node(const char *scheme, unsigned int port,
|
|||||||
* \param port Port number on host associated with path
|
* \param port Port number on host associated with path
|
||||||
* \param host Host tree node to attach to
|
* \param host Host tree node to attach to
|
||||||
* \param path Absolute path to add
|
* \param path Absolute path to add
|
||||||
|
* \param query Path query to add
|
||||||
* \param fragment URL fragment, or NULL
|
* \param fragment URL fragment, or NULL
|
||||||
* \param url_no_frag URL, without fragment
|
* \param url URL (fragment ignored)
|
||||||
* \return Pointer to leaf node, or NULL on memory exhaustion
|
* \return Pointer to leaf node, or NULL on memory exhaustion
|
||||||
*/
|
*/
|
||||||
struct path_data *urldb_add_path(const char *scheme, unsigned int port,
|
struct path_data *urldb_add_path(const char *scheme, unsigned int port,
|
||||||
const struct host_part *host, const char *path,
|
const struct host_part *host, const char *path, const char *query,
|
||||||
const char *fragment, const char *url_no_frag)
|
const char *fragment, const char *url)
|
||||||
{
|
{
|
||||||
struct path_data *d, *e;
|
struct path_data *d, *e;
|
||||||
char *buf;
|
char *buf, *copy;
|
||||||
char *segment, *slash;
|
char *segment, *slash;
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
assert(scheme && host && path && url_no_frag);
|
assert(scheme && host && url);
|
||||||
|
assert(path || query);
|
||||||
|
|
||||||
d = (struct path_data *) &host->paths;
|
d = (struct path_data *) &host->paths;
|
||||||
|
|
||||||
/* Copy path string, so we can corrupt it */
|
/* Copy and merge path/query strings, so we can corrupt them */
|
||||||
buf = malloc(strlen(path) + 1);
|
if (path)
|
||||||
|
len += strlen(path);
|
||||||
|
if (query)
|
||||||
|
len += strlen(query) + 1;
|
||||||
|
buf = malloc(len + 1);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
copy = buf;
|
||||||
/* + 1 to strip leading '/' */
|
if (path) {
|
||||||
strcpy(buf, path + 1);
|
strcpy(copy, path);
|
||||||
|
copy += strlen(path);
|
||||||
|
}
|
||||||
|
if (query) {
|
||||||
|
*copy++ = '?';
|
||||||
|
strcpy(copy, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* skip leading '/' */
|
||||||
segment = buf;
|
segment = buf;
|
||||||
|
if (*segment == '/')
|
||||||
|
segment++;
|
||||||
|
|
||||||
/* Process path segments */
|
/* Process path segments */
|
||||||
do {
|
do {
|
||||||
@ -1679,9 +1654,13 @@ struct path_data *urldb_add_path(const char *scheme, unsigned int port,
|
|||||||
|
|
||||||
if (d && !d->url) {
|
if (d && !d->url) {
|
||||||
/* Insert URL */
|
/* Insert URL */
|
||||||
d->url = strdup(url_no_frag);
|
d->url = strdup(url);
|
||||||
if (!d->url)
|
if (!d->url)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
/** remove fragment */
|
||||||
|
segment = strrchr(d->url, '#');
|
||||||
|
if (segment)
|
||||||
|
*segment = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
@ -1748,34 +1727,22 @@ struct path_data *urldb_find_url(const char *url)
|
|||||||
const struct host_part *h;
|
const struct host_part *h;
|
||||||
struct path_data *p;
|
struct path_data *p;
|
||||||
struct search_node *tree;
|
struct search_node *tree;
|
||||||
char *host, *plq, *scheme, *colon;
|
char *plq, *copy, *colon;
|
||||||
const char *domain;
|
const char *domain;
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
url_func_result ret;
|
url_func_result ret;
|
||||||
|
struct url_components components;
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
assert(url);
|
assert(url);
|
||||||
|
|
||||||
/* extract host */
|
/* extract url components */
|
||||||
ret = url_host(url, &host);
|
ret = url_get_components(url, &components);
|
||||||
if (ret != URL_FUNC_OK)
|
if (ret != URL_FUNC_OK)
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
/* extract path, leafname, query */
|
/* get port and remove from authority */
|
||||||
ret = url_plq(url, &plq);
|
colon = strrchr(components.authority, ':');
|
||||||
if (ret != URL_FUNC_OK) {
|
|
||||||
free(host);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* extract scheme */
|
|
||||||
ret = url_scheme(url, &scheme);
|
|
||||||
if (ret != URL_FUNC_OK) {
|
|
||||||
free(plq);
|
|
||||||
free(host);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
colon = strrchr(host, ':');
|
|
||||||
if (!colon) {
|
if (!colon) {
|
||||||
port = 0;
|
port = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -1784,35 +1751,48 @@ struct path_data *urldb_find_url(const char *url)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* file urls have no host, so manufacture one */
|
/* file urls have no host, so manufacture one */
|
||||||
if (strcasecmp(scheme, "file") == 0)
|
if (strcasecmp(components.scheme, "file") == 0)
|
||||||
domain = "localhost";
|
domain = "localhost";
|
||||||
else
|
else
|
||||||
domain = host;
|
domain = components.authority;
|
||||||
|
|
||||||
if (*domain >= '0' && *domain <= '9')
|
if (*domain >= '0' && *domain <= '9')
|
||||||
tree = search_trees[ST_IP];
|
tree = search_trees[ST_IP];
|
||||||
else if (isalpha(*domain))
|
else if (isalpha(*domain))
|
||||||
tree = search_trees[ST_DN + tolower(*domain) - 'a'];
|
tree = search_trees[ST_DN + tolower(*domain) - 'a'];
|
||||||
else {
|
else {
|
||||||
free(plq);
|
url_destroy_components(&components);
|
||||||
free(host);
|
|
||||||
free(scheme);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
h = urldb_search_find(tree, domain);
|
h = urldb_search_find(tree, domain);
|
||||||
if (!h) {
|
if (!h) {
|
||||||
free(plq);
|
url_destroy_components(&components);
|
||||||
free(host);
|
|
||||||
free(scheme);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = urldb_match_path(&h->paths, plq, scheme, port);
|
/* generate plq */
|
||||||
|
if (components.path)
|
||||||
|
len += strlen(components.path);
|
||||||
|
if (components.query)
|
||||||
|
len += strlen(components.query) + 1;
|
||||||
|
plq = malloc(len + 1);
|
||||||
|
if (!plq)
|
||||||
|
return NULL;
|
||||||
|
copy = plq;
|
||||||
|
if (components.path) {
|
||||||
|
strcpy(copy, components.path);
|
||||||
|
copy += strlen(components.path);
|
||||||
|
}
|
||||||
|
if (components.query) {
|
||||||
|
*copy++ = '?';
|
||||||
|
strcpy(copy, components.query);
|
||||||
|
}
|
||||||
|
|
||||||
|
p = urldb_match_path(&h->paths, plq, components.scheme, port);
|
||||||
|
|
||||||
|
url_destroy_components(&components);
|
||||||
free(plq);
|
free(plq);
|
||||||
free(host);
|
|
||||||
free(scheme);
|
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -2988,7 +2968,7 @@ bool urldb_insert_cookie(struct cookie_internal_data *c, const char *scheme,
|
|||||||
|
|
||||||
/* find path */
|
/* find path */
|
||||||
p = urldb_add_path(scheme, 0, h,
|
p = urldb_add_path(scheme, 0, h,
|
||||||
c->path, NULL, url);
|
c->path, NULL, NULL, url);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
urldb_free_cookie(c);
|
urldb_free_cookie(c);
|
||||||
return false;
|
return false;
|
||||||
@ -3377,7 +3357,7 @@ void urldb_save_cookie_paths(FILE *fp, struct path_data *parent)
|
|||||||
*/
|
*/
|
||||||
bool urldb_set_cache_data(const char *url, const struct content *content) {
|
bool urldb_set_cache_data(const char *url, const struct content *content) {
|
||||||
struct path_data *p;
|
struct path_data *p;
|
||||||
char *filename;
|
const char *filename;
|
||||||
|
|
||||||
assert(url && content);
|
assert(url && content);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user