]> granicus.if.org Git - php/commitdiff
Support for relative path in WSDL and XML Schema <import>
authorDmitry Stogov <dmitry@php.net>
Tue, 27 Jan 2004 15:48:19 +0000 (15:48 +0000)
committerDmitry Stogov <dmitry@php.net>
Tue, 27 Jan 2004 15:48:19 +0000 (15:48 +0000)
ext/soap/php_schema.c
ext/soap/php_sdl.c

index d2ab5ffb2f16fbe4338bdcfa561249d451597510..298eae1b4862fce1dc1fc1956e73511021743a55 100644 (file)
@@ -1,4 +1,5 @@
 #include "php_soap.h"
+#include "libxml/uri.h"
 
 static int schema_simpleType(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr simpleType, sdlTypePtr cur_type);
 static int schema_complexType(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr compType, sdlTypePtr cur_type);
@@ -135,32 +136,32 @@ static void schema_cleanup(xmlNodePtr schema)
        }
 }
 
-static void schema_load_file(sdlPtr sdl, xmlAttrPtr ns, xmlAttrPtr location, xmlAttrPtr tns, int import) {
+static void schema_load_file(sdlPtr sdl, xmlAttrPtr ns, xmlChar *location, xmlAttrPtr tns, int import) {
        if (location != NULL &&
-           !zend_hash_exists(&sdl->docs, location->children->content, strlen(location->children->content)+1)) {
+           !zend_hash_exists(&sdl->docs, location, strlen(location)+1)) {
                xmlDocPtr doc;
                xmlNodePtr schema;
                xmlAttrPtr new_tns;
 
-               doc = xmlParseFile(location->children->content);
+               doc = xmlParseFile(location);
                xmlCleanupParser();
                if (doc == NULL) {
-                       php_error(E_ERROR, "Error parsing schema (can't import schema from '%s')",location->children->content);
+                       php_error(E_ERROR, "Error parsing schema (can't import schema from '%s')",location);
                }
                schema = get_node(doc->children, "schema");
                if (schema == NULL) {
                        xmlFreeDoc(doc);
-                       php_error(E_ERROR, "Error parsing schema (can't import schema from '%s')",location->children->content);
+                       php_error(E_ERROR, "Error parsing schema (can't import schema from '%s')",location);
                }
                new_tns = get_attribute(schema->properties, "targetNamespace");
                if (import) {
                        if (ns != NULL && (new_tns == NULL || strcmp(ns->children->content,new_tns->children->content) != 0)) {
                                xmlFreeDoc(doc);
-                               php_error(E_ERROR, "Error parsing schema (can't import schema from '%s', unexpected 'targetNamespace'='%s')",location->children->content,new_tns->children->content);
+                               php_error(E_ERROR, "Error parsing schema (can't import schema from '%s', unexpected 'targetNamespace'='%s')",location,new_tns->children->content);
                        }
                        if (ns == NULL && new_tns != NULL) {
                                xmlFreeDoc(doc);
-                               php_error(E_ERROR, "Error parsing schema (can't import schema from '%s', unexpected 'targetNamespace'='%s')",location->children->content,new_tns->children->content);
+                               php_error(E_ERROR, "Error parsing schema (can't import schema from '%s', unexpected 'targetNamespace'='%s')",location,new_tns->children->content);
                        }
                } else {
                        new_tns = get_attribute(schema->properties, "targetNamespace");
@@ -171,10 +172,10 @@ static void schema_load_file(sdlPtr sdl, xmlAttrPtr ns, xmlAttrPtr location, xml
                                }
                        } else if (tns != NULL && strcmp(tns->children->content,new_tns->children->content) != 0) {
                                xmlFreeDoc(doc);
-                               php_error(E_ERROR, "Error parsing schema (can't include schema from '%s', different 'targetNamespace')",location->children->content);
+                               php_error(E_ERROR, "Error parsing schema (can't include schema from '%s', different 'targetNamespace')",location);
                        }
                }
-               zend_hash_add(&sdl->docs, location->children->content, strlen(location->children->content)+1, (void**)&doc, sizeof(xmlDocPtr), NULL);
+               zend_hash_add(&sdl->docs, location, strlen(location)+1, (void**)&doc, sizeof(xmlDocPtr), NULL);
                load_schema(sdl, schema);
        }
 }
@@ -225,7 +226,17 @@ int load_schema(sdlPtr sdl,xmlNodePtr schema)
                        if (location == NULL) {
                                php_error(E_ERROR, "Error parsing schema (include has no 'schemaLocation' attribute)");
                        } else {
-                               schema_load_file(sdl,NULL,location,tns,0);
+                         xmlChar *uri;
+                               xmlChar *base = xmlNodeGetBase(trav->doc, trav);
+
+                               if (base == NULL) {
+                           uri = xmlBuildURI(location->children->content, trav->doc->URL);
+                               } else {
+                       uri = xmlBuildURI(location->children->content, base);
+                           xmlFree(base);
+                               }
+                               schema_load_file(sdl,NULL,uri,tns,0);
+                   xmlFree(uri);
                        }
 
                } else if (node_is_equal(trav,"redefine")) {
@@ -235,12 +246,23 @@ int load_schema(sdlPtr sdl,xmlNodePtr schema)
                        if (location == NULL) {
                                php_error(E_ERROR, "Error parsing schema (redefine has no 'schemaLocation' attribute)");
                        } else {
-                               schema_load_file(sdl,NULL,location,tns,0);
+                         xmlChar *uri;
+                               xmlChar *base = xmlNodeGetBase(trav->doc, trav);
+
+                               if (base == NULL) {
+                           uri = xmlBuildURI(location->children->content, trav->doc->URL);
+                               } else {
+                       uri = xmlBuildURI(location->children->content, base);
+                           xmlFree(base);
+                               }
+                               schema_load_file(sdl,NULL,uri,tns,0);
+                   xmlFree(uri);
                                /* TODO: <redefine> support */
                        }
 
                } else if (node_is_equal(trav,"import")) {
                        xmlAttrPtr ns, location;
+                 xmlChar *uri = NULL;
 
                        ns = get_attribute(trav->properties, "namespace");
                        location = get_attribute(trav->properties, "schemaLocation");
@@ -248,7 +270,18 @@ int load_schema(sdlPtr sdl,xmlNodePtr schema)
                        if (ns != NULL && tns != NULL && strcmp(ns->children->content,tns->children->content) == 0) {
                                php_error(E_ERROR, "Error parsing schema (can't import schema from '%s', namespace must not match the enclosing schema 'targetNamespace')",location->children->content);
                        }
-                       schema_load_file(sdl,ns,location,tns,1);
+                       if (location) {
+                               xmlChar *base = xmlNodeGetBase(trav->doc, trav);
+
+                               if (base == NULL) {
+                           uri = xmlBuildURI(location->children->content, trav->doc->URL);
+                               } else {
+                       uri = xmlBuildURI(location->children->content, base);
+                           xmlFree(base);
+                               }
+                       } 
+                       schema_load_file(sdl,ns,uri,tns,1);
+                 if (uri != NULL) {xmlFree(uri);}
                } else if (node_is_equal(trav,"annotation")) {
                        /* TODO: <annotation> support */
 /* annotation cleanup
index 0077ee5a1c9df4f1a7424aaa49054307d4b3b04f..c12b8b22fa92d02f3477d89a02c9976668725001 100644 (file)
@@ -1,4 +1,5 @@
 #include "php_soap.h"
+#include "libxml/uri.h"
 
 typedef struct sdlCtx {
        sdlPtr root;
@@ -198,7 +199,17 @@ static void load_wsdl_ex(char *struri, sdlCtx *ctx, int include)
                                /* TODO: namespace ??? */
                                xmlAttrPtr tmp = get_attribute(trav->properties, "location");
                                if (tmp) {
-                                       load_wsdl_ex(tmp->children->content, ctx, 1);
+                                 xmlChar *uri;
+                                       xmlChar *base = xmlNodeGetBase(trav->doc, trav);
+
+                                       if (base == NULL) {
+                                   uri = xmlBuildURI(tmp->children->content, trav->doc->URL);
+                                       } else {
+                               uri = xmlBuildURI(tmp->children->content, base);
+                                   xmlFree(base);
+                                       }
+                                       load_wsdl_ex(uri, ctx, 1);
+                           xmlFree(uri);
                                }
 
                        } else if (strcmp(trav->name,"message") == 0) {