summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2016-08-22 18:18:26 (GMT)
committer Chris Young <chris@unsatisfactorysoftware.co.uk>2016-08-22 18:18:26 (GMT)
commit13cec75b28d57040c03e0dc8151b8be0f0ac1bf6 (patch)
tree9e17a7b74f83b5ada2d8c0f05c79940a887425ac
parent54c4309526e18a26a7b5b1fb4fdd5b7b7f1d304d (diff)
downloadlibdom-13cec75b28d57040c03e0dc8151b8be0f0ac1bf6.tar.gz
libdom-13cec75b28d57040c03e0dc8151b8be0f0ac1bf6.tar.bz2
Fetch external entities for libexpat/svg through the proper channels.
This currently does fetching, but not parsing.
-rw-r--r--bindings/xml/expat_xmlparser.c30
-rw-r--r--bindings/xml/xmlparser.h5
2 files changed, 23 insertions, 12 deletions
diff --git a/bindings/xml/expat_xmlparser.c b/bindings/xml/expat_xmlparser.c
index e1c22ad..9b7d113 100644
--- a/bindings/xml/expat_xmlparser.c
+++ b/bindings/xml/expat_xmlparser.c
@@ -29,6 +29,7 @@ struct dom_xml_parser {
struct dom_document *doc; /**< DOM Document we're building */
struct dom_node *current; /**< DOM node we're currently building */
bool is_cdata; /**< If the character data is cdata or text */
+ dom_xml_parser_fetch_cb fetch_cb; /**< Callback to fetch external entities */
};
/* Binding functions */
@@ -292,44 +293,49 @@ expat_xmlparser_external_entity_ref_handler(XML_Parser parser,
const XML_Char *system_id,
const XML_Char *public_id)
{
- FILE *fh;
XML_Parser subparser;
unsigned char data[1024];
size_t len;
enum XML_Status status;
- UNUSED(base);
+ UNUSED(data);
+ UNUSED(len);
+ UNUSED(status);
+
UNUSED(public_id);
if (system_id == NULL)
return XML_STATUS_OK;
- fh = fopen(system_id, "r");
+ struct dom_xml_parser *xml_parser = XML_GetUserData(parser);
- if (fh == NULL)
+ if (xml_parser->fetch_cb == NULL) {
return XML_STATUS_OK;
+ }
- subparser = XML_ExternalEntityParserCreate(parser,
- context,
- NULL);
+ subparser = XML_ExternalEntityParserCreate(parser, context, NULL);
if (subparser == NULL) {
- fclose(fh);
return XML_STATUS_OK;
}
+
+ if(xml_parser->fetch_cb(subparser, base, system_id) == false)
+ return XML_STATUS_OK;
+
+#if 0
/* Parse the file bit by bit */
while ((len = fread(data, 1, 1024, fh)) > 0) {
status = XML_Parse(subparser, (const char *)data, len, 0);
if (status != XML_STATUS_OK) {
XML_ParserFree(subparser);
- fclose(fh);
return XML_STATUS_OK;
}
}
+#endif
XML_Parse(subparser, "", 0, 1);
XML_ParserFree(subparser);
- fclose(fh);
+
return XML_STATUS_OK;
}
@@ -447,7 +453,8 @@ expat_xmlparser_unknown_data_handler(void *_parser,
*/
dom_xml_parser *
dom_xml_parser_create(const char *enc, const char *int_enc,
- dom_msg msg, void *mctx, dom_document **document)
+ dom_msg msg, void *mctx, dom_document **document,
+ dom_xml_parser_fetch_cb fetch_cb)
{
dom_xml_parser *parser;
dom_exception err;
@@ -460,6 +467,7 @@ dom_xml_parser_create(const char *enc, const char *int_enc,
return NULL;
}
+ parser->fetch_cb = fetch_cb;
parser->msg = msg;
parser->mctx = mctx;
diff --git a/bindings/xml/xmlparser.h b/bindings/xml/xmlparser.h
index d9bd07b..36b6848 100644
--- a/bindings/xml/xmlparser.h
+++ b/bindings/xml/xmlparser.h
@@ -16,10 +16,13 @@
#include "xmlerror.h"
typedef struct dom_xml_parser dom_xml_parser;
+typedef int (*dom_xml_parser_fetch_cb)(void *parser, const char *base,
+ const char *uri);
/* Create an XML parser instance */
dom_xml_parser *dom_xml_parser_create(const char *enc, const char *int_enc,
- dom_msg msg, void *mctx, dom_document **document);
+ dom_msg msg, void *mctx, dom_document **document,
+ dom_xml_parser_fetch_cb fetch_cb);
/* Destroy an XML parser instance */
void dom_xml_parser_destroy(dom_xml_parser *parser);