From e0833d6dfcd721d42c0914c747b9cf7f07c3f16c Mon Sep 17 00:00:00 2001 From: Chris Young Date: Mon, 22 Aug 2016 19:16:24 +0100 Subject: Fetch external entities for libexpat/svg through the proper channels. This currently does fetching, but not parsing. --- content/handlers/image/svg.c | 55 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'content/handlers/image/svg.c') diff --git a/content/handlers/image/svg.c b/content/handlers/image/svg.c index 94c485822..b81f510ef 100644 --- a/content/handlers/image/svg.c +++ b/content/handlers/image/svg.c @@ -27,11 +27,13 @@ #include +#include "utils/log.h" #include "utils/messages.h" #include "utils/utils.h" #include "netsurf/plotters.h" #include "netsurf/content.h" #include "content/content_protected.h" +#include "content/hlcache.h" #include "image/svg.h" @@ -46,6 +48,57 @@ typedef struct svg_content { +/** Callback for hlcache fetch */ +static nserror svg_fetch_hlcache_cb(hlcache_handle *handle, + const hlcache_event *event, + void *parser) +{ + switch (event->type) { + case CONTENT_MSG_DONE: + LOG("external entity '%s' retrieved", nsurl_access(hlcache_handle_get_url(handle))); + break; + + case CONTENT_MSG_ERROR: + LOG("external entity %s error: %s", nsurl_access(hlcache_handle_get_url(handle)), event->data.error); + hlcache_handle_release(handle); + break; + + default: + break; + } + + return NSERROR_OK; +} + +/** Callback for libsvgtiny fetch */ +static int svg_fetch_cb(void *parser, const char *base, const char *uri) +{ + nsurl *x_ent; + nserror ret; + hlcache_handle *handle; + + LOG("Fetching external entity reference %s", uri); + + /* create url */ + ret = nsurl_create(uri, &x_ent); + if (ret != NSERROR_OK) { + return false; + } + + ret = hlcache_handle_retrieve(x_ent, 0, NULL, NULL, + svg_fetch_hlcache_cb, + parser, /* data */ + NULL, CONTENT_ANY, + &handle); + nsurl_unref(x_ent); + + if (ret != NSERROR_OK) { + return false; + } + + return true; +} + static nserror svg_create_svg_data(svg_content *c) { union content_msg_data msg_data; @@ -139,7 +192,7 @@ static void svg_reformat(struct content *c, int width, int height) svgtiny_parse(svg->diagram, source_data, source_size, nsurl_access(content_get_url(c)), - width, height); + width, height, svg_fetch_cb); svg->current_width = width; svg->current_height = height; -- cgit v1.2.3