summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2016-08-22 22:35:39 (GMT)
committer Chris Young <chris@unsatisfactorysoftware.co.uk>2016-08-22 22:35:39 (GMT)
commit7cef3ce8d0fd29f672da683787ef18e09b22ae57 (patch)
tree1428eb218d89fc69de46134e67df7feeec572e48
parent13cec75b28d57040c03e0dc8151b8be0f0ac1bf6 (diff)
downloadlibdom-7cef3ce8d0fd29f672da683787ef18e09b22ae57.tar.gz
libdom-7cef3ce8d0fd29f672da683787ef18e09b22ae57.tar.bz2
Parse the fetched external entity.
There may be an issue here with parsing at a "random" time as the DOM binding has some context state information which is likely to be wrong. We may need to stop parsing until the reference is fetched. We need to ensure all references are parsed before destroying the parser too.
-rw-r--r--bindings/xml/expat_xmlparser.c42
-rw-r--r--bindings/xml/xmlparser.h4
2 files changed, 22 insertions, 24 deletions
diff --git a/bindings/xml/expat_xmlparser.c b/bindings/xml/expat_xmlparser.c
index 9b7d113..71215e1 100644
--- a/bindings/xml/expat_xmlparser.c
+++ b/bindings/xml/expat_xmlparser.c
@@ -32,6 +32,24 @@ struct dom_xml_parser {
dom_xml_parser_fetch_cb fetch_cb; /**< Callback to fetch external entities */
};
+/* Parser callback */
+static int expat_xmlparser_parse_cb(void *parser, const char *data, int size)
+{
+ enum XML_Status status;
+
+ status = XML_Parse(parser, data, size, 0);
+ if (status != XML_STATUS_OK) {
+ XML_ParserFree(parser);
+ return XML_STATUS_OK;
+ }
+
+ XML_Parse(parser, "", 0, 1);
+ XML_ParserFree(parser);
+
+ return XML_STATUS_OK;
+}
+
+
/* Binding functions */
static void
@@ -294,13 +312,6 @@ expat_xmlparser_external_entity_ref_handler(XML_Parser parser,
const XML_Char *public_id)
{
XML_Parser subparser;
- unsigned char data[1024];
- size_t len;
- enum XML_Status status;
-
- UNUSED(data);
- UNUSED(len);
- UNUSED(status);
UNUSED(public_id);
@@ -319,23 +330,10 @@ expat_xmlparser_external_entity_ref_handler(XML_Parser parser,
return XML_STATUS_OK;
}
- if(xml_parser->fetch_cb(subparser, base, system_id) == false)
+ if(xml_parser->fetch_cb(subparser, base, system_id, expat_xmlparser_parse_cb) == 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);
- return XML_STATUS_OK;
- }
- }
-#endif
- XML_Parse(subparser, "", 0, 1);
- XML_ParserFree(subparser);
-
+// add 1
return XML_STATUS_OK;
}
diff --git a/bindings/xml/xmlparser.h b/bindings/xml/xmlparser.h
index 36b6848..1e1edd7 100644
--- a/bindings/xml/xmlparser.h
+++ b/bindings/xml/xmlparser.h
@@ -16,8 +16,8 @@
#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);
+typedef int (*dom_xml_parser_fetch_cb)(void *parser, const char *base, const char *uri,
+ int (*expat_xmlparser_parse_cb)(void *parser, const char *data, int size));
/* Create an XML parser instance */
dom_xml_parser *dom_xml_parser_create(const char *enc, const char *int_enc,