rrichards               Thu Nov 18 15:16:46 2004 EDT

  Modified files:              (Branch: PHP_5_0)
    /php-src/ext/xml    compat.c 
  Log:
  MFH: Fixed bug #30061 (xml_set_start_namespace_decl_handler not called)
  hopefully resolve a bunch of entity issues
  
http://cvs.php.net/diff.php/php-src/ext/xml/compat.c?r1=1.32.2.4&r2=1.32.2.5&ty=u
Index: php-src/ext/xml/compat.c
diff -u php-src/ext/xml/compat.c:1.32.2.4 php-src/ext/xml/compat.c:1.32.2.5
--- php-src/ext/xml/compat.c:1.32.2.4   Thu Nov 18 13:26:59 2004
+++ php-src/ext/xml/compat.c    Thu Nov 18 15:16:45 2004
@@ -76,6 +76,14 @@
        int z = 0;
        int y = 0;
        
+       if (nb_namespaces > 0 && parser->h_start_ns != NULL) {
+               for (i = 0; i < nb_namespaces; i += 1) {
+                       parser->h_start_ns(parser->user, (const XML_Char *) 
namespaces[y], (const XML_Char *) namespaces[y+1]);
+                       y += 2;
+               }
+               y = 0;
+       }
+       
        if (parser->h_start_element == NULL) {
                return;
        }
@@ -247,33 +255,49 @@
        (*entity)[*entity_len] = '\0';
 }
 
-static xmlEntityPtr
-_get_entity(void *user, const xmlChar *name)
+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;
 
-       if (parser->h_default) {
-               xmlChar *entity;
-               int      len;
-               
-               _build_entity(name, xmlStrlen(name), &entity, &len);
-               parser->h_default(parser->user, (const xmlChar *) entity, len);
-               xmlFree(entity);
+       if (parser->h_external_entity_ref == NULL) {
+               return;
        }
 
-       return NULL;
+       parser->h_external_entity_ref(parser, names, "", sys_id, pub_id);
 }
 
-static void
-_external_entity_ref_handler(void *user, const xmlChar *names, int type, const 
xmlChar *sys_id, const xmlChar *pub_id, xmlChar *content)
+static xmlEntityPtr
+_get_entity(void *user, const xmlChar *name)
 {
        XML_Parser parser = (XML_Parser) user;
+       xmlEntityPtr ret = NULL;
 
-       if (parser->h_external_entity_ref == NULL) {
-               return;
+       if (parser->parser->inSubset == 0) {
+               ret = xmlGetPredefinedEntity(name);
+               if (ret == NULL)
+                       ret = xmlGetDocEntity(parser->parser->myDoc, name);
+
+       
+               if (ret == NULL || (parser->parser->instate != 
XML_PARSER_ENTITY_VALUE && parser->parser->instate != 
XML_PARSER_ATTRIBUTE_VALUE)) {
+                       if (ret == NULL || ret->etype == 
XML_INTERNAL_GENERAL_ENTITY || ret->etype == XML_INTERNAL_PARAMETER_ENTITY || 
ret->etype == XML_INTERNAL_PREDEFINED_ENTITY) {
+                               if (parser->h_default) {
+                                       xmlChar *entity;
+                                       int      len;
+                                       
+                                       _build_entity(name, xmlStrlen(name), 
&entity, &len);
+                                       parser->h_default(parser->user, (const 
xmlChar *) entity, len);
+                                       xmlFree(entity);
+                               }
+                       } else {
+                               if (ret->etype == 
XML_EXTERNAL_GENERAL_PARSED_ENTITY) {
+                                       _external_entity_ref_handler(user, 
ret->name, ret->etype, ret->SystemID, ret->ExternalID, NULL);
+                               }
+                       }
+               }
        }
 
-       parser->h_external_entity_ref(parser, names, "", sys_id, pub_id);
+       return ret;
 }
 
 static xmlSAXHandler 
@@ -284,7 +308,7 @@
        NULL, /* hasExternalSubset */
        NULL, /* resolveEntity */
        _get_entity, /* getEntity */
-       _external_entity_ref_handler, /* entityDecl */
+       NULL, /* entityDecl */
        _notation_decl_handler,
        NULL, /* attributeDecl */
        NULL, /* elementDecl */
@@ -353,6 +377,7 @@
                parser->parser->charset = XML_CHAR_ENCODING_NONE;
        }
        parser->parser->replaceEntities = 1;
+       parser->parser->wellFormed = 0;
        if (sep != NULL) {
                parser->use_namespace = 1;
 #if LIBXML_VERSION >= 20600

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

Reply via email to