summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2016-08-23 17:09:57 (GMT)
committer Chris Young <chris@unsatisfactorysoftware.co.uk>2016-08-23 17:09:57 (GMT)
commit1231bc489c869b719f37bb66937cb7bd327afaf1 (patch)
tree9784178b05dc6c10d94119bf6787ef892805b0f1
parent7cef3ce8d0fd29f672da683787ef18e09b22ae57 (diff)
downloadlibdom-1231bc489c869b719f37bb66937cb7bd327afaf1.tar.gz
libdom-1231bc489c869b719f37bb66937cb7bd327afaf1.tar.bz2
Handle relative URIs properly
-rw-r--r--bindings/xml/expat_xmlparser.c11
-rw-r--r--bindings/xml/xmlparser.h4
2 files changed, 11 insertions, 4 deletions
diff --git a/bindings/xml/expat_xmlparser.c b/bindings/xml/expat_xmlparser.c
index 71215e1..e8ae21a 100644
--- a/bindings/xml/expat_xmlparser.c
+++ b/bindings/xml/expat_xmlparser.c
@@ -33,10 +33,12 @@ struct dom_xml_parser {
};
/* Parser callback */
-static int expat_xmlparser_parse_cb(void *parser, const char *data, int size)
+static int expat_xmlparser_parse_cb(void *parser, const char *data, int size, const char *uri)
{
enum XML_Status status;
+ XML_SetBase(parser, uri);
+
status = XML_Parse(parser, data, size, 0);
if (status != XML_STATUS_OK) {
XML_ParserFree(parser);
@@ -324,6 +326,8 @@ expat_xmlparser_external_entity_ref_handler(XML_Parser parser,
return XML_STATUS_OK;
}
+ /**\todo do we need to push a copy of xml_parser into our parser userdata here? */
+
subparser = XML_ExternalEntityParserCreate(parser, context, NULL);
if (subparser == NULL) {
@@ -445,6 +449,7 @@ expat_xmlparser_unknown_data_handler(void *_parser,
* \param msg Informational message function
* \param mctx Pointer to client-specific private data
* \param document DOM Document
+ * \param fetch_cb Callback to call for fetching entity refs
* \return Pointer to instance, or NULL on memory exhaustion
*
* int_enc is ignored due to it being made of bees.
@@ -452,7 +457,7 @@ 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_xml_parser_fetch_cb fetch_cb)
+ const char *url, dom_xml_parser_fetch_cb fetch_cb)
{
dom_xml_parser *parser;
dom_exception err;
@@ -500,6 +505,8 @@ dom_xml_parser_create(const char *enc, const char *int_enc,
XML_SetUserData(parser->parser, parser);
+ XML_SetBase(parser->parser, url);
+
XML_SetElementHandler(parser->parser,
expat_xmlparser_start_element_handler,
expat_xmlparser_end_element_handler);
diff --git a/bindings/xml/xmlparser.h b/bindings/xml/xmlparser.h
index 1e1edd7..66557e5 100644
--- a/bindings/xml/xmlparser.h
+++ b/bindings/xml/xmlparser.h
@@ -17,12 +17,12 @@
typedef struct dom_xml_parser dom_xml_parser;
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));
+ int (*expat_xmlparser_parse_cb)(void *parser, const char *data, int size, 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_xml_parser_fetch_cb fetch_cb);
+ const char *url, dom_xml_parser_fetch_cb fetch_cb);
/* Destroy an XML parser instance */
void dom_xml_parser_destroy(dom_xml_parser *parser);