summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/xml/compat.c36
-rw-r--r--ext/xml/expat_compat.h2
2 files changed, 36 insertions, 2 deletions
diff --git a/ext/xml/compat.c b/ext/xml/compat.c
index 3a63a69088..9b9b1c4127 100644
--- a/ext/xml/compat.c
+++ b/ext/xml/compat.c
@@ -183,6 +183,33 @@ _notation_decl_handler(void *user, const xmlChar *notation, const xmlChar *sys_i
}
static void
+_build_comment(const xmlChar *data, int data_len, xmlChar **comment, int *comment_len)
+{
+ *comment_len = data_len + 6;
+
+ *comment = emalloc(*comment_len + 1);
+ memcpy(*comment, "<--", 3);
+ memcpy(*comment + 3, data, data_len);
+ memcpy(*comment + 3 + data_len, "-->", 3);
+
+ (*comment)[*comment_len] = '\0';
+}
+
+static void
+_comment_handler(void *user, const xmlChar *comment)
+{
+ XML_Parser parser = (XML_Parser) user;
+
+ if (parser->h_default) {
+ xmlChar *d_comment;
+ int d_comment_len;
+
+ _build_comment(comment, xmlStrlen(comment), &d_comment, &d_comment_len);
+ parser->h_default(parser->user, d_comment, d_comment_len);
+ }
+}
+
+static void
_external_entity_ref_handler(void *user, const xmlChar *names, int type, const xmlChar *sys_id, const xmlChar *pub_id, xmlChar *content)
{
XML_Parser parser = (XML_Parser) user;
@@ -216,7 +243,7 @@ php_xml_compat_handlers = {
_cdata_handler,
NULL, /* ignorableWhitespace */
_pi_handler,
- NULL, /* comment */
+ _comment_handler, /* comment */
NULL, /* warning */
NULL, /* error */
NULL /* fatalError */
@@ -273,7 +300,6 @@ XML_ParserCreate_MM(const XML_Char *encoding, const XML_Memory_Handling_Suite *m
parser->mem_hdlrs = *memsuite;
parser->parser = xmlCreatePushParserCtxt((xmlSAXHandlerPtr) &php_xml_compat_handlers, (void *) parser, NULL, 0, NULL);
if (parser->parser == NULL) {
- parser->mem_hdlrs.free_fcn(parser->parser);
return NULL;
}
if (encoding != NULL) {
@@ -320,6 +346,12 @@ XML_SetProcessingInstructionHandler(XML_Parser parser, XML_ProcessingInstruction
parser->h_pi = pi;
}
+void
+XML_SetCommentHandler(XML_Parser parser, XML_CommentHandler comment)
+{
+ parser->h_comment = comment;
+}
+
void
XML_SetDefaultHandler(XML_Parser parser, XML_DefaultHandler d)
{
diff --git a/ext/xml/expat_compat.h b/ext/xml/expat_compat.h
index 1926afae28..0ac445743e 100644
--- a/ext/xml/expat_compat.h
+++ b/ext/xml/expat_compat.h
@@ -35,6 +35,7 @@ typedef void (*XML_StartElementHandler)(void *, const XML_Char *, const XML_Char
typedef void (*XML_EndElementHandler)(void *, const XML_Char *);
typedef void (*XML_CharacterDataHandler)(void *, const XML_Char *, int);
typedef void (*XML_ProcessingInstructionHandler)(void *, const XML_Char *, const XML_Char *);
+typedef void (*XML_CommentHandler)(void *, const XML_Char *);
typedef void (*XML_DefaultHandler)(void *, const XML_Char *, int);
typedef void (*XML_UnparsedEntityDeclHandler)(void *, const XML_Char *, const XML_Char *, const XML_Char *, const XML_Char *, const XML_Char *);
typedef void (*XML_NotationDeclHandler)(void *, const XML_Char *, const XML_Char *, const XML_Char *, const XML_Char *);
@@ -63,6 +64,7 @@ typedef struct _XML_Parser {
XML_EndElementHandler h_end_element;
XML_CharacterDataHandler h_cdata;
XML_ProcessingInstructionHandler h_pi;
+ XML_CommentHandler h_comment;
XML_DefaultHandler h_default;
XML_UnparsedEntityDeclHandler h_unparsed_entity_decl;
XML_NotationDeclHandler h_notation_decl;