| 1 | n/a | /* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd |
|---|
| 2 | n/a | See the file COPYING for copying permission. |
|---|
| 3 | n/a | */ |
|---|
| 4 | n/a | |
|---|
| 5 | n/a | #define XML_BUILDING_EXPAT 1 |
|---|
| 6 | n/a | |
|---|
| 7 | n/a | #ifdef COMPILED_FROM_DSP |
|---|
| 8 | n/a | #include "winconfig.h" |
|---|
| 9 | n/a | #elif defined(MACOS_CLASSIC) |
|---|
| 10 | n/a | #include "macconfig.h" |
|---|
| 11 | n/a | #elif defined(__amigaos__) |
|---|
| 12 | n/a | #include "amigaconfig.h" |
|---|
| 13 | n/a | #elif defined(__WATCOMC__) |
|---|
| 14 | n/a | #include "watcomconfig.h" |
|---|
| 15 | n/a | #elif defined(HAVE_EXPAT_CONFIG_H) |
|---|
| 16 | n/a | #include <expat_config.h> |
|---|
| 17 | n/a | #endif /* ndef COMPILED_FROM_DSP */ |
|---|
| 18 | n/a | |
|---|
| 19 | n/a | #include <stddef.h> |
|---|
| 20 | n/a | #include <string.h> /* memset(), memcpy() */ |
|---|
| 21 | n/a | #include <assert.h> |
|---|
| 22 | n/a | #include <limits.h> /* UINT_MAX */ |
|---|
| 23 | n/a | #include <time.h> /* time() */ |
|---|
| 24 | n/a | |
|---|
| 25 | n/a | #include "ascii.h" |
|---|
| 26 | n/a | #include "expat.h" |
|---|
| 27 | n/a | |
|---|
| 28 | n/a | #ifdef XML_UNICODE |
|---|
| 29 | n/a | #define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX |
|---|
| 30 | n/a | #define XmlConvert XmlUtf16Convert |
|---|
| 31 | n/a | #define XmlGetInternalEncoding XmlGetUtf16InternalEncoding |
|---|
| 32 | n/a | #define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS |
|---|
| 33 | n/a | #define XmlEncode XmlUtf16Encode |
|---|
| 34 | n/a | /* Using pointer subtraction to convert to integer type. */ |
|---|
| 35 | n/a | #define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((char *)(s) - (char *)NULL) & 1)) |
|---|
| 36 | n/a | typedef unsigned short ICHAR; |
|---|
| 37 | n/a | #else |
|---|
| 38 | n/a | #define XML_ENCODE_MAX XML_UTF8_ENCODE_MAX |
|---|
| 39 | n/a | #define XmlConvert XmlUtf8Convert |
|---|
| 40 | n/a | #define XmlGetInternalEncoding XmlGetUtf8InternalEncoding |
|---|
| 41 | n/a | #define XmlGetInternalEncodingNS XmlGetUtf8InternalEncodingNS |
|---|
| 42 | n/a | #define XmlEncode XmlUtf8Encode |
|---|
| 43 | n/a | #define MUST_CONVERT(enc, s) (!(enc)->isUtf8) |
|---|
| 44 | n/a | typedef char ICHAR; |
|---|
| 45 | n/a | #endif |
|---|
| 46 | n/a | |
|---|
| 47 | n/a | |
|---|
| 48 | n/a | #ifndef XML_NS |
|---|
| 49 | n/a | |
|---|
| 50 | n/a | #define XmlInitEncodingNS XmlInitEncoding |
|---|
| 51 | n/a | #define XmlInitUnknownEncodingNS XmlInitUnknownEncoding |
|---|
| 52 | n/a | #undef XmlGetInternalEncodingNS |
|---|
| 53 | n/a | #define XmlGetInternalEncodingNS XmlGetInternalEncoding |
|---|
| 54 | n/a | #define XmlParseXmlDeclNS XmlParseXmlDecl |
|---|
| 55 | n/a | |
|---|
| 56 | n/a | #endif |
|---|
| 57 | n/a | |
|---|
| 58 | n/a | #ifdef XML_UNICODE |
|---|
| 59 | n/a | |
|---|
| 60 | n/a | #ifdef XML_UNICODE_WCHAR_T |
|---|
| 61 | n/a | #define XML_T(x) (const wchar_t)x |
|---|
| 62 | n/a | #define XML_L(x) L ## x |
|---|
| 63 | n/a | #else |
|---|
| 64 | n/a | #define XML_T(x) (const unsigned short)x |
|---|
| 65 | n/a | #define XML_L(x) x |
|---|
| 66 | n/a | #endif |
|---|
| 67 | n/a | |
|---|
| 68 | n/a | #else |
|---|
| 69 | n/a | |
|---|
| 70 | n/a | #define XML_T(x) x |
|---|
| 71 | n/a | #define XML_L(x) x |
|---|
| 72 | n/a | |
|---|
| 73 | n/a | #endif |
|---|
| 74 | n/a | |
|---|
| 75 | n/a | /* Round up n to be a multiple of sz, where sz is a power of 2. */ |
|---|
| 76 | n/a | #define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1)) |
|---|
| 77 | n/a | |
|---|
| 78 | n/a | /* Handle the case where memmove() doesn't exist. */ |
|---|
| 79 | n/a | #ifndef HAVE_MEMMOVE |
|---|
| 80 | n/a | #ifdef HAVE_BCOPY |
|---|
| 81 | n/a | #define memmove(d,s,l) bcopy((s),(d),(l)) |
|---|
| 82 | n/a | #else |
|---|
| 83 | n/a | #error memmove does not exist on this platform, nor is a substitute available |
|---|
| 84 | n/a | #endif /* HAVE_BCOPY */ |
|---|
| 85 | n/a | #endif /* HAVE_MEMMOVE */ |
|---|
| 86 | n/a | |
|---|
| 87 | n/a | #include "internal.h" |
|---|
| 88 | n/a | #include "xmltok.h" |
|---|
| 89 | n/a | #include "xmlrole.h" |
|---|
| 90 | n/a | |
|---|
| 91 | n/a | typedef const XML_Char *KEY; |
|---|
| 92 | n/a | |
|---|
| 93 | n/a | typedef struct { |
|---|
| 94 | n/a | KEY name; |
|---|
| 95 | n/a | } NAMED; |
|---|
| 96 | n/a | |
|---|
| 97 | n/a | typedef struct { |
|---|
| 98 | n/a | NAMED **v; |
|---|
| 99 | n/a | unsigned char power; |
|---|
| 100 | n/a | size_t size; |
|---|
| 101 | n/a | size_t used; |
|---|
| 102 | n/a | const XML_Memory_Handling_Suite *mem; |
|---|
| 103 | n/a | } HASH_TABLE; |
|---|
| 104 | n/a | |
|---|
| 105 | n/a | /* Basic character hash algorithm, taken from Python's string hash: |
|---|
| 106 | n/a | h = h * 1000003 ^ character, the constant being a prime number. |
|---|
| 107 | n/a | |
|---|
| 108 | n/a | */ |
|---|
| 109 | n/a | #ifdef XML_UNICODE |
|---|
| 110 | n/a | #define CHAR_HASH(h, c) \ |
|---|
| 111 | n/a | (((h) * 0xF4243) ^ (unsigned short)(c)) |
|---|
| 112 | n/a | #else |
|---|
| 113 | n/a | #define CHAR_HASH(h, c) \ |
|---|
| 114 | n/a | (((h) * 0xF4243) ^ (unsigned char)(c)) |
|---|
| 115 | n/a | #endif |
|---|
| 116 | n/a | |
|---|
| 117 | n/a | /* For probing (after a collision) we need a step size relative prime |
|---|
| 118 | n/a | to the hash table size, which is a power of 2. We use double-hashing, |
|---|
| 119 | n/a | since we can calculate a second hash value cheaply by taking those bits |
|---|
| 120 | n/a | of the first hash value that were discarded (masked out) when the table |
|---|
| 121 | n/a | index was calculated: index = hash & mask, where mask = table->size - 1. |
|---|
| 122 | n/a | We limit the maximum step size to table->size / 4 (mask >> 2) and make |
|---|
| 123 | n/a | it odd, since odd numbers are always relative prime to a power of 2. |
|---|
| 124 | n/a | */ |
|---|
| 125 | n/a | #define SECOND_HASH(hash, mask, power) \ |
|---|
| 126 | n/a | ((((hash) & ~(mask)) >> ((power) - 1)) & ((mask) >> 2)) |
|---|
| 127 | n/a | #define PROBE_STEP(hash, mask, power) \ |
|---|
| 128 | n/a | ((unsigned char)((SECOND_HASH(hash, mask, power)) | 1)) |
|---|
| 129 | n/a | |
|---|
| 130 | n/a | typedef struct { |
|---|
| 131 | n/a | NAMED **p; |
|---|
| 132 | n/a | NAMED **end; |
|---|
| 133 | n/a | } HASH_TABLE_ITER; |
|---|
| 134 | n/a | |
|---|
| 135 | n/a | #define INIT_TAG_BUF_SIZE 32 /* must be a multiple of sizeof(XML_Char) */ |
|---|
| 136 | n/a | #define INIT_DATA_BUF_SIZE 1024 |
|---|
| 137 | n/a | #define INIT_ATTS_SIZE 16 |
|---|
| 138 | n/a | #define INIT_ATTS_VERSION 0xFFFFFFFF |
|---|
| 139 | n/a | #define INIT_BLOCK_SIZE 1024 |
|---|
| 140 | n/a | #define INIT_BUFFER_SIZE 1024 |
|---|
| 141 | n/a | |
|---|
| 142 | n/a | #define EXPAND_SPARE 24 |
|---|
| 143 | n/a | |
|---|
| 144 | n/a | typedef struct binding { |
|---|
| 145 | n/a | struct prefix *prefix; |
|---|
| 146 | n/a | struct binding *nextTagBinding; |
|---|
| 147 | n/a | struct binding *prevPrefixBinding; |
|---|
| 148 | n/a | const struct attribute_id *attId; |
|---|
| 149 | n/a | XML_Char *uri; |
|---|
| 150 | n/a | int uriLen; |
|---|
| 151 | n/a | int uriAlloc; |
|---|
| 152 | n/a | } BINDING; |
|---|
| 153 | n/a | |
|---|
| 154 | n/a | typedef struct prefix { |
|---|
| 155 | n/a | const XML_Char *name; |
|---|
| 156 | n/a | BINDING *binding; |
|---|
| 157 | n/a | } PREFIX; |
|---|
| 158 | n/a | |
|---|
| 159 | n/a | typedef struct { |
|---|
| 160 | n/a | const XML_Char *str; |
|---|
| 161 | n/a | const XML_Char *localPart; |
|---|
| 162 | n/a | const XML_Char *prefix; |
|---|
| 163 | n/a | int strLen; |
|---|
| 164 | n/a | int uriLen; |
|---|
| 165 | n/a | int prefixLen; |
|---|
| 166 | n/a | } TAG_NAME; |
|---|
| 167 | n/a | |
|---|
| 168 | n/a | /* TAG represents an open element. |
|---|
| 169 | n/a | The name of the element is stored in both the document and API |
|---|
| 170 | n/a | encodings. The memory buffer 'buf' is a separately-allocated |
|---|
| 171 | n/a | memory area which stores the name. During the XML_Parse()/ |
|---|
| 172 | n/a | XMLParseBuffer() when the element is open, the memory for the 'raw' |
|---|
| 173 | n/a | version of the name (in the document encoding) is shared with the |
|---|
| 174 | n/a | document buffer. If the element is open across calls to |
|---|
| 175 | n/a | XML_Parse()/XML_ParseBuffer(), the buffer is re-allocated to |
|---|
| 176 | n/a | contain the 'raw' name as well. |
|---|
| 177 | n/a | |
|---|
| 178 | n/a | A parser re-uses these structures, maintaining a list of allocated |
|---|
| 179 | n/a | TAG objects in a free list. |
|---|
| 180 | n/a | */ |
|---|
| 181 | n/a | typedef struct tag { |
|---|
| 182 | n/a | struct tag *parent; /* parent of this element */ |
|---|
| 183 | n/a | const char *rawName; /* tagName in the original encoding */ |
|---|
| 184 | n/a | int rawNameLength; |
|---|
| 185 | n/a | TAG_NAME name; /* tagName in the API encoding */ |
|---|
| 186 | n/a | char *buf; /* buffer for name components */ |
|---|
| 187 | n/a | char *bufEnd; /* end of the buffer */ |
|---|
| 188 | n/a | BINDING *bindings; |
|---|
| 189 | n/a | } TAG; |
|---|
| 190 | n/a | |
|---|
| 191 | n/a | typedef struct { |
|---|
| 192 | n/a | const XML_Char *name; |
|---|
| 193 | n/a | const XML_Char *textPtr; |
|---|
| 194 | n/a | int textLen; /* length in XML_Chars */ |
|---|
| 195 | n/a | int processed; /* # of processed bytes - when suspended */ |
|---|
| 196 | n/a | const XML_Char *systemId; |
|---|
| 197 | n/a | const XML_Char *base; |
|---|
| 198 | n/a | const XML_Char *publicId; |
|---|
| 199 | n/a | const XML_Char *notation; |
|---|
| 200 | n/a | XML_Bool open; |
|---|
| 201 | n/a | XML_Bool is_param; |
|---|
| 202 | n/a | XML_Bool is_internal; /* true if declared in internal subset outside PE */ |
|---|
| 203 | n/a | } ENTITY; |
|---|
| 204 | n/a | |
|---|
| 205 | n/a | typedef struct { |
|---|
| 206 | n/a | enum XML_Content_Type type; |
|---|
| 207 | n/a | enum XML_Content_Quant quant; |
|---|
| 208 | n/a | const XML_Char * name; |
|---|
| 209 | n/a | int firstchild; |
|---|
| 210 | n/a | int lastchild; |
|---|
| 211 | n/a | int childcnt; |
|---|
| 212 | n/a | int nextsib; |
|---|
| 213 | n/a | } CONTENT_SCAFFOLD; |
|---|
| 214 | n/a | |
|---|
| 215 | n/a | #define INIT_SCAFFOLD_ELEMENTS 32 |
|---|
| 216 | n/a | |
|---|
| 217 | n/a | typedef struct block { |
|---|
| 218 | n/a | struct block *next; |
|---|
| 219 | n/a | int size; |
|---|
| 220 | n/a | XML_Char s[1]; |
|---|
| 221 | n/a | } BLOCK; |
|---|
| 222 | n/a | |
|---|
| 223 | n/a | typedef struct { |
|---|
| 224 | n/a | BLOCK *blocks; |
|---|
| 225 | n/a | BLOCK *freeBlocks; |
|---|
| 226 | n/a | const XML_Char *end; |
|---|
| 227 | n/a | XML_Char *ptr; |
|---|
| 228 | n/a | XML_Char *start; |
|---|
| 229 | n/a | const XML_Memory_Handling_Suite *mem; |
|---|
| 230 | n/a | } STRING_POOL; |
|---|
| 231 | n/a | |
|---|
| 232 | n/a | /* The XML_Char before the name is used to determine whether |
|---|
| 233 | n/a | an attribute has been specified. */ |
|---|
| 234 | n/a | typedef struct attribute_id { |
|---|
| 235 | n/a | XML_Char *name; |
|---|
| 236 | n/a | PREFIX *prefix; |
|---|
| 237 | n/a | XML_Bool maybeTokenized; |
|---|
| 238 | n/a | XML_Bool xmlns; |
|---|
| 239 | n/a | } ATTRIBUTE_ID; |
|---|
| 240 | n/a | |
|---|
| 241 | n/a | typedef struct { |
|---|
| 242 | n/a | const ATTRIBUTE_ID *id; |
|---|
| 243 | n/a | XML_Bool isCdata; |
|---|
| 244 | n/a | const XML_Char *value; |
|---|
| 245 | n/a | } DEFAULT_ATTRIBUTE; |
|---|
| 246 | n/a | |
|---|
| 247 | n/a | typedef struct { |
|---|
| 248 | n/a | unsigned long version; |
|---|
| 249 | n/a | unsigned long hash; |
|---|
| 250 | n/a | const XML_Char *uriName; |
|---|
| 251 | n/a | } NS_ATT; |
|---|
| 252 | n/a | |
|---|
| 253 | n/a | typedef struct { |
|---|
| 254 | n/a | const XML_Char *name; |
|---|
| 255 | n/a | PREFIX *prefix; |
|---|
| 256 | n/a | const ATTRIBUTE_ID *idAtt; |
|---|
| 257 | n/a | int nDefaultAtts; |
|---|
| 258 | n/a | int allocDefaultAtts; |
|---|
| 259 | n/a | DEFAULT_ATTRIBUTE *defaultAtts; |
|---|
| 260 | n/a | } ELEMENT_TYPE; |
|---|
| 261 | n/a | |
|---|
| 262 | n/a | typedef struct { |
|---|
| 263 | n/a | HASH_TABLE generalEntities; |
|---|
| 264 | n/a | HASH_TABLE elementTypes; |
|---|
| 265 | n/a | HASH_TABLE attributeIds; |
|---|
| 266 | n/a | HASH_TABLE prefixes; |
|---|
| 267 | n/a | STRING_POOL pool; |
|---|
| 268 | n/a | STRING_POOL entityValuePool; |
|---|
| 269 | n/a | /* false once a parameter entity reference has been skipped */ |
|---|
| 270 | n/a | XML_Bool keepProcessing; |
|---|
| 271 | n/a | /* true once an internal or external PE reference has been encountered; |
|---|
| 272 | n/a | this includes the reference to an external subset */ |
|---|
| 273 | n/a | XML_Bool hasParamEntityRefs; |
|---|
| 274 | n/a | XML_Bool standalone; |
|---|
| 275 | n/a | #ifdef XML_DTD |
|---|
| 276 | n/a | /* indicates if external PE has been read */ |
|---|
| 277 | n/a | XML_Bool paramEntityRead; |
|---|
| 278 | n/a | HASH_TABLE paramEntities; |
|---|
| 279 | n/a | #endif /* XML_DTD */ |
|---|
| 280 | n/a | PREFIX defaultPrefix; |
|---|
| 281 | n/a | /* === scaffolding for building content model === */ |
|---|
| 282 | n/a | XML_Bool in_eldecl; |
|---|
| 283 | n/a | CONTENT_SCAFFOLD *scaffold; |
|---|
| 284 | n/a | unsigned contentStringLen; |
|---|
| 285 | n/a | unsigned scaffSize; |
|---|
| 286 | n/a | unsigned scaffCount; |
|---|
| 287 | n/a | int scaffLevel; |
|---|
| 288 | n/a | int *scaffIndex; |
|---|
| 289 | n/a | } DTD; |
|---|
| 290 | n/a | |
|---|
| 291 | n/a | typedef struct open_internal_entity { |
|---|
| 292 | n/a | const char *internalEventPtr; |
|---|
| 293 | n/a | const char *internalEventEndPtr; |
|---|
| 294 | n/a | struct open_internal_entity *next; |
|---|
| 295 | n/a | ENTITY *entity; |
|---|
| 296 | n/a | int startTagLevel; |
|---|
| 297 | n/a | XML_Bool betweenDecl; /* WFC: PE Between Declarations */ |
|---|
| 298 | n/a | } OPEN_INTERNAL_ENTITY; |
|---|
| 299 | n/a | |
|---|
| 300 | n/a | typedef enum XML_Error PTRCALL Processor(XML_Parser parser, |
|---|
| 301 | n/a | const char *start, |
|---|
| 302 | n/a | const char *end, |
|---|
| 303 | n/a | const char **endPtr); |
|---|
| 304 | n/a | |
|---|
| 305 | n/a | static Processor prologProcessor; |
|---|
| 306 | n/a | static Processor prologInitProcessor; |
|---|
| 307 | n/a | static Processor contentProcessor; |
|---|
| 308 | n/a | static Processor cdataSectionProcessor; |
|---|
| 309 | n/a | #ifdef XML_DTD |
|---|
| 310 | n/a | static Processor ignoreSectionProcessor; |
|---|
| 311 | n/a | static Processor externalParEntProcessor; |
|---|
| 312 | n/a | static Processor externalParEntInitProcessor; |
|---|
| 313 | n/a | static Processor entityValueProcessor; |
|---|
| 314 | n/a | static Processor entityValueInitProcessor; |
|---|
| 315 | n/a | #endif /* XML_DTD */ |
|---|
| 316 | n/a | static Processor epilogProcessor; |
|---|
| 317 | n/a | static Processor errorProcessor; |
|---|
| 318 | n/a | static Processor externalEntityInitProcessor; |
|---|
| 319 | n/a | static Processor externalEntityInitProcessor2; |
|---|
| 320 | n/a | static Processor externalEntityInitProcessor3; |
|---|
| 321 | n/a | static Processor externalEntityContentProcessor; |
|---|
| 322 | n/a | static Processor internalEntityProcessor; |
|---|
| 323 | n/a | |
|---|
| 324 | n/a | static enum XML_Error |
|---|
| 325 | n/a | handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName); |
|---|
| 326 | n/a | static enum XML_Error |
|---|
| 327 | n/a | processXmlDecl(XML_Parser parser, int isGeneralTextEntity, |
|---|
| 328 | n/a | const char *s, const char *next); |
|---|
| 329 | n/a | static enum XML_Error |
|---|
| 330 | n/a | initializeEncoding(XML_Parser parser); |
|---|
| 331 | n/a | static enum XML_Error |
|---|
| 332 | n/a | doProlog(XML_Parser parser, const ENCODING *enc, const char *s, |
|---|
| 333 | n/a | const char *end, int tok, const char *next, const char **nextPtr, |
|---|
| 334 | n/a | XML_Bool haveMore); |
|---|
| 335 | n/a | static enum XML_Error |
|---|
| 336 | n/a | processInternalEntity(XML_Parser parser, ENTITY *entity, |
|---|
| 337 | n/a | XML_Bool betweenDecl); |
|---|
| 338 | n/a | static enum XML_Error |
|---|
| 339 | n/a | doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, |
|---|
| 340 | n/a | const char *start, const char *end, const char **endPtr, |
|---|
| 341 | n/a | XML_Bool haveMore); |
|---|
| 342 | n/a | static enum XML_Error |
|---|
| 343 | n/a | doCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr, |
|---|
| 344 | n/a | const char *end, const char **nextPtr, XML_Bool haveMore); |
|---|
| 345 | n/a | #ifdef XML_DTD |
|---|
| 346 | n/a | static enum XML_Error |
|---|
| 347 | n/a | doIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr, |
|---|
| 348 | n/a | const char *end, const char **nextPtr, XML_Bool haveMore); |
|---|
| 349 | n/a | #endif /* XML_DTD */ |
|---|
| 350 | n/a | |
|---|
| 351 | n/a | static enum XML_Error |
|---|
| 352 | n/a | storeAtts(XML_Parser parser, const ENCODING *, const char *s, |
|---|
| 353 | n/a | TAG_NAME *tagNamePtr, BINDING **bindingsPtr); |
|---|
| 354 | n/a | static enum XML_Error |
|---|
| 355 | n/a | addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, |
|---|
| 356 | n/a | const XML_Char *uri, BINDING **bindingsPtr); |
|---|
| 357 | n/a | static int |
|---|
| 358 | n/a | defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *, XML_Bool isCdata, |
|---|
| 359 | n/a | XML_Bool isId, const XML_Char *dfltValue, XML_Parser parser); |
|---|
| 360 | n/a | static enum XML_Error |
|---|
| 361 | n/a | storeAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, |
|---|
| 362 | n/a | const char *, const char *, STRING_POOL *); |
|---|
| 363 | n/a | static enum XML_Error |
|---|
| 364 | n/a | appendAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, |
|---|
| 365 | n/a | const char *, const char *, STRING_POOL *); |
|---|
| 366 | n/a | static ATTRIBUTE_ID * |
|---|
| 367 | n/a | getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start, |
|---|
| 368 | n/a | const char *end); |
|---|
| 369 | n/a | static int |
|---|
| 370 | n/a | setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *); |
|---|
| 371 | n/a | static enum XML_Error |
|---|
| 372 | n/a | storeEntityValue(XML_Parser parser, const ENCODING *enc, const char *start, |
|---|
| 373 | n/a | const char *end); |
|---|
| 374 | n/a | static int |
|---|
| 375 | n/a | reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, |
|---|
| 376 | n/a | const char *start, const char *end); |
|---|
| 377 | n/a | static int |
|---|
| 378 | n/a | reportComment(XML_Parser parser, const ENCODING *enc, const char *start, |
|---|
| 379 | n/a | const char *end); |
|---|
| 380 | n/a | static void |
|---|
| 381 | n/a | reportDefault(XML_Parser parser, const ENCODING *enc, const char *start, |
|---|
| 382 | n/a | const char *end); |
|---|
| 383 | n/a | |
|---|
| 384 | n/a | static const XML_Char * getContext(XML_Parser parser); |
|---|
| 385 | n/a | static XML_Bool |
|---|
| 386 | n/a | setContext(XML_Parser parser, const XML_Char *context); |
|---|
| 387 | n/a | |
|---|
| 388 | n/a | static void FASTCALL normalizePublicId(XML_Char *s); |
|---|
| 389 | n/a | |
|---|
| 390 | n/a | static DTD * dtdCreate(const XML_Memory_Handling_Suite *ms); |
|---|
| 391 | n/a | /* do not call if parentParser != NULL */ |
|---|
| 392 | n/a | static void dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms); |
|---|
| 393 | n/a | static void |
|---|
| 394 | n/a | dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms); |
|---|
| 395 | n/a | static int |
|---|
| 396 | n/a | dtdCopy(XML_Parser oldParser, |
|---|
| 397 | n/a | DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms); |
|---|
| 398 | n/a | static int |
|---|
| 399 | n/a | copyEntityTable(XML_Parser oldParser, |
|---|
| 400 | n/a | HASH_TABLE *, STRING_POOL *, const HASH_TABLE *); |
|---|
| 401 | n/a | static NAMED * |
|---|
| 402 | n/a | lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize); |
|---|
| 403 | n/a | static void FASTCALL |
|---|
| 404 | n/a | hashTableInit(HASH_TABLE *, const XML_Memory_Handling_Suite *ms); |
|---|
| 405 | n/a | static void FASTCALL hashTableClear(HASH_TABLE *); |
|---|
| 406 | n/a | static void FASTCALL hashTableDestroy(HASH_TABLE *); |
|---|
| 407 | n/a | static void FASTCALL |
|---|
| 408 | n/a | hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *); |
|---|
| 409 | n/a | static NAMED * FASTCALL hashTableIterNext(HASH_TABLE_ITER *); |
|---|
| 410 | n/a | |
|---|
| 411 | n/a | static void FASTCALL |
|---|
| 412 | n/a | poolInit(STRING_POOL *, const XML_Memory_Handling_Suite *ms); |
|---|
| 413 | n/a | static void FASTCALL poolClear(STRING_POOL *); |
|---|
| 414 | n/a | static void FASTCALL poolDestroy(STRING_POOL *); |
|---|
| 415 | n/a | static XML_Char * |
|---|
| 416 | n/a | poolAppend(STRING_POOL *pool, const ENCODING *enc, |
|---|
| 417 | n/a | const char *ptr, const char *end); |
|---|
| 418 | n/a | static XML_Char * |
|---|
| 419 | n/a | poolStoreString(STRING_POOL *pool, const ENCODING *enc, |
|---|
| 420 | n/a | const char *ptr, const char *end); |
|---|
| 421 | n/a | static XML_Bool FASTCALL poolGrow(STRING_POOL *pool); |
|---|
| 422 | n/a | static const XML_Char * FASTCALL |
|---|
| 423 | n/a | poolCopyString(STRING_POOL *pool, const XML_Char *s); |
|---|
| 424 | n/a | static const XML_Char * |
|---|
| 425 | n/a | poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n); |
|---|
| 426 | n/a | static const XML_Char * FASTCALL |
|---|
| 427 | n/a | poolAppendString(STRING_POOL *pool, const XML_Char *s); |
|---|
| 428 | n/a | |
|---|
| 429 | n/a | static int FASTCALL nextScaffoldPart(XML_Parser parser); |
|---|
| 430 | n/a | static XML_Content * build_model(XML_Parser parser); |
|---|
| 431 | n/a | static ELEMENT_TYPE * |
|---|
| 432 | n/a | getElementType(XML_Parser parser, const ENCODING *enc, |
|---|
| 433 | n/a | const char *ptr, const char *end); |
|---|
| 434 | n/a | |
|---|
| 435 | n/a | static unsigned long generate_hash_secret_salt(void); |
|---|
| 436 | n/a | static XML_Bool startParsing(XML_Parser parser); |
|---|
| 437 | n/a | |
|---|
| 438 | n/a | static XML_Parser |
|---|
| 439 | n/a | parserCreate(const XML_Char *encodingName, |
|---|
| 440 | n/a | const XML_Memory_Handling_Suite *memsuite, |
|---|
| 441 | n/a | const XML_Char *nameSep, |
|---|
| 442 | n/a | DTD *dtd); |
|---|
| 443 | n/a | |
|---|
| 444 | n/a | static void |
|---|
| 445 | n/a | parserInit(XML_Parser parser, const XML_Char *encodingName); |
|---|
| 446 | n/a | |
|---|
| 447 | n/a | #define poolStart(pool) ((pool)->start) |
|---|
| 448 | n/a | #define poolEnd(pool) ((pool)->ptr) |
|---|
| 449 | n/a | #define poolLength(pool) ((pool)->ptr - (pool)->start) |
|---|
| 450 | n/a | #define poolChop(pool) ((void)--(pool->ptr)) |
|---|
| 451 | n/a | #define poolLastChar(pool) (((pool)->ptr)[-1]) |
|---|
| 452 | n/a | #define poolDiscard(pool) ((pool)->ptr = (pool)->start) |
|---|
| 453 | n/a | #define poolFinish(pool) ((pool)->start = (pool)->ptr) |
|---|
| 454 | n/a | #define poolAppendChar(pool, c) \ |
|---|
| 455 | n/a | (((pool)->ptr == (pool)->end && !poolGrow(pool)) \ |
|---|
| 456 | n/a | ? 0 \ |
|---|
| 457 | n/a | : ((*((pool)->ptr)++ = c), 1)) |
|---|
| 458 | n/a | |
|---|
| 459 | n/a | struct XML_ParserStruct { |
|---|
| 460 | n/a | /* The first member must be userData so that the XML_GetUserData |
|---|
| 461 | n/a | macro works. */ |
|---|
| 462 | n/a | void *m_userData; |
|---|
| 463 | n/a | void *m_handlerArg; |
|---|
| 464 | n/a | char *m_buffer; |
|---|
| 465 | n/a | const XML_Memory_Handling_Suite m_mem; |
|---|
| 466 | n/a | /* first character to be parsed */ |
|---|
| 467 | n/a | const char *m_bufferPtr; |
|---|
| 468 | n/a | /* past last character to be parsed */ |
|---|
| 469 | n/a | char *m_bufferEnd; |
|---|
| 470 | n/a | /* allocated end of buffer */ |
|---|
| 471 | n/a | const char *m_bufferLim; |
|---|
| 472 | n/a | XML_Index m_parseEndByteIndex; |
|---|
| 473 | n/a | const char *m_parseEndPtr; |
|---|
| 474 | n/a | XML_Char *m_dataBuf; |
|---|
| 475 | n/a | XML_Char *m_dataBufEnd; |
|---|
| 476 | n/a | XML_StartElementHandler m_startElementHandler; |
|---|
| 477 | n/a | XML_EndElementHandler m_endElementHandler; |
|---|
| 478 | n/a | XML_CharacterDataHandler m_characterDataHandler; |
|---|
| 479 | n/a | XML_ProcessingInstructionHandler m_processingInstructionHandler; |
|---|
| 480 | n/a | XML_CommentHandler m_commentHandler; |
|---|
| 481 | n/a | XML_StartCdataSectionHandler m_startCdataSectionHandler; |
|---|
| 482 | n/a | XML_EndCdataSectionHandler m_endCdataSectionHandler; |
|---|
| 483 | n/a | XML_DefaultHandler m_defaultHandler; |
|---|
| 484 | n/a | XML_StartDoctypeDeclHandler m_startDoctypeDeclHandler; |
|---|
| 485 | n/a | XML_EndDoctypeDeclHandler m_endDoctypeDeclHandler; |
|---|
| 486 | n/a | XML_UnparsedEntityDeclHandler m_unparsedEntityDeclHandler; |
|---|
| 487 | n/a | XML_NotationDeclHandler m_notationDeclHandler; |
|---|
| 488 | n/a | XML_StartNamespaceDeclHandler m_startNamespaceDeclHandler; |
|---|
| 489 | n/a | XML_EndNamespaceDeclHandler m_endNamespaceDeclHandler; |
|---|
| 490 | n/a | XML_NotStandaloneHandler m_notStandaloneHandler; |
|---|
| 491 | n/a | XML_ExternalEntityRefHandler m_externalEntityRefHandler; |
|---|
| 492 | n/a | XML_Parser m_externalEntityRefHandlerArg; |
|---|
| 493 | n/a | XML_SkippedEntityHandler m_skippedEntityHandler; |
|---|
| 494 | n/a | XML_UnknownEncodingHandler m_unknownEncodingHandler; |
|---|
| 495 | n/a | XML_ElementDeclHandler m_elementDeclHandler; |
|---|
| 496 | n/a | XML_AttlistDeclHandler m_attlistDeclHandler; |
|---|
| 497 | n/a | XML_EntityDeclHandler m_entityDeclHandler; |
|---|
| 498 | n/a | XML_XmlDeclHandler m_xmlDeclHandler; |
|---|
| 499 | n/a | const ENCODING *m_encoding; |
|---|
| 500 | n/a | INIT_ENCODING m_initEncoding; |
|---|
| 501 | n/a | const ENCODING *m_internalEncoding; |
|---|
| 502 | n/a | const XML_Char *m_protocolEncodingName; |
|---|
| 503 | n/a | XML_Bool m_ns; |
|---|
| 504 | n/a | XML_Bool m_ns_triplets; |
|---|
| 505 | n/a | void *m_unknownEncodingMem; |
|---|
| 506 | n/a | void *m_unknownEncodingData; |
|---|
| 507 | n/a | void *m_unknownEncodingHandlerData; |
|---|
| 508 | n/a | void (XMLCALL *m_unknownEncodingRelease)(void *); |
|---|
| 509 | n/a | PROLOG_STATE m_prologState; |
|---|
| 510 | n/a | Processor *m_processor; |
|---|
| 511 | n/a | enum XML_Error m_errorCode; |
|---|
| 512 | n/a | const char *m_eventPtr; |
|---|
| 513 | n/a | const char *m_eventEndPtr; |
|---|
| 514 | n/a | const char *m_positionPtr; |
|---|
| 515 | n/a | OPEN_INTERNAL_ENTITY *m_openInternalEntities; |
|---|
| 516 | n/a | OPEN_INTERNAL_ENTITY *m_freeInternalEntities; |
|---|
| 517 | n/a | XML_Bool m_defaultExpandInternalEntities; |
|---|
| 518 | n/a | int m_tagLevel; |
|---|
| 519 | n/a | ENTITY *m_declEntity; |
|---|
| 520 | n/a | const XML_Char *m_doctypeName; |
|---|
| 521 | n/a | const XML_Char *m_doctypeSysid; |
|---|
| 522 | n/a | const XML_Char *m_doctypePubid; |
|---|
| 523 | n/a | const XML_Char *m_declAttributeType; |
|---|
| 524 | n/a | const XML_Char *m_declNotationName; |
|---|
| 525 | n/a | const XML_Char *m_declNotationPublicId; |
|---|
| 526 | n/a | ELEMENT_TYPE *m_declElementType; |
|---|
| 527 | n/a | ATTRIBUTE_ID *m_declAttributeId; |
|---|
| 528 | n/a | XML_Bool m_declAttributeIsCdata; |
|---|
| 529 | n/a | XML_Bool m_declAttributeIsId; |
|---|
| 530 | n/a | DTD *m_dtd; |
|---|
| 531 | n/a | const XML_Char *m_curBase; |
|---|
| 532 | n/a | TAG *m_tagStack; |
|---|
| 533 | n/a | TAG *m_freeTagList; |
|---|
| 534 | n/a | BINDING *m_inheritedBindings; |
|---|
| 535 | n/a | BINDING *m_freeBindingList; |
|---|
| 536 | n/a | int m_attsSize; |
|---|
| 537 | n/a | int m_nSpecifiedAtts; |
|---|
| 538 | n/a | int m_idAttIndex; |
|---|
| 539 | n/a | ATTRIBUTE *m_atts; |
|---|
| 540 | n/a | NS_ATT *m_nsAtts; |
|---|
| 541 | n/a | unsigned long m_nsAttsVersion; |
|---|
| 542 | n/a | unsigned char m_nsAttsPower; |
|---|
| 543 | n/a | #ifdef XML_ATTR_INFO |
|---|
| 544 | n/a | XML_AttrInfo *m_attInfo; |
|---|
| 545 | n/a | #endif |
|---|
| 546 | n/a | POSITION m_position; |
|---|
| 547 | n/a | STRING_POOL m_tempPool; |
|---|
| 548 | n/a | STRING_POOL m_temp2Pool; |
|---|
| 549 | n/a | char *m_groupConnector; |
|---|
| 550 | n/a | unsigned int m_groupSize; |
|---|
| 551 | n/a | XML_Char m_namespaceSeparator; |
|---|
| 552 | n/a | XML_Parser m_parentParser; |
|---|
| 553 | n/a | XML_ParsingStatus m_parsingStatus; |
|---|
| 554 | n/a | #ifdef XML_DTD |
|---|
| 555 | n/a | XML_Bool m_isParamEntity; |
|---|
| 556 | n/a | XML_Bool m_useForeignDTD; |
|---|
| 557 | n/a | enum XML_ParamEntityParsing m_paramEntityParsing; |
|---|
| 558 | n/a | #endif |
|---|
| 559 | n/a | unsigned long m_hash_secret_salt; |
|---|
| 560 | n/a | }; |
|---|
| 561 | n/a | |
|---|
| 562 | n/a | #define MALLOC(s) (parser->m_mem.malloc_fcn((s))) |
|---|
| 563 | n/a | #define REALLOC(p,s) (parser->m_mem.realloc_fcn((p),(s))) |
|---|
| 564 | n/a | #define FREE(p) (parser->m_mem.free_fcn((p))) |
|---|
| 565 | n/a | |
|---|
| 566 | n/a | #define userData (parser->m_userData) |
|---|
| 567 | n/a | #define handlerArg (parser->m_handlerArg) |
|---|
| 568 | n/a | #define startElementHandler (parser->m_startElementHandler) |
|---|
| 569 | n/a | #define endElementHandler (parser->m_endElementHandler) |
|---|
| 570 | n/a | #define characterDataHandler (parser->m_characterDataHandler) |
|---|
| 571 | n/a | #define processingInstructionHandler \ |
|---|
| 572 | n/a | (parser->m_processingInstructionHandler) |
|---|
| 573 | n/a | #define commentHandler (parser->m_commentHandler) |
|---|
| 574 | n/a | #define startCdataSectionHandler \ |
|---|
| 575 | n/a | (parser->m_startCdataSectionHandler) |
|---|
| 576 | n/a | #define endCdataSectionHandler (parser->m_endCdataSectionHandler) |
|---|
| 577 | n/a | #define defaultHandler (parser->m_defaultHandler) |
|---|
| 578 | n/a | #define startDoctypeDeclHandler (parser->m_startDoctypeDeclHandler) |
|---|
| 579 | n/a | #define endDoctypeDeclHandler (parser->m_endDoctypeDeclHandler) |
|---|
| 580 | n/a | #define unparsedEntityDeclHandler \ |
|---|
| 581 | n/a | (parser->m_unparsedEntityDeclHandler) |
|---|
| 582 | n/a | #define notationDeclHandler (parser->m_notationDeclHandler) |
|---|
| 583 | n/a | #define startNamespaceDeclHandler \ |
|---|
| 584 | n/a | (parser->m_startNamespaceDeclHandler) |
|---|
| 585 | n/a | #define endNamespaceDeclHandler (parser->m_endNamespaceDeclHandler) |
|---|
| 586 | n/a | #define notStandaloneHandler (parser->m_notStandaloneHandler) |
|---|
| 587 | n/a | #define externalEntityRefHandler \ |
|---|
| 588 | n/a | (parser->m_externalEntityRefHandler) |
|---|
| 589 | n/a | #define externalEntityRefHandlerArg \ |
|---|
| 590 | n/a | (parser->m_externalEntityRefHandlerArg) |
|---|
| 591 | n/a | #define internalEntityRefHandler \ |
|---|
| 592 | n/a | (parser->m_internalEntityRefHandler) |
|---|
| 593 | n/a | #define skippedEntityHandler (parser->m_skippedEntityHandler) |
|---|
| 594 | n/a | #define unknownEncodingHandler (parser->m_unknownEncodingHandler) |
|---|
| 595 | n/a | #define elementDeclHandler (parser->m_elementDeclHandler) |
|---|
| 596 | n/a | #define attlistDeclHandler (parser->m_attlistDeclHandler) |
|---|
| 597 | n/a | #define entityDeclHandler (parser->m_entityDeclHandler) |
|---|
| 598 | n/a | #define xmlDeclHandler (parser->m_xmlDeclHandler) |
|---|
| 599 | n/a | #define encoding (parser->m_encoding) |
|---|
| 600 | n/a | #define initEncoding (parser->m_initEncoding) |
|---|
| 601 | n/a | #define internalEncoding (parser->m_internalEncoding) |
|---|
| 602 | n/a | #define unknownEncodingMem (parser->m_unknownEncodingMem) |
|---|
| 603 | n/a | #define unknownEncodingData (parser->m_unknownEncodingData) |
|---|
| 604 | n/a | #define unknownEncodingHandlerData \ |
|---|
| 605 | n/a | (parser->m_unknownEncodingHandlerData) |
|---|
| 606 | n/a | #define unknownEncodingRelease (parser->m_unknownEncodingRelease) |
|---|
| 607 | n/a | #define protocolEncodingName (parser->m_protocolEncodingName) |
|---|
| 608 | n/a | #define ns (parser->m_ns) |
|---|
| 609 | n/a | #define ns_triplets (parser->m_ns_triplets) |
|---|
| 610 | n/a | #define prologState (parser->m_prologState) |
|---|
| 611 | n/a | #define processor (parser->m_processor) |
|---|
| 612 | n/a | #define errorCode (parser->m_errorCode) |
|---|
| 613 | n/a | #define eventPtr (parser->m_eventPtr) |
|---|
| 614 | n/a | #define eventEndPtr (parser->m_eventEndPtr) |
|---|
| 615 | n/a | #define positionPtr (parser->m_positionPtr) |
|---|
| 616 | n/a | #define position (parser->m_position) |
|---|
| 617 | n/a | #define openInternalEntities (parser->m_openInternalEntities) |
|---|
| 618 | n/a | #define freeInternalEntities (parser->m_freeInternalEntities) |
|---|
| 619 | n/a | #define defaultExpandInternalEntities \ |
|---|
| 620 | n/a | (parser->m_defaultExpandInternalEntities) |
|---|
| 621 | n/a | #define tagLevel (parser->m_tagLevel) |
|---|
| 622 | n/a | #define buffer (parser->m_buffer) |
|---|
| 623 | n/a | #define bufferPtr (parser->m_bufferPtr) |
|---|
| 624 | n/a | #define bufferEnd (parser->m_bufferEnd) |
|---|
| 625 | n/a | #define parseEndByteIndex (parser->m_parseEndByteIndex) |
|---|
| 626 | n/a | #define parseEndPtr (parser->m_parseEndPtr) |
|---|
| 627 | n/a | #define bufferLim (parser->m_bufferLim) |
|---|
| 628 | n/a | #define dataBuf (parser->m_dataBuf) |
|---|
| 629 | n/a | #define dataBufEnd (parser->m_dataBufEnd) |
|---|
| 630 | n/a | #define _dtd (parser->m_dtd) |
|---|
| 631 | n/a | #define curBase (parser->m_curBase) |
|---|
| 632 | n/a | #define declEntity (parser->m_declEntity) |
|---|
| 633 | n/a | #define doctypeName (parser->m_doctypeName) |
|---|
| 634 | n/a | #define doctypeSysid (parser->m_doctypeSysid) |
|---|
| 635 | n/a | #define doctypePubid (parser->m_doctypePubid) |
|---|
| 636 | n/a | #define declAttributeType (parser->m_declAttributeType) |
|---|
| 637 | n/a | #define declNotationName (parser->m_declNotationName) |
|---|
| 638 | n/a | #define declNotationPublicId (parser->m_declNotationPublicId) |
|---|
| 639 | n/a | #define declElementType (parser->m_declElementType) |
|---|
| 640 | n/a | #define declAttributeId (parser->m_declAttributeId) |
|---|
| 641 | n/a | #define declAttributeIsCdata (parser->m_declAttributeIsCdata) |
|---|
| 642 | n/a | #define declAttributeIsId (parser->m_declAttributeIsId) |
|---|
| 643 | n/a | #define freeTagList (parser->m_freeTagList) |
|---|
| 644 | n/a | #define freeBindingList (parser->m_freeBindingList) |
|---|
| 645 | n/a | #define inheritedBindings (parser->m_inheritedBindings) |
|---|
| 646 | n/a | #define tagStack (parser->m_tagStack) |
|---|
| 647 | n/a | #define atts (parser->m_atts) |
|---|
| 648 | n/a | #define attsSize (parser->m_attsSize) |
|---|
| 649 | n/a | #define nSpecifiedAtts (parser->m_nSpecifiedAtts) |
|---|
| 650 | n/a | #define idAttIndex (parser->m_idAttIndex) |
|---|
| 651 | n/a | #define nsAtts (parser->m_nsAtts) |
|---|
| 652 | n/a | #define nsAttsVersion (parser->m_nsAttsVersion) |
|---|
| 653 | n/a | #define nsAttsPower (parser->m_nsAttsPower) |
|---|
| 654 | n/a | #define attInfo (parser->m_attInfo) |
|---|
| 655 | n/a | #define tempPool (parser->m_tempPool) |
|---|
| 656 | n/a | #define temp2Pool (parser->m_temp2Pool) |
|---|
| 657 | n/a | #define groupConnector (parser->m_groupConnector) |
|---|
| 658 | n/a | #define groupSize (parser->m_groupSize) |
|---|
| 659 | n/a | #define namespaceSeparator (parser->m_namespaceSeparator) |
|---|
| 660 | n/a | #define parentParser (parser->m_parentParser) |
|---|
| 661 | n/a | #define ps_parsing (parser->m_parsingStatus.parsing) |
|---|
| 662 | n/a | #define ps_finalBuffer (parser->m_parsingStatus.finalBuffer) |
|---|
| 663 | n/a | #ifdef XML_DTD |
|---|
| 664 | n/a | #define isParamEntity (parser->m_isParamEntity) |
|---|
| 665 | n/a | #define useForeignDTD (parser->m_useForeignDTD) |
|---|
| 666 | n/a | #define paramEntityParsing (parser->m_paramEntityParsing) |
|---|
| 667 | n/a | #endif /* XML_DTD */ |
|---|
| 668 | n/a | #define hash_secret_salt (parser->m_hash_secret_salt) |
|---|
| 669 | n/a | |
|---|
| 670 | n/a | XML_Parser XMLCALL |
|---|
| 671 | n/a | XML_ParserCreate(const XML_Char *encodingName) |
|---|
| 672 | n/a | { |
|---|
| 673 | n/a | return XML_ParserCreate_MM(encodingName, NULL, NULL); |
|---|
| 674 | n/a | } |
|---|
| 675 | n/a | |
|---|
| 676 | n/a | XML_Parser XMLCALL |
|---|
| 677 | n/a | XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep) |
|---|
| 678 | n/a | { |
|---|
| 679 | n/a | XML_Char tmp[2]; |
|---|
| 680 | n/a | *tmp = nsSep; |
|---|
| 681 | n/a | return XML_ParserCreate_MM(encodingName, NULL, tmp); |
|---|
| 682 | n/a | } |
|---|
| 683 | n/a | |
|---|
| 684 | n/a | static const XML_Char implicitContext[] = { |
|---|
| 685 | n/a | ASCII_x, ASCII_m, ASCII_l, ASCII_EQUALS, ASCII_h, ASCII_t, ASCII_t, ASCII_p, |
|---|
| 686 | n/a | ASCII_COLON, ASCII_SLASH, ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w, |
|---|
| 687 | n/a | ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, ASCII_o, ASCII_r, ASCII_g, |
|---|
| 688 | n/a | ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, ASCII_SLASH, ASCII_1, ASCII_9, |
|---|
| 689 | n/a | ASCII_9, ASCII_8, ASCII_SLASH, ASCII_n, ASCII_a, ASCII_m, ASCII_e, |
|---|
| 690 | n/a | ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, '\0' |
|---|
| 691 | n/a | }; |
|---|
| 692 | n/a | |
|---|
| 693 | n/a | static unsigned long |
|---|
| 694 | n/a | generate_hash_secret_salt(void) |
|---|
| 695 | n/a | { |
|---|
| 696 | n/a | unsigned int seed = time(NULL) % UINT_MAX; |
|---|
| 697 | n/a | srand(seed); |
|---|
| 698 | n/a | return rand(); |
|---|
| 699 | n/a | } |
|---|
| 700 | n/a | |
|---|
| 701 | n/a | static XML_Bool /* only valid for root parser */ |
|---|
| 702 | n/a | startParsing(XML_Parser parser) |
|---|
| 703 | n/a | { |
|---|
| 704 | n/a | /* hash functions must be initialized before setContext() is called */ |
|---|
| 705 | n/a | if (hash_secret_salt == 0) |
|---|
| 706 | n/a | hash_secret_salt = generate_hash_secret_salt(); |
|---|
| 707 | n/a | if (ns) { |
|---|
| 708 | n/a | /* implicit context only set for root parser, since child |
|---|
| 709 | n/a | parsers (i.e. external entity parsers) will inherit it |
|---|
| 710 | n/a | */ |
|---|
| 711 | n/a | return setContext(parser, implicitContext); |
|---|
| 712 | n/a | } |
|---|
| 713 | n/a | return XML_TRUE; |
|---|
| 714 | n/a | } |
|---|
| 715 | n/a | |
|---|
| 716 | n/a | XML_Parser XMLCALL |
|---|
| 717 | n/a | XML_ParserCreate_MM(const XML_Char *encodingName, |
|---|
| 718 | n/a | const XML_Memory_Handling_Suite *memsuite, |
|---|
| 719 | n/a | const XML_Char *nameSep) |
|---|
| 720 | n/a | { |
|---|
| 721 | n/a | return parserCreate(encodingName, memsuite, nameSep, NULL); |
|---|
| 722 | n/a | } |
|---|
| 723 | n/a | |
|---|
| 724 | n/a | static XML_Parser |
|---|
| 725 | n/a | parserCreate(const XML_Char *encodingName, |
|---|
| 726 | n/a | const XML_Memory_Handling_Suite *memsuite, |
|---|
| 727 | n/a | const XML_Char *nameSep, |
|---|
| 728 | n/a | DTD *dtd) |
|---|
| 729 | n/a | { |
|---|
| 730 | n/a | XML_Parser parser; |
|---|
| 731 | n/a | |
|---|
| 732 | n/a | if (memsuite) { |
|---|
| 733 | n/a | XML_Memory_Handling_Suite *mtemp; |
|---|
| 734 | n/a | parser = (XML_Parser) |
|---|
| 735 | n/a | memsuite->malloc_fcn(sizeof(struct XML_ParserStruct)); |
|---|
| 736 | n/a | if (parser != NULL) { |
|---|
| 737 | n/a | mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); |
|---|
| 738 | n/a | mtemp->malloc_fcn = memsuite->malloc_fcn; |
|---|
| 739 | n/a | mtemp->realloc_fcn = memsuite->realloc_fcn; |
|---|
| 740 | n/a | mtemp->free_fcn = memsuite->free_fcn; |
|---|
| 741 | n/a | } |
|---|
| 742 | n/a | } |
|---|
| 743 | n/a | else { |
|---|
| 744 | n/a | XML_Memory_Handling_Suite *mtemp; |
|---|
| 745 | n/a | parser = (XML_Parser)malloc(sizeof(struct XML_ParserStruct)); |
|---|
| 746 | n/a | if (parser != NULL) { |
|---|
| 747 | n/a | mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); |
|---|
| 748 | n/a | mtemp->malloc_fcn = malloc; |
|---|
| 749 | n/a | mtemp->realloc_fcn = realloc; |
|---|
| 750 | n/a | mtemp->free_fcn = free; |
|---|
| 751 | n/a | } |
|---|
| 752 | n/a | } |
|---|
| 753 | n/a | |
|---|
| 754 | n/a | if (!parser) |
|---|
| 755 | n/a | return parser; |
|---|
| 756 | n/a | |
|---|
| 757 | n/a | buffer = NULL; |
|---|
| 758 | n/a | bufferLim = NULL; |
|---|
| 759 | n/a | |
|---|
| 760 | n/a | attsSize = INIT_ATTS_SIZE; |
|---|
| 761 | n/a | atts = (ATTRIBUTE *)MALLOC(attsSize * sizeof(ATTRIBUTE)); |
|---|
| 762 | n/a | if (atts == NULL) { |
|---|
| 763 | n/a | FREE(parser); |
|---|
| 764 | n/a | return NULL; |
|---|
| 765 | n/a | } |
|---|
| 766 | n/a | #ifdef XML_ATTR_INFO |
|---|
| 767 | n/a | attInfo = (XML_AttrInfo*)MALLOC(attsSize * sizeof(XML_AttrInfo)); |
|---|
| 768 | n/a | if (attInfo == NULL) { |
|---|
| 769 | n/a | FREE(atts); |
|---|
| 770 | n/a | FREE(parser); |
|---|
| 771 | n/a | return NULL; |
|---|
| 772 | n/a | } |
|---|
| 773 | n/a | #endif |
|---|
| 774 | n/a | dataBuf = (XML_Char *)MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char)); |
|---|
| 775 | n/a | if (dataBuf == NULL) { |
|---|
| 776 | n/a | FREE(atts); |
|---|
| 777 | n/a | #ifdef XML_ATTR_INFO |
|---|
| 778 | n/a | FREE(attInfo); |
|---|
| 779 | n/a | #endif |
|---|
| 780 | n/a | FREE(parser); |
|---|
| 781 | n/a | return NULL; |
|---|
| 782 | n/a | } |
|---|
| 783 | n/a | dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE; |
|---|
| 784 | n/a | |
|---|
| 785 | n/a | if (dtd) |
|---|
| 786 | n/a | _dtd = dtd; |
|---|
| 787 | n/a | else { |
|---|
| 788 | n/a | _dtd = dtdCreate(&parser->m_mem); |
|---|
| 789 | n/a | if (_dtd == NULL) { |
|---|
| 790 | n/a | FREE(dataBuf); |
|---|
| 791 | n/a | FREE(atts); |
|---|
| 792 | n/a | #ifdef XML_ATTR_INFO |
|---|
| 793 | n/a | FREE(attInfo); |
|---|
| 794 | n/a | #endif |
|---|
| 795 | n/a | FREE(parser); |
|---|
| 796 | n/a | return NULL; |
|---|
| 797 | n/a | } |
|---|
| 798 | n/a | } |
|---|
| 799 | n/a | |
|---|
| 800 | n/a | freeBindingList = NULL; |
|---|
| 801 | n/a | freeTagList = NULL; |
|---|
| 802 | n/a | freeInternalEntities = NULL; |
|---|
| 803 | n/a | |
|---|
| 804 | n/a | groupSize = 0; |
|---|
| 805 | n/a | groupConnector = NULL; |
|---|
| 806 | n/a | |
|---|
| 807 | n/a | unknownEncodingHandler = NULL; |
|---|
| 808 | n/a | unknownEncodingHandlerData = NULL; |
|---|
| 809 | n/a | |
|---|
| 810 | n/a | namespaceSeparator = ASCII_EXCL; |
|---|
| 811 | n/a | ns = XML_FALSE; |
|---|
| 812 | n/a | ns_triplets = XML_FALSE; |
|---|
| 813 | n/a | |
|---|
| 814 | n/a | nsAtts = NULL; |
|---|
| 815 | n/a | nsAttsVersion = 0; |
|---|
| 816 | n/a | nsAttsPower = 0; |
|---|
| 817 | n/a | |
|---|
| 818 | n/a | poolInit(&tempPool, &(parser->m_mem)); |
|---|
| 819 | n/a | poolInit(&temp2Pool, &(parser->m_mem)); |
|---|
| 820 | n/a | parserInit(parser, encodingName); |
|---|
| 821 | n/a | |
|---|
| 822 | n/a | if (encodingName && !protocolEncodingName) { |
|---|
| 823 | n/a | XML_ParserFree(parser); |
|---|
| 824 | n/a | return NULL; |
|---|
| 825 | n/a | } |
|---|
| 826 | n/a | |
|---|
| 827 | n/a | if (nameSep) { |
|---|
| 828 | n/a | ns = XML_TRUE; |
|---|
| 829 | n/a | internalEncoding = XmlGetInternalEncodingNS(); |
|---|
| 830 | n/a | namespaceSeparator = *nameSep; |
|---|
| 831 | n/a | } |
|---|
| 832 | n/a | else { |
|---|
| 833 | n/a | internalEncoding = XmlGetInternalEncoding(); |
|---|
| 834 | n/a | } |
|---|
| 835 | n/a | |
|---|
| 836 | n/a | return parser; |
|---|
| 837 | n/a | } |
|---|
| 838 | n/a | |
|---|
| 839 | n/a | static void |
|---|
| 840 | n/a | parserInit(XML_Parser parser, const XML_Char *encodingName) |
|---|
| 841 | n/a | { |
|---|
| 842 | n/a | processor = prologInitProcessor; |
|---|
| 843 | n/a | XmlPrologStateInit(&prologState); |
|---|
| 844 | n/a | protocolEncodingName = (encodingName != NULL |
|---|
| 845 | n/a | ? poolCopyString(&tempPool, encodingName) |
|---|
| 846 | n/a | : NULL); |
|---|
| 847 | n/a | curBase = NULL; |
|---|
| 848 | n/a | XmlInitEncoding(&initEncoding, &encoding, 0); |
|---|
| 849 | n/a | userData = NULL; |
|---|
| 850 | n/a | handlerArg = NULL; |
|---|
| 851 | n/a | startElementHandler = NULL; |
|---|
| 852 | n/a | endElementHandler = NULL; |
|---|
| 853 | n/a | characterDataHandler = NULL; |
|---|
| 854 | n/a | processingInstructionHandler = NULL; |
|---|
| 855 | n/a | commentHandler = NULL; |
|---|
| 856 | n/a | startCdataSectionHandler = NULL; |
|---|
| 857 | n/a | endCdataSectionHandler = NULL; |
|---|
| 858 | n/a | defaultHandler = NULL; |
|---|
| 859 | n/a | startDoctypeDeclHandler = NULL; |
|---|
| 860 | n/a | endDoctypeDeclHandler = NULL; |
|---|
| 861 | n/a | unparsedEntityDeclHandler = NULL; |
|---|
| 862 | n/a | notationDeclHandler = NULL; |
|---|
| 863 | n/a | startNamespaceDeclHandler = NULL; |
|---|
| 864 | n/a | endNamespaceDeclHandler = NULL; |
|---|
| 865 | n/a | notStandaloneHandler = NULL; |
|---|
| 866 | n/a | externalEntityRefHandler = NULL; |
|---|
| 867 | n/a | externalEntityRefHandlerArg = parser; |
|---|
| 868 | n/a | skippedEntityHandler = NULL; |
|---|
| 869 | n/a | elementDeclHandler = NULL; |
|---|
| 870 | n/a | attlistDeclHandler = NULL; |
|---|
| 871 | n/a | entityDeclHandler = NULL; |
|---|
| 872 | n/a | xmlDeclHandler = NULL; |
|---|
| 873 | n/a | bufferPtr = buffer; |
|---|
| 874 | n/a | bufferEnd = buffer; |
|---|
| 875 | n/a | parseEndByteIndex = 0; |
|---|
| 876 | n/a | parseEndPtr = NULL; |
|---|
| 877 | n/a | declElementType = NULL; |
|---|
| 878 | n/a | declAttributeId = NULL; |
|---|
| 879 | n/a | declEntity = NULL; |
|---|
| 880 | n/a | doctypeName = NULL; |
|---|
| 881 | n/a | doctypeSysid = NULL; |
|---|
| 882 | n/a | doctypePubid = NULL; |
|---|
| 883 | n/a | declAttributeType = NULL; |
|---|
| 884 | n/a | declNotationName = NULL; |
|---|
| 885 | n/a | declNotationPublicId = NULL; |
|---|
| 886 | n/a | declAttributeIsCdata = XML_FALSE; |
|---|
| 887 | n/a | declAttributeIsId = XML_FALSE; |
|---|
| 888 | n/a | memset(&position, 0, sizeof(POSITION)); |
|---|
| 889 | n/a | errorCode = XML_ERROR_NONE; |
|---|
| 890 | n/a | eventPtr = NULL; |
|---|
| 891 | n/a | eventEndPtr = NULL; |
|---|
| 892 | n/a | positionPtr = NULL; |
|---|
| 893 | n/a | openInternalEntities = NULL; |
|---|
| 894 | n/a | defaultExpandInternalEntities = XML_TRUE; |
|---|
| 895 | n/a | tagLevel = 0; |
|---|
| 896 | n/a | tagStack = NULL; |
|---|
| 897 | n/a | inheritedBindings = NULL; |
|---|
| 898 | n/a | nSpecifiedAtts = 0; |
|---|
| 899 | n/a | unknownEncodingMem = NULL; |
|---|
| 900 | n/a | unknownEncodingRelease = NULL; |
|---|
| 901 | n/a | unknownEncodingData = NULL; |
|---|
| 902 | n/a | parentParser = NULL; |
|---|
| 903 | n/a | ps_parsing = XML_INITIALIZED; |
|---|
| 904 | n/a | #ifdef XML_DTD |
|---|
| 905 | n/a | isParamEntity = XML_FALSE; |
|---|
| 906 | n/a | useForeignDTD = XML_FALSE; |
|---|
| 907 | n/a | paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; |
|---|
| 908 | n/a | #endif |
|---|
| 909 | n/a | hash_secret_salt = 0; |
|---|
| 910 | n/a | } |
|---|
| 911 | n/a | |
|---|
| 912 | n/a | /* moves list of bindings to freeBindingList */ |
|---|
| 913 | n/a | static void FASTCALL |
|---|
| 914 | n/a | moveToFreeBindingList(XML_Parser parser, BINDING *bindings) |
|---|
| 915 | n/a | { |
|---|
| 916 | n/a | while (bindings) { |
|---|
| 917 | n/a | BINDING *b = bindings; |
|---|
| 918 | n/a | bindings = bindings->nextTagBinding; |
|---|
| 919 | n/a | b->nextTagBinding = freeBindingList; |
|---|
| 920 | n/a | freeBindingList = b; |
|---|
| 921 | n/a | } |
|---|
| 922 | n/a | } |
|---|
| 923 | n/a | |
|---|
| 924 | n/a | XML_Bool XMLCALL |
|---|
| 925 | n/a | XML_ParserReset(XML_Parser parser, const XML_Char *encodingName) |
|---|
| 926 | n/a | { |
|---|
| 927 | n/a | TAG *tStk; |
|---|
| 928 | n/a | OPEN_INTERNAL_ENTITY *openEntityList; |
|---|
| 929 | n/a | if (parentParser) |
|---|
| 930 | n/a | return XML_FALSE; |
|---|
| 931 | n/a | /* move tagStack to freeTagList */ |
|---|
| 932 | n/a | tStk = tagStack; |
|---|
| 933 | n/a | while (tStk) { |
|---|
| 934 | n/a | TAG *tag = tStk; |
|---|
| 935 | n/a | tStk = tStk->parent; |
|---|
| 936 | n/a | tag->parent = freeTagList; |
|---|
| 937 | n/a | moveToFreeBindingList(parser, tag->bindings); |
|---|
| 938 | n/a | tag->bindings = NULL; |
|---|
| 939 | n/a | freeTagList = tag; |
|---|
| 940 | n/a | } |
|---|
| 941 | n/a | /* move openInternalEntities to freeInternalEntities */ |
|---|
| 942 | n/a | openEntityList = openInternalEntities; |
|---|
| 943 | n/a | while (openEntityList) { |
|---|
| 944 | n/a | OPEN_INTERNAL_ENTITY *openEntity = openEntityList; |
|---|
| 945 | n/a | openEntityList = openEntity->next; |
|---|
| 946 | n/a | openEntity->next = freeInternalEntities; |
|---|
| 947 | n/a | freeInternalEntities = openEntity; |
|---|
| 948 | n/a | } |
|---|
| 949 | n/a | moveToFreeBindingList(parser, inheritedBindings); |
|---|
| 950 | n/a | FREE(unknownEncodingMem); |
|---|
| 951 | n/a | if (unknownEncodingRelease) |
|---|
| 952 | n/a | unknownEncodingRelease(unknownEncodingData); |
|---|
| 953 | n/a | poolClear(&tempPool); |
|---|
| 954 | n/a | poolClear(&temp2Pool); |
|---|
| 955 | n/a | parserInit(parser, encodingName); |
|---|
| 956 | n/a | dtdReset(_dtd, &parser->m_mem); |
|---|
| 957 | n/a | return XML_TRUE; |
|---|
| 958 | n/a | } |
|---|
| 959 | n/a | |
|---|
| 960 | n/a | enum XML_Status XMLCALL |
|---|
| 961 | n/a | XML_SetEncoding(XML_Parser parser, const XML_Char *encodingName) |
|---|
| 962 | n/a | { |
|---|
| 963 | n/a | /* Block after XML_Parse()/XML_ParseBuffer() has been called. |
|---|
| 964 | n/a | XXX There's no way for the caller to determine which of the |
|---|
| 965 | n/a | XXX possible error cases caused the XML_STATUS_ERROR return. |
|---|
| 966 | n/a | */ |
|---|
| 967 | n/a | if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) |
|---|
| 968 | n/a | return XML_STATUS_ERROR; |
|---|
| 969 | n/a | if (encodingName == NULL) |
|---|
| 970 | n/a | protocolEncodingName = NULL; |
|---|
| 971 | n/a | else { |
|---|
| 972 | n/a | protocolEncodingName = poolCopyString(&tempPool, encodingName); |
|---|
| 973 | n/a | if (!protocolEncodingName) |
|---|
| 974 | n/a | return XML_STATUS_ERROR; |
|---|
| 975 | n/a | } |
|---|
| 976 | n/a | return XML_STATUS_OK; |
|---|
| 977 | n/a | } |
|---|
| 978 | n/a | |
|---|
| 979 | n/a | XML_Parser XMLCALL |
|---|
| 980 | n/a | XML_ExternalEntityParserCreate(XML_Parser oldParser, |
|---|
| 981 | n/a | const XML_Char *context, |
|---|
| 982 | n/a | const XML_Char *encodingName) |
|---|
| 983 | n/a | { |
|---|
| 984 | n/a | XML_Parser parser = oldParser; |
|---|
| 985 | n/a | DTD *newDtd = NULL; |
|---|
| 986 | n/a | DTD *oldDtd = _dtd; |
|---|
| 987 | n/a | XML_StartElementHandler oldStartElementHandler = startElementHandler; |
|---|
| 988 | n/a | XML_EndElementHandler oldEndElementHandler = endElementHandler; |
|---|
| 989 | n/a | XML_CharacterDataHandler oldCharacterDataHandler = characterDataHandler; |
|---|
| 990 | n/a | XML_ProcessingInstructionHandler oldProcessingInstructionHandler |
|---|
| 991 | n/a | = processingInstructionHandler; |
|---|
| 992 | n/a | XML_CommentHandler oldCommentHandler = commentHandler; |
|---|
| 993 | n/a | XML_StartCdataSectionHandler oldStartCdataSectionHandler |
|---|
| 994 | n/a | = startCdataSectionHandler; |
|---|
| 995 | n/a | XML_EndCdataSectionHandler oldEndCdataSectionHandler |
|---|
| 996 | n/a | = endCdataSectionHandler; |
|---|
| 997 | n/a | XML_DefaultHandler oldDefaultHandler = defaultHandler; |
|---|
| 998 | n/a | XML_UnparsedEntityDeclHandler oldUnparsedEntityDeclHandler |
|---|
| 999 | n/a | = unparsedEntityDeclHandler; |
|---|
| 1000 | n/a | XML_NotationDeclHandler oldNotationDeclHandler = notationDeclHandler; |
|---|
| 1001 | n/a | XML_StartNamespaceDeclHandler oldStartNamespaceDeclHandler |
|---|
| 1002 | n/a | = startNamespaceDeclHandler; |
|---|
| 1003 | n/a | XML_EndNamespaceDeclHandler oldEndNamespaceDeclHandler |
|---|
| 1004 | n/a | = endNamespaceDeclHandler; |
|---|
| 1005 | n/a | XML_NotStandaloneHandler oldNotStandaloneHandler = notStandaloneHandler; |
|---|
| 1006 | n/a | XML_ExternalEntityRefHandler oldExternalEntityRefHandler |
|---|
| 1007 | n/a | = externalEntityRefHandler; |
|---|
| 1008 | n/a | XML_SkippedEntityHandler oldSkippedEntityHandler = skippedEntityHandler; |
|---|
| 1009 | n/a | XML_UnknownEncodingHandler oldUnknownEncodingHandler |
|---|
| 1010 | n/a | = unknownEncodingHandler; |
|---|
| 1011 | n/a | XML_ElementDeclHandler oldElementDeclHandler = elementDeclHandler; |
|---|
| 1012 | n/a | XML_AttlistDeclHandler oldAttlistDeclHandler = attlistDeclHandler; |
|---|
| 1013 | n/a | XML_EntityDeclHandler oldEntityDeclHandler = entityDeclHandler; |
|---|
| 1014 | n/a | XML_XmlDeclHandler oldXmlDeclHandler = xmlDeclHandler; |
|---|
| 1015 | n/a | ELEMENT_TYPE * oldDeclElementType = declElementType; |
|---|
| 1016 | n/a | |
|---|
| 1017 | n/a | void *oldUserData = userData; |
|---|
| 1018 | n/a | void *oldHandlerArg = handlerArg; |
|---|
| 1019 | n/a | XML_Bool oldDefaultExpandInternalEntities = defaultExpandInternalEntities; |
|---|
| 1020 | n/a | XML_Parser oldExternalEntityRefHandlerArg = externalEntityRefHandlerArg; |
|---|
| 1021 | n/a | #ifdef XML_DTD |
|---|
| 1022 | n/a | enum XML_ParamEntityParsing oldParamEntityParsing = paramEntityParsing; |
|---|
| 1023 | n/a | int oldInEntityValue = prologState.inEntityValue; |
|---|
| 1024 | n/a | #endif |
|---|
| 1025 | n/a | XML_Bool oldns_triplets = ns_triplets; |
|---|
| 1026 | n/a | /* Note that the new parser shares the same hash secret as the old |
|---|
| 1027 | n/a | parser, so that dtdCopy and copyEntityTable can lookup values |
|---|
| 1028 | n/a | from hash tables associated with either parser without us having |
|---|
| 1029 | n/a | to worry which hash secrets each table has. |
|---|
| 1030 | n/a | */ |
|---|
| 1031 | n/a | unsigned long oldhash_secret_salt = hash_secret_salt; |
|---|
| 1032 | n/a | |
|---|
| 1033 | n/a | #ifdef XML_DTD |
|---|
| 1034 | n/a | if (!context) |
|---|
| 1035 | n/a | newDtd = oldDtd; |
|---|
| 1036 | n/a | #endif /* XML_DTD */ |
|---|
| 1037 | n/a | |
|---|
| 1038 | n/a | /* Note that the magical uses of the pre-processor to make field |
|---|
| 1039 | n/a | access look more like C++ require that `parser' be overwritten |
|---|
| 1040 | n/a | here. This makes this function more painful to follow than it |
|---|
| 1041 | n/a | would be otherwise. |
|---|
| 1042 | n/a | */ |
|---|
| 1043 | n/a | if (ns) { |
|---|
| 1044 | n/a | XML_Char tmp[2]; |
|---|
| 1045 | n/a | *tmp = namespaceSeparator; |
|---|
| 1046 | n/a | parser = parserCreate(encodingName, &parser->m_mem, tmp, newDtd); |
|---|
| 1047 | n/a | } |
|---|
| 1048 | n/a | else { |
|---|
| 1049 | n/a | parser = parserCreate(encodingName, &parser->m_mem, NULL, newDtd); |
|---|
| 1050 | n/a | } |
|---|
| 1051 | n/a | |
|---|
| 1052 | n/a | if (!parser) |
|---|
| 1053 | n/a | return NULL; |
|---|
| 1054 | n/a | |
|---|
| 1055 | n/a | startElementHandler = oldStartElementHandler; |
|---|
| 1056 | n/a | endElementHandler = oldEndElementHandler; |
|---|
| 1057 | n/a | characterDataHandler = oldCharacterDataHandler; |
|---|
| 1058 | n/a | processingInstructionHandler = oldProcessingInstructionHandler; |
|---|
| 1059 | n/a | commentHandler = oldCommentHandler; |
|---|
| 1060 | n/a | startCdataSectionHandler = oldStartCdataSectionHandler; |
|---|
| 1061 | n/a | endCdataSectionHandler = oldEndCdataSectionHandler; |
|---|
| 1062 | n/a | defaultHandler = oldDefaultHandler; |
|---|
| 1063 | n/a | unparsedEntityDeclHandler = oldUnparsedEntityDeclHandler; |
|---|
| 1064 | n/a | notationDeclHandler = oldNotationDeclHandler; |
|---|
| 1065 | n/a | startNamespaceDeclHandler = oldStartNamespaceDeclHandler; |
|---|
| 1066 | n/a | endNamespaceDeclHandler = oldEndNamespaceDeclHandler; |
|---|
| 1067 | n/a | notStandaloneHandler = oldNotStandaloneHandler; |
|---|
| 1068 | n/a | externalEntityRefHandler = oldExternalEntityRefHandler; |
|---|
| 1069 | n/a | skippedEntityHandler = oldSkippedEntityHandler; |
|---|
| 1070 | n/a | unknownEncodingHandler = oldUnknownEncodingHandler; |
|---|
| 1071 | n/a | elementDeclHandler = oldElementDeclHandler; |
|---|
| 1072 | n/a | attlistDeclHandler = oldAttlistDeclHandler; |
|---|
| 1073 | n/a | entityDeclHandler = oldEntityDeclHandler; |
|---|
| 1074 | n/a | xmlDeclHandler = oldXmlDeclHandler; |
|---|
| 1075 | n/a | declElementType = oldDeclElementType; |
|---|
| 1076 | n/a | userData = oldUserData; |
|---|
| 1077 | n/a | if (oldUserData == oldHandlerArg) |
|---|
| 1078 | n/a | handlerArg = userData; |
|---|
| 1079 | n/a | else |
|---|
| 1080 | n/a | handlerArg = parser; |
|---|
| 1081 | n/a | if (oldExternalEntityRefHandlerArg != oldParser) |
|---|
| 1082 | n/a | externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg; |
|---|
| 1083 | n/a | defaultExpandInternalEntities = oldDefaultExpandInternalEntities; |
|---|
| 1084 | n/a | ns_triplets = oldns_triplets; |
|---|
| 1085 | n/a | hash_secret_salt = oldhash_secret_salt; |
|---|
| 1086 | n/a | parentParser = oldParser; |
|---|
| 1087 | n/a | #ifdef XML_DTD |
|---|
| 1088 | n/a | paramEntityParsing = oldParamEntityParsing; |
|---|
| 1089 | n/a | prologState.inEntityValue = oldInEntityValue; |
|---|
| 1090 | n/a | if (context) { |
|---|
| 1091 | n/a | #endif /* XML_DTD */ |
|---|
| 1092 | n/a | if (!dtdCopy(oldParser, _dtd, oldDtd, &parser->m_mem) |
|---|
| 1093 | n/a | || !setContext(parser, context)) { |
|---|
| 1094 | n/a | XML_ParserFree(parser); |
|---|
| 1095 | n/a | return NULL; |
|---|
| 1096 | n/a | } |
|---|
| 1097 | n/a | processor = externalEntityInitProcessor; |
|---|
| 1098 | n/a | #ifdef XML_DTD |
|---|
| 1099 | n/a | } |
|---|
| 1100 | n/a | else { |
|---|
| 1101 | n/a | /* The DTD instance referenced by _dtd is shared between the document's |
|---|
| 1102 | n/a | root parser and external PE parsers, therefore one does not need to |
|---|
| 1103 | n/a | call setContext. In addition, one also *must* not call setContext, |
|---|
| 1104 | n/a | because this would overwrite existing prefix->binding pointers in |
|---|
| 1105 | n/a | _dtd with ones that get destroyed with the external PE parser. |
|---|
| 1106 | n/a | This would leave those prefixes with dangling pointers. |
|---|
| 1107 | n/a | */ |
|---|
| 1108 | n/a | isParamEntity = XML_TRUE; |
|---|
| 1109 | n/a | XmlPrologStateInitExternalEntity(&prologState); |
|---|
| 1110 | n/a | processor = externalParEntInitProcessor; |
|---|
| 1111 | n/a | } |
|---|
| 1112 | n/a | #endif /* XML_DTD */ |
|---|
| 1113 | n/a | return parser; |
|---|
| 1114 | n/a | } |
|---|
| 1115 | n/a | |
|---|
| 1116 | n/a | static void FASTCALL |
|---|
| 1117 | n/a | destroyBindings(BINDING *bindings, XML_Parser parser) |
|---|
| 1118 | n/a | { |
|---|
| 1119 | n/a | for (;;) { |
|---|
| 1120 | n/a | BINDING *b = bindings; |
|---|
| 1121 | n/a | if (!b) |
|---|
| 1122 | n/a | break; |
|---|
| 1123 | n/a | bindings = b->nextTagBinding; |
|---|
| 1124 | n/a | FREE(b->uri); |
|---|
| 1125 | n/a | FREE(b); |
|---|
| 1126 | n/a | } |
|---|
| 1127 | n/a | } |
|---|
| 1128 | n/a | |
|---|
| 1129 | n/a | void XMLCALL |
|---|
| 1130 | n/a | XML_ParserFree(XML_Parser parser) |
|---|
| 1131 | n/a | { |
|---|
| 1132 | n/a | TAG *tagList; |
|---|
| 1133 | n/a | OPEN_INTERNAL_ENTITY *entityList; |
|---|
| 1134 | n/a | if (parser == NULL) |
|---|
| 1135 | n/a | return; |
|---|
| 1136 | n/a | /* free tagStack and freeTagList */ |
|---|
| 1137 | n/a | tagList = tagStack; |
|---|
| 1138 | n/a | for (;;) { |
|---|
| 1139 | n/a | TAG *p; |
|---|
| 1140 | n/a | if (tagList == NULL) { |
|---|
| 1141 | n/a | if (freeTagList == NULL) |
|---|
| 1142 | n/a | break; |
|---|
| 1143 | n/a | tagList = freeTagList; |
|---|
| 1144 | n/a | freeTagList = NULL; |
|---|
| 1145 | n/a | } |
|---|
| 1146 | n/a | p = tagList; |
|---|
| 1147 | n/a | tagList = tagList->parent; |
|---|
| 1148 | n/a | FREE(p->buf); |
|---|
| 1149 | n/a | destroyBindings(p->bindings, parser); |
|---|
| 1150 | n/a | FREE(p); |
|---|
| 1151 | n/a | } |
|---|
| 1152 | n/a | /* free openInternalEntities and freeInternalEntities */ |
|---|
| 1153 | n/a | entityList = openInternalEntities; |
|---|
| 1154 | n/a | for (;;) { |
|---|
| 1155 | n/a | OPEN_INTERNAL_ENTITY *openEntity; |
|---|
| 1156 | n/a | if (entityList == NULL) { |
|---|
| 1157 | n/a | if (freeInternalEntities == NULL) |
|---|
| 1158 | n/a | break; |
|---|
| 1159 | n/a | entityList = freeInternalEntities; |
|---|
| 1160 | n/a | freeInternalEntities = NULL; |
|---|
| 1161 | n/a | } |
|---|
| 1162 | n/a | openEntity = entityList; |
|---|
| 1163 | n/a | entityList = entityList->next; |
|---|
| 1164 | n/a | FREE(openEntity); |
|---|
| 1165 | n/a | } |
|---|
| 1166 | n/a | |
|---|
| 1167 | n/a | destroyBindings(freeBindingList, parser); |
|---|
| 1168 | n/a | destroyBindings(inheritedBindings, parser); |
|---|
| 1169 | n/a | poolDestroy(&tempPool); |
|---|
| 1170 | n/a | poolDestroy(&temp2Pool); |
|---|
| 1171 | n/a | #ifdef XML_DTD |
|---|
| 1172 | n/a | /* external parameter entity parsers share the DTD structure |
|---|
| 1173 | n/a | parser->m_dtd with the root parser, so we must not destroy it |
|---|
| 1174 | n/a | */ |
|---|
| 1175 | n/a | if (!isParamEntity && _dtd) |
|---|
| 1176 | n/a | #else |
|---|
| 1177 | n/a | if (_dtd) |
|---|
| 1178 | n/a | #endif /* XML_DTD */ |
|---|
| 1179 | n/a | dtdDestroy(_dtd, (XML_Bool)!parentParser, &parser->m_mem); |
|---|
| 1180 | n/a | FREE((void *)atts); |
|---|
| 1181 | n/a | #ifdef XML_ATTR_INFO |
|---|
| 1182 | n/a | FREE((void *)attInfo); |
|---|
| 1183 | n/a | #endif |
|---|
| 1184 | n/a | FREE(groupConnector); |
|---|
| 1185 | n/a | FREE(buffer); |
|---|
| 1186 | n/a | FREE(dataBuf); |
|---|
| 1187 | n/a | FREE(nsAtts); |
|---|
| 1188 | n/a | FREE(unknownEncodingMem); |
|---|
| 1189 | n/a | if (unknownEncodingRelease) |
|---|
| 1190 | n/a | unknownEncodingRelease(unknownEncodingData); |
|---|
| 1191 | n/a | FREE(parser); |
|---|
| 1192 | n/a | } |
|---|
| 1193 | n/a | |
|---|
| 1194 | n/a | void XMLCALL |
|---|
| 1195 | n/a | XML_UseParserAsHandlerArg(XML_Parser parser) |
|---|
| 1196 | n/a | { |
|---|
| 1197 | n/a | handlerArg = parser; |
|---|
| 1198 | n/a | } |
|---|
| 1199 | n/a | |
|---|
| 1200 | n/a | enum XML_Error XMLCALL |
|---|
| 1201 | n/a | XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD) |
|---|
| 1202 | n/a | { |
|---|
| 1203 | n/a | #ifdef XML_DTD |
|---|
| 1204 | n/a | /* block after XML_Parse()/XML_ParseBuffer() has been called */ |
|---|
| 1205 | n/a | if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) |
|---|
| 1206 | n/a | return XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING; |
|---|
| 1207 | n/a | useForeignDTD = useDTD; |
|---|
| 1208 | n/a | return XML_ERROR_NONE; |
|---|
| 1209 | n/a | #else |
|---|
| 1210 | n/a | return XML_ERROR_FEATURE_REQUIRES_XML_DTD; |
|---|
| 1211 | n/a | #endif |
|---|
| 1212 | n/a | } |
|---|
| 1213 | n/a | |
|---|
| 1214 | n/a | void XMLCALL |
|---|
| 1215 | n/a | XML_SetReturnNSTriplet(XML_Parser parser, int do_nst) |
|---|
| 1216 | n/a | { |
|---|
| 1217 | n/a | /* block after XML_Parse()/XML_ParseBuffer() has been called */ |
|---|
| 1218 | n/a | if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) |
|---|
| 1219 | n/a | return; |
|---|
| 1220 | n/a | ns_triplets = do_nst ? XML_TRUE : XML_FALSE; |
|---|
| 1221 | n/a | } |
|---|
| 1222 | n/a | |
|---|
| 1223 | n/a | void XMLCALL |
|---|
| 1224 | n/a | XML_SetUserData(XML_Parser parser, void *p) |
|---|
| 1225 | n/a | { |
|---|
| 1226 | n/a | if (handlerArg == userData) |
|---|
| 1227 | n/a | handlerArg = userData = p; |
|---|
| 1228 | n/a | else |
|---|
| 1229 | n/a | userData = p; |
|---|
| 1230 | n/a | } |
|---|
| 1231 | n/a | |
|---|
| 1232 | n/a | enum XML_Status XMLCALL |
|---|
| 1233 | n/a | XML_SetBase(XML_Parser parser, const XML_Char *p) |
|---|
| 1234 | n/a | { |
|---|
| 1235 | n/a | if (p) { |
|---|
| 1236 | n/a | p = poolCopyString(&_dtd->pool, p); |
|---|
| 1237 | n/a | if (!p) |
|---|
| 1238 | n/a | return XML_STATUS_ERROR; |
|---|
| 1239 | n/a | curBase = p; |
|---|
| 1240 | n/a | } |
|---|
| 1241 | n/a | else |
|---|
| 1242 | n/a | curBase = NULL; |
|---|
| 1243 | n/a | return XML_STATUS_OK; |
|---|
| 1244 | n/a | } |
|---|
| 1245 | n/a | |
|---|
| 1246 | n/a | const XML_Char * XMLCALL |
|---|
| 1247 | n/a | XML_GetBase(XML_Parser parser) |
|---|
| 1248 | n/a | { |
|---|
| 1249 | n/a | return curBase; |
|---|
| 1250 | n/a | } |
|---|
| 1251 | n/a | |
|---|
| 1252 | n/a | int XMLCALL |
|---|
| 1253 | n/a | XML_GetSpecifiedAttributeCount(XML_Parser parser) |
|---|
| 1254 | n/a | { |
|---|
| 1255 | n/a | return nSpecifiedAtts; |
|---|
| 1256 | n/a | } |
|---|
| 1257 | n/a | |
|---|
| 1258 | n/a | int XMLCALL |
|---|
| 1259 | n/a | XML_GetIdAttributeIndex(XML_Parser parser) |
|---|
| 1260 | n/a | { |
|---|
| 1261 | n/a | return idAttIndex; |
|---|
| 1262 | n/a | } |
|---|
| 1263 | n/a | |
|---|
| 1264 | n/a | #ifdef XML_ATTR_INFO |
|---|
| 1265 | n/a | const XML_AttrInfo * XMLCALL |
|---|
| 1266 | n/a | XML_GetAttributeInfo(XML_Parser parser) |
|---|
| 1267 | n/a | { |
|---|
| 1268 | n/a | return attInfo; |
|---|
| 1269 | n/a | } |
|---|
| 1270 | n/a | #endif |
|---|
| 1271 | n/a | |
|---|
| 1272 | n/a | void XMLCALL |
|---|
| 1273 | n/a | XML_SetElementHandler(XML_Parser parser, |
|---|
| 1274 | n/a | XML_StartElementHandler start, |
|---|
| 1275 | n/a | XML_EndElementHandler end) |
|---|
| 1276 | n/a | { |
|---|
| 1277 | n/a | startElementHandler = start; |
|---|
| 1278 | n/a | endElementHandler = end; |
|---|
| 1279 | n/a | } |
|---|
| 1280 | n/a | |
|---|
| 1281 | n/a | void XMLCALL |
|---|
| 1282 | n/a | XML_SetStartElementHandler(XML_Parser parser, |
|---|
| 1283 | n/a | XML_StartElementHandler start) { |
|---|
| 1284 | n/a | startElementHandler = start; |
|---|
| 1285 | n/a | } |
|---|
| 1286 | n/a | |
|---|
| 1287 | n/a | void XMLCALL |
|---|
| 1288 | n/a | XML_SetEndElementHandler(XML_Parser parser, |
|---|
| 1289 | n/a | XML_EndElementHandler end) { |
|---|
| 1290 | n/a | endElementHandler = end; |
|---|
| 1291 | n/a | } |
|---|
| 1292 | n/a | |
|---|
| 1293 | n/a | void XMLCALL |
|---|
| 1294 | n/a | XML_SetCharacterDataHandler(XML_Parser parser, |
|---|
| 1295 | n/a | XML_CharacterDataHandler handler) |
|---|
| 1296 | n/a | { |
|---|
| 1297 | n/a | characterDataHandler = handler; |
|---|
| 1298 | n/a | } |
|---|
| 1299 | n/a | |
|---|
| 1300 | n/a | void XMLCALL |
|---|
| 1301 | n/a | XML_SetProcessingInstructionHandler(XML_Parser parser, |
|---|
| 1302 | n/a | XML_ProcessingInstructionHandler handler) |
|---|
| 1303 | n/a | { |
|---|
| 1304 | n/a | processingInstructionHandler = handler; |
|---|
| 1305 | n/a | } |
|---|
| 1306 | n/a | |
|---|
| 1307 | n/a | void XMLCALL |
|---|
| 1308 | n/a | XML_SetCommentHandler(XML_Parser parser, |
|---|
| 1309 | n/a | XML_CommentHandler handler) |
|---|
| 1310 | n/a | { |
|---|
| 1311 | n/a | commentHandler = handler; |
|---|
| 1312 | n/a | } |
|---|
| 1313 | n/a | |
|---|
| 1314 | n/a | void XMLCALL |
|---|
| 1315 | n/a | XML_SetCdataSectionHandler(XML_Parser parser, |
|---|
| 1316 | n/a | XML_StartCdataSectionHandler start, |
|---|
| 1317 | n/a | XML_EndCdataSectionHandler end) |
|---|
| 1318 | n/a | { |
|---|
| 1319 | n/a | startCdataSectionHandler = start; |
|---|
| 1320 | n/a | endCdataSectionHandler = end; |
|---|
| 1321 | n/a | } |
|---|
| 1322 | n/a | |
|---|
| 1323 | n/a | void XMLCALL |
|---|
| 1324 | n/a | XML_SetStartCdataSectionHandler(XML_Parser parser, |
|---|
| 1325 | n/a | XML_StartCdataSectionHandler start) { |
|---|
| 1326 | n/a | startCdataSectionHandler = start; |
|---|
| 1327 | n/a | } |
|---|
| 1328 | n/a | |
|---|
| 1329 | n/a | void XMLCALL |
|---|
| 1330 | n/a | XML_SetEndCdataSectionHandler(XML_Parser parser, |
|---|
| 1331 | n/a | XML_EndCdataSectionHandler end) { |
|---|
| 1332 | n/a | endCdataSectionHandler = end; |
|---|
| 1333 | n/a | } |
|---|
| 1334 | n/a | |
|---|
| 1335 | n/a | void XMLCALL |
|---|
| 1336 | n/a | XML_SetDefaultHandler(XML_Parser parser, |
|---|
| 1337 | n/a | XML_DefaultHandler handler) |
|---|
| 1338 | n/a | { |
|---|
| 1339 | n/a | defaultHandler = handler; |
|---|
| 1340 | n/a | defaultExpandInternalEntities = XML_FALSE; |
|---|
| 1341 | n/a | } |
|---|
| 1342 | n/a | |
|---|
| 1343 | n/a | void XMLCALL |
|---|
| 1344 | n/a | XML_SetDefaultHandlerExpand(XML_Parser parser, |
|---|
| 1345 | n/a | XML_DefaultHandler handler) |
|---|
| 1346 | n/a | { |
|---|
| 1347 | n/a | defaultHandler = handler; |
|---|
| 1348 | n/a | defaultExpandInternalEntities = XML_TRUE; |
|---|
| 1349 | n/a | } |
|---|
| 1350 | n/a | |
|---|
| 1351 | n/a | void XMLCALL |
|---|
| 1352 | n/a | XML_SetDoctypeDeclHandler(XML_Parser parser, |
|---|
| 1353 | n/a | XML_StartDoctypeDeclHandler start, |
|---|
| 1354 | n/a | XML_EndDoctypeDeclHandler end) |
|---|
| 1355 | n/a | { |
|---|
| 1356 | n/a | startDoctypeDeclHandler = start; |
|---|
| 1357 | n/a | endDoctypeDeclHandler = end; |
|---|
| 1358 | n/a | } |
|---|
| 1359 | n/a | |
|---|
| 1360 | n/a | void XMLCALL |
|---|
| 1361 | n/a | XML_SetStartDoctypeDeclHandler(XML_Parser parser, |
|---|
| 1362 | n/a | XML_StartDoctypeDeclHandler start) { |
|---|
| 1363 | n/a | startDoctypeDeclHandler = start; |
|---|
| 1364 | n/a | } |
|---|
| 1365 | n/a | |
|---|
| 1366 | n/a | void XMLCALL |
|---|
| 1367 | n/a | XML_SetEndDoctypeDeclHandler(XML_Parser parser, |
|---|
| 1368 | n/a | XML_EndDoctypeDeclHandler end) { |
|---|
| 1369 | n/a | endDoctypeDeclHandler = end; |
|---|
| 1370 | n/a | } |
|---|
| 1371 | n/a | |
|---|
| 1372 | n/a | void XMLCALL |
|---|
| 1373 | n/a | XML_SetUnparsedEntityDeclHandler(XML_Parser parser, |
|---|
| 1374 | n/a | XML_UnparsedEntityDeclHandler handler) |
|---|
| 1375 | n/a | { |
|---|
| 1376 | n/a | unparsedEntityDeclHandler = handler; |
|---|
| 1377 | n/a | } |
|---|
| 1378 | n/a | |
|---|
| 1379 | n/a | void XMLCALL |
|---|
| 1380 | n/a | XML_SetNotationDeclHandler(XML_Parser parser, |
|---|
| 1381 | n/a | XML_NotationDeclHandler handler) |
|---|
| 1382 | n/a | { |
|---|
| 1383 | n/a | notationDeclHandler = handler; |
|---|
| 1384 | n/a | } |
|---|
| 1385 | n/a | |
|---|
| 1386 | n/a | void XMLCALL |
|---|
| 1387 | n/a | XML_SetNamespaceDeclHandler(XML_Parser parser, |
|---|
| 1388 | n/a | XML_StartNamespaceDeclHandler start, |
|---|
| 1389 | n/a | XML_EndNamespaceDeclHandler end) |
|---|
| 1390 | n/a | { |
|---|
| 1391 | n/a | startNamespaceDeclHandler = start; |
|---|
| 1392 | n/a | endNamespaceDeclHandler = end; |
|---|
| 1393 | n/a | } |
|---|
| 1394 | n/a | |
|---|
| 1395 | n/a | void XMLCALL |
|---|
| 1396 | n/a | XML_SetStartNamespaceDeclHandler(XML_Parser parser, |
|---|
| 1397 | n/a | XML_StartNamespaceDeclHandler start) { |
|---|
| 1398 | n/a | startNamespaceDeclHandler = start; |
|---|
| 1399 | n/a | } |
|---|
| 1400 | n/a | |
|---|
| 1401 | n/a | void XMLCALL |
|---|
| 1402 | n/a | XML_SetEndNamespaceDeclHandler(XML_Parser parser, |
|---|
| 1403 | n/a | XML_EndNamespaceDeclHandler end) { |
|---|
| 1404 | n/a | endNamespaceDeclHandler = end; |
|---|
| 1405 | n/a | } |
|---|
| 1406 | n/a | |
|---|
| 1407 | n/a | void XMLCALL |
|---|
| 1408 | n/a | XML_SetNotStandaloneHandler(XML_Parser parser, |
|---|
| 1409 | n/a | XML_NotStandaloneHandler handler) |
|---|
| 1410 | n/a | { |
|---|
| 1411 | n/a | notStandaloneHandler = handler; |
|---|
| 1412 | n/a | } |
|---|
| 1413 | n/a | |
|---|
| 1414 | n/a | void XMLCALL |
|---|
| 1415 | n/a | XML_SetExternalEntityRefHandler(XML_Parser parser, |
|---|
| 1416 | n/a | XML_ExternalEntityRefHandler handler) |
|---|
| 1417 | n/a | { |
|---|
| 1418 | n/a | externalEntityRefHandler = handler; |
|---|
| 1419 | n/a | } |
|---|
| 1420 | n/a | |
|---|
| 1421 | n/a | void XMLCALL |
|---|
| 1422 | n/a | XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg) |
|---|
| 1423 | n/a | { |
|---|
| 1424 | n/a | if (arg) |
|---|
| 1425 | n/a | externalEntityRefHandlerArg = (XML_Parser)arg; |
|---|
| 1426 | n/a | else |
|---|
| 1427 | n/a | externalEntityRefHandlerArg = parser; |
|---|
| 1428 | n/a | } |
|---|
| 1429 | n/a | |
|---|
| 1430 | n/a | void XMLCALL |
|---|
| 1431 | n/a | XML_SetSkippedEntityHandler(XML_Parser parser, |
|---|
| 1432 | n/a | XML_SkippedEntityHandler handler) |
|---|
| 1433 | n/a | { |
|---|
| 1434 | n/a | skippedEntityHandler = handler; |
|---|
| 1435 | n/a | } |
|---|
| 1436 | n/a | |
|---|
| 1437 | n/a | void XMLCALL |
|---|
| 1438 | n/a | XML_SetUnknownEncodingHandler(XML_Parser parser, |
|---|
| 1439 | n/a | XML_UnknownEncodingHandler handler, |
|---|
| 1440 | n/a | void *data) |
|---|
| 1441 | n/a | { |
|---|
| 1442 | n/a | unknownEncodingHandler = handler; |
|---|
| 1443 | n/a | unknownEncodingHandlerData = data; |
|---|
| 1444 | n/a | } |
|---|
| 1445 | n/a | |
|---|
| 1446 | n/a | void XMLCALL |
|---|
| 1447 | n/a | XML_SetElementDeclHandler(XML_Parser parser, |
|---|
| 1448 | n/a | XML_ElementDeclHandler eldecl) |
|---|
| 1449 | n/a | { |
|---|
| 1450 | n/a | elementDeclHandler = eldecl; |
|---|
| 1451 | n/a | } |
|---|
| 1452 | n/a | |
|---|
| 1453 | n/a | void XMLCALL |
|---|
| 1454 | n/a | XML_SetAttlistDeclHandler(XML_Parser parser, |
|---|
| 1455 | n/a | XML_AttlistDeclHandler attdecl) |
|---|
| 1456 | n/a | { |
|---|
| 1457 | n/a | attlistDeclHandler = attdecl; |
|---|
| 1458 | n/a | } |
|---|
| 1459 | n/a | |
|---|
| 1460 | n/a | void XMLCALL |
|---|
| 1461 | n/a | XML_SetEntityDeclHandler(XML_Parser parser, |
|---|
| 1462 | n/a | XML_EntityDeclHandler handler) |
|---|
| 1463 | n/a | { |
|---|
| 1464 | n/a | entityDeclHandler = handler; |
|---|
| 1465 | n/a | } |
|---|
| 1466 | n/a | |
|---|
| 1467 | n/a | void XMLCALL |
|---|
| 1468 | n/a | XML_SetXmlDeclHandler(XML_Parser parser, |
|---|
| 1469 | n/a | XML_XmlDeclHandler handler) { |
|---|
| 1470 | n/a | xmlDeclHandler = handler; |
|---|
| 1471 | n/a | } |
|---|
| 1472 | n/a | |
|---|
| 1473 | n/a | int XMLCALL |
|---|
| 1474 | n/a | XML_SetParamEntityParsing(XML_Parser parser, |
|---|
| 1475 | n/a | enum XML_ParamEntityParsing peParsing) |
|---|
| 1476 | n/a | { |
|---|
| 1477 | n/a | /* block after XML_Parse()/XML_ParseBuffer() has been called */ |
|---|
| 1478 | n/a | if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) |
|---|
| 1479 | n/a | return 0; |
|---|
| 1480 | n/a | #ifdef XML_DTD |
|---|
| 1481 | n/a | paramEntityParsing = peParsing; |
|---|
| 1482 | n/a | return 1; |
|---|
| 1483 | n/a | #else |
|---|
| 1484 | n/a | return peParsing == XML_PARAM_ENTITY_PARSING_NEVER; |
|---|
| 1485 | n/a | #endif |
|---|
| 1486 | n/a | } |
|---|
| 1487 | n/a | |
|---|
| 1488 | n/a | int XMLCALL |
|---|
| 1489 | n/a | XML_SetHashSalt(XML_Parser parser, |
|---|
| 1490 | n/a | unsigned long hash_salt) |
|---|
| 1491 | n/a | { |
|---|
| 1492 | n/a | /* block after XML_Parse()/XML_ParseBuffer() has been called */ |
|---|
| 1493 | n/a | if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) |
|---|
| 1494 | n/a | return 0; |
|---|
| 1495 | n/a | hash_secret_salt = hash_salt; |
|---|
| 1496 | n/a | return 1; |
|---|
| 1497 | n/a | } |
|---|
| 1498 | n/a | |
|---|
| 1499 | n/a | enum XML_Status XMLCALL |
|---|
| 1500 | n/a | XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) |
|---|
| 1501 | n/a | { |
|---|
| 1502 | n/a | switch (ps_parsing) { |
|---|
| 1503 | n/a | case XML_SUSPENDED: |
|---|
| 1504 | n/a | errorCode = XML_ERROR_SUSPENDED; |
|---|
| 1505 | n/a | return XML_STATUS_ERROR; |
|---|
| 1506 | n/a | case XML_FINISHED: |
|---|
| 1507 | n/a | errorCode = XML_ERROR_FINISHED; |
|---|
| 1508 | n/a | return XML_STATUS_ERROR; |
|---|
| 1509 | n/a | case XML_INITIALIZED: |
|---|
| 1510 | n/a | if (parentParser == NULL && !startParsing(parser)) { |
|---|
| 1511 | n/a | errorCode = XML_ERROR_NO_MEMORY; |
|---|
| 1512 | n/a | return XML_STATUS_ERROR; |
|---|
| 1513 | n/a | } |
|---|
| 1514 | n/a | default: |
|---|
| 1515 | n/a | ps_parsing = XML_PARSING; |
|---|
| 1516 | n/a | } |
|---|
| 1517 | n/a | |
|---|
| 1518 | n/a | if (len == 0) { |
|---|
| 1519 | n/a | ps_finalBuffer = (XML_Bool)isFinal; |
|---|
| 1520 | n/a | if (!isFinal) |
|---|
| 1521 | n/a | return XML_STATUS_OK; |
|---|
| 1522 | n/a | positionPtr = bufferPtr; |
|---|
| 1523 | n/a | parseEndPtr = bufferEnd; |
|---|
| 1524 | n/a | |
|---|
| 1525 | n/a | /* If data are left over from last buffer, and we now know that these |
|---|
| 1526 | n/a | data are the final chunk of input, then we have to check them again |
|---|
| 1527 | n/a | to detect errors based on that fact. |
|---|
| 1528 | n/a | */ |
|---|
| 1529 | n/a | errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr); |
|---|
| 1530 | n/a | |
|---|
| 1531 | n/a | if (errorCode == XML_ERROR_NONE) { |
|---|
| 1532 | n/a | switch (ps_parsing) { |
|---|
| 1533 | n/a | case XML_SUSPENDED: |
|---|
| 1534 | n/a | XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); |
|---|
| 1535 | n/a | positionPtr = bufferPtr; |
|---|
| 1536 | n/a | return XML_STATUS_SUSPENDED; |
|---|
| 1537 | n/a | case XML_INITIALIZED: |
|---|
| 1538 | n/a | case XML_PARSING: |
|---|
| 1539 | n/a | ps_parsing = XML_FINISHED; |
|---|
| 1540 | n/a | /* fall through */ |
|---|
| 1541 | n/a | default: |
|---|
| 1542 | n/a | return XML_STATUS_OK; |
|---|
| 1543 | n/a | } |
|---|
| 1544 | n/a | } |
|---|
| 1545 | n/a | eventEndPtr = eventPtr; |
|---|
| 1546 | n/a | processor = errorProcessor; |
|---|
| 1547 | n/a | return XML_STATUS_ERROR; |
|---|
| 1548 | n/a | } |
|---|
| 1549 | n/a | #ifndef XML_CONTEXT_BYTES |
|---|
| 1550 | n/a | else if (bufferPtr == bufferEnd) { |
|---|
| 1551 | n/a | const char *end; |
|---|
| 1552 | n/a | int nLeftOver; |
|---|
| 1553 | n/a | enum XML_Status result; |
|---|
| 1554 | n/a | parseEndByteIndex += len; |
|---|
| 1555 | n/a | positionPtr = s; |
|---|
| 1556 | n/a | ps_finalBuffer = (XML_Bool)isFinal; |
|---|
| 1557 | n/a | |
|---|
| 1558 | n/a | errorCode = processor(parser, s, parseEndPtr = s + len, &end); |
|---|
| 1559 | n/a | |
|---|
| 1560 | n/a | if (errorCode != XML_ERROR_NONE) { |
|---|
| 1561 | n/a | eventEndPtr = eventPtr; |
|---|
| 1562 | n/a | processor = errorProcessor; |
|---|
| 1563 | n/a | return XML_STATUS_ERROR; |
|---|
| 1564 | n/a | } |
|---|
| 1565 | n/a | else { |
|---|
| 1566 | n/a | switch (ps_parsing) { |
|---|
| 1567 | n/a | case XML_SUSPENDED: |
|---|
| 1568 | n/a | result = XML_STATUS_SUSPENDED; |
|---|
| 1569 | n/a | break; |
|---|
| 1570 | n/a | case XML_INITIALIZED: |
|---|
| 1571 | n/a | case XML_PARSING: |
|---|
| 1572 | n/a | if (isFinal) { |
|---|
| 1573 | n/a | ps_parsing = XML_FINISHED; |
|---|
| 1574 | n/a | return XML_STATUS_OK; |
|---|
| 1575 | n/a | } |
|---|
| 1576 | n/a | /* fall through */ |
|---|
| 1577 | n/a | default: |
|---|
| 1578 | n/a | result = XML_STATUS_OK; |
|---|
| 1579 | n/a | } |
|---|
| 1580 | n/a | } |
|---|
| 1581 | n/a | |
|---|
| 1582 | n/a | XmlUpdatePosition(encoding, positionPtr, end, &position); |
|---|
| 1583 | n/a | nLeftOver = s + len - end; |
|---|
| 1584 | n/a | if (nLeftOver) { |
|---|
| 1585 | n/a | if (buffer == NULL || nLeftOver > bufferLim - buffer) { |
|---|
| 1586 | n/a | /* FIXME avoid integer overflow */ |
|---|
| 1587 | n/a | char *temp; |
|---|
| 1588 | n/a | temp = (buffer == NULL |
|---|
| 1589 | n/a | ? (char *)MALLOC(len * 2) |
|---|
| 1590 | n/a | : (char *)REALLOC(buffer, len * 2)); |
|---|
| 1591 | n/a | if (temp == NULL) { |
|---|
| 1592 | n/a | errorCode = XML_ERROR_NO_MEMORY; |
|---|
| 1593 | n/a | eventPtr = eventEndPtr = NULL; |
|---|
| 1594 | n/a | processor = errorProcessor; |
|---|
| 1595 | n/a | return XML_STATUS_ERROR; |
|---|
| 1596 | n/a | } |
|---|
| 1597 | n/a | buffer = temp; |
|---|
| 1598 | n/a | bufferLim = buffer + len * 2; |
|---|
| 1599 | n/a | } |
|---|
| 1600 | n/a | memcpy(buffer, end, nLeftOver); |
|---|
| 1601 | n/a | } |
|---|
| 1602 | n/a | bufferPtr = buffer; |
|---|
| 1603 | n/a | bufferEnd = buffer + nLeftOver; |
|---|
| 1604 | n/a | positionPtr = bufferPtr; |
|---|
| 1605 | n/a | parseEndPtr = bufferEnd; |
|---|
| 1606 | n/a | eventPtr = bufferPtr; |
|---|
| 1607 | n/a | eventEndPtr = bufferPtr; |
|---|
| 1608 | n/a | return result; |
|---|
| 1609 | n/a | } |
|---|
| 1610 | n/a | #endif /* not defined XML_CONTEXT_BYTES */ |
|---|
| 1611 | n/a | else { |
|---|
| 1612 | n/a | void *buff = XML_GetBuffer(parser, len); |
|---|
| 1613 | n/a | if (buff == NULL) |
|---|
| 1614 | n/a | return XML_STATUS_ERROR; |
|---|
| 1615 | n/a | else { |
|---|
| 1616 | n/a | memcpy(buff, s, len); |
|---|
| 1617 | n/a | return XML_ParseBuffer(parser, len, isFinal); |
|---|
| 1618 | n/a | } |
|---|
| 1619 | n/a | } |
|---|
| 1620 | n/a | } |
|---|
| 1621 | n/a | |
|---|
| 1622 | n/a | enum XML_Status XMLCALL |
|---|
| 1623 | n/a | XML_ParseBuffer(XML_Parser parser, int len, int isFinal) |
|---|
| 1624 | n/a | { |
|---|
| 1625 | n/a | const char *start; |
|---|
| 1626 | n/a | enum XML_Status result = XML_STATUS_OK; |
|---|
| 1627 | n/a | |
|---|
| 1628 | n/a | switch (ps_parsing) { |
|---|
| 1629 | n/a | case XML_SUSPENDED: |
|---|
| 1630 | n/a | errorCode = XML_ERROR_SUSPENDED; |
|---|
| 1631 | n/a | return XML_STATUS_ERROR; |
|---|
| 1632 | n/a | case XML_FINISHED: |
|---|
| 1633 | n/a | errorCode = XML_ERROR_FINISHED; |
|---|
| 1634 | n/a | return XML_STATUS_ERROR; |
|---|
| 1635 | n/a | case XML_INITIALIZED: |
|---|
| 1636 | n/a | if (parentParser == NULL && !startParsing(parser)) { |
|---|
| 1637 | n/a | errorCode = XML_ERROR_NO_MEMORY; |
|---|
| 1638 | n/a | return XML_STATUS_ERROR; |
|---|
| 1639 | n/a | } |
|---|
| 1640 | n/a | default: |
|---|
| 1641 | n/a | ps_parsing = XML_PARSING; |
|---|
| 1642 | n/a | } |
|---|
| 1643 | n/a | |
|---|
| 1644 | n/a | start = bufferPtr; |
|---|
| 1645 | n/a | positionPtr = start; |
|---|
| 1646 | n/a | bufferEnd += len; |
|---|
| 1647 | n/a | parseEndPtr = bufferEnd; |
|---|
| 1648 | n/a | parseEndByteIndex += len; |
|---|
| 1649 | n/a | ps_finalBuffer = (XML_Bool)isFinal; |
|---|
| 1650 | n/a | |
|---|
| 1651 | n/a | errorCode = processor(parser, start, parseEndPtr, &bufferPtr); |
|---|
| 1652 | n/a | |
|---|
| 1653 | n/a | if (errorCode != XML_ERROR_NONE) { |
|---|
| 1654 | n/a | eventEndPtr = eventPtr; |
|---|
| 1655 | n/a | processor = errorProcessor; |
|---|
| 1656 | n/a | return XML_STATUS_ERROR; |
|---|
| 1657 | n/a | } |
|---|
| 1658 | n/a | else { |
|---|
| 1659 | n/a | switch (ps_parsing) { |
|---|
| 1660 | n/a | case XML_SUSPENDED: |
|---|
| 1661 | n/a | result = XML_STATUS_SUSPENDED; |
|---|
| 1662 | n/a | break; |
|---|
| 1663 | n/a | case XML_INITIALIZED: |
|---|
| 1664 | n/a | case XML_PARSING: |
|---|
| 1665 | n/a | if (isFinal) { |
|---|
| 1666 | n/a | ps_parsing = XML_FINISHED; |
|---|
| 1667 | n/a | return result; |
|---|
| 1668 | n/a | } |
|---|
| 1669 | n/a | default: ; /* should not happen */ |
|---|
| 1670 | n/a | } |
|---|
| 1671 | n/a | } |
|---|
| 1672 | n/a | |
|---|
| 1673 | n/a | XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); |
|---|
| 1674 | n/a | positionPtr = bufferPtr; |
|---|
| 1675 | n/a | return result; |
|---|
| 1676 | n/a | } |
|---|
| 1677 | n/a | |
|---|
| 1678 | n/a | void * XMLCALL |
|---|
| 1679 | n/a | XML_GetBuffer(XML_Parser parser, int len) |
|---|
| 1680 | n/a | { |
|---|
| 1681 | n/a | if (len < 0) { |
|---|
| 1682 | n/a | errorCode = XML_ERROR_NO_MEMORY; |
|---|
| 1683 | n/a | return NULL; |
|---|
| 1684 | n/a | } |
|---|
| 1685 | n/a | switch (ps_parsing) { |
|---|
| 1686 | n/a | case XML_SUSPENDED: |
|---|
| 1687 | n/a | errorCode = XML_ERROR_SUSPENDED; |
|---|
| 1688 | n/a | return NULL; |
|---|
| 1689 | n/a | case XML_FINISHED: |
|---|
| 1690 | n/a | errorCode = XML_ERROR_FINISHED; |
|---|
| 1691 | n/a | return NULL; |
|---|
| 1692 | n/a | default: ; |
|---|
| 1693 | n/a | } |
|---|
| 1694 | n/a | |
|---|
| 1695 | n/a | if (len > bufferLim - bufferEnd) { |
|---|
| 1696 | n/a | #ifdef XML_CONTEXT_BYTES |
|---|
| 1697 | n/a | int keep; |
|---|
| 1698 | n/a | #endif |
|---|
| 1699 | n/a | int neededSize = len + (int)(bufferEnd - bufferPtr); |
|---|
| 1700 | n/a | if (neededSize < 0) { |
|---|
| 1701 | n/a | errorCode = XML_ERROR_NO_MEMORY; |
|---|
| 1702 | n/a | return NULL; |
|---|
| 1703 | n/a | } |
|---|
| 1704 | n/a | #ifdef XML_CONTEXT_BYTES |
|---|
| 1705 | n/a | keep = (int)(bufferPtr - buffer); |
|---|
| 1706 | n/a | |
|---|
| 1707 | n/a | if (keep > XML_CONTEXT_BYTES) |
|---|
| 1708 | n/a | keep = XML_CONTEXT_BYTES; |
|---|
| 1709 | n/a | neededSize += keep; |
|---|
| 1710 | n/a | #endif /* defined XML_CONTEXT_BYTES */ |
|---|
| 1711 | n/a | if (neededSize <= bufferLim - buffer) { |
|---|
| 1712 | n/a | #ifdef XML_CONTEXT_BYTES |
|---|
| 1713 | n/a | if (keep < bufferPtr - buffer) { |
|---|
| 1714 | n/a | int offset = (int)(bufferPtr - buffer) - keep; |
|---|
| 1715 | n/a | memmove(buffer, &buffer[offset], bufferEnd - bufferPtr + keep); |
|---|
| 1716 | n/a | bufferEnd -= offset; |
|---|
| 1717 | n/a | bufferPtr -= offset; |
|---|
| 1718 | n/a | } |
|---|
| 1719 | n/a | #else |
|---|
| 1720 | n/a | memmove(buffer, bufferPtr, bufferEnd - bufferPtr); |
|---|
| 1721 | n/a | bufferEnd = buffer + (bufferEnd - bufferPtr); |
|---|
| 1722 | n/a | bufferPtr = buffer; |
|---|
| 1723 | n/a | #endif /* not defined XML_CONTEXT_BYTES */ |
|---|
| 1724 | n/a | } |
|---|
| 1725 | n/a | else { |
|---|
| 1726 | n/a | char *newBuf; |
|---|
| 1727 | n/a | int bufferSize = (int)(bufferLim - bufferPtr); |
|---|
| 1728 | n/a | if (bufferSize == 0) |
|---|
| 1729 | n/a | bufferSize = INIT_BUFFER_SIZE; |
|---|
| 1730 | n/a | do { |
|---|
| 1731 | n/a | bufferSize *= 2; |
|---|
| 1732 | n/a | } while (bufferSize < neededSize && bufferSize > 0); |
|---|
| 1733 | n/a | if (bufferSize <= 0) { |
|---|
| 1734 | n/a | errorCode = XML_ERROR_NO_MEMORY; |
|---|
| 1735 | n/a | return NULL; |
|---|
| 1736 | n/a | } |
|---|
| 1737 | n/a | newBuf = (char *)MALLOC(bufferSize); |
|---|
| 1738 | n/a | if (newBuf == 0) { |
|---|
| 1739 | n/a | errorCode = XML_ERROR_NO_MEMORY; |
|---|
| 1740 | n/a | return NULL; |
|---|
| 1741 | n/a | } |
|---|
| 1742 | n/a | bufferLim = newBuf + bufferSize; |
|---|
| 1743 | n/a | #ifdef XML_CONTEXT_BYTES |
|---|
| 1744 | n/a | if (bufferPtr) { |
|---|
| 1745 | n/a | int keep = (int)(bufferPtr - buffer); |
|---|
| 1746 | n/a | if (keep > XML_CONTEXT_BYTES) |
|---|
| 1747 | n/a | keep = XML_CONTEXT_BYTES; |
|---|
| 1748 | n/a | memcpy(newBuf, &bufferPtr[-keep], bufferEnd - bufferPtr + keep); |
|---|
| 1749 | n/a | FREE(buffer); |
|---|
| 1750 | n/a | buffer = newBuf; |
|---|
| 1751 | n/a | bufferEnd = buffer + (bufferEnd - bufferPtr) + keep; |
|---|
| 1752 | n/a | bufferPtr = buffer + keep; |
|---|
| 1753 | n/a | } |
|---|
| 1754 | n/a | else { |
|---|
| 1755 | n/a | bufferEnd = newBuf + (bufferEnd - bufferPtr); |
|---|
| 1756 | n/a | bufferPtr = buffer = newBuf; |
|---|
| 1757 | n/a | } |
|---|
| 1758 | n/a | #else |
|---|
| 1759 | n/a | if (bufferPtr) { |
|---|
| 1760 | n/a | memcpy(newBuf, bufferPtr, bufferEnd - bufferPtr); |
|---|
| 1761 | n/a | FREE(buffer); |
|---|
| 1762 | n/a | } |
|---|
| 1763 | n/a | bufferEnd = newBuf + (bufferEnd - bufferPtr); |
|---|
| 1764 | n/a | bufferPtr = buffer = newBuf; |
|---|
| 1765 | n/a | #endif /* not defined XML_CONTEXT_BYTES */ |
|---|
| 1766 | n/a | } |
|---|
| 1767 | n/a | eventPtr = eventEndPtr = NULL; |
|---|
| 1768 | n/a | positionPtr = NULL; |
|---|
| 1769 | n/a | } |
|---|
| 1770 | n/a | return bufferEnd; |
|---|
| 1771 | n/a | } |
|---|
| 1772 | n/a | |
|---|
| 1773 | n/a | enum XML_Status XMLCALL |
|---|
| 1774 | n/a | XML_StopParser(XML_Parser parser, XML_Bool resumable) |
|---|
| 1775 | n/a | { |
|---|
| 1776 | n/a | switch (ps_parsing) { |
|---|
| 1777 | n/a | case XML_SUSPENDED: |
|---|
| 1778 | n/a | if (resumable) { |
|---|
| 1779 | n/a | errorCode = XML_ERROR_SUSPENDED; |
|---|
| 1780 | n/a | return XML_STATUS_ERROR; |
|---|
| 1781 | n/a | } |
|---|
| 1782 | n/a | ps_parsing = XML_FINISHED; |
|---|
| 1783 | n/a | break; |
|---|
| 1784 | n/a | case XML_FINISHED: |
|---|
| 1785 | n/a | errorCode = XML_ERROR_FINISHED; |
|---|
| 1786 | n/a | return XML_STATUS_ERROR; |
|---|
| 1787 | n/a | default: |
|---|
| 1788 | n/a | if (resumable) { |
|---|
| 1789 | n/a | #ifdef XML_DTD |
|---|
| 1790 | n/a | if (isParamEntity) { |
|---|
| 1791 | n/a | errorCode = XML_ERROR_SUSPEND_PE; |
|---|
| 1792 | n/a | return XML_STATUS_ERROR; |
|---|
| 1793 | n/a | } |
|---|
| 1794 | n/a | #endif |
|---|
| 1795 | n/a | ps_parsing = XML_SUSPENDED; |
|---|
| 1796 | n/a | } |
|---|
| 1797 | n/a | else |
|---|
| 1798 | n/a | ps_parsing = XML_FINISHED; |
|---|
| 1799 | n/a | } |
|---|
| 1800 | n/a | return XML_STATUS_OK; |
|---|
| 1801 | n/a | } |
|---|
| 1802 | n/a | |
|---|
| 1803 | n/a | enum XML_Status XMLCALL |
|---|
| 1804 | n/a | XML_ResumeParser(XML_Parser parser) |
|---|
| 1805 | n/a | { |
|---|
| 1806 | n/a | enum XML_Status result = XML_STATUS_OK; |
|---|
| 1807 | n/a | |
|---|
| 1808 | n/a | if (ps_parsing != XML_SUSPENDED) { |
|---|
| 1809 | n/a | errorCode = XML_ERROR_NOT_SUSPENDED; |
|---|
| 1810 | n/a | return XML_STATUS_ERROR; |
|---|
| 1811 | n/a | } |
|---|
| 1812 | n/a | ps_parsing = XML_PARSING; |
|---|
| 1813 | n/a | |
|---|
| 1814 | n/a | errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr); |
|---|
| 1815 | n/a | |
|---|
| 1816 | n/a | if (errorCode != XML_ERROR_NONE) { |
|---|
| 1817 | n/a | eventEndPtr = eventPtr; |
|---|
| 1818 | n/a | processor = errorProcessor; |
|---|
| 1819 | n/a | return XML_STATUS_ERROR; |
|---|
| 1820 | n/a | } |
|---|
| 1821 | n/a | else { |
|---|
| 1822 | n/a | switch (ps_parsing) { |
|---|
| 1823 | n/a | case XML_SUSPENDED: |
|---|
| 1824 | n/a | result = XML_STATUS_SUSPENDED; |
|---|
| 1825 | n/a | break; |
|---|
| 1826 | n/a | case XML_INITIALIZED: |
|---|
| 1827 | n/a | case XML_PARSING: |
|---|
| 1828 | n/a | if (ps_finalBuffer) { |
|---|
| 1829 | n/a | ps_parsing = XML_FINISHED; |
|---|
| 1830 | n/a | return result; |
|---|
| 1831 | n/a | } |
|---|
| 1832 | n/a | default: ; |
|---|
| 1833 | n/a | } |
|---|
| 1834 | n/a | } |
|---|
| 1835 | n/a | |
|---|
| 1836 | n/a | XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); |
|---|
| 1837 | n/a | positionPtr = bufferPtr; |
|---|
| 1838 | n/a | return result; |
|---|
| 1839 | n/a | } |
|---|
| 1840 | n/a | |
|---|
| 1841 | n/a | void XMLCALL |
|---|
| 1842 | n/a | XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status) |
|---|
| 1843 | n/a | { |
|---|
| 1844 | n/a | assert(status != NULL); |
|---|
| 1845 | n/a | *status = parser->m_parsingStatus; |
|---|
| 1846 | n/a | } |
|---|
| 1847 | n/a | |
|---|
| 1848 | n/a | enum XML_Error XMLCALL |
|---|
| 1849 | n/a | XML_GetErrorCode(XML_Parser parser) |
|---|
| 1850 | n/a | { |
|---|
| 1851 | n/a | return errorCode; |
|---|
| 1852 | n/a | } |
|---|
| 1853 | n/a | |
|---|
| 1854 | n/a | XML_Index XMLCALL |
|---|
| 1855 | n/a | XML_GetCurrentByteIndex(XML_Parser parser) |
|---|
| 1856 | n/a | { |
|---|
| 1857 | n/a | if (eventPtr) |
|---|
| 1858 | n/a | return parseEndByteIndex - (parseEndPtr - eventPtr); |
|---|
| 1859 | n/a | return -1; |
|---|
| 1860 | n/a | } |
|---|
| 1861 | n/a | |
|---|
| 1862 | n/a | int XMLCALL |
|---|
| 1863 | n/a | XML_GetCurrentByteCount(XML_Parser parser) |
|---|
| 1864 | n/a | { |
|---|
| 1865 | n/a | if (eventEndPtr && eventPtr) |
|---|
| 1866 | n/a | return (int)(eventEndPtr - eventPtr); |
|---|
| 1867 | n/a | return 0; |
|---|
| 1868 | n/a | } |
|---|
| 1869 | n/a | |
|---|
| 1870 | n/a | const char * XMLCALL |
|---|
| 1871 | n/a | XML_GetInputContext(XML_Parser parser, int *offset, int *size) |
|---|
| 1872 | n/a | { |
|---|
| 1873 | n/a | #ifdef XML_CONTEXT_BYTES |
|---|
| 1874 | n/a | if (eventPtr && buffer) { |
|---|
| 1875 | n/a | *offset = (int)(eventPtr - buffer); |
|---|
| 1876 | n/a | *size = (int)(bufferEnd - buffer); |
|---|
| 1877 | n/a | return buffer; |
|---|
| 1878 | n/a | } |
|---|
| 1879 | n/a | #endif /* defined XML_CONTEXT_BYTES */ |
|---|
| 1880 | n/a | return (char *) 0; |
|---|
| 1881 | n/a | } |
|---|
| 1882 | n/a | |
|---|
| 1883 | n/a | XML_Size XMLCALL |
|---|
| 1884 | n/a | XML_GetCurrentLineNumber(XML_Parser parser) |
|---|
| 1885 | n/a | { |
|---|
| 1886 | n/a | if (eventPtr && eventPtr >= positionPtr) { |
|---|
| 1887 | n/a | XmlUpdatePosition(encoding, positionPtr, eventPtr, &position); |
|---|
| 1888 | n/a | positionPtr = eventPtr; |
|---|
| 1889 | n/a | } |
|---|
| 1890 | n/a | return position.lineNumber + 1; |
|---|
| 1891 | n/a | } |
|---|
| 1892 | n/a | |
|---|
| 1893 | n/a | XML_Size XMLCALL |
|---|
| 1894 | n/a | XML_GetCurrentColumnNumber(XML_Parser parser) |
|---|
| 1895 | n/a | { |
|---|
| 1896 | n/a | if (eventPtr && eventPtr >= positionPtr) { |
|---|
| 1897 | n/a | XmlUpdatePosition(encoding, positionPtr, eventPtr, &position); |
|---|
| 1898 | n/a | positionPtr = eventPtr; |
|---|
| 1899 | n/a | } |
|---|
| 1900 | n/a | return position.columnNumber; |
|---|
| 1901 | n/a | } |
|---|
| 1902 | n/a | |
|---|
| 1903 | n/a | void XMLCALL |
|---|
| 1904 | n/a | XML_FreeContentModel(XML_Parser parser, XML_Content *model) |
|---|
| 1905 | n/a | { |
|---|
| 1906 | n/a | FREE(model); |
|---|
| 1907 | n/a | } |
|---|
| 1908 | n/a | |
|---|
| 1909 | n/a | void * XMLCALL |
|---|
| 1910 | n/a | XML_MemMalloc(XML_Parser parser, size_t size) |
|---|
| 1911 | n/a | { |
|---|
| 1912 | n/a | return MALLOC(size); |
|---|
| 1913 | n/a | } |
|---|
| 1914 | n/a | |
|---|
| 1915 | n/a | void * XMLCALL |
|---|
| 1916 | n/a | XML_MemRealloc(XML_Parser parser, void *ptr, size_t size) |
|---|
| 1917 | n/a | { |
|---|
| 1918 | n/a | return REALLOC(ptr, size); |
|---|
| 1919 | n/a | } |
|---|
| 1920 | n/a | |
|---|
| 1921 | n/a | void XMLCALL |
|---|
| 1922 | n/a | XML_MemFree(XML_Parser parser, void *ptr) |
|---|
| 1923 | n/a | { |
|---|
| 1924 | n/a | FREE(ptr); |
|---|
| 1925 | n/a | } |
|---|
| 1926 | n/a | |
|---|
| 1927 | n/a | void XMLCALL |
|---|
| 1928 | n/a | XML_DefaultCurrent(XML_Parser parser) |
|---|
| 1929 | n/a | { |
|---|
| 1930 | n/a | if (defaultHandler) { |
|---|
| 1931 | n/a | if (openInternalEntities) |
|---|
| 1932 | n/a | reportDefault(parser, |
|---|
| 1933 | n/a | internalEncoding, |
|---|
| 1934 | n/a | openInternalEntities->internalEventPtr, |
|---|
| 1935 | n/a | openInternalEntities->internalEventEndPtr); |
|---|
| 1936 | n/a | else |
|---|
| 1937 | n/a | reportDefault(parser, encoding, eventPtr, eventEndPtr); |
|---|
| 1938 | n/a | } |
|---|
| 1939 | n/a | } |
|---|
| 1940 | n/a | |
|---|
| 1941 | n/a | const XML_LChar * XMLCALL |
|---|
| 1942 | n/a | XML_ErrorString(enum XML_Error code) |
|---|
| 1943 | n/a | { |
|---|
| 1944 | n/a | static const XML_LChar* const message[] = { |
|---|
| 1945 | n/a | 0, |
|---|
| 1946 | n/a | XML_L("out of memory"), |
|---|
| 1947 | n/a | XML_L("syntax error"), |
|---|
| 1948 | n/a | XML_L("no element found"), |
|---|
| 1949 | n/a | XML_L("not well-formed (invalid token)"), |
|---|
| 1950 | n/a | XML_L("unclosed token"), |
|---|
| 1951 | n/a | XML_L("partial character"), |
|---|
| 1952 | n/a | XML_L("mismatched tag"), |
|---|
| 1953 | n/a | XML_L("duplicate attribute"), |
|---|
| 1954 | n/a | XML_L("junk after document element"), |
|---|
| 1955 | n/a | XML_L("illegal parameter entity reference"), |
|---|
| 1956 | n/a | XML_L("undefined entity"), |
|---|
| 1957 | n/a | XML_L("recursive entity reference"), |
|---|
| 1958 | n/a | XML_L("asynchronous entity"), |
|---|
| 1959 | n/a | XML_L("reference to invalid character number"), |
|---|
| 1960 | n/a | XML_L("reference to binary entity"), |
|---|
| 1961 | n/a | XML_L("reference to external entity in attribute"), |
|---|
| 1962 | n/a | XML_L("XML or text declaration not at start of entity"), |
|---|
| 1963 | n/a | XML_L("unknown encoding"), |
|---|
| 1964 | n/a | XML_L("encoding specified in XML declaration is incorrect"), |
|---|
| 1965 | n/a | XML_L("unclosed CDATA section"), |
|---|
| 1966 | n/a | XML_L("error in processing external entity reference"), |
|---|
| 1967 | n/a | XML_L("document is not standalone"), |
|---|
| 1968 | n/a | XML_L("unexpected parser state - please send a bug report"), |
|---|
| 1969 | n/a | XML_L("entity declared in parameter entity"), |
|---|
| 1970 | n/a | XML_L("requested feature requires XML_DTD support in Expat"), |
|---|
| 1971 | n/a | XML_L("cannot change setting once parsing has begun"), |
|---|
| 1972 | n/a | XML_L("unbound prefix"), |
|---|
| 1973 | n/a | XML_L("must not undeclare prefix"), |
|---|
| 1974 | n/a | XML_L("incomplete markup in parameter entity"), |
|---|
| 1975 | n/a | XML_L("XML declaration not well-formed"), |
|---|
| 1976 | n/a | XML_L("text declaration not well-formed"), |
|---|
| 1977 | n/a | XML_L("illegal character(s) in public id"), |
|---|
| 1978 | n/a | XML_L("parser suspended"), |
|---|
| 1979 | n/a | XML_L("parser not suspended"), |
|---|
| 1980 | n/a | XML_L("parsing aborted"), |
|---|
| 1981 | n/a | XML_L("parsing finished"), |
|---|
| 1982 | n/a | XML_L("cannot suspend in external parameter entity"), |
|---|
| 1983 | n/a | XML_L("reserved prefix (xml) must not be undeclared or bound to another namespace name"), |
|---|
| 1984 | n/a | XML_L("reserved prefix (xmlns) must not be declared or undeclared"), |
|---|
| 1985 | n/a | XML_L("prefix must not be bound to one of the reserved namespace names") |
|---|
| 1986 | n/a | }; |
|---|
| 1987 | n/a | if (code > 0 && code < sizeof(message)/sizeof(message[0])) |
|---|
| 1988 | n/a | return message[code]; |
|---|
| 1989 | n/a | return NULL; |
|---|
| 1990 | n/a | } |
|---|
| 1991 | n/a | |
|---|
| 1992 | n/a | const XML_LChar * XMLCALL |
|---|
| 1993 | n/a | XML_ExpatVersion(void) { |
|---|
| 1994 | n/a | |
|---|
| 1995 | n/a | /* V1 is used to string-ize the version number. However, it would |
|---|
| 1996 | n/a | string-ize the actual version macro *names* unless we get them |
|---|
| 1997 | n/a | substituted before being passed to V1. CPP is defined to expand |
|---|
| 1998 | n/a | a macro, then rescan for more expansions. Thus, we use V2 to expand |
|---|
| 1999 | n/a | the version macros, then CPP will expand the resulting V1() macro |
|---|
| 2000 | n/a | with the correct numerals. */ |
|---|
| 2001 | n/a | /* ### I'm assuming cpp is portable in this respect... */ |
|---|
| 2002 | n/a | |
|---|
| 2003 | n/a | #define V1(a,b,c) XML_L(#a)XML_L(".")XML_L(#b)XML_L(".")XML_L(#c) |
|---|
| 2004 | n/a | #define V2(a,b,c) XML_L("expat_")V1(a,b,c) |
|---|
| 2005 | n/a | |
|---|
| 2006 | n/a | return V2(XML_MAJOR_VERSION, XML_MINOR_VERSION, XML_MICRO_VERSION); |
|---|
| 2007 | n/a | |
|---|
| 2008 | n/a | #undef V1 |
|---|
| 2009 | n/a | #undef V2 |
|---|
| 2010 | n/a | } |
|---|
| 2011 | n/a | |
|---|
| 2012 | n/a | XML_Expat_Version XMLCALL |
|---|
| 2013 | n/a | XML_ExpatVersionInfo(void) |
|---|
| 2014 | n/a | { |
|---|
| 2015 | n/a | XML_Expat_Version version; |
|---|
| 2016 | n/a | |
|---|
| 2017 | n/a | version.major = XML_MAJOR_VERSION; |
|---|
| 2018 | n/a | version.minor = XML_MINOR_VERSION; |
|---|
| 2019 | n/a | version.micro = XML_MICRO_VERSION; |
|---|
| 2020 | n/a | |
|---|
| 2021 | n/a | return version; |
|---|
| 2022 | n/a | } |
|---|
| 2023 | n/a | |
|---|
| 2024 | n/a | const XML_Feature * XMLCALL |
|---|
| 2025 | n/a | XML_GetFeatureList(void) |
|---|
| 2026 | n/a | { |
|---|
| 2027 | n/a | static const XML_Feature features[] = { |
|---|
| 2028 | n/a | {XML_FEATURE_SIZEOF_XML_CHAR, XML_L("sizeof(XML_Char)"), |
|---|
| 2029 | n/a | sizeof(XML_Char)}, |
|---|
| 2030 | n/a | {XML_FEATURE_SIZEOF_XML_LCHAR, XML_L("sizeof(XML_LChar)"), |
|---|
| 2031 | n/a | sizeof(XML_LChar)}, |
|---|
| 2032 | n/a | #ifdef XML_UNICODE |
|---|
| 2033 | n/a | {XML_FEATURE_UNICODE, XML_L("XML_UNICODE"), 0}, |
|---|
| 2034 | n/a | #endif |
|---|
| 2035 | n/a | #ifdef XML_UNICODE_WCHAR_T |
|---|
| 2036 | n/a | {XML_FEATURE_UNICODE_WCHAR_T, XML_L("XML_UNICODE_WCHAR_T"), 0}, |
|---|
| 2037 | n/a | #endif |
|---|
| 2038 | n/a | #ifdef XML_DTD |
|---|
| 2039 | n/a | {XML_FEATURE_DTD, XML_L("XML_DTD"), 0}, |
|---|
| 2040 | n/a | #endif |
|---|
| 2041 | n/a | #ifdef XML_CONTEXT_BYTES |
|---|
| 2042 | n/a | {XML_FEATURE_CONTEXT_BYTES, XML_L("XML_CONTEXT_BYTES"), |
|---|
| 2043 | n/a | XML_CONTEXT_BYTES}, |
|---|
| 2044 | n/a | #endif |
|---|
| 2045 | n/a | #ifdef XML_MIN_SIZE |
|---|
| 2046 | n/a | {XML_FEATURE_MIN_SIZE, XML_L("XML_MIN_SIZE"), 0}, |
|---|
| 2047 | n/a | #endif |
|---|
| 2048 | n/a | #ifdef XML_NS |
|---|
| 2049 | n/a | {XML_FEATURE_NS, XML_L("XML_NS"), 0}, |
|---|
| 2050 | n/a | #endif |
|---|
| 2051 | n/a | #ifdef XML_LARGE_SIZE |
|---|
| 2052 | n/a | {XML_FEATURE_LARGE_SIZE, XML_L("XML_LARGE_SIZE"), 0}, |
|---|
| 2053 | n/a | #endif |
|---|
| 2054 | n/a | #ifdef XML_ATTR_INFO |
|---|
| 2055 | n/a | {XML_FEATURE_ATTR_INFO, XML_L("XML_ATTR_INFO"), 0}, |
|---|
| 2056 | n/a | #endif |
|---|
| 2057 | n/a | {XML_FEATURE_END, NULL, 0} |
|---|
| 2058 | n/a | }; |
|---|
| 2059 | n/a | |
|---|
| 2060 | n/a | return features; |
|---|
| 2061 | n/a | } |
|---|
| 2062 | n/a | |
|---|
| 2063 | n/a | /* Initially tag->rawName always points into the parse buffer; |
|---|
| 2064 | n/a | for those TAG instances opened while the current parse buffer was |
|---|
| 2065 | n/a | processed, and not yet closed, we need to store tag->rawName in a more |
|---|
| 2066 | n/a | permanent location, since the parse buffer is about to be discarded. |
|---|
| 2067 | n/a | */ |
|---|
| 2068 | n/a | static XML_Bool |
|---|
| 2069 | n/a | storeRawNames(XML_Parser parser) |
|---|
| 2070 | n/a | { |
|---|
| 2071 | n/a | TAG *tag = tagStack; |
|---|
| 2072 | n/a | while (tag) { |
|---|
| 2073 | n/a | int bufSize; |
|---|
| 2074 | n/a | int nameLen = sizeof(XML_Char) * (tag->name.strLen + 1); |
|---|
| 2075 | n/a | char *rawNameBuf = tag->buf + nameLen; |
|---|
| 2076 | n/a | /* Stop if already stored. Since tagStack is a stack, we can stop |
|---|
| 2077 | n/a | at the first entry that has already been copied; everything |
|---|
| 2078 | n/a | below it in the stack is already been accounted for in a |
|---|
| 2079 | n/a | previous call to this function. |
|---|
| 2080 | n/a | */ |
|---|
| 2081 | n/a | if (tag->rawName == rawNameBuf) |
|---|
| 2082 | n/a | break; |
|---|
| 2083 | n/a | /* For re-use purposes we need to ensure that the |
|---|
| 2084 | n/a | size of tag->buf is a multiple of sizeof(XML_Char). |
|---|
| 2085 | n/a | */ |
|---|
| 2086 | n/a | bufSize = nameLen + ROUND_UP(tag->rawNameLength, sizeof(XML_Char)); |
|---|
| 2087 | n/a | if (bufSize > tag->bufEnd - tag->buf) { |
|---|
| 2088 | n/a | char *temp = (char *)REALLOC(tag->buf, bufSize); |
|---|
| 2089 | n/a | if (temp == NULL) |
|---|
| 2090 | n/a | return XML_FALSE; |
|---|
| 2091 | n/a | /* if tag->name.str points to tag->buf (only when namespace |
|---|
| 2092 | n/a | processing is off) then we have to update it |
|---|
| 2093 | n/a | */ |
|---|
| 2094 | n/a | if (tag->name.str == (XML_Char *)tag->buf) |
|---|
| 2095 | n/a | tag->name.str = (XML_Char *)temp; |
|---|
| 2096 | n/a | /* if tag->name.localPart is set (when namespace processing is on) |
|---|
| 2097 | n/a | then update it as well, since it will always point into tag->buf |
|---|
| 2098 | n/a | */ |
|---|
| 2099 | n/a | if (tag->name.localPart) |
|---|
| 2100 | n/a | tag->name.localPart = (XML_Char *)temp + (tag->name.localPart - |
|---|
| 2101 | n/a | (XML_Char *)tag->buf); |
|---|
| 2102 | n/a | tag->buf = temp; |
|---|
| 2103 | n/a | tag->bufEnd = temp + bufSize; |
|---|
| 2104 | n/a | rawNameBuf = temp + nameLen; |
|---|
| 2105 | n/a | } |
|---|
| 2106 | n/a | memcpy(rawNameBuf, tag->rawName, tag->rawNameLength); |
|---|
| 2107 | n/a | tag->rawName = rawNameBuf; |
|---|
| 2108 | n/a | tag = tag->parent; |
|---|
| 2109 | n/a | } |
|---|
| 2110 | n/a | return XML_TRUE; |
|---|
| 2111 | n/a | } |
|---|
| 2112 | n/a | |
|---|
| 2113 | n/a | static enum XML_Error PTRCALL |
|---|
| 2114 | n/a | contentProcessor(XML_Parser parser, |
|---|
| 2115 | n/a | const char *start, |
|---|
| 2116 | n/a | const char *end, |
|---|
| 2117 | n/a | const char **endPtr) |
|---|
| 2118 | n/a | { |
|---|
| 2119 | n/a | enum XML_Error result = doContent(parser, 0, encoding, start, end, |
|---|
| 2120 | n/a | endPtr, (XML_Bool)!ps_finalBuffer); |
|---|
| 2121 | n/a | if (result == XML_ERROR_NONE) { |
|---|
| 2122 | n/a | if (!storeRawNames(parser)) |
|---|
| 2123 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2124 | n/a | } |
|---|
| 2125 | n/a | return result; |
|---|
| 2126 | n/a | } |
|---|
| 2127 | n/a | |
|---|
| 2128 | n/a | static enum XML_Error PTRCALL |
|---|
| 2129 | n/a | externalEntityInitProcessor(XML_Parser parser, |
|---|
| 2130 | n/a | const char *start, |
|---|
| 2131 | n/a | const char *end, |
|---|
| 2132 | n/a | const char **endPtr) |
|---|
| 2133 | n/a | { |
|---|
| 2134 | n/a | enum XML_Error result = initializeEncoding(parser); |
|---|
| 2135 | n/a | if (result != XML_ERROR_NONE) |
|---|
| 2136 | n/a | return result; |
|---|
| 2137 | n/a | processor = externalEntityInitProcessor2; |
|---|
| 2138 | n/a | return externalEntityInitProcessor2(parser, start, end, endPtr); |
|---|
| 2139 | n/a | } |
|---|
| 2140 | n/a | |
|---|
| 2141 | n/a | static enum XML_Error PTRCALL |
|---|
| 2142 | n/a | externalEntityInitProcessor2(XML_Parser parser, |
|---|
| 2143 | n/a | const char *start, |
|---|
| 2144 | n/a | const char *end, |
|---|
| 2145 | n/a | const char **endPtr) |
|---|
| 2146 | n/a | { |
|---|
| 2147 | n/a | const char *next = start; /* XmlContentTok doesn't always set the last arg */ |
|---|
| 2148 | n/a | int tok = XmlContentTok(encoding, start, end, &next); |
|---|
| 2149 | n/a | switch (tok) { |
|---|
| 2150 | n/a | case XML_TOK_BOM: |
|---|
| 2151 | n/a | /* If we are at the end of the buffer, this would cause the next stage, |
|---|
| 2152 | n/a | i.e. externalEntityInitProcessor3, to pass control directly to |
|---|
| 2153 | n/a | doContent (by detecting XML_TOK_NONE) without processing any xml text |
|---|
| 2154 | n/a | declaration - causing the error XML_ERROR_MISPLACED_XML_PI in doContent. |
|---|
| 2155 | n/a | */ |
|---|
| 2156 | n/a | if (next == end && !ps_finalBuffer) { |
|---|
| 2157 | n/a | *endPtr = next; |
|---|
| 2158 | n/a | return XML_ERROR_NONE; |
|---|
| 2159 | n/a | } |
|---|
| 2160 | n/a | start = next; |
|---|
| 2161 | n/a | break; |
|---|
| 2162 | n/a | case XML_TOK_PARTIAL: |
|---|
| 2163 | n/a | if (!ps_finalBuffer) { |
|---|
| 2164 | n/a | *endPtr = start; |
|---|
| 2165 | n/a | return XML_ERROR_NONE; |
|---|
| 2166 | n/a | } |
|---|
| 2167 | n/a | eventPtr = start; |
|---|
| 2168 | n/a | return XML_ERROR_UNCLOSED_TOKEN; |
|---|
| 2169 | n/a | case XML_TOK_PARTIAL_CHAR: |
|---|
| 2170 | n/a | if (!ps_finalBuffer) { |
|---|
| 2171 | n/a | *endPtr = start; |
|---|
| 2172 | n/a | return XML_ERROR_NONE; |
|---|
| 2173 | n/a | } |
|---|
| 2174 | n/a | eventPtr = start; |
|---|
| 2175 | n/a | return XML_ERROR_PARTIAL_CHAR; |
|---|
| 2176 | n/a | } |
|---|
| 2177 | n/a | processor = externalEntityInitProcessor3; |
|---|
| 2178 | n/a | return externalEntityInitProcessor3(parser, start, end, endPtr); |
|---|
| 2179 | n/a | } |
|---|
| 2180 | n/a | |
|---|
| 2181 | n/a | static enum XML_Error PTRCALL |
|---|
| 2182 | n/a | externalEntityInitProcessor3(XML_Parser parser, |
|---|
| 2183 | n/a | const char *start, |
|---|
| 2184 | n/a | const char *end, |
|---|
| 2185 | n/a | const char **endPtr) |
|---|
| 2186 | n/a | { |
|---|
| 2187 | n/a | int tok; |
|---|
| 2188 | n/a | const char *next = start; /* XmlContentTok doesn't always set the last arg */ |
|---|
| 2189 | n/a | eventPtr = start; |
|---|
| 2190 | n/a | tok = XmlContentTok(encoding, start, end, &next); |
|---|
| 2191 | n/a | eventEndPtr = next; |
|---|
| 2192 | n/a | |
|---|
| 2193 | n/a | switch (tok) { |
|---|
| 2194 | n/a | case XML_TOK_XML_DECL: |
|---|
| 2195 | n/a | { |
|---|
| 2196 | n/a | enum XML_Error result; |
|---|
| 2197 | n/a | result = processXmlDecl(parser, 1, start, next); |
|---|
| 2198 | n/a | if (result != XML_ERROR_NONE) |
|---|
| 2199 | n/a | return result; |
|---|
| 2200 | n/a | switch (ps_parsing) { |
|---|
| 2201 | n/a | case XML_SUSPENDED: |
|---|
| 2202 | n/a | *endPtr = next; |
|---|
| 2203 | n/a | return XML_ERROR_NONE; |
|---|
| 2204 | n/a | case XML_FINISHED: |
|---|
| 2205 | n/a | return XML_ERROR_ABORTED; |
|---|
| 2206 | n/a | default: |
|---|
| 2207 | n/a | start = next; |
|---|
| 2208 | n/a | } |
|---|
| 2209 | n/a | } |
|---|
| 2210 | n/a | break; |
|---|
| 2211 | n/a | case XML_TOK_PARTIAL: |
|---|
| 2212 | n/a | if (!ps_finalBuffer) { |
|---|
| 2213 | n/a | *endPtr = start; |
|---|
| 2214 | n/a | return XML_ERROR_NONE; |
|---|
| 2215 | n/a | } |
|---|
| 2216 | n/a | return XML_ERROR_UNCLOSED_TOKEN; |
|---|
| 2217 | n/a | case XML_TOK_PARTIAL_CHAR: |
|---|
| 2218 | n/a | if (!ps_finalBuffer) { |
|---|
| 2219 | n/a | *endPtr = start; |
|---|
| 2220 | n/a | return XML_ERROR_NONE; |
|---|
| 2221 | n/a | } |
|---|
| 2222 | n/a | return XML_ERROR_PARTIAL_CHAR; |
|---|
| 2223 | n/a | } |
|---|
| 2224 | n/a | processor = externalEntityContentProcessor; |
|---|
| 2225 | n/a | tagLevel = 1; |
|---|
| 2226 | n/a | return externalEntityContentProcessor(parser, start, end, endPtr); |
|---|
| 2227 | n/a | } |
|---|
| 2228 | n/a | |
|---|
| 2229 | n/a | static enum XML_Error PTRCALL |
|---|
| 2230 | n/a | externalEntityContentProcessor(XML_Parser parser, |
|---|
| 2231 | n/a | const char *start, |
|---|
| 2232 | n/a | const char *end, |
|---|
| 2233 | n/a | const char **endPtr) |
|---|
| 2234 | n/a | { |
|---|
| 2235 | n/a | enum XML_Error result = doContent(parser, 1, encoding, start, end, |
|---|
| 2236 | n/a | endPtr, (XML_Bool)!ps_finalBuffer); |
|---|
| 2237 | n/a | if (result == XML_ERROR_NONE) { |
|---|
| 2238 | n/a | if (!storeRawNames(parser)) |
|---|
| 2239 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2240 | n/a | } |
|---|
| 2241 | n/a | return result; |
|---|
| 2242 | n/a | } |
|---|
| 2243 | n/a | |
|---|
| 2244 | n/a | static enum XML_Error |
|---|
| 2245 | n/a | doContent(XML_Parser parser, |
|---|
| 2246 | n/a | int startTagLevel, |
|---|
| 2247 | n/a | const ENCODING *enc, |
|---|
| 2248 | n/a | const char *s, |
|---|
| 2249 | n/a | const char *end, |
|---|
| 2250 | n/a | const char **nextPtr, |
|---|
| 2251 | n/a | XML_Bool haveMore) |
|---|
| 2252 | n/a | { |
|---|
| 2253 | n/a | /* save one level of indirection */ |
|---|
| 2254 | n/a | DTD * const dtd = _dtd; |
|---|
| 2255 | n/a | |
|---|
| 2256 | n/a | const char **eventPP; |
|---|
| 2257 | n/a | const char **eventEndPP; |
|---|
| 2258 | n/a | if (enc == encoding) { |
|---|
| 2259 | n/a | eventPP = &eventPtr; |
|---|
| 2260 | n/a | eventEndPP = &eventEndPtr; |
|---|
| 2261 | n/a | } |
|---|
| 2262 | n/a | else { |
|---|
| 2263 | n/a | eventPP = &(openInternalEntities->internalEventPtr); |
|---|
| 2264 | n/a | eventEndPP = &(openInternalEntities->internalEventEndPtr); |
|---|
| 2265 | n/a | } |
|---|
| 2266 | n/a | *eventPP = s; |
|---|
| 2267 | n/a | |
|---|
| 2268 | n/a | for (;;) { |
|---|
| 2269 | n/a | const char *next = s; /* XmlContentTok doesn't always set the last arg */ |
|---|
| 2270 | n/a | int tok = XmlContentTok(enc, s, end, &next); |
|---|
| 2271 | n/a | *eventEndPP = next; |
|---|
| 2272 | n/a | switch (tok) { |
|---|
| 2273 | n/a | case XML_TOK_TRAILING_CR: |
|---|
| 2274 | n/a | if (haveMore) { |
|---|
| 2275 | n/a | *nextPtr = s; |
|---|
| 2276 | n/a | return XML_ERROR_NONE; |
|---|
| 2277 | n/a | } |
|---|
| 2278 | n/a | *eventEndPP = end; |
|---|
| 2279 | n/a | if (characterDataHandler) { |
|---|
| 2280 | n/a | XML_Char c = 0xA; |
|---|
| 2281 | n/a | characterDataHandler(handlerArg, &c, 1); |
|---|
| 2282 | n/a | } |
|---|
| 2283 | n/a | else if (defaultHandler) |
|---|
| 2284 | n/a | reportDefault(parser, enc, s, end); |
|---|
| 2285 | n/a | /* We are at the end of the final buffer, should we check for |
|---|
| 2286 | n/a | XML_SUSPENDED, XML_FINISHED? |
|---|
| 2287 | n/a | */ |
|---|
| 2288 | n/a | if (startTagLevel == 0) |
|---|
| 2289 | n/a | return XML_ERROR_NO_ELEMENTS; |
|---|
| 2290 | n/a | if (tagLevel != startTagLevel) |
|---|
| 2291 | n/a | return XML_ERROR_ASYNC_ENTITY; |
|---|
| 2292 | n/a | *nextPtr = end; |
|---|
| 2293 | n/a | return XML_ERROR_NONE; |
|---|
| 2294 | n/a | case XML_TOK_NONE: |
|---|
| 2295 | n/a | if (haveMore) { |
|---|
| 2296 | n/a | *nextPtr = s; |
|---|
| 2297 | n/a | return XML_ERROR_NONE; |
|---|
| 2298 | n/a | } |
|---|
| 2299 | n/a | if (startTagLevel > 0) { |
|---|
| 2300 | n/a | if (tagLevel != startTagLevel) |
|---|
| 2301 | n/a | return XML_ERROR_ASYNC_ENTITY; |
|---|
| 2302 | n/a | *nextPtr = s; |
|---|
| 2303 | n/a | return XML_ERROR_NONE; |
|---|
| 2304 | n/a | } |
|---|
| 2305 | n/a | return XML_ERROR_NO_ELEMENTS; |
|---|
| 2306 | n/a | case XML_TOK_INVALID: |
|---|
| 2307 | n/a | *eventPP = next; |
|---|
| 2308 | n/a | return XML_ERROR_INVALID_TOKEN; |
|---|
| 2309 | n/a | case XML_TOK_PARTIAL: |
|---|
| 2310 | n/a | if (haveMore) { |
|---|
| 2311 | n/a | *nextPtr = s; |
|---|
| 2312 | n/a | return XML_ERROR_NONE; |
|---|
| 2313 | n/a | } |
|---|
| 2314 | n/a | return XML_ERROR_UNCLOSED_TOKEN; |
|---|
| 2315 | n/a | case XML_TOK_PARTIAL_CHAR: |
|---|
| 2316 | n/a | if (haveMore) { |
|---|
| 2317 | n/a | *nextPtr = s; |
|---|
| 2318 | n/a | return XML_ERROR_NONE; |
|---|
| 2319 | n/a | } |
|---|
| 2320 | n/a | return XML_ERROR_PARTIAL_CHAR; |
|---|
| 2321 | n/a | case XML_TOK_ENTITY_REF: |
|---|
| 2322 | n/a | { |
|---|
| 2323 | n/a | const XML_Char *name; |
|---|
| 2324 | n/a | ENTITY *entity; |
|---|
| 2325 | n/a | XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc, |
|---|
| 2326 | n/a | s + enc->minBytesPerChar, |
|---|
| 2327 | n/a | next - enc->minBytesPerChar); |
|---|
| 2328 | n/a | if (ch) { |
|---|
| 2329 | n/a | if (characterDataHandler) |
|---|
| 2330 | n/a | characterDataHandler(handlerArg, &ch, 1); |
|---|
| 2331 | n/a | else if (defaultHandler) |
|---|
| 2332 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 2333 | n/a | break; |
|---|
| 2334 | n/a | } |
|---|
| 2335 | n/a | name = poolStoreString(&dtd->pool, enc, |
|---|
| 2336 | n/a | s + enc->minBytesPerChar, |
|---|
| 2337 | n/a | next - enc->minBytesPerChar); |
|---|
| 2338 | n/a | if (!name) |
|---|
| 2339 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2340 | n/a | entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0); |
|---|
| 2341 | n/a | poolDiscard(&dtd->pool); |
|---|
| 2342 | n/a | /* First, determine if a check for an existing declaration is needed; |
|---|
| 2343 | n/a | if yes, check that the entity exists, and that it is internal, |
|---|
| 2344 | n/a | otherwise call the skipped entity or default handler. |
|---|
| 2345 | n/a | */ |
|---|
| 2346 | n/a | if (!dtd->hasParamEntityRefs || dtd->standalone) { |
|---|
| 2347 | n/a | if (!entity) |
|---|
| 2348 | n/a | return XML_ERROR_UNDEFINED_ENTITY; |
|---|
| 2349 | n/a | else if (!entity->is_internal) |
|---|
| 2350 | n/a | return XML_ERROR_ENTITY_DECLARED_IN_PE; |
|---|
| 2351 | n/a | } |
|---|
| 2352 | n/a | else if (!entity) { |
|---|
| 2353 | n/a | if (skippedEntityHandler) |
|---|
| 2354 | n/a | skippedEntityHandler(handlerArg, name, 0); |
|---|
| 2355 | n/a | else if (defaultHandler) |
|---|
| 2356 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 2357 | n/a | break; |
|---|
| 2358 | n/a | } |
|---|
| 2359 | n/a | if (entity->open) |
|---|
| 2360 | n/a | return XML_ERROR_RECURSIVE_ENTITY_REF; |
|---|
| 2361 | n/a | if (entity->notation) |
|---|
| 2362 | n/a | return XML_ERROR_BINARY_ENTITY_REF; |
|---|
| 2363 | n/a | if (entity->textPtr) { |
|---|
| 2364 | n/a | enum XML_Error result; |
|---|
| 2365 | n/a | if (!defaultExpandInternalEntities) { |
|---|
| 2366 | n/a | if (skippedEntityHandler) |
|---|
| 2367 | n/a | skippedEntityHandler(handlerArg, entity->name, 0); |
|---|
| 2368 | n/a | else if (defaultHandler) |
|---|
| 2369 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 2370 | n/a | break; |
|---|
| 2371 | n/a | } |
|---|
| 2372 | n/a | result = processInternalEntity(parser, entity, XML_FALSE); |
|---|
| 2373 | n/a | if (result != XML_ERROR_NONE) |
|---|
| 2374 | n/a | return result; |
|---|
| 2375 | n/a | } |
|---|
| 2376 | n/a | else if (externalEntityRefHandler) { |
|---|
| 2377 | n/a | const XML_Char *context; |
|---|
| 2378 | n/a | entity->open = XML_TRUE; |
|---|
| 2379 | n/a | context = getContext(parser); |
|---|
| 2380 | n/a | entity->open = XML_FALSE; |
|---|
| 2381 | n/a | if (!context) |
|---|
| 2382 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2383 | n/a | if (!externalEntityRefHandler(externalEntityRefHandlerArg, |
|---|
| 2384 | n/a | context, |
|---|
| 2385 | n/a | entity->base, |
|---|
| 2386 | n/a | entity->systemId, |
|---|
| 2387 | n/a | entity->publicId)) |
|---|
| 2388 | n/a | return XML_ERROR_EXTERNAL_ENTITY_HANDLING; |
|---|
| 2389 | n/a | poolDiscard(&tempPool); |
|---|
| 2390 | n/a | } |
|---|
| 2391 | n/a | else if (defaultHandler) |
|---|
| 2392 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 2393 | n/a | break; |
|---|
| 2394 | n/a | } |
|---|
| 2395 | n/a | case XML_TOK_START_TAG_NO_ATTS: |
|---|
| 2396 | n/a | /* fall through */ |
|---|
| 2397 | n/a | case XML_TOK_START_TAG_WITH_ATTS: |
|---|
| 2398 | n/a | { |
|---|
| 2399 | n/a | TAG *tag; |
|---|
| 2400 | n/a | enum XML_Error result; |
|---|
| 2401 | n/a | XML_Char *toPtr; |
|---|
| 2402 | n/a | if (freeTagList) { |
|---|
| 2403 | n/a | tag = freeTagList; |
|---|
| 2404 | n/a | freeTagList = freeTagList->parent; |
|---|
| 2405 | n/a | } |
|---|
| 2406 | n/a | else { |
|---|
| 2407 | n/a | tag = (TAG *)MALLOC(sizeof(TAG)); |
|---|
| 2408 | n/a | if (!tag) |
|---|
| 2409 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2410 | n/a | tag->buf = (char *)MALLOC(INIT_TAG_BUF_SIZE); |
|---|
| 2411 | n/a | if (!tag->buf) { |
|---|
| 2412 | n/a | FREE(tag); |
|---|
| 2413 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2414 | n/a | } |
|---|
| 2415 | n/a | tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE; |
|---|
| 2416 | n/a | } |
|---|
| 2417 | n/a | tag->bindings = NULL; |
|---|
| 2418 | n/a | tag->parent = tagStack; |
|---|
| 2419 | n/a | tagStack = tag; |
|---|
| 2420 | n/a | tag->name.localPart = NULL; |
|---|
| 2421 | n/a | tag->name.prefix = NULL; |
|---|
| 2422 | n/a | tag->rawName = s + enc->minBytesPerChar; |
|---|
| 2423 | n/a | tag->rawNameLength = XmlNameLength(enc, tag->rawName); |
|---|
| 2424 | n/a | ++tagLevel; |
|---|
| 2425 | n/a | { |
|---|
| 2426 | n/a | const char *rawNameEnd = tag->rawName + tag->rawNameLength; |
|---|
| 2427 | n/a | const char *fromPtr = tag->rawName; |
|---|
| 2428 | n/a | toPtr = (XML_Char *)tag->buf; |
|---|
| 2429 | n/a | for (;;) { |
|---|
| 2430 | n/a | int bufSize; |
|---|
| 2431 | n/a | int convLen; |
|---|
| 2432 | n/a | XmlConvert(enc, |
|---|
| 2433 | n/a | &fromPtr, rawNameEnd, |
|---|
| 2434 | n/a | (ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1); |
|---|
| 2435 | n/a | convLen = (int)(toPtr - (XML_Char *)tag->buf); |
|---|
| 2436 | n/a | if (fromPtr == rawNameEnd) { |
|---|
| 2437 | n/a | tag->name.strLen = convLen; |
|---|
| 2438 | n/a | break; |
|---|
| 2439 | n/a | } |
|---|
| 2440 | n/a | bufSize = (int)(tag->bufEnd - tag->buf) << 1; |
|---|
| 2441 | n/a | { |
|---|
| 2442 | n/a | char *temp = (char *)REALLOC(tag->buf, bufSize); |
|---|
| 2443 | n/a | if (temp == NULL) |
|---|
| 2444 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2445 | n/a | tag->buf = temp; |
|---|
| 2446 | n/a | tag->bufEnd = temp + bufSize; |
|---|
| 2447 | n/a | toPtr = (XML_Char *)temp + convLen; |
|---|
| 2448 | n/a | } |
|---|
| 2449 | n/a | } |
|---|
| 2450 | n/a | } |
|---|
| 2451 | n/a | tag->name.str = (XML_Char *)tag->buf; |
|---|
| 2452 | n/a | *toPtr = XML_T('\0'); |
|---|
| 2453 | n/a | result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings)); |
|---|
| 2454 | n/a | if (result) |
|---|
| 2455 | n/a | return result; |
|---|
| 2456 | n/a | if (startElementHandler) |
|---|
| 2457 | n/a | startElementHandler(handlerArg, tag->name.str, |
|---|
| 2458 | n/a | (const XML_Char **)atts); |
|---|
| 2459 | n/a | else if (defaultHandler) |
|---|
| 2460 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 2461 | n/a | poolClear(&tempPool); |
|---|
| 2462 | n/a | break; |
|---|
| 2463 | n/a | } |
|---|
| 2464 | n/a | case XML_TOK_EMPTY_ELEMENT_NO_ATTS: |
|---|
| 2465 | n/a | /* fall through */ |
|---|
| 2466 | n/a | case XML_TOK_EMPTY_ELEMENT_WITH_ATTS: |
|---|
| 2467 | n/a | { |
|---|
| 2468 | n/a | const char *rawName = s + enc->minBytesPerChar; |
|---|
| 2469 | n/a | enum XML_Error result; |
|---|
| 2470 | n/a | BINDING *bindings = NULL; |
|---|
| 2471 | n/a | XML_Bool noElmHandlers = XML_TRUE; |
|---|
| 2472 | n/a | TAG_NAME name; |
|---|
| 2473 | n/a | name.str = poolStoreString(&tempPool, enc, rawName, |
|---|
| 2474 | n/a | rawName + XmlNameLength(enc, rawName)); |
|---|
| 2475 | n/a | if (!name.str) |
|---|
| 2476 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2477 | n/a | poolFinish(&tempPool); |
|---|
| 2478 | n/a | result = storeAtts(parser, enc, s, &name, &bindings); |
|---|
| 2479 | n/a | if (result) |
|---|
| 2480 | n/a | return result; |
|---|
| 2481 | n/a | poolFinish(&tempPool); |
|---|
| 2482 | n/a | if (startElementHandler) { |
|---|
| 2483 | n/a | startElementHandler(handlerArg, name.str, (const XML_Char **)atts); |
|---|
| 2484 | n/a | noElmHandlers = XML_FALSE; |
|---|
| 2485 | n/a | } |
|---|
| 2486 | n/a | if (endElementHandler) { |
|---|
| 2487 | n/a | if (startElementHandler) |
|---|
| 2488 | n/a | *eventPP = *eventEndPP; |
|---|
| 2489 | n/a | endElementHandler(handlerArg, name.str); |
|---|
| 2490 | n/a | noElmHandlers = XML_FALSE; |
|---|
| 2491 | n/a | } |
|---|
| 2492 | n/a | if (noElmHandlers && defaultHandler) |
|---|
| 2493 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 2494 | n/a | poolClear(&tempPool); |
|---|
| 2495 | n/a | while (bindings) { |
|---|
| 2496 | n/a | BINDING *b = bindings; |
|---|
| 2497 | n/a | if (endNamespaceDeclHandler) |
|---|
| 2498 | n/a | endNamespaceDeclHandler(handlerArg, b->prefix->name); |
|---|
| 2499 | n/a | bindings = bindings->nextTagBinding; |
|---|
| 2500 | n/a | b->nextTagBinding = freeBindingList; |
|---|
| 2501 | n/a | freeBindingList = b; |
|---|
| 2502 | n/a | b->prefix->binding = b->prevPrefixBinding; |
|---|
| 2503 | n/a | } |
|---|
| 2504 | n/a | } |
|---|
| 2505 | n/a | if (tagLevel == 0) |
|---|
| 2506 | n/a | return epilogProcessor(parser, next, end, nextPtr); |
|---|
| 2507 | n/a | break; |
|---|
| 2508 | n/a | case XML_TOK_END_TAG: |
|---|
| 2509 | n/a | if (tagLevel == startTagLevel) |
|---|
| 2510 | n/a | return XML_ERROR_ASYNC_ENTITY; |
|---|
| 2511 | n/a | else { |
|---|
| 2512 | n/a | int len; |
|---|
| 2513 | n/a | const char *rawName; |
|---|
| 2514 | n/a | TAG *tag = tagStack; |
|---|
| 2515 | n/a | tagStack = tag->parent; |
|---|
| 2516 | n/a | tag->parent = freeTagList; |
|---|
| 2517 | n/a | freeTagList = tag; |
|---|
| 2518 | n/a | rawName = s + enc->minBytesPerChar*2; |
|---|
| 2519 | n/a | len = XmlNameLength(enc, rawName); |
|---|
| 2520 | n/a | if (len != tag->rawNameLength |
|---|
| 2521 | n/a | || memcmp(tag->rawName, rawName, len) != 0) { |
|---|
| 2522 | n/a | *eventPP = rawName; |
|---|
| 2523 | n/a | return XML_ERROR_TAG_MISMATCH; |
|---|
| 2524 | n/a | } |
|---|
| 2525 | n/a | --tagLevel; |
|---|
| 2526 | n/a | if (endElementHandler) { |
|---|
| 2527 | n/a | const XML_Char *localPart; |
|---|
| 2528 | n/a | const XML_Char *prefix; |
|---|
| 2529 | n/a | XML_Char *uri; |
|---|
| 2530 | n/a | localPart = tag->name.localPart; |
|---|
| 2531 | n/a | if (ns && localPart) { |
|---|
| 2532 | n/a | /* localPart and prefix may have been overwritten in |
|---|
| 2533 | n/a | tag->name.str, since this points to the binding->uri |
|---|
| 2534 | n/a | buffer which gets re-used; so we have to add them again |
|---|
| 2535 | n/a | */ |
|---|
| 2536 | n/a | uri = (XML_Char *)tag->name.str + tag->name.uriLen; |
|---|
| 2537 | n/a | /* don't need to check for space - already done in storeAtts() */ |
|---|
| 2538 | n/a | while (*localPart) *uri++ = *localPart++; |
|---|
| 2539 | n/a | prefix = (XML_Char *)tag->name.prefix; |
|---|
| 2540 | n/a | if (ns_triplets && prefix) { |
|---|
| 2541 | n/a | *uri++ = namespaceSeparator; |
|---|
| 2542 | n/a | while (*prefix) *uri++ = *prefix++; |
|---|
| 2543 | n/a | } |
|---|
| 2544 | n/a | *uri = XML_T('\0'); |
|---|
| 2545 | n/a | } |
|---|
| 2546 | n/a | endElementHandler(handlerArg, tag->name.str); |
|---|
| 2547 | n/a | } |
|---|
| 2548 | n/a | else if (defaultHandler) |
|---|
| 2549 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 2550 | n/a | while (tag->bindings) { |
|---|
| 2551 | n/a | BINDING *b = tag->bindings; |
|---|
| 2552 | n/a | if (endNamespaceDeclHandler) |
|---|
| 2553 | n/a | endNamespaceDeclHandler(handlerArg, b->prefix->name); |
|---|
| 2554 | n/a | tag->bindings = tag->bindings->nextTagBinding; |
|---|
| 2555 | n/a | b->nextTagBinding = freeBindingList; |
|---|
| 2556 | n/a | freeBindingList = b; |
|---|
| 2557 | n/a | b->prefix->binding = b->prevPrefixBinding; |
|---|
| 2558 | n/a | } |
|---|
| 2559 | n/a | if (tagLevel == 0) |
|---|
| 2560 | n/a | return epilogProcessor(parser, next, end, nextPtr); |
|---|
| 2561 | n/a | } |
|---|
| 2562 | n/a | break; |
|---|
| 2563 | n/a | case XML_TOK_CHAR_REF: |
|---|
| 2564 | n/a | { |
|---|
| 2565 | n/a | int n = XmlCharRefNumber(enc, s); |
|---|
| 2566 | n/a | if (n < 0) |
|---|
| 2567 | n/a | return XML_ERROR_BAD_CHAR_REF; |
|---|
| 2568 | n/a | if (characterDataHandler) { |
|---|
| 2569 | n/a | XML_Char buf[XML_ENCODE_MAX]; |
|---|
| 2570 | n/a | characterDataHandler(handlerArg, buf, XmlEncode(n, (ICHAR *)buf)); |
|---|
| 2571 | n/a | } |
|---|
| 2572 | n/a | else if (defaultHandler) |
|---|
| 2573 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 2574 | n/a | } |
|---|
| 2575 | n/a | break; |
|---|
| 2576 | n/a | case XML_TOK_XML_DECL: |
|---|
| 2577 | n/a | return XML_ERROR_MISPLACED_XML_PI; |
|---|
| 2578 | n/a | case XML_TOK_DATA_NEWLINE: |
|---|
| 2579 | n/a | if (characterDataHandler) { |
|---|
| 2580 | n/a | XML_Char c = 0xA; |
|---|
| 2581 | n/a | characterDataHandler(handlerArg, &c, 1); |
|---|
| 2582 | n/a | } |
|---|
| 2583 | n/a | else if (defaultHandler) |
|---|
| 2584 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 2585 | n/a | break; |
|---|
| 2586 | n/a | case XML_TOK_CDATA_SECT_OPEN: |
|---|
| 2587 | n/a | { |
|---|
| 2588 | n/a | enum XML_Error result; |
|---|
| 2589 | n/a | if (startCdataSectionHandler) |
|---|
| 2590 | n/a | startCdataSectionHandler(handlerArg); |
|---|
| 2591 | n/a | #if 0 |
|---|
| 2592 | n/a | /* Suppose you doing a transformation on a document that involves |
|---|
| 2593 | n/a | changing only the character data. You set up a defaultHandler |
|---|
| 2594 | n/a | and a characterDataHandler. The defaultHandler simply copies |
|---|
| 2595 | n/a | characters through. The characterDataHandler does the |
|---|
| 2596 | n/a | transformation and writes the characters out escaping them as |
|---|
| 2597 | n/a | necessary. This case will fail to work if we leave out the |
|---|
| 2598 | n/a | following two lines (because & and < inside CDATA sections will |
|---|
| 2599 | n/a | be incorrectly escaped). |
|---|
| 2600 | n/a | |
|---|
| 2601 | n/a | However, now we have a start/endCdataSectionHandler, so it seems |
|---|
| 2602 | n/a | easier to let the user deal with this. |
|---|
| 2603 | n/a | */ |
|---|
| 2604 | n/a | else if (characterDataHandler) |
|---|
| 2605 | n/a | characterDataHandler(handlerArg, dataBuf, 0); |
|---|
| 2606 | n/a | #endif |
|---|
| 2607 | n/a | else if (defaultHandler) |
|---|
| 2608 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 2609 | n/a | result = doCdataSection(parser, enc, &next, end, nextPtr, haveMore); |
|---|
| 2610 | n/a | if (result != XML_ERROR_NONE) |
|---|
| 2611 | n/a | return result; |
|---|
| 2612 | n/a | else if (!next) { |
|---|
| 2613 | n/a | processor = cdataSectionProcessor; |
|---|
| 2614 | n/a | return result; |
|---|
| 2615 | n/a | } |
|---|
| 2616 | n/a | } |
|---|
| 2617 | n/a | break; |
|---|
| 2618 | n/a | case XML_TOK_TRAILING_RSQB: |
|---|
| 2619 | n/a | if (haveMore) { |
|---|
| 2620 | n/a | *nextPtr = s; |
|---|
| 2621 | n/a | return XML_ERROR_NONE; |
|---|
| 2622 | n/a | } |
|---|
| 2623 | n/a | if (characterDataHandler) { |
|---|
| 2624 | n/a | if (MUST_CONVERT(enc, s)) { |
|---|
| 2625 | n/a | ICHAR *dataPtr = (ICHAR *)dataBuf; |
|---|
| 2626 | n/a | XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); |
|---|
| 2627 | n/a | characterDataHandler(handlerArg, dataBuf, |
|---|
| 2628 | n/a | (int)(dataPtr - (ICHAR *)dataBuf)); |
|---|
| 2629 | n/a | } |
|---|
| 2630 | n/a | else |
|---|
| 2631 | n/a | characterDataHandler(handlerArg, |
|---|
| 2632 | n/a | (XML_Char *)s, |
|---|
| 2633 | n/a | (int)((XML_Char *)end - (XML_Char *)s)); |
|---|
| 2634 | n/a | } |
|---|
| 2635 | n/a | else if (defaultHandler) |
|---|
| 2636 | n/a | reportDefault(parser, enc, s, end); |
|---|
| 2637 | n/a | /* We are at the end of the final buffer, should we check for |
|---|
| 2638 | n/a | XML_SUSPENDED, XML_FINISHED? |
|---|
| 2639 | n/a | */ |
|---|
| 2640 | n/a | if (startTagLevel == 0) { |
|---|
| 2641 | n/a | *eventPP = end; |
|---|
| 2642 | n/a | return XML_ERROR_NO_ELEMENTS; |
|---|
| 2643 | n/a | } |
|---|
| 2644 | n/a | if (tagLevel != startTagLevel) { |
|---|
| 2645 | n/a | *eventPP = end; |
|---|
| 2646 | n/a | return XML_ERROR_ASYNC_ENTITY; |
|---|
| 2647 | n/a | } |
|---|
| 2648 | n/a | *nextPtr = end; |
|---|
| 2649 | n/a | return XML_ERROR_NONE; |
|---|
| 2650 | n/a | case XML_TOK_DATA_CHARS: |
|---|
| 2651 | n/a | { |
|---|
| 2652 | n/a | XML_CharacterDataHandler charDataHandler = characterDataHandler; |
|---|
| 2653 | n/a | if (charDataHandler) { |
|---|
| 2654 | n/a | if (MUST_CONVERT(enc, s)) { |
|---|
| 2655 | n/a | for (;;) { |
|---|
| 2656 | n/a | ICHAR *dataPtr = (ICHAR *)dataBuf; |
|---|
| 2657 | n/a | XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); |
|---|
| 2658 | n/a | *eventEndPP = s; |
|---|
| 2659 | n/a | charDataHandler(handlerArg, dataBuf, |
|---|
| 2660 | n/a | (int)(dataPtr - (ICHAR *)dataBuf)); |
|---|
| 2661 | n/a | if (s == next) |
|---|
| 2662 | n/a | break; |
|---|
| 2663 | n/a | *eventPP = s; |
|---|
| 2664 | n/a | } |
|---|
| 2665 | n/a | } |
|---|
| 2666 | n/a | else |
|---|
| 2667 | n/a | charDataHandler(handlerArg, |
|---|
| 2668 | n/a | (XML_Char *)s, |
|---|
| 2669 | n/a | (int)((XML_Char *)next - (XML_Char *)s)); |
|---|
| 2670 | n/a | } |
|---|
| 2671 | n/a | else if (defaultHandler) |
|---|
| 2672 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 2673 | n/a | } |
|---|
| 2674 | n/a | break; |
|---|
| 2675 | n/a | case XML_TOK_PI: |
|---|
| 2676 | n/a | if (!reportProcessingInstruction(parser, enc, s, next)) |
|---|
| 2677 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2678 | n/a | break; |
|---|
| 2679 | n/a | case XML_TOK_COMMENT: |
|---|
| 2680 | n/a | if (!reportComment(parser, enc, s, next)) |
|---|
| 2681 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2682 | n/a | break; |
|---|
| 2683 | n/a | default: |
|---|
| 2684 | n/a | if (defaultHandler) |
|---|
| 2685 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 2686 | n/a | break; |
|---|
| 2687 | n/a | } |
|---|
| 2688 | n/a | *eventPP = s = next; |
|---|
| 2689 | n/a | switch (ps_parsing) { |
|---|
| 2690 | n/a | case XML_SUSPENDED: |
|---|
| 2691 | n/a | *nextPtr = next; |
|---|
| 2692 | n/a | return XML_ERROR_NONE; |
|---|
| 2693 | n/a | case XML_FINISHED: |
|---|
| 2694 | n/a | return XML_ERROR_ABORTED; |
|---|
| 2695 | n/a | default: ; |
|---|
| 2696 | n/a | } |
|---|
| 2697 | n/a | } |
|---|
| 2698 | n/a | /* not reached */ |
|---|
| 2699 | n/a | } |
|---|
| 2700 | n/a | |
|---|
| 2701 | n/a | /* Precondition: all arguments must be non-NULL; |
|---|
| 2702 | n/a | Purpose: |
|---|
| 2703 | n/a | - normalize attributes |
|---|
| 2704 | n/a | - check attributes for well-formedness |
|---|
| 2705 | n/a | - generate namespace aware attribute names (URI, prefix) |
|---|
| 2706 | n/a | - build list of attributes for startElementHandler |
|---|
| 2707 | n/a | - default attributes |
|---|
| 2708 | n/a | - process namespace declarations (check and report them) |
|---|
| 2709 | n/a | - generate namespace aware element name (URI, prefix) |
|---|
| 2710 | n/a | */ |
|---|
| 2711 | n/a | static enum XML_Error |
|---|
| 2712 | n/a | storeAtts(XML_Parser parser, const ENCODING *enc, |
|---|
| 2713 | n/a | const char *attStr, TAG_NAME *tagNamePtr, |
|---|
| 2714 | n/a | BINDING **bindingsPtr) |
|---|
| 2715 | n/a | { |
|---|
| 2716 | n/a | DTD * const dtd = _dtd; /* save one level of indirection */ |
|---|
| 2717 | n/a | ELEMENT_TYPE *elementType; |
|---|
| 2718 | n/a | int nDefaultAtts; |
|---|
| 2719 | n/a | const XML_Char **appAtts; /* the attribute list for the application */ |
|---|
| 2720 | n/a | int attIndex = 0; |
|---|
| 2721 | n/a | int prefixLen; |
|---|
| 2722 | n/a | int i; |
|---|
| 2723 | n/a | int n; |
|---|
| 2724 | n/a | XML_Char *uri; |
|---|
| 2725 | n/a | int nPrefixes = 0; |
|---|
| 2726 | n/a | BINDING *binding; |
|---|
| 2727 | n/a | const XML_Char *localPart; |
|---|
| 2728 | n/a | |
|---|
| 2729 | n/a | /* lookup the element type name */ |
|---|
| 2730 | n/a | elementType = (ELEMENT_TYPE *)lookup(parser, &dtd->elementTypes, tagNamePtr->str,0); |
|---|
| 2731 | n/a | if (!elementType) { |
|---|
| 2732 | n/a | const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str); |
|---|
| 2733 | n/a | if (!name) |
|---|
| 2734 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2735 | n/a | elementType = (ELEMENT_TYPE *)lookup(parser, &dtd->elementTypes, name, |
|---|
| 2736 | n/a | sizeof(ELEMENT_TYPE)); |
|---|
| 2737 | n/a | if (!elementType) |
|---|
| 2738 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2739 | n/a | if (ns && !setElementTypePrefix(parser, elementType)) |
|---|
| 2740 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2741 | n/a | } |
|---|
| 2742 | n/a | nDefaultAtts = elementType->nDefaultAtts; |
|---|
| 2743 | n/a | |
|---|
| 2744 | n/a | /* get the attributes from the tokenizer */ |
|---|
| 2745 | n/a | n = XmlGetAttributes(enc, attStr, attsSize, atts); |
|---|
| 2746 | n/a | if (n + nDefaultAtts > attsSize) { |
|---|
| 2747 | n/a | int oldAttsSize = attsSize; |
|---|
| 2748 | n/a | ATTRIBUTE *temp; |
|---|
| 2749 | n/a | #ifdef XML_ATTR_INFO |
|---|
| 2750 | n/a | XML_AttrInfo *temp2; |
|---|
| 2751 | n/a | #endif |
|---|
| 2752 | n/a | attsSize = n + nDefaultAtts + INIT_ATTS_SIZE; |
|---|
| 2753 | n/a | temp = (ATTRIBUTE *)REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE)); |
|---|
| 2754 | n/a | if (temp == NULL) |
|---|
| 2755 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2756 | n/a | atts = temp; |
|---|
| 2757 | n/a | #ifdef XML_ATTR_INFO |
|---|
| 2758 | n/a | temp2 = (XML_AttrInfo *)REALLOC((void *)attInfo, attsSize * sizeof(XML_AttrInfo)); |
|---|
| 2759 | n/a | if (temp2 == NULL) |
|---|
| 2760 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2761 | n/a | attInfo = temp2; |
|---|
| 2762 | n/a | #endif |
|---|
| 2763 | n/a | if (n > oldAttsSize) |
|---|
| 2764 | n/a | XmlGetAttributes(enc, attStr, n, atts); |
|---|
| 2765 | n/a | } |
|---|
| 2766 | n/a | |
|---|
| 2767 | n/a | appAtts = (const XML_Char **)atts; |
|---|
| 2768 | n/a | for (i = 0; i < n; i++) { |
|---|
| 2769 | n/a | ATTRIBUTE *currAtt = &atts[i]; |
|---|
| 2770 | n/a | #ifdef XML_ATTR_INFO |
|---|
| 2771 | n/a | XML_AttrInfo *currAttInfo = &attInfo[i]; |
|---|
| 2772 | n/a | #endif |
|---|
| 2773 | n/a | /* add the name and value to the attribute list */ |
|---|
| 2774 | n/a | ATTRIBUTE_ID *attId = getAttributeId(parser, enc, currAtt->name, |
|---|
| 2775 | n/a | currAtt->name |
|---|
| 2776 | n/a | + XmlNameLength(enc, currAtt->name)); |
|---|
| 2777 | n/a | if (!attId) |
|---|
| 2778 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2779 | n/a | #ifdef XML_ATTR_INFO |
|---|
| 2780 | n/a | currAttInfo->nameStart = parseEndByteIndex - (parseEndPtr - currAtt->name); |
|---|
| 2781 | n/a | currAttInfo->nameEnd = currAttInfo->nameStart + |
|---|
| 2782 | n/a | XmlNameLength(enc, currAtt->name); |
|---|
| 2783 | n/a | currAttInfo->valueStart = parseEndByteIndex - |
|---|
| 2784 | n/a | (parseEndPtr - currAtt->valuePtr); |
|---|
| 2785 | n/a | currAttInfo->valueEnd = parseEndByteIndex - (parseEndPtr - currAtt->valueEnd); |
|---|
| 2786 | n/a | #endif |
|---|
| 2787 | n/a | /* Detect duplicate attributes by their QNames. This does not work when |
|---|
| 2788 | n/a | namespace processing is turned on and different prefixes for the same |
|---|
| 2789 | n/a | namespace are used. For this case we have a check further down. |
|---|
| 2790 | n/a | */ |
|---|
| 2791 | n/a | if ((attId->name)[-1]) { |
|---|
| 2792 | n/a | if (enc == encoding) |
|---|
| 2793 | n/a | eventPtr = atts[i].name; |
|---|
| 2794 | n/a | return XML_ERROR_DUPLICATE_ATTRIBUTE; |
|---|
| 2795 | n/a | } |
|---|
| 2796 | n/a | (attId->name)[-1] = 1; |
|---|
| 2797 | n/a | appAtts[attIndex++] = attId->name; |
|---|
| 2798 | n/a | if (!atts[i].normalized) { |
|---|
| 2799 | n/a | enum XML_Error result; |
|---|
| 2800 | n/a | XML_Bool isCdata = XML_TRUE; |
|---|
| 2801 | n/a | |
|---|
| 2802 | n/a | /* figure out whether declared as other than CDATA */ |
|---|
| 2803 | n/a | if (attId->maybeTokenized) { |
|---|
| 2804 | n/a | int j; |
|---|
| 2805 | n/a | for (j = 0; j < nDefaultAtts; j++) { |
|---|
| 2806 | n/a | if (attId == elementType->defaultAtts[j].id) { |
|---|
| 2807 | n/a | isCdata = elementType->defaultAtts[j].isCdata; |
|---|
| 2808 | n/a | break; |
|---|
| 2809 | n/a | } |
|---|
| 2810 | n/a | } |
|---|
| 2811 | n/a | } |
|---|
| 2812 | n/a | |
|---|
| 2813 | n/a | /* normalize the attribute value */ |
|---|
| 2814 | n/a | result = storeAttributeValue(parser, enc, isCdata, |
|---|
| 2815 | n/a | atts[i].valuePtr, atts[i].valueEnd, |
|---|
| 2816 | n/a | &tempPool); |
|---|
| 2817 | n/a | if (result) |
|---|
| 2818 | n/a | return result; |
|---|
| 2819 | n/a | appAtts[attIndex] = poolStart(&tempPool); |
|---|
| 2820 | n/a | poolFinish(&tempPool); |
|---|
| 2821 | n/a | } |
|---|
| 2822 | n/a | else { |
|---|
| 2823 | n/a | /* the value did not need normalizing */ |
|---|
| 2824 | n/a | appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr, |
|---|
| 2825 | n/a | atts[i].valueEnd); |
|---|
| 2826 | n/a | if (appAtts[attIndex] == 0) |
|---|
| 2827 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2828 | n/a | poolFinish(&tempPool); |
|---|
| 2829 | n/a | } |
|---|
| 2830 | n/a | /* handle prefixed attribute names */ |
|---|
| 2831 | n/a | if (attId->prefix) { |
|---|
| 2832 | n/a | if (attId->xmlns) { |
|---|
| 2833 | n/a | /* deal with namespace declarations here */ |
|---|
| 2834 | n/a | enum XML_Error result = addBinding(parser, attId->prefix, attId, |
|---|
| 2835 | n/a | appAtts[attIndex], bindingsPtr); |
|---|
| 2836 | n/a | if (result) |
|---|
| 2837 | n/a | return result; |
|---|
| 2838 | n/a | --attIndex; |
|---|
| 2839 | n/a | } |
|---|
| 2840 | n/a | else { |
|---|
| 2841 | n/a | /* deal with other prefixed names later */ |
|---|
| 2842 | n/a | attIndex++; |
|---|
| 2843 | n/a | nPrefixes++; |
|---|
| 2844 | n/a | (attId->name)[-1] = 2; |
|---|
| 2845 | n/a | } |
|---|
| 2846 | n/a | } |
|---|
| 2847 | n/a | else |
|---|
| 2848 | n/a | attIndex++; |
|---|
| 2849 | n/a | } |
|---|
| 2850 | n/a | |
|---|
| 2851 | n/a | /* set-up for XML_GetSpecifiedAttributeCount and XML_GetIdAttributeIndex */ |
|---|
| 2852 | n/a | nSpecifiedAtts = attIndex; |
|---|
| 2853 | n/a | if (elementType->idAtt && (elementType->idAtt->name)[-1]) { |
|---|
| 2854 | n/a | for (i = 0; i < attIndex; i += 2) |
|---|
| 2855 | n/a | if (appAtts[i] == elementType->idAtt->name) { |
|---|
| 2856 | n/a | idAttIndex = i; |
|---|
| 2857 | n/a | break; |
|---|
| 2858 | n/a | } |
|---|
| 2859 | n/a | } |
|---|
| 2860 | n/a | else |
|---|
| 2861 | n/a | idAttIndex = -1; |
|---|
| 2862 | n/a | |
|---|
| 2863 | n/a | /* do attribute defaulting */ |
|---|
| 2864 | n/a | for (i = 0; i < nDefaultAtts; i++) { |
|---|
| 2865 | n/a | const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + i; |
|---|
| 2866 | n/a | if (!(da->id->name)[-1] && da->value) { |
|---|
| 2867 | n/a | if (da->id->prefix) { |
|---|
| 2868 | n/a | if (da->id->xmlns) { |
|---|
| 2869 | n/a | enum XML_Error result = addBinding(parser, da->id->prefix, da->id, |
|---|
| 2870 | n/a | da->value, bindingsPtr); |
|---|
| 2871 | n/a | if (result) |
|---|
| 2872 | n/a | return result; |
|---|
| 2873 | n/a | } |
|---|
| 2874 | n/a | else { |
|---|
| 2875 | n/a | (da->id->name)[-1] = 2; |
|---|
| 2876 | n/a | nPrefixes++; |
|---|
| 2877 | n/a | appAtts[attIndex++] = da->id->name; |
|---|
| 2878 | n/a | appAtts[attIndex++] = da->value; |
|---|
| 2879 | n/a | } |
|---|
| 2880 | n/a | } |
|---|
| 2881 | n/a | else { |
|---|
| 2882 | n/a | (da->id->name)[-1] = 1; |
|---|
| 2883 | n/a | appAtts[attIndex++] = da->id->name; |
|---|
| 2884 | n/a | appAtts[attIndex++] = da->value; |
|---|
| 2885 | n/a | } |
|---|
| 2886 | n/a | } |
|---|
| 2887 | n/a | } |
|---|
| 2888 | n/a | appAtts[attIndex] = 0; |
|---|
| 2889 | n/a | |
|---|
| 2890 | n/a | /* expand prefixed attribute names, check for duplicates, |
|---|
| 2891 | n/a | and clear flags that say whether attributes were specified */ |
|---|
| 2892 | n/a | i = 0; |
|---|
| 2893 | n/a | if (nPrefixes) { |
|---|
| 2894 | n/a | int j; /* hash table index */ |
|---|
| 2895 | n/a | unsigned long version = nsAttsVersion; |
|---|
| 2896 | n/a | int nsAttsSize = (int)1 << nsAttsPower; |
|---|
| 2897 | n/a | /* size of hash table must be at least 2 * (# of prefixed attributes) */ |
|---|
| 2898 | n/a | if ((nPrefixes << 1) >> nsAttsPower) { /* true for nsAttsPower = 0 */ |
|---|
| 2899 | n/a | NS_ATT *temp; |
|---|
| 2900 | n/a | /* hash table size must also be a power of 2 and >= 8 */ |
|---|
| 2901 | n/a | while (nPrefixes >> nsAttsPower++); |
|---|
| 2902 | n/a | if (nsAttsPower < 3) |
|---|
| 2903 | n/a | nsAttsPower = 3; |
|---|
| 2904 | n/a | nsAttsSize = (int)1 << nsAttsPower; |
|---|
| 2905 | n/a | temp = (NS_ATT *)REALLOC(nsAtts, nsAttsSize * sizeof(NS_ATT)); |
|---|
| 2906 | n/a | if (!temp) |
|---|
| 2907 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2908 | n/a | nsAtts = temp; |
|---|
| 2909 | n/a | version = 0; /* force re-initialization of nsAtts hash table */ |
|---|
| 2910 | n/a | } |
|---|
| 2911 | n/a | /* using a version flag saves us from initializing nsAtts every time */ |
|---|
| 2912 | n/a | if (!version) { /* initialize version flags when version wraps around */ |
|---|
| 2913 | n/a | version = INIT_ATTS_VERSION; |
|---|
| 2914 | n/a | for (j = nsAttsSize; j != 0; ) |
|---|
| 2915 | n/a | nsAtts[--j].version = version; |
|---|
| 2916 | n/a | } |
|---|
| 2917 | n/a | nsAttsVersion = --version; |
|---|
| 2918 | n/a | |
|---|
| 2919 | n/a | /* expand prefixed names and check for duplicates */ |
|---|
| 2920 | n/a | for (; i < attIndex; i += 2) { |
|---|
| 2921 | n/a | const XML_Char *s = appAtts[i]; |
|---|
| 2922 | n/a | if (s[-1] == 2) { /* prefixed */ |
|---|
| 2923 | n/a | ATTRIBUTE_ID *id; |
|---|
| 2924 | n/a | const BINDING *b; |
|---|
| 2925 | n/a | unsigned long uriHash = hash_secret_salt; |
|---|
| 2926 | n/a | ((XML_Char *)s)[-1] = 0; /* clear flag */ |
|---|
| 2927 | n/a | id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, s, 0); |
|---|
| 2928 | n/a | if (!id || !id->prefix) |
|---|
| 2929 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2930 | n/a | b = id->prefix->binding; |
|---|
| 2931 | n/a | if (!b) |
|---|
| 2932 | n/a | return XML_ERROR_UNBOUND_PREFIX; |
|---|
| 2933 | n/a | |
|---|
| 2934 | n/a | /* as we expand the name we also calculate its hash value */ |
|---|
| 2935 | n/a | for (j = 0; j < b->uriLen; j++) { |
|---|
| 2936 | n/a | const XML_Char c = b->uri[j]; |
|---|
| 2937 | n/a | if (!poolAppendChar(&tempPool, c)) |
|---|
| 2938 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2939 | n/a | uriHash = CHAR_HASH(uriHash, c); |
|---|
| 2940 | n/a | } |
|---|
| 2941 | n/a | while (*s++ != XML_T(ASCII_COLON)) |
|---|
| 2942 | n/a | ; |
|---|
| 2943 | n/a | do { /* copies null terminator */ |
|---|
| 2944 | n/a | const XML_Char c = *s; |
|---|
| 2945 | n/a | if (!poolAppendChar(&tempPool, *s)) |
|---|
| 2946 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2947 | n/a | uriHash = CHAR_HASH(uriHash, c); |
|---|
| 2948 | n/a | } while (*s++); |
|---|
| 2949 | n/a | |
|---|
| 2950 | n/a | { /* Check hash table for duplicate of expanded name (uriName). |
|---|
| 2951 | n/a | Derived from code in lookup(parser, HASH_TABLE *table, ...). |
|---|
| 2952 | n/a | */ |
|---|
| 2953 | n/a | unsigned char step = 0; |
|---|
| 2954 | n/a | unsigned long mask = nsAttsSize - 1; |
|---|
| 2955 | n/a | j = uriHash & mask; /* index into hash table */ |
|---|
| 2956 | n/a | while (nsAtts[j].version == version) { |
|---|
| 2957 | n/a | /* for speed we compare stored hash values first */ |
|---|
| 2958 | n/a | if (uriHash == nsAtts[j].hash) { |
|---|
| 2959 | n/a | const XML_Char *s1 = poolStart(&tempPool); |
|---|
| 2960 | n/a | const XML_Char *s2 = nsAtts[j].uriName; |
|---|
| 2961 | n/a | /* s1 is null terminated, but not s2 */ |
|---|
| 2962 | n/a | for (; *s1 == *s2 && *s1 != 0; s1++, s2++); |
|---|
| 2963 | n/a | if (*s1 == 0) |
|---|
| 2964 | n/a | return XML_ERROR_DUPLICATE_ATTRIBUTE; |
|---|
| 2965 | n/a | } |
|---|
| 2966 | n/a | if (!step) |
|---|
| 2967 | n/a | step = PROBE_STEP(uriHash, mask, nsAttsPower); |
|---|
| 2968 | n/a | j < step ? (j += nsAttsSize - step) : (j -= step); |
|---|
| 2969 | n/a | } |
|---|
| 2970 | n/a | } |
|---|
| 2971 | n/a | |
|---|
| 2972 | n/a | if (ns_triplets) { /* append namespace separator and prefix */ |
|---|
| 2973 | n/a | tempPool.ptr[-1] = namespaceSeparator; |
|---|
| 2974 | n/a | s = b->prefix->name; |
|---|
| 2975 | n/a | do { |
|---|
| 2976 | n/a | if (!poolAppendChar(&tempPool, *s)) |
|---|
| 2977 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 2978 | n/a | } while (*s++); |
|---|
| 2979 | n/a | } |
|---|
| 2980 | n/a | |
|---|
| 2981 | n/a | /* store expanded name in attribute list */ |
|---|
| 2982 | n/a | s = poolStart(&tempPool); |
|---|
| 2983 | n/a | poolFinish(&tempPool); |
|---|
| 2984 | n/a | appAtts[i] = s; |
|---|
| 2985 | n/a | |
|---|
| 2986 | n/a | /* fill empty slot with new version, uriName and hash value */ |
|---|
| 2987 | n/a | nsAtts[j].version = version; |
|---|
| 2988 | n/a | nsAtts[j].hash = uriHash; |
|---|
| 2989 | n/a | nsAtts[j].uriName = s; |
|---|
| 2990 | n/a | |
|---|
| 2991 | n/a | if (!--nPrefixes) { |
|---|
| 2992 | n/a | i += 2; |
|---|
| 2993 | n/a | break; |
|---|
| 2994 | n/a | } |
|---|
| 2995 | n/a | } |
|---|
| 2996 | n/a | else /* not prefixed */ |
|---|
| 2997 | n/a | ((XML_Char *)s)[-1] = 0; /* clear flag */ |
|---|
| 2998 | n/a | } |
|---|
| 2999 | n/a | } |
|---|
| 3000 | n/a | /* clear flags for the remaining attributes */ |
|---|
| 3001 | n/a | for (; i < attIndex; i += 2) |
|---|
| 3002 | n/a | ((XML_Char *)(appAtts[i]))[-1] = 0; |
|---|
| 3003 | n/a | for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding) |
|---|
| 3004 | n/a | binding->attId->name[-1] = 0; |
|---|
| 3005 | n/a | |
|---|
| 3006 | n/a | if (!ns) |
|---|
| 3007 | n/a | return XML_ERROR_NONE; |
|---|
| 3008 | n/a | |
|---|
| 3009 | n/a | /* expand the element type name */ |
|---|
| 3010 | n/a | if (elementType->prefix) { |
|---|
| 3011 | n/a | binding = elementType->prefix->binding; |
|---|
| 3012 | n/a | if (!binding) |
|---|
| 3013 | n/a | return XML_ERROR_UNBOUND_PREFIX; |
|---|
| 3014 | n/a | localPart = tagNamePtr->str; |
|---|
| 3015 | n/a | while (*localPart++ != XML_T(ASCII_COLON)) |
|---|
| 3016 | n/a | ; |
|---|
| 3017 | n/a | } |
|---|
| 3018 | n/a | else if (dtd->defaultPrefix.binding) { |
|---|
| 3019 | n/a | binding = dtd->defaultPrefix.binding; |
|---|
| 3020 | n/a | localPart = tagNamePtr->str; |
|---|
| 3021 | n/a | } |
|---|
| 3022 | n/a | else |
|---|
| 3023 | n/a | return XML_ERROR_NONE; |
|---|
| 3024 | n/a | prefixLen = 0; |
|---|
| 3025 | n/a | if (ns_triplets && binding->prefix->name) { |
|---|
| 3026 | n/a | for (; binding->prefix->name[prefixLen++];) |
|---|
| 3027 | n/a | ; /* prefixLen includes null terminator */ |
|---|
| 3028 | n/a | } |
|---|
| 3029 | n/a | tagNamePtr->localPart = localPart; |
|---|
| 3030 | n/a | tagNamePtr->uriLen = binding->uriLen; |
|---|
| 3031 | n/a | tagNamePtr->prefix = binding->prefix->name; |
|---|
| 3032 | n/a | tagNamePtr->prefixLen = prefixLen; |
|---|
| 3033 | n/a | for (i = 0; localPart[i++];) |
|---|
| 3034 | n/a | ; /* i includes null terminator */ |
|---|
| 3035 | n/a | n = i + binding->uriLen + prefixLen; |
|---|
| 3036 | n/a | if (n > binding->uriAlloc) { |
|---|
| 3037 | n/a | TAG *p; |
|---|
| 3038 | n/a | uri = (XML_Char *)MALLOC((n + EXPAND_SPARE) * sizeof(XML_Char)); |
|---|
| 3039 | n/a | if (!uri) |
|---|
| 3040 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 3041 | n/a | binding->uriAlloc = n + EXPAND_SPARE; |
|---|
| 3042 | n/a | memcpy(uri, binding->uri, binding->uriLen * sizeof(XML_Char)); |
|---|
| 3043 | n/a | for (p = tagStack; p; p = p->parent) |
|---|
| 3044 | n/a | if (p->name.str == binding->uri) |
|---|
| 3045 | n/a | p->name.str = uri; |
|---|
| 3046 | n/a | FREE(binding->uri); |
|---|
| 3047 | n/a | binding->uri = uri; |
|---|
| 3048 | n/a | } |
|---|
| 3049 | n/a | /* if namespaceSeparator != '\0' then uri includes it already */ |
|---|
| 3050 | n/a | uri = binding->uri + binding->uriLen; |
|---|
| 3051 | n/a | memcpy(uri, localPart, i * sizeof(XML_Char)); |
|---|
| 3052 | n/a | /* we always have a namespace separator between localPart and prefix */ |
|---|
| 3053 | n/a | if (prefixLen) { |
|---|
| 3054 | n/a | uri += i - 1; |
|---|
| 3055 | n/a | *uri = namespaceSeparator; /* replace null terminator */ |
|---|
| 3056 | n/a | memcpy(uri + 1, binding->prefix->name, prefixLen * sizeof(XML_Char)); |
|---|
| 3057 | n/a | } |
|---|
| 3058 | n/a | tagNamePtr->str = binding->uri; |
|---|
| 3059 | n/a | return XML_ERROR_NONE; |
|---|
| 3060 | n/a | } |
|---|
| 3061 | n/a | |
|---|
| 3062 | n/a | /* addBinding() overwrites the value of prefix->binding without checking. |
|---|
| 3063 | n/a | Therefore one must keep track of the old value outside of addBinding(). |
|---|
| 3064 | n/a | */ |
|---|
| 3065 | n/a | static enum XML_Error |
|---|
| 3066 | n/a | addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, |
|---|
| 3067 | n/a | const XML_Char *uri, BINDING **bindingsPtr) |
|---|
| 3068 | n/a | { |
|---|
| 3069 | n/a | static const XML_Char xmlNamespace[] = { |
|---|
| 3070 | n/a | ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, |
|---|
| 3071 | n/a | ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, |
|---|
| 3072 | n/a | ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, |
|---|
| 3073 | n/a | ASCII_SLASH, ASCII_1, ASCII_9, ASCII_9, ASCII_8, ASCII_SLASH, |
|---|
| 3074 | n/a | ASCII_n, ASCII_a, ASCII_m, ASCII_e, ASCII_s, ASCII_p, ASCII_a, ASCII_c, |
|---|
| 3075 | n/a | ASCII_e, '\0' |
|---|
| 3076 | n/a | }; |
|---|
| 3077 | n/a | static const int xmlLen = |
|---|
| 3078 | n/a | (int)sizeof(xmlNamespace)/sizeof(XML_Char) - 1; |
|---|
| 3079 | n/a | static const XML_Char xmlnsNamespace[] = { |
|---|
| 3080 | n/a | ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, |
|---|
| 3081 | n/a | ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, |
|---|
| 3082 | n/a | ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_2, ASCII_0, ASCII_0, |
|---|
| 3083 | n/a | ASCII_0, ASCII_SLASH, ASCII_x, ASCII_m, ASCII_l, ASCII_n, ASCII_s, |
|---|
| 3084 | n/a | ASCII_SLASH, '\0' |
|---|
| 3085 | n/a | }; |
|---|
| 3086 | n/a | static const int xmlnsLen = |
|---|
| 3087 | n/a | (int)sizeof(xmlnsNamespace)/sizeof(XML_Char) - 1; |
|---|
| 3088 | n/a | |
|---|
| 3089 | n/a | XML_Bool mustBeXML = XML_FALSE; |
|---|
| 3090 | n/a | XML_Bool isXML = XML_TRUE; |
|---|
| 3091 | n/a | XML_Bool isXMLNS = XML_TRUE; |
|---|
| 3092 | n/a | |
|---|
| 3093 | n/a | BINDING *b; |
|---|
| 3094 | n/a | int len; |
|---|
| 3095 | n/a | |
|---|
| 3096 | n/a | /* empty URI is only valid for default namespace per XML NS 1.0 (not 1.1) */ |
|---|
| 3097 | n/a | if (*uri == XML_T('\0') && prefix->name) |
|---|
| 3098 | n/a | return XML_ERROR_UNDECLARING_PREFIX; |
|---|
| 3099 | n/a | |
|---|
| 3100 | n/a | if (prefix->name |
|---|
| 3101 | n/a | && prefix->name[0] == XML_T(ASCII_x) |
|---|
| 3102 | n/a | && prefix->name[1] == XML_T(ASCII_m) |
|---|
| 3103 | n/a | && prefix->name[2] == XML_T(ASCII_l)) { |
|---|
| 3104 | n/a | |
|---|
| 3105 | n/a | /* Not allowed to bind xmlns */ |
|---|
| 3106 | n/a | if (prefix->name[3] == XML_T(ASCII_n) |
|---|
| 3107 | n/a | && prefix->name[4] == XML_T(ASCII_s) |
|---|
| 3108 | n/a | && prefix->name[5] == XML_T('\0')) |
|---|
| 3109 | n/a | return XML_ERROR_RESERVED_PREFIX_XMLNS; |
|---|
| 3110 | n/a | |
|---|
| 3111 | n/a | if (prefix->name[3] == XML_T('\0')) |
|---|
| 3112 | n/a | mustBeXML = XML_TRUE; |
|---|
| 3113 | n/a | } |
|---|
| 3114 | n/a | |
|---|
| 3115 | n/a | for (len = 0; uri[len]; len++) { |
|---|
| 3116 | n/a | if (isXML && (len > xmlLen || uri[len] != xmlNamespace[len])) |
|---|
| 3117 | n/a | isXML = XML_FALSE; |
|---|
| 3118 | n/a | |
|---|
| 3119 | n/a | if (!mustBeXML && isXMLNS |
|---|
| 3120 | n/a | && (len > xmlnsLen || uri[len] != xmlnsNamespace[len])) |
|---|
| 3121 | n/a | isXMLNS = XML_FALSE; |
|---|
| 3122 | n/a | } |
|---|
| 3123 | n/a | isXML = isXML && len == xmlLen; |
|---|
| 3124 | n/a | isXMLNS = isXMLNS && len == xmlnsLen; |
|---|
| 3125 | n/a | |
|---|
| 3126 | n/a | if (mustBeXML != isXML) |
|---|
| 3127 | n/a | return mustBeXML ? XML_ERROR_RESERVED_PREFIX_XML |
|---|
| 3128 | n/a | : XML_ERROR_RESERVED_NAMESPACE_URI; |
|---|
| 3129 | n/a | |
|---|
| 3130 | n/a | if (isXMLNS) |
|---|
| 3131 | n/a | return XML_ERROR_RESERVED_NAMESPACE_URI; |
|---|
| 3132 | n/a | |
|---|
| 3133 | n/a | if (namespaceSeparator) |
|---|
| 3134 | n/a | len++; |
|---|
| 3135 | n/a | if (freeBindingList) { |
|---|
| 3136 | n/a | b = freeBindingList; |
|---|
| 3137 | n/a | if (len > b->uriAlloc) { |
|---|
| 3138 | n/a | XML_Char *temp = (XML_Char *)REALLOC(b->uri, |
|---|
| 3139 | n/a | sizeof(XML_Char) * (len + EXPAND_SPARE)); |
|---|
| 3140 | n/a | if (temp == NULL) |
|---|
| 3141 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 3142 | n/a | b->uri = temp; |
|---|
| 3143 | n/a | b->uriAlloc = len + EXPAND_SPARE; |
|---|
| 3144 | n/a | } |
|---|
| 3145 | n/a | freeBindingList = b->nextTagBinding; |
|---|
| 3146 | n/a | } |
|---|
| 3147 | n/a | else { |
|---|
| 3148 | n/a | b = (BINDING *)MALLOC(sizeof(BINDING)); |
|---|
| 3149 | n/a | if (!b) |
|---|
| 3150 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 3151 | n/a | b->uri = (XML_Char *)MALLOC(sizeof(XML_Char) * (len + EXPAND_SPARE)); |
|---|
| 3152 | n/a | if (!b->uri) { |
|---|
| 3153 | n/a | FREE(b); |
|---|
| 3154 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 3155 | n/a | } |
|---|
| 3156 | n/a | b->uriAlloc = len + EXPAND_SPARE; |
|---|
| 3157 | n/a | } |
|---|
| 3158 | n/a | b->uriLen = len; |
|---|
| 3159 | n/a | memcpy(b->uri, uri, len * sizeof(XML_Char)); |
|---|
| 3160 | n/a | if (namespaceSeparator) |
|---|
| 3161 | n/a | b->uri[len - 1] = namespaceSeparator; |
|---|
| 3162 | n/a | b->prefix = prefix; |
|---|
| 3163 | n/a | b->attId = attId; |
|---|
| 3164 | n/a | b->prevPrefixBinding = prefix->binding; |
|---|
| 3165 | n/a | /* NULL binding when default namespace undeclared */ |
|---|
| 3166 | n/a | if (*uri == XML_T('\0') && prefix == &_dtd->defaultPrefix) |
|---|
| 3167 | n/a | prefix->binding = NULL; |
|---|
| 3168 | n/a | else |
|---|
| 3169 | n/a | prefix->binding = b; |
|---|
| 3170 | n/a | b->nextTagBinding = *bindingsPtr; |
|---|
| 3171 | n/a | *bindingsPtr = b; |
|---|
| 3172 | n/a | /* if attId == NULL then we are not starting a namespace scope */ |
|---|
| 3173 | n/a | if (attId && startNamespaceDeclHandler) |
|---|
| 3174 | n/a | startNamespaceDeclHandler(handlerArg, prefix->name, |
|---|
| 3175 | n/a | prefix->binding ? uri : 0); |
|---|
| 3176 | n/a | return XML_ERROR_NONE; |
|---|
| 3177 | n/a | } |
|---|
| 3178 | n/a | |
|---|
| 3179 | n/a | /* The idea here is to avoid using stack for each CDATA section when |
|---|
| 3180 | n/a | the whole file is parsed with one call. |
|---|
| 3181 | n/a | */ |
|---|
| 3182 | n/a | static enum XML_Error PTRCALL |
|---|
| 3183 | n/a | cdataSectionProcessor(XML_Parser parser, |
|---|
| 3184 | n/a | const char *start, |
|---|
| 3185 | n/a | const char *end, |
|---|
| 3186 | n/a | const char **endPtr) |
|---|
| 3187 | n/a | { |
|---|
| 3188 | n/a | enum XML_Error result = doCdataSection(parser, encoding, &start, end, |
|---|
| 3189 | n/a | endPtr, (XML_Bool)!ps_finalBuffer); |
|---|
| 3190 | n/a | if (result != XML_ERROR_NONE) |
|---|
| 3191 | n/a | return result; |
|---|
| 3192 | n/a | if (start) { |
|---|
| 3193 | n/a | if (parentParser) { /* we are parsing an external entity */ |
|---|
| 3194 | n/a | processor = externalEntityContentProcessor; |
|---|
| 3195 | n/a | return externalEntityContentProcessor(parser, start, end, endPtr); |
|---|
| 3196 | n/a | } |
|---|
| 3197 | n/a | else { |
|---|
| 3198 | n/a | processor = contentProcessor; |
|---|
| 3199 | n/a | return contentProcessor(parser, start, end, endPtr); |
|---|
| 3200 | n/a | } |
|---|
| 3201 | n/a | } |
|---|
| 3202 | n/a | return result; |
|---|
| 3203 | n/a | } |
|---|
| 3204 | n/a | |
|---|
| 3205 | n/a | /* startPtr gets set to non-null if the section is closed, and to null if |
|---|
| 3206 | n/a | the section is not yet closed. |
|---|
| 3207 | n/a | */ |
|---|
| 3208 | n/a | static enum XML_Error |
|---|
| 3209 | n/a | doCdataSection(XML_Parser parser, |
|---|
| 3210 | n/a | const ENCODING *enc, |
|---|
| 3211 | n/a | const char **startPtr, |
|---|
| 3212 | n/a | const char *end, |
|---|
| 3213 | n/a | const char **nextPtr, |
|---|
| 3214 | n/a | XML_Bool haveMore) |
|---|
| 3215 | n/a | { |
|---|
| 3216 | n/a | const char *s = *startPtr; |
|---|
| 3217 | n/a | const char **eventPP; |
|---|
| 3218 | n/a | const char **eventEndPP; |
|---|
| 3219 | n/a | if (enc == encoding) { |
|---|
| 3220 | n/a | eventPP = &eventPtr; |
|---|
| 3221 | n/a | *eventPP = s; |
|---|
| 3222 | n/a | eventEndPP = &eventEndPtr; |
|---|
| 3223 | n/a | } |
|---|
| 3224 | n/a | else { |
|---|
| 3225 | n/a | eventPP = &(openInternalEntities->internalEventPtr); |
|---|
| 3226 | n/a | eventEndPP = &(openInternalEntities->internalEventEndPtr); |
|---|
| 3227 | n/a | } |
|---|
| 3228 | n/a | *eventPP = s; |
|---|
| 3229 | n/a | *startPtr = NULL; |
|---|
| 3230 | n/a | |
|---|
| 3231 | n/a | for (;;) { |
|---|
| 3232 | n/a | const char *next; |
|---|
| 3233 | n/a | int tok = XmlCdataSectionTok(enc, s, end, &next); |
|---|
| 3234 | n/a | *eventEndPP = next; |
|---|
| 3235 | n/a | switch (tok) { |
|---|
| 3236 | n/a | case XML_TOK_CDATA_SECT_CLOSE: |
|---|
| 3237 | n/a | if (endCdataSectionHandler) |
|---|
| 3238 | n/a | endCdataSectionHandler(handlerArg); |
|---|
| 3239 | n/a | #if 0 |
|---|
| 3240 | n/a | /* see comment under XML_TOK_CDATA_SECT_OPEN */ |
|---|
| 3241 | n/a | else if (characterDataHandler) |
|---|
| 3242 | n/a | characterDataHandler(handlerArg, dataBuf, 0); |
|---|
| 3243 | n/a | #endif |
|---|
| 3244 | n/a | else if (defaultHandler) |
|---|
| 3245 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 3246 | n/a | *startPtr = next; |
|---|
| 3247 | n/a | *nextPtr = next; |
|---|
| 3248 | n/a | if (ps_parsing == XML_FINISHED) |
|---|
| 3249 | n/a | return XML_ERROR_ABORTED; |
|---|
| 3250 | n/a | else |
|---|
| 3251 | n/a | return XML_ERROR_NONE; |
|---|
| 3252 | n/a | case XML_TOK_DATA_NEWLINE: |
|---|
| 3253 | n/a | if (characterDataHandler) { |
|---|
| 3254 | n/a | XML_Char c = 0xA; |
|---|
| 3255 | n/a | characterDataHandler(handlerArg, &c, 1); |
|---|
| 3256 | n/a | } |
|---|
| 3257 | n/a | else if (defaultHandler) |
|---|
| 3258 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 3259 | n/a | break; |
|---|
| 3260 | n/a | case XML_TOK_DATA_CHARS: |
|---|
| 3261 | n/a | { |
|---|
| 3262 | n/a | XML_CharacterDataHandler charDataHandler = characterDataHandler; |
|---|
| 3263 | n/a | if (charDataHandler) { |
|---|
| 3264 | n/a | if (MUST_CONVERT(enc, s)) { |
|---|
| 3265 | n/a | for (;;) { |
|---|
| 3266 | n/a | ICHAR *dataPtr = (ICHAR *)dataBuf; |
|---|
| 3267 | n/a | XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); |
|---|
| 3268 | n/a | *eventEndPP = next; |
|---|
| 3269 | n/a | charDataHandler(handlerArg, dataBuf, |
|---|
| 3270 | n/a | (int)(dataPtr - (ICHAR *)dataBuf)); |
|---|
| 3271 | n/a | if (s == next) |
|---|
| 3272 | n/a | break; |
|---|
| 3273 | n/a | *eventPP = s; |
|---|
| 3274 | n/a | } |
|---|
| 3275 | n/a | } |
|---|
| 3276 | n/a | else |
|---|
| 3277 | n/a | charDataHandler(handlerArg, |
|---|
| 3278 | n/a | (XML_Char *)s, |
|---|
| 3279 | n/a | (int)((XML_Char *)next - (XML_Char *)s)); |
|---|
| 3280 | n/a | } |
|---|
| 3281 | n/a | else if (defaultHandler) |
|---|
| 3282 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 3283 | n/a | } |
|---|
| 3284 | n/a | break; |
|---|
| 3285 | n/a | case XML_TOK_INVALID: |
|---|
| 3286 | n/a | *eventPP = next; |
|---|
| 3287 | n/a | return XML_ERROR_INVALID_TOKEN; |
|---|
| 3288 | n/a | case XML_TOK_PARTIAL_CHAR: |
|---|
| 3289 | n/a | if (haveMore) { |
|---|
| 3290 | n/a | *nextPtr = s; |
|---|
| 3291 | n/a | return XML_ERROR_NONE; |
|---|
| 3292 | n/a | } |
|---|
| 3293 | n/a | return XML_ERROR_PARTIAL_CHAR; |
|---|
| 3294 | n/a | case XML_TOK_PARTIAL: |
|---|
| 3295 | n/a | case XML_TOK_NONE: |
|---|
| 3296 | n/a | if (haveMore) { |
|---|
| 3297 | n/a | *nextPtr = s; |
|---|
| 3298 | n/a | return XML_ERROR_NONE; |
|---|
| 3299 | n/a | } |
|---|
| 3300 | n/a | return XML_ERROR_UNCLOSED_CDATA_SECTION; |
|---|
| 3301 | n/a | default: |
|---|
| 3302 | n/a | *eventPP = next; |
|---|
| 3303 | n/a | return XML_ERROR_UNEXPECTED_STATE; |
|---|
| 3304 | n/a | } |
|---|
| 3305 | n/a | |
|---|
| 3306 | n/a | *eventPP = s = next; |
|---|
| 3307 | n/a | switch (ps_parsing) { |
|---|
| 3308 | n/a | case XML_SUSPENDED: |
|---|
| 3309 | n/a | *nextPtr = next; |
|---|
| 3310 | n/a | return XML_ERROR_NONE; |
|---|
| 3311 | n/a | case XML_FINISHED: |
|---|
| 3312 | n/a | return XML_ERROR_ABORTED; |
|---|
| 3313 | n/a | default: ; |
|---|
| 3314 | n/a | } |
|---|
| 3315 | n/a | } |
|---|
| 3316 | n/a | /* not reached */ |
|---|
| 3317 | n/a | } |
|---|
| 3318 | n/a | |
|---|
| 3319 | n/a | #ifdef XML_DTD |
|---|
| 3320 | n/a | |
|---|
| 3321 | n/a | /* The idea here is to avoid using stack for each IGNORE section when |
|---|
| 3322 | n/a | the whole file is parsed with one call. |
|---|
| 3323 | n/a | */ |
|---|
| 3324 | n/a | static enum XML_Error PTRCALL |
|---|
| 3325 | n/a | ignoreSectionProcessor(XML_Parser parser, |
|---|
| 3326 | n/a | const char *start, |
|---|
| 3327 | n/a | const char *end, |
|---|
| 3328 | n/a | const char **endPtr) |
|---|
| 3329 | n/a | { |
|---|
| 3330 | n/a | enum XML_Error result = doIgnoreSection(parser, encoding, &start, end, |
|---|
| 3331 | n/a | endPtr, (XML_Bool)!ps_finalBuffer); |
|---|
| 3332 | n/a | if (result != XML_ERROR_NONE) |
|---|
| 3333 | n/a | return result; |
|---|
| 3334 | n/a | if (start) { |
|---|
| 3335 | n/a | processor = prologProcessor; |
|---|
| 3336 | n/a | return prologProcessor(parser, start, end, endPtr); |
|---|
| 3337 | n/a | } |
|---|
| 3338 | n/a | return result; |
|---|
| 3339 | n/a | } |
|---|
| 3340 | n/a | |
|---|
| 3341 | n/a | /* startPtr gets set to non-null is the section is closed, and to null |
|---|
| 3342 | n/a | if the section is not yet closed. |
|---|
| 3343 | n/a | */ |
|---|
| 3344 | n/a | static enum XML_Error |
|---|
| 3345 | n/a | doIgnoreSection(XML_Parser parser, |
|---|
| 3346 | n/a | const ENCODING *enc, |
|---|
| 3347 | n/a | const char **startPtr, |
|---|
| 3348 | n/a | const char *end, |
|---|
| 3349 | n/a | const char **nextPtr, |
|---|
| 3350 | n/a | XML_Bool haveMore) |
|---|
| 3351 | n/a | { |
|---|
| 3352 | n/a | const char *next; |
|---|
| 3353 | n/a | int tok; |
|---|
| 3354 | n/a | const char *s = *startPtr; |
|---|
| 3355 | n/a | const char **eventPP; |
|---|
| 3356 | n/a | const char **eventEndPP; |
|---|
| 3357 | n/a | if (enc == encoding) { |
|---|
| 3358 | n/a | eventPP = &eventPtr; |
|---|
| 3359 | n/a | *eventPP = s; |
|---|
| 3360 | n/a | eventEndPP = &eventEndPtr; |
|---|
| 3361 | n/a | } |
|---|
| 3362 | n/a | else { |
|---|
| 3363 | n/a | eventPP = &(openInternalEntities->internalEventPtr); |
|---|
| 3364 | n/a | eventEndPP = &(openInternalEntities->internalEventEndPtr); |
|---|
| 3365 | n/a | } |
|---|
| 3366 | n/a | *eventPP = s; |
|---|
| 3367 | n/a | *startPtr = NULL; |
|---|
| 3368 | n/a | tok = XmlIgnoreSectionTok(enc, s, end, &next); |
|---|
| 3369 | n/a | *eventEndPP = next; |
|---|
| 3370 | n/a | switch (tok) { |
|---|
| 3371 | n/a | case XML_TOK_IGNORE_SECT: |
|---|
| 3372 | n/a | if (defaultHandler) |
|---|
| 3373 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 3374 | n/a | *startPtr = next; |
|---|
| 3375 | n/a | *nextPtr = next; |
|---|
| 3376 | n/a | if (ps_parsing == XML_FINISHED) |
|---|
| 3377 | n/a | return XML_ERROR_ABORTED; |
|---|
| 3378 | n/a | else |
|---|
| 3379 | n/a | return XML_ERROR_NONE; |
|---|
| 3380 | n/a | case XML_TOK_INVALID: |
|---|
| 3381 | n/a | *eventPP = next; |
|---|
| 3382 | n/a | return XML_ERROR_INVALID_TOKEN; |
|---|
| 3383 | n/a | case XML_TOK_PARTIAL_CHAR: |
|---|
| 3384 | n/a | if (haveMore) { |
|---|
| 3385 | n/a | *nextPtr = s; |
|---|
| 3386 | n/a | return XML_ERROR_NONE; |
|---|
| 3387 | n/a | } |
|---|
| 3388 | n/a | return XML_ERROR_PARTIAL_CHAR; |
|---|
| 3389 | n/a | case XML_TOK_PARTIAL: |
|---|
| 3390 | n/a | case XML_TOK_NONE: |
|---|
| 3391 | n/a | if (haveMore) { |
|---|
| 3392 | n/a | *nextPtr = s; |
|---|
| 3393 | n/a | return XML_ERROR_NONE; |
|---|
| 3394 | n/a | } |
|---|
| 3395 | n/a | return XML_ERROR_SYNTAX; /* XML_ERROR_UNCLOSED_IGNORE_SECTION */ |
|---|
| 3396 | n/a | default: |
|---|
| 3397 | n/a | *eventPP = next; |
|---|
| 3398 | n/a | return XML_ERROR_UNEXPECTED_STATE; |
|---|
| 3399 | n/a | } |
|---|
| 3400 | n/a | /* not reached */ |
|---|
| 3401 | n/a | } |
|---|
| 3402 | n/a | |
|---|
| 3403 | n/a | #endif /* XML_DTD */ |
|---|
| 3404 | n/a | |
|---|
| 3405 | n/a | static enum XML_Error |
|---|
| 3406 | n/a | initializeEncoding(XML_Parser parser) |
|---|
| 3407 | n/a | { |
|---|
| 3408 | n/a | const char *s; |
|---|
| 3409 | n/a | #ifdef XML_UNICODE |
|---|
| 3410 | n/a | char encodingBuf[128]; |
|---|
| 3411 | n/a | if (!protocolEncodingName) |
|---|
| 3412 | n/a | s = NULL; |
|---|
| 3413 | n/a | else { |
|---|
| 3414 | n/a | int i; |
|---|
| 3415 | n/a | for (i = 0; protocolEncodingName[i]; i++) { |
|---|
| 3416 | n/a | if (i == sizeof(encodingBuf) - 1 |
|---|
| 3417 | n/a | || (protocolEncodingName[i] & ~0x7f) != 0) { |
|---|
| 3418 | n/a | encodingBuf[0] = '\0'; |
|---|
| 3419 | n/a | break; |
|---|
| 3420 | n/a | } |
|---|
| 3421 | n/a | encodingBuf[i] = (char)protocolEncodingName[i]; |
|---|
| 3422 | n/a | } |
|---|
| 3423 | n/a | encodingBuf[i] = '\0'; |
|---|
| 3424 | n/a | s = encodingBuf; |
|---|
| 3425 | n/a | } |
|---|
| 3426 | n/a | #else |
|---|
| 3427 | n/a | s = protocolEncodingName; |
|---|
| 3428 | n/a | #endif |
|---|
| 3429 | n/a | if ((ns ? XmlInitEncodingNS : XmlInitEncoding)(&initEncoding, &encoding, s)) |
|---|
| 3430 | n/a | return XML_ERROR_NONE; |
|---|
| 3431 | n/a | return handleUnknownEncoding(parser, protocolEncodingName); |
|---|
| 3432 | n/a | } |
|---|
| 3433 | n/a | |
|---|
| 3434 | n/a | static enum XML_Error |
|---|
| 3435 | n/a | processXmlDecl(XML_Parser parser, int isGeneralTextEntity, |
|---|
| 3436 | n/a | const char *s, const char *next) |
|---|
| 3437 | n/a | { |
|---|
| 3438 | n/a | const char *encodingName = NULL; |
|---|
| 3439 | n/a | const XML_Char *storedEncName = NULL; |
|---|
| 3440 | n/a | const ENCODING *newEncoding = NULL; |
|---|
| 3441 | n/a | const char *version = NULL; |
|---|
| 3442 | n/a | const char *versionend; |
|---|
| 3443 | n/a | const XML_Char *storedversion = NULL; |
|---|
| 3444 | n/a | int standalone = -1; |
|---|
| 3445 | n/a | if (!(ns |
|---|
| 3446 | n/a | ? XmlParseXmlDeclNS |
|---|
| 3447 | n/a | : XmlParseXmlDecl)(isGeneralTextEntity, |
|---|
| 3448 | n/a | encoding, |
|---|
| 3449 | n/a | s, |
|---|
| 3450 | n/a | next, |
|---|
| 3451 | n/a | &eventPtr, |
|---|
| 3452 | n/a | &version, |
|---|
| 3453 | n/a | &versionend, |
|---|
| 3454 | n/a | &encodingName, |
|---|
| 3455 | n/a | &newEncoding, |
|---|
| 3456 | n/a | &standalone)) { |
|---|
| 3457 | n/a | if (isGeneralTextEntity) |
|---|
| 3458 | n/a | return XML_ERROR_TEXT_DECL; |
|---|
| 3459 | n/a | else |
|---|
| 3460 | n/a | return XML_ERROR_XML_DECL; |
|---|
| 3461 | n/a | } |
|---|
| 3462 | n/a | if (!isGeneralTextEntity && standalone == 1) { |
|---|
| 3463 | n/a | _dtd->standalone = XML_TRUE; |
|---|
| 3464 | n/a | #ifdef XML_DTD |
|---|
| 3465 | n/a | if (paramEntityParsing == XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE) |
|---|
| 3466 | n/a | paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; |
|---|
| 3467 | n/a | #endif /* XML_DTD */ |
|---|
| 3468 | n/a | } |
|---|
| 3469 | n/a | if (xmlDeclHandler) { |
|---|
| 3470 | n/a | if (encodingName != NULL) { |
|---|
| 3471 | n/a | storedEncName = poolStoreString(&temp2Pool, |
|---|
| 3472 | n/a | encoding, |
|---|
| 3473 | n/a | encodingName, |
|---|
| 3474 | n/a | encodingName |
|---|
| 3475 | n/a | + XmlNameLength(encoding, encodingName)); |
|---|
| 3476 | n/a | if (!storedEncName) |
|---|
| 3477 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 3478 | n/a | poolFinish(&temp2Pool); |
|---|
| 3479 | n/a | } |
|---|
| 3480 | n/a | if (version) { |
|---|
| 3481 | n/a | storedversion = poolStoreString(&temp2Pool, |
|---|
| 3482 | n/a | encoding, |
|---|
| 3483 | n/a | version, |
|---|
| 3484 | n/a | versionend - encoding->minBytesPerChar); |
|---|
| 3485 | n/a | if (!storedversion) |
|---|
| 3486 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 3487 | n/a | } |
|---|
| 3488 | n/a | xmlDeclHandler(handlerArg, storedversion, storedEncName, standalone); |
|---|
| 3489 | n/a | } |
|---|
| 3490 | n/a | else if (defaultHandler) |
|---|
| 3491 | n/a | reportDefault(parser, encoding, s, next); |
|---|
| 3492 | n/a | if (protocolEncodingName == NULL) { |
|---|
| 3493 | n/a | if (newEncoding) { |
|---|
| 3494 | n/a | if (newEncoding->minBytesPerChar != encoding->minBytesPerChar) { |
|---|
| 3495 | n/a | eventPtr = encodingName; |
|---|
| 3496 | n/a | return XML_ERROR_INCORRECT_ENCODING; |
|---|
| 3497 | n/a | } |
|---|
| 3498 | n/a | encoding = newEncoding; |
|---|
| 3499 | n/a | } |
|---|
| 3500 | n/a | else if (encodingName) { |
|---|
| 3501 | n/a | enum XML_Error result; |
|---|
| 3502 | n/a | if (!storedEncName) { |
|---|
| 3503 | n/a | storedEncName = poolStoreString( |
|---|
| 3504 | n/a | &temp2Pool, encoding, encodingName, |
|---|
| 3505 | n/a | encodingName + XmlNameLength(encoding, encodingName)); |
|---|
| 3506 | n/a | if (!storedEncName) |
|---|
| 3507 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 3508 | n/a | } |
|---|
| 3509 | n/a | result = handleUnknownEncoding(parser, storedEncName); |
|---|
| 3510 | n/a | poolClear(&temp2Pool); |
|---|
| 3511 | n/a | if (result == XML_ERROR_UNKNOWN_ENCODING) |
|---|
| 3512 | n/a | eventPtr = encodingName; |
|---|
| 3513 | n/a | return result; |
|---|
| 3514 | n/a | } |
|---|
| 3515 | n/a | } |
|---|
| 3516 | n/a | |
|---|
| 3517 | n/a | if (storedEncName || storedversion) |
|---|
| 3518 | n/a | poolClear(&temp2Pool); |
|---|
| 3519 | n/a | |
|---|
| 3520 | n/a | return XML_ERROR_NONE; |
|---|
| 3521 | n/a | } |
|---|
| 3522 | n/a | |
|---|
| 3523 | n/a | static enum XML_Error |
|---|
| 3524 | n/a | handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName) |
|---|
| 3525 | n/a | { |
|---|
| 3526 | n/a | if (unknownEncodingHandler) { |
|---|
| 3527 | n/a | XML_Encoding info; |
|---|
| 3528 | n/a | int i; |
|---|
| 3529 | n/a | for (i = 0; i < 256; i++) |
|---|
| 3530 | n/a | info.map[i] = -1; |
|---|
| 3531 | n/a | info.convert = NULL; |
|---|
| 3532 | n/a | info.data = NULL; |
|---|
| 3533 | n/a | info.release = NULL; |
|---|
| 3534 | n/a | if (unknownEncodingHandler(unknownEncodingHandlerData, encodingName, |
|---|
| 3535 | n/a | &info)) { |
|---|
| 3536 | n/a | ENCODING *enc; |
|---|
| 3537 | n/a | unknownEncodingMem = MALLOC(XmlSizeOfUnknownEncoding()); |
|---|
| 3538 | n/a | if (!unknownEncodingMem) { |
|---|
| 3539 | n/a | if (info.release) |
|---|
| 3540 | n/a | info.release(info.data); |
|---|
| 3541 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 3542 | n/a | } |
|---|
| 3543 | n/a | enc = (ns |
|---|
| 3544 | n/a | ? XmlInitUnknownEncodingNS |
|---|
| 3545 | n/a | : XmlInitUnknownEncoding)(unknownEncodingMem, |
|---|
| 3546 | n/a | info.map, |
|---|
| 3547 | n/a | info.convert, |
|---|
| 3548 | n/a | info.data); |
|---|
| 3549 | n/a | if (enc) { |
|---|
| 3550 | n/a | unknownEncodingData = info.data; |
|---|
| 3551 | n/a | unknownEncodingRelease = info.release; |
|---|
| 3552 | n/a | encoding = enc; |
|---|
| 3553 | n/a | return XML_ERROR_NONE; |
|---|
| 3554 | n/a | } |
|---|
| 3555 | n/a | } |
|---|
| 3556 | n/a | if (info.release != NULL) |
|---|
| 3557 | n/a | info.release(info.data); |
|---|
| 3558 | n/a | } |
|---|
| 3559 | n/a | return XML_ERROR_UNKNOWN_ENCODING; |
|---|
| 3560 | n/a | } |
|---|
| 3561 | n/a | |
|---|
| 3562 | n/a | static enum XML_Error PTRCALL |
|---|
| 3563 | n/a | prologInitProcessor(XML_Parser parser, |
|---|
| 3564 | n/a | const char *s, |
|---|
| 3565 | n/a | const char *end, |
|---|
| 3566 | n/a | const char **nextPtr) |
|---|
| 3567 | n/a | { |
|---|
| 3568 | n/a | enum XML_Error result = initializeEncoding(parser); |
|---|
| 3569 | n/a | if (result != XML_ERROR_NONE) |
|---|
| 3570 | n/a | return result; |
|---|
| 3571 | n/a | processor = prologProcessor; |
|---|
| 3572 | n/a | return prologProcessor(parser, s, end, nextPtr); |
|---|
| 3573 | n/a | } |
|---|
| 3574 | n/a | |
|---|
| 3575 | n/a | #ifdef XML_DTD |
|---|
| 3576 | n/a | |
|---|
| 3577 | n/a | static enum XML_Error PTRCALL |
|---|
| 3578 | n/a | externalParEntInitProcessor(XML_Parser parser, |
|---|
| 3579 | n/a | const char *s, |
|---|
| 3580 | n/a | const char *end, |
|---|
| 3581 | n/a | const char **nextPtr) |
|---|
| 3582 | n/a | { |
|---|
| 3583 | n/a | enum XML_Error result = initializeEncoding(parser); |
|---|
| 3584 | n/a | if (result != XML_ERROR_NONE) |
|---|
| 3585 | n/a | return result; |
|---|
| 3586 | n/a | |
|---|
| 3587 | n/a | /* we know now that XML_Parse(Buffer) has been called, |
|---|
| 3588 | n/a | so we consider the external parameter entity read */ |
|---|
| 3589 | n/a | _dtd->paramEntityRead = XML_TRUE; |
|---|
| 3590 | n/a | |
|---|
| 3591 | n/a | if (prologState.inEntityValue) { |
|---|
| 3592 | n/a | processor = entityValueInitProcessor; |
|---|
| 3593 | n/a | return entityValueInitProcessor(parser, s, end, nextPtr); |
|---|
| 3594 | n/a | } |
|---|
| 3595 | n/a | else { |
|---|
| 3596 | n/a | processor = externalParEntProcessor; |
|---|
| 3597 | n/a | return externalParEntProcessor(parser, s, end, nextPtr); |
|---|
| 3598 | n/a | } |
|---|
| 3599 | n/a | } |
|---|
| 3600 | n/a | |
|---|
| 3601 | n/a | static enum XML_Error PTRCALL |
|---|
| 3602 | n/a | entityValueInitProcessor(XML_Parser parser, |
|---|
| 3603 | n/a | const char *s, |
|---|
| 3604 | n/a | const char *end, |
|---|
| 3605 | n/a | const char **nextPtr) |
|---|
| 3606 | n/a | { |
|---|
| 3607 | n/a | int tok; |
|---|
| 3608 | n/a | const char *start = s; |
|---|
| 3609 | n/a | const char *next = start; |
|---|
| 3610 | n/a | eventPtr = start; |
|---|
| 3611 | n/a | |
|---|
| 3612 | n/a | for (;;) { |
|---|
| 3613 | n/a | tok = XmlPrologTok(encoding, start, end, &next); |
|---|
| 3614 | n/a | eventEndPtr = next; |
|---|
| 3615 | n/a | if (tok <= 0) { |
|---|
| 3616 | n/a | if (!ps_finalBuffer && tok != XML_TOK_INVALID) { |
|---|
| 3617 | n/a | *nextPtr = s; |
|---|
| 3618 | n/a | return XML_ERROR_NONE; |
|---|
| 3619 | n/a | } |
|---|
| 3620 | n/a | switch (tok) { |
|---|
| 3621 | n/a | case XML_TOK_INVALID: |
|---|
| 3622 | n/a | return XML_ERROR_INVALID_TOKEN; |
|---|
| 3623 | n/a | case XML_TOK_PARTIAL: |
|---|
| 3624 | n/a | return XML_ERROR_UNCLOSED_TOKEN; |
|---|
| 3625 | n/a | case XML_TOK_PARTIAL_CHAR: |
|---|
| 3626 | n/a | return XML_ERROR_PARTIAL_CHAR; |
|---|
| 3627 | n/a | case XML_TOK_NONE: /* start == end */ |
|---|
| 3628 | n/a | default: |
|---|
| 3629 | n/a | break; |
|---|
| 3630 | n/a | } |
|---|
| 3631 | n/a | /* found end of entity value - can store it now */ |
|---|
| 3632 | n/a | return storeEntityValue(parser, encoding, s, end); |
|---|
| 3633 | n/a | } |
|---|
| 3634 | n/a | else if (tok == XML_TOK_XML_DECL) { |
|---|
| 3635 | n/a | enum XML_Error result; |
|---|
| 3636 | n/a | result = processXmlDecl(parser, 0, start, next); |
|---|
| 3637 | n/a | if (result != XML_ERROR_NONE) |
|---|
| 3638 | n/a | return result; |
|---|
| 3639 | n/a | switch (ps_parsing) { |
|---|
| 3640 | n/a | case XML_SUSPENDED: |
|---|
| 3641 | n/a | *nextPtr = next; |
|---|
| 3642 | n/a | return XML_ERROR_NONE; |
|---|
| 3643 | n/a | case XML_FINISHED: |
|---|
| 3644 | n/a | return XML_ERROR_ABORTED; |
|---|
| 3645 | n/a | default: |
|---|
| 3646 | n/a | *nextPtr = next; |
|---|
| 3647 | n/a | } |
|---|
| 3648 | n/a | /* stop scanning for text declaration - we found one */ |
|---|
| 3649 | n/a | processor = entityValueProcessor; |
|---|
| 3650 | n/a | return entityValueProcessor(parser, next, end, nextPtr); |
|---|
| 3651 | n/a | } |
|---|
| 3652 | n/a | /* If we are at the end of the buffer, this would cause XmlPrologTok to |
|---|
| 3653 | n/a | return XML_TOK_NONE on the next call, which would then cause the |
|---|
| 3654 | n/a | function to exit with *nextPtr set to s - that is what we want for other |
|---|
| 3655 | n/a | tokens, but not for the BOM - we would rather like to skip it; |
|---|
| 3656 | n/a | then, when this routine is entered the next time, XmlPrologTok will |
|---|
| 3657 | n/a | return XML_TOK_INVALID, since the BOM is still in the buffer |
|---|
| 3658 | n/a | */ |
|---|
| 3659 | n/a | else if (tok == XML_TOK_BOM && next == end && !ps_finalBuffer) { |
|---|
| 3660 | n/a | *nextPtr = next; |
|---|
| 3661 | n/a | return XML_ERROR_NONE; |
|---|
| 3662 | n/a | } |
|---|
| 3663 | n/a | start = next; |
|---|
| 3664 | n/a | eventPtr = start; |
|---|
| 3665 | n/a | } |
|---|
| 3666 | n/a | } |
|---|
| 3667 | n/a | |
|---|
| 3668 | n/a | static enum XML_Error PTRCALL |
|---|
| 3669 | n/a | externalParEntProcessor(XML_Parser parser, |
|---|
| 3670 | n/a | const char *s, |
|---|
| 3671 | n/a | const char *end, |
|---|
| 3672 | n/a | const char **nextPtr) |
|---|
| 3673 | n/a | { |
|---|
| 3674 | n/a | const char *next = s; |
|---|
| 3675 | n/a | int tok; |
|---|
| 3676 | n/a | |
|---|
| 3677 | n/a | tok = XmlPrologTok(encoding, s, end, &next); |
|---|
| 3678 | n/a | if (tok <= 0) { |
|---|
| 3679 | n/a | if (!ps_finalBuffer && tok != XML_TOK_INVALID) { |
|---|
| 3680 | n/a | *nextPtr = s; |
|---|
| 3681 | n/a | return XML_ERROR_NONE; |
|---|
| 3682 | n/a | } |
|---|
| 3683 | n/a | switch (tok) { |
|---|
| 3684 | n/a | case XML_TOK_INVALID: |
|---|
| 3685 | n/a | return XML_ERROR_INVALID_TOKEN; |
|---|
| 3686 | n/a | case XML_TOK_PARTIAL: |
|---|
| 3687 | n/a | return XML_ERROR_UNCLOSED_TOKEN; |
|---|
| 3688 | n/a | case XML_TOK_PARTIAL_CHAR: |
|---|
| 3689 | n/a | return XML_ERROR_PARTIAL_CHAR; |
|---|
| 3690 | n/a | case XML_TOK_NONE: /* start == end */ |
|---|
| 3691 | n/a | default: |
|---|
| 3692 | n/a | break; |
|---|
| 3693 | n/a | } |
|---|
| 3694 | n/a | } |
|---|
| 3695 | n/a | /* This would cause the next stage, i.e. doProlog to be passed XML_TOK_BOM. |
|---|
| 3696 | n/a | However, when parsing an external subset, doProlog will not accept a BOM |
|---|
| 3697 | n/a | as valid, and report a syntax error, so we have to skip the BOM |
|---|
| 3698 | n/a | */ |
|---|
| 3699 | n/a | else if (tok == XML_TOK_BOM) { |
|---|
| 3700 | n/a | s = next; |
|---|
| 3701 | n/a | tok = XmlPrologTok(encoding, s, end, &next); |
|---|
| 3702 | n/a | } |
|---|
| 3703 | n/a | |
|---|
| 3704 | n/a | processor = prologProcessor; |
|---|
| 3705 | n/a | return doProlog(parser, encoding, s, end, tok, next, |
|---|
| 3706 | n/a | nextPtr, (XML_Bool)!ps_finalBuffer); |
|---|
| 3707 | n/a | } |
|---|
| 3708 | n/a | |
|---|
| 3709 | n/a | static enum XML_Error PTRCALL |
|---|
| 3710 | n/a | entityValueProcessor(XML_Parser parser, |
|---|
| 3711 | n/a | const char *s, |
|---|
| 3712 | n/a | const char *end, |
|---|
| 3713 | n/a | const char **nextPtr) |
|---|
| 3714 | n/a | { |
|---|
| 3715 | n/a | const char *start = s; |
|---|
| 3716 | n/a | const char *next = s; |
|---|
| 3717 | n/a | const ENCODING *enc = encoding; |
|---|
| 3718 | n/a | int tok; |
|---|
| 3719 | n/a | |
|---|
| 3720 | n/a | for (;;) { |
|---|
| 3721 | n/a | tok = XmlPrologTok(enc, start, end, &next); |
|---|
| 3722 | n/a | if (tok <= 0) { |
|---|
| 3723 | n/a | if (!ps_finalBuffer && tok != XML_TOK_INVALID) { |
|---|
| 3724 | n/a | *nextPtr = s; |
|---|
| 3725 | n/a | return XML_ERROR_NONE; |
|---|
| 3726 | n/a | } |
|---|
| 3727 | n/a | switch (tok) { |
|---|
| 3728 | n/a | case XML_TOK_INVALID: |
|---|
| 3729 | n/a | return XML_ERROR_INVALID_TOKEN; |
|---|
| 3730 | n/a | case XML_TOK_PARTIAL: |
|---|
| 3731 | n/a | return XML_ERROR_UNCLOSED_TOKEN; |
|---|
| 3732 | n/a | case XML_TOK_PARTIAL_CHAR: |
|---|
| 3733 | n/a | return XML_ERROR_PARTIAL_CHAR; |
|---|
| 3734 | n/a | case XML_TOK_NONE: /* start == end */ |
|---|
| 3735 | n/a | default: |
|---|
| 3736 | n/a | break; |
|---|
| 3737 | n/a | } |
|---|
| 3738 | n/a | /* found end of entity value - can store it now */ |
|---|
| 3739 | n/a | return storeEntityValue(parser, enc, s, end); |
|---|
| 3740 | n/a | } |
|---|
| 3741 | n/a | start = next; |
|---|
| 3742 | n/a | } |
|---|
| 3743 | n/a | } |
|---|
| 3744 | n/a | |
|---|
| 3745 | n/a | #endif /* XML_DTD */ |
|---|
| 3746 | n/a | |
|---|
| 3747 | n/a | static enum XML_Error PTRCALL |
|---|
| 3748 | n/a | prologProcessor(XML_Parser parser, |
|---|
| 3749 | n/a | const char *s, |
|---|
| 3750 | n/a | const char *end, |
|---|
| 3751 | n/a | const char **nextPtr) |
|---|
| 3752 | n/a | { |
|---|
| 3753 | n/a | const char *next = s; |
|---|
| 3754 | n/a | int tok = XmlPrologTok(encoding, s, end, &next); |
|---|
| 3755 | n/a | return doProlog(parser, encoding, s, end, tok, next, |
|---|
| 3756 | n/a | nextPtr, (XML_Bool)!ps_finalBuffer); |
|---|
| 3757 | n/a | } |
|---|
| 3758 | n/a | |
|---|
| 3759 | n/a | static enum XML_Error |
|---|
| 3760 | n/a | doProlog(XML_Parser parser, |
|---|
| 3761 | n/a | const ENCODING *enc, |
|---|
| 3762 | n/a | const char *s, |
|---|
| 3763 | n/a | const char *end, |
|---|
| 3764 | n/a | int tok, |
|---|
| 3765 | n/a | const char *next, |
|---|
| 3766 | n/a | const char **nextPtr, |
|---|
| 3767 | n/a | XML_Bool haveMore) |
|---|
| 3768 | n/a | { |
|---|
| 3769 | n/a | #ifdef XML_DTD |
|---|
| 3770 | n/a | static const XML_Char externalSubsetName[] = { ASCII_HASH , '\0' }; |
|---|
| 3771 | n/a | #endif /* XML_DTD */ |
|---|
| 3772 | n/a | static const XML_Char atypeCDATA[] = |
|---|
| 3773 | n/a | { ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; |
|---|
| 3774 | n/a | static const XML_Char atypeID[] = { ASCII_I, ASCII_D, '\0' }; |
|---|
| 3775 | n/a | static const XML_Char atypeIDREF[] = |
|---|
| 3776 | n/a | { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' }; |
|---|
| 3777 | n/a | static const XML_Char atypeIDREFS[] = |
|---|
| 3778 | n/a | { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' }; |
|---|
| 3779 | n/a | static const XML_Char atypeENTITY[] = |
|---|
| 3780 | n/a | { ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' }; |
|---|
| 3781 | n/a | static const XML_Char atypeENTITIES[] = { ASCII_E, ASCII_N, |
|---|
| 3782 | n/a | ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, '\0' }; |
|---|
| 3783 | n/a | static const XML_Char atypeNMTOKEN[] = { |
|---|
| 3784 | n/a | ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' }; |
|---|
| 3785 | n/a | static const XML_Char atypeNMTOKENS[] = { ASCII_N, ASCII_M, ASCII_T, |
|---|
| 3786 | n/a | ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, '\0' }; |
|---|
| 3787 | n/a | static const XML_Char notationPrefix[] = { ASCII_N, ASCII_O, ASCII_T, |
|---|
| 3788 | n/a | ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, ASCII_LPAREN, '\0' }; |
|---|
| 3789 | n/a | static const XML_Char enumValueSep[] = { ASCII_PIPE, '\0' }; |
|---|
| 3790 | n/a | static const XML_Char enumValueStart[] = { ASCII_LPAREN, '\0' }; |
|---|
| 3791 | n/a | |
|---|
| 3792 | n/a | /* save one level of indirection */ |
|---|
| 3793 | n/a | DTD * const dtd = _dtd; |
|---|
| 3794 | n/a | |
|---|
| 3795 | n/a | const char **eventPP; |
|---|
| 3796 | n/a | const char **eventEndPP; |
|---|
| 3797 | n/a | enum XML_Content_Quant quant; |
|---|
| 3798 | n/a | |
|---|
| 3799 | n/a | if (enc == encoding) { |
|---|
| 3800 | n/a | eventPP = &eventPtr; |
|---|
| 3801 | n/a | eventEndPP = &eventEndPtr; |
|---|
| 3802 | n/a | } |
|---|
| 3803 | n/a | else { |
|---|
| 3804 | n/a | eventPP = &(openInternalEntities->internalEventPtr); |
|---|
| 3805 | n/a | eventEndPP = &(openInternalEntities->internalEventEndPtr); |
|---|
| 3806 | n/a | } |
|---|
| 3807 | n/a | |
|---|
| 3808 | n/a | for (;;) { |
|---|
| 3809 | n/a | int role; |
|---|
| 3810 | n/a | XML_Bool handleDefault = XML_TRUE; |
|---|
| 3811 | n/a | *eventPP = s; |
|---|
| 3812 | n/a | *eventEndPP = next; |
|---|
| 3813 | n/a | if (tok <= 0) { |
|---|
| 3814 | n/a | if (haveMore && tok != XML_TOK_INVALID) { |
|---|
| 3815 | n/a | *nextPtr = s; |
|---|
| 3816 | n/a | return XML_ERROR_NONE; |
|---|
| 3817 | n/a | } |
|---|
| 3818 | n/a | switch (tok) { |
|---|
| 3819 | n/a | case XML_TOK_INVALID: |
|---|
| 3820 | n/a | *eventPP = next; |
|---|
| 3821 | n/a | return XML_ERROR_INVALID_TOKEN; |
|---|
| 3822 | n/a | case XML_TOK_PARTIAL: |
|---|
| 3823 | n/a | return XML_ERROR_UNCLOSED_TOKEN; |
|---|
| 3824 | n/a | case XML_TOK_PARTIAL_CHAR: |
|---|
| 3825 | n/a | return XML_ERROR_PARTIAL_CHAR; |
|---|
| 3826 | n/a | case -XML_TOK_PROLOG_S: |
|---|
| 3827 | n/a | tok = -tok; |
|---|
| 3828 | n/a | break; |
|---|
| 3829 | n/a | case XML_TOK_NONE: |
|---|
| 3830 | n/a | #ifdef XML_DTD |
|---|
| 3831 | n/a | /* for internal PE NOT referenced between declarations */ |
|---|
| 3832 | n/a | if (enc != encoding && !openInternalEntities->betweenDecl) { |
|---|
| 3833 | n/a | *nextPtr = s; |
|---|
| 3834 | n/a | return XML_ERROR_NONE; |
|---|
| 3835 | n/a | } |
|---|
| 3836 | n/a | /* WFC: PE Between Declarations - must check that PE contains |
|---|
| 3837 | n/a | complete markup, not only for external PEs, but also for |
|---|
| 3838 | n/a | internal PEs if the reference occurs between declarations. |
|---|
| 3839 | n/a | */ |
|---|
| 3840 | n/a | if (isParamEntity || enc != encoding) { |
|---|
| 3841 | n/a | if (XmlTokenRole(&prologState, XML_TOK_NONE, end, end, enc) |
|---|
| 3842 | n/a | == XML_ROLE_ERROR) |
|---|
| 3843 | n/a | return XML_ERROR_INCOMPLETE_PE; |
|---|
| 3844 | n/a | *nextPtr = s; |
|---|
| 3845 | n/a | return XML_ERROR_NONE; |
|---|
| 3846 | n/a | } |
|---|
| 3847 | n/a | #endif /* XML_DTD */ |
|---|
| 3848 | n/a | return XML_ERROR_NO_ELEMENTS; |
|---|
| 3849 | n/a | default: |
|---|
| 3850 | n/a | tok = -tok; |
|---|
| 3851 | n/a | next = end; |
|---|
| 3852 | n/a | break; |
|---|
| 3853 | n/a | } |
|---|
| 3854 | n/a | } |
|---|
| 3855 | n/a | role = XmlTokenRole(&prologState, tok, s, next, enc); |
|---|
| 3856 | n/a | switch (role) { |
|---|
| 3857 | n/a | case XML_ROLE_XML_DECL: |
|---|
| 3858 | n/a | { |
|---|
| 3859 | n/a | enum XML_Error result = processXmlDecl(parser, 0, s, next); |
|---|
| 3860 | n/a | if (result != XML_ERROR_NONE) |
|---|
| 3861 | n/a | return result; |
|---|
| 3862 | n/a | enc = encoding; |
|---|
| 3863 | n/a | handleDefault = XML_FALSE; |
|---|
| 3864 | n/a | } |
|---|
| 3865 | n/a | break; |
|---|
| 3866 | n/a | case XML_ROLE_DOCTYPE_NAME: |
|---|
| 3867 | n/a | if (startDoctypeDeclHandler) { |
|---|
| 3868 | n/a | doctypeName = poolStoreString(&tempPool, enc, s, next); |
|---|
| 3869 | n/a | if (!doctypeName) |
|---|
| 3870 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 3871 | n/a | poolFinish(&tempPool); |
|---|
| 3872 | n/a | doctypePubid = NULL; |
|---|
| 3873 | n/a | handleDefault = XML_FALSE; |
|---|
| 3874 | n/a | } |
|---|
| 3875 | n/a | doctypeSysid = NULL; /* always initialize to NULL */ |
|---|
| 3876 | n/a | break; |
|---|
| 3877 | n/a | case XML_ROLE_DOCTYPE_INTERNAL_SUBSET: |
|---|
| 3878 | n/a | if (startDoctypeDeclHandler) { |
|---|
| 3879 | n/a | startDoctypeDeclHandler(handlerArg, doctypeName, doctypeSysid, |
|---|
| 3880 | n/a | doctypePubid, 1); |
|---|
| 3881 | n/a | doctypeName = NULL; |
|---|
| 3882 | n/a | poolClear(&tempPool); |
|---|
| 3883 | n/a | handleDefault = XML_FALSE; |
|---|
| 3884 | n/a | } |
|---|
| 3885 | n/a | break; |
|---|
| 3886 | n/a | #ifdef XML_DTD |
|---|
| 3887 | n/a | case XML_ROLE_TEXT_DECL: |
|---|
| 3888 | n/a | { |
|---|
| 3889 | n/a | enum XML_Error result = processXmlDecl(parser, 1, s, next); |
|---|
| 3890 | n/a | if (result != XML_ERROR_NONE) |
|---|
| 3891 | n/a | return result; |
|---|
| 3892 | n/a | enc = encoding; |
|---|
| 3893 | n/a | handleDefault = XML_FALSE; |
|---|
| 3894 | n/a | } |
|---|
| 3895 | n/a | break; |
|---|
| 3896 | n/a | #endif /* XML_DTD */ |
|---|
| 3897 | n/a | case XML_ROLE_DOCTYPE_PUBLIC_ID: |
|---|
| 3898 | n/a | #ifdef XML_DTD |
|---|
| 3899 | n/a | useForeignDTD = XML_FALSE; |
|---|
| 3900 | n/a | declEntity = (ENTITY *)lookup(parser, |
|---|
| 3901 | n/a | &dtd->paramEntities, |
|---|
| 3902 | n/a | externalSubsetName, |
|---|
| 3903 | n/a | sizeof(ENTITY)); |
|---|
| 3904 | n/a | if (!declEntity) |
|---|
| 3905 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 3906 | n/a | #endif /* XML_DTD */ |
|---|
| 3907 | n/a | dtd->hasParamEntityRefs = XML_TRUE; |
|---|
| 3908 | n/a | if (startDoctypeDeclHandler) { |
|---|
| 3909 | n/a | XML_Char *pubId; |
|---|
| 3910 | n/a | if (!XmlIsPublicId(enc, s, next, eventPP)) |
|---|
| 3911 | n/a | return XML_ERROR_PUBLICID; |
|---|
| 3912 | n/a | pubId = poolStoreString(&tempPool, enc, |
|---|
| 3913 | n/a | s + enc->minBytesPerChar, |
|---|
| 3914 | n/a | next - enc->minBytesPerChar); |
|---|
| 3915 | n/a | if (!pubId) |
|---|
| 3916 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 3917 | n/a | normalizePublicId(pubId); |
|---|
| 3918 | n/a | poolFinish(&tempPool); |
|---|
| 3919 | n/a | doctypePubid = pubId; |
|---|
| 3920 | n/a | handleDefault = XML_FALSE; |
|---|
| 3921 | n/a | goto alreadyChecked; |
|---|
| 3922 | n/a | } |
|---|
| 3923 | n/a | /* fall through */ |
|---|
| 3924 | n/a | case XML_ROLE_ENTITY_PUBLIC_ID: |
|---|
| 3925 | n/a | if (!XmlIsPublicId(enc, s, next, eventPP)) |
|---|
| 3926 | n/a | return XML_ERROR_PUBLICID; |
|---|
| 3927 | n/a | alreadyChecked: |
|---|
| 3928 | n/a | if (dtd->keepProcessing && declEntity) { |
|---|
| 3929 | n/a | XML_Char *tem = poolStoreString(&dtd->pool, |
|---|
| 3930 | n/a | enc, |
|---|
| 3931 | n/a | s + enc->minBytesPerChar, |
|---|
| 3932 | n/a | next - enc->minBytesPerChar); |
|---|
| 3933 | n/a | if (!tem) |
|---|
| 3934 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 3935 | n/a | normalizePublicId(tem); |
|---|
| 3936 | n/a | declEntity->publicId = tem; |
|---|
| 3937 | n/a | poolFinish(&dtd->pool); |
|---|
| 3938 | n/a | if (entityDeclHandler) |
|---|
| 3939 | n/a | handleDefault = XML_FALSE; |
|---|
| 3940 | n/a | } |
|---|
| 3941 | n/a | break; |
|---|
| 3942 | n/a | case XML_ROLE_DOCTYPE_CLOSE: |
|---|
| 3943 | n/a | if (doctypeName) { |
|---|
| 3944 | n/a | startDoctypeDeclHandler(handlerArg, doctypeName, |
|---|
| 3945 | n/a | doctypeSysid, doctypePubid, 0); |
|---|
| 3946 | n/a | poolClear(&tempPool); |
|---|
| 3947 | n/a | handleDefault = XML_FALSE; |
|---|
| 3948 | n/a | } |
|---|
| 3949 | n/a | /* doctypeSysid will be non-NULL in the case of a previous |
|---|
| 3950 | n/a | XML_ROLE_DOCTYPE_SYSTEM_ID, even if startDoctypeDeclHandler |
|---|
| 3951 | n/a | was not set, indicating an external subset |
|---|
| 3952 | n/a | */ |
|---|
| 3953 | n/a | #ifdef XML_DTD |
|---|
| 3954 | n/a | if (doctypeSysid || useForeignDTD) { |
|---|
| 3955 | n/a | XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; |
|---|
| 3956 | n/a | dtd->hasParamEntityRefs = XML_TRUE; |
|---|
| 3957 | n/a | if (paramEntityParsing && externalEntityRefHandler) { |
|---|
| 3958 | n/a | ENTITY *entity = (ENTITY *)lookup(parser, |
|---|
| 3959 | n/a | &dtd->paramEntities, |
|---|
| 3960 | n/a | externalSubsetName, |
|---|
| 3961 | n/a | sizeof(ENTITY)); |
|---|
| 3962 | n/a | if (!entity) |
|---|
| 3963 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 3964 | n/a | if (useForeignDTD) |
|---|
| 3965 | n/a | entity->base = curBase; |
|---|
| 3966 | n/a | dtd->paramEntityRead = XML_FALSE; |
|---|
| 3967 | n/a | if (!externalEntityRefHandler(externalEntityRefHandlerArg, |
|---|
| 3968 | n/a | 0, |
|---|
| 3969 | n/a | entity->base, |
|---|
| 3970 | n/a | entity->systemId, |
|---|
| 3971 | n/a | entity->publicId)) |
|---|
| 3972 | n/a | return XML_ERROR_EXTERNAL_ENTITY_HANDLING; |
|---|
| 3973 | n/a | if (dtd->paramEntityRead) { |
|---|
| 3974 | n/a | if (!dtd->standalone && |
|---|
| 3975 | n/a | notStandaloneHandler && |
|---|
| 3976 | n/a | !notStandaloneHandler(handlerArg)) |
|---|
| 3977 | n/a | return XML_ERROR_NOT_STANDALONE; |
|---|
| 3978 | n/a | } |
|---|
| 3979 | n/a | /* if we didn't read the foreign DTD then this means that there |
|---|
| 3980 | n/a | is no external subset and we must reset dtd->hasParamEntityRefs |
|---|
| 3981 | n/a | */ |
|---|
| 3982 | n/a | else if (!doctypeSysid) |
|---|
| 3983 | n/a | dtd->hasParamEntityRefs = hadParamEntityRefs; |
|---|
| 3984 | n/a | /* end of DTD - no need to update dtd->keepProcessing */ |
|---|
| 3985 | n/a | } |
|---|
| 3986 | n/a | useForeignDTD = XML_FALSE; |
|---|
| 3987 | n/a | } |
|---|
| 3988 | n/a | #endif /* XML_DTD */ |
|---|
| 3989 | n/a | if (endDoctypeDeclHandler) { |
|---|
| 3990 | n/a | endDoctypeDeclHandler(handlerArg); |
|---|
| 3991 | n/a | handleDefault = XML_FALSE; |
|---|
| 3992 | n/a | } |
|---|
| 3993 | n/a | break; |
|---|
| 3994 | n/a | case XML_ROLE_INSTANCE_START: |
|---|
| 3995 | n/a | #ifdef XML_DTD |
|---|
| 3996 | n/a | /* if there is no DOCTYPE declaration then now is the |
|---|
| 3997 | n/a | last chance to read the foreign DTD |
|---|
| 3998 | n/a | */ |
|---|
| 3999 | n/a | if (useForeignDTD) { |
|---|
| 4000 | n/a | XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; |
|---|
| 4001 | n/a | dtd->hasParamEntityRefs = XML_TRUE; |
|---|
| 4002 | n/a | if (paramEntityParsing && externalEntityRefHandler) { |
|---|
| 4003 | n/a | ENTITY *entity = (ENTITY *)lookup(parser, &dtd->paramEntities, |
|---|
| 4004 | n/a | externalSubsetName, |
|---|
| 4005 | n/a | sizeof(ENTITY)); |
|---|
| 4006 | n/a | if (!entity) |
|---|
| 4007 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4008 | n/a | entity->base = curBase; |
|---|
| 4009 | n/a | dtd->paramEntityRead = XML_FALSE; |
|---|
| 4010 | n/a | if (!externalEntityRefHandler(externalEntityRefHandlerArg, |
|---|
| 4011 | n/a | 0, |
|---|
| 4012 | n/a | entity->base, |
|---|
| 4013 | n/a | entity->systemId, |
|---|
| 4014 | n/a | entity->publicId)) |
|---|
| 4015 | n/a | return XML_ERROR_EXTERNAL_ENTITY_HANDLING; |
|---|
| 4016 | n/a | if (dtd->paramEntityRead) { |
|---|
| 4017 | n/a | if (!dtd->standalone && |
|---|
| 4018 | n/a | notStandaloneHandler && |
|---|
| 4019 | n/a | !notStandaloneHandler(handlerArg)) |
|---|
| 4020 | n/a | return XML_ERROR_NOT_STANDALONE; |
|---|
| 4021 | n/a | } |
|---|
| 4022 | n/a | /* if we didn't read the foreign DTD then this means that there |
|---|
| 4023 | n/a | is no external subset and we must reset dtd->hasParamEntityRefs |
|---|
| 4024 | n/a | */ |
|---|
| 4025 | n/a | else |
|---|
| 4026 | n/a | dtd->hasParamEntityRefs = hadParamEntityRefs; |
|---|
| 4027 | n/a | /* end of DTD - no need to update dtd->keepProcessing */ |
|---|
| 4028 | n/a | } |
|---|
| 4029 | n/a | } |
|---|
| 4030 | n/a | #endif /* XML_DTD */ |
|---|
| 4031 | n/a | processor = contentProcessor; |
|---|
| 4032 | n/a | return contentProcessor(parser, s, end, nextPtr); |
|---|
| 4033 | n/a | case XML_ROLE_ATTLIST_ELEMENT_NAME: |
|---|
| 4034 | n/a | declElementType = getElementType(parser, enc, s, next); |
|---|
| 4035 | n/a | if (!declElementType) |
|---|
| 4036 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4037 | n/a | goto checkAttListDeclHandler; |
|---|
| 4038 | n/a | case XML_ROLE_ATTRIBUTE_NAME: |
|---|
| 4039 | n/a | declAttributeId = getAttributeId(parser, enc, s, next); |
|---|
| 4040 | n/a | if (!declAttributeId) |
|---|
| 4041 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4042 | n/a | declAttributeIsCdata = XML_FALSE; |
|---|
| 4043 | n/a | declAttributeType = NULL; |
|---|
| 4044 | n/a | declAttributeIsId = XML_FALSE; |
|---|
| 4045 | n/a | goto checkAttListDeclHandler; |
|---|
| 4046 | n/a | case XML_ROLE_ATTRIBUTE_TYPE_CDATA: |
|---|
| 4047 | n/a | declAttributeIsCdata = XML_TRUE; |
|---|
| 4048 | n/a | declAttributeType = atypeCDATA; |
|---|
| 4049 | n/a | goto checkAttListDeclHandler; |
|---|
| 4050 | n/a | case XML_ROLE_ATTRIBUTE_TYPE_ID: |
|---|
| 4051 | n/a | declAttributeIsId = XML_TRUE; |
|---|
| 4052 | n/a | declAttributeType = atypeID; |
|---|
| 4053 | n/a | goto checkAttListDeclHandler; |
|---|
| 4054 | n/a | case XML_ROLE_ATTRIBUTE_TYPE_IDREF: |
|---|
| 4055 | n/a | declAttributeType = atypeIDREF; |
|---|
| 4056 | n/a | goto checkAttListDeclHandler; |
|---|
| 4057 | n/a | case XML_ROLE_ATTRIBUTE_TYPE_IDREFS: |
|---|
| 4058 | n/a | declAttributeType = atypeIDREFS; |
|---|
| 4059 | n/a | goto checkAttListDeclHandler; |
|---|
| 4060 | n/a | case XML_ROLE_ATTRIBUTE_TYPE_ENTITY: |
|---|
| 4061 | n/a | declAttributeType = atypeENTITY; |
|---|
| 4062 | n/a | goto checkAttListDeclHandler; |
|---|
| 4063 | n/a | case XML_ROLE_ATTRIBUTE_TYPE_ENTITIES: |
|---|
| 4064 | n/a | declAttributeType = atypeENTITIES; |
|---|
| 4065 | n/a | goto checkAttListDeclHandler; |
|---|
| 4066 | n/a | case XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN: |
|---|
| 4067 | n/a | declAttributeType = atypeNMTOKEN; |
|---|
| 4068 | n/a | goto checkAttListDeclHandler; |
|---|
| 4069 | n/a | case XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS: |
|---|
| 4070 | n/a | declAttributeType = atypeNMTOKENS; |
|---|
| 4071 | n/a | checkAttListDeclHandler: |
|---|
| 4072 | n/a | if (dtd->keepProcessing && attlistDeclHandler) |
|---|
| 4073 | n/a | handleDefault = XML_FALSE; |
|---|
| 4074 | n/a | break; |
|---|
| 4075 | n/a | case XML_ROLE_ATTRIBUTE_ENUM_VALUE: |
|---|
| 4076 | n/a | case XML_ROLE_ATTRIBUTE_NOTATION_VALUE: |
|---|
| 4077 | n/a | if (dtd->keepProcessing && attlistDeclHandler) { |
|---|
| 4078 | n/a | const XML_Char *prefix; |
|---|
| 4079 | n/a | if (declAttributeType) { |
|---|
| 4080 | n/a | prefix = enumValueSep; |
|---|
| 4081 | n/a | } |
|---|
| 4082 | n/a | else { |
|---|
| 4083 | n/a | prefix = (role == XML_ROLE_ATTRIBUTE_NOTATION_VALUE |
|---|
| 4084 | n/a | ? notationPrefix |
|---|
| 4085 | n/a | : enumValueStart); |
|---|
| 4086 | n/a | } |
|---|
| 4087 | n/a | if (!poolAppendString(&tempPool, prefix)) |
|---|
| 4088 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4089 | n/a | if (!poolAppend(&tempPool, enc, s, next)) |
|---|
| 4090 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4091 | n/a | declAttributeType = tempPool.start; |
|---|
| 4092 | n/a | handleDefault = XML_FALSE; |
|---|
| 4093 | n/a | } |
|---|
| 4094 | n/a | break; |
|---|
| 4095 | n/a | case XML_ROLE_IMPLIED_ATTRIBUTE_VALUE: |
|---|
| 4096 | n/a | case XML_ROLE_REQUIRED_ATTRIBUTE_VALUE: |
|---|
| 4097 | n/a | if (dtd->keepProcessing) { |
|---|
| 4098 | n/a | if (!defineAttribute(declElementType, declAttributeId, |
|---|
| 4099 | n/a | declAttributeIsCdata, declAttributeIsId, |
|---|
| 4100 | n/a | 0, parser)) |
|---|
| 4101 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4102 | n/a | if (attlistDeclHandler && declAttributeType) { |
|---|
| 4103 | n/a | if (*declAttributeType == XML_T(ASCII_LPAREN) |
|---|
| 4104 | n/a | || (*declAttributeType == XML_T(ASCII_N) |
|---|
| 4105 | n/a | && declAttributeType[1] == XML_T(ASCII_O))) { |
|---|
| 4106 | n/a | /* Enumerated or Notation type */ |
|---|
| 4107 | n/a | if (!poolAppendChar(&tempPool, XML_T(ASCII_RPAREN)) |
|---|
| 4108 | n/a | || !poolAppendChar(&tempPool, XML_T('\0'))) |
|---|
| 4109 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4110 | n/a | declAttributeType = tempPool.start; |
|---|
| 4111 | n/a | poolFinish(&tempPool); |
|---|
| 4112 | n/a | } |
|---|
| 4113 | n/a | *eventEndPP = s; |
|---|
| 4114 | n/a | attlistDeclHandler(handlerArg, declElementType->name, |
|---|
| 4115 | n/a | declAttributeId->name, declAttributeType, |
|---|
| 4116 | n/a | 0, role == XML_ROLE_REQUIRED_ATTRIBUTE_VALUE); |
|---|
| 4117 | n/a | poolClear(&tempPool); |
|---|
| 4118 | n/a | handleDefault = XML_FALSE; |
|---|
| 4119 | n/a | } |
|---|
| 4120 | n/a | } |
|---|
| 4121 | n/a | break; |
|---|
| 4122 | n/a | case XML_ROLE_DEFAULT_ATTRIBUTE_VALUE: |
|---|
| 4123 | n/a | case XML_ROLE_FIXED_ATTRIBUTE_VALUE: |
|---|
| 4124 | n/a | if (dtd->keepProcessing) { |
|---|
| 4125 | n/a | const XML_Char *attVal; |
|---|
| 4126 | n/a | enum XML_Error result = |
|---|
| 4127 | n/a | storeAttributeValue(parser, enc, declAttributeIsCdata, |
|---|
| 4128 | n/a | s + enc->minBytesPerChar, |
|---|
| 4129 | n/a | next - enc->minBytesPerChar, |
|---|
| 4130 | n/a | &dtd->pool); |
|---|
| 4131 | n/a | if (result) |
|---|
| 4132 | n/a | return result; |
|---|
| 4133 | n/a | attVal = poolStart(&dtd->pool); |
|---|
| 4134 | n/a | poolFinish(&dtd->pool); |
|---|
| 4135 | n/a | /* ID attributes aren't allowed to have a default */ |
|---|
| 4136 | n/a | if (!defineAttribute(declElementType, declAttributeId, |
|---|
| 4137 | n/a | declAttributeIsCdata, XML_FALSE, attVal, parser)) |
|---|
| 4138 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4139 | n/a | if (attlistDeclHandler && declAttributeType) { |
|---|
| 4140 | n/a | if (*declAttributeType == XML_T(ASCII_LPAREN) |
|---|
| 4141 | n/a | || (*declAttributeType == XML_T(ASCII_N) |
|---|
| 4142 | n/a | && declAttributeType[1] == XML_T(ASCII_O))) { |
|---|
| 4143 | n/a | /* Enumerated or Notation type */ |
|---|
| 4144 | n/a | if (!poolAppendChar(&tempPool, XML_T(ASCII_RPAREN)) |
|---|
| 4145 | n/a | || !poolAppendChar(&tempPool, XML_T('\0'))) |
|---|
| 4146 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4147 | n/a | declAttributeType = tempPool.start; |
|---|
| 4148 | n/a | poolFinish(&tempPool); |
|---|
| 4149 | n/a | } |
|---|
| 4150 | n/a | *eventEndPP = s; |
|---|
| 4151 | n/a | attlistDeclHandler(handlerArg, declElementType->name, |
|---|
| 4152 | n/a | declAttributeId->name, declAttributeType, |
|---|
| 4153 | n/a | attVal, |
|---|
| 4154 | n/a | role == XML_ROLE_FIXED_ATTRIBUTE_VALUE); |
|---|
| 4155 | n/a | poolClear(&tempPool); |
|---|
| 4156 | n/a | handleDefault = XML_FALSE; |
|---|
| 4157 | n/a | } |
|---|
| 4158 | n/a | } |
|---|
| 4159 | n/a | break; |
|---|
| 4160 | n/a | case XML_ROLE_ENTITY_VALUE: |
|---|
| 4161 | n/a | if (dtd->keepProcessing) { |
|---|
| 4162 | n/a | enum XML_Error result = storeEntityValue(parser, enc, |
|---|
| 4163 | n/a | s + enc->minBytesPerChar, |
|---|
| 4164 | n/a | next - enc->minBytesPerChar); |
|---|
| 4165 | n/a | if (declEntity) { |
|---|
| 4166 | n/a | declEntity->textPtr = poolStart(&dtd->entityValuePool); |
|---|
| 4167 | n/a | declEntity->textLen = (int)(poolLength(&dtd->entityValuePool)); |
|---|
| 4168 | n/a | poolFinish(&dtd->entityValuePool); |
|---|
| 4169 | n/a | if (entityDeclHandler) { |
|---|
| 4170 | n/a | *eventEndPP = s; |
|---|
| 4171 | n/a | entityDeclHandler(handlerArg, |
|---|
| 4172 | n/a | declEntity->name, |
|---|
| 4173 | n/a | declEntity->is_param, |
|---|
| 4174 | n/a | declEntity->textPtr, |
|---|
| 4175 | n/a | declEntity->textLen, |
|---|
| 4176 | n/a | curBase, 0, 0, 0); |
|---|
| 4177 | n/a | handleDefault = XML_FALSE; |
|---|
| 4178 | n/a | } |
|---|
| 4179 | n/a | } |
|---|
| 4180 | n/a | else |
|---|
| 4181 | n/a | poolDiscard(&dtd->entityValuePool); |
|---|
| 4182 | n/a | if (result != XML_ERROR_NONE) |
|---|
| 4183 | n/a | return result; |
|---|
| 4184 | n/a | } |
|---|
| 4185 | n/a | break; |
|---|
| 4186 | n/a | case XML_ROLE_DOCTYPE_SYSTEM_ID: |
|---|
| 4187 | n/a | #ifdef XML_DTD |
|---|
| 4188 | n/a | useForeignDTD = XML_FALSE; |
|---|
| 4189 | n/a | #endif /* XML_DTD */ |
|---|
| 4190 | n/a | dtd->hasParamEntityRefs = XML_TRUE; |
|---|
| 4191 | n/a | if (startDoctypeDeclHandler) { |
|---|
| 4192 | n/a | doctypeSysid = poolStoreString(&tempPool, enc, |
|---|
| 4193 | n/a | s + enc->minBytesPerChar, |
|---|
| 4194 | n/a | next - enc->minBytesPerChar); |
|---|
| 4195 | n/a | if (doctypeSysid == NULL) |
|---|
| 4196 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4197 | n/a | poolFinish(&tempPool); |
|---|
| 4198 | n/a | handleDefault = XML_FALSE; |
|---|
| 4199 | n/a | } |
|---|
| 4200 | n/a | #ifdef XML_DTD |
|---|
| 4201 | n/a | else |
|---|
| 4202 | n/a | /* use externalSubsetName to make doctypeSysid non-NULL |
|---|
| 4203 | n/a | for the case where no startDoctypeDeclHandler is set */ |
|---|
| 4204 | n/a | doctypeSysid = externalSubsetName; |
|---|
| 4205 | n/a | #endif /* XML_DTD */ |
|---|
| 4206 | n/a | if (!dtd->standalone |
|---|
| 4207 | n/a | #ifdef XML_DTD |
|---|
| 4208 | n/a | && !paramEntityParsing |
|---|
| 4209 | n/a | #endif /* XML_DTD */ |
|---|
| 4210 | n/a | && notStandaloneHandler |
|---|
| 4211 | n/a | && !notStandaloneHandler(handlerArg)) |
|---|
| 4212 | n/a | return XML_ERROR_NOT_STANDALONE; |
|---|
| 4213 | n/a | #ifndef XML_DTD |
|---|
| 4214 | n/a | break; |
|---|
| 4215 | n/a | #else /* XML_DTD */ |
|---|
| 4216 | n/a | if (!declEntity) { |
|---|
| 4217 | n/a | declEntity = (ENTITY *)lookup(parser, |
|---|
| 4218 | n/a | &dtd->paramEntities, |
|---|
| 4219 | n/a | externalSubsetName, |
|---|
| 4220 | n/a | sizeof(ENTITY)); |
|---|
| 4221 | n/a | if (!declEntity) |
|---|
| 4222 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4223 | n/a | declEntity->publicId = NULL; |
|---|
| 4224 | n/a | } |
|---|
| 4225 | n/a | /* fall through */ |
|---|
| 4226 | n/a | #endif /* XML_DTD */ |
|---|
| 4227 | n/a | case XML_ROLE_ENTITY_SYSTEM_ID: |
|---|
| 4228 | n/a | if (dtd->keepProcessing && declEntity) { |
|---|
| 4229 | n/a | declEntity->systemId = poolStoreString(&dtd->pool, enc, |
|---|
| 4230 | n/a | s + enc->minBytesPerChar, |
|---|
| 4231 | n/a | next - enc->minBytesPerChar); |
|---|
| 4232 | n/a | if (!declEntity->systemId) |
|---|
| 4233 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4234 | n/a | declEntity->base = curBase; |
|---|
| 4235 | n/a | poolFinish(&dtd->pool); |
|---|
| 4236 | n/a | if (entityDeclHandler) |
|---|
| 4237 | n/a | handleDefault = XML_FALSE; |
|---|
| 4238 | n/a | } |
|---|
| 4239 | n/a | break; |
|---|
| 4240 | n/a | case XML_ROLE_ENTITY_COMPLETE: |
|---|
| 4241 | n/a | if (dtd->keepProcessing && declEntity && entityDeclHandler) { |
|---|
| 4242 | n/a | *eventEndPP = s; |
|---|
| 4243 | n/a | entityDeclHandler(handlerArg, |
|---|
| 4244 | n/a | declEntity->name, |
|---|
| 4245 | n/a | declEntity->is_param, |
|---|
| 4246 | n/a | 0,0, |
|---|
| 4247 | n/a | declEntity->base, |
|---|
| 4248 | n/a | declEntity->systemId, |
|---|
| 4249 | n/a | declEntity->publicId, |
|---|
| 4250 | n/a | 0); |
|---|
| 4251 | n/a | handleDefault = XML_FALSE; |
|---|
| 4252 | n/a | } |
|---|
| 4253 | n/a | break; |
|---|
| 4254 | n/a | case XML_ROLE_ENTITY_NOTATION_NAME: |
|---|
| 4255 | n/a | if (dtd->keepProcessing && declEntity) { |
|---|
| 4256 | n/a | declEntity->notation = poolStoreString(&dtd->pool, enc, s, next); |
|---|
| 4257 | n/a | if (!declEntity->notation) |
|---|
| 4258 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4259 | n/a | poolFinish(&dtd->pool); |
|---|
| 4260 | n/a | if (unparsedEntityDeclHandler) { |
|---|
| 4261 | n/a | *eventEndPP = s; |
|---|
| 4262 | n/a | unparsedEntityDeclHandler(handlerArg, |
|---|
| 4263 | n/a | declEntity->name, |
|---|
| 4264 | n/a | declEntity->base, |
|---|
| 4265 | n/a | declEntity->systemId, |
|---|
| 4266 | n/a | declEntity->publicId, |
|---|
| 4267 | n/a | declEntity->notation); |
|---|
| 4268 | n/a | handleDefault = XML_FALSE; |
|---|
| 4269 | n/a | } |
|---|
| 4270 | n/a | else if (entityDeclHandler) { |
|---|
| 4271 | n/a | *eventEndPP = s; |
|---|
| 4272 | n/a | entityDeclHandler(handlerArg, |
|---|
| 4273 | n/a | declEntity->name, |
|---|
| 4274 | n/a | 0,0,0, |
|---|
| 4275 | n/a | declEntity->base, |
|---|
| 4276 | n/a | declEntity->systemId, |
|---|
| 4277 | n/a | declEntity->publicId, |
|---|
| 4278 | n/a | declEntity->notation); |
|---|
| 4279 | n/a | handleDefault = XML_FALSE; |
|---|
| 4280 | n/a | } |
|---|
| 4281 | n/a | } |
|---|
| 4282 | n/a | break; |
|---|
| 4283 | n/a | case XML_ROLE_GENERAL_ENTITY_NAME: |
|---|
| 4284 | n/a | { |
|---|
| 4285 | n/a | if (XmlPredefinedEntityName(enc, s, next)) { |
|---|
| 4286 | n/a | declEntity = NULL; |
|---|
| 4287 | n/a | break; |
|---|
| 4288 | n/a | } |
|---|
| 4289 | n/a | if (dtd->keepProcessing) { |
|---|
| 4290 | n/a | const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); |
|---|
| 4291 | n/a | if (!name) |
|---|
| 4292 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4293 | n/a | declEntity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, |
|---|
| 4294 | n/a | sizeof(ENTITY)); |
|---|
| 4295 | n/a | if (!declEntity) |
|---|
| 4296 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4297 | n/a | if (declEntity->name != name) { |
|---|
| 4298 | n/a | poolDiscard(&dtd->pool); |
|---|
| 4299 | n/a | declEntity = NULL; |
|---|
| 4300 | n/a | } |
|---|
| 4301 | n/a | else { |
|---|
| 4302 | n/a | poolFinish(&dtd->pool); |
|---|
| 4303 | n/a | declEntity->publicId = NULL; |
|---|
| 4304 | n/a | declEntity->is_param = XML_FALSE; |
|---|
| 4305 | n/a | /* if we have a parent parser or are reading an internal parameter |
|---|
| 4306 | n/a | entity, then the entity declaration is not considered "internal" |
|---|
| 4307 | n/a | */ |
|---|
| 4308 | n/a | declEntity->is_internal = !(parentParser || openInternalEntities); |
|---|
| 4309 | n/a | if (entityDeclHandler) |
|---|
| 4310 | n/a | handleDefault = XML_FALSE; |
|---|
| 4311 | n/a | } |
|---|
| 4312 | n/a | } |
|---|
| 4313 | n/a | else { |
|---|
| 4314 | n/a | poolDiscard(&dtd->pool); |
|---|
| 4315 | n/a | declEntity = NULL; |
|---|
| 4316 | n/a | } |
|---|
| 4317 | n/a | } |
|---|
| 4318 | n/a | break; |
|---|
| 4319 | n/a | case XML_ROLE_PARAM_ENTITY_NAME: |
|---|
| 4320 | n/a | #ifdef XML_DTD |
|---|
| 4321 | n/a | if (dtd->keepProcessing) { |
|---|
| 4322 | n/a | const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); |
|---|
| 4323 | n/a | if (!name) |
|---|
| 4324 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4325 | n/a | declEntity = (ENTITY *)lookup(parser, &dtd->paramEntities, |
|---|
| 4326 | n/a | name, sizeof(ENTITY)); |
|---|
| 4327 | n/a | if (!declEntity) |
|---|
| 4328 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4329 | n/a | if (declEntity->name != name) { |
|---|
| 4330 | n/a | poolDiscard(&dtd->pool); |
|---|
| 4331 | n/a | declEntity = NULL; |
|---|
| 4332 | n/a | } |
|---|
| 4333 | n/a | else { |
|---|
| 4334 | n/a | poolFinish(&dtd->pool); |
|---|
| 4335 | n/a | declEntity->publicId = NULL; |
|---|
| 4336 | n/a | declEntity->is_param = XML_TRUE; |
|---|
| 4337 | n/a | /* if we have a parent parser or are reading an internal parameter |
|---|
| 4338 | n/a | entity, then the entity declaration is not considered "internal" |
|---|
| 4339 | n/a | */ |
|---|
| 4340 | n/a | declEntity->is_internal = !(parentParser || openInternalEntities); |
|---|
| 4341 | n/a | if (entityDeclHandler) |
|---|
| 4342 | n/a | handleDefault = XML_FALSE; |
|---|
| 4343 | n/a | } |
|---|
| 4344 | n/a | } |
|---|
| 4345 | n/a | else { |
|---|
| 4346 | n/a | poolDiscard(&dtd->pool); |
|---|
| 4347 | n/a | declEntity = NULL; |
|---|
| 4348 | n/a | } |
|---|
| 4349 | n/a | #else /* not XML_DTD */ |
|---|
| 4350 | n/a | declEntity = NULL; |
|---|
| 4351 | n/a | #endif /* XML_DTD */ |
|---|
| 4352 | n/a | break; |
|---|
| 4353 | n/a | case XML_ROLE_NOTATION_NAME: |
|---|
| 4354 | n/a | declNotationPublicId = NULL; |
|---|
| 4355 | n/a | declNotationName = NULL; |
|---|
| 4356 | n/a | if (notationDeclHandler) { |
|---|
| 4357 | n/a | declNotationName = poolStoreString(&tempPool, enc, s, next); |
|---|
| 4358 | n/a | if (!declNotationName) |
|---|
| 4359 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4360 | n/a | poolFinish(&tempPool); |
|---|
| 4361 | n/a | handleDefault = XML_FALSE; |
|---|
| 4362 | n/a | } |
|---|
| 4363 | n/a | break; |
|---|
| 4364 | n/a | case XML_ROLE_NOTATION_PUBLIC_ID: |
|---|
| 4365 | n/a | if (!XmlIsPublicId(enc, s, next, eventPP)) |
|---|
| 4366 | n/a | return XML_ERROR_PUBLICID; |
|---|
| 4367 | n/a | if (declNotationName) { /* means notationDeclHandler != NULL */ |
|---|
| 4368 | n/a | XML_Char *tem = poolStoreString(&tempPool, |
|---|
| 4369 | n/a | enc, |
|---|
| 4370 | n/a | s + enc->minBytesPerChar, |
|---|
| 4371 | n/a | next - enc->minBytesPerChar); |
|---|
| 4372 | n/a | if (!tem) |
|---|
| 4373 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4374 | n/a | normalizePublicId(tem); |
|---|
| 4375 | n/a | declNotationPublicId = tem; |
|---|
| 4376 | n/a | poolFinish(&tempPool); |
|---|
| 4377 | n/a | handleDefault = XML_FALSE; |
|---|
| 4378 | n/a | } |
|---|
| 4379 | n/a | break; |
|---|
| 4380 | n/a | case XML_ROLE_NOTATION_SYSTEM_ID: |
|---|
| 4381 | n/a | if (declNotationName && notationDeclHandler) { |
|---|
| 4382 | n/a | const XML_Char *systemId |
|---|
| 4383 | n/a | = poolStoreString(&tempPool, enc, |
|---|
| 4384 | n/a | s + enc->minBytesPerChar, |
|---|
| 4385 | n/a | next - enc->minBytesPerChar); |
|---|
| 4386 | n/a | if (!systemId) |
|---|
| 4387 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4388 | n/a | *eventEndPP = s; |
|---|
| 4389 | n/a | notationDeclHandler(handlerArg, |
|---|
| 4390 | n/a | declNotationName, |
|---|
| 4391 | n/a | curBase, |
|---|
| 4392 | n/a | systemId, |
|---|
| 4393 | n/a | declNotationPublicId); |
|---|
| 4394 | n/a | handleDefault = XML_FALSE; |
|---|
| 4395 | n/a | } |
|---|
| 4396 | n/a | poolClear(&tempPool); |
|---|
| 4397 | n/a | break; |
|---|
| 4398 | n/a | case XML_ROLE_NOTATION_NO_SYSTEM_ID: |
|---|
| 4399 | n/a | if (declNotationPublicId && notationDeclHandler) { |
|---|
| 4400 | n/a | *eventEndPP = s; |
|---|
| 4401 | n/a | notationDeclHandler(handlerArg, |
|---|
| 4402 | n/a | declNotationName, |
|---|
| 4403 | n/a | curBase, |
|---|
| 4404 | n/a | 0, |
|---|
| 4405 | n/a | declNotationPublicId); |
|---|
| 4406 | n/a | handleDefault = XML_FALSE; |
|---|
| 4407 | n/a | } |
|---|
| 4408 | n/a | poolClear(&tempPool); |
|---|
| 4409 | n/a | break; |
|---|
| 4410 | n/a | case XML_ROLE_ERROR: |
|---|
| 4411 | n/a | switch (tok) { |
|---|
| 4412 | n/a | case XML_TOK_PARAM_ENTITY_REF: |
|---|
| 4413 | n/a | /* PE references in internal subset are |
|---|
| 4414 | n/a | not allowed within declarations. */ |
|---|
| 4415 | n/a | return XML_ERROR_PARAM_ENTITY_REF; |
|---|
| 4416 | n/a | case XML_TOK_XML_DECL: |
|---|
| 4417 | n/a | return XML_ERROR_MISPLACED_XML_PI; |
|---|
| 4418 | n/a | default: |
|---|
| 4419 | n/a | return XML_ERROR_SYNTAX; |
|---|
| 4420 | n/a | } |
|---|
| 4421 | n/a | #ifdef XML_DTD |
|---|
| 4422 | n/a | case XML_ROLE_IGNORE_SECT: |
|---|
| 4423 | n/a | { |
|---|
| 4424 | n/a | enum XML_Error result; |
|---|
| 4425 | n/a | if (defaultHandler) |
|---|
| 4426 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 4427 | n/a | handleDefault = XML_FALSE; |
|---|
| 4428 | n/a | result = doIgnoreSection(parser, enc, &next, end, nextPtr, haveMore); |
|---|
| 4429 | n/a | if (result != XML_ERROR_NONE) |
|---|
| 4430 | n/a | return result; |
|---|
| 4431 | n/a | else if (!next) { |
|---|
| 4432 | n/a | processor = ignoreSectionProcessor; |
|---|
| 4433 | n/a | return result; |
|---|
| 4434 | n/a | } |
|---|
| 4435 | n/a | } |
|---|
| 4436 | n/a | break; |
|---|
| 4437 | n/a | #endif /* XML_DTD */ |
|---|
| 4438 | n/a | case XML_ROLE_GROUP_OPEN: |
|---|
| 4439 | n/a | if (prologState.level >= groupSize) { |
|---|
| 4440 | n/a | if (groupSize) { |
|---|
| 4441 | n/a | char *temp = (char *)REALLOC(groupConnector, groupSize *= 2); |
|---|
| 4442 | n/a | if (temp == NULL) |
|---|
| 4443 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4444 | n/a | groupConnector = temp; |
|---|
| 4445 | n/a | if (dtd->scaffIndex) { |
|---|
| 4446 | n/a | int *temp = (int *)REALLOC(dtd->scaffIndex, |
|---|
| 4447 | n/a | groupSize * sizeof(int)); |
|---|
| 4448 | n/a | if (temp == NULL) |
|---|
| 4449 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4450 | n/a | dtd->scaffIndex = temp; |
|---|
| 4451 | n/a | } |
|---|
| 4452 | n/a | } |
|---|
| 4453 | n/a | else { |
|---|
| 4454 | n/a | groupConnector = (char *)MALLOC(groupSize = 32); |
|---|
| 4455 | n/a | if (!groupConnector) |
|---|
| 4456 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4457 | n/a | } |
|---|
| 4458 | n/a | } |
|---|
| 4459 | n/a | groupConnector[prologState.level] = 0; |
|---|
| 4460 | n/a | if (dtd->in_eldecl) { |
|---|
| 4461 | n/a | int myindex = nextScaffoldPart(parser); |
|---|
| 4462 | n/a | if (myindex < 0) |
|---|
| 4463 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4464 | n/a | dtd->scaffIndex[dtd->scaffLevel] = myindex; |
|---|
| 4465 | n/a | dtd->scaffLevel++; |
|---|
| 4466 | n/a | dtd->scaffold[myindex].type = XML_CTYPE_SEQ; |
|---|
| 4467 | n/a | if (elementDeclHandler) |
|---|
| 4468 | n/a | handleDefault = XML_FALSE; |
|---|
| 4469 | n/a | } |
|---|
| 4470 | n/a | break; |
|---|
| 4471 | n/a | case XML_ROLE_GROUP_SEQUENCE: |
|---|
| 4472 | n/a | if (groupConnector[prologState.level] == ASCII_PIPE) |
|---|
| 4473 | n/a | return XML_ERROR_SYNTAX; |
|---|
| 4474 | n/a | groupConnector[prologState.level] = ASCII_COMMA; |
|---|
| 4475 | n/a | if (dtd->in_eldecl && elementDeclHandler) |
|---|
| 4476 | n/a | handleDefault = XML_FALSE; |
|---|
| 4477 | n/a | break; |
|---|
| 4478 | n/a | case XML_ROLE_GROUP_CHOICE: |
|---|
| 4479 | n/a | if (groupConnector[prologState.level] == ASCII_COMMA) |
|---|
| 4480 | n/a | return XML_ERROR_SYNTAX; |
|---|
| 4481 | n/a | if (dtd->in_eldecl |
|---|
| 4482 | n/a | && !groupConnector[prologState.level] |
|---|
| 4483 | n/a | && (dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type |
|---|
| 4484 | n/a | != XML_CTYPE_MIXED) |
|---|
| 4485 | n/a | ) { |
|---|
| 4486 | n/a | dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type |
|---|
| 4487 | n/a | = XML_CTYPE_CHOICE; |
|---|
| 4488 | n/a | if (elementDeclHandler) |
|---|
| 4489 | n/a | handleDefault = XML_FALSE; |
|---|
| 4490 | n/a | } |
|---|
| 4491 | n/a | groupConnector[prologState.level] = ASCII_PIPE; |
|---|
| 4492 | n/a | break; |
|---|
| 4493 | n/a | case XML_ROLE_PARAM_ENTITY_REF: |
|---|
| 4494 | n/a | #ifdef XML_DTD |
|---|
| 4495 | n/a | case XML_ROLE_INNER_PARAM_ENTITY_REF: |
|---|
| 4496 | n/a | dtd->hasParamEntityRefs = XML_TRUE; |
|---|
| 4497 | n/a | if (!paramEntityParsing) |
|---|
| 4498 | n/a | dtd->keepProcessing = dtd->standalone; |
|---|
| 4499 | n/a | else { |
|---|
| 4500 | n/a | const XML_Char *name; |
|---|
| 4501 | n/a | ENTITY *entity; |
|---|
| 4502 | n/a | name = poolStoreString(&dtd->pool, enc, |
|---|
| 4503 | n/a | s + enc->minBytesPerChar, |
|---|
| 4504 | n/a | next - enc->minBytesPerChar); |
|---|
| 4505 | n/a | if (!name) |
|---|
| 4506 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4507 | n/a | entity = (ENTITY *)lookup(parser, &dtd->paramEntities, name, 0); |
|---|
| 4508 | n/a | poolDiscard(&dtd->pool); |
|---|
| 4509 | n/a | /* first, determine if a check for an existing declaration is needed; |
|---|
| 4510 | n/a | if yes, check that the entity exists, and that it is internal, |
|---|
| 4511 | n/a | otherwise call the skipped entity handler |
|---|
| 4512 | n/a | */ |
|---|
| 4513 | n/a | if (prologState.documentEntity && |
|---|
| 4514 | n/a | (dtd->standalone |
|---|
| 4515 | n/a | ? !openInternalEntities |
|---|
| 4516 | n/a | : !dtd->hasParamEntityRefs)) { |
|---|
| 4517 | n/a | if (!entity) |
|---|
| 4518 | n/a | return XML_ERROR_UNDEFINED_ENTITY; |
|---|
| 4519 | n/a | else if (!entity->is_internal) |
|---|
| 4520 | n/a | return XML_ERROR_ENTITY_DECLARED_IN_PE; |
|---|
| 4521 | n/a | } |
|---|
| 4522 | n/a | else if (!entity) { |
|---|
| 4523 | n/a | dtd->keepProcessing = dtd->standalone; |
|---|
| 4524 | n/a | /* cannot report skipped entities in declarations */ |
|---|
| 4525 | n/a | if ((role == XML_ROLE_PARAM_ENTITY_REF) && skippedEntityHandler) { |
|---|
| 4526 | n/a | skippedEntityHandler(handlerArg, name, 1); |
|---|
| 4527 | n/a | handleDefault = XML_FALSE; |
|---|
| 4528 | n/a | } |
|---|
| 4529 | n/a | break; |
|---|
| 4530 | n/a | } |
|---|
| 4531 | n/a | if (entity->open) |
|---|
| 4532 | n/a | return XML_ERROR_RECURSIVE_ENTITY_REF; |
|---|
| 4533 | n/a | if (entity->textPtr) { |
|---|
| 4534 | n/a | enum XML_Error result; |
|---|
| 4535 | n/a | XML_Bool betweenDecl = |
|---|
| 4536 | n/a | (role == XML_ROLE_PARAM_ENTITY_REF ? XML_TRUE : XML_FALSE); |
|---|
| 4537 | n/a | result = processInternalEntity(parser, entity, betweenDecl); |
|---|
| 4538 | n/a | if (result != XML_ERROR_NONE) |
|---|
| 4539 | n/a | return result; |
|---|
| 4540 | n/a | handleDefault = XML_FALSE; |
|---|
| 4541 | n/a | break; |
|---|
| 4542 | n/a | } |
|---|
| 4543 | n/a | if (externalEntityRefHandler) { |
|---|
| 4544 | n/a | dtd->paramEntityRead = XML_FALSE; |
|---|
| 4545 | n/a | entity->open = XML_TRUE; |
|---|
| 4546 | n/a | if (!externalEntityRefHandler(externalEntityRefHandlerArg, |
|---|
| 4547 | n/a | 0, |
|---|
| 4548 | n/a | entity->base, |
|---|
| 4549 | n/a | entity->systemId, |
|---|
| 4550 | n/a | entity->publicId)) { |
|---|
| 4551 | n/a | entity->open = XML_FALSE; |
|---|
| 4552 | n/a | return XML_ERROR_EXTERNAL_ENTITY_HANDLING; |
|---|
| 4553 | n/a | } |
|---|
| 4554 | n/a | entity->open = XML_FALSE; |
|---|
| 4555 | n/a | handleDefault = XML_FALSE; |
|---|
| 4556 | n/a | if (!dtd->paramEntityRead) { |
|---|
| 4557 | n/a | dtd->keepProcessing = dtd->standalone; |
|---|
| 4558 | n/a | break; |
|---|
| 4559 | n/a | } |
|---|
| 4560 | n/a | } |
|---|
| 4561 | n/a | else { |
|---|
| 4562 | n/a | dtd->keepProcessing = dtd->standalone; |
|---|
| 4563 | n/a | break; |
|---|
| 4564 | n/a | } |
|---|
| 4565 | n/a | } |
|---|
| 4566 | n/a | #endif /* XML_DTD */ |
|---|
| 4567 | n/a | if (!dtd->standalone && |
|---|
| 4568 | n/a | notStandaloneHandler && |
|---|
| 4569 | n/a | !notStandaloneHandler(handlerArg)) |
|---|
| 4570 | n/a | return XML_ERROR_NOT_STANDALONE; |
|---|
| 4571 | n/a | break; |
|---|
| 4572 | n/a | |
|---|
| 4573 | n/a | /* Element declaration stuff */ |
|---|
| 4574 | n/a | |
|---|
| 4575 | n/a | case XML_ROLE_ELEMENT_NAME: |
|---|
| 4576 | n/a | if (elementDeclHandler) { |
|---|
| 4577 | n/a | declElementType = getElementType(parser, enc, s, next); |
|---|
| 4578 | n/a | if (!declElementType) |
|---|
| 4579 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4580 | n/a | dtd->scaffLevel = 0; |
|---|
| 4581 | n/a | dtd->scaffCount = 0; |
|---|
| 4582 | n/a | dtd->in_eldecl = XML_TRUE; |
|---|
| 4583 | n/a | handleDefault = XML_FALSE; |
|---|
| 4584 | n/a | } |
|---|
| 4585 | n/a | break; |
|---|
| 4586 | n/a | |
|---|
| 4587 | n/a | case XML_ROLE_CONTENT_ANY: |
|---|
| 4588 | n/a | case XML_ROLE_CONTENT_EMPTY: |
|---|
| 4589 | n/a | if (dtd->in_eldecl) { |
|---|
| 4590 | n/a | if (elementDeclHandler) { |
|---|
| 4591 | n/a | XML_Content * content = (XML_Content *) MALLOC(sizeof(XML_Content)); |
|---|
| 4592 | n/a | if (!content) |
|---|
| 4593 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4594 | n/a | content->quant = XML_CQUANT_NONE; |
|---|
| 4595 | n/a | content->name = NULL; |
|---|
| 4596 | n/a | content->numchildren = 0; |
|---|
| 4597 | n/a | content->children = NULL; |
|---|
| 4598 | n/a | content->type = ((role == XML_ROLE_CONTENT_ANY) ? |
|---|
| 4599 | n/a | XML_CTYPE_ANY : |
|---|
| 4600 | n/a | XML_CTYPE_EMPTY); |
|---|
| 4601 | n/a | *eventEndPP = s; |
|---|
| 4602 | n/a | elementDeclHandler(handlerArg, declElementType->name, content); |
|---|
| 4603 | n/a | handleDefault = XML_FALSE; |
|---|
| 4604 | n/a | } |
|---|
| 4605 | n/a | dtd->in_eldecl = XML_FALSE; |
|---|
| 4606 | n/a | } |
|---|
| 4607 | n/a | break; |
|---|
| 4608 | n/a | |
|---|
| 4609 | n/a | case XML_ROLE_CONTENT_PCDATA: |
|---|
| 4610 | n/a | if (dtd->in_eldecl) { |
|---|
| 4611 | n/a | dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type |
|---|
| 4612 | n/a | = XML_CTYPE_MIXED; |
|---|
| 4613 | n/a | if (elementDeclHandler) |
|---|
| 4614 | n/a | handleDefault = XML_FALSE; |
|---|
| 4615 | n/a | } |
|---|
| 4616 | n/a | break; |
|---|
| 4617 | n/a | |
|---|
| 4618 | n/a | case XML_ROLE_CONTENT_ELEMENT: |
|---|
| 4619 | n/a | quant = XML_CQUANT_NONE; |
|---|
| 4620 | n/a | goto elementContent; |
|---|
| 4621 | n/a | case XML_ROLE_CONTENT_ELEMENT_OPT: |
|---|
| 4622 | n/a | quant = XML_CQUANT_OPT; |
|---|
| 4623 | n/a | goto elementContent; |
|---|
| 4624 | n/a | case XML_ROLE_CONTENT_ELEMENT_REP: |
|---|
| 4625 | n/a | quant = XML_CQUANT_REP; |
|---|
| 4626 | n/a | goto elementContent; |
|---|
| 4627 | n/a | case XML_ROLE_CONTENT_ELEMENT_PLUS: |
|---|
| 4628 | n/a | quant = XML_CQUANT_PLUS; |
|---|
| 4629 | n/a | elementContent: |
|---|
| 4630 | n/a | if (dtd->in_eldecl) { |
|---|
| 4631 | n/a | ELEMENT_TYPE *el; |
|---|
| 4632 | n/a | const XML_Char *name; |
|---|
| 4633 | n/a | int nameLen; |
|---|
| 4634 | n/a | const char *nxt = (quant == XML_CQUANT_NONE |
|---|
| 4635 | n/a | ? next |
|---|
| 4636 | n/a | : next - enc->minBytesPerChar); |
|---|
| 4637 | n/a | int myindex = nextScaffoldPart(parser); |
|---|
| 4638 | n/a | if (myindex < 0) |
|---|
| 4639 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4640 | n/a | dtd->scaffold[myindex].type = XML_CTYPE_NAME; |
|---|
| 4641 | n/a | dtd->scaffold[myindex].quant = quant; |
|---|
| 4642 | n/a | el = getElementType(parser, enc, s, nxt); |
|---|
| 4643 | n/a | if (!el) |
|---|
| 4644 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4645 | n/a | name = el->name; |
|---|
| 4646 | n/a | dtd->scaffold[myindex].name = name; |
|---|
| 4647 | n/a | nameLen = 0; |
|---|
| 4648 | n/a | for (; name[nameLen++]; ); |
|---|
| 4649 | n/a | dtd->contentStringLen += nameLen; |
|---|
| 4650 | n/a | if (elementDeclHandler) |
|---|
| 4651 | n/a | handleDefault = XML_FALSE; |
|---|
| 4652 | n/a | } |
|---|
| 4653 | n/a | break; |
|---|
| 4654 | n/a | |
|---|
| 4655 | n/a | case XML_ROLE_GROUP_CLOSE: |
|---|
| 4656 | n/a | quant = XML_CQUANT_NONE; |
|---|
| 4657 | n/a | goto closeGroup; |
|---|
| 4658 | n/a | case XML_ROLE_GROUP_CLOSE_OPT: |
|---|
| 4659 | n/a | quant = XML_CQUANT_OPT; |
|---|
| 4660 | n/a | goto closeGroup; |
|---|
| 4661 | n/a | case XML_ROLE_GROUP_CLOSE_REP: |
|---|
| 4662 | n/a | quant = XML_CQUANT_REP; |
|---|
| 4663 | n/a | goto closeGroup; |
|---|
| 4664 | n/a | case XML_ROLE_GROUP_CLOSE_PLUS: |
|---|
| 4665 | n/a | quant = XML_CQUANT_PLUS; |
|---|
| 4666 | n/a | closeGroup: |
|---|
| 4667 | n/a | if (dtd->in_eldecl) { |
|---|
| 4668 | n/a | if (elementDeclHandler) |
|---|
| 4669 | n/a | handleDefault = XML_FALSE; |
|---|
| 4670 | n/a | dtd->scaffLevel--; |
|---|
| 4671 | n/a | dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel]].quant = quant; |
|---|
| 4672 | n/a | if (dtd->scaffLevel == 0) { |
|---|
| 4673 | n/a | if (!handleDefault) { |
|---|
| 4674 | n/a | XML_Content *model = build_model(parser); |
|---|
| 4675 | n/a | if (!model) |
|---|
| 4676 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4677 | n/a | *eventEndPP = s; |
|---|
| 4678 | n/a | elementDeclHandler(handlerArg, declElementType->name, model); |
|---|
| 4679 | n/a | } |
|---|
| 4680 | n/a | dtd->in_eldecl = XML_FALSE; |
|---|
| 4681 | n/a | dtd->contentStringLen = 0; |
|---|
| 4682 | n/a | } |
|---|
| 4683 | n/a | } |
|---|
| 4684 | n/a | break; |
|---|
| 4685 | n/a | /* End element declaration stuff */ |
|---|
| 4686 | n/a | |
|---|
| 4687 | n/a | case XML_ROLE_PI: |
|---|
| 4688 | n/a | if (!reportProcessingInstruction(parser, enc, s, next)) |
|---|
| 4689 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4690 | n/a | handleDefault = XML_FALSE; |
|---|
| 4691 | n/a | break; |
|---|
| 4692 | n/a | case XML_ROLE_COMMENT: |
|---|
| 4693 | n/a | if (!reportComment(parser, enc, s, next)) |
|---|
| 4694 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4695 | n/a | handleDefault = XML_FALSE; |
|---|
| 4696 | n/a | break; |
|---|
| 4697 | n/a | case XML_ROLE_NONE: |
|---|
| 4698 | n/a | switch (tok) { |
|---|
| 4699 | n/a | case XML_TOK_BOM: |
|---|
| 4700 | n/a | handleDefault = XML_FALSE; |
|---|
| 4701 | n/a | break; |
|---|
| 4702 | n/a | } |
|---|
| 4703 | n/a | break; |
|---|
| 4704 | n/a | case XML_ROLE_DOCTYPE_NONE: |
|---|
| 4705 | n/a | if (startDoctypeDeclHandler) |
|---|
| 4706 | n/a | handleDefault = XML_FALSE; |
|---|
| 4707 | n/a | break; |
|---|
| 4708 | n/a | case XML_ROLE_ENTITY_NONE: |
|---|
| 4709 | n/a | if (dtd->keepProcessing && entityDeclHandler) |
|---|
| 4710 | n/a | handleDefault = XML_FALSE; |
|---|
| 4711 | n/a | break; |
|---|
| 4712 | n/a | case XML_ROLE_NOTATION_NONE: |
|---|
| 4713 | n/a | if (notationDeclHandler) |
|---|
| 4714 | n/a | handleDefault = XML_FALSE; |
|---|
| 4715 | n/a | break; |
|---|
| 4716 | n/a | case XML_ROLE_ATTLIST_NONE: |
|---|
| 4717 | n/a | if (dtd->keepProcessing && attlistDeclHandler) |
|---|
| 4718 | n/a | handleDefault = XML_FALSE; |
|---|
| 4719 | n/a | break; |
|---|
| 4720 | n/a | case XML_ROLE_ELEMENT_NONE: |
|---|
| 4721 | n/a | if (elementDeclHandler) |
|---|
| 4722 | n/a | handleDefault = XML_FALSE; |
|---|
| 4723 | n/a | break; |
|---|
| 4724 | n/a | } /* end of big switch */ |
|---|
| 4725 | n/a | |
|---|
| 4726 | n/a | if (handleDefault && defaultHandler) |
|---|
| 4727 | n/a | reportDefault(parser, enc, s, next); |
|---|
| 4728 | n/a | |
|---|
| 4729 | n/a | switch (ps_parsing) { |
|---|
| 4730 | n/a | case XML_SUSPENDED: |
|---|
| 4731 | n/a | *nextPtr = next; |
|---|
| 4732 | n/a | return XML_ERROR_NONE; |
|---|
| 4733 | n/a | case XML_FINISHED: |
|---|
| 4734 | n/a | return XML_ERROR_ABORTED; |
|---|
| 4735 | n/a | default: |
|---|
| 4736 | n/a | s = next; |
|---|
| 4737 | n/a | tok = XmlPrologTok(enc, s, end, &next); |
|---|
| 4738 | n/a | } |
|---|
| 4739 | n/a | } |
|---|
| 4740 | n/a | /* not reached */ |
|---|
| 4741 | n/a | } |
|---|
| 4742 | n/a | |
|---|
| 4743 | n/a | static enum XML_Error PTRCALL |
|---|
| 4744 | n/a | epilogProcessor(XML_Parser parser, |
|---|
| 4745 | n/a | const char *s, |
|---|
| 4746 | n/a | const char *end, |
|---|
| 4747 | n/a | const char **nextPtr) |
|---|
| 4748 | n/a | { |
|---|
| 4749 | n/a | processor = epilogProcessor; |
|---|
| 4750 | n/a | eventPtr = s; |
|---|
| 4751 | n/a | for (;;) { |
|---|
| 4752 | n/a | const char *next = NULL; |
|---|
| 4753 | n/a | int tok = XmlPrologTok(encoding, s, end, &next); |
|---|
| 4754 | n/a | eventEndPtr = next; |
|---|
| 4755 | n/a | switch (tok) { |
|---|
| 4756 | n/a | /* report partial linebreak - it might be the last token */ |
|---|
| 4757 | n/a | case -XML_TOK_PROLOG_S: |
|---|
| 4758 | n/a | if (defaultHandler) { |
|---|
| 4759 | n/a | reportDefault(parser, encoding, s, next); |
|---|
| 4760 | n/a | if (ps_parsing == XML_FINISHED) |
|---|
| 4761 | n/a | return XML_ERROR_ABORTED; |
|---|
| 4762 | n/a | } |
|---|
| 4763 | n/a | *nextPtr = next; |
|---|
| 4764 | n/a | return XML_ERROR_NONE; |
|---|
| 4765 | n/a | case XML_TOK_NONE: |
|---|
| 4766 | n/a | *nextPtr = s; |
|---|
| 4767 | n/a | return XML_ERROR_NONE; |
|---|
| 4768 | n/a | case XML_TOK_PROLOG_S: |
|---|
| 4769 | n/a | if (defaultHandler) |
|---|
| 4770 | n/a | reportDefault(parser, encoding, s, next); |
|---|
| 4771 | n/a | break; |
|---|
| 4772 | n/a | case XML_TOK_PI: |
|---|
| 4773 | n/a | if (!reportProcessingInstruction(parser, encoding, s, next)) |
|---|
| 4774 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4775 | n/a | break; |
|---|
| 4776 | n/a | case XML_TOK_COMMENT: |
|---|
| 4777 | n/a | if (!reportComment(parser, encoding, s, next)) |
|---|
| 4778 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4779 | n/a | break; |
|---|
| 4780 | n/a | case XML_TOK_INVALID: |
|---|
| 4781 | n/a | eventPtr = next; |
|---|
| 4782 | n/a | return XML_ERROR_INVALID_TOKEN; |
|---|
| 4783 | n/a | case XML_TOK_PARTIAL: |
|---|
| 4784 | n/a | if (!ps_finalBuffer) { |
|---|
| 4785 | n/a | *nextPtr = s; |
|---|
| 4786 | n/a | return XML_ERROR_NONE; |
|---|
| 4787 | n/a | } |
|---|
| 4788 | n/a | return XML_ERROR_UNCLOSED_TOKEN; |
|---|
| 4789 | n/a | case XML_TOK_PARTIAL_CHAR: |
|---|
| 4790 | n/a | if (!ps_finalBuffer) { |
|---|
| 4791 | n/a | *nextPtr = s; |
|---|
| 4792 | n/a | return XML_ERROR_NONE; |
|---|
| 4793 | n/a | } |
|---|
| 4794 | n/a | return XML_ERROR_PARTIAL_CHAR; |
|---|
| 4795 | n/a | default: |
|---|
| 4796 | n/a | return XML_ERROR_JUNK_AFTER_DOC_ELEMENT; |
|---|
| 4797 | n/a | } |
|---|
| 4798 | n/a | eventPtr = s = next; |
|---|
| 4799 | n/a | switch (ps_parsing) { |
|---|
| 4800 | n/a | case XML_SUSPENDED: |
|---|
| 4801 | n/a | *nextPtr = next; |
|---|
| 4802 | n/a | return XML_ERROR_NONE; |
|---|
| 4803 | n/a | case XML_FINISHED: |
|---|
| 4804 | n/a | return XML_ERROR_ABORTED; |
|---|
| 4805 | n/a | default: ; |
|---|
| 4806 | n/a | } |
|---|
| 4807 | n/a | } |
|---|
| 4808 | n/a | } |
|---|
| 4809 | n/a | |
|---|
| 4810 | n/a | static enum XML_Error |
|---|
| 4811 | n/a | processInternalEntity(XML_Parser parser, ENTITY *entity, |
|---|
| 4812 | n/a | XML_Bool betweenDecl) |
|---|
| 4813 | n/a | { |
|---|
| 4814 | n/a | const char *textStart, *textEnd; |
|---|
| 4815 | n/a | const char *next; |
|---|
| 4816 | n/a | enum XML_Error result; |
|---|
| 4817 | n/a | OPEN_INTERNAL_ENTITY *openEntity; |
|---|
| 4818 | n/a | |
|---|
| 4819 | n/a | if (freeInternalEntities) { |
|---|
| 4820 | n/a | openEntity = freeInternalEntities; |
|---|
| 4821 | n/a | freeInternalEntities = openEntity->next; |
|---|
| 4822 | n/a | } |
|---|
| 4823 | n/a | else { |
|---|
| 4824 | n/a | openEntity = (OPEN_INTERNAL_ENTITY *)MALLOC(sizeof(OPEN_INTERNAL_ENTITY)); |
|---|
| 4825 | n/a | if (!openEntity) |
|---|
| 4826 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4827 | n/a | } |
|---|
| 4828 | n/a | entity->open = XML_TRUE; |
|---|
| 4829 | n/a | entity->processed = 0; |
|---|
| 4830 | n/a | openEntity->next = openInternalEntities; |
|---|
| 4831 | n/a | openInternalEntities = openEntity; |
|---|
| 4832 | n/a | openEntity->entity = entity; |
|---|
| 4833 | n/a | openEntity->startTagLevel = tagLevel; |
|---|
| 4834 | n/a | openEntity->betweenDecl = betweenDecl; |
|---|
| 4835 | n/a | openEntity->internalEventPtr = NULL; |
|---|
| 4836 | n/a | openEntity->internalEventEndPtr = NULL; |
|---|
| 4837 | n/a | textStart = (char *)entity->textPtr; |
|---|
| 4838 | n/a | textEnd = (char *)(entity->textPtr + entity->textLen); |
|---|
| 4839 | n/a | |
|---|
| 4840 | n/a | #ifdef XML_DTD |
|---|
| 4841 | n/a | if (entity->is_param) { |
|---|
| 4842 | n/a | int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next); |
|---|
| 4843 | n/a | result = doProlog(parser, internalEncoding, textStart, textEnd, tok, |
|---|
| 4844 | n/a | next, &next, XML_FALSE); |
|---|
| 4845 | n/a | } |
|---|
| 4846 | n/a | else |
|---|
| 4847 | n/a | #endif /* XML_DTD */ |
|---|
| 4848 | n/a | result = doContent(parser, tagLevel, internalEncoding, textStart, |
|---|
| 4849 | n/a | textEnd, &next, XML_FALSE); |
|---|
| 4850 | n/a | |
|---|
| 4851 | n/a | if (result == XML_ERROR_NONE) { |
|---|
| 4852 | n/a | if (textEnd != next && ps_parsing == XML_SUSPENDED) { |
|---|
| 4853 | n/a | entity->processed = (int)(next - textStart); |
|---|
| 4854 | n/a | processor = internalEntityProcessor; |
|---|
| 4855 | n/a | } |
|---|
| 4856 | n/a | else { |
|---|
| 4857 | n/a | entity->open = XML_FALSE; |
|---|
| 4858 | n/a | openInternalEntities = openEntity->next; |
|---|
| 4859 | n/a | /* put openEntity back in list of free instances */ |
|---|
| 4860 | n/a | openEntity->next = freeInternalEntities; |
|---|
| 4861 | n/a | freeInternalEntities = openEntity; |
|---|
| 4862 | n/a | } |
|---|
| 4863 | n/a | } |
|---|
| 4864 | n/a | return result; |
|---|
| 4865 | n/a | } |
|---|
| 4866 | n/a | |
|---|
| 4867 | n/a | static enum XML_Error PTRCALL |
|---|
| 4868 | n/a | internalEntityProcessor(XML_Parser parser, |
|---|
| 4869 | n/a | const char *s, |
|---|
| 4870 | n/a | const char *end, |
|---|
| 4871 | n/a | const char **nextPtr) |
|---|
| 4872 | n/a | { |
|---|
| 4873 | n/a | ENTITY *entity; |
|---|
| 4874 | n/a | const char *textStart, *textEnd; |
|---|
| 4875 | n/a | const char *next; |
|---|
| 4876 | n/a | enum XML_Error result; |
|---|
| 4877 | n/a | OPEN_INTERNAL_ENTITY *openEntity = openInternalEntities; |
|---|
| 4878 | n/a | if (!openEntity) |
|---|
| 4879 | n/a | return XML_ERROR_UNEXPECTED_STATE; |
|---|
| 4880 | n/a | |
|---|
| 4881 | n/a | entity = openEntity->entity; |
|---|
| 4882 | n/a | textStart = ((char *)entity->textPtr) + entity->processed; |
|---|
| 4883 | n/a | textEnd = (char *)(entity->textPtr + entity->textLen); |
|---|
| 4884 | n/a | |
|---|
| 4885 | n/a | #ifdef XML_DTD |
|---|
| 4886 | n/a | if (entity->is_param) { |
|---|
| 4887 | n/a | int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next); |
|---|
| 4888 | n/a | result = doProlog(parser, internalEncoding, textStart, textEnd, tok, |
|---|
| 4889 | n/a | next, &next, XML_FALSE); |
|---|
| 4890 | n/a | } |
|---|
| 4891 | n/a | else |
|---|
| 4892 | n/a | #endif /* XML_DTD */ |
|---|
| 4893 | n/a | result = doContent(parser, openEntity->startTagLevel, internalEncoding, |
|---|
| 4894 | n/a | textStart, textEnd, &next, XML_FALSE); |
|---|
| 4895 | n/a | |
|---|
| 4896 | n/a | if (result != XML_ERROR_NONE) |
|---|
| 4897 | n/a | return result; |
|---|
| 4898 | n/a | else if (textEnd != next && ps_parsing == XML_SUSPENDED) { |
|---|
| 4899 | n/a | entity->processed = (int)(next - (char *)entity->textPtr); |
|---|
| 4900 | n/a | return result; |
|---|
| 4901 | n/a | } |
|---|
| 4902 | n/a | else { |
|---|
| 4903 | n/a | entity->open = XML_FALSE; |
|---|
| 4904 | n/a | openInternalEntities = openEntity->next; |
|---|
| 4905 | n/a | /* put openEntity back in list of free instances */ |
|---|
| 4906 | n/a | openEntity->next = freeInternalEntities; |
|---|
| 4907 | n/a | freeInternalEntities = openEntity; |
|---|
| 4908 | n/a | } |
|---|
| 4909 | n/a | |
|---|
| 4910 | n/a | #ifdef XML_DTD |
|---|
| 4911 | n/a | if (entity->is_param) { |
|---|
| 4912 | n/a | int tok; |
|---|
| 4913 | n/a | processor = prologProcessor; |
|---|
| 4914 | n/a | tok = XmlPrologTok(encoding, s, end, &next); |
|---|
| 4915 | n/a | return doProlog(parser, encoding, s, end, tok, next, nextPtr, |
|---|
| 4916 | n/a | (XML_Bool)!ps_finalBuffer); |
|---|
| 4917 | n/a | } |
|---|
| 4918 | n/a | else |
|---|
| 4919 | n/a | #endif /* XML_DTD */ |
|---|
| 4920 | n/a | { |
|---|
| 4921 | n/a | processor = contentProcessor; |
|---|
| 4922 | n/a | /* see externalEntityContentProcessor vs contentProcessor */ |
|---|
| 4923 | n/a | return doContent(parser, parentParser ? 1 : 0, encoding, s, end, |
|---|
| 4924 | n/a | nextPtr, (XML_Bool)!ps_finalBuffer); |
|---|
| 4925 | n/a | } |
|---|
| 4926 | n/a | } |
|---|
| 4927 | n/a | |
|---|
| 4928 | n/a | static enum XML_Error PTRCALL |
|---|
| 4929 | n/a | errorProcessor(XML_Parser parser, |
|---|
| 4930 | n/a | const char *s, |
|---|
| 4931 | n/a | const char *end, |
|---|
| 4932 | n/a | const char **nextPtr) |
|---|
| 4933 | n/a | { |
|---|
| 4934 | n/a | return errorCode; |
|---|
| 4935 | n/a | } |
|---|
| 4936 | n/a | |
|---|
| 4937 | n/a | static enum XML_Error |
|---|
| 4938 | n/a | storeAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, |
|---|
| 4939 | n/a | const char *ptr, const char *end, |
|---|
| 4940 | n/a | STRING_POOL *pool) |
|---|
| 4941 | n/a | { |
|---|
| 4942 | n/a | enum XML_Error result = appendAttributeValue(parser, enc, isCdata, ptr, |
|---|
| 4943 | n/a | end, pool); |
|---|
| 4944 | n/a | if (result) |
|---|
| 4945 | n/a | return result; |
|---|
| 4946 | n/a | if (!isCdata && poolLength(pool) && poolLastChar(pool) == 0x20) |
|---|
| 4947 | n/a | poolChop(pool); |
|---|
| 4948 | n/a | if (!poolAppendChar(pool, XML_T('\0'))) |
|---|
| 4949 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4950 | n/a | return XML_ERROR_NONE; |
|---|
| 4951 | n/a | } |
|---|
| 4952 | n/a | |
|---|
| 4953 | n/a | static enum XML_Error |
|---|
| 4954 | n/a | appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, |
|---|
| 4955 | n/a | const char *ptr, const char *end, |
|---|
| 4956 | n/a | STRING_POOL *pool) |
|---|
| 4957 | n/a | { |
|---|
| 4958 | n/a | DTD * const dtd = _dtd; /* save one level of indirection */ |
|---|
| 4959 | n/a | for (;;) { |
|---|
| 4960 | n/a | const char *next; |
|---|
| 4961 | n/a | int tok = XmlAttributeValueTok(enc, ptr, end, &next); |
|---|
| 4962 | n/a | switch (tok) { |
|---|
| 4963 | n/a | case XML_TOK_NONE: |
|---|
| 4964 | n/a | return XML_ERROR_NONE; |
|---|
| 4965 | n/a | case XML_TOK_INVALID: |
|---|
| 4966 | n/a | if (enc == encoding) |
|---|
| 4967 | n/a | eventPtr = next; |
|---|
| 4968 | n/a | return XML_ERROR_INVALID_TOKEN; |
|---|
| 4969 | n/a | case XML_TOK_PARTIAL: |
|---|
| 4970 | n/a | if (enc == encoding) |
|---|
| 4971 | n/a | eventPtr = ptr; |
|---|
| 4972 | n/a | return XML_ERROR_INVALID_TOKEN; |
|---|
| 4973 | n/a | case XML_TOK_CHAR_REF: |
|---|
| 4974 | n/a | { |
|---|
| 4975 | n/a | XML_Char buf[XML_ENCODE_MAX]; |
|---|
| 4976 | n/a | int i; |
|---|
| 4977 | n/a | int n = XmlCharRefNumber(enc, ptr); |
|---|
| 4978 | n/a | if (n < 0) { |
|---|
| 4979 | n/a | if (enc == encoding) |
|---|
| 4980 | n/a | eventPtr = ptr; |
|---|
| 4981 | n/a | return XML_ERROR_BAD_CHAR_REF; |
|---|
| 4982 | n/a | } |
|---|
| 4983 | n/a | if (!isCdata |
|---|
| 4984 | n/a | && n == 0x20 /* space */ |
|---|
| 4985 | n/a | && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20)) |
|---|
| 4986 | n/a | break; |
|---|
| 4987 | n/a | n = XmlEncode(n, (ICHAR *)buf); |
|---|
| 4988 | n/a | if (!n) { |
|---|
| 4989 | n/a | if (enc == encoding) |
|---|
| 4990 | n/a | eventPtr = ptr; |
|---|
| 4991 | n/a | return XML_ERROR_BAD_CHAR_REF; |
|---|
| 4992 | n/a | } |
|---|
| 4993 | n/a | for (i = 0; i < n; i++) { |
|---|
| 4994 | n/a | if (!poolAppendChar(pool, buf[i])) |
|---|
| 4995 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 4996 | n/a | } |
|---|
| 4997 | n/a | } |
|---|
| 4998 | n/a | break; |
|---|
| 4999 | n/a | case XML_TOK_DATA_CHARS: |
|---|
| 5000 | n/a | if (!poolAppend(pool, enc, ptr, next)) |
|---|
| 5001 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 5002 | n/a | break; |
|---|
| 5003 | n/a | case XML_TOK_TRAILING_CR: |
|---|
| 5004 | n/a | next = ptr + enc->minBytesPerChar; |
|---|
| 5005 | n/a | /* fall through */ |
|---|
| 5006 | n/a | case XML_TOK_ATTRIBUTE_VALUE_S: |
|---|
| 5007 | n/a | case XML_TOK_DATA_NEWLINE: |
|---|
| 5008 | n/a | if (!isCdata && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20)) |
|---|
| 5009 | n/a | break; |
|---|
| 5010 | n/a | if (!poolAppendChar(pool, 0x20)) |
|---|
| 5011 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 5012 | n/a | break; |
|---|
| 5013 | n/a | case XML_TOK_ENTITY_REF: |
|---|
| 5014 | n/a | { |
|---|
| 5015 | n/a | const XML_Char *name; |
|---|
| 5016 | n/a | ENTITY *entity; |
|---|
| 5017 | n/a | char checkEntityDecl; |
|---|
| 5018 | n/a | XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc, |
|---|
| 5019 | n/a | ptr + enc->minBytesPerChar, |
|---|
| 5020 | n/a | next - enc->minBytesPerChar); |
|---|
| 5021 | n/a | if (ch) { |
|---|
| 5022 | n/a | if (!poolAppendChar(pool, ch)) |
|---|
| 5023 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 5024 | n/a | break; |
|---|
| 5025 | n/a | } |
|---|
| 5026 | n/a | name = poolStoreString(&temp2Pool, enc, |
|---|
| 5027 | n/a | ptr + enc->minBytesPerChar, |
|---|
| 5028 | n/a | next - enc->minBytesPerChar); |
|---|
| 5029 | n/a | if (!name) |
|---|
| 5030 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 5031 | n/a | entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0); |
|---|
| 5032 | n/a | poolDiscard(&temp2Pool); |
|---|
| 5033 | n/a | /* First, determine if a check for an existing declaration is needed; |
|---|
| 5034 | n/a | if yes, check that the entity exists, and that it is internal. |
|---|
| 5035 | n/a | */ |
|---|
| 5036 | n/a | if (pool == &dtd->pool) /* are we called from prolog? */ |
|---|
| 5037 | n/a | checkEntityDecl = |
|---|
| 5038 | n/a | #ifdef XML_DTD |
|---|
| 5039 | n/a | prologState.documentEntity && |
|---|
| 5040 | n/a | #endif /* XML_DTD */ |
|---|
| 5041 | n/a | (dtd->standalone |
|---|
| 5042 | n/a | ? !openInternalEntities |
|---|
| 5043 | n/a | : !dtd->hasParamEntityRefs); |
|---|
| 5044 | n/a | else /* if (pool == &tempPool): we are called from content */ |
|---|
| 5045 | n/a | checkEntityDecl = !dtd->hasParamEntityRefs || dtd->standalone; |
|---|
| 5046 | n/a | if (checkEntityDecl) { |
|---|
| 5047 | n/a | if (!entity) |
|---|
| 5048 | n/a | return XML_ERROR_UNDEFINED_ENTITY; |
|---|
| 5049 | n/a | else if (!entity->is_internal) |
|---|
| 5050 | n/a | return XML_ERROR_ENTITY_DECLARED_IN_PE; |
|---|
| 5051 | n/a | } |
|---|
| 5052 | n/a | else if (!entity) { |
|---|
| 5053 | n/a | /* Cannot report skipped entity here - see comments on |
|---|
| 5054 | n/a | skippedEntityHandler. |
|---|
| 5055 | n/a | if (skippedEntityHandler) |
|---|
| 5056 | n/a | skippedEntityHandler(handlerArg, name, 0); |
|---|
| 5057 | n/a | */ |
|---|
| 5058 | n/a | /* Cannot call the default handler because this would be |
|---|
| 5059 | n/a | out of sync with the call to the startElementHandler. |
|---|
| 5060 | n/a | if ((pool == &tempPool) && defaultHandler) |
|---|
| 5061 | n/a | reportDefault(parser, enc, ptr, next); |
|---|
| 5062 | n/a | */ |
|---|
| 5063 | n/a | break; |
|---|
| 5064 | n/a | } |
|---|
| 5065 | n/a | if (entity->open) { |
|---|
| 5066 | n/a | if (enc == encoding) |
|---|
| 5067 | n/a | eventPtr = ptr; |
|---|
| 5068 | n/a | return XML_ERROR_RECURSIVE_ENTITY_REF; |
|---|
| 5069 | n/a | } |
|---|
| 5070 | n/a | if (entity->notation) { |
|---|
| 5071 | n/a | if (enc == encoding) |
|---|
| 5072 | n/a | eventPtr = ptr; |
|---|
| 5073 | n/a | return XML_ERROR_BINARY_ENTITY_REF; |
|---|
| 5074 | n/a | } |
|---|
| 5075 | n/a | if (!entity->textPtr) { |
|---|
| 5076 | n/a | if (enc == encoding) |
|---|
| 5077 | n/a | eventPtr = ptr; |
|---|
| 5078 | n/a | return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF; |
|---|
| 5079 | n/a | } |
|---|
| 5080 | n/a | else { |
|---|
| 5081 | n/a | enum XML_Error result; |
|---|
| 5082 | n/a | const XML_Char *textEnd = entity->textPtr + entity->textLen; |
|---|
| 5083 | n/a | entity->open = XML_TRUE; |
|---|
| 5084 | n/a | result = appendAttributeValue(parser, internalEncoding, isCdata, |
|---|
| 5085 | n/a | (char *)entity->textPtr, |
|---|
| 5086 | n/a | (char *)textEnd, pool); |
|---|
| 5087 | n/a | entity->open = XML_FALSE; |
|---|
| 5088 | n/a | if (result) |
|---|
| 5089 | n/a | return result; |
|---|
| 5090 | n/a | } |
|---|
| 5091 | n/a | } |
|---|
| 5092 | n/a | break; |
|---|
| 5093 | n/a | default: |
|---|
| 5094 | n/a | if (enc == encoding) |
|---|
| 5095 | n/a | eventPtr = ptr; |
|---|
| 5096 | n/a | return XML_ERROR_UNEXPECTED_STATE; |
|---|
| 5097 | n/a | } |
|---|
| 5098 | n/a | ptr = next; |
|---|
| 5099 | n/a | } |
|---|
| 5100 | n/a | /* not reached */ |
|---|
| 5101 | n/a | } |
|---|
| 5102 | n/a | |
|---|
| 5103 | n/a | static enum XML_Error |
|---|
| 5104 | n/a | storeEntityValue(XML_Parser parser, |
|---|
| 5105 | n/a | const ENCODING *enc, |
|---|
| 5106 | n/a | const char *entityTextPtr, |
|---|
| 5107 | n/a | const char *entityTextEnd) |
|---|
| 5108 | n/a | { |
|---|
| 5109 | n/a | DTD * const dtd = _dtd; /* save one level of indirection */ |
|---|
| 5110 | n/a | STRING_POOL *pool = &(dtd->entityValuePool); |
|---|
| 5111 | n/a | enum XML_Error result = XML_ERROR_NONE; |
|---|
| 5112 | n/a | #ifdef XML_DTD |
|---|
| 5113 | n/a | int oldInEntityValue = prologState.inEntityValue; |
|---|
| 5114 | n/a | prologState.inEntityValue = 1; |
|---|
| 5115 | n/a | #endif /* XML_DTD */ |
|---|
| 5116 | n/a | /* never return Null for the value argument in EntityDeclHandler, |
|---|
| 5117 | n/a | since this would indicate an external entity; therefore we |
|---|
| 5118 | n/a | have to make sure that entityValuePool.start is not null */ |
|---|
| 5119 | n/a | if (!pool->blocks) { |
|---|
| 5120 | n/a | if (!poolGrow(pool)) |
|---|
| 5121 | n/a | return XML_ERROR_NO_MEMORY; |
|---|
| 5122 | n/a | } |
|---|
| 5123 | n/a | |
|---|
| 5124 | n/a | for (;;) { |
|---|
| 5125 | n/a | const char *next; |
|---|
| 5126 | n/a | int tok = XmlEntityValueTok(enc, entityTextPtr, entityTextEnd, &next); |
|---|
| 5127 | n/a | switch (tok) { |
|---|
| 5128 | n/a | case XML_TOK_PARAM_ENTITY_REF: |
|---|
| 5129 | n/a | #ifdef XML_DTD |
|---|
| 5130 | n/a | if (isParamEntity || enc != encoding) { |
|---|
| 5131 | n/a | const XML_Char *name; |
|---|
| 5132 | n/a | ENTITY *entity; |
|---|
| 5133 | n/a | name = poolStoreString(&tempPool, enc, |
|---|
| 5134 | n/a | entityTextPtr + enc->minBytesPerChar, |
|---|
| 5135 | n/a | next - enc->minBytesPerChar); |
|---|
| 5136 | n/a | if (!name) { |
|---|
| 5137 | n/a | result = XML_ERROR_NO_MEMORY; |
|---|
| 5138 | n/a | goto endEntityValue; |
|---|
| 5139 | n/a | } |
|---|
| 5140 | n/a | entity = (ENTITY *)lookup(parser, &dtd->paramEntities, name, 0); |
|---|
| 5141 | n/a | poolDiscard(&tempPool); |
|---|
| 5142 | n/a | if (!entity) { |
|---|
| 5143 | n/a | /* not a well-formedness error - see XML 1.0: WFC Entity Declared */ |
|---|
| 5144 | n/a | /* cannot report skipped entity here - see comments on |
|---|
| 5145 | n/a | skippedEntityHandler |
|---|
| 5146 | n/a | if (skippedEntityHandler) |
|---|
| 5147 | n/a | skippedEntityHandler(handlerArg, name, 0); |
|---|
| 5148 | n/a | */ |
|---|
| 5149 | n/a | dtd->keepProcessing = dtd->standalone; |
|---|
| 5150 | n/a | goto endEntityValue; |
|---|
| 5151 | n/a | } |
|---|
| 5152 | n/a | if (entity->open) { |
|---|
| 5153 | n/a | if (enc == encoding) |
|---|
| 5154 | n/a | eventPtr = entityTextPtr; |
|---|
| 5155 | n/a | result = XML_ERROR_RECURSIVE_ENTITY_REF; |
|---|
| 5156 | n/a | goto endEntityValue; |
|---|
| 5157 | n/a | } |
|---|
| 5158 | n/a | if (entity->systemId) { |
|---|
| 5159 | n/a | if (externalEntityRefHandler) { |
|---|
| 5160 | n/a | dtd->paramEntityRead = XML_FALSE; |
|---|
| 5161 | n/a | entity->open = XML_TRUE; |
|---|
| 5162 | n/a | if (!externalEntityRefHandler(externalEntityRefHandlerArg, |
|---|
| 5163 | n/a | 0, |
|---|
| 5164 | n/a | entity->base, |
|---|
| 5165 | n/a | entity->systemId, |
|---|
| 5166 | n/a | entity->publicId)) { |
|---|
| 5167 | n/a | entity->open = XML_FALSE; |
|---|
| 5168 | n/a | result = XML_ERROR_EXTERNAL_ENTITY_HANDLING; |
|---|
| 5169 | n/a | goto endEntityValue; |
|---|
| 5170 | n/a | } |
|---|
| 5171 | n/a | entity->open = XML_FALSE; |
|---|
| 5172 | n/a | if (!dtd->paramEntityRead) |
|---|
| 5173 | n/a | dtd->keepProcessing = dtd->standalone; |
|---|
| 5174 | n/a | } |
|---|
| 5175 | n/a | else |
|---|
| 5176 | n/a | dtd->keepProcessing = dtd->standalone; |
|---|
| 5177 | n/a | } |
|---|
| 5178 | n/a | else { |
|---|
| 5179 | n/a | entity->open = XML_TRUE; |
|---|
| 5180 | n/a | result = storeEntityValue(parser, |
|---|
| 5181 | n/a | internalEncoding, |
|---|
| 5182 | n/a | (char *)entity->textPtr, |
|---|
| 5183 | n/a | (char *)(entity->textPtr |
|---|
| 5184 | n/a | + entity->textLen)); |
|---|
| 5185 | n/a | entity->open = XML_FALSE; |
|---|
| 5186 | n/a | if (result) |
|---|
| 5187 | n/a | goto endEntityValue; |
|---|
| 5188 | n/a | } |
|---|
| 5189 | n/a | break; |
|---|
| 5190 | n/a | } |
|---|
| 5191 | n/a | #endif /* XML_DTD */ |
|---|
| 5192 | n/a | /* In the internal subset, PE references are not legal |
|---|
| 5193 | n/a | within markup declarations, e.g entity values in this case. */ |
|---|
| 5194 | n/a | eventPtr = entityTextPtr; |
|---|
| 5195 | n/a | result = XML_ERROR_PARAM_ENTITY_REF; |
|---|
| 5196 | n/a | goto endEntityValue; |
|---|
| 5197 | n/a | case XML_TOK_NONE: |
|---|
| 5198 | n/a | result = XML_ERROR_NONE; |
|---|
| 5199 | n/a | goto endEntityValue; |
|---|
| 5200 | n/a | case XML_TOK_ENTITY_REF: |
|---|
| 5201 | n/a | case XML_TOK_DATA_CHARS: |
|---|
| 5202 | n/a | if (!poolAppend(pool, enc, entityTextPtr, next)) { |
|---|
| 5203 | n/a | result = XML_ERROR_NO_MEMORY; |
|---|
| 5204 | n/a | goto endEntityValue; |
|---|
| 5205 | n/a | } |
|---|
| 5206 | n/a | break; |
|---|
| 5207 | n/a | case XML_TOK_TRAILING_CR: |
|---|
| 5208 | n/a | next = entityTextPtr + enc->minBytesPerChar; |
|---|
| 5209 | n/a | /* fall through */ |
|---|
| 5210 | n/a | case XML_TOK_DATA_NEWLINE: |
|---|
| 5211 | n/a | if (pool->end == pool->ptr && !poolGrow(pool)) { |
|---|
| 5212 | n/a | result = XML_ERROR_NO_MEMORY; |
|---|
| 5213 | n/a | goto endEntityValue; |
|---|
| 5214 | n/a | } |
|---|
| 5215 | n/a | *(pool->ptr)++ = 0xA; |
|---|
| 5216 | n/a | break; |
|---|
| 5217 | n/a | case XML_TOK_CHAR_REF: |
|---|
| 5218 | n/a | { |
|---|
| 5219 | n/a | XML_Char buf[XML_ENCODE_MAX]; |
|---|
| 5220 | n/a | int i; |
|---|
| 5221 | n/a | int n = XmlCharRefNumber(enc, entityTextPtr); |
|---|
| 5222 | n/a | if (n < 0) { |
|---|
| 5223 | n/a | if (enc == encoding) |
|---|
| 5224 | n/a | eventPtr = entityTextPtr; |
|---|
| 5225 | n/a | result = XML_ERROR_BAD_CHAR_REF; |
|---|
| 5226 | n/a | goto endEntityValue; |
|---|
| 5227 | n/a | } |
|---|
| 5228 | n/a | n = XmlEncode(n, (ICHAR *)buf); |
|---|
| 5229 | n/a | if (!n) { |
|---|
| 5230 | n/a | if (enc == encoding) |
|---|
| 5231 | n/a | eventPtr = entityTextPtr; |
|---|
| 5232 | n/a | result = XML_ERROR_BAD_CHAR_REF; |
|---|
| 5233 | n/a | goto endEntityValue; |
|---|
| 5234 | n/a | } |
|---|
| 5235 | n/a | for (i = 0; i < n; i++) { |
|---|
| 5236 | n/a | if (pool->end == pool->ptr && !poolGrow(pool)) { |
|---|
| 5237 | n/a | result = XML_ERROR_NO_MEMORY; |
|---|
| 5238 | n/a | goto endEntityValue; |
|---|
| 5239 | n/a | } |
|---|
| 5240 | n/a | *(pool->ptr)++ = buf[i]; |
|---|
| 5241 | n/a | } |
|---|
| 5242 | n/a | } |
|---|
| 5243 | n/a | break; |
|---|
| 5244 | n/a | case XML_TOK_PARTIAL: |
|---|
| 5245 | n/a | if (enc == encoding) |
|---|
| 5246 | n/a | eventPtr = entityTextPtr; |
|---|
| 5247 | n/a | result = XML_ERROR_INVALID_TOKEN; |
|---|
| 5248 | n/a | goto endEntityValue; |
|---|
| 5249 | n/a | case XML_TOK_INVALID: |
|---|
| 5250 | n/a | if (enc == encoding) |
|---|
| 5251 | n/a | eventPtr = next; |
|---|
| 5252 | n/a | result = XML_ERROR_INVALID_TOKEN; |
|---|
| 5253 | n/a | goto endEntityValue; |
|---|
| 5254 | n/a | default: |
|---|
| 5255 | n/a | if (enc == encoding) |
|---|
| 5256 | n/a | eventPtr = entityTextPtr; |
|---|
| 5257 | n/a | result = XML_ERROR_UNEXPECTED_STATE; |
|---|
| 5258 | n/a | goto endEntityValue; |
|---|
| 5259 | n/a | } |
|---|
| 5260 | n/a | entityTextPtr = next; |
|---|
| 5261 | n/a | } |
|---|
| 5262 | n/a | endEntityValue: |
|---|
| 5263 | n/a | #ifdef XML_DTD |
|---|
| 5264 | n/a | prologState.inEntityValue = oldInEntityValue; |
|---|
| 5265 | n/a | #endif /* XML_DTD */ |
|---|
| 5266 | n/a | return result; |
|---|
| 5267 | n/a | } |
|---|
| 5268 | n/a | |
|---|
| 5269 | n/a | static void FASTCALL |
|---|
| 5270 | n/a | normalizeLines(XML_Char *s) |
|---|
| 5271 | n/a | { |
|---|
| 5272 | n/a | XML_Char *p; |
|---|
| 5273 | n/a | for (;; s++) { |
|---|
| 5274 | n/a | if (*s == XML_T('\0')) |
|---|
| 5275 | n/a | return; |
|---|
| 5276 | n/a | if (*s == 0xD) |
|---|
| 5277 | n/a | break; |
|---|
| 5278 | n/a | } |
|---|
| 5279 | n/a | p = s; |
|---|
| 5280 | n/a | do { |
|---|
| 5281 | n/a | if (*s == 0xD) { |
|---|
| 5282 | n/a | *p++ = 0xA; |
|---|
| 5283 | n/a | if (*++s == 0xA) |
|---|
| 5284 | n/a | s++; |
|---|
| 5285 | n/a | } |
|---|
| 5286 | n/a | else |
|---|
| 5287 | n/a | *p++ = *s++; |
|---|
| 5288 | n/a | } while (*s); |
|---|
| 5289 | n/a | *p = XML_T('\0'); |
|---|
| 5290 | n/a | } |
|---|
| 5291 | n/a | |
|---|
| 5292 | n/a | static int |
|---|
| 5293 | n/a | reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, |
|---|
| 5294 | n/a | const char *start, const char *end) |
|---|
| 5295 | n/a | { |
|---|
| 5296 | n/a | const XML_Char *target; |
|---|
| 5297 | n/a | XML_Char *data; |
|---|
| 5298 | n/a | const char *tem; |
|---|
| 5299 | n/a | if (!processingInstructionHandler) { |
|---|
| 5300 | n/a | if (defaultHandler) |
|---|
| 5301 | n/a | reportDefault(parser, enc, start, end); |
|---|
| 5302 | n/a | return 1; |
|---|
| 5303 | n/a | } |
|---|
| 5304 | n/a | start += enc->minBytesPerChar * 2; |
|---|
| 5305 | n/a | tem = start + XmlNameLength(enc, start); |
|---|
| 5306 | n/a | target = poolStoreString(&tempPool, enc, start, tem); |
|---|
| 5307 | n/a | if (!target) |
|---|
| 5308 | n/a | return 0; |
|---|
| 5309 | n/a | poolFinish(&tempPool); |
|---|
| 5310 | n/a | data = poolStoreString(&tempPool, enc, |
|---|
| 5311 | n/a | XmlSkipS(enc, tem), |
|---|
| 5312 | n/a | end - enc->minBytesPerChar*2); |
|---|
| 5313 | n/a | if (!data) |
|---|
| 5314 | n/a | return 0; |
|---|
| 5315 | n/a | normalizeLines(data); |
|---|
| 5316 | n/a | processingInstructionHandler(handlerArg, target, data); |
|---|
| 5317 | n/a | poolClear(&tempPool); |
|---|
| 5318 | n/a | return 1; |
|---|
| 5319 | n/a | } |
|---|
| 5320 | n/a | |
|---|
| 5321 | n/a | static int |
|---|
| 5322 | n/a | reportComment(XML_Parser parser, const ENCODING *enc, |
|---|
| 5323 | n/a | const char *start, const char *end) |
|---|
| 5324 | n/a | { |
|---|
| 5325 | n/a | XML_Char *data; |
|---|
| 5326 | n/a | if (!commentHandler) { |
|---|
| 5327 | n/a | if (defaultHandler) |
|---|
| 5328 | n/a | reportDefault(parser, enc, start, end); |
|---|
| 5329 | n/a | return 1; |
|---|
| 5330 | n/a | } |
|---|
| 5331 | n/a | data = poolStoreString(&tempPool, |
|---|
| 5332 | n/a | enc, |
|---|
| 5333 | n/a | start + enc->minBytesPerChar * 4, |
|---|
| 5334 | n/a | end - enc->minBytesPerChar * 3); |
|---|
| 5335 | n/a | if (!data) |
|---|
| 5336 | n/a | return 0; |
|---|
| 5337 | n/a | normalizeLines(data); |
|---|
| 5338 | n/a | commentHandler(handlerArg, data); |
|---|
| 5339 | n/a | poolClear(&tempPool); |
|---|
| 5340 | n/a | return 1; |
|---|
| 5341 | n/a | } |
|---|
| 5342 | n/a | |
|---|
| 5343 | n/a | static void |
|---|
| 5344 | n/a | reportDefault(XML_Parser parser, const ENCODING *enc, |
|---|
| 5345 | n/a | const char *s, const char *end) |
|---|
| 5346 | n/a | { |
|---|
| 5347 | n/a | if (MUST_CONVERT(enc, s)) { |
|---|
| 5348 | n/a | const char **eventPP; |
|---|
| 5349 | n/a | const char **eventEndPP; |
|---|
| 5350 | n/a | if (enc == encoding) { |
|---|
| 5351 | n/a | eventPP = &eventPtr; |
|---|
| 5352 | n/a | eventEndPP = &eventEndPtr; |
|---|
| 5353 | n/a | } |
|---|
| 5354 | n/a | else { |
|---|
| 5355 | n/a | eventPP = &(openInternalEntities->internalEventPtr); |
|---|
| 5356 | n/a | eventEndPP = &(openInternalEntities->internalEventEndPtr); |
|---|
| 5357 | n/a | } |
|---|
| 5358 | n/a | do { |
|---|
| 5359 | n/a | ICHAR *dataPtr = (ICHAR *)dataBuf; |
|---|
| 5360 | n/a | XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); |
|---|
| 5361 | n/a | *eventEndPP = s; |
|---|
| 5362 | n/a | defaultHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf)); |
|---|
| 5363 | n/a | *eventPP = s; |
|---|
| 5364 | n/a | } while (s != end); |
|---|
| 5365 | n/a | } |
|---|
| 5366 | n/a | else |
|---|
| 5367 | n/a | defaultHandler(handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s)); |
|---|
| 5368 | n/a | } |
|---|
| 5369 | n/a | |
|---|
| 5370 | n/a | |
|---|
| 5371 | n/a | static int |
|---|
| 5372 | n/a | defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata, |
|---|
| 5373 | n/a | XML_Bool isId, const XML_Char *value, XML_Parser parser) |
|---|
| 5374 | n/a | { |
|---|
| 5375 | n/a | DEFAULT_ATTRIBUTE *att; |
|---|
| 5376 | n/a | if (value || isId) { |
|---|
| 5377 | n/a | /* The handling of default attributes gets messed up if we have |
|---|
| 5378 | n/a | a default which duplicates a non-default. */ |
|---|
| 5379 | n/a | int i; |
|---|
| 5380 | n/a | for (i = 0; i < type->nDefaultAtts; i++) |
|---|
| 5381 | n/a | if (attId == type->defaultAtts[i].id) |
|---|
| 5382 | n/a | return 1; |
|---|
| 5383 | n/a | if (isId && !type->idAtt && !attId->xmlns) |
|---|
| 5384 | n/a | type->idAtt = attId; |
|---|
| 5385 | n/a | } |
|---|
| 5386 | n/a | if (type->nDefaultAtts == type->allocDefaultAtts) { |
|---|
| 5387 | n/a | if (type->allocDefaultAtts == 0) { |
|---|
| 5388 | n/a | type->allocDefaultAtts = 8; |
|---|
| 5389 | n/a | type->defaultAtts = (DEFAULT_ATTRIBUTE *)MALLOC(type->allocDefaultAtts |
|---|
| 5390 | n/a | * sizeof(DEFAULT_ATTRIBUTE)); |
|---|
| 5391 | n/a | if (!type->defaultAtts) |
|---|
| 5392 | n/a | return 0; |
|---|
| 5393 | n/a | } |
|---|
| 5394 | n/a | else { |
|---|
| 5395 | n/a | DEFAULT_ATTRIBUTE *temp; |
|---|
| 5396 | n/a | int count = type->allocDefaultAtts * 2; |
|---|
| 5397 | n/a | temp = (DEFAULT_ATTRIBUTE *) |
|---|
| 5398 | n/a | REALLOC(type->defaultAtts, (count * sizeof(DEFAULT_ATTRIBUTE))); |
|---|
| 5399 | n/a | if (temp == NULL) |
|---|
| 5400 | n/a | return 0; |
|---|
| 5401 | n/a | type->allocDefaultAtts = count; |
|---|
| 5402 | n/a | type->defaultAtts = temp; |
|---|
| 5403 | n/a | } |
|---|
| 5404 | n/a | } |
|---|
| 5405 | n/a | att = type->defaultAtts + type->nDefaultAtts; |
|---|
| 5406 | n/a | att->id = attId; |
|---|
| 5407 | n/a | att->value = value; |
|---|
| 5408 | n/a | att->isCdata = isCdata; |
|---|
| 5409 | n/a | if (!isCdata) |
|---|
| 5410 | n/a | attId->maybeTokenized = XML_TRUE; |
|---|
| 5411 | n/a | type->nDefaultAtts += 1; |
|---|
| 5412 | n/a | return 1; |
|---|
| 5413 | n/a | } |
|---|
| 5414 | n/a | |
|---|
| 5415 | n/a | static int |
|---|
| 5416 | n/a | setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *elementType) |
|---|
| 5417 | n/a | { |
|---|
| 5418 | n/a | DTD * const dtd = _dtd; /* save one level of indirection */ |
|---|
| 5419 | n/a | const XML_Char *name; |
|---|
| 5420 | n/a | for (name = elementType->name; *name; name++) { |
|---|
| 5421 | n/a | if (*name == XML_T(ASCII_COLON)) { |
|---|
| 5422 | n/a | PREFIX *prefix; |
|---|
| 5423 | n/a | const XML_Char *s; |
|---|
| 5424 | n/a | for (s = elementType->name; s != name; s++) { |
|---|
| 5425 | n/a | if (!poolAppendChar(&dtd->pool, *s)) |
|---|
| 5426 | n/a | return 0; |
|---|
| 5427 | n/a | } |
|---|
| 5428 | n/a | if (!poolAppendChar(&dtd->pool, XML_T('\0'))) |
|---|
| 5429 | n/a | return 0; |
|---|
| 5430 | n/a | prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd->pool), |
|---|
| 5431 | n/a | sizeof(PREFIX)); |
|---|
| 5432 | n/a | if (!prefix) |
|---|
| 5433 | n/a | return 0; |
|---|
| 5434 | n/a | if (prefix->name == poolStart(&dtd->pool)) |
|---|
| 5435 | n/a | poolFinish(&dtd->pool); |
|---|
| 5436 | n/a | else |
|---|
| 5437 | n/a | poolDiscard(&dtd->pool); |
|---|
| 5438 | n/a | elementType->prefix = prefix; |
|---|
| 5439 | n/a | |
|---|
| 5440 | n/a | } |
|---|
| 5441 | n/a | } |
|---|
| 5442 | n/a | return 1; |
|---|
| 5443 | n/a | } |
|---|
| 5444 | n/a | |
|---|
| 5445 | n/a | static ATTRIBUTE_ID * |
|---|
| 5446 | n/a | getAttributeId(XML_Parser parser, const ENCODING *enc, |
|---|
| 5447 | n/a | const char *start, const char *end) |
|---|
| 5448 | n/a | { |
|---|
| 5449 | n/a | DTD * const dtd = _dtd; /* save one level of indirection */ |
|---|
| 5450 | n/a | ATTRIBUTE_ID *id; |
|---|
| 5451 | n/a | const XML_Char *name; |
|---|
| 5452 | n/a | if (!poolAppendChar(&dtd->pool, XML_T('\0'))) |
|---|
| 5453 | n/a | return NULL; |
|---|
| 5454 | n/a | name = poolStoreString(&dtd->pool, enc, start, end); |
|---|
| 5455 | n/a | if (!name) |
|---|
| 5456 | n/a | return NULL; |
|---|
| 5457 | n/a | /* skip quotation mark - its storage will be re-used (like in name[-1]) */ |
|---|
| 5458 | n/a | ++name; |
|---|
| 5459 | n/a | id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, name, sizeof(ATTRIBUTE_ID)); |
|---|
| 5460 | n/a | if (!id) |
|---|
| 5461 | n/a | return NULL; |
|---|
| 5462 | n/a | if (id->name != name) |
|---|
| 5463 | n/a | poolDiscard(&dtd->pool); |
|---|
| 5464 | n/a | else { |
|---|
| 5465 | n/a | poolFinish(&dtd->pool); |
|---|
| 5466 | n/a | if (!ns) |
|---|
| 5467 | n/a | ; |
|---|
| 5468 | n/a | else if (name[0] == XML_T(ASCII_x) |
|---|
| 5469 | n/a | && name[1] == XML_T(ASCII_m) |
|---|
| 5470 | n/a | && name[2] == XML_T(ASCII_l) |
|---|
| 5471 | n/a | && name[3] == XML_T(ASCII_n) |
|---|
| 5472 | n/a | && name[4] == XML_T(ASCII_s) |
|---|
| 5473 | n/a | && (name[5] == XML_T('\0') || name[5] == XML_T(ASCII_COLON))) { |
|---|
| 5474 | n/a | if (name[5] == XML_T('\0')) |
|---|
| 5475 | n/a | id->prefix = &dtd->defaultPrefix; |
|---|
| 5476 | n/a | else |
|---|
| 5477 | n/a | id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, name + 6, sizeof(PREFIX)); |
|---|
| 5478 | n/a | id->xmlns = XML_TRUE; |
|---|
| 5479 | n/a | } |
|---|
| 5480 | n/a | else { |
|---|
| 5481 | n/a | int i; |
|---|
| 5482 | n/a | for (i = 0; name[i]; i++) { |
|---|
| 5483 | n/a | /* attributes without prefix are *not* in the default namespace */ |
|---|
| 5484 | n/a | if (name[i] == XML_T(ASCII_COLON)) { |
|---|
| 5485 | n/a | int j; |
|---|
| 5486 | n/a | for (j = 0; j < i; j++) { |
|---|
| 5487 | n/a | if (!poolAppendChar(&dtd->pool, name[j])) |
|---|
| 5488 | n/a | return NULL; |
|---|
| 5489 | n/a | } |
|---|
| 5490 | n/a | if (!poolAppendChar(&dtd->pool, XML_T('\0'))) |
|---|
| 5491 | n/a | return NULL; |
|---|
| 5492 | n/a | id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd->pool), |
|---|
| 5493 | n/a | sizeof(PREFIX)); |
|---|
| 5494 | n/a | if (!id->prefix) |
|---|
| 5495 | n/a | return NULL; |
|---|
| 5496 | n/a | if (id->prefix->name == poolStart(&dtd->pool)) |
|---|
| 5497 | n/a | poolFinish(&dtd->pool); |
|---|
| 5498 | n/a | else |
|---|
| 5499 | n/a | poolDiscard(&dtd->pool); |
|---|
| 5500 | n/a | break; |
|---|
| 5501 | n/a | } |
|---|
| 5502 | n/a | } |
|---|
| 5503 | n/a | } |
|---|
| 5504 | n/a | } |
|---|
| 5505 | n/a | return id; |
|---|
| 5506 | n/a | } |
|---|
| 5507 | n/a | |
|---|
| 5508 | n/a | #define CONTEXT_SEP XML_T(ASCII_FF) |
|---|
| 5509 | n/a | |
|---|
| 5510 | n/a | static const XML_Char * |
|---|
| 5511 | n/a | getContext(XML_Parser parser) |
|---|
| 5512 | n/a | { |
|---|
| 5513 | n/a | DTD * const dtd = _dtd; /* save one level of indirection */ |
|---|
| 5514 | n/a | HASH_TABLE_ITER iter; |
|---|
| 5515 | n/a | XML_Bool needSep = XML_FALSE; |
|---|
| 5516 | n/a | |
|---|
| 5517 | n/a | if (dtd->defaultPrefix.binding) { |
|---|
| 5518 | n/a | int i; |
|---|
| 5519 | n/a | int len; |
|---|
| 5520 | n/a | if (!poolAppendChar(&tempPool, XML_T(ASCII_EQUALS))) |
|---|
| 5521 | n/a | return NULL; |
|---|
| 5522 | n/a | len = dtd->defaultPrefix.binding->uriLen; |
|---|
| 5523 | n/a | if (namespaceSeparator) |
|---|
| 5524 | n/a | len--; |
|---|
| 5525 | n/a | for (i = 0; i < len; i++) |
|---|
| 5526 | n/a | if (!poolAppendChar(&tempPool, dtd->defaultPrefix.binding->uri[i])) |
|---|
| 5527 | n/a | return NULL; |
|---|
| 5528 | n/a | needSep = XML_TRUE; |
|---|
| 5529 | n/a | } |
|---|
| 5530 | n/a | |
|---|
| 5531 | n/a | hashTableIterInit(&iter, &(dtd->prefixes)); |
|---|
| 5532 | n/a | for (;;) { |
|---|
| 5533 | n/a | int i; |
|---|
| 5534 | n/a | int len; |
|---|
| 5535 | n/a | const XML_Char *s; |
|---|
| 5536 | n/a | PREFIX *prefix = (PREFIX *)hashTableIterNext(&iter); |
|---|
| 5537 | n/a | if (!prefix) |
|---|
| 5538 | n/a | break; |
|---|
| 5539 | n/a | if (!prefix->binding) |
|---|
| 5540 | n/a | continue; |
|---|
| 5541 | n/a | if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP)) |
|---|
| 5542 | n/a | return NULL; |
|---|
| 5543 | n/a | for (s = prefix->name; *s; s++) |
|---|
| 5544 | n/a | if (!poolAppendChar(&tempPool, *s)) |
|---|
| 5545 | n/a | return NULL; |
|---|
| 5546 | n/a | if (!poolAppendChar(&tempPool, XML_T(ASCII_EQUALS))) |
|---|
| 5547 | n/a | return NULL; |
|---|
| 5548 | n/a | len = prefix->binding->uriLen; |
|---|
| 5549 | n/a | if (namespaceSeparator) |
|---|
| 5550 | n/a | len--; |
|---|
| 5551 | n/a | for (i = 0; i < len; i++) |
|---|
| 5552 | n/a | if (!poolAppendChar(&tempPool, prefix->binding->uri[i])) |
|---|
| 5553 | n/a | return NULL; |
|---|
| 5554 | n/a | needSep = XML_TRUE; |
|---|
| 5555 | n/a | } |
|---|
| 5556 | n/a | |
|---|
| 5557 | n/a | |
|---|
| 5558 | n/a | hashTableIterInit(&iter, &(dtd->generalEntities)); |
|---|
| 5559 | n/a | for (;;) { |
|---|
| 5560 | n/a | const XML_Char *s; |
|---|
| 5561 | n/a | ENTITY *e = (ENTITY *)hashTableIterNext(&iter); |
|---|
| 5562 | n/a | if (!e) |
|---|
| 5563 | n/a | break; |
|---|
| 5564 | n/a | if (!e->open) |
|---|
| 5565 | n/a | continue; |
|---|
| 5566 | n/a | if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP)) |
|---|
| 5567 | n/a | return NULL; |
|---|
| 5568 | n/a | for (s = e->name; *s; s++) |
|---|
| 5569 | n/a | if (!poolAppendChar(&tempPool, *s)) |
|---|
| 5570 | n/a | return 0; |
|---|
| 5571 | n/a | needSep = XML_TRUE; |
|---|
| 5572 | n/a | } |
|---|
| 5573 | n/a | |
|---|
| 5574 | n/a | if (!poolAppendChar(&tempPool, XML_T('\0'))) |
|---|
| 5575 | n/a | return NULL; |
|---|
| 5576 | n/a | return tempPool.start; |
|---|
| 5577 | n/a | } |
|---|
| 5578 | n/a | |
|---|
| 5579 | n/a | static XML_Bool |
|---|
| 5580 | n/a | setContext(XML_Parser parser, const XML_Char *context) |
|---|
| 5581 | n/a | { |
|---|
| 5582 | n/a | DTD * const dtd = _dtd; /* save one level of indirection */ |
|---|
| 5583 | n/a | const XML_Char *s = context; |
|---|
| 5584 | n/a | |
|---|
| 5585 | n/a | while (*context != XML_T('\0')) { |
|---|
| 5586 | n/a | if (*s == CONTEXT_SEP || *s == XML_T('\0')) { |
|---|
| 5587 | n/a | ENTITY *e; |
|---|
| 5588 | n/a | if (!poolAppendChar(&tempPool, XML_T('\0'))) |
|---|
| 5589 | n/a | return XML_FALSE; |
|---|
| 5590 | n/a | e = (ENTITY *)lookup(parser, &dtd->generalEntities, poolStart(&tempPool), 0); |
|---|
| 5591 | n/a | if (e) |
|---|
| 5592 | n/a | e->open = XML_TRUE; |
|---|
| 5593 | n/a | if (*s != XML_T('\0')) |
|---|
| 5594 | n/a | s++; |
|---|
| 5595 | n/a | context = s; |
|---|
| 5596 | n/a | poolDiscard(&tempPool); |
|---|
| 5597 | n/a | } |
|---|
| 5598 | n/a | else if (*s == XML_T(ASCII_EQUALS)) { |
|---|
| 5599 | n/a | PREFIX *prefix; |
|---|
| 5600 | n/a | if (poolLength(&tempPool) == 0) |
|---|
| 5601 | n/a | prefix = &dtd->defaultPrefix; |
|---|
| 5602 | n/a | else { |
|---|
| 5603 | n/a | if (!poolAppendChar(&tempPool, XML_T('\0'))) |
|---|
| 5604 | n/a | return XML_FALSE; |
|---|
| 5605 | n/a | prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&tempPool), |
|---|
| 5606 | n/a | sizeof(PREFIX)); |
|---|
| 5607 | n/a | if (!prefix) |
|---|
| 5608 | n/a | return XML_FALSE; |
|---|
| 5609 | n/a | if (prefix->name == poolStart(&tempPool)) { |
|---|
| 5610 | n/a | prefix->name = poolCopyString(&dtd->pool, prefix->name); |
|---|
| 5611 | n/a | if (!prefix->name) |
|---|
| 5612 | n/a | return XML_FALSE; |
|---|
| 5613 | n/a | } |
|---|
| 5614 | n/a | poolDiscard(&tempPool); |
|---|
| 5615 | n/a | } |
|---|
| 5616 | n/a | for (context = s + 1; |
|---|
| 5617 | n/a | *context != CONTEXT_SEP && *context != XML_T('\0'); |
|---|
| 5618 | n/a | context++) |
|---|
| 5619 | n/a | if (!poolAppendChar(&tempPool, *context)) |
|---|
| 5620 | n/a | return XML_FALSE; |
|---|
| 5621 | n/a | if (!poolAppendChar(&tempPool, XML_T('\0'))) |
|---|
| 5622 | n/a | return XML_FALSE; |
|---|
| 5623 | n/a | if (addBinding(parser, prefix, NULL, poolStart(&tempPool), |
|---|
| 5624 | n/a | &inheritedBindings) != XML_ERROR_NONE) |
|---|
| 5625 | n/a | return XML_FALSE; |
|---|
| 5626 | n/a | poolDiscard(&tempPool); |
|---|
| 5627 | n/a | if (*context != XML_T('\0')) |
|---|
| 5628 | n/a | ++context; |
|---|
| 5629 | n/a | s = context; |
|---|
| 5630 | n/a | } |
|---|
| 5631 | n/a | else { |
|---|
| 5632 | n/a | if (!poolAppendChar(&tempPool, *s)) |
|---|
| 5633 | n/a | return XML_FALSE; |
|---|
| 5634 | n/a | s++; |
|---|
| 5635 | n/a | } |
|---|
| 5636 | n/a | } |
|---|
| 5637 | n/a | return XML_TRUE; |
|---|
| 5638 | n/a | } |
|---|
| 5639 | n/a | |
|---|
| 5640 | n/a | static void FASTCALL |
|---|
| 5641 | n/a | normalizePublicId(XML_Char *publicId) |
|---|
| 5642 | n/a | { |
|---|
| 5643 | n/a | XML_Char *p = publicId; |
|---|
| 5644 | n/a | XML_Char *s; |
|---|
| 5645 | n/a | for (s = publicId; *s; s++) { |
|---|
| 5646 | n/a | switch (*s) { |
|---|
| 5647 | n/a | case 0x20: |
|---|
| 5648 | n/a | case 0xD: |
|---|
| 5649 | n/a | case 0xA: |
|---|
| 5650 | n/a | if (p != publicId && p[-1] != 0x20) |
|---|
| 5651 | n/a | *p++ = 0x20; |
|---|
| 5652 | n/a | break; |
|---|
| 5653 | n/a | default: |
|---|
| 5654 | n/a | *p++ = *s; |
|---|
| 5655 | n/a | } |
|---|
| 5656 | n/a | } |
|---|
| 5657 | n/a | if (p != publicId && p[-1] == 0x20) |
|---|
| 5658 | n/a | --p; |
|---|
| 5659 | n/a | *p = XML_T('\0'); |
|---|
| 5660 | n/a | } |
|---|
| 5661 | n/a | |
|---|
| 5662 | n/a | static DTD * |
|---|
| 5663 | n/a | dtdCreate(const XML_Memory_Handling_Suite *ms) |
|---|
| 5664 | n/a | { |
|---|
| 5665 | n/a | DTD *p = (DTD *)ms->malloc_fcn(sizeof(DTD)); |
|---|
| 5666 | n/a | if (p == NULL) |
|---|
| 5667 | n/a | return p; |
|---|
| 5668 | n/a | poolInit(&(p->pool), ms); |
|---|
| 5669 | n/a | poolInit(&(p->entityValuePool), ms); |
|---|
| 5670 | n/a | hashTableInit(&(p->generalEntities), ms); |
|---|
| 5671 | n/a | hashTableInit(&(p->elementTypes), ms); |
|---|
| 5672 | n/a | hashTableInit(&(p->attributeIds), ms); |
|---|
| 5673 | n/a | hashTableInit(&(p->prefixes), ms); |
|---|
| 5674 | n/a | #ifdef XML_DTD |
|---|
| 5675 | n/a | p->paramEntityRead = XML_FALSE; |
|---|
| 5676 | n/a | hashTableInit(&(p->paramEntities), ms); |
|---|
| 5677 | n/a | #endif /* XML_DTD */ |
|---|
| 5678 | n/a | p->defaultPrefix.name = NULL; |
|---|
| 5679 | n/a | p->defaultPrefix.binding = NULL; |
|---|
| 5680 | n/a | |
|---|
| 5681 | n/a | p->in_eldecl = XML_FALSE; |
|---|
| 5682 | n/a | p->scaffIndex = NULL; |
|---|
| 5683 | n/a | p->scaffold = NULL; |
|---|
| 5684 | n/a | p->scaffLevel = 0; |
|---|
| 5685 | n/a | p->scaffSize = 0; |
|---|
| 5686 | n/a | p->scaffCount = 0; |
|---|
| 5687 | n/a | p->contentStringLen = 0; |
|---|
| 5688 | n/a | |
|---|
| 5689 | n/a | p->keepProcessing = XML_TRUE; |
|---|
| 5690 | n/a | p->hasParamEntityRefs = XML_FALSE; |
|---|
| 5691 | n/a | p->standalone = XML_FALSE; |
|---|
| 5692 | n/a | return p; |
|---|
| 5693 | n/a | } |
|---|
| 5694 | n/a | |
|---|
| 5695 | n/a | static void |
|---|
| 5696 | n/a | dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms) |
|---|
| 5697 | n/a | { |
|---|
| 5698 | n/a | HASH_TABLE_ITER iter; |
|---|
| 5699 | n/a | hashTableIterInit(&iter, &(p->elementTypes)); |
|---|
| 5700 | n/a | for (;;) { |
|---|
| 5701 | n/a | ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter); |
|---|
| 5702 | n/a | if (!e) |
|---|
| 5703 | n/a | break; |
|---|
| 5704 | n/a | if (e->allocDefaultAtts != 0) |
|---|
| 5705 | n/a | ms->free_fcn(e->defaultAtts); |
|---|
| 5706 | n/a | } |
|---|
| 5707 | n/a | hashTableClear(&(p->generalEntities)); |
|---|
| 5708 | n/a | #ifdef XML_DTD |
|---|
| 5709 | n/a | p->paramEntityRead = XML_FALSE; |
|---|
| 5710 | n/a | hashTableClear(&(p->paramEntities)); |
|---|
| 5711 | n/a | #endif /* XML_DTD */ |
|---|
| 5712 | n/a | hashTableClear(&(p->elementTypes)); |
|---|
| 5713 | n/a | hashTableClear(&(p->attributeIds)); |
|---|
| 5714 | n/a | hashTableClear(&(p->prefixes)); |
|---|
| 5715 | n/a | poolClear(&(p->pool)); |
|---|
| 5716 | n/a | poolClear(&(p->entityValuePool)); |
|---|
| 5717 | n/a | p->defaultPrefix.name = NULL; |
|---|
| 5718 | n/a | p->defaultPrefix.binding = NULL; |
|---|
| 5719 | n/a | |
|---|
| 5720 | n/a | p->in_eldecl = XML_FALSE; |
|---|
| 5721 | n/a | |
|---|
| 5722 | n/a | ms->free_fcn(p->scaffIndex); |
|---|
| 5723 | n/a | p->scaffIndex = NULL; |
|---|
| 5724 | n/a | ms->free_fcn(p->scaffold); |
|---|
| 5725 | n/a | p->scaffold = NULL; |
|---|
| 5726 | n/a | |
|---|
| 5727 | n/a | p->scaffLevel = 0; |
|---|
| 5728 | n/a | p->scaffSize = 0; |
|---|
| 5729 | n/a | p->scaffCount = 0; |
|---|
| 5730 | n/a | p->contentStringLen = 0; |
|---|
| 5731 | n/a | |
|---|
| 5732 | n/a | p->keepProcessing = XML_TRUE; |
|---|
| 5733 | n/a | p->hasParamEntityRefs = XML_FALSE; |
|---|
| 5734 | n/a | p->standalone = XML_FALSE; |
|---|
| 5735 | n/a | } |
|---|
| 5736 | n/a | |
|---|
| 5737 | n/a | static void |
|---|
| 5738 | n/a | dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms) |
|---|
| 5739 | n/a | { |
|---|
| 5740 | n/a | HASH_TABLE_ITER iter; |
|---|
| 5741 | n/a | hashTableIterInit(&iter, &(p->elementTypes)); |
|---|
| 5742 | n/a | for (;;) { |
|---|
| 5743 | n/a | ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter); |
|---|
| 5744 | n/a | if (!e) |
|---|
| 5745 | n/a | break; |
|---|
| 5746 | n/a | if (e->allocDefaultAtts != 0) |
|---|
| 5747 | n/a | ms->free_fcn(e->defaultAtts); |
|---|
| 5748 | n/a | } |
|---|
| 5749 | n/a | hashTableDestroy(&(p->generalEntities)); |
|---|
| 5750 | n/a | #ifdef XML_DTD |
|---|
| 5751 | n/a | hashTableDestroy(&(p->paramEntities)); |
|---|
| 5752 | n/a | #endif /* XML_DTD */ |
|---|
| 5753 | n/a | hashTableDestroy(&(p->elementTypes)); |
|---|
| 5754 | n/a | hashTableDestroy(&(p->attributeIds)); |
|---|
| 5755 | n/a | hashTableDestroy(&(p->prefixes)); |
|---|
| 5756 | n/a | poolDestroy(&(p->pool)); |
|---|
| 5757 | n/a | poolDestroy(&(p->entityValuePool)); |
|---|
| 5758 | n/a | if (isDocEntity) { |
|---|
| 5759 | n/a | ms->free_fcn(p->scaffIndex); |
|---|
| 5760 | n/a | ms->free_fcn(p->scaffold); |
|---|
| 5761 | n/a | } |
|---|
| 5762 | n/a | ms->free_fcn(p); |
|---|
| 5763 | n/a | } |
|---|
| 5764 | n/a | |
|---|
| 5765 | n/a | /* Do a deep copy of the DTD. Return 0 for out of memory, non-zero otherwise. |
|---|
| 5766 | n/a | The new DTD has already been initialized. |
|---|
| 5767 | n/a | */ |
|---|
| 5768 | n/a | static int |
|---|
| 5769 | n/a | dtdCopy(XML_Parser oldParser, DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms) |
|---|
| 5770 | n/a | { |
|---|
| 5771 | n/a | HASH_TABLE_ITER iter; |
|---|
| 5772 | n/a | |
|---|
| 5773 | n/a | /* Copy the prefix table. */ |
|---|
| 5774 | n/a | |
|---|
| 5775 | n/a | hashTableIterInit(&iter, &(oldDtd->prefixes)); |
|---|
| 5776 | n/a | for (;;) { |
|---|
| 5777 | n/a | const XML_Char *name; |
|---|
| 5778 | n/a | const PREFIX *oldP = (PREFIX *)hashTableIterNext(&iter); |
|---|
| 5779 | n/a | if (!oldP) |
|---|
| 5780 | n/a | break; |
|---|
| 5781 | n/a | name = poolCopyString(&(newDtd->pool), oldP->name); |
|---|
| 5782 | n/a | if (!name) |
|---|
| 5783 | n/a | return 0; |
|---|
| 5784 | n/a | if (!lookup(oldParser, &(newDtd->prefixes), name, sizeof(PREFIX))) |
|---|
| 5785 | n/a | return 0; |
|---|
| 5786 | n/a | } |
|---|
| 5787 | n/a | |
|---|
| 5788 | n/a | hashTableIterInit(&iter, &(oldDtd->attributeIds)); |
|---|
| 5789 | n/a | |
|---|
| 5790 | n/a | /* Copy the attribute id table. */ |
|---|
| 5791 | n/a | |
|---|
| 5792 | n/a | for (;;) { |
|---|
| 5793 | n/a | ATTRIBUTE_ID *newA; |
|---|
| 5794 | n/a | const XML_Char *name; |
|---|
| 5795 | n/a | const ATTRIBUTE_ID *oldA = (ATTRIBUTE_ID *)hashTableIterNext(&iter); |
|---|
| 5796 | n/a | |
|---|
| 5797 | n/a | if (!oldA) |
|---|
| 5798 | n/a | break; |
|---|
| 5799 | n/a | /* Remember to allocate the scratch byte before the name. */ |
|---|
| 5800 | n/a | if (!poolAppendChar(&(newDtd->pool), XML_T('\0'))) |
|---|
| 5801 | n/a | return 0; |
|---|
| 5802 | n/a | name = poolCopyString(&(newDtd->pool), oldA->name); |
|---|
| 5803 | n/a | if (!name) |
|---|
| 5804 | n/a | return 0; |
|---|
| 5805 | n/a | ++name; |
|---|
| 5806 | n/a | newA = (ATTRIBUTE_ID *)lookup(oldParser, &(newDtd->attributeIds), name, |
|---|
| 5807 | n/a | sizeof(ATTRIBUTE_ID)); |
|---|
| 5808 | n/a | if (!newA) |
|---|
| 5809 | n/a | return 0; |
|---|
| 5810 | n/a | newA->maybeTokenized = oldA->maybeTokenized; |
|---|
| 5811 | n/a | if (oldA->prefix) { |
|---|
| 5812 | n/a | newA->xmlns = oldA->xmlns; |
|---|
| 5813 | n/a | if (oldA->prefix == &oldDtd->defaultPrefix) |
|---|
| 5814 | n/a | newA->prefix = &newDtd->defaultPrefix; |
|---|
| 5815 | n/a | else |
|---|
| 5816 | n/a | newA->prefix = (PREFIX *)lookup(oldParser, &(newDtd->prefixes), |
|---|
| 5817 | n/a | oldA->prefix->name, 0); |
|---|
| 5818 | n/a | } |
|---|
| 5819 | n/a | } |
|---|
| 5820 | n/a | |
|---|
| 5821 | n/a | /* Copy the element type table. */ |
|---|
| 5822 | n/a | |
|---|
| 5823 | n/a | hashTableIterInit(&iter, &(oldDtd->elementTypes)); |
|---|
| 5824 | n/a | |
|---|
| 5825 | n/a | for (;;) { |
|---|
| 5826 | n/a | int i; |
|---|
| 5827 | n/a | ELEMENT_TYPE *newE; |
|---|
| 5828 | n/a | const XML_Char *name; |
|---|
| 5829 | n/a | const ELEMENT_TYPE *oldE = (ELEMENT_TYPE *)hashTableIterNext(&iter); |
|---|
| 5830 | n/a | if (!oldE) |
|---|
| 5831 | n/a | break; |
|---|
| 5832 | n/a | name = poolCopyString(&(newDtd->pool), oldE->name); |
|---|
| 5833 | n/a | if (!name) |
|---|
| 5834 | n/a | return 0; |
|---|
| 5835 | n/a | newE = (ELEMENT_TYPE *)lookup(oldParser, &(newDtd->elementTypes), name, |
|---|
| 5836 | n/a | sizeof(ELEMENT_TYPE)); |
|---|
| 5837 | n/a | if (!newE) |
|---|
| 5838 | n/a | return 0; |
|---|
| 5839 | n/a | if (oldE->nDefaultAtts) { |
|---|
| 5840 | n/a | newE->defaultAtts = (DEFAULT_ATTRIBUTE *) |
|---|
| 5841 | n/a | ms->malloc_fcn(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); |
|---|
| 5842 | n/a | if (!newE->defaultAtts) { |
|---|
| 5843 | n/a | ms->free_fcn(newE); |
|---|
| 5844 | n/a | return 0; |
|---|
| 5845 | n/a | } |
|---|
| 5846 | n/a | } |
|---|
| 5847 | n/a | if (oldE->idAtt) |
|---|
| 5848 | n/a | newE->idAtt = (ATTRIBUTE_ID *) |
|---|
| 5849 | n/a | lookup(oldParser, &(newDtd->attributeIds), oldE->idAtt->name, 0); |
|---|
| 5850 | n/a | newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts; |
|---|
| 5851 | n/a | if (oldE->prefix) |
|---|
| 5852 | n/a | newE->prefix = (PREFIX *)lookup(oldParser, &(newDtd->prefixes), |
|---|
| 5853 | n/a | oldE->prefix->name, 0); |
|---|
| 5854 | n/a | for (i = 0; i < newE->nDefaultAtts; i++) { |
|---|
| 5855 | n/a | newE->defaultAtts[i].id = (ATTRIBUTE_ID *) |
|---|
| 5856 | n/a | lookup(oldParser, &(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0); |
|---|
| 5857 | n/a | newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata; |
|---|
| 5858 | n/a | if (oldE->defaultAtts[i].value) { |
|---|
| 5859 | n/a | newE->defaultAtts[i].value |
|---|
| 5860 | n/a | = poolCopyString(&(newDtd->pool), oldE->defaultAtts[i].value); |
|---|
| 5861 | n/a | if (!newE->defaultAtts[i].value) |
|---|
| 5862 | n/a | return 0; |
|---|
| 5863 | n/a | } |
|---|
| 5864 | n/a | else |
|---|
| 5865 | n/a | newE->defaultAtts[i].value = NULL; |
|---|
| 5866 | n/a | } |
|---|
| 5867 | n/a | } |
|---|
| 5868 | n/a | |
|---|
| 5869 | n/a | /* Copy the entity tables. */ |
|---|
| 5870 | n/a | if (!copyEntityTable(oldParser, |
|---|
| 5871 | n/a | &(newDtd->generalEntities), |
|---|
| 5872 | n/a | &(newDtd->pool), |
|---|
| 5873 | n/a | &(oldDtd->generalEntities))) |
|---|
| 5874 | n/a | return 0; |
|---|
| 5875 | n/a | |
|---|
| 5876 | n/a | #ifdef XML_DTD |
|---|
| 5877 | n/a | if (!copyEntityTable(oldParser, |
|---|
| 5878 | n/a | &(newDtd->paramEntities), |
|---|
| 5879 | n/a | &(newDtd->pool), |
|---|
| 5880 | n/a | &(oldDtd->paramEntities))) |
|---|
| 5881 | n/a | return 0; |
|---|
| 5882 | n/a | newDtd->paramEntityRead = oldDtd->paramEntityRead; |
|---|
| 5883 | n/a | #endif /* XML_DTD */ |
|---|
| 5884 | n/a | |
|---|
| 5885 | n/a | newDtd->keepProcessing = oldDtd->keepProcessing; |
|---|
| 5886 | n/a | newDtd->hasParamEntityRefs = oldDtd->hasParamEntityRefs; |
|---|
| 5887 | n/a | newDtd->standalone = oldDtd->standalone; |
|---|
| 5888 | n/a | |
|---|
| 5889 | n/a | /* Don't want deep copying for scaffolding */ |
|---|
| 5890 | n/a | newDtd->in_eldecl = oldDtd->in_eldecl; |
|---|
| 5891 | n/a | newDtd->scaffold = oldDtd->scaffold; |
|---|
| 5892 | n/a | newDtd->contentStringLen = oldDtd->contentStringLen; |
|---|
| 5893 | n/a | newDtd->scaffSize = oldDtd->scaffSize; |
|---|
| 5894 | n/a | newDtd->scaffLevel = oldDtd->scaffLevel; |
|---|
| 5895 | n/a | newDtd->scaffIndex = oldDtd->scaffIndex; |
|---|
| 5896 | n/a | |
|---|
| 5897 | n/a | return 1; |
|---|
| 5898 | n/a | } /* End dtdCopy */ |
|---|
| 5899 | n/a | |
|---|
| 5900 | n/a | static int |
|---|
| 5901 | n/a | copyEntityTable(XML_Parser oldParser, |
|---|
| 5902 | n/a | HASH_TABLE *newTable, |
|---|
| 5903 | n/a | STRING_POOL *newPool, |
|---|
| 5904 | n/a | const HASH_TABLE *oldTable) |
|---|
| 5905 | n/a | { |
|---|
| 5906 | n/a | HASH_TABLE_ITER iter; |
|---|
| 5907 | n/a | const XML_Char *cachedOldBase = NULL; |
|---|
| 5908 | n/a | const XML_Char *cachedNewBase = NULL; |
|---|
| 5909 | n/a | |
|---|
| 5910 | n/a | hashTableIterInit(&iter, oldTable); |
|---|
| 5911 | n/a | |
|---|
| 5912 | n/a | for (;;) { |
|---|
| 5913 | n/a | ENTITY *newE; |
|---|
| 5914 | n/a | const XML_Char *name; |
|---|
| 5915 | n/a | const ENTITY *oldE = (ENTITY *)hashTableIterNext(&iter); |
|---|
| 5916 | n/a | if (!oldE) |
|---|
| 5917 | n/a | break; |
|---|
| 5918 | n/a | name = poolCopyString(newPool, oldE->name); |
|---|
| 5919 | n/a | if (!name) |
|---|
| 5920 | n/a | return 0; |
|---|
| 5921 | n/a | newE = (ENTITY *)lookup(oldParser, newTable, name, sizeof(ENTITY)); |
|---|
| 5922 | n/a | if (!newE) |
|---|
| 5923 | n/a | return 0; |
|---|
| 5924 | n/a | if (oldE->systemId) { |
|---|
| 5925 | n/a | const XML_Char *tem = poolCopyString(newPool, oldE->systemId); |
|---|
| 5926 | n/a | if (!tem) |
|---|
| 5927 | n/a | return 0; |
|---|
| 5928 | n/a | newE->systemId = tem; |
|---|
| 5929 | n/a | if (oldE->base) { |
|---|
| 5930 | n/a | if (oldE->base == cachedOldBase) |
|---|
| 5931 | n/a | newE->base = cachedNewBase; |
|---|
| 5932 | n/a | else { |
|---|
| 5933 | n/a | cachedOldBase = oldE->base; |
|---|
| 5934 | n/a | tem = poolCopyString(newPool, cachedOldBase); |
|---|
| 5935 | n/a | if (!tem) |
|---|
| 5936 | n/a | return 0; |
|---|
| 5937 | n/a | cachedNewBase = newE->base = tem; |
|---|
| 5938 | n/a | } |
|---|
| 5939 | n/a | } |
|---|
| 5940 | n/a | if (oldE->publicId) { |
|---|
| 5941 | n/a | tem = poolCopyString(newPool, oldE->publicId); |
|---|
| 5942 | n/a | if (!tem) |
|---|
| 5943 | n/a | return 0; |
|---|
| 5944 | n/a | newE->publicId = tem; |
|---|
| 5945 | n/a | } |
|---|
| 5946 | n/a | } |
|---|
| 5947 | n/a | else { |
|---|
| 5948 | n/a | const XML_Char *tem = poolCopyStringN(newPool, oldE->textPtr, |
|---|
| 5949 | n/a | oldE->textLen); |
|---|
| 5950 | n/a | if (!tem) |
|---|
| 5951 | n/a | return 0; |
|---|
| 5952 | n/a | newE->textPtr = tem; |
|---|
| 5953 | n/a | newE->textLen = oldE->textLen; |
|---|
| 5954 | n/a | } |
|---|
| 5955 | n/a | if (oldE->notation) { |
|---|
| 5956 | n/a | const XML_Char *tem = poolCopyString(newPool, oldE->notation); |
|---|
| 5957 | n/a | if (!tem) |
|---|
| 5958 | n/a | return 0; |
|---|
| 5959 | n/a | newE->notation = tem; |
|---|
| 5960 | n/a | } |
|---|
| 5961 | n/a | newE->is_param = oldE->is_param; |
|---|
| 5962 | n/a | newE->is_internal = oldE->is_internal; |
|---|
| 5963 | n/a | } |
|---|
| 5964 | n/a | return 1; |
|---|
| 5965 | n/a | } |
|---|
| 5966 | n/a | |
|---|
| 5967 | n/a | #define INIT_POWER 6 |
|---|
| 5968 | n/a | |
|---|
| 5969 | n/a | static XML_Bool FASTCALL |
|---|
| 5970 | n/a | keyeq(KEY s1, KEY s2) |
|---|
| 5971 | n/a | { |
|---|
| 5972 | n/a | for (; *s1 == *s2; s1++, s2++) |
|---|
| 5973 | n/a | if (*s1 == 0) |
|---|
| 5974 | n/a | return XML_TRUE; |
|---|
| 5975 | n/a | return XML_FALSE; |
|---|
| 5976 | n/a | } |
|---|
| 5977 | n/a | |
|---|
| 5978 | n/a | static unsigned long FASTCALL |
|---|
| 5979 | n/a | hash(XML_Parser parser, KEY s) |
|---|
| 5980 | n/a | { |
|---|
| 5981 | n/a | unsigned long h = hash_secret_salt; |
|---|
| 5982 | n/a | while (*s) |
|---|
| 5983 | n/a | h = CHAR_HASH(h, *s++); |
|---|
| 5984 | n/a | return h; |
|---|
| 5985 | n/a | } |
|---|
| 5986 | n/a | |
|---|
| 5987 | n/a | static NAMED * |
|---|
| 5988 | n/a | lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize) |
|---|
| 5989 | n/a | { |
|---|
| 5990 | n/a | size_t i; |
|---|
| 5991 | n/a | if (table->size == 0) { |
|---|
| 5992 | n/a | size_t tsize; |
|---|
| 5993 | n/a | if (!createSize) |
|---|
| 5994 | n/a | return NULL; |
|---|
| 5995 | n/a | table->power = INIT_POWER; |
|---|
| 5996 | n/a | /* table->size is a power of 2 */ |
|---|
| 5997 | n/a | table->size = (size_t)1 << INIT_POWER; |
|---|
| 5998 | n/a | tsize = table->size * sizeof(NAMED *); |
|---|
| 5999 | n/a | table->v = (NAMED **)table->mem->malloc_fcn(tsize); |
|---|
| 6000 | n/a | if (!table->v) { |
|---|
| 6001 | n/a | table->size = 0; |
|---|
| 6002 | n/a | return NULL; |
|---|
| 6003 | n/a | } |
|---|
| 6004 | n/a | memset(table->v, 0, tsize); |
|---|
| 6005 | n/a | i = hash(parser, name) & ((unsigned long)table->size - 1); |
|---|
| 6006 | n/a | } |
|---|
| 6007 | n/a | else { |
|---|
| 6008 | n/a | unsigned long h = hash(parser, name); |
|---|
| 6009 | n/a | unsigned long mask = (unsigned long)table->size - 1; |
|---|
| 6010 | n/a | unsigned char step = 0; |
|---|
| 6011 | n/a | i = h & mask; |
|---|
| 6012 | n/a | while (table->v[i]) { |
|---|
| 6013 | n/a | if (keyeq(name, table->v[i]->name)) |
|---|
| 6014 | n/a | return table->v[i]; |
|---|
| 6015 | n/a | if (!step) |
|---|
| 6016 | n/a | step = PROBE_STEP(h, mask, table->power); |
|---|
| 6017 | n/a | i < step ? (i += table->size - step) : (i -= step); |
|---|
| 6018 | n/a | } |
|---|
| 6019 | n/a | if (!createSize) |
|---|
| 6020 | n/a | return NULL; |
|---|
| 6021 | n/a | |
|---|
| 6022 | n/a | /* check for overflow (table is half full) */ |
|---|
| 6023 | n/a | if (table->used >> (table->power - 1)) { |
|---|
| 6024 | n/a | unsigned char newPower = table->power + 1; |
|---|
| 6025 | n/a | size_t newSize = (size_t)1 << newPower; |
|---|
| 6026 | n/a | unsigned long newMask = (unsigned long)newSize - 1; |
|---|
| 6027 | n/a | size_t tsize = newSize * sizeof(NAMED *); |
|---|
| 6028 | n/a | NAMED **newV = (NAMED **)table->mem->malloc_fcn(tsize); |
|---|
| 6029 | n/a | if (!newV) |
|---|
| 6030 | n/a | return NULL; |
|---|
| 6031 | n/a | memset(newV, 0, tsize); |
|---|
| 6032 | n/a | for (i = 0; i < table->size; i++) |
|---|
| 6033 | n/a | if (table->v[i]) { |
|---|
| 6034 | n/a | unsigned long newHash = hash(parser, table->v[i]->name); |
|---|
| 6035 | n/a | size_t j = newHash & newMask; |
|---|
| 6036 | n/a | step = 0; |
|---|
| 6037 | n/a | while (newV[j]) { |
|---|
| 6038 | n/a | if (!step) |
|---|
| 6039 | n/a | step = PROBE_STEP(newHash, newMask, newPower); |
|---|
| 6040 | n/a | j < step ? (j += newSize - step) : (j -= step); |
|---|
| 6041 | n/a | } |
|---|
| 6042 | n/a | newV[j] = table->v[i]; |
|---|
| 6043 | n/a | } |
|---|
| 6044 | n/a | table->mem->free_fcn(table->v); |
|---|
| 6045 | n/a | table->v = newV; |
|---|
| 6046 | n/a | table->power = newPower; |
|---|
| 6047 | n/a | table->size = newSize; |
|---|
| 6048 | n/a | i = h & newMask; |
|---|
| 6049 | n/a | step = 0; |
|---|
| 6050 | n/a | while (table->v[i]) { |
|---|
| 6051 | n/a | if (!step) |
|---|
| 6052 | n/a | step = PROBE_STEP(h, newMask, newPower); |
|---|
| 6053 | n/a | i < step ? (i += newSize - step) : (i -= step); |
|---|
| 6054 | n/a | } |
|---|
| 6055 | n/a | } |
|---|
| 6056 | n/a | } |
|---|
| 6057 | n/a | table->v[i] = (NAMED *)table->mem->malloc_fcn(createSize); |
|---|
| 6058 | n/a | if (!table->v[i]) |
|---|
| 6059 | n/a | return NULL; |
|---|
| 6060 | n/a | memset(table->v[i], 0, createSize); |
|---|
| 6061 | n/a | table->v[i]->name = name; |
|---|
| 6062 | n/a | (table->used)++; |
|---|
| 6063 | n/a | return table->v[i]; |
|---|
| 6064 | n/a | } |
|---|
| 6065 | n/a | |
|---|
| 6066 | n/a | static void FASTCALL |
|---|
| 6067 | n/a | hashTableClear(HASH_TABLE *table) |
|---|
| 6068 | n/a | { |
|---|
| 6069 | n/a | size_t i; |
|---|
| 6070 | n/a | for (i = 0; i < table->size; i++) { |
|---|
| 6071 | n/a | table->mem->free_fcn(table->v[i]); |
|---|
| 6072 | n/a | table->v[i] = NULL; |
|---|
| 6073 | n/a | } |
|---|
| 6074 | n/a | table->used = 0; |
|---|
| 6075 | n/a | } |
|---|
| 6076 | n/a | |
|---|
| 6077 | n/a | static void FASTCALL |
|---|
| 6078 | n/a | hashTableDestroy(HASH_TABLE *table) |
|---|
| 6079 | n/a | { |
|---|
| 6080 | n/a | size_t i; |
|---|
| 6081 | n/a | for (i = 0; i < table->size; i++) |
|---|
| 6082 | n/a | table->mem->free_fcn(table->v[i]); |
|---|
| 6083 | n/a | table->mem->free_fcn(table->v); |
|---|
| 6084 | n/a | } |
|---|
| 6085 | n/a | |
|---|
| 6086 | n/a | static void FASTCALL |
|---|
| 6087 | n/a | hashTableInit(HASH_TABLE *p, const XML_Memory_Handling_Suite *ms) |
|---|
| 6088 | n/a | { |
|---|
| 6089 | n/a | p->power = 0; |
|---|
| 6090 | n/a | p->size = 0; |
|---|
| 6091 | n/a | p->used = 0; |
|---|
| 6092 | n/a | p->v = NULL; |
|---|
| 6093 | n/a | p->mem = ms; |
|---|
| 6094 | n/a | } |
|---|
| 6095 | n/a | |
|---|
| 6096 | n/a | static void FASTCALL |
|---|
| 6097 | n/a | hashTableIterInit(HASH_TABLE_ITER *iter, const HASH_TABLE *table) |
|---|
| 6098 | n/a | { |
|---|
| 6099 | n/a | iter->p = table->v; |
|---|
| 6100 | n/a | iter->end = iter->p + table->size; |
|---|
| 6101 | n/a | } |
|---|
| 6102 | n/a | |
|---|
| 6103 | n/a | static NAMED * FASTCALL |
|---|
| 6104 | n/a | hashTableIterNext(HASH_TABLE_ITER *iter) |
|---|
| 6105 | n/a | { |
|---|
| 6106 | n/a | while (iter->p != iter->end) { |
|---|
| 6107 | n/a | NAMED *tem = *(iter->p)++; |
|---|
| 6108 | n/a | if (tem) |
|---|
| 6109 | n/a | return tem; |
|---|
| 6110 | n/a | } |
|---|
| 6111 | n/a | return NULL; |
|---|
| 6112 | n/a | } |
|---|
| 6113 | n/a | |
|---|
| 6114 | n/a | static void FASTCALL |
|---|
| 6115 | n/a | poolInit(STRING_POOL *pool, const XML_Memory_Handling_Suite *ms) |
|---|
| 6116 | n/a | { |
|---|
| 6117 | n/a | pool->blocks = NULL; |
|---|
| 6118 | n/a | pool->freeBlocks = NULL; |
|---|
| 6119 | n/a | pool->start = NULL; |
|---|
| 6120 | n/a | pool->ptr = NULL; |
|---|
| 6121 | n/a | pool->end = NULL; |
|---|
| 6122 | n/a | pool->mem = ms; |
|---|
| 6123 | n/a | } |
|---|
| 6124 | n/a | |
|---|
| 6125 | n/a | static void FASTCALL |
|---|
| 6126 | n/a | poolClear(STRING_POOL *pool) |
|---|
| 6127 | n/a | { |
|---|
| 6128 | n/a | if (!pool->freeBlocks) |
|---|
| 6129 | n/a | pool->freeBlocks = pool->blocks; |
|---|
| 6130 | n/a | else { |
|---|
| 6131 | n/a | BLOCK *p = pool->blocks; |
|---|
| 6132 | n/a | while (p) { |
|---|
| 6133 | n/a | BLOCK *tem = p->next; |
|---|
| 6134 | n/a | p->next = pool->freeBlocks; |
|---|
| 6135 | n/a | pool->freeBlocks = p; |
|---|
| 6136 | n/a | p = tem; |
|---|
| 6137 | n/a | } |
|---|
| 6138 | n/a | } |
|---|
| 6139 | n/a | pool->blocks = NULL; |
|---|
| 6140 | n/a | pool->start = NULL; |
|---|
| 6141 | n/a | pool->ptr = NULL; |
|---|
| 6142 | n/a | pool->end = NULL; |
|---|
| 6143 | n/a | } |
|---|
| 6144 | n/a | |
|---|
| 6145 | n/a | static void FASTCALL |
|---|
| 6146 | n/a | poolDestroy(STRING_POOL *pool) |
|---|
| 6147 | n/a | { |
|---|
| 6148 | n/a | BLOCK *p = pool->blocks; |
|---|
| 6149 | n/a | while (p) { |
|---|
| 6150 | n/a | BLOCK *tem = p->next; |
|---|
| 6151 | n/a | pool->mem->free_fcn(p); |
|---|
| 6152 | n/a | p = tem; |
|---|
| 6153 | n/a | } |
|---|
| 6154 | n/a | p = pool->freeBlocks; |
|---|
| 6155 | n/a | while (p) { |
|---|
| 6156 | n/a | BLOCK *tem = p->next; |
|---|
| 6157 | n/a | pool->mem->free_fcn(p); |
|---|
| 6158 | n/a | p = tem; |
|---|
| 6159 | n/a | } |
|---|
| 6160 | n/a | } |
|---|
| 6161 | n/a | |
|---|
| 6162 | n/a | static XML_Char * |
|---|
| 6163 | n/a | poolAppend(STRING_POOL *pool, const ENCODING *enc, |
|---|
| 6164 | n/a | const char *ptr, const char *end) |
|---|
| 6165 | n/a | { |
|---|
| 6166 | n/a | if (!pool->ptr && !poolGrow(pool)) |
|---|
| 6167 | n/a | return NULL; |
|---|
| 6168 | n/a | for (;;) { |
|---|
| 6169 | n/a | XmlConvert(enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end); |
|---|
| 6170 | n/a | if (ptr == end) |
|---|
| 6171 | n/a | break; |
|---|
| 6172 | n/a | if (!poolGrow(pool)) |
|---|
| 6173 | n/a | return NULL; |
|---|
| 6174 | n/a | } |
|---|
| 6175 | n/a | return pool->start; |
|---|
| 6176 | n/a | } |
|---|
| 6177 | n/a | |
|---|
| 6178 | n/a | static const XML_Char * FASTCALL |
|---|
| 6179 | n/a | poolCopyString(STRING_POOL *pool, const XML_Char *s) |
|---|
| 6180 | n/a | { |
|---|
| 6181 | n/a | do { |
|---|
| 6182 | n/a | if (!poolAppendChar(pool, *s)) |
|---|
| 6183 | n/a | return NULL; |
|---|
| 6184 | n/a | } while (*s++); |
|---|
| 6185 | n/a | s = pool->start; |
|---|
| 6186 | n/a | poolFinish(pool); |
|---|
| 6187 | n/a | return s; |
|---|
| 6188 | n/a | } |
|---|
| 6189 | n/a | |
|---|
| 6190 | n/a | static const XML_Char * |
|---|
| 6191 | n/a | poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n) |
|---|
| 6192 | n/a | { |
|---|
| 6193 | n/a | if (!pool->ptr && !poolGrow(pool)) |
|---|
| 6194 | n/a | return NULL; |
|---|
| 6195 | n/a | for (; n > 0; --n, s++) { |
|---|
| 6196 | n/a | if (!poolAppendChar(pool, *s)) |
|---|
| 6197 | n/a | return NULL; |
|---|
| 6198 | n/a | } |
|---|
| 6199 | n/a | s = pool->start; |
|---|
| 6200 | n/a | poolFinish(pool); |
|---|
| 6201 | n/a | return s; |
|---|
| 6202 | n/a | } |
|---|
| 6203 | n/a | |
|---|
| 6204 | n/a | static const XML_Char * FASTCALL |
|---|
| 6205 | n/a | poolAppendString(STRING_POOL *pool, const XML_Char *s) |
|---|
| 6206 | n/a | { |
|---|
| 6207 | n/a | while (*s) { |
|---|
| 6208 | n/a | if (!poolAppendChar(pool, *s)) |
|---|
| 6209 | n/a | return NULL; |
|---|
| 6210 | n/a | s++; |
|---|
| 6211 | n/a | } |
|---|
| 6212 | n/a | return pool->start; |
|---|
| 6213 | n/a | } |
|---|
| 6214 | n/a | |
|---|
| 6215 | n/a | static XML_Char * |
|---|
| 6216 | n/a | poolStoreString(STRING_POOL *pool, const ENCODING *enc, |
|---|
| 6217 | n/a | const char *ptr, const char *end) |
|---|
| 6218 | n/a | { |
|---|
| 6219 | n/a | if (!poolAppend(pool, enc, ptr, end)) |
|---|
| 6220 | n/a | return NULL; |
|---|
| 6221 | n/a | if (pool->ptr == pool->end && !poolGrow(pool)) |
|---|
| 6222 | n/a | return NULL; |
|---|
| 6223 | n/a | *(pool->ptr)++ = 0; |
|---|
| 6224 | n/a | return pool->start; |
|---|
| 6225 | n/a | } |
|---|
| 6226 | n/a | |
|---|
| 6227 | n/a | static XML_Bool FASTCALL |
|---|
| 6228 | n/a | poolGrow(STRING_POOL *pool) |
|---|
| 6229 | n/a | { |
|---|
| 6230 | n/a | if (pool->freeBlocks) { |
|---|
| 6231 | n/a | if (pool->start == 0) { |
|---|
| 6232 | n/a | pool->blocks = pool->freeBlocks; |
|---|
| 6233 | n/a | pool->freeBlocks = pool->freeBlocks->next; |
|---|
| 6234 | n/a | pool->blocks->next = NULL; |
|---|
| 6235 | n/a | pool->start = pool->blocks->s; |
|---|
| 6236 | n/a | pool->end = pool->start + pool->blocks->size; |
|---|
| 6237 | n/a | pool->ptr = pool->start; |
|---|
| 6238 | n/a | return XML_TRUE; |
|---|
| 6239 | n/a | } |
|---|
| 6240 | n/a | if (pool->end - pool->start < pool->freeBlocks->size) { |
|---|
| 6241 | n/a | BLOCK *tem = pool->freeBlocks->next; |
|---|
| 6242 | n/a | pool->freeBlocks->next = pool->blocks; |
|---|
| 6243 | n/a | pool->blocks = pool->freeBlocks; |
|---|
| 6244 | n/a | pool->freeBlocks = tem; |
|---|
| 6245 | n/a | memcpy(pool->blocks->s, pool->start, |
|---|
| 6246 | n/a | (pool->end - pool->start) * sizeof(XML_Char)); |
|---|
| 6247 | n/a | pool->ptr = pool->blocks->s + (pool->ptr - pool->start); |
|---|
| 6248 | n/a | pool->start = pool->blocks->s; |
|---|
| 6249 | n/a | pool->end = pool->start + pool->blocks->size; |
|---|
| 6250 | n/a | return XML_TRUE; |
|---|
| 6251 | n/a | } |
|---|
| 6252 | n/a | } |
|---|
| 6253 | n/a | if (pool->blocks && pool->start == pool->blocks->s) { |
|---|
| 6254 | n/a | int blockSize = (int)(pool->end - pool->start)*2; |
|---|
| 6255 | n/a | BLOCK *temp = (BLOCK *) |
|---|
| 6256 | n/a | pool->mem->realloc_fcn(pool->blocks, |
|---|
| 6257 | n/a | (offsetof(BLOCK, s) |
|---|
| 6258 | n/a | + blockSize * sizeof(XML_Char))); |
|---|
| 6259 | n/a | if (temp == NULL) |
|---|
| 6260 | n/a | return XML_FALSE; |
|---|
| 6261 | n/a | pool->blocks = temp; |
|---|
| 6262 | n/a | pool->blocks->size = blockSize; |
|---|
| 6263 | n/a | pool->ptr = pool->blocks->s + (pool->ptr - pool->start); |
|---|
| 6264 | n/a | pool->start = pool->blocks->s; |
|---|
| 6265 | n/a | pool->end = pool->start + blockSize; |
|---|
| 6266 | n/a | } |
|---|
| 6267 | n/a | else { |
|---|
| 6268 | n/a | BLOCK *tem; |
|---|
| 6269 | n/a | int blockSize = (int)(pool->end - pool->start); |
|---|
| 6270 | n/a | if (blockSize < INIT_BLOCK_SIZE) |
|---|
| 6271 | n/a | blockSize = INIT_BLOCK_SIZE; |
|---|
| 6272 | n/a | else |
|---|
| 6273 | n/a | blockSize *= 2; |
|---|
| 6274 | n/a | tem = (BLOCK *)pool->mem->malloc_fcn(offsetof(BLOCK, s) |
|---|
| 6275 | n/a | + blockSize * sizeof(XML_Char)); |
|---|
| 6276 | n/a | if (!tem) |
|---|
| 6277 | n/a | return XML_FALSE; |
|---|
| 6278 | n/a | tem->size = blockSize; |
|---|
| 6279 | n/a | tem->next = pool->blocks; |
|---|
| 6280 | n/a | pool->blocks = tem; |
|---|
| 6281 | n/a | if (pool->ptr != pool->start) |
|---|
| 6282 | n/a | memcpy(tem->s, pool->start, |
|---|
| 6283 | n/a | (pool->ptr - pool->start) * sizeof(XML_Char)); |
|---|
| 6284 | n/a | pool->ptr = tem->s + (pool->ptr - pool->start); |
|---|
| 6285 | n/a | pool->start = tem->s; |
|---|
| 6286 | n/a | pool->end = tem->s + blockSize; |
|---|
| 6287 | n/a | } |
|---|
| 6288 | n/a | return XML_TRUE; |
|---|
| 6289 | n/a | } |
|---|
| 6290 | n/a | |
|---|
| 6291 | n/a | static int FASTCALL |
|---|
| 6292 | n/a | nextScaffoldPart(XML_Parser parser) |
|---|
| 6293 | n/a | { |
|---|
| 6294 | n/a | DTD * const dtd = _dtd; /* save one level of indirection */ |
|---|
| 6295 | n/a | CONTENT_SCAFFOLD * me; |
|---|
| 6296 | n/a | int next; |
|---|
| 6297 | n/a | |
|---|
| 6298 | n/a | if (!dtd->scaffIndex) { |
|---|
| 6299 | n/a | dtd->scaffIndex = (int *)MALLOC(groupSize * sizeof(int)); |
|---|
| 6300 | n/a | if (!dtd->scaffIndex) |
|---|
| 6301 | n/a | return -1; |
|---|
| 6302 | n/a | dtd->scaffIndex[0] = 0; |
|---|
| 6303 | n/a | } |
|---|
| 6304 | n/a | |
|---|
| 6305 | n/a | if (dtd->scaffCount >= dtd->scaffSize) { |
|---|
| 6306 | n/a | CONTENT_SCAFFOLD *temp; |
|---|
| 6307 | n/a | if (dtd->scaffold) { |
|---|
| 6308 | n/a | temp = (CONTENT_SCAFFOLD *) |
|---|
| 6309 | n/a | REALLOC(dtd->scaffold, dtd->scaffSize * 2 * sizeof(CONTENT_SCAFFOLD)); |
|---|
| 6310 | n/a | if (temp == NULL) |
|---|
| 6311 | n/a | return -1; |
|---|
| 6312 | n/a | dtd->scaffSize *= 2; |
|---|
| 6313 | n/a | } |
|---|
| 6314 | n/a | else { |
|---|
| 6315 | n/a | temp = (CONTENT_SCAFFOLD *)MALLOC(INIT_SCAFFOLD_ELEMENTS |
|---|
| 6316 | n/a | * sizeof(CONTENT_SCAFFOLD)); |
|---|
| 6317 | n/a | if (temp == NULL) |
|---|
| 6318 | n/a | return -1; |
|---|
| 6319 | n/a | dtd->scaffSize = INIT_SCAFFOLD_ELEMENTS; |
|---|
| 6320 | n/a | } |
|---|
| 6321 | n/a | dtd->scaffold = temp; |
|---|
| 6322 | n/a | } |
|---|
| 6323 | n/a | next = dtd->scaffCount++; |
|---|
| 6324 | n/a | me = &dtd->scaffold[next]; |
|---|
| 6325 | n/a | if (dtd->scaffLevel) { |
|---|
| 6326 | n/a | CONTENT_SCAFFOLD *parent = &dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel-1]]; |
|---|
| 6327 | n/a | if (parent->lastchild) { |
|---|
| 6328 | n/a | dtd->scaffold[parent->lastchild].nextsib = next; |
|---|
| 6329 | n/a | } |
|---|
| 6330 | n/a | if (!parent->childcnt) |
|---|
| 6331 | n/a | parent->firstchild = next; |
|---|
| 6332 | n/a | parent->lastchild = next; |
|---|
| 6333 | n/a | parent->childcnt++; |
|---|
| 6334 | n/a | } |
|---|
| 6335 | n/a | me->firstchild = me->lastchild = me->childcnt = me->nextsib = 0; |
|---|
| 6336 | n/a | return next; |
|---|
| 6337 | n/a | } |
|---|
| 6338 | n/a | |
|---|
| 6339 | n/a | static void |
|---|
| 6340 | n/a | build_node(XML_Parser parser, |
|---|
| 6341 | n/a | int src_node, |
|---|
| 6342 | n/a | XML_Content *dest, |
|---|
| 6343 | n/a | XML_Content **contpos, |
|---|
| 6344 | n/a | XML_Char **strpos) |
|---|
| 6345 | n/a | { |
|---|
| 6346 | n/a | DTD * const dtd = _dtd; /* save one level of indirection */ |
|---|
| 6347 | n/a | dest->type = dtd->scaffold[src_node].type; |
|---|
| 6348 | n/a | dest->quant = dtd->scaffold[src_node].quant; |
|---|
| 6349 | n/a | if (dest->type == XML_CTYPE_NAME) { |
|---|
| 6350 | n/a | const XML_Char *src; |
|---|
| 6351 | n/a | dest->name = *strpos; |
|---|
| 6352 | n/a | src = dtd->scaffold[src_node].name; |
|---|
| 6353 | n/a | for (;;) { |
|---|
| 6354 | n/a | *(*strpos)++ = *src; |
|---|
| 6355 | n/a | if (!*src) |
|---|
| 6356 | n/a | break; |
|---|
| 6357 | n/a | src++; |
|---|
| 6358 | n/a | } |
|---|
| 6359 | n/a | dest->numchildren = 0; |
|---|
| 6360 | n/a | dest->children = NULL; |
|---|
| 6361 | n/a | } |
|---|
| 6362 | n/a | else { |
|---|
| 6363 | n/a | unsigned int i; |
|---|
| 6364 | n/a | int cn; |
|---|
| 6365 | n/a | dest->numchildren = dtd->scaffold[src_node].childcnt; |
|---|
| 6366 | n/a | dest->children = *contpos; |
|---|
| 6367 | n/a | *contpos += dest->numchildren; |
|---|
| 6368 | n/a | for (i = 0, cn = dtd->scaffold[src_node].firstchild; |
|---|
| 6369 | n/a | i < dest->numchildren; |
|---|
| 6370 | n/a | i++, cn = dtd->scaffold[cn].nextsib) { |
|---|
| 6371 | n/a | build_node(parser, cn, &(dest->children[i]), contpos, strpos); |
|---|
| 6372 | n/a | } |
|---|
| 6373 | n/a | dest->name = NULL; |
|---|
| 6374 | n/a | } |
|---|
| 6375 | n/a | } |
|---|
| 6376 | n/a | |
|---|
| 6377 | n/a | static XML_Content * |
|---|
| 6378 | n/a | build_model (XML_Parser parser) |
|---|
| 6379 | n/a | { |
|---|
| 6380 | n/a | DTD * const dtd = _dtd; /* save one level of indirection */ |
|---|
| 6381 | n/a | XML_Content *ret; |
|---|
| 6382 | n/a | XML_Content *cpos; |
|---|
| 6383 | n/a | XML_Char * str; |
|---|
| 6384 | n/a | int allocsize = (dtd->scaffCount * sizeof(XML_Content) |
|---|
| 6385 | n/a | + (dtd->contentStringLen * sizeof(XML_Char))); |
|---|
| 6386 | n/a | |
|---|
| 6387 | n/a | ret = (XML_Content *)MALLOC(allocsize); |
|---|
| 6388 | n/a | if (!ret) |
|---|
| 6389 | n/a | return NULL; |
|---|
| 6390 | n/a | |
|---|
| 6391 | n/a | str = (XML_Char *) (&ret[dtd->scaffCount]); |
|---|
| 6392 | n/a | cpos = &ret[1]; |
|---|
| 6393 | n/a | |
|---|
| 6394 | n/a | build_node(parser, 0, ret, &cpos, &str); |
|---|
| 6395 | n/a | return ret; |
|---|
| 6396 | n/a | } |
|---|
| 6397 | n/a | |
|---|
| 6398 | n/a | static ELEMENT_TYPE * |
|---|
| 6399 | n/a | getElementType(XML_Parser parser, |
|---|
| 6400 | n/a | const ENCODING *enc, |
|---|
| 6401 | n/a | const char *ptr, |
|---|
| 6402 | n/a | const char *end) |
|---|
| 6403 | n/a | { |
|---|
| 6404 | n/a | DTD * const dtd = _dtd; /* save one level of indirection */ |
|---|
| 6405 | n/a | const XML_Char *name = poolStoreString(&dtd->pool, enc, ptr, end); |
|---|
| 6406 | n/a | ELEMENT_TYPE *ret; |
|---|
| 6407 | n/a | |
|---|
| 6408 | n/a | if (!name) |
|---|
| 6409 | n/a | return NULL; |
|---|
| 6410 | n/a | ret = (ELEMENT_TYPE *) lookup(parser, &dtd->elementTypes, name, sizeof(ELEMENT_TYPE)); |
|---|
| 6411 | n/a | if (!ret) |
|---|
| 6412 | n/a | return NULL; |
|---|
| 6413 | n/a | if (ret->name != name) |
|---|
| 6414 | n/a | poolDiscard(&dtd->pool); |
|---|
| 6415 | n/a | else { |
|---|
| 6416 | n/a | poolFinish(&dtd->pool); |
|---|
| 6417 | n/a | if (!setElementTypePrefix(parser, ret)) |
|---|
| 6418 | n/a | return NULL; |
|---|
| 6419 | n/a | } |
|---|
| 6420 | n/a | return ret; |
|---|
| 6421 | n/a | } |
|---|