disabling import if file was already loaded

This commit is contained in:
Dmitry Stogov 2004-01-23 15:29:59 +00:00
parent 695436b709
commit 2a5593dd0d
2 changed files with 68 additions and 74 deletions

View File

@ -68,6 +68,50 @@ static void schema_cleanup(xmlNodePtr schema)
} }
} }
static void schema_load_file(sdlPtr sdl, xmlAttrPtr ns, xmlAttrPtr location, xmlAttrPtr tns, int import) {
if (location != NULL &&
!zend_hash_exists(&sdl->docs, location->children->content, strlen(location->children->content)+1)) {
xmlDocPtr doc;
xmlNodePtr schema;
xmlAttrPtr new_tns;
doc = xmlParseFile(location->children->content);
xmlCleanupParser();
if (doc == NULL) {
php_error(E_ERROR, "Error parsing schema (can't import schema from '%s')",location->children->content);
}
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);
}
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);
}
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);
}
} else {
new_tns = get_attribute(schema->properties, "targetNamespace");
if (new_tns == NULL) {
if (tns != NULL) {
xmlFreeDoc(doc);
xmlSetProp(schema, "targetNamespace", tns->children->content);
}
} 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);
}
}
zend_hash_add(&sdl->docs, location->children->content, strlen(location->children->content)+1, (void**)&doc, sizeof(xmlDocPtr), NULL);
load_schema(sdl, schema);
}
}
/* /*
2.6.1 xsi:type 2.6.1 xsi:type
2.6.2 xsi:nil 2.6.2 xsi:nil
@ -114,29 +158,7 @@ int load_schema(sdlPtr sdl,xmlNodePtr schema)
if (location == NULL) { if (location == NULL) {
php_error(E_ERROR, "Error parsing schema (include has no 'schemaLocation' attribute)"); php_error(E_ERROR, "Error parsing schema (include has no 'schemaLocation' attribute)");
} else { } else {
xmlDocPtr doc; schema_load_file(sdl,NULL,location,tns,0);
xmlNodePtr schema;
xmlAttrPtr new_tns;
doc = xmlParseFile(location->children->content);
xmlCleanupParser();
if (doc == NULL) {
php_error(E_ERROR, "Error parsing schema (can't include schema from '%s')",location->children->content);
}
schema = get_node(doc->children, "schema");
if (schema == NULL) {
php_error(E_ERROR, "Error parsing schema (can't include schema from '%s')",location->children->content);
}
new_tns = get_attribute(schema->properties, "targetNamespace");
if (new_tns == NULL) {
if (tns != NULL) {
xmlSetProp(schema, "targetNamespace", tns->children->content);
}
} else if (tns != NULL && strcmp(tns->children->content,new_tns->children->content) != 0) {
php_error(E_ERROR, "Error parsing schema (can't include schema from '%s', different 'targetNamespace')",location->children->content);
}
zend_hash_next_index_insert(&sdl->docs, (void**)&doc, sizeof(xmlDocPtr), NULL);
load_schema(sdl, schema);
} }
} else if (node_is_equal(trav,"redefine")) { } else if (node_is_equal(trav,"redefine")) {
@ -145,10 +167,11 @@ int load_schema(sdlPtr sdl,xmlNodePtr schema)
location = get_attribute(trav->properties, "schemaLocation"); location = get_attribute(trav->properties, "schemaLocation");
if (location == NULL) { if (location == NULL) {
php_error(E_ERROR, "Error parsing schema (redefine has no 'schemaLocation' attribute)"); php_error(E_ERROR, "Error parsing schema (redefine has no 'schemaLocation' attribute)");
} else {
schema_load_file(sdl,NULL,location,tns,0);
/* TODO: <redefine> support */
} }
/* TODO: <redefine> support */
} else if (node_is_equal(trav,"import")) { } else if (node_is_equal(trav,"import")) {
xmlAttrPtr ns, location; xmlAttrPtr ns, location;
@ -158,31 +181,7 @@ int load_schema(sdlPtr sdl,xmlNodePtr schema)
if (ns != NULL && tns != NULL && strcmp(ns->children->content,tns->children->content) == 0) { 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); php_error(E_ERROR, "Error parsing schema (can't import schema from '%s', namespace must not match the enclosing schema 'targetNamespace')",location->children->content);
} }
if (location != NULL) { schema_load_file(sdl,ns,location,tns,1);
xmlDocPtr doc;
xmlNodePtr schema;
xmlAttrPtr new_tns;
doc = xmlParseFile(location->children->content);
xmlCleanupParser();
if (doc == NULL) {
php_error(E_ERROR, "Error parsing schema (can't import schema from '%s')",location->children->content);
}
schema = get_node(doc->children, "schema");
if (schema == NULL) {
php_error(E_ERROR, "Error parsing schema (can't import schema from '%s')",location->children->content);
}
new_tns = get_attribute(schema->properties, "targetNamespace");
if (ns != NULL && (new_tns == NULL || strcmp(ns->children->content,new_tns->children->content) != 0)) {
php_error(E_ERROR, "Error parsing schema (can't include schema from '%s', unexpected 'targetNamespace'='%s')",location->children->content,new_tns->children->content);
}
if (ns == NULL && new_tns != NULL) {
php_error(E_ERROR, "Error parsing schema (can't include schema from '%s', unexpected 'targetNamespace'='%s')",location->children->content,new_tns->children->content);
}
zend_hash_next_index_insert(&sdl->docs, (void**)&doc, sizeof(xmlDocPtr), NULL);
load_schema(sdl, schema);
}
} else if (node_is_equal(trav,"annotation")) { } else if (node_is_equal(trav,"annotation")) {
/* TODO: <annotation> support */ /* TODO: <annotation> support */
/* annotation cleanup /* annotation cleanup

View File

@ -394,6 +394,10 @@ static void load_wsdl_ex(char *struri, sdlCtx *ctx, int include)
int old_error_reporting; int old_error_reporting;
TSRMLS_FETCH(); TSRMLS_FETCH();
if (zend_hash_exists(&tmpsdl->docs, struri, strlen(struri)+1)) {
return;
}
/* TODO: WSDL Caching */ /* TODO: WSDL Caching */
old_error_reporting = EG(error_reporting); old_error_reporting = EG(error_reporting);
@ -409,7 +413,7 @@ static void load_wsdl_ex(char *struri, sdlCtx *ctx, int include)
php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: Couldn't load from %s", struri); php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: Couldn't load from %s", struri);
} }
zend_hash_next_index_insert(&tmpsdl->docs, (void**)&wsdl, sizeof(xmlDocPtr), NULL); zend_hash_add(&tmpsdl->docs, struri, strlen(struri)+1, (void**)&wsdl, sizeof(xmlDocPtr), NULL);
root = wsdl->children; root = wsdl->children;
definitions = get_node(root, "definitions"); definitions = get_node(root, "definitions");
@ -453,8 +457,9 @@ static void load_wsdl_ex(char *struri, sdlCtx *ctx, int include)
} else if (strcmp(trav->name,"message") == 0) { } else if (strcmp(trav->name,"message") == 0) {
xmlAttrPtr name = get_attribute(trav->properties, "name"); xmlAttrPtr name = get_attribute(trav->properties, "name");
if (name && name->children && name->children->content) { if (name && name->children && name->children->content) {
zend_hash_add(&ctx->messages, name->children->content, strlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL); if (zend_hash_add(&ctx->messages, name->children->content, strlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
/* TODO: redeclaration handling */ php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL (message '%s' already defined)",name->children->content);
}
} else { } else {
php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <message> hasn't name attribute"); php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <message> hasn't name attribute");
} }
@ -462,8 +467,9 @@ static void load_wsdl_ex(char *struri, sdlCtx *ctx, int include)
} else if (strcmp(trav->name,"portType") == 0) { } else if (strcmp(trav->name,"portType") == 0) {
xmlAttrPtr name = get_attribute(trav->properties, "name"); xmlAttrPtr name = get_attribute(trav->properties, "name");
if (name && name->children && name->children->content) { if (name && name->children && name->children->content) {
zend_hash_add(&ctx->portTypes, name->children->content, strlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL); if (zend_hash_add(&ctx->portTypes, name->children->content, strlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
/* TODO: redeclaration handling */ php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL (portType '%s' already defined)",name->children->content);
}
} else { } else {
php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <portType> hasn't name attribute"); php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <portType> hasn't name attribute");
} }
@ -471,8 +477,9 @@ static void load_wsdl_ex(char *struri, sdlCtx *ctx, int include)
} else if (strcmp(trav->name,"binding") == 0) { } else if (strcmp(trav->name,"binding") == 0) {
xmlAttrPtr name = get_attribute(trav->properties, "name"); xmlAttrPtr name = get_attribute(trav->properties, "name");
if (name && name->children && name->children->content) { if (name && name->children && name->children->content) {
zend_hash_add(&ctx->bindings, name->children->content, strlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL); if (zend_hash_add(&ctx->bindings, name->children->content, strlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != NULL) {
/* TODO: redeclaration handling */ php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL (binding '%s' already defined)",name->children->content);
}
} else { } else {
php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <binding> hasn't name attribute"); php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <binding> hasn't name attribute");
} }
@ -480,8 +487,9 @@ static void load_wsdl_ex(char *struri, sdlCtx *ctx, int include)
} else if (strcmp(trav->name,"service") == 0) { } else if (strcmp(trav->name,"service") == 0) {
xmlAttrPtr name = get_attribute(trav->properties, "name"); xmlAttrPtr name = get_attribute(trav->properties, "name");
if (name && name->children && name->children->content) { if (name && name->children && name->children->content) {
zend_hash_add(&ctx->services, name->children->content, strlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL); if (zend_hash_add(&ctx->services, name->children->content, strlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
/* TODO: redeclaration handling */ php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL (service '%s' already defined)",name->children->content);
}
} else { } else {
php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <service> hasn't name attribute"); php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <service> hasn't name attribute");
} }
@ -519,19 +527,11 @@ static sdlPtr load_wsdl(char *struri)
zend_hash_internal_pointer_reset(&ctx.services); zend_hash_internal_pointer_reset(&ctx.services);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
xmlNodePtr *tmp, service; xmlNodePtr *tmp, service;
/*
xmlAttrPtr name;
*/
xmlNodePtr trav, port; xmlNodePtr trav, port;
zend_hash_get_current_data(&ctx.services, (void **)&tmp); zend_hash_get_current_data(&ctx.services, (void **)&tmp);
service = *tmp; service = *tmp;
/*
name = get_attribute(service->properties, "name");
if (!name) {
php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: No name associated with service");
}
*/
trav = service->children; trav = service->children;
FOREACHNODE(trav, "port", port) { FOREACHNODE(trav, "port", port) {
xmlAttrPtr type, name, bindingAttr, location; xmlAttrPtr type, name, bindingAttr, location;
@ -543,12 +543,7 @@ static sdlPtr load_wsdl(char *struri)
tmpbinding = malloc(sizeof(sdlBinding)); tmpbinding = malloc(sizeof(sdlBinding));
memset(tmpbinding, 0, sizeof(sdlBinding)); memset(tmpbinding, 0, sizeof(sdlBinding));
/*
name = get_attribute(port->properties, "name");
if (!name) {
php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: No name associated with port");
}
*/
bindingAttr = get_attribute(port->properties, "binding"); bindingAttr = get_attribute(port->properties, "binding");
if (bindingAttr == NULL) { if (bindingAttr == NULL) {
php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: No binding associated with port"); php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: No binding associated with port");