2004-01-29 17:27:06 +08:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| PHP Version 5 |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2013-01-01 16:28:54 +08:00
| Copyright ( c ) 1997 - 2013 The PHP Group |
2004-01-29 17:27:06 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 20:51:34 +08:00
| This source file is subject to version 3.01 of the PHP license , |
2004-01-29 17:27:06 +08:00
| that is bundled with this package in the file LICENSE , and is |
| available through the world - wide - web at the following url : |
2006-01-01 20:51:34 +08:00
| http : //www.php.net/license/3_01.txt |
2004-01-29 17:27:06 +08:00
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world - wide - web , please send a note to |
| license @ php . net so we can mail you a copy immediately . |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2004-01-29 19:51:11 +08:00
| Authors : Brad Lafountain < rodif_bl @ yahoo . com > |
| Shane Caraveo < shane @ caraveo . com > |
| Dmitry Stogov < dmitry @ zend . com > |
2004-01-29 17:27:06 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
/* $Id$ */
2002-07-08 07:03:43 +08:00
# include "php_soap.h"
2004-01-27 23:48:19 +08:00
# include "libxml/uri.h"
2004-01-06 00:44:01 +08:00
2004-04-01 21:44:12 +08:00
static int schema_simpleType ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr simpleType , sdlTypePtr cur_type ) ;
static int schema_complexType ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr compType , sdlTypePtr cur_type ) ;
static int schema_list ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr listType , sdlTypePtr cur_type ) ;
static int schema_union ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr unionType , sdlTypePtr cur_type ) ;
static int schema_simpleContent ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr simpCompType , sdlTypePtr cur_type ) ;
static int schema_restriction_simpleContent ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr restType , sdlTypePtr cur_type , int simpleType ) ;
static int schema_restriction_complexContent ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr restType , sdlTypePtr cur_type ) ;
static int schema_extension_simpleContent ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr extType , sdlTypePtr cur_type ) ;
static int schema_extension_complexContent ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr extType , sdlTypePtr cur_type ) ;
static int schema_sequence ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr seqType , sdlTypePtr cur_type , sdlContentModelPtr model ) ;
static int schema_all ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr extType , sdlTypePtr cur_type , sdlContentModelPtr model ) ;
static int schema_choice ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr choiceType , sdlTypePtr cur_type , sdlContentModelPtr model ) ;
static int schema_group ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr groupType , sdlTypePtr cur_type , sdlContentModelPtr model ) ;
static int schema_any ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr extType , sdlTypePtr cur_type , sdlContentModelPtr model ) ;
static int schema_element ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr element , sdlTypePtr cur_type , sdlContentModelPtr model ) ;
static int schema_attribute ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr attrType , sdlTypePtr cur_type , sdlCtx * ctx ) ;
static int schema_attributeGroup ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr attrType , sdlTypePtr cur_type , sdlCtx * ctx ) ;
2004-01-06 00:44:01 +08:00
static int schema_restriction_var_int ( xmlNodePtr val , sdlRestrictionIntPtr * valptr ) ;
static int schema_restriction_var_char ( xmlNodePtr val , sdlRestrictionCharPtr * valptr ) ;
2004-01-21 22:00:55 +08:00
2004-02-06 19:56:03 +08:00
static void schema_type_fixup ( sdlCtx * ctx , sdlTypePtr type ) ;
2004-01-22 23:58:03 +08:00
2006-07-11 22:24:18 +08:00
static encodePtr create_encoder ( sdlPtr sdl , sdlTypePtr cur_type , const xmlChar * ns , const xmlChar * type )
2004-01-26 17:51:07 +08:00
{
smart_str nscat = { 0 } ;
encodePtr enc , * enc_ptr ;
if ( sdl - > encoders = = NULL ) {
2004-02-13 19:03:58 +08:00
sdl - > encoders = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( sdl - > encoders , 0 , NULL , delete_encoder , 0 ) ;
2004-01-26 17:51:07 +08:00
}
2006-07-11 22:24:18 +08:00
smart_str_appends ( & nscat , ( char * ) ns ) ;
2004-01-26 17:51:07 +08:00
smart_str_appendc ( & nscat , ' : ' ) ;
2006-07-11 22:24:18 +08:00
smart_str_appends ( & nscat , ( char * ) type ) ;
2004-01-26 17:51:07 +08:00
smart_str_0 ( & nscat ) ;
if ( zend_hash_find ( sdl - > encoders , nscat . c , nscat . len + 1 , ( void * * ) & enc_ptr ) = = SUCCESS ) {
enc = * enc_ptr ;
if ( enc - > details . ns ) {
2004-02-13 19:03:58 +08:00
efree ( enc - > details . ns ) ;
2004-01-26 17:51:07 +08:00
}
if ( enc - > details . type_str ) {
2004-02-13 19:03:58 +08:00
efree ( enc - > details . type_str ) ;
2004-01-26 17:51:07 +08:00
}
} else {
enc_ptr = NULL ;
2004-02-13 19:03:58 +08:00
enc = emalloc ( sizeof ( encode ) ) ;
2004-01-26 17:51:07 +08:00
}
memset ( enc , 0 , sizeof ( encode ) ) ;
2006-07-11 22:24:18 +08:00
enc - > details . ns = estrdup ( ( char * ) ns ) ;
enc - > details . type_str = estrdup ( ( char * ) type ) ;
2004-01-26 17:51:07 +08:00
enc - > details . sdl_type = cur_type ;
enc - > to_xml = sdl_guess_convert_xml ;
enc - > to_zval = sdl_guess_convert_zval ;
if ( enc_ptr = = NULL ) {
zend_hash_update ( sdl - > encoders , nscat . c , nscat . len + 1 , & enc , sizeof ( encodePtr ) , NULL ) ;
}
smart_str_free ( & nscat ) ;
return enc ;
}
2006-07-11 22:24:18 +08:00
static encodePtr get_create_encoder ( sdlPtr sdl , sdlTypePtr cur_type , const xmlChar * ns , const xmlChar * type )
2004-01-26 17:51:07 +08:00
{
2006-07-11 22:24:18 +08:00
encodePtr enc = get_encoder ( sdl , ( char * ) ns , ( char * ) type ) ;
2004-01-26 17:51:07 +08:00
if ( enc = = NULL ) {
enc = create_encoder ( sdl , cur_type , ns , type ) ;
}
return enc ;
}
2004-01-21 22:00:55 +08:00
2005-08-02 19:15:42 +08:00
static void schema_load_file ( sdlCtx * ctx , xmlAttrPtr ns , xmlChar * location , xmlAttrPtr tns , int import TSRMLS_DC ) {
2004-01-23 23:29:59 +08:00
if ( location ! = NULL & &
2006-07-11 22:24:18 +08:00
! zend_hash_exists ( & ctx - > docs , ( char * ) location , xmlStrlen ( location ) + 1 ) ) {
2004-01-23 23:29:59 +08:00
xmlDocPtr doc ;
xmlNodePtr schema ;
xmlAttrPtr new_tns ;
2009-08-18 02:23:48 +08:00
sdl_set_uri_credentials ( ctx , ( char * ) location TSRMLS_CC ) ;
2006-07-11 22:24:18 +08:00
doc = soap_xmlParseFile ( ( char * ) location TSRMLS_CC ) ;
2009-08-18 02:23:48 +08:00
sdl_restore_uri_credentials ( ctx TSRMLS_CC ) ;
2004-01-23 23:29:59 +08:00
if ( doc = = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: can't import schema from '%s' " , location ) ;
2004-01-23 23:29:59 +08:00
}
schema = get_node ( doc - > children , " schema " ) ;
if ( schema = = NULL ) {
xmlFreeDoc ( doc ) ;
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: can't import schema from '%s' " , location ) ;
2004-01-23 23:29:59 +08:00
}
new_tns = get_attribute ( schema - > properties , " targetNamespace " ) ;
if ( import ) {
2006-07-11 22:24:18 +08:00
if ( ns ! = NULL & & ( new_tns = = NULL | | xmlStrcmp ( ns - > children - > content , new_tns - > children - > content ) ! = 0 ) ) {
2004-01-23 23:29:59 +08:00
xmlFreeDoc ( doc ) ;
2006-06-19 19:43:45 +08:00
soap_error2 ( E_ERROR , " Parsing Schema: can't import schema from '%s', unexpected 'targetNamespace'='%s' " , location , ns - > children - > content ) ;
2004-01-23 23:29:59 +08:00
}
if ( ns = = NULL & & new_tns ! = NULL ) {
xmlFreeDoc ( doc ) ;
2004-05-05 18:31:26 +08:00
soap_error2 ( E_ERROR , " Parsing Schema: can't import schema from '%s', unexpected 'targetNamespace'='%s' " , location , new_tns - > children - > content ) ;
2004-01-23 23:29:59 +08:00
}
} else {
new_tns = get_attribute ( schema - > properties , " targetNamespace " ) ;
if ( new_tns = = NULL ) {
if ( tns ! = NULL ) {
2006-07-11 22:24:18 +08:00
xmlSetProp ( schema , BAD_CAST ( " targetNamespace " ) , tns - > children - > content ) ;
2004-01-23 23:29:59 +08:00
}
2006-07-11 22:24:18 +08:00
} else if ( tns ! = NULL & & xmlStrcmp ( tns - > children - > content , new_tns - > children - > content ) ! = 0 ) {
2004-01-23 23:29:59 +08:00
xmlFreeDoc ( doc ) ;
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: can't include schema from '%s', different 'targetNamespace' " , location ) ;
2004-01-23 23:29:59 +08:00
}
}
2006-07-11 22:24:18 +08:00
zend_hash_add ( & ctx - > docs , ( char * ) location , xmlStrlen ( location ) + 1 , ( void * * ) & doc , sizeof ( xmlDocPtr ) , NULL ) ;
2005-08-02 19:15:42 +08:00
load_schema ( ctx , schema TSRMLS_CC ) ;
2004-01-23 23:29:59 +08:00
}
}
2002-07-08 07:03:43 +08:00
/*
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 >
*/
2005-08-02 19:15:42 +08:00
int load_schema ( sdlCtx * ctx , xmlNodePtr schema TSRMLS_DC )
2002-07-08 07:03:43 +08:00
{
2004-01-20 00:40:37 +08:00
xmlNodePtr trav ;
2002-07-08 07:03:43 +08:00
xmlAttrPtr tns ;
2004-02-06 19:56:03 +08:00
if ( ! ctx - > sdl - > types ) {
2004-02-13 19:03:58 +08:00
ctx - > sdl - > types = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( ctx - > sdl - > types , 0 , NULL , delete_type , 0 ) ;
2002-07-08 07:03:43 +08:00
}
2004-02-06 19:56:03 +08:00
if ( ! ctx - > attributes ) {
ctx - > attributes = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( ctx - > attributes , 0 , NULL , delete_attribute , 0 ) ;
}
if ( ! ctx - > attributeGroups ) {
ctx - > attributeGroups = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( ctx - > attributeGroups , 0 , NULL , delete_type , 0 ) ;
2004-01-19 15:22:53 +08:00
}
2002-07-08 07:03:43 +08:00
tns = get_attribute ( schema - > properties , " targetNamespace " ) ;
2004-04-01 21:44:12 +08:00
if ( tns = = NULL ) {
2006-07-11 22:24:18 +08:00
tns = xmlSetProp ( schema , BAD_CAST ( " targetNamespace " ) , BAD_CAST ( " " ) ) ;
xmlNewNs ( schema , BAD_CAST ( " " ) , NULL ) ;
2004-04-01 21:44:12 +08:00
}
2002-07-08 07:03:43 +08:00
trav = schema - > children ;
2004-01-20 00:40:37 +08:00
while ( trav ! = NULL ) {
2004-01-21 22:00:55 +08:00
if ( node_is_equal ( trav , " include " ) ) {
xmlAttrPtr location ;
location = get_attribute ( trav - > properties , " schemaLocation " ) ;
if ( location = = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: include has no 'schemaLocation' attribute " ) ;
2004-01-20 00:40:37 +08:00
} else {
2004-02-13 23:19:09 +08:00
xmlChar * uri ;
2004-01-27 23:48:19 +08:00
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 ) ;
}
2005-08-02 19:15:42 +08:00
schema_load_file ( ctx , NULL , uri , tns , 0 TSRMLS_CC ) ;
2004-02-13 23:19:09 +08:00
xmlFree ( uri ) ;
2004-01-20 00:40:37 +08:00
}
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " redefine " ) ) {
xmlAttrPtr location ;
location = get_attribute ( trav - > properties , " schemaLocation " ) ;
if ( location = = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: redefine has no 'schemaLocation' attribute " ) ;
2004-01-23 23:29:59 +08:00
} else {
2004-01-27 23:48:19 +08:00
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 ) ;
}
2005-08-02 19:15:42 +08:00
schema_load_file ( ctx , NULL , uri , tns , 0 TSRMLS_CC ) ;
2004-02-13 23:19:09 +08:00
xmlFree ( uri ) ;
2004-01-23 23:29:59 +08:00
/* TODO: <redefine> support */
2004-01-21 22:00:55 +08:00
}
} else if ( node_is_equal ( trav , " import " ) ) {
xmlAttrPtr ns , location ;
2004-02-13 23:19:09 +08:00
xmlChar * uri = NULL ;
2004-01-21 22:00:55 +08:00
ns = get_attribute ( trav - > properties , " namespace " ) ;
location = get_attribute ( trav - > properties , " schemaLocation " ) ;
2006-07-11 22:24:18 +08:00
if ( ns ! = NULL & & tns ! = NULL & & xmlStrcmp ( ns - > children - > content , tns - > children - > content ) = = 0 ) {
2005-12-09 23:29:15 +08:00
if ( location ) {
soap_error1 ( E_ERROR , " Parsing Schema: can't import schema from '%s', namespace must not match the enclosing schema 'targetNamespace' " , location - > children - > content ) ;
} else {
soap_error0 ( E_ERROR , " Parsing Schema: can't import schema. Namespace must not match the enclosing schema 'targetNamespace' " ) ;
}
2004-01-21 22:00:55 +08:00
}
2004-01-27 23:48:19 +08:00
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 ) ;
}
2004-01-28 21:30:21 +08:00
}
2005-08-02 19:15:42 +08:00
schema_load_file ( ctx , ns , uri , tns , 1 TSRMLS_CC ) ;
2004-02-13 23:19:09 +08:00
if ( uri ! = NULL ) { xmlFree ( uri ) ; }
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " annotation " ) ) {
/* TODO: <annotation> support */
2004-01-22 23:58:03 +08:00
/* annotation cleanup
xmlNodePtr tmp = trav ;
trav = trav - > next ;
xmlUnlinkNode ( tmp ) ;
xmlFreeNode ( tmp ) ;
continue ;
*/
2004-01-21 22:00:55 +08:00
} else {
2004-02-13 23:19:09 +08:00
break ;
2004-01-16 23:06:23 +08:00
}
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
2002-07-08 07:03:43 +08:00
}
2004-01-20 00:40:37 +08:00
while ( trav ! = NULL ) {
2004-01-21 22:00:55 +08:00
if ( node_is_equal ( trav , " simpleType " ) ) {
2004-02-06 19:56:03 +08:00
schema_simpleType ( ctx - > sdl , tns , trav , NULL ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " complexType " ) ) {
2004-02-06 19:56:03 +08:00
schema_complexType ( ctx - > sdl , tns , trav , NULL ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " group " ) ) {
2004-02-06 19:56:03 +08:00
schema_group ( ctx - > sdl , tns , trav , NULL , NULL ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " attributeGroup " ) ) {
2004-02-06 19:56:03 +08:00
schema_attributeGroup ( ctx - > sdl , tns , trav , NULL , ctx ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " element " ) ) {
2004-02-06 19:56:03 +08:00
schema_element ( ctx - > sdl , tns , trav , NULL , NULL ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " attribute " ) ) {
2004-02-06 19:56:03 +08:00
schema_attribute ( ctx - > sdl , tns , trav , NULL , ctx ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " notation " ) ) {
/* TODO: <notation> support */
} else if ( node_is_equal ( trav , " annotation " ) ) {
/* TODO: <annotation> support */
} else {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in schema " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
trav = trav - > next ;
2004-01-21 22:00:55 +08:00
}
2004-01-20 00:40:37 +08:00
return TRUE ;
2002-07-08 07:03:43 +08:00
}
2004-01-20 00:40:37 +08:00
2002-07-08 07:03:43 +08:00
/*
< simpleType
final = ( # all | ( list | union | restriction ) )
id = ID
name = NCName
{ any attributes with non - schema namespace . . . } >
Content : ( annotation ? , ( restriction | list | union ) )
< / simpleType >
*/
2004-04-01 21:44:12 +08:00
static int schema_simpleType ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr simpleType , sdlTypePtr cur_type )
2002-07-08 07:03:43 +08:00
{
2004-01-20 00:40:37 +08:00
xmlNodePtr trav ;
2002-07-08 07:03:43 +08:00
xmlAttrPtr name , ns ;
ns = get_attribute ( simpleType - > properties , " targetNamespace " ) ;
2004-01-10 02:22:03 +08:00
if ( ns = = NULL ) {
2004-04-01 21:44:12 +08:00
ns = tns ;
2004-01-07 01:14:30 +08:00
}
2002-07-08 07:03:43 +08:00
name = get_attribute ( simpleType - > properties , " name " ) ;
2004-01-21 00:30:38 +08:00
if ( cur_type ! = NULL ) {
/* Anonymous type inside <element> or <restriction> */
sdlTypePtr newType , * ptr ;
2004-02-13 19:03:58 +08:00
newType = emalloc ( sizeof ( sdlType ) ) ;
2004-01-21 00:30:38 +08:00
memset ( newType , 0 , sizeof ( sdlType ) ) ;
newType - > kind = XSD_TYPEKIND_SIMPLE ;
if ( name ! = NULL ) {
2006-07-11 22:24:18 +08:00
newType - > name = estrdup ( ( char * ) name - > children - > content ) ;
newType - > namens = estrdup ( ( char * ) ns - > children - > content ) ;
2004-01-21 00:30:38 +08:00
} else {
2004-02-13 19:03:58 +08:00
newType - > name = estrdup ( cur_type - > name ) ;
newType - > namens = estrdup ( cur_type - > namens ) ;
2004-01-21 00:30:38 +08:00
}
zend_hash_next_index_insert ( sdl - > types , & newType , sizeof ( sdlTypePtr ) , ( void * * ) & ptr ) ;
if ( sdl - > encoders = = NULL ) {
2004-02-13 19:03:58 +08:00
sdl - > encoders = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( sdl - > encoders , 0 , NULL , delete_encoder , 0 ) ;
2004-01-21 00:30:38 +08:00
}
2004-02-13 19:03:58 +08:00
cur_type - > encode = emalloc ( sizeof ( encode ) ) ;
2004-01-21 00:30:38 +08:00
memset ( cur_type - > encode , 0 , sizeof ( encode ) ) ;
2004-02-13 19:03:58 +08:00
cur_type - > encode - > details . ns = estrdup ( newType - > namens ) ;
cur_type - > encode - > details . type_str = estrdup ( newType - > name ) ;
2004-01-21 00:30:38 +08:00
cur_type - > encode - > details . sdl_type = * ptr ;
cur_type - > encode - > to_xml = sdl_guess_convert_xml ;
cur_type - > encode - > to_zval = sdl_guess_convert_zval ;
zend_hash_next_index_insert ( sdl - > encoders , & cur_type - > encode , sizeof ( encodePtr ) , NULL ) ;
cur_type = * ptr ;
} else if ( name ! = NULL ) {
2002-07-08 07:03:43 +08:00
sdlTypePtr newType , * ptr ;
2004-02-13 19:03:58 +08:00
newType = emalloc ( sizeof ( sdlType ) ) ;
2002-07-08 07:03:43 +08:00
memset ( newType , 0 , sizeof ( sdlType ) ) ;
2004-01-21 00:30:38 +08:00
newType - > kind = XSD_TYPEKIND_SIMPLE ;
2006-07-11 22:24:18 +08:00
newType - > name = estrdup ( ( char * ) name - > children - > content ) ;
newType - > namens = estrdup ( ( char * ) ns - > children - > content ) ;
2002-07-08 07:03:43 +08:00
2004-01-10 02:22:03 +08:00
if ( cur_type = = NULL ) {
2004-01-20 00:40:37 +08:00
zend_hash_next_index_insert ( sdl - > types , & newType , sizeof ( sdlTypePtr ) , ( void * * ) & ptr ) ;
2004-01-07 01:14:30 +08:00
} else {
2004-01-10 02:22:03 +08:00
if ( cur_type - > elements = = NULL ) {
2004-02-13 19:03:58 +08:00
cur_type - > elements = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( cur_type - > elements , 0 , NULL , delete_type , 0 ) ;
2002-07-08 07:03:43 +08:00
}
2004-01-20 00:40:37 +08:00
zend_hash_update ( cur_type - > elements , newType - > name , strlen ( newType - > name ) + 1 , & newType , sizeof ( sdlTypePtr ) , ( void * * ) & ptr ) ;
2002-07-08 07:03:43 +08:00
}
cur_type = ( * ptr ) ;
2004-01-20 00:40:37 +08:00
2004-01-16 23:06:23 +08:00
create_encoder ( sdl , cur_type , ns - > children - > content , name - > children - > content ) ;
2004-01-20 00:40:37 +08:00
} else {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: simpleType has no 'name' attribute " ) ;
2002-07-08 07:03:43 +08:00
}
2004-01-20 00:40:37 +08:00
trav = simpleType - > children ;
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
/* TODO: <annotation> support */
trav = trav - > next ;
}
if ( trav ! = NULL ) {
if ( node_is_equal ( trav , " restriction " ) ) {
2004-04-01 21:44:12 +08:00
schema_restriction_simpleContent ( sdl , tns , trav , cur_type , 1 ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " list " ) ) {
2004-01-21 00:30:38 +08:00
cur_type - > kind = XSD_TYPEKIND_LIST ;
2004-04-01 21:44:12 +08:00
schema_list ( sdl , tns , trav , cur_type ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " union " ) ) {
2004-01-21 00:30:38 +08:00
cur_type - > kind = XSD_TYPEKIND_UNION ;
2004-04-01 21:44:12 +08:00
schema_union ( sdl , tns , trav , cur_type ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in simpleType " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
2004-01-21 00:30:38 +08:00
} else {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: expected <restriction>, <list> or <union> in simpleType " ) ;
2004-01-20 00:40:37 +08:00
}
if ( trav ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in simpleType " , trav - > name ) ;
2002-07-08 07:03:43 +08:00
}
2004-01-20 00:40:37 +08:00
return TRUE ;
2002-07-08 07:03:43 +08:00
}
/*
< list
id = ID
itemType = QName
{ any attributes with non - schema namespace . . . } >
Content : ( annotation ? , ( simpleType ? ) )
< / list >
*/
2004-04-01 21:44:12 +08:00
static int schema_list ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr listType , sdlTypePtr cur_type )
2002-07-08 07:03:43 +08:00
{
2004-01-20 00:40:37 +08:00
xmlNodePtr trav ;
xmlAttrPtr itemType ;
itemType = get_attribute ( listType - > properties , " itemType " ) ;
if ( itemType ! = NULL ) {
2004-01-21 00:30:38 +08:00
char * type , * ns ;
xmlNsPtr nsptr ;
parse_namespace ( itemType - > children - > content , & type , & ns ) ;
2006-07-11 22:24:18 +08:00
nsptr = xmlSearchNs ( listType - > doc , listType , BAD_CAST ( ns ) ) ;
2004-01-21 00:30:38 +08:00
if ( nsptr ! = NULL ) {
sdlTypePtr newType , * tmp ;
2004-02-13 19:03:58 +08:00
newType = emalloc ( sizeof ( sdlType ) ) ;
2004-01-21 00:30:38 +08:00
memset ( newType , 0 , sizeof ( sdlType ) ) ;
2004-02-13 19:03:58 +08:00
newType - > name = estrdup ( type ) ;
2006-07-11 22:24:18 +08:00
newType - > namens = estrdup ( ( char * ) nsptr - > href ) ;
2004-01-21 00:30:38 +08:00
2006-07-11 22:24:18 +08:00
newType - > encode = get_create_encoder ( sdl , newType , nsptr - > href , BAD_CAST ( type ) ) ;
2004-01-21 00:30:38 +08:00
if ( cur_type - > elements = = NULL ) {
2004-02-13 19:03:58 +08:00
cur_type - > elements = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( cur_type - > elements , 0 , NULL , delete_type , 0 ) ;
2004-01-21 00:30:38 +08:00
}
2004-01-21 22:00:55 +08:00
zend_hash_next_index_insert ( cur_type - > elements , & newType , sizeof ( sdlTypePtr ) , ( void * * ) & tmp ) ;
2004-01-21 00:30:38 +08:00
}
if ( type ) { efree ( type ) ; }
if ( ns ) { efree ( ns ) ; }
2004-01-20 00:40:37 +08:00
}
trav = listType - > children ;
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
/* TODO: <annotation> support */
trav = trav - > next ;
}
if ( trav ! = NULL & & node_is_equal ( trav , " simpleType " ) ) {
2004-01-21 00:30:38 +08:00
sdlTypePtr newType , * tmp ;
if ( itemType ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: element has both 'itemType' attribute and subtype " ) ;
2004-01-21 00:30:38 +08:00
}
2004-02-13 19:03:58 +08:00
newType = emalloc ( sizeof ( sdlType ) ) ;
2004-01-21 00:30:38 +08:00
memset ( newType , 0 , sizeof ( sdlType ) ) ;
2007-08-31 18:48:45 +08:00
{
smart_str anonymous = { 0 } ;
smart_str_appendl ( & anonymous , " anonymous " , sizeof ( " anonymous " ) - 1 ) ;
smart_str_append_long ( & anonymous , zend_hash_num_elements ( sdl - > types ) ) ;
smart_str_0 ( & anonymous ) ;
newType - > name = anonymous . c ;
}
2006-07-11 22:24:18 +08:00
newType - > namens = estrdup ( ( char * ) tns - > children - > content ) ;
2004-01-21 00:30:38 +08:00
if ( cur_type - > elements = = NULL ) {
2004-02-13 19:03:58 +08:00
cur_type - > elements = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( cur_type - > elements , 0 , NULL , delete_type , 0 ) ;
2004-01-21 00:30:38 +08:00
}
2004-01-21 22:00:55 +08:00
zend_hash_next_index_insert ( cur_type - > elements , & newType , sizeof ( sdlTypePtr ) , ( void * * ) & tmp ) ;
2004-01-21 00:30:38 +08:00
2004-04-01 21:44:12 +08:00
schema_simpleType ( sdl , tns , trav , newType ) ;
2007-08-31 18:48:45 +08:00
2004-02-13 23:19:09 +08:00
trav = trav - > next ;
2004-01-20 00:40:37 +08:00
}
if ( trav ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in list " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
2002-07-08 07:03:43 +08:00
return TRUE ;
}
/*
< union
id = ID
memberTypes = List of QName
{ any attributes with non - schema namespace . . . } >
Content : ( annotation ? , ( simpleType * ) )
< / union >
*/
2004-04-01 21:44:12 +08:00
static int schema_union ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr unionType , sdlTypePtr cur_type )
2002-07-08 07:03:43 +08:00
{
2004-01-20 00:40:37 +08:00
xmlNodePtr trav ;
2004-01-21 00:30:38 +08:00
xmlAttrPtr memberTypes ;
2004-01-20 00:40:37 +08:00
2004-01-21 00:30:38 +08:00
memberTypes = get_attribute ( unionType - > properties , " memberTypes " ) ;
if ( memberTypes ! = NULL ) {
char * str , * start , * end , * next ;
char * type , * ns ;
xmlNsPtr nsptr ;
2006-07-11 22:24:18 +08:00
str = estrdup ( ( char * ) memberTypes - > children - > content ) ;
whiteSpace_collapse ( BAD_CAST ( str ) ) ;
2004-01-21 00:30:38 +08:00
start = str ;
while ( start ! = NULL & & * start ! = ' \0 ' ) {
end = strchr ( start , ' ' ) ;
if ( end = = NULL ) {
2004-02-13 23:19:09 +08:00
next = NULL ;
2004-01-21 00:30:38 +08:00
} else {
2004-02-13 23:19:09 +08:00
* end = ' \0 ' ;
next = end + 1 ;
2004-01-21 00:30:38 +08:00
}
2006-07-11 22:24:18 +08:00
parse_namespace ( BAD_CAST ( start ) , & type , & ns ) ;
nsptr = xmlSearchNs ( unionType - > doc , unionType , BAD_CAST ( ns ) ) ;
2004-01-21 00:30:38 +08:00
if ( nsptr ! = NULL ) {
sdlTypePtr newType , * tmp ;
2004-02-13 19:03:58 +08:00
newType = emalloc ( sizeof ( sdlType ) ) ;
2004-01-21 00:30:38 +08:00
memset ( newType , 0 , sizeof ( sdlType ) ) ;
2004-02-13 19:03:58 +08:00
newType - > name = estrdup ( type ) ;
2006-07-11 22:24:18 +08:00
newType - > namens = estrdup ( ( char * ) nsptr - > href ) ;
2004-01-21 00:30:38 +08:00
2006-07-11 22:24:18 +08:00
newType - > encode = get_create_encoder ( sdl , newType , nsptr - > href , BAD_CAST ( type ) ) ;
2004-01-21 00:30:38 +08:00
if ( cur_type - > elements = = NULL ) {
2004-02-13 19:03:58 +08:00
cur_type - > elements = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( cur_type - > elements , 0 , NULL , delete_type , 0 ) ;
2004-01-21 00:30:38 +08:00
}
2004-01-21 22:00:55 +08:00
zend_hash_next_index_insert ( cur_type - > elements , & newType , sizeof ( sdlTypePtr ) , ( void * * ) & tmp ) ;
2004-01-21 00:30:38 +08:00
}
if ( type ) { efree ( type ) ; }
if ( ns ) { efree ( ns ) ; }
start = next ;
}
efree ( str ) ;
2004-01-20 00:40:37 +08:00
}
trav = unionType - > children ;
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
/* TODO: <annotation> support */
trav = trav - > next ;
}
while ( trav ! = NULL ) {
2004-01-21 22:00:55 +08:00
if ( node_is_equal ( trav , " simpleType " ) ) {
sdlTypePtr newType , * tmp ;
2004-01-21 00:30:38 +08:00
2004-02-13 19:03:58 +08:00
newType = emalloc ( sizeof ( sdlType ) ) ;
2004-01-21 22:00:55 +08:00
memset ( newType , 0 , sizeof ( sdlType ) ) ;
2004-01-21 00:30:38 +08:00
2007-08-31 18:48:45 +08:00
{
smart_str anonymous = { 0 } ;
smart_str_appendl ( & anonymous , " anonymous " , sizeof ( " anonymous " ) - 1 ) ;
smart_str_append_long ( & anonymous , zend_hash_num_elements ( sdl - > types ) ) ;
smart_str_0 ( & anonymous ) ;
newType - > name = anonymous . c ;
}
2006-07-11 22:24:18 +08:00
newType - > namens = estrdup ( ( char * ) tns - > children - > content ) ;
2004-01-21 00:30:38 +08:00
2004-01-21 22:00:55 +08:00
if ( cur_type - > elements = = NULL ) {
2004-02-13 19:03:58 +08:00
cur_type - > elements = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( cur_type - > elements , 0 , NULL , delete_type , 0 ) ;
2004-01-20 00:40:37 +08:00
}
2004-01-21 22:00:55 +08:00
zend_hash_next_index_insert ( cur_type - > elements , & newType , sizeof ( sdlTypePtr ) , ( void * * ) & tmp ) ;
2004-04-01 21:44:12 +08:00
schema_simpleType ( sdl , tns , trav , newType ) ;
2004-01-21 22:00:55 +08:00
} else {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in union " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
trav = trav - > next ;
}
if ( trav ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in union " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
2002-07-08 07:03:43 +08:00
return TRUE ;
}
/*
< simpleContent
id = ID
{ any attributes with non - schema namespace . . . } >
Content : ( annotation ? , ( restriction | extension ) )
< / simpleContent >
*/
2004-04-01 21:44:12 +08:00
static int schema_simpleContent ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr simpCompType , sdlTypePtr cur_type )
2002-07-08 07:03:43 +08:00
{
2004-01-20 00:40:37 +08:00
xmlNodePtr trav ;
2002-07-08 07:03:43 +08:00
2004-01-20 00:40:37 +08:00
trav = simpCompType - > children ;
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
/* TODO: <annotation> support */
trav = trav - > next ;
}
if ( trav ! = NULL ) {
if ( node_is_equal ( trav , " restriction " ) ) {
2004-01-23 22:43:15 +08:00
cur_type - > kind = XSD_TYPEKIND_RESTRICTION ;
2004-04-01 21:44:12 +08:00
schema_restriction_simpleContent ( sdl , tns , trav , cur_type , 0 ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " extension " ) ) {
2004-01-23 22:43:15 +08:00
cur_type - > kind = XSD_TYPEKIND_EXTENSION ;
2004-04-01 21:44:12 +08:00
schema_extension_simpleContent ( sdl , tns , trav , cur_type ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in simpleContent " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
} else {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: expected <restriction> or <extension> in simpleContent " ) ;
2004-01-20 00:40:37 +08:00
}
if ( trav ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in simpleContent " , trav - > name ) ;
2002-07-08 07:03:43 +08:00
}
2004-01-20 00:40:37 +08:00
return TRUE ;
2002-07-08 07:03:43 +08:00
}
/*
2004-01-21 00:30:38 +08:00
simpleType : < 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 >
simpleContent : < restriction
2002-07-08 07:03:43 +08:00
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 >
*/
2004-04-01 21:44:12 +08:00
static int schema_restriction_simpleContent ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr restType , sdlTypePtr cur_type , int simpleType )
2002-07-08 07:03:43 +08:00
{
2004-01-20 00:40:37 +08:00
xmlNodePtr trav ;
2002-07-08 07:03:43 +08:00
xmlAttrPtr base ;
base = get_attribute ( restType - > properties , " base " ) ;
2004-01-10 02:22:03 +08:00
if ( base ! = NULL ) {
2004-01-07 01:14:30 +08:00
char * type , * ns ;
xmlNsPtr nsptr ;
parse_namespace ( base - > children - > content , & type , & ns ) ;
2006-07-11 22:24:18 +08:00
nsptr = xmlSearchNs ( restType - > doc , restType , BAD_CAST ( ns ) ) ;
2004-01-10 02:22:03 +08:00
if ( nsptr ! = NULL ) {
2006-07-11 22:24:18 +08:00
cur_type - > encode = get_create_encoder ( sdl , cur_type , nsptr - > href , BAD_CAST ( type ) ) ;
2004-01-07 01:14:30 +08:00
}
2004-01-10 02:22:03 +08:00
if ( type ) { efree ( type ) ; }
if ( ns ) { efree ( ns ) ; }
2004-01-21 00:30:38 +08:00
} else if ( ! simpleType ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: restriction has no 'base' attribute " ) ;
2002-07-08 07:03:43 +08:00
}
2004-01-10 02:22:03 +08:00
if ( cur_type - > restrictions = = NULL ) {
2004-02-13 19:03:58 +08:00
cur_type - > restrictions = emalloc ( sizeof ( sdlRestrictions ) ) ;
2002-07-08 07:03:43 +08:00
memset ( cur_type - > restrictions , 0 , sizeof ( sdlRestrictions ) ) ;
}
trav = restType - > children ;
2004-02-24 18:13:25 +08:00
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
2004-01-20 00:40:37 +08:00
/* TODO: <annotation> support */
trav = trav - > next ;
}
if ( trav ! = NULL & & node_is_equal ( trav , " simpleType " ) ) {
2004-04-01 21:44:12 +08:00
schema_simpleType ( sdl , tns , trav , cur_type ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
}
2004-01-06 00:44:01 +08:00
while ( trav ! = NULL ) {
2004-02-05 17:28:09 +08:00
if ( node_is_equal ( trav , " minExclusive " ) ) {
2004-01-21 22:00:55 +08:00
schema_restriction_var_int ( trav , & cur_type - > restrictions - > minExclusive ) ;
2004-02-05 17:28:09 +08:00
} else if ( node_is_equal ( trav , " minInclusive " ) ) {
2004-01-21 22:00:55 +08:00
schema_restriction_var_int ( trav , & cur_type - > restrictions - > minInclusive ) ;
2004-02-05 17:28:09 +08:00
} else if ( node_is_equal ( trav , " maxExclusive " ) ) {
2004-01-21 22:00:55 +08:00
schema_restriction_var_int ( trav , & cur_type - > restrictions - > maxExclusive ) ;
2004-02-05 17:28:09 +08:00
} else if ( node_is_equal ( trav , " maxInclusive " ) ) {
2004-01-21 22:00:55 +08:00
schema_restriction_var_int ( trav , & cur_type - > restrictions - > maxInclusive ) ;
2004-02-05 17:28:09 +08:00
} else if ( node_is_equal ( trav , " totalDigits " ) ) {
2004-01-21 22:00:55 +08:00
schema_restriction_var_int ( trav , & cur_type - > restrictions - > totalDigits ) ;
2004-02-05 17:28:09 +08:00
} else if ( node_is_equal ( trav , " fractionDigits " ) ) {
2004-01-21 22:00:55 +08:00
schema_restriction_var_int ( trav , & cur_type - > restrictions - > fractionDigits ) ;
2004-02-05 17:28:09 +08:00
} else if ( node_is_equal ( trav , " length " ) ) {
2004-01-21 22:00:55 +08:00
schema_restriction_var_int ( trav , & cur_type - > restrictions - > length ) ;
2004-02-05 17:28:09 +08:00
} else if ( node_is_equal ( trav , " minLength " ) ) {
2004-01-21 22:00:55 +08:00
schema_restriction_var_int ( trav , & cur_type - > restrictions - > minLength ) ;
2004-02-05 17:28:09 +08:00
} else if ( node_is_equal ( trav , " maxLength " ) ) {
2004-01-21 22:00:55 +08:00
schema_restriction_var_int ( trav , & cur_type - > restrictions - > maxLength ) ;
2004-02-05 17:28:09 +08:00
} else if ( node_is_equal ( trav , " whiteSpace " ) ) {
2004-01-21 22:00:55 +08:00
schema_restriction_var_char ( trav , & cur_type - > restrictions - > whiteSpace ) ;
2004-02-05 17:28:09 +08:00
} else if ( node_is_equal ( trav , " pattern " ) ) {
2004-01-21 22:00:55 +08:00
schema_restriction_var_char ( trav , & cur_type - > restrictions - > pattern ) ;
2004-02-05 17:28:09 +08:00
} else if ( node_is_equal ( trav , " enumeration " ) ) {
2004-01-21 22:00:55 +08:00
sdlRestrictionCharPtr enumval = NULL ;
schema_restriction_var_char ( trav , & enumval ) ;
if ( cur_type - > restrictions - > enumeration = = NULL ) {
2004-02-13 19:03:58 +08:00
cur_type - > restrictions - > enumeration = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( cur_type - > restrictions - > enumeration , 0 , NULL , delete_restriction_var_char , 0 ) ;
2002-07-08 07:03:43 +08:00
}
2007-02-16 01:01:29 +08:00
if ( zend_hash_add ( cur_type - > restrictions - > enumeration , enumval - > value , strlen ( enumval - > value ) + 1 , & enumval , sizeof ( sdlRestrictionCharPtr ) , NULL ) = = FAILURE ) {
delete_restriction_var_char ( & enumval ) ;
}
2004-01-21 22:00:55 +08:00
} else {
break ;
2002-07-08 07:03:43 +08:00
}
2004-02-13 23:19:09 +08:00
trav = trav - > next ;
2004-01-06 00:44:01 +08:00
}
2004-01-21 00:30:38 +08:00
if ( ! simpleType ) {
while ( trav ! = NULL ) {
2004-01-21 22:00:55 +08:00
if ( node_is_equal ( trav , " attribute " ) ) {
2004-04-01 21:44:12 +08:00
schema_attribute ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " attributeGroup " ) ) {
2004-04-01 21:44:12 +08:00
schema_attributeGroup ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " anyAttribute " ) ) {
/* TODO: <anyAttribute> support */
trav = trav - > next ;
break ;
} else {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in restriction " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
2004-01-21 00:30:38 +08:00
trav = trav - > next ;
2004-01-20 00:40:37 +08:00
}
}
if ( trav ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in restriction " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
2002-07-08 07:03:43 +08:00
return TRUE ;
}
/*
< restriction
base = QName
id = ID
{ any attributes with non - schema namespace . . . } >
Content : ( annotation ? , ( group | all | choice | sequence ) ? , ( ( attribute | attributeGroup ) * , anyAttribute ? ) )
< / restriction >
*/
2004-04-01 21:44:12 +08:00
static int schema_restriction_complexContent ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr restType , sdlTypePtr cur_type )
2002-07-08 07:03:43 +08:00
{
xmlAttrPtr base ;
xmlNodePtr trav ;
base = get_attribute ( restType - > properties , " base " ) ;
2004-01-10 02:22:03 +08:00
if ( base ! = NULL ) {
2002-07-08 07:03:43 +08:00
char * type , * ns ;
xmlNsPtr nsptr ;
parse_namespace ( base - > children - > content , & type , & ns ) ;
2006-07-11 22:24:18 +08:00
nsptr = xmlSearchNs ( restType - > doc , restType , BAD_CAST ( ns ) ) ;
2004-01-10 02:22:03 +08:00
if ( nsptr ! = NULL ) {
2006-07-11 22:24:18 +08:00
cur_type - > encode = get_create_encoder ( sdl , cur_type , nsptr - > href , BAD_CAST ( type ) ) ;
2002-07-08 07:03:43 +08:00
}
2004-01-10 02:22:03 +08:00
if ( type ) { efree ( type ) ; }
if ( ns ) { efree ( ns ) ; }
2004-01-20 00:40:37 +08:00
} else {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: restriction has no 'base' attribute " ) ;
2002-07-08 07:03:43 +08:00
}
trav = restType - > children ;
2004-01-20 00:40:37 +08:00
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
2004-02-24 18:13:25 +08:00
/* TODO: <annotation> support */
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
2004-01-12 16:48:00 +08:00
}
2004-01-20 00:40:37 +08:00
if ( trav ! = NULL ) {
if ( node_is_equal ( trav , " group " ) ) {
2004-04-01 21:44:12 +08:00
schema_group ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " all " ) ) {
2004-04-01 21:44:12 +08:00
schema_all ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " choice " ) ) {
2004-04-01 21:44:12 +08:00
schema_choice ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " sequence " ) ) {
2004-04-01 21:44:12 +08:00
schema_sequence ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
}
2004-01-07 01:14:30 +08:00
}
2004-01-06 00:44:01 +08:00
while ( trav ! = NULL ) {
2004-01-21 22:00:55 +08:00
if ( node_is_equal ( trav , " attribute " ) ) {
2004-04-01 21:44:12 +08:00
schema_attribute ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " attributeGroup " ) ) {
2004-04-01 21:44:12 +08:00
schema_attributeGroup ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " anyAttribute " ) ) {
/* TODO: <anyAttribute> support */
trav = trav - > next ;
break ;
} else {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in restriction " , trav - > name ) ;
2002-07-08 07:03:43 +08:00
}
2004-01-10 02:22:03 +08:00
trav = trav - > next ;
2004-01-06 00:44:01 +08:00
}
2004-01-20 00:40:37 +08:00
if ( trav ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in restriction " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
2002-07-08 07:03:43 +08:00
return TRUE ;
}
2004-01-06 00:44:01 +08:00
static int schema_restriction_var_int ( xmlNodePtr val , sdlRestrictionIntPtr * valptr )
2002-07-08 07:03:43 +08:00
{
2004-01-26 17:51:07 +08:00
xmlAttrPtr fixed , value ;
2002-07-08 07:03:43 +08:00
2004-01-10 02:22:03 +08:00
if ( ( * valptr ) = = NULL ) {
2004-02-13 19:03:58 +08:00
( * valptr ) = emalloc ( sizeof ( sdlRestrictionInt ) ) ;
2004-01-07 01:14:30 +08:00
}
memset ( ( * valptr ) , 0 , sizeof ( sdlRestrictionInt ) ) ;
2002-07-08 07:03:43 +08:00
fixed = get_attribute ( val - > properties , " fixed " ) ;
( * valptr ) - > fixed = FALSE ;
2004-01-10 02:22:03 +08:00
if ( fixed ! = NULL ) {
2006-07-11 22:24:18 +08:00
if ( ! strncmp ( ( char * ) fixed - > children - > content , " true " , sizeof ( " true " ) ) | |
! strncmp ( ( char * ) fixed - > children - > content , " 1 " , sizeof ( " 1 " ) ) )
2002-07-08 07:03:43 +08:00
( * valptr ) - > fixed = TRUE ;
}
value = get_attribute ( val - > properties , " value " ) ;
2004-01-10 02:22:03 +08:00
if ( value = = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: missing restriction value " ) ;
2004-01-07 01:14:30 +08:00
}
2002-07-08 07:03:43 +08:00
2006-07-11 22:24:18 +08:00
( * valptr ) - > value = atoi ( ( char * ) value - > children - > content ) ;
2002-07-08 07:03:43 +08:00
return TRUE ;
}
2004-01-06 00:44:01 +08:00
static int schema_restriction_var_char ( xmlNodePtr val , sdlRestrictionCharPtr * valptr )
2002-07-08 07:03:43 +08:00
{
2004-01-26 17:51:07 +08:00
xmlAttrPtr fixed , value ;
2002-07-08 07:03:43 +08:00
2004-01-10 02:22:03 +08:00
if ( ( * valptr ) = = NULL ) {
2004-02-13 19:03:58 +08:00
( * valptr ) = emalloc ( sizeof ( sdlRestrictionChar ) ) ;
2004-01-07 01:14:30 +08:00
}
memset ( ( * valptr ) , 0 , sizeof ( sdlRestrictionChar ) ) ;
2002-07-08 07:03:43 +08:00
fixed = get_attribute ( val - > properties , " fixed " ) ;
( * valptr ) - > fixed = FALSE ;
2004-01-10 02:22:03 +08:00
if ( fixed ! = NULL ) {
2006-07-11 22:24:18 +08:00
if ( ! strncmp ( ( char * ) fixed - > children - > content , " true " , sizeof ( " true " ) ) | |
! strncmp ( ( char * ) fixed - > children - > content , " 1 " , sizeof ( " 1 " ) ) ) {
2002-07-08 07:03:43 +08:00
( * valptr ) - > fixed = TRUE ;
2004-01-07 01:14:30 +08:00
}
2002-07-08 07:03:43 +08:00
}
value = get_attribute ( val - > properties , " value " ) ;
2004-01-10 02:22:03 +08:00
if ( value = = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: missing restriction value " ) ;
2004-01-07 01:14:30 +08:00
}
2002-07-08 07:03:43 +08:00
2006-07-11 22:24:18 +08:00
( * valptr ) - > value = estrdup ( ( char * ) value - > children - > content ) ;
2002-07-08 07:03:43 +08:00
return TRUE ;
}
/*
From simpleContent ( not supported ) :
< extension
base = QName
id = ID
{ any attributes with non - schema namespace . . . } >
Content : ( annotation ? , ( ( attribute | attributeGroup ) * , anyAttribute ? ) )
< / extension >
2004-01-07 01:14:30 +08:00
*/
2004-04-01 21:44:12 +08:00
static int schema_extension_simpleContent ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr extType , sdlTypePtr cur_type )
2004-01-07 01:14:30 +08:00
{
2004-01-20 00:40:37 +08:00
xmlNodePtr trav ;
xmlAttrPtr base ;
base = get_attribute ( extType - > properties , " base " ) ;
if ( base ! = NULL ) {
2004-01-23 17:15:58 +08:00
char * type , * ns ;
xmlNsPtr nsptr ;
parse_namespace ( base - > children - > content , & type , & ns ) ;
2006-07-11 22:24:18 +08:00
nsptr = xmlSearchNs ( extType - > doc , extType , BAD_CAST ( ns ) ) ;
2004-01-23 17:15:58 +08:00
if ( nsptr ! = NULL ) {
2006-07-11 22:24:18 +08:00
cur_type - > encode = get_create_encoder ( sdl , cur_type , nsptr - > href , BAD_CAST ( type ) ) ;
2004-01-23 17:15:58 +08:00
}
if ( type ) { efree ( type ) ; }
if ( ns ) { efree ( ns ) ; }
2004-01-20 00:40:37 +08:00
} else {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: extension has no 'base' attribute " ) ;
2004-01-20 00:40:37 +08:00
}
trav = extType - > children ;
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
2004-02-24 18:13:25 +08:00
/* TODO: <annotation> support */
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
}
while ( trav ! = NULL ) {
2004-01-21 22:00:55 +08:00
if ( node_is_equal ( trav , " attribute " ) ) {
2004-04-01 21:44:12 +08:00
schema_attribute ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " attributeGroup " ) ) {
2004-04-01 21:44:12 +08:00
schema_attributeGroup ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " anyAttribute " ) ) {
/* TODO: <anyAttribute> support */
trav = trav - > next ;
break ;
} else {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in extension " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
trav = trav - > next ;
}
if ( trav ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in extension " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
2004-01-07 01:14:30 +08:00
return TRUE ;
}
2002-07-08 07:03:43 +08:00
2004-01-07 01:14:30 +08:00
/*
2002-07-08 07:03:43 +08: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-04-01 21:44:12 +08:00
static int schema_extension_complexContent ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr extType , sdlTypePtr cur_type )
2002-07-08 07:03:43 +08:00
{
2004-01-20 00:40:37 +08:00
xmlNodePtr trav ;
2002-07-08 07:03:43 +08:00
xmlAttrPtr base ;
base = get_attribute ( extType - > properties , " base " ) ;
2004-01-20 00:40:37 +08:00
if ( base ! = NULL ) {
2004-01-23 17:15:58 +08:00
char * type , * ns ;
xmlNsPtr nsptr ;
parse_namespace ( base - > children - > content , & type , & ns ) ;
2006-07-11 22:24:18 +08:00
nsptr = xmlSearchNs ( extType - > doc , extType , BAD_CAST ( ns ) ) ;
2004-01-23 17:15:58 +08:00
if ( nsptr ! = NULL ) {
2006-07-11 22:24:18 +08:00
cur_type - > encode = get_create_encoder ( sdl , cur_type , nsptr - > href , BAD_CAST ( type ) ) ;
2004-01-23 17:15:58 +08:00
}
if ( type ) { efree ( type ) ; }
if ( ns ) { efree ( ns ) ; }
2004-01-20 00:40:37 +08:00
} else {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: extension has no 'base' attribute " ) ;
2002-07-08 07:03:43 +08:00
}
2004-01-20 00:40:37 +08:00
trav = extType - > children ;
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
2004-02-24 18:13:25 +08:00
/* TODO: <annotation> support */
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
2002-07-08 07:03:43 +08:00
}
2004-01-20 00:40:37 +08:00
if ( trav ! = NULL ) {
if ( node_is_equal ( trav , " group " ) ) {
2004-04-01 21:44:12 +08:00
schema_group ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " all " ) ) {
2004-04-01 21:44:12 +08:00
schema_all ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " choice " ) ) {
2004-04-01 21:44:12 +08:00
schema_choice ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " sequence " ) ) {
2004-04-01 21:44:12 +08:00
schema_sequence ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
}
}
while ( trav ! = NULL ) {
2004-01-21 22:00:55 +08:00
if ( node_is_equal ( trav , " attribute " ) ) {
2004-04-01 21:44:12 +08:00
schema_attribute ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " attributeGroup " ) ) {
2004-04-01 21:44:12 +08:00
schema_attributeGroup ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " anyAttribute " ) ) {
/* TODO: <anyAttribute> support */
trav = trav - > next ;
break ;
} else {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in extension " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
trav = trav - > next ;
2002-07-08 07:03:43 +08:00
}
2004-01-20 00:40:37 +08:00
if ( trav ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in extension " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
return TRUE ;
2002-07-08 07:03:43 +08:00
}
2006-07-11 22:24:18 +08:00
void schema_min_max ( xmlNodePtr node , sdlContentModelPtr model )
{
xmlAttrPtr attr = get_attribute ( node - > properties , " minOccurs " ) ;
if ( attr ) {
model - > min_occurs = atoi ( ( char * ) attr - > children - > content ) ;
} else {
model - > min_occurs = 1 ;
}
attr = get_attribute ( node - > properties , " maxOccurs " ) ;
if ( attr ) {
if ( ! strncmp ( ( char * ) attr - > children - > content , " unbounded " , sizeof ( " unbounded " ) ) ) {
model - > max_occurs = - 1 ;
} else {
model - > max_occurs = atoi ( ( char * ) attr - > children - > content ) ;
}
} else {
model - > max_occurs = 1 ;
}
}
2002-07-08 07:03:43 +08:00
/*
< all
id = ID
maxOccurs = 1 : 1
minOccurs = ( 0 | 1 ) : 1
{ any attributes with non - schema namespace . . . } >
Content : ( annotation ? , element * )
< / all >
*/
2004-04-01 21:44:12 +08:00
static int schema_all ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr all , sdlTypePtr cur_type , sdlContentModelPtr model )
2002-07-08 07:03:43 +08:00
{
2004-01-20 00:40:37 +08:00
xmlNodePtr trav ;
2004-01-22 23:58:03 +08:00
sdlContentModelPtr newModel ;
2004-02-13 19:03:58 +08:00
newModel = emalloc ( sizeof ( sdlContentModel ) ) ;
2004-01-22 23:58:03 +08:00
newModel - > kind = XSD_CONTENT_ALL ;
2004-02-13 19:03:58 +08:00
newModel - > u . content = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( newModel - > u . content , 0 , NULL , delete_model , 0 ) ;
2004-01-22 23:58:03 +08:00
if ( model = = NULL ) {
2004-01-23 17:15:58 +08:00
cur_type - > model = newModel ;
2004-01-22 23:58:03 +08:00
} else {
zend_hash_next_index_insert ( model - > u . content , & newModel , sizeof ( sdlContentModelPtr ) , NULL ) ;
}
2006-07-11 22:24:18 +08:00
schema_min_max ( all , newModel ) ;
2002-07-08 07:03:43 +08:00
trav = all - > children ;
2004-01-20 00:40:37 +08:00
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
2004-02-24 18:13:25 +08:00
/* TODO: <annotation> support */
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
}
while ( trav ! = NULL ) {
2004-01-21 22:00:55 +08:00
if ( node_is_equal ( trav , " element " ) ) {
2004-04-01 21:44:12 +08:00
schema_element ( sdl , tns , trav , cur_type , newModel ) ;
2004-01-21 22:00:55 +08:00
} else {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in all " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
trav = trav - > next ;
2002-07-08 07:03:43 +08:00
}
return TRUE ;
}
/*
< group
2004-01-22 23:58:03 +08:00
name = NCName
2002-07-08 07:03:43 +08:00
Content : ( annotation ? , ( all | choice | sequence ) )
< / group >
2004-01-22 23:58:03 +08:00
< group
name = NCName
ref = QName >
Content : ( annotation ? )
< / group >
2002-07-08 07:03:43 +08:00
*/
2004-04-01 21:44:12 +08:00
static int schema_group ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr groupType , sdlTypePtr cur_type , sdlContentModelPtr model )
2002-07-08 07:03:43 +08:00
{
2004-01-20 00:40:37 +08:00
xmlNodePtr trav ;
2004-01-22 23:58:03 +08:00
xmlAttrPtr ns , name , ref = NULL ;
sdlContentModelPtr newModel ;
ns = get_attribute ( groupType - > properties , " targetNamespace " ) ;
if ( ns = = NULL ) {
2004-04-01 21:44:12 +08:00
ns = tns ;
2004-01-22 23:58:03 +08:00
}
2002-07-08 07:03:43 +08:00
name = get_attribute ( groupType - > properties , " name " ) ;
2004-01-22 23:58:03 +08:00
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 ) ;
2006-07-11 22:24:18 +08:00
nsptr = xmlSearchNs ( groupType - > doc , groupType , BAD_CAST ( ns ) ) ;
2004-01-22 23:58:03 +08:00
if ( nsptr ! = NULL ) {
2006-07-11 22:24:18 +08:00
smart_str_appends ( & key , ( char * ) nsptr - > href ) ;
2013-07-31 21:36:06 +08:00
} else {
xmlAttrPtr ns = get_attribute ( groupType - > properties , " targetNamespace " ) ;
if ( ns = = NULL ) {
ns = tns ;
}
if ( ns ) {
smart_str_appends ( & key , ( char * ) ns - > children - > content ) ;
}
2004-01-22 23:58:03 +08:00
}
2011-11-14 16:43:00 +08:00
smart_str_appendc ( & key , ' : ' ) ;
2004-01-22 23:58:03 +08:00
smart_str_appends ( & key , type ) ;
smart_str_0 ( & key ) ;
2004-02-13 19:03:58 +08:00
newModel = emalloc ( sizeof ( sdlContentModel ) ) ;
2004-01-22 23:58:03 +08:00
newModel - > kind = XSD_CONTENT_GROUP_REF ;
newModel - > u . group_ref = estrdup ( key . c ) ;
2004-01-23 17:15:58 +08:00
2004-01-22 23:58:03 +08:00
if ( type ) { efree ( type ) ; }
if ( ns ) { efree ( ns ) ; }
} else {
2004-02-13 19:03:58 +08:00
newModel = emalloc ( sizeof ( sdlContentModel ) ) ;
2004-01-22 23:58:03 +08:00
newModel - > kind = XSD_CONTENT_SEQUENCE ; /* will be redefined */
2004-02-13 19:03:58 +08:00
newModel - > u . content = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( newModel - > u . content , 0 , NULL , delete_model , 0 ) ;
2004-01-22 23:58:03 +08:00
2006-07-11 22:24:18 +08:00
smart_str_appends ( & key , ( char * ) ns - > children - > content ) ;
2004-01-22 23:58:03 +08:00
smart_str_appendc ( & key , ' : ' ) ;
2006-07-11 22:24:18 +08:00
smart_str_appends ( & key , ( char * ) name - > children - > content ) ;
2004-01-22 23:58:03 +08:00
smart_str_0 ( & key ) ;
}
if ( cur_type = = NULL ) {
sdlTypePtr newType ;
2004-01-23 17:15:58 +08:00
2004-02-13 19:03:58 +08:00
newType = emalloc ( sizeof ( sdlType ) ) ;
2004-01-22 23:58:03 +08:00
memset ( newType , 0 , sizeof ( sdlType ) ) ;
2004-01-23 17:15:58 +08:00
2004-01-22 23:58:03 +08:00
if ( sdl - > groups = = NULL ) {
2004-02-13 19:03:58 +08:00
sdl - > groups = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( sdl - > groups , 0 , NULL , delete_type , 0 ) ;
2004-01-22 23:58:03 +08:00
}
if ( zend_hash_add ( sdl - > groups , key . c , key . len + 1 , ( void * * ) & newType , sizeof ( sdlTypePtr ) , NULL ) ! = SUCCESS ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: group '%s' already defined " , key . c ) ;
2004-01-22 23:58:03 +08:00
}
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 {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: group has no 'name' nor 'ref' attributes " ) ;
2004-01-22 23:58:03 +08:00
}
2006-07-11 22:24:18 +08:00
schema_min_max ( groupType , newModel ) ;
2002-07-08 07:03:43 +08:00
2004-01-20 00:40:37 +08:00
trav = groupType - > children ;
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
2004-02-24 18:13:25 +08:00
/* TODO: <annotation> support */
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
2002-07-08 07:03:43 +08:00
}
2004-01-21 00:30:38 +08:00
if ( trav ! = NULL ) {
if ( node_is_equal ( trav , " choice " ) ) {
2004-01-22 23:58:03 +08:00
if ( ref ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: group has both 'ref' attribute and subcontent " ) ;
2004-01-22 23:58:03 +08:00
}
newModel - > kind = XSD_CONTENT_CHOICE ;
2004-04-01 21:44:12 +08:00
schema_choice ( sdl , tns , trav , cur_type , newModel ) ;
2004-01-21 00:30:38 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " sequence " ) ) {
2004-01-22 23:58:03 +08:00
if ( ref ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: group has both 'ref' attribute and subcontent " ) ;
2004-01-22 23:58:03 +08:00
}
newModel - > kind = XSD_CONTENT_SEQUENCE ;
2004-04-01 21:44:12 +08:00
schema_sequence ( sdl , tns , trav , cur_type , newModel ) ;
2004-01-21 00:30:38 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " all " ) ) {
2004-01-22 23:58:03 +08:00
if ( ref ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: group has both 'ref' attribute and subcontent " ) ;
2004-01-22 23:58:03 +08:00
}
newModel - > kind = XSD_CONTENT_ALL ;
2004-04-01 21:44:12 +08:00
schema_all ( sdl , tns , trav , cur_type , newModel ) ;
2004-01-21 00:30:38 +08:00
trav = trav - > next ;
} else {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in group " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
2004-01-21 00:30:38 +08:00
}
if ( trav ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in group " , trav - > name ) ;
2004-01-21 00:30:38 +08:00
}
2004-01-20 00:40:37 +08:00
return TRUE ;
2002-07-08 07:03:43 +08:00
}
/*
< choice
id = ID
maxOccurs = ( nonNegativeInteger | unbounded ) : 1
minOccurs = nonNegativeInteger : 1
{ any attributes with non - schema namespace . . . } >
Content : ( annotation ? , ( element | group | choice | sequence | any ) * )
< / choice >
*/
2004-04-01 21:44:12 +08:00
static int schema_choice ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr choiceType , sdlTypePtr cur_type , sdlContentModelPtr model )
2002-07-08 07:03:43 +08:00
{
2004-01-20 00:40:37 +08:00
xmlNodePtr trav ;
2004-01-22 23:58:03 +08:00
sdlContentModelPtr newModel ;
2004-02-13 19:03:58 +08:00
newModel = emalloc ( sizeof ( sdlContentModel ) ) ;
2004-01-22 23:58:03 +08:00
newModel - > kind = XSD_CONTENT_CHOICE ;
2004-02-13 19:03:58 +08:00
newModel - > u . content = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( newModel - > u . content , 0 , NULL , delete_model , 0 ) ;
2004-01-22 23:58:03 +08:00
if ( model = = NULL ) {
2004-01-23 17:15:58 +08:00
cur_type - > model = newModel ;
2004-01-22 23:58:03 +08:00
} else {
zend_hash_next_index_insert ( model - > u . content , & newModel , sizeof ( sdlContentModelPtr ) , NULL ) ;
}
2006-07-11 22:24:18 +08:00
schema_min_max ( choiceType , newModel ) ;
2002-07-08 07:03:43 +08:00
trav = choiceType - > children ;
2004-01-20 00:40:37 +08:00
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
2004-02-24 18:13:25 +08:00
/* TODO: <annotation> support */
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
2002-07-08 07:03:43 +08:00
}
2004-01-20 00:40:37 +08:00
while ( trav ! = NULL ) {
2004-01-21 22:00:55 +08:00
if ( node_is_equal ( trav , " element " ) ) {
2004-04-01 21:44:12 +08:00
schema_element ( sdl , tns , trav , cur_type , newModel ) ;
2004-01-22 23:58:03 +08:00
} else if ( node_is_equal ( trav , " group " ) ) {
2004-04-01 21:44:12 +08:00
schema_group ( sdl , tns , trav , cur_type , newModel ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " choice " ) ) {
2004-04-01 21:44:12 +08:00
schema_choice ( sdl , tns , trav , cur_type , newModel ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " sequence " ) ) {
2004-04-01 21:44:12 +08:00
schema_sequence ( sdl , tns , trav , cur_type , newModel ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " any " ) ) {
2004-04-01 21:44:12 +08:00
schema_any ( sdl , tns , trav , cur_type , newModel ) ;
2004-01-21 22:00:55 +08:00
} else {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in choice " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
trav = trav - > next ;
2002-07-08 07:03:43 +08:00
}
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 >
*/
2004-04-01 21:44:12 +08:00
static int schema_sequence ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr seqType , sdlTypePtr cur_type , sdlContentModelPtr model )
2002-07-08 07:03:43 +08:00
{
xmlNodePtr trav ;
2004-01-22 23:58:03 +08:00
sdlContentModelPtr newModel ;
2004-02-13 19:03:58 +08:00
newModel = emalloc ( sizeof ( sdlContentModel ) ) ;
2004-01-22 23:58:03 +08:00
newModel - > kind = XSD_CONTENT_SEQUENCE ;
2004-02-13 19:03:58 +08:00
newModel - > u . content = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( newModel - > u . content , 0 , NULL , delete_model , 0 ) ;
2004-01-22 23:58:03 +08:00
if ( model = = NULL ) {
2004-01-23 17:15:58 +08:00
cur_type - > model = newModel ;
2004-01-22 23:58:03 +08:00
} else {
zend_hash_next_index_insert ( model - > u . content , & newModel , sizeof ( sdlContentModelPtr ) , NULL ) ;
}
2006-07-11 22:24:18 +08:00
schema_min_max ( seqType , newModel ) ;
2002-07-08 07:03:43 +08:00
trav = seqType - > children ;
2004-01-20 00:40:37 +08:00
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
2004-02-24 18:13:25 +08:00
/* TODO: <annotation> support */
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
}
2004-01-06 00:44:01 +08:00
while ( trav ! = NULL ) {
2004-01-21 22:00:55 +08:00
if ( node_is_equal ( trav , " element " ) ) {
2004-04-01 21:44:12 +08:00
schema_element ( sdl , tns , trav , cur_type , newModel ) ;
2004-01-22 23:58:03 +08:00
} else if ( node_is_equal ( trav , " group " ) ) {
2004-04-01 21:44:12 +08:00
schema_group ( sdl , tns , trav , cur_type , newModel ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " choice " ) ) {
2004-04-01 21:44:12 +08:00
schema_choice ( sdl , tns , trav , cur_type , newModel ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " sequence " ) ) {
2004-04-01 21:44:12 +08:00
schema_sequence ( sdl , tns , trav , cur_type , newModel ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " any " ) ) {
2004-04-01 21:44:12 +08:00
schema_any ( sdl , tns , trav , cur_type , newModel ) ;
2004-01-21 22:00:55 +08:00
} else {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in sequence " , trav - > name ) ;
2002-07-08 07:03:43 +08:00
}
2004-01-06 00:44:01 +08:00
trav = trav - > next ;
2002-07-08 07:03:43 +08:00
}
return TRUE ;
}
2005-03-22 18:19:08 +08:00
/*
< any
id = ID
maxOccurs = ( nonNegativeInteger | unbounded ) : 1
minOccurs = nonNegativeInteger : 1
namespace = ( ( # # any | # # other ) | List of ( anyURI | ( # # targetNamespace | # # local ) ) ) : # # any
processContents = ( lax | skip | strict ) : strict
{ any attributes with non - schema namespace . . . } >
Content : ( annotation ? )
< / any >
*/
static int schema_any ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr anyType , sdlTypePtr cur_type , sdlContentModelPtr model )
2002-07-08 07:03:43 +08:00
{
2005-03-22 18:19:08 +08:00
if ( model ! = NULL ) {
sdlContentModelPtr newModel ;
newModel = emalloc ( sizeof ( sdlContentModel ) ) ;
newModel - > kind = XSD_CONTENT_ANY ;
2006-07-11 22:24:18 +08:00
schema_min_max ( anyType , newModel ) ;
2005-03-22 18:19:08 +08:00
zend_hash_next_index_insert ( model - > u . content , & newModel , sizeof ( sdlContentModelPtr ) , NULL ) ;
}
2002-07-08 07:03:43 +08:00
return TRUE ;
}
/*
< complexContent
id = ID
mixed = boolean
{ any attributes with non - schema namespace . . . } >
Content : ( annotation ? , ( restriction | extension ) )
< / complexContent >
*/
2004-04-01 21:44:12 +08:00
static int schema_complexContent ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr compCont , sdlTypePtr cur_type )
2002-07-08 07:03:43 +08:00
{
2004-01-20 00:40:37 +08:00
xmlNodePtr trav ;
2002-07-08 07:03:43 +08:00
2004-01-20 00:40:37 +08:00
trav = compCont - > children ;
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
/* TODO: <annotation> support */
trav = trav - > next ;
}
if ( trav ! = NULL ) {
if ( node_is_equal ( trav , " restriction " ) ) {
2004-01-23 22:43:15 +08:00
cur_type - > kind = XSD_TYPEKIND_RESTRICTION ;
2004-04-01 21:44:12 +08:00
schema_restriction_complexContent ( sdl , tns , trav , cur_type ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " extension " ) ) {
2004-01-23 22:43:15 +08:00
cur_type - > kind = XSD_TYPEKIND_EXTENSION ;
2004-04-01 21:44:12 +08:00
schema_extension_complexContent ( sdl , tns , trav , cur_type ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in complexContent " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
} else {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: <restriction> or <extension> expected in complexContent " ) ;
2004-01-20 00:40:37 +08:00
}
if ( trav ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in complexContent " , trav - > name ) ;
2004-01-07 01:14:30 +08:00
}
2002-07-08 07:03:43 +08:00
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 >
*/
2004-04-01 21:44:12 +08:00
static int schema_complexType ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr compType , sdlTypePtr cur_type )
2002-07-08 07:03:43 +08:00
{
2004-01-20 00:40:37 +08:00
xmlNodePtr trav ;
2002-07-08 07:03:43 +08:00
xmlAttrPtr attrs , name , ns ;
attrs = compType - > properties ;
ns = get_attribute ( attrs , " targetNamespace " ) ;
2004-01-10 02:22:03 +08:00
if ( ns = = NULL ) {
2004-04-01 21:44:12 +08:00
ns = tns ;
2004-01-07 01:14:30 +08:00
}
2002-07-08 07:03:43 +08:00
name = get_attribute ( attrs , " name " ) ;
2004-01-21 00:30:38 +08:00
if ( cur_type ! = NULL ) {
/* Anonymous type inside <element> */
2002-07-08 07:03:43 +08:00
sdlTypePtr newType , * ptr ;
2004-02-13 19:03:58 +08:00
newType = emalloc ( sizeof ( sdlType ) ) ;
2002-07-08 07:03:43 +08:00
memset ( newType , 0 , sizeof ( sdlType ) ) ;
2004-01-21 00:30:38 +08:00
newType - > kind = XSD_TYPEKIND_COMPLEX ;
if ( name ! = NULL ) {
2006-07-11 22:24:18 +08:00
newType - > name = estrdup ( ( char * ) name - > children - > content ) ;
newType - > namens = estrdup ( ( char * ) ns - > children - > content ) ;
2004-01-07 01:14:30 +08:00
} else {
2004-02-13 19:03:58 +08:00
newType - > name = estrdup ( cur_type - > name ) ;
newType - > namens = estrdup ( cur_type - > namens ) ;
2002-07-08 07:03:43 +08:00
}
2004-01-21 00:30:38 +08:00
zend_hash_next_index_insert ( sdl - > types , & newType , sizeof ( sdlTypePtr ) , ( void * * ) & ptr ) ;
if ( sdl - > encoders = = NULL ) {
2004-02-13 19:03:58 +08:00
sdl - > encoders = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( sdl - > encoders , 0 , NULL , delete_encoder , 0 ) ;
2004-01-09 22:16:30 +08:00
}
2004-02-13 19:03:58 +08:00
cur_type - > encode = emalloc ( sizeof ( encode ) ) ;
2004-01-21 00:30:38 +08:00
memset ( cur_type - > encode , 0 , sizeof ( encode ) ) ;
2004-02-13 19:03:58 +08:00
cur_type - > encode - > details . ns = estrdup ( newType - > namens ) ;
cur_type - > encode - > details . type_str = estrdup ( newType - > name ) ;
2004-01-21 00:30:38 +08:00
cur_type - > encode - > details . sdl_type = * ptr ;
cur_type - > encode - > to_xml = sdl_guess_convert_xml ;
cur_type - > encode - > to_zval = sdl_guess_convert_zval ;
zend_hash_next_index_insert ( sdl - > encoders , & cur_type - > encode , sizeof ( encodePtr ) , NULL ) ;
cur_type = * ptr ;
} else if ( name ) {
2004-01-20 00:40:37 +08:00
sdlTypePtr newType , * ptr ;
2002-07-08 07:03:43 +08:00
2004-02-13 19:03:58 +08:00
newType = emalloc ( sizeof ( sdlType ) ) ;
2004-01-20 00:40:37 +08:00
memset ( newType , 0 , sizeof ( sdlType ) ) ;
2004-01-21 00:30:38 +08:00
newType - > kind = XSD_TYPEKIND_COMPLEX ;
2006-07-11 22:24:18 +08:00
newType - > name = estrdup ( ( char * ) name - > children - > content ) ;
newType - > namens = estrdup ( ( char * ) ns - > children - > content ) ;
2002-07-08 07:03:43 +08:00
2004-01-20 00:40:37 +08:00
zend_hash_next_index_insert ( sdl - > types , & newType , sizeof ( sdlTypePtr ) , ( void * * ) & ptr ) ;
2004-01-21 00:30:38 +08:00
cur_type = ( * ptr ) ;
create_encoder ( sdl , cur_type , ns - > children - > content , name - > children - > content ) ;
2004-01-20 00:40:37 +08:00
} else {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: complexType has no 'name' attribute " ) ;
2004-01-21 00:30:38 +08:00
return FALSE ;
2002-07-08 07:03:43 +08:00
}
2004-01-20 00:40:37 +08:00
trav = compType - > children ;
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
/* TODO: <annotation> support */
trav = trav - > next ;
2002-07-08 07:03:43 +08:00
}
2004-01-20 00:40:37 +08:00
if ( trav ! = NULL ) {
if ( node_is_equal ( trav , " simpleContent " ) ) {
2004-04-01 21:44:12 +08:00
schema_simpleContent ( sdl , tns , trav , cur_type ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " complexContent " ) ) {
2004-04-01 21:44:12 +08:00
schema_complexContent ( sdl , tns , trav , cur_type ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else {
if ( node_is_equal ( trav , " group " ) ) {
2004-04-01 21:44:12 +08:00
schema_group ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " all " ) ) {
2004-04-01 21:44:12 +08:00
schema_all ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " choice " ) ) {
2004-04-01 21:44:12 +08:00
schema_choice ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " sequence " ) ) {
2004-04-01 21:44:12 +08:00
schema_sequence ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
}
while ( trav ! = NULL ) {
2004-01-21 22:00:55 +08:00
if ( node_is_equal ( trav , " attribute " ) ) {
2004-04-01 21:44:12 +08:00
schema_attribute ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " attributeGroup " ) ) {
2004-04-01 21:44:12 +08:00
schema_attributeGroup ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " anyAttribute " ) ) {
/* TODO: <anyAttribute> support */
trav = trav - > next ;
break ;
} else {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in complexType " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
trav = trav - > next ;
}
}
}
if ( trav ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in complexType " , trav - > name ) ;
2004-01-07 01:14:30 +08:00
}
2002-07-08 07:03:43 +08: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 >
*/
2004-04-01 21:44:12 +08:00
static int schema_element ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr element , sdlTypePtr cur_type , sdlContentModelPtr model )
2002-07-08 07:03:43 +08:00
{
2004-01-20 00:40:37 +08:00
xmlNodePtr trav ;
2004-01-22 23:58:03 +08:00
xmlAttrPtr attrs , attr , ns , name , type , ref = NULL ;
2002-07-08 07:03:43 +08:00
attrs = element - > properties ;
ns = get_attribute ( attrs , " targetNamespace " ) ;
2004-01-10 02:22:03 +08:00
if ( ns = = NULL ) {
2004-04-01 21:44:12 +08:00
ns = tns ;
2004-01-07 01:14:30 +08:00
}
2002-07-08 07:03:43 +08:00
name = get_attribute ( attrs , " name " ) ;
2004-01-21 00:30:38 +08:00
if ( name = = NULL ) {
name = ref = get_attribute ( attrs , " ref " ) ;
2004-01-07 01:14:30 +08:00
}
2004-01-10 02:22:03 +08:00
if ( name ) {
2002-07-08 07:03:43 +08:00
HashTable * addHash ;
2004-01-22 23:58:03 +08:00
sdlTypePtr newType ;
2002-08-07 11:03:09 +08:00
smart_str key = { 0 } ;
2002-07-08 07:03:43 +08:00
2004-02-13 19:03:58 +08:00
newType = emalloc ( sizeof ( sdlType ) ) ;
2002-07-08 07:03:43 +08:00
memset ( newType , 0 , sizeof ( sdlType ) ) ;
2004-01-07 01:14:30 +08:00
2004-01-21 00:30:38 +08:00
if ( ref ) {
smart_str nscat = { 0 } ;
char * type , * ns ;
xmlNsPtr nsptr ;
parse_namespace ( ref - > children - > content , & type , & ns ) ;
2006-07-11 22:24:18 +08:00
nsptr = xmlSearchNs ( element - > doc , element , BAD_CAST ( ns ) ) ;
2004-01-21 00:30:38 +08:00
if ( nsptr ! = NULL ) {
2006-07-11 22:24:18 +08:00
smart_str_appends ( & nscat , ( char * ) nsptr - > href ) ;
newType - > namens = estrdup ( ( char * ) nsptr - > href ) ;
2013-07-31 21:36:06 +08:00
} else {
xmlAttrPtr ns = get_attribute ( attrs , " targetNamespace " ) ;
if ( ns = = NULL ) {
ns = tns ;
}
if ( ns ) {
smart_str_appends ( & nscat , ( char * ) ns - > children - > content ) ;
}
2011-11-14 16:43:00 +08:00
}
smart_str_appendc ( & nscat , ' : ' ) ;
2004-01-21 00:30:38 +08:00
smart_str_appends ( & nscat , type ) ;
2004-02-13 19:03:58 +08:00
newType - > name = estrdup ( type ) ;
2004-01-21 00:30:38 +08:00
smart_str_0 ( & nscat ) ;
if ( type ) { efree ( type ) ; }
if ( ns ) { efree ( ns ) ; }
newType - > ref = estrdup ( nscat . c ) ;
smart_str_free ( & nscat ) ;
} else {
2006-07-11 22:24:18 +08:00
newType - > name = estrdup ( ( char * ) name - > children - > content ) ;
newType - > namens = estrdup ( ( char * ) ns - > children - > content ) ;
2004-01-21 00:30:38 +08:00
}
2004-01-06 00:44:01 +08:00
newType - > nillable = FALSE ;
2002-07-08 07:03:43 +08:00
2004-01-10 02:22:03 +08:00
if ( cur_type = = NULL ) {
2004-02-06 19:56:03 +08:00
if ( sdl - > elements = = NULL ) {
2004-02-13 19:03:58 +08:00
sdl - > elements = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( sdl - > elements , 0 , NULL , delete_type , 0 ) ;
2004-02-06 19:56:03 +08:00
}
2004-01-19 15:22:53 +08:00
addHash = sdl - > elements ;
2002-08-07 11:03:09 +08:00
smart_str_appends ( & key , newType - > namens ) ;
smart_str_appendc ( & key , ' : ' ) ;
smart_str_appends ( & key , newType - > name ) ;
2004-01-07 01:14:30 +08:00
} else {
2004-01-10 02:22:03 +08:00
if ( cur_type - > elements = = NULL ) {
2004-02-13 19:03:58 +08:00
cur_type - > elements = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( cur_type - > elements , 0 , NULL , delete_type , 0 ) ;
2002-07-08 07:03:43 +08:00
}
addHash = cur_type - > elements ;
2002-08-07 11:03:09 +08:00
smart_str_appends ( & key , newType - > name ) ;
2002-07-08 07:03:43 +08:00
}
2002-08-07 11:03:09 +08:00
smart_str_0 ( & key ) ;
2004-01-22 23:58:03 +08:00
if ( zend_hash_add ( addHash , key . c , key . len + 1 , & newType , sizeof ( sdlTypePtr ) , NULL ) ! = SUCCESS ) {
2004-01-27 20:07:57 +08:00
if ( cur_type = = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: element '%s' already defined " , key . c ) ;
2004-01-27 20:07:57 +08:00
} else {
zend_hash_next_index_insert ( addHash , & newType , sizeof ( sdlTypePtr ) , NULL ) ;
}
2004-01-22 23:58:03 +08:00
}
2002-08-07 11:03:09 +08:00
smart_str_free ( & key ) ;
2004-01-22 23:58:03 +08:00
if ( model ! = NULL ) {
2004-02-13 19:03:58 +08:00
sdlContentModelPtr newModel = emalloc ( sizeof ( sdlContentModel ) ) ;
2004-01-22 23:58:03 +08:00
newModel - > kind = XSD_CONTENT_ELEMENT ;
newModel - > u . element = newType ;
2002-07-08 07:03:43 +08:00
2006-07-11 22:24:18 +08:00
schema_min_max ( element , newModel ) ;
2004-01-22 23:58:03 +08:00
zend_hash_next_index_insert ( model - > u . content , & newModel , sizeof ( sdlContentModelPtr ) , NULL ) ;
}
cur_type = newType ;
} else {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: element has no 'name' nor 'ref' attributes " ) ;
2004-01-07 01:14:30 +08:00
}
2002-08-07 11:03:09 +08:00
2003-01-15 04:24:40 +08:00
/* nillable = boolean : false */
2002-07-08 07:03:43 +08:00
attrs = element - > properties ;
2004-01-22 23:58:03 +08:00
attr = get_attribute ( attrs , " nillable " ) ;
if ( attr ) {
2004-01-26 17:51:07 +08:00
if ( ref ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: element has both 'ref' and 'nillable' attributes " ) ;
2004-01-26 17:51:07 +08:00
}
2006-07-11 22:24:18 +08:00
if ( ! stricmp ( ( char * ) attr - > children - > content , " true " ) | |
! stricmp ( ( char * ) attr - > children - > content , " 1 " ) ) {
2004-01-06 00:44:01 +08:00
cur_type - > nillable = TRUE ;
2004-01-07 01:14:30 +08:00
} else {
2004-01-06 00:44:01 +08:00
cur_type - > nillable = FALSE ;
2004-01-07 01:14:30 +08:00
}
} else {
2004-01-06 00:44:01 +08:00
cur_type - > nillable = FALSE ;
2004-01-07 01:14:30 +08:00
}
2002-07-08 07:03:43 +08:00
2004-01-26 17:51:07 +08:00
attr = get_attribute ( attrs , " fixed " ) ;
if ( attr ) {
if ( ref ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: element has both 'ref' and 'fixed' attributes " ) ;
2004-01-26 17:51:07 +08:00
}
2006-07-11 22:24:18 +08:00
cur_type - > fixed = estrdup ( ( char * ) attr - > children - > content ) ;
2004-01-26 17:51:07 +08:00
}
attr = get_attribute ( attrs , " default " ) ;
if ( attr ) {
if ( ref ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: element has both 'ref' and 'fixed' attributes " ) ;
2004-01-26 17:51:07 +08:00
} else if ( ref ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: element has both 'default' and 'fixed' attributes " ) ;
2004-01-26 17:51:07 +08:00
}
2006-07-11 22:24:18 +08:00
cur_type - > def = estrdup ( ( char * ) attr - > children - > content ) ;
2004-01-26 17:51:07 +08:00
}
2005-04-20 16:30:43 +08:00
/* form */
attr = get_attribute ( attrs , " form " ) ;
if ( attr ) {
2006-07-11 22:24:18 +08:00
if ( strncmp ( ( char * ) attr - > children - > content , " qualified " , sizeof ( " qualified " ) ) = = 0 ) {
2005-04-20 16:30:43 +08:00
cur_type - > form = XSD_FORM_QUALIFIED ;
2006-07-11 22:24:18 +08:00
} else if ( strncmp ( ( char * ) attr - > children - > content , " unqualified " , sizeof ( " unqualified " ) ) = = 0 ) {
2005-04-20 16:30:43 +08:00
cur_type - > form = XSD_FORM_UNQUALIFIED ;
} else {
cur_type - > form = XSD_FORM_DEFAULT ;
}
} else {
cur_type - > form = XSD_FORM_DEFAULT ;
}
if ( cur_type - > form = = XSD_FORM_DEFAULT ) {
xmlNodePtr parent = element - > parent ;
while ( parent ) {
if ( node_is_equal_ex ( parent , " schema " , SCHEMA_NAMESPACE ) ) {
xmlAttrPtr def ;
def = get_attribute ( parent - > properties , " elementFormDefault " ) ;
2006-07-11 22:24:18 +08:00
if ( def = = NULL | | strncmp ( ( char * ) def - > children - > content , " qualified " , sizeof ( " qualified " ) ) ) {
2005-04-20 16:30:43 +08:00
cur_type - > form = XSD_FORM_UNQUALIFIED ;
} else {
cur_type - > form = XSD_FORM_QUALIFIED ;
}
break ;
}
parent = parent - > parent ;
}
if ( parent = = NULL ) {
cur_type - > form = XSD_FORM_UNQUALIFIED ;
}
}
2003-01-15 04:24:40 +08:00
/* type = QName */
2004-01-20 00:40:37 +08:00
type = get_attribute ( attrs , " type " ) ;
if ( type ) {
2002-07-08 07:03:43 +08:00
char * cptype , * str_ns ;
xmlNsPtr nsptr ;
2004-01-21 00:30:38 +08:00
if ( ref ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: element has both 'ref' and 'type' attributes " ) ;
2004-01-21 00:30:38 +08:00
}
2004-01-20 00:40:37 +08:00
parse_namespace ( type - > children - > content , & cptype , & str_ns ) ;
2006-07-11 22:24:18 +08:00
nsptr = xmlSearchNs ( element - > doc , element , BAD_CAST ( str_ns ) ) ;
2004-01-19 15:22:53 +08:00
if ( nsptr ! = NULL ) {
2006-07-11 22:24:18 +08:00
cur_type - > encode = get_create_encoder ( sdl , cur_type , nsptr - > href , BAD_CAST ( cptype ) ) ;
2004-01-10 02:22:03 +08:00
}
if ( str_ns ) { efree ( str_ns ) ; }
if ( cptype ) { efree ( cptype ) ; }
2002-07-08 07:03:43 +08:00
}
2004-01-20 00:40:37 +08:00
trav = element - > children ;
2004-01-21 22:00:55 +08:00
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
/* TODO: <annotation> support */
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
2004-01-07 01:14:30 +08:00
}
2004-01-20 00:40:37 +08:00
if ( trav ! = NULL ) {
if ( node_is_equal ( trav , " simpleType " ) ) {
2004-01-21 00:30:38 +08:00
if ( ref ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: element has both 'ref' attribute and subtype " ) ;
2004-01-21 00:30:38 +08:00
} else if ( type ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: element has both 'type' attribute and subtype " ) ;
2004-01-21 00:30:38 +08:00
}
2004-04-01 21:44:12 +08:00
schema_simpleType ( sdl , tns , trav , cur_type ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
} else if ( node_is_equal ( trav , " complexType " ) ) {
2004-01-21 00:30:38 +08:00
if ( ref ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: element has both 'ref' attribute and subtype " ) ;
2004-01-21 00:30:38 +08:00
} else if ( type ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: element has both 'type' attribute and subtype " ) ;
2004-01-21 00:30:38 +08:00
}
2004-04-01 21:44:12 +08:00
schema_complexType ( sdl , tns , trav , cur_type ) ;
2004-01-20 00:40:37 +08:00
trav = trav - > next ;
}
2004-01-07 01:14:30 +08:00
}
2004-01-20 00:40:37 +08:00
while ( trav ! = NULL ) {
2004-01-21 22:00:55 +08:00
if ( node_is_equal ( trav , " unique " ) ) {
/* TODO: <unique> support */
} else if ( node_is_equal ( trav , " key " ) ) {
/* TODO: <key> support */
2004-04-02 14:23:51 +08:00
} else if ( node_is_equal ( trav , " keyref " ) ) {
2004-01-21 22:00:55 +08:00
/* TODO: <keyref> support */
} else {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in element " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
trav = trav - > next ;
}
return TRUE ;
2002-07-08 07:03:43 +08:00
}
/*
< 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 >
*/
2004-04-01 21:44:12 +08:00
static int schema_attribute ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr attrType , sdlTypePtr cur_type , sdlCtx * ctx )
2002-07-08 07:03:43 +08:00
{
sdlAttributePtr newAttr ;
2004-01-21 22:00:55 +08:00
xmlAttrPtr attr , name , ref = NULL , type = NULL ;
xmlNodePtr trav ;
name = get_attribute ( attrType - > properties , " name " ) ;
if ( name = = NULL ) {
name = ref = get_attribute ( attrType - > properties , " ref " ) ;
}
if ( name ) {
HashTable * addHash ;
smart_str key = { 0 } ;
2002-07-08 07:03:43 +08:00
2004-02-13 19:03:58 +08:00
newAttr = emalloc ( sizeof ( sdlAttribute ) ) ;
2004-01-21 22:00:55 +08:00
memset ( newAttr , 0 , sizeof ( sdlAttribute ) ) ;
2002-07-08 07:03:43 +08:00
2004-01-21 22:00:55 +08:00
if ( ref ) {
char * attr_name , * ns ;
xmlNsPtr nsptr ;
parse_namespace ( ref - > children - > content , & attr_name , & ns ) ;
2006-07-11 22:24:18 +08:00
nsptr = xmlSearchNs ( attrType - > doc , attrType , BAD_CAST ( ns ) ) ;
2004-01-21 22:00:55 +08:00
if ( nsptr ! = NULL ) {
2006-07-11 22:24:18 +08:00
smart_str_appends ( & key , ( char * ) nsptr - > href ) ;
newAttr - > namens = estrdup ( ( char * ) nsptr - > href ) ;
2013-07-31 21:36:06 +08:00
} else {
xmlAttrPtr ns = get_attribute ( attrType - > properties , " targetNamespace " ) ;
if ( ns = = NULL ) {
ns = tns ;
}
if ( ns ) {
smart_str_appends ( & key , ( char * ) ns - > children - > content ) ;
}
2004-01-21 22:00:55 +08:00
}
2011-11-14 16:43:00 +08:00
smart_str_appendc ( & key , ' : ' ) ;
2004-01-21 22:00:55 +08:00
smart_str_appends ( & key , attr_name ) ;
smart_str_0 ( & key ) ;
newAttr - > ref = estrdup ( key . c ) ;
if ( attr_name ) { efree ( attr_name ) ; }
if ( ns ) { efree ( ns ) ; }
} else {
xmlAttrPtr ns ;
ns = get_attribute ( attrType - > properties , " targetNamespace " ) ;
if ( ns = = NULL ) {
2004-04-01 21:44:12 +08:00
ns = tns ;
2004-01-21 22:00:55 +08:00
}
if ( ns ! = NULL ) {
2006-07-11 22:24:18 +08:00
smart_str_appends ( & key , ( char * ) ns - > children - > content ) ;
2004-01-21 22:00:55 +08:00
smart_str_appendc ( & key , ' : ' ) ;
2006-07-11 22:24:18 +08:00
newAttr - > namens = estrdup ( ( char * ) ns - > children - > content ) ;
2004-01-21 22:00:55 +08:00
}
2006-07-11 22:24:18 +08:00
smart_str_appends ( & key , ( char * ) name - > children - > content ) ;
2004-01-21 22:00:55 +08:00
smart_str_0 ( & key ) ;
}
if ( cur_type = = NULL ) {
2004-02-06 19:56:03 +08:00
addHash = ctx - > attributes ;
2004-01-21 22:00:55 +08:00
} else {
if ( cur_type - > attributes = = NULL ) {
2004-02-13 19:03:58 +08:00
cur_type - > attributes = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( cur_type - > attributes , 0 , NULL , delete_attribute , 0 ) ;
2004-01-21 22:00:55 +08:00
}
addHash = cur_type - > attributes ;
}
2004-01-22 23:58:03 +08:00
if ( zend_hash_add ( addHash , key . c , key . len + 1 , & newAttr , sizeof ( sdlAttributePtr ) , NULL ) ! = SUCCESS ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: attribute '%s' already defined " , key . c ) ;
2004-01-22 23:58:03 +08:00
}
2004-01-21 22:00:55 +08:00
smart_str_free ( & key ) ;
} else {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: attribute has no 'name' nor 'ref' attributes " ) ;
2002-07-08 07:03:43 +08:00
}
2004-01-22 23:58:03 +08:00
/* type = QName */
type = get_attribute ( attrType - > properties , " type " ) ;
if ( type ) {
char * cptype , * str_ns ;
xmlNsPtr nsptr ;
if ( ref ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: attribute has both 'ref' and 'type' attributes " ) ;
2004-01-22 23:58:03 +08:00
}
parse_namespace ( type - > children - > content , & cptype , & str_ns ) ;
2006-07-11 22:24:18 +08:00
nsptr = xmlSearchNs ( attrType - > doc , attrType , BAD_CAST ( str_ns ) ) ;
2004-01-22 23:58:03 +08:00
if ( nsptr ! = NULL ) {
2006-07-11 22:24:18 +08:00
newAttr - > encode = get_create_encoder ( sdl , cur_type , nsptr - > href , BAD_CAST ( cptype ) ) ;
2004-01-22 23:58:03 +08:00
}
if ( str_ns ) { efree ( str_ns ) ; }
if ( cptype ) { efree ( cptype ) ; }
}
2004-01-21 22:00:55 +08:00
attr = attrType - > properties ;
while ( attr ! = NULL ) {
if ( attr_is_equal_ex ( attr , " default " , SCHEMA_NAMESPACE ) ) {
2006-07-11 22:24:18 +08:00
newAttr - > def = estrdup ( ( char * ) attr - > children - > content ) ;
2004-01-21 22:00:55 +08:00
} else if ( attr_is_equal_ex ( attr , " fixed " , SCHEMA_NAMESPACE ) ) {
2006-07-11 22:24:18 +08:00
newAttr - > fixed = estrdup ( ( char * ) attr - > children - > content ) ;
2004-01-21 22:00:55 +08:00
} else if ( attr_is_equal_ex ( attr , " form " , SCHEMA_NAMESPACE ) ) {
2006-07-11 22:24:18 +08:00
if ( strncmp ( ( char * ) attr - > children - > content , " qualified " , sizeof ( " qualified " ) ) = = 0 ) {
2004-01-26 17:51:07 +08:00
newAttr - > form = XSD_FORM_QUALIFIED ;
2006-07-11 22:24:18 +08:00
} else if ( strncmp ( ( char * ) attr - > children - > content , " unqualified " , sizeof ( " unqualified " ) ) = = 0 ) {
2004-01-26 17:51:07 +08:00
newAttr - > form = XSD_FORM_UNQUALIFIED ;
} else {
newAttr - > form = XSD_FORM_DEFAULT ;
}
2004-01-21 22:00:55 +08:00
} else if ( attr_is_equal_ex ( attr , " id " , SCHEMA_NAMESPACE ) ) {
2004-01-26 17:51:07 +08:00
/* skip */
2004-01-21 22:00:55 +08:00
} else if ( attr_is_equal_ex ( attr , " name " , SCHEMA_NAMESPACE ) ) {
2006-07-11 22:24:18 +08:00
newAttr - > name = estrdup ( ( char * ) attr - > children - > content ) ;
2004-01-21 22:00:55 +08:00
} else if ( attr_is_equal_ex ( attr , " ref " , SCHEMA_NAMESPACE ) ) {
2004-01-22 23:58:03 +08:00
/* already processed */
2004-01-21 22:00:55 +08:00
} else if ( attr_is_equal_ex ( attr , " type " , SCHEMA_NAMESPACE ) ) {
2004-01-22 23:58:03 +08:00
/* already processed */
2004-01-21 22:00:55 +08:00
} else if ( attr_is_equal_ex ( attr , " use " , SCHEMA_NAMESPACE ) ) {
2006-07-11 22:24:18 +08:00
if ( strncmp ( ( char * ) attr - > children - > content , " prohibited " , sizeof ( " prohibited " ) ) = = 0 ) {
2004-01-26 17:51:07 +08:00
newAttr - > use = XSD_USE_PROHIBITED ;
2006-07-11 22:24:18 +08:00
} else if ( strncmp ( ( char * ) attr - > children - > content , " required " , sizeof ( " required " ) ) = = 0 ) {
2004-01-26 17:51:07 +08:00
newAttr - > use = XSD_USE_REQUIRED ;
2006-07-11 22:24:18 +08:00
} else if ( strncmp ( ( char * ) attr - > children - > content , " optional " , sizeof ( " optional " ) ) = = 0 ) {
2004-01-26 17:51:07 +08:00
newAttr - > use = XSD_USE_OPTIONAL ;
} else {
newAttr - > use = XSD_USE_DEFAULT ;
}
2004-01-07 01:14:30 +08:00
} else {
2004-01-21 22:00:55 +08:00
xmlNsPtr nsPtr = attr_find_ns ( attr ) ;
2002-07-08 07:03:43 +08:00
2006-07-11 22:24:18 +08:00
if ( strncmp ( ( char * ) nsPtr - > href , SCHEMA_NAMESPACE , sizeof ( SCHEMA_NAMESPACE ) ) ) {
2002-07-08 07:03:43 +08:00
smart_str key2 = { 0 } ;
2004-02-06 19:56:03 +08:00
sdlExtraAttributePtr ext ;
xmlNsPtr nsptr ;
char * value , * ns ;
2004-02-13 19:03:58 +08:00
ext = emalloc ( sizeof ( sdlExtraAttribute ) ) ;
2004-02-06 19:56:03 +08:00
memset ( ext , 0 , sizeof ( sdlExtraAttribute ) ) ;
parse_namespace ( attr - > children - > content , & value , & ns ) ;
2006-07-11 22:24:18 +08:00
nsptr = xmlSearchNs ( attr - > doc , attr - > parent , BAD_CAST ( ns ) ) ;
2004-02-06 19:56:03 +08:00
if ( nsptr ) {
2006-07-11 22:24:18 +08:00
ext - > ns = estrdup ( ( char * ) nsptr - > href ) ;
2004-02-13 19:03:58 +08:00
ext - > val = estrdup ( value ) ;
2004-02-06 19:56:03 +08:00
} else {
2006-07-11 22:24:18 +08:00
ext - > val = estrdup ( ( char * ) attr - > children - > content ) ;
2004-02-06 19:56:03 +08:00
}
if ( ns ) { efree ( ns ) ; }
efree ( value ) ;
2002-07-08 07:03:43 +08:00
2004-01-10 02:22:03 +08:00
if ( ! newAttr - > extraAttributes ) {
2004-02-13 19:03:58 +08:00
newAttr - > extraAttributes = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( newAttr - > extraAttributes , 0 , NULL , delete_extra_attribute , 0 ) ;
2002-07-08 07:03:43 +08:00
}
2006-07-11 22:24:18 +08:00
smart_str_appends ( & key2 , ( char * ) nsPtr - > href ) ;
2002-07-08 07:03:43 +08:00
smart_str_appendc ( & key2 , ' : ' ) ;
2006-07-11 22:24:18 +08:00
smart_str_appends ( & key2 , ( char * ) attr - > name ) ;
2002-07-08 07:03:43 +08:00
smart_str_0 ( & key2 ) ;
2004-02-06 19:56:03 +08:00
zend_hash_add ( newAttr - > extraAttributes , key2 . c , key2 . len + 1 , & ext , sizeof ( sdlExtraAttributePtr ) , NULL ) ;
2002-07-08 07:03:43 +08:00
smart_str_free ( & key2 ) ;
}
}
2004-01-21 22:00:55 +08:00
attr = attr - > next ;
2002-07-08 07:03:43 +08:00
}
2005-04-20 16:30:43 +08:00
if ( newAttr - > form = = XSD_FORM_DEFAULT ) {
xmlNodePtr parent = attrType - > parent ;
while ( parent ) {
if ( node_is_equal_ex ( parent , " schema " , SCHEMA_NAMESPACE ) ) {
2005-04-03 23:39:56 +08:00
xmlAttrPtr def ;
def = get_attribute ( parent - > properties , " attributeFormDefault " ) ;
2006-07-11 22:24:18 +08:00
if ( def = = NULL | | strncmp ( ( char * ) def - > children - > content , " qualified " , sizeof ( " qualified " ) ) ) {
2005-04-03 23:39:56 +08:00
newAttr - > form = XSD_FORM_UNQUALIFIED ;
} else {
newAttr - > form = XSD_FORM_QUALIFIED ;
}
break ;
}
parent = parent - > parent ;
2005-04-20 16:30:43 +08:00
}
if ( parent = = NULL ) {
2005-04-03 23:39:56 +08:00
newAttr - > form = XSD_FORM_UNQUALIFIED ;
}
}
2004-01-21 22:00:55 +08:00
trav = attrType - > children ;
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
/* TODO: <annotation> support */
trav = trav - > next ;
}
if ( trav ! = NULL ) {
if ( node_is_equal ( trav , " simpleType " ) ) {
2004-01-22 23:58:03 +08:00
sdlTypePtr dummy_type ;
2004-01-21 22:00:55 +08:00
if ( ref ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: attribute has both 'ref' attribute and subtype " ) ;
2004-01-21 22:00:55 +08:00
} else if ( type ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: attribute has both 'type' attribute and subtype " ) ;
2004-01-21 22:00:55 +08:00
}
2004-02-13 19:03:58 +08:00
dummy_type = emalloc ( sizeof ( sdlType ) ) ;
2004-01-22 23:58:03 +08:00
memset ( dummy_type , 0 , sizeof ( sdlType ) ) ;
2007-08-31 18:48:45 +08:00
{
smart_str anonymous = { 0 } ;
smart_str_appendl ( & anonymous , " anonymous " , sizeof ( " anonymous " ) - 1 ) ;
smart_str_append_long ( & anonymous , zend_hash_num_elements ( sdl - > types ) ) ;
smart_str_0 ( & anonymous ) ;
dummy_type - > name = anonymous . c ;
}
2006-07-11 22:24:18 +08:00
dummy_type - > namens = estrdup ( ( char * ) tns - > children - > content ) ;
2004-04-01 21:44:12 +08:00
schema_simpleType ( sdl , tns , trav , dummy_type ) ;
2004-01-22 23:58:03 +08:00
newAttr - > encode = dummy_type - > encode ;
delete_type ( & dummy_type ) ;
2004-01-21 22:00:55 +08:00
trav = trav - > next ;
}
}
if ( trav ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in attribute " , trav - > name ) ;
2004-01-21 22:00:55 +08:00
}
return TRUE ;
}
2002-07-08 07:03:43 +08:00
2004-04-01 21:44:12 +08:00
static int schema_attributeGroup ( sdlPtr sdl , xmlAttrPtr tns , xmlNodePtr attrGroup , sdlTypePtr cur_type , sdlCtx * ctx )
2004-01-21 22:00:55 +08:00
{
xmlNodePtr trav ;
xmlAttrPtr name , ref = NULL ;
2002-07-08 07:03:43 +08:00
2004-01-22 00:04:37 +08:00
2004-01-21 22:00:55 +08:00
name = get_attribute ( attrGroup - > properties , " name " ) ;
if ( name = = NULL ) {
name = ref = get_attribute ( attrGroup - > properties , " ref " ) ;
}
if ( name ) {
if ( cur_type = = NULL ) {
xmlAttrPtr ns ;
sdlTypePtr newType ;
smart_str key = { 0 } ;
2002-07-08 07:03:43 +08:00
2004-01-21 22:00:55 +08:00
ns = get_attribute ( attrGroup - > properties , " targetNamespace " ) ;
if ( ns = = NULL ) {
2004-04-01 21:44:12 +08:00
ns = tns ;
2004-01-19 15:22:53 +08:00
}
2004-02-13 19:03:58 +08:00
newType = emalloc ( sizeof ( sdlType ) ) ;
2004-01-21 22:00:55 +08:00
memset ( newType , 0 , sizeof ( sdlType ) ) ;
2006-07-11 22:24:18 +08:00
newType - > name = estrdup ( ( char * ) name - > children - > content ) ;
newType - > namens = estrdup ( ( char * ) ns - > children - > content ) ;
2002-07-08 07:03:43 +08:00
2004-01-21 22:00:55 +08:00
smart_str_appends ( & key , newType - > namens ) ;
smart_str_appendc ( & key , ' : ' ) ;
smart_str_appends ( & key , newType - > name ) ;
2002-07-08 07:03:43 +08:00
smart_str_0 ( & key ) ;
2004-01-21 22:00:55 +08:00
2004-02-06 19:56:03 +08:00
if ( zend_hash_add ( ctx - > attributeGroups , key . c , key . len + 1 , & newType , sizeof ( sdlTypePtr ) , NULL ) ! = SUCCESS ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: attributeGroup '%s' already defined " , key . c ) ;
2004-01-22 23:58:03 +08:00
}
2004-01-21 22:00:55 +08:00
cur_type = newType ;
2002-07-08 07:03:43 +08:00
smart_str_free ( & key ) ;
2004-01-21 22:00:55 +08:00
} else if ( ref ) {
sdlAttributePtr newAttr ;
char * group_name , * ns ;
smart_str key = { 0 } ;
xmlNsPtr nsptr ;
2002-07-08 07:03:43 +08:00
2004-01-21 22:00:55 +08:00
if ( cur_type - > attributes = = NULL ) {
2004-02-13 19:03:58 +08:00
cur_type - > attributes = emalloc ( sizeof ( HashTable ) ) ;
zend_hash_init ( cur_type - > attributes , 0 , NULL , delete_attribute , 0 ) ;
2004-01-21 22:00:55 +08:00
}
2004-02-13 19:03:58 +08:00
newAttr = emalloc ( sizeof ( sdlAttribute ) ) ;
2004-01-21 22:00:55 +08:00
memset ( newAttr , 0 , sizeof ( sdlAttribute ) ) ;
2004-01-20 00:40:37 +08:00
2004-01-21 22:00:55 +08:00
parse_namespace ( ref - > children - > content , & group_name , & ns ) ;
2006-07-11 22:24:18 +08:00
nsptr = xmlSearchNs ( attrGroup - > doc , attrGroup , BAD_CAST ( ns ) ) ;
2004-01-21 22:00:55 +08:00
if ( nsptr ! = NULL ) {
2006-07-11 22:24:18 +08:00
smart_str_appends ( & key , ( char * ) nsptr - > href ) ;
2004-01-21 22:00:55 +08:00
}
2011-11-14 16:43:00 +08:00
smart_str_appendc ( & key , ' : ' ) ;
2004-01-21 22:00:55 +08:00
smart_str_appends ( & key , group_name ) ;
smart_str_0 ( & key ) ;
newAttr - > ref = estrdup ( key . c ) ;
if ( group_name ) { efree ( group_name ) ; }
if ( ns ) { efree ( ns ) ; }
smart_str_free ( & key ) ;
2004-01-20 00:40:37 +08:00
2004-01-21 22:00:55 +08:00
zend_hash_next_index_insert ( cur_type - > attributes , & newAttr , sizeof ( sdlAttributePtr ) , NULL ) ;
cur_type = NULL ;
}
} else {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: attributeGroup has no 'name' nor 'ref' attributes " ) ;
2004-01-20 00:40:37 +08:00
}
2004-01-21 22:00:55 +08:00
2004-01-20 00:40:37 +08:00
trav = attrGroup - > children ;
2004-04-02 14:23:51 +08:00
if ( trav ! = NULL & & node_is_equal ( trav , " annotation " ) ) {
/* TODO: <annotation> support */
trav = trav - > next ;
}
2004-01-20 00:40:37 +08:00
while ( trav ! = NULL ) {
2004-01-21 22:00:55 +08:00
if ( node_is_equal ( trav , " attribute " ) ) {
if ( ref ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: attributeGroup has both 'ref' attribute and subattribute " ) ;
2004-01-21 22:00:55 +08:00
}
2004-04-01 21:44:12 +08:00
schema_attribute ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " attributeGroup " ) ) {
if ( ref ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: attributeGroup has both 'ref' attribute and subattribute " ) ;
2004-01-20 00:40:37 +08:00
}
2004-04-01 21:44:12 +08:00
schema_attributeGroup ( sdl , tns , trav , cur_type , NULL ) ;
2004-01-21 22:00:55 +08:00
} else if ( node_is_equal ( trav , " anyAttribute " ) ) {
if ( ref ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error0 ( E_ERROR , " Parsing Schema: attributeGroup has both 'ref' attribute and subattribute " ) ;
2004-01-21 22:00:55 +08:00
}
/* TODO: <anyAttribute> support */
trav = trav - > next ;
break ;
} else {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in attributeGroup " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
trav = trav - > next ;
}
if ( trav ! = NULL ) {
2004-05-05 18:31:26 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unexpected <%s> in attributeGroup " , trav - > name ) ;
2004-01-20 00:40:37 +08:00
}
return TRUE ;
}
2004-02-07 00:52:14 +08:00
static void copy_extra_attribute ( void * attribute )
2004-02-06 19:56:03 +08:00
{
sdlExtraAttributePtr * attr = ( sdlExtraAttributePtr * ) attribute ;
sdlExtraAttributePtr new_attr ;
2004-02-13 19:03:58 +08:00
new_attr = emalloc ( sizeof ( sdlExtraAttribute ) ) ;
2004-02-06 19:56:03 +08:00
memcpy ( new_attr , * attr , sizeof ( sdlExtraAttribute ) ) ;
* attr = new_attr ;
if ( new_attr - > ns ) {
2004-02-13 19:03:58 +08:00
new_attr - > ns = estrdup ( new_attr - > ns ) ;
2004-02-06 19:56:03 +08:00
}
if ( new_attr - > val ) {
2004-02-13 19:03:58 +08:00
new_attr - > val = estrdup ( new_attr - > val ) ;
2004-02-06 19:56:03 +08:00
}
}
2013-07-31 21:36:06 +08:00
static void * schema_find_by_ref ( HashTable * ht , char * ref )
{
void * * tmp ;
if ( zend_hash_find ( ht , ref , strlen ( ref ) + 1 , ( void * * ) & tmp ) = = SUCCESS ) {
return tmp ;
} else {
ref = strrchr ( ref , ' : ' ) ;
if ( ref ) {
if ( zend_hash_find ( ht , ref , strlen ( ref ) + 1 , ( void * * ) & tmp ) = = SUCCESS ) {
return tmp ;
}
}
}
return NULL ;
}
2004-02-06 19:56:03 +08:00
static void schema_attribute_fixup ( sdlCtx * ctx , sdlAttributePtr attr )
2004-01-20 00:40:37 +08:00
{
2004-01-21 22:00:55 +08:00
sdlAttributePtr * tmp ;
if ( attr - > ref ! = NULL ) {
2004-02-06 19:56:03 +08:00
if ( ctx - > attributes ! = NULL ) {
2013-07-31 21:36:06 +08:00
tmp = ( sdlAttributePtr * ) schema_find_by_ref ( ctx - > attributes , attr - > ref ) ;
if ( tmp ) {
2004-02-06 19:56:03 +08:00
schema_attribute_fixup ( ctx , * tmp ) ;
2004-01-21 22:00:55 +08:00
if ( ( * tmp ) - > name ! = NULL & & attr - > name = = NULL ) {
2004-02-13 19:03:58 +08:00
attr - > name = estrdup ( ( * tmp ) - > name ) ;
2004-01-21 22:00:55 +08:00
}
2004-08-27 02:40:10 +08:00
if ( ( * tmp ) - > namens ! = NULL & & attr - > namens = = NULL ) {
attr - > namens = estrdup ( ( * tmp ) - > namens ) ;
}
2004-01-21 22:00:55 +08:00
if ( ( * tmp ) - > def ! = NULL & & attr - > def = = NULL ) {
2004-02-13 19:03:58 +08:00
attr - > def = estrdup ( ( * tmp ) - > def ) ;
2004-01-21 22:00:55 +08:00
}
if ( ( * tmp ) - > fixed ! = NULL & & attr - > fixed = = NULL ) {
2004-02-13 19:03:58 +08:00
attr - > fixed = estrdup ( ( * tmp ) - > fixed ) ;
2004-01-21 22:00:55 +08:00
}
2004-01-26 17:51:07 +08:00
if ( attr - > form = = XSD_FORM_DEFAULT ) {
attr - > form = ( * tmp ) - > form ;
2004-01-21 22:00:55 +08:00
}
2004-01-26 17:51:07 +08:00
if ( attr - > use = = XSD_USE_DEFAULT ) {
attr - > use = ( * tmp ) - > use ;
2004-01-21 22:00:55 +08:00
}
if ( ( * tmp ) - > extraAttributes ! = NULL ) {
xmlNodePtr node ;
2004-01-22 00:04:37 +08:00
2004-02-13 19:03:58 +08:00
attr - > extraAttributes = emalloc ( sizeof ( HashTable ) ) ;
2006-10-04 03:51:01 +08:00
zend_hash_init ( attr - > extraAttributes , zend_hash_num_elements ( ( * tmp ) - > extraAttributes ) , NULL , delete_extra_attribute , 0 ) ;
2004-02-06 19:56:03 +08:00
zend_hash_copy ( attr - > extraAttributes , ( * tmp ) - > extraAttributes , copy_extra_attribute , & node , sizeof ( xmlNodePtr ) ) ;
2004-01-21 22:00:55 +08:00
}
2004-01-22 23:58:03 +08:00
attr - > encode = ( * tmp ) - > encode ;
2004-01-21 22:00:55 +08:00
}
2004-02-05 17:28:09 +08:00
}
2004-02-03 01:39:10 +08:00
if ( attr - > name = = NULL & & attr - > ref ! = NULL ) {
2004-02-07 00:52:14 +08:00
char * name = strrchr ( attr - > ref , ' : ' ) ;
2006-03-16 00:13:18 +08:00
if ( name ) {
2004-02-13 19:03:58 +08:00
attr - > name = estrdup ( name + 1 ) ;
2004-02-07 00:52:14 +08:00
} else {
2004-02-13 19:03:58 +08:00
attr - > name = estrdup ( attr - > ref ) ;
2004-02-07 00:52:14 +08:00
}
2004-01-21 22:00:55 +08:00
}
efree ( attr - > ref ) ;
attr - > ref = NULL ;
}
}
2004-02-06 19:56:03 +08:00
static void schema_attributegroup_fixup ( sdlCtx * ctx , sdlAttributePtr attr , HashTable * ht )
2004-01-21 22:00:55 +08:00
{
sdlTypePtr * tmp ;
sdlAttributePtr * tmp_attr ;
if ( attr - > ref ! = NULL ) {
2004-02-06 19:56:03 +08:00
if ( ctx - > attributeGroups ! = NULL ) {
2013-07-31 21:36:06 +08:00
tmp = ( sdlTypePtr * ) schema_find_by_ref ( ctx - > attributeGroups , attr - > ref ) ;
if ( tmp ) {
2004-01-21 22:00:55 +08:00
if ( ( * tmp ) - > attributes ) {
zend_hash_internal_pointer_reset ( ( * tmp ) - > attributes ) ;
while ( zend_hash_get_current_data ( ( * tmp ) - > attributes , ( void * * ) & tmp_attr ) = = SUCCESS ) {
if ( zend_hash_get_current_key_type ( ( * tmp ) - > attributes ) = = HASH_KEY_IS_STRING ) {
char * key ;
uint key_len ;
sdlAttributePtr newAttr ;
2004-02-06 19:56:03 +08:00
schema_attribute_fixup ( ctx , * tmp_attr ) ;
2004-01-21 22:00:55 +08:00
2004-02-13 19:03:58 +08:00
newAttr = emalloc ( sizeof ( sdlAttribute ) ) ;
2004-01-21 22:00:55 +08:00
memcpy ( newAttr , * tmp_attr , sizeof ( sdlAttribute ) ) ;
2004-02-13 19:03:58 +08:00
if ( newAttr - > def ) { newAttr - > def = estrdup ( newAttr - > def ) ; }
if ( newAttr - > fixed ) { newAttr - > fixed = estrdup ( newAttr - > fixed ) ; }
2004-08-27 02:40:10 +08:00
if ( newAttr - > namens ) { newAttr - > namens = estrdup ( newAttr - > namens ) ; }
2004-02-13 19:03:58 +08:00
if ( newAttr - > name ) { newAttr - > name = estrdup ( newAttr - > name ) ; }
2004-01-21 22:00:55 +08:00
if ( newAttr - > extraAttributes ) {
xmlNodePtr node ;
2004-02-13 19:03:58 +08:00
HashTable * ht = emalloc ( sizeof ( HashTable ) ) ;
2006-10-04 03:51:01 +08:00
zend_hash_init ( ht , zend_hash_num_elements ( newAttr - > extraAttributes ) , NULL , delete_extra_attribute , 0 ) ;
2004-02-06 19:56:03 +08:00
zend_hash_copy ( ht , newAttr - > extraAttributes , copy_extra_attribute , & node , sizeof ( xmlNodePtr ) ) ;
2004-01-21 22:00:55 +08:00
newAttr - > extraAttributes = ht ;
}
zend_hash_get_current_key_ex ( ( * tmp ) - > attributes , & key , & key_len , NULL , 0 , NULL ) ;
zend_hash_add ( ht , key , key_len , & newAttr , sizeof ( sdlAttributePtr ) , NULL ) ;
2004-01-22 00:04:37 +08:00
2004-01-21 22:00:55 +08:00
zend_hash_move_forward ( ( * tmp ) - > attributes ) ;
} else {
ulong index ;
2004-02-06 19:56:03 +08:00
schema_attributegroup_fixup ( ctx , * tmp_attr , ht ) ;
2004-01-21 22:00:55 +08:00
zend_hash_get_current_key ( ( * tmp ) - > attributes , NULL , & index , 0 ) ;
zend_hash_index_del ( ( * tmp ) - > attributes , index ) ;
}
}
}
}
}
efree ( attr - > ref ) ;
attr - > ref = NULL ;
2004-01-20 00:40:37 +08:00
}
}
2004-01-21 00:30:38 +08:00
2004-02-06 19:56:03 +08:00
static void schema_content_model_fixup ( sdlCtx * ctx , sdlContentModelPtr model )
2004-01-22 23:58:03 +08:00
{
switch ( model - > kind ) {
case XSD_CONTENT_GROUP_REF : {
sdlTypePtr * tmp ;
2004-02-06 19:56:03 +08:00
if ( ctx - > sdl - > groups & & zend_hash_find ( ctx - > sdl - > groups , model - > u . group_ref , strlen ( model - > u . group_ref ) + 1 , ( void * * ) & tmp ) = = SUCCESS ) {
schema_type_fixup ( ctx , * tmp ) ;
2004-01-22 23:58:03 +08:00
efree ( model - > u . group_ref ) ;
model - > kind = XSD_CONTENT_GROUP ;
2004-02-10 21:41:21 +08:00
model - > u . group = ( * tmp ) ;
2004-01-22 23:58:03 +08:00
} else {
2013-07-31 21:36:06 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unresolved group 'ref' attribute '%s' " , model - > u . group_ref ) ;
2004-01-22 23:58:03 +08:00
}
break ;
}
case XSD_CONTENT_CHOICE : {
2005-11-08 16:30:19 +08:00
if ( model - > max_occurs ! = 1 ) {
HashPosition pos ;
sdlContentModelPtr * tmp ;
zend_hash_internal_pointer_reset_ex ( model - > u . content , & pos ) ;
while ( zend_hash_get_current_data_ex ( model - > u . content , ( void * * ) & tmp , & pos ) = = SUCCESS ) {
( * tmp ) - > min_occurs = 0 ;
( * tmp ) - > max_occurs = model - > max_occurs ;
zend_hash_move_forward_ex ( model - > u . content , & pos ) ;
}
model - > kind = XSD_CONTENT_ALL ;
model - > min_occurs = 1 ;
model - > max_occurs = 1 ;
}
}
case XSD_CONTENT_SEQUENCE :
case XSD_CONTENT_ALL : {
2004-01-22 23:58:03 +08:00
sdlContentModelPtr * tmp ;
zend_hash_internal_pointer_reset ( model - > u . content ) ;
while ( zend_hash_get_current_data ( model - > u . content , ( void * * ) & tmp ) = = SUCCESS ) {
2004-02-06 19:56:03 +08:00
schema_content_model_fixup ( ctx , * tmp ) ;
2004-01-22 23:58:03 +08:00
zend_hash_move_forward ( model - > u . content ) ;
}
break ;
}
default :
break ;
}
}
2004-02-06 19:56:03 +08:00
static void schema_type_fixup ( sdlCtx * ctx , sdlTypePtr type )
2004-01-21 00:30:38 +08:00
{
sdlTypePtr * tmp ;
2004-01-21 22:00:55 +08:00
sdlAttributePtr * attr ;
2004-01-21 00:30:38 +08:00
if ( type - > ref ! = NULL ) {
2004-02-06 19:56:03 +08:00
if ( ctx - > sdl - > elements ! = NULL ) {
2013-07-31 21:36:06 +08:00
tmp = ( sdlTypePtr * ) schema_find_by_ref ( ctx - > sdl - > elements , type - > ref ) ;
if ( tmp ) {
2004-02-24 17:02:33 +08:00
type - > kind = ( * tmp ) - > kind ;
2004-01-21 22:00:55 +08:00
type - > encode = ( * tmp ) - > encode ;
2004-02-17 23:10:16 +08:00
if ( ( * tmp ) - > nillable ) {
type - > nillable = 1 ;
}
2004-02-24 17:02:33 +08:00
if ( ( * tmp ) - > fixed ) {
type - > fixed = estrdup ( ( * tmp ) - > fixed ) ;
}
if ( ( * tmp ) - > def ) {
type - > def = estrdup ( ( * tmp ) - > def ) ;
}
2005-04-20 16:30:43 +08:00
type - > form = ( * tmp ) - > form ;
2005-03-22 18:19:08 +08:00
} else if ( strcmp ( type - > ref , SCHEMA_NAMESPACE " :schema " ) = = 0 ) {
type - > encode = get_conversion ( XSD_ANYXML ) ;
2004-01-21 22:00:55 +08:00
} else {
2013-07-31 21:36:06 +08:00
soap_error1 ( E_ERROR , " Parsing Schema: unresolved element 'ref' attribute '%s' " , type - > ref ) ;
2004-01-21 22:00:55 +08:00
}
2004-01-21 00:30:38 +08:00
}
efree ( type - > ref ) ;
type - > ref = NULL ;
}
if ( type - > elements ) {
zend_hash_internal_pointer_reset ( type - > elements ) ;
while ( zend_hash_get_current_data ( type - > elements , ( void * * ) & tmp ) = = SUCCESS ) {
2004-02-06 19:56:03 +08:00
schema_type_fixup ( ctx , * tmp ) ;
2004-01-21 00:30:38 +08:00
zend_hash_move_forward ( type - > elements ) ;
}
}
2004-01-22 23:58:03 +08:00
if ( type - > model ) {
2004-02-06 19:56:03 +08:00
schema_content_model_fixup ( ctx , type - > model ) ;
2004-01-22 23:58:03 +08:00
}
2004-01-21 22:00:55 +08:00
if ( type - > attributes ) {
zend_hash_internal_pointer_reset ( type - > attributes ) ;
while ( zend_hash_get_current_data ( type - > attributes , ( void * * ) & attr ) = = SUCCESS ) {
if ( zend_hash_get_current_key_type ( type - > attributes ) = = HASH_KEY_IS_STRING ) {
2004-02-06 19:56:03 +08:00
schema_attribute_fixup ( ctx , * attr ) ;
2004-01-21 22:00:55 +08:00
zend_hash_move_forward ( type - > attributes ) ;
} else {
ulong index ;
2004-02-06 19:56:03 +08:00
schema_attributegroup_fixup ( ctx , * attr , type - > attributes ) ;
2004-01-21 22:00:55 +08:00
zend_hash_get_current_key ( type - > attributes , NULL , & index , 0 ) ;
zend_hash_index_del ( type - > attributes , index ) ;
}
}
}
2004-01-21 00:30:38 +08:00
}
2004-02-06 19:56:03 +08:00
void schema_pass2 ( sdlCtx * ctx )
2004-01-21 00:30:38 +08:00
{
2004-02-06 19:56:03 +08:00
sdlPtr sdl = ctx - > sdl ;
2004-01-21 22:00:55 +08:00
sdlAttributePtr * attr ;
2004-01-21 00:30:38 +08:00
sdlTypePtr * type ;
2004-02-06 19:56:03 +08:00
if ( ctx - > attributes ) {
zend_hash_internal_pointer_reset ( ctx - > attributes ) ;
while ( zend_hash_get_current_data ( ctx - > attributes , ( void * * ) & attr ) = = SUCCESS ) {
schema_attribute_fixup ( ctx , * attr ) ;
zend_hash_move_forward ( ctx - > attributes ) ;
2004-01-21 22:00:55 +08:00
}
}
2004-02-06 19:56:03 +08:00
if ( ctx - > attributeGroups ) {
zend_hash_internal_pointer_reset ( ctx - > attributeGroups ) ;
while ( zend_hash_get_current_data ( ctx - > attributeGroups , ( void * * ) & type ) = = SUCCESS ) {
schema_type_fixup ( ctx , * type ) ;
zend_hash_move_forward ( ctx - > attributeGroups ) ;
2004-01-21 22:00:55 +08:00
}
}
2004-01-21 00:30:38 +08:00
if ( sdl - > elements ) {
zend_hash_internal_pointer_reset ( sdl - > elements ) ;
while ( zend_hash_get_current_data ( sdl - > elements , ( void * * ) & type ) = = SUCCESS ) {
2004-02-06 19:56:03 +08:00
schema_type_fixup ( ctx , * type ) ;
2004-01-21 00:30:38 +08:00
zend_hash_move_forward ( sdl - > elements ) ;
}
}
2004-01-22 23:58:03 +08:00
if ( sdl - > groups ) {
zend_hash_internal_pointer_reset ( sdl - > groups ) ;
while ( zend_hash_get_current_data ( sdl - > groups , ( void * * ) & type ) = = SUCCESS ) {
2004-02-06 19:56:03 +08:00
schema_type_fixup ( ctx , * type ) ;
2004-01-22 23:58:03 +08:00
zend_hash_move_forward ( sdl - > groups ) ;
}
}
2004-01-21 00:30:38 +08:00
if ( sdl - > types ) {
zend_hash_internal_pointer_reset ( sdl - > types ) ;
while ( zend_hash_get_current_data ( sdl - > types , ( void * * ) & type ) = = SUCCESS ) {
2004-02-06 19:56:03 +08:00
schema_type_fixup ( ctx , * type ) ;
2004-01-21 00:30:38 +08:00
zend_hash_move_forward ( sdl - > types ) ;
}
}
2004-02-06 19:56:03 +08:00
if ( ctx - > attributes ) {
zend_hash_destroy ( ctx - > attributes ) ;
efree ( ctx - > attributes ) ;
2004-01-22 23:58:03 +08:00
}
2004-02-06 19:56:03 +08:00
if ( ctx - > attributeGroups ) {
zend_hash_destroy ( ctx - > attributeGroups ) ;
efree ( ctx - > attributeGroups ) ;
2004-01-22 23:58:03 +08:00
}
}
2004-02-10 21:41:21 +08:00
void delete_model ( void * handle )
2004-01-22 23:58:03 +08:00
{
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 ) ;
2004-02-13 19:03:58 +08:00
efree ( tmp - > u . content ) ;
2004-01-22 23:58:03 +08:00
break ;
case XSD_CONTENT_GROUP_REF :
efree ( tmp - > u . group_ref ) ;
break ;
2005-03-22 18:19:08 +08:00
default :
break ;
2004-01-22 23:58:03 +08:00
}
2004-02-13 19:03:58 +08:00
efree ( tmp ) ;
2004-01-22 23:58:03 +08:00
}
2004-01-26 17:51:07 +08:00
2006-04-10 07:35:51 +08:00
void delete_model_persistent ( 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 :
free ( tmp - > u . group_ref ) ;
break ;
default :
break ;
}
free ( tmp ) ;
}
2004-02-10 21:41:21 +08:00
void delete_type ( void * data )
2004-01-26 17:51:07 +08:00
{
sdlTypePtr type = * ( ( sdlTypePtr * ) data ) ;
2007-02-16 01:01:29 +08:00
2004-01-26 17:51:07 +08:00
if ( type - > name ) {
2004-02-13 19:03:58 +08:00
efree ( type - > name ) ;
2004-01-26 17:51:07 +08:00
}
if ( type - > namens ) {
2004-02-13 19:03:58 +08:00
efree ( type - > namens ) ;
2004-01-26 17:51:07 +08:00
}
if ( type - > def ) {
2004-02-13 19:03:58 +08:00
efree ( type - > def ) ;
2004-01-26 17:51:07 +08:00
}
if ( type - > fixed ) {
2004-02-13 19:03:58 +08:00
efree ( type - > fixed ) ;
2004-01-26 17:51:07 +08:00
}
if ( type - > elements ) {
zend_hash_destroy ( type - > elements ) ;
2004-02-13 19:03:58 +08:00
efree ( type - > elements ) ;
2004-01-26 17:51:07 +08:00
}
if ( type - > attributes ) {
zend_hash_destroy ( type - > attributes ) ;
2004-02-13 19:03:58 +08:00
efree ( type - > attributes ) ;
2004-02-06 22:22:33 +08:00
}
if ( type - > model ) {
delete_model ( ( void * * ) & type - > model ) ;
2004-01-26 17:51:07 +08:00
}
if ( type - > restrictions ) {
delete_restriction_var_int ( & type - > restrictions - > minExclusive ) ;
delete_restriction_var_int ( & type - > restrictions - > minInclusive ) ;
delete_restriction_var_int ( & type - > restrictions - > maxExclusive ) ;
delete_restriction_var_int ( & type - > restrictions - > maxInclusive ) ;
delete_restriction_var_int ( & type - > restrictions - > totalDigits ) ;
delete_restriction_var_int ( & type - > restrictions - > fractionDigits ) ;
delete_restriction_var_int ( & type - > restrictions - > length ) ;
delete_restriction_var_int ( & type - > restrictions - > minLength ) ;
delete_restriction_var_int ( & type - > restrictions - > maxLength ) ;
2004-02-10 21:41:21 +08:00
delete_restriction_var_char ( & type - > restrictions - > whiteSpace ) ;
delete_restriction_var_char ( & type - > restrictions - > pattern ) ;
2004-01-26 17:51:07 +08:00
if ( type - > restrictions - > enumeration ) {
zend_hash_destroy ( type - > restrictions - > enumeration ) ;
2004-02-13 19:03:58 +08:00
efree ( type - > restrictions - > enumeration ) ;
2004-01-26 17:51:07 +08:00
}
2004-02-13 19:03:58 +08:00
efree ( type - > restrictions ) ;
2004-01-26 17:51:07 +08:00
}
2004-02-13 19:03:58 +08:00
efree ( type ) ;
2004-01-26 17:51:07 +08:00
}
2006-04-10 07:35:51 +08:00
void delete_type_persistent ( void * data )
{
sdlTypePtr type = * ( ( sdlTypePtr * ) data ) ;
if ( type - > name ) {
free ( type - > name ) ;
}
if ( type - > namens ) {
free ( type - > namens ) ;
}
if ( type - > def ) {
free ( type - > def ) ;
}
if ( type - > fixed ) {
free ( type - > fixed ) ;
}
if ( type - > elements ) {
zend_hash_destroy ( type - > elements ) ;
free ( type - > elements ) ;
}
if ( type - > attributes ) {
zend_hash_destroy ( type - > attributes ) ;
free ( type - > attributes ) ;
}
if ( type - > model ) {
delete_model_persistent ( ( void * * ) & type - > model ) ;
}
if ( type - > restrictions ) {
delete_restriction_var_int_persistent ( & type - > restrictions - > minExclusive ) ;
delete_restriction_var_int_persistent ( & type - > restrictions - > minInclusive ) ;
delete_restriction_var_int_persistent ( & type - > restrictions - > maxExclusive ) ;
delete_restriction_var_int_persistent ( & type - > restrictions - > maxInclusive ) ;
delete_restriction_var_int_persistent ( & type - > restrictions - > totalDigits ) ;
delete_restriction_var_int_persistent ( & type - > restrictions - > fractionDigits ) ;
delete_restriction_var_int_persistent ( & type - > restrictions - > length ) ;
delete_restriction_var_int_persistent ( & type - > restrictions - > minLength ) ;
delete_restriction_var_int_persistent ( & type - > restrictions - > maxLength ) ;
delete_restriction_var_char_persistent ( & type - > restrictions - > whiteSpace ) ;
delete_restriction_var_char_persistent ( & type - > restrictions - > pattern ) ;
if ( type - > restrictions - > enumeration ) {
zend_hash_destroy ( type - > restrictions - > enumeration ) ;
free ( type - > restrictions - > enumeration ) ;
}
free ( type - > restrictions ) ;
}
free ( type ) ;
}
2004-02-10 21:41:21 +08:00
void delete_extra_attribute ( void * attribute )
2004-02-06 19:56:03 +08:00
{
sdlExtraAttributePtr attr = * ( ( sdlExtraAttributePtr * ) attribute ) ;
if ( attr - > ns ) {
2004-02-13 19:03:58 +08:00
efree ( attr - > ns ) ;
2004-02-06 19:56:03 +08:00
}
if ( attr - > val ) {
2004-02-13 19:03:58 +08:00
efree ( attr - > val ) ;
2004-02-06 19:56:03 +08:00
}
2004-02-13 19:03:58 +08:00
efree ( attr ) ;
2004-02-06 19:56:03 +08:00
}
2006-04-10 07:35:51 +08:00
void delete_extra_attribute_persistent ( void * attribute )
{
sdlExtraAttributePtr attr = * ( ( sdlExtraAttributePtr * ) attribute ) ;
if ( attr - > ns ) {
free ( attr - > ns ) ;
}
if ( attr - > val ) {
free ( attr - > val ) ;
}
free ( attr ) ;
}
2004-02-10 21:41:21 +08:00
void delete_attribute ( void * attribute )
2004-01-26 17:51:07 +08:00
{
sdlAttributePtr attr = * ( ( sdlAttributePtr * ) attribute ) ;
if ( attr - > def ) {
2004-02-13 19:03:58 +08:00
efree ( attr - > def ) ;
2004-01-26 17:51:07 +08:00
}
if ( attr - > fixed ) {
2004-02-13 19:03:58 +08:00
efree ( attr - > fixed ) ;
2004-01-26 17:51:07 +08:00
}
if ( attr - > name ) {
2004-02-13 19:03:58 +08:00
efree ( attr - > name ) ;
2004-01-26 17:51:07 +08:00
}
2004-08-27 02:40:10 +08:00
if ( attr - > namens ) {
efree ( attr - > namens ) ;
}
2004-01-26 17:51:07 +08:00
if ( attr - > ref ) {
2004-02-13 19:03:58 +08:00
efree ( attr - > ref ) ;
2004-01-26 17:51:07 +08:00
}
if ( attr - > extraAttributes ) {
zend_hash_destroy ( attr - > extraAttributes ) ;
2004-02-13 19:03:58 +08:00
efree ( attr - > extraAttributes ) ;
2004-01-26 17:51:07 +08:00
}
2004-02-13 19:03:58 +08:00
efree ( attr ) ;
2004-01-26 17:51:07 +08:00
}
2006-04-10 07:35:51 +08:00
void delete_attribute_persistent ( void * attribute )
{
sdlAttributePtr attr = * ( ( sdlAttributePtr * ) attribute ) ;
if ( attr - > def ) {
free ( attr - > def ) ;
}
if ( attr - > fixed ) {
free ( attr - > fixed ) ;
}
if ( attr - > name ) {
free ( attr - > name ) ;
}
if ( attr - > namens ) {
free ( attr - > namens ) ;
}
if ( attr - > ref ) {
free ( attr - > ref ) ;
}
if ( attr - > extraAttributes ) {
zend_hash_destroy ( attr - > extraAttributes ) ;
free ( attr - > extraAttributes ) ;
}
free ( attr ) ;
}
2004-02-10 21:41:21 +08:00
void delete_restriction_var_int ( void * rvi )
2004-01-26 17:51:07 +08:00
{
sdlRestrictionIntPtr ptr = * ( ( sdlRestrictionIntPtr * ) rvi ) ;
if ( ptr ) {
2004-02-13 19:03:58 +08:00
efree ( ptr ) ;
2004-01-26 17:51:07 +08:00
}
}
2006-04-10 07:35:51 +08:00
void delete_restriction_var_int_persistent ( void * rvi )
{
sdlRestrictionIntPtr ptr = * ( ( sdlRestrictionIntPtr * ) rvi ) ;
if ( ptr ) {
free ( ptr ) ;
}
}
2004-02-10 21:41:21 +08:00
void delete_restriction_var_char ( void * srvc )
2004-01-26 17:51:07 +08:00
{
sdlRestrictionCharPtr ptr = * ( ( sdlRestrictionCharPtr * ) srvc ) ;
if ( ptr ) {
if ( ptr - > value ) {
2004-02-13 19:03:58 +08:00
efree ( ptr - > value ) ;
2004-01-26 17:51:07 +08:00
}
2004-02-13 19:03:58 +08:00
efree ( ptr ) ;
2004-01-26 17:51:07 +08:00
}
}
2006-04-10 07:35:51 +08:00
void delete_restriction_var_char_persistent ( void * srvc )
{
sdlRestrictionCharPtr ptr = * ( ( sdlRestrictionCharPtr * ) srvc ) ;
if ( ptr ) {
if ( ptr - > value ) {
free ( ptr - > value ) ;
}
free ( ptr ) ;
}
}