php-src/ext/soap/php_schema.c

1074 lines
31 KiB
C
Raw Normal View History

#include "php_soap.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);
static int schema_sequence(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr seqType, sdlTypePtr cur_type);
static int schema_list(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr listType, sdlTypePtr cur_type);
static int schema_union(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr unionType, sdlTypePtr cur_type);
static int schema_simpleContent(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr simpCompType, sdlTypePtr cur_type);
static int schema_restriction_simpleType(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr restType, sdlTypePtr cur_type);
static int schema_restriction_simpleContent(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr restType, sdlTypePtr cur_type);
static int schema_restriction_complexContent(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr restType, sdlTypePtr cur_type);
2004-01-06 17:14:30 +00:00
static int schema_extension_simpleContent(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr extType, sdlTypePtr cur_type);
static int schema_extension_complexContent(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr extType, sdlTypePtr cur_type);
static int schema_all(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr extType, sdlTypePtr cur_type);
static int schema_group(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr groupType, sdlTypePtr cur_type);
static int schema_choice(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr choiceType, sdlTypePtr cur_type);
static int schema_element(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr element, sdlTypePtr cur_type);
static int schema_attribute(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr attrType, sdlTypePtr cur_type);
static int schema_any(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr extType, sdlTypePtr cur_type);
static int schema_restriction_var_int(xmlNodePtr val, sdlRestrictionIntPtr *valptr);
static int schema_restriction_var_char(xmlNodePtr val, sdlRestrictionCharPtr *valptr);
/*
2.6.1 xsi:type
2.6.2 xsi:nil
2.6.3 xsi:schemaLocation, xsi:noNamespaceSchemaLocation
*/
/*
<schema
attributeFormDefault = (qualified | unqualified) : unqualified
blockDefault = (#all | List of (extension | restriction | substitution)) : ''
elementFormDefault = (qualified | unqualified) : unqualified
finalDefault = (#all | List of (extension | restriction)) : ''
id = ID
targetNamespace = anyURI
version = token
xml:lang = language
{any attributes with non-schema namespace . . .}>
Content: ((include | import | redefine | annotation)*, (((simpleType | complexType | group | attributeGroup) | element | attribute | notation), annotation*)*)
</schema>
*/
int load_schema(sdlPtr *sdl,xmlNodePtr schema)
{
xmlNodePtr trav, element, compType, simpleType, attribute;
xmlAttrPtr tns;
2004-01-06 17:14:30 +00:00
if(!(*sdl)->types) {
(*sdl)->types = malloc(sizeof(HashTable));
zend_hash_init((*sdl)->types, 0, NULL, delete_type, 1);
}
tns = get_attribute(schema->properties, "targetNamespace");
trav = schema->children;
2004-01-06 17:14:30 +00:00
FOREACHNODE(trav,"complexType",compType) {
schema_complexType(sdl, tns, compType, NULL);
}
ENDFOREACH(trav);
trav = schema->children;
2004-01-06 17:14:30 +00:00
FOREACHNODE(trav,"simpleType",simpleType) {
schema_simpleType(sdl, tns, simpleType, NULL);
}
ENDFOREACH(trav);
trav = schema->children;
2004-01-06 17:14:30 +00:00
FOREACHNODE(trav,"element",element) {
schema_element(sdl, tns, element, NULL);
}
ENDFOREACH(trav);
trav = schema->children;
2004-01-06 17:14:30 +00:00
FOREACHNODE(trav, "attribute", attribute) {
schema_attribute(sdl, tns, attribute, NULL);
}
ENDFOREACH(trav);
return FALSE;
}
/*
<simpleType
final = (#all | (list | union | restriction))
id = ID
name = NCName
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (restriction | list | union))
</simpleType>
*/
static int schema_simpleType(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr simpleType, sdlTypePtr cur_type)
{
xmlNodePtr content;
xmlAttrPtr name, ns;
ns = get_attribute(simpleType->properties, "targetNamespace");
2004-01-06 17:14:30 +00:00
if(ns == NULL) {
ns = tsn;
2004-01-06 17:14:30 +00:00
}
name = get_attribute(simpleType->properties, "name");
2004-01-06 17:14:30 +00:00
if(name != NULL) {
HashTable *ht;
2002-08-07 03:03:09 +00:00
smart_str key = {0};
sdlTypePtr newType, *ptr;
newType = malloc(sizeof(sdlType));
memset(newType, 0, sizeof(sdlType));
newType->name = strdup(name->children->content);
newType->namens = strdup(ns->children->content);
2004-01-06 17:14:30 +00:00
if(cur_type == NULL) {
ht = (*sdl)->types;
2002-08-07 03:03:09 +00:00
smart_str_appends(&key, newType->namens);
smart_str_appendc(&key, ':');
smart_str_appends(&key, newType->name);
smart_str_0(&key);
2004-01-06 17:14:30 +00:00
} else {
if(cur_type->elements == NULL) {
cur_type->elements = malloc(sizeof(HashTable));
zend_hash_init(cur_type->elements, 0, NULL, delete_type, 1);
}
ht = cur_type->elements;
2002-08-07 03:03:09 +00:00
smart_str_appends(&key, cur_type->name);
smart_str_0(&key);
}
2002-08-07 03:03:09 +00:00
zend_hash_add(ht, key.c, key.len + 1, &newType, sizeof(sdlTypePtr), (void **)&ptr);
cur_type = (*ptr);
2004-01-06 17:14:30 +00:00
create_encoder((*sdl), cur_type, ns->children->content, name->children->content);
2002-08-07 03:03:09 +00:00
smart_str_free(&key);
}
content = get_node(simpleType->children, "restriction");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_restriction_simpleType(sdl, tsn, content, cur_type);
return TRUE;
}
content = get_node(simpleType->children, "list");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_list(sdl, tsn, content, cur_type);
return TRUE;
}
content = get_node(simpleType->children, "union");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_union(sdl, tsn, content, cur_type);
return TRUE;
}
return FALSE;
}
/*
<list
id = ID
itemType = QName
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (simpleType?))
</list>
*/
static int schema_list(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr listType, sdlTypePtr cur_type)
{
return TRUE;
}
/*
<union
id = ID
memberTypes = List of QName
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (simpleType*))
</union>
*/
static int schema_union(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr unionType, sdlTypePtr cur_type)
{
return TRUE;
}
/*
<simpleContent
id = ID
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (restriction | extension))
</simpleContent>
*/
static int schema_simpleContent(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr simpCompType, sdlTypePtr cur_type)
{
xmlNodePtr content;
content = get_node(simpCompType->children, "restriction");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_restriction_simpleContent(sdl, tsn, content, cur_type);
return TRUE;
}
content = get_node(simpCompType->children, "extension");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_extension_simpleContent(sdl, tsn, content, cur_type);
// php_error(E_ERROR, "Error parsing schema (doesn't support extensions on simpleContent)");
return TRUE;
}
php_error(E_ERROR, "Error parsing schema (simpleContent)");
return FALSE;
}
/*
<restriction
base = QName
id = ID
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))
</restriction>
*/
static int schema_restriction_simpleType(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr restType, sdlTypePtr cur_type)
{
xmlNodePtr content, trav;
xmlAttrPtr base;
content = get_node(restType->children, "simpleType");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_simpleType(sdl, tsn, content, cur_type);
return TRUE;
}
base = get_attribute(restType->properties, "base");
2004-01-06 17:14:30 +00:00
if(base != NULL) {
char *type, *ns;
xmlNsPtr nsptr;
parse_namespace(base->children->content, &type, &ns);
nsptr = xmlSearchNs(restType->doc, restType, ns);
if(nsptr != NULL) {
cur_type->encode = get_encoder((*sdl), (char *)nsptr->href, type);
}
if(type) {efree(type);}
if(ns) {efree(ns);}
}
2004-01-06 17:14:30 +00:00
if(cur_type->restrictions == NULL) {
cur_type->restrictions = malloc(sizeof(sdlRestrictions));
memset(cur_type->restrictions, 0, sizeof(sdlRestrictions));
}
trav = restType->children;
while (trav != NULL) {
2004-01-06 17:14:30 +00:00
if(trav->type == XML_ELEMENT_NODE) {
if(!strcmp(trav->name, "minExclusive")) {
schema_restriction_var_int(trav, &cur_type->restrictions->minExclusive);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "minInclusive")) {
schema_restriction_var_int(trav, &cur_type->restrictions->minInclusive);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "maxExclusive")) {
schema_restriction_var_int(trav, &cur_type->restrictions->maxExclusive);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "maxInclusive")) {
schema_restriction_var_int(trav, &cur_type->restrictions->maxInclusive);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "totalDigits")) {
schema_restriction_var_int(trav, &cur_type->restrictions->totalDigits);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "fractionDigits")) {
schema_restriction_var_int(trav, &cur_type->restrictions->fractionDigits);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "length")) {
schema_restriction_var_int(trav, &cur_type->restrictions->length);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "minLength")) {
schema_restriction_var_int(trav, &cur_type->restrictions->minLength);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "maxLength")) {
schema_restriction_var_int(trav, &cur_type->restrictions->maxLength);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "whiteSpace")) {
schema_restriction_var_char(trav, &cur_type->restrictions->whiteSpace);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "pattern")) {
schema_restriction_var_char(trav, &cur_type->restrictions->pattern);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "enumeration")) {
sdlRestrictionCharPtr enumval = NULL;
schema_restriction_var_char(trav, &enumval);
2004-01-06 17:14:30 +00:00
if(cur_type->restrictions->enumeration == NULL) {
cur_type->restrictions->enumeration = malloc(sizeof(HashTable));
zend_hash_init(cur_type->restrictions->enumeration, 0, NULL, delete_schema_restriction_var_char, 1);
}
2004-01-06 17:14:30 +00:00
zend_hash_add(cur_type->restrictions->enumeration, enumval->value, strlen(enumval->value)+1, &enumval, sizeof(sdlRestrictionCharPtr), NULL);
}
}
trav = trav->next;
}
return TRUE;
}
/*
<restriction
base = QName
id = ID
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))
</restriction>
*/
static int schema_restriction_complexContent(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr restType, sdlTypePtr cur_type)
{
xmlAttrPtr base;
xmlNodePtr trav;
base = get_attribute(restType->properties, "base");
2004-01-06 17:14:30 +00:00
if(base != NULL) {
char *type, *ns;
xmlNsPtr nsptr;
parse_namespace(base->children->content, &type, &ns);
nsptr = xmlSearchNs(restType->doc, restType, ns);
2004-01-06 17:14:30 +00:00
if(nsptr != NULL) {
cur_type->encode = get_encoder((*sdl), (char *)nsptr->href, type);
}
2004-01-06 17:14:30 +00:00
if(type) {efree(type);}
if(ns) {efree(ns);}
}
trav = restType->children;
while (trav != NULL) {
2004-01-06 17:14:30 +00:00
if(trav->type == XML_ELEMENT_NODE) {
if(!strcmp(trav->name, "group")) {
schema_group(sdl, tsn, trav, cur_type);
break;
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "all")) {
schema_all(sdl, tsn, trav, cur_type);
break;
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "choice")) {
schema_choice(sdl, tsn, trav, cur_type);
break;
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "sequence")) {
schema_sequence(sdl, tsn, trav, cur_type);
break;
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "attribute")) {
schema_attribute(sdl, tsn, trav, cur_type);
}
}
trav = trav->next;
}
while (trav != NULL) {
if(trav->type == XML_ELEMENT_NODE) {
if(!strcmp(trav->name, "attribute")) {
schema_attribute(sdl, tsn, trav, cur_type);
}
}
trav = trav->next;
}
return TRUE;
}
/*
<restriction
base = QName
id = ID
{any attributes with non-schema Namespace . . .}>
Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*))
</restriction>
*/
static int schema_restriction_simpleContent(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr restType, sdlTypePtr cur_type)
{
xmlNodePtr content, trav;
xmlAttrPtr base;
base = get_attribute(restType->properties, "base");
if(base != NULL)
cur_type->encode = get_encoder_from_prefix((*sdl), restType, base->children->content);
content = get_node(restType->children, "simpleType");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_simpleType(sdl, tsn, content, cur_type);
return TRUE;
}
2004-01-06 17:14:30 +00:00
if(cur_type->restrictions == NULL) {
cur_type->restrictions = malloc(sizeof(sdlRestrictions));
2004-01-06 17:14:30 +00:00
memset(cur_type->restrictions, 0, sizeof(sdlRestrictions));
}
trav = restType->children;
while (trav != NULL) {
2004-01-06 17:14:30 +00:00
if(trav->type == XML_ELEMENT_NODE) {
if(!strcmp(trav->name, "minExclusive")) {
schema_restriction_var_int(trav, &cur_type->restrictions->minExclusive);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "minInclusive")) {
schema_restriction_var_int(trav, &cur_type->restrictions->minInclusive);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "maxExclusive")) {
schema_restriction_var_int(trav, &cur_type->restrictions->maxExclusive);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "maxInclusive")) {
schema_restriction_var_int(trav, &cur_type->restrictions->maxInclusive);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "totalDigits")) {
schema_restriction_var_int(trav, &cur_type->restrictions->totalDigits);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "fractionDigits")) {
schema_restriction_var_int(trav, &cur_type->restrictions->fractionDigits);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "length")) {
schema_restriction_var_int(trav, &cur_type->restrictions->length);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "minLength")) {
schema_restriction_var_int(trav, &cur_type->restrictions->minLength);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "maxLength")) {
schema_restriction_var_int(trav, &cur_type->restrictions->maxLength);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "whiteSpace")) {
schema_restriction_var_char(trav, &cur_type->restrictions->whiteSpace);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "pattern")) {
schema_restriction_var_char(trav, &cur_type->restrictions->pattern);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "enumeration")) {
sdlRestrictionCharPtr enumval = NULL;
schema_restriction_var_char(trav, &enumval);
2004-01-06 17:14:30 +00:00
if(cur_type->restrictions->enumeration == NULL) {
cur_type->restrictions->enumeration = malloc(sizeof(HashTable));
zend_hash_init(cur_type->restrictions->enumeration, 0, NULL, delete_schema_restriction_var_char, 1);
}
2004-01-06 17:14:30 +00:00
zend_hash_add(cur_type->restrictions->enumeration, enumval->value, strlen(enumval->value)+1, &enumval, sizeof(sdlRestrictionCharPtr), NULL);
// zend_hash_next_index_insert(cur_type->restrictions->enumeration, &enumval, sizeof(sdlRestrictionCharPtr), NULL);
}
}
trav = trav->next;
}
return TRUE;
}
static int schema_restriction_var_int(xmlNodePtr val, sdlRestrictionIntPtr *valptr)
{
xmlAttrPtr fixed, value, id;
2004-01-06 17:14:30 +00:00
if((*valptr) == NULL) {
(*valptr) = malloc(sizeof(sdlRestrictionInt));
2004-01-06 17:14:30 +00:00
}
memset((*valptr), 0, sizeof(sdlRestrictionInt));
fixed = get_attribute(val->properties, "fixed");
(*valptr)->fixed = FALSE;
2004-01-06 17:14:30 +00:00
if(fixed != NULL) {
if(!strcmp(fixed->children->content, "true") ||
!strcmp(fixed->children->content, "1"))
(*valptr)->fixed = TRUE;
}
id = get_attribute(val->properties, "id");
2004-01-06 17:14:30 +00:00
if(id != NULL) {
(*valptr)->id = strdup(id->children->content);
2004-01-06 17:14:30 +00:00
}
value = get_attribute(val->properties, "value");
2004-01-06 17:14:30 +00:00
if(value == NULL) {
php_error(E_ERROR, "Error parsing wsdl schema \"missing restriction value\"");
}
(*valptr)->value = atoi(value->children->content);
return TRUE;
}
2004-01-06 17:14:30 +00:00
void delete_restriction_var_int(void *rvi)
{
sdlRestrictionIntPtr ptr = *((sdlRestrictionIntPtr*)rvi);
2004-01-06 17:14:30 +00:00
if (ptr) {
if (ptr->id) {
free(ptr->id);
}
free(ptr);
}
}
static int schema_restriction_var_char(xmlNodePtr val, sdlRestrictionCharPtr *valptr)
{
xmlAttrPtr fixed, value, id;
2004-01-06 17:14:30 +00:00
if((*valptr) == NULL) {
(*valptr) = malloc(sizeof(sdlRestrictionChar));
2004-01-06 17:14:30 +00:00
}
memset((*valptr), 0, sizeof(sdlRestrictionChar));
fixed = get_attribute(val->properties, "fixed");
(*valptr)->fixed = FALSE;
2004-01-06 17:14:30 +00:00
if(fixed != NULL) {
if(!strcmp(fixed->children->content, "true") ||
2004-01-06 17:14:30 +00:00
!strcmp(fixed->children->content, "1")) {
(*valptr)->fixed = TRUE;
2004-01-06 17:14:30 +00:00
}
}
id = get_attribute(val->properties, "id");
2004-01-06 17:14:30 +00:00
if(id != NULL) {
(*valptr)->id = strdup(id->children->content);
2004-01-06 17:14:30 +00:00
}
value = get_attribute(val->properties, "value");
2004-01-06 17:14:30 +00:00
if(value == NULL) {
php_error(E_ERROR, "Error parsing wsdl schema \"missing restriction value\"");
}
(*valptr)->value = strdup(value->children->content);
return TRUE;
}
2004-01-06 17:14:30 +00:00
void delete_schema_restriction_var_char(void *srvc)
{
sdlRestrictionCharPtr ptr = *((sdlRestrictionCharPtr*)srvc);
2004-01-06 17:14:30 +00:00
if (ptr) {
if(ptr->id) {
free(ptr->id);
}
if(ptr->value) {
free(ptr->value);
}
free(ptr);
}
}
/*
From simpleContent (not supported):
<extension
base = QName
id = ID
{any attributes with non-schema namespace . . .}>
Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
</extension>
2004-01-06 17:14:30 +00:00
*/
static int schema_extension_simpleContent(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr extType, sdlTypePtr cur_type)
{
return TRUE;
}
2004-01-06 17:14:30 +00:00
/*
From complexContent:
<extension
base = QName
id = ID
{any attributes with non-schema namespace . . .}>
Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
</extension>
*/
2004-01-06 17:14:30 +00:00
static int schema_extension_complexContent(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr extType, sdlTypePtr cur_type)
{
xmlNodePtr content;
xmlAttrPtr base;
base = get_attribute(extType->properties, "base");
content = get_node(extType->children, "group");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_group(sdl, tsn, content, cur_type);
return TRUE;
}
content = get_node(extType->children, "all");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_all(sdl, tsn, content, cur_type);
return TRUE;
}
content = get_node(extType->children, "choice");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_choice(sdl, tsn, content, cur_type);
return TRUE;
}
content = get_node(extType->children, "sequence");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_sequence(sdl, tsn, content, cur_type);
return TRUE;
}
return FALSE;
}
/*
<all
id = ID
maxOccurs = 1 : 1
minOccurs = (0 | 1) : 1
{any attributes with non-schema namespace . . .}>
Content: (annotation?, element*)
</all>
*/
static int schema_all(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr all, sdlTypePtr cur_type)
{
xmlNodePtr element, trav;
trav = all->children;
2004-01-06 17:14:30 +00:00
FOREACHNODE(trav, "element", element) {
schema_element(sdl, tsn, element, cur_type);
}
ENDFOREACH(trav);
return TRUE;
}
/*
<group
name = NCName>
Content: (annotation?, (all | choice | sequence))
</group>
*/
static int schema_group(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr groupType, sdlTypePtr cur_type)
{
xmlNodePtr content;
xmlAttrPtr name;
name = get_attribute(groupType->properties, "name");
2004-01-06 17:14:30 +00:00
if(name != NULL) {
}
content = get_node(groupType->children, "all");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_all(sdl, tsn, content, cur_type);
return TRUE;
}
content = get_node(groupType->children, "choice");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_choice(sdl, tsn, content, cur_type);
return TRUE;
}
content = get_node(groupType->children, "sequence");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_sequence(sdl, tsn, content, cur_type);
return TRUE;
}
return FALSE;
}
/*
<choice
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (element | group | choice | sequence | any)*)
</choice>
*/
static int schema_choice(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr choiceType, sdlTypePtr cur_type)
{
xmlNodePtr trav, data;
2003-01-14 20:24:40 +00:00
/*
cur_type->property_type = CHOICE;
*/
trav = choiceType->children;
2004-01-06 17:14:30 +00:00
FOREACHNODE(trav, "element", data) {
schema_element(sdl, tsn, data, cur_type);
}
ENDFOREACH(trav);
trav = choiceType->children;
2004-01-06 17:14:30 +00:00
FOREACHNODE(trav, "group", data) {
schema_group(sdl, tsn, data, cur_type);
}
ENDFOREACH(trav);
trav = choiceType->children;
2004-01-06 17:14:30 +00:00
FOREACHNODE(trav, "choice", data) {
schema_choice(sdl, tsn, data, cur_type);
}
ENDFOREACH(trav);
trav = choiceType->children;
2004-01-06 17:14:30 +00:00
FOREACHNODE(trav, "sequence", data) {
schema_sequence(sdl, tsn, data, cur_type);
}
ENDFOREACH(trav);
trav = choiceType->children;
2004-01-06 17:14:30 +00:00
FOREACHNODE(trav, "any", data) {
schema_any(sdl, tsn, data, cur_type);
}
ENDFOREACH(trav);
return TRUE;
}
/*
<sequence
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (element | group | choice | sequence | any)*)
</sequence>
*/
static int schema_sequence(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr seqType, sdlTypePtr cur_type)
{
xmlNodePtr trav;
trav = seqType->children;
while (trav != NULL) {
2004-01-06 17:14:30 +00:00
if(trav->type == XML_ELEMENT_NODE) {
if(!strcmp(trav->name, "element")) {
schema_element(sdl, tsn, trav, cur_type);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "group")) {
schema_group(sdl, tsn, trav, cur_type);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "choice")) {
schema_choice(sdl, tsn, trav, cur_type);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "sequence")) {
schema_sequence(sdl, tsn, trav, cur_type);
2004-01-06 17:14:30 +00:00
} else if(!strcmp(trav->name, "any")) {
schema_any(sdl, tsn, trav, cur_type);
}
}
trav = trav->next;
}
return TRUE;
}
static int schema_any(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr extType, sdlTypePtr cur_type)
{
return TRUE;
}
/*
<complexContent
id = ID
mixed = boolean
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (restriction | extension))
</complexContent>
*/
static int schema_complexContent(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr compCont, sdlTypePtr cur_type)
{
xmlNodePtr content;
content = get_node(compCont->children, "restriction");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_restriction_complexContent(sdl, tsn, content, cur_type);
return TRUE;
}
2004-01-06 17:14:30 +00:00
content = get_node(compCont->children, "extension");
2004-01-09 14:16:30 +00:00
if(content != NULL) {
2004-01-06 17:14:30 +00:00
// php_error(E_ERROR, "Error parsing schema (doesn't support extensions on complexContent)");
schema_extension_complexContent(sdl, tsn, content, cur_type);
return TRUE;
}
return TRUE;
}
/*
<complexType
abstract = boolean : false
block = (#all | List of (extension | restriction))
final = (#all | List of (extension | restriction))
id = ID
mixed = boolean : false
name = NCName
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (simpleContent | complexContent | ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))))
</complexType>
*/
static int schema_complexType(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr compType, sdlTypePtr cur_type)
{
xmlNodePtr content;
xmlAttrPtr attrs, name, ns;
2004-01-09 15:31:09 +00:00
TSRMLS_FETCH();
attrs = compType->properties;
ns = get_attribute(attrs, "targetNamespace");
2004-01-06 17:14:30 +00:00
if(ns == NULL) {
ns = tsn;
2004-01-06 17:14:30 +00:00
}
name = get_attribute(attrs, "name");
2004-01-06 17:14:30 +00:00
if(name) {
HashTable *ht;
sdlTypePtr newType, *ptr;
2002-08-07 03:03:09 +00:00
smart_str key = {0};
newType = malloc(sizeof(sdlType));
memset(newType, 0, sizeof(sdlType));
newType->name = strdup(name->children->content);
newType->namens = strdup(ns->children->content);
2004-01-06 17:14:30 +00:00
if(cur_type == NULL) {
ht = (*sdl)->types;
2002-08-07 03:03:09 +00:00
smart_str_appends(&key, newType->namens);
smart_str_appendc(&key, ':');
smart_str_appends(&key, newType->name);
smart_str_0(&key);
2004-01-06 17:14:30 +00:00
} else {
if(cur_type->elements == NULL) {
cur_type->elements = malloc(sizeof(HashTable));
zend_hash_init(cur_type->elements, 0, NULL, delete_type, 1);
}
ht = cur_type->elements;
2002-08-07 03:03:09 +00:00
smart_str_appends(&key, newType->name);
smart_str_0(&key);
}
2002-08-07 03:03:09 +00:00
zend_hash_add(ht, key.c, key.len + 1, &newType, sizeof(sdlTypePtr), (void **)&ptr);
cur_type = (*ptr);
create_encoder((*sdl), cur_type, ns->children->content, name->children->content);
2002-08-07 03:03:09 +00:00
smart_str_free(&key);
2004-01-09 14:16:30 +00:00
if (cur_type->encode == NULL) {
cur_type->encode = get_conversion(SOAP_ENC_OBJECT);
}
}
content = get_node(compType->children, "simpleContent");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_simpleContent(sdl, tsn, content, cur_type);
return TRUE;
}
content = get_node(compType->children, "complexContent");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_complexContent(sdl, tsn, content, cur_type);
return TRUE;
}
2003-01-14 20:24:40 +00:00
/* (group | all | choice | sequence) */
content = get_node(compType->children, "group");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_group(sdl, tsn, content, cur_type);
return TRUE;
}
content = get_node(compType->children, "all");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_all(sdl, tsn, content, cur_type);
return TRUE;
}
content = get_node(compType->children, "choice");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_choice(sdl, tsn, content, cur_type);
return TRUE;
}
content = get_node(compType->children, "sequence");
2004-01-06 17:14:30 +00:00
if(content != NULL) {
schema_sequence(sdl, tsn, content, cur_type);
2004-01-06 17:14:30 +00:00
}
return TRUE;
}
/*
<element
abstract = boolean : false
block = (#all | List of (extension | restriction | substitution))
default = string
final = (#all | List of (extension | restriction))
fixed = string
form = (qualified | unqualified)
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
name = NCName
nillable = boolean : false
ref = QName
substitutionGroup = QName
type = QName
{any attributes with non-schema namespace . . .}>
Content: (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*))
</element>
*/
static int schema_element(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr element, sdlTypePtr cur_type)
{
xmlNodePtr content;
xmlAttrPtr attrs, curattr, name, ns;
TSRMLS_FETCH(); /* is this really needed - or the parameter */
attrs = element->properties;
ns = get_attribute(attrs, "targetNamespace");
2004-01-06 17:14:30 +00:00
if(ns == NULL) {
ns = tsn;
2004-01-06 17:14:30 +00:00
}
name = get_attribute(attrs, "name");
2004-01-06 17:14:30 +00:00
if (!name) {
name = get_attribute(attrs, "ref");
2004-01-06 17:14:30 +00:00
}
if(name) {
HashTable *addHash;
sdlTypePtr newType, *tmp;
2002-08-07 03:03:09 +00:00
smart_str key = {0};
newType = malloc(sizeof(sdlType));
memset(newType, 0, sizeof(sdlType));
2004-01-06 17:14:30 +00:00
newType->name = strdup(name->children->content);
newType->namens = strdup(tsn->children->content);
newType->nillable = FALSE;
newType->min_occurs = 1;
newType->max_occurs = 1;
2004-01-06 17:14:30 +00:00
if(cur_type == NULL) {
addHash = (*sdl)->types;
2002-08-07 03:03:09 +00:00
smart_str_appends(&key, newType->namens);
smart_str_appendc(&key, ':');
smart_str_appends(&key, newType->name);
2004-01-06 17:14:30 +00:00
} else {
if(cur_type->elements == NULL) {
cur_type->elements = malloc(sizeof(HashTable));
zend_hash_init(cur_type->elements, 0, NULL, delete_type, 1);
}
addHash = cur_type->elements;
2002-08-07 03:03:09 +00:00
smart_str_appends(&key, newType->name);
}
2002-08-07 03:03:09 +00:00
smart_str_0(&key);
zend_hash_add(addHash, key.c, key.len + 1, &newType, sizeof(sdlTypePtr), (void **)&tmp);
cur_type = (*tmp);
// create_encoder((*sdl), cur_type, ns->children->content, name->children->content);
2002-08-07 03:03:09 +00:00
smart_str_free(&key);
}
curattr = get_attribute(attrs, "maxOccurs");
2004-01-06 17:14:30 +00:00
if(curattr) {
if(!strcmp(curattr->children->content, "unbounded")) {
2002-08-07 03:03:09 +00:00
cur_type->max_occurs = -1;
2004-01-06 17:14:30 +00:00
} else {
2002-08-07 03:03:09 +00:00
cur_type->max_occurs = atoi(curattr->children->content);
2004-01-06 17:14:30 +00:00
}
}
2002-08-07 03:03:09 +00:00
curattr = get_attribute(attrs, "minOccurs");
2004-01-06 17:14:30 +00:00
if(curattr) {
2002-08-07 03:03:09 +00:00
cur_type->min_occurs = atoi(curattr->children->content);
2004-01-06 17:14:30 +00:00
}
2002-08-07 03:03:09 +00:00
2003-01-14 20:24:40 +00:00
/* nillable = boolean : false */
attrs = element->properties;
curattr = get_attribute(attrs, "nillable");
2004-01-06 17:14:30 +00:00
if(curattr) {
if(!stricmp(curattr->children->content, "true") ||
2004-01-06 17:14:30 +00:00
!stricmp(curattr->children->content, "1")) {
cur_type->nillable = TRUE;
2004-01-06 17:14:30 +00:00
} else {
cur_type->nillable = FALSE;
2004-01-06 17:14:30 +00:00
}
} else {
cur_type->nillable = FALSE;
2004-01-06 17:14:30 +00:00
}
2003-01-14 20:24:40 +00:00
/* type = QName */
curattr = get_attribute(attrs, "type");
2004-01-06 17:14:30 +00:00
if(!curattr) {
curattr = name;
2004-01-06 17:14:30 +00:00
}
if(curattr) {
char *cptype, *str_ns;
xmlNsPtr nsptr;
parse_namespace(curattr->children->content, &cptype, &str_ns);
// if(str_ns)
nsptr = xmlSearchNs(element->doc, element, str_ns);
// else
// nsptr = xmlSearchNsByHref(element->doc, element, ns->children->content);
cur_type->encode = get_create_encoder((*sdl), cur_type, (char *)nsptr->href, (char *)cptype);
2004-01-06 17:14:30 +00:00
if(str_ns) {efree(str_ns);}
if(cptype) {efree(cptype);}
}
2004-01-06 17:14:30 +00:00
// if(cur_type->max_occurs == -1 || cur_type->max_occurs > 1)
// cur_type->encode = get_conversion(SOAP_ENC_ARRAY);
2002-08-07 03:03:09 +00:00
content = get_node(element->children, "simpleType");
2004-01-06 17:14:30 +00:00
if(content) {
schema_simpleType(sdl, tsn, content, cur_type);
2004-01-06 17:14:30 +00:00
}
content = get_node(element->children, "complexType");
2004-01-06 17:14:30 +00:00
if(content) {
schema_complexType(sdl, tsn, content, cur_type);
2004-01-06 17:14:30 +00:00
}
return FALSE;
}
/*
<attribute
default = string
fixed = string
form = (qualified | unqualified)
id = ID
name = NCName
ref = QName
type = QName
use = (optional | prohibited | required) : optional
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (simpleType?))
</attribute>
*/
static int schema_attribute(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr attrType, sdlTypePtr cur_type)
{
xmlAttrPtr attr;
sdlAttributePtr newAttr;
xmlAttrPtr trav;
smart_str key = {0};
newAttr = malloc(sizeof(sdlAttribute));
memset(newAttr, 0, sizeof(sdlAttribute));
2004-01-06 17:14:30 +00:00
if(cur_type->attributes == NULL) {
cur_type->attributes = malloc(sizeof(HashTable));
zend_hash_init(cur_type->attributes, 0, NULL, delete_attribute, 1);
}
trav = attrType->properties;
2004-01-06 17:14:30 +00:00
FOREACHATTRNODE(trav, NULL, attr) {
if(attr_is_equal_ex(trav, "default", SCHEMA_NAMESPACE)) {
newAttr->def = strdup(attr->children->content);
2004-01-06 17:14:30 +00:00
} else if(attr_is_equal_ex(trav, "fixed", SCHEMA_NAMESPACE)) {
newAttr->fixed = strdup(attr->children->content);
2004-01-06 17:14:30 +00:00
} else if(attr_is_equal_ex(trav, "form", SCHEMA_NAMESPACE)) {
newAttr->form = strdup(attr->children->content);
2004-01-06 17:14:30 +00:00
} else if(attr_is_equal_ex(trav, "id", SCHEMA_NAMESPACE)) {
newAttr->id = strdup(attr->children->content);
2004-01-06 17:14:30 +00:00
} else if(attr_is_equal_ex(trav, "name", SCHEMA_NAMESPACE)) {
newAttr->name = strdup(attr->children->content);
2004-01-06 17:14:30 +00:00
} else if(attr_is_equal_ex(trav, "ref", SCHEMA_NAMESPACE)) {
newAttr->ref= strdup(attr->children->content);
2004-01-06 17:14:30 +00:00
} else if(attr_is_equal_ex(trav, "type", SCHEMA_NAMESPACE)) {
newAttr->type = strdup(attr->children->content);
2004-01-06 17:14:30 +00:00
} else if(attr_is_equal_ex(trav, "use", SCHEMA_NAMESPACE)) {
newAttr->use = strdup(attr->children->content);
2004-01-06 17:14:30 +00:00
} else {
xmlNsPtr nsPtr = attr_find_ns(trav);
2004-01-06 17:14:30 +00:00
if(strcmp(nsPtr->href, SCHEMA_NAMESPACE)) {
smart_str key2 = {0};
2004-01-06 17:14:30 +00:00
if(!newAttr->extraAttributes) {
newAttr->extraAttributes = malloc(sizeof(HashTable));
zend_hash_init(newAttr->extraAttributes, 0, NULL, NULL, 1);
}
smart_str_appends(&key2, nsPtr->href);
smart_str_appendc(&key2, ':');
smart_str_appends(&key2, trav->name);
smart_str_0(&key2);
zend_hash_add(newAttr->extraAttributes, key2.c, key2.len + 1, &trav, sizeof(xmlAttrPtr), NULL);
smart_str_free(&key2);
}
}
}
ENDFOREACH(trav);
2004-01-06 17:14:30 +00:00
if(newAttr->ref || newAttr->name) {
xmlNsPtr ns;
2004-01-06 17:14:30 +00:00
if(newAttr->ref) {
char *value, *prefix = NULL;
parse_namespace(newAttr->ref, &value, &prefix);
ns = xmlSearchNs(attrType->doc, attrType, prefix);
smart_str_appends(&key, ns->href);
smart_str_appendc(&key, ':');
smart_str_appends(&key, value);
2004-01-06 17:14:30 +00:00
if(value) {efree(value);}
if(prefix) {efree(prefix);}
} else {
ns = node_find_ns(attrType);
smart_str_appends(&key, ns->href);
smart_str_appendc(&key, ':');
smart_str_appends(&key, newAttr->name);
}
2004-01-06 17:14:30 +00:00
if(ns) {
smart_str_0(&key);
zend_hash_add(cur_type->attributes, key.c, key.len + 1, &newAttr, sizeof(sdlAttributePtr), NULL);
smart_str_free(&key);
return TRUE;
}
smart_str_free(&key);
}
zend_hash_next_index_insert(cur_type->attributes, &newAttr, sizeof(sdlAttributePtr), NULL);
return TRUE;
}