summaryrefslogtreecommitdiff
path: root/content/handlers/image/svg.c
diff options
context:
space:
mode:
Diffstat (limited to 'content/handlers/image/svg.c')
-rw-r--r--content/handlers/image/svg.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/content/handlers/image/svg.c b/content/handlers/image/svg.c
index b81f510..5cd3883 100644
--- a/content/handlers/image/svg.c
+++ b/content/handlers/image/svg.c
@@ -46,21 +46,33 @@ typedef struct svg_content {
int current_height;
} svg_content;
-
+struct svg_fetch_cb_data
+{
+ void *parser;
+ int (*cb)(void *parser, const char *data, int size);
+};
/** Callback for hlcache fetch */
static nserror svg_fetch_hlcache_cb(hlcache_handle *handle,
- const hlcache_event *event,
- void *parser)
+ const hlcache_event *event, void *userdata)
{
+ unsigned long size = 0;
+ const char *data;
+ struct svg_fetch_cb_data *cb_userdata = userdata;
+
switch (event->type) {
case CONTENT_MSG_DONE:
LOG("external entity '%s' retrieved", nsurl_access(hlcache_handle_get_url(handle)));
+ data = content_get_source_data(handle, &size);
+ cb_userdata->cb(cb_userdata->parser, data, size);
+ hlcache_handle_release(handle);
+ free(userdata);
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);
+ free(userdata);
break;
default:
@@ -71,23 +83,35 @@ static nserror svg_fetch_hlcache_cb(hlcache_handle *handle,
}
/** Callback for libsvgtiny fetch */
-static int svg_fetch_cb(void *parser, const char *base, const char *uri)
+static int svg_fetch_cb(void *parser, const char *base, const char *uri,
+ int (*svgtiny_expat_xmlparser_parse_cb)(void *parser, const char *data, int size))
{
nsurl *x_ent;
nserror ret;
hlcache_handle *handle;
+ struct svg_fetch_cb_data *userdata;
LOG("Fetching external entity reference %s", uri);
+ userdata = malloc(sizeof(struct svg_fetch_cb_data));
+ if (userdata == NULL) {
+ return false;
+ }
+
+ userdata->parser = parser;
+ userdata->cb = svgtiny_expat_xmlparser_parse_cb;
+
/* create url */
+ /**\todo this should be nsurl_joining base+uri */
ret = nsurl_create(uri, &x_ent);
if (ret != NSERROR_OK) {
+ free(userdata);
return false;
}
ret = hlcache_handle_retrieve(x_ent, 0, NULL, NULL,
svg_fetch_hlcache_cb,
- parser, /* data */
+ userdata, /* data */
NULL, CONTENT_ANY,
&handle);
nsurl_unref(x_ent);