summaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2003-12-26 00:17:55 +0000
committerJames Bursa <james@netsurf-browser.org>2003-12-26 00:17:55 +0000
commitf1b59814f8da2f3e235d47adfb332edf8a093b31 (patch)
tree760327fafeb70a0ed342abba3455da00a684eabc /render
parent3b4de07169777f6f820f08ac1422e9af901b3ee2 (diff)
downloadnetsurf-f1b59814f8da2f3e235d47adfb332edf8a093b31.tar.gz
netsurf-f1b59814f8da2f3e235d47adfb332edf8a093b31.tar.bz2
[project @ 2003-12-26 00:17:55 by bursa]
New url_join using liburi, <base href=...>. svn path=/import/netsurf/; revision=441
Diffstat (limited to 'render')
-rw-r--r--render/box.c94
-rw-r--r--render/html.c38
-rw-r--r--render/html.h1
3 files changed, 93 insertions, 40 deletions
diff --git a/render/box.c b/render/box.c
index e62fd0cd7..e565be0a6 100644
--- a/render/box.c
+++ b/render/box.c
@@ -706,7 +706,10 @@ struct result box_image(xmlNode *n, struct status *status,
if (!(s = (char *) xmlGetProp(n, (const xmlChar *) "src")))
return (struct result) {box, 0};
- url = url_join(s, status->content->url);
+ url = url_join(s, status->content->data.html.base_url);
+ if (!url)
+ return (struct result) {box, 0};
+
LOG(("image '%s'", url));
xmlFree(s);
@@ -1014,8 +1017,9 @@ struct result box_input(xmlNode *n, struct status *status,
gadget->box = box;
gadget->type = GADGET_IMAGE;
if ((s = (char *) xmlGetProp(n, (const xmlChar*) "src"))) {
- url = url_join(s, status->content->url);
- html_fetch_object(status->content, url, box);
+ url = url_join(s, status->content->data.html.base_url);
+ if (url)
+ html_fetch_object(status->content, url, box);
xmlFree(s);
}
}
@@ -1673,9 +1677,13 @@ struct result box_object(xmlNode *n, struct status *status,
/* object data */
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "data"))) {
-
+ url = url_join(s, status->content->data.html.base_url);
+ if (!url) {
+ free(po);
+ xmlFree(s);
+ return (struct result) {box, 1};
+ }
po->data = strdup(s);
- url = url_join(strdup(s), status->content->url);
LOG(("object '%s'", po->data));
xmlFree(s);
}
@@ -1797,10 +1805,14 @@ struct result box_embed(xmlNode *n, struct status *status,
/* embed src */
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "src"))) {
-
- po->data = strdup(s);
- url = url_join(strdup(s), status->content->url);
+ url = url_join(s, status->content->data.html.base_url);
+ if (!url) {
+ free(po);
+ xmlFree(s);
+ return (struct result) {box, 0};
+ }
LOG(("embed '%s'", url));
+ po->data = strdup(s);
xmlFree(s);
}
@@ -1861,14 +1873,18 @@ struct result box_applet(xmlNode *n, struct status *status,
po->classid = 0;
po->params = 0;
- /* code */
+ /* code */
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "code"))) {
-
- po->classid = strdup(s);
- url = url_join(strdup(s), status->content->url);
- LOG(("applet '%s'", url));
- xmlFree(s);
- }
+ url = url_join(s, status->content->data.html.base_url);
+ if (!url) {
+ free(po);
+ xmlFree(s);
+ return (struct result) {box, 1};
+ }
+ LOG(("applet '%s'", url));
+ po->classid = strdup(s);
+ xmlFree(s);
+ }
/* object codebase */
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "codebase"))) {
@@ -1962,12 +1978,16 @@ struct result box_iframe(xmlNode *n, struct status *status,
/* iframe src */
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "src"))) {
-
- po->data = strdup(s);
- url = url_join(strdup(s), status->content->url);
- LOG(("embed '%s'", url));
- xmlFree(s);
- }
+ url = url_join(s, status->content->data.html.base_url);
+ if (!url) {
+ free(po);
+ xmlFree(s);
+ return (struct result) {box, 0};
+ }
+ LOG(("embed '%s'", url));
+ po->data = strdup(s);
+ xmlFree(s);
+ }
box->object_params = po;
@@ -1985,22 +2005,27 @@ struct result box_iframe(xmlNode *n, struct status *status,
* necessary as there are multiple ways of declaring an object's attributes.
*
* Returns false if the object could not be handled.
+ *
+ * TODO: reformat, plug failure leaks
*/
bool plugin_decode(struct content* content, char* url, struct box* box,
struct object_params* po)
{
struct plugin_params * pp;
- /* Set basehref */
- po->basehref = strdup(content->url);
-
/* Check if the codebase attribute is defined.
* If it is not, set it to the codebase of the current document.
*/
if(po->codebase == 0)
- po->codebase = url_join("./", content->url);
+ po->codebase = url_join("./", content->data.html.base_url);
else
- po->codebase = url_join(po->codebase, content->url);
+ po->codebase = url_join(po->codebase, content->data.html.base_url);
+
+ if (!po->codebase)
+ return false;
+
+ /* Set basehref */
+ po->basehref = strdup(content->data.html.base_url);
/* Check that we have some data specified.
* First, check the data attribute.
@@ -2019,11 +2044,16 @@ bool plugin_decode(struct content* content, char* url, struct box* box,
for(pp = po->params; pp != 0 &&
(strcasecmp(pp->name, "movie") != 0);
pp = pp->next);
- if(pp != 0)
- url = url_join(pp->value, po->basehref);
- else return false;
+ if(pp == 0)
+ return false;
+ url = url_join(pp->value, po->basehref);
+ if (!url)
+ return false;
/* munge the codebase */
- po->codebase = url_join("./", content->url);
+ po->codebase = url_join("./",
+ content->data.html.base_url);
+ if (!po->codebase)
+ return false;
}
else {
LOG(("ActiveX object - n0"));
@@ -2032,6 +2062,8 @@ bool plugin_decode(struct content* content, char* url, struct box* box,
}
else {
url = url_join(po->classid, po->codebase);
+ if (!url)
+ return false;
/* The java plugin doesn't need the .class extension
* so we strip it.
@@ -2043,6 +2075,8 @@ bool plugin_decode(struct content* content, char* url, struct box* box,
}
else {
url = url_join(po->data, po->codebase);
+ if (!url)
+ return false;
}
/* Check if the declared mime type is understandable.
diff --git a/render/html.c b/render/html.c
index e3953597e..73bda84ed 100644
--- a/render/html.c
+++ b/render/html.c
@@ -23,7 +23,7 @@
static void html_convert_css_callback(content_msg msg, struct content *css,
void *p1, void *p2, const char *error);
-static void html_title(struct content *c, xmlNode *head);
+static void html_head(struct content *c, xmlNode *head);
static void html_find_stylesheets(struct content *c, xmlNode *head);
static void html_object_callback(content_msg msg, struct content *object,
void *p1, void *p2, const char *error);
@@ -37,6 +37,7 @@ void html_create(struct content *c)
c->data.html.fonts = NULL;
c->data.html.length = 0;
c->data.html.source = xcalloc(0, 1);
+ c->data.html.base_url = xstrdup(c->url);
c->data.html.background_colour = TRANSPARENT;
}
@@ -96,7 +97,7 @@ int html_convert(struct content *c, unsigned int width, unsigned int height)
}
if (head != 0)
- html_title(c, head);
+ html_head(c, head);
/* get stylesheets */
html_find_stylesheets(c, head);
@@ -203,19 +204,31 @@ void html_convert_css_callback(content_msg msg, struct content *css,
}
-void html_title(struct content *c, xmlNode *head)
+
+/**
+ * Process elements in <head>.
+ */
+
+void html_head(struct content *c, xmlNode *head)
{
xmlNode *node;
- xmlChar *title;
c->title = 0;
for (node = head->children; node != 0; node = node->next) {
- if (strcmp(node->name, "title") == 0) {
- title = xmlNodeGetContent(node);
+ if (!c->title && strcmp(node->name, "title") == 0) {
+ xmlChar *title = xmlNodeGetContent(node);
c->title = squash_tolat1(title);
xmlFree(title);
- return;
+
+ } else if (strcmp(node->name, "base") == 0) {
+ char *href = (char *) xmlGetProp(node, (const xmlChar *) "href");
+ if (href) {
+ char *url = url_join(href, 0);
+ if (url)
+ c->data.html.base_url = url;
+ xmlFree(href);
+ }
}
}
}
@@ -286,9 +299,12 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
/* TODO: only the first preferred stylesheets (ie. those with a
* title attribute) should be loaded (see HTML4 14.3) */
- url = url_join(href, c->url);
- LOG(("linked stylesheet %i '%s'", i, url));
+ url = url_join(href, c->data.html.base_url);
xmlFree(href);
+ if (!url)
+ continue;
+
+ LOG(("linked stylesheet %i '%s'", i, url));
/* start fetch */
c->data.html.stylesheet_content = xrealloc(c->data.html.stylesheet_content,
@@ -325,7 +341,8 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
/* create stylesheet */
LOG(("style element"));
if (c->data.html.stylesheet_content[1] == 0) {
- c->data.html.stylesheet_content[1] = content_create(c->url);
+ c->data.html.stylesheet_content[1] =
+ content_create(c->data.html.base_url);
content_set_type(c->data.html.stylesheet_content[1], CONTENT_CSS, "text/css");
}
@@ -567,5 +584,6 @@ void html_destroy(struct content *c)
xfree(c->title);
if (c->data.html.source != 0)
xfree(c->data.html.source);
+ free(c->data.html.base_url);
}
diff --git a/render/html.h b/render/html.h
index db41f7f11..8a5047cc2 100644
--- a/render/html.h
+++ b/render/html.h
@@ -29,6 +29,7 @@ struct content_html_data {
htmlParserCtxt *parser;
char *source;
int length;
+ char *base_url; /**< Base URL (may be a copy of content->url). */
struct box *layout;
colour background_colour;
unsigned int stylesheet_count;