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 | 6e224f1 | 2005-02-17 11:10:44 +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. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15 | * - if we don't intend to use the schema for schemas, we |
| 16 | * need to validate all schema attributes (ref, type, name) |
| 17 | * against their types. |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 18 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19 | #define IN_LIBXML |
| 20 | #include "libxml.h" |
| 21 | |
| 22 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 23 | |
| 24 | #include <string.h> |
| 25 | #include <libxml/xmlmemory.h> |
| 26 | #include <libxml/parser.h> |
| 27 | #include <libxml/parserInternals.h> |
| 28 | #include <libxml/hash.h> |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 29 | #include <libxml/uri.h> |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 30 | |
| 31 | #include <libxml/xmlschemas.h> |
| 32 | #include <libxml/schemasInternals.h> |
| 33 | #include <libxml/xmlschemastypes.h> |
| 34 | #include <libxml/xmlautomata.h> |
| 35 | #include <libxml/xmlregexp.h> |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 36 | #include <libxml/dict.h> |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 37 | #ifdef LIBXML_PATTERN_ENABLED |
| 38 | #include <libxml/pattern.h> |
| 39 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 40 | |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 41 | /* #define DEBUG 1 */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 42 | |
Daniel Veillard | 82bbbd4 | 2003-05-11 20:16:09 +0000 | [diff] [blame] | 43 | /* #define DEBUG_CONTENT 1 */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 44 | |
Daniel Veillard | 82bbbd4 | 2003-05-11 20:16:09 +0000 | [diff] [blame] | 45 | /* #define DEBUG_TYPE 1 */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 46 | |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 47 | /* #define DEBUG_CONTENT_REGEXP 1 */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 48 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 49 | /* #define DEBUG_AUTOMATA 1 */ |
| 50 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 51 | /* #define DEBUG_ATTR_VALIDATION 1 */ |
| 52 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 53 | /* #define DEBUG_UNION_VALIDATION 1 */ |
| 54 | |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 55 | #define ELEM_INFO_ENABLED 1 |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 56 | |
Kasimier T. Buchcik | 285ebab | 2005-03-04 18:04:59 +0000 | [diff] [blame] | 57 | #define IDC_ENABLED 1 |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 58 | |
Kasimier T. Buchcik | 285ebab | 2005-03-04 18:04:59 +0000 | [diff] [blame] | 59 | #define IDC_VALUE_SUPPORT 1 |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 60 | |
Kasimier T. Buchcik | 285ebab | 2005-03-04 18:04:59 +0000 | [diff] [blame] | 61 | #define IDC_XPATH_SUPPORT 1 |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 62 | |
| 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 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 67 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 68 | #define UNBOUNDED (1 << 30) |
| 69 | #define TODO \ |
| 70 | xmlGenericError(xmlGenericErrorContext, \ |
| 71 | "Unimplemented block at %s:%d\n", \ |
| 72 | __FILE__, __LINE__); |
| 73 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 74 | #define XML_SCHEMAS_NO_NAMESPACE (const xmlChar *) "##" |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 75 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 76 | /* |
| 77 | * The XML Schemas namespaces |
| 78 | */ |
| 79 | static const xmlChar *xmlSchemaNs = (const xmlChar *) |
| 80 | "http://www.w3.org/2001/XMLSchema"; |
| 81 | |
| 82 | static const xmlChar *xmlSchemaInstanceNs = (const xmlChar *) |
| 83 | "http://www.w3.org/2001/XMLSchema-instance"; |
| 84 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 85 | static const xmlChar *xmlSchemaElemDesElemDecl = (const xmlChar *) |
| 86 | "Element decl."; |
| 87 | static const xmlChar *xmlSchemaElemDesElemRef = (const xmlChar *) |
| 88 | "Element ref."; |
| 89 | static const xmlChar *xmlSchemaElemDesAttrDecl = (const xmlChar *) |
| 90 | "Attribute decl."; |
| 91 | static const xmlChar *xmlSchemaElemDesAttrRef = (const xmlChar *) |
| 92 | "Attribute ref."; |
| 93 | static const xmlChar *xmlSchemaElemDesST = (const xmlChar *) |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 94 | "simple type"; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 95 | static const xmlChar *xmlSchemaElemDesCT = (const xmlChar *) |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 96 | "complex type"; |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 97 | static const xmlChar *xmlSchemaElemModelGrDef = (const xmlChar *) |
| 98 | "Model group"; |
| 99 | static const xmlChar *xmlSchemaElemModelGrRef = (const xmlChar *) |
| 100 | "Model group ref."; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 101 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 102 | #define IS_SCHEMA(node, type) \ |
| 103 | ((node != NULL) && (node->ns != NULL) && \ |
| 104 | (xmlStrEqual(node->name, (const xmlChar *) type)) && \ |
| 105 | (xmlStrEqual(node->ns->href, xmlSchemaNs))) |
| 106 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 107 | #define FREE_AND_NULL(str) \ |
| 108 | if (str != NULL) { \ |
| 109 | xmlFree(str); \ |
| 110 | str = NULL; \ |
| 111 | } |
| 112 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 113 | #define IS_ANYTYPE(item) \ |
| 114 | ((item->type == XML_SCHEMA_TYPE_BASIC) && \ |
| 115 | (item->builtInType == XML_SCHEMAS_ANYTYPE)) |
| 116 | |
| 117 | #define IS_COMPLEX_TYPE(item) \ |
| 118 | ((item->type == XML_SCHEMA_TYPE_COMPLEX) || \ |
| 119 | (item->builtInType == XML_SCHEMAS_ANYTYPE)) |
| 120 | |
| 121 | #define IS_SIMPLE_TYPE(item) \ |
| 122 | ((item->type == XML_SCHEMA_TYPE_SIMPLE) || \ |
| 123 | ((item->type == XML_SCHEMA_TYPE_BASIC) && \ |
| 124 | (item->builtInType != XML_SCHEMAS_ANYTYPE))) |
| 125 | |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 126 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 127 | #define XML_SCHEMAS_VAL_WTSP_PRESERVE 0 |
| 128 | #define XML_SCHEMAS_VAL_WTSP_REPLACE 1 |
| 129 | #define XML_SCHEMAS_VAL_WTSP_COLLAPSE 2 |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 130 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 131 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 132 | #define XML_SCHEMAS_PARSE_ERROR 1 |
| 133 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 134 | #define SCHEMAS_PARSE_OPTIONS XML_PARSE_NOENT |
| 135 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 136 | |
| 137 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 138 | * XML_SCHEMA_VAL_LOCATE_BY_NSNAME = 1<<2 |
| 139 | * locate schemata to be imported |
| 140 | * using the namespace name; otherwise |
| 141 | * the location URI will be used */ |
| 142 | |
| 143 | /* |
| 144 | * xmlSchemaParserOption: |
| 145 | * |
| 146 | * This is the set of XML Schema parser options. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 147 | * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 148 | typedef enum { |
| 149 | XML_SCHEMA_PAR_LOCATE_BY_NSNAME = 1<<0 |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 150 | * locate schemata to be imported |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 151 | * using the namespace name; otherwise |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 152 | * the location URI will be used * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 153 | } xmlSchemaParserOption; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 154 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 155 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 156 | typedef struct _xmlSchemaAssemble xmlSchemaAssemble; |
| 157 | typedef xmlSchemaAssemble *xmlSchemaAssemblePtr; |
| 158 | struct _xmlSchemaAssemble { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 159 | void **items; /* used for dynamic addition of schemata */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 160 | int nbItems; /* used for dynamic addition of schemata */ |
| 161 | int sizeItems; /* used for dynamic addition of schemata */ |
| 162 | }; |
| 163 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 164 | struct _xmlSchemaParserCtxt { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 165 | void *userData; /* user specific data block */ |
| 166 | xmlSchemaValidityErrorFunc error; /* the callback in case of errors */ |
| 167 | xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */ |
Daniel Veillard | e19fc23 | 2002-04-22 16:01:24 +0000 | [diff] [blame] | 168 | xmlSchemaValidError err; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 169 | int nberrors; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 170 | xmlStructuredErrorFunc serror; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 171 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 172 | xmlSchemaPtr topschema; /* The main schema */ |
| 173 | xmlHashTablePtr namespaces; /* Hash table of namespaces to schemas */ |
| 174 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 175 | xmlSchemaPtr schema; /* The schema in use */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 176 | const xmlChar *container; /* the current element, group, ... */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 177 | int counter; |
| 178 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 179 | const xmlChar *URL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 180 | xmlDocPtr doc; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 181 | int preserve; /* Whether the doc should be freed */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 182 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 183 | const char *buffer; |
| 184 | int size; |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 185 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 186 | /* |
| 187 | * Used to build complex element content models |
| 188 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 189 | xmlAutomataPtr am; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 190 | xmlAutomataStatePtr start; |
| 191 | xmlAutomataStatePtr end; |
| 192 | xmlAutomataStatePtr state; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 193 | |
| 194 | xmlDictPtr dict; /* dictionnary for interned string names */ |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 195 | int includes; /* the inclusion level, 0 for root or imports */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 196 | xmlSchemaTypePtr ctxtType; /* The current context simple/complex type */ |
| 197 | xmlSchemaTypePtr parentItem; /* The current parent schema item */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 198 | xmlSchemaAssemblePtr assemble; |
| 199 | int options; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 200 | xmlSchemaValidCtxtPtr vctxt; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 201 | const xmlChar **localImports; /* list of locally imported namespaces */ |
| 202 | int sizeLocalImports; |
| 203 | int nbLocalImports; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | |
| 207 | #define XML_SCHEMAS_ATTR_UNKNOWN 1 |
| 208 | #define XML_SCHEMAS_ATTR_CHECKED 2 |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 209 | #define XML_SCHEMAS_ATTR_PROHIBITED 3 |
| 210 | #define XML_SCHEMAS_ATTR_MISSING 4 |
| 211 | #define XML_SCHEMAS_ATTR_INVALID_VALUE 5 |
| 212 | #define XML_SCHEMAS_ATTR_TYPE_NOT_RESOLVED 6 |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 213 | #define XML_SCHEMAS_ATTR_INVALID_FIXED_VALUE 7 |
| 214 | #define XML_SCHEMAS_ATTR_DEFAULT 8 |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 215 | #define XML_SCHEMAS_ATTR_VALIDATE_VALUE 9 |
| 216 | #define XML_SCHEMAS_ATTR_WILD_NO_DECL 10 |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 217 | |
| 218 | typedef struct _xmlSchemaAttrState xmlSchemaAttrState; |
| 219 | typedef xmlSchemaAttrState *xmlSchemaAttrStatePtr; |
| 220 | struct _xmlSchemaAttrState { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 221 | xmlSchemaAttrStatePtr next; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 222 | xmlAttrPtr attr; |
| 223 | int state; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 224 | xmlSchemaAttributePtr decl; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 225 | const xmlChar *value; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 226 | }; |
| 227 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 228 | typedef struct _xmlSchemaBasicItem xmlSchemaBasicItem; |
| 229 | typedef xmlSchemaBasicItem *xmlSchemaBasicItemPtr; |
| 230 | struct _xmlSchemaBasicItem { |
| 231 | xmlSchemaTypeType type; |
| 232 | xmlSchemaAnnotPtr annot; |
| 233 | }; |
| 234 | |
| 235 | typedef struct _xmlSchemaItemQNRef xmlSchemaItemQNRef; |
| 236 | typedef xmlSchemaItemQNRef *xmlSchemaItemQNRefPtr; |
| 237 | struct _xmlSchemaItemQNRef { |
| 238 | xmlSchemaBasicItemPtr item; |
| 239 | const xmlChar *name; |
| 240 | const xmlChar *targetNamespace; |
| 241 | }; |
| 242 | |
| 243 | typedef struct _xmlSchemaIDC xmlSchemaIDC; |
| 244 | typedef xmlSchemaIDC *xmlSchemaIDCPtr; |
| 245 | |
| 246 | /** |
| 247 | * xmlSchemaIDCSelect: |
| 248 | * |
| 249 | * The identity-constraint "field" and "selector" item, holding the |
| 250 | * XPath expression. |
| 251 | */ |
| 252 | typedef struct _xmlSchemaIDCSelect xmlSchemaIDCSelect; |
| 253 | typedef xmlSchemaIDCSelect *xmlSchemaIDCSelectPtr; |
| 254 | struct _xmlSchemaIDCSelect { |
| 255 | xmlSchemaIDCSelectPtr next; |
| 256 | xmlSchemaIDCPtr idc; |
| 257 | int index; /* an index position if significant for IDC key-sequences */ |
| 258 | const xmlChar *xpath; /* the XPath expression */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 259 | void *xpathComp; /* the compiled XPath expression */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | /** |
| 263 | * xmlSchemaIDC: |
| 264 | * |
| 265 | * The identity-constraint definition component. |
| 266 | */ |
| 267 | |
| 268 | struct _xmlSchemaIDC { |
| 269 | xmlSchemaTypeType type; |
| 270 | xmlSchemaAnnotPtr annot; |
| 271 | xmlSchemaIDCPtr next; |
| 272 | xmlNodePtr node; |
| 273 | const xmlChar *name; |
| 274 | const xmlChar *targetNamespace; |
| 275 | xmlSchemaIDCSelectPtr selector; |
| 276 | xmlSchemaIDCSelectPtr fields; |
| 277 | int nbFields; |
| 278 | xmlSchemaItemQNRefPtr ref; |
| 279 | }; |
| 280 | |
| 281 | /** |
| 282 | * xmlSchemaIDCAug: |
| 283 | * |
| 284 | * The augmented IDC information used for validation. |
| 285 | */ |
| 286 | typedef struct _xmlSchemaIDCAug xmlSchemaIDCAug; |
| 287 | typedef xmlSchemaIDCAug *xmlSchemaIDCAugPtr; |
| 288 | struct _xmlSchemaIDCAug { |
| 289 | xmlSchemaIDCAugPtr next; /* next in a list */ |
| 290 | xmlSchemaIDCPtr def; /* the IDC definition */ |
| 291 | int bubbleDepth; /* the lowest level to which IDC |
| 292 | tables need to be bubbled upwards */ |
| 293 | }; |
| 294 | |
| 295 | /** |
| 296 | * xmlSchemaPSVIIDCKeySequence: |
| 297 | * |
| 298 | * The key sequence of a node table item. |
| 299 | */ |
| 300 | typedef struct _xmlSchemaPSVIIDCKey xmlSchemaPSVIIDCKey; |
| 301 | typedef xmlSchemaPSVIIDCKey *xmlSchemaPSVIIDCKeyPtr; |
| 302 | struct _xmlSchemaPSVIIDCKey { |
| 303 | xmlSchemaTypePtr type; |
| 304 | xmlSchemaValPtr compValue; |
| 305 | }; |
| 306 | |
| 307 | /** |
| 308 | * xmlSchemaPSVIIDCNode: |
| 309 | * |
| 310 | * The node table item of a node table. |
| 311 | */ |
| 312 | typedef struct _xmlSchemaPSVIIDCNode xmlSchemaPSVIIDCNode; |
| 313 | typedef xmlSchemaPSVIIDCNode *xmlSchemaPSVIIDCNodePtr; |
| 314 | struct _xmlSchemaPSVIIDCNode { |
| 315 | xmlNodePtr node; |
| 316 | xmlSchemaPSVIIDCKeyPtr *keys; |
| 317 | }; |
| 318 | |
| 319 | /** |
| 320 | * xmlSchemaPSVIIDCBinding: |
| 321 | * |
| 322 | * The identity-constraint binding item of the [identity-constraint table]. |
| 323 | */ |
| 324 | typedef struct _xmlSchemaPSVIIDCBinding xmlSchemaPSVIIDCBinding; |
| 325 | typedef xmlSchemaPSVIIDCBinding *xmlSchemaPSVIIDCBindingPtr; |
| 326 | struct _xmlSchemaPSVIIDCBinding { |
| 327 | xmlSchemaPSVIIDCBindingPtr next; /* next binding of a specific node */ |
| 328 | xmlSchemaIDCPtr definition; /* the IDC definition */ |
| 329 | xmlSchemaPSVIIDCNodePtr *nodeTable; /* array of key-sequences */ |
| 330 | int nbNodes; /* number of entries in the node table */ |
| 331 | int sizeNodes; /* size of the node table */ |
| 332 | int nbDupls; /* number of already identified duplicates in the node |
| 333 | table */ |
| 334 | /* int nbKeys; number of keys in each key-sequence */ |
| 335 | }; |
| 336 | |
| 337 | #define XPATH_STATE_OBJ_TYPE_IDC_SELECTOR 1 |
| 338 | #define XPATH_STATE_OBJ_TYPE_IDC_FIELD 2 |
| 339 | |
| 340 | #define XPATH_STATE_OBJ_MATCHES -2 |
| 341 | #define XPATH_STATE_OBJ_BLOCKED -3 |
| 342 | |
| 343 | typedef struct _xmlSchemaIDCMatcher xmlSchemaIDCMatcher; |
| 344 | typedef xmlSchemaIDCMatcher *xmlSchemaIDCMatcherPtr; |
| 345 | |
| 346 | /** |
| 347 | * xmlSchemaIDCStateObj: |
| 348 | * |
| 349 | * The state object used to evaluate XPath expressions. |
| 350 | */ |
| 351 | typedef struct _xmlSchemaIDCStateObj xmlSchemaIDCStateObj; |
| 352 | typedef xmlSchemaIDCStateObj *xmlSchemaIDCStateObjPtr; |
| 353 | struct _xmlSchemaIDCStateObj { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 354 | int type; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 355 | xmlSchemaIDCStateObjPtr next; /* next if in a list */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 356 | int depth; /* depth of creation */ |
| 357 | int *history; /* list of (depth, state-id) tuples */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 358 | int nbHistory; |
| 359 | int sizeHistory; |
| 360 | xmlSchemaIDCMatcherPtr matcher; /* the correspondent field/selector |
| 361 | matcher */ |
| 362 | xmlSchemaIDCSelectPtr sel; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 363 | void *xpathCtxt; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 364 | }; |
| 365 | |
| 366 | #define IDC_MATCHER 0 |
| 367 | |
| 368 | /** |
| 369 | * xmlSchemaIDCMatcher: |
| 370 | * |
| 371 | * Used to IDC selectors (and fields) successively. |
| 372 | */ |
| 373 | struct _xmlSchemaIDCMatcher { |
| 374 | int type; |
| 375 | int depth; /* the tree depth at creation time */ |
| 376 | xmlSchemaIDCMatcherPtr next; /* next in the list */ |
| 377 | xmlSchemaIDCAugPtr aidc; /* the augmented IDC item */ |
| 378 | xmlSchemaPSVIIDCKeyPtr **keySeqs; /* the key-sequences of the target |
| 379 | elements */ |
| 380 | int sizeKeySeqs; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 381 | int targetDepth; |
| 382 | }; |
| 383 | |
| 384 | /* |
| 385 | * Element info flags. |
| 386 | */ |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 387 | #define XML_SCHEMA_ELEM_INFO_VALUE_NEEDED 1 |
| 388 | /* #define XML_SCHEMA_ELEM_INFO_ATTR 2 */ |
| 389 | /* #define XML_SCHEMA_ELEM_INFO_ELEM 4 */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 390 | |
| 391 | /** |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 392 | * xmlSchemaNodeInfo: |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 393 | * |
| 394 | * Holds information of an element node. |
| 395 | */ |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 396 | typedef struct _xmlSchemaNodeInfo xmlSchemaNodeInfo; |
| 397 | typedef xmlSchemaNodeInfo *xmlSchemaNodeInfoPtr; |
| 398 | struct _xmlSchemaNodeInfo { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 399 | int depth; |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 400 | int flags; /* combination of node info flags */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 401 | xmlNodePtr node; |
| 402 | const xmlChar *localName; |
| 403 | const xmlChar *namespaceName; |
| 404 | xmlSchemaTypePtr typeDef; /* the complex/simple type definition if any */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 405 | xmlSchemaTypePtr decl; /* the element/attribute declaration */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 406 | xmlSchemaValPtr value; /* the pre-computed value if any */ |
| 407 | xmlSchemaPSVIIDCBindingPtr idcTable; /* the table of PSVI IDC bindings |
| 408 | for the scope element*/ |
| 409 | xmlSchemaIDCMatcherPtr idcMatchers; /* the IDC matchers for the scope |
| 410 | element */ |
| 411 | }; |
| 412 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 413 | /** |
| 414 | * xmlSchemaValidCtxt: |
| 415 | * |
| 416 | * A Schemas validation context |
| 417 | */ |
| 418 | |
| 419 | struct _xmlSchemaValidCtxt { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 420 | void *userData; /* user specific data block */ |
| 421 | xmlSchemaValidityErrorFunc error; /* the callback in case of errors */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 422 | xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */ |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 423 | xmlStructuredErrorFunc serror; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 424 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 425 | xmlSchemaPtr schema; /* The schema in use */ |
| 426 | xmlDocPtr doc; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 427 | xmlParserInputBufferPtr input; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 428 | xmlCharEncoding enc; |
| 429 | xmlSAXHandlerPtr sax; |
| 430 | void *user_data; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 431 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 432 | xmlDocPtr myDoc; |
| 433 | int err; |
| 434 | int nberrors; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 435 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 436 | xmlNodePtr node; |
| 437 | xmlNodePtr cur; |
| 438 | xmlSchemaTypePtr type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 439 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 440 | xmlRegExecCtxtPtr regexp; |
| 441 | xmlSchemaValPtr value; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 442 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 443 | xmlSchemaAttrStatePtr attrTop; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 444 | xmlSchemaAttrStatePtr attr; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 445 | /* xmlNodePtr scope; not used */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 446 | int valueWS; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 447 | int options; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 448 | xmlNodePtr validationRoot; |
| 449 | xmlSchemaParserCtxtPtr pctxt; |
| 450 | int xsiAssemble; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 451 | #ifdef ELEM_INFO_ENABLED |
| 452 | int depth; |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 453 | xmlSchemaNodeInfoPtr *elemInfos; /* array of element informations */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 454 | int sizeElemInfos; |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 455 | xmlSchemaNodeInfoPtr nodeInfo; /* the current element information */ |
| 456 | xmlSchemaNodeInfoPtr attrInfo; /* node infor for the current attribute */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 457 | #endif |
| 458 | #ifdef IDC_ENABLED |
| 459 | xmlSchemaIDCAugPtr aidcs; /* a list of augmented IDC informations */ |
| 460 | |
| 461 | xmlSchemaIDCStateObjPtr xpathStates; /* first active state object. */ |
| 462 | xmlSchemaIDCStateObjPtr xpathStatePool; /* first stored state object. */ |
| 463 | |
| 464 | xmlSchemaPSVIIDCNodePtr *idcNodes; /* list of all IDC node-table entries*/ |
| 465 | int nbIdcNodes; |
| 466 | int sizeIdcNodes; |
| 467 | |
| 468 | xmlSchemaPSVIIDCKeyPtr *idcKeys; /* list of all IDC node-table entries */ |
| 469 | int nbIdcKeys; |
| 470 | int sizeIdcKeys; |
| 471 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 472 | }; |
| 473 | |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 474 | /* |
| 475 | * These are the entries in the schemas importSchemas hash table |
| 476 | */ |
| 477 | typedef struct _xmlSchemaImport xmlSchemaImport; |
| 478 | typedef xmlSchemaImport *xmlSchemaImportPtr; |
| 479 | struct _xmlSchemaImport { |
| 480 | const xmlChar *schemaLocation; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 481 | xmlSchemaPtr schema; /* not used any more */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 482 | xmlDocPtr doc; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 483 | int isMain; |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 484 | }; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 485 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 486 | /* |
| 487 | * These are the entries associated to includes in a schemas |
| 488 | */ |
| 489 | typedef struct _xmlSchemaInclude xmlSchemaInclude; |
| 490 | typedef xmlSchemaInclude *xmlSchemaIncludePtr; |
| 491 | struct _xmlSchemaInclude { |
| 492 | xmlSchemaIncludePtr next; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 493 | const xmlChar *schemaLocation; |
| 494 | xmlDocPtr doc; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 495 | const xmlChar *origTargetNamespace; |
| 496 | const xmlChar *targetNamespace; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 497 | }; |
| 498 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 499 | typedef struct _xmlSchemaParticle xmlSchemaParticle; |
| 500 | typedef xmlSchemaParticle *xmlSchemaParticlePtr; |
| 501 | struct _xmlSchemaParticle { |
| 502 | xmlSchemaTypeType type; |
| 503 | xmlSchemaParticlePtr next; /* the next particle if in a list */ |
| 504 | int minOccurs; |
| 505 | int maxOccurs; |
| 506 | xmlSchemaTypePtr term; |
| 507 | }; |
| 508 | |
| 509 | |
| 510 | typedef struct _xmlSchemaModelGroup xmlSchemaModelGroup; |
| 511 | typedef xmlSchemaModelGroup *xmlSchemaModelGroupPtr; |
| 512 | struct _xmlSchemaModelGroup { |
| 513 | xmlSchemaTypeType type; |
| 514 | int compositor; /* one of all, choice or sequence */ |
| 515 | xmlSchemaParticlePtr particles; /* list of particles */ |
| 516 | xmlSchemaAnnotPtr annot; |
| 517 | }; |
| 518 | |
| 519 | typedef struct _xmlSchemaModelGroupDef xmlSchemaModelGroupDef; |
| 520 | typedef xmlSchemaModelGroupDef *xmlSchemaModelGroupDefPtr; |
| 521 | struct _xmlSchemaModelGroupDef { |
| 522 | xmlSchemaTypeType type; |
| 523 | const xmlChar *name; |
| 524 | const xmlChar *targetNamespace; |
| 525 | xmlSchemaModelGroupPtr modelGroup; |
| 526 | xmlSchemaAnnotPtr annot; |
| 527 | }; |
| 528 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 529 | /************************************************************************ |
| 530 | * * |
| 531 | * Some predeclarations * |
| 532 | * * |
| 533 | ************************************************************************/ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 534 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 535 | static int xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt, |
| 536 | xmlSchemaPtr schema, |
| 537 | xmlNodePtr node); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 538 | static void |
| 539 | xmlSchemaTypeFixup(xmlSchemaTypePtr typeDecl, |
| 540 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name); |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 541 | static const xmlChar * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 542 | xmlSchemaFacetTypeToString(xmlSchemaTypeType type); |
| 543 | static int |
| 544 | xmlSchemaValidateSimpleTypeValue(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 545 | xmlSchemaTypePtr type, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 546 | const xmlChar *value, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 547 | int fireErrors, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 548 | int applyFacets, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 549 | int normalize, |
| 550 | int checkNodes); |
| 551 | static int |
| 552 | xmlSchemaValidateElementByDeclaration(xmlSchemaValidCtxtPtr ctxt, |
| 553 | xmlSchemaElementPtr elemDecl); |
| 554 | static int |
| 555 | xmlSchemaValidateElementByWildcard(xmlSchemaValidCtxtPtr ctxt, |
| 556 | xmlSchemaTypePtr type); |
| 557 | static int |
| 558 | xmlSchemaHasElemOrCharContent(xmlNodePtr node); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 559 | static int |
| 560 | xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 561 | xmlNodePtr node); |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 562 | static void |
| 563 | xmlSchemaCheckDefaults(xmlSchemaTypePtr typeDecl, |
| 564 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name); |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 565 | static void |
| 566 | xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt); |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 567 | static int |
| 568 | xmlSchemaPostCreateVal(xmlSchemaValidCtxtPtr vctxt, |
| 569 | xmlSchemaTypePtr type, |
| 570 | const xmlChar *value, |
| 571 | xmlSchemaValPtr *val); |
| 572 | static xmlSchemaTypePtr |
| 573 | xmlSchemaGetSimpleContentType(xmlSchemaTypePtr complexType); |
| 574 | static int |
| 575 | xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type); |
William M. Brack | 87640d5 | 2004-04-17 14:58:15 +0000 | [diff] [blame] | 576 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 577 | /************************************************************************ |
| 578 | * * |
| 579 | * Datatype error handlers * |
| 580 | * * |
| 581 | ************************************************************************/ |
| 582 | |
| 583 | /** |
| 584 | * xmlSchemaPErrMemory: |
| 585 | * @node: a context node |
| 586 | * @extra: extra informations |
| 587 | * |
| 588 | * Handle an out of memory condition |
| 589 | */ |
| 590 | static void |
| 591 | xmlSchemaPErrMemory(xmlSchemaParserCtxtPtr ctxt, |
| 592 | const char *extra, xmlNodePtr node) |
| 593 | { |
| 594 | if (ctxt != NULL) |
| 595 | ctxt->nberrors++; |
| 596 | __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, node, NULL, |
| 597 | extra); |
| 598 | } |
| 599 | |
| 600 | /** |
| 601 | * xmlSchemaPErr: |
| 602 | * @ctxt: the parsing context |
| 603 | * @node: the context node |
| 604 | * @error: the error code |
| 605 | * @msg: the error message |
| 606 | * @str1: extra data |
| 607 | * @str2: extra data |
| 608 | * |
| 609 | * Handle a parser error |
| 610 | */ |
| 611 | static void |
| 612 | xmlSchemaPErr(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error, |
| 613 | const char *msg, const xmlChar * str1, const xmlChar * str2) |
| 614 | { |
| 615 | xmlGenericErrorFunc channel = NULL; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 616 | xmlStructuredErrorFunc schannel = NULL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 617 | void *data = NULL; |
| 618 | |
| 619 | if (ctxt != NULL) { |
| 620 | ctxt->nberrors++; |
| 621 | channel = ctxt->error; |
| 622 | data = ctxt->userData; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 623 | schannel = ctxt->serror; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 624 | } |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 625 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 626 | error, XML_ERR_ERROR, NULL, 0, |
| 627 | (const char *) str1, (const char *) str2, NULL, 0, 0, |
| 628 | msg, str1, str2); |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * xmlSchemaPErr2: |
| 633 | * @ctxt: the parsing context |
| 634 | * @node: the context node |
| 635 | * @node: the current child |
| 636 | * @error: the error code |
| 637 | * @msg: the error message |
| 638 | * @str1: extra data |
| 639 | * @str2: extra data |
| 640 | * |
| 641 | * Handle a parser error |
| 642 | */ |
| 643 | static void |
| 644 | xmlSchemaPErr2(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
| 645 | xmlNodePtr child, int error, |
| 646 | const char *msg, const xmlChar * str1, const xmlChar * str2) |
| 647 | { |
| 648 | if (child != NULL) |
| 649 | xmlSchemaPErr(ctxt, child, error, msg, str1, str2); |
| 650 | else |
| 651 | xmlSchemaPErr(ctxt, node, error, msg, str1, str2); |
| 652 | } |
| 653 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 654 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 655 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 656 | * xmlSchemaPErrExt: |
| 657 | * @ctxt: the parsing context |
| 658 | * @node: the context node |
| 659 | * @error: the error code |
| 660 | * @strData1: extra data |
| 661 | * @strData2: extra data |
| 662 | * @strData3: extra data |
| 663 | * @msg: the message |
| 664 | * @str1: extra parameter for the message display |
| 665 | * @str2: extra parameter for the message display |
| 666 | * @str3: extra parameter for the message display |
| 667 | * @str4: extra parameter for the message display |
| 668 | * @str5: extra parameter for the message display |
| 669 | * |
| 670 | * Handle a parser error |
| 671 | */ |
| 672 | static void |
| 673 | xmlSchemaPErrExt(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error, |
| 674 | const xmlChar * strData1, const xmlChar * strData2, |
| 675 | const xmlChar * strData3, const char *msg, const xmlChar * str1, |
| 676 | const xmlChar * str2, const xmlChar * str3, const xmlChar * str4, |
| 677 | const xmlChar * str5) |
| 678 | { |
| 679 | |
| 680 | xmlGenericErrorFunc channel = NULL; |
| 681 | xmlStructuredErrorFunc schannel = NULL; |
| 682 | void *data = NULL; |
| 683 | |
| 684 | if (ctxt != NULL) { |
| 685 | ctxt->nberrors++; |
| 686 | channel = ctxt->error; |
| 687 | data = ctxt->userData; |
| 688 | schannel = ctxt->serror; |
| 689 | } |
| 690 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP, |
| 691 | error, XML_ERR_ERROR, NULL, 0, |
| 692 | (const char *) strData1, (const char *) strData2, |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 693 | (const char *) strData3, 0, 0, msg, str1, str2, |
| 694 | str3, str4, str5); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 695 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 696 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 697 | |
| 698 | /** |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 699 | * xmlSchemaVTypeErrMemory: |
| 700 | * @node: a context node |
| 701 | * @extra: extra informations |
| 702 | * |
| 703 | * Handle an out of memory condition |
| 704 | */ |
| 705 | static void |
| 706 | xmlSchemaVErrMemory(xmlSchemaValidCtxtPtr ctxt, |
| 707 | const char *extra, xmlNodePtr node) |
| 708 | { |
| 709 | if (ctxt != NULL) { |
| 710 | ctxt->nberrors++; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 711 | ctxt->err = XML_SCHEMAV_INTERNAL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 712 | } |
| 713 | __xmlSimpleError(XML_FROM_SCHEMASV, XML_ERR_NO_MEMORY, node, NULL, |
| 714 | extra); |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * xmlSchemaVErr3: |
| 719 | * @ctxt: the validation context |
| 720 | * @node: the context node |
| 721 | * @error: the error code |
| 722 | * @msg: the error message |
| 723 | * @str1: extra data |
| 724 | * @str2: extra data |
| 725 | * @str3: extra data |
| 726 | * |
| 727 | * Handle a validation error |
| 728 | */ |
| 729 | static void |
| 730 | xmlSchemaVErr3(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr node, int error, |
| 731 | const char *msg, const xmlChar *str1, const xmlChar *str2, |
| 732 | const xmlChar *str3) |
| 733 | { |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 734 | xmlStructuredErrorFunc schannel = NULL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 735 | xmlGenericErrorFunc channel = NULL; |
| 736 | void *data = NULL; |
| 737 | |
| 738 | if (ctxt != NULL) { |
| 739 | ctxt->nberrors++; |
| 740 | ctxt->err = error; |
| 741 | channel = ctxt->error; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 742 | schannel = ctxt->serror; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 743 | data = ctxt->userData; |
| 744 | } |
| 745 | /* reajust to global error numbers */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 746 | /* Removed, since the old schema error codes have been |
| 747 | * substituted for the global error codes. |
| 748 | * |
| 749 | * error += XML_SCHEMAV_NOROOT - XML_SCHEMAS_ERR_NOROOT; |
| 750 | */ |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 751 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASV, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 752 | error, XML_ERR_ERROR, NULL, 0, |
| 753 | (const char *) str1, (const char *) str2, |
| 754 | (const char *) str3, 0, 0, |
| 755 | msg, str1, str2, str3); |
| 756 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 757 | |
| 758 | /** |
| 759 | * xmlSchemaVErrExt: |
| 760 | * @ctxt: the validation context |
| 761 | * @node: the context node |
| 762 | * @error: the error code |
| 763 | * @msg: the message |
| 764 | * @str1: extra parameter for the message display |
| 765 | * @str2: extra parameter for the message display |
| 766 | * @str3: extra parameter for the message display |
| 767 | * @str4: extra parameter for the message display |
| 768 | * @str5: extra parameter for the message display |
| 769 | * |
| 770 | * Handle a validation error |
| 771 | */ |
| 772 | static void |
| 773 | xmlSchemaVErrExt(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr node, int error, |
| 774 | const char *msg, const xmlChar * str1, |
| 775 | const xmlChar * str2, const xmlChar * str3, |
| 776 | const xmlChar * str4, const xmlChar * str5) |
| 777 | { |
| 778 | xmlStructuredErrorFunc schannel = NULL; |
| 779 | xmlGenericErrorFunc channel = NULL; |
| 780 | void *data = NULL; |
| 781 | |
| 782 | if (ctxt != NULL) { |
| 783 | ctxt->nberrors++; |
| 784 | ctxt->err = error; |
| 785 | channel = ctxt->error; |
| 786 | schannel = ctxt->serror; |
| 787 | data = ctxt->userData; |
| 788 | } |
| 789 | /* reajust to global error numbers */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 790 | /* Removed, since the old schema error codes have been |
| 791 | * substituted for the global error codes. |
| 792 | * |
| 793 | * error += XML_SCHEMAV_NOROOT - XML_SCHEMAS_ERR_NOROOT; |
| 794 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 795 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP, |
| 796 | error, XML_ERR_ERROR, NULL, 0, NULL, NULL, NULL, 0, 0, |
| 797 | msg, str1, str2, str3, str4, str5); |
| 798 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 799 | /** |
| 800 | * xmlSchemaVErr: |
| 801 | * @ctxt: the validation context |
| 802 | * @node: the context node |
| 803 | * @error: the error code |
| 804 | * @msg: the error message |
| 805 | * @str1: extra data |
| 806 | * @str2: extra data |
| 807 | * |
| 808 | * Handle a validation error |
| 809 | */ |
| 810 | static void |
| 811 | xmlSchemaVErr(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr node, int error, |
| 812 | const char *msg, const xmlChar * str1, const xmlChar * str2) |
| 813 | { |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 814 | xmlStructuredErrorFunc schannel = NULL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 815 | xmlGenericErrorFunc channel = NULL; |
| 816 | void *data = NULL; |
| 817 | |
| 818 | if (ctxt != NULL) { |
| 819 | ctxt->nberrors++; |
| 820 | ctxt->err = error; |
| 821 | channel = ctxt->error; |
| 822 | data = ctxt->userData; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 823 | schannel = ctxt->serror; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 824 | } |
| 825 | /* reajust to global error numbers */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 826 | /* Removed, since the old schema error codes have been |
| 827 | * substituted for the global error codes. |
| 828 | * |
| 829 | * error += XML_SCHEMAV_NOROOT - XML_SCHEMAS_ERR_NOROOT; |
| 830 | */ |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 831 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASV, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 832 | error, XML_ERR_ERROR, NULL, 0, |
| 833 | (const char *) str1, (const char *) str2, NULL, 0, 0, |
| 834 | msg, str1, str2); |
| 835 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 836 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 837 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 838 | * xmlSchemaGetAttrName: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 839 | * @attr: the attribute declaration/use |
| 840 | * |
| 841 | * Returns the name of the attribute; if the attribute |
| 842 | * is a reference, the name of the referenced global type will be returned. |
| 843 | */ |
| 844 | static const xmlChar * |
| 845 | xmlSchemaGetAttrName(xmlSchemaAttributePtr attr) |
| 846 | { |
| 847 | if (attr->ref != NULL) |
| 848 | return(attr->ref); |
| 849 | else |
| 850 | return(attr->name); |
| 851 | } |
| 852 | |
| 853 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 854 | * xmlSchemaGetAttrTargetNsURI: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 855 | * @type: the type (element or attribute) |
| 856 | * |
| 857 | * Returns the target namespace URI of the type; if the type is a reference, |
| 858 | * the target namespace of the referenced type will be returned. |
| 859 | */ |
| 860 | static const xmlChar * |
| 861 | xmlSchemaGetAttrTargetNsURI(xmlSchemaAttributePtr attr) |
| 862 | { |
| 863 | if (attr->ref != NULL) |
| 864 | return (attr->refNs); |
| 865 | else |
| 866 | return(attr->targetNamespace); |
| 867 | } |
| 868 | |
| 869 | /** |
| 870 | * xmlSchemaFormatNsUriLocal: |
| 871 | * @buf: the string buffer |
| 872 | * @uri: the namespace URI |
| 873 | * @local: the local name |
| 874 | * |
| 875 | * Returns a representation of the given URI used |
| 876 | * for error reports. |
| 877 | * |
| 878 | * Returns an empty string, if @ns is NULL, a formatted |
| 879 | * string otherwise. |
| 880 | */ |
| 881 | static const xmlChar* |
| 882 | xmlSchemaFormatNsUriLocal(xmlChar **buf, |
| 883 | const xmlChar *uri, const xmlChar *local) |
| 884 | { |
| 885 | if (*buf != NULL) |
| 886 | xmlFree(*buf); |
| 887 | if (uri == NULL) { |
| 888 | *buf = xmlStrdup(BAD_CAST "{'"); |
| 889 | *buf = xmlStrcat(*buf, local); |
| 890 | } else { |
| 891 | *buf = xmlStrdup(BAD_CAST "{'"); |
| 892 | *buf = xmlStrcat(*buf, uri); |
| 893 | *buf = xmlStrcat(*buf, BAD_CAST "', '"); |
| 894 | *buf = xmlStrcat(*buf, local); |
| 895 | } |
| 896 | *buf = xmlStrcat(*buf, BAD_CAST "'}"); |
| 897 | return ((const xmlChar *) *buf); |
| 898 | } |
| 899 | |
| 900 | /** |
| 901 | * xmlSchemaFormatNsPrefixLocal: |
| 902 | * @buf: the string buffer |
| 903 | * @ns: the namespace |
| 904 | * @local: the local name |
| 905 | * |
| 906 | * Returns a representation of the given URI used |
| 907 | * for error reports. |
| 908 | * |
| 909 | * Returns an empty string, if @ns is NULL, a formatted |
| 910 | * string otherwise. |
| 911 | */ |
| 912 | static const xmlChar* |
| 913 | xmlSchemaFormatNsPrefixLocal(xmlChar **buf, |
| 914 | xmlNsPtr ns, const xmlChar *local) |
| 915 | { |
| 916 | if (*buf != NULL) { |
| 917 | xmlFree(*buf); |
| 918 | *buf = NULL; |
| 919 | } |
| 920 | if ((ns == NULL) || (ns->prefix == NULL)) |
| 921 | return(local); |
| 922 | else { |
| 923 | *buf = xmlStrdup(ns->prefix); |
| 924 | *buf = xmlStrcat(*buf, BAD_CAST ":"); |
| 925 | *buf = xmlStrcat(*buf, local); |
| 926 | } |
| 927 | return ((const xmlChar *) *buf); |
| 928 | } |
| 929 | |
| 930 | /** |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 931 | * xmlSchemaFormatQName: |
| 932 | * @buf: the string buffer |
| 933 | * @namespaceName: the namespace name |
| 934 | * @localName: the local name |
| 935 | * |
| 936 | * Returns the given QName in the format "{namespaceName}localName" or |
| 937 | * just "localName" if @namespaceName is NULL. |
| 938 | * |
| 939 | * Returns the localName if @namespaceName is NULL, a formatted |
| 940 | * string otherwise. |
| 941 | */ |
| 942 | static const xmlChar* |
| 943 | xmlSchemaFormatQName(xmlChar **buf, |
| 944 | const xmlChar *namespaceName, |
| 945 | const xmlChar *localName) |
| 946 | { |
| 947 | FREE_AND_NULL(*buf) |
| 948 | if (namespaceName == NULL) |
| 949 | return(localName); |
| 950 | |
| 951 | *buf = xmlStrdup(BAD_CAST "{"); |
| 952 | *buf = xmlStrcat(*buf, namespaceName); |
| 953 | *buf = xmlStrcat(*buf, BAD_CAST "}"); |
| 954 | *buf = xmlStrcat(*buf, localName); |
| 955 | |
| 956 | return ((const xmlChar *) *buf); |
| 957 | } |
| 958 | |
| 959 | /** |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 960 | * xmlSchemaWildcardPCToString: |
| 961 | * @pc: the type of processContents |
| 962 | * |
| 963 | * Returns a string representation of the type of |
| 964 | * processContents. |
| 965 | */ |
| 966 | static const xmlChar * |
| 967 | xmlSchemaWildcardPCToString(int pc) |
| 968 | { |
| 969 | switch (pc) { |
| 970 | case XML_SCHEMAS_ANY_SKIP: |
| 971 | return (BAD_CAST "skip"); |
| 972 | case XML_SCHEMAS_ANY_LAX: |
| 973 | return (BAD_CAST "lax"); |
| 974 | case XML_SCHEMAS_ANY_STRICT: |
| 975 | return (BAD_CAST "strict"); |
| 976 | default: |
| 977 | return (BAD_CAST "invalid process contents"); |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 982 | * xmlSchemaFormatItemForReport: |
| 983 | * @buf: the string buffer |
| 984 | * @itemDes: the designation of the item |
| 985 | * @itemName: the name of the item |
| 986 | * @item: the item as an object |
| 987 | * @itemNode: the node of the item |
| 988 | * @local: the local name |
| 989 | * @parsing: if the function is used during the parse |
| 990 | * |
| 991 | * Returns a representation of the given item used |
| 992 | * for error reports. |
| 993 | * |
| 994 | * The following order is used to build the resulting |
| 995 | * designation if the arguments are not NULL: |
| 996 | * 1a. If itemDes not NULL -> itemDes |
| 997 | * 1b. If (itemDes not NULL) and (itemName not NULL) |
| 998 | * -> itemDes + itemName |
| 999 | * 2. If the preceding was NULL and (item not NULL) -> item |
| 1000 | * 3. If the preceding was NULL and (itemNode not NULL) -> itemNode |
| 1001 | * |
| 1002 | * If the itemNode is an attribute node, the name of the attribute |
| 1003 | * will be appended to the result. |
| 1004 | * |
| 1005 | * Returns the formatted string and sets @buf to the resulting value. |
| 1006 | */ |
| 1007 | static xmlChar* |
| 1008 | xmlSchemaFormatItemForReport(xmlChar **buf, |
| 1009 | const xmlChar *itemDes, |
| 1010 | xmlSchemaTypePtr item, |
| 1011 | xmlNodePtr itemNode, |
| 1012 | int parsing) |
| 1013 | { |
| 1014 | xmlChar *str = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1015 | int named = 1; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1016 | |
| 1017 | if (*buf != NULL) { |
| 1018 | xmlFree(*buf); |
| 1019 | *buf = NULL; |
| 1020 | } |
| 1021 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1022 | if (itemDes != NULL) { |
| 1023 | *buf = xmlStrdup(itemDes); |
| 1024 | } else if (item != NULL) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 1025 | switch (item->type) { |
| 1026 | case XML_SCHEMA_TYPE_BASIC: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1027 | if (item->builtInType == XML_SCHEMAS_ANYTYPE) |
| 1028 | *buf = xmlStrdup(BAD_CAST "'anyType'"); |
| 1029 | else if (item->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) |
| 1030 | *buf = xmlStrdup(BAD_CAST "'anySimpleType'"); |
| 1031 | else { |
| 1032 | /* *buf = xmlStrdup(BAD_CAST "bi "); */ |
| 1033 | /* *buf = xmlStrcat(*buf, xmlSchemaElemDesST); */ |
| 1034 | *buf = xmlStrdup(BAD_CAST "'"); |
| 1035 | *buf = xmlStrcat(*buf, item->name); |
| 1036 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1037 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 1038 | break; |
| 1039 | case XML_SCHEMA_TYPE_SIMPLE: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1040 | if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) { |
| 1041 | *buf = xmlStrdup(xmlSchemaElemDesST); |
| 1042 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1043 | *buf = xmlStrcat(*buf, item->name); |
| 1044 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1045 | } else { |
| 1046 | *buf = xmlStrdup(xmlSchemaElemDesST); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1047 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 1048 | break; |
| 1049 | case XML_SCHEMA_TYPE_COMPLEX: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1050 | if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) { |
| 1051 | *buf = xmlStrdup(xmlSchemaElemDesCT); |
| 1052 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1053 | *buf = xmlStrcat(*buf, item->name); |
| 1054 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1055 | } else { |
| 1056 | *buf = xmlStrdup(xmlSchemaElemDesCT); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1057 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 1058 | break; |
| 1059 | case XML_SCHEMA_TYPE_ATTRIBUTE: { |
| 1060 | xmlSchemaAttributePtr attr; |
| 1061 | |
| 1062 | attr = (xmlSchemaAttributePtr) item; |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 1063 | if ((attr->flags & XML_SCHEMAS_ATTR_GLOBAL) || |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 1064 | (attr->ref == NULL)) { |
| 1065 | *buf = xmlStrdup(xmlSchemaElemDesAttrDecl); |
| 1066 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1067 | *buf = xmlStrcat(*buf, attr->name); |
| 1068 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1069 | } else { |
| 1070 | *buf = xmlStrdup(xmlSchemaElemDesAttrRef); |
| 1071 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1072 | *buf = xmlStrcat(*buf, attr->refPrefix); |
| 1073 | *buf = xmlStrcat(*buf, BAD_CAST ":"); |
| 1074 | *buf = xmlStrcat(*buf, attr->ref); |
| 1075 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1076 | } |
| 1077 | } |
| 1078 | break; |
| 1079 | case XML_SCHEMA_TYPE_ELEMENT: { |
| 1080 | xmlSchemaElementPtr elem; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1081 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 1082 | elem = (xmlSchemaElementPtr) item; |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 1083 | if ((elem->flags & XML_SCHEMAS_ELEM_GLOBAL) || |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 1084 | (elem->ref == NULL)) { |
| 1085 | *buf = xmlStrdup(xmlSchemaElemDesElemDecl); |
| 1086 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1087 | *buf = xmlStrcat(*buf, elem->name); |
| 1088 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1089 | } else { |
| 1090 | *buf = xmlStrdup(xmlSchemaElemDesElemRef); |
| 1091 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1092 | *buf = xmlStrcat(*buf, elem->refPrefix); |
| 1093 | *buf = xmlStrcat(*buf, BAD_CAST ":"); |
| 1094 | *buf = xmlStrcat(*buf, elem->ref); |
| 1095 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1096 | } |
| 1097 | } |
| 1098 | break; |
| 1099 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
| 1100 | case XML_SCHEMA_TYPE_IDC_KEY: |
| 1101 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
| 1102 | if (item->type == XML_SCHEMA_TYPE_IDC_UNIQUE) |
| 1103 | *buf = xmlStrdup(BAD_CAST "unique '"); |
| 1104 | else if (item->type == XML_SCHEMA_TYPE_IDC_KEY) |
| 1105 | *buf = xmlStrdup(BAD_CAST "key '"); |
| 1106 | else |
| 1107 | *buf = xmlStrdup(BAD_CAST "keyRef '"); |
| 1108 | *buf = xmlStrcat(*buf, ((xmlSchemaIDCPtr) item)->name); |
| 1109 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1110 | break; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 1111 | case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 1112 | *buf = xmlStrdup(xmlSchemaWildcardPCToString( |
| 1113 | ((xmlSchemaWildcardPtr) item)->processContents)); |
| 1114 | *buf = xmlStrcat(*buf, BAD_CAST " wildcard"); |
| 1115 | break; |
| 1116 | case XML_SCHEMA_FACET_MININCLUSIVE: |
| 1117 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
| 1118 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
| 1119 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
| 1120 | case XML_SCHEMA_FACET_TOTALDIGITS: |
| 1121 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
| 1122 | case XML_SCHEMA_FACET_PATTERN: |
| 1123 | case XML_SCHEMA_FACET_ENUMERATION: |
| 1124 | case XML_SCHEMA_FACET_WHITESPACE: |
| 1125 | case XML_SCHEMA_FACET_LENGTH: |
| 1126 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 1127 | case XML_SCHEMA_FACET_MINLENGTH: |
| 1128 | *buf = xmlStrdup(BAD_CAST "facet '"); |
| 1129 | *buf = xmlStrcat(*buf, xmlSchemaFacetTypeToString(item->type)); |
| 1130 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1131 | break; |
| 1132 | case XML_SCHEMA_TYPE_NOTATION: |
| 1133 | *buf = xmlStrdup(BAD_CAST "notation"); |
| 1134 | break; |
| 1135 | case XML_SCHEMA_TYPE_GROUP: |
| 1136 | if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) { |
| 1137 | *buf = xmlStrdup(xmlSchemaElemModelGrDef); |
| 1138 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1139 | *buf = xmlStrcat(*buf, item->name); |
| 1140 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1141 | } else { |
| 1142 | *buf = xmlStrdup(xmlSchemaElemModelGrRef); |
| 1143 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1144 | *buf = xmlStrcat(*buf, item->ref); |
| 1145 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1146 | } |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 1147 | break; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 1148 | default: |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1149 | named = 0; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 1150 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1151 | } else |
| 1152 | named = 0; |
| 1153 | |
| 1154 | if ((named == 0) && (itemNode != NULL)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1155 | xmlNodePtr elem; |
| 1156 | |
| 1157 | if (itemNode->type == XML_ATTRIBUTE_NODE) |
| 1158 | elem = itemNode->parent; |
| 1159 | else |
| 1160 | elem = itemNode; |
| 1161 | *buf = xmlStrdup(BAD_CAST "Element '"); |
| 1162 | if (parsing) |
| 1163 | *buf = xmlStrcat(*buf, elem->name); |
| 1164 | else |
| 1165 | *buf = xmlStrcat(*buf, |
| 1166 | xmlSchemaFormatNsPrefixLocal(&str, elem->ns, elem->name)); |
| 1167 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1168 | } |
| 1169 | if ((itemNode != NULL) && (itemNode->type == XML_ATTRIBUTE_NODE)) { |
| 1170 | *buf = xmlStrcat(*buf, BAD_CAST ", attribute '"); |
| 1171 | *buf = xmlStrcat(*buf, xmlSchemaFormatNsPrefixLocal(&str, |
| 1172 | itemNode->ns, itemNode->name)); |
| 1173 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1174 | } |
| 1175 | FREE_AND_NULL(str); |
| 1176 | |
| 1177 | return (*buf); |
| 1178 | } |
| 1179 | |
| 1180 | /** |
| 1181 | * xmlSchemaPFormatItemDes: |
| 1182 | * @buf: the string buffer |
| 1183 | * @item: the item as a schema object |
| 1184 | * @itemNode: the item as a node |
| 1185 | * |
| 1186 | * If the pointer to @buf is not NULL and @but holds no value, |
| 1187 | * the value is set to a item designation using |
| 1188 | * xmlSchemaFormatItemForReport. This one avoids adding |
| 1189 | * an attribute designation postfix. |
| 1190 | * |
| 1191 | * Returns a string of all enumeration elements. |
| 1192 | */ |
| 1193 | static void |
| 1194 | xmlSchemaPRequestItemDes(xmlChar **buf, |
| 1195 | xmlSchemaTypePtr item, |
| 1196 | xmlNodePtr itemNode) |
| 1197 | { |
| 1198 | if ((buf == 0) || (*buf != NULL)) |
| 1199 | return; |
| 1200 | if (itemNode->type == XML_ATTRIBUTE_NODE) |
| 1201 | itemNode = itemNode->parent; |
| 1202 | xmlSchemaFormatItemForReport(buf, NULL, item, itemNode, 1); |
| 1203 | } |
| 1204 | |
| 1205 | /** |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1206 | * xmlSchemaGetCanonValueWhtsp: |
| 1207 | * @val: the precomputed value |
| 1208 | * @retValue: the returned value |
| 1209 | * @ws: the whitespace type of the value |
| 1210 | * |
| 1211 | * Get a the cononical representation of the value. |
| 1212 | * The caller has to free the returned retValue. |
| 1213 | * |
| 1214 | * Returns 0 if the value could be built and -1 in case of |
| 1215 | * API errors or if the value type is not supported yet. |
| 1216 | */ |
| 1217 | static int |
| 1218 | xmlSchemaGetCanonValueWhtsp(const xmlChar *value, |
| 1219 | xmlSchemaValPtr val, |
| 1220 | xmlSchemaWhitespaceValueType ws, |
| 1221 | const xmlChar **retValue) |
| 1222 | { |
| 1223 | xmlSchemaValType valType; |
| 1224 | |
| 1225 | if ((retValue == NULL) || (value == NULL) || (val == NULL)) |
| 1226 | return (-1); |
| 1227 | *retValue = NULL; |
| 1228 | valType = xmlSchemaGetValType(val); |
| 1229 | switch (valType) { |
| 1230 | case XML_SCHEMAS_STRING: |
| 1231 | if (value == NULL) |
| 1232 | *retValue = BAD_CAST xmlStrdup(BAD_CAST ""); |
| 1233 | else |
| 1234 | *retValue = |
| 1235 | BAD_CAST xmlStrdup(value); |
| 1236 | break; |
| 1237 | case XML_SCHEMAS_NORMSTRING: |
| 1238 | if (value == NULL) |
| 1239 | *retValue = BAD_CAST xmlStrdup(BAD_CAST ""); |
| 1240 | else { |
| 1241 | if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE) |
| 1242 | *retValue = xmlSchemaCollapseString(value); |
| 1243 | else |
| 1244 | *retValue = xmlSchemaWhiteSpaceReplace(value); |
| 1245 | if ((*retValue) == NULL) |
| 1246 | *retValue = BAD_CAST xmlStrdup(value); |
| 1247 | } |
| 1248 | break; |
| 1249 | default: |
| 1250 | return (xmlSchemaGetCanonValue(val, retValue)); |
| 1251 | } |
| 1252 | return (0); |
| 1253 | } |
| 1254 | |
| 1255 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1256 | * xmlSchemaFormatFacetEnumSet: |
| 1257 | * @buf: the string buffer |
| 1258 | * @type: the type holding the enumeration facets |
| 1259 | * |
| 1260 | * Builds a string consisting of all enumeration elements. |
| 1261 | * |
| 1262 | * Returns a string of all enumeration elements. |
| 1263 | */ |
| 1264 | static const xmlChar * |
| 1265 | xmlSchemaFormatFacetEnumSet(xmlChar **buf, xmlSchemaTypePtr type) |
| 1266 | { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1267 | xmlSchemaFacetPtr facet; |
| 1268 | xmlSchemaWhitespaceValueType ws; |
| 1269 | const xmlChar *value; |
| 1270 | int res; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1271 | |
| 1272 | if (*buf != NULL) |
| 1273 | xmlFree(*buf); |
| 1274 | *buf = NULL; |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1275 | |
| 1276 | do { |
| 1277 | /* |
| 1278 | * Use the whitespace type of the base type. |
| 1279 | */ |
| 1280 | if (type->type == XML_SCHEMA_TYPE_COMPLEX) |
| 1281 | /* TODO: Get rid of this case. */ |
| 1282 | ws = (xmlSchemaWhitespaceValueType) |
| 1283 | xmlSchemaGetWhiteSpaceFacetValue( |
| 1284 | xmlSchemaGetSimpleContentType(type)); |
| 1285 | else |
| 1286 | ws = (xmlSchemaWhitespaceValueType) |
| 1287 | xmlSchemaGetWhiteSpaceFacetValue(type->baseType); |
| 1288 | for (facet = type->facets; facet != NULL; facet = facet->next) { |
| 1289 | if (facet->type != XML_SCHEMA_FACET_ENUMERATION) |
| 1290 | continue; |
| 1291 | res = xmlSchemaGetCanonValueWhtsp(facet->value, facet->val, |
| 1292 | ws, &value); |
| 1293 | if (res == -1) { |
| 1294 | xmlSchemaVErr(NULL, NULL, |
| 1295 | XML_SCHEMAV_INTERNAL, |
| 1296 | "Internal error: xmlSchemaFormatFacetEnumSet, failed to " |
| 1297 | "compute the canonical lexical representation.\n", |
| 1298 | NULL, NULL); |
| 1299 | if (*buf != NULL) |
| 1300 | xmlFree(*buf); |
| 1301 | *buf = NULL; |
| 1302 | return (NULL); |
| 1303 | } |
| 1304 | if (*buf == NULL) { |
| 1305 | *buf = xmlStrdup(BAD_CAST "'"); |
| 1306 | *buf = xmlStrcat(*buf, value); |
| 1307 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1308 | } else { |
| 1309 | *buf = xmlStrcat(*buf, BAD_CAST ", '"); |
| 1310 | *buf = xmlStrcat(*buf, value); |
| 1311 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1312 | } |
| 1313 | } |
| 1314 | if (type->type == XML_SCHEMA_TYPE_COMPLEX) |
| 1315 | /* TODO: Get rid of this case. */ |
| 1316 | type = xmlSchemaGetSimpleContentType(type); |
| 1317 | else |
| 1318 | type = type->baseType; |
| 1319 | } while ((type != NULL) && (type->type != XML_SCHEMA_TYPE_BASIC)); |
| 1320 | |
| 1321 | #if 0 |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1322 | for (link = type->facetSet; link != NULL; link = link->next) { |
| 1323 | if (link->facet->type == XML_SCHEMA_FACET_ENUMERATION) { |
| 1324 | if (*buf == NULL) { |
| 1325 | *buf = xmlStrdup(BAD_CAST "'"); |
| 1326 | *buf = xmlStrcat(*buf, link->facet->value); |
| 1327 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1328 | } else { |
| 1329 | *buf = xmlStrcat(*buf, BAD_CAST ", '"); |
| 1330 | *buf = xmlStrcat(*buf, link->facet->value); |
| 1331 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1332 | } |
| 1333 | } |
| 1334 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1335 | #endif |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1336 | return ((const xmlChar *) *buf); |
| 1337 | } |
| 1338 | |
| 1339 | /** |
| 1340 | * xmlSchemaVFacetErr: |
| 1341 | * @ctxt: the schema validation context |
| 1342 | * @error: the error code |
| 1343 | * @node: the node to be validated |
| 1344 | * @value: the value of the node |
| 1345 | * @type: the type holding the facet |
| 1346 | * @facet: the facet |
| 1347 | * @message: the error message of NULL |
| 1348 | * @str1: extra data |
| 1349 | * @str2: extra data |
| 1350 | * @str3: extra data |
| 1351 | * |
| 1352 | * Reports a facet validation error. |
| 1353 | * TODO: Should this report the value of an element as well? |
| 1354 | */ |
| 1355 | static void |
| 1356 | xmlSchemaVFacetErr(xmlSchemaValidCtxtPtr ctxt, |
| 1357 | xmlParserErrors error, |
| 1358 | xmlNodePtr node, |
| 1359 | const xmlChar *value, |
| 1360 | unsigned long length, |
| 1361 | xmlSchemaTypePtr type, |
| 1362 | xmlSchemaFacetPtr facet, |
| 1363 | const char *message, |
| 1364 | const xmlChar *str1, |
| 1365 | const xmlChar *str2, |
| 1366 | const xmlChar *str3) |
| 1367 | { |
| 1368 | xmlChar *str = NULL, *msg = NULL; |
| 1369 | xmlSchemaTypeType facetType; |
| 1370 | |
| 1371 | xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); |
| 1372 | msg = xmlStrcat(msg, BAD_CAST " ["); |
| 1373 | msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); |
| 1374 | msg = xmlStrcat(msg, BAD_CAST ", facet '"); |
| 1375 | if (error == XML_SCHEMAV_CVC_ENUMERATION_VALID) { |
| 1376 | facetType = XML_SCHEMA_FACET_ENUMERATION; |
| 1377 | /* |
| 1378 | * If enumerations are validated, one must not expect the |
| 1379 | * facet to be given. |
| 1380 | */ |
| 1381 | } else |
| 1382 | facetType = facet->type; |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 1383 | msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facetType)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1384 | msg = xmlStrcat(msg, BAD_CAST "']: "); |
| 1385 | if (message == NULL) { |
| 1386 | /* |
| 1387 | * Use a default message. |
| 1388 | */ |
| 1389 | if ((facetType == XML_SCHEMA_FACET_LENGTH) || |
| 1390 | (facetType == XML_SCHEMA_FACET_MINLENGTH) || |
| 1391 | (facetType == XML_SCHEMA_FACET_MAXLENGTH)) { |
| 1392 | |
| 1393 | char len[25], actLen[25]; |
| 1394 | |
| 1395 | /* FIXME, TODO: What is the max expected string length of the |
| 1396 | * this value? |
| 1397 | */ |
| 1398 | if (node->type == XML_ATTRIBUTE_NODE) |
| 1399 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' has a length of '%s'; "); |
| 1400 | else |
| 1401 | msg = xmlStrcat(msg, BAD_CAST "The value has a length of '%s'; "); |
| 1402 | |
| 1403 | snprintf(len, 24, "%lu", xmlSchemaGetFacetValueAsULong(facet)); |
| 1404 | snprintf(actLen, 24, "%lu", length); |
| 1405 | |
| 1406 | if (facetType == XML_SCHEMA_FACET_LENGTH) |
| 1407 | msg = xmlStrcat(msg, |
| 1408 | BAD_CAST "this differs from the allowed length of '%s'.\n"); |
| 1409 | else if (facetType == XML_SCHEMA_FACET_MAXLENGTH) |
| 1410 | msg = xmlStrcat(msg, |
| 1411 | BAD_CAST "this exceeds the allowed maximum length of '%s'.\n"); |
| 1412 | else if (facetType == XML_SCHEMA_FACET_MINLENGTH) |
| 1413 | msg = xmlStrcat(msg, |
| 1414 | BAD_CAST "this underruns the allowed minimum length of '%s'.\n"); |
| 1415 | |
| 1416 | if (node->type == XML_ATTRIBUTE_NODE) |
| 1417 | xmlSchemaVErrExt(ctxt, node, error, |
| 1418 | (const char *) msg, |
| 1419 | value, (const xmlChar *) actLen, (const xmlChar *) len, |
| 1420 | NULL, NULL); |
| 1421 | else |
| 1422 | xmlSchemaVErr(ctxt, node, error, |
| 1423 | (const char *) msg, |
| 1424 | (const xmlChar *) actLen, (const xmlChar *) len); |
| 1425 | |
| 1426 | } else if (facetType == XML_SCHEMA_FACET_ENUMERATION) { |
| 1427 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not an element " |
| 1428 | "of the set {%s}.\n"); |
| 1429 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, |
| 1430 | xmlSchemaFormatFacetEnumSet(&str, type)); |
| 1431 | } else if (facetType == XML_SCHEMA_FACET_PATTERN) { |
| 1432 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not accepted " |
| 1433 | "by the pattern '%s'.\n"); |
| 1434 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 1435 | facet->value); |
Daniel Veillard | cc5e233 | 2005-03-16 21:55:35 +0000 | [diff] [blame] | 1436 | } else if (facetType == XML_SCHEMA_FACET_MININCLUSIVE) { |
| 1437 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is less than the " |
| 1438 | "minimum value allowed ('%s').\n"); |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 1439 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, |
Daniel Veillard | cc5e233 | 2005-03-16 21:55:35 +0000 | [diff] [blame] | 1440 | facet->value); |
| 1441 | } else if (facetType == XML_SCHEMA_FACET_MAXINCLUSIVE) { |
| 1442 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is greater than the " |
| 1443 | "maximum value allowed ('%s').\n"); |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 1444 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, |
Daniel Veillard | cc5e233 | 2005-03-16 21:55:35 +0000 | [diff] [blame] | 1445 | facet->value); |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 1446 | #if 0 |
| 1447 | } else if (facetType == XML_SCHEMA_FACET_MINEXCLUSIVE) { |
| 1448 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is less than the " |
| 1449 | "minimum exclusive value allowed ('%s').\n"); |
| 1450 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, |
| 1451 | facet->value); |
| 1452 | } else if (facetType == XML_SCHEMA_FACET_MAXEXCLUSIVE) { |
| 1453 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is greater than the " |
| 1454 | "maximum exclusive value allowed ('%s').\n"); |
| 1455 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, |
| 1456 | facet->value); |
| 1457 | #endif |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1458 | } else if (node->type == XML_ATTRIBUTE_NODE) { |
| 1459 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not facet-valid.\n"); |
| 1460 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, NULL); |
| 1461 | } else { |
| 1462 | msg = xmlStrcat(msg, BAD_CAST "The value is not facet-valid.\n"); |
| 1463 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, NULL, NULL); |
| 1464 | } |
| 1465 | } else { |
| 1466 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 1467 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1468 | xmlSchemaVErr3(ctxt, node, error, (const char *) msg, str1, str2, str3); |
| 1469 | } |
| 1470 | FREE_AND_NULL(str) |
| 1471 | xmlFree(msg); |
| 1472 | } |
| 1473 | |
| 1474 | /** |
| 1475 | * xmlSchemaVSimpleTypeErr: |
| 1476 | * @ctxt: the schema validation context |
| 1477 | * @error: the error code |
| 1478 | * @type: the type used for validation |
| 1479 | * @node: the node containing the validated value |
| 1480 | * @value: the validated value |
| 1481 | * |
| 1482 | * Reports a simple type validation error. |
| 1483 | * TODO: Should this report the value of an element as well? |
| 1484 | */ |
| 1485 | static void |
| 1486 | xmlSchemaVSimpleTypeErr(xmlSchemaValidCtxtPtr ctxt, |
| 1487 | xmlParserErrors error, |
| 1488 | xmlNodePtr node, |
| 1489 | const xmlChar *value, |
| 1490 | xmlSchemaTypePtr type) |
| 1491 | { |
| 1492 | xmlChar *str = NULL, *msg = NULL; |
| 1493 | |
| 1494 | xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); |
| 1495 | msg = xmlStrcat(msg, BAD_CAST " ["); |
| 1496 | msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); |
| 1497 | if (node->type == XML_ATTRIBUTE_NODE) { |
| 1498 | msg = xmlStrcat(msg, BAD_CAST "]: The value '%s' is not valid.\n"); |
| 1499 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, NULL); |
| 1500 | } else { |
| 1501 | msg = xmlStrcat(msg, BAD_CAST "]: The character content is not valid.\n"); |
| 1502 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, NULL, NULL); |
| 1503 | } |
| 1504 | FREE_AND_NULL(str) |
| 1505 | xmlFree(msg); |
| 1506 | } |
| 1507 | |
| 1508 | /** |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1509 | * xmlSchemaVComplexTypeErr: |
| 1510 | * @ctxt: the schema validation context |
| 1511 | * @error: the error code |
| 1512 | * @node: the node containing the validated value |
| 1513 | * @type: the complex type used for validation |
| 1514 | * @message: the error message |
| 1515 | * |
| 1516 | * Reports a complex type validation error. |
| 1517 | */ |
| 1518 | static void |
| 1519 | xmlSchemaVComplexTypeErr(xmlSchemaValidCtxtPtr ctxt, |
| 1520 | xmlParserErrors error, |
| 1521 | xmlNodePtr node, |
| 1522 | xmlSchemaTypePtr type, |
| 1523 | const char *message) |
| 1524 | { |
| 1525 | xmlChar *str = NULL, *msg = NULL; |
| 1526 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 1527 | xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 1528 | /* Specify the complex type only if it is global. */ |
| 1529 | if ((type != NULL) && (type->flags & XML_SCHEMAS_TYPE_GLOBAL)) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 1530 | msg = xmlStrcat(msg, BAD_CAST " ["); |
| 1531 | msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); |
| 1532 | msg = xmlStrcat(msg, BAD_CAST "]"); |
| 1533 | } |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1534 | msg = xmlStrcat(msg, BAD_CAST ": %s.\n"); |
| 1535 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1536 | (const xmlChar *) message, NULL); |
| 1537 | FREE_AND_NULL(str) |
| 1538 | xmlFree(msg); |
| 1539 | } |
| 1540 | |
| 1541 | /** |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1542 | * xmlSchemaVComplexTypeElemErr: |
| 1543 | * @ctxt: the schema validation context |
| 1544 | * @error: the error code |
| 1545 | * @node: the node containing the validated value |
| 1546 | * @type: the complex type used for validation |
| 1547 | * @message: the error message |
| 1548 | * |
| 1549 | * Reports a complex type validation error. |
| 1550 | */ |
| 1551 | static void |
| 1552 | xmlSchemaVComplexTypeElemErr(xmlSchemaValidCtxtPtr ctxt, |
| 1553 | xmlParserErrors error, |
| 1554 | xmlNodePtr node, |
| 1555 | xmlSchemaTypePtr type, |
| 1556 | const char *message, |
| 1557 | int nbval, |
| 1558 | int nbneg, |
| 1559 | xmlChar **values) |
| 1560 | { |
| 1561 | xmlChar *str = NULL, *msg = NULL; |
| 1562 | xmlChar *localName, *nsName; |
| 1563 | const xmlChar *cur, *end; |
| 1564 | int i; |
| 1565 | |
| 1566 | xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); |
| 1567 | /* Specify the complex type only if it is global. */ |
| 1568 | if ((type != NULL) && (type->flags & XML_SCHEMAS_TYPE_GLOBAL)) { |
| 1569 | msg = xmlStrcat(msg, BAD_CAST " ["); |
| 1570 | msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); |
| 1571 | msg = xmlStrcat(msg, BAD_CAST "]"); |
| 1572 | FREE_AND_NULL(str) |
| 1573 | } |
| 1574 | msg = xmlStrcat(msg, BAD_CAST ": "); |
| 1575 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 1576 | /* |
| 1577 | * Note that is does not make sense to report that we have a |
| 1578 | * wildcard here, since the wildcard might be unfolded into |
| 1579 | * multiple transitions. |
| 1580 | */ |
| 1581 | if (nbval + nbneg > 0) { |
| 1582 | if (nbval + nbneg > 1) { |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 1583 | str = xmlStrdup(BAD_CAST ". Expected is one of ( "); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1584 | } else |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 1585 | str = xmlStrdup(BAD_CAST ". Expected is ( "); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1586 | nsName = NULL; |
| 1587 | |
| 1588 | for (i = 0; i < nbval + nbneg; i++) { |
| 1589 | cur = values[i]; |
| 1590 | /* |
| 1591 | * Get the local name. |
| 1592 | */ |
| 1593 | localName = NULL; |
| 1594 | |
| 1595 | end = cur; |
| 1596 | if (*end == '*') { |
| 1597 | localName = xmlStrdup(BAD_CAST "*"); |
| 1598 | *end++; |
| 1599 | } else { |
| 1600 | while ((*end != 0) && (*end != '|')) |
| 1601 | end++; |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1602 | localName = xmlStrncat(localName, BAD_CAST cur, end - cur); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1603 | } |
| 1604 | if (*end != 0) { |
| 1605 | *end++; |
| 1606 | /* |
| 1607 | * Skip "*|*" if they come with negated expressions, since |
| 1608 | * they represent the same negated wildcard. |
| 1609 | */ |
| 1610 | if ((nbneg == 0) || (*end != '*') || (*localName != '*')) { |
| 1611 | /* |
| 1612 | * Get the namespace name. |
| 1613 | */ |
| 1614 | cur = end; |
| 1615 | if (*end == '*') { |
| 1616 | nsName = xmlStrdup(BAD_CAST "{*}"); |
| 1617 | } else { |
| 1618 | while (*end != 0) |
| 1619 | end++; |
| 1620 | |
| 1621 | if (i >= nbval) |
| 1622 | nsName = xmlStrdup(BAD_CAST "{##other:"); |
| 1623 | else |
| 1624 | nsName = xmlStrdup(BAD_CAST "{"); |
| 1625 | |
| 1626 | nsName = xmlStrncat(nsName, BAD_CAST cur, end - cur); |
| 1627 | nsName = xmlStrcat(nsName, BAD_CAST "}"); |
| 1628 | } |
| 1629 | str = xmlStrcat(str, BAD_CAST nsName); |
| 1630 | FREE_AND_NULL(nsName) |
| 1631 | } else { |
| 1632 | FREE_AND_NULL(localName); |
| 1633 | continue; |
| 1634 | } |
| 1635 | } |
| 1636 | str = xmlStrcat(str, BAD_CAST localName); |
| 1637 | FREE_AND_NULL(localName); |
| 1638 | |
| 1639 | if (i < nbval + nbneg -1) |
| 1640 | str = xmlStrcat(str, BAD_CAST ", "); |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 1641 | } |
| 1642 | str = xmlStrcat(str, BAD_CAST " )"); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1643 | msg = xmlStrcat(msg, BAD_CAST str); |
| 1644 | FREE_AND_NULL(str) |
| 1645 | } |
| 1646 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1647 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, NULL, NULL); |
| 1648 | xmlFree(msg); |
| 1649 | } |
| 1650 | |
| 1651 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1652 | * xmlSchemaPMissingAttrErr: |
| 1653 | * @ctxt: the schema validation context |
| 1654 | * @ownerDes: the designation of the owner |
| 1655 | * @ownerName: the name of the owner |
| 1656 | * @ownerItem: the owner as a schema object |
| 1657 | * @ownerElem: the owner as an element node |
| 1658 | * @node: the parent element node of the missing attribute node |
| 1659 | * @type: the corresponding type of the attribute node |
| 1660 | * |
| 1661 | * Reports an illegal attribute. |
| 1662 | */ |
| 1663 | static void |
| 1664 | xmlSchemaPMissingAttrErr(xmlSchemaParserCtxtPtr ctxt, |
| 1665 | xmlParserErrors error, |
| 1666 | xmlChar **ownerDes, |
| 1667 | xmlSchemaTypePtr ownerItem, |
| 1668 | xmlNodePtr ownerElem, |
| 1669 | const char *name, |
| 1670 | const char *message) |
| 1671 | { |
| 1672 | xmlChar *des = NULL; |
| 1673 | |
| 1674 | if (ownerDes == NULL) |
| 1675 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem, 1); |
| 1676 | else if (*ownerDes == NULL) { |
| 1677 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, ownerElem, 1); |
| 1678 | des = *ownerDes; |
| 1679 | } else |
| 1680 | des = *ownerDes; |
| 1681 | if (message != NULL) |
| 1682 | xmlSchemaPErr(ctxt, ownerElem, error, "%s: %s.\n", BAD_CAST des, BAD_CAST message); |
| 1683 | else |
| 1684 | xmlSchemaPErr(ctxt, ownerElem, error, |
| 1685 | "%s: The attribute '%s' is required but missing.\n", |
| 1686 | BAD_CAST des, BAD_CAST name); |
| 1687 | if (ownerDes == NULL) |
| 1688 | FREE_AND_NULL(des); |
| 1689 | } |
| 1690 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1691 | /** |
| 1692 | * xmlSchemaCompTypeToString: |
| 1693 | * @type: the type of the schema item |
| 1694 | * |
| 1695 | * Returns the component name of a schema item. |
| 1696 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1697 | static const char * |
| 1698 | xmlSchemaCompTypeToString(xmlSchemaTypeType type) |
| 1699 | { |
| 1700 | switch (type) { |
| 1701 | case XML_SCHEMA_TYPE_SIMPLE: |
| 1702 | return("simple type definition"); |
| 1703 | case XML_SCHEMA_TYPE_COMPLEX: |
| 1704 | return("complex type definition"); |
| 1705 | case XML_SCHEMA_TYPE_ELEMENT: |
| 1706 | return("element declaration"); |
| 1707 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 1708 | return("attribute declaration"); |
| 1709 | case XML_SCHEMA_TYPE_GROUP: |
| 1710 | return("model group definition"); |
| 1711 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
| 1712 | return("attribute group definition"); |
| 1713 | case XML_SCHEMA_TYPE_NOTATION: |
| 1714 | return("notation declaration"); |
| 1715 | default: |
| 1716 | return("Not a schema component"); |
| 1717 | } |
| 1718 | } |
| 1719 | /** |
| 1720 | * xmlSchemaPResCompAttrErr: |
| 1721 | * @ctxt: the schema validation context |
| 1722 | * @error: the error code |
| 1723 | * @ownerDes: the designation of the owner |
| 1724 | * @ownerItem: the owner as a schema object |
| 1725 | * @ownerElem: the owner as an element node |
| 1726 | * @name: the name of the attribute holding the QName |
| 1727 | * @refName: the referenced local name |
| 1728 | * @refURI: the referenced namespace URI |
| 1729 | * @message: optional message |
| 1730 | * |
| 1731 | * Used to report QName attribute values that failed to resolve |
| 1732 | * to schema components. |
| 1733 | */ |
| 1734 | static void |
| 1735 | xmlSchemaPResCompAttrErr(xmlSchemaParserCtxtPtr ctxt, |
| 1736 | xmlParserErrors error, |
| 1737 | xmlChar **ownerDes, |
| 1738 | xmlSchemaTypePtr ownerItem, |
| 1739 | xmlNodePtr ownerElem, |
| 1740 | const char *name, |
| 1741 | const xmlChar *refName, |
| 1742 | const xmlChar *refURI, |
| 1743 | xmlSchemaTypeType refType, |
| 1744 | const char *refTypeStr) |
| 1745 | { |
| 1746 | xmlChar *des = NULL, *strA = NULL; |
| 1747 | |
| 1748 | if (ownerDes == NULL) |
| 1749 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem, 1); |
| 1750 | else if (*ownerDes == NULL) { |
| 1751 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, ownerElem, 1); |
| 1752 | des = *ownerDes; |
| 1753 | } else |
| 1754 | des = *ownerDes; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1755 | if (refTypeStr == NULL) |
| 1756 | refTypeStr = xmlSchemaCompTypeToString(refType); |
| 1757 | xmlSchemaPErrExt(ctxt, ownerElem, error, |
| 1758 | NULL, NULL, NULL, |
| 1759 | "%s, attribute '%s': The QName value %s does not resolve to a(n) " |
| 1760 | "%s.\n", BAD_CAST des, BAD_CAST name, |
| 1761 | xmlSchemaFormatNsUriLocal(&strA, refURI, refName), |
| 1762 | BAD_CAST refTypeStr, NULL); |
| 1763 | if (ownerDes == NULL) |
| 1764 | FREE_AND_NULL(des) |
| 1765 | FREE_AND_NULL(strA) |
| 1766 | } |
| 1767 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1768 | /** |
| 1769 | * xmlSchemaPCustomAttrErr: |
| 1770 | * @ctxt: the schema parser context |
| 1771 | * @error: the error code |
| 1772 | * @ownerDes: the designation of the owner |
| 1773 | * @ownerItem: the owner as a schema object |
| 1774 | * @attr: the illegal attribute node |
| 1775 | * |
| 1776 | * Reports an illegal attribute during the parse. |
| 1777 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1778 | static void |
| 1779 | xmlSchemaPCustomAttrErr(xmlSchemaParserCtxtPtr ctxt, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1780 | xmlParserErrors error, |
| 1781 | xmlChar **ownerDes, |
| 1782 | xmlSchemaTypePtr ownerItem, |
| 1783 | xmlAttrPtr attr, |
| 1784 | const char *msg) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1785 | { |
| 1786 | xmlChar *des = NULL; |
| 1787 | |
| 1788 | if (ownerDes == NULL) |
| 1789 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent, 1); |
| 1790 | else if (*ownerDes == NULL) { |
| 1791 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent, 1); |
| 1792 | des = *ownerDes; |
| 1793 | } else |
| 1794 | des = *ownerDes; |
| 1795 | xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL, |
| 1796 | "%s, attribute '%s': %s.\n", |
| 1797 | BAD_CAST des, attr->name, (const xmlChar *) msg, NULL, NULL); |
| 1798 | if (ownerDes == NULL) |
| 1799 | FREE_AND_NULL(des); |
| 1800 | } |
| 1801 | |
| 1802 | /** |
| 1803 | * xmlSchemaPIllegalAttrErr: |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1804 | * @ctxt: the schema parser context |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1805 | * @error: the error code |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1806 | * @ownerDes: the designation of the attribute's owner |
| 1807 | * @ownerItem: the attribute's owner item |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1808 | * @attr: the illegal attribute node |
| 1809 | * |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1810 | * Reports an illegal attribute during the parse. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1811 | */ |
| 1812 | static void |
| 1813 | xmlSchemaPIllegalAttrErr(xmlSchemaParserCtxtPtr ctxt, |
| 1814 | xmlParserErrors error, |
| 1815 | xmlChar **ownerDes, |
| 1816 | xmlSchemaTypePtr ownerItem, |
| 1817 | xmlAttrPtr attr) |
| 1818 | { |
| 1819 | xmlChar *des = NULL, *strA = NULL; |
| 1820 | |
| 1821 | if (ownerDes == NULL) |
| 1822 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent, 1); |
| 1823 | else if (*ownerDes == NULL) { |
| 1824 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent, 1); |
| 1825 | des = *ownerDes; |
| 1826 | } else |
| 1827 | des = *ownerDes; |
| 1828 | xmlSchemaPErr(ctxt, (xmlNodePtr) attr, error, |
| 1829 | "%s: The attribute '%s' is not allowed.\n", BAD_CAST des, |
| 1830 | xmlSchemaFormatNsPrefixLocal(&strA, attr->ns, attr->name)); |
| 1831 | if (ownerDes == NULL) |
| 1832 | FREE_AND_NULL(des); |
| 1833 | FREE_AND_NULL(strA); |
| 1834 | } |
| 1835 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1836 | /** |
| 1837 | * xmlSchemaPAquireDes: |
| 1838 | * @des: the first designation |
| 1839 | * @itemDes: the second designation |
| 1840 | * @item: the schema item |
| 1841 | * @itemElem: the node of the schema item |
| 1842 | * |
| 1843 | * Creates a designation for an item. |
| 1844 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1845 | static void |
| 1846 | xmlSchemaPAquireDes(xmlChar **des, |
| 1847 | xmlChar **itemDes, |
| 1848 | xmlSchemaTypePtr item, |
| 1849 | xmlNodePtr itemElem) |
| 1850 | { |
| 1851 | if (itemDes == NULL) |
| 1852 | xmlSchemaFormatItemForReport(des, NULL, item, itemElem, 1); |
| 1853 | else if (*itemDes == NULL) { |
| 1854 | xmlSchemaFormatItemForReport(itemDes, NULL, item, itemElem, 1); |
| 1855 | *des = *itemDes; |
| 1856 | } else |
| 1857 | *des = *itemDes; |
| 1858 | } |
| 1859 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1860 | /** |
| 1861 | * xmlSchemaPCustomErr: |
| 1862 | * @ctxt: the schema parser context |
| 1863 | * @error: the error code |
| 1864 | * @itemDes: the designation of the schema item |
| 1865 | * @item: the schema item |
| 1866 | * @itemElem: the node of the schema item |
| 1867 | * @message: the error message |
| 1868 | * @str1: an optional param for the error message |
| 1869 | * @str2: an optional param for the error message |
| 1870 | * @str3: an optional param for the error message |
| 1871 | * |
| 1872 | * Reports an error during parsing. |
| 1873 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1874 | static void |
| 1875 | xmlSchemaPCustomErrExt(xmlSchemaParserCtxtPtr ctxt, |
| 1876 | xmlParserErrors error, |
| 1877 | xmlChar **itemDes, |
| 1878 | xmlSchemaTypePtr item, |
| 1879 | xmlNodePtr itemElem, |
| 1880 | const char *message, |
| 1881 | const xmlChar *str1, |
| 1882 | const xmlChar *str2, |
| 1883 | const xmlChar *str3) |
| 1884 | { |
| 1885 | xmlChar *des = NULL, *msg = NULL; |
| 1886 | |
| 1887 | xmlSchemaPAquireDes(&des, itemDes, item, itemElem); |
| 1888 | msg = xmlStrdup(BAD_CAST "%s: "); |
| 1889 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 1890 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1891 | if ((itemElem == NULL) && (item != NULL)) |
| 1892 | itemElem = item->node; |
| 1893 | xmlSchemaPErrExt(ctxt, itemElem, error, NULL, NULL, NULL, |
| 1894 | (const char *) msg, BAD_CAST des, str1, str2, str3, NULL); |
| 1895 | if (itemDes == NULL) |
| 1896 | FREE_AND_NULL(des); |
| 1897 | FREE_AND_NULL(msg); |
| 1898 | } |
| 1899 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1900 | /** |
| 1901 | * xmlSchemaPCustomErr: |
| 1902 | * @ctxt: the schema parser context |
| 1903 | * @error: the error code |
| 1904 | * @itemDes: the designation of the schema item |
| 1905 | * @item: the schema item |
| 1906 | * @itemElem: the node of the schema item |
| 1907 | * @message: the error message |
| 1908 | * @str1: the optional param for the error message |
| 1909 | * |
| 1910 | * Reports an error during parsing. |
| 1911 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1912 | static void |
| 1913 | xmlSchemaPCustomErr(xmlSchemaParserCtxtPtr ctxt, |
| 1914 | xmlParserErrors error, |
| 1915 | xmlChar **itemDes, |
| 1916 | xmlSchemaTypePtr item, |
| 1917 | xmlNodePtr itemElem, |
| 1918 | const char *message, |
| 1919 | const xmlChar *str1) |
| 1920 | { |
| 1921 | xmlSchemaPCustomErrExt(ctxt, error, itemDes, item, itemElem, message, |
| 1922 | str1, NULL, NULL); |
| 1923 | } |
| 1924 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1925 | /** |
| 1926 | * xmlSchemaPAttrUseErr: |
| 1927 | * @ctxt: the schema parser context |
| 1928 | * @error: the error code |
| 1929 | * @itemDes: the designation of the schema type |
| 1930 | * @item: the schema type |
| 1931 | * @itemElem: the node of the schema type |
| 1932 | * @attr: the invalid schema attribute |
| 1933 | * @message: the error message |
| 1934 | * @str1: the optional param for the error message |
| 1935 | * |
| 1936 | * Reports an attribute use error during parsing. |
| 1937 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1938 | static void |
| 1939 | xmlSchemaPAttrUseErr(xmlSchemaParserCtxtPtr ctxt, |
| 1940 | xmlParserErrors error, |
| 1941 | xmlChar **itemDes, |
| 1942 | xmlSchemaTypePtr item, |
| 1943 | xmlNodePtr itemElem, |
| 1944 | const xmlSchemaAttributePtr attr, |
| 1945 | const char *message, |
| 1946 | const xmlChar *str1) |
| 1947 | { |
| 1948 | xmlChar *des = NULL, *strA = NULL, *msg = NULL; |
| 1949 | |
| 1950 | xmlSchemaPAquireDes(&des, itemDes, item, itemElem); |
| 1951 | xmlSchemaFormatNsUriLocal(&strA, xmlSchemaGetAttrTargetNsURI(attr), |
| 1952 | xmlSchemaGetAttrName(attr)); |
| 1953 | msg = xmlStrdup(BAD_CAST "%s, attr. use %s: "); |
| 1954 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 1955 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1956 | if ((itemElem == NULL) && (item != NULL)) |
| 1957 | itemElem = item->node; |
| 1958 | xmlSchemaPErrExt(ctxt, itemElem, error, NULL, NULL, NULL, |
| 1959 | (const char *) msg, BAD_CAST des, BAD_CAST strA, str1, NULL, NULL); |
| 1960 | if (itemDes == NULL) |
| 1961 | FREE_AND_NULL(des); |
| 1962 | FREE_AND_NULL(strA); |
| 1963 | xmlFree(msg); |
| 1964 | } |
| 1965 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1966 | /** |
| 1967 | * xmlSchemaPIllegalFacetAtomicErr: |
| 1968 | * @ctxt: the schema parser context |
| 1969 | * @error: the error code |
| 1970 | * @itemDes: the designation of the type |
| 1971 | * @item: the schema type |
| 1972 | * @baseItem: the base type of type |
| 1973 | * @facet: the illegal facet |
| 1974 | * |
| 1975 | * Reports an illegal facet for atomic simple types. |
| 1976 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1977 | static void |
| 1978 | xmlSchemaPIllegalFacetAtomicErr(xmlSchemaParserCtxtPtr ctxt, |
| 1979 | xmlParserErrors error, |
| 1980 | xmlChar **itemDes, |
| 1981 | xmlSchemaTypePtr item, |
| 1982 | xmlSchemaTypePtr baseItem, |
| 1983 | xmlSchemaFacetPtr facet) |
| 1984 | { |
| 1985 | xmlChar *des = NULL, *strT = NULL; |
| 1986 | |
| 1987 | xmlSchemaPAquireDes(&des, itemDes, item, item->node); |
| 1988 | xmlSchemaPErrExt(ctxt, item->node, error, NULL, NULL, NULL, |
| 1989 | "%s: The facet '%s' is not allowed on types derived from the " |
| 1990 | "type %s.\n", |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 1991 | BAD_CAST des, xmlSchemaFacetTypeToString(facet->type), |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1992 | xmlSchemaFormatItemForReport(&strT, NULL, baseItem, NULL, 1), |
| 1993 | NULL, NULL); |
| 1994 | if (itemDes == NULL) |
| 1995 | FREE_AND_NULL(des); |
| 1996 | FREE_AND_NULL(strT); |
| 1997 | } |
| 1998 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1999 | /** |
| 2000 | * xmlSchemaPIllegalFacetListUnionErr: |
| 2001 | * @ctxt: the schema parser context |
| 2002 | * @error: the error code |
| 2003 | * @itemDes: the designation of the schema item involved |
| 2004 | * @item: the schema item involved |
| 2005 | * @facet: the illegal facet |
| 2006 | * |
| 2007 | * Reports an illegal facet for <list> and <union>. |
| 2008 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2009 | static void |
| 2010 | xmlSchemaPIllegalFacetListUnionErr(xmlSchemaParserCtxtPtr ctxt, |
| 2011 | xmlParserErrors error, |
| 2012 | xmlChar **itemDes, |
| 2013 | xmlSchemaTypePtr item, |
| 2014 | xmlSchemaFacetPtr facet) |
| 2015 | { |
| 2016 | xmlChar *des = NULL, *strT = NULL; |
| 2017 | |
| 2018 | xmlSchemaPAquireDes(&des, itemDes, item, item->node); |
| 2019 | xmlSchemaPErr(ctxt, item->node, error, |
| 2020 | "%s: The facet '%s' is not allowed.\n", |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 2021 | BAD_CAST des, xmlSchemaFacetTypeToString(facet->type)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2022 | if (itemDes == NULL) |
| 2023 | FREE_AND_NULL(des); |
| 2024 | FREE_AND_NULL(strT); |
| 2025 | } |
| 2026 | |
| 2027 | /** |
| 2028 | * xmlSchemaPMutualExclAttrErr: |
| 2029 | * @ctxt: the schema validation context |
| 2030 | * @error: the error code |
| 2031 | * @elemDes: the designation of the parent element node |
| 2032 | * @attr: the bad attribute node |
| 2033 | * @type: the corresponding type of the attribute node |
| 2034 | * |
| 2035 | * Reports an illegal attribute. |
| 2036 | */ |
| 2037 | static void |
| 2038 | xmlSchemaPMutualExclAttrErr(xmlSchemaParserCtxtPtr ctxt, |
| 2039 | xmlParserErrors error, |
| 2040 | xmlChar **ownerDes, |
| 2041 | xmlSchemaTypePtr ownerItem, |
| 2042 | xmlAttrPtr attr, |
| 2043 | const char *name1, |
| 2044 | const char *name2) |
| 2045 | { |
| 2046 | xmlChar *des = NULL; |
| 2047 | |
| 2048 | if (ownerDes == NULL) |
| 2049 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent, 1); |
| 2050 | else if (*ownerDes == NULL) { |
| 2051 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent, 1); |
| 2052 | des = *ownerDes; |
| 2053 | } else |
| 2054 | des = *ownerDes; |
| 2055 | xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL, |
| 2056 | "%s: The attributes '%s' and '%s' are mutually exclusive.\n", |
| 2057 | BAD_CAST des, BAD_CAST name1, BAD_CAST name2, NULL, NULL); |
| 2058 | if (ownerDes == NULL) |
| 2059 | FREE_AND_NULL(des) |
| 2060 | } |
| 2061 | |
| 2062 | /** |
| 2063 | * xmlSchemaPSimpleTypeErr: |
| 2064 | * @ctxt: the schema validation context |
| 2065 | * @error: the error code |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2066 | * @type: the type specifier |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2067 | * @ownerDes: the designation of the owner |
| 2068 | * @ownerItem: the schema object if existent |
| 2069 | * @node: the validated node |
| 2070 | * @value: the validated value |
| 2071 | * |
| 2072 | * Reports a simple type validation error. |
| 2073 | * TODO: Should this report the value of an element as well? |
| 2074 | */ |
| 2075 | static void |
| 2076 | xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt, |
| 2077 | xmlParserErrors error, |
| 2078 | xmlChar **ownerDes, |
| 2079 | xmlSchemaTypePtr ownerItem, |
| 2080 | xmlNodePtr node, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2081 | xmlSchemaTypePtr type, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2082 | const char *typeDes, |
| 2083 | const xmlChar *value, |
| 2084 | const char *message, |
| 2085 | const xmlChar *str1, |
| 2086 | const xmlChar *str2) |
| 2087 | { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2088 | xmlChar *des = NULL, *strA = NULL, *strT = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2089 | |
| 2090 | if (ownerDes == NULL) |
| 2091 | xmlSchemaPRequestItemDes(&des, ownerItem, node); |
| 2092 | else if (*ownerDes == NULL) { |
| 2093 | xmlSchemaPRequestItemDes(ownerDes, ownerItem, node); |
| 2094 | des = *ownerDes; |
| 2095 | } else |
| 2096 | des = *ownerDes; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2097 | if (type != NULL) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2098 | typeDes = (const char *) xmlSchemaFormatItemForReport(&strT, NULL, type, NULL, 1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2099 | if (message == NULL) { |
| 2100 | /* |
| 2101 | * Use default messages. |
| 2102 | */ |
| 2103 | if (node->type == XML_ATTRIBUTE_NODE) { |
| 2104 | xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL, |
| 2105 | "%s, attribute '%s' [%s]: The value '%s' is not " |
| 2106 | "valid.\n", |
| 2107 | BAD_CAST des, xmlSchemaFormatNsPrefixLocal(&strA, node->ns, |
| 2108 | node->name), BAD_CAST typeDes, value, NULL); |
| 2109 | } else { |
| 2110 | xmlSchemaPErr(ctxt, node, error, |
| 2111 | "%s [%s]: The character content is not valid.\n", |
| 2112 | BAD_CAST des, BAD_CAST typeDes); |
| 2113 | } |
| 2114 | } else { |
| 2115 | xmlChar *msg; |
| 2116 | |
| 2117 | msg = xmlStrdup(BAD_CAST "%s"); |
| 2118 | if (node->type == XML_ATTRIBUTE_NODE) |
| 2119 | msg = xmlStrcat(msg, BAD_CAST ", attribute '%s'"); |
| 2120 | msg = xmlStrcat(msg, BAD_CAST " [%s]: "); |
| 2121 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 2122 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 2123 | if (node->type == XML_ATTRIBUTE_NODE) { |
| 2124 | xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL, |
| 2125 | (const char *) msg, |
| 2126 | BAD_CAST des, xmlSchemaFormatNsPrefixLocal(&strA, |
| 2127 | node->ns, node->name), BAD_CAST typeDes, str1, str2); |
| 2128 | } else { |
| 2129 | xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL, |
| 2130 | (const char *) msg, |
| 2131 | BAD_CAST des, BAD_CAST typeDes, str1, str2, NULL); |
| 2132 | } |
| 2133 | xmlFree(msg); |
| 2134 | } |
| 2135 | /* Cleanup. */ |
| 2136 | FREE_AND_NULL(strA) |
| 2137 | FREE_AND_NULL(strT) |
| 2138 | if (ownerDes == NULL) |
| 2139 | FREE_AND_NULL(des) |
| 2140 | } |
| 2141 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2142 | /** |
| 2143 | * xmlSchemaPContentErr: |
| 2144 | * @ctxt: the schema parser context |
| 2145 | * @error: the error code |
| 2146 | * @onwerDes: the designation of the holder of the content |
| 2147 | * @ownerItem: the owner item of the holder of the content |
| 2148 | * @ownerElem: the node of the holder of the content |
| 2149 | * @child: the invalid child node |
| 2150 | * @message: the optional error message |
| 2151 | * @content: the optional string describing the correct content |
| 2152 | * |
| 2153 | * Reports an error concerning the content of a schema element. |
| 2154 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2155 | static void |
| 2156 | xmlSchemaPContentErr(xmlSchemaParserCtxtPtr ctxt, |
| 2157 | xmlParserErrors error, |
| 2158 | xmlChar **ownerDes, |
| 2159 | xmlSchemaTypePtr ownerItem, |
| 2160 | xmlNodePtr ownerElem, |
| 2161 | xmlNodePtr child, |
| 2162 | const char *message, |
| 2163 | const char *content) |
| 2164 | { |
| 2165 | xmlChar *des = NULL; |
| 2166 | |
| 2167 | if (ownerDes == NULL) |
| 2168 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem, 1); |
| 2169 | else if (*ownerDes == NULL) { |
| 2170 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, ownerElem, 1); |
| 2171 | des = *ownerDes; |
| 2172 | } else |
| 2173 | des = *ownerDes; |
| 2174 | if (message != NULL) |
| 2175 | xmlSchemaPErr2(ctxt, ownerElem, child, error, |
| 2176 | "%s: %s.\n", |
| 2177 | BAD_CAST des, BAD_CAST message); |
| 2178 | else { |
| 2179 | if (content != NULL) { |
| 2180 | xmlSchemaPErr2(ctxt, ownerElem, child, error, |
| 2181 | "%s: The content is not valid. Expected is %s.\n", |
| 2182 | BAD_CAST des, BAD_CAST content); |
| 2183 | } else { |
| 2184 | xmlSchemaPErr2(ctxt, ownerElem, child, error, |
| 2185 | "%s: The content is not valid.\n", |
| 2186 | BAD_CAST des, NULL); |
| 2187 | } |
| 2188 | } |
| 2189 | if (ownerDes == NULL) |
| 2190 | FREE_AND_NULL(des) |
| 2191 | } |
| 2192 | |
| 2193 | /** |
| 2194 | * xmlSchemaVIllegalAttrErr: |
| 2195 | * @ctxt: the schema validation context |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2196 | * @error: the error code |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2197 | * @attr: the illegal attribute node |
| 2198 | * |
| 2199 | * Reports an illegal attribute. |
| 2200 | */ |
| 2201 | static void |
| 2202 | xmlSchemaVIllegalAttrErr(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2203 | xmlParserErrors error, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2204 | xmlAttrPtr attr) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2205 | { |
| 2206 | xmlChar *strE = NULL, *strA = NULL; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2207 | |
| 2208 | xmlSchemaVErr(ctxt, (xmlNodePtr) attr, |
| 2209 | error, |
| 2210 | /* XML_SCHEMAS_ERR_ATTRUNKNOWN, */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2211 | "%s: The attribute '%s' is not allowed.\n", |
| 2212 | xmlSchemaFormatItemForReport(&strE, NULL, NULL, attr->parent, 0), |
| 2213 | xmlSchemaFormatNsPrefixLocal(&strA, attr->ns, attr->name)); |
| 2214 | FREE_AND_NULL(strE) |
| 2215 | FREE_AND_NULL(strA) |
| 2216 | } |
| 2217 | |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 2218 | |
| 2219 | static int |
| 2220 | xmlSchemaIsGlobalItem(xmlSchemaTypePtr item) |
| 2221 | { |
| 2222 | switch (item->type) { |
| 2223 | case XML_SCHEMA_TYPE_COMPLEX: |
| 2224 | case XML_SCHEMA_TYPE_SIMPLE: |
| 2225 | case XML_SCHEMA_TYPE_GROUP: |
| 2226 | if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) |
| 2227 | return(1); |
| 2228 | break; |
| 2229 | case XML_SCHEMA_TYPE_ELEMENT: |
| 2230 | if ( ((xmlSchemaElementPtr) item)->flags & |
| 2231 | XML_SCHEMAS_ELEM_GLOBAL) |
| 2232 | return(1); |
| 2233 | break; |
| 2234 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 2235 | if ( ((xmlSchemaAttributePtr) item)->flags & |
| 2236 | XML_SCHEMAS_ATTR_GLOBAL) |
| 2237 | return(1); |
| 2238 | break; |
| 2239 | /* Note that attribute groups are always global. */ |
| 2240 | default: |
| 2241 | return(1); |
| 2242 | } |
| 2243 | return (0); |
| 2244 | } |
| 2245 | |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 2246 | |
| 2247 | static void |
| 2248 | xmlSchemaStreamVCustomErr(xmlSchemaValidCtxtPtr vctxt, |
| 2249 | xmlParserErrors error, |
| 2250 | xmlSchemaNodeInfoPtr nodeInfo, |
| 2251 | xmlSchemaTypePtr type, |
| 2252 | const char *message, |
| 2253 | const xmlChar *str1, |
| 2254 | const xmlChar *str2) |
| 2255 | { |
| 2256 | xmlChar *msg = NULL, *str = NULL; |
| 2257 | |
| 2258 | msg = xmlStrdup(BAD_CAST "Element '"); |
| 2259 | |
| 2260 | if (vctxt->elemInfos[vctxt->depth] != nodeInfo) { |
| 2261 | xmlSchemaNodeInfoPtr elemInfo; |
| 2262 | /* |
| 2263 | * The node info is an attribute info. |
| 2264 | */ |
| 2265 | elemInfo = vctxt->elemInfos[vctxt->depth]; |
| 2266 | msg = xmlStrcat(msg, xmlSchemaFormatQName(&str, |
| 2267 | elemInfo->namespaceName, elemInfo->localName)); |
| 2268 | msg = xmlStrcat(msg, BAD_CAST "', "); |
| 2269 | msg = xmlStrcat(msg, BAD_CAST "attribute '"); |
| 2270 | } |
| 2271 | msg = xmlStrcat(msg, xmlSchemaFormatQName(&str, |
| 2272 | nodeInfo->namespaceName, nodeInfo->localName)); |
| 2273 | msg = xmlStrcat(msg, BAD_CAST "'"); |
| 2274 | |
| 2275 | if ((type != NULL) && (xmlSchemaIsGlobalItem(type))) { |
| 2276 | msg = xmlStrcat(msg, BAD_CAST " ["); |
| 2277 | msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, |
| 2278 | NULL, type, NULL, 0)); |
| 2279 | msg = xmlStrcat(msg, BAD_CAST "]"); |
| 2280 | } |
| 2281 | msg = xmlStrcat(msg, BAD_CAST ": "); |
| 2282 | |
| 2283 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 2284 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 2285 | xmlSchemaVErr(vctxt, nodeInfo->node, error, (const char *) msg, |
| 2286 | str1, str2); |
| 2287 | FREE_AND_NULL(msg) |
| 2288 | FREE_AND_NULL(str) |
| 2289 | } |
| 2290 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2291 | /** |
| 2292 | * xmlSchemaVCustomErr: |
| 2293 | * @ctxt: the schema validation context |
| 2294 | * @error: the error code |
| 2295 | * @node: the validated node |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2296 | * @type: the schema type of the validated node |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2297 | * @message: the error message |
| 2298 | * @str1: the optional param for the message |
| 2299 | * |
| 2300 | * Reports a validation error. |
| 2301 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2302 | static void |
| 2303 | xmlSchemaVCustomErr(xmlSchemaValidCtxtPtr ctxt, |
| 2304 | xmlParserErrors error, |
| 2305 | xmlNodePtr node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2306 | xmlSchemaTypePtr type, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2307 | const char *message, |
| 2308 | const xmlChar *str1) |
| 2309 | { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2310 | xmlChar *msg = NULL, *str = NULL; |
| 2311 | |
| 2312 | if (node == NULL) { |
| 2313 | xmlSchemaVErr(ctxt, NULL, |
| 2314 | XML_SCHEMAV_INTERNAL, |
| 2315 | "Internal error: xmlSchemaVCustomErr, no node " |
| 2316 | "given.\n", NULL, NULL); |
| 2317 | return; |
| 2318 | } |
| 2319 | /* TODO: Are the HTML and DOCB doc nodes expected here? */ |
| 2320 | if (node->type != XML_DOCUMENT_NODE) { |
| 2321 | xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 2322 | if ((type != NULL) && (xmlSchemaIsGlobalItem(type))) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2323 | msg = xmlStrcat(msg, BAD_CAST " ["); |
| 2324 | msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); |
| 2325 | msg = xmlStrcat(msg, BAD_CAST "]"); |
| 2326 | } |
| 2327 | msg = xmlStrcat(msg, BAD_CAST ": "); |
| 2328 | } else |
| 2329 | msg = xmlStrdup((const xmlChar *) ""); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2330 | msg = xmlStrcat(msg, (const xmlChar *) message); |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2331 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 2332 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, str1, NULL); |
| 2333 | FREE_AND_NULL(msg) |
| 2334 | FREE_AND_NULL(str) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2335 | } |
| 2336 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2337 | /** |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2338 | * xmlSchemaVWildcardErr: |
| 2339 | * @ctxt: the schema validation context |
| 2340 | * @error: the error code |
| 2341 | * @node: the validated node |
| 2342 | * @wild: the wildcard used |
| 2343 | * @message: the error message |
| 2344 | * |
| 2345 | * Reports an validation-by-wildcard error. |
| 2346 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2347 | static void |
| 2348 | xmlSchemaVWildcardErr(xmlSchemaValidCtxtPtr ctxt, |
| 2349 | xmlParserErrors error, |
| 2350 | xmlNodePtr node, |
| 2351 | xmlSchemaWildcardPtr wild, |
| 2352 | const char *message) |
| 2353 | { |
| 2354 | xmlChar *des = NULL, *msg = NULL; |
| 2355 | |
| 2356 | xmlSchemaFormatItemForReport(&des, NULL, NULL, node, 0); |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 2357 | msg = xmlStrdup(BAD_CAST "%s ["); |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 2358 | msg = xmlStrcat(msg, xmlSchemaWildcardPCToString(wild->processContents)); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 2359 | msg = xmlStrcat(msg, BAD_CAST " wildcard]: "); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2360 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 2361 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 2362 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, BAD_CAST des, NULL); |
| 2363 | FREE_AND_NULL(des); |
| 2364 | FREE_AND_NULL(msg); |
| 2365 | } |
| 2366 | |
| 2367 | /** |
| 2368 | * xmlSchemaVMissingAttrErr: |
| 2369 | * @ctxt: the schema validation context |
| 2370 | * @node: the parent element node of the missing attribute node |
| 2371 | * @type: the corresponding type of the attribute node |
| 2372 | * |
| 2373 | * Reports an illegal attribute. |
| 2374 | */ |
| 2375 | static void |
| 2376 | xmlSchemaVMissingAttrErr(xmlSchemaValidCtxtPtr ctxt, |
| 2377 | xmlNodePtr elem, |
| 2378 | xmlSchemaAttributePtr type) |
| 2379 | { |
| 2380 | const xmlChar *name, *uri; |
| 2381 | xmlChar *strE = NULL, *strA = NULL; |
| 2382 | |
| 2383 | if (type->ref != NULL) { |
| 2384 | name = type->ref; |
| 2385 | uri = type->refNs; |
| 2386 | } else { |
| 2387 | name = type->name; |
| 2388 | uri = type->targetNamespace; |
| 2389 | } |
| 2390 | xmlSchemaVErr(ctxt, elem, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2391 | XML_SCHEMAV_CVC_COMPLEX_TYPE_4, |
| 2392 | /* XML_SCHEMAS_ERR_MISSING, */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2393 | "%s: The attribute %s is required but missing.\n", |
| 2394 | xmlSchemaFormatItemForReport(&strE, NULL, NULL, elem, 0), |
| 2395 | xmlSchemaFormatNsUriLocal(&strA, uri, name)); |
| 2396 | FREE_AND_NULL(strE) |
| 2397 | FREE_AND_NULL(strA) |
| 2398 | } |
| 2399 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2400 | /************************************************************************ |
| 2401 | * * |
| 2402 | * Allocation functions * |
| 2403 | * * |
| 2404 | ************************************************************************/ |
| 2405 | |
| 2406 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 2407 | * xmlSchemaNewSchemaForParserCtxt: |
William M. Brack | 0817191 | 2003-12-29 02:52:11 +0000 | [diff] [blame] | 2408 | * @ctxt: a schema validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2409 | * |
| 2410 | * Allocate a new Schema structure. |
| 2411 | * |
| 2412 | * Returns the newly allocated structure or NULL in case or error |
| 2413 | */ |
| 2414 | static xmlSchemaPtr |
| 2415 | xmlSchemaNewSchema(xmlSchemaParserCtxtPtr ctxt) |
| 2416 | { |
| 2417 | xmlSchemaPtr ret; |
| 2418 | |
| 2419 | ret = (xmlSchemaPtr) xmlMalloc(sizeof(xmlSchema)); |
| 2420 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2421 | xmlSchemaPErrMemory(ctxt, "allocating schema", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2422 | return (NULL); |
| 2423 | } |
| 2424 | memset(ret, 0, sizeof(xmlSchema)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2425 | ret->dict = ctxt->dict; |
Daniel Veillard | 500a1de | 2004-03-22 15:22:58 +0000 | [diff] [blame] | 2426 | xmlDictReference(ret->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2427 | |
| 2428 | return (ret); |
| 2429 | } |
| 2430 | |
| 2431 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 2432 | * xmlSchemaNewSchema: |
| 2433 | * @ctxt: a schema validation context |
| 2434 | * |
| 2435 | * Allocate a new Schema structure. |
| 2436 | * |
| 2437 | * Returns the newly allocated structure or NULL in case or error |
| 2438 | */ |
| 2439 | static xmlSchemaAssemblePtr |
| 2440 | xmlSchemaNewAssemble(void) |
| 2441 | { |
| 2442 | xmlSchemaAssemblePtr ret; |
| 2443 | |
| 2444 | ret = (xmlSchemaAssemblePtr) xmlMalloc(sizeof(xmlSchemaAssemble)); |
| 2445 | if (ret == NULL) { |
| 2446 | /* xmlSchemaPErrMemory(ctxt, "allocating assemble info", NULL); */ |
| 2447 | return (NULL); |
| 2448 | } |
| 2449 | memset(ret, 0, sizeof(xmlSchemaAssemble)); |
| 2450 | ret->items = NULL; |
| 2451 | return (ret); |
| 2452 | } |
| 2453 | |
| 2454 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2455 | * xmlSchemaNewFacet: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2456 | * |
| 2457 | * Allocate a new Facet structure. |
| 2458 | * |
| 2459 | * Returns the newly allocated structure or NULL in case or error |
| 2460 | */ |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 2461 | xmlSchemaFacetPtr |
| 2462 | xmlSchemaNewFacet(void) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2463 | { |
| 2464 | xmlSchemaFacetPtr ret; |
| 2465 | |
| 2466 | ret = (xmlSchemaFacetPtr) xmlMalloc(sizeof(xmlSchemaFacet)); |
| 2467 | if (ret == NULL) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2468 | return (NULL); |
| 2469 | } |
| 2470 | memset(ret, 0, sizeof(xmlSchemaFacet)); |
| 2471 | |
| 2472 | return (ret); |
| 2473 | } |
| 2474 | |
| 2475 | /** |
| 2476 | * xmlSchemaNewAnnot: |
William M. Brack | 0817191 | 2003-12-29 02:52:11 +0000 | [diff] [blame] | 2477 | * @ctxt: a schema validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2478 | * @node: a node |
| 2479 | * |
| 2480 | * Allocate a new annotation structure. |
| 2481 | * |
| 2482 | * Returns the newly allocated structure or NULL in case or error |
| 2483 | */ |
| 2484 | static xmlSchemaAnnotPtr |
| 2485 | xmlSchemaNewAnnot(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node) |
| 2486 | { |
| 2487 | xmlSchemaAnnotPtr ret; |
| 2488 | |
| 2489 | ret = (xmlSchemaAnnotPtr) xmlMalloc(sizeof(xmlSchemaAnnot)); |
| 2490 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2491 | xmlSchemaPErrMemory(ctxt, "allocating annotation", node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2492 | return (NULL); |
| 2493 | } |
| 2494 | memset(ret, 0, sizeof(xmlSchemaAnnot)); |
| 2495 | ret->content = node; |
| 2496 | return (ret); |
| 2497 | } |
| 2498 | |
| 2499 | /** |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 2500 | * xmlSchemaFreeAnnot: |
| 2501 | * @annot: a schema type structure |
| 2502 | * |
| 2503 | * Deallocate a annotation structure |
| 2504 | */ |
| 2505 | static void |
| 2506 | xmlSchemaFreeAnnot(xmlSchemaAnnotPtr annot) |
| 2507 | { |
| 2508 | if (annot == NULL) |
| 2509 | return; |
| 2510 | xmlFree(annot); |
| 2511 | } |
| 2512 | |
| 2513 | /** |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 2514 | * xmlSchemaFreeImport: |
| 2515 | * @import: a schema import structure |
| 2516 | * |
| 2517 | * Deallocate an import structure |
| 2518 | */ |
| 2519 | static void |
| 2520 | xmlSchemaFreeImport(xmlSchemaImportPtr import) |
| 2521 | { |
| 2522 | if (import == NULL) |
| 2523 | return; |
| 2524 | |
| 2525 | xmlSchemaFree(import->schema); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2526 | xmlFreeDoc(import->doc); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 2527 | xmlFree(import); |
| 2528 | } |
| 2529 | |
| 2530 | /** |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 2531 | * xmlSchemaFreeInclude: |
| 2532 | * @include: a schema include structure |
| 2533 | * |
| 2534 | * Deallocate an include structure |
| 2535 | */ |
| 2536 | static void |
| 2537 | xmlSchemaFreeInclude(xmlSchemaIncludePtr include) |
| 2538 | { |
| 2539 | if (include == NULL) |
| 2540 | return; |
| 2541 | |
| 2542 | xmlFreeDoc(include->doc); |
| 2543 | xmlFree(include); |
| 2544 | } |
| 2545 | |
| 2546 | /** |
| 2547 | * xmlSchemaFreeIncludeList: |
| 2548 | * @includes: a schema include list |
| 2549 | * |
| 2550 | * Deallocate an include structure |
| 2551 | */ |
| 2552 | static void |
| 2553 | xmlSchemaFreeIncludeList(xmlSchemaIncludePtr includes) |
| 2554 | { |
| 2555 | xmlSchemaIncludePtr next; |
| 2556 | |
| 2557 | while (includes != NULL) { |
| 2558 | next = includes->next; |
| 2559 | xmlSchemaFreeInclude(includes); |
| 2560 | includes = next; |
| 2561 | } |
| 2562 | } |
| 2563 | |
| 2564 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2565 | * xmlSchemaFreeNotation: |
| 2566 | * @schema: a schema notation structure |
| 2567 | * |
| 2568 | * Deallocate a Schema Notation structure. |
| 2569 | */ |
| 2570 | static void |
| 2571 | xmlSchemaFreeNotation(xmlSchemaNotationPtr nota) |
| 2572 | { |
| 2573 | if (nota == NULL) |
| 2574 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2575 | xmlFree(nota); |
| 2576 | } |
| 2577 | |
| 2578 | /** |
| 2579 | * xmlSchemaFreeAttribute: |
| 2580 | * @schema: a schema attribute structure |
| 2581 | * |
| 2582 | * Deallocate a Schema Attribute structure. |
| 2583 | */ |
| 2584 | static void |
| 2585 | xmlSchemaFreeAttribute(xmlSchemaAttributePtr attr) |
| 2586 | { |
| 2587 | if (attr == NULL) |
| 2588 | return; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2589 | if (attr->annot != NULL) |
| 2590 | xmlSchemaFreeAnnot(attr->annot); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 2591 | if (attr->defVal != NULL) |
| 2592 | xmlSchemaFreeValue(attr->defVal); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2593 | xmlFree(attr); |
| 2594 | } |
| 2595 | |
| 2596 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2597 | * xmlSchemaFreeWildcardNsSet: |
| 2598 | * set: a schema wildcard namespace |
| 2599 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2600 | * Deallocates a list of wildcard constraint structures. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2601 | */ |
| 2602 | static void |
| 2603 | xmlSchemaFreeWildcardNsSet(xmlSchemaWildcardNsPtr set) |
| 2604 | { |
| 2605 | xmlSchemaWildcardNsPtr next; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2606 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2607 | while (set != NULL) { |
| 2608 | next = set->next; |
| 2609 | xmlFree(set); |
| 2610 | set = next; |
| 2611 | } |
| 2612 | } |
| 2613 | |
| 2614 | /** |
| 2615 | * xmlSchemaFreeWildcard: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2616 | * @wildcard: a wildcard structure |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2617 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2618 | * Deallocates a wildcard structure. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2619 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2620 | void |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2621 | xmlSchemaFreeWildcard(xmlSchemaWildcardPtr wildcard) |
| 2622 | { |
| 2623 | if (wildcard == NULL) |
| 2624 | return; |
| 2625 | if (wildcard->annot != NULL) |
| 2626 | xmlSchemaFreeAnnot(wildcard->annot); |
| 2627 | if (wildcard->nsSet != NULL) |
| 2628 | xmlSchemaFreeWildcardNsSet(wildcard->nsSet); |
| 2629 | if (wildcard->negNsSet != NULL) |
| 2630 | xmlFree(wildcard->negNsSet); |
| 2631 | xmlFree(wildcard); |
| 2632 | } |
| 2633 | |
| 2634 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2635 | * xmlSchemaFreeAttributeGroup: |
| 2636 | * @schema: a schema attribute group structure |
| 2637 | * |
| 2638 | * Deallocate a Schema Attribute Group structure. |
| 2639 | */ |
| 2640 | static void |
| 2641 | xmlSchemaFreeAttributeGroup(xmlSchemaAttributeGroupPtr attr) |
| 2642 | { |
| 2643 | if (attr == NULL) |
| 2644 | return; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2645 | if (attr->annot != NULL) |
| 2646 | xmlSchemaFreeAnnot(attr->annot); |
| 2647 | if ((attr->flags & XML_SCHEMAS_ATTRGROUP_GLOBAL) && |
| 2648 | (attr->attributeWildcard != NULL)) |
| 2649 | xmlSchemaFreeWildcard(attr->attributeWildcard); |
| 2650 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2651 | xmlFree(attr); |
| 2652 | } |
| 2653 | |
| 2654 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2655 | * xmlSchemaFreeAttributeUseList: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2656 | * @attrUse: an attribute link |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2657 | * |
| 2658 | * Deallocate a list of schema attribute uses. |
| 2659 | */ |
| 2660 | static void |
| 2661 | xmlSchemaFreeAttributeUseList(xmlSchemaAttributeLinkPtr attrUse) |
| 2662 | { |
| 2663 | xmlSchemaAttributeLinkPtr next; |
| 2664 | |
| 2665 | while (attrUse != NULL) { |
| 2666 | next = attrUse->next; |
| 2667 | xmlFree(attrUse); |
| 2668 | attrUse = next; |
| 2669 | } |
| 2670 | } |
| 2671 | |
| 2672 | /** |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2673 | * xmlSchemaFreeTypeLinkList: |
| 2674 | * @alink: a type link |
| 2675 | * |
| 2676 | * Deallocate a list of types. |
| 2677 | */ |
| 2678 | static void |
| 2679 | xmlSchemaFreeTypeLinkList(xmlSchemaTypeLinkPtr link) |
| 2680 | { |
| 2681 | xmlSchemaTypeLinkPtr next; |
| 2682 | |
| 2683 | while (link != NULL) { |
| 2684 | next = link->next; |
| 2685 | xmlFree(link); |
| 2686 | link = next; |
| 2687 | } |
| 2688 | } |
| 2689 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 2690 | #ifdef IDC_ENABLED |
| 2691 | static void |
| 2692 | xmlSchemaFreeIDCStateObjList(xmlSchemaIDCStateObjPtr sto) |
| 2693 | { |
| 2694 | xmlSchemaIDCStateObjPtr next; |
| 2695 | while (sto != NULL) { |
| 2696 | next = sto->next; |
| 2697 | if (sto->history != NULL) |
| 2698 | xmlFree(sto->history); |
| 2699 | if (sto->xpathCtxt != NULL) |
| 2700 | xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt); |
| 2701 | xmlFree(sto); |
| 2702 | sto = next; |
| 2703 | } |
| 2704 | } |
| 2705 | |
| 2706 | /** |
| 2707 | * xmlSchemaFreeIDC: |
| 2708 | * @idc: a identity-constraint definition |
| 2709 | * |
| 2710 | * Deallocates an identity-constraint definition. |
| 2711 | */ |
| 2712 | static void |
| 2713 | xmlSchemaFreeIDC(xmlSchemaIDCPtr idcDef) |
| 2714 | { |
| 2715 | xmlSchemaIDCSelectPtr cur, prev; |
| 2716 | |
| 2717 | if (idcDef == NULL) |
| 2718 | return; |
| 2719 | if (idcDef->annot != NULL) |
| 2720 | xmlSchemaFreeAnnot(idcDef->annot); |
| 2721 | if (idcDef->ref != NULL) |
| 2722 | xmlFree(idcDef->ref); |
| 2723 | /* Selector */ |
| 2724 | if (idcDef->selector != NULL) { |
| 2725 | if (idcDef->selector->xpathComp != NULL) |
| 2726 | xmlFreePattern((xmlPatternPtr) idcDef->selector->xpathComp); |
| 2727 | xmlFree(idcDef->selector); |
| 2728 | } |
| 2729 | /* Fields */ |
| 2730 | if (idcDef->fields != NULL) { |
| 2731 | cur = idcDef->fields; |
| 2732 | do { |
| 2733 | prev = cur; |
| 2734 | cur = cur->next; |
| 2735 | if (prev->xpathComp != NULL) |
| 2736 | xmlFreePattern((xmlPatternPtr) prev->xpathComp); |
| 2737 | xmlFree(prev); |
| 2738 | } while (cur != NULL); |
| 2739 | } |
| 2740 | xmlFree(idcDef); |
| 2741 | } |
| 2742 | #endif /* IDC_ENABLED */ |
| 2743 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2744 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2745 | * xmlSchemaFreeElement: |
| 2746 | * @schema: a schema element structure |
| 2747 | * |
| 2748 | * Deallocate a Schema Element structure. |
| 2749 | */ |
| 2750 | static void |
| 2751 | xmlSchemaFreeElement(xmlSchemaElementPtr elem) |
| 2752 | { |
| 2753 | if (elem == NULL) |
| 2754 | return; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 2755 | if (elem->annot != NULL) |
| 2756 | xmlSchemaFreeAnnot(elem->annot); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2757 | if (elem->contModel != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2758 | xmlRegFreeRegexp(elem->contModel); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 2759 | if (elem->defVal != NULL) |
| 2760 | xmlSchemaFreeValue(elem->defVal); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2761 | xmlFree(elem); |
| 2762 | } |
| 2763 | |
| 2764 | /** |
| 2765 | * xmlSchemaFreeFacet: |
| 2766 | * @facet: a schema facet structure |
| 2767 | * |
| 2768 | * Deallocate a Schema Facet structure. |
| 2769 | */ |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 2770 | void |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2771 | xmlSchemaFreeFacet(xmlSchemaFacetPtr facet) |
| 2772 | { |
| 2773 | if (facet == NULL) |
| 2774 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2775 | if (facet->val != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2776 | xmlSchemaFreeValue(facet->val); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2777 | if (facet->regexp != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2778 | xmlRegFreeRegexp(facet->regexp); |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 2779 | if (facet->annot != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2780 | xmlSchemaFreeAnnot(facet->annot); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2781 | xmlFree(facet); |
| 2782 | } |
| 2783 | |
| 2784 | /** |
| 2785 | * xmlSchemaFreeType: |
| 2786 | * @type: a schema type structure |
| 2787 | * |
| 2788 | * Deallocate a Schema Type structure. |
| 2789 | */ |
| 2790 | void |
| 2791 | xmlSchemaFreeType(xmlSchemaTypePtr type) |
| 2792 | { |
| 2793 | if (type == NULL) |
| 2794 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2795 | if (type->annot != NULL) |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 2796 | xmlSchemaFreeAnnot(type->annot); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2797 | if (type->facets != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2798 | xmlSchemaFacetPtr facet, next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2799 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2800 | facet = type->facets; |
| 2801 | while (facet != NULL) { |
| 2802 | next = facet->next; |
| 2803 | xmlSchemaFreeFacet(facet); |
| 2804 | facet = next; |
| 2805 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2806 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2807 | if (type->type != XML_SCHEMA_TYPE_BASIC) { |
| 2808 | if (type->attributeUses != NULL) |
| 2809 | xmlSchemaFreeAttributeUseList(type->attributeUses); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 2810 | if ((type->attributeWildcard != NULL) && |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2811 | ((type->type != XML_SCHEMA_TYPE_COMPLEX) || |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 2812 | (type->flags & XML_SCHEMAS_TYPE_OWNED_ATTR_WILDCARD))) { |
| 2813 | /* |
| 2814 | * NOTE: The only case where an attribute wildcard |
| 2815 | * is not owned, is if a complex type inherits it |
| 2816 | * from a base type. |
| 2817 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2818 | xmlSchemaFreeWildcard(type->attributeWildcard); |
| 2819 | } |
| 2820 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2821 | if (type->memberTypes != NULL) |
| 2822 | xmlSchemaFreeTypeLinkList(type->memberTypes); |
| 2823 | if (type->facetSet != NULL) { |
| 2824 | xmlSchemaFacetLinkPtr next, link; |
| 2825 | |
| 2826 | link = type->facetSet; |
| 2827 | do { |
| 2828 | next = link->next; |
| 2829 | xmlFree(link); |
| 2830 | link = next; |
| 2831 | } while (link != NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 2832 | } |
| 2833 | if (type->contModel != NULL) |
| 2834 | xmlRegFreeRegexp(type->contModel); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2835 | xmlFree(type); |
| 2836 | } |
| 2837 | |
| 2838 | /** |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 2839 | * xmlSchemaFreeTypeList: |
| 2840 | * @type: a schema type structure |
| 2841 | * |
| 2842 | * Deallocate a Schema Type structure. |
| 2843 | */ |
| 2844 | static void |
| 2845 | xmlSchemaFreeTypeList(xmlSchemaTypePtr type) |
| 2846 | { |
| 2847 | xmlSchemaTypePtr next; |
| 2848 | |
| 2849 | while (type != NULL) { |
| 2850 | next = type->redef; |
| 2851 | xmlSchemaFreeType(type); |
| 2852 | type = next; |
| 2853 | } |
| 2854 | } |
| 2855 | |
| 2856 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2857 | * xmlSchemaFree: |
| 2858 | * @schema: a schema structure |
| 2859 | * |
| 2860 | * Deallocate a Schema structure. |
| 2861 | */ |
| 2862 | void |
| 2863 | xmlSchemaFree(xmlSchemaPtr schema) |
| 2864 | { |
| 2865 | if (schema == NULL) |
| 2866 | return; |
| 2867 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2868 | if (schema->notaDecl != NULL) |
| 2869 | xmlHashFree(schema->notaDecl, |
| 2870 | (xmlHashDeallocator) xmlSchemaFreeNotation); |
| 2871 | if (schema->attrDecl != NULL) |
| 2872 | xmlHashFree(schema->attrDecl, |
| 2873 | (xmlHashDeallocator) xmlSchemaFreeAttribute); |
| 2874 | if (schema->attrgrpDecl != NULL) |
| 2875 | xmlHashFree(schema->attrgrpDecl, |
| 2876 | (xmlHashDeallocator) xmlSchemaFreeAttributeGroup); |
| 2877 | if (schema->elemDecl != NULL) |
| 2878 | xmlHashFree(schema->elemDecl, |
| 2879 | (xmlHashDeallocator) xmlSchemaFreeElement); |
| 2880 | if (schema->typeDecl != NULL) |
| 2881 | xmlHashFree(schema->typeDecl, |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 2882 | (xmlHashDeallocator) xmlSchemaFreeTypeList); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 2883 | if (schema->groupDecl != NULL) |
| 2884 | xmlHashFree(schema->groupDecl, |
| 2885 | (xmlHashDeallocator) xmlSchemaFreeType); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 2886 | #ifdef IDC_ENABLED |
| 2887 | if (schema->idcDef != NULL) |
| 2888 | xmlHashFree(schema->idcDef, |
| 2889 | (xmlHashDeallocator) xmlSchemaFreeIDC); |
| 2890 | #endif |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 2891 | if (schema->schemasImports != NULL) |
| 2892 | xmlHashFree(schema->schemasImports, |
| 2893 | (xmlHashDeallocator) xmlSchemaFreeImport); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 2894 | if (schema->includes != NULL) { |
| 2895 | xmlSchemaFreeIncludeList((xmlSchemaIncludePtr) schema->includes); |
| 2896 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2897 | if (schema->annot != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2898 | xmlSchemaFreeAnnot(schema->annot); |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 2899 | if (schema->doc != NULL && !schema->preserve) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2900 | xmlFreeDoc(schema->doc); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 2901 | xmlDictFree(schema->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2902 | xmlFree(schema); |
| 2903 | } |
| 2904 | |
| 2905 | /************************************************************************ |
| 2906 | * * |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2907 | * Debug functions * |
| 2908 | * * |
| 2909 | ************************************************************************/ |
| 2910 | |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2911 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2912 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2913 | /** |
| 2914 | * xmlSchemaElementDump: |
| 2915 | * @elem: an element |
| 2916 | * @output: the file output |
| 2917 | * |
| 2918 | * Dump the element |
| 2919 | */ |
| 2920 | static void |
| 2921 | xmlSchemaElementDump(xmlSchemaElementPtr elem, FILE * output, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2922 | const xmlChar * name ATTRIBUTE_UNUSED, |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2923 | const xmlChar * namespace ATTRIBUTE_UNUSED, |
| 2924 | const xmlChar * context ATTRIBUTE_UNUSED) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2925 | { |
| 2926 | if (elem == NULL) |
| 2927 | return; |
| 2928 | |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2929 | if (elem->flags & XML_SCHEMAS_ELEM_REF) { |
| 2930 | fprintf(output, "Particle: %s", name); |
| 2931 | fprintf(output, ", term element: %s", elem->ref); |
| 2932 | if (elem->refNs != NULL) |
| 2933 | fprintf(output, " ns %s", elem->refNs); |
| 2934 | } else { |
| 2935 | fprintf(output, "Element"); |
| 2936 | if (elem->flags & XML_SCHEMAS_ELEM_GLOBAL) |
| 2937 | fprintf(output, " (global)"); |
| 2938 | fprintf(output, ": %s ", elem->name); |
| 2939 | if (namespace != NULL) |
| 2940 | fprintf(output, "ns %s", namespace); |
| 2941 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2942 | fprintf(output, "\n"); |
| 2943 | if ((elem->minOccurs != 1) || (elem->maxOccurs != 1)) { |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2944 | fprintf(output, " min %d ", elem->minOccurs); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2945 | if (elem->maxOccurs >= UNBOUNDED) |
| 2946 | fprintf(output, "max: unbounded\n"); |
| 2947 | else if (elem->maxOccurs != 1) |
| 2948 | fprintf(output, "max: %d\n", elem->maxOccurs); |
| 2949 | else |
| 2950 | fprintf(output, "\n"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2951 | } |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2952 | /* |
| 2953 | * Misc other properties. |
| 2954 | */ |
| 2955 | if ((elem->flags & XML_SCHEMAS_ELEM_NILLABLE) || |
| 2956 | (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT) || |
| 2957 | (elem->flags & XML_SCHEMAS_ELEM_FIXED) || |
| 2958 | (elem->flags & XML_SCHEMAS_ELEM_DEFAULT) || |
| 2959 | (elem->id != NULL)) { |
| 2960 | fprintf(output, " props: "); |
| 2961 | if (elem->flags & XML_SCHEMAS_ELEM_FIXED) |
| 2962 | fprintf(output, "[fixed] "); |
| 2963 | if (elem->flags & XML_SCHEMAS_ELEM_DEFAULT) |
| 2964 | fprintf(output, "[default] "); |
| 2965 | if (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT) |
| 2966 | fprintf(output, "[abstract] "); |
| 2967 | if (elem->flags & XML_SCHEMAS_ELEM_NILLABLE) |
| 2968 | fprintf(output, "[nillable] "); |
| 2969 | if (elem->id != NULL) |
| 2970 | fprintf(output, "[id: '%s'] ", elem->id); |
| 2971 | fprintf(output, "\n"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2972 | } |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2973 | /* |
| 2974 | * Default/fixed value. |
| 2975 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2976 | if (elem->value != NULL) |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2977 | fprintf(output, " value: '%s'\n", elem->value); |
| 2978 | /* |
| 2979 | * Type. |
| 2980 | */ |
| 2981 | if (elem->namedType != NULL) { |
| 2982 | fprintf(output, " type: %s ", elem->namedType); |
| 2983 | if (elem->namedTypeNs != NULL) |
| 2984 | fprintf(output, "ns %s\n", elem->namedTypeNs); |
| 2985 | else |
| 2986 | fprintf(output, "\n"); |
| 2987 | } |
| 2988 | /* |
| 2989 | * Substitution group. |
| 2990 | */ |
| 2991 | if (elem->substGroup != NULL) { |
| 2992 | fprintf(output, " substitutionGroup: %s ", elem->substGroup); |
| 2993 | if (elem->substGroupNs != NULL) |
| 2994 | fprintf(output, "ns %s\n", elem->substGroupNs); |
| 2995 | else |
| 2996 | fprintf(output, "\n"); |
| 2997 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | /** |
| 3001 | * xmlSchemaAnnotDump: |
| 3002 | * @output: the file output |
| 3003 | * @annot: a annotation |
| 3004 | * |
| 3005 | * Dump the annotation |
| 3006 | */ |
| 3007 | static void |
| 3008 | xmlSchemaAnnotDump(FILE * output, xmlSchemaAnnotPtr annot) |
| 3009 | { |
| 3010 | xmlChar *content; |
| 3011 | |
| 3012 | if (annot == NULL) |
| 3013 | return; |
| 3014 | |
| 3015 | content = xmlNodeGetContent(annot->content); |
| 3016 | if (content != NULL) { |
| 3017 | fprintf(output, " Annot: %s\n", content); |
| 3018 | xmlFree(content); |
| 3019 | } else |
| 3020 | fprintf(output, " Annot: empty\n"); |
| 3021 | } |
| 3022 | |
| 3023 | /** |
| 3024 | * xmlSchemaTypeDump: |
| 3025 | * @output: the file output |
| 3026 | * @type: a type structure |
| 3027 | * |
| 3028 | * Dump a SchemaType structure |
| 3029 | */ |
| 3030 | static void |
| 3031 | xmlSchemaTypeDump(xmlSchemaTypePtr type, FILE * output) |
| 3032 | { |
| 3033 | if (type == NULL) { |
| 3034 | fprintf(output, "Type: NULL\n"); |
| 3035 | return; |
| 3036 | } |
| 3037 | fprintf(output, "Type: "); |
| 3038 | if (type->name != NULL) |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3039 | fprintf(output, "%s ", type->name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3040 | else |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3041 | fprintf(output, "no name "); |
| 3042 | if (type->targetNamespace != NULL) |
| 3043 | fprintf(output, "ns %s ", type->targetNamespace); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3044 | switch (type->type) { |
| 3045 | case XML_SCHEMA_TYPE_BASIC: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3046 | fprintf(output, "[basic] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3047 | break; |
| 3048 | case XML_SCHEMA_TYPE_SIMPLE: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3049 | fprintf(output, "[simple] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3050 | break; |
| 3051 | case XML_SCHEMA_TYPE_COMPLEX: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3052 | fprintf(output, "[complex] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3053 | break; |
| 3054 | case XML_SCHEMA_TYPE_SEQUENCE: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3055 | fprintf(output, "[sequence] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3056 | break; |
| 3057 | case XML_SCHEMA_TYPE_CHOICE: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3058 | fprintf(output, "[choice] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3059 | break; |
| 3060 | case XML_SCHEMA_TYPE_ALL: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3061 | fprintf(output, "[all] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3062 | break; |
| 3063 | case XML_SCHEMA_TYPE_UR: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3064 | fprintf(output, "[ur] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3065 | break; |
| 3066 | case XML_SCHEMA_TYPE_RESTRICTION: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3067 | fprintf(output, "[restriction] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3068 | break; |
| 3069 | case XML_SCHEMA_TYPE_EXTENSION: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3070 | fprintf(output, "[extension] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3071 | break; |
| 3072 | default: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3073 | fprintf(output, "[unknown type %d] ", type->type); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3074 | break; |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3075 | } |
| 3076 | fprintf(output, "content: "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3077 | switch (type->contentType) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3078 | case XML_SCHEMA_CONTENT_UNKNOWN: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3079 | fprintf(output, "[unknown] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3080 | break; |
| 3081 | case XML_SCHEMA_CONTENT_EMPTY: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3082 | fprintf(output, "[empty] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3083 | break; |
| 3084 | case XML_SCHEMA_CONTENT_ELEMENTS: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3085 | fprintf(output, "[element] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3086 | break; |
| 3087 | case XML_SCHEMA_CONTENT_MIXED: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3088 | fprintf(output, "[mixed] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3089 | break; |
| 3090 | case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS: |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 3091 | /* not used. */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3092 | break; |
| 3093 | case XML_SCHEMA_CONTENT_BASIC: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3094 | fprintf(output, "[basic] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3095 | break; |
| 3096 | case XML_SCHEMA_CONTENT_SIMPLE: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3097 | fprintf(output, "[simple] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3098 | break; |
| 3099 | case XML_SCHEMA_CONTENT_ANY: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3100 | fprintf(output, "[any] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3101 | break; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3102 | } |
| 3103 | fprintf(output, "\n"); |
| 3104 | if ((type->minOccurs != 1) || (type->maxOccurs != 1)) { |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3105 | fprintf(output, " min: %d ", type->minOccurs); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3106 | if (type->maxOccurs >= UNBOUNDED) |
| 3107 | fprintf(output, "max: unbounded\n"); |
| 3108 | else if (type->maxOccurs != 1) |
| 3109 | fprintf(output, "max: %d\n", type->maxOccurs); |
| 3110 | else |
| 3111 | fprintf(output, "\n"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3112 | } |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 3113 | if (type->base != NULL) { |
| 3114 | fprintf(output, " base type: %s", type->base); |
| 3115 | if (type->baseNs != NULL) |
| 3116 | fprintf(output, " ns %s\n", type->baseNs); |
| 3117 | else |
| 3118 | fprintf(output, "\n"); |
| 3119 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3120 | if (type->annot != NULL) |
| 3121 | xmlSchemaAnnotDump(output, type->annot); |
| 3122 | if (type->subtypes != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3123 | xmlSchemaTypePtr sub = type->subtypes; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3124 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3125 | fprintf(output, " subtypes: "); |
| 3126 | while (sub != NULL) { |
| 3127 | fprintf(output, "%s ", sub->name); |
| 3128 | sub = sub->next; |
| 3129 | } |
| 3130 | fprintf(output, "\n"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3131 | } |
| 3132 | |
| 3133 | } |
| 3134 | |
| 3135 | /** |
| 3136 | * xmlSchemaDump: |
| 3137 | * @output: the file output |
| 3138 | * @schema: a schema structure |
| 3139 | * |
| 3140 | * Dump a Schema structure. |
| 3141 | */ |
| 3142 | void |
| 3143 | xmlSchemaDump(FILE * output, xmlSchemaPtr schema) |
| 3144 | { |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 3145 | if (output == NULL) |
| 3146 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3147 | if (schema == NULL) { |
| 3148 | fprintf(output, "Schemas: NULL\n"); |
| 3149 | return; |
| 3150 | } |
| 3151 | fprintf(output, "Schemas: "); |
| 3152 | if (schema->name != NULL) |
| 3153 | fprintf(output, "%s, ", schema->name); |
| 3154 | else |
| 3155 | fprintf(output, "no name, "); |
| 3156 | if (schema->targetNamespace != NULL) |
Daniel Veillard | 580ced8 | 2003-03-21 21:22:48 +0000 | [diff] [blame] | 3157 | fprintf(output, "%s", (const char *) schema->targetNamespace); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3158 | else |
| 3159 | fprintf(output, "no target namespace"); |
| 3160 | fprintf(output, "\n"); |
| 3161 | if (schema->annot != NULL) |
| 3162 | xmlSchemaAnnotDump(output, schema->annot); |
| 3163 | |
| 3164 | xmlHashScan(schema->typeDecl, (xmlHashScanner) xmlSchemaTypeDump, |
| 3165 | output); |
| 3166 | xmlHashScanFull(schema->elemDecl, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3167 | (xmlHashScannerFull) xmlSchemaElementDump, output); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3168 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 3169 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3170 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 3171 | #ifdef DEBUG_IDC |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 3172 | /** |
| 3173 | * xmlSchemaDebugDumpIDCTable: |
| 3174 | * @vctxt: the WXS validation context |
| 3175 | * |
| 3176 | * Displays the current IDC table for debug purposes. |
| 3177 | */ |
| 3178 | static void |
| 3179 | xmlSchemaDebugDumpIDCTable(FILE * output, |
| 3180 | const xmlChar *namespaceName, |
| 3181 | const xmlChar *localName, |
| 3182 | xmlSchemaPSVIIDCBindingPtr bind) |
| 3183 | { |
| 3184 | xmlChar *str = NULL, *value; |
| 3185 | xmlSchemaPSVIIDCNodePtr tab; |
| 3186 | xmlSchemaPSVIIDCKeyPtr key; |
| 3187 | int i, j, res; |
| 3188 | |
| 3189 | fprintf(output, "IDC: TABLES on %s\n", |
| 3190 | xmlSchemaFormatNsUriLocal(&str, namespaceName, localName)); |
| 3191 | FREE_AND_NULL(str) |
| 3192 | |
| 3193 | if (bind == NULL) |
| 3194 | return; |
| 3195 | do { |
| 3196 | fprintf(output, "IDC: BINDING %s\n", |
| 3197 | xmlSchemaFormatNsUriLocal(&str, bind->definition->targetNamespace, |
| 3198 | bind->definition->name)); |
| 3199 | FREE_AND_NULL(str) |
| 3200 | for (i = 0; i < bind->nbNodes; i++) { |
| 3201 | tab = bind->nodeTable[i]; |
| 3202 | fprintf(output, " ( "); |
| 3203 | for (j = 0; j < bind->definition->nbFields; j++) { |
| 3204 | key = tab->keys[j]; |
| 3205 | if ((key != NULL) && (key->compValue != NULL)) { |
| 3206 | #ifdef IDC_VALUE_SUPPORT |
| 3207 | res = xmlSchemaGetCanonValue(key->compValue, &value); |
| 3208 | #else |
| 3209 | value = xmlStrdup(BAD_CAST "dummy-value"); |
| 3210 | res = 0; |
| 3211 | #endif |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3212 | if (res >= 0) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 3213 | fprintf(output, "\"%s\" ", value); |
| 3214 | else |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3215 | fprintf(output, "CANON-VALUE-FAILED "); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3216 | if (res == 0) |
| 3217 | FREE_AND_NULL(value) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 3218 | } else if (key != NULL) |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3219 | fprintf(output, "(no val), "); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 3220 | else |
| 3221 | fprintf(output, "(key missing), "); |
| 3222 | } |
| 3223 | fprintf(output, ")\n"); |
| 3224 | } |
| 3225 | bind = bind->next; |
| 3226 | } while (bind != NULL); |
| 3227 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 3228 | #endif /* DEBUG_IDC */ |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3229 | #endif /* IDC_ENABLED */ |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 3230 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3231 | |
| 3232 | /************************************************************************ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3233 | * * |
| 3234 | * Utilities * |
| 3235 | * * |
| 3236 | ************************************************************************/ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3237 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3238 | /** |
| 3239 | * xmlSchemaGetPropNode: |
| 3240 | * @node: the element node |
| 3241 | * @name: the name of the attribute |
| 3242 | * |
| 3243 | * Seeks an attribute with a name of @name in |
| 3244 | * no namespace. |
| 3245 | * |
| 3246 | * Returns the attribute or NULL if not present. |
| 3247 | */ |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 3248 | static xmlAttrPtr |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3249 | xmlSchemaGetPropNode(xmlNodePtr node, const char *name) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3250 | { |
| 3251 | xmlAttrPtr prop; |
| 3252 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3253 | if ((node == NULL) || (name == NULL)) |
| 3254 | return(NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3255 | prop = node->properties; |
| 3256 | while (prop != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3257 | if ((prop->ns == NULL) && xmlStrEqual(prop->name, BAD_CAST name)) |
| 3258 | return(prop); |
| 3259 | prop = prop->next; |
| 3260 | } |
| 3261 | return (NULL); |
| 3262 | } |
| 3263 | |
| 3264 | /** |
| 3265 | * xmlSchemaGetPropNodeNs: |
| 3266 | * @node: the element node |
| 3267 | * @uri: the uri |
| 3268 | * @name: the name of the attribute |
| 3269 | * |
| 3270 | * Seeks an attribute with a local name of @name and |
| 3271 | * a namespace URI of @uri. |
| 3272 | * |
| 3273 | * Returns the attribute or NULL if not present. |
| 3274 | */ |
| 3275 | static xmlAttrPtr |
| 3276 | xmlSchemaGetPropNodeNs(xmlNodePtr node, const char *uri, const char *name) |
| 3277 | { |
| 3278 | xmlAttrPtr prop; |
| 3279 | |
| 3280 | if ((node == NULL) || (name == NULL)) |
| 3281 | return(NULL); |
| 3282 | prop = node->properties; |
| 3283 | while (prop != NULL) { |
| 3284 | if ((prop->ns != NULL) && |
| 3285 | xmlStrEqual(prop->name, BAD_CAST name) && |
| 3286 | xmlStrEqual(prop->ns->href, BAD_CAST uri)) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3287 | return(prop); |
| 3288 | prop = prop->next; |
| 3289 | } |
| 3290 | return (NULL); |
| 3291 | } |
| 3292 | |
| 3293 | static const xmlChar * |
| 3294 | xmlSchemaGetNodeContent(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node) |
| 3295 | { |
| 3296 | xmlChar *val; |
| 3297 | const xmlChar *ret; |
| 3298 | |
| 3299 | val = xmlNodeGetContent(node); |
| 3300 | if (val == NULL) |
| 3301 | return(NULL); |
| 3302 | ret = xmlDictLookup(ctxt->dict, val, -1); |
| 3303 | xmlFree(val); |
| 3304 | return(ret); |
| 3305 | } |
| 3306 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3307 | /** |
| 3308 | * xmlSchemaGetProp: |
| 3309 | * @ctxt: the parser context |
| 3310 | * @node: the node |
| 3311 | * @name: the property name |
| 3312 | * |
| 3313 | * Read a attribute value and internalize the string |
| 3314 | * |
| 3315 | * Returns the string or NULL if not present. |
| 3316 | */ |
| 3317 | static const xmlChar * |
| 3318 | xmlSchemaGetProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
| 3319 | const char *name) |
| 3320 | { |
| 3321 | xmlChar *val; |
| 3322 | const xmlChar *ret; |
| 3323 | |
| 3324 | val = xmlGetProp(node, BAD_CAST name); |
| 3325 | if (val == NULL) |
| 3326 | return(NULL); |
| 3327 | ret = xmlDictLookup(ctxt->dict, val, -1); |
| 3328 | xmlFree(val); |
| 3329 | return(ret); |
| 3330 | } |
| 3331 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3332 | /************************************************************************ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3333 | * * |
| 3334 | * Parsing functions * |
| 3335 | * * |
| 3336 | ************************************************************************/ |
| 3337 | |
| 3338 | /** |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3339 | * xmlSchemaGetElem: |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3340 | * @schema: the schema context |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3341 | * @name: the element name |
| 3342 | * @ns: the element namespace |
| 3343 | * |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3344 | * Lookup a global element declaration in the schema. |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3345 | * |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3346 | * Returns the element declaration or NULL if not found. |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3347 | */ |
| 3348 | static xmlSchemaElementPtr |
| 3349 | xmlSchemaGetElem(xmlSchemaPtr schema, const xmlChar * name, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3350 | const xmlChar * namespace) |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3351 | { |
| 3352 | xmlSchemaElementPtr ret; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3353 | |
| 3354 | if ((name == NULL) || (schema == NULL)) |
| 3355 | return (NULL); |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3356 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3357 | ret = xmlHashLookup2(schema->elemDecl, name, namespace); |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 3358 | if ((ret != NULL) && |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3359 | (ret->flags & XML_SCHEMAS_ELEM_GLOBAL)) { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3360 | return (ret); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3361 | } else |
| 3362 | ret = NULL; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 3363 | /* |
| 3364 | * This one was removed, since top level element declarations have |
| 3365 | * the target namespace specified in targetNamespace of the <schema> |
| 3366 | * information element, even if elementFormDefault is "unqualified". |
| 3367 | */ |
| 3368 | |
| 3369 | /* else if ((schema->flags & XML_SCHEMAS_QUALIF_ELEM) == 0) { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3370 | if (xmlStrEqual(namespace, schema->targetNamespace)) |
| 3371 | ret = xmlHashLookup2(schema->elemDecl, name, NULL); |
| 3372 | else |
| 3373 | ret = xmlHashLookup2(schema->elemDecl, name, namespace); |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 3374 | if ((ret != NULL) && |
| 3375 | ((level == 0) || (ret->flags & XML_SCHEMAS_ELEM_TOPLEVEL))) { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3376 | return (ret); |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 3377 | } |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 3378 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3379 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3380 | /* |
| 3381 | * Removed since imported components will be hold by the main schema only. |
| 3382 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3383 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3384 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3385 | else |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3386 | import = xmlHashLookup(schema->schemasImports, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3387 | if (import != NULL) { |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 3388 | ret = xmlSchemaGetElem(import->schema, name, namespace, level + 1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3389 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ELEM_GLOBAL)) { |
| 3390 | return (ret); |
| 3391 | } else |
| 3392 | ret = NULL; |
| 3393 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3394 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3395 | #ifdef DEBUG |
| 3396 | if (ret == NULL) { |
| 3397 | if (namespace == NULL) |
| 3398 | fprintf(stderr, "Unable to lookup type %s", name); |
| 3399 | else |
| 3400 | fprintf(stderr, "Unable to lookup type %s:%s", name, |
| 3401 | namespace); |
| 3402 | } |
| 3403 | #endif |
| 3404 | return (ret); |
| 3405 | } |
| 3406 | |
| 3407 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3408 | * xmlSchemaGetType: |
| 3409 | * @schema: the schemas context |
| 3410 | * @name: the type name |
| 3411 | * @ns: the type namespace |
| 3412 | * |
| 3413 | * Lookup a type in the schemas or the predefined types |
| 3414 | * |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 3415 | * Returns the group definition or NULL if not found. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3416 | */ |
| 3417 | static xmlSchemaTypePtr |
| 3418 | xmlSchemaGetType(xmlSchemaPtr schema, const xmlChar * name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3419 | const xmlChar * namespace) |
| 3420 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3421 | xmlSchemaTypePtr ret; |
| 3422 | |
| 3423 | if (name == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3424 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3425 | if (schema != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3426 | ret = xmlHashLookup2(schema->typeDecl, name, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3427 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_TYPE_GLOBAL)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3428 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3429 | } |
| 3430 | ret = xmlSchemaGetPredefinedType(name, namespace); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 3431 | if (ret != NULL) |
| 3432 | return (ret); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3433 | /* |
| 3434 | * Removed, since the imported components will be grafted on the |
| 3435 | * main schema only. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3436 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3437 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3438 | else |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 3439 | import = xmlHashLookup(schema->schemasImports, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3440 | if (import != NULL) { |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 3441 | ret = xmlSchemaGetType(import->schema, name, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3442 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_TYPE_GLOBAL)) { |
| 3443 | return (ret); |
| 3444 | } else |
| 3445 | ret = NULL; |
| 3446 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3447 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3448 | #ifdef DEBUG |
| 3449 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3450 | if (namespace == NULL) |
| 3451 | fprintf(stderr, "Unable to lookup type %s", name); |
| 3452 | else |
| 3453 | fprintf(stderr, "Unable to lookup type %s:%s", name, |
| 3454 | namespace); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3455 | } |
| 3456 | #endif |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3457 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3458 | } |
| 3459 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3460 | /** |
| 3461 | * xmlSchemaGetAttribute: |
| 3462 | * @schema: the context of the schema |
| 3463 | * @name: the name of the attribute |
| 3464 | * @ns: the target namespace of the attribute |
| 3465 | * |
| 3466 | * Lookup a an attribute in the schema or imported schemas |
| 3467 | * |
| 3468 | * Returns the attribute declaration or NULL if not found. |
| 3469 | */ |
| 3470 | static xmlSchemaAttributePtr |
| 3471 | xmlSchemaGetAttribute(xmlSchemaPtr schema, const xmlChar * name, |
| 3472 | const xmlChar * namespace) |
| 3473 | { |
| 3474 | xmlSchemaAttributePtr ret; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3475 | |
| 3476 | if ((name == NULL) || (schema == NULL)) |
| 3477 | return (NULL); |
| 3478 | |
| 3479 | |
| 3480 | ret = xmlHashLookup2(schema->attrDecl, name, namespace); |
| 3481 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ATTR_GLOBAL)) |
| 3482 | return (ret); |
| 3483 | else |
| 3484 | ret = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3485 | /* |
| 3486 | * Removed, since imported components will be hold by the main schema only. |
| 3487 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3488 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3489 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3490 | else |
| 3491 | import = xmlHashLookup(schema->schemasImports, namespace); |
| 3492 | if (import != NULL) { |
| 3493 | ret = xmlSchemaGetAttribute(import->schema, name, namespace); |
| 3494 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ATTR_GLOBAL)) { |
| 3495 | return (ret); |
| 3496 | } else |
| 3497 | ret = NULL; |
| 3498 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3499 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3500 | #ifdef DEBUG |
| 3501 | if (ret == NULL) { |
| 3502 | if (namespace == NULL) |
| 3503 | fprintf(stderr, "Unable to lookup attribute %s", name); |
| 3504 | else |
| 3505 | fprintf(stderr, "Unable to lookup attribute %s:%s", name, |
| 3506 | namespace); |
| 3507 | } |
| 3508 | #endif |
| 3509 | return (ret); |
| 3510 | } |
| 3511 | |
| 3512 | /** |
| 3513 | * xmlSchemaGetAttributeGroup: |
| 3514 | * @schema: the context of the schema |
| 3515 | * @name: the name of the attribute group |
| 3516 | * @ns: the target namespace of the attribute group |
| 3517 | * |
| 3518 | * Lookup a an attribute group in the schema or imported schemas |
| 3519 | * |
| 3520 | * Returns the attribute group definition or NULL if not found. |
| 3521 | */ |
| 3522 | static xmlSchemaAttributeGroupPtr |
| 3523 | xmlSchemaGetAttributeGroup(xmlSchemaPtr schema, const xmlChar * name, |
| 3524 | const xmlChar * namespace) |
| 3525 | { |
| 3526 | xmlSchemaAttributeGroupPtr ret; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3527 | |
| 3528 | if ((name == NULL) || (schema == NULL)) |
| 3529 | return (NULL); |
| 3530 | |
| 3531 | |
| 3532 | ret = xmlHashLookup2(schema->attrgrpDecl, name, namespace); |
| 3533 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ATTRGROUP_GLOBAL)) |
| 3534 | return (ret); |
| 3535 | else |
| 3536 | ret = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3537 | /* |
| 3538 | * Removed since imported components will be hold by the main schema only. |
| 3539 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3540 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3541 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3542 | else |
| 3543 | import = xmlHashLookup(schema->schemasImports, namespace); |
| 3544 | if (import != NULL) { |
| 3545 | ret = xmlSchemaGetAttributeGroup(import->schema, name, namespace); |
| 3546 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ATTRGROUP_GLOBAL)) |
| 3547 | return (ret); |
| 3548 | else |
| 3549 | ret = NULL; |
| 3550 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3551 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3552 | #ifdef DEBUG |
| 3553 | if (ret == NULL) { |
| 3554 | if (namespace == NULL) |
| 3555 | fprintf(stderr, "Unable to lookup attribute group %s", name); |
| 3556 | else |
| 3557 | fprintf(stderr, "Unable to lookup attribute group %s:%s", name, |
| 3558 | namespace); |
| 3559 | } |
| 3560 | #endif |
| 3561 | return (ret); |
| 3562 | } |
| 3563 | |
| 3564 | /** |
| 3565 | * xmlSchemaGetGroup: |
| 3566 | * @schema: the context of the schema |
| 3567 | * @name: the name of the group |
| 3568 | * @ns: the target namespace of the group |
| 3569 | * |
| 3570 | * Lookup a group in the schema or imported schemas |
| 3571 | * |
| 3572 | * Returns the group definition or NULL if not found. |
| 3573 | */ |
| 3574 | static xmlSchemaTypePtr |
| 3575 | xmlSchemaGetGroup(xmlSchemaPtr schema, const xmlChar * name, |
| 3576 | const xmlChar * namespace) |
| 3577 | { |
| 3578 | xmlSchemaTypePtr ret; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3579 | |
| 3580 | if ((name == NULL) || (schema == NULL)) |
| 3581 | return (NULL); |
| 3582 | |
| 3583 | |
| 3584 | ret = xmlHashLookup2(schema->groupDecl, name, namespace); |
| 3585 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_TYPE_GLOBAL)) |
| 3586 | return (ret); |
| 3587 | else |
| 3588 | ret = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3589 | /* |
| 3590 | * Removed since imported components will be hold by the main schema only. |
| 3591 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3592 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3593 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3594 | else |
| 3595 | import = xmlHashLookup(schema->schemasImports, namespace); |
| 3596 | if (import != NULL) { |
| 3597 | ret = xmlSchemaGetGroup(import->schema, name, namespace); |
| 3598 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_TYPE_GLOBAL)) |
| 3599 | return (ret); |
| 3600 | else |
| 3601 | ret = NULL; |
| 3602 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3603 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3604 | #ifdef DEBUG |
| 3605 | if (ret == NULL) { |
| 3606 | if (namespace == NULL) |
| 3607 | fprintf(stderr, "Unable to lookup group %s", name); |
| 3608 | else |
| 3609 | fprintf(stderr, "Unable to lookup group %s:%s", name, |
| 3610 | namespace); |
| 3611 | } |
| 3612 | #endif |
| 3613 | return (ret); |
| 3614 | } |
| 3615 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3616 | /************************************************************************ |
| 3617 | * * |
| 3618 | * Parsing functions * |
| 3619 | * * |
| 3620 | ************************************************************************/ |
| 3621 | |
| 3622 | #define IS_BLANK_NODE(n) \ |
| 3623 | (((n)->type == XML_TEXT_NODE) && (xmlSchemaIsBlank((n)->content))) |
| 3624 | |
| 3625 | /** |
| 3626 | * xmlSchemaIsBlank: |
| 3627 | * @str: a string |
| 3628 | * |
| 3629 | * Check if a string is ignorable |
| 3630 | * |
| 3631 | * Returns 1 if the string is NULL or made of blanks chars, 0 otherwise |
| 3632 | */ |
| 3633 | static int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3634 | xmlSchemaIsBlank(xmlChar * str) |
| 3635 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3636 | if (str == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3637 | return (1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3638 | while (*str != 0) { |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3639 | if (!(IS_BLANK_CH(*str))) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3640 | return (0); |
| 3641 | str++; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3642 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3643 | return (1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3644 | } |
| 3645 | |
| 3646 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3647 | * xmlSchemaAddAssembledItem: |
| 3648 | * @ctxt: a schema parser context |
| 3649 | * @schema: the schema being built |
| 3650 | * @item: the item |
| 3651 | * |
| 3652 | * Add a item to the schema's list of current items. |
| 3653 | * This is used if the schema was already constructed and |
| 3654 | * new schemata need to be added to it. |
| 3655 | * *WARNING* this interface is highly subject to change. |
| 3656 | * |
| 3657 | * Returns 0 if suceeds and -1 if an internal error occurs. |
| 3658 | */ |
| 3659 | static int |
| 3660 | xmlSchemaAddAssembledItem(xmlSchemaParserCtxtPtr ctxt, |
| 3661 | xmlSchemaTypePtr item) |
| 3662 | { |
| 3663 | static int growSize = 100; |
| 3664 | xmlSchemaAssemblePtr ass; |
| 3665 | |
| 3666 | ass = ctxt->assemble; |
| 3667 | if (ass->sizeItems < 0) { |
| 3668 | /* If disabled. */ |
| 3669 | return (0); |
| 3670 | } |
| 3671 | if (ass->sizeItems <= 0) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 3672 | ass->items = (void **) xmlMalloc(growSize * sizeof(xmlSchemaTypePtr)); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3673 | if (ass->items == NULL) { |
| 3674 | xmlSchemaPErrMemory(ctxt, |
| 3675 | "allocating new item buffer", NULL); |
| 3676 | return (-1); |
| 3677 | } |
| 3678 | ass->sizeItems = growSize; |
| 3679 | } else if (ass->sizeItems <= ass->nbItems) { |
| 3680 | ass->sizeItems *= 2; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 3681 | ass->items = (void **) xmlRealloc(ass->items, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3682 | ass->sizeItems * sizeof(xmlSchemaTypePtr)); |
| 3683 | if (ass->items == NULL) { |
| 3684 | xmlSchemaPErrMemory(ctxt, |
| 3685 | "growing item buffer", NULL); |
| 3686 | ass->sizeItems = 0; |
| 3687 | return (-1); |
| 3688 | } |
| 3689 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 3690 | /* ass->items[ass->nbItems++] = (void *) item; */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3691 | ((xmlSchemaTypePtr *) ass->items)[ass->nbItems++] = (void *) item; |
| 3692 | return (0); |
| 3693 | } |
| 3694 | |
| 3695 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3696 | * xmlSchemaAddNotation: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3697 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3698 | * @schema: the schema being built |
| 3699 | * @name: the item name |
| 3700 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3701 | * Add an XML schema annotation declaration |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3702 | * *WARNING* this interface is highly subject to change |
| 3703 | * |
| 3704 | * Returns the new struture or NULL in case of error |
| 3705 | */ |
| 3706 | static xmlSchemaNotationPtr |
| 3707 | xmlSchemaAddNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 3708 | const xmlChar *name) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3709 | { |
| 3710 | xmlSchemaNotationPtr ret = NULL; |
| 3711 | int val; |
| 3712 | |
| 3713 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3714 | return (NULL); |
| 3715 | |
| 3716 | if (schema->notaDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 3717 | schema->notaDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3718 | if (schema->notaDecl == NULL) |
| 3719 | return (NULL); |
| 3720 | |
| 3721 | ret = (xmlSchemaNotationPtr) xmlMalloc(sizeof(xmlSchemaNotation)); |
| 3722 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3723 | xmlSchemaPErrMemory(ctxt, "add annotation", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3724 | return (NULL); |
| 3725 | } |
| 3726 | memset(ret, 0, sizeof(xmlSchemaNotation)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3727 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3728 | val = xmlHashAddEntry2(schema->notaDecl, name, schema->targetNamespace, |
| 3729 | ret); |
| 3730 | if (val != 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3731 | /* |
| 3732 | * TODO: This should never happen, since a unique name will be computed. |
| 3733 | * If it fails, then an other internal error must have occured. |
| 3734 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3735 | xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc, |
| 3736 | XML_SCHEMAP_REDEFINED_NOTATION, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3737 | "Annotation declaration '%s' is already declared.\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3738 | name, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3739 | xmlFree(ret); |
| 3740 | return (NULL); |
| 3741 | } |
| 3742 | return (ret); |
| 3743 | } |
| 3744 | |
| 3745 | |
| 3746 | /** |
| 3747 | * xmlSchemaAddAttribute: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3748 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3749 | * @schema: the schema being built |
| 3750 | * @name: the item name |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3751 | * @namespace: the namespace |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3752 | * |
| 3753 | * Add an XML schema Attrribute declaration |
| 3754 | * *WARNING* this interface is highly subject to change |
| 3755 | * |
| 3756 | * Returns the new struture or NULL in case of error |
| 3757 | */ |
| 3758 | static xmlSchemaAttributePtr |
| 3759 | xmlSchemaAddAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3760 | const xmlChar * name, const xmlChar * namespace, |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3761 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3762 | { |
| 3763 | xmlSchemaAttributePtr ret = NULL; |
| 3764 | int val; |
| 3765 | |
| 3766 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3767 | return (NULL); |
| 3768 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3769 | #ifdef DEBUG |
| 3770 | fprintf(stderr, "Adding attribute %s\n", name); |
| 3771 | if (namespace != NULL) |
| 3772 | fprintf(stderr, " target namespace %s\n", namespace); |
| 3773 | #endif |
| 3774 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3775 | if (schema->attrDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 3776 | schema->attrDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3777 | if (schema->attrDecl == NULL) |
| 3778 | return (NULL); |
| 3779 | |
| 3780 | ret = (xmlSchemaAttributePtr) xmlMalloc(sizeof(xmlSchemaAttribute)); |
| 3781 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3782 | xmlSchemaPErrMemory(ctxt, "allocating attribute", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3783 | return (NULL); |
| 3784 | } |
| 3785 | memset(ret, 0, sizeof(xmlSchemaAttribute)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3786 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 3787 | ret->targetNamespace = namespace; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3788 | val = xmlHashAddEntry3(schema->attrDecl, name, |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 3789 | namespace, ctxt->container, ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3790 | if (val != 0) { |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3791 | if (topLevel) { |
| 3792 | xmlSchemaPCustomErr(ctxt, |
| 3793 | XML_SCHEMAP_REDEFINED_ATTR, |
| 3794 | NULL, NULL, node, |
| 3795 | "A global attribute declaration with the name '%s' does " |
| 3796 | "already exist", name); |
| 3797 | xmlFree(ret); |
| 3798 | return (NULL); |
| 3799 | } else { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3800 | char buf[30]; |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3801 | /* |
| 3802 | * Using the ctxt->container for xmlHashAddEntry3 is ambigious |
| 3803 | * in the scenario: |
| 3804 | * 1. multiple top-level complex types have different target |
| 3805 | * namespaces but have the SAME NAME; this can happen if |
| 3806 | * schemata are imported |
| 3807 | * 2. those complex types contain attributes with an equal name |
| 3808 | * 3. those attributes are in no namespace |
| 3809 | * We will compute a new context string. |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3810 | */ |
| 3811 | snprintf(buf, 29, "#aCont%d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3812 | val = xmlHashAddEntry3(schema->attrDecl, name, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 3813 | namespace, xmlDictLookup(ctxt->dict, BAD_CAST buf, -1), ret); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3814 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3815 | if (val != 0) { |
| 3816 | xmlSchemaPCustomErr(ctxt, |
| 3817 | XML_SCHEMAP_INTERNAL, |
| 3818 | NULL, NULL, node, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3819 | "Internal error: xmlSchemaAddAttribute, " |
| 3820 | "a dublicate attribute declaration with the name '%s' " |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3821 | "could not be added to the hash.", name); |
| 3822 | xmlFree(ret); |
| 3823 | return (NULL); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3824 | } |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3825 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3826 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3827 | if (ctxt->assemble != NULL) |
| 3828 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3829 | return (ret); |
| 3830 | } |
| 3831 | |
| 3832 | /** |
| 3833 | * xmlSchemaAddAttributeGroup: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3834 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3835 | * @schema: the schema being built |
| 3836 | * @name: the item name |
| 3837 | * |
| 3838 | * Add an XML schema Attrribute Group declaration |
| 3839 | * |
| 3840 | * Returns the new struture or NULL in case of error |
| 3841 | */ |
| 3842 | static xmlSchemaAttributeGroupPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3843 | xmlSchemaAddAttributeGroup(xmlSchemaParserCtxtPtr ctxt, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3844 | xmlSchemaPtr schema, const xmlChar * name, |
| 3845 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3846 | { |
| 3847 | xmlSchemaAttributeGroupPtr ret = NULL; |
| 3848 | int val; |
| 3849 | |
| 3850 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3851 | return (NULL); |
| 3852 | |
| 3853 | if (schema->attrgrpDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 3854 | schema->attrgrpDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3855 | if (schema->attrgrpDecl == NULL) |
| 3856 | return (NULL); |
| 3857 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3858 | ret = |
| 3859 | (xmlSchemaAttributeGroupPtr) |
| 3860 | xmlMalloc(sizeof(xmlSchemaAttributeGroup)); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3861 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3862 | xmlSchemaPErrMemory(ctxt, "allocating attribute group", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3863 | return (NULL); |
| 3864 | } |
| 3865 | memset(ret, 0, sizeof(xmlSchemaAttributeGroup)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3866 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3867 | val = xmlHashAddEntry3(schema->attrgrpDecl, name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3868 | schema->targetNamespace, ctxt->container, ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3869 | if (val != 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3870 | xmlSchemaPCustomErr(ctxt, |
| 3871 | XML_SCHEMAP_REDEFINED_ATTRGROUP, |
| 3872 | NULL, NULL, node, |
| 3873 | "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] | 3874 | xmlFree(ret); |
| 3875 | return (NULL); |
| 3876 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3877 | if (ctxt->assemble != NULL) |
| 3878 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3879 | return (ret); |
| 3880 | } |
| 3881 | |
| 3882 | /** |
| 3883 | * xmlSchemaAddElement: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3884 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3885 | * @schema: the schema being built |
| 3886 | * @name: the type name |
| 3887 | * @namespace: the type namespace |
| 3888 | * |
| 3889 | * Add an XML schema Element declaration |
| 3890 | * *WARNING* this interface is highly subject to change |
| 3891 | * |
| 3892 | * Returns the new struture or NULL in case of error |
| 3893 | */ |
| 3894 | static xmlSchemaElementPtr |
| 3895 | xmlSchemaAddElement(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3896 | const xmlChar * name, const xmlChar * namespace, |
| 3897 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3898 | { |
| 3899 | xmlSchemaElementPtr ret = NULL; |
| 3900 | int val; |
| 3901 | |
| 3902 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3903 | return (NULL); |
| 3904 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3905 | #ifdef DEBUG |
| 3906 | fprintf(stderr, "Adding element %s\n", name); |
| 3907 | if (namespace != NULL) |
| 3908 | fprintf(stderr, " target namespace %s\n", namespace); |
| 3909 | #endif |
| 3910 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3911 | if (schema->elemDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 3912 | schema->elemDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3913 | if (schema->elemDecl == NULL) |
| 3914 | return (NULL); |
| 3915 | |
| 3916 | ret = (xmlSchemaElementPtr) xmlMalloc(sizeof(xmlSchemaElement)); |
| 3917 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3918 | xmlSchemaPErrMemory(ctxt, "allocating element", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3919 | return (NULL); |
| 3920 | } |
| 3921 | memset(ret, 0, sizeof(xmlSchemaElement)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3922 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3923 | val = xmlHashAddEntry3(schema->elemDecl, name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3924 | namespace, ctxt->container, ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3925 | if (val != 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3926 | if (topLevel) { |
| 3927 | xmlSchemaPCustomErr(ctxt, |
| 3928 | XML_SCHEMAP_REDEFINED_ELEMENT, |
| 3929 | NULL, NULL, node, |
| 3930 | "A global element declaration with the name '%s' does " |
| 3931 | "already exist", name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3932 | xmlFree(ret); |
| 3933 | return (NULL); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3934 | } else { |
| 3935 | char buf[30]; |
| 3936 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3937 | snprintf(buf, 29, "#eCont%d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3938 | val = xmlHashAddEntry3(schema->elemDecl, name, |
| 3939 | namespace, (xmlChar *) buf, ret); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3940 | if (val != 0) { |
| 3941 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3942 | XML_SCHEMAP_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3943 | NULL, NULL, node, |
| 3944 | "Internal error: xmlSchemaAddElement, " |
| 3945 | "a dublicate element declaration with the name '%s' " |
| 3946 | "could not be added to the hash.", name); |
| 3947 | xmlFree(ret); |
| 3948 | return (NULL); |
| 3949 | } |
| 3950 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3951 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3952 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3953 | if (ctxt->assemble != NULL) |
| 3954 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3955 | return (ret); |
| 3956 | } |
| 3957 | |
| 3958 | /** |
| 3959 | * xmlSchemaAddType: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3960 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3961 | * @schema: the schema being built |
| 3962 | * @name: the item name |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3963 | * @namespace: the namespace |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3964 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3965 | * Add an XML schema item |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3966 | * *WARNING* this interface is highly subject to change |
| 3967 | * |
| 3968 | * Returns the new struture or NULL in case of error |
| 3969 | */ |
| 3970 | static xmlSchemaTypePtr |
| 3971 | xmlSchemaAddType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3972 | const xmlChar * name, const xmlChar * namespace, |
| 3973 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3974 | { |
| 3975 | xmlSchemaTypePtr ret = NULL; |
| 3976 | int val; |
| 3977 | |
| 3978 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3979 | return (NULL); |
| 3980 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3981 | #ifdef DEBUG |
| 3982 | fprintf(stderr, "Adding type %s\n", name); |
| 3983 | if (namespace != NULL) |
| 3984 | fprintf(stderr, " target namespace %s\n", namespace); |
| 3985 | #endif |
| 3986 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3987 | if (schema->typeDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 3988 | schema->typeDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3989 | if (schema->typeDecl == NULL) |
| 3990 | return (NULL); |
| 3991 | |
| 3992 | ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType)); |
| 3993 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3994 | xmlSchemaPErrMemory(ctxt, "allocating type", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3995 | return (NULL); |
| 3996 | } |
| 3997 | memset(ret, 0, sizeof(xmlSchemaType)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3998 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 3999 | ret->redef = NULL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4000 | val = xmlHashAddEntry2(schema->typeDecl, name, namespace, ret); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4001 | if (val != 0) { |
| 4002 | if (ctxt->includes == 0) { |
| 4003 | xmlSchemaPCustomErr(ctxt, |
| 4004 | XML_SCHEMAP_REDEFINED_TYPE, |
| 4005 | NULL, NULL, node, |
| 4006 | "A global type definition with the name '%s' does already exist", name); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 4007 | xmlFree(ret); |
| 4008 | return (NULL); |
| 4009 | } else { |
| 4010 | xmlSchemaTypePtr prev; |
| 4011 | |
| 4012 | prev = xmlHashLookup2(schema->typeDecl, name, namespace); |
| 4013 | if (prev == NULL) { |
| 4014 | xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4015 | XML_ERR_INTERNAL_ERROR, |
| 4016 | "Internal error: xmlSchemaAddType, on type " |
| 4017 | "'%s'.\n", |
| 4018 | name, NULL); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 4019 | xmlFree(ret); |
| 4020 | return (NULL); |
| 4021 | } |
| 4022 | ret->redef = prev->redef; |
| 4023 | prev->redef = ret; |
| 4024 | } |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4025 | } |
| 4026 | ret->minOccurs = 1; |
| 4027 | ret->maxOccurs = 1; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4028 | ret->attributeUses = NULL; |
| 4029 | ret->attributeWildcard = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4030 | if (ctxt->assemble != NULL) |
| 4031 | xmlSchemaAddAssembledItem(ctxt,ret); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4032 | return (ret); |
| 4033 | } |
| 4034 | |
| 4035 | /** |
| 4036 | * xmlSchemaAddGroup: |
| 4037 | * @ctxt: a schema validation context |
| 4038 | * @schema: the schema being built |
| 4039 | * @name: the group name |
| 4040 | * |
| 4041 | * Add an XML schema Group definition |
| 4042 | * |
| 4043 | * Returns the new struture or NULL in case of error |
| 4044 | */ |
| 4045 | static xmlSchemaTypePtr |
| 4046 | xmlSchemaAddGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 4047 | const xmlChar *name, const xmlChar *namespaceName, |
| 4048 | xmlNodePtr node) |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4049 | { |
| 4050 | xmlSchemaTypePtr ret = NULL; |
| 4051 | int val; |
| 4052 | |
| 4053 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 4054 | return (NULL); |
| 4055 | |
| 4056 | if (schema->groupDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 4057 | schema->groupDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4058 | if (schema->groupDecl == NULL) |
| 4059 | return (NULL); |
| 4060 | |
| 4061 | ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType)); |
| 4062 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4063 | xmlSchemaPErrMemory(ctxt, "adding group", NULL); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4064 | return (NULL); |
| 4065 | } |
| 4066 | memset(ret, 0, sizeof(xmlSchemaType)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4067 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4068 | val = |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 4069 | xmlHashAddEntry2(schema->groupDecl, name, namespaceName, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4070 | ret); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 4071 | if (val != 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4072 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 4073 | XML_SCHEMAP_REDEFINED_GROUP, |
| 4074 | NULL, NULL, node, |
| 4075 | "A global model group definition with the name '%s' does already " |
| 4076 | "exist", name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4077 | xmlFree(ret); |
| 4078 | return (NULL); |
| 4079 | } |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 4080 | ret->targetNamespace = namespaceName; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4081 | ret->minOccurs = 1; |
| 4082 | ret->maxOccurs = 1; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4083 | if (ctxt->assemble != NULL) |
| 4084 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4085 | return (ret); |
| 4086 | } |
| 4087 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4088 | /** |
| 4089 | * xmlSchemaNewWildcardNs: |
| 4090 | * @ctxt: a schema validation context |
| 4091 | * |
| 4092 | * Creates a new wildcard namespace constraint. |
| 4093 | * |
| 4094 | * Returns the new struture or NULL in case of error |
| 4095 | */ |
| 4096 | static xmlSchemaWildcardNsPtr |
| 4097 | xmlSchemaNewWildcardNsConstraint(xmlSchemaParserCtxtPtr ctxt) |
| 4098 | { |
| 4099 | xmlSchemaWildcardNsPtr ret; |
| 4100 | |
| 4101 | ret = (xmlSchemaWildcardNsPtr) |
| 4102 | xmlMalloc(sizeof(xmlSchemaWildcardNs)); |
| 4103 | if (ret == NULL) { |
| 4104 | xmlSchemaPErrMemory(ctxt, "creating wildcard namespace constraint", NULL); |
| 4105 | return (NULL); |
| 4106 | } |
| 4107 | ret->value = NULL; |
| 4108 | ret->next = NULL; |
| 4109 | return (ret); |
| 4110 | } |
| 4111 | |
| 4112 | /** |
| 4113 | * xmlSchemaAddWildcard: |
| 4114 | * @ctxt: a schema validation context |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4115 | * Adds a wildcard. It corresponds to a |
| 4116 | * xsd:anyAttribute and is used as storage for namespace |
| 4117 | * constraints on a xsd:any. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4118 | * |
| 4119 | * Returns the new struture or NULL in case of error |
| 4120 | */ |
| 4121 | static xmlSchemaWildcardPtr |
| 4122 | xmlSchemaAddWildcard(xmlSchemaParserCtxtPtr ctxt) |
| 4123 | { |
| 4124 | xmlSchemaWildcardPtr ret = NULL; |
| 4125 | |
| 4126 | if (ctxt == NULL) |
| 4127 | return (NULL); |
| 4128 | |
| 4129 | ret = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard)); |
| 4130 | if (ret == NULL) { |
| 4131 | xmlSchemaPErrMemory(ctxt, "adding wildcard", NULL); |
| 4132 | return (NULL); |
| 4133 | } |
| 4134 | memset(ret, 0, sizeof(xmlSchemaWildcard)); |
| 4135 | ret->minOccurs = 1; |
| 4136 | ret->maxOccurs = 1; |
| 4137 | |
| 4138 | return (ret); |
| 4139 | } |
| 4140 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4141 | /************************************************************************ |
| 4142 | * * |
| 4143 | * Utilities for parsing * |
| 4144 | * * |
| 4145 | ************************************************************************/ |
| 4146 | |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 4147 | #if 0 |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4148 | /** |
| 4149 | * xmlGetQNameProp: |
| 4150 | * @ctxt: a schema validation context |
| 4151 | * @node: a subtree containing XML Schema informations |
| 4152 | * @name: the attribute name |
| 4153 | * @namespace: the result namespace if any |
| 4154 | * |
| 4155 | * Extract a QName Attribute value |
| 4156 | * |
| 4157 | * Returns the NCName or NULL if not found, and also update @namespace |
| 4158 | * with the namespace URI |
| 4159 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4160 | static const xmlChar * |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4161 | xmlGetQNameProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4162 | const char *name, const xmlChar ** namespace) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4163 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4164 | const xmlChar *val; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4165 | xmlNsPtr ns; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4166 | const xmlChar *ret, *prefix; |
| 4167 | int len; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 4168 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4169 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4170 | *namespace = NULL; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 4171 | attr = xmlSchemaGetPropNode(node, name); |
| 4172 | if (attr == NULL) |
| 4173 | return (NULL); |
| 4174 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 4175 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4176 | if (val == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4177 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4178 | |
Daniel Veillard | ba0153a | 2004-04-01 10:42:31 +0000 | [diff] [blame] | 4179 | if (!strchr((char *) val, ':')) { |
Daniel Veillard | ebcdebd | 2004-03-05 00:15:50 +0000 | [diff] [blame] | 4180 | ns = xmlSearchNs(node->doc, node, 0); |
| 4181 | if (ns) { |
| 4182 | *namespace = xmlDictLookup(ctxt->dict, ns->href, -1); |
| 4183 | return (val); |
| 4184 | } |
| 4185 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4186 | ret = xmlSplitQName3(val, &len); |
| 4187 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4188 | return (val); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4189 | } |
| 4190 | ret = xmlDictLookup(ctxt->dict, ret, -1); |
| 4191 | prefix = xmlDictLookup(ctxt->dict, val, len); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4192 | |
| 4193 | ns = xmlSearchNs(node->doc, node, prefix); |
| 4194 | if (ns == NULL) { |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 4195 | xmlSchemaPSimpleTypeErr(ctxt, XML_SCHEMAP_PREFIX_UNDEFINED, |
| 4196 | NULL, NULL, (xmlNodePtr) attr, |
| 4197 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), NULL, val, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4198 | "The QName value '%s' has no corresponding namespace " |
| 4199 | "declaration in scope", val, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4200 | } else { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4201 | *namespace = xmlDictLookup(ctxt->dict, ns->href, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4202 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4203 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4204 | } |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 4205 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4206 | |
| 4207 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4208 | * xmlSchemaPValAttrNodeQNameValue: |
| 4209 | * @ctxt: a schema parser context |
| 4210 | * @schema: the schema context |
| 4211 | * @ownerDes: the designation of the parent element |
| 4212 | * @ownerItem: the parent as a schema object |
| 4213 | * @value: the QName value |
| 4214 | * @local: the resulting local part if found, the attribute value otherwise |
| 4215 | * @uri: the resulting namespace URI if found |
| 4216 | * |
| 4217 | * Extracts the local name and the URI of a QName value and validates it. |
| 4218 | * This one is intended to be used on attribute values that |
| 4219 | * should resolve to schema components. |
| 4220 | * |
| 4221 | * Returns 0, in case the QName is valid, a positive error code |
| 4222 | * if not valid and -1 if an internal error occurs. |
| 4223 | */ |
| 4224 | static int |
| 4225 | xmlSchemaPValAttrNodeQNameValue(xmlSchemaParserCtxtPtr ctxt, |
| 4226 | xmlSchemaPtr schema, |
| 4227 | xmlChar **ownerDes, |
| 4228 | xmlSchemaTypePtr ownerItem, |
| 4229 | xmlAttrPtr attr, |
| 4230 | const xmlChar *value, |
| 4231 | const xmlChar **uri, |
| 4232 | const xmlChar **prefix, |
| 4233 | const xmlChar **local) |
| 4234 | { |
| 4235 | const xmlChar *pref; |
| 4236 | xmlNsPtr ns; |
| 4237 | int len, ret; |
| 4238 | |
| 4239 | *uri = NULL; |
| 4240 | *local = NULL; |
| 4241 | if (prefix != 0) |
| 4242 | *prefix = NULL; |
| 4243 | ret = xmlValidateQName(value, 1); |
| 4244 | if (ret > 0) { |
| 4245 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4246 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4247 | ownerDes, ownerItem, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4248 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
| 4249 | "QName", value, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4250 | NULL, NULL, NULL); |
| 4251 | *local = value; |
| 4252 | return (ctxt->err); |
| 4253 | } else if (ret < 0) |
| 4254 | return (-1); |
| 4255 | |
| 4256 | if (!strchr((char *) value, ':')) { |
| 4257 | ns = xmlSearchNs(attr->doc, attr->parent, 0); |
| 4258 | if (ns) |
| 4259 | *uri = xmlDictLookup(ctxt->dict, ns->href, -1); |
| 4260 | else if (schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) { |
| 4261 | /* |
| 4262 | * This one takes care of included schemas with no |
| 4263 | * target namespace. |
| 4264 | */ |
| 4265 | *uri = schema->targetNamespace; |
| 4266 | } |
| 4267 | *local = value; |
| 4268 | return (0); |
| 4269 | } |
| 4270 | /* |
| 4271 | * At this point xmlSplitQName3 has to return a local name. |
| 4272 | */ |
| 4273 | *local = xmlSplitQName3(value, &len); |
| 4274 | *local = xmlDictLookup(ctxt->dict, *local, -1); |
| 4275 | pref = xmlDictLookup(ctxt->dict, value, len); |
| 4276 | if (prefix != 0) |
| 4277 | *prefix = pref; |
| 4278 | ns = xmlSearchNs(attr->doc, attr->parent, pref); |
| 4279 | if (ns == NULL) { |
| 4280 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4281 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4282 | ownerDes, ownerItem, (xmlNodePtr) attr, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4283 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), "QName", value, |
| 4284 | "The QName value '%s' has no corresponding namespace " |
| 4285 | "declaration in scope", value, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4286 | return (ctxt->err); |
| 4287 | } else { |
| 4288 | *uri = xmlDictLookup(ctxt->dict, ns->href, -1); |
| 4289 | } |
| 4290 | return (0); |
| 4291 | } |
| 4292 | |
| 4293 | /** |
| 4294 | * xmlSchemaPValAttrNodeQName: |
| 4295 | * @ctxt: a schema parser context |
| 4296 | * @schema: the schema context |
| 4297 | * @ownerDes: the designation of the owner element |
| 4298 | * @ownerItem: the owner as a schema object |
| 4299 | * @attr: the attribute node |
| 4300 | * @local: the resulting local part if found, the attribute value otherwise |
| 4301 | * @uri: the resulting namespace URI if found |
| 4302 | * |
| 4303 | * Extracts and validates the QName of an attribute value. |
| 4304 | * This one is intended to be used on attribute values that |
| 4305 | * should resolve to schema components. |
| 4306 | * |
| 4307 | * Returns 0, in case the QName is valid, a positive error code |
| 4308 | * if not valid and -1 if an internal error occurs. |
| 4309 | */ |
| 4310 | static int |
| 4311 | xmlSchemaPValAttrNodeQName(xmlSchemaParserCtxtPtr ctxt, |
| 4312 | xmlSchemaPtr schema, |
| 4313 | xmlChar **ownerDes, |
| 4314 | xmlSchemaTypePtr ownerItem, |
| 4315 | xmlAttrPtr attr, |
| 4316 | const xmlChar **uri, |
| 4317 | const xmlChar **prefix, |
| 4318 | const xmlChar **local) |
| 4319 | { |
| 4320 | const xmlChar *value; |
| 4321 | |
| 4322 | value = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 4323 | return (xmlSchemaPValAttrNodeQNameValue(ctxt, schema, |
| 4324 | ownerDes, ownerItem, attr, value, uri, prefix, local)); |
| 4325 | } |
| 4326 | |
| 4327 | /** |
| 4328 | * xmlSchemaPValAttrQName: |
| 4329 | * @ctxt: a schema parser context |
| 4330 | * @schema: the schema context |
| 4331 | * @ownerDes: the designation of the parent element |
| 4332 | * @ownerItem: the owner as a schema object |
| 4333 | * @ownerElem: the parent node of the attribute |
| 4334 | * @name: the name of the attribute |
| 4335 | * @local: the resulting local part if found, the attribute value otherwise |
| 4336 | * @uri: the resulting namespace URI if found |
| 4337 | * |
| 4338 | * Extracts and validates the QName of an attribute value. |
| 4339 | * |
| 4340 | * Returns 0, in case the QName is valid, a positive error code |
| 4341 | * if not valid and -1 if an internal error occurs. |
| 4342 | */ |
| 4343 | static int |
| 4344 | xmlSchemaPValAttrQName(xmlSchemaParserCtxtPtr ctxt, |
| 4345 | xmlSchemaPtr schema, |
| 4346 | xmlChar **ownerDes, |
| 4347 | xmlSchemaTypePtr ownerItem, |
| 4348 | xmlNodePtr ownerElem, |
| 4349 | const char *name, |
| 4350 | const xmlChar **uri, |
| 4351 | const xmlChar **prefix, |
| 4352 | const xmlChar **local) |
| 4353 | { |
| 4354 | xmlAttrPtr attr; |
| 4355 | |
| 4356 | attr = xmlSchemaGetPropNode(ownerElem, name); |
| 4357 | if (attr == NULL) { |
| 4358 | *local = NULL; |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 4359 | if (prefix != NULL) |
| 4360 | *prefix = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4361 | *uri = NULL; |
| 4362 | return (0); |
| 4363 | } |
| 4364 | return (xmlSchemaPValAttrNodeQName(ctxt, schema, |
| 4365 | ownerDes, ownerItem, attr, uri, prefix, local)); |
| 4366 | } |
| 4367 | |
| 4368 | /** |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 4369 | * xmlSchemaPValAttrID: |
| 4370 | * @ctxt: a schema parser context |
| 4371 | * @schema: the schema context |
| 4372 | * @ownerDes: the designation of the parent element |
| 4373 | * @ownerItem: the owner as a schema object |
| 4374 | * @ownerElem: the parent node of the attribute |
| 4375 | * @name: the name of the attribute |
| 4376 | * |
| 4377 | * Extracts and validates the ID of an attribute value. |
| 4378 | * |
| 4379 | * Returns 0, in case the ID is valid, a positive error code |
| 4380 | * if not valid and -1 if an internal error occurs. |
| 4381 | */ |
| 4382 | static int |
| 4383 | xmlSchemaPValAttrID(xmlSchemaParserCtxtPtr ctxt, |
| 4384 | xmlChar **ownerDes, |
| 4385 | xmlSchemaTypePtr ownerItem, |
| 4386 | xmlNodePtr ownerElem, |
| 4387 | const xmlChar *name) |
| 4388 | { |
| 4389 | int ret; |
| 4390 | xmlChar *value; |
| 4391 | xmlAttrPtr attr; |
| 4392 | |
| 4393 | value = xmlGetNoNsProp(ownerElem, name); |
| 4394 | if (value == NULL) |
| 4395 | return (0); |
| 4396 | |
| 4397 | attr = xmlSchemaGetPropNode(ownerElem, (const char *) name); |
| 4398 | if (attr == NULL) |
| 4399 | return (-1); |
| 4400 | |
| 4401 | ret = xmlValidateNCName(BAD_CAST value, 1); |
| 4402 | if (ret == 0) { |
| 4403 | /* |
| 4404 | * NOTE: the IDness might have already be declared in the DTD |
| 4405 | */ |
| 4406 | if (attr->atype != XML_ATTRIBUTE_ID) { |
| 4407 | xmlIDPtr res; |
| 4408 | xmlChar *strip; |
| 4409 | |
| 4410 | /* |
| 4411 | * TODO: Use xmlSchemaStrip here; it's not exported at this |
| 4412 | * moment. |
| 4413 | */ |
| 4414 | strip = xmlSchemaCollapseString(BAD_CAST value); |
| 4415 | if (strip != NULL) |
| 4416 | value = strip; |
| 4417 | res = xmlAddID(NULL, ownerElem->doc, BAD_CAST value, attr); |
| 4418 | if (res == NULL) { |
| 4419 | ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE; |
| 4420 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4421 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4422 | ownerDes, ownerItem, (xmlNodePtr) attr, |
| 4423 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ID), |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 4424 | NULL, NULL, "The ID '%s' is already defined", |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 4425 | BAD_CAST value, NULL); |
| 4426 | } else |
| 4427 | attr->atype = XML_ATTRIBUTE_ID; |
| 4428 | if (strip != NULL) |
| 4429 | xmlFree(strip); |
| 4430 | } |
| 4431 | } else if (ret > 0) { |
| 4432 | ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE; |
| 4433 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4434 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4435 | ownerDes, ownerItem, (xmlNodePtr) attr, |
| 4436 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ID), |
| 4437 | NULL, BAD_CAST value, NULL, NULL, NULL); |
| 4438 | } |
| 4439 | xmlFree(value); |
| 4440 | |
| 4441 | return (ret); |
| 4442 | } |
| 4443 | |
| 4444 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4445 | * xmlGetMaxOccurs: |
| 4446 | * @ctxt: a schema validation context |
| 4447 | * @node: a subtree containing XML Schema informations |
| 4448 | * |
| 4449 | * Get the maxOccurs property |
| 4450 | * |
| 4451 | * Returns the default if not found, or the value |
| 4452 | */ |
| 4453 | static int |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4454 | xmlGetMaxOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
| 4455 | int min, int max, int def, const char *expected) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4456 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4457 | const xmlChar *val, *cur; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4458 | int ret = 0; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4459 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4460 | |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4461 | attr = xmlSchemaGetPropNode(node, "maxOccurs"); |
| 4462 | if (attr == NULL) |
| 4463 | return (def); |
| 4464 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4465 | |
| 4466 | if (xmlStrEqual(val, (const xmlChar *) "unbounded")) { |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4467 | if (max != UNBOUNDED) { |
| 4468 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4469 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4470 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 4471 | NULL, NULL, (xmlNodePtr) attr, NULL, expected, |
| 4472 | val, NULL, NULL, NULL); |
| 4473 | return (def); |
| 4474 | } else |
| 4475 | return (UNBOUNDED); /* encoding it with -1 might be another option */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4476 | } |
| 4477 | |
| 4478 | cur = val; |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4479 | while (IS_BLANK_CH(*cur)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4480 | cur++; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4481 | if (*cur == 0) { |
| 4482 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4483 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4484 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 4485 | NULL, NULL, (xmlNodePtr) attr, NULL, expected, |
| 4486 | val, NULL, NULL, NULL); |
| 4487 | return (def); |
| 4488 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4489 | while ((*cur >= '0') && (*cur <= '9')) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4490 | ret = ret * 10 + (*cur - '0'); |
| 4491 | cur++; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4492 | } |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4493 | while (IS_BLANK_CH(*cur)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4494 | cur++; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4495 | /* |
| 4496 | * TODO: Restrict the maximal value to Integer. |
| 4497 | */ |
| 4498 | if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) { |
| 4499 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4500 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4501 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 4502 | NULL, NULL, (xmlNodePtr) attr, NULL, expected, |
| 4503 | val, NULL, NULL, NULL); |
| 4504 | return (def); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4505 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4506 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4507 | } |
| 4508 | |
| 4509 | /** |
| 4510 | * xmlGetMinOccurs: |
| 4511 | * @ctxt: a schema validation context |
| 4512 | * @node: a subtree containing XML Schema informations |
| 4513 | * |
| 4514 | * Get the minOccurs property |
| 4515 | * |
| 4516 | * Returns the default if not found, or the value |
| 4517 | */ |
| 4518 | static int |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4519 | xmlGetMinOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
| 4520 | int min, int max, int def, const char *expected) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4521 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4522 | const xmlChar *val, *cur; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4523 | int ret = 0; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4524 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4525 | |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4526 | attr = xmlSchemaGetPropNode(node, "minOccurs"); |
| 4527 | if (attr == NULL) |
| 4528 | return (def); |
| 4529 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4530 | cur = val; |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4531 | while (IS_BLANK_CH(*cur)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4532 | cur++; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4533 | if (*cur == 0) { |
| 4534 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4535 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4536 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 4537 | NULL, NULL, (xmlNodePtr) attr, NULL, expected, |
| 4538 | val, NULL, NULL, NULL); |
| 4539 | return (def); |
| 4540 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4541 | while ((*cur >= '0') && (*cur <= '9')) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4542 | ret = ret * 10 + (*cur - '0'); |
| 4543 | cur++; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4544 | } |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4545 | while (IS_BLANK_CH(*cur)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4546 | cur++; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4547 | /* |
| 4548 | * TODO: Restrict the maximal value to Integer. |
| 4549 | */ |
| 4550 | if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) { |
| 4551 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4552 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4553 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 4554 | NULL, NULL, (xmlNodePtr) attr, NULL, expected, |
| 4555 | val, NULL, NULL, NULL); |
| 4556 | return (def); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4557 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4558 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4559 | } |
| 4560 | |
| 4561 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 4562 | * xmlSchemaPGetBoolNodeValue: |
| 4563 | * @ctxt: a schema validation context |
| 4564 | * @ownerDes: owner designation |
| 4565 | * @ownerItem: the owner as a schema item |
| 4566 | * @node: the node holding the value |
| 4567 | * |
| 4568 | * Converts a boolean string value into 1 or 0. |
| 4569 | * |
| 4570 | * Returns 0 or 1. |
| 4571 | */ |
| 4572 | static int |
| 4573 | xmlSchemaPGetBoolNodeValue(xmlSchemaParserCtxtPtr ctxt, |
| 4574 | xmlChar **ownerDes, |
| 4575 | xmlSchemaTypePtr ownerItem, |
| 4576 | xmlNodePtr node) |
| 4577 | { |
| 4578 | xmlChar *value = NULL; |
| 4579 | int res = 0; |
| 4580 | |
| 4581 | value = xmlNodeGetContent(node); |
| 4582 | /* |
| 4583 | * 3.2.2.1 Lexical representation |
| 4584 | * An instance of a datatype that is defined as ·boolean· |
| 4585 | * can have the following legal literals {true, false, 1, 0}. |
| 4586 | */ |
| 4587 | if (xmlStrEqual(BAD_CAST value, BAD_CAST "true")) |
| 4588 | res = 1; |
| 4589 | else if (xmlStrEqual(BAD_CAST value, BAD_CAST "false")) |
| 4590 | res = 0; |
| 4591 | else if (xmlStrEqual(BAD_CAST value, BAD_CAST "1")) |
| 4592 | res = 1; |
| 4593 | else if (xmlStrEqual(BAD_CAST value, BAD_CAST "0")) |
| 4594 | res = 0; |
| 4595 | else { |
| 4596 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4597 | XML_SCHEMAP_INVALID_BOOLEAN, |
| 4598 | ownerDes, ownerItem, node, |
| 4599 | xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN), |
| 4600 | "(1 | 0 | true | false)", BAD_CAST value, |
| 4601 | NULL, NULL, NULL); |
| 4602 | } |
| 4603 | if (value != NULL) |
| 4604 | xmlFree(value); |
| 4605 | return (res); |
| 4606 | } |
| 4607 | |
| 4608 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4609 | * xmlGetBooleanProp: |
| 4610 | * @ctxt: a schema validation context |
| 4611 | * @node: a subtree containing XML Schema informations |
| 4612 | * @name: the attribute name |
| 4613 | * @def: the default value |
| 4614 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4615 | * Evaluate if a boolean property is set |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4616 | * |
| 4617 | * Returns the default if not found, 0 if found to be false, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4618 | * 1 if found to be true |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4619 | */ |
| 4620 | static int |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4621 | xmlGetBooleanProp(xmlSchemaParserCtxtPtr ctxt, |
| 4622 | xmlChar **ownerDes, |
| 4623 | xmlSchemaTypePtr ownerItem, |
| 4624 | xmlNodePtr node, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4625 | const char *name, int def) |
| 4626 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4627 | const xmlChar *val; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4628 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4629 | val = xmlSchemaGetProp(ctxt, node, name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4630 | if (val == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4631 | return (def); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4632 | /* |
| 4633 | * 3.2.2.1 Lexical representation |
| 4634 | * An instance of a datatype that is defined as ·boolean· |
| 4635 | * can have the following legal literals {true, false, 1, 0}. |
| 4636 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4637 | if (xmlStrEqual(val, BAD_CAST "true")) |
| 4638 | def = 1; |
| 4639 | else if (xmlStrEqual(val, BAD_CAST "false")) |
| 4640 | def = 0; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4641 | else if (xmlStrEqual(val, BAD_CAST "1")) |
| 4642 | def = 1; |
| 4643 | else if (xmlStrEqual(val, BAD_CAST "0")) |
| 4644 | def = 0; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 4645 | else { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4646 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4647 | XML_SCHEMAP_INVALID_BOOLEAN, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 4648 | ownerDes, ownerItem, |
| 4649 | (xmlNodePtr) xmlSchemaGetPropNode(node, name), |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4650 | xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN), |
| 4651 | "(1 | 0 | true | false)", val, NULL, NULL, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4652 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4653 | return (def); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4654 | } |
| 4655 | |
| 4656 | /************************************************************************ |
| 4657 | * * |
| 4658 | * Shema extraction from an Infoset * |
| 4659 | * * |
| 4660 | ************************************************************************/ |
| 4661 | static xmlSchemaTypePtr xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr |
| 4662 | ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4663 | xmlNodePtr node, |
| 4664 | int topLevel); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4665 | static xmlSchemaTypePtr xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr |
| 4666 | ctxt, |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4667 | xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4668 | xmlNodePtr node, |
| 4669 | int topLevel); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4670 | static xmlSchemaTypePtr xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr |
| 4671 | ctxt, |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4672 | xmlSchemaPtr schema, |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 4673 | xmlNodePtr node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4674 | static xmlSchemaTypePtr xmlSchemaParseSequence(xmlSchemaParserCtxtPtr ctxt, |
| 4675 | xmlSchemaPtr schema, |
| 4676 | xmlNodePtr node); |
| 4677 | static xmlSchemaTypePtr xmlSchemaParseAll(xmlSchemaParserCtxtPtr ctxt, |
| 4678 | xmlSchemaPtr schema, |
| 4679 | xmlNodePtr node); |
| 4680 | static xmlSchemaAttributePtr xmlSchemaParseAttribute(xmlSchemaParserCtxtPtr |
| 4681 | ctxt, |
| 4682 | xmlSchemaPtr schema, |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4683 | xmlNodePtr node, |
| 4684 | int topLevel); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4685 | static xmlSchemaAttributeGroupPtr |
| 4686 | xmlSchemaParseAttributeGroup(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4687 | xmlSchemaPtr schema, xmlNodePtr node, |
| 4688 | int topLevel); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4689 | static xmlSchemaTypePtr xmlSchemaParseChoice(xmlSchemaParserCtxtPtr ctxt, |
| 4690 | xmlSchemaPtr schema, |
| 4691 | xmlNodePtr node); |
| 4692 | static xmlSchemaTypePtr xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt, |
| 4693 | xmlSchemaPtr schema, |
| 4694 | xmlNodePtr node); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4695 | static xmlSchemaWildcardPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4696 | xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt, |
| 4697 | xmlSchemaPtr schema, xmlNodePtr node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4698 | |
| 4699 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4700 | * xmlSchemaPValAttrNodeValue: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4701 | * |
| 4702 | * @ctxt: a schema parser context |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4703 | * @ownerDes: the designation of the parent element |
| 4704 | * @ownerItem: the schema object owner if existent |
| 4705 | * @attr: the schema attribute node being validated |
| 4706 | * @value: the value |
| 4707 | * @type: the built-in type to be validated against |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4708 | * |
| 4709 | * Validates a value against the given built-in type. |
| 4710 | * This one is intended to be used internally for validation |
| 4711 | * of schema attribute values during parsing of the schema. |
| 4712 | * |
| 4713 | * Returns 0 if the value is valid, a positive error code |
| 4714 | * number otherwise and -1 in case of an internal or API error. |
| 4715 | */ |
| 4716 | static int |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4717 | xmlSchemaPValAttrNodeValue(xmlSchemaParserCtxtPtr ctxt, |
| 4718 | xmlChar **ownerDes, |
| 4719 | xmlSchemaTypePtr ownerItem, |
| 4720 | xmlAttrPtr attr, |
| 4721 | const xmlChar *value, |
| 4722 | xmlSchemaTypePtr type) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4723 | { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4724 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4725 | int ret = 0; |
| 4726 | |
| 4727 | /* |
| 4728 | * NOTE: Should we move this to xmlschematypes.c? Hmm, but this |
| 4729 | * one is really meant to be used internally, so better not. |
| 4730 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4731 | if ((ctxt == NULL) || (type == NULL) || (attr == NULL)) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4732 | return (-1); |
| 4733 | if (type->type != XML_SCHEMA_TYPE_BASIC) { |
| 4734 | xmlSchemaPErr(ctxt, (xmlNodePtr) attr, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 4735 | XML_SCHEMAP_INTERNAL, |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 4736 | "Internal error: xmlSchemaPValAttrNodeValue, the given " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4737 | "type '%s' is not a built-in type.\n", |
| 4738 | type->name, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4739 | return (-1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4740 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4741 | switch (type->builtInType) { |
| 4742 | case XML_SCHEMAS_NCNAME: |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 4743 | case XML_SCHEMAS_QNAME: |
| 4744 | case XML_SCHEMAS_ANYURI: |
| 4745 | case XML_SCHEMAS_TOKEN: |
| 4746 | case XML_SCHEMAS_LANGUAGE: |
| 4747 | ret = xmlSchemaValPredefTypeNode(type, value, NULL, (xmlNodePtr) attr); |
| 4748 | break; |
| 4749 | |
| 4750 | /* |
| 4751 | case XML_SCHEMAS_NCNAME: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4752 | ret = xmlValidateNCName(value, 1); |
| 4753 | break; |
| 4754 | case XML_SCHEMAS_QNAME: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4755 | xmlSchemaPErr(ctxt, (xmlNodePtr) attr, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 4756 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4757 | "Internal error: xmlSchemaPvalueAttrNode, use " |
| 4758 | "the function xmlSchemaExtractSchemaQNamePropvalueidated " |
| 4759 | "for extracting QName valueues instead.\n", |
| 4760 | NULL, NULL); |
| 4761 | return (-1); |
| 4762 | case XML_SCHEMAS_ANYURI: |
| 4763 | if (value != NULL) { |
| 4764 | xmlURIPtr uri = xmlParseURI((const char *) value); |
| 4765 | if (uri == NULL) |
| 4766 | ret = 1; |
| 4767 | else |
| 4768 | xmlFreeURI(uri); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4769 | } |
| 4770 | break; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4771 | case XML_SCHEMAS_TOKEN: { |
| 4772 | const xmlChar *cur = value; |
| 4773 | |
| 4774 | if (IS_BLANK_CH(*cur)) { |
| 4775 | ret = 1; |
| 4776 | } else while (*cur != 0) { |
| 4777 | if ((*cur == 0xd) || (*cur == 0xa) || (*cur == 0x9)) { |
| 4778 | ret = 1; |
| 4779 | break; |
| 4780 | } else if (*cur == ' ') { |
| 4781 | cur++; |
| 4782 | if ((*cur == 0) || (*cur == ' ')) { |
| 4783 | ret = 1; |
| 4784 | break; |
| 4785 | } |
| 4786 | } else { |
| 4787 | cur++; |
| 4788 | } |
| 4789 | } |
| 4790 | } |
| 4791 | break; |
| 4792 | case XML_SCHEMAS_LANGUAGE: |
| 4793 | if (xmlCheckLanguageID(value) != 1) |
| 4794 | ret = 1; |
| 4795 | break; |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 4796 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4797 | default: { |
| 4798 | xmlSchemaPErr(ctxt, (xmlNodePtr) attr, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 4799 | XML_SCHEMAP_INTERNAL, |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 4800 | "Internal error: xmlSchemaPValAttrNodeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4801 | "valueidation using the type '%s' is not implemented " |
| 4802 | "yet.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4803 | type->name, NULL); |
| 4804 | return (-1); |
| 4805 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4806 | } |
| 4807 | /* |
| 4808 | * TODO: Should we use the S4S error codes instead? |
| 4809 | */ |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 4810 | if (ret < 0) { |
| 4811 | xmlSchemaPErr(ctxt, (xmlNodePtr) attr, |
| 4812 | XML_SCHEMAP_INTERNAL, |
| 4813 | "Internal error: xmlSchemaPValAttrNodeValue, " |
| 4814 | "failed to validate a schema attribute value.\n", |
| 4815 | NULL, NULL); |
| 4816 | return (-1); |
| 4817 | } else if (ret > 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4818 | if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 4819 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4820 | XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2, |
| 4821 | ownerDes, ownerItem, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4822 | type, NULL, value, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4823 | NULL, NULL, NULL); |
| 4824 | return(XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2); |
| 4825 | } else { |
| 4826 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4827 | XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, |
| 4828 | ownerDes, ownerItem, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4829 | type, NULL, value, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4830 | NULL, NULL, NULL); |
| 4831 | return(XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1); |
| 4832 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4833 | } |
| 4834 | return (ret); |
| 4835 | } |
| 4836 | |
| 4837 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4838 | * xmlSchemaPValAttrNode: |
| 4839 | * |
| 4840 | * @ctxt: a schema parser context |
| 4841 | * @ownerDes: the designation of the parent element |
| 4842 | * @ownerItem: the schema object owner if existent |
| 4843 | * @attr: the schema attribute node being validated |
| 4844 | * @type: the built-in type to be validated against |
| 4845 | * @value: the resulting value if any |
| 4846 | * |
| 4847 | * Extracts and validates a value against the given built-in type. |
| 4848 | * This one is intended to be used internally for validation |
| 4849 | * of schema attribute values during parsing of the schema. |
| 4850 | * |
| 4851 | * Returns 0 if the value is valid, a positive error code |
| 4852 | * number otherwise and -1 in case of an internal or API error. |
| 4853 | */ |
| 4854 | static int |
| 4855 | xmlSchemaPValAttrNode(xmlSchemaParserCtxtPtr ctxt, |
| 4856 | xmlChar **ownerDes, |
| 4857 | xmlSchemaTypePtr ownerItem, |
| 4858 | xmlAttrPtr attr, |
| 4859 | xmlSchemaTypePtr type, |
| 4860 | const xmlChar **value) |
| 4861 | { |
| 4862 | const xmlChar *val; |
| 4863 | |
| 4864 | if ((ctxt == NULL) || (type == NULL) || (attr == NULL)) |
| 4865 | return (-1); |
| 4866 | |
| 4867 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 4868 | if (value != NULL) |
| 4869 | *value = val; |
| 4870 | |
| 4871 | return (xmlSchemaPValAttrNodeValue(ctxt, ownerDes, ownerItem, attr, |
| 4872 | val, type)); |
| 4873 | } |
| 4874 | |
| 4875 | /** |
| 4876 | * xmlSchemaPValAttr: |
| 4877 | * |
| 4878 | * @ctxt: a schema parser context |
| 4879 | * @node: the element node of the attribute |
| 4880 | * @ownerDes: the designation of the parent element |
| 4881 | * @ownerItem: the schema object owner if existent |
| 4882 | * @ownerElem: the owner element node |
| 4883 | * @name: the name of the schema attribute node |
| 4884 | * @type: the built-in type to be validated against |
| 4885 | * @value: the resulting value if any |
| 4886 | * |
| 4887 | * Extracts and validates a value against the given built-in type. |
| 4888 | * This one is intended to be used internally for validation |
| 4889 | * of schema attribute values during parsing of the schema. |
| 4890 | * |
| 4891 | * Returns 0 if the value is valid, a positive error code |
| 4892 | * number otherwise and -1 in case of an internal or API error. |
| 4893 | */ |
| 4894 | static int |
| 4895 | xmlSchemaPValAttr(xmlSchemaParserCtxtPtr ctxt, |
| 4896 | xmlChar **ownerDes, |
| 4897 | xmlSchemaTypePtr ownerItem, |
| 4898 | xmlNodePtr ownerElem, |
| 4899 | const char *name, |
| 4900 | xmlSchemaTypePtr type, |
| 4901 | const xmlChar **value) |
| 4902 | { |
| 4903 | xmlAttrPtr attr; |
| 4904 | |
| 4905 | if ((ctxt == NULL) || (type == NULL)) { |
| 4906 | if (value != NULL) |
| 4907 | *value = NULL; |
| 4908 | return (-1); |
| 4909 | } |
| 4910 | if (type->type != XML_SCHEMA_TYPE_BASIC) { |
| 4911 | if (value != NULL) |
| 4912 | *value = NULL; |
| 4913 | xmlSchemaPErr(ctxt, ownerElem, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 4914 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4915 | "Internal error: xmlSchemaPValAttr, the given " |
| 4916 | "type '%s' is not a built-in type.\n", |
| 4917 | type->name, NULL); |
| 4918 | return (-1); |
| 4919 | } |
| 4920 | attr = xmlSchemaGetPropNode(ownerElem, name); |
| 4921 | if (attr == NULL) { |
| 4922 | if (value != NULL) |
| 4923 | *value = NULL; |
| 4924 | return (0); |
| 4925 | } |
| 4926 | return (xmlSchemaPValAttrNode(ctxt, ownerDes, ownerItem, attr, |
| 4927 | type, value)); |
| 4928 | } |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 4929 | |
| 4930 | static int |
| 4931 | xmlSchemaCheckReference(xmlSchemaParserCtxtPtr pctxt, |
| 4932 | xmlSchemaPtr schema, |
| 4933 | xmlNodePtr node, |
| 4934 | xmlSchemaTypePtr item, |
| 4935 | const xmlChar *namespaceName) |
| 4936 | { |
| 4937 | if (xmlStrEqual(schema->targetNamespace, namespaceName)) |
| 4938 | return (1); |
| 4939 | if (pctxt->localImports != NULL) { |
| 4940 | int i; |
| 4941 | for (i = 0; i < pctxt->nbLocalImports; i++) |
| 4942 | if (xmlStrEqual(namespaceName, pctxt->localImports[i])) |
| 4943 | return (1); |
| 4944 | } |
| 4945 | if (namespaceName == NULL) |
| 4946 | xmlSchemaPCustomErr(pctxt, XML_SCHEMAP_SRC_RESOLVE, |
| 4947 | NULL, item, node, "References from this schema to components in no " |
| 4948 | "namespace are not valid, since not indicated by an import " |
| 4949 | "statement", NULL); |
| 4950 | else |
| 4951 | xmlSchemaPCustomErr(pctxt, XML_SCHEMAP_SRC_RESOLVE, |
| 4952 | NULL, item, node, "References from this schema to components in the " |
| 4953 | "namespace '%s' are not valid, since not indicated by an import " |
| 4954 | "statement", namespaceName); |
| 4955 | return (0); |
| 4956 | } |
| 4957 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4958 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4959 | * xmlSchemaParseAttrDecls: |
| 4960 | * @ctxt: a schema validation context |
| 4961 | * @schema: the schema being built |
| 4962 | * @node: a subtree containing XML Schema informations |
| 4963 | * @type: the hosting type |
| 4964 | * |
| 4965 | * parse a XML schema attrDecls declaration corresponding to |
| 4966 | * <!ENTITY % attrDecls |
| 4967 | * '((%attribute;| %attributeGroup;)*,(%anyAttribute;)?)'> |
| 4968 | */ |
| 4969 | static xmlNodePtr |
| 4970 | xmlSchemaParseAttrDecls(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 4971 | xmlNodePtr child, xmlSchemaTypePtr type) |
| 4972 | { |
| 4973 | xmlSchemaAttributePtr lastattr, attr; |
| 4974 | |
| 4975 | lastattr = NULL; |
| 4976 | while ((IS_SCHEMA(child, "attribute")) || |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4977 | (IS_SCHEMA(child, "attributeGroup"))) { |
| 4978 | attr = NULL; |
| 4979 | if (IS_SCHEMA(child, "attribute")) { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4980 | attr = xmlSchemaParseAttribute(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4981 | } else if (IS_SCHEMA(child, "attributeGroup")) { |
| 4982 | attr = (xmlSchemaAttributePtr) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4983 | xmlSchemaParseAttributeGroup(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4984 | } |
| 4985 | if (attr != NULL) { |
| 4986 | if (lastattr == NULL) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4987 | if (type->type == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) |
| 4988 | ((xmlSchemaAttributeGroupPtr) type)->attributes = attr; |
| 4989 | else |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4990 | type->attributes = attr; |
| 4991 | lastattr = attr; |
| 4992 | } else { |
| 4993 | lastattr->next = attr; |
| 4994 | lastattr = attr; |
| 4995 | } |
| 4996 | } |
| 4997 | child = child->next; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4998 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4999 | return (child); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5000 | } |
| 5001 | |
| 5002 | /** |
| 5003 | * xmlSchemaParseAnnotation: |
| 5004 | * @ctxt: a schema validation context |
| 5005 | * @schema: the schema being built |
| 5006 | * @node: a subtree containing XML Schema informations |
| 5007 | * |
| 5008 | * parse a XML schema Attrribute declaration |
| 5009 | * *WARNING* this interface is highly subject to change |
| 5010 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5011 | * 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] | 5012 | * 1 in case of success. |
| 5013 | */ |
| 5014 | static xmlSchemaAnnotPtr |
| 5015 | xmlSchemaParseAnnotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 5016 | xmlNodePtr node) |
| 5017 | { |
| 5018 | xmlSchemaAnnotPtr ret; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5019 | xmlNodePtr child = NULL; |
| 5020 | xmlAttrPtr attr; |
| 5021 | int barked = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5022 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5023 | /* |
| 5024 | * INFO: S4S completed. |
| 5025 | */ |
| 5026 | /* |
| 5027 | * id = ID |
| 5028 | * {any attributes with non-schema namespace . . .}> |
| 5029 | * Content: (appinfo | documentation)* |
| 5030 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5031 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5032 | return (NULL); |
| 5033 | ret = xmlSchemaNewAnnot(ctxt, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5034 | attr = node->properties; |
| 5035 | while (attr != NULL) { |
| 5036 | if (((attr->ns == NULL) && |
| 5037 | (!xmlStrEqual(attr->name, BAD_CAST "id"))) || |
| 5038 | ((attr->ns != NULL) && |
| 5039 | xmlStrEqual(attr->ns->href, xmlSchemaNs))) { |
| 5040 | |
| 5041 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5042 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5043 | NULL, NULL, attr); |
| 5044 | } |
| 5045 | attr = attr->next; |
| 5046 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 5047 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5048 | /* |
| 5049 | * And now for the children... |
| 5050 | */ |
| 5051 | child = node->children; |
| 5052 | while (child != NULL) { |
| 5053 | if (IS_SCHEMA(child, "appinfo")) { |
| 5054 | /* TODO: make available the content of "appinfo". */ |
| 5055 | /* |
| 5056 | * source = anyURI |
| 5057 | * {any attributes with non-schema namespace . . .}> |
| 5058 | * Content: ({any})* |
| 5059 | */ |
| 5060 | attr = child->properties; |
| 5061 | while (attr != NULL) { |
| 5062 | if (((attr->ns == NULL) && |
| 5063 | (!xmlStrEqual(attr->name, BAD_CAST "source"))) || |
| 5064 | ((attr->ns != NULL) && |
| 5065 | xmlStrEqual(attr->ns->href, xmlSchemaNs))) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5066 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5067 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5068 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5069 | NULL, NULL, attr); |
| 5070 | } |
| 5071 | attr = attr->next; |
| 5072 | } |
| 5073 | xmlSchemaPValAttr(ctxt, NULL, NULL, child, "source", |
| 5074 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), NULL); |
| 5075 | child = child->next; |
| 5076 | } else if (IS_SCHEMA(child, "documentation")) { |
| 5077 | /* TODO: make available the content of "documentation". */ |
| 5078 | /* |
| 5079 | * source = anyURI |
| 5080 | * {any attributes with non-schema namespace . . .}> |
| 5081 | * Content: ({any})* |
| 5082 | */ |
| 5083 | attr = child->properties; |
| 5084 | while (attr != NULL) { |
| 5085 | if (attr->ns == NULL) { |
| 5086 | if (!xmlStrEqual(attr->name, BAD_CAST "source")) { |
| 5087 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5088 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5089 | NULL, NULL, attr); |
| 5090 | } |
| 5091 | } else { |
| 5092 | if (xmlStrEqual(attr->ns->href, xmlSchemaNs) || |
| 5093 | (xmlStrEqual(attr->name, BAD_CAST "lang") && |
| 5094 | (!xmlStrEqual(attr->ns->href, XML_XML_NAMESPACE)))) { |
| 5095 | |
| 5096 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5097 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5098 | NULL, NULL, attr); |
| 5099 | } |
| 5100 | } |
| 5101 | attr = attr->next; |
| 5102 | } |
| 5103 | /* |
| 5104 | * Attribute "xml:lang". |
| 5105 | */ |
| 5106 | attr = xmlSchemaGetPropNodeNs(child, (const char *) XML_XML_NAMESPACE, "lang"); |
| 5107 | if (attr != NULL) |
| 5108 | xmlSchemaPValAttrNode(ctxt, NULL, NULL, attr, |
| 5109 | xmlSchemaGetBuiltInType(XML_SCHEMAS_LANGUAGE), NULL); |
| 5110 | child = child->next; |
| 5111 | } else { |
| 5112 | if (!barked) |
| 5113 | xmlSchemaPContentErr(ctxt, |
| 5114 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 5115 | NULL, NULL, node, child, NULL, "(appinfo | documentation)*"); |
| 5116 | barked = 1; |
| 5117 | child = child->next; |
| 5118 | } |
| 5119 | } |
| 5120 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5121 | return (ret); |
| 5122 | } |
| 5123 | |
| 5124 | /** |
| 5125 | * xmlSchemaParseFacet: |
| 5126 | * @ctxt: a schema validation context |
| 5127 | * @schema: the schema being built |
| 5128 | * @node: a subtree containing XML Schema informations |
| 5129 | * |
| 5130 | * parse a XML schema Facet declaration |
| 5131 | * *WARNING* this interface is highly subject to change |
| 5132 | * |
| 5133 | * Returns the new type structure or NULL in case of error |
| 5134 | */ |
| 5135 | static xmlSchemaFacetPtr |
| 5136 | xmlSchemaParseFacet(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5137 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5138 | { |
| 5139 | xmlSchemaFacetPtr facet; |
| 5140 | xmlNodePtr child = NULL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5141 | const xmlChar *value; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5142 | |
| 5143 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5144 | return (NULL); |
| 5145 | |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 5146 | facet = xmlSchemaNewFacet(); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5147 | if (facet == NULL) { |
| 5148 | xmlSchemaPErrMemory(ctxt, "allocating facet", node); |
| 5149 | return (NULL); |
| 5150 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5151 | facet->node = node; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5152 | value = xmlSchemaGetProp(ctxt, node, "value"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5153 | if (value == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5154 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_FACET_NO_VALUE, |
| 5155 | "Facet %s has no value\n", node->name, NULL); |
| 5156 | xmlSchemaFreeFacet(facet); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5157 | return (NULL); |
| 5158 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5159 | if (IS_SCHEMA(node, "minInclusive")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5160 | facet->type = XML_SCHEMA_FACET_MININCLUSIVE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5161 | } else if (IS_SCHEMA(node, "minExclusive")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5162 | facet->type = XML_SCHEMA_FACET_MINEXCLUSIVE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5163 | } else if (IS_SCHEMA(node, "maxInclusive")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5164 | facet->type = XML_SCHEMA_FACET_MAXINCLUSIVE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5165 | } else if (IS_SCHEMA(node, "maxExclusive")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5166 | facet->type = XML_SCHEMA_FACET_MAXEXCLUSIVE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5167 | } else if (IS_SCHEMA(node, "totalDigits")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5168 | facet->type = XML_SCHEMA_FACET_TOTALDIGITS; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5169 | } else if (IS_SCHEMA(node, "fractionDigits")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5170 | facet->type = XML_SCHEMA_FACET_FRACTIONDIGITS; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5171 | } else if (IS_SCHEMA(node, "pattern")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5172 | facet->type = XML_SCHEMA_FACET_PATTERN; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5173 | } else if (IS_SCHEMA(node, "enumeration")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5174 | facet->type = XML_SCHEMA_FACET_ENUMERATION; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5175 | } else if (IS_SCHEMA(node, "whiteSpace")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5176 | facet->type = XML_SCHEMA_FACET_WHITESPACE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5177 | } else if (IS_SCHEMA(node, "length")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5178 | facet->type = XML_SCHEMA_FACET_LENGTH; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5179 | } else if (IS_SCHEMA(node, "maxLength")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5180 | facet->type = XML_SCHEMA_FACET_MAXLENGTH; |
| 5181 | } else if (IS_SCHEMA(node, "minLength")) { |
| 5182 | facet->type = XML_SCHEMA_FACET_MINLENGTH; |
| 5183 | } else { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5184 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_TYPE, |
| 5185 | "Unknown facet type %s\n", node->name, NULL); |
| 5186 | xmlSchemaFreeFacet(facet); |
| 5187 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5188 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 5189 | xmlSchemaPValAttrID(ctxt, NULL, |
| 5190 | (xmlSchemaTypePtr) facet, node, BAD_CAST "id"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5191 | facet->value = value; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5192 | if ((facet->type != XML_SCHEMA_FACET_PATTERN) && |
| 5193 | (facet->type != XML_SCHEMA_FACET_ENUMERATION)) { |
| 5194 | const xmlChar *fixed; |
| 5195 | |
| 5196 | fixed = xmlSchemaGetProp(ctxt, node, "fixed"); |
| 5197 | if (fixed != NULL) { |
| 5198 | if (xmlStrEqual(fixed, BAD_CAST "true")) |
| 5199 | facet->fixed = 1; |
| 5200 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5201 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5202 | child = node->children; |
| 5203 | |
| 5204 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5205 | facet->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5206 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5207 | } |
| 5208 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5209 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_CHILD, |
| 5210 | "Facet %s has unexpected child content\n", |
| 5211 | node->name, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5212 | } |
| 5213 | return (facet); |
| 5214 | } |
| 5215 | |
| 5216 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5217 | * xmlSchemaParseWildcardNs: |
| 5218 | * @ctxt: a schema parser context |
| 5219 | * @wildc: the wildcard, already created |
| 5220 | * @node: a subtree containing XML Schema informations |
| 5221 | * |
| 5222 | * Parses the attribute "processContents" and "namespace" |
| 5223 | * of a xsd:anyAttribute and xsd:any. |
| 5224 | * *WARNING* this interface is highly subject to change |
| 5225 | * |
| 5226 | * Returns 0 if everything goes fine, a positive error code |
| 5227 | * if something is not valid and -1 if an internal error occurs. |
| 5228 | */ |
| 5229 | static int |
| 5230 | xmlSchemaParseWildcardNs(xmlSchemaParserCtxtPtr ctxt, |
| 5231 | xmlSchemaPtr schema, |
| 5232 | xmlSchemaWildcardPtr wildc, |
| 5233 | xmlNodePtr node) |
| 5234 | { |
| 5235 | const xmlChar *pc, *ns, *dictnsItem; |
| 5236 | int ret = 0; |
| 5237 | xmlChar *nsItem; |
| 5238 | xmlSchemaWildcardNsPtr tmp, lastNs = NULL; |
| 5239 | xmlAttrPtr attr; |
| 5240 | |
| 5241 | pc = xmlSchemaGetProp(ctxt, node, "processContents"); |
| 5242 | if ((pc == NULL) |
| 5243 | || (xmlStrEqual(pc, (const xmlChar *) "strict"))) { |
| 5244 | wildc->processContents = XML_SCHEMAS_ANY_STRICT; |
| 5245 | } else if (xmlStrEqual(pc, (const xmlChar *) "skip")) { |
| 5246 | wildc->processContents = XML_SCHEMAS_ANY_SKIP; |
| 5247 | } else if (xmlStrEqual(pc, (const xmlChar *) "lax")) { |
| 5248 | wildc->processContents = XML_SCHEMAS_ANY_LAX; |
| 5249 | } else { |
| 5250 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5251 | XML_SCHEMAP_UNKNOWN_PROCESSCONTENT_CHILD, |
| 5252 | NULL, NULL, node, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5253 | NULL, "(strict | skip | lax)", pc, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5254 | NULL, NULL, NULL); |
| 5255 | wildc->processContents = XML_SCHEMAS_ANY_STRICT; |
| 5256 | ret = XML_SCHEMAP_UNKNOWN_PROCESSCONTENT_CHILD; |
| 5257 | } |
| 5258 | /* |
| 5259 | * Build the namespace constraints. |
| 5260 | */ |
| 5261 | attr = xmlSchemaGetPropNode(node, "namespace"); |
| 5262 | ns = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 5263 | if ((ns == NULL) || (xmlStrEqual(ns, BAD_CAST "##any"))) |
| 5264 | wildc->any = 1; |
| 5265 | else if (xmlStrEqual(ns, BAD_CAST "##other")) { |
| 5266 | wildc->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 5267 | if (wildc->negNsSet == NULL) { |
| 5268 | return (-1); |
| 5269 | } |
| 5270 | wildc->negNsSet->value = schema->targetNamespace; |
| 5271 | } else { |
| 5272 | const xmlChar *end, *cur; |
| 5273 | |
| 5274 | cur = ns; |
| 5275 | do { |
| 5276 | while (IS_BLANK_CH(*cur)) |
| 5277 | cur++; |
| 5278 | end = cur; |
| 5279 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 5280 | end++; |
| 5281 | if (end == cur) |
| 5282 | break; |
| 5283 | nsItem = xmlStrndup(cur, end - cur); |
| 5284 | if ((xmlStrEqual(nsItem, BAD_CAST "##other")) || |
| 5285 | (xmlStrEqual(nsItem, BAD_CAST "##any"))) { |
| 5286 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5287 | XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER, |
| 5288 | NULL, NULL, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5289 | NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5290 | "((##any | ##other) | List of (anyURI | " |
| 5291 | "(##targetNamespace | ##local)))", |
| 5292 | nsItem, NULL, NULL, NULL); |
| 5293 | ret = XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER; |
| 5294 | } else { |
| 5295 | if (xmlStrEqual(nsItem, BAD_CAST "##targetNamespace")) { |
| 5296 | dictnsItem = schema->targetNamespace; |
| 5297 | } else if (xmlStrEqual(nsItem, BAD_CAST "##local")) { |
| 5298 | dictnsItem = NULL; |
| 5299 | } else { |
| 5300 | /* |
| 5301 | * Validate the item (anyURI). |
| 5302 | */ |
| 5303 | xmlSchemaPValAttrNodeValue(ctxt, NULL, NULL, attr, |
| 5304 | nsItem, xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI)); |
| 5305 | dictnsItem = xmlDictLookup(ctxt->dict, nsItem, -1); |
| 5306 | } |
| 5307 | /* |
| 5308 | * Avoid dublicate namespaces. |
| 5309 | */ |
| 5310 | tmp = wildc->nsSet; |
| 5311 | while (tmp != NULL) { |
| 5312 | if (dictnsItem == tmp->value) |
| 5313 | break; |
| 5314 | tmp = tmp->next; |
| 5315 | } |
| 5316 | if (tmp == NULL) { |
| 5317 | tmp = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 5318 | if (tmp == NULL) { |
| 5319 | xmlFree(nsItem); |
| 5320 | return (-1); |
| 5321 | } |
| 5322 | tmp->value = dictnsItem; |
| 5323 | tmp->next = NULL; |
| 5324 | if (wildc->nsSet == NULL) |
| 5325 | wildc->nsSet = tmp; |
| 5326 | else |
| 5327 | lastNs->next = tmp; |
| 5328 | lastNs = tmp; |
| 5329 | } |
| 5330 | |
| 5331 | } |
| 5332 | xmlFree(nsItem); |
| 5333 | cur = end; |
| 5334 | } while (*cur != 0); |
| 5335 | } |
| 5336 | return (ret); |
| 5337 | } |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5338 | |
| 5339 | static int |
| 5340 | xmlSchemaPCheckParticleCorrect_2(xmlSchemaParserCtxtPtr ctxt, |
| 5341 | xmlSchemaTypePtr item, |
| 5342 | xmlNodePtr node, |
| 5343 | int minOccurs, |
| 5344 | int maxOccurs) { |
| 5345 | |
| 5346 | if (maxOccurs != UNBOUNDED) { |
| 5347 | /* |
| 5348 | * TODO: Maby we should better not create the particle, |
| 5349 | * if min/max is invalid, since it could confuse the build of the |
| 5350 | * content model. |
| 5351 | */ |
| 5352 | /* |
| 5353 | * 3.9.6 Schema Component Constraint: Particle Correct |
| 5354 | * |
| 5355 | */ |
| 5356 | if (maxOccurs < 1) { |
| 5357 | /* |
| 5358 | * 2.2 {max occurs} must be greater than or equal to 1. |
| 5359 | */ |
| 5360 | xmlSchemaPCustomAttrErr(ctxt, |
| 5361 | XML_SCHEMAP_P_PROPS_CORRECT_2_2, |
| 5362 | NULL, item, xmlSchemaGetPropNode(node, "maxOccurs"), |
| 5363 | "The value must be greater than or equal to 1"); |
| 5364 | return (XML_SCHEMAP_P_PROPS_CORRECT_2_2); |
| 5365 | } else if (minOccurs > maxOccurs) { |
| 5366 | /* |
| 5367 | * 2.1 {min occurs} must not be greater than {max occurs}. |
| 5368 | */ |
| 5369 | xmlSchemaPCustomAttrErr(ctxt, |
| 5370 | XML_SCHEMAP_P_PROPS_CORRECT_2_1, |
| 5371 | NULL, item, xmlSchemaGetPropNode(node, "minOccurs"), |
| 5372 | "The value must not be greater than the value of 'maxOccurs'"); |
| 5373 | return (XML_SCHEMAP_P_PROPS_CORRECT_2_1); |
| 5374 | } |
| 5375 | } |
| 5376 | return (0); |
| 5377 | } |
| 5378 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5379 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5380 | * xmlSchemaParseAny: |
| 5381 | * @ctxt: a schema validation context |
| 5382 | * @schema: the schema being built |
| 5383 | * @node: a subtree containing XML Schema informations |
| 5384 | * |
| 5385 | * parse a XML schema Any declaration |
| 5386 | * *WARNING* this interface is highly subject to change |
| 5387 | * |
| 5388 | * Returns the new type structure or NULL in case of error |
| 5389 | */ |
| 5390 | static xmlSchemaTypePtr |
| 5391 | xmlSchemaParseAny(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 5392 | xmlNodePtr node) |
| 5393 | { |
| 5394 | xmlSchemaTypePtr type; |
| 5395 | xmlNodePtr child = NULL; |
| 5396 | xmlChar name[30]; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5397 | xmlSchemaWildcardPtr wildc; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5398 | int minOccurs, maxOccurs; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5399 | |
| 5400 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5401 | return (NULL); |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5402 | maxOccurs = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, |
| 5403 | "(nonNegativeInteger | unbounded)"); |
| 5404 | minOccurs = xmlGetMinOccurs(ctxt, node, 0, -1, 1, |
| 5405 | "nonNegativeInteger"); |
| 5406 | if ((minOccurs == 0) && (maxOccurs == 0)) |
| 5407 | return (NULL); |
| 5408 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 5409 | snprintf((char *) name, 30, "#any%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5410 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5411 | if (type == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5412 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5413 | type->node = node; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5414 | type->type = XML_SCHEMA_TYPE_ANY; |
| 5415 | |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 5416 | /* |
| 5417 | * TODO: Use a particle component here. |
| 5418 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5419 | wildc = xmlSchemaAddWildcard(ctxt); |
| 5420 | /* |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5421 | * Check min/max sanity. |
| 5422 | */ |
| 5423 | type->maxOccurs = maxOccurs; |
| 5424 | type->minOccurs = minOccurs; |
| 5425 | xmlSchemaPCheckParticleCorrect_2(ctxt, type, |
| 5426 | node, type->minOccurs, type->maxOccurs); |
| 5427 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5428 | * This is not nice, since it is won't be used as a attribute wildcard, |
| 5429 | * but better than adding a field to the structure. |
| 5430 | */ |
| 5431 | type->attributeWildcard = wildc; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5432 | xmlSchemaParseWildcardNs(ctxt, schema, wildc, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5433 | child = node->children; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5434 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5435 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5436 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5437 | } |
| 5438 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5439 | xmlSchemaPErr2(ctxt, node, child, |
| 5440 | XML_SCHEMAP_UNKNOWN_SEQUENCE_CHILD, |
| 5441 | "Sequence %s has unexpected content\n", type->name, |
| 5442 | NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5443 | } |
| 5444 | |
| 5445 | return (type); |
| 5446 | } |
| 5447 | |
| 5448 | /** |
| 5449 | * xmlSchemaParseNotation: |
| 5450 | * @ctxt: a schema validation context |
| 5451 | * @schema: the schema being built |
| 5452 | * @node: a subtree containing XML Schema informations |
| 5453 | * |
| 5454 | * parse a XML schema Notation declaration |
| 5455 | * |
| 5456 | * Returns the new structure or NULL in case of error |
| 5457 | */ |
| 5458 | static xmlSchemaNotationPtr |
| 5459 | xmlSchemaParseNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5460 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5461 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5462 | const xmlChar *name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5463 | xmlSchemaNotationPtr ret; |
| 5464 | xmlNodePtr child = NULL; |
| 5465 | |
| 5466 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5467 | return (NULL); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5468 | name = xmlSchemaGetProp(ctxt, node, "name"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5469 | if (name == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5470 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_NOTATION_NO_NAME, |
| 5471 | "Notation has no name\n", NULL, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5472 | return (NULL); |
| 5473 | } |
| 5474 | ret = xmlSchemaAddNotation(ctxt, schema, name); |
| 5475 | if (ret == NULL) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5476 | return (NULL); |
| 5477 | } |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 5478 | ret->targetNamespace = schema->targetNamespace; |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 5479 | |
| 5480 | xmlSchemaPValAttrID(ctxt, NULL, (xmlSchemaTypePtr) ret, |
| 5481 | node, BAD_CAST "id"); |
| 5482 | |
| 5483 | if (IS_SCHEMA(child, "annotation")) { |
| 5484 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5485 | child = child->next; |
| 5486 | } |
| 5487 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5488 | child = node->children; |
| 5489 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5490 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5491 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5492 | } |
| 5493 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5494 | xmlSchemaPErr2(ctxt, node, child, |
| 5495 | XML_SCHEMAP_UNKNOWN_NOTATION_CHILD, |
| 5496 | "notation %s has unexpected content\n", name, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5497 | } |
| 5498 | |
| 5499 | return (ret); |
| 5500 | } |
| 5501 | |
| 5502 | /** |
| 5503 | * xmlSchemaParseAnyAttribute: |
| 5504 | * @ctxt: a schema validation context |
| 5505 | * @schema: the schema being built |
| 5506 | * @node: a subtree containing XML Schema informations |
| 5507 | * |
| 5508 | * parse a XML schema AnyAttrribute declaration |
| 5509 | * *WARNING* this interface is highly subject to change |
| 5510 | * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5511 | * Returns a wildcard or NULL. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5512 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5513 | static xmlSchemaWildcardPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5514 | xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt, |
| 5515 | xmlSchemaPtr schema, xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5516 | { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5517 | xmlSchemaWildcardPtr ret; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5518 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5519 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5520 | |
| 5521 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5522 | return (NULL); |
| 5523 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5524 | ret = xmlSchemaAddWildcard(ctxt); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5525 | if (ret == NULL) { |
| 5526 | return (NULL); |
| 5527 | } |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5528 | ret->type = XML_SCHEMA_TYPE_ANY_ATTRIBUTE; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5529 | /* |
| 5530 | * Check for illegal attributes. |
| 5531 | */ |
| 5532 | attr = node->properties; |
| 5533 | while (attr != NULL) { |
| 5534 | if (attr->ns == NULL) { |
| 5535 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 5536 | (!xmlStrEqual(attr->name, BAD_CAST "namespace")) && |
| 5537 | (!xmlStrEqual(attr->name, BAD_CAST "processContents"))) { |
| 5538 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5539 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5540 | NULL, NULL, attr); |
| 5541 | } |
| 5542 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 5543 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5544 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5545 | NULL, NULL, attr); |
| 5546 | } |
| 5547 | attr = attr->next; |
| 5548 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 5549 | xmlSchemaPValAttrID(ctxt, NULL, (xmlSchemaTypePtr) ret, |
| 5550 | node, BAD_CAST "id"); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5551 | /* |
| 5552 | * Parse the namespace list. |
| 5553 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5554 | if (xmlSchemaParseWildcardNs(ctxt, schema, ret, node) != 0) { |
| 5555 | xmlSchemaFreeWildcard(ret); |
| 5556 | return (NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5557 | } |
| 5558 | /* |
| 5559 | * And now for the children... |
| 5560 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5561 | child = node->children; |
| 5562 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5563 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5564 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5565 | } |
| 5566 | if (child != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5567 | xmlSchemaPContentErr(ctxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5568 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 5569 | NULL, NULL, node, child, |
| 5570 | NULL, "(annotation?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5571 | } |
| 5572 | |
| 5573 | return (ret); |
| 5574 | } |
| 5575 | |
| 5576 | |
| 5577 | /** |
| 5578 | * xmlSchemaParseAttribute: |
| 5579 | * @ctxt: a schema validation context |
| 5580 | * @schema: the schema being built |
| 5581 | * @node: a subtree containing XML Schema informations |
| 5582 | * |
| 5583 | * parse a XML schema Attrribute declaration |
| 5584 | * *WARNING* this interface is highly subject to change |
| 5585 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5586 | * Returns the attribute declaration. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5587 | */ |
| 5588 | static xmlSchemaAttributePtr |
| 5589 | xmlSchemaParseAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5590 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5591 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5592 | const xmlChar *name, *attrValue; |
| 5593 | xmlChar *repName = NULL; /* The reported designation. */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5594 | xmlSchemaAttributePtr ret; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5595 | xmlNodePtr child = NULL; |
| 5596 | xmlAttrPtr attr, nameAttr; |
| 5597 | int isRef = 0; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5598 | |
| 5599 | /* |
| 5600 | * Note that the w3c spec assumes the schema to be validated with schema |
| 5601 | * for schemas beforehand. |
| 5602 | * |
| 5603 | * 3.2.3 Constraints on XML Representations of Attribute Declarations |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5604 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5605 | |
| 5606 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5607 | return (NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5608 | attr = xmlSchemaGetPropNode(node, "ref"); |
| 5609 | nameAttr = xmlSchemaGetPropNode(node, "name"); |
| 5610 | |
| 5611 | if ((attr == NULL) && (nameAttr == NULL)) { |
| 5612 | /* |
| 5613 | * 3.2.3 : 3.1 |
| 5614 | * One of ref or name must be present, but not both |
| 5615 | */ |
| 5616 | xmlSchemaPMissingAttrErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_3_1, |
| 5617 | (xmlChar **) &xmlSchemaElemDesAttrDecl, NULL, node, NULL, |
| 5618 | "One of the attributes 'ref' or 'name' must be present"); |
| 5619 | return (NULL); |
| 5620 | } |
| 5621 | if ((topLevel) || (attr == NULL)) { |
| 5622 | if (nameAttr == NULL) { |
| 5623 | xmlSchemaPMissingAttrErr(ctxt, XML_SCHEMAP_S4S_ATTR_MISSING, |
| 5624 | (xmlChar **) &xmlSchemaElemDesAttrDecl, NULL, node, |
| 5625 | "name", NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5626 | return (NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5627 | } |
| 5628 | } else |
| 5629 | isRef = 1; |
| 5630 | |
| 5631 | if (isRef) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5632 | char buf[50]; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5633 | const xmlChar *refNs = NULL, *ref = NULL, *refPrefix = NULL; |
| 5634 | |
| 5635 | /* |
| 5636 | * Parse as attribute reference. |
| 5637 | */ |
| 5638 | if (xmlSchemaPValAttrNodeQName(ctxt, schema, |
| 5639 | (xmlChar **) &xmlSchemaElemDesAttrRef, NULL, attr, &refNs, |
| 5640 | &refPrefix, &ref) != 0) { |
| 5641 | return (NULL); |
| 5642 | } |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 5643 | snprintf(buf, 49, "#aRef%d", ctxt->counter++ + 1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5644 | name = (const xmlChar *) buf; |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 5645 | ret = xmlSchemaAddAttribute(ctxt, schema, name, NULL, node, 0); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5646 | if (ret == NULL) { |
| 5647 | if (repName != NULL) |
| 5648 | xmlFree(repName); |
| 5649 | return (NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5650 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5651 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTE; |
| 5652 | ret->node = node; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 5653 | ret->refNs = refNs; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5654 | ret->refPrefix = refPrefix; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 5655 | ret->ref = ref; |
| 5656 | xmlSchemaCheckReference(ctxt, schema, node, (xmlSchemaTypePtr) ret, refNs); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5657 | /* |
| 5658 | xmlSchemaFormatTypeRep(&repName, (xmlSchemaTypePtr) ret, NULL, NULL); |
| 5659 | */ |
| 5660 | if (nameAttr != NULL) |
| 5661 | xmlSchemaPMutualExclAttrErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_3_1, |
| 5662 | &repName, (xmlSchemaTypePtr) ret, nameAttr, |
| 5663 | "ref", "name"); |
| 5664 | /* |
| 5665 | * Check for illegal attributes. |
| 5666 | */ |
| 5667 | attr = node->properties; |
| 5668 | while (attr != NULL) { |
| 5669 | if (attr->ns == NULL) { |
| 5670 | if (xmlStrEqual(attr->name, BAD_CAST "type") || |
| 5671 | xmlStrEqual(attr->name, BAD_CAST "form")) { |
| 5672 | /* |
| 5673 | * 3.2.3 : 3.2 |
| 5674 | * If ref is present, then all of <simpleType>, |
| 5675 | * form and type must be absent. |
| 5676 | */ |
| 5677 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5678 | XML_SCHEMAP_SRC_ATTRIBUTE_3_2, &repName, |
| 5679 | (xmlSchemaTypePtr) ret, attr); |
| 5680 | } else if ((!xmlStrEqual(attr->name, BAD_CAST "ref")) && |
| 5681 | (!xmlStrEqual(attr->name, BAD_CAST "use")) && |
| 5682 | (!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 5683 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
| 5684 | (!xmlStrEqual(attr->name, BAD_CAST "fixed")) && |
| 5685 | (!xmlStrEqual(attr->name, BAD_CAST "default"))) { |
| 5686 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5687 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5688 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 5689 | } |
| 5690 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 5691 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5692 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5693 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 5694 | } |
| 5695 | attr = attr->next; |
| 5696 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5697 | } else { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5698 | const xmlChar *ns = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5699 | |
| 5700 | /* |
| 5701 | * Parse as attribute declaration. |
| 5702 | */ |
| 5703 | if (xmlSchemaPValAttrNode(ctxt, |
| 5704 | (xmlChar **) &xmlSchemaElemDesAttrDecl, NULL, nameAttr, |
| 5705 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 5706 | return (NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5707 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5708 | /* |
| 5709 | xmlSchemaFormatTypeRep(&repName, NULL, xmlSchemaElemDesAttrDecl, name); |
| 5710 | */ |
| 5711 | /* |
| 5712 | * 3.2.6 Schema Component Constraint: xmlns Not Allowed |
| 5713 | */ |
| 5714 | if (xmlStrEqual(name, BAD_CAST "xmlns")) { |
| 5715 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5716 | XML_SCHEMAP_NO_XMLNS, |
| 5717 | &repName, NULL, (xmlNodePtr) nameAttr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5718 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), "NCName", NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5719 | "The value must not match 'xmlns'", |
| 5720 | NULL, NULL); |
| 5721 | if (repName != NULL) |
| 5722 | xmlFree(repName); |
| 5723 | return (NULL); |
| 5724 | } |
| 5725 | /* |
| 5726 | * Evaluate the target namespace |
| 5727 | */ |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5728 | if (topLevel) { |
| 5729 | ns = schema->targetNamespace; |
| 5730 | } else { |
| 5731 | attr = xmlSchemaGetPropNode(node, "form"); |
| 5732 | if (attr != NULL) { |
| 5733 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 5734 | if (xmlStrEqual(attrValue, BAD_CAST "qualified")) { |
| 5735 | ns = schema->targetNamespace; |
| 5736 | } else if (!xmlStrEqual(attrValue, BAD_CAST "unqualified")) { |
| 5737 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5738 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 5739 | &repName, NULL, (xmlNodePtr) attr, |
| 5740 | NULL, "(qualified | unqualified)", |
| 5741 | attrValue, NULL, NULL, NULL); |
| 5742 | } |
| 5743 | } else if (schema->flags & XML_SCHEMAS_QUALIF_ATTR) |
| 5744 | ns = schema->targetNamespace; |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 5745 | } |
| 5746 | ret = xmlSchemaAddAttribute(ctxt, schema, name, ns, node, topLevel); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5747 | if (ret == NULL) { |
| 5748 | if (repName != NULL) |
| 5749 | xmlFree(repName); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5750 | return (NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5751 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5752 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTE; |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 5753 | ret->node = node; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5754 | if (topLevel) |
| 5755 | ret->flags |= XML_SCHEMAS_ATTR_GLOBAL; |
| 5756 | /* |
| 5757 | * 3.2.6 Schema Component Constraint: xsi: Not Allowed |
| 5758 | */ |
| 5759 | if (xmlStrEqual(ret->targetNamespace, xmlSchemaInstanceNs)) { |
| 5760 | xmlSchemaPCustomErr(ctxt, |
| 5761 | XML_SCHEMAP_NO_XSI, |
| 5762 | &repName, (xmlSchemaTypePtr) ret, node, |
| 5763 | "The target namespace must not match '%s'", |
| 5764 | xmlSchemaInstanceNs); |
| 5765 | } |
| 5766 | /* |
| 5767 | * Check for illegal attributes. |
| 5768 | */ |
| 5769 | attr = node->properties; |
| 5770 | while (attr != NULL) { |
| 5771 | if (attr->ns == NULL) { |
| 5772 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 5773 | (!xmlStrEqual(attr->name, BAD_CAST "default")) && |
| 5774 | (!xmlStrEqual(attr->name, BAD_CAST "fixed")) && |
| 5775 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
| 5776 | (!xmlStrEqual(attr->name, BAD_CAST "type"))) { |
| 5777 | if ((topLevel) || |
| 5778 | ((!xmlStrEqual(attr->name, BAD_CAST "form")) && |
| 5779 | (!xmlStrEqual(attr->name, BAD_CAST "use")))) { |
| 5780 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5781 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5782 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 5783 | } |
| 5784 | } |
| 5785 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 5786 | xmlSchemaPIllegalAttrErr(ctxt, XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5787 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 5788 | } |
| 5789 | attr = attr->next; |
| 5790 | } |
| 5791 | xmlSchemaPValAttrQName(ctxt, schema, &repName, (xmlSchemaTypePtr) ret, |
| 5792 | node, "type", &ret->typeNs, NULL, &ret->typeName); |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 5793 | } |
| 5794 | xmlSchemaPValAttrID(ctxt, NULL, (xmlSchemaTypePtr) ret, |
| 5795 | node, BAD_CAST "id"); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5796 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5797 | * Attribute "fixed". |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5798 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5799 | ret->defValue = xmlSchemaGetProp(ctxt, node, "fixed"); |
| 5800 | if (ret->defValue != NULL) |
| 5801 | ret->flags |= XML_SCHEMAS_ATTR_FIXED; |
| 5802 | /* |
| 5803 | * Attribute "default". |
| 5804 | */ |
| 5805 | attr = xmlSchemaGetPropNode(node, "default"); |
| 5806 | if (attr != NULL) { |
| 5807 | /* |
| 5808 | * 3.2.3 : 1 |
| 5809 | * default and fixed must not both be present. |
| 5810 | */ |
| 5811 | if (ret->flags & XML_SCHEMAS_ATTR_FIXED) { |
| 5812 | xmlSchemaPMutualExclAttrErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_1, |
| 5813 | &repName, (xmlSchemaTypePtr) ret, attr, "default", "fixed"); |
| 5814 | } else |
| 5815 | ret->defValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 5816 | } |
| 5817 | if (topLevel == 0) { |
| 5818 | /* |
| 5819 | * Attribute "use". |
| 5820 | */ |
| 5821 | attr = xmlSchemaGetPropNode(node, "use"); |
| 5822 | if (attr != NULL) { |
| 5823 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 5824 | if (xmlStrEqual(attrValue, BAD_CAST "optional")) |
| 5825 | ret->occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL; |
| 5826 | else if (xmlStrEqual(attrValue, BAD_CAST "prohibited")) |
| 5827 | ret->occurs = XML_SCHEMAS_ATTR_USE_PROHIBITED; |
| 5828 | else if (xmlStrEqual(attrValue, BAD_CAST "required")) |
| 5829 | ret->occurs = XML_SCHEMAS_ATTR_USE_REQUIRED; |
| 5830 | else |
| 5831 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5832 | XML_SCHEMAP_INVALID_ATTR_USE, |
| 5833 | &repName, (xmlSchemaTypePtr) ret, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5834 | NULL, "(optional | prohibited | required)", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5835 | attrValue, NULL, NULL, NULL); |
| 5836 | } else |
| 5837 | ret->occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL; |
| 5838 | /* |
| 5839 | * 3.2.3 : 2 |
| 5840 | * If default and use are both present, use must have |
| 5841 | * the actual value optional. |
| 5842 | */ |
| 5843 | if ((ret->occurs != XML_SCHEMAS_ATTR_USE_OPTIONAL) && |
| 5844 | (ret->defValue != NULL) && |
| 5845 | ((ret->flags & XML_SCHEMAS_ATTR_FIXED) == 0)) { |
| 5846 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5847 | XML_SCHEMAP_SRC_ATTRIBUTE_2, |
| 5848 | &repName, (xmlSchemaTypePtr) ret, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5849 | NULL, "(optional | prohibited | required)", NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5850 | "The value must be 'optional' if the attribute " |
| 5851 | "'default' is present as well", NULL, NULL); |
| 5852 | } |
| 5853 | } |
| 5854 | /* |
| 5855 | * And now for the children... |
| 5856 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5857 | child = node->children; |
| 5858 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5859 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5860 | child = child->next; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5861 | } |
| 5862 | if (isRef) { |
| 5863 | if (child != NULL) { |
| 5864 | if (IS_SCHEMA(child, "simpleType")) |
| 5865 | /* |
| 5866 | * 3.2.3 : 3.2 |
| 5867 | * If ref is present, then all of <simpleType>, |
| 5868 | * form and type must be absent. |
| 5869 | */ |
| 5870 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_3_2, |
| 5871 | &repName, (xmlSchemaTypePtr) ret, node, child, NULL, |
| 5872 | "(annotation?)"); |
| 5873 | else |
| 5874 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 5875 | &repName, (xmlSchemaTypePtr) ret, node, child, NULL, |
| 5876 | "(annotation?)"); |
| 5877 | } |
| 5878 | } else { |
| 5879 | if (IS_SCHEMA(child, "simpleType")) { |
| 5880 | if (ret->typeName != NULL) { |
| 5881 | /* |
| 5882 | * 3.2.3 : 4 |
| 5883 | * type and <simpleType> must not both be present. |
| 5884 | */ |
| 5885 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_4, |
| 5886 | &repName, (xmlSchemaTypePtr) ret, node, child, |
| 5887 | "The attribute 'type' and the <simpleType> child " |
| 5888 | "are mutually exclusive", NULL); |
| 5889 | } else |
| 5890 | ret->subtypes = xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
| 5891 | child = child->next; |
| 5892 | } |
| 5893 | if (child != NULL) |
| 5894 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 5895 | &repName, (xmlSchemaTypePtr) ret, node, child, NULL, |
| 5896 | "(annotation?, simpleType?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5897 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5898 | /* |
| 5899 | * Cleanup. |
| 5900 | */ |
| 5901 | if (repName != NULL) |
| 5902 | xmlFree(repName); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5903 | return (ret); |
| 5904 | } |
| 5905 | |
| 5906 | /** |
| 5907 | * xmlSchemaParseAttributeGroup: |
| 5908 | * @ctxt: a schema validation context |
| 5909 | * @schema: the schema being built |
| 5910 | * @node: a subtree containing XML Schema informations |
| 5911 | * |
| 5912 | * parse a XML schema Attribute Group declaration |
| 5913 | * *WARNING* this interface is highly subject to change |
| 5914 | * |
| 5915 | * Returns the attribute group or NULL in case of error. |
| 5916 | */ |
| 5917 | static xmlSchemaAttributeGroupPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5918 | xmlSchemaParseAttributeGroup(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5919 | xmlSchemaPtr schema, xmlNodePtr node, |
| 5920 | int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5921 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5922 | const xmlChar *name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5923 | xmlSchemaAttributeGroupPtr ret; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5924 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5925 | const xmlChar *oldcontainer; |
| 5926 | xmlAttrPtr attr, nameAttr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5927 | |
| 5928 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5929 | return (NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5930 | |
| 5931 | nameAttr = xmlSchemaGetPropNode(node, "name"); |
| 5932 | attr = xmlSchemaGetPropNode(node, "ref"); |
| 5933 | if ((topLevel) || (attr == NULL)) { |
| 5934 | /* |
| 5935 | * Parse as an attribute group definition. |
| 5936 | * Note that those are allowed at top level only. |
| 5937 | */ |
| 5938 | if (nameAttr == NULL) { |
| 5939 | xmlSchemaPMissingAttrErr(ctxt, |
| 5940 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 5941 | NULL, NULL, node, "name", NULL); |
| 5942 | return (NULL); |
| 5943 | } |
| 5944 | name = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) nameAttr); |
| 5945 | /* |
| 5946 | * The name is crucial, exit if invalid. |
| 5947 | */ |
| 5948 | if (xmlSchemaPValAttrNode(ctxt, |
| 5949 | NULL, NULL, nameAttr, |
| 5950 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 5951 | return (NULL); |
| 5952 | } |
| 5953 | ret = xmlSchemaAddAttributeGroup(ctxt, schema, name, node); |
| 5954 | if (ret == NULL) |
| 5955 | return (NULL); |
| 5956 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTEGROUP; |
| 5957 | ret->flags |= XML_SCHEMAS_ATTRGROUP_GLOBAL; |
| 5958 | ret->node = node; |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 5959 | ret->targetNamespace = schema->targetNamespace; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5960 | } else { |
| 5961 | char buf[50]; |
| 5962 | const xmlChar *refNs = NULL, *ref = NULL, *refPrefix; |
| 5963 | |
| 5964 | /* |
| 5965 | * Parse as an attribute group definition reference. |
| 5966 | */ |
| 5967 | if (attr == NULL) { |
| 5968 | xmlSchemaPMissingAttrErr(ctxt, |
| 5969 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 5970 | NULL, NULL, node, "ref", NULL); |
| 5971 | } |
| 5972 | xmlSchemaPValAttrNodeQName(ctxt, schema, |
| 5973 | NULL, NULL, attr, &refNs, &refPrefix, &ref); |
| 5974 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 5975 | snprintf(buf, 49, "#agRef%d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5976 | name = (const xmlChar *) buf; |
| 5977 | if (name == NULL) { |
| 5978 | xmlSchemaPErrMemory(ctxt, "creating internal name for an " |
| 5979 | "attribute group definition reference", node); |
| 5980 | return (NULL); |
| 5981 | } |
| 5982 | ret = xmlSchemaAddAttributeGroup(ctxt, schema, name, node); |
| 5983 | if (ret == NULL) |
| 5984 | return (NULL); |
| 5985 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTEGROUP; |
| 5986 | ret->ref = ref; |
| 5987 | ret->refNs = refNs; |
| 5988 | /* TODO: Is @refPrefix currently used? */ |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 5989 | ret->refPrefix = refPrefix; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5990 | ret->node = node; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 5991 | xmlSchemaCheckReference(ctxt, schema, node, (xmlSchemaTypePtr) ret, refNs); |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 5992 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5993 | /* |
| 5994 | * Check for illegal attributes. |
| 5995 | */ |
| 5996 | attr = node->properties; |
| 5997 | while (attr != NULL) { |
| 5998 | if (attr->ns == NULL) { |
| 5999 | if ((((topLevel == 0) && (!xmlStrEqual(attr->name, BAD_CAST "ref"))) || |
| 6000 | (topLevel && (!xmlStrEqual(attr->name, BAD_CAST "name")))) && |
| 6001 | (!xmlStrEqual(attr->name, BAD_CAST "id"))) |
| 6002 | { |
| 6003 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6004 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6005 | NULL, NULL, attr); |
| 6006 | } |
| 6007 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 6008 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6009 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6010 | NULL, NULL, attr); |
| 6011 | } |
| 6012 | attr = attr->next; |
| 6013 | } |
| 6014 | /* TODO: Validate "id" ? */ |
| 6015 | /* |
| 6016 | * And now for the children... |
| 6017 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6018 | oldcontainer = ctxt->container; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6019 | ctxt->container = name; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6020 | child = node->children; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6021 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6022 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6023 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6024 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6025 | if (topLevel) { |
| 6026 | child = xmlSchemaParseAttrDecls(ctxt, schema, child, (xmlSchemaTypePtr) ret); |
| 6027 | if (IS_SCHEMA(child, "anyAttribute")) { |
| 6028 | ret->attributeWildcard = xmlSchemaParseAnyAttribute(ctxt, schema, child); |
| 6029 | child = child->next; |
| 6030 | } |
| 6031 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6032 | if (child != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6033 | xmlSchemaPContentErr(ctxt, |
| 6034 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 6035 | NULL, NULL, node, child, NULL, |
| 6036 | "(annotation?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6037 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6038 | ctxt->container = oldcontainer; |
| 6039 | return (ret); |
| 6040 | } |
| 6041 | |
| 6042 | /** |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6043 | * xmlSchemaPValAttrFormDefault: |
| 6044 | * @value: the value |
| 6045 | * @flags: the flags to be modified |
| 6046 | * @flagQualified: the specific flag for "qualified" |
| 6047 | * |
| 6048 | * Returns 0 if the value is valid, 1 otherwise. |
| 6049 | */ |
| 6050 | static int |
| 6051 | xmlSchemaPValAttrFormDefault(const xmlChar *value, |
| 6052 | int *flags, |
| 6053 | int flagQualified) |
| 6054 | { |
| 6055 | if (xmlStrEqual(value, BAD_CAST "qualified")) { |
| 6056 | if ((*flags & flagQualified) == 0) |
| 6057 | *flags |= flagQualified; |
| 6058 | } else if (!xmlStrEqual(value, BAD_CAST "unqualified")) |
| 6059 | return (1); |
| 6060 | |
| 6061 | return (0); |
| 6062 | } |
| 6063 | |
| 6064 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6065 | * xmlSchemaPValAttrBlockFinal: |
| 6066 | * @value: the value |
| 6067 | * @flags: the flags to be modified |
| 6068 | * @flagAll: the specific flag for "#all" |
| 6069 | * @flagExtension: the specific flag for "extension" |
| 6070 | * @flagRestriction: the specific flag for "restriction" |
| 6071 | * @flagSubstitution: the specific flag for "substitution" |
| 6072 | * @flagList: the specific flag for "list" |
| 6073 | * @flagUnion: the specific flag for "union" |
| 6074 | * |
| 6075 | * Validates the value of the attribute "final" and "block". The value |
| 6076 | * is converted into the specified flag values and returned in @flags. |
| 6077 | * |
| 6078 | * Returns 0 if the value is valid, 1 otherwise. |
| 6079 | */ |
| 6080 | |
| 6081 | static int |
| 6082 | xmlSchemaPValAttrBlockFinal(const xmlChar *value, |
| 6083 | int *flags, |
| 6084 | int flagAll, |
| 6085 | int flagExtension, |
| 6086 | int flagRestriction, |
| 6087 | int flagSubstitution, |
| 6088 | int flagList, |
| 6089 | int flagUnion) |
| 6090 | { |
| 6091 | int ret = 0; |
| 6092 | |
| 6093 | /* |
| 6094 | * TODO: This does not check for dublicate entries. |
| 6095 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6096 | if (value == NULL) |
| 6097 | return (1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6098 | if (xmlStrEqual(value, BAD_CAST "#all")) { |
| 6099 | if (flagAll != -1) |
| 6100 | *flags |= flagAll; |
| 6101 | else { |
| 6102 | if (flagExtension != -1) |
| 6103 | *flags |= flagExtension; |
| 6104 | if (flagRestriction != -1) |
| 6105 | *flags |= flagRestriction; |
| 6106 | if (flagSubstitution != -1) |
| 6107 | *flags |= flagSubstitution; |
| 6108 | if (flagList != -1) |
| 6109 | *flags |= flagList; |
| 6110 | if (flagUnion != -1) |
| 6111 | *flags |= flagUnion; |
| 6112 | } |
| 6113 | } else { |
| 6114 | const xmlChar *end, *cur = value; |
| 6115 | xmlChar *item; |
| 6116 | |
| 6117 | do { |
| 6118 | while (IS_BLANK_CH(*cur)) |
| 6119 | cur++; |
| 6120 | end = cur; |
| 6121 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 6122 | end++; |
| 6123 | if (end == cur) |
| 6124 | break; |
| 6125 | item = xmlStrndup(cur, end - cur); |
| 6126 | if (xmlStrEqual(item, BAD_CAST "extension")) { |
| 6127 | if (flagExtension != -1) { |
| 6128 | if ((*flags & flagExtension) == 0) |
| 6129 | *flags |= flagExtension; |
| 6130 | } else |
| 6131 | ret = 1; |
| 6132 | } else if (xmlStrEqual(item, BAD_CAST "restriction")) { |
| 6133 | if (flagRestriction != -1) { |
| 6134 | if ((*flags & flagRestriction) == 0) |
| 6135 | *flags |= flagRestriction; |
| 6136 | } else |
| 6137 | ret = 1; |
| 6138 | } else if (xmlStrEqual(item, BAD_CAST "substitution")) { |
| 6139 | if (flagSubstitution != -1) { |
| 6140 | if ((*flags & flagSubstitution) == 0) |
| 6141 | *flags |= flagSubstitution; |
| 6142 | } else |
| 6143 | ret = 1; |
| 6144 | } else if (xmlStrEqual(item, BAD_CAST "list")) { |
| 6145 | if (flagList != -1) { |
| 6146 | if ((*flags & flagList) == 0) |
| 6147 | *flags |= flagList; |
| 6148 | } else |
| 6149 | ret = 1; |
| 6150 | } else if (xmlStrEqual(item, BAD_CAST "union")) { |
| 6151 | if (flagUnion != -1) { |
| 6152 | if ((*flags & flagUnion) == 0) |
| 6153 | *flags |= flagUnion; |
| 6154 | } else |
| 6155 | ret = 1; |
| 6156 | } else |
| 6157 | ret = 1; |
| 6158 | if (item != NULL) |
| 6159 | xmlFree(item); |
| 6160 | cur = end; |
| 6161 | } while ((ret == 0) && (*cur != 0)); |
| 6162 | } |
| 6163 | |
| 6164 | return (ret); |
| 6165 | } |
| 6166 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 6167 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6168 | static int |
| 6169 | xmlSchemaCheckCSelectorXPath(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6170 | xmlSchemaIDCPtr idc, |
| 6171 | xmlSchemaIDCSelectPtr selector, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6172 | xmlAttrPtr attr, |
| 6173 | int isField) |
| 6174 | { |
| 6175 | xmlNodePtr node; |
| 6176 | |
| 6177 | /* |
| 6178 | * c-selector-xpath: |
| 6179 | * Schema Component Constraint: Selector Value OK |
| 6180 | * |
| 6181 | * TODO: 1 The {selector} must be a valid XPath expression, as defined |
| 6182 | * in [XPath]. |
| 6183 | */ |
| 6184 | if (selector == NULL) { |
| 6185 | xmlSchemaPErr(ctxt, idc->node, |
| 6186 | XML_SCHEMAP_INTERNAL, |
| 6187 | "Internal error: xmlSchemaCheckCSelectorXPath, " |
| 6188 | "the selector is not specified.\n", NULL, NULL); |
| 6189 | return (-1); |
| 6190 | } |
| 6191 | if (attr == NULL) |
| 6192 | node = idc->node; |
| 6193 | else |
| 6194 | node = (xmlNodePtr) attr; |
| 6195 | if (selector->xpath == NULL) { |
| 6196 | xmlSchemaPCustomErr(ctxt, |
| 6197 | /* TODO: Adjust error code. */ |
| 6198 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 6199 | NULL, NULL, node, |
| 6200 | "The XPath expression of the selector is not valid", NULL); |
| 6201 | return (XML_SCHEMAP_S4S_ATTR_INVALID_VALUE); |
| 6202 | } else { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 6203 | const xmlChar **nsArray = NULL; |
| 6204 | xmlNsPtr *nsList = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6205 | /* |
| 6206 | * Compile the XPath expression. |
| 6207 | */ |
| 6208 | /* |
| 6209 | * TODO: We need the array of in-scope namespaces for compilation. |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 6210 | * TODO: Call xmlPatterncompile with different options for selector/ |
| 6211 | * field. |
| 6212 | */ |
| 6213 | nsList = xmlGetNsList(attr->doc, attr->parent); |
| 6214 | /* |
| 6215 | * Build an array of prefixes and namespaces. |
| 6216 | */ |
| 6217 | if (nsList != NULL) { |
| 6218 | int i, count = 0; |
| 6219 | xmlNsPtr ns; |
| 6220 | |
| 6221 | for (i = 0; nsList[i] != NULL; i++) |
| 6222 | count++; |
| 6223 | |
| 6224 | nsArray = (const xmlChar **) xmlMalloc( |
| 6225 | (count * 2 + 1) * sizeof(const xmlChar *)); |
| 6226 | if (nsArray == NULL) { |
| 6227 | xmlSchemaPErrMemory(ctxt, "allocating a namespace array", |
| 6228 | NULL); |
| 6229 | return (-1); |
| 6230 | } |
| 6231 | for (i = 0; i < count; i++) { |
| 6232 | ns = nsList[i]; |
| 6233 | nsArray[2 * i] = nsList[i]->href; |
| 6234 | nsArray[2 * i + 1] = nsList[i]->prefix; |
| 6235 | } |
| 6236 | nsArray[count * 2] = NULL; |
| 6237 | xmlFree(nsList); |
| 6238 | } |
| 6239 | if (isField) |
| 6240 | selector->xpathComp = (void *) xmlPatterncompile(selector->xpath, |
Kasimier T. Buchcik | 285ebab | 2005-03-04 18:04:59 +0000 | [diff] [blame] | 6241 | NULL, 1, nsArray); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 6242 | else |
| 6243 | selector->xpathComp = (void *) xmlPatterncompile(selector->xpath, |
Kasimier T. Buchcik | 285ebab | 2005-03-04 18:04:59 +0000 | [diff] [blame] | 6244 | NULL, 1, nsArray); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 6245 | if (nsArray != NULL) |
| 6246 | xmlFree((xmlChar **) nsArray); |
| 6247 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6248 | #ifdef IDC_XPATH_SUPPORT |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 6249 | if (selector->xpathComp == NULL) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6250 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 6251 | /* TODO: Adjust error code? */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6252 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 6253 | NULL, NULL, node, |
| 6254 | "The XPath expression '%s' could not be " |
| 6255 | "compiled", selector->xpath); |
| 6256 | return (XML_SCHEMAP_S4S_ATTR_INVALID_VALUE); |
| 6257 | } |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 6258 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6259 | } |
| 6260 | return (0); |
| 6261 | } |
| 6262 | |
| 6263 | /** |
| 6264 | * xmlSchemaAssignAnnotation: |
| 6265 | * @item: the schema component |
| 6266 | * @annot: the annotation |
| 6267 | * |
| 6268 | * Adds the annotation to the given schema component. |
| 6269 | * |
| 6270 | * Returns the given annotaion. |
| 6271 | */ |
| 6272 | static xmlSchemaAnnotPtr |
| 6273 | xmlSchemaAssignAnnotation(xmlSchemaBasicItemPtr item, |
| 6274 | xmlSchemaAnnotPtr annot) |
| 6275 | { |
| 6276 | xmlSchemaAnnotPtr cur = item->annot; |
| 6277 | |
| 6278 | if (item->annot == NULL) { |
| 6279 | item->annot = annot; |
| 6280 | return (annot); |
| 6281 | } |
| 6282 | cur = item->annot; |
| 6283 | if (cur->next != NULL) { |
| 6284 | cur = cur->next; |
| 6285 | } |
| 6286 | cur->next = annot; |
| 6287 | return (annot); |
| 6288 | } |
| 6289 | |
| 6290 | /** |
| 6291 | * xmlSchemaParseIDCSelectorAndField: |
| 6292 | * @ctxt: a schema validation context |
| 6293 | * @schema: the schema being built |
| 6294 | * @node: a subtree containing XML Schema informations |
| 6295 | * |
| 6296 | * Parses a XML Schema identity-contraint definition's |
| 6297 | * <selector> and <field> elements. |
| 6298 | * |
| 6299 | * Returns the parsed identity-constraint definition. |
| 6300 | */ |
| 6301 | static xmlSchemaIDCSelectPtr |
| 6302 | xmlSchemaParseIDCSelectorAndField(xmlSchemaParserCtxtPtr ctxt, |
| 6303 | xmlSchemaPtr schema, |
| 6304 | xmlSchemaIDCPtr idc, |
| 6305 | xmlNodePtr node, |
| 6306 | int isField) |
| 6307 | { |
| 6308 | xmlSchemaIDCSelectPtr item; |
| 6309 | xmlNodePtr child = NULL; |
| 6310 | xmlAttrPtr attr; |
| 6311 | |
| 6312 | /* |
| 6313 | * Check for illegal attributes. |
| 6314 | */ |
| 6315 | attr = node->properties; |
| 6316 | while (attr != NULL) { |
| 6317 | if (attr->ns == NULL) { |
| 6318 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 6319 | (!xmlStrEqual(attr->name, BAD_CAST "xpath"))) { |
| 6320 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6321 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6322 | NULL, NULL, attr); |
| 6323 | } |
| 6324 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 6325 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6326 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6327 | NULL, NULL, attr); |
| 6328 | } |
| 6329 | attr = attr->next; |
| 6330 | } |
| 6331 | /* |
| 6332 | * Create the item. |
| 6333 | */ |
| 6334 | item = (xmlSchemaIDCSelectPtr) xmlMalloc(sizeof(xmlSchemaIDCSelect)); |
| 6335 | if (item == NULL) { |
| 6336 | xmlSchemaPErrMemory(ctxt, |
| 6337 | "allocating a 'selector' of an identity-constraint definition", |
| 6338 | NULL); |
| 6339 | return (NULL); |
| 6340 | } |
| 6341 | memset(item, 0, sizeof(xmlSchemaIDCSelect)); |
| 6342 | /* |
| 6343 | * Attribute "xpath" (mandatory). |
| 6344 | */ |
| 6345 | attr = xmlSchemaGetPropNode(node, "xpath"); |
| 6346 | if (attr == NULL) { |
| 6347 | xmlSchemaPMissingAttrErr(ctxt, |
| 6348 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 6349 | NULL, NULL, node, |
| 6350 | "name", NULL); |
| 6351 | } else { |
| 6352 | item->xpath = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 6353 | /* |
| 6354 | * URGENT TODO: "field"s have an other syntax than "selector"s. |
| 6355 | */ |
| 6356 | |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 6357 | if (xmlSchemaCheckCSelectorXPath(ctxt, idc, item, attr, |
| 6358 | isField) == -1) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6359 | xmlSchemaPErr(ctxt, |
| 6360 | (xmlNodePtr) attr, |
| 6361 | XML_SCHEMAP_INTERNAL, |
| 6362 | "Internal error: xmlSchemaParseIDCSelectorAndField, " |
| 6363 | "validating the XPath expression of a IDC selector.\n", |
| 6364 | NULL, NULL); |
| 6365 | } |
| 6366 | |
| 6367 | } |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 6368 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6369 | /* |
| 6370 | * And now for the children... |
| 6371 | */ |
| 6372 | child = node->children; |
| 6373 | if (IS_SCHEMA(child, "annotation")) { |
| 6374 | /* |
| 6375 | * Add the annotation to the parent IDC. |
| 6376 | */ |
| 6377 | xmlSchemaAssignAnnotation((xmlSchemaBasicItemPtr) idc, |
| 6378 | xmlSchemaParseAnnotation(ctxt, schema, child)); |
| 6379 | child = child->next; |
| 6380 | } |
| 6381 | if (child != NULL) { |
| 6382 | xmlSchemaPContentErr(ctxt, |
| 6383 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 6384 | NULL, NULL, node, child, |
| 6385 | NULL, "(annotation?)"); |
| 6386 | } |
| 6387 | |
| 6388 | return (item); |
| 6389 | } |
| 6390 | |
| 6391 | /** |
| 6392 | * xmlSchemaParseIDC: |
| 6393 | * @ctxt: a schema validation context |
| 6394 | * @schema: the schema being built |
| 6395 | * @node: a subtree containing XML Schema informations |
| 6396 | * |
| 6397 | * Parses a XML Schema identity-contraint definition. |
| 6398 | * |
| 6399 | * Returns the parsed identity-constraint definition. |
| 6400 | */ |
| 6401 | static xmlSchemaIDCPtr |
| 6402 | xmlSchemaParseIDC(xmlSchemaParserCtxtPtr ctxt, |
| 6403 | xmlSchemaPtr schema, |
| 6404 | xmlNodePtr node, |
| 6405 | xmlSchemaTypeType idcCategory, |
| 6406 | const xmlChar *targetNamespace) |
| 6407 | { |
| 6408 | xmlSchemaIDCPtr item = NULL; |
| 6409 | xmlNodePtr child = NULL; |
| 6410 | xmlAttrPtr attr; |
| 6411 | const xmlChar *name = NULL; |
| 6412 | xmlSchemaIDCSelectPtr field = NULL, lastField = NULL; |
| 6413 | int resAdd; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 6414 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6415 | /* |
| 6416 | * Check for illegal attributes. |
| 6417 | */ |
| 6418 | attr = node->properties; |
| 6419 | while (attr != NULL) { |
| 6420 | if (attr->ns == NULL) { |
| 6421 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 6422 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
| 6423 | ((idcCategory != XML_SCHEMA_TYPE_IDC_KEYREF) || |
| 6424 | (!xmlStrEqual(attr->name, BAD_CAST "refer")))) { |
| 6425 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6426 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6427 | NULL, NULL, attr); |
| 6428 | } |
| 6429 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 6430 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6431 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6432 | NULL, NULL, attr); |
| 6433 | } |
| 6434 | attr = attr->next; |
| 6435 | } |
| 6436 | /* |
| 6437 | * Attribute "name" (mandatory). |
| 6438 | */ |
| 6439 | attr = xmlSchemaGetPropNode(node, "name"); |
| 6440 | if (attr == NULL) { |
| 6441 | xmlSchemaPMissingAttrErr(ctxt, |
| 6442 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 6443 | NULL, NULL, node, |
| 6444 | "name", NULL); |
| 6445 | return (NULL); |
| 6446 | } else if (xmlSchemaPValAttrNode(ctxt, |
| 6447 | NULL, NULL, attr, |
| 6448 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 6449 | return (NULL); |
| 6450 | } |
| 6451 | /* |
| 6452 | * Create the component. |
| 6453 | */ |
| 6454 | if (schema->idcDef == NULL) |
| 6455 | schema->idcDef = xmlHashCreateDict(10, ctxt->dict); |
| 6456 | if (schema->idcDef == NULL) |
| 6457 | return (NULL); |
| 6458 | |
| 6459 | item = (xmlSchemaIDCPtr) xmlMalloc(sizeof(xmlSchemaIDC)); |
| 6460 | if (item == NULL) { |
| 6461 | xmlSchemaPErrMemory(ctxt, |
| 6462 | "allocating an identity-constraint definition", NULL); |
| 6463 | return (NULL); |
| 6464 | } |
| 6465 | /* |
| 6466 | * Add the IDC to the list of IDCs on the schema component. |
| 6467 | */ |
| 6468 | resAdd = xmlHashAddEntry2(schema->idcDef, name, targetNamespace, item); |
| 6469 | if (resAdd != 0) { |
| 6470 | xmlSchemaPCustomErrExt(ctxt, |
| 6471 | XML_SCHEMAP_REDEFINED_TYPE, |
| 6472 | NULL, NULL, node, |
| 6473 | "An identity-constraint definition with the name '%s' " |
| 6474 | "and targetNamespace '%s' does already exist", |
| 6475 | name, targetNamespace, NULL); |
| 6476 | xmlFree(item); |
| 6477 | return (NULL); |
| 6478 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6479 | memset(item, 0, sizeof(xmlSchemaIDC)); |
| 6480 | item->name = name; |
| 6481 | item->type = idcCategory; |
| 6482 | item->node = node; |
| 6483 | /* |
| 6484 | * The target namespace of the parent element declaration. |
| 6485 | */ |
| 6486 | item->targetNamespace = targetNamespace; |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 6487 | xmlSchemaPValAttrID(ctxt, NULL, (xmlSchemaTypePtr) item, |
| 6488 | node, BAD_CAST "id"); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6489 | if (idcCategory == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 6490 | /* |
| 6491 | * Attribute "refer" (mandatory). |
| 6492 | */ |
| 6493 | attr = xmlSchemaGetPropNode(node, "refer"); |
| 6494 | if (attr == NULL) { |
| 6495 | xmlSchemaPMissingAttrErr(ctxt, |
| 6496 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 6497 | NULL, NULL, node, |
| 6498 | "refer", NULL); |
| 6499 | } else { |
| 6500 | /* |
| 6501 | * Create a reference item. |
| 6502 | */ |
| 6503 | item->ref = (xmlSchemaItemQNRefPtr) xmlMalloc( |
| 6504 | sizeof(xmlSchemaItemQNRef)); |
| 6505 | if (item->ref == NULL) { |
| 6506 | xmlSchemaPErrMemory(ctxt, |
| 6507 | "allocating a QName reference item", NULL); |
| 6508 | return (NULL); |
| 6509 | } |
| 6510 | memset(item->ref, 0, sizeof(xmlSchemaItemQNRef)); |
| 6511 | xmlSchemaPValAttrNodeQName(ctxt, schema, |
| 6512 | NULL, NULL, attr, |
| 6513 | &(item->ref->targetNamespace), 0, |
| 6514 | &(item->ref->name)); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 6515 | xmlSchemaCheckReference(ctxt, schema, node, (xmlSchemaTypePtr) item, |
| 6516 | item->ref->targetNamespace); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6517 | } |
| 6518 | } |
| 6519 | /* |
| 6520 | * And now for the children... |
| 6521 | */ |
| 6522 | child = node->children; |
| 6523 | if (IS_SCHEMA(child, "annotation")) { |
| 6524 | item->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6525 | child = child->next; |
| 6526 | } |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 6527 | if (child == NULL) { |
| 6528 | xmlSchemaPContentErr(ctxt, |
| 6529 | XML_SCHEMAP_S4S_ELEM_MISSING, |
| 6530 | NULL, NULL, node, child, |
| 6531 | "A child element is missing", |
| 6532 | "(annotation?, (selector, field+))"); |
| 6533 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6534 | /* |
| 6535 | * Child element <selector>. |
| 6536 | */ |
| 6537 | if (IS_SCHEMA(child, "selector")) { |
| 6538 | item->selector = xmlSchemaParseIDCSelectorAndField(ctxt, schema, |
| 6539 | item, child, 0); |
| 6540 | child = child->next; |
| 6541 | /* |
| 6542 | * Child elements <field>. |
| 6543 | */ |
| 6544 | if (IS_SCHEMA(child, "field")) { |
| 6545 | do { |
| 6546 | field = xmlSchemaParseIDCSelectorAndField(ctxt, schema, |
| 6547 | item, child, 1); |
| 6548 | if (field != NULL) { |
| 6549 | field->index = item->nbFields; |
| 6550 | item->nbFields++; |
| 6551 | if (lastField != NULL) |
| 6552 | lastField->next = field; |
| 6553 | else |
| 6554 | item->fields = field; |
| 6555 | lastField = field; |
| 6556 | } |
| 6557 | child = child->next; |
| 6558 | } while (IS_SCHEMA(child, "field")); |
| 6559 | } else { |
| 6560 | xmlSchemaPContentErr(ctxt, |
| 6561 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 6562 | NULL, NULL, node, child, |
| 6563 | NULL, "(annotation?, (selector, field+))"); |
| 6564 | } |
| 6565 | } |
| 6566 | if (child != NULL) { |
| 6567 | xmlSchemaPContentErr(ctxt, |
| 6568 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 6569 | NULL, NULL, node, child, |
| 6570 | NULL, "(annotation?, (selector, field+))"); |
| 6571 | } |
| 6572 | |
| 6573 | return (item); |
| 6574 | } |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 6575 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6576 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6577 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6578 | * xmlSchemaParseElement: |
| 6579 | * @ctxt: a schema validation context |
| 6580 | * @schema: the schema being built |
| 6581 | * @node: a subtree containing XML Schema informations |
| 6582 | * |
| 6583 | * parse a XML schema Element declaration |
| 6584 | * *WARNING* this interface is highly subject to change |
| 6585 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6586 | * Returns the parsed element declaration. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6587 | */ |
| 6588 | static xmlSchemaElementPtr |
| 6589 | xmlSchemaParseElement(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6590 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6591 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6592 | const xmlChar *name = NULL; |
| 6593 | const xmlChar *attrValue; |
| 6594 | xmlChar *repName = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6595 | xmlSchemaElementPtr ret; |
| 6596 | xmlNodePtr child = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6597 | const xmlChar *oldcontainer; |
| 6598 | xmlAttrPtr attr, nameAttr; |
| 6599 | int minOccurs, maxOccurs; |
| 6600 | int isRef = 0; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6601 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 6602 | xmlSchemaIDCPtr curIDC = NULL, lastIDC = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6603 | #endif |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6604 | |
| 6605 | /* 3.3.3 Constraints on XML Representations of Element Declarations */ |
| 6606 | /* TODO: Complete implementation of 3.3.6 */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6607 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6608 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 6609 | return (NULL); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 6610 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6611 | oldcontainer = ctxt->container; |
| 6612 | |
| 6613 | nameAttr = xmlSchemaGetPropNode(node, "name"); |
| 6614 | attr = xmlSchemaGetPropNode(node, "ref"); |
| 6615 | if ((topLevel) || (attr == NULL)) { |
| 6616 | if (nameAttr == NULL) { |
| 6617 | xmlSchemaPMissingAttrErr(ctxt, |
| 6618 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 6619 | (xmlChar **) &xmlSchemaElemDesElemDecl, NULL, node, |
| 6620 | "name", NULL); |
| 6621 | return (NULL); |
| 6622 | } |
| 6623 | name = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) nameAttr); |
| 6624 | } else { |
| 6625 | isRef = 1; |
| 6626 | |
| 6627 | } |
| 6628 | /* |
| 6629 | * ... unless minOccurs=maxOccurs=0, in which case the item corresponds |
| 6630 | * to no component at all |
| 6631 | * TODO: It might be better to validate the element, even if it won't be |
| 6632 | * used. |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6633 | */ |
| 6634 | minOccurs = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "nonNegativeInteger"); |
| 6635 | maxOccurs = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, "(nonNegativeInteger | unbounded)"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6636 | if ((minOccurs == 0) && (maxOccurs == 0)) |
| 6637 | return (NULL); |
| 6638 | /* |
| 6639 | * If we get a "ref" attribute on a local <element> we will assume it's |
| 6640 | * a reference - even if there's a "name" attribute; this seems to be more |
| 6641 | * robust. |
| 6642 | */ |
| 6643 | if (isRef) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6644 | char buf[50]; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6645 | const xmlChar *refNs = NULL, *ref = NULL, *refPrefix; |
| 6646 | |
| 6647 | /* |
| 6648 | * Parse as a particle. |
| 6649 | */ |
| 6650 | xmlSchemaPValAttrNodeQName(ctxt, schema, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6651 | (xmlChar **) &xmlSchemaElemDesElemRef, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6652 | NULL, attr, &refNs, &refPrefix, &ref); |
| 6653 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 6654 | snprintf(buf, 49, "#eRef%d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 6655 | ret = xmlSchemaAddElement(ctxt, schema, (const xmlChar *) buf, NULL, node, 0); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6656 | if (ret == NULL) { |
| 6657 | if (repName != NULL) |
| 6658 | xmlFree(repName); |
| 6659 | return (NULL); |
| 6660 | } |
| 6661 | ret->type = XML_SCHEMA_TYPE_ELEMENT; |
| 6662 | ret->node = node; |
| 6663 | ret->ref = ref; |
| 6664 | ret->refNs = refNs; |
| 6665 | ret->refPrefix = refPrefix; |
| 6666 | ret->flags |= XML_SCHEMAS_ELEM_REF; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 6667 | xmlSchemaCheckReference(ctxt, schema, node, (xmlSchemaTypePtr) ret, refNs); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6668 | /* |
| 6669 | * Check for illegal attributes. |
| 6670 | */ |
| 6671 | /* |
| 6672 | * 3.3.3 : 2.1 |
| 6673 | * One of ref or name must be present, but not both |
| 6674 | */ |
| 6675 | if (nameAttr != NULL) { |
| 6676 | xmlSchemaPMutualExclAttrErr(ctxt, |
| 6677 | XML_SCHEMAP_SRC_ELEMENT_2_1, |
| 6678 | &repName, (xmlSchemaTypePtr) ret, nameAttr, |
| 6679 | "ref", "name"); |
| 6680 | } |
| 6681 | /* 3.3.3 : 2.2 */ |
| 6682 | attr = node->properties; |
| 6683 | while (attr != NULL) { |
| 6684 | if (attr->ns == NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6685 | if (xmlStrEqual(attr->name, BAD_CAST "ref") || |
| 6686 | xmlStrEqual(attr->name, BAD_CAST "name") || |
| 6687 | xmlStrEqual(attr->name, BAD_CAST "id") || |
| 6688 | xmlStrEqual(attr->name, BAD_CAST "maxOccurs") || |
| 6689 | xmlStrEqual(attr->name, BAD_CAST "minOccurs")) |
| 6690 | { |
| 6691 | attr = attr->next; |
| 6692 | continue; |
| 6693 | } else { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6694 | xmlSchemaPCustomAttrErr(ctxt, |
| 6695 | XML_SCHEMAP_SRC_ELEMENT_2_2, |
| 6696 | &repName, (xmlSchemaTypePtr) ret, attr, |
| 6697 | "Only the attributes 'minOccurs', 'maxOccurs' and " |
| 6698 | "'id' are allowed in addition to 'ref'"); |
| 6699 | break; |
| 6700 | } |
| 6701 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 6702 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6703 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6704 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 6705 | } |
| 6706 | attr = attr->next; |
| 6707 | } |
| 6708 | } else { |
| 6709 | const xmlChar *ns = NULL, *fixed; |
| 6710 | |
| 6711 | /* |
| 6712 | * Parse as an element declaration. |
| 6713 | */ |
| 6714 | if (xmlSchemaPValAttrNode(ctxt, |
| 6715 | (xmlChar **) &xmlSchemaElemDesElemDecl, NULL, nameAttr, |
| 6716 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) |
| 6717 | return (NULL); |
| 6718 | /* |
| 6719 | * Evaluate the target namespace. |
| 6720 | */ |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6721 | if (topLevel) { |
| 6722 | ns = schema->targetNamespace; |
| 6723 | } else { |
| 6724 | attr = xmlSchemaGetPropNode(node, "form"); |
| 6725 | if (attr != NULL) { |
| 6726 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 6727 | if (xmlStrEqual(attrValue, BAD_CAST "qualified")) { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6728 | ns = schema->targetNamespace; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6729 | } else if (!xmlStrEqual(attrValue, BAD_CAST "unqualified")) { |
| 6730 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6731 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 6732 | &repName, NULL, (xmlNodePtr) attr, |
| 6733 | NULL, "(qualified | unqualified)", |
| 6734 | attrValue, NULL, NULL, NULL); |
| 6735 | } |
| 6736 | } else if (schema->flags & XML_SCHEMAS_QUALIF_ELEM) |
| 6737 | ns = schema->targetNamespace; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6738 | } |
| 6739 | ret = xmlSchemaAddElement(ctxt, schema, name, ns, node, topLevel); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6740 | if (ret == NULL) { |
| 6741 | if (repName != NULL) |
| 6742 | xmlFree(repName); |
| 6743 | return (NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6744 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6745 | ret->type = XML_SCHEMA_TYPE_ELEMENT; |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 6746 | ret->node = node; |
| 6747 | ret->targetNamespace = ns; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6748 | /* |
| 6749 | * Check for illegal attributes. |
| 6750 | */ |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6751 | attr = node->properties; |
| 6752 | while (attr != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6753 | if (attr->ns == NULL) { |
| 6754 | if ((!xmlStrEqual(attr->name, BAD_CAST "name")) && |
| 6755 | (!xmlStrEqual(attr->name, BAD_CAST "type")) && |
| 6756 | (!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 6757 | (!xmlStrEqual(attr->name, BAD_CAST "default")) && |
| 6758 | (!xmlStrEqual(attr->name, BAD_CAST "fixed")) && |
| 6759 | (!xmlStrEqual(attr->name, BAD_CAST "block")) && |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6760 | (!xmlStrEqual(attr->name, BAD_CAST "nillable"))) |
| 6761 | { |
| 6762 | if (topLevel == 0) { |
| 6763 | if ((!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) && |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6764 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) && |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6765 | (!xmlStrEqual(attr->name, BAD_CAST "form"))) |
| 6766 | { |
| 6767 | if (xmlStrEqual(attr->name, BAD_CAST "substitutionGroup")) { |
| 6768 | /* |
| 6769 | * 3.3.6 : 3 If there is a non-·absent· {substitution |
| 6770 | * group affiliation}, then {scope} must be global. |
| 6771 | * TODO: This one is redundant, since the S4S does |
| 6772 | * prohibit this attribute on local declarations already; |
| 6773 | * so why an explicit error code? Weird spec. |
| 6774 | * TODO: Move this to the proper constraint layer. |
| 6775 | * TODO: Or better wait for spec 1.1 to come. |
| 6776 | */ |
| 6777 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6778 | XML_SCHEMAP_E_PROPS_CORRECT_3, |
| 6779 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 6780 | } else { |
| 6781 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6782 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6783 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 6784 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6785 | } |
| 6786 | } else if ((!xmlStrEqual(attr->name, BAD_CAST "final")) && |
| 6787 | (!xmlStrEqual(attr->name, BAD_CAST "abstract")) && |
| 6788 | (!xmlStrEqual(attr->name, BAD_CAST "substitutionGroup"))) { |
| 6789 | |
| 6790 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6791 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6792 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 6793 | } |
| 6794 | } |
| 6795 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 6796 | |
| 6797 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6798 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6799 | &repName, (xmlSchemaTypePtr) ret, attr); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6800 | } |
| 6801 | attr = attr->next; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6802 | } |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6803 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6804 | * Extract/validate attributes. |
| 6805 | */ |
| 6806 | if (topLevel) { |
| 6807 | /* |
| 6808 | * Process top attributes of global element declarations here. |
| 6809 | */ |
| 6810 | ret->flags |= XML_SCHEMAS_ELEM_GLOBAL; |
| 6811 | ret->flags |= XML_SCHEMAS_ELEM_TOPLEVEL; |
| 6812 | xmlSchemaPValAttrQName(ctxt, schema, &repName, |
| 6813 | (xmlSchemaTypePtr) ret, node, "substitutionGroup", |
| 6814 | &(ret->substGroupNs), NULL, &(ret->substGroup)); |
| 6815 | if (xmlGetBooleanProp(ctxt, &repName, (xmlSchemaTypePtr) ret, |
| 6816 | node, "abstract", 0)) |
| 6817 | ret->flags |= XML_SCHEMAS_ELEM_ABSTRACT; |
| 6818 | /* |
| 6819 | * Attribute "final". |
| 6820 | */ |
| 6821 | attr = xmlSchemaGetPropNode(node, "final"); |
| 6822 | if (attr == NULL) { |
| 6823 | ret->flags |= XML_SCHEMAS_ELEM_FINAL_ABSENT; |
| 6824 | } else { |
| 6825 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 6826 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(ret->flags), |
| 6827 | -1, |
| 6828 | XML_SCHEMAS_ELEM_FINAL_EXTENSION, |
| 6829 | XML_SCHEMAS_ELEM_FINAL_RESTRICTION, -1, -1, -1) != 0) { |
| 6830 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6831 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 6832 | &repName, (xmlSchemaTypePtr) ret, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6833 | NULL, "(#all | List of (extension | restriction))", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6834 | attrValue, NULL, NULL, NULL); |
| 6835 | } |
| 6836 | } |
| 6837 | } |
| 6838 | /* |
| 6839 | * Attribute "block". |
| 6840 | */ |
| 6841 | attr = xmlSchemaGetPropNode(node, "block"); |
| 6842 | if (attr == NULL) { |
| 6843 | ret->flags |= XML_SCHEMAS_ELEM_BLOCK_ABSENT; |
| 6844 | } else { |
| 6845 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 6846 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(ret->flags), |
| 6847 | -1, |
| 6848 | XML_SCHEMAS_ELEM_BLOCK_EXTENSION, |
| 6849 | XML_SCHEMAS_ELEM_BLOCK_RESTRICTION, |
| 6850 | XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION, -1, -1) != 0) { |
| 6851 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6852 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 6853 | &repName, (xmlSchemaTypePtr) ret, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6854 | NULL, "(#all | List of (extension | " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6855 | "restriction | substitution))", attrValue, |
| 6856 | NULL, NULL, NULL); |
| 6857 | } |
| 6858 | } |
| 6859 | if (xmlGetBooleanProp(ctxt, &repName, (xmlSchemaTypePtr) ret, |
| 6860 | node, "nillable", 0)) |
| 6861 | ret->flags |= XML_SCHEMAS_ELEM_NILLABLE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6862 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6863 | xmlSchemaPValAttrQName(ctxt, schema, |
| 6864 | &repName, (xmlSchemaTypePtr) ret, node, |
| 6865 | "type", &(ret->namedTypeNs), NULL, &(ret->namedType)); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6866 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6867 | ret->value = xmlSchemaGetProp(ctxt, node, "default"); |
| 6868 | attr = xmlSchemaGetPropNode(node, "fixed"); |
| 6869 | if (attr != NULL) { |
| 6870 | fixed = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 6871 | if (ret->value != NULL) { |
| 6872 | /* |
| 6873 | * 3.3.3 : 1 |
| 6874 | * default and fixed must not both be present. |
| 6875 | */ |
| 6876 | xmlSchemaPMutualExclAttrErr(ctxt, |
| 6877 | XML_SCHEMAP_SRC_ELEMENT_1, |
| 6878 | &repName, (xmlSchemaTypePtr) ret, attr, |
| 6879 | "default", "fixed"); |
| 6880 | } else { |
| 6881 | ret->flags |= XML_SCHEMAS_ELEM_FIXED; |
| 6882 | ret->value = fixed; |
| 6883 | } |
| 6884 | } |
| 6885 | } |
| 6886 | /* |
| 6887 | * Extract/validate common attributes. |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 6888 | */ |
| 6889 | xmlSchemaPValAttrID(ctxt, NULL, (xmlSchemaTypePtr) ret, |
| 6890 | node, BAD_CAST "id"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6891 | ret->minOccurs = minOccurs; |
| 6892 | ret->maxOccurs = maxOccurs; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6893 | if (topLevel != 1) |
| 6894 | xmlSchemaPCheckParticleCorrect_2(ctxt, (xmlSchemaTypePtr) ret, |
| 6895 | node, minOccurs, maxOccurs); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6896 | /* |
| 6897 | * And now for the children... |
| 6898 | */ |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 6899 | ctxt->container = ret->name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6900 | child = node->children; |
| 6901 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6902 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6903 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6904 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6905 | if (isRef) { |
| 6906 | if (child != NULL) { |
| 6907 | xmlSchemaPContentErr(ctxt, |
| 6908 | XML_SCHEMAP_SRC_ELEMENT_2_2, |
| 6909 | &repName, (xmlSchemaTypePtr) ret, node, child, |
| 6910 | NULL, "(annotation?)"); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6911 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6912 | } else { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6913 | if (IS_SCHEMA(child, "complexType")) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6914 | /* |
| 6915 | * 3.3.3 : 3 |
| 6916 | * "type" and either <simpleType> or <complexType> are mutually |
| 6917 | * exclusive |
| 6918 | */ |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6919 | if (ret->namedType != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6920 | xmlSchemaPContentErr(ctxt, |
| 6921 | XML_SCHEMAP_SRC_ELEMENT_3, |
| 6922 | &repName, (xmlSchemaTypePtr) ret, node, child, |
| 6923 | "The attribute 'type' and the <complexType> child are " |
| 6924 | "mutually exclusive", NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6925 | } else |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6926 | ret->subtypes = xmlSchemaParseComplexType(ctxt, schema, child, 0); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6927 | child = child->next; |
| 6928 | } else if (IS_SCHEMA(child, "simpleType")) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6929 | /* |
| 6930 | * 3.3.3 : 3 |
| 6931 | * "type" and either <simpleType> or <complexType> are |
| 6932 | * mutually exclusive |
| 6933 | */ |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6934 | if (ret->namedType != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6935 | xmlSchemaPContentErr(ctxt, |
| 6936 | XML_SCHEMAP_SRC_ELEMENT_3, |
| 6937 | &repName, (xmlSchemaTypePtr) ret, node, child, |
| 6938 | "The attribute 'type' and the <simpleType> child are " |
| 6939 | "mutually exclusive", NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6940 | } else |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6941 | ret->subtypes = xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6942 | child = child->next; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6943 | } |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6944 | while ((IS_SCHEMA(child, "unique")) || |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6945 | (IS_SCHEMA(child, "key")) || (IS_SCHEMA(child, "keyref"))) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6946 | #ifdef IDC_ENABLED |
| 6947 | if (IS_SCHEMA(child, "unique")) { |
| 6948 | curIDC = xmlSchemaParseIDC(ctxt, schema, child, |
| 6949 | XML_SCHEMA_TYPE_IDC_UNIQUE, ret->targetNamespace); |
| 6950 | } else if (IS_SCHEMA(child, "key")) { |
| 6951 | curIDC = xmlSchemaParseIDC(ctxt, schema, child, |
| 6952 | XML_SCHEMA_TYPE_IDC_KEY, ret->targetNamespace); |
| 6953 | } else if (IS_SCHEMA(child, "keyref")) { |
| 6954 | curIDC = xmlSchemaParseIDC(ctxt, schema, child, |
| 6955 | XML_SCHEMA_TYPE_IDC_KEYREF, ret->targetNamespace); |
| 6956 | } |
| 6957 | if (lastIDC != NULL) |
| 6958 | lastIDC->next = curIDC; |
| 6959 | else |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 6960 | ret->idcs = (void *) curIDC; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6961 | lastIDC = curIDC; |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 6962 | #else |
| 6963 | TODO |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6964 | #endif |
| 6965 | child = child->next; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6966 | } |
| 6967 | if (child != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6968 | xmlSchemaPContentErr(ctxt, |
| 6969 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 6970 | &repName, (xmlSchemaTypePtr) ret, node, child, |
| 6971 | NULL, "(annotation?, ((simpleType | complexType)?, " |
| 6972 | "(unique | key | keyref)*))"); |
| 6973 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6974 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6975 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6976 | ctxt->container = oldcontainer; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6977 | /* |
| 6978 | * Cleanup. |
| 6979 | */ |
| 6980 | if (repName != NULL) |
| 6981 | xmlFree(repName); |
| 6982 | /* |
| 6983 | * NOTE: Element Declaration Representation OK 4. will be checked at a |
| 6984 | * different layer. |
| 6985 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6986 | return (ret); |
| 6987 | } |
| 6988 | |
| 6989 | /** |
| 6990 | * xmlSchemaParseUnion: |
| 6991 | * @ctxt: a schema validation context |
| 6992 | * @schema: the schema being built |
| 6993 | * @node: a subtree containing XML Schema informations |
| 6994 | * |
| 6995 | * parse a XML schema Union definition |
| 6996 | * *WARNING* this interface is highly subject to change |
| 6997 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6998 | * 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] | 6999 | * 1 in case of success. |
| 7000 | */ |
| 7001 | static xmlSchemaTypePtr |
| 7002 | xmlSchemaParseUnion(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7003 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7004 | { |
| 7005 | xmlSchemaTypePtr type, subtype, last = NULL; |
| 7006 | xmlNodePtr child = NULL; |
| 7007 | xmlChar name[30]; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7008 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7009 | |
| 7010 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 7011 | return (NULL); |
| 7012 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 7013 | snprintf((char *) name, 30, "#union%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7014 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7015 | if (type == NULL) |
| 7016 | return (NULL); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 7017 | type->type = XML_SCHEMA_TYPE_UNION; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7018 | type->node = node; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7019 | /* |
| 7020 | * Check for illegal attributes. |
| 7021 | */ |
| 7022 | attr = node->properties; |
| 7023 | while (attr != NULL) { |
| 7024 | if (attr->ns == NULL) { |
| 7025 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 7026 | (!xmlStrEqual(attr->name, BAD_CAST "memberTypes"))) { |
| 7027 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7028 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7029 | NULL, type, attr); |
| 7030 | } |
| 7031 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 7032 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7033 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7034 | NULL, type, attr); |
| 7035 | } |
| 7036 | attr = attr->next; |
| 7037 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 7038 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7039 | /* |
| 7040 | * Attribute "memberTypes". This is a list of QNames. |
| 7041 | * TODO: Validate the QNames. |
| 7042 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7043 | type->base = xmlSchemaGetProp(ctxt, node, "memberTypes"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7044 | /* |
| 7045 | * And now for the children... |
| 7046 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7047 | child = node->children; |
| 7048 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7049 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7050 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7051 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7052 | while (IS_SCHEMA(child, "simpleType")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7053 | subtype = (xmlSchemaTypePtr) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 7054 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7055 | if (subtype != NULL) { |
| 7056 | if (last == NULL) { |
| 7057 | type->subtypes = subtype; |
| 7058 | last = subtype; |
| 7059 | } else { |
| 7060 | last->next = subtype; |
| 7061 | last = subtype; |
| 7062 | } |
| 7063 | last->next = NULL; |
| 7064 | } |
| 7065 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7066 | } |
| 7067 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7068 | /* TODO: Think about the error code. */ |
| 7069 | xmlSchemaPContentErr(ctxt, |
| 7070 | XML_SCHEMAP_UNKNOWN_UNION_CHILD, |
| 7071 | NULL, type, node, child, NULL, "(annotation?, simpleType*)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7072 | } |
| 7073 | return (type); |
| 7074 | } |
| 7075 | |
| 7076 | /** |
| 7077 | * xmlSchemaParseList: |
| 7078 | * @ctxt: a schema validation context |
| 7079 | * @schema: the schema being built |
| 7080 | * @node: a subtree containing XML Schema informations |
| 7081 | * |
| 7082 | * parse a XML schema List definition |
| 7083 | * *WARNING* this interface is highly subject to change |
| 7084 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7085 | * 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] | 7086 | * 1 in case of success. |
| 7087 | */ |
| 7088 | static xmlSchemaTypePtr |
| 7089 | xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7090 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7091 | { |
| 7092 | xmlSchemaTypePtr type, subtype; |
| 7093 | xmlNodePtr child = NULL; |
| 7094 | xmlChar name[30]; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7095 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7096 | |
| 7097 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 7098 | return (NULL); |
| 7099 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 7100 | snprintf((char *) name, 30, "#list%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7101 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7102 | if (type == NULL) |
| 7103 | return (NULL); |
| 7104 | type->node = node; |
| 7105 | type->type = XML_SCHEMA_TYPE_LIST; |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 7106 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7107 | /* |
| 7108 | * Check for illegal attributes. |
| 7109 | */ |
| 7110 | attr = node->properties; |
| 7111 | while (attr != NULL) { |
| 7112 | if (attr->ns == NULL) { |
| 7113 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 7114 | (!xmlStrEqual(attr->name, BAD_CAST "itemType"))) { |
| 7115 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7116 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7117 | NULL, type, attr); |
| 7118 | } |
| 7119 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 7120 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7121 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7122 | NULL, type, attr); |
| 7123 | } |
| 7124 | attr = attr->next; |
| 7125 | } |
| 7126 | /* |
| 7127 | * Attribute "itemType". |
| 7128 | */ |
| 7129 | xmlSchemaPValAttrQName(ctxt, schema, NULL, NULL, |
| 7130 | node, "itemType", &(type->baseNs), NULL, &(type->base)); |
| 7131 | /* |
| 7132 | * And now for the children... |
| 7133 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7134 | child = node->children; |
| 7135 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7136 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7137 | child = child->next; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7138 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7139 | subtype = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7140 | if (IS_SCHEMA(child, "simpleType")) { |
| 7141 | if (type->base != NULL) { |
| 7142 | xmlSchemaPCustomErr(ctxt, |
| 7143 | XML_SCHEMAP_SRC_SIMPLE_TYPE_1, |
| 7144 | NULL, type, node, |
| 7145 | "The attribute 'itemType' and the <simpleType> child " |
| 7146 | "are mutually exclusive", NULL); |
| 7147 | } else { |
| 7148 | subtype = (xmlSchemaTypePtr) |
| 7149 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
| 7150 | type->subtypes = subtype; |
| 7151 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7152 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7153 | } |
| 7154 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7155 | /* TODO: Think about the error code. */ |
| 7156 | xmlSchemaPContentErr(ctxt, |
| 7157 | XML_SCHEMAP_UNKNOWN_LIST_CHILD, |
| 7158 | NULL, type, node, child, NULL, "(annotation?, simpleType?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7159 | } |
| 7160 | return (type); |
| 7161 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7162 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7163 | /** |
| 7164 | * xmlSchemaParseSimpleType: |
| 7165 | * @ctxt: a schema validation context |
| 7166 | * @schema: the schema being built |
| 7167 | * @node: a subtree containing XML Schema informations |
| 7168 | * |
| 7169 | * parse a XML schema Simple Type definition |
| 7170 | * *WARNING* this interface is highly subject to change |
| 7171 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7172 | * 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] | 7173 | * 1 in case of success. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7174 | */ |
| 7175 | static xmlSchemaTypePtr |
| 7176 | xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 7177 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7178 | { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7179 | xmlSchemaTypePtr type, subtype, oldCtxtType, oldParentItem; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7180 | xmlNodePtr child = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7181 | const xmlChar *attrValue = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7182 | xmlChar *des = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7183 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7184 | |
| 7185 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 7186 | return (NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7187 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7188 | if (topLevel) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7189 | attr = xmlSchemaGetPropNode(node, "name"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7190 | if (attr == NULL) { |
| 7191 | xmlSchemaPMissingAttrErr(ctxt, |
| 7192 | XML_SCHEMAP_S4S_ATTR_MISSING, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7193 | (xmlChar **) &xmlSchemaElemDesST, NULL, node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7194 | "name", NULL); |
| 7195 | return (NULL); |
| 7196 | } else if (xmlSchemaPValAttrNode(ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7197 | (xmlChar **) &xmlSchemaElemDesST, NULL, attr, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7198 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &attrValue) != 0) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7199 | return (NULL); |
| 7200 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7201 | } |
| 7202 | |
| 7203 | if (topLevel == 0) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7204 | char buf[40]; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7205 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7206 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7207 | * Parse as local simple type definition. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7208 | */ |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 7209 | snprintf(buf, 39, "#ST%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7210 | type = xmlSchemaAddType(ctxt, schema, (const xmlChar *)buf, NULL, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7211 | if (type == NULL) |
| 7212 | return (NULL); |
| 7213 | type->node = node; |
| 7214 | type->type = XML_SCHEMA_TYPE_SIMPLE; |
| 7215 | /* |
| 7216 | * Check for illegal attributes. |
| 7217 | */ |
| 7218 | attr = node->properties; |
| 7219 | while (attr != NULL) { |
| 7220 | if (attr->ns == NULL) { |
| 7221 | if (!xmlStrEqual(attr->name, BAD_CAST "id")) { |
| 7222 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7223 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7224 | &des, type, attr); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7225 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7226 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 7227 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7228 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7229 | &des, type, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7230 | } |
| 7231 | attr = attr->next; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7232 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7233 | } else { |
| 7234 | /* |
| 7235 | * Parse as global simple type definition. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7236 | * |
| 7237 | * Note that attrValue is the value of the attribute "name" here. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7238 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7239 | type = xmlSchemaAddType(ctxt, schema, attrValue, schema->targetNamespace, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7240 | if (type == NULL) |
| 7241 | return (NULL); |
| 7242 | type->node = node; |
| 7243 | type->type = XML_SCHEMA_TYPE_SIMPLE; |
| 7244 | type->flags |= XML_SCHEMAS_TYPE_GLOBAL; |
| 7245 | /* |
| 7246 | * Check for illegal attributes. |
| 7247 | */ |
| 7248 | attr = node->properties; |
| 7249 | while (attr != NULL) { |
| 7250 | if (attr->ns == NULL) { |
| 7251 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 7252 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7253 | (!xmlStrEqual(attr->name, BAD_CAST "final"))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7254 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7255 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7256 | &des, type, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7257 | } |
| 7258 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 7259 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7260 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7261 | &des, type, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7262 | } |
| 7263 | attr = attr->next; |
| 7264 | } |
| 7265 | /* |
| 7266 | * Attribute "final". |
| 7267 | */ |
| 7268 | attr = xmlSchemaGetPropNode(node, "final"); |
| 7269 | if (attr == NULL) { |
| 7270 | type->flags |= XML_SCHEMAS_TYPE_FINAL_DEFAULT; |
| 7271 | } else { |
| 7272 | attrValue = xmlSchemaGetProp(ctxt, node, "final"); |
| 7273 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(type->flags), |
| 7274 | -1, -1, XML_SCHEMAS_TYPE_FINAL_RESTRICTION, -1, |
| 7275 | XML_SCHEMAS_TYPE_FINAL_LIST, |
| 7276 | XML_SCHEMAS_TYPE_FINAL_UNION) != 0) { |
| 7277 | |
| 7278 | xmlSchemaPSimpleTypeErr(ctxt, |
| 7279 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7280 | &des, type, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7281 | NULL, "(#all | List of (list | union | restriction)", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7282 | attrValue, NULL, NULL, NULL); |
| 7283 | } |
| 7284 | } |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 7285 | } |
| 7286 | type->targetNamespace = schema->targetNamespace; |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 7287 | xmlSchemaPValAttrID(ctxt, NULL, type, node, BAD_CAST "id"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7288 | /* |
| 7289 | * And now for the children... |
| 7290 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7291 | oldCtxtType = ctxt->ctxtType; |
| 7292 | oldParentItem = ctxt->parentItem; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7293 | ctxt->ctxtType = type; |
| 7294 | ctxt->parentItem = type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7295 | child = node->children; |
| 7296 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7297 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7298 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7299 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7300 | subtype = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7301 | if (IS_SCHEMA(child, "restriction")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7302 | subtype = (xmlSchemaTypePtr) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 7303 | xmlSchemaParseRestriction(ctxt, schema, child); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7304 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7305 | } else if (IS_SCHEMA(child, "list")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7306 | subtype = (xmlSchemaTypePtr) |
| 7307 | xmlSchemaParseList(ctxt, schema, child); |
| 7308 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7309 | } else if (IS_SCHEMA(child, "union")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7310 | subtype = (xmlSchemaTypePtr) |
| 7311 | xmlSchemaParseUnion(ctxt, schema, child); |
| 7312 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7313 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7314 | type->subtypes = subtype; |
| 7315 | if ((child != NULL) || (subtype == NULL)) { |
| 7316 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7317 | &des, type, node, child, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7318 | "(annotation?, (restriction | list | union))"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7319 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7320 | ctxt->parentItem = oldParentItem; |
| 7321 | ctxt->ctxtType = oldCtxtType; |
| 7322 | FREE_AND_NULL(des) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7323 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7324 | return (type); |
| 7325 | } |
| 7326 | |
| 7327 | |
| 7328 | /** |
| 7329 | * xmlSchemaParseGroup: |
| 7330 | * @ctxt: a schema validation context |
| 7331 | * @schema: the schema being built |
| 7332 | * @node: a subtree containing XML Schema informations |
| 7333 | * |
| 7334 | * parse a XML schema Group definition |
| 7335 | * *WARNING* this interface is highly subject to change |
| 7336 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7337 | * 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] | 7338 | * 1 in case of success. |
| 7339 | */ |
| 7340 | static xmlSchemaTypePtr |
| 7341 | xmlSchemaParseGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 7342 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7343 | { |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 7344 | xmlSchemaTypePtr item; |
| 7345 | xmlNodePtr child = NULL; |
| 7346 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7347 | |
| 7348 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 7349 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7350 | |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 7351 | if (topLevel) { |
| 7352 | const xmlChar *name; |
| 7353 | /* |
| 7354 | * Parse as model group definition. |
| 7355 | */ |
| 7356 | attr = xmlSchemaGetPropNode(node, "name"); |
| 7357 | if (attr == NULL) { |
| 7358 | xmlSchemaPMissingAttrErr(ctxt, |
| 7359 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 7360 | NULL, NULL, node, |
| 7361 | "name", NULL); |
| 7362 | return (NULL); |
| 7363 | } else if (xmlSchemaPValAttrNode(ctxt, |
| 7364 | NULL, NULL, attr, |
| 7365 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 7366 | return (NULL); |
| 7367 | } |
| 7368 | item = xmlSchemaAddGroup(ctxt, schema, name, |
| 7369 | schema->targetNamespace, node); |
| 7370 | if (item == NULL) |
| 7371 | return (NULL); |
| 7372 | item->node = node; |
| 7373 | item->type = XML_SCHEMA_TYPE_GROUP; |
| 7374 | item->flags |= XML_SCHEMAS_TYPE_GLOBAL; |
| 7375 | /* |
| 7376 | * Check for illegal attributes. |
| 7377 | */ |
| 7378 | attr = node->properties; |
| 7379 | while (attr != NULL) { |
| 7380 | if (attr->ns == NULL) { |
| 7381 | if ((!xmlStrEqual(attr->name, BAD_CAST "name")) && |
| 7382 | (!xmlStrEqual(attr->name, BAD_CAST "id"))) { |
| 7383 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7384 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7385 | NULL, item, attr); |
| 7386 | } |
| 7387 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 7388 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7389 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7390 | NULL, item, attr); |
| 7391 | } |
| 7392 | attr = attr->next; |
| 7393 | } |
| 7394 | xmlSchemaPValAttrID(ctxt, NULL, item, node, BAD_CAST "id"); |
| 7395 | /* |
| 7396 | * And now for the children... |
| 7397 | */ |
| 7398 | child = node->children; |
| 7399 | if (IS_SCHEMA(child, "annotation")) { |
| 7400 | item->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7401 | child = child->next; |
| 7402 | } |
| 7403 | if (IS_SCHEMA(child, "all")) { |
| 7404 | item->subtypes = (xmlSchemaTypePtr) |
| 7405 | xmlSchemaParseAll(ctxt, schema, child); |
| 7406 | child = child->next; |
| 7407 | } else if (IS_SCHEMA(child, "choice")) { |
| 7408 | item->subtypes = xmlSchemaParseChoice(ctxt, schema, child); |
| 7409 | child = child->next; |
| 7410 | } else if (IS_SCHEMA(child, "sequence")) { |
| 7411 | item->subtypes = xmlSchemaParseSequence(ctxt, schema, child); |
| 7412 | child = child->next; |
| 7413 | } |
| 7414 | if (child != NULL) { |
| 7415 | xmlSchemaPContentErr(ctxt, |
| 7416 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 7417 | NULL, item, node, child, NULL, |
| 7418 | "(annotation?, (all | choice | sequence)?)"); |
| 7419 | } |
| 7420 | } else { |
| 7421 | const xmlChar *ref = NULL, *refNs = NULL, *refPrefix = NULL; |
| 7422 | int minOccurs, maxOccurs; |
| 7423 | char buf[40]; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7424 | |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 7425 | /* |
| 7426 | * Parse as particle. |
| 7427 | */ |
| 7428 | attr = xmlSchemaGetPropNode(node, "ref"); |
| 7429 | if (attr == NULL) { |
| 7430 | xmlSchemaPMissingAttrErr(ctxt, |
| 7431 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 7432 | NULL, NULL, node, |
| 7433 | "ref", NULL); |
| 7434 | return (NULL); |
| 7435 | } else if (xmlSchemaPValAttrNodeQName(ctxt, schema, NULL, NULL, |
| 7436 | attr, &refNs, &refPrefix, &ref) != 0) { |
| 7437 | return (NULL); |
| 7438 | } |
| 7439 | |
| 7440 | /* |
| 7441 | * TODO: Validate the element even if no item is created |
| 7442 | * (i.e. min/maxOccurs == 0). |
| 7443 | */ |
| 7444 | minOccurs = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "nonNegativeInteger"); |
| 7445 | maxOccurs = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, |
| 7446 | "(nonNegativeInteger | unbounded)"); |
| 7447 | if ((minOccurs == 0) && (maxOccurs == 0)) { |
| 7448 | return (NULL); |
| 7449 | } |
| 7450 | |
| 7451 | snprintf(buf, 39, "#grRef%d", ctxt->counter++ + 1); |
| 7452 | item = xmlSchemaAddGroup(ctxt, schema, (const xmlChar *)buf, NULL, node); |
| 7453 | if (item == NULL) |
| 7454 | return (NULL); |
| 7455 | item->node = node; |
| 7456 | item->type = XML_SCHEMA_TYPE_GROUP; |
| 7457 | item->ref = ref; |
| 7458 | item->refNs = refNs; |
| 7459 | xmlSchemaCheckReference(ctxt, schema, node, item, refNs); |
| 7460 | item->minOccurs = minOccurs; |
| 7461 | item->maxOccurs = maxOccurs; |
| 7462 | xmlSchemaPCheckParticleCorrect_2(ctxt, item, |
| 7463 | node, item->minOccurs, item->maxOccurs); |
| 7464 | /* |
| 7465 | * Check for illegal attributes. |
| 7466 | */ |
| 7467 | attr = node->properties; |
| 7468 | while (attr != NULL) { |
| 7469 | if (attr->ns == NULL) { |
| 7470 | if ((!xmlStrEqual(attr->name, BAD_CAST "ref")) && |
| 7471 | (!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 7472 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) && |
| 7473 | (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs"))) { |
| 7474 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7475 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7476 | NULL, item, attr); |
| 7477 | } |
| 7478 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 7479 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7480 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7481 | NULL, item, attr); |
| 7482 | } |
| 7483 | attr = attr->next; |
| 7484 | } |
| 7485 | xmlSchemaPValAttrID(ctxt, NULL, item, node, BAD_CAST "id"); |
| 7486 | /* |
| 7487 | * And now for the children... |
| 7488 | */ |
| 7489 | child = node->children; |
| 7490 | if (IS_SCHEMA(child, "annotation")) { |
| 7491 | item->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7492 | child = child->next; |
| 7493 | } |
| 7494 | if (child != NULL) { |
| 7495 | xmlSchemaPContentErr(ctxt, |
| 7496 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 7497 | NULL, item, node, child, NULL, |
| 7498 | "(annotation?, (all | choice | sequence)?)"); |
| 7499 | } |
| 7500 | } |
| 7501 | |
| 7502 | return (item); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7503 | } |
| 7504 | |
| 7505 | /** |
| 7506 | * xmlSchemaParseAll: |
| 7507 | * @ctxt: a schema validation context |
| 7508 | * @schema: the schema being built |
| 7509 | * @node: a subtree containing XML Schema informations |
| 7510 | * |
| 7511 | * parse a XML schema All definition |
| 7512 | * *WARNING* this interface is highly subject to change |
| 7513 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7514 | * 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] | 7515 | * 1 in case of success. |
| 7516 | */ |
| 7517 | static xmlSchemaTypePtr |
| 7518 | xmlSchemaParseAll(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7519 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7520 | { |
| 7521 | xmlSchemaTypePtr type, subtype, last = NULL; |
| 7522 | xmlNodePtr child = NULL; |
| 7523 | xmlChar name[30]; |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 7524 | const xmlChar *oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7525 | |
| 7526 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 7527 | return (NULL); |
| 7528 | |
| 7529 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 7530 | snprintf((char *) name, 30, "#all%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7531 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7532 | if (type == NULL) |
| 7533 | return (NULL); |
| 7534 | type->node = node; |
Daniel Veillard | 7646b18 | 2002-04-20 06:41:40 +0000 | [diff] [blame] | 7535 | type->type = XML_SCHEMA_TYPE_ALL; |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 7536 | |
| 7537 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 7538 | |
| 7539 | type->minOccurs = xmlGetMinOccurs(ctxt, node, 0, 1, 1, "(0 | 1)"); |
| 7540 | type->maxOccurs = xmlGetMaxOccurs(ctxt, node, 1, 1, 1, "1"); |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 7541 | |
| 7542 | oldcontainer = ctxt->container; |
| 7543 | ctxt->container = (const xmlChar *) name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7544 | child = node->children; |
| 7545 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7546 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7547 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7548 | } |
| 7549 | while (IS_SCHEMA(child, "element")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7550 | subtype = (xmlSchemaTypePtr) |
| 7551 | xmlSchemaParseElement(ctxt, schema, child, 0); |
| 7552 | if (subtype != NULL) { |
William M. Brack | b15351e | 2003-12-27 04:34:42 +0000 | [diff] [blame] | 7553 | if (subtype->minOccurs > 1) |
| 7554 | xmlSchemaPErr(ctxt, child, XML_SCHEMAP_INVALID_MINOCCURS, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7555 | "invalid value for minOccurs (must be 0 or 1).\n", |
William M. Brack | b15351e | 2003-12-27 04:34:42 +0000 | [diff] [blame] | 7556 | NULL, NULL); |
| 7557 | if (subtype->maxOccurs > 1) |
| 7558 | xmlSchemaPErr(ctxt, child, XML_SCHEMAP_INVALID_MAXOCCURS, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7559 | "invalid value for maxOccurs (must be 0 or 1).\n", |
William M. Brack | b15351e | 2003-12-27 04:34:42 +0000 | [diff] [blame] | 7560 | NULL, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7561 | if (last == NULL) { |
| 7562 | type->subtypes = subtype; |
| 7563 | last = subtype; |
| 7564 | } else { |
| 7565 | last->next = subtype; |
| 7566 | last = subtype; |
| 7567 | } |
| 7568 | last->next = NULL; |
| 7569 | } |
| 7570 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7571 | } |
| 7572 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7573 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_ALL_CHILD, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7574 | "<all> has unexpected content.\n", type->name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7575 | NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7576 | } |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 7577 | ctxt->container = oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7578 | return (type); |
| 7579 | } |
| 7580 | |
| 7581 | /** |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7582 | * xmlSchemaCleanupDoc: |
| 7583 | * @ctxt: a schema validation context |
| 7584 | * @node: the root of the document. |
| 7585 | * |
| 7586 | * removes unwanted nodes in a schemas document tree |
| 7587 | */ |
| 7588 | static void |
| 7589 | xmlSchemaCleanupDoc(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr root) |
| 7590 | { |
| 7591 | xmlNodePtr delete, cur; |
| 7592 | |
| 7593 | if ((ctxt == NULL) || (root == NULL)) return; |
| 7594 | |
| 7595 | /* |
| 7596 | * Remove all the blank text nodes |
| 7597 | */ |
| 7598 | delete = NULL; |
| 7599 | cur = root; |
| 7600 | while (cur != NULL) { |
| 7601 | if (delete != NULL) { |
| 7602 | xmlUnlinkNode(delete); |
| 7603 | xmlFreeNode(delete); |
| 7604 | delete = NULL; |
| 7605 | } |
| 7606 | if (cur->type == XML_TEXT_NODE) { |
| 7607 | if (IS_BLANK_NODE(cur)) { |
| 7608 | if (xmlNodeGetSpacePreserve(cur) != 1) { |
| 7609 | delete = cur; |
| 7610 | } |
| 7611 | } |
| 7612 | } else if ((cur->type != XML_ELEMENT_NODE) && |
| 7613 | (cur->type != XML_CDATA_SECTION_NODE)) { |
| 7614 | delete = cur; |
| 7615 | goto skip_children; |
| 7616 | } |
| 7617 | |
| 7618 | /* |
| 7619 | * Skip to next node |
| 7620 | */ |
| 7621 | if (cur->children != NULL) { |
| 7622 | if ((cur->children->type != XML_ENTITY_DECL) && |
| 7623 | (cur->children->type != XML_ENTITY_REF_NODE) && |
| 7624 | (cur->children->type != XML_ENTITY_NODE)) { |
| 7625 | cur = cur->children; |
| 7626 | continue; |
| 7627 | } |
| 7628 | } |
| 7629 | skip_children: |
| 7630 | if (cur->next != NULL) { |
| 7631 | cur = cur->next; |
| 7632 | continue; |
| 7633 | } |
| 7634 | |
| 7635 | do { |
| 7636 | cur = cur->parent; |
| 7637 | if (cur == NULL) |
| 7638 | break; |
| 7639 | if (cur == root) { |
| 7640 | cur = NULL; |
| 7641 | break; |
| 7642 | } |
| 7643 | if (cur->next != NULL) { |
| 7644 | cur = cur->next; |
| 7645 | break; |
| 7646 | } |
| 7647 | } while (cur != NULL); |
| 7648 | } |
| 7649 | if (delete != NULL) { |
| 7650 | xmlUnlinkNode(delete); |
| 7651 | xmlFreeNode(delete); |
| 7652 | delete = NULL; |
| 7653 | } |
| 7654 | } |
| 7655 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7656 | |
| 7657 | /** |
| 7658 | * xmlSchemaImportSchema |
| 7659 | * |
| 7660 | * @ctxt: a schema validation context |
| 7661 | * @schemaLocation: an URI defining where to find the imported schema |
| 7662 | * |
| 7663 | * import a XML schema |
| 7664 | * *WARNING* this interface is highly subject to change |
| 7665 | * |
| 7666 | * Returns -1 in case of error and 1 in case of success. |
| 7667 | */ |
| 7668 | #if 0 |
| 7669 | static xmlSchemaImportPtr |
| 7670 | xmlSchemaImportSchema(xmlSchemaParserCtxtPtr ctxt, |
| 7671 | const xmlChar *schemaLocation) |
| 7672 | { |
| 7673 | xmlSchemaImportPtr import; |
| 7674 | xmlSchemaParserCtxtPtr newctxt; |
| 7675 | |
| 7676 | newctxt = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 7677 | if (newctxt == NULL) { |
| 7678 | xmlSchemaPErrMemory(ctxt, "allocating schema parser context", |
| 7679 | NULL); |
| 7680 | return (NULL); |
| 7681 | } |
| 7682 | memset(newctxt, 0, sizeof(xmlSchemaParserCtxt)); |
| 7683 | /* Keep the same dictionnary for parsing, really */ |
| 7684 | xmlDictReference(ctxt->dict); |
| 7685 | newctxt->dict = ctxt->dict; |
| 7686 | newctxt->includes = 0; |
| 7687 | newctxt->URL = xmlDictLookup(newctxt->dict, schemaLocation, -1); |
| 7688 | |
| 7689 | xmlSchemaSetParserErrors(newctxt, ctxt->error, ctxt->warning, |
| 7690 | ctxt->userData); |
| 7691 | |
| 7692 | import = (xmlSchemaImport*) xmlMalloc(sizeof(xmlSchemaImport)); |
| 7693 | if (import == NULL) { |
| 7694 | xmlSchemaPErrMemory(NULL, "allocating imported schema", |
| 7695 | NULL); |
| 7696 | xmlSchemaFreeParserCtxt(newctxt); |
| 7697 | return (NULL); |
| 7698 | } |
| 7699 | |
| 7700 | memset(import, 0, sizeof(xmlSchemaImport)); |
| 7701 | import->schemaLocation = xmlDictLookup(ctxt->dict, schemaLocation, -1); |
| 7702 | import->schema = xmlSchemaParse(newctxt); |
| 7703 | |
| 7704 | if (import->schema == NULL) { |
| 7705 | /* FIXME use another error enum here ? */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 7706 | xmlSchemaPErr(ctxt, NULL, XML_SCHEMAP_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7707 | "Failed to import schema from location \"%s\".\n", |
| 7708 | schemaLocation, NULL); |
| 7709 | |
| 7710 | xmlSchemaFreeParserCtxt(newctxt); |
| 7711 | /* The schemaLocation is held by the dictionary. |
| 7712 | if (import->schemaLocation != NULL) |
| 7713 | xmlFree((xmlChar *)import->schemaLocation); |
| 7714 | */ |
| 7715 | xmlFree(import); |
| 7716 | return NULL; |
| 7717 | } |
| 7718 | |
| 7719 | xmlSchemaFreeParserCtxt(newctxt); |
| 7720 | return import; |
| 7721 | } |
| 7722 | #endif |
| 7723 | |
| 7724 | static void |
| 7725 | xmlSchemaClearSchemaDefaults(xmlSchemaPtr schema) |
| 7726 | { |
| 7727 | if (schema->flags & XML_SCHEMAS_QUALIF_ELEM) |
| 7728 | schema->flags ^= XML_SCHEMAS_QUALIF_ELEM; |
| 7729 | |
| 7730 | if (schema->flags & XML_SCHEMAS_QUALIF_ATTR) |
| 7731 | schema->flags ^= XML_SCHEMAS_QUALIF_ATTR; |
| 7732 | |
| 7733 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION) |
| 7734 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_EXTENSION; |
| 7735 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION) |
| 7736 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION; |
| 7737 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_LIST) |
| 7738 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_LIST; |
| 7739 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_UNION) |
| 7740 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_UNION; |
| 7741 | |
| 7742 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION) |
| 7743 | schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION; |
| 7744 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION) |
| 7745 | schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION; |
| 7746 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION) |
| 7747 | schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION; |
| 7748 | } |
| 7749 | |
| 7750 | static void |
| 7751 | xmlSchemaParseSchemaDefaults(xmlSchemaParserCtxtPtr ctxt, |
| 7752 | xmlSchemaPtr schema, |
| 7753 | xmlNodePtr node) |
| 7754 | { |
| 7755 | xmlAttrPtr attr; |
| 7756 | const xmlChar *val; |
| 7757 | |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 7758 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
| 7759 | if (schema->version == NULL) |
| 7760 | xmlSchemaPValAttr(ctxt, NULL, NULL, node, "version", |
| 7761 | xmlSchemaGetBuiltInType(XML_SCHEMAS_TOKEN), &(schema->version)); |
| 7762 | else |
| 7763 | xmlSchemaPValAttr(ctxt, NULL, NULL, node, "version", |
| 7764 | xmlSchemaGetBuiltInType(XML_SCHEMAS_TOKEN), NULL); |
| 7765 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7766 | attr = xmlSchemaGetPropNode(node, "elementFormDefault"); |
| 7767 | if (attr != NULL) { |
| 7768 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 7769 | if (xmlSchemaPValAttrFormDefault(val, &schema->flags, |
| 7770 | XML_SCHEMAS_QUALIF_ELEM) != 0) { |
| 7771 | xmlSchemaPSimpleTypeErr(ctxt, |
| 7772 | XML_SCHEMAP_ELEMFORMDEFAULT_VALUE, |
| 7773 | NULL, NULL, (xmlNodePtr) attr, NULL, |
| 7774 | "(qualified | unqualified)", val, NULL, NULL, NULL); |
| 7775 | } |
| 7776 | } |
| 7777 | |
| 7778 | attr = xmlSchemaGetPropNode(node, "attributeFormDefault"); |
| 7779 | if (attr != NULL) { |
| 7780 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 7781 | if (xmlSchemaPValAttrFormDefault(val, &schema->flags, |
| 7782 | XML_SCHEMAS_QUALIF_ATTR) != 0) { |
| 7783 | xmlSchemaPSimpleTypeErr(ctxt, |
| 7784 | XML_SCHEMAP_ATTRFORMDEFAULT_VALUE, |
| 7785 | NULL, NULL, (xmlNodePtr) attr, NULL, |
| 7786 | "(qualified | unqualified)", val, NULL, NULL, NULL); |
| 7787 | } |
| 7788 | } |
| 7789 | |
| 7790 | attr = xmlSchemaGetPropNode(node, "finalDefault"); |
| 7791 | if (attr != NULL) { |
| 7792 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 7793 | if (xmlSchemaPValAttrBlockFinal(val, &(schema->flags), -1, |
| 7794 | XML_SCHEMAS_FINAL_DEFAULT_EXTENSION, |
| 7795 | XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION, |
| 7796 | -1, |
| 7797 | XML_SCHEMAS_FINAL_DEFAULT_LIST, |
| 7798 | XML_SCHEMAS_FINAL_DEFAULT_UNION) != 0) { |
| 7799 | xmlSchemaPSimpleTypeErr(ctxt, |
| 7800 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 7801 | NULL, NULL, (xmlNodePtr) attr, NULL, |
| 7802 | "(#all | List of (extension | restriction | list | union))", |
| 7803 | val, NULL, NULL, NULL); |
| 7804 | } |
| 7805 | } |
| 7806 | |
| 7807 | attr = xmlSchemaGetPropNode(node, "blockDefault"); |
| 7808 | if (attr != NULL) { |
| 7809 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 7810 | if (xmlSchemaPValAttrBlockFinal(val, &(schema->flags), -1, |
| 7811 | XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION, |
| 7812 | XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION, |
| 7813 | XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION, -1, -1) != 0) { |
| 7814 | xmlSchemaPSimpleTypeErr(ctxt, |
| 7815 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 7816 | NULL, NULL, (xmlNodePtr) attr, NULL, |
| 7817 | "(#all | List of (extension | restriction | substitution))", |
| 7818 | val, NULL, NULL, NULL); |
| 7819 | } |
| 7820 | } |
| 7821 | } |
| 7822 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7823 | /** |
| 7824 | * xmlSchemaParseSchemaTopLevel: |
| 7825 | * @ctxt: a schema validation context |
| 7826 | * @schema: the schemas |
| 7827 | * @nodes: the list of top level nodes |
| 7828 | * |
| 7829 | * Returns the internal XML Schema structure built from the resource or |
| 7830 | * NULL in case of error |
| 7831 | */ |
| 7832 | static void |
| 7833 | xmlSchemaParseSchemaTopLevel(xmlSchemaParserCtxtPtr ctxt, |
| 7834 | xmlSchemaPtr schema, xmlNodePtr nodes) |
| 7835 | { |
| 7836 | xmlNodePtr child; |
| 7837 | xmlSchemaAnnotPtr annot; |
| 7838 | |
| 7839 | if ((ctxt == NULL) || (schema == NULL) || (nodes == NULL)) |
| 7840 | return; |
| 7841 | |
| 7842 | child = nodes; |
| 7843 | while ((IS_SCHEMA(child, "include")) || |
| 7844 | (IS_SCHEMA(child, "import")) || |
| 7845 | (IS_SCHEMA(child, "redefine")) || |
| 7846 | (IS_SCHEMA(child, "annotation"))) { |
| 7847 | if (IS_SCHEMA(child, "annotation")) { |
| 7848 | annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7849 | if (schema->annot == NULL) |
| 7850 | schema->annot = annot; |
| 7851 | else |
| 7852 | xmlSchemaFreeAnnot(annot); |
| 7853 | } else if (IS_SCHEMA(child, "import")) { |
| 7854 | xmlSchemaParseImport(ctxt, schema, child); |
| 7855 | } else if (IS_SCHEMA(child, "include")) { |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 7856 | ctxt->includes++; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7857 | xmlSchemaParseInclude(ctxt, schema, child); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 7858 | ctxt->includes--; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7859 | } else if (IS_SCHEMA(child, "redefine")) { |
| 7860 | TODO |
| 7861 | } |
| 7862 | child = child->next; |
| 7863 | } |
| 7864 | while (child != NULL) { |
| 7865 | if (IS_SCHEMA(child, "complexType")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 7866 | xmlSchemaParseComplexType(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7867 | child = child->next; |
| 7868 | } else if (IS_SCHEMA(child, "simpleType")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 7869 | xmlSchemaParseSimpleType(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7870 | child = child->next; |
| 7871 | } else if (IS_SCHEMA(child, "element")) { |
| 7872 | xmlSchemaParseElement(ctxt, schema, child, 1); |
| 7873 | child = child->next; |
| 7874 | } else if (IS_SCHEMA(child, "attribute")) { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7875 | xmlSchemaParseAttribute(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7876 | child = child->next; |
| 7877 | } else if (IS_SCHEMA(child, "attributeGroup")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 7878 | xmlSchemaParseAttributeGroup(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7879 | child = child->next; |
| 7880 | } else if (IS_SCHEMA(child, "group")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 7881 | xmlSchemaParseGroup(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7882 | child = child->next; |
| 7883 | } else if (IS_SCHEMA(child, "notation")) { |
| 7884 | xmlSchemaParseNotation(ctxt, schema, child); |
| 7885 | child = child->next; |
| 7886 | } else { |
| 7887 | xmlSchemaPErr2(ctxt, NULL, child, |
| 7888 | XML_SCHEMAP_UNKNOWN_SCHEMAS_CHILD, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7889 | "Unexpected element \"%s\" as child of <schema>.\n", |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7890 | child->name, NULL); |
| 7891 | child = child->next; |
| 7892 | } |
| 7893 | while (IS_SCHEMA(child, "annotation")) { |
| 7894 | annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7895 | if (schema->annot == NULL) |
| 7896 | schema->annot = annot; |
| 7897 | else |
| 7898 | xmlSchemaFreeAnnot(annot); |
| 7899 | child = child->next; |
| 7900 | } |
| 7901 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7902 | ctxt->parentItem = NULL; |
| 7903 | ctxt->ctxtType = NULL; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7904 | } |
| 7905 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7906 | static xmlSchemaImportPtr |
| 7907 | xmlSchemaAddImport(xmlSchemaParserCtxtPtr ctxt, |
| 7908 | xmlHashTablePtr *imports, |
| 7909 | const xmlChar *nsName) |
| 7910 | { |
| 7911 | xmlSchemaImportPtr ret; |
| 7912 | |
| 7913 | if (*imports == NULL) { |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 7914 | *imports = xmlHashCreateDict(10, ctxt->dict); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7915 | if (*imports == NULL) { |
| 7916 | xmlSchemaPCustomErr(ctxt, |
| 7917 | XML_SCHEMAP_FAILED_BUILD_IMPORT, |
| 7918 | NULL, NULL, (xmlNodePtr) ctxt->doc, |
| 7919 | "Internal error: failed to build the import table", |
| 7920 | NULL); |
| 7921 | return (NULL); |
| 7922 | } |
| 7923 | } |
| 7924 | ret = (xmlSchemaImport*) xmlMalloc(sizeof(xmlSchemaImport)); |
| 7925 | if (ret == NULL) { |
| 7926 | xmlSchemaPErrMemory(NULL, "allocating import struct", NULL); |
| 7927 | return (NULL); |
| 7928 | } |
| 7929 | memset(ret, 0, sizeof(xmlSchemaImport)); |
| 7930 | if (nsName == NULL) |
| 7931 | nsName = XML_SCHEMAS_NO_NAMESPACE; |
| 7932 | xmlHashAddEntry(*imports, nsName, ret); |
| 7933 | |
| 7934 | return (ret); |
| 7935 | } |
| 7936 | |
| 7937 | static int |
| 7938 | xmlSchemaAcquireSchemaDoc(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7939 | xmlSchemaPtr schema, |
| 7940 | xmlNodePtr node, |
| 7941 | const xmlChar *nsName, |
| 7942 | const xmlChar *location, |
| 7943 | xmlDocPtr *doc, |
| 7944 | const xmlChar **targetNamespace, |
| 7945 | int absolute) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7946 | { |
| 7947 | xmlParserCtxtPtr parserCtxt; |
| 7948 | xmlSchemaImportPtr import; |
| 7949 | const xmlChar *ns; |
| 7950 | xmlNodePtr root; |
| 7951 | |
| 7952 | /* |
| 7953 | * NOTE: This will be used for <import>, <xsi:schemaLocation> and |
| 7954 | * <xsi:noNamespaceSchemaLocation>. |
| 7955 | */ |
| 7956 | *doc = NULL; |
| 7957 | /* |
| 7958 | * Given that the schemaLocation [attribute] is only a hint, it is open |
| 7959 | * to applications to ignore all but the first <import> for a given |
| 7960 | * namespace, regardless of the ·actual value· of schemaLocation, but |
| 7961 | * such a strategy risks missing useful information when new |
| 7962 | * schemaLocations are offered. |
| 7963 | * |
| 7964 | * XSV (ver 2.5-2) does use the first <import> which resolves to a valid schema. |
| 7965 | * Xerces-J (ver 2.5.1) ignores all but the first given <import> - regardless if |
| 7966 | * valid or not. |
| 7967 | * We will follow XSV here. |
| 7968 | */ |
| 7969 | if (location == NULL) { |
| 7970 | /* |
| 7971 | * Schema Document Location Strategy: |
| 7972 | * |
| 7973 | * 3 Based on the namespace name, identify an existing schema document, |
| 7974 | * either as a resource which is an XML document or a <schema> element |
| 7975 | * information item, in some local schema repository; |
| 7976 | * |
| 7977 | * 5 Attempt to resolve the namespace name to locate such a resource. |
| 7978 | * |
| 7979 | * NOTE: Those stategies are not supported, so we will skip. |
| 7980 | */ |
| 7981 | return (0); |
| 7982 | } |
| 7983 | if (nsName == NULL) |
| 7984 | ns = XML_SCHEMAS_NO_NAMESPACE; |
| 7985 | else |
| 7986 | ns = nsName; |
| 7987 | |
| 7988 | import = xmlHashLookup(schema->schemasImports, ns); |
| 7989 | if (import != NULL) { |
| 7990 | /* |
| 7991 | * There was a valid resource for the specified namespace already |
| 7992 | * defined, so skip. |
| 7993 | * TODO: This might be changed someday to allow import of |
| 7994 | * components from multiple documents for a single target namespace. |
| 7995 | */ |
| 7996 | return (0); |
| 7997 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7998 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7999 | /* |
| 8000 | * Schema Document Location Strategy: |
| 8001 | * |
| 8002 | * 2 Based on the location URI, identify an existing schema document, |
| 8003 | * either as a resource which is an XML document or a <schema> element |
| 8004 | * information item, in some local schema repository; |
| 8005 | * |
| 8006 | * 4 Attempt to resolve the location URI, to locate a resource on the |
| 8007 | * web which is or contains or references a <schema> element; |
| 8008 | * TODO: Hmm, I don't know if the reference stuff in 4. will work. |
| 8009 | * |
| 8010 | */ |
| 8011 | if ((absolute == 0) && (node != NULL)) { |
| 8012 | xmlChar *base, *URI; |
| 8013 | |
| 8014 | base = xmlNodeGetBase(node->doc, node); |
| 8015 | if (base == NULL) { |
| 8016 | URI = xmlBuildURI(location, node->doc->URL); |
| 8017 | } else { |
| 8018 | URI = xmlBuildURI(location, base); |
| 8019 | xmlFree(base); |
| 8020 | } |
| 8021 | if (URI != NULL) { |
| 8022 | location = xmlDictLookup(ctxt->dict, URI, -1); |
| 8023 | xmlFree(URI); |
| 8024 | } |
| 8025 | } |
| 8026 | parserCtxt = xmlNewParserCtxt(); |
| 8027 | if (parserCtxt == NULL) { |
| 8028 | xmlSchemaPErrMemory(NULL, "xmlSchemaParseImport: " |
| 8029 | "allocating a parser context", NULL); |
| 8030 | return(-1); |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 8031 | } |
| 8032 | |
| 8033 | if ((ctxt->dict != NULL) && (parserCtxt->dict != NULL)) { |
| 8034 | xmlDictFree(parserCtxt->dict); |
| 8035 | parserCtxt->dict = ctxt->dict; |
| 8036 | xmlDictReference(parserCtxt->dict); |
| 8037 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8038 | |
| 8039 | *doc = xmlCtxtReadFile(parserCtxt, (const char *) location, |
| 8040 | NULL, SCHEMAS_PARSE_OPTIONS); |
| 8041 | |
| 8042 | /* |
| 8043 | * 2.1 The referent is (a fragment of) a resource which is an |
| 8044 | * XML document (see clause 1.1), which in turn corresponds to |
| 8045 | * a <schema> element information item in a well-formed information |
| 8046 | * set, which in turn corresponds to a valid schema. |
| 8047 | * TODO: What to do with the "fragment" stuff? |
| 8048 | * |
| 8049 | * 2.2 The referent is a <schema> element information item in |
| 8050 | * a well-formed information set, which in turn corresponds |
| 8051 | * to a valid schema. |
| 8052 | * NOTE: 2.2 won't apply, since only XML documents will be processed |
| 8053 | * here. |
| 8054 | */ |
| 8055 | if (*doc == NULL) { |
| 8056 | xmlErrorPtr lerr; |
| 8057 | /* |
| 8058 | * It is *not* an error for the application schema reference |
| 8059 | * strategy to fail. |
| 8060 | * |
| 8061 | * If the doc is NULL and the parser error is an IO error we |
| 8062 | * will assume that the resource could not be located or accessed. |
| 8063 | * |
| 8064 | * TODO: Try to find specific error codes to react only on |
| 8065 | * localisation failures. |
| 8066 | * |
| 8067 | * TODO, FIXME: Check the spec: is a namespace added to the imported |
| 8068 | * namespaces, even if the schemaLocation did not provide |
| 8069 | * a resource? I guess so, since omitting the "schemaLocation" |
| 8070 | * attribute, imports a namespace as well. |
| 8071 | */ |
| 8072 | lerr = xmlGetLastError(); |
| 8073 | if ((lerr != NULL) && (lerr->domain == XML_FROM_IO)) { |
| 8074 | xmlFreeParserCtxt(parserCtxt); |
| 8075 | return(0); |
| 8076 | } |
| 8077 | |
| 8078 | xmlSchemaPCustomErr(ctxt, |
| 8079 | XML_SCHEMAP_SRC_IMPORT_2_1, |
| 8080 | NULL, NULL, node, |
| 8081 | "Failed to parse the resource '%s' for import", |
| 8082 | location); |
| 8083 | xmlFreeParserCtxt(parserCtxt); |
| 8084 | return(XML_SCHEMAP_SRC_IMPORT_2_1); |
| 8085 | } |
| 8086 | xmlFreeParserCtxt(parserCtxt); |
| 8087 | |
| 8088 | root = xmlDocGetRootElement(*doc); |
| 8089 | if (root == NULL) { |
| 8090 | xmlSchemaPCustomErr(ctxt, |
| 8091 | XML_SCHEMAP_SRC_IMPORT_2_1, |
| 8092 | NULL, NULL, node, |
| 8093 | "The XML document '%s' to be imported has no document " |
| 8094 | "element", location); |
| 8095 | xmlFreeDoc(*doc); |
| 8096 | *doc = NULL; |
| 8097 | return (XML_SCHEMAP_SRC_IMPORT_2_1); |
| 8098 | } |
| 8099 | |
| 8100 | xmlSchemaCleanupDoc(ctxt, root); |
| 8101 | |
| 8102 | if (!IS_SCHEMA(root, "schema")) { |
| 8103 | xmlSchemaPCustomErr(ctxt, |
| 8104 | XML_SCHEMAP_SRC_IMPORT_2_1, |
| 8105 | NULL, NULL, node, |
| 8106 | "The XML document '%s' to be imported is not a XML schema document", |
| 8107 | location); |
| 8108 | xmlFreeDoc(*doc); |
| 8109 | *doc = NULL; |
| 8110 | return (XML_SCHEMAP_SRC_IMPORT_2_1); |
| 8111 | } |
| 8112 | *targetNamespace = xmlSchemaGetProp(ctxt, root, "targetNamespace"); |
| 8113 | /* |
| 8114 | * Schema Representation Constraint: Import Constraints and Semantics |
| 8115 | */ |
| 8116 | if (nsName == NULL) { |
| 8117 | if (*targetNamespace != NULL) { |
| 8118 | xmlSchemaPCustomErr(ctxt, |
| 8119 | XML_SCHEMAP_SRC_IMPORT_3_2, |
| 8120 | NULL, NULL, node, |
| 8121 | "The XML schema to be imported is not expected " |
| 8122 | "to have a target namespace; this differs from " |
| 8123 | "its target namespace of '%s'", *targetNamespace); |
| 8124 | xmlFreeDoc(*doc); |
| 8125 | *doc = NULL; |
| 8126 | return (XML_SCHEMAP_SRC_IMPORT_3_2); |
| 8127 | } |
| 8128 | } else { |
| 8129 | if (*targetNamespace == NULL) { |
| 8130 | xmlSchemaPCustomErr(ctxt, |
| 8131 | XML_SCHEMAP_SRC_IMPORT_3_1, |
| 8132 | NULL, NULL, node, |
| 8133 | "The XML schema to be imported is expected to have a target " |
| 8134 | "namespace of '%s'", nsName); |
| 8135 | xmlFreeDoc(*doc); |
| 8136 | *doc = NULL; |
| 8137 | return (XML_SCHEMAP_SRC_IMPORT_3_1); |
| 8138 | } else if (!xmlStrEqual(*targetNamespace, nsName)) { |
| 8139 | xmlSchemaPCustomErrExt(ctxt, |
| 8140 | XML_SCHEMAP_SRC_IMPORT_3_1, |
| 8141 | NULL, NULL, node, |
| 8142 | "The XML schema to be imported is expected to have a " |
| 8143 | "target namespace of '%s'; this differs from " |
| 8144 | "its target namespace of '%s'", |
| 8145 | nsName, *targetNamespace, NULL); |
| 8146 | xmlFreeDoc(*doc); |
| 8147 | *doc = NULL; |
| 8148 | return (XML_SCHEMAP_SRC_IMPORT_3_1); |
| 8149 | } |
| 8150 | } |
| 8151 | |
| 8152 | import = xmlSchemaAddImport(ctxt, &(schema->schemasImports), nsName); |
| 8153 | if (import == NULL) { |
| 8154 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_FAILED_BUILD_IMPORT, |
| 8155 | NULL, NULL, NULL, |
| 8156 | "Internal error: xmlSchemaAcquireSchemaDoc, " |
| 8157 | "failed to build import table", NULL); |
| 8158 | xmlFreeDoc(*doc); |
| 8159 | *doc = NULL; |
| 8160 | return (-1); |
| 8161 | } |
| 8162 | import->schemaLocation = location; |
| 8163 | import->doc = *doc; |
| 8164 | return (0); |
| 8165 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8166 | |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8167 | static void |
| 8168 | xmlSchemaParseForImpInc(xmlSchemaParserCtxtPtr pctxt, |
| 8169 | xmlSchemaPtr schema, |
| 8170 | const xmlChar *targetNamespace, |
| 8171 | xmlNodePtr node) |
| 8172 | { |
| 8173 | const xmlChar *oldURL, **oldLocImps, *oldTNS; |
| 8174 | int oldFlags, oldNumLocImps, oldSizeLocImps; |
| 8175 | |
| 8176 | /* |
| 8177 | * Save and reset the context & schema. |
| 8178 | */ |
| 8179 | oldURL = pctxt->URL; |
| 8180 | /* TODO: Is using the doc->URL here correct? */ |
| 8181 | pctxt->URL = node->doc->URL; |
| 8182 | oldLocImps = pctxt->localImports; |
| 8183 | pctxt->localImports = NULL; |
| 8184 | oldNumLocImps = pctxt->nbLocalImports; |
| 8185 | pctxt->nbLocalImports = 0; |
| 8186 | oldSizeLocImps = pctxt->sizeLocalImports; |
| 8187 | pctxt->sizeLocalImports = 0; |
| 8188 | oldFlags = schema->flags; |
| 8189 | xmlSchemaClearSchemaDefaults(schema); |
| 8190 | oldTNS = schema->targetNamespace; |
| 8191 | schema->targetNamespace = targetNamespace; |
| 8192 | /* |
| 8193 | * Parse the schema. |
| 8194 | */ |
| 8195 | xmlSchemaParseSchemaDefaults(pctxt, schema, node); |
| 8196 | xmlSchemaParseSchemaTopLevel(pctxt, schema, node->children); |
| 8197 | /* |
| 8198 | * Restore the context & schema. |
| 8199 | */ |
| 8200 | schema->flags = oldFlags; |
| 8201 | schema->targetNamespace = oldTNS; |
| 8202 | if (pctxt->localImports != NULL) |
| 8203 | xmlFree((xmlChar *) pctxt->localImports); |
| 8204 | pctxt->localImports = oldLocImps; |
| 8205 | pctxt->nbLocalImports = oldNumLocImps; |
| 8206 | pctxt->sizeLocalImports = oldSizeLocImps; |
| 8207 | pctxt->URL = oldURL; |
| 8208 | } |
| 8209 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8210 | /** |
| 8211 | * xmlSchemaParseImport: |
| 8212 | * @ctxt: a schema validation context |
| 8213 | * @schema: the schema being built |
| 8214 | * @node: a subtree containing XML Schema informations |
| 8215 | * |
| 8216 | * parse a XML schema Import definition |
| 8217 | * *WARNING* this interface is highly subject to change |
| 8218 | * |
| 8219 | * Returns 0 in case of success, a positive error code if |
| 8220 | * not valid and -1 in case of an internal error. |
| 8221 | */ |
| 8222 | static int |
| 8223 | xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 8224 | xmlNodePtr node) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8225 | { |
| 8226 | xmlNodePtr child; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8227 | const xmlChar *namespaceName = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8228 | const xmlChar *schemaLocation = NULL; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8229 | const xmlChar *targetNamespace; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8230 | xmlAttrPtr attr; |
| 8231 | xmlDocPtr doc; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8232 | int ret = 0; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8233 | |
| 8234 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 8235 | return (-1); |
| 8236 | |
| 8237 | /* |
| 8238 | * Check for illegal attributes. |
| 8239 | */ |
| 8240 | attr = node->properties; |
| 8241 | while (attr != NULL) { |
| 8242 | if (attr->ns == NULL) { |
| 8243 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 8244 | (!xmlStrEqual(attr->name, BAD_CAST "namespace")) && |
| 8245 | (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation"))) { |
| 8246 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8247 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8248 | NULL, NULL, attr); |
| 8249 | } |
| 8250 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 8251 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8252 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8253 | NULL, NULL, attr); |
| 8254 | } |
| 8255 | attr = attr->next; |
| 8256 | } |
| 8257 | /* |
| 8258 | * Extract and validate attributes. |
| 8259 | */ |
| 8260 | if (xmlSchemaPValAttr(ctxt, NULL, NULL, node, |
| 8261 | "namespace", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8262 | &namespaceName) != 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8263 | xmlSchemaPSimpleTypeErr(ctxt, |
| 8264 | XML_SCHEMAP_IMPORT_NAMESPACE_NOT_URI, |
| 8265 | NULL, NULL, node, |
| 8266 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8267 | NULL, namespaceName, NULL, NULL, NULL); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8268 | return (XML_SCHEMAP_IMPORT_NAMESPACE_NOT_URI); |
| 8269 | } |
| 8270 | |
| 8271 | if (xmlSchemaPValAttr(ctxt, NULL, NULL, node, |
| 8272 | "schemaLocation", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
| 8273 | &schemaLocation) != 0) { |
| 8274 | xmlSchemaPSimpleTypeErr(ctxt, |
| 8275 | XML_SCHEMAP_IMPORT_SCHEMA_NOT_URI, |
| 8276 | NULL, NULL, node, |
| 8277 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8278 | NULL, namespaceName, NULL, NULL, NULL); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8279 | return (XML_SCHEMAP_IMPORT_SCHEMA_NOT_URI); |
| 8280 | } |
| 8281 | /* |
| 8282 | * And now for the children... |
| 8283 | */ |
| 8284 | child = node->children; |
| 8285 | if (IS_SCHEMA(child, "annotation")) { |
| 8286 | /* |
| 8287 | * the annotation here is simply discarded ... |
| 8288 | */ |
| 8289 | child = child->next; |
| 8290 | } |
| 8291 | if (child != NULL) { |
| 8292 | xmlSchemaPContentErr(ctxt, |
| 8293 | XML_SCHEMAP_UNKNOWN_IMPORT_CHILD, |
| 8294 | NULL, NULL, node, child, NULL, |
| 8295 | "(annotation?)"); |
| 8296 | } |
| 8297 | /* |
| 8298 | * Apply additional constraints. |
| 8299 | */ |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8300 | if (namespaceName != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8301 | /* |
| 8302 | * 1.1 If the namespace [attribute] is present, then its ·actual value· |
| 8303 | * must not match the ·actual value· of the enclosing <schema>'s |
| 8304 | * targetNamespace [attribute]. |
| 8305 | */ |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8306 | if (xmlStrEqual(schema->targetNamespace, namespaceName)) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8307 | xmlSchemaPCustomErr(ctxt, |
| 8308 | XML_SCHEMAP_SRC_IMPORT_1_1, |
| 8309 | NULL, NULL, node, |
| 8310 | "The value of the attribute 'namespace' must not match " |
| 8311 | "the target namespace '%s' of the importing schema", |
| 8312 | schema->targetNamespace); |
| 8313 | return (XML_SCHEMAP_SRC_IMPORT_1_1); |
| 8314 | } |
| 8315 | } else { |
| 8316 | /* |
| 8317 | * 1.2 If the namespace [attribute] is not present, then the enclosing |
| 8318 | * <schema> must have a targetNamespace [attribute]. |
| 8319 | */ |
| 8320 | if (schema->targetNamespace == NULL) { |
| 8321 | xmlSchemaPCustomErr(ctxt, |
| 8322 | XML_SCHEMAP_SRC_IMPORT_1_2, |
| 8323 | NULL, NULL, node, |
| 8324 | "The attribute 'namespace' must be existent if " |
| 8325 | "the importing schema has no target namespace", |
| 8326 | NULL); |
| 8327 | return (XML_SCHEMAP_SRC_IMPORT_1_2); |
| 8328 | } |
| 8329 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8330 | /* |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8331 | * Add the namespace to the list of locally imported namespace. |
| 8332 | */ |
| 8333 | if (ctxt->localImports == NULL) { |
| 8334 | ctxt->localImports = (const xmlChar **) xmlMalloc(10 * |
| 8335 | sizeof(const xmlChar*)); |
| 8336 | ctxt->sizeLocalImports = 10; |
| 8337 | ctxt->nbLocalImports = 0; |
| 8338 | } else if (ctxt->sizeLocalImports <= ctxt->nbLocalImports) { |
| 8339 | ctxt->sizeLocalImports *= 2; |
| 8340 | ctxt->localImports = (const xmlChar **) xmlRealloc( |
| 8341 | (xmlChar **) ctxt->localImports, |
| 8342 | ctxt->sizeLocalImports * sizeof(const xmlChar*)); |
| 8343 | } |
| 8344 | ctxt->localImports[ctxt->nbLocalImports++] = namespaceName; |
| 8345 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8346 | * Locate and aquire the schema document. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8347 | */ |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8348 | ret = xmlSchemaAcquireSchemaDoc(ctxt, schema, node, namespaceName, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8349 | schemaLocation, &doc, &targetNamespace, 0); |
| 8350 | if (ret != 0) { |
| 8351 | if (doc != NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8352 | xmlFreeDoc(doc); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8353 | return (ret); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8354 | } else if (doc != NULL) { |
| 8355 | xmlSchemaParseForImpInc(ctxt, schema, targetNamespace, |
| 8356 | xmlDocGetRootElement(doc)); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8357 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8358 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8359 | return (0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8360 | } |
| 8361 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8362 | /** |
| 8363 | * xmlSchemaParseInclude: |
| 8364 | * @ctxt: a schema validation context |
| 8365 | * @schema: the schema being built |
| 8366 | * @node: a subtree containing XML Schema informations |
| 8367 | * |
| 8368 | * parse a XML schema Include definition |
| 8369 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 8370 | * 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] | 8371 | * 1 in case of success. |
| 8372 | */ |
| 8373 | static int |
| 8374 | xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 8375 | xmlNodePtr node) |
| 8376 | { |
| 8377 | xmlNodePtr child = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8378 | const xmlChar *schemaLocation, *targetNamespace; |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8379 | xmlDocPtr doc = NULL; |
| 8380 | xmlNodePtr root = NULL; |
Daniel Veillard | cffc1c7 | 2005-03-12 18:54:55 +0000 | [diff] [blame] | 8381 | xmlSchemaIncludePtr include = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8382 | int wasConvertingNs = 0; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8383 | xmlAttrPtr attr; |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 8384 | xmlParserCtxtPtr parserCtxt; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8385 | |
| 8386 | |
| 8387 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 8388 | return (-1); |
| 8389 | |
| 8390 | /* |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8391 | * Check for illegal attributes. |
| 8392 | */ |
| 8393 | attr = node->properties; |
| 8394 | while (attr != NULL) { |
| 8395 | if (attr->ns == NULL) { |
| 8396 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 8397 | (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation"))) { |
| 8398 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8399 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8400 | NULL, NULL, attr); |
| 8401 | } |
| 8402 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 8403 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8404 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8405 | NULL, NULL, attr); |
| 8406 | } |
| 8407 | attr = attr->next; |
| 8408 | } |
| 8409 | /* |
| 8410 | * Extract and validate attributes. |
| 8411 | */ |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8412 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8413 | /* |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8414 | * Preliminary step, extract the URI-Reference for the include and |
| 8415 | * make an URI from the base. |
| 8416 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8417 | attr = xmlSchemaGetPropNode(node, "schemaLocation"); |
| 8418 | if (attr != NULL) { |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8419 | xmlChar *base = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8420 | xmlChar *uri = NULL; |
| 8421 | |
| 8422 | if (xmlSchemaPValAttrNode(ctxt, NULL, NULL, attr, |
| 8423 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), &schemaLocation) != 0) |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8424 | goto exit_invalid; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8425 | base = xmlNodeGetBase(node->doc, node); |
| 8426 | if (base == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8427 | uri = xmlBuildURI(schemaLocation, node->doc->URL); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8428 | } else { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8429 | uri = xmlBuildURI(schemaLocation, base); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8430 | xmlFree(base); |
| 8431 | } |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8432 | if (uri == NULL) { |
| 8433 | xmlSchemaPErr(ctxt, |
| 8434 | node, |
| 8435 | XML_SCHEMAP_INTERNAL, |
| 8436 | "Internal error: xmlSchemaParseInclude, " |
| 8437 | "could not build an URI from the schemaLocation.\n", |
| 8438 | NULL, NULL); |
| 8439 | goto exit_failure; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8440 | } |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8441 | schemaLocation = xmlDictLookup(ctxt->dict, uri, -1); |
| 8442 | xmlFree(uri); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8443 | } else { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8444 | xmlSchemaPMissingAttrErr(ctxt, |
| 8445 | XML_SCHEMAP_INCLUDE_SCHEMA_NO_URI, |
| 8446 | NULL, NULL, node, "schemaLocation", NULL); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8447 | goto exit_invalid; |
| 8448 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8449 | /* |
| 8450 | * And now for the children... |
| 8451 | */ |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8452 | child = node->children; |
| 8453 | while (IS_SCHEMA(child, "annotation")) { |
| 8454 | /* |
| 8455 | * the annotations here are simply discarded ... |
| 8456 | */ |
| 8457 | child = child->next; |
| 8458 | } |
| 8459 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8460 | xmlSchemaPContentErr(ctxt, |
| 8461 | XML_SCHEMAP_UNKNOWN_INCLUDE_CHILD, |
| 8462 | NULL, NULL, node, child, NULL, |
| 8463 | "(annotation?)"); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8464 | } |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8465 | /* |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8466 | * Report self-inclusion. |
| 8467 | */ |
| 8468 | if (xmlStrEqual(schemaLocation, ctxt->URL)) { |
| 8469 | xmlSchemaPCustomErr(ctxt, |
| 8470 | XML_SCHEMAP_SRC_INCLUDE, |
| 8471 | NULL, NULL, node, |
| 8472 | "The schema document '%s' cannot include itself.", |
| 8473 | schemaLocation); |
| 8474 | return (XML_SCHEMAP_SRC_INCLUDE); |
| 8475 | } |
| 8476 | /* |
| 8477 | * Check if this one was already processed to avoid incorrect |
| 8478 | * duplicate component errors and infinite circular inclusion. |
| 8479 | */ |
| 8480 | include = schema->includes; |
| 8481 | while (include != NULL) { |
| 8482 | if (xmlStrEqual(include->schemaLocation, schemaLocation)) { |
| 8483 | targetNamespace = include->origTargetNamespace; |
| 8484 | if (targetNamespace == NULL) { |
| 8485 | /* |
| 8486 | * Chameleon include: skip only if it was build for |
| 8487 | * the targetNamespace of the including schema. |
| 8488 | */ |
| 8489 | if (xmlStrEqual(schema->targetNamespace, |
| 8490 | include->targetNamespace)) { |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8491 | goto check_targetNamespace; |
| 8492 | } |
| 8493 | } else { |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8494 | goto check_targetNamespace; |
| 8495 | } |
| 8496 | } |
| 8497 | include = include->next; |
| 8498 | } |
| 8499 | /* |
| 8500 | * First step is to parse the input document into an DOM/Infoset |
| 8501 | * TODO: Use xmlCtxtReadFile to share the dictionary? |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 8502 | */ |
| 8503 | parserCtxt = xmlNewParserCtxt(); |
| 8504 | if (parserCtxt == NULL) { |
| 8505 | xmlSchemaPErrMemory(NULL, "xmlSchemaParseInclude: " |
| 8506 | "allocating a parser context", NULL); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8507 | goto exit_failure; |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 8508 | } |
| 8509 | |
| 8510 | if ((ctxt->dict != NULL) && (parserCtxt->dict != NULL)) { |
| 8511 | xmlDictFree(parserCtxt->dict); |
| 8512 | parserCtxt->dict = ctxt->dict; |
| 8513 | xmlDictReference(parserCtxt->dict); |
| 8514 | } |
| 8515 | |
| 8516 | doc = xmlCtxtReadFile(parserCtxt, (const char *) schemaLocation, |
| 8517 | NULL, SCHEMAS_PARSE_OPTIONS); |
| 8518 | xmlFreeParserCtxt(parserCtxt); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8519 | if (doc == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8520 | /* |
| 8521 | * TODO: It is not an error for the ·actual value· of the |
| 8522 | * schemaLocation [attribute] to fail to resolve it all, in which |
| 8523 | * case no corresponding inclusion is performed. |
| 8524 | * So do we need a warning report here? |
| 8525 | */ |
| 8526 | xmlSchemaPCustomErr(ctxt, |
| 8527 | XML_SCHEMAP_FAILED_LOAD, |
| 8528 | NULL, NULL, node, |
| 8529 | "Failed to load the document '%s' for inclusion", schemaLocation); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8530 | goto exit_invalid; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8531 | } |
| 8532 | |
| 8533 | /* |
| 8534 | * Then extract the root of the schema |
| 8535 | */ |
| 8536 | root = xmlDocGetRootElement(doc); |
| 8537 | if (root == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8538 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8539 | XML_SCHEMAP_NOROOT, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8540 | NULL, NULL, node, |
| 8541 | "The included document '%s' has no document " |
| 8542 | "element", schemaLocation); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8543 | goto exit_invalid; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8544 | } |
| 8545 | |
| 8546 | /* |
| 8547 | * Remove all the blank text nodes |
| 8548 | */ |
| 8549 | xmlSchemaCleanupDoc(ctxt, root); |
| 8550 | |
| 8551 | /* |
| 8552 | * Check the schemas top level element |
| 8553 | */ |
| 8554 | if (!IS_SCHEMA(root, "schema")) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8555 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8556 | XML_SCHEMAP_NOT_SCHEMA, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8557 | NULL, NULL, node, |
| 8558 | "The document '%s' to be included is not a schema document", |
| 8559 | schemaLocation); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8560 | goto exit_invalid; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8561 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8562 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8563 | targetNamespace = xmlSchemaGetProp(ctxt, root, "targetNamespace"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8564 | /* |
| 8565 | * 2.1 SII has a targetNamespace [attribute], and its ·actual |
| 8566 | * value· is identical to the ·actual value· of the targetNamespace |
| 8567 | * [attribute] of SIIÂ’ (which must have such an [attribute]). |
| 8568 | */ |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8569 | check_targetNamespace: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8570 | if (targetNamespace != NULL) { |
| 8571 | if (schema->targetNamespace == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8572 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8573 | XML_SCHEMAP_SRC_INCLUDE, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8574 | NULL, NULL, node, |
| 8575 | "The target namespace of the included schema " |
| 8576 | "'%s' has to be absent, since the including schema " |
| 8577 | "has no target namespace", |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8578 | schemaLocation); |
| 8579 | goto exit_invalid; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8580 | } else if (!xmlStrEqual(targetNamespace, schema->targetNamespace)) { |
| 8581 | xmlSchemaPCustomErrExt(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8582 | XML_SCHEMAP_SRC_INCLUDE, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8583 | NULL, NULL, node, |
| 8584 | "The target namespace '%s' of the included schema '%s' " |
| 8585 | "differs from '%s' of the including schema", |
| 8586 | targetNamespace, schemaLocation, schema->targetNamespace); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8587 | goto exit_invalid; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8588 | } |
| 8589 | } else if (schema->targetNamespace != NULL) { |
| 8590 | if ((schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) == 0) { |
| 8591 | schema->flags |= XML_SCHEMAS_INCLUDING_CONVERT_NS; |
| 8592 | } else |
| 8593 | wasConvertingNs = 1; |
| 8594 | } |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8595 | |
| 8596 | if (include != NULL) |
| 8597 | goto exit; |
| 8598 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8599 | /* |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8600 | * URGENT TODO: If the schema is a chameleon-include then copy the |
| 8601 | * components into the including schema and modify the targetNamespace |
| 8602 | * of those components, do nothing otherwise. |
| 8603 | * NOTE: This is currently worked-around by compiling the chameleon |
| 8604 | * for every destinct including targetNamespace; thus not performant at |
| 8605 | * the moment. |
| 8606 | * TODO: Check when the namespace in wildcards for chameleons needs |
| 8607 | * to be converted: before we built wildcard intersections or after. |
| 8608 | */ |
| 8609 | /* |
| 8610 | * Register the include. |
| 8611 | */ |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8612 | include = (xmlSchemaIncludePtr) xmlMalloc(sizeof(xmlSchemaInclude)); |
| 8613 | if (include == NULL) { |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8614 | xmlSchemaPErrMemory(ctxt, "allocating include entry", NULL); |
| 8615 | goto exit_failure; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8616 | } |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8617 | memset(include, 0, sizeof(xmlSchemaInclude)); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8618 | include->next = schema->includes; |
| 8619 | schema->includes = include; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8620 | /* |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8621 | * TODO: Use the resolved URI for the this location, since it might |
| 8622 | * differ if using filenames/URIs simultaneosly. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8623 | */ |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8624 | include->schemaLocation = schemaLocation; |
| 8625 | include->doc = doc; |
| 8626 | /* |
| 8627 | * In case of chameleons, the original target namespace will differ |
| 8628 | * from the resulting namespace. |
| 8629 | */ |
| 8630 | include->origTargetNamespace = targetNamespace; |
| 8631 | include->targetNamespace = schema->targetNamespace; |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 8632 | #ifdef DEBUG_INCLUDES |
| 8633 | if (targetNamespace != schema->targetNamespace) |
| 8634 | xmlGenericError(xmlGenericErrorContext, |
| 8635 | "INCLUDING CHAMELEON '%s'\n orig TNS '%s'\n" |
| 8636 | " into TNS '%s'\n", schemaLocation, |
| 8637 | targetNamespace, schema->targetNamespace); |
| 8638 | else |
| 8639 | xmlGenericError(xmlGenericErrorContext, |
| 8640 | "INCLUDING '%s'\n orig-TNS '%s'\n", schemaLocation, |
| 8641 | targetNamespace); |
| 8642 | #endif |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8643 | /* |
| 8644 | * Compile the included schema. |
| 8645 | */ |
| 8646 | xmlSchemaParseForImpInc(ctxt, schema, schema->targetNamespace, root); |
| 8647 | |
| 8648 | exit: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8649 | /* |
| 8650 | * Remove the converting flag. |
| 8651 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8652 | if ((wasConvertingNs == 0) && |
| 8653 | (schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS)) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8654 | schema->flags ^= XML_SCHEMAS_INCLUDING_CONVERT_NS; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8655 | return (1); |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 8656 | |
| 8657 | exit_invalid: |
| 8658 | if (doc != NULL) { |
| 8659 | if (include != NULL) |
| 8660 | include->doc = NULL; |
| 8661 | xmlFreeDoc(doc); |
| 8662 | } |
| 8663 | return (ctxt->err); |
| 8664 | |
| 8665 | exit_failure: |
| 8666 | if (doc != NULL) { |
| 8667 | if (include != NULL) |
| 8668 | include->doc = NULL; |
| 8669 | xmlFreeDoc(doc); |
| 8670 | } |
| 8671 | return (-1); |
| 8672 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8673 | } |
| 8674 | |
| 8675 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8676 | * xmlSchemaParseChoice: |
| 8677 | * @ctxt: a schema validation context |
| 8678 | * @schema: the schema being built |
| 8679 | * @node: a subtree containing XML Schema informations |
| 8680 | * |
| 8681 | * parse a XML schema Choice definition |
| 8682 | * *WARNING* this interface is highly subject to change |
| 8683 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 8684 | * 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] | 8685 | * 1 in case of success. |
| 8686 | */ |
| 8687 | static xmlSchemaTypePtr |
| 8688 | xmlSchemaParseChoice(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8689 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8690 | { |
| 8691 | xmlSchemaTypePtr type, subtype, last = NULL; |
| 8692 | xmlNodePtr child = NULL; |
| 8693 | xmlChar name[30]; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8694 | xmlAttrPtr attr; |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 8695 | const xmlChar *oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8696 | |
| 8697 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 8698 | return (NULL); |
| 8699 | |
| 8700 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 8701 | snprintf((char *) name, 30, "#ch%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8702 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8703 | if (type == NULL) |
| 8704 | return (NULL); |
| 8705 | type->node = node; |
| 8706 | type->type = XML_SCHEMA_TYPE_CHOICE; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8707 | /* |
| 8708 | * Check for illegal attributes. |
| 8709 | */ |
| 8710 | attr = node->properties; |
| 8711 | while (attr != NULL) { |
| 8712 | if (attr->ns == NULL) { |
| 8713 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 8714 | (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) && |
| 8715 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs"))) { |
| 8716 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8717 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8718 | NULL, type, attr); |
| 8719 | } |
| 8720 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 8721 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8722 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8723 | NULL, type, attr); |
| 8724 | } |
| 8725 | attr = attr->next; |
| 8726 | } |
| 8727 | /* |
| 8728 | * Extract and validate attributes. |
| 8729 | */ |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 8730 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 8731 | type->minOccurs = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "nonNegativeInteger"); |
| 8732 | type->maxOccurs = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, |
| 8733 | "(nonNegativeInteger | unbounded)"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8734 | /* |
| 8735 | * And now for the children... |
| 8736 | */ |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 8737 | oldcontainer = ctxt->container; |
| 8738 | ctxt->container = (const xmlChar *) name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8739 | child = node->children; |
| 8740 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8741 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 8742 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8743 | } |
| 8744 | while ((IS_SCHEMA(child, "element")) || |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8745 | (IS_SCHEMA(child, "group")) || |
| 8746 | (IS_SCHEMA(child, "any")) || |
| 8747 | (IS_SCHEMA(child, "choice")) || |
| 8748 | (IS_SCHEMA(child, "sequence"))) { |
| 8749 | subtype = NULL; |
| 8750 | if (IS_SCHEMA(child, "element")) { |
| 8751 | subtype = (xmlSchemaTypePtr) |
| 8752 | xmlSchemaParseElement(ctxt, schema, child, 0); |
| 8753 | } else if (IS_SCHEMA(child, "group")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 8754 | subtype = xmlSchemaParseGroup(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8755 | } else if (IS_SCHEMA(child, "any")) { |
| 8756 | subtype = xmlSchemaParseAny(ctxt, schema, child); |
| 8757 | } else if (IS_SCHEMA(child, "sequence")) { |
| 8758 | subtype = xmlSchemaParseSequence(ctxt, schema, child); |
| 8759 | } else if (IS_SCHEMA(child, "choice")) { |
| 8760 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 8761 | } |
| 8762 | if (subtype != NULL) { |
| 8763 | if (last == NULL) { |
| 8764 | type->subtypes = subtype; |
| 8765 | last = subtype; |
| 8766 | } else { |
| 8767 | last->next = subtype; |
| 8768 | last = subtype; |
| 8769 | } |
| 8770 | last->next = NULL; |
| 8771 | } |
| 8772 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8773 | } |
| 8774 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8775 | /* TODO: error code. */ |
| 8776 | xmlSchemaPContentErr(ctxt, |
| 8777 | XML_SCHEMAP_UNKNOWN_CHOICE_CHILD, |
| 8778 | NULL, type, node, child, NULL, |
| 8779 | "(annotation?, (element | group | choice | sequence | any)*)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8780 | } |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 8781 | ctxt->container = oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8782 | return (type); |
| 8783 | } |
| 8784 | |
| 8785 | /** |
| 8786 | * xmlSchemaParseSequence: |
| 8787 | * @ctxt: a schema validation context |
| 8788 | * @schema: the schema being built |
| 8789 | * @node: a subtree containing XML Schema informations |
| 8790 | * |
| 8791 | * parse a XML schema Sequence definition |
| 8792 | * *WARNING* this interface is highly subject to change |
| 8793 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 8794 | * 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] | 8795 | * 1 in case of success. |
| 8796 | */ |
| 8797 | static xmlSchemaTypePtr |
| 8798 | xmlSchemaParseSequence(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8799 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8800 | { |
| 8801 | xmlSchemaTypePtr type, subtype, last = NULL; |
| 8802 | xmlNodePtr child = NULL; |
| 8803 | xmlChar name[30]; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8804 | xmlAttrPtr attr; |
| 8805 | const xmlChar *oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8806 | |
| 8807 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 8808 | return (NULL); |
| 8809 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8810 | oldcontainer = ctxt->container; |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 8811 | snprintf((char *) name, 30, "#seq%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8812 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8813 | if (type == NULL) |
| 8814 | return (NULL); |
| 8815 | type->node = node; |
| 8816 | type->type = XML_SCHEMA_TYPE_SEQUENCE; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8817 | /* |
| 8818 | * Check for illegal attributes. |
| 8819 | */ |
| 8820 | attr = node->properties; |
| 8821 | while (attr != NULL) { |
| 8822 | if (attr->ns == NULL) { |
| 8823 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 8824 | (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) && |
| 8825 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs"))) { |
| 8826 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8827 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8828 | NULL, type, attr); |
| 8829 | } |
| 8830 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 8831 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8832 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8833 | NULL, type, attr); |
| 8834 | } |
| 8835 | attr = attr->next; |
| 8836 | } |
| 8837 | /* |
| 8838 | * Extract and validate attributes. |
| 8839 | */ |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 8840 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 8841 | type->minOccurs = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "nonNegativeInteger"); |
| 8842 | type->maxOccurs = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, |
| 8843 | "(nonNegativeInteger | unbounded)"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8844 | /* |
| 8845 | * And now for the children... |
| 8846 | */ |
| 8847 | ctxt->container = (const xmlChar *) name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8848 | child = node->children; |
| 8849 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8850 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 8851 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8852 | } |
| 8853 | while ((IS_SCHEMA(child, "element")) || |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8854 | (IS_SCHEMA(child, "group")) || |
| 8855 | (IS_SCHEMA(child, "any")) || |
| 8856 | (IS_SCHEMA(child, "choice")) || |
| 8857 | (IS_SCHEMA(child, "sequence"))) { |
| 8858 | subtype = NULL; |
| 8859 | if (IS_SCHEMA(child, "element")) { |
| 8860 | subtype = (xmlSchemaTypePtr) |
| 8861 | xmlSchemaParseElement(ctxt, schema, child, 0); |
| 8862 | } else if (IS_SCHEMA(child, "group")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 8863 | subtype = xmlSchemaParseGroup(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8864 | } else if (IS_SCHEMA(child, "any")) { |
| 8865 | subtype = xmlSchemaParseAny(ctxt, schema, child); |
| 8866 | } else if (IS_SCHEMA(child, "choice")) { |
| 8867 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 8868 | } else if (IS_SCHEMA(child, "sequence")) { |
| 8869 | subtype = xmlSchemaParseSequence(ctxt, schema, child); |
| 8870 | } |
| 8871 | if (subtype != NULL) { |
| 8872 | if (last == NULL) { |
| 8873 | type->subtypes = subtype; |
| 8874 | last = subtype; |
| 8875 | } else { |
| 8876 | last->next = subtype; |
| 8877 | last = subtype; |
| 8878 | } |
| 8879 | last->next = NULL; |
| 8880 | } |
| 8881 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8882 | } |
| 8883 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8884 | xmlSchemaPContentErr(ctxt, |
| 8885 | XML_SCHEMAP_UNKNOWN_SEQUENCE_CHILD, |
| 8886 | NULL, type, node, child, NULL, |
| 8887 | "(annotation?, (element | group | choice | sequence | any)*)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8888 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8889 | ctxt->container = oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8890 | |
| 8891 | return (type); |
| 8892 | } |
| 8893 | |
| 8894 | /** |
| 8895 | * xmlSchemaParseRestriction: |
| 8896 | * @ctxt: a schema validation context |
| 8897 | * @schema: the schema being built |
| 8898 | * @node: a subtree containing XML Schema informations |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8899 | * |
| 8900 | * parse a XML schema Restriction definition |
| 8901 | * *WARNING* this interface is highly subject to change |
| 8902 | * |
| 8903 | * Returns the type definition or NULL in case of error |
| 8904 | */ |
| 8905 | static xmlSchemaTypePtr |
| 8906 | xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 8907 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8908 | { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8909 | xmlSchemaTypePtr type, subtype; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8910 | xmlNodePtr child = NULL; |
| 8911 | xmlChar name[30]; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 8912 | const xmlChar *oldcontainer; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8913 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8914 | |
| 8915 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 8916 | return (NULL); |
| 8917 | |
| 8918 | oldcontainer = ctxt->container; |
| 8919 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 8920 | snprintf((char *) name, 30, "#restr%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8921 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8922 | if (type == NULL) |
| 8923 | return (NULL); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 8924 | type->type = XML_SCHEMA_TYPE_RESTRICTION; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8925 | type->node = node; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8926 | /* |
| 8927 | * Check for illegal attributes. |
| 8928 | */ |
| 8929 | attr = node->properties; |
| 8930 | while (attr != NULL) { |
| 8931 | if (attr->ns == NULL) { |
| 8932 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 8933 | (!xmlStrEqual(attr->name, BAD_CAST "base"))) { |
| 8934 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8935 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8936 | NULL, type, attr); |
| 8937 | } |
| 8938 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 8939 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8940 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8941 | NULL, type, attr); |
| 8942 | } |
| 8943 | attr = attr->next; |
| 8944 | } |
| 8945 | /* |
| 8946 | * Extract and validate attributes. |
| 8947 | */ |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 8948 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8949 | /* |
| 8950 | * Attribute "base". |
| 8951 | */ |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 8952 | if ((xmlSchemaPValAttrQName(ctxt, schema, |
| 8953 | NULL, NULL, node, "base", &(type->baseNs), NULL, &(type->base)) == 0) && |
| 8954 | (type->base == NULL) && |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8955 | (ctxt->ctxtType->type == XML_SCHEMA_TYPE_COMPLEX)) { |
| 8956 | /* TODO: Think about the error code. */ |
| 8957 | xmlSchemaPMissingAttrErr(ctxt, |
| 8958 | XML_SCHEMAP_RESTRICTION_NONAME_NOREF, |
| 8959 | NULL, type, node, "base", NULL); |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 8960 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8961 | /* |
| 8962 | * And now for the children... |
| 8963 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8964 | ctxt->container = name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8965 | child = node->children; |
| 8966 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8967 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 8968 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8969 | } |
| 8970 | subtype = NULL; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8971 | if (ctxt->parentItem->type == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
| 8972 | if (IS_SCHEMA(child, "all")) { |
| 8973 | subtype = (xmlSchemaTypePtr) |
| 8974 | xmlSchemaParseAll(ctxt, schema, child); |
| 8975 | child = child->next; |
| 8976 | type->subtypes = subtype; |
| 8977 | } else if (IS_SCHEMA(child, "choice")) { |
| 8978 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 8979 | child = child->next; |
| 8980 | type->subtypes = subtype; |
| 8981 | } else if (IS_SCHEMA(child, "sequence")) { |
| 8982 | subtype = (xmlSchemaTypePtr) |
| 8983 | xmlSchemaParseSequence(ctxt, schema, child); |
| 8984 | child = child->next; |
| 8985 | type->subtypes = subtype; |
| 8986 | } else if (IS_SCHEMA(child, "group")) { |
| 8987 | subtype = (xmlSchemaTypePtr) |
| 8988 | xmlSchemaParseGroup(ctxt, schema, child, 0); |
| 8989 | child = child->next; |
| 8990 | type->subtypes = subtype; |
| 8991 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8992 | } else if (ctxt->ctxtType->type == XML_SCHEMA_TYPE_SIMPLE) { |
| 8993 | if (IS_SCHEMA(child, "simpleType")) { |
| 8994 | if (type->base != NULL) { |
| 8995 | /* |
| 8996 | * src-restriction-base-or-simpleType |
| 8997 | * Either the base [attribute] or the simpleType [child] of the |
| 8998 | * <restriction> element must be present, but not both. |
| 8999 | */ |
| 9000 | xmlSchemaPContentErr(ctxt, |
| 9001 | XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE, |
| 9002 | NULL, NULL, type->node, child, |
| 9003 | "The attribute 'base' and the <simpleType> child are " |
| 9004 | "mutually exclusive", NULL); |
| 9005 | } else { |
| 9006 | subtype = (xmlSchemaTypePtr) |
| 9007 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
| 9008 | type->baseType = subtype; |
| 9009 | } |
| 9010 | child = child->next; |
| 9011 | } |
| 9012 | } else if (ctxt->parentItem->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9013 | if (IS_SCHEMA(child, "simpleType")) { |
| 9014 | subtype = (xmlSchemaTypePtr) |
| 9015 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9016 | type->subtypes = subtype; |
| 9017 | child = child->next; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9018 | } |
| 9019 | } |
| 9020 | if ((ctxt->ctxtType->type == XML_SCHEMA_TYPE_SIMPLE) || |
| 9021 | (ctxt->parentItem->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT)) { |
| 9022 | xmlSchemaFacetPtr facet, lastfacet = NULL; |
| 9023 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9024 | /* |
| 9025 | * Add the facets to the parent simpleType/complexType. |
| 9026 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9027 | /* |
| 9028 | * TODO: Datatypes: 4.1.3 Constraints on XML Representation of |
| 9029 | * Simple Type Definition Schema Representation Constraint: |
| 9030 | * *Single Facet Value* |
| 9031 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9032 | while ((IS_SCHEMA(child, "minInclusive")) || |
| 9033 | (IS_SCHEMA(child, "minExclusive")) || |
| 9034 | (IS_SCHEMA(child, "maxInclusive")) || |
| 9035 | (IS_SCHEMA(child, "maxExclusive")) || |
| 9036 | (IS_SCHEMA(child, "totalDigits")) || |
| 9037 | (IS_SCHEMA(child, "fractionDigits")) || |
| 9038 | (IS_SCHEMA(child, "pattern")) || |
| 9039 | (IS_SCHEMA(child, "enumeration")) || |
| 9040 | (IS_SCHEMA(child, "whiteSpace")) || |
| 9041 | (IS_SCHEMA(child, "length")) || |
| 9042 | (IS_SCHEMA(child, "maxLength")) || |
| 9043 | (IS_SCHEMA(child, "minLength"))) { |
| 9044 | facet = xmlSchemaParseFacet(ctxt, schema, child); |
| 9045 | if (facet != NULL) { |
| 9046 | if (lastfacet == NULL) |
| 9047 | ctxt->ctxtType->facets = facet; |
| 9048 | else |
| 9049 | lastfacet->next = facet; |
| 9050 | lastfacet = facet; |
| 9051 | lastfacet->next = NULL; |
| 9052 | } |
| 9053 | child = child->next; |
| 9054 | } |
| 9055 | /* |
| 9056 | * Create links for derivation and validation. |
| 9057 | */ |
| 9058 | if (lastfacet != NULL) { |
| 9059 | xmlSchemaFacetLinkPtr facetLink, lastFacetLink = NULL; |
| 9060 | |
| 9061 | facet = ctxt->ctxtType->facets; |
| 9062 | do { |
| 9063 | facetLink = (xmlSchemaFacetLinkPtr) xmlMalloc(sizeof(xmlSchemaFacetLink)); |
| 9064 | if (facetLink == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9065 | xmlSchemaPErrMemory(ctxt, "allocating a facet link", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9066 | xmlFree(facetLink); |
| 9067 | return (NULL); |
| 9068 | } |
| 9069 | facetLink->facet = facet; |
| 9070 | facetLink->next = NULL; |
| 9071 | if (lastFacetLink == NULL) |
| 9072 | ctxt->ctxtType->facetSet = facetLink; |
| 9073 | else |
| 9074 | lastFacetLink->next = facetLink; |
| 9075 | lastFacetLink = facetLink; |
| 9076 | facet = facet->next; |
| 9077 | } while (facet != NULL); |
| 9078 | } |
| 9079 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9080 | if (ctxt->ctxtType->type == XML_SCHEMA_TYPE_COMPLEX) { |
| 9081 | child = xmlSchemaParseAttrDecls(ctxt, schema, child, type); |
| 9082 | if (IS_SCHEMA(child, "anyAttribute")) { |
| 9083 | ctxt->ctxtType->attributeWildcard = xmlSchemaParseAnyAttribute(ctxt, schema, child); |
| 9084 | child = child->next; |
| 9085 | } |
| 9086 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9087 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9088 | /* TODO: Think about the error code. */ |
| 9089 | if (ctxt->parentItem->type == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
| 9090 | xmlSchemaPContentErr(ctxt, |
| 9091 | XML_SCHEMAP_UNKNOWN_RESTRICTION_CHILD, |
| 9092 | NULL, type, node, child, NULL, |
| 9093 | "annotation?, (group | all | choice | sequence)?, " |
| 9094 | "((attribute | attributeGroup)*, anyAttribute?))"); |
| 9095 | } else if (ctxt->parentItem->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT) { |
| 9096 | xmlSchemaPContentErr(ctxt, |
| 9097 | XML_SCHEMAP_UNKNOWN_RESTRICTION_CHILD, |
| 9098 | NULL, type, node, child, NULL, |
| 9099 | "(annotation?, (simpleType?, (minExclusive | minInclusive | " |
| 9100 | "maxExclusive | maxInclusive | totalDigits | fractionDigits | " |
| 9101 | "length | minLength | maxLength | enumeration | whiteSpace | " |
| 9102 | "pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))"); |
| 9103 | } else { |
| 9104 | /* Simple type */ |
| 9105 | xmlSchemaPContentErr(ctxt, |
| 9106 | XML_SCHEMAP_UNKNOWN_RESTRICTION_CHILD, |
| 9107 | NULL, type, node, child, NULL, |
| 9108 | "(annotation?, (simpleType?, (minExclusive | minInclusive | " |
| 9109 | "maxExclusive | maxInclusive | totalDigits | fractionDigits | " |
| 9110 | "length | minLength | maxLength | enumeration | whiteSpace | " |
| 9111 | "pattern)*))"); |
| 9112 | } |
| 9113 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9114 | ctxt->container = oldcontainer; |
| 9115 | return (type); |
| 9116 | } |
| 9117 | |
| 9118 | /** |
| 9119 | * xmlSchemaParseExtension: |
| 9120 | * @ctxt: a schema validation context |
| 9121 | * @schema: the schema being built |
| 9122 | * @node: a subtree containing XML Schema informations |
| 9123 | * |
| 9124 | * parse a XML schema Extension definition |
| 9125 | * *WARNING* this interface is highly subject to change |
| 9126 | * |
| 9127 | * Returns the type definition or NULL in case of error |
| 9128 | */ |
| 9129 | static xmlSchemaTypePtr |
| 9130 | xmlSchemaParseExtension(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9131 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9132 | { |
| 9133 | xmlSchemaTypePtr type, subtype; |
| 9134 | xmlNodePtr child = NULL; |
| 9135 | xmlChar name[30]; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 9136 | const xmlChar *oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9137 | |
| 9138 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 9139 | return (NULL); |
| 9140 | |
| 9141 | oldcontainer = ctxt->container; |
| 9142 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 9143 | snprintf((char *) name, 30, "#ext%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9144 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9145 | if (type == NULL) |
| 9146 | return (NULL); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 9147 | type->type = XML_SCHEMA_TYPE_EXTENSION; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9148 | type->node = node; |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 9149 | |
| 9150 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
| 9151 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9152 | ctxt->container = name; |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 9153 | /* |
| 9154 | * Attribute "base". |
| 9155 | */ |
| 9156 | if ((xmlSchemaPValAttrQName(ctxt, schema, |
| 9157 | NULL, NULL, node, "base", &(type->baseNs), NULL, &(type->base)) == 0) && |
| 9158 | (type->base == NULL) && |
| 9159 | (ctxt->ctxtType->type == XML_SCHEMA_TYPE_COMPLEX)) { |
| 9160 | /* TODO: Think about the error code. */ |
| 9161 | xmlSchemaPMissingAttrErr(ctxt, |
| 9162 | XML_SCHEMAP_RESTRICTION_NONAME_NOREF, |
| 9163 | NULL, type, node, "base", NULL); |
| 9164 | } |
| 9165 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9166 | child = node->children; |
| 9167 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9168 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 9169 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9170 | } |
| 9171 | subtype = NULL; |
| 9172 | |
| 9173 | if (IS_SCHEMA(child, "all")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9174 | subtype = xmlSchemaParseAll(ctxt, schema, child); |
| 9175 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9176 | } else if (IS_SCHEMA(child, "choice")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9177 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 9178 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9179 | } else if (IS_SCHEMA(child, "sequence")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9180 | subtype = xmlSchemaParseSequence(ctxt, schema, child); |
| 9181 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9182 | } else if (IS_SCHEMA(child, "group")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9183 | subtype = xmlSchemaParseGroup(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9184 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9185 | } |
| 9186 | if (subtype != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9187 | type->subtypes = subtype; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9188 | if ((ctxt->ctxtType != NULL) && |
| 9189 | (ctxt->ctxtType->type == XML_SCHEMA_TYPE_COMPLEX)) { |
| 9190 | child = xmlSchemaParseAttrDecls(ctxt, schema, child, type); |
| 9191 | if (IS_SCHEMA(child, "anyAttribute")) { |
| 9192 | ctxt->ctxtType->attributeWildcard = |
| 9193 | xmlSchemaParseAnyAttribute(ctxt, schema, child); |
| 9194 | child = child->next; |
| 9195 | } |
| 9196 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9197 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9198 | xmlSchemaPErr2(ctxt, node, child, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9199 | XML_SCHEMAP_UNKNOWN_EXTENSION_CHILD, |
| 9200 | "<extension> has unexpected content.\n", type->name, |
| 9201 | NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9202 | } |
| 9203 | ctxt->container = oldcontainer; |
| 9204 | return (type); |
| 9205 | } |
| 9206 | |
| 9207 | /** |
| 9208 | * xmlSchemaParseSimpleContent: |
| 9209 | * @ctxt: a schema validation context |
| 9210 | * @schema: the schema being built |
| 9211 | * @node: a subtree containing XML Schema informations |
| 9212 | * |
| 9213 | * parse a XML schema SimpleContent definition |
| 9214 | * *WARNING* this interface is highly subject to change |
| 9215 | * |
| 9216 | * Returns the type definition or NULL in case of error |
| 9217 | */ |
| 9218 | static xmlSchemaTypePtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9219 | xmlSchemaParseSimpleContent(xmlSchemaParserCtxtPtr ctxt, |
| 9220 | xmlSchemaPtr schema, xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9221 | { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9222 | xmlSchemaTypePtr type, subtype, oldParentItem; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9223 | xmlNodePtr child = NULL; |
| 9224 | xmlChar name[30]; |
| 9225 | |
| 9226 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 9227 | return (NULL); |
| 9228 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 9229 | snprintf((char *) name, 30, "#SC%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9230 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9231 | if (type == NULL) |
| 9232 | return (NULL); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 9233 | type->type = XML_SCHEMA_TYPE_SIMPLE_CONTENT; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9234 | type->node = node; |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 9235 | |
| 9236 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9237 | |
| 9238 | child = node->children; |
| 9239 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9240 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 9241 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9242 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9243 | oldParentItem = ctxt->parentItem; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9244 | ctxt->parentItem = type; |
| 9245 | subtype = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9246 | if (IS_SCHEMA(child, "restriction")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9247 | subtype = (xmlSchemaTypePtr) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 9248 | xmlSchemaParseRestriction(ctxt, schema, child); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9249 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9250 | } else if (IS_SCHEMA(child, "extension")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9251 | subtype = (xmlSchemaTypePtr) |
| 9252 | xmlSchemaParseExtension(ctxt, schema, child); |
| 9253 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9254 | } |
| 9255 | type->subtypes = subtype; |
| 9256 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9257 | xmlSchemaPErr2(ctxt, node, child, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9258 | XML_SCHEMAP_UNKNOWN_SIMPLECONTENT_CHILD, |
| 9259 | "<simpleContent> has unexpected content.\n", |
| 9260 | NULL, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9261 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9262 | ctxt->parentItem = oldParentItem; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9263 | return (type); |
| 9264 | } |
| 9265 | |
| 9266 | /** |
| 9267 | * xmlSchemaParseComplexContent: |
| 9268 | * @ctxt: a schema validation context |
| 9269 | * @schema: the schema being built |
| 9270 | * @node: a subtree containing XML Schema informations |
| 9271 | * |
| 9272 | * parse a XML schema ComplexContent definition |
| 9273 | * *WARNING* this interface is highly subject to change |
| 9274 | * |
| 9275 | * Returns the type definition or NULL in case of error |
| 9276 | */ |
| 9277 | static xmlSchemaTypePtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9278 | xmlSchemaParseComplexContent(xmlSchemaParserCtxtPtr ctxt, |
| 9279 | xmlSchemaPtr schema, xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9280 | { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9281 | xmlSchemaTypePtr type, subtype, oldParentItem; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9282 | xmlNodePtr child = NULL; |
| 9283 | xmlChar name[30]; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9284 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9285 | |
| 9286 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 9287 | return (NULL); |
| 9288 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 9289 | snprintf((char *) name, 30, "#CC%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9290 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9291 | if (type == NULL) |
| 9292 | return (NULL); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 9293 | type->type = XML_SCHEMA_TYPE_COMPLEX_CONTENT; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9294 | type->node = node; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9295 | /* |
| 9296 | * Check for illegal attributes. |
| 9297 | */ |
| 9298 | attr = node->properties; |
| 9299 | while (attr != NULL) { |
| 9300 | if (attr->ns == NULL) { |
| 9301 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 9302 | (!xmlStrEqual(attr->name, BAD_CAST "mixed"))) |
| 9303 | { |
| 9304 | xmlSchemaPIllegalAttrErr(ctxt, |
| 9305 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 9306 | NULL, NULL, attr); |
| 9307 | } |
| 9308 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 9309 | xmlSchemaPIllegalAttrErr(ctxt, |
| 9310 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 9311 | NULL, NULL, attr); |
| 9312 | } |
| 9313 | attr = attr->next; |
| 9314 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 9315 | |
| 9316 | xmlSchemaPValAttrID(ctxt, NULL, NULL, node, BAD_CAST "id"); |
| 9317 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9318 | /* |
| 9319 | * Handle attribute 'mixed'. |
| 9320 | */ |
| 9321 | if (xmlGetBooleanProp(ctxt, NULL, type, node, "mixed", 0)) { |
| 9322 | if ((ctxt->ctxtType->flags & XML_SCHEMAS_TYPE_MIXED) == 0) |
| 9323 | ctxt->ctxtType->flags |= XML_SCHEMAS_TYPE_MIXED; |
| 9324 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9325 | child = node->children; |
| 9326 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9327 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 9328 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9329 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9330 | oldParentItem = ctxt->parentItem; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9331 | ctxt->parentItem = type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9332 | subtype = NULL; |
| 9333 | if (IS_SCHEMA(child, "restriction")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9334 | subtype = (xmlSchemaTypePtr) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 9335 | xmlSchemaParseRestriction(ctxt, schema, child); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9336 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9337 | } else if (IS_SCHEMA(child, "extension")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9338 | subtype = (xmlSchemaTypePtr) |
| 9339 | xmlSchemaParseExtension(ctxt, schema, child); |
| 9340 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9341 | } |
| 9342 | type->subtypes = subtype; |
| 9343 | if (child != NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9344 | xmlSchemaPContentErr(ctxt, |
| 9345 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 9346 | NULL, NULL, node, child, |
| 9347 | NULL, "(annotation?, (restriction | extension))"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9348 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9349 | ctxt->parentItem = oldParentItem; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9350 | return (type); |
| 9351 | } |
| 9352 | |
| 9353 | /** |
| 9354 | * xmlSchemaParseComplexType: |
| 9355 | * @ctxt: a schema validation context |
| 9356 | * @schema: the schema being built |
| 9357 | * @node: a subtree containing XML Schema informations |
| 9358 | * |
| 9359 | * parse a XML schema Complex Type definition |
| 9360 | * *WARNING* this interface is highly subject to change |
| 9361 | * |
| 9362 | * Returns the type definition or NULL in case of error |
| 9363 | */ |
| 9364 | static xmlSchemaTypePtr |
| 9365 | xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9366 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9367 | { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9368 | xmlSchemaTypePtr type, subtype, ctxtType; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9369 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9370 | const xmlChar *name = NULL; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 9371 | const xmlChar *oldcontainer; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9372 | xmlAttrPtr attr; |
| 9373 | const xmlChar *attrValue; |
| 9374 | xmlChar *des = NULL; /* The reported designation. */ |
Daniel Veillard | 1a380b8 | 2004-10-21 16:00:06 +0000 | [diff] [blame] | 9375 | char buf[40]; |
| 9376 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9377 | |
| 9378 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 9379 | return (NULL); |
| 9380 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9381 | ctxtType = ctxt->ctxtType; |
| 9382 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9383 | if (topLevel) { |
| 9384 | attr = xmlSchemaGetPropNode(node, "name"); |
| 9385 | if (attr == NULL) { |
| 9386 | xmlSchemaPMissingAttrErr(ctxt, |
| 9387 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 9388 | (xmlChar **) &xmlSchemaElemDesCT, NULL, node, |
| 9389 | "name", NULL); |
| 9390 | return (NULL); |
| 9391 | } else if (xmlSchemaPValAttrNode(ctxt, |
| 9392 | (xmlChar **) &xmlSchemaElemDesCT, NULL, attr, |
| 9393 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 9394 | return (NULL); |
| 9395 | } |
| 9396 | } |
| 9397 | |
| 9398 | if (topLevel == 0) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9399 | /* |
| 9400 | * Parse as local complex type definition. |
| 9401 | */ |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 9402 | snprintf(buf, 39, "#CT%d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9403 | type = xmlSchemaAddType(ctxt, schema, (const xmlChar *)buf, NULL, node); |
| 9404 | if (type == NULL) |
| 9405 | return (NULL); |
| 9406 | name = (const xmlChar *) buf; |
| 9407 | type->node = node; |
| 9408 | type->type = XML_SCHEMA_TYPE_COMPLEX; |
| 9409 | /* |
| 9410 | * TODO: We need the target namespace. |
| 9411 | */ |
| 9412 | } else { |
| 9413 | /* |
| 9414 | * Parse as global complex type definition. |
| 9415 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9416 | type = xmlSchemaAddType(ctxt, schema, name, schema->targetNamespace, node); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9417 | if (type == NULL) |
| 9418 | return (NULL); |
| 9419 | type->node = node; |
| 9420 | type->type = XML_SCHEMA_TYPE_COMPLEX; |
| 9421 | type->flags |= XML_SCHEMAS_TYPE_GLOBAL; |
| 9422 | /* |
| 9423 | * Set defaults. |
| 9424 | */ |
| 9425 | type->flags |= XML_SCHEMAS_TYPE_FINAL_DEFAULT; |
| 9426 | type->flags |= XML_SCHEMAS_TYPE_BLOCK_DEFAULT; |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 9427 | } |
| 9428 | type->targetNamespace = schema->targetNamespace; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9429 | /* |
| 9430 | * Handle attributes. |
| 9431 | */ |
| 9432 | attr = node->properties; |
| 9433 | while (attr != NULL) { |
| 9434 | if (attr->ns == NULL) { |
| 9435 | if (xmlStrEqual(attr->name, BAD_CAST "id")) { |
| 9436 | /* |
| 9437 | * Attribute "id". |
| 9438 | */ |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 9439 | xmlSchemaPValAttrID(ctxt, NULL, type, node, |
| 9440 | BAD_CAST "id"); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9441 | } else if (xmlStrEqual(attr->name, BAD_CAST "mixed")) { |
| 9442 | /* |
| 9443 | * Attribute "mixed". |
| 9444 | */ |
| 9445 | if (xmlSchemaPGetBoolNodeValue(ctxt, &des, type, |
| 9446 | (xmlNodePtr) attr)) |
| 9447 | type->flags |= XML_SCHEMAS_TYPE_MIXED; |
| 9448 | } else if (topLevel) { |
| 9449 | /* |
| 9450 | * Attributes of global complex type definitions. |
| 9451 | */ |
| 9452 | if (xmlStrEqual(attr->name, BAD_CAST "name")) { |
| 9453 | /* Pass. */ |
| 9454 | } else if (xmlStrEqual(attr->name, BAD_CAST "abstract")) { |
| 9455 | /* |
| 9456 | * Attribute "abstract". |
| 9457 | */ |
| 9458 | if (xmlSchemaPGetBoolNodeValue(ctxt, &des, type, |
| 9459 | (xmlNodePtr) attr)) |
| 9460 | type->flags |= XML_SCHEMAS_TYPE_ABSTRACT; |
| 9461 | } else if (xmlStrEqual(attr->name, BAD_CAST "final")) { |
| 9462 | /* |
| 9463 | * Attribute "final". |
| 9464 | */ |
| 9465 | attrValue = xmlSchemaGetNodeContent(ctxt, |
| 9466 | (xmlNodePtr) attr); |
| 9467 | if (xmlSchemaPValAttrBlockFinal(attrValue, |
| 9468 | &(type->flags), |
| 9469 | -1, |
| 9470 | XML_SCHEMAS_TYPE_FINAL_EXTENSION, |
| 9471 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION, |
| 9472 | -1, -1, -1) != 0) |
| 9473 | { |
| 9474 | xmlSchemaPSimpleTypeErr(ctxt, |
| 9475 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 9476 | &des, type, (xmlNodePtr) attr, |
| 9477 | NULL, |
| 9478 | "(#all | List of (extension | restriction))", |
| 9479 | attrValue, NULL, NULL, NULL); |
| 9480 | } |
| 9481 | } else if (xmlStrEqual(attr->name, BAD_CAST "block")) { |
| 9482 | /* |
| 9483 | * Attribute "block". |
| 9484 | */ |
| 9485 | attrValue = xmlSchemaGetNodeContent(ctxt, |
| 9486 | (xmlNodePtr) attr); |
| 9487 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(type->flags), |
| 9488 | -1, |
| 9489 | XML_SCHEMAS_TYPE_BLOCK_EXTENSION, |
| 9490 | XML_SCHEMAS_TYPE_BLOCK_RESTRICTION, |
| 9491 | -1, -1, -1) != 0) { |
| 9492 | xmlSchemaPSimpleTypeErr(ctxt, |
| 9493 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 9494 | &des, type, (xmlNodePtr) attr, |
| 9495 | NULL, |
| 9496 | "(#all | List of (extension | restriction)) ", |
| 9497 | attrValue, NULL, NULL, NULL); |
| 9498 | } |
| 9499 | } else { |
| 9500 | xmlSchemaPIllegalAttrErr(ctxt, |
| 9501 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 9502 | &des, type, attr); |
| 9503 | } |
| 9504 | } else { |
| 9505 | xmlSchemaPIllegalAttrErr(ctxt, |
| 9506 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 9507 | &des, type, attr); |
| 9508 | } |
| 9509 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 9510 | xmlSchemaPIllegalAttrErr(ctxt, |
| 9511 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 9512 | &des, type, attr); |
| 9513 | } |
| 9514 | attr = attr->next; |
| 9515 | } |
| 9516 | /* |
| 9517 | * Set as default for attribute wildcards. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9518 | * This will be only changed if a complex type |
| 9519 | * inherits an attribute wildcard from a base type. |
| 9520 | */ |
| 9521 | type->flags |= XML_SCHEMAS_TYPE_OWNED_ATTR_WILDCARD; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9522 | /* |
| 9523 | * And now for the children... |
| 9524 | */ |
| 9525 | oldcontainer = ctxt->container; |
| 9526 | ctxt->container = name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9527 | child = node->children; |
| 9528 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9529 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 9530 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9531 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9532 | ctxt->ctxtType = type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9533 | if (IS_SCHEMA(child, "simpleContent")) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9534 | /* |
| 9535 | * 3.4.3 : 2.2 |
| 9536 | * Specifying mixed='true' when the <simpleContent> |
| 9537 | * alternative is chosen has no effect |
| 9538 | */ |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 9539 | if (type->flags & XML_SCHEMAS_TYPE_MIXED) |
| 9540 | type->flags ^= XML_SCHEMAS_TYPE_MIXED; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9541 | type->subtypes = xmlSchemaParseSimpleContent(ctxt, schema, child); |
| 9542 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9543 | } else if (IS_SCHEMA(child, "complexContent")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9544 | type->subtypes = xmlSchemaParseComplexContent(ctxt, schema, child); |
| 9545 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9546 | } else { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9547 | subtype = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9548 | /* |
| 9549 | * Parse model groups. |
| 9550 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9551 | if (IS_SCHEMA(child, "all")) { |
| 9552 | subtype = xmlSchemaParseAll(ctxt, schema, child); |
| 9553 | child = child->next; |
| 9554 | } else if (IS_SCHEMA(child, "choice")) { |
| 9555 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 9556 | child = child->next; |
| 9557 | } else if (IS_SCHEMA(child, "sequence")) { |
| 9558 | subtype = xmlSchemaParseSequence(ctxt, schema, child); |
| 9559 | child = child->next; |
| 9560 | } else if (IS_SCHEMA(child, "group")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9561 | subtype = xmlSchemaParseGroup(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9562 | child = child->next; |
| 9563 | } |
| 9564 | if (subtype != NULL) |
| 9565 | type->subtypes = subtype; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9566 | /* |
| 9567 | * Parse attribute decls/refs. |
| 9568 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9569 | child = xmlSchemaParseAttrDecls(ctxt, schema, child, type); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9570 | /* |
| 9571 | * Parse attribute wildcard. |
| 9572 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9573 | if (IS_SCHEMA(child, "anyAttribute")) { |
| 9574 | type->attributeWildcard = xmlSchemaParseAnyAttribute(ctxt, schema, child); |
| 9575 | child = child->next; |
| 9576 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9577 | } |
| 9578 | if (child != NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9579 | xmlSchemaPContentErr(ctxt, |
| 9580 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 9581 | &des, type, node, child, |
| 9582 | NULL, "(annotation?, (simpleContent | complexContent | " |
| 9583 | "((group | all | choice | sequence)?, ((attribute | " |
| 9584 | "attributeGroup)*, anyAttribute?))))"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9585 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9586 | FREE_AND_NULL(des); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9587 | ctxt->container = oldcontainer; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9588 | ctxt->ctxtType = ctxtType; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9589 | return (type); |
| 9590 | } |
| 9591 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9592 | /** |
| 9593 | * xmlSchemaParseSchema: |
| 9594 | * @ctxt: a schema validation context |
| 9595 | * @node: a subtree containing XML Schema informations |
| 9596 | * |
| 9597 | * parse a XML schema definition from a node set |
| 9598 | * *WARNING* this interface is highly subject to change |
| 9599 | * |
| 9600 | * Returns the internal XML Schema structure built from the resource or |
| 9601 | * NULL in case of error |
| 9602 | */ |
| 9603 | static xmlSchemaPtr |
| 9604 | xmlSchemaParseSchema(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node) |
| 9605 | { |
| 9606 | xmlSchemaPtr schema = NULL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 9607 | const xmlChar *val; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 9608 | int nberrors; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9609 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9610 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9611 | /* |
| 9612 | * This one is called by xmlSchemaParse only and is used if |
| 9613 | * the schema to be parsed was specified via the API; i.e. not |
| 9614 | * automatically by the validated instance document. |
| 9615 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9616 | if ((ctxt == NULL) || (node == NULL)) |
| 9617 | return (NULL); |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 9618 | nberrors = ctxt->nberrors; |
| 9619 | ctxt->nberrors = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9620 | if (IS_SCHEMA(node, "schema")) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9621 | xmlSchemaImportPtr import; |
| 9622 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9623 | schema = xmlSchemaNewSchema(ctxt); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9624 | if (schema == NULL) |
| 9625 | return (NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9626 | /* |
| 9627 | * Disable build of list of items. |
| 9628 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9629 | attr = xmlSchemaGetPropNode(node, "targetNamespace"); |
| 9630 | if (attr != NULL) { |
| 9631 | xmlSchemaPValAttrNode(ctxt, NULL, NULL, attr, |
| 9632 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), &val); |
| 9633 | /* |
| 9634 | * TODO: Should we proceed with an invalid target namespace? |
| 9635 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 9636 | schema->targetNamespace = xmlDictLookup(ctxt->dict, val, -1); |
| 9637 | } else { |
| 9638 | schema->targetNamespace = NULL; |
| 9639 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9640 | /* |
| 9641 | * Add the current ns name and location to the import table; |
| 9642 | * this is needed to have a consistent mechanism, regardless |
| 9643 | * if all schemata are constructed dynamically fired by the |
| 9644 | * instance or if the schema to be used was specified via |
| 9645 | * the API. |
| 9646 | */ |
| 9647 | import = xmlSchemaAddImport(ctxt, &(schema->schemasImports), |
| 9648 | schema->targetNamespace); |
| 9649 | if (import == NULL) { |
| 9650 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_FAILED_BUILD_IMPORT, |
| 9651 | NULL, NULL, (xmlNodePtr) ctxt->doc, |
| 9652 | "Internal error: xmlSchemaParseSchema, " |
| 9653 | "failed to add an import entry", NULL); |
| 9654 | xmlSchemaFree(schema); |
| 9655 | schema = NULL; |
| 9656 | return (NULL); |
| 9657 | } |
| 9658 | import->schemaLocation = ctxt->URL; |
| 9659 | /* |
| 9660 | * NOTE: We won't set the doc here, otherwise it will be freed |
| 9661 | * if the import struct is freed. |
| 9662 | * import->doc = ctxt->doc; |
| 9663 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9664 | xmlSchemaParseSchemaDefaults(ctxt, schema, node); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9665 | xmlSchemaParseSchemaTopLevel(ctxt, schema, node->children); |
| 9666 | } else { |
| 9667 | xmlDocPtr doc; |
| 9668 | |
| 9669 | doc = node->doc; |
| 9670 | |
| 9671 | if ((doc != NULL) && (doc->URL != NULL)) { |
| 9672 | xmlSchemaPErr(ctxt, (xmlNodePtr) doc, |
| 9673 | XML_SCHEMAP_NOT_SCHEMA, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9674 | "The file \"%s\" is not a XML schema.\n", doc->URL, NULL); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9675 | } else { |
| 9676 | xmlSchemaPErr(ctxt, (xmlNodePtr) doc, |
| 9677 | XML_SCHEMAP_NOT_SCHEMA, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9678 | "The file is not a XML schema.\n", NULL, NULL); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9679 | } |
| 9680 | return(NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9681 | } |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 9682 | if (ctxt->nberrors != 0) { |
| 9683 | if (schema != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9684 | xmlSchemaFree(schema); |
| 9685 | schema = NULL; |
| 9686 | } |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 9687 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9688 | if (schema != NULL) |
| 9689 | schema->counter = ctxt->counter; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 9690 | ctxt->nberrors = nberrors; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9691 | #ifdef DEBUG |
| 9692 | if (schema == NULL) |
| 9693 | xmlGenericError(xmlGenericErrorContext, |
| 9694 | "xmlSchemaParse() failed\n"); |
| 9695 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9696 | return (schema); |
| 9697 | } |
| 9698 | |
| 9699 | /************************************************************************ |
| 9700 | * * |
| 9701 | * Validating using Schemas * |
| 9702 | * * |
| 9703 | ************************************************************************/ |
| 9704 | |
| 9705 | /************************************************************************ |
| 9706 | * * |
| 9707 | * Reading/Writing Schemas * |
| 9708 | * * |
| 9709 | ************************************************************************/ |
| 9710 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9711 | #if 0 /* Will be enabled if it is clear what options are needed. */ |
| 9712 | /** |
| 9713 | * xmlSchemaParserCtxtSetOptions: |
| 9714 | * @ctxt: a schema parser context |
| 9715 | * @options: a combination of xmlSchemaParserOption |
| 9716 | * |
| 9717 | * Sets the options to be used during the parse. |
| 9718 | * |
| 9719 | * Returns 0 in case of success, -1 in case of an |
| 9720 | * API error. |
| 9721 | */ |
| 9722 | static int |
| 9723 | xmlSchemaParserCtxtSetOptions(xmlSchemaParserCtxtPtr ctxt, |
| 9724 | int options) |
| 9725 | |
| 9726 | { |
| 9727 | int i; |
| 9728 | |
| 9729 | if (ctxt == NULL) |
| 9730 | return (-1); |
| 9731 | /* |
| 9732 | * WARNING: Change the start value if adding to the |
| 9733 | * xmlSchemaParseOption. |
| 9734 | */ |
| 9735 | for (i = 1; i < (int) sizeof(int) * 8; i++) { |
| 9736 | if (options & 1<<i) { |
| 9737 | return (-1); |
| 9738 | } |
| 9739 | } |
| 9740 | ctxt->options = options; |
| 9741 | return (0); |
| 9742 | } |
| 9743 | |
| 9744 | /** |
| 9745 | * xmlSchemaValidCtxtGetOptions: |
| 9746 | * @ctxt: a schema parser context |
| 9747 | * |
| 9748 | * Returns the option combination of the parser context. |
| 9749 | */ |
| 9750 | static int |
| 9751 | xmlSchemaParserCtxtGetOptions(xmlSchemaParserCtxtPtr ctxt) |
| 9752 | |
| 9753 | { |
| 9754 | if (ctxt == NULL) |
| 9755 | return (-1); |
| 9756 | else |
| 9757 | return (ctxt->options); |
| 9758 | } |
| 9759 | |
| 9760 | void *curItems; /* used for dynamic addition of schemata */ |
| 9761 | int nbCurItems; /* used for dynamic addition of schemata */ |
| 9762 | int sizeCurItems; /* used for dynamic addition of schemata */ |
| 9763 | |
| 9764 | #endif |
| 9765 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9766 | /** |
| 9767 | * xmlSchemaNewParserCtxt: |
| 9768 | * @URL: the location of the schema |
| 9769 | * |
| 9770 | * Create an XML Schemas parse context for that file/resource expected |
| 9771 | * to contain an XML Schemas file. |
| 9772 | * |
| 9773 | * Returns the parser context or NULL in case of error |
| 9774 | */ |
| 9775 | xmlSchemaParserCtxtPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9776 | xmlSchemaNewParserCtxt(const char *URL) |
| 9777 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9778 | xmlSchemaParserCtxtPtr ret; |
| 9779 | |
| 9780 | if (URL == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9781 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9782 | |
| 9783 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 9784 | if (ret == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9785 | xmlSchemaPErrMemory(NULL, "allocating schema parser context", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9786 | NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9787 | return (NULL); |
| 9788 | } |
| 9789 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 9790 | ret->dict = xmlDictCreate(); |
| 9791 | ret->URL = xmlDictLookup(ret->dict, (const xmlChar *) URL, -1); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 9792 | ret->includes = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9793 | return (ret); |
| 9794 | } |
| 9795 | |
| 9796 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9797 | * xmlSchemaNewParserCtxtUseDict: |
| 9798 | * @URL: the location of the schema |
| 9799 | * @dict: the dictionary to be used |
| 9800 | * |
| 9801 | * Create an XML Schemas parse context for that file/resource expected |
| 9802 | * to contain an XML Schemas file. |
| 9803 | * |
| 9804 | * Returns the parser context or NULL in case of error |
| 9805 | */ |
| 9806 | static xmlSchemaParserCtxtPtr |
| 9807 | xmlSchemaNewParserCtxtUseDict(const char *URL, xmlDictPtr dict) |
| 9808 | { |
| 9809 | xmlSchemaParserCtxtPtr ret; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9810 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9811 | if (URL == NULL) |
| 9812 | return (NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9813 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9814 | |
| 9815 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 9816 | if (ret == NULL) { |
| 9817 | xmlSchemaPErrMemory(NULL, "allocating schema parser context", |
| 9818 | NULL); |
| 9819 | return (NULL); |
| 9820 | } |
| 9821 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
| 9822 | ret->dict = dict; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9823 | xmlDictReference(dict); |
| 9824 | if (URL != NULL) |
| 9825 | ret->URL = xmlDictLookup(dict, (const xmlChar *) URL, -1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9826 | ret->includes = 0; |
| 9827 | return (ret); |
| 9828 | } |
| 9829 | |
| 9830 | |
| 9831 | /** |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 9832 | * xmlSchemaNewMemParserCtxt: |
| 9833 | * @buffer: a pointer to a char array containing the schemas |
| 9834 | * @size: the size of the array |
| 9835 | * |
| 9836 | * Create an XML Schemas parse context for that memory buffer expected |
| 9837 | * to contain an XML Schemas file. |
| 9838 | * |
| 9839 | * Returns the parser context or NULL in case of error |
| 9840 | */ |
| 9841 | xmlSchemaParserCtxtPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9842 | xmlSchemaNewMemParserCtxt(const char *buffer, int size) |
| 9843 | { |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 9844 | xmlSchemaParserCtxtPtr ret; |
| 9845 | |
| 9846 | if ((buffer == NULL) || (size <= 0)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9847 | return (NULL); |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 9848 | |
| 9849 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 9850 | if (ret == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9851 | xmlSchemaPErrMemory(NULL, "allocating schema parser context", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9852 | NULL); |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 9853 | return (NULL); |
| 9854 | } |
| 9855 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
| 9856 | ret->buffer = buffer; |
| 9857 | ret->size = size; |
William M. Brack | cf9eadf | 2003-12-25 13:24:05 +0000 | [diff] [blame] | 9858 | ret->dict = xmlDictCreate(); |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 9859 | return (ret); |
| 9860 | } |
| 9861 | |
| 9862 | /** |
Daniel Veillard | 9d75150 | 2003-10-29 13:21:47 +0000 | [diff] [blame] | 9863 | * xmlSchemaNewDocParserCtxt: |
| 9864 | * @doc: a preparsed document tree |
| 9865 | * |
| 9866 | * Create an XML Schemas parse context for that document. |
| 9867 | * NB. The document may be modified during the parsing process. |
| 9868 | * |
| 9869 | * Returns the parser context or NULL in case of error |
| 9870 | */ |
| 9871 | xmlSchemaParserCtxtPtr |
| 9872 | xmlSchemaNewDocParserCtxt(xmlDocPtr doc) |
| 9873 | { |
| 9874 | xmlSchemaParserCtxtPtr ret; |
| 9875 | |
| 9876 | if (doc == NULL) |
| 9877 | return (NULL); |
| 9878 | |
| 9879 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 9880 | if (ret == NULL) { |
| 9881 | xmlSchemaPErrMemory(NULL, "allocating schema parser context", |
| 9882 | NULL); |
| 9883 | return (NULL); |
| 9884 | } |
| 9885 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
| 9886 | ret->doc = doc; |
William M. Brack | cf9eadf | 2003-12-25 13:24:05 +0000 | [diff] [blame] | 9887 | ret->dict = xmlDictCreate(); |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 9888 | /* The application has responsibility for the document */ |
| 9889 | ret->preserve = 1; |
Daniel Veillard | 9d75150 | 2003-10-29 13:21:47 +0000 | [diff] [blame] | 9890 | |
| 9891 | return (ret); |
| 9892 | } |
| 9893 | |
| 9894 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9895 | * xmlSchemaFreeParserCtxt: |
| 9896 | * @ctxt: the schema parser context |
| 9897 | * |
| 9898 | * Free the resources associated to the schema parser context |
| 9899 | */ |
| 9900 | void |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9901 | xmlSchemaFreeParserCtxt(xmlSchemaParserCtxtPtr ctxt) |
| 9902 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9903 | if (ctxt == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9904 | return; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 9905 | if (ctxt->doc != NULL && !ctxt->preserve) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9906 | xmlFreeDoc(ctxt->doc); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9907 | if (ctxt->assemble != NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9908 | xmlFree((xmlSchemaTypePtr *) ctxt->assemble->items); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9909 | xmlFree(ctxt->assemble); |
| 9910 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9911 | if (ctxt->vctxt != NULL) { |
| 9912 | xmlSchemaFreeValidCtxt(ctxt->vctxt); |
| 9913 | } |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 9914 | if (ctxt->localImports != NULL) |
| 9915 | xmlFree((xmlChar *) ctxt->localImports); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 9916 | xmlDictFree(ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9917 | xmlFree(ctxt); |
| 9918 | } |
| 9919 | |
| 9920 | /************************************************************************ |
| 9921 | * * |
| 9922 | * Building the content models * |
| 9923 | * * |
| 9924 | ************************************************************************/ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9925 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9926 | /** |
| 9927 | * xmlSchemaBuildAContentModel: |
| 9928 | * @type: the schema type definition |
| 9929 | * @ctxt: the schema parser context |
| 9930 | * @name: the element name whose content is being built |
| 9931 | * |
| 9932 | * Generate the automata sequence needed for that type |
| 9933 | */ |
| 9934 | static void |
| 9935 | xmlSchemaBuildAContentModel(xmlSchemaTypePtr type, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9936 | xmlSchemaParserCtxtPtr ctxt, |
| 9937 | const xmlChar * name) |
| 9938 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9939 | if (type == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9940 | xmlGenericError(xmlGenericErrorContext, |
| 9941 | "Found unexpected type = NULL in %s content model\n", |
| 9942 | name); |
| 9943 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9944 | } |
| 9945 | switch (type->type) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9946 | case XML_SCHEMA_TYPE_ANY: { |
| 9947 | xmlAutomataStatePtr start, end; |
| 9948 | xmlSchemaWildcardPtr wild; |
| 9949 | xmlSchemaWildcardNsPtr ns; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 9950 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9951 | wild = type->attributeWildcard; |
| 9952 | |
| 9953 | if (wild == NULL) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 9954 | xmlSchemaPErr(ctxt, type->node, XML_SCHEMAP_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9955 | "Internal error: xmlSchemaBuildAContentModel, " |
| 9956 | "no wildcard on xsd:any.\n", NULL, NULL); |
| 9957 | return; |
| 9958 | } |
| 9959 | |
| 9960 | start = ctxt->state; |
| 9961 | end = xmlAutomataNewState(ctxt->am); |
| 9962 | |
| 9963 | if (type->maxOccurs == 1) { |
| 9964 | if (wild->any == 1) { |
| 9965 | /* |
| 9966 | * We need to add both transitions: |
| 9967 | * |
| 9968 | * 1. the {"*", "*"} for elements in a namespace. |
| 9969 | */ |
| 9970 | ctxt->state = |
| 9971 | xmlAutomataNewTransition2(ctxt->am, |
| 9972 | start, NULL, BAD_CAST "*", BAD_CAST "*", type); |
| 9973 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 9974 | /* |
| 9975 | * 2. the {"*"} for elements in no namespace. |
| 9976 | */ |
| 9977 | ctxt->state = |
| 9978 | xmlAutomataNewTransition2(ctxt->am, |
| 9979 | start, NULL, BAD_CAST "*", NULL, type); |
| 9980 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 9981 | |
| 9982 | } else if (wild->nsSet != NULL) { |
| 9983 | ns = wild->nsSet; |
| 9984 | do { |
| 9985 | ctxt->state = start; |
| 9986 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 9987 | ctxt->state, NULL, BAD_CAST "*", ns->value, type); |
| 9988 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 9989 | ns = ns->next; |
| 9990 | } while (ns != NULL); |
| 9991 | |
| 9992 | } else if (wild->negNsSet != NULL) { |
| 9993 | xmlAutomataStatePtr deadEnd; |
| 9994 | |
| 9995 | deadEnd = xmlAutomataNewState(ctxt->am); |
| 9996 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 9997 | start, deadEnd, BAD_CAST "*", wild->negNsSet->value, type); |
| 9998 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 9999 | start, NULL, BAD_CAST "*", BAD_CAST "*", type); |
| 10000 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 10001 | } |
| 10002 | } else { |
| 10003 | int counter; |
| 10004 | xmlAutomataStatePtr hop; |
| 10005 | int maxOccurs = |
| 10006 | type->maxOccurs == UNBOUNDED ? UNBOUNDED : type->maxOccurs - 1; |
| 10007 | int minOccurs = |
| 10008 | type->minOccurs < 1 ? 0 : type->minOccurs - 1; |
| 10009 | |
| 10010 | counter = xmlAutomataNewCounter(ctxt->am, minOccurs, maxOccurs); |
| 10011 | hop = xmlAutomataNewState(ctxt->am); |
| 10012 | if (wild->any == 1) { |
| 10013 | ctxt->state = |
| 10014 | xmlAutomataNewTransition2(ctxt->am, |
| 10015 | start, NULL, BAD_CAST "*", BAD_CAST "*", type); |
| 10016 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 10017 | ctxt->state = |
| 10018 | xmlAutomataNewTransition2(ctxt->am, |
| 10019 | start, NULL, BAD_CAST "*", NULL, type); |
| 10020 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 10021 | } else if (wild->nsSet != NULL) { |
| 10022 | ns = wild->nsSet; |
| 10023 | do { |
| 10024 | ctxt->state = |
| 10025 | xmlAutomataNewTransition2(ctxt->am, |
| 10026 | start, NULL, BAD_CAST "*", ns->value, type); |
| 10027 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 10028 | ns = ns->next; |
| 10029 | } while (ns != NULL); |
| 10030 | |
| 10031 | } else if (wild->negNsSet != NULL) { |
| 10032 | xmlAutomataStatePtr deadEnd; |
| 10033 | |
| 10034 | deadEnd = xmlAutomataNewState(ctxt->am); |
| 10035 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 10036 | start, deadEnd, BAD_CAST "*", wild->negNsSet->value, type); |
| 10037 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 10038 | start, NULL, BAD_CAST "*", BAD_CAST "*", type); |
| 10039 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 10040 | } |
| 10041 | xmlAutomataNewCountedTrans(ctxt->am, hop, start, counter); |
| 10042 | xmlAutomataNewCounterTrans(ctxt->am, hop, end, counter); |
| 10043 | } |
| 10044 | if (type->minOccurs == 0) { |
| 10045 | xmlAutomataNewEpsilon(ctxt->am, start, end); |
| 10046 | } |
| 10047 | ctxt->state = end; |
| 10048 | break; |
| 10049 | } |
| 10050 | case XML_SCHEMA_TYPE_ELEMENT:{ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10051 | xmlAutomataStatePtr oldstate; |
| 10052 | xmlSchemaElementPtr particle, elemDecl; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 10053 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10054 | /* |
| 10055 | * IMPORTANT: This puts element declarations |
| 10056 | * (and never element decl. references) into the |
| 10057 | * automaton. This is crucial and should not be changed, |
| 10058 | * since validating functions rely now on it. |
| 10059 | */ |
| 10060 | particle = (xmlSchemaElementPtr) type; |
| 10061 | if (particle->ref != NULL) { |
| 10062 | if (particle->refDecl == NULL) { |
| 10063 | /* |
| 10064 | * Skip content model creation if the reference |
| 10065 | * did not resolve to a declaration. |
| 10066 | */ |
| 10067 | break; |
| 10068 | } else { |
| 10069 | /* |
| 10070 | * Referenced global element declaration. |
| 10071 | */ |
| 10072 | elemDecl = particle->refDecl; |
| 10073 | } |
| 10074 | } else { |
| 10075 | /* |
| 10076 | * Anonymous element declaration. |
| 10077 | */ |
| 10078 | elemDecl = particle; |
| 10079 | } |
| 10080 | |
| 10081 | oldstate = ctxt->state; |
| 10082 | |
| 10083 | if (particle->maxOccurs >= UNBOUNDED) { |
| 10084 | if (particle->minOccurs > 1) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10085 | xmlAutomataStatePtr tmp; |
| 10086 | int counter; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 10087 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10088 | ctxt->state = xmlAutomataNewEpsilon(ctxt->am, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10089 | oldstate, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10090 | oldstate = ctxt->state; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10091 | counter = xmlAutomataNewCounter(ctxt->am, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10092 | particle->minOccurs - 1, UNBOUNDED); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 10093 | ctxt->state = |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10094 | xmlAutomataNewTransition2(ctxt->am, |
| 10095 | ctxt->state, NULL, |
| 10096 | elemDecl->name, |
| 10097 | elemDecl->targetNamespace, |
| 10098 | (xmlSchemaTypePtr) elemDecl); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10099 | tmp = ctxt->state; |
| 10100 | xmlAutomataNewCountedTrans(ctxt->am, tmp, oldstate, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10101 | counter); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10102 | ctxt->state = |
| 10103 | xmlAutomataNewCounterTrans(ctxt->am, tmp, NULL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10104 | counter); |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 10105 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10106 | } else { |
| 10107 | ctxt->state = |
| 10108 | xmlAutomataNewTransition2(ctxt->am, |
| 10109 | ctxt->state, NULL, |
| 10110 | elemDecl->name, |
| 10111 | elemDecl->targetNamespace, |
| 10112 | (xmlSchemaTypePtr) elemDecl); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10113 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, |
| 10114 | oldstate); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10115 | if (particle->minOccurs == 0) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10116 | /* basically an elem* */ |
| 10117 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
| 10118 | ctxt->state); |
| 10119 | } |
| 10120 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10121 | } else if ((particle->maxOccurs > 1) || (particle->minOccurs > 1)) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10122 | xmlAutomataStatePtr tmp; |
| 10123 | int counter; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 10124 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10125 | ctxt->state = xmlAutomataNewEpsilon(ctxt->am, |
| 10126 | oldstate, NULL); |
| 10127 | oldstate = ctxt->state; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10128 | counter = xmlAutomataNewCounter(ctxt->am, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10129 | particle->minOccurs - 1, |
| 10130 | particle->maxOccurs - 1); |
| 10131 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 10132 | ctxt->state, |
| 10133 | NULL, |
| 10134 | elemDecl->name, |
| 10135 | elemDecl->targetNamespace, |
| 10136 | (xmlSchemaTypePtr) elemDecl); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10137 | tmp = ctxt->state; |
| 10138 | xmlAutomataNewCountedTrans(ctxt->am, tmp, oldstate, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10139 | counter); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10140 | ctxt->state = xmlAutomataNewCounterTrans(ctxt->am, tmp, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10141 | NULL, counter); |
| 10142 | if (particle->minOccurs == 0) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10143 | /* basically an elem? */ |
| 10144 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10145 | ctxt->state); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10146 | } |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 10147 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10148 | } else { |
| 10149 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 10150 | ctxt->state, |
| 10151 | NULL, |
| 10152 | elemDecl->name, |
| 10153 | elemDecl->targetNamespace, |
| 10154 | (xmlSchemaTypePtr) elemDecl); |
| 10155 | if (particle->minOccurs == 0) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10156 | /* basically an elem? */ |
| 10157 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10158 | ctxt->state); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10159 | } |
| 10160 | } |
| 10161 | break; |
| 10162 | } |
| 10163 | case XML_SCHEMA_TYPE_SEQUENCE:{ |
| 10164 | xmlSchemaTypePtr subtypes; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 10165 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10166 | /* |
| 10167 | * If max and min occurances are default (1) then |
| 10168 | * simply iterate over the subtypes |
| 10169 | */ |
| 10170 | if ((type->minOccurs == 1) && (type->maxOccurs == 1)) { |
| 10171 | subtypes = type->subtypes; |
| 10172 | while (subtypes != NULL) { |
| 10173 | xmlSchemaBuildAContentModel(subtypes, ctxt, name); |
| 10174 | subtypes = subtypes->next; |
| 10175 | } |
| 10176 | } else { |
| 10177 | xmlAutomataStatePtr oldstate = ctxt->state; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 10178 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10179 | if (type->maxOccurs >= UNBOUNDED) { |
| 10180 | if (type->minOccurs > 1) { |
| 10181 | xmlAutomataStatePtr tmp; |
| 10182 | int counter; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 10183 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10184 | ctxt->state = xmlAutomataNewEpsilon(ctxt->am, |
| 10185 | oldstate, |
| 10186 | NULL); |
| 10187 | oldstate = ctxt->state; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 10188 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10189 | counter = xmlAutomataNewCounter(ctxt->am, |
| 10190 | type-> |
| 10191 | minOccurs - 1, |
| 10192 | UNBOUNDED); |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 10193 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10194 | subtypes = type->subtypes; |
| 10195 | while (subtypes != NULL) { |
| 10196 | xmlSchemaBuildAContentModel(subtypes, ctxt, |
| 10197 | name); |
| 10198 | subtypes = subtypes->next; |
| 10199 | } |
| 10200 | tmp = ctxt->state; |
| 10201 | xmlAutomataNewCountedTrans(ctxt->am, tmp, |
| 10202 | oldstate, counter); |
| 10203 | ctxt->state = |
| 10204 | xmlAutomataNewCounterTrans(ctxt->am, tmp, |
| 10205 | NULL, counter); |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 10206 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10207 | } else { |
| 10208 | subtypes = type->subtypes; |
| 10209 | while (subtypes != NULL) { |
| 10210 | xmlSchemaBuildAContentModel(subtypes, ctxt, |
| 10211 | name); |
| 10212 | subtypes = subtypes->next; |
| 10213 | } |
| 10214 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, |
| 10215 | oldstate); |
| 10216 | if (type->minOccurs == 0) { |
| 10217 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
| 10218 | ctxt->state); |
| 10219 | } |
| 10220 | } |
| 10221 | } else if ((type->maxOccurs > 1) |
| 10222 | || (type->minOccurs > 1)) { |
| 10223 | xmlAutomataStatePtr tmp; |
| 10224 | int counter; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 10225 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10226 | ctxt->state = xmlAutomataNewEpsilon(ctxt->am, |
| 10227 | oldstate, |
| 10228 | NULL); |
| 10229 | oldstate = ctxt->state; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10230 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10231 | counter = xmlAutomataNewCounter(ctxt->am, |
| 10232 | type->minOccurs - |
| 10233 | 1, |
| 10234 | type->maxOccurs - |
| 10235 | 1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10236 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10237 | subtypes = type->subtypes; |
| 10238 | while (subtypes != NULL) { |
| 10239 | xmlSchemaBuildAContentModel(subtypes, ctxt, |
| 10240 | name); |
| 10241 | subtypes = subtypes->next; |
| 10242 | } |
| 10243 | tmp = ctxt->state; |
| 10244 | xmlAutomataNewCountedTrans(ctxt->am, tmp, oldstate, |
| 10245 | counter); |
| 10246 | ctxt->state = |
| 10247 | xmlAutomataNewCounterTrans(ctxt->am, tmp, NULL, |
| 10248 | counter); |
| 10249 | if (type->minOccurs == 0) { |
| 10250 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
| 10251 | ctxt->state); |
| 10252 | } |
Daniel Veillard | b509f15 | 2002-04-17 16:28:10 +0000 | [diff] [blame] | 10253 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10254 | } else { |
| 10255 | subtypes = type->subtypes; |
| 10256 | while (subtypes != NULL) { |
| 10257 | xmlSchemaBuildAContentModel(subtypes, ctxt, |
| 10258 | name); |
| 10259 | subtypes = subtypes->next; |
| 10260 | } |
| 10261 | if (type->minOccurs == 0) { |
| 10262 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
| 10263 | ctxt->state); |
| 10264 | } |
| 10265 | } |
| 10266 | } |
| 10267 | break; |
| 10268 | } |
| 10269 | case XML_SCHEMA_TYPE_CHOICE:{ |
| 10270 | xmlSchemaTypePtr subtypes; |
| 10271 | xmlAutomataStatePtr start, end; |
Daniel Veillard | b509f15 | 2002-04-17 16:28:10 +0000 | [diff] [blame] | 10272 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10273 | start = ctxt->state; |
| 10274 | end = xmlAutomataNewState(ctxt->am); |
Daniel Veillard | 7646b18 | 2002-04-20 06:41:40 +0000 | [diff] [blame] | 10275 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10276 | /* |
| 10277 | * iterate over the subtypes and remerge the end with an |
| 10278 | * epsilon transition |
| 10279 | */ |
| 10280 | if (type->maxOccurs == 1) { |
| 10281 | subtypes = type->subtypes; |
| 10282 | while (subtypes != NULL) { |
| 10283 | ctxt->state = start; |
| 10284 | xmlSchemaBuildAContentModel(subtypes, ctxt, name); |
| 10285 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 10286 | subtypes = subtypes->next; |
| 10287 | } |
| 10288 | } else { |
| 10289 | int counter; |
| 10290 | xmlAutomataStatePtr hop; |
| 10291 | int maxOccurs = type->maxOccurs == UNBOUNDED ? |
| 10292 | UNBOUNDED : type->maxOccurs - 1; |
| 10293 | int minOccurs = |
| 10294 | type->minOccurs < 1 ? 0 : type->minOccurs - 1; |
Daniel Veillard | 7646b18 | 2002-04-20 06:41:40 +0000 | [diff] [blame] | 10295 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10296 | /* |
| 10297 | * use a counter to keep track of the number of transtions |
| 10298 | * which went through the choice. |
| 10299 | */ |
| 10300 | counter = |
| 10301 | xmlAutomataNewCounter(ctxt->am, minOccurs, |
| 10302 | maxOccurs); |
| 10303 | hop = xmlAutomataNewState(ctxt->am); |
Daniel Veillard | 6231e84 | 2002-04-18 11:54:04 +0000 | [diff] [blame] | 10304 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10305 | subtypes = type->subtypes; |
| 10306 | while (subtypes != NULL) { |
| 10307 | ctxt->state = start; |
| 10308 | xmlSchemaBuildAContentModel(subtypes, ctxt, name); |
| 10309 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 10310 | subtypes = subtypes->next; |
| 10311 | } |
| 10312 | xmlAutomataNewCountedTrans(ctxt->am, hop, start, |
| 10313 | counter); |
| 10314 | xmlAutomataNewCounterTrans(ctxt->am, hop, end, |
| 10315 | counter); |
| 10316 | } |
| 10317 | if (type->minOccurs == 0) { |
| 10318 | xmlAutomataNewEpsilon(ctxt->am, start, end); |
| 10319 | } |
| 10320 | ctxt->state = end; |
| 10321 | break; |
| 10322 | } |
| 10323 | case XML_SCHEMA_TYPE_ALL:{ |
| 10324 | xmlAutomataStatePtr start; |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 10325 | xmlSchemaElementPtr elemDecl, particle; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10326 | int lax; |
| 10327 | |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 10328 | particle = (xmlSchemaElementPtr) type->subtypes; |
| 10329 | if (particle == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10330 | break; |
| 10331 | start = ctxt->state; |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 10332 | while (particle != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10333 | ctxt->state = start; |
William M. Brack | 9989c7d | 2004-05-12 14:39:38 +0000 | [diff] [blame] | 10334 | /* |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 10335 | * Changed to put the element declaration and |
| 10336 | * never the element decl. reference into the |
| 10337 | * automaton. This fixes bug 139897 and bug 167754. |
William M. Brack | 9989c7d | 2004-05-12 14:39:38 +0000 | [diff] [blame] | 10338 | */ |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 10339 | if (particle->ref != NULL) { |
| 10340 | if (particle->refDecl == NULL) { |
| 10341 | /* |
| 10342 | * TODO: Note that we break on missing |
| 10343 | * sub-components. |
| 10344 | */ |
| 10345 | break; |
| 10346 | } else |
| 10347 | elemDecl = particle->refDecl; |
| 10348 | } else |
| 10349 | elemDecl = particle; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10350 | /* |
| 10351 | * NOTE: The {max occurs} of all the particles in the |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 10352 | * {particles} of the group must be 0 or 1; this is |
| 10353 | * already ensured during the parse of the content of |
| 10354 | * <all>. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10355 | */ |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 10356 | if ((particle->minOccurs == 1) && |
| 10357 | (particle->maxOccurs == 1)) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10358 | xmlAutomataNewOnceTrans2(ctxt->am, ctxt->state, |
| 10359 | ctxt->state, |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 10360 | elemDecl->name, |
| 10361 | elemDecl->targetNamespace, |
| 10362 | 1, 1, elemDecl); |
| 10363 | } else if ((particle->minOccurs == 0) && |
| 10364 | (particle->maxOccurs == 1)) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10365 | |
| 10366 | xmlAutomataNewCountTrans2(ctxt->am, ctxt->state, |
| 10367 | ctxt->state, |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 10368 | elemDecl->name, |
| 10369 | elemDecl->targetNamespace, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10370 | 0, |
| 10371 | 1, |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 10372 | elemDecl); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10373 | } |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 10374 | particle = (xmlSchemaElementPtr) particle->next; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10375 | } |
| 10376 | lax = type->minOccurs == 0; |
| 10377 | ctxt->state = |
| 10378 | xmlAutomataNewAllTrans(ctxt->am, ctxt->state, NULL, |
| 10379 | lax); |
| 10380 | break; |
| 10381 | } |
| 10382 | case XML_SCHEMA_TYPE_RESTRICTION: |
| 10383 | if (type->subtypes != NULL) |
| 10384 | xmlSchemaBuildAContentModel(type->subtypes, ctxt, name); |
| 10385 | break; |
| 10386 | case XML_SCHEMA_TYPE_EXTENSION: |
| 10387 | if (type->baseType != NULL) { |
| 10388 | xmlSchemaTypePtr subtypes; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10389 | |
| 10390 | /* |
| 10391 | * TODO: Circular definitions will be checked at the |
| 10392 | * constraint level. So remove this when the complex type |
| 10393 | * constraints are implemented. |
| 10394 | */ |
Daniel Veillard | f762755 | 2004-04-22 07:15:40 +0000 | [diff] [blame] | 10395 | if (type->recurse) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10396 | /* TODO: Change the error code. */ |
| 10397 | xmlSchemaPCustomErr(ctxt, |
| 10398 | XML_SCHEMAP_UNKNOWN_BASE_TYPE, |
| 10399 | NULL, type, type->node, |
| 10400 | "This item is circular", NULL); |
Daniel Veillard | f762755 | 2004-04-22 07:15:40 +0000 | [diff] [blame] | 10401 | return; |
| 10402 | } |
| 10403 | type->recurse = 1; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10404 | xmlSchemaBuildAContentModel(type->baseType, ctxt, name); |
Daniel Veillard | f762755 | 2004-04-22 07:15:40 +0000 | [diff] [blame] | 10405 | type->recurse = 0; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10406 | subtypes = type->subtypes; |
| 10407 | while (subtypes != NULL) { |
| 10408 | xmlSchemaBuildAContentModel(subtypes, ctxt, name); |
| 10409 | subtypes = subtypes->next; |
| 10410 | } |
| 10411 | } else if (type->subtypes != NULL) |
| 10412 | xmlSchemaBuildAContentModel(type->subtypes, ctxt, name); |
| 10413 | break; |
| 10414 | case XML_SCHEMA_TYPE_GROUP: |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 10415 | /* |
| 10416 | * Handle model group definition references. |
| 10417 | * NOTE: type->subtypes is the referenced model grop definition; |
| 10418 | * and type->subtypes->subtypes is the model group (i.e. <all> or |
| 10419 | * <choice> or <sequence>). |
| 10420 | */ |
| 10421 | if ((type->ref != NULL) && (type->subtypes != NULL) && |
| 10422 | (type->subtypes->subtypes != NULL)) { |
| 10423 | xmlSchemaTypePtr modelGr; |
| 10424 | xmlAutomataStatePtr start, end; |
| 10425 | |
| 10426 | modelGr = type->subtypes->subtypes; |
| 10427 | start = ctxt->state; |
| 10428 | end = xmlAutomataNewState(ctxt->am); |
| 10429 | if (type->maxOccurs == 1) { |
| 10430 | ctxt->state = start; |
| 10431 | xmlSchemaBuildAContentModel(modelGr, ctxt, name); |
| 10432 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 10433 | } else { |
| 10434 | int counter; |
| 10435 | xmlAutomataStatePtr hop; |
| 10436 | int maxOccurs = type->maxOccurs == UNBOUNDED ? |
| 10437 | UNBOUNDED : type->maxOccurs - 1; |
| 10438 | int minOccurs = |
| 10439 | type->minOccurs < 1 ? 0 : type->minOccurs - 1; |
| 10440 | |
| 10441 | counter = |
| 10442 | xmlAutomataNewCounter(ctxt->am, minOccurs, maxOccurs); |
| 10443 | hop = xmlAutomataNewState(ctxt->am); |
| 10444 | ctxt->state = start; |
| 10445 | xmlSchemaBuildAContentModel(modelGr, ctxt, name); |
| 10446 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 10447 | xmlAutomataNewCountedTrans(ctxt->am, hop, start, |
| 10448 | counter); |
| 10449 | xmlAutomataNewCounterTrans(ctxt->am, hop, end, |
| 10450 | counter); |
| 10451 | } |
| 10452 | if (type->minOccurs == 0) { |
| 10453 | xmlAutomataNewEpsilon(ctxt->am, start, end); |
| 10454 | } |
| 10455 | ctxt->state = end; |
| 10456 | break; |
| 10457 | } |
| 10458 | break; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10459 | case XML_SCHEMA_TYPE_COMPLEX: |
| 10460 | case XML_SCHEMA_TYPE_COMPLEX_CONTENT: |
| 10461 | if (type->subtypes != NULL) |
| 10462 | xmlSchemaBuildAContentModel(type->subtypes, ctxt, name); |
| 10463 | break; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 10464 | case XML_SCHEMA_TYPE_SIMPLE_CONTENT: |
| 10465 | break; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10466 | default: |
| 10467 | xmlGenericError(xmlGenericErrorContext, |
| 10468 | "Found unexpected type %d in %s content model\n", |
| 10469 | type->type, name); |
| 10470 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10471 | } |
| 10472 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10473 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10474 | /** |
| 10475 | * xmlSchemaBuildContentModel: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10476 | * @type: the type definition (or reference) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10477 | * @ctxt: the schema parser context |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 10478 | * @name: the element name |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10479 | * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10480 | * Builds the content model of the complex type. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10481 | */ |
| 10482 | static void |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10483 | xmlSchemaBuildContentModel(xmlSchemaTypePtr type, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10484 | xmlSchemaParserCtxtPtr ctxt, |
| 10485 | const xmlChar * name) |
| 10486 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10487 | xmlAutomataStatePtr start; |
| 10488 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10489 | if ((type->type != XML_SCHEMA_TYPE_COMPLEX) || (type->ref != NULL) || |
| 10490 | (type->contentType == XML_SCHEMA_CONTENT_BASIC) || |
| 10491 | (type->contentType == XML_SCHEMA_CONTENT_SIMPLE) || |
| 10492 | (type->contModel != NULL)) |
| 10493 | return; |
Daniel Veillard | decd64d | 2002-04-18 14:41:51 +0000 | [diff] [blame] | 10494 | |
| 10495 | #ifdef DEBUG_CONTENT |
| 10496 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10497 | "Building content model for %s\n", name); |
Daniel Veillard | decd64d | 2002-04-18 14:41:51 +0000 | [diff] [blame] | 10498 | #endif |
| 10499 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10500 | ctxt->am = xmlNewAutomata(); |
| 10501 | if (ctxt->am == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10502 | xmlGenericError(xmlGenericErrorContext, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10503 | "Cannot create automata for complex tpye %s\n", name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10504 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10505 | } |
| 10506 | start = ctxt->state = xmlAutomataGetInitState(ctxt->am); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10507 | xmlSchemaBuildAContentModel(type, ctxt, name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10508 | xmlAutomataSetFinalState(ctxt->am, ctxt->state); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10509 | type->contModel = xmlAutomataCompile(ctxt->am); |
| 10510 | if (type->contModel == NULL) { |
| 10511 | xmlSchemaPCustomErr(ctxt, |
| 10512 | XML_SCHEMAP_INTERNAL, |
| 10513 | NULL, type, type->node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10514 | "Failed to compile the content model", NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10515 | } else if (xmlRegexpIsDeterminist(type->contModel) != 1) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 10516 | xmlSchemaPCustomErr(ctxt, |
| 10517 | XML_SCHEMAP_NOT_DETERMINISTIC, |
| 10518 | /* XML_SCHEMAS_ERR_NOTDETERMINIST, */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10519 | NULL, type, type->node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10520 | "The content model is not determinist", NULL); |
Daniel Veillard | e19fc23 | 2002-04-22 16:01:24 +0000 | [diff] [blame] | 10521 | } else { |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 10522 | #ifdef DEBUG_CONTENT_REGEXP |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10523 | xmlGenericError(xmlGenericErrorContext, |
| 10524 | "Content model of %s:\n", name); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10525 | xmlRegexpPrint(stderr, type->contModel); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10526 | #endif |
Daniel Veillard | e19fc23 | 2002-04-22 16:01:24 +0000 | [diff] [blame] | 10527 | } |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 10528 | ctxt->state = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10529 | xmlFreeAutomata(ctxt->am); |
| 10530 | ctxt->am = NULL; |
| 10531 | } |
| 10532 | |
| 10533 | /** |
| 10534 | * xmlSchemaRefFixupCallback: |
| 10535 | * @elem: the schema element context |
| 10536 | * @ctxt: the schema parser context |
| 10537 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10538 | * Resolves the references of an element declaration |
| 10539 | * or particle, which has an element declaration as it's |
| 10540 | * term. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10541 | */ |
| 10542 | static void |
| 10543 | xmlSchemaRefFixupCallback(xmlSchemaElementPtr elem, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10544 | xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10545 | const xmlChar * name ATTRIBUTE_UNUSED, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10546 | const xmlChar * context ATTRIBUTE_UNUSED, |
| 10547 | const xmlChar * namespace ATTRIBUTE_UNUSED) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10548 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10549 | if ((ctxt == NULL) || (elem == NULL) || |
| 10550 | ((elem != NULL) && (elem->flags & XML_SCHEMAS_ELEM_INTERNAL_RESOLVED))) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10551 | return; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10552 | elem->flags |= XML_SCHEMAS_ELEM_INTERNAL_RESOLVED; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10553 | if (elem->ref != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 10554 | xmlSchemaElementPtr elemDecl; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10555 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10556 | /* |
| 10557 | * TODO: Evaluate, what errors could occur if the declaration is not |
| 10558 | * found. It might be possible that the "typefixup" might crash if |
| 10559 | * no ref declaration was found. |
| 10560 | */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 10561 | elemDecl = xmlSchemaGetElem(ctxt->schema, elem->ref, elem->refNs); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10562 | if (elemDecl == NULL) { |
| 10563 | xmlSchemaPResCompAttrErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10564 | XML_SCHEMAP_SRC_RESOLVE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10565 | NULL, (xmlSchemaTypePtr) elem, elem->node, |
| 10566 | "ref", elem->ref, elem->refNs, |
| 10567 | XML_SCHEMA_TYPE_ELEMENT, NULL); |
| 10568 | } else |
| 10569 | elem->refDecl = elemDecl; |
| 10570 | } else { |
| 10571 | if ((elem->subtypes == NULL) && (elem->namedType != NULL)) { |
| 10572 | xmlSchemaTypePtr type; |
| 10573 | |
| 10574 | /* (type definition) ... otherwise the type definition ·resolved· |
| 10575 | * to by the ·actual value· of the type [attribute] ... |
| 10576 | */ |
| 10577 | type = xmlSchemaGetType(ctxt->schema, elem->namedType, |
| 10578 | elem->namedTypeNs); |
| 10579 | if (type == NULL) { |
| 10580 | xmlSchemaPResCompAttrErr(ctxt, |
| 10581 | XML_SCHEMAP_SRC_RESOLVE, |
| 10582 | NULL, (xmlSchemaTypePtr) elem, elem->node, |
| 10583 | "type", elem->namedType, elem->namedTypeNs, |
| 10584 | XML_SCHEMA_TYPE_BASIC, "type definition"); |
| 10585 | } else |
| 10586 | elem->subtypes = type; |
| 10587 | } |
| 10588 | if (elem->substGroup != NULL) { |
| 10589 | xmlSchemaElementPtr substHead; |
| 10590 | |
| 10591 | /* |
| 10592 | * FIXME TODO: Do we need a new field in _xmlSchemaElement for |
| 10593 | * substitutionGroup? |
| 10594 | */ |
| 10595 | substHead = xmlSchemaGetElem(ctxt->schema, elem->substGroup, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 10596 | elem->substGroupNs); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10597 | if (substHead == NULL) { |
| 10598 | xmlSchemaPResCompAttrErr(ctxt, |
| 10599 | XML_SCHEMAP_SRC_RESOLVE, |
| 10600 | NULL, (xmlSchemaTypePtr) elem, NULL, |
| 10601 | "substitutionGroup", elem->substGroup, elem->substGroupNs, |
| 10602 | XML_SCHEMA_TYPE_ELEMENT, NULL); |
| 10603 | } else { |
| 10604 | xmlSchemaRefFixupCallback(substHead, ctxt, NULL, NULL, NULL); |
| 10605 | /* |
| 10606 | * (type definition)...otherwise the {type definition} of the |
| 10607 | * element declaration ·resolved· to by the ·actual value· of |
| 10608 | * the substitutionGroup [attribute], if present |
| 10609 | */ |
| 10610 | if (elem->subtypes == NULL) |
| 10611 | elem->subtypes = substHead->subtypes; |
| 10612 | } |
| 10613 | } |
| 10614 | if ((elem->subtypes == NULL) && (elem->namedType == NULL) && |
| 10615 | (elem->substGroup == NULL)) |
| 10616 | elem->subtypes = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 10617 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10618 | } |
| 10619 | |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 10620 | /** |
| 10621 | * xmlSchemaParseListRefFixup: |
| 10622 | * @type: the schema type definition |
| 10623 | * @ctxt: the schema parser context |
| 10624 | * |
| 10625 | * Fixup of the itemType reference of the list type. |
| 10626 | */ |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 10627 | static void |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 10628 | xmlSchemaParseListRefFixup(xmlSchemaTypePtr type, xmlSchemaParserCtxtPtr ctxt) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10629 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10630 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10631 | if (((type->base == NULL) && |
| 10632 | (type->subtypes == NULL)) || |
| 10633 | ((type->base != NULL) && |
| 10634 | (type->subtypes != NULL))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10635 | /* |
| 10636 | * src-list-itemType-or-simpleType |
| 10637 | * Either the itemType [attribute] or the <simpleType> [child] of |
| 10638 | * the <list> element must be present, but not both. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10639 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10640 | /* |
| 10641 | * TODO: Move this to the parse function. |
| 10642 | */ |
| 10643 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10644 | XML_SCHEMAP_SRC_LIST_ITEMTYPE_OR_SIMPLETYPE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10645 | NULL, type, type->node, |
| 10646 | "The attribute 'itemType' and the <simpleType> child " |
| 10647 | "are mutually exclusive", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10648 | } else if (type->base!= NULL) { |
| 10649 | type->subtypes = xmlSchemaGetType(ctxt->schema, type->base, type->baseNs); |
| 10650 | if (type->subtypes == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10651 | xmlSchemaPResCompAttrErr(ctxt, |
| 10652 | XML_SCHEMAP_SRC_RESOLVE, |
| 10653 | NULL, type, type->node, |
| 10654 | "itemType", type->base, type->baseNs, |
| 10655 | XML_SCHEMA_TYPE_SIMPLE, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10656 | } |
| 10657 | } |
| 10658 | if ((type->subtypes != NULL) && |
| 10659 | (type->subtypes->contentType == XML_SCHEMA_CONTENT_UNKNOWN)) |
| 10660 | xmlSchemaTypeFixup(type->subtypes, ctxt, NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 10661 | } |
| 10662 | |
| 10663 | /** |
| 10664 | * xmlSchemaParseUnionRefCheck: |
| 10665 | * @typeDecl: the schema type definition |
| 10666 | * @ctxt: the schema parser context |
| 10667 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10668 | * Checks and builds the memberTypes of the union type. |
| 10669 | * Returns -1 in case of an internal error, 0 otherwise. |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 10670 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10671 | static int |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 10672 | xmlSchemaParseUnionRefCheck(xmlSchemaTypePtr type, |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 10673 | xmlSchemaParserCtxtPtr ctxt) |
| 10674 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10675 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10676 | xmlSchemaTypeLinkPtr link, lastLink = NULL, prevLink, subLink, newLink; |
| 10677 | xmlSchemaTypePtr memberType, ctxtType; |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 10678 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10679 | /* 1 If the <union> alternative is chosen, then [Definition:] |
| 10680 | * define the explicit members as the type definitions ·resolved· |
| 10681 | * to by the items in the ·actual value· of the memberTypes [attribute], |
| 10682 | * if any, followed by the type definitions corresponding to the |
| 10683 | * <simpleType>s among the [children] of <union>, if any. |
| 10684 | */ |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 10685 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10686 | if (type->type != XML_SCHEMA_TYPE_UNION) |
| 10687 | return (-1); |
| 10688 | if (ctxt->ctxtType == NULL) { |
| 10689 | xmlSchemaPErr(ctxt, type->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 10690 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10691 | "Internal error: xmlSchemaParseUnionRefCheck, no parent type " |
| 10692 | "available", NULL, NULL); |
| 10693 | return (-1); |
| 10694 | } |
| 10695 | /* |
| 10696 | * src-union-memberTypes-or-simpleTypes |
| 10697 | * Either the memberTypes [attribute] of the <union> element must |
| 10698 | * be non-empty or there must be at least one simpleType [child]. |
| 10699 | */ |
| 10700 | if ((type->base == NULL) && |
| 10701 | (type->subtypes == NULL)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10702 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10703 | XML_SCHEMAP_SRC_UNION_MEMBERTYPES_OR_SIMPLETYPES, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10704 | NULL, NULL, type->node, |
| 10705 | "Either the attribute 'memberTypes' must be non-empty " |
| 10706 | "or there must be at least one <simpleType> child", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10707 | } |
| 10708 | |
| 10709 | ctxtType = ctxt->ctxtType; |
| 10710 | if (type->base != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10711 | xmlAttrPtr attr; |
| 10712 | const xmlChar *cur, *end; |
| 10713 | xmlChar *tmp; |
| 10714 | const xmlChar *localName, *uri; |
| 10715 | |
| 10716 | attr = xmlSchemaGetPropNode(type->node, "memberTypes"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10717 | cur = type->base; |
| 10718 | do { |
| 10719 | while (IS_BLANK_CH(*cur)) |
| 10720 | cur++; |
| 10721 | end = cur; |
| 10722 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 10723 | end++; |
| 10724 | if (end == cur) |
| 10725 | break; |
| 10726 | tmp = xmlStrndup(cur, end - cur); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10727 | xmlSchemaPValAttrNodeQNameValue(ctxt, ctxt->schema, NULL, |
| 10728 | NULL, attr, BAD_CAST tmp, &uri, NULL, &localName); |
| 10729 | memberType = xmlSchemaGetType(ctxt->schema, localName, uri); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10730 | if (memberType == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10731 | xmlSchemaPResCompAttrErr(ctxt, |
| 10732 | XML_SCHEMAP_UNKNOWN_MEMBER_TYPE, |
| 10733 | NULL, NULL, type->node, "memberTypes", localName, uri, |
| 10734 | XML_SCHEMA_TYPE_SIMPLE, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10735 | } else { |
| 10736 | if (memberType->contentType == XML_SCHEMA_CONTENT_UNKNOWN) |
| 10737 | xmlSchemaTypeFixup(memberType, ctxt, NULL); |
| 10738 | link = (xmlSchemaTypeLinkPtr) xmlMalloc(sizeof(xmlSchemaTypeLink)); |
| 10739 | if (link == NULL) { |
| 10740 | xmlSchemaPErrMemory(ctxt, "allocating a type link", NULL); |
| 10741 | return (-1); |
| 10742 | } |
| 10743 | link->type = memberType; |
| 10744 | link->next = NULL; |
| 10745 | if (lastLink == NULL) |
| 10746 | ctxtType->memberTypes = link; |
| 10747 | else |
| 10748 | lastLink->next = link; |
| 10749 | lastLink = link; |
| 10750 | } |
| 10751 | xmlFree(tmp); |
| 10752 | cur = end; |
| 10753 | } while (*cur != 0); |
| 10754 | } |
| 10755 | /* |
| 10756 | * Add local simple types, |
| 10757 | */ |
| 10758 | memberType = type->subtypes; |
| 10759 | while (memberType != NULL) { |
| 10760 | if (memberType->contentType == XML_SCHEMA_CONTENT_UNKNOWN) |
| 10761 | xmlSchemaTypeFixup(memberType, ctxt, NULL); |
| 10762 | link = (xmlSchemaTypeLinkPtr) xmlMalloc(sizeof(xmlSchemaTypeLink)); |
| 10763 | if (link == NULL) { |
| 10764 | xmlSchemaPErrMemory(ctxt, "allocating a type link", NULL); |
| 10765 | return (-1); |
| 10766 | } |
| 10767 | link->type = memberType; |
| 10768 | link->next = NULL; |
| 10769 | if (lastLink == NULL) |
| 10770 | ctxtType->memberTypes = link; |
| 10771 | else |
| 10772 | lastLink->next = link; |
| 10773 | lastLink = link; |
| 10774 | memberType = memberType->next; |
| 10775 | } |
| 10776 | /* |
| 10777 | * The actual value is then formed by replacing any union type |
| 10778 | * definition in the ·explicit members· with the members of their |
| 10779 | * {member type definitions}, in order. |
| 10780 | */ |
| 10781 | link = ctxtType->memberTypes; |
| 10782 | while (link != NULL) { |
| 10783 | if (link->type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
| 10784 | subLink = link->type->memberTypes; |
| 10785 | if (subLink != NULL) { |
| 10786 | link->type = subLink->type; |
| 10787 | if (subLink->next != NULL) { |
| 10788 | lastLink = link->next; |
| 10789 | subLink = subLink->next; |
| 10790 | prevLink = link; |
| 10791 | while (subLink != NULL) { |
| 10792 | newLink = (xmlSchemaTypeLinkPtr) |
| 10793 | xmlMalloc(sizeof(xmlSchemaTypeLink)); |
| 10794 | if (newLink == NULL) { |
| 10795 | xmlSchemaPErrMemory(ctxt, "allocating a type link", |
| 10796 | NULL); |
| 10797 | return (-1); |
| 10798 | } |
| 10799 | newLink->type = memberType; |
| 10800 | prevLink->next = newLink; |
| 10801 | prevLink = newLink; |
| 10802 | newLink->next = lastLink; |
| 10803 | |
| 10804 | subLink = subLink->next; |
| 10805 | } |
| 10806 | } |
| 10807 | } |
| 10808 | } |
| 10809 | link = link->next; |
| 10810 | } |
| 10811 | |
| 10812 | return (0); |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 10813 | } |
| 10814 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10815 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10816 | * xmlSchemaIsDerivedFromBuiltInType: |
| 10817 | * @ctxt: the schema parser context |
| 10818 | * @type: the type definition |
| 10819 | * @valType: the value type |
| 10820 | * |
| 10821 | * |
| 10822 | * Returns 1 if the type has the given value type, or |
| 10823 | * is derived from such a type. |
| 10824 | */ |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 10825 | static int |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10826 | xmlSchemaIsDerivedFromBuiltInType(xmlSchemaParserCtxtPtr ctxt, |
| 10827 | xmlSchemaTypePtr type, int valType) |
| 10828 | { |
| 10829 | /* TODO: Check if this works in every case. */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10830 | if ((type->type == XML_SCHEMA_TYPE_BASIC) && |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10831 | (type->contentType == XML_SCHEMA_CONTENT_BASIC)) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10832 | if (type->builtInType == valType) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10833 | return(1); |
| 10834 | } else if (type->type == XML_SCHEMA_TYPE_ATTRIBUTE) { |
| 10835 | if (((xmlSchemaAttributePtr) type)->subtypes != NULL) |
| 10836 | return(xmlSchemaIsDerivedFromBuiltInType(ctxt, |
| 10837 | ((xmlSchemaAttributePtr) type)->subtypes, valType)); |
| 10838 | } else if ((type->type == XML_SCHEMA_TYPE_RESTRICTION) || |
| 10839 | (type->type == XML_SCHEMA_TYPE_EXTENSION)) { |
| 10840 | if (type->baseType != NULL) |
| 10841 | return(xmlSchemaIsDerivedFromBuiltInType(ctxt, type->baseType, |
| 10842 | valType)); |
| 10843 | } else if ((type->subtypes != NULL) && |
| 10844 | ((type->subtypes->type == XML_SCHEMA_TYPE_COMPLEX) || |
| 10845 | (type->subtypes->type == XML_SCHEMA_TYPE_COMPLEX_CONTENT) || |
| 10846 | (type->subtypes->type == XML_SCHEMA_TYPE_SIMPLE) || |
| 10847 | (type->subtypes->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT))) { |
| 10848 | return(xmlSchemaIsDerivedFromBuiltInType(ctxt, type->subtypes, |
| 10849 | valType)); |
| 10850 | } |
| 10851 | |
| 10852 | return (0); |
| 10853 | } |
| 10854 | |
| 10855 | /** |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 10856 | * xmlSchemaGetPrimitiveType: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10857 | * @type: the simpleType definition |
| 10858 | * |
| 10859 | * Returns the primitive type of the given type or |
| 10860 | * NULL in case of error. |
| 10861 | */ |
| 10862 | static xmlSchemaTypePtr |
| 10863 | xmlSchemaGetPrimitiveType(xmlSchemaTypePtr type) |
| 10864 | { |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 10865 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10866 | while (type != NULL) { |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 10867 | /* |
| 10868 | * Note that anySimpleType is actually not a primitive type |
| 10869 | * but we need that here. |
| 10870 | */ |
| 10871 | if ((type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) || |
| 10872 | (type->flags & XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE)) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10873 | return (type); |
| 10874 | type = type->baseType; |
| 10875 | } |
| 10876 | |
| 10877 | return (NULL); |
| 10878 | } |
| 10879 | |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 10880 | #if 0 |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 10881 | /** |
| 10882 | * xmlSchemaGetBuiltInTypeAncestor: |
| 10883 | * @type: the simpleType definition |
| 10884 | * |
| 10885 | * Returns the primitive type of the given type or |
| 10886 | * NULL in case of error. |
| 10887 | */ |
| 10888 | static xmlSchemaTypePtr |
| 10889 | xmlSchemaGetBuiltInTypeAncestor(xmlSchemaTypePtr type) |
| 10890 | { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 10891 | if ((type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) || |
| 10892 | (type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION)) |
| 10893 | return (0); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 10894 | while (type != NULL) { |
| 10895 | if (type->type == XML_SCHEMA_TYPE_BASIC) |
| 10896 | return (type); |
| 10897 | type = type->baseType; |
| 10898 | } |
| 10899 | |
| 10900 | return (NULL); |
| 10901 | } |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 10902 | #endif |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 10903 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10904 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10905 | * xmlSchemaBuildAttributeUsesOwned: |
| 10906 | * @ctxt: the schema parser context |
| 10907 | * @type: the complex type definition |
| 10908 | * @cur: the attribute declaration list |
| 10909 | * @lastUse: the top of the attribute use list |
| 10910 | * |
| 10911 | * Builds the attribute uses list on the given complex type. |
| 10912 | * This one is supposed to be called by |
| 10913 | * xmlSchemaBuildAttributeValidation only. |
| 10914 | */ |
| 10915 | static int |
| 10916 | xmlSchemaBuildAttributeUsesOwned(xmlSchemaParserCtxtPtr ctxt, |
| 10917 | xmlSchemaAttributePtr cur, |
| 10918 | xmlSchemaAttributeLinkPtr *uses, |
| 10919 | xmlSchemaAttributeLinkPtr *lastUse) |
| 10920 | { |
| 10921 | xmlSchemaAttributeLinkPtr tmp; |
| 10922 | while (cur != NULL) { |
| 10923 | if (cur->type == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) { |
| 10924 | /* |
| 10925 | * W3C: "2 The {attribute uses} of the attribute groups ·resolved· |
| 10926 | * to by the ·actual value·s of the ref [attribute] of the |
| 10927 | * <attributeGroup> [children], if any." |
| 10928 | */ |
| 10929 | if (xmlSchemaBuildAttributeUsesOwned(ctxt, |
| 10930 | ((xmlSchemaAttributeGroupPtr) cur)->attributes, uses, |
| 10931 | lastUse) == -1) { |
| 10932 | return (-1); |
| 10933 | } |
| 10934 | } else { |
| 10935 | /* W3C: "1 The set of attribute uses corresponding to the |
| 10936 | * <attribute> [children], if any." |
| 10937 | */ |
| 10938 | tmp = (xmlSchemaAttributeLinkPtr) |
| 10939 | xmlMalloc(sizeof(xmlSchemaAttributeLink)); |
| 10940 | if (tmp == NULL) { |
| 10941 | xmlSchemaPErrMemory(ctxt, "building attribute uses", NULL); |
| 10942 | return (-1); |
| 10943 | } |
| 10944 | tmp->attr = cur; |
| 10945 | tmp->next = NULL; |
| 10946 | if (*uses == NULL) |
| 10947 | *uses = tmp; |
| 10948 | else |
| 10949 | (*lastUse)->next = tmp; |
| 10950 | *lastUse = tmp; |
| 10951 | } |
| 10952 | cur = cur->next; |
| 10953 | } |
| 10954 | return (0); |
| 10955 | } |
| 10956 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10957 | /** |
| 10958 | * xmlSchemaCloneWildcardNsConstraints: |
| 10959 | * @ctxt: the schema parser context |
| 10960 | * @dest: the destination wildcard |
| 10961 | * @source: the source wildcard |
| 10962 | * |
| 10963 | * Clones the namespace constraints of source |
| 10964 | * and assignes them to dest. |
| 10965 | * Returns -1 on internal error, 0 otherwise. |
| 10966 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10967 | static int |
| 10968 | xmlSchemaCloneWildcardNsConstraints(xmlSchemaParserCtxtPtr ctxt, |
| 10969 | xmlSchemaWildcardPtr *dest, |
| 10970 | xmlSchemaWildcardPtr source) |
| 10971 | { |
| 10972 | xmlSchemaWildcardNsPtr cur, tmp, last; |
| 10973 | |
| 10974 | if ((source == NULL) || (*dest == NULL)) |
| 10975 | return(-1); |
| 10976 | (*dest)->any = source->any; |
| 10977 | cur = source->nsSet; |
| 10978 | last = NULL; |
| 10979 | while (cur != NULL) { |
| 10980 | tmp = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 10981 | if (tmp == NULL) |
| 10982 | return(-1); |
| 10983 | tmp->value = cur->value; |
| 10984 | if (last == NULL) |
| 10985 | (*dest)->nsSet = tmp; |
| 10986 | else |
| 10987 | last->next = tmp; |
| 10988 | last = tmp; |
| 10989 | cur = cur->next; |
| 10990 | } |
| 10991 | if ((*dest)->negNsSet != NULL) |
| 10992 | xmlSchemaFreeWildcardNsSet((*dest)->negNsSet); |
| 10993 | if (source->negNsSet != NULL) { |
| 10994 | (*dest)->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 10995 | if ((*dest)->negNsSet == NULL) |
| 10996 | return(-1); |
| 10997 | (*dest)->negNsSet->value = source->negNsSet->value; |
| 10998 | } else |
| 10999 | (*dest)->negNsSet = NULL; |
| 11000 | return(0); |
| 11001 | } |
| 11002 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11003 | /** |
| 11004 | * xmlSchemaUnionWildcards: |
| 11005 | * @ctxt: the schema parser context |
| 11006 | * @completeWild: the first wildcard |
| 11007 | * @curWild: the second wildcard |
| 11008 | * |
| 11009 | * Unions the namespace constraints of the given wildcards. |
| 11010 | * @completeWild will hold the resulting union. |
| 11011 | * Returns a positive error code on failure, -1 in case of an |
| 11012 | * internal error, 0 otherwise. |
| 11013 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11014 | static int |
| 11015 | xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt, |
| 11016 | xmlSchemaWildcardPtr completeWild, |
| 11017 | xmlSchemaWildcardPtr curWild) |
| 11018 | { |
| 11019 | xmlSchemaWildcardNsPtr cur, curB, tmp; |
| 11020 | |
| 11021 | /* |
| 11022 | * 1 If O1 and O2 are the same value, then that value must be the |
| 11023 | * value. |
| 11024 | */ |
| 11025 | if ((completeWild->any == curWild->any) && |
| 11026 | ((completeWild->nsSet == NULL) == (curWild->nsSet == NULL)) && |
| 11027 | ((completeWild->negNsSet == NULL) == (curWild->negNsSet == NULL))) { |
| 11028 | |
| 11029 | if ((completeWild->negNsSet == NULL) || |
| 11030 | (completeWild->negNsSet->value == curWild->negNsSet->value)) { |
| 11031 | |
| 11032 | if (completeWild->nsSet != NULL) { |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 11033 | int found = 0; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11034 | |
| 11035 | /* |
| 11036 | * Check equality of sets. |
| 11037 | */ |
| 11038 | cur = completeWild->nsSet; |
| 11039 | while (cur != NULL) { |
| 11040 | found = 0; |
| 11041 | curB = curWild->nsSet; |
| 11042 | while (curB != NULL) { |
| 11043 | if (cur->value == curB->value) { |
| 11044 | found = 1; |
| 11045 | break; |
| 11046 | } |
| 11047 | curB = curB->next; |
| 11048 | } |
| 11049 | if (!found) |
| 11050 | break; |
| 11051 | cur = cur->next; |
| 11052 | } |
| 11053 | if (found) |
| 11054 | return(0); |
| 11055 | } else |
| 11056 | return(0); |
| 11057 | } |
| 11058 | } |
| 11059 | /* |
| 11060 | * 2 If either O1 or O2 is any, then any must be the value |
| 11061 | */ |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11062 | if (completeWild->any != curWild->any) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11063 | if (completeWild->any == 0) { |
| 11064 | completeWild->any = 1; |
| 11065 | if (completeWild->nsSet != NULL) { |
| 11066 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 11067 | completeWild->nsSet = NULL; |
| 11068 | } |
| 11069 | if (completeWild->negNsSet != NULL) { |
| 11070 | xmlFree(completeWild->negNsSet); |
| 11071 | completeWild->negNsSet = NULL; |
| 11072 | } |
| 11073 | } |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11074 | return (0); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11075 | } |
| 11076 | /* |
| 11077 | * 3 If both O1 and O2 are sets of (namespace names or ·absent·), |
| 11078 | * then the union of those sets must be the value. |
| 11079 | */ |
| 11080 | if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) { |
| 11081 | int found; |
| 11082 | xmlSchemaWildcardNsPtr start; |
| 11083 | |
| 11084 | cur = curWild->nsSet; |
| 11085 | start = completeWild->nsSet; |
| 11086 | while (cur != NULL) { |
| 11087 | found = 0; |
| 11088 | curB = start; |
| 11089 | while (curB != NULL) { |
| 11090 | if (cur->value == curB->value) { |
| 11091 | found = 1; |
| 11092 | break; |
| 11093 | } |
| 11094 | curB = curB->next; |
| 11095 | } |
| 11096 | if (!found) { |
| 11097 | tmp = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 11098 | if (tmp == NULL) |
| 11099 | return (-1); |
| 11100 | tmp->value = cur->value; |
| 11101 | tmp->next = completeWild->nsSet; |
| 11102 | completeWild->nsSet = tmp; |
| 11103 | } |
| 11104 | cur = cur->next; |
| 11105 | } |
| 11106 | |
| 11107 | return(0); |
| 11108 | } |
| 11109 | /* |
| 11110 | * 4 If the two are negations of different values (namespace names |
| 11111 | * or ·absent·), then a pair of not and ·absent· must be the value. |
| 11112 | */ |
| 11113 | if ((completeWild->negNsSet != NULL) && |
| 11114 | (curWild->negNsSet != NULL) && |
| 11115 | (completeWild->negNsSet->value != curWild->negNsSet->value)) { |
| 11116 | completeWild->negNsSet->value = NULL; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11117 | |
| 11118 | return(0); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11119 | } |
| 11120 | /* |
| 11121 | * 5. |
| 11122 | */ |
| 11123 | if (((completeWild->negNsSet != NULL) && |
| 11124 | (completeWild->negNsSet->value != NULL) && |
| 11125 | (curWild->nsSet != NULL)) || |
| 11126 | ((curWild->negNsSet != NULL) && |
| 11127 | (curWild->negNsSet->value != NULL) && |
| 11128 | (completeWild->nsSet != NULL))) { |
| 11129 | |
| 11130 | int nsFound, absentFound = 0; |
| 11131 | |
| 11132 | if (completeWild->nsSet != NULL) { |
| 11133 | cur = completeWild->nsSet; |
| 11134 | curB = curWild->negNsSet; |
| 11135 | } else { |
| 11136 | cur = curWild->nsSet; |
| 11137 | curB = completeWild->negNsSet; |
| 11138 | } |
| 11139 | nsFound = 0; |
| 11140 | while (cur != NULL) { |
| 11141 | if (cur->value == NULL) |
| 11142 | absentFound = 1; |
| 11143 | else if (cur->value == curB->value) |
| 11144 | nsFound = 1; |
| 11145 | if (nsFound && absentFound) |
| 11146 | break; |
| 11147 | cur = cur->next; |
| 11148 | } |
| 11149 | |
| 11150 | if (nsFound && absentFound) { |
| 11151 | /* |
| 11152 | * 5.1 If the set S includes both the negated namespace |
| 11153 | * name and ·absent·, then any must be the value. |
| 11154 | */ |
| 11155 | completeWild->any = 1; |
| 11156 | if (completeWild->nsSet != NULL) { |
| 11157 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 11158 | completeWild->nsSet = NULL; |
| 11159 | } |
| 11160 | if (completeWild->negNsSet != NULL) { |
| 11161 | xmlFree(completeWild->negNsSet); |
| 11162 | completeWild->negNsSet = NULL; |
| 11163 | } |
| 11164 | } else if (nsFound && (!absentFound)) { |
| 11165 | /* |
| 11166 | * 5.2 If the set S includes the negated namespace name |
| 11167 | * but not ·absent·, then a pair of not and ·absent· must |
| 11168 | * be the value. |
| 11169 | */ |
| 11170 | if (completeWild->nsSet != NULL) { |
| 11171 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 11172 | completeWild->nsSet = NULL; |
| 11173 | } |
| 11174 | if (completeWild->negNsSet == NULL) { |
| 11175 | completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 11176 | if (completeWild->negNsSet == NULL) |
| 11177 | return (-1); |
| 11178 | } |
| 11179 | completeWild->negNsSet->value = NULL; |
| 11180 | } else if ((!nsFound) && absentFound) { |
| 11181 | /* |
| 11182 | * 5.3 If the set S includes ·absent· but not the negated |
| 11183 | * namespace name, then the union is not expressible. |
| 11184 | */ |
| 11185 | xmlSchemaPErr(ctxt, completeWild->node, |
| 11186 | XML_SCHEMAP_UNION_NOT_EXPRESSIBLE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11187 | "The union of the wilcard is not expressible.\n", |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11188 | NULL, NULL); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11189 | return(XML_SCHEMAP_UNION_NOT_EXPRESSIBLE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11190 | } else if ((!nsFound) && (!absentFound)) { |
| 11191 | /* |
| 11192 | * 5.4 If the set S does not include either the negated namespace |
| 11193 | * name or ·absent·, then whichever of O1 or O2 is a pair of not |
| 11194 | * and a namespace name must be the value. |
| 11195 | */ |
| 11196 | if (completeWild->negNsSet == NULL) { |
| 11197 | if (completeWild->nsSet != NULL) { |
| 11198 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 11199 | completeWild->nsSet = NULL; |
| 11200 | } |
| 11201 | completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 11202 | if (completeWild->negNsSet == NULL) |
| 11203 | return (-1); |
| 11204 | completeWild->negNsSet->value = curWild->negNsSet->value; |
| 11205 | } |
| 11206 | } |
| 11207 | return (0); |
| 11208 | } |
| 11209 | /* |
| 11210 | * 6. |
| 11211 | */ |
| 11212 | if (((completeWild->negNsSet != NULL) && |
| 11213 | (completeWild->negNsSet->value == NULL) && |
| 11214 | (curWild->nsSet != NULL)) || |
| 11215 | ((curWild->negNsSet != NULL) && |
| 11216 | (curWild->negNsSet->value == NULL) && |
| 11217 | (completeWild->nsSet != NULL))) { |
| 11218 | |
| 11219 | if (completeWild->nsSet != NULL) { |
| 11220 | cur = completeWild->nsSet; |
| 11221 | } else { |
| 11222 | cur = curWild->nsSet; |
| 11223 | } |
| 11224 | while (cur != NULL) { |
| 11225 | if (cur->value == NULL) { |
| 11226 | /* |
| 11227 | * 6.1 If the set S includes ·absent·, then any must be the |
| 11228 | * value. |
| 11229 | */ |
| 11230 | completeWild->any = 1; |
| 11231 | if (completeWild->nsSet != NULL) { |
| 11232 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 11233 | completeWild->nsSet = NULL; |
| 11234 | } |
| 11235 | if (completeWild->negNsSet != NULL) { |
| 11236 | xmlFree(completeWild->negNsSet); |
| 11237 | completeWild->negNsSet = NULL; |
| 11238 | } |
| 11239 | return (0); |
| 11240 | } |
| 11241 | cur = cur->next; |
| 11242 | } |
| 11243 | if (completeWild->negNsSet == NULL) { |
| 11244 | /* |
| 11245 | * 6.2 If the set S does not include ·absent·, then a pair of not |
| 11246 | * and ·absent· must be the value. |
| 11247 | */ |
| 11248 | if (completeWild->nsSet != NULL) { |
| 11249 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 11250 | completeWild->nsSet = NULL; |
| 11251 | } |
| 11252 | completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 11253 | if (completeWild->negNsSet == NULL) |
| 11254 | return (-1); |
| 11255 | completeWild->negNsSet->value = NULL; |
| 11256 | } |
| 11257 | return (0); |
| 11258 | } |
| 11259 | return (0); |
| 11260 | |
| 11261 | } |
| 11262 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11263 | /** |
| 11264 | * xmlSchemaIntersectWildcards: |
| 11265 | * @ctxt: the schema parser context |
| 11266 | * @completeWild: the first wildcard |
| 11267 | * @curWild: the second wildcard |
| 11268 | * |
| 11269 | * Intersects the namespace constraints of the given wildcards. |
| 11270 | * @completeWild will hold the resulting intersection. |
| 11271 | * Returns a positive error code on failure, -1 in case of an |
| 11272 | * internal error, 0 otherwise. |
| 11273 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11274 | static int |
| 11275 | xmlSchemaIntersectWildcards(xmlSchemaParserCtxtPtr ctxt, |
| 11276 | xmlSchemaWildcardPtr completeWild, |
| 11277 | xmlSchemaWildcardPtr curWild) |
| 11278 | { |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 11279 | xmlSchemaWildcardNsPtr cur, curB, prev, tmp; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11280 | |
| 11281 | /* |
| 11282 | * 1 If O1 and O2 are the same value, then that value must be the |
| 11283 | * value. |
| 11284 | */ |
| 11285 | if ((completeWild->any == curWild->any) && |
| 11286 | ((completeWild->nsSet == NULL) == (curWild->nsSet == NULL)) && |
| 11287 | ((completeWild->negNsSet == NULL) == (curWild->negNsSet == NULL))) { |
| 11288 | |
| 11289 | if ((completeWild->negNsSet == NULL) || |
| 11290 | (completeWild->negNsSet->value == curWild->negNsSet->value)) { |
| 11291 | |
| 11292 | if (completeWild->nsSet != NULL) { |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 11293 | int found = 0; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11294 | |
| 11295 | /* |
| 11296 | * Check equality of sets. |
| 11297 | */ |
| 11298 | cur = completeWild->nsSet; |
| 11299 | while (cur != NULL) { |
| 11300 | found = 0; |
| 11301 | curB = curWild->nsSet; |
| 11302 | while (curB != NULL) { |
| 11303 | if (cur->value == curB->value) { |
| 11304 | found = 1; |
| 11305 | break; |
| 11306 | } |
| 11307 | curB = curB->next; |
| 11308 | } |
| 11309 | if (!found) |
| 11310 | break; |
| 11311 | cur = cur->next; |
| 11312 | } |
| 11313 | if (found) |
| 11314 | return(0); |
| 11315 | } else |
| 11316 | return(0); |
| 11317 | } |
| 11318 | } |
| 11319 | /* |
| 11320 | * 2 If either O1 or O2 is any, then the other must be the value. |
| 11321 | */ |
| 11322 | if ((completeWild->any != curWild->any) && (completeWild->any)) { |
| 11323 | if (xmlSchemaCloneWildcardNsConstraints(ctxt, &completeWild, curWild) == -1) |
| 11324 | return(-1); |
| 11325 | return(0); |
| 11326 | } |
| 11327 | /* |
| 11328 | * 3 If either O1 or O2 is a pair of not and a value (a namespace |
| 11329 | * name or ·absent·) and the other is a set of (namespace names or |
| 11330 | * ·absent·), then that set, minus the negated value if it was in |
| 11331 | * the set, minus ·absent· if it was in the set, must be the value. |
| 11332 | */ |
| 11333 | if (((completeWild->negNsSet != NULL) && (curWild->nsSet != NULL)) || |
| 11334 | ((curWild->negNsSet != NULL) && (completeWild->nsSet != NULL))) { |
| 11335 | const xmlChar *neg; |
| 11336 | |
| 11337 | if (completeWild->nsSet == NULL) { |
| 11338 | neg = completeWild->negNsSet->value; |
| 11339 | if (xmlSchemaCloneWildcardNsConstraints(ctxt, &completeWild, curWild) == -1) |
| 11340 | return(-1); |
| 11341 | } else |
| 11342 | neg = curWild->negNsSet->value; |
| 11343 | /* |
| 11344 | * Remove absent and negated. |
| 11345 | */ |
| 11346 | prev = NULL; |
| 11347 | cur = completeWild->nsSet; |
| 11348 | while (cur != NULL) { |
| 11349 | if (cur->value == NULL) { |
| 11350 | if (prev == NULL) |
| 11351 | completeWild->nsSet = cur->next; |
| 11352 | else |
| 11353 | prev->next = cur->next; |
| 11354 | xmlFree(cur); |
| 11355 | break; |
| 11356 | } |
| 11357 | prev = cur; |
| 11358 | cur = cur->next; |
| 11359 | } |
| 11360 | if (neg != NULL) { |
| 11361 | prev = NULL; |
| 11362 | cur = completeWild->nsSet; |
| 11363 | while (cur != NULL) { |
| 11364 | if (cur->value == neg) { |
| 11365 | if (prev == NULL) |
| 11366 | completeWild->nsSet = cur->next; |
| 11367 | else |
| 11368 | prev->next = cur->next; |
| 11369 | xmlFree(cur); |
| 11370 | break; |
| 11371 | } |
| 11372 | prev = cur; |
| 11373 | cur = cur->next; |
| 11374 | } |
| 11375 | } |
| 11376 | |
| 11377 | return(0); |
| 11378 | } |
| 11379 | /* |
| 11380 | * 4 If both O1 and O2 are sets of (namespace names or ·absent·), |
| 11381 | * then the intersection of those sets must be the value. |
| 11382 | */ |
| 11383 | if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) { |
| 11384 | int found; |
| 11385 | |
| 11386 | cur = completeWild->nsSet; |
| 11387 | prev = NULL; |
| 11388 | while (cur != NULL) { |
| 11389 | found = 0; |
| 11390 | curB = curWild->nsSet; |
| 11391 | while (curB != NULL) { |
| 11392 | if (cur->value == curB->value) { |
| 11393 | found = 1; |
| 11394 | break; |
| 11395 | } |
| 11396 | curB = curB->next; |
| 11397 | } |
| 11398 | if (!found) { |
| 11399 | if (prev == NULL) |
| 11400 | completeWild->nsSet = cur->next; |
| 11401 | else |
| 11402 | prev->next = cur->next; |
| 11403 | tmp = cur->next; |
| 11404 | xmlFree(cur); |
| 11405 | cur = tmp; |
| 11406 | continue; |
| 11407 | } |
| 11408 | prev = cur; |
| 11409 | cur = cur->next; |
| 11410 | } |
| 11411 | |
| 11412 | return(0); |
| 11413 | } |
| 11414 | /* 5 If the two are negations of different namespace names, |
| 11415 | * then the intersection is not expressible |
| 11416 | */ |
| 11417 | if ((completeWild->negNsSet != NULL) && |
| 11418 | (curWild->negNsSet != NULL) && |
| 11419 | (completeWild->negNsSet->value != curWild->negNsSet->value) && |
| 11420 | (completeWild->negNsSet->value != NULL) && |
| 11421 | (curWild->negNsSet->value != NULL)) { |
| 11422 | |
| 11423 | xmlSchemaPErr(ctxt, completeWild->node, XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11424 | "The intersection of the wilcard is not expressible.\n", |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11425 | NULL, NULL); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11426 | return(XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11427 | } |
| 11428 | /* |
| 11429 | * 6 If the one is a negation of a namespace name and the other |
| 11430 | * is a negation of ·absent·, then the one which is the negation |
| 11431 | * of a namespace name must be the value. |
| 11432 | */ |
| 11433 | if ((completeWild->negNsSet != NULL) && (curWild->negNsSet != NULL) && |
| 11434 | (completeWild->negNsSet->value != curWild->negNsSet->value) && |
| 11435 | (completeWild->negNsSet->value == NULL)) { |
| 11436 | completeWild->negNsSet->value = curWild->negNsSet->value; |
| 11437 | } |
| 11438 | return(0); |
| 11439 | } |
| 11440 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11441 | /** |
| 11442 | * xmlSchemaIsWildcardNsConstraintSubset: |
| 11443 | * @ctxt: the schema parser context |
| 11444 | * @wildA: the first wildcard |
| 11445 | * @wildB: the second wildcard |
| 11446 | * |
| 11447 | * Returns 1 if the namespace constraint of @wildA is an intensional |
| 11448 | * subset of @wildB, 0 otherwise. |
| 11449 | */ |
| 11450 | static int |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11451 | xmlSchemaIsWildcardNsConstraintSubset(xmlSchemaWildcardPtr wildA, |
| 11452 | xmlSchemaWildcardPtr wildB) |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11453 | { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11454 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11455 | /* |
| 11456 | * Schema Component Constraint: Wildcard Subset |
| 11457 | */ |
| 11458 | /* |
| 11459 | * 1 super must be any. |
| 11460 | */ |
| 11461 | if (wildB->any) |
| 11462 | return (1); |
| 11463 | /* |
| 11464 | * 2.1 sub must be a pair of not and a namespace name or ·absent·. |
| 11465 | * 2.2 super must be a pair of not and the same value. |
| 11466 | */ |
| 11467 | if ((wildA->negNsSet != NULL) && |
| 11468 | (wildB->negNsSet != NULL) && |
| 11469 | (wildA->negNsSet->value == wildA->negNsSet->value)) |
| 11470 | return (1); |
| 11471 | /* |
| 11472 | * 3.1 sub must be a set whose members are either namespace names or ·absent·. |
| 11473 | */ |
| 11474 | if (wildA->nsSet != NULL) { |
| 11475 | /* |
| 11476 | * 3.2.1 super must be the same set or a superset thereof. |
| 11477 | */ |
| 11478 | if (wildB->nsSet != NULL) { |
| 11479 | xmlSchemaWildcardNsPtr cur, curB; |
| 11480 | int found = 0; |
| 11481 | |
| 11482 | cur = wildA->nsSet; |
| 11483 | while (cur != NULL) { |
| 11484 | found = 0; |
| 11485 | curB = wildB->nsSet; |
| 11486 | while (curB != NULL) { |
| 11487 | if (cur->value == curB->value) { |
| 11488 | found = 1; |
| 11489 | break; |
| 11490 | } |
| 11491 | curB = curB->next; |
| 11492 | } |
| 11493 | if (!found) |
| 11494 | return (0); |
| 11495 | cur = cur->next; |
| 11496 | } |
| 11497 | if (found) |
| 11498 | return (1); |
| 11499 | } else if (wildB->negNsSet != NULL) { |
| 11500 | xmlSchemaWildcardNsPtr cur; |
| 11501 | /* |
| 11502 | * 3.2.2 super must be a pair of not and a namespace name or |
| 11503 | * ·absent· and that value must not be in sub's set. |
| 11504 | */ |
| 11505 | cur = wildA->nsSet; |
| 11506 | while (cur != NULL) { |
| 11507 | if (cur->value == wildB->negNsSet->value) |
| 11508 | return (0); |
| 11509 | cur = cur->next; |
| 11510 | } |
| 11511 | return (1); |
| 11512 | } |
| 11513 | } |
| 11514 | return (0); |
| 11515 | } |
| 11516 | |
| 11517 | /** |
| 11518 | * xmlSchemaBuildCompleteAttributeWildcard: |
| 11519 | * @ctxt: the schema parser context |
| 11520 | * @attrs: the attribute list |
| 11521 | * @completeWild: the resulting complete wildcard |
| 11522 | * |
| 11523 | * Returns -1 in case of an internal error, 0 otherwise. |
| 11524 | */ |
| 11525 | static int |
| 11526 | xmlSchemaBuildCompleteAttributeWildcard(xmlSchemaParserCtxtPtr ctxt, |
| 11527 | xmlSchemaAttributePtr attrs, |
| 11528 | xmlSchemaWildcardPtr *completeWild) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11529 | { |
| 11530 | while (attrs != NULL) { |
| 11531 | if (attrs->type == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) { |
| 11532 | xmlSchemaAttributeGroupPtr group; |
| 11533 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11534 | group = (xmlSchemaAttributeGroupPtr) attrs; |
| 11535 | /* |
| 11536 | * Handle attribute group references. |
| 11537 | */ |
| 11538 | if (group->ref != NULL) { |
| 11539 | if (group->refItem == NULL) { |
| 11540 | /* |
| 11541 | * TODO: Should we raise a warning here? |
| 11542 | */ |
| 11543 | /* |
| 11544 | * The referenced attribute group definition could not |
| 11545 | * be resolved beforehand, so skip. |
| 11546 | */ |
| 11547 | attrs = attrs->next; |
| 11548 | continue; |
| 11549 | } else |
| 11550 | group = group->refItem; |
| 11551 | } |
| 11552 | /* |
| 11553 | * For every attribute group definition, an intersected wildcard |
| 11554 | * will be created (assumed that a wildcard exists on the |
| 11555 | * particular attr. gr. def. or on any contained attr. gr. def |
| 11556 | * at all). |
| 11557 | * The flag XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED ensures |
| 11558 | * that the intersection will be performed only once. |
| 11559 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11560 | if ((group->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED) == 0) { |
| 11561 | if (group->attributes != NULL) { |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11562 | if (xmlSchemaBuildCompleteAttributeWildcard(ctxt, |
| 11563 | group->attributes, &group->attributeWildcard) == -1) |
| 11564 | return (-1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11565 | } |
| 11566 | group->flags |= XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED; |
| 11567 | } |
| 11568 | if (group->attributeWildcard != NULL) { |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11569 | if (*completeWild == NULL) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11570 | /* |
| 11571 | * Copy the first encountered wildcard as context, except for the annotation. |
| 11572 | */ |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11573 | *completeWild = xmlSchemaAddWildcard(ctxt); |
| 11574 | (*completeWild)->type = XML_SCHEMA_TYPE_ANY_ATTRIBUTE; |
| 11575 | if (xmlSchemaCloneWildcardNsConstraints(ctxt, |
| 11576 | completeWild, group->attributeWildcard) == -1) |
| 11577 | return (-1); |
| 11578 | (*completeWild)->processContents = group->attributeWildcard->processContents; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11579 | /* |
| 11580 | * Although the complete wildcard might not correspond to any |
| 11581 | * node in the schema, we will save this context node. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11582 | * TODO: Hmm, is this sane? |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11583 | */ |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11584 | (*completeWild)->node = group->attributeWildcard->node; |
| 11585 | |
| 11586 | } else if (xmlSchemaIntersectWildcards(ctxt, *completeWild, group->attributeWildcard) == -1) { |
| 11587 | xmlSchemaFreeWildcard(*completeWild); |
| 11588 | return (-1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11589 | } |
| 11590 | } |
| 11591 | } |
| 11592 | attrs = attrs->next; |
| 11593 | } |
| 11594 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11595 | return (0); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11596 | } |
| 11597 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11598 | static int |
| 11599 | xmlSchemaGetEffectiveValueConstraint(xmlSchemaAttributePtr item, |
| 11600 | int *fixed, |
| 11601 | const xmlChar **value, |
| 11602 | xmlSchemaValPtr *val) |
| 11603 | { |
| 11604 | *fixed = 0; |
| 11605 | *value = NULL; |
| 11606 | if (val != 0) |
| 11607 | *val = NULL; |
| 11608 | |
| 11609 | if (item->defValue == NULL) |
| 11610 | item = item->refDecl; |
| 11611 | |
| 11612 | if (item == NULL) |
| 11613 | return (0); |
| 11614 | |
| 11615 | if (item->defValue != NULL) { |
| 11616 | *value = item->defValue; |
| 11617 | if (val != 0) |
| 11618 | *val = item->defVal; |
| 11619 | if (item->flags & XML_SCHEMAS_ATTR_FIXED) |
| 11620 | *fixed = 1; |
| 11621 | return (1); |
| 11622 | } |
| 11623 | return (0); |
| 11624 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11625 | /** |
| 11626 | * xmlSchemaMatchesWildcardNs: |
| 11627 | * @wild: the wildcard |
| 11628 | * @ns: the namespace |
| 11629 | * |
| 11630 | * |
| 11631 | * Returns 1 if the given namespace matches the wildcard, |
| 11632 | * 0 otherwise. |
| 11633 | */ |
| 11634 | static int |
| 11635 | xmlSchemaMatchesWildcardNs(xmlSchemaWildcardPtr wild, const xmlChar* ns) |
| 11636 | { |
| 11637 | if (wild == NULL) |
| 11638 | return(0); |
| 11639 | |
| 11640 | if (wild->any) |
| 11641 | return(1); |
| 11642 | else if (wild->nsSet != NULL) { |
| 11643 | xmlSchemaWildcardNsPtr cur; |
| 11644 | |
| 11645 | cur = wild->nsSet; |
| 11646 | while (cur != NULL) { |
| 11647 | if (xmlStrEqual(cur->value, ns)) |
| 11648 | return(1); |
| 11649 | cur = cur->next; |
| 11650 | } |
| 11651 | } else if ((wild->negNsSet != NULL) && (ns != NULL) && |
| 11652 | (!xmlStrEqual(wild->negNsSet->value, ns))) |
| 11653 | return(1); |
| 11654 | |
| 11655 | return(0); |
| 11656 | } |
| 11657 | |
| 11658 | /** |
| 11659 | * xmlSchemaBuildAttributeValidation: |
| 11660 | * @ctxt: the schema parser context |
| 11661 | * @type: the complex type definition |
| 11662 | * |
| 11663 | * |
| 11664 | * Builds the wildcard and the attribute uses on the given complex type. |
| 11665 | * Returns -1 if an internal error occurs, 0 otherwise. |
| 11666 | */ |
| 11667 | static int |
| 11668 | xmlSchemaBuildAttributeValidation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaTypePtr type) |
| 11669 | { |
| 11670 | xmlSchemaTypePtr baseType = NULL; |
| 11671 | xmlSchemaAttributeLinkPtr cur, base, tmp, id = NULL, prev = NULL, uses = NULL, |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 11672 | lastUse = NULL, lastBaseUse = NULL; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11673 | xmlSchemaAttributePtr attrs; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11674 | xmlSchemaTypePtr anyType; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11675 | int baseIsAnyType = 0; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11676 | xmlChar *str = NULL; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 11677 | int err = 0; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11678 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11679 | anyType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11680 | /* |
| 11681 | * Complex Type Definition with complex content Schema Component. |
| 11682 | * |
| 11683 | * Attribute uses. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11684 | * TODO: Add checks for absent referenced attribute declarations and |
| 11685 | * simple types. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11686 | */ |
| 11687 | if (type->attributeUses != NULL) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 11688 | xmlSchemaPErr(ctxt, type->node, XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11689 | "Internal error: xmlSchemaBuildAttributeValidation: " |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11690 | "attribute uses already builded.\n", |
| 11691 | NULL, NULL); |
| 11692 | return (-1); |
| 11693 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11694 | if (type->baseType == NULL) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 11695 | xmlSchemaPErr(ctxt, type->node, XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11696 | "Internal error: xmlSchemaBuildAttributeValidation: " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11697 | "complex type '%s' has no base type.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11698 | type->name, NULL); |
| 11699 | return (-1); |
| 11700 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11701 | baseType = type->baseType; |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11702 | if (baseType == anyType) |
| 11703 | baseIsAnyType = 1; |
| 11704 | /* |
| 11705 | * Inherit the attribute uses of the base type. |
| 11706 | */ |
| 11707 | /* |
| 11708 | * NOTE: It is allowed to "extend" the anyType complex type. |
| 11709 | */ |
| 11710 | if (!baseIsAnyType) { |
| 11711 | if (baseType != NULL) { |
| 11712 | for (cur = baseType->attributeUses; cur != NULL; cur = cur->next) { |
| 11713 | tmp = (xmlSchemaAttributeLinkPtr) |
| 11714 | xmlMalloc(sizeof(xmlSchemaAttributeLink)); |
| 11715 | if (tmp == NULL) { |
| 11716 | xmlSchemaPErrMemory(ctxt, |
| 11717 | "building attribute uses of complexType", NULL); |
| 11718 | return (-1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11719 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11720 | tmp->attr = cur->attr; |
| 11721 | tmp->next = NULL; |
| 11722 | if (type->attributeUses == NULL) { |
| 11723 | type->attributeUses = tmp; |
| 11724 | } else |
| 11725 | lastBaseUse->next = tmp; |
| 11726 | lastBaseUse = tmp; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11727 | } |
| 11728 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11729 | } |
| 11730 | if ((type->subtypes != NULL) && |
| 11731 | ((type->subtypes->type == XML_SCHEMA_TYPE_COMPLEX_CONTENT) || |
| 11732 | (type->subtypes->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT))) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11733 | /* |
| 11734 | * type --> (<simpleContent>|<complexContent>) |
| 11735 | * --> (<restriction>|<extension>) --> attributes |
| 11736 | */ |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11737 | attrs = type->subtypes->subtypes->attributes; |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11738 | } else { |
| 11739 | /* Short hand form of the complexType. */ |
| 11740 | attrs = type->attributes; |
| 11741 | } |
| 11742 | /* |
| 11743 | * Handle attribute wildcards. |
| 11744 | */ |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 11745 | err = xmlSchemaBuildCompleteAttributeWildcard(ctxt, |
| 11746 | attrs, &type->attributeWildcard); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11747 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11748 | * NOTE: During the parse time, the wildcard is created on the complexType |
| 11749 | * directly, if encountered in a <restriction> or <extension> element. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11750 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11751 | if (err == -1) { |
| 11752 | xmlSchemaPErr(ctxt, type->node, XML_SCHEMAP_INTERNAL, |
| 11753 | "Internal error: xmlSchemaBuildAttributeValidation: " |
| 11754 | "failed to build an intersected attribute wildcard.\n", |
| 11755 | NULL, NULL); |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 11756 | return (-1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11757 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11758 | |
| 11759 | if ((type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) && |
| 11760 | ((baseIsAnyType) || |
| 11761 | ((baseType != NULL) && |
| 11762 | (baseType->type == XML_SCHEMA_TYPE_COMPLEX) && |
| 11763 | (baseType->attributeWildcard != NULL)))) { |
| 11764 | if (type->attributeWildcard != NULL) { |
| 11765 | /* |
| 11766 | * Union the complete wildcard with the base wildcard. |
| 11767 | */ |
| 11768 | if (xmlSchemaUnionWildcards(ctxt, type->attributeWildcard, |
| 11769 | baseType->attributeWildcard) == -1) |
| 11770 | return (-1); |
| 11771 | } else { |
| 11772 | /* |
| 11773 | * Just inherit the wildcard. |
| 11774 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11775 | /* |
| 11776 | * NOTE: This is the only case where an attribute |
| 11777 | * wildcard is shared. |
| 11778 | */ |
| 11779 | if (type->flags & XML_SCHEMAS_TYPE_OWNED_ATTR_WILDCARD) |
| 11780 | type->flags ^= XML_SCHEMAS_TYPE_OWNED_ATTR_WILDCARD; |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11781 | type->attributeWildcard = baseType->attributeWildcard; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11782 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11783 | } |
| 11784 | |
| 11785 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
| 11786 | if (type->attributeWildcard != NULL) { |
| 11787 | /* |
| 11788 | * Derivation Valid (Restriction, Complex) |
| 11789 | * 4.1 The {base type definition} must also have one. |
| 11790 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11791 | if (baseType->attributeWildcard == NULL) { |
| 11792 | xmlSchemaPCustomErr(ctxt, |
| 11793 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_1, |
| 11794 | NULL, type, NULL, |
| 11795 | "The type has an attribute wildcard, " |
| 11796 | "but the base type %s does not have one", |
| 11797 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 11798 | FREE_AND_NULL(str) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11799 | return (1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11800 | } else if (xmlSchemaIsWildcardNsConstraintSubset( |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11801 | type->attributeWildcard, baseType->attributeWildcard) == 0) { |
| 11802 | /* 4.2 */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11803 | xmlSchemaPCustomErr(ctxt, |
| 11804 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_2, |
| 11805 | NULL, type, NULL, |
| 11806 | "The attribute wildcard is not a valid " |
| 11807 | "subset of the wildcard in the base type %s", |
| 11808 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 11809 | FREE_AND_NULL(str) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11810 | return (1); |
| 11811 | } |
| 11812 | /* 4.3 Unless the {base type definition} is the ·ur-type |
| 11813 | * definition·, the complex type definition's {attribute |
| 11814 | * wildcard}'s {process contents} must be identical to or |
| 11815 | * stronger than the {base type definition}'s {attribute |
| 11816 | * wildcard}'s {process contents}, where strict is stronger |
| 11817 | * than lax is stronger than skip. |
| 11818 | */ |
| 11819 | if ((type->baseType != anyType) && |
| 11820 | (type->attributeWildcard->processContents < |
| 11821 | baseType->attributeWildcard->processContents)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11822 | xmlSchemaPCustomErr(ctxt, |
| 11823 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_3, |
| 11824 | NULL, type, NULL, |
| 11825 | "The 'process contents' of the attribute wildcard is weaker than " |
| 11826 | "the one in the base type %s", |
| 11827 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 11828 | FREE_AND_NULL(str) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11829 | return (1); |
| 11830 | } |
| 11831 | } |
| 11832 | } else if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) { |
| 11833 | /* |
| 11834 | * Derivation Valid (Extension) |
| 11835 | * At this point the type and the base have both, either |
| 11836 | * no wildcard or a wildcard. |
| 11837 | */ |
| 11838 | if ((baseType->attributeWildcard != NULL) && |
| 11839 | (baseType->attributeWildcard != type->attributeWildcard)) { |
| 11840 | /* 1.3 */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11841 | if (xmlSchemaIsWildcardNsConstraintSubset( |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11842 | baseType->attributeWildcard, type->attributeWildcard) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11843 | xmlSchemaPCustomErr(ctxt, |
| 11844 | XML_SCHEMAP_COS_CT_EXTENDS_1_3, |
| 11845 | NULL, type, NULL, |
| 11846 | "The attribute wildcard is not a valid " |
| 11847 | "superset of the one in the base type %s", |
| 11848 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 11849 | FREE_AND_NULL(str) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11850 | return (1); |
| 11851 | } |
| 11852 | } |
| 11853 | } |
| 11854 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11855 | /* |
| 11856 | * Gather attribute uses defined by this type. |
| 11857 | */ |
| 11858 | if (attrs != NULL) { |
| 11859 | if (xmlSchemaBuildAttributeUsesOwned(ctxt, attrs, |
| 11860 | &uses, &lastUse) == -1) { |
| 11861 | return (-1); |
| 11862 | } |
| 11863 | } |
| 11864 | /* 3.4.6 -> Complex Type Definition Properties Correct 4. |
| 11865 | * "Two distinct attribute declarations in the {attribute uses} must |
| 11866 | * not have identical {name}s and {target namespace}s." |
| 11867 | * |
| 11868 | * For "extension" this is done further down. |
| 11869 | */ |
| 11870 | if ((uses != NULL) && ((type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) == 0)) { |
| 11871 | cur = uses; |
| 11872 | while (cur != NULL) { |
| 11873 | tmp = cur->next; |
| 11874 | while (tmp != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11875 | if ((xmlStrEqual(xmlSchemaGetAttrName(cur->attr), |
| 11876 | xmlSchemaGetAttrName(tmp->attr))) && |
| 11877 | (xmlStrEqual(xmlSchemaGetAttrTargetNsURI(cur->attr ), |
| 11878 | xmlSchemaGetAttrTargetNsURI(tmp->attr)))) { |
| 11879 | |
| 11880 | xmlSchemaPAttrUseErr(ctxt, |
| 11881 | XML_SCHEMAP_CT_PROPS_CORRECT_4, |
| 11882 | NULL, type, NULL, cur->attr, |
| 11883 | "Duplicate attribute use %s specified", |
| 11884 | xmlSchemaFormatNsUriLocal(&str, |
| 11885 | xmlSchemaGetAttrTargetNsURI(tmp->attr), |
| 11886 | xmlSchemaGetAttrName(tmp->attr)) |
| 11887 | ); |
| 11888 | FREE_AND_NULL(str) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11889 | break; |
| 11890 | } |
| 11891 | tmp = tmp->next; |
| 11892 | } |
| 11893 | cur = cur->next; |
| 11894 | } |
| 11895 | } |
| 11896 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
| 11897 | /* |
| 11898 | * Derive by restriction. |
| 11899 | */ |
| 11900 | if (baseIsAnyType) { |
| 11901 | type->attributeUses = uses; |
| 11902 | } else { |
| 11903 | int found; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11904 | const xmlChar *bEffValue; |
| 11905 | int effFixed; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11906 | |
| 11907 | cur = uses; |
| 11908 | while (cur != NULL) { |
| 11909 | found = 0; |
| 11910 | base = type->attributeUses; |
| 11911 | while (base != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11912 | if (xmlStrEqual(xmlSchemaGetAttrName(cur->attr), |
| 11913 | xmlSchemaGetAttrName(base->attr)) && |
| 11914 | xmlStrEqual(xmlSchemaGetAttrTargetNsURI(cur->attr), |
| 11915 | xmlSchemaGetAttrTargetNsURI(base->attr))) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11916 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11917 | found = 1; |
| 11918 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11919 | if ((cur->attr->occurs == XML_SCHEMAS_ATTR_USE_OPTIONAL) && |
| 11920 | (base->attr->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED)) { |
| 11921 | /* |
| 11922 | * derivation-ok-restriction 2.1.1 |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11923 | */ |
| 11924 | xmlSchemaPAttrUseErr(ctxt, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11925 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11926 | NULL, type, NULL, cur->attr, |
| 11927 | "The 'optional' use is inconsistent with a matching " |
| 11928 | "'required' use of the base type", NULL); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11929 | } else if ((cur->attr->occurs == XML_SCHEMAS_ATTR_USE_PROHIBITED) && |
| 11930 | (base->attr->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED)) { |
| 11931 | /* |
| 11932 | * derivation-ok-restriction 3 |
| 11933 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11934 | xmlSchemaPCustomErr(ctxt, |
| 11935 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_3, |
| 11936 | NULL, type, NULL, |
| 11937 | "A matching attribute use for the 'required' " |
| 11938 | "attribute use %s of the base type is missing", |
| 11939 | xmlSchemaFormatNsUriLocal(&str, |
| 11940 | xmlSchemaGetAttrTargetNsURI(base->attr), |
| 11941 | xmlSchemaGetAttrName(base->attr))); |
| 11942 | FREE_AND_NULL(str) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11943 | } else { |
| 11944 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11945 | * 2.1.3 [Definition:] Let the effective value |
| 11946 | * constraint of an attribute use be its {value |
| 11947 | * constraint}, if present, otherwise its {attribute |
| 11948 | * declaration}'s {value constraint} . |
| 11949 | */ |
| 11950 | xmlSchemaGetEffectiveValueConstraint(base->attr, &effFixed, |
| 11951 | &bEffValue, 0); |
| 11952 | /* |
| 11953 | * 2.1.3 ... one of the following must be true |
| 11954 | * |
| 11955 | * 2.1.3.1 B's ·effective value constraint· is |
| 11956 | * ·absent· or default. |
| 11957 | */ |
| 11958 | if ((bEffValue != NULL) && |
| 11959 | (effFixed == 1)) { |
| 11960 | const xmlChar *rEffValue = NULL; |
| 11961 | |
| 11962 | xmlSchemaGetEffectiveValueConstraint(base->attr, &effFixed, |
| 11963 | &rEffValue, 0); |
| 11964 | /* |
| 11965 | * 2.1.3.2 R's ·effective value constraint· is |
| 11966 | * fixed with the same string as B's. |
| 11967 | */ |
| 11968 | if ((effFixed == 0) || |
| 11969 | (! xmlStrEqual(rEffValue, bEffValue))) { |
| 11970 | xmlSchemaPAttrUseErr(ctxt, |
| 11971 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_3, |
| 11972 | NULL, type, NULL, cur->attr, |
| 11973 | "The effective value constraint of the " |
| 11974 | "attribute use is inconsistent with " |
| 11975 | "its correspondent of the base type", |
| 11976 | NULL); |
| 11977 | } |
| 11978 | } |
| 11979 | /* |
| 11980 | * TODO: derivation-ok-restriction 2.1.2 ({type definition} must be validly derived) |
| 11981 | */ |
| 11982 | /* |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11983 | * Override the attribute use. |
| 11984 | */ |
| 11985 | base->attr = cur->attr; |
| 11986 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11987 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11988 | break; |
| 11989 | } |
| 11990 | base = base->next; |
| 11991 | } |
| 11992 | |
| 11993 | if (!found) { |
| 11994 | if (cur->attr->occurs != XML_SCHEMAS_ATTR_USE_PROHIBITED) { |
| 11995 | /* |
| 11996 | * derivation-ok-restriction 2.2 |
| 11997 | */ |
| 11998 | if ((type->attributeWildcard != NULL) && |
| 11999 | xmlSchemaMatchesWildcardNs(type->attributeWildcard, |
| 12000 | cur->attr->targetNamespace)) |
| 12001 | found = 1; |
| 12002 | |
| 12003 | if (!found) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12004 | xmlSchemaPAttrUseErr(ctxt, |
| 12005 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_2, |
| 12006 | NULL, type, NULL, cur->attr, |
| 12007 | "Neither a matching attribute use, " |
| 12008 | "nor a matching wildcard in the base type does exist", |
| 12009 | NULL); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12010 | } else { |
| 12011 | /* |
| 12012 | * Add the attribute use. |
| 12013 | * |
| 12014 | * Note that this may lead to funny derivation error reports, if |
| 12015 | * multiple equal attribute uses exist; but this is not |
| 12016 | * allowed anyway, and it will be reported beforehand. |
| 12017 | */ |
| 12018 | tmp = cur; |
| 12019 | if (prev != NULL) |
| 12020 | prev->next = cur->next; |
| 12021 | else |
| 12022 | uses = cur->next; |
| 12023 | cur = cur->next; |
| 12024 | if (type->attributeUses == NULL) { |
| 12025 | type->attributeUses = tmp; |
| 12026 | } else |
| 12027 | lastBaseUse->next = tmp; |
| 12028 | lastBaseUse = tmp; |
| 12029 | |
| 12030 | continue; |
| 12031 | } |
| 12032 | } |
| 12033 | } |
| 12034 | prev = cur; |
| 12035 | cur = cur->next; |
| 12036 | } |
| 12037 | if (uses != NULL) |
| 12038 | xmlSchemaFreeAttributeUseList(uses); |
| 12039 | } |
| 12040 | } else if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) { |
| 12041 | /* |
| 12042 | * The spec allows only appending, and not other kinds of extensions. |
| 12043 | * |
| 12044 | * This ensures: Schema Component Constraint: Derivation Valid (Extension) : 1.2 |
| 12045 | */ |
| 12046 | if (uses != NULL) { |
| 12047 | if (type->attributeUses == NULL) { |
| 12048 | type->attributeUses = uses; |
| 12049 | } else |
| 12050 | lastBaseUse->next = uses; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12051 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12052 | } else { |
| 12053 | /* |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12054 | * Derive implicitely from the ur-type. |
| 12055 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12056 | type->attributeUses = uses; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12057 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12058 | /* |
| 12059 | * 3.4.6 -> Complex Type Definition Properties Correct |
| 12060 | */ |
| 12061 | if (type->attributeUses != NULL) { |
| 12062 | cur = type->attributeUses; |
| 12063 | prev = NULL; |
| 12064 | while (cur != NULL) { |
| 12065 | /* |
| 12066 | * 4. Two distinct attribute declarations in the {attribute uses} must |
| 12067 | * not have identical {name}s and {target namespace}s. |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12068 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12069 | * Note that this was already done for "restriction" and types derived from |
| 12070 | * the ur-type. |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12071 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12072 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) { |
| 12073 | tmp = cur->next; |
| 12074 | while (tmp != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12075 | if ((xmlStrEqual(xmlSchemaGetAttrName(cur->attr), |
| 12076 | xmlSchemaGetAttrName(tmp->attr))) && |
| 12077 | (xmlStrEqual(xmlSchemaGetAttrTargetNsURI(cur->attr ), |
| 12078 | xmlSchemaGetAttrTargetNsURI(tmp->attr)))) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12079 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12080 | xmlSchemaPAttrUseErr(ctxt, |
| 12081 | XML_SCHEMAP_CT_PROPS_CORRECT_4, |
| 12082 | NULL, type, NULL, tmp->attr, |
| 12083 | "Duplicate attribute use specified", NULL); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12084 | break; |
| 12085 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12086 | tmp = tmp->next; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12087 | } |
| 12088 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12089 | /* |
| 12090 | * 5. Two distinct attribute declarations in the {attribute uses} must |
| 12091 | * not have {type definition}s which are or are derived from ID. |
| 12092 | */ |
| 12093 | if ((cur->attr->subtypes != NULL) && |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12094 | (xmlSchemaIsDerivedFromBuiltInType(ctxt, (xmlSchemaTypePtr) cur->attr, XML_SCHEMAS_ID))) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12095 | if (id != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12096 | xmlSchemaPAttrUseErr(ctxt, |
| 12097 | XML_SCHEMAP_CT_PROPS_CORRECT_5, |
| 12098 | NULL, type, NULL, cur->attr, |
| 12099 | "There must not exist more than one attribute use, " |
| 12100 | "declared of type 'ID' or derived from it", |
| 12101 | NULL); |
| 12102 | FREE_AND_NULL(str) |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12103 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12104 | id = cur; |
| 12105 | } |
| 12106 | /* |
| 12107 | * Remove "prohibited" attribute uses. The reason this is done at this late |
| 12108 | * stage is to be able to catch dublicate attribute uses. So we had to keep |
| 12109 | * prohibited uses in the list as well. |
| 12110 | */ |
| 12111 | if (cur->attr->occurs == XML_SCHEMAS_ATTR_USE_PROHIBITED) { |
| 12112 | tmp = cur; |
| 12113 | if (prev == NULL) |
| 12114 | type->attributeUses = cur->next; |
| 12115 | else |
| 12116 | prev->next = cur->next; |
| 12117 | cur = cur->next; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 12118 | xmlFree(tmp); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12119 | } else { |
| 12120 | prev = cur; |
| 12121 | cur = cur->next; |
| 12122 | } |
| 12123 | } |
| 12124 | } |
| 12125 | /* |
| 12126 | * TODO: This check should be removed if we are 100% sure of |
| 12127 | * the base type attribute uses already being built. |
| 12128 | */ |
| 12129 | if ((baseType != NULL) && (!baseIsAnyType) && |
| 12130 | (baseType->type == XML_SCHEMA_TYPE_COMPLEX) && |
| 12131 | (baseType->contentType == XML_SCHEMA_CONTENT_UNKNOWN)) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 12132 | xmlSchemaPErr(ctxt, baseType->node, XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12133 | "Internal error: xmlSchemaBuildAttributeValidation: " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12134 | "attribute uses not builded on base type '%s'.\n", |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12135 | baseType->name, NULL); |
| 12136 | } |
| 12137 | return (0); |
| 12138 | } |
| 12139 | |
| 12140 | /** |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12141 | * xmlSchemaTypeFinalContains: |
| 12142 | * @schema: the schema |
| 12143 | * @type: the type definition |
| 12144 | * @final: the final |
| 12145 | * |
| 12146 | * Evaluates if a type definition contains the given "final". |
| 12147 | * This does take "finalDefault" into account as well. |
| 12148 | * |
| 12149 | * Returns 1 if the type does containt the given "final", |
| 12150 | * 0 otherwise. |
| 12151 | */ |
| 12152 | static int |
| 12153 | xmlSchemaTypeFinalContains(xmlSchemaPtr schema, xmlSchemaTypePtr type, int final) |
| 12154 | { |
| 12155 | int tfinal = final, tflags = type->flags; |
| 12156 | |
| 12157 | if (type == NULL) |
| 12158 | return (0); |
| 12159 | if (type->flags & XML_SCHEMAS_TYPE_FINAL_DEFAULT) { |
| 12160 | switch (final) { |
| 12161 | case XML_SCHEMAS_TYPE_FINAL_RESTRICTION: |
| 12162 | tfinal = XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION; |
| 12163 | break; |
| 12164 | case XML_SCHEMAS_TYPE_FINAL_EXTENSION: |
| 12165 | tfinal = XML_SCHEMAS_FINAL_DEFAULT_EXTENSION; |
| 12166 | break; |
| 12167 | case XML_SCHEMAS_TYPE_FINAL_LIST: |
| 12168 | tfinal = XML_SCHEMAS_FINAL_DEFAULT_LIST; |
| 12169 | break; |
| 12170 | case XML_SCHEMAS_TYPE_FINAL_UNION: |
| 12171 | tfinal = XML_SCHEMAS_FINAL_DEFAULT_UNION; |
| 12172 | break; |
| 12173 | } |
| 12174 | tflags = schema->flags; |
| 12175 | } |
| 12176 | if (tflags & tfinal) |
| 12177 | return (1); |
| 12178 | else |
| 12179 | return (0); |
| 12180 | |
| 12181 | } |
| 12182 | |
| 12183 | /** |
| 12184 | * xmlSchemaGetUnionSimpleTypeMemberTypes: |
| 12185 | * @type: the Union Simple Type |
| 12186 | * |
| 12187 | * Returns a list of member types of @type if existing, |
| 12188 | * returns NULL otherwise. |
| 12189 | */ |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12190 | static xmlSchemaTypeLinkPtr |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12191 | xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type) |
| 12192 | { |
| 12193 | while (type != NULL) { |
| 12194 | if (type->memberTypes != NULL) |
| 12195 | return (type->memberTypes); |
| 12196 | else |
| 12197 | type = type->baseType; |
| 12198 | } |
| 12199 | return (NULL); |
| 12200 | } |
| 12201 | |
| 12202 | /** |
| 12203 | * xmlSchemaGetListSimpleTypeItemType: |
| 12204 | * @type: the simple type definition |
| 12205 | * |
| 12206 | * Returns the item type definition of the list simple type. |
| 12207 | */ |
| 12208 | static xmlSchemaTypePtr |
| 12209 | xmlSchemaGetListSimpleTypeItemType(xmlSchemaTypePtr type) |
| 12210 | { |
| 12211 | if ((type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) == 0) |
| 12212 | return (NULL); |
| 12213 | /* |
| 12214 | * Note: In libxml2, the built-in types do not reflect |
| 12215 | * the datatype hierarchy (yet?) - we have to treat them |
| 12216 | * in a special way. |
| 12217 | */ |
| 12218 | if (type->type == XML_SCHEMA_TYPE_BASIC) |
| 12219 | return (xmlSchemaGetBuiltInListSimpleTypeItemType(type)); |
| 12220 | if (type->subtypes->type == XML_SCHEMA_TYPE_LIST) |
| 12221 | /* 1 If the <list> alternative is chosen, then the type |
| 12222 | * definition ·resolved· to by the ·actual value· of the |
| 12223 | * itemType [attribute] of <list>, if present, otherwise |
| 12224 | * the type definition corresponding to the <simpleType> |
| 12225 | * among the [children] of <list>. |
| 12226 | */ |
| 12227 | return (type->subtypes->subtypes); |
| 12228 | else { |
| 12229 | /* 2 If the <restriction> option is chosen, then the |
| 12230 | * {item type definition} of the {base type definition}. |
| 12231 | */ |
| 12232 | return (xmlSchemaGetListSimpleTypeItemType(type->baseType)); |
| 12233 | } |
| 12234 | } |
| 12235 | |
| 12236 | /** |
| 12237 | * xmlSchemaCheckCOSSTDerivedOK: |
| 12238 | * @type: the derived simple type definition |
| 12239 | * @baseType: the base type definition |
| 12240 | * |
| 12241 | * Checks wheter @type can be validly |
| 12242 | * derived from @baseType. |
| 12243 | * |
| 12244 | * Returns 0 on success, an positive error code otherwise. |
| 12245 | */ |
| 12246 | static int |
| 12247 | xmlSchemaCheckCOSSTDerivedOK(xmlSchemaPtr schema, |
| 12248 | xmlSchemaTypePtr type, |
| 12249 | xmlSchemaTypePtr baseType, |
| 12250 | int subset) |
| 12251 | { |
| 12252 | /* |
| 12253 | * Schema Component Constraint: Type Derivation OK (Simple) |
| 12254 | * |
| 12255 | * |
| 12256 | * 1 They are the same type definition. |
| 12257 | * TODO: The identy check might have to be more complex than this. |
| 12258 | */ |
| 12259 | if (type == baseType) |
| 12260 | return (0); |
| 12261 | /* |
| 12262 | * 2.1 restriction is not in the subset, or in the {final} |
| 12263 | * of its own {base type definition}; |
| 12264 | */ |
| 12265 | if ((subset & XML_SCHEMAS_TYPE_FINAL_RESTRICTION) || |
| 12266 | (xmlSchemaTypeFinalContains(schema, |
| 12267 | type->baseType, XML_SCHEMAS_TYPE_FINAL_RESTRICTION))) { |
| 12268 | return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_1); |
| 12269 | } |
| 12270 | /* 2.2 */ |
| 12271 | if (type->baseType == baseType) { |
| 12272 | /* |
| 12273 | * 2.2.1 D's ·base type definition· is B. |
| 12274 | */ |
| 12275 | return (0); |
| 12276 | } |
| 12277 | /* |
| 12278 | * 2.2.2 D's ·base type definition· is not the ·ur-type definition· |
| 12279 | * and is validly derived from B given the subset, as defined by this |
| 12280 | * constraint. |
| 12281 | */ |
| 12282 | if ((type->baseType != xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE)) && |
| 12283 | (xmlSchemaCheckCOSSTDerivedOK(schema, type->baseType, baseType, subset) == 0)) { |
| 12284 | return (0); |
| 12285 | } |
| 12286 | /* |
| 12287 | * 2.2.3 D's {variety} is list or union and B is the ·simple ur-type |
| 12288 | * definition·. |
| 12289 | */ |
| 12290 | if (((type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) || |
| 12291 | (type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION)) && |
| 12292 | (baseType == xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE))) { |
| 12293 | return (0); |
| 12294 | } |
| 12295 | /* |
| 12296 | * 2.2.4 B's {variety} is union and D is validly derived from a type |
| 12297 | * definition in B's {member type definitions} given the subset, as |
| 12298 | * defined by this constraint. |
| 12299 | * |
| 12300 | * NOTE: This seems not to involve built-in types, since there is no |
| 12301 | * built-in Union Simple Type. |
| 12302 | */ |
| 12303 | if (baseType->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
| 12304 | xmlSchemaTypeLinkPtr cur; |
| 12305 | |
| 12306 | cur = baseType->memberTypes; |
| 12307 | while (cur != NULL) { |
| 12308 | if (xmlSchemaCheckCOSSTDerivedOK(schema, type, |
| 12309 | cur->type, subset) == 0) |
| 12310 | return (0); |
| 12311 | cur = cur->next; |
| 12312 | } |
| 12313 | } |
| 12314 | |
| 12315 | return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_2); |
| 12316 | } |
| 12317 | |
| 12318 | |
| 12319 | /** |
| 12320 | * xmlSchemaCheckSTPropsCorrect: |
| 12321 | * @ctxt: the schema parser context |
| 12322 | * @type: the simple type definition |
| 12323 | * |
| 12324 | * Checks st-props-correct. |
| 12325 | * |
| 12326 | * Returns 0 if the properties are correct, |
| 12327 | * if not, a positive error code and -1 on internal |
| 12328 | * errors. |
| 12329 | */ |
| 12330 | static int |
| 12331 | xmlSchemaCheckSTPropsCorrect(xmlSchemaParserCtxtPtr ctxt, |
| 12332 | xmlSchemaTypePtr type) |
| 12333 | { |
| 12334 | xmlSchemaTypePtr baseType = type->baseType, anySimpleType, |
| 12335 | anyType; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12336 | xmlChar *str = NULL; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12337 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12338 | /* STATE: error funcs converted. */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12339 | /* |
| 12340 | * Schema Component Constraint: Simple Type Definition Properties Correct |
| 12341 | * |
| 12342 | * NOTE: This is somehow redundant, since we actually built a simple type |
| 12343 | * to have all the needed information; this acts as an self test. |
| 12344 | */ |
| 12345 | anySimpleType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 12346 | anyType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 12347 | /* |
| 12348 | * TODO: 1 The values of the properties of a simple type definition must be as |
| 12349 | * described in the property tableau in Datatype definition, modulo the |
| 12350 | * impact of Missing Sub-components (§5.3). |
| 12351 | */ |
| 12352 | /* Base type: If the datatype has been ·derived· by ·restriction· |
| 12353 | * then the Simple Type Definition component from which it is ·derived·, |
| 12354 | * otherwise the Simple Type Definition for anySimpleType (§4.1.6). |
| 12355 | */ |
| 12356 | if (baseType == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12357 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12358 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12359 | NULL, type, NULL, |
| 12360 | "No base type existent", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12361 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
| 12362 | } |
| 12363 | if ((baseType->type != XML_SCHEMA_TYPE_SIMPLE) && |
| 12364 | ((baseType->type != XML_SCHEMA_TYPE_BASIC) || |
| 12365 | (baseType == anyType))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12366 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12367 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12368 | NULL, type, NULL, |
| 12369 | "The base type %s is not a simple type", |
| 12370 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 12371 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12372 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
| 12373 | } |
| 12374 | if ((baseType != anySimpleType) && |
| 12375 | (type->subtypes->type != XML_SCHEMA_TYPE_RESTRICTION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12376 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12377 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12378 | NULL, type, NULL, |
| 12379 | "A type, derived by list or union, must have" |
| 12380 | "the simple ur-type definition as base type, not %s", |
| 12381 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 12382 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12383 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
| 12384 | } |
| 12385 | /* |
| 12386 | * Variety: One of {atomic, list, union}. |
| 12387 | */ |
| 12388 | if (((type->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) == 0) && |
| 12389 | ((type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) == 0) && |
| 12390 | ((type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) == 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12391 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12392 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12393 | NULL, type, NULL, |
| 12394 | "The variety is absent", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12395 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
| 12396 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12397 | /* TODO: Finish this. Hmm, is this finished? */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12398 | |
| 12399 | /* |
| 12400 | * 2 All simple type definitions must be derived ultimately from the ·simple |
| 12401 | * ur-type definition (so· circular definitions are disallowed). That is, it |
| 12402 | * must be possible to reach a built-in primitive datatype or the ·simple |
| 12403 | * ur-type definition· by repeatedly following the {base type definition}. |
| 12404 | */ |
| 12405 | baseType = type->baseType; |
| 12406 | while ((baseType != NULL) && (baseType->type != XML_SCHEMA_TYPE_BASIC)) { |
| 12407 | if (baseType->contentType == XML_SCHEMA_CONTENT_UNKNOWN) |
| 12408 | xmlSchemaTypeFixup(baseType, ctxt, NULL); |
| 12409 | if (baseType == anySimpleType) |
| 12410 | break; |
| 12411 | else if (baseType == type) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12412 | xmlSchemaPCustomErr(ctxt, |
| 12413 | XML_SCHEMAP_ST_PROPS_CORRECT_2, |
| 12414 | NULL, type, NULL, |
| 12415 | "The definition is circular", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12416 | return (XML_SCHEMAP_ST_PROPS_CORRECT_2); |
| 12417 | } |
| 12418 | baseType = baseType->baseType; |
| 12419 | } |
| 12420 | /* |
| 12421 | * 3 The {final} of the {base type definition} must not contain restriction. |
| 12422 | */ |
| 12423 | if (xmlSchemaTypeFinalContains(ctxt->schema, baseType, |
| 12424 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12425 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12426 | XML_SCHEMAP_ST_PROPS_CORRECT_3, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12427 | NULL, type, NULL, |
| 12428 | "The 'final' of its base type %s must not contain " |
| 12429 | "'restriction'", |
| 12430 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 12431 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12432 | return (XML_SCHEMAP_ST_PROPS_CORRECT_3); |
| 12433 | } |
| 12434 | return (0); |
| 12435 | } |
| 12436 | |
| 12437 | /** |
| 12438 | * xmlSchemaCheckDerivationValidSimpleRestriction: |
| 12439 | * @ctxt: the schema parser context |
| 12440 | * @type: the simple type definition |
| 12441 | * |
| 12442 | * Checks if the given @type (simpleType) is derived |
| 12443 | * validly by restriction. |
| 12444 | * |
| 12445 | * Returns -1 on internal errors, 0 if the type is validly derived, |
| 12446 | * a positive error code otherwise. |
| 12447 | */ |
| 12448 | static int |
| 12449 | xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12450 | xmlSchemaTypePtr type) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12451 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12452 | xmlChar *str = NULL; |
| 12453 | |
| 12454 | /* STATE: error funcs converted. */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12455 | |
| 12456 | if (type->type != XML_SCHEMA_TYPE_SIMPLE) { |
| 12457 | xmlSchemaPErr(ctxt, type->node, |
| 12458 | XML_ERR_INTERNAL_ERROR, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12459 | "xmlSchemaCheckDerivationValidSimpleRestriction: The given " |
| 12460 | "type '%s' is not a user-derived simpleType.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12461 | type->name, NULL); |
| 12462 | return (-1); |
| 12463 | } |
| 12464 | |
| 12465 | if (type->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) { |
| 12466 | xmlSchemaTypePtr primitive; |
| 12467 | /* |
| 12468 | * 1.1 The {base type definition} must be an atomic simple |
| 12469 | * type definition or a built-in primitive datatype. |
| 12470 | */ |
| 12471 | if ((type->baseType->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12472 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12473 | XML_SCHEMAP_COS_ST_RESTRICTS_1_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12474 | NULL, type, NULL, |
| 12475 | "The base type %s is not an atomic simple type", |
| 12476 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 12477 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12478 | return (XML_SCHEMAP_COS_ST_RESTRICTS_1_1); |
| 12479 | } |
| 12480 | /* 1.2 The {final} of the {base type definition} must not contain |
| 12481 | * restriction. |
| 12482 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12483 | /* OPTIMIZE TODO : This is already done in xmlSchemaCheckStPropsCorrect */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12484 | if (xmlSchemaTypeFinalContains(ctxt->schema, type->baseType, |
| 12485 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12486 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12487 | XML_SCHEMAP_COS_ST_RESTRICTS_1_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12488 | NULL, type, NULL, |
| 12489 | "The final of its base type %s must not contain 'restriction'", |
| 12490 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 12491 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12492 | return (XML_SCHEMAP_COS_ST_RESTRICTS_1_2); |
| 12493 | } |
| 12494 | |
| 12495 | /* |
| 12496 | * 1.3.1 DF must be an allowed constraining facet for the {primitive |
| 12497 | * type definition}, as specified in the appropriate subsection of 3.2 |
| 12498 | * Primitive datatypes. |
| 12499 | */ |
| 12500 | if (type->facets != NULL) { |
| 12501 | xmlSchemaFacetPtr facet; |
| 12502 | int ok = 1; |
| 12503 | |
| 12504 | primitive = xmlSchemaGetPrimitiveType(type); |
| 12505 | if (primitive == NULL) { |
| 12506 | xmlSchemaPErr(ctxt, type->node, |
| 12507 | XML_ERR_INTERNAL_ERROR, |
| 12508 | "xmlSchemaCheckDerivationValidSimpleRestriction: failed " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12509 | "to get primitive type of type '%s'.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12510 | type->name, NULL); |
| 12511 | return (-1); |
| 12512 | } |
| 12513 | facet = type->facets; |
| 12514 | do { |
| 12515 | if (xmlSchemaIsBuiltInTypeFacet(primitive, facet->type) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12516 | ok = 0; |
| 12517 | xmlSchemaPIllegalFacetAtomicErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12518 | XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12519 | NULL, type, primitive, facet); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12520 | } |
| 12521 | facet = facet->next; |
| 12522 | } while (facet != NULL); |
| 12523 | if (ok == 0) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12524 | return (XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12525 | } |
| 12526 | /* |
| 12527 | * TODO: 1.3.2 (facet derivation) |
| 12528 | */ |
| 12529 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 12530 | xmlSchemaTypePtr itemType = NULL; |
| 12531 | |
| 12532 | itemType = xmlSchemaGetListSimpleTypeItemType(type); |
| 12533 | if (itemType == NULL) { |
| 12534 | xmlSchemaPErr(ctxt, type->node, |
| 12535 | XML_ERR_INTERNAL_ERROR, |
| 12536 | "Internal error: xmlSchemaCheckDerivationValidSimpleRestriction: " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12537 | "failed to evaluate the item type of type '%s'.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12538 | type->name, NULL); |
| 12539 | return (-1); |
| 12540 | } |
| 12541 | /* |
| 12542 | * 2.1 The {item type definition} must have a {variety} of atomic or |
| 12543 | * union (in which case all the {member type definitions} |
| 12544 | * must be atomic). |
| 12545 | */ |
| 12546 | if (((itemType->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) == 0) && |
| 12547 | ((itemType->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) == 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12548 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12549 | XML_SCHEMAP_COS_ST_RESTRICTS_2_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12550 | NULL, type, NULL, |
| 12551 | "The item type %s must have a variety of atomic or union", |
| 12552 | xmlSchemaFormatItemForReport(&str, NULL, itemType, NULL, 1)); |
| 12553 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12554 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1); |
| 12555 | } else if (itemType->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
| 12556 | xmlSchemaTypeLinkPtr member; |
| 12557 | |
| 12558 | member = itemType->memberTypes; |
| 12559 | while (member != NULL) { |
| 12560 | if ((member->type->flags & |
| 12561 | XML_SCHEMAS_TYPE_VARIETY_ATOMIC) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12562 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12563 | XML_SCHEMAP_COS_ST_RESTRICTS_2_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12564 | NULL, type, NULL, |
| 12565 | "The item type is a union type, but the " |
| 12566 | "member type %s of this item type is not atomic", |
| 12567 | xmlSchemaFormatItemForReport(&str, NULL, member->type, NULL, 1)); |
| 12568 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12569 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1); |
| 12570 | } |
| 12571 | member = member->next; |
| 12572 | } |
| 12573 | } |
| 12574 | |
| 12575 | if (type->baseType == xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE)) { |
| 12576 | xmlSchemaFacetPtr facet; |
| 12577 | /* |
| 12578 | * This is the case if we have: <simpleType><list .. |
| 12579 | */ |
| 12580 | /* |
| 12581 | * 2.3.1 |
| 12582 | * 2.3.1.1 The {final} of the {item type definition} must not |
| 12583 | * contain list. |
| 12584 | */ |
| 12585 | if (xmlSchemaTypeFinalContains(ctxt->schema, |
| 12586 | itemType, XML_SCHEMAS_TYPE_FINAL_LIST)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12587 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12588 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12589 | NULL, type, NULL, |
| 12590 | "The final of its item type %s must not contain 'list'", |
| 12591 | xmlSchemaFormatItemForReport(&str, NULL, itemType, NULL, 1)); |
| 12592 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12593 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1); |
| 12594 | } |
| 12595 | /* |
| 12596 | * 2.3.1.2 The {facets} must only contain the whiteSpace |
| 12597 | * facet component. |
| 12598 | */ |
| 12599 | if (type->facets != NULL) { |
| 12600 | facet = type->facets; |
| 12601 | do { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12602 | if (facet->type != XML_SCHEMA_FACET_WHITESPACE) { |
| 12603 | xmlSchemaPIllegalFacetListUnionErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12604 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12605 | NULL, type, facet); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12606 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2); |
| 12607 | } |
| 12608 | facet = facet->next; |
| 12609 | } while (facet != NULL); |
| 12610 | } |
| 12611 | /* |
| 12612 | * TODO: Datatypes states: |
| 12613 | * A ·list· datatype can be ·derived· from an ·atomic· datatype |
| 12614 | * whose ·lexical space· allows space (such as string or anyURI)or |
| 12615 | * a ·union· datatype any of whose {member type definitions}'s |
| 12616 | * ·lexical space· allows space. |
| 12617 | */ |
| 12618 | } else { |
| 12619 | /* |
| 12620 | * This is the case if we have: <simpleType><restriction ... |
| 12621 | */ |
| 12622 | /* |
| 12623 | * 2.3.2 |
| 12624 | * 2.3.2.1 The {base type definition} must have a {variety} of list. |
| 12625 | */ |
| 12626 | if ((type->baseType->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12627 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12628 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12629 | NULL, type, NULL, |
| 12630 | "The base type %s must be a list type", |
| 12631 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 12632 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12633 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1); |
| 12634 | } |
| 12635 | /* |
| 12636 | * 2.3.2.2 The {final} of the {base type definition} must not |
| 12637 | * contain restriction. |
| 12638 | */ |
| 12639 | if (xmlSchemaTypeFinalContains(ctxt->schema, type->baseType, |
| 12640 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12641 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12642 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12643 | NULL, type, NULL, |
| 12644 | "The final of the base type %s must not contain 'restriction'", |
| 12645 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 12646 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12647 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2); |
| 12648 | } |
| 12649 | /* |
| 12650 | * 2.3.2.3 The {item type definition} must be validly derived |
| 12651 | * from the {base type definition}'s {item type definition} given |
| 12652 | * the empty set, as defined in Type Derivation OK (Simple) (§3.14.6). |
| 12653 | */ |
| 12654 | { |
| 12655 | xmlSchemaTypePtr baseItemType; |
| 12656 | |
| 12657 | baseItemType = xmlSchemaGetListSimpleTypeItemType(type->baseType); |
| 12658 | if (baseItemType == NULL) { |
| 12659 | xmlSchemaPErr(ctxt, type->node, |
| 12660 | XML_ERR_INTERNAL_ERROR, |
| 12661 | "xmlSchemaCheckDerivationValidSimpleRestriction: " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12662 | "List simple type '%s': Failed to " |
| 12663 | "evaluate the item type of its base type '%s'.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12664 | type->name, type->baseType->name); |
| 12665 | return (-1); |
| 12666 | } |
| 12667 | if ((itemType != baseItemType) && |
| 12668 | (xmlSchemaCheckCOSSTDerivedOK(ctxt->schema, itemType, |
| 12669 | baseItemType, 0) != 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12670 | xmlChar *strBIT = NULL, *strBT = NULL; |
| 12671 | xmlSchemaPCustomErrExt(ctxt, |
| 12672 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3, |
| 12673 | NULL, type, NULL, |
| 12674 | "The item type %s is not validly derived from the " |
| 12675 | "item type %s of the base type %s", |
| 12676 | xmlSchemaFormatItemForReport(&str, NULL, itemType, NULL, 1), |
| 12677 | xmlSchemaFormatItemForReport(&strBIT, NULL, baseItemType, NULL, 1), |
| 12678 | xmlSchemaFormatItemForReport(&strBT, NULL, type->baseType, NULL, 1)); |
| 12679 | |
| 12680 | FREE_AND_NULL(str) |
| 12681 | FREE_AND_NULL(strBIT) |
| 12682 | FREE_AND_NULL(strBT) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12683 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3); |
| 12684 | } |
| 12685 | } |
| 12686 | |
| 12687 | if (type->facets != NULL) { |
| 12688 | xmlSchemaFacetPtr facet; |
| 12689 | int ok = 1; |
| 12690 | /* |
| 12691 | * 2.3.2.4 Only length, minLength, maxLength, whiteSpace, pattern |
| 12692 | * and enumeration facet components are allowed among the {facets}. |
| 12693 | */ |
| 12694 | facet = type->facets; |
| 12695 | do { |
| 12696 | switch (facet->type) { |
| 12697 | case XML_SCHEMA_FACET_LENGTH: |
| 12698 | case XML_SCHEMA_FACET_MINLENGTH: |
| 12699 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 12700 | case XML_SCHEMA_FACET_WHITESPACE: |
| 12701 | /* |
| 12702 | * TODO: 2.5.1.2 List datatypes |
| 12703 | * The value of ·whiteSpace· is fixed to the value collapse. |
| 12704 | */ |
| 12705 | case XML_SCHEMA_FACET_PATTERN: |
| 12706 | case XML_SCHEMA_FACET_ENUMERATION: |
| 12707 | break; |
| 12708 | default: { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12709 | xmlSchemaPIllegalFacetListUnionErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12710 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12711 | NULL, type, facet); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12712 | /* |
| 12713 | * We could return, but it's nicer to report all |
| 12714 | * invalid facets. |
| 12715 | */ |
| 12716 | ok = 0; |
| 12717 | } |
| 12718 | } |
| 12719 | facet = facet->next; |
| 12720 | } while (facet != NULL); |
| 12721 | if (ok == 0) |
| 12722 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4); |
| 12723 | /* |
| 12724 | * TODO: 2.3.2.5 For each facet in the {facets} (call this DF), if there |
| 12725 | * is a facet of the same kind in the {facets} of the {base type |
| 12726 | * definition} (call this BF),then the DF's {value} must be a valid |
| 12727 | * restriction of BF's {value} as defined in [XML Schemas: Datatypes]. |
| 12728 | */ |
| 12729 | } |
| 12730 | |
| 12731 | |
| 12732 | } |
| 12733 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
| 12734 | /* |
| 12735 | * 3.1 The {member type definitions} must all have {variety} of |
| 12736 | * atomic or list. |
| 12737 | */ |
| 12738 | xmlSchemaTypeLinkPtr member; |
| 12739 | |
| 12740 | member = type->memberTypes; |
| 12741 | while (member != NULL) { |
| 12742 | if (((member->type->flags & |
| 12743 | XML_SCHEMAS_TYPE_VARIETY_ATOMIC) == 0) && |
| 12744 | ((member->type->flags & |
| 12745 | XML_SCHEMAS_TYPE_VARIETY_LIST) == 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12746 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12747 | XML_SCHEMAP_COS_ST_RESTRICTS_3_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12748 | NULL, type, NULL, |
| 12749 | "The member type %s is neither an atomic, nor a list type", |
| 12750 | xmlSchemaFormatItemForReport(&str, NULL, member->type, NULL, 1)); |
| 12751 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12752 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_1); |
| 12753 | } |
| 12754 | member = member->next; |
| 12755 | } |
| 12756 | /* |
| 12757 | * 3.3.1 If the {base type definition} is the ·simple ur-type |
| 12758 | * definition· |
| 12759 | */ |
| 12760 | if (type->baseType == xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE)) { |
| 12761 | /* |
| 12762 | * 3.3.1.1 All of the {member type definitions} must have a |
| 12763 | * {final} which does not contain union. |
| 12764 | */ |
| 12765 | member = type->memberTypes; |
| 12766 | while (member != NULL) { |
| 12767 | if (xmlSchemaTypeFinalContains(ctxt->schema, member->type, |
| 12768 | XML_SCHEMAS_TYPE_FINAL_UNION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12769 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12770 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12771 | NULL, type, NULL, |
| 12772 | "The final of member type %s contains 'union'", |
| 12773 | xmlSchemaFormatItemForReport(&str, NULL, member->type, NULL, 1)); |
| 12774 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12775 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1); |
| 12776 | } |
| 12777 | member = member->next; |
| 12778 | } |
| 12779 | /* |
| 12780 | * 3.3.1.2 The {facets} must be empty. |
| 12781 | */ |
| 12782 | if (type->facetSet != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12783 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12784 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12785 | NULL, type, NULL, |
| 12786 | "No facets allowed", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12787 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2); |
| 12788 | } |
| 12789 | } else { |
| 12790 | /* |
| 12791 | * 3.3.2.1 The {base type definition} must have a {variety} of union. |
| 12792 | */ |
| 12793 | if ((type->baseType->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12794 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12795 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12796 | NULL, type, NULL, |
| 12797 | "The base type %s is not a union type", |
| 12798 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 12799 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12800 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1); |
| 12801 | } |
| 12802 | /* |
| 12803 | * 3.3.2.2 The {final} of the {base type definition} must not contain restriction. |
| 12804 | */ |
| 12805 | if (xmlSchemaTypeFinalContains(ctxt->schema, type->baseType, |
| 12806 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12807 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12808 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12809 | NULL, type, NULL, |
| 12810 | "The final of its base type %s must not contain 'restriction'", |
| 12811 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 12812 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12813 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2); |
| 12814 | } |
| 12815 | /* |
| 12816 | * 3.3.2.3 The {member type definitions}, in order, must be validly |
| 12817 | * derived from the corresponding type definitions in the {base |
| 12818 | * type definition}'s {member type definitions} given the empty set, |
| 12819 | * as defined in Type Derivation OK (Simple) (§3.14.6). |
| 12820 | */ |
| 12821 | { |
| 12822 | xmlSchemaTypeLinkPtr baseMember; |
| 12823 | |
| 12824 | /* |
| 12825 | * OPTIMIZE: if the type is restricting, it has no local defined |
| 12826 | * member types and inherits the member types of the base type; |
| 12827 | * thus a check for equality can be skipped. |
| 12828 | */ |
| 12829 | /* |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 12830 | * Even worse: I cannot see a scenario where a restricting |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12831 | * union simple type can have other member types as the member |
| 12832 | * types of it's base type. This check seems not necessary with |
| 12833 | * respect to the derivation process in libxml2. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 12834 | * But necessary if constructing types with an API. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12835 | */ |
| 12836 | if (type->memberTypes != NULL) { |
| 12837 | member = type->memberTypes; |
| 12838 | baseMember = xmlSchemaGetUnionSimpleTypeMemberTypes(type->baseType); |
| 12839 | if ((member == NULL) && (baseMember != NULL)) { |
| 12840 | xmlSchemaPErr(ctxt, type->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 12841 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12842 | "Internal error: " |
| 12843 | "xmlSchemaCheckDerivationValidSimpleRestriction " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12844 | "(3.3.2.3), union simple type '%s', unequal number " |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12845 | "of member types in the base type\n", |
| 12846 | type->name, NULL); |
| 12847 | } |
| 12848 | while (member != NULL) { |
| 12849 | if (baseMember == NULL) { |
| 12850 | xmlSchemaPErr(ctxt, type->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 12851 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12852 | "Internal error: " |
| 12853 | "xmlSchemaCheckDerivationValidSimpleRestriction " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12854 | "(3.3.2.3), union simple type '%s', unequal number " |
| 12855 | "of member types in the base type.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12856 | type->name, NULL); |
| 12857 | } |
| 12858 | if ((member->type != baseMember->type) && |
| 12859 | (xmlSchemaCheckCOSSTDerivedOK(ctxt->schema, |
| 12860 | member->type, baseMember->type, 0) != 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12861 | xmlChar *strBMT = NULL, *strBT = NULL; |
| 12862 | |
| 12863 | xmlSchemaPCustomErrExt(ctxt, |
| 12864 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3, |
| 12865 | NULL, type, NULL, |
| 12866 | "The member type %s is not validly derived from its " |
| 12867 | "corresponding member type %s of the base type %s", |
| 12868 | xmlSchemaFormatItemForReport(&str, NULL, member->type, NULL, 1), |
| 12869 | xmlSchemaFormatItemForReport(&strBMT, NULL, baseMember->type, NULL, 1), |
| 12870 | xmlSchemaFormatItemForReport(&strBT, NULL, type->baseType, NULL, 1)); |
| 12871 | FREE_AND_NULL(str) |
| 12872 | FREE_AND_NULL(strBMT) |
| 12873 | FREE_AND_NULL(strBT) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12874 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3); |
| 12875 | } |
| 12876 | member = member->next; |
| 12877 | baseMember = baseMember->next; |
| 12878 | } |
| 12879 | } |
| 12880 | } |
| 12881 | /* |
| 12882 | * 3.3.2.4 Only pattern and enumeration facet components are |
| 12883 | * allowed among the {facets}. |
| 12884 | */ |
| 12885 | if (type->facets != NULL) { |
| 12886 | xmlSchemaFacetPtr facet; |
| 12887 | int ok = 1; |
| 12888 | |
| 12889 | facet = type->facets; |
| 12890 | do { |
| 12891 | if ((facet->type != XML_SCHEMA_FACET_PATTERN) && |
| 12892 | (facet->type != XML_SCHEMA_FACET_ENUMERATION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12893 | xmlSchemaPIllegalFacetListUnionErr(ctxt, |
| 12894 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4, |
| 12895 | NULL, type, facet); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12896 | ok = 0; |
| 12897 | } |
| 12898 | facet = facet->next; |
| 12899 | } while (facet != NULL); |
| 12900 | if (ok == 0) |
| 12901 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4); |
| 12902 | |
| 12903 | } |
| 12904 | /* |
| 12905 | * TODO: 3.3.2.5 (facet derivation) |
| 12906 | */ |
| 12907 | } |
| 12908 | } |
| 12909 | |
| 12910 | return (0); |
| 12911 | } |
| 12912 | |
| 12913 | /** |
| 12914 | * xmlSchemaCheckSRCSimpleType: |
| 12915 | * @ctxt: the schema parser context |
| 12916 | * @type: the simple type definition |
| 12917 | * |
| 12918 | * Checks crc-simple-type constraints. |
| 12919 | * |
| 12920 | * Returns 0 if the constraints are satisfied, |
| 12921 | * if not a positive error code and -1 on internal |
| 12922 | * errors. |
| 12923 | */ |
| 12924 | static int |
| 12925 | xmlSchemaCheckSRCSimpleType(xmlSchemaParserCtxtPtr ctxt, |
| 12926 | xmlSchemaTypePtr type) |
| 12927 | { |
| 12928 | /* |
| 12929 | * NOTE: src-simple-type 2-4 are redundant, since the checks |
| 12930 | * were are done for the corresponding <restriction>, <list> and <union> |
| 12931 | * elements, but W3C wants a <simpleType> error as well, so it gets one. |
| 12932 | * Maby this can be skipped in the future, if we get sure it's not needed. |
| 12933 | */ |
| 12934 | if (type->subtypes == NULL) { |
| 12935 | xmlSchemaPErr(ctxt, type->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 12936 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12937 | "Internal error: xmlSchemaCheckSRCSimpleType, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12938 | "no subtype on simple type '%s'.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12939 | type->name, NULL); |
| 12940 | return (-1); |
| 12941 | } |
| 12942 | /* |
| 12943 | * src-simple-type.1 The corresponding simple type definition, if any, |
| 12944 | * must satisfy the conditions set out in Constraints on Simple Type |
| 12945 | * Definition Schema Components (§3.14.6). |
| 12946 | */ |
| 12947 | if ((xmlSchemaCheckSTPropsCorrect(ctxt, type) != 0) || |
| 12948 | (xmlSchemaCheckCOSSTRestricts(ctxt, type) != 0)) { |
| 12949 | /* |
| 12950 | * TODO: Removed this, since it got annoying to get an |
| 12951 | * extra error report, if anything failed until now. |
| 12952 | * Enable this if needed. |
| 12953 | */ |
| 12954 | /* |
| 12955 | xmlSchemaPErr(ctxt, type->node, |
| 12956 | XML_SCHEMAP_SRC_SIMPLE_TYPE_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12957 | "Simple type '%s' does not satisfy the constraints " |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12958 | "on simple type definitions.\n", |
| 12959 | type->name, NULL); |
| 12960 | */ |
| 12961 | return (XML_SCHEMAP_SRC_SIMPLE_TYPE_1); |
| 12962 | } |
| 12963 | |
| 12964 | if (type->subtypes->type == XML_SCHEMA_TYPE_RESTRICTION) { |
| 12965 | /* |
| 12966 | * src-simple-type.2 If the <restriction> alternative is chosen, |
| 12967 | * either it must have a base [attribute] or a <simpleType> among its |
| 12968 | * [children], but not both. |
| 12969 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12970 | /* |
| 12971 | * XML_SCHEMAP_SRC_SIMPLE_TYPE_2 |
| 12972 | * NOTE: This was removed, since this will be already handled |
| 12973 | * in the parse function for <restriction>. |
| 12974 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12975 | } else if (type->subtypes->type == XML_SCHEMA_TYPE_LIST) { |
| 12976 | /* src-simple-type.3 If the <list> alternative is chosen, either it must have |
| 12977 | * an itemType [attribute] or a <simpleType> among its [children], |
| 12978 | * but not both. |
| 12979 | * NOTE: baseType is set to the local simple type definiton, |
| 12980 | * if existent, at parse time. This is a hack and not nice. |
| 12981 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12982 | /* |
| 12983 | * TODO: Remove this, and add the check to the parse function of <list>. |
| 12984 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12985 | if (((type->subtypes->base == NULL) && |
| 12986 | (type->baseType == NULL)) || |
| 12987 | ((type->subtypes->base != NULL) && |
| 12988 | (type->subtypes->baseType != NULL))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12989 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12990 | XML_SCHEMAP_SRC_SIMPLE_TYPE_3, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12991 | NULL, type, NULL, |
| 12992 | "Either the attribute 'itemType' or the <simpleType> child " |
| 12993 | "must be present on the <list> child ", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12994 | return (XML_SCHEMAP_SRC_SIMPLE_TYPE_3); |
| 12995 | } |
| 12996 | |
| 12997 | |
| 12998 | } else if (type->subtypes->type == XML_SCHEMA_TYPE_UNION) { |
| 12999 | xmlSchemaTypeLinkPtr member; |
| 13000 | xmlSchemaTypePtr ancestor, anySimpleType; |
| 13001 | |
| 13002 | anySimpleType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 13003 | |
| 13004 | /* src-simple-type.4 Circular union type definition is disallowed. That is, if |
| 13005 | * the <union> alternative is chosen, there must not be any entries |
| 13006 | * in the memberTypes [attribute] at any depth which resolve to the |
| 13007 | * component corresponding to the <simpleType>. |
| 13008 | */ |
| 13009 | member = type->memberTypes; |
| 13010 | while (member != NULL) { |
| 13011 | ancestor = member->type; |
| 13012 | while ((ancestor != NULL) && (ancestor->type != XML_SCHEMA_TYPE_BASIC)) { |
| 13013 | if (ancestor->contentType == XML_SCHEMA_CONTENT_UNKNOWN) |
| 13014 | xmlSchemaTypeFixup(ancestor, ctxt, NULL); |
| 13015 | if (ancestor == anySimpleType) |
| 13016 | break; |
| 13017 | else if (ancestor == type) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13018 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13019 | XML_SCHEMAP_SRC_SIMPLE_TYPE_4, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13020 | NULL, type, NULL, |
| 13021 | "The definition is circular", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13022 | return (XML_SCHEMAP_SRC_SIMPLE_TYPE_4); |
| 13023 | } else if (ancestor->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 13024 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13025 | * TODO, FIXME: Although a list simple type must not have a union ST |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13026 | * type as item type, which in turn has a list ST as member |
| 13027 | * type, we will assume this here as well, since this check |
| 13028 | * was not yet performed. |
| 13029 | */ |
| 13030 | |
| 13031 | } |
| 13032 | ancestor = ancestor->baseType; |
| 13033 | } |
| 13034 | member = member->next; |
| 13035 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13036 | } |
| 13037 | |
| 13038 | return (0); |
| 13039 | } |
| 13040 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13041 | #if 0 /* Not yet used code for CT schema validation */ |
| 13042 | static int |
| 13043 | xmlSchemaCheckCVCSimpleType(xmlSchemaValidCtxtPtr ctxt, |
| 13044 | const xmlChar * value, |
| 13045 | xmlSchemaTypePtr type, |
| 13046 | int fireErrors) |
| 13047 | { |
| 13048 | int ret; |
| 13049 | /* |
| 13050 | * 3.14.4 Simple Type Definition Validation Rules |
| 13051 | * Validation Rule: String Valid |
| 13052 | */ |
| 13053 | /* |
| 13054 | * 1 It is schema-valid with respect to that definition as defined |
| 13055 | * by Datatype Valid in [XML Schemas: Datatypes]. |
| 13056 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13057 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, type, value, |
| 13058 | fireErrors, 1, 1, 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13059 | return (ret); |
| 13060 | /* |
| 13061 | * 2.1 If The definition is ENTITY or is validly derived from ENTITY given |
| 13062 | * the empty set, as defined in Type Derivation OK (Simple) (§3.14.6), then |
| 13063 | * the string must be a ·declared entity name·. |
| 13064 | */ |
| 13065 | /* |
| 13066 | * 2.2 If The definition is ENTITIES or is validly derived from ENTITIES |
| 13067 | * given the empty set, as defined in Type Derivation OK (Simple) (§3.14.6), |
| 13068 | * then every whitespace-delimited substring of the string must be a ·declared |
| 13069 | * entity name·. |
| 13070 | */ |
| 13071 | /* |
| 13072 | * 2.3 otherwise no further condition applies. |
| 13073 | */ |
| 13074 | |
| 13075 | return (0); |
| 13076 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13077 | #endif |
| 13078 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13079 | |
| 13080 | static int |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13081 | xmlSchemaCreatePCtxtOnVCtxt(xmlSchemaValidCtxtPtr vctxt) |
| 13082 | { |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 13083 | if (vctxt->pctxt == NULL) { |
| 13084 | if (vctxt->schema != NULL) |
| 13085 | vctxt->pctxt = xmlSchemaNewParserCtxtUseDict("*", vctxt->schema->dict); |
| 13086 | else |
| 13087 | vctxt->pctxt = xmlSchemaNewParserCtxt("*"); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13088 | if (vctxt->pctxt == NULL) { |
| 13089 | xmlSchemaVErr(vctxt, NULL, |
| 13090 | XML_SCHEMAV_INTERNAL, |
| 13091 | "Internal error: xmlSchemaCreatePCtxtOnVCtxt, " |
| 13092 | "failed to create a temp. parser context.\n", |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13093 | NULL, NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13094 | return (-1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13095 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13096 | /* TODO: Pass user data. */ |
| 13097 | xmlSchemaSetParserErrors(vctxt->pctxt, vctxt->error, vctxt->warning, NULL); |
| 13098 | } |
| 13099 | return (0); |
| 13100 | } |
| 13101 | |
| 13102 | static int |
| 13103 | xmlSchemaCreateVCtxtOnPCtxt(xmlSchemaParserCtxtPtr ctxt) |
| 13104 | { |
| 13105 | if (ctxt->vctxt == NULL) { |
| 13106 | ctxt->vctxt = xmlSchemaNewValidCtxt(NULL); |
| 13107 | if (ctxt->vctxt == NULL) { |
| 13108 | xmlSchemaPErr(ctxt, NULL, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 13109 | XML_SCHEMAP_INTERNAL, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13110 | "Internal error: xmlSchemaCreatePCtxtOnVCtxt, " |
| 13111 | "failed to create a temp. validation context.\n", |
| 13112 | NULL, NULL); |
| 13113 | return (-1); |
| 13114 | } |
| 13115 | /* TODO: Pass user data. */ |
| 13116 | xmlSchemaSetValidErrors(ctxt->vctxt, ctxt->error, ctxt->warning, NULL); |
| 13117 | } |
| 13118 | return (0); |
| 13119 | } |
| 13120 | |
| 13121 | /** |
| 13122 | * xmlSchemaCheckCOSValidDefault: |
| 13123 | * @ctxt: the schema parser context |
| 13124 | * @type: the simple type definition |
| 13125 | * @value: the default value |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 13126 | * @val: the precomputed value to be returned |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13127 | * @node: an optional node (the holder of the value) |
| 13128 | * |
| 13129 | * Checks the "cos-valid-default" constraints. |
| 13130 | * |
| 13131 | * Returns 0 if the constraints are satisfied, |
| 13132 | * if not, a positive error code and -1 on internal |
| 13133 | * errors. |
| 13134 | */ |
| 13135 | static int |
| 13136 | xmlSchemaCheckCOSValidDefault(xmlSchemaParserCtxtPtr pctxt, |
| 13137 | xmlSchemaValidCtxtPtr vctxt, |
| 13138 | xmlSchemaTypePtr type, |
| 13139 | const xmlChar *value, |
| 13140 | xmlNodePtr node) |
| 13141 | { |
| 13142 | int ret = 0; |
| 13143 | |
| 13144 | /* |
| 13145 | * cos-valid-default: |
| 13146 | * Schema Component Constraint: Element Default Valid (Immediate) |
| 13147 | * For a string to be a valid default with respect to a type |
| 13148 | * definition the appropriate case among the following must be true: |
| 13149 | */ |
| 13150 | /* |
| 13151 | * NOTE: This has to work without a given node (the holder of the |
| 13152 | * value), since it should work on the component, i.e. an underlying |
| 13153 | * DOM must not be mandatory. |
| 13154 | */ |
| 13155 | if ((pctxt == NULL) || (vctxt == NULL)) { |
| 13156 | xmlSchemaPErr(pctxt, node, |
| 13157 | XML_SCHEMAP_INTERNAL, |
| 13158 | "Internal error: xmlSchemaCheckCOSValidDefault, " |
| 13159 | "bad arguments: the parser and/or validation context is " |
| 13160 | "missing.\n", |
| 13161 | NULL, NULL); |
| 13162 | return (-1); |
| 13163 | } |
| 13164 | if IS_COMPLEX_TYPE(type) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13165 | /* |
| 13166 | * Complex type. |
| 13167 | * |
| 13168 | * 2.1 its {content type} must be a simple type definition or mixed. |
| 13169 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13170 | /* |
| 13171 | * TODO: Adjust this when the content type will be computed |
| 13172 | * correctly. |
| 13173 | */ |
| 13174 | if ((type->contentType != XML_SCHEMA_CONTENT_SIMPLE) && |
| 13175 | (type->contentType != XML_SCHEMA_CONTENT_BASIC) && |
| 13176 | (type->contentType != XML_SCHEMA_CONTENT_MIXED)) { |
| 13177 | xmlSchemaPSimpleTypeErr(pctxt, |
| 13178 | XML_SCHEMAP_COS_VALID_DEFAULT_2_1, |
| 13179 | NULL, NULL, node, |
| 13180 | type, NULL, NULL, |
| 13181 | "If the type of a constraint value is complex, its content " |
| 13182 | "type must be mixed or a simple type", |
| 13183 | NULL, NULL); |
| 13184 | return(XML_SCHEMAP_COS_VALID_DEFAULT_2_1); |
| 13185 | } |
| 13186 | if (type->contentType == XML_SCHEMA_CONTENT_MIXED) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13187 | /* |
| 13188 | * 2.2.2 If the {content type} is mixed, then the {content type}'s |
| 13189 | * particle must be ·emptiable· as defined by Particle Emptiable |
| 13190 | * (§3.9.6). |
| 13191 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13192 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13193 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13194 | * URGENT TODO: Implement this. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13195 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13196 | return (0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13197 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13198 | } |
| 13199 | /* |
| 13200 | * 1 If the type definition is a simple type definition, then the string |
| 13201 | * must be ·valid· with respect to that definition as defined by String |
| 13202 | * Valid (§3.14.4). |
| 13203 | * |
| 13204 | * AND |
| 13205 | * |
| 13206 | * 2.2.1 If the {content type} is a simple type definition, then the |
| 13207 | * string must be ·valid· with respect to that simple type definition |
| 13208 | * as defined by String Valid (§3.14.4). |
| 13209 | */ |
| 13210 | vctxt->node = node; |
| 13211 | vctxt->cur = NULL; |
| 13212 | ret = xmlSchemaValidateSimpleTypeValue(vctxt, type, value, 1, 1, 1, 0); |
| 13213 | /* ret = xmlSchemaCheckCVCSimpleType(vctxt, elemDecl->value, typeDef, 0); */ |
| 13214 | if (ret < 0) { |
| 13215 | xmlSchemaPErr(pctxt, node, |
| 13216 | /* NOTNICE: error code: This function will be used during |
| 13217 | * schema construction and xsi:type validation. |
| 13218 | */ |
| 13219 | XML_SCHEMAP_INTERNAL, |
| 13220 | "Internal error: xmlSchemaCheckCOSValidDefault, " |
| 13221 | "while validating a value constaint value.\n", |
| 13222 | NULL, NULL); |
| 13223 | |
| 13224 | } |
| 13225 | return (ret); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13226 | } |
| 13227 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13228 | #if 0 /* Not yet used code for CT schema validation */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13229 | /** |
| 13230 | * xmlSchemaGetSTContentOfCT: |
| 13231 | * @ctxt: the schema parser context |
| 13232 | * @type: the complex type definition |
| 13233 | * |
| 13234 | * |
| 13235 | * Returns the corresponding simple type for the content of |
| 13236 | * the complex type. |
| 13237 | */ |
| 13238 | static xmlSchemaTypePtr |
| 13239 | xmlSchemaGetSTContentOfCT(xmlSchemaParserCtxtPtr ctxt, |
| 13240 | xmlSchemaTypePtr type) |
| 13241 | { |
| 13242 | xmlSchemaTypePtr orig = type, anyType; |
| 13243 | |
| 13244 | anyType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 13245 | while ((type != NULL) && (type != anyType) && |
| 13246 | (type->type == XML_SCHEMA_TYPE_COMPLEX)) { |
| 13247 | if (type->type == XML_SCHEMA_TYPE_SIMPLE) |
| 13248 | return(type); |
| 13249 | type = type->baseType; |
| 13250 | } |
| 13251 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 13252 | XML_SCHEMAP_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13253 | NULL, orig, NULL, |
| 13254 | "Internal error: xmlSchemaGetSTContentTypeOfCT, " |
| 13255 | "no simple type for the content of complex type '%s' could be " |
| 13256 | "computed", orig->name); |
| 13257 | return (NULL); |
| 13258 | } |
| 13259 | |
| 13260 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13261 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13262 | |
| 13263 | /** |
| 13264 | * xmlSchemaCheckCOSCTExtends: |
| 13265 | * @ctxt: the schema parser context |
| 13266 | * @type: the complex type definition |
| 13267 | * |
| 13268 | * Schema Component Constraint: Derivation Valid (Extension) |
| 13269 | * |
| 13270 | * Returns 0 if the constraints are satisfied, a positive |
| 13271 | * error code if not and -1 if an internal error occured. |
| 13272 | */ |
| 13273 | static int |
| 13274 | xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt, |
| 13275 | xmlSchemaTypePtr type) |
| 13276 | { |
| 13277 | xmlSchemaTypePtr base; |
| 13278 | /* |
| 13279 | * 1 If the {base type definition} is a complex type definition, |
| 13280 | * then all of the following must be true: |
| 13281 | */ |
| 13282 | base = type->baseType; |
| 13283 | if (base == NULL) { |
| 13284 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 13285 | XML_SCHEMAP_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13286 | NULL, type, NULL, |
| 13287 | "Internal error: xmlSchemaCheckCOSCTExtends, " |
| 13288 | "the complex type '%s' has no base type", type->name); |
| 13289 | return (-1); |
| 13290 | } |
| 13291 | if (base->type == XML_SCHEMA_TYPE_COMPLEX) { |
| 13292 | /* |
| 13293 | * 1.1 The {final} of the {base type definition} must not |
| 13294 | * contain extension. |
| 13295 | */ |
| 13296 | if (base->flags & XML_SCHEMAS_TYPE_FINAL_EXTENSION) { |
| 13297 | xmlSchemaPCustomErr(ctxt, |
| 13298 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
| 13299 | NULL, type, NULL, |
| 13300 | "The 'final' of the base type definition " |
| 13301 | "contains extension", NULL); |
| 13302 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
| 13303 | } |
| 13304 | /* |
| 13305 | * 1.2 Its {attribute uses} must be a subset of the {attribute uses} |
| 13306 | * of the complex type definition itself, that is, for every attribute |
| 13307 | * use in the {attribute uses} of the {base type definition}, there |
| 13308 | * must be an attribute use in the {attribute uses} of the complex |
| 13309 | * type definition itself whose {attribute declaration} has the same |
| 13310 | * {name}, {target namespace} and {type definition} as its attribute |
| 13311 | * declaration |
| 13312 | * |
| 13313 | * NOTE: This will be already satisfied by the way the attribute uses |
| 13314 | * are extended in xmlSchemaBuildAttributeValidation; thus this check |
| 13315 | * is not needed. |
| 13316 | */ |
| 13317 | |
| 13318 | /* |
| 13319 | * 1.3 If it has an {attribute wildcard}, the complex type definition |
| 13320 | * must also have one, and the base type definition's {attribute |
| 13321 | * wildcard}'s {namespace constraint} must be a subset of the complex |
| 13322 | * type definition's {attribute wildcard}'s {namespace constraint}, |
| 13323 | * as defined by Wildcard Subset (§3.10.6). |
| 13324 | * |
| 13325 | * This is already checked in xmlSchemaBuildAttributeValidation; thus |
| 13326 | * this check is not needed. |
| 13327 | */ |
| 13328 | |
| 13329 | /* |
| 13330 | * 1.4 One of the following must be true: |
| 13331 | * |
| 13332 | * 1.4.1 The {content type} of the {base type definition} and the |
| 13333 | * {content type} of the complex type definition itself must be the same |
| 13334 | * simple type definition |
| 13335 | */ |
| 13336 | |
| 13337 | |
| 13338 | |
| 13339 | } else { |
| 13340 | /* |
| 13341 | * 2 If the {base type definition} is a simple type definition, |
| 13342 | * then all of the following must be true: |
| 13343 | */ |
| 13344 | /* |
| 13345 | * 2.1 The {content type} must be the same simple type definition. |
| 13346 | */ |
| 13347 | /* |
| 13348 | * 2.2 The {final} of the {base type definition} must not contain |
| 13349 | * extension |
| 13350 | */ |
| 13351 | } |
| 13352 | |
| 13353 | } |
| 13354 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13355 | static int |
| 13356 | xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt, |
| 13357 | xmlSchemaTypePtr type) |
| 13358 | { |
| 13359 | xmlSchemaTypePtr base, content; |
| 13360 | int OK = 0; |
| 13361 | |
| 13362 | /* |
| 13363 | * TODO: Adjust the error codes here, as I used |
| 13364 | * XML_SCHEMAP_SRC_CT_1 only yet. |
| 13365 | */ |
| 13366 | /* |
| 13367 | * Schema Representation Constraint: |
| 13368 | * Complex Type Definition Representation OK |
| 13369 | */ |
| 13370 | base = type->baseType; |
| 13371 | if (base == NULL) { |
| 13372 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, NULL, type, NULL, |
| 13373 | "Internal error: xmlSchemaCheckSRCCT, '%s', no base type", |
| 13374 | type->name); |
| 13375 | return (-1); |
| 13376 | } |
| 13377 | |
| 13378 | if (type->subtypes != NULL) { |
| 13379 | if (type->subtypes->type == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
| 13380 | if IS_COMPLEX_TYPE(base) { |
| 13381 | /* |
| 13382 | * 1 If the <complexContent> alternative is chosen, the type definition |
| 13383 | * ·resolved· to by the ·actual value· of the base [attribute] |
| 13384 | * must be a complex type definition; |
| 13385 | */ |
| 13386 | xmlSchemaPCustomErr(ctxt, |
| 13387 | XML_SCHEMAP_SRC_CT_1, |
| 13388 | NULL, type, NULL, |
| 13389 | "The base type is not a complex type", NULL); |
| 13390 | return (XML_SCHEMAP_SRC_CT_1); |
| 13391 | } |
| 13392 | } else if (type->subtypes->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT) { |
| 13393 | |
| 13394 | if IS_SIMPLE_TYPE(base) { |
| 13395 | if (type->flags & |
| 13396 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
| 13397 | /* |
| 13398 | * 2.1.3 only if the <extension> alternative is also |
| 13399 | * chosen, a simple type definition. |
| 13400 | */ |
| 13401 | /* TODO: Change error code to ..._SRC_CT_2_1_3. */ |
| 13402 | xmlSchemaPCustomErr(ctxt, |
| 13403 | XML_SCHEMAP_SRC_CT_1, |
| 13404 | NULL, type, NULL, |
| 13405 | "A complex type (simple content) cannot restrict " |
| 13406 | "an other simple type", |
| 13407 | NULL); |
| 13408 | return (XML_SCHEMAP_SRC_CT_1); |
| 13409 | } |
| 13410 | OK = 1; |
| 13411 | |
| 13412 | } else { /* if IS_SIMPLE_TYPE(base) */ |
Daniel Veillard | bc69d4f | 2005-03-17 10:04:46 +0000 | [diff] [blame] | 13413 | if (base->contentType == XML_SCHEMA_CONTENT_MIXED) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13414 | /* |
| 13415 | * 2.1.2 only if the <restriction> alternative is also |
| 13416 | * chosen, a complex type definition whose {content type} |
| 13417 | * is mixed and a particle emptyable. |
| 13418 | */ |
| 13419 | /* |
| 13420 | * FIXME TODO: Check for *empiable particle* is missing. |
| 13421 | */ |
| 13422 | if ((type->flags & |
| 13423 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) == 0) { |
| 13424 | xmlSchemaPCustomErr(ctxt, |
| 13425 | XML_SCHEMAP_SRC_CT_1, |
| 13426 | NULL, type, NULL, |
| 13427 | "A complex type (simple content) cannot " |
| 13428 | "extend an other complex type which has a " |
| 13429 | "content type of: 'mixed' and emptiable particle", |
| 13430 | NULL); |
| 13431 | return (XML_SCHEMAP_SRC_CT_1); |
| 13432 | } |
| 13433 | /* |
| 13434 | * NOTE: This will be fired as well, if the base type |
| 13435 | * is *'anyType'*. |
| 13436 | * NOTE: type->subtypes->subtypes will be the |
| 13437 | * <restriction> item. |
| 13438 | */ |
| 13439 | if (type->subtypes->subtypes == NULL) { |
| 13440 | /* Yes, this is paranoid programming. */ |
| 13441 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, |
| 13442 | NULL, type, NULL, |
| 13443 | "Internal error: xmlSchemaCheckSRCCT, " |
| 13444 | "'%s', <simpleContent> has no <restriction>", |
| 13445 | type->name); |
| 13446 | return (-1); |
| 13447 | } |
| 13448 | /* |
| 13449 | * 2.2 If clause 2.1.2 above is satisfied, then there |
| 13450 | * must be a <simpleType> among the [children] of |
| 13451 | * <restriction>. |
| 13452 | */ |
| 13453 | if (type->subtypes->subtypes->type != |
| 13454 | XML_SCHEMA_TYPE_SIMPLE) { |
| 13455 | /* TODO: Change error code to ..._SRC_CT_2_2. */ |
| 13456 | xmlSchemaPCustomErr(ctxt, |
| 13457 | XML_SCHEMAP_SRC_CT_1, |
| 13458 | NULL, type, NULL, |
| 13459 | "A <simpleType> is expected among the children " |
| 13460 | "of <restriction>", NULL); |
| 13461 | return (XML_SCHEMAP_SRC_CT_1); |
| 13462 | } |
| 13463 | OK = 1; |
Daniel Veillard | bc69d4f | 2005-03-17 10:04:46 +0000 | [diff] [blame] | 13464 | } else { /* if (base->contentType == XML_SCHEMA_CONTENT_MIXED)*/ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13465 | /* |
| 13466 | * 2.1.1 a complex type definition whose {content type} is a |
| 13467 | * simple type definition; |
| 13468 | */ |
| 13469 | if (base->contentType == XML_SCHEMA_CONTENT_ELEMENTS) { |
| 13470 | xmlSchemaPCustomErr(ctxt, |
| 13471 | XML_SCHEMAP_SRC_CT_1, |
| 13472 | NULL, type, NULL, |
| 13473 | "A complex type (simple content) cannot " |
| 13474 | "be derived from the complex type '%s'", |
| 13475 | base->name); |
| 13476 | return (XML_SCHEMAP_SRC_CT_1); |
| 13477 | } |
| 13478 | content = base->contentTypeDef; |
| 13479 | if (content == NULL) { |
| 13480 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, |
| 13481 | NULL, type, NULL, |
| 13482 | "Internal error: xmlSchemaCheckSRCCT, " |
| 13483 | "'%s', base type has no content type", |
| 13484 | type->name); |
| 13485 | return (-1); |
| 13486 | } |
| 13487 | if (content->type != XML_SCHEMA_TYPE_SIMPLE) { |
| 13488 | xmlSchemaPCustomErr(ctxt, |
| 13489 | XML_SCHEMAP_SRC_CT_1, |
| 13490 | NULL, type, NULL, |
| 13491 | "A complex type (simple content) cannot " |
| 13492 | "be derived from the complex type '%s'", |
| 13493 | base->name); |
| 13494 | return (XML_SCHEMAP_SRC_CT_1); |
| 13495 | } |
| 13496 | } |
| 13497 | } |
| 13498 | } |
| 13499 | } |
| 13500 | /* |
| 13501 | * TODO: 3 The corresponding complex type definition component must |
| 13502 | * satisfy the conditions set out in Constraints on Complex Type |
| 13503 | * Definition Schema Components (§3.4.6); |
| 13504 | * |
| 13505 | * TODO: 4 If clause 2.2.1 or clause 2.2.2 in the correspondence specification |
| 13506 | * above for {attribute wildcard} is satisfied, the intensional |
| 13507 | * intersection must be expressible, as defined in Attribute Wildcard |
| 13508 | * Intersection (§3.10.6). |
| 13509 | */ |
| 13510 | |
| 13511 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13512 | #endif |
| 13513 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13514 | /** |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 13515 | * xmlSchemaGroupDefFixup: |
| 13516 | * @typeDecl: the schema model group definition |
| 13517 | * @ctxt: the schema parser context |
| 13518 | * |
| 13519 | * Fixes model group definitions. |
| 13520 | */ |
| 13521 | static void |
| 13522 | xmlSchemaGroupDefFixup(xmlSchemaTypePtr group, |
| 13523 | xmlSchemaParserCtxtPtr ctxt, |
| 13524 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 13525 | { |
| 13526 | group->contentType = XML_SCHEMA_CONTENT_ELEMENTS; |
| 13527 | if ((group->ref != NULL) && (group->subtypes == NULL)) { |
| 13528 | xmlSchemaTypePtr groupDef; |
| 13529 | /* |
| 13530 | * Resolve the reference. |
| 13531 | */ |
| 13532 | groupDef = xmlSchemaGetGroup(ctxt->schema, group->ref, |
| 13533 | group->refNs); |
| 13534 | if (groupDef == NULL) { |
| 13535 | xmlSchemaPResCompAttrErr(ctxt, |
| 13536 | XML_SCHEMAP_SRC_RESOLVE, |
| 13537 | NULL, group, NULL, |
| 13538 | "ref", group->ref, group->refNs, |
| 13539 | XML_SCHEMA_TYPE_GROUP, NULL); |
| 13540 | return; |
| 13541 | } |
| 13542 | group->subtypes = groupDef; |
| 13543 | } |
| 13544 | } |
| 13545 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13546 | #if 0 /* Enable when the content type will be computed. */ |
| 13547 | static int |
| 13548 | xmlSchemaComputeContentType(xmlSchemaParserCtxtPtr ctxt, |
| 13549 | xmlSchemaTypePtr type) |
| 13550 | { |
| 13551 | xmlSchemaTypePtr base, res = NULL; |
| 13552 | |
| 13553 | base = type->baseType; |
| 13554 | if (base == NULL) { |
| 13555 | xmlSchemaPCustomErr(ctxt, |
| 13556 | XML_SCHEMAP_INTERNAL, |
| 13557 | NULL, type, NULL, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 13558 | "Internal error: xmlSchemaComputeContentType, " |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13559 | "the complex type '%s' has no base type", type->name); |
| 13560 | return (-1); |
| 13561 | } |
| 13562 | if (IS_ANYTYPE(base) || (type->subtypes->type == |
| 13563 | XML_SCHEMA_TYPE_COMPLEX_CONTENT)) { |
| 13564 | xmlSchemaTypePtr start; |
| 13565 | /* |
| 13566 | * Effective 'mixed'. |
| 13567 | */ |
| 13568 | if (type->flags & XML_SCHEMAS_TYPE_MIXED) |
| 13569 | type->contentType = XML_SCHEMA_CONTENT_MIXED; |
| 13570 | /* |
| 13571 | * Effective content. |
| 13572 | */ |
| 13573 | if (IS_ANYTYPE(base)) |
| 13574 | start = type; |
| 13575 | else |
| 13576 | start = type->subtypes; |
| 13577 | |
| 13578 | } else { /* if XML_SCHEMA_TYPE_COMPLEX_CONTENT */ |
| 13579 | xmlSchemaTypePtr baseContentItem; |
| 13580 | |
| 13581 | /* |
| 13582 | * Complex type with simple content. |
| 13583 | */ |
| 13584 | if IS_COMPLEX_TYPE(base) { |
| 13585 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
| 13586 | /* |
| 13587 | * Summary: a complex type (simple content) can *restrict* |
| 13588 | * a complex type with the following content type: |
| 13589 | * 1. 'mixed' and an emptiable particle |
| 13590 | * 2. simple type |
| 13591 | */ |
| 13592 | if (base->contentType == XML_SCHEMA_CONTENT_MIXED) { |
| 13593 | /* |
| 13594 | * 2 if the {content type} of the base type is mixed and a |
| 13595 | * particle which is ·emptiable·, |
| 13596 | * [...] |
| 13597 | * then starting from the simple type definition |
| 13598 | * corresponding to the <simpleType> among the [children] |
| 13599 | * of <restriction> (**which must be present**) |
| 13600 | * |
| 13601 | * FIXME TODO: Handle "emptiable particle". |
| 13602 | */ |
| 13603 | res = type->subtypes->subtypes; |
| 13604 | if (res == NULL) { |
| 13605 | xmlSchemaPCustomErr(ctxt, |
| 13606 | XML_SCHEMAP_INTERNAL, |
| 13607 | NULL, type, NULL, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 13608 | "Internal error: xmlSchemaComputeContentType, " |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13609 | "CT '%s' (restricting): <simpleContent> has no " |
| 13610 | "<restriction>", |
| 13611 | type->name); |
| 13612 | return (-1); |
| 13613 | } |
| 13614 | |
| 13615 | res->subtypes; |
| 13616 | if (res == NULL) { |
| 13617 | xmlSchemaPCustomErr(ctxt, |
| 13618 | XML_SCHEMAP_INTERNAL, |
| 13619 | NULL, type, NULL, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 13620 | "Internal error: xmlSchemaComputeContentType, " |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13621 | "CT '%s' (restricting): <restriction> has no " |
| 13622 | "mandatory <simpleType>", |
| 13623 | type->name); |
| 13624 | return (-1); |
| 13625 | } |
| 13626 | } else { |
| 13627 | baseContentItem = base->contentTypeDef; |
| 13628 | if (baseContentItem == NULL) { |
| 13629 | xmlSchemaPCustomErr(ctxt, |
| 13630 | XML_SCHEMAP_INTERNAL, |
| 13631 | NULL, type, NULL, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 13632 | "Internal error: xmlSchemaComputeContentType, " |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13633 | "CT '%s' (restricting), the base type has no " |
| 13634 | "content type", type->name); |
| 13635 | return (-1); |
| 13636 | } |
| 13637 | if IS_SIMPLE_TYPE(baseContentItem) { |
| 13638 | /* |
| 13639 | * 1 If the base type is a complex type whose own |
| 13640 | * {content type} is a simple type and the <restriction> |
| 13641 | * alternative is chosen |
| 13642 | */ |
| 13643 | /* type->subtypes->subtypes will be the restriction item.*/ |
| 13644 | res = type->subtypes->subtypes; |
| 13645 | if (res == NULL) { |
| 13646 | xmlSchemaPCustomErr(ctxt, |
| 13647 | XML_SCHEMAP_INTERNAL, |
| 13648 | NULL, type, NULL, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 13649 | "Internal error: xmlSchemaComputeContentType, " |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13650 | "CT '%s' (restricting): <simpleType> has no " |
| 13651 | "<restriction>", type->name); |
| 13652 | return (-1); |
| 13653 | } |
| 13654 | /* |
| 13655 | * 1.1 the simple type definition corresponding to the |
| 13656 | * <simpleType> among the [children] of <restriction>if |
| 13657 | * there is one; |
| 13658 | */ |
| 13659 | res = res->subtypes; |
| 13660 | if (res == NULL) { |
| 13661 | /* |
| 13662 | * 1.2 otherwise the {content type} |
| 13663 | * of the base type . |
| 13664 | */ |
| 13665 | res = baseContentItem; |
| 13666 | } |
| 13667 | } |
| 13668 | } |
| 13669 | /* |
| 13670 | * SPECIAL TODO: If *restricting* the spec wants us to |
| 13671 | * create an *additional* simple type which restricts the |
| 13672 | * located simple type; we won't do this yet, and look how |
| 13673 | * far we get with it. |
| 13674 | */ |
| 13675 | } else { /* if XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION */ |
| 13676 | /* |
| 13677 | * Summary: a complex type (simple content) can *extend* |
| 13678 | * only a complex base with a simple type as content. |
| 13679 | */ |
| 13680 | /* |
| 13681 | * 3 If the type definition ·resolved· to by the ·actual |
| 13682 | * value· of the base [attribute] is a complex type |
| 13683 | * definition (whose own {content type} *must be* a simple |
| 13684 | * type definition, see below) and the *<extension>* |
| 13685 | * alternative is chosen, then the {content type} of that |
| 13686 | * complex type definition; |
| 13687 | */ |
| 13688 | res = base->contentTypeDef; |
| 13689 | if (res == NULL) { |
| 13690 | xmlSchemaPCustomErr(ctxt, |
| 13691 | XML_SCHEMAP_INTERNAL, |
| 13692 | NULL, type, NULL, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 13693 | "Internal error: xmlSchemaComputeContentType, " |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13694 | "CT '%s' (extending), the base type has no content " |
| 13695 | "type", type->name); |
| 13696 | return (-1); |
| 13697 | } |
| 13698 | if (! IS_SIMPLE_TYPE(res)) { |
| 13699 | xmlSchemaPCustomErr(ctxt, |
| 13700 | XML_SCHEMAP_INTERNAL, |
| 13701 | NULL, type, NULL, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 13702 | "Internal error: xmlSchemaComputeContentType, " |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13703 | "CT '%s' (extending), the content type of the " |
| 13704 | "base is not a simple type", type->name); |
| 13705 | return (-1); |
| 13706 | } |
| 13707 | } |
| 13708 | } else /* if IS_COMPLEX_TYPE(base) */ |
| 13709 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) { |
| 13710 | /* |
| 13711 | * 4 otherwise (the type definition ·resolved· to by the |
| 13712 | * ·actual value· of the base [attribute] is a simple type |
| 13713 | * definition and the <extension> alternative is chosen), |
| 13714 | * then that simple type definition. |
| 13715 | */ |
| 13716 | res = base; |
| 13717 | } |
| 13718 | type->contentTypeDef = res; |
| 13719 | if (res == NULL) { |
| 13720 | xmlSchemaPCustomErr(ctxt, |
| 13721 | XML_SCHEMAP_INTERNAL, |
| 13722 | NULL, type, NULL, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 13723 | "Internal error: xmlSchemaComputeContentType, " |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13724 | "'%s', the content type could not be determined", |
| 13725 | type->name); |
| 13726 | return (-1); |
| 13727 | } |
| 13728 | |
| 13729 | } |
| 13730 | |
| 13731 | } |
| 13732 | #endif |
| 13733 | |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 13734 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13735 | * xmlSchemaTypeFixup: |
| 13736 | * @typeDecl: the schema type definition |
| 13737 | * @ctxt: the schema parser context |
| 13738 | * |
| 13739 | * Fixes the content model of the type. |
| 13740 | */ |
| 13741 | static void |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13742 | xmlSchemaTypeFixup(xmlSchemaTypePtr item, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13743 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13744 | { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13745 | xmlSchemaTypePtr ctxtType; |
| 13746 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13747 | if (item == NULL) |
Daniel Veillard | 82bbbd4 | 2003-05-11 20:16:09 +0000 | [diff] [blame] | 13748 | return; |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 13749 | /* |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 13750 | * Do not fixup built-in types. |
| 13751 | */ |
| 13752 | if (item->type == XML_SCHEMA_TYPE_BASIC) |
| 13753 | return; |
| 13754 | /* |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 13755 | * Do not allow the following types to be typefixed, prior to |
| 13756 | * the corresponding simple/complex types. |
| 13757 | */ |
| 13758 | if (ctxt->ctxtType == NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13759 | switch (item->type) { |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 13760 | case XML_SCHEMA_TYPE_SIMPLE_CONTENT: |
| 13761 | case XML_SCHEMA_TYPE_COMPLEX_CONTENT: |
| 13762 | case XML_SCHEMA_TYPE_UNION: |
| 13763 | case XML_SCHEMA_TYPE_RESTRICTION: |
| 13764 | case XML_SCHEMA_TYPE_EXTENSION: |
| 13765 | return; |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 13766 | default: |
| 13767 | break; |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 13768 | } |
| 13769 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13770 | if (name == NULL) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13771 | name = item->name; |
| 13772 | if (item->contentType == XML_SCHEMA_CONTENT_UNKNOWN) { |
| 13773 | switch (item->type) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13774 | case XML_SCHEMA_TYPE_SIMPLE_CONTENT:{ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13775 | if (item->subtypes != NULL) { |
| 13776 | if (item->subtypes->contentType == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13777 | XML_SCHEMA_CONTENT_UNKNOWN) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13778 | xmlSchemaTypeFixup(item->subtypes, ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13779 | NULL); |
| 13780 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13781 | item->contentType = |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13782 | XML_SCHEMA_CONTENT_SIMPLE; |
| 13783 | /* item->subtypes->contentType; */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13784 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13785 | break; |
| 13786 | } |
| 13787 | case XML_SCHEMA_TYPE_RESTRICTION:{ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13788 | xmlSchemaTypePtr base = NULL; |
| 13789 | |
| 13790 | ctxt->ctxtType->flags |= |
| 13791 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13792 | if (item->baseType != NULL) |
| 13793 | base = item->baseType; |
| 13794 | else if (item->base != NULL) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13795 | base = |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13796 | xmlSchemaGetType(ctxt->schema, item->base, |
| 13797 | item->baseNs); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13798 | if (base == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13799 | xmlSchemaPResCompAttrErr(ctxt, |
| 13800 | XML_SCHEMAP_SRC_RESOLVE, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13801 | NULL, NULL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13802 | (xmlNodePtr) xmlSchemaGetPropNode(item->node, "base"), |
| 13803 | "base", item->base, item->baseNs, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13804 | XML_SCHEMA_TYPE_BASIC, "type definition"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13805 | } else if (base->contentType == |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 13806 | XML_SCHEMA_CONTENT_UNKNOWN) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13807 | xmlSchemaTypeFixup(base, ctxt, NULL); |
| 13808 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13809 | } |
| 13810 | ctxt->ctxtType->baseType = base; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13811 | if (ctxt->ctxtType->type == XML_SCHEMA_TYPE_COMPLEX) { |
| 13812 | /* |
| 13813 | * ComplexType restriction. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13814 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13815 | /* |
| 13816 | * Content type. |
| 13817 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13818 | if (item->subtypes == NULL) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13819 | /* 1.1.1 */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13820 | item->contentType = XML_SCHEMA_CONTENT_EMPTY; |
| 13821 | else if ((item->subtypes->subtypes == NULL) && |
| 13822 | ((item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13823 | XML_SCHEMA_TYPE_ALL) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13824 | || (item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13825 | XML_SCHEMA_TYPE_SEQUENCE))) |
| 13826 | /* 1.1.2 */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13827 | item->contentType = XML_SCHEMA_CONTENT_EMPTY; |
| 13828 | else if ((item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13829 | XML_SCHEMA_TYPE_CHOICE) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13830 | && (item->subtypes->subtypes == NULL)) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13831 | /* 1.1.3 */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13832 | item->contentType = XML_SCHEMA_CONTENT_EMPTY; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13833 | else { |
| 13834 | /* 1.2 and 2.X are applied at the other layer */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13835 | item->contentType = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13836 | XML_SCHEMA_CONTENT_ELEMENTS; |
| 13837 | } |
| 13838 | } else { |
| 13839 | /* |
| 13840 | * SimpleType restriction. |
| 13841 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13842 | /* TODO: Nothing? */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13843 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13844 | break; |
| 13845 | } |
| 13846 | case XML_SCHEMA_TYPE_EXTENSION:{ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13847 | xmlSchemaTypePtr base = NULL; |
| 13848 | xmlSchemaContentType explicitContentType; |
| 13849 | |
| 13850 | /* |
| 13851 | * An extension does exist on a complexType only. |
| 13852 | */ |
| 13853 | ctxt->ctxtType->flags |= |
| 13854 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13855 | if (item->recurse) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13856 | xmlSchemaPCustomErr(ctxt, |
| 13857 | XML_SCHEMAP_UNKNOWN_BASE_TYPE, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13858 | NULL, item, item->node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13859 | "This item is circular", NULL); |
Daniel Veillard | 2582a33 | 2004-04-18 19:49:46 +0000 | [diff] [blame] | 13860 | return; |
| 13861 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13862 | if (item->base != NULL) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13863 | base = |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13864 | xmlSchemaGetType(ctxt->schema, item->base, |
| 13865 | item->baseNs); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13866 | if (base == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13867 | xmlSchemaPResCompAttrErr(ctxt, |
| 13868 | XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13869 | NULL, item, item->node, |
| 13870 | "base", item->base, item->baseNs, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13871 | XML_SCHEMA_TYPE_BASIC, "type definition"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13872 | } else if (base->contentType == |
| 13873 | XML_SCHEMA_CONTENT_UNKNOWN) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13874 | item->recurse = 1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13875 | xmlSchemaTypeFixup(base, ctxt, NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13876 | item->recurse = 0; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13877 | } |
| 13878 | /* |
| 13879 | * The type definition ·resolved· to by the ·actual |
| 13880 | * value· of the base [attribute] |
| 13881 | */ |
| 13882 | ctxt->ctxtType->baseType = base; |
| 13883 | /* |
| 13884 | * TODO: This one is still needed for computation of |
| 13885 | * the content model by xmlSchemaBuildAContentModel. |
| 13886 | * Try to get rid of it. |
| 13887 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13888 | item->baseType = base; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13889 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13890 | if ((item->subtypes != NULL) && |
| 13891 | (item->subtypes->contentType == XML_SCHEMA_CONTENT_UNKNOWN)) |
| 13892 | xmlSchemaTypeFixup(item->subtypes, ctxt, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13893 | |
| 13894 | explicitContentType = XML_SCHEMA_CONTENT_ELEMENTS; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13895 | if (item->subtypes == NULL) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13896 | /* 1.1.1 */ |
| 13897 | explicitContentType = XML_SCHEMA_CONTENT_EMPTY; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13898 | else if ((item->subtypes->subtypes == NULL) && |
| 13899 | ((item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13900 | XML_SCHEMA_TYPE_ALL) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13901 | || (item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13902 | XML_SCHEMA_TYPE_SEQUENCE))) |
| 13903 | /* 1.1.2 */ |
| 13904 | explicitContentType = XML_SCHEMA_CONTENT_EMPTY; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13905 | else if ((item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13906 | XML_SCHEMA_TYPE_CHOICE) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13907 | && (item->subtypes->subtypes == NULL)) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13908 | /* 1.1.3 */ |
| 13909 | explicitContentType = XML_SCHEMA_CONTENT_EMPTY; |
| 13910 | if (base != NULL) { |
| 13911 | /* It will be reported later, if the base is missing. */ |
| 13912 | if (explicitContentType == XML_SCHEMA_CONTENT_EMPTY) { |
| 13913 | /* 2.1 */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13914 | item->contentType = base->contentType; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13915 | } else if (base->contentType == |
| 13916 | XML_SCHEMA_CONTENT_EMPTY) { |
| 13917 | /* 2.2 imbitable ! */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13918 | item->contentType = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13919 | XML_SCHEMA_CONTENT_ELEMENTS; |
| 13920 | } else { |
| 13921 | /* 2.3 imbitable pareil ! */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13922 | item->contentType = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13923 | XML_SCHEMA_CONTENT_ELEMENTS; |
| 13924 | } |
| 13925 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13926 | break; |
| 13927 | } |
| 13928 | case XML_SCHEMA_TYPE_COMPLEX:{ |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 13929 | ctxtType = ctxt->ctxtType; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13930 | ctxt->ctxtType = item; |
| 13931 | /* |
| 13932 | * Start with an empty content-type type. |
| 13933 | */ |
| 13934 | if (item->subtypes == NULL) |
| 13935 | item->contentType = XML_SCHEMA_CONTENT_EMPTY; |
| 13936 | |
| 13937 | if ((item->subtypes == NULL) || |
| 13938 | ((item->subtypes->type != |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13939 | XML_SCHEMA_TYPE_SIMPLE_CONTENT) && |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13940 | (item->subtypes->type != |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13941 | XML_SCHEMA_TYPE_COMPLEX_CONTENT))) { |
| 13942 | /* |
| 13943 | * This case is understood as shorthand for complex |
| 13944 | * content restricting the ur-type definition, and |
| 13945 | * the details of the mappings should be modified as |
| 13946 | * necessary. |
| 13947 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13948 | item->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 13949 | item->flags |= |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13950 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13951 | /* |
Kasimier T. Buchcik | 289dbb4 | 2005-03-17 12:39:31 +0000 | [diff] [blame] | 13952 | * NOTE that if restricting, the content type of the |
| 13953 | * base type is not inherited. |
| 13954 | * REMOVED: item->contentType = item->baseType->contentType; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13955 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13956 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13957 | /* |
| 13958 | * Fixup the sub components. |
| 13959 | */ |
| 13960 | if ((item->subtypes != NULL) && |
| 13961 | (item->subtypes->contentType == |
| 13962 | XML_SCHEMA_CONTENT_UNKNOWN)) { |
| 13963 | xmlSchemaTypeFixup(item->subtypes, ctxt, NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13964 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13965 | if (item->flags & XML_SCHEMAS_TYPE_MIXED) { |
| 13966 | item->contentType = XML_SCHEMA_CONTENT_MIXED; |
| 13967 | } else if (item->subtypes != NULL) { |
| 13968 | /* |
| 13969 | * Use the content-type type of the model groups |
| 13970 | * defined, if 'mixed' is not set. If 'mixed' is set |
| 13971 | * it will expand the content-type by allowing character |
| 13972 | * content to appear. |
| 13973 | */ |
| 13974 | item->contentType = |
| 13975 | item->subtypes->contentType; |
| 13976 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 13977 | |
| 13978 | /* |
| 13979 | * Some optimization for validation: |
| 13980 | * If there are no facets beside the "whitespace" facet, |
| 13981 | * then a value needs not to checked against against a |
| 13982 | * facet, thus no computed value is needed. |
| 13983 | * TODO URGENT: This is just a workaround, we need to |
| 13984 | * introduce the correct usage of contentType to store the |
| 13985 | * facets in! |
| 13986 | */ |
Daniel Veillard | d3210bc | 2005-01-28 17:56:39 +0000 | [diff] [blame] | 13987 | if ((item->baseType != NULL) && |
| 13988 | (item->baseType->flags & |
| 13989 | XML_SCHEMAS_TYPE_FACETSNEEDVALUE)) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 13990 | item->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE; |
| 13991 | else { |
| 13992 | xmlSchemaFacetLinkPtr cur; |
| 13993 | |
| 13994 | for (cur = item->facetSet; cur != NULL; |
| 13995 | cur = cur->next) { |
| 13996 | if (cur->facet->type != XML_SCHEMA_FACET_WHITESPACE) { |
| 13997 | item->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE; |
| 13998 | break; |
| 13999 | } |
| 14000 | } |
| 14001 | } |
| 14002 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14003 | xmlSchemaBuildAttributeValidation(ctxt, item); |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 14004 | xmlSchemaCheckDefaults(item, ctxt, item->name); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 14005 | ctxt->ctxtType = ctxtType; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14006 | break; |
| 14007 | } |
| 14008 | case XML_SCHEMA_TYPE_COMPLEX_CONTENT:{ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14009 | if (item->subtypes == NULL) { |
| 14010 | item->contentType = XML_SCHEMA_CONTENT_EMPTY; |
| 14011 | if (item->flags & XML_SCHEMAS_TYPE_MIXED) |
| 14012 | item->contentType = |
Daniel Veillard | 1aefc86 | 2004-03-04 11:40:48 +0000 | [diff] [blame] | 14013 | XML_SCHEMA_CONTENT_MIXED; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14014 | } else { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14015 | if (item->flags & XML_SCHEMAS_TYPE_MIXED) { |
| 14016 | item->contentType = |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14017 | XML_SCHEMA_CONTENT_MIXED; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14018 | } else { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14019 | xmlSchemaTypeFixup(item->subtypes, ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14020 | NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14021 | if (item->subtypes != NULL) |
| 14022 | item->contentType = |
| 14023 | item->subtypes->contentType; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14024 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14025 | /* |
| 14026 | * Removed due to implementation of the build of attribute uses. |
| 14027 | */ |
| 14028 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14029 | if (item->attributes == NULL) |
| 14030 | item->attributes = |
| 14031 | item->subtypes->attributes; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14032 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14033 | } |
| 14034 | break; |
| 14035 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14036 | case XML_SCHEMA_TYPE_SIMPLE: |
| 14037 | /* |
| 14038 | * Simple Type Definition Schema Component |
| 14039 | * |
| 14040 | */ |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 14041 | ctxtType = ctxt->ctxtType; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14042 | item->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
| 14043 | if (item->subtypes->contentType == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14044 | XML_SCHEMA_CONTENT_UNKNOWN) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14045 | ctxt->ctxtType = item; |
| 14046 | xmlSchemaTypeFixup(item->subtypes, ctxt, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14047 | } |
| 14048 | /* Fixup base type */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14049 | if ((item->baseType != NULL) && |
| 14050 | (item->baseType->contentType == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14051 | XML_SCHEMA_CONTENT_UNKNOWN)) { |
| 14052 | /* OPTIMIZE: Actually this one will never by hit, since |
| 14053 | * the base type is already type-fixed in <restriction>. |
| 14054 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14055 | ctxt->ctxtType = item; |
| 14056 | xmlSchemaTypeFixup(item->baseType, ctxt, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14057 | } |
| 14058 | /* Base type: |
| 14059 | * 2 If the <list> or <union> alternative is chosen, |
| 14060 | * then the ·simple ur-type definition·. |
| 14061 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14062 | if (item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14063 | XML_SCHEMA_TYPE_LIST) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14064 | item->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 14065 | item->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST; |
| 14066 | } else if (item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14067 | XML_SCHEMA_TYPE_UNION) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14068 | item->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 14069 | item->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION; |
| 14070 | } else if (item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14071 | XML_SCHEMA_TYPE_RESTRICTION) { |
| 14072 | xmlSchemaFacetLinkPtr facet, cur, last = NULL; |
| 14073 | |
| 14074 | /* |
| 14075 | * Variety |
| 14076 | * If the <restriction> alternative is chosen, then the |
| 14077 | * {variety} of the {base type definition}. |
| 14078 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14079 | if (item->baseType != NULL) { |
| 14080 | if (item->baseType->flags & |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14081 | XML_SCHEMAS_TYPE_VARIETY_ATOMIC) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14082 | item->flags |= XML_SCHEMAS_TYPE_VARIETY_ATOMIC; |
| 14083 | else if (item->baseType->flags & |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14084 | XML_SCHEMAS_TYPE_VARIETY_LIST) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14085 | item->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST; |
| 14086 | else if (item->baseType->flags & |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14087 | XML_SCHEMAS_TYPE_VARIETY_UNION) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14088 | item->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14089 | /* |
| 14090 | * Schema Component Constraint: Simple Type Restriction |
| 14091 | * (Facets) |
| 14092 | * NOTE: Satisfaction of 1 and 2 arise from the fixup |
| 14093 | * applied beforehand. |
| 14094 | * |
| 14095 | * 3 The {facets} of R are the union of S and the {facets} |
| 14096 | * of B, eliminating duplicates. To eliminate duplicates, |
| 14097 | * when a facet of the same kind occurs in both S and the |
| 14098 | * {facets} of B, the one in the {facets} of B is not |
| 14099 | * included, with the exception of enumeration and pattern |
| 14100 | * facets, for which multiple occurrences with distinct values |
| 14101 | * are allowed. |
| 14102 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14103 | if (item->baseType->facetSet != NULL) { |
| 14104 | last = item->facetSet; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14105 | if (last != NULL) |
| 14106 | while (last->next != NULL) |
| 14107 | last = last->next; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 14108 | cur = item->baseType->facetSet; |
| 14109 | for (; cur != NULL; cur = cur->next) { |
| 14110 | /* |
| 14111 | * Base patterns won't be add here: |
| 14112 | * they are ORed in a type and |
| 14113 | * ANDed in derived types. This will |
| 14114 | * happed at validation level by |
| 14115 | * walking the base axis of the type. |
| 14116 | */ |
| 14117 | if (cur->facet->type == |
| 14118 | XML_SCHEMA_FACET_PATTERN) |
| 14119 | continue; |
| 14120 | facet = NULL; |
| 14121 | if ((item->facetSet != NULL) && |
| 14122 | /* REMOVED: a check for |
| 14123 | * XML_SCHEMA_FACET_PATTERN was already |
| 14124 | * performed above. |
| 14125 | |
| 14126 | * (cur->facet->type != |
| 14127 | * XML_SCHEMA_FACET_PATTERN) && |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14128 | */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 14129 | (cur->facet->type != |
| 14130 | XML_SCHEMA_FACET_ENUMERATION)) { |
| 14131 | facet = item->facetSet; |
| 14132 | do { |
| 14133 | if (cur->facet->type == |
| 14134 | facet->facet->type) |
| 14135 | break; |
| 14136 | facet = facet->next; |
| 14137 | } while (facet != NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14138 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 14139 | if (facet == NULL) { |
| 14140 | facet = (xmlSchemaFacetLinkPtr) |
| 14141 | xmlMalloc(sizeof(xmlSchemaFacetLink)); |
| 14142 | if (facet == NULL) { |
| 14143 | xmlSchemaPErrMemory(ctxt, |
| 14144 | "fixing simpleType", NULL); |
| 14145 | return; |
| 14146 | } |
| 14147 | /* |
| 14148 | * The facets are not copied but referenced |
| 14149 | * via the facet link. |
| 14150 | */ |
| 14151 | facet->facet = cur->facet; |
| 14152 | facet->next = NULL; |
| 14153 | if (last == NULL) |
| 14154 | item->facetSet = facet; |
| 14155 | else |
| 14156 | last->next = facet; |
| 14157 | last = facet; |
| 14158 | } |
| 14159 | } |
| 14160 | } |
| 14161 | /* |
| 14162 | * Some optimization for validation: |
| 14163 | * If there are no facets beside the "whitespace" facet, |
| 14164 | * then a value needs not to checked against against a |
| 14165 | * facet, thus no computed value is needed. |
| 14166 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 14167 | if (item->baseType->flags & XML_SCHEMAS_TYPE_FACETSNEEDVALUE) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 14168 | item->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE; |
| 14169 | else { |
| 14170 | for (cur = item->facetSet; cur != NULL; |
| 14171 | cur = cur->next) { |
| 14172 | if (cur->facet->type != XML_SCHEMA_FACET_WHITESPACE) { |
| 14173 | item->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE; |
| 14174 | break; |
| 14175 | } |
| 14176 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14177 | } |
| 14178 | } |
| 14179 | } |
| 14180 | /* |
| 14181 | * Check constraints. |
| 14182 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14183 | xmlSchemaCheckSRCSimpleType(ctxt, item); |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 14184 | xmlSchemaCheckDefaults(item, ctxt, item->name); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 14185 | ctxt->ctxtType = ctxtType; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14186 | break; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 14187 | case XML_SCHEMA_TYPE_SEQUENCE: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14188 | case XML_SCHEMA_TYPE_ALL: |
| 14189 | case XML_SCHEMA_TYPE_CHOICE: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14190 | item->contentType = XML_SCHEMA_CONTENT_ELEMENTS; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14191 | break; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 14192 | case XML_SCHEMA_TYPE_GROUP: |
| 14193 | /* |
| 14194 | * TODO: Handling was moved to xmlSchemaGroupDefFixup. |
| 14195 | */ |
| 14196 | break; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14197 | case XML_SCHEMA_TYPE_LIST: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14198 | xmlSchemaParseListRefFixup(item, ctxt); |
| 14199 | item->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14200 | break; |
| 14201 | case XML_SCHEMA_TYPE_UNION: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14202 | xmlSchemaParseUnionRefCheck(item, ctxt); |
| 14203 | item->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14204 | break; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14205 | case XML_SCHEMA_TYPE_BASIC: |
| 14206 | case XML_SCHEMA_TYPE_ANY: |
| 14207 | case XML_SCHEMA_TYPE_FACET: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14208 | case XML_SCHEMA_TYPE_UR: |
| 14209 | case XML_SCHEMA_TYPE_ELEMENT: |
| 14210 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 14211 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
William M. Brack | 29aa772 | 2004-05-12 00:27:56 +0000 | [diff] [blame] | 14212 | case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14213 | case XML_SCHEMA_TYPE_NOTATION: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14214 | case XML_SCHEMA_FACET_MININCLUSIVE: |
| 14215 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
| 14216 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
| 14217 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
| 14218 | case XML_SCHEMA_FACET_TOTALDIGITS: |
| 14219 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
| 14220 | case XML_SCHEMA_FACET_PATTERN: |
| 14221 | case XML_SCHEMA_FACET_ENUMERATION: |
| 14222 | case XML_SCHEMA_FACET_WHITESPACE: |
| 14223 | case XML_SCHEMA_FACET_LENGTH: |
| 14224 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 14225 | case XML_SCHEMA_FACET_MINLENGTH: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14226 | item->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
| 14227 | if (item->subtypes != NULL) |
| 14228 | xmlSchemaTypeFixup(item->subtypes, ctxt, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14229 | break; |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 14230 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
| 14231 | case XML_SCHEMA_TYPE_IDC_KEY: |
| 14232 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
| 14233 | break; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14234 | } |
| 14235 | } |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 14236 | #ifdef DEBUG_TYPE |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14237 | if (item->node != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14238 | xmlGenericError(xmlGenericErrorContext, |
| 14239 | "Type of %s : %s:%d :", name, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14240 | item->node->doc->URL, |
| 14241 | xmlGetLineNo(item->node)); |
Daniel Veillard | decd64d | 2002-04-18 14:41:51 +0000 | [diff] [blame] | 14242 | } else { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14243 | xmlGenericError(xmlGenericErrorContext, "Type of %s :", name); |
Daniel Veillard | decd64d | 2002-04-18 14:41:51 +0000 | [diff] [blame] | 14244 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14245 | switch (item->contentType) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14246 | case XML_SCHEMA_CONTENT_SIMPLE: |
| 14247 | xmlGenericError(xmlGenericErrorContext, "simple\n"); |
| 14248 | break; |
| 14249 | case XML_SCHEMA_CONTENT_ELEMENTS: |
| 14250 | xmlGenericError(xmlGenericErrorContext, "elements\n"); |
| 14251 | break; |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 14252 | case XML_SCHEMA_CONTENT_UNKNOWN: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14253 | xmlGenericError(xmlGenericErrorContext, "unknown !!!\n"); |
| 14254 | break; |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 14255 | case XML_SCHEMA_CONTENT_EMPTY: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14256 | xmlGenericError(xmlGenericErrorContext, "empty\n"); |
| 14257 | break; |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 14258 | case XML_SCHEMA_CONTENT_MIXED: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14259 | xmlGenericError(xmlGenericErrorContext, "mixed\n"); |
| 14260 | break; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14261 | /* Removed, since not used. */ |
| 14262 | /* |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 14263 | case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14264 | xmlGenericError(xmlGenericErrorContext, "mixed or elems\n"); |
| 14265 | break; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14266 | */ |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 14267 | case XML_SCHEMA_CONTENT_BASIC: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14268 | xmlGenericError(xmlGenericErrorContext, "basic\n"); |
| 14269 | break; |
| 14270 | default: |
| 14271 | xmlGenericError(xmlGenericErrorContext, |
| 14272 | "not registered !!!\n"); |
| 14273 | break; |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 14274 | } |
| 14275 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14276 | } |
| 14277 | |
| 14278 | /** |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 14279 | * xmlSchemaCheckFacet: |
| 14280 | * @facet: the facet |
| 14281 | * @typeDecl: the schema type definition |
| 14282 | * @ctxt: the schema parser context or NULL |
| 14283 | * @name: name of the type |
| 14284 | * |
| 14285 | * Checks the default values types, especially for facets |
| 14286 | * |
| 14287 | * Returns 0 if okay or -1 in cae of error |
| 14288 | */ |
| 14289 | int |
| 14290 | xmlSchemaCheckFacet(xmlSchemaFacetPtr facet, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14291 | xmlSchemaTypePtr typeDecl, |
| 14292 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name) |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 14293 | { |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 14294 | xmlSchemaTypePtr nonNegativeIntegerType = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14295 | int ret = 0, reuseValCtxt = 0; |
| 14296 | |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 14297 | if ((facet == NULL) || (typeDecl == NULL)) |
| 14298 | return(-1); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14299 | /* |
| 14300 | * TODO: will the parser context be given if used from |
| 14301 | * the relaxNG module? |
| 14302 | */ |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 14303 | |
| 14304 | if (nonNegativeIntegerType == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14305 | nonNegativeIntegerType = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14306 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NNINTEGER); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 14307 | } |
| 14308 | switch (facet->type) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14309 | case XML_SCHEMA_FACET_MININCLUSIVE: |
| 14310 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
| 14311 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 14312 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
| 14313 | case XML_SCHEMA_FACET_ENUMERATION: { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14314 | /* |
| 14315 | * Okay we need to validate the value |
| 14316 | * at that point. |
| 14317 | */ |
| 14318 | xmlSchemaValidCtxtPtr vctxt; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14319 | xmlSchemaTypePtr base; |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 14320 | |
| 14321 | /* 4.3.5.5 Constraints on enumeration Schema Components |
| 14322 | * Schema Component Constraint: enumeration valid restriction |
| 14323 | * It is an ·error· if any member of {value} is not in the |
| 14324 | * ·value space· of {base type definition}. |
| 14325 | * |
| 14326 | * minInclusive, maxInclusive, minExclusive, maxExclusive: |
| 14327 | * The value ·must· be in the |
| 14328 | * ·value space· of the ·base type·. |
| 14329 | */ |
| 14330 | /* |
| 14331 | * This function is intended to deliver a compiled value |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 14332 | * on the facet. In this implementation of XML Schemata the |
| 14333 | * type holding a facet, won't be a built-in type. |
| 14334 | * Thus to ensure that other API |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 14335 | * calls (relaxng) do work, if the given type is a built-in |
| 14336 | * type, we will assume that the given built-in type *is |
| 14337 | * already* the base type. |
| 14338 | */ |
| 14339 | if (typeDecl->type != XML_SCHEMA_TYPE_BASIC) { |
| 14340 | base = typeDecl->baseType; |
| 14341 | if (base == NULL) { |
| 14342 | xmlSchemaPErr(ctxt, typeDecl->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 14343 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 14344 | "Internal error: xmlSchemaCheckFacet, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14345 | "the type '%s' has no base type.\n", |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 14346 | typeDecl->name, NULL); |
| 14347 | return (-1); |
| 14348 | } |
| 14349 | } else |
| 14350 | base = typeDecl; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14351 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14352 | * This avoids perseverative creation of the |
| 14353 | * validation context if a parser context is |
| 14354 | * used. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14355 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14356 | if (ctxt != NULL) { |
| 14357 | reuseValCtxt = 1; |
| 14358 | if (ctxt->vctxt == NULL) { |
| 14359 | if (xmlSchemaCreateVCtxtOnPCtxt(ctxt) == -1) |
| 14360 | return (-1); |
| 14361 | } |
| 14362 | vctxt = ctxt->vctxt; |
| 14363 | } else { |
| 14364 | vctxt = xmlSchemaNewValidCtxt(NULL); |
| 14365 | if (vctxt == NULL) { |
| 14366 | xmlSchemaPErr(ctxt, typeDecl->node, |
| 14367 | XML_SCHEMAP_INTERNAL, |
| 14368 | "Internal error: xmlSchemaCheckFacet, " |
| 14369 | "creating a new validation context.\n", |
| 14370 | NULL, NULL); |
| 14371 | return (-1); |
| 14372 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14373 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14374 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14375 | vctxt->node = facet->node; |
| 14376 | vctxt->cur = NULL; |
| 14377 | /* |
| 14378 | * NOTE: This call does not check the content nodes, |
| 14379 | * since they are not available: |
| 14380 | * facet->node is just the node holding the facet |
| 14381 | * definition, *not* the attribute holding the *value* |
| 14382 | * of the facet. |
| 14383 | */ |
| 14384 | ret = xmlSchemaValidateSimpleTypeValue(vctxt, base, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 14385 | facet->value, 0, 1, 1, 0); |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 14386 | if (ret > 0) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14387 | /* error code */ |
| 14388 | if (ctxt != NULL) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 14389 | xmlChar *str = NULL; |
| 14390 | |
| 14391 | xmlSchemaPCustomErrExt(ctxt, |
| 14392 | XML_SCHEMAP_INVALID_FACET_VALUE, |
| 14393 | NULL, (xmlSchemaTypePtr) facet, facet->node, |
| 14394 | "The value '%s' of the facet does not validate " |
| 14395 | "against the base type '%s'", |
| 14396 | facet->value, |
| 14397 | xmlSchemaFormatQName(&str, |
| 14398 | base->targetNamespace, base->name), NULL); |
| 14399 | FREE_AND_NULL(str) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14400 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 14401 | /* xmlSchemaFacetTypeToString(facet->type), */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14402 | ret = -1; |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 14403 | } else if (ret < 0) { |
| 14404 | xmlSchemaPErrExt(ctxt, facet->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 14405 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 14406 | NULL, NULL, NULL, |
| 14407 | "Internal error: xmlSchemaCheckFacet, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14408 | "failed to validate the value '%s' name of the " |
| 14409 | "facet '%s' against the base type '%s'.\n", |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 14410 | facet->value, |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 14411 | xmlSchemaFacetTypeToString(facet->type), |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 14412 | base->name, NULL, NULL); |
| 14413 | ret = -1; |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 14414 | } else { |
| 14415 | if (vctxt->value != NULL) { |
| 14416 | facet->val = vctxt->value; |
| 14417 | vctxt->value = NULL; |
| 14418 | } else { |
| 14419 | xmlChar *str; |
| 14420 | /* |
| 14421 | * Ensure computed values even for type string. |
| 14422 | * TODO OPTIMIZE MEMORY: The value will be hold twice, |
| 14423 | * by the facet->value and by the computed value. |
| 14424 | */ |
| 14425 | str = xmlStrdup(facet->value); |
| 14426 | if (xmlSchemaPostCreateVal(vctxt, typeDecl, |
| 14427 | BAD_CAST str, &(facet->val)) == -1) { |
| 14428 | FREE_AND_NULL(str) |
| 14429 | xmlSchemaPErr(ctxt, typeDecl->node, |
| 14430 | XML_SCHEMAP_INTERNAL, |
| 14431 | "Internal error: xmlSchemaCheckFacet, " |
| 14432 | "post-creating a computed value.\n", |
| 14433 | NULL, NULL); |
| 14434 | /* Note that we don't return a failure yet.*/ |
| 14435 | } |
| 14436 | } |
| 14437 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14438 | if (reuseValCtxt == 0) |
| 14439 | xmlSchemaFreeValidCtxt(vctxt); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14440 | break; |
| 14441 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14442 | case XML_SCHEMA_FACET_PATTERN: |
| 14443 | facet->regexp = xmlRegexpCompile(facet->value); |
| 14444 | if (facet->regexp == NULL) { |
| 14445 | xmlSchemaPErr(ctxt, typeDecl->node, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14446 | XML_SCHEMAP_REGEXP_INVALID, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14447 | "Type definition '%s': The value '%s' of the " |
| 14448 | "facet 'pattern' is not valid.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14449 | name, facet->value); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14450 | ret = -1; |
| 14451 | } |
| 14452 | break; |
| 14453 | case XML_SCHEMA_FACET_TOTALDIGITS: |
| 14454 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
| 14455 | case XML_SCHEMA_FACET_LENGTH: |
| 14456 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 14457 | case XML_SCHEMA_FACET_MINLENGTH:{ |
| 14458 | int tmp; |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 14459 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14460 | tmp = |
| 14461 | xmlSchemaValidatePredefinedType(nonNegativeIntegerType, |
| 14462 | facet->value, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 14463 | &(facet->val)); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14464 | if (tmp != 0) { |
| 14465 | /* error code */ |
| 14466 | if (ctxt != NULL) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 14467 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14468 | XML_SCHEMAP_INVALID_FACET_VALUE, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 14469 | NULL, (xmlSchemaTypePtr) facet, facet->node, |
| 14470 | "The value '%s' of the facet is not a valid " |
| 14471 | "nonNegativeInteger", facet->value); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14472 | } |
| 14473 | ret = -1; |
| 14474 | } |
| 14475 | break; |
| 14476 | } |
| 14477 | case XML_SCHEMA_FACET_WHITESPACE:{ |
| 14478 | if (xmlStrEqual(facet->value, BAD_CAST "preserve")) { |
| 14479 | facet->whitespace = XML_SCHEMAS_FACET_PRESERVE; |
| 14480 | } else if (xmlStrEqual(facet->value, BAD_CAST "replace")) { |
| 14481 | facet->whitespace = XML_SCHEMAS_FACET_REPLACE; |
| 14482 | } else if (xmlStrEqual(facet->value, BAD_CAST "collapse")) { |
| 14483 | facet->whitespace = XML_SCHEMAS_FACET_COLLAPSE; |
| 14484 | } else { |
| 14485 | if (ctxt != NULL) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 14486 | /* error was previously: XML_SCHEMAP_INVALID_WHITE_SPACE */ |
| 14487 | xmlSchemaPCustomErr(ctxt, |
| 14488 | XML_SCHEMAP_INVALID_FACET_VALUE, |
| 14489 | NULL, (xmlSchemaTypePtr) facet, facet->node, |
| 14490 | "The value '%s' of the facet is not a valid", |
| 14491 | facet->value); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14492 | } |
| 14493 | ret = -1; |
| 14494 | } |
| 14495 | } |
| 14496 | default: |
| 14497 | break; |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 14498 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14499 | return (ret); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 14500 | } |
| 14501 | |
| 14502 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14503 | * xmlSchemaCheckDefaults: |
| 14504 | * @typeDecl: the schema type definition |
| 14505 | * @ctxt: the schema parser context |
| 14506 | * |
| 14507 | * Checks the default values types, especially for facets |
| 14508 | */ |
| 14509 | static void |
| 14510 | xmlSchemaCheckDefaults(xmlSchemaTypePtr typeDecl, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14511 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14512 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14513 | if (name == NULL) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14514 | name = typeDecl->name; |
| 14515 | /* |
| 14516 | * NOTE: It is intended to use the facets list, instead |
| 14517 | * of facetSet. |
| 14518 | */ |
| 14519 | if (typeDecl->facets != NULL) { |
| 14520 | xmlSchemaFacetPtr facet = typeDecl->facets; |
| 14521 | |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 14522 | /* |
| 14523 | * Temporarily assign the "schema" to the validation context |
| 14524 | * of the parser context. This is needed for NOTATION validation. |
| 14525 | */ |
| 14526 | if (ctxt->vctxt == NULL) { |
| 14527 | if (xmlSchemaCreateVCtxtOnPCtxt(ctxt) == -1) |
| 14528 | return; |
| 14529 | } |
| 14530 | ctxt->vctxt->schema = ctxt->schema; |
| 14531 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14532 | while (facet != NULL) { |
| 14533 | xmlSchemaCheckFacet(facet, typeDecl, ctxt, name); |
| 14534 | facet = facet->next; |
| 14535 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 14536 | |
| 14537 | ctxt->vctxt->schema = NULL; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14538 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14539 | } |
| 14540 | |
| 14541 | /** |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 14542 | * xmlSchemaGetCircModelGrDefRef: |
| 14543 | * @ctxtGr: the searched model group |
| 14544 | * @list: the list of model groups to be processed |
| 14545 | * |
| 14546 | * This one is intended to be used by |
| 14547 | * xmlSchemaCheckGroupDefCircular only. |
| 14548 | * |
| 14549 | * Returns the circular model group definition reference, otherwise NULL. |
| 14550 | */ |
| 14551 | static xmlSchemaTypePtr |
| 14552 | xmlSchemaGetCircModelGrDefRef(xmlSchemaTypePtr ctxtGrDef, |
| 14553 | xmlSchemaTypePtr gr) |
| 14554 | { |
| 14555 | xmlSchemaTypePtr circ = NULL; |
| 14556 | int marked; |
| 14557 | /* |
| 14558 | * We will search for an model group reference which |
| 14559 | * references the context model group definition. |
| 14560 | */ |
| 14561 | while (gr != NULL) { |
| 14562 | if (((gr->type == XML_SCHEMA_TYPE_GROUP) || |
| 14563 | (gr->type == XML_SCHEMA_TYPE_ALL) || |
| 14564 | (gr->type == XML_SCHEMA_TYPE_SEQUENCE) || |
| 14565 | (gr->type == XML_SCHEMA_TYPE_CHOICE)) && |
| 14566 | (gr->subtypes != NULL)) { |
| 14567 | marked = 0; |
| 14568 | if ((gr->type == XML_SCHEMA_TYPE_GROUP) && |
| 14569 | (gr->ref != NULL)) { |
| 14570 | if (gr->subtypes == ctxtGrDef) |
| 14571 | return (gr); |
| 14572 | else if (gr->subtypes->flags & |
| 14573 | XML_SCHEMAS_TYPE_MARKED) { |
| 14574 | gr = gr->next; |
| 14575 | continue; |
| 14576 | } else { |
| 14577 | /* |
| 14578 | * Mark to avoid infinite recursion on |
| 14579 | * circular references not yet examined. |
| 14580 | */ |
| 14581 | gr->subtypes->flags |= XML_SCHEMAS_TYPE_MARKED; |
| 14582 | marked = 1; |
| 14583 | } |
| 14584 | if (gr->subtypes->subtypes != NULL) |
| 14585 | circ = xmlSchemaGetCircModelGrDefRef(ctxtGrDef, |
| 14586 | gr->subtypes->subtypes); |
| 14587 | /* |
| 14588 | * Unmark the visited model group definition. |
| 14589 | */ |
| 14590 | if (marked) |
| 14591 | gr->subtypes->flags ^= XML_SCHEMAS_TYPE_MARKED; |
| 14592 | if (circ != NULL) |
| 14593 | return (circ); |
| 14594 | } else { |
| 14595 | circ = xmlSchemaGetCircModelGrDefRef(ctxtGrDef, |
| 14596 | (xmlSchemaTypePtr) gr->subtypes); |
| 14597 | if (circ != NULL) |
| 14598 | return (circ); |
| 14599 | } |
| 14600 | |
| 14601 | } |
| 14602 | gr = gr->next; |
| 14603 | } |
| 14604 | return (NULL); |
| 14605 | } |
| 14606 | |
| 14607 | /** |
| 14608 | * xmlSchemaCheckGroupDefCircular: |
| 14609 | * attrGr: the model group definition |
| 14610 | * @ctxt: the parser context |
| 14611 | * @name: the name |
| 14612 | * |
| 14613 | * Checks for circular references to model group definitions. |
| 14614 | */ |
| 14615 | static void |
| 14616 | xmlSchemaCheckGroupDefCircular(xmlSchemaTypePtr modelGrDef, |
| 14617 | xmlSchemaParserCtxtPtr ctxt, |
| 14618 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 14619 | { |
| 14620 | /* |
| 14621 | * Schema Component Constraint: Model Group Correct |
| 14622 | * 2 Circular groups are disallowed. That is, within the {particles} |
| 14623 | * of a group there must not be at any depth a particle whose {term} |
| 14624 | * is the group itself. |
| 14625 | */ |
| 14626 | /* |
| 14627 | * NOTE: "gr->subtypes" holds the referenced group. |
| 14628 | */ |
| 14629 | if ((modelGrDef->type != XML_SCHEMA_TYPE_GROUP) || |
| 14630 | ((modelGrDef->flags & XML_SCHEMAS_TYPE_GLOBAL) == 0) || |
| 14631 | (modelGrDef->subtypes == NULL)) |
| 14632 | return; |
| 14633 | else { |
| 14634 | xmlSchemaTypePtr circ; |
| 14635 | |
| 14636 | circ = xmlSchemaGetCircModelGrDefRef(modelGrDef, modelGrDef->subtypes); |
| 14637 | if (circ != NULL) { |
| 14638 | /* |
| 14639 | * TODO: Report the referenced attr group as QName. |
| 14640 | */ |
| 14641 | xmlSchemaPCustomErr(ctxt, |
| 14642 | XML_SCHEMAP_MG_PROPS_CORRECT_2, |
| 14643 | NULL, NULL, circ->node, |
| 14644 | "Circular reference to the model group definition '%s' " |
| 14645 | "defined", modelGrDef->name); |
| 14646 | /* |
| 14647 | * NOTE: We will cut the reference to avoid further |
| 14648 | * confusion of the processor. |
| 14649 | * TODO: SPEC: Does the spec define how to process here? |
| 14650 | */ |
| 14651 | circ->subtypes = NULL; |
| 14652 | } |
| 14653 | } |
| 14654 | } |
| 14655 | |
| 14656 | |
| 14657 | /** |
| 14658 | * xmlSchemaGetCircAttrGrRef: |
| 14659 | * @ctxtGr: the searched attribute group |
| 14660 | * @attr: the current attribute list to be processed |
| 14661 | * |
| 14662 | * This one is intended to be used by |
| 14663 | * xmlSchemaCheckSRCAttributeGroupCircular only. |
| 14664 | * |
| 14665 | * Returns the circular attribute grou reference, otherwise NULL. |
| 14666 | */ |
| 14667 | static xmlSchemaAttributeGroupPtr |
| 14668 | xmlSchemaGetCircAttrGrRef(xmlSchemaAttributeGroupPtr ctxtGr, |
| 14669 | xmlSchemaAttributePtr attr) |
| 14670 | { |
| 14671 | xmlSchemaAttributeGroupPtr circ = NULL, gr; |
| 14672 | int marked; |
| 14673 | /* |
| 14674 | * We will search for an attribute group reference which |
| 14675 | * references the context attribute group. |
| 14676 | */ |
| 14677 | while (attr != NULL) { |
| 14678 | marked = 0; |
| 14679 | if (attr->type == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) { |
| 14680 | gr = (xmlSchemaAttributeGroupPtr) attr; |
| 14681 | if (gr->refItem != NULL) { |
| 14682 | if (gr->refItem == ctxtGr) |
| 14683 | return (gr); |
| 14684 | else if (gr->refItem->flags & |
| 14685 | XML_SCHEMAS_ATTRGROUP_MARKED) { |
| 14686 | attr = attr->next; |
| 14687 | continue; |
| 14688 | } else { |
| 14689 | /* |
| 14690 | * Mark as visited to avoid infinite recursion on |
| 14691 | * circular references not yet examined. |
| 14692 | */ |
| 14693 | gr->refItem->flags |= XML_SCHEMAS_ATTRGROUP_MARKED; |
| 14694 | marked = 1; |
| 14695 | } |
| 14696 | } |
| 14697 | if (gr->attributes != NULL) |
| 14698 | circ = xmlSchemaGetCircAttrGrRef(ctxtGr, gr->attributes); |
| 14699 | /* |
| 14700 | * Unmark the visited group's attributes. |
| 14701 | */ |
| 14702 | if (marked) |
| 14703 | gr->refItem->flags ^= XML_SCHEMAS_ATTRGROUP_MARKED; |
| 14704 | if (circ != NULL) |
| 14705 | return (circ); |
| 14706 | } |
| 14707 | attr = attr->next; |
| 14708 | } |
| 14709 | return (NULL); |
| 14710 | } |
| 14711 | |
| 14712 | /** |
| 14713 | * xmlSchemaCheckSRCAttributeGroupCircular: |
| 14714 | * attrGr: the attribute group definition |
| 14715 | * @ctxt: the parser context |
| 14716 | * @name: the name |
| 14717 | * |
| 14718 | * Checks for circular references of attribute groups. |
| 14719 | */ |
| 14720 | static void |
| 14721 | xmlSchemaCheckAttributeGroupCircular(xmlSchemaAttributeGroupPtr attrGr, |
| 14722 | xmlSchemaParserCtxtPtr ctxt, |
| 14723 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 14724 | { |
| 14725 | /* |
| 14726 | * Schema Representation Constraint: |
| 14727 | * Attribute Group Definition Representation OK |
| 14728 | * 3 Circular group reference is disallowed outside <redefine>. |
| 14729 | * That is, unless this element information item's parent is |
| 14730 | * <redefine>, then among the [children], if any, there must |
| 14731 | * not be an <attributeGroup> with ref [attribute] which resolves |
| 14732 | * to the component corresponding to this <attributeGroup>. Indirect |
| 14733 | * circularity is also ruled out. That is, when QName resolution |
| 14734 | * (Schema Document) (§3.15.3) is applied to a ·QName· arising from |
| 14735 | * any <attributeGroup>s with a ref [attribute] among the [children], |
| 14736 | * it must not be the case that a ·QName· is encountered at any depth |
| 14737 | * which resolves to the component corresponding to this <attributeGroup>. |
| 14738 | */ |
| 14739 | /* |
| 14740 | * Only global components can be referenced. |
| 14741 | */ |
| 14742 | if (((attrGr->flags & XML_SCHEMAS_ATTRGROUP_GLOBAL) == 0) || |
| 14743 | (attrGr->attributes == NULL)) |
| 14744 | return; |
| 14745 | else { |
| 14746 | xmlSchemaAttributeGroupPtr circ; |
| 14747 | |
| 14748 | circ = xmlSchemaGetCircAttrGrRef(attrGr, attrGr->attributes); |
| 14749 | if (circ != NULL) { |
| 14750 | /* |
| 14751 | * TODO: Report the referenced attr group as QName. |
| 14752 | */ |
| 14753 | xmlSchemaPCustomErr(ctxt, |
| 14754 | XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_3, |
| 14755 | NULL, NULL, circ->node, |
| 14756 | "Circular reference to the attribute group '%s' " |
| 14757 | "defined", attrGr->name); |
| 14758 | /* |
| 14759 | * NOTE: We will cut the reference to avoid further |
| 14760 | * confusion of the processor. |
| 14761 | * BADSPEC: The spec should define how to process in this case. |
| 14762 | */ |
| 14763 | circ->attributes = NULL; |
| 14764 | circ->refItem = NULL; |
| 14765 | } |
| 14766 | } |
| 14767 | } |
| 14768 | |
| 14769 | /** |
Daniel Veillard | 13e04c6 | 2002-04-23 17:51:29 +0000 | [diff] [blame] | 14770 | * xmlSchemaAttrGrpFixup: |
| 14771 | * @attrgrpDecl: the schema attribute definition |
| 14772 | * @ctxt: the schema parser context |
| 14773 | * @name: the attribute name |
| 14774 | * |
| 14775 | * Fixes finish doing the computations on the attributes definitions |
| 14776 | */ |
| 14777 | static void |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14778 | xmlSchemaAttrGrpFixup(xmlSchemaAttributeGroupPtr attrgrp, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14779 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name) |
Daniel Veillard | 13e04c6 | 2002-04-23 17:51:29 +0000 | [diff] [blame] | 14780 | { |
| 14781 | if (name == NULL) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14782 | name = attrgrp->name; |
| 14783 | if (attrgrp->attributes != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14784 | return; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14785 | if (attrgrp->ref != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14786 | xmlSchemaAttributeGroupPtr ref; |
Daniel Veillard | 13e04c6 | 2002-04-23 17:51:29 +0000 | [diff] [blame] | 14787 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14788 | ref = xmlSchemaGetAttributeGroup(ctxt->schema, attrgrp->ref, |
| 14789 | attrgrp->refNs); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14790 | if (ref == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14791 | xmlSchemaPResCompAttrErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14792 | XML_SCHEMAP_SRC_RESOLVE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14793 | NULL, (xmlSchemaTypePtr) attrgrp, attrgrp->node, |
| 14794 | "ref", attrgrp->ref, attrgrp->refNs, |
| 14795 | XML_SCHEMA_TYPE_ATTRIBUTEGROUP, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14796 | return; |
| 14797 | } |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 14798 | attrgrp->refItem = ref; |
| 14799 | /* |
| 14800 | * Check for self reference! |
| 14801 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14802 | xmlSchemaAttrGrpFixup(ref, ctxt, NULL); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14803 | attrgrp->attributes = ref->attributes; |
| 14804 | attrgrp->attributeWildcard = ref->attributeWildcard; |
| 14805 | } |
Daniel Veillard | 13e04c6 | 2002-04-23 17:51:29 +0000 | [diff] [blame] | 14806 | } |
| 14807 | |
| 14808 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14809 | * xmlSchemaAttrCheckValConstr: |
| 14810 | * @item: an schema attribute declaration/use |
| 14811 | * @ctxt: a schema parser context |
| 14812 | * @name: the name of the attribute |
| 14813 | * |
| 14814 | * Validates the value constraints of an attribute declaration/use. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14815 | * |
| 14816 | * Fixes finish doing the computations on the attributes definitions |
| 14817 | */ |
| 14818 | static void |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14819 | xmlSchemaCheckAttrValConstr(xmlSchemaAttributePtr item, |
| 14820 | xmlSchemaParserCtxtPtr ctxt, |
| 14821 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 14822 | { |
| 14823 | |
| 14824 | /* |
| 14825 | * a-props-correct |
| 14826 | * Schema Component Constraint: Attribute Declaration Properties Correct |
| 14827 | * |
| 14828 | * 2 if there is a {value constraint}, the canonical lexical |
| 14829 | * representation of its value must be ·valid· with respect |
| 14830 | * to the {type definition} as defined in String Valid (§3.14.4). |
| 14831 | */ |
| 14832 | |
| 14833 | if (item->defValue != NULL) { |
| 14834 | int ret; |
| 14835 | xmlNodePtr node; |
| 14836 | xmlSchemaTypePtr type; |
| 14837 | |
| 14838 | if (item->subtypes == NULL) { |
| 14839 | xmlSchemaPErr(ctxt, item->node, |
| 14840 | XML_SCHEMAP_INTERNAL, |
| 14841 | "Internal error: xmlSchemaCheckAttrValConstr, " |
| 14842 | "type is missing... skipping validation of " |
| 14843 | "value constraint", NULL, NULL); |
| 14844 | return; |
| 14845 | } |
| 14846 | |
| 14847 | /* |
| 14848 | * TODO: Try to avoid creating a new context. |
| 14849 | * TODO: This all is not very performant. |
| 14850 | */ |
| 14851 | type = item->subtypes; |
| 14852 | /* |
| 14853 | * Ensure there's validation context. |
| 14854 | */ |
| 14855 | if (ctxt->vctxt == NULL) { |
| 14856 | if (xmlSchemaCreateVCtxtOnPCtxt(ctxt) == -1) { |
| 14857 | xmlSchemaPErr(ctxt, item->node, |
| 14858 | XML_SCHEMAP_INTERNAL, |
| 14859 | "Internal error: xmlSchemaCheckAttrValConstr, " |
| 14860 | "creating a new validation context.\n", |
| 14861 | NULL, NULL); |
| 14862 | return; |
| 14863 | } |
| 14864 | } |
| 14865 | |
| 14866 | if (item->flags & XML_SCHEMAS_ATTR_FIXED) |
| 14867 | node = (xmlNodePtr) xmlHasProp(item->node, BAD_CAST "fixed"); |
| 14868 | else |
| 14869 | node = (xmlNodePtr) xmlHasProp(item->node, BAD_CAST "default"); |
| 14870 | ctxt->vctxt->node = node; |
| 14871 | ctxt->vctxt->cur = NULL; |
| 14872 | /* |
| 14873 | * NOTE: This call does not check the content nodes, |
| 14874 | * since they are not available: |
| 14875 | * facet->node is just the node holding the facet |
| 14876 | * definition, *not* the attribute holding the *value* |
| 14877 | * of the facet. |
| 14878 | */ |
| 14879 | ret = xmlSchemaValidateSimpleTypeValue(ctxt->vctxt, type, |
| 14880 | item->defValue, 0, 1, 1, 0); |
| 14881 | if (ret == 0) { |
| 14882 | /* |
| 14883 | * Store the computed value. |
| 14884 | */ |
| 14885 | item->defVal = ctxt->vctxt->value; |
| 14886 | ctxt->vctxt->value = NULL; |
| 14887 | } else if (ret > 0) { |
| 14888 | if (ctxt != NULL) { |
| 14889 | xmlSchemaPSimpleTypeErr(ctxt, |
| 14890 | XML_SCHEMAP_A_PROPS_CORRECT_2, |
| 14891 | NULL, NULL, node, |
| 14892 | type, NULL, item->defValue, |
| 14893 | NULL, NULL, NULL); |
| 14894 | } |
| 14895 | } else if (ret < 0) { |
| 14896 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, |
| 14897 | NULL, NULL, node, |
| 14898 | "Internal error: xmlSchemaAttrCheckValConstr, " |
| 14899 | "failed to validate the value constraint of the " |
| 14900 | "attribute decl/use against the type '%s'", |
| 14901 | type->name); |
| 14902 | } |
| 14903 | } |
| 14904 | } |
| 14905 | |
| 14906 | #if 0 /* Not used yet. */ |
| 14907 | static int |
| 14908 | xmlSchemaCheckElemPropsCorrect(xmlSchemaParserCtxtPtr ctxt, |
| 14909 | xmlSchemaElementPtr edecl) |
| 14910 | { |
| 14911 | /* |
| 14912 | * TODO: 1 The values of the properties of an element declaration must be as |
| 14913 | * described in the property tableau in The Element Declaration Schema |
| 14914 | * Component (§3.3.1), modulo the impact of Missing Sub-components (§5.3). |
| 14915 | */ |
| 14916 | /* |
| 14917 | * 2 If there is a {value constraint}, the canonical lexical |
| 14918 | * representation of its value must be ·valid· with respect to the {type |
| 14919 | * definition} as defined in Element Default Valid (Immediate) (§3.3.6). |
| 14920 | * |
| 14921 | * NOTE: This is done in xmlSchemaCheckElemValConstr. |
| 14922 | */ |
| 14923 | /* |
| 14924 | * 3 If there is a non-·absent· {substitution group affiliation}, |
| 14925 | * then {scope} must be global. |
| 14926 | * |
| 14927 | * NOTE: This is done in xmlSchemaParseElement. |
| 14928 | * TODO: Move it to this layer here. |
| 14929 | */ |
| 14930 | /* |
| 14931 | * TODO: 4 If there is a {substitution group affiliation}, the {type definition} |
| 14932 | * of the element declaration must be validly derived from the {type |
| 14933 | * definition} of the {substitution group affiliation}, given the value |
| 14934 | * of the {substitution group exclusions} of the {substitution group |
| 14935 | * affiliation}, as defined in Type Derivation OK (Complex) (§3.4.6) |
| 14936 | * (if the {type definition} is complex) or as defined in |
| 14937 | * Type Derivation OK (Simple) (§3.14.6) (if the {type definition} is |
| 14938 | * simple). |
| 14939 | */ |
| 14940 | /* |
| 14941 | * TODO: 5 If the {type definition} or {type definition}'s {content type} |
| 14942 | * is or is derived from ID then there must not be a {value constraint}. |
| 14943 | * Note: The use of ID as a type definition for elements goes beyond |
| 14944 | * XML 1.0, and should be avoided if backwards compatibility is desired |
| 14945 | */ |
| 14946 | /* |
| 14947 | * TODO: 6 Circular substitution groups are disallowed. That is, it must not |
| 14948 | * be possible to return to an element declaration by repeatedly following |
| 14949 | * the {substitution group affiliation} property. |
| 14950 | */ |
| 14951 | } |
| 14952 | #endif |
| 14953 | |
| 14954 | /** |
| 14955 | * xmlSchemaCheckElemValConstr: |
| 14956 | * @item: an schema element declaration/particle |
| 14957 | * @ctxt: a schema parser context |
| 14958 | * @name: the name of the attribute |
| 14959 | * |
| 14960 | * Validates the value constraints of an element declaration. |
| 14961 | * |
| 14962 | * Fixes finish doing the computations on the element declarations. |
| 14963 | */ |
| 14964 | static void |
| 14965 | xmlSchemaCheckElemValConstr(xmlSchemaElementPtr decl, |
| 14966 | xmlSchemaParserCtxtPtr ctxt, |
| 14967 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 14968 | { |
| 14969 | if (decl->value != NULL) { |
| 14970 | int ret; |
| 14971 | xmlNodePtr node = NULL; |
| 14972 | xmlSchemaTypePtr type; |
| 14973 | |
| 14974 | /* |
| 14975 | * 2 If there is a {value constraint}, the canonical lexical |
| 14976 | * representation of its value must be ·valid· with respect to the {type |
| 14977 | * definition} as defined in Element Default Valid (Immediate) (§3.3.6). |
| 14978 | */ |
| 14979 | if (decl->subtypes == NULL) { |
| 14980 | xmlSchemaPErr(ctxt, decl->node, |
| 14981 | XML_SCHEMAP_INTERNAL, |
| 14982 | "Internal error: xmlSchemaCheckElemValConstr, " |
| 14983 | "type is missing... skipping validation of " |
| 14984 | "the value constraint", NULL, NULL); |
| 14985 | return; |
| 14986 | } |
| 14987 | /* |
| 14988 | * Ensure there's a validation context. |
| 14989 | */ |
| 14990 | if (xmlSchemaCreateVCtxtOnPCtxt(ctxt) == -1) |
| 14991 | return; |
| 14992 | |
| 14993 | type = decl->subtypes; |
| 14994 | |
| 14995 | if (decl->node != NULL) { |
| 14996 | if (decl->flags & XML_SCHEMAS_ELEM_FIXED) |
| 14997 | node = (xmlNodePtr) xmlHasProp(decl->node, BAD_CAST "fixed"); |
| 14998 | else |
| 14999 | node = (xmlNodePtr) xmlHasProp(decl->node, BAD_CAST "default"); |
| 15000 | } |
| 15001 | ctxt->vctxt->node = node; |
| 15002 | ctxt->vctxt->cur = NULL; |
| 15003 | ret = xmlSchemaCheckCOSValidDefault(ctxt, ctxt->vctxt, type, decl->value, |
| 15004 | node); |
| 15005 | if (ret == 0) { |
| 15006 | /* |
| 15007 | * Consume the computed value. |
| 15008 | */ |
| 15009 | decl->defVal = ctxt->vctxt->value; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 15010 | ctxt->vctxt->value = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15011 | } else if (ret < 0) { |
| 15012 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, |
| 15013 | NULL, NULL, node, |
| 15014 | "Internal error: xmlSchemaElemCheckValConstr, " |
| 15015 | "failed to validate the value constraint of the " |
| 15016 | "element declaration '%s'", |
| 15017 | decl->name); |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 15018 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15019 | } |
| 15020 | } |
| 15021 | |
| 15022 | /** |
| 15023 | * xmlSchemaAttrFixup: |
| 15024 | * @item: an schema attribute declaration/use. |
| 15025 | * @ctxt: a schema parser context |
| 15026 | * @name: the name of the attribute |
| 15027 | * |
| 15028 | * Fixes finish doing the computations on attribute declarations/uses. |
| 15029 | */ |
| 15030 | static void |
| 15031 | xmlSchemaAttrFixup(xmlSchemaAttributePtr item, |
| 15032 | xmlSchemaParserCtxtPtr ctxt, |
| 15033 | const xmlChar * name ATTRIBUTE_UNUSED) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15034 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15035 | /* |
| 15036 | * TODO: If including this is done twice (!) for every attribute. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15037 | * -> Hmm, check if this is still done. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15038 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15039 | /* |
| 15040 | * The simple type definition corresponding to the <simpleType> element |
| 15041 | * information item in the [children], if present, otherwise the simple |
| 15042 | * type definition ·resolved· to by the ·actual value· of the type |
| 15043 | * [attribute], if present, otherwise the ·simple ur-type definition·. |
| 15044 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15045 | if (item->flags & XML_SCHEMAS_ATTR_INTERNAL_RESOLVED) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15046 | return; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15047 | item->flags |= XML_SCHEMAS_ATTR_INTERNAL_RESOLVED; |
| 15048 | if (item->subtypes != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15049 | return; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15050 | if (item->typeName != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15051 | xmlSchemaTypePtr type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15052 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15053 | type = xmlSchemaGetType(ctxt->schema, item->typeName, |
| 15054 | item->typeNs); |
| 15055 | if ((type == NULL) || (! IS_SIMPLE_TYPE(type))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15056 | xmlSchemaPResCompAttrErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15057 | XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15058 | NULL, (xmlSchemaTypePtr) item, item->node, |
| 15059 | "type", item->typeName, item->typeNs, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15060 | XML_SCHEMA_TYPE_SIMPLE, NULL); |
| 15061 | } else |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15062 | item->subtypes = type; |
| 15063 | |
| 15064 | } else if (item->ref != NULL) { |
| 15065 | xmlSchemaAttributePtr decl; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15066 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15067 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15068 | * We have an attribute use here; assign the referenced |
| 15069 | * attribute declaration. |
| 15070 | */ |
| 15071 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15072 | * TODO: Evaluate, what errors could occur if the declaration is not |
| 15073 | * found. It might be possible that the "typefixup" might crash if |
| 15074 | * no ref declaration was found. |
| 15075 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15076 | decl = xmlSchemaGetAttribute(ctxt->schema, item->ref, item->refNs); |
| 15077 | if (decl == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15078 | xmlSchemaPResCompAttrErr(ctxt, |
| 15079 | XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15080 | NULL, (xmlSchemaTypePtr) item, item->node, |
| 15081 | "ref", item->ref, item->refNs, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15082 | XML_SCHEMA_TYPE_ATTRIBUTE, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15083 | return; |
| 15084 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15085 | item->refDecl = decl; |
| 15086 | xmlSchemaAttrFixup(decl, ctxt, NULL); |
| 15087 | |
| 15088 | item->subtypes = decl->subtypes; |
| 15089 | /* |
| 15090 | * Attribute Use Correct |
| 15091 | * au-props-correct.2: If the {attribute declaration} has a fixed |
| 15092 | * {value constraint}, then if the attribute use itself has a |
| 15093 | * {value constraint}, it must also be fixed and its value must match |
| 15094 | * that of the {attribute declaration}'s {value constraint}. |
| 15095 | */ |
| 15096 | if ((decl->flags & XML_SCHEMAS_ATTR_FIXED) && |
| 15097 | (item->defValue != NULL)) { |
| 15098 | if (((item->flags & XML_SCHEMAS_ATTR_FIXED) == 0) || |
| 15099 | (!xmlStrEqual(item->defValue, decl->defValue))) { |
| 15100 | xmlSchemaPCustomErr(ctxt, |
| 15101 | XML_SCHEMAP_AU_PROPS_CORRECT_2, |
| 15102 | NULL, NULL, item->node, |
| 15103 | "The value constraint must be fixed " |
| 15104 | "and match the referenced attribute " |
| 15105 | "declarations's value constraint '%s'", |
| 15106 | decl->defValue); |
| 15107 | } |
| 15108 | /* |
| 15109 | * FUTURE: One should change the values of the attr. use |
| 15110 | * if ever validation should be attempted even if the |
| 15111 | * schema itself was not fully valid. |
| 15112 | */ |
| 15113 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15114 | } else { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15115 | item->subtypes = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 15116 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15117 | } |
| 15118 | |
| 15119 | /** |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15120 | * xmlSchemaResolveIDCKeyRef: |
| 15121 | * @idc: the identity-constraint definition |
| 15122 | * @ctxt: the schema parser context |
| 15123 | * @name: the attribute name |
| 15124 | * |
| 15125 | * Resolve keyRef references to key/unique IDCs. |
| 15126 | */ |
| 15127 | static void |
| 15128 | xmlSchemaResolveIDCKeyRef(xmlSchemaIDCPtr idc, |
| 15129 | xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 15130 | const xmlChar * name ATTRIBUTE_UNUSED) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15131 | { |
| 15132 | if (idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) |
| 15133 | return; |
| 15134 | if (idc->ref->name != NULL) { |
| 15135 | idc->ref->item = (xmlSchemaBasicItemPtr) xmlHashLookup2( |
| 15136 | ctxt->schema->idcDef, |
| 15137 | idc->ref->name, |
| 15138 | idc->ref->targetNamespace); |
| 15139 | if (idc->ref->item == NULL) { |
| 15140 | /* |
| 15141 | * TODO: It is actually not an error to fail to resolve. |
| 15142 | */ |
| 15143 | xmlSchemaPResCompAttrErr(ctxt, |
| 15144 | XML_SCHEMAP_SRC_RESOLVE, |
| 15145 | NULL, (xmlSchemaTypePtr) idc, idc->node, |
| 15146 | "refer", idc->ref->name, |
| 15147 | idc->ref->targetNamespace, |
| 15148 | XML_SCHEMA_TYPE_IDC_KEYREF, NULL); |
| 15149 | return; |
| 15150 | } |
| 15151 | } |
| 15152 | } |
| 15153 | |
| 15154 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15155 | * xmlSchemaParse: |
| 15156 | * @ctxt: a schema validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15157 | * |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 15158 | * parse a schema definition resource and build an internal |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15159 | * XML Shema struture which can be used to validate instances. |
| 15160 | * *WARNING* this interface is highly subject to change |
| 15161 | * |
| 15162 | * Returns the internal XML Schema structure built from the resource or |
| 15163 | * NULL in case of error |
| 15164 | */ |
| 15165 | xmlSchemaPtr |
| 15166 | xmlSchemaParse(xmlSchemaParserCtxtPtr ctxt) |
| 15167 | { |
| 15168 | xmlSchemaPtr ret = NULL; |
| 15169 | xmlDocPtr doc; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 15170 | xmlNodePtr root; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 15171 | int preserve = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15172 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15173 | /* |
| 15174 | * This one is used if the schema to be parsed was specified via |
| 15175 | * the API; i.e. not automatically by the validated instance document. |
| 15176 | */ |
| 15177 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15178 | xmlSchemaInitTypes(); |
| 15179 | |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 15180 | if (ctxt == NULL) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15181 | return (NULL); |
| 15182 | |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 15183 | ctxt->nberrors = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15184 | ctxt->counter = 0; |
| 15185 | ctxt->container = NULL; |
| 15186 | |
| 15187 | /* |
| 15188 | * First step is to parse the input document into an DOM/Infoset |
| 15189 | */ |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 15190 | if (ctxt->URL != NULL) { |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 15191 | doc = xmlReadFile((const char *) ctxt->URL, NULL, |
| 15192 | SCHEMAS_PARSE_OPTIONS); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15193 | if (doc == NULL) { |
| 15194 | xmlSchemaPErr(ctxt, NULL, |
| 15195 | XML_SCHEMAP_FAILED_LOAD, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15196 | "xmlSchemaParse: could not load '%s'.\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15197 | ctxt->URL, NULL); |
| 15198 | return (NULL); |
| 15199 | } |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 15200 | } else if (ctxt->buffer != NULL) { |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 15201 | doc = xmlReadMemory(ctxt->buffer, ctxt->size, NULL, NULL, |
| 15202 | SCHEMAS_PARSE_OPTIONS); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15203 | if (doc == NULL) { |
| 15204 | xmlSchemaPErr(ctxt, NULL, |
| 15205 | XML_SCHEMAP_FAILED_PARSE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15206 | "xmlSchemaParse: could not parse.\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15207 | NULL, NULL); |
| 15208 | return (NULL); |
| 15209 | } |
| 15210 | doc->URL = xmlStrdup(BAD_CAST "in_memory_buffer"); |
Daniel Veillard | 6576528 | 2004-01-08 16:59:30 +0000 | [diff] [blame] | 15211 | ctxt->URL = xmlDictLookup(ctxt->dict, BAD_CAST "in_memory_buffer", -1); |
Daniel Veillard | 9d75150 | 2003-10-29 13:21:47 +0000 | [diff] [blame] | 15212 | } else if (ctxt->doc != NULL) { |
| 15213 | doc = ctxt->doc; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 15214 | preserve = 1; |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 15215 | } else { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15216 | xmlSchemaPErr(ctxt, NULL, |
| 15217 | XML_SCHEMAP_NOTHING_TO_PARSE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15218 | "xmlSchemaParse: could not parse.\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15219 | NULL, NULL); |
| 15220 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15221 | } |
| 15222 | |
| 15223 | /* |
| 15224 | * Then extract the root and Schema parse it |
| 15225 | */ |
| 15226 | root = xmlDocGetRootElement(doc); |
| 15227 | if (root == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15228 | xmlSchemaPErr(ctxt, (xmlNodePtr) doc, |
| 15229 | XML_SCHEMAP_NOROOT, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15230 | "The schema has no document element.\n", NULL, NULL); |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 15231 | if (!preserve) { |
| 15232 | xmlFreeDoc(doc); |
| 15233 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15234 | return (NULL); |
| 15235 | } |
| 15236 | |
| 15237 | /* |
| 15238 | * Remove all the blank text nodes |
| 15239 | */ |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 15240 | xmlSchemaCleanupDoc(ctxt, root); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15241 | |
| 15242 | /* |
| 15243 | * Then do the parsing for good |
| 15244 | */ |
| 15245 | ret = xmlSchemaParseSchema(ctxt, root); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 15246 | if (ret == NULL) { |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 15247 | if (!preserve) { |
| 15248 | xmlFreeDoc(doc); |
| 15249 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15250 | return (NULL); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 15251 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15252 | ret->doc = doc; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 15253 | ret->preserve = preserve; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15254 | ctxt->schema = ret; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15255 | ctxt->ctxtType = NULL; |
| 15256 | ctxt->parentItem = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15257 | /* |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 15258 | * Then fixup all attributes declarations |
| 15259 | */ |
| 15260 | xmlHashScan(ret->attrDecl, (xmlHashScanner) xmlSchemaAttrFixup, ctxt); |
| 15261 | |
| 15262 | /* |
| 15263 | * Then fixup all attributes group declarations |
| 15264 | */ |
| 15265 | xmlHashScan(ret->attrgrpDecl, (xmlHashScanner) xmlSchemaAttrGrpFixup, |
| 15266 | ctxt); |
| 15267 | |
| 15268 | /* |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15269 | * Resolve identity-constraint keyRefs. |
| 15270 | */ |
| 15271 | xmlHashScan(ret->idcDef, (xmlHashScanner) xmlSchemaResolveIDCKeyRef, ctxt); |
| 15272 | |
| 15273 | /* |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 15274 | * Check attribute groups for circular references. |
| 15275 | */ |
| 15276 | xmlHashScan(ret->attrgrpDecl, (xmlHashScanner) |
| 15277 | xmlSchemaCheckAttributeGroupCircular, ctxt); |
| 15278 | |
| 15279 | /* |
| 15280 | * Then fixup all model group definitions. |
| 15281 | */ |
| 15282 | xmlHashScan(ret->groupDecl, (xmlHashScanner) xmlSchemaGroupDefFixup, ctxt); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15283 | |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 15284 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15285 | * Then fix references of element declaration; apply constraints. |
| 15286 | */ |
| 15287 | xmlHashScanFull(ret->elemDecl, |
| 15288 | (xmlHashScannerFull) xmlSchemaRefFixupCallback, ctxt); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15289 | |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 15290 | /* |
| 15291 | * We will stop here if the schema was not valid to avoid internal errors |
| 15292 | * on missing sub-components. This is not conforming to the spec, since it |
| 15293 | * allows missing components, but it might make further processing crash. |
| 15294 | * So see it as a very strict handling, which might be made more lax in the |
| 15295 | * future. |
| 15296 | */ |
| 15297 | if (ctxt->nberrors != 0) |
| 15298 | goto exit; |
| 15299 | /* |
| 15300 | * Then fixup all types properties |
| 15301 | */ |
| 15302 | xmlHashScan(ret->typeDecl, (xmlHashScanner) xmlSchemaTypeFixup, ctxt); |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 15303 | /* |
| 15304 | * Check model groups defnitions for circular references. |
| 15305 | */ |
| 15306 | xmlHashScan(ret->groupDecl, (xmlHashScanner) |
| 15307 | xmlSchemaCheckGroupDefCircular, ctxt); |
| 15308 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15309 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15310 | * Then build the content model for all complex types |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15311 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15312 | xmlHashScan(ret->typeDecl, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15313 | (xmlHashScanner) xmlSchemaBuildContentModel, ctxt); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15314 | |
| 15315 | /* |
| 15316 | * Then check the defaults part of the type like facets values |
| 15317 | */ |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 15318 | /* OLD: xmlHashScan(ret->typeDecl, (xmlHashScanner) xmlSchemaCheckDefaults, ctxt); */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15319 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15320 | /* |
| 15321 | * Validate the value constraint of attribute declarations/uses. |
| 15322 | */ |
| 15323 | xmlHashScan(ret->attrDecl, (xmlHashScanner) xmlSchemaCheckAttrValConstr, ctxt); |
| 15324 | |
| 15325 | /* |
| 15326 | * Validate the value constraint of element declarations. |
| 15327 | */ |
| 15328 | xmlHashScan(ret->elemDecl, (xmlHashScanner) xmlSchemaCheckElemValConstr, ctxt); |
| 15329 | |
Kasimier T. Buchcik | b474fa4 | 2005-03-11 12:34:42 +0000 | [diff] [blame] | 15330 | exit: |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 15331 | if (ctxt->nberrors != 0) { |
| 15332 | xmlSchemaFree(ret); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15333 | ret = NULL; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 15334 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15335 | return (ret); |
| 15336 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15337 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15338 | /** |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 15339 | * xmlSchemaSetParserErrors: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15340 | * @ctxt: a schema validation context |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 15341 | * @err: the error callback |
| 15342 | * @warn: the warning callback |
| 15343 | * @ctx: contextual data for the callbacks |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15344 | * |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 15345 | * Set the callback functions used to handle errors for a validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15346 | */ |
| 15347 | void |
| 15348 | xmlSchemaSetParserErrors(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15349 | xmlSchemaValidityErrorFunc err, |
| 15350 | xmlSchemaValidityWarningFunc warn, void *ctx) |
| 15351 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15352 | if (ctxt == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15353 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15354 | ctxt->error = err; |
| 15355 | ctxt->warning = warn; |
| 15356 | ctxt->userData = ctx; |
| 15357 | } |
| 15358 | |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 15359 | /** |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 15360 | * xmlSchemaGetParserErrors: |
| 15361 | * @ctxt: a XMl-Schema parser context |
| 15362 | * @err: the error callback result |
| 15363 | * @warn: the warning callback result |
| 15364 | * @ctx: contextual data for the callbacks result |
| 15365 | * |
| 15366 | * Get the callback information used to handle errors for a parser context |
| 15367 | * |
| 15368 | * Returns -1 in case of failure, 0 otherwise |
| 15369 | */ |
| 15370 | int |
| 15371 | xmlSchemaGetParserErrors(xmlSchemaParserCtxtPtr ctxt, |
| 15372 | xmlSchemaValidityErrorFunc * err, |
| 15373 | xmlSchemaValidityWarningFunc * warn, void **ctx) |
| 15374 | { |
| 15375 | if (ctxt == NULL) |
| 15376 | return(-1); |
| 15377 | if (err != NULL) |
| 15378 | *err = ctxt->error; |
| 15379 | if (warn != NULL) |
| 15380 | *warn = ctxt->warning; |
| 15381 | if (ctx != NULL) |
| 15382 | *ctx = ctxt->userData; |
| 15383 | return(0); |
| 15384 | } |
| 15385 | |
| 15386 | /** |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 15387 | * xmlSchemaFacetTypeToString: |
| 15388 | * @type: the facet type |
| 15389 | * |
| 15390 | * Convert the xmlSchemaTypeType to a char string. |
| 15391 | * |
| 15392 | * Returns the char string representation of the facet type if the |
| 15393 | * type is a facet and an "Internal Error" string otherwise. |
| 15394 | */ |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 15395 | static const xmlChar * |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 15396 | xmlSchemaFacetTypeToString(xmlSchemaTypeType type) |
| 15397 | { |
| 15398 | switch (type) { |
| 15399 | case XML_SCHEMA_FACET_PATTERN: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 15400 | return (BAD_CAST "pattern"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15401 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 15402 | return (BAD_CAST "maxExclusive"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15403 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 15404 | return (BAD_CAST "maxInclusive"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15405 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 15406 | return (BAD_CAST "minExclusive"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15407 | case XML_SCHEMA_FACET_MININCLUSIVE: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 15408 | return (BAD_CAST "minInclusive"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15409 | case XML_SCHEMA_FACET_WHITESPACE: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 15410 | return (BAD_CAST "whiteSpace"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15411 | case XML_SCHEMA_FACET_ENUMERATION: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 15412 | return (BAD_CAST "enumeration"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15413 | case XML_SCHEMA_FACET_LENGTH: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 15414 | return (BAD_CAST "length"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15415 | case XML_SCHEMA_FACET_MAXLENGTH: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 15416 | return (BAD_CAST "maxLength"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15417 | case XML_SCHEMA_FACET_MINLENGTH: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 15418 | return (BAD_CAST "minLength"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15419 | case XML_SCHEMA_FACET_TOTALDIGITS: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 15420 | return (BAD_CAST "totalDigits"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15421 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 15422 | return (BAD_CAST "fractionDigits"); |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 15423 | default: |
| 15424 | break; |
| 15425 | } |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 15426 | return (BAD_CAST "Internal Error"); |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 15427 | } |
| 15428 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15429 | static int |
| 15430 | xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type) |
| 15431 | { |
| 15432 | xmlSchemaTypePtr anc; |
| 15433 | |
| 15434 | /* |
| 15435 | * The normalization type can be changed only for types which are derived |
| 15436 | * from xsd:string. |
| 15437 | */ |
| 15438 | if (type->type == XML_SCHEMA_TYPE_BASIC) { |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 15439 | if (type->builtInType == XML_SCHEMAS_STRING) |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 15440 | return(XML_SCHEMAS_FACET_PRESERVE); |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 15441 | else if (type->builtInType == XML_SCHEMAS_NORMSTRING) |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 15442 | return(XML_SCHEMAS_FACET_REPLACE); |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 15443 | else if (type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) |
| 15444 | /* |
| 15445 | * Note that we assume a whitespace of preserve for anySimpleType. |
| 15446 | */ |
| 15447 | return(XML_SCHEMAS_FACET_PRESERVE); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15448 | else { |
| 15449 | /* |
| 15450 | * For all ·atomic· datatypes other than string (and types ·derived· |
| 15451 | * by ·restriction· from it) the value of whiteSpace is fixed to |
| 15452 | * collapse |
| 15453 | */ |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 15454 | return(XML_SCHEMAS_FACET_COLLAPSE); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15455 | } |
| 15456 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 15457 | /* |
| 15458 | * For list types the facet "whiteSpace" is fixed to "collapse". |
| 15459 | */ |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 15460 | return (XML_SCHEMAS_FACET_COLLAPSE); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15461 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 15462 | return (XML_SCHEMAS_FACET_UNKNOWN); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15463 | } else if (type->facetSet != NULL) { |
| 15464 | xmlSchemaTypePtr anyST; |
| 15465 | xmlSchemaFacetLinkPtr lin; |
| 15466 | |
| 15467 | /* |
| 15468 | * Atomic types. |
| 15469 | */ |
| 15470 | anyST = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 15471 | anc = type->baseType; |
| 15472 | do { |
| 15473 | /* |
| 15474 | * For all ·atomic· datatypes other than string (and types ·derived· |
| 15475 | * by ·restriction· from it) the value of whiteSpace is fixed to |
| 15476 | * collapse |
| 15477 | */ |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 15478 | if ((anc->builtInType == XML_SCHEMAS_STRING) || |
| 15479 | (anc->builtInType == XML_SCHEMAS_NORMSTRING)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15480 | |
| 15481 | lin = type->facetSet; |
| 15482 | do { |
| 15483 | if (lin->facet->type == XML_SCHEMA_FACET_WHITESPACE) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 15484 | return(lin->facet->whitespace); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15485 | break; |
| 15486 | } |
| 15487 | lin = lin->next; |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 15488 | } while (lin != NULL); |
| 15489 | if (anc->builtInType == XML_SCHEMAS_NORMSTRING) |
| 15490 | return (XML_SCHEMAS_FACET_REPLACE); |
| 15491 | else |
| 15492 | return (XML_SCHEMAS_FACET_PRESERVE); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15493 | } |
| 15494 | anc = anc->baseType; |
| 15495 | } while (anc != anyST); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 15496 | return (XML_SCHEMAS_FACET_COLLAPSE); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15497 | } |
| 15498 | return (-1); |
| 15499 | } |
| 15500 | |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 15501 | /** |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 15502 | * xmlSchemaValidateFacetsInternal: |
| 15503 | * @ctxt: a schema validation context |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15504 | * @type: the type holding the facets |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 15505 | * @facets: the list of facets to check |
| 15506 | * @value: the lexical repr of the value to validate |
| 15507 | * @val: the precomputed value |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 15508 | * @fireErrors: if 0, only internal errors will be fired; |
| 15509 | * otherwise all errors will be fired. |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 15510 | * |
| 15511 | * Check a value against all facet conditions |
| 15512 | * |
| 15513 | * Returns 0 if the element is schemas valid, a positive error code |
| 15514 | * number otherwise and -1 in case of internal or API error. |
| 15515 | */ |
| 15516 | static int |
| 15517 | xmlSchemaValidateFacetsInternal(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15518 | xmlSchemaTypePtr type, |
| 15519 | const xmlChar * value, |
| 15520 | unsigned long length, |
| 15521 | int fireErrors) |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 15522 | { |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 15523 | int ret = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15524 | xmlNodePtr node; |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 15525 | xmlSchemaTypePtr biType; /* The build-in type. */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15526 | xmlSchemaTypePtr tmpType; |
| 15527 | xmlSchemaFacetLinkPtr facetLink; |
Daniel Veillard | c7e3cc4 | 2004-09-28 12:33:52 +0000 | [diff] [blame] | 15528 | int retFacet; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15529 | xmlSchemaFacetPtr facet; |
| 15530 | unsigned long len = 0; |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 15531 | xmlSchemaWhitespaceValueType ws; |
| 15532 | |
| 15533 | if (type->type == XML_SCHEMA_TYPE_COMPLEX) { |
| 15534 | xmlSchemaTypePtr tp; |
| 15535 | /* |
| 15536 | * TODO: Get rid of this case: the complex type still holds facets in some |
| 15537 | * cases. |
| 15538 | */ |
| 15539 | tp = xmlSchemaGetSimpleContentType(type); |
| 15540 | ws = (xmlSchemaWhitespaceValueType) xmlSchemaGetWhiteSpaceFacetValue(tp); |
| 15541 | } else |
| 15542 | ws = (xmlSchemaWhitespaceValueType) xmlSchemaGetWhiteSpaceFacetValue(type); |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 15543 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15544 | #ifdef DEBUG_UNION_VALIDATION |
| 15545 | printf("Facets of type: '%s'\n", (const char *) type->name); |
| 15546 | printf(" fireErrors: %d\n", fireErrors); |
| 15547 | #endif |
| 15548 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15549 | node = ctxt->node; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15550 | /* |
| 15551 | * NOTE: Do not jump away, if the facetSet of the given type is |
| 15552 | * empty: until now, "pattern" facets of the *base types* need to |
| 15553 | * be checked as well. |
| 15554 | */ |
| 15555 | biType = type->baseType; |
| 15556 | while ((biType != NULL) && (biType->type != XML_SCHEMA_TYPE_BASIC)) |
| 15557 | biType = biType->baseType; |
| 15558 | if (biType == NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15559 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15560 | "Internal error: xmlSchemaValidateFacetsInternal, " |
| 15561 | "the base type axis of the given type '%s' does not resolve to " |
| 15562 | "a built-in type.\n", |
| 15563 | type->name, NULL); |
| 15564 | return (-1); |
| 15565 | } |
| 15566 | |
| 15567 | if (type->facetSet != NULL) { |
| 15568 | facetLink = type->facetSet; |
| 15569 | while (facetLink != NULL) { |
| 15570 | facet = facetLink->facet; |
| 15571 | /* |
| 15572 | * Skip the pattern "whiteSpace": it is used to |
| 15573 | * format the character content beforehand. |
| 15574 | */ |
| 15575 | switch (facet->type) { |
| 15576 | case XML_SCHEMA_FACET_WHITESPACE: |
| 15577 | case XML_SCHEMA_FACET_PATTERN: |
| 15578 | case XML_SCHEMA_FACET_ENUMERATION: |
| 15579 | break; |
| 15580 | case XML_SCHEMA_FACET_LENGTH: |
| 15581 | case XML_SCHEMA_FACET_MINLENGTH: |
| 15582 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 15583 | if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 15584 | ret = xmlSchemaValidateListSimpleTypeFacet(facet, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 15585 | value, length, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15586 | len = length; |
| 15587 | } else |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 15588 | ret = xmlSchemaValidateLengthFacetWhtsp(facet, |
| 15589 | (xmlSchemaValType) biType->builtInType, |
| 15590 | value, ctxt->value, &len, ws); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15591 | break; |
| 15592 | default: |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 15593 | ret = xmlSchemaValidateFacetWhtsp(facet, ws, |
| 15594 | biType->builtInType, value, ctxt->value, ws); |
| 15595 | /* |
| 15596 | * ret = xmlSchemaValidateFacet(biType, facet, value, |
| 15597 | * ctxt->value); |
| 15598 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15599 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15600 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15601 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15602 | "Internal error: xmlSchemaValidateFacetsInternal, " |
| 15603 | "validating facet of type '%s'.\n", |
| 15604 | type->name, NULL); |
| 15605 | break; |
| 15606 | } else if ((ret > 0) && (fireErrors)) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15607 | xmlSchemaVFacetErr(ctxt, ret, node, value, len, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15608 | type, facet, NULL, NULL, NULL, NULL); |
| 15609 | } |
| 15610 | |
| 15611 | facetLink = facetLink->next; |
| 15612 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 15613 | |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 15614 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15615 | if (ret >= 0) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 15616 | xmlSchemaWhitespaceValueType fws; |
| 15617 | /* |
| 15618 | * Process enumerations. Facet values are in the value space |
| 15619 | * of the defining type's base type. This seems to be a bug in the |
| 15620 | * XML Schema 1.0 spec. For use, the normalized value is only |
| 15621 | * significant for enumerations. We need to localize the base type for eatch |
| 15622 | * enumeration facet, thus walk the ancestor type axis. |
| 15623 | */ |
| 15624 | tmpType = type; |
| 15625 | do { |
| 15626 | /* |
| 15627 | * Use the whitespace type of the base type. |
| 15628 | */ |
| 15629 | if (tmpType->type == XML_SCHEMA_TYPE_COMPLEX) |
| 15630 | /* TODO: Get rid of this case. */ |
| 15631 | fws = (xmlSchemaWhitespaceValueType) |
| 15632 | xmlSchemaGetWhiteSpaceFacetValue( |
| 15633 | xmlSchemaGetSimpleContentType(tmpType)); |
| 15634 | else |
| 15635 | fws = (xmlSchemaWhitespaceValueType) |
| 15636 | xmlSchemaGetWhiteSpaceFacetValue(tmpType->baseType); |
| 15637 | retFacet = 0; |
| 15638 | for (facet = tmpType->facets; facet != NULL; facet = facet->next) { |
| 15639 | if (facet->type != XML_SCHEMA_FACET_ENUMERATION) |
| 15640 | continue; |
| 15641 | retFacet = xmlSchemaValidateFacetWhtsp(facet, fws, |
| 15642 | biType->builtInType, value, ctxt->value, ws); |
| 15643 | if (retFacet == 0) |
| 15644 | break; |
| 15645 | else if (retFacet < 0) { |
| 15646 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
| 15647 | "Internal error: xmlSchemaValidateFacetsInternal, " |
| 15648 | "validating enumeration facet '%s' of type '%s'.\n", |
| 15649 | facet->value, tmpType->name); |
| 15650 | ret = -1; |
| 15651 | break; |
| 15652 | } |
| 15653 | } |
| 15654 | if (retFacet <= 0) |
| 15655 | break; |
| 15656 | if (tmpType->type == XML_SCHEMA_TYPE_COMPLEX) |
| 15657 | /* TODO: Get rid of this case. */ |
| 15658 | tmpType = xmlSchemaGetSimpleContentType(tmpType); |
| 15659 | else |
| 15660 | tmpType = tmpType->baseType; |
| 15661 | } while ((tmpType != NULL) && (tmpType->type != XML_SCHEMA_TYPE_BASIC)); |
| 15662 | if (retFacet > 0) { |
| 15663 | ret = XML_SCHEMAV_CVC_PATTERN_VALID; |
| 15664 | if (fireErrors) { |
| 15665 | xmlSchemaVFacetErr(ctxt, ret, node, value, 0, type, NULL, |
| 15666 | NULL, NULL, NULL, NULL); |
| 15667 | } |
| 15668 | } |
| 15669 | } |
| 15670 | |
| 15671 | if (ret >= 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15672 | /* |
| 15673 | * Process patters. Pattern facets are ORed at type level |
| 15674 | * and ANDed if derived. Walk the base type axis. |
| 15675 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15676 | tmpType = type; |
| 15677 | facet = NULL; |
| 15678 | do { |
| 15679 | retFacet = 0; |
| 15680 | for (facetLink = tmpType->facetSet; facetLink != NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15681 | facetLink = facetLink->next) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15682 | if (facetLink->facet->type != XML_SCHEMA_FACET_PATTERN) |
| 15683 | continue; |
| 15684 | retFacet = xmlSchemaValidateFacet(biType, facetLink->facet, |
| 15685 | value, ctxt->value); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15686 | if (retFacet == 0) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15687 | break; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15688 | else if (retFacet < 0) { |
| 15689 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
| 15690 | "Internal error: xmlSchemaValidateFacetsInternal, " |
| 15691 | "validating 'pattern' facet '%s' of type '%s'.\n", |
| 15692 | facetLink->facet->value, tmpType->name); |
| 15693 | ret = -1; |
| 15694 | break; |
| 15695 | } else |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15696 | /* Save the last non-validating facet. */ |
| 15697 | facet = facetLink->facet; |
| 15698 | } |
| 15699 | if (retFacet != 0) |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 15700 | break; |
| 15701 | if (tmpType->type == XML_SCHEMA_TYPE_COMPLEX) |
| 15702 | /* TODO: Get rid of this case. */ |
| 15703 | tmpType = xmlSchemaGetSimpleContentType(tmpType); |
| 15704 | else |
| 15705 | tmpType = tmpType->baseType; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15706 | } while ((tmpType != NULL) && (tmpType->type != XML_SCHEMA_TYPE_BASIC)); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15707 | if (retFacet > 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15708 | ret = XML_SCHEMAV_CVC_PATTERN_VALID; |
| 15709 | if (fireErrors) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15710 | xmlSchemaVFacetErr(ctxt, ret, node, value, 0, type, facet, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15711 | NULL, NULL, NULL, NULL); |
| 15712 | } |
| 15713 | } |
| 15714 | } |
| 15715 | |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 15716 | return (ret); |
| 15717 | } |
| 15718 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15719 | /************************************************************************ |
| 15720 | * * |
| 15721 | * Simple type validation * |
| 15722 | * * |
| 15723 | ************************************************************************/ |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 15724 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15725 | |
| 15726 | /************************************************************************ |
| 15727 | * * |
| 15728 | * DOM Validation code * |
| 15729 | * * |
| 15730 | ************************************************************************/ |
| 15731 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15732 | static int xmlSchemaValidateAttributes(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15733 | xmlNodePtr elem, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15734 | xmlSchemaTypePtr type); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15735 | static int xmlSchemaValidateElementByType(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15736 | xmlSchemaTypePtr type, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 15737 | int isNil, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15738 | int valSimpleContent); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15739 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15740 | static void xmlSchemaBeginElement(xmlSchemaValidCtxtPtr vctxt); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 15741 | static int xmlSchemaEndElement(xmlSchemaValidCtxtPtr vctxt); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15742 | |
| 15743 | #ifdef ELEM_INFO_ENABLED |
| 15744 | /** |
| 15745 | * xmlSchemaGetFreshElemInfo: |
| 15746 | * @vctxt: the schema validation context |
| 15747 | * |
| 15748 | * Creates/reuses and initializes the element info item for |
| 15749 | * the currect tree depth. |
| 15750 | * |
| 15751 | * Returns the element info item or NULL on API or internal errors. |
| 15752 | */ |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 15753 | static xmlSchemaNodeInfoPtr |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 15754 | xmlSchemaGetFreshElemInfo(xmlSchemaValidCtxtPtr vctxt, |
| 15755 | int depth) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15756 | { |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 15757 | xmlSchemaNodeInfoPtr info = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15758 | |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 15759 | if (depth > vctxt->sizeElemInfos) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15760 | xmlSchemaVErr(vctxt, NULL, XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 15761 | "Internal error: xmlSchemaGetFreshElemInfo, " |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15762 | "an inconsistent depth encountered.\n", |
| 15763 | NULL, NULL); |
| 15764 | return (NULL); |
| 15765 | } |
| 15766 | if (vctxt->elemInfos == NULL) { |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 15767 | vctxt->elemInfos = (xmlSchemaNodeInfoPtr *) |
| 15768 | xmlMalloc(10 * sizeof(xmlSchemaNodeInfoPtr)); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15769 | if (vctxt->elemInfos == NULL) { |
| 15770 | xmlSchemaVErrMemory(vctxt, |
| 15771 | "allocating the element info array", NULL); |
| 15772 | return (NULL); |
| 15773 | } |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 15774 | memset(vctxt->elemInfos, 0, 10 * sizeof(xmlSchemaNodeInfoPtr)); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15775 | vctxt->sizeElemInfos = 10; |
| 15776 | } else if (vctxt->sizeElemInfos == vctxt->depth) { |
| 15777 | int i = vctxt->sizeElemInfos; |
| 15778 | |
| 15779 | vctxt->sizeElemInfos *= 2; |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 15780 | vctxt->elemInfos = (xmlSchemaNodeInfoPtr *) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15781 | xmlRealloc(vctxt->elemInfos, vctxt->sizeElemInfos * |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 15782 | sizeof(xmlSchemaNodeInfoPtr)); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15783 | if (vctxt->elemInfos == NULL) { |
| 15784 | xmlSchemaVErrMemory(vctxt, |
| 15785 | "re-allocating the element info array", NULL); |
| 15786 | return (NULL); |
| 15787 | } |
| 15788 | /* |
| 15789 | * We need the new memory to be NULLed. |
| 15790 | * TODO: Use memset instead? |
| 15791 | */ |
| 15792 | for (; i < vctxt->sizeElemInfos; i++) |
| 15793 | vctxt->elemInfos[i] = NULL; |
| 15794 | } else |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 15795 | info = vctxt->elemInfos[depth]; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15796 | |
| 15797 | if (info == NULL) { |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 15798 | info = (xmlSchemaNodeInfoPtr) |
| 15799 | xmlMalloc(sizeof(xmlSchemaNodeInfo)); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15800 | if (info == NULL) { |
| 15801 | xmlSchemaVErrMemory(vctxt, |
| 15802 | "allocating an element info", NULL); |
| 15803 | return (NULL); |
| 15804 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 15805 | vctxt->elemInfos[depth] = info; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15806 | } |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 15807 | memset(info, 0, sizeof(xmlSchemaNodeInfo)); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 15808 | info->depth = depth; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15809 | |
| 15810 | return (info); |
| 15811 | } |
| 15812 | #endif /* ELEM_INFO_ENABLED */ |
| 15813 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15814 | |
| 15815 | /** |
| 15816 | * xmlSchemaFreeAttrStates: |
| 15817 | * @state: a list of attribute states |
| 15818 | * |
| 15819 | * Free the given list of attribute states |
| 15820 | * |
| 15821 | */ |
| 15822 | static void |
| 15823 | xmlSchemaFreeAttributeStates(xmlSchemaAttrStatePtr state) |
| 15824 | { |
| 15825 | xmlSchemaAttrStatePtr tmp; |
| 15826 | while (state != NULL) { |
| 15827 | tmp = state; |
| 15828 | state = state->next; |
| 15829 | xmlFree(tmp); |
| 15830 | } |
| 15831 | } |
| 15832 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15833 | /** |
| 15834 | * xmlSchemaRegisterAttributes: |
| 15835 | * @ctxt: a schema validation context |
| 15836 | * @attrs: a list of attributes |
| 15837 | * |
| 15838 | * Register the list of attributes as the set to be validated on that element |
| 15839 | * |
| 15840 | * Returns -1 in case of error, 0 otherwise |
| 15841 | */ |
| 15842 | static int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15843 | xmlSchemaRegisterAttributes(xmlSchemaValidCtxtPtr ctxt, xmlAttrPtr attrs) |
| 15844 | { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15845 | xmlSchemaAttrStatePtr tmp; |
| 15846 | |
| 15847 | ctxt->attr = NULL; |
| 15848 | ctxt->attrTop = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15849 | while (attrs != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15850 | if ((attrs->ns != NULL) && |
| 15851 | (xmlStrEqual(attrs->ns->href, xmlSchemaInstanceNs))) { |
| 15852 | attrs = attrs->next; |
| 15853 | continue; |
| 15854 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15855 | tmp = (xmlSchemaAttrStatePtr) |
| 15856 | xmlMalloc(sizeof(xmlSchemaAttrState)); |
| 15857 | if (tmp == NULL) { |
| 15858 | xmlSchemaVErrMemory(ctxt, "registering attributes", NULL); |
| 15859 | return (-1); |
| 15860 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15861 | tmp->attr = attrs; |
| 15862 | tmp->state = XML_SCHEMAS_ATTR_UNKNOWN; |
| 15863 | tmp->next = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15864 | tmp->decl = NULL; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15865 | if (ctxt->attr == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15866 | ctxt->attr = tmp; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15867 | else |
| 15868 | ctxt->attrTop->next = tmp; |
| 15869 | ctxt->attrTop = tmp; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15870 | attrs = attrs->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15871 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15872 | return (0); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15873 | } |
| 15874 | |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15875 | #if 0 /* Currently not used */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15876 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15877 | * xmlSchemaValidateCheckNodeList |
| 15878 | * @nodelist: the list of nodes |
| 15879 | * |
| 15880 | * Check the node list is only made of text nodes and entities pointing |
| 15881 | * to text nodes |
| 15882 | * |
| 15883 | * Returns 1 if true, 0 if false and -1 in case of error |
| 15884 | */ |
| 15885 | static int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15886 | xmlSchemaValidateCheckNodeList(xmlNodePtr nodelist) |
| 15887 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15888 | while (nodelist != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15889 | if (nodelist->type == XML_ENTITY_REF_NODE) { |
| 15890 | TODO /* implement recursion in the entity content */ |
| 15891 | } |
| 15892 | if ((nodelist->type != XML_TEXT_NODE) && |
| 15893 | (nodelist->type != XML_COMMENT_NODE) && |
| 15894 | (nodelist->type != XML_PI_NODE) && |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 15895 | (nodelist->type != XML_CDATA_SECTION_NODE)) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15896 | return (0); |
| 15897 | } |
| 15898 | nodelist = nodelist->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15899 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15900 | return (1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15901 | } |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15902 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15903 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15904 | static void |
| 15905 | xmlSchemaPostSchemaAssembleFixup(xmlSchemaParserCtxtPtr ctxt) |
| 15906 | { |
| 15907 | int i, nbItems; |
| 15908 | xmlSchemaTypePtr item, *items; |
| 15909 | |
| 15910 | |
| 15911 | /* |
| 15912 | * During the Assemble of the schema ctxt->curItems has |
| 15913 | * been filled with the relevant new items. Fix those up. |
| 15914 | */ |
| 15915 | nbItems = ctxt->assemble->nbItems; |
| 15916 | items = (xmlSchemaTypePtr *) ctxt->assemble->items; |
| 15917 | |
| 15918 | for (i = 0; i < nbItems; i++) { |
| 15919 | item = items[i]; |
| 15920 | switch (item->type) { |
| 15921 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 15922 | xmlSchemaAttrFixup((xmlSchemaAttributePtr) item, ctxt, NULL); |
| 15923 | break; |
| 15924 | case XML_SCHEMA_TYPE_ELEMENT: |
| 15925 | xmlSchemaRefFixupCallback((xmlSchemaElementPtr) item, ctxt, |
| 15926 | NULL, NULL, NULL); |
| 15927 | break; |
| 15928 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
| 15929 | xmlSchemaAttrGrpFixup((xmlSchemaAttributeGroupPtr) item, |
| 15930 | ctxt, NULL); |
| 15931 | break; |
| 15932 | case XML_SCHEMA_TYPE_GROUP: |
| 15933 | xmlSchemaGroupDefFixup(item, ctxt, NULL); |
| 15934 | default: |
| 15935 | break; |
| 15936 | } |
| 15937 | } |
| 15938 | /* |
| 15939 | * Circularity checks. |
| 15940 | */ |
| 15941 | for (i = 0; i < nbItems; i++) { |
| 15942 | item = items[i]; |
| 15943 | switch (item->type) { |
| 15944 | case XML_SCHEMA_TYPE_GROUP: |
| 15945 | xmlSchemaCheckGroupDefCircular(item, ctxt, NULL); |
| 15946 | break; |
| 15947 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
| 15948 | xmlSchemaCheckAttributeGroupCircular( |
| 15949 | (xmlSchemaAttributeGroupPtr) item, ctxt, NULL); |
| 15950 | break; |
| 15951 | default: |
| 15952 | break; |
| 15953 | } |
| 15954 | } |
| 15955 | /* |
| 15956 | * Fixup for all other item. |
| 15957 | * TODO: Hmm, not sure if starting from complex/simple types, |
| 15958 | * all subsequent items will be reached. |
| 15959 | */ |
| 15960 | for (i = 0; i < nbItems; i++) { |
| 15961 | item = items[i]; |
| 15962 | switch (item->type) { |
| 15963 | case XML_SCHEMA_TYPE_SIMPLE: |
| 15964 | case XML_SCHEMA_TYPE_COMPLEX: |
| 15965 | xmlSchemaTypeFixup(item, ctxt, NULL); |
| 15966 | break; |
| 15967 | default: |
| 15968 | break; |
| 15969 | } |
| 15970 | } |
| 15971 | /* |
| 15972 | * Check facet values. Note that facets are |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 15973 | * hold by simple type components only (and |
| 15974 | * by complex types in the current implementation). |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15975 | */ |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 15976 | /* OLD: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15977 | for (i = 0; i < nbItems; i++) { |
| 15978 | item = items[i]; |
| 15979 | switch (item->type) { |
| 15980 | case XML_SCHEMA_TYPE_SIMPLE: |
| 15981 | case XML_SCHEMA_TYPE_COMPLEX: |
| 15982 | xmlSchemaCheckDefaults(item, ctxt, NULL); |
| 15983 | break; |
| 15984 | default: |
| 15985 | break; |
| 15986 | } |
| 15987 | } |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 15988 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15989 | /* |
| 15990 | * Build the content model for complex types. |
| 15991 | */ |
| 15992 | for (i = 0; i < nbItems; i++) { |
| 15993 | item = items[i]; |
| 15994 | switch (item->type) { |
| 15995 | case XML_SCHEMA_TYPE_COMPLEX: |
| 15996 | xmlSchemaBuildContentModel(item, ctxt, NULL); |
| 15997 | break; |
| 15998 | default: |
| 15999 | break; |
| 16000 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16001 | } |
| 16002 | /* |
| 16003 | * Validate value contraint values. |
| 16004 | */ |
| 16005 | for (i = 0; i < nbItems; i++) { |
| 16006 | item = items[i]; |
| 16007 | switch (item->type) { |
| 16008 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 16009 | xmlSchemaCheckAttrValConstr((xmlSchemaAttributePtr) item, ctxt, NULL); |
| 16010 | break; |
| 16011 | case XML_SCHEMA_TYPE_ELEMENT: |
| 16012 | xmlSchemaCheckElemValConstr((xmlSchemaElementPtr) item, ctxt, NULL); |
| 16013 | break; |
| 16014 | default: |
| 16015 | break; |
| 16016 | } |
| 16017 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16018 | } |
| 16019 | |
| 16020 | /** |
| 16021 | * xmlSchemaAssembleByLocation: |
| 16022 | * @pctxt: a schema parser context |
| 16023 | * @vctxt: a schema validation context |
| 16024 | * @schema: the existing schema |
| 16025 | * @node: the node that fired the assembling |
| 16026 | * @nsName: the namespace name of the new schema |
| 16027 | * @location: the location of the schema |
| 16028 | * |
| 16029 | * Expands an existing schema by an additional schema. |
| 16030 | * |
| 16031 | * Returns 0 if the new schema is correct, a positive error code |
| 16032 | * number otherwise and -1 in case of an internal or API error. |
| 16033 | */ |
| 16034 | static int |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16035 | xmlSchemaAssembleByLocation(xmlSchemaValidCtxtPtr vctxt, |
| 16036 | xmlSchemaPtr schema, |
| 16037 | xmlNodePtr node, |
| 16038 | const xmlChar *nsName, |
| 16039 | const xmlChar *location) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16040 | { |
| 16041 | const xmlChar *targetNs, *oldtns; |
| 16042 | xmlDocPtr doc, olddoc; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16043 | int oldflags, ret = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16044 | xmlNodePtr docElem; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16045 | xmlSchemaParserCtxtPtr pctxt; |
| 16046 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16047 | /* |
| 16048 | * This should be used: |
| 16049 | * 1. on <import>(s) |
| 16050 | * 2. if requested by the validated instance |
| 16051 | * 3. if requested via the API |
| 16052 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16053 | if ((vctxt == NULL) || (schema == NULL)) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16054 | return (-1); |
| 16055 | /* |
| 16056 | * Create a temporary parser context. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16057 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16058 | if ((vctxt->pctxt == NULL) && |
| 16059 | (xmlSchemaCreatePCtxtOnVCtxt(vctxt) == -1)) { |
| 16060 | xmlSchemaVErr(vctxt, node, |
| 16061 | XML_SCHEMAV_INTERNAL, |
| 16062 | "Internal error: xmlSchemaAssembleByLocation, " |
| 16063 | "failed to create a temp. parser context.\n", |
| 16064 | NULL, NULL); |
| 16065 | return (-1); |
| 16066 | } |
| 16067 | pctxt = vctxt->pctxt; |
| 16068 | /* |
| 16069 | * Set the counter to produce unique names for anonymous items. |
| 16070 | */ |
| 16071 | pctxt->counter = schema->counter; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16072 | /* |
| 16073 | * Acquire the schema document. |
| 16074 | */ |
| 16075 | ret = xmlSchemaAcquireSchemaDoc(pctxt, schema, node, |
| 16076 | nsName, location, &doc, &targetNs, 0); |
| 16077 | if (ret != 0) { |
| 16078 | if (doc != NULL) |
| 16079 | xmlFreeDoc(doc); |
| 16080 | } else if (doc != NULL) { |
| 16081 | docElem = xmlDocGetRootElement(doc); |
| 16082 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16083 | * Create new assemble info. |
| 16084 | */ |
| 16085 | if (pctxt->assemble == NULL) { |
| 16086 | pctxt->assemble = xmlSchemaNewAssemble(); |
| 16087 | if (pctxt->assemble == NULL) { |
| 16088 | xmlSchemaVErrMemory(vctxt, |
| 16089 | "Memory error: xmlSchemaAssembleByLocation, " |
| 16090 | "allocating assemble info", NULL); |
| 16091 | xmlFreeDoc(doc); |
| 16092 | return (-1); |
| 16093 | } |
| 16094 | } |
| 16095 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16096 | * Save and reset the context & schema. |
| 16097 | */ |
| 16098 | oldflags = schema->flags; |
| 16099 | oldtns = schema->targetNamespace; |
| 16100 | olddoc = schema->doc; |
| 16101 | |
| 16102 | xmlSchemaClearSchemaDefaults(schema); |
| 16103 | schema->targetNamespace = targetNs; |
| 16104 | /* schema->nbCurItems = 0; */ |
| 16105 | pctxt->schema = schema; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16106 | pctxt->ctxtType = NULL; |
| 16107 | pctxt->parentItem = NULL; |
| 16108 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16109 | xmlSchemaParseSchemaDefaults(pctxt, schema, docElem); |
| 16110 | xmlSchemaParseSchemaTopLevel(pctxt, schema, docElem->children); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16111 | xmlSchemaPostSchemaAssembleFixup(pctxt); |
| 16112 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16113 | * Set the counter of items. |
| 16114 | */ |
| 16115 | schema->counter = pctxt->counter; |
| 16116 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16117 | * Free the list of assembled components. |
| 16118 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16119 | pctxt->assemble->nbItems = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16120 | /* |
| 16121 | * Restore the context & schema. |
| 16122 | */ |
| 16123 | schema->flags = oldflags; |
| 16124 | schema->targetNamespace = oldtns; |
| 16125 | schema->doc = olddoc; |
| 16126 | ret = pctxt->err; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16127 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16128 | return (ret); |
| 16129 | } |
| 16130 | |
| 16131 | /** |
| 16132 | * xmlSchemaAssembleByXSIAttr: |
| 16133 | * @vctxt: a schema validation context |
| 16134 | * @xsiAttr: an xsi attribute |
| 16135 | * @noNamespace: whether a schema with no target namespace is exptected |
| 16136 | * |
| 16137 | * Expands an existing schema by an additional schema using |
| 16138 | * the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attribute |
| 16139 | * of an instance. If xsi:noNamespaceSchemaLocation is used, @noNamespace |
| 16140 | * must be set to 1. |
| 16141 | * |
| 16142 | * Returns 0 if the new schema is correct, a positive error code |
| 16143 | * number otherwise and -1 in case of an internal or API error. |
| 16144 | */ |
| 16145 | static int |
| 16146 | xmlSchemaAssembleByXSIAttr(xmlSchemaValidCtxtPtr vctxt, |
| 16147 | xmlAttrPtr xsiAttr, |
| 16148 | int noNamespace) |
| 16149 | { |
| 16150 | xmlChar *value; |
| 16151 | const xmlChar *cur, *end; |
| 16152 | const xmlChar *nsname = NULL, *location; |
| 16153 | int count = 0; |
| 16154 | int ret = 0; |
| 16155 | |
| 16156 | if (xsiAttr == NULL) { |
| 16157 | xmlSchemaVCustomErr(vctxt, XML_SCHEMAV_INTERNAL, |
| 16158 | NULL, NULL, |
| 16159 | "Internal error: xmlSchemaAssembleByXSIAttr, " |
| 16160 | "bad arguments", NULL); |
| 16161 | return (-1); |
| 16162 | } |
| 16163 | /* |
| 16164 | * Parse the value; we will assume an even number of values |
| 16165 | * to be given (this is how Xerces and XSV work). |
| 16166 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16167 | value = xmlNodeGetContent((xmlNodePtr) xsiAttr); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16168 | cur = value; |
| 16169 | do { |
| 16170 | if (noNamespace != 1) { |
| 16171 | /* |
| 16172 | * Get the namespace name. |
| 16173 | */ |
| 16174 | while (IS_BLANK_CH(*cur)) |
| 16175 | cur++; |
| 16176 | end = cur; |
| 16177 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 16178 | end++; |
| 16179 | if (end == cur) |
| 16180 | break; |
| 16181 | count++; |
| 16182 | nsname = xmlDictLookup(vctxt->schema->dict, cur, end - cur); |
| 16183 | cur = end; |
| 16184 | } |
| 16185 | /* |
| 16186 | * Get the URI. |
| 16187 | */ |
| 16188 | while (IS_BLANK_CH(*cur)) |
| 16189 | cur++; |
| 16190 | end = cur; |
| 16191 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 16192 | end++; |
| 16193 | if (end == cur) |
| 16194 | break; |
| 16195 | count++; |
| 16196 | location = xmlDictLookup(vctxt->schema->dict, cur, end - cur); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16197 | cur = end; |
| 16198 | ret = xmlSchemaAssembleByLocation(vctxt, vctxt->schema, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16199 | xsiAttr->parent, nsname, location); |
| 16200 | if (ret == -1) { |
| 16201 | xmlSchemaVCustomErr(vctxt, |
| 16202 | XML_SCHEMAV_INTERNAL, |
| 16203 | (xmlNodePtr) xsiAttr, NULL, |
| 16204 | "Internal error: xmlSchemaAssembleByXSIAttr, " |
| 16205 | "assembling schemata", NULL); |
| 16206 | if (value != NULL) |
| 16207 | xmlFree(value); |
| 16208 | return (-1); |
| 16209 | } |
| 16210 | } while (*cur != 0); |
| 16211 | if (value != NULL) |
| 16212 | xmlFree(value); |
| 16213 | return (ret); |
| 16214 | } |
| 16215 | |
| 16216 | /** |
| 16217 | * xmlSchemaAssembleByXSIElem: |
| 16218 | * @vctxt: a schema validation context |
| 16219 | * @elem: an element node possibly holding xsi attributes |
| 16220 | * @noNamespace: whether a schema with no target namespace is exptected |
| 16221 | * |
| 16222 | * Assembles an existing schema by an additional schema using |
| 16223 | * the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attributes |
| 16224 | * of the given @elem. |
| 16225 | * |
| 16226 | * Returns 0 if the new schema is correct, a positive error code |
| 16227 | * number otherwise and -1 in case of an internal or API error. |
| 16228 | */ |
| 16229 | static int |
| 16230 | xmlSchemaAssembleByXSIElem(xmlSchemaValidCtxtPtr vctxt, |
| 16231 | xmlNodePtr elem) |
| 16232 | { |
| 16233 | int ret = 0, retNs = 0; |
| 16234 | xmlAttrPtr attr; |
| 16235 | |
| 16236 | attr = xmlHasNsProp(elem, BAD_CAST "schemaLocation", xmlSchemaInstanceNs); |
| 16237 | if (attr != NULL) { |
| 16238 | retNs = xmlSchemaAssembleByXSIAttr(vctxt, attr, 0); |
| 16239 | if (retNs == -1) |
| 16240 | return (-1); |
| 16241 | } |
| 16242 | attr = xmlHasNsProp(elem, BAD_CAST "noNamespaceSchemaLocation", xmlSchemaInstanceNs); |
| 16243 | if (attr != NULL) { |
| 16244 | ret = xmlSchemaAssembleByXSIAttr(vctxt, attr, 1); |
| 16245 | if (ret == -1) |
| 16246 | return (-1); |
| 16247 | } |
| 16248 | if (retNs != 0) |
| 16249 | return (retNs); |
| 16250 | else |
| 16251 | return (ret); |
| 16252 | } |
| 16253 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16254 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16255 | * xmlSchemaValidateCallback: |
| 16256 | * @ctxt: a schema validation context |
| 16257 | * @name: the name of the element detected (might be NULL) |
| 16258 | * @type: the type |
| 16259 | * |
| 16260 | * A transition has been made in the automata associated to an element |
| 16261 | * content model |
| 16262 | */ |
| 16263 | static void |
| 16264 | xmlSchemaValidateCallback(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16265 | const xmlChar * name ATTRIBUTE_UNUSED, |
| 16266 | xmlSchemaTypePtr type, xmlNodePtr node) |
| 16267 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16268 | xmlSchemaTypePtr oldtype = ctxt->type; |
| 16269 | xmlNodePtr oldnode = ctxt->node; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16270 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16271 | #ifdef DEBUG_CONTENT |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 16272 | xmlGenericError(xmlGenericErrorContext, |
| 16273 | "xmlSchemaValidateCallback: %s, %s, %s\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16274 | name, type->name, node->name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16275 | #endif |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16276 | /* |
| 16277 | * @type->type will be XML_SCHEMA_TYPE_ANY or XML_SCHEMA_TYPE_ELEMENT. |
| 16278 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16279 | ctxt->type = type; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16280 | ctxt->node = node; |
| 16281 | ctxt->cur = node->children; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16282 | |
| 16283 | #ifdef ELEM_INFO_ENABLED |
| 16284 | xmlSchemaBeginElement(ctxt); |
| 16285 | #endif |
| 16286 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16287 | /* |
| 16288 | * Assemble new schemata using xsi. |
| 16289 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16290 | if (ctxt->xsiAssemble) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16291 | int ret; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16292 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16293 | ret = xmlSchemaAssembleByXSIElem(ctxt, ctxt->node); |
| 16294 | if (ret == -1) { |
| 16295 | xmlSchemaVCustomErr(ctxt, |
| 16296 | XML_SCHEMAV_INTERNAL, |
| 16297 | ctxt->node, NULL, |
| 16298 | "Internal error: xmlSchemaValidateElement, " |
| 16299 | "assembling schema by xsi", NULL); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16300 | goto leave; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16301 | } |
| 16302 | /* |
| 16303 | * NOTE: We won't react on schema parser errors here. |
| 16304 | * TODO: But a warning would be nice. |
| 16305 | */ |
| 16306 | } |
| 16307 | switch (type->type) { |
| 16308 | case XML_SCHEMA_TYPE_ELEMENT: { |
| 16309 | /* |
| 16310 | * NOTE: The build of the content model |
| 16311 | * (xmlSchemaBuildAContentModel) ensures that the element |
| 16312 | * declaration (and not a reference to it) will be given. |
| 16313 | */ |
| 16314 | if (((xmlSchemaElementPtr) ctxt->type)->ref != NULL) { |
| 16315 | /* |
| 16316 | * This is paranoid coding ;-)... it should not |
| 16317 | * happen here any more. |
| 16318 | */ |
| 16319 | xmlSchemaVCustomErr(ctxt, |
| 16320 | XML_SCHEMAV_INTERNAL, |
| 16321 | node, NULL, |
| 16322 | "Internal error: xmlSchemaValidateCallback, " |
| 16323 | "element declaration 'reference' encountered, " |
| 16324 | "but an element declaration was expected", |
| 16325 | NULL); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16326 | goto leave; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16327 | } |
| 16328 | xmlSchemaValidateElementByDeclaration(ctxt, |
| 16329 | (xmlSchemaElementPtr) type); |
| 16330 | break; |
| 16331 | } |
| 16332 | case XML_SCHEMA_TYPE_ANY: |
| 16333 | xmlSchemaValidateElementByWildcard(ctxt, type); |
| 16334 | break; |
| 16335 | default: |
| 16336 | break; |
| 16337 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16338 | leave: |
| 16339 | |
| 16340 | #ifdef ELEM_INFO_ENABLED |
| 16341 | xmlSchemaEndElement(ctxt); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16342 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16343 | ctxt->type = oldtype; |
| 16344 | ctxt->node = oldnode; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16345 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16346 | |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 16347 | static int |
| 16348 | xmlSchemaValidateNotation(xmlSchemaValidCtxtPtr vctxt, |
| 16349 | const xmlChar *value, |
| 16350 | xmlSchemaValPtr *val, |
| 16351 | xmlNodePtr node) |
| 16352 | { |
| 16353 | int ret; |
| 16354 | |
| 16355 | ret = xmlValidateQName(value, 1); |
| 16356 | if (ret != 0) |
| 16357 | return (ret); |
| 16358 | |
| 16359 | { |
| 16360 | xmlChar *uri = NULL; |
| 16361 | xmlChar *local = NULL; |
| 16362 | xmlChar *prefix; |
| 16363 | |
| 16364 | local = xmlSplitQName2(value, &prefix); |
| 16365 | if (prefix != NULL) { |
| 16366 | xmlNsPtr ns; |
| 16367 | |
| 16368 | /* |
| 16369 | * TODO: Make this streamable. |
| 16370 | */ |
| 16371 | if ((node == NULL) || (node->doc == NULL)) { |
| 16372 | xmlFree(prefix); |
| 16373 | xmlFree(local); |
| 16374 | return (3); |
| 16375 | } |
| 16376 | |
| 16377 | ns = xmlSearchNs(node->doc, node, prefix); |
| 16378 | if (ns == NULL) { |
| 16379 | xmlFree(prefix); |
| 16380 | xmlFree(local); |
| 16381 | return (1); |
| 16382 | } |
| 16383 | } |
| 16384 | if (prefix != NULL) { |
| 16385 | if (xmlHashLookup2(vctxt->schema->notaDecl, local, uri) == NULL) |
| 16386 | ret = 1; |
| 16387 | } else if (xmlHashLookup2(vctxt->schema->notaDecl, value, |
| 16388 | NULL) == NULL) |
| 16389 | ret = 1; |
| 16390 | |
| 16391 | if ((ret == 0) && (val != NULL)) { |
| 16392 | if (prefix != NULL) { |
| 16393 | (*val) = xmlSchemaNewNOTATIONValue(BAD_CAST local, |
| 16394 | BAD_CAST xmlStrdup(uri)); |
| 16395 | local = NULL; |
| 16396 | } else |
| 16397 | (*val) = xmlSchemaNewNOTATIONValue(BAD_CAST xmlStrdup(value), |
| 16398 | NULL); |
| 16399 | if (*val == NULL) |
| 16400 | ret = -1; |
| 16401 | } |
| 16402 | if (local != NULL) |
| 16403 | xmlFree(local); |
| 16404 | } |
| 16405 | |
| 16406 | return (ret); |
| 16407 | } |
| 16408 | |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 16409 | static xmlSchemaTypePtr |
| 16410 | xmlSchemaGetSimpleContentType(xmlSchemaTypePtr complexType) |
| 16411 | { |
| 16412 | xmlSchemaTypePtr ret; |
| 16413 | |
| 16414 | if (complexType->type != XML_SCHEMA_TYPE_COMPLEX) |
| 16415 | return (NULL); |
| 16416 | if (complexType->contentTypeDef != NULL) |
| 16417 | return (complexType->contentTypeDef); |
| 16418 | /* |
| 16419 | * TODO: This is only a workaround until the simple content |
| 16420 | * type is computed for complex types with simple content. |
| 16421 | */ |
| 16422 | ret = complexType->baseType; |
| 16423 | while (ret != NULL) { |
| 16424 | if (IS_SIMPLE_TYPE(ret)) |
| 16425 | return (ret); |
| 16426 | if (ret->builtInType == XML_SCHEMAS_ANYTYPE) |
| 16427 | return (NULL); |
| 16428 | if ((ret->type == XML_SCHEMA_TYPE_COMPLEX) && |
| 16429 | (ret->contentTypeDef != NULL)) |
| 16430 | ret = ret->contentTypeDef; |
| 16431 | else |
| 16432 | ret = ret->baseType; |
| 16433 | } |
| 16434 | return (ret); |
| 16435 | } |
| 16436 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16437 | /** |
| 16438 | * xmlSchemaValidateSimpleTypeValue: |
| 16439 | * @ctxt: a schema validation context |
| 16440 | * @value: the value to be validated |
| 16441 | * @fireErrors: shall errors be reported? |
| 16442 | * @applyFacets: shall facets be applied? |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16443 | * @normalize: shall the value be normalized? |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16444 | * @checkNodes: shall the content nodes be checked? |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16445 | * |
| 16446 | * Validates a value by the given type (user derived or built-in). |
| 16447 | * |
| 16448 | * Returns 0 if the value is valid, a positive error code |
| 16449 | * number otherwise and -1 in case of an internal or API error. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16450 | */ |
| 16451 | static int |
| 16452 | xmlSchemaValidateSimpleTypeValue(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16453 | xmlSchemaTypePtr type, |
| 16454 | const xmlChar *value, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16455 | int fireErrors, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16456 | int applyFacets, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16457 | int normalize, |
| 16458 | int checkNodes) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16459 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16460 | xmlNodePtr node; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16461 | int ret = 0; |
| 16462 | xmlChar *normValue = NULL; |
| 16463 | int wtsp; |
| 16464 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16465 | node = ctxt->node; |
| 16466 | /* Save the current whitespace normalization type. */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16467 | wtsp = ctxt->valueWS; |
| 16468 | /* |
| 16469 | * Normalize the value. |
| 16470 | */ |
| 16471 | if (normalize && |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 16472 | (ctxt->valueWS != XML_SCHEMAS_FACET_COLLAPSE)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16473 | int norm = xmlSchemaGetWhiteSpaceFacetValue(type); |
| 16474 | |
| 16475 | if ((norm != -1) && (norm > ctxt->valueWS)) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 16476 | if (norm == XML_SCHEMAS_FACET_COLLAPSE) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16477 | normValue = xmlSchemaCollapseString(value); |
| 16478 | else |
| 16479 | normValue = xmlSchemaWhiteSpaceReplace(value); |
| 16480 | ctxt->valueWS = norm; |
| 16481 | if (normValue != NULL) |
| 16482 | value = (const xmlChar *) normValue; |
| 16483 | } |
| 16484 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16485 | /* |
| 16486 | * The nodes of a content must be checked only once, |
| 16487 | * this is not working since list types will fire this |
| 16488 | * multiple times. |
| 16489 | */ |
| 16490 | if ((checkNodes == 1) && (ctxt->cur != NULL)) { |
| 16491 | xmlNodePtr cur = ctxt->cur; |
| 16492 | |
| 16493 | do { |
| 16494 | switch (cur->type) { |
| 16495 | case XML_TEXT_NODE: |
| 16496 | case XML_CDATA_SECTION_NODE: |
| 16497 | case XML_PI_NODE: |
| 16498 | case XML_COMMENT_NODE: |
| 16499 | case XML_XINCLUDE_START: |
| 16500 | case XML_XINCLUDE_END: |
| 16501 | break; |
| 16502 | case XML_ENTITY_REF_NODE: |
| 16503 | case XML_ENTITY_NODE: |
| 16504 | /* TODO: Scour the entities for illegal nodes. */ |
| 16505 | TODO break; |
| 16506 | case XML_ELEMENT_NODE: { |
| 16507 | /* NOTE: Changed to an internal error, since the |
| 16508 | * existence of an element node will be already checked in |
| 16509 | * xmlSchemaValidateElementBySimpleType and in |
| 16510 | * xmlSchemaValidateElementByComplexType. |
| 16511 | */ |
| 16512 | xmlSchemaVCustomErr(ctxt, |
| 16513 | XML_SCHEMAV_INTERNAL, |
| 16514 | /* XML_SCHEMAS_ERR_INVALIDELEM, */ |
| 16515 | node, type, |
| 16516 | "Element '%s' found in simple type content", |
| 16517 | cur->name); |
| 16518 | return (XML_SCHEMAV_INTERNAL); |
| 16519 | } |
| 16520 | case XML_ATTRIBUTE_NODE: |
| 16521 | case XML_DOCUMENT_NODE: |
| 16522 | case XML_DOCUMENT_TYPE_NODE: |
| 16523 | case XML_DOCUMENT_FRAG_NODE: |
| 16524 | case XML_NOTATION_NODE: |
| 16525 | case XML_HTML_DOCUMENT_NODE: |
| 16526 | case XML_DTD_NODE: |
| 16527 | case XML_ELEMENT_DECL: |
| 16528 | case XML_ATTRIBUTE_DECL: |
| 16529 | case XML_ENTITY_DECL: |
| 16530 | case XML_NAMESPACE_DECL: |
| 16531 | #ifdef LIBXML_DOCB_ENABLED |
| 16532 | case XML_DOCB_DOCUMENT_NODE: |
| 16533 | #endif |
| 16534 | xmlSchemaVCustomErr(ctxt, |
| 16535 | XML_SCHEMAV_INTERNAL, |
| 16536 | /* XML_SCHEMAS_ERR_INVALIDELEM, */ |
| 16537 | node, NULL, |
| 16538 | "Node of unexpected type found in simple type content", |
| 16539 | NULL); |
| 16540 | return (XML_SCHEMAV_INTERNAL); |
| 16541 | } |
| 16542 | cur = cur->next; |
| 16543 | } while (cur != NULL); |
| 16544 | } |
| 16545 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16546 | if (type->type == XML_SCHEMA_TYPE_COMPLEX) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 16547 | xmlSchemaTypePtr simpType, anyType; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16548 | |
| 16549 | anyType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 16550 | |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 16551 | simpType = xmlSchemaGetSimpleContentType(type); |
| 16552 | if (simpType == NULL) { |
| 16553 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
| 16554 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 16555 | "failed to obtain the simple content type of the complex " |
| 16556 | "type '%s'\n", |
| 16557 | type->name, NULL); |
| 16558 | return (-1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16559 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 16560 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, simpType, value, 1, 0, 1, 0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16561 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16562 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16563 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 16564 | "validating complex type '%s'\n", |
| 16565 | type->name, NULL); |
| 16566 | } else if ((ret == 0) && (applyFacets) && (type->facetSet != NULL)) { |
| 16567 | /* |
| 16568 | * Check facets. |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 16569 | * |
| 16570 | * TODO: This is somehow not nice, since if an error occurs |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16571 | * the reported type will be the complex type; the spec |
| 16572 | * wants a simple type to be created on the complex type |
| 16573 | * if it has a simple content. For now we have to live with |
| 16574 | * it. |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 16575 | */ |
| 16576 | ret = xmlSchemaValidateFacetsInternal(ctxt, type, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16577 | value, 0, fireErrors); |
| 16578 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16579 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16580 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 16581 | "validating facets of complex type '%s'\n", |
| 16582 | type->name, NULL); |
| 16583 | } else if (ret > 0) { |
| 16584 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16585 | if (fireErrors) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16586 | xmlSchemaVSimpleTypeErr(ctxt, ret, node, value, type); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16587 | } |
| 16588 | } |
| 16589 | } else if (type->type == XML_SCHEMA_TYPE_BASIC) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16590 | |
| 16591 | if (ctxt->value != NULL) { |
| 16592 | xmlSchemaFreeValue(ctxt->value); |
| 16593 | ctxt->value = NULL; |
| 16594 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16595 | /* |
| 16596 | * STREAM-READ-CHILDREN. |
| 16597 | */ |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 16598 | if ((type->builtInType == XML_SCHEMAS_NOTATION) && |
| 16599 | (ctxt->schema != NULL)) { |
| 16600 | /* |
| 16601 | * NOTATIONs need to be processed here, since they need |
| 16602 | * to lookup in the hashtable of NOTATION declarations. |
| 16603 | */ |
| 16604 | ret = xmlSchemaValidateNotation(ctxt, value, &(ctxt->value), node); |
| 16605 | } else |
| 16606 | ret = xmlSchemaValPredefTypeNodeNoNorm(type, value, &(ctxt->value), node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16607 | if (ret > 0) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16608 | if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) |
| 16609 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
| 16610 | else |
| 16611 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16612 | if (fireErrors) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16613 | xmlSchemaVSimpleTypeErr(ctxt, ret, node, value, type); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16614 | } else if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16615 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16616 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16617 | "validating built-in type '%s'\n", type->name, NULL); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16618 | } else if ((ctxt->value == NULL) && |
| 16619 | (type->builtInType == XML_SCHEMAS_STRING) && |
| 16620 | (ctxt->nodeInfo != NULL) && |
| 16621 | (ctxt->nodeInfo->flags & XML_SCHEMA_ELEM_INFO_VALUE_NEEDED)) { |
| 16622 | #ifdef IDC_VALUE_SUPPORT |
| 16623 | xmlChar *valdup; |
| 16624 | /* |
| 16625 | * Create a precomputed string value for "string" as well if |
| 16626 | * requested. |
| 16627 | */ |
| 16628 | valdup = xmlStrdup(value); |
| 16629 | ctxt->value = xmlSchemaNewStringValue(XML_SCHEMAS_STRING, |
| 16630 | BAD_CAST valdup); |
| 16631 | if ((valdup != NULL) && (ctxt->value == NULL)) |
| 16632 | xmlFree(valdup); |
| 16633 | #endif |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16634 | } |
| 16635 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) { |
| 16636 | /* 1.2.1 if {variety} is ·atomic· then the string must ·match· |
| 16637 | * a literal in the ·lexical space· of {base type definition} |
| 16638 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16639 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, type->baseType, value, 0, 0, 0, 0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16640 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16641 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16642 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16643 | "validating atomic simple type '%s'\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16644 | type->name, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16645 | } else if (ret > 0) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16646 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16647 | if (fireErrors) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16648 | xmlSchemaVSimpleTypeErr(ctxt, ret, node, value, type); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16649 | } else if ((applyFacets) && (type->facetSet != NULL)) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16650 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16651 | * Check facets. |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 16652 | */ |
| 16653 | ret = xmlSchemaValidateFacetsInternal(ctxt, type, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16654 | value, 0, fireErrors); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16655 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16656 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16657 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16658 | "validating facets of atomic simple type '%s'\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16659 | type->name, NULL); |
| 16660 | } else if (ret > 0) { |
| 16661 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16662 | /* |
| 16663 | Disabled, since the facet validation already reports errors. |
| 16664 | if (fireErrors) |
| 16665 | xmlSchemaVSimpleTypeErr(ctxt, ret, ctxt->cur, value, type); |
| 16666 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16667 | } |
| 16668 | } |
| 16669 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 16670 | |
| 16671 | xmlSchemaTypePtr tmpType; |
| 16672 | const xmlChar *cur, *end; |
| 16673 | xmlChar *tmp; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16674 | unsigned long len = 0; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16675 | |
| 16676 | /* 1.2.2 if {variety} is ·list· then the string must be a sequence |
| 16677 | * of white space separated tokens, each of which ·match·es a literal |
| 16678 | * in the ·lexical space· of {item type definition} |
| 16679 | */ |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 16680 | |
Kasimier T. Buchcik | de938cd | 2005-01-13 12:25:57 +0000 | [diff] [blame] | 16681 | if (value == NULL) |
| 16682 | value = BAD_CAST ""; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16683 | tmpType = xmlSchemaGetListSimpleTypeItemType(type); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16684 | cur = value; |
| 16685 | do { |
| 16686 | while (IS_BLANK_CH(*cur)) |
| 16687 | cur++; |
| 16688 | end = cur; |
| 16689 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 16690 | end++; |
| 16691 | if (end == cur) |
| 16692 | break; |
| 16693 | tmp = xmlStrndup(cur, end - cur); |
| 16694 | len++; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16695 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, tmpType, tmp, 0, 1, 0, 0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16696 | xmlFree(tmp); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16697 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16698 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16699 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 16700 | "validating an item of list simple type '%s'\n", |
| 16701 | type->name, NULL); |
| 16702 | break; |
| 16703 | } else if (ret > 0) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16704 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16705 | if (fireErrors) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16706 | xmlSchemaVSimpleTypeErr(ctxt, ret, node, value, type); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16707 | break; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16708 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16709 | cur = end; |
| 16710 | } while (*cur != 0); |
| 16711 | /* |
| 16712 | * Check facets. |
| 16713 | */ |
| 16714 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16715 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16716 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16717 | "validating list simple type '%s'\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16718 | type->name, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16719 | } else if ((ret == 0) && (applyFacets)) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 16720 | ret = xmlSchemaValidateFacetsInternal(ctxt, type, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16721 | value, len, fireErrors); |
| 16722 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16723 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16724 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 16725 | "validating facets of list simple type '%s'\n", |
| 16726 | type->name, NULL); |
| 16727 | } else if (ret > 0) { |
| 16728 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16729 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16730 | Disabled, since the facet validation already reports errors. |
| 16731 | if (fireErrors) |
| 16732 | xmlSchemaVSimpleTypeErr(ctxt, ret, ctxt->cur, value, type); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16733 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16734 | } |
| 16735 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16736 | } |
| 16737 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
| 16738 | xmlSchemaTypeLinkPtr memberLink; |
| 16739 | |
| 16740 | /* |
| 16741 | * TODO: For all datatypes ·derived· by ·union· whiteSpace does |
| 16742 | * not apply directly; however, the normalization behavior of ·union· |
| 16743 | * types is controlled by the value of whiteSpace on that one of the |
| 16744 | * ·memberTypes· against which the ·union· is successfully validated. |
| 16745 | * |
| 16746 | * This means that the value is normalized by the first validating |
| 16747 | * member type, then the facets of the union type are applied. This |
| 16748 | * needs changing of the value! |
| 16749 | */ |
| 16750 | |
| 16751 | /* |
| 16752 | * 1.2.3 if {variety} is ·union· then the string must ·match· a |
| 16753 | * literal in the ·lexical space· of at least one member of |
| 16754 | * {member type definitions} |
| 16755 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16756 | #ifdef DEBUG_UNION_VALIDATION |
| 16757 | printf("Union ST : '%s'\n", (const char *) type->name); |
| 16758 | printf(" fireErrors : %d\n", fireErrors); |
| 16759 | printf(" applyFacets: %d\n", applyFacets); |
| 16760 | #endif |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16761 | memberLink = xmlSchemaGetUnionSimpleTypeMemberTypes(type); |
| 16762 | if (memberLink == NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16763 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16764 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16765 | "union simple type '%s' has no member types\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16766 | type->name, NULL); |
| 16767 | ret = -1; |
| 16768 | } |
| 16769 | if (ret == 0) { |
| 16770 | while (memberLink != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16771 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, memberLink->type, |
| 16772 | value, 0, 1, 1, 0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16773 | if ((ret <= 0) || (ret == 0)) |
| 16774 | break; |
| 16775 | memberLink = memberLink->next; |
| 16776 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16777 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16778 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16779 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16780 | "validating members of union simple type '%s'\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16781 | type->name, NULL); |
| 16782 | } else if (ret > 0) { |
| 16783 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16784 | if (fireErrors) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16785 | xmlSchemaVSimpleTypeErr(ctxt, ret, node, value, type); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16786 | } |
| 16787 | } |
| 16788 | /* |
| 16789 | * Apply facets (pattern, enumeration). |
| 16790 | */ |
| 16791 | if ((ret == 0) && (applyFacets) && (type->facetSet != NULL)) { |
| 16792 | int mws; |
| 16793 | /* |
| 16794 | * The normalization behavior of ·union· types is controlled by |
| 16795 | * the value of whiteSpace on that one of the ·memberTypes· |
| 16796 | * against which the ·union· is successfully validated. |
| 16797 | */ |
| 16798 | if (normValue != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16799 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16800 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 16801 | "the value was already normalized for the union simple " |
| 16802 | "type '%s'.\n", type->name, NULL); |
| 16803 | } |
| 16804 | mws = xmlSchemaGetWhiteSpaceFacetValue(memberLink->type); |
| 16805 | if (mws > ctxt->valueWS) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 16806 | if (mws == XML_SCHEMAS_FACET_COLLAPSE) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16807 | normValue = xmlSchemaCollapseString(value); |
| 16808 | else |
| 16809 | normValue = xmlSchemaWhiteSpaceReplace(value); |
| 16810 | if (normValue != NULL) |
| 16811 | value = (const xmlChar *) normValue; |
| 16812 | } |
| 16813 | |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 16814 | ret = xmlSchemaValidateFacetsInternal(ctxt, type, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16815 | value, 0, fireErrors); |
| 16816 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16817 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16818 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 16819 | "validating facets of union simple type '%s'\n", |
| 16820 | type->name, NULL); |
| 16821 | } else if (ret > 0) { |
| 16822 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3; |
| 16823 | /* |
| 16824 | if (fireErrors) |
| 16825 | xmlSchemaVSimpleTypeErr(ctxt, ret, ctxt->cur, value, type); |
| 16826 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16827 | } |
| 16828 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16829 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16830 | ctxt->valueWS = wtsp; |
| 16831 | if (normValue != NULL) |
| 16832 | xmlFree(normValue); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16833 | return (ret); |
| 16834 | } |
| 16835 | |
| 16836 | /** |
| 16837 | * xmlSchemaValidateSimpleTypeElement: |
| 16838 | * @ctxt: a schema validation context |
| 16839 | * @node: the element node to be validated. |
| 16840 | * |
| 16841 | * Validate the element against a simple type. |
| 16842 | * |
| 16843 | * Returns 0 if the element is valid, a positive error code |
| 16844 | * number otherwise and -1 in case of an internal or API error. |
| 16845 | */ |
| 16846 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16847 | xmlSchemaValidateElementBySimpleType(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16848 | xmlSchemaTypePtr type, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 16849 | int isNil, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16850 | int valSimpleContent) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16851 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16852 | xmlSchemaTypePtr oldtype; |
| 16853 | xmlNodePtr node; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16854 | xmlAttrPtr attr; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16855 | xmlNodePtr cur; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16856 | int ret = 0, retval = 0; |
| 16857 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16858 | if ((ctxt == NULL) || (type == NULL)) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16859 | xmlSchemaVCustomErr(ctxt, XML_SCHEMAV_INTERNAL, NULL, NULL, |
| 16860 | "Internal error: xmlSchemaValidateElementBySimpleType, " |
| 16861 | "bad arguments", NULL); |
| 16862 | return (-1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16863 | } |
| 16864 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16865 | oldtype = ctxt->type; |
| 16866 | node = ctxt->node; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16867 | /* |
| 16868 | * cvc-type: 3.1.2 The element information item must have no element |
| 16869 | * information item [children]. |
| 16870 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16871 | /* |
| 16872 | * STREAM: Child nodes are processed. |
| 16873 | */ |
| 16874 | cur = node->children; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16875 | while (cur != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16876 | /* |
| 16877 | * TODO: Entities, will they produce elements as well? |
| 16878 | */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16879 | if (cur->type == XML_ELEMENT_NODE) { |
| 16880 | xmlSchemaVCustomErr(ctxt, |
| 16881 | XML_SCHEMAV_CVC_TYPE_3_1_2, |
| 16882 | node, type, |
| 16883 | "No element content allowed", NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16884 | ret = XML_SCHEMAV_CVC_TYPE_3_1_2; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16885 | } |
| 16886 | cur = cur->next; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16887 | } |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16888 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16889 | /* |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16890 | * cvc-type 3.1.1: |
| 16891 | * |
| 16892 | * The attributes of must be empty, excepting those whose namespace name |
| 16893 | * is identical to http://www.w3.org/2001/XMLSchema-instance and whose local |
| 16894 | * name is one of type, nil, schemaLocation or noNamespaceSchemaLocation. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16895 | */ |
| 16896 | /* |
| 16897 | * STREAM: Attribute nodes are processed. |
| 16898 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16899 | attr = node->properties; |
| 16900 | while (attr != NULL) { |
| 16901 | if ((attr->ns == NULL) || |
| 16902 | (!xmlStrEqual(attr->ns->href, xmlSchemaInstanceNs)) || |
| 16903 | ((!xmlStrEqual(attr->name, BAD_CAST "type")) && |
| 16904 | (!xmlStrEqual(attr->name, BAD_CAST "nil")) && |
| 16905 | (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation")) && |
| 16906 | (!xmlStrEqual |
| 16907 | (attr->name, BAD_CAST "noNamespaceSchemaLocation")))) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16908 | xmlSchemaVIllegalAttrErr(ctxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16909 | XML_SCHEMAV_CVC_TYPE_3_1_1, attr); |
| 16910 | ret = XML_SCHEMAV_CVC_TYPE_3_1_1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16911 | } |
| 16912 | attr = attr->next; |
| 16913 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16914 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16915 | * This will skip validation if the type is 'anySimpleType' and |
| 16916 | * if the value was already validated (e.g. default values). |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16917 | */ |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 16918 | if ((! isNil) && |
| 16919 | (valSimpleContent == 1) && |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16920 | ((type->type != XML_SCHEMA_TYPE_BASIC) || |
| 16921 | (type->builtInType != XML_SCHEMAS_ANYSIMPLETYPE))) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16922 | xmlChar *value; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16923 | |
| 16924 | value = xmlNodeGetContent(node); |
| 16925 | /* |
| 16926 | * NOTE: This call will not check the content nodes, since |
| 16927 | * this should be checked here already. |
| 16928 | */ |
| 16929 | retval = xmlSchemaValidateSimpleTypeValue(ctxt, type, value, |
| 16930 | 1, 1, 1, 0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16931 | if (value != NULL) |
| 16932 | xmlFree(value); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16933 | if (retval != 0) |
| 16934 | ret = retval; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16935 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16936 | ctxt->type = oldtype; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16937 | return (ret); |
| 16938 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16939 | |
| 16940 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16941 | * xmlSchemaValQNameAcquire: |
| 16942 | * @value: the lexical represantation of the QName value |
| 16943 | * @node: the node to search for the corresponding namespace declaration |
| 16944 | * @nsName: the resulting namespace name if found |
| 16945 | * |
| 16946 | * Checks that a value conforms to the lexical space of the type QName; |
| 16947 | * if valid, the corresponding namespace name is searched and retured |
| 16948 | * as a copy in @nsName. The local name is returned in @localName as |
| 16949 | * a copy. |
| 16950 | * |
| 16951 | * Returns 0 if valid, 1 if not valid by type, 2 if no corresponding |
| 16952 | * namespace declaration was found in scope; -1 in case of an internal or |
| 16953 | * API error. |
| 16954 | */ |
| 16955 | static int |
| 16956 | xmlSchemaValQNameAcquire(const xmlChar *value, xmlNodePtr node, |
| 16957 | xmlChar **nsName, xmlChar **localName) |
| 16958 | { |
| 16959 | int ret; |
| 16960 | xmlChar *local = NULL; |
| 16961 | |
| 16962 | if ((nsName == NULL) || (localName == NULL) || (node == NULL)) |
| 16963 | return (-1); |
| 16964 | *nsName = NULL; |
| 16965 | *localName = NULL; |
| 16966 | ret = xmlValidateQName(value, 1); |
| 16967 | if (ret == 0) { |
| 16968 | xmlChar *prefix; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16969 | xmlNsPtr ns; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16970 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16971 | /* |
| 16972 | * NOTE: xmlSplitQName2 will return a duplicated |
| 16973 | * string. |
| 16974 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16975 | local = xmlSplitQName2(value, &prefix); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16976 | if (local == NULL) |
| 16977 | local = xmlStrdup(value); |
| 16978 | ns = xmlSearchNs(node->doc, node, prefix); |
| 16979 | /* |
| 16980 | * A namespace need not to be found if the prefix is NULL. |
| 16981 | */ |
| 16982 | if (ns != NULL) { |
| 16983 | /* |
| 16984 | * TODO: Is it necessary to duplicate the URI here? |
| 16985 | */ |
| 16986 | *nsName = xmlStrdup(ns->href); |
| 16987 | } else if (prefix != NULL) { |
| 16988 | xmlFree(prefix); |
| 16989 | if (local != NULL) |
| 16990 | xmlFree(local); |
| 16991 | return (2); |
| 16992 | } |
| 16993 | *localName = local; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16994 | if (prefix != NULL) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16995 | xmlFree(prefix); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16996 | } else |
| 16997 | return (1); |
| 16998 | return (ret); |
| 16999 | } |
| 17000 | |
| 17001 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17002 | * xmlSchemaHasElemContent: |
| 17003 | * @node: the node |
| 17004 | * |
| 17005 | * Scours the content of the given node for element |
| 17006 | * nodes. |
| 17007 | * |
| 17008 | * Returns 1 if an element node is found, |
| 17009 | * 0 otherwise. |
| 17010 | */ |
| 17011 | static int |
| 17012 | xmlSchemaHasElemContent(xmlNodePtr node) |
| 17013 | { |
| 17014 | if (node == NULL) |
| 17015 | return (0); |
| 17016 | node = node->children; |
| 17017 | while (node != NULL) { |
| 17018 | if (node->type == XML_ELEMENT_NODE) |
| 17019 | return (1); |
| 17020 | node = node->next; |
| 17021 | } |
| 17022 | return (0); |
| 17023 | } |
| 17024 | /** |
| 17025 | * xmlSchemaHasElemOrCharContent: |
| 17026 | * @node: the node |
| 17027 | * |
| 17028 | * Scours the content of the given node for element |
| 17029 | * and character nodes. |
| 17030 | * |
| 17031 | * Returns 1 if an element or character node is found, |
| 17032 | * 0 otherwise. |
| 17033 | */ |
| 17034 | static int |
| 17035 | xmlSchemaHasElemOrCharContent(xmlNodePtr node) |
| 17036 | { |
| 17037 | if (node == NULL) |
| 17038 | return (0); |
| 17039 | node = node->children; |
| 17040 | while (node != NULL) { |
| 17041 | switch (node->type) { |
| 17042 | case XML_ELEMENT_NODE: |
| 17043 | /* |
| 17044 | * TODO: Ask Daniel if these are all character nodes. |
| 17045 | */ |
| 17046 | case XML_TEXT_NODE: |
| 17047 | case XML_CDATA_SECTION_NODE: |
| 17048 | /* |
| 17049 | * TODO: How XML_ENTITY_NODEs evaluated? |
| 17050 | */ |
| 17051 | case XML_ENTITY_REF_NODE: |
| 17052 | case XML_ENTITY_NODE: |
| 17053 | return (1); |
| 17054 | break; |
| 17055 | default: |
| 17056 | break; |
| 17057 | } |
| 17058 | node = node->next; |
| 17059 | } |
| 17060 | return (0); |
| 17061 | } |
| 17062 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17063 | /************************************************************************ |
| 17064 | * * |
| 17065 | * Identity-constraints (IDC) * |
| 17066 | * * |
| 17067 | ************************************************************************/ |
| 17068 | |
| 17069 | #ifdef IDC_ENABLED |
| 17070 | |
| 17071 | /** |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17072 | * xmlSchemaAugmentIDC: |
| 17073 | * @idcDef: the IDC definition |
| 17074 | * |
| 17075 | * Creates an augmented IDC definition item. |
| 17076 | * |
| 17077 | * Returns the item, or NULL on internal errors. |
| 17078 | */ |
| 17079 | static void |
| 17080 | xmlSchemaAugmentIDC(xmlSchemaIDCPtr idcDef, |
| 17081 | xmlSchemaValidCtxtPtr vctxt) |
| 17082 | { |
| 17083 | xmlSchemaIDCAugPtr aidc; |
| 17084 | |
| 17085 | aidc = (xmlSchemaIDCAugPtr) xmlMalloc(sizeof(xmlSchemaIDCAug)); |
| 17086 | if (aidc == NULL) { |
| 17087 | xmlSchemaVErrMemory(vctxt, |
| 17088 | "xmlSchemaAugmentIDC: allocating an augmented IDC definition", |
| 17089 | NULL); |
| 17090 | return; |
| 17091 | } |
| 17092 | aidc->bubbleDepth = -1; |
| 17093 | aidc->def = idcDef; |
| 17094 | aidc->next = NULL; |
| 17095 | if (vctxt->aidcs == NULL) |
| 17096 | vctxt->aidcs = aidc; |
| 17097 | else { |
| 17098 | aidc->next = vctxt->aidcs; |
| 17099 | vctxt->aidcs = aidc; |
| 17100 | } |
| 17101 | } |
| 17102 | |
| 17103 | /** |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17104 | * xmlSchemaIDCNewBinding: |
| 17105 | * @idcDef: the IDC definition of this binding |
| 17106 | * |
| 17107 | * Creates a new IDC binding. |
| 17108 | * |
| 17109 | * Returns the new binding in case of succeeded, NULL on internal errors. |
| 17110 | */ |
| 17111 | static xmlSchemaPSVIIDCBindingPtr |
| 17112 | xmlSchemaIDCNewBinding(xmlSchemaIDCPtr idcDef) |
| 17113 | { |
| 17114 | xmlSchemaPSVIIDCBindingPtr ret; |
| 17115 | |
| 17116 | ret = (xmlSchemaPSVIIDCBindingPtr) xmlMalloc( |
| 17117 | sizeof(xmlSchemaPSVIIDCBinding)); |
| 17118 | if (ret == NULL) { |
| 17119 | xmlSchemaVErrMemory(NULL, |
| 17120 | "allocating a PSVI IDC binding item", NULL); |
| 17121 | return (NULL); |
| 17122 | } |
| 17123 | memset(ret, 0, sizeof(xmlSchemaPSVIIDCBinding)); |
| 17124 | ret->definition = idcDef; |
| 17125 | return (ret); |
| 17126 | } |
| 17127 | |
| 17128 | /** |
| 17129 | * xmlSchemaIDCStoreNodeTableItem: |
| 17130 | * @vctxt: the WXS validation context |
| 17131 | * @item: the IDC node table item |
| 17132 | * |
| 17133 | * The validation context is used to store an IDC node table items. |
| 17134 | * They are stored to avoid copying them if IDC node-tables are merged |
| 17135 | * with corresponding parent IDC node-tables (bubbling). |
| 17136 | * |
| 17137 | * Returns 0 if succeeded, -1 on internal errors. |
| 17138 | */ |
| 17139 | static int |
| 17140 | xmlSchemaIDCStoreNodeTableItem(xmlSchemaValidCtxtPtr vctxt, |
| 17141 | xmlSchemaPSVIIDCNodePtr item) |
| 17142 | { |
| 17143 | /* |
| 17144 | * Add to gobal list. |
| 17145 | */ |
| 17146 | if (vctxt->idcNodes == NULL) { |
| 17147 | vctxt->idcNodes = (xmlSchemaPSVIIDCNodePtr *) |
| 17148 | xmlMalloc(20 * sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 17149 | if (vctxt->idcNodes == NULL) { |
| 17150 | xmlSchemaVErrMemory(vctxt, |
| 17151 | "allocating the IDC node table item list", NULL); |
| 17152 | return (-1); |
| 17153 | } |
| 17154 | vctxt->sizeIdcNodes = 20; |
| 17155 | } else if (vctxt->sizeIdcNodes <= vctxt->nbIdcNodes) { |
| 17156 | vctxt->sizeIdcNodes *= 2; |
| 17157 | vctxt->idcNodes = (xmlSchemaPSVIIDCNodePtr *) |
| 17158 | xmlRealloc(vctxt->idcNodes, vctxt->sizeIdcNodes * |
| 17159 | sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 17160 | if (vctxt->idcNodes == NULL) { |
| 17161 | xmlSchemaVErrMemory(vctxt, |
| 17162 | "re-allocating the IDC node table item list", NULL); |
| 17163 | return (-1); |
| 17164 | } |
| 17165 | } |
| 17166 | vctxt->idcNodes[vctxt->nbIdcNodes++] = item; |
| 17167 | |
| 17168 | return (0); |
| 17169 | } |
| 17170 | |
| 17171 | /** |
| 17172 | * xmlSchemaIDCStoreKey: |
| 17173 | * @vctxt: the WXS validation context |
| 17174 | * @item: the IDC key |
| 17175 | * |
| 17176 | * The validation context is used to store an IDC key. |
| 17177 | * |
| 17178 | * Returns 0 if succeeded, -1 on internal errors. |
| 17179 | */ |
| 17180 | static int |
| 17181 | xmlSchemaIDCStoreKey(xmlSchemaValidCtxtPtr vctxt, |
| 17182 | xmlSchemaPSVIIDCKeyPtr key) |
| 17183 | { |
| 17184 | /* |
| 17185 | * Add to gobal list. |
| 17186 | */ |
| 17187 | if (vctxt->idcKeys == NULL) { |
| 17188 | vctxt->idcKeys = (xmlSchemaPSVIIDCKeyPtr *) |
| 17189 | xmlMalloc(40 * sizeof(xmlSchemaPSVIIDCKeyPtr)); |
| 17190 | if (vctxt->idcKeys == NULL) { |
| 17191 | xmlSchemaVErrMemory(vctxt, |
| 17192 | "allocating the IDC key storage list", NULL); |
| 17193 | return (-1); |
| 17194 | } |
| 17195 | vctxt->sizeIdcKeys = 40; |
| 17196 | } else if (vctxt->sizeIdcKeys <= vctxt->nbIdcKeys) { |
| 17197 | vctxt->sizeIdcKeys *= 2; |
| 17198 | vctxt->idcKeys = (xmlSchemaPSVIIDCKeyPtr *) |
| 17199 | xmlRealloc(vctxt->idcKeys, vctxt->sizeIdcKeys * |
| 17200 | sizeof(xmlSchemaPSVIIDCKeyPtr)); |
| 17201 | if (vctxt->idcKeys == NULL) { |
| 17202 | xmlSchemaVErrMemory(vctxt, |
| 17203 | "re-allocating the IDC key storage list", NULL); |
| 17204 | return (-1); |
| 17205 | } |
| 17206 | } |
| 17207 | vctxt->idcKeys[vctxt->nbIdcKeys++] = key; |
| 17208 | |
| 17209 | return (0); |
| 17210 | } |
| 17211 | |
| 17212 | /** |
| 17213 | * xmlSchemaIDCAppendNodeTableItem: |
| 17214 | * @bind: the IDC binding |
| 17215 | * @ntItem: the node-table item |
| 17216 | * |
| 17217 | * Appends the IDC node-table item to the binding. |
| 17218 | * |
| 17219 | * Returns 0 on success and -1 on internal errors. |
| 17220 | */ |
| 17221 | static int |
| 17222 | xmlSchemaIDCAppendNodeTableItem(xmlSchemaPSVIIDCBindingPtr bind, |
| 17223 | xmlSchemaPSVIIDCNodePtr ntItem) |
| 17224 | { |
| 17225 | if (bind->nodeTable == NULL) { |
| 17226 | bind->sizeNodes = 10; |
| 17227 | bind->nodeTable = (xmlSchemaPSVIIDCNodePtr *) |
| 17228 | xmlMalloc(10 * sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 17229 | if (bind->nodeTable == NULL) { |
| 17230 | xmlSchemaVErrMemory(NULL, |
| 17231 | "allocating an array of IDC node-table items", NULL); |
| 17232 | return(-1); |
| 17233 | } |
| 17234 | } else if (bind->sizeNodes <= bind->nbNodes) { |
| 17235 | bind->sizeNodes *= 2; |
| 17236 | bind->nodeTable = (xmlSchemaPSVIIDCNodePtr *) |
| 17237 | xmlRealloc(bind->nodeTable, bind->sizeNodes * |
| 17238 | sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 17239 | if (bind->nodeTable == NULL) { |
| 17240 | xmlSchemaVErrMemory(NULL, |
| 17241 | "re-allocating an array of IDC node-table items", NULL); |
| 17242 | return(-1); |
| 17243 | } |
| 17244 | } |
| 17245 | bind->nodeTable[bind->nbNodes++] = ntItem; |
| 17246 | return(0); |
| 17247 | } |
| 17248 | |
| 17249 | /** |
| 17250 | * xmlSchemaIDCAquireBinding: |
| 17251 | * @vctxt: the WXS validation context |
| 17252 | * @matcher: the IDC matcher |
| 17253 | * |
| 17254 | * Looks up an PSVI IDC binding, for the IDC definition and |
| 17255 | * of the given matcher. If none found, a new one is created |
| 17256 | * and added to the IDC table. |
| 17257 | * |
| 17258 | * Returns an IDC binding or NULL on internal errors. |
| 17259 | */ |
| 17260 | static xmlSchemaPSVIIDCBindingPtr |
| 17261 | xmlSchemaIDCAquireBinding(xmlSchemaValidCtxtPtr vctxt, |
| 17262 | xmlSchemaIDCMatcherPtr matcher) |
| 17263 | { |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 17264 | xmlSchemaNodeInfoPtr info; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17265 | |
| 17266 | info = vctxt->elemInfos[matcher->depth]; |
| 17267 | |
| 17268 | if (info->idcTable == NULL) { |
| 17269 | info->idcTable = xmlSchemaIDCNewBinding(matcher->aidc->def); |
| 17270 | if (info->idcTable == NULL) |
| 17271 | return (NULL); |
| 17272 | return(info->idcTable); |
| 17273 | } else { |
| 17274 | xmlSchemaPSVIIDCBindingPtr bind = NULL; |
| 17275 | |
| 17276 | bind = info->idcTable; |
| 17277 | do { |
| 17278 | if (bind->definition == matcher->aidc->def) |
| 17279 | return(bind); |
| 17280 | if (bind->next == NULL) { |
| 17281 | bind->next = xmlSchemaIDCNewBinding(matcher->aidc->def); |
| 17282 | if (bind->next == NULL) |
| 17283 | return (NULL); |
| 17284 | return(bind->next); |
| 17285 | } |
| 17286 | bind = bind->next; |
| 17287 | } while (bind != NULL); |
| 17288 | } |
| 17289 | return (NULL); |
| 17290 | } |
| 17291 | |
| 17292 | /** |
| 17293 | * xmlSchemaIDCFreeKey: |
| 17294 | * @key: the IDC key |
| 17295 | * |
| 17296 | * Frees an IDC key together with its compiled value. |
| 17297 | */ |
| 17298 | static void |
| 17299 | xmlSchemaIDCFreeKey(xmlSchemaPSVIIDCKeyPtr key) |
| 17300 | { |
| 17301 | if (key->compValue != NULL) |
| 17302 | xmlSchemaFreeValue(key->compValue); |
| 17303 | xmlFree(key); |
| 17304 | } |
| 17305 | |
| 17306 | /** |
| 17307 | * xmlSchemaIDCFreeBinding: |
| 17308 | * |
| 17309 | * Frees an IDC binding. Note that the node table-items |
| 17310 | * are not freed. |
| 17311 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17312 | static void |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17313 | xmlSchemaIDCFreeBinding(xmlSchemaPSVIIDCBindingPtr bind) |
| 17314 | { |
| 17315 | if (bind->nodeTable != NULL) { |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 17316 | if (bind->definition->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 17317 | int i; |
| 17318 | /* |
| 17319 | * Node-table items for keyrefs are not stored globally |
| 17320 | * to the validation context, since they are not bubbled. |
| 17321 | * We need to free them here. |
| 17322 | */ |
| 17323 | for (i = 0; i < bind->nbNodes; i++) { |
| 17324 | xmlFree(bind->nodeTable[i]->keys); |
| 17325 | xmlFree(bind->nodeTable[i]); |
| 17326 | } |
| 17327 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17328 | xmlFree(bind->nodeTable); |
| 17329 | } |
| 17330 | xmlFree(bind); |
| 17331 | } |
| 17332 | |
| 17333 | /** |
| 17334 | * xmlSchemaIDCFreeIDCTable: |
| 17335 | * @bind: the first IDC binding in the list |
| 17336 | * |
| 17337 | * Frees an IDC table, i.e. all the IDC bindings in the list. |
| 17338 | */ |
| 17339 | static void |
| 17340 | xmlSchemaIDCFreeIDCTable(xmlSchemaPSVIIDCBindingPtr bind) |
| 17341 | { |
| 17342 | xmlSchemaPSVIIDCBindingPtr prev; |
| 17343 | |
| 17344 | while (bind != NULL) { |
| 17345 | prev = bind; |
| 17346 | bind = bind->next; |
| 17347 | xmlSchemaIDCFreeBinding(prev); |
| 17348 | } |
| 17349 | } |
| 17350 | |
| 17351 | /** |
| 17352 | * xmlSchemaIDCFreeMatcherList: |
| 17353 | * @matcher: the first IDC matcher in the list |
| 17354 | * |
| 17355 | * Frees a list of IDC matchers. |
| 17356 | */ |
| 17357 | static void |
| 17358 | xmlSchemaIDCFreeMatcherList(xmlSchemaIDCMatcherPtr matcher) |
| 17359 | { |
| 17360 | xmlSchemaIDCMatcherPtr next; |
| 17361 | |
| 17362 | while (matcher != NULL) { |
| 17363 | next = matcher->next; |
| 17364 | if (matcher->keySeqs != NULL) { |
| 17365 | int i; |
| 17366 | for (i = 0; i < matcher->sizeKeySeqs; i++) |
| 17367 | if (matcher->keySeqs[i] != NULL) |
| 17368 | xmlFree(matcher->keySeqs[i]); |
| 17369 | xmlFree(matcher->keySeqs); |
| 17370 | } |
| 17371 | xmlFree(matcher); |
| 17372 | matcher = next; |
| 17373 | } |
| 17374 | } |
| 17375 | |
| 17376 | /** |
| 17377 | * xmlSchemaAreValuesEqual: |
| 17378 | * @ta: the first type |
| 17379 | * @a: the first value |
| 17380 | * @tb: the second type |
| 17381 | * @b: the second value |
| 17382 | * |
| 17383 | * Compares two values. |
| 17384 | * |
| 17385 | * Returns 1 if they are equal, 0 if not and -1 on internal errors. |
| 17386 | */ |
| 17387 | static int |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17388 | xmlSchemaAreValuesEqual(xmlSchemaValidCtxtPtr vctxt, |
| 17389 | xmlSchemaTypePtr ta, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17390 | xmlSchemaValPtr a, |
| 17391 | xmlSchemaTypePtr tb, |
| 17392 | xmlSchemaValPtr b) |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17393 | { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17394 | /* Same user derived/built-in derived/built-in primitive types. */ |
| 17395 | if (ta == tb) |
| 17396 | goto compareValue; |
| 17397 | |
| 17398 | /* |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 17399 | * Note that comparison with anySimpleTypes with be supported for |
| 17400 | * string based types as well. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17401 | */ |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 17402 | #if 0 |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17403 | if ((ta->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) || |
| 17404 | (tb->builtInType == XML_SCHEMAS_ANYSIMPLETYPE)) |
| 17405 | return(0); |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 17406 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17407 | |
| 17408 | /* |
| 17409 | * 4.2.1 equal (data-types) |
| 17410 | * |
| 17411 | * the ·value space·s of all ·primitive· datatypes are disjoint |
| 17412 | * (they do not share any values) |
| 17413 | */ |
| 17414 | if ((ta->builtInType != 0) && (tb->builtInType != 0) && |
| 17415 | (ta->flags & XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE) && |
| 17416 | (tb->flags & XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE)) |
| 17417 | return(0); |
| 17418 | |
| 17419 | if ((ta->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) || |
| 17420 | (ta->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) || |
| 17421 | (tb->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) || |
| 17422 | (tb->flags & XML_SCHEMAS_TYPE_VARIETY_UNION)) { |
| 17423 | TODO |
| 17424 | return(0); |
| 17425 | } |
| 17426 | /* |
| 17427 | * (1) if a datatype T' is ·derived· by ·restriction· from an atomic datatype |
| 17428 | * T then the ·value space· of T' is a subset of the ·value space· of T. |
| 17429 | */ |
| 17430 | /* |
| 17431 | * (2) if datatypes T' and T'' are ·derived· by ·restriction· from a common |
| 17432 | * atomic ancestor T then the ·value space·s of T' and T'' may overlap. |
| 17433 | */ |
| 17434 | |
| 17435 | { |
| 17436 | xmlSchemaTypePtr pta = ta, ptb = tb; |
| 17437 | |
| 17438 | /* Note that we will compare the primitives here. */ |
| 17439 | while ((pta->builtInType == 0) || |
| 17440 | ((pta->flags & XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE) == 0)) |
| 17441 | pta = pta->baseType; |
| 17442 | while ((ptb->builtInType == 0) || |
| 17443 | ((ptb->flags & XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE) == 0)) |
| 17444 | ptb = ptb->baseType; |
| 17445 | if (pta == ptb) |
| 17446 | goto compareValue; |
| 17447 | return(0); |
| 17448 | } |
| 17449 | compareValue: |
| 17450 | { |
| 17451 | #ifdef IDC_VALUE_SUPPORT |
| 17452 | int ret; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 17453 | int aws, bws; |
| 17454 | |
| 17455 | aws = xmlSchemaGetWhiteSpaceFacetValue(ta); |
| 17456 | bws = xmlSchemaGetWhiteSpaceFacetValue(tb); |
| 17457 | |
| 17458 | ret = xmlSchemaCompareValuesWhtsp( |
| 17459 | a, (xmlSchemaWhitespaceValueType) aws, |
| 17460 | b, (xmlSchemaWhitespaceValueType) bws); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17461 | if (ret == 0) |
| 17462 | return(1); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17463 | else if (ret == -2) { |
| 17464 | xmlSchemaVErr(vctxt, vctxt->node, |
| 17465 | XML_SCHEMAV_INTERNAL, |
| 17466 | "Internal error: xmlSchemaAreValuesEqual, " |
| 17467 | "failed to compare the values.\n", |
| 17468 | NULL, NULL); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17469 | return(-1); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17470 | } else |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17471 | return(0); |
| 17472 | #else |
| 17473 | return (1); |
| 17474 | #endif |
| 17475 | } |
| 17476 | } |
| 17477 | |
| 17478 | /** |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17479 | * xmlSchemaIDCAddStateObject: |
| 17480 | * @vctxt: the WXS validation context |
| 17481 | * @matcher: the IDC matcher |
| 17482 | * @sel: the XPath information |
| 17483 | * @parent: the parent "selector" state object if any |
| 17484 | * @type: "selector" or "field" |
| 17485 | * |
| 17486 | * Creates/reuses and activates state objects for the given |
| 17487 | * XPath information; if the XPath expression consists of unions, |
| 17488 | * multiple state objects are created for every unioned expression. |
| 17489 | * |
| 17490 | * Returns 0 on success and -1 on internal errors. |
| 17491 | */ |
| 17492 | static int |
| 17493 | xmlSchemaIDCAddStateObject(xmlSchemaValidCtxtPtr vctxt, |
| 17494 | xmlSchemaIDCMatcherPtr matcher, |
| 17495 | xmlSchemaIDCSelectPtr sel, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17496 | int type) |
| 17497 | { |
| 17498 | xmlSchemaIDCStateObjPtr sto; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17499 | |
| 17500 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17501 | * Reuse the state objects from the pool. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17502 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17503 | if (vctxt->xpathStatePool != NULL) { |
| 17504 | sto = vctxt->xpathStatePool; |
| 17505 | vctxt->xpathStatePool = sto->next; |
| 17506 | sto->next = NULL; |
| 17507 | } else { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17508 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17509 | * Create a new state object. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17510 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17511 | sto = (xmlSchemaIDCStateObjPtr) xmlMalloc(sizeof(xmlSchemaIDCStateObj)); |
| 17512 | if (sto == NULL) { |
| 17513 | xmlSchemaVErrMemory(NULL, |
| 17514 | "allocating an IDC state object", NULL); |
| 17515 | return (-1); |
| 17516 | } |
| 17517 | memset(sto, 0, sizeof(xmlSchemaIDCStateObj)); |
| 17518 | } |
| 17519 | /* |
| 17520 | * Add to global list. |
| 17521 | */ |
| 17522 | if (vctxt->xpathStates != NULL) |
| 17523 | sto->next = vctxt->xpathStates; |
| 17524 | vctxt->xpathStates = sto; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17525 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17526 | /* |
| 17527 | * Free the old xpath validation context. |
| 17528 | */ |
| 17529 | if (sto->xpathCtxt != NULL) |
| 17530 | xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt); |
| 17531 | |
| 17532 | /* |
| 17533 | * Create a new XPath (pattern) validation context. |
| 17534 | */ |
| 17535 | sto->xpathCtxt = (void *) xmlPatternGetStreamCtxt( |
| 17536 | (xmlPatternPtr) sel->xpathComp); |
| 17537 | if (sto->xpathCtxt == NULL) { |
| 17538 | xmlSchemaVErr(vctxt, vctxt->node, |
| 17539 | XML_SCHEMAV_INTERNAL, |
| 17540 | "Internal error: xmlSchemaIDCAddStateObject, " |
| 17541 | "failed to create the XPath validation context.\n", |
| 17542 | NULL, NULL); |
| 17543 | return (-1); |
| 17544 | } |
| 17545 | sto->type = type; |
| 17546 | sto->depth = vctxt->depth; |
| 17547 | sto->matcher = matcher; |
| 17548 | sto->sel = sel; |
| 17549 | sto->nbHistory = 0; |
| 17550 | |
| 17551 | #if DEBUG_IDC |
| 17552 | xmlGenericError(xmlGenericErrorContext, "IDC: STO push '%s'\n", |
| 17553 | sto->sel->xpath); |
| 17554 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17555 | return (0); |
| 17556 | } |
| 17557 | |
| 17558 | /** |
| 17559 | * xmlSchemaXPathEvaluate: |
| 17560 | * @vctxt: the WXS validation context |
| 17561 | * @nodeType: the nodeType of the current node |
| 17562 | * |
| 17563 | * Evaluates all active XPath state objects. |
| 17564 | * |
| 17565 | * Returns the number of IC "field" state objects which resolved to |
| 17566 | * this node, 0 if none resolved and -1 on internal errors. |
| 17567 | */ |
| 17568 | static int |
| 17569 | xmlSchemaXPathEvaluate(xmlSchemaValidCtxtPtr vctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17570 | xmlElementType nodeType) |
| 17571 | { |
| 17572 | xmlSchemaIDCStateObjPtr sto, head = NULL, first; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17573 | int res, resolved = 0, depth = vctxt->depth; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17574 | |
| 17575 | if (vctxt->xpathStates == NULL) |
| 17576 | return (0); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17577 | |
| 17578 | if (nodeType == XML_ATTRIBUTE_NODE) |
| 17579 | depth++; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17580 | #if DEBUG_IDC |
| 17581 | { |
| 17582 | xmlChar *str = NULL; |
| 17583 | xmlGenericError(xmlGenericErrorContext, |
| 17584 | "IDC: EVAL on %s, depth %d, type %d\n", |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17585 | xmlSchemaFormatNsUriLocal(&str, vctxt->nodeInfo->namespaceName, |
| 17586 | vctxt->nodeInfo->localName), depth, nodeType); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17587 | FREE_AND_NULL(str) |
| 17588 | } |
| 17589 | #endif |
| 17590 | /* |
| 17591 | * Process all active XPath state objects. |
| 17592 | */ |
| 17593 | first = vctxt->xpathStates; |
| 17594 | sto = first; |
| 17595 | while (sto != head) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17596 | #if DEBUG_IDC |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17597 | if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17598 | xmlGenericError(xmlGenericErrorContext, "IDC: ['%s'] selector '%s'\n", |
| 17599 | sto->matcher->aidc->def->name, sto->sel->xpath); |
| 17600 | else |
| 17601 | xmlGenericError(xmlGenericErrorContext, "IDC: ['%s'] field '%s'\n", |
| 17602 | sto->matcher->aidc->def->name, sto->sel->xpath); |
| 17603 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17604 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17605 | #ifdef IDC_XPATH_SUPPORT |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17606 | if (nodeType == XML_ELEMENT_NODE) |
| 17607 | res = xmlStreamPush((xmlStreamCtxtPtr) sto->xpathCtxt, |
| 17608 | vctxt->nodeInfo->localName, vctxt->nodeInfo->namespaceName); |
| 17609 | else |
| 17610 | res = xmlStreamPushAttr((xmlStreamCtxtPtr) sto->xpathCtxt, |
| 17611 | vctxt->nodeInfo->localName, vctxt->nodeInfo->namespaceName); |
| 17612 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17613 | #else |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17614 | res = 0; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 17615 | #endif |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17616 | if (res == -1) { |
| 17617 | xmlSchemaVErr(vctxt, vctxt->node, |
| 17618 | XML_SCHEMAV_INTERNAL, |
| 17619 | "Internal error: xmlSchemaXPathEvaluate, " |
| 17620 | "failed to evaluate a node.\n", |
| 17621 | NULL, NULL); |
| 17622 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17623 | } |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17624 | if (res == 0) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17625 | goto next_sto; |
| 17626 | /* |
| 17627 | * Full match. |
| 17628 | */ |
| 17629 | #if DEBUG_IDC |
| 17630 | xmlGenericError(xmlGenericErrorContext, "IDC: " |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17631 | "MATCH\n"); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17632 | #endif |
| 17633 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17634 | * Register a match in the state object history. |
| 17635 | */ |
| 17636 | if (sto->history == NULL) { |
| 17637 | sto->history = (int *) xmlMalloc(5 * sizeof(int)); |
| 17638 | if (sto->history == NULL) { |
| 17639 | xmlSchemaVErrMemory(NULL, |
| 17640 | "allocating the state object history", NULL); |
| 17641 | return(-1); |
| 17642 | } |
| 17643 | sto->sizeHistory = 10; |
| 17644 | } else if (sto->sizeHistory <= sto->nbHistory) { |
| 17645 | sto->sizeHistory *= 2; |
| 17646 | sto->history = (int *) xmlRealloc(sto->history, |
| 17647 | sto->sizeHistory * sizeof(int)); |
| 17648 | if (sto->history == NULL) { |
| 17649 | xmlSchemaVErrMemory(NULL, |
| 17650 | "re-allocating the state object history", NULL); |
| 17651 | return(-1); |
| 17652 | } |
| 17653 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17654 | sto->history[sto->nbHistory++] = depth; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17655 | |
| 17656 | #ifdef DEBUG_IDC |
| 17657 | xmlGenericError(xmlGenericErrorContext, "IDC: push match '%d'\n", |
| 17658 | vctxt->depth); |
| 17659 | #endif |
| 17660 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17661 | if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) { |
| 17662 | xmlSchemaIDCSelectPtr sel; |
| 17663 | /* |
| 17664 | * Activate state objects for the IDC fields of |
| 17665 | * the IDC selector. |
| 17666 | */ |
| 17667 | #if DEBUG_IDC |
| 17668 | xmlGenericError(xmlGenericErrorContext, "IDC: " |
| 17669 | "activating field states\n"); |
| 17670 | #endif |
| 17671 | sel = sto->matcher->aidc->def->fields; |
| 17672 | while (sel != NULL) { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17673 | if (xmlSchemaIDCAddStateObject(vctxt, sto->matcher, |
| 17674 | sel, XPATH_STATE_OBJ_TYPE_IDC_FIELD) == -1) |
| 17675 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17676 | sel = sel->next; |
| 17677 | } |
| 17678 | } else if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_FIELD) { |
| 17679 | /* |
| 17680 | * An IDC key node was found. |
| 17681 | */ |
| 17682 | #if DEBUG_IDC |
| 17683 | xmlGenericError(xmlGenericErrorContext, |
| 17684 | "IDC: key found\n"); |
| 17685 | #endif |
| 17686 | /* |
| 17687 | * Notify that the character value of this node is |
| 17688 | * needed. |
| 17689 | */ |
| 17690 | if (resolved == 0) |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17691 | vctxt->nodeInfo->flags |= XML_SCHEMA_ELEM_INFO_VALUE_NEEDED; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17692 | resolved++; |
| 17693 | } |
| 17694 | next_sto: |
| 17695 | if (sto->next == NULL) { |
| 17696 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17697 | * Evaluate field state objects created on this node as well. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17698 | */ |
| 17699 | head = first; |
| 17700 | sto = vctxt->xpathStates; |
| 17701 | } else |
| 17702 | sto = sto->next; |
| 17703 | } |
| 17704 | return (resolved); |
| 17705 | } |
| 17706 | |
| 17707 | /** |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 17708 | * xmlSchemaXPathProcessHistory: |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17709 | * @vctxt: the WXS validation context |
| 17710 | * @type: the simple/complex type of the current node if any at all |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 17711 | * @compValue: the precompiled value |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17712 | * |
| 17713 | * Processes and pops the history items of the IDC state objects. |
| 17714 | * IDC key-sequences are validated/created on IDC bindings. |
| 17715 | * |
| 17716 | * Returns 0 on success and -1 on internal errors. |
| 17717 | */ |
| 17718 | static int |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 17719 | xmlSchemaXPathProcessHistory(xmlSchemaValidCtxtPtr vctxt, |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17720 | int depth) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17721 | { |
| 17722 | xmlSchemaIDCStateObjPtr sto, nextsto; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17723 | int res, matchDepth; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17724 | xmlSchemaPSVIIDCKeyPtr key = NULL; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17725 | xmlSchemaTypePtr type = vctxt->nodeInfo->typeDef; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17726 | |
| 17727 | if (vctxt->xpathStates == NULL) |
| 17728 | return (0); |
| 17729 | sto = vctxt->xpathStates; |
| 17730 | |
| 17731 | #if DEBUG_IDC |
| 17732 | { |
| 17733 | xmlChar *str = NULL; |
| 17734 | xmlGenericError(xmlGenericErrorContext, |
| 17735 | "IDC: BACK on %s, depth %d\n", |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17736 | xmlSchemaFormatNsUriLocal(&str, vctxt->nodeInfo->namespaceName, |
| 17737 | vctxt->nodeInfo->localName), vctxt->depth); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17738 | FREE_AND_NULL(str) |
| 17739 | } |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 17740 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17741 | /* |
| 17742 | * Evaluate the state objects. |
| 17743 | */ |
| 17744 | while (sto != NULL) { |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 17745 | #ifdef IDC_XPATH_SUPPORT |
| 17746 | xmlStreamPop((xmlStreamCtxtPtr) sto->xpathCtxt); |
| 17747 | #if DEBUG_IDC |
| 17748 | xmlGenericError(xmlGenericErrorContext, "IDC: stream pop '%s'\n", |
| 17749 | sto->sel->xpath); |
| 17750 | #endif |
| 17751 | #endif |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17752 | if (sto->nbHistory == 0) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17753 | goto deregister_check; |
| 17754 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17755 | matchDepth = sto->history[sto->nbHistory -1]; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17756 | |
| 17757 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17758 | * Only matches at the current depth are of interest. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17759 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17760 | if (matchDepth != depth) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17761 | sto = sto->next; |
| 17762 | continue; |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 17763 | } |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17764 | if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_FIELD) { |
| 17765 | if (! IS_SIMPLE_TYPE(type)) { |
| 17766 | /* |
| 17767 | * Not qualified if the field resolves to a node of non |
| 17768 | * simple type. |
| 17769 | */ |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 17770 | xmlSchemaStreamVCustomErr(vctxt, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17771 | XML_SCHEMAV_CVC_IDC, |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 17772 | vctxt->nodeInfo, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17773 | (xmlSchemaTypePtr) sto->matcher->aidc->def, |
| 17774 | "The field '%s' does evaluate to a node of " |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 17775 | "non-simple type", sto->sel->xpath, NULL); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17776 | |
| 17777 | sto->nbHistory--; |
| 17778 | goto deregister_check; |
| 17779 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17780 | if ((key == NULL) && (vctxt->nodeInfo->value == NULL)) { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17781 | /* |
| 17782 | * Failed to provide the normalized value; maby |
| 17783 | * the value was invalid. |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 17784 | */ |
| 17785 | xmlSchemaStreamVCustomErr(vctxt, |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 17786 | XML_SCHEMAV_CVC_IDC, |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 17787 | vctxt->nodeInfo, |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 17788 | (xmlSchemaTypePtr) sto->matcher->aidc->def, |
| 17789 | "Warning: No precomputed value available, the value " |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 17790 | "was either invalid or something strange happend", |
| 17791 | NULL, NULL); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 17792 | /* |
| 17793 | xmlSchemaVErr(vctxt, vctxt->nodeInfo->node, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17794 | XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 17795 | "Internal error: xmlSchemaXPathProcessHistory, " |
| 17796 | "computed value not available.\n", |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17797 | NULL, NULL); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 17798 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17799 | sto->nbHistory--; |
| 17800 | goto deregister_check; |
| 17801 | } else { |
| 17802 | xmlSchemaIDCMatcherPtr matcher = sto->matcher; |
| 17803 | xmlSchemaPSVIIDCKeyPtr *keySeq; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17804 | int pos, idx; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17805 | |
| 17806 | /* |
| 17807 | * The key will be anchored on the matcher's list of |
| 17808 | * key-sequences. The position in this list is determined |
| 17809 | * by the target node's depth relative to the matcher's |
| 17810 | * depth of creation (i.e. the depth of the scope element). |
| 17811 | */ |
| 17812 | pos = sto->depth - matcher->depth; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17813 | idx = sto->sel->index; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17814 | |
| 17815 | /* |
| 17816 | * Create/grow the array of key-sequences. |
| 17817 | */ |
| 17818 | if (matcher->keySeqs == NULL) { |
| 17819 | if (pos > 9) |
| 17820 | matcher->sizeKeySeqs = pos * 2; |
| 17821 | else |
| 17822 | matcher->sizeKeySeqs = 10; |
| 17823 | matcher->keySeqs = (xmlSchemaPSVIIDCKeyPtr **) |
| 17824 | xmlMalloc(matcher->sizeKeySeqs * |
| 17825 | sizeof(xmlSchemaPSVIIDCKeyPtr *)); |
| 17826 | if (matcher->keySeqs == NULL) { |
| 17827 | xmlSchemaVErrMemory(NULL, |
| 17828 | "allocating an array of key-sequences", |
| 17829 | NULL); |
| 17830 | return(-1); |
| 17831 | } |
| 17832 | memset(matcher->keySeqs, 0, |
| 17833 | matcher->sizeKeySeqs * |
| 17834 | sizeof(xmlSchemaPSVIIDCKeyPtr *)); |
| 17835 | } else if (pos >= matcher->sizeKeySeqs) { |
| 17836 | int i = matcher->sizeKeySeqs; |
| 17837 | |
| 17838 | matcher->sizeKeySeqs *= 2; |
| 17839 | matcher->keySeqs = (xmlSchemaPSVIIDCKeyPtr **) |
| 17840 | xmlRealloc(matcher->keySeqs, |
| 17841 | matcher->sizeKeySeqs * |
| 17842 | sizeof(xmlSchemaPSVIIDCKeyPtr *)); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17843 | if (matcher->keySeqs == NULL) { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17844 | xmlSchemaVErrMemory(NULL, |
| 17845 | "reallocating an array of key-sequences", |
| 17846 | NULL); |
| 17847 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17848 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17849 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17850 | * The array needs to be NULLed. |
| 17851 | * TODO: Use memset? |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17852 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17853 | for (; i < matcher->sizeKeySeqs; i++) |
| 17854 | matcher->keySeqs[i] = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17855 | } |
| 17856 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17857 | /* |
| 17858 | * Get/create the key-sequence. |
| 17859 | */ |
| 17860 | keySeq = matcher->keySeqs[pos]; |
| 17861 | if (keySeq == NULL) { |
| 17862 | goto create_sequence; |
| 17863 | } else { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17864 | if (keySeq[idx] != NULL) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17865 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17866 | * cvc-identity-constraint: |
| 17867 | * 3 For each node in the ·target node set· all |
| 17868 | * of the {fields}, with that node as the context |
| 17869 | * node, evaluate to either an empty node-set or |
| 17870 | * a node-set with exactly one member, which must |
| 17871 | * have a simple type. |
| 17872 | * |
| 17873 | * The key was already set; report an error. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17874 | */ |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 17875 | xmlSchemaStreamVCustomErr(vctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17876 | XML_SCHEMAV_CVC_IDC, |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 17877 | vctxt->nodeInfo, |
| 17878 | (xmlSchemaTypePtr) matcher->aidc->def, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17879 | "The field '%s' evaluates to a node-set " |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 17880 | "with more than one member", |
| 17881 | sto->sel->xpath, NULL); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17882 | sto->nbHistory--; |
| 17883 | goto deregister_check; |
| 17884 | } else { |
| 17885 | goto create_key; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17886 | } |
| 17887 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17888 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17889 | create_sequence: |
| 17890 | /* |
| 17891 | * Create a key-sequence. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17892 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17893 | keySeq = (xmlSchemaPSVIIDCKeyPtr *) xmlMalloc( |
| 17894 | matcher->aidc->def->nbFields * |
| 17895 | sizeof(xmlSchemaPSVIIDCKeyPtr)); |
| 17896 | if (keySeq == NULL) { |
| 17897 | xmlSchemaVErrMemory(NULL, |
| 17898 | "allocating an IDC key-sequence", NULL); |
| 17899 | return(-1); |
| 17900 | } |
| 17901 | memset(keySeq, 0, matcher->aidc->def->nbFields * |
| 17902 | sizeof(xmlSchemaPSVIIDCKeyPtr)); |
| 17903 | matcher->keySeqs[pos] = keySeq; |
| 17904 | create_key: |
| 17905 | /* |
| 17906 | * Created a key once per node only. |
| 17907 | */ |
| 17908 | if (key == NULL) { |
| 17909 | key = (xmlSchemaPSVIIDCKeyPtr) xmlMalloc( |
| 17910 | sizeof(xmlSchemaPSVIIDCKey)); |
| 17911 | if (key == NULL) { |
| 17912 | xmlSchemaVErrMemory(NULL, |
| 17913 | "allocating a IDC key", NULL); |
| 17914 | xmlFree(keySeq); |
| 17915 | matcher->keySeqs[pos] = NULL; |
| 17916 | return(-1); |
| 17917 | } |
| 17918 | /* |
| 17919 | * Consume the compiled value. |
| 17920 | */ |
| 17921 | key->type = type; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17922 | key->compValue = vctxt->nodeInfo->value; |
| 17923 | vctxt->nodeInfo->value = NULL; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17924 | /* |
| 17925 | * Store the key in a global list. |
| 17926 | */ |
| 17927 | if (xmlSchemaIDCStoreKey(vctxt, key) == -1) { |
| 17928 | xmlSchemaIDCFreeKey(key); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17929 | return (-1); |
| 17930 | } |
| 17931 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17932 | keySeq[idx] = key; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17933 | } |
| 17934 | } else if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17935 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17936 | xmlSchemaPSVIIDCKeyPtr **keySeq = NULL; |
| 17937 | xmlSchemaPSVIIDCBindingPtr bind; |
| 17938 | xmlSchemaPSVIIDCNodePtr ntItem; |
| 17939 | xmlSchemaIDCMatcherPtr matcher; |
| 17940 | xmlSchemaIDCPtr idc; |
| 17941 | int pos, i, j, nbKeys; |
| 17942 | /* |
| 17943 | * Here we have the following scenario: |
| 17944 | * An IDC 'selector' state object resolved to a target node, |
| 17945 | * during the time this target node was in the |
| 17946 | * ancestor-or-self axis, the 'field' state object(s) looked |
| 17947 | * out for matching nodes to create a key-sequence for this |
| 17948 | * target node. Now we are back to this target node and need |
| 17949 | * to put the key-sequence, together with the target node |
| 17950 | * itself, into the node-table of the corresponding IDC |
| 17951 | * binding. |
| 17952 | */ |
| 17953 | matcher = sto->matcher; |
| 17954 | idc = matcher->aidc->def; |
| 17955 | nbKeys = idc->nbFields; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17956 | pos = depth - matcher->depth; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17957 | /* |
| 17958 | * Check if the matcher has any key-sequences at all, plus |
| 17959 | * if it has a key-sequence for the current target node. |
| 17960 | */ |
| 17961 | if ((matcher->keySeqs == NULL) || |
| 17962 | (matcher->sizeKeySeqs <= pos)) { |
| 17963 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEY) |
| 17964 | goto selector_key_error; |
| 17965 | else |
| 17966 | goto selector_leave; |
| 17967 | } |
| 17968 | |
| 17969 | keySeq = &(matcher->keySeqs[pos]); |
| 17970 | if (*keySeq == NULL) { |
| 17971 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEY) |
| 17972 | goto selector_key_error; |
| 17973 | else |
| 17974 | goto selector_leave; |
| 17975 | } |
| 17976 | |
| 17977 | for (i = 0; i < nbKeys; i++) { |
| 17978 | if ((*keySeq)[i] == NULL) { |
| 17979 | /* |
| 17980 | * Not qualified, if not all fields did resolve. |
| 17981 | */ |
| 17982 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEY) { |
| 17983 | /* |
| 17984 | * All fields of a "key" IDC must resolve. |
| 17985 | */ |
| 17986 | goto selector_key_error; |
| 17987 | } |
| 17988 | goto selector_leave; |
| 17989 | } |
| 17990 | } |
| 17991 | /* |
| 17992 | * All fields did resolve. |
| 17993 | */ |
| 17994 | |
| 17995 | /* |
| 17996 | * 4.1 If the {identity-constraint category} is unique(/key), |
| 17997 | * then no two members of the ·qualified node set· have |
| 17998 | * ·key-sequences· whose members are pairwise equal, as |
| 17999 | * defined by Equal in [XML Schemas: Datatypes]. |
| 18000 | * |
| 18001 | * Get the IDC binding from the matcher and check for |
| 18002 | * duplicate key-sequences. |
| 18003 | */ |
| 18004 | bind = xmlSchemaIDCAquireBinding(vctxt, matcher); |
| 18005 | if ((idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) && |
| 18006 | (bind->nbNodes != 0)) { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18007 | xmlSchemaPSVIIDCKeyPtr ckey, bkey, *bkeySeq; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18008 | |
| 18009 | i = 0; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18010 | res = 0; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18011 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18012 | * Compare the key-sequences, key by key. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18013 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18014 | do { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18015 | bkeySeq = bind->nodeTable[i]->keys; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18016 | for (j = 0; j < nbKeys; j++) { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18017 | ckey = (*keySeq)[j]; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18018 | bkey = bkeySeq[j]; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18019 | res = xmlSchemaAreValuesEqual(vctxt, ckey->type, |
| 18020 | ckey->compValue, bkey->type, bkey->compValue); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18021 | if (res == -1) { |
| 18022 | return (-1); |
| 18023 | } else if (res == 0) |
| 18024 | break; |
| 18025 | } |
| 18026 | if (res == 1) { |
| 18027 | /* |
| 18028 | * Duplicate found. |
| 18029 | */ |
| 18030 | break; |
| 18031 | } |
| 18032 | i++; |
| 18033 | } while (i < bind->nbNodes); |
| 18034 | if (i != bind->nbNodes) { |
| 18035 | /* |
| 18036 | * TODO: Try to report the key-sequence. |
| 18037 | */ |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 18038 | xmlSchemaStreamVCustomErr(vctxt, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18039 | XML_SCHEMAV_CVC_IDC, |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 18040 | vctxt->nodeInfo, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18041 | (xmlSchemaTypePtr) idc, |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 18042 | "Duplicate key-sequence found", NULL, NULL); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18043 | |
| 18044 | goto selector_leave; |
| 18045 | } |
| 18046 | } |
| 18047 | /* |
| 18048 | * Add a node-table item to the IDC binding. |
| 18049 | */ |
| 18050 | ntItem = (xmlSchemaPSVIIDCNodePtr) xmlMalloc( |
| 18051 | sizeof(xmlSchemaPSVIIDCNode)); |
| 18052 | if (ntItem == NULL) { |
| 18053 | xmlSchemaVErrMemory(NULL, |
| 18054 | "allocating an IDC node-table item", NULL); |
| 18055 | xmlFree(*keySeq); |
| 18056 | *keySeq = NULL; |
| 18057 | return(-1); |
| 18058 | } |
| 18059 | memset(ntItem, 0, sizeof(xmlSchemaPSVIIDCNode)); |
| 18060 | |
| 18061 | /* |
| 18062 | * Store the node-table item on global list. |
| 18063 | */ |
| 18064 | if (idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 18065 | if (xmlSchemaIDCStoreNodeTableItem(vctxt, ntItem) == -1) { |
| 18066 | xmlFree(ntItem); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18067 | xmlFree(*keySeq); |
| 18068 | *keySeq = NULL; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18069 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18070 | } |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18071 | } |
| 18072 | /* |
| 18073 | * Init the node-table item. Consume the key-sequence. |
| 18074 | */ |
| 18075 | ntItem->node = vctxt->node; |
| 18076 | ntItem->keys = *keySeq; |
| 18077 | *keySeq = NULL; |
| 18078 | if (xmlSchemaIDCAppendNodeTableItem(bind, ntItem) == -1) { |
| 18079 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 18080 | /* |
| 18081 | * Free the item, since keyref items won't be |
| 18082 | * put on a global list. |
| 18083 | */ |
| 18084 | xmlFree(ntItem->keys); |
| 18085 | xmlFree(ntItem); |
| 18086 | } |
| 18087 | return (-1); |
| 18088 | } |
| 18089 | |
| 18090 | goto selector_leave; |
| 18091 | selector_key_error: |
| 18092 | /* |
| 18093 | * 4.2.1 (KEY) The ·target node set· and the |
| 18094 | * ·qualified node set· are equal, that is, every |
| 18095 | * member of the ·target node set· is also a member |
| 18096 | * of the ·qualified node set· and vice versa. |
| 18097 | */ |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 18098 | xmlSchemaStreamVCustomErr(vctxt, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18099 | XML_SCHEMAV_CVC_IDC, |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 18100 | vctxt->nodeInfo, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18101 | (xmlSchemaTypePtr) idc, |
| 18102 | "All 'key' fields must evaluate to a node", |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 18103 | NULL, NULL); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18104 | selector_leave: |
| 18105 | /* |
| 18106 | * Free the key-sequence if not added to the IDC table. |
| 18107 | */ |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18108 | if ((keySeq != NULL) && (*keySeq != NULL)) { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18109 | xmlFree(*keySeq); |
| 18110 | *keySeq = NULL; |
| 18111 | } |
| 18112 | } /* if selector */ |
| 18113 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18114 | sto->nbHistory--; |
| 18115 | |
| 18116 | deregister_check: |
| 18117 | /* |
| 18118 | * Deregister state objects if they reach the depth of creation. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18119 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18120 | if ((sto->nbHistory == 0) && (sto->depth == depth)) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18121 | #if DEBUG_IDC |
| 18122 | xmlGenericError(xmlGenericErrorContext, "IDC: STO pop '%s'\n", |
| 18123 | sto->sel->xpath); |
| 18124 | #endif |
| 18125 | if (vctxt->xpathStates != sto) { |
| 18126 | xmlSchemaVErr(vctxt, vctxt->node, |
| 18127 | XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18128 | "Internal error: xmlSchemaXPathProcessHistory, " |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18129 | "The state object to be removed is not the first " |
| 18130 | "in the list.\n", |
| 18131 | NULL, NULL); |
| 18132 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18133 | nextsto = sto->next; |
| 18134 | /* |
| 18135 | * Unlink from the list of active XPath state objects. |
| 18136 | */ |
| 18137 | vctxt->xpathStates = sto->next; |
| 18138 | sto->next = vctxt->xpathStatePool; |
| 18139 | /* |
| 18140 | * Link it to the pool of reusable state objects. |
| 18141 | */ |
| 18142 | vctxt->xpathStatePool = sto; |
| 18143 | sto = nextsto; |
| 18144 | } else |
| 18145 | sto = sto->next; |
| 18146 | } /* while (sto != NULL) */ |
| 18147 | return (0); |
| 18148 | } |
| 18149 | |
| 18150 | /** |
| 18151 | * xmlSchemaIDCRegisterMatchers: |
| 18152 | * @vctxt: the WXS validation context |
| 18153 | * @elemDecl: the element declaration |
| 18154 | * |
| 18155 | * Creates helper objects to evaluate IDC selectors/fields |
| 18156 | * successively. |
| 18157 | * |
| 18158 | * Returns 0 if OK and -1 on internal errors. |
| 18159 | */ |
| 18160 | static int |
| 18161 | xmlSchemaIDCRegisterMatchers(xmlSchemaValidCtxtPtr vctxt, |
| 18162 | xmlSchemaElementPtr elemDecl) |
| 18163 | { |
| 18164 | xmlSchemaIDCMatcherPtr matcher, last = NULL; |
| 18165 | xmlSchemaIDCPtr idc, refIdc; |
| 18166 | xmlSchemaIDCAugPtr aidc; |
| 18167 | |
| 18168 | idc = (xmlSchemaIDCPtr) elemDecl->idcs; |
| 18169 | if (idc == NULL) |
| 18170 | return (0); |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18171 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18172 | #if DEBUG_IDC |
| 18173 | { |
| 18174 | xmlChar *str = NULL; |
| 18175 | xmlGenericError(xmlGenericErrorContext, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18176 | "IDC: REGISTER on %s, depth %d\n", |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18177 | (char *) xmlSchemaFormatNsUriLocal(&str, vctxt->nodeInfo->namespaceName, |
| 18178 | vctxt->nodeInfo->localName), vctxt->depth); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18179 | FREE_AND_NULL(str) |
| 18180 | } |
| 18181 | #endif |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18182 | if (vctxt->nodeInfo->idcMatchers != NULL) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18183 | xmlSchemaVErr(vctxt, vctxt->node, |
| 18184 | XML_SCHEMAV_INTERNAL, |
| 18185 | "Internal error: xmlSchemaIDCRegisterMatchers: " |
| 18186 | "The chain of IDC matchers is expected to be empty.\n", |
| 18187 | NULL, NULL); |
| 18188 | return (-1); |
| 18189 | } |
| 18190 | do { |
| 18191 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 18192 | /* |
| 18193 | * Since IDCs bubbles are expensive we need to know the |
| 18194 | * depth at which the bubbles should stop; this will be |
| 18195 | * the depth of the top-most keyref IDC. If no keyref |
| 18196 | * references a key/unique IDC, the bubbleDepth will |
| 18197 | * be -1, indicating that no bubbles are needed. |
| 18198 | */ |
| 18199 | refIdc = (xmlSchemaIDCPtr) idc->ref->item; |
| 18200 | if (refIdc != NULL) { |
| 18201 | /* |
| 18202 | * Lookup the augmented IDC. |
| 18203 | */ |
| 18204 | aidc = vctxt->aidcs; |
| 18205 | while (aidc != NULL) { |
| 18206 | if (aidc->def == refIdc) |
| 18207 | break; |
| 18208 | aidc = aidc->next; |
| 18209 | } |
| 18210 | if (aidc == NULL) { |
| 18211 | xmlSchemaVErr(vctxt, vctxt->node, |
| 18212 | XML_SCHEMAV_INTERNAL, |
| 18213 | "Internal error: xmlSchemaIDCRegisterMatchers: " |
| 18214 | "Could not find an augmented IDC item for an IDC " |
| 18215 | "definition.\n", |
| 18216 | NULL, NULL); |
| 18217 | return (-1); |
| 18218 | } |
| 18219 | if ((aidc->bubbleDepth == -1) || |
| 18220 | (vctxt->depth < aidc->bubbleDepth)) |
| 18221 | aidc->bubbleDepth = vctxt->depth; |
| 18222 | } |
| 18223 | } |
| 18224 | /* |
| 18225 | * Lookup the augmented IDC item for the IDC definition. |
| 18226 | */ |
| 18227 | aidc = vctxt->aidcs; |
| 18228 | while (aidc != NULL) { |
| 18229 | if (aidc->def == idc) |
| 18230 | break; |
| 18231 | aidc = aidc->next; |
| 18232 | } |
| 18233 | if (aidc == NULL) { |
| 18234 | xmlSchemaVErr(vctxt, vctxt->node, |
| 18235 | XML_SCHEMAV_INTERNAL, |
| 18236 | "Internal error: xmlSchemaIDCRegisterMatchers: " |
| 18237 | "Could not find an augmented IDC item for an IDC definition.\n", |
| 18238 | NULL, NULL); |
| 18239 | return (-1); |
| 18240 | } |
| 18241 | /* |
| 18242 | * Create an IDC matcher for every IDC definition. |
| 18243 | */ |
| 18244 | matcher = (xmlSchemaIDCMatcherPtr) |
| 18245 | xmlMalloc(sizeof(xmlSchemaIDCMatcher)); |
| 18246 | if (matcher == NULL) { |
| 18247 | xmlSchemaVErrMemory(vctxt, |
| 18248 | "allocating an IDC matcher", NULL); |
| 18249 | return (-1); |
| 18250 | } |
| 18251 | memset(matcher, 0, sizeof(xmlSchemaIDCMatcher)); |
| 18252 | if (last == NULL) |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18253 | vctxt->nodeInfo->idcMatchers = matcher; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18254 | else |
| 18255 | last->next = matcher; |
| 18256 | last = matcher; |
| 18257 | |
| 18258 | matcher->type = IDC_MATCHER; |
| 18259 | matcher->depth = vctxt->depth; |
| 18260 | matcher->aidc = aidc; |
| 18261 | #if DEBUG_IDC |
| 18262 | xmlGenericError(xmlGenericErrorContext, "IDC: register matcher\n"); |
| 18263 | #endif |
| 18264 | /* |
| 18265 | * Init the automaton state object. |
| 18266 | */ |
| 18267 | if (xmlSchemaIDCAddStateObject(vctxt, matcher, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18268 | idc->selector, XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) == -1) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18269 | return (-1); |
| 18270 | |
| 18271 | idc = idc->next; |
| 18272 | } while (idc != NULL); |
| 18273 | return (0); |
| 18274 | } |
| 18275 | |
| 18276 | /** |
| 18277 | * xmlSchemaBubbleIDCNodeTables: |
| 18278 | * @depth: the current tree depth |
| 18279 | * |
| 18280 | * Merges IDC bindings of an element at @depth into the corresponding IDC |
| 18281 | * bindings of its parent element. If a duplicate note-table entry is found, |
| 18282 | * both, the parent node-table entry and child entry are discarded from the |
| 18283 | * node-table of the parent. |
| 18284 | * |
| 18285 | * Returns 0 if OK and -1 on internal errors. |
| 18286 | */ |
| 18287 | static int |
| 18288 | xmlSchemaBubbleIDCNodeTables(xmlSchemaValidCtxtPtr vctxt) |
| 18289 | { |
| 18290 | xmlSchemaPSVIIDCBindingPtr bind; /* IDC bindings of the current node. */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18291 | xmlSchemaPSVIIDCBindingPtr *parTable, parBind = NULL, lastParBind = NULL; /* parent IDC bindings. */ |
| 18292 | xmlSchemaPSVIIDCNodePtr node, parNode = NULL; /* node-table entries. */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18293 | xmlSchemaPSVIIDCKeyPtr key, parKey; /* keys of in a key-sequence. */ |
| 18294 | xmlSchemaIDCAugPtr aidc; |
Kasimier T. Buchcik | b34ad1b | 2005-03-21 20:10:31 +0000 | [diff] [blame^] | 18295 | int i, j, k, ret = 0, oldNum, newDupls; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18296 | int duplTop; |
| 18297 | |
| 18298 | /* |
| 18299 | * The node table has the following sections: |
| 18300 | * |
| 18301 | * O --> old node-table entries (first) |
| 18302 | * O |
| 18303 | * + --> new node-table entries |
| 18304 | * + |
| 18305 | * % --> new duplicate node-table entries |
| 18306 | * % |
| 18307 | * # --> old duplicate node-table entries |
| 18308 | * # (last) |
| 18309 | * |
| 18310 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18311 | bind = vctxt->nodeInfo->idcTable; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18312 | if (bind == NULL) { |
| 18313 | /* Fine, no table, no bubbles. */ |
| 18314 | return (0); |
| 18315 | } |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18316 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18317 | parTable = &(vctxt->elemInfos[vctxt->depth -1]->idcTable); |
| 18318 | /* |
| 18319 | * Walk all bindings; create new or add to existing bindings. |
| 18320 | * Remove duplicate key-sequences. |
| 18321 | */ |
| 18322 | start_binding: |
| 18323 | while (bind != NULL) { |
| 18324 | /* |
| 18325 | * Skip keyref IDCs. |
| 18326 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18327 | if (bind->definition->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 18328 | bind = bind->next; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18329 | continue; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18330 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18331 | /* |
| 18332 | * Check if the key/unique IDC table needs to be bubbled. |
| 18333 | */ |
| 18334 | aidc = vctxt->aidcs; |
| 18335 | do { |
| 18336 | if (aidc->def == bind->definition) { |
Kasimier T. Buchcik | b34ad1b | 2005-03-21 20:10:31 +0000 | [diff] [blame^] | 18337 | if ((aidc->bubbleDepth == -1) || |
| 18338 | (aidc->bubbleDepth >= vctxt->depth)) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18339 | bind = bind->next; |
| 18340 | goto start_binding; |
| 18341 | } |
| 18342 | break; |
| 18343 | } |
| 18344 | aidc = aidc->next; |
| 18345 | } while (aidc != NULL); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18346 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18347 | if (parTable != NULL) |
| 18348 | parBind = *parTable; |
| 18349 | while (parBind != NULL) { |
| 18350 | /* |
| 18351 | * Search a matching parent binding for the |
| 18352 | * IDC definition. |
| 18353 | */ |
| 18354 | if (parBind->definition == bind->definition) { |
| 18355 | |
| 18356 | /* |
| 18357 | * Compare every node-table entry of the child node, |
| 18358 | * i.e. the key-sequence within, ... |
| 18359 | */ |
| 18360 | oldNum = parBind->nbNodes; /* Skip newly added items. */ |
| 18361 | duplTop = oldNum + parBind->nbDupls; |
Kasimier T. Buchcik | b34ad1b | 2005-03-21 20:10:31 +0000 | [diff] [blame^] | 18362 | newDupls = 0; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18363 | |
| 18364 | for (i = 0; i < bind->nbNodes; i++) { |
| 18365 | node = bind->nodeTable[i]; |
| 18366 | if (node == NULL) |
| 18367 | continue; |
| 18368 | /* |
| 18369 | * ...with every key-sequence of the parent node, already |
| 18370 | * evaluated to be a duplicate key-sequence. |
| 18371 | */ |
| 18372 | if (parBind->nbDupls != 0) { |
| 18373 | j = bind->nbNodes + newDupls; |
| 18374 | while (j < duplTop) { |
| 18375 | parNode = parBind->nodeTable[j]; |
| 18376 | for (k = 0; k < bind->definition->nbFields; k++) { |
| 18377 | key = node->keys[k]; |
| 18378 | parKey = parNode->keys[k]; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18379 | ret = xmlSchemaAreValuesEqual(vctxt, key->type, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18380 | key->compValue, |
| 18381 | parKey->type, parKey->compValue); |
| 18382 | if (ret == -1) { |
| 18383 | /* TODO: Internal error */ |
| 18384 | return(-1); |
| 18385 | } else if (ret == 0) |
| 18386 | break; |
| 18387 | |
| 18388 | } |
| 18389 | if (ret == 1) |
| 18390 | /* Duplicate found. */ |
| 18391 | break; |
| 18392 | j++; |
| 18393 | } |
| 18394 | if (j != duplTop) { |
| 18395 | /* Duplicate found. */ |
| 18396 | continue; |
| 18397 | } |
| 18398 | } |
| 18399 | /* |
| 18400 | * ... and with every key-sequence of the parent node. |
| 18401 | */ |
| 18402 | j = 0; |
| 18403 | while (j < oldNum) { |
| 18404 | parNode = parBind->nodeTable[j]; |
| 18405 | /* |
| 18406 | * Compare key by key. |
| 18407 | */ |
| 18408 | for (k = 0; k < parBind->definition->nbFields; k++) { |
| 18409 | key = node->keys[k]; |
| 18410 | parKey = parNode->keys[k]; |
| 18411 | |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18412 | ret = xmlSchemaAreValuesEqual(vctxt, key->type, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18413 | key->compValue, |
| 18414 | parKey->type, parKey->compValue); |
| 18415 | if (ret == -1) { |
| 18416 | /* TODO: Internal error */ |
| 18417 | } else if (ret == 0) |
| 18418 | break; |
| 18419 | |
| 18420 | } |
| 18421 | if (ret == 1) |
| 18422 | /* |
| 18423 | * The key-sequences are equal. |
| 18424 | */ |
| 18425 | break; |
| 18426 | j++; |
| 18427 | } |
| 18428 | if (j != oldNum) { |
| 18429 | /* |
| 18430 | * Handle duplicates. |
| 18431 | */ |
| 18432 | newDupls++; |
| 18433 | oldNum--; |
| 18434 | parBind->nbNodes--; |
| 18435 | /* |
| 18436 | * Move last old item to pos of duplicate. |
| 18437 | */ |
| 18438 | parBind->nodeTable[j] = |
| 18439 | parBind->nodeTable[oldNum]; |
| 18440 | |
| 18441 | if (parBind->nbNodes != oldNum) { |
| 18442 | /* |
| 18443 | * If new items exist, move last new item to |
| 18444 | * last of old items. |
| 18445 | */ |
| 18446 | parBind->nodeTable[oldNum] = |
| 18447 | parBind->nodeTable[parBind->nbNodes]; |
| 18448 | } |
| 18449 | /* |
| 18450 | * Move duplicate to last pos of new/old items. |
| 18451 | */ |
| 18452 | parBind->nodeTable[parBind->nbNodes] = parNode; |
| 18453 | |
| 18454 | } else { |
| 18455 | /* |
| 18456 | * Add the node-table entry (node and key-sequence) of |
| 18457 | * the child node to the node table of the parent node. |
| 18458 | */ |
| 18459 | if (parBind->nodeTable == NULL) { |
| 18460 | parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *) |
Kasimier T. Buchcik | b34ad1b | 2005-03-21 20:10:31 +0000 | [diff] [blame^] | 18461 | xmlMalloc(10 * sizeof(xmlSchemaPSVIIDCNodePtr)); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18462 | if (parBind->nodeTable == NULL) { |
| 18463 | xmlSchemaVErrMemory(NULL, |
| 18464 | "allocating IDC list of node-table items", NULL); |
| 18465 | return(-1); |
| 18466 | } |
| 18467 | parBind->sizeNodes = 1; |
| 18468 | } else if (duplTop >= parBind->sizeNodes) { |
Kasimier T. Buchcik | b34ad1b | 2005-03-21 20:10:31 +0000 | [diff] [blame^] | 18469 | parBind->sizeNodes *= 2; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18470 | parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *) |
| 18471 | xmlRealloc(parBind->nodeTable, parBind->sizeNodes * |
| 18472 | sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 18473 | if (parBind->nodeTable == NULL) { |
| 18474 | xmlSchemaVErrMemory(NULL, |
| 18475 | "re-allocating IDC list of node-table items", NULL); |
| 18476 | return(-1); |
| 18477 | } |
| 18478 | } |
| 18479 | |
| 18480 | /* |
| 18481 | * Move first old duplicate to last position |
| 18482 | * of old duplicates +1. |
| 18483 | */ |
| 18484 | if (parBind->nbDupls != 0) { |
| 18485 | parBind->nodeTable[duplTop] = |
| 18486 | parBind->nodeTable[parBind->nbNodes + newDupls]; |
| 18487 | } |
| 18488 | /* |
| 18489 | * Move first new duplicate to last position of |
| 18490 | * new duplicates +1. |
| 18491 | */ |
| 18492 | if (newDupls != 0) { |
| 18493 | parBind->nodeTable[parBind->nbNodes + newDupls] = |
| 18494 | parBind->nodeTable[parBind->nbNodes]; |
| 18495 | } |
| 18496 | /* |
| 18497 | * Append the new node-table entry to the 'new node-table |
| 18498 | * entries' section. |
| 18499 | */ |
| 18500 | parBind->nodeTable[parBind->nbNodes] = node; |
| 18501 | parBind->nbNodes++; |
| 18502 | duplTop++; |
| 18503 | } |
| 18504 | } |
| 18505 | parBind->nbDupls += newDupls; |
| 18506 | break; |
| 18507 | } |
| 18508 | if (parBind->next == NULL) |
| 18509 | lastParBind = parBind; |
| 18510 | parBind = parBind->next; |
| 18511 | } |
Kasimier T. Buchcik | b34ad1b | 2005-03-21 20:10:31 +0000 | [diff] [blame^] | 18512 | if ((parBind == NULL) && (bind->nbNodes != 0)) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18513 | /* |
| 18514 | * No binding for the IDC was found: create a new one and |
| 18515 | * copy all node-tables. |
| 18516 | */ |
| 18517 | parBind = xmlSchemaIDCNewBinding(bind->definition); |
| 18518 | if (parBind == NULL) |
| 18519 | return(-1); |
| 18520 | |
| 18521 | parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *) |
| 18522 | xmlMalloc(bind->nbNodes * sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 18523 | if (parBind->nodeTable == NULL) { |
| 18524 | xmlSchemaVErrMemory(NULL, |
| 18525 | "allocating an array of IDC node-table items", NULL); |
| 18526 | xmlSchemaIDCFreeBinding(parBind); |
| 18527 | return(-1); |
| 18528 | } |
| 18529 | parBind->sizeNodes = bind->nbNodes; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18530 | parBind->nbNodes = bind->nbNodes; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18531 | memcpy(parBind->nodeTable, bind->nodeTable, |
| 18532 | bind->nbNodes * sizeof(xmlSchemaPSVIIDCNodePtr)); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18533 | if (*parTable == NULL) |
| 18534 | *parTable = parBind; |
| 18535 | else |
| 18536 | lastParBind->next = parBind; |
| 18537 | } |
| 18538 | bind = bind->next; |
| 18539 | } |
| 18540 | return (0); |
| 18541 | } |
| 18542 | |
| 18543 | /** |
| 18544 | * xmlSchemaCheckCVCIDCKeyRef: |
| 18545 | * @vctxt: the WXS validation context |
| 18546 | * @elemDecl: the element declaration |
| 18547 | * |
| 18548 | * Check the cvc-idc-keyref constraints. |
| 18549 | */ |
| 18550 | static int |
| 18551 | xmlSchemaCheckCVCIDCKeyRef(xmlSchemaValidCtxtPtr vctxt) |
| 18552 | { |
| 18553 | xmlSchemaPSVIIDCBindingPtr refbind, bind; |
| 18554 | |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18555 | refbind = vctxt->nodeInfo->idcTable; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18556 | /* |
| 18557 | * Find a keyref. |
| 18558 | */ |
| 18559 | while (refbind != NULL) { |
| 18560 | if (refbind->definition->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 18561 | int i, j, k, res; |
| 18562 | xmlSchemaPSVIIDCKeyPtr *refKeys, *keys; |
| 18563 | xmlSchemaPSVIIDCKeyPtr refKey, key; |
| 18564 | |
| 18565 | /* |
| 18566 | * Find the referred key/unique. |
| 18567 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18568 | bind = vctxt->nodeInfo->idcTable; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18569 | do { |
| 18570 | if ((xmlSchemaIDCPtr) refbind->definition->ref->item == |
| 18571 | bind->definition) |
| 18572 | break; |
| 18573 | bind = bind->next; |
| 18574 | } while (bind != NULL); |
| 18575 | |
| 18576 | /* |
| 18577 | * Search for a matching key-sequences. |
| 18578 | */ |
| 18579 | for (i = 0; i < refbind->nbNodes; i++) { |
| 18580 | res = 0; |
| 18581 | if (bind != NULL) { |
| 18582 | refKeys = refbind->nodeTable[i]->keys; |
| 18583 | for (j = 0; j < bind->nbNodes; j++) { |
| 18584 | keys = bind->nodeTable[j]->keys; |
| 18585 | for (k = 0; k < bind->definition->nbFields; k++) { |
| 18586 | refKey = refKeys[k]; |
| 18587 | key = keys[k]; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18588 | res = xmlSchemaAreValuesEqual(vctxt, |
| 18589 | key->type, key->compValue, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18590 | refKey->type, refKey->compValue); |
| 18591 | if (res == 0) |
| 18592 | break; |
| 18593 | else if (res == -1) { |
| 18594 | return (-1); |
| 18595 | } |
| 18596 | } |
| 18597 | if (res == 1) { |
| 18598 | /* |
| 18599 | * Match found. |
| 18600 | */ |
| 18601 | break; |
| 18602 | } |
| 18603 | } |
| 18604 | } |
| 18605 | if (res == 0) { |
| 18606 | /* TODO: Report the key-sequence. */ |
| 18607 | xmlSchemaVCustomErr(vctxt, |
| 18608 | XML_SCHEMAV_CVC_IDC, |
| 18609 | refbind->nodeTable[i]->node, |
| 18610 | (xmlSchemaTypePtr) refbind->definition, |
| 18611 | "No matching key-sequence found", NULL); |
| 18612 | } |
| 18613 | } |
| 18614 | } |
| 18615 | refbind = refbind->next; |
| 18616 | } |
| 18617 | return (0); |
| 18618 | } |
| 18619 | #endif /* IDC_ENABLED */ |
| 18620 | |
| 18621 | #ifdef ELEM_INFO_ENABLED |
| 18622 | /** |
| 18623 | * xmlSchemaBeginElement: |
| 18624 | * @vctxt: the WXS validation context |
| 18625 | * |
| 18626 | * Just a temporary workaround to simulate streaming validation |
| 18627 | * a bit. |
| 18628 | */ |
| 18629 | static void |
| 18630 | xmlSchemaBeginElement(xmlSchemaValidCtxtPtr vctxt) |
| 18631 | { |
| 18632 | vctxt->depth++; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18633 | vctxt->nodeInfo = xmlSchemaGetFreshElemInfo(vctxt, vctxt->depth); |
| 18634 | vctxt->nodeInfo->node = vctxt->node; |
| 18635 | vctxt->nodeInfo->localName = vctxt->node->name; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18636 | if (vctxt->node->ns != NULL) |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18637 | vctxt->nodeInfo->namespaceName = vctxt->node->ns->href; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18638 | else |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18639 | vctxt->nodeInfo->namespaceName = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18640 | } |
| 18641 | |
| 18642 | /** |
| 18643 | * xmlSchemaEndElement: |
| 18644 | * @vctxt: the WXS validation context |
| 18645 | * |
| 18646 | * Just a temporary workaround to simulate streaming validation |
| 18647 | * a bit. |
| 18648 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18649 | static int |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18650 | xmlSchemaEndElement(xmlSchemaValidCtxtPtr vctxt) |
| 18651 | { |
| 18652 | if (vctxt->depth < 0) { |
| 18653 | /* TODO: raise error? */ |
| 18654 | vctxt->depth--; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18655 | return (0); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18656 | } |
| 18657 | #ifdef IDC_ENABLED |
| 18658 | /* |
| 18659 | * Evaluate the history of changes of active state objects. |
| 18660 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18661 | if (xmlSchemaXPathProcessHistory(vctxt, vctxt->depth) == -1) |
| 18662 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18663 | |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18664 | if (vctxt->nodeInfo->value != NULL) { |
| 18665 | xmlSchemaFreeValue(vctxt->nodeInfo->value); |
| 18666 | vctxt->nodeInfo->value = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18667 | } |
| 18668 | /* |
| 18669 | * TODO: 6 The element information item must be ·valid· with respect to each of |
| 18670 | * the {identity-constraint definitions} as per Identity-constraint |
| 18671 | * Satisfied (§3.11.4). |
| 18672 | */ |
| 18673 | /* |
| 18674 | * Validate IDC keyrefs. |
| 18675 | */ |
| 18676 | xmlSchemaCheckCVCIDCKeyRef(vctxt); |
| 18677 | #endif |
| 18678 | |
| 18679 | /* |
| 18680 | * Merge/free the IDC table. |
| 18681 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18682 | if (vctxt->nodeInfo->idcTable != NULL) { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 18683 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18684 | #ifdef DEBUG_IDC |
| 18685 | xmlSchemaDebugDumpIDCTable(stdout, |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18686 | vctxt->nodeInfo->namespaceName, |
| 18687 | vctxt->nodeInfo->localName, |
| 18688 | vctxt->nodeInfo->idcTable); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18689 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18690 | if (vctxt->depth > 0) { |
| 18691 | /* |
| 18692 | * Merge the IDC node table with the table of the parent node. |
| 18693 | */ |
| 18694 | xmlSchemaBubbleIDCNodeTables(vctxt); |
| 18695 | } |
| 18696 | /* |
| 18697 | * TODO: Don't free the PSVI IDC tables if they are |
| 18698 | * requested for the PSVI. |
| 18699 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18700 | xmlSchemaIDCFreeIDCTable(vctxt->nodeInfo->idcTable); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18701 | #endif |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18702 | vctxt->nodeInfo->idcTable = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18703 | } |
| 18704 | |
| 18705 | /* |
| 18706 | * Cleanup IDC matchers. |
| 18707 | */ |
| 18708 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18709 | if (vctxt->nodeInfo->idcMatchers != NULL) { |
| 18710 | xmlSchemaIDCFreeMatcherList(vctxt->nodeInfo->idcMatchers); |
| 18711 | vctxt->nodeInfo->idcMatchers = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18712 | } |
| 18713 | #endif |
| 18714 | |
| 18715 | /* |
| 18716 | * Skip further processing if we are on the validation root. |
| 18717 | */ |
| 18718 | if (vctxt->depth == 0) { |
| 18719 | vctxt->depth--; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18720 | return (0); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18721 | } |
| 18722 | |
| 18723 | /* |
| 18724 | * Reset the bubbleDepth if needed. |
| 18725 | */ |
| 18726 | #ifdef IDC_ENABLED |
| 18727 | if (vctxt->aidcs != NULL) { |
| 18728 | xmlSchemaIDCAugPtr aidc = vctxt->aidcs; |
| 18729 | do { |
| 18730 | if (aidc->bubbleDepth == vctxt->depth) { |
| 18731 | /* |
| 18732 | * A bubbleDepth of a key/unique IDC matches the current |
| 18733 | * depth, this means that we are leaving the scope of the |
| 18734 | * top-most keyref IDC. |
| 18735 | */ |
| 18736 | aidc->bubbleDepth = -1; |
| 18737 | } |
| 18738 | aidc = aidc->next; |
| 18739 | } while (aidc != NULL); |
| 18740 | } |
| 18741 | #endif |
| 18742 | vctxt->depth--; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18743 | /* |
| 18744 | * Clear the current elemInfo. |
| 18745 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18746 | if (vctxt->nodeInfo->value != NULL) { |
| 18747 | xmlSchemaFreeValue(vctxt->nodeInfo->value); |
| 18748 | vctxt->nodeInfo->value = NULL; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18749 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18750 | vctxt->nodeInfo = vctxt->elemInfos[vctxt->depth]; |
| 18751 | vctxt->node = vctxt->nodeInfo->node; |
| 18752 | |
| 18753 | return (0); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18754 | } |
| 18755 | |
| 18756 | #endif /* ELEM_INFO_ENABLED */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18757 | |
| 18758 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18759 | * xmlSchemaValidateElementByDeclaration: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 18760 | * @ctxt: a schema validation context |
| 18761 | * @node: the top node. |
| 18762 | * |
| 18763 | * Validate the content of an element type. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18764 | * Validation Rule: Element Locally Valid (Element) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 18765 | * |
| 18766 | * Returns 0 if the element is schemas valid, a positive error code |
| 18767 | * number otherwise and -1 in case of internal or API error. |
| 18768 | */ |
| 18769 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18770 | xmlSchemaValidateElementByDeclaration(xmlSchemaValidCtxtPtr ctxt, |
| 18771 | xmlSchemaElementPtr elemDecl) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 18772 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18773 | xmlNodePtr elem; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18774 | int ret = 0; |
| 18775 | xmlSchemaTypePtr actualType = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18776 | xmlAttrPtr attr; |
| 18777 | xmlChar *attrValue; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18778 | int nilled = 0, elemHasContent = -1; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 18779 | |
| 18780 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18781 | * This one is called by xmlSchemaValidateElementByWildcardInternal, |
| 18782 | * xmlSchemaValidateElementByAnyType and xmlSchemaValidateElement. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18783 | * Note that @elemDecl will be the declaration and never the |
| 18784 | * reference to a declaration. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18785 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 18786 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18787 | if (ctxt == NULL) { |
| 18788 | xmlSchemaVErr(ctxt, NULL, XML_SCHEMAV_INTERNAL, |
| 18789 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 18790 | "bad arguments.\n", |
| 18791 | NULL, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 18792 | return (-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 18793 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18794 | |
| 18795 | elem = ctxt->node; |
| 18796 | |
| 18797 | /* |
| 18798 | * cvc-elt (3.3.4) : 1 |
| 18799 | */ |
| 18800 | if (elemDecl == NULL) { |
| 18801 | xmlSchemaVCustomErr(ctxt, |
| 18802 | XML_SCHEMAV_CVC_ELT_1, |
| 18803 | elem, NULL, |
| 18804 | "No matching declaration available", NULL); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18805 | /* |
| 18806 | * Evaluate IDCs even if an error occured. |
| 18807 | */ |
| 18808 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18809 | if (xmlSchemaXPathEvaluate(ctxt, XML_ELEMENT_NODE) == -1) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18810 | return (-1); |
| 18811 | #endif |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18812 | return (ctxt->err); |
| 18813 | } |
| 18814 | /* |
| 18815 | * cvc-elt (3.3.4) : 2 |
| 18816 | */ |
| 18817 | if (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT) { |
| 18818 | xmlSchemaVCustomErr(ctxt, |
| 18819 | XML_SCHEMAV_CVC_ELT_2, |
| 18820 | elem, NULL, |
| 18821 | "The element declaration is abstract", NULL); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18822 | /* |
| 18823 | * Evaluate IDCs even if an error occured. |
| 18824 | */ |
| 18825 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18826 | if (xmlSchemaXPathEvaluate(ctxt, XML_ELEMENT_NODE) == -1) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18827 | return (-1); |
| 18828 | #endif |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18829 | return (ctxt->err); |
| 18830 | } |
| 18831 | |
| 18832 | /* |
| 18833 | * cvc-elt (3.3.4) : 3 |
| 18834 | * Handle 'xsi:nil'. |
| 18835 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18836 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18837 | attr = xmlHasNsProp(elem, BAD_CAST "nil", xmlSchemaInstanceNs); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18838 | if (attr != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18839 | attrValue = xmlNodeGetContent((xmlNodePtr) attr); |
| 18840 | ctxt->node = (xmlNodePtr) attr; |
| 18841 | ctxt->cur = attr->children; |
| 18842 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, |
| 18843 | xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN), |
| 18844 | BAD_CAST attrValue, 1, 1, 1, 1); |
| 18845 | ctxt->node = elem; |
| 18846 | ctxt->type = (xmlSchemaTypePtr) elemDecl; |
| 18847 | if (ret < 0) { |
| 18848 | xmlSchemaVCustomErr(ctxt, |
| 18849 | XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18850 | (xmlNodePtr) attr, (xmlSchemaTypePtr) elemDecl, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18851 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 18852 | "validating the attribute 'xsi:nil'", NULL); |
| 18853 | if (attrValue != NULL) |
| 18854 | xmlFree(attrValue); |
| 18855 | return (-1); |
| 18856 | } |
| 18857 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_NILLABLE) == 0) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18858 | /* |
| 18859 | * cvc-elt (3.3.4) : 3.1 |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18860 | */ |
| 18861 | xmlSchemaVCustomErr(ctxt, |
| 18862 | XML_SCHEMAV_CVC_ELT_3_1, |
| 18863 | elem, NULL, |
| 18864 | "The element is not 'nillable'", NULL); |
| 18865 | } else { |
| 18866 | if (xmlStrEqual(BAD_CAST attrValue, BAD_CAST "true") || |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18867 | xmlStrEqual(BAD_CAST attrValue, BAD_CAST "1")) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18868 | ret = 0; |
| 18869 | /* |
| 18870 | * cvc-elt (3.3.4) : 3.2.1 |
| 18871 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18872 | elemHasContent = xmlSchemaHasElemOrCharContent(elem); |
| 18873 | if (elemHasContent == 1) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18874 | xmlSchemaVCustomErr(ctxt, |
| 18875 | XML_SCHEMAV_CVC_ELT_3_2_1, |
| 18876 | /* XML_SCHEMAS_ERR_NOTEMPTY, */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18877 | elem, (xmlSchemaTypePtr) elemDecl, |
| 18878 | "The 'nilled' element must have no character or " |
| 18879 | "element content", NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18880 | ret = XML_SCHEMAV_CVC_ELT_3_2_1; |
| 18881 | } |
| 18882 | /* |
| 18883 | * cvc-elt (3.3.4) : 3.2.2 |
| 18884 | */ |
| 18885 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_FIXED) && |
| 18886 | (elemDecl->value != NULL)) { |
| 18887 | xmlSchemaVCustomErr(ctxt, XML_SCHEMAV_CVC_ELT_3_2_2, |
| 18888 | /* XML_SCHEMAS_ERR_HAVEDEFAULT, */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18889 | elem, (xmlSchemaTypePtr) elemDecl, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18890 | "There is a fixed value constraint defined for " |
| 18891 | "the 'nilled' element", NULL); |
| 18892 | ret = XML_SCHEMAV_CVC_ELT_3_2_2; |
| 18893 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18894 | if (ret == 0) |
| 18895 | nilled = 1; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18896 | } |
| 18897 | } |
| 18898 | if (attrValue != NULL) |
| 18899 | xmlFree(attrValue); |
| 18900 | } |
| 18901 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18902 | |
| 18903 | actualType = elemDecl->subtypes; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18904 | /* |
| 18905 | * cvc-elt (3.3.4) : 4 |
| 18906 | * Handle 'xsi:type'. |
| 18907 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18908 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18909 | attr = xmlHasNsProp(elem, BAD_CAST "type", xmlSchemaInstanceNs); |
| 18910 | if (attr != NULL) { |
| 18911 | xmlChar *nsName = NULL, *local = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18912 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18913 | /* |
| 18914 | * TODO: We should report a *warning* that the type was overriden |
| 18915 | * by the instance. |
| 18916 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18917 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18918 | /* |
| 18919 | * cvc-elt (3.3.4) : 4.1 |
| 18920 | */ |
| 18921 | attrValue = xmlNodeGetContent((xmlNodePtr) attr); |
| 18922 | ret = xmlSchemaValQNameAcquire(attrValue, attr->parent, |
| 18923 | &nsName, &local); |
| 18924 | if (ret < 0) { |
| 18925 | xmlSchemaVCustomErr(ctxt, |
| 18926 | XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18927 | (xmlNodePtr) attr, (xmlSchemaTypePtr) elemDecl, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18928 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 18929 | "validating the attribute 'xsi:type'", NULL);; |
| 18930 | FREE_AND_NULL(attrValue) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18931 | FREE_AND_NULL(nsName) |
| 18932 | FREE_AND_NULL(local) |
| 18933 | return (-1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18934 | } else if (ret == 1) { |
| 18935 | xmlSchemaVSimpleTypeErr(ctxt, |
| 18936 | XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, |
| 18937 | (xmlNodePtr) attr, attrValue, |
| 18938 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME)); |
| 18939 | } else if (ret == 2) { |
| 18940 | xmlSchemaVCustomErr(ctxt, |
| 18941 | XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, |
| 18942 | (xmlNodePtr) attr, |
| 18943 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
| 18944 | "The QName value '%s' has no " |
| 18945 | "corresponding namespace declaration in scope", |
| 18946 | attrValue); |
| 18947 | } else { |
| 18948 | /* |
| 18949 | * cvc-elt (3.3.4) : 4.2 |
| 18950 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18951 | actualType = xmlSchemaGetType(ctxt->schema, local, nsName); |
| 18952 | if (actualType == NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18953 | xmlChar *strA = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18954 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18955 | xmlSchemaVCustomErr(ctxt, |
| 18956 | XML_SCHEMAV_CVC_ELT_4_2, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18957 | (xmlNodePtr) attr, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18958 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
| 18959 | "The value %s does not resolve to a type " |
| 18960 | "definition", |
| 18961 | xmlSchemaFormatNsUriLocal(&strA, nsName, local)); |
| 18962 | FREE_AND_NULL(strA); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18963 | } else { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18964 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18965 | * URGENT TODO: cvc-elt (3.3.4) : 4.3 (Type Derivation OK) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18966 | */ |
| 18967 | } |
| 18968 | } |
| 18969 | FREE_AND_NULL(attrValue) |
| 18970 | FREE_AND_NULL(nsName) |
| 18971 | FREE_AND_NULL(local) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18972 | } |
| 18973 | /* TODO: Change the handling of missing types according to |
| 18974 | * the spec. |
| 18975 | */ |
| 18976 | if (actualType == NULL) { |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 18977 | xmlSchemaVCustomErr(ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18978 | XML_SCHEMAV_CVC_TYPE_1, |
| 18979 | elem, (xmlSchemaTypePtr) elemDecl, |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 18980 | "The type definition is absent", NULL); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18981 | /* |
| 18982 | * Evaluate IDCs even if an error occured. |
| 18983 | */ |
| 18984 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18985 | if (xmlSchemaXPathEvaluate(ctxt, XML_ELEMENT_NODE) == -1) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18986 | return (-1); |
| 18987 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18988 | return (XML_SCHEMAV_CVC_TYPE_1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18989 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18990 | |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 18991 | /* |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18992 | * Remember the actual-type definition. |
| 18993 | */ |
| 18994 | #ifdef ELEM_INFO_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18995 | ctxt->nodeInfo->typeDef = actualType; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18996 | #endif |
| 18997 | |
| 18998 | /* |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 18999 | * TODO: Since this should be already checked by the content model automaton, |
| 19000 | * and we want to get rid of the XML_SCHEMAS_ERR... types, the error code |
| 19001 | * has been changed to XML_SCHEMAV_INTERNAL. |
| 19002 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19003 | /* |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19004 | if (child == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19005 | if (decl->minOccurs > 0) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 19006 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19007 | XML_SCHEMAS_ERR_MISSING, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 19008 | "Element %s: missing child %s\n", |
| 19009 | node->name, decl->name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19010 | } |
| 19011 | return (ctxt->err); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19012 | } |
| 19013 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19014 | /* |
| 19015 | * Verify the element matches |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 19016 | * TODO, FIXME: Can this still happen here? Isn't this already checked |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19017 | * by the content model automaton? |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19018 | if (!xmlStrEqual(child->name, decl->name)) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 19019 | xmlSchemaVErr3(ctxt, node, XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19020 | XML_SCHEMAS_ERR_WRONGELEM, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 19021 | "Element %s: missing child %s found %s\n", |
| 19022 | node->name, decl->name, child->name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19023 | return (ctxt->err); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19024 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19025 | */ |
| 19026 | if (elemHasContent == -1) |
| 19027 | elemHasContent = xmlSchemaHasElemOrCharContent(elem); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19028 | |
| 19029 | /* |
| 19030 | * IDC: Register identity-constraint XPath matchers. |
| 19031 | */ |
| 19032 | #ifdef IDC_ENABLED |
| 19033 | if (elemDecl->idcs != NULL) |
| 19034 | xmlSchemaIDCRegisterMatchers(ctxt, elemDecl); |
| 19035 | /* |
| 19036 | * Evaluate IDCs. |
| 19037 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19038 | if (xmlSchemaXPathEvaluate(ctxt, XML_ELEMENT_NODE) == -1) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19039 | return (-1); |
| 19040 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19041 | /* |
| 19042 | * cvc-elt (3.3.4) : 5 |
| 19043 | * The appropriate case among the following must be true: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19044 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19045 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19046 | * cvc-elt (3.3.4) : 5.1 |
| 19047 | * If the declaration has a {value constraint}, |
| 19048 | * the item has neither element nor character [children] and |
| 19049 | * clause 3.2 has not applied, then all of the following must be true: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19050 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19051 | if ((elemHasContent == 0) && (nilled == 0) && (elemDecl->value != NULL)) { |
| 19052 | /* |
| 19053 | * cvc-elt (3.3.4) : 5.1.1 |
| 19054 | * If the ·actual type definition· is a ·local type definition· |
| 19055 | * then the canonical lexical representation of the {value constraint} |
| 19056 | * value must be a valid default for the ·actual type definition· as |
| 19057 | * defined in Element Default Valid (Immediate) (§3.3.6). |
| 19058 | */ |
| 19059 | /* |
| 19060 | * NOTE: 'local' above means types aquired by xsi:type. |
| 19061 | */ |
| 19062 | ret = 0; |
| 19063 | if (actualType != elemDecl->subtypes) { |
| 19064 | xmlSchemaCreatePCtxtOnVCtxt(ctxt); |
| 19065 | ret = xmlSchemaCheckCOSValidDefault(ctxt->pctxt, ctxt, actualType, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19066 | elemDecl->value, NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19067 | if (ret < 0) { |
| 19068 | xmlSchemaVCustomErr(ctxt, |
| 19069 | XML_SCHEMAV_INTERNAL, |
| 19070 | elem, actualType, |
| 19071 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 19072 | "validating a default value", NULL); |
| 19073 | return (-1); |
| 19074 | } |
| 19075 | } |
| 19076 | /* |
| 19077 | * cvc-elt (3.3.4) : 5.1.2 |
| 19078 | * The element information item with the canonical lexical |
| 19079 | * representation of the {value constraint} value used as its |
| 19080 | * ·normalized value· must be ·valid· with respect to the |
| 19081 | * ·actual type definition· as defined by Element Locally Valid (Type) |
| 19082 | * (§3.3.4). |
| 19083 | */ |
| 19084 | /* |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19085 | * Disable validation of the simple content, if it was already |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19086 | * done above. |
| 19087 | */ |
| 19088 | if (ret == 0) { |
| 19089 | if (actualType != elemDecl->subtypes) |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19090 | ret = xmlSchemaValidateElementByType(ctxt, actualType, 0, 0); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19091 | else |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19092 | ret = xmlSchemaValidateElementByType(ctxt, actualType, 0, 1); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19093 | ctxt->node = elem; |
| 19094 | if (ret < 0) { |
| 19095 | xmlSchemaVCustomErr(ctxt, |
| 19096 | XML_SCHEMAV_INTERNAL, |
| 19097 | elem, actualType, |
| 19098 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 19099 | "validating against the type", NULL); |
| 19100 | return (-1); |
| 19101 | } |
| 19102 | /* |
| 19103 | * PSVI: Create a text node on the instance element. |
| 19104 | */ |
| 19105 | if (ctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) { |
| 19106 | xmlNodePtr textChild; |
| 19107 | |
| 19108 | textChild = xmlNewText(elemDecl->value); |
| 19109 | if (textChild == NULL) { |
| 19110 | xmlSchemaVCustomErr(ctxt, |
| 19111 | XML_SCHEMAV_INTERNAL, |
| 19112 | elem, actualType, |
| 19113 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 19114 | "could not create a default text node for the instance", |
| 19115 | NULL); |
| 19116 | } else |
| 19117 | xmlAddChild(elem, textChild); |
| 19118 | } |
| 19119 | } |
| 19120 | |
| 19121 | } else { |
| 19122 | /* |
| 19123 | * 5.2.1 The element information item must be ·valid· with respect |
| 19124 | * to the ·actual type definition· as defined by Element Locally |
| 19125 | * Valid (Type) (§3.3.4). |
| 19126 | */ |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19127 | ret = xmlSchemaValidateElementByType(ctxt, actualType, nilled, 1); |
| 19128 | /* |
| 19129 | * Consume the computed value for IDCs, ect. Note that default |
| 19130 | * values are not supported yet. |
| 19131 | */ |
| 19132 | #ifdef ELEM_INFO_ENABLED |
| 19133 | if (ctxt->value != NULL) { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19134 | ctxt->nodeInfo->value = ctxt->value; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19135 | ctxt->value = NULL; |
| 19136 | } |
| 19137 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19138 | ctxt->node = elem; |
| 19139 | if (ret < 0) { |
| 19140 | xmlSchemaVCustomErr(ctxt, |
| 19141 | XML_SCHEMAV_INTERNAL, |
| 19142 | elem, actualType, |
| 19143 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 19144 | "calling validation by type", NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19145 | return (-1); |
| 19146 | } |
| 19147 | /* |
| 19148 | * 5.2.2 If there is a fixed {value constraint} and clause 3.2 has |
| 19149 | * not applied, all of the following must be true: |
| 19150 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19151 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_FIXED) && (nilled == 0)) { |
| 19152 | /* |
| 19153 | * 5.2.2.1 The element information item must have no element |
| 19154 | * information item [children]. |
| 19155 | * |
| 19156 | * TODO REDUNDANT: If the actual type exists, the above call to |
| 19157 | * xmlSchemaValidateElementByType will already check for element |
| 19158 | * nodes. |
| 19159 | */ |
| 19160 | if (xmlSchemaHasElemContent(elem)) { |
| 19161 | xmlSchemaVCustomErr(ctxt, |
| 19162 | XML_SCHEMAV_CVC_ELT_5_2_2_1, |
| 19163 | elem, (xmlSchemaTypePtr) elemDecl, |
| 19164 | "Elements in the content are not allowed if it is " |
| 19165 | "constrained by a fixed value", NULL); |
| 19166 | } else { |
| 19167 | /* |
| 19168 | * 5.2.2.2 The appropriate case among the following must |
| 19169 | * be true: |
| 19170 | */ |
| 19171 | |
| 19172 | if (actualType->contentType == XML_SCHEMA_CONTENT_MIXED) { |
| 19173 | xmlChar *value; |
| 19174 | /* |
| 19175 | * 5.2.2.2.1 If the {content type} of the ·actual type |
| 19176 | * definition· is mixed, then the *initial value* of the |
| 19177 | * item must match the canonical lexical representation |
| 19178 | * of the {value constraint} value. |
| 19179 | * |
| 19180 | * ... the *initial value* of an element information |
| 19181 | * item is the string composed of, in order, the |
| 19182 | * [character code] of each character information item in |
| 19183 | * the [children] of that element information item. |
| 19184 | */ |
| 19185 | value = xmlNodeListGetString(elem->doc, elem->children, 1); |
| 19186 | if (! xmlStrEqual(BAD_CAST value, elemDecl->value)) { |
| 19187 | /* |
| 19188 | * TODO: Report invalid & expected values as well. |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19189 | * TODO: Implement the canonical stuff. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19190 | */ |
| 19191 | xmlSchemaVCustomErr(ctxt, |
| 19192 | XML_SCHEMAV_CVC_ELT_5_2_2_2_1, |
| 19193 | elem, (xmlSchemaTypePtr) elemDecl, |
| 19194 | "The value does not match the cononical " |
| 19195 | "lexical representation of the fixed constraint", |
| 19196 | NULL); |
| 19197 | } |
| 19198 | if (value != NULL) |
| 19199 | xmlFree(value); |
| 19200 | } else if ((actualType->contentType == |
| 19201 | XML_SCHEMA_CONTENT_SIMPLE) || |
| 19202 | (actualType->contentType == XML_SCHEMA_CONTENT_BASIC)) { |
| 19203 | xmlChar *value; |
| 19204 | |
| 19205 | /* |
| 19206 | * 5.2.2.2.2 If the {content type} of the ·actual type |
| 19207 | * definition· is a simple type definition, then the |
| 19208 | * *actual value* of the item must match the canonical |
| 19209 | * lexical representation of the {value constraint} value. |
| 19210 | */ |
| 19211 | /* |
| 19212 | * TODO: *actual value* is the normalized value, impl. this. |
| 19213 | * TODO: Report invalid & expected values as well. |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19214 | * TODO: Implement the canonical stuff. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19215 | * |
| 19216 | */ |
| 19217 | value = xmlNodeListGetString(elem->doc, elem->children, 1); |
| 19218 | if (! xmlStrEqual(BAD_CAST value, elemDecl->value)) { |
| 19219 | xmlSchemaVCustomErr(ctxt, |
| 19220 | XML_SCHEMAV_CVC_ELT_5_2_2_2_2, |
| 19221 | elem, (xmlSchemaTypePtr) elemDecl, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19222 | "The normalized value does not match the canonical " |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19223 | "lexical representation of the fixed constraint", |
| 19224 | NULL); |
| 19225 | } |
| 19226 | if (value != NULL) |
| 19227 | xmlFree(value); |
| 19228 | |
| 19229 | } |
| 19230 | /* |
| 19231 | * TODO: What if the content type is not 'mixed' or simple? |
| 19232 | */ |
| 19233 | |
| 19234 | } |
| 19235 | |
| 19236 | } |
| 19237 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19238 | /* |
| 19239 | * TODO: 7 If the element information item is the ·validation root·, it must be |
| 19240 | * ·valid· per Validation Root Valid (ID/IDREF) (§3.3.4). |
| 19241 | */ |
| 19242 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19243 | return (ctxt->err); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19244 | } |
| 19245 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19246 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19247 | * xmlSchemaValidateElementByWildcardInternal: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19248 | * @ctxt: a schema validation context |
| 19249 | * @node: the top node. |
| 19250 | * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19251 | * Represents the recursive portion of xmlSchemaValidateElementByWildcard. |
| 19252 | * Not intended to be used by other functions. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19253 | * |
| 19254 | * Returns 0 if the element is valid, a positive error code |
| 19255 | * number otherwise and -1 in case of an internal error. |
| 19256 | */ |
| 19257 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19258 | xmlSchemaValidateElementByWildcardInternal(xmlSchemaValidCtxtPtr ctxt, |
| 19259 | xmlSchemaWildcardPtr wild, |
| 19260 | xmlNodePtr node) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19261 | { |
| 19262 | const xmlChar *uri; |
| 19263 | int ret = 0; |
| 19264 | xmlNodePtr child; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19265 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19266 | if (ctxt->xsiAssemble) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19267 | ret = xmlSchemaAssembleByXSIElem(ctxt, ctxt->node); |
| 19268 | if (ret == -1) { |
| 19269 | xmlSchemaVCustomErr(ctxt, |
| 19270 | XML_SCHEMAV_INTERNAL, |
| 19271 | ctxt->node, NULL, |
| 19272 | "Internal error: xmlSchemaValidateElement, " |
| 19273 | "assembling schema by xsi", NULL); |
| 19274 | return (-1); |
| 19275 | } |
| 19276 | /* |
| 19277 | * NOTE: We won't react on schema parser errors here. |
| 19278 | * TODO: But a warning would be nice. |
| 19279 | */ |
| 19280 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19281 | if (wild->processContents != XML_SCHEMAS_ANY_SKIP) { |
| 19282 | xmlSchemaElementPtr decl = NULL; |
| 19283 | |
| 19284 | if (node->ns != NULL) |
| 19285 | decl = xmlHashLookup3(ctxt->schema->elemDecl, |
| 19286 | node->name, node->ns->href, NULL); |
| 19287 | else |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19288 | decl = xmlHashLookup3(ctxt->schema->elemDecl, node->name, |
| 19289 | NULL, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19290 | if (decl != NULL) { |
| 19291 | ctxt->node = node; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19292 | ret = xmlSchemaValidateElementByDeclaration(ctxt, decl); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19293 | if (ret < 0) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 19294 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19295 | "Internal error: xmlSchemaValidateAnyInternal, " |
| 19296 | "validating an element in the context of a wildcard.", |
| 19297 | NULL, NULL); |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 19298 | } |
| 19299 | return (ret); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19300 | } else if (wild->processContents == XML_SCHEMAS_ANY_STRICT) { |
| 19301 | /* TODO: Change to proper error code. */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 19302 | xmlSchemaVWildcardErr(ctxt, XML_SCHEMAV_CVC_ELT_1, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19303 | node, wild, "No matching global declaration available"); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19304 | /* |
| 19305 | * Evaluate IDCs even if a validation error occured. |
| 19306 | */ |
| 19307 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19308 | if (xmlSchemaXPathEvaluate(ctxt,XML_ELEMENT_NODE) == -1) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19309 | return(-1); |
| 19310 | #endif |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19311 | return (ctxt->err); |
| 19312 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19313 | /* |
| 19314 | * Evaluate IDCs; we need to know if an IDC field resolves to |
| 19315 | * such a node. This node has no type definition and will |
| 19316 | * definitely result in an IDC validation error if an IDC field |
| 19317 | * resolves. |
| 19318 | */ |
| 19319 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19320 | if (xmlSchemaXPathEvaluate(ctxt, XML_ELEMENT_NODE) == -1) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19321 | return(-1); |
| 19322 | #endif |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19323 | } |
| 19324 | if (node->children != NULL) { |
| 19325 | child = node->children; |
| 19326 | do { |
| 19327 | if (child->type == XML_ELEMENT_NODE) { |
| 19328 | if (child->ns != NULL) |
| 19329 | uri = child->ns->href; |
| 19330 | else |
| 19331 | uri = NULL; |
| 19332 | if (xmlSchemaMatchesWildcardNs(wild, uri) == 0) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 19333 | /* TODO: error code. */ |
| 19334 | xmlSchemaVWildcardErr(ctxt, XML_SCHEMAV_ELEMENT_CONTENT, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19335 | child, wild, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19336 | "The namespace of the element is not allowed"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19337 | return (ctxt->err); |
| 19338 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19339 | #ifdef ELEM_INFO_ENABLED |
| 19340 | ctxt->node = child; |
| 19341 | xmlSchemaBeginElement(ctxt); |
| 19342 | #endif |
| 19343 | /* |
| 19344 | * Recurse over the children. |
| 19345 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19346 | ret = xmlSchemaValidateElementByWildcardInternal(ctxt, |
| 19347 | wild, child); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19348 | if (ret == -1) |
| 19349 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19350 | #ifdef ELEM_INFO_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19351 | if (xmlSchemaEndElement(ctxt) == -1) |
| 19352 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19353 | #endif |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19354 | if (ret != 0) |
| 19355 | return (ret); |
| 19356 | } |
| 19357 | child = child->next; |
| 19358 | } while (child != NULL); |
| 19359 | } |
| 19360 | return (0); |
| 19361 | } |
| 19362 | |
| 19363 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19364 | * xmlSchemaValidateElementContByWildcard: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19365 | * @ctxt: a schema validation context |
| 19366 | * |
| 19367 | * Returns 0 if the element is valid, a positive error code |
| 19368 | * number otherwise and -1 in case of an internal or API error. |
| 19369 | */ |
| 19370 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19371 | xmlSchemaValidateElementByWildcard(xmlSchemaValidCtxtPtr ctxt, |
| 19372 | xmlSchemaTypePtr type) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19373 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19374 | if ((type == NULL) || (type->type != XML_SCHEMA_TYPE_ANY) || |
| 19375 | (ctxt->node == NULL)) { |
| 19376 | xmlSchemaVCustomErr(ctxt, |
| 19377 | XML_SCHEMAV_INTERNAL, ctxt->node, NULL, |
| 19378 | "Internal error: xmlSchemaValidateElementByWildcard, " |
| 19379 | "bad arguments", NULL); |
| 19380 | return (-1); |
| 19381 | } |
| 19382 | return(xmlSchemaValidateElementByWildcardInternal(ctxt, |
| 19383 | type->attributeWildcard, ctxt->node)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19384 | } |
| 19385 | |
| 19386 | /** |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19387 | * xmlSchemaValidateAnyTypeContent: |
| 19388 | * @ctxt: a schema validation context |
| 19389 | * @node: the current element |
| 19390 | * |
| 19391 | * This one validates the content of an element of the type |
| 19392 | * 'anyType'. The process contents of the wildcard of 'anyType' is "lax", |
| 19393 | * thus elements in the subtree will be validated, if a corresponding |
| 19394 | * declaration in the schema exists. |
| 19395 | * |
| 19396 | * Returns 0 if the element and its subtree is valid, a positive error code |
| 19397 | * otherwise and -1 in case of an internal or API error. |
| 19398 | */ |
| 19399 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19400 | xmlSchemaValidateElementByAnyType(xmlSchemaValidCtxtPtr ctxt, |
| 19401 | xmlSchemaTypePtr type) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19402 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19403 | xmlSchemaTypePtr oldtype; |
| 19404 | xmlNodePtr top, cur; |
| 19405 | xmlSchemaElementPtr decl; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19406 | int skipContent, ret; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19407 | |
| 19408 | if ((type == NULL) || (ctxt->node == NULL)) |
| 19409 | return (-1); |
| 19410 | |
| 19411 | if (ctxt->node->children == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19412 | return (0); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19413 | |
| 19414 | oldtype = ctxt->type; |
| 19415 | top = ctxt->node; |
| 19416 | /* |
| 19417 | * STREAM: Child nodes are processed. |
| 19418 | */ |
| 19419 | cur = ctxt->node->children; |
| 19420 | while (cur != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19421 | skipContent = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19422 | if (cur->type == XML_ELEMENT_NODE) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19423 | /* |
| 19424 | * The process contents of the wildcard is "lax", thus |
| 19425 | * we need to validate the element if a declaration |
| 19426 | * exists. |
| 19427 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19428 | if (cur->ns != NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19429 | decl = xmlHashLookup3(ctxt->schema->elemDecl, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19430 | cur->name, cur->ns->href, NULL); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19431 | else |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19432 | decl = xmlHashLookup3(ctxt->schema->elemDecl, cur->name, NULL, NULL); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19433 | if (decl != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19434 | ctxt->node = cur; |
| 19435 | ret = xmlSchemaValidateElementByDeclaration(ctxt, decl); |
| 19436 | ctxt->node = top; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19437 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19438 | xmlSchemaVErr(ctxt, cur, XML_SCHEMAV_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19439 | "Internal error: xmlSchemaValidateAnyTypeContent, " |
| 19440 | "validating an element in the context of a wildcard.", |
| 19441 | NULL, NULL); |
| 19442 | return (ret); |
| 19443 | } else if (ret > 0) |
| 19444 | return (ret); |
| 19445 | skipContent = 1; |
| 19446 | } |
| 19447 | } |
| 19448 | /* |
| 19449 | * Browse the full subtree, deep first. |
| 19450 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19451 | if ((skipContent == 0) && (cur->children != NULL)) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19452 | /* deep first */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19453 | cur = cur->children; |
| 19454 | } else if ((cur != top) && (cur->next != NULL)) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19455 | /* then siblings */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19456 | cur = cur->next; |
| 19457 | } else if (cur != top) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19458 | /* go up to parents->next if needed */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19459 | while (cur != top) { |
| 19460 | if (cur->parent != NULL) |
| 19461 | cur = cur->parent; |
| 19462 | if ((cur != top) && (cur->next != NULL)) { |
| 19463 | cur = cur->next; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19464 | break; |
| 19465 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19466 | if (cur->parent == NULL) { |
| 19467 | cur = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19468 | break; |
| 19469 | } |
| 19470 | } |
| 19471 | /* exit condition */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19472 | if (cur == top) |
| 19473 | cur = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19474 | } else |
| 19475 | break; |
| 19476 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19477 | ctxt->type = oldtype; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19478 | return (0); |
| 19479 | } |
| 19480 | |
| 19481 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19482 | * xmlSchemaValidateElementByComplexType: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19483 | * @ctxt: a schema validation context |
| 19484 | * @node: the top node. |
| 19485 | * |
| 19486 | * Validate the content of an element expected to be a complex type type |
| 19487 | * xmlschema-1.html#cvc-complex-type |
| 19488 | * Validation Rule: Element Locally Valid (Complex Type) |
| 19489 | * |
| 19490 | * Returns 0 if the element is schemas valid, a positive error code |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19491 | * number otherwise and -1 in case of internal or API error. |
| 19492 | * Note on reported errors: Although it might be nice to report |
| 19493 | * the name of the simple/complex type, used to validate the content |
| 19494 | * of a node, it is quite unnecessary: for global defined types |
| 19495 | * the local name of the element is equal to the NCName of the type, |
| 19496 | * for local defined types it makes no sense to output the internal |
| 19497 | * computed name of the type. TODO: Instead, one should attach the |
| 19498 | * struct of the type involved to the error handler - this allows |
| 19499 | * the report of any additional information by the user. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19500 | */ |
| 19501 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19502 | xmlSchemaValidateElementByComplexType(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19503 | xmlSchemaTypePtr type, |
| 19504 | int valSimpleContent) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19505 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19506 | xmlSchemaTypePtr oldtype; |
| 19507 | xmlNodePtr elem, child; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19508 | int ret = 0; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19509 | const xmlChar *nsUri; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19510 | xmlSchemaAttrStatePtr attrs = NULL, attrTop = NULL; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19511 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19512 | if ((ctxt == NULL) || (type->type != XML_SCHEMA_TYPE_COMPLEX)) |
| 19513 | return (-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19514 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19515 | oldtype = ctxt->type; |
| 19516 | ctxt->type = type; |
| 19517 | elem = ctxt->node; |
| 19518 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19519 | /* |
| 19520 | * Verify the attributes |
| 19521 | */ |
| 19522 | /* |
| 19523 | * TODO: This "attrTop" thing is not needed any more. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19524 | */ |
| 19525 | /* NOTE: removed, since a check for abstract is |
| 19526 | * done in the cvc-type constraint. |
| 19527 | * |
| 19528 | * |
| 19529 | * if (type->flags & XML_SCHEMAS_TYPE_ABSTRACT) { |
| 19530 | * xmlSchemaVComplexTypeErr(ctxt, |
| 19531 | * XML_SCHEMAV_CVC_COMPLEX_TYPE_1, |
| 19532 | * elem, type, |
| 19533 | * "The type definition is abstract"); |
| 19534 | * return (XML_SCHEMAV_CVC_COMPLEX_TYPE_1); |
| 19535 | *} |
| 19536 | */ |
| 19537 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19538 | attrs = ctxt->attr; |
| 19539 | attrTop = ctxt->attrTop; |
| 19540 | /* |
| 19541 | * STREAM: Attribute nodes are processed. |
| 19542 | */ |
| 19543 | xmlSchemaRegisterAttributes(ctxt, elem->properties); |
| 19544 | xmlSchemaValidateAttributes(ctxt, elem, type); |
| 19545 | if (ctxt->attr != NULL) |
| 19546 | xmlSchemaFreeAttributeStates(ctxt->attr); |
| 19547 | ctxt->attr = attrs; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19548 | ctxt->attrTop = attrTop; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19549 | |
| 19550 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19551 | * TODO: This one creates a regexp even if no content |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19552 | * model was defined. Somehow ->contModel is always not NULL |
| 19553 | * for complex types, even if they are empty. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19554 | * TODO: Check if the obove still occurs. |
| 19555 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19556 | switch (type->contentType) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19557 | case XML_SCHEMA_CONTENT_EMPTY: { |
| 19558 | /* |
| 19559 | * 1 If the {content type} is empty, then the element information |
| 19560 | * item has no character or element information item [children]. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19561 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19562 | /* |
| 19563 | * TODO: Is the entity stuff correct? |
| 19564 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19565 | if (xmlSchemaHasElemOrCharContent(elem) == 1) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19566 | xmlSchemaVComplexTypeErr(ctxt, |
| 19567 | XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19568 | elem, type, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19569 | "Character or element content is not allowed, " |
| 19570 | "because the content type is empty"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19571 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19572 | break; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19573 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19574 | case XML_SCHEMA_CONTENT_MIXED: |
| 19575 | if ((type->subtypes == NULL) && |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19576 | (type->baseType->builtInType == XML_SCHEMAS_ANYTYPE)) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19577 | /* |
| 19578 | * The type has 'anyType' as its base and no content model |
| 19579 | * is defined -> use 'anyType' as the type to validate |
| 19580 | * against. |
| 19581 | */ |
| 19582 | ret = xmlSchemaValidateElementByAnyType(ctxt, type->baseType); |
| 19583 | /* TODO: Handle -1. */ |
| 19584 | break; |
| 19585 | } |
| 19586 | /* No break on purpose. */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19587 | case XML_SCHEMA_CONTENT_ELEMENTS: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19588 | { |
| 19589 | xmlRegExecCtxtPtr oldregexp = NULL; |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 19590 | xmlChar *values[10]; |
| 19591 | int terminal, nbval = 10, nbneg; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19592 | |
| 19593 | /* |
| 19594 | * Content model check initialization. |
| 19595 | */ |
| 19596 | if (type->contModel != NULL) { |
| 19597 | oldregexp = ctxt->regexp; |
| 19598 | ctxt->regexp = xmlRegNewExecCtxt(type->contModel, |
| 19599 | (xmlRegExecCallbacks) |
| 19600 | xmlSchemaValidateCallback, ctxt); |
| 19601 | #ifdef DEBUG_AUTOMATA |
| 19602 | xmlGenericError(xmlGenericErrorContext, "====> %s\n", elem->name); |
| 19603 | #endif |
| 19604 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19605 | /* |
| 19606 | * STREAM: Children are processed. |
| 19607 | */ |
| 19608 | child = elem->children; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19609 | while (child != NULL) { |
| 19610 | if (child->type == XML_ELEMENT_NODE) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19611 | if (child->ns != NULL) |
| 19612 | nsUri = child->ns->href; |
| 19613 | else |
| 19614 | nsUri = NULL; |
| 19615 | ret = xmlRegExecPushString2(ctxt->regexp, |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19616 | child->name, nsUri, child); |
| 19617 | if (ctxt->err == XML_SCHEMAV_INTERNAL) |
| 19618 | return (-1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19619 | /* |
| 19620 | * URGENT TODO: Could we anchor an error report |
| 19621 | * here to notify of invalid elements? |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 19622 | * TODO: Perhaps it would be better to report |
| 19623 | * only the first erroneous element and then break. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19624 | */ |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 19625 | #ifdef DEBUG_AUTOMATA |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19626 | if (ret < 0) |
| 19627 | xmlGenericError(xmlGenericErrorContext, |
| 19628 | " --> %s Error\n", child->name); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 19629 | else |
| 19630 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19631 | " --> %s\n", child->name); |
| 19632 | #endif |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 19633 | if (ret < 0) { |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 19634 | xmlRegExecErrInfo(ctxt->regexp, NULL, &nbval, &nbneg, |
| 19635 | &values[0], &terminal); |
| 19636 | xmlSchemaVComplexTypeElemErr(ctxt, |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 19637 | XML_SCHEMAV_ELEMENT_CONTENT, |
| 19638 | child, NULL/* type */, |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 19639 | "This element is not expected", |
| 19640 | nbval, nbneg, values); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 19641 | ret = 1; |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 19642 | /* |
| 19643 | * Note that this will skip further validation of the |
| 19644 | * content. |
| 19645 | */ |
| 19646 | break; |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 19647 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19648 | } else if ((type->contentType == XML_SCHEMA_CONTENT_ELEMENTS) && |
| 19649 | /* |
| 19650 | * TODO: Ask Daniel if this are all character nodes. |
| 19651 | */ |
| 19652 | (((child->type == XML_TEXT_NODE) && (!IS_BLANK_NODE(child))) || |
| 19653 | (child->type == XML_ENTITY_NODE) || |
| 19654 | (child->type == XML_ENTITY_REF_NODE) || |
| 19655 | (child->type == XML_CDATA_SECTION_NODE))) { |
| 19656 | /* |
| 19657 | * 2.3 If the {content type} is element-only, then the |
| 19658 | * element information item has no character information |
| 19659 | * item [children] other than those whose [character |
| 19660 | * code] is defined as a white space in [XML 1.0 (Second |
| 19661 | * Edition)]. |
| 19662 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19663 | xmlSchemaVComplexTypeErr(ctxt, |
| 19664 | XML_SCHEMAV_CVC_COMPLEX_TYPE_2_3, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19665 | elem, type, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19666 | "Character content is not allowed, " |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 19667 | "because the content type is element-only"); |
| 19668 | ret = 1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19669 | break; |
| 19670 | } |
| 19671 | child = child->next; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19672 | } |
| 19673 | /* |
| 19674 | * Content model check finalization. |
| 19675 | */ |
| 19676 | if (type->contModel != NULL) { |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 19677 | if (ret == 0) { |
| 19678 | xmlRegExecNextValues(ctxt->regexp, &nbval, &nbneg, |
| 19679 | &values[0], &terminal); |
| 19680 | if (nbval + nbneg != 0) { |
| 19681 | /* |
| 19682 | * If a next value still exists, I does not have to |
| 19683 | * mean that there's an element missing, since it |
| 19684 | * might be an optional element. So double check it. |
| 19685 | */ |
| 19686 | ret = xmlRegExecPushString(ctxt->regexp, |
| 19687 | NULL, NULL); |
| 19688 | if (ret <= 0) { |
| 19689 | ret = 1; |
| 19690 | xmlSchemaVComplexTypeElemErr(ctxt, |
| 19691 | XML_SCHEMAV_ELEMENT_CONTENT, |
| 19692 | elem, type, "Missing child element(s)", |
| 19693 | nbval, nbneg, values); |
| 19694 | } else |
| 19695 | ret = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19696 | #ifdef DEBUG_AUTOMATA |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 19697 | xmlGenericError(xmlGenericErrorContext, |
| 19698 | "====> %s : %d\n", elem->name, ret); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19699 | #endif |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 19700 | } |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 19701 | #ifdef DEBUG_CONTENT |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 19702 | if (ret == 0) |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 19703 | xmlGenericError(xmlGenericErrorContext, |
| 19704 | "Element %s content check succeeded\n", |
| 19705 | elem->name); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 19706 | #endif |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19707 | } |
| 19708 | xmlRegFreeExecCtxt(ctxt->regexp); |
| 19709 | ctxt->regexp = oldregexp; |
| 19710 | } |
| 19711 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19712 | break; |
| 19713 | case XML_SCHEMA_CONTENT_SIMPLE: |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19714 | case XML_SCHEMA_CONTENT_BASIC: |
| 19715 | /* |
| 19716 | * If the simple content was already validated |
| 19717 | * (e.g. a default value), the content need not |
| 19718 | * to be validated again. |
| 19719 | */ |
| 19720 | if (valSimpleContent == 1) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19721 | xmlChar *value = NULL; |
| 19722 | /* |
| 19723 | * We hit a complexType with a simpleContent resolving |
| 19724 | * to a user derived or built-in simple type. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19725 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19726 | /* |
| 19727 | * 2.2 If the {content type} is a simple type definition, |
| 19728 | * then the element information item has no element |
| 19729 | * information item [children], and the ·normalized value· |
| 19730 | * of the element information item is ·valid· with respect |
| 19731 | * to that simple type definition as defined by String |
| 19732 | * Valid (§3.14.4). |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19733 | */ |
| 19734 | /* |
| 19735 | * STREAM: Children are processed. |
| 19736 | */ |
| 19737 | child = elem->children; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19738 | while (child != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19739 | /* |
| 19740 | * TODO: Could the entity stuff produce elements |
| 19741 | * as well? |
| 19742 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19743 | if (child->type == XML_ELEMENT_NODE) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19744 | xmlSchemaVComplexTypeErr(ctxt, |
| 19745 | XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19746 | elem, type, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19747 | "Element content is not allowed, because " |
| 19748 | "the content type is a simple type"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19749 | ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2; |
| 19750 | break; |
| 19751 | } |
| 19752 | child = child->next; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19753 | } |
| 19754 | ctxt->node = elem; |
| 19755 | ctxt->cur = elem->children; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19756 | if (ret == 0) { |
| 19757 | /* |
| 19758 | * Validate the character content against a simple type. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19759 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19760 | /* |
| 19761 | * STREAM: Children are processed. |
| 19762 | */ |
| 19763 | if (elem->children == NULL) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19764 | value = NULL; |
| 19765 | else |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19766 | value = xmlNodeGetContent(elem); |
| 19767 | /* |
| 19768 | * URGENT TODO: Should facets for the simple type validation be |
| 19769 | * disabled, if the derivation of facets for complex types |
| 19770 | * is implemented? |
| 19771 | */ |
| 19772 | /* |
| 19773 | * NOTE: This call won't check the correct types of the |
| 19774 | * content nodes, since this should be done here. |
| 19775 | */ |
| 19776 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, type, value, 1, 1, 1, 0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19777 | if (ret > 0) { |
| 19778 | /* |
| 19779 | * NOTE: Although an error will be reported by |
| 19780 | * xmlSchemaValidateSimpleTypeValue, the spec wants |
| 19781 | * a specific complex type error to be reported |
| 19782 | * additionally. |
| 19783 | */ |
| 19784 | xmlSchemaVComplexTypeErr(ctxt, |
| 19785 | XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19786 | elem, type, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19787 | "The character content is not valid"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19788 | ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2; |
| 19789 | } else if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19790 | xmlSchemaVErr(ctxt, elem, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19791 | "Internal error: xmlSchemaValidateComplexType, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19792 | "Element '%s': Error while validating character " |
| 19793 | "content against complex type '%s'.\n", |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19794 | elem->name, type->name); |
| 19795 | if (value != NULL) |
| 19796 | xmlFree(value); |
| 19797 | ctxt->type = oldtype; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19798 | return (-1); |
| 19799 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 19800 | } |
| 19801 | #if 0 |
| 19802 | /* |
| 19803 | * REMOVED since handled by xmlSchemaValidateSimpleTypeValue |
| 19804 | * already. |
| 19805 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19806 | if (ret == 0) { |
| 19807 | /* |
| 19808 | * Apply facets of the complexType. Be sure to pass the |
| 19809 | * built-in type to xmlSchemaValidateFacetsInternal. |
| 19810 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19811 | /* URGENT TODO: I don't know yet if the facets of the simple type |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19812 | * are used, or if the facets, defined by this complex type, |
| 19813 | * are to be used only. This here applies both facet sets. |
| 19814 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19815 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19816 | ret = xmlSchemaValidateFacetsInternal(ctxt, |
| 19817 | type, value, 0, 1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19818 | if (ret > 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19819 | xmlSchemaVComplexTypeErr(ctxt, |
| 19820 | XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19821 | elem, type, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19822 | "The character content is not valid"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19823 | ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2; |
| 19824 | } else if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19825 | xmlSchemaVErr(ctxt, elem, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19826 | "Internal error: xmlSchemaValidateComplexType, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19827 | "Element '%s': Error while validating character " |
| 19828 | "content against complex type '%s'; failed to " |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19829 | "apply facets.\n", |
| 19830 | type->name, NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19831 | if (value != NULL) |
| 19832 | xmlFree(value); |
| 19833 | ctxt->type = oldtype; |
| 19834 | return (-1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19835 | } |
| 19836 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 19837 | #endif |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19838 | if (value != NULL) |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 19839 | xmlFree(value); |
| 19840 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19841 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19842 | break; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19843 | default: |
| 19844 | TODO xmlGenericError(xmlGenericErrorContext, |
| 19845 | "unimplemented content type %d\n", |
| 19846 | type->contentType); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19847 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19848 | ctxt->type = oldtype; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19849 | return (ctxt->err); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19850 | } |
| 19851 | |
| 19852 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19853 | * xmlSchemaValidateElementByType: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19854 | * @ctxt: a schema validation context |
| 19855 | * @elem: an element |
| 19856 | * @type: the list of type declarations |
| 19857 | * |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19858 | * Validation Rule: Element Locally Valid (Type). |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19859 | * |
| 19860 | * Returns 0 if the element is schemas valid, a positive error code |
| 19861 | * number otherwise and -1 in case of internal or API error. |
| 19862 | */ |
| 19863 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19864 | xmlSchemaValidateElementByType(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19865 | xmlSchemaTypePtr type, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19866 | int isNil, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19867 | int valSimpleContent) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19868 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19869 | int ret; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19870 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19871 | |
| 19872 | if ((ctxt == NULL) || (type == NULL)) { |
| 19873 | xmlSchemaVCustomErr(ctxt, XML_SCHEMAV_INTERNAL, NULL, NULL, |
| 19874 | "Internal error: xmlSchemaValidateElementByType, " |
| 19875 | "bad arguments", NULL); |
| 19876 | return (-1); |
| 19877 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19878 | /* |
| 19879 | * This one is called by "xmlSchemaValidateElementByDeclaration". |
| 19880 | * It will forward to the proper validation |
| 19881 | * procedures for the given type. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19882 | */ |
| 19883 | if (type == NULL) { |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 19884 | xmlSchemaVCustomErr(ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19885 | XML_SCHEMAV_CVC_TYPE_1, |
| 19886 | ctxt->node, NULL, |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 19887 | "The type definition is absent", NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19888 | return (XML_SCHEMAV_CVC_TYPE_1); |
| 19889 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19890 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19891 | if (type->flags & XML_SCHEMAS_TYPE_ABSTRACT) { |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 19892 | xmlSchemaVCustomErr(ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19893 | XML_SCHEMAV_CVC_TYPE_2, |
| 19894 | ctxt->node, type, |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 19895 | "The type definition is abstract", NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19896 | return (XML_SCHEMAV_CVC_TYPE_2); |
| 19897 | } |
| 19898 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19899 | switch (type->type) { |
| 19900 | case XML_SCHEMA_TYPE_COMPLEX: |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19901 | ret = xmlSchemaValidateElementByComplexType(ctxt, type, |
| 19902 | valSimpleContent); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19903 | break; |
| 19904 | case XML_SCHEMA_TYPE_SIMPLE: |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19905 | ret = xmlSchemaValidateElementBySimpleType(ctxt, type, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19906 | isNil, valSimpleContent); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19907 | break; |
| 19908 | case XML_SCHEMA_TYPE_BASIC: |
| 19909 | if (type->builtInType == XML_SCHEMAS_ANYTYPE) |
| 19910 | ret = xmlSchemaValidateElementByAnyType(ctxt, type); |
| 19911 | else |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19912 | ret = xmlSchemaValidateElementBySimpleType(ctxt, type, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19913 | isNil, valSimpleContent); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19914 | break; |
| 19915 | default: |
| 19916 | ret = -1; |
| 19917 | break; |
| 19918 | } |
| 19919 | if (ret == -1) |
| 19920 | return (-1); |
| 19921 | else |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19922 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19923 | } |
| 19924 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19925 | static int |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 19926 | xmlSchemaPostCreateVal(xmlSchemaValidCtxtPtr vctxt, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 19927 | xmlSchemaTypePtr type, |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 19928 | const xmlChar *value, |
| 19929 | xmlSchemaValPtr *val) |
| 19930 | { |
| 19931 | xmlSchemaTypePtr prim; |
| 19932 | |
| 19933 | if (val == NULL) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 19934 | xmlSchemaVErr(vctxt, NULL, |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 19935 | XML_SCHEMAV_INTERNAL, |
| 19936 | "Internal error: xmlSchemaPostCreateVal, " |
| 19937 | "bad arguments", NULL, NULL); |
| 19938 | return (-1); |
| 19939 | } |
| 19940 | /* |
| 19941 | * Only string or anySimpleType values are expected to be post-created. |
| 19942 | */ |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 19943 | prim = xmlSchemaGetPrimitiveType(type); |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 19944 | if ((prim->builtInType == XML_SCHEMAS_STRING) || |
| 19945 | (prim->builtInType == XML_SCHEMAS_ANYSIMPLETYPE)) |
| 19946 | { |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 19947 | if (value == NULL) |
| 19948 | /* TODO: Can this happen at all? */ |
| 19949 | *val = xmlSchemaNewStringValue(XML_SCHEMAS_STRING, |
| 19950 | xmlStrdup(BAD_CAST "")); |
| 19951 | else |
| 19952 | *val = xmlSchemaNewStringValue(XML_SCHEMAS_STRING, value); |
| 19953 | if ((*val) == NULL) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 19954 | xmlSchemaVErr(vctxt, NULL, |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 19955 | XML_SCHEMAV_INTERNAL, |
| 19956 | "Internal error: xmlSchemaPostCreateVal, " |
| 19957 | "failed to create the value", NULL, NULL); |
| 19958 | return (-1); |
| 19959 | } |
| 19960 | return (0); |
| 19961 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 19962 | xmlSchemaVErr(vctxt, NULL, |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 19963 | XML_SCHEMAV_INTERNAL, |
| 19964 | "Internal error: xmlSchemaPostCreateVal, " |
| 19965 | "the given type is not supported", NULL, NULL); |
| 19966 | return (-1); |
| 19967 | } |
| 19968 | |
| 19969 | static int |
| 19970 | xmlSchemaCheckAttrLocallyValid(xmlSchemaValidCtxtPtr vctxt, |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19971 | xmlSchemaAttrStatePtr state) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19972 | { |
| 19973 | xmlChar *value; |
| 19974 | const xmlChar *defValue; |
| 19975 | xmlSchemaValPtr defVal; |
| 19976 | int fixed; |
| 19977 | int ret; |
| 19978 | |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 19979 | if (vctxt->attrInfo->typeDef == NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19980 | state->state = XML_SCHEMAS_ATTR_TYPE_NOT_RESOLVED; |
| 19981 | return (XML_SCHEMAS_ATTR_TYPE_NOT_RESOLVED); |
| 19982 | } |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 19983 | vctxt->node = vctxt->attrInfo->node; |
| 19984 | vctxt->cur = vctxt->node->children; |
| 19985 | /* STREAM */ |
| 19986 | value = xmlNodeListGetString(vctxt->node->doc, vctxt->cur, 1); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19987 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19988 | /* |
| 19989 | * NOTE: This call also checks the content nodes for correct type. |
| 19990 | */ |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 19991 | ret = xmlSchemaValidateSimpleTypeValue(vctxt, vctxt->attrInfo->typeDef, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19992 | value, 1, 1, 1, 1); |
| 19993 | |
| 19994 | /* |
| 19995 | * Handle 'fixed' attributes. |
| 19996 | */ |
| 19997 | if (ret > 0) { |
| 19998 | state->state = XML_SCHEMAS_ATTR_INVALID_VALUE; |
| 19999 | /* |
| 20000 | * NOTE: Fixed value constraints will be not |
| 20001 | * applied if the value was invalid, because: |
| 20002 | * 1. The validation process does not return a precomputed |
| 20003 | * value. |
| 20004 | * 2. An invalid value implies a violation of a fixed |
| 20005 | * value constraint. |
| 20006 | */ |
| 20007 | } else if (ret == 0) { |
| 20008 | state->state = XML_SCHEMAS_ATTR_CHECKED; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 20009 | if (xmlSchemaGetEffectiveValueConstraint( |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 20010 | (xmlSchemaAttributePtr) vctxt->attrInfo->decl, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20011 | &fixed, &defValue, &defVal) && (fixed == 1)) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 20012 | |
| 20013 | int ws = xmlSchemaGetWhiteSpaceFacetValue( |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 20014 | vctxt->nodeInfo->typeDef); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20015 | /* |
| 20016 | * cvc-au : Attribute Locally Valid (Use) |
| 20017 | * For an attribute information item to be·valid· |
| 20018 | * with respect to an attribute use its ·normalized |
| 20019 | * value· must match the canonical lexical representation |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 20020 | * of the attribute use's {value constraint} value, if it |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20021 | * is present and fixed. |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 20022 | * |
| 20023 | * TODO: Use somehow the *normalized* value and the *canonical* |
| 20024 | * fixed value. This here compares the canonical values of both. |
| 20025 | * The normalized value of, for example, a float type can differ |
| 20026 | * from its canonical representation. This all means that a fixed |
| 20027 | * value can only be OK, if it's present in the canonical form in |
| 20028 | * the instance. |
| 20029 | * NOTE: Since the value for string and anySimpleType is not always |
| 20030 | * precomputed during validation, we need to do it now. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20031 | */ |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 20032 | if (vctxt->value == NULL) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 20033 | /* |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 20034 | * Post-create the value. |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 20035 | */ |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 20036 | if (xmlSchemaPostCreateVal(vctxt, vctxt->attrInfo->typeDef, |
| 20037 | value, &(vctxt->value)) == -1) { |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 20038 | ret = -1; |
| 20039 | goto exit; |
| 20040 | } |
| 20041 | value = NULL; |
| 20042 | } |
| 20043 | if (defVal == NULL) { |
| 20044 | xmlChar *str; |
| 20045 | |
| 20046 | /* |
| 20047 | * Post-create the default/fixed value. |
| 20048 | */ |
| 20049 | if (defValue == NULL) |
| 20050 | str = xmlStrdup(BAD_CAST ""); |
| 20051 | else |
| 20052 | str = xmlStrdup(defValue); |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 20053 | if (xmlSchemaPostCreateVal(vctxt, vctxt->attrInfo->typeDef, |
| 20054 | str, &defVal) == -1) { |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 20055 | ret = -1; |
| 20056 | FREE_AND_NULL(str) |
| 20057 | goto exit; |
| 20058 | } |
| 20059 | ((xmlSchemaAttributePtr) vctxt->attrInfo->decl)->defVal = defVal; |
| 20060 | } |
| 20061 | if (xmlSchemaCompareValuesWhtsp(vctxt->value, |
| 20062 | (xmlSchemaWhitespaceValueType) ws, |
| 20063 | defVal, |
| 20064 | (xmlSchemaWhitespaceValueType) ws) != 0) |
| 20065 | { |
| 20066 | state->state = XML_SCHEMAS_ATTR_INVALID_FIXED_VALUE; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20067 | } |
| 20068 | } |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 20069 | } |
| 20070 | exit: |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20071 | if (value != NULL) { |
| 20072 | xmlFree(value); |
| 20073 | } |
| 20074 | return (ret); |
| 20075 | } |
| 20076 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20077 | /** |
| 20078 | * xmlSchemaValidateAttributes: |
| 20079 | * @ctxt: a schema validation context |
| 20080 | * @elem: an element |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20081 | * @type: the complexType holding the attribute uses |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20082 | * |
| 20083 | * Validate the attributes of an element. |
| 20084 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 20085 | * 1. Existent, invalid attributes are reported in the form |
| 20086 | * "prefix:localName". |
| 20087 | * Reason: readability - it is easier to find the actual XML |
| 20088 | * representation of the attributes QName. |
| 20089 | * 2. Missing attributes are reported in the form |
| 20090 | * {"URI", "localName"}. |
| 20091 | * This is necessary, since the the prefix need not to be declared |
| 20092 | * at all, and thus is not computable. |
| 20093 | * |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20094 | * Returns 0 if the element is schemas valid, a positive error code |
| 20095 | * number otherwise and -1 in case of internal or API error. |
| 20096 | */ |
| 20097 | static int |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20098 | xmlSchemaValidateAttributes(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem, xmlSchemaTypePtr type) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20099 | { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20100 | const xmlChar *nsURI; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20101 | int ret; |
| 20102 | xmlAttrPtr attr; /* An attribute on the element. */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20103 | const xmlChar *defValue; |
| 20104 | xmlSchemaValPtr defVal; |
| 20105 | int fixed; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20106 | xmlSchemaAttributeLinkPtr attrUse = NULL; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20107 | xmlSchemaAttributePtr attrDecl; |
Daniel Veillard | c85d0fe | 2004-04-16 16:46:51 +0000 | [diff] [blame] | 20108 | int found; |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 20109 | xmlSchemaAttrStatePtr curState, reqAttrStates = NULL, reqAttrStatesTop = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20110 | xmlSchemaAttrStatePtr defAttrStates = NULL, defAttrStatesTop = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20111 | xmlNodePtr oldnode; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20112 | #ifdef DEBUG_ATTR_VALIDATION |
| 20113 | int redundant = 0; |
| 20114 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20115 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20116 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 20117 | /* |
| 20118 | * Allow all attributes if the type is anyType. |
| 20119 | */ |
| 20120 | if (type == xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE)) |
| 20121 | return (0); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20122 | |
| 20123 | oldnode = ctxt->node; |
| 20124 | if (type != NULL) |
| 20125 | attrUse = type->attributeUses; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20126 | while (attrUse != NULL) { |
Daniel Veillard | c85d0fe | 2004-04-16 16:46:51 +0000 | [diff] [blame] | 20127 | found = 0; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20128 | attrDecl = attrUse->attr; |
| 20129 | #ifdef DEBUG_ATTR_VALIDATION |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20130 | printf("attr use - name: %s\n", xmlSchemaGetAttrName(attrDecl)); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20131 | printf("attr use - use: %d\n", attrDecl->occurs); |
| 20132 | #endif |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 20133 | for (curState = ctxt->attr; curState != NULL; curState = curState->next) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20134 | |
| 20135 | if (curState->decl == attrUse->attr) { |
| 20136 | #ifdef DEBUG_ATTR_VALIDATION |
| 20137 | redundant = 1; |
| 20138 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20139 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20140 | attr = curState->attr; |
| 20141 | #ifdef DEBUG_ATTR_VALIDATION |
| 20142 | printf("attr - name: %s\n", attr->name); |
| 20143 | if (attr->ns != NULL) |
| 20144 | printf("attr - ns: %s\n", attr->ns->href); |
| 20145 | else |
| 20146 | printf("attr - ns: none\n"); |
| 20147 | #endif |
| 20148 | /* TODO: Can this ever happen? */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20149 | if (attr == NULL) |
| 20150 | continue; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20151 | if (attrDecl->ref != NULL) { |
| 20152 | if (!xmlStrEqual(attr->name, attrDecl->ref)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20153 | continue; |
| 20154 | if (attr->ns != NULL) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20155 | if ((attrDecl->refNs == NULL) || |
| 20156 | (!xmlStrEqual(attr->ns->href, attrDecl->refNs))) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20157 | continue; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20158 | } else if (attrDecl->refNs != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20159 | continue; |
| 20160 | } |
| 20161 | } else { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20162 | if (!xmlStrEqual(attr->name, attrDecl->name)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20163 | continue; |
| 20164 | /* |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 20165 | * handle the namespaces checks here |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20166 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 20167 | if (attr->ns == NULL) { |
| 20168 | /* |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 20169 | * accept an unqualified attribute only if the target |
| 20170 | * namespace of the declaration is absent. |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 20171 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20172 | if (attrDecl->targetNamespace != NULL) |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 20173 | /* |
| 20174 | * This check was removed, since the target namespace |
| 20175 | * was evaluated during parsing and already took |
| 20176 | * "attributeFormDefault" into account. |
| 20177 | */ |
| 20178 | /* ((attributes->flags & XML_SCHEMAS_ATTR_NSDEFAULT) == 0)) */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 20179 | continue; |
| 20180 | } else { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20181 | if (attrDecl->targetNamespace == NULL) |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 20182 | continue; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20183 | if (!xmlStrEqual(attrDecl->targetNamespace, |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 20184 | attr->ns->href)) |
| 20185 | continue; |
| 20186 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20187 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20188 | #ifdef DEBUG_ATTR_VALIDATION |
| 20189 | printf("found\n"); |
| 20190 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20191 | found = 1; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20192 | curState->decl = attrDecl; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 20193 | curState->state = XML_SCHEMAS_ATTR_VALIDATE_VALUE; |
| 20194 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20195 | ret = xmlSchemaCheckAttrLocallyValid(ctxt, attrDecl, curState, attr); |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 20196 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20197 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20198 | if (!found) { |
| 20199 | if (attrDecl->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED) { |
| 20200 | xmlSchemaAttrStatePtr tmp; |
| 20201 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20202 | #ifdef DEBUG_ATTR_VALIDATION |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20203 | printf("required attr not found\n"); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20204 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20205 | /* |
| 20206 | * Add a new dummy attribute state. |
| 20207 | */ |
| 20208 | tmp = (xmlSchemaAttrStatePtr) xmlMalloc(sizeof(xmlSchemaAttrState)); |
| 20209 | if (tmp == NULL) { |
| 20210 | xmlSchemaVErrMemory(ctxt, "registering required attributes", NULL); |
| 20211 | ctxt->node = oldnode; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 20212 | goto fatal_exit; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20213 | } |
| 20214 | tmp->attr = NULL; |
| 20215 | tmp->state = XML_SCHEMAS_ATTR_MISSING; |
| 20216 | tmp->decl = attrDecl; |
| 20217 | tmp->next = NULL; |
| 20218 | |
| 20219 | if (reqAttrStates == NULL) { |
| 20220 | reqAttrStates = tmp; |
| 20221 | reqAttrStatesTop = tmp; |
| 20222 | } else { |
| 20223 | reqAttrStatesTop->next = tmp; |
| 20224 | reqAttrStatesTop = tmp; |
| 20225 | } |
| 20226 | } else if ((attrDecl->occurs == XML_SCHEMAS_ATTR_USE_OPTIONAL) && |
| 20227 | (xmlSchemaGetEffectiveValueConstraint(attrDecl, |
| 20228 | &fixed, &defValue, &defVal))) { |
| 20229 | xmlSchemaAttrStatePtr tmp; |
| 20230 | /* |
| 20231 | * Handle non existent default/fixed attributes. |
| 20232 | */ |
| 20233 | tmp = (xmlSchemaAttrStatePtr) |
| 20234 | xmlMalloc(sizeof(xmlSchemaAttrState)); |
| 20235 | if (tmp == NULL) { |
| 20236 | xmlSchemaVErrMemory(ctxt, |
| 20237 | "registering schema specified attributes", NULL); |
| 20238 | ctxt->node = oldnode; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 20239 | goto fatal_exit; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20240 | } |
| 20241 | tmp->attr = NULL; |
| 20242 | tmp->state = XML_SCHEMAS_ATTR_DEFAULT; |
| 20243 | tmp->decl = attrDecl; |
| 20244 | tmp->value = defValue; |
| 20245 | tmp->next = NULL; |
| 20246 | |
| 20247 | if (defAttrStates == NULL) { |
| 20248 | defAttrStates = tmp; |
| 20249 | defAttrStates = tmp; |
| 20250 | } else { |
| 20251 | defAttrStates->next = tmp; |
| 20252 | defAttrStatesTop = tmp; |
| 20253 | } |
| 20254 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20255 | } |
| 20256 | attrUse = attrUse->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20257 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20258 | /* |
| 20259 | * Add required attributes to the attribute states of the context. |
| 20260 | */ |
| 20261 | if (reqAttrStates != NULL) { |
| 20262 | if (ctxt->attr == NULL) { |
| 20263 | ctxt->attr = reqAttrStates; |
| 20264 | } else { |
| 20265 | ctxt->attrTop->next = reqAttrStates; |
| 20266 | } |
| 20267 | ctxt->attrTop = reqAttrStatesTop; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 20268 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20269 | /* |
| 20270 | * Process wildcards. |
| 20271 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20272 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20273 | if ((type != NULL) && (type->attributeWildcard != NULL)) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20274 | #ifdef DEBUG_ATTR_VALIDATION |
| 20275 | xmlSchemaWildcardNsPtr ns; |
| 20276 | printf("matching wildcard: [%d] of complexType: %s\n", type->attributeWildcard, type->name); |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 20277 | if (type->attributeWildcard->processContents == |
| 20278 | XML_SCHEMAS_ANY_LAX) |
| 20279 | printf("processContents: lax\n"); |
| 20280 | else if (type->attributeWildcard->processContents == |
| 20281 | XML_SCHEMAS_ANY_STRICT) |
| 20282 | printf("processContents: strict\n"); |
| 20283 | else |
| 20284 | printf("processContents: skip\n"); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20285 | if (type->attributeWildcard->any) |
| 20286 | printf("type: any\n"); |
| 20287 | else if (type->attributeWildcard->negNsSet != NULL) { |
| 20288 | printf("type: negated\n"); |
| 20289 | if (type->attributeWildcard->negNsSet->value == NULL) |
| 20290 | printf("ns: (absent)\n"); |
| 20291 | else |
| 20292 | printf("ns: %s\n", type->attributeWildcard->negNsSet->value); |
| 20293 | } else if (type->attributeWildcard->nsSet != NULL) { |
| 20294 | printf("type: set\n"); |
| 20295 | ns = type->attributeWildcard->nsSet; |
| 20296 | while (ns != NULL) { |
| 20297 | if (ns->value == NULL) |
| 20298 | printf("ns: (absent)\n"); |
| 20299 | else |
| 20300 | printf("ns: %s\n", ns->value); |
| 20301 | ns = ns->next; |
| 20302 | } |
| 20303 | } else |
| 20304 | printf("empty\n"); |
| 20305 | |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 20306 | |
| 20307 | #endif |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20308 | curState = ctxt->attr; |
| 20309 | while (curState != NULL) { |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 20310 | if (curState->state == XML_SCHEMAS_ATTR_UNKNOWN) { |
| 20311 | if (curState->attr->ns != NULL) |
| 20312 | nsURI = curState->attr->ns->href; |
| 20313 | else |
| 20314 | nsURI = NULL; |
| 20315 | if (xmlSchemaMatchesWildcardNs(type->attributeWildcard, |
| 20316 | nsURI)) { |
| 20317 | /* |
| 20318 | * Handle processContents. |
| 20319 | */ |
| 20320 | if ((type->attributeWildcard->processContents == |
| 20321 | XML_SCHEMAS_ANY_LAX) || |
| 20322 | (type->attributeWildcard->processContents == |
| 20323 | XML_SCHEMAS_ANY_STRICT)) { |
| 20324 | |
| 20325 | attr = curState->attr; |
| 20326 | attrDecl = xmlSchemaGetAttribute(ctxt->schema, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20327 | attr->name, nsURI); |
| 20328 | curState->decl = attrDecl; |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 20329 | if (attrDecl != NULL) { |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 20330 | curState->decl = attrDecl; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 20331 | curState->state = XML_SCHEMAS_ATTR_VALIDATE_VALUE; |
| 20332 | /* TODO |
| 20333 | ret = xmlSchemaCheckAttrLocallyValid(ctxt, attrDecl, curState, attr); |
| 20334 | */ |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 20335 | } else if (type->attributeWildcard->processContents == |
| 20336 | XML_SCHEMAS_ANY_LAX) { |
| 20337 | curState->state = XML_SCHEMAS_ATTR_CHECKED; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 20338 | } else |
| 20339 | curState->state = XML_SCHEMAS_ATTR_WILD_NO_DECL; |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 20340 | } else |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20341 | curState->state = XML_SCHEMAS_ATTR_CHECKED; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 20342 | } |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 20343 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20344 | curState = curState->next; |
| 20345 | } |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 20346 | } |
| 20347 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 20348 | if (ctxt->attr != NULL) { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 20349 | int valueNeeded; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 20350 | |
| 20351 | /* |
| 20352 | * Validate the value of the attribute. |
| 20353 | */ |
| 20354 | if (ctxt->value != NULL) { |
| 20355 | xmlSchemaFreeValue(ctxt->value); |
| 20356 | ctxt->value = NULL; |
| 20357 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 20358 | curState = ctxt->attr; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 20359 | while ((curState != NULL) && (curState != ctxt->attrTop->next)) { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 20360 | valueNeeded = 0; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 20361 | switch (curState->state) { |
| 20362 | case XML_SCHEMAS_ATTR_VALIDATE_VALUE: |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 20363 | |
| 20364 | /* |
| 20365 | * Create an attribute info if needed. |
| 20366 | */ |
| 20367 | if (ctxt->attrInfo == NULL) { |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 20368 | ctxt->attrInfo = (xmlSchemaNodeInfoPtr) |
| 20369 | xmlMalloc(sizeof(xmlSchemaNodeInfo)); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 20370 | if (ctxt->attrInfo == NULL) { |
| 20371 | xmlSchemaVErrMemory(ctxt, |
| 20372 | "allocating an attribute info", NULL); |
| 20373 | goto fatal_exit; |
| 20374 | } |
| 20375 | } |
| 20376 | /* |
| 20377 | * Init the attribute info. |
| 20378 | */ |
| 20379 | ctxt->attrInfo->flags = 0; |
| 20380 | ctxt->attrInfo->node = (xmlNodePtr) curState->attr; |
| 20381 | ctxt->attrInfo->decl = (xmlSchemaTypePtr) curState->decl; |
| 20382 | ctxt->attrInfo->value = NULL; |
| 20383 | if (curState->decl != NULL) |
| 20384 | ctxt->attrInfo->typeDef = curState->decl->subtypes; |
| 20385 | else |
| 20386 | ctxt->attrInfo->typeDef = NULL; |
| 20387 | if (curState->attr->ns != NULL) |
| 20388 | ctxt->attrInfo->namespaceName = |
| 20389 | curState->attr->ns->href; |
| 20390 | else |
| 20391 | ctxt->attrInfo->namespaceName = NULL; |
| 20392 | ctxt->attrInfo->localName = curState->attr->name; |
| 20393 | |
| 20394 | ctxt->nodeInfo = ctxt->attrInfo; |
| 20395 | |
| 20396 | #ifdef IDC_ENABLED |
| 20397 | /* |
| 20398 | * Evaluate IDCs. |
| 20399 | */ |
| 20400 | if (ctxt->xpathStates != NULL) { |
| 20401 | ret = xmlSchemaXPathEvaluate(ctxt, |
| 20402 | XML_ATTRIBUTE_NODE); |
| 20403 | if (ret == -1) |
| 20404 | goto fatal_exit; |
| 20405 | } |
| 20406 | |
| 20407 | #endif |
| 20408 | ret = xmlSchemaCheckAttrLocallyValid(ctxt, curState); |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 20409 | if (ret == -1) |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 20410 | goto fatal_exit; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 20411 | if ((ret != 0) && (ctxt->value != NULL)) { |
| 20412 | xmlSchemaFreeValue(ctxt->value); |
| 20413 | ctxt->value = NULL; |
| 20414 | } |
| 20415 | /* No break on purpose. */ |
| 20416 | case XML_SCHEMAS_ATTR_CHECKED: |
| 20417 | #ifdef IDC_ENABLED |
| 20418 | if (ctxt->xpathStates != NULL) { |
| 20419 | /* |
| 20420 | * Evaluate IDCs. |
| 20421 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 20422 | if (ctxt->value != NULL) { |
| 20423 | ctxt->attrInfo->value = ctxt->value; |
| 20424 | ctxt->value = NULL; |
| 20425 | } |
| 20426 | if (xmlSchemaXPathProcessHistory(ctxt, ctxt->depth +1) == -1) |
| 20427 | goto fatal_exit; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 20428 | } |
| 20429 | break; |
| 20430 | #endif |
| 20431 | default: |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 20432 | break; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 20433 | } |
| 20434 | curState = curState->next; |
| 20435 | } |
| 20436 | |
| 20437 | /* |
| 20438 | * Report missing and illegal attributes. |
| 20439 | */ |
| 20440 | curState = ctxt->attr; |
| 20441 | while ((curState != NULL) && (curState != ctxt->attrTop->next)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 20442 | if (curState->state != XML_SCHEMAS_ATTR_CHECKED) { |
| 20443 | attr = curState->attr; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20444 | if (curState->decl != NULL) { |
| 20445 | if (curState->decl->ref != NULL) |
| 20446 | attrDecl = curState->decl->refDecl; |
| 20447 | else |
| 20448 | attrDecl = curState->decl; |
| 20449 | } else |
| 20450 | attrDecl = NULL; |
| 20451 | if (curState->state == XML_SCHEMAS_ATTR_MISSING) { |
| 20452 | xmlSchemaVMissingAttrErr(ctxt, elem, attrDecl); |
| 20453 | } else if (curState->state == |
| 20454 | XML_SCHEMAS_ATTR_TYPE_NOT_RESOLVED) { |
| 20455 | xmlSchemaVCustomErr(ctxt, |
| 20456 | XML_SCHEMAV_CVC_ATTRIBUTE_2, |
| 20457 | (xmlNodePtr) attr, |
| 20458 | (xmlSchemaTypePtr) attrDecl, |
| 20459 | "The type definition is absent", |
| 20460 | NULL); |
| 20461 | } else if (curState->state == |
| 20462 | XML_SCHEMAS_ATTR_INVALID_FIXED_VALUE) { |
| 20463 | xmlSchemaVCustomErr(ctxt, |
| 20464 | XML_SCHEMAV_CVC_AU, |
| 20465 | (xmlNodePtr) attr, (xmlSchemaTypePtr) attrDecl, |
| 20466 | "The value does not match the fixed value " |
| 20467 | "constraint", NULL); |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 20468 | } else if (curState->state == XML_SCHEMAS_ATTR_WILD_NO_DECL) { |
| 20469 | xmlSchemaVWildcardErr(ctxt, |
| 20470 | XML_SCHEMAV_CVC_WILDCARD, |
| 20471 | (xmlNodePtr) attr, |
| 20472 | type->attributeWildcard, |
| 20473 | "No global attribute declaration found, but " |
| 20474 | "stipulated by the strict processContents of " |
| 20475 | "the wildcard"); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20476 | } else if (curState->state == XML_SCHEMAS_ATTR_UNKNOWN) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 20477 | /* TODO: "prohibited" won't ever be touched here!. |
| 20478 | (curState->state == XML_SCHEMAS_ATTR_PROHIBITED)) |
| 20479 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20480 | /* |
| 20481 | * TODO: One might report different error messages |
| 20482 | * for the following errors. |
| 20483 | */ |
| 20484 | if ((type == NULL) || (type->attributeWildcard == NULL)) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 20485 | xmlSchemaVIllegalAttrErr(ctxt, |
| 20486 | XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_1, attr); |
| 20487 | } else { |
| 20488 | xmlSchemaVIllegalAttrErr(ctxt, |
| 20489 | XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_2, attr); |
| 20490 | } |
| 20491 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 20492 | } |
| 20493 | curState = curState->next; |
| 20494 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20495 | } |
| 20496 | |
| 20497 | /* |
| 20498 | * Add missing default/fixed attributes. |
| 20499 | */ |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 20500 | if (defAttrStates != NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20501 | curState = defAttrStates; |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 20502 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20503 | while (curState != NULL) { |
| 20504 | attrDecl = curState->decl; |
| 20505 | if (attrDecl->ref != NULL) |
| 20506 | attrDecl = attrDecl->refDecl; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20507 | |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 20508 | #ifdef IDC_ENABLED |
| 20509 | /* |
| 20510 | * Evaluate IDCs on default attributes. |
| 20511 | */ |
| 20512 | if (ctxt->xpathStates != NULL) { |
| 20513 | /* |
| 20514 | * Create an attribute info if needed. |
| 20515 | */ |
| 20516 | if (ctxt->attrInfo == NULL) { |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 20517 | ctxt->attrInfo = (xmlSchemaNodeInfoPtr) |
| 20518 | xmlMalloc(sizeof(xmlSchemaNodeInfo)); |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 20519 | if (ctxt->attrInfo == NULL) { |
| 20520 | xmlSchemaVErrMemory(ctxt, |
| 20521 | "allocating an attribute info", NULL); |
| 20522 | goto fatal_exit; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20523 | } |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 20524 | ctxt->attrInfo->value = NULL; |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 20525 | } |
| 20526 | /* |
| 20527 | * Init the attribute info. |
Kasimier T. Buchcik | 285ebab | 2005-03-04 18:04:59 +0000 | [diff] [blame] | 20528 | * TODO: Hmm, maby a bit oversized this all. |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 20529 | */ |
| 20530 | ctxt->attrInfo->flags = 0; |
| 20531 | ctxt->attrInfo->decl = (xmlSchemaTypePtr) attrDecl; |
| 20532 | ctxt->attrInfo->node = NULL; |
| 20533 | ctxt->attrInfo->typeDef = attrDecl->subtypes; |
| 20534 | ctxt->attrInfo->namespaceName = attrDecl->targetNamespace; |
| 20535 | ctxt->attrInfo->localName = attrDecl->name; |
| 20536 | |
| 20537 | ctxt->nodeInfo = ctxt->attrInfo; |
| 20538 | |
| 20539 | ret = xmlSchemaXPathEvaluate(ctxt, |
| 20540 | XML_ATTRIBUTE_NODE); |
| 20541 | if (ret == -1) |
| 20542 | goto fatal_exit; |
| 20543 | if (ctxt->attrInfo->value != NULL) { |
| 20544 | xmlSchemaFreeValue(ctxt->attrInfo->value); |
| 20545 | ctxt->attrInfo->value = NULL; |
| 20546 | } |
| 20547 | if (ret > 0) { |
Kasimier T. Buchcik | 285ebab | 2005-03-04 18:04:59 +0000 | [diff] [blame] | 20548 | /* |
| 20549 | * IDCs will consume the precomputed default value, |
| 20550 | * so we need to clone it somehow. |
| 20551 | */ |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 20552 | /* |
| 20553 | * string or anySimpleType does not create a precomputed value |
| 20554 | * by default, so it will be created here on demand. |
| 20555 | * TODO: default/fixed attributes are a bit unoptimized: |
| 20556 | * the string value will be hold by ->defValue and inside |
| 20557 | * the precomputed value. |
| 20558 | */ |
| 20559 | if (attrDecl->defVal == NULL) { |
| 20560 | xmlChar *str = xmlStrdup(attrDecl->defValue); |
| 20561 | |
| 20562 | if (xmlSchemaPostCreateVal(ctxt, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 20563 | ctxt->attrInfo->typeDef, |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 20564 | str, |
| 20565 | &(attrDecl->defVal)) == -1) { |
| 20566 | FREE_AND_NULL(str) |
| 20567 | goto fatal_exit; |
| 20568 | } |
| 20569 | } |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 20570 | ctxt->attrInfo->value = xmlSchemaCopyValue(attrDecl->defVal); |
| 20571 | /* TODO: error on NULL return. */ |
| 20572 | } |
Kasimier T. Buchcik | 285ebab | 2005-03-04 18:04:59 +0000 | [diff] [blame] | 20573 | |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 20574 | if (xmlSchemaXPathProcessHistory(ctxt, ctxt->depth +1) == -1) |
| 20575 | goto fatal_exit; |
| 20576 | } |
| 20577 | #endif |
| 20578 | |
| 20579 | if (ctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) { |
| 20580 | /* |
| 20581 | * PSVI: Add a new attribute node to the current element. |
| 20582 | */ |
| 20583 | if (attrDecl->targetNamespace == NULL) { |
| 20584 | xmlNewProp(elem, attrDecl->name, curState->value); |
| 20585 | } else { |
| 20586 | xmlNsPtr ns; |
| 20587 | |
| 20588 | ns = xmlSearchNsByHref(elem->doc, elem, |
| 20589 | attrDecl->targetNamespace); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20590 | if (ns == NULL) { |
Kasimier T. Buchcik | ff858ca | 2005-02-18 11:37:58 +0000 | [diff] [blame] | 20591 | xmlChar prefix[12]; |
| 20592 | int counter = 1; |
| 20593 | |
| 20594 | attr = curState->attr; |
| 20595 | /* |
| 20596 | * Create a namespace declaration on the validation |
| 20597 | * root node if no namespace declaration is in scope. |
| 20598 | */ |
| 20599 | snprintf((char *) prefix, sizeof(prefix), "p"); |
| 20600 | /* |
| 20601 | * This is somehow not performant, since the ancestor |
| 20602 | * axis beyond @elem will be searched as well. |
| 20603 | */ |
| 20604 | ns = xmlSearchNs(elem->doc, elem, BAD_CAST prefix); |
| 20605 | while (ns != NULL) { |
| 20606 | if (counter > 1000) { |
| 20607 | xmlSchemaVErr(ctxt, (xmlNodePtr) attr, |
| 20608 | XML_SCHEMAV_INTERNAL, |
| 20609 | "Internal error: xmlSchemaValidateAttributes, " |
| 20610 | "could not compute a ns prefix for " |
| 20611 | "default/fixed attribute '%s'.\n", |
| 20612 | attrDecl->name, NULL); |
| 20613 | |
| 20614 | break; |
| 20615 | } |
| 20616 | snprintf((char *) prefix, |
| 20617 | sizeof(prefix), "p%d", counter++); |
| 20618 | ns = xmlSearchNs(elem->doc, elem, |
| 20619 | BAD_CAST prefix); |
| 20620 | } |
| 20621 | if (ns == NULL) { |
| 20622 | ns = xmlNewNs(ctxt->validationRoot, |
| 20623 | attrDecl->targetNamespace, BAD_CAST prefix); |
| 20624 | xmlNewNsProp(elem, ns, attrDecl->name, |
| 20625 | curState->value); |
| 20626 | } |
| 20627 | } else { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20628 | xmlNewNsProp(elem, ns, attrDecl->name, |
| 20629 | curState->value); |
| 20630 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20631 | } |
| 20632 | } |
| 20633 | curState = curState->next; |
| 20634 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 20635 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 20636 | ret = ctxt->err; |
| 20637 | goto exit; |
| 20638 | |
| 20639 | fatal_exit: |
| 20640 | ret = -1; |
| 20641 | |
| 20642 | exit: |
| 20643 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20644 | if (defAttrStates != NULL) |
| 20645 | xmlSchemaFreeAttributeStates(defAttrStates); |
| 20646 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20647 | #ifdef DEBUG_ATTR_VALIDATION |
| 20648 | if (redundant) |
| 20649 | xmlGenericError(xmlGenericErrorContext, |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 20650 | "xmlSchemaValidateAttributes: redundant call by " |
| 20651 | "type: %s\n", type->name); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20652 | #endif |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 20653 | ctxt->nodeInfo = ctxt->elemInfos[ctxt->depth]; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20654 | ctxt->node = oldnode; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 20655 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20656 | } |
| 20657 | |
| 20658 | /** |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 20659 | * xmlSchemaStartValidation: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20660 | * @ctxt: a schema validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20661 | * |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 20662 | * The starting point of the validation, called by |
| 20663 | * xmlSchemaValidateDocument and xmlSchemaValidateOneElement. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20664 | * |
| 20665 | * Returns 0 if the element is schemas valid, a positive error code |
| 20666 | * number otherwise and -1 in case of internal or API error. |
| 20667 | */ |
| 20668 | static int |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 20669 | xmlSchemaStartValidation(xmlSchemaValidCtxtPtr ctxt) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20670 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20671 | xmlSchemaElementPtr elemDecl; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20672 | int ret = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20673 | |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 20674 | ctxt->err = 0; |
| 20675 | ctxt->nberrors = 0; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20676 | if (ctxt->schema == NULL) { |
| 20677 | /* |
| 20678 | * No schema was specified at time of creation of the validation |
| 20679 | * context. Use xsi:schemaLocation and xsi:noNamespaceSchemaLocation |
| 20680 | * of the instance to build a schema. |
| 20681 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20682 | if (ctxt->pctxt == NULL) |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 20683 | if (xmlSchemaCreatePCtxtOnVCtxt(ctxt) == -1) |
| 20684 | return (-1); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20685 | ctxt->schema = xmlSchemaNewSchema(ctxt->pctxt); |
| 20686 | if (ctxt->schema == NULL) |
| 20687 | return (-1); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20688 | ctxt->xsiAssemble = 1; |
| 20689 | } else |
| 20690 | ctxt->xsiAssemble = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20691 | /* |
| 20692 | * Assemble new schemata using xsi. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 20693 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20694 | if (ctxt->xsiAssemble) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20695 | ret = xmlSchemaAssembleByXSIElem(ctxt, ctxt->node); |
| 20696 | if (ret == -1) { |
| 20697 | xmlSchemaVCustomErr(ctxt, |
| 20698 | XML_SCHEMAV_INTERNAL, |
| 20699 | ctxt->node, NULL, |
| 20700 | "Internal error: xmlSchemaValidateElement, " |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20701 | "assembling schema by xsi", NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20702 | } |
| 20703 | /* |
| 20704 | * NOTE: We won't react on schema parser errors here. |
| 20705 | * TODO: But a warning would be nice. |
| 20706 | */ |
| 20707 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20708 | if (ret != -1) { |
| 20709 | if (ctxt->node->ns != NULL) |
| 20710 | elemDecl = xmlSchemaGetElem(ctxt->schema, ctxt->node->name, |
| 20711 | ctxt->node->ns->href); |
| 20712 | else |
| 20713 | elemDecl = xmlSchemaGetElem(ctxt->schema, ctxt->node->name, NULL); |
| 20714 | |
| 20715 | if (elemDecl == NULL) { |
| 20716 | xmlSchemaVCustomErr(ctxt, |
| 20717 | XML_SCHEMAV_CVC_ELT_1, |
| 20718 | ctxt->node, NULL, |
| 20719 | "No matching global declaration available", NULL); |
| 20720 | ret = XML_SCHEMAV_CVC_ELT_1; |
| 20721 | } else { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 20722 | /* |
| 20723 | * Augment the IDC definitions. |
| 20724 | */ |
| 20725 | if (ctxt->schema->idcDef != NULL) { |
| 20726 | xmlHashScan(ctxt->schema->idcDef, |
| 20727 | (xmlHashScanner) xmlSchemaAugmentIDC, ctxt); |
| 20728 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20729 | ctxt->depth = -1; |
| 20730 | xmlSchemaBeginElement(ctxt); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20731 | ret = xmlSchemaValidateElementByDeclaration(ctxt, elemDecl); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20732 | xmlSchemaEndElement(ctxt); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20733 | if (ret < 0) { |
| 20734 | xmlSchemaVCustomErr(ctxt, |
| 20735 | XML_SCHEMAV_INTERNAL, ctxt->node, NULL, |
| 20736 | "Internal error: xmlSchemaValidateElement, " |
| 20737 | "calling validation by declaration", NULL); |
| 20738 | } |
| 20739 | } |
| 20740 | } |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 20741 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20742 | if (ctxt->xsiAssemble) { |
| 20743 | if (ctxt->schema != NULL) { |
| 20744 | xmlSchemaFree(ctxt->schema); |
| 20745 | ctxt->schema = NULL; |
| 20746 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20747 | } |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 20748 | xmlSchemaClearValidCtxt(ctxt); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20749 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20750 | } |
| 20751 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20752 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20753 | /** |
Kasimier T. Buchcik | 5eba91f | 2004-09-08 09:17:27 +0000 | [diff] [blame] | 20754 | * xmlSchemaValidateOneElement: |
| 20755 | * @ctxt: a schema validation context |
| 20756 | * @elem: an element node |
| 20757 | * |
| 20758 | * Validate a branch of a tree, starting with the given @elem. |
| 20759 | * |
| 20760 | * Returns 0 if the element and its subtree is valid, a positive error |
| 20761 | * code number otherwise and -1 in case of an internal or API error. |
| 20762 | */ |
| 20763 | int |
| 20764 | xmlSchemaValidateOneElement(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem) |
| 20765 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20766 | if ((ctxt == NULL) || (elem == NULL) || (elem->type != XML_ELEMENT_NODE)) |
Kasimier T. Buchcik | 5eba91f | 2004-09-08 09:17:27 +0000 | [diff] [blame] | 20767 | return (-1); |
| 20768 | |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 20769 | if (ctxt->schema == NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20770 | xmlSchemaVErr(ctxt, NULL, |
| 20771 | XML_SCHEMAV_INTERNAL, |
| 20772 | "API error: xmlSchemaValidateOneElement, " |
| 20773 | "no schema specified.\n", NULL, NULL); |
| 20774 | return (-1); |
| 20775 | } |
| 20776 | |
Kasimier T. Buchcik | 5eba91f | 2004-09-08 09:17:27 +0000 | [diff] [blame] | 20777 | ctxt->doc = elem->doc; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20778 | ctxt->node = elem; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20779 | ctxt->validationRoot = elem; |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 20780 | return (xmlSchemaStartValidation(ctxt)); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20781 | } |
| 20782 | |
| 20783 | /************************************************************************ |
| 20784 | * * |
| 20785 | * SAX Validation code * |
| 20786 | * * |
| 20787 | ************************************************************************/ |
| 20788 | |
| 20789 | /************************************************************************ |
| 20790 | * * |
| 20791 | * Validation interfaces * |
| 20792 | * * |
| 20793 | ************************************************************************/ |
| 20794 | |
| 20795 | /** |
| 20796 | * xmlSchemaNewValidCtxt: |
| 20797 | * @schema: a precompiled XML Schemas |
| 20798 | * |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 20799 | * Create an XML Schemas validation context based on the given schema. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20800 | * |
| 20801 | * Returns the validation context or NULL in case of error |
| 20802 | */ |
| 20803 | xmlSchemaValidCtxtPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20804 | xmlSchemaNewValidCtxt(xmlSchemaPtr schema) |
| 20805 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20806 | xmlSchemaValidCtxtPtr ret; |
| 20807 | |
| 20808 | ret = (xmlSchemaValidCtxtPtr) xmlMalloc(sizeof(xmlSchemaValidCtxt)); |
| 20809 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20810 | xmlSchemaVErrMemory(NULL, "allocating validation context", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20811 | return (NULL); |
| 20812 | } |
| 20813 | memset(ret, 0, sizeof(xmlSchemaValidCtxt)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 20814 | ret->schema = schema; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20815 | return (ret); |
| 20816 | } |
| 20817 | |
| 20818 | /** |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 20819 | * xmlSchemaClearValidCtxt: |
| 20820 | * @ctxt: the schema validation context |
| 20821 | * |
| 20822 | * Free the resources associated to the schema validation context; |
| 20823 | * leaves some fields alive intended for reuse of the context. |
| 20824 | */ |
| 20825 | static void |
| 20826 | xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt) |
| 20827 | { |
| 20828 | if (vctxt == NULL) |
| 20829 | return; |
| 20830 | |
| 20831 | vctxt->validationRoot = NULL; |
| 20832 | if (vctxt->attr != NULL) { |
| 20833 | xmlSchemaFreeAttributeStates(vctxt->attr); |
| 20834 | vctxt->attr = NULL; |
| 20835 | } |
| 20836 | if (vctxt->value != NULL) { |
| 20837 | xmlSchemaFreeValue(vctxt->value); |
| 20838 | vctxt->value = NULL; |
| 20839 | } |
| 20840 | /* |
| 20841 | * Augmented IDC information. |
| 20842 | */ |
| 20843 | if (vctxt->aidcs != NULL) { |
| 20844 | xmlSchemaIDCAugPtr cur = vctxt->aidcs, next; |
| 20845 | do { |
| 20846 | next = cur->next; |
| 20847 | xmlFree(cur); |
| 20848 | cur = next; |
| 20849 | } while (cur != NULL); |
| 20850 | vctxt->aidcs = NULL; |
| 20851 | } |
| 20852 | if (vctxt->idcNodes != NULL) { |
| 20853 | int i; |
| 20854 | xmlSchemaPSVIIDCNodePtr item; |
| 20855 | |
| 20856 | for (i = 0; i < vctxt->nbIdcNodes; i++) { |
| 20857 | item = vctxt->idcNodes[i]; |
| 20858 | xmlFree(item->keys); |
| 20859 | xmlFree(item); |
| 20860 | } |
| 20861 | xmlFree(vctxt->idcNodes); |
| 20862 | vctxt->idcNodes = NULL; |
| 20863 | } |
| 20864 | /* |
| 20865 | * Note that we won't delete the XPath state pool here. |
| 20866 | */ |
| 20867 | if (vctxt->xpathStates != NULL) { |
| 20868 | xmlSchemaFreeIDCStateObjList(vctxt->xpathStates); |
| 20869 | vctxt->xpathStates = NULL; |
| 20870 | } |
| 20871 | if (vctxt->attrInfo != NULL) { |
| 20872 | if (vctxt->attrInfo->value != NULL) { |
| 20873 | xmlSchemaFreeValue(vctxt->attrInfo->value); |
| 20874 | } |
| 20875 | memset(vctxt->attrInfo, 0, sizeof(xmlSchemaNodeInfo)); |
| 20876 | } |
| 20877 | if (vctxt->elemInfos != NULL) { |
| 20878 | int i; |
| 20879 | xmlSchemaNodeInfoPtr info; |
| 20880 | |
| 20881 | for (i = 0; i < vctxt->sizeElemInfos; i++) { |
| 20882 | info = vctxt->elemInfos[i]; |
| 20883 | if (info == NULL) |
| 20884 | break; |
| 20885 | if (info->value != NULL) { |
| 20886 | xmlSchemaFreeValue(info->value); |
| 20887 | info->value = NULL; |
| 20888 | } |
| 20889 | if (info->idcMatchers != NULL) { |
| 20890 | xmlSchemaIDCFreeMatcherList(info->idcMatchers); |
| 20891 | info->idcMatchers = NULL; |
| 20892 | } |
| 20893 | if (info->idcTable != NULL) { |
| 20894 | xmlSchemaIDCFreeIDCTable(info->idcTable); |
| 20895 | info->idcTable = NULL; |
| 20896 | } |
| 20897 | } |
| 20898 | } |
| 20899 | } |
| 20900 | |
| 20901 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20902 | * xmlSchemaFreeValidCtxt: |
| 20903 | * @ctxt: the schema validation context |
| 20904 | * |
| 20905 | * Free the resources associated to the schema validation context |
| 20906 | */ |
| 20907 | void |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20908 | xmlSchemaFreeValidCtxt(xmlSchemaValidCtxtPtr ctxt) |
| 20909 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20910 | if (ctxt == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20911 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20912 | if (ctxt->attr != NULL) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 20913 | xmlSchemaFreeAttributeStates(ctxt->attr); |
Daniel Veillard | 88c5891 | 2002-04-23 07:12:20 +0000 | [diff] [blame] | 20914 | if (ctxt->value != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20915 | xmlSchemaFreeValue(ctxt->value); |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 20916 | if (ctxt->pctxt != NULL) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20917 | xmlSchemaFreeParserCtxt(ctxt->pctxt); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20918 | if (ctxt->idcNodes != NULL) { |
| 20919 | int i; |
| 20920 | xmlSchemaPSVIIDCNodePtr item; |
| 20921 | |
| 20922 | for (i = 0; i < ctxt->nbIdcNodes; i++) { |
| 20923 | item = ctxt->idcNodes[i]; |
| 20924 | xmlFree(item->keys); |
| 20925 | xmlFree(item); |
| 20926 | } |
| 20927 | xmlFree(ctxt->idcNodes); |
| 20928 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20929 | if (ctxt->idcKeys != NULL) { |
| 20930 | int i; |
| 20931 | for (i = 0; i < ctxt->nbIdcKeys; i++) |
| 20932 | xmlSchemaIDCFreeKey(ctxt->idcKeys[i]); |
| 20933 | xmlFree(ctxt->idcKeys); |
| 20934 | } |
| 20935 | |
| 20936 | if (ctxt->xpathStates != NULL) |
| 20937 | xmlSchemaFreeIDCStateObjList(ctxt->xpathStates); |
| 20938 | if (ctxt->xpathStatePool != NULL) |
| 20939 | xmlSchemaFreeIDCStateObjList(ctxt->xpathStatePool); |
| 20940 | |
| 20941 | /* |
| 20942 | * Augmented IDC information. |
| 20943 | */ |
| 20944 | if (ctxt->aidcs != NULL) { |
| 20945 | xmlSchemaIDCAugPtr cur = ctxt->aidcs, next; |
| 20946 | do { |
| 20947 | next = cur->next; |
| 20948 | xmlFree(cur); |
| 20949 | cur = next; |
| 20950 | } while (cur != NULL); |
| 20951 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 20952 | if (ctxt->attrInfo != NULL) { |
| 20953 | if (ctxt->attrInfo->value != NULL) |
| 20954 | xmlSchemaFreeValue(ctxt->attrInfo->value); |
| 20955 | xmlFree(ctxt->attrInfo); |
| 20956 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20957 | if (ctxt->elemInfos != NULL) { |
| 20958 | int i; |
Kasimier T. Buchcik | 9b77aa0 | 2005-03-04 22:04:16 +0000 | [diff] [blame] | 20959 | xmlSchemaNodeInfoPtr info; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 20960 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20961 | for (i = 0; i < ctxt->sizeElemInfos; i++) { |
| 20962 | info = ctxt->elemInfos[i]; |
| 20963 | if (info == NULL) |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 20964 | break; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20965 | if (info->value != NULL) |
| 20966 | xmlSchemaFreeValue(info->value); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20967 | if (info->idcMatchers != NULL) |
| 20968 | xmlSchemaIDCFreeMatcherList(info->idcMatchers); |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 20969 | if (info->idcTable != NULL) |
| 20970 | xmlSchemaIDCFreeIDCTable(info->idcTable); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20971 | /* |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 20972 | * TODO: Don't know if those will have to be freed if in streaming |
| 20973 | * mode. |
| 20974 | * |
| 20975 | * xmlFree(info->localName); |
| 20976 | * if (info->namespaceName != NULL) |
| 20977 | * xmlFree(info->namespaceName); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20978 | */ |
| 20979 | xmlFree(info); |
| 20980 | } |
| 20981 | xmlFree(ctxt->elemInfos); |
| 20982 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20983 | xmlFree(ctxt); |
| 20984 | } |
| 20985 | |
| 20986 | /** |
| 20987 | * xmlSchemaSetValidErrors: |
| 20988 | * @ctxt: a schema validation context |
| 20989 | * @err: the error function |
| 20990 | * @warn: the warning function |
Daniel Veillard | a9b66d0 | 2002-12-11 14:23:49 +0000 | [diff] [blame] | 20991 | * @ctx: the functions context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20992 | * |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 20993 | * Set the error and warning callback informations |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20994 | */ |
| 20995 | void |
| 20996 | xmlSchemaSetValidErrors(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20997 | xmlSchemaValidityErrorFunc err, |
| 20998 | xmlSchemaValidityWarningFunc warn, void *ctx) |
| 20999 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 21000 | if (ctxt == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 21001 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 21002 | ctxt->error = err; |
| 21003 | ctxt->warning = warn; |
| 21004 | ctxt->userData = ctx; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 21005 | if (ctxt->pctxt != NULL) |
| 21006 | xmlSchemaSetParserErrors(ctxt->pctxt, err, warn, ctx); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 21007 | } |
| 21008 | |
| 21009 | /** |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 21010 | * xmlSchemaGetValidErrors: |
| 21011 | * @ctxt: a XML-Schema validation context |
| 21012 | * @err: the error function result |
| 21013 | * @warn: the warning function result |
| 21014 | * @ctx: the functions context result |
| 21015 | * |
| 21016 | * Get the error and warning callback informations |
| 21017 | * |
| 21018 | * Returns -1 in case of error and 0 otherwise |
| 21019 | */ |
| 21020 | int |
| 21021 | xmlSchemaGetValidErrors(xmlSchemaValidCtxtPtr ctxt, |
| 21022 | xmlSchemaValidityErrorFunc * err, |
| 21023 | xmlSchemaValidityWarningFunc * warn, void **ctx) |
| 21024 | { |
| 21025 | if (ctxt == NULL) |
| 21026 | return (-1); |
| 21027 | if (err != NULL) |
| 21028 | *err = ctxt->error; |
| 21029 | if (warn != NULL) |
| 21030 | *warn = ctxt->warning; |
| 21031 | if (ctx != NULL) |
| 21032 | *ctx = ctxt->userData; |
| 21033 | return (0); |
| 21034 | } |
| 21035 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 21036 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 21037 | /** |
Daniel Veillard | 6927b10 | 2004-10-27 17:29:04 +0000 | [diff] [blame] | 21038 | * xmlSchemaSetValidOptions: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 21039 | * @ctxt: a schema validation context |
| 21040 | * @options: a combination of xmlSchemaValidOption |
| 21041 | * |
| 21042 | * Sets the options to be used during the validation. |
| 21043 | * |
| 21044 | * Returns 0 in case of success, -1 in case of an |
| 21045 | * API error. |
| 21046 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 21047 | int |
| 21048 | xmlSchemaSetValidOptions(xmlSchemaValidCtxtPtr ctxt, |
| 21049 | int options) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 21050 | |
| 21051 | { |
| 21052 | int i; |
| 21053 | |
| 21054 | if (ctxt == NULL) |
| 21055 | return (-1); |
| 21056 | /* |
| 21057 | * WARNING: Change the start value if adding to the |
| 21058 | * xmlSchemaValidOption. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 21059 | * TODO: Is there an other, more easy to maintain, |
| 21060 | * way? |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 21061 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 21062 | for (i = 1; i < (int) sizeof(int) * 8; i++) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 21063 | if (options & 1<<i) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 21064 | xmlSchemaVErr(ctxt, NULL, |
| 21065 | XML_SCHEMAV_INTERNAL, |
| 21066 | "Internal error: xmlSchemaSetValidOptions, " |
| 21067 | "invalid option argument.\n", NULL, NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 21068 | return (-1); |
| 21069 | } |
| 21070 | } |
| 21071 | ctxt->options = options; |
| 21072 | return (0); |
| 21073 | } |
| 21074 | |
| 21075 | /** |
Daniel Veillard | 6927b10 | 2004-10-27 17:29:04 +0000 | [diff] [blame] | 21076 | * xmlSchemaValidCtxtGetOptions: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 21077 | * @ctxt: a schema validation context |
| 21078 | * |
William M. Brack | 21e4ef2 | 2005-01-02 09:53:13 +0000 | [diff] [blame] | 21079 | * Get the validation context options. |
| 21080 | * |
| 21081 | * Returns the option combination or -1 on error. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 21082 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 21083 | int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 21084 | xmlSchemaValidCtxtGetOptions(xmlSchemaValidCtxtPtr ctxt) |
| 21085 | |
| 21086 | { |
| 21087 | if (ctxt == NULL) |
| 21088 | return (-1); |
| 21089 | else |
| 21090 | return (ctxt->options); |
| 21091 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 21092 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 21093 | |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 21094 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 21095 | * xmlSchemaValidateDoc: |
| 21096 | * @ctxt: a schema validation context |
| 21097 | * @doc: a parsed document tree |
| 21098 | * |
| 21099 | * Validate a document tree in memory. |
| 21100 | * |
| 21101 | * Returns 0 if the document is schemas valid, a positive error code |
| 21102 | * number otherwise and -1 in case of internal or API error. |
| 21103 | */ |
| 21104 | int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 21105 | xmlSchemaValidateDoc(xmlSchemaValidCtxtPtr ctxt, xmlDocPtr doc) |
| 21106 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 21107 | if ((ctxt == NULL) || (doc == NULL)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 21108 | return (-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 21109 | |
Kasimier T. Buchcik | 7f3efa9 | 2005-03-07 17:41:58 +0000 | [diff] [blame] | 21110 | ctxt->doc = doc; |
| 21111 | ctxt->node = xmlDocGetRootElement(doc); |
| 21112 | if (ctxt->node == NULL) { |
| 21113 | xmlSchemaVCustomErr(ctxt, |
| 21114 | XML_SCHEMAV_DOCUMENT_ELEMENT_MISSING, |
| 21115 | (xmlNodePtr) doc, NULL, |
| 21116 | "The document has no document element", NULL); |
| 21117 | return (ctxt->err); |
| 21118 | } |
| 21119 | ctxt->validationRoot = ctxt->node; |
| 21120 | xmlSchemaStartValidation(ctxt); |
| 21121 | |
| 21122 | return (ctxt->err); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 21123 | } |
| 21124 | |
| 21125 | /** |
| 21126 | * xmlSchemaValidateStream: |
| 21127 | * @ctxt: a schema validation context |
| 21128 | * @input: the input to use for reading the data |
| 21129 | * @enc: an optional encoding information |
| 21130 | * @sax: a SAX handler for the resulting events |
| 21131 | * @user_data: the context to provide to the SAX handler. |
| 21132 | * |
| 21133 | * Validate a document tree in memory. |
| 21134 | * |
| 21135 | * Returns 0 if the document is schemas valid, a positive error code |
| 21136 | * number otherwise and -1 in case of internal or API error. |
| 21137 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 21138 | int |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 21139 | xmlSchemaValidateStream(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 21140 | xmlParserInputBufferPtr input, xmlCharEncoding enc, |
| 21141 | xmlSAXHandlerPtr sax, void *user_data) |
| 21142 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 21143 | if ((ctxt == NULL) || (input == NULL)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 21144 | return (-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 21145 | ctxt->input = input; |
| 21146 | ctxt->enc = enc; |
| 21147 | ctxt->sax = sax; |
| 21148 | ctxt->user_data = user_data; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 21149 | TODO return (0); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 21150 | } |
| 21151 | |
| 21152 | #endif /* LIBXML_SCHEMAS_ENABLED */ |