}
object_init(ret);
- trav = data->children;
-
- while (trav != NULL) {
- if (trav->type == XML_ELEMENT_NODE) {
- sdlTypePtr *element;
- encodePtr enc = NULL;
- zval *tmpVal;
-
- xmlAttrPtr typeAttr = get_attribute(trav->properties,"type");
- if (typeAttr != NULL && typeAttr->children && typeAttr->children->content) {
- enc = get_encoder_from_prefix(sdl, trav, typeAttr->children->content);
- }
- if (enc == NULL && sdlType != NULL && sdlType->elements != NULL && trav->name != NULL &&
- zend_hash_find(sdlType->elements, (char*)trav->name, strlen(trav->name)+1,(void **)&element) == SUCCESS) {
- enc = (*element)->encode;
+ if (type.sdl_type) {
+ if (type.sdl_type->elements) {
+ sdlTypePtr *tmpType;
+ zend_hash_internal_pointer_reset(type.sdl_type->elements);
+ while (zend_hash_get_current_data(type.sdl_type->elements, (void**)&tmpType) == SUCCESS) {
+ if ((*tmpType)->name) {
+ xmlNodePtr node = get_node(data->children, (*tmpType)->name);
+ if (node) {
+ xmlAttrPtr typeAttr = get_attribute(node->properties,"type");
+ encodePtr enc = NULL;
+ zval *val;
+
+ if (typeAttr != NULL && typeAttr->children && typeAttr->children->content) {
+ enc = get_encoder_from_prefix(sdl, node, typeAttr->children->content);
+ }
+ if (enc == NULL) {
+ enc = (*tmpType)->encode;
+ }
+ val = master_to_zval(enc, node);
+ if ((node = get_node(node->next, (*tmpType)->name)) != NULL) {
+ zval *array;
+ MAKE_STD_ZVAL(array);
+ array_init(array);
+ add_next_index_zval(array, val);
+ do {
+ typeAttr = get_attribute(node->properties,"type");
+ enc = NULL;
+ if (typeAttr != NULL && typeAttr->children && typeAttr->children->content) {
+ enc = get_encoder_from_prefix(sdl, node, typeAttr->children->content);
+ }
+ if (enc == NULL) {
+ enc = (*tmpType)->encode;
+ }
+ val = master_to_zval(enc, node);
+ add_next_index_zval(array, val);
+ } while ((node = get_node(node->next, (*tmpType)->name)) != NULL);
+ val = array;
+ }
+#ifdef ZEND_ENGINE_2
+ val->refcount--;
+#endif
+ add_property_zval(ret, (*tmpType)->name, val);
+ }
+ }
+ zend_hash_move_forward(type.sdl_type->elements);
}
- if (enc == NULL) {
- enc = get_conversion(UNKNOWN_TYPE);
+ }
+ if (type.sdl_type->attributes) {
+ sdlAttributePtr *attr;
+
+ zend_hash_internal_pointer_reset(type.sdl_type->attributes);
+ while (zend_hash_get_current_data(type.sdl_type->attributes, (void**)&attr) == SUCCESS) {
+ if ((*attr)->name) {
+ xmlAttrPtr val = get_attribute(data->properties, (*attr)->name);
+ if (val && val->children && val->children->content) {
+ add_property_string(ret, (*attr)->name, val->children->content, 1);
+ }
+ }
+ zend_hash_move_forward(type.sdl_type->attributes);
}
+ }
+ } else {
+ trav = data->children;
- tmpVal = master_to_zval(enc, trav);
+ while (trav != NULL) {
+ if (trav->type == XML_ELEMENT_NODE) {
+ encodePtr enc = NULL;
+ zval *tmpVal;
+
+ xmlAttrPtr typeAttr = get_attribute(trav->properties,"type");
+ if (typeAttr != NULL && typeAttr->children && typeAttr->children->content) {
+ enc = get_encoder_from_prefix(sdl, trav, typeAttr->children->content);
+ }
+ tmpVal = master_to_zval(enc, trav);
#ifdef ZEND_ENGINE_2
- tmpVal->refcount--;
+ tmpVal->refcount--;
#endif
- add_property_zval(ret, (char *)trav->name, tmpVal);
+ add_property_zval(ret, (char *)trav->name, tmpVal);
+ }
+ trav = trav->next;
}
- trav = trav->next;
}
return ret;
}
+static int model_to_xml_object(xmlNodePtr node, sdlContentModelPtr model, HashTable *prop, int style, int strict)
+{
+ switch (model->kind) {
+ case XSD_CONTENT_ELEMENT: {
+ zval **data;
+ xmlNodePtr property;
+ encodePtr enc;
+
+ if (zend_hash_find(prop, model->u.element->name, strlen(model->u.element->name)+1, (void**)&data) == SUCCESS) {
+ enc = model->u.element->encode;
+ if ((model->max_occurs == -1 || model->max_occurs > 1) && Z_TYPE_PP(data) == IS_ARRAY) {
+ HashTable *ht = Z_ARRVAL_PP(data);
+ zval **val;
+
+ zend_hash_internal_pointer_reset(ht);
+ while (zend_hash_get_current_data(ht,(void**)&val) == SUCCESS) {
+ property = master_to_xml(enc, *val, style);
+ xmlNodeSetName(property, model->u.element->name);
+ xmlAddChild(node, property);
+ zend_hash_move_forward(ht);
+ }
+ } else {
+ property = master_to_xml(enc, *data, style);
+ xmlNodeSetName(property, model->u.element->name);
+ xmlAddChild(node, property);
+ }
+ return 1;
+ } else if (model->min_occurs == 0) {
+ return 1;
+ } else {
+ if (strict) {
+ php_error(E_ERROR, "object hasn't '%s' property",model->u.element->name);
+ }
+ return 0;
+ }
+ break;
+ }
+ case XSD_CONTENT_SEQUENCE:
+ case XSD_CONTENT_ALL: {
+ sdlContentModelPtr *tmp;
+
+ zend_hash_internal_pointer_reset(model->u.content);
+ while (zend_hash_get_current_data(model->u.content, (void**)&tmp) == SUCCESS) {
+ if (!model_to_xml_object(node, *tmp, prop, style, model->min_occurs > 0)) {
+ return 0;
+ }
+ zend_hash_move_forward(model->u.content);
+ }
+ return 1;
+ }
+ case XSD_CONTENT_CHOICE: {
+ sdlContentModelPtr *tmp;
+
+ zend_hash_internal_pointer_reset(model->u.content);
+ while (zend_hash_get_current_data(model->u.content, (void**)&tmp) == SUCCESS) {
+ if (model_to_xml_object(node, *tmp, prop, style, 0)) {
+ return 1;
+ }
+ zend_hash_move_forward(model->u.content);
+ }
+ return 0;
+ }
+ case XSD_CONTENT_GROUP: {
+ return model_to_xml_object(node, model->u.group, prop, style, model->min_occurs > 0);
+ }
+ default:
+ break;
+ }
+ return 1;
+}
+
xmlNodePtr to_xml_object(encodeType type, zval *data, int style)
{
xmlNodePtr xmlParam;
smart_str_free(ns);
efree(ns);
}
- } else {
+ } else if (type.sdl_type) {
xmlParam = xmlNewNode(NULL, "BOGUS");
FIND_ZVAL_NULL(data, xmlParam, style);
+ prop = NULL;
if (Z_TYPE_P(data) == IS_OBJECT) {
- sdlTypePtr sdl_type = type.sdl_type;
+ prop = Z_OBJPROP_P(data);
+ } else if (Z_TYPE_P(data) == IS_ARRAY) {
+ prop = Z_ARRVAL_P(data);
+ }
+ if (prop != NULL) {
+ if (type.sdl_type->model) {
+ model_to_xml_object(xmlParam, type.sdl_type->model, prop, style, 1);
+ }
+ if (type.sdl_type->attributes) {
+ sdlAttributePtr *attr;
+ zval **data;
+
+ zend_hash_internal_pointer_reset(type.sdl_type->attributes);
+ while (zend_hash_get_current_data(type.sdl_type->attributes, (void**)&attr) == SUCCESS) {
+ if ((*attr)->name) {
+ if (zend_hash_find(prop, (*attr)->name, strlen((*attr)->name)+1, (void**)&data) == SUCCESS) {
+ xmlNodePtr dummy;
+
+ dummy = master_to_xml((*attr)->encode, *data, SOAP_LITERAL);
+ if (dummy->children && dummy->children->content) {
+ xmlSetProp(xmlParam, (*attr)->name, dummy->children->content);
+ }
+ xmlFreeNode(dummy);
+ }
+ }
+ zend_hash_move_forward(type.sdl_type->attributes);
+ }
+ }
+ }
+ if (style == SOAP_ENCODED) {
+ set_ns_and_type(xmlParam, type);
+ }
+ } else {
+ xmlParam = xmlNewNode(NULL, "BOGUS");
+ FIND_ZVAL_NULL(data, xmlParam, style);
+ prop = NULL;
+ if (Z_TYPE_P(data) == IS_OBJECT) {
prop = Z_OBJPROP_P(data);
+ } else if (Z_TYPE_P(data) == IS_ARRAY) {
+ prop = Z_ARRVAL_P(data);
+ }
+ if (prop != NULL) {
i = zend_hash_num_elements(prop);
zend_hash_internal_pointer_reset(prop);
for (;i > 0;i--) {
xmlNodePtr property;
- encodePtr enc = NULL;
zval **zprop;
char *str_key;
zend_hash_get_current_key(prop, &str_key, NULL, FALSE);
zend_hash_get_current_data(prop, (void **)&zprop);
- if (sdl_type && sdl_type->elements) {
- sdlTypePtr *el_type;
- if (zend_hash_find(sdl_type->elements, str_key, strlen(str_key) + 1, (void **)&el_type) == SUCCESS) {
- enc = (*el_type)->encode;
- }
- }
- if (enc == NULL) {
- enc = get_conversion((*zprop)->type);
- }
- property = master_to_xml(enc, (*zprop), style);
+ property = master_to_xml(get_conversion((*zprop)->type), (*zprop), style);
xmlNodeSetName(property, str_key);
xmlAddChild(xmlParam, property);
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_complexContent(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr restType, sdlTypePtr cur_type);
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_sequence(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr seqType, sdlTypePtr cur_type, sdlContentModelPtr model);
+static int schema_all(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr extType, sdlTypePtr cur_type, sdlContentModelPtr model);
+static int schema_choice(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr choiceType, sdlTypePtr cur_type, sdlContentModelPtr model);
+static int schema_group(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr groupType, sdlTypePtr cur_type, sdlContentModelPtr model);
+static int schema_any(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr extType, sdlTypePtr cur_type, sdlContentModelPtr model);
+static int schema_element(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr element, sdlTypePtr cur_type, sdlContentModelPtr model);
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_attributeGroup(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrType, sdlTypePtr cur_type);
static int schema_restriction_var_int(xmlNodePtr val, sdlRestrictionIntPtr *valptr);
static int schema_restriction_var_char(xmlNodePtr val, sdlRestrictionCharPtr *valptr);
+static void schema_type_fixup(sdlPtr sdl, sdlTypePtr type);
+
+static void delete_model(void *handle);
static int is_blank(const char* str)
{
}
} else if (node_is_equal(trav,"annotation")) {
/* TODO: <annotation> support */
+/* annotation cleanup
+ xmlNodePtr tmp = trav;
+ trav = trav->next;
+ xmlUnlinkNode(tmp);
+ xmlFreeNode(tmp);
+ continue;
+*/
} else {
break;
}
} else if (node_is_equal(trav,"complexType")) {
schema_complexType(sdl, tns, trav, NULL);
} else if (node_is_equal(trav,"group")) {
- schema_group(sdl, tns, trav, NULL);
+ schema_group(sdl, tns, trav, NULL, NULL);
} else if (node_is_equal(trav,"attributeGroup")) {
schema_attributeGroup(sdl, tns, trav, NULL);
} else if (node_is_equal(trav,"element")) {
- schema_element(sdl, tns, trav, NULL);
+ schema_element(sdl, tns, trav, NULL, NULL);
} else if (node_is_equal(trav,"attribute")) {
schema_attribute(sdl, tns, trav, NULL);
} else if (node_is_equal(trav,"notation")) {
}
if (trav != NULL) {
if (node_is_equal(trav,"group")) {
- schema_group(sdl, tsn, trav, cur_type);
+ schema_group(sdl, tsn, trav, cur_type, NULL);
trav = trav->next;
} else if (node_is_equal(trav,"all")) {
- cur_type->kind = XSD_TYPEKIND_ALL;
- schema_all(sdl, tsn, trav, cur_type);
+ schema_all(sdl, tsn, trav, cur_type, NULL);
trav = trav->next;
} else if (node_is_equal(trav,"choice")) {
- cur_type->kind = XSD_TYPEKIND_CHOICE;
- schema_choice(sdl, tsn, trav, cur_type);
+ schema_choice(sdl, tsn, trav, cur_type, NULL);
trav = trav->next;
- cur_type->kind = XSD_TYPEKIND_SEQUENCE;
} else if (node_is_equal(trav,"sequence")) {
- schema_sequence(sdl, tsn, trav, cur_type);
+ schema_sequence(sdl, tsn, trav, cur_type, NULL);
trav = trav->next;
}
}
}
if (trav != NULL) {
if (node_is_equal(trav,"group")) {
- schema_group(sdl, tsn, trav, cur_type);
+ schema_group(sdl, tsn, trav, cur_type, NULL);
trav = trav->next;
} else if (node_is_equal(trav,"all")) {
- cur_type->kind = XSD_TYPEKIND_ALL;
- schema_all(sdl, tsn, trav, cur_type);
+ schema_all(sdl, tsn, trav, cur_type, NULL);
trav = trav->next;
} else if (node_is_equal(trav,"choice")) {
- cur_type->kind = XSD_TYPEKIND_CHOICE;
- schema_choice(sdl, tsn, trav, cur_type);
+ schema_choice(sdl, tsn, trav, cur_type, NULL);
trav = trav->next;
} else if (node_is_equal(trav,"sequence")) {
- cur_type->kind = XSD_TYPEKIND_SEQUENCE;
- schema_sequence(sdl, tsn, trav, cur_type);
+ schema_sequence(sdl, tsn, trav, cur_type, NULL);
trav = trav->next;
}
}
Content: (annotation?, element*)
</all>
*/
-static int schema_all(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr all, sdlTypePtr cur_type)
+static int schema_all(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr all, sdlTypePtr cur_type, sdlContentModelPtr model)
{
xmlNodePtr trav;
+ xmlAttrPtr attr;
+ sdlContentModelPtr newModel;
+
+ newModel = malloc(sizeof(sdlContentModel));
+ newModel->kind = XSD_CONTENT_ALL;
+ newModel->u.content = malloc(sizeof(HashTable));
+ zend_hash_init(newModel->u.content, 0, NULL, delete_model, 1);
+ if (model == NULL) {
+ cur_type->model = newModel;
+ } else {
+ zend_hash_next_index_insert(model->u.content,&newModel,sizeof(sdlContentModelPtr), NULL);
+ }
+
+ newModel->min_occurs = 1;
+ newModel->max_occurs = 1;
+
+ attr = get_attribute(all->properties, "minOccurs");
+ if (attr) {
+ newModel->min_occurs = atoi(attr->children->content);
+ }
+
+ attr = get_attribute(all->properties, "maxOccurs");
+ if (attr) {
+ if (!strcmp(attr->children->content, "unbounded")) {
+ newModel->max_occurs = -1;
+ } else {
+ newModel->max_occurs = atoi(attr->children->content);
+ }
+ }
trav = all->children;
if (trav != NULL && node_is_equal(trav,"annotation")) {
}
while (trav != NULL) {
if (node_is_equal(trav,"element")) {
- schema_element(sdl, tsn, trav, cur_type);
+ schema_element(sdl, tsn, trav, cur_type, newModel);
} else {
php_error(E_ERROR, "Error parsing schema (unexpected <%s> in all)",trav->name);
}
/*
<group
- name = NCName>
+ name = NCName
Content: (annotation?, (all | choice | sequence))
</group>
+<group
+ name = NCName
+ ref = QName>
+ Content: (annotation?)
+</group>
*/
-static int schema_group(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr groupType, sdlTypePtr cur_type)
+static int schema_group(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr groupType, sdlTypePtr cur_type, sdlContentModelPtr model)
{
xmlNodePtr trav;
- xmlAttrPtr name;
+ xmlAttrPtr attr;
+ xmlAttrPtr ns, name, ref = NULL;
+ sdlContentModelPtr newModel;
+
+ ns = get_attribute(groupType->properties, "targetNamespace");
+ if (ns == NULL) {
+ ns = tsn;
+ }
name = get_attribute(groupType->properties, "name");
- if (name != NULL) {
- /*FIXME*/
+ if (name == NULL) {
+ name = ref = get_attribute(groupType->properties, "ref");
+ }
+
+ if (name) {
+ smart_str key = {0};
+
+ if (ref) {
+ char *type, *ns;
+ xmlNsPtr nsptr;
+
+ parse_namespace(ref->children->content, &type, &ns);
+ nsptr = xmlSearchNs(groupType->doc, groupType, ns);
+ if (nsptr != NULL) {
+ smart_str_appends(&key, nsptr->href);
+ smart_str_appendc(&key, ':');
+ }
+ smart_str_appends(&key, type);
+ smart_str_0(&key);
+
+ newModel = malloc(sizeof(sdlContentModel));
+ newModel->kind = XSD_CONTENT_GROUP_REF;
+ newModel->u.group_ref = estrdup(key.c);
+
+ if (type) {efree(type);}
+ if (ns) {efree(ns);}
+ } else {
+ newModel = malloc(sizeof(sdlContentModel));
+ newModel->kind = XSD_CONTENT_SEQUENCE; /* will be redefined */
+ newModel->u.content = malloc(sizeof(HashTable));
+ zend_hash_init(newModel->u.content, 0, NULL, delete_model, 1);
+
+ smart_str_appends(&key, ns->children->content);
+ smart_str_appendc(&key, ':');
+ smart_str_appends(&key, name->children->content);
+ smart_str_0(&key);
+ }
+
+ if (cur_type == NULL) {
+ sdlTypePtr newType;
+
+ newType = malloc(sizeof(sdlType));
+ memset(newType, 0, sizeof(sdlType));
+
+ if (sdl->groups == NULL) {
+ sdl->groups = malloc(sizeof(HashTable));
+ zend_hash_init(sdl->groups, 0, NULL, delete_type, 1);
+ }
+ if (zend_hash_add(sdl->groups, key.c, key.len+1, (void**)&newType, sizeof(sdlTypePtr), NULL) != SUCCESS) {
+ php_error(E_ERROR, "Error parsing schema (group '%s' already defined)",key.c);
+ }
+
+ cur_type = newType;
+ }
+ smart_str_free(&key);
+
+ if (model == NULL) {
+ cur_type->model = newModel;
+ } else {
+ zend_hash_next_index_insert(model->u.content, &newModel, sizeof(sdlContentModelPtr), NULL);
+ }
+ } else {
+ php_error(E_ERROR, "Error parsing schema (group has no 'name' nor 'ref' attributes)");
+ }
+
+ newModel->min_occurs = 1;
+ newModel->max_occurs = 1;
+
+ attr = get_attribute(groupType->properties, "minOccurs");
+ if (attr) {
+ newModel->min_occurs = atoi(attr->children->content);
+ }
+
+ attr = get_attribute(groupType->properties, "maxOccurs");
+ if (attr) {
+ if (!strcmp(attr->children->content, "unbounded")) {
+ newModel->max_occurs = -1;
+ } else {
+ newModel->max_occurs = atoi(attr->children->content);
+ }
}
trav = groupType->children;
}
if (trav != NULL) {
if (node_is_equal(trav,"choice")) {
- cur_type->kind = XSD_TYPEKIND_CHOICE;
- schema_choice(sdl, tsn, trav, cur_type);
+ if (ref != NULL) {
+ php_error(E_ERROR, "Error parsing schema (group have both 'ref' attribute and subcontent)");
+ }
+ newModel->kind = XSD_CONTENT_CHOICE;
+ schema_choice(sdl, tsn, trav, cur_type, newModel);
trav = trav->next;
} else if (node_is_equal(trav,"sequence")) {
- cur_type->kind = XSD_TYPEKIND_SEQUENCE;
- schema_sequence(sdl, tsn, trav, cur_type);
+ if (ref != NULL) {
+ php_error(E_ERROR, "Error parsing schema (group have both 'ref' attribute and subcontent)");
+ }
+ newModel->kind = XSD_CONTENT_SEQUENCE;
+ schema_sequence(sdl, tsn, trav, cur_type, newModel);
trav = trav->next;
} else if (node_is_equal(trav,"all")) {
- cur_type->kind = XSD_TYPEKIND_ALL;
- schema_all(sdl, tsn, trav, cur_type);
+ if (ref != NULL) {
+ php_error(E_ERROR, "Error parsing schema (group have both 'ref' attribute and subcontent)");
+ }
+ newModel->kind = XSD_CONTENT_ALL;
+ schema_all(sdl, tsn, trav, cur_type, newModel);
trav = trav->next;
} else {
php_error(E_ERROR, "Error parsing schema (unexpected <%s> in group)",trav->name);
Content: (annotation?, (element | group | choice | sequence | any)*)
</choice>
*/
-static int schema_choice(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr choiceType, sdlTypePtr cur_type)
+static int schema_choice(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr choiceType, sdlTypePtr cur_type, sdlContentModelPtr model)
{
xmlNodePtr trav;
+ xmlAttrPtr attr;
+ sdlContentModelPtr newModel;
+
+ newModel = malloc(sizeof(sdlContentModel));
+ newModel->kind = XSD_CONTENT_CHOICE;
+ newModel->u.content = malloc(sizeof(HashTable));
+ zend_hash_init(newModel->u.content, 0, NULL, delete_model, 1);
+ if (model == NULL) {
+ cur_type->model = newModel;
+ } else {
+ zend_hash_next_index_insert(model->u.content,&newModel,sizeof(sdlContentModelPtr), NULL);
+ }
+
+ newModel->min_occurs = 1;
+ newModel->max_occurs = 1;
+
+ attr = get_attribute(choiceType->properties, "minOccurs");
+ if (attr) {
+ newModel->min_occurs = atoi(attr->children->content);
+ }
- /*
- cur_type->property_type = CHOICE;
- */
+ attr = get_attribute(choiceType->properties, "maxOccurs");
+ if (attr) {
+ if (!strcmp(attr->children->content, "unbounded")) {
+ newModel->max_occurs = -1;
+ } else {
+ newModel->max_occurs = atoi(attr->children->content);
+ }
+ }
trav = choiceType->children;
if (trav != NULL && node_is_equal(trav,"annotation")) {
}
while (trav != NULL) {
if (node_is_equal(trav,"element")) {
- schema_element(sdl, tsn, trav, cur_type);
- } else if (node_is_equal(trav,"grouop")) {
- /*FIXME*/
- schema_group(sdl, tsn, trav, cur_type);
+ schema_element(sdl, tsn, trav, cur_type, newModel);
+ } else if (node_is_equal(trav,"group")) {
+ schema_group(sdl, tsn, trav, cur_type, newModel);
} else if (node_is_equal(trav,"choice")) {
- /*FIXME*/
- schema_choice(sdl, tsn, trav, cur_type);
+ schema_choice(sdl, tsn, trav, cur_type, newModel);
} else if (node_is_equal(trav,"sequence")) {
- /*FIXME*/
- schema_sequence(sdl, tsn, trav, cur_type);
+ schema_sequence(sdl, tsn, trav, cur_type, newModel);
} else if (node_is_equal(trav,"any")) {
- /*FIXME*/
- schema_any(sdl, tsn, trav, cur_type);
+ schema_any(sdl, tsn, trav, cur_type, newModel);
} else {
php_error(E_ERROR, "Error parsing schema (unexpected <%s> in choice)",trav->name);
}
Content: (annotation?, (element | group | choice | sequence | any)*)
</sequence>
*/
-static int schema_sequence(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr seqType, sdlTypePtr cur_type)
+static int schema_sequence(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr seqType, sdlTypePtr cur_type, sdlContentModelPtr model)
{
xmlNodePtr trav;
+ xmlAttrPtr attr;
+ sdlContentModelPtr newModel;
+
+ newModel = malloc(sizeof(sdlContentModel));
+ newModel->kind = XSD_CONTENT_SEQUENCE;
+ newModel->u.content = malloc(sizeof(HashTable));
+ zend_hash_init(newModel->u.content, 0, NULL, delete_model, 1);
+ if (model == NULL) {
+ cur_type->model = newModel;
+ } else {
+ zend_hash_next_index_insert(model->u.content,&newModel,sizeof(sdlContentModelPtr), NULL);
+ }
+
+ newModel->min_occurs = 1;
+ newModel->max_occurs = 1;
+
+ attr = get_attribute(seqType->properties, "minOccurs");
+ if (attr) {
+ newModel->min_occurs = atoi(attr->children->content);
+ }
+
+ attr = get_attribute(seqType->properties, "maxOccurs");
+ if (attr) {
+ if (!strcmp(attr->children->content, "unbounded")) {
+ newModel->max_occurs = -1;
+ } else {
+ newModel->max_occurs = atoi(attr->children->content);
+ }
+ }
trav = seqType->children;
if (trav != NULL && node_is_equal(trav,"annotation")) {
}
while (trav != NULL) {
if (node_is_equal(trav,"element")) {
- schema_element(sdl, tsn, trav, cur_type);
- } else if (node_is_equal(trav,"grouop")) {
- /*FIXME*/
- schema_group(sdl, tsn, trav, cur_type);
+ schema_element(sdl, tsn, trav, cur_type, newModel);
+ } else if (node_is_equal(trav,"group")) {
+ schema_group(sdl, tsn, trav, cur_type, newModel);
} else if (node_is_equal(trav,"choice")) {
- /*FIXME*/
- schema_choice(sdl, tsn, trav, cur_type);
+ schema_choice(sdl, tsn, trav, cur_type, newModel);
} else if (node_is_equal(trav,"sequence")) {
- /*FIXME*/
- schema_sequence(sdl, tsn, trav, cur_type);
+ schema_sequence(sdl, tsn, trav, cur_type, newModel);
} else if (node_is_equal(trav,"any")) {
- /*FIXME*/
- schema_any(sdl, tsn, trav, cur_type);
+ schema_any(sdl, tsn, trav, cur_type, newModel);
} else {
php_error(E_ERROR, "Error parsing schema (unexpected <%s> in sequence)",trav->name);
}
return TRUE;
}
-static int schema_any(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr extType, sdlTypePtr cur_type)
+static int schema_any(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr extType, sdlTypePtr cur_type, sdlContentModelPtr model)
{
/* TODO: <any> support */
return TRUE;
cur_type = (*ptr);
create_encoder(sdl, cur_type, ns->children->content, name->children->content);
-/*
- if (cur_type->encode == NULL) {
- cur_type->encode = get_conversion(SOAP_ENC_OBJECT);
- }
-*/
} else {
php_error(E_ERROR, "Error parsing schema (complexType has no 'name' attribute)");
return FALSE;
trav = trav->next;
} else {
if (node_is_equal(trav,"group")) {
- schema_group(sdl, tsn, trav, cur_type);
+ schema_group(sdl, tsn, trav, cur_type, NULL);
trav = trav->next;
} else if (node_is_equal(trav,"all")) {
- cur_type->kind = XSD_TYPEKIND_ALL;
- schema_all(sdl, tsn, trav, cur_type);
+ schema_all(sdl, tsn, trav, cur_type, NULL);
trav = trav->next;
} else if (node_is_equal(trav,"choice")) {
- cur_type->kind = XSD_TYPEKIND_CHOICE;
- schema_choice(sdl, tsn, trav, cur_type);
+ schema_choice(sdl, tsn, trav, cur_type, NULL);
trav = trav->next;
} else if (node_is_equal(trav,"sequence")) {
- cur_type->kind = XSD_TYPEKIND_SEQUENCE;
- schema_sequence(sdl, tsn, trav, cur_type);
+ schema_sequence(sdl, tsn, trav, cur_type, NULL);
trav = trav->next;
}
while (trav != NULL) {
Content: (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*))
</element>
*/
-static int schema_element(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr element, sdlTypePtr cur_type)
+static int schema_element(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr element, sdlTypePtr cur_type, sdlContentModelPtr model)
{
xmlNodePtr trav;
- xmlAttrPtr attrs, curattr, ns, name, type, ref = NULL;
+ xmlAttrPtr attrs, attr, ns, name, type, ref = NULL;
attrs = element->properties;
ns = get_attribute(attrs, "targetNamespace");
if (name) {
HashTable *addHash;
- sdlTypePtr newType, *tmp;
+ sdlTypePtr newType;
smart_str key = {0};
newType = malloc(sizeof(sdlType));
}
newType->nillable = FALSE;
- newType->min_occurs = 1;
- newType->max_occurs = 1;
if (cur_type == NULL) {
addHash = sdl->elements;
}
smart_str_0(&key);
- zend_hash_update(addHash, key.c, key.len + 1, &newType, sizeof(sdlTypePtr), (void **)&tmp);
- cur_type = (*tmp);
+ if (zend_hash_add(addHash, key.c, key.len + 1, &newType, sizeof(sdlTypePtr), NULL) != SUCCESS) {
+ php_error(E_ERROR, "Error parsing schema (element '%s' already defined)",key.c);
+ }
smart_str_free(&key);
- } else {
- php_error(E_ERROR, "Error parsing schema (element has no 'name' nor 'ref' attributes)");
- }
- curattr = get_attribute(attrs, "maxOccurs");
- if (curattr) {
- if (!strcmp(curattr->children->content, "unbounded")) {
- cur_type->max_occurs = -1;
- } else {
- cur_type->max_occurs = atoi(curattr->children->content);
- }
- }
+ if (model != NULL) {
+ sdlContentModelPtr newModel = malloc(sizeof(sdlContentModel));
+
+ newModel->kind = XSD_CONTENT_ELEMENT;
+ newModel->u.element = newType;
+ newModel->min_occurs = 1;
+ newModel->max_occurs = 1;
- curattr = get_attribute(attrs, "minOccurs");
- if (curattr) {
- cur_type->min_occurs = atoi(curattr->children->content);
+ attr = get_attribute(attrs, "maxOccurs");
+ if (attr) {
+ if (!strcmp(attr->children->content, "unbounded")) {
+ newModel->max_occurs = -1;
+ } else {
+ newModel->max_occurs = atoi(attr->children->content);
+ }
+ }
+
+ attr = get_attribute(attrs, "minOccurs");
+ if (attr) {
+ newModel->min_occurs = atoi(attr->children->content);
+ }
+
+ zend_hash_next_index_insert(model->u.content, &newModel, sizeof(sdlContentModelPtr), NULL);
+ }
+ cur_type = newType;
+ } else {
+ php_error(E_ERROR, "Error parsing schema (element has no 'name' nor 'ref' attributes)");
}
/* nillable = boolean : false */
attrs = element->properties;
- curattr = get_attribute(attrs, "nillable");
- if (curattr) {
- if (!stricmp(curattr->children->content, "true") ||
- !stricmp(curattr->children->content, "1")) {
+ attr = get_attribute(attrs, "nillable");
+ if (attr) {
+ if (!stricmp(attr->children->content, "true") ||
+ !stricmp(attr->children->content, "1")) {
cur_type->nillable = TRUE;
} else {
cur_type->nillable = FALSE;
if (cptype) {efree(cptype);}
}
-/*
- if (cur_type->max_occurs == -1 || cur_type->max_occurs > 1) {
- cur_type->encode = get_conversion(SOAP_ENC_ARRAY);
- }
-*/
-
trav = element->children;
if (trav != NULL && node_is_equal(trav, "annotation")) {
/* TODO: <annotation> support */
addHash = cur_type->attributes;
}
- zend_hash_update(addHash, key.c, key.len + 1, &newAttr, sizeof(sdlAttributePtr), NULL);
+ if (zend_hash_add(addHash, key.c, key.len + 1, &newAttr, sizeof(sdlAttributePtr), NULL) != SUCCESS) {
+ php_error(E_ERROR, "Error parsing schema (attribute '%s' already defined)", key.c);
+ }
smart_str_free(&key);
} else{
php_error(E_ERROR, "Error parsing schema (attribute has no 'name' nor 'ref' attributes)");
}
+ /* type = QName */
+ type = get_attribute(attrType->properties, "type");
+ if (type) {
+ char *cptype, *str_ns;
+ xmlNsPtr nsptr;
+
+ if (ref != NULL) {
+ php_error(E_ERROR, "Error parsing schema (attribute have both 'ref' and 'type' attributes)");
+ }
+ parse_namespace(type->children->content, &cptype, &str_ns);
+ nsptr = xmlSearchNs(attrType->doc, attrType, str_ns);
+ if (nsptr != NULL) {
+ newAttr->encode = get_create_encoder(sdl, cur_type, (char *)nsptr->href, (char *)cptype);
+ }
+ if (str_ns) {efree(str_ns);}
+ if (cptype) {efree(cptype);}
+ }
+
attr = attrType->properties;
while (attr != NULL) {
if (attr_is_equal_ex(attr, "default", SCHEMA_NAMESPACE)) {
} else if (attr_is_equal_ex(attr, "name", SCHEMA_NAMESPACE)) {
newAttr->name = strdup(attr->children->content);
} else if (attr_is_equal_ex(attr, "ref", SCHEMA_NAMESPACE)) {
- /*newAttr->ref= strdup(attr->children->content);*/
+ /* already processed */
} else if (attr_is_equal_ex(attr, "type", SCHEMA_NAMESPACE)) {
- type = attr;
- newAttr->type = strdup(attr->children->content);
+ /* already processed */
} else if (attr_is_equal_ex(attr, "use", SCHEMA_NAMESPACE)) {
newAttr->use = strdup(attr->children->content);
} else {
}
if (trav != NULL) {
if (node_is_equal(trav,"simpleType")) {
+ sdlTypePtr dummy_type;
if (ref != NULL) {
php_error(E_ERROR, "Error parsing schema (attribute have both 'ref' attribute and subtype)");
} else if (type != NULL) {
php_error(E_ERROR, "Error parsing schema (attribute have both 'type' attribute and subtype)");
}
- /*FIXME*/
- /*schema_simpleType(sdl, tsn, trav, cur_type);*/
+ dummy_type = malloc(sizeof(sdlType));
+ memset(dummy_type, 0, sizeof(sdlType));
+ dummy_type->name = strdup("anonymous");
+ dummy_type->namens = strdup(tsn->children->content);
+ schema_simpleType(sdl, tsn, trav, dummy_type);
+ newAttr->encode = dummy_type->encode;
+ delete_type(&dummy_type);
trav = trav->next;
}
}
smart_str_appends(&key, newType->name);
smart_str_0(&key);
- zend_hash_update(sdl->attributeGroups, key.c, key.len + 1, &newType, sizeof(sdlTypePtr), NULL);
+ if (zend_hash_add(sdl->attributeGroups, key.c, key.len + 1, &newType, sizeof(sdlTypePtr), NULL) != SUCCESS) {
+ php_error(E_ERROR, "Error parsing schema (attributeGroup '%s' already defined)", key.c);
+ }
cur_type = newType;
smart_str_free(&key);
} else if (ref) {
if ((*tmp)->form != NULL && attr->form == NULL) {
attr->form = strdup((*tmp)->form);
}
- if ((*tmp)->type != NULL && attr->type == NULL) {
- attr->type = strdup((*tmp)->type);
- }
if ((*tmp)->use != NULL && attr->use == NULL) {
attr->use = strdup((*tmp)->use);
}
zend_hash_init(attr->extraAttributes, 0, NULL, NULL, 1);
zend_hash_copy(attr->extraAttributes, (*tmp)->extraAttributes, NULL, &node, sizeof(xmlNodePtr));
}
+ attr->encode = (*tmp)->encode;
}
}
efree(attr->ref);
if (newAttr->def) {newAttr->def = strdup(newAttr->def);}
if (newAttr->fixed) {newAttr->fixed = strdup(newAttr->fixed);}
if (newAttr->form) {newAttr->form = strdup(newAttr->form);}
- if (newAttr->name) {newAttr->fixed = strdup(newAttr->name);}
if (newAttr->name) {newAttr->name = strdup(newAttr->name);}
- if (newAttr->type) {newAttr->type = strdup(newAttr->type);}
if (newAttr->use) {newAttr->use = strdup(newAttr->use);}
if (newAttr->extraAttributes) {
xmlNodePtr node;
}
}
+static void schema_content_model_fixup(sdlPtr sdl, sdlContentModelPtr model)
+{
+ switch (model->kind) {
+ case XSD_CONTENT_GROUP_REF: {
+ sdlTypePtr *tmp;
+
+ if (sdl->groups && zend_hash_find(sdl->groups, model->u.group_ref, strlen(model->u.group_ref)+1, (void**)&tmp) == SUCCESS) {
+ schema_type_fixup(sdl,*tmp);
+ efree(model->u.group_ref);
+ model->kind = XSD_CONTENT_GROUP;
+ model->u.group = (*tmp)->model;
+ } else {
+ php_error(E_ERROR, "Error parsing schema (unresolved group 'ref' attribute)");
+ }
+ break;
+ }
+ case XSD_CONTENT_SEQUENCE:
+ case XSD_CONTENT_ALL:
+ case XSD_CONTENT_CHOICE: {
+ sdlContentModelPtr *tmp;
+
+ zend_hash_internal_pointer_reset(model->u.content);
+ while (zend_hash_get_current_data(model->u.content, (void**)&tmp) == SUCCESS) {
+ schema_content_model_fixup(sdl, *tmp);
+ zend_hash_move_forward(model->u.content);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+}
+
static void schema_type_fixup(sdlPtr sdl, sdlTypePtr type)
{
sdlTypePtr *tmp;
if (sdl->elements != NULL) {
if (zend_hash_find(sdl->elements, type->ref, strlen(type->ref)+1, (void**)&tmp) == SUCCESS) {
type->encode = (*tmp)->encode;
- /* TODO: nillable minOccurs, maxOccurs */
+ /* TODO: nillable */
} else {
php_error(E_ERROR, "Error parsing schema (unresolved element 'ref' attribute)");
}
zend_hash_move_forward(type->elements);
}
}
+ if (type->model) {
+ schema_content_model_fixup(sdl, type->model);
+ }
if (type->attributes) {
zend_hash_internal_pointer_reset(type->attributes);
while (zend_hash_get_current_data(type->attributes,(void**)&attr) == SUCCESS) {
zend_hash_move_forward(sdl->elements);
}
}
+ if (sdl->groups) {
+ zend_hash_internal_pointer_reset(sdl->groups);
+ while (zend_hash_get_current_data(sdl->groups,(void**)&type) == SUCCESS) {
+ schema_type_fixup(sdl,*type);
+ zend_hash_move_forward(sdl->groups);
+ }
+ }
if (sdl->types) {
zend_hash_internal_pointer_reset(sdl->types);
while (zend_hash_get_current_data(sdl->types,(void**)&type) == SUCCESS) {
}
return TRUE;
}
+
+int schema_pass3(sdlPtr sdl)
+{
+ if (sdl->elements) {
+ zend_hash_destroy(sdl->elements);
+ free(sdl->elements);
+ sdl->elements = NULL;
+ }
+ if (sdl->attributes) {
+ zend_hash_destroy(sdl->attributes);
+ free(sdl->attributes);
+ sdl->attributes = NULL;
+ }
+ if (sdl->attributeGroups) {
+ zend_hash_destroy(sdl->attributeGroups);
+ free(sdl->attributeGroups);
+ sdl->attributeGroups = NULL;
+ }
+ return TRUE;
+}
+
+static void delete_model(void *handle)
+{
+ sdlContentModelPtr tmp = *((sdlContentModelPtr*)handle);
+ switch (tmp->kind) {
+ case XSD_CONTENT_ELEMENT:
+ case XSD_CONTENT_GROUP:
+ break;
+ case XSD_CONTENT_SEQUENCE:
+ case XSD_CONTENT_ALL:
+ case XSD_CONTENT_CHOICE:
+ zend_hash_destroy(tmp->u.content);
+ free(tmp->u.content);
+ break;
+ case XSD_CONTENT_GROUP_REF:
+ efree(tmp->u.group_ref);
+ break;
+ }
+ free(tmp);
+}