summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2016-08-22 18:16:24 (GMT)
committer Chris Young <chris@unsatisfactorysoftware.co.uk>2016-08-22 18:16:24 (GMT)
commite0833d6dfcd721d42c0914c747b9cf7f07c3f16c (patch)
treee93f20e5945d3de4528688e75c5ca8b17b7dea88
parenta8a6098f689a936307ca11cc922a8fc535654007 (diff)
downloadnetsurf-e0833d6dfcd721d42c0914c747b9cf7f07c3f16c.tar.gz
netsurf-e0833d6dfcd721d42c0914c747b9cf7f07c3f16c.tar.bz2
Fetch external entities for libexpat/svg through the proper channels.
This currently does fetching, but not parsing.
-rw-r--r--content/handlers/image/svg.c55
-rw-r--r--frontends/amiga/iff_dr2d.c2
2 files changed, 55 insertions, 2 deletions
diff --git a/content/handlers/image/svg.c b/content/handlers/image/svg.c
index 94c4858..b81f510 100644
--- a/content/handlers/image/svg.c
+++ b/content/handlers/image/svg.c
@@ -27,11 +27,13 @@
#include <svgtiny.h>
+#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;
diff --git a/frontends/amiga/iff_dr2d.c b/frontends/amiga/iff_dr2d.c
index aea7738..053f948 100644
--- a/frontends/amiga/iff_dr2d.c
+++ b/frontends/amiga/iff_dr2d.c
@@ -91,7 +91,7 @@ bool ami_svg_to_dr2d(struct IFFHandle *iffh, const char *buffer,
}
/* parse */
- code = svgtiny_parse(diagram, buffer, size, url, 1000, 1000);
+ code = svgtiny_parse(diagram, buffer, size, url, 1000, 1000, NULL);
if (code != svgtiny_OK) {
fprintf(stderr, "svgtiny_parse failed: ");
switch (code) {