rrichards               Tue Oct 11 23:20:14 2005 EDT

  Modified files:              
    /php-src/ext/xml    compat.c xml.c 
  Log:
  Fixed Bug #27908 (xml default_handlers not being called)
  Fix memleak when entitydecls are parsed
  remove old ifdefs
  
http://cvs.php.net/diff.php/php-src/ext/xml/compat.c?r1=1.44&r2=1.45&ty=u
Index: php-src/ext/xml/compat.c
diff -u php-src/ext/xml/compat.c:1.44 php-src/ext/xml/compat.c:1.45
--- php-src/ext/xml/compat.c:1.44       Wed Aug  3 10:08:21 2005
+++ php-src/ext/xml/compat.c    Tue Oct 11 23:20:13 2005
@@ -33,7 +33,6 @@
        ((__ns) != NULL && strlen(__ns) == 5 && *(__ns) == 'x' && *((__ns)+1) 
== 'm' && \
         *((__ns)+2) == 'l' && *((__ns)+3) == 'n' && *((__ns)+4) == 's')
 
-#if LIBXML_VERSION >= 20600 
 static void 
 _qualify_namespace(XML_Parser parser, const xmlChar *name, const xmlChar *URI, 
xmlChar **qualified)
 {
@@ -46,7 +45,6 @@
                *qualified = xmlStrdup(name);
        }
 }
-#endif
 
 static void
 _start_element_handler(void *user, const xmlChar *name, const xmlChar 
**attributes)
@@ -55,6 +53,25 @@
        xmlChar    *qualified_name = NULL;
 
        if (parser->h_start_element == NULL) {
+               if (parser->h_default) {
+                       int attno = 0;
+
+                       qualified_name = xmlStrncatNew((xmlChar *)"<", name, 
xmlStrlen(name));
+                       if (attributes) {
+                               while (attributes[attno] != NULL) {
+                                       qualified_name = 
xmlStrncat(qualified_name, (xmlChar *)" ", 1);
+                                       qualified_name = 
xmlStrcat(qualified_name, (xmlChar *)attributes[attno]);
+                                       qualified_name = 
xmlStrncat(qualified_name, (xmlChar *)"=\"", 2);
+                                       qualified_name = 
xmlStrcat(qualified_name, (xmlChar *)attributes[++attno]);
+                                       qualified_name = 
xmlStrncat(qualified_name, (xmlChar *)"\"", 1);
+                                       attno++;
+                               }
+
+                       }
+                       qualified_name = xmlStrncat(qualified_name, (xmlChar 
*)">", 1);
+                       parser->h_default(parser->user, (const XML_Char *) 
qualified_name, xmlStrlen(qualified_name));
+                       xmlFree(qualified_name);
+               }
                return;
        }
 
@@ -65,7 +82,6 @@
        xmlFree(qualified_name);
 }
 
-#if LIBXML_VERSION >= 20600 
 static void
 _start_element_handler_ns(void *user, const xmlChar *name, const xmlChar 
*prefix, const xmlChar *URI, int nb_namespaces, const xmlChar ** namespaces, 
int nb_attributes, int nb_defaulted, const xmlChar ** attributes)
 {
@@ -84,7 +100,7 @@
                y = 0;
        }
        
-       if (parser->h_start_element == NULL) {
+       if (parser->h_start_element == NULL && parser->h_default == NULL) {
                return;
        }
        _qualify_namespace(parser, name, URI, &qualified_name);
@@ -117,7 +133,6 @@
        }
        xmlFree(qualified_name);
 }
-#endif
 
 static void
 _namespace_handler(XML_Parser parser, xmlNsPtr nsptr)
@@ -135,6 +150,12 @@
        XML_Parser  parser = (XML_Parser) user;
 
        if (parser->h_end_element == NULL) {
+               if (parser->h_default) {
+                       qualified_name = xmlStrncatNew((xmlChar *)"</", name, 
xmlStrlen(name));
+                       qualified_name = xmlStrncat(qualified_name, (xmlChar 
*)">", 1);
+                       parser->h_default(parser->user, (const XML_Char *) 
qualified_name, xmlStrlen(qualified_name));
+                       xmlFree(qualified_name);
+               }
                return;
        }
        
@@ -145,7 +166,6 @@
        xmlFree(qualified_name);
 }
 
-#if LIBXML_VERSION >= 20600 
 static void
 _end_element_handler_ns(void *user, const xmlChar *name, const xmlChar * 
prefix, const xmlChar *URI)
 {
@@ -162,7 +182,6 @@
 
        xmlFree(qualified_name);
 }
-#endif
 
 static void
 _cdata_handler(void *user, const xmlChar *cdata, int cdata_len)
@@ -170,6 +189,9 @@
        XML_Parser parser = (XML_Parser) user;
 
        if (parser->h_cdata == NULL) {
+               if (parser->h_default) {
+                       parser->h_default(parser->user, (const XML_Char *) 
cdata, cdata_len);
+               }
                return;
        }
 
@@ -182,6 +204,16 @@
        XML_Parser parser = (XML_Parser) user;
 
        if (parser->h_pi == NULL) {
+               if (parser->h_default) {
+                       xmlChar    *full_pi;
+
+                       full_pi = xmlStrncatNew((xmlChar *)"<?", target, 
xmlStrlen(target));
+                       full_pi = xmlStrncat(full_pi, (xmlChar *)" ", 1);
+                       full_pi = xmlStrcat(full_pi, data);
+                       full_pi = xmlStrncat(full_pi, (xmlChar *)"?>", 2);
+                       parser->h_default(parser->user, (const XML_Char *) 
full_pi, xmlStrlen(full_pi));
+                       xmlFree(full_pi);
+               }
                return;
        }
 
@@ -335,16 +367,11 @@
        NULL,  /* getParameterEntity */
        _cdata_handler, /* cdataBlock */
        NULL, /* externalSubset */
-#if LIBXML_VERSION < 20600
-       1,
-#else
        XML_SAX2_MAGIC,
        NULL,
        _start_element_handler_ns,
        _end_element_handler_ns,
        NULL
-#endif
-       
 };
 
 PHPAPI XML_Parser 
@@ -390,16 +417,12 @@
        parser->parser->wellFormed = 0;
        if (sep != NULL) {
                parser->use_namespace = 1;
-#if LIBXML_VERSION >= 20600
                parser->parser->sax2 = 1;
-#endif
                parser->_ns_seperator = xmlStrdup(sep);
-#if LIBXML_VERSION >= 20600
        } else {
                /* Reset flag as XML_SAX2_MAGIC is needed for 
xmlCreatePushParserCtxt 
                so must be set in the handlers */
                parser->parser->sax->initialized = 1;
-#endif
        }
        return parser;
 }
@@ -480,9 +503,7 @@
 PHPAPI int
 XML_Parse(XML_Parser parser, const XML_Char *data, int data_len, int is_final)
 {
-#if LIBXML_VERSION >= 20600
        int error;
-#endif
 
 /* The following is a hack to keep BC with PHP 4 while avoiding 
 the inifite loop in libxml <= 2.6.17 which occurs when no encoding 
@@ -508,7 +529,6 @@
        }
 #endif
 
-#if LIBXML_VERSION >= 20600
        error = xmlParseChunk(parser->parser, data, data_len, is_final);
        if (!error) {
                return 1;
@@ -517,9 +537,6 @@
        } else {
                return 1;
        }
-#else
-       return !xmlParseChunk(parser->parser, data, data_len, is_final);
-#endif
 }
 
 PHPAPI int
@@ -684,6 +701,10 @@
                        xmlFree(parser->_ns_seperator);
                }
        }
+       if (parser->parser->myDoc) {
+               xmlFreeDoc(parser->parser->myDoc);
+               parser->parser->myDoc = NULL;
+       }
        xmlFreeParserCtxt(parser->parser);
        efree(parser);
 }
http://cvs.php.net/diff.php/php-src/ext/xml/xml.c?r1=1.158&r2=1.159&ty=u
Index: php-src/ext/xml/xml.c
diff -u php-src/ext/xml/xml.c:1.158 php-src/ext/xml/xml.c:1.159
--- php-src/ext/xml/xml.c:1.158 Thu Aug 11 19:36:01 2005
+++ php-src/ext/xml/xml.c       Tue Oct 11 23:20:13 2005
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: xml.c,v 1.158 2005/08/11 23:36:01 andrei Exp $ */
+/* $Id: xml.c,v 1.159 2005/10/12 03:20:13 rrichards Exp $ */
 
 #define IS_EXT_MODULE
 
@@ -1108,12 +1108,7 @@
    Create an XML parser */
 PHP_FUNCTION(xml_parser_create_ns)
 {
-#if defined(HAVE_LIBXML) && defined(HAVE_XML) && !defined(HAVE_LIBEXPAT) && 
LIBXML_VERSION < 20600 
-       php_error_docref(NULL TSRMLS_CC, E_WARNING, "is broken with libxml2 %s. 
Please upgrade to libxml2 2.6", LIBXML_DOTTED_VERSION);
-       RETURN_FALSE;
-#else
        php_xml_parser_create_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
-#endif
 }
 /* }}} */
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to