Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * schemas.c : implementation of the XML Schema handling and |
| 3 | * schema validity checking |
| 4 | * |
| 5 | * See Copyright for the status of this software. |
| 6 | * |
| 7 | * Daniel Veillard <veillard@redhat.com> |
| 8 | */ |
| 9 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10 | /* |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 11 | * TODO: |
| 12 | * - when types are redefined in includes, check that all |
| 13 | * types in the redef list are equal |
| 14 | * -> need a type equality operation. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15 | * - if we don't intend to use the schema for schemas, we |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16 | * need to validate all schema attributes (ref, type, name) |
| 17 | * against their types. |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 18 | * - Eliminate item creation for: ?? |
| 19 | * |
| 20 | * NOTES: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 21 | * - Elimated item creation for: <restriction>, <extension>, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 22 | * <simpleContent>, <complexContent>, <list>, <union> |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23 | * |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 24 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 25 | #define IN_LIBXML |
| 26 | #include "libxml.h" |
| 27 | |
| 28 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 29 | |
| 30 | #include <string.h> |
| 31 | #include <libxml/xmlmemory.h> |
| 32 | #include <libxml/parser.h> |
| 33 | #include <libxml/parserInternals.h> |
| 34 | #include <libxml/hash.h> |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 35 | #include <libxml/uri.h> |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 36 | #include <libxml/xmlschemas.h> |
| 37 | #include <libxml/schemasInternals.h> |
| 38 | #include <libxml/xmlschemastypes.h> |
| 39 | #include <libxml/xmlautomata.h> |
| 40 | #include <libxml/xmlregexp.h> |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 41 | #include <libxml/dict.h> |
Kasimier T. Buchcik | 72d3adc | 2005-07-08 16:43:37 +0000 | [diff] [blame] | 42 | #include <libxml/encoding.h> |
| 43 | #include <libxml/xmlIO.h> |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 44 | #ifdef LIBXML_PATTERN_ENABLED |
| 45 | #include <libxml/pattern.h> |
| 46 | #endif |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 47 | #ifdef LIBXML_READER_ENABLED |
| 48 | #include <libxml/xmlreader.h> |
| 49 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 50 | |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 51 | /* #define DEBUG 1 */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 52 | |
Daniel Veillard | 82bbbd4 | 2003-05-11 20:16:09 +0000 | [diff] [blame] | 53 | /* #define DEBUG_CONTENT 1 */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 54 | |
Daniel Veillard | 82bbbd4 | 2003-05-11 20:16:09 +0000 | [diff] [blame] | 55 | /* #define DEBUG_TYPE 1 */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 56 | |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 57 | /* #define DEBUG_CONTENT_REGEXP 1 */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 58 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 59 | /* #define DEBUG_AUTOMATA 1 */ |
| 60 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 61 | #define DEBUG_ATTR_VALIDATION 0 |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 62 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 63 | /* #define DEBUG_IDC 1 */ |
| 64 | |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 65 | /* #define DEBUG_INCLUDES 1 */ |
| 66 | |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 67 | /* #define ENABLE_PARTICLE_RESTRICTION 1 */ |
| 68 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 69 | #define DUMP_CONTENT_MODEL |
| 70 | |
Kasimier T. Buchcik | c63fbbf | 2005-06-15 12:54:05 +0000 | [diff] [blame] | 71 | #define XML_SCHEMA_SAX_ENABLED |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 72 | |
| 73 | #ifdef LIBXML_READER_ENABLED |
| 74 | /* #define XML_SCHEMA_READER_ENABLED */ |
| 75 | #endif |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 76 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 77 | #define UNBOUNDED (1 << 30) |
| 78 | #define TODO \ |
| 79 | xmlGenericError(xmlGenericErrorContext, \ |
| 80 | "Unimplemented block at %s:%d\n", \ |
| 81 | __FILE__, __LINE__); |
| 82 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 83 | #define XML_SCHEMAS_NO_NAMESPACE (const xmlChar *) "##" |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 84 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 85 | /* |
| 86 | * The XML Schemas namespaces |
| 87 | */ |
| 88 | static const xmlChar *xmlSchemaNs = (const xmlChar *) |
| 89 | "http://www.w3.org/2001/XMLSchema"; |
| 90 | |
| 91 | static const xmlChar *xmlSchemaInstanceNs = (const xmlChar *) |
| 92 | "http://www.w3.org/2001/XMLSchema-instance"; |
| 93 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 94 | static const xmlChar *xmlNamespaceNs = (const xmlChar *) |
| 95 | "http://www.w3.org/2000/xmlns/"; |
| 96 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 97 | static const xmlChar *xmlSchemaElemDesElemDecl = (const xmlChar *) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 98 | "element decl."; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 99 | static const xmlChar *xmlSchemaElemDesAttrDecl = (const xmlChar *) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 100 | "attribute decl."; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 101 | static const xmlChar *xmlSchemaElemDesAttrRef = (const xmlChar *) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 102 | "attribute use"; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 103 | static const xmlChar *xmlSchemaElemDesCT = (const xmlChar *) |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 104 | "complex type"; |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 105 | static const xmlChar *xmlSchemaElemModelGrDef = (const xmlChar *) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 106 | "model group"; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 107 | #if 0 |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 108 | static const xmlChar *xmlSchemaElemModelGrRef = (const xmlChar *) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 109 | "model group ref."; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 110 | #endif |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 111 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 112 | #define IS_SCHEMA(node, type) \ |
| 113 | ((node != NULL) && (node->ns != NULL) && \ |
| 114 | (xmlStrEqual(node->name, (const xmlChar *) type)) && \ |
| 115 | (xmlStrEqual(node->ns->href, xmlSchemaNs))) |
| 116 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 117 | #define FREE_AND_NULL(str) \ |
| 118 | if (str != NULL) { \ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 119 | xmlFree((xmlChar *) str); \ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 120 | str = NULL; \ |
| 121 | } |
| 122 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 123 | #define IS_ANYTYPE(item) \ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 124 | ((item->type == XML_SCHEMA_TYPE_BASIC) && \ |
| 125 | (item->builtInType == XML_SCHEMAS_ANYTYPE)) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 126 | |
| 127 | #define IS_COMPLEX_TYPE(item) \ |
| 128 | ((item->type == XML_SCHEMA_TYPE_COMPLEX) || \ |
| 129 | (item->builtInType == XML_SCHEMAS_ANYTYPE)) |
| 130 | |
| 131 | #define IS_SIMPLE_TYPE(item) \ |
| 132 | ((item->type == XML_SCHEMA_TYPE_SIMPLE) || \ |
| 133 | ((item->type == XML_SCHEMA_TYPE_BASIC) && \ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 134 | (item->builtInType != XML_SCHEMAS_ANYTYPE))) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 135 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 136 | #define IS_ANY_SIMPLE_TYPE(item) \ |
| 137 | ((item->type == XML_SCHEMA_TYPE_BASIC) && \ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 138 | (item->builtInType == XML_SCHEMAS_ANYSIMPLETYPE)) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 139 | |
| 140 | #define IS_NOT_TYPEFIXED(item) \ |
| 141 | ((item->type != XML_SCHEMA_TYPE_BASIC) && \ |
| 142 | ((item->flags & XML_SCHEMAS_TYPE_INTERNAL_RESOLVED) == 0)) |
| 143 | |
| 144 | #define HAS_COMPLEX_CONTENT(item) \ |
| 145 | ((item->contentType == XML_SCHEMA_CONTENT_MIXED) || \ |
| 146 | (item->contentType == XML_SCHEMA_CONTENT_EMPTY) || \ |
| 147 | (item->contentType == XML_SCHEMA_CONTENT_ELEMENTS)) |
| 148 | |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 149 | #define HAS_SIMPLE_CONTENT(item) \ |
| 150 | ((item->contentType == XML_SCHEMA_CONTENT_SIMPLE) || \ |
| 151 | (item->contentType == XML_SCHEMA_CONTENT_BASIC)) |
| 152 | |
| 153 | #define HAS_MIXED_CONTENT(item) (item->contentType == XML_SCHEMA_CONTENT_MIXED) |
| 154 | |
| 155 | #define IS_PARTICLE_EMPTIABLE(item) \ |
| 156 | (xmlSchemaIsParticleEmptiable((xmlSchemaParticlePtr) item->subtypes)) |
| 157 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 158 | #define GET_NODE(item) xmlSchemaGetComponentNode((xmlSchemaBasicItemPtr) item) |
| 159 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 160 | #define GET_LIST_ITEM_TYPE(item) item->subtypes |
| 161 | |
| 162 | #define VARIETY_ATOMIC(item) (item->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) |
| 163 | #define VARIETY_LIST(item) (item->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) |
| 164 | #define VARIETY_UNION(item) (item->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) |
| 165 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 166 | #define IS_MODEL_GROUP(item) \ |
| 167 | ((item->type == XML_SCHEMA_TYPE_SEQUENCE) || \ |
| 168 | (item->type == XML_SCHEMA_TYPE_CHOICE) || \ |
| 169 | (item->type == XML_SCHEMA_TYPE_ALL)) |
| 170 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 171 | #define INODE_NILLED(item) (item->flags & XML_SCHEMA_ELEM_INFO_NILLED) |
| 172 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 173 | #define ELEM_TYPE(item) item->subtypes |
| 174 | |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 175 | #define GET_PARTICLE(item) (xmlSchemaParticlePtr) item->subtypes; |
| 176 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 177 | #define SUBST_GROUP_AFF(item) item->refDecl |
| 178 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 179 | #if 0 |
| 180 | #define WXS_GET_NEXT(item) xmlSchemaGetNextComponent((xmlSchemaBasicItemPtr) item) |
| 181 | #endif |
| 182 | |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 183 | #define SUBSET_RESTRICTION 1<<0 |
| 184 | #define SUBSET_EXTENSION 1<<1 |
| 185 | #define SUBSET_SUBSTITUTION 1<<2 |
| 186 | #define SUBSET_LIST 1<<3 |
| 187 | #define SUBSET_UNION 1<<4 |
| 188 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 189 | #define XML_SCHEMAS_PARSE_ERROR 1 |
| 190 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 191 | #define SCHEMAS_PARSE_OPTIONS XML_PARSE_NOENT |
| 192 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 193 | typedef struct _xmlSchemaNodeInfo xmlSchemaNodeInfo; |
| 194 | typedef xmlSchemaNodeInfo *xmlSchemaNodeInfoPtr; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 195 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 196 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 197 | typedef struct _xmlSchemaItemList xmlSchemaAssemble; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 198 | typedef xmlSchemaAssemble *xmlSchemaAssemblePtr; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 199 | |
| 200 | typedef struct _xmlSchemaItemList xmlSchemaItemList; |
| 201 | typedef xmlSchemaItemList *xmlSchemaItemListPtr; |
| 202 | |
| 203 | struct _xmlSchemaItemList { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 204 | void **items; /* used for dynamic addition of schemata */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 205 | int nbItems; /* used for dynamic addition of schemata */ |
| 206 | int sizeItems; /* used for dynamic addition of schemata */ |
| 207 | }; |
| 208 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 209 | typedef struct _xmlSchemaAbstractCtxt xmlSchemaAbstractCtxt; |
| 210 | typedef xmlSchemaAbstractCtxt *xmlSchemaAbstractCtxtPtr; |
| 211 | struct _xmlSchemaAbstractCtxt { |
| 212 | int type; |
| 213 | }; |
| 214 | |
| 215 | #define XML_SCHEMA_CTXT_PARSER 1 |
| 216 | #define XML_SCHEMA_CTXT_VALIDATOR 2 |
| 217 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 218 | struct _xmlSchemaParserCtxt { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 219 | int type; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 220 | void *userData; /* user specific data block */ |
| 221 | xmlSchemaValidityErrorFunc error; /* the callback in case of errors */ |
| 222 | xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */ |
Daniel Veillard | e19fc23 | 2002-04-22 16:01:24 +0000 | [diff] [blame] | 223 | xmlSchemaValidError err; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 224 | int nberrors; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 225 | xmlStructuredErrorFunc serror; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 226 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 227 | xmlSchemaPtr topschema; /* The main schema */ |
| 228 | xmlHashTablePtr namespaces; /* Hash table of namespaces to schemas */ |
| 229 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 230 | xmlSchemaPtr schema; /* The schema in use */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 231 | const xmlChar *container; /* the current element, group, ... */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 232 | int counter; |
| 233 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 234 | const xmlChar *URL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 235 | xmlDocPtr doc; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 236 | int preserve; /* Whether the doc should be freed */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 237 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 238 | const char *buffer; |
| 239 | int size; |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 240 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 241 | /* |
| 242 | * Used to build complex element content models |
| 243 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 244 | xmlAutomataPtr am; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 245 | xmlAutomataStatePtr start; |
| 246 | xmlAutomataStatePtr end; |
| 247 | xmlAutomataStatePtr state; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 248 | |
| 249 | xmlDictPtr dict; /* dictionnary for interned string names */ |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 250 | int includes; /* the inclusion level, 0 for root or imports */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 251 | xmlSchemaTypePtr ctxtType; /* The current context simple/complex type */ |
| 252 | xmlSchemaTypePtr parentItem; /* The current parent schema item */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 253 | xmlSchemaAssemblePtr assemble; |
| 254 | int options; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 255 | xmlSchemaValidCtxtPtr vctxt; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 256 | const xmlChar **localImports; /* list of locally imported namespaces */ |
| 257 | int sizeLocalImports; |
| 258 | int nbLocalImports; |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 259 | xmlHashTablePtr substGroups; |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 260 | int isS4S; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 261 | }; |
| 262 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 263 | #define XML_SCHEMAS_ATTR_UNKNOWN 1 |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 264 | #define XML_SCHEMAS_ATTR_ASSESSED 2 |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 265 | #define XML_SCHEMAS_ATTR_PROHIBITED 3 |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 266 | #define XML_SCHEMAS_ATTR_ERR_MISSING 4 |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 267 | #define XML_SCHEMAS_ATTR_INVALID_VALUE 5 |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 268 | #define XML_SCHEMAS_ATTR_ERR_NO_TYPE 6 |
| 269 | #define XML_SCHEMAS_ATTR_ERR_FIXED_VALUE 7 |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 270 | #define XML_SCHEMAS_ATTR_DEFAULT 8 |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 271 | #define XML_SCHEMAS_ATTR_VALIDATE_VALUE 9 |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 272 | #define XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL 10 |
| 273 | #define XML_SCHEMAS_ATTR_HAS_ATTR_USE 11 |
| 274 | #define XML_SCHEMAS_ATTR_HAS_ATTR_DECL 12 |
| 275 | #define XML_SCHEMAS_ATTR_WILD_SKIP 13 |
| 276 | #define XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL 14 |
| 277 | #define XML_SCHEMAS_ATTR_ERR_WILD_DUPLICATE_ID 15 |
| 278 | #define XML_SCHEMAS_ATTR_ERR_WILD_AND_USE_ID 16 |
| 279 | #define XML_SCHEMAS_ATTR_META 17 |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 280 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 281 | /** |
| 282 | * xmlSchemaBasicItem: |
| 283 | * |
| 284 | * The abstract base type for schema components. |
| 285 | */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 286 | typedef struct _xmlSchemaBasicItem xmlSchemaBasicItem; |
| 287 | typedef xmlSchemaBasicItem *xmlSchemaBasicItemPtr; |
| 288 | struct _xmlSchemaBasicItem { |
| 289 | xmlSchemaTypeType type; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 290 | }; |
| 291 | |
| 292 | /** |
| 293 | * xmlSchemaAnnotItem: |
| 294 | * |
| 295 | * The abstract base type for annotated schema components. |
| 296 | * (Extends xmlSchemaBasicItem) |
| 297 | */ |
| 298 | typedef struct _xmlSchemaAnnotItem xmlSchemaAnnotItem; |
| 299 | typedef xmlSchemaAnnotItem *xmlSchemaAnnotItemPtr; |
| 300 | struct _xmlSchemaAnnotItem { |
| 301 | xmlSchemaTypeType type; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 302 | xmlSchemaAnnotPtr annot; |
| 303 | }; |
| 304 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 305 | /** |
| 306 | * xmlSchemaTreeItem: |
| 307 | * |
| 308 | * The abstract base type for tree-like structured schema components. |
| 309 | * (Extends xmlSchemaAnnotItem) |
| 310 | */ |
| 311 | typedef struct _xmlSchemaTreeItem xmlSchemaTreeItem; |
| 312 | typedef xmlSchemaTreeItem *xmlSchemaTreeItemPtr; |
| 313 | struct _xmlSchemaTreeItem { |
| 314 | xmlSchemaTypeType type; |
| 315 | xmlSchemaAnnotPtr annot; |
| 316 | xmlSchemaTreeItemPtr next; |
| 317 | xmlSchemaTreeItemPtr children; |
| 318 | }; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 319 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 320 | /** |
| 321 | * xmlSchemaQNameRef: |
| 322 | * |
| 323 | * A component reference item (not a schema component) |
| 324 | * (Extends xmlSchemaBasicItem) |
| 325 | */ |
| 326 | typedef struct _xmlSchemaQNameRef xmlSchemaQNameRef; |
| 327 | typedef xmlSchemaQNameRef *xmlSchemaQNameRefPtr; |
| 328 | struct _xmlSchemaQNameRef { |
| 329 | xmlSchemaTypeType type; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 330 | xmlSchemaBasicItemPtr item; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 331 | xmlSchemaTypeType itemType; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 332 | const xmlChar *name; |
| 333 | const xmlChar *targetNamespace; |
| 334 | }; |
| 335 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 336 | /** |
| 337 | * xmlSchemaParticle: |
| 338 | * |
| 339 | * A particle component. |
| 340 | * (Extends xmlSchemaTreeItem) |
| 341 | */ |
| 342 | typedef struct _xmlSchemaParticle xmlSchemaParticle; |
| 343 | typedef xmlSchemaParticle *xmlSchemaParticlePtr; |
| 344 | struct _xmlSchemaParticle { |
| 345 | xmlSchemaTypeType type; |
| 346 | xmlSchemaAnnotPtr annot; |
| 347 | xmlSchemaTreeItemPtr next; /* next particle (OR "element decl" OR "wildcard") */ |
| 348 | xmlSchemaTreeItemPtr children; /* the "term" ("model group" OR "group definition") */ |
| 349 | int minOccurs; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 350 | int maxOccurs; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 351 | xmlNodePtr node; |
| 352 | }; |
| 353 | |
| 354 | /** |
| 355 | * xmlSchemaModelGroup: |
| 356 | * |
| 357 | * A model group component. |
| 358 | * (Extends xmlSchemaTreeItem) |
| 359 | */ |
| 360 | typedef struct _xmlSchemaModelGroup xmlSchemaModelGroup; |
| 361 | typedef xmlSchemaModelGroup *xmlSchemaModelGroupPtr; |
| 362 | struct _xmlSchemaModelGroup { |
| 363 | xmlSchemaTypeType type; /* XML_SCHEMA_TYPE_SEQUENCE, XML_SCHEMA_TYPE_CHOICE, XML_SCHEMA_TYPE_ALL */ |
| 364 | xmlSchemaAnnotPtr annot; |
| 365 | xmlSchemaTreeItemPtr next; /* not used */ |
| 366 | xmlSchemaTreeItemPtr children; /* first particle (OR "element decl" OR "wildcard") */ |
| 367 | xmlNodePtr node; |
| 368 | }; |
| 369 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 370 | #define XML_SCHEMA_MODEL_GROUP_DEF_MARKED 1<<0 |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 371 | /** |
| 372 | * xmlSchemaModelGroupDef: |
| 373 | * |
| 374 | * A model group definition component. |
| 375 | * (Extends xmlSchemaTreeItem) |
| 376 | */ |
| 377 | typedef struct _xmlSchemaModelGroupDef xmlSchemaModelGroupDef; |
| 378 | typedef xmlSchemaModelGroupDef *xmlSchemaModelGroupDefPtr; |
| 379 | struct _xmlSchemaModelGroupDef { |
| 380 | xmlSchemaTypeType type; /* XML_SCHEMA_TYPE_GROUP */ |
| 381 | xmlSchemaAnnotPtr annot; |
| 382 | xmlSchemaTreeItemPtr next; /* not used */ |
| 383 | xmlSchemaTreeItemPtr children; /* the "model group" */ |
| 384 | const xmlChar *name; |
| 385 | const xmlChar *targetNamespace; |
| 386 | xmlNodePtr node; |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 387 | int flags; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 388 | }; |
| 389 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 390 | typedef struct _xmlSchemaIDC xmlSchemaIDC; |
| 391 | typedef xmlSchemaIDC *xmlSchemaIDCPtr; |
| 392 | |
| 393 | /** |
| 394 | * xmlSchemaIDCSelect: |
| 395 | * |
| 396 | * The identity-constraint "field" and "selector" item, holding the |
| 397 | * XPath expression. |
| 398 | */ |
| 399 | typedef struct _xmlSchemaIDCSelect xmlSchemaIDCSelect; |
| 400 | typedef xmlSchemaIDCSelect *xmlSchemaIDCSelectPtr; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 401 | struct _xmlSchemaIDCSelect { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 402 | xmlSchemaIDCSelectPtr next; |
| 403 | xmlSchemaIDCPtr idc; |
| 404 | int index; /* an index position if significant for IDC key-sequences */ |
| 405 | const xmlChar *xpath; /* the XPath expression */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 406 | void *xpathComp; /* the compiled XPath expression */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 407 | }; |
| 408 | |
| 409 | /** |
| 410 | * xmlSchemaIDC: |
| 411 | * |
| 412 | * The identity-constraint definition component. |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 413 | * (Extends xmlSchemaAnnotItem) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 414 | */ |
| 415 | |
| 416 | struct _xmlSchemaIDC { |
| 417 | xmlSchemaTypeType type; |
| 418 | xmlSchemaAnnotPtr annot; |
| 419 | xmlSchemaIDCPtr next; |
| 420 | xmlNodePtr node; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 421 | const xmlChar *name; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 422 | const xmlChar *targetNamespace; |
| 423 | xmlSchemaIDCSelectPtr selector; |
| 424 | xmlSchemaIDCSelectPtr fields; |
| 425 | int nbFields; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 426 | xmlSchemaQNameRefPtr ref; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 427 | }; |
| 428 | |
| 429 | /** |
| 430 | * xmlSchemaIDCAug: |
| 431 | * |
| 432 | * The augmented IDC information used for validation. |
| 433 | */ |
| 434 | typedef struct _xmlSchemaIDCAug xmlSchemaIDCAug; |
| 435 | typedef xmlSchemaIDCAug *xmlSchemaIDCAugPtr; |
| 436 | struct _xmlSchemaIDCAug { |
| 437 | xmlSchemaIDCAugPtr next; /* next in a list */ |
| 438 | xmlSchemaIDCPtr def; /* the IDC definition */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 439 | int bubbleDepth; /* the lowest tree level to which IDC |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 440 | tables need to be bubbled upwards */ |
| 441 | }; |
| 442 | |
| 443 | /** |
| 444 | * xmlSchemaPSVIIDCKeySequence: |
| 445 | * |
| 446 | * The key sequence of a node table item. |
| 447 | */ |
| 448 | typedef struct _xmlSchemaPSVIIDCKey xmlSchemaPSVIIDCKey; |
| 449 | typedef xmlSchemaPSVIIDCKey *xmlSchemaPSVIIDCKeyPtr; |
| 450 | struct _xmlSchemaPSVIIDCKey { |
| 451 | xmlSchemaTypePtr type; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 452 | xmlSchemaValPtr val; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 453 | }; |
| 454 | |
| 455 | /** |
| 456 | * xmlSchemaPSVIIDCNode: |
| 457 | * |
| 458 | * The node table item of a node table. |
| 459 | */ |
| 460 | typedef struct _xmlSchemaPSVIIDCNode xmlSchemaPSVIIDCNode; |
| 461 | typedef xmlSchemaPSVIIDCNode *xmlSchemaPSVIIDCNodePtr; |
| 462 | struct _xmlSchemaPSVIIDCNode { |
| 463 | xmlNodePtr node; |
| 464 | xmlSchemaPSVIIDCKeyPtr *keys; |
| 465 | }; |
| 466 | |
| 467 | /** |
| 468 | * xmlSchemaPSVIIDCBinding: |
| 469 | * |
| 470 | * The identity-constraint binding item of the [identity-constraint table]. |
| 471 | */ |
| 472 | typedef struct _xmlSchemaPSVIIDCBinding xmlSchemaPSVIIDCBinding; |
| 473 | typedef xmlSchemaPSVIIDCBinding *xmlSchemaPSVIIDCBindingPtr; |
| 474 | struct _xmlSchemaPSVIIDCBinding { |
| 475 | xmlSchemaPSVIIDCBindingPtr next; /* next binding of a specific node */ |
| 476 | xmlSchemaIDCPtr definition; /* the IDC definition */ |
| 477 | xmlSchemaPSVIIDCNodePtr *nodeTable; /* array of key-sequences */ |
| 478 | int nbNodes; /* number of entries in the node table */ |
| 479 | int sizeNodes; /* size of the node table */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 480 | int nbDupls; /* number of already identified duplicates in the node |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 481 | table */ |
| 482 | /* int nbKeys; number of keys in each key-sequence */ |
| 483 | }; |
| 484 | |
| 485 | #define XPATH_STATE_OBJ_TYPE_IDC_SELECTOR 1 |
| 486 | #define XPATH_STATE_OBJ_TYPE_IDC_FIELD 2 |
| 487 | |
| 488 | #define XPATH_STATE_OBJ_MATCHES -2 |
| 489 | #define XPATH_STATE_OBJ_BLOCKED -3 |
| 490 | |
| 491 | typedef struct _xmlSchemaIDCMatcher xmlSchemaIDCMatcher; |
| 492 | typedef xmlSchemaIDCMatcher *xmlSchemaIDCMatcherPtr; |
| 493 | |
| 494 | /** |
| 495 | * xmlSchemaIDCStateObj: |
| 496 | * |
| 497 | * The state object used to evaluate XPath expressions. |
| 498 | */ |
| 499 | typedef struct _xmlSchemaIDCStateObj xmlSchemaIDCStateObj; |
| 500 | typedef xmlSchemaIDCStateObj *xmlSchemaIDCStateObjPtr; |
| 501 | struct _xmlSchemaIDCStateObj { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 502 | int type; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 503 | xmlSchemaIDCStateObjPtr next; /* next if in a list */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 504 | int depth; /* depth of creation */ |
| 505 | int *history; /* list of (depth, state-id) tuples */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 506 | int nbHistory; |
| 507 | int sizeHistory; |
| 508 | xmlSchemaIDCMatcherPtr matcher; /* the correspondent field/selector |
| 509 | matcher */ |
| 510 | xmlSchemaIDCSelectPtr sel; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 511 | void *xpathCtxt; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 512 | }; |
| 513 | |
| 514 | #define IDC_MATCHER 0 |
| 515 | |
| 516 | /** |
| 517 | * xmlSchemaIDCMatcher: |
| 518 | * |
| 519 | * Used to IDC selectors (and fields) successively. |
| 520 | */ |
| 521 | struct _xmlSchemaIDCMatcher { |
| 522 | int type; |
| 523 | int depth; /* the tree depth at creation time */ |
| 524 | xmlSchemaIDCMatcherPtr next; /* next in the list */ |
| 525 | xmlSchemaIDCAugPtr aidc; /* the augmented IDC item */ |
| 526 | xmlSchemaPSVIIDCKeyPtr **keySeqs; /* the key-sequences of the target |
| 527 | elements */ |
| 528 | int sizeKeySeqs; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 529 | int targetDepth; |
| 530 | }; |
| 531 | |
| 532 | /* |
| 533 | * Element info flags. |
| 534 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 535 | #define XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES 1<<0 |
| 536 | #define XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES 1<<1 |
| 537 | #define XML_SCHEMA_ELEM_INFO_NILLED 1<<2 |
| 538 | #define XML_SCHEMA_ELEM_INFO_LOCAL_TYPE 1<<3 |
| 539 | |
| 540 | #define XML_SCHEMA_NODE_INFO_VALUE_NEEDED 1<<4 |
| 541 | #define XML_SCHEMA_ELEM_INFO_EMPTY 1<<5 |
| 542 | #define XML_SCHEMA_ELEM_INFO_HAS_CONTENT 1<<6 |
| 543 | |
| 544 | #define XML_SCHEMA_ELEM_INFO_HAS_ELEM_CONTENT 1<<7 |
| 545 | #define XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT 1<<8 |
| 546 | #define XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED 1<<9 |
| 547 | #define XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE 1<<10 |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 548 | |
| 549 | /** |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 550 | * xmlSchemaNodeInfo: |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 551 | * |
| 552 | * Holds information of an element node. |
| 553 | */ |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 554 | struct _xmlSchemaNodeInfo { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 555 | xmlNodePtr node; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 556 | int nodeType; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 557 | const xmlChar *localName; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 558 | const xmlChar *nsName; |
| 559 | const xmlChar *value; |
| 560 | xmlSchemaValPtr val; /* the pre-computed value if any */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 561 | xmlSchemaTypePtr typeDef; /* the complex/simple type definition if any */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 562 | int flags; /* combination of node info flags */ |
| 563 | int valNeeded; |
| 564 | int normVal; |
| 565 | |
| 566 | xmlSchemaElementPtr decl; /* the element/attribute declaration */ |
| 567 | int depth; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 568 | xmlSchemaPSVIIDCBindingPtr idcTable; /* the table of PSVI IDC bindings |
| 569 | for the scope element*/ |
| 570 | xmlSchemaIDCMatcherPtr idcMatchers; /* the IDC matchers for the scope |
| 571 | element */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 572 | xmlRegExecCtxtPtr regexCtxt; |
| 573 | |
| 574 | const xmlChar **nsBindings; /* Namespace bindings on this element */ |
| 575 | int nbNsBindings; |
| 576 | int sizeNsBindings; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 577 | }; |
| 578 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 579 | /* |
| 580 | * @metaType values of xmlSchemaAttrInfo. |
| 581 | */ |
| 582 | #define XML_SCHEMA_ATTR_INFO_META_XSI_TYPE 1 |
| 583 | #define XML_SCHEMA_ATTR_INFO_META_XSI_NIL 2 |
| 584 | #define XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC 3 |
| 585 | #define XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC 4 |
| 586 | #define XML_SCHEMA_ATTR_INFO_META_XMLNS 5 |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 587 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 588 | typedef struct _xmlSchemaAttrInfo xmlSchemaAttrInfo; |
| 589 | typedef xmlSchemaAttrInfo *xmlSchemaAttrInfoPtr; |
| 590 | struct _xmlSchemaAttrInfo { |
| 591 | xmlNodePtr node; |
| 592 | int nodeType; |
| 593 | const xmlChar *localName; |
| 594 | const xmlChar *nsName; |
| 595 | const xmlChar *value; |
| 596 | xmlSchemaValPtr val; /* the pre-computed value if any */ |
| 597 | xmlSchemaTypePtr typeDef; /* the complex/simple type definition if any */ |
| 598 | int flags; /* combination of node info flags */ |
| 599 | |
| 600 | xmlSchemaAttributePtr decl; /* the attribute declaration */ |
| 601 | xmlSchemaAttributePtr use; /* the attribute use */ |
| 602 | int state; |
| 603 | int metaType; |
| 604 | const xmlChar *vcValue; /* the value constraint value */ |
| 605 | xmlSchemaNodeInfoPtr parent; |
| 606 | }; |
| 607 | |
| 608 | |
| 609 | #define XML_SCHEMA_VALID_CTXT_FLAG_STREAM 1 |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 610 | /** |
| 611 | * xmlSchemaValidCtxt: |
| 612 | * |
| 613 | * A Schemas validation context |
| 614 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 615 | struct _xmlSchemaValidCtxt { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 616 | int type; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 617 | void *userData; /* user specific data block */ |
| 618 | xmlSchemaValidityErrorFunc error; /* the callback in case of errors */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 619 | xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */ |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 620 | xmlStructuredErrorFunc serror; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 621 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 622 | xmlSchemaPtr schema; /* The schema in use */ |
| 623 | xmlDocPtr doc; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 624 | xmlParserInputBufferPtr input; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 625 | xmlCharEncoding enc; |
| 626 | xmlSAXHandlerPtr sax; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 627 | xmlParserCtxtPtr parserCtxt; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 628 | void *user_data; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 629 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 630 | int err; |
| 631 | int nberrors; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 632 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 633 | xmlNodePtr node; |
| 634 | xmlNodePtr cur; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 635 | /* xmlSchemaTypePtr type; */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 636 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 637 | xmlRegExecCtxtPtr regexp; |
| 638 | xmlSchemaValPtr value; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 639 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 640 | int valueWS; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 641 | int options; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 642 | xmlNodePtr validationRoot; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 643 | xmlSchemaParserCtxtPtr pctxt; |
| 644 | int xsiAssemble; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 645 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 646 | int depth; |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 647 | xmlSchemaNodeInfoPtr *elemInfos; /* array of element informations */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 648 | int sizeElemInfos; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 649 | xmlSchemaNodeInfoPtr inode; /* the current element information */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 650 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 651 | xmlSchemaIDCAugPtr aidcs; /* a list of augmented IDC informations */ |
| 652 | |
| 653 | xmlSchemaIDCStateObjPtr xpathStates; /* first active state object. */ |
| 654 | xmlSchemaIDCStateObjPtr xpathStatePool; /* first stored state object. */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 655 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 656 | xmlSchemaPSVIIDCNodePtr *idcNodes; /* list of all IDC node-table entries*/ |
| 657 | int nbIdcNodes; |
| 658 | int sizeIdcNodes; |
| 659 | |
| 660 | xmlSchemaPSVIIDCKeyPtr *idcKeys; /* list of all IDC node-table entries */ |
| 661 | int nbIdcKeys; |
| 662 | int sizeIdcKeys; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 663 | |
| 664 | int flags; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 665 | |
| 666 | xmlDictPtr dict; |
| 667 | |
Daniel Veillard | 39e5c89 | 2005-07-03 22:48:50 +0000 | [diff] [blame] | 668 | #ifdef LIBXML_READER_ENABLED |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 669 | xmlTextReaderPtr reader; |
Daniel Veillard | 39e5c89 | 2005-07-03 22:48:50 +0000 | [diff] [blame] | 670 | #endif |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 671 | |
| 672 | xmlSchemaAttrInfoPtr *attrInfos; |
| 673 | int nbAttrInfos; |
| 674 | int sizeAttrInfos; |
| 675 | |
| 676 | int skipDepth; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 677 | }; |
| 678 | |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 679 | /* |
| 680 | * These are the entries in the schemas importSchemas hash table |
| 681 | */ |
| 682 | typedef struct _xmlSchemaImport xmlSchemaImport; |
| 683 | typedef xmlSchemaImport *xmlSchemaImportPtr; |
| 684 | struct _xmlSchemaImport { |
| 685 | const xmlChar *schemaLocation; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 686 | xmlSchemaPtr schema; /* not used any more */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 687 | xmlDocPtr doc; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 688 | int isMain; |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 689 | }; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 690 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 691 | /* |
| 692 | * These are the entries associated to includes in a schemas |
| 693 | */ |
| 694 | typedef struct _xmlSchemaInclude xmlSchemaInclude; |
| 695 | typedef xmlSchemaInclude *xmlSchemaIncludePtr; |
| 696 | struct _xmlSchemaInclude { |
| 697 | xmlSchemaIncludePtr next; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 698 | const xmlChar *schemaLocation; |
| 699 | xmlDocPtr doc; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 700 | const xmlChar *origTargetNamespace; |
| 701 | const xmlChar *targetNamespace; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 702 | }; |
| 703 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 704 | /** |
| 705 | * xmlSchemaSubstGroup: |
| 706 | * |
| 707 | * |
| 708 | */ |
| 709 | typedef struct _xmlSchemaSubstGroup xmlSchemaSubstGroup; |
| 710 | typedef xmlSchemaSubstGroup *xmlSchemaSubstGroupPtr; |
| 711 | struct _xmlSchemaSubstGroup { |
| 712 | xmlSchemaElementPtr head; |
| 713 | xmlSchemaItemListPtr members; |
| 714 | }; |
| 715 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 716 | /************************************************************************ |
| 717 | * * |
| 718 | * Some predeclarations * |
| 719 | * * |
| 720 | ************************************************************************/ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 721 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 722 | static int xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt, |
| 723 | xmlSchemaPtr schema, |
| 724 | xmlNodePtr node); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 725 | static void |
| 726 | xmlSchemaTypeFixup(xmlSchemaTypePtr typeDecl, |
| 727 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name); |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 728 | static const xmlChar * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 729 | xmlSchemaFacetTypeToString(xmlSchemaTypeType type); |
| 730 | static int |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 731 | xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 732 | xmlNodePtr node); |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 733 | static void |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 734 | xmlSchemaCheckFacetValues(xmlSchemaTypePtr typeDecl, |
| 735 | xmlSchemaParserCtxtPtr ctxt); |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 736 | static void |
| 737 | xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 738 | static xmlSchemaWhitespaceValueType |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 739 | xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 740 | static xmlSchemaTreeItemPtr |
| 741 | xmlSchemaParseModelGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 742 | xmlNodePtr node, xmlSchemaTypeType type, |
| 743 | int withParticle); |
| 744 | static const xmlChar * |
| 745 | xmlSchemaCompTypeToString(xmlSchemaTypeType type); |
| 746 | static xmlSchemaTypeLinkPtr |
| 747 | xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 748 | static void |
| 749 | xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt, |
| 750 | const char *funcName, |
| 751 | const char *message); |
| 752 | static int |
| 753 | xmlSchemaCheckCOSSTDerivedOK(xmlSchemaTypePtr type, |
| 754 | xmlSchemaTypePtr baseType, |
| 755 | int subset); |
| 756 | static void |
| 757 | xmlSchemaCheckElementDeclComponent(xmlSchemaElementPtr elemDecl, |
| 758 | xmlSchemaParserCtxtPtr ctxt, |
| 759 | const xmlChar * name ATTRIBUTE_UNUSED); |
William M. Brack | 87640d5 | 2004-04-17 14:58:15 +0000 | [diff] [blame] | 760 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 761 | /************************************************************************ |
| 762 | * * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 763 | * Helper functions * |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 764 | * * |
| 765 | ************************************************************************/ |
| 766 | |
| 767 | /** |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 768 | * xmlSchemaCompTypeToString: |
| 769 | * @type: the type of the schema item |
| 770 | * |
| 771 | * Returns the component name of a schema item. |
| 772 | */ |
| 773 | static const xmlChar * |
| 774 | xmlSchemaCompTypeToString(xmlSchemaTypeType type) |
| 775 | { |
| 776 | switch (type) { |
| 777 | case XML_SCHEMA_TYPE_SIMPLE: |
| 778 | return(BAD_CAST "simple type definition"); |
| 779 | case XML_SCHEMA_TYPE_COMPLEX: |
| 780 | return(BAD_CAST "complex type definition"); |
| 781 | case XML_SCHEMA_TYPE_ELEMENT: |
| 782 | return(BAD_CAST "element declaration"); |
| 783 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 784 | return(BAD_CAST "attribute declaration"); |
| 785 | case XML_SCHEMA_TYPE_GROUP: |
| 786 | return(BAD_CAST "model group definition"); |
| 787 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
| 788 | return(BAD_CAST "attribute group definition"); |
| 789 | case XML_SCHEMA_TYPE_NOTATION: |
| 790 | return(BAD_CAST "notation declaration"); |
| 791 | case XML_SCHEMA_TYPE_SEQUENCE: |
| 792 | return(BAD_CAST "model group (sequence)"); |
| 793 | case XML_SCHEMA_TYPE_CHOICE: |
| 794 | return(BAD_CAST "model group (choice)"); |
| 795 | case XML_SCHEMA_TYPE_ALL: |
| 796 | return(BAD_CAST "model group (all)"); |
| 797 | case XML_SCHEMA_TYPE_PARTICLE: |
| 798 | return(BAD_CAST "particle"); |
| 799 | default: |
| 800 | return(BAD_CAST "Not a schema component"); |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | /** |
| 805 | * xmlSchemaGetComponentNode: |
| 806 | * @item: a schema component |
| 807 | * |
| 808 | * Returns node associated with the schema component. |
| 809 | * NOTE that such a node need not be available; plus, a component's |
| 810 | * node need not to reflect the component directly, since there is no |
| 811 | * one-to-one relationship between the XML Schema representation and |
| 812 | * the component representation. |
| 813 | */ |
| 814 | static xmlNodePtr |
| 815 | xmlSchemaGetComponentNode(xmlSchemaBasicItemPtr item) |
| 816 | { |
| 817 | switch (item->type) { |
| 818 | case XML_SCHEMA_TYPE_ELEMENT: |
| 819 | return (((xmlSchemaElementPtr) item)->node); |
| 820 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 821 | return (((xmlSchemaAttributePtr) item)->node); |
| 822 | case XML_SCHEMA_TYPE_COMPLEX: |
| 823 | case XML_SCHEMA_TYPE_SIMPLE: |
| 824 | return (((xmlSchemaTypePtr) item)->node); |
| 825 | case XML_SCHEMA_TYPE_ANY: |
| 826 | case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: |
| 827 | return (((xmlSchemaWildcardPtr) item)->node); |
| 828 | case XML_SCHEMA_TYPE_PARTICLE: |
| 829 | return (((xmlSchemaParticlePtr) item)->node); |
| 830 | case XML_SCHEMA_TYPE_SEQUENCE: |
| 831 | case XML_SCHEMA_TYPE_CHOICE: |
| 832 | case XML_SCHEMA_TYPE_ALL: |
| 833 | return (((xmlSchemaModelGroupPtr) item)->node); |
| 834 | case XML_SCHEMA_TYPE_GROUP: |
| 835 | return (((xmlSchemaModelGroupDefPtr) item)->node); |
| 836 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
| 837 | return (((xmlSchemaAttributeGroupPtr) item)->node); |
| 838 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
| 839 | case XML_SCHEMA_TYPE_IDC_KEY: |
| 840 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
| 841 | return (((xmlSchemaIDCPtr) item)->node); |
| 842 | default: |
| 843 | return (NULL); |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | #if 0 |
| 848 | /** |
| 849 | * xmlSchemaGetNextComponent: |
| 850 | * @item: a schema component |
| 851 | * |
| 852 | * Returns the next sibling of the schema component. |
| 853 | */ |
| 854 | static xmlSchemaBasicItemPtr |
| 855 | xmlSchemaGetNextComponent(xmlSchemaBasicItemPtr item) |
| 856 | { |
| 857 | switch (item->type) { |
| 858 | case XML_SCHEMA_TYPE_ELEMENT: |
| 859 | return ((xmlSchemaBasicItemPtr) ((xmlSchemaElementPtr) item)->next); |
| 860 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 861 | return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributePtr) item)->next); |
| 862 | case XML_SCHEMA_TYPE_COMPLEX: |
| 863 | case XML_SCHEMA_TYPE_SIMPLE: |
| 864 | return ((xmlSchemaBasicItemPtr) ((xmlSchemaTypePtr) item)->next); |
| 865 | case XML_SCHEMA_TYPE_ANY: |
| 866 | case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: |
| 867 | return (NULL); |
| 868 | case XML_SCHEMA_TYPE_PARTICLE: |
| 869 | return ((xmlSchemaBasicItemPtr) ((xmlSchemaParticlePtr) item)->next); |
| 870 | case XML_SCHEMA_TYPE_SEQUENCE: |
| 871 | case XML_SCHEMA_TYPE_CHOICE: |
| 872 | case XML_SCHEMA_TYPE_ALL: |
| 873 | return (NULL); |
| 874 | case XML_SCHEMA_TYPE_GROUP: |
| 875 | return (NULL); |
| 876 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
| 877 | return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributeGroupPtr) item)->next); |
| 878 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
| 879 | case XML_SCHEMA_TYPE_IDC_KEY: |
| 880 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
| 881 | return ((xmlSchemaBasicItemPtr) ((xmlSchemaIDCPtr) item)->next); |
| 882 | default: |
| 883 | return (NULL); |
| 884 | } |
| 885 | } |
| 886 | #endif |
| 887 | |
| 888 | /** |
| 889 | * xmlSchemaGetAttrName: |
| 890 | * @attr: the attribute declaration/use |
| 891 | * |
| 892 | * Returns the name of the attribute; if the attribute |
| 893 | * is a reference, the name of the referenced global type will be returned. |
| 894 | */ |
| 895 | static const xmlChar * |
| 896 | xmlSchemaGetAttrName(xmlSchemaAttributePtr attr) |
| 897 | { |
| 898 | if (attr->ref != NULL) |
| 899 | return(attr->ref); |
| 900 | else |
| 901 | return(attr->name); |
| 902 | } |
| 903 | |
| 904 | /** |
| 905 | * xmlSchemaGetAttrTargetNsURI: |
| 906 | * @type: the type (element or attribute) |
| 907 | * |
| 908 | * Returns the target namespace URI of the type; if the type is a reference, |
| 909 | * the target namespace of the referenced type will be returned. |
| 910 | */ |
| 911 | static const xmlChar * |
| 912 | xmlSchemaGetAttrTargetNsURI(xmlSchemaAttributePtr attr) |
| 913 | { |
| 914 | if (attr->ref != NULL) |
| 915 | return (attr->refNs); |
| 916 | else |
| 917 | return(attr->targetNamespace); |
| 918 | } |
| 919 | |
| 920 | /** |
| 921 | * xmlSchemaFormatQName: |
| 922 | * @buf: the string buffer |
| 923 | * @namespaceName: the namespace name |
| 924 | * @localName: the local name |
| 925 | * |
| 926 | * Returns the given QName in the format "{namespaceName}localName" or |
| 927 | * just "localName" if @namespaceName is NULL. |
| 928 | * |
| 929 | * Returns the localName if @namespaceName is NULL, a formatted |
| 930 | * string otherwise. |
| 931 | */ |
| 932 | static const xmlChar* |
| 933 | xmlSchemaFormatQName(xmlChar **buf, |
| 934 | const xmlChar *namespaceName, |
| 935 | const xmlChar *localName) |
| 936 | { |
| 937 | FREE_AND_NULL(*buf) |
| 938 | if (namespaceName == NULL) |
| 939 | return(localName); |
| 940 | |
| 941 | *buf = xmlStrdup(BAD_CAST "{"); |
| 942 | *buf = xmlStrcat(*buf, namespaceName); |
| 943 | *buf = xmlStrcat(*buf, BAD_CAST "}"); |
| 944 | *buf = xmlStrcat(*buf, localName); |
| 945 | |
| 946 | return ((const xmlChar *) *buf); |
| 947 | } |
| 948 | |
| 949 | static const xmlChar* |
| 950 | xmlSchemaFormatQNameNs(xmlChar **buf, xmlNsPtr ns, const xmlChar *localName) |
| 951 | { |
| 952 | if (ns != NULL) |
| 953 | return (xmlSchemaFormatQName(buf, ns->href, localName)); |
| 954 | else |
| 955 | return (xmlSchemaFormatQName(buf, NULL, localName)); |
| 956 | } |
| 957 | |
| 958 | static const xmlChar * |
| 959 | xmlSchemaGetComponentName(xmlSchemaBasicItemPtr item) |
| 960 | { |
| 961 | switch (item->type) { |
| 962 | case XML_SCHEMA_TYPE_ELEMENT: |
| 963 | return (((xmlSchemaElementPtr) item)->name); |
| 964 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 965 | return (((xmlSchemaAttributePtr) item)->name); |
| 966 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
| 967 | return (((xmlSchemaAttributeGroupPtr) item)->name); |
| 968 | case XML_SCHEMA_TYPE_BASIC: |
| 969 | case XML_SCHEMA_TYPE_SIMPLE: |
| 970 | case XML_SCHEMA_TYPE_COMPLEX: |
| 971 | return (((xmlSchemaTypePtr) item)->name); |
| 972 | case XML_SCHEMA_TYPE_GROUP: |
| 973 | return (((xmlSchemaModelGroupDefPtr) item)->name); |
| 974 | case XML_SCHEMA_TYPE_IDC_KEY: |
| 975 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
| 976 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
| 977 | return (((xmlSchemaIDCPtr) item)->name); |
| 978 | default: |
| 979 | /* |
| 980 | * Other components cannot have names. |
| 981 | */ |
| 982 | break; |
| 983 | } |
| 984 | return (NULL); |
| 985 | } |
| 986 | |
| 987 | static const xmlChar * |
| 988 | xmlSchemaGetComponentTargetNs(xmlSchemaBasicItemPtr item) |
| 989 | { |
| 990 | switch (item->type) { |
| 991 | case XML_SCHEMA_TYPE_ELEMENT: |
| 992 | return (((xmlSchemaElementPtr) item)->targetNamespace); |
| 993 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 994 | return (((xmlSchemaAttributePtr) item)->targetNamespace); |
| 995 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
| 996 | return (((xmlSchemaAttributeGroupPtr) item)->targetNamespace); |
| 997 | case XML_SCHEMA_TYPE_BASIC: |
| 998 | return (BAD_CAST "http://www.w3.org/2001/XMLSchema"); |
| 999 | case XML_SCHEMA_TYPE_SIMPLE: |
| 1000 | case XML_SCHEMA_TYPE_COMPLEX: |
| 1001 | return (((xmlSchemaTypePtr) item)->targetNamespace); |
| 1002 | case XML_SCHEMA_TYPE_GROUP: |
| 1003 | return (((xmlSchemaModelGroupDefPtr) item)->targetNamespace); |
| 1004 | case XML_SCHEMA_TYPE_IDC_KEY: |
| 1005 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
| 1006 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
| 1007 | return (((xmlSchemaIDCPtr) item)->targetNamespace); |
| 1008 | default: |
| 1009 | /* |
| 1010 | * Other components cannot have names. |
| 1011 | */ |
| 1012 | break; |
| 1013 | } |
| 1014 | return (NULL); |
| 1015 | } |
| 1016 | |
| 1017 | static const xmlChar* |
| 1018 | xmlSchemaGetComponentQName(xmlChar **buf, |
| 1019 | void *item) |
| 1020 | { |
| 1021 | return (xmlSchemaFormatQName(buf, |
| 1022 | xmlSchemaGetComponentTargetNs((xmlSchemaBasicItemPtr) item), |
| 1023 | xmlSchemaGetComponentName((xmlSchemaBasicItemPtr) item))); |
| 1024 | } |
| 1025 | |
| 1026 | /** |
| 1027 | * xmlSchemaWildcardPCToString: |
| 1028 | * @pc: the type of processContents |
| 1029 | * |
| 1030 | * Returns a string representation of the type of |
| 1031 | * processContents. |
| 1032 | */ |
| 1033 | static const xmlChar * |
| 1034 | xmlSchemaWildcardPCToString(int pc) |
| 1035 | { |
| 1036 | switch (pc) { |
| 1037 | case XML_SCHEMAS_ANY_SKIP: |
| 1038 | return (BAD_CAST "skip"); |
| 1039 | case XML_SCHEMAS_ANY_LAX: |
| 1040 | return (BAD_CAST "lax"); |
| 1041 | case XML_SCHEMAS_ANY_STRICT: |
| 1042 | return (BAD_CAST "strict"); |
| 1043 | default: |
| 1044 | return (BAD_CAST "invalid process contents"); |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | /** |
| 1049 | * xmlSchemaGetCanonValueWhtspExt: |
| 1050 | * @val: the precomputed value |
| 1051 | * @retValue: the returned value |
| 1052 | * @ws: the whitespace type of the value |
| 1053 | * |
| 1054 | * Get a the cononical representation of the value. |
| 1055 | * The caller has to free the returned retValue. |
| 1056 | * |
| 1057 | * Returns 0 if the value could be built and -1 in case of |
| 1058 | * API errors or if the value type is not supported yet. |
| 1059 | */ |
| 1060 | static int |
| 1061 | xmlSchemaGetCanonValueWhtspExt(xmlSchemaValPtr val, |
| 1062 | xmlSchemaWhitespaceValueType ws, |
| 1063 | xmlChar **retValue) |
| 1064 | { |
| 1065 | int list; |
| 1066 | xmlSchemaValType valType; |
| 1067 | const xmlChar *value, *value2 = NULL; |
| 1068 | |
| 1069 | |
| 1070 | if ((retValue == NULL) || (val == NULL)) |
| 1071 | return (-1); |
| 1072 | list = xmlSchemaValueGetNext(val) ? 1 : 0; |
| 1073 | *retValue = NULL; |
| 1074 | do { |
| 1075 | value = NULL; |
| 1076 | valType = xmlSchemaGetValType(val); |
| 1077 | switch (valType) { |
| 1078 | case XML_SCHEMAS_STRING: |
| 1079 | case XML_SCHEMAS_NORMSTRING: |
| 1080 | case XML_SCHEMAS_ANYSIMPLETYPE: |
| 1081 | value = xmlSchemaValueGetAsString(val); |
| 1082 | if (value != NULL) { |
| 1083 | if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE) |
| 1084 | value2 = xmlSchemaCollapseString(value); |
| 1085 | else if (ws == XML_SCHEMA_WHITESPACE_REPLACE) |
| 1086 | value2 = xmlSchemaWhiteSpaceReplace(value); |
| 1087 | if (value2 != NULL) |
| 1088 | value = value2; |
| 1089 | } |
| 1090 | break; |
| 1091 | default: |
| 1092 | if (xmlSchemaGetCanonValue(val, &value2) == -1) { |
| 1093 | if (value2 != NULL) |
| 1094 | xmlFree((xmlChar *) value2); |
| 1095 | goto internal_error; |
| 1096 | } |
| 1097 | value = value2; |
| 1098 | } |
| 1099 | if (*retValue == NULL) |
| 1100 | if (value == NULL) { |
| 1101 | if (! list) |
| 1102 | *retValue = xmlStrdup(BAD_CAST ""); |
| 1103 | } else |
| 1104 | *retValue = xmlStrdup(value); |
| 1105 | else if (value != NULL) { |
| 1106 | /* List. */ |
| 1107 | *retValue = xmlStrcat((xmlChar *) *retValue, BAD_CAST " "); |
| 1108 | *retValue = xmlStrcat((xmlChar *) *retValue, value); |
| 1109 | } |
| 1110 | FREE_AND_NULL(value2) |
| 1111 | val = xmlSchemaValueGetNext(val); |
| 1112 | } while (val != NULL); |
| 1113 | |
| 1114 | return (0); |
| 1115 | internal_error: |
| 1116 | if (*retValue != NULL) |
| 1117 | xmlFree((xmlChar *) (*retValue)); |
| 1118 | if (value2 != NULL) |
| 1119 | xmlFree((xmlChar *) value2); |
| 1120 | return (-1); |
| 1121 | } |
| 1122 | |
| 1123 | /** |
| 1124 | * xmlSchemaFormatItemForReport: |
| 1125 | * @buf: the string buffer |
| 1126 | * @itemDes: the designation of the item |
| 1127 | * @itemName: the name of the item |
| 1128 | * @item: the item as an object |
| 1129 | * @itemNode: the node of the item |
| 1130 | * @local: the local name |
| 1131 | * @parsing: if the function is used during the parse |
| 1132 | * |
| 1133 | * Returns a representation of the given item used |
| 1134 | * for error reports. |
| 1135 | * |
| 1136 | * The following order is used to build the resulting |
| 1137 | * designation if the arguments are not NULL: |
| 1138 | * 1a. If itemDes not NULL -> itemDes |
| 1139 | * 1b. If (itemDes not NULL) and (itemName not NULL) |
| 1140 | * -> itemDes + itemName |
| 1141 | * 2. If the preceding was NULL and (item not NULL) -> item |
| 1142 | * 3. If the preceding was NULL and (itemNode not NULL) -> itemNode |
| 1143 | * |
| 1144 | * If the itemNode is an attribute node, the name of the attribute |
| 1145 | * will be appended to the result. |
| 1146 | * |
| 1147 | * Returns the formatted string and sets @buf to the resulting value. |
| 1148 | */ |
| 1149 | static xmlChar* |
| 1150 | xmlSchemaFormatItemForReport(xmlChar **buf, |
| 1151 | const xmlChar *itemDes, |
| 1152 | xmlSchemaTypePtr item, |
| 1153 | xmlNodePtr itemNode) |
| 1154 | { |
| 1155 | xmlChar *str = NULL; |
| 1156 | int named = 1; |
| 1157 | |
| 1158 | if (*buf != NULL) { |
| 1159 | xmlFree(*buf); |
| 1160 | *buf = NULL; |
| 1161 | } |
| 1162 | |
| 1163 | if (itemDes != NULL) { |
| 1164 | *buf = xmlStrdup(itemDes); |
| 1165 | } else if (item != NULL) { |
| 1166 | switch (item->type) { |
| 1167 | case XML_SCHEMA_TYPE_BASIC: |
| 1168 | if (VARIETY_ATOMIC(item)) |
| 1169 | *buf = xmlStrdup(BAD_CAST "atomic type 'xs:"); |
| 1170 | else if (VARIETY_LIST(item)) |
| 1171 | *buf = xmlStrdup(BAD_CAST "list type 'xs:"); |
| 1172 | else if (VARIETY_UNION(item)) |
| 1173 | *buf = xmlStrdup(BAD_CAST "union type 'xs:"); |
| 1174 | else |
| 1175 | *buf = xmlStrdup(BAD_CAST "simple type 'xs:"); |
| 1176 | *buf = xmlStrcat(*buf, item->name); |
| 1177 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1178 | break; |
| 1179 | case XML_SCHEMA_TYPE_SIMPLE: |
| 1180 | if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) { |
| 1181 | *buf = xmlStrdup(BAD_CAST""); |
| 1182 | } else { |
| 1183 | *buf = xmlStrdup(BAD_CAST "local "); |
| 1184 | } |
| 1185 | if (VARIETY_ATOMIC(item)) |
| 1186 | *buf = xmlStrcat(*buf, BAD_CAST "atomic type"); |
| 1187 | else if (VARIETY_LIST(item)) |
| 1188 | *buf = xmlStrcat(*buf, BAD_CAST "list type"); |
| 1189 | else if (VARIETY_UNION(item)) |
| 1190 | *buf = xmlStrcat(*buf, BAD_CAST "union type"); |
| 1191 | else |
| 1192 | *buf = xmlStrcat(*buf, BAD_CAST "simple type"); |
| 1193 | if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) { |
| 1194 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1195 | *buf = xmlStrcat(*buf, item->name); |
| 1196 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1197 | } |
| 1198 | break; |
| 1199 | case XML_SCHEMA_TYPE_COMPLEX: |
| 1200 | if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) |
| 1201 | *buf = xmlStrdup(BAD_CAST ""); |
| 1202 | else |
| 1203 | *buf = xmlStrdup(BAD_CAST "local "); |
| 1204 | *buf = xmlStrcat(*buf, BAD_CAST "complex type"); |
| 1205 | if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) { |
| 1206 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1207 | *buf = xmlStrcat(*buf, item->name); |
| 1208 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1209 | } |
| 1210 | break; |
| 1211 | case XML_SCHEMA_TYPE_ATTRIBUTE: { |
| 1212 | xmlSchemaAttributePtr attr; |
| 1213 | |
| 1214 | attr = (xmlSchemaAttributePtr) item; |
| 1215 | if ((attr->flags & XML_SCHEMAS_ATTR_GLOBAL) || |
| 1216 | (attr->ref == NULL)) { |
| 1217 | *buf = xmlStrdup(xmlSchemaElemDesAttrDecl); |
| 1218 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1219 | *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str, |
| 1220 | attr->targetNamespace, attr->name)); |
| 1221 | FREE_AND_NULL(str) |
| 1222 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1223 | } else { |
| 1224 | *buf = xmlStrdup(xmlSchemaElemDesAttrRef); |
| 1225 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1226 | *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str, |
| 1227 | attr->refNs, attr->ref)); |
| 1228 | FREE_AND_NULL(str) |
| 1229 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1230 | } |
| 1231 | } |
| 1232 | break; |
| 1233 | case XML_SCHEMA_TYPE_ELEMENT: { |
| 1234 | xmlSchemaElementPtr elem; |
| 1235 | |
| 1236 | elem = (xmlSchemaElementPtr) item; |
| 1237 | if ((elem->flags & XML_SCHEMAS_ELEM_GLOBAL) || |
| 1238 | (elem->ref == NULL)) { |
| 1239 | *buf = xmlStrdup(xmlSchemaElemDesElemDecl); |
| 1240 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1241 | *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str, |
| 1242 | elem->targetNamespace, elem->name)); |
| 1243 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1244 | } |
| 1245 | } |
| 1246 | break; |
| 1247 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
| 1248 | case XML_SCHEMA_TYPE_IDC_KEY: |
| 1249 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
| 1250 | if (item->type == XML_SCHEMA_TYPE_IDC_UNIQUE) |
| 1251 | *buf = xmlStrdup(BAD_CAST "unique '"); |
| 1252 | else if (item->type == XML_SCHEMA_TYPE_IDC_KEY) |
| 1253 | *buf = xmlStrdup(BAD_CAST "key '"); |
| 1254 | else |
| 1255 | *buf = xmlStrdup(BAD_CAST "keyRef '"); |
| 1256 | *buf = xmlStrcat(*buf, ((xmlSchemaIDCPtr) item)->name); |
| 1257 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1258 | break; |
| 1259 | case XML_SCHEMA_TYPE_ANY: |
| 1260 | case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: |
| 1261 | *buf = xmlStrdup(xmlSchemaWildcardPCToString( |
| 1262 | ((xmlSchemaWildcardPtr) item)->processContents)); |
| 1263 | *buf = xmlStrcat(*buf, BAD_CAST " wildcard"); |
| 1264 | break; |
| 1265 | case XML_SCHEMA_FACET_MININCLUSIVE: |
| 1266 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
| 1267 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
| 1268 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
| 1269 | case XML_SCHEMA_FACET_TOTALDIGITS: |
| 1270 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
| 1271 | case XML_SCHEMA_FACET_PATTERN: |
| 1272 | case XML_SCHEMA_FACET_ENUMERATION: |
| 1273 | case XML_SCHEMA_FACET_WHITESPACE: |
| 1274 | case XML_SCHEMA_FACET_LENGTH: |
| 1275 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 1276 | case XML_SCHEMA_FACET_MINLENGTH: |
| 1277 | *buf = xmlStrdup(BAD_CAST "facet '"); |
| 1278 | *buf = xmlStrcat(*buf, xmlSchemaFacetTypeToString(item->type)); |
| 1279 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1280 | break; |
| 1281 | case XML_SCHEMA_TYPE_NOTATION: |
| 1282 | *buf = xmlStrdup(BAD_CAST "notation"); |
| 1283 | break; |
| 1284 | case XML_SCHEMA_TYPE_GROUP: { |
| 1285 | *buf = xmlStrdup(xmlSchemaElemModelGrDef); |
| 1286 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1287 | *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str, |
| 1288 | ((xmlSchemaModelGroupDefPtr) item)->targetNamespace, |
| 1289 | ((xmlSchemaModelGroupDefPtr) item)->name)); |
| 1290 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1291 | FREE_AND_NULL(str) |
| 1292 | } |
| 1293 | break; |
| 1294 | case XML_SCHEMA_TYPE_SEQUENCE: |
| 1295 | case XML_SCHEMA_TYPE_CHOICE: |
| 1296 | case XML_SCHEMA_TYPE_ALL: |
| 1297 | case XML_SCHEMA_TYPE_PARTICLE: |
| 1298 | *buf = xmlStrdup(xmlSchemaCompTypeToString(item->type)); |
| 1299 | break; |
| 1300 | default: |
| 1301 | named = 0; |
| 1302 | } |
| 1303 | } else |
| 1304 | named = 0; |
| 1305 | |
| 1306 | if ((named == 0) && (itemNode != NULL)) { |
| 1307 | xmlNodePtr elem; |
| 1308 | |
| 1309 | if (itemNode->type == XML_ATTRIBUTE_NODE) |
| 1310 | elem = itemNode->parent; |
| 1311 | else |
| 1312 | elem = itemNode; |
| 1313 | *buf = xmlStrdup(BAD_CAST "Element '"); |
| 1314 | if (elem->ns != NULL) { |
| 1315 | *buf = xmlStrcat(*buf, |
| 1316 | xmlSchemaFormatQName(&str, elem->ns->href, elem->name)); |
| 1317 | FREE_AND_NULL(str) |
| 1318 | } else |
| 1319 | *buf = xmlStrcat(*buf, elem->name); |
| 1320 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1321 | |
| 1322 | } |
| 1323 | if ((itemNode != NULL) && (itemNode->type == XML_ATTRIBUTE_NODE)) { |
| 1324 | *buf = xmlStrcat(*buf, BAD_CAST ", attribute '"); |
| 1325 | if (itemNode->ns != NULL) { |
| 1326 | *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str, |
| 1327 | itemNode->ns->href, itemNode->name)); |
| 1328 | FREE_AND_NULL(str) |
| 1329 | } else |
| 1330 | *buf = xmlStrcat(*buf, itemNode->name); |
| 1331 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1332 | } |
| 1333 | FREE_AND_NULL(str) |
| 1334 | |
| 1335 | return (*buf); |
| 1336 | } |
| 1337 | |
| 1338 | /** |
| 1339 | * xmlSchemaFormatFacetEnumSet: |
| 1340 | * @buf: the string buffer |
| 1341 | * @type: the type holding the enumeration facets |
| 1342 | * |
| 1343 | * Builds a string consisting of all enumeration elements. |
| 1344 | * |
| 1345 | * Returns a string of all enumeration elements. |
| 1346 | */ |
| 1347 | static const xmlChar * |
| 1348 | xmlSchemaFormatFacetEnumSet(xmlSchemaAbstractCtxtPtr actxt, |
| 1349 | xmlChar **buf, xmlSchemaTypePtr type) |
| 1350 | { |
| 1351 | xmlSchemaFacetPtr facet; |
| 1352 | xmlSchemaWhitespaceValueType ws; |
| 1353 | xmlChar *value = NULL; |
| 1354 | int res; |
| 1355 | |
| 1356 | if (*buf != NULL) |
| 1357 | xmlFree(*buf); |
| 1358 | *buf = NULL; |
| 1359 | |
| 1360 | do { |
| 1361 | /* |
| 1362 | * Use the whitespace type of the base type. |
| 1363 | */ |
| 1364 | ws = xmlSchemaGetWhiteSpaceFacetValue(type->baseType); |
| 1365 | for (facet = type->facets; facet != NULL; facet = facet->next) { |
| 1366 | if (facet->type != XML_SCHEMA_FACET_ENUMERATION) |
| 1367 | continue; |
| 1368 | res = xmlSchemaGetCanonValueWhtspExt(facet->val, |
| 1369 | ws, &value); |
| 1370 | if (res == -1) { |
| 1371 | xmlSchemaInternalErr(actxt, |
| 1372 | "xmlSchemaFormatFacetEnumSet", |
| 1373 | "compute the canonical lexical representation"); |
| 1374 | if (*buf != NULL) |
| 1375 | xmlFree(*buf); |
| 1376 | *buf = NULL; |
| 1377 | return (NULL); |
| 1378 | } |
| 1379 | if (*buf == NULL) |
| 1380 | *buf = xmlStrdup(BAD_CAST "'"); |
| 1381 | else |
| 1382 | *buf = xmlStrcat(*buf, BAD_CAST ", '"); |
| 1383 | *buf = xmlStrcat(*buf, BAD_CAST value); |
| 1384 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1385 | if (value != NULL) { |
| 1386 | xmlFree((xmlChar *)value); |
| 1387 | value = NULL; |
| 1388 | } |
| 1389 | } |
| 1390 | type = type->baseType; |
| 1391 | } while ((type != NULL) && (type->type != XML_SCHEMA_TYPE_BASIC)); |
| 1392 | |
| 1393 | return ((const xmlChar *) *buf); |
| 1394 | } |
| 1395 | |
| 1396 | /************************************************************************ |
| 1397 | * * |
| 1398 | * Error functions * |
| 1399 | * * |
| 1400 | ************************************************************************/ |
| 1401 | |
| 1402 | #if 0 |
| 1403 | static void |
| 1404 | xmlSchemaErrMemory(const char *msg) |
| 1405 | { |
| 1406 | __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, NULL, NULL, |
| 1407 | msg); |
| 1408 | } |
| 1409 | #endif |
| 1410 | |
| 1411 | /** |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 1412 | * xmlSchemaPErrMemory: |
| 1413 | * @node: a context node |
| 1414 | * @extra: extra informations |
| 1415 | * |
| 1416 | * Handle an out of memory condition |
| 1417 | */ |
| 1418 | static void |
| 1419 | xmlSchemaPErrMemory(xmlSchemaParserCtxtPtr ctxt, |
| 1420 | const char *extra, xmlNodePtr node) |
| 1421 | { |
| 1422 | if (ctxt != NULL) |
| 1423 | ctxt->nberrors++; |
| 1424 | __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, node, NULL, |
| 1425 | extra); |
| 1426 | } |
| 1427 | |
| 1428 | /** |
| 1429 | * xmlSchemaPErr: |
| 1430 | * @ctxt: the parsing context |
| 1431 | * @node: the context node |
| 1432 | * @error: the error code |
| 1433 | * @msg: the error message |
| 1434 | * @str1: extra data |
| 1435 | * @str2: extra data |
| 1436 | * |
| 1437 | * Handle a parser error |
| 1438 | */ |
| 1439 | static void |
| 1440 | xmlSchemaPErr(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error, |
| 1441 | const char *msg, const xmlChar * str1, const xmlChar * str2) |
| 1442 | { |
| 1443 | xmlGenericErrorFunc channel = NULL; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 1444 | xmlStructuredErrorFunc schannel = NULL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 1445 | void *data = NULL; |
| 1446 | |
| 1447 | if (ctxt != NULL) { |
| 1448 | ctxt->nberrors++; |
| 1449 | channel = ctxt->error; |
| 1450 | data = ctxt->userData; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 1451 | schannel = ctxt->serror; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 1452 | } |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 1453 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 1454 | error, XML_ERR_ERROR, NULL, 0, |
| 1455 | (const char *) str1, (const char *) str2, NULL, 0, 0, |
| 1456 | msg, str1, str2); |
| 1457 | } |
| 1458 | |
| 1459 | /** |
| 1460 | * xmlSchemaPErr2: |
| 1461 | * @ctxt: the parsing context |
| 1462 | * @node: the context node |
| 1463 | * @node: the current child |
| 1464 | * @error: the error code |
| 1465 | * @msg: the error message |
| 1466 | * @str1: extra data |
| 1467 | * @str2: extra data |
| 1468 | * |
| 1469 | * Handle a parser error |
| 1470 | */ |
| 1471 | static void |
| 1472 | xmlSchemaPErr2(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
| 1473 | xmlNodePtr child, int error, |
| 1474 | const char *msg, const xmlChar * str1, const xmlChar * str2) |
| 1475 | { |
| 1476 | if (child != NULL) |
| 1477 | xmlSchemaPErr(ctxt, child, error, msg, str1, str2); |
| 1478 | else |
| 1479 | xmlSchemaPErr(ctxt, node, error, msg, str1, str2); |
| 1480 | } |
| 1481 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 1482 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 1483 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 1484 | * xmlSchemaPErrExt: |
| 1485 | * @ctxt: the parsing context |
| 1486 | * @node: the context node |
| 1487 | * @error: the error code |
| 1488 | * @strData1: extra data |
| 1489 | * @strData2: extra data |
| 1490 | * @strData3: extra data |
| 1491 | * @msg: the message |
| 1492 | * @str1: extra parameter for the message display |
| 1493 | * @str2: extra parameter for the message display |
| 1494 | * @str3: extra parameter for the message display |
| 1495 | * @str4: extra parameter for the message display |
| 1496 | * @str5: extra parameter for the message display |
| 1497 | * |
| 1498 | * Handle a parser error |
| 1499 | */ |
| 1500 | static void |
| 1501 | xmlSchemaPErrExt(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error, |
| 1502 | const xmlChar * strData1, const xmlChar * strData2, |
| 1503 | const xmlChar * strData3, const char *msg, const xmlChar * str1, |
| 1504 | const xmlChar * str2, const xmlChar * str3, const xmlChar * str4, |
| 1505 | const xmlChar * str5) |
| 1506 | { |
| 1507 | |
| 1508 | xmlGenericErrorFunc channel = NULL; |
| 1509 | xmlStructuredErrorFunc schannel = NULL; |
| 1510 | void *data = NULL; |
| 1511 | |
| 1512 | if (ctxt != NULL) { |
| 1513 | ctxt->nberrors++; |
| 1514 | channel = ctxt->error; |
| 1515 | data = ctxt->userData; |
| 1516 | schannel = ctxt->serror; |
| 1517 | } |
| 1518 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP, |
| 1519 | error, XML_ERR_ERROR, NULL, 0, |
| 1520 | (const char *) strData1, (const char *) strData2, |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 1521 | (const char *) strData3, 0, 0, msg, str1, str2, |
| 1522 | str3, str4, str5); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 1523 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 1524 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1525 | /************************************************************************ |
| 1526 | * * |
| 1527 | * Allround error functions * |
| 1528 | * * |
| 1529 | ************************************************************************/ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 1530 | |
| 1531 | /** |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 1532 | * xmlSchemaVTypeErrMemory: |
| 1533 | * @node: a context node |
| 1534 | * @extra: extra informations |
| 1535 | * |
| 1536 | * Handle an out of memory condition |
| 1537 | */ |
| 1538 | static void |
| 1539 | xmlSchemaVErrMemory(xmlSchemaValidCtxtPtr ctxt, |
| 1540 | const char *extra, xmlNodePtr node) |
| 1541 | { |
| 1542 | if (ctxt != NULL) { |
| 1543 | ctxt->nberrors++; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 1544 | ctxt->err = XML_SCHEMAV_INTERNAL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 1545 | } |
| 1546 | __xmlSimpleError(XML_FROM_SCHEMASV, XML_ERR_NO_MEMORY, node, NULL, |
| 1547 | extra); |
| 1548 | } |
| 1549 | |
| 1550 | /** |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1551 | * xmlSchemaErr3: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 1552 | * @ctxt: the validation context |
| 1553 | * @node: the context node |
| 1554 | * @error: the error code |
| 1555 | * @msg: the error message |
| 1556 | * @str1: extra data |
| 1557 | * @str2: extra data |
| 1558 | * @str3: extra data |
| 1559 | * |
| 1560 | * Handle a validation error |
| 1561 | */ |
| 1562 | static void |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1563 | xmlSchemaErr3(xmlSchemaAbstractCtxtPtr ctxt, |
| 1564 | int error, xmlNodePtr node, const char *msg, |
| 1565 | const xmlChar *str1, const xmlChar *str2, const xmlChar *str3) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 1566 | { |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 1567 | xmlStructuredErrorFunc schannel = NULL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 1568 | xmlGenericErrorFunc channel = NULL; |
| 1569 | void *data = NULL; |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 1570 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1571 | if (ctxt != NULL) { |
| 1572 | if (ctxt->type == XML_SCHEMA_CTXT_VALIDATOR) { |
| 1573 | xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctxt; |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 1574 | int line = 0; |
| 1575 | const char *file = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1576 | |
| 1577 | vctxt->nberrors++; |
| 1578 | vctxt->err = error; |
| 1579 | channel = vctxt->error; |
| 1580 | schannel = vctxt->serror; |
| 1581 | data = vctxt->userData; |
| 1582 | if ((node == NULL) && (vctxt->depth >= 0) && |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 1583 | (vctxt->inode != NULL)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1584 | node = vctxt->inode->node; |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 1585 | } |
| 1586 | if ((node == NULL) && (vctxt->parserCtxt != NULL) && |
| 1587 | (vctxt->parserCtxt->input != NULL)) { |
| 1588 | file = vctxt->parserCtxt->input->filename; |
| 1589 | line = vctxt->parserCtxt->input->line; |
| 1590 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1591 | __xmlRaiseError(schannel, channel, data, ctxt, |
| 1592 | node, XML_FROM_SCHEMASV, |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 1593 | error, XML_ERR_ERROR, file, line, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1594 | (const char *) str1, (const char *) str2, |
| 1595 | (const char *) str3, 0, 0, msg, str1, str2, str3); |
| 1596 | |
| 1597 | } else if (ctxt->type == XML_SCHEMA_CTXT_PARSER) { |
| 1598 | xmlSchemaParserCtxtPtr pctxt = (xmlSchemaParserCtxtPtr) ctxt; |
| 1599 | |
| 1600 | pctxt->nberrors++; |
| 1601 | pctxt->err = error; |
| 1602 | channel = pctxt->error; |
| 1603 | schannel = pctxt->serror; |
| 1604 | data = pctxt->userData; |
| 1605 | __xmlRaiseError(schannel, channel, data, ctxt, |
| 1606 | node, XML_FROM_SCHEMASP, |
| 1607 | error, XML_ERR_ERROR, NULL, 0, |
| 1608 | (const char *) str1, (const char *) str2, |
| 1609 | (const char *) str3, 0, 0, msg, str1, str2, str3); |
| 1610 | } else { |
| 1611 | TODO |
| 1612 | } |
| 1613 | } |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 1614 | } |
| 1615 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1616 | static void |
| 1617 | xmlSchemaErr(xmlSchemaAbstractCtxtPtr actxt, |
| 1618 | int error, xmlNodePtr node, const char *msg, |
| 1619 | const xmlChar *str1, const xmlChar *str2) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 1620 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1621 | xmlSchemaErr3(actxt, error, node, msg, str1, str2, NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 1622 | } |
| 1623 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1624 | static xmlChar * |
| 1625 | xmlSchemaFormatNodeForError(xmlChar ** msg, |
| 1626 | xmlSchemaAbstractCtxtPtr actxt, |
| 1627 | xmlNodePtr node) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1628 | { |
| 1629 | xmlChar *str = NULL; |
| 1630 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1631 | if (node != NULL) { |
| 1632 | /* |
| 1633 | * Work on tree nodes. |
| 1634 | */ |
| 1635 | if (node->type == XML_ATTRIBUTE_NODE) { |
| 1636 | xmlNodePtr elem = node->parent; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 1637 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1638 | *msg = xmlStrdup(BAD_CAST "Element '"); |
| 1639 | if (elem->ns != NULL) |
| 1640 | *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str, |
| 1641 | elem->ns->href, elem->name)); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 1642 | else |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1643 | *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str, |
| 1644 | NULL, elem->name)); |
| 1645 | FREE_AND_NULL(str); |
| 1646 | *msg = xmlStrcat(*msg, BAD_CAST "', "); |
| 1647 | *msg = xmlStrcat(*msg, BAD_CAST "attribute '"); |
| 1648 | } else { |
| 1649 | *msg = xmlStrdup(BAD_CAST "Element '"); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 1650 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1651 | if (node->ns != NULL) |
| 1652 | *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str, |
| 1653 | node->ns->href, node->name)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1654 | else |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1655 | *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str, |
| 1656 | NULL, node->name)); |
| 1657 | FREE_AND_NULL(str); |
| 1658 | *msg = xmlStrcat(*msg, BAD_CAST "': "); |
| 1659 | } else if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR) { |
| 1660 | xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) actxt; |
| 1661 | /* |
| 1662 | * Work on node infos. |
| 1663 | */ |
| 1664 | if (vctxt->inode->nodeType == XML_ATTRIBUTE_NODE) { |
| 1665 | xmlSchemaNodeInfoPtr ielem = |
| 1666 | vctxt->elemInfos[vctxt->depth]; |
| 1667 | |
| 1668 | *msg = xmlStrdup(BAD_CAST "Element '"); |
| 1669 | *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str, |
| 1670 | ielem->nsName, ielem->localName)); |
| 1671 | FREE_AND_NULL(str); |
| 1672 | *msg = xmlStrcat(*msg, BAD_CAST "', "); |
| 1673 | *msg = xmlStrcat(*msg, BAD_CAST "attribute '"); |
| 1674 | } else { |
| 1675 | *msg = xmlStrdup(BAD_CAST "Element '"); |
| 1676 | } |
| 1677 | *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str, |
| 1678 | vctxt->inode->nsName, vctxt->inode->localName)); |
| 1679 | FREE_AND_NULL(str); |
| 1680 | *msg = xmlStrcat(*msg, BAD_CAST "': "); |
| 1681 | } else { |
| 1682 | TODO |
| 1683 | return (NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1684 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1685 | /* |
| 1686 | * VAL TODO: The output of the given schema component is currently |
| 1687 | * disabled. |
| 1688 | */ |
| 1689 | #if 0 |
| 1690 | if ((type != NULL) && (xmlSchemaIsGlobalItem(type))) { |
| 1691 | *msg = xmlStrcat(*msg, BAD_CAST " ["); |
| 1692 | *msg = xmlStrcat(*msg, xmlSchemaFormatItemForReport(&str, |
| 1693 | NULL, type, NULL, 0)); |
| 1694 | FREE_AND_NULL(str) |
| 1695 | *msg = xmlStrcat(*msg, BAD_CAST "]"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1696 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1697 | #endif |
| 1698 | return (*msg); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1699 | } |
| 1700 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1701 | static void |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1702 | xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt, |
| 1703 | const char *funcName, |
| 1704 | const char *message) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1705 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1706 | xmlChar *msg = NULL; |
| 1707 | |
| 1708 | msg = xmlStrdup(BAD_CAST "Internal error: "); |
| 1709 | msg = xmlStrcat(msg, BAD_CAST funcName); |
| 1710 | msg = xmlStrcat(msg, BAD_CAST ", "); |
| 1711 | msg = xmlStrcat(msg, BAD_CAST message); |
| 1712 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1713 | |
| 1714 | if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR) |
| 1715 | xmlSchemaErr(actxt, XML_SCHEMAV_INTERNAL, NULL, |
| 1716 | (const char *) msg, NULL, NULL); |
| 1717 | |
| 1718 | else if (actxt->type == XML_SCHEMA_CTXT_PARSER) |
| 1719 | xmlSchemaErr(actxt, XML_SCHEMAP_INTERNAL, NULL, |
| 1720 | (const char *) msg, NULL, NULL); |
| 1721 | |
| 1722 | FREE_AND_NULL(msg) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1723 | } |
| 1724 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1725 | static void |
| 1726 | xmlSchemaCustomErr(xmlSchemaAbstractCtxtPtr actxt, |
| 1727 | xmlParserErrors error, |
| 1728 | xmlNodePtr node, |
| 1729 | xmlSchemaTypePtr type ATTRIBUTE_UNUSED, |
| 1730 | const char *message, |
| 1731 | const xmlChar *str1, |
| 1732 | const xmlChar *str2) |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1733 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1734 | xmlChar *msg = NULL; |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1735 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1736 | xmlSchemaFormatNodeForError(&msg, actxt, node); |
| 1737 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 1738 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1739 | xmlSchemaErr(actxt, error, node, |
| 1740 | (const char *) msg, str1, str2); |
| 1741 | FREE_AND_NULL(msg) |
| 1742 | } |
| 1743 | |
| 1744 | static int |
| 1745 | xmlSchemaEvalErrorNodeType(xmlSchemaAbstractCtxtPtr actxt, |
| 1746 | xmlNodePtr node) |
| 1747 | { |
| 1748 | if (node != NULL) |
| 1749 | return (node->type); |
| 1750 | if ((actxt->type == XML_SCHEMA_CTXT_VALIDATOR) && |
| 1751 | (((xmlSchemaValidCtxtPtr) actxt)->inode != NULL)) |
| 1752 | return ( ((xmlSchemaValidCtxtPtr) actxt)->inode->nodeType); |
| 1753 | return (-1); |
| 1754 | } |
| 1755 | |
| 1756 | static int |
| 1757 | xmlSchemaIsGlobalItem(xmlSchemaTypePtr item) |
| 1758 | { |
| 1759 | switch (item->type) { |
| 1760 | case XML_SCHEMA_TYPE_COMPLEX: |
| 1761 | case XML_SCHEMA_TYPE_SIMPLE: |
| 1762 | if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) |
| 1763 | return(1); |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1764 | break; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1765 | case XML_SCHEMA_TYPE_GROUP: |
| 1766 | return (1); |
| 1767 | case XML_SCHEMA_TYPE_ELEMENT: |
| 1768 | if ( ((xmlSchemaElementPtr) item)->flags & |
| 1769 | XML_SCHEMAS_ELEM_GLOBAL) |
| 1770 | return(1); |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1771 | break; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1772 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 1773 | if ( ((xmlSchemaAttributePtr) item)->flags & |
| 1774 | XML_SCHEMAS_ATTR_GLOBAL) |
| 1775 | return(1); |
| 1776 | break; |
| 1777 | /* Note that attribute groups are always global. */ |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1778 | default: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1779 | return(1); |
| 1780 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1781 | return (0); |
| 1782 | } |
| 1783 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1784 | static void |
| 1785 | xmlSchemaSimpleTypeErr(xmlSchemaAbstractCtxtPtr actxt, |
| 1786 | xmlParserErrors error, |
| 1787 | xmlNodePtr node, |
| 1788 | const xmlChar *value, |
| 1789 | xmlSchemaTypePtr type, |
| 1790 | int displayValue) |
| 1791 | { |
| 1792 | xmlChar *msg = NULL; |
| 1793 | |
| 1794 | xmlSchemaFormatNodeForError(&msg, actxt, node); |
| 1795 | |
| 1796 | if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) == |
| 1797 | XML_ATTRIBUTE_NODE)) |
| 1798 | msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of "); |
| 1799 | else |
| 1800 | msg = xmlStrcat(msg, BAD_CAST "The character content is not a valid " |
| 1801 | "value of "); |
| 1802 | |
| 1803 | if (! xmlSchemaIsGlobalItem(type)) |
| 1804 | msg = xmlStrcat(msg, BAD_CAST "the local "); |
| 1805 | else |
| 1806 | msg = xmlStrcat(msg, BAD_CAST "the "); |
| 1807 | |
| 1808 | if (VARIETY_ATOMIC(type)) |
| 1809 | msg = xmlStrcat(msg, BAD_CAST "atomic type"); |
| 1810 | else if (VARIETY_LIST(type)) |
| 1811 | msg = xmlStrcat(msg, BAD_CAST "list type"); |
| 1812 | else if (VARIETY_UNION(type)) |
| 1813 | msg = xmlStrcat(msg, BAD_CAST "union type"); |
| 1814 | |
| 1815 | if (xmlSchemaIsGlobalItem(type)) { |
| 1816 | xmlChar *str = NULL; |
| 1817 | msg = xmlStrcat(msg, BAD_CAST " '"); |
| 1818 | if (type->builtInType != 0) { |
| 1819 | msg = xmlStrcat(msg, BAD_CAST "xs:"); |
| 1820 | msg = xmlStrcat(msg, type->name); |
| 1821 | } else |
| 1822 | msg = xmlStrcat(msg, |
| 1823 | xmlSchemaFormatQName(&str, |
| 1824 | type->targetNamespace, type->name)); |
| 1825 | msg = xmlStrcat(msg, BAD_CAST "'"); |
| 1826 | FREE_AND_NULL(str); |
| 1827 | } |
| 1828 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1829 | if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) == |
| 1830 | XML_ATTRIBUTE_NODE)) |
| 1831 | xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL); |
| 1832 | else |
| 1833 | xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL); |
| 1834 | FREE_AND_NULL(msg) |
| 1835 | } |
| 1836 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1837 | static const xmlChar * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1838 | xmlSchemaFormatErrorNodeQName(xmlChar ** str, |
| 1839 | xmlSchemaNodeInfoPtr ni, |
| 1840 | xmlNodePtr node) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1841 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1842 | if (node != NULL) { |
| 1843 | if (node->ns != NULL) |
| 1844 | return (xmlSchemaFormatQName(str, node->ns->href, node->name)); |
| 1845 | else |
| 1846 | return (xmlSchemaFormatQName(str, NULL, node->name)); |
| 1847 | } else if (ni != NULL) |
| 1848 | return (xmlSchemaFormatQName(str, ni->nsName, ni->localName)); |
| 1849 | return (NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1852 | static void |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1853 | xmlSchemaIllegalAttrErr(xmlSchemaAbstractCtxtPtr actxt, |
| 1854 | xmlParserErrors error, |
| 1855 | xmlSchemaAttrInfoPtr ni, |
| 1856 | xmlNodePtr node) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1857 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1858 | xmlChar *msg = NULL, *str = NULL; |
| 1859 | |
| 1860 | xmlSchemaFormatNodeForError(&msg, actxt, node); |
| 1861 | msg = xmlStrcat(msg, BAD_CAST "The attribute '%s' is not allowed.\n"); |
| 1862 | xmlSchemaErr(actxt, error, node, (const char *) msg, |
| 1863 | xmlSchemaFormatErrorNodeQName(&str, (xmlSchemaNodeInfoPtr) ni, node), |
| 1864 | NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1865 | FREE_AND_NULL(str) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1866 | FREE_AND_NULL(msg) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1867 | } |
| 1868 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1869 | static void |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1870 | xmlSchemaComplexTypeErr(xmlSchemaAbstractCtxtPtr actxt, |
| 1871 | xmlParserErrors error, |
| 1872 | xmlNodePtr node, |
| 1873 | xmlSchemaTypePtr type ATTRIBUTE_UNUSED, |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1874 | const char *message, |
| 1875 | int nbval, |
| 1876 | int nbneg, |
| 1877 | xmlChar **values) |
| 1878 | { |
| 1879 | xmlChar *str = NULL, *msg = NULL; |
| 1880 | xmlChar *localName, *nsName; |
| 1881 | const xmlChar *cur, *end; |
| 1882 | int i; |
| 1883 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1884 | xmlSchemaFormatNodeForError(&msg, actxt, node); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1885 | msg = xmlStrcat(msg, (const xmlChar *) message); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1886 | msg = xmlStrcat(msg, BAD_CAST "."); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1887 | /* |
| 1888 | * Note that is does not make sense to report that we have a |
| 1889 | * wildcard here, since the wildcard might be unfolded into |
| 1890 | * multiple transitions. |
| 1891 | */ |
| 1892 | if (nbval + nbneg > 0) { |
| 1893 | if (nbval + nbneg > 1) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1894 | str = xmlStrdup(BAD_CAST " Expected is one of ( "); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1895 | } else |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1896 | str = xmlStrdup(BAD_CAST " Expected is ( "); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1897 | nsName = NULL; |
| 1898 | |
| 1899 | for (i = 0; i < nbval + nbneg; i++) { |
| 1900 | cur = values[i]; |
| 1901 | /* |
| 1902 | * Get the local name. |
| 1903 | */ |
| 1904 | localName = NULL; |
| 1905 | |
| 1906 | end = cur; |
| 1907 | if (*end == '*') { |
| 1908 | localName = xmlStrdup(BAD_CAST "*"); |
Kasimier T. Buchcik | c0e833f | 2005-04-19 15:02:20 +0000 | [diff] [blame] | 1909 | end++; |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1910 | } else { |
| 1911 | while ((*end != 0) && (*end != '|')) |
| 1912 | end++; |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1913 | localName = xmlStrncat(localName, BAD_CAST cur, end - cur); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1914 | } |
| 1915 | if (*end != 0) { |
Kasimier T. Buchcik | c0e833f | 2005-04-19 15:02:20 +0000 | [diff] [blame] | 1916 | end++; |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1917 | /* |
| 1918 | * Skip "*|*" if they come with negated expressions, since |
| 1919 | * they represent the same negated wildcard. |
| 1920 | */ |
| 1921 | if ((nbneg == 0) || (*end != '*') || (*localName != '*')) { |
| 1922 | /* |
| 1923 | * Get the namespace name. |
| 1924 | */ |
| 1925 | cur = end; |
| 1926 | if (*end == '*') { |
| 1927 | nsName = xmlStrdup(BAD_CAST "{*}"); |
| 1928 | } else { |
| 1929 | while (*end != 0) |
| 1930 | end++; |
| 1931 | |
| 1932 | if (i >= nbval) |
| 1933 | nsName = xmlStrdup(BAD_CAST "{##other:"); |
| 1934 | else |
| 1935 | nsName = xmlStrdup(BAD_CAST "{"); |
| 1936 | |
| 1937 | nsName = xmlStrncat(nsName, BAD_CAST cur, end - cur); |
| 1938 | nsName = xmlStrcat(nsName, BAD_CAST "}"); |
| 1939 | } |
| 1940 | str = xmlStrcat(str, BAD_CAST nsName); |
| 1941 | FREE_AND_NULL(nsName) |
| 1942 | } else { |
| 1943 | FREE_AND_NULL(localName); |
| 1944 | continue; |
| 1945 | } |
| 1946 | } |
| 1947 | str = xmlStrcat(str, BAD_CAST localName); |
| 1948 | FREE_AND_NULL(localName); |
| 1949 | |
| 1950 | if (i < nbval + nbneg -1) |
| 1951 | str = xmlStrcat(str, BAD_CAST ", "); |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 1952 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1953 | str = xmlStrcat(str, BAD_CAST " ).\n"); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1954 | msg = xmlStrcat(msg, BAD_CAST str); |
| 1955 | FREE_AND_NULL(str) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1956 | } else |
| 1957 | msg = xmlStrcat(msg, BAD_CAST "\n"); |
| 1958 | xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1959 | xmlFree(msg); |
| 1960 | } |
| 1961 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1962 | static void |
| 1963 | xmlSchemaFacetErr(xmlSchemaAbstractCtxtPtr actxt, |
| 1964 | xmlParserErrors error, |
| 1965 | xmlNodePtr node, |
| 1966 | const xmlChar *value, |
| 1967 | unsigned long length, |
| 1968 | xmlSchemaTypePtr type, |
| 1969 | xmlSchemaFacetPtr facet, |
| 1970 | const char *message, |
| 1971 | const xmlChar *str1, |
| 1972 | const xmlChar *str2) |
| 1973 | { |
| 1974 | xmlChar *str = NULL, *msg = NULL; |
| 1975 | xmlSchemaTypeType facetType; |
| 1976 | int nodeType = xmlSchemaEvalErrorNodeType(actxt, node); |
| 1977 | |
| 1978 | xmlSchemaFormatNodeForError(&msg, actxt, node); |
| 1979 | if (error == XML_SCHEMAV_CVC_ENUMERATION_VALID) { |
| 1980 | facetType = XML_SCHEMA_FACET_ENUMERATION; |
| 1981 | /* |
| 1982 | * If enumerations are validated, one must not expect the |
| 1983 | * facet to be given. |
| 1984 | */ |
| 1985 | } else |
| 1986 | facetType = facet->type; |
| 1987 | msg = xmlStrcat(msg, BAD_CAST "["); |
| 1988 | msg = xmlStrcat(msg, BAD_CAST "facet '"); |
| 1989 | msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facetType)); |
| 1990 | msg = xmlStrcat(msg, BAD_CAST "'] "); |
| 1991 | if (message == NULL) { |
| 1992 | /* |
| 1993 | * Use a default message. |
| 1994 | */ |
| 1995 | if ((facetType == XML_SCHEMA_FACET_LENGTH) || |
| 1996 | (facetType == XML_SCHEMA_FACET_MINLENGTH) || |
| 1997 | (facetType == XML_SCHEMA_FACET_MAXLENGTH)) { |
| 1998 | |
| 1999 | char len[25], actLen[25]; |
| 2000 | |
| 2001 | /* FIXME, TODO: What is the max expected string length of the |
| 2002 | * this value? |
| 2003 | */ |
| 2004 | if (nodeType == XML_ATTRIBUTE_NODE) |
| 2005 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' has a length of '%s'; "); |
| 2006 | else |
| 2007 | msg = xmlStrcat(msg, BAD_CAST "The value has a length of '%s'; "); |
| 2008 | |
| 2009 | snprintf(len, 24, "%lu", xmlSchemaGetFacetValueAsULong(facet)); |
| 2010 | snprintf(actLen, 24, "%lu", length); |
| 2011 | |
| 2012 | if (facetType == XML_SCHEMA_FACET_LENGTH) |
| 2013 | msg = xmlStrcat(msg, |
| 2014 | BAD_CAST "this differs from the allowed length of '%s'.\n"); |
| 2015 | else if (facetType == XML_SCHEMA_FACET_MAXLENGTH) |
| 2016 | msg = xmlStrcat(msg, |
| 2017 | BAD_CAST "this exceeds the allowed maximum length of '%s'.\n"); |
| 2018 | else if (facetType == XML_SCHEMA_FACET_MINLENGTH) |
| 2019 | msg = xmlStrcat(msg, |
| 2020 | BAD_CAST "this underruns the allowed minimum length of '%s'.\n"); |
| 2021 | |
| 2022 | if (nodeType == XML_ATTRIBUTE_NODE) |
| 2023 | xmlSchemaErr3(actxt, error, node, (const char *) msg, |
| 2024 | value, (const xmlChar *) actLen, (const xmlChar *) len); |
| 2025 | else |
| 2026 | xmlSchemaErr(actxt, error, node, (const char *) msg, |
| 2027 | (const xmlChar *) actLen, (const xmlChar *) len); |
| 2028 | |
| 2029 | } else if (facetType == XML_SCHEMA_FACET_ENUMERATION) { |
| 2030 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not an element " |
| 2031 | "of the set {%s}.\n"); |
| 2032 | xmlSchemaErr(actxt, error, node, (const char *) msg, value, |
| 2033 | xmlSchemaFormatFacetEnumSet(actxt, &str, type)); |
| 2034 | } else if (facetType == XML_SCHEMA_FACET_PATTERN) { |
| 2035 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not accepted " |
| 2036 | "by the pattern '%s'.\n"); |
| 2037 | xmlSchemaErr(actxt, error, node, (const char *) msg, value, |
| 2038 | facet->value); |
| 2039 | } else if (facetType == XML_SCHEMA_FACET_MININCLUSIVE) { |
| 2040 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is less than the " |
| 2041 | "minimum value allowed ('%s').\n"); |
| 2042 | xmlSchemaErr(actxt, error, node, (const char *) msg, value, |
| 2043 | facet->value); |
| 2044 | } else if (facetType == XML_SCHEMA_FACET_MAXINCLUSIVE) { |
| 2045 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is greater than the " |
| 2046 | "maximum value allowed ('%s').\n"); |
| 2047 | xmlSchemaErr(actxt, error, node, (const char *) msg, value, |
| 2048 | facet->value); |
| 2049 | } else if (facetType == XML_SCHEMA_FACET_MINEXCLUSIVE) { |
| 2050 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be less than " |
| 2051 | "'%s'.\n"); |
| 2052 | xmlSchemaErr(actxt, error, node, (const char *) msg, value, |
| 2053 | facet->value); |
| 2054 | } else if (facetType == XML_SCHEMA_FACET_MAXEXCLUSIVE) { |
| 2055 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be more than " |
| 2056 | "'%s'.\n"); |
| 2057 | xmlSchemaErr(actxt, error, node, (const char *) msg, value, |
| 2058 | facet->value); |
| 2059 | } else if (facetType == XML_SCHEMA_FACET_TOTALDIGITS) { |
| 2060 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more " |
| 2061 | "digits than are allowed ('%s').\n"); |
| 2062 | xmlSchemaErr(actxt, error, node, (const char*) msg, value, |
| 2063 | facet->value); |
| 2064 | } else if (facetType == XML_SCHEMA_FACET_FRACTIONDIGITS) { |
| 2065 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more fractional " |
| 2066 | "digits than are allowed ('%s').\n"); |
| 2067 | xmlSchemaErr(actxt, error, node, (const char*) msg, value, |
| 2068 | facet->value); |
| 2069 | } else if (nodeType == XML_ATTRIBUTE_NODE) { |
| 2070 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not facet-valid.\n"); |
| 2071 | xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL); |
| 2072 | } else { |
| 2073 | msg = xmlStrcat(msg, BAD_CAST "The value is not facet-valid.\n"); |
| 2074 | xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL); |
| 2075 | } |
| 2076 | } else { |
| 2077 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 2078 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 2079 | xmlSchemaErr(actxt, error, node, (const char *) msg, str1, str2); |
| 2080 | } |
| 2081 | FREE_AND_NULL(str) |
| 2082 | xmlFree(msg); |
| 2083 | } |
| 2084 | |
| 2085 | #define VERROR(err, type, msg) \ |
| 2086 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) vctxt, err, NULL, type, msg, NULL, NULL); |
| 2087 | |
| 2088 | #define VERROR_INT(func, msg) xmlSchemaInternalErr((xmlSchemaAbstractCtxtPtr) vctxt, func, msg); |
| 2089 | |
| 2090 | #define PERROR_INT(func, msg) xmlSchemaInternalErr((xmlSchemaAbstractCtxtPtr) pctxt, func, msg); |
| 2091 | |
| 2092 | #define AERROR_INT(func, msg) xmlSchemaInternalErr(actxt, func, msg); |
| 2093 | |
| 2094 | |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 2095 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2096 | * xmlSchemaPMissingAttrErr: |
| 2097 | * @ctxt: the schema validation context |
| 2098 | * @ownerDes: the designation of the owner |
| 2099 | * @ownerName: the name of the owner |
| 2100 | * @ownerItem: the owner as a schema object |
| 2101 | * @ownerElem: the owner as an element node |
| 2102 | * @node: the parent element node of the missing attribute node |
| 2103 | * @type: the corresponding type of the attribute node |
| 2104 | * |
| 2105 | * Reports an illegal attribute. |
| 2106 | */ |
| 2107 | static void |
| 2108 | xmlSchemaPMissingAttrErr(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2109 | xmlParserErrors error, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2110 | xmlSchemaTypePtr ownerItem, |
| 2111 | xmlNodePtr ownerElem, |
| 2112 | const char *name, |
| 2113 | const char *message) |
| 2114 | { |
| 2115 | xmlChar *des = NULL; |
| 2116 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2117 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem); |
| 2118 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2119 | if (message != NULL) |
| 2120 | xmlSchemaPErr(ctxt, ownerElem, error, "%s: %s.\n", BAD_CAST des, BAD_CAST message); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2121 | else |
| 2122 | xmlSchemaPErr(ctxt, ownerElem, error, |
| 2123 | "%s: The attribute '%s' is required but missing.\n", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2124 | BAD_CAST des, BAD_CAST name); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2125 | FREE_AND_NULL(des); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2126 | } |
| 2127 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2128 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2129 | /** |
| 2130 | * xmlSchemaPResCompAttrErr: |
| 2131 | * @ctxt: the schema validation context |
| 2132 | * @error: the error code |
| 2133 | * @ownerDes: the designation of the owner |
| 2134 | * @ownerItem: the owner as a schema object |
| 2135 | * @ownerElem: the owner as an element node |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2136 | * @name: the name of the attribute holding the QName |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2137 | * @refName: the referenced local name |
| 2138 | * @refURI: the referenced namespace URI |
| 2139 | * @message: optional message |
| 2140 | * |
| 2141 | * Used to report QName attribute values that failed to resolve |
| 2142 | * to schema components. |
| 2143 | */ |
| 2144 | static void |
| 2145 | xmlSchemaPResCompAttrErr(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2146 | xmlParserErrors error, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2147 | xmlSchemaTypePtr ownerItem, |
| 2148 | xmlNodePtr ownerElem, |
| 2149 | const char *name, |
| 2150 | const xmlChar *refName, |
| 2151 | const xmlChar *refURI, |
| 2152 | xmlSchemaTypeType refType, |
| 2153 | const char *refTypeStr) |
| 2154 | { |
| 2155 | xmlChar *des = NULL, *strA = NULL; |
| 2156 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2157 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2158 | if (refTypeStr == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2159 | refTypeStr = (const char *) xmlSchemaCompTypeToString(refType); |
| 2160 | xmlSchemaPErrExt(ctxt, ownerElem, error, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2161 | NULL, NULL, NULL, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2162 | "%s, attribute '%s': The QName value '%s' does not resolve to a(n) " |
| 2163 | "%s.\n", BAD_CAST des, BAD_CAST name, |
| 2164 | xmlSchemaFormatQName(&strA, refURI, refName), |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2165 | BAD_CAST refTypeStr, NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2166 | FREE_AND_NULL(des) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2167 | FREE_AND_NULL(strA) |
| 2168 | } |
| 2169 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2170 | /** |
| 2171 | * xmlSchemaPCustomAttrErr: |
| 2172 | * @ctxt: the schema parser context |
| 2173 | * @error: the error code |
| 2174 | * @ownerDes: the designation of the owner |
| 2175 | * @ownerItem: the owner as a schema object |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2176 | * @attr: the illegal attribute node |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2177 | * |
| 2178 | * Reports an illegal attribute during the parse. |
| 2179 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2180 | static void |
| 2181 | xmlSchemaPCustomAttrErr(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2182 | xmlParserErrors error, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2183 | xmlChar **ownerDes, |
| 2184 | xmlSchemaTypePtr ownerItem, |
| 2185 | xmlAttrPtr attr, |
| 2186 | const char *msg) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2187 | { |
| 2188 | xmlChar *des = NULL; |
| 2189 | |
| 2190 | if (ownerDes == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2191 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2192 | else if (*ownerDes == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2193 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2194 | des = *ownerDes; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2195 | } else |
| 2196 | des = *ownerDes; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2197 | xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2198 | "%s, attribute '%s': %s.\n", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2199 | BAD_CAST des, attr->name, (const xmlChar *) msg, NULL, NULL); |
| 2200 | if (ownerDes == NULL) |
| 2201 | FREE_AND_NULL(des); |
| 2202 | } |
| 2203 | |
| 2204 | /** |
| 2205 | * xmlSchemaPIllegalAttrErr: |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2206 | * @ctxt: the schema parser context |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2207 | * @error: the error code |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2208 | * @ownerDes: the designation of the attribute's owner |
| 2209 | * @ownerItem: the attribute's owner item |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2210 | * @attr: the illegal attribute node |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2211 | * |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2212 | * Reports an illegal attribute during the parse. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2213 | */ |
| 2214 | static void |
| 2215 | xmlSchemaPIllegalAttrErr(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2216 | xmlParserErrors error, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2217 | xmlChar **ownerDes, |
| 2218 | xmlSchemaTypePtr ownerItem, |
| 2219 | xmlAttrPtr attr) |
| 2220 | { |
| 2221 | xmlChar *des = NULL, *strA = NULL; |
| 2222 | |
| 2223 | if (ownerDes == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2224 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2225 | else if (*ownerDes == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2226 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2227 | des = *ownerDes; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2228 | } else |
| 2229 | des = *ownerDes; |
| 2230 | xmlSchemaPErr(ctxt, (xmlNodePtr) attr, error, |
| 2231 | "%s: The attribute '%s' is not allowed.\n", BAD_CAST des, |
| 2232 | xmlSchemaFormatQNameNs(&strA, attr->ns, attr->name)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2233 | if (ownerDes == NULL) |
| 2234 | FREE_AND_NULL(des); |
| 2235 | FREE_AND_NULL(strA); |
| 2236 | } |
| 2237 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2238 | /** |
| 2239 | * xmlSchemaPAquireDes: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2240 | * @des: the first designation |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2241 | * @itemDes: the second designation |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2242 | * @item: the schema item |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2243 | * @itemElem: the node of the schema item |
| 2244 | * |
| 2245 | * Creates a designation for an item. |
| 2246 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2247 | static void |
| 2248 | xmlSchemaPAquireDes(xmlChar **des, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2249 | xmlChar **itemDes, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2250 | xmlSchemaTypePtr item, |
| 2251 | xmlNodePtr itemElem) |
| 2252 | { |
| 2253 | if (itemDes == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2254 | xmlSchemaFormatItemForReport(des, NULL, item, itemElem); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2255 | else if (*itemDes == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2256 | xmlSchemaFormatItemForReport(itemDes, NULL, item, itemElem); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2257 | *des = *itemDes; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2258 | } else |
| 2259 | *des = *itemDes; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2260 | } |
| 2261 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2262 | /** |
| 2263 | * xmlSchemaPCustomErr: |
| 2264 | * @ctxt: the schema parser context |
| 2265 | * @error: the error code |
| 2266 | * @itemDes: the designation of the schema item |
| 2267 | * @item: the schema item |
| 2268 | * @itemElem: the node of the schema item |
| 2269 | * @message: the error message |
| 2270 | * @str1: an optional param for the error message |
| 2271 | * @str2: an optional param for the error message |
| 2272 | * @str3: an optional param for the error message |
| 2273 | * |
| 2274 | * Reports an error during parsing. |
| 2275 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2276 | static void |
| 2277 | xmlSchemaPCustomErrExt(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2278 | xmlParserErrors error, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2279 | xmlChar **itemDes, |
| 2280 | xmlSchemaTypePtr item, |
| 2281 | xmlNodePtr itemElem, |
| 2282 | const char *message, |
| 2283 | const xmlChar *str1, |
| 2284 | const xmlChar *str2, |
| 2285 | const xmlChar *str3) |
| 2286 | { |
| 2287 | xmlChar *des = NULL, *msg = NULL; |
| 2288 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2289 | xmlSchemaPAquireDes(&des, itemDes, item, itemElem); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2290 | msg = xmlStrdup(BAD_CAST "%s: "); |
| 2291 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 2292 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 2293 | if ((itemElem == NULL) && (item != NULL)) |
| 2294 | itemElem = item->node; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2295 | xmlSchemaPErrExt(ctxt, itemElem, error, NULL, NULL, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2296 | (const char *) msg, BAD_CAST des, str1, str2, str3, NULL); |
| 2297 | if (itemDes == NULL) |
| 2298 | FREE_AND_NULL(des); |
| 2299 | FREE_AND_NULL(msg); |
| 2300 | } |
| 2301 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2302 | /** |
| 2303 | * xmlSchemaPCustomErr: |
| 2304 | * @ctxt: the schema parser context |
| 2305 | * @error: the error code |
| 2306 | * @itemDes: the designation of the schema item |
| 2307 | * @item: the schema item |
| 2308 | * @itemElem: the node of the schema item |
| 2309 | * @message: the error message |
| 2310 | * @str1: the optional param for the error message |
| 2311 | * |
| 2312 | * Reports an error during parsing. |
| 2313 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2314 | static void |
| 2315 | xmlSchemaPCustomErr(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2316 | xmlParserErrors error, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2317 | xmlChar **itemDes, |
| 2318 | xmlSchemaTypePtr item, |
| 2319 | xmlNodePtr itemElem, |
| 2320 | const char *message, |
| 2321 | const xmlChar *str1) |
| 2322 | { |
| 2323 | xmlSchemaPCustomErrExt(ctxt, error, itemDes, item, itemElem, message, |
| 2324 | str1, NULL, NULL); |
| 2325 | } |
| 2326 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2327 | /** |
| 2328 | * xmlSchemaPAttrUseErr: |
| 2329 | * @ctxt: the schema parser context |
| 2330 | * @error: the error code |
| 2331 | * @itemDes: the designation of the schema type |
| 2332 | * @item: the schema type |
| 2333 | * @itemElem: the node of the schema type |
| 2334 | * @attr: the invalid schema attribute |
| 2335 | * @message: the error message |
| 2336 | * @str1: the optional param for the error message |
| 2337 | * |
| 2338 | * Reports an attribute use error during parsing. |
| 2339 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2340 | static void |
| 2341 | xmlSchemaPAttrUseErr(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2342 | xmlParserErrors error, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2343 | xmlSchemaTypePtr item, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2344 | const xmlSchemaAttributePtr attr, |
| 2345 | const char *message, |
| 2346 | const xmlChar *str1) |
| 2347 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2348 | xmlChar *str = NULL, *msg = NULL; |
| 2349 | xmlSchemaFormatItemForReport(&msg, NULL, item, NULL); |
| 2350 | msg = xmlStrcat(msg, BAD_CAST ", "); |
| 2351 | msg = xmlStrcat(msg, |
| 2352 | BAD_CAST xmlSchemaFormatItemForReport(&str, NULL, |
| 2353 | (xmlSchemaTypePtr) attr, NULL)); |
| 2354 | FREE_AND_NULL(str); |
| 2355 | msg = xmlStrcat(msg, BAD_CAST ": "); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2356 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 2357 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2358 | xmlSchemaPErr(ctxt, attr->node, error, |
| 2359 | (const char *) msg, str1, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2360 | xmlFree(msg); |
| 2361 | } |
| 2362 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2363 | /** |
| 2364 | * xmlSchemaPIllegalFacetAtomicErr: |
| 2365 | * @ctxt: the schema parser context |
| 2366 | * @error: the error code |
| 2367 | * @itemDes: the designation of the type |
| 2368 | * @item: the schema type |
| 2369 | * @baseItem: the base type of type |
| 2370 | * @facet: the illegal facet |
| 2371 | * |
| 2372 | * Reports an illegal facet for atomic simple types. |
| 2373 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2374 | static void |
| 2375 | xmlSchemaPIllegalFacetAtomicErr(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2376 | xmlParserErrors error, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2377 | xmlChar **itemDes, |
| 2378 | xmlSchemaTypePtr item, |
| 2379 | xmlSchemaTypePtr baseItem, |
| 2380 | xmlSchemaFacetPtr facet) |
| 2381 | { |
| 2382 | xmlChar *des = NULL, *strT = NULL; |
| 2383 | |
| 2384 | xmlSchemaPAquireDes(&des, itemDes, item, item->node); |
| 2385 | xmlSchemaPErrExt(ctxt, item->node, error, NULL, NULL, NULL, |
| 2386 | "%s: The facet '%s' is not allowed on types derived from the " |
| 2387 | "type %s.\n", |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 2388 | BAD_CAST des, xmlSchemaFacetTypeToString(facet->type), |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2389 | xmlSchemaFormatItemForReport(&strT, NULL, baseItem, NULL), |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2390 | NULL, NULL); |
| 2391 | if (itemDes == NULL) |
| 2392 | FREE_AND_NULL(des); |
| 2393 | FREE_AND_NULL(strT); |
| 2394 | } |
| 2395 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2396 | /** |
| 2397 | * xmlSchemaPIllegalFacetListUnionErr: |
| 2398 | * @ctxt: the schema parser context |
| 2399 | * @error: the error code |
| 2400 | * @itemDes: the designation of the schema item involved |
| 2401 | * @item: the schema item involved |
| 2402 | * @facet: the illegal facet |
| 2403 | * |
| 2404 | * Reports an illegal facet for <list> and <union>. |
| 2405 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2406 | static void |
| 2407 | xmlSchemaPIllegalFacetListUnionErr(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2408 | xmlParserErrors error, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2409 | xmlChar **itemDes, |
| 2410 | xmlSchemaTypePtr item, |
| 2411 | xmlSchemaFacetPtr facet) |
| 2412 | { |
| 2413 | xmlChar *des = NULL, *strT = NULL; |
| 2414 | |
| 2415 | xmlSchemaPAquireDes(&des, itemDes, item, item->node); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2416 | xmlSchemaPErr(ctxt, item->node, error, |
| 2417 | "%s: The facet '%s' is not allowed.\n", |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 2418 | BAD_CAST des, xmlSchemaFacetTypeToString(facet->type)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2419 | if (itemDes == NULL) |
| 2420 | FREE_AND_NULL(des); |
| 2421 | FREE_AND_NULL(strT); |
| 2422 | } |
| 2423 | |
| 2424 | /** |
| 2425 | * xmlSchemaPMutualExclAttrErr: |
| 2426 | * @ctxt: the schema validation context |
| 2427 | * @error: the error code |
| 2428 | * @elemDes: the designation of the parent element node |
| 2429 | * @attr: the bad attribute node |
| 2430 | * @type: the corresponding type of the attribute node |
| 2431 | * |
| 2432 | * Reports an illegal attribute. |
| 2433 | */ |
| 2434 | static void |
| 2435 | xmlSchemaPMutualExclAttrErr(xmlSchemaParserCtxtPtr ctxt, |
| 2436 | xmlParserErrors error, |
| 2437 | xmlChar **ownerDes, |
| 2438 | xmlSchemaTypePtr ownerItem, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2439 | xmlAttrPtr attr, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2440 | const char *name1, |
| 2441 | const char *name2) |
| 2442 | { |
| 2443 | xmlChar *des = NULL; |
| 2444 | |
| 2445 | if (ownerDes == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2446 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2447 | else if (*ownerDes == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2448 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2449 | des = *ownerDes; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2450 | } else |
| 2451 | des = *ownerDes; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2452 | xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2453 | "%s: The attributes '%s' and '%s' are mutually exclusive.\n", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2454 | BAD_CAST des, BAD_CAST name1, BAD_CAST name2, NULL, NULL); |
| 2455 | if (ownerDes == NULL) |
| 2456 | FREE_AND_NULL(des) |
| 2457 | } |
| 2458 | |
| 2459 | /** |
| 2460 | * xmlSchemaPSimpleTypeErr: |
| 2461 | * @ctxt: the schema validation context |
| 2462 | * @error: the error code |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2463 | * @type: the type specifier |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2464 | * @ownerDes: the designation of the owner |
| 2465 | * @ownerItem: the schema object if existent |
| 2466 | * @node: the validated node |
| 2467 | * @value: the validated value |
| 2468 | * |
| 2469 | * Reports a simple type validation error. |
| 2470 | * TODO: Should this report the value of an element as well? |
| 2471 | */ |
| 2472 | static void |
| 2473 | xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt, |
| 2474 | xmlParserErrors error, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2475 | xmlSchemaTypePtr ownerItem ATTRIBUTE_UNUSED, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2476 | xmlNodePtr node, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2477 | xmlSchemaTypePtr type, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2478 | const char *expected, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2479 | const xmlChar *value, |
| 2480 | const char *message, |
| 2481 | const xmlChar *str1, |
| 2482 | const xmlChar *str2) |
| 2483 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2484 | xmlChar *msg = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2485 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2486 | xmlSchemaFormatNodeForError(&msg, (xmlSchemaAbstractCtxtPtr) ctxt, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2487 | if (message == NULL) { |
| 2488 | /* |
| 2489 | * Use default messages. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2490 | */ |
| 2491 | if (type != NULL) { |
| 2492 | if (node->type == XML_ATTRIBUTE_NODE) |
| 2493 | msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of "); |
| 2494 | else |
| 2495 | msg = xmlStrcat(msg, BAD_CAST "The character content is not a " |
| 2496 | "valid value of "); |
| 2497 | if (! xmlSchemaIsGlobalItem(type)) |
| 2498 | msg = xmlStrcat(msg, BAD_CAST "the local "); |
| 2499 | else |
| 2500 | msg = xmlStrcat(msg, BAD_CAST "the "); |
| 2501 | |
| 2502 | if (VARIETY_ATOMIC(type)) |
| 2503 | msg = xmlStrcat(msg, BAD_CAST "atomic type"); |
| 2504 | else if (VARIETY_LIST(type)) |
| 2505 | msg = xmlStrcat(msg, BAD_CAST "list type"); |
| 2506 | else if (VARIETY_UNION(type)) |
| 2507 | msg = xmlStrcat(msg, BAD_CAST "union type"); |
| 2508 | |
| 2509 | if (xmlSchemaIsGlobalItem(type)) { |
| 2510 | xmlChar *str = NULL; |
| 2511 | msg = xmlStrcat(msg, BAD_CAST " '"); |
| 2512 | if (type->builtInType != 0) { |
| 2513 | msg = xmlStrcat(msg, BAD_CAST "xs:"); |
| 2514 | msg = xmlStrcat(msg, type->name); |
| 2515 | } else |
| 2516 | msg = xmlStrcat(msg, |
| 2517 | xmlSchemaFormatQName(&str, |
| 2518 | type->targetNamespace, type->name)); |
| 2519 | msg = xmlStrcat(msg, BAD_CAST "'."); |
| 2520 | FREE_AND_NULL(str); |
| 2521 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2522 | } else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2523 | if (node->type == XML_ATTRIBUTE_NODE) |
| 2524 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not valid."); |
| 2525 | else |
| 2526 | msg = xmlStrcat(msg, BAD_CAST "The character content is not " |
| 2527 | "valid."); |
| 2528 | } |
| 2529 | if (expected) { |
| 2530 | msg = xmlStrcat(msg, BAD_CAST " Expected is '"); |
| 2531 | msg = xmlStrcat(msg, BAD_CAST expected); |
| 2532 | msg = xmlStrcat(msg, BAD_CAST "'.\n"); |
| 2533 | } else |
| 2534 | msg = xmlStrcat(msg, BAD_CAST "\n"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2535 | if (node->type == XML_ATTRIBUTE_NODE) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2536 | xmlSchemaPErr(ctxt, node, error, (const char *) msg, value, NULL); |
| 2537 | else |
| 2538 | xmlSchemaPErr(ctxt, node, error, (const char *) msg, NULL, NULL); |
| 2539 | } else { |
| 2540 | xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL, |
| 2541 | "%s%s.\n", msg, BAD_CAST message, str1, str2, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2542 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2543 | /* Cleanup. */ |
| 2544 | FREE_AND_NULL(msg) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2545 | } |
| 2546 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2547 | /** |
| 2548 | * xmlSchemaPContentErr: |
| 2549 | * @ctxt: the schema parser context |
| 2550 | * @error: the error code |
| 2551 | * @onwerDes: the designation of the holder of the content |
| 2552 | * @ownerItem: the owner item of the holder of the content |
| 2553 | * @ownerElem: the node of the holder of the content |
| 2554 | * @child: the invalid child node |
| 2555 | * @message: the optional error message |
| 2556 | * @content: the optional string describing the correct content |
| 2557 | * |
| 2558 | * Reports an error concerning the content of a schema element. |
| 2559 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2560 | static void |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2561 | xmlSchemaPContentErr(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2562 | xmlParserErrors error, |
| 2563 | xmlChar **ownerDes, |
| 2564 | xmlSchemaTypePtr ownerItem, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2565 | xmlNodePtr ownerElem, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2566 | xmlNodePtr child, |
| 2567 | const char *message, |
| 2568 | const char *content) |
| 2569 | { |
| 2570 | xmlChar *des = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2571 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2572 | if (ownerDes == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2573 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2574 | else if (*ownerDes == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2575 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, ownerElem); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2576 | des = *ownerDes; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2577 | } else |
| 2578 | des = *ownerDes; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2579 | if (message != NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2580 | xmlSchemaPErr2(ctxt, ownerElem, child, error, |
| 2581 | "%s: %s.\n", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2582 | BAD_CAST des, BAD_CAST message); |
| 2583 | else { |
| 2584 | if (content != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2585 | xmlSchemaPErr2(ctxt, ownerElem, child, error, |
| 2586 | "%s: The content is not valid. Expected is %s.\n", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2587 | BAD_CAST des, BAD_CAST content); |
| 2588 | } else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2589 | xmlSchemaPErr2(ctxt, ownerElem, child, error, |
| 2590 | "%s: The content is not valid.\n", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2591 | BAD_CAST des, NULL); |
| 2592 | } |
| 2593 | } |
| 2594 | if (ownerDes == NULL) |
| 2595 | FREE_AND_NULL(des) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2596 | } |
| 2597 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2598 | /************************************************************************ |
| 2599 | * * |
| 2600 | * Streamable error functions * |
| 2601 | * * |
| 2602 | ************************************************************************/ |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 2603 | |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 2604 | |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 2605 | |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 2606 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2607 | /************************************************************************ |
| 2608 | * * |
| 2609 | * Validation helper functions * |
| 2610 | * * |
| 2611 | ************************************************************************/ |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 2612 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2613 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2614 | /************************************************************************ |
| 2615 | * * |
| 2616 | * Allocation functions * |
| 2617 | * * |
| 2618 | ************************************************************************/ |
| 2619 | |
| 2620 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 2621 | * xmlSchemaNewSchemaForParserCtxt: |
William M. Brack | 0817191 | 2003-12-29 02:52:11 +0000 | [diff] [blame] | 2622 | * @ctxt: a schema validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2623 | * |
| 2624 | * Allocate a new Schema structure. |
| 2625 | * |
| 2626 | * Returns the newly allocated structure or NULL in case or error |
| 2627 | */ |
| 2628 | static xmlSchemaPtr |
| 2629 | xmlSchemaNewSchema(xmlSchemaParserCtxtPtr ctxt) |
| 2630 | { |
| 2631 | xmlSchemaPtr ret; |
| 2632 | |
| 2633 | ret = (xmlSchemaPtr) xmlMalloc(sizeof(xmlSchema)); |
| 2634 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2635 | xmlSchemaPErrMemory(ctxt, "allocating schema", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2636 | return (NULL); |
| 2637 | } |
| 2638 | memset(ret, 0, sizeof(xmlSchema)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2639 | ret->dict = ctxt->dict; |
Daniel Veillard | 500a1de | 2004-03-22 15:22:58 +0000 | [diff] [blame] | 2640 | xmlDictReference(ret->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2641 | |
| 2642 | return (ret); |
| 2643 | } |
| 2644 | |
| 2645 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 2646 | * xmlSchemaNewSchema: |
| 2647 | * @ctxt: a schema validation context |
| 2648 | * |
| 2649 | * Allocate a new Schema structure. |
| 2650 | * |
| 2651 | * Returns the newly allocated structure or NULL in case or error |
| 2652 | */ |
| 2653 | static xmlSchemaAssemblePtr |
| 2654 | xmlSchemaNewAssemble(void) |
| 2655 | { |
| 2656 | xmlSchemaAssemblePtr ret; |
| 2657 | |
| 2658 | ret = (xmlSchemaAssemblePtr) xmlMalloc(sizeof(xmlSchemaAssemble)); |
| 2659 | if (ret == NULL) { |
| 2660 | /* xmlSchemaPErrMemory(ctxt, "allocating assemble info", NULL); */ |
| 2661 | return (NULL); |
| 2662 | } |
| 2663 | memset(ret, 0, sizeof(xmlSchemaAssemble)); |
| 2664 | ret->items = NULL; |
| 2665 | return (ret); |
| 2666 | } |
| 2667 | |
| 2668 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2669 | * xmlSchemaNewFacet: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2670 | * |
| 2671 | * Allocate a new Facet structure. |
| 2672 | * |
| 2673 | * Returns the newly allocated structure or NULL in case or error |
| 2674 | */ |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 2675 | xmlSchemaFacetPtr |
| 2676 | xmlSchemaNewFacet(void) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2677 | { |
| 2678 | xmlSchemaFacetPtr ret; |
| 2679 | |
| 2680 | ret = (xmlSchemaFacetPtr) xmlMalloc(sizeof(xmlSchemaFacet)); |
| 2681 | if (ret == NULL) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2682 | return (NULL); |
| 2683 | } |
| 2684 | memset(ret, 0, sizeof(xmlSchemaFacet)); |
| 2685 | |
| 2686 | return (ret); |
| 2687 | } |
| 2688 | |
| 2689 | /** |
| 2690 | * xmlSchemaNewAnnot: |
William M. Brack | 0817191 | 2003-12-29 02:52:11 +0000 | [diff] [blame] | 2691 | * @ctxt: a schema validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2692 | * @node: a node |
| 2693 | * |
| 2694 | * Allocate a new annotation structure. |
| 2695 | * |
| 2696 | * Returns the newly allocated structure or NULL in case or error |
| 2697 | */ |
| 2698 | static xmlSchemaAnnotPtr |
| 2699 | xmlSchemaNewAnnot(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node) |
| 2700 | { |
| 2701 | xmlSchemaAnnotPtr ret; |
| 2702 | |
| 2703 | ret = (xmlSchemaAnnotPtr) xmlMalloc(sizeof(xmlSchemaAnnot)); |
| 2704 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2705 | xmlSchemaPErrMemory(ctxt, "allocating annotation", node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2706 | return (NULL); |
| 2707 | } |
| 2708 | memset(ret, 0, sizeof(xmlSchemaAnnot)); |
| 2709 | ret->content = node; |
| 2710 | return (ret); |
| 2711 | } |
| 2712 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 2713 | static xmlSchemaItemListPtr |
| 2714 | xmlSchemaNewItemList(void) |
| 2715 | { |
| 2716 | xmlSchemaItemListPtr ret; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2717 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 2718 | ret = xmlMalloc(sizeof(xmlSchemaItemList)); |
| 2719 | if (ret == NULL) { |
| 2720 | xmlSchemaPErrMemory(NULL, |
| 2721 | "allocating an item list structure", NULL); |
| 2722 | return (NULL); |
| 2723 | } |
| 2724 | memset(ret, 0, sizeof(xmlSchemaItemList)); |
| 2725 | return (ret); |
| 2726 | } |
| 2727 | |
| 2728 | /** |
| 2729 | * xmlSchemaAddElementSubstitutionMember: |
| 2730 | * @pctxt: a schema parser context |
| 2731 | * @head: the head of the substitution group |
| 2732 | * @member: the new member of the substitution group |
| 2733 | * |
| 2734 | * Allocate a new annotation structure. |
| 2735 | * |
| 2736 | * Returns the newly allocated structure or NULL in case or error |
| 2737 | */ |
| 2738 | static int |
| 2739 | xmlSchemaAddElementSubstitutionMember(xmlSchemaParserCtxtPtr pctxt, |
| 2740 | xmlSchemaElementPtr head, |
| 2741 | xmlSchemaElementPtr member) |
| 2742 | { |
| 2743 | xmlSchemaSubstGroupPtr substGroup; |
| 2744 | |
| 2745 | if (pctxt == NULL) |
| 2746 | return (-1); |
| 2747 | |
| 2748 | if (pctxt->substGroups == NULL) { |
| 2749 | pctxt->substGroups = xmlHashCreateDict(10, pctxt->dict); |
| 2750 | if (pctxt->substGroups == NULL) |
| 2751 | return (-1); |
| 2752 | } |
| 2753 | substGroup = xmlHashLookup2(pctxt->substGroups, head->name, |
| 2754 | head->targetNamespace); |
| 2755 | if (substGroup == NULL) { |
| 2756 | int res; |
| 2757 | |
| 2758 | substGroup = (xmlSchemaSubstGroupPtr) xmlMalloc(sizeof(xmlSchemaSubstGroup)); |
| 2759 | if (substGroup == NULL) { |
| 2760 | xmlSchemaPErrMemory(NULL, |
| 2761 | "xmlSchemaAddElementSubstitution, allocating a substitution " |
| 2762 | "group container", |
| 2763 | NULL); |
| 2764 | return (-1); |
| 2765 | } |
| 2766 | substGroup->members = xmlSchemaNewItemList(); |
| 2767 | if (substGroup->members == NULL) { |
| 2768 | xmlFree(substGroup); |
| 2769 | return (-1); |
| 2770 | } |
| 2771 | substGroup->head = head; |
| 2772 | |
| 2773 | res = xmlHashAddEntry2(pctxt->substGroups, |
| 2774 | head->name, head->targetNamespace, substGroup); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2775 | if (res != 0) { |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 2776 | xmlFree(substGroup->members); |
| 2777 | xmlFree(substGroup); |
| 2778 | xmlSchemaPErr(pctxt, member->node, |
| 2779 | XML_SCHEMAP_INTERNAL, |
| 2780 | "Internal error: xmlSchemaAddElementSubstitution, " |
| 2781 | "failed to add a new substitution group container for " |
| 2782 | "'%s'.\n", head->name, NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2783 | return (-1); |
| 2784 | } |
| 2785 | } |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 2786 | if (substGroup->members->items == NULL) { |
| 2787 | substGroup->members->items = (void **) xmlMalloc( |
| 2788 | 5 * sizeof(xmlSchemaElementPtr)); |
| 2789 | if (substGroup->members->items == NULL) { |
| 2790 | xmlSchemaPErrMemory(NULL, |
| 2791 | "allocating list of substitution group members", NULL); |
| 2792 | return (-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2793 | } |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 2794 | substGroup->members->sizeItems = 5; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2795 | } else if (substGroup->members->sizeItems <= |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 2796 | substGroup->members->nbItems) { |
| 2797 | substGroup->members->sizeItems *= 2; |
| 2798 | substGroup->members->items = (void **) xmlRealloc( |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2799 | substGroup->members->items, |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 2800 | substGroup->members->sizeItems * sizeof(xmlSchemaElementPtr)); |
| 2801 | if (substGroup->members->items == NULL) { |
| 2802 | xmlSchemaPErrMemory(NULL, |
| 2803 | "re-allocating list of substitution group members", NULL); |
| 2804 | substGroup->members->sizeItems = 0; |
| 2805 | return (-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2806 | } |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 2807 | } |
| 2808 | ((xmlSchemaElementPtr *) substGroup->members->items) |
| 2809 | [substGroup->members->nbItems++] = (void *) member; |
| 2810 | return (0); |
| 2811 | } |
| 2812 | |
| 2813 | /** |
| 2814 | * xmlSchemaGetElementSubstitutionGroup: |
| 2815 | * @pctxt: a schema parser context |
| 2816 | * @head: the head of the substitution group |
| 2817 | * @member: the new member of the substitution group |
| 2818 | * |
| 2819 | * Allocate a new annotation structure. |
| 2820 | * |
| 2821 | * Returns the newly allocated structure or NULL in case or error |
| 2822 | */ |
| 2823 | static xmlSchemaSubstGroupPtr |
| 2824 | xmlSchemaGetElementSubstitutionGroup(xmlSchemaParserCtxtPtr pctxt, |
| 2825 | xmlSchemaElementPtr head) |
| 2826 | { |
| 2827 | if (pctxt == NULL) |
| 2828 | return (NULL); |
| 2829 | |
| 2830 | if (pctxt->substGroups == NULL) |
| 2831 | return (NULL); |
| 2832 | |
| 2833 | return ((xmlSchemaSubstGroupPtr) xmlHashLookup2(pctxt->substGroups, |
| 2834 | head->name, head->targetNamespace)); |
| 2835 | } |
| 2836 | |
| 2837 | /** |
| 2838 | * xmlSchemaFreeItemList: |
| 2839 | * @annot: a schema type structure |
| 2840 | * |
| 2841 | * Deallocate a annotation structure |
| 2842 | */ |
| 2843 | static void |
| 2844 | xmlSchemaFreeItemList(xmlSchemaItemListPtr list) |
| 2845 | { |
| 2846 | if (list == NULL) |
| 2847 | return; |
| 2848 | if (list->items != NULL) |
| 2849 | xmlFree(list->items); |
| 2850 | xmlFree(list); |
| 2851 | } |
| 2852 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2853 | /** |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 2854 | * xmlSchemaFreeAnnot: |
| 2855 | * @annot: a schema type structure |
| 2856 | * |
| 2857 | * Deallocate a annotation structure |
| 2858 | */ |
| 2859 | static void |
| 2860 | xmlSchemaFreeAnnot(xmlSchemaAnnotPtr annot) |
| 2861 | { |
| 2862 | if (annot == NULL) |
| 2863 | return; |
| 2864 | xmlFree(annot); |
| 2865 | } |
| 2866 | |
| 2867 | /** |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 2868 | * xmlSchemaFreeImport: |
| 2869 | * @import: a schema import structure |
| 2870 | * |
| 2871 | * Deallocate an import structure |
| 2872 | */ |
| 2873 | static void |
| 2874 | xmlSchemaFreeImport(xmlSchemaImportPtr import) |
| 2875 | { |
| 2876 | if (import == NULL) |
| 2877 | return; |
| 2878 | |
| 2879 | xmlSchemaFree(import->schema); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2880 | xmlFreeDoc(import->doc); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 2881 | xmlFree(import); |
| 2882 | } |
| 2883 | |
| 2884 | /** |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 2885 | * xmlSchemaFreeInclude: |
| 2886 | * @include: a schema include structure |
| 2887 | * |
| 2888 | * Deallocate an include structure |
| 2889 | */ |
| 2890 | static void |
| 2891 | xmlSchemaFreeInclude(xmlSchemaIncludePtr include) |
| 2892 | { |
| 2893 | if (include == NULL) |
| 2894 | return; |
| 2895 | |
| 2896 | xmlFreeDoc(include->doc); |
| 2897 | xmlFree(include); |
| 2898 | } |
| 2899 | |
| 2900 | /** |
| 2901 | * xmlSchemaFreeIncludeList: |
| 2902 | * @includes: a schema include list |
| 2903 | * |
| 2904 | * Deallocate an include structure |
| 2905 | */ |
| 2906 | static void |
| 2907 | xmlSchemaFreeIncludeList(xmlSchemaIncludePtr includes) |
| 2908 | { |
| 2909 | xmlSchemaIncludePtr next; |
| 2910 | |
| 2911 | while (includes != NULL) { |
| 2912 | next = includes->next; |
| 2913 | xmlSchemaFreeInclude(includes); |
| 2914 | includes = next; |
| 2915 | } |
| 2916 | } |
| 2917 | |
| 2918 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2919 | * xmlSchemaFreeNotation: |
| 2920 | * @schema: a schema notation structure |
| 2921 | * |
| 2922 | * Deallocate a Schema Notation structure. |
| 2923 | */ |
| 2924 | static void |
| 2925 | xmlSchemaFreeNotation(xmlSchemaNotationPtr nota) |
| 2926 | { |
| 2927 | if (nota == NULL) |
| 2928 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2929 | xmlFree(nota); |
| 2930 | } |
| 2931 | |
| 2932 | /** |
| 2933 | * xmlSchemaFreeAttribute: |
| 2934 | * @schema: a schema attribute structure |
| 2935 | * |
| 2936 | * Deallocate a Schema Attribute structure. |
| 2937 | */ |
| 2938 | static void |
| 2939 | xmlSchemaFreeAttribute(xmlSchemaAttributePtr attr) |
| 2940 | { |
| 2941 | if (attr == NULL) |
| 2942 | return; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2943 | if (attr->annot != NULL) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2944 | xmlSchemaFreeAnnot(attr->annot); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 2945 | if (attr->defVal != NULL) |
| 2946 | xmlSchemaFreeValue(attr->defVal); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2947 | xmlFree(attr); |
| 2948 | } |
| 2949 | |
| 2950 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2951 | * xmlSchemaFreeWildcardNsSet: |
| 2952 | * set: a schema wildcard namespace |
| 2953 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2954 | * Deallocates a list of wildcard constraint structures. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2955 | */ |
| 2956 | static void |
| 2957 | xmlSchemaFreeWildcardNsSet(xmlSchemaWildcardNsPtr set) |
| 2958 | { |
| 2959 | xmlSchemaWildcardNsPtr next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2960 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2961 | while (set != NULL) { |
| 2962 | next = set->next; |
| 2963 | xmlFree(set); |
| 2964 | set = next; |
| 2965 | } |
| 2966 | } |
| 2967 | |
| 2968 | /** |
| 2969 | * xmlSchemaFreeWildcard: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2970 | * @wildcard: a wildcard structure |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2971 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2972 | * Deallocates a wildcard structure. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2973 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2974 | void |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2975 | xmlSchemaFreeWildcard(xmlSchemaWildcardPtr wildcard) |
| 2976 | { |
| 2977 | if (wildcard == NULL) |
| 2978 | return; |
| 2979 | if (wildcard->annot != NULL) |
| 2980 | xmlSchemaFreeAnnot(wildcard->annot); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2981 | if (wildcard->nsSet != NULL) |
| 2982 | xmlSchemaFreeWildcardNsSet(wildcard->nsSet); |
| 2983 | if (wildcard->negNsSet != NULL) |
| 2984 | xmlFree(wildcard->negNsSet); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2985 | xmlFree(wildcard); |
| 2986 | } |
| 2987 | |
| 2988 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2989 | * xmlSchemaFreeAttributeGroup: |
| 2990 | * @schema: a schema attribute group structure |
| 2991 | * |
| 2992 | * Deallocate a Schema Attribute Group structure. |
| 2993 | */ |
| 2994 | static void |
| 2995 | xmlSchemaFreeAttributeGroup(xmlSchemaAttributeGroupPtr attr) |
| 2996 | { |
| 2997 | if (attr == NULL) |
| 2998 | return; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2999 | if (attr->annot != NULL) |
| 3000 | xmlSchemaFreeAnnot(attr->annot); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3001 | xmlFree(attr); |
| 3002 | } |
| 3003 | |
| 3004 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3005 | * xmlSchemaFreeAttributeUseList: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3006 | * @attrUse: an attribute link |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3007 | * |
| 3008 | * Deallocate a list of schema attribute uses. |
| 3009 | */ |
| 3010 | static void |
| 3011 | xmlSchemaFreeAttributeUseList(xmlSchemaAttributeLinkPtr attrUse) |
| 3012 | { |
| 3013 | xmlSchemaAttributeLinkPtr next; |
| 3014 | |
| 3015 | while (attrUse != NULL) { |
| 3016 | next = attrUse->next; |
| 3017 | xmlFree(attrUse); |
| 3018 | attrUse = next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3019 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3020 | } |
| 3021 | |
| 3022 | /** |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3023 | * xmlSchemaFreeQNameRef: |
| 3024 | * @item: a QName reference structure |
| 3025 | * |
| 3026 | * Deallocatea a QName reference structure. |
| 3027 | */ |
| 3028 | static void |
| 3029 | xmlSchemaFreeQNameRef(xmlSchemaQNameRefPtr item) |
| 3030 | { |
| 3031 | xmlFree(item); |
| 3032 | } |
| 3033 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 3034 | /** |
| 3035 | * xmlSchemaFreeQNameRef: |
| 3036 | * @item: a QName reference structure |
| 3037 | * |
| 3038 | * Deallocatea a QName reference structure. |
| 3039 | */ |
| 3040 | static void |
| 3041 | xmlSchemaFreeSubstGroup(xmlSchemaSubstGroupPtr item) |
| 3042 | { |
| 3043 | if (item == NULL) |
| 3044 | return; |
| 3045 | if (item->members != NULL) |
| 3046 | xmlSchemaFreeItemList(item->members); |
| 3047 | xmlFree(item); |
| 3048 | } |
| 3049 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3050 | static int |
| 3051 | xmlSchemaAddVolatile(xmlSchemaPtr schema, |
| 3052 | xmlSchemaBasicItemPtr item) |
| 3053 | { |
| 3054 | xmlSchemaItemListPtr list; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3055 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3056 | if (schema->volatiles == NULL) { |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 3057 | schema->volatiles = (void *) xmlSchemaNewItemList(); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3058 | if (schema->volatiles == NULL) { |
| 3059 | xmlSchemaPErrMemory(NULL, |
| 3060 | "allocating list of volatiles", NULL); |
| 3061 | return (-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3062 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3063 | } |
| 3064 | list = (xmlSchemaItemListPtr) schema->volatiles; |
| 3065 | if (list->items == NULL) { |
| 3066 | list->items = (void **) xmlMalloc( |
| 3067 | 20 * sizeof(xmlSchemaBasicItemPtr)); |
| 3068 | if (list->items == NULL) { |
| 3069 | xmlSchemaPErrMemory(NULL, |
| 3070 | "allocating new volatile item buffer", NULL); |
| 3071 | return (-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3072 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3073 | list->sizeItems = 20; |
| 3074 | } else if (list->sizeItems <= list->nbItems) { |
| 3075 | list->sizeItems *= 2; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3076 | list->items = (void **) xmlRealloc(list->items, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3077 | list->sizeItems * sizeof(xmlSchemaTypePtr)); |
| 3078 | if (list->items == NULL) { |
| 3079 | xmlSchemaPErrMemory(NULL, |
| 3080 | "growing volatile item buffer", NULL); |
| 3081 | list->sizeItems = 0; |
| 3082 | return (-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3083 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3084 | } |
| 3085 | ((xmlSchemaBasicItemPtr *) list->items)[list->nbItems++] = (void *) item; |
| 3086 | return (0); |
| 3087 | } |
| 3088 | |
| 3089 | /** |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3090 | * xmlSchemaFreeTypeLinkList: |
| 3091 | * @alink: a type link |
| 3092 | * |
| 3093 | * Deallocate a list of types. |
| 3094 | */ |
| 3095 | static void |
| 3096 | xmlSchemaFreeTypeLinkList(xmlSchemaTypeLinkPtr link) |
| 3097 | { |
| 3098 | xmlSchemaTypeLinkPtr next; |
| 3099 | |
| 3100 | while (link != NULL) { |
| 3101 | next = link->next; |
| 3102 | xmlFree(link); |
| 3103 | link = next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3104 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3105 | } |
| 3106 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3107 | static void |
| 3108 | xmlSchemaFreeIDCStateObjList(xmlSchemaIDCStateObjPtr sto) |
| 3109 | { |
| 3110 | xmlSchemaIDCStateObjPtr next; |
| 3111 | while (sto != NULL) { |
| 3112 | next = sto->next; |
| 3113 | if (sto->history != NULL) |
| 3114 | xmlFree(sto->history); |
| 3115 | if (sto->xpathCtxt != NULL) |
| 3116 | xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt); |
| 3117 | xmlFree(sto); |
| 3118 | sto = next; |
| 3119 | } |
| 3120 | } |
| 3121 | |
| 3122 | /** |
| 3123 | * xmlSchemaFreeIDC: |
| 3124 | * @idc: a identity-constraint definition |
| 3125 | * |
| 3126 | * Deallocates an identity-constraint definition. |
| 3127 | */ |
| 3128 | static void |
| 3129 | xmlSchemaFreeIDC(xmlSchemaIDCPtr idcDef) |
| 3130 | { |
| 3131 | xmlSchemaIDCSelectPtr cur, prev; |
| 3132 | |
| 3133 | if (idcDef == NULL) |
| 3134 | return; |
| 3135 | if (idcDef->annot != NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3136 | xmlSchemaFreeAnnot(idcDef->annot); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3137 | /* Selector */ |
| 3138 | if (idcDef->selector != NULL) { |
| 3139 | if (idcDef->selector->xpathComp != NULL) |
| 3140 | xmlFreePattern((xmlPatternPtr) idcDef->selector->xpathComp); |
| 3141 | xmlFree(idcDef->selector); |
| 3142 | } |
| 3143 | /* Fields */ |
| 3144 | if (idcDef->fields != NULL) { |
| 3145 | cur = idcDef->fields; |
| 3146 | do { |
| 3147 | prev = cur; |
| 3148 | cur = cur->next; |
| 3149 | if (prev->xpathComp != NULL) |
| 3150 | xmlFreePattern((xmlPatternPtr) prev->xpathComp); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3151 | xmlFree(prev); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3152 | } while (cur != NULL); |
| 3153 | } |
| 3154 | xmlFree(idcDef); |
| 3155 | } |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3156 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3157 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3158 | * xmlSchemaFreeElement: |
| 3159 | * @schema: a schema element structure |
| 3160 | * |
| 3161 | * Deallocate a Schema Element structure. |
| 3162 | */ |
| 3163 | static void |
| 3164 | xmlSchemaFreeElement(xmlSchemaElementPtr elem) |
| 3165 | { |
| 3166 | if (elem == NULL) |
| 3167 | return; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 3168 | if (elem->annot != NULL) |
| 3169 | xmlSchemaFreeAnnot(elem->annot); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3170 | if (elem->contModel != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3171 | xmlRegFreeRegexp(elem->contModel); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 3172 | if (elem->defVal != NULL) |
| 3173 | xmlSchemaFreeValue(elem->defVal); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3174 | xmlFree(elem); |
| 3175 | } |
| 3176 | |
| 3177 | /** |
| 3178 | * xmlSchemaFreeFacet: |
| 3179 | * @facet: a schema facet structure |
| 3180 | * |
| 3181 | * Deallocate a Schema Facet structure. |
| 3182 | */ |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 3183 | void |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3184 | xmlSchemaFreeFacet(xmlSchemaFacetPtr facet) |
| 3185 | { |
| 3186 | if (facet == NULL) |
| 3187 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3188 | if (facet->val != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3189 | xmlSchemaFreeValue(facet->val); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3190 | if (facet->regexp != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3191 | xmlRegFreeRegexp(facet->regexp); |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 3192 | if (facet->annot != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3193 | xmlSchemaFreeAnnot(facet->annot); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3194 | xmlFree(facet); |
| 3195 | } |
| 3196 | |
| 3197 | /** |
| 3198 | * xmlSchemaFreeType: |
| 3199 | * @type: a schema type structure |
| 3200 | * |
| 3201 | * Deallocate a Schema Type structure. |
| 3202 | */ |
| 3203 | void |
| 3204 | xmlSchemaFreeType(xmlSchemaTypePtr type) |
| 3205 | { |
| 3206 | if (type == NULL) |
| 3207 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3208 | if (type->annot != NULL) |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 3209 | xmlSchemaFreeAnnot(type->annot); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3210 | if (type->facets != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3211 | xmlSchemaFacetPtr facet, next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3212 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3213 | facet = type->facets; |
| 3214 | while (facet != NULL) { |
| 3215 | next = facet->next; |
| 3216 | xmlSchemaFreeFacet(facet); |
| 3217 | facet = next; |
| 3218 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3219 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3220 | if (type->type != XML_SCHEMA_TYPE_BASIC) { |
| 3221 | if (type->attributeUses != NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3222 | xmlSchemaFreeAttributeUseList(type->attributeUses); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3223 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3224 | if (type->memberTypes != NULL) |
| 3225 | xmlSchemaFreeTypeLinkList(type->memberTypes); |
| 3226 | if (type->facetSet != NULL) { |
| 3227 | xmlSchemaFacetLinkPtr next, link; |
| 3228 | |
| 3229 | link = type->facetSet; |
| 3230 | do { |
| 3231 | next = link->next; |
| 3232 | xmlFree(link); |
| 3233 | link = next; |
| 3234 | } while (link != NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3235 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3236 | if (type->contModel != NULL) |
| 3237 | xmlRegFreeRegexp(type->contModel); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3238 | xmlFree(type); |
| 3239 | } |
| 3240 | |
| 3241 | /** |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3242 | * xmlSchemaFreeModelGroupDef: |
| 3243 | * @item: a schema model group definition |
| 3244 | * |
| 3245 | * Deallocates a schema model group definition. |
| 3246 | */ |
| 3247 | static void |
| 3248 | xmlSchemaFreeModelGroupDef(xmlSchemaModelGroupDefPtr item) |
| 3249 | { |
| 3250 | if (item->annot != NULL) |
| 3251 | xmlSchemaFreeAnnot(item->annot); |
| 3252 | xmlFree(item); |
| 3253 | } |
| 3254 | |
| 3255 | /** |
| 3256 | * xmlSchemaFreeModelGroup: |
| 3257 | * @item: a schema model group |
| 3258 | * |
| 3259 | * Deallocates a schema model group structure. |
| 3260 | */ |
| 3261 | static void |
| 3262 | xmlSchemaFreeModelGroup(xmlSchemaModelGroupPtr item) |
| 3263 | { |
| 3264 | if (item->annot != NULL) |
| 3265 | xmlSchemaFreeAnnot(item->annot); |
| 3266 | xmlFree(item); |
| 3267 | } |
| 3268 | |
| 3269 | /** |
| 3270 | * xmlSchemaFreeParticle: |
| 3271 | * @type: a schema type structure |
| 3272 | * |
| 3273 | * Deallocate a Schema Type structure. |
| 3274 | */ |
| 3275 | static void |
| 3276 | xmlSchemaFreeParticle(xmlSchemaParticlePtr item) |
| 3277 | { |
| 3278 | if (item->annot != NULL) |
| 3279 | xmlSchemaFreeAnnot(item->annot); |
| 3280 | xmlFree(item); |
| 3281 | } |
| 3282 | |
| 3283 | /** |
| 3284 | * xmlSchemaFreeMiscComponents: |
| 3285 | * @item: a schema component |
| 3286 | * |
| 3287 | * Deallocates misc. schema component structures. |
| 3288 | */ |
| 3289 | static void |
| 3290 | xmlSchemaFreeMiscComponents(xmlSchemaTreeItemPtr item) |
| 3291 | { |
| 3292 | if (item == NULL) |
| 3293 | return; |
| 3294 | switch (item->type) { |
| 3295 | case XML_SCHEMA_TYPE_PARTICLE: |
| 3296 | xmlSchemaFreeParticle((xmlSchemaParticlePtr) item); |
| 3297 | return; |
| 3298 | case XML_SCHEMA_TYPE_SEQUENCE: |
| 3299 | case XML_SCHEMA_TYPE_CHOICE: |
| 3300 | case XML_SCHEMA_TYPE_ALL: |
| 3301 | xmlSchemaFreeModelGroup((xmlSchemaModelGroupPtr) item); |
| 3302 | return; |
| 3303 | case XML_SCHEMA_TYPE_ANY: |
| 3304 | case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: |
| 3305 | xmlSchemaFreeWildcard((xmlSchemaWildcardPtr) item); |
| 3306 | break; |
| 3307 | default: |
| 3308 | /* TODO: This should never be hit. */ |
| 3309 | TODO |
| 3310 | return; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3311 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | static void |
| 3315 | xmlSchemaFreeVolatiles(xmlSchemaPtr schema) |
| 3316 | { |
| 3317 | if (schema->volatiles == NULL) |
| 3318 | return; |
| 3319 | { |
| 3320 | xmlSchemaItemListPtr list = (xmlSchemaItemListPtr) schema->volatiles; |
| 3321 | xmlSchemaTreeItemPtr item; |
| 3322 | int i; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3323 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3324 | for (i = 0; i < list->nbItems; i++) { |
| 3325 | if (list->items[i] != NULL) { |
| 3326 | item = (xmlSchemaTreeItemPtr) list->items[i]; |
| 3327 | switch (item->type) { |
| 3328 | case XML_SCHEMA_EXTRA_QNAMEREF: |
| 3329 | xmlSchemaFreeQNameRef((xmlSchemaQNameRefPtr) item); |
| 3330 | break; |
| 3331 | default: |
| 3332 | xmlSchemaFreeMiscComponents(item); |
| 3333 | } |
| 3334 | } |
| 3335 | } |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 3336 | xmlSchemaFreeItemList(list); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3337 | } |
| 3338 | } |
| 3339 | /** |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 3340 | * xmlSchemaFreeTypeList: |
| 3341 | * @type: a schema type structure |
| 3342 | * |
| 3343 | * Deallocate a Schema Type structure. |
| 3344 | */ |
| 3345 | static void |
| 3346 | xmlSchemaFreeTypeList(xmlSchemaTypePtr type) |
| 3347 | { |
| 3348 | xmlSchemaTypePtr next; |
| 3349 | |
| 3350 | while (type != NULL) { |
| 3351 | next = type->redef; |
| 3352 | xmlSchemaFreeType(type); |
| 3353 | type = next; |
| 3354 | } |
| 3355 | } |
| 3356 | |
| 3357 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3358 | * xmlSchemaFree: |
| 3359 | * @schema: a schema structure |
| 3360 | * |
| 3361 | * Deallocate a Schema structure. |
| 3362 | */ |
| 3363 | void |
| 3364 | xmlSchemaFree(xmlSchemaPtr schema) |
| 3365 | { |
| 3366 | if (schema == NULL) |
| 3367 | return; |
| 3368 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3369 | if (schema->volatiles != NULL) |
| 3370 | xmlSchemaFreeVolatiles(schema); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3371 | if (schema->notaDecl != NULL) |
| 3372 | xmlHashFree(schema->notaDecl, |
| 3373 | (xmlHashDeallocator) xmlSchemaFreeNotation); |
| 3374 | if (schema->attrDecl != NULL) |
| 3375 | xmlHashFree(schema->attrDecl, |
| 3376 | (xmlHashDeallocator) xmlSchemaFreeAttribute); |
| 3377 | if (schema->attrgrpDecl != NULL) |
| 3378 | xmlHashFree(schema->attrgrpDecl, |
| 3379 | (xmlHashDeallocator) xmlSchemaFreeAttributeGroup); |
| 3380 | if (schema->elemDecl != NULL) |
| 3381 | xmlHashFree(schema->elemDecl, |
| 3382 | (xmlHashDeallocator) xmlSchemaFreeElement); |
| 3383 | if (schema->typeDecl != NULL) |
| 3384 | xmlHashFree(schema->typeDecl, |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 3385 | (xmlHashDeallocator) xmlSchemaFreeTypeList); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 3386 | if (schema->groupDecl != NULL) |
| 3387 | xmlHashFree(schema->groupDecl, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3388 | (xmlHashDeallocator) xmlSchemaFreeModelGroupDef); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3389 | if (schema->idcDef != NULL) |
| 3390 | xmlHashFree(schema->idcDef, |
| 3391 | (xmlHashDeallocator) xmlSchemaFreeIDC); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 3392 | if (schema->schemasImports != NULL) |
| 3393 | xmlHashFree(schema->schemasImports, |
| 3394 | (xmlHashDeallocator) xmlSchemaFreeImport); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 3395 | if (schema->includes != NULL) { |
| 3396 | xmlSchemaFreeIncludeList((xmlSchemaIncludePtr) schema->includes); |
| 3397 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3398 | if (schema->annot != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3399 | xmlSchemaFreeAnnot(schema->annot); |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 3400 | if (schema->doc != NULL && !schema->preserve) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3401 | xmlFreeDoc(schema->doc); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3402 | xmlDictFree(schema->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3403 | xmlFree(schema); |
| 3404 | } |
| 3405 | |
| 3406 | /************************************************************************ |
| 3407 | * * |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3408 | * Debug functions * |
| 3409 | * * |
| 3410 | ************************************************************************/ |
| 3411 | |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 3412 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3413 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3414 | /** |
| 3415 | * xmlSchemaElementDump: |
| 3416 | * @elem: an element |
| 3417 | * @output: the file output |
| 3418 | * |
| 3419 | * Dump the element |
| 3420 | */ |
| 3421 | static void |
| 3422 | xmlSchemaElementDump(xmlSchemaElementPtr elem, FILE * output, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3423 | const xmlChar * name ATTRIBUTE_UNUSED, |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3424 | const xmlChar * namespace ATTRIBUTE_UNUSED, |
| 3425 | const xmlChar * context ATTRIBUTE_UNUSED) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3426 | { |
| 3427 | if (elem == NULL) |
| 3428 | return; |
| 3429 | |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3430 | if (elem->flags & XML_SCHEMAS_ELEM_REF) { |
| 3431 | fprintf(output, "Particle: %s", name); |
| 3432 | fprintf(output, ", term element: %s", elem->ref); |
| 3433 | if (elem->refNs != NULL) |
| 3434 | fprintf(output, " ns %s", elem->refNs); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3435 | } else { |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3436 | fprintf(output, "Element"); |
| 3437 | if (elem->flags & XML_SCHEMAS_ELEM_GLOBAL) |
| 3438 | fprintf(output, " (global)"); |
| 3439 | fprintf(output, ": %s ", elem->name); |
| 3440 | if (namespace != NULL) |
| 3441 | fprintf(output, "ns %s", namespace); |
| 3442 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3443 | fprintf(output, "\n"); |
| 3444 | if ((elem->minOccurs != 1) || (elem->maxOccurs != 1)) { |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3445 | fprintf(output, " min %d ", elem->minOccurs); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3446 | if (elem->maxOccurs >= UNBOUNDED) |
| 3447 | fprintf(output, "max: unbounded\n"); |
| 3448 | else if (elem->maxOccurs != 1) |
| 3449 | fprintf(output, "max: %d\n", elem->maxOccurs); |
| 3450 | else |
| 3451 | fprintf(output, "\n"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3452 | } |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3453 | /* |
| 3454 | * Misc other properties. |
| 3455 | */ |
| 3456 | if ((elem->flags & XML_SCHEMAS_ELEM_NILLABLE) || |
| 3457 | (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT) || |
| 3458 | (elem->flags & XML_SCHEMAS_ELEM_FIXED) || |
| 3459 | (elem->flags & XML_SCHEMAS_ELEM_DEFAULT) || |
| 3460 | (elem->id != NULL)) { |
| 3461 | fprintf(output, " props: "); |
| 3462 | if (elem->flags & XML_SCHEMAS_ELEM_FIXED) |
| 3463 | fprintf(output, "[fixed] "); |
| 3464 | if (elem->flags & XML_SCHEMAS_ELEM_DEFAULT) |
| 3465 | fprintf(output, "[default] "); |
| 3466 | if (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT) |
| 3467 | fprintf(output, "[abstract] "); |
| 3468 | if (elem->flags & XML_SCHEMAS_ELEM_NILLABLE) |
| 3469 | fprintf(output, "[nillable] "); |
| 3470 | if (elem->id != NULL) |
| 3471 | fprintf(output, "[id: '%s'] ", elem->id); |
| 3472 | fprintf(output, "\n"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3473 | } |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3474 | /* |
| 3475 | * Default/fixed value. |
| 3476 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3477 | if (elem->value != NULL) |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3478 | fprintf(output, " value: '%s'\n", elem->value); |
| 3479 | /* |
| 3480 | * Type. |
| 3481 | */ |
| 3482 | if (elem->namedType != NULL) { |
| 3483 | fprintf(output, " type: %s ", elem->namedType); |
| 3484 | if (elem->namedTypeNs != NULL) |
| 3485 | fprintf(output, "ns %s\n", elem->namedTypeNs); |
| 3486 | else |
| 3487 | fprintf(output, "\n"); |
| 3488 | } |
| 3489 | /* |
| 3490 | * Substitution group. |
| 3491 | */ |
| 3492 | if (elem->substGroup != NULL) { |
| 3493 | fprintf(output, " substitutionGroup: %s ", elem->substGroup); |
| 3494 | if (elem->substGroupNs != NULL) |
| 3495 | fprintf(output, "ns %s\n", elem->substGroupNs); |
| 3496 | else |
| 3497 | fprintf(output, "\n"); |
| 3498 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3499 | } |
| 3500 | |
| 3501 | /** |
| 3502 | * xmlSchemaAnnotDump: |
| 3503 | * @output: the file output |
| 3504 | * @annot: a annotation |
| 3505 | * |
| 3506 | * Dump the annotation |
| 3507 | */ |
| 3508 | static void |
| 3509 | xmlSchemaAnnotDump(FILE * output, xmlSchemaAnnotPtr annot) |
| 3510 | { |
| 3511 | xmlChar *content; |
| 3512 | |
| 3513 | if (annot == NULL) |
| 3514 | return; |
| 3515 | |
| 3516 | content = xmlNodeGetContent(annot->content); |
| 3517 | if (content != NULL) { |
| 3518 | fprintf(output, " Annot: %s\n", content); |
| 3519 | xmlFree(content); |
| 3520 | } else |
| 3521 | fprintf(output, " Annot: empty\n"); |
| 3522 | } |
| 3523 | |
| 3524 | /** |
| 3525 | * xmlSchemaTypeDump: |
| 3526 | * @output: the file output |
| 3527 | * @type: a type structure |
| 3528 | * |
| 3529 | * Dump a SchemaType structure |
| 3530 | */ |
| 3531 | static void |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3532 | xmlSchemaContentModelDump(xmlSchemaParticlePtr particle, FILE * output, int depth) |
| 3533 | { |
| 3534 | xmlChar *str = NULL; |
| 3535 | xmlSchemaTreeItemPtr term; |
| 3536 | char shift[100]; |
| 3537 | int i; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3538 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3539 | if (particle == NULL) |
| 3540 | return; |
| 3541 | for (i = 0;((i < depth) && (i < 25));i++) |
| 3542 | shift[2 * i] = shift[2 * i + 1] = ' '; |
| 3543 | shift[2 * i] = shift[2 * i + 1] = 0; |
| 3544 | fprintf(output, shift); |
| 3545 | if (particle->children == NULL) { |
| 3546 | fprintf(output, "MISSING particle term\n"); |
| 3547 | return; |
| 3548 | } |
| 3549 | term = particle->children; |
| 3550 | switch (term->type) { |
| 3551 | case XML_SCHEMA_TYPE_ELEMENT: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3552 | fprintf(output, "ELEM '%s'", xmlSchemaFormatQName(&str, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3553 | ((xmlSchemaElementPtr)term)->targetNamespace, |
| 3554 | ((xmlSchemaElementPtr)term)->name)); |
| 3555 | break; |
| 3556 | case XML_SCHEMA_TYPE_SEQUENCE: |
| 3557 | fprintf(output, "SEQUENCE"); |
| 3558 | break; |
| 3559 | case XML_SCHEMA_TYPE_CHOICE: |
| 3560 | fprintf(output, "CHOICE"); |
| 3561 | break; |
| 3562 | case XML_SCHEMA_TYPE_ALL: |
| 3563 | fprintf(output, "ALL"); |
| 3564 | break; |
| 3565 | case XML_SCHEMA_TYPE_ANY: |
| 3566 | fprintf(output, "ANY"); |
| 3567 | break; |
| 3568 | default: |
| 3569 | fprintf(output, "UNKNOWN\n"); |
| 3570 | return; |
| 3571 | } |
| 3572 | if (particle->minOccurs != 1) |
| 3573 | fprintf(output, " min: %d", particle->minOccurs); |
| 3574 | if (particle->maxOccurs >= UNBOUNDED) |
| 3575 | fprintf(output, " max: unbounded"); |
| 3576 | else if (particle->maxOccurs != 1) |
| 3577 | fprintf(output, " max: %d", particle->maxOccurs); |
| 3578 | fprintf(output, "\n"); |
| 3579 | if (((term->type == XML_SCHEMA_TYPE_SEQUENCE) || |
| 3580 | (term->type == XML_SCHEMA_TYPE_CHOICE) || |
| 3581 | (term->type == XML_SCHEMA_TYPE_ALL)) && |
| 3582 | (term->children != NULL)) { |
| 3583 | xmlSchemaContentModelDump((xmlSchemaParticlePtr) term->children, |
| 3584 | output, depth +1); |
| 3585 | } |
| 3586 | if (particle->next != NULL) |
| 3587 | xmlSchemaContentModelDump((xmlSchemaParticlePtr) particle->next, |
| 3588 | output, depth); |
| 3589 | } |
| 3590 | /** |
| 3591 | * xmlSchemaTypeDump: |
| 3592 | * @output: the file output |
| 3593 | * @type: a type structure |
| 3594 | * |
| 3595 | * Dump a SchemaType structure |
| 3596 | */ |
| 3597 | static void |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3598 | xmlSchemaTypeDump(xmlSchemaTypePtr type, FILE * output) |
| 3599 | { |
| 3600 | if (type == NULL) { |
| 3601 | fprintf(output, "Type: NULL\n"); |
| 3602 | return; |
| 3603 | } |
| 3604 | fprintf(output, "Type: "); |
| 3605 | if (type->name != NULL) |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3606 | fprintf(output, "%s ", type->name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3607 | else |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3608 | fprintf(output, "no name "); |
| 3609 | if (type->targetNamespace != NULL) |
| 3610 | fprintf(output, "ns %s ", type->targetNamespace); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3611 | switch (type->type) { |
| 3612 | case XML_SCHEMA_TYPE_BASIC: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3613 | fprintf(output, "[basic] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3614 | break; |
| 3615 | case XML_SCHEMA_TYPE_SIMPLE: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3616 | fprintf(output, "[simple] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3617 | break; |
| 3618 | case XML_SCHEMA_TYPE_COMPLEX: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3619 | fprintf(output, "[complex] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3620 | break; |
| 3621 | case XML_SCHEMA_TYPE_SEQUENCE: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3622 | fprintf(output, "[sequence] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3623 | break; |
| 3624 | case XML_SCHEMA_TYPE_CHOICE: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3625 | fprintf(output, "[choice] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3626 | break; |
| 3627 | case XML_SCHEMA_TYPE_ALL: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3628 | fprintf(output, "[all] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3629 | break; |
| 3630 | case XML_SCHEMA_TYPE_UR: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3631 | fprintf(output, "[ur] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3632 | break; |
| 3633 | case XML_SCHEMA_TYPE_RESTRICTION: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3634 | fprintf(output, "[restriction] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3635 | break; |
| 3636 | case XML_SCHEMA_TYPE_EXTENSION: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3637 | fprintf(output, "[extension] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3638 | break; |
| 3639 | default: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3640 | fprintf(output, "[unknown type %d] ", type->type); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3641 | break; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3642 | } |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3643 | fprintf(output, "content: "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3644 | switch (type->contentType) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3645 | case XML_SCHEMA_CONTENT_UNKNOWN: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3646 | fprintf(output, "[unknown] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3647 | break; |
| 3648 | case XML_SCHEMA_CONTENT_EMPTY: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3649 | fprintf(output, "[empty] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3650 | break; |
| 3651 | case XML_SCHEMA_CONTENT_ELEMENTS: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3652 | fprintf(output, "[element] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3653 | break; |
| 3654 | case XML_SCHEMA_CONTENT_MIXED: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3655 | fprintf(output, "[mixed] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3656 | break; |
| 3657 | case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS: |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 3658 | /* not used. */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3659 | break; |
| 3660 | case XML_SCHEMA_CONTENT_BASIC: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3661 | fprintf(output, "[basic] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3662 | break; |
| 3663 | case XML_SCHEMA_CONTENT_SIMPLE: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3664 | fprintf(output, "[simple] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3665 | break; |
| 3666 | case XML_SCHEMA_CONTENT_ANY: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3667 | fprintf(output, "[any] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3668 | break; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3669 | } |
| 3670 | fprintf(output, "\n"); |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3671 | if (type->base != NULL) { |
| 3672 | fprintf(output, " base type: %s", type->base); |
| 3673 | if (type->baseNs != NULL) |
| 3674 | fprintf(output, " ns %s\n", type->baseNs); |
| 3675 | else |
| 3676 | fprintf(output, "\n"); |
| 3677 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3678 | if (type->annot != NULL) |
| 3679 | xmlSchemaAnnotDump(output, type->annot); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3680 | #ifdef DUMP_CONTENT_MODEL |
| 3681 | if ((type->type == XML_SCHEMA_TYPE_COMPLEX) && |
| 3682 | (type->subtypes != NULL)) { |
| 3683 | xmlSchemaContentModelDump((xmlSchemaParticlePtr) type->subtypes, |
| 3684 | output, 1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3685 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3686 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | /** |
| 3690 | * xmlSchemaDump: |
| 3691 | * @output: the file output |
| 3692 | * @schema: a schema structure |
| 3693 | * |
| 3694 | * Dump a Schema structure. |
| 3695 | */ |
| 3696 | void |
| 3697 | xmlSchemaDump(FILE * output, xmlSchemaPtr schema) |
| 3698 | { |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 3699 | if (output == NULL) |
| 3700 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3701 | if (schema == NULL) { |
| 3702 | fprintf(output, "Schemas: NULL\n"); |
| 3703 | return; |
| 3704 | } |
| 3705 | fprintf(output, "Schemas: "); |
| 3706 | if (schema->name != NULL) |
| 3707 | fprintf(output, "%s, ", schema->name); |
| 3708 | else |
| 3709 | fprintf(output, "no name, "); |
| 3710 | if (schema->targetNamespace != NULL) |
Daniel Veillard | 580ced8 | 2003-03-21 21:22:48 +0000 | [diff] [blame] | 3711 | fprintf(output, "%s", (const char *) schema->targetNamespace); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3712 | else |
| 3713 | fprintf(output, "no target namespace"); |
| 3714 | fprintf(output, "\n"); |
| 3715 | if (schema->annot != NULL) |
| 3716 | xmlSchemaAnnotDump(output, schema->annot); |
| 3717 | |
| 3718 | xmlHashScan(schema->typeDecl, (xmlHashScanner) xmlSchemaTypeDump, |
| 3719 | output); |
| 3720 | xmlHashScanFull(schema->elemDecl, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3721 | (xmlHashScannerFull) xmlSchemaElementDump, output); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3722 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 3723 | |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 3724 | #ifdef DEBUG_IDC |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 3725 | /** |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3726 | * xmlSchemaDebugDumpIDCTable: |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 3727 | * @vctxt: the WXS validation context |
| 3728 | * |
| 3729 | * Displays the current IDC table for debug purposes. |
| 3730 | */ |
| 3731 | static void |
| 3732 | xmlSchemaDebugDumpIDCTable(FILE * output, |
| 3733 | const xmlChar *namespaceName, |
| 3734 | const xmlChar *localName, |
| 3735 | xmlSchemaPSVIIDCBindingPtr bind) |
| 3736 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3737 | xmlChar *str = NULL, *value; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 3738 | xmlSchemaPSVIIDCNodePtr tab; |
| 3739 | xmlSchemaPSVIIDCKeyPtr key; |
| 3740 | int i, j, res; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3741 | |
| 3742 | fprintf(output, "IDC: TABLES on %s\n", |
| 3743 | xmlSchemaFormatQName(&str, namespaceName, localName)); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 3744 | FREE_AND_NULL(str) |
| 3745 | |
| 3746 | if (bind == NULL) |
| 3747 | return; |
| 3748 | do { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3749 | fprintf(output, "IDC: BINDING %s\n", |
| 3750 | xmlSchemaFormatQName(&str, bind->definition->targetNamespace, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 3751 | bind->definition->name)); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3752 | FREE_AND_NULL(str) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 3753 | for (i = 0; i < bind->nbNodes; i++) { |
| 3754 | tab = bind->nodeTable[i]; |
| 3755 | fprintf(output, " ( "); |
| 3756 | for (j = 0; j < bind->definition->nbFields; j++) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3757 | key = tab->keys[j]; |
| 3758 | if ((key != NULL) && (key->val != NULL)) { |
| 3759 | res = xmlSchemaGetCanonValue(key->val, &value); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3760 | if (res >= 0) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 3761 | fprintf(output, "\"%s\" ", value); |
| 3762 | else |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3763 | fprintf(output, "CANON-VALUE-FAILED "); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3764 | if (res == 0) |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3765 | FREE_AND_NULL(value) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 3766 | } else if (key != NULL) |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3767 | fprintf(output, "(no val), "); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 3768 | else |
| 3769 | fprintf(output, "(key missing), "); |
| 3770 | } |
| 3771 | fprintf(output, ")\n"); |
| 3772 | } |
| 3773 | bind = bind->next; |
| 3774 | } while (bind != NULL); |
| 3775 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 3776 | #endif /* DEBUG_IDC */ |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 3777 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3778 | |
| 3779 | /************************************************************************ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3780 | * * |
| 3781 | * Utilities * |
| 3782 | * * |
| 3783 | ************************************************************************/ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3784 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3785 | /** |
| 3786 | * xmlSchemaGetPropNode: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3787 | * @node: the element node |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3788 | * @name: the name of the attribute |
| 3789 | * |
| 3790 | * Seeks an attribute with a name of @name in |
| 3791 | * no namespace. |
| 3792 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3793 | * Returns the attribute or NULL if not present. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3794 | */ |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 3795 | static xmlAttrPtr |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3796 | xmlSchemaGetPropNode(xmlNodePtr node, const char *name) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3797 | { |
| 3798 | xmlAttrPtr prop; |
| 3799 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3800 | if ((node == NULL) || (name == NULL)) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3801 | return(NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3802 | prop = node->properties; |
| 3803 | while (prop != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3804 | if ((prop->ns == NULL) && xmlStrEqual(prop->name, BAD_CAST name)) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3805 | return(prop); |
| 3806 | prop = prop->next; |
| 3807 | } |
| 3808 | return (NULL); |
| 3809 | } |
| 3810 | |
| 3811 | /** |
| 3812 | * xmlSchemaGetPropNodeNs: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3813 | * @node: the element node |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3814 | * @uri: the uri |
| 3815 | * @name: the name of the attribute |
| 3816 | * |
| 3817 | * Seeks an attribute with a local name of @name and |
| 3818 | * a namespace URI of @uri. |
| 3819 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3820 | * Returns the attribute or NULL if not present. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3821 | */ |
| 3822 | static xmlAttrPtr |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3823 | xmlSchemaGetPropNodeNs(xmlNodePtr node, const char *uri, const char *name) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3824 | { |
| 3825 | xmlAttrPtr prop; |
| 3826 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3827 | if ((node == NULL) || (name == NULL)) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3828 | return(NULL); |
| 3829 | prop = node->properties; |
| 3830 | while (prop != NULL) { |
| 3831 | if ((prop->ns != NULL) && |
| 3832 | xmlStrEqual(prop->name, BAD_CAST name) && |
| 3833 | xmlStrEqual(prop->ns->href, BAD_CAST uri)) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3834 | return(prop); |
| 3835 | prop = prop->next; |
| 3836 | } |
| 3837 | return (NULL); |
| 3838 | } |
| 3839 | |
| 3840 | static const xmlChar * |
| 3841 | xmlSchemaGetNodeContent(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node) |
| 3842 | { |
| 3843 | xmlChar *val; |
| 3844 | const xmlChar *ret; |
| 3845 | |
| 3846 | val = xmlNodeGetContent(node); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3847 | if (val == NULL) |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 3848 | val = xmlStrdup((xmlChar *)""); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3849 | ret = xmlDictLookup(ctxt->dict, val, -1); |
| 3850 | xmlFree(val); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3851 | return(ret); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3852 | } |
| 3853 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3854 | /** |
| 3855 | * xmlSchemaGetProp: |
| 3856 | * @ctxt: the parser context |
| 3857 | * @node: the node |
| 3858 | * @name: the property name |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3859 | * |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3860 | * Read a attribute value and internalize the string |
| 3861 | * |
| 3862 | * Returns the string or NULL if not present. |
| 3863 | */ |
| 3864 | static const xmlChar * |
| 3865 | xmlSchemaGetProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
| 3866 | const char *name) |
| 3867 | { |
| 3868 | xmlChar *val; |
| 3869 | const xmlChar *ret; |
| 3870 | |
| 3871 | val = xmlGetProp(node, BAD_CAST name); |
| 3872 | if (val == NULL) |
| 3873 | return(NULL); |
| 3874 | ret = xmlDictLookup(ctxt->dict, val, -1); |
| 3875 | xmlFree(val); |
| 3876 | return(ret); |
| 3877 | } |
| 3878 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3879 | /************************************************************************ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3880 | * * |
| 3881 | * Parsing functions * |
| 3882 | * * |
| 3883 | ************************************************************************/ |
| 3884 | |
| 3885 | /** |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3886 | * xmlSchemaGetElem: |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3887 | * @schema: the schema context |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3888 | * @name: the element name |
| 3889 | * @ns: the element namespace |
| 3890 | * |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3891 | * Lookup a global element declaration in the schema. |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3892 | * |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3893 | * Returns the element declaration or NULL if not found. |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3894 | */ |
| 3895 | static xmlSchemaElementPtr |
| 3896 | xmlSchemaGetElem(xmlSchemaPtr schema, const xmlChar * name, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3897 | const xmlChar * namespace) |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3898 | { |
| 3899 | xmlSchemaElementPtr ret; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3900 | |
| 3901 | if ((name == NULL) || (schema == NULL)) |
| 3902 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3903 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3904 | ret = xmlHashLookup2(schema->elemDecl, name, namespace); |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 3905 | if ((ret != NULL) && |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3906 | (ret->flags & XML_SCHEMAS_ELEM_GLOBAL)) { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3907 | return (ret); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3908 | } else |
| 3909 | ret = NULL; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 3910 | /* |
| 3911 | * This one was removed, since top level element declarations have |
| 3912 | * the target namespace specified in targetNamespace of the <schema> |
| 3913 | * information element, even if elementFormDefault is "unqualified". |
| 3914 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3915 | |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 3916 | /* else if ((schema->flags & XML_SCHEMAS_QUALIF_ELEM) == 0) { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3917 | if (xmlStrEqual(namespace, schema->targetNamespace)) |
| 3918 | ret = xmlHashLookup2(schema->elemDecl, name, NULL); |
| 3919 | else |
| 3920 | ret = xmlHashLookup2(schema->elemDecl, name, namespace); |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 3921 | if ((ret != NULL) && |
| 3922 | ((level == 0) || (ret->flags & XML_SCHEMAS_ELEM_TOPLEVEL))) { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3923 | return (ret); |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 3924 | } |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 3925 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3926 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3927 | /* |
| 3928 | * Removed since imported components will be hold by the main schema only. |
| 3929 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3930 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3931 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3932 | else |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3933 | import = xmlHashLookup(schema->schemasImports, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3934 | if (import != NULL) { |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 3935 | ret = xmlSchemaGetElem(import->schema, name, namespace, level + 1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3936 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ELEM_GLOBAL)) { |
| 3937 | return (ret); |
| 3938 | } else |
| 3939 | ret = NULL; |
| 3940 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3941 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3942 | #ifdef DEBUG |
| 3943 | if (ret == NULL) { |
| 3944 | if (namespace == NULL) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3945 | fprintf(stderr, "Unable to lookup element decl. %s", name); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3946 | else |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 3947 | fprintf(stderr, "Unable to lookup element decl. %s:%s", name, |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3948 | namespace); |
| 3949 | } |
| 3950 | #endif |
| 3951 | return (ret); |
| 3952 | } |
| 3953 | |
| 3954 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3955 | * xmlSchemaGetType: |
| 3956 | * @schema: the schemas context |
| 3957 | * @name: the type name |
| 3958 | * @ns: the type namespace |
| 3959 | * |
| 3960 | * Lookup a type in the schemas or the predefined types |
| 3961 | * |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 3962 | * Returns the group definition or NULL if not found. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3963 | */ |
| 3964 | static xmlSchemaTypePtr |
| 3965 | xmlSchemaGetType(xmlSchemaPtr schema, const xmlChar * name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3966 | const xmlChar * namespace) |
| 3967 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3968 | xmlSchemaTypePtr ret; |
| 3969 | |
| 3970 | if (name == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3971 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3972 | if (schema != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3973 | ret = xmlHashLookup2(schema->typeDecl, name, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3974 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_TYPE_GLOBAL)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3975 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3976 | } |
| 3977 | ret = xmlSchemaGetPredefinedType(name, namespace); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 3978 | if (ret != NULL) |
| 3979 | return (ret); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3980 | /* |
| 3981 | * Removed, since the imported components will be grafted on the |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3982 | * main schema only. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3983 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3984 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3985 | else |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 3986 | import = xmlHashLookup(schema->schemasImports, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3987 | if (import != NULL) { |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 3988 | ret = xmlSchemaGetType(import->schema, name, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3989 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_TYPE_GLOBAL)) { |
| 3990 | return (ret); |
| 3991 | } else |
| 3992 | ret = NULL; |
| 3993 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3994 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3995 | #ifdef DEBUG |
| 3996 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3997 | if (namespace == NULL) |
| 3998 | fprintf(stderr, "Unable to lookup type %s", name); |
| 3999 | else |
| 4000 | fprintf(stderr, "Unable to lookup type %s:%s", name, |
| 4001 | namespace); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4002 | } |
| 4003 | #endif |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4004 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4005 | } |
| 4006 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4007 | /** |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4008 | * xmlSchemaGetAttributeDecl: |
| 4009 | * @schema: the context of the schema |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4010 | * @name: the name of the attribute |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4011 | * @ns: the target namespace of the attribute |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4012 | * |
| 4013 | * Lookup a an attribute in the schema or imported schemas |
| 4014 | * |
| 4015 | * Returns the attribute declaration or NULL if not found. |
| 4016 | */ |
| 4017 | static xmlSchemaAttributePtr |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4018 | xmlSchemaGetAttributeDecl(xmlSchemaPtr schema, const xmlChar * name, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4019 | const xmlChar * namespace) |
| 4020 | { |
| 4021 | xmlSchemaAttributePtr ret; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4022 | |
| 4023 | if ((name == NULL) || (schema == NULL)) |
| 4024 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4025 | |
| 4026 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4027 | ret = xmlHashLookup2(schema->attrDecl, name, namespace); |
| 4028 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ATTR_GLOBAL)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4029 | return (ret); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4030 | else |
| 4031 | ret = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4032 | /* |
| 4033 | * Removed, since imported components will be hold by the main schema only. |
| 4034 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4035 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4036 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4037 | else |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4038 | import = xmlHashLookup(schema->schemasImports, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4039 | if (import != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4040 | ret = xmlSchemaGetAttributeDecl(import->schema, name, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4041 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ATTR_GLOBAL)) { |
| 4042 | return (ret); |
| 4043 | } else |
| 4044 | ret = NULL; |
| 4045 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4046 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4047 | #ifdef DEBUG |
| 4048 | if (ret == NULL) { |
| 4049 | if (namespace == NULL) |
| 4050 | fprintf(stderr, "Unable to lookup attribute %s", name); |
| 4051 | else |
| 4052 | fprintf(stderr, "Unable to lookup attribute %s:%s", name, |
| 4053 | namespace); |
| 4054 | } |
| 4055 | #endif |
| 4056 | return (ret); |
| 4057 | } |
| 4058 | |
| 4059 | /** |
| 4060 | * xmlSchemaGetAttributeGroup: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4061 | * @schema: the context of the schema |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4062 | * @name: the name of the attribute group |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4063 | * @ns: the target namespace of the attribute group |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4064 | * |
| 4065 | * Lookup a an attribute group in the schema or imported schemas |
| 4066 | * |
| 4067 | * Returns the attribute group definition or NULL if not found. |
| 4068 | */ |
| 4069 | static xmlSchemaAttributeGroupPtr |
| 4070 | xmlSchemaGetAttributeGroup(xmlSchemaPtr schema, const xmlChar * name, |
| 4071 | const xmlChar * namespace) |
| 4072 | { |
| 4073 | xmlSchemaAttributeGroupPtr ret; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4074 | |
| 4075 | if ((name == NULL) || (schema == NULL)) |
| 4076 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4077 | |
| 4078 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4079 | ret = xmlHashLookup2(schema->attrgrpDecl, name, namespace); |
| 4080 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ATTRGROUP_GLOBAL)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4081 | return (ret); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4082 | else |
| 4083 | ret = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4084 | /* |
| 4085 | * Removed since imported components will be hold by the main schema only. |
| 4086 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4087 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4088 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4089 | else |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4090 | import = xmlHashLookup(schema->schemasImports, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4091 | if (import != NULL) { |
| 4092 | ret = xmlSchemaGetAttributeGroup(import->schema, name, namespace); |
| 4093 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ATTRGROUP_GLOBAL)) |
| 4094 | return (ret); |
| 4095 | else |
| 4096 | ret = NULL; |
| 4097 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4098 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4099 | #ifdef DEBUG |
| 4100 | if (ret == NULL) { |
| 4101 | if (namespace == NULL) |
| 4102 | fprintf(stderr, "Unable to lookup attribute group %s", name); |
| 4103 | else |
| 4104 | fprintf(stderr, "Unable to lookup attribute group %s:%s", name, |
| 4105 | namespace); |
| 4106 | } |
| 4107 | #endif |
| 4108 | return (ret); |
| 4109 | } |
| 4110 | |
| 4111 | /** |
| 4112 | * xmlSchemaGetGroup: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4113 | * @schema: the context of the schema |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4114 | * @name: the name of the group |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4115 | * @ns: the target namespace of the group |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4116 | * |
| 4117 | * Lookup a group in the schema or imported schemas |
| 4118 | * |
| 4119 | * Returns the group definition or NULL if not found. |
| 4120 | */ |
| 4121 | static xmlSchemaTypePtr |
| 4122 | xmlSchemaGetGroup(xmlSchemaPtr schema, const xmlChar * name, |
| 4123 | const xmlChar * namespace) |
| 4124 | { |
| 4125 | xmlSchemaTypePtr ret; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4126 | |
| 4127 | if ((name == NULL) || (schema == NULL)) |
| 4128 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4129 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4130 | ret = xmlHashLookup2(schema->groupDecl, name, namespace); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4131 | /* |
| 4132 | * Removed since imported components will be hold by the main schema only. |
| 4133 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4134 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4135 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4136 | else |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4137 | import = xmlHashLookup(schema->schemasImports, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4138 | if (import != NULL) { |
| 4139 | ret = xmlSchemaGetGroup(import->schema, name, namespace); |
| 4140 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_TYPE_GLOBAL)) |
| 4141 | return (ret); |
| 4142 | else |
| 4143 | ret = NULL; |
| 4144 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4145 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4146 | #ifdef DEBUG |
| 4147 | if (ret == NULL) { |
| 4148 | if (namespace == NULL) |
| 4149 | fprintf(stderr, "Unable to lookup group %s", name); |
| 4150 | else |
| 4151 | fprintf(stderr, "Unable to lookup group %s:%s", name, |
| 4152 | namespace); |
| 4153 | } |
| 4154 | #endif |
| 4155 | return (ret); |
| 4156 | } |
| 4157 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4158 | /** |
| 4159 | * xmlSchemaGetNamedComponent: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4160 | * @schema: the schema |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4161 | * @name: the name of the group |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4162 | * @ns: the target namespace of the group |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4163 | * |
| 4164 | * Lookup a group in the schema or imported schemas |
| 4165 | * |
| 4166 | * Returns the group definition or NULL if not found. |
| 4167 | */ |
| 4168 | static xmlSchemaTreeItemPtr |
| 4169 | xmlSchemaGetNamedComponent(xmlSchemaPtr schema, |
| 4170 | xmlSchemaTypeType itemType, |
| 4171 | const xmlChar *name, |
| 4172 | const xmlChar *targetNs) |
| 4173 | { |
| 4174 | switch (itemType) { |
| 4175 | case XML_SCHEMA_TYPE_GROUP: |
| 4176 | return ((xmlSchemaTreeItemPtr) xmlSchemaGetGroup(schema, |
| 4177 | name, targetNs)); |
| 4178 | case XML_SCHEMA_TYPE_ELEMENT: |
| 4179 | return ((xmlSchemaTreeItemPtr) xmlSchemaGetElem(schema, |
| 4180 | name, targetNs)); |
| 4181 | default: |
| 4182 | return (NULL); |
| 4183 | } |
| 4184 | } |
| 4185 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4186 | /************************************************************************ |
| 4187 | * * |
| 4188 | * Parsing functions * |
| 4189 | * * |
| 4190 | ************************************************************************/ |
| 4191 | |
| 4192 | #define IS_BLANK_NODE(n) \ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4193 | (((n)->type == XML_TEXT_NODE) && (xmlSchemaIsBlank((n)->content, -1))) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4194 | |
| 4195 | /** |
| 4196 | * xmlSchemaIsBlank: |
| 4197 | * @str: a string |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4198 | * @len: the length of the string or -1 |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4199 | * |
| 4200 | * Check if a string is ignorable |
| 4201 | * |
| 4202 | * Returns 1 if the string is NULL or made of blanks chars, 0 otherwise |
| 4203 | */ |
| 4204 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4205 | xmlSchemaIsBlank(xmlChar * str, int len) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4206 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4207 | if (str == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4208 | return (1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4209 | if (len < 0) { |
| 4210 | while (*str != 0) { |
| 4211 | if (!(IS_BLANK_CH(*str))) |
| 4212 | return (0); |
| 4213 | str++; |
| 4214 | } |
| 4215 | } else while ((*str != 0) && (len != 0)) { |
| 4216 | if (!(IS_BLANK_CH(*str))) |
| 4217 | return (0); |
| 4218 | str++; |
| 4219 | len--; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4220 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4221 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4222 | return (1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4226 | * xmlSchemaAddAssembledItem: |
| 4227 | * @ctxt: a schema parser context |
| 4228 | * @schema: the schema being built |
| 4229 | * @item: the item |
| 4230 | * |
| 4231 | * Add a item to the schema's list of current items. |
| 4232 | * This is used if the schema was already constructed and |
| 4233 | * new schemata need to be added to it. |
| 4234 | * *WARNING* this interface is highly subject to change. |
| 4235 | * |
| 4236 | * Returns 0 if suceeds and -1 if an internal error occurs. |
| 4237 | */ |
| 4238 | static int |
| 4239 | xmlSchemaAddAssembledItem(xmlSchemaParserCtxtPtr ctxt, |
| 4240 | xmlSchemaTypePtr item) |
| 4241 | { |
| 4242 | static int growSize = 100; |
| 4243 | xmlSchemaAssemblePtr ass; |
| 4244 | |
| 4245 | ass = ctxt->assemble; |
| 4246 | if (ass->sizeItems < 0) { |
| 4247 | /* If disabled. */ |
| 4248 | return (0); |
| 4249 | } |
| 4250 | if (ass->sizeItems <= 0) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 4251 | ass->items = (void **) xmlMalloc(growSize * sizeof(xmlSchemaTypePtr)); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4252 | if (ass->items == NULL) { |
| 4253 | xmlSchemaPErrMemory(ctxt, |
| 4254 | "allocating new item buffer", NULL); |
| 4255 | return (-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4256 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4257 | ass->sizeItems = growSize; |
| 4258 | } else if (ass->sizeItems <= ass->nbItems) { |
| 4259 | ass->sizeItems *= 2; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4260 | ass->items = (void **) xmlRealloc(ass->items, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4261 | ass->sizeItems * sizeof(xmlSchemaTypePtr)); |
| 4262 | if (ass->items == NULL) { |
| 4263 | xmlSchemaPErrMemory(ctxt, |
| 4264 | "growing item buffer", NULL); |
| 4265 | ass->sizeItems = 0; |
| 4266 | return (-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4267 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4268 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 4269 | /* ass->items[ass->nbItems++] = (void *) item; */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4270 | ((xmlSchemaTypePtr *) ass->items)[ass->nbItems++] = (void *) item; |
| 4271 | return (0); |
| 4272 | } |
| 4273 | |
| 4274 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4275 | * xmlSchemaAddNotation: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4276 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4277 | * @schema: the schema being built |
| 4278 | * @name: the item name |
| 4279 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4280 | * Add an XML schema annotation declaration |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4281 | * *WARNING* this interface is highly subject to change |
| 4282 | * |
| 4283 | * Returns the new struture or NULL in case of error |
| 4284 | */ |
| 4285 | static xmlSchemaNotationPtr |
| 4286 | xmlSchemaAddNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 4287 | const xmlChar *name) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4288 | { |
| 4289 | xmlSchemaNotationPtr ret = NULL; |
| 4290 | int val; |
| 4291 | |
| 4292 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 4293 | return (NULL); |
| 4294 | |
| 4295 | if (schema->notaDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 4296 | schema->notaDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4297 | if (schema->notaDecl == NULL) |
| 4298 | return (NULL); |
| 4299 | |
| 4300 | ret = (xmlSchemaNotationPtr) xmlMalloc(sizeof(xmlSchemaNotation)); |
| 4301 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4302 | xmlSchemaPErrMemory(ctxt, "add annotation", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4303 | return (NULL); |
| 4304 | } |
| 4305 | memset(ret, 0, sizeof(xmlSchemaNotation)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4306 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4307 | val = xmlHashAddEntry2(schema->notaDecl, name, schema->targetNamespace, |
| 4308 | ret); |
| 4309 | if (val != 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4310 | /* |
| 4311 | * TODO: This should never happen, since a unique name will be computed. |
| 4312 | * If it fails, then an other internal error must have occured. |
| 4313 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4314 | xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc, |
| 4315 | XML_SCHEMAP_REDEFINED_NOTATION, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4316 | "Annotation declaration '%s' is already declared.\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4317 | name, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4318 | xmlFree(ret); |
| 4319 | return (NULL); |
| 4320 | } |
| 4321 | return (ret); |
| 4322 | } |
| 4323 | |
| 4324 | |
| 4325 | /** |
| 4326 | * xmlSchemaAddAttribute: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4327 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4328 | * @schema: the schema being built |
| 4329 | * @name: the item name |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4330 | * @namespace: the namespace |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4331 | * |
| 4332 | * Add an XML schema Attrribute declaration |
| 4333 | * *WARNING* this interface is highly subject to change |
| 4334 | * |
| 4335 | * Returns the new struture or NULL in case of error |
| 4336 | */ |
| 4337 | static xmlSchemaAttributePtr |
| 4338 | xmlSchemaAddAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4339 | const xmlChar * name, const xmlChar * namespace, |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 4340 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4341 | { |
| 4342 | xmlSchemaAttributePtr ret = NULL; |
| 4343 | int val; |
| 4344 | |
| 4345 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 4346 | return (NULL); |
| 4347 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4348 | #ifdef DEBUG |
| 4349 | fprintf(stderr, "Adding attribute %s\n", name); |
| 4350 | if (namespace != NULL) |
| 4351 | fprintf(stderr, " target namespace %s\n", namespace); |
| 4352 | #endif |
| 4353 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4354 | if (schema->attrDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 4355 | schema->attrDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4356 | if (schema->attrDecl == NULL) |
| 4357 | return (NULL); |
| 4358 | |
| 4359 | ret = (xmlSchemaAttributePtr) xmlMalloc(sizeof(xmlSchemaAttribute)); |
| 4360 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4361 | xmlSchemaPErrMemory(ctxt, "allocating attribute", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4362 | return (NULL); |
| 4363 | } |
| 4364 | memset(ret, 0, sizeof(xmlSchemaAttribute)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4365 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 4366 | ret->targetNamespace = namespace; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4367 | val = xmlHashAddEntry3(schema->attrDecl, name, |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 4368 | namespace, ctxt->container, ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4369 | if (val != 0) { |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 4370 | if (topLevel) { |
| 4371 | xmlSchemaPCustomErr(ctxt, |
| 4372 | XML_SCHEMAP_REDEFINED_ATTR, |
| 4373 | NULL, NULL, node, |
| 4374 | "A global attribute declaration with the name '%s' does " |
| 4375 | "already exist", name); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4376 | xmlFree(ret); |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 4377 | return (NULL); |
| 4378 | } else { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 4379 | char buf[30]; |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 4380 | /* |
| 4381 | * Using the ctxt->container for xmlHashAddEntry3 is ambigious |
| 4382 | * in the scenario: |
| 4383 | * 1. multiple top-level complex types have different target |
| 4384 | * namespaces but have the SAME NAME; this can happen if |
| 4385 | * schemata are imported |
| 4386 | * 2. those complex types contain attributes with an equal name |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4387 | * 3. those attributes are in no namespace |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 4388 | * We will compute a new context string. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4389 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 4390 | snprintf(buf, 29, "#aCont%d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 4391 | val = xmlHashAddEntry3(schema->attrDecl, name, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 4392 | namespace, xmlDictLookup(ctxt->dict, BAD_CAST buf, -1), ret); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 4393 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 4394 | if (val != 0) { |
| 4395 | xmlSchemaPCustomErr(ctxt, |
| 4396 | XML_SCHEMAP_INTERNAL, |
| 4397 | NULL, NULL, node, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 4398 | "Internal error: xmlSchemaAddAttribute, " |
| 4399 | "a dublicate attribute declaration with the name '%s' " |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 4400 | "could not be added to the hash.", name); |
| 4401 | xmlFree(ret); |
| 4402 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4403 | } |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 4404 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4405 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4406 | if (ctxt->assemble != NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4407 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4408 | return (ret); |
| 4409 | } |
| 4410 | |
| 4411 | /** |
| 4412 | * xmlSchemaAddAttributeGroup: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4413 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4414 | * @schema: the schema being built |
| 4415 | * @name: the item name |
| 4416 | * |
| 4417 | * Add an XML schema Attrribute Group declaration |
| 4418 | * |
| 4419 | * Returns the new struture or NULL in case of error |
| 4420 | */ |
| 4421 | static xmlSchemaAttributeGroupPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4422 | xmlSchemaAddAttributeGroup(xmlSchemaParserCtxtPtr ctxt, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4423 | xmlSchemaPtr schema, const xmlChar * name, |
| 4424 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4425 | { |
| 4426 | xmlSchemaAttributeGroupPtr ret = NULL; |
| 4427 | int val; |
| 4428 | |
| 4429 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 4430 | return (NULL); |
| 4431 | |
| 4432 | if (schema->attrgrpDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 4433 | schema->attrgrpDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4434 | if (schema->attrgrpDecl == NULL) |
| 4435 | return (NULL); |
| 4436 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4437 | ret = |
| 4438 | (xmlSchemaAttributeGroupPtr) |
| 4439 | xmlMalloc(sizeof(xmlSchemaAttributeGroup)); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4440 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4441 | xmlSchemaPErrMemory(ctxt, "allocating attribute group", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4442 | return (NULL); |
| 4443 | } |
| 4444 | memset(ret, 0, sizeof(xmlSchemaAttributeGroup)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4445 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4446 | val = xmlHashAddEntry3(schema->attrgrpDecl, name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4447 | schema->targetNamespace, ctxt->container, ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4448 | if (val != 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4449 | xmlSchemaPCustomErr(ctxt, |
| 4450 | XML_SCHEMAP_REDEFINED_ATTRGROUP, |
| 4451 | NULL, NULL, node, |
| 4452 | "A global attribute group definition with the name '%s' does already exist", name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4453 | xmlFree(ret); |
| 4454 | return (NULL); |
| 4455 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4456 | if (ctxt->assemble != NULL) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4457 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4458 | return (ret); |
| 4459 | } |
| 4460 | |
| 4461 | /** |
| 4462 | * xmlSchemaAddElement: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4463 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4464 | * @schema: the schema being built |
| 4465 | * @name: the type name |
| 4466 | * @namespace: the type namespace |
| 4467 | * |
| 4468 | * Add an XML schema Element declaration |
| 4469 | * *WARNING* this interface is highly subject to change |
| 4470 | * |
| 4471 | * Returns the new struture or NULL in case of error |
| 4472 | */ |
| 4473 | static xmlSchemaElementPtr |
| 4474 | xmlSchemaAddElement(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4475 | const xmlChar * name, const xmlChar * namespace, |
| 4476 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4477 | { |
| 4478 | xmlSchemaElementPtr ret = NULL; |
| 4479 | int val; |
| 4480 | |
| 4481 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 4482 | return (NULL); |
| 4483 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4484 | #ifdef DEBUG |
| 4485 | fprintf(stderr, "Adding element %s\n", name); |
| 4486 | if (namespace != NULL) |
| 4487 | fprintf(stderr, " target namespace %s\n", namespace); |
| 4488 | #endif |
| 4489 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4490 | if (schema->elemDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 4491 | schema->elemDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4492 | if (schema->elemDecl == NULL) |
| 4493 | return (NULL); |
| 4494 | |
| 4495 | ret = (xmlSchemaElementPtr) xmlMalloc(sizeof(xmlSchemaElement)); |
| 4496 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4497 | xmlSchemaPErrMemory(ctxt, "allocating element", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4498 | return (NULL); |
| 4499 | } |
| 4500 | memset(ret, 0, sizeof(xmlSchemaElement)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4501 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4502 | val = xmlHashAddEntry3(schema->elemDecl, name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4503 | namespace, ctxt->container, ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4504 | if (val != 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4505 | if (topLevel) { |
| 4506 | xmlSchemaPCustomErr(ctxt, |
| 4507 | XML_SCHEMAP_REDEFINED_ELEMENT, |
| 4508 | NULL, NULL, node, |
| 4509 | "A global element declaration with the name '%s' does " |
| 4510 | "already exist", name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4511 | xmlFree(ret); |
| 4512 | return (NULL); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4513 | } else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4514 | char buf[30]; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4515 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 4516 | snprintf(buf, 29, "#eCont%d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4517 | val = xmlHashAddEntry3(schema->elemDecl, name, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 4518 | namespace, (xmlChar *) buf, ret); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4519 | if (val != 0) { |
| 4520 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 4521 | XML_SCHEMAP_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4522 | NULL, NULL, node, |
| 4523 | "Internal error: xmlSchemaAddElement, " |
| 4524 | "a dublicate element declaration with the name '%s' " |
| 4525 | "could not be added to the hash.", name); |
| 4526 | xmlFree(ret); |
| 4527 | return (NULL); |
| 4528 | } |
| 4529 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4530 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4531 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4532 | if (ctxt->assemble != NULL) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4533 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4534 | return (ret); |
| 4535 | } |
| 4536 | |
| 4537 | /** |
| 4538 | * xmlSchemaAddType: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4539 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4540 | * @schema: the schema being built |
| 4541 | * @name: the item name |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4542 | * @namespace: the namespace |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4543 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4544 | * Add an XML schema item |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4545 | * *WARNING* this interface is highly subject to change |
| 4546 | * |
| 4547 | * Returns the new struture or NULL in case of error |
| 4548 | */ |
| 4549 | static xmlSchemaTypePtr |
| 4550 | xmlSchemaAddType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4551 | const xmlChar * name, const xmlChar * namespace, |
| 4552 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4553 | { |
| 4554 | xmlSchemaTypePtr ret = NULL; |
| 4555 | int val; |
| 4556 | |
| 4557 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 4558 | return (NULL); |
| 4559 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4560 | #ifdef DEBUG |
| 4561 | fprintf(stderr, "Adding type %s\n", name); |
| 4562 | if (namespace != NULL) |
| 4563 | fprintf(stderr, " target namespace %s\n", namespace); |
| 4564 | #endif |
| 4565 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4566 | if (schema->typeDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 4567 | schema->typeDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4568 | if (schema->typeDecl == NULL) |
| 4569 | return (NULL); |
| 4570 | |
| 4571 | ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType)); |
| 4572 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4573 | xmlSchemaPErrMemory(ctxt, "allocating type", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4574 | return (NULL); |
| 4575 | } |
| 4576 | memset(ret, 0, sizeof(xmlSchemaType)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4577 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 4578 | ret->redef = NULL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4579 | val = xmlHashAddEntry2(schema->typeDecl, name, namespace, ret); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4580 | if (val != 0) { |
| 4581 | if (ctxt->includes == 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4582 | xmlSchemaPCustomErr(ctxt, |
| 4583 | XML_SCHEMAP_REDEFINED_TYPE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4584 | NULL, NULL, node, |
| 4585 | "A global type definition with the name '%s' does already exist", name); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 4586 | xmlFree(ret); |
| 4587 | return (NULL); |
| 4588 | } else { |
| 4589 | xmlSchemaTypePtr prev; |
| 4590 | |
| 4591 | prev = xmlHashLookup2(schema->typeDecl, name, namespace); |
| 4592 | if (prev == NULL) { |
| 4593 | xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4594 | XML_ERR_INTERNAL_ERROR, |
| 4595 | "Internal error: xmlSchemaAddType, on type " |
| 4596 | "'%s'.\n", |
| 4597 | name, NULL); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 4598 | xmlFree(ret); |
| 4599 | return (NULL); |
| 4600 | } |
| 4601 | ret->redef = prev->redef; |
| 4602 | prev->redef = ret; |
| 4603 | } |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4604 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4605 | ret->node = node; |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4606 | ret->minOccurs = 1; |
| 4607 | ret->maxOccurs = 1; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4608 | ret->attributeUses = NULL; |
| 4609 | ret->attributeWildcard = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4610 | if (ctxt->assemble != NULL) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4611 | xmlSchemaAddAssembledItem(ctxt,ret); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4612 | return (ret); |
| 4613 | } |
| 4614 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4615 | static xmlSchemaQNameRefPtr |
| 4616 | xmlSchemaNewQNameRef(xmlSchemaPtr schema, |
| 4617 | xmlSchemaTypeType refType, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4618 | const xmlChar *refName, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4619 | const xmlChar *refNs) |
| 4620 | { |
| 4621 | xmlSchemaQNameRefPtr ret; |
| 4622 | |
| 4623 | ret = (xmlSchemaQNameRefPtr) |
| 4624 | xmlMalloc(sizeof(xmlSchemaQNameRef)); |
| 4625 | if (ret == NULL) { |
| 4626 | xmlSchemaPErrMemory(NULL, "allocating QName reference item", |
| 4627 | NULL); |
| 4628 | return (NULL); |
| 4629 | } |
| 4630 | ret->type = XML_SCHEMA_EXTRA_QNAMEREF; |
| 4631 | ret->name = refName; |
| 4632 | ret->targetNamespace = refNs; |
| 4633 | ret->item = NULL; |
| 4634 | ret->itemType = refType; |
| 4635 | /* |
| 4636 | * Store the reference item in the schema. |
| 4637 | */ |
| 4638 | xmlSchemaAddVolatile(schema, (xmlSchemaBasicItemPtr) ret); |
| 4639 | return (ret); |
| 4640 | } |
| 4641 | |
| 4642 | /** |
| 4643 | * xmlSchemaAddModelGroup: |
| 4644 | * @ctxt: a schema parser context |
| 4645 | * @schema: the schema being built |
| 4646 | * @type: the "compositor" type of the model group |
| 4647 | * @container: the internal component name |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4648 | * @node: the node in the schema doc |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4649 | * |
| 4650 | * Adds a schema model group |
| 4651 | * *WARNING* this interface is highly subject to change |
| 4652 | * |
| 4653 | * Returns the new struture or NULL in case of error |
| 4654 | */ |
| 4655 | static xmlSchemaModelGroupPtr |
| 4656 | xmlSchemaAddModelGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 4657 | xmlSchemaTypeType type, const xmlChar **container, |
| 4658 | xmlNodePtr node) |
| 4659 | { |
| 4660 | xmlSchemaModelGroupPtr ret = NULL; |
| 4661 | xmlChar buf[30]; |
| 4662 | |
| 4663 | if ((ctxt == NULL) || (schema == NULL)) |
| 4664 | return (NULL); |
| 4665 | |
| 4666 | #ifdef DEBUG |
| 4667 | fprintf(stderr, "Adding model group component\n"); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4668 | #endif |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4669 | ret = (xmlSchemaModelGroupPtr) |
| 4670 | xmlMalloc(sizeof(xmlSchemaModelGroup)); |
| 4671 | if (ret == NULL) { |
| 4672 | xmlSchemaPErrMemory(ctxt, "allocating model group component", |
| 4673 | NULL); |
| 4674 | return (NULL); |
| 4675 | } |
| 4676 | ret->type = type; |
| 4677 | ret->annot = NULL; |
| 4678 | ret->node = node; |
| 4679 | ret->children = NULL; |
| 4680 | ret->next = NULL; |
| 4681 | if (type == XML_SCHEMA_TYPE_SEQUENCE) { |
| 4682 | if (container != NULL) |
| 4683 | snprintf((char *) buf, 29, "#seq%d", ctxt->counter++ + 1); |
| 4684 | } else if (type == XML_SCHEMA_TYPE_CHOICE) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4685 | if (container != NULL) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4686 | snprintf((char *) buf, 29, "#cho%d", ctxt->counter++ + 1); |
| 4687 | } else { |
| 4688 | if (container != NULL) |
| 4689 | snprintf((char *) buf, 29, "#all%d", ctxt->counter++ + 1); |
| 4690 | } |
| 4691 | if (container != NULL) |
| 4692 | *container = xmlDictLookup(ctxt->dict, BAD_CAST buf, -1); |
| 4693 | /* |
| 4694 | * Add to volatile items. |
| 4695 | * TODO: this should be changed someday. |
| 4696 | */ |
| 4697 | if (xmlSchemaAddVolatile(schema, (xmlSchemaBasicItemPtr) ret) != 0) { |
| 4698 | xmlFree(ret); |
| 4699 | return (NULL); |
| 4700 | } |
| 4701 | return (ret); |
| 4702 | } |
| 4703 | |
| 4704 | |
| 4705 | /** |
| 4706 | * xmlSchemaAddParticle: |
| 4707 | * @ctxt: a schema parser context |
| 4708 | * @schema: the schema being built |
| 4709 | * @node: the corresponding node in the schema doc |
| 4710 | * @min: the minOccurs |
| 4711 | * @max: the maxOccurs |
| 4712 | * |
| 4713 | * Adds an XML schema particle component. |
| 4714 | * *WARNING* this interface is highly subject to change |
| 4715 | * |
| 4716 | * Returns the new struture or NULL in case of error |
| 4717 | */ |
| 4718 | static xmlSchemaParticlePtr |
| 4719 | xmlSchemaAddParticle(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 4720 | xmlNodePtr node, int min, int max) |
| 4721 | { |
| 4722 | xmlSchemaParticlePtr ret = NULL; |
| 4723 | if ((ctxt == NULL) || (schema == NULL)) |
| 4724 | return (NULL); |
| 4725 | |
| 4726 | #ifdef DEBUG |
| 4727 | fprintf(stderr, "Adding particle component\n"); |
| 4728 | #endif |
| 4729 | ret = (xmlSchemaParticlePtr) |
| 4730 | xmlMalloc(sizeof(xmlSchemaParticle)); |
| 4731 | if (ret == NULL) { |
| 4732 | xmlSchemaPErrMemory(ctxt, "allocating particle component", |
| 4733 | NULL); |
| 4734 | return (NULL); |
| 4735 | } |
| 4736 | ret->type = XML_SCHEMA_TYPE_PARTICLE; |
| 4737 | ret->annot = NULL; |
| 4738 | ret->node = node; |
| 4739 | ret->minOccurs = min; |
| 4740 | ret->maxOccurs = max; |
| 4741 | ret->next = NULL; |
| 4742 | ret->children = NULL; |
| 4743 | |
| 4744 | if (xmlSchemaAddVolatile(schema, (xmlSchemaBasicItemPtr) ret) != 0) { |
| 4745 | xmlFree(ret); |
| 4746 | return (NULL); |
| 4747 | } |
| 4748 | return (ret); |
| 4749 | } |
| 4750 | |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4751 | /** |
| 4752 | * xmlSchemaAddGroup: |
| 4753 | * @ctxt: a schema validation context |
| 4754 | * @schema: the schema being built |
| 4755 | * @name: the group name |
| 4756 | * |
| 4757 | * Add an XML schema Group definition |
| 4758 | * |
| 4759 | * Returns the new struture or NULL in case of error |
| 4760 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4761 | static xmlSchemaModelGroupDefPtr |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4762 | xmlSchemaAddGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 4763 | const xmlChar *name, const xmlChar *namespaceName, |
| 4764 | xmlNodePtr node) |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4765 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4766 | xmlSchemaModelGroupDefPtr ret = NULL; |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4767 | int val; |
| 4768 | |
| 4769 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 4770 | return (NULL); |
| 4771 | |
| 4772 | if (schema->groupDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 4773 | schema->groupDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4774 | if (schema->groupDecl == NULL) |
| 4775 | return (NULL); |
| 4776 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4777 | ret = (xmlSchemaModelGroupDefPtr) xmlMalloc(sizeof(xmlSchemaModelGroupDef)); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4778 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4779 | xmlSchemaPErrMemory(ctxt, "adding group", NULL); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4780 | return (NULL); |
| 4781 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4782 | memset(ret, 0, sizeof(xmlSchemaModelGroupDef)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4783 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4784 | ret->type = XML_SCHEMA_TYPE_GROUP; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4785 | ret->node = node; |
| 4786 | ret->targetNamespace = namespaceName; |
| 4787 | val = xmlHashAddEntry2(schema->groupDecl, ret->name, namespaceName, ret); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4788 | if (val != 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4789 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 4790 | XML_SCHEMAP_REDEFINED_GROUP, |
| 4791 | NULL, NULL, node, |
| 4792 | "A global model group definition with the name '%s' does already " |
| 4793 | "exist", name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4794 | xmlFree(ret); |
| 4795 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4796 | } |
| 4797 | if (ctxt->assemble != NULL) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4798 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4799 | return (ret); |
| 4800 | } |
| 4801 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4802 | /** |
| 4803 | * xmlSchemaNewWildcardNs: |
| 4804 | * @ctxt: a schema validation context |
| 4805 | * |
| 4806 | * Creates a new wildcard namespace constraint. |
| 4807 | * |
| 4808 | * Returns the new struture or NULL in case of error |
| 4809 | */ |
| 4810 | static xmlSchemaWildcardNsPtr |
| 4811 | xmlSchemaNewWildcardNsConstraint(xmlSchemaParserCtxtPtr ctxt) |
| 4812 | { |
| 4813 | xmlSchemaWildcardNsPtr ret; |
| 4814 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4815 | ret = (xmlSchemaWildcardNsPtr) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4816 | xmlMalloc(sizeof(xmlSchemaWildcardNs)); |
| 4817 | if (ret == NULL) { |
| 4818 | xmlSchemaPErrMemory(ctxt, "creating wildcard namespace constraint", NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4819 | return (NULL); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4820 | } |
| 4821 | ret->value = NULL; |
| 4822 | ret->next = NULL; |
| 4823 | return (ret); |
| 4824 | } |
| 4825 | |
| 4826 | /** |
| 4827 | * xmlSchemaAddWildcard: |
| 4828 | * @ctxt: a schema validation context |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4829 | * @schema: a schema |
| 4830 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4831 | * Adds a wildcard. |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4832 | * It corresponds to a xsd:anyAttribute and xsd:any. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4833 | * |
| 4834 | * Returns the new struture or NULL in case of error |
| 4835 | */ |
| 4836 | static xmlSchemaWildcardPtr |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4837 | xmlSchemaAddWildcard(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 4838 | xmlSchemaTypeType type, xmlNodePtr node) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4839 | { |
| 4840 | xmlSchemaWildcardPtr ret = NULL; |
| 4841 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4842 | if ((ctxt == NULL) || (schema == NULL)) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4843 | return (NULL); |
| 4844 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4845 | #ifdef DEBUG |
| 4846 | fprintf(stderr, "Adding wildcard component\n"); |
| 4847 | #endif |
| 4848 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4849 | ret = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard)); |
| 4850 | if (ret == NULL) { |
| 4851 | xmlSchemaPErrMemory(ctxt, "adding wildcard", NULL); |
| 4852 | return (NULL); |
| 4853 | } |
| 4854 | memset(ret, 0, sizeof(xmlSchemaWildcard)); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4855 | ret->type = type; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4856 | ret->minOccurs = 1; |
| 4857 | ret->maxOccurs = 1; |
| 4858 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4859 | if (xmlSchemaAddVolatile(schema, (xmlSchemaBasicItemPtr) ret) != 0) { |
| 4860 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, NULL, NULL, node, |
| 4861 | "Failed to add a wildcard component to the list", NULL); |
| 4862 | xmlFree(ret); |
| 4863 | return (NULL); |
| 4864 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4865 | return (ret); |
| 4866 | } |
| 4867 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4868 | /************************************************************************ |
| 4869 | * * |
| 4870 | * Utilities for parsing * |
| 4871 | * * |
| 4872 | ************************************************************************/ |
| 4873 | |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 4874 | #if 0 |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4875 | /** |
| 4876 | * xmlGetQNameProp: |
| 4877 | * @ctxt: a schema validation context |
| 4878 | * @node: a subtree containing XML Schema informations |
| 4879 | * @name: the attribute name |
| 4880 | * @namespace: the result namespace if any |
| 4881 | * |
| 4882 | * Extract a QName Attribute value |
| 4883 | * |
| 4884 | * Returns the NCName or NULL if not found, and also update @namespace |
| 4885 | * with the namespace URI |
| 4886 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4887 | static const xmlChar * |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4888 | xmlGetQNameProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4889 | const char *name, const xmlChar ** namespace) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4890 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4891 | const xmlChar *val; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4892 | xmlNsPtr ns; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4893 | const xmlChar *ret, *prefix; |
| 4894 | int len; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 4895 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4896 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4897 | *namespace = NULL; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 4898 | attr = xmlSchemaGetPropNode(node, name); |
| 4899 | if (attr == NULL) |
| 4900 | return (NULL); |
| 4901 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 4902 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4903 | if (val == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4904 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4905 | |
Daniel Veillard | ba0153a | 2004-04-01 10:42:31 +0000 | [diff] [blame] | 4906 | if (!strchr((char *) val, ':')) { |
Daniel Veillard | ebcdebd | 2004-03-05 00:15:50 +0000 | [diff] [blame] | 4907 | ns = xmlSearchNs(node->doc, node, 0); |
| 4908 | if (ns) { |
| 4909 | *namespace = xmlDictLookup(ctxt->dict, ns->href, -1); |
| 4910 | return (val); |
| 4911 | } |
| 4912 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4913 | ret = xmlSplitQName3(val, &len); |
| 4914 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4915 | return (val); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4916 | } |
| 4917 | ret = xmlDictLookup(ctxt->dict, ret, -1); |
| 4918 | prefix = xmlDictLookup(ctxt->dict, val, len); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4919 | |
| 4920 | ns = xmlSearchNs(node->doc, node, prefix); |
| 4921 | if (ns == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4922 | xmlSchemaPSimpleTypeErr(ctxt, XML_SCHEMAP_PREFIX_UNDEFINED, |
| 4923 | NULL, NULL, (xmlNodePtr) attr, |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 4924 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), NULL, val, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4925 | "The QName value '%s' has no corresponding namespace " |
| 4926 | "declaration in scope", val, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4927 | } else { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4928 | *namespace = xmlDictLookup(ctxt->dict, ns->href, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4929 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4930 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4931 | } |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 4932 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4933 | |
| 4934 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4935 | * xmlSchemaPValAttrNodeQNameValue: |
| 4936 | * @ctxt: a schema parser context |
| 4937 | * @schema: the schema context |
| 4938 | * @ownerDes: the designation of the parent element |
| 4939 | * @ownerItem: the parent as a schema object |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4940 | * @value: the QName value |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4941 | * @local: the resulting local part if found, the attribute value otherwise |
| 4942 | * @uri: the resulting namespace URI if found |
| 4943 | * |
| 4944 | * Extracts the local name and the URI of a QName value and validates it. |
| 4945 | * This one is intended to be used on attribute values that |
| 4946 | * should resolve to schema components. |
| 4947 | * |
| 4948 | * Returns 0, in case the QName is valid, a positive error code |
| 4949 | * if not valid and -1 if an internal error occurs. |
| 4950 | */ |
| 4951 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4952 | xmlSchemaPValAttrNodeQNameValue(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4953 | xmlSchemaPtr schema, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4954 | xmlChar **ownerDes ATTRIBUTE_UNUSED, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4955 | xmlSchemaTypePtr ownerItem, |
| 4956 | xmlAttrPtr attr, |
| 4957 | const xmlChar *value, |
| 4958 | const xmlChar **uri, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4959 | const xmlChar **local) |
| 4960 | { |
| 4961 | const xmlChar *pref; |
| 4962 | xmlNsPtr ns; |
| 4963 | int len, ret; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4964 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4965 | *uri = NULL; |
| 4966 | *local = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4967 | ret = xmlValidateQName(value, 1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4968 | if (ret > 0) { |
| 4969 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4970 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4971 | ownerItem, (xmlNodePtr) attr, |
| 4972 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
| 4973 | NULL, value, NULL, NULL, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4974 | *local = value; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4975 | return (ctxt->err); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4976 | } else if (ret < 0) |
| 4977 | return (-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4978 | |
| 4979 | if (!strchr((char *) value, ':')) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4980 | ns = xmlSearchNs(attr->doc, attr->parent, 0); |
| 4981 | if (ns) |
| 4982 | *uri = xmlDictLookup(ctxt->dict, ns->href, -1); |
| 4983 | else if (schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) { |
| 4984 | /* |
| 4985 | * This one takes care of included schemas with no |
| 4986 | * target namespace. |
| 4987 | */ |
| 4988 | *uri = schema->targetNamespace; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4989 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 4990 | *local = xmlDictLookup(ctxt->dict, value, -1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4991 | return (0); |
| 4992 | } |
| 4993 | /* |
| 4994 | * At this point xmlSplitQName3 has to return a local name. |
| 4995 | */ |
| 4996 | *local = xmlSplitQName3(value, &len); |
| 4997 | *local = xmlDictLookup(ctxt->dict, *local, -1); |
| 4998 | pref = xmlDictLookup(ctxt->dict, value, len); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4999 | ns = xmlSearchNs(attr->doc, attr->parent, pref); |
| 5000 | if (ns == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5001 | xmlSchemaPSimpleTypeErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5002 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5003 | ownerItem, (xmlNodePtr) attr, |
| 5004 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), NULL, value, |
| 5005 | "The value '%s' of simple type 'xs:QName' has no " |
| 5006 | "corresponding namespace declaration in scope", value, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5007 | return (ctxt->err); |
| 5008 | } else { |
| 5009 | *uri = xmlDictLookup(ctxt->dict, ns->href, -1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5010 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5011 | return (0); |
| 5012 | } |
| 5013 | |
| 5014 | /** |
| 5015 | * xmlSchemaPValAttrNodeQName: |
| 5016 | * @ctxt: a schema parser context |
| 5017 | * @schema: the schema context |
| 5018 | * @ownerDes: the designation of the owner element |
| 5019 | * @ownerItem: the owner as a schema object |
| 5020 | * @attr: the attribute node |
| 5021 | * @local: the resulting local part if found, the attribute value otherwise |
| 5022 | * @uri: the resulting namespace URI if found |
| 5023 | * |
| 5024 | * Extracts and validates the QName of an attribute value. |
| 5025 | * This one is intended to be used on attribute values that |
| 5026 | * should resolve to schema components. |
| 5027 | * |
| 5028 | * Returns 0, in case the QName is valid, a positive error code |
| 5029 | * if not valid and -1 if an internal error occurs. |
| 5030 | */ |
| 5031 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5032 | xmlSchemaPValAttrNodeQName(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5033 | xmlSchemaPtr schema, |
| 5034 | xmlChar **ownerDes, |
| 5035 | xmlSchemaTypePtr ownerItem, |
| 5036 | xmlAttrPtr attr, |
| 5037 | const xmlChar **uri, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5038 | const xmlChar **local) |
| 5039 | { |
| 5040 | const xmlChar *value; |
| 5041 | |
| 5042 | value = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5043 | return (xmlSchemaPValAttrNodeQNameValue(ctxt, schema, |
| 5044 | ownerDes, ownerItem, attr, value, uri, local)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5045 | } |
| 5046 | |
| 5047 | /** |
| 5048 | * xmlSchemaPValAttrQName: |
| 5049 | * @ctxt: a schema parser context |
| 5050 | * @schema: the schema context |
| 5051 | * @ownerDes: the designation of the parent element |
| 5052 | * @ownerItem: the owner as a schema object |
| 5053 | * @ownerElem: the parent node of the attribute |
| 5054 | * @name: the name of the attribute |
| 5055 | * @local: the resulting local part if found, the attribute value otherwise |
| 5056 | * @uri: the resulting namespace URI if found |
| 5057 | * |
| 5058 | * Extracts and validates the QName of an attribute value. |
| 5059 | * |
| 5060 | * Returns 0, in case the QName is valid, a positive error code |
| 5061 | * if not valid and -1 if an internal error occurs. |
| 5062 | */ |
| 5063 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5064 | xmlSchemaPValAttrQName(xmlSchemaParserCtxtPtr ctxt, |
| 5065 | xmlSchemaPtr schema, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5066 | xmlChar **ownerDes, |
| 5067 | xmlSchemaTypePtr ownerItem, |
| 5068 | xmlNodePtr ownerElem, |
| 5069 | const char *name, |
| 5070 | const xmlChar **uri, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5071 | const xmlChar **local) |
| 5072 | { |
| 5073 | xmlAttrPtr attr; |
| 5074 | |
| 5075 | attr = xmlSchemaGetPropNode(ownerElem, name); |
| 5076 | if (attr == NULL) { |
| 5077 | *local = NULL; |
| 5078 | *uri = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5079 | return (0); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5080 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5081 | return (xmlSchemaPValAttrNodeQName(ctxt, schema, |
| 5082 | ownerDes, ownerItem, attr, uri, local)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5083 | } |
| 5084 | |
| 5085 | /** |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 5086 | * xmlSchemaPValAttrID: |
| 5087 | * @ctxt: a schema parser context |
| 5088 | * @schema: the schema context |
| 5089 | * @ownerDes: the designation of the parent element |
| 5090 | * @ownerItem: the owner as a schema object |
| 5091 | * @ownerElem: the parent node of the attribute |
| 5092 | * @name: the name of the attribute |
| 5093 | * |
| 5094 | * Extracts and validates the ID of an attribute value. |
| 5095 | * |
| 5096 | * Returns 0, in case the ID is valid, a positive error code |
| 5097 | * if not valid and -1 if an internal error occurs. |
| 5098 | */ |
| 5099 | static int |
| 5100 | xmlSchemaPValAttrID(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5101 | xmlChar **ownerDes ATTRIBUTE_UNUSED, |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 5102 | xmlSchemaTypePtr ownerItem, |
| 5103 | xmlNodePtr ownerElem, |
| 5104 | const xmlChar *name) |
| 5105 | { |
| 5106 | int ret; |
| 5107 | xmlChar *value; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5108 | xmlAttrPtr attr; |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 5109 | |
| 5110 | value = xmlGetNoNsProp(ownerElem, name); |
| 5111 | if (value == NULL) |
| 5112 | return (0); |
| 5113 | |
| 5114 | attr = xmlSchemaGetPropNode(ownerElem, (const char *) name); |
| 5115 | if (attr == NULL) |
| 5116 | return (-1); |
| 5117 | |
| 5118 | ret = xmlValidateNCName(BAD_CAST value, 1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5119 | if (ret == 0) { |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 5120 | /* |
| 5121 | * NOTE: the IDness might have already be declared in the DTD |
| 5122 | */ |
| 5123 | if (attr->atype != XML_ATTRIBUTE_ID) { |
| 5124 | xmlIDPtr res; |
| 5125 | xmlChar *strip; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5126 | |
| 5127 | /* |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 5128 | * TODO: Use xmlSchemaStrip here; it's not exported at this |
| 5129 | * moment. |
| 5130 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5131 | strip = xmlSchemaCollapseString(BAD_CAST value); |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 5132 | if (strip != NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5133 | value = strip; |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 5134 | res = xmlAddID(NULL, ownerElem->doc, BAD_CAST value, attr); |
| 5135 | if (res == NULL) { |
| 5136 | ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5137 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5138 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 5139 | ownerItem, (xmlNodePtr) attr, |
| 5140 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ID), |
| 5141 | NULL, NULL, "Duplicate value '%s' of simple " |
| 5142 | "type 'xs:ID'", BAD_CAST value, NULL); |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 5143 | } else |
| 5144 | attr->atype = XML_ATTRIBUTE_ID; |
| 5145 | if (strip != NULL) |
| 5146 | xmlFree(strip); |
| 5147 | } |
| 5148 | } else if (ret > 0) { |
| 5149 | ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5150 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5151 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 5152 | ownerItem, (xmlNodePtr) attr, |
| 5153 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ID), |
| 5154 | NULL, NULL, "The value '%s' of simple type 'xs:ID' is " |
| 5155 | "not a valid 'xs:NCName'", |
| 5156 | BAD_CAST value, NULL); |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 5157 | } |
| 5158 | xmlFree(value); |
| 5159 | |
| 5160 | return (ret); |
| 5161 | } |
| 5162 | |
| 5163 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5164 | * xmlGetMaxOccurs: |
| 5165 | * @ctxt: a schema validation context |
| 5166 | * @node: a subtree containing XML Schema informations |
| 5167 | * |
| 5168 | * Get the maxOccurs property |
| 5169 | * |
| 5170 | * Returns the default if not found, or the value |
| 5171 | */ |
| 5172 | static int |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5173 | xmlGetMaxOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
| 5174 | int min, int max, int def, const char *expected) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5175 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5176 | const xmlChar *val, *cur; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5177 | int ret = 0; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5178 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5179 | |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5180 | attr = xmlSchemaGetPropNode(node, "maxOccurs"); |
| 5181 | if (attr == NULL) |
| 5182 | return (def); |
| 5183 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5184 | |
| 5185 | if (xmlStrEqual(val, (const xmlChar *) "unbounded")) { |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5186 | if (max != UNBOUNDED) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5187 | xmlSchemaPSimpleTypeErr(ctxt, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5188 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 5189 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5190 | NULL, (xmlNodePtr) attr, NULL, expected, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5191 | val, NULL, NULL, NULL); |
| 5192 | return (def); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5193 | } else |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5194 | return (UNBOUNDED); /* encoding it with -1 might be another option */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | cur = val; |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 5198 | while (IS_BLANK_CH(*cur)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5199 | cur++; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5200 | if (*cur == 0) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5201 | xmlSchemaPSimpleTypeErr(ctxt, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5202 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 5203 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5204 | NULL, (xmlNodePtr) attr, NULL, expected, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5205 | val, NULL, NULL, NULL); |
| 5206 | return (def); |
| 5207 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5208 | while ((*cur >= '0') && (*cur <= '9')) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5209 | ret = ret * 10 + (*cur - '0'); |
| 5210 | cur++; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5211 | } |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 5212 | while (IS_BLANK_CH(*cur)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5213 | cur++; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5214 | /* |
| 5215 | * TODO: Restrict the maximal value to Integer. |
| 5216 | */ |
| 5217 | if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5218 | xmlSchemaPSimpleTypeErr(ctxt, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5219 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 5220 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5221 | NULL, (xmlNodePtr) attr, NULL, expected, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5222 | val, NULL, NULL, NULL); |
| 5223 | return (def); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5224 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5225 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5226 | } |
| 5227 | |
| 5228 | /** |
| 5229 | * xmlGetMinOccurs: |
| 5230 | * @ctxt: a schema validation context |
| 5231 | * @node: a subtree containing XML Schema informations |
| 5232 | * |
| 5233 | * Get the minOccurs property |
| 5234 | * |
| 5235 | * Returns the default if not found, or the value |
| 5236 | */ |
| 5237 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5238 | xmlGetMinOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5239 | int min, int max, int def, const char *expected) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5240 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5241 | const xmlChar *val, *cur; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5242 | int ret = 0; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5243 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5244 | |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5245 | attr = xmlSchemaGetPropNode(node, "minOccurs"); |
| 5246 | if (attr == NULL) |
| 5247 | return (def); |
| 5248 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5249 | cur = val; |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 5250 | while (IS_BLANK_CH(*cur)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5251 | cur++; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5252 | if (*cur == 0) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5253 | xmlSchemaPSimpleTypeErr(ctxt, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5254 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 5255 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5256 | NULL, (xmlNodePtr) attr, NULL, expected, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5257 | val, NULL, NULL, NULL); |
| 5258 | return (def); |
| 5259 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5260 | while ((*cur >= '0') && (*cur <= '9')) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5261 | ret = ret * 10 + (*cur - '0'); |
| 5262 | cur++; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5263 | } |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 5264 | while (IS_BLANK_CH(*cur)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5265 | cur++; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5266 | /* |
| 5267 | * TODO: Restrict the maximal value to Integer. |
| 5268 | */ |
| 5269 | if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5270 | xmlSchemaPSimpleTypeErr(ctxt, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5271 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 5272 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5273 | NULL, (xmlNodePtr) attr, NULL, expected, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5274 | val, NULL, NULL, NULL); |
| 5275 | return (def); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5276 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5277 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5278 | } |
| 5279 | |
| 5280 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5281 | * xmlSchemaPGetBoolNodeValue: |
| 5282 | * @ctxt: a schema validation context |
| 5283 | * @ownerDes: owner designation |
| 5284 | * @ownerItem: the owner as a schema item |
| 5285 | * @node: the node holding the value |
| 5286 | * |
| 5287 | * Converts a boolean string value into 1 or 0. |
| 5288 | * |
| 5289 | * Returns 0 or 1. |
| 5290 | */ |
| 5291 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5292 | xmlSchemaPGetBoolNodeValue(xmlSchemaParserCtxtPtr ctxt, |
| 5293 | xmlChar **ownerDes ATTRIBUTE_UNUSED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5294 | xmlSchemaTypePtr ownerItem, |
| 5295 | xmlNodePtr node) |
| 5296 | { |
| 5297 | xmlChar *value = NULL; |
| 5298 | int res = 0; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5299 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5300 | value = xmlNodeGetContent(node); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5301 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5302 | * 3.2.2.1 Lexical representation |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5303 | * An instance of a datatype that is defined as ·boolean· |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5304 | * can have the following legal literals {true, false, 1, 0}. |
| 5305 | */ |
| 5306 | if (xmlStrEqual(BAD_CAST value, BAD_CAST "true")) |
| 5307 | res = 1; |
| 5308 | else if (xmlStrEqual(BAD_CAST value, BAD_CAST "false")) |
| 5309 | res = 0; |
| 5310 | else if (xmlStrEqual(BAD_CAST value, BAD_CAST "1")) |
| 5311 | res = 1; |
| 5312 | else if (xmlStrEqual(BAD_CAST value, BAD_CAST "0")) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5313 | res = 0; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5314 | else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5315 | xmlSchemaPSimpleTypeErr(ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5316 | XML_SCHEMAP_INVALID_BOOLEAN, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5317 | ownerItem, node, |
| 5318 | xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN), |
| 5319 | NULL, BAD_CAST value, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5320 | NULL, NULL, NULL); |
| 5321 | } |
| 5322 | if (value != NULL) |
| 5323 | xmlFree(value); |
| 5324 | return (res); |
| 5325 | } |
| 5326 | |
| 5327 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5328 | * xmlGetBooleanProp: |
| 5329 | * @ctxt: a schema validation context |
| 5330 | * @node: a subtree containing XML Schema informations |
| 5331 | * @name: the attribute name |
| 5332 | * @def: the default value |
| 5333 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5334 | * Evaluate if a boolean property is set |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5335 | * |
| 5336 | * Returns the default if not found, 0 if found to be false, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5337 | * 1 if found to be true |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5338 | */ |
| 5339 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5340 | xmlGetBooleanProp(xmlSchemaParserCtxtPtr ctxt, |
| 5341 | xmlChar **ownerDes ATTRIBUTE_UNUSED, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5342 | xmlSchemaTypePtr ownerItem, |
| 5343 | xmlNodePtr node, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5344 | const char *name, int def) |
| 5345 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5346 | const xmlChar *val; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5347 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5348 | val = xmlSchemaGetProp(ctxt, node, name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5349 | if (val == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5350 | return (def); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5351 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5352 | * 3.2.2.1 Lexical representation |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5353 | * An instance of a datatype that is defined as ·boolean· |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5354 | * can have the following legal literals {true, false, 1, 0}. |
| 5355 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5356 | if (xmlStrEqual(val, BAD_CAST "true")) |
| 5357 | def = 1; |
| 5358 | else if (xmlStrEqual(val, BAD_CAST "false")) |
| 5359 | def = 0; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5360 | else if (xmlStrEqual(val, BAD_CAST "1")) |
| 5361 | def = 1; |
| 5362 | else if (xmlStrEqual(val, BAD_CAST "0")) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5363 | def = 0; |
| 5364 | else { |
| 5365 | xmlSchemaPSimpleTypeErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5366 | XML_SCHEMAP_INVALID_BOOLEAN, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5367 | ownerItem, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 5368 | (xmlNodePtr) xmlSchemaGetPropNode(node, name), |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5369 | xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN), |
| 5370 | NULL, val, NULL, NULL, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5371 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5372 | return (def); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5373 | } |
| 5374 | |
| 5375 | /************************************************************************ |
| 5376 | * * |
| 5377 | * Shema extraction from an Infoset * |
| 5378 | * * |
| 5379 | ************************************************************************/ |
| 5380 | static xmlSchemaTypePtr xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr |
| 5381 | ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5382 | xmlNodePtr node, |
| 5383 | int topLevel); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5384 | static xmlSchemaTypePtr xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr |
| 5385 | ctxt, |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5386 | xmlSchemaPtr schema, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5387 | xmlNodePtr node, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5388 | int topLevel); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5389 | static xmlSchemaTypePtr xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr |
| 5390 | ctxt, |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5391 | xmlSchemaPtr schema, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 5392 | xmlNodePtr node, |
| 5393 | xmlSchemaTypeType parentType); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5394 | static xmlSchemaAttributePtr xmlSchemaParseAttribute(xmlSchemaParserCtxtPtr |
| 5395 | ctxt, |
| 5396 | xmlSchemaPtr schema, |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5397 | xmlNodePtr node, |
| 5398 | int topLevel); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5399 | static xmlSchemaAttributeGroupPtr |
| 5400 | xmlSchemaParseAttributeGroup(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5401 | xmlSchemaPtr schema, xmlNodePtr node, |
| 5402 | int topLevel); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5403 | static xmlSchemaTypePtr xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt, |
| 5404 | xmlSchemaPtr schema, |
| 5405 | xmlNodePtr node); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5406 | static xmlSchemaWildcardPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5407 | xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt, |
| 5408 | xmlSchemaPtr schema, xmlNodePtr node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5409 | |
| 5410 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5411 | * xmlSchemaPValAttrNodeValue: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5412 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5413 | * @ctxt: a schema parser context |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5414 | * @ownerDes: the designation of the parent element |
| 5415 | * @ownerItem: the schema object owner if existent |
| 5416 | * @attr: the schema attribute node being validated |
| 5417 | * @value: the value |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5418 | * @type: the built-in type to be validated against |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5419 | * |
| 5420 | * Validates a value against the given built-in type. |
| 5421 | * This one is intended to be used internally for validation |
| 5422 | * of schema attribute values during parsing of the schema. |
| 5423 | * |
| 5424 | * Returns 0 if the value is valid, a positive error code |
| 5425 | * number otherwise and -1 in case of an internal or API error. |
| 5426 | */ |
| 5427 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5428 | xmlSchemaPValAttrNodeValue(xmlSchemaParserCtxtPtr pctxt, |
| 5429 | xmlChar **ownerDes ATTRIBUTE_UNUSED, |
| 5430 | xmlSchemaTypePtr ownerItem, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5431 | xmlAttrPtr attr, |
| 5432 | const xmlChar *value, |
| 5433 | xmlSchemaTypePtr type) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5434 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5435 | |
| 5436 | int ret = 0; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5437 | |
| 5438 | /* |
| 5439 | * NOTE: Should we move this to xmlschematypes.c? Hmm, but this |
| 5440 | * one is really meant to be used internally, so better not. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5441 | */ |
| 5442 | if ((pctxt == NULL) || (type == NULL) || (attr == NULL)) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5443 | return (-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5444 | if (type->type != XML_SCHEMA_TYPE_BASIC) { |
| 5445 | PERROR_INT("xmlSchemaPValAttrNodeValue", |
| 5446 | "the given type is not a built-in type"); |
| 5447 | return (-1); |
| 5448 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5449 | switch (type->builtInType) { |
| 5450 | case XML_SCHEMAS_NCNAME: |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 5451 | case XML_SCHEMAS_QNAME: |
| 5452 | case XML_SCHEMAS_ANYURI: |
| 5453 | case XML_SCHEMAS_TOKEN: |
| 5454 | case XML_SCHEMAS_LANGUAGE: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5455 | ret = xmlSchemaValPredefTypeNode(type, value, NULL, |
| 5456 | (xmlNodePtr) attr); |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 5457 | break; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5458 | default: { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5459 | PERROR_INT("xmlSchemaPValAttrNodeValue", |
| 5460 | "validation using the given type is not supported"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5461 | return (-1); |
| 5462 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5463 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5464 | /* |
| 5465 | * TODO: Should we use the S4S error codes instead? |
| 5466 | */ |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 5467 | if (ret < 0) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5468 | PERROR_INT("xmlSchemaPValAttrNodeValue", |
| 5469 | "failed to validate a schema attribute value"); |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 5470 | return (-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5471 | } else if (ret > 0) { |
| 5472 | if (VARIETY_LIST(type)) |
| 5473 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
| 5474 | else |
| 5475 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
| 5476 | xmlSchemaPSimpleTypeErr(pctxt, |
| 5477 | ret, ownerItem, (xmlNodePtr) attr, |
| 5478 | type, NULL, value, NULL, NULL, NULL); |
| 5479 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5480 | return (ret); |
| 5481 | } |
| 5482 | |
| 5483 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5484 | * xmlSchemaPValAttrNode: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5485 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5486 | * @ctxt: a schema parser context |
| 5487 | * @ownerDes: the designation of the parent element |
| 5488 | * @ownerItem: the schema object owner if existent |
| 5489 | * @attr: the schema attribute node being validated |
| 5490 | * @type: the built-in type to be validated against |
| 5491 | * @value: the resulting value if any |
| 5492 | * |
| 5493 | * Extracts and validates a value against the given built-in type. |
| 5494 | * This one is intended to be used internally for validation |
| 5495 | * of schema attribute values during parsing of the schema. |
| 5496 | * |
| 5497 | * Returns 0 if the value is valid, a positive error code |
| 5498 | * number otherwise and -1 in case of an internal or API error. |
| 5499 | */ |
| 5500 | static int |
| 5501 | xmlSchemaPValAttrNode(xmlSchemaParserCtxtPtr ctxt, |
| 5502 | xmlChar **ownerDes, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5503 | xmlSchemaTypePtr ownerItem, |
| 5504 | xmlAttrPtr attr, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5505 | xmlSchemaTypePtr type, |
| 5506 | const xmlChar **value) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5507 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5508 | const xmlChar *val; |
| 5509 | |
| 5510 | if ((ctxt == NULL) || (type == NULL) || (attr == NULL)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5511 | return (-1); |
| 5512 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5513 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 5514 | if (value != NULL) |
| 5515 | *value = val; |
| 5516 | |
| 5517 | return (xmlSchemaPValAttrNodeValue(ctxt, ownerDes, ownerItem, attr, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5518 | val, type)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5519 | } |
| 5520 | |
| 5521 | /** |
| 5522 | * xmlSchemaPValAttr: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5523 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5524 | * @ctxt: a schema parser context |
| 5525 | * @node: the element node of the attribute |
| 5526 | * @ownerDes: the designation of the parent element |
| 5527 | * @ownerItem: the schema object owner if existent |
| 5528 | * @ownerElem: the owner element node |
| 5529 | * @name: the name of the schema attribute node |
| 5530 | * @type: the built-in type to be validated against |
| 5531 | * @value: the resulting value if any |
| 5532 | * |
| 5533 | * Extracts and validates a value against the given built-in type. |
| 5534 | * This one is intended to be used internally for validation |
| 5535 | * of schema attribute values during parsing of the schema. |
| 5536 | * |
| 5537 | * Returns 0 if the value is valid, a positive error code |
| 5538 | * number otherwise and -1 in case of an internal or API error. |
| 5539 | */ |
| 5540 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5541 | xmlSchemaPValAttr(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5542 | xmlChar **ownerDes, |
| 5543 | xmlSchemaTypePtr ownerItem, |
| 5544 | xmlNodePtr ownerElem, |
| 5545 | const char *name, |
| 5546 | xmlSchemaTypePtr type, |
| 5547 | const xmlChar **value) |
| 5548 | { |
| 5549 | xmlAttrPtr attr; |
| 5550 | |
| 5551 | if ((ctxt == NULL) || (type == NULL)) { |
| 5552 | if (value != NULL) |
| 5553 | *value = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5554 | return (-1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5555 | } |
| 5556 | if (type->type != XML_SCHEMA_TYPE_BASIC) { |
| 5557 | if (value != NULL) |
| 5558 | *value = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5559 | xmlSchemaPErr(ctxt, ownerElem, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 5560 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5561 | "Internal error: xmlSchemaPValAttr, the given " |
| 5562 | "type '%s' is not a built-in type.\n", |
| 5563 | type->name, NULL); |
| 5564 | return (-1); |
| 5565 | } |
| 5566 | attr = xmlSchemaGetPropNode(ownerElem, name); |
| 5567 | if (attr == NULL) { |
| 5568 | if (value != NULL) |
| 5569 | *value = NULL; |
| 5570 | return (0); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5571 | } |
| 5572 | return (xmlSchemaPValAttrNode(ctxt, ownerDes, ownerItem, attr, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5573 | type, value)); |
| 5574 | } |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 5575 | |
| 5576 | static int |
| 5577 | xmlSchemaCheckReference(xmlSchemaParserCtxtPtr pctxt, |
| 5578 | xmlSchemaPtr schema, |
| 5579 | xmlNodePtr node, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 5580 | xmlSchemaBasicItemPtr item, |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 5581 | const xmlChar *namespaceName) |
| 5582 | { |
| 5583 | if (xmlStrEqual(schema->targetNamespace, namespaceName)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5584 | return (1); |
| 5585 | if (xmlStrEqual(xmlSchemaNs, namespaceName)) |
| 5586 | return (1); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 5587 | if (pctxt->localImports != NULL) { |
| 5588 | int i; |
| 5589 | for (i = 0; i < pctxt->nbLocalImports; i++) |
| 5590 | if (xmlStrEqual(namespaceName, pctxt->localImports[i])) |
| 5591 | return (1); |
| 5592 | } |
| 5593 | if (namespaceName == NULL) |
| 5594 | xmlSchemaPCustomErr(pctxt, XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 5595 | NULL, (xmlSchemaTypePtr) item, node, |
| 5596 | "References from this schema to components in no " |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 5597 | "namespace are not valid, since not indicated by an import " |
| 5598 | "statement", NULL); |
| 5599 | else |
| 5600 | xmlSchemaPCustomErr(pctxt, XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 5601 | NULL, (xmlSchemaTypePtr) item, node, |
| 5602 | "References from this schema to components in the " |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 5603 | "namespace '%s' are not valid, since not indicated by an import " |
| 5604 | "statement", namespaceName); |
| 5605 | return (0); |
| 5606 | } |
| 5607 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5608 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5609 | * xmlSchemaParseAttrDecls: |
| 5610 | * @ctxt: a schema validation context |
| 5611 | * @schema: the schema being built |
| 5612 | * @node: a subtree containing XML Schema informations |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 5613 | * @type: the hosting type where the attributes will be anchored |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5614 | * |
| 5615 | * parse a XML schema attrDecls declaration corresponding to |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5616 | * <!ENTITY % attrDecls |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5617 | * '((%attribute;| %attributeGroup;)*,(%anyAttribute;)?)'> |
| 5618 | */ |
| 5619 | static xmlNodePtr |
| 5620 | xmlSchemaParseAttrDecls(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 5621 | xmlNodePtr child, xmlSchemaTypePtr type) |
| 5622 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 5623 | xmlSchemaAttributePtr lastattr = NULL, attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5624 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5625 | while ((IS_SCHEMA(child, "attribute")) || |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5626 | (IS_SCHEMA(child, "attributeGroup"))) { |
| 5627 | attr = NULL; |
| 5628 | if (IS_SCHEMA(child, "attribute")) { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5629 | attr = xmlSchemaParseAttribute(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5630 | } else if (IS_SCHEMA(child, "attributeGroup")) { |
| 5631 | attr = (xmlSchemaAttributePtr) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5632 | xmlSchemaParseAttributeGroup(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5633 | } |
| 5634 | if (attr != NULL) { |
| 5635 | if (lastattr == NULL) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5636 | if (type->type == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) |
| 5637 | ((xmlSchemaAttributeGroupPtr) type)->attributes = attr; |
| 5638 | else |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 5639 | type->attributes = attr; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5640 | lastattr = attr; |
| 5641 | } else { |
| 5642 | lastattr->next = attr; |
| 5643 | lastattr = attr; |
| 5644 | } |
| 5645 | } |
| 5646 | child = child->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5647 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5648 | return (child); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5649 | } |
| 5650 | |
| 5651 | /** |
| 5652 | * xmlSchemaParseAnnotation: |
| 5653 | * @ctxt: a schema validation context |
| 5654 | * @schema: the schema being built |
| 5655 | * @node: a subtree containing XML Schema informations |
| 5656 | * |
| 5657 | * parse a XML schema Attrribute declaration |
| 5658 | * *WARNING* this interface is highly subject to change |
| 5659 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5660 | * Returns -1 in case of error, 0 if the declaration is improper and |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5661 | * 1 in case of success. |
| 5662 | */ |
| 5663 | static xmlSchemaAnnotPtr |
| 5664 | xmlSchemaParseAnnotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 5665 | xmlNodePtr node) |
| 5666 | { |
| 5667 | xmlSchemaAnnotPtr ret; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5668 | xmlNodePtr child = NULL; |
| 5669 | xmlAttrPtr attr; |
| 5670 | int barked = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5671 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5672 | /* |
| 5673 | * INFO: S4S completed. |
| 5674 | */ |
| 5675 | /* |
| 5676 | * id = ID |
| 5677 | * {any attributes with non-schema namespace . . .}> |
| 5678 | * Content: (appinfo | documentation)* |
| 5679 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5680 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5681 | return (NULL); |
| 5682 | ret = xmlSchemaNewAnnot(ctxt, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5683 | attr = node->properties; |
| 5684 | while (attr != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5685 | if (((attr->ns == NULL) && |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5686 | (!xmlStrEqual(attr->name, BAD_CAST "id"))) || |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5687 | ((attr->ns != NULL) && |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5688 | xmlStrEqual(attr->ns->href, xmlSchemaNs))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5689 | |
| 5690 | xmlSchemaPIllegalAttrErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5691 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5692 | NULL, NULL, attr); |
| 5693 | } |
| 5694 | attr = attr->next; |
| 5695 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 5696 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5697 | /* |
| 5698 | * And now for the children... |
| 5699 | */ |
| 5700 | child = node->children; |
| 5701 | while (child != NULL) { |
| 5702 | if (IS_SCHEMA(child, "appinfo")) { |
| 5703 | /* TODO: make available the content of "appinfo". */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5704 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5705 | * source = anyURI |
| 5706 | * {any attributes with non-schema namespace . . .}> |
| 5707 | * Content: ({any})* |
| 5708 | */ |
| 5709 | attr = child->properties; |
| 5710 | while (attr != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5711 | if (((attr->ns == NULL) && |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5712 | (!xmlStrEqual(attr->name, BAD_CAST "source"))) || |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5713 | ((attr->ns != NULL) && |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5714 | xmlStrEqual(attr->ns->href, xmlSchemaNs))) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5715 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5716 | xmlSchemaPIllegalAttrErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5717 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5718 | NULL, NULL, attr); |
| 5719 | } |
| 5720 | attr = attr->next; |
| 5721 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5722 | xmlSchemaPValAttr(ctxt, NULL, NULL, child, "source", |
| 5723 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5724 | child = child->next; |
| 5725 | } else if (IS_SCHEMA(child, "documentation")) { |
| 5726 | /* TODO: make available the content of "documentation". */ |
| 5727 | /* |
| 5728 | * source = anyURI |
| 5729 | * {any attributes with non-schema namespace . . .}> |
| 5730 | * Content: ({any})* |
| 5731 | */ |
| 5732 | attr = child->properties; |
| 5733 | while (attr != NULL) { |
| 5734 | if (attr->ns == NULL) { |
| 5735 | if (!xmlStrEqual(attr->name, BAD_CAST "source")) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5736 | xmlSchemaPIllegalAttrErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5737 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5738 | NULL, NULL, attr); |
| 5739 | } |
| 5740 | } else { |
| 5741 | if (xmlStrEqual(attr->ns->href, xmlSchemaNs) || |
| 5742 | (xmlStrEqual(attr->name, BAD_CAST "lang") && |
| 5743 | (!xmlStrEqual(attr->ns->href, XML_XML_NAMESPACE)))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5744 | |
| 5745 | xmlSchemaPIllegalAttrErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5746 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5747 | NULL, NULL, attr); |
| 5748 | } |
| 5749 | } |
| 5750 | attr = attr->next; |
| 5751 | } |
| 5752 | /* |
| 5753 | * Attribute "xml:lang". |
| 5754 | */ |
| 5755 | attr = xmlSchemaGetPropNodeNs(child, (const char *) XML_XML_NAMESPACE, "lang"); |
| 5756 | if (attr != NULL) |
| 5757 | xmlSchemaPValAttrNode(ctxt, NULL, NULL, attr, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5758 | xmlSchemaGetBuiltInType(XML_SCHEMAS_LANGUAGE), NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5759 | child = child->next; |
| 5760 | } else { |
| 5761 | if (!barked) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5762 | xmlSchemaPContentErr(ctxt, |
| 5763 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5764 | NULL, NULL, node, child, NULL, "(appinfo | documentation)*"); |
| 5765 | barked = 1; |
| 5766 | child = child->next; |
| 5767 | } |
| 5768 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5769 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5770 | return (ret); |
| 5771 | } |
| 5772 | |
| 5773 | /** |
| 5774 | * xmlSchemaParseFacet: |
| 5775 | * @ctxt: a schema validation context |
| 5776 | * @schema: the schema being built |
| 5777 | * @node: a subtree containing XML Schema informations |
| 5778 | * |
| 5779 | * parse a XML schema Facet declaration |
| 5780 | * *WARNING* this interface is highly subject to change |
| 5781 | * |
| 5782 | * Returns the new type structure or NULL in case of error |
| 5783 | */ |
| 5784 | static xmlSchemaFacetPtr |
| 5785 | xmlSchemaParseFacet(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5786 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5787 | { |
| 5788 | xmlSchemaFacetPtr facet; |
| 5789 | xmlNodePtr child = NULL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5790 | const xmlChar *value; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5791 | |
| 5792 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5793 | return (NULL); |
| 5794 | |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 5795 | facet = xmlSchemaNewFacet(); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5796 | if (facet == NULL) { |
| 5797 | xmlSchemaPErrMemory(ctxt, "allocating facet", node); |
| 5798 | return (NULL); |
| 5799 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5800 | facet->node = node; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5801 | value = xmlSchemaGetProp(ctxt, node, "value"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5802 | if (value == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5803 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_FACET_NO_VALUE, |
| 5804 | "Facet %s has no value\n", node->name, NULL); |
| 5805 | xmlSchemaFreeFacet(facet); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5806 | return (NULL); |
| 5807 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5808 | if (IS_SCHEMA(node, "minInclusive")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5809 | facet->type = XML_SCHEMA_FACET_MININCLUSIVE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5810 | } else if (IS_SCHEMA(node, "minExclusive")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5811 | facet->type = XML_SCHEMA_FACET_MINEXCLUSIVE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5812 | } else if (IS_SCHEMA(node, "maxInclusive")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5813 | facet->type = XML_SCHEMA_FACET_MAXINCLUSIVE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5814 | } else if (IS_SCHEMA(node, "maxExclusive")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5815 | facet->type = XML_SCHEMA_FACET_MAXEXCLUSIVE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5816 | } else if (IS_SCHEMA(node, "totalDigits")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5817 | facet->type = XML_SCHEMA_FACET_TOTALDIGITS; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5818 | } else if (IS_SCHEMA(node, "fractionDigits")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5819 | facet->type = XML_SCHEMA_FACET_FRACTIONDIGITS; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5820 | } else if (IS_SCHEMA(node, "pattern")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5821 | facet->type = XML_SCHEMA_FACET_PATTERN; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5822 | } else if (IS_SCHEMA(node, "enumeration")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5823 | facet->type = XML_SCHEMA_FACET_ENUMERATION; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5824 | } else if (IS_SCHEMA(node, "whiteSpace")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5825 | facet->type = XML_SCHEMA_FACET_WHITESPACE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5826 | } else if (IS_SCHEMA(node, "length")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5827 | facet->type = XML_SCHEMA_FACET_LENGTH; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5828 | } else if (IS_SCHEMA(node, "maxLength")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5829 | facet->type = XML_SCHEMA_FACET_MAXLENGTH; |
| 5830 | } else if (IS_SCHEMA(node, "minLength")) { |
| 5831 | facet->type = XML_SCHEMA_FACET_MINLENGTH; |
| 5832 | } else { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5833 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_TYPE, |
| 5834 | "Unknown facet type %s\n", node->name, NULL); |
| 5835 | xmlSchemaFreeFacet(facet); |
| 5836 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5837 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 5838 | xmlSchemaPValAttrID(ctxt, NULL, |
| 5839 | (xmlSchemaTypePtr) facet, node, BAD_CAST "id"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5840 | facet->value = value; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5841 | if ((facet->type != XML_SCHEMA_FACET_PATTERN) && |
| 5842 | (facet->type != XML_SCHEMA_FACET_ENUMERATION)) { |
| 5843 | const xmlChar *fixed; |
| 5844 | |
| 5845 | fixed = xmlSchemaGetProp(ctxt, node, "fixed"); |
| 5846 | if (fixed != NULL) { |
| 5847 | if (xmlStrEqual(fixed, BAD_CAST "true")) |
| 5848 | facet->fixed = 1; |
| 5849 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5850 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5851 | child = node->children; |
| 5852 | |
| 5853 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5854 | facet->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5855 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5856 | } |
| 5857 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5858 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_CHILD, |
| 5859 | "Facet %s has unexpected child content\n", |
| 5860 | node->name, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5861 | } |
| 5862 | return (facet); |
| 5863 | } |
| 5864 | |
| 5865 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5866 | * xmlSchemaParseWildcardNs: |
| 5867 | * @ctxt: a schema parser context |
| 5868 | * @wildc: the wildcard, already created |
| 5869 | * @node: a subtree containing XML Schema informations |
| 5870 | * |
| 5871 | * Parses the attribute "processContents" and "namespace" |
| 5872 | * of a xsd:anyAttribute and xsd:any. |
| 5873 | * *WARNING* this interface is highly subject to change |
| 5874 | * |
| 5875 | * Returns 0 if everything goes fine, a positive error code |
| 5876 | * if something is not valid and -1 if an internal error occurs. |
| 5877 | */ |
| 5878 | static int |
| 5879 | xmlSchemaParseWildcardNs(xmlSchemaParserCtxtPtr ctxt, |
| 5880 | xmlSchemaPtr schema, |
| 5881 | xmlSchemaWildcardPtr wildc, |
| 5882 | xmlNodePtr node) |
| 5883 | { |
| 5884 | const xmlChar *pc, *ns, *dictnsItem; |
| 5885 | int ret = 0; |
| 5886 | xmlChar *nsItem; |
| 5887 | xmlSchemaWildcardNsPtr tmp, lastNs = NULL; |
| 5888 | xmlAttrPtr attr; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5889 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5890 | pc = xmlSchemaGetProp(ctxt, node, "processContents"); |
| 5891 | if ((pc == NULL) |
| 5892 | || (xmlStrEqual(pc, (const xmlChar *) "strict"))) { |
| 5893 | wildc->processContents = XML_SCHEMAS_ANY_STRICT; |
| 5894 | } else if (xmlStrEqual(pc, (const xmlChar *) "skip")) { |
| 5895 | wildc->processContents = XML_SCHEMAS_ANY_SKIP; |
| 5896 | } else if (xmlStrEqual(pc, (const xmlChar *) "lax")) { |
| 5897 | wildc->processContents = XML_SCHEMAS_ANY_LAX; |
| 5898 | } else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5899 | xmlSchemaPSimpleTypeErr(ctxt, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 5900 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5901 | NULL, node, |
| 5902 | NULL, "(strict | skip | lax)", pc, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5903 | NULL, NULL, NULL); |
| 5904 | wildc->processContents = XML_SCHEMAS_ANY_STRICT; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 5905 | ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5906 | } |
| 5907 | /* |
| 5908 | * Build the namespace constraints. |
| 5909 | */ |
| 5910 | attr = xmlSchemaGetPropNode(node, "namespace"); |
| 5911 | ns = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 5912 | if ((attr == NULL) || (xmlStrEqual(ns, BAD_CAST "##any"))) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5913 | wildc->any = 1; |
| 5914 | else if (xmlStrEqual(ns, BAD_CAST "##other")) { |
| 5915 | wildc->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5916 | if (wildc->negNsSet == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5917 | return (-1); |
| 5918 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5919 | wildc->negNsSet->value = schema->targetNamespace; |
| 5920 | } else { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5921 | const xmlChar *end, *cur; |
| 5922 | |
| 5923 | cur = ns; |
| 5924 | do { |
| 5925 | while (IS_BLANK_CH(*cur)) |
| 5926 | cur++; |
| 5927 | end = cur; |
| 5928 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 5929 | end++; |
| 5930 | if (end == cur) |
| 5931 | break; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5932 | nsItem = xmlStrndup(cur, end - cur); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5933 | if ((xmlStrEqual(nsItem, BAD_CAST "##other")) || |
| 5934 | (xmlStrEqual(nsItem, BAD_CAST "##any"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5935 | xmlSchemaPSimpleTypeErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5936 | XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5937 | NULL, (xmlNodePtr) attr, |
| 5938 | NULL, |
| 5939 | "((##any | ##other) | List of (xs:anyURI | " |
| 5940 | "(##targetNamespace | ##local)))", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5941 | nsItem, NULL, NULL, NULL); |
| 5942 | ret = XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER; |
| 5943 | } else { |
| 5944 | if (xmlStrEqual(nsItem, BAD_CAST "##targetNamespace")) { |
| 5945 | dictnsItem = schema->targetNamespace; |
| 5946 | } else if (xmlStrEqual(nsItem, BAD_CAST "##local")) { |
| 5947 | dictnsItem = NULL; |
| 5948 | } else { |
| 5949 | /* |
| 5950 | * Validate the item (anyURI). |
| 5951 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5952 | xmlSchemaPValAttrNodeValue(ctxt, NULL, NULL, attr, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5953 | nsItem, xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI)); |
| 5954 | dictnsItem = xmlDictLookup(ctxt->dict, nsItem, -1); |
| 5955 | } |
| 5956 | /* |
| 5957 | * Avoid dublicate namespaces. |
| 5958 | */ |
| 5959 | tmp = wildc->nsSet; |
| 5960 | while (tmp != NULL) { |
| 5961 | if (dictnsItem == tmp->value) |
| 5962 | break; |
| 5963 | tmp = tmp->next; |
| 5964 | } |
| 5965 | if (tmp == NULL) { |
| 5966 | tmp = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 5967 | if (tmp == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5968 | xmlFree(nsItem); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5969 | return (-1); |
| 5970 | } |
| 5971 | tmp->value = dictnsItem; |
| 5972 | tmp->next = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5973 | if (wildc->nsSet == NULL) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5974 | wildc->nsSet = tmp; |
| 5975 | else |
| 5976 | lastNs->next = tmp; |
| 5977 | lastNs = tmp; |
| 5978 | } |
| 5979 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5980 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5981 | xmlFree(nsItem); |
| 5982 | cur = end; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5983 | } while (*cur != 0); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5984 | } |
| 5985 | return (ret); |
| 5986 | } |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5987 | |
| 5988 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5989 | xmlSchemaPCheckParticleCorrect_2(xmlSchemaParserCtxtPtr ctxt, |
| 5990 | xmlSchemaParticlePtr item ATTRIBUTE_UNUSED, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5991 | xmlNodePtr node, |
| 5992 | int minOccurs, |
| 5993 | int maxOccurs) { |
| 5994 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 5995 | if ((maxOccurs == 0) && ( minOccurs == 0)) |
| 5996 | return (0); |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5997 | if (maxOccurs != UNBOUNDED) { |
| 5998 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5999 | * TODO: Maybe we should better not create the particle, |
| 6000 | * if min/max is invalid, since it could confuse the build of the |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6001 | * content model. |
| 6002 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6003 | /* |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6004 | * 3.9.6 Schema Component Constraint: Particle Correct |
| 6005 | * |
| 6006 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6007 | if (maxOccurs < 1) { |
| 6008 | /* |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6009 | * 2.2 {max occurs} must be greater than or equal to 1. |
| 6010 | */ |
| 6011 | xmlSchemaPCustomAttrErr(ctxt, |
| 6012 | XML_SCHEMAP_P_PROPS_CORRECT_2_2, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6013 | NULL, NULL, |
| 6014 | xmlSchemaGetPropNode(node, "maxOccurs"), |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6015 | "The value must be greater than or equal to 1"); |
| 6016 | return (XML_SCHEMAP_P_PROPS_CORRECT_2_2); |
| 6017 | } else if (minOccurs > maxOccurs) { |
| 6018 | /* |
| 6019 | * 2.1 {min occurs} must not be greater than {max occurs}. |
| 6020 | */ |
| 6021 | xmlSchemaPCustomAttrErr(ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6022 | XML_SCHEMAP_P_PROPS_CORRECT_2_1, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6023 | NULL, NULL, |
| 6024 | xmlSchemaGetPropNode(node, "minOccurs"), |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6025 | "The value must not be greater than the value of 'maxOccurs'"); |
| 6026 | return (XML_SCHEMAP_P_PROPS_CORRECT_2_1); |
| 6027 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6028 | } |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6029 | return (0); |
| 6030 | } |
| 6031 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6032 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6033 | * xmlSchemaParseAny: |
| 6034 | * @ctxt: a schema validation context |
| 6035 | * @schema: the schema being built |
| 6036 | * @node: a subtree containing XML Schema informations |
| 6037 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6038 | * Parsea a XML schema <any> element. A particle and wildcard |
| 6039 | * will be created (except if minOccurs==maxOccurs==0, in this case |
| 6040 | * nothing will be created). |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6041 | * *WARNING* this interface is highly subject to change |
| 6042 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6043 | * Returns the particle or NULL in case of error or if minOccurs==maxOccurs==0 |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6044 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6045 | static xmlSchemaParticlePtr |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6046 | xmlSchemaParseAny(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 6047 | xmlNodePtr node) |
| 6048 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6049 | xmlSchemaParticlePtr particle; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6050 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6051 | xmlSchemaWildcardPtr wild; |
| 6052 | int min, max; |
| 6053 | xmlAttrPtr attr; |
| 6054 | xmlSchemaAnnotPtr annot = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6055 | |
| 6056 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 6057 | return (NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6058 | /* |
| 6059 | * Check for illegal attributes. |
| 6060 | */ |
| 6061 | attr = node->properties; |
| 6062 | while (attr != NULL) { |
| 6063 | if (attr->ns == NULL) { |
| 6064 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 6065 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) && |
| 6066 | (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) && |
| 6067 | (!xmlStrEqual(attr->name, BAD_CAST "namespace")) && |
| 6068 | (!xmlStrEqual(attr->name, BAD_CAST "processContents"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6069 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6070 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6071 | NULL, NULL, attr); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6072 | } |
| 6073 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6074 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6075 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6076 | NULL, NULL, attr); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6077 | } |
| 6078 | attr = attr->next; |
| 6079 | } |
| 6080 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
| 6081 | /* |
| 6082 | * minOccurs/maxOccurs. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6083 | */ |
| 6084 | max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, |
| 6085 | "(xs:nonNegativeInteger | unbounded)"); |
| 6086 | min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, |
| 6087 | "xs:nonNegativeInteger"); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6088 | xmlSchemaPCheckParticleCorrect_2(ctxt, NULL, node, min, max); |
| 6089 | /* |
| 6090 | * Create & parse the wildcard. |
| 6091 | */ |
| 6092 | wild = xmlSchemaAddWildcard(ctxt, schema, XML_SCHEMA_TYPE_ANY, node); |
| 6093 | if (wild == NULL) |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6094 | return (NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6095 | xmlSchemaParseWildcardNs(ctxt, schema, wild, node); |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 6096 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6097 | * And now for the children... |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 6098 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6099 | child = node->children; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6100 | if (IS_SCHEMA(child, "annotation")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6101 | annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6102 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6103 | } |
| 6104 | if (child != NULL) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6105 | xmlSchemaPContentErr(ctxt, |
| 6106 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6107 | NULL, NULL, node, child, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6108 | NULL, "(annotation?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6109 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6110 | /* |
| 6111 | * No component if minOccurs==maxOccurs==0. |
| 6112 | */ |
| 6113 | if ((min == 0) && (max == 0)) { |
| 6114 | /* Don't free the wildcard, since it's already on the list. */ |
| 6115 | return (NULL); |
| 6116 | } |
| 6117 | /* |
| 6118 | * Create the particle. |
| 6119 | */ |
| 6120 | particle = xmlSchemaAddParticle(ctxt, schema, node, min, max); |
| 6121 | if (particle == NULL) |
| 6122 | return (NULL); |
| 6123 | particle->annot = annot; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6124 | wild->minOccurs = min; |
| 6125 | wild->maxOccurs = max; |
| 6126 | particle->children = (xmlSchemaTreeItemPtr) wild; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6127 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6128 | return (particle); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6129 | } |
| 6130 | |
| 6131 | /** |
| 6132 | * xmlSchemaParseNotation: |
| 6133 | * @ctxt: a schema validation context |
| 6134 | * @schema: the schema being built |
| 6135 | * @node: a subtree containing XML Schema informations |
| 6136 | * |
| 6137 | * parse a XML schema Notation declaration |
| 6138 | * |
| 6139 | * Returns the new structure or NULL in case of error |
| 6140 | */ |
| 6141 | static xmlSchemaNotationPtr |
| 6142 | xmlSchemaParseNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6143 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6144 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 6145 | const xmlChar *name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6146 | xmlSchemaNotationPtr ret; |
| 6147 | xmlNodePtr child = NULL; |
| 6148 | |
| 6149 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 6150 | return (NULL); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 6151 | name = xmlSchemaGetProp(ctxt, node, "name"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6152 | if (name == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6153 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_NOTATION_NO_NAME, |
| 6154 | "Notation has no name\n", NULL, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6155 | return (NULL); |
| 6156 | } |
| 6157 | ret = xmlSchemaAddNotation(ctxt, schema, name); |
| 6158 | if (ret == NULL) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6159 | return (NULL); |
| 6160 | } |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 6161 | ret->targetNamespace = schema->targetNamespace; |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 6162 | |
| 6163 | xmlSchemaPValAttrID(ctxt, NULL, (xmlSchemaTypePtr) ret, |
| 6164 | node, BAD_CAST "id"); |
| 6165 | |
| 6166 | if (IS_SCHEMA(child, "annotation")) { |
| 6167 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6168 | child = child->next; |
| 6169 | } |
| 6170 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6171 | child = node->children; |
| 6172 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6173 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6174 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6175 | } |
| 6176 | if (child != NULL) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6177 | xmlSchemaPContentErr(ctxt, |
| 6178 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6179 | NULL, NULL, node, child, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6180 | NULL, "(annotation?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6181 | } |
| 6182 | |
| 6183 | return (ret); |
| 6184 | } |
| 6185 | |
| 6186 | /** |
| 6187 | * xmlSchemaParseAnyAttribute: |
| 6188 | * @ctxt: a schema validation context |
| 6189 | * @schema: the schema being built |
| 6190 | * @node: a subtree containing XML Schema informations |
| 6191 | * |
| 6192 | * parse a XML schema AnyAttrribute declaration |
| 6193 | * *WARNING* this interface is highly subject to change |
| 6194 | * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6195 | * Returns a wildcard or NULL. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6196 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6197 | static xmlSchemaWildcardPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6198 | xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt, |
| 6199 | xmlSchemaPtr schema, xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6200 | { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6201 | xmlSchemaWildcardPtr ret; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6202 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6203 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6204 | |
| 6205 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 6206 | return (NULL); |
| 6207 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6208 | ret = xmlSchemaAddWildcard(ctxt, schema, XML_SCHEMA_TYPE_ANY_ATTRIBUTE, |
| 6209 | node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6210 | if (ret == NULL) { |
| 6211 | return (NULL); |
| 6212 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6213 | /* |
| 6214 | * Check for illegal attributes. |
| 6215 | */ |
| 6216 | attr = node->properties; |
| 6217 | while (attr != NULL) { |
| 6218 | if (attr->ns == NULL) { |
| 6219 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 6220 | (!xmlStrEqual(attr->name, BAD_CAST "namespace")) && |
| 6221 | (!xmlStrEqual(attr->name, BAD_CAST "processContents"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6222 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6223 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6224 | NULL, NULL, attr); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6225 | } |
| 6226 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6227 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6228 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6229 | NULL, NULL, attr); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6230 | } |
| 6231 | attr = attr->next; |
| 6232 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 6233 | xmlSchemaPValAttrID(ctxt, NULL, (xmlSchemaTypePtr) ret, |
| 6234 | node, BAD_CAST "id"); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6235 | /* |
| 6236 | * Parse the namespace list. |
| 6237 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6238 | if (xmlSchemaParseWildcardNs(ctxt, schema, ret, node) != 0) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6239 | return (NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6240 | /* |
| 6241 | * And now for the children... |
| 6242 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6243 | child = node->children; |
| 6244 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6245 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6246 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6247 | } |
| 6248 | if (child != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6249 | xmlSchemaPContentErr(ctxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6250 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6251 | NULL, NULL, node, child, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6252 | NULL, "(annotation?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6253 | } |
| 6254 | |
| 6255 | return (ret); |
| 6256 | } |
| 6257 | |
| 6258 | |
| 6259 | /** |
| 6260 | * xmlSchemaParseAttribute: |
| 6261 | * @ctxt: a schema validation context |
| 6262 | * @schema: the schema being built |
| 6263 | * @node: a subtree containing XML Schema informations |
| 6264 | * |
| 6265 | * parse a XML schema Attrribute declaration |
| 6266 | * *WARNING* this interface is highly subject to change |
| 6267 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6268 | * Returns the attribute declaration. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6269 | */ |
| 6270 | static xmlSchemaAttributePtr |
| 6271 | xmlSchemaParseAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6272 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6273 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6274 | const xmlChar *name, *attrValue; |
| 6275 | xmlChar *repName = NULL; /* The reported designation. */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6276 | xmlSchemaAttributePtr ret; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6277 | xmlNodePtr child = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6278 | xmlAttrPtr attr, nameAttr; |
| 6279 | int isRef = 0; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6280 | |
| 6281 | /* |
| 6282 | * Note that the w3c spec assumes the schema to be validated with schema |
| 6283 | * for schemas beforehand. |
| 6284 | * |
| 6285 | * 3.2.3 Constraints on XML Representations of Attribute Declarations |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6286 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6287 | |
| 6288 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 6289 | return (NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6290 | attr = xmlSchemaGetPropNode(node, "ref"); |
| 6291 | nameAttr = xmlSchemaGetPropNode(node, "name"); |
| 6292 | |
| 6293 | if ((attr == NULL) && (nameAttr == NULL)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6294 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6295 | * 3.2.3 : 3.1 |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6296 | * One of ref or name must be present, but not both |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6297 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6298 | xmlSchemaPMissingAttrErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_3_1, |
| 6299 | NULL, node, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6300 | "One of the attributes 'ref' or 'name' must be present"); |
| 6301 | return (NULL); |
| 6302 | } |
| 6303 | if ((topLevel) || (attr == NULL)) { |
| 6304 | if (nameAttr == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6305 | xmlSchemaPMissingAttrErr(ctxt, XML_SCHEMAP_S4S_ATTR_MISSING, |
| 6306 | NULL, node, "name", NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6307 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6308 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6309 | } else |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6310 | isRef = 1; |
| 6311 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6312 | if (isRef) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6313 | char buf[50]; |
| 6314 | const xmlChar *refNs = NULL, *ref = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6315 | |
| 6316 | /* |
| 6317 | * Parse as attribute reference. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6318 | */ |
| 6319 | if (xmlSchemaPValAttrNodeQName(ctxt, schema, |
| 6320 | (xmlChar **) &xmlSchemaElemDesAttrRef, NULL, attr, &refNs, |
| 6321 | &ref) != 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6322 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6323 | } |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 6324 | snprintf(buf, 49, "#aRef%d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6325 | name = (const xmlChar *) buf; |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 6326 | ret = xmlSchemaAddAttribute(ctxt, schema, name, NULL, node, 0); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6327 | if (ret == NULL) { |
| 6328 | if (repName != NULL) |
| 6329 | xmlFree(repName); |
| 6330 | return (NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6331 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6332 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTE; |
| 6333 | ret->node = node; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6334 | ret->refNs = refNs; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 6335 | ret->ref = ref; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6336 | xmlSchemaCheckReference(ctxt, schema, node, (xmlSchemaBasicItemPtr) ret, |
| 6337 | refNs); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6338 | /* |
| 6339 | xmlSchemaFormatTypeRep(&repName, (xmlSchemaTypePtr) ret, NULL, NULL); |
| 6340 | */ |
| 6341 | if (nameAttr != NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6342 | xmlSchemaPMutualExclAttrErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_3_1, |
| 6343 | &repName, (xmlSchemaTypePtr) ret, nameAttr, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6344 | "ref", "name"); |
| 6345 | /* |
| 6346 | * Check for illegal attributes. |
| 6347 | */ |
| 6348 | attr = node->properties; |
| 6349 | while (attr != NULL) { |
| 6350 | if (attr->ns == NULL) { |
| 6351 | if (xmlStrEqual(attr->name, BAD_CAST "type") || |
| 6352 | xmlStrEqual(attr->name, BAD_CAST "form")) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6353 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6354 | * 3.2.3 : 3.2 |
| 6355 | * If ref is present, then all of <simpleType>, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6356 | * form and type must be absent. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6357 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6358 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6359 | XML_SCHEMAP_SRC_ATTRIBUTE_3_2, &repName, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6360 | (xmlSchemaTypePtr) ret, attr); |
| 6361 | } else if ((!xmlStrEqual(attr->name, BAD_CAST "ref")) && |
| 6362 | (!xmlStrEqual(attr->name, BAD_CAST "use")) && |
| 6363 | (!xmlStrEqual(attr->name, BAD_CAST "id")) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6364 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
| 6365 | (!xmlStrEqual(attr->name, BAD_CAST "fixed")) && |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6366 | (!xmlStrEqual(attr->name, BAD_CAST "default"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6367 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6368 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6369 | &repName, (xmlSchemaTypePtr) ret, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6370 | } |
| 6371 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6372 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6373 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6374 | &repName, (xmlSchemaTypePtr) ret, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6375 | } |
| 6376 | attr = attr->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6377 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 6378 | } else { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6379 | const xmlChar *ns = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6380 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6381 | /* |
| 6382 | * Parse as attribute declaration. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6383 | */ |
| 6384 | if (xmlSchemaPValAttrNode(ctxt, |
| 6385 | (xmlChar **) &xmlSchemaElemDesAttrDecl, NULL, nameAttr, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6386 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 6387 | return (NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6388 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6389 | /* |
| 6390 | xmlSchemaFormatTypeRep(&repName, NULL, xmlSchemaElemDesAttrDecl, name); |
| 6391 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6392 | /* |
| 6393 | * 3.2.6 Schema Component Constraint: xmlns Not Allowed |
| 6394 | * TODO: Move this to the component layer. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6395 | */ |
| 6396 | if (xmlStrEqual(name, BAD_CAST "xmlns")) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6397 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6398 | XML_SCHEMAP_NO_XMLNS, |
| 6399 | NULL, (xmlNodePtr) nameAttr, |
| 6400 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), NULL, NULL, |
| 6401 | "The value of type 'xs:NCName' must not match 'xmlns'", |
| 6402 | NULL, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6403 | if (repName != NULL) |
| 6404 | xmlFree(repName); |
| 6405 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6406 | } |
| 6407 | /* |
| 6408 | * Evaluate the target namespace |
| 6409 | */ |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6410 | if (topLevel) { |
| 6411 | ns = schema->targetNamespace; |
| 6412 | } else { |
| 6413 | attr = xmlSchemaGetPropNode(node, "form"); |
| 6414 | if (attr != NULL) { |
| 6415 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 6416 | if (xmlStrEqual(attrValue, BAD_CAST "qualified")) { |
| 6417 | ns = schema->targetNamespace; |
| 6418 | } else if (!xmlStrEqual(attrValue, BAD_CAST "unqualified")) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6419 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6420 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 6421 | NULL, (xmlNodePtr) attr, |
| 6422 | NULL, "(qualified | unqualified)", |
| 6423 | attrValue, NULL, NULL, NULL); |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6424 | } |
| 6425 | } else if (schema->flags & XML_SCHEMAS_QUALIF_ATTR) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6426 | ns = schema->targetNamespace; |
| 6427 | } |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 6428 | ret = xmlSchemaAddAttribute(ctxt, schema, name, ns, node, topLevel); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6429 | if (ret == NULL) { |
| 6430 | if (repName != NULL) |
| 6431 | xmlFree(repName); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6432 | return (NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6433 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6434 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTE; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6435 | ret->node = node; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6436 | if (topLevel) |
| 6437 | ret->flags |= XML_SCHEMAS_ATTR_GLOBAL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6438 | /* |
| 6439 | * 3.2.6 Schema Component Constraint: xsi: Not Allowed |
| 6440 | * TODO: Move this to the component layer. |
| 6441 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6442 | if (xmlStrEqual(ret->targetNamespace, xmlSchemaInstanceNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6443 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6444 | XML_SCHEMAP_NO_XSI, |
| 6445 | &repName, (xmlSchemaTypePtr) ret, node, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6446 | "The target namespace must not match '%s'", |
| 6447 | xmlSchemaInstanceNs); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6448 | } |
| 6449 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6450 | * Check for illegal attributes. |
| 6451 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6452 | attr = node->properties; |
| 6453 | while (attr != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6454 | if (attr->ns == NULL) { |
| 6455 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 6456 | (!xmlStrEqual(attr->name, BAD_CAST "default")) && |
| 6457 | (!xmlStrEqual(attr->name, BAD_CAST "fixed")) && |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6458 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
| 6459 | (!xmlStrEqual(attr->name, BAD_CAST "type"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6460 | if ((topLevel) || |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6461 | ((!xmlStrEqual(attr->name, BAD_CAST "form")) && |
| 6462 | (!xmlStrEqual(attr->name, BAD_CAST "use")))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6463 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6464 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6465 | &repName, (xmlSchemaTypePtr) ret, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6466 | } |
| 6467 | } |
| 6468 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6469 | xmlSchemaPIllegalAttrErr(ctxt, XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6470 | &repName, (xmlSchemaTypePtr) ret, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6471 | } |
| 6472 | attr = attr->next; |
| 6473 | } |
| 6474 | xmlSchemaPValAttrQName(ctxt, schema, &repName, (xmlSchemaTypePtr) ret, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6475 | node, "type", &ret->typeNs, &ret->typeName); |
| 6476 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 6477 | xmlSchemaPValAttrID(ctxt, NULL, (xmlSchemaTypePtr) ret, |
| 6478 | node, BAD_CAST "id"); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6479 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6480 | * Attribute "fixed". |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6481 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6482 | ret->defValue = xmlSchemaGetProp(ctxt, node, "fixed"); |
| 6483 | if (ret->defValue != NULL) |
| 6484 | ret->flags |= XML_SCHEMAS_ATTR_FIXED; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6485 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6486 | * Attribute "default". |
| 6487 | */ |
| 6488 | attr = xmlSchemaGetPropNode(node, "default"); |
| 6489 | if (attr != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6490 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6491 | * 3.2.3 : 1 |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6492 | * default and fixed must not both be present. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6493 | */ |
| 6494 | if (ret->flags & XML_SCHEMAS_ATTR_FIXED) { |
| 6495 | xmlSchemaPMutualExclAttrErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_1, |
| 6496 | &repName, (xmlSchemaTypePtr) ret, attr, "default", "fixed"); |
| 6497 | } else |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6498 | ret->defValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 6499 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6500 | if (topLevel == 0) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6501 | /* |
| 6502 | * Attribute "use". |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6503 | */ |
| 6504 | attr = xmlSchemaGetPropNode(node, "use"); |
| 6505 | if (attr != NULL) { |
| 6506 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 6507 | if (xmlStrEqual(attrValue, BAD_CAST "optional")) |
| 6508 | ret->occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL; |
| 6509 | else if (xmlStrEqual(attrValue, BAD_CAST "prohibited")) |
| 6510 | ret->occurs = XML_SCHEMAS_ATTR_USE_PROHIBITED; |
| 6511 | else if (xmlStrEqual(attrValue, BAD_CAST "required")) |
| 6512 | ret->occurs = XML_SCHEMAS_ATTR_USE_REQUIRED; |
| 6513 | else |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6514 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6515 | XML_SCHEMAP_INVALID_ATTR_USE, |
| 6516 | (xmlSchemaTypePtr) ret, (xmlNodePtr) attr, |
| 6517 | NULL, "(optional | prohibited | required)", |
| 6518 | attrValue, NULL, NULL, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6519 | } else |
| 6520 | ret->occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6521 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6522 | * 3.2.3 : 2 |
| 6523 | * If default and use are both present, use must have |
| 6524 | * the actual value optional. |
| 6525 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6526 | if ((ret->occurs != XML_SCHEMAS_ATTR_USE_OPTIONAL) && |
| 6527 | (ret->defValue != NULL) && |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6528 | ((ret->flags & XML_SCHEMAS_ATTR_FIXED) == 0)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6529 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6530 | XML_SCHEMAP_SRC_ATTRIBUTE_2, |
| 6531 | (xmlSchemaTypePtr) ret, (xmlNodePtr) attr, |
| 6532 | NULL, "(optional | prohibited | required)", NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6533 | "The value must be 'optional' if the attribute " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6534 | "'default' is present as well", NULL, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6535 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6536 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6537 | /* |
| 6538 | * And now for the children... |
| 6539 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6540 | child = node->children; |
| 6541 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6542 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6543 | child = child->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6544 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6545 | if (isRef) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6546 | if (child != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6547 | if (IS_SCHEMA(child, "simpleType")) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6548 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6549 | * 3.2.3 : 3.2 |
| 6550 | * If ref is present, then all of <simpleType>, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6551 | * form and type must be absent. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6552 | */ |
| 6553 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_3_2, |
| 6554 | &repName, (xmlSchemaTypePtr) ret, node, child, NULL, |
| 6555 | "(annotation?)"); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6556 | else |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6557 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 6558 | &repName, (xmlSchemaTypePtr) ret, node, child, NULL, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6559 | "(annotation?)"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6560 | } |
| 6561 | } else { |
| 6562 | if (IS_SCHEMA(child, "simpleType")) { |
| 6563 | if (ret->typeName != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6564 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6565 | * 3.2.3 : 4 |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6566 | * type and <simpleType> must not both be present. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6567 | */ |
| 6568 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_4, |
| 6569 | &repName, (xmlSchemaTypePtr) ret, node, child, |
| 6570 | "The attribute 'type' and the <simpleType> child " |
| 6571 | "are mutually exclusive", NULL); |
| 6572 | } else |
| 6573 | ret->subtypes = xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
| 6574 | child = child->next; |
| 6575 | } |
| 6576 | if (child != NULL) |
| 6577 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 6578 | &repName, (xmlSchemaTypePtr) ret, node, child, NULL, |
| 6579 | "(annotation?, simpleType?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6580 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6581 | /* |
| 6582 | * Cleanup. |
| 6583 | */ |
| 6584 | if (repName != NULL) |
| 6585 | xmlFree(repName); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6586 | return (ret); |
| 6587 | } |
| 6588 | |
| 6589 | /** |
| 6590 | * xmlSchemaParseAttributeGroup: |
| 6591 | * @ctxt: a schema validation context |
| 6592 | * @schema: the schema being built |
| 6593 | * @node: a subtree containing XML Schema informations |
| 6594 | * |
| 6595 | * parse a XML schema Attribute Group declaration |
| 6596 | * *WARNING* this interface is highly subject to change |
| 6597 | * |
| 6598 | * Returns the attribute group or NULL in case of error. |
| 6599 | */ |
| 6600 | static xmlSchemaAttributeGroupPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6601 | xmlSchemaParseAttributeGroup(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6602 | xmlSchemaPtr schema, xmlNodePtr node, |
| 6603 | int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6604 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6605 | const xmlChar *name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6606 | xmlSchemaAttributeGroupPtr ret; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6607 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6608 | const xmlChar *oldcontainer; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6609 | xmlAttrPtr attr, nameAttr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6610 | |
| 6611 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 6612 | return (NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6613 | |
| 6614 | nameAttr = xmlSchemaGetPropNode(node, "name"); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6615 | attr = xmlSchemaGetPropNode(node, "ref"); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6616 | if ((topLevel) || (attr == NULL)) { |
| 6617 | /* |
| 6618 | * Parse as an attribute group definition. |
| 6619 | * Note that those are allowed at top level only. |
| 6620 | */ |
| 6621 | if (nameAttr == NULL) { |
| 6622 | xmlSchemaPMissingAttrErr(ctxt, |
| 6623 | XML_SCHEMAP_S4S_ATTR_MISSING, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6624 | NULL, node, "name", NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6625 | return (NULL); |
| 6626 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6627 | /* REDUNDANT: name = xmlSchemaGetNodeContent(ctxt, |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 6628 | * (xmlNodePtr) nameAttr); |
| 6629 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6630 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6631 | * The name is crucial, exit if invalid. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6632 | */ |
| 6633 | if (xmlSchemaPValAttrNode(ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6634 | NULL, NULL, nameAttr, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6635 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 6636 | return (NULL); |
| 6637 | } |
| 6638 | ret = xmlSchemaAddAttributeGroup(ctxt, schema, name, node); |
| 6639 | if (ret == NULL) |
| 6640 | return (NULL); |
| 6641 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTEGROUP; |
| 6642 | ret->flags |= XML_SCHEMAS_ATTRGROUP_GLOBAL; |
| 6643 | ret->node = node; |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 6644 | ret->targetNamespace = schema->targetNamespace; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6645 | } else { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6646 | char buf[50]; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6647 | const xmlChar *refNs = NULL, *ref = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6648 | |
| 6649 | /* |
| 6650 | * Parse as an attribute group definition reference. |
| 6651 | */ |
| 6652 | if (attr == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6653 | xmlSchemaPMissingAttrErr(ctxt, |
| 6654 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 6655 | NULL, node, "ref", NULL); |
| 6656 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6657 | xmlSchemaPValAttrNodeQName(ctxt, schema, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6658 | NULL, NULL, attr, &refNs,&ref); |
| 6659 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 6660 | snprintf(buf, 49, "#agRef%d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6661 | name = (const xmlChar *) buf; |
| 6662 | if (name == NULL) { |
| 6663 | xmlSchemaPErrMemory(ctxt, "creating internal name for an " |
| 6664 | "attribute group definition reference", node); |
| 6665 | return (NULL); |
| 6666 | } |
| 6667 | ret = xmlSchemaAddAttributeGroup(ctxt, schema, name, node); |
| 6668 | if (ret == NULL) |
| 6669 | return (NULL); |
| 6670 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTEGROUP; |
| 6671 | ret->ref = ref; |
| 6672 | ret->refNs = refNs; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6673 | ret->node = node; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6674 | xmlSchemaCheckReference(ctxt, schema, node, |
| 6675 | (xmlSchemaBasicItemPtr) ret, refNs); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6676 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6677 | /* |
| 6678 | * Check for illegal attributes. |
| 6679 | */ |
| 6680 | attr = node->properties; |
| 6681 | while (attr != NULL) { |
| 6682 | if (attr->ns == NULL) { |
| 6683 | if ((((topLevel == 0) && (!xmlStrEqual(attr->name, BAD_CAST "ref"))) || |
| 6684 | (topLevel && (!xmlStrEqual(attr->name, BAD_CAST "name")))) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6685 | (!xmlStrEqual(attr->name, BAD_CAST "id"))) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6686 | { |
| 6687 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6688 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6689 | NULL, NULL, attr); |
| 6690 | } |
| 6691 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 6692 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6693 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6694 | NULL, NULL, attr); |
| 6695 | } |
| 6696 | attr = attr->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6697 | } |
| 6698 | /* TODO: Validate "id" ? */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6699 | /* |
| 6700 | * And now for the children... |
| 6701 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6702 | oldcontainer = ctxt->container; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6703 | ctxt->container = name; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6704 | child = node->children; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6705 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6706 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6707 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6708 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6709 | if (topLevel) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6710 | child = xmlSchemaParseAttrDecls(ctxt, schema, child, (xmlSchemaTypePtr) ret); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6711 | if (IS_SCHEMA(child, "anyAttribute")) { |
| 6712 | ret->attributeWildcard = xmlSchemaParseAnyAttribute(ctxt, schema, child); |
| 6713 | child = child->next; |
| 6714 | } |
| 6715 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6716 | if (child != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6717 | xmlSchemaPContentErr(ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6718 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 6719 | NULL, NULL, node, child, NULL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6720 | "(annotation?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6721 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6722 | ctxt->container = oldcontainer; |
| 6723 | return (ret); |
| 6724 | } |
| 6725 | |
| 6726 | /** |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6727 | * xmlSchemaPValAttrFormDefault: |
| 6728 | * @value: the value |
| 6729 | * @flags: the flags to be modified |
| 6730 | * @flagQualified: the specific flag for "qualified" |
| 6731 | * |
| 6732 | * Returns 0 if the value is valid, 1 otherwise. |
| 6733 | */ |
| 6734 | static int |
| 6735 | xmlSchemaPValAttrFormDefault(const xmlChar *value, |
| 6736 | int *flags, |
| 6737 | int flagQualified) |
| 6738 | { |
| 6739 | if (xmlStrEqual(value, BAD_CAST "qualified")) { |
| 6740 | if ((*flags & flagQualified) == 0) |
| 6741 | *flags |= flagQualified; |
| 6742 | } else if (!xmlStrEqual(value, BAD_CAST "unqualified")) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6743 | return (1); |
| 6744 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6745 | return (0); |
| 6746 | } |
| 6747 | |
| 6748 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6749 | * xmlSchemaPValAttrBlockFinal: |
| 6750 | * @value: the value |
| 6751 | * @flags: the flags to be modified |
| 6752 | * @flagAll: the specific flag for "#all" |
| 6753 | * @flagExtension: the specific flag for "extension" |
| 6754 | * @flagRestriction: the specific flag for "restriction" |
| 6755 | * @flagSubstitution: the specific flag for "substitution" |
| 6756 | * @flagList: the specific flag for "list" |
| 6757 | * @flagUnion: the specific flag for "union" |
| 6758 | * |
| 6759 | * Validates the value of the attribute "final" and "block". The value |
| 6760 | * is converted into the specified flag values and returned in @flags. |
| 6761 | * |
| 6762 | * Returns 0 if the value is valid, 1 otherwise. |
| 6763 | */ |
| 6764 | |
| 6765 | static int |
| 6766 | xmlSchemaPValAttrBlockFinal(const xmlChar *value, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6767 | int *flags, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6768 | int flagAll, |
| 6769 | int flagExtension, |
| 6770 | int flagRestriction, |
| 6771 | int flagSubstitution, |
| 6772 | int flagList, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6773 | int flagUnion) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6774 | { |
| 6775 | int ret = 0; |
| 6776 | |
| 6777 | /* |
| 6778 | * TODO: This does not check for dublicate entries. |
| 6779 | */ |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 6780 | if ((flags == NULL) || (value == NULL)) |
| 6781 | return (-1); |
| 6782 | if (value[0] == 0) |
| 6783 | return (0); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6784 | if (xmlStrEqual(value, BAD_CAST "#all")) { |
| 6785 | if (flagAll != -1) |
| 6786 | *flags |= flagAll; |
| 6787 | else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6788 | if (flagExtension != -1) |
| 6789 | *flags |= flagExtension; |
| 6790 | if (flagRestriction != -1) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6791 | *flags |= flagRestriction; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6792 | if (flagSubstitution != -1) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6793 | *flags |= flagSubstitution; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6794 | if (flagList != -1) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6795 | *flags |= flagList; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6796 | if (flagUnion != -1) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6797 | *flags |= flagUnion; |
| 6798 | } |
| 6799 | } else { |
| 6800 | const xmlChar *end, *cur = value; |
| 6801 | xmlChar *item; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6802 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6803 | do { |
| 6804 | while (IS_BLANK_CH(*cur)) |
| 6805 | cur++; |
| 6806 | end = cur; |
| 6807 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 6808 | end++; |
| 6809 | if (end == cur) |
| 6810 | break; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6811 | item = xmlStrndup(cur, end - cur); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6812 | if (xmlStrEqual(item, BAD_CAST "extension")) { |
| 6813 | if (flagExtension != -1) { |
| 6814 | if ((*flags & flagExtension) == 0) |
| 6815 | *flags |= flagExtension; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6816 | } else |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6817 | ret = 1; |
| 6818 | } else if (xmlStrEqual(item, BAD_CAST "restriction")) { |
| 6819 | if (flagRestriction != -1) { |
| 6820 | if ((*flags & flagRestriction) == 0) |
| 6821 | *flags |= flagRestriction; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6822 | } else |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6823 | ret = 1; |
| 6824 | } else if (xmlStrEqual(item, BAD_CAST "substitution")) { |
| 6825 | if (flagSubstitution != -1) { |
| 6826 | if ((*flags & flagSubstitution) == 0) |
| 6827 | *flags |= flagSubstitution; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6828 | } else |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6829 | ret = 1; |
| 6830 | } else if (xmlStrEqual(item, BAD_CAST "list")) { |
| 6831 | if (flagList != -1) { |
| 6832 | if ((*flags & flagList) == 0) |
| 6833 | *flags |= flagList; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6834 | } else |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6835 | ret = 1; |
| 6836 | } else if (xmlStrEqual(item, BAD_CAST "union")) { |
| 6837 | if (flagUnion != -1) { |
| 6838 | if ((*flags & flagUnion) == 0) |
| 6839 | *flags |= flagUnion; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6840 | } else |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6841 | ret = 1; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6842 | } else |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6843 | ret = 1; |
| 6844 | if (item != NULL) |
| 6845 | xmlFree(item); |
| 6846 | cur = end; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6847 | } while ((ret == 0) && (*cur != 0)); |
| 6848 | } |
| 6849 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6850 | return (ret); |
| 6851 | } |
| 6852 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6853 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6854 | xmlSchemaCheckCSelectorXPath(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6855 | xmlSchemaIDCPtr idc, |
| 6856 | xmlSchemaIDCSelectPtr selector, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6857 | xmlAttrPtr attr, |
| 6858 | int isField) |
| 6859 | { |
| 6860 | xmlNodePtr node; |
| 6861 | |
| 6862 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6863 | * c-selector-xpath: |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6864 | * Schema Component Constraint: Selector Value OK |
| 6865 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6866 | * TODO: 1 The {selector} must be a valid XPath expression, as defined |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6867 | * in [XPath]. |
| 6868 | */ |
| 6869 | if (selector == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6870 | xmlSchemaPErr(ctxt, idc->node, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6871 | XML_SCHEMAP_INTERNAL, |
| 6872 | "Internal error: xmlSchemaCheckCSelectorXPath, " |
| 6873 | "the selector is not specified.\n", NULL, NULL); |
| 6874 | return (-1); |
| 6875 | } |
| 6876 | if (attr == NULL) |
| 6877 | node = idc->node; |
| 6878 | else |
| 6879 | node = (xmlNodePtr) attr; |
| 6880 | if (selector->xpath == NULL) { |
| 6881 | xmlSchemaPCustomErr(ctxt, |
| 6882 | /* TODO: Adjust error code. */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6883 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 6884 | NULL, NULL, node, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6885 | "The XPath expression of the selector is not valid", NULL); |
| 6886 | return (XML_SCHEMAP_S4S_ATTR_INVALID_VALUE); |
| 6887 | } else { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 6888 | const xmlChar **nsArray = NULL; |
| 6889 | xmlNsPtr *nsList = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6890 | /* |
| 6891 | * Compile the XPath expression. |
| 6892 | */ |
| 6893 | /* |
| 6894 | * TODO: We need the array of in-scope namespaces for compilation. |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 6895 | * TODO: Call xmlPatterncompile with different options for selector/ |
| 6896 | * field. |
| 6897 | */ |
| 6898 | nsList = xmlGetNsList(attr->doc, attr->parent); |
| 6899 | /* |
| 6900 | * Build an array of prefixes and namespaces. |
| 6901 | */ |
| 6902 | if (nsList != NULL) { |
| 6903 | int i, count = 0; |
| 6904 | xmlNsPtr ns; |
| 6905 | |
| 6906 | for (i = 0; nsList[i] != NULL; i++) |
| 6907 | count++; |
| 6908 | |
| 6909 | nsArray = (const xmlChar **) xmlMalloc( |
| 6910 | (count * 2 + 1) * sizeof(const xmlChar *)); |
| 6911 | if (nsArray == NULL) { |
| 6912 | xmlSchemaPErrMemory(ctxt, "allocating a namespace array", |
| 6913 | NULL); |
| 6914 | return (-1); |
| 6915 | } |
| 6916 | for (i = 0; i < count; i++) { |
| 6917 | ns = nsList[i]; |
| 6918 | nsArray[2 * i] = nsList[i]->href; |
| 6919 | nsArray[2 * i + 1] = nsList[i]->prefix; |
| 6920 | } |
| 6921 | nsArray[count * 2] = NULL; |
| 6922 | xmlFree(nsList); |
| 6923 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6924 | /* |
| 6925 | * TODO: Differentiate between "selector" and "field". |
| 6926 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 6927 | if (isField) |
| 6928 | selector->xpathComp = (void *) xmlPatterncompile(selector->xpath, |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 6929 | NULL, XML_PATTERN_XSFIELD, nsArray); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 6930 | else |
| 6931 | selector->xpathComp = (void *) xmlPatterncompile(selector->xpath, |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 6932 | NULL, XML_PATTERN_XSSEL, nsArray); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 6933 | if (nsArray != NULL) |
| 6934 | xmlFree((xmlChar **) nsArray); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6935 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 6936 | if (selector->xpathComp == NULL) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6937 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 6938 | /* TODO: Adjust error code? */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6939 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 6940 | NULL, NULL, node, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6941 | "The XPath expression '%s' could not be " |
| 6942 | "compiled", selector->xpath); |
| 6943 | return (XML_SCHEMAP_S4S_ATTR_INVALID_VALUE); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6944 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6945 | } |
| 6946 | return (0); |
| 6947 | } |
| 6948 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6949 | #define ADD_ANNOTATION(annot) \ |
| 6950 | xmlSchemaAnnotPtr cur = item->annot; \ |
| 6951 | if (item->annot == NULL) { \ |
| 6952 | item->annot = annot; \ |
| 6953 | return (annot); \ |
| 6954 | } \ |
| 6955 | cur = item->annot; \ |
| 6956 | if (cur->next != NULL) { \ |
| 6957 | cur = cur->next; \ |
| 6958 | } \ |
| 6959 | cur->next = annot; |
| 6960 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6961 | /** |
| 6962 | * xmlSchemaAssignAnnotation: |
| 6963 | * @item: the schema component |
| 6964 | * @annot: the annotation |
| 6965 | * |
| 6966 | * Adds the annotation to the given schema component. |
| 6967 | * |
| 6968 | * Returns the given annotaion. |
| 6969 | */ |
| 6970 | static xmlSchemaAnnotPtr |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6971 | xmlSchemaAddAnnotation(xmlSchemaAnnotItemPtr annItem, |
| 6972 | xmlSchemaAnnotPtr annot) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6973 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6974 | if ((annItem == NULL) || (annot == NULL)) |
| 6975 | return (NULL); |
| 6976 | switch (annItem->type) { |
| 6977 | case XML_SCHEMA_TYPE_ELEMENT: { |
| 6978 | xmlSchemaElementPtr item = (xmlSchemaElementPtr) annItem; |
| 6979 | ADD_ANNOTATION(annot) |
| 6980 | } |
| 6981 | break; |
| 6982 | case XML_SCHEMA_TYPE_ATTRIBUTE: { |
| 6983 | xmlSchemaAttributePtr item = (xmlSchemaAttributePtr) annItem; |
| 6984 | ADD_ANNOTATION(annot) |
| 6985 | } |
| 6986 | break; |
| 6987 | case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: |
| 6988 | case XML_SCHEMA_TYPE_ANY: { |
| 6989 | xmlSchemaWildcardPtr item = (xmlSchemaWildcardPtr) annItem; |
| 6990 | ADD_ANNOTATION(annot) |
| 6991 | } |
| 6992 | break; |
| 6993 | case XML_SCHEMA_TYPE_PARTICLE: |
| 6994 | case XML_SCHEMA_TYPE_IDC_KEY: |
| 6995 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 6996 | case XML_SCHEMA_TYPE_IDC_UNIQUE: { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 6997 | xmlSchemaAnnotItemPtr item = (xmlSchemaAnnotItemPtr) annItem; |
| 6998 | ADD_ANNOTATION(annot) |
| 6999 | } |
| 7000 | break; |
| 7001 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: { |
| 7002 | xmlSchemaAttributeGroupPtr item = |
| 7003 | (xmlSchemaAttributeGroupPtr) annItem; |
| 7004 | ADD_ANNOTATION(annot) |
| 7005 | } |
| 7006 | break; |
| 7007 | case XML_SCHEMA_TYPE_NOTATION: { |
| 7008 | xmlSchemaNotationPtr item = (xmlSchemaNotationPtr) annItem; |
| 7009 | ADD_ANNOTATION(annot) |
| 7010 | } |
| 7011 | break; |
| 7012 | case XML_SCHEMA_FACET_MININCLUSIVE: |
| 7013 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
| 7014 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
| 7015 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
| 7016 | case XML_SCHEMA_FACET_TOTALDIGITS: |
| 7017 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
| 7018 | case XML_SCHEMA_FACET_PATTERN: |
| 7019 | case XML_SCHEMA_FACET_ENUMERATION: |
| 7020 | case XML_SCHEMA_FACET_WHITESPACE: |
| 7021 | case XML_SCHEMA_FACET_LENGTH: |
| 7022 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 7023 | case XML_SCHEMA_FACET_MINLENGTH: { |
| 7024 | xmlSchemaFacetPtr item = (xmlSchemaFacetPtr) annItem; |
| 7025 | ADD_ANNOTATION(annot) |
| 7026 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7027 | break; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7028 | case XML_SCHEMA_TYPE_SIMPLE: |
| 7029 | case XML_SCHEMA_TYPE_COMPLEX: { |
| 7030 | xmlSchemaTypePtr item = (xmlSchemaTypePtr) annItem; |
| 7031 | ADD_ANNOTATION(annot) |
| 7032 | } |
| 7033 | break; |
| 7034 | case XML_SCHEMA_TYPE_GROUP: { |
| 7035 | xmlSchemaModelGroupDefPtr item = (xmlSchemaModelGroupDefPtr) annItem; |
| 7036 | ADD_ANNOTATION(annot) |
| 7037 | } |
| 7038 | break; |
| 7039 | case XML_SCHEMA_TYPE_SEQUENCE: |
| 7040 | case XML_SCHEMA_TYPE_CHOICE: |
| 7041 | case XML_SCHEMA_TYPE_ALL: { |
| 7042 | xmlSchemaModelGroupPtr item = (xmlSchemaModelGroupPtr) annItem; |
| 7043 | ADD_ANNOTATION(annot) |
| 7044 | } |
| 7045 | break; |
| 7046 | default: |
| 7047 | xmlSchemaPCustomErr(NULL, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7048 | XML_SCHEMAP_INTERNAL, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7049 | NULL, NULL, NULL, |
| 7050 | "Internal error: xmlSchemaAddAnnotation, " |
| 7051 | "The item is not a annotated schema component", NULL); |
| 7052 | break; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7053 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7054 | return (annot); |
| 7055 | } |
| 7056 | |
| 7057 | /** |
| 7058 | * xmlSchemaParseIDCSelectorAndField: |
| 7059 | * @ctxt: a schema validation context |
| 7060 | * @schema: the schema being built |
| 7061 | * @node: a subtree containing XML Schema informations |
| 7062 | * |
| 7063 | * Parses a XML Schema identity-contraint definition's |
| 7064 | * <selector> and <field> elements. |
| 7065 | * |
| 7066 | * Returns the parsed identity-constraint definition. |
| 7067 | */ |
| 7068 | static xmlSchemaIDCSelectPtr |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7069 | xmlSchemaParseIDCSelectorAndField(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7070 | xmlSchemaPtr schema, |
| 7071 | xmlSchemaIDCPtr idc, |
| 7072 | xmlNodePtr node, |
| 7073 | int isField) |
| 7074 | { |
| 7075 | xmlSchemaIDCSelectPtr item; |
| 7076 | xmlNodePtr child = NULL; |
| 7077 | xmlAttrPtr attr; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7078 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7079 | /* |
| 7080 | * Check for illegal attributes. |
| 7081 | */ |
| 7082 | attr = node->properties; |
| 7083 | while (attr != NULL) { |
| 7084 | if (attr->ns == NULL) { |
| 7085 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 7086 | (!xmlStrEqual(attr->name, BAD_CAST "xpath"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7087 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7088 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7089 | NULL, NULL, attr); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7090 | } |
| 7091 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7092 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7093 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7094 | NULL, NULL, attr); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7095 | } |
| 7096 | attr = attr->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7097 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7098 | /* |
| 7099 | * Create the item. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7100 | */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7101 | item = (xmlSchemaIDCSelectPtr) xmlMalloc(sizeof(xmlSchemaIDCSelect)); |
| 7102 | if (item == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7103 | xmlSchemaPErrMemory(ctxt, |
| 7104 | "allocating a 'selector' of an identity-constraint definition", |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7105 | NULL); |
| 7106 | return (NULL); |
| 7107 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7108 | memset(item, 0, sizeof(xmlSchemaIDCSelect)); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7109 | /* |
| 7110 | * Attribute "xpath" (mandatory). |
| 7111 | */ |
| 7112 | attr = xmlSchemaGetPropNode(node, "xpath"); |
| 7113 | if (attr == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7114 | xmlSchemaPMissingAttrErr(ctxt, |
| 7115 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 7116 | NULL, node, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7117 | "name", NULL); |
| 7118 | } else { |
| 7119 | item->xpath = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 7120 | /* |
| 7121 | * URGENT TODO: "field"s have an other syntax than "selector"s. |
| 7122 | */ |
| 7123 | |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 7124 | if (xmlSchemaCheckCSelectorXPath(ctxt, idc, item, attr, |
| 7125 | isField) == -1) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7126 | xmlSchemaPErr(ctxt, |
| 7127 | (xmlNodePtr) attr, |
| 7128 | XML_SCHEMAP_INTERNAL, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7129 | "Internal error: xmlSchemaParseIDCSelectorAndField, " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7130 | "validating the XPath expression of a IDC selector.\n", |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7131 | NULL, NULL); |
| 7132 | } |
| 7133 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7134 | } |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 7135 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7136 | /* |
| 7137 | * And now for the children... |
| 7138 | */ |
| 7139 | child = node->children; |
| 7140 | if (IS_SCHEMA(child, "annotation")) { |
| 7141 | /* |
| 7142 | * Add the annotation to the parent IDC. |
| 7143 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7144 | xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) idc, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7145 | xmlSchemaParseAnnotation(ctxt, schema, child)); |
| 7146 | child = child->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7147 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7148 | if (child != NULL) { |
| 7149 | xmlSchemaPContentErr(ctxt, |
| 7150 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7151 | NULL, NULL, node, child, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7152 | NULL, "(annotation?)"); |
| 7153 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7154 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7155 | return (item); |
| 7156 | } |
| 7157 | |
| 7158 | /** |
| 7159 | * xmlSchemaParseIDC: |
| 7160 | * @ctxt: a schema validation context |
| 7161 | * @schema: the schema being built |
| 7162 | * @node: a subtree containing XML Schema informations |
| 7163 | * |
| 7164 | * Parses a XML Schema identity-contraint definition. |
| 7165 | * |
| 7166 | * Returns the parsed identity-constraint definition. |
| 7167 | */ |
| 7168 | static xmlSchemaIDCPtr |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7169 | xmlSchemaParseIDC(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7170 | xmlSchemaPtr schema, |
| 7171 | xmlNodePtr node, |
| 7172 | xmlSchemaTypeType idcCategory, |
| 7173 | const xmlChar *targetNamespace) |
| 7174 | { |
| 7175 | xmlSchemaIDCPtr item = NULL; |
| 7176 | xmlNodePtr child = NULL; |
| 7177 | xmlAttrPtr attr; |
| 7178 | const xmlChar *name = NULL; |
| 7179 | xmlSchemaIDCSelectPtr field = NULL, lastField = NULL; |
| 7180 | int resAdd; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7181 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7182 | /* |
| 7183 | * Check for illegal attributes. |
| 7184 | */ |
| 7185 | attr = node->properties; |
| 7186 | while (attr != NULL) { |
| 7187 | if (attr->ns == NULL) { |
| 7188 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 7189 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
| 7190 | ((idcCategory != XML_SCHEMA_TYPE_IDC_KEYREF) || |
| 7191 | (!xmlStrEqual(attr->name, BAD_CAST "refer")))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7192 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7193 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7194 | NULL, NULL, attr); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7195 | } |
| 7196 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7197 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7198 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7199 | NULL, NULL, attr); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7200 | } |
| 7201 | attr = attr->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7202 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7203 | /* |
| 7204 | * Attribute "name" (mandatory). |
| 7205 | */ |
| 7206 | attr = xmlSchemaGetPropNode(node, "name"); |
| 7207 | if (attr == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7208 | xmlSchemaPMissingAttrErr(ctxt, |
| 7209 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 7210 | NULL, node, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7211 | "name", NULL); |
| 7212 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7213 | } else if (xmlSchemaPValAttrNode(ctxt, |
| 7214 | NULL, NULL, attr, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7215 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 7216 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7217 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7218 | /* |
| 7219 | * Create the component. |
| 7220 | */ |
| 7221 | if (schema->idcDef == NULL) |
| 7222 | schema->idcDef = xmlHashCreateDict(10, ctxt->dict); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7223 | if (schema->idcDef == NULL) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7224 | return (NULL); |
| 7225 | |
| 7226 | item = (xmlSchemaIDCPtr) xmlMalloc(sizeof(xmlSchemaIDC)); |
| 7227 | if (item == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7228 | xmlSchemaPErrMemory(ctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7229 | "allocating an identity-constraint definition", NULL); |
| 7230 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7231 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7232 | /* |
| 7233 | * Add the IDC to the list of IDCs on the schema component. |
| 7234 | */ |
| 7235 | resAdd = xmlHashAddEntry2(schema->idcDef, name, targetNamespace, item); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7236 | if (resAdd != 0) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7237 | xmlSchemaPCustomErrExt(ctxt, |
| 7238 | XML_SCHEMAP_REDEFINED_TYPE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7239 | NULL, NULL, node, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7240 | "An identity-constraint definition with the name '%s' " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7241 | "and targetNamespace '%s' does already exist", |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7242 | name, targetNamespace, NULL); |
| 7243 | xmlFree(item); |
| 7244 | return (NULL); |
| 7245 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7246 | memset(item, 0, sizeof(xmlSchemaIDC)); |
| 7247 | item->name = name; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7248 | item->type = idcCategory; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7249 | item->node = node; |
Kasimier T. Buchcik | c306d90 | 2005-07-08 21:37:44 +0000 | [diff] [blame] | 7250 | if (ctxt->assemble != NULL) |
| 7251 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) item); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7252 | /* |
| 7253 | * The target namespace of the parent element declaration. |
| 7254 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7255 | item->targetNamespace = targetNamespace; |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 7256 | xmlSchemaPValAttrID(ctxt, NULL, (xmlSchemaTypePtr) item, |
| 7257 | node, BAD_CAST "id"); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7258 | if (idcCategory == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 7259 | /* |
| 7260 | * Attribute "refer" (mandatory). |
| 7261 | */ |
| 7262 | attr = xmlSchemaGetPropNode(node, "refer"); |
| 7263 | if (attr == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7264 | xmlSchemaPMissingAttrErr(ctxt, |
| 7265 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 7266 | NULL, node, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7267 | "refer", NULL); |
| 7268 | } else { |
| 7269 | /* |
| 7270 | * Create a reference item. |
| 7271 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7272 | item->ref = xmlSchemaNewQNameRef(schema, XML_SCHEMA_TYPE_IDC_KEY, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7273 | NULL, NULL); |
| 7274 | if (item->ref == NULL) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7275 | return (NULL); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7276 | xmlSchemaPValAttrNodeQName(ctxt, schema, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7277 | NULL, NULL, attr, |
| 7278 | &(item->ref->targetNamespace), |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7279 | &(item->ref->name)); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7280 | xmlSchemaCheckReference(ctxt, schema, node, |
| 7281 | (xmlSchemaBasicItemPtr) item, |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 7282 | item->ref->targetNamespace); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7283 | } |
| 7284 | } |
| 7285 | /* |
| 7286 | * And now for the children... |
| 7287 | */ |
| 7288 | child = node->children; |
| 7289 | if (IS_SCHEMA(child, "annotation")) { |
| 7290 | item->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7291 | child = child->next; |
| 7292 | } |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 7293 | if (child == NULL) { |
| 7294 | xmlSchemaPContentErr(ctxt, |
| 7295 | XML_SCHEMAP_S4S_ELEM_MISSING, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7296 | NULL, NULL, node, child, |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 7297 | "A child element is missing", |
| 7298 | "(annotation?, (selector, field+))"); |
| 7299 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7300 | /* |
| 7301 | * Child element <selector>. |
| 7302 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7303 | if (IS_SCHEMA(child, "selector")) { |
| 7304 | item->selector = xmlSchemaParseIDCSelectorAndField(ctxt, schema, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7305 | item, child, 0); |
| 7306 | child = child->next; |
| 7307 | /* |
| 7308 | * Child elements <field>. |
| 7309 | */ |
| 7310 | if (IS_SCHEMA(child, "field")) { |
| 7311 | do { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7312 | field = xmlSchemaParseIDCSelectorAndField(ctxt, schema, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7313 | item, child, 1); |
| 7314 | if (field != NULL) { |
| 7315 | field->index = item->nbFields; |
| 7316 | item->nbFields++; |
| 7317 | if (lastField != NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7318 | lastField->next = field; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7319 | else |
| 7320 | item->fields = field; |
| 7321 | lastField = field; |
| 7322 | } |
| 7323 | child = child->next; |
| 7324 | } while (IS_SCHEMA(child, "field")); |
| 7325 | } else { |
| 7326 | xmlSchemaPContentErr(ctxt, |
| 7327 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7328 | NULL, NULL, node, child, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7329 | NULL, "(annotation?, (selector, field+))"); |
| 7330 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7331 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7332 | if (child != NULL) { |
| 7333 | xmlSchemaPContentErr(ctxt, |
| 7334 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7335 | NULL, NULL, node, child, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7336 | NULL, "(annotation?, (selector, field+))"); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7337 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7338 | |
| 7339 | return (item); |
| 7340 | } |
| 7341 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7342 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7343 | * xmlSchemaParseElement: |
| 7344 | * @ctxt: a schema validation context |
| 7345 | * @schema: the schema being built |
| 7346 | * @node: a subtree containing XML Schema informations |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7347 | * @topLevel: indicates if this is global declaration |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7348 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7349 | * Parses a XML schema element declaration. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7350 | * *WARNING* this interface is highly subject to change |
| 7351 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7352 | * Returns the element declaration or a particle; NULL in case |
| 7353 | * of an error or if the particle has minOccurs==maxOccurs==0. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7354 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7355 | static xmlSchemaBasicItemPtr |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7356 | xmlSchemaParseElement(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 7357 | xmlNodePtr node, int topLevel) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7358 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7359 | xmlSchemaElementPtr decl = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7360 | xmlSchemaParticlePtr particle = NULL; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7361 | xmlSchemaAnnotPtr annot = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7362 | xmlNodePtr child = NULL; |
| 7363 | xmlAttrPtr attr, nameAttr; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7364 | int min, max, isRef = 0; |
| 7365 | xmlChar *des = NULL; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7366 | |
| 7367 | /* 3.3.3 Constraints on XML Representations of Element Declarations */ |
| 7368 | /* TODO: Complete implementation of 3.3.6 */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7369 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7370 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7371 | return (NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7372 | /* |
| 7373 | * If we get a "ref" attribute on a local <element> we will assume it's |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7374 | * a reference - even if there's a "name" attribute; this seems to be more |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7375 | * robust. |
| 7376 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7377 | nameAttr = xmlSchemaGetPropNode(node, "name"); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7378 | attr = xmlSchemaGetPropNode(node, "ref"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7379 | if ((topLevel) || (attr == NULL)) { |
| 7380 | if (nameAttr == NULL) { |
| 7381 | xmlSchemaPMissingAttrErr(ctxt, |
| 7382 | XML_SCHEMAP_S4S_ATTR_MISSING, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7383 | NULL, node, "name", NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7384 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7385 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7386 | } else |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7387 | isRef = 1; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7388 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7389 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7390 | child = node->children; |
| 7391 | if (IS_SCHEMA(child, "annotation")) { |
| 7392 | annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7393 | child = child->next; |
| 7394 | } |
| 7395 | /* |
| 7396 | * Skip particle part if a global declaration. |
| 7397 | */ |
| 7398 | if (topLevel) |
| 7399 | goto declaration_part; |
| 7400 | /* |
| 7401 | * The particle part ================================================== |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7402 | */ |
| 7403 | min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "xs:nonNegativeInteger"); |
| 7404 | max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, "(xs:nonNegativeInteger | unbounded)"); |
| 7405 | xmlSchemaPCheckParticleCorrect_2(ctxt, NULL, node, min, max); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7406 | particle = xmlSchemaAddParticle(ctxt, schema, node, min, max); |
| 7407 | if (particle == NULL) |
| 7408 | goto return_null; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7409 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7410 | /* ret->flags |= XML_SCHEMAS_ELEM_REF; */ |
| 7411 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7412 | if (isRef) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7413 | const xmlChar *refNs = NULL, *ref = NULL; |
| 7414 | xmlSchemaQNameRefPtr refer = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7415 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7416 | * The reference part ============================================= |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7417 | */ |
| 7418 | xmlSchemaPValAttrNodeQName(ctxt, schema, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7419 | NULL, NULL, attr, &refNs, &ref); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7420 | xmlSchemaCheckReference(ctxt, schema, node, NULL, refNs); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7421 | /* |
| 7422 | * SPEC (3.3.3 : 2.1) "One of ref or name must be present, but not both" |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7423 | */ |
| 7424 | if (nameAttr != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7425 | xmlSchemaPMutualExclAttrErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7426 | XML_SCHEMAP_SRC_ELEMENT_2_1, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7427 | NULL, NULL, nameAttr, "ref", "name"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7428 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7429 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7430 | * Check for illegal attributes. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7431 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7432 | attr = node->properties; |
| 7433 | while (attr != NULL) { |
| 7434 | if (attr->ns == NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7435 | if (xmlStrEqual(attr->name, BAD_CAST "ref") || |
| 7436 | xmlStrEqual(attr->name, BAD_CAST "name") || |
| 7437 | xmlStrEqual(attr->name, BAD_CAST "id") || |
| 7438 | xmlStrEqual(attr->name, BAD_CAST "maxOccurs") || |
| 7439 | xmlStrEqual(attr->name, BAD_CAST "minOccurs")) |
| 7440 | { |
| 7441 | attr = attr->next; |
| 7442 | continue; |
| 7443 | } else { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7444 | /* SPEC (3.3.3 : 2.2) */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7445 | xmlSchemaPCustomAttrErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7446 | XML_SCHEMAP_SRC_ELEMENT_2_2, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7447 | NULL, NULL, attr, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7448 | "Only the attributes 'minOccurs', 'maxOccurs' and " |
| 7449 | "'id' are allowed in addition to 'ref'"); |
| 7450 | break; |
| 7451 | } |
| 7452 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 7453 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7454 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7455 | NULL, NULL, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7456 | } |
| 7457 | attr = attr->next; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7458 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7459 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7460 | * No children except <annotation> expected. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7461 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7462 | if (child != NULL) { |
| 7463 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 7464 | NULL, NULL, node, child, NULL, "(annotation?)"); |
| 7465 | } |
| 7466 | if ((min == 0) && (max == 0)) |
| 7467 | goto return_null; |
| 7468 | /* |
| 7469 | * Create the reference item. |
| 7470 | */ |
| 7471 | refer = xmlSchemaNewQNameRef(schema, XML_SCHEMA_TYPE_ELEMENT, |
| 7472 | ref, refNs); |
| 7473 | if (refer == NULL) |
| 7474 | goto return_null; |
| 7475 | particle->children = (xmlSchemaTreeItemPtr) refer; |
| 7476 | particle->annot = annot; |
| 7477 | /* |
| 7478 | * Add to assembled items; the reference need to be resolved. |
| 7479 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7480 | if (ctxt->assemble != NULL) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7481 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) particle); |
| 7482 | |
| 7483 | return ((xmlSchemaBasicItemPtr) particle); |
| 7484 | } |
| 7485 | /* |
| 7486 | * The declaration part =============================================== |
| 7487 | */ |
| 7488 | declaration_part: |
| 7489 | { |
| 7490 | const xmlChar *ns = NULL, *fixed, *name, *oldcontainer, *attrValue; |
| 7491 | xmlSchemaIDCPtr curIDC = NULL, lastIDC = NULL; |
| 7492 | |
| 7493 | if (xmlSchemaPValAttrNode(ctxt, NULL, NULL, nameAttr, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7494 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7495 | goto return_null; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7496 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7497 | * Evaluate the target namespace. |
| 7498 | */ |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 7499 | if (topLevel) { |
| 7500 | ns = schema->targetNamespace; |
| 7501 | } else { |
| 7502 | attr = xmlSchemaGetPropNode(node, "form"); |
| 7503 | if (attr != NULL) { |
| 7504 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 7505 | if (xmlStrEqual(attrValue, BAD_CAST "qualified")) { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7506 | ns = schema->targetNamespace; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 7507 | } else if (!xmlStrEqual(attrValue, BAD_CAST "unqualified")) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7508 | xmlSchemaPSimpleTypeErr(ctxt, |
| 7509 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 7510 | NULL, (xmlNodePtr) attr, |
| 7511 | NULL, "(qualified | unqualified)", |
| 7512 | attrValue, NULL, NULL, NULL); |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 7513 | } |
| 7514 | } else if (schema->flags & XML_SCHEMAS_QUALIF_ELEM) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7515 | ns = schema->targetNamespace; |
| 7516 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7517 | decl = xmlSchemaAddElement(ctxt, schema, name, ns, node, topLevel); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7518 | if (decl == NULL) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7519 | goto return_null; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7520 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7521 | decl->type = XML_SCHEMA_TYPE_ELEMENT; |
| 7522 | decl->node = node; |
| 7523 | decl->targetNamespace = ns; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7524 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7525 | * Check for illegal attributes. |
| 7526 | */ |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7527 | attr = node->properties; |
| 7528 | while (attr != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7529 | if (attr->ns == NULL) { |
| 7530 | if ((!xmlStrEqual(attr->name, BAD_CAST "name")) && |
| 7531 | (!xmlStrEqual(attr->name, BAD_CAST "type")) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7532 | (!xmlStrEqual(attr->name, BAD_CAST "id")) && |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7533 | (!xmlStrEqual(attr->name, BAD_CAST "default")) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7534 | (!xmlStrEqual(attr->name, BAD_CAST "fixed")) && |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7535 | (!xmlStrEqual(attr->name, BAD_CAST "block")) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7536 | (!xmlStrEqual(attr->name, BAD_CAST "nillable"))) |
| 7537 | { |
| 7538 | if (topLevel == 0) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7539 | if ((!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) && |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7540 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7541 | (!xmlStrEqual(attr->name, BAD_CAST "form"))) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7542 | { |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 7543 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7544 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7545 | NULL, (xmlSchemaTypePtr) decl, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7546 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7547 | } else if ((!xmlStrEqual(attr->name, BAD_CAST "final")) && |
| 7548 | (!xmlStrEqual(attr->name, BAD_CAST "abstract")) && |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7549 | (!xmlStrEqual(attr->name, BAD_CAST "substitutionGroup"))) { |
| 7550 | |
| 7551 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7552 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7553 | NULL, (xmlSchemaTypePtr) decl, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7554 | } |
| 7555 | } |
| 7556 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7557 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7558 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7559 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7560 | NULL, (xmlSchemaTypePtr) decl, attr); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7561 | } |
| 7562 | attr = attr->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7563 | } |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7564 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7565 | * Extract/validate attributes. |
| 7566 | */ |
| 7567 | if (topLevel) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7568 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7569 | * Process top attributes of global element declarations here. |
| 7570 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7571 | decl->flags |= XML_SCHEMAS_ELEM_GLOBAL; |
| 7572 | decl->flags |= XML_SCHEMAS_ELEM_TOPLEVEL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7573 | xmlSchemaPValAttrQName(ctxt, schema, NULL, |
| 7574 | (xmlSchemaTypePtr) decl, node, "substitutionGroup", |
| 7575 | &(decl->substGroupNs), &(decl->substGroup)); |
| 7576 | if (xmlGetBooleanProp(ctxt, NULL, (xmlSchemaTypePtr) decl, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7577 | node, "abstract", 0)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7578 | decl->flags |= XML_SCHEMAS_ELEM_ABSTRACT; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7579 | /* |
| 7580 | * Attribute "final". |
| 7581 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7582 | attr = xmlSchemaGetPropNode(node, "final"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7583 | if (attr == NULL) { |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 7584 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION) |
| 7585 | decl->flags |= XML_SCHEMAS_ELEM_FINAL_EXTENSION; |
| 7586 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION) |
| 7587 | decl->flags |= XML_SCHEMAS_ELEM_FINAL_RESTRICTION; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7588 | } else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7589 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 7590 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(decl->flags), |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7591 | -1, |
| 7592 | XML_SCHEMAS_ELEM_FINAL_EXTENSION, |
| 7593 | XML_SCHEMAS_ELEM_FINAL_RESTRICTION, -1, -1, -1) != 0) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7594 | xmlSchemaPSimpleTypeErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7595 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7596 | (xmlSchemaTypePtr) decl, (xmlNodePtr) attr, |
| 7597 | NULL, "(#all | List of (extension | restriction))", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7598 | attrValue, NULL, NULL, NULL); |
| 7599 | } |
| 7600 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7601 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7602 | /* |
| 7603 | * Attribute "block". |
| 7604 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7605 | attr = xmlSchemaGetPropNode(node, "block"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7606 | if (attr == NULL) { |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 7607 | /* |
| 7608 | * Apply default "block" values. |
| 7609 | */ |
| 7610 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION) |
| 7611 | decl->flags |= XML_SCHEMAS_ELEM_BLOCK_RESTRICTION; |
| 7612 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION) |
| 7613 | decl->flags |= XML_SCHEMAS_ELEM_BLOCK_EXTENSION; |
| 7614 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION) |
| 7615 | decl->flags |= XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7616 | } else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7617 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 7618 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(decl->flags), |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7619 | -1, |
| 7620 | XML_SCHEMAS_ELEM_BLOCK_EXTENSION, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7621 | XML_SCHEMAS_ELEM_BLOCK_RESTRICTION, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7622 | XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION, -1, -1) != 0) { |
| 7623 | xmlSchemaPSimpleTypeErr(ctxt, |
| 7624 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7625 | (xmlSchemaTypePtr) decl, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7626 | NULL, "(#all | List of (extension | " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7627 | "restriction | substitution))", attrValue, |
| 7628 | NULL, NULL, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7629 | } |
| 7630 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7631 | if (xmlGetBooleanProp(ctxt, NULL, (xmlSchemaTypePtr) decl, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7632 | node, "nillable", 0)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7633 | decl->flags |= XML_SCHEMAS_ELEM_NILLABLE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7634 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7635 | attr = xmlSchemaGetPropNode(node, "type"); |
| 7636 | if (attr != NULL) { |
| 7637 | xmlSchemaPValAttrNodeQName(ctxt, schema, |
| 7638 | NULL, (xmlSchemaTypePtr) decl, attr, |
| 7639 | &(decl->namedTypeNs), &(decl->namedType)); |
| 7640 | xmlSchemaCheckReference(ctxt, schema, node, |
| 7641 | (xmlSchemaBasicItemPtr) decl, decl->namedTypeNs); |
| 7642 | } |
| 7643 | decl->value = xmlSchemaGetProp(ctxt, node, "default"); |
| 7644 | attr = xmlSchemaGetPropNode(node, "fixed"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7645 | if (attr != NULL) { |
| 7646 | fixed = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7647 | if (decl->value != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7648 | /* |
| 7649 | * 3.3.3 : 1 |
| 7650 | * default and fixed must not both be present. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7651 | */ |
| 7652 | xmlSchemaPMutualExclAttrErr(ctxt, |
| 7653 | XML_SCHEMAP_SRC_ELEMENT_1, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7654 | NULL, (xmlSchemaTypePtr) decl, attr, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7655 | "default", "fixed"); |
| 7656 | } else { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7657 | decl->flags |= XML_SCHEMAS_ELEM_FIXED; |
| 7658 | decl->value = fixed; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7659 | } |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7660 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7661 | /* |
| 7662 | * And now for the children... |
| 7663 | */ |
| 7664 | oldcontainer = ctxt->container; |
| 7665 | ctxt->container = decl->name; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7666 | if (IS_SCHEMA(child, "complexType")) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7667 | /* |
| 7668 | * 3.3.3 : 3 |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7669 | * "type" and either <simpleType> or <complexType> are mutually |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7670 | * exclusive |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7671 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7672 | if (decl->namedType != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7673 | xmlSchemaPContentErr(ctxt, |
| 7674 | XML_SCHEMAP_SRC_ELEMENT_3, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7675 | NULL, (xmlSchemaTypePtr) decl, node, child, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7676 | "The attribute 'type' and the <complexType> child are " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7677 | "mutually exclusive", NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7678 | } else |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 7679 | ELEM_TYPE(decl) = xmlSchemaParseComplexType(ctxt, schema, child, 0); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7680 | child = child->next; |
| 7681 | } else if (IS_SCHEMA(child, "simpleType")) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7682 | /* |
| 7683 | * 3.3.3 : 3 |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7684 | * "type" and either <simpleType> or <complexType> are |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7685 | * mutually exclusive |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7686 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7687 | if (decl->namedType != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7688 | xmlSchemaPContentErr(ctxt, |
| 7689 | XML_SCHEMAP_SRC_ELEMENT_3, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7690 | NULL, (xmlSchemaTypePtr) decl, node, child, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7691 | "The attribute 'type' and the <simpleType> child are " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7692 | "mutually exclusive", NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7693 | } else |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 7694 | ELEM_TYPE(decl) = xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7695 | child = child->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7696 | } |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7697 | while ((IS_SCHEMA(child, "unique")) || |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7698 | (IS_SCHEMA(child, "key")) || (IS_SCHEMA(child, "keyref"))) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7699 | if (IS_SCHEMA(child, "unique")) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7700 | curIDC = xmlSchemaParseIDC(ctxt, schema, child, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7701 | XML_SCHEMA_TYPE_IDC_UNIQUE, decl->targetNamespace); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7702 | } else if (IS_SCHEMA(child, "key")) { |
| 7703 | curIDC = xmlSchemaParseIDC(ctxt, schema, child, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7704 | XML_SCHEMA_TYPE_IDC_KEY, decl->targetNamespace); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7705 | } else if (IS_SCHEMA(child, "keyref")) { |
| 7706 | curIDC = xmlSchemaParseIDC(ctxt, schema, child, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7707 | XML_SCHEMA_TYPE_IDC_KEYREF, decl->targetNamespace); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7708 | } |
| 7709 | if (lastIDC != NULL) |
| 7710 | lastIDC->next = curIDC; |
| 7711 | else |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7712 | decl->idcs = (void *) curIDC; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7713 | lastIDC = curIDC; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 7714 | child = child->next; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7715 | } |
| 7716 | if (child != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7717 | xmlSchemaPContentErr(ctxt, |
| 7718 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7719 | NULL, (xmlSchemaTypePtr) decl, node, child, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7720 | NULL, "(annotation?, ((simpleType | complexType)?, " |
| 7721 | "(unique | key | keyref)*))"); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7722 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7723 | ctxt->container = oldcontainer; |
| 7724 | decl->annot = annot; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7725 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7726 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7727 | * NOTE: Element Declaration Representation OK 4. will be checked at a |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7728 | * different layer. |
| 7729 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7730 | FREE_AND_NULL(des) |
| 7731 | if (topLevel) |
| 7732 | return ((xmlSchemaBasicItemPtr) decl); |
| 7733 | else { |
| 7734 | particle->children = (xmlSchemaTreeItemPtr) decl; |
| 7735 | return ((xmlSchemaBasicItemPtr) particle); |
| 7736 | } |
| 7737 | |
| 7738 | return_null: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7739 | FREE_AND_NULL(des); |
| 7740 | if (annot != NULL) { |
| 7741 | if (particle != NULL) |
| 7742 | particle->annot = NULL; |
| 7743 | if (decl != NULL) |
| 7744 | decl->annot = NULL; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7745 | xmlSchemaFreeAnnot(annot); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7746 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7747 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7748 | } |
| 7749 | |
| 7750 | /** |
| 7751 | * xmlSchemaParseUnion: |
| 7752 | * @ctxt: a schema validation context |
| 7753 | * @schema: the schema being built |
| 7754 | * @node: a subtree containing XML Schema informations |
| 7755 | * |
| 7756 | * parse a XML schema Union definition |
| 7757 | * *WARNING* this interface is highly subject to change |
| 7758 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7759 | * Returns -1 in case of internal error, 0 in case of success and a positive |
| 7760 | * error code otherwise. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7761 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7762 | static int |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7763 | xmlSchemaParseUnion(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7764 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7765 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7766 | xmlSchemaTypePtr type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7767 | xmlNodePtr child = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7768 | xmlAttrPtr attr; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7769 | const xmlChar *cur = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7770 | |
| 7771 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7772 | return (-1); |
| 7773 | /* Not a component, don't create it. */ |
| 7774 | type = ctxt->ctxtType; |
| 7775 | /* |
| 7776 | * Mark the simple type as being of variety "union". |
| 7777 | */ |
| 7778 | type->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7779 | /* |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 7780 | * SPEC (Base type) (2) "If the <list> or <union> alternative is chosen, |
| 7781 | * then the ·simple ur-type definition·." |
| 7782 | */ |
| 7783 | type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7784 | /* |
| 7785 | * Check for illegal attributes. |
| 7786 | */ |
| 7787 | attr = node->properties; |
| 7788 | while (attr != NULL) { |
| 7789 | if (attr->ns == NULL) { |
| 7790 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 7791 | (!xmlStrEqual(attr->name, BAD_CAST "memberTypes"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7792 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7793 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7794 | NULL, NULL, attr); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7795 | } |
| 7796 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7797 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7798 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7799 | NULL, NULL, attr); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7800 | } |
| 7801 | attr = attr->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7802 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 7803 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7804 | /* |
| 7805 | * Attribute "memberTypes". This is a list of QNames. |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7806 | * TODO: Check the value to contain anything. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7807 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7808 | attr = xmlSchemaGetPropNode(node, "memberTypes"); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7809 | if (attr != NULL) { |
| 7810 | const xmlChar *end; |
| 7811 | xmlChar *tmp; |
| 7812 | const xmlChar *localName, *nsName; |
| 7813 | xmlSchemaTypeLinkPtr link, lastLink = NULL; |
| 7814 | xmlSchemaQNameRefPtr ref; |
| 7815 | |
| 7816 | cur = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7817 | type->ref = cur; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7818 | do { |
| 7819 | while (IS_BLANK_CH(*cur)) |
| 7820 | cur++; |
| 7821 | end = cur; |
| 7822 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 7823 | end++; |
| 7824 | if (end == cur) |
| 7825 | break; |
| 7826 | tmp = xmlStrndup(cur, end - cur); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7827 | if (xmlSchemaPValAttrNodeQNameValue(ctxt, schema, NULL, |
| 7828 | NULL, attr, BAD_CAST tmp, &nsName, &localName) == 0) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7829 | /* |
| 7830 | * Create the member type link. |
| 7831 | */ |
| 7832 | link = (xmlSchemaTypeLinkPtr) |
| 7833 | xmlMalloc(sizeof(xmlSchemaTypeLink)); |
| 7834 | if (link == NULL) { |
| 7835 | xmlSchemaPErrMemory(ctxt, "xmlSchemaParseUnion, " |
| 7836 | "allocating a type link", NULL); |
| 7837 | return (-1); |
| 7838 | } |
| 7839 | link->type = NULL; |
| 7840 | link->next = NULL; |
| 7841 | if (lastLink == NULL) |
| 7842 | type->memberTypes = link; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7843 | else |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7844 | lastLink->next = link; |
| 7845 | lastLink = link; |
| 7846 | /* |
| 7847 | * Create a reference item. |
| 7848 | */ |
| 7849 | ref = xmlSchemaNewQNameRef(schema, XML_SCHEMA_TYPE_SIMPLE, |
| 7850 | localName, nsName); |
| 7851 | if (ref == NULL) { |
| 7852 | FREE_AND_NULL(tmp) |
| 7853 | return (-1); |
| 7854 | } |
| 7855 | /* |
| 7856 | * Assign the reference to the link, it will be resolved |
| 7857 | * later during fixup of the union simple type. |
| 7858 | */ |
| 7859 | link->type = (xmlSchemaTypePtr) ref; |
| 7860 | } |
| 7861 | FREE_AND_NULL(tmp) |
| 7862 | cur = end; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7863 | } while (*cur != 0); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7864 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7865 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7866 | /* |
| 7867 | * And now for the children... |
| 7868 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7869 | child = node->children; |
| 7870 | if (IS_SCHEMA(child, "annotation")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7871 | /* |
| 7872 | * Add the annotation to the simple type ancestor. |
| 7873 | */ |
| 7874 | xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type, |
| 7875 | xmlSchemaParseAnnotation(ctxt, schema, child)); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7876 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7877 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7878 | if (IS_SCHEMA(child, "simpleType")) { |
| 7879 | xmlSchemaTypePtr subtype, last = NULL; |
| 7880 | |
| 7881 | /* |
| 7882 | * Anchor the member types in the "subtypes" field of the |
| 7883 | * simple type. |
| 7884 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7885 | while (IS_SCHEMA(child, "simpleType")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7886 | subtype = (xmlSchemaTypePtr) |
| 7887 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
| 7888 | if (subtype != NULL) { |
| 7889 | if (last == NULL) { |
| 7890 | type->subtypes = subtype; |
| 7891 | last = subtype; |
| 7892 | } else { |
| 7893 | last->next = subtype; |
| 7894 | last = subtype; |
| 7895 | } |
| 7896 | last->next = NULL; |
| 7897 | } |
| 7898 | child = child->next; |
| 7899 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7900 | } |
| 7901 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7902 | xmlSchemaPContentErr(ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7903 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7904 | NULL, NULL, node, child, NULL, "(annotation?, simpleType*)"); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7905 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7906 | if ((attr == NULL) && (type->subtypes == NULL)) { |
| 7907 | /* |
| 7908 | * src-union-memberTypes-or-simpleTypes |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7909 | * Either the memberTypes [attribute] of the <union> element must |
| 7910 | * be non-empty or there must be at least one simpleType [child]. |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7911 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7912 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7913 | XML_SCHEMAP_SRC_UNION_MEMBERTYPES_OR_SIMPLETYPES, |
| 7914 | NULL, NULL, node, |
| 7915 | "Either the attribute 'memberTypes' or " |
| 7916 | "at least one <simpleType> child must be present", NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7917 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7918 | return (0); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7919 | } |
| 7920 | |
| 7921 | /** |
| 7922 | * xmlSchemaParseList: |
| 7923 | * @ctxt: a schema validation context |
| 7924 | * @schema: the schema being built |
| 7925 | * @node: a subtree containing XML Schema informations |
| 7926 | * |
| 7927 | * parse a XML schema List definition |
| 7928 | * *WARNING* this interface is highly subject to change |
| 7929 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7930 | * Returns -1 in case of error, 0 if the declaration is improper and |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7931 | * 1 in case of success. |
| 7932 | */ |
| 7933 | static xmlSchemaTypePtr |
| 7934 | xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7935 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7936 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7937 | xmlSchemaTypePtr type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7938 | xmlNodePtr child = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7939 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7940 | |
| 7941 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 7942 | return (NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7943 | /* Not a component, don't create it. */ |
| 7944 | type = ctxt->ctxtType; |
| 7945 | /* |
| 7946 | * Mark the type as being of variety "list". |
| 7947 | */ |
| 7948 | type->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7949 | /* |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 7950 | * SPEC (Base type) (2) "If the <list> or <union> alternative is chosen, |
| 7951 | * then the ·simple ur-type definition·." |
| 7952 | */ |
| 7953 | type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7954 | /* |
| 7955 | * Check for illegal attributes. |
| 7956 | */ |
| 7957 | attr = node->properties; |
| 7958 | while (attr != NULL) { |
| 7959 | if (attr->ns == NULL) { |
| 7960 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 7961 | (!xmlStrEqual(attr->name, BAD_CAST "itemType"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7962 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7963 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7964 | NULL, NULL, attr); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7965 | } |
| 7966 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7967 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7968 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7969 | NULL, NULL, attr); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7970 | } |
| 7971 | attr = attr->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7972 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7973 | |
| 7974 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
| 7975 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7976 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7977 | * Attribute "itemType". NOTE that we will use the "ref" and "refNs" |
| 7978 | * fields for holding the reference to the itemType. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7979 | */ |
| 7980 | xmlSchemaPValAttrQName(ctxt, schema, NULL, NULL, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7981 | node, "itemType", &(type->refNs), &(type->ref)); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7982 | /* |
| 7983 | * And now for the children... |
| 7984 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7985 | child = node->children; |
| 7986 | if (IS_SCHEMA(child, "annotation")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7987 | xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type, |
| 7988 | xmlSchemaParseAnnotation(ctxt, schema, child)); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7989 | child = child->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7990 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7991 | if (IS_SCHEMA(child, "simpleType")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7992 | /* |
| 7993 | * src-list-itemType-or-simpleType |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7994 | * Either the itemType [attribute] or the <simpleType> [child] of |
| 7995 | * the <list> element must be present, but not both. |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 7996 | */ |
| 7997 | if (type->ref != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 7998 | xmlSchemaPCustomErr(ctxt, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7999 | XML_SCHEMAP_SRC_SIMPLE_TYPE_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8000 | NULL, NULL, node, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8001 | "The attribute 'itemType' and the <simpleType> child " |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8002 | "are mutually exclusive", NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8003 | } else { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8004 | type->subtypes = xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8005 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8006 | child = child->next; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8007 | } else if (type->ref == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8008 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8009 | XML_SCHEMAP_SRC_SIMPLE_TYPE_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8010 | NULL, NULL, node, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8011 | "Either the attribute 'itemType' or the <simpleType> child " |
| 8012 | "must be present", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8013 | } |
| 8014 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8015 | xmlSchemaPContentErr(ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8016 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8017 | NULL, NULL, node, child, NULL, "(annotation?, simpleType?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8018 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8019 | if ((type->ref == NULL) && |
| 8020 | (type->subtypes == NULL) && |
| 8021 | (xmlSchemaGetPropNode(node, "itemType") == NULL)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8022 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8023 | XML_SCHEMAP_SRC_SIMPLE_TYPE_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8024 | NULL, NULL, node, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8025 | "Either the attribute 'itemType' or the <simpleType> child " |
| 8026 | "must be present", NULL); |
| 8027 | } |
| 8028 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8029 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8030 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8031 | /** |
| 8032 | * xmlSchemaParseSimpleType: |
| 8033 | * @ctxt: a schema validation context |
| 8034 | * @schema: the schema being built |
| 8035 | * @node: a subtree containing XML Schema informations |
| 8036 | * |
| 8037 | * parse a XML schema Simple Type definition |
| 8038 | * *WARNING* this interface is highly subject to change |
| 8039 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 8040 | * Returns -1 in case of error, 0 if the declaration is improper and |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8041 | * 1 in case of success. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8042 | */ |
| 8043 | static xmlSchemaTypePtr |
| 8044 | xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 8045 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8046 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8047 | xmlSchemaTypePtr type, oldCtxtType, oldParentItem; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8048 | xmlNodePtr child = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8049 | const xmlChar *attrValue = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8050 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8051 | |
| 8052 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 8053 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8054 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8055 | if (topLevel) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8056 | attr = xmlSchemaGetPropNode(node, "name"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8057 | if (attr == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8058 | xmlSchemaPMissingAttrErr(ctxt, |
| 8059 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 8060 | NULL, node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8061 | "name", NULL); |
| 8062 | return (NULL); |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 8063 | } else { |
| 8064 | if (xmlSchemaPValAttrNode(ctxt, |
| 8065 | NULL, NULL, attr, |
| 8066 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &attrValue) != 0) |
| 8067 | return (NULL); |
| 8068 | /* |
| 8069 | * Skip built-in types. |
| 8070 | */ |
| 8071 | if (ctxt->isS4S) { |
| 8072 | xmlSchemaTypePtr biType; |
| 8073 | |
| 8074 | biType = xmlSchemaGetPredefinedType(attrValue, xmlSchemaNs); |
| 8075 | if (biType != NULL) |
| 8076 | return (biType); |
| 8077 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8078 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8079 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8080 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8081 | if (topLevel == 0) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8082 | char buf[40]; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8083 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8084 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8085 | * Parse as local simple type definition. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8086 | */ |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 8087 | snprintf(buf, 39, "#ST%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8088 | type = xmlSchemaAddType(ctxt, schema, (const xmlChar *)buf, NULL, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8089 | if (type == NULL) |
| 8090 | return (NULL); |
| 8091 | type->node = node; |
| 8092 | type->type = XML_SCHEMA_TYPE_SIMPLE; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8093 | type->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8094 | /* |
| 8095 | * Check for illegal attributes. |
| 8096 | */ |
| 8097 | attr = node->properties; |
| 8098 | while (attr != NULL) { |
| 8099 | if (attr->ns == NULL) { |
| 8100 | if (!xmlStrEqual(attr->name, BAD_CAST "id")) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8101 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8102 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8103 | NULL, type, attr); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8104 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8105 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8106 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8107 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8108 | NULL, type, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8109 | } |
| 8110 | attr = attr->next; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8111 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8112 | } else { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8113 | /* |
| 8114 | * Parse as global simple type definition. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8115 | * |
| 8116 | * Note that attrValue is the value of the attribute "name" here. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8117 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8118 | type = xmlSchemaAddType(ctxt, schema, attrValue, schema->targetNamespace, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8119 | if (type == NULL) |
| 8120 | return (NULL); |
| 8121 | type->node = node; |
| 8122 | type->type = XML_SCHEMA_TYPE_SIMPLE; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8123 | type->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8124 | type->flags |= XML_SCHEMAS_TYPE_GLOBAL; |
| 8125 | /* |
| 8126 | * Check for illegal attributes. |
| 8127 | */ |
| 8128 | attr = node->properties; |
| 8129 | while (attr != NULL) { |
| 8130 | if (attr->ns == NULL) { |
| 8131 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 8132 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8133 | (!xmlStrEqual(attr->name, BAD_CAST "final"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8134 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8135 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8136 | NULL, type, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8137 | } |
| 8138 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8139 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8140 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8141 | NULL, type, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8142 | } |
| 8143 | attr = attr->next; |
| 8144 | } |
| 8145 | /* |
| 8146 | * Attribute "final". |
| 8147 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8148 | attr = xmlSchemaGetPropNode(node, "final"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8149 | if (attr == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8150 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION) |
| 8151 | type->flags |= XML_SCHEMAS_TYPE_FINAL_RESTRICTION; |
| 8152 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_LIST) |
| 8153 | type->flags |= XML_SCHEMAS_TYPE_FINAL_LIST; |
| 8154 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_UNION) |
| 8155 | type->flags |= XML_SCHEMAS_TYPE_FINAL_UNION; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8156 | } else { |
| 8157 | attrValue = xmlSchemaGetProp(ctxt, node, "final"); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8158 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(type->flags), |
| 8159 | -1, -1, XML_SCHEMAS_TYPE_FINAL_RESTRICTION, -1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8160 | XML_SCHEMAS_TYPE_FINAL_LIST, |
| 8161 | XML_SCHEMAS_TYPE_FINAL_UNION) != 0) { |
| 8162 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8163 | xmlSchemaPSimpleTypeErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8164 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8165 | type, (xmlNodePtr) attr, |
| 8166 | NULL, "(#all | List of (list | union | restriction)", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8167 | attrValue, NULL, NULL, NULL); |
| 8168 | } |
| 8169 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8170 | } |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 8171 | type->targetNamespace = schema->targetNamespace; |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 8172 | xmlSchemaPValAttrID(ctxt, NULL, type, node, BAD_CAST "id"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8173 | /* |
| 8174 | * And now for the children... |
| 8175 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8176 | oldCtxtType = ctxt->ctxtType; |
| 8177 | oldParentItem = ctxt->parentItem; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8178 | ctxt->ctxtType = type; |
| 8179 | ctxt->parentItem = type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8180 | child = node->children; |
| 8181 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8182 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 8183 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8184 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8185 | if (child == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8186 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_MISSING, |
| 8187 | NULL, type, node, child, NULL, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8188 | "(annotation?, (restriction | list | union))"); |
| 8189 | } else if (IS_SCHEMA(child, "restriction")) { |
| 8190 | xmlSchemaParseRestriction(ctxt, schema, child, |
| 8191 | XML_SCHEMA_TYPE_SIMPLE); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8192 | child = child->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8193 | } else if (IS_SCHEMA(child, "list")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8194 | xmlSchemaParseList(ctxt, schema, child); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8195 | child = child->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8196 | } else if (IS_SCHEMA(child, "union")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8197 | xmlSchemaParseUnion(ctxt, schema, child); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8198 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8199 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8200 | if (child != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8201 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 8202 | NULL, type, node, child, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8203 | "(annotation?, (restriction | list | union))"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8204 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8205 | ctxt->parentItem = oldParentItem; |
| 8206 | ctxt->ctxtType = oldCtxtType; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8207 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8208 | return (type); |
| 8209 | } |
| 8210 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8211 | /** |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8212 | * xmlSchemaParseModelGroupDefRef: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8213 | * @ctxt: a schema validation context |
| 8214 | * @schema: the schema being built |
| 8215 | * @node: a subtree containing XML Schema informations |
| 8216 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8217 | * Parses a XML schema particle (reference to a model group definition). |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8218 | * *WARNING* this interface is highly subject to change |
| 8219 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 8220 | * Returns -1 in case of error, 0 if the declaration is improper and |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8221 | * 1 in case of success. |
| 8222 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8223 | static xmlSchemaTreeItemPtr |
| 8224 | xmlSchemaParseModelGroupDefRef(xmlSchemaParserCtxtPtr ctxt, |
| 8225 | xmlSchemaPtr schema, |
| 8226 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8227 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8228 | xmlSchemaParticlePtr item; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8229 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8230 | xmlAttrPtr attr; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8231 | const xmlChar *ref = NULL, *refNs = NULL; |
| 8232 | int min, max; |
| 8233 | |
| 8234 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8235 | return (NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8236 | |
| 8237 | attr = xmlSchemaGetPropNode(node, "ref"); |
| 8238 | if (attr == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8239 | xmlSchemaPMissingAttrErr(ctxt, |
| 8240 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 8241 | NULL, node, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8242 | "ref", NULL); |
| 8243 | return (NULL); |
| 8244 | } else if (xmlSchemaPValAttrNodeQName(ctxt, schema, NULL, NULL, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8245 | attr, &refNs, &ref) != 0) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8246 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8247 | } |
| 8248 | min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "xs:nonNegativeInteger"); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8249 | max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8250 | "(xs:nonNegativeInteger | unbounded)"); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8251 | /* |
| 8252 | * Check for illegal attributes. |
| 8253 | */ |
| 8254 | attr = node->properties; |
| 8255 | while (attr != NULL) { |
| 8256 | if (attr->ns == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8257 | if ((!xmlStrEqual(attr->name, BAD_CAST "ref")) && |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8258 | (!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 8259 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) && |
| 8260 | (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8261 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8262 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8263 | NULL, NULL, attr); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8264 | } |
| 8265 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8266 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8267 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8268 | NULL, NULL, attr); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8269 | } |
| 8270 | attr = attr->next; |
| 8271 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8272 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8273 | item = xmlSchemaAddParticle(ctxt, schema, node, min, max); |
| 8274 | if (item == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8275 | return (NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8276 | /* |
| 8277 | * Create a reference item as the term; it will be substituted for |
| 8278 | * the model group after the reference has been resolved. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8279 | */ |
| 8280 | item->children = (xmlSchemaTreeItemPtr) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8281 | xmlSchemaNewQNameRef(schema, XML_SCHEMA_TYPE_GROUP, ref, refNs); |
| 8282 | xmlSchemaCheckReference(ctxt, schema, node, (xmlSchemaBasicItemPtr) item, refNs); |
| 8283 | xmlSchemaPCheckParticleCorrect_2(ctxt, item, node, min, max); |
| 8284 | /* |
| 8285 | * And now for the children... |
| 8286 | */ |
| 8287 | child = node->children; |
| 8288 | /* TODO: Is annotation even allowed for a model group reference? */ |
| 8289 | if (IS_SCHEMA(child, "annotation")) { |
| 8290 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8291 | * TODO: What to do exactly with the annotation? |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8292 | */ |
| 8293 | item->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 8294 | child = child->next; |
| 8295 | } |
| 8296 | if (child != NULL) { |
| 8297 | xmlSchemaPContentErr(ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8298 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8299 | NULL, NULL, node, child, NULL, |
| 8300 | "(annotation?)"); |
| 8301 | } |
| 8302 | /* |
| 8303 | * Corresponds to no component at all if minOccurs==maxOccurs==0. |
| 8304 | */ |
| 8305 | if ((min == 0) && (max == 0)) |
| 8306 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8307 | if (ctxt->assemble != NULL) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8308 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) item); |
| 8309 | return ((xmlSchemaTreeItemPtr) item); |
| 8310 | } |
| 8311 | |
| 8312 | /** |
| 8313 | * xmlSchemaParseModelGroupDefinition: |
| 8314 | * @ctxt: a schema validation context |
| 8315 | * @schema: the schema being built |
| 8316 | * @node: a subtree containing XML Schema informations |
| 8317 | * |
| 8318 | * Parses a XML schema model group definition. |
| 8319 | * *WARNING* this interface is highly subject to change |
| 8320 | * |
| 8321 | * Returns -1 in case of error, 0 if the declaration is improper and |
| 8322 | * 1 in case of success. |
| 8323 | */ |
| 8324 | static xmlSchemaModelGroupDefPtr |
| 8325 | xmlSchemaParseModelGroupDefinition(xmlSchemaParserCtxtPtr ctxt, |
| 8326 | xmlSchemaPtr schema, |
| 8327 | xmlNodePtr node) |
| 8328 | { |
| 8329 | xmlSchemaModelGroupDefPtr item; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8330 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8331 | xmlAttrPtr attr; |
| 8332 | const xmlChar *name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8333 | |
| 8334 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8335 | return (NULL); |
| 8336 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8337 | attr = xmlSchemaGetPropNode(node, "name"); |
| 8338 | if (attr == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8339 | xmlSchemaPMissingAttrErr(ctxt, |
| 8340 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 8341 | NULL, node, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8342 | "name", NULL); |
| 8343 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8344 | } else if (xmlSchemaPValAttrNode(ctxt, |
| 8345 | NULL, NULL, attr, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8346 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 8347 | return (NULL); |
| 8348 | } |
| 8349 | item = xmlSchemaAddGroup(ctxt, schema, name, schema->targetNamespace, node); |
| 8350 | if (item == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8351 | return (NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8352 | /* |
| 8353 | * Check for illegal attributes. |
| 8354 | */ |
| 8355 | attr = node->properties; |
| 8356 | while (attr != NULL) { |
| 8357 | if (attr->ns == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8358 | if ((!xmlStrEqual(attr->name, BAD_CAST "name")) && |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8359 | (!xmlStrEqual(attr->name, BAD_CAST "id"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8360 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8361 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8362 | NULL, NULL, attr); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8363 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8364 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8365 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8366 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8367 | NULL, NULL, attr); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8368 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8369 | attr = attr->next; |
| 8370 | } |
| 8371 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
| 8372 | /* |
| 8373 | * And now for the children... |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8374 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8375 | child = node->children; |
| 8376 | if (IS_SCHEMA(child, "annotation")) { |
| 8377 | item->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 8378 | child = child->next; |
| 8379 | } |
| 8380 | if (IS_SCHEMA(child, "all")) { |
| 8381 | item->children = xmlSchemaParseModelGroup(ctxt, schema, child, |
| 8382 | XML_SCHEMA_TYPE_ALL, 0); |
| 8383 | child = child->next; |
| 8384 | } else if (IS_SCHEMA(child, "choice")) { |
| 8385 | item->children = xmlSchemaParseModelGroup(ctxt, schema, child, |
| 8386 | XML_SCHEMA_TYPE_CHOICE, 0); |
| 8387 | child = child->next; |
| 8388 | } else if (IS_SCHEMA(child, "sequence")) { |
| 8389 | item->children = xmlSchemaParseModelGroup(ctxt, schema, child, |
| 8390 | XML_SCHEMA_TYPE_SEQUENCE, 0); |
| 8391 | child = child->next; |
| 8392 | } |
| 8393 | if (child != NULL) { |
| 8394 | xmlSchemaPContentErr(ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8395 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 8396 | NULL, NULL, node, child, NULL, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8397 | "(annotation?, (all | choice | sequence)?)"); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8398 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8399 | |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8400 | return (item); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8401 | } |
| 8402 | |
| 8403 | /** |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8404 | * xmlSchemaCleanupDoc: |
| 8405 | * @ctxt: a schema validation context |
| 8406 | * @node: the root of the document. |
| 8407 | * |
| 8408 | * removes unwanted nodes in a schemas document tree |
| 8409 | */ |
| 8410 | static void |
| 8411 | xmlSchemaCleanupDoc(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr root) |
| 8412 | { |
| 8413 | xmlNodePtr delete, cur; |
| 8414 | |
| 8415 | if ((ctxt == NULL) || (root == NULL)) return; |
| 8416 | |
| 8417 | /* |
| 8418 | * Remove all the blank text nodes |
| 8419 | */ |
| 8420 | delete = NULL; |
| 8421 | cur = root; |
| 8422 | while (cur != NULL) { |
| 8423 | if (delete != NULL) { |
| 8424 | xmlUnlinkNode(delete); |
| 8425 | xmlFreeNode(delete); |
| 8426 | delete = NULL; |
| 8427 | } |
| 8428 | if (cur->type == XML_TEXT_NODE) { |
| 8429 | if (IS_BLANK_NODE(cur)) { |
| 8430 | if (xmlNodeGetSpacePreserve(cur) != 1) { |
| 8431 | delete = cur; |
| 8432 | } |
| 8433 | } |
| 8434 | } else if ((cur->type != XML_ELEMENT_NODE) && |
| 8435 | (cur->type != XML_CDATA_SECTION_NODE)) { |
| 8436 | delete = cur; |
| 8437 | goto skip_children; |
| 8438 | } |
| 8439 | |
| 8440 | /* |
| 8441 | * Skip to next node |
| 8442 | */ |
| 8443 | if (cur->children != NULL) { |
| 8444 | if ((cur->children->type != XML_ENTITY_DECL) && |
| 8445 | (cur->children->type != XML_ENTITY_REF_NODE) && |
| 8446 | (cur->children->type != XML_ENTITY_NODE)) { |
| 8447 | cur = cur->children; |
| 8448 | continue; |
| 8449 | } |
| 8450 | } |
| 8451 | skip_children: |
| 8452 | if (cur->next != NULL) { |
| 8453 | cur = cur->next; |
| 8454 | continue; |
| 8455 | } |
| 8456 | |
| 8457 | do { |
| 8458 | cur = cur->parent; |
| 8459 | if (cur == NULL) |
| 8460 | break; |
| 8461 | if (cur == root) { |
| 8462 | cur = NULL; |
| 8463 | break; |
| 8464 | } |
| 8465 | if (cur->next != NULL) { |
| 8466 | cur = cur->next; |
| 8467 | break; |
| 8468 | } |
| 8469 | } while (cur != NULL); |
| 8470 | } |
| 8471 | if (delete != NULL) { |
| 8472 | xmlUnlinkNode(delete); |
| 8473 | xmlFreeNode(delete); |
| 8474 | delete = NULL; |
| 8475 | } |
| 8476 | } |
| 8477 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8478 | |
| 8479 | /** |
| 8480 | * xmlSchemaImportSchema |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8481 | * |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8482 | * @ctxt: a schema validation context |
| 8483 | * @schemaLocation: an URI defining where to find the imported schema |
| 8484 | * |
| 8485 | * import a XML schema |
| 8486 | * *WARNING* this interface is highly subject to change |
| 8487 | * |
| 8488 | * Returns -1 in case of error and 1 in case of success. |
| 8489 | */ |
| 8490 | #if 0 |
| 8491 | static xmlSchemaImportPtr |
| 8492 | xmlSchemaImportSchema(xmlSchemaParserCtxtPtr ctxt, |
| 8493 | const xmlChar *schemaLocation) |
| 8494 | { |
| 8495 | xmlSchemaImportPtr import; |
| 8496 | xmlSchemaParserCtxtPtr newctxt; |
| 8497 | |
| 8498 | newctxt = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 8499 | if (newctxt == NULL) { |
| 8500 | xmlSchemaPErrMemory(ctxt, "allocating schema parser context", |
| 8501 | NULL); |
| 8502 | return (NULL); |
| 8503 | } |
| 8504 | memset(newctxt, 0, sizeof(xmlSchemaParserCtxt)); |
| 8505 | /* Keep the same dictionnary for parsing, really */ |
| 8506 | xmlDictReference(ctxt->dict); |
| 8507 | newctxt->dict = ctxt->dict; |
| 8508 | newctxt->includes = 0; |
| 8509 | newctxt->URL = xmlDictLookup(newctxt->dict, schemaLocation, -1); |
| 8510 | |
| 8511 | xmlSchemaSetParserErrors(newctxt, ctxt->error, ctxt->warning, |
| 8512 | ctxt->userData); |
| 8513 | |
| 8514 | import = (xmlSchemaImport*) xmlMalloc(sizeof(xmlSchemaImport)); |
| 8515 | if (import == NULL) { |
| 8516 | xmlSchemaPErrMemory(NULL, "allocating imported schema", |
| 8517 | NULL); |
| 8518 | xmlSchemaFreeParserCtxt(newctxt); |
| 8519 | return (NULL); |
| 8520 | } |
| 8521 | |
| 8522 | memset(import, 0, sizeof(xmlSchemaImport)); |
| 8523 | import->schemaLocation = xmlDictLookup(ctxt->dict, schemaLocation, -1); |
| 8524 | import->schema = xmlSchemaParse(newctxt); |
| 8525 | |
| 8526 | if (import->schema == NULL) { |
| 8527 | /* FIXME use another error enum here ? */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 8528 | xmlSchemaPErr(ctxt, NULL, XML_SCHEMAP_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8529 | "Failed to import schema from location \"%s\".\n", |
| 8530 | schemaLocation, NULL); |
| 8531 | |
| 8532 | xmlSchemaFreeParserCtxt(newctxt); |
| 8533 | /* The schemaLocation is held by the dictionary. |
| 8534 | if (import->schemaLocation != NULL) |
| 8535 | xmlFree((xmlChar *)import->schemaLocation); |
| 8536 | */ |
| 8537 | xmlFree(import); |
| 8538 | return NULL; |
| 8539 | } |
| 8540 | |
| 8541 | xmlSchemaFreeParserCtxt(newctxt); |
| 8542 | return import; |
| 8543 | } |
| 8544 | #endif |
| 8545 | |
| 8546 | static void |
| 8547 | xmlSchemaClearSchemaDefaults(xmlSchemaPtr schema) |
| 8548 | { |
| 8549 | if (schema->flags & XML_SCHEMAS_QUALIF_ELEM) |
| 8550 | schema->flags ^= XML_SCHEMAS_QUALIF_ELEM; |
| 8551 | |
| 8552 | if (schema->flags & XML_SCHEMAS_QUALIF_ATTR) |
| 8553 | schema->flags ^= XML_SCHEMAS_QUALIF_ATTR; |
| 8554 | |
| 8555 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION) |
| 8556 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_EXTENSION; |
| 8557 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION) |
| 8558 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION; |
| 8559 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_LIST) |
| 8560 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_LIST; |
| 8561 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_UNION) |
| 8562 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_UNION; |
| 8563 | |
| 8564 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION) |
| 8565 | schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION; |
| 8566 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION) |
| 8567 | schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION; |
| 8568 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION) |
| 8569 | schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION; |
| 8570 | } |
| 8571 | |
| 8572 | static void |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8573 | xmlSchemaParseSchemaDefaults(xmlSchemaParserCtxtPtr ctxt, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8574 | xmlSchemaPtr schema, |
| 8575 | xmlNodePtr node) |
| 8576 | { |
| 8577 | xmlAttrPtr attr; |
| 8578 | const xmlChar *val; |
| 8579 | |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8580 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
| 8581 | if (schema->version == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8582 | xmlSchemaPValAttr(ctxt, NULL, NULL, node, "version", |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8583 | xmlSchemaGetBuiltInType(XML_SCHEMAS_TOKEN), &(schema->version)); |
| 8584 | else |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8585 | xmlSchemaPValAttr(ctxt, NULL, NULL, node, "version", |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8586 | xmlSchemaGetBuiltInType(XML_SCHEMAS_TOKEN), NULL); |
| 8587 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8588 | attr = xmlSchemaGetPropNode(node, "elementFormDefault"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8589 | if (attr != NULL) { |
| 8590 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8591 | if (xmlSchemaPValAttrFormDefault(val, &schema->flags, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8592 | XML_SCHEMAS_QUALIF_ELEM) != 0) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8593 | xmlSchemaPSimpleTypeErr(ctxt, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8594 | XML_SCHEMAP_ELEMFORMDEFAULT_VALUE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8595 | NULL, (xmlNodePtr) attr, NULL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8596 | "(qualified | unqualified)", val, NULL, NULL, NULL); |
| 8597 | } |
| 8598 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8599 | |
| 8600 | attr = xmlSchemaGetPropNode(node, "attributeFormDefault"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8601 | if (attr != NULL) { |
| 8602 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8603 | if (xmlSchemaPValAttrFormDefault(val, &schema->flags, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8604 | XML_SCHEMAS_QUALIF_ATTR) != 0) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8605 | xmlSchemaPSimpleTypeErr(ctxt, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8606 | XML_SCHEMAP_ATTRFORMDEFAULT_VALUE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8607 | NULL, (xmlNodePtr) attr, NULL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8608 | "(qualified | unqualified)", val, NULL, NULL, NULL); |
| 8609 | } |
| 8610 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8611 | |
| 8612 | attr = xmlSchemaGetPropNode(node, "finalDefault"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8613 | if (attr != NULL) { |
| 8614 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 8615 | if (xmlSchemaPValAttrBlockFinal(val, &(schema->flags), -1, |
| 8616 | XML_SCHEMAS_FINAL_DEFAULT_EXTENSION, |
| 8617 | XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION, |
| 8618 | -1, |
| 8619 | XML_SCHEMAS_FINAL_DEFAULT_LIST, |
| 8620 | XML_SCHEMAS_FINAL_DEFAULT_UNION) != 0) { |
| 8621 | xmlSchemaPSimpleTypeErr(ctxt, |
| 8622 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8623 | NULL, (xmlNodePtr) attr, NULL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8624 | "(#all | List of (extension | restriction | list | union))", |
| 8625 | val, NULL, NULL, NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8626 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8627 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8628 | |
| 8629 | attr = xmlSchemaGetPropNode(node, "blockDefault"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8630 | if (attr != NULL) { |
| 8631 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 8632 | if (xmlSchemaPValAttrBlockFinal(val, &(schema->flags), -1, |
| 8633 | XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION, |
| 8634 | XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION, |
| 8635 | XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION, -1, -1) != 0) { |
| 8636 | xmlSchemaPSimpleTypeErr(ctxt, |
| 8637 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8638 | NULL, (xmlNodePtr) attr, NULL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8639 | "(#all | List of (extension | restriction | substitution))", |
| 8640 | val, NULL, NULL, NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8641 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8642 | } |
| 8643 | } |
| 8644 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8645 | /** |
| 8646 | * xmlSchemaParseSchemaTopLevel: |
| 8647 | * @ctxt: a schema validation context |
| 8648 | * @schema: the schemas |
| 8649 | * @nodes: the list of top level nodes |
| 8650 | * |
| 8651 | * Returns the internal XML Schema structure built from the resource or |
| 8652 | * NULL in case of error |
| 8653 | */ |
| 8654 | static void |
| 8655 | xmlSchemaParseSchemaTopLevel(xmlSchemaParserCtxtPtr ctxt, |
| 8656 | xmlSchemaPtr schema, xmlNodePtr nodes) |
| 8657 | { |
| 8658 | xmlNodePtr child; |
| 8659 | xmlSchemaAnnotPtr annot; |
| 8660 | |
| 8661 | if ((ctxt == NULL) || (schema == NULL) || (nodes == NULL)) |
| 8662 | return; |
| 8663 | |
| 8664 | child = nodes; |
| 8665 | while ((IS_SCHEMA(child, "include")) || |
| 8666 | (IS_SCHEMA(child, "import")) || |
| 8667 | (IS_SCHEMA(child, "redefine")) || |
| 8668 | (IS_SCHEMA(child, "annotation"))) { |
| 8669 | if (IS_SCHEMA(child, "annotation")) { |
| 8670 | annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 8671 | if (schema->annot == NULL) |
| 8672 | schema->annot = annot; |
| 8673 | else |
| 8674 | xmlSchemaFreeAnnot(annot); |
| 8675 | } else if (IS_SCHEMA(child, "import")) { |
| 8676 | xmlSchemaParseImport(ctxt, schema, child); |
| 8677 | } else if (IS_SCHEMA(child, "include")) { |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 8678 | ctxt->includes++; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8679 | xmlSchemaParseInclude(ctxt, schema, child); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 8680 | ctxt->includes--; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8681 | } else if (IS_SCHEMA(child, "redefine")) { |
| 8682 | TODO |
| 8683 | } |
| 8684 | child = child->next; |
| 8685 | } |
| 8686 | while (child != NULL) { |
| 8687 | if (IS_SCHEMA(child, "complexType")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 8688 | xmlSchemaParseComplexType(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8689 | child = child->next; |
| 8690 | } else if (IS_SCHEMA(child, "simpleType")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 8691 | xmlSchemaParseSimpleType(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8692 | child = child->next; |
| 8693 | } else if (IS_SCHEMA(child, "element")) { |
| 8694 | xmlSchemaParseElement(ctxt, schema, child, 1); |
| 8695 | child = child->next; |
| 8696 | } else if (IS_SCHEMA(child, "attribute")) { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 8697 | xmlSchemaParseAttribute(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8698 | child = child->next; |
| 8699 | } else if (IS_SCHEMA(child, "attributeGroup")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 8700 | xmlSchemaParseAttributeGroup(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8701 | child = child->next; |
| 8702 | } else if (IS_SCHEMA(child, "group")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 8703 | xmlSchemaParseModelGroupDefinition(ctxt, schema, child); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8704 | child = child->next; |
| 8705 | } else if (IS_SCHEMA(child, "notation")) { |
| 8706 | xmlSchemaParseNotation(ctxt, schema, child); |
| 8707 | child = child->next; |
| 8708 | } else { |
| 8709 | xmlSchemaPErr2(ctxt, NULL, child, |
| 8710 | XML_SCHEMAP_UNKNOWN_SCHEMAS_CHILD, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8711 | "Unexpected element \"%s\" as child of <schema>.\n", |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8712 | child->name, NULL); |
| 8713 | child = child->next; |
| 8714 | } |
| 8715 | while (IS_SCHEMA(child, "annotation")) { |
| 8716 | annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 8717 | if (schema->annot == NULL) |
| 8718 | schema->annot = annot; |
| 8719 | else |
| 8720 | xmlSchemaFreeAnnot(annot); |
| 8721 | child = child->next; |
| 8722 | } |
| 8723 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8724 | ctxt->parentItem = NULL; |
| 8725 | ctxt->ctxtType = NULL; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8726 | } |
| 8727 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8728 | static xmlSchemaImportPtr |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8729 | xmlSchemaAddImport(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8730 | xmlHashTablePtr *imports, |
| 8731 | const xmlChar *nsName) |
| 8732 | { |
| 8733 | xmlSchemaImportPtr ret; |
| 8734 | |
| 8735 | if (*imports == NULL) { |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 8736 | *imports = xmlHashCreateDict(10, ctxt->dict); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8737 | if (*imports == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8738 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8739 | XML_SCHEMAP_FAILED_BUILD_IMPORT, |
| 8740 | NULL, NULL, (xmlNodePtr) ctxt->doc, |
| 8741 | "Internal error: failed to build the import table", |
| 8742 | NULL); |
| 8743 | return (NULL); |
| 8744 | } |
| 8745 | } |
| 8746 | ret = (xmlSchemaImport*) xmlMalloc(sizeof(xmlSchemaImport)); |
| 8747 | if (ret == NULL) { |
| 8748 | xmlSchemaPErrMemory(NULL, "allocating import struct", NULL); |
| 8749 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8750 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8751 | memset(ret, 0, sizeof(xmlSchemaImport)); |
| 8752 | if (nsName == NULL) |
| 8753 | nsName = XML_SCHEMAS_NO_NAMESPACE; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8754 | xmlHashAddEntry(*imports, nsName, ret); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8755 | |
| 8756 | return (ret); |
| 8757 | } |
| 8758 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8759 | /** |
| 8760 | * xmlSchemaNewParserCtxtUseDict: |
| 8761 | * @URL: the location of the schema |
| 8762 | * @dict: the dictionary to be used |
| 8763 | * |
| 8764 | * Create an XML Schemas parse context for that file/resource expected |
| 8765 | * to contain an XML Schemas file. |
| 8766 | * |
| 8767 | * Returns the parser context or NULL in case of error |
| 8768 | */ |
| 8769 | static xmlSchemaParserCtxtPtr |
| 8770 | xmlSchemaNewParserCtxtUseDict(const char *URL, xmlDictPtr dict) |
| 8771 | { |
| 8772 | xmlSchemaParserCtxtPtr ret; |
| 8773 | /* |
| 8774 | if (URL == NULL) |
| 8775 | return (NULL); |
| 8776 | */ |
| 8777 | |
| 8778 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 8779 | if (ret == NULL) { |
| 8780 | xmlSchemaPErrMemory(NULL, "allocating schema parser context", |
| 8781 | NULL); |
| 8782 | return (NULL); |
| 8783 | } |
| 8784 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
| 8785 | ret->dict = dict; |
| 8786 | xmlDictReference(dict); |
| 8787 | if (URL != NULL) |
| 8788 | ret->URL = xmlDictLookup(dict, (const xmlChar *) URL, -1); |
| 8789 | ret->includes = 0; |
| 8790 | return (ret); |
| 8791 | } |
| 8792 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8793 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8794 | xmlSchemaCreatePCtxtOnVCtxt(xmlSchemaValidCtxtPtr vctxt) |
| 8795 | { |
| 8796 | if (vctxt->pctxt == NULL) { |
| 8797 | if (vctxt->schema != NULL) |
| 8798 | vctxt->pctxt = xmlSchemaNewParserCtxtUseDict("*", vctxt->schema->dict); |
| 8799 | else |
| 8800 | vctxt->pctxt = xmlSchemaNewParserCtxt("*"); |
| 8801 | if (vctxt->pctxt == NULL) { |
| 8802 | VERROR_INT("xmlSchemaCreatePCtxtOnVCtxt", |
| 8803 | "failed to create a temp. parser context"); |
| 8804 | return (-1); |
| 8805 | } |
| 8806 | /* TODO: Pass user data. */ |
| 8807 | xmlSchemaSetParserErrors(vctxt->pctxt, vctxt->error, vctxt->warning, NULL); |
| 8808 | } |
| 8809 | return (0); |
| 8810 | } |
| 8811 | |
| 8812 | static int |
| 8813 | xmlSchemaAcquireSchemaDoc(xmlSchemaAbstractCtxtPtr actxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8814 | xmlSchemaPtr schema, |
| 8815 | xmlNodePtr node, |
| 8816 | const xmlChar *nsName, |
| 8817 | const xmlChar *location, |
| 8818 | xmlDocPtr *doc, |
| 8819 | const xmlChar **targetNamespace, |
| 8820 | int absolute) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8821 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8822 | xmlSchemaParserCtxtPtr pctxt; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8823 | xmlParserCtxtPtr parserCtxt; |
| 8824 | xmlSchemaImportPtr import; |
| 8825 | const xmlChar *ns; |
| 8826 | xmlNodePtr root; |
| 8827 | |
| 8828 | /* |
| 8829 | * NOTE: This will be used for <import>, <xsi:schemaLocation> and |
| 8830 | * <xsi:noNamespaceSchemaLocation>. |
| 8831 | */ |
| 8832 | *doc = NULL; |
| 8833 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8834 | * Given that the schemaLocation [attribute] is only a hint, it is open |
| 8835 | * to applications to ignore all but the first <import> for a given |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8836 | * namespace, regardless of the ·actual value· of schemaLocation, but |
| 8837 | * such a strategy risks missing useful information when new |
| 8838 | * schemaLocations are offered. |
| 8839 | * |
| 8840 | * XSV (ver 2.5-2) does use the first <import> which resolves to a valid schema. |
| 8841 | * Xerces-J (ver 2.5.1) ignores all but the first given <import> - regardless if |
| 8842 | * valid or not. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8843 | * We will follow XSV here. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8844 | */ |
| 8845 | if (location == NULL) { |
| 8846 | /* |
| 8847 | * Schema Document Location Strategy: |
| 8848 | * |
| 8849 | * 3 Based on the namespace name, identify an existing schema document, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8850 | * either as a resource which is an XML document or a <schema> element |
| 8851 | * information item, in some local schema repository; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8852 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8853 | * 5 Attempt to resolve the namespace name to locate such a resource. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8854 | * |
| 8855 | * NOTE: Those stategies are not supported, so we will skip. |
| 8856 | */ |
| 8857 | return (0); |
| 8858 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8859 | if (nsName == NULL) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8860 | ns = XML_SCHEMAS_NO_NAMESPACE; |
| 8861 | else |
| 8862 | ns = nsName; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8863 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8864 | import = xmlHashLookup(schema->schemasImports, ns); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8865 | if (import != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8866 | /* |
| 8867 | * There was a valid resource for the specified namespace already |
| 8868 | * defined, so skip. |
| 8869 | * TODO: This might be changed someday to allow import of |
| 8870 | * components from multiple documents for a single target namespace. |
| 8871 | */ |
| 8872 | return (0); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8873 | } |
| 8874 | if (actxt->type == XML_SCHEMA_CTXT_PARSER) |
| 8875 | pctxt = (xmlSchemaParserCtxtPtr) actxt; |
| 8876 | else { |
| 8877 | xmlSchemaCreatePCtxtOnVCtxt((xmlSchemaValidCtxtPtr) actxt); |
| 8878 | pctxt = ((xmlSchemaValidCtxtPtr) actxt)->pctxt; |
| 8879 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8880 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8881 | * Schema Document Location Strategy: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8882 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8883 | * 2 Based on the location URI, identify an existing schema document, |
| 8884 | * either as a resource which is an XML document or a <schema> element |
| 8885 | * information item, in some local schema repository; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8886 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8887 | * 4 Attempt to resolve the location URI, to locate a resource on the |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8888 | * web which is or contains or references a <schema> element; |
| 8889 | * TODO: Hmm, I don't know if the reference stuff in 4. will work. |
| 8890 | * |
| 8891 | */ |
| 8892 | if ((absolute == 0) && (node != NULL)) { |
| 8893 | xmlChar *base, *URI; |
| 8894 | |
| 8895 | base = xmlNodeGetBase(node->doc, node); |
| 8896 | if (base == NULL) { |
| 8897 | URI = xmlBuildURI(location, node->doc->URL); |
| 8898 | } else { |
| 8899 | URI = xmlBuildURI(location, base); |
| 8900 | xmlFree(base); |
| 8901 | } |
| 8902 | if (URI != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8903 | location = xmlDictLookup(pctxt->dict, URI, -1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8904 | xmlFree(URI); |
| 8905 | } |
| 8906 | } |
| 8907 | parserCtxt = xmlNewParserCtxt(); |
| 8908 | if (parserCtxt == NULL) { |
| 8909 | xmlSchemaPErrMemory(NULL, "xmlSchemaParseImport: " |
| 8910 | "allocating a parser context", NULL); |
| 8911 | return(-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8912 | } |
| 8913 | if ((pctxt->dict != NULL) && (parserCtxt->dict != NULL)) { |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 8914 | xmlDictFree(parserCtxt->dict); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8915 | parserCtxt->dict = pctxt->dict; |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 8916 | xmlDictReference(parserCtxt->dict); |
| 8917 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8918 | *doc = xmlCtxtReadFile(parserCtxt, (const char *) location, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8919 | NULL, SCHEMAS_PARSE_OPTIONS); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8920 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8921 | * 2.1 The referent is (a fragment of) a resource which is an |
| 8922 | * XML document (see clause 1.1), which in turn corresponds to |
| 8923 | * a <schema> element information item in a well-formed information |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8924 | * set, which in turn corresponds to a valid schema. |
| 8925 | * TODO: What to do with the "fragment" stuff? |
| 8926 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8927 | * 2.2 The referent is a <schema> element information item in |
| 8928 | * a well-formed information set, which in turn corresponds |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8929 | * to a valid schema. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8930 | * NOTE: 2.2 won't apply, since only XML documents will be processed |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8931 | * here. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8932 | */ |
| 8933 | if (*doc == NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8934 | xmlErrorPtr lerr; |
| 8935 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8936 | * It is *not* an error for the application schema reference |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8937 | * strategy to fail. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8938 | * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8939 | * If the doc is NULL and the parser error is an IO error we |
| 8940 | * will assume that the resource could not be located or accessed. |
| 8941 | * |
| 8942 | * TODO: Try to find specific error codes to react only on |
| 8943 | * localisation failures. |
| 8944 | * |
| 8945 | * TODO, FIXME: Check the spec: is a namespace added to the imported |
| 8946 | * namespaces, even if the schemaLocation did not provide |
| 8947 | * a resource? I guess so, since omitting the "schemaLocation" |
| 8948 | * attribute, imports a namespace as well. |
| 8949 | */ |
| 8950 | lerr = xmlGetLastError(); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8951 | if ((lerr != NULL) && (lerr->domain == XML_FROM_IO)) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8952 | xmlFreeParserCtxt(parserCtxt); |
| 8953 | return(0); |
| 8954 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8955 | xmlSchemaCustomErr(actxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8956 | XML_SCHEMAP_SRC_IMPORT_2_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8957 | node, NULL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8958 | "Failed to parse the resource '%s' for import", |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8959 | location, NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8960 | xmlFreeParserCtxt(parserCtxt); |
| 8961 | return(XML_SCHEMAP_SRC_IMPORT_2_1); |
| 8962 | } |
| 8963 | xmlFreeParserCtxt(parserCtxt); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8964 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8965 | root = xmlDocGetRootElement(*doc); |
| 8966 | if (root == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8967 | xmlSchemaCustomErr(actxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8968 | XML_SCHEMAP_SRC_IMPORT_2_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8969 | node, NULL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8970 | "The XML document '%s' to be imported has no document " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8971 | "element", location, NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8972 | xmlFreeDoc(*doc); |
| 8973 | *doc = NULL; |
| 8974 | return (XML_SCHEMAP_SRC_IMPORT_2_1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8975 | } |
| 8976 | |
| 8977 | xmlSchemaCleanupDoc(pctxt, root); |
| 8978 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8979 | if (!IS_SCHEMA(root, "schema")) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8980 | xmlSchemaCustomErr(actxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8981 | XML_SCHEMAP_SRC_IMPORT_2_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8982 | node, NULL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8983 | "The XML document '%s' to be imported is not a XML schema document", |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8984 | location, NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8985 | xmlFreeDoc(*doc); |
| 8986 | *doc = NULL; |
| 8987 | return (XML_SCHEMAP_SRC_IMPORT_2_1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8988 | } |
| 8989 | *targetNamespace = xmlSchemaGetProp(pctxt, root, "targetNamespace"); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8990 | /* |
| 8991 | * Schema Representation Constraint: Import Constraints and Semantics |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8992 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8993 | if (nsName == NULL) { |
| 8994 | if (*targetNamespace != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8995 | xmlSchemaCustomErr(actxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8996 | XML_SCHEMAP_SRC_IMPORT_3_2, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 8997 | node, NULL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8998 | "The XML schema to be imported is not expected " |
| 8999 | "to have a target namespace; this differs from " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9000 | "its target namespace of '%s'", *targetNamespace, NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9001 | xmlFreeDoc(*doc); |
| 9002 | *doc = NULL; |
| 9003 | return (XML_SCHEMAP_SRC_IMPORT_3_2); |
| 9004 | } |
| 9005 | } else { |
| 9006 | if (*targetNamespace == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9007 | xmlSchemaCustomErr(actxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9008 | XML_SCHEMAP_SRC_IMPORT_3_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9009 | node, NULL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9010 | "The XML schema to be imported is expected to have a target " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9011 | "namespace of '%s'", nsName, NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9012 | xmlFreeDoc(*doc); |
| 9013 | *doc = NULL; |
| 9014 | return (XML_SCHEMAP_SRC_IMPORT_3_1); |
| 9015 | } else if (!xmlStrEqual(*targetNamespace, nsName)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9016 | xmlSchemaCustomErr(actxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9017 | XML_SCHEMAP_SRC_IMPORT_3_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9018 | node, NULL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9019 | "The XML schema to be imported is expected to have a " |
| 9020 | "target namespace of '%s'; this differs from " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9021 | "its target namespace of '%s'", |
| 9022 | nsName, *targetNamespace); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9023 | xmlFreeDoc(*doc); |
| 9024 | *doc = NULL; |
| 9025 | return (XML_SCHEMAP_SRC_IMPORT_3_1); |
| 9026 | } |
| 9027 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9028 | import = xmlSchemaAddImport(pctxt, &(schema->schemasImports), nsName); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9029 | if (import == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9030 | AERROR_INT("xmlSchemaAcquireSchemaDoc", |
| 9031 | "failed to build import table"); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9032 | xmlFreeDoc(*doc); |
| 9033 | *doc = NULL; |
| 9034 | return (-1); |
| 9035 | } |
| 9036 | import->schemaLocation = location; |
| 9037 | import->doc = *doc; |
| 9038 | return (0); |
| 9039 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9040 | |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9041 | static void |
| 9042 | xmlSchemaParseForImpInc(xmlSchemaParserCtxtPtr pctxt, |
| 9043 | xmlSchemaPtr schema, |
| 9044 | const xmlChar *targetNamespace, |
| 9045 | xmlNodePtr node) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9046 | { |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9047 | const xmlChar *oldURL, **oldLocImps, *oldTNS; |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 9048 | int oldFlags, oldNumLocImps, oldSizeLocImps, oldIsS4S; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9049 | |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9050 | /* |
| 9051 | * Save and reset the context & schema. |
| 9052 | */ |
| 9053 | oldURL = pctxt->URL; |
| 9054 | /* TODO: Is using the doc->URL here correct? */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9055 | pctxt->URL = node->doc->URL; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9056 | oldLocImps = pctxt->localImports; |
| 9057 | pctxt->localImports = NULL; |
| 9058 | oldNumLocImps = pctxt->nbLocalImports; |
| 9059 | pctxt->nbLocalImports = 0; |
| 9060 | oldSizeLocImps = pctxt->sizeLocalImports; |
| 9061 | pctxt->sizeLocalImports = 0; |
| 9062 | oldFlags = schema->flags; |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 9063 | oldIsS4S = pctxt->isS4S; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9064 | xmlSchemaClearSchemaDefaults(schema); |
| 9065 | oldTNS = schema->targetNamespace; |
| 9066 | schema->targetNamespace = targetNamespace; |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 9067 | if ((targetNamespace != NULL) && |
| 9068 | xmlStrEqual(targetNamespace, xmlSchemaNs)) { |
| 9069 | /* |
| 9070 | * We are parsing the schema for schema! |
| 9071 | */ |
| 9072 | pctxt->isS4S = 1; |
| 9073 | } |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9074 | /* |
| 9075 | * Parse the schema. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9076 | */ |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9077 | xmlSchemaParseSchemaDefaults(pctxt, schema, node); |
| 9078 | xmlSchemaParseSchemaTopLevel(pctxt, schema, node->children); |
| 9079 | /* |
| 9080 | * Restore the context & schema. |
| 9081 | */ |
| 9082 | schema->flags = oldFlags; |
| 9083 | schema->targetNamespace = oldTNS; |
| 9084 | if (pctxt->localImports != NULL) |
| 9085 | xmlFree((xmlChar *) pctxt->localImports); |
| 9086 | pctxt->localImports = oldLocImps; |
| 9087 | pctxt->nbLocalImports = oldNumLocImps; |
| 9088 | pctxt->sizeLocalImports = oldSizeLocImps; |
| 9089 | pctxt->URL = oldURL; |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 9090 | pctxt->isS4S = oldIsS4S; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9091 | } |
| 9092 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9093 | /** |
| 9094 | * xmlSchemaParseImport: |
| 9095 | * @ctxt: a schema validation context |
| 9096 | * @schema: the schema being built |
| 9097 | * @node: a subtree containing XML Schema informations |
| 9098 | * |
| 9099 | * parse a XML schema Import definition |
| 9100 | * *WARNING* this interface is highly subject to change |
| 9101 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9102 | * Returns 0 in case of success, a positive error code if |
| 9103 | * not valid and -1 in case of an internal error. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9104 | */ |
| 9105 | static int |
| 9106 | xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 9107 | xmlNodePtr node) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9108 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9109 | xmlNodePtr child; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9110 | const xmlChar *namespaceName = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9111 | const xmlChar *schemaLocation = NULL; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9112 | const xmlChar *targetNamespace; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9113 | xmlAttrPtr attr; |
| 9114 | xmlDocPtr doc; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9115 | int ret = 0; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9116 | |
| 9117 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 9118 | return (-1); |
| 9119 | |
| 9120 | /* |
| 9121 | * Check for illegal attributes. |
| 9122 | */ |
| 9123 | attr = node->properties; |
| 9124 | while (attr != NULL) { |
| 9125 | if (attr->ns == NULL) { |
| 9126 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 9127 | (!xmlStrEqual(attr->name, BAD_CAST "namespace")) && |
| 9128 | (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9129 | xmlSchemaPIllegalAttrErr(ctxt, |
| 9130 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 9131 | NULL, NULL, attr); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9132 | } |
| 9133 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9134 | xmlSchemaPIllegalAttrErr(ctxt, |
| 9135 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 9136 | NULL, NULL, attr); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9137 | } |
| 9138 | attr = attr->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9139 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9140 | /* |
| 9141 | * Extract and validate attributes. |
| 9142 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9143 | if (xmlSchemaPValAttr(ctxt, NULL, NULL, node, |
| 9144 | "namespace", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9145 | &namespaceName) != 0) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9146 | xmlSchemaPSimpleTypeErr(ctxt, |
| 9147 | XML_SCHEMAP_IMPORT_NAMESPACE_NOT_URI, |
| 9148 | NULL, node, |
| 9149 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9150 | NULL, namespaceName, NULL, NULL, NULL); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9151 | return (XML_SCHEMAP_IMPORT_NAMESPACE_NOT_URI); |
| 9152 | } |
| 9153 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9154 | if (xmlSchemaPValAttr(ctxt, NULL, NULL, node, |
| 9155 | "schemaLocation", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9156 | &schemaLocation) != 0) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9157 | xmlSchemaPSimpleTypeErr(ctxt, |
| 9158 | XML_SCHEMAP_IMPORT_SCHEMA_NOT_URI, |
| 9159 | NULL, node, |
| 9160 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9161 | NULL, namespaceName, NULL, NULL, NULL); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9162 | return (XML_SCHEMAP_IMPORT_SCHEMA_NOT_URI); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9163 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9164 | /* |
| 9165 | * And now for the children... |
| 9166 | */ |
| 9167 | child = node->children; |
| 9168 | if (IS_SCHEMA(child, "annotation")) { |
| 9169 | /* |
| 9170 | * the annotation here is simply discarded ... |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9171 | * TODO: really? |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9172 | */ |
| 9173 | child = child->next; |
| 9174 | } |
| 9175 | if (child != NULL) { |
| 9176 | xmlSchemaPContentErr(ctxt, |
| 9177 | XML_SCHEMAP_UNKNOWN_IMPORT_CHILD, |
| 9178 | NULL, NULL, node, child, NULL, |
| 9179 | "(annotation?)"); |
| 9180 | } |
| 9181 | /* |
| 9182 | * Apply additional constraints. |
| 9183 | */ |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9184 | if (namespaceName != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9185 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9186 | * 1.1 If the namespace [attribute] is present, then its ·actual value· |
| 9187 | * must not match the ·actual value· of the enclosing <schema>'s |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9188 | * targetNamespace [attribute]. |
| 9189 | */ |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9190 | if (xmlStrEqual(schema->targetNamespace, namespaceName)) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9191 | xmlSchemaPCustomErr(ctxt, |
| 9192 | XML_SCHEMAP_SRC_IMPORT_1_1, |
| 9193 | NULL, NULL, node, |
| 9194 | "The value of the attribute 'namespace' must not match " |
| 9195 | "the target namespace '%s' of the importing schema", |
| 9196 | schema->targetNamespace); |
| 9197 | return (XML_SCHEMAP_SRC_IMPORT_1_1); |
| 9198 | } |
| 9199 | } else { |
| 9200 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9201 | * 1.2 If the namespace [attribute] is not present, then the enclosing |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9202 | * <schema> must have a targetNamespace [attribute]. |
| 9203 | */ |
| 9204 | if (schema->targetNamespace == NULL) { |
| 9205 | xmlSchemaPCustomErr(ctxt, |
| 9206 | XML_SCHEMAP_SRC_IMPORT_1_2, |
| 9207 | NULL, NULL, node, |
| 9208 | "The attribute 'namespace' must be existent if " |
| 9209 | "the importing schema has no target namespace", |
| 9210 | NULL); |
| 9211 | return (XML_SCHEMAP_SRC_IMPORT_1_2); |
| 9212 | } |
| 9213 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9214 | /* |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9215 | * Add the namespace to the list of locally imported namespace. |
| 9216 | */ |
| 9217 | if (ctxt->localImports == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9218 | ctxt->localImports = (const xmlChar **) xmlMalloc(10 * |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9219 | sizeof(const xmlChar*)); |
| 9220 | ctxt->sizeLocalImports = 10; |
| 9221 | ctxt->nbLocalImports = 0; |
| 9222 | } else if (ctxt->sizeLocalImports <= ctxt->nbLocalImports) { |
| 9223 | ctxt->sizeLocalImports *= 2; |
| 9224 | ctxt->localImports = (const xmlChar **) xmlRealloc( |
| 9225 | (xmlChar **) ctxt->localImports, |
| 9226 | ctxt->sizeLocalImports * sizeof(const xmlChar*)); |
| 9227 | } |
| 9228 | ctxt->localImports[ctxt->nbLocalImports++] = namespaceName; |
| 9229 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9230 | * Locate and aquire the schema document. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9231 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9232 | ret = xmlSchemaAcquireSchemaDoc((xmlSchemaAbstractCtxtPtr) ctxt, |
| 9233 | schema, node, namespaceName, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9234 | schemaLocation, &doc, &targetNamespace, 0); |
| 9235 | if (ret != 0) { |
| 9236 | if (doc != NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9237 | xmlFreeDoc(doc); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9238 | return (ret); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9239 | } else if (doc != NULL) { |
| 9240 | xmlSchemaParseForImpInc(ctxt, schema, targetNamespace, |
| 9241 | xmlDocGetRootElement(doc)); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9242 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9243 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9244 | return (0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9245 | } |
| 9246 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9247 | /** |
| 9248 | * xmlSchemaParseInclude: |
| 9249 | * @ctxt: a schema validation context |
| 9250 | * @schema: the schema being built |
| 9251 | * @node: a subtree containing XML Schema informations |
| 9252 | * |
| 9253 | * parse a XML schema Include definition |
| 9254 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 9255 | * Returns -1 in case of error, 0 if the declaration is improper and |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9256 | * 1 in case of success. |
| 9257 | */ |
| 9258 | static int |
| 9259 | xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 9260 | xmlNodePtr node) |
| 9261 | { |
| 9262 | xmlNodePtr child = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9263 | const xmlChar *schemaLocation, *targetNamespace; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9264 | xmlDocPtr doc = NULL; |
| 9265 | xmlNodePtr root = NULL; |
Daniel Veillard | cffc1c7 | 2005-03-12 18:54:55 +0000 | [diff] [blame] | 9266 | xmlSchemaIncludePtr include = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9267 | int wasConvertingNs = 0; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9268 | xmlAttrPtr attr; |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 9269 | xmlParserCtxtPtr parserCtxt; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9270 | |
| 9271 | |
| 9272 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 9273 | return (-1); |
| 9274 | |
| 9275 | /* |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9276 | * Check for illegal attributes. |
| 9277 | */ |
| 9278 | attr = node->properties; |
| 9279 | while (attr != NULL) { |
| 9280 | if (attr->ns == NULL) { |
| 9281 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 9282 | (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9283 | xmlSchemaPIllegalAttrErr(ctxt, |
| 9284 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 9285 | NULL, NULL, attr); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9286 | } |
| 9287 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9288 | xmlSchemaPIllegalAttrErr(ctxt, |
| 9289 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 9290 | NULL, NULL, attr); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9291 | } |
| 9292 | attr = attr->next; |
| 9293 | } |
| 9294 | /* |
| 9295 | * Extract and validate attributes. |
| 9296 | */ |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9297 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9298 | /* |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9299 | * Preliminary step, extract the URI-Reference for the include and |
| 9300 | * make an URI from the base. |
| 9301 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9302 | attr = xmlSchemaGetPropNode(node, "schemaLocation"); |
| 9303 | if (attr != NULL) { |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9304 | xmlChar *base = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9305 | xmlChar *uri = NULL; |
| 9306 | |
| 9307 | if (xmlSchemaPValAttrNode(ctxt, NULL, NULL, attr, |
| 9308 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), &schemaLocation) != 0) |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9309 | goto exit_invalid; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9310 | base = xmlNodeGetBase(node->doc, node); |
| 9311 | if (base == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9312 | uri = xmlBuildURI(schemaLocation, node->doc->URL); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9313 | } else { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9314 | uri = xmlBuildURI(schemaLocation, base); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9315 | xmlFree(base); |
| 9316 | } |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9317 | if (uri == NULL) { |
| 9318 | xmlSchemaPErr(ctxt, |
| 9319 | node, |
| 9320 | XML_SCHEMAP_INTERNAL, |
| 9321 | "Internal error: xmlSchemaParseInclude, " |
| 9322 | "could not build an URI from the schemaLocation.\n", |
| 9323 | NULL, NULL); |
| 9324 | goto exit_failure; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9325 | } |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9326 | schemaLocation = xmlDictLookup(ctxt->dict, uri, -1); |
| 9327 | xmlFree(uri); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9328 | } else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9329 | xmlSchemaPMissingAttrErr(ctxt, |
| 9330 | XML_SCHEMAP_INCLUDE_SCHEMA_NO_URI, |
| 9331 | NULL, node, "schemaLocation", NULL); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9332 | goto exit_invalid; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9333 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9334 | /* |
| 9335 | * And now for the children... |
| 9336 | */ |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9337 | child = node->children; |
| 9338 | while (IS_SCHEMA(child, "annotation")) { |
| 9339 | /* |
| 9340 | * the annotations here are simply discarded ... |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9341 | * TODO: really? |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9342 | */ |
| 9343 | child = child->next; |
| 9344 | } |
| 9345 | if (child != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9346 | xmlSchemaPContentErr(ctxt, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9347 | XML_SCHEMAP_UNKNOWN_INCLUDE_CHILD, |
| 9348 | NULL, NULL, node, child, NULL, |
| 9349 | "(annotation?)"); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9350 | } |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9351 | /* |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9352 | * Report self-inclusion. |
| 9353 | */ |
| 9354 | if (xmlStrEqual(schemaLocation, ctxt->URL)) { |
| 9355 | xmlSchemaPCustomErr(ctxt, |
| 9356 | XML_SCHEMAP_SRC_INCLUDE, |
| 9357 | NULL, NULL, node, |
| 9358 | "The schema document '%s' cannot include itself.", |
| 9359 | schemaLocation); |
| 9360 | return (XML_SCHEMAP_SRC_INCLUDE); |
| 9361 | } |
| 9362 | /* |
| 9363 | * Check if this one was already processed to avoid incorrect |
| 9364 | * duplicate component errors and infinite circular inclusion. |
| 9365 | */ |
| 9366 | include = schema->includes; |
| 9367 | while (include != NULL) { |
| 9368 | if (xmlStrEqual(include->schemaLocation, schemaLocation)) { |
| 9369 | targetNamespace = include->origTargetNamespace; |
| 9370 | if (targetNamespace == NULL) { |
| 9371 | /* |
| 9372 | * Chameleon include: skip only if it was build for |
| 9373 | * the targetNamespace of the including schema. |
| 9374 | */ |
| 9375 | if (xmlStrEqual(schema->targetNamespace, |
| 9376 | include->targetNamespace)) { |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9377 | goto check_targetNamespace; |
| 9378 | } |
| 9379 | } else { |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9380 | goto check_targetNamespace; |
| 9381 | } |
| 9382 | } |
| 9383 | include = include->next; |
| 9384 | } |
| 9385 | /* |
| 9386 | * First step is to parse the input document into an DOM/Infoset |
| 9387 | * TODO: Use xmlCtxtReadFile to share the dictionary? |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 9388 | */ |
| 9389 | parserCtxt = xmlNewParserCtxt(); |
| 9390 | if (parserCtxt == NULL) { |
| 9391 | xmlSchemaPErrMemory(NULL, "xmlSchemaParseInclude: " |
| 9392 | "allocating a parser context", NULL); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9393 | goto exit_failure; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9394 | } |
| 9395 | |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 9396 | if ((ctxt->dict != NULL) && (parserCtxt->dict != NULL)) { |
| 9397 | xmlDictFree(parserCtxt->dict); |
| 9398 | parserCtxt->dict = ctxt->dict; |
| 9399 | xmlDictReference(parserCtxt->dict); |
| 9400 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9401 | |
| 9402 | doc = xmlCtxtReadFile(parserCtxt, (const char *) schemaLocation, |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 9403 | NULL, SCHEMAS_PARSE_OPTIONS); |
| 9404 | xmlFreeParserCtxt(parserCtxt); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9405 | if (doc == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9406 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9407 | * TODO: It is not an error for the ·actual value· of the |
| 9408 | * schemaLocation [attribute] to fail to resolve it all, in which |
| 9409 | * case no corresponding inclusion is performed. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9410 | * So do we need a warning report here? |
| 9411 | */ |
| 9412 | xmlSchemaPCustomErr(ctxt, |
| 9413 | XML_SCHEMAP_FAILED_LOAD, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9414 | NULL, NULL, node, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9415 | "Failed to load the document '%s' for inclusion", schemaLocation); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9416 | goto exit_invalid; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9417 | } |
| 9418 | |
| 9419 | /* |
| 9420 | * Then extract the root of the schema |
| 9421 | */ |
| 9422 | root = xmlDocGetRootElement(doc); |
| 9423 | if (root == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9424 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9425 | XML_SCHEMAP_NOROOT, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9426 | NULL, NULL, node, |
| 9427 | "The included document '%s' has no document " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9428 | "element", schemaLocation); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9429 | goto exit_invalid; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9430 | } |
| 9431 | |
| 9432 | /* |
| 9433 | * Remove all the blank text nodes |
| 9434 | */ |
| 9435 | xmlSchemaCleanupDoc(ctxt, root); |
| 9436 | |
| 9437 | /* |
| 9438 | * Check the schemas top level element |
| 9439 | */ |
| 9440 | if (!IS_SCHEMA(root, "schema")) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9441 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9442 | XML_SCHEMAP_NOT_SCHEMA, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9443 | NULL, NULL, node, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9444 | "The document '%s' to be included is not a schema document", |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9445 | schemaLocation); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9446 | goto exit_invalid; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9447 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9448 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9449 | targetNamespace = xmlSchemaGetProp(ctxt, root, "targetNamespace"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9450 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9451 | * 2.1 SII has a targetNamespace [attribute], and its ·actual |
| 9452 | * value· is identical to the ·actual value· of the targetNamespace |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9453 | * [attribute] of SIIÂ’ (which must have such an [attribute]). |
| 9454 | */ |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9455 | check_targetNamespace: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9456 | if (targetNamespace != NULL) { |
| 9457 | if (schema->targetNamespace == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9458 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9459 | XML_SCHEMAP_SRC_INCLUDE, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9460 | NULL, NULL, node, |
| 9461 | "The target namespace of the included schema " |
| 9462 | "'%s' has to be absent, since the including schema " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9463 | "has no target namespace", |
| 9464 | schemaLocation); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9465 | goto exit_invalid; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9466 | } else if (!xmlStrEqual(targetNamespace, schema->targetNamespace)) { |
| 9467 | xmlSchemaPCustomErrExt(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9468 | XML_SCHEMAP_SRC_INCLUDE, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9469 | NULL, NULL, node, |
| 9470 | "The target namespace '%s' of the included schema '%s' " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9471 | "differs from '%s' of the including schema", |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9472 | targetNamespace, schemaLocation, schema->targetNamespace); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9473 | goto exit_invalid; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9474 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9475 | } else if (schema->targetNamespace != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9476 | if ((schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) == 0) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9477 | schema->flags |= XML_SCHEMAS_INCLUDING_CONVERT_NS; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9478 | } else |
| 9479 | wasConvertingNs = 1; |
| 9480 | } |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9481 | |
| 9482 | if (include != NULL) |
| 9483 | goto exit; |
| 9484 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9485 | /* |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9486 | * URGENT TODO: If the schema is a chameleon-include then copy the |
| 9487 | * components into the including schema and modify the targetNamespace |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9488 | * of those components, do nothing otherwise. |
| 9489 | * NOTE: This is currently worked-around by compiling the chameleon |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9490 | * for every destinct including targetNamespace; thus not performant at |
| 9491 | * the moment. |
| 9492 | * TODO: Check when the namespace in wildcards for chameleons needs |
| 9493 | * to be converted: before we built wildcard intersections or after. |
| 9494 | */ |
| 9495 | /* |
| 9496 | * Register the include. |
| 9497 | */ |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9498 | include = (xmlSchemaIncludePtr) xmlMalloc(sizeof(xmlSchemaInclude)); |
| 9499 | if (include == NULL) { |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9500 | xmlSchemaPErrMemory(ctxt, "allocating include entry", NULL); |
| 9501 | goto exit_failure; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9502 | } |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9503 | memset(include, 0, sizeof(xmlSchemaInclude)); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9504 | include->next = schema->includes; |
| 9505 | schema->includes = include; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9506 | /* |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9507 | * TODO: Use the resolved URI for the this location, since it might |
| 9508 | * differ if using filenames/URIs simultaneosly. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9509 | */ |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9510 | include->schemaLocation = schemaLocation; |
| 9511 | include->doc = doc; |
| 9512 | /* |
| 9513 | * In case of chameleons, the original target namespace will differ |
| 9514 | * from the resulting namespace. |
| 9515 | */ |
| 9516 | include->origTargetNamespace = targetNamespace; |
| 9517 | include->targetNamespace = schema->targetNamespace; |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 9518 | #ifdef DEBUG_INCLUDES |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9519 | if (targetNamespace != schema->targetNamespace) |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 9520 | xmlGenericError(xmlGenericErrorContext, |
| 9521 | "INCLUDING CHAMELEON '%s'\n orig TNS '%s'\n" |
| 9522 | " into TNS '%s'\n", schemaLocation, |
| 9523 | targetNamespace, schema->targetNamespace); |
| 9524 | else |
| 9525 | xmlGenericError(xmlGenericErrorContext, |
| 9526 | "INCLUDING '%s'\n orig-TNS '%s'\n", schemaLocation, |
| 9527 | targetNamespace); |
| 9528 | #endif |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9529 | /* |
| 9530 | * Compile the included schema. |
| 9531 | */ |
| 9532 | xmlSchemaParseForImpInc(ctxt, schema, schema->targetNamespace, root); |
| 9533 | |
| 9534 | exit: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9535 | /* |
| 9536 | * Remove the converting flag. |
| 9537 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9538 | if ((wasConvertingNs == 0) && |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9539 | (schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS)) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9540 | schema->flags ^= XML_SCHEMAS_INCLUDING_CONVERT_NS; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9541 | return (1); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9542 | |
| 9543 | exit_invalid: |
| 9544 | if (doc != NULL) { |
| 9545 | if (include != NULL) |
| 9546 | include->doc = NULL; |
| 9547 | xmlFreeDoc(doc); |
| 9548 | } |
| 9549 | return (ctxt->err); |
| 9550 | |
| 9551 | exit_failure: |
| 9552 | if (doc != NULL) { |
| 9553 | if (include != NULL) |
| 9554 | include->doc = NULL; |
| 9555 | xmlFreeDoc(doc); |
| 9556 | } |
| 9557 | return (-1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9558 | } |
| 9559 | |
| 9560 | /** |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9561 | * xmlSchemaParseModelGroup: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9562 | * @ctxt: a schema validation context |
| 9563 | * @schema: the schema being built |
| 9564 | * @node: a subtree containing XML Schema informations |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9565 | * @type: the "compositor" type |
| 9566 | * @particleNeeded: if a a model group with a particle |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9567 | * |
| 9568 | * parse a XML schema Sequence definition |
| 9569 | * *WARNING* this interface is highly subject to change |
| 9570 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 9571 | * Returns -1 in case of error, 0 if the declaration is improper and |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9572 | * 1 in case of success. |
| 9573 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9574 | static xmlSchemaTreeItemPtr |
| 9575 | xmlSchemaParseModelGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 9576 | xmlNodePtr node, xmlSchemaTypeType type, |
| 9577 | int withParticle) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9578 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9579 | xmlSchemaModelGroupPtr item; |
| 9580 | xmlSchemaParticlePtr particle = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9581 | xmlNodePtr child = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9582 | xmlAttrPtr attr; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9583 | const xmlChar *oldcontainer, *container; |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 9584 | int min = 0, max = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9585 | |
| 9586 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9587 | return (NULL); |
| 9588 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9589 | * Create a model group with the given compositor. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9590 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9591 | item = xmlSchemaAddModelGroup(ctxt, schema, type, &container, node); |
| 9592 | if (item == NULL) |
| 9593 | return (NULL); |
| 9594 | |
| 9595 | if (withParticle) { |
| 9596 | if (type == XML_SCHEMA_TYPE_ALL) { |
| 9597 | min = xmlGetMinOccurs(ctxt, node, 0, 1, 1, "(0 | 1)"); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9598 | max = xmlGetMaxOccurs(ctxt, node, 1, 1, 1, "1"); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9599 | } else { |
| 9600 | /* choice + sequence */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9601 | min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "xs:nonNegativeInteger"); |
| 9602 | max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, |
| 9603 | "(xs:nonNegativeInteger | unbounded)"); |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 9604 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9605 | xmlSchemaPCheckParticleCorrect_2(ctxt, NULL, node, min, max); |
| 9606 | /* |
| 9607 | * Create a particle |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9608 | */ |
| 9609 | particle = xmlSchemaAddParticle(ctxt, schema, node, min, max); |
| 9610 | if (particle == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9611 | return (NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9612 | particle->children = (xmlSchemaTreeItemPtr) item; |
| 9613 | /* |
| 9614 | * Check for illegal attributes. |
| 9615 | */ |
| 9616 | attr = node->properties; |
| 9617 | while (attr != NULL) { |
| 9618 | if (attr->ns == NULL) { |
| 9619 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 9620 | (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) && |
| 9621 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9622 | xmlSchemaPIllegalAttrErr(ctxt, |
| 9623 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 9624 | NULL, NULL, attr); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9625 | } |
| 9626 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9627 | xmlSchemaPIllegalAttrErr(ctxt, |
| 9628 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 9629 | NULL, NULL, attr); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9630 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9631 | attr = attr->next; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9632 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9633 | } else { |
| 9634 | /* |
| 9635 | * Check for illegal attributes. |
| 9636 | */ |
| 9637 | attr = node->properties; |
| 9638 | while (attr != NULL) { |
| 9639 | if (attr->ns == NULL) { |
| 9640 | if (!xmlStrEqual(attr->name, BAD_CAST "id")) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9641 | xmlSchemaPIllegalAttrErr(ctxt, |
| 9642 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 9643 | NULL, NULL, attr); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9644 | } |
| 9645 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9646 | xmlSchemaPIllegalAttrErr(ctxt, |
| 9647 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 9648 | NULL, NULL, attr); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9649 | } |
| 9650 | attr = attr->next; |
| 9651 | } |
| 9652 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9653 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9654 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9655 | /* |
| 9656 | * Extract and validate attributes. |
| 9657 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9658 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9659 | /* |
| 9660 | * And now for the children... |
| 9661 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9662 | child = node->children; |
| 9663 | if (IS_SCHEMA(child, "annotation")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9664 | item->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9665 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9666 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9667 | oldcontainer = ctxt->container; |
| 9668 | ctxt->container = container; |
| 9669 | if (type == XML_SCHEMA_TYPE_ALL) { |
| 9670 | xmlSchemaParticlePtr part, last = NULL; |
| 9671 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9672 | while (IS_SCHEMA(child, "element")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9673 | part = (xmlSchemaParticlePtr) xmlSchemaParseElement(ctxt, |
| 9674 | schema, child, 0); |
| 9675 | if (part != NULL) { |
| 9676 | if (part->minOccurs > 1) |
| 9677 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INVALID_MINOCCURS, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9678 | NULL, NULL, child, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9679 | "Invalid value for minOccurs (must be 0 or 1)", NULL); |
| 9680 | if (part->maxOccurs > 1) |
| 9681 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INVALID_MAXOCCURS, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9682 | NULL, NULL, child, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9683 | "Invalid value for maxOccurs (must be 0 or 1)", |
| 9684 | NULL); |
| 9685 | if (last == NULL) |
| 9686 | item->children = (xmlSchemaTreeItemPtr) part; |
| 9687 | else |
| 9688 | last->next = (xmlSchemaTreeItemPtr) part; |
| 9689 | last = part; |
| 9690 | } |
| 9691 | child = child->next; |
| 9692 | } |
| 9693 | if (child != NULL) { |
| 9694 | xmlSchemaPContentErr(ctxt, |
| 9695 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 9696 | NULL, NULL, node, child, NULL, |
| 9697 | "(annotation?, (annotation?, element*)"); |
| 9698 | } |
| 9699 | } else { |
| 9700 | /* choice + sequence */ |
| 9701 | xmlSchemaTreeItemPtr part = NULL, last = NULL; |
| 9702 | |
| 9703 | while ((IS_SCHEMA(child, "element")) || |
| 9704 | (IS_SCHEMA(child, "group")) || |
| 9705 | (IS_SCHEMA(child, "any")) || |
| 9706 | (IS_SCHEMA(child, "choice")) || |
| 9707 | (IS_SCHEMA(child, "sequence"))) { |
| 9708 | |
| 9709 | if (IS_SCHEMA(child, "element")) { |
| 9710 | part = (xmlSchemaTreeItemPtr) |
| 9711 | xmlSchemaParseElement(ctxt, schema, child, 0); |
| 9712 | } else if (IS_SCHEMA(child, "group")) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9713 | part = |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9714 | xmlSchemaParseModelGroupDefRef(ctxt, schema, child); |
| 9715 | } else if (IS_SCHEMA(child, "any")) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9716 | part = (xmlSchemaTreeItemPtr) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9717 | xmlSchemaParseAny(ctxt, schema, child); |
| 9718 | } else if (IS_SCHEMA(child, "choice")) { |
| 9719 | part = xmlSchemaParseModelGroup(ctxt, schema, child, |
| 9720 | XML_SCHEMA_TYPE_CHOICE, 1); |
| 9721 | } else if (IS_SCHEMA(child, "sequence")) { |
| 9722 | part = xmlSchemaParseModelGroup(ctxt, schema, child, |
| 9723 | XML_SCHEMA_TYPE_SEQUENCE, 1); |
| 9724 | } |
| 9725 | if (part != NULL) { |
| 9726 | if (last == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9727 | item->children = part; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9728 | else |
| 9729 | last->next = part; |
| 9730 | last = part; |
| 9731 | } |
| 9732 | child = child->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9733 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9734 | if (child != NULL) { |
| 9735 | xmlSchemaPContentErr(ctxt, |
| 9736 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 9737 | NULL, NULL, node, child, NULL, |
| 9738 | "(annotation?, (element | group | choice | sequence | any)*)"); |
| 9739 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9740 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9741 | ctxt->container = oldcontainer; |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 9742 | if (withParticle) { |
| 9743 | if ((min == 0) && (max == 0)) |
| 9744 | return (NULL); |
| 9745 | else |
| 9746 | return ((xmlSchemaTreeItemPtr) particle); |
| 9747 | } else |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9748 | return ((xmlSchemaTreeItemPtr) item); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9749 | } |
| 9750 | |
| 9751 | /** |
| 9752 | * xmlSchemaParseRestriction: |
| 9753 | * @ctxt: a schema validation context |
| 9754 | * @schema: the schema being built |
| 9755 | * @node: a subtree containing XML Schema informations |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9756 | * |
| 9757 | * parse a XML schema Restriction definition |
| 9758 | * *WARNING* this interface is highly subject to change |
| 9759 | * |
| 9760 | * Returns the type definition or NULL in case of error |
| 9761 | */ |
| 9762 | static xmlSchemaTypePtr |
| 9763 | xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9764 | xmlNodePtr node, xmlSchemaTypeType parentType) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9765 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9766 | xmlSchemaTypePtr type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9767 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9768 | char buf[30]; |
| 9769 | const xmlChar *oldcontainer, *container; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9770 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9771 | |
| 9772 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 9773 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9774 | /* Not a component, don't create it. */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9775 | type = ctxt->ctxtType; |
| 9776 | type->flags |= XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9777 | |
| 9778 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9779 | * TODO: Is the container needed at all? the anonymous |
| 9780 | * items inside should generate unique names already. |
| 9781 | */ |
| 9782 | snprintf(buf, 29, "#restr%d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9783 | container = xmlDictLookup(ctxt->dict, BAD_CAST buf, -1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9784 | /* |
| 9785 | * Check for illegal attributes. |
| 9786 | */ |
| 9787 | attr = node->properties; |
| 9788 | while (attr != NULL) { |
| 9789 | if (attr->ns == NULL) { |
| 9790 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 9791 | (!xmlStrEqual(attr->name, BAD_CAST "base"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9792 | xmlSchemaPIllegalAttrErr(ctxt, |
| 9793 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 9794 | NULL, NULL, attr); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9795 | } |
| 9796 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9797 | xmlSchemaPIllegalAttrErr(ctxt, |
| 9798 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 9799 | NULL, NULL, attr); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9800 | } |
| 9801 | attr = attr->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9802 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9803 | /* |
| 9804 | * Extract and validate attributes. |
| 9805 | */ |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 9806 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9807 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9808 | * Attribute "base" - mandatory if inside a complex type. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9809 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9810 | /* |
| 9811 | * SPEC (1.2) "otherwise (<restriction> has no <simpleType> " |
| 9812 | * among its [children]), the simple type definition which is |
| 9813 | * the {content type} of the type definition ·resolved· to by |
| 9814 | * the ·actual value· of the base [attribute]" |
| 9815 | */ |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 9816 | if ((xmlSchemaPValAttrQName(ctxt, schema, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9817 | NULL, NULL, node, "base", |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9818 | &(type->baseNs), &(type->base)) == 0) && |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 9819 | (type->base == NULL) && |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9820 | (type->type == XML_SCHEMA_TYPE_COMPLEX)) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9821 | xmlSchemaPMissingAttrErr(ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9822 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 9823 | type, node, "base", NULL); |
| 9824 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9825 | /* |
| 9826 | * And now for the children... |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9827 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9828 | child = node->children; |
| 9829 | if (IS_SCHEMA(child, "annotation")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9830 | /* |
| 9831 | * Add the annotation to the simple type ancestor. |
| 9832 | */ |
| 9833 | xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type, |
| 9834 | xmlSchemaParseAnnotation(ctxt, schema, child)); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9835 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9836 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9837 | oldcontainer = ctxt->container; |
| 9838 | ctxt->container = container; |
| 9839 | if (parentType == XML_SCHEMA_TYPE_SIMPLE) { |
| 9840 | /* |
| 9841 | * Corresponds to <simpleType><restriction><simpleType>. |
| 9842 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9843 | if (IS_SCHEMA(child, "simpleType")) { |
| 9844 | if (type->base != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9845 | /* |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9846 | * src-restriction-base-or-simpleType |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9847 | * Either the base [attribute] or the simpleType [child] of the |
| 9848 | * <restriction> element must be present, but not both. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9849 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9850 | xmlSchemaPContentErr(ctxt, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9851 | XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9852 | NULL, NULL, node, child, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9853 | "The attribute 'base' and the <simpleType> child are " |
| 9854 | "mutually exclusive", NULL); |
| 9855 | } else { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9856 | type->baseType = (xmlSchemaTypePtr) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9857 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9858 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9859 | child = child->next; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9860 | } else if (type->base == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9861 | xmlSchemaPContentErr(ctxt, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9862 | XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE, |
| 9863 | NULL, NULL, node, child, |
| 9864 | "Either the attribute 'base' or a <simpleType> child " |
| 9865 | "must be present", NULL); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9866 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9867 | } else if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
| 9868 | /* |
| 9869 | * Corresponds to <complexType><complexContent><restriction>... |
| 9870 | * followed by: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9871 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9872 | * Model groups <all>, <choice> and <sequence>. |
| 9873 | */ |
| 9874 | if (IS_SCHEMA(child, "all")) { |
| 9875 | type->subtypes = (xmlSchemaTypePtr) |
| 9876 | xmlSchemaParseModelGroup(ctxt, schema, child, |
| 9877 | XML_SCHEMA_TYPE_ALL, 1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9878 | child = child->next; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9879 | } else if (IS_SCHEMA(child, "choice")) { |
| 9880 | type->subtypes = (xmlSchemaTypePtr) |
| 9881 | xmlSchemaParseModelGroup(ctxt, |
| 9882 | schema, child, XML_SCHEMA_TYPE_CHOICE, 1); |
| 9883 | child = child->next; |
| 9884 | } else if (IS_SCHEMA(child, "sequence")) { |
| 9885 | type->subtypes = (xmlSchemaTypePtr) |
| 9886 | xmlSchemaParseModelGroup(ctxt, schema, child, |
| 9887 | XML_SCHEMA_TYPE_SEQUENCE, 1); |
| 9888 | child = child->next; |
| 9889 | /* |
| 9890 | * Model group reference <group>. |
| 9891 | */ |
| 9892 | } else if (IS_SCHEMA(child, "group")) { |
| 9893 | type->subtypes = (xmlSchemaTypePtr) |
| 9894 | xmlSchemaParseModelGroupDefRef(ctxt, schema, child); |
| 9895 | child = child->next; |
| 9896 | } |
| 9897 | } else if (parentType == XML_SCHEMA_TYPE_SIMPLE_CONTENT) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9898 | /* |
| 9899 | * Corresponds to <complexType><simpleContent><restriction>... |
| 9900 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9901 | * "1.1 the simple type definition corresponding to the <simpleType> |
| 9902 | * among the [children] of <restriction> if there is one;" |
| 9903 | */ |
| 9904 | if (IS_SCHEMA(child, "simpleType")) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9905 | /* |
| 9906 | * We will store the to-be-restricted simple type in |
| 9907 | * type->contentTypeDef *temporarily*. |
| 9908 | */ |
| 9909 | type->contentTypeDef = (xmlSchemaTypePtr) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9910 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9911 | if ( type->contentTypeDef == NULL) |
| 9912 | return (NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9913 | child = child->next; |
| 9914 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9915 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9916 | |
| 9917 | if ((parentType == XML_SCHEMA_TYPE_SIMPLE) || |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9918 | (parentType == XML_SCHEMA_TYPE_SIMPLE_CONTENT)) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9919 | xmlSchemaFacetPtr facet, lastfacet = NULL; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9920 | /* |
| 9921 | * Corresponds to <complexType><simpleContent><restriction>... |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9922 | * <simpleType><restriction>... |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9923 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9924 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9925 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9926 | * Add the facets to the simple type ancestor. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9927 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9928 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9929 | * TODO: Datatypes: 4.1.3 Constraints on XML Representation of |
| 9930 | * Simple Type Definition Schema Representation Constraint: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9931 | * *Single Facet Value* |
| 9932 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9933 | while ((IS_SCHEMA(child, "minInclusive")) || |
| 9934 | (IS_SCHEMA(child, "minExclusive")) || |
| 9935 | (IS_SCHEMA(child, "maxInclusive")) || |
| 9936 | (IS_SCHEMA(child, "maxExclusive")) || |
| 9937 | (IS_SCHEMA(child, "totalDigits")) || |
| 9938 | (IS_SCHEMA(child, "fractionDigits")) || |
| 9939 | (IS_SCHEMA(child, "pattern")) || |
| 9940 | (IS_SCHEMA(child, "enumeration")) || |
| 9941 | (IS_SCHEMA(child, "whiteSpace")) || |
| 9942 | (IS_SCHEMA(child, "length")) || |
| 9943 | (IS_SCHEMA(child, "maxLength")) || |
| 9944 | (IS_SCHEMA(child, "minLength"))) { |
| 9945 | facet = xmlSchemaParseFacet(ctxt, schema, child); |
| 9946 | if (facet != NULL) { |
| 9947 | if (lastfacet == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9948 | type->facets = facet; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9949 | else |
| 9950 | lastfacet->next = facet; |
| 9951 | lastfacet = facet; |
| 9952 | lastfacet->next = NULL; |
| 9953 | } |
| 9954 | child = child->next; |
| 9955 | } |
| 9956 | /* |
| 9957 | * Create links for derivation and validation. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9958 | */ |
| 9959 | if (type->facets != NULL) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9960 | xmlSchemaFacetLinkPtr facetLink, lastFacetLink = NULL; |
| 9961 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9962 | facet = type->facets; |
| 9963 | do { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9964 | facetLink = (xmlSchemaFacetLinkPtr) |
| 9965 | xmlMalloc(sizeof(xmlSchemaFacetLink)); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9966 | if (facetLink == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9967 | xmlSchemaPErrMemory(ctxt, "allocating a facet link", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9968 | xmlFree(facetLink); |
| 9969 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9970 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9971 | facetLink->facet = facet; |
| 9972 | facetLink->next = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9973 | if (lastFacetLink == NULL) |
| 9974 | type->facetSet = facetLink; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9975 | else |
| 9976 | lastFacetLink->next = facetLink; |
| 9977 | lastFacetLink = facetLink; |
| 9978 | facet = facet->next; |
| 9979 | } while (facet != NULL); |
| 9980 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9981 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9982 | if (type->type == XML_SCHEMA_TYPE_COMPLEX) { |
| 9983 | /* |
| 9984 | * Attribute uses/declarations. |
| 9985 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9986 | child = xmlSchemaParseAttrDecls(ctxt, schema, child, type); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9987 | /* |
| 9988 | * Attribute wildcard. |
| 9989 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9990 | if (IS_SCHEMA(child, "anyAttribute")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 9991 | type->attributeWildcard = |
| 9992 | xmlSchemaParseAnyAttribute(ctxt, schema, child); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9993 | child = child->next; |
| 9994 | } |
| 9995 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9996 | if (child != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 9997 | if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
| 9998 | xmlSchemaPContentErr(ctxt, |
| 9999 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10000 | NULL, NULL, node, child, NULL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 10001 | "annotation?, (group | all | choice | sequence)?, " |
| 10002 | "((attribute | attributeGroup)*, anyAttribute?))"); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10003 | } else if (parentType == XML_SCHEMA_TYPE_SIMPLE_CONTENT) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10004 | xmlSchemaPContentErr(ctxt, |
| 10005 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10006 | NULL, NULL, node, child, NULL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 10007 | "(annotation?, (simpleType?, (minExclusive | minInclusive | " |
| 10008 | "maxExclusive | maxInclusive | totalDigits | fractionDigits | " |
| 10009 | "length | minLength | maxLength | enumeration | whiteSpace | " |
| 10010 | "pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))"); |
| 10011 | } else { |
| 10012 | /* Simple type */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10013 | xmlSchemaPContentErr(ctxt, |
| 10014 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10015 | NULL, NULL, node, child, NULL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 10016 | "(annotation?, (simpleType?, (minExclusive | minInclusive | " |
| 10017 | "maxExclusive | maxInclusive | totalDigits | fractionDigits | " |
| 10018 | "length | minLength | maxLength | enumeration | whiteSpace | " |
| 10019 | "pattern)*))"); |
| 10020 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10021 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10022 | ctxt->container = oldcontainer; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10023 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10024 | } |
| 10025 | |
| 10026 | /** |
| 10027 | * xmlSchemaParseExtension: |
| 10028 | * @ctxt: a schema validation context |
| 10029 | * @schema: the schema being built |
| 10030 | * @node: a subtree containing XML Schema informations |
| 10031 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10032 | * Parses an <extension>, which is found inside a |
| 10033 | * <simpleContent> or <complexContent>. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10034 | * *WARNING* this interface is highly subject to change. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10035 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10036 | * TODO: Returns the type definition or NULL in case of error |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10037 | */ |
| 10038 | static xmlSchemaTypePtr |
| 10039 | xmlSchemaParseExtension(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10040 | xmlNodePtr node, xmlSchemaTypeType parentType) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10041 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10042 | xmlSchemaTypePtr type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10043 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10044 | char buf[30]; |
| 10045 | const xmlChar *oldcontainer, *container; |
| 10046 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10047 | |
| 10048 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 10049 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10050 | /* Not a component, don't create it. */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10051 | type = ctxt->ctxtType; |
| 10052 | type->flags |= XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10053 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10054 | snprintf(buf, 29, "#ext%d", ctxt->counter++ + 1); |
| 10055 | container = xmlDictLookup(ctxt->dict, BAD_CAST buf, -1); |
| 10056 | /* |
| 10057 | * Check for illegal attributes. |
| 10058 | */ |
| 10059 | attr = node->properties; |
| 10060 | while (attr != NULL) { |
| 10061 | if (attr->ns == NULL) { |
| 10062 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 10063 | (!xmlStrEqual(attr->name, BAD_CAST "base"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10064 | xmlSchemaPIllegalAttrErr(ctxt, |
| 10065 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 10066 | NULL, NULL, attr); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10067 | } |
| 10068 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10069 | xmlSchemaPIllegalAttrErr(ctxt, |
| 10070 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 10071 | NULL, NULL, attr); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10072 | } |
| 10073 | attr = attr->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10074 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 10075 | |
| 10076 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10077 | |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 10078 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10079 | * Attribute "base" - mandatory. |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 10080 | */ |
| 10081 | if ((xmlSchemaPValAttrQName(ctxt, schema, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10082 | NULL, NULL, node, "base", &(type->baseNs), &(type->base)) == 0) && |
| 10083 | (type->base == NULL)) { |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 10084 | xmlSchemaPMissingAttrErr(ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10085 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 10086 | NULL, node, "base", NULL); |
| 10087 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10088 | /* |
| 10089 | * And now for the children... |
| 10090 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10091 | child = node->children; |
| 10092 | if (IS_SCHEMA(child, "annotation")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10093 | /* |
| 10094 | * Add the annotation to the type ancestor. |
| 10095 | */ |
| 10096 | xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type, |
| 10097 | xmlSchemaParseAnnotation(ctxt, schema, child)); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10098 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10099 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10100 | oldcontainer = ctxt->container; |
| 10101 | ctxt->container = container; |
| 10102 | if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
| 10103 | /* |
| 10104 | * Corresponds to <complexType><complexContent><extension>... and: |
| 10105 | * |
| 10106 | * Model groups <all>, <choice>, <sequence> and <group>. |
| 10107 | */ |
| 10108 | if (IS_SCHEMA(child, "all")) { |
| 10109 | type->subtypes = (xmlSchemaTypePtr) |
| 10110 | xmlSchemaParseModelGroup(ctxt, schema, |
| 10111 | child, XML_SCHEMA_TYPE_ALL, 1); |
| 10112 | child = child->next; |
| 10113 | } else if (IS_SCHEMA(child, "choice")) { |
| 10114 | type->subtypes = (xmlSchemaTypePtr) |
| 10115 | xmlSchemaParseModelGroup(ctxt, schema, |
| 10116 | child, XML_SCHEMA_TYPE_CHOICE, 1); |
| 10117 | child = child->next; |
| 10118 | } else if (IS_SCHEMA(child, "sequence")) { |
| 10119 | type->subtypes = (xmlSchemaTypePtr) |
| 10120 | xmlSchemaParseModelGroup(ctxt, schema, |
| 10121 | child, XML_SCHEMA_TYPE_SEQUENCE, 1); |
| 10122 | child = child->next; |
| 10123 | } else if (IS_SCHEMA(child, "group")) { |
| 10124 | type->subtypes = (xmlSchemaTypePtr) |
| 10125 | xmlSchemaParseModelGroupDefRef(ctxt, schema, child); |
| 10126 | child = child->next; |
| 10127 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10128 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10129 | if (child != NULL) { |
| 10130 | /* |
| 10131 | * Attribute uses/declarations. |
| 10132 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10133 | child = xmlSchemaParseAttrDecls(ctxt, schema, child, type); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10134 | /* |
| 10135 | * Attribute wildcard. |
| 10136 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10137 | if (IS_SCHEMA(child, "anyAttribute")) { |
| 10138 | ctxt->ctxtType->attributeWildcard = |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10139 | xmlSchemaParseAnyAttribute(ctxt, schema, child); |
| 10140 | child = child->next; |
| 10141 | } |
| 10142 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10143 | if (child != NULL) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10144 | if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
| 10145 | /* Complex content extension. */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10146 | xmlSchemaPContentErr(ctxt, |
| 10147 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10148 | NULL, NULL, node, child, NULL, |
| 10149 | "(annotation?, ((group | all | choice | sequence)?, " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10150 | "((attribute | attributeGroup)*, anyAttribute?)))"); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10151 | } else { |
| 10152 | /* Simple content extension. */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10153 | xmlSchemaPContentErr(ctxt, |
| 10154 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10155 | NULL, NULL, node, child, NULL, |
| 10156 | "(annotation?, ((attribute | attributeGroup)*, " |
| 10157 | "anyAttribute?))"); |
| 10158 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10159 | } |
| 10160 | ctxt->container = oldcontainer; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10161 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10162 | } |
| 10163 | |
| 10164 | /** |
| 10165 | * xmlSchemaParseSimpleContent: |
| 10166 | * @ctxt: a schema validation context |
| 10167 | * @schema: the schema being built |
| 10168 | * @node: a subtree containing XML Schema informations |
| 10169 | * |
| 10170 | * parse a XML schema SimpleContent definition |
| 10171 | * *WARNING* this interface is highly subject to change |
| 10172 | * |
| 10173 | * Returns the type definition or NULL in case of error |
| 10174 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10175 | static int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10176 | xmlSchemaParseSimpleContent(xmlSchemaParserCtxtPtr ctxt, |
| 10177 | xmlSchemaPtr schema, xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10178 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10179 | xmlSchemaTypePtr type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10180 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10181 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10182 | |
| 10183 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10184 | return (-1); |
| 10185 | /* Not a component, don't create it. */ |
| 10186 | type = ctxt->ctxtType; |
| 10187 | type->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
| 10188 | /* |
| 10189 | * Check for illegal attributes. |
| 10190 | */ |
| 10191 | attr = node->properties; |
| 10192 | while (attr != NULL) { |
| 10193 | if (attr->ns == NULL) { |
| 10194 | if ((!xmlStrEqual(attr->name, BAD_CAST "id"))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10195 | xmlSchemaPIllegalAttrErr(ctxt, |
| 10196 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 10197 | NULL, NULL, attr); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10198 | } |
| 10199 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10200 | xmlSchemaPIllegalAttrErr(ctxt, |
| 10201 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 10202 | NULL, NULL, attr); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10203 | } |
| 10204 | attr = attr->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10205 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 10206 | |
| 10207 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10208 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10209 | /* |
| 10210 | * And now for the children... |
| 10211 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10212 | child = node->children; |
| 10213 | if (IS_SCHEMA(child, "annotation")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10214 | /* |
| 10215 | * Add the annotation to the complex type ancestor. |
| 10216 | */ |
| 10217 | xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type, |
| 10218 | xmlSchemaParseAnnotation(ctxt, schema, child)); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10219 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10220 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10221 | if (IS_SCHEMA(child, "restriction")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10222 | xmlSchemaParseRestriction(ctxt, schema, child, |
| 10223 | XML_SCHEMA_TYPE_SIMPLE_CONTENT); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10224 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10225 | } else if (IS_SCHEMA(child, "extension")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10226 | xmlSchemaParseExtension(ctxt, schema, child, |
| 10227 | XML_SCHEMA_TYPE_SIMPLE_CONTENT); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10228 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10229 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10230 | if (child != NULL) { |
| 10231 | xmlSchemaPContentErr(ctxt, |
| 10232 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10233 | NULL, NULL, node, child, NULL, |
| 10234 | "(annotation?, (restriction | extension))"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10235 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10236 | return (0); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10237 | } |
| 10238 | |
| 10239 | /** |
| 10240 | * xmlSchemaParseComplexContent: |
| 10241 | * @ctxt: a schema validation context |
| 10242 | * @schema: the schema being built |
| 10243 | * @node: a subtree containing XML Schema informations |
| 10244 | * |
| 10245 | * parse a XML schema ComplexContent definition |
| 10246 | * *WARNING* this interface is highly subject to change |
| 10247 | * |
| 10248 | * Returns the type definition or NULL in case of error |
| 10249 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10250 | static int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10251 | xmlSchemaParseComplexContent(xmlSchemaParserCtxtPtr ctxt, |
| 10252 | xmlSchemaPtr schema, xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10253 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10254 | xmlSchemaTypePtr type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10255 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10256 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10257 | |
| 10258 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10259 | return (-1); |
| 10260 | /* Not a component, don't create it. */ |
| 10261 | type = ctxt->ctxtType; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10262 | /* |
| 10263 | * Check for illegal attributes. |
| 10264 | */ |
| 10265 | attr = node->properties; |
| 10266 | while (attr != NULL) { |
| 10267 | if (attr->ns == NULL) { |
| 10268 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10269 | (!xmlStrEqual(attr->name, BAD_CAST "mixed"))) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10270 | { |
| 10271 | xmlSchemaPIllegalAttrErr(ctxt, |
| 10272 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 10273 | NULL, NULL, attr); |
| 10274 | } |
| 10275 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 10276 | xmlSchemaPIllegalAttrErr(ctxt, |
| 10277 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 10278 | NULL, NULL, attr); |
| 10279 | } |
| 10280 | attr = attr->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10281 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 10282 | |
| 10283 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
| 10284 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10285 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10286 | * Set the 'mixed' on the complex type ancestor. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10287 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10288 | if (xmlGetBooleanProp(ctxt, NULL, NULL, node, "mixed", 0)) { |
| 10289 | if ((type->flags & XML_SCHEMAS_TYPE_MIXED) == 0) |
| 10290 | type->flags |= XML_SCHEMAS_TYPE_MIXED; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10291 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10292 | child = node->children; |
| 10293 | if (IS_SCHEMA(child, "annotation")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10294 | /* |
| 10295 | * Add the annotation to the complex type ancestor. |
| 10296 | */ |
| 10297 | xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type, |
| 10298 | xmlSchemaParseAnnotation(ctxt, schema, child)); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10299 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10300 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10301 | if (IS_SCHEMA(child, "restriction")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10302 | xmlSchemaParseRestriction(ctxt, schema, child, |
| 10303 | XML_SCHEMA_TYPE_COMPLEX_CONTENT); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10304 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10305 | } else if (IS_SCHEMA(child, "extension")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10306 | xmlSchemaParseExtension(ctxt, schema, child, |
| 10307 | XML_SCHEMA_TYPE_COMPLEX_CONTENT); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10308 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10309 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10310 | if (child != NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10311 | xmlSchemaPContentErr(ctxt, |
| 10312 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 10313 | NULL, NULL, node, child, |
| 10314 | NULL, "(annotation?, (restriction | extension))"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10315 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10316 | return (0); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10317 | } |
| 10318 | |
| 10319 | /** |
| 10320 | * xmlSchemaParseComplexType: |
| 10321 | * @ctxt: a schema validation context |
| 10322 | * @schema: the schema being built |
| 10323 | * @node: a subtree containing XML Schema informations |
| 10324 | * |
| 10325 | * parse a XML schema Complex Type definition |
| 10326 | * *WARNING* this interface is highly subject to change |
| 10327 | * |
| 10328 | * Returns the type definition or NULL in case of error |
| 10329 | */ |
| 10330 | static xmlSchemaTypePtr |
| 10331 | xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10332 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10333 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10334 | xmlSchemaTypePtr type, ctxtType; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10335 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10336 | const xmlChar *oldcontainer, *name = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10337 | xmlAttrPtr attr; |
| 10338 | const xmlChar *attrValue; |
| 10339 | xmlChar *des = NULL; /* The reported designation. */ |
Daniel Veillard | 1a380b8 | 2004-10-21 16:00:06 +0000 | [diff] [blame] | 10340 | char buf[40]; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10341 | int final = 0, block = 0; |
Daniel Veillard | 1a380b8 | 2004-10-21 16:00:06 +0000 | [diff] [blame] | 10342 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10343 | |
| 10344 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 10345 | return (NULL); |
| 10346 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10347 | ctxtType = ctxt->ctxtType; |
| 10348 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10349 | if (topLevel) { |
| 10350 | attr = xmlSchemaGetPropNode(node, "name"); |
| 10351 | if (attr == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10352 | xmlSchemaPMissingAttrErr(ctxt, |
| 10353 | XML_SCHEMAP_S4S_ATTR_MISSING, NULL, node, "name", NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10354 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10355 | } else if (xmlSchemaPValAttrNode(ctxt, |
| 10356 | (xmlChar **) &xmlSchemaElemDesCT, NULL, attr, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10357 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 10358 | return (NULL); |
| 10359 | } |
| 10360 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10361 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10362 | if (topLevel == 0) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10363 | /* |
| 10364 | * Parse as local complex type definition. |
| 10365 | */ |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 10366 | snprintf(buf, 39, "#CT%d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10367 | type = xmlSchemaAddType(ctxt, schema, (const xmlChar *)buf, NULL, node); |
| 10368 | if (type == NULL) |
| 10369 | return (NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10370 | name = type->name; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10371 | type->node = node; |
| 10372 | type->type = XML_SCHEMA_TYPE_COMPLEX; |
| 10373 | /* |
| 10374 | * TODO: We need the target namespace. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10375 | */ |
| 10376 | } else { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10377 | /* |
| 10378 | * Parse as global complex type definition. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10379 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 10380 | type = xmlSchemaAddType(ctxt, schema, name, schema->targetNamespace, node); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10381 | if (type == NULL) |
| 10382 | return (NULL); |
| 10383 | type->node = node; |
| 10384 | type->type = XML_SCHEMA_TYPE_COMPLEX; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10385 | type->flags |= XML_SCHEMAS_TYPE_GLOBAL; |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 10386 | } |
| 10387 | type->targetNamespace = schema->targetNamespace; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10388 | /* |
| 10389 | * Handle attributes. |
| 10390 | */ |
| 10391 | attr = node->properties; |
| 10392 | while (attr != NULL) { |
| 10393 | if (attr->ns == NULL) { |
| 10394 | if (xmlStrEqual(attr->name, BAD_CAST "id")) { |
| 10395 | /* |
| 10396 | * Attribute "id". |
| 10397 | */ |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 10398 | xmlSchemaPValAttrID(ctxt, NULL, type, node, |
| 10399 | BAD_CAST "id"); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10400 | } else if (xmlStrEqual(attr->name, BAD_CAST "mixed")) { |
| 10401 | /* |
| 10402 | * Attribute "mixed". |
| 10403 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10404 | if (xmlSchemaPGetBoolNodeValue(ctxt, &des, type, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10405 | (xmlNodePtr) attr)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10406 | type->flags |= XML_SCHEMAS_TYPE_MIXED; |
| 10407 | } else if (topLevel) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10408 | /* |
| 10409 | * Attributes of global complex type definitions. |
| 10410 | */ |
| 10411 | if (xmlStrEqual(attr->name, BAD_CAST "name")) { |
| 10412 | /* Pass. */ |
| 10413 | } else if (xmlStrEqual(attr->name, BAD_CAST "abstract")) { |
| 10414 | /* |
| 10415 | * Attribute "abstract". |
| 10416 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10417 | if (xmlSchemaPGetBoolNodeValue(ctxt, &des, type, |
| 10418 | (xmlNodePtr) attr)) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10419 | type->flags |= XML_SCHEMAS_TYPE_ABSTRACT; |
| 10420 | } else if (xmlStrEqual(attr->name, BAD_CAST "final")) { |
| 10421 | /* |
| 10422 | * Attribute "final". |
| 10423 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10424 | attrValue = xmlSchemaGetNodeContent(ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10425 | (xmlNodePtr) attr); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10426 | if (xmlSchemaPValAttrBlockFinal(attrValue, |
| 10427 | &(type->flags), |
| 10428 | -1, |
| 10429 | XML_SCHEMAS_TYPE_FINAL_EXTENSION, |
| 10430 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION, |
| 10431 | -1, -1, -1) != 0) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10432 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10433 | xmlSchemaPSimpleTypeErr(ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10434 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10435 | type, (xmlNodePtr) attr, NULL, |
| 10436 | "(#all | List of (extension | restriction))", |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10437 | attrValue, NULL, NULL, NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10438 | } else |
| 10439 | final = 1; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10440 | } else if (xmlStrEqual(attr->name, BAD_CAST "block")) { |
| 10441 | /* |
| 10442 | * Attribute "block". |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10443 | */ |
| 10444 | attrValue = xmlSchemaGetNodeContent(ctxt, |
| 10445 | (xmlNodePtr) attr); |
| 10446 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(type->flags), |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10447 | -1, |
| 10448 | XML_SCHEMAS_TYPE_BLOCK_EXTENSION, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10449 | XML_SCHEMAS_TYPE_BLOCK_RESTRICTION, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10450 | -1, -1, -1) != 0) { |
| 10451 | xmlSchemaPSimpleTypeErr(ctxt, |
| 10452 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10453 | type, (xmlNodePtr) attr, NULL, |
| 10454 | "(#all | List of (extension | restriction)) ", |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10455 | attrValue, NULL, NULL, NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10456 | } else |
| 10457 | block = 1; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10458 | } else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10459 | xmlSchemaPIllegalAttrErr(ctxt, |
| 10460 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10461 | &des, type, attr); |
| 10462 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10463 | } else { |
| 10464 | xmlSchemaPIllegalAttrErr(ctxt, |
| 10465 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10466 | &des, type, attr); |
| 10467 | } |
| 10468 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10469 | xmlSchemaPIllegalAttrErr(ctxt, |
| 10470 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 10471 | &des, type, attr); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10472 | } |
| 10473 | attr = attr->next; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10474 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10475 | if (! block) { |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 10476 | /* |
| 10477 | * Apply default "block" values. |
| 10478 | */ |
| 10479 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION) |
| 10480 | type->flags |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION; |
| 10481 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION) |
| 10482 | type->flags |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION; |
| 10483 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10484 | if (! final) { |
| 10485 | /* |
| 10486 | * Apply default "block" values. |
| 10487 | */ |
| 10488 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION) |
| 10489 | type->flags |= XML_SCHEMAS_TYPE_FINAL_RESTRICTION; |
| 10490 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION) |
| 10491 | type->flags |= XML_SCHEMAS_TYPE_FINAL_EXTENSION; |
| 10492 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10493 | /* |
| 10494 | * And now for the children... |
| 10495 | */ |
| 10496 | oldcontainer = ctxt->container; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10497 | ctxt->container = name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10498 | child = node->children; |
| 10499 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10500 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 10501 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10502 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10503 | ctxt->ctxtType = type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10504 | if (IS_SCHEMA(child, "simpleContent")) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10505 | /* |
| 10506 | * 3.4.3 : 2.2 |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10507 | * Specifying mixed='true' when the <simpleContent> |
| 10508 | * alternative is chosen has no effect |
| 10509 | */ |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 10510 | if (type->flags & XML_SCHEMAS_TYPE_MIXED) |
| 10511 | type->flags ^= XML_SCHEMAS_TYPE_MIXED; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10512 | xmlSchemaParseSimpleContent(ctxt, schema, child); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10513 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10514 | } else if (IS_SCHEMA(child, "complexContent")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10515 | type->contentType = XML_SCHEMA_CONTENT_EMPTY; |
| 10516 | xmlSchemaParseComplexContent(ctxt, schema, child); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10517 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10518 | } else { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10519 | /* |
| 10520 | * SPEC |
| 10521 | * "...the third alternative (neither <simpleContent> nor |
| 10522 | * <complexContent>) is chosen. This case is understood as shorthand |
| 10523 | * for complex content restricting the ·ur-type definition·, and the |
| 10524 | * details of the mappings should be modified as necessary. |
| 10525 | */ |
| 10526 | type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 10527 | type->flags |= XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10528 | /* |
| 10529 | * Parse model groups. |
| 10530 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10531 | if (IS_SCHEMA(child, "all")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10532 | type->subtypes = (xmlSchemaTypePtr) |
| 10533 | xmlSchemaParseModelGroup(ctxt, schema, child, |
| 10534 | XML_SCHEMA_TYPE_ALL, 1); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10535 | child = child->next; |
| 10536 | } else if (IS_SCHEMA(child, "choice")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10537 | type->subtypes = (xmlSchemaTypePtr) |
| 10538 | xmlSchemaParseModelGroup(ctxt, schema, child, |
| 10539 | XML_SCHEMA_TYPE_CHOICE, 1); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10540 | child = child->next; |
| 10541 | } else if (IS_SCHEMA(child, "sequence")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10542 | type->subtypes = (xmlSchemaTypePtr) |
| 10543 | xmlSchemaParseModelGroup(ctxt, schema, child, |
| 10544 | XML_SCHEMA_TYPE_SEQUENCE, 1); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10545 | child = child->next; |
| 10546 | } else if (IS_SCHEMA(child, "group")) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 10547 | type->subtypes = (xmlSchemaTypePtr) |
| 10548 | xmlSchemaParseModelGroupDefRef(ctxt, schema, child); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10549 | child = child->next; |
| 10550 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10551 | /* |
| 10552 | * Parse attribute decls/refs. |
| 10553 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10554 | child = xmlSchemaParseAttrDecls(ctxt, schema, child, type); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10555 | /* |
| 10556 | * Parse attribute wildcard. |
| 10557 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10558 | if (IS_SCHEMA(child, "anyAttribute")) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10559 | type->attributeWildcard = xmlSchemaParseAnyAttribute(ctxt, schema, child); |
| 10560 | child = child->next; |
| 10561 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10562 | } |
| 10563 | if (child != NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10564 | xmlSchemaPContentErr(ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10565 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10566 | &des, type, node, child, |
| 10567 | NULL, "(annotation?, (simpleContent | complexContent | " |
| 10568 | "((group | all | choice | sequence)?, ((attribute | " |
| 10569 | "attributeGroup)*, anyAttribute?))))"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10570 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10571 | FREE_AND_NULL(des); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10572 | ctxt->container = oldcontainer; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10573 | ctxt->ctxtType = ctxtType; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10574 | return (type); |
| 10575 | } |
| 10576 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10577 | /** |
| 10578 | * xmlSchemaParseSchema: |
| 10579 | * @ctxt: a schema validation context |
| 10580 | * @node: a subtree containing XML Schema informations |
| 10581 | * |
| 10582 | * parse a XML schema definition from a node set |
| 10583 | * *WARNING* this interface is highly subject to change |
| 10584 | * |
| 10585 | * Returns the internal XML Schema structure built from the resource or |
| 10586 | * NULL in case of error |
| 10587 | */ |
| 10588 | static xmlSchemaPtr |
| 10589 | xmlSchemaParseSchema(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node) |
| 10590 | { |
| 10591 | xmlSchemaPtr schema = NULL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 10592 | const xmlChar *val; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 10593 | int nberrors; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10594 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10595 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10596 | /* |
| 10597 | * This one is called by xmlSchemaParse only and is used if |
| 10598 | * the schema to be parsed was specified via the API; i.e. not |
| 10599 | * automatically by the validated instance document. |
| 10600 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10601 | if ((ctxt == NULL) || (node == NULL)) |
| 10602 | return (NULL); |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 10603 | nberrors = ctxt->nberrors; |
| 10604 | ctxt->nberrors = 0; |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 10605 | ctxt->isS4S = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10606 | if (IS_SCHEMA(node, "schema")) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10607 | xmlSchemaImportPtr import; |
| 10608 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10609 | schema = xmlSchemaNewSchema(ctxt); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10610 | if (schema == NULL) |
| 10611 | return (NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10612 | attr = xmlSchemaGetPropNode(node, "targetNamespace"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10613 | if (attr != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10614 | xmlSchemaPValAttrNode(ctxt, NULL, NULL, attr, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10615 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), &val); |
| 10616 | /* |
| 10617 | * TODO: Should we proceed with an invalid target namespace? |
| 10618 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 10619 | schema->targetNamespace = xmlDictLookup(ctxt->dict, val, -1); |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 10620 | if (xmlStrEqual(schema->targetNamespace, xmlSchemaNs)) { |
| 10621 | /* |
| 10622 | * We are parsing the schema for schema! |
| 10623 | */ |
| 10624 | ctxt->isS4S = 1; |
| 10625 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 10626 | } else { |
| 10627 | schema->targetNamespace = NULL; |
| 10628 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10629 | /* |
| 10630 | * Add the current ns name and location to the import table; |
| 10631 | * this is needed to have a consistent mechanism, regardless |
| 10632 | * if all schemata are constructed dynamically fired by the |
| 10633 | * instance or if the schema to be used was specified via |
| 10634 | * the API. |
| 10635 | */ |
| 10636 | import = xmlSchemaAddImport(ctxt, &(schema->schemasImports), |
| 10637 | schema->targetNamespace); |
| 10638 | if (import == NULL) { |
| 10639 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_FAILED_BUILD_IMPORT, |
| 10640 | NULL, NULL, (xmlNodePtr) ctxt->doc, |
| 10641 | "Internal error: xmlSchemaParseSchema, " |
| 10642 | "failed to add an import entry", NULL); |
| 10643 | xmlSchemaFree(schema); |
| 10644 | schema = NULL; |
| 10645 | return (NULL); |
| 10646 | } |
| 10647 | import->schemaLocation = ctxt->URL; |
| 10648 | /* |
| 10649 | * NOTE: We won't set the doc here, otherwise it will be freed |
| 10650 | * if the import struct is freed. |
| 10651 | * import->doc = ctxt->doc; |
| 10652 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10653 | xmlSchemaParseSchemaDefaults(ctxt, schema, node); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 10654 | xmlSchemaParseSchemaTopLevel(ctxt, schema, node->children); |
| 10655 | } else { |
| 10656 | xmlDocPtr doc; |
| 10657 | |
| 10658 | doc = node->doc; |
| 10659 | |
| 10660 | if ((doc != NULL) && (doc->URL != NULL)) { |
| 10661 | xmlSchemaPErr(ctxt, (xmlNodePtr) doc, |
| 10662 | XML_SCHEMAP_NOT_SCHEMA, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10663 | "The file \"%s\" is not a XML schema.\n", doc->URL, NULL); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 10664 | } else { |
| 10665 | xmlSchemaPErr(ctxt, (xmlNodePtr) doc, |
| 10666 | XML_SCHEMAP_NOT_SCHEMA, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10667 | "The file is not a XML schema.\n", NULL, NULL); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 10668 | } |
| 10669 | return(NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10670 | } |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 10671 | if (ctxt->nberrors != 0) { |
| 10672 | if (schema != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10673 | xmlSchemaFree(schema); |
| 10674 | schema = NULL; |
| 10675 | } |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 10676 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10677 | if (schema != NULL) |
| 10678 | schema->counter = ctxt->counter; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 10679 | ctxt->nberrors = nberrors; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10680 | #ifdef DEBUG |
| 10681 | if (schema == NULL) |
| 10682 | xmlGenericError(xmlGenericErrorContext, |
| 10683 | "xmlSchemaParse() failed\n"); |
| 10684 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10685 | return (schema); |
| 10686 | } |
| 10687 | |
| 10688 | /************************************************************************ |
| 10689 | * * |
| 10690 | * Validating using Schemas * |
| 10691 | * * |
| 10692 | ************************************************************************/ |
| 10693 | |
| 10694 | /************************************************************************ |
| 10695 | * * |
| 10696 | * Reading/Writing Schemas * |
| 10697 | * * |
| 10698 | ************************************************************************/ |
| 10699 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10700 | #if 0 /* Will be enabled if it is clear what options are needed. */ |
| 10701 | /** |
| 10702 | * xmlSchemaParserCtxtSetOptions: |
| 10703 | * @ctxt: a schema parser context |
| 10704 | * @options: a combination of xmlSchemaParserOption |
| 10705 | * |
| 10706 | * Sets the options to be used during the parse. |
| 10707 | * |
| 10708 | * Returns 0 in case of success, -1 in case of an |
| 10709 | * API error. |
| 10710 | */ |
| 10711 | static int |
| 10712 | xmlSchemaParserCtxtSetOptions(xmlSchemaParserCtxtPtr ctxt, |
| 10713 | int options) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10714 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10715 | { |
| 10716 | int i; |
| 10717 | |
| 10718 | if (ctxt == NULL) |
| 10719 | return (-1); |
| 10720 | /* |
| 10721 | * WARNING: Change the start value if adding to the |
| 10722 | * xmlSchemaParseOption. |
| 10723 | */ |
| 10724 | for (i = 1; i < (int) sizeof(int) * 8; i++) { |
| 10725 | if (options & 1<<i) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10726 | return (-1); |
| 10727 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10728 | } |
| 10729 | ctxt->options = options; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10730 | return (0); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10731 | } |
| 10732 | |
| 10733 | /** |
| 10734 | * xmlSchemaValidCtxtGetOptions: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10735 | * @ctxt: a schema parser context |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10736 | * |
| 10737 | * Returns the option combination of the parser context. |
| 10738 | */ |
| 10739 | static int |
| 10740 | xmlSchemaParserCtxtGetOptions(xmlSchemaParserCtxtPtr ctxt) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10741 | |
| 10742 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10743 | if (ctxt == NULL) |
| 10744 | return (-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10745 | else |
| 10746 | return (ctxt->options); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10747 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10748 | #endif |
| 10749 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10750 | /** |
| 10751 | * xmlSchemaNewParserCtxt: |
| 10752 | * @URL: the location of the schema |
| 10753 | * |
| 10754 | * Create an XML Schemas parse context for that file/resource expected |
| 10755 | * to contain an XML Schemas file. |
| 10756 | * |
| 10757 | * Returns the parser context or NULL in case of error |
| 10758 | */ |
| 10759 | xmlSchemaParserCtxtPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10760 | xmlSchemaNewParserCtxt(const char *URL) |
| 10761 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10762 | xmlSchemaParserCtxtPtr ret; |
| 10763 | |
| 10764 | if (URL == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10765 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10766 | |
| 10767 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 10768 | if (ret == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10769 | xmlSchemaPErrMemory(NULL, "allocating schema parser context", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10770 | NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10771 | return (NULL); |
| 10772 | } |
| 10773 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10774 | ret->type = XML_SCHEMA_CTXT_PARSER; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 10775 | ret->dict = xmlDictCreate(); |
| 10776 | ret->URL = xmlDictLookup(ret->dict, (const xmlChar *) URL, -1); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 10777 | ret->includes = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10778 | return (ret); |
| 10779 | } |
| 10780 | |
| 10781 | /** |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 10782 | * xmlSchemaNewMemParserCtxt: |
| 10783 | * @buffer: a pointer to a char array containing the schemas |
| 10784 | * @size: the size of the array |
| 10785 | * |
| 10786 | * Create an XML Schemas parse context for that memory buffer expected |
| 10787 | * to contain an XML Schemas file. |
| 10788 | * |
| 10789 | * Returns the parser context or NULL in case of error |
| 10790 | */ |
| 10791 | xmlSchemaParserCtxtPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10792 | xmlSchemaNewMemParserCtxt(const char *buffer, int size) |
| 10793 | { |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 10794 | xmlSchemaParserCtxtPtr ret; |
| 10795 | |
| 10796 | if ((buffer == NULL) || (size <= 0)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10797 | return (NULL); |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 10798 | |
| 10799 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 10800 | if (ret == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10801 | xmlSchemaPErrMemory(NULL, "allocating schema parser context", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10802 | NULL); |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 10803 | return (NULL); |
| 10804 | } |
| 10805 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
| 10806 | ret->buffer = buffer; |
| 10807 | ret->size = size; |
William M. Brack | cf9eadf | 2003-12-25 13:24:05 +0000 | [diff] [blame] | 10808 | ret->dict = xmlDictCreate(); |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 10809 | return (ret); |
| 10810 | } |
| 10811 | |
| 10812 | /** |
Daniel Veillard | 9d75150 | 2003-10-29 13:21:47 +0000 | [diff] [blame] | 10813 | * xmlSchemaNewDocParserCtxt: |
| 10814 | * @doc: a preparsed document tree |
| 10815 | * |
| 10816 | * Create an XML Schemas parse context for that document. |
| 10817 | * NB. The document may be modified during the parsing process. |
| 10818 | * |
| 10819 | * Returns the parser context or NULL in case of error |
| 10820 | */ |
| 10821 | xmlSchemaParserCtxtPtr |
| 10822 | xmlSchemaNewDocParserCtxt(xmlDocPtr doc) |
| 10823 | { |
| 10824 | xmlSchemaParserCtxtPtr ret; |
| 10825 | |
| 10826 | if (doc == NULL) |
| 10827 | return (NULL); |
| 10828 | |
| 10829 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 10830 | if (ret == NULL) { |
| 10831 | xmlSchemaPErrMemory(NULL, "allocating schema parser context", |
| 10832 | NULL); |
| 10833 | return (NULL); |
| 10834 | } |
| 10835 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
| 10836 | ret->doc = doc; |
William M. Brack | cf9eadf | 2003-12-25 13:24:05 +0000 | [diff] [blame] | 10837 | ret->dict = xmlDictCreate(); |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 10838 | /* The application has responsibility for the document */ |
| 10839 | ret->preserve = 1; |
Daniel Veillard | 9d75150 | 2003-10-29 13:21:47 +0000 | [diff] [blame] | 10840 | |
| 10841 | return (ret); |
| 10842 | } |
| 10843 | |
| 10844 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10845 | * xmlSchemaFreeParserCtxt: |
| 10846 | * @ctxt: the schema parser context |
| 10847 | * |
| 10848 | * Free the resources associated to the schema parser context |
| 10849 | */ |
| 10850 | void |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10851 | xmlSchemaFreeParserCtxt(xmlSchemaParserCtxtPtr ctxt) |
| 10852 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10853 | if (ctxt == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10854 | return; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 10855 | if (ctxt->doc != NULL && !ctxt->preserve) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10856 | xmlFreeDoc(ctxt->doc); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10857 | if (ctxt->assemble != NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10858 | xmlFree((xmlSchemaTypePtr *) ctxt->assemble->items); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10859 | xmlFree(ctxt->assemble); |
| 10860 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10861 | if (ctxt->vctxt != NULL) { |
| 10862 | xmlSchemaFreeValidCtxt(ctxt->vctxt); |
| 10863 | } |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 10864 | if (ctxt->localImports != NULL) |
| 10865 | xmlFree((xmlChar *) ctxt->localImports); |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10866 | if (ctxt->substGroups != NULL) |
| 10867 | xmlHashFree(ctxt->substGroups, |
| 10868 | (xmlHashDeallocator) xmlSchemaFreeSubstGroup); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 10869 | xmlDictFree(ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10870 | xmlFree(ctxt); |
| 10871 | } |
| 10872 | |
| 10873 | /************************************************************************ |
| 10874 | * * |
| 10875 | * Building the content models * |
| 10876 | * * |
| 10877 | ************************************************************************/ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10878 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10879 | static void |
| 10880 | xmlSchemaBuildContentModelForSubstGroup(xmlSchemaParserCtxtPtr pctxt, |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 10881 | xmlSchemaParticlePtr particle) |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10882 | { |
| 10883 | xmlAutomataStatePtr start; |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 10884 | xmlSchemaElementPtr elemDecl, member; |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10885 | xmlAutomataStatePtr end; |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 10886 | xmlSchemaSubstGroupPtr substGroup; |
| 10887 | int i; |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10888 | |
| 10889 | elemDecl = (xmlSchemaElementPtr) particle->children; |
| 10890 | /* |
| 10891 | * Wrap the substitution group with a CHOICE. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10892 | */ |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10893 | start = pctxt->state; |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 10894 | end = xmlAutomataNewState(pctxt->am); |
| 10895 | substGroup = xmlSchemaGetElementSubstitutionGroup(pctxt, elemDecl); |
| 10896 | if (substGroup == NULL) { |
| 10897 | xmlSchemaPErr(pctxt, GET_NODE(particle), |
| 10898 | XML_SCHEMAP_INTERNAL, |
| 10899 | "Internal error: xmlSchemaBuildContentModelForSubstGroup, " |
| 10900 | "declaration is marked having a subst. group but none " |
| 10901 | "available.\n", elemDecl->name, NULL); |
| 10902 | return; |
| 10903 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10904 | if (particle->maxOccurs == 1) { |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10905 | /* |
| 10906 | * NOTE that we put the declaration in, even if it's abstract, |
| 10907 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10908 | xmlAutomataNewEpsilon(pctxt->am, |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10909 | xmlAutomataNewTransition2(pctxt->am, |
| 10910 | start, NULL, |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 10911 | elemDecl->name, elemDecl->targetNamespace, elemDecl), end); |
| 10912 | /* |
| 10913 | * Add subst. group members. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10914 | */ |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 10915 | for (i = 0; i < substGroup->members->nbItems; i++) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10916 | member = (xmlSchemaElementPtr) substGroup->members->items[i]; |
| 10917 | xmlAutomataNewEpsilon(pctxt->am, |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 10918 | xmlAutomataNewTransition2(pctxt->am, |
| 10919 | start, NULL, |
| 10920 | member->name, member->targetNamespace, member), |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10921 | end); |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 10922 | } |
| 10923 | } else { |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10924 | int counter; |
| 10925 | xmlAutomataStatePtr hop; |
| 10926 | int maxOccurs = particle->maxOccurs == UNBOUNDED ? |
| 10927 | UNBOUNDED : particle->maxOccurs - 1; |
| 10928 | int minOccurs = particle->minOccurs < 1 ? 0 : particle->minOccurs - 1; |
| 10929 | |
| 10930 | counter = |
| 10931 | xmlAutomataNewCounter(pctxt->am, minOccurs, |
| 10932 | maxOccurs); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10933 | hop = xmlAutomataNewState(pctxt->am); |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10934 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10935 | xmlAutomataNewEpsilon(pctxt->am, |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10936 | xmlAutomataNewTransition2(pctxt->am, |
| 10937 | start, NULL, |
| 10938 | elemDecl->name, elemDecl->targetNamespace, elemDecl), |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 10939 | hop); |
| 10940 | /* |
| 10941 | * Add subst. group members. |
| 10942 | */ |
| 10943 | for (i = 0; i < substGroup->members->nbItems; i++) { |
| 10944 | member = (xmlSchemaElementPtr) substGroup->members->items[i]; |
| 10945 | xmlAutomataNewEpsilon(pctxt->am, |
| 10946 | xmlAutomataNewTransition2(pctxt->am, |
| 10947 | start, NULL, |
| 10948 | member->name, member->targetNamespace, member), |
| 10949 | hop); |
| 10950 | } |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10951 | xmlAutomataNewCountedTrans(pctxt->am, hop, start, counter); |
| 10952 | xmlAutomataNewCounterTrans(pctxt->am, hop, end, counter); |
| 10953 | } |
| 10954 | if (particle->minOccurs == 0) |
| 10955 | xmlAutomataNewEpsilon(pctxt->am, start, end); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10956 | pctxt->state = end; |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10957 | } |
| 10958 | |
| 10959 | static void |
| 10960 | xmlSchemaBuildContentModelForElement(xmlSchemaParserCtxtPtr ctxt, |
| 10961 | xmlSchemaParticlePtr particle) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10962 | { |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 10963 | if (((xmlSchemaElementPtr) particle->children)->flags & |
| 10964 | XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD) { |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10965 | /* |
| 10966 | * Substitution groups. |
| 10967 | */ |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 10968 | xmlSchemaBuildContentModelForSubstGroup(ctxt, particle); |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10969 | } else { |
| 10970 | xmlSchemaElementPtr elemDecl; |
| 10971 | xmlAutomataStatePtr start; |
| 10972 | |
| 10973 | elemDecl = (xmlSchemaElementPtr) particle->children; |
| 10974 | |
| 10975 | if (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10976 | return; |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10977 | if (particle->maxOccurs == 1) { |
| 10978 | start = ctxt->state; |
| 10979 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, start, NULL, |
| 10980 | elemDecl->name, elemDecl->targetNamespace, elemDecl); |
| 10981 | } else if ((particle->maxOccurs >= UNBOUNDED) && (particle->minOccurs < 2)) { |
| 10982 | /* Special case. */ |
| 10983 | start = ctxt->state; |
| 10984 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, start, NULL, |
| 10985 | elemDecl->name, elemDecl->targetNamespace, elemDecl); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10986 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, start); |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10987 | } else { |
| 10988 | int counter; |
| 10989 | int maxOccurs = particle->maxOccurs == UNBOUNDED ? |
| 10990 | UNBOUNDED : particle->maxOccurs - 1; |
| 10991 | int minOccurs = particle->minOccurs < 1 ? |
| 10992 | 0 : particle->minOccurs - 1; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 10993 | |
| 10994 | start = xmlAutomataNewEpsilon(ctxt->am, ctxt->state, NULL); |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 10995 | counter = xmlAutomataNewCounter(ctxt->am, minOccurs, maxOccurs); |
| 10996 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, start, NULL, |
| 10997 | elemDecl->name, elemDecl->targetNamespace, elemDecl); |
| 10998 | xmlAutomataNewCountedTrans(ctxt->am, ctxt->state, start, counter); |
| 10999 | ctxt->state = xmlAutomataNewCounterTrans(ctxt->am, ctxt->state, |
| 11000 | NULL, counter); |
| 11001 | } |
| 11002 | if (particle->minOccurs == 0) |
| 11003 | xmlAutomataNewEpsilon(ctxt->am, start, ctxt->state); |
| 11004 | } |
| 11005 | } |
| 11006 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11007 | /** |
| 11008 | * xmlSchemaBuildAContentModel: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11009 | * @ctxt: the schema parser context |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11010 | * @particle: the particle component |
| 11011 | * @name: the complex type's name whose content is being built |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11012 | * |
| 11013 | * Generate the automata sequence needed for that type |
| 11014 | */ |
| 11015 | static void |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11016 | xmlSchemaBuildAContentModel(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11017 | xmlSchemaParticlePtr particle, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11018 | const xmlChar * name) |
| 11019 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11020 | if (particle == NULL) { |
| 11021 | xmlSchemaPErr(ctxt, NULL, |
| 11022 | XML_SCHEMAP_INTERNAL, |
| 11023 | "Internal error: xmlSchemaBuildAContentModel, " |
| 11024 | "particle is NULL.\n", NULL, NULL); |
| 11025 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11026 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11027 | if (particle->children == NULL) { |
| 11028 | xmlSchemaPErr(ctxt, GET_NODE(particle), |
| 11029 | XML_SCHEMAP_INTERNAL, |
| 11030 | "Internal error: xmlSchemaBuildAContentModel, " |
| 11031 | "no term on particle.\n", NULL, NULL); |
| 11032 | return; |
| 11033 | } |
| 11034 | |
| 11035 | switch (particle->children->type) { |
| 11036 | case XML_SCHEMA_TYPE_ANY: { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11037 | xmlAutomataStatePtr start, end; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11038 | xmlSchemaWildcardPtr wild; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11039 | xmlSchemaWildcardNsPtr ns; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 11040 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11041 | wild = (xmlSchemaWildcardPtr) particle->children; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11042 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11043 | start = ctxt->state; |
| 11044 | end = xmlAutomataNewState(ctxt->am); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11045 | |
| 11046 | if (particle->maxOccurs == 1) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11047 | if (wild->any == 1) { |
| 11048 | /* |
| 11049 | * We need to add both transitions: |
| 11050 | * |
| 11051 | * 1. the {"*", "*"} for elements in a namespace. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11052 | */ |
| 11053 | ctxt->state = |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11054 | xmlAutomataNewTransition2(ctxt->am, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11055 | start, NULL, BAD_CAST "*", BAD_CAST "*", wild); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11056 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 11057 | /* |
| 11058 | * 2. the {"*"} for elements in no namespace. |
| 11059 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11060 | ctxt->state = |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11061 | xmlAutomataNewTransition2(ctxt->am, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11062 | start, NULL, BAD_CAST "*", NULL, wild); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11063 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 11064 | |
| 11065 | } else if (wild->nsSet != NULL) { |
| 11066 | ns = wild->nsSet; |
| 11067 | do { |
| 11068 | ctxt->state = start; |
| 11069 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11070 | ctxt->state, NULL, BAD_CAST "*", ns->value, wild); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11071 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 11072 | ns = ns->next; |
| 11073 | } while (ns != NULL); |
| 11074 | |
| 11075 | } else if (wild->negNsSet != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11076 | |
Kasimier T. Buchcik | c0e833f | 2005-04-19 15:02:20 +0000 | [diff] [blame] | 11077 | /* |
| 11078 | * Lead nodes with the negated namespace to the sink-state |
| 11079 | * {"*", "##other"}. |
| 11080 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11081 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, start, NULL, |
Kasimier T. Buchcik | c0e833f | 2005-04-19 15:02:20 +0000 | [diff] [blame] | 11082 | BAD_CAST "*", wild->negNsSet->value, wild); |
Kasimier T. Buchcik | c0e833f | 2005-04-19 15:02:20 +0000 | [diff] [blame] | 11083 | /* |
| 11084 | * Open a door for nodes with any other namespace |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11085 | * {"*", "*"} |
Kasimier T. Buchcik | c0e833f | 2005-04-19 15:02:20 +0000 | [diff] [blame] | 11086 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11087 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11088 | start, NULL, BAD_CAST "*", BAD_CAST "*", wild); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11089 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11090 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11091 | } else { |
| 11092 | int counter; |
| 11093 | xmlAutomataStatePtr hop; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11094 | int maxOccurs = |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11095 | particle->maxOccurs == UNBOUNDED ? UNBOUNDED : particle->maxOccurs - 1; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11096 | int minOccurs = |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11097 | particle->minOccurs < 1 ? 0 : particle->minOccurs - 1; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11098 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11099 | counter = xmlAutomataNewCounter(ctxt->am, minOccurs, maxOccurs); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11100 | hop = xmlAutomataNewState(ctxt->am); |
| 11101 | if (wild->any == 1) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11102 | ctxt->state = |
| 11103 | xmlAutomataNewTransition2(ctxt->am, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11104 | start, NULL, BAD_CAST "*", BAD_CAST "*", wild); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11105 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11106 | ctxt->state = |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11107 | xmlAutomataNewTransition2(ctxt->am, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11108 | start, NULL, BAD_CAST "*", NULL, wild); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11109 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11110 | } else if (wild->nsSet != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11111 | ns = wild->nsSet; |
| 11112 | do { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11113 | ctxt->state = |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11114 | xmlAutomataNewTransition2(ctxt->am, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11115 | start, NULL, BAD_CAST "*", ns->value, wild); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11116 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 11117 | ns = ns->next; |
| 11118 | } while (ns != NULL); |
| 11119 | |
| 11120 | } else if (wild->negNsSet != NULL) { |
| 11121 | xmlAutomataStatePtr deadEnd; |
| 11122 | |
| 11123 | deadEnd = xmlAutomataNewState(ctxt->am); |
| 11124 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11125 | start, deadEnd, BAD_CAST "*", wild->negNsSet->value, wild); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11126 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11127 | start, NULL, BAD_CAST "*", BAD_CAST "*", wild); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11128 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11129 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11130 | xmlAutomataNewCountedTrans(ctxt->am, hop, start, counter); |
| 11131 | xmlAutomataNewCounterTrans(ctxt->am, hop, end, counter); |
| 11132 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11133 | if (particle->minOccurs == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11134 | xmlAutomataNewEpsilon(ctxt->am, start, end); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11135 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11136 | ctxt->state = end; |
| 11137 | break; |
| 11138 | } |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 11139 | case XML_SCHEMA_TYPE_ELEMENT: |
| 11140 | xmlSchemaBuildContentModelForElement(ctxt, particle); |
| 11141 | break; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11142 | case XML_SCHEMA_TYPE_SEQUENCE:{ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11143 | xmlSchemaTreeItemPtr sub; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 11144 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11145 | /* |
| 11146 | * If max and min occurances are default (1) then |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11147 | * simply iterate over the particles of the <sequence>. |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11148 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11149 | if ((particle->minOccurs == 1) && (particle->maxOccurs == 1)) { |
| 11150 | sub = particle->children->children; |
| 11151 | while (sub != NULL) { |
| 11152 | xmlSchemaBuildAContentModel(ctxt, |
| 11153 | (xmlSchemaParticlePtr) sub, name); |
| 11154 | sub = sub->next; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11155 | } |
| 11156 | } else { |
| 11157 | xmlAutomataStatePtr oldstate = ctxt->state; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 11158 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11159 | if (particle->maxOccurs >= UNBOUNDED) { |
| 11160 | if (particle->minOccurs > 1) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11161 | xmlAutomataStatePtr tmp; |
| 11162 | int counter; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 11163 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11164 | ctxt->state = xmlAutomataNewEpsilon(ctxt->am, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11165 | oldstate, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11166 | oldstate = ctxt->state; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 11167 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11168 | counter = xmlAutomataNewCounter(ctxt->am, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11169 | particle->minOccurs - 1, UNBOUNDED); |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 11170 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11171 | sub = particle->children->children; |
| 11172 | while (sub != NULL) { |
| 11173 | xmlSchemaBuildAContentModel(ctxt, |
| 11174 | (xmlSchemaParticlePtr) sub, name); |
| 11175 | sub = sub->next; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11176 | } |
| 11177 | tmp = ctxt->state; |
| 11178 | xmlAutomataNewCountedTrans(ctxt->am, tmp, |
| 11179 | oldstate, counter); |
| 11180 | ctxt->state = |
| 11181 | xmlAutomataNewCounterTrans(ctxt->am, tmp, |
| 11182 | NULL, counter); |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 11183 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11184 | } else { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11185 | sub = particle->children->children; |
| 11186 | while (sub != NULL) { |
| 11187 | xmlSchemaBuildAContentModel(ctxt, |
| 11188 | (xmlSchemaParticlePtr) sub, name); |
| 11189 | sub = sub->next; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11190 | } |
| 11191 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, |
| 11192 | oldstate); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11193 | if (particle->minOccurs == 0) { |
| 11194 | xmlAutomataNewEpsilon(ctxt->am, |
| 11195 | oldstate, ctxt->state); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11196 | } |
| 11197 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11198 | } else if ((particle->maxOccurs > 1) |
| 11199 | || (particle->minOccurs > 1)) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11200 | xmlAutomataStatePtr tmp; |
| 11201 | int counter; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 11202 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11203 | ctxt->state = xmlAutomataNewEpsilon(ctxt->am, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11204 | oldstate, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11205 | oldstate = ctxt->state; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11206 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11207 | counter = xmlAutomataNewCounter(ctxt->am, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11208 | particle->minOccurs - 1, |
| 11209 | particle->maxOccurs - 1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11210 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11211 | sub = particle->children->children; |
| 11212 | while (sub != NULL) { |
| 11213 | xmlSchemaBuildAContentModel(ctxt, |
| 11214 | (xmlSchemaParticlePtr) sub, name); |
| 11215 | sub = sub->next; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11216 | } |
| 11217 | tmp = ctxt->state; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11218 | xmlAutomataNewCountedTrans(ctxt->am, |
| 11219 | tmp, oldstate, counter); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11220 | ctxt->state = |
| 11221 | xmlAutomataNewCounterTrans(ctxt->am, tmp, NULL, |
| 11222 | counter); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11223 | if (particle->minOccurs == 0) { |
| 11224 | xmlAutomataNewEpsilon(ctxt->am, |
| 11225 | oldstate, ctxt->state); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11226 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11227 | } else { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11228 | sub = particle->children->children; |
| 11229 | while (sub != NULL) { |
| 11230 | xmlSchemaBuildAContentModel(ctxt, |
| 11231 | (xmlSchemaParticlePtr) sub, name); |
| 11232 | sub = sub->next; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11233 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11234 | if (particle->minOccurs == 0) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11235 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
| 11236 | ctxt->state); |
| 11237 | } |
| 11238 | } |
| 11239 | } |
| 11240 | break; |
| 11241 | } |
| 11242 | case XML_SCHEMA_TYPE_CHOICE:{ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11243 | xmlSchemaTreeItemPtr sub; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11244 | xmlAutomataStatePtr start, end; |
Daniel Veillard | b509f15 | 2002-04-17 16:28:10 +0000 | [diff] [blame] | 11245 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11246 | start = ctxt->state; |
| 11247 | end = xmlAutomataNewState(ctxt->am); |
Daniel Veillard | 7646b18 | 2002-04-20 06:41:40 +0000 | [diff] [blame] | 11248 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11249 | /* |
| 11250 | * iterate over the subtypes and remerge the end with an |
| 11251 | * epsilon transition |
| 11252 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11253 | if (particle->maxOccurs == 1) { |
| 11254 | sub = particle->children->children; |
| 11255 | while (sub != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11256 | ctxt->state = start; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11257 | xmlSchemaBuildAContentModel(ctxt, |
| 11258 | (xmlSchemaParticlePtr) sub, name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11259 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11260 | sub = sub->next; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11261 | } |
| 11262 | } else { |
| 11263 | int counter; |
| 11264 | xmlAutomataStatePtr hop; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11265 | int maxOccurs = particle->maxOccurs == UNBOUNDED ? |
| 11266 | UNBOUNDED : particle->maxOccurs - 1; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11267 | int minOccurs = |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11268 | particle->minOccurs < 1 ? 0 : particle->minOccurs - 1; |
Daniel Veillard | 7646b18 | 2002-04-20 06:41:40 +0000 | [diff] [blame] | 11269 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11270 | /* |
| 11271 | * use a counter to keep track of the number of transtions |
| 11272 | * which went through the choice. |
| 11273 | */ |
| 11274 | counter = |
| 11275 | xmlAutomataNewCounter(ctxt->am, minOccurs, |
| 11276 | maxOccurs); |
| 11277 | hop = xmlAutomataNewState(ctxt->am); |
Daniel Veillard | 6231e84 | 2002-04-18 11:54:04 +0000 | [diff] [blame] | 11278 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11279 | sub = particle->children->children; |
| 11280 | while (sub != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11281 | ctxt->state = start; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11282 | xmlSchemaBuildAContentModel(ctxt, |
| 11283 | (xmlSchemaParticlePtr) sub, name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11284 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11285 | sub = sub->next; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11286 | } |
| 11287 | xmlAutomataNewCountedTrans(ctxt->am, hop, start, |
| 11288 | counter); |
| 11289 | xmlAutomataNewCounterTrans(ctxt->am, hop, end, |
| 11290 | counter); |
| 11291 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11292 | if (particle->minOccurs == 0) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11293 | xmlAutomataNewEpsilon(ctxt->am, start, end); |
| 11294 | } |
| 11295 | ctxt->state = end; |
| 11296 | break; |
| 11297 | } |
| 11298 | case XML_SCHEMA_TYPE_ALL:{ |
| 11299 | xmlAutomataStatePtr start; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11300 | xmlSchemaParticlePtr sub; |
| 11301 | xmlSchemaElementPtr elemDecl; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11302 | int lax; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11303 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11304 | sub = (xmlSchemaParticlePtr) particle->children->children; |
| 11305 | if (sub == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11306 | break; |
| 11307 | start = ctxt->state; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11308 | while (sub != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11309 | ctxt->state = start; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11310 | |
| 11311 | elemDecl = (xmlSchemaElementPtr) sub->children; |
| 11312 | if (elemDecl == NULL) { |
| 11313 | xmlSchemaPErr(ctxt, NULL, |
| 11314 | XML_SCHEMAP_INTERNAL, |
| 11315 | "Internal error: xmlSchemaBuildAContentModel, " |
| 11316 | "<element> particle a NULL term.\n", NULL, NULL); |
| 11317 | return; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11318 | }; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11319 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11320 | * NOTE: The {max occurs} of all the particles in the |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 11321 | * {particles} of the group must be 0 or 1; this is |
| 11322 | * already ensured during the parse of the content of |
| 11323 | * <all>. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11324 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11325 | if ((sub->minOccurs == 1) && |
| 11326 | (sub->maxOccurs == 1)) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11327 | xmlAutomataNewOnceTrans2(ctxt->am, ctxt->state, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11328 | ctxt->state, |
| 11329 | elemDecl->name, |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 11330 | elemDecl->targetNamespace, |
| 11331 | 1, 1, elemDecl); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11332 | } else if ((sub->minOccurs == 0) && |
| 11333 | (sub->maxOccurs == 1)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11334 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11335 | xmlAutomataNewCountTrans2(ctxt->am, ctxt->state, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11336 | ctxt->state, |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 11337 | elemDecl->name, |
| 11338 | elemDecl->targetNamespace, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11339 | 0, |
| 11340 | 1, |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 11341 | elemDecl); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11342 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11343 | sub = (xmlSchemaParticlePtr) sub->next; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11344 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11345 | lax = particle->minOccurs == 0; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11346 | ctxt->state = |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11347 | xmlAutomataNewAllTrans(ctxt->am, ctxt->state, NULL, lax); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11348 | break; |
| 11349 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11350 | default: |
| 11351 | xmlGenericError(xmlGenericErrorContext, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11352 | "Internal error: xmlSchemaBuildAContentModel, found " |
| 11353 | "unexpected term of type %d in content model of complex " |
| 11354 | "type '%s'.\n", |
| 11355 | particle->children->type, name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11356 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11357 | } |
| 11358 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11359 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11360 | /** |
| 11361 | * xmlSchemaBuildContentModel: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11362 | * @ctxt: the schema parser context |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11363 | * @type: the complex type definition |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 11364 | * @name: the element name |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11365 | * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11366 | * Builds the content model of the complex type. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11367 | */ |
| 11368 | static void |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11369 | xmlSchemaBuildContentModel(xmlSchemaTypePtr type, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11370 | xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11371 | const xmlChar * name) |
| 11372 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11373 | xmlAutomataStatePtr start; |
| 11374 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11375 | if ((type->type != XML_SCHEMA_TYPE_COMPLEX) || |
| 11376 | (type->contModel != NULL) || |
| 11377 | ((type->contentType != XML_SCHEMA_CONTENT_ELEMENTS) && |
| 11378 | (type->contentType != XML_SCHEMA_CONTENT_MIXED))) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11379 | return; |
Daniel Veillard | decd64d | 2002-04-18 14:41:51 +0000 | [diff] [blame] | 11380 | |
| 11381 | #ifdef DEBUG_CONTENT |
| 11382 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11383 | "Building content model for %s\n", name); |
Daniel Veillard | decd64d | 2002-04-18 14:41:51 +0000 | [diff] [blame] | 11384 | #endif |
| 11385 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11386 | ctxt->am = xmlNewAutomata(); |
| 11387 | if (ctxt->am == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11388 | xmlGenericError(xmlGenericErrorContext, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11389 | "Cannot create automata for complex type %s\n", name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11390 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11391 | } |
| 11392 | start = ctxt->state = xmlAutomataGetInitState(ctxt->am); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11393 | xmlSchemaBuildAContentModel(ctxt, (xmlSchemaParticlePtr) type->subtypes, name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11394 | xmlAutomataSetFinalState(ctxt->am, ctxt->state); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11395 | type->contModel = xmlAutomataCompile(ctxt->am); |
| 11396 | if (type->contModel == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11397 | xmlSchemaPCustomErr(ctxt, |
| 11398 | XML_SCHEMAP_INTERNAL, |
| 11399 | NULL, type, type->node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11400 | "Failed to compile the content model", NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11401 | } else if (xmlRegexpIsDeterminist(type->contModel) != 1) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11402 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 11403 | XML_SCHEMAP_NOT_DETERMINISTIC, |
| 11404 | /* XML_SCHEMAS_ERR_NOTDETERMINIST, */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11405 | NULL, type, type->node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11406 | "The content model is not determinist", NULL); |
Daniel Veillard | e19fc23 | 2002-04-22 16:01:24 +0000 | [diff] [blame] | 11407 | } else { |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 11408 | #ifdef DEBUG_CONTENT_REGEXP |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11409 | xmlGenericError(xmlGenericErrorContext, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11410 | "Content model of %s:\n", type->name); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11411 | xmlRegexpPrint(stderr, type->contModel); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11412 | #endif |
Daniel Veillard | e19fc23 | 2002-04-22 16:01:24 +0000 | [diff] [blame] | 11413 | } |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 11414 | ctxt->state = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11415 | xmlFreeAutomata(ctxt->am); |
| 11416 | ctxt->am = NULL; |
| 11417 | } |
| 11418 | |
| 11419 | /** |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11420 | * xmlSchemaElementFixup: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11421 | * @elem: the schema element context |
| 11422 | * @ctxt: the schema parser context |
| 11423 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11424 | * Resolves the references of an element declaration |
| 11425 | * or particle, which has an element declaration as it's |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11426 | * term. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11427 | */ |
| 11428 | static void |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 11429 | xmlSchemaElementFixup(xmlSchemaElementPtr elemDecl, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11430 | xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11431 | const xmlChar * name ATTRIBUTE_UNUSED, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11432 | const xmlChar * context ATTRIBUTE_UNUSED, |
| 11433 | const xmlChar * namespace ATTRIBUTE_UNUSED) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11434 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11435 | if ((ctxt == NULL) || (elemDecl == NULL) || |
| 11436 | ((elemDecl != NULL) && |
| 11437 | (elemDecl->flags & XML_SCHEMAS_ELEM_INTERNAL_RESOLVED))) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 11438 | return; |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 11439 | elemDecl->flags |= XML_SCHEMAS_ELEM_INTERNAL_RESOLVED; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11440 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 11441 | if ((elemDecl->subtypes == NULL) && (elemDecl->namedType != NULL)) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11442 | xmlSchemaTypePtr type; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11443 | |
| 11444 | /* (type definition) ... otherwise the type definition ·resolved· |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11445 | * to by the ·actual value· of the type [attribute] ... |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11446 | */ |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 11447 | type = xmlSchemaGetType(ctxt->schema, elemDecl->namedType, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11448 | elemDecl->namedTypeNs); |
| 11449 | if (type == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11450 | xmlSchemaPResCompAttrErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11451 | XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11452 | (xmlSchemaTypePtr) elemDecl, elemDecl->node, |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 11453 | "type", elemDecl->namedType, elemDecl->namedTypeNs, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11454 | XML_SCHEMA_TYPE_BASIC, "type definition"); |
| 11455 | } else |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 11456 | elemDecl->subtypes = type; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11457 | } |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 11458 | if (elemDecl->substGroup != NULL) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11459 | xmlSchemaElementPtr substHead; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11460 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11461 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11462 | * FIXME TODO: Do we need a new field in _xmlSchemaElement for |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11463 | * substitutionGroup? |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11464 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11465 | substHead = xmlSchemaGetElem(ctxt->schema, elemDecl->substGroup, |
| 11466 | elemDecl->substGroupNs); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11467 | if (substHead == NULL) { |
| 11468 | xmlSchemaPResCompAttrErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11469 | XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11470 | (xmlSchemaTypePtr) elemDecl, NULL, |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 11471 | "substitutionGroup", elemDecl->substGroup, |
| 11472 | elemDecl->substGroupNs, XML_SCHEMA_TYPE_ELEMENT, NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11473 | } else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11474 | xmlSchemaElementFixup(substHead, ctxt, NULL, NULL, NULL); |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 11475 | /* |
| 11476 | * Set the "substitution group affiliation". |
| 11477 | * NOTE that now we use the "refDecl" field for this. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11478 | */ |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 11479 | elemDecl->refDecl = substHead; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11480 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11481 | * (type definition)...otherwise the {type definition} of the |
| 11482 | * element declaration ·resolved· to by the ·actual value· of |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11483 | * the substitutionGroup [attribute], if present |
| 11484 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11485 | if (elemDecl->subtypes == NULL) |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 11486 | elemDecl->subtypes = substHead->subtypes; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11487 | } |
| 11488 | } |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 11489 | if ((elemDecl->subtypes == NULL) && (elemDecl->namedType == NULL) && |
| 11490 | (elemDecl->substGroup == NULL)) |
| 11491 | elemDecl->subtypes = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 11492 | } |
| 11493 | |
| 11494 | /** |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11495 | * xmlSchemaResolveUnionMemberTypes: |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 11496 | * @ctxt: the schema parser context |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11497 | * @type: the schema simple type definition |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 11498 | * |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 11499 | * Checks and builds the "member type definitions" property of the union |
| 11500 | * simple type. This handles part (1), part (2) is done in |
| 11501 | * xmlSchemaFinishMemberTypeDefinitionsProperty() |
| 11502 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11503 | * Returns -1 in case of an internal error, 0 otherwise. |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 11504 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11505 | static int |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11506 | xmlSchemaResolveUnionMemberTypes(xmlSchemaParserCtxtPtr ctxt, |
| 11507 | xmlSchemaTypePtr type) |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 11508 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11509 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 11510 | xmlSchemaTypeLinkPtr link, lastLink, newLink; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11511 | xmlSchemaTypePtr memberType; |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 11512 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11513 | /* |
| 11514 | * SPEC (1) "If the <union> alternative is chosen, then [Definition:] |
| 11515 | * define the explicit members as the type definitions ·resolved· |
| 11516 | * to by the items in the ·actual value· of the memberTypes [attribute], |
| 11517 | * if any, followed by the type definitions corresponding to the |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 11518 | * <simpleType>s among the [children] of <union>, if any." |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11519 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11520 | /* |
| 11521 | * Resolve references. |
| 11522 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11523 | link = type->memberTypes; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11524 | lastLink = NULL; |
| 11525 | while (link != NULL) { |
| 11526 | const xmlChar *name, *nsName; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11527 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11528 | name = ((xmlSchemaQNameRefPtr) link->type)->name; |
| 11529 | nsName = ((xmlSchemaQNameRefPtr) link->type)->targetNamespace; |
| 11530 | |
| 11531 | memberType = xmlSchemaGetType(ctxt->schema, name, nsName); |
| 11532 | if ((memberType == NULL) || (! IS_SIMPLE_TYPE(memberType))) { |
| 11533 | xmlSchemaPResCompAttrErr(ctxt, XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11534 | type, type->node, "memberTypes", |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11535 | name, nsName, XML_SCHEMA_TYPE_SIMPLE, NULL); |
| 11536 | /* |
| 11537 | * Remove the member type link. |
| 11538 | */ |
| 11539 | if (lastLink == NULL) |
| 11540 | type->memberTypes = link->next; |
| 11541 | else |
| 11542 | lastLink->next = link->next; |
| 11543 | newLink = link; |
| 11544 | link = link->next; |
| 11545 | xmlFree(newLink); |
| 11546 | } else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11547 | link->type = memberType; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 11548 | lastLink = link; |
| 11549 | link = link->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11550 | } |
| 11551 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11552 | /* |
| 11553 | * Add local simple types, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11554 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11555 | memberType = type->subtypes; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11556 | while (memberType != NULL) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11557 | link = (xmlSchemaTypeLinkPtr) xmlMalloc(sizeof(xmlSchemaTypeLink)); |
| 11558 | if (link == NULL) { |
| 11559 | xmlSchemaPErrMemory(ctxt, "allocating a type link", NULL); |
| 11560 | return (-1); |
| 11561 | } |
| 11562 | link->type = memberType; |
| 11563 | link->next = NULL; |
| 11564 | if (lastLink == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11565 | type->memberTypes = link; |
| 11566 | else |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11567 | lastLink->next = link; |
| 11568 | lastLink = link; |
| 11569 | memberType = memberType->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11570 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11571 | return (0); |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 11572 | } |
| 11573 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 11574 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11575 | * xmlSchemaIsDerivedFromBuiltInType: |
| 11576 | * @ctxt: the schema parser context |
| 11577 | * @type: the type definition |
| 11578 | * @valType: the value type |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11579 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11580 | * |
| 11581 | * Returns 1 if the type has the given value type, or |
| 11582 | * is derived from such a type. |
| 11583 | */ |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 11584 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11585 | xmlSchemaIsDerivedFromBuiltInType(xmlSchemaTypePtr type, int valType) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11586 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11587 | if (type == NULL) |
| 11588 | return (0); |
| 11589 | if (IS_COMPLEX_TYPE(type)) |
| 11590 | return (0); |
| 11591 | if (type->type == XML_SCHEMA_TYPE_BASIC) { |
| 11592 | if (type->builtInType == valType) |
| 11593 | return(1); |
| 11594 | if ((type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) || |
| 11595 | (type->builtInType == XML_SCHEMAS_ANYTYPE)) |
| 11596 | return (0); |
| 11597 | return(xmlSchemaIsDerivedFromBuiltInType(type->subtypes, valType)); |
| 11598 | } else |
| 11599 | return(xmlSchemaIsDerivedFromBuiltInType(type->subtypes, valType)); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11600 | |
| 11601 | return (0); |
| 11602 | } |
| 11603 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11604 | #if 0 |
| 11605 | /** |
| 11606 | * xmlSchemaIsDerivedFromBuiltInType: |
| 11607 | * @ctxt: the schema parser context |
| 11608 | * @type: the type definition |
| 11609 | * @valType: the value type |
| 11610 | * |
| 11611 | * |
| 11612 | * Returns 1 if the type has the given value type, or |
| 11613 | * is derived from such a type. |
| 11614 | */ |
| 11615 | static int |
| 11616 | xmlSchemaIsUserDerivedFromBuiltInType(xmlSchemaTypePtr type, int valType) |
| 11617 | { |
| 11618 | if (type == NULL) |
| 11619 | return (0); |
| 11620 | if (IS_COMPLEX_TYPE(type)) |
| 11621 | return (0); |
| 11622 | if (type->type == XML_SCHEMA_TYPE_BASIC) { |
| 11623 | if (type->builtInType == valType) |
| 11624 | return(1); |
| 11625 | return (0); |
| 11626 | } else |
| 11627 | return(xmlSchemaIsDerivedFromBuiltInType(type->subtypes, valType)); |
| 11628 | |
| 11629 | return (0); |
| 11630 | } |
| 11631 | #endif |
| 11632 | |
| 11633 | static xmlSchemaTypePtr |
| 11634 | xmlSchemaQueryBuiltInType(xmlSchemaTypePtr type) |
| 11635 | { |
| 11636 | if (type == NULL) |
| 11637 | return (NULL); |
| 11638 | if (IS_COMPLEX_TYPE(type)) |
| 11639 | return (NULL); |
| 11640 | if (type->type == XML_SCHEMA_TYPE_BASIC) |
| 11641 | return(type); |
| 11642 | else |
| 11643 | return(xmlSchemaQueryBuiltInType(type->subtypes)); |
| 11644 | |
| 11645 | return (NULL); |
| 11646 | } |
| 11647 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11648 | /** |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 11649 | * xmlSchemaGetPrimitiveType: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11650 | * @type: the simpleType definition |
| 11651 | * |
| 11652 | * Returns the primitive type of the given type or |
| 11653 | * NULL in case of error. |
| 11654 | */ |
| 11655 | static xmlSchemaTypePtr |
| 11656 | xmlSchemaGetPrimitiveType(xmlSchemaTypePtr type) |
| 11657 | { |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 11658 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11659 | while (type != NULL) { |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 11660 | /* |
| 11661 | * Note that anySimpleType is actually not a primitive type |
| 11662 | * but we need that here. |
| 11663 | */ |
| 11664 | if ((type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) || |
| 11665 | (type->flags & XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE)) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11666 | return (type); |
| 11667 | type = type->baseType; |
| 11668 | } |
| 11669 | |
| 11670 | return (NULL); |
| 11671 | } |
| 11672 | |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 11673 | #if 0 |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 11674 | /** |
| 11675 | * xmlSchemaGetBuiltInTypeAncestor: |
| 11676 | * @type: the simpleType definition |
| 11677 | * |
| 11678 | * Returns the primitive type of the given type or |
| 11679 | * NULL in case of error. |
| 11680 | */ |
| 11681 | static xmlSchemaTypePtr |
| 11682 | xmlSchemaGetBuiltInTypeAncestor(xmlSchemaTypePtr type) |
| 11683 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11684 | if (VARIETY_LIST(type) || VARIETY_UNION(type)) |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 11685 | return (0); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 11686 | while (type != NULL) { |
| 11687 | if (type->type == XML_SCHEMA_TYPE_BASIC) |
| 11688 | return (type); |
| 11689 | type = type->baseType; |
| 11690 | } |
| 11691 | |
| 11692 | return (NULL); |
| 11693 | } |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 11694 | #endif |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 11695 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11696 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11697 | * xmlSchemaBuildAttributeUsesOwned: |
| 11698 | * @ctxt: the schema parser context |
| 11699 | * @type: the complex type definition |
| 11700 | * @cur: the attribute declaration list |
| 11701 | * @lastUse: the top of the attribute use list |
| 11702 | * |
| 11703 | * Builds the attribute uses list on the given complex type. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11704 | * This one is supposed to be called by |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11705 | * xmlSchemaBuildAttributeValidation only. |
| 11706 | */ |
| 11707 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11708 | xmlSchemaBuildAttributeUsesOwned(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11709 | xmlSchemaAttributePtr cur, |
| 11710 | xmlSchemaAttributeLinkPtr *uses, |
| 11711 | xmlSchemaAttributeLinkPtr *lastUse) |
| 11712 | { |
| 11713 | xmlSchemaAttributeLinkPtr tmp; |
| 11714 | while (cur != NULL) { |
| 11715 | if (cur->type == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11716 | /* |
| 11717 | * W3C: "2 The {attribute uses} of the attribute groups ·resolved· |
| 11718 | * to by the ·actual value·s of the ref [attribute] of the |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11719 | * <attributeGroup> [children], if any." |
| 11720 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11721 | if (xmlSchemaBuildAttributeUsesOwned(ctxt, |
| 11722 | ((xmlSchemaAttributeGroupPtr) cur)->attributes, uses, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11723 | lastUse) == -1) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11724 | return (-1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11725 | } |
| 11726 | } else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11727 | /* W3C: "1 The set of attribute uses corresponding to the |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11728 | * <attribute> [children], if any." |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11729 | */ |
| 11730 | tmp = (xmlSchemaAttributeLinkPtr) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11731 | xmlMalloc(sizeof(xmlSchemaAttributeLink)); |
| 11732 | if (tmp == NULL) { |
| 11733 | xmlSchemaPErrMemory(ctxt, "building attribute uses", NULL); |
| 11734 | return (-1); |
| 11735 | } |
| 11736 | tmp->attr = cur; |
| 11737 | tmp->next = NULL; |
| 11738 | if (*uses == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11739 | *uses = tmp; |
| 11740 | else |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11741 | (*lastUse)->next = tmp; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11742 | *lastUse = tmp; |
| 11743 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11744 | cur = cur->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11745 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11746 | return (0); |
| 11747 | } |
| 11748 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11749 | /** |
| 11750 | * xmlSchemaCloneWildcardNsConstraints: |
| 11751 | * @ctxt: the schema parser context |
| 11752 | * @dest: the destination wildcard |
| 11753 | * @source: the source wildcard |
| 11754 | * |
| 11755 | * Clones the namespace constraints of source |
| 11756 | * and assignes them to dest. |
| 11757 | * Returns -1 on internal error, 0 otherwise. |
| 11758 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11759 | static int |
| 11760 | xmlSchemaCloneWildcardNsConstraints(xmlSchemaParserCtxtPtr ctxt, |
| 11761 | xmlSchemaWildcardPtr *dest, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11762 | xmlSchemaWildcardPtr source) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11763 | { |
| 11764 | xmlSchemaWildcardNsPtr cur, tmp, last; |
| 11765 | |
| 11766 | if ((source == NULL) || (*dest == NULL)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11767 | return(-1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11768 | (*dest)->any = source->any; |
| 11769 | cur = source->nsSet; |
| 11770 | last = NULL; |
| 11771 | while (cur != NULL) { |
| 11772 | tmp = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 11773 | if (tmp == NULL) |
| 11774 | return(-1); |
| 11775 | tmp->value = cur->value; |
| 11776 | if (last == NULL) |
| 11777 | (*dest)->nsSet = tmp; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11778 | else |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11779 | last->next = tmp; |
| 11780 | last = tmp; |
| 11781 | cur = cur->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11782 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11783 | if ((*dest)->negNsSet != NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11784 | xmlSchemaFreeWildcardNsSet((*dest)->negNsSet); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11785 | if (source->negNsSet != NULL) { |
| 11786 | (*dest)->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 11787 | if ((*dest)->negNsSet == NULL) |
| 11788 | return(-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11789 | (*dest)->negNsSet->value = source->negNsSet->value; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11790 | } else |
| 11791 | (*dest)->negNsSet = NULL; |
| 11792 | return(0); |
| 11793 | } |
| 11794 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11795 | /** |
| 11796 | * xmlSchemaUnionWildcards: |
| 11797 | * @ctxt: the schema parser context |
| 11798 | * @completeWild: the first wildcard |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11799 | * @curWild: the second wildcard |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11800 | * |
| 11801 | * Unions the namespace constraints of the given wildcards. |
| 11802 | * @completeWild will hold the resulting union. |
| 11803 | * Returns a positive error code on failure, -1 in case of an |
| 11804 | * internal error, 0 otherwise. |
| 11805 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11806 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11807 | xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11808 | xmlSchemaWildcardPtr completeWild, |
| 11809 | xmlSchemaWildcardPtr curWild) |
| 11810 | { |
| 11811 | xmlSchemaWildcardNsPtr cur, curB, tmp; |
| 11812 | |
| 11813 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11814 | * 1 If O1 and O2 are the same value, then that value must be the |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11815 | * value. |
| 11816 | */ |
| 11817 | if ((completeWild->any == curWild->any) && |
| 11818 | ((completeWild->nsSet == NULL) == (curWild->nsSet == NULL)) && |
| 11819 | ((completeWild->negNsSet == NULL) == (curWild->negNsSet == NULL))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11820 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11821 | if ((completeWild->negNsSet == NULL) || |
| 11822 | (completeWild->negNsSet->value == curWild->negNsSet->value)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11823 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11824 | if (completeWild->nsSet != NULL) { |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 11825 | int found = 0; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11826 | |
| 11827 | /* |
| 11828 | * Check equality of sets. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11829 | */ |
| 11830 | cur = completeWild->nsSet; |
| 11831 | while (cur != NULL) { |
| 11832 | found = 0; |
| 11833 | curB = curWild->nsSet; |
| 11834 | while (curB != NULL) { |
| 11835 | if (cur->value == curB->value) { |
| 11836 | found = 1; |
| 11837 | break; |
| 11838 | } |
| 11839 | curB = curB->next; |
| 11840 | } |
| 11841 | if (!found) |
| 11842 | break; |
| 11843 | cur = cur->next; |
| 11844 | } |
| 11845 | if (found) |
| 11846 | return(0); |
| 11847 | } else |
| 11848 | return(0); |
| 11849 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11850 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11851 | /* |
| 11852 | * 2 If either O1 or O2 is any, then any must be the value |
| 11853 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11854 | if (completeWild->any != curWild->any) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11855 | if (completeWild->any == 0) { |
| 11856 | completeWild->any = 1; |
| 11857 | if (completeWild->nsSet != NULL) { |
| 11858 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 11859 | completeWild->nsSet = NULL; |
| 11860 | } |
| 11861 | if (completeWild->negNsSet != NULL) { |
| 11862 | xmlFree(completeWild->negNsSet); |
| 11863 | completeWild->negNsSet = NULL; |
| 11864 | } |
| 11865 | } |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11866 | return (0); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11867 | } |
| 11868 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11869 | * 3 If both O1 and O2 are sets of (namespace names or ·absent·), |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11870 | * then the union of those sets must be the value. |
| 11871 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11872 | if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11873 | int found; |
| 11874 | xmlSchemaWildcardNsPtr start; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11875 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11876 | cur = curWild->nsSet; |
| 11877 | start = completeWild->nsSet; |
| 11878 | while (cur != NULL) { |
| 11879 | found = 0; |
| 11880 | curB = start; |
| 11881 | while (curB != NULL) { |
| 11882 | if (cur->value == curB->value) { |
| 11883 | found = 1; |
| 11884 | break; |
| 11885 | } |
| 11886 | curB = curB->next; |
| 11887 | } |
| 11888 | if (!found) { |
| 11889 | tmp = xmlSchemaNewWildcardNsConstraint(ctxt); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11890 | if (tmp == NULL) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11891 | return (-1); |
| 11892 | tmp->value = cur->value; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11893 | tmp->next = completeWild->nsSet; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11894 | completeWild->nsSet = tmp; |
| 11895 | } |
| 11896 | cur = cur->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11897 | } |
| 11898 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11899 | return(0); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11900 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11901 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11902 | * 4 If the two are negations of different values (namespace names |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11903 | * or ·absent·), then a pair of not and ·absent· must be the value. |
| 11904 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11905 | if ((completeWild->negNsSet != NULL) && |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11906 | (curWild->negNsSet != NULL) && |
| 11907 | (completeWild->negNsSet->value != curWild->negNsSet->value)) { |
| 11908 | completeWild->negNsSet->value = NULL; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11909 | |
| 11910 | return(0); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11911 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11912 | /* |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11913 | * 5. |
| 11914 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11915 | if (((completeWild->negNsSet != NULL) && |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11916 | (completeWild->negNsSet->value != NULL) && |
| 11917 | (curWild->nsSet != NULL)) || |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11918 | ((curWild->negNsSet != NULL) && |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11919 | (curWild->negNsSet->value != NULL) && |
| 11920 | (completeWild->nsSet != NULL))) { |
| 11921 | |
| 11922 | int nsFound, absentFound = 0; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11923 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11924 | if (completeWild->nsSet != NULL) { |
| 11925 | cur = completeWild->nsSet; |
| 11926 | curB = curWild->negNsSet; |
| 11927 | } else { |
| 11928 | cur = curWild->nsSet; |
| 11929 | curB = completeWild->negNsSet; |
| 11930 | } |
| 11931 | nsFound = 0; |
| 11932 | while (cur != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11933 | if (cur->value == NULL) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11934 | absentFound = 1; |
| 11935 | else if (cur->value == curB->value) |
| 11936 | nsFound = 1; |
| 11937 | if (nsFound && absentFound) |
| 11938 | break; |
| 11939 | cur = cur->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11940 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11941 | |
| 11942 | if (nsFound && absentFound) { |
| 11943 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11944 | * 5.1 If the set S includes both the negated namespace |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11945 | * name and ·absent·, then any must be the value. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11946 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11947 | completeWild->any = 1; |
| 11948 | if (completeWild->nsSet != NULL) { |
| 11949 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 11950 | completeWild->nsSet = NULL; |
| 11951 | } |
| 11952 | if (completeWild->negNsSet != NULL) { |
| 11953 | xmlFree(completeWild->negNsSet); |
| 11954 | completeWild->negNsSet = NULL; |
| 11955 | } |
| 11956 | } else if (nsFound && (!absentFound)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11957 | /* |
| 11958 | * 5.2 If the set S includes the negated namespace name |
| 11959 | * but not ·absent·, then a pair of not and ·absent· must |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11960 | * be the value. |
| 11961 | */ |
| 11962 | if (completeWild->nsSet != NULL) { |
| 11963 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 11964 | completeWild->nsSet = NULL; |
| 11965 | } |
| 11966 | if (completeWild->negNsSet == NULL) { |
| 11967 | completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 11968 | if (completeWild->negNsSet == NULL) |
| 11969 | return (-1); |
| 11970 | } |
| 11971 | completeWild->negNsSet->value = NULL; |
| 11972 | } else if ((!nsFound) && absentFound) { |
| 11973 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11974 | * 5.3 If the set S includes ·absent· but not the negated |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11975 | * namespace name, then the union is not expressible. |
| 11976 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11977 | xmlSchemaPErr(ctxt, completeWild->node, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11978 | XML_SCHEMAP_UNION_NOT_EXPRESSIBLE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11979 | "The union of the wilcard is not expressible.\n", |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11980 | NULL, NULL); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11981 | return(XML_SCHEMAP_UNION_NOT_EXPRESSIBLE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11982 | } else if ((!nsFound) && (!absentFound)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 11983 | /* |
| 11984 | * 5.4 If the set S does not include either the negated namespace |
| 11985 | * name or ·absent·, then whichever of O1 or O2 is a pair of not |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11986 | * and a namespace name must be the value. |
| 11987 | */ |
| 11988 | if (completeWild->negNsSet == NULL) { |
| 11989 | if (completeWild->nsSet != NULL) { |
| 11990 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 11991 | completeWild->nsSet = NULL; |
| 11992 | } |
| 11993 | completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 11994 | if (completeWild->negNsSet == NULL) |
| 11995 | return (-1); |
| 11996 | completeWild->negNsSet->value = curWild->negNsSet->value; |
| 11997 | } |
| 11998 | } |
| 11999 | return (0); |
| 12000 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12001 | /* |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12002 | * 6. |
| 12003 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12004 | if (((completeWild->negNsSet != NULL) && |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12005 | (completeWild->negNsSet->value == NULL) && |
| 12006 | (curWild->nsSet != NULL)) || |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12007 | ((curWild->negNsSet != NULL) && |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12008 | (curWild->negNsSet->value == NULL) && |
| 12009 | (completeWild->nsSet != NULL))) { |
| 12010 | |
| 12011 | if (completeWild->nsSet != NULL) { |
| 12012 | cur = completeWild->nsSet; |
| 12013 | } else { |
| 12014 | cur = curWild->nsSet; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12015 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12016 | while (cur != NULL) { |
| 12017 | if (cur->value == NULL) { |
| 12018 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12019 | * 6.1 If the set S includes ·absent·, then any must be the |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12020 | * value. |
| 12021 | */ |
| 12022 | completeWild->any = 1; |
| 12023 | if (completeWild->nsSet != NULL) { |
| 12024 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 12025 | completeWild->nsSet = NULL; |
| 12026 | } |
| 12027 | if (completeWild->negNsSet != NULL) { |
| 12028 | xmlFree(completeWild->negNsSet); |
| 12029 | completeWild->negNsSet = NULL; |
| 12030 | } |
| 12031 | return (0); |
| 12032 | } |
| 12033 | cur = cur->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12034 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12035 | if (completeWild->negNsSet == NULL) { |
| 12036 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12037 | * 6.2 If the set S does not include ·absent·, then a pair of not |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12038 | * and ·absent· must be the value. |
| 12039 | */ |
| 12040 | if (completeWild->nsSet != NULL) { |
| 12041 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 12042 | completeWild->nsSet = NULL; |
| 12043 | } |
| 12044 | completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 12045 | if (completeWild->negNsSet == NULL) |
| 12046 | return (-1); |
| 12047 | completeWild->negNsSet->value = NULL; |
| 12048 | } |
| 12049 | return (0); |
| 12050 | } |
| 12051 | return (0); |
| 12052 | |
| 12053 | } |
| 12054 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12055 | /** |
| 12056 | * xmlSchemaIntersectWildcards: |
| 12057 | * @ctxt: the schema parser context |
| 12058 | * @completeWild: the first wildcard |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12059 | * @curWild: the second wildcard |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12060 | * |
| 12061 | * Intersects the namespace constraints of the given wildcards. |
| 12062 | * @completeWild will hold the resulting intersection. |
| 12063 | * Returns a positive error code on failure, -1 in case of an |
| 12064 | * internal error, 0 otherwise. |
| 12065 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12066 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12067 | xmlSchemaIntersectWildcards(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12068 | xmlSchemaWildcardPtr completeWild, |
| 12069 | xmlSchemaWildcardPtr curWild) |
| 12070 | { |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 12071 | xmlSchemaWildcardNsPtr cur, curB, prev, tmp; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12072 | |
| 12073 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12074 | * 1 If O1 and O2 are the same value, then that value must be the |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12075 | * value. |
| 12076 | */ |
| 12077 | if ((completeWild->any == curWild->any) && |
| 12078 | ((completeWild->nsSet == NULL) == (curWild->nsSet == NULL)) && |
| 12079 | ((completeWild->negNsSet == NULL) == (curWild->negNsSet == NULL))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12080 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12081 | if ((completeWild->negNsSet == NULL) || |
| 12082 | (completeWild->negNsSet->value == curWild->negNsSet->value)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12083 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12084 | if (completeWild->nsSet != NULL) { |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 12085 | int found = 0; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12086 | |
| 12087 | /* |
| 12088 | * Check equality of sets. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12089 | */ |
| 12090 | cur = completeWild->nsSet; |
| 12091 | while (cur != NULL) { |
| 12092 | found = 0; |
| 12093 | curB = curWild->nsSet; |
| 12094 | while (curB != NULL) { |
| 12095 | if (cur->value == curB->value) { |
| 12096 | found = 1; |
| 12097 | break; |
| 12098 | } |
| 12099 | curB = curB->next; |
| 12100 | } |
| 12101 | if (!found) |
| 12102 | break; |
| 12103 | cur = cur->next; |
| 12104 | } |
| 12105 | if (found) |
| 12106 | return(0); |
| 12107 | } else |
| 12108 | return(0); |
| 12109 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12110 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12111 | /* |
| 12112 | * 2 If either O1 or O2 is any, then the other must be the value. |
| 12113 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12114 | if ((completeWild->any != curWild->any) && (completeWild->any)) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12115 | if (xmlSchemaCloneWildcardNsConstraints(ctxt, &completeWild, curWild) == -1) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12116 | return(-1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12117 | return(0); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12118 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12119 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12120 | * 3 If either O1 or O2 is a pair of not and a value (a namespace |
| 12121 | * name or ·absent·) and the other is a set of (namespace names or |
| 12122 | * ·absent·), then that set, minus the negated value if it was in |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12123 | * the set, minus ·absent· if it was in the set, must be the value. |
| 12124 | */ |
| 12125 | if (((completeWild->negNsSet != NULL) && (curWild->nsSet != NULL)) || |
| 12126 | ((curWild->negNsSet != NULL) && (completeWild->nsSet != NULL))) { |
| 12127 | const xmlChar *neg; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12128 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12129 | if (completeWild->nsSet == NULL) { |
| 12130 | neg = completeWild->negNsSet->value; |
| 12131 | if (xmlSchemaCloneWildcardNsConstraints(ctxt, &completeWild, curWild) == -1) |
| 12132 | return(-1); |
| 12133 | } else |
| 12134 | neg = curWild->negNsSet->value; |
| 12135 | /* |
| 12136 | * Remove absent and negated. |
| 12137 | */ |
| 12138 | prev = NULL; |
| 12139 | cur = completeWild->nsSet; |
| 12140 | while (cur != NULL) { |
| 12141 | if (cur->value == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12142 | if (prev == NULL) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12143 | completeWild->nsSet = cur->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12144 | else |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12145 | prev->next = cur->next; |
| 12146 | xmlFree(cur); |
| 12147 | break; |
| 12148 | } |
| 12149 | prev = cur; |
| 12150 | cur = cur->next; |
| 12151 | } |
| 12152 | if (neg != NULL) { |
| 12153 | prev = NULL; |
| 12154 | cur = completeWild->nsSet; |
| 12155 | while (cur != NULL) { |
| 12156 | if (cur->value == neg) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12157 | if (prev == NULL) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12158 | completeWild->nsSet = cur->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12159 | else |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12160 | prev->next = cur->next; |
| 12161 | xmlFree(cur); |
| 12162 | break; |
| 12163 | } |
| 12164 | prev = cur; |
| 12165 | cur = cur->next; |
| 12166 | } |
| 12167 | } |
| 12168 | |
| 12169 | return(0); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12170 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12171 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12172 | * 4 If both O1 and O2 are sets of (namespace names or ·absent·), |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12173 | * then the intersection of those sets must be the value. |
| 12174 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12175 | if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12176 | int found; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12177 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12178 | cur = completeWild->nsSet; |
| 12179 | prev = NULL; |
| 12180 | while (cur != NULL) { |
| 12181 | found = 0; |
| 12182 | curB = curWild->nsSet; |
| 12183 | while (curB != NULL) { |
| 12184 | if (cur->value == curB->value) { |
| 12185 | found = 1; |
| 12186 | break; |
| 12187 | } |
| 12188 | curB = curB->next; |
| 12189 | } |
| 12190 | if (!found) { |
| 12191 | if (prev == NULL) |
| 12192 | completeWild->nsSet = cur->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12193 | else |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12194 | prev->next = cur->next; |
| 12195 | tmp = cur->next; |
| 12196 | xmlFree(cur); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12197 | cur = tmp; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12198 | continue; |
| 12199 | } |
| 12200 | prev = cur; |
| 12201 | cur = cur->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12202 | } |
| 12203 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12204 | return(0); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12205 | } |
| 12206 | /* 5 If the two are negations of different namespace names, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12207 | * then the intersection is not expressible |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12208 | */ |
| 12209 | if ((completeWild->negNsSet != NULL) && |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12210 | (curWild->negNsSet != NULL) && |
| 12211 | (completeWild->negNsSet->value != curWild->negNsSet->value) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12212 | (completeWild->negNsSet->value != NULL) && |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12213 | (curWild->negNsSet->value != NULL)) { |
| 12214 | |
| 12215 | xmlSchemaPErr(ctxt, completeWild->node, XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12216 | "The intersection of the wilcard is not expressible.\n", |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12217 | NULL, NULL); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12218 | return(XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12219 | } |
| 12220 | /* |
| 12221 | * 6 If the one is a negation of a namespace name and the other |
| 12222 | * is a negation of ·absent·, then the one which is the negation |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12223 | * of a namespace name must be the value. |
| 12224 | */ |
| 12225 | if ((completeWild->negNsSet != NULL) && (curWild->negNsSet != NULL) && |
| 12226 | (completeWild->negNsSet->value != curWild->negNsSet->value) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12227 | (completeWild->negNsSet->value == NULL)) { |
| 12228 | completeWild->negNsSet->value = curWild->negNsSet->value; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12229 | } |
| 12230 | return(0); |
| 12231 | } |
| 12232 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12233 | /** |
| 12234 | * xmlSchemaIsWildcardNsConstraintSubset: |
| 12235 | * @ctxt: the schema parser context |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12236 | * @sub: the first wildcard |
| 12237 | * @super: the second wildcard |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12238 | * |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12239 | * Schema Component Constraint: Wildcard Subset (cos-ns-subset) |
| 12240 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12241 | * Returns 0 if the namespace constraint of @sub is an intensional |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12242 | * subset of @super, 1 otherwise. |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12243 | */ |
| 12244 | static int |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12245 | xmlSchemaCheckCOSNSSubset(xmlSchemaWildcardPtr sub, |
| 12246 | xmlSchemaWildcardPtr super) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12247 | { |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12248 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12249 | * 1 super must be any. |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12250 | */ |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12251 | if (super->any) |
| 12252 | return (0); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12253 | /* |
| 12254 | * 2.1 sub must be a pair of not and a namespace name or ·absent·. |
| 12255 | * 2.2 super must be a pair of not and the same value. |
| 12256 | */ |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12257 | if ((sub->negNsSet != NULL) && |
| 12258 | (super->negNsSet != NULL) && |
| 12259 | (sub->negNsSet->value == sub->negNsSet->value)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12260 | return (0); |
| 12261 | /* |
| 12262 | * 3.1 sub must be a set whose members are either namespace names or ·absent·. |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12263 | */ |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12264 | if (sub->nsSet != NULL) { |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12265 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12266 | * 3.2.1 super must be the same set or a superset thereof. |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12267 | */ |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12268 | if (super->nsSet != NULL) { |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12269 | xmlSchemaWildcardNsPtr cur, curB; |
| 12270 | int found = 0; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12271 | |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12272 | cur = sub->nsSet; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12273 | while (cur != NULL) { |
| 12274 | found = 0; |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12275 | curB = super->nsSet; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12276 | while (curB != NULL) { |
| 12277 | if (cur->value == curB->value) { |
| 12278 | found = 1; |
| 12279 | break; |
| 12280 | } |
| 12281 | curB = curB->next; |
| 12282 | } |
| 12283 | if (!found) |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12284 | return (1); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12285 | cur = cur->next; |
| 12286 | } |
| 12287 | if (found) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12288 | return (0); |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12289 | } else if (super->negNsSet != NULL) { |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12290 | xmlSchemaWildcardNsPtr cur; |
| 12291 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12292 | * 3.2.2 super must be a pair of not and a namespace name or |
| 12293 | * ·absent· and that value must not be in sub's set. |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12294 | */ |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12295 | cur = sub->nsSet; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12296 | while (cur != NULL) { |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12297 | if (cur->value == super->negNsSet->value) |
| 12298 | return (1); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12299 | cur = cur->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12300 | } |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12301 | return (0); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12302 | } |
| 12303 | } |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12304 | return (1); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12305 | } |
| 12306 | |
| 12307 | /** |
| 12308 | * xmlSchemaBuildCompleteAttributeWildcard: |
| 12309 | * @ctxt: the schema parser context |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12310 | * @attrs: the attribute list |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12311 | * @completeWild: the resulting complete wildcard |
| 12312 | * |
| 12313 | * Returns -1 in case of an internal error, 0 otherwise. |
| 12314 | */ |
| 12315 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12316 | xmlSchemaBuildCompleteAttributeWildcard(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12317 | xmlSchemaAttributePtr attrs, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12318 | xmlSchemaWildcardPtr *completeWild) |
| 12319 | { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12320 | while (attrs != NULL) { |
| 12321 | if (attrs->type == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) { |
| 12322 | xmlSchemaAttributeGroupPtr group; |
| 12323 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12324 | group = (xmlSchemaAttributeGroupPtr) attrs; |
| 12325 | /* |
| 12326 | * Handle attribute group references. |
| 12327 | */ |
| 12328 | if (group->ref != NULL) { |
| 12329 | if (group->refItem == NULL) { |
| 12330 | /* |
| 12331 | * TODO: Should we raise a warning here? |
| 12332 | */ |
| 12333 | /* |
| 12334 | * The referenced attribute group definition could not |
| 12335 | * be resolved beforehand, so skip. |
| 12336 | */ |
| 12337 | attrs = attrs->next; |
| 12338 | continue; |
| 12339 | } else |
| 12340 | group = group->refItem; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12341 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12342 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12343 | * For every attribute group definition, an intersected wildcard |
| 12344 | * will be created (assumed that a wildcard exists on the |
| 12345 | * particular attr. gr. def. or on any contained attr. gr. def |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12346 | * at all). |
| 12347 | * The flag XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED ensures |
| 12348 | * that the intersection will be performed only once. |
| 12349 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12350 | if ((group->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED) == 0) { |
| 12351 | if (group->attributes != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12352 | if (xmlSchemaBuildCompleteAttributeWildcard(ctxt, |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12353 | group->attributes, &group->attributeWildcard) == -1) |
| 12354 | return (-1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12355 | } |
| 12356 | group->flags |= XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12357 | } |
| 12358 | if (group->attributeWildcard != NULL) { |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12359 | if (*completeWild == NULL) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12360 | /* |
| 12361 | * Copy the first encountered wildcard as context, except for the annotation. |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 12362 | * |
| 12363 | * Although the complete wildcard might not correspond to any |
| 12364 | * node in the schema, we will save this context node. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12365 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 12366 | *completeWild = xmlSchemaAddWildcard(ctxt, ctxt->schema, |
| 12367 | XML_SCHEMA_TYPE_ANY_ATTRIBUTE, |
| 12368 | group->attributeWildcard->node); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12369 | if (xmlSchemaCloneWildcardNsConstraints(ctxt, |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12370 | completeWild, group->attributeWildcard) == -1) |
| 12371 | return (-1); |
| 12372 | (*completeWild)->processContents = group->attributeWildcard->processContents; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 12373 | (*completeWild)->node = group->attributeWildcard->node; |
| 12374 | } else if (xmlSchemaIntersectWildcards(ctxt, *completeWild, group->attributeWildcard) == -1) |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12375 | return (-1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12376 | } |
| 12377 | } |
| 12378 | attrs = attrs->next; |
| 12379 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12380 | |
| 12381 | return (0); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12382 | } |
| 12383 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12384 | static int |
| 12385 | xmlSchemaGetEffectiveValueConstraint(xmlSchemaAttributePtr item, |
| 12386 | int *fixed, |
| 12387 | const xmlChar **value, |
| 12388 | xmlSchemaValPtr *val) |
| 12389 | { |
| 12390 | *fixed = 0; |
| 12391 | *value = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12392 | if (val != 0) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12393 | *val = NULL; |
| 12394 | |
| 12395 | if (item->defValue == NULL) |
| 12396 | item = item->refDecl; |
| 12397 | |
| 12398 | if (item == NULL) |
| 12399 | return (0); |
| 12400 | |
| 12401 | if (item->defValue != NULL) { |
| 12402 | *value = item->defValue; |
| 12403 | if (val != 0) |
| 12404 | *val = item->defVal; |
| 12405 | if (item->flags & XML_SCHEMAS_ATTR_FIXED) |
| 12406 | *fixed = 1; |
| 12407 | return (1); |
| 12408 | } |
| 12409 | return (0); |
| 12410 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12411 | /** |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12412 | * xmlSchemaCheckCVCWildcardNamespace: |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12413 | * @wild: the wildcard |
| 12414 | * @ns: the namespace |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12415 | * |
| 12416 | * Validation Rule: Wildcard allows Namespace Name |
| 12417 | * (cvc-wildcard-namespace) |
| 12418 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12419 | * |
| 12420 | * Returns 1 if the given namespace matches the wildcard, |
| 12421 | * 0 otherwise. |
| 12422 | */ |
| 12423 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12424 | xmlSchemaCheckCVCWildcardNamespace(xmlSchemaWildcardPtr wild, |
| 12425 | const xmlChar* ns) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12426 | { |
| 12427 | if (wild == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12428 | return(-1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12429 | |
| 12430 | if (wild->any) |
| 12431 | return(1); |
| 12432 | else if (wild->nsSet != NULL) { |
| 12433 | xmlSchemaWildcardNsPtr cur; |
| 12434 | |
| 12435 | cur = wild->nsSet; |
| 12436 | while (cur != NULL) { |
| 12437 | if (xmlStrEqual(cur->value, ns)) |
| 12438 | return(1); |
| 12439 | cur = cur->next; |
| 12440 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12441 | } else if ((wild->negNsSet != NULL) && (ns != NULL) && |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12442 | (!xmlStrEqual(wild->negNsSet->value, ns))) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12443 | return(1); |
| 12444 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12445 | return(0); |
| 12446 | } |
| 12447 | |
| 12448 | /** |
| 12449 | * xmlSchemaBuildAttributeValidation: |
| 12450 | * @ctxt: the schema parser context |
| 12451 | * @type: the complex type definition |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12452 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12453 | * |
| 12454 | * Builds the wildcard and the attribute uses on the given complex type. |
| 12455 | * Returns -1 if an internal error occurs, 0 otherwise. |
| 12456 | */ |
| 12457 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12458 | xmlSchemaBuildAttributeValidation(xmlSchemaParserCtxtPtr pctxt, |
| 12459 | xmlSchemaTypePtr type) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12460 | { |
| 12461 | xmlSchemaTypePtr baseType = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12462 | xmlSchemaAttributeLinkPtr cur, base, tmp, id = NULL, |
| 12463 | prev = NULL, uses = NULL, lastUse = NULL, lastBaseUse = NULL; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12464 | xmlSchemaAttributePtr attrs; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12465 | xmlSchemaTypePtr anyType; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12466 | xmlChar *str = NULL; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 12467 | int err = 0; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12468 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12469 | anyType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12470 | /* |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12471 | * Complex Type Definition with complex content Schema Component. |
| 12472 | * |
| 12473 | * Attribute uses. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12474 | * TODO: Add checks for absent referenced attribute declarations and |
| 12475 | * simple types. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12476 | */ |
| 12477 | if (type->attributeUses != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12478 | PERROR_INT("xmlSchemaBuildAttributeValidation", |
| 12479 | "attribute uses already builded"); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12480 | return (-1); |
| 12481 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12482 | if (type->baseType == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12483 | PERROR_INT("xmlSchemaBuildAttributeValidation", |
| 12484 | "no base type"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12485 | return (-1); |
| 12486 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12487 | baseType = type->baseType; |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12488 | /* |
| 12489 | * Inherit the attribute uses of the base type. |
| 12490 | */ |
| 12491 | /* |
| 12492 | * NOTE: It is allowed to "extend" the anyType complex type. |
| 12493 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12494 | if (! IS_ANYTYPE(baseType)) { |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12495 | if (baseType != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12496 | for (cur = baseType->attributeUses; cur != NULL; |
| 12497 | cur = cur->next) { |
| 12498 | tmp = (xmlSchemaAttributeLinkPtr) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12499 | xmlMalloc(sizeof(xmlSchemaAttributeLink)); |
| 12500 | if (tmp == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12501 | xmlSchemaPErrMemory(pctxt, |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12502 | "building attribute uses of complexType", NULL); |
| 12503 | return (-1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12504 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12505 | tmp->attr = cur->attr; |
| 12506 | tmp->next = NULL; |
| 12507 | if (type->attributeUses == NULL) { |
| 12508 | type->attributeUses = tmp; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12509 | } else |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12510 | lastBaseUse->next = tmp; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12511 | lastBaseUse = tmp; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12512 | } |
| 12513 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12514 | } |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 12515 | attrs = type->attributes; |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12516 | /* |
| 12517 | * Handle attribute wildcards. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12518 | */ |
| 12519 | err = xmlSchemaBuildCompleteAttributeWildcard(pctxt, |
| 12520 | attrs, &type->attributeWildcard); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12521 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12522 | * NOTE: During the parse time, the wildcard is created on the complexType |
| 12523 | * directly, if encountered in a <restriction> or <extension> element. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12524 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12525 | if (err == -1) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12526 | PERROR_INT("xmlSchemaBuildAttributeValidation", |
| 12527 | "failed to build an intersected attribute wildcard"); |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 12528 | return (-1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12529 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12530 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12531 | if ((type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) && |
| 12532 | ((IS_ANYTYPE(baseType)) || |
| 12533 | ((baseType != NULL) && |
| 12534 | (baseType->type == XML_SCHEMA_TYPE_COMPLEX) && |
| 12535 | (baseType->attributeWildcard != NULL)))) { |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12536 | if (type->attributeWildcard != NULL) { |
| 12537 | /* |
| 12538 | * Union the complete wildcard with the base wildcard. |
| 12539 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12540 | if (xmlSchemaUnionWildcards(pctxt, type->attributeWildcard, |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12541 | baseType->attributeWildcard) == -1) |
| 12542 | return (-1); |
| 12543 | } else { |
| 12544 | /* |
| 12545 | * Just inherit the wildcard. |
| 12546 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12547 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12548 | * NOTE: This is the only case where an attribute |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12549 | * wildcard is shared. |
| 12550 | */ |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12551 | type->attributeWildcard = baseType->attributeWildcard; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12552 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12553 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12554 | |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12555 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
| 12556 | if (type->attributeWildcard != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12557 | /* |
| 12558 | * Derivation Valid (Restriction, Complex) |
| 12559 | * 4.1 The {base type definition} must also have one. |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12560 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12561 | if (baseType->attributeWildcard == NULL) { |
| 12562 | xmlSchemaPCustomErr(pctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12563 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12564 | NULL, type, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12565 | "The type has an attribute wildcard, " |
| 12566 | "but the base type %s does not have one", |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12567 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12568 | FREE_AND_NULL(str) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12569 | return (1); |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12570 | } else if (xmlSchemaCheckCOSNSSubset( |
| 12571 | type->attributeWildcard, baseType->attributeWildcard)) { |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12572 | /* 4.2 */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12573 | xmlSchemaPCustomErr(pctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12574 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_2, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12575 | NULL, type, NULL, |
| 12576 | "The attribute wildcard is not a valid " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12577 | "subset of the wildcard in the base type %s", |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12578 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL)); |
| 12579 | FREE_AND_NULL(str) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12580 | return (1); |
| 12581 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12582 | /* 4.3 Unless the {base type definition} is the ·ur-type |
| 12583 | * definition·, the complex type definition's {attribute |
| 12584 | * wildcard}'s {process contents} must be identical to or |
| 12585 | * stronger than the {base type definition}'s {attribute |
| 12586 | * wildcard}'s {process contents}, where strict is stronger |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12587 | * than lax is stronger than skip. |
| 12588 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12589 | if ((! IS_ANYTYPE(baseType)) && |
| 12590 | (type->attributeWildcard->processContents < |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12591 | baseType->attributeWildcard->processContents)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12592 | xmlSchemaPCustomErr(pctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12593 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_3, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12594 | NULL, type, NULL, |
| 12595 | "The 'process contents' of the attribute wildcard is " |
| 12596 | "weaker than the one in the base type %s", |
| 12597 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12598 | FREE_AND_NULL(str) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12599 | return (1); |
| 12600 | } |
| 12601 | } |
| 12602 | } else if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) { |
| 12603 | /* |
| 12604 | * Derivation Valid (Extension) |
| 12605 | * At this point the type and the base have both, either |
| 12606 | * no wildcard or a wildcard. |
| 12607 | */ |
| 12608 | if ((baseType->attributeWildcard != NULL) && |
| 12609 | (baseType->attributeWildcard != type->attributeWildcard)) { |
| 12610 | /* 1.3 */ |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12611 | if (xmlSchemaCheckCOSNSSubset( |
| 12612 | baseType->attributeWildcard, type->attributeWildcard)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12613 | xmlSchemaPCustomErr(pctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12614 | XML_SCHEMAP_COS_CT_EXTENDS_1_3, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12615 | NULL, type, NULL, |
| 12616 | "The attribute wildcard is not a valid " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12617 | "superset of the one in the base type %s", |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12618 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL)); |
| 12619 | FREE_AND_NULL(str) |
| 12620 | return (1); |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12621 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12622 | } |
| 12623 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12624 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12625 | /* |
| 12626 | * Gather attribute uses defined by this type. |
| 12627 | */ |
| 12628 | if (attrs != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12629 | if (xmlSchemaBuildAttributeUsesOwned(pctxt, attrs, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12630 | &uses, &lastUse) == -1) { |
| 12631 | return (-1); |
| 12632 | } |
| 12633 | } |
| 12634 | /* 3.4.6 -> Complex Type Definition Properties Correct 4. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12635 | * "Two distinct attribute declarations in the {attribute uses} must |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12636 | * not have identical {name}s and {target namespace}s." |
| 12637 | * |
| 12638 | * For "extension" this is done further down. |
| 12639 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12640 | if ((uses != NULL) && ((type->flags & |
| 12641 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) == 0)) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12642 | cur = uses; |
| 12643 | while (cur != NULL) { |
| 12644 | tmp = cur->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12645 | while (tmp != NULL) { |
| 12646 | if ((xmlStrEqual(xmlSchemaGetAttrName(cur->attr), |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12647 | xmlSchemaGetAttrName(tmp->attr))) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12648 | (xmlStrEqual(xmlSchemaGetAttrTargetNsURI(cur->attr), |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12649 | xmlSchemaGetAttrTargetNsURI(tmp->attr)))) { |
| 12650 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12651 | xmlSchemaPAttrUseErr(pctxt, |
| 12652 | XML_SCHEMAP_CT_PROPS_CORRECT_4, |
| 12653 | type, cur->attr, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12654 | "Duplicate attribute use %s specified", |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12655 | xmlSchemaFormatQName(&str, |
| 12656 | xmlSchemaGetAttrTargetNsURI(tmp->attr), |
| 12657 | xmlSchemaGetAttrName(tmp->attr))); |
| 12658 | FREE_AND_NULL(str) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12659 | break; |
| 12660 | } |
| 12661 | tmp = tmp->next; |
| 12662 | } |
| 12663 | cur = cur->next; |
| 12664 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12665 | } |
| 12666 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12667 | /* |
| 12668 | * Derive by restriction. |
| 12669 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12670 | if (IS_ANYTYPE(baseType)) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12671 | type->attributeUses = uses; |
| 12672 | } else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12673 | int found, valid; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12674 | const xmlChar *bEffValue; |
| 12675 | int effFixed; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12676 | |
| 12677 | cur = uses; |
| 12678 | while (cur != NULL) { |
| 12679 | found = 0; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12680 | valid = 1; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12681 | base = type->attributeUses; |
| 12682 | while (base != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12683 | if (xmlStrEqual(xmlSchemaGetAttrName(cur->attr), |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12684 | xmlSchemaGetAttrName(base->attr)) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12685 | xmlStrEqual(xmlSchemaGetAttrTargetNsURI(cur->attr), |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12686 | xmlSchemaGetAttrTargetNsURI(base->attr))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12687 | |
| 12688 | found = 1; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12689 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12690 | if ((cur->attr->occurs == |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 12691 | XML_SCHEMAS_ATTR_USE_PROHIBITED) && |
| 12692 | (base->attr->occurs == |
| 12693 | XML_SCHEMAS_ATTR_USE_OPTIONAL)) { |
| 12694 | /* |
| 12695 | * NOOP. |
| 12696 | */ |
| 12697 | } else if ((cur->attr->occurs == |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12698 | XML_SCHEMAS_ATTR_USE_OPTIONAL) && |
| 12699 | (base->attr->occurs == |
| 12700 | XML_SCHEMAS_ATTR_USE_REQUIRED)) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12701 | /* |
| 12702 | * derivation-ok-restriction 2.1.1 |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12703 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12704 | xmlSchemaPAttrUseErr(pctxt, |
| 12705 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_1, |
| 12706 | type, cur->attr, |
| 12707 | "The 'optional' use is inconsistent with a " |
| 12708 | "matching 'required' use of the base type", |
| 12709 | NULL); |
| 12710 | } else if ((cur->attr->occurs == |
| 12711 | XML_SCHEMAS_ATTR_USE_PROHIBITED) && |
| 12712 | (base->attr->occurs == |
| 12713 | XML_SCHEMAS_ATTR_USE_REQUIRED)) { |
| 12714 | /* |
| 12715 | * derivation-ok-restriction 3 |
| 12716 | */ |
| 12717 | xmlSchemaPCustomErr(pctxt, |
| 12718 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_3, |
| 12719 | NULL, type, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12720 | "A matching attribute use for the 'required' " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12721 | "attribute use '%s' of the base type is " |
| 12722 | "missing", |
| 12723 | xmlSchemaFormatQName(&str, |
| 12724 | xmlSchemaGetAttrTargetNsURI(base->attr), |
| 12725 | xmlSchemaGetAttrName(base->attr))); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12726 | FREE_AND_NULL(str) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12727 | } else if (xmlSchemaCheckCOSSTDerivedOK( |
| 12728 | cur->attr->subtypes, base->attr->subtypes, 0) != 0) { |
| 12729 | |
| 12730 | /* |
| 12731 | * SPEC (2.1.2) "R's {attribute declaration}'s |
| 12732 | * {type definition} must be validly derived from |
| 12733 | * B's {type definition} given the empty set as |
| 12734 | * defined in Type Derivation OK (Simple) (§3.14.6)." |
| 12735 | */ |
| 12736 | xmlSchemaPAttrUseErr(pctxt, |
| 12737 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_2, |
| 12738 | type, cur->attr, |
| 12739 | "The attribute declaration's type " |
| 12740 | "definition is not validly derived from " |
| 12741 | "the corresponding definition in the " |
| 12742 | "base type", NULL); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12743 | } else { |
| 12744 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12745 | * 2.1.3 [Definition:] Let the effective value |
| 12746 | * constraint of an attribute use be its {value |
| 12747 | * constraint}, if present, otherwise its {attribute |
| 12748 | * declaration}'s {value constraint} . |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12749 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12750 | xmlSchemaGetEffectiveValueConstraint(base->attr, |
| 12751 | &effFixed, &bEffValue, 0); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12752 | /* |
| 12753 | * 2.1.3 ... one of the following must be true |
| 12754 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12755 | * 2.1.3.1 B's ·effective value constraint· is |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12756 | * ·absent· or default. |
| 12757 | */ |
| 12758 | if ((bEffValue != NULL) && |
| 12759 | (effFixed == 1)) { |
| 12760 | const xmlChar *rEffValue = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12761 | |
| 12762 | xmlSchemaGetEffectiveValueConstraint(base->attr, |
| 12763 | &effFixed, &rEffValue, 0); |
| 12764 | /* |
| 12765 | * 2.1.3.2 R's ·effective value constraint· is |
| 12766 | * fixed with the same string as B's. |
| 12767 | * TODO: Compare the computed values. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12768 | */ |
| 12769 | if ((effFixed == 0) || |
| 12770 | (! xmlStrEqual(rEffValue, bEffValue))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12771 | xmlSchemaPAttrUseErr(pctxt, |
| 12772 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_3, |
| 12773 | type, cur->attr, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12774 | "The effective value constraint of the " |
| 12775 | "attribute use is inconsistent with " |
| 12776 | "its correspondent of the base type", |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12777 | NULL); |
| 12778 | } else { |
| 12779 | /* |
| 12780 | * Override the attribute use. |
| 12781 | */ |
| 12782 | base->attr = cur->attr; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12783 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12784 | } else |
| 12785 | base->attr = cur->attr; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12786 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12787 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12788 | break; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12789 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12790 | base = base->next; |
| 12791 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12792 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12793 | if ((!found) && (cur->attr->occurs != |
| 12794 | XML_SCHEMAS_ATTR_USE_PROHIBITED)) { |
| 12795 | /* |
| 12796 | * derivation-ok-restriction 2.2 |
| 12797 | */ |
| 12798 | if ((baseType->attributeWildcard == NULL) || |
| 12799 | (xmlSchemaCheckCVCWildcardNamespace( |
| 12800 | baseType->attributeWildcard, |
| 12801 | cur->attr->targetNamespace) != 1)) { |
| 12802 | xmlSchemaPAttrUseErr(pctxt, |
| 12803 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_2, |
| 12804 | type, cur->attr, |
| 12805 | "Neither a matching attribute use, " |
| 12806 | "nor a matching wildcard in the base type does exist", |
| 12807 | NULL); |
| 12808 | } else { |
| 12809 | /* |
| 12810 | * Add the attribute use. |
| 12811 | * |
| 12812 | * Note that this may lead to funny derivation error reports, if |
| 12813 | * multiple equal attribute uses exist; but this is not |
| 12814 | * allowed anyway, and it will be reported beforehand. |
| 12815 | */ |
| 12816 | tmp = cur; |
| 12817 | if (prev != NULL) |
| 12818 | prev->next = cur->next; |
| 12819 | else |
| 12820 | uses = cur->next; |
| 12821 | cur = cur->next; |
| 12822 | tmp->next = NULL; |
| 12823 | if (type->attributeUses == NULL) { |
| 12824 | type->attributeUses = tmp; |
| 12825 | } else |
| 12826 | lastBaseUse->next = tmp; |
| 12827 | lastBaseUse = tmp; |
| 12828 | |
| 12829 | continue; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12830 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12831 | } |
| 12832 | prev = cur; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12833 | cur = cur->next; |
| 12834 | } |
| 12835 | if (uses != NULL) |
| 12836 | xmlSchemaFreeAttributeUseList(uses); |
| 12837 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12838 | } else if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12839 | /* |
| 12840 | * The spec allows only appending, and not other kinds of extensions. |
| 12841 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12842 | * This ensures: Schema Component Constraint: Derivation Valid (Extension) : 1.2 |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12843 | */ |
| 12844 | if (uses != NULL) { |
| 12845 | if (type->attributeUses == NULL) { |
| 12846 | type->attributeUses = uses; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12847 | } else |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12848 | lastBaseUse->next = uses; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12849 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12850 | } else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12851 | PERROR_INT("xmlSchemaBuildAttributeValidation", |
| 12852 | "no derivation method"); |
| 12853 | return (-1); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12854 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12855 | /* |
| 12856 | * 3.4.6 -> Complex Type Definition Properties Correct |
| 12857 | */ |
| 12858 | if (type->attributeUses != NULL) { |
| 12859 | cur = type->attributeUses; |
| 12860 | prev = NULL; |
| 12861 | while (cur != NULL) { |
| 12862 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12863 | * 4. Two distinct attribute declarations in the {attribute uses} must |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12864 | * not have identical {name}s and {target namespace}s. |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12865 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12866 | * Note that this was already done for "restriction" and types derived from |
| 12867 | * the ur-type. |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12868 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12869 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) { |
| 12870 | tmp = cur->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12871 | while (tmp != NULL) { |
| 12872 | if ((xmlStrEqual(xmlSchemaGetAttrName(cur->attr), |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12873 | xmlSchemaGetAttrName(tmp->attr))) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12874 | (xmlStrEqual(xmlSchemaGetAttrTargetNsURI(cur->attr ), |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12875 | xmlSchemaGetAttrTargetNsURI(tmp->attr)))) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12876 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12877 | xmlSchemaPAttrUseErr(pctxt, |
| 12878 | XML_SCHEMAP_CT_PROPS_CORRECT_4, |
| 12879 | type, tmp->attr, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12880 | "Duplicate attribute use specified", NULL); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12881 | break; |
| 12882 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12883 | tmp = tmp->next; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12884 | } |
| 12885 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12886 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12887 | * 5. Two distinct attribute declarations in the {attribute uses} must |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12888 | * not have {type definition}s which are or are derived from ID. |
| 12889 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12890 | if ((cur->attr->subtypes != NULL) && |
| 12891 | (xmlSchemaIsDerivedFromBuiltInType(cur->attr->subtypes, |
| 12892 | XML_SCHEMAS_ID))) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12893 | if (id != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12894 | xmlSchemaPAttrUseErr(pctxt, |
| 12895 | XML_SCHEMAP_CT_PROPS_CORRECT_5, |
| 12896 | type, cur->attr, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12897 | "There must not exist more than one attribute use, " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12898 | "declared of type 'ID' or derived from it", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12899 | NULL); |
| 12900 | FREE_AND_NULL(str) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12901 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12902 | id = cur; |
| 12903 | } |
| 12904 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12905 | * Remove "prohibited" attribute uses. The reason this is done at this late |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12906 | * stage is to be able to catch dublicate attribute uses. So we had to keep |
| 12907 | * prohibited uses in the list as well. |
| 12908 | */ |
| 12909 | if (cur->attr->occurs == XML_SCHEMAS_ATTR_USE_PROHIBITED) { |
| 12910 | tmp = cur; |
| 12911 | if (prev == NULL) |
| 12912 | type->attributeUses = cur->next; |
| 12913 | else |
| 12914 | prev->next = cur->next; |
| 12915 | cur = cur->next; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12916 | xmlFree(tmp); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12917 | } else { |
| 12918 | prev = cur; |
| 12919 | cur = cur->next; |
| 12920 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12921 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12922 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12923 | /* |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12924 | * TODO: This check should be removed if we are 100% sure of |
| 12925 | * the base type attribute uses already being built. |
| 12926 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12927 | if ((baseType != NULL) && (! IS_ANYTYPE(baseType)) && |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12928 | (baseType->type == XML_SCHEMA_TYPE_COMPLEX) && |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 12929 | (IS_NOT_TYPEFIXED(baseType))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12930 | PERROR_INT("xmlSchemaBuildAttributeValidation", |
| 12931 | "attribute uses not builded on base type"); |
| 12932 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12933 | return (0); |
| 12934 | } |
| 12935 | |
| 12936 | /** |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12937 | * xmlSchemaTypeFinalContains: |
| 12938 | * @schema: the schema |
| 12939 | * @type: the type definition |
| 12940 | * @final: the final |
| 12941 | * |
| 12942 | * Evaluates if a type definition contains the given "final". |
| 12943 | * This does take "finalDefault" into account as well. |
| 12944 | * |
| 12945 | * Returns 1 if the type does containt the given "final", |
| 12946 | * 0 otherwise. |
| 12947 | */ |
| 12948 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12949 | xmlSchemaTypeFinalContains(xmlSchemaTypePtr type, int final) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12950 | { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12951 | if (type == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12952 | return (0); |
| 12953 | if (type->flags & final) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12954 | return (1); |
| 12955 | else |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12956 | return (0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12957 | } |
| 12958 | |
| 12959 | /** |
| 12960 | * xmlSchemaGetUnionSimpleTypeMemberTypes: |
| 12961 | * @type: the Union Simple Type |
| 12962 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12963 | * Returns a list of member types of @type if existing, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12964 | * returns NULL otherwise. |
| 12965 | */ |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12966 | static xmlSchemaTypeLinkPtr |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12967 | xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type) |
| 12968 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 12969 | while ((type != NULL) && (type->type == XML_SCHEMA_TYPE_SIMPLE)) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12970 | if (type->memberTypes != NULL) |
| 12971 | return (type->memberTypes); |
| 12972 | else |
| 12973 | type = type->baseType; |
| 12974 | } |
| 12975 | return (NULL); |
| 12976 | } |
| 12977 | |
| 12978 | /** |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12979 | * xmlSchemaGetParticleTotalRangeMin: |
| 12980 | * @particle: the particle |
| 12981 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12982 | * Schema Component Constraint: Effective Total Range |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12983 | * (all and sequence) + (choice) |
| 12984 | * |
| 12985 | * Returns the minimun Effective Total Range. |
| 12986 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 12987 | static int |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12988 | xmlSchemaGetParticleTotalRangeMin(xmlSchemaParticlePtr particle) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 12989 | { |
| 12990 | if ((particle->children == NULL) || |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12991 | (particle->minOccurs == 0)) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 12992 | return (0); |
| 12993 | if (particle->children->type == XML_SCHEMA_TYPE_CHOICE) { |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12994 | int min = -1, cur; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12995 | xmlSchemaParticlePtr part = |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 12996 | (xmlSchemaParticlePtr) particle->children->children; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 12997 | |
| 12998 | if (part == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 12999 | return (0); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13000 | while (part != NULL) { |
| 13001 | if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) || |
| 13002 | (part->children->type == XML_SCHEMA_TYPE_ANY)) |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13003 | cur = part->minOccurs; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13004 | else |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13005 | cur = xmlSchemaGetParticleTotalRangeMin(part); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13006 | if (cur == 0) |
| 13007 | return (0); |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13008 | if ((min > cur) || (min == -1)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13009 | min = cur; |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13010 | part = (xmlSchemaParticlePtr) part->next; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13011 | } |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13012 | return (particle->minOccurs * min); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13013 | } else { |
| 13014 | /* <all> and <sequence> */ |
| 13015 | int sum = 0; |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13016 | xmlSchemaParticlePtr part = |
| 13017 | (xmlSchemaParticlePtr) particle->children->children; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13018 | |
| 13019 | if (part == NULL) |
| 13020 | return (0); |
| 13021 | do { |
| 13022 | if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) || |
| 13023 | (part->children->type == XML_SCHEMA_TYPE_ANY)) |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13024 | sum += part->minOccurs; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13025 | else |
| 13026 | sum += xmlSchemaGetParticleTotalRangeMin(part); |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13027 | part = (xmlSchemaParticlePtr) part->next; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13028 | } while (part != NULL); |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13029 | return (particle->minOccurs * sum); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13030 | } |
| 13031 | } |
| 13032 | |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13033 | /** |
| 13034 | * xmlSchemaGetParticleTotalRangeMax: |
| 13035 | * @particle: the particle |
| 13036 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13037 | * Schema Component Constraint: Effective Total Range |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13038 | * (all and sequence) + (choice) |
| 13039 | * |
| 13040 | * Returns the maximum Effective Total Range. |
| 13041 | */ |
| 13042 | static int |
| 13043 | xmlSchemaGetParticleTotalRangeMax(xmlSchemaParticlePtr particle) |
| 13044 | { |
| 13045 | if ((particle->children == NULL) || |
| 13046 | (particle->children->children == NULL)) |
| 13047 | return (0); |
| 13048 | if (particle->children->type == XML_SCHEMA_TYPE_CHOICE) { |
| 13049 | int max = -1, cur; |
| 13050 | xmlSchemaParticlePtr part = |
| 13051 | (xmlSchemaParticlePtr) particle->children->children; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13052 | |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13053 | for (; part != NULL; part = (xmlSchemaParticlePtr) part->next) { |
| 13054 | if (part->children == NULL) |
| 13055 | continue; |
| 13056 | if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) || |
| 13057 | (part->children->type == XML_SCHEMA_TYPE_ANY)) |
| 13058 | cur = part->maxOccurs; |
| 13059 | else |
| 13060 | cur = xmlSchemaGetParticleTotalRangeMax(part); |
| 13061 | if (cur == UNBOUNDED) |
| 13062 | return (UNBOUNDED); |
| 13063 | if ((max < cur) || (max == -1)) |
| 13064 | max = cur; |
| 13065 | } |
| 13066 | /* TODO: Handle overflows? */ |
| 13067 | return (particle->maxOccurs * max); |
| 13068 | } else { |
| 13069 | /* <all> and <sequence> */ |
| 13070 | int sum = 0, cur; |
| 13071 | xmlSchemaParticlePtr part = |
| 13072 | (xmlSchemaParticlePtr) particle->children->children; |
| 13073 | |
| 13074 | for (; part != NULL; part = (xmlSchemaParticlePtr) part->next) { |
| 13075 | if (part->children == NULL) |
| 13076 | continue; |
| 13077 | if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) || |
| 13078 | (part->children->type == XML_SCHEMA_TYPE_ANY)) |
| 13079 | cur = part->maxOccurs; |
| 13080 | else |
| 13081 | cur = xmlSchemaGetParticleTotalRangeMax(part); |
| 13082 | if (cur == UNBOUNDED) |
| 13083 | return (UNBOUNDED); |
| 13084 | if ((cur > 0) && (particle->maxOccurs == UNBOUNDED)) |
| 13085 | return (UNBOUNDED); |
| 13086 | sum += cur; |
| 13087 | } |
| 13088 | /* TODO: Handle overflows? */ |
| 13089 | return (particle->maxOccurs * sum); |
| 13090 | } |
| 13091 | } |
| 13092 | |
| 13093 | /** |
| 13094 | * xmlSchemaIsParticleEmptiable: |
| 13095 | * @particle: the particle |
| 13096 | * |
| 13097 | * Schema Component Constraint: Particle Emptiable |
| 13098 | * Checks whether the given particle is emptiable. |
| 13099 | * |
| 13100 | * Returns 1 if emptiable, 0 otherwise. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13101 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13102 | static int |
| 13103 | xmlSchemaIsParticleEmptiable(xmlSchemaParticlePtr particle) |
| 13104 | { |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13105 | /* |
| 13106 | * SPEC (1) "Its {min occurs} is 0." |
| 13107 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13108 | if ((particle == NULL) || (particle->minOccurs == 0) || |
| 13109 | (particle->children == NULL)) |
| 13110 | return (1); |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13111 | /* |
| 13112 | * SPEC (2) "Its {term} is a group and the minimum part of the |
| 13113 | * effective total range of that group, [...] is 0." |
| 13114 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13115 | if (IS_MODEL_GROUP(particle->children)) { |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13116 | if (xmlSchemaGetParticleTotalRangeMin(particle) == 0) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13117 | return (1); |
| 13118 | } |
| 13119 | return (0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13120 | } |
| 13121 | |
| 13122 | /** |
| 13123 | * xmlSchemaCheckCOSSTDerivedOK: |
| 13124 | * @type: the derived simple type definition |
| 13125 | * @baseType: the base type definition |
| 13126 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13127 | * Schema Component Constraint: |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 13128 | * Type Derivation OK (Simple) (cos-st-derived-OK) |
| 13129 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13130 | * Checks wheter @type can be validly |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13131 | * derived from @baseType. |
| 13132 | * |
| 13133 | * Returns 0 on success, an positive error code otherwise. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13134 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13135 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13136 | xmlSchemaCheckCOSSTDerivedOK(xmlSchemaTypePtr type, |
| 13137 | xmlSchemaTypePtr baseType, |
| 13138 | int subset) |
| 13139 | { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13140 | /* |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13141 | * 1 They are the same type definition. |
| 13142 | * TODO: The identy check might have to be more complex than this. |
| 13143 | */ |
| 13144 | if (type == baseType) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13145 | return (0); |
| 13146 | /* |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13147 | * 2.1 restriction is not in the subset, or in the {final} |
| 13148 | * of its own {base type definition}; |
| 13149 | */ |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13150 | if ((subset & SUBSET_RESTRICTION) || |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13151 | (xmlSchemaTypeFinalContains(type->baseType, |
| 13152 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION))) { |
| 13153 | return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13154 | } |
| 13155 | /* 2.2 */ |
| 13156 | if (type->baseType == baseType) { |
| 13157 | /* |
| 13158 | * 2.2.1 D's ·base type definition· is B. |
| 13159 | */ |
| 13160 | return (0); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13161 | } |
| 13162 | /* |
| 13163 | * 2.2.2 D's ·base type definition· is not the ·ur-type definition· |
| 13164 | * and is validly derived from B given the subset, as defined by this |
| 13165 | * constraint. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13166 | */ |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13167 | if ((! IS_ANYTYPE(type->baseType)) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13168 | (xmlSchemaCheckCOSSTDerivedOK(type->baseType, |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13169 | baseType, subset) == 0)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13170 | return (0); |
| 13171 | } |
| 13172 | /* |
| 13173 | * 2.2.3 D's {variety} is list or union and B is the ·simple ur-type |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13174 | * definition·. |
| 13175 | */ |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 13176 | if (IS_ANY_SIMPLE_TYPE(baseType) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13177 | (VARIETY_LIST(type) || VARIETY_UNION(type))) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13178 | return (0); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13179 | } |
| 13180 | /* |
| 13181 | * 2.2.4 B's {variety} is union and D is validly derived from a type |
| 13182 | * definition in B's {member type definitions} given the subset, as |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13183 | * defined by this constraint. |
| 13184 | * |
| 13185 | * NOTE: This seems not to involve built-in types, since there is no |
| 13186 | * built-in Union Simple Type. |
| 13187 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13188 | if (VARIETY_UNION(baseType)) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13189 | xmlSchemaTypeLinkPtr cur; |
| 13190 | |
| 13191 | cur = baseType->memberTypes; |
| 13192 | while (cur != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13193 | if (xmlSchemaCheckCOSSTDerivedOK(type, cur->type, subset) == 0) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13194 | return (0); |
| 13195 | cur = cur->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13196 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13197 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13198 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13199 | return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_2); |
| 13200 | } |
| 13201 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13202 | /** |
| 13203 | * xmlSchemaCheckTypeDefCircularInternal: |
| 13204 | * @pctxt: the schema parser context |
| 13205 | * @ctxtType: the type definition |
| 13206 | * @ancestor: an ancestor of @ctxtType |
| 13207 | * |
| 13208 | * Checks st-props-correct (2) + ct-props-correct (3). |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13209 | * Circular type definitions are not allowed. |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13210 | * |
| 13211 | * Returns XML_SCHEMAP_ST_PROPS_CORRECT_2 if the given type is |
| 13212 | * circular, 0 otherwise. |
| 13213 | */ |
| 13214 | static int |
| 13215 | xmlSchemaCheckTypeDefCircularInternal(xmlSchemaParserCtxtPtr pctxt, |
| 13216 | xmlSchemaTypePtr ctxtType, |
| 13217 | xmlSchemaTypePtr ancestor) |
| 13218 | { |
| 13219 | int ret; |
| 13220 | |
| 13221 | if ((ancestor == NULL) || (ancestor->type == XML_SCHEMA_TYPE_BASIC)) |
| 13222 | return (0); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13223 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13224 | if (ctxtType == ancestor) { |
| 13225 | xmlSchemaPCustomErr(pctxt, |
| 13226 | XML_SCHEMAP_ST_PROPS_CORRECT_2, |
| 13227 | NULL, ctxtType, GET_NODE(ctxtType), |
| 13228 | "The definition is circular", NULL); |
| 13229 | return (XML_SCHEMAP_ST_PROPS_CORRECT_2); |
| 13230 | } |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 13231 | if (ancestor->flags & XML_SCHEMAS_TYPE_MARKED) { |
| 13232 | /* |
| 13233 | * Avoid inifinite recursion on circular types not yet checked. |
| 13234 | */ |
| 13235 | return (0); |
| 13236 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13237 | ancestor->flags |= XML_SCHEMAS_TYPE_MARKED; |
| 13238 | ret = xmlSchemaCheckTypeDefCircularInternal(pctxt, ctxtType, |
| 13239 | ancestor->baseType); |
| 13240 | ancestor->flags ^= XML_SCHEMAS_TYPE_MARKED; |
| 13241 | return (ret); |
| 13242 | } |
| 13243 | |
| 13244 | /** |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 13245 | * xmlSchemaCheckTypeDefCircular: |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13246 | * @item: the complex/simple type definition |
| 13247 | * @ctxt: the parser context |
| 13248 | * @name: the name |
| 13249 | * |
| 13250 | * Checks for circular type definitions. |
| 13251 | */ |
| 13252 | static void |
| 13253 | xmlSchemaCheckTypeDefCircular(xmlSchemaTypePtr item, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13254 | xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13255 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 13256 | { |
| 13257 | if ((item == NULL) || |
| 13258 | ((item->type != XML_SCHEMA_TYPE_COMPLEX) && |
| 13259 | (item->type != XML_SCHEMA_TYPE_SIMPLE))) |
| 13260 | return; |
| 13261 | xmlSchemaCheckTypeDefCircularInternal(ctxt, item, item->baseType); |
| 13262 | |
| 13263 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13264 | |
| 13265 | /** |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 13266 | * xmlSchemaResolveTypeDefs: |
| 13267 | * @item: the complex/simple type definition |
| 13268 | * @ctxt: the parser context |
| 13269 | * @name: the name |
| 13270 | * |
| 13271 | * Checks for circular type definitions. |
| 13272 | */ |
| 13273 | static void |
| 13274 | xmlSchemaResolveTypeDefs(xmlSchemaTypePtr typeDef, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13275 | xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 13276 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 13277 | { |
| 13278 | if (typeDef == NULL) |
| 13279 | return; |
| 13280 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 13281 | /* |
| 13282 | * Resolve the base type. |
| 13283 | */ |
| 13284 | if (typeDef->baseType == NULL) { |
| 13285 | typeDef->baseType = xmlSchemaGetType(ctxt->schema, |
| 13286 | typeDef->base, typeDef->baseNs); |
| 13287 | if (typeDef->baseType == NULL) { |
| 13288 | xmlSchemaPResCompAttrErr(ctxt, |
| 13289 | XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13290 | typeDef, typeDef->node, |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 13291 | "base", typeDef->base, typeDef->baseNs, |
| 13292 | XML_SCHEMA_TYPE_SIMPLE, NULL); |
| 13293 | return; |
| 13294 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13295 | } |
| 13296 | if (IS_SIMPLE_TYPE(typeDef)) { |
| 13297 | if (VARIETY_UNION(typeDef)) { |
| 13298 | /* |
| 13299 | * Resolve the memberTypes. |
| 13300 | */ |
| 13301 | xmlSchemaResolveUnionMemberTypes(ctxt, typeDef); |
| 13302 | return; |
| 13303 | } else if (VARIETY_LIST(typeDef)) { |
| 13304 | /* |
| 13305 | * Resolve the itemType. |
| 13306 | */ |
| 13307 | if ((typeDef->subtypes == NULL) && (typeDef->ref != NULL)) { |
| 13308 | typeDef->subtypes = xmlSchemaGetType(ctxt->schema, |
| 13309 | typeDef->ref, typeDef->refNs); |
| 13310 | if ((typeDef->subtypes == NULL) || |
| 13311 | (! IS_SIMPLE_TYPE(typeDef->subtypes))) { |
| 13312 | typeDef->subtypes = NULL; |
| 13313 | xmlSchemaPResCompAttrErr(ctxt, |
| 13314 | XML_SCHEMAP_SRC_RESOLVE, |
| 13315 | typeDef, typeDef->node, |
| 13316 | "itemType", typeDef->ref, typeDef->refNs, |
| 13317 | XML_SCHEMA_TYPE_SIMPLE, NULL); |
| 13318 | } |
| 13319 | } |
| 13320 | return; |
| 13321 | } |
| 13322 | } |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 13323 | } |
| 13324 | |
| 13325 | |
| 13326 | |
| 13327 | /** |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13328 | * xmlSchemaCheckSTPropsCorrect: |
| 13329 | * @ctxt: the schema parser context |
| 13330 | * @type: the simple type definition |
| 13331 | * |
| 13332 | * Checks st-props-correct. |
| 13333 | * |
| 13334 | * Returns 0 if the properties are correct, |
| 13335 | * if not, a positive error code and -1 on internal |
| 13336 | * errors. |
| 13337 | */ |
| 13338 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13339 | xmlSchemaCheckSTPropsCorrect(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13340 | xmlSchemaTypePtr type) |
| 13341 | { |
| 13342 | xmlSchemaTypePtr baseType = type->baseType, anySimpleType, |
| 13343 | anyType; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13344 | xmlChar *str = NULL; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13345 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13346 | /* STATE: error funcs converted. */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13347 | /* |
| 13348 | * Schema Component Constraint: Simple Type Definition Properties Correct |
| 13349 | * |
| 13350 | * NOTE: This is somehow redundant, since we actually built a simple type |
| 13351 | * to have all the needed information; this acts as an self test. |
| 13352 | */ |
| 13353 | anySimpleType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 13354 | anyType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13355 | /* Base type: If the datatype has been ·derived· by ·restriction· |
| 13356 | * then the Simple Type Definition component from which it is ·derived·, |
| 13357 | * otherwise the Simple Type Definition for anySimpleType (§4.1.6). |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13358 | */ |
| 13359 | if (baseType == NULL) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13360 | /* |
| 13361 | * TODO: Think about: "modulo the impact of Missing |
| 13362 | * Sub-components (§5.3)." |
| 13363 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13364 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13365 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13366 | NULL, type, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13367 | "No base type existent", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13368 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13369 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13370 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13371 | if (! IS_SIMPLE_TYPE(baseType)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13372 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13373 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13374 | NULL, type, NULL, |
| 13375 | "The base type '%s' is not a simple type", |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13376 | xmlSchemaGetComponentQName(&str, baseType)); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13377 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13378 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
| 13379 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13380 | if ( (VARIETY_LIST(type) || VARIETY_UNION(type)) && |
| 13381 | ((type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) == 0) && |
| 13382 | (! IS_ANY_SIMPLE_TYPE(baseType))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13383 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13384 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13385 | NULL, type, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13386 | "A type, derived by list or union, must have" |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13387 | "the simple ur-type definition as base type, not '%s'", |
| 13388 | xmlSchemaGetComponentQName(&str, baseType)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13389 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13390 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
| 13391 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13392 | /* |
| 13393 | * Variety: One of {atomic, list, union}. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13394 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13395 | if ((! VARIETY_ATOMIC(type)) && (! VARIETY_UNION(type)) && |
| 13396 | (! VARIETY_LIST(type))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13397 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13398 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13399 | NULL, type, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13400 | "The variety is absent", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13401 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
| 13402 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13403 | /* TODO: Finish this. Hmm, is this finished? */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13404 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13405 | /* |
| 13406 | * 3 The {final} of the {base type definition} must not contain restriction. |
| 13407 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13408 | if (xmlSchemaTypeFinalContains(baseType, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13409 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
| 13410 | xmlSchemaPCustomErr(ctxt, |
| 13411 | XML_SCHEMAP_ST_PROPS_CORRECT_3, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13412 | NULL, type, NULL, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13413 | "The 'final' of its base type '%s' must not contain " |
| 13414 | "'restriction'", |
| 13415 | xmlSchemaGetComponentQName(&str, baseType)); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13416 | FREE_AND_NULL(str) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13417 | return (XML_SCHEMAP_ST_PROPS_CORRECT_3); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13418 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13419 | |
| 13420 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13421 | * 2 All simple type definitions must be derived ultimately from the ·simple |
| 13422 | * ur-type definition (so· circular definitions are disallowed). That is, it |
| 13423 | * must be possible to reach a built-in primitive datatype or the ·simple |
| 13424 | * ur-type definition· by repeatedly following the {base type definition}. |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13425 | * |
| 13426 | * NOTE: this is done in xmlSchemaCheckTypeDefCircular(). |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13427 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13428 | return (0); |
| 13429 | } |
| 13430 | |
| 13431 | /** |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13432 | * xmlSchemaCheckCOSSTRestricts: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13433 | * @ctxt: the schema parser context |
| 13434 | * @type: the simple type definition |
| 13435 | * |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 13436 | * Schema Component Constraint: |
| 13437 | * Derivation Valid (Restriction, Simple) (cos-st-restricts) |
| 13438 | |
| 13439 | * Checks if the given @type (simpleType) is derived validly by restriction. |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13440 | * STATUS: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13441 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13442 | * Returns -1 on internal errors, 0 if the type is validly derived, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13443 | * a positive error code otherwise. |
| 13444 | */ |
| 13445 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13446 | xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr pctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13447 | xmlSchemaTypePtr type) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13448 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13449 | xmlChar *str = NULL; |
| 13450 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13451 | if (type->type != XML_SCHEMA_TYPE_SIMPLE) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13452 | PERROR_INT("xmlSchemaCheckCOSSTRestricts", |
| 13453 | "given type is not a user-derived simpleType"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13454 | return (-1); |
| 13455 | } |
| 13456 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13457 | if (VARIETY_ATOMIC(type)) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13458 | xmlSchemaTypePtr primitive; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13459 | /* |
| 13460 | * 1.1 The {base type definition} must be an atomic simple |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13461 | * type definition or a built-in primitive datatype. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13462 | */ |
| 13463 | if (! VARIETY_ATOMIC(type->baseType)) { |
| 13464 | xmlSchemaPCustomErr(pctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13465 | XML_SCHEMAP_COS_ST_RESTRICTS_1_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13466 | NULL, type, NULL, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13467 | "The base type '%s' is not an atomic simple type", |
| 13468 | xmlSchemaGetComponentQName(&str, type->baseType)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13469 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13470 | return (XML_SCHEMAP_COS_ST_RESTRICTS_1_1); |
| 13471 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13472 | /* 1.2 The {final} of the {base type definition} must not contain |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13473 | * restriction. |
| 13474 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13475 | /* OPTIMIZE TODO : This is already done in xmlSchemaCheckStPropsCorrect */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13476 | if (xmlSchemaTypeFinalContains(type->baseType, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13477 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13478 | xmlSchemaPCustomErr(pctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13479 | XML_SCHEMAP_COS_ST_RESTRICTS_1_2, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13480 | NULL, type, NULL, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13481 | "The final of its base type '%s' must not contain 'restriction'", |
| 13482 | xmlSchemaGetComponentQName(&str, type->baseType)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13483 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13484 | return (XML_SCHEMAP_COS_ST_RESTRICTS_1_2); |
| 13485 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13486 | |
| 13487 | /* |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13488 | * 1.3.1 DF must be an allowed constraining facet for the {primitive |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13489 | * type definition}, as specified in the appropriate subsection of 3.2 |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13490 | * Primitive datatypes. |
| 13491 | */ |
| 13492 | if (type->facets != NULL) { |
| 13493 | xmlSchemaFacetPtr facet; |
| 13494 | int ok = 1; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13495 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13496 | primitive = xmlSchemaGetPrimitiveType(type); |
| 13497 | if (primitive == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13498 | PERROR_INT("xmlSchemaCheckCOSSTRestricts", |
| 13499 | "failed to get primitive type"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13500 | return (-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13501 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13502 | facet = type->facets; |
| 13503 | do { |
| 13504 | if (xmlSchemaIsBuiltInTypeFacet(primitive, facet->type) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13505 | ok = 0; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13506 | xmlSchemaPIllegalFacetAtomicErr(pctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13507 | XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13508 | NULL, type, primitive, facet); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13509 | } |
| 13510 | facet = facet->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13511 | } while (facet != NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13512 | if (ok == 0) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13513 | return (XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13514 | } |
| 13515 | /* |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 13516 | * SPEC (1.3.2) "If there is a facet of the same kind in the {facets} |
| 13517 | * of the {base type definition} (call this BF),then the DF's {value} |
| 13518 | * must be a valid restriction of BF's {value} as defined in |
| 13519 | * [XML Schemas: Datatypes]." |
| 13520 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13521 | * NOTE (1.3.2) Facet derivation constraints are currently handled in |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 13522 | * xmlSchemaDeriveAndValidateFacets() |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13523 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13524 | } else if (VARIETY_LIST(type)) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13525 | xmlSchemaTypePtr itemType = NULL; |
| 13526 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13527 | itemType = type->subtypes; |
| 13528 | if ((itemType == NULL) || (! IS_SIMPLE_TYPE(itemType))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13529 | PERROR_INT("xmlSchemaCheckCOSSTRestricts", |
| 13530 | "failed to evaluate the item type"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13531 | return (-1); |
| 13532 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13533 | if (IS_NOT_TYPEFIXED(itemType)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13534 | xmlSchemaTypeFixup(itemType, pctxt, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13535 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13536 | * 2.1 The {item type definition} must have a {variety} of atomic or |
| 13537 | * union (in which case all the {member type definitions} |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13538 | * must be atomic). |
| 13539 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13540 | if ((! VARIETY_ATOMIC(itemType)) && |
| 13541 | (! VARIETY_UNION(itemType))) { |
| 13542 | xmlSchemaPCustomErr(pctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13543 | XML_SCHEMAP_COS_ST_RESTRICTS_2_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13544 | NULL, type, NULL, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13545 | "The item type '%s' does not have a variety of atomic or union", |
| 13546 | xmlSchemaGetComponentQName(&str, itemType)); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13547 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13548 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13549 | } else if (VARIETY_UNION(itemType)) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13550 | xmlSchemaTypeLinkPtr member; |
| 13551 | |
| 13552 | member = itemType->memberTypes; |
| 13553 | while (member != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13554 | if (! VARIETY_ATOMIC(member->type)) { |
| 13555 | xmlSchemaPCustomErr(pctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13556 | XML_SCHEMAP_COS_ST_RESTRICTS_2_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13557 | NULL, type, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13558 | "The item type is a union type, but the " |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13559 | "member type '%s' of this item type is not atomic", |
| 13560 | xmlSchemaGetComponentQName(&str, member->type)); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13561 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13562 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1); |
| 13563 | } |
| 13564 | member = member->next; |
| 13565 | } |
| 13566 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13567 | |
| 13568 | if (IS_ANY_SIMPLE_TYPE(type->baseType)) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13569 | xmlSchemaFacetPtr facet; |
| 13570 | /* |
| 13571 | * This is the case if we have: <simpleType><list .. |
| 13572 | */ |
| 13573 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13574 | * 2.3.1 |
| 13575 | * 2.3.1.1 The {final} of the {item type definition} must not |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13576 | * contain list. |
| 13577 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13578 | if (xmlSchemaTypeFinalContains(itemType, |
| 13579 | XML_SCHEMAS_TYPE_FINAL_LIST)) { |
| 13580 | xmlSchemaPCustomErr(pctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13581 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13582 | NULL, type, NULL, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13583 | "The final of its item type '%s' must not contain 'list'", |
| 13584 | xmlSchemaGetComponentQName(&str, itemType)); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13585 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13586 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1); |
| 13587 | } |
| 13588 | /* |
| 13589 | * 2.3.1.2 The {facets} must only contain the whiteSpace |
| 13590 | * facet component. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13591 | * OPTIMIZE TODO: the S4S already disallows any facet |
| 13592 | * to be specified. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13593 | */ |
| 13594 | if (type->facets != NULL) { |
| 13595 | facet = type->facets; |
| 13596 | do { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13597 | if (facet->type != XML_SCHEMA_FACET_WHITESPACE) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13598 | xmlSchemaPIllegalFacetListUnionErr(pctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13599 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13600 | NULL, type, facet); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13601 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2); |
| 13602 | } |
| 13603 | facet = facet->next; |
| 13604 | } while (facet != NULL); |
| 13605 | } |
| 13606 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13607 | * MAYBE TODO: (Hmm, not really) Datatypes states: |
| 13608 | * A ·list· datatype can be ·derived· from an ·atomic· datatype |
| 13609 | * whose ·lexical space· allows space (such as string or anyURI)or |
| 13610 | * a ·union· datatype any of whose {member type definitions}'s |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13611 | * ·lexical space· allows space. |
| 13612 | */ |
| 13613 | } else { |
| 13614 | /* |
| 13615 | * This is the case if we have: <simpleType><restriction ... |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13616 | * I.e. the variety of "list" is inherited. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13617 | */ |
| 13618 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13619 | * 2.3.2 |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13620 | * 2.3.2.1 The {base type definition} must have a {variety} of list. |
| 13621 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13622 | if (! VARIETY_LIST(type->baseType)) { |
| 13623 | xmlSchemaPCustomErr(pctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13624 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13625 | NULL, type, NULL, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13626 | "The base type '%s' must be a list type", |
| 13627 | xmlSchemaGetComponentQName(&str, type->baseType)); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13628 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13629 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1); |
| 13630 | } |
| 13631 | /* |
| 13632 | * 2.3.2.2 The {final} of the {base type definition} must not |
| 13633 | * contain restriction. |
| 13634 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13635 | if (xmlSchemaTypeFinalContains(type->baseType, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13636 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13637 | xmlSchemaPCustomErr(pctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13638 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13639 | NULL, type, NULL, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13640 | "The 'final' of the base type '%s' must not contain 'restriction'", |
| 13641 | xmlSchemaGetComponentQName(&str, type->baseType)); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13642 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13643 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2); |
| 13644 | } |
| 13645 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13646 | * 2.3.2.3 The {item type definition} must be validly derived |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13647 | * from the {base type definition}'s {item type definition} given |
| 13648 | * the empty set, as defined in Type Derivation OK (Simple) (§3.14.6). |
| 13649 | */ |
| 13650 | { |
| 13651 | xmlSchemaTypePtr baseItemType; |
| 13652 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13653 | baseItemType = type->baseType->subtypes; |
| 13654 | if ((baseItemType == NULL) || (! IS_SIMPLE_TYPE(baseItemType))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13655 | PERROR_INT("xmlSchemaCheckCOSSTRestricts", |
| 13656 | "failed to eval the item type of a base type"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13657 | return (-1); |
| 13658 | } |
| 13659 | if ((itemType != baseItemType) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13660 | (xmlSchemaCheckCOSSTDerivedOK(itemType, |
| 13661 | baseItemType, 0) != 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13662 | xmlChar *strBIT = NULL, *strBT = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13663 | xmlSchemaPCustomErrExt(pctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13664 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13665 | NULL, type, NULL, |
| 13666 | "The item type '%s' is not validly derived from " |
| 13667 | "the item type '%s' of the base type '%s'", |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13668 | xmlSchemaGetComponentQName(&str, itemType), |
| 13669 | xmlSchemaGetComponentQName(&strBIT, baseItemType), |
| 13670 | xmlSchemaGetComponentQName(&strBT, type->baseType)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13671 | |
| 13672 | FREE_AND_NULL(str) |
| 13673 | FREE_AND_NULL(strBIT) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13674 | FREE_AND_NULL(strBT) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13675 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3); |
| 13676 | } |
| 13677 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13678 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13679 | if (type->facets != NULL) { |
| 13680 | xmlSchemaFacetPtr facet; |
| 13681 | int ok = 1; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13682 | /* |
| 13683 | * 2.3.2.4 Only length, minLength, maxLength, whiteSpace, pattern |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13684 | * and enumeration facet components are allowed among the {facets}. |
| 13685 | */ |
| 13686 | facet = type->facets; |
| 13687 | do { |
| 13688 | switch (facet->type) { |
| 13689 | case XML_SCHEMA_FACET_LENGTH: |
| 13690 | case XML_SCHEMA_FACET_MINLENGTH: |
| 13691 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 13692 | case XML_SCHEMA_FACET_WHITESPACE: |
| 13693 | /* |
| 13694 | * TODO: 2.5.1.2 List datatypes |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13695 | * The value of ·whiteSpace· is fixed to the value collapse. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13696 | */ |
| 13697 | case XML_SCHEMA_FACET_PATTERN: |
| 13698 | case XML_SCHEMA_FACET_ENUMERATION: |
| 13699 | break; |
| 13700 | default: { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13701 | xmlSchemaPIllegalFacetListUnionErr(pctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13702 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13703 | NULL, type, facet); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13704 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13705 | * We could return, but it's nicer to report all |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13706 | * invalid facets. |
| 13707 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13708 | ok = 0; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13709 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13710 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13711 | facet = facet->next; |
| 13712 | } while (facet != NULL); |
| 13713 | if (ok == 0) |
| 13714 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4); |
| 13715 | /* |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 13716 | * SPEC (2.3.2.5) (same as 1.3.2) |
| 13717 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13718 | * NOTE (2.3.2.5) This is currently done in |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 13719 | * xmlSchemaDeriveAndValidateFacets() |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13720 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13721 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13722 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13723 | } else if (VARIETY_UNION(type)) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13724 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13725 | * 3.1 The {member type definitions} must all have {variety} of |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13726 | * atomic or list. |
| 13727 | */ |
| 13728 | xmlSchemaTypeLinkPtr member; |
| 13729 | |
| 13730 | member = type->memberTypes; |
| 13731 | while (member != NULL) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13732 | if (IS_NOT_TYPEFIXED(member->type)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13733 | xmlSchemaTypeFixup(member->type, pctxt, NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13734 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13735 | if ((! VARIETY_ATOMIC(member->type)) && |
| 13736 | (! VARIETY_LIST(member->type))) { |
| 13737 | xmlSchemaPCustomErr(pctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13738 | XML_SCHEMAP_COS_ST_RESTRICTS_3_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13739 | NULL, type, NULL, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13740 | "The member type '%s' is neither an atomic, nor a list type", |
| 13741 | xmlSchemaGetComponentQName(&str, member->type)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13742 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13743 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_1); |
| 13744 | } |
| 13745 | member = member->next; |
| 13746 | } |
| 13747 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13748 | * 3.3.1 If the {base type definition} is the ·simple ur-type |
| 13749 | * definition· |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13750 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13751 | if (type->baseType->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13752 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13753 | * 3.3.1.1 All of the {member type definitions} must have a |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13754 | * {final} which does not contain union. |
| 13755 | */ |
| 13756 | member = type->memberTypes; |
| 13757 | while (member != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13758 | if (xmlSchemaTypeFinalContains(member->type, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13759 | XML_SCHEMAS_TYPE_FINAL_UNION)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13760 | xmlSchemaPCustomErr(pctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13761 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13762 | NULL, type, NULL, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13763 | "The 'final' of member type '%s' contains 'union'", |
| 13764 | xmlSchemaGetComponentQName(&str, member->type)); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13765 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13766 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1); |
| 13767 | } |
| 13768 | member = member->next; |
| 13769 | } |
| 13770 | /* |
| 13771 | * 3.3.1.2 The {facets} must be empty. |
| 13772 | */ |
| 13773 | if (type->facetSet != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13774 | xmlSchemaPCustomErr(pctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13775 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13776 | NULL, type, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13777 | "No facets allowed", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13778 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2); |
| 13779 | } |
| 13780 | } else { |
| 13781 | /* |
| 13782 | * 3.3.2.1 The {base type definition} must have a {variety} of union. |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13783 | * I.e. the variety of "list" is inherited. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13784 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13785 | if (! VARIETY_UNION(type->baseType)) { |
| 13786 | xmlSchemaPCustomErr(pctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13787 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13788 | NULL, type, NULL, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13789 | "The base type '%s' is not a union type", |
| 13790 | xmlSchemaGetComponentQName(&str, type->baseType)); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13791 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13792 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1); |
| 13793 | } |
| 13794 | /* |
| 13795 | * 3.3.2.2 The {final} of the {base type definition} must not contain restriction. |
| 13796 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13797 | if (xmlSchemaTypeFinalContains(type->baseType, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13798 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13799 | xmlSchemaPCustomErr(pctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13800 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13801 | NULL, type, NULL, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13802 | "The 'final' of its base type '%s' must not contain 'restriction'", |
| 13803 | xmlSchemaGetComponentQName(&str, type->baseType)); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13804 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13805 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2); |
| 13806 | } |
| 13807 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13808 | * 3.3.2.3 The {member type definitions}, in order, must be validly |
| 13809 | * derived from the corresponding type definitions in the {base |
| 13810 | * type definition}'s {member type definitions} given the empty set, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13811 | * as defined in Type Derivation OK (Simple) (§3.14.6). |
| 13812 | */ |
| 13813 | { |
| 13814 | xmlSchemaTypeLinkPtr baseMember; |
| 13815 | |
| 13816 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13817 | * OPTIMIZE: if the type is restricting, it has no local defined |
| 13818 | * member types and inherits the member types of the base type; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13819 | * thus a check for equality can be skipped. |
| 13820 | */ |
| 13821 | /* |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 13822 | * Even worse: I cannot see a scenario where a restricting |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13823 | * union simple type can have other member types as the member |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13824 | * types of it's base type. This check seems not necessary with |
| 13825 | * respect to the derivation process in libxml2. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 13826 | * But necessary if constructing types with an API. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13827 | */ |
| 13828 | if (type->memberTypes != NULL) { |
| 13829 | member = type->memberTypes; |
| 13830 | baseMember = xmlSchemaGetUnionSimpleTypeMemberTypes(type->baseType); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13831 | if ((member == NULL) && (baseMember != NULL)) { |
| 13832 | PERROR_INT("xmlSchemaCheckCOSSTRestricts", |
| 13833 | "different number of member types in base"); |
| 13834 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13835 | while (member != NULL) { |
| 13836 | if (baseMember == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13837 | PERROR_INT("xmlSchemaCheckCOSSTRestricts", |
| 13838 | "different number of member types in base"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13839 | } |
| 13840 | if ((member->type != baseMember->type) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13841 | (xmlSchemaCheckCOSSTDerivedOK( |
| 13842 | member->type, baseMember->type, 0) != 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13843 | xmlChar *strBMT = NULL, *strBT = NULL; |
| 13844 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13845 | xmlSchemaPCustomErrExt(pctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13846 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3, |
| 13847 | NULL, type, NULL, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13848 | "The member type %s is not validly " |
| 13849 | "derived from its corresponding member " |
| 13850 | "type %s of the base type %s", |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13851 | xmlSchemaGetComponentQName(&str, member->type), |
| 13852 | xmlSchemaGetComponentQName(&strBMT, baseMember->type), |
| 13853 | xmlSchemaGetComponentQName(&strBT, type->baseType)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13854 | FREE_AND_NULL(str) |
| 13855 | FREE_AND_NULL(strBMT) |
| 13856 | FREE_AND_NULL(strBT) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13857 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13858 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13859 | member = member->next; |
| 13860 | baseMember = baseMember->next; |
| 13861 | } |
| 13862 | } |
| 13863 | } |
| 13864 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13865 | * 3.3.2.4 Only pattern and enumeration facet components are |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13866 | * allowed among the {facets}. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13867 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13868 | if (type->facets != NULL) { |
| 13869 | xmlSchemaFacetPtr facet; |
| 13870 | int ok = 1; |
| 13871 | |
| 13872 | facet = type->facets; |
| 13873 | do { |
| 13874 | if ((facet->type != XML_SCHEMA_FACET_PATTERN) && |
| 13875 | (facet->type != XML_SCHEMA_FACET_ENUMERATION)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13876 | xmlSchemaPIllegalFacetListUnionErr(pctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13877 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13878 | NULL, type, facet); |
| 13879 | ok = 0; |
| 13880 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13881 | facet = facet->next; |
| 13882 | } while (facet != NULL); |
| 13883 | if (ok == 0) |
| 13884 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13885 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13886 | } |
| 13887 | /* |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 13888 | * SPEC (3.3.2.5) (same as 1.3.2) |
| 13889 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13890 | * NOTE (3.3.2.5) This is currently done in |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 13891 | * xmlSchemaDeriveAndValidateFacets() |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13892 | */ |
| 13893 | } |
| 13894 | } |
| 13895 | |
| 13896 | return (0); |
| 13897 | } |
| 13898 | |
| 13899 | /** |
| 13900 | * xmlSchemaCheckSRCSimpleType: |
| 13901 | * @ctxt: the schema parser context |
| 13902 | * @type: the simple type definition |
| 13903 | * |
| 13904 | * Checks crc-simple-type constraints. |
| 13905 | * |
| 13906 | * Returns 0 if the constraints are satisfied, |
| 13907 | * if not a positive error code and -1 on internal |
| 13908 | * errors. |
| 13909 | */ |
| 13910 | static int |
| 13911 | xmlSchemaCheckSRCSimpleType(xmlSchemaParserCtxtPtr ctxt, |
| 13912 | xmlSchemaTypePtr type) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13913 | { |
| 13914 | /* |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13915 | * src-simple-type.1 The corresponding simple type definition, if any, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13916 | * must satisfy the conditions set out in Constraints on Simple Type |
| 13917 | * Definition Schema Components (§3.14.6). |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13918 | */ |
| 13919 | if ((xmlSchemaCheckSTPropsCorrect(ctxt, type) != 0) || |
| 13920 | (xmlSchemaCheckCOSSTRestricts(ctxt, type) != 0)) { |
| 13921 | /* |
| 13922 | * TODO: Removed this, since it got annoying to get an |
| 13923 | * extra error report, if anything failed until now. |
| 13924 | * Enable this if needed. |
| 13925 | */ |
| 13926 | /* |
| 13927 | xmlSchemaPErr(ctxt, type->node, |
| 13928 | XML_SCHEMAP_SRC_SIMPLE_TYPE_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13929 | "Simple type '%s' does not satisfy the constraints " |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13930 | "on simple type definitions.\n", |
| 13931 | type->name, NULL); |
| 13932 | */ |
| 13933 | return (XML_SCHEMAP_SRC_SIMPLE_TYPE_1); |
| 13934 | } |
| 13935 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13936 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13937 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13938 | * src-simple-type.2 If the <restriction> alternative is chosen, |
| 13939 | * either it must have a base [attribute] or a <simpleType> among its |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13940 | * [children], but not both. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13941 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13942 | /* |
| 13943 | * XML_SCHEMAP_SRC_SIMPLE_TYPE_2 |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13944 | * NOTE: This is checked in the parse function of <restriction>. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13945 | */ |
| 13946 | } else if (VARIETY_LIST(type)) { |
| 13947 | /* src-simple-type.3 If the <list> alternative is chosen, either it must have |
| 13948 | * an itemType [attribute] or a <simpleType> among its [children], |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13949 | * but not both. |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13950 | * |
| 13951 | * REMOVED: This is checked in the parse function of <list>. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13952 | */ |
| 13953 | } else if (VARIETY_UNION(type)) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13954 | xmlSchemaTypeLinkPtr member; |
| 13955 | xmlSchemaTypePtr ancestor, anySimpleType; |
| 13956 | |
| 13957 | anySimpleType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 13958 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13959 | /* src-simple-type.4 Circular union type definition is disallowed. That is, if |
| 13960 | * the <union> alternative is chosen, there must not be any entries |
| 13961 | * in the memberTypes [attribute] at any depth which resolve to the |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13962 | * component corresponding to the <simpleType>. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13963 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13964 | member = type->memberTypes; |
| 13965 | while (member != NULL) { |
| 13966 | ancestor = member->type; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13967 | while ((ancestor != NULL) && (ancestor->type != XML_SCHEMA_TYPE_BASIC)) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13968 | if (ancestor == type) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13969 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13970 | XML_SCHEMAP_SRC_SIMPLE_TYPE_4, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13971 | NULL, type, NULL, |
| 13972 | "The definition is circular", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13973 | return (XML_SCHEMAP_SRC_SIMPLE_TYPE_4); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 13974 | } |
| 13975 | if (IS_NOT_TYPEFIXED(ancestor)) |
| 13976 | xmlSchemaTypeFixup(ancestor, ctxt, NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13977 | if (VARIETY_LIST(ancestor)) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13978 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13979 | * TODO, FIXME: Although a list simple type must not have a union ST |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13980 | * type as item type, which in turn has a list ST as member |
| 13981 | * type, we will assume this here as well, since this check |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13982 | * was not yet performed. |
| 13983 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13984 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13985 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13986 | ancestor = ancestor->baseType; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 13987 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13988 | member = member->next; |
| 13989 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13990 | } |
| 13991 | |
| 13992 | return (0); |
| 13993 | } |
| 13994 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13995 | static int |
| 13996 | xmlSchemaCreateVCtxtOnPCtxt(xmlSchemaParserCtxtPtr ctxt) |
| 13997 | { |
| 13998 | if (ctxt->vctxt == NULL) { |
| 13999 | ctxt->vctxt = xmlSchemaNewValidCtxt(NULL); |
| 14000 | if (ctxt->vctxt == NULL) { |
| 14001 | xmlSchemaPErr(ctxt, NULL, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 14002 | XML_SCHEMAP_INTERNAL, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14003 | "Internal error: xmlSchemaCreateVCtxtOnPCtxt, " |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14004 | "failed to create a temp. validation context.\n", |
| 14005 | NULL, NULL); |
| 14006 | return (-1); |
| 14007 | } |
| 14008 | /* TODO: Pass user data. */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14009 | xmlSchemaSetValidErrors(ctxt->vctxt, ctxt->error, ctxt->warning, NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14010 | } |
| 14011 | return (0); |
| 14012 | } |
| 14013 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14014 | static int |
| 14015 | xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt, |
| 14016 | xmlNodePtr node, |
| 14017 | xmlSchemaTypePtr type, |
| 14018 | const xmlChar *value, |
| 14019 | xmlSchemaValPtr *retVal, |
| 14020 | int fireErrors, |
| 14021 | int normalize, |
| 14022 | int isNormalized); |
| 14023 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14024 | /** |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14025 | * xmlSchemaParseCheckCOSValidDefault: |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14026 | * @pctxt: the schema parser context |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14027 | * @type: the simple type definition |
| 14028 | * @value: the default value |
| 14029 | * @node: an optional node (the holder of the value) |
| 14030 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14031 | * Schema Component Constraint: Element Default Valid (Immediate) |
| 14032 | * (cos-valid-default) |
| 14033 | * This will be used by the parser only. For the validator there's |
| 14034 | * an other version. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14035 | * |
| 14036 | * Returns 0 if the constraints are satisfied, |
| 14037 | * if not, a positive error code and -1 on internal |
| 14038 | * errors. |
| 14039 | */ |
| 14040 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14041 | xmlSchemaParseCheckCOSValidDefault(xmlSchemaParserCtxtPtr pctxt, |
| 14042 | xmlNodePtr node, |
| 14043 | xmlSchemaTypePtr type, |
| 14044 | const xmlChar *value, |
| 14045 | xmlSchemaValPtr *val) |
| 14046 | { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14047 | int ret = 0; |
| 14048 | |
| 14049 | /* |
| 14050 | * cos-valid-default: |
| 14051 | * Schema Component Constraint: Element Default Valid (Immediate) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14052 | * For a string to be a valid default with respect to a type |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14053 | * definition the appropriate case among the following must be true: |
| 14054 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14055 | if IS_COMPLEX_TYPE(type) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14056 | /* |
| 14057 | * Complex type. |
| 14058 | * |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14059 | * SPEC (2.1) "its {content type} must be a simple type definition |
| 14060 | * or mixed." |
| 14061 | * SPEC (2.2.2) "If the {content type} is mixed, then the {content |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14062 | * type}'s particle must be ·emptiable· as defined by |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14063 | * Particle Emptiable (§3.9.6)." |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14064 | */ |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14065 | if ((! HAS_SIMPLE_CONTENT(type)) && |
| 14066 | ((! HAS_MIXED_CONTENT(type)) || (! IS_PARTICLE_EMPTIABLE(type)))) { |
| 14067 | /* NOTE that this covers (2.2.2) as well. */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14068 | xmlSchemaPCustomErr(pctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14069 | XML_SCHEMAP_COS_VALID_DEFAULT_2_1, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14070 | NULL, type, type->node, |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14071 | "For a string to be a valid default, the type definition " |
| 14072 | "must be a simple type or a complex type with mixed content " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14073 | "and a particle emptiable", NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14074 | return(XML_SCHEMAP_COS_VALID_DEFAULT_2_1); |
| 14075 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14076 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14077 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14078 | * 1 If the type definition is a simple type definition, then the string |
| 14079 | * must be ·valid· with respect to that definition as defined by String |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14080 | * Valid (§3.14.4). |
| 14081 | * |
| 14082 | * AND |
| 14083 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14084 | * 2.2.1 If the {content type} is a simple type definition, then the |
| 14085 | * string must be ·valid· with respect to that simple type definition |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14086 | * as defined by String Valid (§3.14.4). |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14087 | */ |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14088 | if (IS_SIMPLE_TYPE(type)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14089 | ret = xmlSchemaVCheckCVCSimpleType((xmlSchemaAbstractCtxtPtr) pctxt, node, |
| 14090 | type, value, val, 1, 1, 0); |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14091 | else if (HAS_SIMPLE_CONTENT(type)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14092 | ret = xmlSchemaVCheckCVCSimpleType((xmlSchemaAbstractCtxtPtr) pctxt, node, |
| 14093 | type->contentTypeDef, value, val, 1, 1, 0); |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14094 | else |
| 14095 | return (ret); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14096 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14097 | if (ret < 0) { |
| 14098 | PERROR_INT("xmlSchemaParseCheckCOSValidDefault", |
| 14099 | "calling xmlSchemaVCheckCVCSimpleType()"); |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 14100 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14101 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14102 | return (ret); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14103 | } |
| 14104 | |
| 14105 | /** |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14106 | * xmlSchemaCheckCTPropsCorrect: |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14107 | * @ctxt: the schema parser context |
| 14108 | * @type: the complex type definition |
| 14109 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14110 | *.(4.6) Constraints on Complex Type Definition Schema Components |
| 14111 | * Schema Component Constraint: |
| 14112 | * Complex Type Definition Properties Correct (ct-props-correct) |
| 14113 | * STATUS: (seems) complete |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14114 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14115 | * Returns 0 if the constraints are satisfied, a positive |
| 14116 | * error code if not and -1 if an internal error occured. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14117 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14118 | static int |
| 14119 | xmlSchemaCheckCTPropsCorrect(xmlSchemaParserCtxtPtr pctxt, |
| 14120 | xmlSchemaTypePtr type) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14121 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14122 | /* |
| 14123 | * TODO: Correct the error code; XML_SCHEMAP_SRC_CT_1 is used temporarily. |
| 14124 | * |
| 14125 | * SPEC (1) "The values of the properties of a complex type definition must |
| 14126 | * be as described in the property tableau in The Complex Type Definition |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14127 | * Schema Component (§3.4.1), modulo the impact of Missing |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14128 | * Sub-components (§5.3)." |
| 14129 | */ |
| 14130 | if ((type->baseType != NULL) && |
| 14131 | (IS_SIMPLE_TYPE(type->baseType)) && |
| 14132 | ((type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) == 0)) { |
| 14133 | /* |
| 14134 | * SPEC (2) "If the {base type definition} is a simple type definition, |
| 14135 | * the {derivation method} must be extension." |
| 14136 | */ |
| 14137 | xmlSchemaPCustomErr(pctxt, |
| 14138 | XML_SCHEMAP_SRC_CT_1, |
| 14139 | NULL, type, NULL, |
| 14140 | "If the base type is a simple type, the derivation method must be " |
| 14141 | "'extension'", NULL); |
| 14142 | return (XML_SCHEMAP_SRC_CT_1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14143 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14144 | /* |
| 14145 | * SPEC (3) "Circular definitions are disallowed, except for the ·ur-type |
| 14146 | * definition·. That is, it must be possible to reach the ·ur-type |
| 14147 | * definition by repeatedly following the {base type definition}." |
| 14148 | * |
| 14149 | * NOTE (3) is done in xmlSchemaCheckTypeDefCircular(). |
| 14150 | * |
| 14151 | * SPEC (4) "Two distinct attribute declarations in the {attribute uses} |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14152 | * must not have identical {name}s and {target namespace}s." |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14153 | * SPEC (5) "Two distinct attribute declarations in the {attribute uses} |
| 14154 | * must not have {type definition}s which are or are derived from ID." |
| 14155 | * |
| 14156 | * NOTE (4) and (5) are done in xmlSchemaBuildAttributeValidation(). |
| 14157 | */ |
| 14158 | return (0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14159 | } |
| 14160 | |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14161 | static int |
| 14162 | xmlSchemaAreEqualTypes(xmlSchemaTypePtr typeA, |
| 14163 | xmlSchemaTypePtr typeB) |
| 14164 | { |
| 14165 | /* |
| 14166 | * TODO: This should implement component-identity |
| 14167 | * in the future. |
| 14168 | */ |
| 14169 | if ((typeA == NULL) || (typeB == NULL)) |
| 14170 | return (0); |
| 14171 | return (typeA == typeB); |
| 14172 | } |
| 14173 | |
| 14174 | /** |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 14175 | * xmlSchemaCheckCOSCTDerivedOK: |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14176 | * @ctxt: the schema parser context |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 14177 | * @type: the to-be derived complex type definition |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14178 | * @baseType: the base complex type definition |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 14179 | * @set: the given set |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14180 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14181 | * Schema Component Constraint: |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14182 | * Type Derivation OK (Complex) (cos-ct-derived-ok) |
| 14183 | * |
| 14184 | * STATUS: completed |
| 14185 | * |
| 14186 | * Returns 0 if the constraints are satisfied, or 1 |
| 14187 | * if not. |
| 14188 | */ |
| 14189 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14190 | xmlSchemaCheckCOSCTDerivedOK(xmlSchemaTypePtr type, |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14191 | xmlSchemaTypePtr baseType, |
| 14192 | int set) |
| 14193 | { |
| 14194 | int equal = xmlSchemaAreEqualTypes(type, baseType); |
| 14195 | /* TODO: Error codes. */ |
| 14196 | /* |
| 14197 | * SPEC "For a complex type definition (call it D, for derived) |
| 14198 | * to be validly derived from a type definition (call this |
| 14199 | * B, for base) given a subset of {extension, restriction} |
| 14200 | * all of the following must be true:" |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14201 | */ |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14202 | if (! equal) { |
| 14203 | /* |
| 14204 | * SPEC (1) "If B and D are not the same type definition, then the |
| 14205 | * {derivation method} of D must not be in the subset." |
| 14206 | */ |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 14207 | if (((set & SUBSET_EXTENSION) && |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14208 | (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION)) || |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 14209 | ((set & SUBSET_RESTRICTION) && |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14210 | (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION))) |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 14211 | return (1); |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14212 | } else { |
| 14213 | /* |
| 14214 | * SPEC (2.1) "B and D must be the same type definition." |
| 14215 | */ |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 14216 | return (0); |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14217 | } |
| 14218 | /* |
| 14219 | * SPEC (2.2) "B must be D's {base type definition}." |
| 14220 | */ |
| 14221 | if (type->baseType == baseType) |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 14222 | return (0); |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14223 | /* |
| 14224 | * SPEC (2.3.1) "D's {base type definition} must not be the ·ur-type |
| 14225 | * definition·." |
| 14226 | */ |
| 14227 | if (IS_ANYTYPE(type->baseType)) |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 14228 | return (1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14229 | |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14230 | if (IS_COMPLEX_TYPE(type->baseType)) { |
| 14231 | /* |
| 14232 | * SPEC (2.3.2.1) "If D's {base type definition} is complex, then it |
| 14233 | * must be validly derived from B given the subset as defined by this |
| 14234 | * constraint." |
| 14235 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14236 | return (xmlSchemaCheckCOSCTDerivedOK(type->baseType, |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14237 | baseType, set)); |
| 14238 | } else { |
| 14239 | /* |
| 14240 | * SPEC (2.3.2.2) "If D's {base type definition} is simple, then it |
| 14241 | * must be validly derived from B given the subset as defined in Type |
| 14242 | * Derivation OK (Simple) (§3.14.6). |
| 14243 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14244 | return (xmlSchemaCheckCOSSTDerivedOK(type->baseType, baseType, set)); |
| 14245 | } |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14246 | } |
| 14247 | |
| 14248 | /** |
| 14249 | * xmlSchemaCheckCOSDerivedOK: |
| 14250 | * @type: the derived simple type definition |
| 14251 | * @baseType: the base type definition |
| 14252 | * |
| 14253 | * Calls: |
| 14254 | * Type Derivation OK (Simple) AND Type Derivation OK (Complex) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14255 | * |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14256 | * Checks wheter @type can be validly derived from @baseType. |
| 14257 | * |
| 14258 | * Returns 0 on success, an positive error code otherwise. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14259 | */ |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14260 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14261 | xmlSchemaCheckCOSDerivedOK(xmlSchemaTypePtr type, |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 14262 | xmlSchemaTypePtr baseType, |
| 14263 | int set) |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14264 | { |
| 14265 | if (IS_SIMPLE_TYPE(type)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14266 | return (xmlSchemaCheckCOSSTDerivedOK(type, baseType, set)); |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14267 | else |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14268 | return (xmlSchemaCheckCOSCTDerivedOK(type, baseType, set)); |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14269 | } |
| 14270 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14271 | /** |
| 14272 | * xmlSchemaCheckCOSCTExtends: |
| 14273 | * @ctxt: the schema parser context |
| 14274 | * @type: the complex type definition |
| 14275 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14276 | * (3.4.6) Constraints on Complex Type Definition Schema Components |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14277 | * Schema Component Constraint: |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14278 | * Derivation Valid (Extension) (cos-ct-extends) |
| 14279 | * |
| 14280 | * STATUS: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14281 | * missing: |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14282 | * (1.5) |
| 14283 | * (1.4.3.2.2.2) "Particle Valid (Extension)", which is not really needed. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14284 | * |
| 14285 | * Returns 0 if the constraints are satisfied, a positive |
| 14286 | * error code if not and -1 if an internal error occured. |
| 14287 | */ |
| 14288 | static int |
| 14289 | xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt, |
| 14290 | xmlSchemaTypePtr type) |
| 14291 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14292 | xmlSchemaTypePtr base = type->baseType; |
| 14293 | /* |
| 14294 | * TODO: Correct the error code; XML_SCHEMAP_COS_CT_EXTENDS_1_1 is used |
| 14295 | * temporarily only. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14296 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14297 | /* |
| 14298 | * SPEC (1) "If the {base type definition} is a complex type definition, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14299 | * then all of the following must be true:" |
| 14300 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14301 | if (base->type == XML_SCHEMA_TYPE_COMPLEX) { |
| 14302 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14303 | * SPEC (1.1) "The {final} of the {base type definition} must not |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14304 | * contain extension." |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14305 | */ |
| 14306 | if (base->flags & XML_SCHEMAS_TYPE_FINAL_EXTENSION) { |
| 14307 | xmlSchemaPCustomErr(ctxt, |
| 14308 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
| 14309 | NULL, type, NULL, |
| 14310 | "The 'final' of the base type definition " |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14311 | "contains 'extension'", NULL); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14312 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
| 14313 | } |
| 14314 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14315 | * SPEC (1.2) "Its {attribute uses} must be a subset of the {attribute |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14316 | * uses} |
| 14317 | * of the complex type definition itself, that is, for every attribute |
| 14318 | * use in the {attribute uses} of the {base type definition}, there |
| 14319 | * must be an attribute use in the {attribute uses} of the complex |
| 14320 | * type definition itself whose {attribute declaration} has the same |
| 14321 | * {name}, {target namespace} and {type definition} as its attribute |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14322 | * declaration" |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14323 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14324 | * NOTE (1.2): This will be already satisfied by the way the attribute |
| 14325 | * uses are extended in xmlSchemaBuildAttributeValidation(); thus this |
| 14326 | * check is not needed. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14327 | */ |
| 14328 | |
| 14329 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14330 | * SPEC (1.3) "If it has an {attribute wildcard}, the complex type |
| 14331 | * definition must also have one, and the base type definition's |
| 14332 | * {attribute wildcard}'s {namespace constraint} must be a subset |
| 14333 | * of the complex type definition's {attribute wildcard}'s {namespace |
| 14334 | * constraint}, as defined by Wildcard Subset (§3.10.6)." |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14335 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14336 | * NOTE (1.3) This is already checked in |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14337 | * xmlSchemaBuildAttributeValidation; thus this check is not needed. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14338 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14339 | * SPEC (1.4) "One of the following must be true:" |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14340 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14341 | if ((type->contentTypeDef != NULL) && |
| 14342 | (type->contentTypeDef == base->contentTypeDef)) { |
| 14343 | /* |
| 14344 | * SPEC (1.4.1) "The {content type} of the {base type definition} |
| 14345 | * and the {content type} of the complex type definition itself |
| 14346 | * must be the same simple type definition" |
| 14347 | * PASS |
| 14348 | */ |
| 14349 | } else if ((type->contentType == XML_SCHEMA_CONTENT_EMPTY) && |
| 14350 | (base->contentType == XML_SCHEMA_CONTENT_EMPTY) ) { |
| 14351 | /* |
| 14352 | * SPEC (1.4.2) "The {content type} of both the {base type |
| 14353 | * definition} and the complex type definition itself must |
| 14354 | * be empty." |
| 14355 | * PASS |
| 14356 | */ |
| 14357 | } else { |
| 14358 | /* |
| 14359 | * SPEC (1.4.3) "All of the following must be true:" |
| 14360 | */ |
| 14361 | if (type->subtypes == NULL) { |
| 14362 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14363 | * SPEC 1.4.3.1 The {content type} of the complex type |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14364 | * definition itself must specify a particle. |
| 14365 | */ |
| 14366 | xmlSchemaPCustomErr(ctxt, |
| 14367 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
| 14368 | NULL, type, NULL, |
| 14369 | "The content type must specify a particle", NULL); |
| 14370 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
| 14371 | } |
| 14372 | /* |
| 14373 | * SPEC (1.4.3.2) "One of the following must be true:" |
| 14374 | */ |
| 14375 | if (base->contentType == XML_SCHEMA_CONTENT_EMPTY) { |
| 14376 | /* |
| 14377 | * SPEC (1.4.3.2.1) "The {content type} of the {base type |
| 14378 | * definition} must be empty. |
| 14379 | * PASS |
| 14380 | */ |
| 14381 | } else { |
| 14382 | /* |
| 14383 | * SPEC (1.4.3.2.2) "All of the following must be true:" |
| 14384 | */ |
| 14385 | if ((type->contentType != base->contentType) || |
| 14386 | ((type->contentType != XML_SCHEMA_CONTENT_MIXED) && |
| 14387 | (type->contentType != XML_SCHEMA_CONTENT_ELEMENTS))) { |
| 14388 | /* |
| 14389 | * SPEC (1.4.3.2.2.1) "Both {content type}s must be mixed |
| 14390 | * or both must be element-only." |
| 14391 | */ |
| 14392 | xmlSchemaPCustomErr(ctxt, |
| 14393 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
| 14394 | NULL, type, NULL, |
| 14395 | "The content type of both, the type and its base " |
| 14396 | "type, must either 'mixed' or 'element-only'", NULL); |
| 14397 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14398 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14399 | /* |
| 14400 | * FUTURE TODO SPEC (1.4.3.2.2.2) "The particle of the |
| 14401 | * complex type definition must be a ·valid extension· |
| 14402 | * of the {base type definition}'s particle, as defined |
| 14403 | * in Particle Valid (Extension) (§3.9.6)." |
| 14404 | * |
| 14405 | * NOTE that we won't check "Particle Valid (Extension)", |
| 14406 | * since it is ensured by the derivation process in |
| 14407 | * xmlSchemaTypeFixup(). We need to implement this when heading |
| 14408 | * for a construction API |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14409 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14410 | } |
| 14411 | /* |
| 14412 | * TODO (1.5) |
| 14413 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14414 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14415 | } else { |
| 14416 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14417 | * SPEC (2) "If the {base type definition} is a simple type definition, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14418 | * then all of the following must be true:" |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14419 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14420 | if (type->contentTypeDef != base) { |
| 14421 | /* |
| 14422 | * SPEC (2.1) "The {content type} must be the same simple type |
| 14423 | * definition." |
| 14424 | */ |
| 14425 | xmlSchemaPCustomErr(ctxt, |
| 14426 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
| 14427 | NULL, type, NULL, |
| 14428 | "The content type must be the simple base type", NULL); |
| 14429 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
| 14430 | } |
| 14431 | if (base->flags & XML_SCHEMAS_TYPE_FINAL_EXTENSION) { |
| 14432 | /* |
| 14433 | * SPEC (2.2) "The {final} of the {base type definition} must not |
| 14434 | * contain extension" |
| 14435 | * NOTE that this is the same as (1.1). |
| 14436 | */ |
| 14437 | xmlSchemaPCustomErr(ctxt, |
| 14438 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
| 14439 | NULL, type, NULL, |
| 14440 | "The 'final' of the base type definition " |
| 14441 | "contains 'extension'", NULL); |
| 14442 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14443 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14444 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14445 | return (0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14446 | } |
| 14447 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14448 | /** |
| 14449 | * xmlSchemaCheckDerivationOKRestriction: |
| 14450 | * @ctxt: the schema parser context |
| 14451 | * @type: the complex type definition |
| 14452 | * |
| 14453 | * (3.4.6) Constraints on Complex Type Definition Schema Components |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14454 | * Schema Component Constraint: |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14455 | * Derivation Valid (Restriction, Complex) (derivation-ok-restriction) |
| 14456 | * |
| 14457 | * STATUS: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14458 | * missing: |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14459 | * (5.4.2), (5.2.2.1) |
| 14460 | * |
| 14461 | * Returns 0 if the constraints are satisfied, a positive |
| 14462 | * error code if not and -1 if an internal error occured. |
| 14463 | */ |
| 14464 | static int |
| 14465 | xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt, |
| 14466 | xmlSchemaTypePtr type) |
| 14467 | { |
| 14468 | xmlSchemaTypePtr base; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14469 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14470 | /* |
| 14471 | * TODO: Correct the error code; XML_SCHEMAP_COS_CT_EXTENDS_1_1 is used |
| 14472 | * temporarily only. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14473 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14474 | base = type->baseType; |
| 14475 | if (base->flags & XML_SCHEMAS_TYPE_FINAL_RESTRICTION) { |
| 14476 | /* |
| 14477 | * SPEC (1) "The {base type definition} must be a complex type |
| 14478 | * definition whose {final} does not contain restriction." |
| 14479 | */ |
| 14480 | xmlSchemaPCustomErr(ctxt, |
| 14481 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
| 14482 | NULL, type, NULL, |
| 14483 | "The 'final' of the base type definition " |
| 14484 | "contains 'restriction'", NULL); |
| 14485 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
| 14486 | } |
| 14487 | /* |
| 14488 | * NOTE (3) and (4) are done in xmlSchemaBuildAttributeValidation(). |
| 14489 | * |
| 14490 | * SPEC (5) "One of the following must be true:" |
| 14491 | */ |
| 14492 | if (base->builtInType == XML_SCHEMAS_ANYTYPE) { |
| 14493 | /* |
| 14494 | * SPEC (5.1) "The {base type definition} must be the |
| 14495 | * ·ur-type definition·." |
| 14496 | * PASS |
| 14497 | */ |
| 14498 | } else if ((type->contentType == XML_SCHEMA_CONTENT_SIMPLE) || |
| 14499 | (type->contentType == XML_SCHEMA_CONTENT_BASIC)) { |
| 14500 | /* |
| 14501 | * SPEC (5.2.1) "The {content type} of the complex type definition |
| 14502 | * must be a simple type definition" |
| 14503 | * |
| 14504 | * SPEC (5.2.2) "One of the following must be true:" |
| 14505 | */ |
| 14506 | if ((base->contentType == XML_SCHEMA_CONTENT_SIMPLE) || |
| 14507 | (base->contentType == XML_SCHEMA_CONTENT_BASIC)) { |
| 14508 | /* |
| 14509 | * SPEC (5.2.2.1) "The {content type} of the {base type |
| 14510 | * definition} must be a simple type definition from which |
| 14511 | * the {content type} is validly derived given the empty |
| 14512 | * set as defined in Type Derivation OK (Simple) (§3.14.6)." |
| 14513 | * URGENT TODO |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14514 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14515 | } else if ((base->contentType == XML_SCHEMA_CONTENT_MIXED) && |
| 14516 | (xmlSchemaIsParticleEmptiable( |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14517 | (xmlSchemaParticlePtr) base->subtypes))) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14518 | /* |
| 14519 | * SPEC (5.2.2.2) "The {base type definition} must be mixed |
| 14520 | * and have a particle which is ·emptiable· as defined in |
| 14521 | * Particle Emptiable (§3.9.6)." |
| 14522 | * PASS |
| 14523 | */ |
| 14524 | } else { |
| 14525 | xmlSchemaPCustomErr(ctxt, |
| 14526 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
| 14527 | NULL, type, NULL, |
| 14528 | "The content type of the base type must be either " |
| 14529 | "a simple type or 'mixed' and an emptiable particle", NULL); |
| 14530 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
| 14531 | } |
| 14532 | } else if (type->contentType == XML_SCHEMA_CONTENT_EMPTY) { |
| 14533 | /* |
| 14534 | * SPEC (5.3.1) "The {content type} of the complex type itself must |
| 14535 | * be empty" |
| 14536 | */ |
| 14537 | if (base->contentType == XML_SCHEMA_CONTENT_EMPTY) { |
| 14538 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14539 | * SPEC (5.3.2.1) "The {content type} of the {base type |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14540 | * definition} must also be empty." |
| 14541 | * PASS |
| 14542 | */ |
| 14543 | } else if (((base->contentType == XML_SCHEMA_CONTENT_ELEMENTS) || |
| 14544 | (base->contentType == XML_SCHEMA_CONTENT_MIXED)) && |
| 14545 | xmlSchemaIsParticleEmptiable( |
| 14546 | (xmlSchemaParticlePtr) base->subtypes)) { |
| 14547 | /* |
| 14548 | * SPEC (5.3.2.2) "The {content type} of the {base type |
| 14549 | * definition} must be elementOnly or mixed and have a particle |
| 14550 | * which is ·emptiable· as defined in Particle Emptiable (§3.9.6)." |
| 14551 | * PASS |
| 14552 | */ |
| 14553 | } else { |
| 14554 | xmlSchemaPCustomErr(ctxt, |
| 14555 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
| 14556 | NULL, type, NULL, |
| 14557 | "The content type of the base type must be either " |
| 14558 | "empty or 'mixed' (or 'elements-only') and an emptiable " |
| 14559 | "particle", NULL); |
| 14560 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
| 14561 | } |
| 14562 | } else if ((type->contentType == XML_SCHEMA_CONTENT_ELEMENTS) || |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14563 | HAS_MIXED_CONTENT(type)) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14564 | /* |
| 14565 | * SPEC (5.4.1.1) "The {content type} of the complex type definition |
| 14566 | * itself must be element-only" |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14567 | */ |
| 14568 | if (HAS_MIXED_CONTENT(type) && (! HAS_MIXED_CONTENT(base))) { |
| 14569 | /* |
| 14570 | * SPEC (5.4.1.2) "The {content type} of the complex type |
| 14571 | * definition itself and of the {base type definition} must be |
| 14572 | * mixed" |
| 14573 | */ |
| 14574 | xmlSchemaPCustomErr(ctxt, |
| 14575 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
| 14576 | NULL, type, NULL, |
| 14577 | "If the content type is 'mixed', then the content type of the " |
| 14578 | "base type must also be 'mixed'", NULL); |
| 14579 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
| 14580 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14581 | /* |
| 14582 | * SPEC (5.4.2) "The particle of the complex type definition itself |
| 14583 | * must be a ·valid restriction· of the particle of the {content |
| 14584 | * type} of the {base type definition} as defined in Particle Valid |
| 14585 | * (Restriction) (§3.9.6). |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14586 | * |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14587 | * URGENT TODO: (5.4.2) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14588 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14589 | } else { |
| 14590 | xmlSchemaPCustomErr(ctxt, |
| 14591 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
| 14592 | NULL, type, NULL, |
| 14593 | "The type is not a valid restriction of its base type", NULL); |
| 14594 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
| 14595 | } |
| 14596 | return (0); |
| 14597 | } |
| 14598 | |
| 14599 | /** |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14600 | * xmlSchemaCheckCTComponent: |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14601 | * @ctxt: the schema parser context |
| 14602 | * @type: the complex type definition |
| 14603 | * |
| 14604 | * (3.4.6) Constraints on Complex Type Definition Schema Components |
| 14605 | * |
| 14606 | * Returns 0 if the constraints are satisfied, a positive |
| 14607 | * error code if not and -1 if an internal error occured. |
| 14608 | */ |
| 14609 | static int |
| 14610 | xmlSchemaCheckCTComponent(xmlSchemaParserCtxtPtr ctxt, |
| 14611 | xmlSchemaTypePtr type) |
| 14612 | { |
| 14613 | int ret; |
| 14614 | /* |
| 14615 | * Complex Type Definition Properties Correct |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14616 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14617 | ret = xmlSchemaCheckCTPropsCorrect(ctxt, type); |
| 14618 | if (ret != 0) |
| 14619 | return (ret); |
| 14620 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) |
| 14621 | ret = xmlSchemaCheckCOSCTExtends(ctxt, type); |
| 14622 | else |
| 14623 | ret = xmlSchemaCheckDerivationOKRestriction(ctxt, type); |
| 14624 | return (ret); |
| 14625 | } |
| 14626 | |
| 14627 | /** |
| 14628 | * xmlSchemaCheckSRCCT: |
| 14629 | * @ctxt: the schema parser context |
| 14630 | * @type: the complex type definition |
| 14631 | * |
| 14632 | * (3.4.3) Constraints on XML Representations of Complex Type Definitions: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14633 | * Schema Representation Constraint: |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14634 | * Complex Type Definition Representation OK (src-ct) |
| 14635 | * |
| 14636 | * Returns 0 if the constraints are satisfied, a positive |
| 14637 | * error code if not and -1 if an internal error occured. |
| 14638 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14639 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14640 | xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14641 | xmlSchemaTypePtr type) |
| 14642 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14643 | xmlSchemaTypePtr base; |
| 14644 | int ret = 0; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14645 | |
| 14646 | /* |
| 14647 | * TODO: Adjust the error codes here, as I used |
| 14648 | * XML_SCHEMAP_SRC_CT_1 only yet. |
| 14649 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14650 | base = type->baseType; |
Kasimier T. Buchcik | 5e371a0 | 2005-04-05 15:08:05 +0000 | [diff] [blame] | 14651 | if (! HAS_SIMPLE_CONTENT(type)) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14652 | /* |
| 14653 | * 1 If the <complexContent> alternative is chosen, the type definition |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14654 | * ·resolved· to by the ·actual value· of the base [attribute] |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14655 | * must be a complex type definition; |
| 14656 | */ |
| 14657 | if (! IS_COMPLEX_TYPE(base)) { |
| 14658 | xmlChar *str = NULL; |
| 14659 | xmlSchemaPCustomErr(ctxt, |
| 14660 | XML_SCHEMAP_SRC_CT_1, |
| 14661 | NULL, type, type->node, |
| 14662 | "If using <complexContent>, the base type is expected to be " |
| 14663 | "a complex type. The base type '%s' is a simple type", |
| 14664 | xmlSchemaFormatQName(&str, base->targetNamespace, |
| 14665 | base->name)); |
| 14666 | FREE_AND_NULL(str) |
| 14667 | return (XML_SCHEMAP_SRC_CT_1); |
| 14668 | } |
| 14669 | } else { |
| 14670 | /* |
| 14671 | * SPEC |
| 14672 | * 2 If the <simpleContent> alternative is chosen, all of the |
| 14673 | * following must be true: |
| 14674 | * 2.1 The type definition ·resolved· to by the ·actual value· of the |
| 14675 | * base [attribute] must be one of the following: |
| 14676 | */ |
| 14677 | if (IS_SIMPLE_TYPE(base)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14678 | if ((type->flags & |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14679 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) == 0) { |
| 14680 | xmlChar *str = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14681 | /* |
| 14682 | * 2.1.3 only if the <extension> alternative is also |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14683 | * chosen, a simple type definition. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14684 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14685 | /* TODO: Change error code to ..._SRC_CT_2_1_3. */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14686 | xmlSchemaPCustomErr(ctxt, |
| 14687 | XML_SCHEMAP_SRC_CT_1, |
| 14688 | NULL, type, NULL, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14689 | "If using <simpleContent> and <restriction>, the base " |
| 14690 | "type must be a complex type. The base type '%s' is " |
| 14691 | "a simple type", |
| 14692 | xmlSchemaFormatQName(&str, base->targetNamespace, |
| 14693 | base->name)); |
| 14694 | FREE_AND_NULL(str) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14695 | return (XML_SCHEMAP_SRC_CT_1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14696 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14697 | } else { |
| 14698 | /* Base type is a complex type. */ |
| 14699 | if ((base->contentType == XML_SCHEMA_CONTENT_SIMPLE) || |
| 14700 | (base->contentType == XML_SCHEMA_CONTENT_BASIC)) { |
| 14701 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14702 | * 2.1.1 a complex type definition whose {content type} is a |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14703 | * simple type definition; |
| 14704 | * PASS |
| 14705 | */ |
| 14706 | if (base->contentTypeDef == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14707 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14708 | NULL, type, NULL, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14709 | "Internal error: xmlSchemaCheckSRCCT, " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14710 | "'%s', base type has no content type", |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14711 | type->name); |
| 14712 | return (-1); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14713 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14714 | } else if ((base->contentType == XML_SCHEMA_CONTENT_MIXED) && |
| 14715 | (type->flags & |
| 14716 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION)) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14717 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14718 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14719 | * 2.1.2 only if the <restriction> alternative is also |
| 14720 | * chosen, a complex type definition whose {content type} |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14721 | * is mixed and a particle emptiable. |
| 14722 | */ |
| 14723 | if (! xmlSchemaIsParticleEmptiable( |
| 14724 | (xmlSchemaParticlePtr) base->subtypes)) { |
| 14725 | ret = XML_SCHEMAP_SRC_CT_1; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14726 | } else |
| 14727 | /* |
| 14728 | * Attention: at this point the <simpleType> child is in |
| 14729 | * ->contentTypeDef (put there during parsing). |
| 14730 | */ |
| 14731 | if (type->contentTypeDef == NULL) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14732 | xmlChar *str = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14733 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14734 | * 2.2 If clause 2.1.2 above is satisfied, then there |
| 14735 | * must be a <simpleType> among the [children] of |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14736 | * <restriction>. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14737 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14738 | /* TODO: Change error code to ..._SRC_CT_2_2. */ |
| 14739 | xmlSchemaPCustomErr(ctxt, |
| 14740 | XML_SCHEMAP_SRC_CT_1, |
| 14741 | NULL, type, NULL, |
| 14742 | "A <simpleType> is expected among the children " |
| 14743 | "of <restriction>, if <simpleContent> is used and " |
| 14744 | "the base type '%s' is a complex type", |
| 14745 | xmlSchemaFormatQName(&str, base->targetNamespace, |
| 14746 | base->name)); |
| 14747 | FREE_AND_NULL(str) |
| 14748 | return (XML_SCHEMAP_SRC_CT_1); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14749 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14750 | } else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14751 | ret = XML_SCHEMAP_SRC_CT_1; |
| 14752 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14753 | } |
| 14754 | if (ret > 0) { |
| 14755 | xmlChar *str = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14756 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14757 | xmlSchemaPCustomErr(ctxt, |
| 14758 | XML_SCHEMAP_SRC_CT_1, |
| 14759 | NULL, type, NULL, |
| 14760 | "If <simpleContent> and <restriction> is used, the " |
| 14761 | "base type must be a simple type or a complex type with " |
| 14762 | "mixed content and particle emptiable. The base type " |
| 14763 | "'%s' is none of those", |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14764 | xmlSchemaFormatQName(&str, base->targetNamespace, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14765 | base->name)); |
| 14766 | } else { |
| 14767 | xmlSchemaPCustomErr(ctxt, |
| 14768 | XML_SCHEMAP_SRC_CT_1, |
| 14769 | NULL, type, NULL, |
| 14770 | "If <simpleContent> and <extension> is used, the " |
| 14771 | "base type must be a simple type. The base type '%s' " |
| 14772 | "is a complex type", |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14773 | xmlSchemaFormatQName(&str, base->targetNamespace, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14774 | base->name)); |
| 14775 | } |
| 14776 | FREE_AND_NULL(str) |
| 14777 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14778 | } |
| 14779 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14780 | * SPEC (3) "The corresponding complex type definition component must |
| 14781 | * satisfy the conditions set out in Constraints on Complex Type |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14782 | * Definition Schema Components (§3.4.6);" |
| 14783 | * NOTE (3) will be done in xmlSchemaTypeFixup(). |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14784 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14785 | /* |
| 14786 | * SPEC (4) If clause 2.2.1 or clause 2.2.2 in the correspondence specification |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14787 | * above for {attribute wildcard} is satisfied, the intensional |
| 14788 | * intersection must be expressible, as defined in Attribute Wildcard |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14789 | * Intersection (§3.10.6). |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14790 | * NOTE (4) is done in xmlSchemaBuildAttributeValidation(). |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14791 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 14792 | return (ret); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14793 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14794 | |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 14795 | #ifdef ENABLE_PARTICLE_RESTRICTION |
| 14796 | /** |
| 14797 | * xmlSchemaCheckParticleRangeOK: |
| 14798 | * @ctxt: the schema parser context |
| 14799 | * @type: the complex type definition |
| 14800 | * |
| 14801 | * (3.9.6) Constraints on Particle Schema Components |
| 14802 | * Schema Component Constraint: |
| 14803 | * Occurrence Range OK (range-ok) |
| 14804 | * |
| 14805 | * STATUS: complete |
| 14806 | * |
| 14807 | * Returns 0 if the constraints are satisfied, a positive |
| 14808 | * error code if not and -1 if an internal error occured. |
| 14809 | */ |
| 14810 | static int |
| 14811 | xmlSchemaCheckParticleRangeOK(int rmin, int rmax, |
| 14812 | int bmin, int bmax) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14813 | { |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 14814 | if (rmin < bmin) |
| 14815 | return (1); |
| 14816 | if ((bmax != UNBOUNDED) && |
| 14817 | (rmax > bmax)) |
| 14818 | return (1); |
| 14819 | return (0); |
| 14820 | } |
| 14821 | |
| 14822 | /** |
| 14823 | * xmlSchemaCheckRCaseNameAndTypeOK: |
| 14824 | * @ctxt: the schema parser context |
| 14825 | * @r: the restricting element declaration particle |
| 14826 | * @b: the base element declaration particle |
| 14827 | * |
| 14828 | * (3.9.6) Constraints on Particle Schema Components |
| 14829 | * Schema Component Constraint: |
| 14830 | * Particle Restriction OK (Elt:Elt -- NameAndTypeOK) |
| 14831 | * (rcase-NameAndTypeOK) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14832 | * |
| 14833 | * STATUS: |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 14834 | * MISSING (3.2.3) |
| 14835 | * CLARIFY: (3.2.2) |
| 14836 | * |
| 14837 | * Returns 0 if the constraints are satisfied, a positive |
| 14838 | * error code if not and -1 if an internal error occured. |
| 14839 | */ |
| 14840 | static int |
| 14841 | xmlSchemaCheckRCaseNameAndTypeOK(xmlSchemaParserCtxtPtr ctxt, |
| 14842 | xmlSchemaParticlePtr r, |
| 14843 | xmlSchemaParticlePtr b) |
| 14844 | { |
| 14845 | xmlSchemaElementPtr elemR, elemB; |
| 14846 | |
| 14847 | /* TODO: Error codes (rcase-NameAndTypeOK). */ |
| 14848 | elemR = (xmlSchemaElementPtr) r->children; |
| 14849 | elemB = (xmlSchemaElementPtr) b->children; |
| 14850 | /* |
| 14851 | * SPEC (1) "The declarations' {name}s and {target namespace}s are |
| 14852 | * the same." |
| 14853 | */ |
| 14854 | if ((elemR != elemB) && |
| 14855 | ((! xmlStrEqual(elemR->name, elemB->name)) || |
| 14856 | (! xmlStrEqual(elemR->targetNamespace, elemB->targetNamespace)))) |
| 14857 | return (1); |
| 14858 | /* |
| 14859 | * SPEC (2) "R's occurrence range is a valid restriction of B's |
| 14860 | * occurrence range as defined by Occurrence Range OK (§3.9.6)." |
| 14861 | */ |
| 14862 | if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs, |
| 14863 | b->minOccurs, b->maxOccurs) != 0) |
| 14864 | return (1); |
| 14865 | /* |
| 14866 | * SPEC (3.1) "Both B's declaration's {scope} and R's declaration's |
| 14867 | * {scope} are global." |
| 14868 | */ |
| 14869 | if (elemR == elemB) |
| 14870 | return (0); |
| 14871 | /* |
| 14872 | * SPEC (3.2.1) "Either B's {nillable} is true or R's {nillable} is false." |
| 14873 | */ |
| 14874 | if (((elemB->flags & XML_SCHEMAS_ELEM_NILLABLE) == 0) && |
| 14875 | (elemR->flags & XML_SCHEMAS_ELEM_NILLABLE)) |
| 14876 | return (1); |
| 14877 | /* |
| 14878 | * SPEC (3.2.2) "either B's declaration's {value constraint} is absent, |
| 14879 | * or is not fixed, or R's declaration's {value constraint} is fixed |
| 14880 | * with the same value." |
| 14881 | */ |
| 14882 | if ((elemB->value != NULL) && (elemB->flags & XML_SCHEMAS_ELEM_FIXED) && |
| 14883 | ((elemR->value == NULL) || |
| 14884 | ((elemR->flags & XML_SCHEMAS_ELEM_FIXED) == 0) || |
| 14885 | /* TODO: Equality of the initial value or normalized or canonical? */ |
| 14886 | (! xmlStrEqual(elemR->value, elemB->value)))) |
| 14887 | return (1); |
| 14888 | /* |
| 14889 | * TODO: SPEC (3.2.3) "R's declaration's {identity-constraint |
| 14890 | * definitions} is a subset of B's declaration's {identity-constraint |
| 14891 | * definitions}, if any." |
| 14892 | */ |
| 14893 | if (elemB->idcs != NULL) { |
| 14894 | /* TODO */ |
| 14895 | } |
| 14896 | /* |
| 14897 | * SPEC (3.2.4) "R's declaration's {disallowed substitutions} is a |
| 14898 | * superset of B's declaration's {disallowed substitutions}." |
| 14899 | */ |
| 14900 | if (((elemB->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) && |
| 14901 | ((elemR->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) == 0)) || |
| 14902 | ((elemB->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) && |
| 14903 | ((elemR->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) == 0)) || |
| 14904 | ((elemB->flags & XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION) && |
| 14905 | ((elemR->flags & XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION) == 0))) |
| 14906 | return (1); |
| 14907 | /* |
| 14908 | * SPEC (3.2.5) "R's {type definition} is validly derived given |
| 14909 | * {extension, list, union} from B's {type definition}" |
| 14910 | * |
| 14911 | * BADSPEC TODO: What's the point of adding "list" and "union" to the |
| 14912 | * set, if the corresponding constraints handle "restriction" and |
| 14913 | * "extension" only? |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14914 | * |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 14915 | */ |
| 14916 | { |
| 14917 | int set = 0; |
| 14918 | |
| 14919 | set |= SUBSET_EXTENSION; |
| 14920 | set |= SUBSET_LIST; |
| 14921 | set |= SUBSET_UNION; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14922 | if (xmlSchemaCheckCOSDerivedOK(elemR->subtypes, |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 14923 | elemB->subtypes, set) != 0) |
| 14924 | return (1); |
| 14925 | } |
| 14926 | return (0); |
| 14927 | } |
| 14928 | |
| 14929 | /** |
| 14930 | * xmlSchemaCheckRCaseNSCompat: |
| 14931 | * @ctxt: the schema parser context |
| 14932 | * @r: the restricting element declaration particle |
| 14933 | * @b: the base wildcard particle |
| 14934 | * |
| 14935 | * (3.9.6) Constraints on Particle Schema Components |
| 14936 | * Schema Component Constraint: |
| 14937 | * Particle Derivation OK (Elt:Any -- NSCompat) |
| 14938 | * (rcase-NSCompat) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14939 | * |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 14940 | * STATUS: complete |
| 14941 | * |
| 14942 | * Returns 0 if the constraints are satisfied, a positive |
| 14943 | * error code if not and -1 if an internal error occured. |
| 14944 | */ |
| 14945 | static int |
| 14946 | xmlSchemaCheckRCaseNSCompat(xmlSchemaParserCtxtPtr ctxt, |
| 14947 | xmlSchemaParticlePtr r, |
| 14948 | xmlSchemaParticlePtr b) |
| 14949 | { |
| 14950 | /* TODO:Error codes (rcase-NSCompat). */ |
| 14951 | /* |
| 14952 | * SPEC "For an element declaration particle to be a ·valid restriction· |
| 14953 | * of a wildcard particle all of the following must be true:" |
| 14954 | * |
| 14955 | * SPEC (1) "The element declaration's {target namespace} is ·valid· |
| 14956 | * with respect to the wildcard's {namespace constraint} as defined by |
| 14957 | * Wildcard allows Namespace Name (§3.10.4)." |
| 14958 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14959 | if (xmlSchemaCheckCVCWildcardNamespace((xmlSchemaWildcardPtr) b->children, |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 14960 | ((xmlSchemaElementPtr) r->children)->targetNamespace) != 0) |
| 14961 | return (1); |
| 14962 | /* |
| 14963 | * SPEC (2) "R's occurrence range is a valid restriction of B's |
| 14964 | * occurrence range as defined by Occurrence Range OK (§3.9.6)." |
| 14965 | */ |
| 14966 | if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs, |
| 14967 | b->minOccurs, b->maxOccurs) != 0) |
| 14968 | return (1); |
| 14969 | |
| 14970 | return (0); |
| 14971 | } |
| 14972 | |
| 14973 | /** |
| 14974 | * xmlSchemaCheckRCaseRecurseAsIfGroup: |
| 14975 | * @ctxt: the schema parser context |
| 14976 | * @r: the restricting element declaration particle |
| 14977 | * @b: the base model group particle |
| 14978 | * |
| 14979 | * (3.9.6) Constraints on Particle Schema Components |
| 14980 | * Schema Component Constraint: |
| 14981 | * Particle Derivation OK (Elt:All/Choice/Sequence -- RecurseAsIfGroup) |
| 14982 | * (rcase-RecurseAsIfGroup) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 14983 | * |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 14984 | * STATUS: TODO |
| 14985 | * |
| 14986 | * Returns 0 if the constraints are satisfied, a positive |
| 14987 | * error code if not and -1 if an internal error occured. |
| 14988 | */ |
| 14989 | static int |
| 14990 | xmlSchemaCheckRCaseRecurseAsIfGroup(xmlSchemaParserCtxtPtr ctxt, |
| 14991 | xmlSchemaParticlePtr r, |
| 14992 | xmlSchemaParticlePtr b) |
| 14993 | { |
| 14994 | /* TODO: Error codes (rcase-RecurseAsIfGroup). */ |
| 14995 | TODO |
| 14996 | return (0); |
| 14997 | } |
| 14998 | |
| 14999 | /** |
| 15000 | * xmlSchemaCheckRCaseNSSubset: |
| 15001 | * @ctxt: the schema parser context |
| 15002 | * @r: the restricting wildcard particle |
| 15003 | * @b: the base wildcard particle |
| 15004 | * |
| 15005 | * (3.9.6) Constraints on Particle Schema Components |
| 15006 | * Schema Component Constraint: |
| 15007 | * Particle Derivation OK (Any:Any -- NSSubset) |
| 15008 | * (rcase-NSSubset) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15009 | * |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 15010 | * STATUS: complete |
| 15011 | * |
| 15012 | * Returns 0 if the constraints are satisfied, a positive |
| 15013 | * error code if not and -1 if an internal error occured. |
| 15014 | */ |
| 15015 | static int |
| 15016 | xmlSchemaCheckRCaseNSSubset(xmlSchemaParserCtxtPtr ctxt, |
| 15017 | xmlSchemaParticlePtr r, |
| 15018 | xmlSchemaParticlePtr b, |
| 15019 | int isAnyTypeBase) |
| 15020 | { |
| 15021 | /* TODO: Error codes (rcase-NSSubset). */ |
| 15022 | /* |
| 15023 | * SPEC (1) "R's occurrence range is a valid restriction of B's |
| 15024 | * occurrence range as defined by Occurrence Range OK (§3.9.6)." |
| 15025 | */ |
| 15026 | if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs, |
| 15027 | b->minOccurs, b->maxOccurs)) |
| 15028 | return (1); |
| 15029 | /* |
| 15030 | * SPEC (2) "R's {namespace constraint} must be an intensional subset |
| 15031 | * of B's {namespace constraint} as defined by Wildcard Subset (§3.10.6)." |
| 15032 | */ |
| 15033 | if (xmlSchemaCheckCOSNSSubset((xmlSchemaWildcardPtr) r->children, |
| 15034 | (xmlSchemaWildcardPtr) b->children)) |
| 15035 | return (1); |
| 15036 | /* |
| 15037 | * SPEC (3) "Unless B is the content model wildcard of the ·ur-type |
| 15038 | * definition·, R's {process contents} must be identical to or stronger |
| 15039 | * than B's {process contents}, where strict is stronger than lax is |
| 15040 | * stronger than skip." |
| 15041 | */ |
| 15042 | if (! isAnyTypeBase) { |
| 15043 | if ( ((xmlSchemaWildcardPtr) r->children)->processContents < |
| 15044 | ((xmlSchemaWildcardPtr) b->children)->processContents) |
| 15045 | return (1); |
| 15046 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15047 | |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 15048 | return (0); |
| 15049 | } |
| 15050 | |
| 15051 | /** |
| 15052 | * xmlSchemaCheckCOSParticleRestrict: |
| 15053 | * @ctxt: the schema parser context |
| 15054 | * @type: the complex type definition |
| 15055 | * |
| 15056 | * (3.9.6) Constraints on Particle Schema Components |
| 15057 | * Schema Component Constraint: |
| 15058 | * Particle Valid (Restriction) (cos-particle-restrict) |
| 15059 | * |
| 15060 | * STATUS: TODO |
| 15061 | * |
| 15062 | * Returns 0 if the constraints are satisfied, a positive |
| 15063 | * error code if not and -1 if an internal error occured. |
| 15064 | */ |
| 15065 | static int |
| 15066 | xmlSchemaCheckCOSParticleRestrict(xmlSchemaParserCtxtPtr ctxt, |
| 15067 | xmlSchemaParticlePtr r, |
| 15068 | xmlSchemaParticlePtr b) |
| 15069 | { |
| 15070 | int ret = 0; |
| 15071 | |
| 15072 | /*part = GET_PARTICLE(type); |
| 15073 | basePart = GET_PARTICLE(base); |
| 15074 | */ |
| 15075 | |
| 15076 | TODO |
| 15077 | |
| 15078 | /* |
| 15079 | * SPEC (1) "They are the same particle." |
| 15080 | */ |
| 15081 | if (r == b) |
| 15082 | return (0); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15083 | |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 15084 | |
| 15085 | return (0); |
| 15086 | } |
| 15087 | |
| 15088 | /** |
| 15089 | * xmlSchemaCheckRCaseNSRecurseCheckCardinality: |
| 15090 | * @ctxt: the schema parser context |
| 15091 | * @r: the model group particle |
| 15092 | * @b: the base wildcard particle |
| 15093 | * |
| 15094 | * (3.9.6) Constraints on Particle Schema Components |
| 15095 | * Schema Component Constraint: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15096 | * Particle Derivation OK (All/Choice/Sequence:Any -- |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 15097 | * NSRecurseCheckCardinality) |
| 15098 | * (rcase-NSRecurseCheckCardinality) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15099 | * |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 15100 | * STATUS: TODO: subst-groups |
| 15101 | * |
| 15102 | * Returns 0 if the constraints are satisfied, a positive |
| 15103 | * error code if not and -1 if an internal error occured. |
| 15104 | */ |
| 15105 | static int |
| 15106 | xmlSchemaCheckRCaseNSRecurseCheckCardinality(xmlSchemaParserCtxtPtr ctxt, |
| 15107 | xmlSchemaParticlePtr r, |
| 15108 | xmlSchemaParticlePtr b) |
| 15109 | { |
| 15110 | xmlSchemaParticlePtr part; |
| 15111 | /* TODO: Error codes (rcase-NSRecurseCheckCardinality). */ |
| 15112 | if ((r->children == NULL) || (r->children->children == NULL)) |
| 15113 | return (-1); |
| 15114 | /* |
| 15115 | * SPEC "For a group particle to be a ·valid restriction· of a |
| 15116 | * wildcard particle..." |
| 15117 | * |
| 15118 | * SPEC (1) "Every member of the {particles} of the group is a ·valid |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15119 | * restriction· of the wildcard as defined by |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 15120 | * Particle Valid (Restriction) (§3.9.6)." |
| 15121 | */ |
| 15122 | part = (xmlSchemaParticlePtr) r->children->children; |
| 15123 | do { |
| 15124 | if (xmlSchemaCheckCOSParticleRestrict(ctxt, part, b)) |
| 15125 | return (1); |
| 15126 | part = (xmlSchemaParticlePtr) part->next; |
| 15127 | } while (part != NULL); |
| 15128 | /* |
| 15129 | * SPEC (2) "The effective total range of the group [...] is a |
| 15130 | * valid restriction of B's occurrence range as defined by |
| 15131 | * Occurrence Range OK (§3.9.6)." |
| 15132 | */ |
| 15133 | if (xmlSchemaCheckParticleRangeOK( |
| 15134 | xmlSchemaGetParticleTotalRangeMin(r), |
| 15135 | xmlSchemaGetParticleTotalRangeMax(r), |
| 15136 | b->minOccurs, b->maxOccurs) != 0) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15137 | return (1); |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 15138 | return (0); |
| 15139 | } |
| 15140 | |
| 15141 | /** |
| 15142 | * xmlSchemaCheckRCaseRecurse: |
| 15143 | * @ctxt: the schema parser context |
| 15144 | * @r: the <all> or <sequence> model group particle |
| 15145 | * @b: the base <all> or <sequence> model group particle |
| 15146 | * |
| 15147 | * (3.9.6) Constraints on Particle Schema Components |
| 15148 | * Schema Component Constraint: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15149 | * Particle Derivation OK (All:All,Sequence:Sequence -- |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 15150 | Recurse) |
| 15151 | * (rcase-Recurse) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15152 | * |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 15153 | * STATUS: ? |
| 15154 | * TODO: subst-groups |
| 15155 | * |
| 15156 | * Returns 0 if the constraints are satisfied, a positive |
| 15157 | * error code if not and -1 if an internal error occured. |
| 15158 | */ |
| 15159 | static int |
| 15160 | xmlSchemaCheckRCaseRecurse(xmlSchemaParserCtxtPtr ctxt, |
| 15161 | xmlSchemaParticlePtr r, |
| 15162 | xmlSchemaParticlePtr b) |
| 15163 | { |
| 15164 | /* xmlSchemaParticlePtr part; */ |
| 15165 | /* TODO: Error codes (rcase-Recurse). */ |
| 15166 | if ((r->children == NULL) || (b->children == NULL) || |
| 15167 | (r->children->type != b->children->type)) |
| 15168 | return (-1); |
| 15169 | /* |
| 15170 | * SPEC "For an all or sequence group particle to be a ·valid |
| 15171 | * restriction· of another group particle with the same {compositor}..." |
| 15172 | * |
| 15173 | * SPEC (1) "R's occurrence range is a valid restriction of B's |
| 15174 | * occurrence range as defined by Occurrence Range OK (§3.9.6)." |
| 15175 | */ |
| 15176 | if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs, |
| 15177 | b->minOccurs, b->maxOccurs)) |
| 15178 | return (1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15179 | |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 15180 | |
| 15181 | return (0); |
| 15182 | } |
| 15183 | |
| 15184 | #endif |
| 15185 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15186 | #define FACET_RESTR_MUTUAL_ERR(fac1, fac2) \ |
| 15187 | xmlSchemaPCustomErrExt(pctxt, \ |
| 15188 | XML_SCHEMAP_INVALID_FACET_VALUE, \ |
| 15189 | NULL, (xmlSchemaTypePtr) fac1, fac1->node, \ |
| 15190 | "It is an error for both '%s' and '%s' to be specified on the "\ |
| 15191 | "same type definition", \ |
| 15192 | BAD_CAST xmlSchemaFacetTypeToString(fac1->type), \ |
| 15193 | BAD_CAST xmlSchemaFacetTypeToString(fac2->type), NULL); |
| 15194 | |
| 15195 | #define FACET_RESTR_ERR(fac1, msg) \ |
| 15196 | xmlSchemaPCustomErr(pctxt, \ |
| 15197 | XML_SCHEMAP_INVALID_FACET_VALUE, \ |
| 15198 | NULL, (xmlSchemaTypePtr) fac1, fac1->node, \ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15199 | msg, NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15200 | |
| 15201 | #define FACET_RESTR_FIXED_ERR(fac) \ |
| 15202 | xmlSchemaPCustomErr(pctxt, \ |
| 15203 | XML_SCHEMAP_INVALID_FACET_VALUE, \ |
| 15204 | NULL, (xmlSchemaTypePtr) fac, fac->node, \ |
| 15205 | "The base type's facet is 'fixed', thus the value must not " \ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15206 | "differ", NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15207 | |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 15208 | static void |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15209 | xmlSchemaDeriveFacetErr(xmlSchemaParserCtxtPtr pctxt, |
| 15210 | xmlSchemaFacetPtr facet1, |
| 15211 | xmlSchemaFacetPtr facet2, |
| 15212 | int lessGreater, |
| 15213 | int orEqual, |
| 15214 | int ofBase) |
| 15215 | { |
| 15216 | xmlChar *msg = NULL; |
| 15217 | |
| 15218 | msg = xmlStrdup(BAD_CAST "'"); |
| 15219 | msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facet1->type)); |
| 15220 | msg = xmlStrcat(msg, BAD_CAST "' has to be"); |
| 15221 | if (lessGreater == 0) |
| 15222 | msg = xmlStrcat(msg, BAD_CAST " equal to"); |
| 15223 | if (lessGreater == 1) |
| 15224 | msg = xmlStrcat(msg, BAD_CAST " greater than"); |
| 15225 | else |
| 15226 | msg = xmlStrcat(msg, BAD_CAST " less than"); |
| 15227 | |
| 15228 | if (orEqual) |
| 15229 | msg = xmlStrcat(msg, BAD_CAST " or equal to"); |
| 15230 | msg = xmlStrcat(msg, BAD_CAST " '"); |
| 15231 | msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facet2->type)); |
| 15232 | if (ofBase) |
| 15233 | msg = xmlStrcat(msg, BAD_CAST "' of the base type"); |
| 15234 | else |
| 15235 | msg = xmlStrcat(msg, BAD_CAST "'"); |
| 15236 | |
| 15237 | xmlSchemaPCustomErr(pctxt, |
| 15238 | XML_SCHEMAP_INVALID_FACET_VALUE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15239 | NULL, (xmlSchemaTypePtr) facet1, facet1->node, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15240 | (const char *) msg, NULL); |
| 15241 | |
| 15242 | if (msg != NULL) |
| 15243 | xmlFree(msg); |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 15244 | } |
| 15245 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15246 | static int |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15247 | xmlSchemaDeriveAndValidateFacets(xmlSchemaParserCtxtPtr pctxt, |
| 15248 | xmlSchemaTypePtr type) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15249 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15250 | xmlSchemaTypePtr base = type->baseType; |
| 15251 | xmlSchemaFacetLinkPtr link, cur, last = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15252 | xmlSchemaFacetPtr facet, bfacet, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15253 | flength = NULL, ftotdig = NULL, ffracdig = NULL, |
| 15254 | fmaxlen = NULL, fminlen = NULL, /* facets of the current type */ |
| 15255 | fmininc = NULL, fmaxinc = NULL, |
| 15256 | fminexc = NULL, fmaxexc = NULL, |
| 15257 | bflength = NULL, bftotdig = NULL, bffracdig = NULL, |
| 15258 | bfmaxlen = NULL, bfminlen = NULL, /* facets of the base type */ |
| 15259 | bfmininc = NULL, bfmaxinc = NULL, |
| 15260 | bfminexc = NULL, bfmaxexc = NULL; |
| 15261 | int res, err = 0, fixedErr; |
| 15262 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15263 | * 3 The {facets} of R are the union of S and the {facets} |
| 15264 | * of B, eliminating duplicates. To eliminate duplicates, |
| 15265 | * when a facet of the same kind occurs in both S and the |
| 15266 | * {facets} of B, the one in the {facets} of B is not |
| 15267 | * included, with the exception of enumeration and pattern |
| 15268 | * facets, for which multiple occurrences with distinct values |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15269 | * are allowed. |
| 15270 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15271 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15272 | if ((type->facetSet == NULL) && (base->facetSet == NULL)) |
| 15273 | return (0); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15274 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15275 | last = type->facetSet; |
| 15276 | if (last != NULL) |
| 15277 | while (last->next != NULL) |
| 15278 | last = last->next; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15279 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15280 | for (cur = type->facetSet; cur != NULL; cur = cur->next) { |
| 15281 | facet = cur->facet; |
| 15282 | switch (facet->type) { |
| 15283 | case XML_SCHEMA_FACET_LENGTH: |
| 15284 | flength = facet; break; |
| 15285 | case XML_SCHEMA_FACET_MINLENGTH: |
| 15286 | fminlen = facet; break; |
| 15287 | case XML_SCHEMA_FACET_MININCLUSIVE: |
| 15288 | fmininc = facet; break; |
| 15289 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
| 15290 | fminexc = facet; break; |
| 15291 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 15292 | fmaxlen = facet; break; |
| 15293 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
| 15294 | fmaxinc = facet; break; |
| 15295 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
| 15296 | fmaxexc = facet; break; |
| 15297 | case XML_SCHEMA_FACET_TOTALDIGITS: |
| 15298 | ftotdig = facet; break; |
| 15299 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
| 15300 | ffracdig = facet; break; |
| 15301 | default: |
| 15302 | break; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15303 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15304 | } |
| 15305 | for (cur = base->facetSet; cur != NULL; cur = cur->next) { |
| 15306 | facet = cur->facet; |
| 15307 | switch (facet->type) { |
| 15308 | case XML_SCHEMA_FACET_LENGTH: |
| 15309 | bflength = facet; break; |
| 15310 | case XML_SCHEMA_FACET_MINLENGTH: |
| 15311 | bfminlen = facet; break; |
| 15312 | case XML_SCHEMA_FACET_MININCLUSIVE: |
| 15313 | bfmininc = facet; break; |
| 15314 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
| 15315 | bfminexc = facet; break; |
| 15316 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 15317 | bfmaxlen = facet; break; |
| 15318 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
| 15319 | bfmaxinc = facet; break; |
| 15320 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
| 15321 | bfmaxexc = facet; break; |
| 15322 | case XML_SCHEMA_FACET_TOTALDIGITS: |
| 15323 | bftotdig = facet; break; |
| 15324 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
| 15325 | bffracdig = facet; break; |
| 15326 | default: |
| 15327 | break; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15328 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15329 | } |
| 15330 | err = 0; |
| 15331 | /* |
| 15332 | * length and minLength or maxLength (2.2) + (3.2) |
| 15333 | */ |
| 15334 | if (flength && (fminlen || fmaxlen)) { |
| 15335 | FACET_RESTR_ERR(flength, "It is an error for both 'length' and " |
| 15336 | "either of 'minLength' or 'maxLength' to be specified on " |
| 15337 | "the same type definition") |
| 15338 | } |
| 15339 | /* |
| 15340 | * Mutual exclusions in the same derivation step. |
| 15341 | */ |
| 15342 | if ((fmaxinc) && (fmaxexc)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15343 | /* |
| 15344 | * SCC "maxInclusive and maxExclusive" |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15345 | */ |
| 15346 | FACET_RESTR_MUTUAL_ERR(fmaxinc, fmaxexc) |
| 15347 | } |
| 15348 | if ((fmininc) && (fminexc)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15349 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15350 | * SCC "minInclusive and minExclusive" |
| 15351 | */ |
| 15352 | FACET_RESTR_MUTUAL_ERR(fmininc, fminexc) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15353 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15354 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15355 | if (flength && bflength) { |
| 15356 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15357 | * SCC "length valid restriction" |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15358 | * The values have to be equal. |
| 15359 | */ |
| 15360 | res = xmlSchemaCompareValues(flength->val, bflength->val); |
| 15361 | if (res == -2) |
| 15362 | goto internal_error; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15363 | if (res != 0) |
| 15364 | xmlSchemaDeriveFacetErr(pctxt, flength, bflength, 0, 0, 1); |
| 15365 | if ((res != 0) && (bflength->fixed)) { |
| 15366 | FACET_RESTR_FIXED_ERR(flength) |
| 15367 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15368 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15369 | } |
| 15370 | if (fminlen && bfminlen) { |
| 15371 | /* |
| 15372 | * SCC "minLength valid restriction" |
| 15373 | * minLength >= BASE minLength |
| 15374 | */ |
| 15375 | res = xmlSchemaCompareValues(fminlen->val, bfminlen->val); |
| 15376 | if (res == -2) |
| 15377 | goto internal_error; |
| 15378 | if (res == -1) |
| 15379 | xmlSchemaDeriveFacetErr(pctxt, fminlen, bfminlen, 1, 1, 1); |
| 15380 | if ((res != 0) && (bfminlen->fixed)) { |
| 15381 | FACET_RESTR_FIXED_ERR(fminlen) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15382 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15383 | } |
| 15384 | if (fmaxlen && bfmaxlen) { |
| 15385 | /* |
| 15386 | * SCC "maxLength valid restriction" |
| 15387 | * maxLength <= BASE minLength |
| 15388 | */ |
| 15389 | res = xmlSchemaCompareValues(fmaxlen->val, bfmaxlen->val); |
| 15390 | if (res == -2) |
| 15391 | goto internal_error; |
| 15392 | if (res == 1) |
| 15393 | xmlSchemaDeriveFacetErr(pctxt, fmaxlen, bfmaxlen, -1, 1, 1); |
| 15394 | if ((res != 0) && (bfmaxlen->fixed)) { |
| 15395 | FACET_RESTR_FIXED_ERR(fmaxlen) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15396 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15397 | } |
| 15398 | /* |
| 15399 | * SCC "length and minLength or maxLength" |
| 15400 | */ |
| 15401 | if (! flength) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15402 | flength = bflength; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15403 | if (flength) { |
| 15404 | if (! fminlen) |
| 15405 | flength = bflength; |
| 15406 | if (fminlen) { |
| 15407 | /* (1.1) length >= minLength */ |
| 15408 | res = xmlSchemaCompareValues(flength->val, fminlen->val); |
| 15409 | if (res == -2) |
| 15410 | goto internal_error; |
| 15411 | if (res == -1) |
| 15412 | xmlSchemaDeriveFacetErr(pctxt, flength, fminlen, 1, 1, 0); |
| 15413 | } |
| 15414 | if (! fmaxlen) |
| 15415 | fmaxlen = bfmaxlen; |
| 15416 | if (fmaxlen) { |
| 15417 | /* (2.1) length <= maxLength */ |
| 15418 | res = xmlSchemaCompareValues(flength->val, fmaxlen->val); |
| 15419 | if (res == -2) |
| 15420 | goto internal_error; |
| 15421 | if (res == 1) |
| 15422 | xmlSchemaDeriveFacetErr(pctxt, flength, fmaxlen, -1, 1, 0); |
| 15423 | } |
| 15424 | } |
| 15425 | if (fmaxinc) { |
| 15426 | /* |
| 15427 | * "maxInclusive" |
| 15428 | */ |
| 15429 | if (fmininc) { |
| 15430 | /* SCC "maxInclusive >= minInclusive" */ |
| 15431 | res = xmlSchemaCompareValues(fmaxinc->val, fmininc->val); |
| 15432 | if (res == -2) |
| 15433 | goto internal_error; |
| 15434 | if (res == -1) { |
| 15435 | xmlSchemaDeriveFacetErr(pctxt, fmaxinc, fmininc, 1, 1, 0); |
| 15436 | } |
| 15437 | } |
| 15438 | /* |
| 15439 | * SCC "maxInclusive valid restriction" |
| 15440 | */ |
| 15441 | if (bfmaxinc) { |
| 15442 | /* maxInclusive <= BASE maxInclusive */ |
| 15443 | res = xmlSchemaCompareValues(fmaxinc->val, bfmaxinc->val); |
| 15444 | if (res == -2) |
| 15445 | goto internal_error; |
| 15446 | if (res == 1) |
| 15447 | xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfmaxinc, -1, 1, 1); |
| 15448 | if ((res != 0) && (bfmaxinc->fixed)) { |
| 15449 | FACET_RESTR_FIXED_ERR(fmaxinc) |
| 15450 | } |
| 15451 | } |
| 15452 | if (bfmaxexc) { |
| 15453 | /* maxInclusive < BASE maxExclusive */ |
| 15454 | res = xmlSchemaCompareValues(fmaxinc->val, bfmaxexc->val); |
| 15455 | if (res == -2) |
| 15456 | goto internal_error; |
| 15457 | if (res != -1) { |
| 15458 | xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfmaxexc, -1, 0, 1); |
| 15459 | } |
| 15460 | } |
| 15461 | if (bfmininc) { |
| 15462 | /* maxInclusive >= BASE minInclusive */ |
| 15463 | res = xmlSchemaCompareValues(fmaxinc->val, bfmininc->val); |
| 15464 | if (res == -2) |
| 15465 | goto internal_error; |
| 15466 | if (res == -1) { |
| 15467 | xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfmininc, 1, 1, 1); |
| 15468 | } |
| 15469 | } |
| 15470 | if (bfminexc) { |
| 15471 | /* maxInclusive > BASE minExclusive */ |
| 15472 | res = xmlSchemaCompareValues(fmaxinc->val, bfminexc->val); |
| 15473 | if (res == -2) |
| 15474 | goto internal_error; |
| 15475 | if (res != 1) { |
| 15476 | xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfminexc, 1, 0, 1); |
| 15477 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15478 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15479 | } |
| 15480 | if (fmaxexc) { |
| 15481 | /* |
| 15482 | * "maxExclusive >= minExclusive" |
| 15483 | */ |
| 15484 | if (fminexc) { |
| 15485 | res = xmlSchemaCompareValues(fmaxexc->val, fminexc->val); |
| 15486 | if (res == -2) |
| 15487 | goto internal_error; |
| 15488 | if (res == -1) { |
| 15489 | xmlSchemaDeriveFacetErr(pctxt, fmaxexc, fminexc, 1, 1, 0); |
| 15490 | } |
| 15491 | } |
| 15492 | /* |
| 15493 | * "maxExclusive valid restriction" |
| 15494 | */ |
| 15495 | if (bfmaxexc) { |
| 15496 | /* maxExclusive <= BASE maxExclusive */ |
| 15497 | res = xmlSchemaCompareValues(fmaxexc->val, bfmaxexc->val); |
| 15498 | if (res == -2) |
| 15499 | goto internal_error; |
| 15500 | if (res == 1) { |
| 15501 | xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfmaxexc, -1, 1, 1); |
| 15502 | } |
| 15503 | if ((res != 0) && (bfmaxexc->fixed)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15504 | FACET_RESTR_FIXED_ERR(fmaxexc) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15505 | } |
| 15506 | } |
| 15507 | if (bfmaxinc) { |
| 15508 | /* maxExclusive <= BASE maxInclusive */ |
| 15509 | res = xmlSchemaCompareValues(fmaxexc->val, bfmaxinc->val); |
| 15510 | if (res == -2) |
| 15511 | goto internal_error; |
| 15512 | if (res == 1) { |
| 15513 | xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfmaxinc, -1, 1, 1); |
| 15514 | } |
| 15515 | } |
| 15516 | if (bfmininc) { |
| 15517 | /* maxExclusive > BASE minInclusive */ |
| 15518 | res = xmlSchemaCompareValues(fmaxexc->val, bfmininc->val); |
| 15519 | if (res == -2) |
| 15520 | goto internal_error; |
| 15521 | if (res != 1) { |
| 15522 | xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfmininc, 1, 0, 1); |
| 15523 | } |
| 15524 | } |
| 15525 | if (bfminexc) { |
| 15526 | /* maxExclusive > BASE minExclusive */ |
| 15527 | res = xmlSchemaCompareValues(fmaxexc->val, bfminexc->val); |
| 15528 | if (res == -2) |
| 15529 | goto internal_error; |
| 15530 | if (res != 1) { |
| 15531 | xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfminexc, 1, 0, 1); |
| 15532 | } |
| 15533 | } |
| 15534 | } |
| 15535 | if (fminexc) { |
| 15536 | /* |
| 15537 | * "minExclusive < maxInclusive" |
| 15538 | */ |
| 15539 | if (fmaxinc) { |
| 15540 | res = xmlSchemaCompareValues(fminexc->val, fmaxinc->val); |
| 15541 | if (res == -2) |
| 15542 | goto internal_error; |
| 15543 | if (res != -1) { |
| 15544 | xmlSchemaDeriveFacetErr(pctxt, fminexc, fmaxinc, -1, 0, 0); |
| 15545 | } |
| 15546 | } |
| 15547 | /* |
| 15548 | * "minExclusive valid restriction" |
| 15549 | */ |
| 15550 | if (bfminexc) { |
| 15551 | /* minExclusive >= BASE minExclusive */ |
| 15552 | res = xmlSchemaCompareValues(fminexc->val, bfminexc->val); |
| 15553 | if (res == -2) |
| 15554 | goto internal_error; |
| 15555 | if (res == -1) { |
| 15556 | xmlSchemaDeriveFacetErr(pctxt, fminexc, bfminexc, 1, 1, 1); |
| 15557 | } |
| 15558 | if ((res != 0) && (bfminexc->fixed)) { |
| 15559 | FACET_RESTR_FIXED_ERR(fminexc) |
| 15560 | } |
| 15561 | } |
| 15562 | if (bfmaxinc) { |
| 15563 | /* minExclusive <= BASE maxInclusive */ |
| 15564 | res = xmlSchemaCompareValues(fminexc->val, bfmaxinc->val); |
| 15565 | if (res == -2) |
| 15566 | goto internal_error; |
| 15567 | if (res == 1) { |
| 15568 | xmlSchemaDeriveFacetErr(pctxt, fminexc, bfmaxinc, -1, 1, 1); |
| 15569 | } |
| 15570 | } |
| 15571 | if (bfmininc) { |
| 15572 | /* minExclusive >= BASE minInclusive */ |
| 15573 | res = xmlSchemaCompareValues(fminexc->val, bfmininc->val); |
| 15574 | if (res == -2) |
| 15575 | goto internal_error; |
| 15576 | if (res == -1) { |
| 15577 | xmlSchemaDeriveFacetErr(pctxt, fminexc, bfmininc, 1, 1, 1); |
| 15578 | } |
| 15579 | } |
| 15580 | if (bfmaxexc) { |
| 15581 | /* minExclusive < BASE maxExclusive */ |
| 15582 | res = xmlSchemaCompareValues(fminexc->val, bfmaxexc->val); |
| 15583 | if (res == -2) |
| 15584 | goto internal_error; |
| 15585 | if (res != -1) { |
| 15586 | xmlSchemaDeriveFacetErr(pctxt, fminexc, bfmaxexc, -1, 0, 1); |
| 15587 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15588 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15589 | } |
| 15590 | if (fmininc) { |
| 15591 | /* |
| 15592 | * "minInclusive < maxExclusive" |
| 15593 | */ |
| 15594 | if (fmaxexc) { |
| 15595 | res = xmlSchemaCompareValues(fmininc->val, fmaxexc->val); |
| 15596 | if (res == -2) |
| 15597 | goto internal_error; |
| 15598 | if (res != -1) { |
| 15599 | xmlSchemaDeriveFacetErr(pctxt, fmininc, fmaxexc, -1, 0, 0); |
| 15600 | } |
| 15601 | } |
| 15602 | /* |
| 15603 | * "minExclusive valid restriction" |
| 15604 | */ |
| 15605 | if (bfmininc) { |
| 15606 | /* minInclusive >= BASE minInclusive */ |
| 15607 | res = xmlSchemaCompareValues(fmininc->val, bfmininc->val); |
| 15608 | if (res == -2) |
| 15609 | goto internal_error; |
| 15610 | if (res == -1) { |
| 15611 | xmlSchemaDeriveFacetErr(pctxt, fmininc, bfmininc, 1, 1, 1); |
| 15612 | } |
| 15613 | if ((res != 0) && (bfmininc->fixed)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15614 | FACET_RESTR_FIXED_ERR(fmininc) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15615 | } |
| 15616 | } |
| 15617 | if (bfmaxinc) { |
| 15618 | /* minInclusive <= BASE maxInclusive */ |
| 15619 | res = xmlSchemaCompareValues(fmininc->val, bfmaxinc->val); |
| 15620 | if (res == -2) |
| 15621 | goto internal_error; |
| 15622 | if (res == -1) { |
| 15623 | xmlSchemaDeriveFacetErr(pctxt, fmininc, bfmaxinc, -1, 1, 1); |
| 15624 | } |
| 15625 | } |
| 15626 | if (bfminexc) { |
| 15627 | /* minInclusive > BASE minExclusive */ |
| 15628 | res = xmlSchemaCompareValues(fmininc->val, bfminexc->val); |
| 15629 | if (res == -2) |
| 15630 | goto internal_error; |
| 15631 | if (res != 1) |
| 15632 | xmlSchemaDeriveFacetErr(pctxt, fmininc, bfminexc, 1, 0, 1); |
| 15633 | } |
| 15634 | if (bfmaxexc) { |
| 15635 | /* minInclusive < BASE maxExclusive */ |
| 15636 | res = xmlSchemaCompareValues(fmininc->val, bfmaxexc->val); |
| 15637 | if (res == -2) |
| 15638 | goto internal_error; |
| 15639 | if (res != -1) |
| 15640 | xmlSchemaDeriveFacetErr(pctxt, fmininc, bfmaxexc, -1, 0, 1); |
| 15641 | } |
| 15642 | } |
| 15643 | if (ftotdig && bftotdig) { |
| 15644 | /* |
| 15645 | * SCC " totalDigits valid restriction" |
| 15646 | * totalDigits <= BASE totalDigits |
| 15647 | */ |
| 15648 | res = xmlSchemaCompareValues(ftotdig->val, bftotdig->val); |
| 15649 | if (res == -2) |
| 15650 | goto internal_error; |
| 15651 | if (res == 1) |
| 15652 | xmlSchemaDeriveFacetErr(pctxt, ftotdig, bftotdig, |
| 15653 | -1, 1, 1); |
| 15654 | if ((res != 0) && (bftotdig->fixed)) { |
| 15655 | FACET_RESTR_FIXED_ERR(ftotdig) |
| 15656 | } |
| 15657 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15658 | if (ffracdig && bffracdig) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15659 | /* |
| 15660 | * SCC "fractionDigits valid restriction" |
| 15661 | * fractionDigits <= BASE fractionDigits |
| 15662 | */ |
| 15663 | res = xmlSchemaCompareValues(ffracdig->val, bffracdig->val); |
| 15664 | if (res == -2) |
| 15665 | goto internal_error; |
| 15666 | if (res == 1) |
| 15667 | xmlSchemaDeriveFacetErr(pctxt, ffracdig, bffracdig, |
| 15668 | -1, 1, 1); |
| 15669 | if ((res != 0) && (bffracdig->fixed)) { |
| 15670 | FACET_RESTR_FIXED_ERR(ffracdig) |
| 15671 | } |
| 15672 | } |
| 15673 | /* |
| 15674 | * SCC "fractionDigits less than or equal to totalDigits" |
| 15675 | */ |
| 15676 | if (! ftotdig) |
| 15677 | ftotdig = bftotdig; |
| 15678 | if (! ffracdig) |
| 15679 | ffracdig = bffracdig; |
| 15680 | if (ftotdig && ffracdig) { |
| 15681 | res = xmlSchemaCompareValues(ffracdig->val, ftotdig->val); |
| 15682 | if (res == -2) |
| 15683 | goto internal_error; |
| 15684 | if (res == 1) |
| 15685 | xmlSchemaDeriveFacetErr(pctxt, ffracdig, ftotdig, |
| 15686 | -1, 1, 0); |
| 15687 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15688 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15689 | * *Enumerations* won' be added here, since only the first set |
| 15690 | * of enumerations in the ancestor-or-self axis is used |
| 15691 | * for validation, plus we need to use the base type of those |
| 15692 | * enumerations for whitespace. |
| 15693 | * |
| 15694 | * *Patterns*: won't be add here, since they are ORed at |
| 15695 | * type level and ANDed at ancestor level. This will |
| 15696 | * happed during validation by walking the base axis |
| 15697 | * of the type. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15698 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15699 | for (cur = base->facetSet; cur != NULL; cur = cur->next) { |
| 15700 | bfacet = cur->facet; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15701 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15702 | * Special handling of enumerations and patterns. |
| 15703 | * TODO: hmm, they should not appear in the set, so remove this. |
| 15704 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15705 | if ((bfacet->type == XML_SCHEMA_FACET_PATTERN) || |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15706 | (bfacet->type == XML_SCHEMA_FACET_ENUMERATION)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15707 | continue; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15708 | /* |
| 15709 | * Search for a duplicate facet in the current type. |
| 15710 | */ |
| 15711 | link = type->facetSet; |
| 15712 | err = 0; |
| 15713 | fixedErr = 0; |
| 15714 | while (link != NULL) { |
| 15715 | facet = link->facet; |
| 15716 | if (facet->type == bfacet->type) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15717 | switch (facet->type) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15718 | case XML_SCHEMA_FACET_WHITESPACE: |
| 15719 | /* |
| 15720 | * The whitespace must be stronger. |
| 15721 | */ |
| 15722 | if (facet->whitespace < bfacet->whitespace) { |
| 15723 | FACET_RESTR_ERR(flength, |
| 15724 | "The 'whitespace' value has to be equal to " |
| 15725 | "or stronger than the 'whitespace' value of " |
| 15726 | "the base type") |
| 15727 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15728 | if ((bfacet->fixed) && |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15729 | (facet->whitespace != bfacet->whitespace)) { |
| 15730 | FACET_RESTR_FIXED_ERR(facet) |
| 15731 | } |
| 15732 | break; |
| 15733 | default: |
| 15734 | break; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15735 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15736 | /* Duplicate found. */ |
| 15737 | break; |
| 15738 | } |
| 15739 | link = link->next; |
| 15740 | } |
| 15741 | /* |
| 15742 | * If no duplicate was found: add the base types's facet |
| 15743 | * to the set. |
| 15744 | */ |
| 15745 | if (link == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15746 | link = (xmlSchemaFacetLinkPtr) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15747 | xmlMalloc(sizeof(xmlSchemaFacetLink)); |
| 15748 | if (link == NULL) { |
| 15749 | xmlSchemaPErrMemory(pctxt, |
| 15750 | "deriving facets, creating a facet link", NULL); |
| 15751 | return (-1); |
| 15752 | } |
| 15753 | link->facet = cur->facet; |
| 15754 | link->next = NULL; |
| 15755 | if (last == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15756 | type->facetSet = link; |
| 15757 | else |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15758 | last->next = link; |
| 15759 | last = link; |
| 15760 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15761 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15762 | } |
| 15763 | |
| 15764 | return (0); |
| 15765 | internal_error: |
| 15766 | xmlSchemaPCustomErr(pctxt, |
| 15767 | XML_SCHEMAP_INVALID_FACET_VALUE, |
| 15768 | NULL, type, NULL, |
| 15769 | "Internal error: xmlSchemaDeriveAndValidateFacets", NULL); |
| 15770 | return (-1); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15771 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15772 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 15773 | static int |
| 15774 | xmlSchemaFinishMemberTypeDefinitionsProperty(xmlSchemaParserCtxtPtr pctxt, |
| 15775 | xmlSchemaTypePtr type) |
| 15776 | { |
| 15777 | xmlSchemaTypeLinkPtr link, lastLink, prevLink, subLink, newLink; |
| 15778 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15779 | * The actual value is then formed by replacing any union type |
| 15780 | * definition in the ·explicit members· with the members of their |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 15781 | * {member type definitions}, in order. |
| 15782 | */ |
| 15783 | link = type->memberTypes; |
| 15784 | while (link != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15785 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 15786 | if (IS_NOT_TYPEFIXED(link->type)) |
| 15787 | xmlSchemaTypeFixup(link->type, pctxt, NULL); |
| 15788 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15789 | if (VARIETY_UNION(link->type)) { |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 15790 | subLink = xmlSchemaGetUnionSimpleTypeMemberTypes(link->type); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15791 | if (subLink != NULL) { |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 15792 | link->type = subLink->type; |
| 15793 | if (subLink->next != NULL) { |
| 15794 | lastLink = link->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15795 | subLink = subLink->next; |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 15796 | prevLink = link; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15797 | while (subLink != NULL) { |
| 15798 | newLink = (xmlSchemaTypeLinkPtr) |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 15799 | xmlMalloc(sizeof(xmlSchemaTypeLink)); |
| 15800 | if (newLink == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15801 | xmlSchemaPErrMemory(pctxt, "allocating a type link", |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 15802 | NULL); |
| 15803 | return (-1); |
| 15804 | } |
| 15805 | newLink->type = subLink->type; |
| 15806 | prevLink->next = newLink; |
| 15807 | prevLink = newLink; |
| 15808 | newLink->next = lastLink; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15809 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 15810 | subLink = subLink->next; |
| 15811 | } |
| 15812 | } |
| 15813 | } |
| 15814 | } |
| 15815 | link = link->next; |
| 15816 | } |
| 15817 | return (0); |
| 15818 | } |
| 15819 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15820 | static void |
| 15821 | xmlSchemaTypeFixupOptimFacets(xmlSchemaTypePtr type) |
| 15822 | { |
| 15823 | int has = 0, needVal = 0, normVal = 0; |
| 15824 | |
| 15825 | has = (type->baseType->flags & XML_SCHEMAS_TYPE_HAS_FACETS) ? 1 : 0; |
| 15826 | if (has) { |
| 15827 | needVal = (type->baseType->flags & |
| 15828 | XML_SCHEMAS_TYPE_FACETSNEEDVALUE) ? 1 : 0; |
| 15829 | normVal = (type->baseType->flags & |
| 15830 | XML_SCHEMAS_TYPE_NORMVALUENEEDED) ? 1 : 0; |
| 15831 | } |
| 15832 | if (type->facets != NULL) { |
| 15833 | xmlSchemaFacetPtr fac; |
| 15834 | |
| 15835 | for (fac = type->facets; fac != NULL; fac = fac->next) { |
| 15836 | switch (fac->type) { |
| 15837 | case XML_SCHEMA_FACET_WHITESPACE: |
| 15838 | break; |
| 15839 | case XML_SCHEMA_FACET_PATTERN: |
| 15840 | normVal = 1; |
| 15841 | has = 1; |
| 15842 | break; |
| 15843 | case XML_SCHEMA_FACET_ENUMERATION: |
| 15844 | needVal = 1; |
| 15845 | normVal = 1; |
| 15846 | has = 1; |
| 15847 | break; |
| 15848 | default: |
| 15849 | has = 1; |
| 15850 | break; |
| 15851 | } |
| 15852 | } |
| 15853 | } |
| 15854 | if (normVal) |
| 15855 | type->flags |= XML_SCHEMAS_TYPE_NORMVALUENEEDED; |
| 15856 | if (needVal) |
| 15857 | type->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE; |
| 15858 | if (has) |
| 15859 | type->flags |= XML_SCHEMAS_TYPE_HAS_FACETS; |
| 15860 | |
| 15861 | if (has && (! needVal) && VARIETY_ATOMIC(type)) { |
| 15862 | xmlSchemaTypePtr prim = xmlSchemaGetPrimitiveType(type); |
| 15863 | /* |
| 15864 | * OPTIMIZE VAL TODO: Some facets need a computed value. |
| 15865 | */ |
| 15866 | if ((prim->builtInType != XML_SCHEMAS_ANYSIMPLETYPE) && |
| 15867 | (prim->builtInType != XML_SCHEMAS_STRING)) { |
| 15868 | type->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE; |
| 15869 | } |
| 15870 | } |
| 15871 | } |
| 15872 | |
| 15873 | static int |
| 15874 | xmlSchemaTypeFixupWhitespace(xmlSchemaTypePtr type) |
| 15875 | { |
| 15876 | |
| 15877 | |
| 15878 | /* |
| 15879 | * Evaluate the whitespace-facet value. |
| 15880 | */ |
| 15881 | if (VARIETY_LIST(type)) { |
| 15882 | type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE; |
| 15883 | return (0); |
| 15884 | } else if (VARIETY_UNION(type)) |
| 15885 | return (0); |
| 15886 | |
| 15887 | if (type->facetSet != NULL) { |
| 15888 | xmlSchemaFacetLinkPtr lin; |
| 15889 | |
| 15890 | for (lin = type->facetSet; lin != NULL; lin = lin->next) { |
| 15891 | if (lin->facet->type == XML_SCHEMA_FACET_WHITESPACE) { |
| 15892 | switch (lin->facet->whitespace) { |
| 15893 | case XML_SCHEMAS_FACET_PRESERVE: |
| 15894 | type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE; |
| 15895 | break; |
| 15896 | case XML_SCHEMAS_FACET_REPLACE: |
| 15897 | type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_REPLACE; |
| 15898 | break; |
| 15899 | case XML_SCHEMAS_FACET_COLLAPSE: |
| 15900 | type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE; |
| 15901 | break; |
| 15902 | default: |
| 15903 | return (-1); |
| 15904 | } |
| 15905 | return (0); |
| 15906 | } |
| 15907 | } |
| 15908 | } |
| 15909 | /* |
| 15910 | * For all ·atomic· datatypes other than string (and types ·derived· |
| 15911 | * by ·restriction· from it) the value of whiteSpace is fixed to |
| 15912 | * collapse |
| 15913 | */ |
| 15914 | { |
| 15915 | xmlSchemaTypePtr anc; |
| 15916 | |
| 15917 | for (anc = type->baseType; anc != NULL && |
| 15918 | anc->builtInType != XML_SCHEMAS_ANYTYPE; |
| 15919 | anc = anc->baseType) { |
| 15920 | |
| 15921 | if (anc->type == XML_SCHEMA_TYPE_BASIC) { |
| 15922 | if (anc->builtInType == XML_SCHEMAS_NORMSTRING) { |
| 15923 | type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_REPLACE; |
| 15924 | |
| 15925 | } else if ((anc->builtInType == XML_SCHEMAS_STRING) || |
| 15926 | (anc->builtInType == XML_SCHEMAS_ANYSIMPLETYPE)) { |
| 15927 | type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE; |
| 15928 | |
| 15929 | } else |
| 15930 | type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE; |
| 15931 | break; |
| 15932 | } |
| 15933 | } |
| 15934 | return (0); |
| 15935 | } |
| 15936 | return (0); |
| 15937 | } |
| 15938 | |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 15939 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15940 | * xmlSchemaTypeFixup: |
| 15941 | * @typeDecl: the schema type definition |
| 15942 | * @ctxt: the schema parser context |
| 15943 | * |
| 15944 | * Fixes the content model of the type. |
| 15945 | */ |
| 15946 | static void |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15947 | xmlSchemaTypeFixup(xmlSchemaTypePtr type, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15948 | xmlSchemaParserCtxtPtr pctxt, const xmlChar * name) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15949 | { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15950 | if (type == NULL) |
Daniel Veillard | 82bbbd4 | 2003-05-11 20:16:09 +0000 | [diff] [blame] | 15951 | return; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15952 | if ((type->type != XML_SCHEMA_TYPE_COMPLEX) && |
| 15953 | (type->type != XML_SCHEMA_TYPE_SIMPLE)) |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 15954 | return; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15955 | if (! IS_NOT_TYPEFIXED(type)) |
| 15956 | return; |
| 15957 | type->flags |= XML_SCHEMAS_TYPE_INTERNAL_RESOLVED; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15958 | if (name == NULL) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15959 | name = type->name; |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 15960 | |
| 15961 | if (type->baseType == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15962 | xmlSchemaPCustomErr(pctxt, |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 15963 | XML_SCHEMAP_INTERNAL, |
| 15964 | NULL, type, NULL, |
| 15965 | "Internal error: xmlSchemaTypeFixup, " |
| 15966 | "baseType is missing on '%s'", type->name); |
| 15967 | return; |
| 15968 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15969 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15970 | if (type->type == XML_SCHEMA_TYPE_COMPLEX) { |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 15971 | xmlSchemaTypePtr baseType = type->baseType; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15972 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15973 | /* |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 15974 | * Type-fix the base type. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15975 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15976 | if (IS_NOT_TYPEFIXED(baseType)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15977 | xmlSchemaTypeFixup(baseType, pctxt, NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15978 | if (baseType->flags & XML_SCHEMAS_TYPE_INTERNAL_INVALID) { |
| 15979 | /* |
| 15980 | * Skip fixup if the base type is invalid. |
| 15981 | * TODO: Generate a warning! |
| 15982 | */ |
| 15983 | return; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15984 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15985 | /* |
| 15986 | * This basically checks if the base type can be derived. |
| 15987 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15988 | if (xmlSchemaCheckSRCCT(pctxt, type) != 0) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15989 | type->flags |= XML_SCHEMAS_TYPE_INTERNAL_INVALID; |
| 15990 | return; |
| 15991 | } |
| 15992 | /* |
| 15993 | * Fixup the content type. |
| 15994 | */ |
| 15995 | if (type->contentType == XML_SCHEMA_CONTENT_SIMPLE) { |
| 15996 | /* |
| 15997 | * Corresponds to <complexType><simpleContent>... |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 15998 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 15999 | if ((IS_COMPLEX_TYPE(baseType)) && |
| 16000 | (baseType->contentTypeDef != NULL) && |
| 16001 | (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16002 | xmlSchemaTypePtr contentBase, content; |
| 16003 | char buf[30]; |
| 16004 | const xmlChar *tmpname; |
| 16005 | /* |
| 16006 | * SPEC (1) If <restriction> + base type is <complexType>, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16007 | * "whose own {content type} is a simple type..." |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16008 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16009 | if (type->contentTypeDef != NULL) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16010 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16011 | * SPEC (1.1) "the simple type definition corresponding to the |
| 16012 | * <simpleType> among the [children] of <restriction> if there |
| 16013 | * is one;" |
| 16014 | * Note that this "<simpleType> among the [children]" was put |
| 16015 | * into ->contentTypeDef during parsing. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16016 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16017 | contentBase = type->contentTypeDef; |
| 16018 | type->contentTypeDef = NULL; |
| 16019 | } else { |
| 16020 | /* |
| 16021 | * (1.2) "...otherwise (<restriction> has no <simpleType> |
| 16022 | * among its [children]), the simple type definition which |
| 16023 | * is the {content type} of the ... base type." |
| 16024 | */ |
| 16025 | contentBase = baseType->contentTypeDef; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16026 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16027 | /* |
| 16028 | * SPEC |
| 16029 | * "... a simple type definition which restricts the simple |
| 16030 | * type definition identified in clause 1.1 or clause 1.2 |
| 16031 | * with a set of facet components" |
| 16032 | * |
| 16033 | * Create the anonymous simple type, which will be the content |
| 16034 | * type of the complex type. |
| 16035 | */ |
| 16036 | snprintf(buf, 29, "#scST%d", ++(pctxt->counter)); |
| 16037 | tmpname = xmlDictLookup(pctxt->dict, BAD_CAST buf, -1); |
| 16038 | content = xmlSchemaAddType(pctxt, |
| 16039 | pctxt->schema, tmpname, tmpname, type->node); |
| 16040 | if (content == NULL) |
| 16041 | return; |
| 16042 | /* |
| 16043 | * We will use the same node as for the <complexType> |
| 16044 | * to have it somehow anchored in the schema doc. |
| 16045 | */ |
| 16046 | content->node = type->node; |
| 16047 | content->type = XML_SCHEMA_TYPE_SIMPLE; |
| 16048 | content->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
| 16049 | content->baseType = contentBase; |
| 16050 | /* |
| 16051 | * Move the facets, previously anchored on the complexType. |
| 16052 | */ |
| 16053 | content->facets = type->facets; |
| 16054 | type->facets = NULL; |
| 16055 | content->facetSet = type->facetSet; |
| 16056 | type->facetSet = NULL; |
| 16057 | |
| 16058 | type->contentTypeDef = content; |
| 16059 | if (IS_NOT_TYPEFIXED(contentBase)) |
| 16060 | xmlSchemaTypeFixup(contentBase, pctxt, NULL); |
| 16061 | xmlSchemaTypeFixup(content, pctxt, NULL); |
| 16062 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16063 | } else if ((IS_COMPLEX_TYPE(baseType)) && |
| 16064 | (baseType->contentType == XML_SCHEMA_CONTENT_MIXED) && |
| 16065 | (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION)) { |
| 16066 | /* |
| 16067 | * SPEC (2) If <restriction> + base is a mixed <complexType> with |
| 16068 | * an emptiable particle, then a simple type definition which |
| 16069 | * restricts the <restriction>'s <simpleType> child. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16070 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16071 | if ((type->contentTypeDef == NULL) || |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16072 | (type->contentTypeDef->baseType == NULL)) { |
| 16073 | /* |
| 16074 | * TODO: Check if this ever happens. |
| 16075 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16076 | xmlSchemaPCustomErr(pctxt, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16077 | XML_SCHEMAP_INTERNAL, |
| 16078 | NULL, type, NULL, |
| 16079 | "Internal error: xmlSchemaTypeFixup, " |
| 16080 | "complex type '%s': the <simpleContent><restriction> " |
| 16081 | "is missing a <simpleType> child, but was not catched " |
| 16082 | "by xmlSchemaCheckSRCCT()", type->name); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16083 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16084 | } else if ((IS_COMPLEX_TYPE(baseType)) && |
| 16085 | (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION)) { |
| 16086 | /* |
| 16087 | * SPEC (3) If <extension> + base is <complexType> with |
| 16088 | * <simpleType> content, "...then the {content type} of that |
| 16089 | * complex type definition" |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16090 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16091 | if (baseType->contentTypeDef == NULL) { |
| 16092 | /* |
| 16093 | * TODO: Check if this ever happens. xmlSchemaCheckSRCCT |
| 16094 | * should have catched this already. |
| 16095 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16096 | xmlSchemaPCustomErr(pctxt, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16097 | XML_SCHEMAP_INTERNAL, |
| 16098 | NULL, type, NULL, |
| 16099 | "Internal error: xmlSchemaTypeFixup, " |
| 16100 | "complex type '%s': the <extension>ed base type is " |
| 16101 | "a complex type with no simple content type", |
| 16102 | type->name); |
| 16103 | } |
| 16104 | type->contentTypeDef = baseType->contentTypeDef; |
| 16105 | } else if ((IS_SIMPLE_TYPE(baseType)) && |
| 16106 | (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION)) { |
| 16107 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16108 | * SPEC (4) <extension> + base is <simpleType> |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16109 | * "... then that simple type definition" |
| 16110 | */ |
| 16111 | type->contentTypeDef = baseType; |
| 16112 | } else { |
| 16113 | /* |
| 16114 | * TODO: Check if this ever happens. |
| 16115 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16116 | xmlSchemaPCustomErr(pctxt, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16117 | XML_SCHEMAP_INTERNAL, |
| 16118 | NULL, type, NULL, |
| 16119 | "Internal error: xmlSchemaTypeFixup, " |
| 16120 | "complex type '%s' with <simpleContent>: unhandled " |
| 16121 | "derivation case", type->name); |
| 16122 | } |
| 16123 | } else { |
| 16124 | int dummySequence = 0; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16125 | xmlSchemaParticlePtr particle = |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16126 | (xmlSchemaParticlePtr) type->subtypes; |
| 16127 | /* |
| 16128 | * Corresponds to <complexType><complexContent>... |
| 16129 | * |
| 16130 | * NOTE that the effective mixed was already set during parsing of |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16131 | * <complexType> and <complexContent>; its flag value is |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16132 | * XML_SCHEMAS_TYPE_MIXED. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16133 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16134 | * Compute the "effective content": |
| 16135 | * (2.1.1) + (2.1.2) + (2.1.3) |
| 16136 | */ |
| 16137 | if ((particle == NULL) || |
| 16138 | ((particle->type == XML_SCHEMA_TYPE_PARTICLE) && |
| 16139 | ((particle->children->type == XML_SCHEMA_TYPE_ALL) || |
| 16140 | (particle->children->type == XML_SCHEMA_TYPE_SEQUENCE) || |
| 16141 | ((particle->children->type == XML_SCHEMA_TYPE_CHOICE) && |
| 16142 | (particle->minOccurs == 0))) && |
| 16143 | ( ((xmlSchemaTreeItemPtr) particle->children)->children == NULL))) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16144 | if (type->flags & XML_SCHEMAS_TYPE_MIXED) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16145 | /* |
| 16146 | * SPEC (2.1.4) "If the ·effective mixed· is true, then |
| 16147 | * a particle whose properties are as follows:..." |
| 16148 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16149 | * Empty sequence model group with |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16150 | * minOccurs/maxOccurs = 1 (i.e. a "particle emptiable"). |
| 16151 | * NOTE that we sill assign it the <complexType> node to |
| 16152 | * somehow anchor it in the doc. |
| 16153 | */ |
| 16154 | if ((particle == NULL) || |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16155 | (particle->children->type != XML_SCHEMA_TYPE_SEQUENCE)) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16156 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16157 | * Create the particle. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16158 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16159 | particle = xmlSchemaAddParticle(pctxt, pctxt->schema, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16160 | type->node, 1, 1); |
| 16161 | if (particle == NULL) |
| 16162 | return; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16163 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16164 | * Create the model group. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16165 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16166 | particle->children = (xmlSchemaTreeItemPtr) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16167 | xmlSchemaAddModelGroup(pctxt, pctxt->schema, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16168 | XML_SCHEMA_TYPE_SEQUENCE, NULL, type->node); |
| 16169 | if (particle->children == NULL) |
| 16170 | return; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16171 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16172 | type->subtypes = (xmlSchemaTypePtr) particle; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16173 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16174 | dummySequence = 1; |
| 16175 | type->contentType = XML_SCHEMA_CONTENT_ELEMENTS; |
| 16176 | } else { |
| 16177 | /* |
| 16178 | * SPEC (2.1.5) "otherwise empty" |
| 16179 | */ |
| 16180 | type->contentType = XML_SCHEMA_CONTENT_EMPTY; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16181 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16182 | } else { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16183 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16184 | * SPEC (2.2) "otherwise the particle corresponding to the |
| 16185 | * <all>, <choice>, <group> or <sequence> among the |
| 16186 | * [children]." |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16187 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16188 | type->contentType = XML_SCHEMA_CONTENT_ELEMENTS; |
| 16189 | } |
| 16190 | /* |
| 16191 | * Compute the "content type". |
| 16192 | */ |
| 16193 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16194 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16195 | * SPEC (3.1) "If <restriction>..." |
| 16196 | * (3.1.1) + (3.1.2) */ |
| 16197 | if (type->contentType != XML_SCHEMA_CONTENT_EMPTY) { |
| 16198 | if (type->flags & XML_SCHEMAS_TYPE_MIXED) |
| 16199 | type->contentType = XML_SCHEMA_CONTENT_MIXED; |
| 16200 | } |
| 16201 | } else { |
| 16202 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16203 | * SPEC (3.2) "If <extension>..." |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16204 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16205 | if (type->contentType == XML_SCHEMA_CONTENT_EMPTY) { |
| 16206 | /* |
| 16207 | * SPEC (3.2.1) |
| 16208 | */ |
| 16209 | type->contentType = baseType->contentType; |
| 16210 | type->subtypes = baseType->subtypes; |
| 16211 | /* |
| 16212 | * NOTE that the effective mixed is ignored here. |
| 16213 | */ |
| 16214 | } else if (baseType->contentType == XML_SCHEMA_CONTENT_EMPTY) { |
| 16215 | /* |
| 16216 | * SPEC (3.2.2) |
| 16217 | */ |
| 16218 | if (type->flags & XML_SCHEMAS_TYPE_MIXED) |
| 16219 | type->contentType = XML_SCHEMA_CONTENT_MIXED; |
| 16220 | } else { |
| 16221 | /* |
| 16222 | * SPEC (3.2.3) |
| 16223 | */ |
| 16224 | if (type->flags & XML_SCHEMAS_TYPE_MIXED) |
| 16225 | type->contentType = XML_SCHEMA_CONTENT_MIXED; |
| 16226 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16227 | * "A model group whose {compositor} is sequence and whose |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16228 | * {particles} are..." |
| 16229 | */ |
| 16230 | if (! dummySequence) { |
| 16231 | xmlSchemaTreeItemPtr effectiveContent = |
| 16232 | (xmlSchemaTreeItemPtr) type->subtypes; |
| 16233 | /* |
| 16234 | * Create the particle. |
| 16235 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16236 | particle = xmlSchemaAddParticle(pctxt, pctxt->schema, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16237 | type->node, 1, 1); |
| 16238 | if (particle == NULL) |
| 16239 | return; |
| 16240 | /* |
| 16241 | * Create the "sequence" model group. |
| 16242 | */ |
| 16243 | particle->children = (xmlSchemaTreeItemPtr) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16244 | xmlSchemaAddModelGroup(pctxt, pctxt->schema, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16245 | XML_SCHEMA_TYPE_SEQUENCE, NULL, type->node); |
| 16246 | if (particle->children == NULL) |
| 16247 | return; |
| 16248 | type->subtypes = (xmlSchemaTypePtr) particle; |
| 16249 | /* |
| 16250 | * SPEC "the particle of the {content type} of |
| 16251 | * the ... base ..." |
| 16252 | * Create a duplicate of the base type's particle |
| 16253 | * and assign its "term" to it. |
| 16254 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16255 | particle->children->children = |
| 16256 | (xmlSchemaTreeItemPtr) xmlSchemaAddParticle(pctxt, |
| 16257 | pctxt->schema, type->node, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16258 | ((xmlSchemaParticlePtr) type->subtypes)->minOccurs, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16259 | ((xmlSchemaParticlePtr) type->subtypes)->maxOccurs); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16260 | if (particle->children->children == NULL) |
| 16261 | return; |
| 16262 | particle = (xmlSchemaParticlePtr) |
| 16263 | particle->children->children; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16264 | particle->children = |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16265 | ((xmlSchemaParticlePtr) baseType->subtypes)->children; |
| 16266 | /* |
| 16267 | * SPEC "followed by the ·effective content·." |
| 16268 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16269 | particle->next = effectiveContent; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16270 | } else { |
| 16271 | /* |
| 16272 | * This is the case when there is already an empty |
| 16273 | * <sequence> with minOccurs==maxOccurs==1. |
| 16274 | * Just add the base types's content type. |
| 16275 | * NOTE that, although we miss to add an intermediate |
| 16276 | * <sequence>, this should produce no difference to |
| 16277 | * neither the regex compilation of the content model, |
| 16278 | * nor to the complex type contraints. |
| 16279 | */ |
| 16280 | particle->children->children = |
| 16281 | (xmlSchemaTreeItemPtr) baseType->subtypes; |
| 16282 | } |
| 16283 | } |
| 16284 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16285 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16286 | /* |
| 16287 | * Apply the complex type component constraints; this will not |
| 16288 | * check attributes, since this is done in |
| 16289 | * xmlSchemaBuildAttributeValidation(). |
| 16290 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16291 | if (xmlSchemaCheckCTComponent(pctxt, type) != 0) |
| 16292 | return; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16293 | /* |
| 16294 | * Inherit & check constraints for attributes. |
| 16295 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16296 | xmlSchemaBuildAttributeValidation(pctxt, type); |
| 16297 | } else if (type->type == XML_SCHEMA_TYPE_SIMPLE) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16298 | /* |
| 16299 | * Simple Type Definition Schema Component |
| 16300 | */ |
| 16301 | type->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16302 | if (VARIETY_LIST(type)) { |
| 16303 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16304 | * Corresponds to <simpleType><list>... |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16305 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16306 | if (type->subtypes == NULL) { |
| 16307 | /* |
| 16308 | * This one is really needed, so get out. |
| 16309 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16310 | PERROR_INT("xmlSchemaTypeFixup", |
| 16311 | "list type has no item-type assigned"); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16312 | return; |
| 16313 | } |
| 16314 | if (IS_NOT_TYPEFIXED(type->subtypes)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16315 | xmlSchemaTypeFixup(type->subtypes, pctxt, NULL); |
| 16316 | } else if (VARIETY_UNION(type)) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16317 | /* |
| 16318 | * Corresponds to <simpleType><union>... |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16319 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16320 | if (type->memberTypes == NULL) { |
| 16321 | /* |
| 16322 | * This one is really needed, so get out. |
| 16323 | */ |
| 16324 | return; |
| 16325 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16326 | if (xmlSchemaFinishMemberTypeDefinitionsProperty(pctxt, type) == -1) |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 16327 | return; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16328 | } else { |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 16329 | xmlSchemaTypePtr baseType = type->baseType; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16330 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16331 | * Corresponds to <simpleType><restriction>... |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16332 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16333 | if (IS_NOT_TYPEFIXED(baseType)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16334 | xmlSchemaTypeFixup(baseType, pctxt, NULL); |
| 16335 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16336 | * Variety |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16337 | * If the <restriction> alternative is chosen, then the |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16338 | * {variety} of the {base type definition}. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16339 | */ |
| 16340 | if (VARIETY_ATOMIC(baseType)) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16341 | type->flags |= XML_SCHEMAS_TYPE_VARIETY_ATOMIC; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16342 | else if (VARIETY_LIST(baseType)) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16343 | type->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST; |
| 16344 | /* |
| 16345 | * Inherit the itemType. |
| 16346 | */ |
| 16347 | type->subtypes = baseType->subtypes; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16348 | } else if (VARIETY_UNION(baseType)) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16349 | type->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION; |
| 16350 | /* |
| 16351 | * NOTE that we won't assign the memberTypes of the base, |
| 16352 | * since this will make trouble when freeing them; we will |
| 16353 | * use a lookup function to access them instead. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16354 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16355 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16356 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16357 | /* |
| 16358 | * Check constraints. |
| 16359 | * |
| 16360 | * TODO: Split this somehow, we need to know first if we can derive |
| 16361 | * from the base type at all! |
| 16362 | */ |
| 16363 | if (type->baseType != NULL) { |
| 16364 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16365 | * Schema Component Constraint: Simple Type Restriction |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16366 | * (Facets) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16367 | * NOTE: Satisfaction of 1 and 2 arise from the fixup |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16368 | * applied beforehand. |
| 16369 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16370 | xmlSchemaCheckSRCSimpleType(pctxt, type); |
| 16371 | xmlSchemaCheckFacetValues(type, pctxt); |
| 16372 | if ((type->facetSet != NULL) || |
| 16373 | (type->baseType->facetSet != NULL)) |
| 16374 | xmlSchemaDeriveAndValidateFacets(pctxt, type); |
| 16375 | /* |
| 16376 | * Whitespace value. |
| 16377 | */ |
| 16378 | xmlSchemaTypeFixupWhitespace(type); |
| 16379 | xmlSchemaTypeFixupOptimFacets(type); |
| 16380 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16381 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16382 | |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 16383 | #ifdef DEBUG_TYPE |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16384 | if (type->node != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16385 | xmlGenericError(xmlGenericErrorContext, |
| 16386 | "Type of %s : %s:%d :", name, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16387 | type->node->doc->URL, |
| 16388 | xmlGetLineNo(type->node)); |
Daniel Veillard | decd64d | 2002-04-18 14:41:51 +0000 | [diff] [blame] | 16389 | } else { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16390 | xmlGenericError(xmlGenericErrorContext, "Type of %s :", name); |
Daniel Veillard | decd64d | 2002-04-18 14:41:51 +0000 | [diff] [blame] | 16391 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16392 | if ((IS_SIMPLE_TYPE(type)) || (IS_COMPLEX_TYPE(type))) { |
| 16393 | switch (type->contentType) { |
| 16394 | case XML_SCHEMA_CONTENT_SIMPLE: |
| 16395 | xmlGenericError(xmlGenericErrorContext, "simple\n"); |
| 16396 | break; |
| 16397 | case XML_SCHEMA_CONTENT_ELEMENTS: |
| 16398 | xmlGenericError(xmlGenericErrorContext, "elements\n"); |
| 16399 | break; |
| 16400 | case XML_SCHEMA_CONTENT_UNKNOWN: |
| 16401 | xmlGenericError(xmlGenericErrorContext, "unknown !!!\n"); |
| 16402 | break; |
| 16403 | case XML_SCHEMA_CONTENT_EMPTY: |
| 16404 | xmlGenericError(xmlGenericErrorContext, "empty\n"); |
| 16405 | break; |
| 16406 | case XML_SCHEMA_CONTENT_MIXED: |
| 16407 | if (xmlSchemaIsParticleEmptiable((xmlSchemaParticlePtr) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16408 | type->subtypes)) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16409 | xmlGenericError(xmlGenericErrorContext, |
| 16410 | "mixed as emptiable particle\n"); |
| 16411 | else |
| 16412 | xmlGenericError(xmlGenericErrorContext, "mixed\n"); |
| 16413 | break; |
| 16414 | /* Removed, since not used. */ |
| 16415 | /* |
| 16416 | case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS: |
| 16417 | xmlGenericError(xmlGenericErrorContext, "mixed or elems\n"); |
| 16418 | break; |
| 16419 | */ |
| 16420 | case XML_SCHEMA_CONTENT_BASIC: |
| 16421 | xmlGenericError(xmlGenericErrorContext, "basic\n"); |
| 16422 | break; |
| 16423 | default: |
| 16424 | xmlGenericError(xmlGenericErrorContext, |
| 16425 | "not registered !!!\n"); |
| 16426 | break; |
| 16427 | } |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 16428 | } |
| 16429 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16430 | } |
| 16431 | |
| 16432 | /** |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 16433 | * xmlSchemaCheckFacet: |
| 16434 | * @facet: the facet |
| 16435 | * @typeDecl: the schema type definition |
Daniel Veillard | 81562d2 | 2005-06-15 13:27:56 +0000 | [diff] [blame] | 16436 | * @pctxt: the schema parser context or NULL |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16437 | * @name: the optional name of the type |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 16438 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16439 | * Checks and computes the values of facets. |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 16440 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16441 | * Returns 0 if valid, a positive error code if not valid and |
| 16442 | * -1 in case of an internal or API error. |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 16443 | */ |
| 16444 | int |
| 16445 | xmlSchemaCheckFacet(xmlSchemaFacetPtr facet, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16446 | xmlSchemaTypePtr typeDecl, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16447 | xmlSchemaParserCtxtPtr pctxt, |
| 16448 | const xmlChar * name ATTRIBUTE_UNUSED) |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 16449 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16450 | int ret = 0, ctxtGiven; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16451 | |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 16452 | if ((facet == NULL) || (typeDecl == NULL)) |
| 16453 | return(-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16454 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16455 | * TODO: will the parser context be given if used from |
| 16456 | * the relaxNG module? |
| 16457 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16458 | if (pctxt == NULL) |
| 16459 | ctxtGiven = 0; |
| 16460 | else |
| 16461 | ctxtGiven = 1; |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 16462 | |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 16463 | switch (facet->type) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16464 | case XML_SCHEMA_FACET_MININCLUSIVE: |
| 16465 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
| 16466 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 16467 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
| 16468 | case XML_SCHEMA_FACET_ENUMERATION: { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16469 | /* |
| 16470 | * Okay we need to validate the value |
| 16471 | * at that point. |
| 16472 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16473 | xmlSchemaTypePtr base; |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 16474 | |
| 16475 | /* 4.3.5.5 Constraints on enumeration Schema Components |
| 16476 | * Schema Component Constraint: enumeration valid restriction |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16477 | * It is an ·error· if any member of {value} is not in the |
| 16478 | * ·value space· of {base type definition}. |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 16479 | * |
| 16480 | * minInclusive, maxInclusive, minExclusive, maxExclusive: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16481 | * The value ·must· be in the |
| 16482 | * ·value space· of the ·base type·. |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 16483 | */ |
| 16484 | /* |
| 16485 | * This function is intended to deliver a compiled value |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 16486 | * on the facet. In this implementation of XML Schemata the |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16487 | * type holding a facet, won't be a built-in type. |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 16488 | * Thus to ensure that other API |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16489 | * calls (relaxng) do work, if the given type is a built-in |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 16490 | * type, we will assume that the given built-in type *is |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16491 | * already* the base type. |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 16492 | */ |
| 16493 | if (typeDecl->type != XML_SCHEMA_TYPE_BASIC) { |
| 16494 | base = typeDecl->baseType; |
| 16495 | if (base == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16496 | PERROR_INT("xmlSchemaCheckFacet", |
| 16497 | "a type user derived type has no base type"); |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 16498 | return (-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16499 | } |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 16500 | } else |
| 16501 | base = typeDecl; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16502 | |
| 16503 | if (! ctxtGiven) { |
| 16504 | /* |
| 16505 | * A context is needed if called from RelaxNG. |
| 16506 | */ |
| 16507 | pctxt = xmlSchemaNewParserCtxt("*"); |
| 16508 | if (pctxt == NULL) |
| 16509 | return (-1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16510 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16511 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16512 | * NOTE: This call does not check the content nodes, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16513 | * since they are not available: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16514 | * facet->node is just the node holding the facet |
| 16515 | * definition, *not* the attribute holding the *value* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16516 | * of the facet. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16517 | */ |
| 16518 | ret = xmlSchemaVCheckCVCSimpleType( |
| 16519 | (xmlSchemaAbstractCtxtPtr) pctxt, facet->node, base, |
| 16520 | facet->value, &(facet->val), 1, 1, 0); |
| 16521 | if (ret != 0) { |
| 16522 | if (ret < 0) { |
| 16523 | /* No error message for RelaxNG. */ |
| 16524 | if (ctxtGiven) { |
| 16525 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) pctxt, |
| 16526 | XML_SCHEMAP_INTERNAL, facet->node, NULL, |
| 16527 | "Internal error: xmlSchemaCheckFacet, " |
| 16528 | "failed to validate the value '%s' of the " |
| 16529 | "facet '%s' against the base type", |
| 16530 | facet->value, xmlSchemaFacetTypeToString(facet->type)); |
| 16531 | } |
| 16532 | goto internal_error; |
| 16533 | } |
| 16534 | ret = XML_SCHEMAP_INVALID_FACET_VALUE; |
| 16535 | /* No error message for RelaxNG. */ |
| 16536 | if (ctxtGiven) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 16537 | xmlChar *str = NULL; |
| 16538 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16539 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) pctxt, |
| 16540 | ret, facet->node, (xmlSchemaTypePtr) facet, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 16541 | "The value '%s' of the facet does not validate " |
| 16542 | "against the base type '%s'", |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16543 | facet->value, |
| 16544 | xmlSchemaFormatQName(&str, |
| 16545 | base->targetNamespace, base->name)); |
| 16546 | FREE_AND_NULL(str); |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 16547 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16548 | goto exit; |
| 16549 | } else if (facet->val == NULL) { |
| 16550 | if (ctxtGiven) { |
| 16551 | PERROR_INT("xmlSchemaCheckFacet", |
| 16552 | "value was not computed"); |
| 16553 | } |
| 16554 | TODO |
| 16555 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16556 | break; |
| 16557 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16558 | case XML_SCHEMA_FACET_PATTERN: |
| 16559 | facet->regexp = xmlRegexpCompile(facet->value); |
| 16560 | if (facet->regexp == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16561 | ret = XML_SCHEMAP_REGEXP_INVALID; |
| 16562 | /* No error message for RelaxNG. */ |
| 16563 | if (ctxtGiven) { |
| 16564 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) pctxt, |
| 16565 | ret, facet->node, typeDecl, |
| 16566 | "The value '%s' of the facet 'pattern' is not a " |
| 16567 | "valid regular expression", |
| 16568 | facet->value, NULL); |
| 16569 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16570 | } |
| 16571 | break; |
| 16572 | case XML_SCHEMA_FACET_TOTALDIGITS: |
| 16573 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
| 16574 | case XML_SCHEMA_FACET_LENGTH: |
| 16575 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 16576 | case XML_SCHEMA_FACET_MINLENGTH:{ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16577 | ret = xmlSchemaValidatePredefinedType( |
| 16578 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NNINTEGER), |
| 16579 | facet->value, &(facet->val)); |
| 16580 | if (ret != 0) { |
| 16581 | if (ret < 0) { |
| 16582 | /* No error message for RelaxNG. */ |
| 16583 | if (ctxtGiven) { |
| 16584 | PERROR_INT("xmlSchemaCheckFacet", |
| 16585 | "validating facet value"); |
| 16586 | } |
| 16587 | goto internal_error; |
| 16588 | } |
| 16589 | ret = XML_SCHEMAP_INVALID_FACET_VALUE; |
| 16590 | /* No error message for RelaxNG. */ |
| 16591 | if (ctxtGiven) { |
| 16592 | /* error code */ |
| 16593 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) pctxt, |
| 16594 | ret, facet->node, typeDecl, |
| 16595 | "The value '%s' of the facet '%s' is not a valid " |
| 16596 | "'nonNegativeInteger'", |
| 16597 | facet->value, |
| 16598 | xmlSchemaFacetTypeToString(facet->type)); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16599 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16600 | } |
| 16601 | break; |
| 16602 | } |
| 16603 | case XML_SCHEMA_FACET_WHITESPACE:{ |
| 16604 | if (xmlStrEqual(facet->value, BAD_CAST "preserve")) { |
| 16605 | facet->whitespace = XML_SCHEMAS_FACET_PRESERVE; |
| 16606 | } else if (xmlStrEqual(facet->value, BAD_CAST "replace")) { |
| 16607 | facet->whitespace = XML_SCHEMAS_FACET_REPLACE; |
| 16608 | } else if (xmlStrEqual(facet->value, BAD_CAST "collapse")) { |
| 16609 | facet->whitespace = XML_SCHEMAS_FACET_COLLAPSE; |
| 16610 | } else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16611 | ret = XML_SCHEMAP_INVALID_FACET_VALUE; |
| 16612 | /* No error message for RelaxNG. */ |
| 16613 | if (ctxtGiven) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 16614 | /* error was previously: XML_SCHEMAP_INVALID_WHITE_SPACE */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16615 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) pctxt, |
| 16616 | ret, facet->node, typeDecl, |
| 16617 | "The value '%s' of the facet 'whitespace' is not " |
| 16618 | "valid", facet->value, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16619 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16620 | } |
| 16621 | } |
| 16622 | default: |
| 16623 | break; |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 16624 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16625 | exit: |
| 16626 | if ((! ctxtGiven) && (pctxt != NULL)) |
| 16627 | xmlSchemaFreeParserCtxt(pctxt); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16628 | return (ret); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16629 | internal_error: |
| 16630 | if ((! ctxtGiven) && (pctxt != NULL)) |
| 16631 | xmlSchemaFreeParserCtxt(pctxt); |
| 16632 | return (-1); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 16633 | } |
| 16634 | |
| 16635 | /** |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16636 | * xmlSchemaCheckFacetValues: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16637 | * @typeDecl: the schema type definition |
| 16638 | * @ctxt: the schema parser context |
| 16639 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16640 | * Checks the default values types, especially for facets |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16641 | */ |
| 16642 | static void |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16643 | xmlSchemaCheckFacetValues(xmlSchemaTypePtr typeDecl, |
| 16644 | xmlSchemaParserCtxtPtr ctxt) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16645 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16646 | const xmlChar *name = typeDecl->name; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16647 | /* |
| 16648 | * NOTE: It is intended to use the facets list, instead |
| 16649 | * of facetSet. |
| 16650 | */ |
| 16651 | if (typeDecl->facets != NULL) { |
| 16652 | xmlSchemaFacetPtr facet = typeDecl->facets; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16653 | |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 16654 | /* |
| 16655 | * Temporarily assign the "schema" to the validation context |
| 16656 | * of the parser context. This is needed for NOTATION validation. |
| 16657 | */ |
| 16658 | if (ctxt->vctxt == NULL) { |
| 16659 | if (xmlSchemaCreateVCtxtOnPCtxt(ctxt) == -1) |
| 16660 | return; |
| 16661 | } |
| 16662 | ctxt->vctxt->schema = ctxt->schema; |
| 16663 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16664 | while (facet != NULL) { |
| 16665 | xmlSchemaCheckFacet(facet, typeDecl, ctxt, name); |
| 16666 | facet = facet->next; |
| 16667 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 16668 | |
| 16669 | ctxt->vctxt->schema = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16670 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16671 | } |
| 16672 | |
| 16673 | /** |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16674 | * xmlSchemaGetCircModelGrDefRef: |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16675 | * @ctxtMGroup: the searched model group |
| 16676 | * @selfMGroup: the second searched model group |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16677 | * @particle: the first particle |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16678 | * |
| 16679 | * This one is intended to be used by |
| 16680 | * xmlSchemaCheckGroupDefCircular only. |
| 16681 | * |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16682 | * Returns the particle with the circular model group definition reference, |
| 16683 | * otherwise NULL. |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16684 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16685 | static xmlSchemaTreeItemPtr |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 16686 | xmlSchemaGetCircModelGrDefRef(xmlSchemaModelGroupDefPtr groupDef, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16687 | xmlSchemaTreeItemPtr particle) |
| 16688 | { |
| 16689 | xmlSchemaTreeItemPtr circ = NULL; |
| 16690 | xmlSchemaTreeItemPtr term; |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 16691 | xmlSchemaModelGroupDefPtr gdef; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16692 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 16693 | for (; particle != NULL; particle = particle->next) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16694 | term = particle->children; |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 16695 | if (term == NULL) |
| 16696 | continue; |
| 16697 | switch (term->type) { |
| 16698 | case XML_SCHEMA_TYPE_GROUP: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16699 | gdef = (xmlSchemaModelGroupDefPtr) term; |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 16700 | if (gdef == groupDef) |
| 16701 | return (particle); |
| 16702 | /* |
| 16703 | * Mark this model group definition to avoid infinite |
| 16704 | * recursion on circular references not yet examined. |
| 16705 | */ |
| 16706 | if (gdef->flags & XML_SCHEMA_MODEL_GROUP_DEF_MARKED) |
| 16707 | continue; |
| 16708 | if (gdef->children != NULL) { |
| 16709 | gdef->flags |= XML_SCHEMA_MODEL_GROUP_DEF_MARKED; |
| 16710 | circ = xmlSchemaGetCircModelGrDefRef(groupDef, |
| 16711 | gdef->children->children); |
| 16712 | gdef->flags ^= XML_SCHEMA_MODEL_GROUP_DEF_MARKED; |
| 16713 | if (circ != NULL) |
| 16714 | return (circ); |
| 16715 | } |
| 16716 | break; |
| 16717 | case XML_SCHEMA_TYPE_SEQUENCE: |
| 16718 | case XML_SCHEMA_TYPE_CHOICE: |
| 16719 | case XML_SCHEMA_TYPE_ALL: |
| 16720 | circ = xmlSchemaGetCircModelGrDefRef(groupDef, term->children); |
| 16721 | if (circ != NULL) |
| 16722 | return (circ); |
| 16723 | break; |
| 16724 | default: |
| 16725 | break; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16726 | } |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16727 | } |
| 16728 | return (NULL); |
| 16729 | } |
| 16730 | |
| 16731 | /** |
| 16732 | * xmlSchemaCheckGroupDefCircular: |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16733 | * @item: the model group definition |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16734 | * @ctxt: the parser context |
| 16735 | * @name: the name |
| 16736 | * |
| 16737 | * Checks for circular references to model group definitions. |
| 16738 | */ |
| 16739 | static void |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16740 | xmlSchemaCheckGroupDefCircular(xmlSchemaModelGroupDefPtr item, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16741 | xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 16742 | const xmlChar * name ATTRIBUTE_UNUSED) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16743 | { |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16744 | /* |
| 16745 | * Schema Component Constraint: Model Group Correct |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16746 | * 2 Circular groups are disallowed. That is, within the {particles} |
| 16747 | * of a group there must not be at any depth a particle whose {term} |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16748 | * is the group itself. |
| 16749 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16750 | if ((item == NULL) || |
| 16751 | (item->type != XML_SCHEMA_TYPE_GROUP) || |
| 16752 | (item->children == NULL)) |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16753 | return; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16754 | { |
| 16755 | xmlSchemaTreeItemPtr circ; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16756 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 16757 | circ = xmlSchemaGetCircModelGrDefRef(item, item->children->children); |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16758 | if (circ != NULL) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16759 | xmlChar *str = NULL; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16760 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16761 | * TODO: The error report is not adequate: this constraint |
| 16762 | * is defined for model groups but not definitions, but since |
| 16763 | * there cannot be any circular model groups without a model group |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16764 | * definition (if not using a construction API), we check those |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16765 | * defintions only. |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16766 | */ |
| 16767 | xmlSchemaPCustomErr(ctxt, |
| 16768 | XML_SCHEMAP_MG_PROPS_CORRECT_2, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16769 | NULL, NULL, GET_NODE(circ), |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16770 | "Circular reference to the model group definition '%s' " |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16771 | "defined", xmlSchemaFormatQName(&str, |
| 16772 | item->targetNamespace, item->name)); |
| 16773 | FREE_AND_NULL(str) |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16774 | /* |
| 16775 | * NOTE: We will cut the reference to avoid further |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16776 | * confusion of the processor. This is a fatal error. |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16777 | */ |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 16778 | circ->children = NULL; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16779 | } |
| 16780 | } |
| 16781 | } |
| 16782 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 16783 | /** |
| 16784 | * xmlSchemaGroupDefTermFixup: |
| 16785 | * @item: the particle with a model group definition as term |
| 16786 | * @ctxt: the parser context |
| 16787 | * @name: the name |
| 16788 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16789 | * Checks cos-all-limited. |
| 16790 | * |
| 16791 | * Assigns the model group of model group definitions to the "term" |
| 16792 | * of the referencing particle. |
| 16793 | * In xmlSchemaMiscRefFixup the model group definitions was assigned |
| 16794 | * to the "term", since needed for the circularity check. |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 16795 | */ |
| 16796 | static void |
| 16797 | xmlSchemaGroupDefTermFixup(xmlSchemaParticlePtr item, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16798 | xmlSchemaParserCtxtPtr ctxt ATTRIBUTE_UNUSED, |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 16799 | const xmlChar * name ATTRIBUTE_UNUSED) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16800 | { |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 16801 | if ((item == NULL) || |
| 16802 | (item->type != XML_SCHEMA_TYPE_PARTICLE) || |
| 16803 | (item->children == NULL) || |
| 16804 | (item->children->type != XML_SCHEMA_TYPE_GROUP) || |
| 16805 | (item->children->children == NULL)) |
| 16806 | return; |
| 16807 | item->children = item->children->children; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16808 | /* |
| 16809 | * TODO: Not nice, but we will anchor cos-all-limited here. |
| 16810 | */ |
| 16811 | if ((item->children->type == XML_SCHEMA_TYPE_ALL) && |
| 16812 | (item->maxOccurs != 1)) { |
| 16813 | /* |
| 16814 | * SPEC (1.2) "the {term} property of a particle with |
| 16815 | * {max occurs}=1which is part of a pair which constitutes the |
| 16816 | * {content type} of a complex type definition." |
| 16817 | */ |
| 16818 | xmlSchemaPCustomErr(ctxt, |
| 16819 | XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_3, |
| 16820 | NULL, (xmlSchemaTypePtr) item, item->node, |
| 16821 | "The particle's 'maxOccurs' must be 1, since an xs:all model " |
| 16822 | "group is its term", NULL); |
| 16823 | } |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 16824 | } |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16825 | |
| 16826 | /** |
| 16827 | * xmlSchemaGetCircAttrGrRef: |
| 16828 | * @ctxtGr: the searched attribute group |
| 16829 | * @attr: the current attribute list to be processed |
| 16830 | * |
| 16831 | * This one is intended to be used by |
| 16832 | * xmlSchemaCheckSRCAttributeGroupCircular only. |
| 16833 | * |
| 16834 | * Returns the circular attribute grou reference, otherwise NULL. |
| 16835 | */ |
| 16836 | static xmlSchemaAttributeGroupPtr |
| 16837 | xmlSchemaGetCircAttrGrRef(xmlSchemaAttributeGroupPtr ctxtGr, |
| 16838 | xmlSchemaAttributePtr attr) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16839 | { |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16840 | xmlSchemaAttributeGroupPtr circ = NULL, gr; |
| 16841 | int marked; |
| 16842 | /* |
| 16843 | * We will search for an attribute group reference which |
| 16844 | * references the context attribute group. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16845 | */ |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16846 | while (attr != NULL) { |
| 16847 | marked = 0; |
| 16848 | if (attr->type == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) { |
| 16849 | gr = (xmlSchemaAttributeGroupPtr) attr; |
| 16850 | if (gr->refItem != NULL) { |
| 16851 | if (gr->refItem == ctxtGr) |
| 16852 | return (gr); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16853 | else if (gr->refItem->flags & |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16854 | XML_SCHEMAS_ATTRGROUP_MARKED) { |
| 16855 | attr = attr->next; |
| 16856 | continue; |
| 16857 | } else { |
| 16858 | /* |
| 16859 | * Mark as visited to avoid infinite recursion on |
| 16860 | * circular references not yet examined. |
| 16861 | */ |
| 16862 | gr->refItem->flags |= XML_SCHEMAS_ATTRGROUP_MARKED; |
| 16863 | marked = 1; |
| 16864 | } |
| 16865 | } |
| 16866 | if (gr->attributes != NULL) |
| 16867 | circ = xmlSchemaGetCircAttrGrRef(ctxtGr, gr->attributes); |
| 16868 | /* |
| 16869 | * Unmark the visited group's attributes. |
| 16870 | */ |
| 16871 | if (marked) |
| 16872 | gr->refItem->flags ^= XML_SCHEMAS_ATTRGROUP_MARKED; |
| 16873 | if (circ != NULL) |
| 16874 | return (circ); |
| 16875 | } |
| 16876 | attr = attr->next; |
| 16877 | } |
| 16878 | return (NULL); |
| 16879 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16880 | |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16881 | /** |
| 16882 | * xmlSchemaCheckSRCAttributeGroupCircular: |
| 16883 | * attrGr: the attribute group definition |
| 16884 | * @ctxt: the parser context |
| 16885 | * @name: the name |
| 16886 | * |
| 16887 | * Checks for circular references of attribute groups. |
| 16888 | */ |
| 16889 | static void |
| 16890 | xmlSchemaCheckAttributeGroupCircular(xmlSchemaAttributeGroupPtr attrGr, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16891 | xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16892 | const xmlChar * name ATTRIBUTE_UNUSED) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16893 | { |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16894 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16895 | * Schema Representation Constraint: |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16896 | * Attribute Group Definition Representation OK |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16897 | * 3 Circular group reference is disallowed outside <redefine>. |
| 16898 | * That is, unless this element information item's parent is |
| 16899 | * <redefine>, then among the [children], if any, there must |
| 16900 | * not be an <attributeGroup> with ref [attribute] which resolves |
| 16901 | * to the component corresponding to this <attributeGroup>. Indirect |
| 16902 | * circularity is also ruled out. That is, when QName resolution |
| 16903 | * (Schema Document) (§3.15.3) is applied to a ·QName· arising from |
| 16904 | * any <attributeGroup>s with a ref [attribute] among the [children], |
| 16905 | * it must not be the case that a ·QName· is encountered at any depth |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16906 | * which resolves to the component corresponding to this <attributeGroup>. |
| 16907 | */ |
| 16908 | /* |
| 16909 | * Only global components can be referenced. |
| 16910 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16911 | if (((attrGr->flags & XML_SCHEMAS_ATTRGROUP_GLOBAL) == 0) || |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16912 | (attrGr->attributes == NULL)) |
| 16913 | return; |
| 16914 | else { |
| 16915 | xmlSchemaAttributeGroupPtr circ; |
| 16916 | |
| 16917 | circ = xmlSchemaGetCircAttrGrRef(attrGr, attrGr->attributes); |
| 16918 | if (circ != NULL) { |
| 16919 | /* |
| 16920 | * TODO: Report the referenced attr group as QName. |
| 16921 | */ |
| 16922 | xmlSchemaPCustomErr(ctxt, |
| 16923 | XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_3, |
| 16924 | NULL, NULL, circ->node, |
| 16925 | "Circular reference to the attribute group '%s' " |
| 16926 | "defined", attrGr->name); |
| 16927 | /* |
| 16928 | * NOTE: We will cut the reference to avoid further |
| 16929 | * confusion of the processor. |
| 16930 | * BADSPEC: The spec should define how to process in this case. |
| 16931 | */ |
| 16932 | circ->attributes = NULL; |
| 16933 | circ->refItem = NULL; |
| 16934 | } |
| 16935 | } |
| 16936 | } |
| 16937 | |
| 16938 | /** |
Daniel Veillard | 13e04c6 | 2002-04-23 17:51:29 +0000 | [diff] [blame] | 16939 | * xmlSchemaAttrGrpFixup: |
| 16940 | * @attrgrpDecl: the schema attribute definition |
| 16941 | * @ctxt: the schema parser context |
| 16942 | * @name: the attribute name |
| 16943 | * |
| 16944 | * Fixes finish doing the computations on the attributes definitions |
| 16945 | */ |
| 16946 | static void |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16947 | xmlSchemaAttrGrpFixup(xmlSchemaAttributeGroupPtr attrgrp, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16948 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name) |
Daniel Veillard | 13e04c6 | 2002-04-23 17:51:29 +0000 | [diff] [blame] | 16949 | { |
| 16950 | if (name == NULL) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16951 | name = attrgrp->name; |
| 16952 | if (attrgrp->attributes != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16953 | return; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16954 | if (attrgrp->ref != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16955 | xmlSchemaAttributeGroupPtr ref; |
Daniel Veillard | 13e04c6 | 2002-04-23 17:51:29 +0000 | [diff] [blame] | 16956 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16957 | ref = xmlSchemaGetAttributeGroup(ctxt->schema, attrgrp->ref, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16958 | attrgrp->refNs); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16959 | if (ref == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16960 | xmlSchemaPResCompAttrErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16961 | XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16962 | (xmlSchemaTypePtr) attrgrp, attrgrp->node, |
| 16963 | "ref", attrgrp->ref, attrgrp->refNs, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16964 | XML_SCHEMA_TYPE_ATTRIBUTEGROUP, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16965 | return; |
| 16966 | } |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 16967 | attrgrp->refItem = ref; |
| 16968 | /* |
| 16969 | * Check for self reference! |
| 16970 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16971 | xmlSchemaAttrGrpFixup(ref, ctxt, NULL); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16972 | attrgrp->attributes = ref->attributes; |
| 16973 | attrgrp->attributeWildcard = ref->attributeWildcard; |
| 16974 | } |
Daniel Veillard | 13e04c6 | 2002-04-23 17:51:29 +0000 | [diff] [blame] | 16975 | } |
| 16976 | |
| 16977 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16978 | * xmlSchemaAttrCheckValConstr: |
| 16979 | * @item: an schema attribute declaration/use |
| 16980 | * @ctxt: a schema parser context |
| 16981 | * @name: the name of the attribute |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16982 | * |
| 16983 | * |
| 16984 | * Schema Component Constraint: Attribute Declaration Properties Correct |
| 16985 | * (a-props-correct) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16986 | * Validates the value constraints of an attribute declaration/use. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16987 | * |
| 16988 | * Fixes finish doing the computations on the attributes definitions |
| 16989 | */ |
| 16990 | static void |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16991 | xmlSchemaCheckAttrValConstr(xmlSchemaAttributePtr item, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16992 | xmlSchemaParserCtxtPtr pctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16993 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 16994 | { |
| 16995 | |
| 16996 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 16997 | * 2 if there is a {value constraint}, the canonical lexical |
| 16998 | * representation of its value must be ·valid· with respect |
| 16999 | * to the {type definition} as defined in String Valid (§3.14.4). |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17000 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17001 | if (item->defValue != NULL) { |
| 17002 | int ret; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17003 | |
| 17004 | if (item->subtypes == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17005 | PERROR_INT("xmlSchemaCheckAttrValConstr", |
| 17006 | "type is missing"); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17007 | return; |
| 17008 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17009 | ret = xmlSchemaVCheckCVCSimpleType((xmlSchemaAbstractCtxtPtr) pctxt, |
| 17010 | item->node, item->subtypes, item->defValue, &(item->defVal), |
| 17011 | 1, 1, 0); |
| 17012 | if (ret != 0) { |
| 17013 | if (ret < 0) { |
| 17014 | PERROR_INT("xmlSchemaAttrCheckValConstr", |
| 17015 | "calling xmlSchemaVCheckCVCSimpleType()"); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17016 | return; |
| 17017 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17018 | ret = XML_SCHEMAP_A_PROPS_CORRECT_2; |
| 17019 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) pctxt, |
| 17020 | ret, item->node, (xmlSchemaTypePtr) item, |
| 17021 | "The value of the value constraint is not valid", NULL, NULL); |
| 17022 | return; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17023 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17024 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17025 | } |
| 17026 | |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17027 | static xmlSchemaElementPtr |
| 17028 | xmlSchemaCheckSubstGroupCircular(xmlSchemaElementPtr elemDecl, |
| 17029 | xmlSchemaElementPtr ancestor) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17030 | { |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17031 | xmlSchemaElementPtr ret; |
| 17032 | |
| 17033 | if (SUBST_GROUP_AFF(ancestor) == NULL) |
| 17034 | return (NULL); |
| 17035 | if (SUBST_GROUP_AFF(ancestor) == elemDecl) |
| 17036 | return (ancestor); |
| 17037 | |
| 17038 | if (SUBST_GROUP_AFF(ancestor)->flags & XML_SCHEMAS_ELEM_CIRCULAR) |
| 17039 | return (NULL); |
| 17040 | SUBST_GROUP_AFF(ancestor)->flags |= XML_SCHEMAS_ELEM_CIRCULAR; |
| 17041 | ret = xmlSchemaCheckSubstGroupCircular(elemDecl, |
| 17042 | SUBST_GROUP_AFF(ancestor)); |
| 17043 | SUBST_GROUP_AFF(ancestor)->flags ^= XML_SCHEMAS_ELEM_CIRCULAR; |
| 17044 | |
| 17045 | return (ret); |
| 17046 | } |
| 17047 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17048 | /** |
| 17049 | * xmlSchemaCheckElemPropsCorrect: |
| 17050 | * @ctxt: a schema parser context |
| 17051 | * @decl: the element declaration |
| 17052 | * @name: the name of the attribute |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17053 | * |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17054 | * Schema Component Constraint: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17055 | * Element Declaration Properties Correct (e-props-correct) |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17056 | * |
| 17057 | * STATUS: |
| 17058 | * missing: (6) |
| 17059 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17060 | static int |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17061 | xmlSchemaCheckElemPropsCorrect(xmlSchemaParserCtxtPtr pctxt, |
| 17062 | xmlSchemaElementPtr elemDecl) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17063 | { |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17064 | int ret = 0; |
| 17065 | xmlSchemaTypePtr typeDef = ELEM_TYPE(elemDecl); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17066 | /* |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17067 | * SPEC (1) "The values of the properties of an element declaration |
| 17068 | * must be as described in the property tableau in The Element |
| 17069 | * Declaration Schema Component (§3.3.1), modulo the impact of Missing |
| 17070 | * Sub-components (§5.3)." |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17071 | */ |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17072 | if (SUBST_GROUP_AFF(elemDecl) != NULL) { |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17073 | xmlSchemaElementPtr head = SUBST_GROUP_AFF(elemDecl), circ; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17074 | |
| 17075 | xmlSchemaCheckElementDeclComponent(head, pctxt, NULL); |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17076 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17077 | * SPEC (3) "If there is a non-·absent· {substitution group |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17078 | * affiliation}, then {scope} must be global." |
| 17079 | */ |
| 17080 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_GLOBAL) == 0) { |
| 17081 | xmlSchemaPCustomErr(pctxt, |
| 17082 | XML_SCHEMAP_E_PROPS_CORRECT_3, |
| 17083 | NULL, (xmlSchemaTypePtr) elemDecl, elemDecl->node, |
| 17084 | "Only global element declarations can have a " |
| 17085 | "substitution group affiliation", NULL); |
| 17086 | ret = XML_SCHEMAP_E_PROPS_CORRECT_3; |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17087 | } |
| 17088 | /* |
| 17089 | * TODO: SPEC (6) "Circular substitution groups are disallowed. |
| 17090 | * That is, it must not be possible to return to an element declaration |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17091 | * by repeatedly following the {substitution group affiliation} |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17092 | * property." |
| 17093 | */ |
| 17094 | if (head == elemDecl) |
| 17095 | circ = head; |
| 17096 | else if (SUBST_GROUP_AFF(head) != NULL) |
| 17097 | circ = xmlSchemaCheckSubstGroupCircular(head, head); |
| 17098 | else |
| 17099 | circ = NULL; |
| 17100 | if (circ != NULL) { |
| 17101 | xmlChar *strA = NULL, *strB = NULL; |
| 17102 | |
| 17103 | xmlSchemaPCustomErrExt(pctxt, |
| 17104 | XML_SCHEMAP_E_PROPS_CORRECT_6, |
| 17105 | NULL, (xmlSchemaTypePtr) circ, circ->node, |
| 17106 | "The element declaration '%s' defines a circular " |
| 17107 | "substitution group to element declaration '%s'", |
| 17108 | xmlSchemaGetComponentQName(&strA, circ), |
| 17109 | xmlSchemaGetComponentQName(&strB, head), |
| 17110 | NULL); |
| 17111 | FREE_AND_NULL(strA) |
| 17112 | FREE_AND_NULL(strB) |
| 17113 | ret = XML_SCHEMAP_E_PROPS_CORRECT_6; |
| 17114 | } |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17115 | /* |
| 17116 | * SPEC (4) "If there is a {substitution group affiliation}, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17117 | * the {type definition} |
| 17118 | * of the element declaration must be validly derived from the {type |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17119 | * definition} of the {substitution group affiliation}, given the value |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17120 | * of the {substitution group exclusions} of the {substitution group |
| 17121 | * affiliation}, as defined in Type Derivation OK (Complex) (§3.4.6) |
| 17122 | * (if the {type definition} is complex) or as defined in |
| 17123 | * Type Derivation OK (Simple) (§3.14.6) (if the {type definition} is |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17124 | * simple)." |
| 17125 | * |
| 17126 | * NOTE: {substitution group exclusions} means the values of the |
| 17127 | * attribute "final". |
| 17128 | */ |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17129 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17130 | if (typeDef != ELEM_TYPE(SUBST_GROUP_AFF(elemDecl))) { |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17131 | int set = 0; |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17132 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17133 | if (head->flags & XML_SCHEMAS_ELEM_FINAL_EXTENSION) |
| 17134 | set |= SUBSET_EXTENSION; |
| 17135 | if (head->flags & XML_SCHEMAS_ELEM_FINAL_RESTRICTION) |
| 17136 | set |= SUBSET_RESTRICTION; |
| 17137 | |
| 17138 | if (xmlSchemaCheckCOSDerivedOK(typeDef, |
| 17139 | ELEM_TYPE(head), set) != 0) { |
| 17140 | xmlChar *strA = NULL, *strB = NULL, *strC = NULL; |
| 17141 | |
| 17142 | ret = XML_SCHEMAP_E_PROPS_CORRECT_4; |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17143 | xmlSchemaPCustomErrExt(pctxt, |
| 17144 | XML_SCHEMAP_E_PROPS_CORRECT_4, |
| 17145 | NULL, (xmlSchemaTypePtr) elemDecl, elemDecl->node, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17146 | "The type definition '%s' was " |
| 17147 | "either rejected by the substitution group " |
| 17148 | "affiliation '%s', or not validly derived from its type " |
| 17149 | "definition '%s'", |
| 17150 | xmlSchemaGetComponentQName(&strA, typeDef), |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17151 | xmlSchemaGetComponentQName(&strB, head), |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17152 | xmlSchemaGetComponentQName(&strC, ELEM_TYPE(head))); |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17153 | FREE_AND_NULL(strA) |
| 17154 | FREE_AND_NULL(strB) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17155 | FREE_AND_NULL(strC) |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17156 | } |
| 17157 | } |
| 17158 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17159 | /* |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17160 | * SPEC (5) "If the {type definition} or {type definition}'s |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17161 | * {content type} |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17162 | * is or is derived from ID then there must not be a {value constraint}. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17163 | * Note: The use of ID as a type definition for elements goes beyond |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17164 | * XML 1.0, and should be avoided if backwards compatibility is desired" |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17165 | */ |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17166 | if ((elemDecl->value != NULL) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17167 | ((IS_SIMPLE_TYPE(typeDef) && |
| 17168 | xmlSchemaIsDerivedFromBuiltInType(typeDef, XML_SCHEMAS_ID)) || |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17169 | (IS_COMPLEX_TYPE(typeDef) && |
| 17170 | HAS_SIMPLE_CONTENT(typeDef) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17171 | xmlSchemaIsDerivedFromBuiltInType(typeDef->contentTypeDef, |
| 17172 | XML_SCHEMAS_ID)))) { |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17173 | |
| 17174 | ret = XML_SCHEMAP_E_PROPS_CORRECT_5; |
| 17175 | xmlSchemaPCustomErr(pctxt, |
| 17176 | XML_SCHEMAP_E_PROPS_CORRECT_5, |
| 17177 | NULL, (xmlSchemaTypePtr) elemDecl, elemDecl->node, |
| 17178 | "The type definition (or type definition's content type) is or " |
| 17179 | "is derived from ID; value constraints are not allowed in " |
| 17180 | "conjunction with such a type definition", NULL); |
| 17181 | } else if (elemDecl->value != NULL) { |
| 17182 | int vcret; |
| 17183 | xmlNodePtr node = NULL; |
| 17184 | |
| 17185 | /* |
| 17186 | * SPEC (2) "If there is a {value constraint}, the canonical lexical |
| 17187 | * representation of its value must be ·valid· with respect to the |
| 17188 | * {type definition} as defined in Element Default Valid (Immediate) |
| 17189 | * (§3.3.6)." |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17190 | */ |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17191 | if (typeDef == NULL) { |
| 17192 | xmlSchemaPErr(pctxt, elemDecl->node, |
| 17193 | XML_SCHEMAP_INTERNAL, |
| 17194 | "Internal error: xmlSchemaCheckElemPropsCorrect, " |
| 17195 | "type is missing... skipping validation of " |
| 17196 | "the value constraint", NULL, NULL); |
| 17197 | return (-1); |
| 17198 | } |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17199 | if (elemDecl->node != NULL) { |
| 17200 | if (elemDecl->flags & XML_SCHEMAS_ELEM_FIXED) |
| 17201 | node = (xmlNodePtr) xmlHasProp(elemDecl->node, |
| 17202 | BAD_CAST "fixed"); |
| 17203 | else |
| 17204 | node = (xmlNodePtr) xmlHasProp(elemDecl->node, |
| 17205 | BAD_CAST "default"); |
| 17206 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17207 | vcret = xmlSchemaParseCheckCOSValidDefault(pctxt, node, |
| 17208 | typeDef, elemDecl->value, &(elemDecl->defVal)); |
| 17209 | if (vcret != 0) { |
| 17210 | if (vcret < 0) { |
| 17211 | PERROR_INT("xmlSchemaElemCheckValConstr", |
| 17212 | "failed to validate the value constraint of an " |
| 17213 | "element declaration"); |
| 17214 | return (-1); |
| 17215 | } |
| 17216 | return (vcret); |
| 17217 | } |
| 17218 | } |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17219 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17220 | return (ret); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17221 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17222 | |
| 17223 | /** |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17224 | * xmlSchemaCheckElemSubstGroup: |
| 17225 | * @ctxt: a schema parser context |
| 17226 | * @decl: the element declaration |
| 17227 | * @name: the name of the attribute |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17228 | * |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17229 | * Schema Component Constraint: |
| 17230 | * Substitution Group (cos-equiv-class) |
| 17231 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17232 | * In Libxml2 the subst. groups will be precomputed, in terms of that |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17233 | * a list will be built for each subst. group head, holding all direct |
| 17234 | * referents to this head. |
| 17235 | * NOTE that this function needs: |
| 17236 | * 1. circular subst. groups to be checked beforehand |
| 17237 | * 2. the declaration's type to be derived from the head's type |
| 17238 | * |
| 17239 | * STATUS: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17240 | * |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17241 | */ |
| 17242 | static void |
| 17243 | xmlSchemaCheckElemSubstGroup(xmlSchemaParserCtxtPtr ctxt, |
| 17244 | xmlSchemaElementPtr elemDecl) |
| 17245 | { |
| 17246 | if ((SUBST_GROUP_AFF(elemDecl) == NULL) || |
| 17247 | /* SPEC (1) "Its {abstract} is false." */ |
| 17248 | (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT)) |
| 17249 | return; |
| 17250 | { |
| 17251 | xmlSchemaElementPtr head; |
| 17252 | xmlSchemaTypePtr headType, type; |
| 17253 | int set, methSet; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17254 | /* |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17255 | * SPEC (2) "It is validly substitutable for HEAD subject to HEAD's |
| 17256 | * {disallowed substitutions} as the blocking constraint, as defined in |
| 17257 | * Substitution Group OK (Transitive) (§3.3.6)." |
| 17258 | */ |
| 17259 | for (head = SUBST_GROUP_AFF(elemDecl); head != NULL; |
| 17260 | head = SUBST_GROUP_AFF(head)) { |
| 17261 | set = 0; |
| 17262 | methSet = 0; |
| 17263 | /* |
| 17264 | * The blocking constraints. |
| 17265 | */ |
| 17266 | if (head->flags & XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION) |
| 17267 | continue; |
| 17268 | headType = head->subtypes; |
| 17269 | type = elemDecl->subtypes; |
| 17270 | if (headType == type) |
| 17271 | goto add_member; |
| 17272 | if (head->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) |
| 17273 | set |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION; |
| 17274 | if (head->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) |
| 17275 | set |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION; |
| 17276 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17277 | * SPEC: Substitution Group OK (Transitive) (2.3) |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17278 | * "The set of all {derivation method}s involved in the |
| 17279 | * derivation of D's {type definition} from C's {type definition} |
| 17280 | * does not intersect with the union of the blocking constraint, |
| 17281 | * C's {prohibited substitutions} (if C is complex, otherwise the |
| 17282 | * empty set) and the {prohibited substitutions} (respectively the |
| 17283 | * empty set) of any intermediate {type definition}s in the |
| 17284 | * derivation of D's {type definition} from C's {type definition}." |
| 17285 | */ |
| 17286 | /* |
| 17287 | * OPTIMIZE TODO: Optimize this a bit, since, if traversing the |
| 17288 | * subst.head axis, the methSet does not need to be computed for |
| 17289 | * the full depth over and over. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17290 | */ |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17291 | /* |
| 17292 | * The set of all {derivation method}s involved in the derivation |
| 17293 | */ |
| 17294 | while ((type != NULL) && (type != headType)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17295 | if ((type->flags & |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17296 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) && |
| 17297 | ((methSet & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) == 0)) |
| 17298 | methSet |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17299 | |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17300 | if ((type->flags & |
| 17301 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) && |
| 17302 | ((methSet & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) == 0)) |
| 17303 | methSet |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION; |
| 17304 | |
| 17305 | type = type->baseType; |
| 17306 | } |
| 17307 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17308 | * The {prohibited substitutions} of all intermediate types + |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17309 | * the head's type. |
| 17310 | */ |
| 17311 | type = elemDecl->subtypes->baseType; |
| 17312 | while (type != NULL) { |
| 17313 | if (IS_COMPLEX_TYPE(type)) { |
| 17314 | if ((type->flags & |
| 17315 | XML_SCHEMAS_TYPE_BLOCK_EXTENSION) && |
| 17316 | ((set & XML_SCHEMAS_TYPE_BLOCK_EXTENSION) == 0)) |
| 17317 | set |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION; |
| 17318 | if ((type->flags & |
| 17319 | XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) && |
| 17320 | ((set & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) == 0)) |
| 17321 | set |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION; |
| 17322 | } else |
| 17323 | break; |
| 17324 | if (type == headType) |
| 17325 | break; |
| 17326 | type = type->baseType; |
| 17327 | } |
| 17328 | if ((set != 0) && |
| 17329 | (((set & XML_SCHEMAS_TYPE_BLOCK_EXTENSION) && |
| 17330 | (methSet & XML_SCHEMAS_TYPE_BLOCK_EXTENSION)) || |
| 17331 | ((set & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) && |
| 17332 | (methSet & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION)))) { |
| 17333 | continue; |
| 17334 | } |
| 17335 | add_member: |
| 17336 | xmlSchemaAddElementSubstitutionMember(ctxt, head, elemDecl); |
| 17337 | if ((head->flags & XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD) == 0) |
| 17338 | head->flags |= XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD; |
| 17339 | } |
| 17340 | } |
| 17341 | } |
| 17342 | |
| 17343 | /** |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17344 | * xmlSchemaCheckElementDeclComponent |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17345 | * @item: an schema element declaration/particle |
| 17346 | * @ctxt: a schema parser context |
| 17347 | * @name: the name of the attribute |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17348 | * |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17349 | * Validates the value constraints of an element declaration. |
| 17350 | * |
| 17351 | * Fixes finish doing the computations on the element declarations. |
| 17352 | */ |
| 17353 | static void |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17354 | xmlSchemaCheckElementDeclComponent(xmlSchemaElementPtr elemDecl, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17355 | xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17356 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 17357 | { |
| 17358 | if (elemDecl == NULL) |
| 17359 | return; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17360 | if (elemDecl->flags & XML_SCHEMAS_ELEM_INTERNAL_CHECKED) |
| 17361 | return; |
| 17362 | elemDecl->flags |= XML_SCHEMAS_ELEM_INTERNAL_CHECKED; |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17363 | if (xmlSchemaCheckElemPropsCorrect(ctxt, elemDecl) == 0) |
| 17364 | xmlSchemaCheckElemSubstGroup(ctxt, elemDecl); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17365 | } |
| 17366 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 17367 | /** |
| 17368 | * xmlSchemaMiscRefFixup: |
| 17369 | * @item: an schema component |
| 17370 | * @ctxt: a schema parser context |
| 17371 | * @name: the internal name of the component |
| 17372 | * |
| 17373 | * Resolves references of misc. schema components. |
| 17374 | */ |
| 17375 | static void |
| 17376 | xmlSchemaMiscRefFixup(xmlSchemaTreeItemPtr item, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17377 | xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 17378 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 17379 | { |
| 17380 | if (item->type == XML_SCHEMA_TYPE_PARTICLE) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17381 | if ((item->children != NULL) && |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 17382 | (item->children->type == XML_SCHEMA_EXTRA_QNAMEREF)) { |
| 17383 | xmlSchemaQNameRefPtr ref = (xmlSchemaQNameRefPtr) item->children; |
| 17384 | xmlSchemaTreeItemPtr refItem; |
| 17385 | /* |
| 17386 | * Resolve the reference. |
| 17387 | */ |
| 17388 | item->children = NULL; |
| 17389 | refItem = xmlSchemaGetNamedComponent(ctxt->schema, |
| 17390 | ref->itemType, ref->name, ref->targetNamespace); |
| 17391 | if (refItem == NULL) { |
| 17392 | xmlSchemaPResCompAttrErr(ctxt, XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17393 | NULL, GET_NODE(item), "ref", ref->name, |
| 17394 | ref->targetNamespace, ref->itemType, NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 17395 | } else { |
| 17396 | if (refItem->type == XML_SCHEMA_TYPE_GROUP) { |
| 17397 | /* |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17398 | * NOTE that we will assign the model group definition |
| 17399 | * itself to the "term" of the particle. This will ease |
| 17400 | * the check for circular model group definitions. After |
| 17401 | * that the "term" will be assigned the model group of the |
| 17402 | * model group definition. |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 17403 | */ |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17404 | item->children = refItem; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 17405 | } else |
| 17406 | item->children = refItem; |
| 17407 | } |
| 17408 | } |
| 17409 | } |
| 17410 | } |
| 17411 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17412 | static int |
| 17413 | xmlSchemaAreValuesEqual(xmlSchemaValPtr x, |
| 17414 | xmlSchemaValPtr y) |
| 17415 | { |
| 17416 | xmlSchemaTypePtr tx, ty, ptx, pty; |
| 17417 | int ret; |
| 17418 | |
| 17419 | while (x != NULL) { |
| 17420 | /* Same types. */ |
| 17421 | tx = xmlSchemaGetBuiltInType(xmlSchemaGetValType(x)); |
| 17422 | ty = xmlSchemaGetBuiltInType(xmlSchemaGetValType(y)); |
| 17423 | ptx = xmlSchemaGetPrimitiveType(tx); |
| 17424 | pty = xmlSchemaGetPrimitiveType(ty); |
| 17425 | /* |
| 17426 | * (1) if a datatype T' is ·derived· by ·restriction· from an |
| 17427 | * atomic datatype T then the ·value space· of T' is a subset of |
| 17428 | * the ·value space· of T. */ |
| 17429 | /* |
| 17430 | * (2) if datatypes T' and T'' are ·derived· by ·restriction· |
| 17431 | * from a common atomic ancestor T then the ·value space·s of T' |
| 17432 | * and T'' may overlap. |
| 17433 | */ |
| 17434 | if (ptx != pty) |
| 17435 | return(0); |
| 17436 | /* |
| 17437 | * We assume computed values to be normalized, so do a fast |
| 17438 | * string comparison for string based types. |
| 17439 | */ |
| 17440 | if ((ptx->builtInType == XML_SCHEMAS_STRING) || |
| 17441 | IS_ANY_SIMPLE_TYPE(ptx)) { |
| 17442 | if (! xmlStrEqual( |
| 17443 | xmlSchemaValueGetAsString(x), |
| 17444 | xmlSchemaValueGetAsString(y))) |
| 17445 | return (0); |
| 17446 | } else { |
| 17447 | ret = xmlSchemaCompareValuesWhtsp( |
| 17448 | x, XML_SCHEMA_WHITESPACE_PRESERVE, |
| 17449 | y, XML_SCHEMA_WHITESPACE_PRESERVE); |
| 17450 | if (ret == -2) |
| 17451 | return(-1); |
| 17452 | if (ret != 0) |
| 17453 | return(0); |
| 17454 | } |
| 17455 | /* |
| 17456 | * Lists. |
| 17457 | */ |
| 17458 | x = xmlSchemaValueGetNext(x); |
| 17459 | if (x != NULL) { |
| 17460 | y = xmlSchemaValueGetNext(y); |
| 17461 | if (y == NULL) |
| 17462 | return (0); |
| 17463 | } else if (xmlSchemaValueGetNext(y) != NULL) |
| 17464 | return (0); |
| 17465 | else |
| 17466 | return (1); |
| 17467 | } |
| 17468 | return (0); |
| 17469 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 17470 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17471 | /** |
| 17472 | * xmlSchemaAttrFixup: |
| 17473 | * @item: an schema attribute declaration/use. |
| 17474 | * @ctxt: a schema parser context |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17475 | * @name: the name of the attribute |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17476 | * |
| 17477 | * Fixes finish doing the computations on attribute declarations/uses. |
| 17478 | */ |
| 17479 | static void |
| 17480 | xmlSchemaAttrFixup(xmlSchemaAttributePtr item, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17481 | xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17482 | const xmlChar * name ATTRIBUTE_UNUSED) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17483 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17484 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17485 | * TODO: If including this is done twice (!) for every attribute. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17486 | * -> Hmm, check if this is still done. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17487 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 17488 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17489 | * The simple type definition corresponding to the <simpleType> element |
| 17490 | * information item in the [children], if present, otherwise the simple |
| 17491 | * type definition ·resolved· to by the ·actual value· of the type |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 17492 | * [attribute], if present, otherwise the ·simple ur-type definition·. |
| 17493 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17494 | if (item->flags & XML_SCHEMAS_ATTR_INTERNAL_RESOLVED) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17495 | return; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17496 | item->flags |= XML_SCHEMAS_ATTR_INTERNAL_RESOLVED; |
| 17497 | if (item->subtypes != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17498 | return; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17499 | if (item->typeName != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17500 | xmlSchemaTypePtr type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17501 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17502 | type = xmlSchemaGetType(ctxt->schema, item->typeName, |
| 17503 | item->typeNs); |
| 17504 | if ((type == NULL) || (! IS_SIMPLE_TYPE(type))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17505 | xmlSchemaPResCompAttrErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 17506 | XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17507 | (xmlSchemaTypePtr) item, item->node, |
| 17508 | "type", item->typeName, item->typeNs, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17509 | XML_SCHEMA_TYPE_SIMPLE, NULL); |
| 17510 | } else |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17511 | item->subtypes = type; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17512 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17513 | } else if (item->ref != NULL) { |
| 17514 | xmlSchemaAttributePtr decl; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17515 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17516 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17517 | * We have an attribute use here; assign the referenced |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17518 | * attribute declaration. |
| 17519 | */ |
| 17520 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17521 | * TODO: Evaluate, what errors could occur if the declaration is not |
| 17522 | * found. It might be possible that the "typefixup" might crash if |
| 17523 | * no ref declaration was found. |
| 17524 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17525 | decl = xmlSchemaGetAttributeDecl(ctxt->schema, item->ref, item->refNs); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17526 | if (decl == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17527 | xmlSchemaPResCompAttrErr(ctxt, |
| 17528 | XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17529 | (xmlSchemaTypePtr) item, item->node, |
| 17530 | "ref", item->ref, item->refNs, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17531 | XML_SCHEMA_TYPE_ATTRIBUTE, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17532 | return; |
| 17533 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17534 | item->refDecl = decl; |
| 17535 | xmlSchemaAttrFixup(decl, ctxt, NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17536 | item->subtypes = decl->subtypes; |
| 17537 | /* |
| 17538 | * Attribute Use Correct |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17539 | * au-props-correct.2: If the {attribute declaration} has a fixed |
| 17540 | * {value constraint}, then if the attribute use itself has a |
| 17541 | * {value constraint}, it must also be fixed and its value must match |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17542 | * that of the {attribute declaration}'s {value constraint}. |
| 17543 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17544 | if ((decl->flags & XML_SCHEMAS_ATTR_FIXED) && |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17545 | (item->defValue != NULL)) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17546 | if ((item->flags & XML_SCHEMAS_ATTR_FIXED) == 0) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17547 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17548 | XML_SCHEMAP_AU_PROPS_CORRECT_2, |
| 17549 | NULL, NULL, item->node, |
| 17550 | "The attribute declaration has a 'fixed' value constraint " |
| 17551 | ", thus it must be 'fixed' in attribute use as well", |
| 17552 | NULL); |
| 17553 | } else { |
| 17554 | if (! xmlSchemaAreValuesEqual(item->defVal, decl->defVal)) { |
| 17555 | xmlSchemaPCustomErr(ctxt, |
| 17556 | XML_SCHEMAP_AU_PROPS_CORRECT_2, |
| 17557 | NULL, NULL, item->node, |
| 17558 | "The 'fixed' value constraint of the attribute use " |
| 17559 | "must match the attribute declaration's value " |
| 17560 | "constraint '%s'", |
| 17561 | decl->defValue); |
| 17562 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17563 | } |
| 17564 | /* |
| 17565 | * FUTURE: One should change the values of the attr. use |
| 17566 | * if ever validation should be attempted even if the |
| 17567 | * schema itself was not fully valid. |
| 17568 | */ |
| 17569 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 17570 | } else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17571 | item->subtypes = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 17572 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17573 | } |
| 17574 | |
| 17575 | /** |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17576 | * xmlSchemaResolveIDCKeyRef: |
| 17577 | * @idc: the identity-constraint definition |
| 17578 | * @ctxt: the schema parser context |
| 17579 | * @name: the attribute name |
| 17580 | * |
| 17581 | * Resolve keyRef references to key/unique IDCs. |
| 17582 | */ |
| 17583 | static void |
| 17584 | xmlSchemaResolveIDCKeyRef(xmlSchemaIDCPtr idc, |
Kasimier T. Buchcik | c306d90 | 2005-07-08 21:37:44 +0000 | [diff] [blame] | 17585 | xmlSchemaParserCtxtPtr pctxt, |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 17586 | const xmlChar * name ATTRIBUTE_UNUSED) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17587 | { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17588 | if (idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) |
| 17589 | return; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17590 | if (idc->ref->name != NULL) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17591 | idc->ref->item = (xmlSchemaBasicItemPtr) xmlHashLookup2( |
Kasimier T. Buchcik | c306d90 | 2005-07-08 21:37:44 +0000 | [diff] [blame] | 17592 | pctxt->schema->idcDef, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17593 | idc->ref->name, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17594 | idc->ref->targetNamespace); |
| 17595 | if (idc->ref->item == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17596 | /* |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17597 | * TODO: It is actually not an error to fail to resolve. |
| 17598 | */ |
Kasimier T. Buchcik | c306d90 | 2005-07-08 21:37:44 +0000 | [diff] [blame] | 17599 | xmlSchemaPResCompAttrErr(pctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17600 | XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17601 | (xmlSchemaTypePtr) idc, idc->node, |
| 17602 | "refer", idc->ref->name, |
| 17603 | idc->ref->targetNamespace, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17604 | XML_SCHEMA_TYPE_IDC_KEYREF, NULL); |
| 17605 | return; |
Kasimier T. Buchcik | c306d90 | 2005-07-08 21:37:44 +0000 | [diff] [blame] | 17606 | } else { |
| 17607 | if (idc->nbFields != |
| 17608 | ((xmlSchemaIDCPtr) idc->ref->item)->nbFields) { |
| 17609 | xmlChar *str = NULL; |
| 17610 | xmlSchemaIDCPtr refer; |
| 17611 | |
| 17612 | refer = (xmlSchemaIDCPtr) idc->ref->item; |
| 17613 | /* |
| 17614 | * SPEC c-props-correct(2) |
| 17615 | * "If the {identity-constraint category} is keyref, |
| 17616 | * the cardinality of the {fields} must equal that of |
| 17617 | * the {fields} of the {referenced key}. |
| 17618 | */ |
| 17619 | xmlSchemaPCustomErr(pctxt, |
| 17620 | XML_SCHEMAP_C_PROPS_CORRECT, |
| 17621 | NULL, (xmlSchemaTypePtr) idc, idc->node, |
| 17622 | "The cardinality of the keyref differs from the " |
| 17623 | "cardinality of the referenced key '%s'", |
| 17624 | xmlSchemaFormatQName(&str, refer->targetNamespace, |
| 17625 | refer->name) |
| 17626 | ); |
| 17627 | FREE_AND_NULL(str) |
| 17628 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17629 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17630 | } |
| 17631 | } |
| 17632 | |
| 17633 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17634 | * xmlSchemaParse: |
| 17635 | * @ctxt: a schema validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17636 | * |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 17637 | * parse a schema definition resource and build an internal |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17638 | * XML Shema struture which can be used to validate instances. |
| 17639 | * *WARNING* this interface is highly subject to change |
| 17640 | * |
| 17641 | * Returns the internal XML Schema structure built from the resource or |
| 17642 | * NULL in case of error |
| 17643 | */ |
| 17644 | xmlSchemaPtr |
| 17645 | xmlSchemaParse(xmlSchemaParserCtxtPtr ctxt) |
| 17646 | { |
| 17647 | xmlSchemaPtr ret = NULL; |
| 17648 | xmlDocPtr doc; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 17649 | xmlNodePtr root; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 17650 | int preserve = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17651 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17652 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17653 | * This one is used if the schema to be parsed was specified via |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17654 | * the API; i.e. not automatically by the validated instance document. |
| 17655 | */ |
| 17656 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17657 | xmlSchemaInitTypes(); |
| 17658 | |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 17659 | if (ctxt == NULL) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17660 | return (NULL); |
| 17661 | |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 17662 | ctxt->nberrors = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17663 | ctxt->counter = 0; |
| 17664 | ctxt->container = NULL; |
| 17665 | |
| 17666 | /* |
| 17667 | * First step is to parse the input document into an DOM/Infoset |
| 17668 | */ |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 17669 | if (ctxt->URL != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17670 | doc = xmlReadFile((const char *) ctxt->URL, NULL, |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 17671 | SCHEMAS_PARSE_OPTIONS); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17672 | if (doc == NULL) { |
| 17673 | xmlSchemaPErr(ctxt, NULL, |
| 17674 | XML_SCHEMAP_FAILED_LOAD, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17675 | "xmlSchemaParse: could not load '%s'.\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17676 | ctxt->URL, NULL); |
| 17677 | return (NULL); |
| 17678 | } |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 17679 | } else if (ctxt->buffer != NULL) { |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 17680 | doc = xmlReadMemory(ctxt->buffer, ctxt->size, NULL, NULL, |
| 17681 | SCHEMAS_PARSE_OPTIONS); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17682 | if (doc == NULL) { |
| 17683 | xmlSchemaPErr(ctxt, NULL, |
| 17684 | XML_SCHEMAP_FAILED_PARSE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17685 | "xmlSchemaParse: could not parse.\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17686 | NULL, NULL); |
| 17687 | return (NULL); |
| 17688 | } |
| 17689 | doc->URL = xmlStrdup(BAD_CAST "in_memory_buffer"); |
Daniel Veillard | 6576528 | 2004-01-08 16:59:30 +0000 | [diff] [blame] | 17690 | ctxt->URL = xmlDictLookup(ctxt->dict, BAD_CAST "in_memory_buffer", -1); |
Daniel Veillard | 9d75150 | 2003-10-29 13:21:47 +0000 | [diff] [blame] | 17691 | } else if (ctxt->doc != NULL) { |
| 17692 | doc = ctxt->doc; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 17693 | preserve = 1; |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 17694 | } else { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17695 | xmlSchemaPErr(ctxt, NULL, |
| 17696 | XML_SCHEMAP_NOTHING_TO_PARSE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17697 | "xmlSchemaParse: could not parse.\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17698 | NULL, NULL); |
| 17699 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17700 | } |
| 17701 | |
| 17702 | /* |
| 17703 | * Then extract the root and Schema parse it |
| 17704 | */ |
| 17705 | root = xmlDocGetRootElement(doc); |
| 17706 | if (root == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17707 | xmlSchemaPErr(ctxt, (xmlNodePtr) doc, |
| 17708 | XML_SCHEMAP_NOROOT, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17709 | "The schema has no document element.\n", NULL, NULL); |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 17710 | if (!preserve) { |
| 17711 | xmlFreeDoc(doc); |
| 17712 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17713 | return (NULL); |
| 17714 | } |
| 17715 | |
| 17716 | /* |
| 17717 | * Remove all the blank text nodes |
| 17718 | */ |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 17719 | xmlSchemaCleanupDoc(ctxt, root); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17720 | |
| 17721 | /* |
| 17722 | * Then do the parsing for good |
| 17723 | */ |
| 17724 | ret = xmlSchemaParseSchema(ctxt, root); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 17725 | if (ret == NULL) { |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 17726 | if (!preserve) { |
| 17727 | xmlFreeDoc(doc); |
| 17728 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17729 | return (NULL); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 17730 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17731 | ret->doc = doc; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 17732 | ret->preserve = preserve; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17733 | ctxt->schema = ret; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17734 | ctxt->ctxtType = NULL; |
| 17735 | ctxt->parentItem = NULL; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 17736 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17737 | /* |
| 17738 | * Resolve base types of simple/complex types. |
| 17739 | */ |
| 17740 | xmlHashScan(ret->typeDecl, (xmlHashScanner) xmlSchemaResolveTypeDefs, ctxt); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17741 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17742 | if (ctxt->nberrors != 0) |
| 17743 | goto exit; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 17744 | |
| 17745 | if (ret->volatiles != NULL) { |
| 17746 | xmlSchemaItemListPtr list = (xmlSchemaItemListPtr) ret->volatiles; |
| 17747 | int i; |
| 17748 | xmlSchemaTreeItemPtr item; |
| 17749 | |
| 17750 | for (i = 0; i < list->nbItems; i++) { |
| 17751 | item = (xmlSchemaTreeItemPtr) list->items[i]; |
| 17752 | if (item->type == XML_SCHEMA_TYPE_PARTICLE) |
| 17753 | xmlSchemaMiscRefFixup(item, ctxt, NULL); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 17754 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17755 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17756 | /* |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 17757 | * Then fixup all attributes declarations |
| 17758 | */ |
| 17759 | xmlHashScan(ret->attrDecl, (xmlHashScanner) xmlSchemaAttrFixup, ctxt); |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 17760 | /* |
| 17761 | * Then fixup all attributes group declarations |
| 17762 | */ |
| 17763 | xmlHashScan(ret->attrgrpDecl, (xmlHashScanner) xmlSchemaAttrGrpFixup, |
| 17764 | ctxt); |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 17765 | /* |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17766 | * Resolve identity-constraint keyRefs. |
| 17767 | */ |
| 17768 | xmlHashScan(ret->idcDef, (xmlHashScanner) xmlSchemaResolveIDCKeyRef, ctxt); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 17769 | /* |
| 17770 | * Check type defnitions for circular references. |
| 17771 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17772 | xmlHashScan(ret->typeDecl, (xmlHashScanner) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 17773 | xmlSchemaCheckTypeDefCircular, ctxt); |
| 17774 | /* |
| 17775 | * Check model groups defnitions for circular references. |
| 17776 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17777 | xmlHashScan(ret->groupDecl, (xmlHashScanner) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 17778 | xmlSchemaCheckGroupDefCircular, ctxt); |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17779 | /* |
| 17780 | * Set the "term" of particles pointing to model group definitions |
| 17781 | * to the contained model group. |
| 17782 | */ |
| 17783 | if (ret->volatiles != NULL) { |
| 17784 | xmlSchemaItemListPtr list = (xmlSchemaItemListPtr) ret->volatiles; |
| 17785 | int i; |
| 17786 | xmlSchemaParticlePtr item; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17787 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17788 | for (i = 0; i < list->nbItems; i++) { |
| 17789 | item = (xmlSchemaParticlePtr) list->items[i]; |
| 17790 | if (item->type == XML_SCHEMA_TYPE_PARTICLE) |
| 17791 | xmlSchemaGroupDefTermFixup(item, ctxt, NULL); |
| 17792 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17793 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17794 | /* |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 17795 | * Check attribute groups for circular references. |
| 17796 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17797 | xmlHashScan(ret->attrgrpDecl, (xmlHashScanner) |
| 17798 | xmlSchemaCheckAttributeGroupCircular, ctxt); |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 17799 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17800 | * Then fix references of element declaration; apply constraints. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17801 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17802 | xmlHashScanFull(ret->elemDecl, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 17803 | (xmlHashScannerFull) xmlSchemaElementFixup, ctxt); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 17804 | /* |
| 17805 | * We will stop here if the schema was not valid to avoid internal errors |
| 17806 | * on missing sub-components. This is not conforming to the spec, since it |
| 17807 | * allows missing components, but it might make further processing crash. |
| 17808 | * So see it as a very strict handling, which might be made more lax in the |
| 17809 | * future. |
| 17810 | */ |
| 17811 | if (ctxt->nberrors != 0) |
| 17812 | goto exit; |
| 17813 | /* |
| 17814 | * Then fixup all types properties |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17815 | */ |
| 17816 | xmlHashScan(ret->typeDecl, (xmlHashScanner) xmlSchemaTypeFixup, ctxt); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17817 | /* |
| 17818 | * Validate the value constraint of attribute declarations/uses. |
| 17819 | */ |
| 17820 | xmlHashScan(ret->attrDecl, (xmlHashScanner) xmlSchemaCheckAttrValConstr, ctxt); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17821 | /* |
| 17822 | * Validate the value constraint of element declarations. |
| 17823 | */ |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 17824 | xmlHashScan(ret->elemDecl, (xmlHashScanner) xmlSchemaCheckElementDeclComponent, ctxt); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17825 | |
| 17826 | if (ctxt->nberrors != 0) |
| 17827 | goto exit; |
| 17828 | |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17829 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17830 | * TODO: cos-element-consistent, cos-all-limited |
| 17831 | * |
| 17832 | * Then build the content model for all complex types |
| 17833 | */ |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 17834 | xmlHashScan(ret->typeDecl, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17835 | (xmlHashScanner) xmlSchemaBuildContentModel, ctxt); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17836 | |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 17837 | exit: |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 17838 | if (ctxt->nberrors != 0) { |
| 17839 | xmlSchemaFree(ret); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17840 | ret = NULL; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 17841 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17842 | return (ret); |
| 17843 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17844 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17845 | /** |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 17846 | * xmlSchemaSetParserErrors: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17847 | * @ctxt: a schema validation context |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 17848 | * @err: the error callback |
| 17849 | * @warn: the warning callback |
| 17850 | * @ctx: contextual data for the callbacks |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17851 | * |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 17852 | * Set the callback functions used to handle errors for a validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17853 | */ |
| 17854 | void |
| 17855 | xmlSchemaSetParserErrors(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17856 | xmlSchemaValidityErrorFunc err, |
| 17857 | xmlSchemaValidityWarningFunc warn, void *ctx) |
| 17858 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17859 | if (ctxt == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17860 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17861 | ctxt->error = err; |
| 17862 | ctxt->warning = warn; |
| 17863 | ctxt->userData = ctx; |
| 17864 | } |
| 17865 | |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 17866 | /** |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 17867 | * xmlSchemaGetParserErrors: |
| 17868 | * @ctxt: a XMl-Schema parser context |
| 17869 | * @err: the error callback result |
| 17870 | * @warn: the warning callback result |
| 17871 | * @ctx: contextual data for the callbacks result |
| 17872 | * |
| 17873 | * Get the callback information used to handle errors for a parser context |
| 17874 | * |
| 17875 | * Returns -1 in case of failure, 0 otherwise |
| 17876 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17877 | int |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 17878 | xmlSchemaGetParserErrors(xmlSchemaParserCtxtPtr ctxt, |
| 17879 | xmlSchemaValidityErrorFunc * err, |
| 17880 | xmlSchemaValidityWarningFunc * warn, void **ctx) |
| 17881 | { |
| 17882 | if (ctxt == NULL) |
| 17883 | return(-1); |
| 17884 | if (err != NULL) |
| 17885 | *err = ctxt->error; |
| 17886 | if (warn != NULL) |
| 17887 | *warn = ctxt->warning; |
| 17888 | if (ctx != NULL) |
| 17889 | *ctx = ctxt->userData; |
| 17890 | return(0); |
| 17891 | } |
| 17892 | |
| 17893 | /** |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 17894 | * xmlSchemaFacetTypeToString: |
| 17895 | * @type: the facet type |
| 17896 | * |
| 17897 | * Convert the xmlSchemaTypeType to a char string. |
| 17898 | * |
| 17899 | * Returns the char string representation of the facet type if the |
| 17900 | * type is a facet and an "Internal Error" string otherwise. |
| 17901 | */ |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 17902 | static const xmlChar * |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 17903 | xmlSchemaFacetTypeToString(xmlSchemaTypeType type) |
| 17904 | { |
| 17905 | switch (type) { |
| 17906 | case XML_SCHEMA_FACET_PATTERN: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 17907 | return (BAD_CAST "pattern"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17908 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 17909 | return (BAD_CAST "maxExclusive"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17910 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 17911 | return (BAD_CAST "maxInclusive"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17912 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 17913 | return (BAD_CAST "minExclusive"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17914 | case XML_SCHEMA_FACET_MININCLUSIVE: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 17915 | return (BAD_CAST "minInclusive"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17916 | case XML_SCHEMA_FACET_WHITESPACE: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 17917 | return (BAD_CAST "whiteSpace"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17918 | case XML_SCHEMA_FACET_ENUMERATION: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 17919 | return (BAD_CAST "enumeration"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17920 | case XML_SCHEMA_FACET_LENGTH: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 17921 | return (BAD_CAST "length"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17922 | case XML_SCHEMA_FACET_MAXLENGTH: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 17923 | return (BAD_CAST "maxLength"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17924 | case XML_SCHEMA_FACET_MINLENGTH: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 17925 | return (BAD_CAST "minLength"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17926 | case XML_SCHEMA_FACET_TOTALDIGITS: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 17927 | return (BAD_CAST "totalDigits"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17928 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 17929 | return (BAD_CAST "fractionDigits"); |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 17930 | default: |
| 17931 | break; |
| 17932 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 17933 | return (BAD_CAST "Internal Error"); |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 17934 | } |
| 17935 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17936 | static xmlSchemaWhitespaceValueType |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17937 | xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type) |
| 17938 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17939 | /* |
| 17940 | * The normalization type can be changed only for types which are derived |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17941 | * from xsd:string. |
| 17942 | */ |
| 17943 | if (type->type == XML_SCHEMA_TYPE_BASIC) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17944 | /* |
| 17945 | * Note that we assume a whitespace of preserve for anySimpleType. |
| 17946 | */ |
| 17947 | if ((type->builtInType == XML_SCHEMAS_STRING) || |
| 17948 | (type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE)) |
| 17949 | return(XML_SCHEMA_WHITESPACE_PRESERVE); |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 17950 | else if (type->builtInType == XML_SCHEMAS_NORMSTRING) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17951 | return(XML_SCHEMA_WHITESPACE_REPLACE); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17952 | else { |
| 17953 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17954 | * For all ·atomic· datatypes other than string (and types ·derived· |
| 17955 | * by ·restriction· from it) the value of whiteSpace is fixed to |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17956 | * collapse |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17957 | * Note that this includes built-in list datatypes. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17958 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17959 | return(XML_SCHEMA_WHITESPACE_COLLAPSE); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 17960 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17961 | } else if (VARIETY_LIST(type)) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 17962 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17963 | * For list types the facet "whiteSpace" is fixed to "collapse". |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 17964 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17965 | return (XML_SCHEMA_WHITESPACE_COLLAPSE); |
| 17966 | } else if (VARIETY_UNION(type)) { |
| 17967 | return (XML_SCHEMA_WHITESPACE_UNKNOWN); |
| 17968 | } else if (VARIETY_ATOMIC(type)) { |
| 17969 | if (type->flags & XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE) |
| 17970 | return (XML_SCHEMA_WHITESPACE_PRESERVE); |
| 17971 | else if (type->flags & XML_SCHEMAS_TYPE_WHITESPACE_REPLACE) |
| 17972 | return (XML_SCHEMA_WHITESPACE_REPLACE); |
| 17973 | else |
| 17974 | return (XML_SCHEMA_WHITESPACE_COLLAPSE); |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 17975 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 17976 | return (-1); |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 17977 | } |
| 17978 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17979 | /************************************************************************ |
| 17980 | * * |
| 17981 | * Simple type validation * |
| 17982 | * * |
| 17983 | ************************************************************************/ |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 17984 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17985 | |
| 17986 | /************************************************************************ |
| 17987 | * * |
| 17988 | * DOM Validation code * |
| 17989 | * * |
| 17990 | ************************************************************************/ |
| 17991 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17992 | static void |
| 17993 | xmlSchemaPostSchemaAssembleFixup(xmlSchemaParserCtxtPtr ctxt) |
| 17994 | { |
| 17995 | int i, nbItems; |
| 17996 | xmlSchemaTypePtr item, *items; |
| 17997 | |
| 17998 | |
| 17999 | /* |
| 18000 | * During the Assemble of the schema ctxt->curItems has |
| 18001 | * been filled with the relevant new items. Fix those up. |
| 18002 | */ |
| 18003 | nbItems = ctxt->assemble->nbItems; |
| 18004 | items = (xmlSchemaTypePtr *) ctxt->assemble->items; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18005 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18006 | for (i = 0; i < nbItems; i++) { |
| 18007 | item = items[i]; |
| 18008 | switch (item->type) { |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 18009 | case XML_SCHEMA_TYPE_COMPLEX: |
| 18010 | case XML_SCHEMA_TYPE_SIMPLE: |
| 18011 | xmlSchemaResolveTypeDefs(item, ctxt, NULL); |
| 18012 | break; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18013 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 18014 | xmlSchemaAttrFixup((xmlSchemaAttributePtr) item, ctxt, NULL); |
| 18015 | break; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18016 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18017 | xmlSchemaAttrGrpFixup((xmlSchemaAttributeGroupPtr) item, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18018 | ctxt, NULL); |
| 18019 | break; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 18020 | case XML_SCHEMA_TYPE_PARTICLE: |
| 18021 | xmlSchemaMiscRefFixup((xmlSchemaTreeItemPtr) item, ctxt, NULL); |
Kasimier T. Buchcik | c306d90 | 2005-07-08 21:37:44 +0000 | [diff] [blame] | 18022 | break; |
| 18023 | case XML_SCHEMA_TYPE_IDC_KEY: |
| 18024 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
| 18025 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
| 18026 | xmlSchemaResolveIDCKeyRef((xmlSchemaIDCPtr) item, ctxt, NULL); |
| 18027 | break; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18028 | default: |
| 18029 | break; |
| 18030 | } |
| 18031 | } |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 18032 | if (ctxt->nberrors != 0) |
| 18033 | return; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18034 | /* |
| 18035 | * Circularity checks. |
| 18036 | */ |
| 18037 | for (i = 0; i < nbItems; i++) { |
| 18038 | item = items[i]; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 18039 | switch (item->type) { |
| 18040 | case XML_SCHEMA_TYPE_COMPLEX: |
| 18041 | case XML_SCHEMA_TYPE_SIMPLE: |
| 18042 | xmlSchemaCheckTypeDefCircular( |
| 18043 | (xmlSchemaTypePtr) item, ctxt, NULL); |
| 18044 | break; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18045 | case XML_SCHEMA_TYPE_GROUP: |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 18046 | xmlSchemaCheckGroupDefCircular( |
| 18047 | (xmlSchemaModelGroupDefPtr) item, ctxt, NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18048 | break; |
| 18049 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
| 18050 | xmlSchemaCheckAttributeGroupCircular( |
| 18051 | (xmlSchemaAttributeGroupPtr) item, ctxt, NULL); |
| 18052 | break; |
| 18053 | default: |
| 18054 | break; |
| 18055 | } |
| 18056 | } |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 18057 | if (ctxt->nberrors != 0) |
| 18058 | return; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18059 | /* |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 18060 | * Set the "term" of particles pointing to model group definitions |
| 18061 | * to the contained model group. |
| 18062 | */ |
| 18063 | for (i = 0; i < nbItems; i++) { |
| 18064 | item = items[i]; |
| 18065 | if ((item->type == XML_SCHEMA_TYPE_PARTICLE) && |
| 18066 | (((xmlSchemaParticlePtr) item)->children != NULL) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18067 | (((xmlSchemaParticlePtr) item)->children->type == |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 18068 | XML_SCHEMA_TYPE_GROUP)) { |
| 18069 | xmlSchemaGroupDefTermFixup((xmlSchemaParticlePtr) item, |
| 18070 | ctxt, NULL); |
| 18071 | } |
| 18072 | } |
Kasimier T. Buchcik | c306d90 | 2005-07-08 21:37:44 +0000 | [diff] [blame] | 18073 | if (ctxt->nberrors != 0) |
| 18074 | return; |
| 18075 | for (i = 0; i < nbItems; i++) { |
| 18076 | item = items[i]; |
| 18077 | switch (item->type) { |
| 18078 | case XML_SCHEMA_TYPE_ELEMENT: |
| 18079 | xmlSchemaElementFixup((xmlSchemaElementPtr) item, ctxt, |
| 18080 | NULL, NULL, NULL); |
| 18081 | break; |
| 18082 | default: |
| 18083 | break; |
| 18084 | } |
| 18085 | } |
| 18086 | if (ctxt->nberrors != 0) |
| 18087 | return; |
| 18088 | |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 18089 | /* |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 18090 | * Fixup for simple/complex types. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18091 | */ |
| 18092 | for (i = 0; i < nbItems; i++) { |
| 18093 | item = items[i]; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18094 | switch (item->type) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18095 | case XML_SCHEMA_TYPE_SIMPLE: |
| 18096 | case XML_SCHEMA_TYPE_COMPLEX: |
| 18097 | xmlSchemaTypeFixup(item, ctxt, NULL); |
| 18098 | break; |
| 18099 | default: |
| 18100 | break; |
| 18101 | } |
| 18102 | } |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 18103 | if (ctxt->nberrors != 0) |
| 18104 | return; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18105 | /* |
| 18106 | * Validate value contraint values. |
| 18107 | */ |
| 18108 | for (i = 0; i < nbItems; i++) { |
| 18109 | item = items[i]; |
| 18110 | switch (item->type) { |
| 18111 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 18112 | xmlSchemaCheckAttrValConstr((xmlSchemaAttributePtr) item, |
| 18113 | ctxt, NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18114 | break; |
| 18115 | case XML_SCHEMA_TYPE_ELEMENT: |
Kasimier T. Buchcik | 1a99a39 | 2005-04-08 11:23:56 +0000 | [diff] [blame] | 18116 | xmlSchemaCheckElementDeclComponent((xmlSchemaElementPtr) item, |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 18117 | ctxt, NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18118 | break; |
| 18119 | default: |
| 18120 | break; |
| 18121 | } |
| 18122 | } |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 18123 | if (ctxt->nberrors != 0) |
| 18124 | return; |
| 18125 | /* |
| 18126 | * Build the content model for complex types. |
| 18127 | */ |
| 18128 | for (i = 0; i < nbItems; i++) { |
| 18129 | item = items[i]; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18130 | switch (item->type) { |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 18131 | case XML_SCHEMA_TYPE_COMPLEX: |
| 18132 | xmlSchemaBuildContentModel(item, ctxt, NULL); |
| 18133 | break; |
| 18134 | default: |
| 18135 | break; |
| 18136 | } |
| 18137 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18138 | } |
| 18139 | |
| 18140 | /** |
| 18141 | * xmlSchemaAssembleByLocation: |
| 18142 | * @pctxt: a schema parser context |
| 18143 | * @vctxt: a schema validation context |
| 18144 | * @schema: the existing schema |
| 18145 | * @node: the node that fired the assembling |
| 18146 | * @nsName: the namespace name of the new schema |
| 18147 | * @location: the location of the schema |
| 18148 | * |
| 18149 | * Expands an existing schema by an additional schema. |
| 18150 | * |
| 18151 | * Returns 0 if the new schema is correct, a positive error code |
| 18152 | * number otherwise and -1 in case of an internal or API error. |
| 18153 | */ |
| 18154 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18155 | xmlSchemaAssembleByLocation(xmlSchemaValidCtxtPtr vctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18156 | xmlSchemaPtr schema, |
| 18157 | xmlNodePtr node, |
| 18158 | const xmlChar *nsName, |
| 18159 | const xmlChar *location) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18160 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18161 | const xmlChar *targetNs, *oldtns; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18162 | xmlDocPtr doc, olddoc; |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 18163 | int oldflags, ret = 0, oldIsS4S; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18164 | xmlNodePtr docElem; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18165 | xmlSchemaParserCtxtPtr pctxt; |
| 18166 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18167 | /* |
| 18168 | * This should be used: |
| 18169 | * 1. on <import>(s) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18170 | * 2. if requested by the validated instance |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18171 | * 3. if requested via the API |
| 18172 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18173 | if ((vctxt == NULL) || (schema == NULL)) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18174 | return (-1); |
| 18175 | /* |
| 18176 | * Create a temporary parser context. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18177 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18178 | if ((vctxt->pctxt == NULL) && |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18179 | (xmlSchemaCreatePCtxtOnVCtxt(vctxt) == -1)) |
| 18180 | return (-1); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18181 | pctxt = vctxt->pctxt; |
| 18182 | /* |
| 18183 | * Set the counter to produce unique names for anonymous items. |
| 18184 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18185 | pctxt->counter = schema->counter; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18186 | /* |
| 18187 | * Acquire the schema document. |
| 18188 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18189 | ret = xmlSchemaAcquireSchemaDoc((xmlSchemaAbstractCtxtPtr) vctxt, schema, |
| 18190 | node, nsName, location, &doc, &targetNs, 0); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18191 | if (ret != 0) { |
| 18192 | if (doc != NULL) |
| 18193 | xmlFreeDoc(doc); |
| 18194 | } else if (doc != NULL) { |
| 18195 | docElem = xmlDocGetRootElement(doc); |
| 18196 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18197 | * Create new assemble info. |
| 18198 | */ |
| 18199 | if (pctxt->assemble == NULL) { |
| 18200 | pctxt->assemble = xmlSchemaNewAssemble(); |
| 18201 | if (pctxt->assemble == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18202 | xmlSchemaVErrMemory(vctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18203 | "Memory error: xmlSchemaAssembleByLocation, " |
| 18204 | "allocating assemble info", NULL); |
| 18205 | xmlFreeDoc(doc); |
| 18206 | return (-1); |
| 18207 | } |
| 18208 | } |
| 18209 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18210 | * Save and reset the context & schema. |
| 18211 | */ |
| 18212 | oldflags = schema->flags; |
| 18213 | oldtns = schema->targetNamespace; |
| 18214 | olddoc = schema->doc; |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 18215 | oldIsS4S = vctxt->pctxt->isS4S; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18216 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18217 | xmlSchemaClearSchemaDefaults(schema); |
| 18218 | schema->targetNamespace = targetNs; |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 18219 | if ((targetNs != NULL) && |
| 18220 | xmlStrEqual(targetNs, xmlSchemaNs)) { |
| 18221 | /* |
| 18222 | * We are parsing the schema for schema! |
| 18223 | */ |
| 18224 | vctxt->pctxt->isS4S = 1; |
| 18225 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18226 | /* schema->nbCurItems = 0; */ |
| 18227 | pctxt->schema = schema; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18228 | pctxt->ctxtType = NULL; |
| 18229 | pctxt->parentItem = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18230 | |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 18231 | xmlSchemaParseSchemaDefaults(pctxt, schema, docElem); |
| 18232 | if (pctxt->nberrors != 0) { |
| 18233 | vctxt->nberrors += pctxt->nberrors; |
| 18234 | goto finally; |
| 18235 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18236 | xmlSchemaParseSchemaTopLevel(pctxt, schema, docElem->children); |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 18237 | if (pctxt->nberrors != 0) { |
| 18238 | vctxt->nberrors += pctxt->nberrors; |
| 18239 | goto finally; |
| 18240 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18241 | xmlSchemaPostSchemaAssembleFixup(pctxt); |
Kasimier T. Buchcik | 016d92e | 2005-04-08 20:08:40 +0000 | [diff] [blame] | 18242 | if (pctxt->nberrors != 0) |
| 18243 | vctxt->nberrors += pctxt->nberrors; |
| 18244 | finally: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18245 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18246 | * Set the counter of items. |
| 18247 | */ |
| 18248 | schema->counter = pctxt->counter; |
| 18249 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18250 | * Free the list of assembled components. |
| 18251 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18252 | pctxt->assemble->nbItems = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18253 | /* |
| 18254 | * Restore the context & schema. |
| 18255 | */ |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 18256 | vctxt->pctxt->isS4S = oldIsS4S; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18257 | schema->flags = oldflags; |
| 18258 | schema->targetNamespace = oldtns; |
| 18259 | schema->doc = olddoc; |
| 18260 | ret = pctxt->err; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18261 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18262 | return (ret); |
| 18263 | } |
| 18264 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18265 | static xmlSchemaAttrInfoPtr |
| 18266 | xmlSchemaGetMetaAttrInfo(xmlSchemaValidCtxtPtr vctxt, |
| 18267 | int metaType) |
| 18268 | { |
| 18269 | if (vctxt->nbAttrInfos == 0) |
| 18270 | return (NULL); |
| 18271 | { |
| 18272 | int i; |
| 18273 | xmlSchemaAttrInfoPtr iattr; |
| 18274 | |
| 18275 | for (i = 0; i < vctxt->nbAttrInfos; i++) { |
| 18276 | iattr = vctxt->attrInfos[i]; |
| 18277 | if (iattr->metaType == metaType) |
| 18278 | return (iattr); |
| 18279 | } |
| 18280 | |
| 18281 | } |
| 18282 | return (NULL); |
| 18283 | } |
| 18284 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18285 | /** |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18286 | * xmlSchemaAssembleByXSI: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18287 | * @vctxt: a schema validation context |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18288 | * |
| 18289 | * Expands an existing schema by an additional schema using |
| 18290 | * the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attribute |
| 18291 | * of an instance. If xsi:noNamespaceSchemaLocation is used, @noNamespace |
| 18292 | * must be set to 1. |
| 18293 | * |
| 18294 | * Returns 0 if the new schema is correct, a positive error code |
| 18295 | * number otherwise and -1 in case of an internal or API error. |
| 18296 | */ |
| 18297 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18298 | xmlSchemaAssembleByXSI(xmlSchemaValidCtxtPtr vctxt) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18299 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18300 | const xmlChar *cur, *end; |
| 18301 | const xmlChar *nsname = NULL, *location; |
| 18302 | int count = 0; |
| 18303 | int ret = 0; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18304 | xmlSchemaAttrInfoPtr iattr; |
| 18305 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18306 | /* |
| 18307 | * Parse the value; we will assume an even number of values |
| 18308 | * to be given (this is how Xerces and XSV work). |
| 18309 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18310 | iattr = xmlSchemaGetMetaAttrInfo(vctxt, |
| 18311 | XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC); |
| 18312 | if (iattr == NULL) |
| 18313 | xmlSchemaGetMetaAttrInfo(vctxt, |
| 18314 | XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC); |
| 18315 | if (iattr == NULL) |
| 18316 | return (0); |
| 18317 | cur = iattr->value; |
| 18318 | do { |
| 18319 | if (iattr->metaType == XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18320 | /* |
| 18321 | * Get the namespace name. |
| 18322 | */ |
| 18323 | while (IS_BLANK_CH(*cur)) |
| 18324 | cur++; |
| 18325 | end = cur; |
| 18326 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 18327 | end++; |
| 18328 | if (end == cur) |
| 18329 | break; |
| 18330 | count++; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18331 | nsname = xmlDictLookup(vctxt->schema->dict, cur, end - cur); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18332 | cur = end; |
| 18333 | } |
| 18334 | /* |
| 18335 | * Get the URI. |
| 18336 | */ |
| 18337 | while (IS_BLANK_CH(*cur)) |
| 18338 | cur++; |
| 18339 | end = cur; |
| 18340 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 18341 | end++; |
| 18342 | if (end == cur) |
| 18343 | break; |
| 18344 | count++; |
| 18345 | location = xmlDictLookup(vctxt->schema->dict, cur, end - cur); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18346 | cur = end; |
| 18347 | ret = xmlSchemaAssembleByLocation(vctxt, vctxt->schema, |
| 18348 | iattr->node, nsname, location); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18349 | if (ret == -1) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18350 | VERROR_INT("xmlSchemaAssembleByXSI", |
| 18351 | "assembling schemata"); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18352 | return (-1); |
| 18353 | } |
| 18354 | } while (*cur != 0); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18355 | return (ret); |
| 18356 | } |
| 18357 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18358 | #define VAL_CREATE_DICT if (vctxt->dict == NULL) vctxt->dict = xmlDictCreate(); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18359 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18360 | static const xmlChar * |
| 18361 | xmlSchemaLookupNamespace(xmlSchemaValidCtxtPtr vctxt, |
| 18362 | const xmlChar *prefix) |
| 18363 | { |
| 18364 | if (vctxt->sax != NULL) { |
| 18365 | int i, j; |
| 18366 | xmlSchemaNodeInfoPtr inode; |
| 18367 | |
| 18368 | for (i = vctxt->depth; i >= 0; i--) { |
| 18369 | if (vctxt->elemInfos[i]->nbNsBindings != 0) { |
| 18370 | inode = vctxt->elemInfos[i]; |
| 18371 | for (j = 0; j < inode->nbNsBindings * 2; j += 2) { |
| 18372 | if (((prefix == NULL) && |
| 18373 | (inode->nsBindings[j] == NULL)) || |
| 18374 | ((prefix != NULL) && xmlStrEqual(prefix, |
| 18375 | inode->nsBindings[j]))) { |
| 18376 | |
| 18377 | /* |
| 18378 | * Note that the namespace bindings are already |
| 18379 | * in a string dict. |
| 18380 | */ |
| 18381 | return (inode->nsBindings[j+1]); |
| 18382 | } |
| 18383 | } |
| 18384 | } |
| 18385 | } |
| 18386 | return (NULL); |
Daniel Veillard | 39e5c89 | 2005-07-03 22:48:50 +0000 | [diff] [blame] | 18387 | #ifdef LIBXML_WRITER_ENABLED |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18388 | } else if (vctxt->reader != NULL) { |
| 18389 | xmlChar *nsName; |
| 18390 | |
| 18391 | nsName = xmlTextReaderLookupNamespace(vctxt->reader, prefix); |
| 18392 | if (nsName != NULL) { |
| 18393 | const xmlChar *ret; |
| 18394 | |
| 18395 | VAL_CREATE_DICT; |
| 18396 | ret = xmlDictLookup(vctxt->dict, nsName, -1); |
| 18397 | xmlFree(nsName); |
| 18398 | return (ret); |
| 18399 | } else |
| 18400 | return (NULL); |
Daniel Veillard | 39e5c89 | 2005-07-03 22:48:50 +0000 | [diff] [blame] | 18401 | #endif |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18402 | } else { |
| 18403 | xmlNsPtr ns; |
| 18404 | |
| 18405 | if ((vctxt->inode->node == NULL) || |
| 18406 | (vctxt->inode->node->doc == NULL)) { |
| 18407 | VERROR_INT("xmlSchemaLookupNamespace", |
| 18408 | "no node or node's doc avaliable"); |
| 18409 | return (NULL); |
| 18410 | } |
| 18411 | ns = xmlSearchNs(vctxt->inode->node->doc, |
| 18412 | vctxt->inode->node, prefix); |
| 18413 | if (ns != NULL) |
| 18414 | return (ns->href); |
| 18415 | return (NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18416 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18417 | } |
| 18418 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18419 | /* |
| 18420 | * This one works on the schema of the validation context. |
| 18421 | */ |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 18422 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18423 | xmlSchemaValidateNotation(xmlSchemaValidCtxtPtr vctxt, |
| 18424 | xmlSchemaPtr schema, |
| 18425 | xmlNodePtr node, |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 18426 | const xmlChar *value, |
| 18427 | xmlSchemaValPtr *val, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18428 | int valNeeded) |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 18429 | { |
| 18430 | int ret; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18431 | |
| 18432 | if (vctxt && (vctxt->schema == NULL)) { |
| 18433 | VERROR_INT("xmlSchemaValidateNotation", |
| 18434 | "a schema is needed on the validation context"); |
| 18435 | return (-1); |
| 18436 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 18437 | ret = xmlValidateQName(value, 1); |
| 18438 | if (ret != 0) |
| 18439 | return (ret); |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 18440 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18441 | xmlChar *localName = NULL; |
| 18442 | xmlChar *prefix = NULL; |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 18443 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18444 | localName = xmlSplitQName2(value, &prefix); |
| 18445 | if (prefix != NULL) { |
| 18446 | const xmlChar *nsName = NULL; |
| 18447 | |
| 18448 | if (vctxt != NULL) |
| 18449 | nsName = xmlSchemaLookupNamespace(vctxt, BAD_CAST prefix); |
| 18450 | else if (node != NULL) { |
| 18451 | xmlNsPtr ns = xmlSearchNs(node->doc, node, prefix); |
| 18452 | if (ns != NULL) |
| 18453 | nsName = ns->href; |
| 18454 | } else { |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 18455 | xmlFree(prefix); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18456 | xmlFree(localName); |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 18457 | return (1); |
| 18458 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18459 | if (nsName == NULL) { |
| 18460 | xmlFree(prefix); |
| 18461 | xmlFree(localName); |
| 18462 | return (1); |
| 18463 | } |
| 18464 | if (xmlHashLookup2(schema->notaDecl, localName, |
| 18465 | nsName) != NULL) { |
| 18466 | if (valNeeded && (val != NULL)) { |
| 18467 | (*val) = xmlSchemaNewNOTATIONValue(BAD_CAST localName, |
| 18468 | BAD_CAST xmlStrdup(nsName)); |
| 18469 | if (*val == NULL) |
| 18470 | ret = -1; |
| 18471 | } |
| 18472 | } else |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 18473 | ret = 1; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18474 | xmlFree(prefix); |
| 18475 | xmlFree(localName); |
| 18476 | } else { |
| 18477 | if (xmlHashLookup2(schema->notaDecl, value, NULL) != NULL) { |
| 18478 | if (valNeeded && (val != NULL)) { |
| 18479 | (*val) = xmlSchemaNewNOTATIONValue( |
| 18480 | BAD_CAST xmlStrdup(value), NULL); |
| 18481 | if (*val == NULL) |
| 18482 | ret = -1; |
| 18483 | } |
| 18484 | } else |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18485 | return (1); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18486 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18487 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18488 | return (ret); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18489 | } |
| 18490 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18491 | /************************************************************************ |
| 18492 | * * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18493 | * Validation of identity-constraints (IDC) * |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18494 | * * |
| 18495 | ************************************************************************/ |
| 18496 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18497 | /** |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18498 | * xmlSchemaAugmentIDC: |
| 18499 | * @idcDef: the IDC definition |
| 18500 | * |
| 18501 | * Creates an augmented IDC definition item. |
| 18502 | * |
| 18503 | * Returns the item, or NULL on internal errors. |
| 18504 | */ |
| 18505 | static void |
| 18506 | xmlSchemaAugmentIDC(xmlSchemaIDCPtr idcDef, |
| 18507 | xmlSchemaValidCtxtPtr vctxt) |
| 18508 | { |
| 18509 | xmlSchemaIDCAugPtr aidc; |
| 18510 | |
| 18511 | aidc = (xmlSchemaIDCAugPtr) xmlMalloc(sizeof(xmlSchemaIDCAug)); |
| 18512 | if (aidc == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18513 | xmlSchemaVErrMemory(vctxt, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18514 | "xmlSchemaAugmentIDC: allocating an augmented IDC definition", |
| 18515 | NULL); |
| 18516 | return; |
| 18517 | } |
| 18518 | aidc->bubbleDepth = -1; |
| 18519 | aidc->def = idcDef; |
| 18520 | aidc->next = NULL; |
| 18521 | if (vctxt->aidcs == NULL) |
| 18522 | vctxt->aidcs = aidc; |
| 18523 | else { |
| 18524 | aidc->next = vctxt->aidcs; |
| 18525 | vctxt->aidcs = aidc; |
| 18526 | } |
| 18527 | } |
| 18528 | |
| 18529 | /** |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18530 | * xmlSchemaIDCNewBinding: |
| 18531 | * @idcDef: the IDC definition of this binding |
| 18532 | * |
| 18533 | * Creates a new IDC binding. |
| 18534 | * |
| 18535 | * Returns the new binding in case of succeeded, NULL on internal errors. |
| 18536 | */ |
| 18537 | static xmlSchemaPSVIIDCBindingPtr |
| 18538 | xmlSchemaIDCNewBinding(xmlSchemaIDCPtr idcDef) |
| 18539 | { |
| 18540 | xmlSchemaPSVIIDCBindingPtr ret; |
| 18541 | |
| 18542 | ret = (xmlSchemaPSVIIDCBindingPtr) xmlMalloc( |
| 18543 | sizeof(xmlSchemaPSVIIDCBinding)); |
| 18544 | if (ret == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18545 | xmlSchemaVErrMemory(NULL, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18546 | "allocating a PSVI IDC binding item", NULL); |
| 18547 | return (NULL); |
| 18548 | } |
| 18549 | memset(ret, 0, sizeof(xmlSchemaPSVIIDCBinding)); |
| 18550 | ret->definition = idcDef; |
| 18551 | return (ret); |
| 18552 | } |
| 18553 | |
| 18554 | /** |
| 18555 | * xmlSchemaIDCStoreNodeTableItem: |
| 18556 | * @vctxt: the WXS validation context |
| 18557 | * @item: the IDC node table item |
| 18558 | * |
| 18559 | * The validation context is used to store an IDC node table items. |
| 18560 | * They are stored to avoid copying them if IDC node-tables are merged |
| 18561 | * with corresponding parent IDC node-tables (bubbling). |
| 18562 | * |
| 18563 | * Returns 0 if succeeded, -1 on internal errors. |
| 18564 | */ |
| 18565 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18566 | xmlSchemaIDCStoreNodeTableItem(xmlSchemaValidCtxtPtr vctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18567 | xmlSchemaPSVIIDCNodePtr item) |
| 18568 | { |
| 18569 | /* |
| 18570 | * Add to gobal list. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18571 | */ |
| 18572 | if (vctxt->idcNodes == NULL) { |
| 18573 | vctxt->idcNodes = (xmlSchemaPSVIIDCNodePtr *) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18574 | xmlMalloc(20 * sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 18575 | if (vctxt->idcNodes == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18576 | xmlSchemaVErrMemory(vctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18577 | "allocating the IDC node table item list", NULL); |
| 18578 | return (-1); |
| 18579 | } |
| 18580 | vctxt->sizeIdcNodes = 20; |
| 18581 | } else if (vctxt->sizeIdcNodes <= vctxt->nbIdcNodes) { |
| 18582 | vctxt->sizeIdcNodes *= 2; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18583 | vctxt->idcNodes = (xmlSchemaPSVIIDCNodePtr *) |
| 18584 | xmlRealloc(vctxt->idcNodes, vctxt->sizeIdcNodes * |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18585 | sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 18586 | if (vctxt->idcNodes == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18587 | xmlSchemaVErrMemory(vctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18588 | "re-allocating the IDC node table item list", NULL); |
| 18589 | return (-1); |
| 18590 | } |
| 18591 | } |
| 18592 | vctxt->idcNodes[vctxt->nbIdcNodes++] = item; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18593 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18594 | return (0); |
| 18595 | } |
| 18596 | |
| 18597 | /** |
| 18598 | * xmlSchemaIDCStoreKey: |
| 18599 | * @vctxt: the WXS validation context |
| 18600 | * @item: the IDC key |
| 18601 | * |
| 18602 | * The validation context is used to store an IDC key. |
| 18603 | * |
| 18604 | * Returns 0 if succeeded, -1 on internal errors. |
| 18605 | */ |
| 18606 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18607 | xmlSchemaIDCStoreKey(xmlSchemaValidCtxtPtr vctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18608 | xmlSchemaPSVIIDCKeyPtr key) |
| 18609 | { |
| 18610 | /* |
| 18611 | * Add to gobal list. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18612 | */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18613 | if (vctxt->idcKeys == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18614 | vctxt->idcKeys = (xmlSchemaPSVIIDCKeyPtr *) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18615 | xmlMalloc(40 * sizeof(xmlSchemaPSVIIDCKeyPtr)); |
| 18616 | if (vctxt->idcKeys == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18617 | xmlSchemaVErrMemory(vctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18618 | "allocating the IDC key storage list", NULL); |
| 18619 | return (-1); |
| 18620 | } |
| 18621 | vctxt->sizeIdcKeys = 40; |
| 18622 | } else if (vctxt->sizeIdcKeys <= vctxt->nbIdcKeys) { |
| 18623 | vctxt->sizeIdcKeys *= 2; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18624 | vctxt->idcKeys = (xmlSchemaPSVIIDCKeyPtr *) |
| 18625 | xmlRealloc(vctxt->idcKeys, vctxt->sizeIdcKeys * |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18626 | sizeof(xmlSchemaPSVIIDCKeyPtr)); |
| 18627 | if (vctxt->idcKeys == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18628 | xmlSchemaVErrMemory(vctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18629 | "re-allocating the IDC key storage list", NULL); |
| 18630 | return (-1); |
| 18631 | } |
| 18632 | } |
| 18633 | vctxt->idcKeys[vctxt->nbIdcKeys++] = key; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18634 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18635 | return (0); |
| 18636 | } |
| 18637 | |
| 18638 | /** |
| 18639 | * xmlSchemaIDCAppendNodeTableItem: |
| 18640 | * @bind: the IDC binding |
| 18641 | * @ntItem: the node-table item |
| 18642 | * |
| 18643 | * Appends the IDC node-table item to the binding. |
| 18644 | * |
| 18645 | * Returns 0 on success and -1 on internal errors. |
| 18646 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18647 | static int |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18648 | xmlSchemaIDCAppendNodeTableItem(xmlSchemaPSVIIDCBindingPtr bind, |
| 18649 | xmlSchemaPSVIIDCNodePtr ntItem) |
| 18650 | { |
| 18651 | if (bind->nodeTable == NULL) { |
| 18652 | bind->sizeNodes = 10; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18653 | bind->nodeTable = (xmlSchemaPSVIIDCNodePtr *) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18654 | xmlMalloc(10 * sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 18655 | if (bind->nodeTable == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18656 | xmlSchemaVErrMemory(NULL, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18657 | "allocating an array of IDC node-table items", NULL); |
| 18658 | return(-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18659 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18660 | } else if (bind->sizeNodes <= bind->nbNodes) { |
| 18661 | bind->sizeNodes *= 2; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18662 | bind->nodeTable = (xmlSchemaPSVIIDCNodePtr *) |
| 18663 | xmlRealloc(bind->nodeTable, bind->sizeNodes * |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18664 | sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 18665 | if (bind->nodeTable == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18666 | xmlSchemaVErrMemory(NULL, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18667 | "re-allocating an array of IDC node-table items", NULL); |
| 18668 | return(-1); |
| 18669 | } |
| 18670 | } |
| 18671 | bind->nodeTable[bind->nbNodes++] = ntItem; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18672 | return(0); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18673 | } |
| 18674 | |
| 18675 | /** |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18676 | * xmlSchemaIDCAquireBinding: |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18677 | * @vctxt: the WXS validation context |
| 18678 | * @matcher: the IDC matcher |
| 18679 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18680 | * Looks up an PSVI IDC binding, for the IDC definition and |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18681 | * of the given matcher. If none found, a new one is created |
| 18682 | * and added to the IDC table. |
| 18683 | * |
| 18684 | * Returns an IDC binding or NULL on internal errors. |
| 18685 | */ |
| 18686 | static xmlSchemaPSVIIDCBindingPtr |
| 18687 | xmlSchemaIDCAquireBinding(xmlSchemaValidCtxtPtr vctxt, |
| 18688 | xmlSchemaIDCMatcherPtr matcher) |
| 18689 | { |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 18690 | xmlSchemaNodeInfoPtr info; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18691 | |
| 18692 | info = vctxt->elemInfos[matcher->depth]; |
| 18693 | |
| 18694 | if (info->idcTable == NULL) { |
| 18695 | info->idcTable = xmlSchemaIDCNewBinding(matcher->aidc->def); |
| 18696 | if (info->idcTable == NULL) |
| 18697 | return (NULL); |
| 18698 | return(info->idcTable); |
| 18699 | } else { |
| 18700 | xmlSchemaPSVIIDCBindingPtr bind = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18701 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18702 | bind = info->idcTable; |
| 18703 | do { |
| 18704 | if (bind->definition == matcher->aidc->def) |
| 18705 | return(bind); |
| 18706 | if (bind->next == NULL) { |
| 18707 | bind->next = xmlSchemaIDCNewBinding(matcher->aidc->def); |
| 18708 | if (bind->next == NULL) |
| 18709 | return (NULL); |
| 18710 | return(bind->next); |
| 18711 | } |
| 18712 | bind = bind->next; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18713 | } while (bind != NULL); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18714 | } |
| 18715 | return (NULL); |
| 18716 | } |
| 18717 | |
| 18718 | /** |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18719 | * xmlSchemaIDCFreeKey: |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18720 | * @key: the IDC key |
| 18721 | * |
| 18722 | * Frees an IDC key together with its compiled value. |
| 18723 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18724 | static void |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18725 | xmlSchemaIDCFreeKey(xmlSchemaPSVIIDCKeyPtr key) |
| 18726 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18727 | if (key->val != NULL) |
| 18728 | xmlSchemaFreeValue(key->val); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18729 | xmlFree(key); |
| 18730 | } |
| 18731 | |
| 18732 | /** |
| 18733 | * xmlSchemaIDCFreeBinding: |
| 18734 | * |
| 18735 | * Frees an IDC binding. Note that the node table-items |
| 18736 | * are not freed. |
| 18737 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18738 | static void |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18739 | xmlSchemaIDCFreeBinding(xmlSchemaPSVIIDCBindingPtr bind) |
| 18740 | { |
| 18741 | if (bind->nodeTable != NULL) { |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18742 | if (bind->definition->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 18743 | int i; |
| 18744 | /* |
| 18745 | * Node-table items for keyrefs are not stored globally |
| 18746 | * to the validation context, since they are not bubbled. |
| 18747 | * We need to free them here. |
| 18748 | */ |
| 18749 | for (i = 0; i < bind->nbNodes; i++) { |
| 18750 | xmlFree(bind->nodeTable[i]->keys); |
| 18751 | xmlFree(bind->nodeTable[i]); |
| 18752 | } |
| 18753 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18754 | xmlFree(bind->nodeTable); |
| 18755 | } |
| 18756 | xmlFree(bind); |
| 18757 | } |
| 18758 | |
| 18759 | /** |
| 18760 | * xmlSchemaIDCFreeIDCTable: |
| 18761 | * @bind: the first IDC binding in the list |
| 18762 | * |
| 18763 | * Frees an IDC table, i.e. all the IDC bindings in the list. |
| 18764 | */ |
| 18765 | static void |
| 18766 | xmlSchemaIDCFreeIDCTable(xmlSchemaPSVIIDCBindingPtr bind) |
| 18767 | { |
| 18768 | xmlSchemaPSVIIDCBindingPtr prev; |
| 18769 | |
| 18770 | while (bind != NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18771 | prev = bind; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18772 | bind = bind->next; |
| 18773 | xmlSchemaIDCFreeBinding(prev); |
| 18774 | } |
| 18775 | } |
| 18776 | |
| 18777 | /** |
| 18778 | * xmlSchemaIDCFreeMatcherList: |
| 18779 | * @matcher: the first IDC matcher in the list |
| 18780 | * |
| 18781 | * Frees a list of IDC matchers. |
| 18782 | */ |
| 18783 | static void |
| 18784 | xmlSchemaIDCFreeMatcherList(xmlSchemaIDCMatcherPtr matcher) |
| 18785 | { |
| 18786 | xmlSchemaIDCMatcherPtr next; |
| 18787 | |
| 18788 | while (matcher != NULL) { |
| 18789 | next = matcher->next; |
| 18790 | if (matcher->keySeqs != NULL) { |
| 18791 | int i; |
| 18792 | for (i = 0; i < matcher->sizeKeySeqs; i++) |
| 18793 | if (matcher->keySeqs[i] != NULL) |
| 18794 | xmlFree(matcher->keySeqs[i]); |
| 18795 | xmlFree(matcher->keySeqs); |
| 18796 | } |
| 18797 | xmlFree(matcher); |
| 18798 | matcher = next; |
| 18799 | } |
| 18800 | } |
| 18801 | |
| 18802 | /** |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18803 | * xmlSchemaIDCAddStateObject: |
| 18804 | * @vctxt: the WXS validation context |
| 18805 | * @matcher: the IDC matcher |
| 18806 | * @sel: the XPath information |
| 18807 | * @parent: the parent "selector" state object if any |
| 18808 | * @type: "selector" or "field" |
| 18809 | * |
| 18810 | * Creates/reuses and activates state objects for the given |
| 18811 | * XPath information; if the XPath expression consists of unions, |
| 18812 | * multiple state objects are created for every unioned expression. |
| 18813 | * |
| 18814 | * Returns 0 on success and -1 on internal errors. |
| 18815 | */ |
| 18816 | static int |
| 18817 | xmlSchemaIDCAddStateObject(xmlSchemaValidCtxtPtr vctxt, |
| 18818 | xmlSchemaIDCMatcherPtr matcher, |
| 18819 | xmlSchemaIDCSelectPtr sel, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18820 | int type) |
| 18821 | { |
| 18822 | xmlSchemaIDCStateObjPtr sto; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18823 | |
| 18824 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18825 | * Reuse the state objects from the pool. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18826 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18827 | if (vctxt->xpathStatePool != NULL) { |
| 18828 | sto = vctxt->xpathStatePool; |
| 18829 | vctxt->xpathStatePool = sto->next; |
| 18830 | sto->next = NULL; |
| 18831 | } else { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18832 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18833 | * Create a new state object. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18834 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18835 | sto = (xmlSchemaIDCStateObjPtr) xmlMalloc(sizeof(xmlSchemaIDCStateObj)); |
| 18836 | if (sto == NULL) { |
| 18837 | xmlSchemaVErrMemory(NULL, |
| 18838 | "allocating an IDC state object", NULL); |
| 18839 | return (-1); |
| 18840 | } |
| 18841 | memset(sto, 0, sizeof(xmlSchemaIDCStateObj)); |
| 18842 | } |
| 18843 | /* |
| 18844 | * Add to global list. |
| 18845 | */ |
| 18846 | if (vctxt->xpathStates != NULL) |
| 18847 | sto->next = vctxt->xpathStates; |
| 18848 | vctxt->xpathStates = sto; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18849 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18850 | /* |
| 18851 | * Free the old xpath validation context. |
| 18852 | */ |
| 18853 | if (sto->xpathCtxt != NULL) |
| 18854 | xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt); |
| 18855 | |
| 18856 | /* |
| 18857 | * Create a new XPath (pattern) validation context. |
| 18858 | */ |
| 18859 | sto->xpathCtxt = (void *) xmlPatternGetStreamCtxt( |
| 18860 | (xmlPatternPtr) sel->xpathComp); |
| 18861 | if (sto->xpathCtxt == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18862 | VERROR_INT("xmlSchemaIDCAddStateObject", |
| 18863 | "failed to create an XPath validation context"); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18864 | return (-1); |
| 18865 | } |
| 18866 | sto->type = type; |
| 18867 | sto->depth = vctxt->depth; |
| 18868 | sto->matcher = matcher; |
| 18869 | sto->sel = sel; |
| 18870 | sto->nbHistory = 0; |
| 18871 | |
| 18872 | #if DEBUG_IDC |
| 18873 | xmlGenericError(xmlGenericErrorContext, "IDC: STO push '%s'\n", |
| 18874 | sto->sel->xpath); |
| 18875 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18876 | return (0); |
| 18877 | } |
| 18878 | |
| 18879 | /** |
| 18880 | * xmlSchemaXPathEvaluate: |
| 18881 | * @vctxt: the WXS validation context |
| 18882 | * @nodeType: the nodeType of the current node |
| 18883 | * |
| 18884 | * Evaluates all active XPath state objects. |
| 18885 | * |
| 18886 | * Returns the number of IC "field" state objects which resolved to |
| 18887 | * this node, 0 if none resolved and -1 on internal errors. |
| 18888 | */ |
| 18889 | static int |
| 18890 | xmlSchemaXPathEvaluate(xmlSchemaValidCtxtPtr vctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18891 | xmlElementType nodeType) |
| 18892 | { |
| 18893 | xmlSchemaIDCStateObjPtr sto, head = NULL, first; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18894 | int res, resolved = 0, depth = vctxt->depth; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18895 | |
| 18896 | if (vctxt->xpathStates == NULL) |
| 18897 | return (0); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18898 | |
| 18899 | if (nodeType == XML_ATTRIBUTE_NODE) |
| 18900 | depth++; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18901 | #if DEBUG_IDC |
| 18902 | { |
| 18903 | xmlChar *str = NULL; |
| 18904 | xmlGenericError(xmlGenericErrorContext, |
| 18905 | "IDC: EVAL on %s, depth %d, type %d\n", |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18906 | xmlSchemaFormatQName(&str, vctxt->inode->nsName, |
| 18907 | vctxt->inode->localName), depth, nodeType); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18908 | FREE_AND_NULL(str) |
| 18909 | } |
| 18910 | #endif |
| 18911 | /* |
| 18912 | * Process all active XPath state objects. |
| 18913 | */ |
| 18914 | first = vctxt->xpathStates; |
| 18915 | sto = first; |
| 18916 | while (sto != head) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18917 | #if DEBUG_IDC |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18918 | if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18919 | xmlGenericError(xmlGenericErrorContext, "IDC: ['%s'] selector '%s'\n", |
| 18920 | sto->matcher->aidc->def->name, sto->sel->xpath); |
| 18921 | else |
| 18922 | xmlGenericError(xmlGenericErrorContext, "IDC: ['%s'] field '%s'\n", |
| 18923 | sto->matcher->aidc->def->name, sto->sel->xpath); |
| 18924 | #endif |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18925 | if (nodeType == XML_ELEMENT_NODE) |
| 18926 | res = xmlStreamPush((xmlStreamCtxtPtr) sto->xpathCtxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18927 | vctxt->inode->localName, vctxt->inode->nsName); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18928 | else |
| 18929 | res = xmlStreamPushAttr((xmlStreamCtxtPtr) sto->xpathCtxt, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18930 | vctxt->inode->localName, vctxt->inode->nsName); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18931 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18932 | if (res == -1) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 18933 | VERROR_INT("xmlSchemaXPathEvaluate", |
| 18934 | "calling xmlStreamPush()"); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18935 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18936 | } |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18937 | if (res == 0) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18938 | goto next_sto; |
| 18939 | /* |
| 18940 | * Full match. |
| 18941 | */ |
| 18942 | #if DEBUG_IDC |
| 18943 | xmlGenericError(xmlGenericErrorContext, "IDC: " |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18944 | "MATCH\n"); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18945 | #endif |
| 18946 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18947 | * Register a match in the state object history. |
| 18948 | */ |
| 18949 | if (sto->history == NULL) { |
| 18950 | sto->history = (int *) xmlMalloc(5 * sizeof(int)); |
| 18951 | if (sto->history == NULL) { |
| 18952 | xmlSchemaVErrMemory(NULL, |
| 18953 | "allocating the state object history", NULL); |
| 18954 | return(-1); |
| 18955 | } |
| 18956 | sto->sizeHistory = 10; |
| 18957 | } else if (sto->sizeHistory <= sto->nbHistory) { |
| 18958 | sto->sizeHistory *= 2; |
| 18959 | sto->history = (int *) xmlRealloc(sto->history, |
| 18960 | sto->sizeHistory * sizeof(int)); |
| 18961 | if (sto->history == NULL) { |
| 18962 | xmlSchemaVErrMemory(NULL, |
| 18963 | "re-allocating the state object history", NULL); |
| 18964 | return(-1); |
| 18965 | } |
| 18966 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18967 | sto->history[sto->nbHistory++] = depth; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18968 | |
| 18969 | #ifdef DEBUG_IDC |
| 18970 | xmlGenericError(xmlGenericErrorContext, "IDC: push match '%d'\n", |
| 18971 | vctxt->depth); |
| 18972 | #endif |
| 18973 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18974 | if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) { |
| 18975 | xmlSchemaIDCSelectPtr sel; |
| 18976 | /* |
| 18977 | * Activate state objects for the IDC fields of |
| 18978 | * the IDC selector. |
| 18979 | */ |
| 18980 | #if DEBUG_IDC |
| 18981 | xmlGenericError(xmlGenericErrorContext, "IDC: " |
| 18982 | "activating field states\n"); |
| 18983 | #endif |
| 18984 | sel = sto->matcher->aidc->def->fields; |
| 18985 | while (sel != NULL) { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18986 | if (xmlSchemaIDCAddStateObject(vctxt, sto->matcher, |
| 18987 | sel, XPATH_STATE_OBJ_TYPE_IDC_FIELD) == -1) |
| 18988 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18989 | sel = sel->next; |
| 18990 | } |
| 18991 | } else if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_FIELD) { |
| 18992 | /* |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 18993 | * An IDC key node was found by the IDC field. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18994 | */ |
| 18995 | #if DEBUG_IDC |
| 18996 | xmlGenericError(xmlGenericErrorContext, |
| 18997 | "IDC: key found\n"); |
| 18998 | #endif |
| 18999 | /* |
| 19000 | * Notify that the character value of this node is |
| 19001 | * needed. |
| 19002 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19003 | if (resolved == 0) { |
| 19004 | if ((vctxt->inode->flags & |
| 19005 | XML_SCHEMA_NODE_INFO_VALUE_NEEDED) == 0) |
| 19006 | vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_VALUE_NEEDED; |
| 19007 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19008 | resolved++; |
| 19009 | } |
| 19010 | next_sto: |
| 19011 | if (sto->next == NULL) { |
| 19012 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19013 | * Evaluate field state objects created on this node as well. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19014 | */ |
| 19015 | head = first; |
| 19016 | sto = vctxt->xpathStates; |
| 19017 | } else |
| 19018 | sto = sto->next; |
| 19019 | } |
| 19020 | return (resolved); |
| 19021 | } |
| 19022 | |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 19023 | static const xmlChar * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19024 | xmlSchemaFormatIDCKeySequence(xmlSchemaValidCtxtPtr vctxt, |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 19025 | xmlChar **buf, |
| 19026 | xmlSchemaPSVIIDCKeyPtr *seq, |
| 19027 | int count) |
| 19028 | { |
| 19029 | int i, res; |
| 19030 | const xmlChar *value = NULL; |
| 19031 | |
| 19032 | *buf = xmlStrdup(BAD_CAST "["); |
| 19033 | for (i = 0; i < count; i++) { |
| 19034 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19035 | res = xmlSchemaGetCanonValueWhtsp(seq[i]->val, &value, |
| 19036 | xmlSchemaGetWhiteSpaceFacetValue(seq[i]->type)); |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 19037 | if (res == 0) |
| 19038 | *buf = xmlStrcat(*buf, value); |
| 19039 | else { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19040 | VERROR_INT("xmlSchemaFormatIDCKeySequence", |
| 19041 | "failed to compute a canonical value"); |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 19042 | *buf = xmlStrcat(*buf, BAD_CAST "???"); |
| 19043 | } |
| 19044 | if (i < count -1) |
| 19045 | *buf = xmlStrcat(*buf, BAD_CAST "', "); |
| 19046 | else |
| 19047 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 19048 | if (value != NULL) { |
| 19049 | xmlFree((xmlChar *) value); |
| 19050 | value = NULL; |
| 19051 | } |
| 19052 | } |
| 19053 | *buf = xmlStrcat(*buf, BAD_CAST "]"); |
| 19054 | |
| 19055 | return (BAD_CAST *buf); |
| 19056 | } |
| 19057 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19058 | /** |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19059 | * xmlSchemaXPathProcessHistory: |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19060 | * @vctxt: the WXS validation context |
| 19061 | * @type: the simple/complex type of the current node if any at all |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19062 | * @val: the precompiled value |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19063 | * |
| 19064 | * Processes and pops the history items of the IDC state objects. |
| 19065 | * IDC key-sequences are validated/created on IDC bindings. |
| 19066 | * |
| 19067 | * Returns 0 on success and -1 on internal errors. |
| 19068 | */ |
| 19069 | static int |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19070 | xmlSchemaXPathProcessHistory(xmlSchemaValidCtxtPtr vctxt, |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19071 | int depth) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19072 | { |
| 19073 | xmlSchemaIDCStateObjPtr sto, nextsto; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19074 | int res, matchDepth; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19075 | xmlSchemaPSVIIDCKeyPtr key = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19076 | xmlSchemaTypePtr type = vctxt->inode->typeDef; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19077 | |
| 19078 | if (vctxt->xpathStates == NULL) |
| 19079 | return (0); |
| 19080 | sto = vctxt->xpathStates; |
| 19081 | |
| 19082 | #if DEBUG_IDC |
| 19083 | { |
| 19084 | xmlChar *str = NULL; |
| 19085 | xmlGenericError(xmlGenericErrorContext, |
| 19086 | "IDC: BACK on %s, depth %d\n", |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19087 | xmlSchemaFormatQName(&str, vctxt->inode->nsName, |
| 19088 | vctxt->inode->localName), vctxt->depth); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19089 | FREE_AND_NULL(str) |
| 19090 | } |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19091 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19092 | /* |
| 19093 | * Evaluate the state objects. |
| 19094 | */ |
| 19095 | while (sto != NULL) { |
Kasimier T. Buchcik | c63fbbf | 2005-06-15 12:54:05 +0000 | [diff] [blame] | 19096 | res = xmlStreamPop((xmlStreamCtxtPtr) sto->xpathCtxt); |
| 19097 | if (res == -1) { |
| 19098 | VERROR_INT("xmlSchemaXPathProcessHistory", |
| 19099 | "calling xmlStreamPop()"); |
| 19100 | return (-1); |
| 19101 | } |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 19102 | #if DEBUG_IDC |
| 19103 | xmlGenericError(xmlGenericErrorContext, "IDC: stream pop '%s'\n", |
| 19104 | sto->sel->xpath); |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19105 | #endif |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19106 | if (sto->nbHistory == 0) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19107 | goto deregister_check; |
| 19108 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19109 | matchDepth = sto->history[sto->nbHistory -1]; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19110 | |
| 19111 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19112 | * Only matches at the current depth are of interest. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19113 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19114 | if (matchDepth != depth) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19115 | sto = sto->next; |
| 19116 | continue; |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 19117 | } |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19118 | if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_FIELD) { |
| 19119 | if (! IS_SIMPLE_TYPE(type)) { |
| 19120 | /* |
| 19121 | * Not qualified if the field resolves to a node of non |
| 19122 | * simple type. |
| 19123 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19124 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 19125 | XML_SCHEMAV_CVC_IDC, NULL, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19126 | (xmlSchemaTypePtr) sto->matcher->aidc->def, |
| 19127 | "The field '%s' does evaluate to a node of " |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 19128 | "non-simple type", sto->sel->xpath, NULL); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19129 | |
| 19130 | sto->nbHistory--; |
| 19131 | goto deregister_check; |
| 19132 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19133 | if ((key == NULL) && (vctxt->inode->val == NULL)) { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19134 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19135 | * Failed to provide the normalized value; maybe |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19136 | * the value was invalid. |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 19137 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19138 | VERROR(XML_SCHEMAV_CVC_IDC, |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 19139 | (xmlSchemaTypePtr) sto->matcher->aidc->def, |
| 19140 | "Warning: No precomputed value available, the value " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19141 | "was either invalid or something strange happend"); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19142 | sto->nbHistory--; |
| 19143 | goto deregister_check; |
| 19144 | } else { |
| 19145 | xmlSchemaIDCMatcherPtr matcher = sto->matcher; |
| 19146 | xmlSchemaPSVIIDCKeyPtr *keySeq; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19147 | int pos, idx; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19148 | |
| 19149 | /* |
| 19150 | * The key will be anchored on the matcher's list of |
| 19151 | * key-sequences. The position in this list is determined |
| 19152 | * by the target node's depth relative to the matcher's |
| 19153 | * depth of creation (i.e. the depth of the scope element). |
| 19154 | */ |
| 19155 | pos = sto->depth - matcher->depth; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19156 | idx = sto->sel->index; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19157 | |
| 19158 | /* |
| 19159 | * Create/grow the array of key-sequences. |
| 19160 | */ |
| 19161 | if (matcher->keySeqs == NULL) { |
| 19162 | if (pos > 9) |
| 19163 | matcher->sizeKeySeqs = pos * 2; |
| 19164 | else |
| 19165 | matcher->sizeKeySeqs = 10; |
| 19166 | matcher->keySeqs = (xmlSchemaPSVIIDCKeyPtr **) |
| 19167 | xmlMalloc(matcher->sizeKeySeqs * |
| 19168 | sizeof(xmlSchemaPSVIIDCKeyPtr *)); |
| 19169 | if (matcher->keySeqs == NULL) { |
| 19170 | xmlSchemaVErrMemory(NULL, |
| 19171 | "allocating an array of key-sequences", |
| 19172 | NULL); |
| 19173 | return(-1); |
| 19174 | } |
| 19175 | memset(matcher->keySeqs, 0, |
| 19176 | matcher->sizeKeySeqs * |
| 19177 | sizeof(xmlSchemaPSVIIDCKeyPtr *)); |
| 19178 | } else if (pos >= matcher->sizeKeySeqs) { |
| 19179 | int i = matcher->sizeKeySeqs; |
| 19180 | |
| 19181 | matcher->sizeKeySeqs *= 2; |
| 19182 | matcher->keySeqs = (xmlSchemaPSVIIDCKeyPtr **) |
| 19183 | xmlRealloc(matcher->keySeqs, |
| 19184 | matcher->sizeKeySeqs * |
| 19185 | sizeof(xmlSchemaPSVIIDCKeyPtr *)); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19186 | if (matcher->keySeqs == NULL) { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19187 | xmlSchemaVErrMemory(NULL, |
| 19188 | "reallocating an array of key-sequences", |
| 19189 | NULL); |
| 19190 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19191 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19192 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19193 | * The array needs to be NULLed. |
| 19194 | * TODO: Use memset? |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19195 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19196 | for (; i < matcher->sizeKeySeqs; i++) |
| 19197 | matcher->keySeqs[i] = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19198 | } |
| 19199 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19200 | /* |
| 19201 | * Get/create the key-sequence. |
| 19202 | */ |
| 19203 | keySeq = matcher->keySeqs[pos]; |
| 19204 | if (keySeq == NULL) { |
| 19205 | goto create_sequence; |
| 19206 | } else { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19207 | if (keySeq[idx] != NULL) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19208 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19209 | * cvc-identity-constraint: |
| 19210 | * 3 For each node in the ·target node set· all |
| 19211 | * of the {fields}, with that node as the context |
| 19212 | * node, evaluate to either an empty node-set or |
| 19213 | * a node-set with exactly one member, which must |
| 19214 | * have a simple type. |
| 19215 | * |
| 19216 | * The key was already set; report an error. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19217 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19218 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 19219 | XML_SCHEMAV_CVC_IDC, NULL, |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 19220 | (xmlSchemaTypePtr) matcher->aidc->def, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19221 | "The field '%s' evaluates to a node-set " |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 19222 | "with more than one member", |
| 19223 | sto->sel->xpath, NULL); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19224 | sto->nbHistory--; |
| 19225 | goto deregister_check; |
| 19226 | } else { |
| 19227 | goto create_key; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19228 | } |
| 19229 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19230 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19231 | create_sequence: |
| 19232 | /* |
| 19233 | * Create a key-sequence. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19234 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19235 | keySeq = (xmlSchemaPSVIIDCKeyPtr *) xmlMalloc( |
| 19236 | matcher->aidc->def->nbFields * |
| 19237 | sizeof(xmlSchemaPSVIIDCKeyPtr)); |
| 19238 | if (keySeq == NULL) { |
| 19239 | xmlSchemaVErrMemory(NULL, |
| 19240 | "allocating an IDC key-sequence", NULL); |
| 19241 | return(-1); |
| 19242 | } |
| 19243 | memset(keySeq, 0, matcher->aidc->def->nbFields * |
| 19244 | sizeof(xmlSchemaPSVIIDCKeyPtr)); |
| 19245 | matcher->keySeqs[pos] = keySeq; |
| 19246 | create_key: |
| 19247 | /* |
| 19248 | * Created a key once per node only. |
| 19249 | */ |
| 19250 | if (key == NULL) { |
| 19251 | key = (xmlSchemaPSVIIDCKeyPtr) xmlMalloc( |
| 19252 | sizeof(xmlSchemaPSVIIDCKey)); |
| 19253 | if (key == NULL) { |
| 19254 | xmlSchemaVErrMemory(NULL, |
| 19255 | "allocating a IDC key", NULL); |
| 19256 | xmlFree(keySeq); |
| 19257 | matcher->keySeqs[pos] = NULL; |
| 19258 | return(-1); |
| 19259 | } |
| 19260 | /* |
| 19261 | * Consume the compiled value. |
| 19262 | */ |
| 19263 | key->type = type; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19264 | key->val = vctxt->inode->val; |
| 19265 | vctxt->inode->val = NULL; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19266 | /* |
| 19267 | * Store the key in a global list. |
| 19268 | */ |
| 19269 | if (xmlSchemaIDCStoreKey(vctxt, key) == -1) { |
| 19270 | xmlSchemaIDCFreeKey(key); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19271 | return (-1); |
| 19272 | } |
| 19273 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19274 | keySeq[idx] = key; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19275 | } |
| 19276 | } else if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19277 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19278 | xmlSchemaPSVIIDCKeyPtr **keySeq = NULL; |
| 19279 | xmlSchemaPSVIIDCBindingPtr bind; |
| 19280 | xmlSchemaPSVIIDCNodePtr ntItem; |
| 19281 | xmlSchemaIDCMatcherPtr matcher; |
| 19282 | xmlSchemaIDCPtr idc; |
| 19283 | int pos, i, j, nbKeys; |
| 19284 | /* |
| 19285 | * Here we have the following scenario: |
| 19286 | * An IDC 'selector' state object resolved to a target node, |
| 19287 | * during the time this target node was in the |
| 19288 | * ancestor-or-self axis, the 'field' state object(s) looked |
| 19289 | * out for matching nodes to create a key-sequence for this |
| 19290 | * target node. Now we are back to this target node and need |
| 19291 | * to put the key-sequence, together with the target node |
| 19292 | * itself, into the node-table of the corresponding IDC |
| 19293 | * binding. |
| 19294 | */ |
| 19295 | matcher = sto->matcher; |
| 19296 | idc = matcher->aidc->def; |
| 19297 | nbKeys = idc->nbFields; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19298 | pos = depth - matcher->depth; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19299 | /* |
| 19300 | * Check if the matcher has any key-sequences at all, plus |
| 19301 | * if it has a key-sequence for the current target node. |
| 19302 | */ |
| 19303 | if ((matcher->keySeqs == NULL) || |
| 19304 | (matcher->sizeKeySeqs <= pos)) { |
| 19305 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEY) |
| 19306 | goto selector_key_error; |
| 19307 | else |
| 19308 | goto selector_leave; |
| 19309 | } |
| 19310 | |
| 19311 | keySeq = &(matcher->keySeqs[pos]); |
| 19312 | if (*keySeq == NULL) { |
| 19313 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEY) |
| 19314 | goto selector_key_error; |
| 19315 | else |
| 19316 | goto selector_leave; |
| 19317 | } |
| 19318 | |
| 19319 | for (i = 0; i < nbKeys; i++) { |
| 19320 | if ((*keySeq)[i] == NULL) { |
| 19321 | /* |
| 19322 | * Not qualified, if not all fields did resolve. |
| 19323 | */ |
| 19324 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEY) { |
| 19325 | /* |
| 19326 | * All fields of a "key" IDC must resolve. |
| 19327 | */ |
| 19328 | goto selector_key_error; |
| 19329 | } |
| 19330 | goto selector_leave; |
| 19331 | } |
| 19332 | } |
| 19333 | /* |
| 19334 | * All fields did resolve. |
| 19335 | */ |
| 19336 | |
| 19337 | /* |
| 19338 | * 4.1 If the {identity-constraint category} is unique(/key), |
| 19339 | * then no two members of the ·qualified node set· have |
| 19340 | * ·key-sequences· whose members are pairwise equal, as |
| 19341 | * defined by Equal in [XML Schemas: Datatypes]. |
| 19342 | * |
| 19343 | * Get the IDC binding from the matcher and check for |
| 19344 | * duplicate key-sequences. |
| 19345 | */ |
| 19346 | bind = xmlSchemaIDCAquireBinding(vctxt, matcher); |
| 19347 | if ((idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) && |
| 19348 | (bind->nbNodes != 0)) { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19349 | xmlSchemaPSVIIDCKeyPtr ckey, bkey, *bkeySeq; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19350 | |
| 19351 | i = 0; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19352 | res = 0; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19353 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19354 | * Compare the key-sequences, key by key. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19355 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19356 | do { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19357 | bkeySeq = bind->nodeTable[i]->keys; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19358 | for (j = 0; j < nbKeys; j++) { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19359 | ckey = (*keySeq)[j]; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19360 | bkey = bkeySeq[j]; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19361 | res = xmlSchemaAreValuesEqual(ckey->val, bkey->val); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19362 | if (res == -1) { |
| 19363 | return (-1); |
| 19364 | } else if (res == 0) |
| 19365 | break; |
| 19366 | } |
| 19367 | if (res == 1) { |
| 19368 | /* |
| 19369 | * Duplicate found. |
| 19370 | */ |
| 19371 | break; |
| 19372 | } |
| 19373 | i++; |
| 19374 | } while (i < bind->nbNodes); |
| 19375 | if (i != bind->nbNodes) { |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 19376 | xmlChar *str = NULL; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19377 | /* |
| 19378 | * TODO: Try to report the key-sequence. |
| 19379 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19380 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 19381 | XML_SCHEMAV_CVC_IDC, NULL, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19382 | (xmlSchemaTypePtr) idc, |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 19383 | "Duplicate key-sequence %s", |
| 19384 | xmlSchemaFormatIDCKeySequence(vctxt, &str, |
| 19385 | (*keySeq), nbKeys), NULL); |
| 19386 | FREE_AND_NULL(str) |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19387 | goto selector_leave; |
| 19388 | } |
| 19389 | } |
| 19390 | /* |
| 19391 | * Add a node-table item to the IDC binding. |
| 19392 | */ |
| 19393 | ntItem = (xmlSchemaPSVIIDCNodePtr) xmlMalloc( |
| 19394 | sizeof(xmlSchemaPSVIIDCNode)); |
| 19395 | if (ntItem == NULL) { |
| 19396 | xmlSchemaVErrMemory(NULL, |
| 19397 | "allocating an IDC node-table item", NULL); |
| 19398 | xmlFree(*keySeq); |
| 19399 | *keySeq = NULL; |
| 19400 | return(-1); |
| 19401 | } |
| 19402 | memset(ntItem, 0, sizeof(xmlSchemaPSVIIDCNode)); |
| 19403 | |
| 19404 | /* |
| 19405 | * Store the node-table item on global list. |
| 19406 | */ |
| 19407 | if (idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 19408 | if (xmlSchemaIDCStoreNodeTableItem(vctxt, ntItem) == -1) { |
| 19409 | xmlFree(ntItem); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19410 | xmlFree(*keySeq); |
| 19411 | *keySeq = NULL; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19412 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19413 | } |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19414 | } |
| 19415 | /* |
| 19416 | * Init the node-table item. Consume the key-sequence. |
| 19417 | */ |
| 19418 | ntItem->node = vctxt->node; |
| 19419 | ntItem->keys = *keySeq; |
| 19420 | *keySeq = NULL; |
| 19421 | if (xmlSchemaIDCAppendNodeTableItem(bind, ntItem) == -1) { |
| 19422 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 19423 | /* |
| 19424 | * Free the item, since keyref items won't be |
| 19425 | * put on a global list. |
| 19426 | */ |
| 19427 | xmlFree(ntItem->keys); |
| 19428 | xmlFree(ntItem); |
| 19429 | } |
| 19430 | return (-1); |
| 19431 | } |
| 19432 | |
| 19433 | goto selector_leave; |
| 19434 | selector_key_error: |
| 19435 | /* |
| 19436 | * 4.2.1 (KEY) The ·target node set· and the |
| 19437 | * ·qualified node set· are equal, that is, every |
| 19438 | * member of the ·target node set· is also a member |
| 19439 | * of the ·qualified node set· and vice versa. |
| 19440 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19441 | VERROR(XML_SCHEMAV_CVC_IDC, (xmlSchemaTypePtr) idc, |
| 19442 | "All 'key' fields must evaluate to a node"); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19443 | selector_leave: |
| 19444 | /* |
| 19445 | * Free the key-sequence if not added to the IDC table. |
| 19446 | */ |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19447 | if ((keySeq != NULL) && (*keySeq != NULL)) { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19448 | xmlFree(*keySeq); |
| 19449 | *keySeq = NULL; |
| 19450 | } |
| 19451 | } /* if selector */ |
| 19452 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19453 | sto->nbHistory--; |
| 19454 | |
| 19455 | deregister_check: |
| 19456 | /* |
| 19457 | * Deregister state objects if they reach the depth of creation. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19458 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19459 | if ((sto->nbHistory == 0) && (sto->depth == depth)) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19460 | #if DEBUG_IDC |
| 19461 | xmlGenericError(xmlGenericErrorContext, "IDC: STO pop '%s'\n", |
| 19462 | sto->sel->xpath); |
| 19463 | #endif |
| 19464 | if (vctxt->xpathStates != sto) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19465 | VERROR_INT("xmlSchemaXPathProcessHistory", |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19466 | "The state object to be removed is not the first " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19467 | "in the list"); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19468 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19469 | nextsto = sto->next; |
| 19470 | /* |
| 19471 | * Unlink from the list of active XPath state objects. |
| 19472 | */ |
| 19473 | vctxt->xpathStates = sto->next; |
| 19474 | sto->next = vctxt->xpathStatePool; |
| 19475 | /* |
| 19476 | * Link it to the pool of reusable state objects. |
| 19477 | */ |
| 19478 | vctxt->xpathStatePool = sto; |
| 19479 | sto = nextsto; |
| 19480 | } else |
| 19481 | sto = sto->next; |
| 19482 | } /* while (sto != NULL) */ |
| 19483 | return (0); |
| 19484 | } |
| 19485 | |
| 19486 | /** |
| 19487 | * xmlSchemaIDCRegisterMatchers: |
| 19488 | * @vctxt: the WXS validation context |
| 19489 | * @elemDecl: the element declaration |
| 19490 | * |
| 19491 | * Creates helper objects to evaluate IDC selectors/fields |
| 19492 | * successively. |
| 19493 | * |
| 19494 | * Returns 0 if OK and -1 on internal errors. |
| 19495 | */ |
| 19496 | static int |
| 19497 | xmlSchemaIDCRegisterMatchers(xmlSchemaValidCtxtPtr vctxt, |
| 19498 | xmlSchemaElementPtr elemDecl) |
| 19499 | { |
| 19500 | xmlSchemaIDCMatcherPtr matcher, last = NULL; |
| 19501 | xmlSchemaIDCPtr idc, refIdc; |
| 19502 | xmlSchemaIDCAugPtr aidc; |
| 19503 | |
| 19504 | idc = (xmlSchemaIDCPtr) elemDecl->idcs; |
| 19505 | if (idc == NULL) |
| 19506 | return (0); |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19507 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19508 | #if DEBUG_IDC |
| 19509 | { |
| 19510 | xmlChar *str = NULL; |
| 19511 | xmlGenericError(xmlGenericErrorContext, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19512 | "IDC: REGISTER on %s, depth %d\n", |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19513 | (char *) xmlSchemaFormatQName(&str, vctxt->inode->nsName, |
| 19514 | vctxt->inode->localName), vctxt->depth); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19515 | FREE_AND_NULL(str) |
| 19516 | } |
| 19517 | #endif |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19518 | if (vctxt->inode->idcMatchers != NULL) { |
| 19519 | VERROR_INT("xmlSchemaIDCRegisterMatchers", |
| 19520 | "The chain of IDC matchers is expected to be empty"); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19521 | return (-1); |
| 19522 | } |
| 19523 | do { |
| 19524 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 19525 | /* |
| 19526 | * Since IDCs bubbles are expensive we need to know the |
| 19527 | * depth at which the bubbles should stop; this will be |
| 19528 | * the depth of the top-most keyref IDC. If no keyref |
| 19529 | * references a key/unique IDC, the bubbleDepth will |
| 19530 | * be -1, indicating that no bubbles are needed. |
| 19531 | */ |
| 19532 | refIdc = (xmlSchemaIDCPtr) idc->ref->item; |
| 19533 | if (refIdc != NULL) { |
| 19534 | /* |
| 19535 | * Lookup the augmented IDC. |
| 19536 | */ |
| 19537 | aidc = vctxt->aidcs; |
| 19538 | while (aidc != NULL) { |
| 19539 | if (aidc->def == refIdc) |
| 19540 | break; |
| 19541 | aidc = aidc->next; |
| 19542 | } |
| 19543 | if (aidc == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19544 | VERROR_INT("xmlSchemaIDCRegisterMatchers", |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19545 | "Could not find an augmented IDC item for an IDC " |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19546 | "definition"); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19547 | return (-1); |
| 19548 | } |
| 19549 | if ((aidc->bubbleDepth == -1) || |
| 19550 | (vctxt->depth < aidc->bubbleDepth)) |
| 19551 | aidc->bubbleDepth = vctxt->depth; |
| 19552 | } |
| 19553 | } |
| 19554 | /* |
| 19555 | * Lookup the augmented IDC item for the IDC definition. |
| 19556 | */ |
| 19557 | aidc = vctxt->aidcs; |
| 19558 | while (aidc != NULL) { |
| 19559 | if (aidc->def == idc) |
| 19560 | break; |
| 19561 | aidc = aidc->next; |
| 19562 | } |
| 19563 | if (aidc == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19564 | VERROR_INT("xmlSchemaIDCRegisterMatchers", |
| 19565 | "Could not find an augmented IDC item for an IDC definition"); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19566 | return (-1); |
| 19567 | } |
| 19568 | /* |
| 19569 | * Create an IDC matcher for every IDC definition. |
| 19570 | */ |
| 19571 | matcher = (xmlSchemaIDCMatcherPtr) |
| 19572 | xmlMalloc(sizeof(xmlSchemaIDCMatcher)); |
| 19573 | if (matcher == NULL) { |
| 19574 | xmlSchemaVErrMemory(vctxt, |
| 19575 | "allocating an IDC matcher", NULL); |
| 19576 | return (-1); |
| 19577 | } |
| 19578 | memset(matcher, 0, sizeof(xmlSchemaIDCMatcher)); |
| 19579 | if (last == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19580 | vctxt->inode->idcMatchers = matcher; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19581 | else |
| 19582 | last->next = matcher; |
| 19583 | last = matcher; |
| 19584 | |
| 19585 | matcher->type = IDC_MATCHER; |
| 19586 | matcher->depth = vctxt->depth; |
| 19587 | matcher->aidc = aidc; |
| 19588 | #if DEBUG_IDC |
| 19589 | xmlGenericError(xmlGenericErrorContext, "IDC: register matcher\n"); |
| 19590 | #endif |
| 19591 | /* |
| 19592 | * Init the automaton state object. |
| 19593 | */ |
| 19594 | if (xmlSchemaIDCAddStateObject(vctxt, matcher, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19595 | idc->selector, XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) == -1) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19596 | return (-1); |
| 19597 | |
| 19598 | idc = idc->next; |
| 19599 | } while (idc != NULL); |
| 19600 | return (0); |
| 19601 | } |
| 19602 | |
| 19603 | /** |
| 19604 | * xmlSchemaBubbleIDCNodeTables: |
| 19605 | * @depth: the current tree depth |
| 19606 | * |
| 19607 | * Merges IDC bindings of an element at @depth into the corresponding IDC |
| 19608 | * bindings of its parent element. If a duplicate note-table entry is found, |
| 19609 | * both, the parent node-table entry and child entry are discarded from the |
| 19610 | * node-table of the parent. |
| 19611 | * |
| 19612 | * Returns 0 if OK and -1 on internal errors. |
| 19613 | */ |
| 19614 | static int |
| 19615 | xmlSchemaBubbleIDCNodeTables(xmlSchemaValidCtxtPtr vctxt) |
| 19616 | { |
| 19617 | xmlSchemaPSVIIDCBindingPtr bind; /* IDC bindings of the current node. */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19618 | xmlSchemaPSVIIDCBindingPtr *parTable, parBind = NULL, lastParBind = NULL; /* parent IDC bindings. */ |
| 19619 | xmlSchemaPSVIIDCNodePtr node, parNode = NULL; /* node-table entries. */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19620 | xmlSchemaPSVIIDCKeyPtr key, parKey; /* keys of in a key-sequence. */ |
| 19621 | xmlSchemaIDCAugPtr aidc; |
Kasimier T. Buchcik | b34ad1b | 2005-03-21 20:10:31 +0000 | [diff] [blame] | 19622 | int i, j, k, ret = 0, oldNum, newDupls; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19623 | int duplTop; |
| 19624 | |
| 19625 | /* |
| 19626 | * The node table has the following sections: |
| 19627 | * |
| 19628 | * O --> old node-table entries (first) |
| 19629 | * O |
| 19630 | * + --> new node-table entries |
| 19631 | * + |
| 19632 | * % --> new duplicate node-table entries |
| 19633 | * % |
| 19634 | * # --> old duplicate node-table entries |
| 19635 | * # (last) |
| 19636 | * |
| 19637 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19638 | bind = vctxt->inode->idcTable; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19639 | if (bind == NULL) { |
| 19640 | /* Fine, no table, no bubbles. */ |
| 19641 | return (0); |
| 19642 | } |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19643 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19644 | parTable = &(vctxt->elemInfos[vctxt->depth -1]->idcTable); |
| 19645 | /* |
| 19646 | * Walk all bindings; create new or add to existing bindings. |
| 19647 | * Remove duplicate key-sequences. |
| 19648 | */ |
| 19649 | start_binding: |
| 19650 | while (bind != NULL) { |
| 19651 | /* |
| 19652 | * Skip keyref IDCs. |
| 19653 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19654 | if (bind->definition->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 19655 | bind = bind->next; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19656 | continue; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19657 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19658 | /* |
| 19659 | * Check if the key/unique IDC table needs to be bubbled. |
| 19660 | */ |
| 19661 | aidc = vctxt->aidcs; |
| 19662 | do { |
| 19663 | if (aidc->def == bind->definition) { |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 19664 | if ((aidc->bubbleDepth == -1) || |
Kasimier T. Buchcik | b34ad1b | 2005-03-21 20:10:31 +0000 | [diff] [blame] | 19665 | (aidc->bubbleDepth >= vctxt->depth)) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19666 | bind = bind->next; |
| 19667 | goto start_binding; |
| 19668 | } |
| 19669 | break; |
| 19670 | } |
| 19671 | aidc = aidc->next; |
| 19672 | } while (aidc != NULL); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19673 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19674 | if (parTable != NULL) |
| 19675 | parBind = *parTable; |
| 19676 | while (parBind != NULL) { |
| 19677 | /* |
| 19678 | * Search a matching parent binding for the |
| 19679 | * IDC definition. |
| 19680 | */ |
| 19681 | if (parBind->definition == bind->definition) { |
| 19682 | |
| 19683 | /* |
| 19684 | * Compare every node-table entry of the child node, |
| 19685 | * i.e. the key-sequence within, ... |
| 19686 | */ |
| 19687 | oldNum = parBind->nbNodes; /* Skip newly added items. */ |
| 19688 | duplTop = oldNum + parBind->nbDupls; |
Kasimier T. Buchcik | b34ad1b | 2005-03-21 20:10:31 +0000 | [diff] [blame] | 19689 | newDupls = 0; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19690 | |
| 19691 | for (i = 0; i < bind->nbNodes; i++) { |
| 19692 | node = bind->nodeTable[i]; |
| 19693 | if (node == NULL) |
| 19694 | continue; |
| 19695 | /* |
| 19696 | * ...with every key-sequence of the parent node, already |
| 19697 | * evaluated to be a duplicate key-sequence. |
| 19698 | */ |
| 19699 | if (parBind->nbDupls != 0) { |
| 19700 | j = bind->nbNodes + newDupls; |
| 19701 | while (j < duplTop) { |
| 19702 | parNode = parBind->nodeTable[j]; |
| 19703 | for (k = 0; k < bind->definition->nbFields; k++) { |
| 19704 | key = node->keys[k]; |
| 19705 | parKey = parNode->keys[k]; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19706 | ret = xmlSchemaAreValuesEqual(key->val, |
| 19707 | parKey->val); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19708 | if (ret == -1) { |
| 19709 | /* TODO: Internal error */ |
| 19710 | return(-1); |
| 19711 | } else if (ret == 0) |
| 19712 | break; |
| 19713 | |
| 19714 | } |
| 19715 | if (ret == 1) |
| 19716 | /* Duplicate found. */ |
| 19717 | break; |
| 19718 | j++; |
| 19719 | } |
| 19720 | if (j != duplTop) { |
| 19721 | /* Duplicate found. */ |
| 19722 | continue; |
| 19723 | } |
| 19724 | } |
| 19725 | /* |
| 19726 | * ... and with every key-sequence of the parent node. |
| 19727 | */ |
| 19728 | j = 0; |
| 19729 | while (j < oldNum) { |
| 19730 | parNode = parBind->nodeTable[j]; |
| 19731 | /* |
| 19732 | * Compare key by key. |
| 19733 | */ |
| 19734 | for (k = 0; k < parBind->definition->nbFields; k++) { |
| 19735 | key = node->keys[k]; |
| 19736 | parKey = parNode->keys[k]; |
| 19737 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19738 | ret = xmlSchemaAreValuesEqual(key->val, |
| 19739 | parKey->val); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19740 | if (ret == -1) { |
| 19741 | /* TODO: Internal error */ |
| 19742 | } else if (ret == 0) |
| 19743 | break; |
| 19744 | |
| 19745 | } |
| 19746 | if (ret == 1) |
| 19747 | /* |
| 19748 | * The key-sequences are equal. |
| 19749 | */ |
| 19750 | break; |
| 19751 | j++; |
| 19752 | } |
| 19753 | if (j != oldNum) { |
| 19754 | /* |
| 19755 | * Handle duplicates. |
| 19756 | */ |
| 19757 | newDupls++; |
| 19758 | oldNum--; |
| 19759 | parBind->nbNodes--; |
| 19760 | /* |
| 19761 | * Move last old item to pos of duplicate. |
| 19762 | */ |
| 19763 | parBind->nodeTable[j] = |
| 19764 | parBind->nodeTable[oldNum]; |
| 19765 | |
| 19766 | if (parBind->nbNodes != oldNum) { |
| 19767 | /* |
| 19768 | * If new items exist, move last new item to |
| 19769 | * last of old items. |
| 19770 | */ |
| 19771 | parBind->nodeTable[oldNum] = |
| 19772 | parBind->nodeTable[parBind->nbNodes]; |
| 19773 | } |
| 19774 | /* |
| 19775 | * Move duplicate to last pos of new/old items. |
| 19776 | */ |
| 19777 | parBind->nodeTable[parBind->nbNodes] = parNode; |
| 19778 | |
| 19779 | } else { |
| 19780 | /* |
| 19781 | * Add the node-table entry (node and key-sequence) of |
| 19782 | * the child node to the node table of the parent node. |
| 19783 | */ |
| 19784 | if (parBind->nodeTable == NULL) { |
| 19785 | parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *) |
Kasimier T. Buchcik | b34ad1b | 2005-03-21 20:10:31 +0000 | [diff] [blame] | 19786 | xmlMalloc(10 * sizeof(xmlSchemaPSVIIDCNodePtr)); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19787 | if (parBind->nodeTable == NULL) { |
| 19788 | xmlSchemaVErrMemory(NULL, |
| 19789 | "allocating IDC list of node-table items", NULL); |
| 19790 | return(-1); |
| 19791 | } |
| 19792 | parBind->sizeNodes = 1; |
| 19793 | } else if (duplTop >= parBind->sizeNodes) { |
Kasimier T. Buchcik | b34ad1b | 2005-03-21 20:10:31 +0000 | [diff] [blame] | 19794 | parBind->sizeNodes *= 2; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19795 | parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *) |
| 19796 | xmlRealloc(parBind->nodeTable, parBind->sizeNodes * |
| 19797 | sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 19798 | if (parBind->nodeTable == NULL) { |
| 19799 | xmlSchemaVErrMemory(NULL, |
| 19800 | "re-allocating IDC list of node-table items", NULL); |
| 19801 | return(-1); |
| 19802 | } |
| 19803 | } |
| 19804 | |
| 19805 | /* |
| 19806 | * Move first old duplicate to last position |
| 19807 | * of old duplicates +1. |
| 19808 | */ |
| 19809 | if (parBind->nbDupls != 0) { |
| 19810 | parBind->nodeTable[duplTop] = |
| 19811 | parBind->nodeTable[parBind->nbNodes + newDupls]; |
| 19812 | } |
| 19813 | /* |
| 19814 | * Move first new duplicate to last position of |
| 19815 | * new duplicates +1. |
| 19816 | */ |
| 19817 | if (newDupls != 0) { |
| 19818 | parBind->nodeTable[parBind->nbNodes + newDupls] = |
| 19819 | parBind->nodeTable[parBind->nbNodes]; |
| 19820 | } |
| 19821 | /* |
| 19822 | * Append the new node-table entry to the 'new node-table |
| 19823 | * entries' section. |
| 19824 | */ |
| 19825 | parBind->nodeTable[parBind->nbNodes] = node; |
| 19826 | parBind->nbNodes++; |
| 19827 | duplTop++; |
| 19828 | } |
| 19829 | } |
| 19830 | parBind->nbDupls += newDupls; |
| 19831 | break; |
| 19832 | } |
| 19833 | if (parBind->next == NULL) |
| 19834 | lastParBind = parBind; |
| 19835 | parBind = parBind->next; |
| 19836 | } |
Kasimier T. Buchcik | b34ad1b | 2005-03-21 20:10:31 +0000 | [diff] [blame] | 19837 | if ((parBind == NULL) && (bind->nbNodes != 0)) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19838 | /* |
| 19839 | * No binding for the IDC was found: create a new one and |
| 19840 | * copy all node-tables. |
| 19841 | */ |
| 19842 | parBind = xmlSchemaIDCNewBinding(bind->definition); |
| 19843 | if (parBind == NULL) |
| 19844 | return(-1); |
| 19845 | |
| 19846 | parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *) |
| 19847 | xmlMalloc(bind->nbNodes * sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 19848 | if (parBind->nodeTable == NULL) { |
| 19849 | xmlSchemaVErrMemory(NULL, |
| 19850 | "allocating an array of IDC node-table items", NULL); |
| 19851 | xmlSchemaIDCFreeBinding(parBind); |
| 19852 | return(-1); |
| 19853 | } |
| 19854 | parBind->sizeNodes = bind->nbNodes; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19855 | parBind->nbNodes = bind->nbNodes; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19856 | memcpy(parBind->nodeTable, bind->nodeTable, |
| 19857 | bind->nbNodes * sizeof(xmlSchemaPSVIIDCNodePtr)); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19858 | if (*parTable == NULL) |
| 19859 | *parTable = parBind; |
| 19860 | else |
| 19861 | lastParBind->next = parBind; |
| 19862 | } |
| 19863 | bind = bind->next; |
| 19864 | } |
| 19865 | return (0); |
| 19866 | } |
| 19867 | |
| 19868 | /** |
| 19869 | * xmlSchemaCheckCVCIDCKeyRef: |
| 19870 | * @vctxt: the WXS validation context |
| 19871 | * @elemDecl: the element declaration |
| 19872 | * |
| 19873 | * Check the cvc-idc-keyref constraints. |
| 19874 | */ |
| 19875 | static int |
| 19876 | xmlSchemaCheckCVCIDCKeyRef(xmlSchemaValidCtxtPtr vctxt) |
| 19877 | { |
| 19878 | xmlSchemaPSVIIDCBindingPtr refbind, bind; |
| 19879 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19880 | refbind = vctxt->inode->idcTable; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19881 | /* |
| 19882 | * Find a keyref. |
| 19883 | */ |
| 19884 | while (refbind != NULL) { |
| 19885 | if (refbind->definition->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 19886 | int i, j, k, res; |
| 19887 | xmlSchemaPSVIIDCKeyPtr *refKeys, *keys; |
| 19888 | xmlSchemaPSVIIDCKeyPtr refKey, key; |
| 19889 | |
| 19890 | /* |
| 19891 | * Find the referred key/unique. |
| 19892 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19893 | bind = vctxt->inode->idcTable; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19894 | do { |
| 19895 | if ((xmlSchemaIDCPtr) refbind->definition->ref->item == |
| 19896 | bind->definition) |
| 19897 | break; |
| 19898 | bind = bind->next; |
| 19899 | } while (bind != NULL); |
| 19900 | |
| 19901 | /* |
| 19902 | * Search for a matching key-sequences. |
| 19903 | */ |
| 19904 | for (i = 0; i < refbind->nbNodes; i++) { |
| 19905 | res = 0; |
| 19906 | if (bind != NULL) { |
| 19907 | refKeys = refbind->nodeTable[i]->keys; |
| 19908 | for (j = 0; j < bind->nbNodes; j++) { |
| 19909 | keys = bind->nodeTable[j]->keys; |
| 19910 | for (k = 0; k < bind->definition->nbFields; k++) { |
| 19911 | refKey = refKeys[k]; |
| 19912 | key = keys[k]; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19913 | res = xmlSchemaAreValuesEqual(key->val, |
| 19914 | refKey->val); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19915 | if (res == 0) |
| 19916 | break; |
| 19917 | else if (res == -1) { |
| 19918 | return (-1); |
| 19919 | } |
| 19920 | } |
| 19921 | if (res == 1) { |
| 19922 | /* |
| 19923 | * Match found. |
| 19924 | */ |
| 19925 | break; |
| 19926 | } |
| 19927 | } |
| 19928 | } |
| 19929 | if (res == 0) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19930 | xmlChar *str = NULL, *strB = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19931 | /* TODO: Report the key-sequence. */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19932 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 19933 | XML_SCHEMAV_CVC_IDC, NULL, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19934 | (xmlSchemaTypePtr) refbind->definition, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19935 | "No match found for key-sequence %s of key " |
| 19936 | "reference '%s'", |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 19937 | xmlSchemaFormatIDCKeySequence(vctxt, &str, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19938 | refbind->nodeTable[i]->keys, |
| 19939 | refbind->definition->nbFields), |
| 19940 | xmlSchemaFormatQName(&strB, |
| 19941 | refbind->definition->targetNamespace, |
| 19942 | refbind->definition->name)); |
| 19943 | FREE_AND_NULL(str); |
| 19944 | FREE_AND_NULL(strB); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19945 | } |
| 19946 | } |
| 19947 | } |
| 19948 | refbind = refbind->next; |
| 19949 | } |
| 19950 | return (0); |
| 19951 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19952 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19953 | /************************************************************************ |
| 19954 | * * |
| 19955 | * XML Reader validation code * |
| 19956 | * * |
| 19957 | ************************************************************************/ |
| 19958 | |
| 19959 | static xmlSchemaAttrInfoPtr |
| 19960 | xmlSchemaGetFreshAttrInfo(xmlSchemaValidCtxtPtr vctxt) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19961 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 19962 | xmlSchemaAttrInfoPtr iattr; |
| 19963 | /* |
| 19964 | * Grow/create list of attribute infos. |
| 19965 | */ |
| 19966 | if (vctxt->attrInfos == NULL) { |
| 19967 | vctxt->attrInfos = (xmlSchemaAttrInfoPtr *) |
| 19968 | xmlMalloc(sizeof(xmlSchemaAttrInfoPtr)); |
| 19969 | vctxt->sizeAttrInfos = 1; |
| 19970 | if (vctxt->attrInfos == NULL) { |
| 19971 | xmlSchemaVErrMemory(vctxt, |
| 19972 | "allocating attribute info list", NULL); |
| 19973 | return (NULL); |
| 19974 | } |
| 19975 | } else if (vctxt->sizeAttrInfos <= vctxt->nbAttrInfos) { |
| 19976 | vctxt->sizeAttrInfos++; |
| 19977 | vctxt->attrInfos = (xmlSchemaAttrInfoPtr *) |
| 19978 | xmlRealloc(vctxt->attrInfos, |
| 19979 | vctxt->sizeAttrInfos * sizeof(xmlSchemaAttrInfoPtr)); |
| 19980 | if (vctxt->attrInfos == NULL) { |
| 19981 | xmlSchemaVErrMemory(vctxt, |
| 19982 | "re-allocating attribute info list", NULL); |
| 19983 | return (NULL); |
| 19984 | } |
| 19985 | } else { |
| 19986 | iattr = vctxt->attrInfos[vctxt->nbAttrInfos++]; |
| 19987 | if (iattr->localName != NULL) { |
| 19988 | VERROR_INT("xmlSchemaGetFreshAttrInfo", |
| 19989 | "attr info not cleared"); |
| 19990 | return (NULL); |
| 19991 | } |
| 19992 | iattr->nodeType = XML_ATTRIBUTE_NODE; |
| 19993 | return (iattr); |
| 19994 | } |
| 19995 | /* |
| 19996 | * Create an attribute info. |
| 19997 | */ |
| 19998 | iattr = (xmlSchemaAttrInfoPtr) |
| 19999 | xmlMalloc(sizeof(xmlSchemaAttrInfo)); |
| 20000 | if (iattr == NULL) { |
| 20001 | xmlSchemaVErrMemory(vctxt, "creating new attribute info", NULL); |
| 20002 | return (NULL); |
| 20003 | } |
| 20004 | memset(iattr, 0, sizeof(xmlSchemaAttrInfo)); |
| 20005 | iattr->nodeType = XML_ATTRIBUTE_NODE; |
| 20006 | vctxt->attrInfos[vctxt->nbAttrInfos++] = iattr; |
| 20007 | |
| 20008 | return (iattr); |
| 20009 | } |
| 20010 | |
| 20011 | static int |
| 20012 | xmlSchemaValidatorPushAttribute(xmlSchemaValidCtxtPtr vctxt, |
| 20013 | xmlNodePtr attrNode, |
| 20014 | const xmlChar *localName, |
| 20015 | const xmlChar *nsName, |
| 20016 | int ownedNames, |
| 20017 | xmlChar *value, |
| 20018 | int ownedValue) |
| 20019 | { |
| 20020 | xmlSchemaAttrInfoPtr attr; |
| 20021 | |
| 20022 | attr = xmlSchemaGetFreshAttrInfo(vctxt); |
| 20023 | if (attr == NULL) { |
| 20024 | VERROR_INT("xmlSchemaPushAttribute", |
| 20025 | "calling xmlSchemaGetFreshAttrInfo()"); |
| 20026 | return (-1); |
| 20027 | } |
| 20028 | attr->node = attrNode; |
| 20029 | attr->state = XML_SCHEMAS_ATTR_UNKNOWN; |
| 20030 | attr->localName = localName; |
| 20031 | attr->nsName = nsName; |
| 20032 | if (ownedNames) |
| 20033 | attr->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES; |
| 20034 | /* |
| 20035 | * Evaluate if it's an XSI attribute. |
| 20036 | */ |
| 20037 | if (nsName != NULL) { |
| 20038 | if (xmlStrEqual(localName, BAD_CAST "nil")) { |
| 20039 | if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) { |
| 20040 | attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_NIL; |
| 20041 | } |
| 20042 | } else if (xmlStrEqual(localName, BAD_CAST "type")) { |
| 20043 | if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) { |
| 20044 | attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_TYPE; |
| 20045 | } |
| 20046 | } else if (xmlStrEqual(localName, BAD_CAST "schemaLocation")) { |
| 20047 | if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) { |
| 20048 | attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC; |
| 20049 | } |
| 20050 | } else if (xmlStrEqual(localName, BAD_CAST "noNamespaceSchemaLocation")) { |
| 20051 | if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) { |
| 20052 | attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC; |
| 20053 | } |
| 20054 | } else if (xmlStrEqual(attr->nsName, xmlNamespaceNs)) { |
| 20055 | attr->metaType = XML_SCHEMA_ATTR_INFO_META_XMLNS; |
| 20056 | } |
| 20057 | } |
| 20058 | attr->value = value; |
| 20059 | if (ownedValue) |
| 20060 | attr->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES; |
| 20061 | if (attr->metaType != 0) |
| 20062 | attr->state = XML_SCHEMAS_ATTR_META; |
| 20063 | return (0); |
| 20064 | } |
| 20065 | |
| 20066 | static void |
| 20067 | xmlSchemaClearElemInfo(xmlSchemaNodeInfoPtr ielem) |
| 20068 | { |
| 20069 | if (ielem->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES) { |
| 20070 | FREE_AND_NULL(ielem->localName); |
| 20071 | FREE_AND_NULL(ielem->nsName); |
| 20072 | } else { |
| 20073 | ielem->localName = NULL; |
| 20074 | ielem->nsName = NULL; |
| 20075 | } |
| 20076 | if (ielem->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) { |
| 20077 | FREE_AND_NULL(ielem->value); |
| 20078 | } else { |
| 20079 | ielem->value = NULL; |
| 20080 | } |
| 20081 | if (ielem->val != NULL) { |
| 20082 | xmlSchemaFreeValue(ielem->val); |
| 20083 | ielem->val = NULL; |
| 20084 | } |
| 20085 | if (ielem->idcMatchers != NULL) { |
| 20086 | xmlSchemaIDCFreeMatcherList(ielem->idcMatchers); |
| 20087 | ielem->idcMatchers = NULL; |
| 20088 | } |
| 20089 | if (ielem->idcTable != NULL) { |
| 20090 | xmlSchemaIDCFreeIDCTable(ielem->idcTable); |
| 20091 | ielem->idcTable = NULL; |
| 20092 | } |
| 20093 | if (ielem->regexCtxt != NULL) { |
| 20094 | xmlRegFreeExecCtxt(ielem->regexCtxt); |
| 20095 | ielem->regexCtxt = NULL; |
| 20096 | } |
| 20097 | if (ielem->nsBindings != NULL) { |
| 20098 | xmlFree((xmlChar **)ielem->nsBindings); |
| 20099 | ielem->nsBindings = NULL; |
| 20100 | ielem->nbNsBindings = 0; |
| 20101 | ielem->sizeNsBindings = 0; |
| 20102 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20103 | } |
| 20104 | |
| 20105 | /** |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 20106 | * xmlSchemaGetFreshElemInfo: |
| 20107 | * @vctxt: the schema validation context |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20108 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 20109 | * Creates/reuses and initializes the element info item for |
| 20110 | * the currect tree depth. |
| 20111 | * |
| 20112 | * Returns the element info item or NULL on API or internal errors. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20113 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 20114 | static xmlSchemaNodeInfoPtr |
| 20115 | xmlSchemaGetFreshElemInfo(xmlSchemaValidCtxtPtr vctxt) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20116 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 20117 | xmlSchemaNodeInfoPtr info = NULL; |
| 20118 | |
| 20119 | if (vctxt->depth > vctxt->sizeElemInfos) { |
| 20120 | VERROR_INT("xmlSchemaGetFreshElemInfo", |
| 20121 | "inconsistent depth encountered"); |
| 20122 | return (NULL); |
| 20123 | } |
| 20124 | if (vctxt->elemInfos == NULL) { |
| 20125 | vctxt->elemInfos = (xmlSchemaNodeInfoPtr *) |
| 20126 | xmlMalloc(10 * sizeof(xmlSchemaNodeInfoPtr)); |
| 20127 | if (vctxt->elemInfos == NULL) { |
| 20128 | xmlSchemaVErrMemory(vctxt, |
| 20129 | "allocating the element info array", NULL); |
| 20130 | return (NULL); |
| 20131 | } |
| 20132 | memset(vctxt->elemInfos, 0, 10 * sizeof(xmlSchemaNodeInfoPtr)); |
| 20133 | vctxt->sizeElemInfos = 10; |
| 20134 | } else if (vctxt->sizeElemInfos <= vctxt->depth) { |
| 20135 | int i = vctxt->sizeElemInfos; |
| 20136 | |
| 20137 | vctxt->sizeElemInfos *= 2; |
| 20138 | vctxt->elemInfos = (xmlSchemaNodeInfoPtr *) |
| 20139 | xmlRealloc(vctxt->elemInfos, vctxt->sizeElemInfos * |
| 20140 | sizeof(xmlSchemaNodeInfoPtr)); |
| 20141 | if (vctxt->elemInfos == NULL) { |
| 20142 | xmlSchemaVErrMemory(vctxt, |
| 20143 | "re-allocating the element info array", NULL); |
| 20144 | return (NULL); |
| 20145 | } |
| 20146 | /* |
| 20147 | * We need the new memory to be NULLed. |
| 20148 | * TODO: Use memset instead? |
| 20149 | */ |
| 20150 | for (; i < vctxt->sizeElemInfos; i++) |
| 20151 | vctxt->elemInfos[i] = NULL; |
| 20152 | } else |
| 20153 | info = vctxt->elemInfos[vctxt->depth]; |
| 20154 | |
| 20155 | if (info == NULL) { |
| 20156 | info = (xmlSchemaNodeInfoPtr) |
| 20157 | xmlMalloc(sizeof(xmlSchemaNodeInfo)); |
| 20158 | if (info == NULL) { |
| 20159 | xmlSchemaVErrMemory(vctxt, |
| 20160 | "allocating an element info", NULL); |
| 20161 | return (NULL); |
| 20162 | } |
| 20163 | vctxt->elemInfos[vctxt->depth] = info; |
| 20164 | } else { |
| 20165 | if (info->localName != NULL) { |
| 20166 | VERROR_INT("xmlSchemaGetFreshElemInfo", |
| 20167 | "elem info has not been cleared"); |
| 20168 | return (NULL); |
| 20169 | } |
| 20170 | } |
| 20171 | memset(info, 0, sizeof(xmlSchemaNodeInfo)); |
| 20172 | info->nodeType = XML_ELEMENT_NODE; |
| 20173 | info->depth = vctxt->depth; |
| 20174 | |
| 20175 | return (info); |
| 20176 | } |
| 20177 | |
| 20178 | #define ACTIVATE_ATTRIBUTE(item) vctxt->inode = (xmlSchemaNodeInfoPtr) item; |
| 20179 | #define ACTIVATE_ELEM vctxt->inode = vctxt->elemInfos[vctxt->depth]; |
| 20180 | #define ACTIVATE_PARENT_ELEM vctxt->inode = vctxt->elemInfos[vctxt->depth -1]; |
| 20181 | |
| 20182 | static int |
| 20183 | xmlSchemaValidateFacets(xmlSchemaAbstractCtxtPtr actxt, |
| 20184 | xmlNodePtr node, |
| 20185 | xmlSchemaTypePtr type, |
| 20186 | xmlSchemaValType valType, |
| 20187 | const xmlChar * value, |
| 20188 | xmlSchemaValPtr val, |
| 20189 | unsigned long length, |
| 20190 | int fireErrors) |
| 20191 | { |
| 20192 | int ret, error = 0; |
| 20193 | |
| 20194 | xmlSchemaTypePtr tmpType; |
| 20195 | xmlSchemaFacetLinkPtr facetLink; |
| 20196 | xmlSchemaFacetPtr facet; |
| 20197 | unsigned long len = 0; |
| 20198 | xmlSchemaWhitespaceValueType ws; |
| 20199 | |
| 20200 | /* |
| 20201 | * In Libxml2, derived built-in types have currently no explicit facets. |
| 20202 | */ |
| 20203 | if (type->type == XML_SCHEMA_TYPE_BASIC) |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 20204 | return (0); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 20205 | |
| 20206 | /* |
| 20207 | * NOTE: Do not jump away, if the facetSet of the given type is |
| 20208 | * empty: until now, "pattern" and "enumeration" facets of the |
| 20209 | * *base types* need to be checked as well. |
| 20210 | */ |
| 20211 | if (type->facetSet == NULL) |
| 20212 | goto pattern_and_enum; |
| 20213 | |
| 20214 | if (! VARIETY_ATOMIC(type)) { |
| 20215 | if (VARIETY_LIST(type)) |
| 20216 | goto variety_list; |
| 20217 | else |
| 20218 | goto pattern_and_enum; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20219 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20220 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 20221 | * Whitespace handling is only of importance for string-based |
| 20222 | * types. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20223 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 20224 | tmpType = xmlSchemaGetPrimitiveType(type); |
| 20225 | if ((tmpType->builtInType == XML_SCHEMAS_STRING) || |
| 20226 | IS_ANY_SIMPLE_TYPE(tmpType)) { |
| 20227 | ws = xmlSchemaGetWhiteSpaceFacetValue(type); |
| 20228 | } else |
| 20229 | ws = XML_SCHEMA_WHITESPACE_COLLAPSE; |
| 20230 | /* |
| 20231 | * If the value was not computed (for string or |
| 20232 | * anySimpleType based types), then use the provided |
| 20233 | * type. |
| 20234 | */ |
| 20235 | if (val == NULL) |
| 20236 | valType = valType; |
| 20237 | else |
| 20238 | valType = xmlSchemaGetValType(val); |
| 20239 | |
| 20240 | ret = 0; |
| 20241 | for (facetLink = type->facetSet; facetLink != NULL; |
| 20242 | facetLink = facetLink->next) { |
| 20243 | /* |
| 20244 | * Skip the pattern "whiteSpace": it is used to |
| 20245 | * format the character content beforehand. |
| 20246 | */ |
| 20247 | switch (facetLink->facet->type) { |
| 20248 | case XML_SCHEMA_FACET_WHITESPACE: |
| 20249 | case XML_SCHEMA_FACET_PATTERN: |
| 20250 | case XML_SCHEMA_FACET_ENUMERATION: |
| 20251 | continue; |
| 20252 | case XML_SCHEMA_FACET_LENGTH: |
| 20253 | case XML_SCHEMA_FACET_MINLENGTH: |
| 20254 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 20255 | ret = xmlSchemaValidateLengthFacetWhtsp(facetLink->facet, |
| 20256 | valType, value, val, &len, ws); |
| 20257 | break; |
| 20258 | default: |
| 20259 | ret = xmlSchemaValidateFacetWhtsp(facetLink->facet, ws, |
| 20260 | valType, value, val, ws); |
| 20261 | break; |
| 20262 | } |
| 20263 | if (ret < 0) { |
| 20264 | AERROR_INT("xmlSchemaValidateFacets", |
| 20265 | "validating against a atomic type facet"); |
| 20266 | return (-1); |
| 20267 | } else if (ret > 0) { |
| 20268 | if (fireErrors) |
| 20269 | xmlSchemaFacetErr(actxt, ret, node, |
| 20270 | value, len, type, facetLink->facet, NULL, NULL, NULL); |
| 20271 | else |
| 20272 | return (ret); |
| 20273 | if (error == 0) |
| 20274 | error = ret; |
| 20275 | } |
| 20276 | ret = 0; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20277 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 20278 | |
| 20279 | variety_list: |
| 20280 | if (! VARIETY_LIST(type)) |
| 20281 | goto pattern_and_enum; |
| 20282 | /* |
| 20283 | * "length", "minLength" and "maxLength" of list types. |
| 20284 | */ |
| 20285 | ret = 0; |
| 20286 | for (facetLink = type->facetSet; facetLink != NULL; |
| 20287 | facetLink = facetLink->next) { |
| 20288 | |
| 20289 | switch (facetLink->facet->type) { |
| 20290 | case XML_SCHEMA_FACET_LENGTH: |
| 20291 | case XML_SCHEMA_FACET_MINLENGTH: |
| 20292 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 20293 | ret = xmlSchemaValidateListSimpleTypeFacet(facetLink->facet, |
| 20294 | value, length, NULL); |
| 20295 | break; |
| 20296 | default: |
| 20297 | continue; |
| 20298 | } |
| 20299 | if (ret < 0) { |
| 20300 | AERROR_INT("xmlSchemaValidateFacets", |
| 20301 | "validating against a list type facet"); |
| 20302 | return (-1); |
| 20303 | } else if (ret > 0) { |
| 20304 | if (fireErrors) |
| 20305 | xmlSchemaFacetErr(actxt, ret, node, |
| 20306 | value, length, type, facetLink->facet, NULL, NULL, NULL); |
| 20307 | else |
| 20308 | return (ret); |
| 20309 | if (error == 0) |
| 20310 | error = ret; |
| 20311 | } |
| 20312 | ret = 0; |
| 20313 | } |
| 20314 | |
| 20315 | pattern_and_enum: |
| 20316 | if (error >= 0) { |
| 20317 | int found = 0; |
| 20318 | /* |
| 20319 | * Process enumerations. Facet values are in the value space |
| 20320 | * of the defining type's base type. This seems to be a bug in the |
| 20321 | * XML Schema 1.0 spec. Use the whitespace type of the base type. |
| 20322 | * Only the first set of enumerations in the ancestor-or-self axis |
| 20323 | * is used for validation. |
| 20324 | */ |
| 20325 | ret = 0; |
| 20326 | tmpType = type; |
| 20327 | do { |
| 20328 | for (facet = tmpType->facets; facet != NULL; facet = facet->next) { |
| 20329 | if (facet->type != XML_SCHEMA_FACET_ENUMERATION) |
| 20330 | continue; |
| 20331 | found = 1; |
| 20332 | ret = xmlSchemaAreValuesEqual(facet->val, val); |
| 20333 | if (ret == 1) |
| 20334 | break; |
| 20335 | else if (ret < 0) { |
| 20336 | AERROR_INT("xmlSchemaValidateFacets", |
| 20337 | "validating against an enumeration facet"); |
| 20338 | return (-1); |
| 20339 | } |
| 20340 | } |
| 20341 | if (ret != 0) |
| 20342 | break; |
| 20343 | tmpType = tmpType->baseType; |
| 20344 | } while ((tmpType != NULL) && |
| 20345 | (tmpType->type != XML_SCHEMA_TYPE_BASIC)); |
| 20346 | if (found && (ret == 0)) { |
| 20347 | ret = XML_SCHEMAV_CVC_ENUMERATION_VALID; |
| 20348 | if (fireErrors) { |
| 20349 | xmlSchemaFacetErr(actxt, ret, node, |
| 20350 | value, 0, type, NULL, NULL, NULL, NULL); |
| 20351 | } else |
| 20352 | return (ret); |
| 20353 | if (error == 0) |
| 20354 | error = ret; |
| 20355 | } |
| 20356 | } |
| 20357 | |
| 20358 | if (error >= 0) { |
| 20359 | int found; |
| 20360 | /* |
| 20361 | * Process patters. Pattern facets are ORed at type level |
| 20362 | * and ANDed if derived. Walk the base type axis. |
| 20363 | */ |
| 20364 | tmpType = type; |
| 20365 | facet = NULL; |
| 20366 | do { |
| 20367 | found = 0; |
| 20368 | for (facetLink = tmpType->facetSet; facetLink != NULL; |
| 20369 | facetLink = facetLink->next) { |
| 20370 | if (facetLink->facet->type != XML_SCHEMA_FACET_PATTERN) |
| 20371 | continue; |
| 20372 | found = 1; |
| 20373 | /* |
| 20374 | * NOTE that for patterns, @value needs to be the |
| 20375 | * normalized vaule. |
| 20376 | */ |
| 20377 | ret = xmlRegexpExec(facetLink->facet->regexp, value); |
| 20378 | if (ret == 1) |
| 20379 | break; |
| 20380 | else if (ret < 0) { |
| 20381 | AERROR_INT("xmlSchemaValidateFacets", |
| 20382 | "validating against a pattern facet"); |
| 20383 | return (-1); |
| 20384 | } else { |
| 20385 | /* |
| 20386 | * Save the last non-validating facet. |
| 20387 | */ |
| 20388 | facet = facetLink->facet; |
| 20389 | } |
| 20390 | } |
| 20391 | if (found && (ret != 1)) { |
| 20392 | ret = XML_SCHEMAV_CVC_PATTERN_VALID; |
| 20393 | if (fireErrors) { |
| 20394 | xmlSchemaFacetErr(actxt, ret, node, |
| 20395 | value, 0, type, facet, NULL, NULL, NULL); |
| 20396 | } else |
| 20397 | return (ret); |
| 20398 | if (error == 0) |
| 20399 | error = ret; |
| 20400 | break; |
| 20401 | } |
| 20402 | tmpType = tmpType->baseType; |
| 20403 | } while ((tmpType != NULL) && (tmpType->type != XML_SCHEMA_TYPE_BASIC)); |
| 20404 | } |
| 20405 | |
| 20406 | return (error); |
| 20407 | } |
| 20408 | |
| 20409 | static xmlChar * |
| 20410 | xmlSchemaNormalizeValue(xmlSchemaTypePtr type, |
| 20411 | const xmlChar *value) |
| 20412 | { |
| 20413 | switch (xmlSchemaGetWhiteSpaceFacetValue(type)) { |
| 20414 | case XML_SCHEMA_WHITESPACE_COLLAPSE: |
| 20415 | return (xmlSchemaCollapseString(value)); |
| 20416 | case XML_SCHEMA_WHITESPACE_REPLACE: |
| 20417 | return (xmlSchemaWhiteSpaceReplace(value)); |
| 20418 | default: |
| 20419 | return (NULL); |
| 20420 | } |
| 20421 | } |
| 20422 | |
| 20423 | static int |
| 20424 | xmlSchemaValidateQName(xmlSchemaValidCtxtPtr vctxt, |
| 20425 | const xmlChar *value, |
| 20426 | xmlSchemaValPtr *val, |
| 20427 | int valNeeded) |
| 20428 | { |
| 20429 | int ret; |
| 20430 | const xmlChar *nsName; |
| 20431 | xmlChar *local, *prefix = NULL; |
| 20432 | |
| 20433 | ret = xmlValidateQName(value, 1); |
| 20434 | if (ret != 0) { |
| 20435 | if (ret == -1) { |
| 20436 | VERROR_INT("xmlSchemaValidateQName", |
| 20437 | "calling xmlValidateQName()"); |
| 20438 | return (-1); |
| 20439 | } |
| 20440 | return( XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1); |
| 20441 | } |
| 20442 | /* |
| 20443 | * NOTE: xmlSplitQName2 will always return a duplicated |
| 20444 | * strings. |
| 20445 | */ |
| 20446 | local = xmlSplitQName2(value, &prefix); |
| 20447 | if (local == NULL) |
| 20448 | local = xmlStrdup(value); |
| 20449 | /* |
| 20450 | * OPTIMIZE TODO: Use flags for: |
| 20451 | * - is there any namespace binding? |
| 20452 | * - is there a default namespace? |
| 20453 | */ |
| 20454 | nsName = xmlSchemaLookupNamespace(vctxt, prefix); |
| 20455 | |
| 20456 | if (prefix != NULL) { |
| 20457 | xmlFree(prefix); |
| 20458 | /* |
| 20459 | * A namespace must be found if the prefix is |
| 20460 | * NOT NULL. |
| 20461 | */ |
| 20462 | if (nsName == NULL) { |
| 20463 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
| 20464 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) vctxt, ret, NULL, |
| 20465 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
| 20466 | "The QName value '%s' has no " |
| 20467 | "corresponding namespace declaration in " |
| 20468 | "scope", value, NULL); |
| 20469 | if (local != NULL) |
| 20470 | xmlFree(local); |
| 20471 | return (ret); |
| 20472 | } |
| 20473 | } |
| 20474 | if (valNeeded && val) { |
| 20475 | if (nsName != NULL) |
| 20476 | *val = xmlSchemaNewQNameValue( |
| 20477 | BAD_CAST xmlStrdup(nsName), BAD_CAST local); |
| 20478 | else |
| 20479 | *val = xmlSchemaNewQNameValue(NULL, |
| 20480 | BAD_CAST local); |
| 20481 | } else |
| 20482 | xmlFree(local); |
| 20483 | return (0); |
| 20484 | } |
| 20485 | |
| 20486 | /* |
| 20487 | * cvc-simple-type |
| 20488 | */ |
| 20489 | static int |
| 20490 | xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt, |
| 20491 | xmlNodePtr node, |
| 20492 | xmlSchemaTypePtr type, |
| 20493 | const xmlChar *value, |
| 20494 | xmlSchemaValPtr *retVal, |
| 20495 | int fireErrors, |
| 20496 | int normalize, |
| 20497 | int isNormalized) |
| 20498 | { |
| 20499 | int ret = 0, valNeeded = (retVal) ? 1 : 0; |
| 20500 | xmlSchemaValPtr val = NULL; |
| 20501 | xmlSchemaWhitespaceValueType ws; |
| 20502 | xmlChar *normValue = NULL; |
| 20503 | |
| 20504 | #define NORMALIZE(atype) \ |
| 20505 | if ((! isNormalized) && \ |
| 20506 | (normalize || (type->flags & XML_SCHEMAS_TYPE_NORMVALUENEEDED))) { \ |
| 20507 | normValue = xmlSchemaNormalizeValue(atype, value); \ |
| 20508 | if (normValue != NULL) \ |
| 20509 | value = normValue; \ |
| 20510 | isNormalized = 1; \ |
| 20511 | } |
| 20512 | |
| 20513 | if ((retVal != NULL) && (*retVal != NULL)) { |
| 20514 | xmlSchemaFreeValue(*retVal); |
| 20515 | *retVal = NULL; |
| 20516 | } |
| 20517 | /* |
| 20518 | * 3.14.4 Simple Type Definition Validation Rules |
| 20519 | * Validation Rule: String Valid |
| 20520 | */ |
| 20521 | /* |
| 20522 | * 1 It is schema-valid with respect to that definition as defined |
| 20523 | * by Datatype Valid in [XML Schemas: Datatypes]. |
| 20524 | */ |
| 20525 | /* |
| 20526 | * 2.1 If The definition is ENTITY or is validly derived from ENTITY given |
| 20527 | * the empty set, as defined in Type Derivation OK (Simple) (§3.14.6), then |
| 20528 | * the string must be a ·declared entity name·. |
| 20529 | */ |
| 20530 | /* |
| 20531 | * 2.2 If The definition is ENTITIES or is validly derived from ENTITIES |
| 20532 | * given the empty set, as defined in Type Derivation OK (Simple) (§3.14.6), |
| 20533 | * then every whitespace-delimited substring of the string must be a ·declared |
| 20534 | * entity name·. |
| 20535 | */ |
| 20536 | /* |
| 20537 | * 2.3 otherwise no further condition applies. |
| 20538 | */ |
| 20539 | if ((! valNeeded) && (type->flags & XML_SCHEMAS_TYPE_FACETSNEEDVALUE)) |
| 20540 | valNeeded = 1; |
Kasimier T. Buchcik | 9c215eb | 2005-06-21 08:38:49 +0000 | [diff] [blame] | 20541 | if (value == NULL) |
| 20542 | value = BAD_CAST ""; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 20543 | if (IS_ANY_SIMPLE_TYPE(type) || VARIETY_ATOMIC(type)) { |
| 20544 | xmlSchemaTypePtr biType; /* The built-in type. */ |
| 20545 | /* |
| 20546 | * SPEC (1.2.1) "if {variety} is ·atomic· then the string must ·match· |
| 20547 | * a literal in the ·lexical space· of {base type definition}" |
| 20548 | */ |
| 20549 | /* |
| 20550 | * Whitespace-normalize. |
| 20551 | */ |
| 20552 | NORMALIZE(type); |
| 20553 | if (type->type != XML_SCHEMA_TYPE_BASIC) { |
| 20554 | /* |
| 20555 | * Get the built-in type. |
| 20556 | */ |
| 20557 | biType = type->baseType; |
| 20558 | while ((biType != NULL) && |
| 20559 | (biType->type != XML_SCHEMA_TYPE_BASIC)) |
| 20560 | biType = biType->baseType; |
| 20561 | |
| 20562 | if (biType == NULL) { |
| 20563 | AERROR_INT("xmlSchemaVCheckCVCSimpleType", |
| 20564 | "could not get the built-in type"); |
| 20565 | goto internal_error; |
| 20566 | } |
| 20567 | } else |
| 20568 | biType = type; |
| 20569 | /* |
| 20570 | * NOTATIONs need to be processed here, since they need |
| 20571 | * to lookup in the hashtable of NOTATION declarations of the schema. |
| 20572 | */ |
| 20573 | if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR) { |
| 20574 | switch (biType->builtInType) { |
| 20575 | case XML_SCHEMAS_NOTATION: |
| 20576 | ret = xmlSchemaValidateNotation( |
| 20577 | (xmlSchemaValidCtxtPtr) actxt, |
| 20578 | ((xmlSchemaValidCtxtPtr) actxt)->schema, |
| 20579 | NULL, value, &val, valNeeded); |
| 20580 | break; |
| 20581 | case XML_SCHEMAS_QNAME: |
| 20582 | ret = xmlSchemaValidateQName((xmlSchemaValidCtxtPtr) actxt, |
| 20583 | value, &val, valNeeded); |
| 20584 | break; |
| 20585 | default: |
| 20586 | ws = xmlSchemaGetWhiteSpaceFacetValue(type); |
| 20587 | if (valNeeded) |
| 20588 | ret = xmlSchemaValPredefTypeNodeNoNorm(biType, |
| 20589 | value, &val, NULL); |
| 20590 | else |
| 20591 | ret = xmlSchemaValPredefTypeNodeNoNorm(biType, |
| 20592 | value, NULL, NULL); |
| 20593 | break; |
| 20594 | } |
| 20595 | } else if (actxt->type == XML_SCHEMA_CTXT_PARSER) { |
| 20596 | switch (biType->builtInType) { |
| 20597 | case XML_SCHEMAS_NOTATION: |
| 20598 | ret = xmlSchemaValidateNotation(NULL, |
| 20599 | ((xmlSchemaParserCtxtPtr) actxt)->schema, node, |
| 20600 | value, &val, valNeeded); |
| 20601 | break; |
| 20602 | default: |
| 20603 | ws = xmlSchemaGetWhiteSpaceFacetValue(type); |
| 20604 | if (valNeeded) |
| 20605 | ret = xmlSchemaValPredefTypeNodeNoNorm(biType, |
| 20606 | value, &val, node); |
| 20607 | else |
| 20608 | ret = xmlSchemaValPredefTypeNodeNoNorm(biType, |
| 20609 | value, NULL, node); |
| 20610 | break; |
| 20611 | } |
| 20612 | } else { |
| 20613 | /* |
| 20614 | * Validation via a public API is not implemented yet. |
| 20615 | */ |
| 20616 | TODO |
| 20617 | goto internal_error; |
| 20618 | } |
| 20619 | if (ret != 0) { |
| 20620 | if (ret < 0) { |
| 20621 | AERROR_INT("xmlSchemaVCheckCVCSimpleType", |
| 20622 | "validating against a built-in type"); |
| 20623 | goto internal_error; |
| 20624 | } |
| 20625 | if (VARIETY_LIST(type)) |
| 20626 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
| 20627 | else |
| 20628 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
| 20629 | } |
| 20630 | if ((ret == 0) && (type->flags & XML_SCHEMAS_TYPE_HAS_FACETS)) { |
| 20631 | /* |
| 20632 | * Check facets. |
| 20633 | */ |
| 20634 | ret = xmlSchemaValidateFacets(actxt, node, type, |
| 20635 | (xmlSchemaValType) biType->builtInType, value, val, |
| 20636 | 0, fireErrors); |
| 20637 | if (ret != 0) { |
| 20638 | if (ret < 0) { |
| 20639 | AERROR_INT("xmlSchemaVCheckCVCSimpleType", |
| 20640 | "validating facets of atomic simple type"); |
| 20641 | goto internal_error; |
| 20642 | } |
| 20643 | if (VARIETY_LIST(type)) |
| 20644 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
| 20645 | else |
| 20646 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
| 20647 | } |
| 20648 | } |
| 20649 | if (fireErrors && (ret > 0)) |
| 20650 | xmlSchemaSimpleTypeErr(actxt, ret, node, value, type, 1); |
| 20651 | } else if (VARIETY_LIST(type)) { |
| 20652 | |
| 20653 | xmlSchemaTypePtr itemType; |
| 20654 | const xmlChar *cur, *end; |
| 20655 | xmlChar *tmpValue = NULL; |
| 20656 | unsigned long len = 0; |
| 20657 | xmlSchemaValPtr prevVal = NULL, curVal = NULL; |
| 20658 | /* 1.2.2 if {variety} is ·list· then the string must be a sequence |
| 20659 | * of white space separated tokens, each of which ·match·es a literal |
| 20660 | * in the ·lexical space· of {item type definition} |
| 20661 | */ |
| 20662 | /* |
| 20663 | * Note that XML_SCHEMAS_TYPE_NORMVALUENEEDED will be set if |
| 20664 | * the list type has an enum or pattern facet. |
| 20665 | */ |
| 20666 | NORMALIZE(type); |
| 20667 | /* |
| 20668 | * VAL TODO: Optimize validation of empty values. |
| 20669 | * VAL TODO: We do not have computed values for lists. |
| 20670 | */ |
Kasimier T. Buchcik | 9c215eb | 2005-06-21 08:38:49 +0000 | [diff] [blame] | 20671 | itemType = GET_LIST_ITEM_TYPE(type); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 20672 | cur = value; |
| 20673 | do { |
| 20674 | while (IS_BLANK_CH(*cur)) |
| 20675 | cur++; |
| 20676 | end = cur; |
| 20677 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 20678 | end++; |
| 20679 | if (end == cur) |
| 20680 | break; |
| 20681 | tmpValue = xmlStrndup(cur, end - cur); |
| 20682 | len++; |
| 20683 | |
| 20684 | if (valNeeded) |
| 20685 | ret = xmlSchemaVCheckCVCSimpleType(actxt, node, itemType, |
| 20686 | tmpValue, &curVal, fireErrors, 0, 1); |
| 20687 | else |
| 20688 | ret = xmlSchemaVCheckCVCSimpleType(actxt, node, itemType, |
| 20689 | tmpValue, NULL, fireErrors, 0, 1); |
| 20690 | FREE_AND_NULL(tmpValue); |
| 20691 | if (curVal != NULL) { |
| 20692 | /* |
| 20693 | * Add to list of computed values. |
| 20694 | */ |
| 20695 | if (val == NULL) |
| 20696 | val = curVal; |
| 20697 | else |
| 20698 | xmlSchemaValueAppend(prevVal, curVal); |
| 20699 | prevVal = curVal; |
| 20700 | curVal = NULL; |
| 20701 | } |
| 20702 | if (ret != 0) { |
| 20703 | if (ret < 0) { |
| 20704 | AERROR_INT("xmlSchemaVCheckCVCSimpleType", |
| 20705 | "validating an item of list simple type"); |
| 20706 | goto internal_error; |
| 20707 | } |
| 20708 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
| 20709 | break; |
| 20710 | } |
| 20711 | cur = end; |
| 20712 | } while (*cur != 0); |
| 20713 | FREE_AND_NULL(tmpValue); |
| 20714 | if ((ret == 0) && (type->flags & XML_SCHEMAS_TYPE_HAS_FACETS)) { |
| 20715 | /* |
| 20716 | * Apply facets (pattern, enumeration). |
| 20717 | */ |
| 20718 | ret = xmlSchemaValidateFacets(actxt, node, type, |
| 20719 | XML_SCHEMAS_UNKNOWN, value, val, |
| 20720 | len, fireErrors); |
| 20721 | if (ret != 0) { |
| 20722 | if (ret < 0) { |
| 20723 | AERROR_INT("xmlSchemaVCheckCVCSimpleType", |
| 20724 | "validating facets of list simple type"); |
| 20725 | goto internal_error; |
| 20726 | } |
| 20727 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
| 20728 | } |
| 20729 | } |
| 20730 | if (fireErrors && (ret > 0)) { |
| 20731 | /* |
| 20732 | * Report the normalized value. |
| 20733 | */ |
| 20734 | normalize = 1; |
| 20735 | NORMALIZE(type); |
| 20736 | xmlSchemaSimpleTypeErr(actxt, ret, node, value, type, 1); |
| 20737 | } |
| 20738 | } else if (VARIETY_UNION(type)) { |
| 20739 | xmlSchemaTypeLinkPtr memberLink; |
| 20740 | /* |
| 20741 | * TODO: For all datatypes ·derived· by ·union· whiteSpace does |
| 20742 | * not apply directly; however, the normalization behavior of ·union· |
| 20743 | * types is controlled by the value of whiteSpace on that one of the |
| 20744 | * ·memberTypes· against which the ·union· is successfully validated. |
| 20745 | * |
| 20746 | * This means that the value is normalized by the first validating |
| 20747 | * member type, then the facets of the union type are applied. This |
| 20748 | * needs changing of the value! |
| 20749 | */ |
| 20750 | |
| 20751 | /* |
| 20752 | * 1.2.3 if {variety} is ·union· then the string must ·match· a |
| 20753 | * literal in the ·lexical space· of at least one member of |
| 20754 | * {member type definitions} |
| 20755 | */ |
| 20756 | memberLink = xmlSchemaGetUnionSimpleTypeMemberTypes(type); |
| 20757 | if (memberLink == NULL) { |
| 20758 | AERROR_INT("xmlSchemaVCheckCVCSimpleType", |
| 20759 | "union simple type has no member types"); |
| 20760 | goto internal_error; |
| 20761 | } |
| 20762 | /* |
| 20763 | * Always normalize union type values, since we currently |
| 20764 | * cannot store the whitespace information with the value |
| 20765 | * itself; otherwise a later value-comparison would be |
| 20766 | * not possible. |
| 20767 | */ |
| 20768 | while (memberLink != NULL) { |
| 20769 | if (valNeeded) |
| 20770 | ret = xmlSchemaVCheckCVCSimpleType(actxt, node, |
| 20771 | memberLink->type, value, &val, 0, 1, 0); |
| 20772 | else |
| 20773 | ret = xmlSchemaVCheckCVCSimpleType(actxt, node, |
| 20774 | memberLink->type, value, NULL, 0, 1, 0); |
| 20775 | if (ret <= 0) |
| 20776 | break; |
| 20777 | memberLink = memberLink->next; |
| 20778 | } |
| 20779 | if (ret != 0) { |
| 20780 | if (ret < 0) { |
| 20781 | AERROR_INT("xmlSchemaVCheckCVCSimpleType", |
| 20782 | "validating members of union simple type"); |
| 20783 | goto internal_error; |
| 20784 | } |
| 20785 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3; |
| 20786 | } |
| 20787 | /* |
| 20788 | * Apply facets (pattern, enumeration). |
| 20789 | */ |
| 20790 | if ((ret == 0) && (type->flags & XML_SCHEMAS_TYPE_HAS_FACETS)) { |
| 20791 | /* |
| 20792 | * The normalization behavior of ·union· types is controlled by |
| 20793 | * the value of whiteSpace on that one of the ·memberTypes· |
| 20794 | * against which the ·union· is successfully validated. |
| 20795 | */ |
| 20796 | NORMALIZE(memberLink->type); |
| 20797 | ret = xmlSchemaValidateFacets(actxt, node, type, |
| 20798 | XML_SCHEMAS_UNKNOWN, value, val, |
| 20799 | 0, fireErrors); |
| 20800 | if (ret != 0) { |
| 20801 | if (ret < 0) { |
| 20802 | AERROR_INT("xmlSchemaVCheckCVCSimpleType", |
| 20803 | "validating facets of union simple type"); |
| 20804 | goto internal_error; |
| 20805 | } |
| 20806 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3; |
| 20807 | } |
| 20808 | } |
| 20809 | if (fireErrors && (ret > 0)) |
| 20810 | xmlSchemaSimpleTypeErr(actxt, ret, node, value, type, 1); |
| 20811 | } |
| 20812 | |
| 20813 | if (normValue != NULL) |
| 20814 | xmlFree(normValue); |
| 20815 | if (ret == 0) { |
| 20816 | if (retVal != NULL) |
| 20817 | *retVal = val; |
| 20818 | else if (val != NULL) |
| 20819 | xmlSchemaFreeValue(val); |
| 20820 | } else if (val != NULL) |
| 20821 | xmlSchemaFreeValue(val); |
| 20822 | return (ret); |
| 20823 | internal_error: |
| 20824 | if (normValue != NULL) |
| 20825 | xmlFree(normValue); |
| 20826 | if (val != NULL) |
| 20827 | xmlSchemaFreeValue(val); |
| 20828 | return (-1); |
| 20829 | } |
| 20830 | |
| 20831 | static int |
| 20832 | xmlSchemaVExpandQName(xmlSchemaValidCtxtPtr vctxt, |
| 20833 | const xmlChar *value, |
| 20834 | const xmlChar **nsName, |
| 20835 | const xmlChar **localName) |
| 20836 | { |
| 20837 | int ret = 0; |
| 20838 | |
| 20839 | if ((nsName == NULL) || (localName == NULL)) |
| 20840 | return (-1); |
| 20841 | *nsName = NULL; |
| 20842 | *localName = NULL; |
| 20843 | |
| 20844 | ret = xmlValidateQName(value, 1); |
| 20845 | if (ret == -1) |
| 20846 | return (-1); |
| 20847 | if (ret > 0) { |
| 20848 | xmlSchemaSimpleTypeErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 20849 | XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, NULL, |
| 20850 | value, xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), 1); |
| 20851 | return (1); |
| 20852 | } |
| 20853 | { |
| 20854 | xmlChar *local = NULL; |
| 20855 | xmlChar *prefix; |
| 20856 | |
| 20857 | /* |
| 20858 | * NOTE: xmlSplitQName2 will return a duplicated |
| 20859 | * string. |
| 20860 | */ |
| 20861 | local = xmlSplitQName2(value, &prefix); |
| 20862 | VAL_CREATE_DICT; |
| 20863 | if (local == NULL) |
| 20864 | *localName = xmlDictLookup(vctxt->dict, value, -1); |
| 20865 | else { |
| 20866 | *localName = xmlDictLookup(vctxt->dict, local, -1); |
| 20867 | xmlFree(local); |
| 20868 | } |
| 20869 | |
| 20870 | *nsName = xmlSchemaLookupNamespace(vctxt, prefix); |
| 20871 | |
| 20872 | if (prefix != NULL) { |
| 20873 | xmlFree(prefix); |
| 20874 | /* |
| 20875 | * A namespace must be found if the prefix is NOT NULL. |
| 20876 | */ |
| 20877 | if (*nsName == NULL) { |
| 20878 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 20879 | XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, NULL, |
| 20880 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
| 20881 | "The QName value '%s' has no " |
| 20882 | "corresponding namespace declaration in scope", |
| 20883 | value, NULL); |
| 20884 | return (2); |
| 20885 | } |
| 20886 | } |
| 20887 | } |
| 20888 | return (0); |
| 20889 | } |
| 20890 | |
| 20891 | static int |
| 20892 | xmlSchemaProcessXSIType(xmlSchemaValidCtxtPtr vctxt, |
| 20893 | xmlSchemaAttrInfoPtr iattr, |
| 20894 | xmlSchemaTypePtr *localType, |
| 20895 | xmlSchemaElementPtr elemDecl) |
| 20896 | { |
| 20897 | int ret = 0; |
| 20898 | /* |
| 20899 | * cvc-elt (3.3.4) : (4) |
| 20900 | * AND |
| 20901 | * Schema-Validity Assessment (Element) (cvc-assess-elt) |
| 20902 | * (1.2.1.2.1) - (1.2.1.2.4) |
| 20903 | * Handle 'xsi:type'. |
| 20904 | */ |
| 20905 | if (localType == NULL) |
| 20906 | return (-1); |
| 20907 | *localType = NULL; |
| 20908 | if (iattr == NULL) |
| 20909 | return (0); |
| 20910 | else { |
| 20911 | const xmlChar *nsName = NULL, *local = NULL; |
| 20912 | /* |
| 20913 | * TODO: We should report a *warning* that the type was overriden |
| 20914 | * by the instance. |
| 20915 | */ |
| 20916 | ACTIVATE_ATTRIBUTE(iattr); |
| 20917 | /* |
| 20918 | * (cvc-elt) (3.3.4) : (4.1) |
| 20919 | * (cvc-assess-elt) (1.2.1.2.2) |
| 20920 | */ |
| 20921 | ret = xmlSchemaVExpandQName(vctxt, iattr->value, |
| 20922 | &nsName, &local); |
| 20923 | if (ret != 0) { |
| 20924 | if (ret < 0) { |
| 20925 | VERROR_INT("xmlSchemaValidateElementByDeclaration", |
| 20926 | "calling xmlSchemaQNameExpand() to validate the " |
| 20927 | "attribute 'xsi:type'"); |
| 20928 | goto internal_error; |
| 20929 | } |
| 20930 | goto exit; |
| 20931 | } |
| 20932 | /* |
| 20933 | * (cvc-elt) (3.3.4) : (4.2) |
| 20934 | * (cvc-assess-elt) (1.2.1.2.3) |
| 20935 | */ |
| 20936 | *localType = xmlSchemaGetType(vctxt->schema, local, nsName); |
| 20937 | if (*localType == NULL) { |
| 20938 | xmlChar *str = NULL; |
| 20939 | |
| 20940 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 20941 | XML_SCHEMAV_CVC_ELT_4_2, NULL, |
| 20942 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
| 20943 | "The QName value '%s' of the xsi:type attribute does not " |
| 20944 | "resolve to a type definition", |
| 20945 | xmlSchemaFormatQName(&str, nsName, local), NULL); |
| 20946 | FREE_AND_NULL(str); |
| 20947 | ret = vctxt->err; |
| 20948 | goto exit; |
| 20949 | } |
| 20950 | if (elemDecl != NULL) { |
| 20951 | int set = 0; |
| 20952 | |
| 20953 | /* |
| 20954 | * SPEC cvc-elt (3.3.4) : (4.3) (Type Derivation OK) |
| 20955 | * "The ·local type definition· must be validly |
| 20956 | * derived from the {type definition} given the union of |
| 20957 | * the {disallowed substitutions} and the {type definition}'s |
| 20958 | * {prohibited substitutions}, as defined in |
| 20959 | * Type Derivation OK (Complex) (§3.4.6) |
| 20960 | * (if it is a complex type definition), |
| 20961 | * or given {disallowed substitutions} as defined in Type |
| 20962 | * Derivation OK (Simple) (§3.14.6) (if it is a simple type |
| 20963 | * definition)." |
| 20964 | * |
| 20965 | * {disallowed substitutions}: the "block" on the element decl. |
| 20966 | * {prohibited substitutions}: the "block" on the type def. |
| 20967 | */ |
| 20968 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) || |
| 20969 | (elemDecl->subtypes->flags & |
| 20970 | XML_SCHEMAS_TYPE_BLOCK_EXTENSION)) |
| 20971 | set |= SUBSET_EXTENSION; |
| 20972 | |
| 20973 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) || |
| 20974 | (elemDecl->subtypes->flags & |
| 20975 | XML_SCHEMAS_TYPE_BLOCK_RESTRICTION)) |
| 20976 | set |= SUBSET_RESTRICTION; |
| 20977 | |
| 20978 | if (xmlSchemaCheckCOSDerivedOK(*localType, |
| 20979 | elemDecl->subtypes, set) != 0) { |
| 20980 | xmlChar *str = NULL; |
| 20981 | |
| 20982 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 20983 | XML_SCHEMAV_CVC_ELT_4_3, NULL, NULL, |
| 20984 | "The type definition '%s', specified by xsi:type, is " |
| 20985 | "blocked or not validly derived from the type definition " |
| 20986 | "of the element declaration", |
| 20987 | xmlSchemaFormatQName(&str, |
| 20988 | (*localType)->targetNamespace, |
| 20989 | (*localType)->name), |
| 20990 | NULL); |
| 20991 | FREE_AND_NULL(str); |
| 20992 | ret = vctxt->err; |
| 20993 | *localType = NULL; |
| 20994 | } |
| 20995 | } |
| 20996 | } |
| 20997 | exit: |
| 20998 | ACTIVATE_ELEM; |
| 20999 | return (ret); |
| 21000 | internal_error: |
| 21001 | ACTIVATE_ELEM; |
| 21002 | return (-1); |
| 21003 | } |
| 21004 | |
| 21005 | static int |
| 21006 | xmlSchemaValidateElemDecl(xmlSchemaValidCtxtPtr vctxt) |
| 21007 | { |
| 21008 | xmlSchemaElementPtr elemDecl = vctxt->inode->decl; |
| 21009 | xmlSchemaTypePtr actualType = ELEM_TYPE(elemDecl); |
| 21010 | |
| 21011 | /* |
| 21012 | * cvc-elt (3.3.4) : 1 |
| 21013 | */ |
| 21014 | if (elemDecl == NULL) { |
| 21015 | VERROR(XML_SCHEMAV_CVC_ELT_1, NULL, |
| 21016 | "No matching declaration available"); |
| 21017 | return (vctxt->err); |
| 21018 | } |
| 21019 | /* |
| 21020 | * cvc-elt (3.3.4) : 2 |
| 21021 | */ |
| 21022 | if (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT) { |
| 21023 | VERROR(XML_SCHEMAV_CVC_ELT_2, NULL, |
| 21024 | "The element declaration is abstract"); |
| 21025 | return (vctxt->err); |
| 21026 | } |
| 21027 | if (actualType == NULL) { |
| 21028 | VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL, |
| 21029 | "The type definition is absent"); |
| 21030 | return (XML_SCHEMAV_CVC_TYPE_1); |
| 21031 | } |
| 21032 | if (vctxt->nbAttrInfos != 0) { |
| 21033 | int ret; |
| 21034 | xmlSchemaAttrInfoPtr iattr; |
| 21035 | /* |
| 21036 | * cvc-elt (3.3.4) : 3 |
| 21037 | * Handle 'xsi:nil'. |
| 21038 | */ |
| 21039 | iattr = xmlSchemaGetMetaAttrInfo(vctxt, |
| 21040 | XML_SCHEMA_ATTR_INFO_META_XSI_NIL); |
| 21041 | if (iattr) { |
| 21042 | ACTIVATE_ATTRIBUTE(iattr); |
| 21043 | /* |
| 21044 | * Validate the value. |
| 21045 | */ |
| 21046 | ret = xmlSchemaVCheckCVCSimpleType( |
| 21047 | (xmlSchemaAbstractCtxtPtr) vctxt, NULL, |
| 21048 | xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN), |
| 21049 | iattr->value, &(iattr->val), 1, 0, 0); |
| 21050 | ACTIVATE_ELEM; |
| 21051 | if (ret < 0) { |
| 21052 | VERROR_INT("xmlSchemaValidateElemDecl", |
| 21053 | "calling xmlSchemaVCheckCVCSimpleType() to " |
| 21054 | "validate the attribute 'xsi:nil'"); |
| 21055 | return (-1); |
| 21056 | } |
| 21057 | if (ret == 0) { |
| 21058 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_NILLABLE) == 0) { |
| 21059 | /* |
| 21060 | * cvc-elt (3.3.4) : 3.1 |
| 21061 | */ |
| 21062 | VERROR(XML_SCHEMAV_CVC_ELT_3_1, NULL, |
| 21063 | "The element is not 'nillable'"); |
| 21064 | /* Does not return an error on purpose. */ |
| 21065 | } else { |
| 21066 | if (xmlSchemaValueGetAsBoolean(iattr->val)) { |
| 21067 | /* |
| 21068 | * cvc-elt (3.3.4) : 3.2.2 |
| 21069 | */ |
| 21070 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_FIXED) && |
| 21071 | (elemDecl->value != NULL)) { |
| 21072 | VERROR(XML_SCHEMAV_CVC_ELT_3_2_2, NULL, |
| 21073 | "The element cannot be 'nilled' because " |
| 21074 | "there is a fixed value constraint defined " |
| 21075 | "for it"); |
| 21076 | /* Does not return an error on purpose. */ |
| 21077 | } else |
| 21078 | vctxt->inode->flags |= |
| 21079 | XML_SCHEMA_ELEM_INFO_NILLED; |
| 21080 | } |
| 21081 | } |
| 21082 | } |
| 21083 | } |
| 21084 | /* |
| 21085 | * cvc-elt (3.3.4) : 4 |
| 21086 | * Handle 'xsi:type'. |
| 21087 | */ |
| 21088 | iattr = xmlSchemaGetMetaAttrInfo(vctxt, |
| 21089 | XML_SCHEMA_ATTR_INFO_META_XSI_TYPE); |
| 21090 | if (iattr) { |
| 21091 | xmlSchemaTypePtr localType = NULL; |
| 21092 | |
| 21093 | ret = xmlSchemaProcessXSIType(vctxt, iattr, &localType, |
| 21094 | elemDecl); |
| 21095 | if (ret != 0) { |
| 21096 | if (ret == -1) { |
| 21097 | VERROR_INT("xmlSchemaValidateElemDecl", |
| 21098 | "calling xmlSchemaProcessXSIType() to " |
| 21099 | "process the attribute 'xsi:type'"); |
| 21100 | return (-1); |
| 21101 | } |
| 21102 | /* Does not return an error on purpose. */ |
| 21103 | } |
| 21104 | if (localType != NULL) { |
| 21105 | vctxt->inode->flags |= XML_SCHEMA_ELEM_INFO_LOCAL_TYPE; |
| 21106 | actualType = localType; |
| 21107 | } |
| 21108 | } |
| 21109 | } |
| 21110 | /* |
| 21111 | * IDC: Register identity-constraint XPath matchers. |
| 21112 | */ |
| 21113 | if ((elemDecl->idcs != NULL) && |
| 21114 | (xmlSchemaIDCRegisterMatchers(vctxt, elemDecl) == -1)) |
| 21115 | return (-1); |
| 21116 | /* |
| 21117 | * No actual type definition. |
| 21118 | */ |
| 21119 | if (actualType == NULL) { |
| 21120 | VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL, |
| 21121 | "The type definition is absent"); |
| 21122 | return (XML_SCHEMAV_CVC_TYPE_1); |
| 21123 | } |
| 21124 | /* |
| 21125 | * Remember the actual type definition. |
| 21126 | */ |
| 21127 | vctxt->inode->typeDef = actualType; |
| 21128 | |
| 21129 | return (0); |
| 21130 | } |
| 21131 | |
| 21132 | static int |
| 21133 | xmlSchemaVAttributesSimple(xmlSchemaValidCtxtPtr vctxt) |
| 21134 | { |
| 21135 | xmlSchemaAttrInfoPtr iattr; |
| 21136 | int ret = 0, i; |
| 21137 | |
| 21138 | /* |
| 21139 | * SPEC cvc-type (3.1.1) |
| 21140 | * "The attributes of must be empty, excepting those whose namespace |
| 21141 | * name is identical to http://www.w3.org/2001/XMLSchema-instance and |
| 21142 | * whose local name is one of type, nil, schemaLocation or |
| 21143 | * noNamespaceSchemaLocation." |
| 21144 | */ |
| 21145 | if (vctxt->nbAttrInfos == 0) |
| 21146 | return (0); |
| 21147 | for (i = 0; i < vctxt->nbAttrInfos; i++) { |
| 21148 | iattr = vctxt->attrInfos[i]; |
| 21149 | if (! iattr->metaType) { |
| 21150 | ACTIVATE_ATTRIBUTE(iattr) |
| 21151 | xmlSchemaIllegalAttrErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 21152 | XML_SCHEMAV_CVC_TYPE_3_1_1, iattr, NULL); |
| 21153 | ret = XML_SCHEMAV_CVC_TYPE_3_1_1; |
| 21154 | } |
| 21155 | } |
| 21156 | ACTIVATE_ELEM |
| 21157 | return (ret); |
| 21158 | } |
| 21159 | |
| 21160 | /* |
| 21161 | * Cleanup currently used attribute infos. |
| 21162 | */ |
| 21163 | static void |
| 21164 | xmlSchemaClearAttrInfos(xmlSchemaValidCtxtPtr vctxt) |
| 21165 | { |
| 21166 | int i; |
| 21167 | xmlSchemaAttrInfoPtr attr; |
| 21168 | |
| 21169 | if (vctxt->nbAttrInfos == 0) |
| 21170 | return; |
| 21171 | for (i = 0; i < vctxt->nbAttrInfos; i++) { |
| 21172 | attr = vctxt->attrInfos[i]; |
| 21173 | if (attr->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES) { |
| 21174 | if (attr->localName != NULL) |
| 21175 | xmlFree((xmlChar *) attr->localName); |
| 21176 | if (attr->nsName != NULL) |
| 21177 | xmlFree((xmlChar *) attr->nsName); |
| 21178 | } |
| 21179 | if (attr->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) { |
| 21180 | if (attr->value != NULL) |
| 21181 | xmlFree((xmlChar *) attr->value); |
| 21182 | } |
| 21183 | if (attr->val != NULL) { |
| 21184 | xmlSchemaFreeValue(attr->val); |
| 21185 | attr->val = NULL; |
| 21186 | } |
| 21187 | memset(attr, 0, sizeof(xmlSchemaAttrInfo)); |
| 21188 | } |
| 21189 | vctxt->nbAttrInfos = 0; |
| 21190 | } |
| 21191 | |
| 21192 | /* |
| 21193 | * 3.4.4 Complex Type Definition Validation Rules |
| 21194 | * Element Locally Valid (Complex Type) (cvc-complex-type) |
| 21195 | * 3.2.4 Attribute Declaration Validation Rules |
| 21196 | * Validation Rule: Attribute Locally Valid (cvc-attribute) |
| 21197 | * Attribute Locally Valid (Use) (cvc-au) |
| 21198 | * |
| 21199 | * Only "assessed" attribute information items will be visible to |
| 21200 | * IDCs. I.e. not "lax" (without declaration) and "skip" wild attributes. |
| 21201 | */ |
| 21202 | static int |
| 21203 | xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt) |
| 21204 | { |
| 21205 | xmlSchemaTypePtr type = vctxt->inode->typeDef; |
| 21206 | xmlSchemaAttributeLinkPtr attrUseLink; |
| 21207 | xmlSchemaAttributePtr attrUse = NULL, attrDecl = NULL; |
| 21208 | xmlSchemaAttrInfoPtr attr, tmpAttr; |
| 21209 | int i, found, nbAttrs; |
| 21210 | int xpathRes = 0, res, wildIDs = 0, fixed; |
| 21211 | |
| 21212 | /* |
| 21213 | * SPEC (cvc-attribute) |
| 21214 | * (1) "The declaration must not be ·absent· (see Missing |
| 21215 | * Sub-components (§5.3) for how this can fail to be |
| 21216 | * the case)." |
| 21217 | * (2) "Its {type definition} must not be absent." |
| 21218 | * |
| 21219 | * NOTE (1) + (2): This is not handled here, since we currently do not |
| 21220 | * allow validation against schemas which have missing sub-components. |
| 21221 | * |
| 21222 | * SPEC (cvc-complex-type) |
| 21223 | * (3) "For each attribute information item in the element information |
| 21224 | * item's [attributes] excepting those whose [namespace name] is |
| 21225 | * identical to http://www.w3.org/2001/XMLSchema-instance and whose |
| 21226 | * [local name] is one of type, nil, schemaLocation or |
| 21227 | * noNamespaceSchemaLocation, the appropriate case among the following |
| 21228 | * must be true: |
| 21229 | * |
| 21230 | */ |
| 21231 | nbAttrs = vctxt->nbAttrInfos; |
| 21232 | for (attrUseLink = type->attributeUses; attrUseLink != NULL; |
| 21233 | attrUseLink = attrUseLink->next) { |
| 21234 | |
| 21235 | found = 0; |
| 21236 | attrUse = attrUseLink->attr; |
| 21237 | /* |
| 21238 | * VAL TODO: Implement a real "attribute use" component. |
| 21239 | */ |
| 21240 | if (attrUse->refDecl != NULL) |
| 21241 | attrDecl = attrUse->refDecl; |
| 21242 | else |
| 21243 | attrDecl = attrUse; |
| 21244 | for (i = 0; i < nbAttrs; i++) { |
| 21245 | attr = vctxt->attrInfos[i]; |
| 21246 | /* |
| 21247 | * SPEC (cvc-complex-type) (3) |
| 21248 | * Skip meta attributes. |
| 21249 | */ |
| 21250 | if (attr->metaType) |
| 21251 | continue; |
| 21252 | if (attr->localName[0] != attrDecl->name[0]) |
| 21253 | continue; |
| 21254 | if (!xmlStrEqual(attr->localName, attrDecl->name)) |
| 21255 | continue; |
| 21256 | if (!xmlStrEqual(attr->nsName, attrDecl->targetNamespace)) |
| 21257 | continue; |
| 21258 | found = 1; |
| 21259 | /* |
| 21260 | * SPEC (cvc-complex-type) |
| 21261 | * (3.1) "If there is among the {attribute uses} an attribute |
| 21262 | * use with an {attribute declaration} whose {name} matches |
| 21263 | * the attribute information item's [local name] and whose |
| 21264 | * {target namespace} is identical to the attribute information |
| 21265 | * item's [namespace name] (where an ·absent· {target namespace} |
| 21266 | * is taken to be identical to a [namespace name] with no value), |
| 21267 | * then the attribute information must be ·valid· with respect |
| 21268 | * to that attribute use as per Attribute Locally Valid (Use) |
| 21269 | * (§3.5.4). In this case the {attribute declaration} of that |
| 21270 | * attribute use is the ·context-determined declaration· for the |
| 21271 | * attribute information item with respect to Schema-Validity |
| 21272 | * Assessment (Attribute) (§3.2.4) and |
| 21273 | * Assessment Outcome (Attribute) (§3.2.5). |
| 21274 | */ |
| 21275 | attr->state = XML_SCHEMAS_ATTR_ASSESSED; |
| 21276 | attr->use = attrUse; |
| 21277 | /* |
| 21278 | * Context-determined declaration. |
| 21279 | */ |
| 21280 | attr->decl = attrDecl; |
| 21281 | attr->typeDef = attrDecl->subtypes; |
| 21282 | break; |
| 21283 | } |
| 21284 | |
| 21285 | if (found) |
| 21286 | continue; |
| 21287 | |
| 21288 | if (attrUse->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED) { |
| 21289 | /* |
| 21290 | * Handle non-existent, required attributes. |
| 21291 | * |
| 21292 | * SPEC (cvc-complex-type) |
| 21293 | * (4) "The {attribute declaration} of each attribute use in |
| 21294 | * the {attribute uses} whose {required} is true matches one |
| 21295 | * of the attribute information items in the element information |
| 21296 | * item's [attributes] as per clause 3.1 above." |
| 21297 | */ |
| 21298 | tmpAttr = xmlSchemaGetFreshAttrInfo(vctxt); |
| 21299 | if (tmpAttr == NULL) { |
| 21300 | VERROR_INT( |
| 21301 | "xmlSchemaVAttributesComplex", |
| 21302 | "calling xmlSchemaGetFreshAttrInfo()"); |
| 21303 | return (-1); |
| 21304 | } |
| 21305 | tmpAttr->state = XML_SCHEMAS_ATTR_ERR_MISSING; |
| 21306 | tmpAttr->use = attrUse; |
| 21307 | tmpAttr->decl = attrDecl; |
| 21308 | } else if ((attrUse->occurs == XML_SCHEMAS_ATTR_USE_OPTIONAL) && |
| 21309 | ((attrUse->defValue != NULL) || |
| 21310 | (attrDecl->defValue != NULL))) { |
| 21311 | /* |
| 21312 | * Handle non-existent, optional, default/fixed attributes. |
| 21313 | */ |
| 21314 | tmpAttr = xmlSchemaGetFreshAttrInfo(vctxt); |
| 21315 | if (tmpAttr == NULL) { |
| 21316 | VERROR_INT( |
| 21317 | "xmlSchemaVAttributesComplex", |
| 21318 | "calling xmlSchemaGetFreshAttrInfo()"); |
| 21319 | return (-1); |
| 21320 | } |
| 21321 | tmpAttr->state = XML_SCHEMAS_ATTR_DEFAULT; |
| 21322 | tmpAttr->use = attrUse; |
| 21323 | tmpAttr->decl = attrDecl; |
| 21324 | tmpAttr->typeDef = attrDecl->subtypes; |
| 21325 | tmpAttr->localName = attrDecl->name; |
| 21326 | tmpAttr->nsName = attrDecl->targetNamespace; |
| 21327 | } |
| 21328 | } |
| 21329 | if (vctxt->nbAttrInfos == 0) |
| 21330 | return (0); |
| 21331 | /* |
| 21332 | * Validate against the wildcard. |
| 21333 | */ |
| 21334 | if (type->attributeWildcard != NULL) { |
| 21335 | /* |
| 21336 | * SPEC (cvc-complex-type) |
| 21337 | * (3.2.1) "There must be an {attribute wildcard}." |
| 21338 | */ |
| 21339 | for (i = 0; i < nbAttrs; i++) { |
| 21340 | attr = vctxt->attrInfos[i]; |
| 21341 | /* |
| 21342 | * SPEC (cvc-complex-type) (3) |
| 21343 | * Skip meta attributes. |
| 21344 | */ |
| 21345 | if (attr->state != XML_SCHEMAS_ATTR_UNKNOWN) |
| 21346 | continue; |
| 21347 | /* |
| 21348 | * SPEC (cvc-complex-type) |
| 21349 | * (3.2.2) "The attribute information item must be ·valid· with |
| 21350 | * respect to it as defined in Item Valid (Wildcard) (§3.10.4)." |
| 21351 | * |
| 21352 | * SPEC Item Valid (Wildcard) (cvc-wildcard) |
| 21353 | * "... its [namespace name] must be ·valid· with respect to |
| 21354 | * the wildcard constraint, as defined in Wildcard allows |
| 21355 | * Namespace Name (§3.10.4)." |
| 21356 | */ |
| 21357 | if (xmlSchemaCheckCVCWildcardNamespace(type->attributeWildcard, |
| 21358 | attr->nsName)) { |
| 21359 | /* |
| 21360 | * Handle processContents. |
| 21361 | * |
| 21362 | * SPEC (cvc-wildcard): |
| 21363 | * processContents | context-determined declaration: |
| 21364 | * "strict" "mustFind" |
| 21365 | * "lax" "none" |
| 21366 | * "skip" "skip" |
| 21367 | */ |
| 21368 | if (type->attributeWildcard->processContents == |
| 21369 | XML_SCHEMAS_ANY_SKIP) { |
| 21370 | /* |
| 21371 | * context-determined declaration = "skip" |
| 21372 | * |
| 21373 | * SPEC PSVI Assessment Outcome (Attribute) |
| 21374 | * [validity] = "notKnown" |
| 21375 | * [validation attempted] = "none" |
| 21376 | */ |
| 21377 | attr->state = XML_SCHEMAS_ATTR_WILD_SKIP; |
| 21378 | continue; |
| 21379 | } |
| 21380 | /* |
| 21381 | * Find an attribute declaration. |
| 21382 | */ |
| 21383 | attr->decl = xmlSchemaGetAttributeDecl(vctxt->schema, |
| 21384 | attr->localName, attr->nsName); |
| 21385 | if (attr->decl != NULL) { |
| 21386 | attr->state = XML_SCHEMAS_ATTR_ASSESSED; |
| 21387 | /* |
| 21388 | * SPEC (cvc-complex-type) |
| 21389 | * (5) "Let [Definition:] the wild IDs be the set of |
| 21390 | * all attribute information item to which clause 3.2 |
| 21391 | * applied and whose ·validation· resulted in a |
| 21392 | * ·context-determined declaration· of mustFind or no |
| 21393 | * ·context-determined declaration· at all, and whose |
| 21394 | * [local name] and [namespace name] resolve (as |
| 21395 | * defined by QName resolution (Instance) (§3.15.4)) to |
| 21396 | * an attribute declaration whose {type definition} is |
| 21397 | * or is derived from ID. Then all of the following |
| 21398 | * must be true:" |
| 21399 | */ |
| 21400 | attr->typeDef = attr->decl->subtypes; |
| 21401 | if (xmlSchemaIsDerivedFromBuiltInType( |
| 21402 | attr->typeDef, XML_SCHEMAS_ID)) { |
| 21403 | /* |
| 21404 | * SPEC (5.1) "There must be no more than one |
| 21405 | * item in ·wild IDs·." |
| 21406 | */ |
| 21407 | if (wildIDs != 0) { |
| 21408 | /* VAL TODO */ |
| 21409 | attr->state = XML_SCHEMAS_ATTR_ERR_WILD_DUPLICATE_ID; |
| 21410 | TODO |
| 21411 | continue; |
| 21412 | } |
| 21413 | wildIDs++; |
| 21414 | /* |
| 21415 | * SPEC (cvc-complex-type) |
| 21416 | * (5.2) "If ·wild IDs· is non-empty, there must not |
| 21417 | * be any attribute uses among the {attribute uses} |
| 21418 | * whose {attribute declaration}'s {type definition} |
| 21419 | * is or is derived from ID." |
| 21420 | */ |
| 21421 | for (attrUseLink = type->attributeUses; |
| 21422 | attrUseLink != NULL; |
| 21423 | attrUseLink = attrUseLink->next) { |
| 21424 | if (xmlSchemaIsDerivedFromBuiltInType( |
| 21425 | attrUseLink->attr->subtypes, |
| 21426 | XML_SCHEMAS_ID)) { |
| 21427 | /* VAL TODO */ |
| 21428 | attr->state = XML_SCHEMAS_ATTR_ERR_WILD_AND_USE_ID; |
| 21429 | TODO |
| 21430 | } |
| 21431 | } |
| 21432 | } |
| 21433 | } else if (type->attributeWildcard->processContents == |
| 21434 | XML_SCHEMAS_ANY_LAX) { |
| 21435 | attr->state = XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL; |
| 21436 | /* |
| 21437 | * SPEC PSVI Assessment Outcome (Attribute) |
| 21438 | * [validity] = "notKnown" |
| 21439 | * [validation attempted] = "none" |
| 21440 | */ |
| 21441 | } else { |
| 21442 | attr->state = XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL; |
| 21443 | } |
| 21444 | } |
| 21445 | } |
| 21446 | } |
| 21447 | |
| 21448 | |
| 21449 | if (vctxt->nbAttrInfos == 0) |
| 21450 | return (0); |
| 21451 | |
| 21452 | /* |
| 21453 | * Validate values, create default attributes, evaluate IDCs. |
| 21454 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 21455 | for (i = 0; i < vctxt->nbAttrInfos; i++) { |
| 21456 | attr = vctxt->attrInfos[i]; |
| 21457 | /* |
| 21458 | * VAL TODO: Note that we won't try to resolve IDCs to |
| 21459 | * "lax" and "skip" validated attributes. Check what to |
| 21460 | * do in this case. |
| 21461 | */ |
| 21462 | if ((attr->state != XML_SCHEMAS_ATTR_ASSESSED) && |
| 21463 | (attr->state != XML_SCHEMAS_ATTR_DEFAULT)) |
| 21464 | continue; |
| 21465 | /* |
| 21466 | * VAL TODO: What to do if the type definition is missing? |
| 21467 | */ |
| 21468 | if (attr->typeDef == NULL) { |
| 21469 | attr->state = XML_SCHEMAS_ATTR_ERR_NO_TYPE; |
| 21470 | continue; |
| 21471 | } |
| 21472 | |
| 21473 | ACTIVATE_ATTRIBUTE(attr); |
Kasimier T. Buchcik | 828f654 | 2005-06-09 11:23:39 +0000 | [diff] [blame] | 21474 | fixed = 0; |
| 21475 | xpathRes = 0; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 21476 | |
| 21477 | if (vctxt->xpathStates != NULL) { |
| 21478 | /* |
| 21479 | * Evaluate IDCs. |
| 21480 | */ |
| 21481 | xpathRes = xmlSchemaXPathEvaluate(vctxt, |
| 21482 | XML_ATTRIBUTE_NODE); |
| 21483 | if (xpathRes == -1) { |
| 21484 | VERROR_INT("xmlSchemaVAttributesComplex", |
| 21485 | "calling xmlSchemaXPathEvaluate()"); |
| 21486 | goto internal_error; |
| 21487 | } |
| 21488 | } |
| 21489 | |
| 21490 | if (attr->state == XML_SCHEMAS_ATTR_DEFAULT) { |
| 21491 | /* |
| 21492 | * Default/fixed attributes. |
| 21493 | */ |
| 21494 | if (xpathRes) { |
| 21495 | if (attr->use->defValue == NULL) { |
| 21496 | attr->value = (xmlChar *) attr->use->defValue; |
| 21497 | attr->val = attr->use->defVal; |
| 21498 | } else { |
| 21499 | attr->value = (xmlChar *) attr->decl->defValue; |
| 21500 | attr->val = attr->decl->defVal; |
| 21501 | } |
| 21502 | /* |
| 21503 | * IDCs will consume the precomputed default value, |
| 21504 | * so we need to clone it. |
| 21505 | */ |
| 21506 | if (attr->val == NULL) { |
| 21507 | VERROR_INT("xmlSchemaVAttributesComplex", |
| 21508 | "default/fixed value on an attribute use was " |
| 21509 | "not precomputed"); |
| 21510 | goto internal_error; |
| 21511 | } |
| 21512 | attr->val = xmlSchemaCopyValue(attr->val); |
| 21513 | if (attr->val == NULL) { |
| 21514 | VERROR_INT("xmlSchemaVAttributesComplex", |
| 21515 | "calling xmlSchemaCopyValue()"); |
| 21516 | goto internal_error; |
| 21517 | } |
| 21518 | } |
| 21519 | /* |
| 21520 | * PSVI: Add the default attribute to the current element. |
| 21521 | * VAL TODO: Should we use the *normalized* value? This currently |
| 21522 | * uses the *initial* value. |
| 21523 | */ |
| 21524 | if ((vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) && |
| 21525 | (attr->node != NULL) && (attr->node->doc != NULL)) { |
| 21526 | xmlChar *normValue; |
| 21527 | const xmlChar *value; |
| 21528 | |
| 21529 | value = attr->value; |
| 21530 | /* |
| 21531 | * Normalize the value. |
| 21532 | */ |
| 21533 | normValue = xmlSchemaNormalizeValue(attr->typeDef, |
| 21534 | attr->value); |
| 21535 | if (normValue != NULL) |
| 21536 | value = BAD_CAST normValue; |
| 21537 | |
| 21538 | if (attr->nsName == NULL) { |
| 21539 | if (xmlNewProp(attr->node->parent, |
| 21540 | attr->localName, value) == NULL) { |
| 21541 | VERROR_INT("xmlSchemaVAttributesComplex", |
| 21542 | "callling xmlNewProp()"); |
| 21543 | if (normValue != NULL) |
| 21544 | xmlFree(normValue); |
| 21545 | goto internal_error; |
| 21546 | } |
| 21547 | } else { |
| 21548 | xmlNsPtr ns; |
| 21549 | |
| 21550 | ns = xmlSearchNsByHref(attr->node->doc, |
| 21551 | attr->node->parent, attr->nsName); |
| 21552 | if (ns == NULL) { |
| 21553 | xmlChar prefix[12]; |
| 21554 | int counter = 0; |
| 21555 | |
| 21556 | /* |
| 21557 | * Create a namespace declaration on the validation |
| 21558 | * root node if no namespace declaration is in scope. |
| 21559 | */ |
| 21560 | do { |
| 21561 | snprintf((char *) prefix, 12, "p%d", counter++); |
| 21562 | ns = xmlSearchNs(attr->node->doc, |
| 21563 | attr->node->parent, BAD_CAST prefix); |
| 21564 | if (counter > 1000) { |
| 21565 | VERROR_INT( |
| 21566 | "xmlSchemaVAttributesComplex", |
| 21567 | "could not compute a ns prefix for a " |
| 21568 | "default/fixed attribute"); |
| 21569 | if (normValue != NULL) |
| 21570 | xmlFree(normValue); |
| 21571 | goto internal_error; |
| 21572 | } |
| 21573 | } while (ns != NULL); |
| 21574 | ns = xmlNewNs(vctxt->validationRoot, |
| 21575 | attr->nsName, BAD_CAST prefix); |
| 21576 | } |
| 21577 | xmlNewNsProp(attr->node->parent, ns, |
| 21578 | attr->localName, value); |
| 21579 | } |
| 21580 | if (normValue != NULL) |
| 21581 | xmlFree(normValue); |
| 21582 | } |
| 21583 | /* |
| 21584 | * Go directly to IDC evaluation. |
| 21585 | */ |
| 21586 | goto eval_idcs; |
| 21587 | } |
| 21588 | /* |
| 21589 | * Validate the value. |
| 21590 | */ |
| 21591 | if (vctxt->value != NULL) { |
| 21592 | /* |
| 21593 | * Free last computed value; just for safety reasons. |
| 21594 | */ |
| 21595 | xmlSchemaFreeValue(vctxt->value); |
| 21596 | vctxt->value = NULL; |
| 21597 | } |
| 21598 | /* |
| 21599 | * Note that the attribute *use* can be unavailable, if |
| 21600 | * the attribute was a wild attribute. |
| 21601 | */ |
| 21602 | if ((attr->decl->flags & XML_SCHEMAS_ATTR_FIXED) || |
| 21603 | ((attr->use != NULL) && |
| 21604 | (attr->use->flags & XML_SCHEMAS_ATTR_FIXED))) |
| 21605 | fixed = 1; |
| 21606 | else |
| 21607 | fixed = 0; |
| 21608 | /* |
| 21609 | * SPEC (cvc-attribute) |
| 21610 | * (3) "The item's ·normalized value· must be locally ·valid· |
| 21611 | * with respect to that {type definition} as per |
| 21612 | * String Valid (§3.14.4)." |
| 21613 | * |
| 21614 | * VAL TODO: Do we already have the |
| 21615 | * "normalized attribute value" here? |
| 21616 | */ |
| 21617 | if (xpathRes || fixed) { |
| 21618 | attr->flags |= XML_SCHEMA_NODE_INFO_VALUE_NEEDED; |
| 21619 | /* |
| 21620 | * Request a computed value. |
| 21621 | */ |
| 21622 | res = xmlSchemaVCheckCVCSimpleType( |
| 21623 | (xmlSchemaAbstractCtxtPtr) vctxt, |
| 21624 | attr->node, attr->typeDef, attr->value, &(attr->val), |
| 21625 | 1, 1, 0); |
| 21626 | } else { |
| 21627 | res = xmlSchemaVCheckCVCSimpleType( |
| 21628 | (xmlSchemaAbstractCtxtPtr) vctxt, |
| 21629 | attr->node, attr->typeDef, attr->value, NULL, |
| 21630 | 1, 0, 0); |
| 21631 | } |
| 21632 | |
| 21633 | if (res != 0) { |
| 21634 | if (res == -1) { |
| 21635 | VERROR_INT("xmlSchemaVAttributesComplex", |
| 21636 | "calling xmlSchemaStreamValidateSimpleTypeValue()"); |
| 21637 | goto internal_error; |
| 21638 | } |
| 21639 | attr->state = XML_SCHEMAS_ATTR_INVALID_VALUE; |
| 21640 | /* |
| 21641 | * SPEC PSVI Assessment Outcome (Attribute) |
| 21642 | * [validity] = "invalid" |
| 21643 | */ |
| 21644 | goto eval_idcs; |
| 21645 | } |
| 21646 | |
| 21647 | if (fixed) { |
| 21648 | int ws; |
| 21649 | /* |
| 21650 | * SPEC Attribute Locally Valid (Use) (cvc-au) |
| 21651 | * "For an attribute information item to be·valid· |
| 21652 | * with respect to an attribute use its *normalized* |
| 21653 | * value· must match the *canonical* lexical |
| 21654 | * representation of the attribute use's {value |
| 21655 | * constraint}value, if it is present and fixed." |
| 21656 | * |
| 21657 | * VAL TODO: The requirement for the *canonical* value |
| 21658 | * will be removed in XML Schema 1.1. |
| 21659 | */ |
| 21660 | /* |
| 21661 | * SPEC Attribute Locally Valid (cvc-attribute) |
| 21662 | * (4) "The item's *actual* value· must match the *value* of |
| 21663 | * the {value constraint}, if it is present and fixed." |
| 21664 | */ |
| 21665 | ws = xmlSchemaGetWhiteSpaceFacetValue(attr->typeDef); |
| 21666 | if (attr->val == NULL) { |
| 21667 | /* VAL TODO: A value was not precomputed. */ |
| 21668 | TODO |
| 21669 | goto eval_idcs; |
| 21670 | } |
| 21671 | if ((attr->use != NULL) && |
| 21672 | (attr->use->defValue != NULL)) { |
| 21673 | if (attr->use->defVal == NULL) { |
| 21674 | /* VAL TODO: A default value was not precomputed. */ |
| 21675 | TODO |
| 21676 | goto eval_idcs; |
| 21677 | } |
| 21678 | attr->vcValue = attr->use->defValue; |
| 21679 | /* |
| 21680 | if (xmlSchemaCompareValuesWhtsp(attr->val, |
| 21681 | (xmlSchemaWhitespaceValueType) ws, |
| 21682 | attr->use->defVal, |
| 21683 | (xmlSchemaWhitespaceValueType) ws) != 0) { |
| 21684 | */ |
| 21685 | if (! xmlSchemaAreValuesEqual(attr->val, attr->use->defVal)) |
| 21686 | attr->state = XML_SCHEMAS_ATTR_ERR_FIXED_VALUE; |
| 21687 | } else { |
Kasimier T. Buchcik | 828f654 | 2005-06-09 11:23:39 +0000 | [diff] [blame] | 21688 | if (attr->decl->defVal == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 21689 | /* VAL TODO: A default value was not precomputed. */ |
| 21690 | TODO |
| 21691 | goto eval_idcs; |
| 21692 | } |
Kasimier T. Buchcik | 828f654 | 2005-06-09 11:23:39 +0000 | [diff] [blame] | 21693 | attr->vcValue = attr->decl->defValue; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 21694 | /* |
| 21695 | if (xmlSchemaCompareValuesWhtsp(attr->val, |
| 21696 | (xmlSchemaWhitespaceValueType) ws, |
| 21697 | attrDecl->defVal, |
| 21698 | (xmlSchemaWhitespaceValueType) ws) != 0) { |
| 21699 | */ |
Kasimier T. Buchcik | 828f654 | 2005-06-09 11:23:39 +0000 | [diff] [blame] | 21700 | if (! xmlSchemaAreValuesEqual(attr->val, attr->decl->defVal)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 21701 | attr->state = XML_SCHEMAS_ATTR_ERR_FIXED_VALUE; |
| 21702 | } |
| 21703 | /* |
| 21704 | * [validity] = "valid" |
| 21705 | */ |
| 21706 | } |
| 21707 | eval_idcs: |
| 21708 | /* |
| 21709 | * Evaluate IDCs. |
| 21710 | */ |
| 21711 | if (xpathRes) { |
| 21712 | if (xmlSchemaXPathProcessHistory(vctxt, |
| 21713 | vctxt->depth +1) == -1) { |
| 21714 | VERROR_INT("xmlSchemaVAttributesComplex", |
| 21715 | "calling xmlSchemaXPathEvaluate()"); |
| 21716 | goto internal_error; |
| 21717 | } |
| 21718 | } |
| 21719 | } |
| 21720 | |
| 21721 | /* |
| 21722 | * Report errors. |
| 21723 | */ |
| 21724 | for (i = 0; i < vctxt->nbAttrInfos; i++) { |
| 21725 | attr = vctxt->attrInfos[i]; |
| 21726 | if ((attr->state == XML_SCHEMAS_ATTR_META) || |
| 21727 | (attr->state == XML_SCHEMAS_ATTR_ASSESSED) || |
| 21728 | (attr->state == XML_SCHEMAS_ATTR_WILD_SKIP) || |
| 21729 | (attr->state == XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL)) |
| 21730 | continue; |
| 21731 | ACTIVATE_ATTRIBUTE(attr); |
| 21732 | switch (attr->state) { |
| 21733 | case XML_SCHEMAS_ATTR_ERR_MISSING: { |
| 21734 | xmlChar *str = NULL; |
| 21735 | ACTIVATE_ELEM; |
| 21736 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 21737 | XML_SCHEMAV_CVC_COMPLEX_TYPE_4, NULL, NULL, |
| 21738 | "The attribute '%s' is required but missing", |
| 21739 | xmlSchemaFormatQName(&str, |
| 21740 | attr->decl->targetNamespace, |
| 21741 | attr->decl->name), |
| 21742 | NULL); |
| 21743 | FREE_AND_NULL(str) |
| 21744 | break; |
| 21745 | } |
| 21746 | case XML_SCHEMAS_ATTR_ERR_NO_TYPE: |
| 21747 | VERROR(XML_SCHEMAV_CVC_ATTRIBUTE_2, NULL, |
| 21748 | "The type definition is absent"); |
| 21749 | break; |
| 21750 | case XML_SCHEMAS_ATTR_ERR_FIXED_VALUE: |
| 21751 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 21752 | XML_SCHEMAV_CVC_AU, NULL, NULL, |
| 21753 | "The value '%s' does not match the fixed " |
| 21754 | "value constraint '%s'", |
| 21755 | attr->value, attr->vcValue); |
| 21756 | break; |
| 21757 | case XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL: |
| 21758 | VERROR(XML_SCHEMAV_CVC_WILDCARD, NULL, |
| 21759 | "No matching global attribute declaration available, but " |
| 21760 | "demanded by the strict wildcard"); |
| 21761 | break; |
| 21762 | case XML_SCHEMAS_ATTR_UNKNOWN: |
| 21763 | if (attr->metaType) |
| 21764 | break; |
| 21765 | /* |
| 21766 | * MAYBE VAL TODO: One might report different error messages |
| 21767 | * for the following errors. |
| 21768 | */ |
| 21769 | if (type->attributeWildcard == NULL) { |
| 21770 | xmlSchemaIllegalAttrErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 21771 | XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_1, attr, NULL); |
| 21772 | } else { |
| 21773 | xmlSchemaIllegalAttrErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 21774 | XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_2, attr, NULL); |
| 21775 | } |
| 21776 | break; |
| 21777 | default: |
| 21778 | break; |
| 21779 | } |
| 21780 | } |
| 21781 | |
| 21782 | ACTIVATE_ELEM; |
| 21783 | return (0); |
| 21784 | internal_error: |
| 21785 | ACTIVATE_ELEM; |
| 21786 | return (-1); |
| 21787 | } |
| 21788 | |
| 21789 | static int |
| 21790 | xmlSchemaValidateElemWildcard(xmlSchemaValidCtxtPtr vctxt, |
| 21791 | int *skip) |
| 21792 | { |
| 21793 | xmlSchemaWildcardPtr wild = (xmlSchemaWildcardPtr) vctxt->inode->decl; |
| 21794 | /* |
| 21795 | * The namespace of the element was already identified to be |
| 21796 | * matching the wildcard. |
| 21797 | */ |
| 21798 | if ((skip == NULL) || (wild == NULL) || |
| 21799 | (wild->type != XML_SCHEMA_TYPE_ANY)) { |
| 21800 | VERROR_INT("xmlSchemaValidateElemWildcard", |
| 21801 | "bad arguments"); |
| 21802 | return (-1); |
| 21803 | } |
| 21804 | *skip = 0; |
| 21805 | if (wild->negNsSet != NULL) { |
| 21806 | /* |
| 21807 | * URGENT VAL TODO: Fix the content model to reject |
| 21808 | * "##other" wildcards. |
| 21809 | */ |
| 21810 | if (xmlSchemaCheckCVCWildcardNamespace(wild, |
| 21811 | vctxt->inode->nsName) != 0) { |
| 21812 | if ((wild->minOccurs == 1) && (wild->maxOccurs == 1)) { |
| 21813 | xmlSchemaNodeInfoPtr pinode = vctxt->elemInfos[vctxt->depth -1]; |
| 21814 | /* |
| 21815 | * VAL TODO: Workaround possible *only* if minOccurs and |
| 21816 | * maxOccurs are 1. |
| 21817 | */ |
| 21818 | xmlSchemaComplexTypeErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 21819 | /* VAL TODO: error code? */ |
| 21820 | XML_SCHEMAV_ELEMENT_CONTENT, NULL, |
| 21821 | (xmlSchemaTypePtr) wild, |
| 21822 | "This element is not accepted by the wildcard", |
| 21823 | 0, 0, NULL); |
| 21824 | vctxt->skipDepth = vctxt->depth; |
| 21825 | if ((pinode->flags & |
| 21826 | XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT) == 0) |
| 21827 | pinode->flags |= XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT; |
| 21828 | vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED; |
| 21829 | return (XML_SCHEMAV_ELEMENT_CONTENT); |
| 21830 | } |
| 21831 | if (wild->processContents == XML_SCHEMAS_ANY_SKIP) { |
| 21832 | *skip = 1; |
| 21833 | return (0); |
| 21834 | } |
| 21835 | vctxt->inode->typeDef = |
| 21836 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 21837 | return (0); |
| 21838 | } |
| 21839 | } |
| 21840 | if (wild->processContents == XML_SCHEMAS_ANY_SKIP) { |
| 21841 | /* |
| 21842 | * URGENT VAL TODO: Either we need to position the stream to the |
| 21843 | * next sibling, or walk the whole subtree. |
| 21844 | */ |
| 21845 | *skip = 1; |
| 21846 | return (0); |
| 21847 | } |
| 21848 | { |
| 21849 | xmlSchemaElementPtr decl = NULL; |
| 21850 | |
| 21851 | decl = xmlHashLookup3(vctxt->schema->elemDecl, |
| 21852 | vctxt->inode->localName, vctxt->inode->nsName, |
| 21853 | NULL); |
| 21854 | if (decl != NULL) { |
| 21855 | vctxt->inode->decl = decl; |
| 21856 | return (0); |
| 21857 | } |
| 21858 | } |
| 21859 | if (wild->processContents == XML_SCHEMAS_ANY_STRICT) { |
| 21860 | /* VAL TODO: Change to proper error code. */ |
| 21861 | VERROR(XML_SCHEMAV_CVC_ELT_1, (xmlSchemaTypePtr) wild, |
| 21862 | "No matching global element declaration available, but " |
| 21863 | "demanded by the strict wildcard"); |
| 21864 | return (vctxt->err); |
| 21865 | } |
| 21866 | if (vctxt->nbAttrInfos != 0) { |
| 21867 | xmlSchemaAttrInfoPtr iattr; |
| 21868 | /* |
| 21869 | * SPEC Validation Rule: Schema-Validity Assessment (Element) |
| 21870 | * (1.2.1.2.1) - (1.2.1.2.3 ) |
| 21871 | * |
| 21872 | * Use the xsi:type attribute for the type definition. |
| 21873 | */ |
| 21874 | iattr = xmlSchemaGetMetaAttrInfo(vctxt, |
| 21875 | XML_SCHEMA_ATTR_INFO_META_XSI_TYPE); |
| 21876 | if (iattr != NULL) { |
| 21877 | if (xmlSchemaProcessXSIType(vctxt, iattr, |
| 21878 | &(vctxt->inode->typeDef), NULL) == -1) { |
| 21879 | VERROR_INT("xmlSchemaValidateElemWildcard", |
| 21880 | "calling xmlSchemaProcessXSIType() to " |
| 21881 | "process the attribute 'xsi:nil'"); |
| 21882 | return (-1); |
| 21883 | } |
| 21884 | /* |
| 21885 | * Don't return an error on purpose. |
| 21886 | */ |
| 21887 | return (0); |
| 21888 | } |
| 21889 | } |
| 21890 | /* |
| 21891 | * SPEC Validation Rule: Schema-Validity Assessment (Element) |
| 21892 | * |
| 21893 | * Fallback to "anyType". |
| 21894 | */ |
| 21895 | vctxt->inode->typeDef = |
| 21896 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 21897 | return (0); |
| 21898 | } |
| 21899 | |
| 21900 | /* |
| 21901 | * xmlSchemaCheckCOSValidDefault: |
| 21902 | * |
| 21903 | * This will be called if: not nilled, no content and a default/fixed |
| 21904 | * value is provided. |
| 21905 | */ |
| 21906 | |
| 21907 | static int |
| 21908 | xmlSchemaCheckCOSValidDefault(xmlSchemaValidCtxtPtr vctxt, |
| 21909 | const xmlChar *value, |
| 21910 | xmlSchemaValPtr *val) |
| 21911 | { |
| 21912 | int ret = 0; |
| 21913 | xmlSchemaNodeInfoPtr inode = vctxt->inode; |
| 21914 | |
| 21915 | /* |
| 21916 | * cos-valid-default: |
| 21917 | * Schema Component Constraint: Element Default Valid (Immediate) |
| 21918 | * For a string to be a valid default with respect to a type |
| 21919 | * definition the appropriate case among the following must be true: |
| 21920 | */ |
| 21921 | if IS_COMPLEX_TYPE(inode->typeDef) { |
| 21922 | /* |
| 21923 | * Complex type. |
| 21924 | * |
| 21925 | * SPEC (2.1) "its {content type} must be a simple type definition |
| 21926 | * or mixed." |
| 21927 | * SPEC (2.2.2) "If the {content type} is mixed, then the {content |
| 21928 | * type}'s particle must be ·emptiable· as defined by |
| 21929 | * Particle Emptiable (§3.9.6)." |
| 21930 | */ |
| 21931 | if ((! HAS_SIMPLE_CONTENT(inode->typeDef)) && |
| 21932 | ((! HAS_MIXED_CONTENT(inode->typeDef)) || |
| 21933 | (! IS_PARTICLE_EMPTIABLE(inode->typeDef)))) { |
| 21934 | ret = XML_SCHEMAP_COS_VALID_DEFAULT_2_1; |
| 21935 | /* NOTE that this covers (2.2.2) as well. */ |
| 21936 | VERROR(ret, NULL, |
| 21937 | "For a string to be a valid default, the type definition " |
| 21938 | "must be a simple type or a complex type with simple content " |
| 21939 | "or mixed content and a particle emptiable"); |
| 21940 | return(ret); |
| 21941 | } |
| 21942 | } |
| 21943 | /* |
| 21944 | * 1 If the type definition is a simple type definition, then the string |
| 21945 | * must be ·valid· with respect to that definition as defined by String |
| 21946 | * Valid (§3.14.4). |
| 21947 | * |
| 21948 | * AND |
| 21949 | * |
| 21950 | * 2.2.1 If the {content type} is a simple type definition, then the |
| 21951 | * string must be ·valid· with respect to that simple type definition |
| 21952 | * as defined by String Valid (§3.14.4). |
| 21953 | */ |
| 21954 | if (IS_SIMPLE_TYPE(inode->typeDef)) { |
| 21955 | |
| 21956 | ret = xmlSchemaVCheckCVCSimpleType((xmlSchemaAbstractCtxtPtr) vctxt, |
| 21957 | NULL, inode->typeDef, value, val, 1, 1, 0); |
| 21958 | |
| 21959 | } else if (HAS_SIMPLE_CONTENT(inode->typeDef)) { |
| 21960 | |
| 21961 | ret = xmlSchemaVCheckCVCSimpleType((xmlSchemaAbstractCtxtPtr) vctxt, |
| 21962 | NULL, inode->typeDef->contentTypeDef, value, val, 1, 1, 0); |
| 21963 | } |
| 21964 | if (ret < 0) { |
| 21965 | VERROR_INT("xmlSchemaCheckCOSValidDefault", |
| 21966 | "calling xmlSchemaVCheckCVCSimpleType()"); |
| 21967 | } |
| 21968 | return (ret); |
| 21969 | } |
| 21970 | |
| 21971 | static void |
| 21972 | xmlSchemaVContentModelCallback(xmlSchemaValidCtxtPtr vctxt ATTRIBUTE_UNUSED, |
| 21973 | const xmlChar * name ATTRIBUTE_UNUSED, |
| 21974 | xmlSchemaElementPtr item, |
| 21975 | xmlSchemaNodeInfoPtr inode) |
| 21976 | { |
| 21977 | inode->decl = item; |
| 21978 | #ifdef DEBUG_CONTENT |
| 21979 | { |
| 21980 | xmlChar *str = NULL; |
| 21981 | |
| 21982 | if (item->type == XML_SCHEMA_TYPE_ELEMENT) { |
| 21983 | xmlGenericError(xmlGenericErrorContext, |
| 21984 | "AUTOMATON callback for '%s' [declaration]\n", |
| 21985 | xmlSchemaFormatQName(&str, |
| 21986 | inode->localName, inode->nsName)); |
| 21987 | } else { |
| 21988 | xmlGenericError(xmlGenericErrorContext, |
| 21989 | "AUTOMATON callback for '%s' [wildcard]\n", |
| 21990 | xmlSchemaFormatQName(&str, |
| 21991 | inode->localName, inode->nsName)); |
| 21992 | |
| 21993 | } |
| 21994 | FREE_AND_NULL(str) |
| 21995 | } |
| 21996 | #endif |
| 21997 | } |
| 21998 | |
| 21999 | static int |
| 22000 | xmlSchemaValidatorPushElem(xmlSchemaValidCtxtPtr vctxt) |
Kasimier T. Buchcik | 84a56e3 | 2005-06-16 12:44:35 +0000 | [diff] [blame] | 22001 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22002 | vctxt->inode = xmlSchemaGetFreshElemInfo(vctxt); |
| 22003 | if (vctxt->inode == NULL) { |
| 22004 | VERROR_INT("xmlSchemaValidatorPushElem", |
| 22005 | "calling xmlSchemaGetFreshElemInfo()"); |
| 22006 | return (-1); |
| 22007 | } |
| 22008 | vctxt->nbAttrInfos = 0; |
| 22009 | return (0); |
| 22010 | } |
| 22011 | |
| 22012 | static int |
| 22013 | xmlSchemaVCheckINodeDataType(xmlSchemaValidCtxtPtr vctxt, |
| 22014 | xmlSchemaNodeInfoPtr inode, |
| 22015 | xmlSchemaTypePtr type, |
| 22016 | const xmlChar *value) |
| 22017 | { |
| 22018 | if (inode->flags & XML_SCHEMA_NODE_INFO_VALUE_NEEDED) |
| 22019 | return (xmlSchemaVCheckCVCSimpleType( |
| 22020 | (xmlSchemaAbstractCtxtPtr) vctxt, NULL, |
| 22021 | type, value, &(inode->val), 1, 1, 0)); |
| 22022 | else |
| 22023 | return (xmlSchemaVCheckCVCSimpleType( |
| 22024 | (xmlSchemaAbstractCtxtPtr) vctxt, NULL, |
| 22025 | type, value, NULL, 1, 0, 0)); |
| 22026 | } |
| 22027 | |
| 22028 | |
| 22029 | |
| 22030 | /* |
| 22031 | * Process END of element. |
| 22032 | */ |
| 22033 | static int |
| 22034 | xmlSchemaValidatorPopElem(xmlSchemaValidCtxtPtr vctxt) |
| 22035 | { |
| 22036 | int ret = 0; |
| 22037 | xmlSchemaNodeInfoPtr inode = vctxt->inode; |
| 22038 | |
| 22039 | if (vctxt->nbAttrInfos != 0) |
| 22040 | xmlSchemaClearAttrInfos(vctxt); |
| 22041 | if (inode->flags & XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED) { |
| 22042 | /* |
| 22043 | * This element was not expected; |
| 22044 | * we will not validate child elements of broken parents. |
| 22045 | * Skip validation of all content of the parent. |
| 22046 | */ |
| 22047 | vctxt->skipDepth = vctxt->depth -1; |
| 22048 | goto end_elem; |
| 22049 | } |
| 22050 | if ((inode->typeDef == NULL) || |
| 22051 | (inode->flags & XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE)) { |
| 22052 | /* |
Kasimier T. Buchcik | 84a56e3 | 2005-06-16 12:44:35 +0000 | [diff] [blame] | 22053 | * 1. the type definition might be missing if the element was |
| 22054 | * error prone |
| 22055 | * 2. it might be abstract. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22056 | */ |
| 22057 | goto end_elem; |
| 22058 | } |
| 22059 | /* |
| 22060 | * Check the content model. |
| 22061 | */ |
| 22062 | if ((inode->typeDef->contentType == XML_SCHEMA_CONTENT_MIXED) || |
| 22063 | (inode->typeDef->contentType == XML_SCHEMA_CONTENT_ELEMENTS)) { |
| 22064 | |
| 22065 | /* |
| 22066 | * Workaround for "anyType". |
| 22067 | */ |
| 22068 | if (inode->typeDef->builtInType == XML_SCHEMAS_ANYTYPE) |
| 22069 | goto character_content; |
| 22070 | |
| 22071 | if ((inode->flags & XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT) == 0) { |
| 22072 | xmlChar *values[10]; |
| 22073 | int terminal, nbval = 10, nbneg; |
| 22074 | |
| 22075 | if (inode->regexCtxt == NULL) { |
| 22076 | /* |
| 22077 | * Create the regex context. |
| 22078 | */ |
| 22079 | inode->regexCtxt = |
| 22080 | xmlRegNewExecCtxt(inode->typeDef->contModel, |
| 22081 | (xmlRegExecCallbacks) xmlSchemaVContentModelCallback, |
| 22082 | vctxt); |
| 22083 | if (inode->regexCtxt == NULL) { |
| 22084 | VERROR_INT("xmlSchemaValidatorPopElem", |
| 22085 | "failed to create a regex context"); |
| 22086 | goto internal_error; |
| 22087 | } |
| 22088 | #ifdef DEBUG_AUTOMATA |
| 22089 | xmlGenericError(xmlGenericErrorContext, |
| 22090 | "AUTOMATON create on '%s'\n", inode->localName); |
| 22091 | #endif |
| 22092 | } |
| 22093 | /* |
| 22094 | * Get hold of the still expected content, since a further |
| 22095 | * call to xmlRegExecPushString() will loose this information. |
| 22096 | */ |
| 22097 | xmlRegExecNextValues(inode->regexCtxt, |
| 22098 | &nbval, &nbneg, &values[0], &terminal); |
| 22099 | ret = xmlRegExecPushString(inode->regexCtxt, NULL, NULL); |
| 22100 | if (ret <= 0) { |
| 22101 | /* |
| 22102 | * Still missing something. |
| 22103 | */ |
| 22104 | ret = 1; |
| 22105 | inode->flags |= |
| 22106 | XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT; |
| 22107 | xmlSchemaComplexTypeErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 22108 | XML_SCHEMAV_ELEMENT_CONTENT, NULL, NULL, |
| 22109 | "Missing child element(s)", |
| 22110 | nbval, nbneg, values); |
| 22111 | #ifdef DEBUG_AUTOMATA |
| 22112 | xmlGenericError(xmlGenericErrorContext, |
| 22113 | "AUTOMATON missing ERROR on '%s'\n", |
| 22114 | inode->localName); |
| 22115 | #endif |
| 22116 | } else { |
| 22117 | /* |
| 22118 | * Content model is satisfied. |
| 22119 | */ |
| 22120 | ret = 0; |
| 22121 | #ifdef DEBUG_AUTOMATA |
| 22122 | xmlGenericError(xmlGenericErrorContext, |
| 22123 | "AUTOMATON succeeded on '%s'\n", |
| 22124 | inode->localName); |
| 22125 | #endif |
| 22126 | } |
| 22127 | |
| 22128 | } |
| 22129 | } |
| 22130 | if (inode->typeDef->contentType == XML_SCHEMA_CONTENT_ELEMENTS) |
| 22131 | goto end_elem; |
| 22132 | |
| 22133 | character_content: |
| 22134 | |
| 22135 | if (vctxt->value != NULL) { |
| 22136 | xmlSchemaFreeValue(vctxt->value); |
| 22137 | vctxt->value = NULL; |
| 22138 | } |
| 22139 | /* |
| 22140 | * Check character content. |
| 22141 | */ |
| 22142 | if (inode->decl == NULL) { |
| 22143 | /* |
| 22144 | * Speedup if no declaration exists. |
| 22145 | */ |
| 22146 | if (IS_SIMPLE_TYPE(inode->typeDef)) { |
| 22147 | ret = xmlSchemaVCheckINodeDataType(vctxt, |
| 22148 | inode, inode->typeDef, inode->value); |
| 22149 | } else if (HAS_SIMPLE_CONTENT(inode->typeDef)) { |
| 22150 | ret = xmlSchemaVCheckINodeDataType(vctxt, |
| 22151 | inode, inode->typeDef->contentTypeDef, |
| 22152 | inode->value); |
| 22153 | } |
| 22154 | if (ret < 0) { |
| 22155 | VERROR_INT("xmlSchemaValidatorPopElem", |
| 22156 | "calling xmlSchemaVCheckCVCSimpleType()"); |
| 22157 | goto internal_error; |
| 22158 | } |
| 22159 | goto end_elem; |
| 22160 | } |
| 22161 | /* |
| 22162 | * cvc-elt (3.3.4) : 5 |
| 22163 | * The appropriate case among the following must be true: |
| 22164 | */ |
| 22165 | /* |
| 22166 | * cvc-elt (3.3.4) : 5.1 |
| 22167 | * If the declaration has a {value constraint}, |
| 22168 | * the item has neither element nor character [children] and |
| 22169 | * clause 3.2 has not applied, then all of the following must be true: |
| 22170 | */ |
| 22171 | if ((inode->decl->value != NULL) && |
| 22172 | (inode->flags & XML_SCHEMA_ELEM_INFO_EMPTY) && |
| 22173 | (! INODE_NILLED(inode))) { |
| 22174 | /* |
| 22175 | * cvc-elt (3.3.4) : 5.1.1 |
| 22176 | * If the ·actual type definition· is a ·local type definition· |
| 22177 | * then the canonical lexical representation of the {value constraint} |
| 22178 | * value must be a valid default for the ·actual type definition· as |
| 22179 | * defined in Element Default Valid (Immediate) (§3.3.6). |
| 22180 | */ |
| 22181 | /* |
| 22182 | * NOTE: 'local' above means types aquired by xsi:type. |
| 22183 | * NOTE: Although the *canonical* value is stated, it is not |
| 22184 | * relevant if canonical or not. Additionally XML Schema 1.1 |
| 22185 | * will removed this requirement as well. |
| 22186 | */ |
| 22187 | if (inode->flags & XML_SCHEMA_ELEM_INFO_LOCAL_TYPE) { |
| 22188 | |
| 22189 | ret = xmlSchemaCheckCOSValidDefault(vctxt, |
| 22190 | inode->decl->value, &(inode->val)); |
| 22191 | if (ret != 0) { |
| 22192 | if (ret < 0) { |
| 22193 | VERROR_INT("xmlSchemaValidatorPopElem", |
| 22194 | "calling xmlSchemaCheckCOSValidDefault()"); |
| 22195 | goto internal_error; |
| 22196 | } |
| 22197 | goto end_elem; |
| 22198 | } |
| 22199 | /* |
| 22200 | * Stop here, to avoid redundant validation of the value |
| 22201 | * (see following). |
| 22202 | */ |
| 22203 | goto default_psvi; |
| 22204 | } |
| 22205 | /* |
| 22206 | * cvc-elt (3.3.4) : 5.1.2 |
| 22207 | * The element information item with the canonical lexical |
| 22208 | * representation of the {value constraint} value used as its |
| 22209 | * ·normalized value· must be ·valid· with respect to the |
| 22210 | * ·actual type definition· as defined by Element Locally Valid (Type) |
| 22211 | * (§3.3.4). |
| 22212 | */ |
| 22213 | if (IS_SIMPLE_TYPE(inode->typeDef)) { |
| 22214 | ret = xmlSchemaVCheckINodeDataType(vctxt, |
| 22215 | inode, inode->typeDef, inode->decl->value); |
| 22216 | } else if (HAS_SIMPLE_CONTENT(inode->typeDef)) { |
| 22217 | ret = xmlSchemaVCheckINodeDataType(vctxt, |
| 22218 | inode, inode->typeDef->contentTypeDef, |
| 22219 | inode->decl->value); |
| 22220 | } |
| 22221 | if (ret != 0) { |
| 22222 | if (ret < 0) { |
| 22223 | VERROR_INT("xmlSchemaValidatorPopElem", |
| 22224 | "calling xmlSchemaVCheckCVCSimpleType()"); |
| 22225 | goto internal_error; |
| 22226 | } |
| 22227 | goto end_elem; |
| 22228 | } |
| 22229 | |
| 22230 | default_psvi: |
| 22231 | /* |
| 22232 | * PSVI: Create a text node on the instance element. |
| 22233 | */ |
| 22234 | if ((vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) && |
| 22235 | (inode->node != NULL)) { |
| 22236 | xmlNodePtr textChild; |
| 22237 | xmlChar *normValue; |
| 22238 | /* |
| 22239 | * VAL TODO: Normalize the value. |
| 22240 | */ |
| 22241 | normValue = xmlSchemaNormalizeValue(inode->typeDef, |
| 22242 | inode->decl->value); |
| 22243 | if (normValue != NULL) { |
| 22244 | textChild = xmlNewText(BAD_CAST normValue); |
| 22245 | xmlFree(normValue); |
| 22246 | } else |
| 22247 | textChild = xmlNewText(inode->decl->value); |
| 22248 | if (textChild == NULL) { |
| 22249 | VERROR_INT("xmlSchemaValidatorPopElem", |
| 22250 | "calling xmlNewText()"); |
| 22251 | goto internal_error; |
| 22252 | } else |
| 22253 | xmlAddChild(inode->node, textChild); |
| 22254 | } |
| 22255 | |
| 22256 | } else if (! INODE_NILLED(inode)) { |
| 22257 | /* |
| 22258 | * 5.2.1 The element information item must be ·valid· with respect |
| 22259 | * to the ·actual type definition· as defined by Element Locally |
| 22260 | * Valid (Type) (§3.3.4). |
| 22261 | */ |
| 22262 | if (IS_SIMPLE_TYPE(inode->typeDef)) { |
| 22263 | /* |
| 22264 | * SPEC (cvc-type) (3.1) |
| 22265 | * "If the type definition is a simple type definition, ..." |
| 22266 | * (3.1.3) "If clause 3.2 of Element Locally Valid |
| 22267 | * (Element) (§3.3.4) did not apply, then the ·normalized value· |
| 22268 | * must be ·valid· with respect to the type definition as defined |
| 22269 | * by String Valid (§3.14.4). |
| 22270 | */ |
| 22271 | ret = xmlSchemaVCheckINodeDataType(vctxt, |
| 22272 | inode, inode->typeDef, inode->value); |
| 22273 | } else if (HAS_SIMPLE_CONTENT(inode->typeDef)) { |
| 22274 | /* |
| 22275 | * SPEC (cvc-type) (3.2) "If the type definition is a complex type |
| 22276 | * definition, then the element information item must be |
| 22277 | * ·valid· with respect to the type definition as per |
| 22278 | * Element Locally Valid (Complex Type) (§3.4.4);" |
| 22279 | * |
| 22280 | * SPEC (cvc-complex-type) (2.2) |
| 22281 | * "If the {content type} is a simple type definition, ... |
| 22282 | * the ·normalized value· of the element information item is |
| 22283 | * ·valid· with respect to that simple type definition as |
| 22284 | * defined by String Valid (§3.14.4)." |
| 22285 | */ |
| 22286 | ret = xmlSchemaVCheckINodeDataType(vctxt, |
| 22287 | inode, inode->typeDef->contentTypeDef, inode->value); |
| 22288 | } |
| 22289 | if (ret != 0) { |
| 22290 | if (ret < 0) { |
| 22291 | VERROR_INT("xmlSchemaValidatorPopElem", |
| 22292 | "calling xmlSchemaVCheckCVCSimpleType()"); |
| 22293 | goto internal_error; |
| 22294 | } |
| 22295 | goto end_elem; |
| 22296 | } |
| 22297 | /* |
| 22298 | * 5.2.2 If there is a fixed {value constraint} and clause 3.2 has |
| 22299 | * not applied, all of the following must be true: |
| 22300 | */ |
| 22301 | if ((inode->decl->value != NULL) && |
| 22302 | (inode->decl->flags & XML_SCHEMAS_ELEM_FIXED)) { |
| 22303 | |
| 22304 | /* |
| 22305 | * TODO: We will need a computed value, when comparison is |
| 22306 | * done on computed values. |
| 22307 | */ |
| 22308 | /* |
| 22309 | * 5.2.2.1 The element information item must have no element |
| 22310 | * information item [children]. |
| 22311 | */ |
| 22312 | if (inode->flags & |
| 22313 | XML_SCHEMA_ELEM_INFO_HAS_ELEM_CONTENT) { |
| 22314 | ret = XML_SCHEMAV_CVC_ELT_5_2_2_1; |
| 22315 | VERROR(ret, NULL, |
| 22316 | "The content must not containt element nodes since " |
| 22317 | "there is a fixed value constraint"); |
| 22318 | goto end_elem; |
| 22319 | } else { |
| 22320 | /* |
| 22321 | * 5.2.2.2 The appropriate case among the following must |
| 22322 | * be true: |
| 22323 | */ |
| 22324 | if (HAS_MIXED_CONTENT(inode->typeDef)) { |
| 22325 | /* |
| 22326 | * 5.2.2.2.1 If the {content type} of the ·actual type |
| 22327 | * definition· is mixed, then the *initial value* of the |
| 22328 | * item must match the canonical lexical representation |
| 22329 | * of the {value constraint} value. |
| 22330 | * |
| 22331 | * ... the *initial value* of an element information |
| 22332 | * item is the string composed of, in order, the |
| 22333 | * [character code] of each character information item in |
| 22334 | * the [children] of that element information item. |
| 22335 | */ |
| 22336 | if (! xmlStrEqual(inode->value, inode->decl->value)){ |
| 22337 | /* |
| 22338 | * VAL TODO: Report invalid & expected values as well. |
| 22339 | * VAL TODO: Implement the canonical stuff. |
| 22340 | */ |
| 22341 | ret = XML_SCHEMAV_CVC_ELT_5_2_2_2_1; |
| 22342 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 22343 | ret, NULL, NULL, |
| 22344 | "The initial value '%s' does not match the fixed " |
| 22345 | "value constraint '%s'", |
| 22346 | inode->value, inode->decl->value); |
| 22347 | goto end_elem; |
| 22348 | } |
| 22349 | } else if (HAS_SIMPLE_CONTENT(inode->typeDef)) { |
| 22350 | /* |
| 22351 | * 5.2.2.2.2 If the {content type} of the ·actual type |
| 22352 | * definition· is a simple type definition, then the |
| 22353 | * *actual value* of the item must match the canonical |
| 22354 | * lexical representation of the {value constraint} value. |
| 22355 | */ |
| 22356 | /* |
| 22357 | * VAL TODO: *actual value* is the normalized value, impl. |
| 22358 | * this. |
| 22359 | * VAL TODO: Report invalid & expected values as well. |
| 22360 | * VAL TODO: Implement a comparison with the computed values. |
| 22361 | */ |
| 22362 | if (! xmlStrEqual(inode->value, |
| 22363 | inode->decl->value)) { |
| 22364 | ret = XML_SCHEMAV_CVC_ELT_5_2_2_2_2; |
| 22365 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 22366 | ret, NULL, NULL, |
| 22367 | "The actual value '%s' does not match the fixed " |
| 22368 | "value constraint '%s'", |
| 22369 | inode->value, |
| 22370 | inode->decl->value); |
| 22371 | goto end_elem; |
| 22372 | } |
| 22373 | } |
| 22374 | } |
| 22375 | } |
| 22376 | } |
| 22377 | |
| 22378 | end_elem: |
| 22379 | if (vctxt->depth < 0) { |
| 22380 | /* TODO: raise error? */ |
| 22381 | return (0); |
| 22382 | } |
| 22383 | if (vctxt->depth == vctxt->skipDepth) |
| 22384 | vctxt->skipDepth = -1; |
| 22385 | /* |
| 22386 | * Evaluate the history of XPath state objects. |
| 22387 | */ |
| 22388 | if (xmlSchemaXPathProcessHistory(vctxt, vctxt->depth) == -1) |
| 22389 | goto internal_error; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 22390 | /* |
| 22391 | * TODO: 6 The element information item must be ·valid· with respect to each of |
| 22392 | * the {identity-constraint definitions} as per Identity-constraint |
| 22393 | * Satisfied (§3.11.4). |
| 22394 | */ |
| 22395 | /* |
| 22396 | * Validate IDC keyrefs. |
| 22397 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22398 | if (xmlSchemaCheckCVCIDCKeyRef(vctxt) == -1) |
| 22399 | goto internal_error; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 22400 | /* |
| 22401 | * Merge/free the IDC table. |
| 22402 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22403 | if (inode->idcTable != NULL) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 22404 | #ifdef DEBUG_IDC |
| 22405 | xmlSchemaDebugDumpIDCTable(stdout, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22406 | inode->nsName, |
| 22407 | inode->localName, |
| 22408 | inode->idcTable); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 22409 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 22410 | if (vctxt->depth > 0) { |
| 22411 | /* |
| 22412 | * Merge the IDC node table with the table of the parent node. |
| 22413 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22414 | if (xmlSchemaBubbleIDCNodeTables(vctxt) == -1) |
| 22415 | goto internal_error; |
| 22416 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 22417 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 22418 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22419 | * Clear the current ielem. |
| 22420 | * VAL TODO: Don't free the PSVI IDC tables if they are |
| 22421 | * requested for the PSVI. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 22422 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22423 | xmlSchemaClearElemInfo(inode); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 22424 | /* |
| 22425 | * Skip further processing if we are on the validation root. |
| 22426 | */ |
| 22427 | if (vctxt->depth == 0) { |
| 22428 | vctxt->depth--; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22429 | vctxt->inode = NULL; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 22430 | return (0); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 22431 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 22432 | /* |
| 22433 | * Reset the bubbleDepth if needed. |
| 22434 | */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 22435 | if (vctxt->aidcs != NULL) { |
| 22436 | xmlSchemaIDCAugPtr aidc = vctxt->aidcs; |
| 22437 | do { |
| 22438 | if (aidc->bubbleDepth == vctxt->depth) { |
| 22439 | /* |
| 22440 | * A bubbleDepth of a key/unique IDC matches the current |
| 22441 | * depth, this means that we are leaving the scope of the |
| 22442 | * top-most keyref IDC. |
| 22443 | */ |
| 22444 | aidc->bubbleDepth = -1; |
| 22445 | } |
| 22446 | aidc = aidc->next; |
| 22447 | } while (aidc != NULL); |
| 22448 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22449 | vctxt->depth--; |
| 22450 | vctxt->inode = vctxt->elemInfos[vctxt->depth]; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 22451 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22452 | * VAL TODO: 7 If the element information item is the ·validation root·, it must be |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 22453 | * ·valid· per Validation Root Valid (ID/IDREF) (§3.3.4). |
| 22454 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22455 | return (ret); |
| 22456 | |
| 22457 | internal_error: |
| 22458 | vctxt->err = -1; |
| 22459 | return (-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 22460 | } |
| 22461 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22462 | /* |
| 22463 | * 3.4.4 Complex Type Definition Validation Rules |
| 22464 | * Validation Rule: Element Locally Valid (Complex Type) (cvc-complex-type) |
| 22465 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 22466 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22467 | xmlSchemaValidateChildElem(xmlSchemaValidCtxtPtr vctxt) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 22468 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22469 | xmlSchemaNodeInfoPtr pielem; |
| 22470 | xmlSchemaTypePtr ptype; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 22471 | int ret = 0; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 22472 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22473 | if (vctxt->depth <= 0) { |
| 22474 | VERROR_INT("xmlSchemaValidateChildElem", |
| 22475 | "not intended for the validation root"); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 22476 | return (-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22477 | } |
| 22478 | pielem = vctxt->elemInfos[vctxt->depth -1]; |
| 22479 | if (pielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY) |
| 22480 | pielem->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 22481 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22482 | * Handle 'nilled' elements. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 22483 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22484 | if (INODE_NILLED(pielem)) { |
| 22485 | /* |
| 22486 | * SPEC (cvc-elt) (3.3.4) : (3.2.1) |
| 22487 | */ |
| 22488 | ACTIVATE_PARENT_ELEM; |
| 22489 | ret = XML_SCHEMAV_CVC_ELT_3_2_1; |
| 22490 | VERROR(ret, NULL, |
| 22491 | "Neither character nor element content is allowed, " |
| 22492 | "because the element was 'nilled'"); |
| 22493 | ACTIVATE_ELEM; |
| 22494 | goto unexpected_elem; |
| 22495 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 22496 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22497 | ptype = pielem->typeDef; |
| 22498 | |
| 22499 | if (ptype->builtInType == XML_SCHEMAS_ANYTYPE) { |
| 22500 | /* |
| 22501 | * Workaround for "anyType": we have currently no content model |
| 22502 | * assigned for "anyType", so handle it explicitely. |
| 22503 | * "anyType" has an unbounded, lax "any" wildcard. |
| 22504 | */ |
| 22505 | vctxt->inode->decl = xmlSchemaGetElem(vctxt->schema, |
| 22506 | vctxt->inode->localName, |
| 22507 | vctxt->inode->nsName); |
| 22508 | |
| 22509 | if (vctxt->inode->decl == NULL) { |
| 22510 | xmlSchemaAttrInfoPtr iattr; |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 22511 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22512 | * Process "xsi:type". |
| 22513 | * SPEC (cvc-assess-elt) (1.2.1.2.1) - (1.2.1.2.3) |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 22514 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22515 | iattr = xmlSchemaGetMetaAttrInfo(vctxt, |
| 22516 | XML_SCHEMA_ATTR_INFO_META_XSI_TYPE); |
| 22517 | if (iattr != NULL) { |
| 22518 | ret = xmlSchemaProcessXSIType(vctxt, iattr, |
| 22519 | &(vctxt->inode->typeDef), NULL); |
| 22520 | if (ret != 0) { |
| 22521 | if (ret == -1) { |
| 22522 | VERROR_INT("xmlSchemaValidateChildElem", |
| 22523 | "calling xmlSchemaProcessXSIType() to " |
| 22524 | "process the attribute 'xsi:nil'"); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 22525 | return (-1); |
Kasimier T. Buchcik | 187ea5f | 2005-04-19 11:25:43 +0000 | [diff] [blame] | 22526 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22527 | return (ret); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 22528 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22529 | } else { |
| 22530 | /* |
| 22531 | * Fallback to "anyType". |
| 22532 | * |
| 22533 | * SPEC (cvc-assess-elt) |
| 22534 | * "If the item cannot be ·strictly assessed·, [...] |
| 22535 | * an element information item's schema validity may be laxly |
| 22536 | * assessed if its ·context-determined declaration· is not |
| 22537 | * skip by ·validating· with respect to the ·ur-type |
| 22538 | * definition· as per Element Locally Valid (Type) (§3.3.4)." |
| 22539 | */ |
| 22540 | vctxt->inode->typeDef = |
| 22541 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 22542 | } |
| 22543 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22544 | return (0); |
| 22545 | } |
| 22546 | |
| 22547 | switch (ptype->contentType) { |
| 22548 | case XML_SCHEMA_CONTENT_EMPTY: |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 22549 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22550 | * SPEC (2.1) "If the {content type} is empty, then the |
| 22551 | * element information item has no character or element |
| 22552 | * information item [children]." |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 22553 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22554 | ACTIVATE_PARENT_ELEM |
| 22555 | ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1; |
| 22556 | VERROR(ret, NULL, |
| 22557 | "Element content is not allowed, " |
| 22558 | "because the content type is empty"); |
| 22559 | ACTIVATE_ELEM |
| 22560 | goto unexpected_elem; |
| 22561 | break; |
| 22562 | |
| 22563 | case XML_SCHEMA_CONTENT_MIXED: |
| 22564 | case XML_SCHEMA_CONTENT_ELEMENTS: { |
| 22565 | xmlRegExecCtxtPtr regexCtxt; |
| 22566 | xmlChar *values[10]; |
| 22567 | int terminal, nbval = 10, nbneg; |
| 22568 | |
| 22569 | /* VAL TODO: Optimized "anyType" validation.*/ |
| 22570 | |
| 22571 | if (ptype->contModel == NULL) { |
| 22572 | VERROR_INT("xmlSchemaValidateChildElem", |
| 22573 | "type has elem content but no content model"); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 22574 | return (-1); |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 22575 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22576 | /* |
| 22577 | * Safety belf for evaluation if the cont. model was already |
| 22578 | * examined to be invalid. |
| 22579 | */ |
| 22580 | if (pielem->flags & XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT) { |
| 22581 | VERROR_INT("xmlSchemaValidateChildElem", |
| 22582 | "validating elem, but elem content is already invalid"); |
| 22583 | return (-1); |
| 22584 | } |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 22585 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22586 | regexCtxt = pielem->regexCtxt; |
| 22587 | if (regexCtxt == NULL) { |
| 22588 | /* |
| 22589 | * Create the regex context. |
| 22590 | */ |
| 22591 | regexCtxt = xmlRegNewExecCtxt(ptype->contModel, |
| 22592 | (xmlRegExecCallbacks) xmlSchemaVContentModelCallback, |
| 22593 | vctxt); |
| 22594 | if (regexCtxt == NULL) { |
| 22595 | VERROR_INT("xmlSchemaValidateChildElem", |
| 22596 | "failed to create a regex context"); |
| 22597 | return (-1); |
| 22598 | } |
| 22599 | pielem->regexCtxt = regexCtxt; |
| 22600 | #ifdef DEBUG_AUTOMATA |
| 22601 | xmlGenericError(xmlGenericErrorContext, "AUTOMATA create on '%s'\n", |
| 22602 | pielem->localName); |
| 22603 | #endif |
| 22604 | } |
| 22605 | |
| 22606 | /* |
| 22607 | * SPEC (2.4) "If the {content type} is element-only or mixed, |
| 22608 | * then the sequence of the element information item's |
| 22609 | * element information item [children], if any, taken in |
| 22610 | * order, is ·valid· with respect to the {content type}'s |
| 22611 | * particle, as defined in Element Sequence Locally Valid |
| 22612 | * (Particle) (§3.9.4)." |
| 22613 | */ |
| 22614 | ret = xmlRegExecPushString2(regexCtxt, |
| 22615 | vctxt->inode->localName, |
| 22616 | vctxt->inode->nsName, |
| 22617 | vctxt->inode); |
| 22618 | #ifdef DEBUG_AUTOMATA |
| 22619 | if (ret < 0) |
| 22620 | xmlGenericError(xmlGenericErrorContext, |
| 22621 | "AUTOMATON push ERROR for '%s' on '%s'\n", |
| 22622 | vctxt->inode->localName, pielem->localName); |
| 22623 | else |
| 22624 | xmlGenericError(xmlGenericErrorContext, |
| 22625 | "AUTOMATON push OK for '%s' on '%s'\n", |
| 22626 | vctxt->inode->localName, pielem->localName); |
| 22627 | #endif |
| 22628 | if (vctxt->err == XML_SCHEMAV_INTERNAL) { |
| 22629 | VERROR_INT("xmlSchemaValidateChildElem", |
| 22630 | "calling xmlRegExecPushString2()"); |
| 22631 | return (-1); |
| 22632 | } |
| 22633 | if (ret < 0) { |
| 22634 | xmlRegExecErrInfo(regexCtxt, NULL, &nbval, &nbneg, |
| 22635 | &values[0], &terminal); |
| 22636 | xmlSchemaComplexTypeErr((xmlSchemaAbstractCtxtPtr) vctxt, |
| 22637 | XML_SCHEMAV_ELEMENT_CONTENT, NULL,NULL, |
| 22638 | "This element is not expected", |
| 22639 | nbval, nbneg, values); |
| 22640 | ret = vctxt->err; |
| 22641 | goto unexpected_elem; |
| 22642 | } else |
| 22643 | ret = 0; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 22644 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 22645 | break; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22646 | case XML_SCHEMA_CONTENT_SIMPLE: |
| 22647 | case XML_SCHEMA_CONTENT_BASIC: |
| 22648 | ACTIVATE_PARENT_ELEM |
| 22649 | if (IS_COMPLEX_TYPE(ptype)) { |
| 22650 | /* |
| 22651 | * SPEC (cvc-complex-type) (2.2) |
| 22652 | * "If the {content type} is a simple type definition, then |
| 22653 | * the element information item has no element information |
| 22654 | * item [children], ..." |
| 22655 | */ |
| 22656 | ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2; |
| 22657 | VERROR(ret, NULL, "Element content is not allowed, " |
| 22658 | "because the content type is a simple type definition"); |
| 22659 | } else { |
| 22660 | /* |
| 22661 | * SPEC (cvc-type) (3.1.2) "The element information item must |
| 22662 | * have no element information item [children]." |
| 22663 | */ |
| 22664 | ret = XML_SCHEMAV_CVC_TYPE_3_1_2; |
| 22665 | VERROR(ret, NULL, "Element content is not allowed, " |
| 22666 | "because the type definition is simple"); |
| 22667 | } |
| 22668 | ACTIVATE_ELEM |
| 22669 | ret = vctxt->err; |
| 22670 | goto unexpected_elem; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 22671 | break; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22672 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 22673 | default: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 22674 | break; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22675 | } |
| 22676 | return (ret); |
| 22677 | unexpected_elem: |
| 22678 | /* |
| 22679 | * Pop this element and set the skipDepth to skip |
| 22680 | * all further content of the parent element. |
| 22681 | */ |
| 22682 | vctxt->skipDepth = vctxt->depth; |
| 22683 | vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED; |
| 22684 | pielem->flags |= XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT; |
| 22685 | return (ret); |
| 22686 | } |
| 22687 | |
| 22688 | #define XML_SCHEMA_PUSH_TEXT_PERSIST 1 |
| 22689 | #define XML_SCHEMA_PUSH_TEXT_CREATED 2 |
| 22690 | #define XML_SCHEMA_PUSH_TEXT_VOLATILE 3 |
| 22691 | |
| 22692 | static int |
| 22693 | xmlSchemaVPushText(xmlSchemaValidCtxtPtr vctxt, |
| 22694 | int nodeType, const xmlChar *value, int len, |
| 22695 | int mode, int *consumed) |
| 22696 | { |
| 22697 | /* |
| 22698 | * Unfortunately we have to duplicate the text sometimes. |
| 22699 | * OPTIMIZE: Maybe we could skip it, if: |
| 22700 | * 1. content type is simple |
| 22701 | * 2. whitespace is "collapse" |
| 22702 | * 3. it consists of whitespace only |
| 22703 | * |
| 22704 | * Process character content. |
| 22705 | */ |
| 22706 | if (consumed != NULL) |
| 22707 | *consumed = 0; |
| 22708 | if (INODE_NILLED(vctxt->inode)) { |
| 22709 | /* |
| 22710 | * SPEC cvc-elt (3.3.4 - 3.2.1) |
| 22711 | * "The element information item must have no character or |
| 22712 | * element information item [children]." |
| 22713 | */ |
| 22714 | VERROR(XML_SCHEMAV_CVC_ELT_3_2_1, NULL, |
| 22715 | "Neither character nor element content is allowed " |
| 22716 | "because the element is 'nilled'"); |
| 22717 | return (vctxt->err); |
| 22718 | } |
| 22719 | /* |
| 22720 | * SPEC (2.1) "If the {content type} is empty, then the |
| 22721 | * element information item has no character or element |
| 22722 | * information item [children]." |
| 22723 | */ |
| 22724 | if (vctxt->inode->typeDef->contentType == |
| 22725 | XML_SCHEMA_CONTENT_EMPTY) { |
| 22726 | VERROR(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1, NULL, |
| 22727 | "Character content is not allowed, " |
| 22728 | "because the content type is empty"); |
| 22729 | return (vctxt->err); |
| 22730 | } |
| 22731 | |
| 22732 | if (vctxt->inode->typeDef->contentType == |
| 22733 | XML_SCHEMA_CONTENT_ELEMENTS) { |
| 22734 | if ((nodeType != XML_TEXT_NODE) || |
| 22735 | (! xmlSchemaIsBlank((xmlChar *) value, len))) { |
| 22736 | /* |
| 22737 | * SPEC cvc-complex-type (2.3) |
| 22738 | * "If the {content type} is element-only, then the |
| 22739 | * element information item has no character information |
| 22740 | * item [children] other than those whose [character |
| 22741 | * code] is defined as a white space in [XML 1.0 (Second |
| 22742 | * Edition)]." |
| 22743 | */ |
| 22744 | VERROR(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_3, NULL, |
| 22745 | "Character content other than whitespace is not allowed " |
| 22746 | "because the content type is 'element-only'"); |
| 22747 | return (vctxt->err); |
| 22748 | } |
| 22749 | return (0); |
| 22750 | } |
| 22751 | |
| 22752 | if ((value == NULL) || (value[0] == 0)) |
| 22753 | return (0); |
| 22754 | /* |
| 22755 | * Save the value. |
| 22756 | * NOTE that even if the content type is *mixed*, we need the |
| 22757 | * *initial value* for default/fixed value constraints. |
| 22758 | */ |
| 22759 | if ((vctxt->inode->typeDef->contentType == XML_SCHEMA_CONTENT_MIXED) && |
| 22760 | ((vctxt->inode->decl == NULL) || |
| 22761 | (vctxt->inode->decl->value == NULL))) |
| 22762 | return (0); |
| 22763 | |
| 22764 | if (vctxt->inode->value == NULL) { |
| 22765 | /* |
| 22766 | * Set the value. |
| 22767 | */ |
| 22768 | switch (mode) { |
| 22769 | case XML_SCHEMA_PUSH_TEXT_PERSIST: |
| 22770 | /* |
| 22771 | * When working on a tree. |
| 22772 | */ |
| 22773 | vctxt->inode->value = value; |
| 22774 | break; |
| 22775 | case XML_SCHEMA_PUSH_TEXT_CREATED: |
| 22776 | /* |
| 22777 | * When working with the reader. |
| 22778 | * The value will be freed by the element info. |
| 22779 | */ |
| 22780 | vctxt->inode->value = value; |
| 22781 | if (consumed != NULL) |
| 22782 | *consumed = 1; |
| 22783 | vctxt->inode->flags |= |
| 22784 | XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES; |
| 22785 | break; |
| 22786 | case XML_SCHEMA_PUSH_TEXT_VOLATILE: |
| 22787 | /* |
| 22788 | * When working with SAX. |
| 22789 | * The value will be freed by the element info. |
| 22790 | */ |
| 22791 | if (len != -1) |
| 22792 | vctxt->inode->value = BAD_CAST xmlStrndup(value, len); |
| 22793 | else |
| 22794 | vctxt->inode->value = BAD_CAST xmlStrdup(value); |
| 22795 | vctxt->inode->flags |= |
| 22796 | XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES; |
| 22797 | break; |
| 22798 | default: |
| 22799 | break; |
| 22800 | } |
| 22801 | } else { |
| 22802 | /* |
| 22803 | * Concat the value. |
| 22804 | */ |
| 22805 | if (vctxt->inode->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) { |
Kasimier T. Buchcik | 9c215eb | 2005-06-21 08:38:49 +0000 | [diff] [blame] | 22806 | vctxt->inode->value = BAD_CAST xmlStrncat( |
| 22807 | (xmlChar *) vctxt->inode->value, value, len); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22808 | } else { |
| 22809 | vctxt->inode->value = |
Kasimier T. Buchcik | 84a56e3 | 2005-06-16 12:44:35 +0000 | [diff] [blame] | 22810 | BAD_CAST xmlStrncatNew(vctxt->inode->value, value, len); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22811 | vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES; |
| 22812 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 22813 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22814 | |
| 22815 | return (0); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 22816 | } |
| 22817 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 22818 | static int |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22819 | xmlSchemaValidateElem(xmlSchemaValidCtxtPtr vctxt) |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 22820 | { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 22821 | int ret = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 22822 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22823 | if ((vctxt->skipDepth != -1) && |
| 22824 | (vctxt->depth >= vctxt->skipDepth)) { |
| 22825 | VERROR_INT("xmlSchemaValidateElem", |
| 22826 | "in skip-state"); |
| 22827 | goto internal_error; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 22828 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22829 | if (vctxt->xsiAssemble) { |
| 22830 | if (xmlSchemaAssembleByXSI(vctxt) == -1) |
| 22831 | goto internal_error; |
| 22832 | } |
| 22833 | if (vctxt->depth > 0) { |
| 22834 | /* |
| 22835 | * Validate this element against the content model |
| 22836 | * of the parent. |
| 22837 | */ |
| 22838 | ret = xmlSchemaValidateChildElem(vctxt); |
| 22839 | if (ret != 0) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 22840 | if (ret < 0) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22841 | VERROR_INT("xmlSchemaValidateElem", |
| 22842 | "calling xmlSchemaStreamValidateChildElement()"); |
| 22843 | goto internal_error; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 22844 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22845 | goto exit; |
| 22846 | } |
| 22847 | if (vctxt->depth == vctxt->skipDepth) |
| 22848 | goto exit; |
| 22849 | if ((vctxt->inode->decl == NULL) && |
| 22850 | (vctxt->inode->typeDef == NULL)) { |
| 22851 | VERROR_INT("xmlSchemaValidateElem", |
| 22852 | "the child element was valid but neither the " |
| 22853 | "declaration nor the type was set"); |
| 22854 | goto internal_error; |
| 22855 | } |
| 22856 | } else { |
| 22857 | /* |
| 22858 | * Get the declaration of the validation root. |
| 22859 | */ |
| 22860 | vctxt->inode->decl = xmlSchemaGetElem(vctxt->schema, |
| 22861 | vctxt->inode->localName, |
| 22862 | vctxt->inode->nsName); |
| 22863 | if (vctxt->inode->decl == NULL) { |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 22864 | ret = XML_SCHEMAV_CVC_ELT_1; |
| 22865 | VERROR(ret, NULL, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22866 | "No matching global declaration available " |
| 22867 | "for the validation root"); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22868 | goto exit; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 22869 | } |
| 22870 | } |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 22871 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22872 | if (vctxt->inode->decl == NULL) |
| 22873 | goto type_validation; |
| 22874 | |
| 22875 | if (vctxt->inode->decl->type == XML_SCHEMA_TYPE_ANY) { |
| 22876 | int skip; |
| 22877 | /* |
| 22878 | * Wildcards. |
| 22879 | */ |
| 22880 | ret = xmlSchemaValidateElemWildcard(vctxt, &skip); |
| 22881 | if (ret != 0) { |
| 22882 | if (ret < 0) { |
| 22883 | VERROR_INT("xmlSchemaValidateElem", |
| 22884 | "calling xmlSchemaValidateElemWildcard()"); |
| 22885 | goto internal_error; |
| 22886 | } |
| 22887 | goto exit; |
| 22888 | } |
| 22889 | if (skip) { |
| 22890 | vctxt->skipDepth = vctxt->depth; |
| 22891 | goto exit; |
| 22892 | } |
| 22893 | /* |
| 22894 | * The declaration might be set by the wildcard validation, |
| 22895 | * when the processContents is "lax" or "strict". |
| 22896 | */ |
| 22897 | if (vctxt->inode->decl->type != XML_SCHEMA_TYPE_ELEMENT) { |
| 22898 | /* |
| 22899 | * Clear the "decl" field to not confuse further processing. |
| 22900 | */ |
| 22901 | vctxt->inode->decl = NULL; |
| 22902 | goto type_validation; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 22903 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 22904 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22905 | /* |
| 22906 | * Validate against the declaration. |
| 22907 | */ |
| 22908 | ret = xmlSchemaValidateElemDecl(vctxt); |
| 22909 | if (ret != 0) { |
| 22910 | if (ret < 0) { |
| 22911 | VERROR_INT("xmlSchemaValidateElem", |
| 22912 | "calling xmlSchemaValidateElemDecl()"); |
| 22913 | goto internal_error; |
| 22914 | } |
| 22915 | goto exit; |
| 22916 | } |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 22917 | /* |
| 22918 | * Validate against the type definition. |
| 22919 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22920 | type_validation: |
| 22921 | |
| 22922 | if (vctxt->inode->typeDef == NULL) { |
| 22923 | vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE; |
| 22924 | ret = XML_SCHEMAV_CVC_TYPE_1; |
| 22925 | VERROR(ret, NULL, |
| 22926 | "The type definition is absent"); |
| 22927 | goto exit; |
| 22928 | } |
| 22929 | if (vctxt->inode->typeDef->flags & XML_SCHEMAS_TYPE_ABSTRACT) { |
| 22930 | vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE; |
| 22931 | ret = XML_SCHEMAV_CVC_TYPE_2; |
| 22932 | VERROR(ret, NULL, |
Kasimier T. Buchcik | 84a56e3 | 2005-06-16 12:44:35 +0000 | [diff] [blame] | 22933 | "The type definition is abstract"); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22934 | goto exit; |
| 22935 | } |
| 22936 | /* |
Kasimier T. Buchcik | 9ca11bf | 2005-06-14 19:24:47 +0000 | [diff] [blame] | 22937 | * Evaluate IDCs. Do it here, since new IDC matchers are registered |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22938 | * during validation against the declaration. This must be done |
| 22939 | * _before_ attribute validation. |
| 22940 | */ |
| 22941 | ret = xmlSchemaXPathEvaluate(vctxt, XML_ELEMENT_NODE); |
| 22942 | if (ret == -1) { |
| 22943 | VERROR_INT("xmlSchemaValidateElem", |
| 22944 | "calling xmlSchemaXPathEvaluate()"); |
| 22945 | goto internal_error; |
| 22946 | } |
| 22947 | /* |
| 22948 | * Validate attributes. |
| 22949 | */ |
| 22950 | if (IS_COMPLEX_TYPE(vctxt->inode->typeDef)) { |
| 22951 | if ((vctxt->nbAttrInfos != 0) || |
| 22952 | (vctxt->inode->typeDef->attributeUses != NULL)) { |
| 22953 | |
| 22954 | ret = xmlSchemaVAttributesComplex(vctxt); |
| 22955 | } |
| 22956 | } else if (vctxt->nbAttrInfos != 0) { |
| 22957 | |
| 22958 | ret = xmlSchemaVAttributesSimple(vctxt); |
| 22959 | } |
| 22960 | /* |
| 22961 | * Clear registered attributes. |
| 22962 | */ |
| 22963 | if (vctxt->nbAttrInfos != 0) |
| 22964 | xmlSchemaClearAttrInfos(vctxt); |
| 22965 | if (ret == -1) { |
| 22966 | VERROR_INT("xmlSchemaValidateElem", |
| 22967 | "calling attributes validation"); |
| 22968 | goto internal_error; |
| 22969 | } |
| 22970 | /* |
| 22971 | * Don't return an error if attributes are invalid on purpose. |
| 22972 | */ |
| 22973 | ret = 0; |
| 22974 | |
| 22975 | exit: |
| 22976 | if (ret != 0) |
| 22977 | vctxt->skipDepth = vctxt->depth; |
| 22978 | return (ret); |
| 22979 | internal_error: |
| 22980 | return (-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 22981 | } |
| 22982 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22983 | #ifdef XML_SCHEMA_READER_ENABLED |
| 22984 | static int |
| 22985 | xmlSchemaVReaderWalk(xmlSchemaValidCtxtPtr vctxt) |
Kasimier T. Buchcik | 5eba91f | 2004-09-08 09:17:27 +0000 | [diff] [blame] | 22986 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22987 | const int WHTSP = 13, SIGN_WHTSP = 14, END_ELEM = 15; |
| 22988 | int depth, nodeType, ret = 0, consumed; |
| 22989 | xmlSchemaNodeInfoPtr ielem; |
Kasimier T. Buchcik | 5eba91f | 2004-09-08 09:17:27 +0000 | [diff] [blame] | 22990 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 22991 | vctxt->depth = -1; |
| 22992 | ret = xmlTextReaderRead(vctxt->reader); |
| 22993 | /* |
| 22994 | * Move to the document element. |
| 22995 | */ |
| 22996 | while (ret == 1) { |
| 22997 | nodeType = xmlTextReaderNodeType(vctxt->reader); |
| 22998 | if (nodeType == XML_ELEMENT_NODE) |
| 22999 | goto root_found; |
| 23000 | ret = xmlTextReaderRead(vctxt->reader); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 23001 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23002 | goto exit; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 23003 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23004 | root_found: |
| 23005 | |
| 23006 | do { |
| 23007 | depth = xmlTextReaderDepth(vctxt->reader); |
| 23008 | nodeType = xmlTextReaderNodeType(vctxt->reader); |
| 23009 | |
| 23010 | if (nodeType == XML_ELEMENT_NODE) { |
| 23011 | |
Kasimier T. Buchcik | 84a56e3 | 2005-06-16 12:44:35 +0000 | [diff] [blame] | 23012 | vctxt->depth++; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23013 | if (xmlSchemaValidatorPushElem(vctxt) == -1) { |
| 23014 | VERROR_INT("xmlSchemaVReaderWalk", |
| 23015 | "calling xmlSchemaValidatorPushElem()"); |
| 23016 | goto internal_error; |
| 23017 | } |
| 23018 | ielem = vctxt->inode; |
| 23019 | ielem->localName = xmlTextReaderLocalName(vctxt->reader); |
| 23020 | ielem->nsName = xmlTextReaderNamespaceUri(vctxt->reader); |
| 23021 | ielem->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES; |
| 23022 | /* |
| 23023 | * Is the element empty? |
| 23024 | */ |
| 23025 | ret = xmlTextReaderIsEmptyElement(vctxt->reader); |
| 23026 | if (ret == -1) { |
| 23027 | VERROR_INT("xmlSchemaVReaderWalk", |
| 23028 | "calling xmlTextReaderIsEmptyElement()"); |
| 23029 | goto internal_error; |
| 23030 | } |
| 23031 | if (ret) { |
| 23032 | ielem->flags |= XML_SCHEMA_ELEM_INFO_EMPTY; |
| 23033 | } |
| 23034 | /* |
| 23035 | * Register attributes. |
| 23036 | */ |
| 23037 | vctxt->nbAttrInfos = 0; |
| 23038 | ret = xmlTextReaderMoveToFirstAttribute(vctxt->reader); |
| 23039 | if (ret == -1) { |
| 23040 | VERROR_INT("xmlSchemaVReaderWalk", |
| 23041 | "calling xmlTextReaderMoveToFirstAttribute()"); |
| 23042 | goto internal_error; |
| 23043 | } |
| 23044 | if (ret == 1) { |
| 23045 | do { |
| 23046 | /* |
| 23047 | * VAL TODO: How do we know that the reader works on a |
| 23048 | * node tree, to be able to pass a node here? |
| 23049 | */ |
| 23050 | if (xmlSchemaValidatorPushAttribute(vctxt, NULL, |
| 23051 | (const xmlChar *) xmlTextReaderLocalName(vctxt->reader), |
| 23052 | xmlTextReaderNamespaceUri(vctxt->reader), 1, |
| 23053 | xmlTextReaderValue(vctxt->reader), 1) == -1) { |
| 23054 | |
| 23055 | VERROR_INT("xmlSchemaVReaderWalk", |
| 23056 | "calling xmlSchemaValidatorPushAttribute()"); |
| 23057 | goto internal_error; |
| 23058 | } |
| 23059 | ret = xmlTextReaderMoveToNextAttribute(vctxt->reader); |
| 23060 | if (ret == -1) { |
| 23061 | VERROR_INT("xmlSchemaVReaderWalk", |
| 23062 | "calling xmlTextReaderMoveToFirstAttribute()"); |
| 23063 | goto internal_error; |
| 23064 | } |
| 23065 | } while (ret == 1); |
| 23066 | /* |
| 23067 | * Back to element position. |
| 23068 | */ |
| 23069 | ret = xmlTextReaderMoveToElement(vctxt->reader); |
| 23070 | if (ret == -1) { |
| 23071 | VERROR_INT("xmlSchemaVReaderWalk", |
| 23072 | "calling xmlTextReaderMoveToElement()"); |
| 23073 | goto internal_error; |
| 23074 | } |
| 23075 | } |
| 23076 | /* |
| 23077 | * Validate the element. |
| 23078 | */ |
| 23079 | ret= xmlSchemaValidateElem(vctxt); |
| 23080 | if (ret != 0) { |
| 23081 | if (ret == -1) { |
| 23082 | VERROR_INT("xmlSchemaVReaderWalk", |
| 23083 | "calling xmlSchemaValidateElem()"); |
| 23084 | goto internal_error; |
| 23085 | } |
| 23086 | goto exit; |
| 23087 | } |
| 23088 | if (vctxt->depth == vctxt->skipDepth) { |
| 23089 | int curDepth; |
| 23090 | /* |
| 23091 | * Skip all content. |
| 23092 | */ |
| 23093 | if ((ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY) == 0) { |
| 23094 | ret = xmlTextReaderRead(vctxt->reader); |
| 23095 | curDepth = xmlTextReaderDepth(vctxt->reader); |
| 23096 | while ((ret == 1) && (curDepth != depth)) { |
| 23097 | ret = xmlTextReaderRead(vctxt->reader); |
| 23098 | curDepth = xmlTextReaderDepth(vctxt->reader); |
| 23099 | } |
| 23100 | if (ret < 0) { |
| 23101 | /* |
| 23102 | * VAL TODO: A reader error occured; what to do here? |
| 23103 | */ |
| 23104 | ret = 1; |
| 23105 | goto exit; |
| 23106 | } |
| 23107 | } |
| 23108 | goto leave_elem; |
| 23109 | } |
| 23110 | /* |
| 23111 | * READER VAL TODO: Is an END_ELEM really never called |
| 23112 | * if the elem is empty? |
| 23113 | */ |
| 23114 | if (ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY) |
| 23115 | goto leave_elem; |
| 23116 | } else if (nodeType == END_ELEM) { |
| 23117 | /* |
| 23118 | * Process END of element. |
| 23119 | */ |
| 23120 | leave_elem: |
| 23121 | ret = xmlSchemaValidatorPopElem(vctxt); |
| 23122 | if (ret != 0) { |
| 23123 | if (ret < 0) { |
| 23124 | VERROR_INT("xmlSchemaVReaderWalk", |
| 23125 | "calling xmlSchemaValidatorPopElem()"); |
| 23126 | goto internal_error; |
| 23127 | } |
| 23128 | goto exit; |
| 23129 | } |
| 23130 | if (vctxt->depth >= 0) |
| 23131 | ielem = vctxt->inode; |
| 23132 | else |
| 23133 | ielem = NULL; |
| 23134 | } else if ((nodeType == XML_TEXT_NODE) || |
| 23135 | (nodeType == XML_CDATA_SECTION_NODE) || |
| 23136 | (nodeType == WHTSP) || |
| 23137 | (nodeType == SIGN_WHTSP)) { |
| 23138 | /* |
| 23139 | * Process character content. |
| 23140 | */ |
| 23141 | xmlChar *value; |
| 23142 | |
| 23143 | if ((nodeType == WHTSP) || (nodeType == SIGN_WHTSP)) |
| 23144 | nodeType = XML_TEXT_NODE; |
| 23145 | |
| 23146 | value = xmlTextReaderValue(vctxt->reader); |
| 23147 | ret = xmlSchemaVPushText(vctxt, nodeType, BAD_CAST value, |
| 23148 | -1, XML_SCHEMA_PUSH_TEXT_CREATED, &consumed); |
| 23149 | if (! consumed) |
| 23150 | xmlFree(value); |
| 23151 | if (ret == -1) { |
| 23152 | VERROR_INT("xmlSchemaVReaderWalk", |
| 23153 | "calling xmlSchemaVPushText()"); |
| 23154 | goto internal_error; |
| 23155 | } |
| 23156 | } else if ((nodeType == XML_ENTITY_NODE) || |
| 23157 | (nodeType == XML_ENTITY_REF_NODE)) { |
| 23158 | /* |
| 23159 | * VAL TODO: What to do with entities? |
| 23160 | */ |
| 23161 | TODO |
| 23162 | } |
| 23163 | /* |
| 23164 | * Read next node. |
| 23165 | */ |
| 23166 | ret = xmlTextReaderRead(vctxt->reader); |
| 23167 | } while (ret == 1); |
| 23168 | |
| 23169 | exit: |
| 23170 | return (ret); |
| 23171 | internal_error: |
| 23172 | return (-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23173 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23174 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23175 | |
| 23176 | /************************************************************************ |
| 23177 | * * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23178 | * SAX validation handlers * |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23179 | * * |
| 23180 | ************************************************************************/ |
| 23181 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23182 | #ifdef XML_SCHEMA_SAX_ENABLED |
| 23183 | /* |
| 23184 | * Process text content. |
| 23185 | */ |
| 23186 | static void |
| 23187 | xmlSchemaSAXHandleText(void *ctx, |
| 23188 | const xmlChar * ch, |
| 23189 | int len) |
| 23190 | { |
| 23191 | xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx; |
| 23192 | |
| 23193 | if (vctxt->depth < 0) |
| 23194 | return; |
| 23195 | if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth)) |
| 23196 | return; |
| 23197 | if (vctxt->inode->flags & XML_SCHEMA_ELEM_INFO_EMPTY) |
| 23198 | vctxt->inode->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY; |
| 23199 | if (xmlSchemaVPushText(vctxt, XML_TEXT_NODE, ch, len, |
| 23200 | XML_SCHEMA_PUSH_TEXT_VOLATILE, NULL) == -1) { |
| 23201 | VERROR_INT("xmlSchemaSAXHandleCDataSection", |
| 23202 | "calling xmlSchemaVPushText()"); |
| 23203 | vctxt->err = -1; |
| 23204 | xmlStopParser(vctxt->parserCtxt); |
| 23205 | } |
| 23206 | } |
| 23207 | |
| 23208 | /* |
| 23209 | * Process CDATA content. |
| 23210 | */ |
| 23211 | static void |
| 23212 | xmlSchemaSAXHandleCDataSection(void *ctx, |
| 23213 | const xmlChar * ch, |
| 23214 | int len) |
| 23215 | { |
| 23216 | xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx; |
| 23217 | |
| 23218 | if (vctxt->depth < 0) |
| 23219 | return; |
| 23220 | if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth)) |
| 23221 | return; |
| 23222 | if (vctxt->inode->flags & XML_SCHEMA_ELEM_INFO_EMPTY) |
| 23223 | vctxt->inode->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY; |
| 23224 | if (xmlSchemaVPushText(vctxt, XML_CDATA_SECTION_NODE, ch, len, |
| 23225 | XML_SCHEMA_PUSH_TEXT_VOLATILE, NULL) == -1) { |
| 23226 | VERROR_INT("xmlSchemaSAXHandleCDataSection", |
| 23227 | "calling xmlSchemaVPushText()"); |
| 23228 | vctxt->err = -1; |
| 23229 | xmlStopParser(vctxt->parserCtxt); |
| 23230 | } |
| 23231 | } |
| 23232 | |
| 23233 | static void |
| 23234 | xmlSchemaSAXHandleReference(void *ctx ATTRIBUTE_UNUSED, |
| 23235 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 23236 | { |
| 23237 | xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx; |
| 23238 | |
| 23239 | if (vctxt->depth < 0) |
| 23240 | return; |
| 23241 | if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth)) |
| 23242 | return; |
| 23243 | /* SAX VAL TODO: What to do here? */ |
| 23244 | TODO |
| 23245 | } |
| 23246 | |
| 23247 | static void |
| 23248 | xmlSchemaSAXHandleStartElementNs(void *ctx, |
| 23249 | const xmlChar * localname, |
| 23250 | const xmlChar * prefix ATTRIBUTE_UNUSED, |
| 23251 | const xmlChar * URI, |
| 23252 | int nb_namespaces, |
| 23253 | const xmlChar ** namespaces, |
| 23254 | int nb_attributes, |
| 23255 | int nb_defaulted ATTRIBUTE_UNUSED, |
| 23256 | const xmlChar ** attributes) |
| 23257 | { |
| 23258 | xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx; |
| 23259 | int ret; |
| 23260 | xmlSchemaNodeInfoPtr ielem; |
| 23261 | int i, j; |
| 23262 | |
| 23263 | /* |
| 23264 | * SAX VAL TODO: What to do with nb_defaulted? |
| 23265 | */ |
| 23266 | /* |
Kasimier T. Buchcik | 84a56e3 | 2005-06-16 12:44:35 +0000 | [diff] [blame] | 23267 | * Skip elements if inside a "skip" wildcard or invalid. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23268 | */ |
Kasimier T. Buchcik | 84a56e3 | 2005-06-16 12:44:35 +0000 | [diff] [blame] | 23269 | vctxt->depth++; |
| 23270 | if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth)) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23271 | return; |
| 23272 | /* |
| 23273 | * Push the element. |
| 23274 | */ |
| 23275 | if (xmlSchemaValidatorPushElem(vctxt) == -1) { |
| 23276 | VERROR_INT("xmlSchemaSAXHandleStartElementNs", |
| 23277 | "calling xmlSchemaValidatorPushElem()"); |
| 23278 | goto internal_error; |
| 23279 | } |
| 23280 | ielem = vctxt->inode; |
| 23281 | ielem->localName = localname; |
| 23282 | ielem->nsName = URI; |
| 23283 | ielem->flags |= XML_SCHEMA_ELEM_INFO_EMPTY; |
| 23284 | /* |
| 23285 | * Register namespaces on the elem info. |
| 23286 | */ |
| 23287 | if (nb_namespaces != 0) { |
| 23288 | /* |
| 23289 | * Although the parser builds its own namespace list, |
| 23290 | * we have no access to it, so we'll use an own one. |
| 23291 | */ |
| 23292 | for (i = 0, j = 0; i < nb_namespaces; i++, j += 2) { |
| 23293 | /* |
| 23294 | * Store prefix and namespace name. |
| 23295 | */ |
| 23296 | if (ielem->nsBindings == NULL) { |
| 23297 | ielem->nsBindings = |
| 23298 | (const xmlChar **) xmlMalloc(10 * |
| 23299 | sizeof(const xmlChar *)); |
| 23300 | if (ielem->nsBindings == NULL) { |
| 23301 | xmlSchemaVErrMemory(vctxt, |
| 23302 | "allocating namespace bindings for SAX validation", |
| 23303 | NULL); |
| 23304 | goto internal_error; |
| 23305 | } |
| 23306 | ielem->nbNsBindings = 0; |
| 23307 | ielem->sizeNsBindings = 5; |
| 23308 | } else if (ielem->sizeNsBindings <= ielem->nbNsBindings) { |
| 23309 | ielem->sizeNsBindings *= 2; |
| 23310 | ielem->nsBindings = |
| 23311 | (const xmlChar **) xmlRealloc( |
| 23312 | (void *) ielem->nsBindings, |
Kasimier T. Buchcik | 84a56e3 | 2005-06-16 12:44:35 +0000 | [diff] [blame] | 23313 | ielem->sizeNsBindings * 2 * sizeof(const xmlChar *)); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23314 | if (ielem->nsBindings == NULL) { |
| 23315 | xmlSchemaVErrMemory(vctxt, |
| 23316 | "re-allocating namespace bindings for SAX validation", |
| 23317 | NULL); |
| 23318 | goto internal_error; |
| 23319 | } |
| 23320 | } |
| 23321 | |
| 23322 | ielem->nsBindings[ielem->nbNsBindings * 2] = namespaces[j]; |
| 23323 | if (namespaces[j+1][0] == 0) { |
| 23324 | /* |
| 23325 | * Handle xmlns="". |
| 23326 | */ |
| 23327 | ielem->nsBindings[ielem->nbNsBindings * 2 + 1] = NULL; |
| 23328 | } else |
| 23329 | ielem->nsBindings[ielem->nbNsBindings * 2 + 1] = |
| 23330 | namespaces[j+1]; |
| 23331 | ielem->nbNsBindings++; |
| 23332 | } |
| 23333 | } |
| 23334 | /* |
| 23335 | * Register attributes. |
| 23336 | * SAX VAL TODO: We are not adding namespace declaration |
| 23337 | * attributes yet. |
| 23338 | */ |
| 23339 | if (nb_attributes != 0) { |
| 23340 | xmlChar *value; |
| 23341 | |
| 23342 | for (j = 0, i = 0; i < nb_attributes; i++, j += 5) { |
| 23343 | /* |
| 23344 | * Duplicate the value. |
| 23345 | */ |
| 23346 | value = xmlStrndup(attributes[j+3], |
| 23347 | attributes[j+4] - attributes[j+3]); |
| 23348 | ret = xmlSchemaValidatorPushAttribute(vctxt, |
| 23349 | NULL, attributes[j], attributes[j+2], 0, |
| 23350 | value, 1); |
| 23351 | if (ret == -1) { |
| 23352 | VERROR_INT("xmlSchemaSAXHandleStartElementNs", |
| 23353 | "calling xmlSchemaValidatorPushAttribute()"); |
| 23354 | goto internal_error; |
| 23355 | } |
| 23356 | } |
| 23357 | } |
| 23358 | /* |
| 23359 | * Validate the element. |
| 23360 | */ |
| 23361 | ret = xmlSchemaValidateElem(vctxt); |
| 23362 | if (ret != 0) { |
| 23363 | if (ret == -1) { |
| 23364 | VERROR_INT("xmlSchemaSAXHandleStartElementNs", |
| 23365 | "calling xmlSchemaValidateElem()"); |
| 23366 | goto internal_error; |
| 23367 | } |
| 23368 | goto exit; |
| 23369 | } |
| 23370 | |
| 23371 | exit: |
| 23372 | return; |
| 23373 | internal_error: |
| 23374 | vctxt->err = -1; |
| 23375 | xmlStopParser(vctxt->parserCtxt); |
| 23376 | return; |
| 23377 | } |
| 23378 | |
| 23379 | static void |
| 23380 | xmlSchemaSAXHandleEndElementNs(void *ctx, |
| 23381 | const xmlChar * localname ATTRIBUTE_UNUSED, |
| 23382 | const xmlChar * prefix ATTRIBUTE_UNUSED, |
| 23383 | const xmlChar * URI ATTRIBUTE_UNUSED) |
| 23384 | { |
| 23385 | xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx; |
| 23386 | int res; |
| 23387 | |
| 23388 | /* |
Kasimier T. Buchcik | 84a56e3 | 2005-06-16 12:44:35 +0000 | [diff] [blame] | 23389 | * Skip elements if inside a "skip" wildcard or if invalid. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23390 | */ |
| 23391 | if (vctxt->skipDepth != -1) { |
| 23392 | if (vctxt->depth > vctxt->skipDepth) { |
| 23393 | vctxt->depth--; |
| 23394 | return; |
| 23395 | } else |
| 23396 | vctxt->skipDepth = -1; |
| 23397 | } |
| 23398 | /* |
| 23399 | * SAX VAL TODO: Just a temporary check. |
| 23400 | */ |
| 23401 | if ((!xmlStrEqual(vctxt->inode->localName, localname)) || |
| 23402 | (!xmlStrEqual(vctxt->inode->nsName, URI))) { |
| 23403 | VERROR_INT("xmlSchemaSAXHandleEndElementNs", |
| 23404 | "elem pop mismatch"); |
| 23405 | } |
| 23406 | res = xmlSchemaValidatorPopElem(vctxt); |
| 23407 | if (res != 0) { |
| 23408 | if (res < 0) { |
| 23409 | VERROR_INT("xmlSchemaSAXHandleEndElementNs", |
| 23410 | "calling xmlSchemaValidatorPopElem()"); |
| 23411 | goto internal_error; |
| 23412 | } |
| 23413 | goto exit; |
| 23414 | } |
| 23415 | exit: |
| 23416 | return; |
| 23417 | internal_error: |
| 23418 | vctxt->err = -1; |
| 23419 | xmlStopParser(vctxt->parserCtxt); |
| 23420 | return; |
| 23421 | } |
| 23422 | #endif |
| 23423 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23424 | /************************************************************************ |
| 23425 | * * |
| 23426 | * Validation interfaces * |
| 23427 | * * |
| 23428 | ************************************************************************/ |
| 23429 | |
| 23430 | /** |
| 23431 | * xmlSchemaNewValidCtxt: |
| 23432 | * @schema: a precompiled XML Schemas |
| 23433 | * |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 23434 | * Create an XML Schemas validation context based on the given schema. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23435 | * |
| 23436 | * Returns the validation context or NULL in case of error |
| 23437 | */ |
| 23438 | xmlSchemaValidCtxtPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 23439 | xmlSchemaNewValidCtxt(xmlSchemaPtr schema) |
| 23440 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23441 | xmlSchemaValidCtxtPtr ret; |
| 23442 | |
| 23443 | ret = (xmlSchemaValidCtxtPtr) xmlMalloc(sizeof(xmlSchemaValidCtxt)); |
| 23444 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 23445 | xmlSchemaVErrMemory(NULL, "allocating validation context", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23446 | return (NULL); |
| 23447 | } |
| 23448 | memset(ret, 0, sizeof(xmlSchemaValidCtxt)); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23449 | ret->type = XML_SCHEMA_CTXT_VALIDATOR; |
| 23450 | ret->schema = schema; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23451 | return (ret); |
| 23452 | } |
| 23453 | |
| 23454 | /** |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 23455 | * xmlSchemaClearValidCtxt: |
| 23456 | * @ctxt: the schema validation context |
| 23457 | * |
| 23458 | * Free the resources associated to the schema validation context; |
| 23459 | * leaves some fields alive intended for reuse of the context. |
| 23460 | */ |
| 23461 | static void |
| 23462 | xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt) |
| 23463 | { |
| 23464 | if (vctxt == NULL) |
| 23465 | return; |
| 23466 | |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 23467 | vctxt->flags = 0; |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 23468 | vctxt->validationRoot = NULL; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23469 | vctxt->doc = NULL; |
Daniel Veillard | 39e5c89 | 2005-07-03 22:48:50 +0000 | [diff] [blame] | 23470 | #ifdef LIBXML_READER_ENABLED |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23471 | vctxt->reader = NULL; |
Daniel Veillard | 39e5c89 | 2005-07-03 22:48:50 +0000 | [diff] [blame] | 23472 | #endif |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 23473 | if (vctxt->value != NULL) { |
| 23474 | xmlSchemaFreeValue(vctxt->value); |
| 23475 | vctxt->value = NULL; |
| 23476 | } |
| 23477 | /* |
| 23478 | * Augmented IDC information. |
| 23479 | */ |
| 23480 | if (vctxt->aidcs != NULL) { |
| 23481 | xmlSchemaIDCAugPtr cur = vctxt->aidcs, next; |
| 23482 | do { |
| 23483 | next = cur->next; |
| 23484 | xmlFree(cur); |
| 23485 | cur = next; |
| 23486 | } while (cur != NULL); |
| 23487 | vctxt->aidcs = NULL; |
| 23488 | } |
| 23489 | if (vctxt->idcNodes != NULL) { |
| 23490 | int i; |
| 23491 | xmlSchemaPSVIIDCNodePtr item; |
| 23492 | |
| 23493 | for (i = 0; i < vctxt->nbIdcNodes; i++) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23494 | item = vctxt->idcNodes[i]; |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 23495 | xmlFree(item->keys); |
| 23496 | xmlFree(item); |
| 23497 | } |
| 23498 | xmlFree(vctxt->idcNodes); |
| 23499 | vctxt->idcNodes = NULL; |
| 23500 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23501 | /* |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 23502 | * Note that we won't delete the XPath state pool here. |
| 23503 | */ |
| 23504 | if (vctxt->xpathStates != NULL) { |
| 23505 | xmlSchemaFreeIDCStateObjList(vctxt->xpathStates); |
| 23506 | vctxt->xpathStates = NULL; |
| 23507 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23508 | /* |
| 23509 | * Attribute info. |
| 23510 | */ |
| 23511 | if (vctxt->nbAttrInfos != 0) { |
| 23512 | xmlSchemaClearAttrInfos(vctxt); |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 23513 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23514 | /* |
| 23515 | * Element info. |
| 23516 | */ |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 23517 | if (vctxt->elemInfos != NULL) { |
| 23518 | int i; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23519 | xmlSchemaNodeInfoPtr ei; |
| 23520 | |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 23521 | for (i = 0; i < vctxt->sizeElemInfos; i++) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23522 | ei = vctxt->elemInfos[i]; |
| 23523 | if (ei == NULL) |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 23524 | break; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23525 | xmlSchemaClearElemInfo(ei); |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 23526 | } |
| 23527 | } |
| 23528 | } |
| 23529 | |
| 23530 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23531 | * xmlSchemaFreeValidCtxt: |
| 23532 | * @ctxt: the schema validation context |
| 23533 | * |
| 23534 | * Free the resources associated to the schema validation context |
| 23535 | */ |
| 23536 | void |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 23537 | xmlSchemaFreeValidCtxt(xmlSchemaValidCtxtPtr ctxt) |
| 23538 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23539 | if (ctxt == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 23540 | return; |
Daniel Veillard | 88c5891 | 2002-04-23 07:12:20 +0000 | [diff] [blame] | 23541 | if (ctxt->value != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 23542 | xmlSchemaFreeValue(ctxt->value); |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 23543 | if (ctxt->pctxt != NULL) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 23544 | xmlSchemaFreeParserCtxt(ctxt->pctxt); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 23545 | if (ctxt->idcNodes != NULL) { |
| 23546 | int i; |
| 23547 | xmlSchemaPSVIIDCNodePtr item; |
| 23548 | |
| 23549 | for (i = 0; i < ctxt->nbIdcNodes; i++) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23550 | item = ctxt->idcNodes[i]; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 23551 | xmlFree(item->keys); |
| 23552 | xmlFree(item); |
| 23553 | } |
| 23554 | xmlFree(ctxt->idcNodes); |
| 23555 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 23556 | if (ctxt->idcKeys != NULL) { |
| 23557 | int i; |
| 23558 | for (i = 0; i < ctxt->nbIdcKeys; i++) |
| 23559 | xmlSchemaIDCFreeKey(ctxt->idcKeys[i]); |
| 23560 | xmlFree(ctxt->idcKeys); |
| 23561 | } |
| 23562 | |
| 23563 | if (ctxt->xpathStates != NULL) |
| 23564 | xmlSchemaFreeIDCStateObjList(ctxt->xpathStates); |
| 23565 | if (ctxt->xpathStatePool != NULL) |
| 23566 | xmlSchemaFreeIDCStateObjList(ctxt->xpathStatePool); |
| 23567 | |
| 23568 | /* |
| 23569 | * Augmented IDC information. |
| 23570 | */ |
| 23571 | if (ctxt->aidcs != NULL) { |
| 23572 | xmlSchemaIDCAugPtr cur = ctxt->aidcs, next; |
| 23573 | do { |
| 23574 | next = cur->next; |
| 23575 | xmlFree(cur); |
| 23576 | cur = next; |
| 23577 | } while (cur != NULL); |
| 23578 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23579 | if (ctxt->attrInfos != NULL) { |
| 23580 | int i; |
| 23581 | xmlSchemaAttrInfoPtr attr; |
| 23582 | |
| 23583 | /* Just a paranoid call to the cleanup. */ |
| 23584 | if (ctxt->nbAttrInfos != 0) |
| 23585 | xmlSchemaClearAttrInfos(ctxt); |
| 23586 | for (i = 0; i < ctxt->sizeAttrInfos; i++) { |
| 23587 | attr = ctxt->attrInfos[i]; |
| 23588 | xmlFree(attr); |
| 23589 | } |
| 23590 | xmlFree(ctxt->attrInfos); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 23591 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 23592 | if (ctxt->elemInfos != NULL) { |
| 23593 | int i; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23594 | xmlSchemaNodeInfoPtr ei; |
| 23595 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 23596 | for (i = 0; i < ctxt->sizeElemInfos; i++) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23597 | ei = ctxt->elemInfos[i]; |
| 23598 | if (ei == NULL) |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 23599 | break; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23600 | xmlSchemaClearElemInfo(ei); |
| 23601 | xmlFree(ei); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 23602 | } |
| 23603 | xmlFree(ctxt->elemInfos); |
| 23604 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23605 | if (ctxt->dict != NULL) |
| 23606 | xmlDictFree(ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23607 | xmlFree(ctxt); |
| 23608 | } |
| 23609 | |
| 23610 | /** |
Daniel Veillard | f10ae12 | 2005-07-10 19:03:16 +0000 | [diff] [blame] | 23611 | * xmlSchemaIsValid: |
| 23612 | * @ctxt: the schema validation context |
| 23613 | * |
| 23614 | * Check if any error was detected during validation. |
| 23615 | * |
| 23616 | * Returns 1 if valid so far, 0 if errors were detected, and -1 in case |
| 23617 | * of internal error. |
| 23618 | */ |
| 23619 | int |
| 23620 | xmlSchemaIsValid(xmlSchemaValidCtxtPtr ctxt) |
| 23621 | { |
| 23622 | if (ctxt == NULL) |
| 23623 | return(-1); |
| 23624 | return(ctxt->err == 0); |
| 23625 | } |
| 23626 | |
| 23627 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23628 | * xmlSchemaSetValidErrors: |
| 23629 | * @ctxt: a schema validation context |
| 23630 | * @err: the error function |
| 23631 | * @warn: the warning function |
Daniel Veillard | a9b66d0 | 2002-12-11 14:23:49 +0000 | [diff] [blame] | 23632 | * @ctx: the functions context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23633 | * |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 23634 | * Set the error and warning callback informations |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23635 | */ |
| 23636 | void |
| 23637 | xmlSchemaSetValidErrors(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 23638 | xmlSchemaValidityErrorFunc err, |
| 23639 | xmlSchemaValidityWarningFunc warn, void *ctx) |
| 23640 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23641 | if (ctxt == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 23642 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23643 | ctxt->error = err; |
| 23644 | ctxt->warning = warn; |
| 23645 | ctxt->userData = ctx; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 23646 | if (ctxt->pctxt != NULL) |
| 23647 | xmlSchemaSetParserErrors(ctxt->pctxt, err, warn, ctx); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23648 | } |
| 23649 | |
| 23650 | /** |
Daniel Veillard | da0aa4c | 2005-07-13 23:07:49 +0000 | [diff] [blame] | 23651 | * xmlSchemaSetValidStructuredErrors: |
| 23652 | * @ctxt: a schema validation context |
| 23653 | * @serror: the structured error function |
| 23654 | * @ctx: the functions context |
| 23655 | * |
| 23656 | * Set the structured error callback |
| 23657 | */ |
| 23658 | void |
| 23659 | xmlSchemaSetValidStructuredErrors(xmlSchemaValidCtxtPtr ctxt, |
| 23660 | xmlStructuredErrorFunc serror, void *ctx) |
| 23661 | { |
| 23662 | if (ctxt == NULL) |
| 23663 | return; |
| 23664 | ctxt->serror = serror; |
| 23665 | ctxt->error = NULL; |
| 23666 | ctxt->warning = NULL; |
| 23667 | ctxt->userData = ctx; |
| 23668 | } |
| 23669 | |
| 23670 | /** |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 23671 | * xmlSchemaGetValidErrors: |
| 23672 | * @ctxt: a XML-Schema validation context |
| 23673 | * @err: the error function result |
| 23674 | * @warn: the warning function result |
| 23675 | * @ctx: the functions context result |
| 23676 | * |
| 23677 | * Get the error and warning callback informations |
| 23678 | * |
| 23679 | * Returns -1 in case of error and 0 otherwise |
| 23680 | */ |
| 23681 | int |
| 23682 | xmlSchemaGetValidErrors(xmlSchemaValidCtxtPtr ctxt, |
| 23683 | xmlSchemaValidityErrorFunc * err, |
| 23684 | xmlSchemaValidityWarningFunc * warn, void **ctx) |
| 23685 | { |
| 23686 | if (ctxt == NULL) |
| 23687 | return (-1); |
| 23688 | if (err != NULL) |
| 23689 | *err = ctxt->error; |
| 23690 | if (warn != NULL) |
| 23691 | *warn = ctxt->warning; |
| 23692 | if (ctx != NULL) |
| 23693 | *ctx = ctxt->userData; |
| 23694 | return (0); |
| 23695 | } |
| 23696 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 23697 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 23698 | /** |
Daniel Veillard | 6927b10 | 2004-10-27 17:29:04 +0000 | [diff] [blame] | 23699 | * xmlSchemaSetValidOptions: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 23700 | * @ctxt: a schema validation context |
| 23701 | * @options: a combination of xmlSchemaValidOption |
| 23702 | * |
| 23703 | * Sets the options to be used during the validation. |
| 23704 | * |
| 23705 | * Returns 0 in case of success, -1 in case of an |
| 23706 | * API error. |
| 23707 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 23708 | int |
| 23709 | xmlSchemaSetValidOptions(xmlSchemaValidCtxtPtr ctxt, |
| 23710 | int options) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23711 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 23712 | { |
| 23713 | int i; |
| 23714 | |
| 23715 | if (ctxt == NULL) |
| 23716 | return (-1); |
| 23717 | /* |
| 23718 | * WARNING: Change the start value if adding to the |
| 23719 | * xmlSchemaValidOption. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 23720 | * TODO: Is there an other, more easy to maintain, |
| 23721 | * way? |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 23722 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 23723 | for (i = 1; i < (int) sizeof(int) * 8; i++) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23724 | if (options & 1<<i) |
| 23725 | return (-1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 23726 | } |
| 23727 | ctxt->options = options; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23728 | return (0); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 23729 | } |
| 23730 | |
| 23731 | /** |
Daniel Veillard | 6927b10 | 2004-10-27 17:29:04 +0000 | [diff] [blame] | 23732 | * xmlSchemaValidCtxtGetOptions: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23733 | * @ctxt: a schema validation context |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 23734 | * |
William M. Brack | 21e4ef2 | 2005-01-02 09:53:13 +0000 | [diff] [blame] | 23735 | * Get the validation context options. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23736 | * |
William M. Brack | 21e4ef2 | 2005-01-02 09:53:13 +0000 | [diff] [blame] | 23737 | * Returns the option combination or -1 on error. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 23738 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 23739 | int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 23740 | xmlSchemaValidCtxtGetOptions(xmlSchemaValidCtxtPtr ctxt) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23741 | |
| 23742 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 23743 | if (ctxt == NULL) |
| 23744 | return (-1); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23745 | else |
| 23746 | return (ctxt->options); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 23747 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 23748 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23749 | static int |
| 23750 | xmlSchemaVDocWalk(xmlSchemaValidCtxtPtr vctxt) |
| 23751 | { |
| 23752 | xmlAttrPtr attr; |
| 23753 | int ret = 0; |
| 23754 | xmlSchemaNodeInfoPtr ielem = NULL; |
| 23755 | xmlNodePtr node, valRoot; |
| 23756 | const xmlChar *nsName; |
| 23757 | |
| 23758 | /* DOC VAL TODO: Move this to the start function. */ |
| 23759 | valRoot = xmlDocGetRootElement(vctxt->doc); |
| 23760 | if (valRoot == NULL) { |
| 23761 | /* VAL TODO: Error code? */ |
| 23762 | VERROR(1, NULL, "The document has no document element"); |
| 23763 | return (1); |
| 23764 | } |
| 23765 | vctxt->depth = -1; |
| 23766 | vctxt->validationRoot = valRoot; |
| 23767 | node = valRoot; |
| 23768 | while (node != NULL) { |
| 23769 | if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth)) |
| 23770 | goto next_sibling; |
| 23771 | if (node->type == XML_ELEMENT_NODE) { |
| 23772 | |
| 23773 | /* |
| 23774 | * Init the node-info. |
| 23775 | */ |
Kasimier T. Buchcik | 84a56e3 | 2005-06-16 12:44:35 +0000 | [diff] [blame] | 23776 | vctxt->depth++; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23777 | if (xmlSchemaValidatorPushElem(vctxt) == -1) |
| 23778 | goto internal_error; |
| 23779 | ielem = vctxt->inode; |
| 23780 | ielem->node = node; |
| 23781 | ielem->localName = node->name; |
| 23782 | if (node->ns != NULL) |
| 23783 | ielem->nsName = node->ns->href; |
| 23784 | ielem->flags |= XML_SCHEMA_ELEM_INFO_EMPTY; |
| 23785 | /* |
| 23786 | * Register attributes. |
| 23787 | * DOC VAL TODO: We do not register namespace declaration |
| 23788 | * attributes yet. |
| 23789 | */ |
| 23790 | vctxt->nbAttrInfos = 0; |
| 23791 | if (node->properties != NULL) { |
| 23792 | attr = node->properties; |
| 23793 | do { |
| 23794 | if (attr->ns != NULL) |
| 23795 | nsName = attr->ns->href; |
| 23796 | else |
| 23797 | nsName = NULL; |
| 23798 | ret = xmlSchemaValidatorPushAttribute(vctxt, |
| 23799 | (xmlNodePtr) attr, |
| 23800 | attr->name, nsName, 0, |
| 23801 | xmlNodeListGetString(attr->doc, attr->children, 1), 1); |
| 23802 | if (ret == -1) { |
| 23803 | VERROR_INT("xmlSchemaDocWalk", |
| 23804 | "calling xmlSchemaValidatorPushAttribute()"); |
| 23805 | goto internal_error; |
| 23806 | } |
| 23807 | attr = attr->next; |
| 23808 | } while (attr); |
| 23809 | } |
| 23810 | /* |
| 23811 | * Validate the element. |
| 23812 | */ |
| 23813 | ret = xmlSchemaValidateElem(vctxt); |
| 23814 | if (ret != 0) { |
| 23815 | if (ret == -1) { |
| 23816 | VERROR_INT("xmlSchemaDocWalk", |
| 23817 | "calling xmlSchemaValidateElem()"); |
| 23818 | goto internal_error; |
| 23819 | } |
| 23820 | /* |
| 23821 | * Don't stop validation; just skip the content |
| 23822 | * of this element. |
| 23823 | */ |
| 23824 | goto leave_node; |
| 23825 | } |
| 23826 | if ((vctxt->skipDepth != -1) && |
| 23827 | (vctxt->depth >= vctxt->skipDepth)) |
| 23828 | goto leave_node; |
| 23829 | } else if ((node->type == XML_TEXT_NODE) || |
| 23830 | (node->type == XML_CDATA_SECTION_NODE)) { |
| 23831 | /* |
| 23832 | * Process character content. |
| 23833 | */ |
| 23834 | if (ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY) |
| 23835 | ielem->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY; |
| 23836 | ret = xmlSchemaVPushText(vctxt, node->type, node->content, |
| 23837 | -1, XML_SCHEMA_PUSH_TEXT_PERSIST, NULL); |
| 23838 | if (ret < 0) { |
| 23839 | VERROR_INT("xmlSchemaVDocWalk", |
| 23840 | "calling xmlSchemaVPushText()"); |
| 23841 | goto internal_error; |
| 23842 | } |
| 23843 | /* |
| 23844 | * DOC VAL TODO: Should we skip further validation of the |
| 23845 | * element content here? |
| 23846 | */ |
| 23847 | } else if ((node->type == XML_ENTITY_NODE) || |
| 23848 | (node->type == XML_ENTITY_REF_NODE)) { |
| 23849 | /* |
| 23850 | * DOC VAL TODO: What to do with entities? |
| 23851 | */ |
| 23852 | TODO |
| 23853 | } else { |
| 23854 | goto leave_node; |
| 23855 | /* |
| 23856 | * DOC VAL TODO: XInclude nodes, etc. |
| 23857 | */ |
| 23858 | } |
| 23859 | /* |
| 23860 | * Walk the doc. |
| 23861 | */ |
| 23862 | if (node->children != NULL) { |
| 23863 | node = node->children; |
| 23864 | continue; |
| 23865 | } |
| 23866 | leave_node: |
| 23867 | if (node->type == XML_ELEMENT_NODE) { |
| 23868 | /* |
| 23869 | * Leaving the scope of an element. |
| 23870 | */ |
| 23871 | if (node != vctxt->inode->node) { |
| 23872 | VERROR_INT("xmlSchemaVDocWalk", |
| 23873 | "element position mismatch"); |
| 23874 | goto internal_error; |
| 23875 | } |
| 23876 | ret = xmlSchemaValidatorPopElem(vctxt); |
| 23877 | if (ret != 0) { |
| 23878 | if (ret < 0) { |
| 23879 | VERROR_INT("xmlSchemaVDocWalk", |
| 23880 | "calling xmlSchemaValidatorPopElem()"); |
| 23881 | goto internal_error; |
| 23882 | } |
| 23883 | } |
| 23884 | if (node == valRoot) |
| 23885 | goto exit; |
| 23886 | } |
| 23887 | next_sibling: |
| 23888 | if (node->next != NULL) |
| 23889 | node = node->next; |
| 23890 | else { |
| 23891 | node = node->parent; |
| 23892 | goto leave_node; |
| 23893 | } |
| 23894 | } |
| 23895 | |
| 23896 | exit: |
| 23897 | return (ret); |
| 23898 | internal_error: |
| 23899 | return (-1); |
| 23900 | } |
| 23901 | |
| 23902 | static int |
Daniel Veillard | f10ae12 | 2005-07-10 19:03:16 +0000 | [diff] [blame] | 23903 | xmlSchemaPreRun(xmlSchemaValidCtxtPtr vctxt) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23904 | /* |
| 23905 | * Some initialization. |
| 23906 | */ |
| 23907 | vctxt->err = 0; |
| 23908 | vctxt->nberrors = 0; |
| 23909 | vctxt->depth = -1; |
| 23910 | vctxt->skipDepth = -1; |
| 23911 | /* |
| 23912 | * Create a schema + parser if necessary. |
| 23913 | */ |
| 23914 | if (vctxt->schema == NULL) { |
| 23915 | |
| 23916 | if ((vctxt->pctxt == NULL) && |
| 23917 | (xmlSchemaCreatePCtxtOnVCtxt(vctxt) == -1)) |
| 23918 | return (-1); |
| 23919 | |
| 23920 | vctxt->schema = xmlSchemaNewSchema(vctxt->pctxt); |
| 23921 | if (vctxt->schema == NULL) { |
| 23922 | VERROR_INT("xmlSchemaVStartValidation", |
| 23923 | "creating a schema"); |
| 23924 | return (-1); |
| 23925 | } |
| 23926 | vctxt->xsiAssemble = 1; |
| 23927 | } else |
| 23928 | vctxt->xsiAssemble = 0; |
| 23929 | /* |
| 23930 | * Augment the IDC definitions. |
| 23931 | */ |
| 23932 | if (vctxt->schema->idcDef != NULL) { |
| 23933 | xmlHashScan(vctxt->schema->idcDef, |
| 23934 | (xmlHashScanner) xmlSchemaAugmentIDC, vctxt); |
| 23935 | } |
Daniel Veillard | f10ae12 | 2005-07-10 19:03:16 +0000 | [diff] [blame] | 23936 | return(0); |
| 23937 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23938 | |
Daniel Veillard | f10ae12 | 2005-07-10 19:03:16 +0000 | [diff] [blame] | 23939 | static void |
| 23940 | xmlSchemaPostRun(xmlSchemaValidCtxtPtr vctxt) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23941 | if (vctxt->xsiAssemble) { |
| 23942 | if (vctxt->schema != NULL) { |
| 23943 | xmlSchemaFree(vctxt->schema); |
| 23944 | vctxt->schema = NULL; |
| 23945 | } |
| 23946 | } |
| 23947 | xmlSchemaClearValidCtxt(vctxt); |
Daniel Veillard | f10ae12 | 2005-07-10 19:03:16 +0000 | [diff] [blame] | 23948 | } |
| 23949 | |
| 23950 | static int |
| 23951 | xmlSchemaVStart(xmlSchemaValidCtxtPtr vctxt) |
| 23952 | { |
| 23953 | int ret = 0; |
| 23954 | |
| 23955 | if (xmlSchemaPreRun(vctxt) < 0) |
| 23956 | return(-1); |
| 23957 | |
| 23958 | if (vctxt->doc != NULL) { |
| 23959 | /* |
| 23960 | * Tree validation. |
| 23961 | */ |
| 23962 | ret = xmlSchemaVDocWalk(vctxt); |
| 23963 | #ifdef LIBXML_READER_ENABLED |
| 23964 | } else if (vctxt->reader != NULL) { |
| 23965 | /* |
| 23966 | * XML Reader validation. |
| 23967 | */ |
| 23968 | #ifdef XML_SCHEMA_READER_ENABLED |
| 23969 | ret = xmlSchemaVReaderWalk(vctxt); |
| 23970 | #endif |
| 23971 | #endif |
| 23972 | } else if ((vctxt->sax != NULL) && (vctxt->parserCtxt != NULL)) { |
| 23973 | /* |
| 23974 | * SAX validation. |
| 23975 | */ |
| 23976 | ret = xmlParseDocument(vctxt->parserCtxt); |
| 23977 | } else { |
| 23978 | VERROR_INT("xmlSchemaVStartValidation", |
| 23979 | "no instance to validate"); |
| 23980 | ret = -1; |
| 23981 | } |
| 23982 | |
| 23983 | xmlSchemaPostRun(vctxt); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 23984 | if (ret == 0) |
| 23985 | ret = vctxt->err; |
| 23986 | return (ret); |
| 23987 | } |
| 23988 | |
| 23989 | /** |
| 23990 | * xmlSchemaValidateOneElement: |
| 23991 | * @ctxt: a schema validation context |
| 23992 | * @elem: an element node |
| 23993 | * |
| 23994 | * Validate a branch of a tree, starting with the given @elem. |
| 23995 | * |
| 23996 | * Returns 0 if the element and its subtree is valid, a positive error |
| 23997 | * code number otherwise and -1 in case of an internal or API error. |
| 23998 | */ |
| 23999 | int |
| 24000 | xmlSchemaValidateOneElement(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem) |
| 24001 | { |
| 24002 | if ((ctxt == NULL) || (elem == NULL) || (elem->type != XML_ELEMENT_NODE)) |
| 24003 | return (-1); |
| 24004 | |
| 24005 | if (ctxt->schema == NULL) |
| 24006 | return (-1); |
| 24007 | |
| 24008 | ctxt->doc = elem->doc; |
| 24009 | ctxt->node = elem; |
| 24010 | ctxt->validationRoot = elem; |
| 24011 | return(xmlSchemaVStart(ctxt)); |
| 24012 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 24013 | |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 24014 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 24015 | * xmlSchemaValidateDoc: |
| 24016 | * @ctxt: a schema validation context |
| 24017 | * @doc: a parsed document tree |
| 24018 | * |
| 24019 | * Validate a document tree in memory. |
| 24020 | * |
| 24021 | * Returns 0 if the document is schemas valid, a positive error code |
| 24022 | * number otherwise and -1 in case of internal or API error. |
| 24023 | */ |
| 24024 | int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 24025 | xmlSchemaValidateDoc(xmlSchemaValidCtxtPtr ctxt, xmlDocPtr doc) |
| 24026 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 24027 | if ((ctxt == NULL) || (doc == NULL)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 24028 | return (-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 24029 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 24030 | ctxt->doc = doc; |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 24031 | ctxt->node = xmlDocGetRootElement(doc); |
| 24032 | if (ctxt->node == NULL) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 24033 | xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) ctxt, |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 24034 | XML_SCHEMAV_DOCUMENT_ELEMENT_MISSING, |
| 24035 | (xmlNodePtr) doc, NULL, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 24036 | "The document has no document element", NULL, NULL); |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 24037 | return (ctxt->err); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 24038 | } |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 24039 | ctxt->validationRoot = ctxt->node; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 24040 | return (xmlSchemaVStart(ctxt)); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 24041 | } |
| 24042 | |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24043 | |
| 24044 | /************************************************************************ |
| 24045 | * * |
| 24046 | * Function and data for SAX streaming API * |
| 24047 | * * |
| 24048 | ************************************************************************/ |
| 24049 | typedef struct _xmlSchemaSplitSAXData xmlSchemaSplitSAXData; |
| 24050 | typedef xmlSchemaSplitSAXData *xmlSchemaSplitSAXDataPtr; |
| 24051 | |
| 24052 | struct _xmlSchemaSplitSAXData { |
| 24053 | xmlSAXHandlerPtr user_sax; |
| 24054 | void *user_data; |
| 24055 | xmlSchemaValidCtxtPtr ctxt; |
| 24056 | xmlSAXHandlerPtr schemas_sax; |
| 24057 | }; |
| 24058 | |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24059 | #define XML_SAX_PLUG_MAGIC 0xdc43ba21 |
| 24060 | |
| 24061 | struct _xmlSchemaSAXPlug { |
| 24062 | unsigned int magic; |
| 24063 | |
| 24064 | /* the original callbacks informations */ |
| 24065 | xmlSAXHandlerPtr *user_sax_ptr; |
| 24066 | xmlSAXHandlerPtr user_sax; |
| 24067 | void **user_data_ptr; |
| 24068 | void *user_data; |
| 24069 | |
| 24070 | /* the block plugged back and validation informations */ |
| 24071 | xmlSAXHandler schemas_sax; |
| 24072 | xmlSchemaValidCtxtPtr ctxt; |
| 24073 | }; |
| 24074 | |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24075 | /* All those functions just bounces to the user provided SAX handlers */ |
| 24076 | static void |
| 24077 | internalSubsetSplit(void *ctx, const xmlChar *name, |
| 24078 | const xmlChar *ExternalID, const xmlChar *SystemID) |
| 24079 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24080 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24081 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24082 | (ctxt->user_sax->internalSubset != NULL)) |
| 24083 | ctxt->user_sax->internalSubset(ctxt->user_data, name, ExternalID, |
| 24084 | SystemID); |
| 24085 | } |
| 24086 | |
| 24087 | static int |
| 24088 | isStandaloneSplit(void *ctx) |
| 24089 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24090 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24091 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24092 | (ctxt->user_sax->isStandalone != NULL)) |
| 24093 | return(ctxt->user_sax->isStandalone(ctxt->user_data)); |
| 24094 | return(0); |
| 24095 | } |
| 24096 | |
| 24097 | static int |
| 24098 | hasInternalSubsetSplit(void *ctx) |
| 24099 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24100 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24101 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24102 | (ctxt->user_sax->hasInternalSubset != NULL)) |
| 24103 | return(ctxt->user_sax->hasInternalSubset(ctxt->user_data)); |
| 24104 | return(0); |
| 24105 | } |
| 24106 | |
| 24107 | static int |
| 24108 | hasExternalSubsetSplit(void *ctx) |
| 24109 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24110 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24111 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24112 | (ctxt->user_sax->hasExternalSubset != NULL)) |
| 24113 | return(ctxt->user_sax->hasExternalSubset(ctxt->user_data)); |
| 24114 | return(0); |
| 24115 | } |
| 24116 | |
| 24117 | static void |
| 24118 | externalSubsetSplit(void *ctx, const xmlChar *name, |
| 24119 | const xmlChar *ExternalID, const xmlChar *SystemID) |
| 24120 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24121 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24122 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24123 | (ctxt->user_sax->internalSubset != NULL)) |
| 24124 | ctxt->user_sax->internalSubset(ctxt->user_data, name, ExternalID, |
| 24125 | SystemID); |
| 24126 | } |
| 24127 | |
| 24128 | static xmlParserInputPtr |
| 24129 | resolveEntitySplit(void *ctx, const xmlChar *publicId, const xmlChar *systemId) |
| 24130 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24131 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24132 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24133 | (ctxt->user_sax->resolveEntity != NULL)) |
| 24134 | return(ctxt->user_sax->resolveEntity(ctxt->user_data, publicId, |
| 24135 | systemId)); |
| 24136 | return(NULL); |
| 24137 | } |
| 24138 | |
| 24139 | static xmlEntityPtr |
| 24140 | getEntitySplit(void *ctx, const xmlChar *name) |
| 24141 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24142 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24143 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24144 | (ctxt->user_sax->getEntity != NULL)) |
| 24145 | return(ctxt->user_sax->getEntity(ctxt->user_data, name)); |
| 24146 | return(NULL); |
| 24147 | } |
| 24148 | |
| 24149 | static xmlEntityPtr |
| 24150 | getParameterEntitySplit(void *ctx, const xmlChar *name) |
| 24151 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24152 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24153 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24154 | (ctxt->user_sax->getParameterEntity != NULL)) |
| 24155 | return(ctxt->user_sax->getParameterEntity(ctxt->user_data, name)); |
| 24156 | return(NULL); |
| 24157 | } |
| 24158 | |
| 24159 | |
| 24160 | static void |
| 24161 | entityDeclSplit(void *ctx, const xmlChar *name, int type, |
| 24162 | const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) |
| 24163 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24164 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24165 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24166 | (ctxt->user_sax->entityDecl != NULL)) |
| 24167 | ctxt->user_sax->entityDecl(ctxt->user_data, name, type, publicId, |
| 24168 | systemId, content); |
| 24169 | } |
| 24170 | |
| 24171 | static void |
| 24172 | attributeDeclSplit(void *ctx, const xmlChar * elem, |
| 24173 | const xmlChar * name, int type, int def, |
| 24174 | const xmlChar * defaultValue, xmlEnumerationPtr tree) |
| 24175 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24176 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24177 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24178 | (ctxt->user_sax->attributeDecl != NULL)) { |
| 24179 | ctxt->user_sax->attributeDecl(ctxt->user_data, elem, name, type, |
| 24180 | def, defaultValue, tree); |
| 24181 | } else { |
| 24182 | xmlFreeEnumeration(tree); |
| 24183 | } |
| 24184 | } |
| 24185 | |
| 24186 | static void |
| 24187 | elementDeclSplit(void *ctx, const xmlChar *name, int type, |
| 24188 | xmlElementContentPtr content) |
| 24189 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24190 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24191 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24192 | (ctxt->user_sax->elementDecl != NULL)) |
| 24193 | ctxt->user_sax->elementDecl(ctxt->user_data, name, type, content); |
| 24194 | } |
| 24195 | |
| 24196 | static void |
| 24197 | notationDeclSplit(void *ctx, const xmlChar *name, |
| 24198 | const xmlChar *publicId, const xmlChar *systemId) |
| 24199 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24200 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24201 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24202 | (ctxt->user_sax->notationDecl != NULL)) |
| 24203 | ctxt->user_sax->notationDecl(ctxt->user_data, name, publicId, |
| 24204 | systemId); |
| 24205 | } |
| 24206 | |
| 24207 | static void |
| 24208 | unparsedEntityDeclSplit(void *ctx, const xmlChar *name, |
| 24209 | const xmlChar *publicId, const xmlChar *systemId, |
| 24210 | const xmlChar *notationName) |
| 24211 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24212 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24213 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24214 | (ctxt->user_sax->unparsedEntityDecl != NULL)) |
| 24215 | ctxt->user_sax->unparsedEntityDecl(ctxt->user_data, name, publicId, |
| 24216 | systemId, notationName); |
| 24217 | } |
| 24218 | |
| 24219 | static void |
| 24220 | setDocumentLocatorSplit(void *ctx, xmlSAXLocatorPtr loc) |
| 24221 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24222 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24223 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24224 | (ctxt->user_sax->setDocumentLocator != NULL)) |
| 24225 | ctxt->user_sax->setDocumentLocator(ctxt->user_data, loc); |
| 24226 | } |
| 24227 | |
| 24228 | static void |
| 24229 | startDocumentSplit(void *ctx) |
| 24230 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24231 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24232 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24233 | (ctxt->user_sax->startDocument != NULL)) |
| 24234 | ctxt->user_sax->startDocument(ctxt->user_data); |
| 24235 | } |
| 24236 | |
| 24237 | static void |
| 24238 | endDocumentSplit(void *ctx) |
| 24239 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24240 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24241 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24242 | (ctxt->user_sax->endDocument != NULL)) |
| 24243 | ctxt->user_sax->endDocument(ctxt->user_data); |
| 24244 | } |
| 24245 | |
| 24246 | static void |
| 24247 | processingInstructionSplit(void *ctx, const xmlChar *target, |
| 24248 | const xmlChar *data) |
| 24249 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24250 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24251 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24252 | (ctxt->user_sax->processingInstruction != NULL)) |
| 24253 | ctxt->user_sax->processingInstruction(ctxt->user_data, target, data); |
| 24254 | } |
| 24255 | |
| 24256 | static void |
| 24257 | commentSplit(void *ctx, const xmlChar *value) |
| 24258 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24259 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24260 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24261 | (ctxt->user_sax->comment != NULL)) |
| 24262 | ctxt->user_sax->comment(ctxt->user_data, value); |
| 24263 | } |
| 24264 | |
| 24265 | /* |
| 24266 | * Varargs error callbacks to the user application, harder ... |
| 24267 | */ |
| 24268 | |
| 24269 | static void |
| 24270 | warningSplit(void *ctx, const char *msg, ...) { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24271 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24272 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24273 | (ctxt->user_sax->warning != NULL)) { |
| 24274 | TODO |
| 24275 | } |
| 24276 | } |
| 24277 | static void |
| 24278 | errorSplit(void *ctx, const char *msg, ...) { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24279 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24280 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24281 | (ctxt->user_sax->error != NULL)) { |
| 24282 | TODO |
| 24283 | } |
| 24284 | } |
| 24285 | static void |
| 24286 | fatalErrorSplit(void *ctx, const char *msg, ...) { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24287 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24288 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24289 | (ctxt->user_sax->fatalError != NULL)) { |
| 24290 | TODO |
| 24291 | } |
| 24292 | } |
| 24293 | |
| 24294 | /* |
| 24295 | * Those are function where both the user handler and the schemas handler |
| 24296 | * need to be called. |
| 24297 | */ |
| 24298 | static void |
| 24299 | charactersSplit(void *ctx, const xmlChar *ch, int len) |
| 24300 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24301 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24302 | if (ctxt == NULL) |
| 24303 | return; |
| 24304 | if ((ctxt->user_sax != NULL) && (ctxt->user_sax->characters != NULL)) |
| 24305 | ctxt->user_sax->characters(ctxt->user_data, ch, len); |
| 24306 | if (ctxt->ctxt != NULL) |
| 24307 | xmlSchemaSAXHandleText(ctxt->ctxt, ch, len); |
| 24308 | } |
| 24309 | |
| 24310 | static void |
| 24311 | ignorableWhitespaceSplit(void *ctx, const xmlChar *ch, int len) |
| 24312 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24313 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24314 | if (ctxt == NULL) |
| 24315 | return; |
| 24316 | if ((ctxt->user_sax != NULL) && |
| 24317 | (ctxt->user_sax->ignorableWhitespace != NULL)) |
| 24318 | ctxt->user_sax->ignorableWhitespace(ctxt->user_data, ch, len); |
| 24319 | if (ctxt->ctxt != NULL) |
| 24320 | xmlSchemaSAXHandleText(ctxt->ctxt, ch, len); |
| 24321 | } |
| 24322 | |
| 24323 | static void |
| 24324 | cdataBlockSplit(void *ctx, const xmlChar *value, int len) |
| 24325 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24326 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24327 | if (ctxt == NULL) |
| 24328 | return; |
| 24329 | if ((ctxt->user_sax != NULL) && |
| 24330 | (ctxt->user_sax->ignorableWhitespace != NULL)) |
| 24331 | ctxt->user_sax->ignorableWhitespace(ctxt->user_data, value, len); |
| 24332 | if (ctxt->ctxt != NULL) |
| 24333 | xmlSchemaSAXHandleCDataSection(ctxt->ctxt, value, len); |
| 24334 | } |
| 24335 | |
| 24336 | static void |
| 24337 | referenceSplit(void *ctx, const xmlChar *name) |
| 24338 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24339 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24340 | if ((ctxt != NULL) && (ctxt->user_sax != NULL) && |
| 24341 | (ctxt->user_sax->reference != NULL)) |
| 24342 | ctxt->user_sax->reference(ctxt->user_data, name); |
| 24343 | if (ctxt->ctxt != NULL) |
| 24344 | xmlSchemaSAXHandleReference(ctxt->user_data, name); |
| 24345 | } |
| 24346 | |
| 24347 | static void |
| 24348 | startElementNsSplit(void *ctx, const xmlChar * localname, |
| 24349 | const xmlChar * prefix, const xmlChar * URI, |
| 24350 | int nb_namespaces, const xmlChar ** namespaces, |
| 24351 | int nb_attributes, int nb_defaulted, |
| 24352 | const xmlChar ** attributes) { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24353 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24354 | if (ctxt == NULL) |
| 24355 | return; |
| 24356 | if ((ctxt->user_sax != NULL) && |
| 24357 | (ctxt->user_sax->startElementNs != NULL)) |
| 24358 | ctxt->user_sax->startElementNs(ctxt->user_data, localname, prefix, |
| 24359 | URI, nb_namespaces, namespaces, |
| 24360 | nb_attributes, nb_defaulted, |
| 24361 | attributes); |
| 24362 | if (ctxt->ctxt != NULL) |
| 24363 | xmlSchemaSAXHandleStartElementNs(ctxt->ctxt, localname, prefix, |
| 24364 | URI, nb_namespaces, namespaces, |
| 24365 | nb_attributes, nb_defaulted, |
| 24366 | attributes); |
| 24367 | } |
| 24368 | |
| 24369 | static void |
| 24370 | endElementNsSplit(void *ctx, const xmlChar * localname, |
| 24371 | const xmlChar * prefix, const xmlChar * URI) { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24372 | xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24373 | if (ctxt == NULL) |
| 24374 | return; |
| 24375 | if ((ctxt->user_sax != NULL) && |
| 24376 | (ctxt->user_sax->endElementNs != NULL)) |
| 24377 | ctxt->user_sax->endElementNs(ctxt->user_data, localname, prefix, URI); |
| 24378 | if (ctxt->ctxt != NULL) |
| 24379 | xmlSchemaSAXHandleEndElementNs(ctxt->ctxt, localname, prefix, URI); |
| 24380 | } |
| 24381 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 24382 | /** |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24383 | * xmlSchemaSAXPlug: |
| 24384 | * @ctxt: a schema validation context |
Daniel Veillard | 1f33c4d | 2005-07-10 21:38:31 +0000 | [diff] [blame] | 24385 | * @sax: a pointer to the original xmlSAXHandlerPtr |
| 24386 | * @user_data: a pointer to the original SAX user data pointer |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24387 | * |
| 24388 | * Plug a SAX based validation layer in a SAX parsing event flow. |
| 24389 | * The original @saxptr and @dataptr data are replaced by new pointers |
| 24390 | * but the calls to the original will be maintained. |
| 24391 | * |
| 24392 | * Returns a pointer to a data structure needed to unplug the validation layer |
| 24393 | * or NULL in case of errors. |
| 24394 | */ |
| 24395 | xmlSchemaSAXPlugPtr |
| 24396 | xmlSchemaSAXPlug(xmlSchemaValidCtxtPtr ctxt, |
| 24397 | xmlSAXHandlerPtr *sax, void **user_data) |
| 24398 | { |
| 24399 | xmlSchemaSAXPlugPtr ret; |
| 24400 | xmlSAXHandlerPtr old_sax; |
| 24401 | |
| 24402 | if ((ctxt == NULL) || (sax == NULL) || (user_data == NULL)) |
| 24403 | return(NULL); |
| 24404 | |
| 24405 | /* |
| 24406 | * We only allow to plug into SAX2 event streams |
| 24407 | */ |
| 24408 | old_sax = *sax; |
| 24409 | if ((old_sax != NULL) && (old_sax->initialized != XML_SAX2_MAGIC)) |
| 24410 | return(NULL); |
| 24411 | if ((old_sax != NULL) && |
| 24412 | (old_sax->startElementNs == NULL) && (old_sax->endElementNs == NULL) && |
| 24413 | ((old_sax->startElement != NULL) || (old_sax->endElement != NULL))) |
| 24414 | return(NULL); |
| 24415 | |
| 24416 | /* |
| 24417 | * everything seems right allocate the local data needed for that layer |
| 24418 | */ |
| 24419 | ret = (xmlSchemaSAXPlugPtr) xmlMalloc(sizeof(xmlSchemaSAXPlugStruct)); |
| 24420 | if (ret == NULL) { |
| 24421 | return(NULL); |
| 24422 | } |
| 24423 | memset(ret, 0, sizeof(xmlSchemaSAXPlugStruct)); |
| 24424 | ret->magic = XML_SAX_PLUG_MAGIC; |
| 24425 | ret->schemas_sax.initialized = XML_SAX2_MAGIC; |
| 24426 | ret->ctxt = ctxt; |
| 24427 | ret->user_sax_ptr = sax; |
| 24428 | ret->user_sax = old_sax; |
| 24429 | if (old_sax == NULL) { |
| 24430 | /* |
| 24431 | * go direct, no need for the split block and functions. |
| 24432 | */ |
| 24433 | ret->schemas_sax.startElementNs = xmlSchemaSAXHandleStartElementNs; |
| 24434 | ret->schemas_sax.endElementNs = xmlSchemaSAXHandleEndElementNs; |
| 24435 | /* |
| 24436 | * Note that we use the same text-function for both, to prevent |
| 24437 | * the parser from testing for ignorable whitespace. |
| 24438 | */ |
| 24439 | ret->schemas_sax.ignorableWhitespace = xmlSchemaSAXHandleText; |
| 24440 | ret->schemas_sax.characters = xmlSchemaSAXHandleText; |
| 24441 | |
| 24442 | ret->schemas_sax.cdataBlock = xmlSchemaSAXHandleCDataSection; |
| 24443 | ret->schemas_sax.reference = xmlSchemaSAXHandleReference; |
| 24444 | |
| 24445 | ret->user_data = ctxt; |
| 24446 | *user_data = ctxt; |
| 24447 | } else { |
| 24448 | /* |
| 24449 | * for each callback unused by Schemas initialize it to the Split |
| 24450 | * routine only if non NULL in the user block, this can speed up |
| 24451 | * things at the SAX level. |
| 24452 | */ |
| 24453 | if (old_sax->internalSubset != NULL) |
| 24454 | ret->schemas_sax.internalSubset = internalSubsetSplit; |
| 24455 | if (old_sax->isStandalone != NULL) |
| 24456 | ret->schemas_sax.isStandalone = isStandaloneSplit; |
| 24457 | if (old_sax->hasInternalSubset != NULL) |
| 24458 | ret->schemas_sax.hasInternalSubset = hasInternalSubsetSplit; |
| 24459 | if (old_sax->hasExternalSubset != NULL) |
| 24460 | ret->schemas_sax.hasExternalSubset = hasExternalSubsetSplit; |
| 24461 | if (old_sax->resolveEntity != NULL) |
| 24462 | ret->schemas_sax.resolveEntity = resolveEntitySplit; |
| 24463 | if (old_sax->getEntity != NULL) |
| 24464 | ret->schemas_sax.getEntity = getEntitySplit; |
| 24465 | if (old_sax->entityDecl != NULL) |
| 24466 | ret->schemas_sax.entityDecl = entityDeclSplit; |
| 24467 | if (old_sax->notationDecl != NULL) |
| 24468 | ret->schemas_sax.notationDecl = notationDeclSplit; |
| 24469 | if (old_sax->attributeDecl != NULL) |
| 24470 | ret->schemas_sax.attributeDecl = attributeDeclSplit; |
| 24471 | if (old_sax->elementDecl != NULL) |
| 24472 | ret->schemas_sax.elementDecl = elementDeclSplit; |
| 24473 | if (old_sax->unparsedEntityDecl != NULL) |
| 24474 | ret->schemas_sax.unparsedEntityDecl = unparsedEntityDeclSplit; |
| 24475 | if (old_sax->setDocumentLocator != NULL) |
| 24476 | ret->schemas_sax.setDocumentLocator = setDocumentLocatorSplit; |
| 24477 | if (old_sax->startDocument != NULL) |
| 24478 | ret->schemas_sax.startDocument = startDocumentSplit; |
| 24479 | if (old_sax->endDocument != NULL) |
| 24480 | ret->schemas_sax.endDocument = endDocumentSplit; |
| 24481 | if (old_sax->processingInstruction != NULL) |
| 24482 | ret->schemas_sax.processingInstruction = processingInstructionSplit; |
| 24483 | if (old_sax->comment != NULL) |
| 24484 | ret->schemas_sax.comment = commentSplit; |
| 24485 | if (old_sax->warning != NULL) |
| 24486 | ret->schemas_sax.warning = warningSplit; |
| 24487 | if (old_sax->error != NULL) |
| 24488 | ret->schemas_sax.error = errorSplit; |
| 24489 | if (old_sax->fatalError != NULL) |
| 24490 | ret->schemas_sax.fatalError = fatalErrorSplit; |
| 24491 | if (old_sax->getParameterEntity != NULL) |
| 24492 | ret->schemas_sax.getParameterEntity = getParameterEntitySplit; |
| 24493 | if (old_sax->externalSubset != NULL) |
| 24494 | ret->schemas_sax.externalSubset = externalSubsetSplit; |
| 24495 | |
| 24496 | /* |
| 24497 | * the 6 schemas callback have to go to the splitter functions |
| 24498 | * Note that we use the same text-function for ignorableWhitespace |
| 24499 | * if possible, to prevent the parser from testing for ignorable |
| 24500 | * whitespace. |
| 24501 | */ |
| 24502 | ret->schemas_sax.characters = charactersSplit; |
| 24503 | if ((old_sax->ignorableWhitespace != NULL) && |
| 24504 | (old_sax->ignorableWhitespace != old_sax->characters)) |
| 24505 | ret->schemas_sax.ignorableWhitespace = ignorableWhitespaceSplit; |
| 24506 | else |
| 24507 | ret->schemas_sax.ignorableWhitespace = charactersSplit; |
| 24508 | ret->schemas_sax.cdataBlock = cdataBlockSplit; |
| 24509 | ret->schemas_sax.reference = referenceSplit; |
| 24510 | ret->schemas_sax.startElementNs = startElementNsSplit; |
| 24511 | ret->schemas_sax.endElementNs = endElementNsSplit; |
| 24512 | |
| 24513 | ret->user_data_ptr = user_data; |
| 24514 | ret->user_data = *user_data; |
| 24515 | *user_data = ret; |
| 24516 | } |
| 24517 | |
| 24518 | /* |
| 24519 | * plug the pointers back. |
| 24520 | */ |
| 24521 | *sax = &(ret->schemas_sax); |
Daniel Veillard | f10ae12 | 2005-07-10 19:03:16 +0000 | [diff] [blame] | 24522 | ctxt->sax = *sax; |
| 24523 | ctxt->flags |= XML_SCHEMA_VALID_CTXT_FLAG_STREAM; |
| 24524 | xmlSchemaPreRun(ctxt); |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24525 | return(ret); |
| 24526 | } |
| 24527 | |
| 24528 | /** |
| 24529 | * xmlSchemaSAXUnplug: |
| 24530 | * @plug: a data structure returned by xmlSchemaSAXPlug |
| 24531 | * |
| 24532 | * Unplug a SAX based validation layer in a SAX parsing event flow. |
| 24533 | * The original pointers used in the call are restored. |
| 24534 | * |
| 24535 | * Returns 0 in case of success and -1 in case of failure. |
| 24536 | */ |
| 24537 | int |
| 24538 | xmlSchemaSAXUnplug(xmlSchemaSAXPlugPtr plug) |
| 24539 | { |
| 24540 | xmlSAXHandlerPtr *sax; |
| 24541 | void **user_data; |
| 24542 | |
| 24543 | if ((plug == NULL) || (plug->magic != XML_SAX_PLUG_MAGIC)) |
| 24544 | return(-1); |
| 24545 | plug->magic = 0; |
| 24546 | |
Daniel Veillard | f10ae12 | 2005-07-10 19:03:16 +0000 | [diff] [blame] | 24547 | xmlSchemaPostRun(plug->ctxt); |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24548 | /* restore the data */ |
| 24549 | sax = plug->user_sax_ptr; |
| 24550 | *sax = plug->user_sax; |
| 24551 | if (plug->user_sax != NULL) { |
| 24552 | user_data = plug->user_data_ptr; |
| 24553 | *user_data = plug->user_data; |
| 24554 | } |
| 24555 | |
| 24556 | /* free and return */ |
| 24557 | xmlFree(plug); |
| 24558 | return(0); |
| 24559 | } |
| 24560 | |
| 24561 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 24562 | * xmlSchemaValidateStream: |
| 24563 | * @ctxt: a schema validation context |
| 24564 | * @input: the input to use for reading the data |
| 24565 | * @enc: an optional encoding information |
| 24566 | * @sax: a SAX handler for the resulting events |
| 24567 | * @user_data: the context to provide to the SAX handler. |
| 24568 | * |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24569 | * Validate an input based on a flow of SAX event from the parser |
| 24570 | * and forward the events to the @sax handler with the provided @user_data |
| 24571 | * the user provided @sax handler must be a SAX2 one. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 24572 | * |
| 24573 | * Returns 0 if the document is schemas valid, a positive error code |
| 24574 | * number otherwise and -1 in case of internal or API error. |
| 24575 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 24576 | int |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 24577 | xmlSchemaValidateStream(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 24578 | xmlParserInputBufferPtr input, xmlCharEncoding enc, |
| 24579 | xmlSAXHandlerPtr sax, void *user_data) |
| 24580 | { |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24581 | xmlSchemaSAXPlugPtr plug = NULL; |
| 24582 | xmlSAXHandlerPtr old_sax = NULL; |
| 24583 | xmlParserCtxtPtr pctxt = NULL; |
| 24584 | xmlParserInputPtr inputStream = NULL; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24585 | int ret; |
| 24586 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 24587 | if ((ctxt == NULL) || (input == NULL)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 24588 | return (-1); |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24589 | |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24590 | /* |
| 24591 | * prepare the parser |
| 24592 | */ |
| 24593 | pctxt = xmlNewParserCtxt(); |
| 24594 | if (pctxt == NULL) |
| 24595 | return (-1); |
| 24596 | old_sax = pctxt->sax; |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24597 | pctxt->sax = sax; |
| 24598 | pctxt->userData = user_data; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24599 | #if 0 |
| 24600 | if (options) |
| 24601 | xmlCtxtUseOptions(pctxt, options); |
| 24602 | #endif |
Kasimier T. Buchcik | 85aed6d | 2005-07-08 18:06:18 +0000 | [diff] [blame] | 24603 | pctxt->linenumbers = 1; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24604 | |
Daniel Veillard | f0af8ec | 2005-07-08 17:27:33 +0000 | [diff] [blame] | 24605 | inputStream = xmlNewIOInputStream(pctxt, input, enc);; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24606 | if (inputStream == NULL) { |
| 24607 | ret = -1; |
| 24608 | goto done; |
| 24609 | } |
| 24610 | inputPush(pctxt, inputStream); |
| 24611 | ctxt->parserCtxt = pctxt; |
| 24612 | ctxt->input = input; |
| 24613 | |
| 24614 | /* |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24615 | * Plug the validation and launch the parsing |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24616 | */ |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24617 | plug = xmlSchemaSAXPlug(ctxt, &(pctxt->sax), &(pctxt->userData)); |
| 24618 | if (plug == NULL) { |
| 24619 | ret = -1; |
| 24620 | goto done; |
| 24621 | } |
| 24622 | ctxt->input = input; |
| 24623 | ctxt->enc = enc; |
| 24624 | ctxt->sax = pctxt->sax; |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24625 | ctxt->flags |= XML_SCHEMA_VALID_CTXT_FLAG_STREAM; |
| 24626 | ret = xmlSchemaVStart(ctxt); |
| 24627 | |
| 24628 | if ((ret == 0) && (! ctxt->parserCtxt->wellFormed)) { |
| 24629 | ret = ctxt->parserCtxt->errNo; |
| 24630 | if (ret == 0) |
| 24631 | ret = 1; |
| 24632 | } |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24633 | |
| 24634 | done: |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24635 | ctxt->parserCtxt = NULL; |
| 24636 | ctxt->sax = NULL; |
| 24637 | ctxt->input = NULL; |
| 24638 | if (plug != NULL) { |
| 24639 | xmlSchemaSAXUnplug(plug); |
| 24640 | } |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24641 | /* cleanup */ |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 24642 | if (pctxt != NULL) { |
| 24643 | pctxt->sax = old_sax; |
| 24644 | xmlFreeParserCtxt(pctxt); |
| 24645 | } |
Daniel Veillard | cdc8273 | 2005-07-08 15:04:06 +0000 | [diff] [blame] | 24646 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 24647 | } |
| 24648 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 24649 | /** |
| 24650 | * xmlSchemaValidateFile: |
| 24651 | * @ctxt: a schema validation context |
Daniel Veillard | 81562d2 | 2005-06-15 13:27:56 +0000 | [diff] [blame] | 24652 | * @filename: the URI of the instance |
| 24653 | * @options: a future set of options, currently unused |
| 24654 | * |
| 24655 | * Do a schemas validation of the given resource, it will use the |
| 24656 | * SAX streamable validation internally. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 24657 | * |
| 24658 | * Returns 0 if the document is valid, a positive error code |
| 24659 | * number otherwise and -1 in case of an internal or API error. |
| 24660 | */ |
| 24661 | int |
| 24662 | xmlSchemaValidateFile(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | c63fbbf | 2005-06-15 12:54:05 +0000 | [diff] [blame] | 24663 | const char * filename, |
| 24664 | int options ATTRIBUTE_UNUSED) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 24665 | { |
Daniel Veillard | 81562d2 | 2005-06-15 13:27:56 +0000 | [diff] [blame] | 24666 | #ifdef XML_SCHEMA_SAX_ENABLED |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 24667 | int ret; |
Kasimier T. Buchcik | 72d3adc | 2005-07-08 16:43:37 +0000 | [diff] [blame] | 24668 | xmlParserInputBufferPtr input; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 24669 | |
| 24670 | if ((ctxt == NULL) || (filename == NULL)) |
| 24671 | return (-1); |
| 24672 | |
Kasimier T. Buchcik | 72d3adc | 2005-07-08 16:43:37 +0000 | [diff] [blame] | 24673 | input = xmlParserInputBufferCreateFilename(filename, |
| 24674 | XML_CHAR_ENCODING_NONE); |
| 24675 | if (input == NULL) |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 24676 | return (-1); |
Kasimier T. Buchcik | 72d3adc | 2005-07-08 16:43:37 +0000 | [diff] [blame] | 24677 | ret = xmlSchemaValidateStream(ctxt, input, XML_CHAR_ENCODING_NONE, |
| 24678 | NULL, NULL); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 24679 | return (ret); |
Daniel Veillard | 81562d2 | 2005-06-15 13:27:56 +0000 | [diff] [blame] | 24680 | #else |
| 24681 | return (-1); |
Kasimier T. Buchcik | c63fbbf | 2005-06-15 12:54:05 +0000 | [diff] [blame] | 24682 | #endif /* XML_SCHEMA_SAX_ENABLED */ |
Daniel Veillard | 81562d2 | 2005-06-15 13:27:56 +0000 | [diff] [blame] | 24683 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 24684 | |
Daniel Veillard | 5d4644e | 2005-04-01 13:11:58 +0000 | [diff] [blame] | 24685 | #define bottom_xmlschemas |
| 24686 | #include "elfgcchack.h" |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 24687 | #endif /* LIBXML_SCHEMAS_ENABLED */ |