dmitry          Tue Oct  3 07:00:35 2006 UTC

  Added files:                 (Branch: PHP_5_2)
    /php-src/ext/soap/tests     typemap013.phpt 

  Modified files:              
    /php-src/ext/soap   php_encoding.c 
  Log:
  Fixed possible crash with default namespaces
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/soap/php_encoding.c?r1=1.103.2.21.2.10&r2=1.103.2.21.2.11&diff_format=u
Index: php-src/ext/soap/php_encoding.c
diff -u php-src/ext/soap/php_encoding.c:1.103.2.21.2.10 
php-src/ext/soap/php_encoding.c:1.103.2.21.2.11
--- php-src/ext/soap/php_encoding.c:1.103.2.21.2.10     Wed Sep 20 13:42:50 2006
+++ php-src/ext/soap/php_encoding.c     Tue Oct  3 07:00:35 2006
@@ -17,7 +17,7 @@
   |          Dmitry Stogov <[EMAIL PROTECTED]>                             |
   +----------------------------------------------------------------------+
 */
-/* $Id: php_encoding.c,v 1.103.2.21.2.10 2006/09/20 13:42:50 dmitry Exp $ */
+/* $Id: php_encoding.c,v 1.103.2.21.2.11 2006/10/03 07:00:35 dmitry Exp $ */
 
 #include <time.h>
 
@@ -3035,6 +3035,43 @@
        smart_str_free(&nstype);
 }
 
+static xmlNsPtr xmlSearchNsPrefixByHref(xmlDocPtr doc, xmlNodePtr node, const 
xmlChar * href)
+{
+       xmlNsPtr cur;
+       xmlNodePtr orig = node;
+
+       while (node) {
+               if (node->type == XML_ENTITY_REF_NODE ||
+                   node->type == XML_ENTITY_NODE ||
+                   node->type == XML_ENTITY_DECL) {
+                       return NULL;
+               }
+               if (node->type == XML_ELEMENT_NODE) {
+                       cur = node->nsDef;
+                       while (cur != NULL) {
+                               if (cur->prefix && cur->href && 
xmlStrEqual(cur->href, href)) {
+                                       if (xmlSearchNs(doc, node, cur->prefix) 
== cur) {
+                                               return cur;
+                                       }
+                               }
+                               cur = cur->next;
+                       }
+                       if (orig != node) {
+                               cur = node->ns;
+                               if (cur != NULL) {
+                                       if (cur->prefix && cur->href && 
xmlStrEqual(cur->href, href)) {
+                                               if (xmlSearchNs(doc, node, 
cur->prefix) == cur) {
+                                                       return cur;
+                                               }
+                                       }
+                               }
+                       }    
+               }
+               node = node->parent;
+       }
+       return NULL;
+}
+
 xmlNsPtr encode_add_ns(xmlNodePtr node, const char* ns)
 {
        xmlNsPtr xmlns;
@@ -3044,6 +3081,9 @@
        }
 
        xmlns = xmlSearchNsByHref(node->doc, node, BAD_CAST(ns));
+       if (xmlns != NULL && xmlns->prefix == NULL) {
+               xmlns = xmlSearchNsPrefixByHref(node->doc, node, BAD_CAST(ns));
+       }
        if (xmlns == NULL) {
                xmlChar* prefix;
                TSRMLS_FETCH();
@@ -3054,9 +3094,19 @@
                        smart_str prefix = {0};
                        int num = ++SOAP_GLOBAL(cur_uniq_ns);
 
-                       smart_str_appendl(&prefix, "ns", 2);
-                       smart_str_append_long(&prefix, num);
-                       smart_str_0(&prefix);
+                       while (1) {
+                               smart_str_appendl(&prefix, "ns", 2);
+                               smart_str_append_long(&prefix, num);
+                               smart_str_0(&prefix);
+                               if (xmlSearchNs(node->doc, node, 
BAD_CAST(prefix.c)) == NULL) {
+                                       break;
+                               }
+                               smart_str_free(&prefix);
+                               prefix.c = NULL;
+                               prefix.len = 0;
+                               num = ++SOAP_GLOBAL(cur_uniq_ns);
+                       }
+
                        xmlns = xmlNewNs(node->doc->children, BAD_CAST(ns), 
BAD_CAST(prefix.c));
                        smart_str_free(&prefix);
                }

http://cvs.php.net/viewvc.cgi/php-src/ext/soap/tests/typemap013.phpt?view=markup&rev=1.1
Index: php-src/ext/soap/tests/typemap013.phpt
+++ php-src/ext/soap/tests/typemap013.phpt

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

Reply via email to