cvs: php4 /ext/xml compat.c expat_compat.h

From: Date: Sat, 17 May 2003 22:09:58 +0000
Subject: cvs: php4 /ext/xml compat.c expat_compat.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-21023@lists.php.net to get a copy of this message
sterling Sat May 17 18:09:58 2003 EDT Modified files: /php4/ext/xml compat.c expat_compat.h Log: send comments to the default handler like done with expat, add a setcommenthandler function, which exists in expat, but isn't used by the extension. Index: php4/ext/xml/compat.c diff -u php4/ext/xml/compat.c:1.7 php4/ext/xml/compat.c:1.8 --- php4/ext/xml/compat.c:1.7 Fri May 16 19:21:48 2003 +++ php4/ext/xml/compat.c Sat May 17 18:09:58 2003 @@ -183,6 +183,33 @@ } 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 @@ _cdata_handler, NULL, /* ignorableWhitespace */ _pi_handler, - NULL, /* comment */ + _comment_handler, /* comment */ NULL, /* warning */ NULL, /* error */ NULL /* fatalError */ @@ -273,7 +300,6 @@ 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) { @@ -318,6 +344,12 @@ XML_SetProcessingInstructionHandler(XML_Parser parser, XML_ProcessingInstructionHandler pi) { parser->h_pi = pi; +} + +void +XML_SetCommentHandler(XML_Parser parser, XML_CommentHandler comment) +{ + parser->h_comment = comment; } void Index: php4/ext/xml/expat_compat.h diff -u php4/ext/xml/expat_compat.h:1.5 php4/ext/xml/expat_compat.h:1.6 --- php4/ext/xml/expat_compat.h:1.5 Sun May 11 05:10:48 2003 +++ php4/ext/xml/expat_compat.h Sat May 17 18:09:58 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: expat_compat.h,v 1.5 2003/05/11 09:10:48 moriyoshi Exp $ */ +/* $Id: expat_compat.h,v 1.6 2003/05/17 22:09:58 sterling Exp $ */ #ifndef PHP_EXPAT_COMPAT_H #define PHP_EXPAT_COMPAT_H @@ -35,6 +35,7 @@ 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 @@ 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;

« previous php.cvs (#21023) next »