xmlparse.c (104349) | xmlparse.c (178848) |
---|---|
1/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd 2 See the file COPYING for copying permission. 3*/ 4 5#include <stddef.h> 6#include <string.h> /* memset(), memcpy() */ | 1/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd 2 See the file COPYING for copying permission. 3*/ 4 5#include <stddef.h> 6#include <string.h> /* memset(), memcpy() */ |
7#include <assert.h> |
|
7 | 8 |
8#ifdef COMPILED_FROM_DSP | 9#define XML_BUILDING_EXPAT 1 |
9 | 10 |
11#ifdef COMPILED_FROM_DSP |
|
10#include "winconfig.h" | 12#include "winconfig.h" |
11#ifdef _LIB 12#define XMLPARSEAPI(type) type __cdecl 13#else 14#define XMLPARSEAPI(type) __declspec(dllexport) type __cdecl 15#endif 16#include "expat.h" 17#undef XMLPARSEAPI 18 | |
19#elif defined(MACOS_CLASSIC) | 13#elif defined(MACOS_CLASSIC) |
20 | |
21#include "macconfig.h" | 14#include "macconfig.h" |
22#include "expat.h" 23 24#else 25 | 15#elif defined(__amigaos4__) 16#include "amigaconfig.h" 17#elif defined(__WATCOMC__) 18#include "watcomconfig.h" 19#elif defined(HAVE_EXPAT_CONFIG_H) |
26#include <expat_config.h> | 20#include <expat_config.h> |
21#endif /* ndef COMPILED_FROM_DSP */ |
|
27 | 22 |
28#ifdef __declspec 29#define XMLPARSEAPI(type) __declspec(dllexport) type __cdecl 30#endif 31 | 23#include "ascii.h" |
32#include "expat.h" 33 | 24#include "expat.h" 25 |
34#ifdef __declspec 35#undef XMLPARSEAPI 36#endif 37#endif /* ndef COMPILED_FROM_DSP */ 38 | |
39#ifdef XML_UNICODE 40#define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX 41#define XmlConvert XmlUtf16Convert 42#define XmlGetInternalEncoding XmlGetUtf16InternalEncoding 43#define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS 44#define XmlEncode XmlUtf16Encode | 26#ifdef XML_UNICODE 27#define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX 28#define XmlConvert XmlUtf16Convert 29#define XmlGetInternalEncoding XmlGetUtf16InternalEncoding 30#define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS 31#define XmlEncode XmlUtf16Encode |
45#define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((unsigned long)s) & 1)) | 32/* Using pointer subtraction to convert to integer type. */ 33#define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((char *)(s) - (char *)NULL) & 1)) |
46typedef unsigned short ICHAR; 47#else 48#define XML_ENCODE_MAX XML_UTF8_ENCODE_MAX 49#define XmlConvert XmlUtf8Convert 50#define XmlGetInternalEncoding XmlGetUtf8InternalEncoding 51#define XmlGetInternalEncodingNS XmlGetUtf8InternalEncodingNS 52#define XmlEncode XmlUtf8Encode 53#define MUST_CONVERT(enc, s) (!(enc)->isUtf8) --- 47 unchanged lines hidden (view full) --- 101typedef const XML_Char *KEY; 102 103typedef struct { 104 KEY name; 105} NAMED; 106 107typedef struct { 108 NAMED **v; | 34typedef unsigned short ICHAR; 35#else 36#define XML_ENCODE_MAX XML_UTF8_ENCODE_MAX 37#define XmlConvert XmlUtf8Convert 38#define XmlGetInternalEncoding XmlGetUtf8InternalEncoding 39#define XmlGetInternalEncodingNS XmlGetUtf8InternalEncodingNS 40#define XmlEncode XmlUtf8Encode 41#define MUST_CONVERT(enc, s) (!(enc)->isUtf8) --- 47 unchanged lines hidden (view full) --- 89typedef const XML_Char *KEY; 90 91typedef struct { 92 KEY name; 93} NAMED; 94 95typedef struct { 96 NAMED **v; |
97 unsigned char power; |
|
109 size_t size; 110 size_t used; | 98 size_t size; 99 size_t used; |
111 size_t usedLim; 112 XML_Memory_Handling_Suite *mem; | 100 const XML_Memory_Handling_Suite *mem; |
113} HASH_TABLE; 114 | 101} HASH_TABLE; 102 |
103/* Basic character hash algorithm, taken from Python's string hash: 104 h = h * 1000003 ^ character, the constant being a prime number. 105 106*/ 107#ifdef XML_UNICODE 108#define CHAR_HASH(h, c) \ 109 (((h) * 0xF4243) ^ (unsigned short)(c)) 110#else 111#define CHAR_HASH(h, c) \ 112 (((h) * 0xF4243) ^ (unsigned char)(c)) 113#endif 114 115/* For probing (after a collision) we need a step size relative prime 116 to the hash table size, which is a power of 2. We use double-hashing, 117 since we can calculate a second hash value cheaply by taking those bits 118 of the first hash value that were discarded (masked out) when the table 119 index was calculated: index = hash & mask, where mask = table->size - 1. 120 We limit the maximum step size to table->size / 4 (mask >> 2) and make 121 it odd, since odd numbers are always relative prime to a power of 2. 122*/ 123#define SECOND_HASH(hash, mask, power) \ 124 ((((hash) & ~(mask)) >> ((power) - 1)) & ((mask) >> 2)) 125#define PROBE_STEP(hash, mask, power) \ 126 ((unsigned char)((SECOND_HASH(hash, mask, power)) | 1)) 127 |
|
115typedef struct { 116 NAMED **p; 117 NAMED **end; 118} HASH_TABLE_ITER; 119 120#define INIT_TAG_BUF_SIZE 32 /* must be a multiple of sizeof(XML_Char) */ 121#define INIT_DATA_BUF_SIZE 1024 122#define INIT_ATTS_SIZE 16 | 128typedef struct { 129 NAMED **p; 130 NAMED **end; 131} HASH_TABLE_ITER; 132 133#define INIT_TAG_BUF_SIZE 32 /* must be a multiple of sizeof(XML_Char) */ 134#define INIT_DATA_BUF_SIZE 1024 135#define INIT_ATTS_SIZE 16 |
136#define INIT_ATTS_VERSION 0xFFFFFFFF |
|
123#define INIT_BLOCK_SIZE 1024 124#define INIT_BUFFER_SIZE 1024 125 126#define EXPAND_SPARE 24 127 128typedef struct binding { 129 struct prefix *prefix; 130 struct binding *nextTagBinding; --- 39 unchanged lines hidden (view full) --- 170 char *buf; /* buffer for name components */ 171 char *bufEnd; /* end of the buffer */ 172 BINDING *bindings; 173} TAG; 174 175typedef struct { 176 const XML_Char *name; 177 const XML_Char *textPtr; | 137#define INIT_BLOCK_SIZE 1024 138#define INIT_BUFFER_SIZE 1024 139 140#define EXPAND_SPARE 24 141 142typedef struct binding { 143 struct prefix *prefix; 144 struct binding *nextTagBinding; --- 39 unchanged lines hidden (view full) --- 184 char *buf; /* buffer for name components */ 185 char *bufEnd; /* end of the buffer */ 186 BINDING *bindings; 187} TAG; 188 189typedef struct { 190 const XML_Char *name; 191 const XML_Char *textPtr; |
178 int textLen; | 192 int textLen; /* length in XML_Chars */ 193 int processed; /* # of processed bytes - when suspended */ |
179 const XML_Char *systemId; 180 const XML_Char *base; 181 const XML_Char *publicId; 182 const XML_Char *notation; 183 XML_Bool open; 184 XML_Bool is_param; 185 XML_Bool is_internal; /* true if declared in internal subset outside PE */ 186} ENTITY; --- 17 unchanged lines hidden (view full) --- 204} BLOCK; 205 206typedef struct { 207 BLOCK *blocks; 208 BLOCK *freeBlocks; 209 const XML_Char *end; 210 XML_Char *ptr; 211 XML_Char *start; | 194 const XML_Char *systemId; 195 const XML_Char *base; 196 const XML_Char *publicId; 197 const XML_Char *notation; 198 XML_Bool open; 199 XML_Bool is_param; 200 XML_Bool is_internal; /* true if declared in internal subset outside PE */ 201} ENTITY; --- 17 unchanged lines hidden (view full) --- 219} BLOCK; 220 221typedef struct { 222 BLOCK *blocks; 223 BLOCK *freeBlocks; 224 const XML_Char *end; 225 XML_Char *ptr; 226 XML_Char *start; |
212 XML_Memory_Handling_Suite *mem; | 227 const XML_Memory_Handling_Suite *mem; |
213} STRING_POOL; 214 215/* The XML_Char before the name is used to determine whether 216 an attribute has been specified. */ 217typedef struct attribute_id { 218 XML_Char *name; 219 PREFIX *prefix; 220 XML_Bool maybeTokenized; 221 XML_Bool xmlns; 222} ATTRIBUTE_ID; 223 224typedef struct { 225 const ATTRIBUTE_ID *id; 226 XML_Bool isCdata; 227 const XML_Char *value; 228} DEFAULT_ATTRIBUTE; 229 230typedef struct { | 228} STRING_POOL; 229 230/* The XML_Char before the name is used to determine whether 231 an attribute has been specified. */ 232typedef struct attribute_id { 233 XML_Char *name; 234 PREFIX *prefix; 235 XML_Bool maybeTokenized; 236 XML_Bool xmlns; 237} ATTRIBUTE_ID; 238 239typedef struct { 240 const ATTRIBUTE_ID *id; 241 XML_Bool isCdata; 242 const XML_Char *value; 243} DEFAULT_ATTRIBUTE; 244 245typedef struct { |
246 unsigned long version; 247 unsigned long hash; 248 const XML_Char *uriName; 249} NS_ATT; 250 251typedef struct { |
|
231 const XML_Char *name; 232 PREFIX *prefix; 233 const ATTRIBUTE_ID *idAtt; 234 int nDefaultAtts; 235 int allocDefaultAtts; 236 DEFAULT_ATTRIBUTE *defaultAtts; 237} ELEMENT_TYPE; 238 239typedef struct { 240 HASH_TABLE generalEntities; 241 HASH_TABLE elementTypes; 242 HASH_TABLE attributeIds; 243 HASH_TABLE prefixes; 244 STRING_POOL pool; 245 STRING_POOL entityValuePool; 246 /* false once a parameter entity reference has been skipped */ 247 XML_Bool keepProcessing; 248 /* true once an internal or external PE reference has been encountered; | 252 const XML_Char *name; 253 PREFIX *prefix; 254 const ATTRIBUTE_ID *idAtt; 255 int nDefaultAtts; 256 int allocDefaultAtts; 257 DEFAULT_ATTRIBUTE *defaultAtts; 258} ELEMENT_TYPE; 259 260typedef struct { 261 HASH_TABLE generalEntities; 262 HASH_TABLE elementTypes; 263 HASH_TABLE attributeIds; 264 HASH_TABLE prefixes; 265 STRING_POOL pool; 266 STRING_POOL entityValuePool; 267 /* false once a parameter entity reference has been skipped */ 268 XML_Bool keepProcessing; 269 /* true once an internal or external PE reference has been encountered; |
249 any external subset is considered an external PE reference */ | 270 this includes the reference to an external subset */ |
250 XML_Bool hasParamEntityRefs; 251 XML_Bool standalone; 252#ifdef XML_DTD 253 /* indicates if external PE has been read */ 254 XML_Bool paramEntityRead; 255 HASH_TABLE paramEntities; 256#endif /* XML_DTD */ 257 PREFIX defaultPrefix; --- 7 unchanged lines hidden (view full) --- 265 int *scaffIndex; 266} DTD; 267 268typedef struct open_internal_entity { 269 const char *internalEventPtr; 270 const char *internalEventEndPtr; 271 struct open_internal_entity *next; 272 ENTITY *entity; | 271 XML_Bool hasParamEntityRefs; 272 XML_Bool standalone; 273#ifdef XML_DTD 274 /* indicates if external PE has been read */ 275 XML_Bool paramEntityRead; 276 HASH_TABLE paramEntities; 277#endif /* XML_DTD */ 278 PREFIX defaultPrefix; --- 7 unchanged lines hidden (view full) --- 286 int *scaffIndex; 287} DTD; 288 289typedef struct open_internal_entity { 290 const char *internalEventPtr; 291 const char *internalEventEndPtr; 292 struct open_internal_entity *next; 293 ENTITY *entity; |
294 int startTagLevel; 295 XML_Bool betweenDecl; /* WFC: PE Between Declarations */ |
|
273} OPEN_INTERNAL_ENTITY; 274 | 296} OPEN_INTERNAL_ENTITY; 297 |
275typedef enum XML_Error FASTCALL Processor(XML_Parser parser, 276 const char *start, 277 const char *end, 278 const char **endPtr); | 298typedef enum XML_Error PTRCALL Processor(XML_Parser parser, 299 const char *start, 300 const char *end, 301 const char **endPtr); |
279 280static Processor prologProcessor; 281static Processor prologInitProcessor; 282static Processor contentProcessor; 283static Processor cdataSectionProcessor; 284#ifdef XML_DTD 285static Processor ignoreSectionProcessor; 286static Processor externalParEntProcessor; 287static Processor externalParEntInitProcessor; 288static Processor entityValueProcessor; 289static Processor entityValueInitProcessor; 290#endif /* XML_DTD */ 291static Processor epilogProcessor; 292static Processor errorProcessor; 293static Processor externalEntityInitProcessor; 294static Processor externalEntityInitProcessor2; 295static Processor externalEntityInitProcessor3; 296static Processor externalEntityContentProcessor; | 302 303static Processor prologProcessor; 304static Processor prologInitProcessor; 305static Processor contentProcessor; 306static Processor cdataSectionProcessor; 307#ifdef XML_DTD 308static Processor ignoreSectionProcessor; 309static Processor externalParEntProcessor; 310static Processor externalParEntInitProcessor; 311static Processor entityValueProcessor; 312static Processor entityValueInitProcessor; 313#endif /* XML_DTD */ 314static Processor epilogProcessor; 315static Processor errorProcessor; 316static Processor externalEntityInitProcessor; 317static Processor externalEntityInitProcessor2; 318static Processor externalEntityInitProcessor3; 319static Processor externalEntityContentProcessor; |
320static Processor internalEntityProcessor; |
|
297 | 321 |
298static enum XML_Error FASTCALL | 322static enum XML_Error |
299handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName); | 323handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName); |
300static enum XML_Error FASTCALL | 324static enum XML_Error |
301processXmlDecl(XML_Parser parser, int isGeneralTextEntity, | 325processXmlDecl(XML_Parser parser, int isGeneralTextEntity, |
302 const char *, const char *); 303static enum XML_Error FASTCALL | 326 const char *s, const char *next); 327static enum XML_Error |
304initializeEncoding(XML_Parser parser); | 328initializeEncoding(XML_Parser parser); |
305static enum XML_Error FASTCALL 306doProlog(XML_Parser parser, const ENCODING *enc, const char *s, 307 const char *end, int tok, const char *next, const char **nextPtr); 308static enum XML_Error FASTCALL 309processInternalParamEntity(XML_Parser parser, ENTITY *entity); 310static enum XML_Error FASTCALL | 329static enum XML_Error 330doProlog(XML_Parser parser, const ENCODING *enc, const char *s, 331 const char *end, int tok, const char *next, const char **nextPtr, 332 XML_Bool haveMore); 333static enum XML_Error 334processInternalEntity(XML_Parser parser, ENTITY *entity, 335 XML_Bool betweenDecl); 336static enum XML_Error |
311doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, | 337doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, |
312 const char *start, const char *end, const char **endPtr); 313static enum XML_Error FASTCALL | 338 const char *start, const char *end, const char **endPtr, 339 XML_Bool haveMore); 340static enum XML_Error |
314doCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr, | 341doCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr, |
315 const char *end, const char **nextPtr); | 342 const char *end, const char **nextPtr, XML_Bool haveMore); |
316#ifdef XML_DTD | 343#ifdef XML_DTD |
317static enum XML_Error FASTCALL | 344static enum XML_Error |
318doIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr, | 345doIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr, |
319 const char *end, const char **nextPtr); | 346 const char *end, const char **nextPtr, XML_Bool haveMore); |
320#endif /* XML_DTD */ | 347#endif /* XML_DTD */ |
321static enum XML_Error FASTCALL 322storeAtts(XML_Parser parser, const ENCODING *, 323 const char *s, TAG_NAME *tagNamePtr, BINDING **bindingsPtr); 324static int FASTCALL | 348 349static enum XML_Error 350storeAtts(XML_Parser parser, const ENCODING *, const char *s, 351 TAG_NAME *tagNamePtr, BINDING **bindingsPtr); 352static enum XML_Error |
325addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, 326 const XML_Char *uri, BINDING **bindingsPtr); | 353addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, 354 const XML_Char *uri, BINDING **bindingsPtr); |
327 328static int FASTCALL 329defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *, 330 XML_Bool isCdata, XML_Bool isId, const XML_Char *dfltValue, 331 XML_Parser parser); 332 333static enum XML_Error FASTCALL | 355static int 356defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *, XML_Bool isCdata, 357 XML_Bool isId, const XML_Char *dfltValue, XML_Parser parser); 358static enum XML_Error |
334storeAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, 335 const char *, const char *, STRING_POOL *); | 359storeAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, 360 const char *, const char *, STRING_POOL *); |
336static enum XML_Error FASTCALL | 361static enum XML_Error |
337appendAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, 338 const char *, const char *, STRING_POOL *); | 362appendAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, 363 const char *, const char *, STRING_POOL *); |
339static ATTRIBUTE_ID * FASTCALL | 364static ATTRIBUTE_ID * |
340getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start, 341 const char *end); | 365getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start, 366 const char *end); |
342static int FASTCALL | 367static int |
343setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *); | 368setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *); |
344static enum XML_Error FASTCALL | 369static enum XML_Error |
345storeEntityValue(XML_Parser parser, const ENCODING *enc, const char *start, 346 const char *end); | 370storeEntityValue(XML_Parser parser, const ENCODING *enc, const char *start, 371 const char *end); |
347static int FASTCALL | 372static int |
348reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, 349 const char *start, const char *end); | 373reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, 374 const char *start, const char *end); |
350static int FASTCALL | 375static int |
351reportComment(XML_Parser parser, const ENCODING *enc, const char *start, 352 const char *end); | 376reportComment(XML_Parser parser, const ENCODING *enc, const char *start, 377 const char *end); |
353static void FASTCALL | 378static void |
354reportDefault(XML_Parser parser, const ENCODING *enc, const char *start, 355 const char *end); 356 | 379reportDefault(XML_Parser parser, const ENCODING *enc, const char *start, 380 const char *end); 381 |
357static const XML_Char * FASTCALL getContext(XML_Parser parser); 358static XML_Bool FASTCALL | 382static const XML_Char * getContext(XML_Parser parser); 383static XML_Bool |
359setContext(XML_Parser parser, const XML_Char *context); | 384setContext(XML_Parser parser, const XML_Char *context); |
385 |
|
360static void FASTCALL normalizePublicId(XML_Char *s); | 386static void FASTCALL normalizePublicId(XML_Char *s); |
361static void FASTCALL dtdInit(DTD *, XML_Parser parser); | |
362 | 387 |
388static DTD * dtdCreate(const XML_Memory_Handling_Suite *ms); |
|
363/* do not call if parentParser != NULL */ | 389/* do not call if parentParser != NULL */ |
364static void FASTCALL dtdReset(DTD *, XML_Parser parser); 365static void FASTCALL dtdDestroy(DTD *, XML_Parser parser); | 390static void dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms); 391static void 392dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms); 393static int 394dtdCopy(DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms); 395static int 396copyEntityTable(HASH_TABLE *, STRING_POOL *, const HASH_TABLE *); |
366 | 397 |
367static int FASTCALL dtdCopy(DTD *newDtd, const DTD *oldDtd, XML_Parser parser); 368 369static int FASTCALL copyEntityTable(HASH_TABLE *, STRING_POOL *, 370 const HASH_TABLE *, XML_Parser parser); 371 372#ifdef XML_DTD 373static void FASTCALL dtdSwap(DTD *, DTD *); 374#endif /* XML_DTD */ 375 376static NAMED * FASTCALL | 398static NAMED * |
377lookup(HASH_TABLE *table, KEY name, size_t createSize); | 399lookup(HASH_TABLE *table, KEY name, size_t createSize); |
378 | |
379static void FASTCALL | 400static void FASTCALL |
380hashTableInit(HASH_TABLE *, XML_Memory_Handling_Suite *ms); 381 | 401hashTableInit(HASH_TABLE *, const XML_Memory_Handling_Suite *ms); |
382static void FASTCALL hashTableClear(HASH_TABLE *); 383static void FASTCALL hashTableDestroy(HASH_TABLE *); | 402static void FASTCALL hashTableClear(HASH_TABLE *); 403static void FASTCALL hashTableDestroy(HASH_TABLE *); |
384static void FASTCALL hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *); | 404static void FASTCALL 405hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *); |
385static NAMED * FASTCALL hashTableIterNext(HASH_TABLE_ITER *); | 406static NAMED * FASTCALL hashTableIterNext(HASH_TABLE_ITER *); |
386static void FASTCALL poolInit(STRING_POOL *, XML_Memory_Handling_Suite *ms); | 407 408static void FASTCALL 409poolInit(STRING_POOL *, const XML_Memory_Handling_Suite *ms); |
387static void FASTCALL poolClear(STRING_POOL *); 388static void FASTCALL poolDestroy(STRING_POOL *); | 410static void FASTCALL poolClear(STRING_POOL *); 411static void FASTCALL poolDestroy(STRING_POOL *); |
389static XML_Char * FASTCALL | 412static XML_Char * |
390poolAppend(STRING_POOL *pool, const ENCODING *enc, 391 const char *ptr, const char *end); | 413poolAppend(STRING_POOL *pool, const ENCODING *enc, 414 const char *ptr, const char *end); |
392static XML_Char * FASTCALL | 415static XML_Char * |
393poolStoreString(STRING_POOL *pool, const ENCODING *enc, 394 const char *ptr, const char *end); | 416poolStoreString(STRING_POOL *pool, const ENCODING *enc, 417 const char *ptr, const char *end); |
395 | |
396static XML_Bool FASTCALL poolGrow(STRING_POOL *pool); | 418static XML_Bool FASTCALL poolGrow(STRING_POOL *pool); |
397 398static int FASTCALL nextScaffoldPart(XML_Parser parser); 399static XML_Content * FASTCALL build_model(XML_Parser parser); 400 | |
401static const XML_Char * FASTCALL 402poolCopyString(STRING_POOL *pool, const XML_Char *s); | 419static const XML_Char * FASTCALL 420poolCopyString(STRING_POOL *pool, const XML_Char *s); |
403static const XML_Char * FASTCALL | 421static const XML_Char * |
404poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n); 405static const XML_Char * FASTCALL 406poolAppendString(STRING_POOL *pool, const XML_Char *s); | 422poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n); 423static const XML_Char * FASTCALL 424poolAppendString(STRING_POOL *pool, const XML_Char *s); |
407static ELEMENT_TYPE * FASTCALL 408getElementType(XML_Parser Paraser, const ENCODING *enc, | 425 426static int FASTCALL nextScaffoldPart(XML_Parser parser); 427static XML_Content * build_model(XML_Parser parser); 428static ELEMENT_TYPE * 429getElementType(XML_Parser parser, const ENCODING *enc, |
409 const char *ptr, const char *end); 410 | 430 const char *ptr, const char *end); 431 |
411static void FASTCALL | 432static XML_Parser 433parserCreate(const XML_Char *encodingName, 434 const XML_Memory_Handling_Suite *memsuite, 435 const XML_Char *nameSep, 436 DTD *dtd); 437static void |
412parserInit(XML_Parser parser, const XML_Char *encodingName); 413 414#define poolStart(pool) ((pool)->start) 415#define poolEnd(pool) ((pool)->ptr) 416#define poolLength(pool) ((pool)->ptr - (pool)->start) 417#define poolChop(pool) ((void)--(pool->ptr)) 418#define poolLastChar(pool) (((pool)->ptr)[-1]) 419#define poolDiscard(pool) ((pool)->ptr = (pool)->start) --- 4 unchanged lines hidden (view full) --- 424 : ((*((pool)->ptr)++ = c), 1)) 425 426struct XML_ParserStruct { 427 /* The first member must be userData so that the XML_GetUserData 428 macro works. */ 429 void *m_userData; 430 void *m_handlerArg; 431 char *m_buffer; | 438parserInit(XML_Parser parser, const XML_Char *encodingName); 439 440#define poolStart(pool) ((pool)->start) 441#define poolEnd(pool) ((pool)->ptr) 442#define poolLength(pool) ((pool)->ptr - (pool)->start) 443#define poolChop(pool) ((void)--(pool->ptr)) 444#define poolLastChar(pool) (((pool)->ptr)[-1]) 445#define poolDiscard(pool) ((pool)->ptr = (pool)->start) --- 4 unchanged lines hidden (view full) --- 450 : ((*((pool)->ptr)++ = c), 1)) 451 452struct XML_ParserStruct { 453 /* The first member must be userData so that the XML_GetUserData 454 macro works. */ 455 void *m_userData; 456 void *m_handlerArg; 457 char *m_buffer; |
432 XML_Memory_Handling_Suite m_mem; | 458 const XML_Memory_Handling_Suite m_mem; |
433 /* first character to be parsed */ 434 const char *m_bufferPtr; 435 /* past last character to be parsed */ 436 char *m_bufferEnd; 437 /* allocated end of buffer */ 438 const char *m_bufferLim; | 459 /* first character to be parsed */ 460 const char *m_bufferPtr; 461 /* past last character to be parsed */ 462 char *m_bufferEnd; 463 /* allocated end of buffer */ 464 const char *m_bufferLim; |
439 long m_parseEndByteIndex; | 465 XML_Index m_parseEndByteIndex; |
440 const char *m_parseEndPtr; 441 XML_Char *m_dataBuf; 442 XML_Char *m_dataBufEnd; 443 XML_StartElementHandler m_startElementHandler; 444 XML_EndElementHandler m_endElementHandler; 445 XML_CharacterDataHandler m_characterDataHandler; 446 XML_ProcessingInstructionHandler m_processingInstructionHandler; 447 XML_CommentHandler m_commentHandler; 448 XML_StartCdataSectionHandler m_startCdataSectionHandler; 449 XML_EndCdataSectionHandler m_endCdataSectionHandler; 450 XML_DefaultHandler m_defaultHandler; 451 XML_StartDoctypeDeclHandler m_startDoctypeDeclHandler; 452 XML_EndDoctypeDeclHandler m_endDoctypeDeclHandler; 453 XML_UnparsedEntityDeclHandler m_unparsedEntityDeclHandler; 454 XML_NotationDeclHandler m_notationDeclHandler; 455 XML_StartNamespaceDeclHandler m_startNamespaceDeclHandler; 456 XML_EndNamespaceDeclHandler m_endNamespaceDeclHandler; 457 XML_NotStandaloneHandler m_notStandaloneHandler; 458 XML_ExternalEntityRefHandler m_externalEntityRefHandler; | 466 const char *m_parseEndPtr; 467 XML_Char *m_dataBuf; 468 XML_Char *m_dataBufEnd; 469 XML_StartElementHandler m_startElementHandler; 470 XML_EndElementHandler m_endElementHandler; 471 XML_CharacterDataHandler m_characterDataHandler; 472 XML_ProcessingInstructionHandler m_processingInstructionHandler; 473 XML_CommentHandler m_commentHandler; 474 XML_StartCdataSectionHandler m_startCdataSectionHandler; 475 XML_EndCdataSectionHandler m_endCdataSectionHandler; 476 XML_DefaultHandler m_defaultHandler; 477 XML_StartDoctypeDeclHandler m_startDoctypeDeclHandler; 478 XML_EndDoctypeDeclHandler m_endDoctypeDeclHandler; 479 XML_UnparsedEntityDeclHandler m_unparsedEntityDeclHandler; 480 XML_NotationDeclHandler m_notationDeclHandler; 481 XML_StartNamespaceDeclHandler m_startNamespaceDeclHandler; 482 XML_EndNamespaceDeclHandler m_endNamespaceDeclHandler; 483 XML_NotStandaloneHandler m_notStandaloneHandler; 484 XML_ExternalEntityRefHandler m_externalEntityRefHandler; |
459 void *m_externalEntityRefHandlerArg; | 485 XML_Parser m_externalEntityRefHandlerArg; |
460 XML_SkippedEntityHandler m_skippedEntityHandler; 461 XML_UnknownEncodingHandler m_unknownEncodingHandler; 462 XML_ElementDeclHandler m_elementDeclHandler; 463 XML_AttlistDeclHandler m_attlistDeclHandler; 464 XML_EntityDeclHandler m_entityDeclHandler; 465 XML_XmlDeclHandler m_xmlDeclHandler; 466 const ENCODING *m_encoding; 467 INIT_ENCODING m_initEncoding; 468 const ENCODING *m_internalEncoding; 469 const XML_Char *m_protocolEncodingName; 470 XML_Bool m_ns; 471 XML_Bool m_ns_triplets; 472 void *m_unknownEncodingMem; 473 void *m_unknownEncodingData; 474 void *m_unknownEncodingHandlerData; | 486 XML_SkippedEntityHandler m_skippedEntityHandler; 487 XML_UnknownEncodingHandler m_unknownEncodingHandler; 488 XML_ElementDeclHandler m_elementDeclHandler; 489 XML_AttlistDeclHandler m_attlistDeclHandler; 490 XML_EntityDeclHandler m_entityDeclHandler; 491 XML_XmlDeclHandler m_xmlDeclHandler; 492 const ENCODING *m_encoding; 493 INIT_ENCODING m_initEncoding; 494 const ENCODING *m_internalEncoding; 495 const XML_Char *m_protocolEncodingName; 496 XML_Bool m_ns; 497 XML_Bool m_ns_triplets; 498 void *m_unknownEncodingMem; 499 void *m_unknownEncodingData; 500 void *m_unknownEncodingHandlerData; |
475 void (*m_unknownEncodingRelease)(void *); | 501 void (XMLCALL *m_unknownEncodingRelease)(void *); |
476 PROLOG_STATE m_prologState; 477 Processor *m_processor; 478 enum XML_Error m_errorCode; 479 const char *m_eventPtr; 480 const char *m_eventEndPtr; 481 const char *m_positionPtr; 482 OPEN_INTERNAL_ENTITY *m_openInternalEntities; | 502 PROLOG_STATE m_prologState; 503 Processor *m_processor; 504 enum XML_Error m_errorCode; 505 const char *m_eventPtr; 506 const char *m_eventEndPtr; 507 const char *m_positionPtr; 508 OPEN_INTERNAL_ENTITY *m_openInternalEntities; |
509 OPEN_INTERNAL_ENTITY *m_freeInternalEntities; |
|
483 XML_Bool m_defaultExpandInternalEntities; 484 int m_tagLevel; 485 ENTITY *m_declEntity; 486 const XML_Char *m_doctypeName; 487 const XML_Char *m_doctypeSysid; 488 const XML_Char *m_doctypePubid; 489 const XML_Char *m_declAttributeType; 490 const XML_Char *m_declNotationName; 491 const XML_Char *m_declNotationPublicId; 492 ELEMENT_TYPE *m_declElementType; 493 ATTRIBUTE_ID *m_declAttributeId; 494 XML_Bool m_declAttributeIsCdata; 495 XML_Bool m_declAttributeIsId; | 510 XML_Bool m_defaultExpandInternalEntities; 511 int m_tagLevel; 512 ENTITY *m_declEntity; 513 const XML_Char *m_doctypeName; 514 const XML_Char *m_doctypeSysid; 515 const XML_Char *m_doctypePubid; 516 const XML_Char *m_declAttributeType; 517 const XML_Char *m_declNotationName; 518 const XML_Char *m_declNotationPublicId; 519 ELEMENT_TYPE *m_declElementType; 520 ATTRIBUTE_ID *m_declAttributeId; 521 XML_Bool m_declAttributeIsCdata; 522 XML_Bool m_declAttributeIsId; |
496 DTD m_dtd; | 523 DTD *m_dtd; |
497 const XML_Char *m_curBase; 498 TAG *m_tagStack; 499 TAG *m_freeTagList; 500 BINDING *m_inheritedBindings; 501 BINDING *m_freeBindingList; 502 int m_attsSize; 503 int m_nSpecifiedAtts; 504 int m_idAttIndex; 505 ATTRIBUTE *m_atts; | 524 const XML_Char *m_curBase; 525 TAG *m_tagStack; 526 TAG *m_freeTagList; 527 BINDING *m_inheritedBindings; 528 BINDING *m_freeBindingList; 529 int m_attsSize; 530 int m_nSpecifiedAtts; 531 int m_idAttIndex; 532 ATTRIBUTE *m_atts; |
533 NS_ATT *m_nsAtts; 534 unsigned long m_nsAttsVersion; 535 unsigned char m_nsAttsPower; |
|
506 POSITION m_position; 507 STRING_POOL m_tempPool; 508 STRING_POOL m_temp2Pool; 509 char *m_groupConnector; | 536 POSITION m_position; 537 STRING_POOL m_tempPool; 538 STRING_POOL m_temp2Pool; 539 char *m_groupConnector; |
510 unsigned m_groupSize; | 540 unsigned int m_groupSize; |
511 XML_Char m_namespaceSeparator; 512 XML_Parser m_parentParser; | 541 XML_Char m_namespaceSeparator; 542 XML_Parser m_parentParser; |
543 XML_ParsingStatus m_parsingStatus; |
|
513#ifdef XML_DTD 514 XML_Bool m_isParamEntity; 515 XML_Bool m_useForeignDTD; 516 enum XML_ParamEntityParsing m_paramEntityParsing; 517#endif 518}; 519 | 544#ifdef XML_DTD 545 XML_Bool m_isParamEntity; 546 XML_Bool m_useForeignDTD; 547 enum XML_ParamEntityParsing m_paramEntityParsing; 548#endif 549}; 550 |
520#define MALLOC(s) ((parser)->m_mem.malloc_fcn((s))) 521#define REALLOC(p,s) ((parser)->m_mem.realloc_fcn((p),(s))) 522#define FREE(p) ((parser)->m_mem.free_fcn((p))) | 551#define MALLOC(s) (parser->m_mem.malloc_fcn((s))) 552#define REALLOC(p,s) (parser->m_mem.realloc_fcn((p),(s))) 553#define FREE(p) (parser->m_mem.free_fcn((p))) |
523 524#define userData (parser->m_userData) 525#define handlerArg (parser->m_handlerArg) 526#define startElementHandler (parser->m_startElementHandler) 527#define endElementHandler (parser->m_endElementHandler) 528#define characterDataHandler (parser->m_characterDataHandler) 529#define processingInstructionHandler \ 530 (parser->m_processingInstructionHandler) --- 37 unchanged lines hidden (view full) --- 568#define prologState (parser->m_prologState) 569#define processor (parser->m_processor) 570#define errorCode (parser->m_errorCode) 571#define eventPtr (parser->m_eventPtr) 572#define eventEndPtr (parser->m_eventEndPtr) 573#define positionPtr (parser->m_positionPtr) 574#define position (parser->m_position) 575#define openInternalEntities (parser->m_openInternalEntities) | 554 555#define userData (parser->m_userData) 556#define handlerArg (parser->m_handlerArg) 557#define startElementHandler (parser->m_startElementHandler) 558#define endElementHandler (parser->m_endElementHandler) 559#define characterDataHandler (parser->m_characterDataHandler) 560#define processingInstructionHandler \ 561 (parser->m_processingInstructionHandler) --- 37 unchanged lines hidden (view full) --- 599#define prologState (parser->m_prologState) 600#define processor (parser->m_processor) 601#define errorCode (parser->m_errorCode) 602#define eventPtr (parser->m_eventPtr) 603#define eventEndPtr (parser->m_eventEndPtr) 604#define positionPtr (parser->m_positionPtr) 605#define position (parser->m_position) 606#define openInternalEntities (parser->m_openInternalEntities) |
607#define freeInternalEntities (parser->m_freeInternalEntities) |
|
576#define defaultExpandInternalEntities \ 577 (parser->m_defaultExpandInternalEntities) 578#define tagLevel (parser->m_tagLevel) 579#define buffer (parser->m_buffer) 580#define bufferPtr (parser->m_bufferPtr) 581#define bufferEnd (parser->m_bufferEnd) 582#define parseEndByteIndex (parser->m_parseEndByteIndex) 583#define parseEndPtr (parser->m_parseEndPtr) 584#define bufferLim (parser->m_bufferLim) 585#define dataBuf (parser->m_dataBuf) 586#define dataBufEnd (parser->m_dataBufEnd) | 608#define defaultExpandInternalEntities \ 609 (parser->m_defaultExpandInternalEntities) 610#define tagLevel (parser->m_tagLevel) 611#define buffer (parser->m_buffer) 612#define bufferPtr (parser->m_bufferPtr) 613#define bufferEnd (parser->m_bufferEnd) 614#define parseEndByteIndex (parser->m_parseEndByteIndex) 615#define parseEndPtr (parser->m_parseEndPtr) 616#define bufferLim (parser->m_bufferLim) 617#define dataBuf (parser->m_dataBuf) 618#define dataBufEnd (parser->m_dataBufEnd) |
587#define dtd (parser->m_dtd) | 619#define _dtd (parser->m_dtd) |
588#define curBase (parser->m_curBase) 589#define declEntity (parser->m_declEntity) 590#define doctypeName (parser->m_doctypeName) 591#define doctypeSysid (parser->m_doctypeSysid) 592#define doctypePubid (parser->m_doctypePubid) 593#define declAttributeType (parser->m_declAttributeType) 594#define declNotationName (parser->m_declNotationName) 595#define declNotationPublicId (parser->m_declNotationPublicId) --- 4 unchanged lines hidden (view full) --- 600#define freeTagList (parser->m_freeTagList) 601#define freeBindingList (parser->m_freeBindingList) 602#define inheritedBindings (parser->m_inheritedBindings) 603#define tagStack (parser->m_tagStack) 604#define atts (parser->m_atts) 605#define attsSize (parser->m_attsSize) 606#define nSpecifiedAtts (parser->m_nSpecifiedAtts) 607#define idAttIndex (parser->m_idAttIndex) | 620#define curBase (parser->m_curBase) 621#define declEntity (parser->m_declEntity) 622#define doctypeName (parser->m_doctypeName) 623#define doctypeSysid (parser->m_doctypeSysid) 624#define doctypePubid (parser->m_doctypePubid) 625#define declAttributeType (parser->m_declAttributeType) 626#define declNotationName (parser->m_declNotationName) 627#define declNotationPublicId (parser->m_declNotationPublicId) --- 4 unchanged lines hidden (view full) --- 632#define freeTagList (parser->m_freeTagList) 633#define freeBindingList (parser->m_freeBindingList) 634#define inheritedBindings (parser->m_inheritedBindings) 635#define tagStack (parser->m_tagStack) 636#define atts (parser->m_atts) 637#define attsSize (parser->m_attsSize) 638#define nSpecifiedAtts (parser->m_nSpecifiedAtts) 639#define idAttIndex (parser->m_idAttIndex) |
640#define nsAtts (parser->m_nsAtts) 641#define nsAttsVersion (parser->m_nsAttsVersion) 642#define nsAttsPower (parser->m_nsAttsPower) |
|
608#define tempPool (parser->m_tempPool) 609#define temp2Pool (parser->m_temp2Pool) 610#define groupConnector (parser->m_groupConnector) 611#define groupSize (parser->m_groupSize) 612#define namespaceSeparator (parser->m_namespaceSeparator) 613#define parentParser (parser->m_parentParser) | 643#define tempPool (parser->m_tempPool) 644#define temp2Pool (parser->m_temp2Pool) 645#define groupConnector (parser->m_groupConnector) 646#define groupSize (parser->m_groupSize) 647#define namespaceSeparator (parser->m_namespaceSeparator) 648#define parentParser (parser->m_parentParser) |
649#define ps_parsing (parser->m_parsingStatus.parsing) 650#define ps_finalBuffer (parser->m_parsingStatus.finalBuffer) |
|
614#ifdef XML_DTD 615#define isParamEntity (parser->m_isParamEntity) 616#define useForeignDTD (parser->m_useForeignDTD) 617#define paramEntityParsing (parser->m_paramEntityParsing) 618#endif /* XML_DTD */ 619 | 651#ifdef XML_DTD 652#define isParamEntity (parser->m_isParamEntity) 653#define useForeignDTD (parser->m_useForeignDTD) 654#define paramEntityParsing (parser->m_paramEntityParsing) 655#endif /* XML_DTD */ 656 |
620#define parsing (processor != prologInitProcessor) 621 622XML_Parser | 657XML_Parser XMLCALL |
623XML_ParserCreate(const XML_Char *encodingName) 624{ 625 return XML_ParserCreate_MM(encodingName, NULL, NULL); 626} 627 | 658XML_ParserCreate(const XML_Char *encodingName) 659{ 660 return XML_ParserCreate_MM(encodingName, NULL, NULL); 661} 662 |
628XML_Parser | 663XML_Parser XMLCALL |
629XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep) 630{ 631 XML_Char tmp[2]; 632 *tmp = nsSep; 633 return XML_ParserCreate_MM(encodingName, NULL, tmp); 634} 635 | 664XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep) 665{ 666 XML_Char tmp[2]; 667 *tmp = nsSep; 668 return XML_ParserCreate_MM(encodingName, NULL, tmp); 669} 670 |
636XML_Parser | 671static const XML_Char implicitContext[] = { 672 ASCII_x, ASCII_m, ASCII_l, ASCII_EQUALS, ASCII_h, ASCII_t, ASCII_t, ASCII_p, 673 ASCII_COLON, ASCII_SLASH, ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w, 674 ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, ASCII_o, ASCII_r, ASCII_g, 675 ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, ASCII_SLASH, ASCII_1, ASCII_9, 676 ASCII_9, ASCII_8, ASCII_SLASH, ASCII_n, ASCII_a, ASCII_m, ASCII_e, 677 ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, '\0' 678}; 679 680XML_Parser XMLCALL |
637XML_ParserCreate_MM(const XML_Char *encodingName, 638 const XML_Memory_Handling_Suite *memsuite, | 681XML_ParserCreate_MM(const XML_Char *encodingName, 682 const XML_Memory_Handling_Suite *memsuite, |
639 const XML_Char *nameSep) { | 683 const XML_Char *nameSep) 684{ 685 XML_Parser parser = parserCreate(encodingName, memsuite, nameSep, NULL); 686 if (parser != NULL && ns) { 687 /* implicit context only set for root parser, since child 688 parsers (i.e. external entity parsers) will inherit it 689 */ 690 if (!setContext(parser, implicitContext)) { 691 XML_ParserFree(parser); 692 return NULL; 693 } 694 } 695 return parser; 696} 697 698static XML_Parser 699parserCreate(const XML_Char *encodingName, 700 const XML_Memory_Handling_Suite *memsuite, 701 const XML_Char *nameSep, 702 DTD *dtd) 703{ |
640 XML_Parser parser; | 704 XML_Parser parser; |
641 static const XML_Char implicitContext[] = { 642 'x', 'm', 'l', '=', 'h', 't', 't', 'p', ':', '/', '/', 643 'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/', 644 'X', 'M', 'L', '/', '1', '9', '9', '8', '/', 645 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\0' 646 }; | |
647 | 705 |
648 | |
649 if (memsuite) { 650 XML_Memory_Handling_Suite *mtemp; | 706 if (memsuite) { 707 XML_Memory_Handling_Suite *mtemp; |
651 parser = memsuite->malloc_fcn(sizeof(struct XML_ParserStruct)); | 708 parser = (XML_Parser) 709 memsuite->malloc_fcn(sizeof(struct XML_ParserStruct)); |
652 if (parser != NULL) { | 710 if (parser != NULL) { |
653 mtemp = &(parser->m_mem); | 711 mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); |
654 mtemp->malloc_fcn = memsuite->malloc_fcn; 655 mtemp->realloc_fcn = memsuite->realloc_fcn; 656 mtemp->free_fcn = memsuite->free_fcn; 657 } 658 } 659 else { 660 XML_Memory_Handling_Suite *mtemp; | 712 mtemp->malloc_fcn = memsuite->malloc_fcn; 713 mtemp->realloc_fcn = memsuite->realloc_fcn; 714 mtemp->free_fcn = memsuite->free_fcn; 715 } 716 } 717 else { 718 XML_Memory_Handling_Suite *mtemp; |
661 parser = malloc(sizeof(struct XML_ParserStruct)); | 719 parser = (XML_Parser)malloc(sizeof(struct XML_ParserStruct)); |
662 if (parser != NULL) { | 720 if (parser != NULL) { |
663 mtemp = &(parser->m_mem); | 721 mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); |
664 mtemp->malloc_fcn = malloc; 665 mtemp->realloc_fcn = realloc; 666 mtemp->free_fcn = free; 667 } 668 } 669 670 if (!parser) 671 return parser; 672 673 buffer = NULL; 674 bufferLim = NULL; 675 676 attsSize = INIT_ATTS_SIZE; | 722 mtemp->malloc_fcn = malloc; 723 mtemp->realloc_fcn = realloc; 724 mtemp->free_fcn = free; 725 } 726 } 727 728 if (!parser) 729 return parser; 730 731 buffer = NULL; 732 bufferLim = NULL; 733 734 attsSize = INIT_ATTS_SIZE; |
677 atts = MALLOC(attsSize * sizeof(ATTRIBUTE)); | 735 atts = (ATTRIBUTE *)MALLOC(attsSize * sizeof(ATTRIBUTE)); |
678 if (atts == NULL) { 679 FREE(parser); 680 return NULL; 681 } | 736 if (atts == NULL) { 737 FREE(parser); 738 return NULL; 739 } |
682 dataBuf = MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char)); | 740 dataBuf = (XML_Char *)MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char)); |
683 if (dataBuf == NULL) { 684 FREE(atts); 685 FREE(parser); 686 return NULL; 687 } 688 dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE; 689 | 741 if (dataBuf == NULL) { 742 FREE(atts); 743 FREE(parser); 744 return NULL; 745 } 746 dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE; 747 |
748 if (dtd) 749 _dtd = dtd; 750 else { 751 _dtd = dtdCreate(&parser->m_mem); 752 if (_dtd == NULL) { 753 FREE(dataBuf); 754 FREE(atts); 755 FREE(parser); 756 return NULL; 757 } 758 } 759 |
|
690 freeBindingList = NULL; 691 freeTagList = NULL; | 760 freeBindingList = NULL; 761 freeTagList = NULL; |
762 freeInternalEntities = NULL; |
|
692 693 groupSize = 0; 694 groupConnector = NULL; 695 696 unknownEncodingHandler = NULL; 697 unknownEncodingHandlerData = NULL; 698 | 763 764 groupSize = 0; 765 groupConnector = NULL; 766 767 unknownEncodingHandler = NULL; 768 unknownEncodingHandlerData = NULL; 769 |
699 namespaceSeparator = '!'; | 770 namespaceSeparator = ASCII_EXCL; |
700 ns = XML_FALSE; 701 ns_triplets = XML_FALSE; 702 | 771 ns = XML_FALSE; 772 ns_triplets = XML_FALSE; 773 |
774 nsAtts = NULL; 775 nsAttsVersion = 0; 776 nsAttsPower = 0; 777 |
|
703 poolInit(&tempPool, &(parser->m_mem)); 704 poolInit(&temp2Pool, &(parser->m_mem)); 705 parserInit(parser, encodingName); | 778 poolInit(&tempPool, &(parser->m_mem)); 779 poolInit(&temp2Pool, &(parser->m_mem)); 780 parserInit(parser, encodingName); |
706 dtdInit(&dtd, parser); | |
707 | 781 |
708 if (!atts || !dataBuf || (encodingName && !protocolEncodingName)) { | 782 if (encodingName && !protocolEncodingName) { |
709 XML_ParserFree(parser); 710 return NULL; 711 } 712 713 if (nameSep) { 714 ns = XML_TRUE; 715 internalEncoding = XmlGetInternalEncodingNS(); 716 namespaceSeparator = *nameSep; | 783 XML_ParserFree(parser); 784 return NULL; 785 } 786 787 if (nameSep) { 788 ns = XML_TRUE; 789 internalEncoding = XmlGetInternalEncodingNS(); 790 namespaceSeparator = *nameSep; |
717 718 if (!setContext(parser, implicitContext)) { 719 XML_ParserFree(parser); 720 return NULL; 721 } | |
722 } 723 else { 724 internalEncoding = XmlGetInternalEncoding(); 725 } 726 727 return parser; 728} 729 | 791 } 792 else { 793 internalEncoding = XmlGetInternalEncoding(); 794 } 795 796 return parser; 797} 798 |
730static void FASTCALL | 799static void |
731parserInit(XML_Parser parser, const XML_Char *encodingName) 732{ 733 processor = prologInitProcessor; 734 XmlPrologStateInit(&prologState); 735 protocolEncodingName = (encodingName != NULL 736 ? poolCopyString(&tempPool, encodingName) 737 : NULL); 738 curBase = NULL; --- 37 unchanged lines hidden (view full) --- 776 declNotationPublicId = NULL; 777 declAttributeIsCdata = XML_FALSE; 778 declAttributeIsId = XML_FALSE; 779 memset(&position, 0, sizeof(POSITION)); 780 errorCode = XML_ERROR_NONE; 781 eventPtr = NULL; 782 eventEndPtr = NULL; 783 positionPtr = NULL; | 800parserInit(XML_Parser parser, const XML_Char *encodingName) 801{ 802 processor = prologInitProcessor; 803 XmlPrologStateInit(&prologState); 804 protocolEncodingName = (encodingName != NULL 805 ? poolCopyString(&tempPool, encodingName) 806 : NULL); 807 curBase = NULL; --- 37 unchanged lines hidden (view full) --- 845 declNotationPublicId = NULL; 846 declAttributeIsCdata = XML_FALSE; 847 declAttributeIsId = XML_FALSE; 848 memset(&position, 0, sizeof(POSITION)); 849 errorCode = XML_ERROR_NONE; 850 eventPtr = NULL; 851 eventEndPtr = NULL; 852 positionPtr = NULL; |
784 openInternalEntities = 0; | 853 openInternalEntities = NULL; |
785 defaultExpandInternalEntities = XML_TRUE; 786 tagLevel = 0; 787 tagStack = NULL; 788 inheritedBindings = NULL; 789 nSpecifiedAtts = 0; 790 unknownEncodingMem = NULL; 791 unknownEncodingRelease = NULL; 792 unknownEncodingData = NULL; 793 parentParser = NULL; | 854 defaultExpandInternalEntities = XML_TRUE; 855 tagLevel = 0; 856 tagStack = NULL; 857 inheritedBindings = NULL; 858 nSpecifiedAtts = 0; 859 unknownEncodingMem = NULL; 860 unknownEncodingRelease = NULL; 861 unknownEncodingData = NULL; 862 parentParser = NULL; |
863 ps_parsing = XML_INITIALIZED; |
|
794#ifdef XML_DTD 795 isParamEntity = XML_FALSE; 796 useForeignDTD = XML_FALSE; 797 paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; 798#endif 799} 800 801/* moves list of bindings to freeBindingList */ 802static void FASTCALL 803moveToFreeBindingList(XML_Parser parser, BINDING *bindings) 804{ 805 while (bindings) { 806 BINDING *b = bindings; 807 bindings = bindings->nextTagBinding; 808 b->nextTagBinding = freeBindingList; 809 freeBindingList = b; 810 } 811} 812 | 864#ifdef XML_DTD 865 isParamEntity = XML_FALSE; 866 useForeignDTD = XML_FALSE; 867 paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; 868#endif 869} 870 871/* moves list of bindings to freeBindingList */ 872static void FASTCALL 873moveToFreeBindingList(XML_Parser parser, BINDING *bindings) 874{ 875 while (bindings) { 876 BINDING *b = bindings; 877 bindings = bindings->nextTagBinding; 878 b->nextTagBinding = freeBindingList; 879 freeBindingList = b; 880 } 881} 882 |
813XML_Bool | 883XML_Bool XMLCALL |
814XML_ParserReset(XML_Parser parser, const XML_Char *encodingName) 815{ 816 TAG *tStk; | 884XML_ParserReset(XML_Parser parser, const XML_Char *encodingName) 885{ 886 TAG *tStk; |
817 if (parentParser) | 887 OPEN_INTERNAL_ENTITY *openEntityList; 888 if (parentParser) |
818 return XML_FALSE; 819 /* move tagStack to freeTagList */ 820 tStk = tagStack; 821 while (tStk) { 822 TAG *tag = tStk; 823 tStk = tStk->parent; 824 tag->parent = freeTagList; 825 moveToFreeBindingList(parser, tag->bindings); 826 tag->bindings = NULL; 827 freeTagList = tag; 828 } | 889 return XML_FALSE; 890 /* move tagStack to freeTagList */ 891 tStk = tagStack; 892 while (tStk) { 893 TAG *tag = tStk; 894 tStk = tStk->parent; 895 tag->parent = freeTagList; 896 moveToFreeBindingList(parser, tag->bindings); 897 tag->bindings = NULL; 898 freeTagList = tag; 899 } |
900 /* move openInternalEntities to freeInternalEntities */ 901 openEntityList = openInternalEntities; 902 while (openEntityList) { 903 OPEN_INTERNAL_ENTITY *openEntity = openEntityList; 904 openEntityList = openEntity->next; 905 openEntity->next = freeInternalEntities; 906 freeInternalEntities = openEntity; 907 } |
|
829 moveToFreeBindingList(parser, inheritedBindings); | 908 moveToFreeBindingList(parser, inheritedBindings); |
830 if (unknownEncodingMem) 831 FREE(unknownEncodingMem); | 909 FREE(unknownEncodingMem); |
832 if (unknownEncodingRelease) 833 unknownEncodingRelease(unknownEncodingData); 834 poolClear(&tempPool); 835 poolClear(&temp2Pool); 836 parserInit(parser, encodingName); | 910 if (unknownEncodingRelease) 911 unknownEncodingRelease(unknownEncodingData); 912 poolClear(&tempPool); 913 poolClear(&temp2Pool); 914 parserInit(parser, encodingName); |
837 dtdReset(&dtd, parser); 838 return XML_TRUE; | 915 dtdReset(_dtd, &parser->m_mem); 916 return setContext(parser, implicitContext); |
839} 840 | 917} 918 |
841int | 919enum XML_Status XMLCALL |
842XML_SetEncoding(XML_Parser parser, const XML_Char *encodingName) 843{ | 920XML_SetEncoding(XML_Parser parser, const XML_Char *encodingName) 921{ |
844 /* block after XML_Parse()/XML_ParseBuffer() has been called */ 845 if (parsing) 846 return 0; | 922 /* Block after XML_Parse()/XML_ParseBuffer() has been called. 923 XXX There's no way for the caller to determine which of the 924 XXX possible error cases caused the XML_STATUS_ERROR return. 925 */ 926 if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) 927 return XML_STATUS_ERROR; |
847 if (encodingName == NULL) 848 protocolEncodingName = NULL; 849 else { 850 protocolEncodingName = poolCopyString(&tempPool, encodingName); 851 if (!protocolEncodingName) | 928 if (encodingName == NULL) 929 protocolEncodingName = NULL; 930 else { 931 protocolEncodingName = poolCopyString(&tempPool, encodingName); 932 if (!protocolEncodingName) |
852 return 0; | 933 return XML_STATUS_ERROR; |
853 } | 934 } |
854 return 1; | 935 return XML_STATUS_OK; |
855} 856 | 936} 937 |
857XML_Parser | 938XML_Parser XMLCALL |
858XML_ExternalEntityParserCreate(XML_Parser oldParser, 859 const XML_Char *context, 860 const XML_Char *encodingName) 861{ 862 XML_Parser parser = oldParser; | 939XML_ExternalEntityParserCreate(XML_Parser oldParser, 940 const XML_Char *context, 941 const XML_Char *encodingName) 942{ 943 XML_Parser parser = oldParser; |
863 DTD *oldDtd = &dtd; | 944 DTD *newDtd = NULL; 945 DTD *oldDtd = _dtd; |
864 XML_StartElementHandler oldStartElementHandler = startElementHandler; 865 XML_EndElementHandler oldEndElementHandler = endElementHandler; 866 XML_CharacterDataHandler oldCharacterDataHandler = characterDataHandler; 867 XML_ProcessingInstructionHandler oldProcessingInstructionHandler 868 = processingInstructionHandler; 869 XML_CommentHandler oldCommentHandler = commentHandler; 870 XML_StartCdataSectionHandler oldStartCdataSectionHandler 871 = startCdataSectionHandler; --- 17 unchanged lines hidden (view full) --- 889 XML_AttlistDeclHandler oldAttlistDeclHandler = attlistDeclHandler; 890 XML_EntityDeclHandler oldEntityDeclHandler = entityDeclHandler; 891 XML_XmlDeclHandler oldXmlDeclHandler = xmlDeclHandler; 892 ELEMENT_TYPE * oldDeclElementType = declElementType; 893 894 void *oldUserData = userData; 895 void *oldHandlerArg = handlerArg; 896 XML_Bool oldDefaultExpandInternalEntities = defaultExpandInternalEntities; | 946 XML_StartElementHandler oldStartElementHandler = startElementHandler; 947 XML_EndElementHandler oldEndElementHandler = endElementHandler; 948 XML_CharacterDataHandler oldCharacterDataHandler = characterDataHandler; 949 XML_ProcessingInstructionHandler oldProcessingInstructionHandler 950 = processingInstructionHandler; 951 XML_CommentHandler oldCommentHandler = commentHandler; 952 XML_StartCdataSectionHandler oldStartCdataSectionHandler 953 = startCdataSectionHandler; --- 17 unchanged lines hidden (view full) --- 971 XML_AttlistDeclHandler oldAttlistDeclHandler = attlistDeclHandler; 972 XML_EntityDeclHandler oldEntityDeclHandler = entityDeclHandler; 973 XML_XmlDeclHandler oldXmlDeclHandler = xmlDeclHandler; 974 ELEMENT_TYPE * oldDeclElementType = declElementType; 975 976 void *oldUserData = userData; 977 void *oldHandlerArg = handlerArg; 978 XML_Bool oldDefaultExpandInternalEntities = defaultExpandInternalEntities; |
897 void *oldExternalEntityRefHandlerArg = externalEntityRefHandlerArg; | 979 XML_Parser oldExternalEntityRefHandlerArg = externalEntityRefHandlerArg; |
898#ifdef XML_DTD | 980#ifdef XML_DTD |
899 int oldParamEntityParsing = paramEntityParsing; | 981 enum XML_ParamEntityParsing oldParamEntityParsing = paramEntityParsing; |
900 int oldInEntityValue = prologState.inEntityValue; 901#endif 902 XML_Bool oldns_triplets = ns_triplets; 903 | 982 int oldInEntityValue = prologState.inEntityValue; 983#endif 984 XML_Bool oldns_triplets = ns_triplets; 985 |
986#ifdef XML_DTD 987 if (!context) 988 newDtd = oldDtd; 989#endif /* XML_DTD */ 990 |
|
904 /* Note that the magical uses of the pre-processor to make field 905 access look more like C++ require that `parser' be overwritten 906 here. This makes this function more painful to follow than it 907 would be otherwise. 908 */ 909 if (ns) { 910 XML_Char tmp[2]; | 991 /* Note that the magical uses of the pre-processor to make field 992 access look more like C++ require that `parser' be overwritten 993 here. This makes this function more painful to follow than it 994 would be otherwise. 995 */ 996 if (ns) { 997 XML_Char tmp[2]; |
911 | |
912 *tmp = namespaceSeparator; | 998 *tmp = namespaceSeparator; |
913 parser = XML_ParserCreate_MM(encodingName, &parser->m_mem, 914 tmp); | 999 parser = parserCreate(encodingName, &parser->m_mem, tmp, newDtd); |
915 } 916 else { | 1000 } 1001 else { |
917 parser = XML_ParserCreate_MM(encodingName, &parser->m_mem, 918 NULL); | 1002 parser = parserCreate(encodingName, &parser->m_mem, NULL, newDtd); |
919 } 920 921 if (!parser) 922 return NULL; 923 924 startElementHandler = oldStartElementHandler; 925 endElementHandler = oldEndElementHandler; 926 characterDataHandler = oldCharacterDataHandler; --- 25 unchanged lines hidden (view full) --- 952 defaultExpandInternalEntities = oldDefaultExpandInternalEntities; 953 ns_triplets = oldns_triplets; 954 parentParser = oldParser; 955#ifdef XML_DTD 956 paramEntityParsing = oldParamEntityParsing; 957 prologState.inEntityValue = oldInEntityValue; 958 if (context) { 959#endif /* XML_DTD */ | 1003 } 1004 1005 if (!parser) 1006 return NULL; 1007 1008 startElementHandler = oldStartElementHandler; 1009 endElementHandler = oldEndElementHandler; 1010 characterDataHandler = oldCharacterDataHandler; --- 25 unchanged lines hidden (view full) --- 1036 defaultExpandInternalEntities = oldDefaultExpandInternalEntities; 1037 ns_triplets = oldns_triplets; 1038 parentParser = oldParser; 1039#ifdef XML_DTD 1040 paramEntityParsing = oldParamEntityParsing; 1041 prologState.inEntityValue = oldInEntityValue; 1042 if (context) { 1043#endif /* XML_DTD */ |
960 if (!dtdCopy(&dtd, oldDtd, parser) || !setContext(parser, context)) { | 1044 if (!dtdCopy(_dtd, oldDtd, &parser->m_mem) 1045 || !setContext(parser, context)) { |
961 XML_ParserFree(parser); 962 return NULL; 963 } 964 processor = externalEntityInitProcessor; 965#ifdef XML_DTD 966 } 967 else { | 1046 XML_ParserFree(parser); 1047 return NULL; 1048 } 1049 processor = externalEntityInitProcessor; 1050#ifdef XML_DTD 1051 } 1052 else { |
968 dtdSwap(&dtd, oldDtd); | 1053 /* The DTD instance referenced by _dtd is shared between the document's 1054 root parser and external PE parsers, therefore one does not need to 1055 call setContext. In addition, one also *must* not call setContext, 1056 because this would overwrite existing prefix->binding pointers in 1057 _dtd with ones that get destroyed with the external PE parser. 1058 This would leave those prefixes with dangling pointers. 1059 */ |
969 isParamEntity = XML_TRUE; 970 XmlPrologStateInitExternalEntity(&prologState); 971 processor = externalParEntInitProcessor; 972 } 973#endif /* XML_DTD */ 974 return parser; 975} 976 --- 5 unchanged lines hidden (view full) --- 982 if (!b) 983 break; 984 bindings = b->nextTagBinding; 985 FREE(b->uri); 986 FREE(b); 987 } 988} 989 | 1060 isParamEntity = XML_TRUE; 1061 XmlPrologStateInitExternalEntity(&prologState); 1062 processor = externalParEntInitProcessor; 1063 } 1064#endif /* XML_DTD */ 1065 return parser; 1066} 1067 --- 5 unchanged lines hidden (view full) --- 1073 if (!b) 1074 break; 1075 bindings = b->nextTagBinding; 1076 FREE(b->uri); 1077 FREE(b); 1078 } 1079} 1080 |
990void | 1081void XMLCALL |
991XML_ParserFree(XML_Parser parser) 992{ | 1082XML_ParserFree(XML_Parser parser) 1083{ |
1084 TAG *tagList; 1085 OPEN_INTERNAL_ENTITY *entityList; 1086 if (parser == NULL) 1087 return; 1088 /* free tagStack and freeTagList */ 1089 tagList = tagStack; |
|
993 for (;;) { 994 TAG *p; | 1090 for (;;) { 1091 TAG *p; |
995 if (tagStack == 0) { | 1092 if (tagList == NULL) { |
996 if (freeTagList == NULL) 997 break; | 1093 if (freeTagList == NULL) 1094 break; |
998 tagStack = freeTagList; | 1095 tagList = freeTagList; |
999 freeTagList = NULL; 1000 } | 1096 freeTagList = NULL; 1097 } |
1001 p = tagStack; 1002 tagStack = tagStack->parent; | 1098 p = tagList; 1099 tagList = tagList->parent; |
1003 FREE(p->buf); 1004 destroyBindings(p->bindings, parser); 1005 FREE(p); 1006 } | 1100 FREE(p->buf); 1101 destroyBindings(p->bindings, parser); 1102 FREE(p); 1103 } |
1104 /* free openInternalEntities and freeInternalEntities */ 1105 entityList = openInternalEntities; 1106 for (;;) { 1107 OPEN_INTERNAL_ENTITY *openEntity; 1108 if (entityList == NULL) { 1109 if (freeInternalEntities == NULL) 1110 break; 1111 entityList = freeInternalEntities; 1112 freeInternalEntities = NULL; 1113 } 1114 openEntity = entityList; 1115 entityList = entityList->next; 1116 FREE(openEntity); 1117 } 1118 |
|
1007 destroyBindings(freeBindingList, parser); 1008 destroyBindings(inheritedBindings, parser); 1009 poolDestroy(&tempPool); 1010 poolDestroy(&temp2Pool); 1011#ifdef XML_DTD | 1119 destroyBindings(freeBindingList, parser); 1120 destroyBindings(inheritedBindings, parser); 1121 poolDestroy(&tempPool); 1122 poolDestroy(&temp2Pool); 1123#ifdef XML_DTD |
1012 if (isParamEntity) 1013 dtdSwap(&dtd, &parentParser->m_dtd); | 1124 /* external parameter entity parsers share the DTD structure 1125 parser->m_dtd with the root parser, so we must not destroy it 1126 */ 1127 if (!isParamEntity && _dtd) 1128#else 1129 if (_dtd) |
1014#endif /* XML_DTD */ | 1130#endif /* XML_DTD */ |
1015 dtdDestroy(&dtd, parser); | 1131 dtdDestroy(_dtd, (XML_Bool)!parentParser, &parser->m_mem); |
1016 FREE((void *)atts); | 1132 FREE((void *)atts); |
1017 if (groupConnector) 1018 FREE(groupConnector); 1019 if (buffer) 1020 FREE(buffer); | 1133 FREE(groupConnector); 1134 FREE(buffer); |
1021 FREE(dataBuf); | 1135 FREE(dataBuf); |
1022 if (unknownEncodingMem) 1023 FREE(unknownEncodingMem); | 1136 FREE(nsAtts); 1137 FREE(unknownEncodingMem); |
1024 if (unknownEncodingRelease) 1025 unknownEncodingRelease(unknownEncodingData); 1026 FREE(parser); 1027} 1028 | 1138 if (unknownEncodingRelease) 1139 unknownEncodingRelease(unknownEncodingData); 1140 FREE(parser); 1141} 1142 |
1029void | 1143void XMLCALL |
1030XML_UseParserAsHandlerArg(XML_Parser parser) 1031{ 1032 handlerArg = parser; 1033} 1034 | 1144XML_UseParserAsHandlerArg(XML_Parser parser) 1145{ 1146 handlerArg = parser; 1147} 1148 |
1035enum XML_Error | 1149enum XML_Error XMLCALL |
1036XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD) 1037{ 1038#ifdef XML_DTD 1039 /* block after XML_Parse()/XML_ParseBuffer() has been called */ | 1150XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD) 1151{ 1152#ifdef XML_DTD 1153 /* block after XML_Parse()/XML_ParseBuffer() has been called */ |
1040 if (parsing) | 1154 if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) |
1041 return XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING; 1042 useForeignDTD = useDTD; 1043 return XML_ERROR_NONE; 1044#else 1045 return XML_ERROR_FEATURE_REQUIRES_XML_DTD; 1046#endif 1047} 1048 | 1155 return XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING; 1156 useForeignDTD = useDTD; 1157 return XML_ERROR_NONE; 1158#else 1159 return XML_ERROR_FEATURE_REQUIRES_XML_DTD; 1160#endif 1161} 1162 |
1049void | 1163void XMLCALL |
1050XML_SetReturnNSTriplet(XML_Parser parser, int do_nst) 1051{ 1052 /* block after XML_Parse()/XML_ParseBuffer() has been called */ | 1164XML_SetReturnNSTriplet(XML_Parser parser, int do_nst) 1165{ 1166 /* block after XML_Parse()/XML_ParseBuffer() has been called */ |
1053 if (parsing) | 1167 if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) |
1054 return; 1055 ns_triplets = do_nst ? XML_TRUE : XML_FALSE; 1056} 1057 | 1168 return; 1169 ns_triplets = do_nst ? XML_TRUE : XML_FALSE; 1170} 1171 |
1058void | 1172void XMLCALL |
1059XML_SetUserData(XML_Parser parser, void *p) 1060{ 1061 if (handlerArg == userData) 1062 handlerArg = userData = p; 1063 else 1064 userData = p; 1065} 1066 | 1173XML_SetUserData(XML_Parser parser, void *p) 1174{ 1175 if (handlerArg == userData) 1176 handlerArg = userData = p; 1177 else 1178 userData = p; 1179} 1180 |
1067int | 1181enum XML_Status XMLCALL |
1068XML_SetBase(XML_Parser parser, const XML_Char *p) 1069{ 1070 if (p) { | 1182XML_SetBase(XML_Parser parser, const XML_Char *p) 1183{ 1184 if (p) { |
1071 p = poolCopyString(&dtd.pool, p); | 1185 p = poolCopyString(&_dtd->pool, p); |
1072 if (!p) | 1186 if (!p) |
1073 return 0; | 1187 return XML_STATUS_ERROR; |
1074 curBase = p; 1075 } 1076 else 1077 curBase = NULL; | 1188 curBase = p; 1189 } 1190 else 1191 curBase = NULL; |
1078 return 1; | 1192 return XML_STATUS_OK; |
1079} 1080 | 1193} 1194 |
1081const XML_Char * | 1195const XML_Char * XMLCALL |
1082XML_GetBase(XML_Parser parser) 1083{ 1084 return curBase; 1085} 1086 | 1196XML_GetBase(XML_Parser parser) 1197{ 1198 return curBase; 1199} 1200 |
1087int | 1201int XMLCALL |
1088XML_GetSpecifiedAttributeCount(XML_Parser parser) 1089{ 1090 return nSpecifiedAtts; 1091} 1092 | 1202XML_GetSpecifiedAttributeCount(XML_Parser parser) 1203{ 1204 return nSpecifiedAtts; 1205} 1206 |
1093int | 1207int XMLCALL |
1094XML_GetIdAttributeIndex(XML_Parser parser) 1095{ 1096 return idAttIndex; 1097} 1098 | 1208XML_GetIdAttributeIndex(XML_Parser parser) 1209{ 1210 return idAttIndex; 1211} 1212 |
1099void | 1213void XMLCALL |
1100XML_SetElementHandler(XML_Parser parser, 1101 XML_StartElementHandler start, 1102 XML_EndElementHandler end) 1103{ 1104 startElementHandler = start; 1105 endElementHandler = end; 1106} 1107 | 1214XML_SetElementHandler(XML_Parser parser, 1215 XML_StartElementHandler start, 1216 XML_EndElementHandler end) 1217{ 1218 startElementHandler = start; 1219 endElementHandler = end; 1220} 1221 |
1108void | 1222void XMLCALL |
1109XML_SetStartElementHandler(XML_Parser parser, 1110 XML_StartElementHandler start) { 1111 startElementHandler = start; 1112} 1113 | 1223XML_SetStartElementHandler(XML_Parser parser, 1224 XML_StartElementHandler start) { 1225 startElementHandler = start; 1226} 1227 |
1114void | 1228void XMLCALL |
1115XML_SetEndElementHandler(XML_Parser parser, 1116 XML_EndElementHandler end) { 1117 endElementHandler = end; 1118} 1119 | 1229XML_SetEndElementHandler(XML_Parser parser, 1230 XML_EndElementHandler end) { 1231 endElementHandler = end; 1232} 1233 |
1120void | 1234void XMLCALL |
1121XML_SetCharacterDataHandler(XML_Parser parser, 1122 XML_CharacterDataHandler handler) 1123{ 1124 characterDataHandler = handler; 1125} 1126 | 1235XML_SetCharacterDataHandler(XML_Parser parser, 1236 XML_CharacterDataHandler handler) 1237{ 1238 characterDataHandler = handler; 1239} 1240 |
1127void | 1241void XMLCALL |
1128XML_SetProcessingInstructionHandler(XML_Parser parser, 1129 XML_ProcessingInstructionHandler handler) 1130{ 1131 processingInstructionHandler = handler; 1132} 1133 | 1242XML_SetProcessingInstructionHandler(XML_Parser parser, 1243 XML_ProcessingInstructionHandler handler) 1244{ 1245 processingInstructionHandler = handler; 1246} 1247 |
1134void | 1248void XMLCALL |
1135XML_SetCommentHandler(XML_Parser parser, 1136 XML_CommentHandler handler) 1137{ 1138 commentHandler = handler; 1139} 1140 | 1249XML_SetCommentHandler(XML_Parser parser, 1250 XML_CommentHandler handler) 1251{ 1252 commentHandler = handler; 1253} 1254 |
1141void | 1255void XMLCALL |
1142XML_SetCdataSectionHandler(XML_Parser parser, 1143 XML_StartCdataSectionHandler start, 1144 XML_EndCdataSectionHandler end) 1145{ 1146 startCdataSectionHandler = start; 1147 endCdataSectionHandler = end; 1148} 1149 | 1256XML_SetCdataSectionHandler(XML_Parser parser, 1257 XML_StartCdataSectionHandler start, 1258 XML_EndCdataSectionHandler end) 1259{ 1260 startCdataSectionHandler = start; 1261 endCdataSectionHandler = end; 1262} 1263 |
1150void | 1264void XMLCALL |
1151XML_SetStartCdataSectionHandler(XML_Parser parser, 1152 XML_StartCdataSectionHandler start) { 1153 startCdataSectionHandler = start; 1154} 1155 | 1265XML_SetStartCdataSectionHandler(XML_Parser parser, 1266 XML_StartCdataSectionHandler start) { 1267 startCdataSectionHandler = start; 1268} 1269 |
1156void | 1270void XMLCALL |
1157XML_SetEndCdataSectionHandler(XML_Parser parser, 1158 XML_EndCdataSectionHandler end) { 1159 endCdataSectionHandler = end; 1160} 1161 | 1271XML_SetEndCdataSectionHandler(XML_Parser parser, 1272 XML_EndCdataSectionHandler end) { 1273 endCdataSectionHandler = end; 1274} 1275 |
1162void | 1276void XMLCALL |
1163XML_SetDefaultHandler(XML_Parser parser, 1164 XML_DefaultHandler handler) 1165{ 1166 defaultHandler = handler; 1167 defaultExpandInternalEntities = XML_FALSE; 1168} 1169 | 1277XML_SetDefaultHandler(XML_Parser parser, 1278 XML_DefaultHandler handler) 1279{ 1280 defaultHandler = handler; 1281 defaultExpandInternalEntities = XML_FALSE; 1282} 1283 |
1170void | 1284void XMLCALL |
1171XML_SetDefaultHandlerExpand(XML_Parser parser, 1172 XML_DefaultHandler handler) 1173{ 1174 defaultHandler = handler; 1175 defaultExpandInternalEntities = XML_TRUE; 1176} 1177 | 1285XML_SetDefaultHandlerExpand(XML_Parser parser, 1286 XML_DefaultHandler handler) 1287{ 1288 defaultHandler = handler; 1289 defaultExpandInternalEntities = XML_TRUE; 1290} 1291 |
1178void | 1292void XMLCALL |
1179XML_SetDoctypeDeclHandler(XML_Parser parser, 1180 XML_StartDoctypeDeclHandler start, 1181 XML_EndDoctypeDeclHandler end) 1182{ 1183 startDoctypeDeclHandler = start; 1184 endDoctypeDeclHandler = end; 1185} 1186 | 1293XML_SetDoctypeDeclHandler(XML_Parser parser, 1294 XML_StartDoctypeDeclHandler start, 1295 XML_EndDoctypeDeclHandler end) 1296{ 1297 startDoctypeDeclHandler = start; 1298 endDoctypeDeclHandler = end; 1299} 1300 |
1187void | 1301void XMLCALL |
1188XML_SetStartDoctypeDeclHandler(XML_Parser parser, 1189 XML_StartDoctypeDeclHandler start) { 1190 startDoctypeDeclHandler = start; 1191} 1192 | 1302XML_SetStartDoctypeDeclHandler(XML_Parser parser, 1303 XML_StartDoctypeDeclHandler start) { 1304 startDoctypeDeclHandler = start; 1305} 1306 |
1193void | 1307void XMLCALL |
1194XML_SetEndDoctypeDeclHandler(XML_Parser parser, 1195 XML_EndDoctypeDeclHandler end) { 1196 endDoctypeDeclHandler = end; 1197} 1198 | 1308XML_SetEndDoctypeDeclHandler(XML_Parser parser, 1309 XML_EndDoctypeDeclHandler end) { 1310 endDoctypeDeclHandler = end; 1311} 1312 |
1199void | 1313void XMLCALL |
1200XML_SetUnparsedEntityDeclHandler(XML_Parser parser, 1201 XML_UnparsedEntityDeclHandler handler) 1202{ 1203 unparsedEntityDeclHandler = handler; 1204} 1205 | 1314XML_SetUnparsedEntityDeclHandler(XML_Parser parser, 1315 XML_UnparsedEntityDeclHandler handler) 1316{ 1317 unparsedEntityDeclHandler = handler; 1318} 1319 |
1206void | 1320void XMLCALL |
1207XML_SetNotationDeclHandler(XML_Parser parser, 1208 XML_NotationDeclHandler handler) 1209{ 1210 notationDeclHandler = handler; 1211} 1212 | 1321XML_SetNotationDeclHandler(XML_Parser parser, 1322 XML_NotationDeclHandler handler) 1323{ 1324 notationDeclHandler = handler; 1325} 1326 |
1213void | 1327void XMLCALL |
1214XML_SetNamespaceDeclHandler(XML_Parser parser, 1215 XML_StartNamespaceDeclHandler start, 1216 XML_EndNamespaceDeclHandler end) 1217{ 1218 startNamespaceDeclHandler = start; 1219 endNamespaceDeclHandler = end; 1220} 1221 | 1328XML_SetNamespaceDeclHandler(XML_Parser parser, 1329 XML_StartNamespaceDeclHandler start, 1330 XML_EndNamespaceDeclHandler end) 1331{ 1332 startNamespaceDeclHandler = start; 1333 endNamespaceDeclHandler = end; 1334} 1335 |
1222void | 1336void XMLCALL |
1223XML_SetStartNamespaceDeclHandler(XML_Parser parser, 1224 XML_StartNamespaceDeclHandler start) { 1225 startNamespaceDeclHandler = start; 1226} 1227 | 1337XML_SetStartNamespaceDeclHandler(XML_Parser parser, 1338 XML_StartNamespaceDeclHandler start) { 1339 startNamespaceDeclHandler = start; 1340} 1341 |
1228void | 1342void XMLCALL |
1229XML_SetEndNamespaceDeclHandler(XML_Parser parser, 1230 XML_EndNamespaceDeclHandler end) { 1231 endNamespaceDeclHandler = end; 1232} 1233 | 1343XML_SetEndNamespaceDeclHandler(XML_Parser parser, 1344 XML_EndNamespaceDeclHandler end) { 1345 endNamespaceDeclHandler = end; 1346} 1347 |
1234void | 1348void XMLCALL |
1235XML_SetNotStandaloneHandler(XML_Parser parser, 1236 XML_NotStandaloneHandler handler) 1237{ 1238 notStandaloneHandler = handler; 1239} 1240 | 1349XML_SetNotStandaloneHandler(XML_Parser parser, 1350 XML_NotStandaloneHandler handler) 1351{ 1352 notStandaloneHandler = handler; 1353} 1354 |
1241void | 1355void XMLCALL |
1242XML_SetExternalEntityRefHandler(XML_Parser parser, 1243 XML_ExternalEntityRefHandler handler) 1244{ 1245 externalEntityRefHandler = handler; 1246} 1247 | 1356XML_SetExternalEntityRefHandler(XML_Parser parser, 1357 XML_ExternalEntityRefHandler handler) 1358{ 1359 externalEntityRefHandler = handler; 1360} 1361 |
1248void | 1362void XMLCALL |
1249XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg) 1250{ 1251 if (arg) | 1363XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg) 1364{ 1365 if (arg) |
1252 externalEntityRefHandlerArg = arg; | 1366 externalEntityRefHandlerArg = (XML_Parser)arg; |
1253 else 1254 externalEntityRefHandlerArg = parser; 1255} 1256 | 1367 else 1368 externalEntityRefHandlerArg = parser; 1369} 1370 |
1257void | 1371void XMLCALL |
1258XML_SetSkippedEntityHandler(XML_Parser parser, 1259 XML_SkippedEntityHandler handler) 1260{ 1261 skippedEntityHandler = handler; 1262} 1263 | 1372XML_SetSkippedEntityHandler(XML_Parser parser, 1373 XML_SkippedEntityHandler handler) 1374{ 1375 skippedEntityHandler = handler; 1376} 1377 |
1264void | 1378void XMLCALL |
1265XML_SetUnknownEncodingHandler(XML_Parser parser, 1266 XML_UnknownEncodingHandler handler, 1267 void *data) 1268{ 1269 unknownEncodingHandler = handler; 1270 unknownEncodingHandlerData = data; 1271} 1272 | 1379XML_SetUnknownEncodingHandler(XML_Parser parser, 1380 XML_UnknownEncodingHandler handler, 1381 void *data) 1382{ 1383 unknownEncodingHandler = handler; 1384 unknownEncodingHandlerData = data; 1385} 1386 |
1273void | 1387void XMLCALL |
1274XML_SetElementDeclHandler(XML_Parser parser, 1275 XML_ElementDeclHandler eldecl) 1276{ 1277 elementDeclHandler = eldecl; 1278} 1279 | 1388XML_SetElementDeclHandler(XML_Parser parser, 1389 XML_ElementDeclHandler eldecl) 1390{ 1391 elementDeclHandler = eldecl; 1392} 1393 |
1280void | 1394void XMLCALL |
1281XML_SetAttlistDeclHandler(XML_Parser parser, 1282 XML_AttlistDeclHandler attdecl) 1283{ 1284 attlistDeclHandler = attdecl; 1285} 1286 | 1395XML_SetAttlistDeclHandler(XML_Parser parser, 1396 XML_AttlistDeclHandler attdecl) 1397{ 1398 attlistDeclHandler = attdecl; 1399} 1400 |
1287void | 1401void XMLCALL |
1288XML_SetEntityDeclHandler(XML_Parser parser, 1289 XML_EntityDeclHandler handler) 1290{ 1291 entityDeclHandler = handler; 1292} 1293 | 1402XML_SetEntityDeclHandler(XML_Parser parser, 1403 XML_EntityDeclHandler handler) 1404{ 1405 entityDeclHandler = handler; 1406} 1407 |
1294void | 1408void XMLCALL |
1295XML_SetXmlDeclHandler(XML_Parser parser, 1296 XML_XmlDeclHandler handler) { 1297 xmlDeclHandler = handler; 1298} 1299 | 1409XML_SetXmlDeclHandler(XML_Parser parser, 1410 XML_XmlDeclHandler handler) { 1411 xmlDeclHandler = handler; 1412} 1413 |
1300int | 1414int XMLCALL |
1301XML_SetParamEntityParsing(XML_Parser parser, 1302 enum XML_ParamEntityParsing peParsing) 1303{ 1304 /* block after XML_Parse()/XML_ParseBuffer() has been called */ | 1415XML_SetParamEntityParsing(XML_Parser parser, 1416 enum XML_ParamEntityParsing peParsing) 1417{ 1418 /* block after XML_Parse()/XML_ParseBuffer() has been called */ |
1305 if (parsing) | 1419 if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) |
1306 return 0; 1307#ifdef XML_DTD 1308 paramEntityParsing = peParsing; 1309 return 1; 1310#else 1311 return peParsing == XML_PARAM_ENTITY_PARSING_NEVER; 1312#endif 1313} 1314 | 1420 return 0; 1421#ifdef XML_DTD 1422 paramEntityParsing = peParsing; 1423 return 1; 1424#else 1425 return peParsing == XML_PARAM_ENTITY_PARSING_NEVER; 1426#endif 1427} 1428 |
1315enum XML_Status | 1429enum XML_Status XMLCALL |
1316XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) 1317{ | 1430XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) 1431{ |
1432 switch (ps_parsing) { 1433 case XML_SUSPENDED: 1434 errorCode = XML_ERROR_SUSPENDED; 1435 return XML_STATUS_ERROR; 1436 case XML_FINISHED: 1437 errorCode = XML_ERROR_FINISHED; 1438 return XML_STATUS_ERROR; 1439 default: 1440 ps_parsing = XML_PARSING; 1441 } 1442 |
|
1318 if (len == 0) { | 1443 if (len == 0) { |
1444 ps_finalBuffer = (XML_Bool)isFinal; |
|
1319 if (!isFinal) 1320 return XML_STATUS_OK; 1321 positionPtr = bufferPtr; | 1445 if (!isFinal) 1446 return XML_STATUS_OK; 1447 positionPtr = bufferPtr; |
1322 errorCode = processor(parser, bufferPtr, parseEndPtr = bufferEnd, 0); 1323 if (errorCode == XML_ERROR_NONE) 1324 return XML_STATUS_OK; | 1448 parseEndPtr = bufferEnd; 1449 1450 /* If data are left over from last buffer, and we now know that these 1451 data are the final chunk of input, then we have to check them again 1452 to detect errors based on that fact. 1453 */ 1454 errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr); 1455 1456 if (errorCode == XML_ERROR_NONE) { 1457 switch (ps_parsing) { 1458 case XML_SUSPENDED: 1459 XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); 1460 positionPtr = bufferPtr; 1461 return XML_STATUS_SUSPENDED; 1462 case XML_INITIALIZED: 1463 case XML_PARSING: 1464 ps_parsing = XML_FINISHED; 1465 /* fall through */ 1466 default: 1467 return XML_STATUS_OK; 1468 } 1469 } |
1325 eventEndPtr = eventPtr; 1326 processor = errorProcessor; 1327 return XML_STATUS_ERROR; 1328 } 1329#ifndef XML_CONTEXT_BYTES 1330 else if (bufferPtr == bufferEnd) { 1331 const char *end; 1332 int nLeftOver; | 1470 eventEndPtr = eventPtr; 1471 processor = errorProcessor; 1472 return XML_STATUS_ERROR; 1473 } 1474#ifndef XML_CONTEXT_BYTES 1475 else if (bufferPtr == bufferEnd) { 1476 const char *end; 1477 int nLeftOver; |
1478 enum XML_Error result; |
|
1333 parseEndByteIndex += len; 1334 positionPtr = s; | 1479 parseEndByteIndex += len; 1480 positionPtr = s; |
1335 if (isFinal) { 1336 errorCode = processor(parser, s, parseEndPtr = s + len, 0); 1337 if (errorCode == XML_ERROR_NONE) 1338 return XML_STATUS_OK; 1339 eventEndPtr = eventPtr; 1340 processor = errorProcessor; 1341 return XML_STATUS_ERROR; 1342 } | 1481 ps_finalBuffer = (XML_Bool)isFinal; 1482 |
1343 errorCode = processor(parser, s, parseEndPtr = s + len, &end); | 1483 errorCode = processor(parser, s, parseEndPtr = s + len, &end); |
1484 |
|
1344 if (errorCode != XML_ERROR_NONE) { 1345 eventEndPtr = eventPtr; 1346 processor = errorProcessor; 1347 return XML_STATUS_ERROR; 1348 } | 1485 if (errorCode != XML_ERROR_NONE) { 1486 eventEndPtr = eventPtr; 1487 processor = errorProcessor; 1488 return XML_STATUS_ERROR; 1489 } |
1490 else { 1491 switch (ps_parsing) { 1492 case XML_SUSPENDED: 1493 result = XML_STATUS_SUSPENDED; 1494 break; 1495 case XML_INITIALIZED: 1496 case XML_PARSING: 1497 result = XML_STATUS_OK; 1498 if (isFinal) { 1499 ps_parsing = XML_FINISHED; 1500 return result; 1501 } 1502 } 1503 } 1504 |
|
1349 XmlUpdatePosition(encoding, positionPtr, end, &position); 1350 nLeftOver = s + len - end; 1351 if (nLeftOver) { 1352 if (buffer == NULL || nLeftOver > bufferLim - buffer) { 1353 /* FIXME avoid integer overflow */ 1354 char *temp; | 1505 XmlUpdatePosition(encoding, positionPtr, end, &position); 1506 nLeftOver = s + len - end; 1507 if (nLeftOver) { 1508 if (buffer == NULL || nLeftOver > bufferLim - buffer) { 1509 /* FIXME avoid integer overflow */ 1510 char *temp; |
1355 temp = buffer == NULL ? MALLOC(len * 2) : REALLOC(buffer, len * 2); | 1511 temp = (buffer == NULL 1512 ? (char *)MALLOC(len * 2) 1513 : (char *)REALLOC(buffer, len * 2)); |
1356 if (temp == NULL) { 1357 errorCode = XML_ERROR_NO_MEMORY; 1358 return XML_STATUS_ERROR; 1359 } 1360 buffer = temp; 1361 if (!buffer) { 1362 errorCode = XML_ERROR_NO_MEMORY; 1363 eventPtr = eventEndPtr = NULL; 1364 processor = errorProcessor; 1365 return XML_STATUS_ERROR; 1366 } 1367 bufferLim = buffer + len * 2; 1368 } 1369 memcpy(buffer, end, nLeftOver); | 1514 if (temp == NULL) { 1515 errorCode = XML_ERROR_NO_MEMORY; 1516 return XML_STATUS_ERROR; 1517 } 1518 buffer = temp; 1519 if (!buffer) { 1520 errorCode = XML_ERROR_NO_MEMORY; 1521 eventPtr = eventEndPtr = NULL; 1522 processor = errorProcessor; 1523 return XML_STATUS_ERROR; 1524 } 1525 bufferLim = buffer + len * 2; 1526 } 1527 memcpy(buffer, end, nLeftOver); |
1370 bufferPtr = buffer; 1371 bufferEnd = buffer + nLeftOver; | |
1372 } | 1528 } |
1373 return XML_STATUS_OK; | 1529 bufferPtr = buffer; 1530 bufferEnd = buffer + nLeftOver; 1531 positionPtr = bufferPtr; 1532 parseEndPtr = bufferEnd; 1533 eventPtr = bufferPtr; 1534 eventEndPtr = bufferPtr; 1535 return result; |
1374 } 1375#endif /* not defined XML_CONTEXT_BYTES */ 1376 else { 1377 void *buff = XML_GetBuffer(parser, len); 1378 if (buff == NULL) 1379 return XML_STATUS_ERROR; 1380 else { 1381 memcpy(buff, s, len); 1382 return XML_ParseBuffer(parser, len, isFinal); 1383 } 1384 } 1385} 1386 | 1536 } 1537#endif /* not defined XML_CONTEXT_BYTES */ 1538 else { 1539 void *buff = XML_GetBuffer(parser, len); 1540 if (buff == NULL) 1541 return XML_STATUS_ERROR; 1542 else { 1543 memcpy(buff, s, len); 1544 return XML_ParseBuffer(parser, len, isFinal); 1545 } 1546 } 1547} 1548 |
1387enum XML_Status | 1549enum XML_Status XMLCALL |
1388XML_ParseBuffer(XML_Parser parser, int len, int isFinal) 1389{ | 1550XML_ParseBuffer(XML_Parser parser, int len, int isFinal) 1551{ |
1390 const char *start = bufferPtr; | 1552 const char *start; 1553 enum XML_Status result = XML_STATUS_OK; 1554 1555 switch (ps_parsing) { 1556 case XML_SUSPENDED: 1557 errorCode = XML_ERROR_SUSPENDED; 1558 return XML_STATUS_ERROR; 1559 case XML_FINISHED: 1560 errorCode = XML_ERROR_FINISHED; 1561 return XML_STATUS_ERROR; 1562 default: 1563 ps_parsing = XML_PARSING; 1564 } 1565 1566 start = bufferPtr; |
1391 positionPtr = start; 1392 bufferEnd += len; | 1567 positionPtr = start; 1568 bufferEnd += len; |
1569 parseEndPtr = bufferEnd; |
|
1393 parseEndByteIndex += len; | 1570 parseEndByteIndex += len; |
1394 errorCode = processor(parser, start, parseEndPtr = bufferEnd, 1395 isFinal ? (const char **)NULL : &bufferPtr); 1396 if (errorCode == XML_ERROR_NONE) { 1397 if (!isFinal) 1398 XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); 1399 return XML_STATUS_OK; 1400 } 1401 else { | 1571 ps_finalBuffer = (XML_Bool)isFinal; 1572 1573 errorCode = processor(parser, start, parseEndPtr, &bufferPtr); 1574 1575 if (errorCode != XML_ERROR_NONE) { |
1402 eventEndPtr = eventPtr; 1403 processor = errorProcessor; 1404 return XML_STATUS_ERROR; 1405 } | 1576 eventEndPtr = eventPtr; 1577 processor = errorProcessor; 1578 return XML_STATUS_ERROR; 1579 } |
1580 else { 1581 switch (ps_parsing) { 1582 case XML_SUSPENDED: 1583 result = XML_STATUS_SUSPENDED; 1584 break; 1585 case XML_INITIALIZED: 1586 case XML_PARSING: 1587 if (isFinal) { 1588 ps_parsing = XML_FINISHED; 1589 return result; 1590 } 1591 default: ; /* should not happen */ 1592 } 1593 } 1594 1595 XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); 1596 positionPtr = bufferPtr; 1597 return result; |
|
1406} 1407 | 1598} 1599 |
1408void * | 1600void * XMLCALL |
1409XML_GetBuffer(XML_Parser parser, int len) 1410{ | 1601XML_GetBuffer(XML_Parser parser, int len) 1602{ |
1603 switch (ps_parsing) { 1604 case XML_SUSPENDED: 1605 errorCode = XML_ERROR_SUSPENDED; 1606 return NULL; 1607 case XML_FINISHED: 1608 errorCode = XML_ERROR_FINISHED; 1609 return NULL; 1610 default: ; 1611 } 1612 |
|
1411 if (len > bufferLim - bufferEnd) { 1412 /* FIXME avoid integer overflow */ | 1613 if (len > bufferLim - bufferEnd) { 1614 /* FIXME avoid integer overflow */ |
1413 int neededSize = len + (bufferEnd - bufferPtr); | 1615 int neededSize = len + (int)(bufferEnd - bufferPtr); |
1414#ifdef XML_CONTEXT_BYTES | 1616#ifdef XML_CONTEXT_BYTES |
1415 int keep = bufferPtr - buffer; | 1617 int keep = (int)(bufferPtr - buffer); |
1416 1417 if (keep > XML_CONTEXT_BYTES) 1418 keep = XML_CONTEXT_BYTES; 1419 neededSize += keep; 1420#endif /* defined XML_CONTEXT_BYTES */ 1421 if (neededSize <= bufferLim - buffer) { 1422#ifdef XML_CONTEXT_BYTES 1423 if (keep < bufferPtr - buffer) { | 1618 1619 if (keep > XML_CONTEXT_BYTES) 1620 keep = XML_CONTEXT_BYTES; 1621 neededSize += keep; 1622#endif /* defined XML_CONTEXT_BYTES */ 1623 if (neededSize <= bufferLim - buffer) { 1624#ifdef XML_CONTEXT_BYTES 1625 if (keep < bufferPtr - buffer) { |
1424 int offset = (bufferPtr - buffer) - keep; | 1626 int offset = (int)(bufferPtr - buffer) - keep; |
1425 memmove(buffer, &buffer[offset], bufferEnd - bufferPtr + keep); 1426 bufferEnd -= offset; 1427 bufferPtr -= offset; 1428 } 1429#else 1430 memmove(buffer, bufferPtr, bufferEnd - bufferPtr); 1431 bufferEnd = buffer + (bufferEnd - bufferPtr); 1432 bufferPtr = buffer; 1433#endif /* not defined XML_CONTEXT_BYTES */ 1434 } 1435 else { 1436 char *newBuf; | 1627 memmove(buffer, &buffer[offset], bufferEnd - bufferPtr + keep); 1628 bufferEnd -= offset; 1629 bufferPtr -= offset; 1630 } 1631#else 1632 memmove(buffer, bufferPtr, bufferEnd - bufferPtr); 1633 bufferEnd = buffer + (bufferEnd - bufferPtr); 1634 bufferPtr = buffer; 1635#endif /* not defined XML_CONTEXT_BYTES */ 1636 } 1637 else { 1638 char *newBuf; |
1437 int bufferSize = bufferLim - bufferPtr; | 1639 int bufferSize = (int)(bufferLim - bufferPtr); |
1438 if (bufferSize == 0) 1439 bufferSize = INIT_BUFFER_SIZE; 1440 do { 1441 bufferSize *= 2; 1442 } while (bufferSize < neededSize); | 1640 if (bufferSize == 0) 1641 bufferSize = INIT_BUFFER_SIZE; 1642 do { 1643 bufferSize *= 2; 1644 } while (bufferSize < neededSize); |
1443 newBuf = MALLOC(bufferSize); | 1645 newBuf = (char *)MALLOC(bufferSize); |
1444 if (newBuf == 0) { 1445 errorCode = XML_ERROR_NO_MEMORY; 1446 return NULL; 1447 } 1448 bufferLim = newBuf + bufferSize; 1449#ifdef XML_CONTEXT_BYTES 1450 if (bufferPtr) { | 1646 if (newBuf == 0) { 1647 errorCode = XML_ERROR_NO_MEMORY; 1648 return NULL; 1649 } 1650 bufferLim = newBuf + bufferSize; 1651#ifdef XML_CONTEXT_BYTES 1652 if (bufferPtr) { |
1451 int keep = bufferPtr - buffer; | 1653 int keep = (int)(bufferPtr - buffer); |
1452 if (keep > XML_CONTEXT_BYTES) 1453 keep = XML_CONTEXT_BYTES; 1454 memcpy(newBuf, &bufferPtr[-keep], bufferEnd - bufferPtr + keep); 1455 FREE(buffer); 1456 buffer = newBuf; 1457 bufferEnd = buffer + (bufferEnd - bufferPtr) + keep; 1458 bufferPtr = buffer + keep; 1459 } --- 9 unchanged lines hidden (view full) --- 1469 bufferEnd = newBuf + (bufferEnd - bufferPtr); 1470 bufferPtr = buffer = newBuf; 1471#endif /* not defined XML_CONTEXT_BYTES */ 1472 } 1473 } 1474 return bufferEnd; 1475} 1476 | 1654 if (keep > XML_CONTEXT_BYTES) 1655 keep = XML_CONTEXT_BYTES; 1656 memcpy(newBuf, &bufferPtr[-keep], bufferEnd - bufferPtr + keep); 1657 FREE(buffer); 1658 buffer = newBuf; 1659 bufferEnd = buffer + (bufferEnd - bufferPtr) + keep; 1660 bufferPtr = buffer + keep; 1661 } --- 9 unchanged lines hidden (view full) --- 1671 bufferEnd = newBuf + (bufferEnd - bufferPtr); 1672 bufferPtr = buffer = newBuf; 1673#endif /* not defined XML_CONTEXT_BYTES */ 1674 } 1675 } 1676 return bufferEnd; 1677} 1678 |
1477enum XML_Error | 1679enum XML_Status XMLCALL 1680XML_StopParser(XML_Parser parser, XML_Bool resumable) 1681{ 1682 switch (ps_parsing) { 1683 case XML_SUSPENDED: 1684 if (resumable) { 1685 errorCode = XML_ERROR_SUSPENDED; 1686 return XML_STATUS_ERROR; 1687 } 1688 ps_parsing = XML_FINISHED; 1689 break; 1690 case XML_FINISHED: 1691 errorCode = XML_ERROR_FINISHED; 1692 return XML_STATUS_ERROR; 1693 default: 1694 if (resumable) { 1695#ifdef XML_DTD 1696 if (isParamEntity) { 1697 errorCode = XML_ERROR_SUSPEND_PE; 1698 return XML_STATUS_ERROR; 1699 } 1700#endif 1701 ps_parsing = XML_SUSPENDED; 1702 } 1703 else 1704 ps_parsing = XML_FINISHED; 1705 } 1706 return XML_STATUS_OK; 1707} 1708 1709enum XML_Status XMLCALL 1710XML_ResumeParser(XML_Parser parser) 1711{ 1712 enum XML_Status result = XML_STATUS_OK; 1713 1714 if (ps_parsing != XML_SUSPENDED) { 1715 errorCode = XML_ERROR_NOT_SUSPENDED; 1716 return XML_STATUS_ERROR; 1717 } 1718 ps_parsing = XML_PARSING; 1719 1720 errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr); 1721 1722 if (errorCode != XML_ERROR_NONE) { 1723 eventEndPtr = eventPtr; 1724 processor = errorProcessor; 1725 return XML_STATUS_ERROR; 1726 } 1727 else { 1728 switch (ps_parsing) { 1729 case XML_SUSPENDED: 1730 result = XML_STATUS_SUSPENDED; 1731 break; 1732 case XML_INITIALIZED: 1733 case XML_PARSING: 1734 if (ps_finalBuffer) { 1735 ps_parsing = XML_FINISHED; 1736 return result; 1737 } 1738 default: ; 1739 } 1740 } 1741 1742 XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); 1743 positionPtr = bufferPtr; 1744 return result; 1745} 1746 1747void XMLCALL 1748XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status) 1749{ 1750 assert(status != NULL); 1751 *status = parser->m_parsingStatus; 1752} 1753 1754enum XML_Error XMLCALL |
1478XML_GetErrorCode(XML_Parser parser) 1479{ 1480 return errorCode; 1481} 1482 | 1755XML_GetErrorCode(XML_Parser parser) 1756{ 1757 return errorCode; 1758} 1759 |
1483long | 1760XML_Index XMLCALL |
1484XML_GetCurrentByteIndex(XML_Parser parser) 1485{ 1486 if (eventPtr) 1487 return parseEndByteIndex - (parseEndPtr - eventPtr); 1488 return -1; 1489} 1490 | 1761XML_GetCurrentByteIndex(XML_Parser parser) 1762{ 1763 if (eventPtr) 1764 return parseEndByteIndex - (parseEndPtr - eventPtr); 1765 return -1; 1766} 1767 |
1491int | 1768int XMLCALL |
1492XML_GetCurrentByteCount(XML_Parser parser) 1493{ 1494 if (eventEndPtr && eventPtr) | 1769XML_GetCurrentByteCount(XML_Parser parser) 1770{ 1771 if (eventEndPtr && eventPtr) |
1495 return eventEndPtr - eventPtr; | 1772 return (int)(eventEndPtr - eventPtr); |
1496 return 0; 1497} 1498 | 1773 return 0; 1774} 1775 |
1499const char * | 1776const char * XMLCALL |
1500XML_GetInputContext(XML_Parser parser, int *offset, int *size) 1501{ 1502#ifdef XML_CONTEXT_BYTES 1503 if (eventPtr && buffer) { | 1777XML_GetInputContext(XML_Parser parser, int *offset, int *size) 1778{ 1779#ifdef XML_CONTEXT_BYTES 1780 if (eventPtr && buffer) { |
1504 *offset = eventPtr - buffer; 1505 *size = bufferEnd - buffer; | 1781 *offset = (int)(eventPtr - buffer); 1782 *size = (int)(bufferEnd - buffer); |
1506 return buffer; 1507 } 1508#endif /* defined XML_CONTEXT_BYTES */ 1509 return (char *) 0; 1510} 1511 | 1783 return buffer; 1784 } 1785#endif /* defined XML_CONTEXT_BYTES */ 1786 return (char *) 0; 1787} 1788 |
1512int | 1789XML_Size XMLCALL |
1513XML_GetCurrentLineNumber(XML_Parser parser) 1514{ | 1790XML_GetCurrentLineNumber(XML_Parser parser) 1791{ |
1515 if (eventPtr) { | 1792 if (eventPtr && eventPtr >= positionPtr) { |
1516 XmlUpdatePosition(encoding, positionPtr, eventPtr, &position); 1517 positionPtr = eventPtr; 1518 } 1519 return position.lineNumber + 1; 1520} 1521 | 1793 XmlUpdatePosition(encoding, positionPtr, eventPtr, &position); 1794 positionPtr = eventPtr; 1795 } 1796 return position.lineNumber + 1; 1797} 1798 |
1522int | 1799XML_Size XMLCALL |
1523XML_GetCurrentColumnNumber(XML_Parser parser) 1524{ | 1800XML_GetCurrentColumnNumber(XML_Parser parser) 1801{ |
1525 if (eventPtr) { | 1802 if (eventPtr && eventPtr >= positionPtr) { |
1526 XmlUpdatePosition(encoding, positionPtr, eventPtr, &position); 1527 positionPtr = eventPtr; 1528 } 1529 return position.columnNumber; 1530} 1531 | 1803 XmlUpdatePosition(encoding, positionPtr, eventPtr, &position); 1804 positionPtr = eventPtr; 1805 } 1806 return position.columnNumber; 1807} 1808 |
1532void | 1809void XMLCALL 1810XML_FreeContentModel(XML_Parser parser, XML_Content *model) 1811{ 1812 FREE(model); 1813} 1814 1815void * XMLCALL 1816XML_MemMalloc(XML_Parser parser, size_t size) 1817{ 1818 return MALLOC(size); 1819} 1820 1821void * XMLCALL 1822XML_MemRealloc(XML_Parser parser, void *ptr, size_t size) 1823{ 1824 return REALLOC(ptr, size); 1825} 1826 1827void XMLCALL 1828XML_MemFree(XML_Parser parser, void *ptr) 1829{ 1830 FREE(ptr); 1831} 1832 1833void XMLCALL |
1533XML_DefaultCurrent(XML_Parser parser) 1534{ 1535 if (defaultHandler) { 1536 if (openInternalEntities) 1537 reportDefault(parser, 1538 internalEncoding, 1539 openInternalEntities->internalEventPtr, 1540 openInternalEntities->internalEventEndPtr); 1541 else 1542 reportDefault(parser, encoding, eventPtr, eventEndPtr); 1543 } 1544} 1545 | 1834XML_DefaultCurrent(XML_Parser parser) 1835{ 1836 if (defaultHandler) { 1837 if (openInternalEntities) 1838 reportDefault(parser, 1839 internalEncoding, 1840 openInternalEntities->internalEventPtr, 1841 openInternalEntities->internalEventEndPtr); 1842 else 1843 reportDefault(parser, encoding, eventPtr, eventEndPtr); 1844 } 1845} 1846 |
1546const XML_LChar * | 1847const XML_LChar * XMLCALL |
1547XML_ErrorString(enum XML_Error code) 1548{ | 1848XML_ErrorString(enum XML_Error code) 1849{ |
1549 static const XML_LChar *message[] = { | 1850 static const XML_LChar* const message[] = { |
1550 0, 1551 XML_L("out of memory"), 1552 XML_L("syntax error"), 1553 XML_L("no element found"), 1554 XML_L("not well-formed (invalid token)"), 1555 XML_L("unclosed token"), 1556 XML_L("partial character"), 1557 XML_L("mismatched tag"), 1558 XML_L("duplicate attribute"), 1559 XML_L("junk after document element"), 1560 XML_L("illegal parameter entity reference"), 1561 XML_L("undefined entity"), 1562 XML_L("recursive entity reference"), 1563 XML_L("asynchronous entity"), 1564 XML_L("reference to invalid character number"), 1565 XML_L("reference to binary entity"), 1566 XML_L("reference to external entity in attribute"), | 1851 0, 1852 XML_L("out of memory"), 1853 XML_L("syntax error"), 1854 XML_L("no element found"), 1855 XML_L("not well-formed (invalid token)"), 1856 XML_L("unclosed token"), 1857 XML_L("partial character"), 1858 XML_L("mismatched tag"), 1859 XML_L("duplicate attribute"), 1860 XML_L("junk after document element"), 1861 XML_L("illegal parameter entity reference"), 1862 XML_L("undefined entity"), 1863 XML_L("recursive entity reference"), 1864 XML_L("asynchronous entity"), 1865 XML_L("reference to invalid character number"), 1866 XML_L("reference to binary entity"), 1867 XML_L("reference to external entity in attribute"), |
1567 XML_L("xml declaration not at start of external entity"), | 1868 XML_L("XML or text declaration not at start of entity"), |
1568 XML_L("unknown encoding"), 1569 XML_L("encoding specified in XML declaration is incorrect"), 1570 XML_L("unclosed CDATA section"), 1571 XML_L("error in processing external entity reference"), 1572 XML_L("document is not standalone"), 1573 XML_L("unexpected parser state - please send a bug report"), 1574 XML_L("entity declared in parameter entity"), 1575 XML_L("requested feature requires XML_DTD support in Expat"), | 1869 XML_L("unknown encoding"), 1870 XML_L("encoding specified in XML declaration is incorrect"), 1871 XML_L("unclosed CDATA section"), 1872 XML_L("error in processing external entity reference"), 1873 XML_L("document is not standalone"), 1874 XML_L("unexpected parser state - please send a bug report"), 1875 XML_L("entity declared in parameter entity"), 1876 XML_L("requested feature requires XML_DTD support in Expat"), |
1576 XML_L("cannot change setting once parsing has begun") | 1877 XML_L("cannot change setting once parsing has begun"), 1878 XML_L("unbound prefix"), 1879 XML_L("must not undeclare prefix"), 1880 XML_L("incomplete markup in parameter entity"), 1881 XML_L("XML declaration not well-formed"), 1882 XML_L("text declaration not well-formed"), 1883 XML_L("illegal character(s) in public id"), 1884 XML_L("parser suspended"), 1885 XML_L("parser not suspended"), 1886 XML_L("parsing aborted"), 1887 XML_L("parsing finished"), 1888 XML_L("cannot suspend in external parameter entity"), 1889 XML_L("reserved prefix (xml) must not be undeclared or bound to another namespace name"), 1890 XML_L("reserved prefix (xmlns) must not be declared or undeclared"), 1891 XML_L("prefix must not be bound to one of the reserved namespace names") |
1577 }; 1578 if (code > 0 && code < sizeof(message)/sizeof(message[0])) 1579 return message[code]; 1580 return NULL; 1581} 1582 | 1892 }; 1893 if (code > 0 && code < sizeof(message)/sizeof(message[0])) 1894 return message[code]; 1895 return NULL; 1896} 1897 |
1583const XML_LChar * | 1898const XML_LChar * XMLCALL |
1584XML_ExpatVersion(void) { 1585 1586 /* V1 is used to string-ize the version number. However, it would 1587 string-ize the actual version macro *names* unless we get them 1588 substituted before being passed to V1. CPP is defined to expand 1589 a macro, then rescan for more expansions. Thus, we use V2 to expand 1590 the version macros, then CPP will expand the resulting V1() macro 1591 with the correct numerals. */ 1592 /* ### I'm assuming cpp is portable in this respect... */ 1593 1594#define V1(a,b,c) XML_L(#a)XML_L(".")XML_L(#b)XML_L(".")XML_L(#c) 1595#define V2(a,b,c) XML_L("expat_")V1(a,b,c) 1596 1597 return V2(XML_MAJOR_VERSION, XML_MINOR_VERSION, XML_MICRO_VERSION); 1598 1599#undef V1 1600#undef V2 1601} 1602 | 1899XML_ExpatVersion(void) { 1900 1901 /* V1 is used to string-ize the version number. However, it would 1902 string-ize the actual version macro *names* unless we get them 1903 substituted before being passed to V1. CPP is defined to expand 1904 a macro, then rescan for more expansions. Thus, we use V2 to expand 1905 the version macros, then CPP will expand the resulting V1() macro 1906 with the correct numerals. */ 1907 /* ### I'm assuming cpp is portable in this respect... */ 1908 1909#define V1(a,b,c) XML_L(#a)XML_L(".")XML_L(#b)XML_L(".")XML_L(#c) 1910#define V2(a,b,c) XML_L("expat_")V1(a,b,c) 1911 1912 return V2(XML_MAJOR_VERSION, XML_MINOR_VERSION, XML_MICRO_VERSION); 1913 1914#undef V1 1915#undef V2 1916} 1917 |
1603XML_Expat_Version | 1918XML_Expat_Version XMLCALL |
1604XML_ExpatVersionInfo(void) 1605{ 1606 XML_Expat_Version version; 1607 1608 version.major = XML_MAJOR_VERSION; 1609 version.minor = XML_MINOR_VERSION; 1610 version.micro = XML_MICRO_VERSION; 1611 1612 return version; 1613} 1614 | 1919XML_ExpatVersionInfo(void) 1920{ 1921 XML_Expat_Version version; 1922 1923 version.major = XML_MAJOR_VERSION; 1924 version.minor = XML_MINOR_VERSION; 1925 version.micro = XML_MICRO_VERSION; 1926 1927 return version; 1928} 1929 |
1615const XML_Feature * | 1930const XML_Feature * XMLCALL |
1616XML_GetFeatureList(void) 1617{ | 1931XML_GetFeatureList(void) 1932{ |
1618 static XML_Feature features[] = { 1619 {XML_FEATURE_SIZEOF_XML_CHAR, XML_L("sizeof(XML_Char)")}, 1620 {XML_FEATURE_SIZEOF_XML_LCHAR, XML_L("sizeof(XML_LChar)")}, | 1933 static const XML_Feature features[] = { 1934 {XML_FEATURE_SIZEOF_XML_CHAR, XML_L("sizeof(XML_Char)"), 1935 sizeof(XML_Char)}, 1936 {XML_FEATURE_SIZEOF_XML_LCHAR, XML_L("sizeof(XML_LChar)"), 1937 sizeof(XML_LChar)}, |
1621#ifdef XML_UNICODE | 1938#ifdef XML_UNICODE |
1622 {XML_FEATURE_UNICODE, XML_L("XML_UNICODE")}, | 1939 {XML_FEATURE_UNICODE, XML_L("XML_UNICODE"), 0}, |
1623#endif 1624#ifdef XML_UNICODE_WCHAR_T | 1940#endif 1941#ifdef XML_UNICODE_WCHAR_T |
1625 {XML_FEATURE_UNICODE_WCHAR_T, XML_L("XML_UNICODE_WCHAR_T")}, | 1942 {XML_FEATURE_UNICODE_WCHAR_T, XML_L("XML_UNICODE_WCHAR_T"), 0}, |
1626#endif 1627#ifdef XML_DTD | 1943#endif 1944#ifdef XML_DTD |
1628 {XML_FEATURE_DTD, XML_L("XML_DTD")}, | 1945 {XML_FEATURE_DTD, XML_L("XML_DTD"), 0}, |
1629#endif 1630#ifdef XML_CONTEXT_BYTES 1631 {XML_FEATURE_CONTEXT_BYTES, XML_L("XML_CONTEXT_BYTES"), 1632 XML_CONTEXT_BYTES}, 1633#endif 1634#ifdef XML_MIN_SIZE | 1946#endif 1947#ifdef XML_CONTEXT_BYTES 1948 {XML_FEATURE_CONTEXT_BYTES, XML_L("XML_CONTEXT_BYTES"), 1949 XML_CONTEXT_BYTES}, 1950#endif 1951#ifdef XML_MIN_SIZE |
1635 {XML_FEATURE_MIN_SIZE, XML_L("XML_MIN_SIZE")}, | 1952 {XML_FEATURE_MIN_SIZE, XML_L("XML_MIN_SIZE"), 0}, |
1636#endif | 1953#endif |
1637 {XML_FEATURE_END, NULL} | 1954#ifdef XML_NS 1955 {XML_FEATURE_NS, XML_L("XML_NS"), 0}, 1956#endif 1957#ifdef XML_LARGE_SIZE 1958 {XML_FEATURE_LARGE_SIZE, XML_L("XML_LARGE_SIZE"), 0}, 1959#endif 1960 {XML_FEATURE_END, NULL, 0} |
1638 }; 1639 | 1961 }; 1962 |
1640 features[0].value = sizeof(XML_Char); 1641 features[1].value = sizeof(XML_LChar); | |
1642 return features; 1643} 1644 1645/* Initially tag->rawName always points into the parse buffer; 1646 for those TAG instances opened while the current parse buffer was 1647 processed, and not yet closed, we need to store tag->rawName in a more 1648 permanent location, since the parse buffer is about to be discarded. 1649*/ | 1963 return features; 1964} 1965 1966/* Initially tag->rawName always points into the parse buffer; 1967 for those TAG instances opened while the current parse buffer was 1968 processed, and not yet closed, we need to store tag->rawName in a more 1969 permanent location, since the parse buffer is about to be discarded. 1970*/ |
1650static XML_Bool FASTCALL | 1971static XML_Bool |
1651storeRawNames(XML_Parser parser) 1652{ 1653 TAG *tag = tagStack; 1654 while (tag) { 1655 int bufSize; 1656 int nameLen = sizeof(XML_Char) * (tag->name.strLen + 1); 1657 char *rawNameBuf = tag->buf + nameLen; 1658 /* Stop if already stored. Since tagStack is a stack, we can stop 1659 at the first entry that has already been copied; everything 1660 below it in the stack is already been accounted for in a 1661 previous call to this function. 1662 */ | 1972storeRawNames(XML_Parser parser) 1973{ 1974 TAG *tag = tagStack; 1975 while (tag) { 1976 int bufSize; 1977 int nameLen = sizeof(XML_Char) * (tag->name.strLen + 1); 1978 char *rawNameBuf = tag->buf + nameLen; 1979 /* Stop if already stored. Since tagStack is a stack, we can stop 1980 at the first entry that has already been copied; everything 1981 below it in the stack is already been accounted for in a 1982 previous call to this function. 1983 */ |
1663 if (tag->rawName == rawNameBuf) | 1984 if (tag->rawName == rawNameBuf) |
1664 break; 1665 /* For re-use purposes we need to ensure that the 1666 size of tag->buf is a multiple of sizeof(XML_Char). 1667 */ 1668 bufSize = nameLen + ROUND_UP(tag->rawNameLength, sizeof(XML_Char)); 1669 if (bufSize > tag->bufEnd - tag->buf) { | 1985 break; 1986 /* For re-use purposes we need to ensure that the 1987 size of tag->buf is a multiple of sizeof(XML_Char). 1988 */ 1989 bufSize = nameLen + ROUND_UP(tag->rawNameLength, sizeof(XML_Char)); 1990 if (bufSize > tag->bufEnd - tag->buf) { |
1670 char *temp = REALLOC(tag->buf, bufSize); | 1991 char *temp = (char *)REALLOC(tag->buf, bufSize); |
1671 if (temp == NULL) 1672 return XML_FALSE; | 1992 if (temp == NULL) 1993 return XML_FALSE; |
1994 /* if tag->name.str points to tag->buf (only when namespace 1995 processing is off) then we have to update it 1996 */ 1997 if (tag->name.str == (XML_Char *)tag->buf) 1998 tag->name.str = (XML_Char *)temp; 1999 /* if tag->name.localPart is set (when namespace processing is on) 2000 then update it as well, since it will always point into tag->buf 2001 */ 2002 if (tag->name.localPart) 2003 tag->name.localPart = (XML_Char *)temp + (tag->name.localPart - 2004 (XML_Char *)tag->buf); |
|
1673 tag->buf = temp; | 2005 tag->buf = temp; |
1674 tag->name.str = (XML_Char *)temp; | |
1675 tag->bufEnd = temp + bufSize; 1676 rawNameBuf = temp + nameLen; 1677 } 1678 memcpy(rawNameBuf, tag->rawName, tag->rawNameLength); 1679 tag->rawName = rawNameBuf; 1680 tag = tag->parent; 1681 } 1682 return XML_TRUE; 1683} 1684 | 2006 tag->bufEnd = temp + bufSize; 2007 rawNameBuf = temp + nameLen; 2008 } 2009 memcpy(rawNameBuf, tag->rawName, tag->rawNameLength); 2010 tag->rawName = rawNameBuf; 2011 tag = tag->parent; 2012 } 2013 return XML_TRUE; 2014} 2015 |
1685static enum XML_Error FASTCALL | 2016static enum XML_Error PTRCALL |
1686contentProcessor(XML_Parser parser, 1687 const char *start, 1688 const char *end, 1689 const char **endPtr) 1690{ | 2017contentProcessor(XML_Parser parser, 2018 const char *start, 2019 const char *end, 2020 const char **endPtr) 2021{ |
1691 enum XML_Error result = 1692 doContent(parser, 0, encoding, start, end, endPtr); 1693 if (result != XML_ERROR_NONE) 1694 return result; 1695 if (!storeRawNames(parser)) 1696 return XML_ERROR_NO_MEMORY; | 2022 enum XML_Error result = doContent(parser, 0, encoding, start, end, 2023 endPtr, (XML_Bool)!ps_finalBuffer); 2024 if (result == XML_ERROR_NONE) { 2025 if (!storeRawNames(parser)) 2026 return XML_ERROR_NO_MEMORY; 2027 } |
1697 return result; 1698} 1699 | 2028 return result; 2029} 2030 |
1700static enum XML_Error FASTCALL | 2031static enum XML_Error PTRCALL |
1701externalEntityInitProcessor(XML_Parser parser, 1702 const char *start, 1703 const char *end, 1704 const char **endPtr) 1705{ 1706 enum XML_Error result = initializeEncoding(parser); 1707 if (result != XML_ERROR_NONE) 1708 return result; 1709 processor = externalEntityInitProcessor2; 1710 return externalEntityInitProcessor2(parser, start, end, endPtr); 1711} 1712 | 2032externalEntityInitProcessor(XML_Parser parser, 2033 const char *start, 2034 const char *end, 2035 const char **endPtr) 2036{ 2037 enum XML_Error result = initializeEncoding(parser); 2038 if (result != XML_ERROR_NONE) 2039 return result; 2040 processor = externalEntityInitProcessor2; 2041 return externalEntityInitProcessor2(parser, start, end, endPtr); 2042} 2043 |
1713static enum XML_Error FASTCALL | 2044static enum XML_Error PTRCALL |
1714externalEntityInitProcessor2(XML_Parser parser, 1715 const char *start, 1716 const char *end, 1717 const char **endPtr) 1718{ 1719 const char *next = start; /* XmlContentTok doesn't always set the last arg */ 1720 int tok = XmlContentTok(encoding, start, end, &next); 1721 switch (tok) { 1722 case XML_TOK_BOM: 1723 /* If we are at the end of the buffer, this would cause the next stage, 1724 i.e. externalEntityInitProcessor3, to pass control directly to 1725 doContent (by detecting XML_TOK_NONE) without processing any xml text 1726 declaration - causing the error XML_ERROR_MISPLACED_XML_PI in doContent. 1727 */ | 2045externalEntityInitProcessor2(XML_Parser parser, 2046 const char *start, 2047 const char *end, 2048 const char **endPtr) 2049{ 2050 const char *next = start; /* XmlContentTok doesn't always set the last arg */ 2051 int tok = XmlContentTok(encoding, start, end, &next); 2052 switch (tok) { 2053 case XML_TOK_BOM: 2054 /* If we are at the end of the buffer, this would cause the next stage, 2055 i.e. externalEntityInitProcessor3, to pass control directly to 2056 doContent (by detecting XML_TOK_NONE) without processing any xml text 2057 declaration - causing the error XML_ERROR_MISPLACED_XML_PI in doContent. 2058 */ |
1728 if (next == end && endPtr) { | 2059 if (next == end && !ps_finalBuffer) { |
1729 *endPtr = next; 1730 return XML_ERROR_NONE; 1731 } 1732 start = next; 1733 break; 1734 case XML_TOK_PARTIAL: | 2060 *endPtr = next; 2061 return XML_ERROR_NONE; 2062 } 2063 start = next; 2064 break; 2065 case XML_TOK_PARTIAL: |
1735 if (endPtr) { | 2066 if (!ps_finalBuffer) { |
1736 *endPtr = start; 1737 return XML_ERROR_NONE; 1738 } 1739 eventPtr = start; 1740 return XML_ERROR_UNCLOSED_TOKEN; 1741 case XML_TOK_PARTIAL_CHAR: | 2067 *endPtr = start; 2068 return XML_ERROR_NONE; 2069 } 2070 eventPtr = start; 2071 return XML_ERROR_UNCLOSED_TOKEN; 2072 case XML_TOK_PARTIAL_CHAR: |
1742 if (endPtr) { | 2073 if (!ps_finalBuffer) { |
1743 *endPtr = start; 1744 return XML_ERROR_NONE; 1745 } 1746 eventPtr = start; 1747 return XML_ERROR_PARTIAL_CHAR; 1748 } 1749 processor = externalEntityInitProcessor3; 1750 return externalEntityInitProcessor3(parser, start, end, endPtr); 1751} 1752 | 2074 *endPtr = start; 2075 return XML_ERROR_NONE; 2076 } 2077 eventPtr = start; 2078 return XML_ERROR_PARTIAL_CHAR; 2079 } 2080 processor = externalEntityInitProcessor3; 2081 return externalEntityInitProcessor3(parser, start, end, endPtr); 2082} 2083 |
1753static enum XML_Error FASTCALL | 2084static enum XML_Error PTRCALL |
1754externalEntityInitProcessor3(XML_Parser parser, 1755 const char *start, 1756 const char *end, 1757 const char **endPtr) 1758{ | 2085externalEntityInitProcessor3(XML_Parser parser, 2086 const char *start, 2087 const char *end, 2088 const char **endPtr) 2089{ |
2090 int tok; |
|
1759 const char *next = start; /* XmlContentTok doesn't always set the last arg */ | 2091 const char *next = start; /* XmlContentTok doesn't always set the last arg */ |
1760 int tok = XmlContentTok(encoding, start, end, &next); | 2092 eventPtr = start; 2093 tok = XmlContentTok(encoding, start, end, &next); 2094 eventEndPtr = next; 2095 |
1761 switch (tok) { 1762 case XML_TOK_XML_DECL: 1763 { | 2096 switch (tok) { 2097 case XML_TOK_XML_DECL: 2098 { |
1764 enum XML_Error result = processXmlDecl(parser, 1, start, next); | 2099 enum XML_Error result; 2100 result = processXmlDecl(parser, 1, start, next); |
1765 if (result != XML_ERROR_NONE) 1766 return result; | 2101 if (result != XML_ERROR_NONE) 2102 return result; |
1767 start = next; | 2103 switch (ps_parsing) { 2104 case XML_SUSPENDED: 2105 *endPtr = next; 2106 return XML_ERROR_NONE; 2107 case XML_FINISHED: 2108 return XML_ERROR_ABORTED; 2109 default: 2110 start = next; 2111 } |
1768 } 1769 break; 1770 case XML_TOK_PARTIAL: | 2112 } 2113 break; 2114 case XML_TOK_PARTIAL: |
1771 if (endPtr) { | 2115 if (!ps_finalBuffer) { |
1772 *endPtr = start; 1773 return XML_ERROR_NONE; 1774 } | 2116 *endPtr = start; 2117 return XML_ERROR_NONE; 2118 } |
1775 eventPtr = start; | |
1776 return XML_ERROR_UNCLOSED_TOKEN; 1777 case XML_TOK_PARTIAL_CHAR: | 2119 return XML_ERROR_UNCLOSED_TOKEN; 2120 case XML_TOK_PARTIAL_CHAR: |
1778 if (endPtr) { | 2121 if (!ps_finalBuffer) { |
1779 *endPtr = start; 1780 return XML_ERROR_NONE; 1781 } | 2122 *endPtr = start; 2123 return XML_ERROR_NONE; 2124 } |
1782 eventPtr = start; | |
1783 return XML_ERROR_PARTIAL_CHAR; 1784 } 1785 processor = externalEntityContentProcessor; 1786 tagLevel = 1; 1787 return externalEntityContentProcessor(parser, start, end, endPtr); 1788} 1789 | 2125 return XML_ERROR_PARTIAL_CHAR; 2126 } 2127 processor = externalEntityContentProcessor; 2128 tagLevel = 1; 2129 return externalEntityContentProcessor(parser, start, end, endPtr); 2130} 2131 |
1790static enum XML_Error FASTCALL | 2132static enum XML_Error PTRCALL |
1791externalEntityContentProcessor(XML_Parser parser, 1792 const char *start, 1793 const char *end, 1794 const char **endPtr) 1795{ | 2133externalEntityContentProcessor(XML_Parser parser, 2134 const char *start, 2135 const char *end, 2136 const char **endPtr) 2137{ |
1796 enum XML_Error result = 1797 doContent(parser, 1, encoding, start, end, endPtr); 1798 if (result != XML_ERROR_NONE) 1799 return result; 1800 if (!storeRawNames(parser)) 1801 return XML_ERROR_NO_MEMORY; | 2138 enum XML_Error result = doContent(parser, 1, encoding, start, end, 2139 endPtr, (XML_Bool)!ps_finalBuffer); 2140 if (result == XML_ERROR_NONE) { 2141 if (!storeRawNames(parser)) 2142 return XML_ERROR_NO_MEMORY; 2143 } |
1802 return result; 1803} 1804 | 2144 return result; 2145} 2146 |
1805static enum XML_Error FASTCALL | 2147static enum XML_Error |
1806doContent(XML_Parser parser, 1807 int startTagLevel, 1808 const ENCODING *enc, 1809 const char *s, 1810 const char *end, | 2148doContent(XML_Parser parser, 2149 int startTagLevel, 2150 const ENCODING *enc, 2151 const char *s, 2152 const char *end, |
1811 const char **nextPtr) | 2153 const char **nextPtr, 2154 XML_Bool haveMore) |
1812{ | 2155{ |
2156 /* save one level of indirection */ 2157 DTD * const dtd = _dtd; 2158 |
|
1813 const char **eventPP; 1814 const char **eventEndPP; 1815 if (enc == encoding) { 1816 eventPP = &eventPtr; 1817 eventEndPP = &eventEndPtr; 1818 } 1819 else { 1820 eventPP = &(openInternalEntities->internalEventPtr); 1821 eventEndPP = &(openInternalEntities->internalEventEndPtr); 1822 } 1823 *eventPP = s; | 2159 const char **eventPP; 2160 const char **eventEndPP; 2161 if (enc == encoding) { 2162 eventPP = &eventPtr; 2163 eventEndPP = &eventEndPtr; 2164 } 2165 else { 2166 eventPP = &(openInternalEntities->internalEventPtr); 2167 eventEndPP = &(openInternalEntities->internalEventEndPtr); 2168 } 2169 *eventPP = s; |
2170 |
|
1824 for (;;) { 1825 const char *next = s; /* XmlContentTok doesn't always set the last arg */ 1826 int tok = XmlContentTok(enc, s, end, &next); 1827 *eventEndPP = next; 1828 switch (tok) { 1829 case XML_TOK_TRAILING_CR: | 2171 for (;;) { 2172 const char *next = s; /* XmlContentTok doesn't always set the last arg */ 2173 int tok = XmlContentTok(enc, s, end, &next); 2174 *eventEndPP = next; 2175 switch (tok) { 2176 case XML_TOK_TRAILING_CR: |
1830 if (nextPtr) { | 2177 if (haveMore) { |
1831 *nextPtr = s; 1832 return XML_ERROR_NONE; 1833 } 1834 *eventEndPP = end; 1835 if (characterDataHandler) { 1836 XML_Char c = 0xA; 1837 characterDataHandler(handlerArg, &c, 1); 1838 } 1839 else if (defaultHandler) 1840 reportDefault(parser, enc, s, end); | 2178 *nextPtr = s; 2179 return XML_ERROR_NONE; 2180 } 2181 *eventEndPP = end; 2182 if (characterDataHandler) { 2183 XML_Char c = 0xA; 2184 characterDataHandler(handlerArg, &c, 1); 2185 } 2186 else if (defaultHandler) 2187 reportDefault(parser, enc, s, end); |
2188 /* We are at the end of the final buffer, should we check for 2189 XML_SUSPENDED, XML_FINISHED? 2190 */ |
|
1841 if (startTagLevel == 0) 1842 return XML_ERROR_NO_ELEMENTS; 1843 if (tagLevel != startTagLevel) 1844 return XML_ERROR_ASYNC_ENTITY; | 2191 if (startTagLevel == 0) 2192 return XML_ERROR_NO_ELEMENTS; 2193 if (tagLevel != startTagLevel) 2194 return XML_ERROR_ASYNC_ENTITY; |
2195 *nextPtr = end; |
|
1845 return XML_ERROR_NONE; 1846 case XML_TOK_NONE: | 2196 return XML_ERROR_NONE; 2197 case XML_TOK_NONE: |
1847 if (nextPtr) { | 2198 if (haveMore) { |
1848 *nextPtr = s; 1849 return XML_ERROR_NONE; 1850 } 1851 if (startTagLevel > 0) { 1852 if (tagLevel != startTagLevel) 1853 return XML_ERROR_ASYNC_ENTITY; | 2199 *nextPtr = s; 2200 return XML_ERROR_NONE; 2201 } 2202 if (startTagLevel > 0) { 2203 if (tagLevel != startTagLevel) 2204 return XML_ERROR_ASYNC_ENTITY; |
2205 *nextPtr = s; |
|
1854 return XML_ERROR_NONE; 1855 } 1856 return XML_ERROR_NO_ELEMENTS; 1857 case XML_TOK_INVALID: 1858 *eventPP = next; 1859 return XML_ERROR_INVALID_TOKEN; 1860 case XML_TOK_PARTIAL: | 2206 return XML_ERROR_NONE; 2207 } 2208 return XML_ERROR_NO_ELEMENTS; 2209 case XML_TOK_INVALID: 2210 *eventPP = next; 2211 return XML_ERROR_INVALID_TOKEN; 2212 case XML_TOK_PARTIAL: |
1861 if (nextPtr) { | 2213 if (haveMore) { |
1862 *nextPtr = s; 1863 return XML_ERROR_NONE; 1864 } 1865 return XML_ERROR_UNCLOSED_TOKEN; 1866 case XML_TOK_PARTIAL_CHAR: | 2214 *nextPtr = s; 2215 return XML_ERROR_NONE; 2216 } 2217 return XML_ERROR_UNCLOSED_TOKEN; 2218 case XML_TOK_PARTIAL_CHAR: |
1867 if (nextPtr) { | 2219 if (haveMore) { |
1868 *nextPtr = s; 1869 return XML_ERROR_NONE; 1870 } 1871 return XML_ERROR_PARTIAL_CHAR; 1872 case XML_TOK_ENTITY_REF: 1873 { 1874 const XML_Char *name; 1875 ENTITY *entity; 1876 XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc, 1877 s + enc->minBytesPerChar, 1878 next - enc->minBytesPerChar); 1879 if (ch) { 1880 if (characterDataHandler) 1881 characterDataHandler(handlerArg, &ch, 1); 1882 else if (defaultHandler) 1883 reportDefault(parser, enc, s, next); 1884 break; 1885 } | 2220 *nextPtr = s; 2221 return XML_ERROR_NONE; 2222 } 2223 return XML_ERROR_PARTIAL_CHAR; 2224 case XML_TOK_ENTITY_REF: 2225 { 2226 const XML_Char *name; 2227 ENTITY *entity; 2228 XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc, 2229 s + enc->minBytesPerChar, 2230 next - enc->minBytesPerChar); 2231 if (ch) { 2232 if (characterDataHandler) 2233 characterDataHandler(handlerArg, &ch, 1); 2234 else if (defaultHandler) 2235 reportDefault(parser, enc, s, next); 2236 break; 2237 } |
1886 name = poolStoreString(&dtd.pool, enc, | 2238 name = poolStoreString(&dtd->pool, enc, |
1887 s + enc->minBytesPerChar, 1888 next - enc->minBytesPerChar); 1889 if (!name) 1890 return XML_ERROR_NO_MEMORY; | 2239 s + enc->minBytesPerChar, 2240 next - enc->minBytesPerChar); 2241 if (!name) 2242 return XML_ERROR_NO_MEMORY; |
1891 entity = (ENTITY *)lookup(&dtd.generalEntities, name, 0); 1892 poolDiscard(&dtd.pool); | 2243 entity = (ENTITY *)lookup(&dtd->generalEntities, name, 0); 2244 poolDiscard(&dtd->pool); |
1893 /* First, determine if a check for an existing declaration is needed; 1894 if yes, check that the entity exists, and that it is internal, 1895 otherwise call the skipped entity or default handler. 1896 */ | 2245 /* First, determine if a check for an existing declaration is needed; 2246 if yes, check that the entity exists, and that it is internal, 2247 otherwise call the skipped entity or default handler. 2248 */ |
1897 if (!dtd.hasParamEntityRefs || dtd.standalone) { | 2249 if (!dtd->hasParamEntityRefs || dtd->standalone) { |
1898 if (!entity) 1899 return XML_ERROR_UNDEFINED_ENTITY; 1900 else if (!entity->is_internal) 1901 return XML_ERROR_ENTITY_DECLARED_IN_PE; 1902 } 1903 else if (!entity) { 1904 if (skippedEntityHandler) 1905 skippedEntityHandler(handlerArg, name, 0); 1906 else if (defaultHandler) 1907 reportDefault(parser, enc, s, next); 1908 break; 1909 } 1910 if (entity->open) 1911 return XML_ERROR_RECURSIVE_ENTITY_REF; 1912 if (entity->notation) 1913 return XML_ERROR_BINARY_ENTITY_REF; 1914 if (entity->textPtr) { 1915 enum XML_Error result; | 2250 if (!entity) 2251 return XML_ERROR_UNDEFINED_ENTITY; 2252 else if (!entity->is_internal) 2253 return XML_ERROR_ENTITY_DECLARED_IN_PE; 2254 } 2255 else if (!entity) { 2256 if (skippedEntityHandler) 2257 skippedEntityHandler(handlerArg, name, 0); 2258 else if (defaultHandler) 2259 reportDefault(parser, enc, s, next); 2260 break; 2261 } 2262 if (entity->open) 2263 return XML_ERROR_RECURSIVE_ENTITY_REF; 2264 if (entity->notation) 2265 return XML_ERROR_BINARY_ENTITY_REF; 2266 if (entity->textPtr) { 2267 enum XML_Error result; |
1916 OPEN_INTERNAL_ENTITY openEntity; | |
1917 if (!defaultExpandInternalEntities) { 1918 if (skippedEntityHandler) 1919 skippedEntityHandler(handlerArg, entity->name, 0); 1920 else if (defaultHandler) 1921 reportDefault(parser, enc, s, next); 1922 break; 1923 } | 2268 if (!defaultExpandInternalEntities) { 2269 if (skippedEntityHandler) 2270 skippedEntityHandler(handlerArg, entity->name, 0); 2271 else if (defaultHandler) 2272 reportDefault(parser, enc, s, next); 2273 break; 2274 } |
1924 entity->open = XML_TRUE; 1925 openEntity.next = openInternalEntities; 1926 openInternalEntities = &openEntity; 1927 openEntity.entity = entity; 1928 openEntity.internalEventPtr = NULL; 1929 openEntity.internalEventEndPtr = NULL; 1930 result = doContent(parser, 1931 tagLevel, 1932 internalEncoding, 1933 (char *)entity->textPtr, 1934 (char *)(entity->textPtr + entity->textLen), 1935 0); 1936 entity->open = XML_FALSE; 1937 openInternalEntities = openEntity.next; 1938 if (result) | 2275 result = processInternalEntity(parser, entity, XML_FALSE); 2276 if (result != XML_ERROR_NONE) |
1939 return result; 1940 } 1941 else if (externalEntityRefHandler) { 1942 const XML_Char *context; 1943 entity->open = XML_TRUE; 1944 context = getContext(parser); 1945 entity->open = XML_FALSE; 1946 if (!context) --- 5 unchanged lines hidden (view full) --- 1952 entity->publicId)) 1953 return XML_ERROR_EXTERNAL_ENTITY_HANDLING; 1954 poolDiscard(&tempPool); 1955 } 1956 else if (defaultHandler) 1957 reportDefault(parser, enc, s, next); 1958 break; 1959 } | 2277 return result; 2278 } 2279 else if (externalEntityRefHandler) { 2280 const XML_Char *context; 2281 entity->open = XML_TRUE; 2282 context = getContext(parser); 2283 entity->open = XML_FALSE; 2284 if (!context) --- 5 unchanged lines hidden (view full) --- 2290 entity->publicId)) 2291 return XML_ERROR_EXTERNAL_ENTITY_HANDLING; 2292 poolDiscard(&tempPool); 2293 } 2294 else if (defaultHandler) 2295 reportDefault(parser, enc, s, next); 2296 break; 2297 } |
1960 case XML_TOK_START_TAG_WITH_ATTS: 1961 if (!startElementHandler) { 1962 enum XML_Error result = storeAtts(parser, enc, s, 0, 0); 1963 if (result) 1964 return result; 1965 } 1966 /* fall through */ | |
1967 case XML_TOK_START_TAG_NO_ATTS: | 2298 case XML_TOK_START_TAG_NO_ATTS: |
2299 /* fall through */ 2300 case XML_TOK_START_TAG_WITH_ATTS: |
|
1968 { 1969 TAG *tag; 1970 enum XML_Error result; 1971 XML_Char *toPtr; 1972 if (freeTagList) { 1973 tag = freeTagList; 1974 freeTagList = freeTagList->parent; 1975 } 1976 else { | 2301 { 2302 TAG *tag; 2303 enum XML_Error result; 2304 XML_Char *toPtr; 2305 if (freeTagList) { 2306 tag = freeTagList; 2307 freeTagList = freeTagList->parent; 2308 } 2309 else { |
1977 tag = MALLOC(sizeof(TAG)); | 2310 tag = (TAG *)MALLOC(sizeof(TAG)); |
1978 if (!tag) 1979 return XML_ERROR_NO_MEMORY; | 2311 if (!tag) 2312 return XML_ERROR_NO_MEMORY; |
1980 tag->buf = MALLOC(INIT_TAG_BUF_SIZE); | 2313 tag->buf = (char *)MALLOC(INIT_TAG_BUF_SIZE); |
1981 if (!tag->buf) { 1982 FREE(tag); 1983 return XML_ERROR_NO_MEMORY; 1984 } 1985 tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE; 1986 } 1987 tag->bindings = NULL; 1988 tag->parent = tagStack; --- 8 unchanged lines hidden (view full) --- 1997 const char *fromPtr = tag->rawName; 1998 toPtr = (XML_Char *)tag->buf; 1999 for (;;) { 2000 int bufSize; 2001 int convLen; 2002 XmlConvert(enc, 2003 &fromPtr, rawNameEnd, 2004 (ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1); | 2314 if (!tag->buf) { 2315 FREE(tag); 2316 return XML_ERROR_NO_MEMORY; 2317 } 2318 tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE; 2319 } 2320 tag->bindings = NULL; 2321 tag->parent = tagStack; --- 8 unchanged lines hidden (view full) --- 2330 const char *fromPtr = tag->rawName; 2331 toPtr = (XML_Char *)tag->buf; 2332 for (;;) { 2333 int bufSize; 2334 int convLen; 2335 XmlConvert(enc, 2336 &fromPtr, rawNameEnd, 2337 (ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1); |
2005 convLen = toPtr - (XML_Char *)tag->buf; | 2338 convLen = (int)(toPtr - (XML_Char *)tag->buf); |
2006 if (fromPtr == rawNameEnd) { 2007 tag->name.strLen = convLen; 2008 break; 2009 } | 2339 if (fromPtr == rawNameEnd) { 2340 tag->name.strLen = convLen; 2341 break; 2342 } |
2010 bufSize = (tag->bufEnd - tag->buf) << 1; | 2343 bufSize = (int)(tag->bufEnd - tag->buf) << 1; |
2011 { | 2344 { |
2012 char *temp = REALLOC(tag->buf, bufSize); | 2345 char *temp = (char *)REALLOC(tag->buf, bufSize); |
2013 if (temp == NULL) 2014 return XML_ERROR_NO_MEMORY; 2015 tag->buf = temp; 2016 tag->bufEnd = temp + bufSize; 2017 toPtr = (XML_Char *)temp + convLen; 2018 } 2019 } 2020 } 2021 tag->name.str = (XML_Char *)tag->buf; 2022 *toPtr = XML_T('\0'); | 2346 if (temp == NULL) 2347 return XML_ERROR_NO_MEMORY; 2348 tag->buf = temp; 2349 tag->bufEnd = temp + bufSize; 2350 toPtr = (XML_Char *)temp + convLen; 2351 } 2352 } 2353 } 2354 tag->name.str = (XML_Char *)tag->buf; 2355 *toPtr = XML_T('\0'); |
2023 if (startElementHandler) { 2024 result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings)); 2025 if (result) 2026 return result; | 2356 result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings)); 2357 if (result) 2358 return result; 2359 if (startElementHandler) |
2027 startElementHandler(handlerArg, tag->name.str, 2028 (const XML_Char **)atts); | 2360 startElementHandler(handlerArg, tag->name.str, 2361 (const XML_Char **)atts); |
2029 } | |
2030 else if (defaultHandler) 2031 reportDefault(parser, enc, s, next); 2032 poolClear(&tempPool); 2033 break; 2034 } | 2362 else if (defaultHandler) 2363 reportDefault(parser, enc, s, next); 2364 poolClear(&tempPool); 2365 break; 2366 } |
2035 case XML_TOK_EMPTY_ELEMENT_WITH_ATTS: 2036 if (!startElementHandler) { 2037 enum XML_Error result = storeAtts(parser, enc, s, 0, 0); 2038 if (result) 2039 return result; 2040 } 2041 /* fall through */ | |
2042 case XML_TOK_EMPTY_ELEMENT_NO_ATTS: | 2367 case XML_TOK_EMPTY_ELEMENT_NO_ATTS: |
2043 if (startElementHandler || endElementHandler) { | 2368 /* fall through */ 2369 case XML_TOK_EMPTY_ELEMENT_WITH_ATTS: 2370 { |
2044 const char *rawName = s + enc->minBytesPerChar; 2045 enum XML_Error result; 2046 BINDING *bindings = NULL; | 2371 const char *rawName = s + enc->minBytesPerChar; 2372 enum XML_Error result; 2373 BINDING *bindings = NULL; |
2374 XML_Bool noElmHandlers = XML_TRUE; |
|
2047 TAG_NAME name; 2048 name.str = poolStoreString(&tempPool, enc, rawName, 2049 rawName + XmlNameLength(enc, rawName)); 2050 if (!name.str) 2051 return XML_ERROR_NO_MEMORY; 2052 poolFinish(&tempPool); 2053 result = storeAtts(parser, enc, s, &name, &bindings); 2054 if (result) 2055 return result; 2056 poolFinish(&tempPool); | 2375 TAG_NAME name; 2376 name.str = poolStoreString(&tempPool, enc, rawName, 2377 rawName + XmlNameLength(enc, rawName)); 2378 if (!name.str) 2379 return XML_ERROR_NO_MEMORY; 2380 poolFinish(&tempPool); 2381 result = storeAtts(parser, enc, s, &name, &bindings); 2382 if (result) 2383 return result; 2384 poolFinish(&tempPool); |
2057 if (startElementHandler) | 2385 if (startElementHandler) { |
2058 startElementHandler(handlerArg, name.str, (const XML_Char **)atts); | 2386 startElementHandler(handlerArg, name.str, (const XML_Char **)atts); |
2387 noElmHandlers = XML_FALSE; 2388 } |
|
2059 if (endElementHandler) { 2060 if (startElementHandler) 2061 *eventPP = *eventEndPP; 2062 endElementHandler(handlerArg, name.str); | 2389 if (endElementHandler) { 2390 if (startElementHandler) 2391 *eventPP = *eventEndPP; 2392 endElementHandler(handlerArg, name.str); |
2393 noElmHandlers = XML_FALSE; |
|
2063 } | 2394 } |
2395 if (noElmHandlers && defaultHandler) 2396 reportDefault(parser, enc, s, next); |
|
2064 poolClear(&tempPool); 2065 while (bindings) { 2066 BINDING *b = bindings; 2067 if (endNamespaceDeclHandler) 2068 endNamespaceDeclHandler(handlerArg, b->prefix->name); 2069 bindings = bindings->nextTagBinding; 2070 b->nextTagBinding = freeBindingList; 2071 freeBindingList = b; 2072 b->prefix->binding = b->prevPrefixBinding; 2073 } 2074 } | 2397 poolClear(&tempPool); 2398 while (bindings) { 2399 BINDING *b = bindings; 2400 if (endNamespaceDeclHandler) 2401 endNamespaceDeclHandler(handlerArg, b->prefix->name); 2402 bindings = bindings->nextTagBinding; 2403 b->nextTagBinding = freeBindingList; 2404 freeBindingList = b; 2405 b->prefix->binding = b->prevPrefixBinding; 2406 } 2407 } |
2075 else if (defaultHandler) 2076 reportDefault(parser, enc, s, next); | |
2077 if (tagLevel == 0) 2078 return epilogProcessor(parser, next, end, nextPtr); 2079 break; 2080 case XML_TOK_END_TAG: 2081 if (tagLevel == startTagLevel) 2082 return XML_ERROR_ASYNC_ENTITY; 2083 else { 2084 int len; --- 88 unchanged lines hidden (view full) --- 2173 However, now we have a start/endCdataSectionHandler, so it seems 2174 easier to let the user deal with this. 2175 */ 2176 else if (characterDataHandler) 2177 characterDataHandler(handlerArg, dataBuf, 0); 2178#endif 2179 else if (defaultHandler) 2180 reportDefault(parser, enc, s, next); | 2408 if (tagLevel == 0) 2409 return epilogProcessor(parser, next, end, nextPtr); 2410 break; 2411 case XML_TOK_END_TAG: 2412 if (tagLevel == startTagLevel) 2413 return XML_ERROR_ASYNC_ENTITY; 2414 else { 2415 int len; --- 88 unchanged lines hidden (view full) --- 2504 However, now we have a start/endCdataSectionHandler, so it seems 2505 easier to let the user deal with this. 2506 */ 2507 else if (characterDataHandler) 2508 characterDataHandler(handlerArg, dataBuf, 0); 2509#endif 2510 else if (defaultHandler) 2511 reportDefault(parser, enc, s, next); |
2181 result = doCdataSection(parser, enc, &next, end, nextPtr); 2182 if (!next) { | 2512 result = doCdataSection(parser, enc, &next, end, nextPtr, haveMore); 2513 if (result != XML_ERROR_NONE) 2514 return result; 2515 else if (!next) { |
2183 processor = cdataSectionProcessor; 2184 return result; 2185 } 2186 } 2187 break; 2188 case XML_TOK_TRAILING_RSQB: | 2516 processor = cdataSectionProcessor; 2517 return result; 2518 } 2519 } 2520 break; 2521 case XML_TOK_TRAILING_RSQB: |
2189 if (nextPtr) { | 2522 if (haveMore) { |
2190 *nextPtr = s; 2191 return XML_ERROR_NONE; 2192 } 2193 if (characterDataHandler) { 2194 if (MUST_CONVERT(enc, s)) { 2195 ICHAR *dataPtr = (ICHAR *)dataBuf; 2196 XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); 2197 characterDataHandler(handlerArg, dataBuf, | 2523 *nextPtr = s; 2524 return XML_ERROR_NONE; 2525 } 2526 if (characterDataHandler) { 2527 if (MUST_CONVERT(enc, s)) { 2528 ICHAR *dataPtr = (ICHAR *)dataBuf; 2529 XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); 2530 characterDataHandler(handlerArg, dataBuf, |
2198 dataPtr - (ICHAR *)dataBuf); | 2531 (int)(dataPtr - (ICHAR *)dataBuf)); |
2199 } 2200 else 2201 characterDataHandler(handlerArg, 2202 (XML_Char *)s, | 2532 } 2533 else 2534 characterDataHandler(handlerArg, 2535 (XML_Char *)s, |
2203 (XML_Char *)end - (XML_Char *)s); | 2536 (int)((XML_Char *)end - (XML_Char *)s)); |
2204 } 2205 else if (defaultHandler) 2206 reportDefault(parser, enc, s, end); | 2537 } 2538 else if (defaultHandler) 2539 reportDefault(parser, enc, s, end); |
2540 /* We are at the end of the final buffer, should we check for 2541 XML_SUSPENDED, XML_FINISHED? 2542 */ |
|
2207 if (startTagLevel == 0) { 2208 *eventPP = end; 2209 return XML_ERROR_NO_ELEMENTS; 2210 } 2211 if (tagLevel != startTagLevel) { 2212 *eventPP = end; 2213 return XML_ERROR_ASYNC_ENTITY; 2214 } | 2543 if (startTagLevel == 0) { 2544 *eventPP = end; 2545 return XML_ERROR_NO_ELEMENTS; 2546 } 2547 if (tagLevel != startTagLevel) { 2548 *eventPP = end; 2549 return XML_ERROR_ASYNC_ENTITY; 2550 } |
2551 *nextPtr = end; |
|
2215 return XML_ERROR_NONE; | 2552 return XML_ERROR_NONE; |
2216 case XML_TOK_DATA_CHARS: 2217 if (characterDataHandler) { 2218 if (MUST_CONVERT(enc, s)) { 2219 for (;;) { 2220 ICHAR *dataPtr = (ICHAR *)dataBuf; 2221 XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); 2222 *eventEndPP = s; 2223 characterDataHandler(handlerArg, dataBuf, 2224 dataPtr - (ICHAR *)dataBuf); 2225 if (s == next) 2226 break; 2227 *eventPP = s; | 2553 case XML_TOK_DATA_CHARS: 2554 { 2555 XML_CharacterDataHandler charDataHandler = characterDataHandler; 2556 if (charDataHandler) { 2557 if (MUST_CONVERT(enc, s)) { 2558 for (;;) { 2559 ICHAR *dataPtr = (ICHAR *)dataBuf; 2560 XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); 2561 *eventEndPP = s; 2562 charDataHandler(handlerArg, dataBuf, 2563 (int)(dataPtr - (ICHAR *)dataBuf)); 2564 if (s == next) 2565 break; 2566 *eventPP = s; 2567 } |
2228 } | 2568 } |
2569 else 2570 charDataHandler(handlerArg, 2571 (XML_Char *)s, 2572 (int)((XML_Char *)next - (XML_Char *)s)); |
|
2229 } | 2573 } |
2230 else 2231 characterDataHandler(handlerArg, 2232 (XML_Char *)s, 2233 (XML_Char *)next - (XML_Char *)s); | 2574 else if (defaultHandler) 2575 reportDefault(parser, enc, s, next); |
2234 } | 2576 } |
2235 else if (defaultHandler) 2236 reportDefault(parser, enc, s, next); | |
2237 break; 2238 case XML_TOK_PI: 2239 if (!reportProcessingInstruction(parser, enc, s, next)) 2240 return XML_ERROR_NO_MEMORY; 2241 break; 2242 case XML_TOK_COMMENT: 2243 if (!reportComment(parser, enc, s, next)) 2244 return XML_ERROR_NO_MEMORY; 2245 break; 2246 default: 2247 if (defaultHandler) 2248 reportDefault(parser, enc, s, next); 2249 break; 2250 } 2251 *eventPP = s = next; | 2577 break; 2578 case XML_TOK_PI: 2579 if (!reportProcessingInstruction(parser, enc, s, next)) 2580 return XML_ERROR_NO_MEMORY; 2581 break; 2582 case XML_TOK_COMMENT: 2583 if (!reportComment(parser, enc, s, next)) 2584 return XML_ERROR_NO_MEMORY; 2585 break; 2586 default: 2587 if (defaultHandler) 2588 reportDefault(parser, enc, s, next); 2589 break; 2590 } 2591 *eventPP = s = next; |
2592 switch (ps_parsing) { 2593 case XML_SUSPENDED: 2594 *nextPtr = next; 2595 return XML_ERROR_NONE; 2596 case XML_FINISHED: 2597 return XML_ERROR_ABORTED; 2598 default: ; 2599 } |
|
2252 } 2253 /* not reached */ 2254} 2255 | 2600 } 2601 /* not reached */ 2602} 2603 |
2256/* If tagNamePtr is non-null, build a real list of attributes, 2257 otherwise just check the attributes for well-formedness. | 2604/* Precondition: all arguments must be non-NULL; 2605 Purpose: 2606 - normalize attributes 2607 - check attributes for well-formedness 2608 - generate namespace aware attribute names (URI, prefix) 2609 - build list of attributes for startElementHandler 2610 - default attributes 2611 - process namespace declarations (check and report them) 2612 - generate namespace aware element name (URI, prefix) |
2258*/ | 2613*/ |
2259static enum XML_Error FASTCALL | 2614static enum XML_Error |
2260storeAtts(XML_Parser parser, const ENCODING *enc, 2261 const char *attStr, TAG_NAME *tagNamePtr, 2262 BINDING **bindingsPtr) 2263{ | 2615storeAtts(XML_Parser parser, const ENCODING *enc, 2616 const char *attStr, TAG_NAME *tagNamePtr, 2617 BINDING **bindingsPtr) 2618{ |
2264 ELEMENT_TYPE *elementType = NULL; 2265 int nDefaultAtts = 0; | 2619 DTD * const dtd = _dtd; /* save one level of indirection */ 2620 ELEMENT_TYPE *elementType; 2621 int nDefaultAtts; |
2266 const XML_Char **appAtts; /* the attribute list for the application */ 2267 int attIndex = 0; 2268 int prefixLen; 2269 int i; 2270 int n; 2271 XML_Char *uri; 2272 int nPrefixes = 0; 2273 BINDING *binding; 2274 const XML_Char *localPart; 2275 2276 /* lookup the element type name */ | 2622 const XML_Char **appAtts; /* the attribute list for the application */ 2623 int attIndex = 0; 2624 int prefixLen; 2625 int i; 2626 int n; 2627 XML_Char *uri; 2628 int nPrefixes = 0; 2629 BINDING *binding; 2630 const XML_Char *localPart; 2631 2632 /* lookup the element type name */ |
2277 if (tagNamePtr) { 2278 elementType = (ELEMENT_TYPE *)lookup(&dtd.elementTypes, tagNamePtr->str,0); 2279 if (!elementType) { 2280 tagNamePtr->str = poolCopyString(&dtd.pool, tagNamePtr->str); 2281 if (!tagNamePtr->str) 2282 return XML_ERROR_NO_MEMORY; 2283 elementType = (ELEMENT_TYPE *)lookup(&dtd.elementTypes, tagNamePtr->str, 2284 sizeof(ELEMENT_TYPE)); 2285 if (!elementType) 2286 return XML_ERROR_NO_MEMORY; 2287 if (ns && !setElementTypePrefix(parser, elementType)) 2288 return XML_ERROR_NO_MEMORY; 2289 } 2290 nDefaultAtts = elementType->nDefaultAtts; | 2633 elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, tagNamePtr->str,0); 2634 if (!elementType) { 2635 const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str); 2636 if (!name) 2637 return XML_ERROR_NO_MEMORY; 2638 elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, name, 2639 sizeof(ELEMENT_TYPE)); 2640 if (!elementType) 2641 return XML_ERROR_NO_MEMORY; 2642 if (ns && !setElementTypePrefix(parser, elementType)) 2643 return XML_ERROR_NO_MEMORY; |
2291 } | 2644 } |
2645 nDefaultAtts = elementType->nDefaultAtts; 2646 |
|
2292 /* get the attributes from the tokenizer */ 2293 n = XmlGetAttributes(enc, attStr, attsSize, atts); 2294 if (n + nDefaultAtts > attsSize) { 2295 int oldAttsSize = attsSize; 2296 ATTRIBUTE *temp; 2297 attsSize = n + nDefaultAtts + INIT_ATTS_SIZE; | 2647 /* get the attributes from the tokenizer */ 2648 n = XmlGetAttributes(enc, attStr, attsSize, atts); 2649 if (n + nDefaultAtts > attsSize) { 2650 int oldAttsSize = attsSize; 2651 ATTRIBUTE *temp; 2652 attsSize = n + nDefaultAtts + INIT_ATTS_SIZE; |
2298 temp = REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE)); | 2653 temp = (ATTRIBUTE *)REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE)); |
2299 if (temp == NULL) 2300 return XML_ERROR_NO_MEMORY; 2301 atts = temp; 2302 if (n > oldAttsSize) 2303 XmlGetAttributes(enc, attStr, n, atts); 2304 } | 2654 if (temp == NULL) 2655 return XML_ERROR_NO_MEMORY; 2656 atts = temp; 2657 if (n > oldAttsSize) 2658 XmlGetAttributes(enc, attStr, n, atts); 2659 } |
2660 |
|
2305 appAtts = (const XML_Char **)atts; 2306 for (i = 0; i < n; i++) { 2307 /* add the name and value to the attribute list */ 2308 ATTRIBUTE_ID *attId = getAttributeId(parser, enc, atts[i].name, 2309 atts[i].name 2310 + XmlNameLength(enc, atts[i].name)); 2311 if (!attId) 2312 return XML_ERROR_NO_MEMORY; | 2661 appAtts = (const XML_Char **)atts; 2662 for (i = 0; i < n; i++) { 2663 /* add the name and value to the attribute list */ 2664 ATTRIBUTE_ID *attId = getAttributeId(parser, enc, atts[i].name, 2665 atts[i].name 2666 + XmlNameLength(enc, atts[i].name)); 2667 if (!attId) 2668 return XML_ERROR_NO_MEMORY; |
2313 /* detect duplicate attributes */ | 2669 /* Detect duplicate attributes by their QNames. This does not work when 2670 namespace processing is turned on and different prefixes for the same 2671 namespace are used. For this case we have a check further down. 2672 */ |
2314 if ((attId->name)[-1]) { 2315 if (enc == encoding) 2316 eventPtr = atts[i].name; 2317 return XML_ERROR_DUPLICATE_ATTRIBUTE; 2318 } 2319 (attId->name)[-1] = 1; 2320 appAtts[attIndex++] = attId->name; 2321 if (!atts[i].normalized) { --- 12 unchanged lines hidden (view full) --- 2334 } 2335 2336 /* normalize the attribute value */ 2337 result = storeAttributeValue(parser, enc, isCdata, 2338 atts[i].valuePtr, atts[i].valueEnd, 2339 &tempPool); 2340 if (result) 2341 return result; | 2673 if ((attId->name)[-1]) { 2674 if (enc == encoding) 2675 eventPtr = atts[i].name; 2676 return XML_ERROR_DUPLICATE_ATTRIBUTE; 2677 } 2678 (attId->name)[-1] = 1; 2679 appAtts[attIndex++] = attId->name; 2680 if (!atts[i].normalized) { --- 12 unchanged lines hidden (view full) --- 2693 } 2694 2695 /* normalize the attribute value */ 2696 result = storeAttributeValue(parser, enc, isCdata, 2697 atts[i].valuePtr, atts[i].valueEnd, 2698 &tempPool); 2699 if (result) 2700 return result; |
2342 if (tagNamePtr) { 2343 appAtts[attIndex] = poolStart(&tempPool); 2344 poolFinish(&tempPool); 2345 } 2346 else 2347 poolDiscard(&tempPool); | 2701 appAtts[attIndex] = poolStart(&tempPool); 2702 poolFinish(&tempPool); |
2348 } | 2703 } |
2349 else if (tagNamePtr) { | 2704 else { |
2350 /* the value did not need normalizing */ 2351 appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr, 2352 atts[i].valueEnd); 2353 if (appAtts[attIndex] == 0) 2354 return XML_ERROR_NO_MEMORY; 2355 poolFinish(&tempPool); 2356 } 2357 /* handle prefixed attribute names */ | 2705 /* the value did not need normalizing */ 2706 appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr, 2707 atts[i].valueEnd); 2708 if (appAtts[attIndex] == 0) 2709 return XML_ERROR_NO_MEMORY; 2710 poolFinish(&tempPool); 2711 } 2712 /* handle prefixed attribute names */ |
2358 if (attId->prefix && tagNamePtr) { | 2713 if (attId->prefix) { |
2359 if (attId->xmlns) { 2360 /* deal with namespace declarations here */ | 2714 if (attId->xmlns) { 2715 /* deal with namespace declarations here */ |
2361 if (!addBinding(parser, attId->prefix, attId, appAtts[attIndex], 2362 bindingsPtr)) 2363 return XML_ERROR_NO_MEMORY; | 2716 enum XML_Error result = addBinding(parser, attId->prefix, attId, 2717 appAtts[attIndex], bindingsPtr); 2718 if (result) 2719 return result; |
2364 --attIndex; 2365 } 2366 else { 2367 /* deal with other prefixed names later */ 2368 attIndex++; 2369 nPrefixes++; 2370 (attId->name)[-1] = 2; 2371 } 2372 } 2373 else 2374 attIndex++; 2375 } | 2720 --attIndex; 2721 } 2722 else { 2723 /* deal with other prefixed names later */ 2724 attIndex++; 2725 nPrefixes++; 2726 (attId->name)[-1] = 2; 2727 } 2728 } 2729 else 2730 attIndex++; 2731 } |
2376 if (tagNamePtr) { 2377 int j; 2378 nSpecifiedAtts = attIndex; 2379 if (elementType->idAtt && (elementType->idAtt->name)[-1]) { 2380 for (i = 0; i < attIndex; i += 2) 2381 if (appAtts[i] == elementType->idAtt->name) { 2382 idAttIndex = i; 2383 break; | 2732 2733 /* set-up for XML_GetSpecifiedAttributeCount and XML_GetIdAttributeIndex */ 2734 nSpecifiedAtts = attIndex; 2735 if (elementType->idAtt && (elementType->idAtt->name)[-1]) { 2736 for (i = 0; i < attIndex; i += 2) 2737 if (appAtts[i] == elementType->idAtt->name) { 2738 idAttIndex = i; 2739 break; 2740 } 2741 } 2742 else 2743 idAttIndex = -1; 2744 2745 /* do attribute defaulting */ 2746 for (i = 0; i < nDefaultAtts; i++) { 2747 const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + i; 2748 if (!(da->id->name)[-1] && da->value) { 2749 if (da->id->prefix) { 2750 if (da->id->xmlns) { 2751 enum XML_Error result = addBinding(parser, da->id->prefix, da->id, 2752 da->value, bindingsPtr); 2753 if (result) 2754 return result; |
2384 } | 2755 } |
2385 } 2386 else 2387 idAttIndex = -1; 2388 /* do attribute defaulting */ 2389 for (j = 0; j < nDefaultAtts; j++) { 2390 const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + j; 2391 if (!(da->id->name)[-1] && da->value) { 2392 if (da->id->prefix) { 2393 if (da->id->xmlns) { 2394 if (!addBinding(parser, da->id->prefix, da->id, da->value, 2395 bindingsPtr)) 2396 return XML_ERROR_NO_MEMORY; 2397 } 2398 else { 2399 (da->id->name)[-1] = 2; 2400 nPrefixes++; 2401 appAtts[attIndex++] = da->id->name; 2402 appAtts[attIndex++] = da->value; 2403 } 2404 } | |
2405 else { | 2756 else { |
2406 (da->id->name)[-1] = 1; | 2757 (da->id->name)[-1] = 2; 2758 nPrefixes++; |
2407 appAtts[attIndex++] = da->id->name; 2408 appAtts[attIndex++] = da->value; 2409 } 2410 } | 2759 appAtts[attIndex++] = da->id->name; 2760 appAtts[attIndex++] = da->value; 2761 } 2762 } |
2763 else { 2764 (da->id->name)[-1] = 1; 2765 appAtts[attIndex++] = da->id->name; 2766 appAtts[attIndex++] = da->value; 2767 } |
|
2411 } | 2768 } |
2412 appAtts[attIndex] = 0; | |
2413 } | 2769 } |
2770 appAtts[attIndex] = 0; 2771 2772 /* expand prefixed attribute names, check for duplicates, 2773 and clear flags that say whether attributes were specified */ |
|
2414 i = 0; 2415 if (nPrefixes) { | 2774 i = 0; 2775 if (nPrefixes) { |
2416 /* expand prefixed attribute names */ | 2776 int j; /* hash table index */ 2777 unsigned long version = nsAttsVersion; 2778 int nsAttsSize = (int)1 << nsAttsPower; 2779 /* size of hash table must be at least 2 * (# of prefixed attributes) */ 2780 if ((nPrefixes << 1) >> nsAttsPower) { /* true for nsAttsPower = 0 */ 2781 NS_ATT *temp; 2782 /* hash table size must also be a power of 2 and >= 8 */ 2783 while (nPrefixes >> nsAttsPower++); 2784 if (nsAttsPower < 3) 2785 nsAttsPower = 3; 2786 nsAttsSize = (int)1 << nsAttsPower; 2787 temp = (NS_ATT *)REALLOC(nsAtts, nsAttsSize * sizeof(NS_ATT)); 2788 if (!temp) 2789 return XML_ERROR_NO_MEMORY; 2790 nsAtts = temp; 2791 version = 0; /* force re-initialization of nsAtts hash table */ 2792 } 2793 /* using a version flag saves us from initializing nsAtts every time */ 2794 if (!version) { /* initialize version flags when version wraps around */ 2795 version = INIT_ATTS_VERSION; 2796 for (j = nsAttsSize; j != 0; ) 2797 nsAtts[--j].version = version; 2798 } 2799 nsAttsVersion = --version; 2800 2801 /* expand prefixed names and check for duplicates */ |
2417 for (; i < attIndex; i += 2) { | 2802 for (; i < attIndex; i += 2) { |
2418 if (appAtts[i][-1] == 2) { | 2803 const XML_Char *s = appAtts[i]; 2804 if (s[-1] == 2) { /* prefixed */ |
2419 ATTRIBUTE_ID *id; | 2805 ATTRIBUTE_ID *id; |
2420 ((XML_Char *)(appAtts[i]))[-1] = 0; 2421 id = (ATTRIBUTE_ID *)lookup(&dtd.attributeIds, appAtts[i], 0); 2422 if (id->prefix->binding) { 2423 int j; 2424 const BINDING *b = id->prefix->binding; 2425 const XML_Char *s = appAtts[i]; 2426 for (j = 0; j < b->uriLen; j++) { 2427 if (!poolAppendChar(&tempPool, b->uri[j])) 2428 return XML_ERROR_NO_MEMORY; | 2806 const BINDING *b; 2807 unsigned long uriHash = 0; 2808 ((XML_Char *)s)[-1] = 0; /* clear flag */ 2809 id = (ATTRIBUTE_ID *)lookup(&dtd->attributeIds, s, 0); 2810 b = id->prefix->binding; 2811 if (!b) 2812 return XML_ERROR_UNBOUND_PREFIX; 2813 2814 /* as we expand the name we also calculate its hash value */ 2815 for (j = 0; j < b->uriLen; j++) { 2816 const XML_Char c = b->uri[j]; 2817 if (!poolAppendChar(&tempPool, c)) 2818 return XML_ERROR_NO_MEMORY; 2819 uriHash = CHAR_HASH(uriHash, c); 2820 } 2821 while (*s++ != XML_T(ASCII_COLON)) 2822 ; 2823 do { /* copies null terminator */ 2824 const XML_Char c = *s; 2825 if (!poolAppendChar(&tempPool, *s)) 2826 return XML_ERROR_NO_MEMORY; 2827 uriHash = CHAR_HASH(uriHash, c); 2828 } while (*s++); 2829 2830 { /* Check hash table for duplicate of expanded name (uriName). 2831 Derived from code in lookup(HASH_TABLE *table, ...). 2832 */ 2833 unsigned char step = 0; 2834 unsigned long mask = nsAttsSize - 1; 2835 j = uriHash & mask; /* index into hash table */ 2836 while (nsAtts[j].version == version) { 2837 /* for speed we compare stored hash values first */ 2838 if (uriHash == nsAtts[j].hash) { 2839 const XML_Char *s1 = poolStart(&tempPool); 2840 const XML_Char *s2 = nsAtts[j].uriName; 2841 /* s1 is null terminated, but not s2 */ 2842 for (; *s1 == *s2 && *s1 != 0; s1++, s2++); 2843 if (*s1 == 0) 2844 return XML_ERROR_DUPLICATE_ATTRIBUTE; 2845 } 2846 if (!step) 2847 step = PROBE_STEP(uriHash, mask, nsAttsPower); 2848 j < step ? (j += nsAttsSize - step) : (j -= step); |
2429 } | 2849 } |
2430 while (*s++ != XML_T(':')) 2431 ; | 2850 } 2851 2852 if (ns_triplets) { /* append namespace separator and prefix */ 2853 tempPool.ptr[-1] = namespaceSeparator; 2854 s = b->prefix->name; |
2432 do { 2433 if (!poolAppendChar(&tempPool, *s)) 2434 return XML_ERROR_NO_MEMORY; 2435 } while (*s++); | 2855 do { 2856 if (!poolAppendChar(&tempPool, *s)) 2857 return XML_ERROR_NO_MEMORY; 2858 } while (*s++); |
2436 if (ns_triplets) { 2437 tempPool.ptr[-1] = namespaceSeparator; 2438 s = b->prefix->name; 2439 do { 2440 if (!poolAppendChar(&tempPool, *s)) 2441 return XML_ERROR_NO_MEMORY; 2442 } while (*s++); 2443 } 2444 2445 appAtts[i] = poolStart(&tempPool); 2446 poolFinish(&tempPool); | |
2447 } | 2859 } |
2448 if (!--nPrefixes) | 2860 2861 /* store expanded name in attribute list */ 2862 s = poolStart(&tempPool); 2863 poolFinish(&tempPool); 2864 appAtts[i] = s; 2865 2866 /* fill empty slot with new version, uriName and hash value */ 2867 nsAtts[j].version = version; 2868 nsAtts[j].hash = uriHash; 2869 nsAtts[j].uriName = s; 2870 2871 if (!--nPrefixes) { 2872 i += 2; |
2449 break; | 2873 break; |
2874 } |
|
2450 } | 2875 } |
2451 else 2452 ((XML_Char *)(appAtts[i]))[-1] = 0; | 2876 else /* not prefixed */ 2877 ((XML_Char *)s)[-1] = 0; /* clear flag */ |
2453 } 2454 } | 2878 } 2879 } |
2455 /* clear the flags that say whether attributes were specified */ | 2880 /* clear flags for the remaining attributes */ |
2456 for (; i < attIndex; i += 2) 2457 ((XML_Char *)(appAtts[i]))[-1] = 0; | 2881 for (; i < attIndex; i += 2) 2882 ((XML_Char *)(appAtts[i]))[-1] = 0; |
2458 if (!tagNamePtr) 2459 return XML_ERROR_NONE; | |
2460 for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding) 2461 binding->attId->name[-1] = 0; | 2883 for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding) 2884 binding->attId->name[-1] = 0; |
2885 2886 if (!ns) 2887 return XML_ERROR_NONE; 2888 |
|
2462 /* expand the element type name */ 2463 if (elementType->prefix) { 2464 binding = elementType->prefix->binding; 2465 if (!binding) | 2889 /* expand the element type name */ 2890 if (elementType->prefix) { 2891 binding = elementType->prefix->binding; 2892 if (!binding) |
2466 return XML_ERROR_NONE; | 2893 return XML_ERROR_UNBOUND_PREFIX; |
2467 localPart = tagNamePtr->str; | 2894 localPart = tagNamePtr->str; |
2468 while (*localPart++ != XML_T(':')) | 2895 while (*localPart++ != XML_T(ASCII_COLON)) |
2469 ; 2470 } | 2896 ; 2897 } |
2471 else if (dtd.defaultPrefix.binding) { 2472 binding = dtd.defaultPrefix.binding; | 2898 else if (dtd->defaultPrefix.binding) { 2899 binding = dtd->defaultPrefix.binding; |
2473 localPart = tagNamePtr->str; 2474 } 2475 else 2476 return XML_ERROR_NONE; 2477 prefixLen = 0; | 2900 localPart = tagNamePtr->str; 2901 } 2902 else 2903 return XML_ERROR_NONE; 2904 prefixLen = 0; |
2478 if (ns && ns_triplets && binding->prefix->name) { | 2905 if (ns_triplets && binding->prefix->name) { |
2479 for (; binding->prefix->name[prefixLen++];) | 2906 for (; binding->prefix->name[prefixLen++];) |
2480 ; | 2907 ; /* prefixLen includes null terminator */ |
2481 } 2482 tagNamePtr->localPart = localPart; 2483 tagNamePtr->uriLen = binding->uriLen; 2484 tagNamePtr->prefix = binding->prefix->name; 2485 tagNamePtr->prefixLen = prefixLen; 2486 for (i = 0; localPart[i++];) | 2908 } 2909 tagNamePtr->localPart = localPart; 2910 tagNamePtr->uriLen = binding->uriLen; 2911 tagNamePtr->prefix = binding->prefix->name; 2912 tagNamePtr->prefixLen = prefixLen; 2913 for (i = 0; localPart[i++];) |
2487 ; | 2914 ; /* i includes null terminator */ |
2488 n = i + binding->uriLen + prefixLen; 2489 if (n > binding->uriAlloc) { 2490 TAG *p; | 2915 n = i + binding->uriLen + prefixLen; 2916 if (n > binding->uriAlloc) { 2917 TAG *p; |
2491 uri = MALLOC((n + EXPAND_SPARE) * sizeof(XML_Char)); | 2918 uri = (XML_Char *)MALLOC((n + EXPAND_SPARE) * sizeof(XML_Char)); |
2492 if (!uri) 2493 return XML_ERROR_NO_MEMORY; 2494 binding->uriAlloc = n + EXPAND_SPARE; 2495 memcpy(uri, binding->uri, binding->uriLen * sizeof(XML_Char)); 2496 for (p = tagStack; p; p = p->parent) 2497 if (p->name.str == binding->uri) 2498 p->name.str = uri; 2499 FREE(binding->uri); 2500 binding->uri = uri; 2501 } | 2919 if (!uri) 2920 return XML_ERROR_NO_MEMORY; 2921 binding->uriAlloc = n + EXPAND_SPARE; 2922 memcpy(uri, binding->uri, binding->uriLen * sizeof(XML_Char)); 2923 for (p = tagStack; p; p = p->parent) 2924 if (p->name.str == binding->uri) 2925 p->name.str = uri; 2926 FREE(binding->uri); 2927 binding->uri = uri; 2928 } |
2929 /* if namespaceSeparator != '\0' then uri includes it already */ |
|
2502 uri = binding->uri + binding->uriLen; 2503 memcpy(uri, localPart, i * sizeof(XML_Char)); | 2930 uri = binding->uri + binding->uriLen; 2931 memcpy(uri, localPart, i * sizeof(XML_Char)); |
2932 /* we always have a namespace separator between localPart and prefix */ |
|
2504 if (prefixLen) { | 2933 if (prefixLen) { |
2505 uri = uri + (i - 1); 2506 if (namespaceSeparator) { *(uri) = namespaceSeparator; } | 2934 uri += i - 1; 2935 *uri = namespaceSeparator; /* replace null terminator */ |
2507 memcpy(uri + 1, binding->prefix->name, prefixLen * sizeof(XML_Char)); 2508 } 2509 tagNamePtr->str = binding->uri; 2510 return XML_ERROR_NONE; 2511} 2512 | 2936 memcpy(uri + 1, binding->prefix->name, prefixLen * sizeof(XML_Char)); 2937 } 2938 tagNamePtr->str = binding->uri; 2939 return XML_ERROR_NONE; 2940} 2941 |
2513static int FASTCALL | 2942/* addBinding() overwrites the value of prefix->binding without checking. 2943 Therefore one must keep track of the old value outside of addBinding(). 2944*/ 2945static enum XML_Error |
2514addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, 2515 const XML_Char *uri, BINDING **bindingsPtr) 2516{ | 2946addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, 2947 const XML_Char *uri, BINDING **bindingsPtr) 2948{ |
2949 static const XML_Char xmlNamespace[] = { 2950 ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, 2951 ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, 2952 ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, 2953 ASCII_SLASH, ASCII_1, ASCII_9, ASCII_9, ASCII_8, ASCII_SLASH, 2954 ASCII_n, ASCII_a, ASCII_m, ASCII_e, ASCII_s, ASCII_p, ASCII_a, ASCII_c, 2955 ASCII_e, '\0' 2956 }; 2957 static const int xmlLen = 2958 (int)sizeof(xmlNamespace)/sizeof(XML_Char) - 1; 2959 static const XML_Char xmlnsNamespace[] = { 2960 ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, 2961 ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, 2962 ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_2, ASCII_0, ASCII_0, 2963 ASCII_0, ASCII_SLASH, ASCII_x, ASCII_m, ASCII_l, ASCII_n, ASCII_s, 2964 ASCII_SLASH, '\0' 2965 }; 2966 static const int xmlnsLen = 2967 (int)sizeof(xmlnsNamespace)/sizeof(XML_Char) - 1; 2968 2969 XML_Bool mustBeXML = XML_FALSE; 2970 XML_Bool isXML = XML_TRUE; 2971 XML_Bool isXMLNS = XML_TRUE; 2972 |
|
2517 BINDING *b; 2518 int len; | 2973 BINDING *b; 2974 int len; |
2519 for (len = 0; uri[len]; len++) 2520 ; | 2975 2976 /* empty URI is only valid for default namespace per XML NS 1.0 (not 1.1) */ 2977 if (*uri == XML_T('\0') && prefix->name) 2978 return XML_ERROR_UNDECLARING_PREFIX; 2979 2980 if (prefix->name 2981 && prefix->name[0] == XML_T(ASCII_x) 2982 && prefix->name[1] == XML_T(ASCII_m) 2983 && prefix->name[2] == XML_T(ASCII_l)) { 2984 2985 /* Not allowed to bind xmlns */ 2986 if (prefix->name[3] == XML_T(ASCII_n) 2987 && prefix->name[4] == XML_T(ASCII_s) 2988 && prefix->name[5] == XML_T('\0')) 2989 return XML_ERROR_RESERVED_PREFIX_XMLNS; 2990 2991 if (prefix->name[3] == XML_T('\0')) 2992 mustBeXML = XML_TRUE; 2993 } 2994 2995 for (len = 0; uri[len]; len++) { 2996 if (isXML && (len > xmlLen || uri[len] != xmlNamespace[len])) 2997 isXML = XML_FALSE; 2998 2999 if (!mustBeXML && isXMLNS 3000 && (len > xmlnsLen || uri[len] != xmlnsNamespace[len])) 3001 isXMLNS = XML_FALSE; 3002 } 3003 isXML = isXML && len == xmlLen; 3004 isXMLNS = isXMLNS && len == xmlnsLen; 3005 3006 if (mustBeXML != isXML) 3007 return mustBeXML ? XML_ERROR_RESERVED_PREFIX_XML 3008 : XML_ERROR_RESERVED_NAMESPACE_URI; 3009 3010 if (isXMLNS) 3011 return XML_ERROR_RESERVED_NAMESPACE_URI; 3012 |
2521 if (namespaceSeparator) 2522 len++; 2523 if (freeBindingList) { 2524 b = freeBindingList; 2525 if (len > b->uriAlloc) { | 3013 if (namespaceSeparator) 3014 len++; 3015 if (freeBindingList) { 3016 b = freeBindingList; 3017 if (len > b->uriAlloc) { |
2526 XML_Char *temp = REALLOC(b->uri, 2527 sizeof(XML_Char) * (len + EXPAND_SPARE)); | 3018 XML_Char *temp = (XML_Char *)REALLOC(b->uri, 3019 sizeof(XML_Char) * (len + EXPAND_SPARE)); |
2528 if (temp == NULL) | 3020 if (temp == NULL) |
2529 return 0; | 3021 return XML_ERROR_NO_MEMORY; |
2530 b->uri = temp; 2531 b->uriAlloc = len + EXPAND_SPARE; 2532 } 2533 freeBindingList = b->nextTagBinding; 2534 } 2535 else { | 3022 b->uri = temp; 3023 b->uriAlloc = len + EXPAND_SPARE; 3024 } 3025 freeBindingList = b->nextTagBinding; 3026 } 3027 else { |
2536 b = MALLOC(sizeof(BINDING)); | 3028 b = (BINDING *)MALLOC(sizeof(BINDING)); |
2537 if (!b) | 3029 if (!b) |
2538 return 0; 2539 b->uri = MALLOC(sizeof(XML_Char) * (len + EXPAND_SPARE)); | 3030 return XML_ERROR_NO_MEMORY; 3031 b->uri = (XML_Char *)MALLOC(sizeof(XML_Char) * (len + EXPAND_SPARE)); |
2540 if (!b->uri) { 2541 FREE(b); | 3032 if (!b->uri) { 3033 FREE(b); |
2542 return 0; | 3034 return XML_ERROR_NO_MEMORY; |
2543 } 2544 b->uriAlloc = len + EXPAND_SPARE; 2545 } 2546 b->uriLen = len; 2547 memcpy(b->uri, uri, len * sizeof(XML_Char)); 2548 if (namespaceSeparator) 2549 b->uri[len - 1] = namespaceSeparator; 2550 b->prefix = prefix; 2551 b->attId = attId; 2552 b->prevPrefixBinding = prefix->binding; | 3035 } 3036 b->uriAlloc = len + EXPAND_SPARE; 3037 } 3038 b->uriLen = len; 3039 memcpy(b->uri, uri, len * sizeof(XML_Char)); 3040 if (namespaceSeparator) 3041 b->uri[len - 1] = namespaceSeparator; 3042 b->prefix = prefix; 3043 b->attId = attId; 3044 b->prevPrefixBinding = prefix->binding; |
2553 if (*uri == XML_T('\0') && prefix == &dtd.defaultPrefix) | 3045 /* NULL binding when default namespace undeclared */ 3046 if (*uri == XML_T('\0') && prefix == &_dtd->defaultPrefix) |
2554 prefix->binding = NULL; 2555 else 2556 prefix->binding = b; 2557 b->nextTagBinding = *bindingsPtr; 2558 *bindingsPtr = b; | 3047 prefix->binding = NULL; 3048 else 3049 prefix->binding = b; 3050 b->nextTagBinding = *bindingsPtr; 3051 *bindingsPtr = b; |
2559 if (startNamespaceDeclHandler) | 3052 /* if attId == NULL then we are not starting a namespace scope */ 3053 if (attId && startNamespaceDeclHandler) |
2560 startNamespaceDeclHandler(handlerArg, prefix->name, 2561 prefix->binding ? uri : 0); | 3054 startNamespaceDeclHandler(handlerArg, prefix->name, 3055 prefix->binding ? uri : 0); |
2562 return 1; | 3056 return XML_ERROR_NONE; |
2563} 2564 2565/* The idea here is to avoid using stack for each CDATA section when 2566 the whole file is parsed with one call. 2567*/ | 3057} 3058 3059/* The idea here is to avoid using stack for each CDATA section when 3060 the whole file is parsed with one call. 3061*/ |
2568static enum XML_Error FASTCALL | 3062static enum XML_Error PTRCALL |
2569cdataSectionProcessor(XML_Parser parser, 2570 const char *start, 2571 const char *end, 2572 const char **endPtr) 2573{ | 3063cdataSectionProcessor(XML_Parser parser, 3064 const char *start, 3065 const char *end, 3066 const char **endPtr) 3067{ |
2574 enum XML_Error result = doCdataSection(parser, encoding, &start, 2575 end, endPtr); | 3068 enum XML_Error result = doCdataSection(parser, encoding, &start, end, 3069 endPtr, (XML_Bool)!ps_finalBuffer); 3070 if (result != XML_ERROR_NONE) 3071 return result; |
2576 if (start) { 2577 if (parentParser) { /* we are parsing an external entity */ 2578 processor = externalEntityContentProcessor; 2579 return externalEntityContentProcessor(parser, start, end, endPtr); 2580 } 2581 else { 2582 processor = contentProcessor; 2583 return contentProcessor(parser, start, end, endPtr); 2584 } 2585 } 2586 return result; 2587} 2588 | 3072 if (start) { 3073 if (parentParser) { /* we are parsing an external entity */ 3074 processor = externalEntityContentProcessor; 3075 return externalEntityContentProcessor(parser, start, end, endPtr); 3076 } 3077 else { 3078 processor = contentProcessor; 3079 return contentProcessor(parser, start, end, endPtr); 3080 } 3081 } 3082 return result; 3083} 3084 |
2589/* startPtr gets set to non-null is the section is closed, and to null if | 3085/* startPtr gets set to non-null if the section is closed, and to null if |
2590 the section is not yet closed. 2591*/ | 3086 the section is not yet closed. 3087*/ |
2592static enum XML_Error FASTCALL | 3088static enum XML_Error |
2593doCdataSection(XML_Parser parser, 2594 const ENCODING *enc, 2595 const char **startPtr, 2596 const char *end, | 3089doCdataSection(XML_Parser parser, 3090 const ENCODING *enc, 3091 const char **startPtr, 3092 const char *end, |
2597 const char **nextPtr) | 3093 const char **nextPtr, 3094 XML_Bool haveMore) |
2598{ 2599 const char *s = *startPtr; 2600 const char **eventPP; 2601 const char **eventEndPP; 2602 if (enc == encoding) { 2603 eventPP = &eventPtr; 2604 *eventPP = s; 2605 eventEndPP = &eventEndPtr; 2606 } 2607 else { 2608 eventPP = &(openInternalEntities->internalEventPtr); 2609 eventEndPP = &(openInternalEntities->internalEventEndPtr); 2610 } 2611 *eventPP = s; 2612 *startPtr = NULL; | 3095{ 3096 const char *s = *startPtr; 3097 const char **eventPP; 3098 const char **eventEndPP; 3099 if (enc == encoding) { 3100 eventPP = &eventPtr; 3101 *eventPP = s; 3102 eventEndPP = &eventEndPtr; 3103 } 3104 else { 3105 eventPP = &(openInternalEntities->internalEventPtr); 3106 eventEndPP = &(openInternalEntities->internalEventEndPtr); 3107 } 3108 *eventPP = s; 3109 *startPtr = NULL; |
3110 |
|
2613 for (;;) { 2614 const char *next; 2615 int tok = XmlCdataSectionTok(enc, s, end, &next); 2616 *eventEndPP = next; 2617 switch (tok) { 2618 case XML_TOK_CDATA_SECT_CLOSE: 2619 if (endCdataSectionHandler) 2620 endCdataSectionHandler(handlerArg); 2621#if 0 2622 /* see comment under XML_TOK_CDATA_SECT_OPEN */ 2623 else if (characterDataHandler) 2624 characterDataHandler(handlerArg, dataBuf, 0); 2625#endif 2626 else if (defaultHandler) 2627 reportDefault(parser, enc, s, next); 2628 *startPtr = next; | 3111 for (;;) { 3112 const char *next; 3113 int tok = XmlCdataSectionTok(enc, s, end, &next); 3114 *eventEndPP = next; 3115 switch (tok) { 3116 case XML_TOK_CDATA_SECT_CLOSE: 3117 if (endCdataSectionHandler) 3118 endCdataSectionHandler(handlerArg); 3119#if 0 3120 /* see comment under XML_TOK_CDATA_SECT_OPEN */ 3121 else if (characterDataHandler) 3122 characterDataHandler(handlerArg, dataBuf, 0); 3123#endif 3124 else if (defaultHandler) 3125 reportDefault(parser, enc, s, next); 3126 *startPtr = next; |
2629 return XML_ERROR_NONE; | 3127 *nextPtr = next; 3128 if (ps_parsing == XML_FINISHED) 3129 return XML_ERROR_ABORTED; 3130 else 3131 return XML_ERROR_NONE; |
2630 case XML_TOK_DATA_NEWLINE: 2631 if (characterDataHandler) { 2632 XML_Char c = 0xA; 2633 characterDataHandler(handlerArg, &c, 1); 2634 } 2635 else if (defaultHandler) 2636 reportDefault(parser, enc, s, next); 2637 break; 2638 case XML_TOK_DATA_CHARS: | 3132 case XML_TOK_DATA_NEWLINE: 3133 if (characterDataHandler) { 3134 XML_Char c = 0xA; 3135 characterDataHandler(handlerArg, &c, 1); 3136 } 3137 else if (defaultHandler) 3138 reportDefault(parser, enc, s, next); 3139 break; 3140 case XML_TOK_DATA_CHARS: |
2639 if (characterDataHandler) { 2640 if (MUST_CONVERT(enc, s)) { 2641 for (;;) { 2642 ICHAR *dataPtr = (ICHAR *)dataBuf; 2643 XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); 2644 *eventEndPP = next; 2645 characterDataHandler(handlerArg, dataBuf, 2646 dataPtr - (ICHAR *)dataBuf); 2647 if (s == next) 2648 break; 2649 *eventPP = s; | 3141 { 3142 XML_CharacterDataHandler charDataHandler = characterDataHandler; 3143 if (charDataHandler) { 3144 if (MUST_CONVERT(enc, s)) { 3145 for (;;) { 3146 ICHAR *dataPtr = (ICHAR *)dataBuf; 3147 XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); 3148 *eventEndPP = next; 3149 charDataHandler(handlerArg, dataBuf, 3150 (int)(dataPtr - (ICHAR *)dataBuf)); 3151 if (s == next) 3152 break; 3153 *eventPP = s; 3154 } |
2650 } | 3155 } |
3156 else 3157 charDataHandler(handlerArg, 3158 (XML_Char *)s, 3159 (int)((XML_Char *)next - (XML_Char *)s)); |
|
2651 } | 3160 } |
2652 else 2653 characterDataHandler(handlerArg, 2654 (XML_Char *)s, 2655 (XML_Char *)next - (XML_Char *)s); | 3161 else if (defaultHandler) 3162 reportDefault(parser, enc, s, next); |
2656 } | 3163 } |
2657 else if (defaultHandler) 2658 reportDefault(parser, enc, s, next); | |
2659 break; 2660 case XML_TOK_INVALID: 2661 *eventPP = next; 2662 return XML_ERROR_INVALID_TOKEN; 2663 case XML_TOK_PARTIAL_CHAR: | 3164 break; 3165 case XML_TOK_INVALID: 3166 *eventPP = next; 3167 return XML_ERROR_INVALID_TOKEN; 3168 case XML_TOK_PARTIAL_CHAR: |
2664 if (nextPtr) { | 3169 if (haveMore) { |
2665 *nextPtr = s; 2666 return XML_ERROR_NONE; 2667 } 2668 return XML_ERROR_PARTIAL_CHAR; 2669 case XML_TOK_PARTIAL: 2670 case XML_TOK_NONE: | 3170 *nextPtr = s; 3171 return XML_ERROR_NONE; 3172 } 3173 return XML_ERROR_PARTIAL_CHAR; 3174 case XML_TOK_PARTIAL: 3175 case XML_TOK_NONE: |
2671 if (nextPtr) { | 3176 if (haveMore) { |
2672 *nextPtr = s; 2673 return XML_ERROR_NONE; 2674 } 2675 return XML_ERROR_UNCLOSED_CDATA_SECTION; 2676 default: 2677 *eventPP = next; 2678 return XML_ERROR_UNEXPECTED_STATE; 2679 } | 3177 *nextPtr = s; 3178 return XML_ERROR_NONE; 3179 } 3180 return XML_ERROR_UNCLOSED_CDATA_SECTION; 3181 default: 3182 *eventPP = next; 3183 return XML_ERROR_UNEXPECTED_STATE; 3184 } |
3185 |
|
2680 *eventPP = s = next; | 3186 *eventPP = s = next; |
3187 switch (ps_parsing) { 3188 case XML_SUSPENDED: 3189 *nextPtr = next; 3190 return XML_ERROR_NONE; 3191 case XML_FINISHED: 3192 return XML_ERROR_ABORTED; 3193 default: ; 3194 } |
|
2681 } 2682 /* not reached */ 2683} 2684 2685#ifdef XML_DTD 2686 2687/* The idea here is to avoid using stack for each IGNORE section when 2688 the whole file is parsed with one call. 2689*/ | 3195 } 3196 /* not reached */ 3197} 3198 3199#ifdef XML_DTD 3200 3201/* The idea here is to avoid using stack for each IGNORE section when 3202 the whole file is parsed with one call. 3203*/ |
2690static enum XML_Error FASTCALL | 3204static enum XML_Error PTRCALL |
2691ignoreSectionProcessor(XML_Parser parser, 2692 const char *start, 2693 const char *end, 2694 const char **endPtr) 2695{ | 3205ignoreSectionProcessor(XML_Parser parser, 3206 const char *start, 3207 const char *end, 3208 const char **endPtr) 3209{ |
2696 enum XML_Error result = doIgnoreSection(parser, encoding, &start, 2697 end, endPtr); | 3210 enum XML_Error result = doIgnoreSection(parser, encoding, &start, end, 3211 endPtr, (XML_Bool)!ps_finalBuffer); 3212 if (result != XML_ERROR_NONE) 3213 return result; |
2698 if (start) { 2699 processor = prologProcessor; 2700 return prologProcessor(parser, start, end, endPtr); 2701 } 2702 return result; 2703} 2704 2705/* startPtr gets set to non-null is the section is closed, and to null 2706 if the section is not yet closed. 2707*/ | 3214 if (start) { 3215 processor = prologProcessor; 3216 return prologProcessor(parser, start, end, endPtr); 3217 } 3218 return result; 3219} 3220 3221/* startPtr gets set to non-null is the section is closed, and to null 3222 if the section is not yet closed. 3223*/ |
2708static enum XML_Error FASTCALL | 3224static enum XML_Error |
2709doIgnoreSection(XML_Parser parser, 2710 const ENCODING *enc, 2711 const char **startPtr, 2712 const char *end, | 3225doIgnoreSection(XML_Parser parser, 3226 const ENCODING *enc, 3227 const char **startPtr, 3228 const char *end, |
2713 const char **nextPtr) | 3229 const char **nextPtr, 3230 XML_Bool haveMore) |
2714{ 2715 const char *next; 2716 int tok; 2717 const char *s = *startPtr; 2718 const char **eventPP; 2719 const char **eventEndPP; 2720 if (enc == encoding) { 2721 eventPP = &eventPtr; --- 8 unchanged lines hidden (view full) --- 2730 *startPtr = NULL; 2731 tok = XmlIgnoreSectionTok(enc, s, end, &next); 2732 *eventEndPP = next; 2733 switch (tok) { 2734 case XML_TOK_IGNORE_SECT: 2735 if (defaultHandler) 2736 reportDefault(parser, enc, s, next); 2737 *startPtr = next; | 3231{ 3232 const char *next; 3233 int tok; 3234 const char *s = *startPtr; 3235 const char **eventPP; 3236 const char **eventEndPP; 3237 if (enc == encoding) { 3238 eventPP = &eventPtr; --- 8 unchanged lines hidden (view full) --- 3247 *startPtr = NULL; 3248 tok = XmlIgnoreSectionTok(enc, s, end, &next); 3249 *eventEndPP = next; 3250 switch (tok) { 3251 case XML_TOK_IGNORE_SECT: 3252 if (defaultHandler) 3253 reportDefault(parser, enc, s, next); 3254 *startPtr = next; |
2738 return XML_ERROR_NONE; | 3255 *nextPtr = next; 3256 if (ps_parsing == XML_FINISHED) 3257 return XML_ERROR_ABORTED; 3258 else 3259 return XML_ERROR_NONE; |
2739 case XML_TOK_INVALID: 2740 *eventPP = next; 2741 return XML_ERROR_INVALID_TOKEN; 2742 case XML_TOK_PARTIAL_CHAR: | 3260 case XML_TOK_INVALID: 3261 *eventPP = next; 3262 return XML_ERROR_INVALID_TOKEN; 3263 case XML_TOK_PARTIAL_CHAR: |
2743 if (nextPtr) { | 3264 if (haveMore) { |
2744 *nextPtr = s; 2745 return XML_ERROR_NONE; 2746 } 2747 return XML_ERROR_PARTIAL_CHAR; 2748 case XML_TOK_PARTIAL: 2749 case XML_TOK_NONE: | 3265 *nextPtr = s; 3266 return XML_ERROR_NONE; 3267 } 3268 return XML_ERROR_PARTIAL_CHAR; 3269 case XML_TOK_PARTIAL: 3270 case XML_TOK_NONE: |
2750 if (nextPtr) { | 3271 if (haveMore) { |
2751 *nextPtr = s; 2752 return XML_ERROR_NONE; 2753 } 2754 return XML_ERROR_SYNTAX; /* XML_ERROR_UNCLOSED_IGNORE_SECTION */ 2755 default: 2756 *eventPP = next; 2757 return XML_ERROR_UNEXPECTED_STATE; 2758 } 2759 /* not reached */ 2760} 2761 2762#endif /* XML_DTD */ 2763 | 3272 *nextPtr = s; 3273 return XML_ERROR_NONE; 3274 } 3275 return XML_ERROR_SYNTAX; /* XML_ERROR_UNCLOSED_IGNORE_SECTION */ 3276 default: 3277 *eventPP = next; 3278 return XML_ERROR_UNEXPECTED_STATE; 3279 } 3280 /* not reached */ 3281} 3282 3283#endif /* XML_DTD */ 3284 |
2764static enum XML_Error FASTCALL | 3285static enum XML_Error |
2765initializeEncoding(XML_Parser parser) 2766{ 2767 const char *s; 2768#ifdef XML_UNICODE 2769 char encodingBuf[128]; 2770 if (!protocolEncodingName) 2771 s = NULL; 2772 else { --- 12 unchanged lines hidden (view full) --- 2785#else 2786 s = protocolEncodingName; 2787#endif 2788 if ((ns ? XmlInitEncodingNS : XmlInitEncoding)(&initEncoding, &encoding, s)) 2789 return XML_ERROR_NONE; 2790 return handleUnknownEncoding(parser, protocolEncodingName); 2791} 2792 | 3286initializeEncoding(XML_Parser parser) 3287{ 3288 const char *s; 3289#ifdef XML_UNICODE 3290 char encodingBuf[128]; 3291 if (!protocolEncodingName) 3292 s = NULL; 3293 else { --- 12 unchanged lines hidden (view full) --- 3306#else 3307 s = protocolEncodingName; 3308#endif 3309 if ((ns ? XmlInitEncodingNS : XmlInitEncoding)(&initEncoding, &encoding, s)) 3310 return XML_ERROR_NONE; 3311 return handleUnknownEncoding(parser, protocolEncodingName); 3312} 3313 |
2793static enum XML_Error FASTCALL | 3314static enum XML_Error |
2794processXmlDecl(XML_Parser parser, int isGeneralTextEntity, 2795 const char *s, const char *next) 2796{ 2797 const char *encodingName = NULL; 2798 const XML_Char *storedEncName = NULL; 2799 const ENCODING *newEncoding = NULL; 2800 const char *version = NULL; 2801 const char *versionend; --- 5 unchanged lines hidden (view full) --- 2807 encoding, 2808 s, 2809 next, 2810 &eventPtr, 2811 &version, 2812 &versionend, 2813 &encodingName, 2814 &newEncoding, | 3315processXmlDecl(XML_Parser parser, int isGeneralTextEntity, 3316 const char *s, const char *next) 3317{ 3318 const char *encodingName = NULL; 3319 const XML_Char *storedEncName = NULL; 3320 const ENCODING *newEncoding = NULL; 3321 const char *version = NULL; 3322 const char *versionend; --- 5 unchanged lines hidden (view full) --- 3328 encoding, 3329 s, 3330 next, 3331 &eventPtr, 3332 &version, 3333 &versionend, 3334 &encodingName, 3335 &newEncoding, |
2815 &standalone)) 2816 return XML_ERROR_SYNTAX; | 3336 &standalone)) { 3337 if (isGeneralTextEntity) 3338 return XML_ERROR_TEXT_DECL; 3339 else 3340 return XML_ERROR_XML_DECL; 3341 } |
2817 if (!isGeneralTextEntity && standalone == 1) { | 3342 if (!isGeneralTextEntity && standalone == 1) { |
2818 dtd.standalone = XML_TRUE; | 3343 _dtd->standalone = XML_TRUE; |
2819#ifdef XML_DTD 2820 if (paramEntityParsing == XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE) 2821 paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; 2822#endif /* XML_DTD */ 2823 } 2824 if (xmlDeclHandler) { 2825 if (encodingName != NULL) { 2826 storedEncName = poolStoreString(&temp2Pool, --- 43 unchanged lines hidden (view full) --- 2870 } 2871 2872 if (storedEncName || storedversion) 2873 poolClear(&temp2Pool); 2874 2875 return XML_ERROR_NONE; 2876} 2877 | 3344#ifdef XML_DTD 3345 if (paramEntityParsing == XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE) 3346 paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; 3347#endif /* XML_DTD */ 3348 } 3349 if (xmlDeclHandler) { 3350 if (encodingName != NULL) { 3351 storedEncName = poolStoreString(&temp2Pool, --- 43 unchanged lines hidden (view full) --- 3395 } 3396 3397 if (storedEncName || storedversion) 3398 poolClear(&temp2Pool); 3399 3400 return XML_ERROR_NONE; 3401} 3402 |
2878static enum XML_Error FASTCALL | 3403static enum XML_Error |
2879handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName) 2880{ 2881 if (unknownEncodingHandler) { 2882 XML_Encoding info; 2883 int i; 2884 for (i = 0; i < 256; i++) 2885 info.map[i] = -1; 2886 info.convert = NULL; --- 22 unchanged lines hidden (view full) --- 2909 } 2910 } 2911 if (info.release != NULL) 2912 info.release(info.data); 2913 } 2914 return XML_ERROR_UNKNOWN_ENCODING; 2915} 2916 | 3404handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName) 3405{ 3406 if (unknownEncodingHandler) { 3407 XML_Encoding info; 3408 int i; 3409 for (i = 0; i < 256; i++) 3410 info.map[i] = -1; 3411 info.convert = NULL; --- 22 unchanged lines hidden (view full) --- 3434 } 3435 } 3436 if (info.release != NULL) 3437 info.release(info.data); 3438 } 3439 return XML_ERROR_UNKNOWN_ENCODING; 3440} 3441 |
2917static enum XML_Error FASTCALL | 3442static enum XML_Error PTRCALL |
2918prologInitProcessor(XML_Parser parser, 2919 const char *s, 2920 const char *end, 2921 const char **nextPtr) 2922{ 2923 enum XML_Error result = initializeEncoding(parser); 2924 if (result != XML_ERROR_NONE) 2925 return result; 2926 processor = prologProcessor; 2927 return prologProcessor(parser, s, end, nextPtr); 2928} 2929 2930#ifdef XML_DTD 2931 | 3443prologInitProcessor(XML_Parser parser, 3444 const char *s, 3445 const char *end, 3446 const char **nextPtr) 3447{ 3448 enum XML_Error result = initializeEncoding(parser); 3449 if (result != XML_ERROR_NONE) 3450 return result; 3451 processor = prologProcessor; 3452 return prologProcessor(parser, s, end, nextPtr); 3453} 3454 3455#ifdef XML_DTD 3456 |
2932static enum XML_Error FASTCALL | 3457static enum XML_Error PTRCALL |
2933externalParEntInitProcessor(XML_Parser parser, 2934 const char *s, 2935 const char *end, 2936 const char **nextPtr) 2937{ 2938 enum XML_Error result = initializeEncoding(parser); 2939 if (result != XML_ERROR_NONE) 2940 return result; 2941 2942 /* we know now that XML_Parse(Buffer) has been called, 2943 so we consider the external parameter entity read */ | 3458externalParEntInitProcessor(XML_Parser parser, 3459 const char *s, 3460 const char *end, 3461 const char **nextPtr) 3462{ 3463 enum XML_Error result = initializeEncoding(parser); 3464 if (result != XML_ERROR_NONE) 3465 return result; 3466 3467 /* we know now that XML_Parse(Buffer) has been called, 3468 so we consider the external parameter entity read */ |
2944 dtd.paramEntityRead = XML_TRUE; | 3469 _dtd->paramEntityRead = XML_TRUE; |
2945 2946 if (prologState.inEntityValue) { 2947 processor = entityValueInitProcessor; 2948 return entityValueInitProcessor(parser, s, end, nextPtr); 2949 } 2950 else { 2951 processor = externalParEntProcessor; 2952 return externalParEntProcessor(parser, s, end, nextPtr); 2953 } 2954} 2955 | 3470 3471 if (prologState.inEntityValue) { 3472 processor = entityValueInitProcessor; 3473 return entityValueInitProcessor(parser, s, end, nextPtr); 3474 } 3475 else { 3476 processor = externalParEntProcessor; 3477 return externalParEntProcessor(parser, s, end, nextPtr); 3478 } 3479} 3480 |
2956static enum XML_Error FASTCALL | 3481static enum XML_Error PTRCALL |
2957entityValueInitProcessor(XML_Parser parser, 2958 const char *s, 2959 const char *end, 2960 const char **nextPtr) 2961{ | 3482entityValueInitProcessor(XML_Parser parser, 3483 const char *s, 3484 const char *end, 3485 const char **nextPtr) 3486{ |
2962 const char *start = s; 2963 const char *next = s; | |
2964 int tok; | 3487 int tok; |
3488 const char *start = s; 3489 const char *next = start; 3490 eventPtr = start; |
|
2965 | 3491 |
2966 for (;;) { | 3492 for (;;) { |
2967 tok = XmlPrologTok(encoding, start, end, &next); | 3493 tok = XmlPrologTok(encoding, start, end, &next); |
3494 eventEndPtr = next; |
|
2968 if (tok <= 0) { | 3495 if (tok <= 0) { |
2969 if (nextPtr != 0 && tok != XML_TOK_INVALID) { 2970 *nextPtr = s; 2971 return XML_ERROR_NONE; | 3496 if (!ps_finalBuffer && tok != XML_TOK_INVALID) { 3497 *nextPtr = s; 3498 return XML_ERROR_NONE; |
2972 } 2973 switch (tok) { 2974 case XML_TOK_INVALID: | 3499 } 3500 switch (tok) { 3501 case XML_TOK_INVALID: |
2975 return XML_ERROR_INVALID_TOKEN; | 3502 return XML_ERROR_INVALID_TOKEN; |
2976 case XML_TOK_PARTIAL: | 3503 case XML_TOK_PARTIAL: |
2977 return XML_ERROR_UNCLOSED_TOKEN; | 3504 return XML_ERROR_UNCLOSED_TOKEN; |
2978 case XML_TOK_PARTIAL_CHAR: | 3505 case XML_TOK_PARTIAL_CHAR: |
2979 return XML_ERROR_PARTIAL_CHAR; | 3506 return XML_ERROR_PARTIAL_CHAR; |
2980 case XML_TOK_NONE: /* start == end */ 2981 default: 2982 break; 2983 } | 3507 case XML_TOK_NONE: /* start == end */ 3508 default: 3509 break; 3510 } |
3511 /* found end of entity value - can store it now */ |
|
2984 return storeEntityValue(parser, encoding, s, end); 2985 } 2986 else if (tok == XML_TOK_XML_DECL) { | 3512 return storeEntityValue(parser, encoding, s, end); 3513 } 3514 else if (tok == XML_TOK_XML_DECL) { |
2987 enum XML_Error result = processXmlDecl(parser, 0, start, next); 2988 if (result != XML_ERROR_NONE) 2989 return result; 2990 if (nextPtr) *nextPtr = next; | 3515 enum XML_Error result; 3516 result = processXmlDecl(parser, 0, start, next); 3517 if (result != XML_ERROR_NONE) 3518 return result; 3519 switch (ps_parsing) { 3520 case XML_SUSPENDED: 3521 *nextPtr = next; 3522 return XML_ERROR_NONE; 3523 case XML_FINISHED: 3524 return XML_ERROR_ABORTED; 3525 default: 3526 *nextPtr = next; 3527 } |
2991 /* stop scanning for text declaration - we found one */ 2992 processor = entityValueProcessor; 2993 return entityValueProcessor(parser, next, end, nextPtr); 2994 } 2995 /* If we are at the end of the buffer, this would cause XmlPrologTok to 2996 return XML_TOK_NONE on the next call, which would then cause the 2997 function to exit with *nextPtr set to s - that is what we want for other 2998 tokens, but not for the BOM - we would rather like to skip it; 2999 then, when this routine is entered the next time, XmlPrologTok will 3000 return XML_TOK_INVALID, since the BOM is still in the buffer 3001 */ | 3528 /* stop scanning for text declaration - we found one */ 3529 processor = entityValueProcessor; 3530 return entityValueProcessor(parser, next, end, nextPtr); 3531 } 3532 /* If we are at the end of the buffer, this would cause XmlPrologTok to 3533 return XML_TOK_NONE on the next call, which would then cause the 3534 function to exit with *nextPtr set to s - that is what we want for other 3535 tokens, but not for the BOM - we would rather like to skip it; 3536 then, when this routine is entered the next time, XmlPrologTok will 3537 return XML_TOK_INVALID, since the BOM is still in the buffer 3538 */ |
3002 else if (tok == XML_TOK_BOM && next == end && nextPtr) { | 3539 else if (tok == XML_TOK_BOM && next == end && !ps_finalBuffer) { |
3003 *nextPtr = next; 3004 return XML_ERROR_NONE; 3005 } 3006 start = next; | 3540 *nextPtr = next; 3541 return XML_ERROR_NONE; 3542 } 3543 start = next; |
3544 eventPtr = start; |
|
3007 } 3008} 3009 | 3545 } 3546} 3547 |
3010static enum XML_Error FASTCALL | 3548static enum XML_Error PTRCALL |
3011externalParEntProcessor(XML_Parser parser, 3012 const char *s, 3013 const char *end, 3014 const char **nextPtr) 3015{ | 3549externalParEntProcessor(XML_Parser parser, 3550 const char *s, 3551 const char *end, 3552 const char **nextPtr) 3553{ |
3016 const char *start = s; | |
3017 const char *next = s; 3018 int tok; 3019 | 3554 const char *next = s; 3555 int tok; 3556 |
3020 tok = XmlPrologTok(encoding, start, end, &next); | 3557 tok = XmlPrologTok(encoding, s, end, &next); |
3021 if (tok <= 0) { | 3558 if (tok <= 0) { |
3022 if (nextPtr != 0 && tok != XML_TOK_INVALID) { | 3559 if (!ps_finalBuffer && tok != XML_TOK_INVALID) { |
3023 *nextPtr = s; 3024 return XML_ERROR_NONE; 3025 } 3026 switch (tok) { 3027 case XML_TOK_INVALID: 3028 return XML_ERROR_INVALID_TOKEN; 3029 case XML_TOK_PARTIAL: 3030 return XML_ERROR_UNCLOSED_TOKEN; --- 9 unchanged lines hidden (view full) --- 3040 as valid, and report a syntax error, so we have to skip the BOM 3041 */ 3042 else if (tok == XML_TOK_BOM) { 3043 s = next; 3044 tok = XmlPrologTok(encoding, s, end, &next); 3045 } 3046 3047 processor = prologProcessor; | 3560 *nextPtr = s; 3561 return XML_ERROR_NONE; 3562 } 3563 switch (tok) { 3564 case XML_TOK_INVALID: 3565 return XML_ERROR_INVALID_TOKEN; 3566 case XML_TOK_PARTIAL: 3567 return XML_ERROR_UNCLOSED_TOKEN; --- 9 unchanged lines hidden (view full) --- 3577 as valid, and report a syntax error, so we have to skip the BOM 3578 */ 3579 else if (tok == XML_TOK_BOM) { 3580 s = next; 3581 tok = XmlPrologTok(encoding, s, end, &next); 3582 } 3583 3584 processor = prologProcessor; |
3048 return doProlog(parser, encoding, s, end, tok, next, nextPtr); | 3585 return doProlog(parser, encoding, s, end, tok, next, 3586 nextPtr, (XML_Bool)!ps_finalBuffer); |
3049} 3050 | 3587} 3588 |
3051static enum XML_Error FASTCALL | 3589static enum XML_Error PTRCALL |
3052entityValueProcessor(XML_Parser parser, 3053 const char *s, 3054 const char *end, 3055 const char **nextPtr) 3056{ 3057 const char *start = s; 3058 const char *next = s; 3059 const ENCODING *enc = encoding; 3060 int tok; 3061 3062 for (;;) { 3063 tok = XmlPrologTok(enc, start, end, &next); 3064 if (tok <= 0) { | 3590entityValueProcessor(XML_Parser parser, 3591 const char *s, 3592 const char *end, 3593 const char **nextPtr) 3594{ 3595 const char *start = s; 3596 const char *next = s; 3597 const ENCODING *enc = encoding; 3598 int tok; 3599 3600 for (;;) { 3601 tok = XmlPrologTok(enc, start, end, &next); 3602 if (tok <= 0) { |
3065 if (nextPtr != 0 && tok != XML_TOK_INVALID) { | 3603 if (!ps_finalBuffer && tok != XML_TOK_INVALID) { |
3066 *nextPtr = s; 3067 return XML_ERROR_NONE; 3068 } 3069 switch (tok) { 3070 case XML_TOK_INVALID: | 3604 *nextPtr = s; 3605 return XML_ERROR_NONE; 3606 } 3607 switch (tok) { 3608 case XML_TOK_INVALID: |
3071 return XML_ERROR_INVALID_TOKEN; | 3609 return XML_ERROR_INVALID_TOKEN; |
3072 case XML_TOK_PARTIAL: | 3610 case XML_TOK_PARTIAL: |
3073 return XML_ERROR_UNCLOSED_TOKEN; | 3611 return XML_ERROR_UNCLOSED_TOKEN; |
3074 case XML_TOK_PARTIAL_CHAR: | 3612 case XML_TOK_PARTIAL_CHAR: |
3075 return XML_ERROR_PARTIAL_CHAR; | 3613 return XML_ERROR_PARTIAL_CHAR; |
3076 case XML_TOK_NONE: /* start == end */ 3077 default: 3078 break; 3079 } | 3614 case XML_TOK_NONE: /* start == end */ 3615 default: 3616 break; 3617 } |
3618 /* found end of entity value - can store it now */ |
|
3080 return storeEntityValue(parser, enc, s, end); 3081 } 3082 start = next; 3083 } 3084} 3085 3086#endif /* XML_DTD */ 3087 | 3619 return storeEntityValue(parser, enc, s, end); 3620 } 3621 start = next; 3622 } 3623} 3624 3625#endif /* XML_DTD */ 3626 |
3088static enum XML_Error FASTCALL | 3627static enum XML_Error PTRCALL |
3089prologProcessor(XML_Parser parser, 3090 const char *s, 3091 const char *end, 3092 const char **nextPtr) 3093{ 3094 const char *next = s; 3095 int tok = XmlPrologTok(encoding, s, end, &next); | 3628prologProcessor(XML_Parser parser, 3629 const char *s, 3630 const char *end, 3631 const char **nextPtr) 3632{ 3633 const char *next = s; 3634 int tok = XmlPrologTok(encoding, s, end, &next); |
3096 return doProlog(parser, encoding, s, end, tok, next, nextPtr); | 3635 return doProlog(parser, encoding, s, end, tok, next, 3636 nextPtr, (XML_Bool)!ps_finalBuffer); |
3097} 3098 | 3637} 3638 |
3099static enum XML_Error FASTCALL | 3639static enum XML_Error |
3100doProlog(XML_Parser parser, 3101 const ENCODING *enc, 3102 const char *s, 3103 const char *end, 3104 int tok, 3105 const char *next, | 3640doProlog(XML_Parser parser, 3641 const ENCODING *enc, 3642 const char *s, 3643 const char *end, 3644 int tok, 3645 const char *next, |
3106 const char **nextPtr) | 3646 const char **nextPtr, 3647 XML_Bool haveMore) |
3107{ 3108#ifdef XML_DTD | 3648{ 3649#ifdef XML_DTD |
3109 static const XML_Char externalSubsetName[] = { '#' , '\0' }; | 3650 static const XML_Char externalSubsetName[] = { ASCII_HASH , '\0' }; |
3110#endif /* XML_DTD */ | 3651#endif /* XML_DTD */ |
3111 static const XML_Char atypeCDATA[] = { 'C', 'D', 'A', 'T', 'A', '\0' }; 3112 static const XML_Char atypeID[] = { 'I', 'D', '\0' }; 3113 static const XML_Char atypeIDREF[] = { 'I', 'D', 'R', 'E', 'F', '\0' }; 3114 static const XML_Char atypeIDREFS[] = { 'I', 'D', 'R', 'E', 'F', 'S', '\0' }; 3115 static const XML_Char atypeENTITY[] = { 'E', 'N', 'T', 'I', 'T', 'Y', '\0' }; 3116 static const XML_Char atypeENTITIES[] = 3117 { 'E', 'N', 'T', 'I', 'T', 'I', 'E', 'S', '\0' }; | 3652 static const XML_Char atypeCDATA[] = 3653 { ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; 3654 static const XML_Char atypeID[] = { ASCII_I, ASCII_D, '\0' }; 3655 static const XML_Char atypeIDREF[] = 3656 { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' }; 3657 static const XML_Char atypeIDREFS[] = 3658 { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' }; 3659 static const XML_Char atypeENTITY[] = 3660 { ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' }; 3661 static const XML_Char atypeENTITIES[] = { ASCII_E, ASCII_N, 3662 ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, '\0' }; |
3118 static const XML_Char atypeNMTOKEN[] = { | 3663 static const XML_Char atypeNMTOKEN[] = { |
3119 'N', 'M', 'T', 'O', 'K', 'E', 'N', '\0' }; 3120 static const XML_Char atypeNMTOKENS[] = { 3121 'N', 'M', 'T', 'O', 'K', 'E', 'N', 'S', '\0' }; 3122 static const XML_Char notationPrefix[] = { 3123 'N', 'O', 'T', 'A', 'T', 'I', 'O', 'N', '(', '\0' }; 3124 static const XML_Char enumValueSep[] = { '|', '\0' }; 3125 static const XML_Char enumValueStart[] = { '(', '\0' }; | 3664 ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' }; 3665 static const XML_Char atypeNMTOKENS[] = { ASCII_N, ASCII_M, ASCII_T, 3666 ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, '\0' }; 3667 static const XML_Char notationPrefix[] = { ASCII_N, ASCII_O, ASCII_T, 3668 ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, ASCII_LPAREN, '\0' }; 3669 static const XML_Char enumValueSep[] = { ASCII_PIPE, '\0' }; 3670 static const XML_Char enumValueStart[] = { ASCII_LPAREN, '\0' }; |
3126 | 3671 |
3672 /* save one level of indirection */ 3673 DTD * const dtd = _dtd; 3674 |
|
3127 const char **eventPP; 3128 const char **eventEndPP; 3129 enum XML_Content_Quant quant; 3130 3131 if (enc == encoding) { 3132 eventPP = &eventPtr; 3133 eventEndPP = &eventEndPtr; 3134 } 3135 else { 3136 eventPP = &(openInternalEntities->internalEventPtr); 3137 eventEndPP = &(openInternalEntities->internalEventEndPtr); 3138 } | 3675 const char **eventPP; 3676 const char **eventEndPP; 3677 enum XML_Content_Quant quant; 3678 3679 if (enc == encoding) { 3680 eventPP = &eventPtr; 3681 eventEndPP = &eventEndPtr; 3682 } 3683 else { 3684 eventPP = &(openInternalEntities->internalEventPtr); 3685 eventEndPP = &(openInternalEntities->internalEventEndPtr); 3686 } |
3687 |
|
3139 for (;;) { 3140 int role; 3141 XML_Bool handleDefault = XML_TRUE; 3142 *eventPP = s; 3143 *eventEndPP = next; 3144 if (tok <= 0) { | 3688 for (;;) { 3689 int role; 3690 XML_Bool handleDefault = XML_TRUE; 3691 *eventPP = s; 3692 *eventEndPP = next; 3693 if (tok <= 0) { |
3145 if (nextPtr != 0 && tok != XML_TOK_INVALID) { | 3694 if (haveMore && tok != XML_TOK_INVALID) { |
3146 *nextPtr = s; 3147 return XML_ERROR_NONE; 3148 } 3149 switch (tok) { 3150 case XML_TOK_INVALID: 3151 *eventPP = next; 3152 return XML_ERROR_INVALID_TOKEN; 3153 case XML_TOK_PARTIAL: 3154 return XML_ERROR_UNCLOSED_TOKEN; 3155 case XML_TOK_PARTIAL_CHAR: 3156 return XML_ERROR_PARTIAL_CHAR; 3157 case XML_TOK_NONE: 3158#ifdef XML_DTD | 3695 *nextPtr = s; 3696 return XML_ERROR_NONE; 3697 } 3698 switch (tok) { 3699 case XML_TOK_INVALID: 3700 *eventPP = next; 3701 return XML_ERROR_INVALID_TOKEN; 3702 case XML_TOK_PARTIAL: 3703 return XML_ERROR_UNCLOSED_TOKEN; 3704 case XML_TOK_PARTIAL_CHAR: 3705 return XML_ERROR_PARTIAL_CHAR; 3706 case XML_TOK_NONE: 3707#ifdef XML_DTD |
3159 if (enc != encoding) | 3708 /* for internal PE NOT referenced between declarations */ 3709 if (enc != encoding && !openInternalEntities->betweenDecl) { 3710 *nextPtr = s; |
3160 return XML_ERROR_NONE; | 3711 return XML_ERROR_NONE; |
3161 if (isParamEntity) { | 3712 } 3713 /* WFC: PE Between Declarations - must check that PE contains 3714 complete markup, not only for external PEs, but also for 3715 internal PEs if the reference occurs between declarations. 3716 */ 3717 if (isParamEntity || enc != encoding) { |
3162 if (XmlTokenRole(&prologState, XML_TOK_NONE, end, end, enc) 3163 == XML_ROLE_ERROR) | 3718 if (XmlTokenRole(&prologState, XML_TOK_NONE, end, end, enc) 3719 == XML_ROLE_ERROR) |
3164 return XML_ERROR_SYNTAX; | 3720 return XML_ERROR_INCOMPLETE_PE; 3721 *nextPtr = s; |
3165 return XML_ERROR_NONE; 3166 } 3167#endif /* XML_DTD */ 3168 return XML_ERROR_NO_ELEMENTS; 3169 default: 3170 tok = -tok; 3171 next = end; 3172 break; --- 39 unchanged lines hidden (view full) --- 3212 enc = encoding; 3213 handleDefault = XML_FALSE; 3214 } 3215 break; 3216#endif /* XML_DTD */ 3217 case XML_ROLE_DOCTYPE_PUBLIC_ID: 3218#ifdef XML_DTD 3219 useForeignDTD = XML_FALSE; | 3722 return XML_ERROR_NONE; 3723 } 3724#endif /* XML_DTD */ 3725 return XML_ERROR_NO_ELEMENTS; 3726 default: 3727 tok = -tok; 3728 next = end; 3729 break; --- 39 unchanged lines hidden (view full) --- 3769 enc = encoding; 3770 handleDefault = XML_FALSE; 3771 } 3772 break; 3773#endif /* XML_DTD */ 3774 case XML_ROLE_DOCTYPE_PUBLIC_ID: 3775#ifdef XML_DTD 3776 useForeignDTD = XML_FALSE; |
3777 declEntity = (ENTITY *)lookup(&dtd->paramEntities, 3778 externalSubsetName, 3779 sizeof(ENTITY)); 3780 if (!declEntity) 3781 return XML_ERROR_NO_MEMORY; |
|
3220#endif /* XML_DTD */ | 3782#endif /* XML_DTD */ |
3221 dtd.hasParamEntityRefs = XML_TRUE; | 3783 dtd->hasParamEntityRefs = XML_TRUE; |
3222 if (startDoctypeDeclHandler) { | 3784 if (startDoctypeDeclHandler) { |
3785 if (!XmlIsPublicId(enc, s, next, eventPP)) 3786 return XML_ERROR_PUBLICID; |
|
3223 doctypePubid = poolStoreString(&tempPool, enc, 3224 s + enc->minBytesPerChar, 3225 next - enc->minBytesPerChar); 3226 if (!doctypePubid) 3227 return XML_ERROR_NO_MEMORY; | 3787 doctypePubid = poolStoreString(&tempPool, enc, 3788 s + enc->minBytesPerChar, 3789 next - enc->minBytesPerChar); 3790 if (!doctypePubid) 3791 return XML_ERROR_NO_MEMORY; |
3792 normalizePublicId((XML_Char *)doctypePubid); |
|
3228 poolFinish(&tempPool); 3229 handleDefault = XML_FALSE; | 3793 poolFinish(&tempPool); 3794 handleDefault = XML_FALSE; |
3795 goto alreadyChecked; |
|
3230 } | 3796 } |
3231#ifdef XML_DTD 3232 declEntity = (ENTITY *)lookup(&dtd.paramEntities, 3233 externalSubsetName, 3234 sizeof(ENTITY)); 3235 if (!declEntity) 3236 return XML_ERROR_NO_MEMORY; 3237#endif /* XML_DTD */ | |
3238 /* fall through */ 3239 case XML_ROLE_ENTITY_PUBLIC_ID: 3240 if (!XmlIsPublicId(enc, s, next, eventPP)) | 3797 /* fall through */ 3798 case XML_ROLE_ENTITY_PUBLIC_ID: 3799 if (!XmlIsPublicId(enc, s, next, eventPP)) |
3241 return XML_ERROR_SYNTAX; 3242 if (dtd.keepProcessing && declEntity) { 3243 XML_Char *tem = poolStoreString(&dtd.pool, | 3800 return XML_ERROR_PUBLICID; 3801 alreadyChecked: 3802 if (dtd->keepProcessing && declEntity) { 3803 XML_Char *tem = poolStoreString(&dtd->pool, |
3244 enc, 3245 s + enc->minBytesPerChar, 3246 next - enc->minBytesPerChar); 3247 if (!tem) 3248 return XML_ERROR_NO_MEMORY; 3249 normalizePublicId(tem); 3250 declEntity->publicId = tem; | 3804 enc, 3805 s + enc->minBytesPerChar, 3806 next - enc->minBytesPerChar); 3807 if (!tem) 3808 return XML_ERROR_NO_MEMORY; 3809 normalizePublicId(tem); 3810 declEntity->publicId = tem; |
3251 poolFinish(&dtd.pool); | 3811 poolFinish(&dtd->pool); |
3252 if (entityDeclHandler) 3253 handleDefault = XML_FALSE; 3254 } 3255 break; 3256 case XML_ROLE_DOCTYPE_CLOSE: 3257 if (doctypeName) { 3258 startDoctypeDeclHandler(handlerArg, doctypeName, 3259 doctypeSysid, doctypePubid, 0); 3260 poolClear(&tempPool); 3261 handleDefault = XML_FALSE; 3262 } 3263 /* doctypeSysid will be non-NULL in the case of a previous 3264 XML_ROLE_DOCTYPE_SYSTEM_ID, even if startDoctypeDeclHandler 3265 was not set, indicating an external subset 3266 */ | 3812 if (entityDeclHandler) 3813 handleDefault = XML_FALSE; 3814 } 3815 break; 3816 case XML_ROLE_DOCTYPE_CLOSE: 3817 if (doctypeName) { 3818 startDoctypeDeclHandler(handlerArg, doctypeName, 3819 doctypeSysid, doctypePubid, 0); 3820 poolClear(&tempPool); 3821 handleDefault = XML_FALSE; 3822 } 3823 /* doctypeSysid will be non-NULL in the case of a previous 3824 XML_ROLE_DOCTYPE_SYSTEM_ID, even if startDoctypeDeclHandler 3825 was not set, indicating an external subset 3826 */ |
3267#ifdef XML_DTD | 3827#ifdef XML_DTD |
3268 if (doctypeSysid || useForeignDTD) { | 3828 if (doctypeSysid || useForeignDTD) { |
3269 dtd.hasParamEntityRefs = XML_TRUE; /* when docTypeSysid == NULL */ | 3829 XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; 3830 dtd->hasParamEntityRefs = XML_TRUE; |
3270 if (paramEntityParsing && externalEntityRefHandler) { | 3831 if (paramEntityParsing && externalEntityRefHandler) { |
3271 ENTITY *entity = (ENTITY *)lookup(&dtd.paramEntities, | 3832 ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities, |
3272 externalSubsetName, 3273 sizeof(ENTITY)); 3274 if (!entity) 3275 return XML_ERROR_NO_MEMORY; | 3833 externalSubsetName, 3834 sizeof(ENTITY)); 3835 if (!entity) 3836 return XML_ERROR_NO_MEMORY; |
3276 if (useForeignDTD) | 3837 if (useForeignDTD) |
3277 entity->base = curBase; | 3838 entity->base = curBase; |
3278 dtd.paramEntityRead = XML_FALSE; | 3839 dtd->paramEntityRead = XML_FALSE; |
3279 if (!externalEntityRefHandler(externalEntityRefHandlerArg, 3280 0, 3281 entity->base, 3282 entity->systemId, 3283 entity->publicId)) 3284 return XML_ERROR_EXTERNAL_ENTITY_HANDLING; | 3840 if (!externalEntityRefHandler(externalEntityRefHandlerArg, 3841 0, 3842 entity->base, 3843 entity->systemId, 3844 entity->publicId)) 3845 return XML_ERROR_EXTERNAL_ENTITY_HANDLING; |
3285 if (dtd.paramEntityRead && 3286 !dtd.standalone && 3287 notStandaloneHandler && 3288 !notStandaloneHandler(handlerArg)) 3289 return XML_ERROR_NOT_STANDALONE; 3290 /* end of DTD - no need to update dtd.keepProcessing */ | 3846 if (dtd->paramEntityRead) { 3847 if (!dtd->standalone && 3848 notStandaloneHandler && 3849 !notStandaloneHandler(handlerArg)) 3850 return XML_ERROR_NOT_STANDALONE; 3851 } 3852 /* if we didn't read the foreign DTD then this means that there 3853 is no external subset and we must reset dtd->hasParamEntityRefs 3854 */ 3855 else if (!doctypeSysid) 3856 dtd->hasParamEntityRefs = hadParamEntityRefs; 3857 /* end of DTD - no need to update dtd->keepProcessing */ |
3291 } 3292 useForeignDTD = XML_FALSE; 3293 } 3294#endif /* XML_DTD */ 3295 if (endDoctypeDeclHandler) { 3296 endDoctypeDeclHandler(handlerArg); 3297 handleDefault = XML_FALSE; 3298 } 3299 break; 3300 case XML_ROLE_INSTANCE_START: 3301#ifdef XML_DTD | 3858 } 3859 useForeignDTD = XML_FALSE; 3860 } 3861#endif /* XML_DTD */ 3862 if (endDoctypeDeclHandler) { 3863 endDoctypeDeclHandler(handlerArg); 3864 handleDefault = XML_FALSE; 3865 } 3866 break; 3867 case XML_ROLE_INSTANCE_START: 3868#ifdef XML_DTD |
3302 /* if there is no DOCTYPE declaration then now is the | 3869 /* if there is no DOCTYPE declaration then now is the |
3303 last chance to read the foreign DTD 3304 */ | 3870 last chance to read the foreign DTD 3871 */ |
3305 if (useForeignDTD) { 3306 dtd.hasParamEntityRefs = XML_TRUE; | 3872 if (useForeignDTD) { 3873 XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; 3874 dtd->hasParamEntityRefs = XML_TRUE; |
3307 if (paramEntityParsing && externalEntityRefHandler) { | 3875 if (paramEntityParsing && externalEntityRefHandler) { |
3308 ENTITY *entity = (ENTITY *)lookup(&dtd.paramEntities, | 3876 ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities, |
3309 externalSubsetName, 3310 sizeof(ENTITY)); 3311 if (!entity) 3312 return XML_ERROR_NO_MEMORY; 3313 entity->base = curBase; | 3877 externalSubsetName, 3878 sizeof(ENTITY)); 3879 if (!entity) 3880 return XML_ERROR_NO_MEMORY; 3881 entity->base = curBase; |
3314 dtd.paramEntityRead = XML_FALSE; | 3882 dtd->paramEntityRead = XML_FALSE; |
3315 if (!externalEntityRefHandler(externalEntityRefHandlerArg, 3316 0, 3317 entity->base, 3318 entity->systemId, 3319 entity->publicId)) 3320 return XML_ERROR_EXTERNAL_ENTITY_HANDLING; | 3883 if (!externalEntityRefHandler(externalEntityRefHandlerArg, 3884 0, 3885 entity->base, 3886 entity->systemId, 3887 entity->publicId)) 3888 return XML_ERROR_EXTERNAL_ENTITY_HANDLING; |
3321 if (dtd.paramEntityRead && 3322 !dtd.standalone && 3323 notStandaloneHandler && 3324 !notStandaloneHandler(handlerArg)) 3325 return XML_ERROR_NOT_STANDALONE; 3326 /* end of DTD - no need to update dtd.keepProcessing */ | 3889 if (dtd->paramEntityRead) { 3890 if (!dtd->standalone && 3891 notStandaloneHandler && 3892 !notStandaloneHandler(handlerArg)) 3893 return XML_ERROR_NOT_STANDALONE; 3894 } 3895 /* if we didn't read the foreign DTD then this means that there 3896 is no external subset and we must reset dtd->hasParamEntityRefs 3897 */ 3898 else 3899 dtd->hasParamEntityRefs = hadParamEntityRefs; 3900 /* end of DTD - no need to update dtd->keepProcessing */ |
3327 } | 3901 } |
3328 } | 3902 } |
3329#endif /* XML_DTD */ 3330 processor = contentProcessor; 3331 return contentProcessor(parser, s, end, nextPtr); 3332 case XML_ROLE_ATTLIST_ELEMENT_NAME: 3333 declElementType = getElementType(parser, enc, s, next); 3334 if (!declElementType) 3335 return XML_ERROR_NO_MEMORY; 3336 goto checkAttListDeclHandler; --- 26 unchanged lines hidden (view full) --- 3363 declAttributeType = atypeENTITIES; 3364 goto checkAttListDeclHandler; 3365 case XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN: 3366 declAttributeType = atypeNMTOKEN; 3367 goto checkAttListDeclHandler; 3368 case XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS: 3369 declAttributeType = atypeNMTOKENS; 3370 checkAttListDeclHandler: | 3903#endif /* XML_DTD */ 3904 processor = contentProcessor; 3905 return contentProcessor(parser, s, end, nextPtr); 3906 case XML_ROLE_ATTLIST_ELEMENT_NAME: 3907 declElementType = getElementType(parser, enc, s, next); 3908 if (!declElementType) 3909 return XML_ERROR_NO_MEMORY; 3910 goto checkAttListDeclHandler; --- 26 unchanged lines hidden (view full) --- 3937 declAttributeType = atypeENTITIES; 3938 goto checkAttListDeclHandler; 3939 case XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN: 3940 declAttributeType = atypeNMTOKEN; 3941 goto checkAttListDeclHandler; 3942 case XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS: 3943 declAttributeType = atypeNMTOKENS; 3944 checkAttListDeclHandler: |
3371 if (dtd.keepProcessing && attlistDeclHandler) | 3945 if (dtd->keepProcessing && attlistDeclHandler) |
3372 handleDefault = XML_FALSE; 3373 break; 3374 case XML_ROLE_ATTRIBUTE_ENUM_VALUE: 3375 case XML_ROLE_ATTRIBUTE_NOTATION_VALUE: | 3946 handleDefault = XML_FALSE; 3947 break; 3948 case XML_ROLE_ATTRIBUTE_ENUM_VALUE: 3949 case XML_ROLE_ATTRIBUTE_NOTATION_VALUE: |
3376 if (dtd.keepProcessing && attlistDeclHandler) { | 3950 if (dtd->keepProcessing && attlistDeclHandler) { |
3377 const XML_Char *prefix; 3378 if (declAttributeType) { 3379 prefix = enumValueSep; 3380 } 3381 else { 3382 prefix = (role == XML_ROLE_ATTRIBUTE_NOTATION_VALUE 3383 ? notationPrefix 3384 : enumValueStart); 3385 } 3386 if (!poolAppendString(&tempPool, prefix)) 3387 return XML_ERROR_NO_MEMORY; 3388 if (!poolAppend(&tempPool, enc, s, next)) 3389 return XML_ERROR_NO_MEMORY; 3390 declAttributeType = tempPool.start; 3391 handleDefault = XML_FALSE; 3392 } 3393 break; 3394 case XML_ROLE_IMPLIED_ATTRIBUTE_VALUE: 3395 case XML_ROLE_REQUIRED_ATTRIBUTE_VALUE: | 3951 const XML_Char *prefix; 3952 if (declAttributeType) { 3953 prefix = enumValueSep; 3954 } 3955 else { 3956 prefix = (role == XML_ROLE_ATTRIBUTE_NOTATION_VALUE 3957 ? notationPrefix 3958 : enumValueStart); 3959 } 3960 if (!poolAppendString(&tempPool, prefix)) 3961 return XML_ERROR_NO_MEMORY; 3962 if (!poolAppend(&tempPool, enc, s, next)) 3963 return XML_ERROR_NO_MEMORY; 3964 declAttributeType = tempPool.start; 3965 handleDefault = XML_FALSE; 3966 } 3967 break; 3968 case XML_ROLE_IMPLIED_ATTRIBUTE_VALUE: 3969 case XML_ROLE_REQUIRED_ATTRIBUTE_VALUE: |
3396 if (dtd.keepProcessing) { | 3970 if (dtd->keepProcessing) { |
3397 if (!defineAttribute(declElementType, declAttributeId, | 3971 if (!defineAttribute(declElementType, declAttributeId, |
3398 declAttributeIsCdata, declAttributeIsId, 0, 3399 parser)) | 3972 declAttributeIsCdata, declAttributeIsId, 3973 0, parser)) |
3400 return XML_ERROR_NO_MEMORY; 3401 if (attlistDeclHandler && declAttributeType) { | 3974 return XML_ERROR_NO_MEMORY; 3975 if (attlistDeclHandler && declAttributeType) { |
3402 if (*declAttributeType == XML_T('(') 3403 || (*declAttributeType == XML_T('N') 3404 && declAttributeType[1] == XML_T('O'))) { | 3976 if (*declAttributeType == XML_T(ASCII_LPAREN) 3977 || (*declAttributeType == XML_T(ASCII_N) 3978 && declAttributeType[1] == XML_T(ASCII_O))) { |
3405 /* Enumerated or Notation type */ | 3979 /* Enumerated or Notation type */ |
3406 if (!poolAppendChar(&tempPool, XML_T(')')) | 3980 if (!poolAppendChar(&tempPool, XML_T(ASCII_RPAREN)) |
3407 || !poolAppendChar(&tempPool, XML_T('\0'))) 3408 return XML_ERROR_NO_MEMORY; 3409 declAttributeType = tempPool.start; 3410 poolFinish(&tempPool); 3411 } 3412 *eventEndPP = s; 3413 attlistDeclHandler(handlerArg, declElementType->name, 3414 declAttributeId->name, declAttributeType, 3415 0, role == XML_ROLE_REQUIRED_ATTRIBUTE_VALUE); 3416 poolClear(&tempPool); 3417 handleDefault = XML_FALSE; 3418 } 3419 } 3420 break; 3421 case XML_ROLE_DEFAULT_ATTRIBUTE_VALUE: 3422 case XML_ROLE_FIXED_ATTRIBUTE_VALUE: | 3981 || !poolAppendChar(&tempPool, XML_T('\0'))) 3982 return XML_ERROR_NO_MEMORY; 3983 declAttributeType = tempPool.start; 3984 poolFinish(&tempPool); 3985 } 3986 *eventEndPP = s; 3987 attlistDeclHandler(handlerArg, declElementType->name, 3988 declAttributeId->name, declAttributeType, 3989 0, role == XML_ROLE_REQUIRED_ATTRIBUTE_VALUE); 3990 poolClear(&tempPool); 3991 handleDefault = XML_FALSE; 3992 } 3993 } 3994 break; 3995 case XML_ROLE_DEFAULT_ATTRIBUTE_VALUE: 3996 case XML_ROLE_FIXED_ATTRIBUTE_VALUE: |
3423 if (dtd.keepProcessing) { | 3997 if (dtd->keepProcessing) { |
3424 const XML_Char *attVal; | 3998 const XML_Char *attVal; |
3425 enum XML_Error result 3426 = storeAttributeValue(parser, enc, declAttributeIsCdata, 3427 s + enc->minBytesPerChar, 3428 next - enc->minBytesPerChar, 3429 &dtd.pool); | 3999 enum XML_Error result = 4000 storeAttributeValue(parser, enc, declAttributeIsCdata, 4001 s + enc->minBytesPerChar, 4002 next - enc->minBytesPerChar, 4003 &dtd->pool); |
3430 if (result) 3431 return result; | 4004 if (result) 4005 return result; |
3432 attVal = poolStart(&dtd.pool); 3433 poolFinish(&dtd.pool); | 4006 attVal = poolStart(&dtd->pool); 4007 poolFinish(&dtd->pool); |
3434 /* ID attributes aren't allowed to have a default */ 3435 if (!defineAttribute(declElementType, declAttributeId, 3436 declAttributeIsCdata, XML_FALSE, attVal, parser)) 3437 return XML_ERROR_NO_MEMORY; 3438 if (attlistDeclHandler && declAttributeType) { | 4008 /* ID attributes aren't allowed to have a default */ 4009 if (!defineAttribute(declElementType, declAttributeId, 4010 declAttributeIsCdata, XML_FALSE, attVal, parser)) 4011 return XML_ERROR_NO_MEMORY; 4012 if (attlistDeclHandler && declAttributeType) { |
3439 if (*declAttributeType == XML_T('(') 3440 || (*declAttributeType == XML_T('N') 3441 && declAttributeType[1] == XML_T('O'))) { | 4013 if (*declAttributeType == XML_T(ASCII_LPAREN) 4014 || (*declAttributeType == XML_T(ASCII_N) 4015 && declAttributeType[1] == XML_T(ASCII_O))) { |
3442 /* Enumerated or Notation type */ | 4016 /* Enumerated or Notation type */ |
3443 if (!poolAppendChar(&tempPool, XML_T(')')) | 4017 if (!poolAppendChar(&tempPool, XML_T(ASCII_RPAREN)) |
3444 || !poolAppendChar(&tempPool, XML_T('\0'))) 3445 return XML_ERROR_NO_MEMORY; 3446 declAttributeType = tempPool.start; 3447 poolFinish(&tempPool); 3448 } 3449 *eventEndPP = s; 3450 attlistDeclHandler(handlerArg, declElementType->name, 3451 declAttributeId->name, declAttributeType, 3452 attVal, 3453 role == XML_ROLE_FIXED_ATTRIBUTE_VALUE); 3454 poolClear(&tempPool); 3455 handleDefault = XML_FALSE; 3456 } 3457 } 3458 break; 3459 case XML_ROLE_ENTITY_VALUE: | 4018 || !poolAppendChar(&tempPool, XML_T('\0'))) 4019 return XML_ERROR_NO_MEMORY; 4020 declAttributeType = tempPool.start; 4021 poolFinish(&tempPool); 4022 } 4023 *eventEndPP = s; 4024 attlistDeclHandler(handlerArg, declElementType->name, 4025 declAttributeId->name, declAttributeType, 4026 attVal, 4027 role == XML_ROLE_FIXED_ATTRIBUTE_VALUE); 4028 poolClear(&tempPool); 4029 handleDefault = XML_FALSE; 4030 } 4031 } 4032 break; 4033 case XML_ROLE_ENTITY_VALUE: |
3460 if (dtd.keepProcessing) { | 4034 if (dtd->keepProcessing) { |
3461 enum XML_Error result = storeEntityValue(parser, enc, 3462 s + enc->minBytesPerChar, 3463 next - enc->minBytesPerChar); 3464 if (declEntity) { | 4035 enum XML_Error result = storeEntityValue(parser, enc, 4036 s + enc->minBytesPerChar, 4037 next - enc->minBytesPerChar); 4038 if (declEntity) { |
3465 declEntity->textPtr = poolStart(&dtd.entityValuePool); 3466 declEntity->textLen = poolLength(&dtd.entityValuePool); 3467 poolFinish(&dtd.entityValuePool); | 4039 declEntity->textPtr = poolStart(&dtd->entityValuePool); 4040 declEntity->textLen = (int)(poolLength(&dtd->entityValuePool)); 4041 poolFinish(&dtd->entityValuePool); |
3468 if (entityDeclHandler) { 3469 *eventEndPP = s; 3470 entityDeclHandler(handlerArg, 3471 declEntity->name, 3472 declEntity->is_param, 3473 declEntity->textPtr, 3474 declEntity->textLen, 3475 curBase, 0, 0, 0); 3476 handleDefault = XML_FALSE; 3477 } 3478 } 3479 else | 4042 if (entityDeclHandler) { 4043 *eventEndPP = s; 4044 entityDeclHandler(handlerArg, 4045 declEntity->name, 4046 declEntity->is_param, 4047 declEntity->textPtr, 4048 declEntity->textLen, 4049 curBase, 0, 0, 0); 4050 handleDefault = XML_FALSE; 4051 } 4052 } 4053 else |
3480 poolDiscard(&dtd.entityValuePool); | 4054 poolDiscard(&dtd->entityValuePool); |
3481 if (result != XML_ERROR_NONE) 3482 return result; 3483 } 3484 break; 3485 case XML_ROLE_DOCTYPE_SYSTEM_ID: 3486#ifdef XML_DTD 3487 useForeignDTD = XML_FALSE; 3488#endif /* XML_DTD */ | 4055 if (result != XML_ERROR_NONE) 4056 return result; 4057 } 4058 break; 4059 case XML_ROLE_DOCTYPE_SYSTEM_ID: 4060#ifdef XML_DTD 4061 useForeignDTD = XML_FALSE; 4062#endif /* XML_DTD */ |
3489 dtd.hasParamEntityRefs = XML_TRUE; | 4063 dtd->hasParamEntityRefs = XML_TRUE; |
3490 if (startDoctypeDeclHandler) { 3491 doctypeSysid = poolStoreString(&tempPool, enc, 3492 s + enc->minBytesPerChar, 3493 next - enc->minBytesPerChar); 3494 if (doctypeSysid == NULL) 3495 return XML_ERROR_NO_MEMORY; 3496 poolFinish(&tempPool); 3497 handleDefault = XML_FALSE; 3498 } 3499#ifdef XML_DTD 3500 else 3501 /* use externalSubsetName to make doctypeSysid non-NULL 3502 for the case where no startDoctypeDeclHandler is set */ 3503 doctypeSysid = externalSubsetName; 3504#endif /* XML_DTD */ | 4064 if (startDoctypeDeclHandler) { 4065 doctypeSysid = poolStoreString(&tempPool, enc, 4066 s + enc->minBytesPerChar, 4067 next - enc->minBytesPerChar); 4068 if (doctypeSysid == NULL) 4069 return XML_ERROR_NO_MEMORY; 4070 poolFinish(&tempPool); 4071 handleDefault = XML_FALSE; 4072 } 4073#ifdef XML_DTD 4074 else 4075 /* use externalSubsetName to make doctypeSysid non-NULL 4076 for the case where no startDoctypeDeclHandler is set */ 4077 doctypeSysid = externalSubsetName; 4078#endif /* XML_DTD */ |
3505 if (!dtd.standalone | 4079 if (!dtd->standalone |
3506#ifdef XML_DTD 3507 && !paramEntityParsing 3508#endif /* XML_DTD */ 3509 && notStandaloneHandler 3510 && !notStandaloneHandler(handlerArg)) 3511 return XML_ERROR_NOT_STANDALONE; 3512#ifndef XML_DTD 3513 break; 3514#else /* XML_DTD */ 3515 if (!declEntity) { | 4080#ifdef XML_DTD 4081 && !paramEntityParsing 4082#endif /* XML_DTD */ 4083 && notStandaloneHandler 4084 && !notStandaloneHandler(handlerArg)) 4085 return XML_ERROR_NOT_STANDALONE; 4086#ifndef XML_DTD 4087 break; 4088#else /* XML_DTD */ 4089 if (!declEntity) { |
3516 declEntity = (ENTITY *)lookup(&dtd.paramEntities, | 4090 declEntity = (ENTITY *)lookup(&dtd->paramEntities, |
3517 externalSubsetName, 3518 sizeof(ENTITY)); 3519 if (!declEntity) 3520 return XML_ERROR_NO_MEMORY; 3521 declEntity->publicId = NULL; 3522 } 3523 /* fall through */ 3524#endif /* XML_DTD */ 3525 case XML_ROLE_ENTITY_SYSTEM_ID: | 4091 externalSubsetName, 4092 sizeof(ENTITY)); 4093 if (!declEntity) 4094 return XML_ERROR_NO_MEMORY; 4095 declEntity->publicId = NULL; 4096 } 4097 /* fall through */ 4098#endif /* XML_DTD */ 4099 case XML_ROLE_ENTITY_SYSTEM_ID: |
3526 if (dtd.keepProcessing && declEntity) { 3527 declEntity->systemId = poolStoreString(&dtd.pool, enc, | 4100 if (dtd->keepProcessing && declEntity) { 4101 declEntity->systemId = poolStoreString(&dtd->pool, enc, |
3528 s + enc->minBytesPerChar, 3529 next - enc->minBytesPerChar); 3530 if (!declEntity->systemId) 3531 return XML_ERROR_NO_MEMORY; 3532 declEntity->base = curBase; | 4102 s + enc->minBytesPerChar, 4103 next - enc->minBytesPerChar); 4104 if (!declEntity->systemId) 4105 return XML_ERROR_NO_MEMORY; 4106 declEntity->base = curBase; |
3533 poolFinish(&dtd.pool); | 4107 poolFinish(&dtd->pool); |
3534 if (entityDeclHandler) 3535 handleDefault = XML_FALSE; 3536 } 3537 break; 3538 case XML_ROLE_ENTITY_COMPLETE: | 4108 if (entityDeclHandler) 4109 handleDefault = XML_FALSE; 4110 } 4111 break; 4112 case XML_ROLE_ENTITY_COMPLETE: |
3539 if (dtd.keepProcessing && declEntity && entityDeclHandler) { | 4113 if (dtd->keepProcessing && declEntity && entityDeclHandler) { |
3540 *eventEndPP = s; 3541 entityDeclHandler(handlerArg, 3542 declEntity->name, 3543 declEntity->is_param, 3544 0,0, 3545 declEntity->base, 3546 declEntity->systemId, 3547 declEntity->publicId, 3548 0); 3549 handleDefault = XML_FALSE; 3550 } 3551 break; 3552 case XML_ROLE_ENTITY_NOTATION_NAME: | 4114 *eventEndPP = s; 4115 entityDeclHandler(handlerArg, 4116 declEntity->name, 4117 declEntity->is_param, 4118 0,0, 4119 declEntity->base, 4120 declEntity->systemId, 4121 declEntity->publicId, 4122 0); 4123 handleDefault = XML_FALSE; 4124 } 4125 break; 4126 case XML_ROLE_ENTITY_NOTATION_NAME: |
3553 if (dtd.keepProcessing && declEntity) { 3554 declEntity->notation = poolStoreString(&dtd.pool, enc, s, next); | 4127 if (dtd->keepProcessing && declEntity) { 4128 declEntity->notation = poolStoreString(&dtd->pool, enc, s, next); |
3555 if (!declEntity->notation) 3556 return XML_ERROR_NO_MEMORY; | 4129 if (!declEntity->notation) 4130 return XML_ERROR_NO_MEMORY; |
3557 poolFinish(&dtd.pool); | 4131 poolFinish(&dtd->pool); |
3558 if (unparsedEntityDeclHandler) { 3559 *eventEndPP = s; 3560 unparsedEntityDeclHandler(handlerArg, 3561 declEntity->name, 3562 declEntity->base, 3563 declEntity->systemId, 3564 declEntity->publicId, 3565 declEntity->notation); --- 13 unchanged lines hidden (view full) --- 3579 } 3580 break; 3581 case XML_ROLE_GENERAL_ENTITY_NAME: 3582 { 3583 if (XmlPredefinedEntityName(enc, s, next)) { 3584 declEntity = NULL; 3585 break; 3586 } | 4132 if (unparsedEntityDeclHandler) { 4133 *eventEndPP = s; 4134 unparsedEntityDeclHandler(handlerArg, 4135 declEntity->name, 4136 declEntity->base, 4137 declEntity->systemId, 4138 declEntity->publicId, 4139 declEntity->notation); --- 13 unchanged lines hidden (view full) --- 4153 } 4154 break; 4155 case XML_ROLE_GENERAL_ENTITY_NAME: 4156 { 4157 if (XmlPredefinedEntityName(enc, s, next)) { 4158 declEntity = NULL; 4159 break; 4160 } |
3587 if (dtd.keepProcessing) { 3588 const XML_Char *name = poolStoreString(&dtd.pool, enc, s, next); | 4161 if (dtd->keepProcessing) { 4162 const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); |
3589 if (!name) 3590 return XML_ERROR_NO_MEMORY; | 4163 if (!name) 4164 return XML_ERROR_NO_MEMORY; |
3591 declEntity = (ENTITY *)lookup(&dtd.generalEntities, name, | 4165 declEntity = (ENTITY *)lookup(&dtd->generalEntities, name, |
3592 sizeof(ENTITY)); 3593 if (!declEntity) 3594 return XML_ERROR_NO_MEMORY; 3595 if (declEntity->name != name) { | 4166 sizeof(ENTITY)); 4167 if (!declEntity) 4168 return XML_ERROR_NO_MEMORY; 4169 if (declEntity->name != name) { |
3596 poolDiscard(&dtd.pool); | 4170 poolDiscard(&dtd->pool); |
3597 declEntity = NULL; 3598 } 3599 else { | 4171 declEntity = NULL; 4172 } 4173 else { |
3600 poolFinish(&dtd.pool); | 4174 poolFinish(&dtd->pool); |
3601 declEntity->publicId = NULL; 3602 declEntity->is_param = XML_FALSE; 3603 /* if we have a parent parser or are reading an internal parameter 3604 entity, then the entity declaration is not considered "internal" 3605 */ 3606 declEntity->is_internal = !(parentParser || openInternalEntities); 3607 if (entityDeclHandler) 3608 handleDefault = XML_FALSE; 3609 } 3610 } 3611 else { | 4175 declEntity->publicId = NULL; 4176 declEntity->is_param = XML_FALSE; 4177 /* if we have a parent parser or are reading an internal parameter 4178 entity, then the entity declaration is not considered "internal" 4179 */ 4180 declEntity->is_internal = !(parentParser || openInternalEntities); 4181 if (entityDeclHandler) 4182 handleDefault = XML_FALSE; 4183 } 4184 } 4185 else { |
3612 poolDiscard(&dtd.pool); | 4186 poolDiscard(&dtd->pool); |
3613 declEntity = NULL; 3614 } 3615 } 3616 break; 3617 case XML_ROLE_PARAM_ENTITY_NAME: 3618#ifdef XML_DTD | 4187 declEntity = NULL; 4188 } 4189 } 4190 break; 4191 case XML_ROLE_PARAM_ENTITY_NAME: 4192#ifdef XML_DTD |
3619 if (dtd.keepProcessing) { 3620 const XML_Char *name = poolStoreString(&dtd.pool, enc, s, next); | 4193 if (dtd->keepProcessing) { 4194 const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); |
3621 if (!name) 3622 return XML_ERROR_NO_MEMORY; | 4195 if (!name) 4196 return XML_ERROR_NO_MEMORY; |
3623 declEntity = (ENTITY *)lookup(&dtd.paramEntities, | 4197 declEntity = (ENTITY *)lookup(&dtd->paramEntities, |
3624 name, sizeof(ENTITY)); 3625 if (!declEntity) 3626 return XML_ERROR_NO_MEMORY; 3627 if (declEntity->name != name) { | 4198 name, sizeof(ENTITY)); 4199 if (!declEntity) 4200 return XML_ERROR_NO_MEMORY; 4201 if (declEntity->name != name) { |
3628 poolDiscard(&dtd.pool); | 4202 poolDiscard(&dtd->pool); |
3629 declEntity = NULL; 3630 } 3631 else { | 4203 declEntity = NULL; 4204 } 4205 else { |
3632 poolFinish(&dtd.pool); | 4206 poolFinish(&dtd->pool); |
3633 declEntity->publicId = NULL; 3634 declEntity->is_param = XML_TRUE; 3635 /* if we have a parent parser or are reading an internal parameter 3636 entity, then the entity declaration is not considered "internal" 3637 */ 3638 declEntity->is_internal = !(parentParser || openInternalEntities); 3639 if (entityDeclHandler) 3640 handleDefault = XML_FALSE; 3641 } 3642 } 3643 else { | 4207 declEntity->publicId = NULL; 4208 declEntity->is_param = XML_TRUE; 4209 /* if we have a parent parser or are reading an internal parameter 4210 entity, then the entity declaration is not considered "internal" 4211 */ 4212 declEntity->is_internal = !(parentParser || openInternalEntities); 4213 if (entityDeclHandler) 4214 handleDefault = XML_FALSE; 4215 } 4216 } 4217 else { |
3644 poolDiscard(&dtd.pool); | 4218 poolDiscard(&dtd->pool); |
3645 declEntity = NULL; 3646 } 3647#else /* not XML_DTD */ 3648 declEntity = NULL; 3649#endif /* XML_DTD */ 3650 break; 3651 case XML_ROLE_NOTATION_NAME: 3652 declNotationPublicId = NULL; 3653 declNotationName = NULL; 3654 if (notationDeclHandler) { 3655 declNotationName = poolStoreString(&tempPool, enc, s, next); 3656 if (!declNotationName) 3657 return XML_ERROR_NO_MEMORY; 3658 poolFinish(&tempPool); 3659 handleDefault = XML_FALSE; 3660 } 3661 break; 3662 case XML_ROLE_NOTATION_PUBLIC_ID: 3663 if (!XmlIsPublicId(enc, s, next, eventPP)) | 4219 declEntity = NULL; 4220 } 4221#else /* not XML_DTD */ 4222 declEntity = NULL; 4223#endif /* XML_DTD */ 4224 break; 4225 case XML_ROLE_NOTATION_NAME: 4226 declNotationPublicId = NULL; 4227 declNotationName = NULL; 4228 if (notationDeclHandler) { 4229 declNotationName = poolStoreString(&tempPool, enc, s, next); 4230 if (!declNotationName) 4231 return XML_ERROR_NO_MEMORY; 4232 poolFinish(&tempPool); 4233 handleDefault = XML_FALSE; 4234 } 4235 break; 4236 case XML_ROLE_NOTATION_PUBLIC_ID: 4237 if (!XmlIsPublicId(enc, s, next, eventPP)) |
3664 return XML_ERROR_SYNTAX; | 4238 return XML_ERROR_PUBLICID; |
3665 if (declNotationName) { /* means notationDeclHandler != NULL */ 3666 XML_Char *tem = poolStoreString(&tempPool, 3667 enc, 3668 s + enc->minBytesPerChar, 3669 next - enc->minBytesPerChar); 3670 if (!tem) 3671 return XML_ERROR_NO_MEMORY; 3672 normalizePublicId(tem); --- 30 unchanged lines hidden (view full) --- 3703 declNotationPublicId); 3704 handleDefault = XML_FALSE; 3705 } 3706 poolClear(&tempPool); 3707 break; 3708 case XML_ROLE_ERROR: 3709 switch (tok) { 3710 case XML_TOK_PARAM_ENTITY_REF: | 4239 if (declNotationName) { /* means notationDeclHandler != NULL */ 4240 XML_Char *tem = poolStoreString(&tempPool, 4241 enc, 4242 s + enc->minBytesPerChar, 4243 next - enc->minBytesPerChar); 4244 if (!tem) 4245 return XML_ERROR_NO_MEMORY; 4246 normalizePublicId(tem); --- 30 unchanged lines hidden (view full) --- 4277 declNotationPublicId); 4278 handleDefault = XML_FALSE; 4279 } 4280 poolClear(&tempPool); 4281 break; 4282 case XML_ROLE_ERROR: 4283 switch (tok) { 4284 case XML_TOK_PARAM_ENTITY_REF: |
4285 /* PE references in internal subset are 4286 not allowed within declarations. */ |
|
3711 return XML_ERROR_PARAM_ENTITY_REF; 3712 case XML_TOK_XML_DECL: 3713 return XML_ERROR_MISPLACED_XML_PI; 3714 default: 3715 return XML_ERROR_SYNTAX; 3716 } 3717#ifdef XML_DTD 3718 case XML_ROLE_IGNORE_SECT: 3719 { 3720 enum XML_Error result; 3721 if (defaultHandler) 3722 reportDefault(parser, enc, s, next); 3723 handleDefault = XML_FALSE; | 4287 return XML_ERROR_PARAM_ENTITY_REF; 4288 case XML_TOK_XML_DECL: 4289 return XML_ERROR_MISPLACED_XML_PI; 4290 default: 4291 return XML_ERROR_SYNTAX; 4292 } 4293#ifdef XML_DTD 4294 case XML_ROLE_IGNORE_SECT: 4295 { 4296 enum XML_Error result; 4297 if (defaultHandler) 4298 reportDefault(parser, enc, s, next); 4299 handleDefault = XML_FALSE; |
3724 result = doIgnoreSection(parser, enc, &next, end, nextPtr); 3725 if (!next) { | 4300 result = doIgnoreSection(parser, enc, &next, end, nextPtr, haveMore); 4301 if (result != XML_ERROR_NONE) 4302 return result; 4303 else if (!next) { |
3726 processor = ignoreSectionProcessor; 3727 return result; 3728 } 3729 } 3730 break; 3731#endif /* XML_DTD */ 3732 case XML_ROLE_GROUP_OPEN: 3733 if (prologState.level >= groupSize) { 3734 if (groupSize) { | 4304 processor = ignoreSectionProcessor; 4305 return result; 4306 } 4307 } 4308 break; 4309#endif /* XML_DTD */ 4310 case XML_ROLE_GROUP_OPEN: 4311 if (prologState.level >= groupSize) { 4312 if (groupSize) { |
3735 char *temp = REALLOC(groupConnector, groupSize *= 2); | 4313 char *temp = (char *)REALLOC(groupConnector, groupSize *= 2); |
3736 if (temp == NULL) 3737 return XML_ERROR_NO_MEMORY; 3738 groupConnector = temp; | 4314 if (temp == NULL) 4315 return XML_ERROR_NO_MEMORY; 4316 groupConnector = temp; |
3739 if (dtd.scaffIndex) { 3740 int *temp = REALLOC(dtd.scaffIndex, groupSize * sizeof(int)); | 4317 if (dtd->scaffIndex) { 4318 int *temp = (int *)REALLOC(dtd->scaffIndex, 4319 groupSize * sizeof(int)); |
3741 if (temp == NULL) 3742 return XML_ERROR_NO_MEMORY; | 4320 if (temp == NULL) 4321 return XML_ERROR_NO_MEMORY; |
3743 dtd.scaffIndex = temp; | 4322 dtd->scaffIndex = temp; |
3744 } 3745 } 3746 else { | 4323 } 4324 } 4325 else { |
3747 groupConnector = MALLOC(groupSize = 32); | 4326 groupConnector = (char *)MALLOC(groupSize = 32); |
3748 if (!groupConnector) 3749 return XML_ERROR_NO_MEMORY; 3750 } 3751 } 3752 groupConnector[prologState.level] = 0; | 4327 if (!groupConnector) 4328 return XML_ERROR_NO_MEMORY; 4329 } 4330 } 4331 groupConnector[prologState.level] = 0; |
3753 if (dtd.in_eldecl) { | 4332 if (dtd->in_eldecl) { |
3754 int myindex = nextScaffoldPart(parser); 3755 if (myindex < 0) 3756 return XML_ERROR_NO_MEMORY; | 4333 int myindex = nextScaffoldPart(parser); 4334 if (myindex < 0) 4335 return XML_ERROR_NO_MEMORY; |
3757 dtd.scaffIndex[dtd.scaffLevel] = myindex; 3758 dtd.scaffLevel++; 3759 dtd.scaffold[myindex].type = XML_CTYPE_SEQ; | 4336 dtd->scaffIndex[dtd->scaffLevel] = myindex; 4337 dtd->scaffLevel++; 4338 dtd->scaffold[myindex].type = XML_CTYPE_SEQ; |
3760 if (elementDeclHandler) 3761 handleDefault = XML_FALSE; 3762 } 3763 break; 3764 case XML_ROLE_GROUP_SEQUENCE: | 4339 if (elementDeclHandler) 4340 handleDefault = XML_FALSE; 4341 } 4342 break; 4343 case XML_ROLE_GROUP_SEQUENCE: |
3765 if (groupConnector[prologState.level] == '|') | 4344 if (groupConnector[prologState.level] == ASCII_PIPE) |
3766 return XML_ERROR_SYNTAX; | 4345 return XML_ERROR_SYNTAX; |
3767 groupConnector[prologState.level] = ','; 3768 if (dtd.in_eldecl && elementDeclHandler) | 4346 groupConnector[prologState.level] = ASCII_COMMA; 4347 if (dtd->in_eldecl && elementDeclHandler) |
3769 handleDefault = XML_FALSE; 3770 break; 3771 case XML_ROLE_GROUP_CHOICE: | 4348 handleDefault = XML_FALSE; 4349 break; 4350 case XML_ROLE_GROUP_CHOICE: |
3772 if (groupConnector[prologState.level] == ',') | 4351 if (groupConnector[prologState.level] == ASCII_COMMA) |
3773 return XML_ERROR_SYNTAX; | 4352 return XML_ERROR_SYNTAX; |
3774 if (dtd.in_eldecl | 4353 if (dtd->in_eldecl |
3775 && !groupConnector[prologState.level] | 4354 && !groupConnector[prologState.level] |
3776 && (dtd.scaffold[dtd.scaffIndex[dtd.scaffLevel - 1]].type | 4355 && (dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type |
3777 != XML_CTYPE_MIXED) 3778 ) { | 4356 != XML_CTYPE_MIXED) 4357 ) { |
3779 dtd.scaffold[dtd.scaffIndex[dtd.scaffLevel - 1]].type | 4358 dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type |
3780 = XML_CTYPE_CHOICE; 3781 if (elementDeclHandler) 3782 handleDefault = XML_FALSE; 3783 } | 4359 = XML_CTYPE_CHOICE; 4360 if (elementDeclHandler) 4361 handleDefault = XML_FALSE; 4362 } |
3784 groupConnector[prologState.level] = '|'; | 4363 groupConnector[prologState.level] = ASCII_PIPE; |
3785 break; 3786 case XML_ROLE_PARAM_ENTITY_REF: 3787#ifdef XML_DTD 3788 case XML_ROLE_INNER_PARAM_ENTITY_REF: | 4364 break; 4365 case XML_ROLE_PARAM_ENTITY_REF: 4366#ifdef XML_DTD 4367 case XML_ROLE_INNER_PARAM_ENTITY_REF: |
3789 /* PE references in internal subset are 3790 not allowed within declarations */ 3791 if (prologState.documentEntity && 3792 role == XML_ROLE_INNER_PARAM_ENTITY_REF) 3793 return XML_ERROR_PARAM_ENTITY_REF; 3794 dtd.hasParamEntityRefs = XML_TRUE; | 4368 dtd->hasParamEntityRefs = XML_TRUE; |
3795 if (!paramEntityParsing) | 4369 if (!paramEntityParsing) |
3796 dtd.keepProcessing = dtd.standalone; | 4370 dtd->keepProcessing = dtd->standalone; |
3797 else { 3798 const XML_Char *name; 3799 ENTITY *entity; | 4371 else { 4372 const XML_Char *name; 4373 ENTITY *entity; |
3800 name = poolStoreString(&dtd.pool, enc, | 4374 name = poolStoreString(&dtd->pool, enc, |
3801 s + enc->minBytesPerChar, 3802 next - enc->minBytesPerChar); 3803 if (!name) 3804 return XML_ERROR_NO_MEMORY; | 4375 s + enc->minBytesPerChar, 4376 next - enc->minBytesPerChar); 4377 if (!name) 4378 return XML_ERROR_NO_MEMORY; |
3805 entity = (ENTITY *)lookup(&dtd.paramEntities, name, 0); 3806 poolDiscard(&dtd.pool); | 4379 entity = (ENTITY *)lookup(&dtd->paramEntities, name, 0); 4380 poolDiscard(&dtd->pool); |
3807 /* first, determine if a check for an existing declaration is needed; 3808 if yes, check that the entity exists, and that it is internal, 3809 otherwise call the skipped entity handler 3810 */ 3811 if (prologState.documentEntity && | 4381 /* first, determine if a check for an existing declaration is needed; 4382 if yes, check that the entity exists, and that it is internal, 4383 otherwise call the skipped entity handler 4384 */ 4385 if (prologState.documentEntity && |
3812 (dtd.standalone | 4386 (dtd->standalone |
3813 ? !openInternalEntities | 4387 ? !openInternalEntities |
3814 : !dtd.hasParamEntityRefs)) { | 4388 : !dtd->hasParamEntityRefs)) { |
3815 if (!entity) 3816 return XML_ERROR_UNDEFINED_ENTITY; 3817 else if (!entity->is_internal) 3818 return XML_ERROR_ENTITY_DECLARED_IN_PE; 3819 } 3820 else if (!entity) { | 4389 if (!entity) 4390 return XML_ERROR_UNDEFINED_ENTITY; 4391 else if (!entity->is_internal) 4392 return XML_ERROR_ENTITY_DECLARED_IN_PE; 4393 } 4394 else if (!entity) { |
3821 dtd.keepProcessing = dtd.standalone; | 4395 dtd->keepProcessing = dtd->standalone; |
3822 /* cannot report skipped entities in declarations */ 3823 if ((role == XML_ROLE_PARAM_ENTITY_REF) && skippedEntityHandler) { 3824 skippedEntityHandler(handlerArg, name, 1); 3825 handleDefault = XML_FALSE; 3826 } 3827 break; 3828 } 3829 if (entity->open) 3830 return XML_ERROR_RECURSIVE_ENTITY_REF; 3831 if (entity->textPtr) { 3832 enum XML_Error result; | 4396 /* cannot report skipped entities in declarations */ 4397 if ((role == XML_ROLE_PARAM_ENTITY_REF) && skippedEntityHandler) { 4398 skippedEntityHandler(handlerArg, name, 1); 4399 handleDefault = XML_FALSE; 4400 } 4401 break; 4402 } 4403 if (entity->open) 4404 return XML_ERROR_RECURSIVE_ENTITY_REF; 4405 if (entity->textPtr) { 4406 enum XML_Error result; |
3833 result = processInternalParamEntity(parser, entity); | 4407 XML_Bool betweenDecl = 4408 (role == XML_ROLE_PARAM_ENTITY_REF ? XML_TRUE : XML_FALSE); 4409 result = processInternalEntity(parser, entity, betweenDecl); |
3834 if (result != XML_ERROR_NONE) 3835 return result; 3836 handleDefault = XML_FALSE; 3837 break; 3838 } 3839 if (externalEntityRefHandler) { | 4410 if (result != XML_ERROR_NONE) 4411 return result; 4412 handleDefault = XML_FALSE; 4413 break; 4414 } 4415 if (externalEntityRefHandler) { |
3840 dtd.paramEntityRead = XML_FALSE; | 4416 dtd->paramEntityRead = XML_FALSE; |
3841 entity->open = XML_TRUE; 3842 if (!externalEntityRefHandler(externalEntityRefHandlerArg, 3843 0, 3844 entity->base, 3845 entity->systemId, 3846 entity->publicId)) { 3847 entity->open = XML_FALSE; 3848 return XML_ERROR_EXTERNAL_ENTITY_HANDLING; 3849 } 3850 entity->open = XML_FALSE; 3851 handleDefault = XML_FALSE; | 4417 entity->open = XML_TRUE; 4418 if (!externalEntityRefHandler(externalEntityRefHandlerArg, 4419 0, 4420 entity->base, 4421 entity->systemId, 4422 entity->publicId)) { 4423 entity->open = XML_FALSE; 4424 return XML_ERROR_EXTERNAL_ENTITY_HANDLING; 4425 } 4426 entity->open = XML_FALSE; 4427 handleDefault = XML_FALSE; |
3852 if (!dtd.paramEntityRead) { 3853 dtd.keepProcessing = dtd.standalone; | 4428 if (!dtd->paramEntityRead) { 4429 dtd->keepProcessing = dtd->standalone; |
3854 break; 3855 } 3856 } 3857 else { | 4430 break; 4431 } 4432 } 4433 else { |
3858 dtd.keepProcessing = dtd.standalone; | 4434 dtd->keepProcessing = dtd->standalone; |
3859 break; 3860 } 3861 } 3862#endif /* XML_DTD */ | 4435 break; 4436 } 4437 } 4438#endif /* XML_DTD */ |
3863 if (!dtd.standalone && | 4439 if (!dtd->standalone && |
3864 notStandaloneHandler && 3865 !notStandaloneHandler(handlerArg)) 3866 return XML_ERROR_NOT_STANDALONE; 3867 break; 3868 3869 /* Element declaration stuff */ 3870 3871 case XML_ROLE_ELEMENT_NAME: 3872 if (elementDeclHandler) { 3873 declElementType = getElementType(parser, enc, s, next); 3874 if (!declElementType) 3875 return XML_ERROR_NO_MEMORY; | 4440 notStandaloneHandler && 4441 !notStandaloneHandler(handlerArg)) 4442 return XML_ERROR_NOT_STANDALONE; 4443 break; 4444 4445 /* Element declaration stuff */ 4446 4447 case XML_ROLE_ELEMENT_NAME: 4448 if (elementDeclHandler) { 4449 declElementType = getElementType(parser, enc, s, next); 4450 if (!declElementType) 4451 return XML_ERROR_NO_MEMORY; |
3876 dtd.scaffLevel = 0; 3877 dtd.scaffCount = 0; 3878 dtd.in_eldecl = XML_TRUE; | 4452 dtd->scaffLevel = 0; 4453 dtd->scaffCount = 0; 4454 dtd->in_eldecl = XML_TRUE; |
3879 handleDefault = XML_FALSE; 3880 } 3881 break; 3882 3883 case XML_ROLE_CONTENT_ANY: 3884 case XML_ROLE_CONTENT_EMPTY: | 4455 handleDefault = XML_FALSE; 4456 } 4457 break; 4458 4459 case XML_ROLE_CONTENT_ANY: 4460 case XML_ROLE_CONTENT_EMPTY: |
3885 if (dtd.in_eldecl) { | 4461 if (dtd->in_eldecl) { |
3886 if (elementDeclHandler) { 3887 XML_Content * content = (XML_Content *) MALLOC(sizeof(XML_Content)); 3888 if (!content) 3889 return XML_ERROR_NO_MEMORY; 3890 content->quant = XML_CQUANT_NONE; 3891 content->name = NULL; 3892 content->numchildren = 0; 3893 content->children = NULL; 3894 content->type = ((role == XML_ROLE_CONTENT_ANY) ? 3895 XML_CTYPE_ANY : 3896 XML_CTYPE_EMPTY); 3897 *eventEndPP = s; 3898 elementDeclHandler(handlerArg, declElementType->name, content); 3899 handleDefault = XML_FALSE; 3900 } | 4462 if (elementDeclHandler) { 4463 XML_Content * content = (XML_Content *) MALLOC(sizeof(XML_Content)); 4464 if (!content) 4465 return XML_ERROR_NO_MEMORY; 4466 content->quant = XML_CQUANT_NONE; 4467 content->name = NULL; 4468 content->numchildren = 0; 4469 content->children = NULL; 4470 content->type = ((role == XML_ROLE_CONTENT_ANY) ? 4471 XML_CTYPE_ANY : 4472 XML_CTYPE_EMPTY); 4473 *eventEndPP = s; 4474 elementDeclHandler(handlerArg, declElementType->name, content); 4475 handleDefault = XML_FALSE; 4476 } |
3901 dtd.in_eldecl = XML_FALSE; | 4477 dtd->in_eldecl = XML_FALSE; |
3902 } 3903 break; 3904 3905 case XML_ROLE_CONTENT_PCDATA: | 4478 } 4479 break; 4480 4481 case XML_ROLE_CONTENT_PCDATA: |
3906 if (dtd.in_eldecl) { 3907 dtd.scaffold[dtd.scaffIndex[dtd.scaffLevel - 1]].type | 4482 if (dtd->in_eldecl) { 4483 dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type |
3908 = XML_CTYPE_MIXED; 3909 if (elementDeclHandler) 3910 handleDefault = XML_FALSE; 3911 } 3912 break; 3913 3914 case XML_ROLE_CONTENT_ELEMENT: 3915 quant = XML_CQUANT_NONE; 3916 goto elementContent; 3917 case XML_ROLE_CONTENT_ELEMENT_OPT: 3918 quant = XML_CQUANT_OPT; 3919 goto elementContent; 3920 case XML_ROLE_CONTENT_ELEMENT_REP: 3921 quant = XML_CQUANT_REP; 3922 goto elementContent; 3923 case XML_ROLE_CONTENT_ELEMENT_PLUS: 3924 quant = XML_CQUANT_PLUS; 3925 elementContent: | 4484 = XML_CTYPE_MIXED; 4485 if (elementDeclHandler) 4486 handleDefault = XML_FALSE; 4487 } 4488 break; 4489 4490 case XML_ROLE_CONTENT_ELEMENT: 4491 quant = XML_CQUANT_NONE; 4492 goto elementContent; 4493 case XML_ROLE_CONTENT_ELEMENT_OPT: 4494 quant = XML_CQUANT_OPT; 4495 goto elementContent; 4496 case XML_ROLE_CONTENT_ELEMENT_REP: 4497 quant = XML_CQUANT_REP; 4498 goto elementContent; 4499 case XML_ROLE_CONTENT_ELEMENT_PLUS: 4500 quant = XML_CQUANT_PLUS; 4501 elementContent: |
3926 if (dtd.in_eldecl) { | 4502 if (dtd->in_eldecl) { |
3927 ELEMENT_TYPE *el; 3928 const XML_Char *name; 3929 int nameLen; 3930 const char *nxt = (quant == XML_CQUANT_NONE 3931 ? next 3932 : next - enc->minBytesPerChar); 3933 int myindex = nextScaffoldPart(parser); 3934 if (myindex < 0) 3935 return XML_ERROR_NO_MEMORY; | 4503 ELEMENT_TYPE *el; 4504 const XML_Char *name; 4505 int nameLen; 4506 const char *nxt = (quant == XML_CQUANT_NONE 4507 ? next 4508 : next - enc->minBytesPerChar); 4509 int myindex = nextScaffoldPart(parser); 4510 if (myindex < 0) 4511 return XML_ERROR_NO_MEMORY; |
3936 dtd.scaffold[myindex].type = XML_CTYPE_NAME; 3937 dtd.scaffold[myindex].quant = quant; | 4512 dtd->scaffold[myindex].type = XML_CTYPE_NAME; 4513 dtd->scaffold[myindex].quant = quant; |
3938 el = getElementType(parser, enc, s, nxt); 3939 if (!el) 3940 return XML_ERROR_NO_MEMORY; 3941 name = el->name; | 4514 el = getElementType(parser, enc, s, nxt); 4515 if (!el) 4516 return XML_ERROR_NO_MEMORY; 4517 name = el->name; |
3942 dtd.scaffold[myindex].name = name; | 4518 dtd->scaffold[myindex].name = name; |
3943 nameLen = 0; 3944 for (; name[nameLen++]; ); | 4519 nameLen = 0; 4520 for (; name[nameLen++]; ); |
3945 dtd.contentStringLen += nameLen; | 4521 dtd->contentStringLen += nameLen; |
3946 if (elementDeclHandler) 3947 handleDefault = XML_FALSE; 3948 } 3949 break; 3950 3951 case XML_ROLE_GROUP_CLOSE: 3952 quant = XML_CQUANT_NONE; 3953 goto closeGroup; 3954 case XML_ROLE_GROUP_CLOSE_OPT: 3955 quant = XML_CQUANT_OPT; 3956 goto closeGroup; 3957 case XML_ROLE_GROUP_CLOSE_REP: 3958 quant = XML_CQUANT_REP; 3959 goto closeGroup; 3960 case XML_ROLE_GROUP_CLOSE_PLUS: 3961 quant = XML_CQUANT_PLUS; 3962 closeGroup: | 4522 if (elementDeclHandler) 4523 handleDefault = XML_FALSE; 4524 } 4525 break; 4526 4527 case XML_ROLE_GROUP_CLOSE: 4528 quant = XML_CQUANT_NONE; 4529 goto closeGroup; 4530 case XML_ROLE_GROUP_CLOSE_OPT: 4531 quant = XML_CQUANT_OPT; 4532 goto closeGroup; 4533 case XML_ROLE_GROUP_CLOSE_REP: 4534 quant = XML_CQUANT_REP; 4535 goto closeGroup; 4536 case XML_ROLE_GROUP_CLOSE_PLUS: 4537 quant = XML_CQUANT_PLUS; 4538 closeGroup: |
3963 if (dtd.in_eldecl) { | 4539 if (dtd->in_eldecl) { |
3964 if (elementDeclHandler) 3965 handleDefault = XML_FALSE; | 4540 if (elementDeclHandler) 4541 handleDefault = XML_FALSE; |
3966 dtd.scaffLevel--; 3967 dtd.scaffold[dtd.scaffIndex[dtd.scaffLevel]].quant = quant; 3968 if (dtd.scaffLevel == 0) { | 4542 dtd->scaffLevel--; 4543 dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel]].quant = quant; 4544 if (dtd->scaffLevel == 0) { |
3969 if (!handleDefault) { 3970 XML_Content *model = build_model(parser); 3971 if (!model) 3972 return XML_ERROR_NO_MEMORY; 3973 *eventEndPP = s; 3974 elementDeclHandler(handlerArg, declElementType->name, model); 3975 } | 4545 if (!handleDefault) { 4546 XML_Content *model = build_model(parser); 4547 if (!model) 4548 return XML_ERROR_NO_MEMORY; 4549 *eventEndPP = s; 4550 elementDeclHandler(handlerArg, declElementType->name, model); 4551 } |
3976 dtd.in_eldecl = XML_FALSE; 3977 dtd.contentStringLen = 0; | 4552 dtd->in_eldecl = XML_FALSE; 4553 dtd->contentStringLen = 0; |
3978 } 3979 } 3980 break; 3981 /* End element declaration stuff */ 3982 3983 case XML_ROLE_PI: 3984 if (!reportProcessingInstruction(parser, enc, s, next)) 3985 return XML_ERROR_NO_MEMORY; --- 11 unchanged lines hidden (view full) --- 3997 break; 3998 } 3999 break; 4000 case XML_ROLE_DOCTYPE_NONE: 4001 if (startDoctypeDeclHandler) 4002 handleDefault = XML_FALSE; 4003 break; 4004 case XML_ROLE_ENTITY_NONE: | 4554 } 4555 } 4556 break; 4557 /* End element declaration stuff */ 4558 4559 case XML_ROLE_PI: 4560 if (!reportProcessingInstruction(parser, enc, s, next)) 4561 return XML_ERROR_NO_MEMORY; --- 11 unchanged lines hidden (view full) --- 4573 break; 4574 } 4575 break; 4576 case XML_ROLE_DOCTYPE_NONE: 4577 if (startDoctypeDeclHandler) 4578 handleDefault = XML_FALSE; 4579 break; 4580 case XML_ROLE_ENTITY_NONE: |
4005 if (dtd.keepProcessing && entityDeclHandler) | 4581 if (dtd->keepProcessing && entityDeclHandler) |
4006 handleDefault = XML_FALSE; 4007 break; 4008 case XML_ROLE_NOTATION_NONE: 4009 if (notationDeclHandler) 4010 handleDefault = XML_FALSE; 4011 break; 4012 case XML_ROLE_ATTLIST_NONE: | 4582 handleDefault = XML_FALSE; 4583 break; 4584 case XML_ROLE_NOTATION_NONE: 4585 if (notationDeclHandler) 4586 handleDefault = XML_FALSE; 4587 break; 4588 case XML_ROLE_ATTLIST_NONE: |
4013 if (dtd.keepProcessing && attlistDeclHandler) | 4589 if (dtd->keepProcessing && attlistDeclHandler) |
4014 handleDefault = XML_FALSE; 4015 break; 4016 case XML_ROLE_ELEMENT_NONE: 4017 if (elementDeclHandler) 4018 handleDefault = XML_FALSE; 4019 break; 4020 } /* end of big switch */ 4021 | 4590 handleDefault = XML_FALSE; 4591 break; 4592 case XML_ROLE_ELEMENT_NONE: 4593 if (elementDeclHandler) 4594 handleDefault = XML_FALSE; 4595 break; 4596 } /* end of big switch */ 4597 |
4022 if (handleDefault && defaultHandler) | 4598 if (handleDefault && defaultHandler) |
4023 reportDefault(parser, enc, s, next); 4024 | 4599 reportDefault(parser, enc, s, next); 4600 |
4025 s = next; 4026 tok = XmlPrologTok(enc, s, end, &next); | 4601 switch (ps_parsing) { 4602 case XML_SUSPENDED: 4603 *nextPtr = next; 4604 return XML_ERROR_NONE; 4605 case XML_FINISHED: 4606 return XML_ERROR_ABORTED; 4607 default: 4608 s = next; 4609 tok = XmlPrologTok(enc, s, end, &next); 4610 } |
4027 } 4028 /* not reached */ 4029} 4030 | 4611 } 4612 /* not reached */ 4613} 4614 |
4031static enum XML_Error FASTCALL | 4615static enum XML_Error PTRCALL |
4032epilogProcessor(XML_Parser parser, 4033 const char *s, 4034 const char *end, 4035 const char **nextPtr) 4036{ 4037 processor = epilogProcessor; 4038 eventPtr = s; 4039 for (;;) { 4040 const char *next = NULL; 4041 int tok = XmlPrologTok(encoding, s, end, &next); 4042 eventEndPtr = next; 4043 switch (tok) { 4044 /* report partial linebreak - it might be the last token */ | 4616epilogProcessor(XML_Parser parser, 4617 const char *s, 4618 const char *end, 4619 const char **nextPtr) 4620{ 4621 processor = epilogProcessor; 4622 eventPtr = s; 4623 for (;;) { 4624 const char *next = NULL; 4625 int tok = XmlPrologTok(encoding, s, end, &next); 4626 eventEndPtr = next; 4627 switch (tok) { 4628 /* report partial linebreak - it might be the last token */ |
4045 case -XML_TOK_PROLOG_S: | 4629 case -XML_TOK_PROLOG_S: |
4046 if (defaultHandler) { | 4630 if (defaultHandler) { |
4047 eventEndPtr = next; | |
4048 reportDefault(parser, encoding, s, next); | 4631 reportDefault(parser, encoding, s, next); |
4632 if (ps_parsing == XML_FINISHED) 4633 return XML_ERROR_ABORTED; |
|
4049 } | 4634 } |
4050 if (nextPtr) 4051 *nextPtr = next; | 4635 *nextPtr = next; |
4052 return XML_ERROR_NONE; 4053 case XML_TOK_NONE: | 4636 return XML_ERROR_NONE; 4637 case XML_TOK_NONE: |
4054 if (nextPtr) 4055 *nextPtr = s; | 4638 *nextPtr = s; |
4056 return XML_ERROR_NONE; 4057 case XML_TOK_PROLOG_S: 4058 if (defaultHandler) 4059 reportDefault(parser, encoding, s, next); 4060 break; 4061 case XML_TOK_PI: 4062 if (!reportProcessingInstruction(parser, encoding, s, next)) 4063 return XML_ERROR_NO_MEMORY; 4064 break; 4065 case XML_TOK_COMMENT: 4066 if (!reportComment(parser, encoding, s, next)) 4067 return XML_ERROR_NO_MEMORY; 4068 break; 4069 case XML_TOK_INVALID: 4070 eventPtr = next; 4071 return XML_ERROR_INVALID_TOKEN; 4072 case XML_TOK_PARTIAL: | 4639 return XML_ERROR_NONE; 4640 case XML_TOK_PROLOG_S: 4641 if (defaultHandler) 4642 reportDefault(parser, encoding, s, next); 4643 break; 4644 case XML_TOK_PI: 4645 if (!reportProcessingInstruction(parser, encoding, s, next)) 4646 return XML_ERROR_NO_MEMORY; 4647 break; 4648 case XML_TOK_COMMENT: 4649 if (!reportComment(parser, encoding, s, next)) 4650 return XML_ERROR_NO_MEMORY; 4651 break; 4652 case XML_TOK_INVALID: 4653 eventPtr = next; 4654 return XML_ERROR_INVALID_TOKEN; 4655 case XML_TOK_PARTIAL: |
4073 if (nextPtr) { | 4656 if (!ps_finalBuffer) { |
4074 *nextPtr = s; 4075 return XML_ERROR_NONE; 4076 } 4077 return XML_ERROR_UNCLOSED_TOKEN; 4078 case XML_TOK_PARTIAL_CHAR: | 4657 *nextPtr = s; 4658 return XML_ERROR_NONE; 4659 } 4660 return XML_ERROR_UNCLOSED_TOKEN; 4661 case XML_TOK_PARTIAL_CHAR: |
4079 if (nextPtr) { | 4662 if (!ps_finalBuffer) { |
4080 *nextPtr = s; 4081 return XML_ERROR_NONE; 4082 } 4083 return XML_ERROR_PARTIAL_CHAR; 4084 default: 4085 return XML_ERROR_JUNK_AFTER_DOC_ELEMENT; 4086 } 4087 eventPtr = s = next; | 4663 *nextPtr = s; 4664 return XML_ERROR_NONE; 4665 } 4666 return XML_ERROR_PARTIAL_CHAR; 4667 default: 4668 return XML_ERROR_JUNK_AFTER_DOC_ELEMENT; 4669 } 4670 eventPtr = s = next; |
4671 switch (ps_parsing) { 4672 case XML_SUSPENDED: 4673 *nextPtr = next; 4674 return XML_ERROR_NONE; 4675 case XML_FINISHED: 4676 return XML_ERROR_ABORTED; 4677 default: ; 4678 } |
|
4088 } 4089} 4090 | 4679 } 4680} 4681 |
4091#ifdef XML_DTD 4092 4093static enum XML_Error FASTCALL 4094processInternalParamEntity(XML_Parser parser, ENTITY *entity) | 4682static enum XML_Error 4683processInternalEntity(XML_Parser parser, ENTITY *entity, 4684 XML_Bool betweenDecl) |
4095{ | 4685{ |
4096 const char *s, *end, *next; 4097 int tok; | 4686 const char *textStart, *textEnd; 4687 const char *next; |
4098 enum XML_Error result; | 4688 enum XML_Error result; |
4099 OPEN_INTERNAL_ENTITY openEntity; | 4689 OPEN_INTERNAL_ENTITY *openEntity; 4690 4691 if (freeInternalEntities) { 4692 openEntity = freeInternalEntities; 4693 freeInternalEntities = openEntity->next; 4694 } 4695 else { 4696 openEntity = (OPEN_INTERNAL_ENTITY *)MALLOC(sizeof(OPEN_INTERNAL_ENTITY)); 4697 if (!openEntity) 4698 return XML_ERROR_NO_MEMORY; 4699 } |
4100 entity->open = XML_TRUE; | 4700 entity->open = XML_TRUE; |
4101 openEntity.next = openInternalEntities; 4102 openInternalEntities = &openEntity; 4103 openEntity.entity = entity; 4104 openEntity.internalEventPtr = NULL; 4105 openEntity.internalEventEndPtr = NULL; 4106 s = (char *)entity->textPtr; 4107 end = (char *)(entity->textPtr + entity->textLen); 4108 tok = XmlPrologTok(internalEncoding, s, end, &next); 4109 result = doProlog(parser, internalEncoding, s, end, tok, next, 0); 4110 entity->open = XML_FALSE; 4111 openInternalEntities = openEntity.next; | 4701 entity->processed = 0; 4702 openEntity->next = openInternalEntities; 4703 openInternalEntities = openEntity; 4704 openEntity->entity = entity; 4705 openEntity->startTagLevel = tagLevel; 4706 openEntity->betweenDecl = betweenDecl; 4707 openEntity->internalEventPtr = NULL; 4708 openEntity->internalEventEndPtr = NULL; 4709 textStart = (char *)entity->textPtr; 4710 textEnd = (char *)(entity->textPtr + entity->textLen); 4711 4712#ifdef XML_DTD 4713 if (entity->is_param) { 4714 int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next); 4715 result = doProlog(parser, internalEncoding, textStart, textEnd, tok, 4716 next, &next, XML_FALSE); 4717 } 4718 else 4719#endif /* XML_DTD */ 4720 result = doContent(parser, tagLevel, internalEncoding, textStart, 4721 textEnd, &next, XML_FALSE); 4722 4723 if (result == XML_ERROR_NONE) { 4724 if (textEnd != next && ps_parsing == XML_SUSPENDED) { 4725 entity->processed = (int)(next - textStart); 4726 processor = internalEntityProcessor; 4727 } 4728 else { 4729 entity->open = XML_FALSE; 4730 openInternalEntities = openEntity->next; 4731 /* put openEntity back in list of free instances */ 4732 openEntity->next = freeInternalEntities; 4733 freeInternalEntities = openEntity; 4734 } 4735 } |
4112 return result; 4113} 4114 | 4736 return result; 4737} 4738 |
4739static enum XML_Error PTRCALL 4740internalEntityProcessor(XML_Parser parser, 4741 const char *s, 4742 const char *end, 4743 const char **nextPtr) 4744{ 4745 ENTITY *entity; 4746 const char *textStart, *textEnd; 4747 const char *next; 4748 enum XML_Error result; 4749 OPEN_INTERNAL_ENTITY *openEntity = openInternalEntities; 4750 if (!openEntity) 4751 return XML_ERROR_UNEXPECTED_STATE; 4752 4753 entity = openEntity->entity; 4754 textStart = ((char *)entity->textPtr) + entity->processed; 4755 textEnd = (char *)(entity->textPtr + entity->textLen); 4756 4757#ifdef XML_DTD 4758 if (entity->is_param) { 4759 int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next); 4760 result = doProlog(parser, internalEncoding, textStart, textEnd, tok, 4761 next, &next, XML_FALSE); 4762 } 4763 else |
|
4115#endif /* XML_DTD */ | 4764#endif /* XML_DTD */ |
4765 result = doContent(parser, openEntity->startTagLevel, internalEncoding, 4766 textStart, textEnd, &next, XML_FALSE); |
|
4116 | 4767 |
4117static enum XML_Error FASTCALL | 4768 if (result != XML_ERROR_NONE) 4769 return result; 4770 else if (textEnd != next && ps_parsing == XML_SUSPENDED) { 4771 entity->processed = (int)(next - (char *)entity->textPtr); 4772 return result; 4773 } 4774 else { 4775 entity->open = XML_FALSE; 4776 openInternalEntities = openEntity->next; 4777 /* put openEntity back in list of free instances */ 4778 openEntity->next = freeInternalEntities; 4779 freeInternalEntities = openEntity; 4780 } 4781 4782#ifdef XML_DTD 4783 if (entity->is_param) { 4784 int tok; 4785 processor = prologProcessor; 4786 tok = XmlPrologTok(encoding, s, end, &next); 4787 return doProlog(parser, encoding, s, end, tok, next, nextPtr, 4788 (XML_Bool)!ps_finalBuffer); 4789 } 4790 else 4791#endif /* XML_DTD */ 4792 { 4793 processor = contentProcessor; 4794 /* see externalEntityContentProcessor vs contentProcessor */ 4795 return doContent(parser, parentParser ? 1 : 0, encoding, s, end, 4796 nextPtr, (XML_Bool)!ps_finalBuffer); 4797 } 4798} 4799 4800static enum XML_Error PTRCALL |
4118errorProcessor(XML_Parser parser, 4119 const char *s, 4120 const char *end, 4121 const char **nextPtr) 4122{ 4123 return errorCode; 4124} 4125 | 4801errorProcessor(XML_Parser parser, 4802 const char *s, 4803 const char *end, 4804 const char **nextPtr) 4805{ 4806 return errorCode; 4807} 4808 |
4126static enum XML_Error FASTCALL | 4809static enum XML_Error |
4127storeAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, 4128 const char *ptr, const char *end, 4129 STRING_POOL *pool) 4130{ 4131 enum XML_Error result = appendAttributeValue(parser, enc, isCdata, ptr, 4132 end, pool); 4133 if (result) 4134 return result; 4135 if (!isCdata && poolLength(pool) && poolLastChar(pool) == 0x20) 4136 poolChop(pool); 4137 if (!poolAppendChar(pool, XML_T('\0'))) 4138 return XML_ERROR_NO_MEMORY; 4139 return XML_ERROR_NONE; 4140} 4141 | 4810storeAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, 4811 const char *ptr, const char *end, 4812 STRING_POOL *pool) 4813{ 4814 enum XML_Error result = appendAttributeValue(parser, enc, isCdata, ptr, 4815 end, pool); 4816 if (result) 4817 return result; 4818 if (!isCdata && poolLength(pool) && poolLastChar(pool) == 0x20) 4819 poolChop(pool); 4820 if (!poolAppendChar(pool, XML_T('\0'))) 4821 return XML_ERROR_NO_MEMORY; 4822 return XML_ERROR_NONE; 4823} 4824 |
4142static enum XML_Error FASTCALL | 4825static enum XML_Error |
4143appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, 4144 const char *ptr, const char *end, 4145 STRING_POOL *pool) 4146{ | 4826appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, 4827 const char *ptr, const char *end, 4828 STRING_POOL *pool) 4829{ |
4830 DTD * const dtd = _dtd; /* save one level of indirection */ |
|
4147 for (;;) { 4148 const char *next; 4149 int tok = XmlAttributeValueTok(enc, ptr, end, &next); 4150 switch (tok) { 4151 case XML_TOK_NONE: 4152 return XML_ERROR_NONE; 4153 case XML_TOK_INVALID: 4154 if (enc == encoding) --- 56 unchanged lines hidden (view full) --- 4211 return XML_ERROR_NO_MEMORY; 4212 break; 4213 } 4214 name = poolStoreString(&temp2Pool, enc, 4215 ptr + enc->minBytesPerChar, 4216 next - enc->minBytesPerChar); 4217 if (!name) 4218 return XML_ERROR_NO_MEMORY; | 4831 for (;;) { 4832 const char *next; 4833 int tok = XmlAttributeValueTok(enc, ptr, end, &next); 4834 switch (tok) { 4835 case XML_TOK_NONE: 4836 return XML_ERROR_NONE; 4837 case XML_TOK_INVALID: 4838 if (enc == encoding) --- 56 unchanged lines hidden (view full) --- 4895 return XML_ERROR_NO_MEMORY; 4896 break; 4897 } 4898 name = poolStoreString(&temp2Pool, enc, 4899 ptr + enc->minBytesPerChar, 4900 next - enc->minBytesPerChar); 4901 if (!name) 4902 return XML_ERROR_NO_MEMORY; |
4219 entity = (ENTITY *)lookup(&dtd.generalEntities, name, 0); | 4903 entity = (ENTITY *)lookup(&dtd->generalEntities, name, 0); |
4220 poolDiscard(&temp2Pool); | 4904 poolDiscard(&temp2Pool); |
4221 /* first, determine if a check for an existing declaration is needed; 4222 if yes, check that the entity exists, and that it is internal, 4223 otherwise call the default handler (if called from content) | 4905 /* First, determine if a check for an existing declaration is needed; 4906 if yes, check that the entity exists, and that it is internal. |
4224 */ | 4907 */ |
4225 if (pool == &dtd.pool) /* are we called from prolog? */ | 4908 if (pool == &dtd->pool) /* are we called from prolog? */ |
4226 checkEntityDecl = 4227#ifdef XML_DTD 4228 prologState.documentEntity && 4229#endif /* XML_DTD */ | 4909 checkEntityDecl = 4910#ifdef XML_DTD 4911 prologState.documentEntity && 4912#endif /* XML_DTD */ |
4230 (dtd.standalone | 4913 (dtd->standalone |
4231 ? !openInternalEntities | 4914 ? !openInternalEntities |
4232 : !dtd.hasParamEntityRefs); | 4915 : !dtd->hasParamEntityRefs); |
4233 else /* if (pool == &tempPool): we are called from content */ | 4916 else /* if (pool == &tempPool): we are called from content */ |
4234 checkEntityDecl = !dtd.hasParamEntityRefs || dtd.standalone; | 4917 checkEntityDecl = !dtd->hasParamEntityRefs || dtd->standalone; |
4235 if (checkEntityDecl) { 4236 if (!entity) 4237 return XML_ERROR_UNDEFINED_ENTITY; 4238 else if (!entity->is_internal) 4239 return XML_ERROR_ENTITY_DECLARED_IN_PE; 4240 } 4241 else if (!entity) { | 4918 if (checkEntityDecl) { 4919 if (!entity) 4920 return XML_ERROR_UNDEFINED_ENTITY; 4921 else if (!entity->is_internal) 4922 return XML_ERROR_ENTITY_DECLARED_IN_PE; 4923 } 4924 else if (!entity) { |
4242 /* cannot report skipped entity here - see comments on 4243 skippedEntityHandler | 4925 /* Cannot report skipped entity here - see comments on 4926 skippedEntityHandler. |
4244 if (skippedEntityHandler) 4245 skippedEntityHandler(handlerArg, name, 0); 4246 */ | 4927 if (skippedEntityHandler) 4928 skippedEntityHandler(handlerArg, name, 0); 4929 */ |
4930 /* Cannot call the default handler because this would be 4931 out of sync with the call to the startElementHandler. |
|
4247 if ((pool == &tempPool) && defaultHandler) 4248 reportDefault(parser, enc, ptr, next); | 4932 if ((pool == &tempPool) && defaultHandler) 4933 reportDefault(parser, enc, ptr, next); |
4934 */ |
|
4249 break; 4250 } 4251 if (entity->open) { 4252 if (enc == encoding) 4253 eventPtr = ptr; 4254 return XML_ERROR_RECURSIVE_ENTITY_REF; 4255 } 4256 if (entity->notation) { --- 24 unchanged lines hidden (view full) --- 4281 eventPtr = ptr; 4282 return XML_ERROR_UNEXPECTED_STATE; 4283 } 4284 ptr = next; 4285 } 4286 /* not reached */ 4287} 4288 | 4935 break; 4936 } 4937 if (entity->open) { 4938 if (enc == encoding) 4939 eventPtr = ptr; 4940 return XML_ERROR_RECURSIVE_ENTITY_REF; 4941 } 4942 if (entity->notation) { --- 24 unchanged lines hidden (view full) --- 4967 eventPtr = ptr; 4968 return XML_ERROR_UNEXPECTED_STATE; 4969 } 4970 ptr = next; 4971 } 4972 /* not reached */ 4973} 4974 |
4289static enum XML_Error FASTCALL | 4975static enum XML_Error |
4290storeEntityValue(XML_Parser parser, 4291 const ENCODING *enc, 4292 const char *entityTextPtr, 4293 const char *entityTextEnd) 4294{ | 4976storeEntityValue(XML_Parser parser, 4977 const ENCODING *enc, 4978 const char *entityTextPtr, 4979 const char *entityTextEnd) 4980{ |
4295 STRING_POOL *pool = &(dtd.entityValuePool); | 4981 DTD * const dtd = _dtd; /* save one level of indirection */ 4982 STRING_POOL *pool = &(dtd->entityValuePool); |
4296 enum XML_Error result = XML_ERROR_NONE; 4297#ifdef XML_DTD 4298 int oldInEntityValue = prologState.inEntityValue; 4299 prologState.inEntityValue = 1; 4300#endif /* XML_DTD */ 4301 /* never return Null for the value argument in EntityDeclHandler, 4302 since this would indicate an external entity; therefore we 4303 have to make sure that entityValuePool.start is not null */ --- 13 unchanged lines hidden (view full) --- 4317 ENTITY *entity; 4318 name = poolStoreString(&tempPool, enc, 4319 entityTextPtr + enc->minBytesPerChar, 4320 next - enc->minBytesPerChar); 4321 if (!name) { 4322 result = XML_ERROR_NO_MEMORY; 4323 goto endEntityValue; 4324 } | 4983 enum XML_Error result = XML_ERROR_NONE; 4984#ifdef XML_DTD 4985 int oldInEntityValue = prologState.inEntityValue; 4986 prologState.inEntityValue = 1; 4987#endif /* XML_DTD */ 4988 /* never return Null for the value argument in EntityDeclHandler, 4989 since this would indicate an external entity; therefore we 4990 have to make sure that entityValuePool.start is not null */ --- 13 unchanged lines hidden (view full) --- 5004 ENTITY *entity; 5005 name = poolStoreString(&tempPool, enc, 5006 entityTextPtr + enc->minBytesPerChar, 5007 next - enc->minBytesPerChar); 5008 if (!name) { 5009 result = XML_ERROR_NO_MEMORY; 5010 goto endEntityValue; 5011 } |
4325 entity = (ENTITY *)lookup(&dtd.paramEntities, name, 0); | 5012 entity = (ENTITY *)lookup(&dtd->paramEntities, name, 0); |
4326 poolDiscard(&tempPool); 4327 if (!entity) { 4328 /* not a well-formedness error - see XML 1.0: WFC Entity Declared */ 4329 /* cannot report skipped entity here - see comments on 4330 skippedEntityHandler 4331 if (skippedEntityHandler) 4332 skippedEntityHandler(handlerArg, name, 0); 4333 */ | 5013 poolDiscard(&tempPool); 5014 if (!entity) { 5015 /* not a well-formedness error - see XML 1.0: WFC Entity Declared */ 5016 /* cannot report skipped entity here - see comments on 5017 skippedEntityHandler 5018 if (skippedEntityHandler) 5019 skippedEntityHandler(handlerArg, name, 0); 5020 */ |
4334 dtd.keepProcessing = dtd.standalone; | 5021 dtd->keepProcessing = dtd->standalone; |
4335 goto endEntityValue; 4336 } 4337 if (entity->open) { 4338 if (enc == encoding) 4339 eventPtr = entityTextPtr; 4340 result = XML_ERROR_RECURSIVE_ENTITY_REF; 4341 goto endEntityValue; 4342 } 4343 if (entity->systemId) { 4344 if (externalEntityRefHandler) { | 5022 goto endEntityValue; 5023 } 5024 if (entity->open) { 5025 if (enc == encoding) 5026 eventPtr = entityTextPtr; 5027 result = XML_ERROR_RECURSIVE_ENTITY_REF; 5028 goto endEntityValue; 5029 } 5030 if (entity->systemId) { 5031 if (externalEntityRefHandler) { |
4345 dtd.paramEntityRead = XML_FALSE; | 5032 dtd->paramEntityRead = XML_FALSE; |
4346 entity->open = XML_TRUE; 4347 if (!externalEntityRefHandler(externalEntityRefHandlerArg, 4348 0, 4349 entity->base, 4350 entity->systemId, 4351 entity->publicId)) { 4352 entity->open = XML_FALSE; 4353 result = XML_ERROR_EXTERNAL_ENTITY_HANDLING; 4354 goto endEntityValue; 4355 } 4356 entity->open = XML_FALSE; | 5033 entity->open = XML_TRUE; 5034 if (!externalEntityRefHandler(externalEntityRefHandlerArg, 5035 0, 5036 entity->base, 5037 entity->systemId, 5038 entity->publicId)) { 5039 entity->open = XML_FALSE; 5040 result = XML_ERROR_EXTERNAL_ENTITY_HANDLING; 5041 goto endEntityValue; 5042 } 5043 entity->open = XML_FALSE; |
4357 if (!dtd.paramEntityRead) 4358 dtd.keepProcessing = dtd.standalone; | 5044 if (!dtd->paramEntityRead) 5045 dtd->keepProcessing = dtd->standalone; |
4359 } 4360 else | 5046 } 5047 else |
4361 dtd.keepProcessing = dtd.standalone; | 5048 dtd->keepProcessing = dtd->standalone; |
4362 } 4363 else { 4364 entity->open = XML_TRUE; 4365 result = storeEntityValue(parser, 4366 internalEncoding, 4367 (char *)entity->textPtr, 4368 (char *)(entity->textPtr 4369 + entity->textLen)); 4370 entity->open = XML_FALSE; 4371 if (result) 4372 goto endEntityValue; 4373 } 4374 break; 4375 } 4376#endif /* XML_DTD */ | 5049 } 5050 else { 5051 entity->open = XML_TRUE; 5052 result = storeEntityValue(parser, 5053 internalEncoding, 5054 (char *)entity->textPtr, 5055 (char *)(entity->textPtr 5056 + entity->textLen)); 5057 entity->open = XML_FALSE; 5058 if (result) 5059 goto endEntityValue; 5060 } 5061 break; 5062 } 5063#endif /* XML_DTD */ |
4377 /* in the internal subset, PE references are not legal 4378 within markup declarations, e.g entity values in this case */ | 5064 /* In the internal subset, PE references are not legal 5065 within markup declarations, e.g entity values in this case. */ |
4379 eventPtr = entityTextPtr; 4380 result = XML_ERROR_PARAM_ENTITY_REF; 4381 goto endEntityValue; 4382 case XML_TOK_NONE: 4383 result = XML_ERROR_NONE; 4384 goto endEntityValue; 4385 case XML_TOK_ENTITY_REF: 4386 case XML_TOK_DATA_CHARS: --- 82 unchanged lines hidden (view full) --- 4469 s++; 4470 } 4471 else 4472 *p++ = *s++; 4473 } while (*s); 4474 *p = XML_T('\0'); 4475} 4476 | 5066 eventPtr = entityTextPtr; 5067 result = XML_ERROR_PARAM_ENTITY_REF; 5068 goto endEntityValue; 5069 case XML_TOK_NONE: 5070 result = XML_ERROR_NONE; 5071 goto endEntityValue; 5072 case XML_TOK_ENTITY_REF: 5073 case XML_TOK_DATA_CHARS: --- 82 unchanged lines hidden (view full) --- 5156 s++; 5157 } 5158 else 5159 *p++ = *s++; 5160 } while (*s); 5161 *p = XML_T('\0'); 5162} 5163 |
4477static int FASTCALL | 5164static int |
4478reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, 4479 const char *start, const char *end) 4480{ 4481 const XML_Char *target; 4482 XML_Char *data; 4483 const char *tem; 4484 if (!processingInstructionHandler) { 4485 if (defaultHandler) --- 12 unchanged lines hidden (view full) --- 4498 if (!data) 4499 return 0; 4500 normalizeLines(data); 4501 processingInstructionHandler(handlerArg, target, data); 4502 poolClear(&tempPool); 4503 return 1; 4504} 4505 | 5165reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, 5166 const char *start, const char *end) 5167{ 5168 const XML_Char *target; 5169 XML_Char *data; 5170 const char *tem; 5171 if (!processingInstructionHandler) { 5172 if (defaultHandler) --- 12 unchanged lines hidden (view full) --- 5185 if (!data) 5186 return 0; 5187 normalizeLines(data); 5188 processingInstructionHandler(handlerArg, target, data); 5189 poolClear(&tempPool); 5190 return 1; 5191} 5192 |
4506static int FASTCALL | 5193static int |
4507reportComment(XML_Parser parser, const ENCODING *enc, 4508 const char *start, const char *end) 4509{ 4510 XML_Char *data; 4511 if (!commentHandler) { 4512 if (defaultHandler) 4513 reportDefault(parser, enc, start, end); 4514 return 1; --- 5 unchanged lines hidden (view full) --- 4520 if (!data) 4521 return 0; 4522 normalizeLines(data); 4523 commentHandler(handlerArg, data); 4524 poolClear(&tempPool); 4525 return 1; 4526} 4527 | 5194reportComment(XML_Parser parser, const ENCODING *enc, 5195 const char *start, const char *end) 5196{ 5197 XML_Char *data; 5198 if (!commentHandler) { 5199 if (defaultHandler) 5200 reportDefault(parser, enc, start, end); 5201 return 1; --- 5 unchanged lines hidden (view full) --- 5207 if (!data) 5208 return 0; 5209 normalizeLines(data); 5210 commentHandler(handlerArg, data); 5211 poolClear(&tempPool); 5212 return 1; 5213} 5214 |
4528static void FASTCALL | 5215static void |
4529reportDefault(XML_Parser parser, const ENCODING *enc, 4530 const char *s, const char *end) 4531{ 4532 if (MUST_CONVERT(enc, s)) { 4533 const char **eventPP; 4534 const char **eventEndPP; 4535 if (enc == encoding) { 4536 eventPP = &eventPtr; 4537 eventEndPP = &eventEndPtr; 4538 } 4539 else { 4540 eventPP = &(openInternalEntities->internalEventPtr); 4541 eventEndPP = &(openInternalEntities->internalEventEndPtr); 4542 } 4543 do { 4544 ICHAR *dataPtr = (ICHAR *)dataBuf; 4545 XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); 4546 *eventEndPP = s; | 5216reportDefault(XML_Parser parser, const ENCODING *enc, 5217 const char *s, const char *end) 5218{ 5219 if (MUST_CONVERT(enc, s)) { 5220 const char **eventPP; 5221 const char **eventEndPP; 5222 if (enc == encoding) { 5223 eventPP = &eventPtr; 5224 eventEndPP = &eventEndPtr; 5225 } 5226 else { 5227 eventPP = &(openInternalEntities->internalEventPtr); 5228 eventEndPP = &(openInternalEntities->internalEventEndPtr); 5229 } 5230 do { 5231 ICHAR *dataPtr = (ICHAR *)dataBuf; 5232 XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); 5233 *eventEndPP = s; |
4547 defaultHandler(handlerArg, dataBuf, dataPtr - (ICHAR *)dataBuf); | 5234 defaultHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf)); |
4548 *eventPP = s; 4549 } while (s != end); 4550 } 4551 else | 5235 *eventPP = s; 5236 } while (s != end); 5237 } 5238 else |
4552 defaultHandler(handlerArg, (XML_Char *)s, (XML_Char *)end - (XML_Char *)s); | 5239 defaultHandler(handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s)); |
4553} 4554 4555 | 5240} 5241 5242 |
4556static int FASTCALL | 5243static int |
4557defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata, 4558 XML_Bool isId, const XML_Char *value, XML_Parser parser) 4559{ 4560 DEFAULT_ATTRIBUTE *att; 4561 if (value || isId) { 4562 /* The handling of default attributes gets messed up if we have 4563 a default which duplicates a non-default. */ 4564 int i; 4565 for (i = 0; i < type->nDefaultAtts; i++) 4566 if (attId == type->defaultAtts[i].id) 4567 return 1; 4568 if (isId && !type->idAtt && !attId->xmlns) 4569 type->idAtt = attId; 4570 } 4571 if (type->nDefaultAtts == type->allocDefaultAtts) { 4572 if (type->allocDefaultAtts == 0) { 4573 type->allocDefaultAtts = 8; | 5244defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata, 5245 XML_Bool isId, const XML_Char *value, XML_Parser parser) 5246{ 5247 DEFAULT_ATTRIBUTE *att; 5248 if (value || isId) { 5249 /* The handling of default attributes gets messed up if we have 5250 a default which duplicates a non-default. */ 5251 int i; 5252 for (i = 0; i < type->nDefaultAtts; i++) 5253 if (attId == type->defaultAtts[i].id) 5254 return 1; 5255 if (isId && !type->idAtt && !attId->xmlns) 5256 type->idAtt = attId; 5257 } 5258 if (type->nDefaultAtts == type->allocDefaultAtts) { 5259 if (type->allocDefaultAtts == 0) { 5260 type->allocDefaultAtts = 8; |
4574 type->defaultAtts = MALLOC(type->allocDefaultAtts 4575 * sizeof(DEFAULT_ATTRIBUTE)); | 5261 type->defaultAtts = (DEFAULT_ATTRIBUTE *)MALLOC(type->allocDefaultAtts 5262 * sizeof(DEFAULT_ATTRIBUTE)); |
4576 if (!type->defaultAtts) 4577 return 0; 4578 } 4579 else { 4580 DEFAULT_ATTRIBUTE *temp; 4581 int count = type->allocDefaultAtts * 2; | 5263 if (!type->defaultAtts) 5264 return 0; 5265 } 5266 else { 5267 DEFAULT_ATTRIBUTE *temp; 5268 int count = type->allocDefaultAtts * 2; |
4582 temp = REALLOC(type->defaultAtts, (count * sizeof(DEFAULT_ATTRIBUTE))); | 5269 temp = (DEFAULT_ATTRIBUTE *) 5270 REALLOC(type->defaultAtts, (count * sizeof(DEFAULT_ATTRIBUTE))); |
4583 if (temp == NULL) 4584 return 0; 4585 type->allocDefaultAtts = count; 4586 type->defaultAtts = temp; 4587 } 4588 } 4589 att = type->defaultAtts + type->nDefaultAtts; 4590 att->id = attId; 4591 att->value = value; 4592 att->isCdata = isCdata; 4593 if (!isCdata) 4594 attId->maybeTokenized = XML_TRUE; 4595 type->nDefaultAtts += 1; 4596 return 1; 4597} 4598 | 5271 if (temp == NULL) 5272 return 0; 5273 type->allocDefaultAtts = count; 5274 type->defaultAtts = temp; 5275 } 5276 } 5277 att = type->defaultAtts + type->nDefaultAtts; 5278 att->id = attId; 5279 att->value = value; 5280 att->isCdata = isCdata; 5281 if (!isCdata) 5282 attId->maybeTokenized = XML_TRUE; 5283 type->nDefaultAtts += 1; 5284 return 1; 5285} 5286 |
4599static int FASTCALL | 5287static int |
4600setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *elementType) 4601{ | 5288setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *elementType) 5289{ |
5290 DTD * const dtd = _dtd; /* save one level of indirection */ |
|
4602 const XML_Char *name; 4603 for (name = elementType->name; *name; name++) { | 5291 const XML_Char *name; 5292 for (name = elementType->name; *name; name++) { |
4604 if (*name == XML_T(':')) { | 5293 if (*name == XML_T(ASCII_COLON)) { |
4605 PREFIX *prefix; 4606 const XML_Char *s; 4607 for (s = elementType->name; s != name; s++) { | 5294 PREFIX *prefix; 5295 const XML_Char *s; 5296 for (s = elementType->name; s != name; s++) { |
4608 if (!poolAppendChar(&dtd.pool, *s)) | 5297 if (!poolAppendChar(&dtd->pool, *s)) |
4609 return 0; 4610 } | 5298 return 0; 5299 } |
4611 if (!poolAppendChar(&dtd.pool, XML_T('\0'))) | 5300 if (!poolAppendChar(&dtd->pool, XML_T('\0'))) |
4612 return 0; | 5301 return 0; |
4613 prefix = (PREFIX *)lookup(&dtd.prefixes, poolStart(&dtd.pool), | 5302 prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&dtd->pool), |
4614 sizeof(PREFIX)); 4615 if (!prefix) 4616 return 0; | 5303 sizeof(PREFIX)); 5304 if (!prefix) 5305 return 0; |
4617 if (prefix->name == poolStart(&dtd.pool)) 4618 poolFinish(&dtd.pool); | 5306 if (prefix->name == poolStart(&dtd->pool)) 5307 poolFinish(&dtd->pool); |
4619 else | 5308 else |
4620 poolDiscard(&dtd.pool); | 5309 poolDiscard(&dtd->pool); |
4621 elementType->prefix = prefix; 4622 4623 } 4624 } 4625 return 1; 4626} 4627 | 5310 elementType->prefix = prefix; 5311 5312 } 5313 } 5314 return 1; 5315} 5316 |
4628static ATTRIBUTE_ID * FASTCALL | 5317static ATTRIBUTE_ID * |
4629getAttributeId(XML_Parser parser, const ENCODING *enc, 4630 const char *start, const char *end) 4631{ | 5318getAttributeId(XML_Parser parser, const ENCODING *enc, 5319 const char *start, const char *end) 5320{ |
5321 DTD * const dtd = _dtd; /* save one level of indirection */ |
|
4632 ATTRIBUTE_ID *id; 4633 const XML_Char *name; | 5322 ATTRIBUTE_ID *id; 5323 const XML_Char *name; |
4634 if (!poolAppendChar(&dtd.pool, XML_T('\0'))) | 5324 if (!poolAppendChar(&dtd->pool, XML_T('\0'))) |
4635 return NULL; | 5325 return NULL; |
4636 name = poolStoreString(&dtd.pool, enc, start, end); | 5326 name = poolStoreString(&dtd->pool, enc, start, end); |
4637 if (!name) 4638 return NULL; | 5327 if (!name) 5328 return NULL; |
5329 /* skip quotation mark - its storage will be re-used (like in name[-1]) */ |
|
4639 ++name; | 5330 ++name; |
4640 id = (ATTRIBUTE_ID *)lookup(&dtd.attributeIds, name, sizeof(ATTRIBUTE_ID)); | 5331 id = (ATTRIBUTE_ID *)lookup(&dtd->attributeIds, name, sizeof(ATTRIBUTE_ID)); |
4641 if (!id) 4642 return NULL; 4643 if (id->name != name) | 5332 if (!id) 5333 return NULL; 5334 if (id->name != name) |
4644 poolDiscard(&dtd.pool); | 5335 poolDiscard(&dtd->pool); |
4645 else { | 5336 else { |
4646 poolFinish(&dtd.pool); | 5337 poolFinish(&dtd->pool); |
4647 if (!ns) 4648 ; | 5338 if (!ns) 5339 ; |
4649 else if (name[0] == 'x' 4650 && name[1] == 'm' 4651 && name[2] == 'l' 4652 && name[3] == 'n' 4653 && name[4] == 's' 4654 && (name[5] == XML_T('\0') || name[5] == XML_T(':'))) { 4655 if (name[5] == '\0') 4656 id->prefix = &dtd.defaultPrefix; | 5340 else if (name[0] == XML_T(ASCII_x) 5341 && name[1] == XML_T(ASCII_m) 5342 && name[2] == XML_T(ASCII_l) 5343 && name[3] == XML_T(ASCII_n) 5344 && name[4] == XML_T(ASCII_s) 5345 && (name[5] == XML_T('\0') || name[5] == XML_T(ASCII_COLON))) { 5346 if (name[5] == XML_T('\0')) 5347 id->prefix = &dtd->defaultPrefix; |
4657 else | 5348 else |
4658 id->prefix = (PREFIX *)lookup(&dtd.prefixes, name + 6, sizeof(PREFIX)); | 5349 id->prefix = (PREFIX *)lookup(&dtd->prefixes, name + 6, sizeof(PREFIX)); |
4659 id->xmlns = XML_TRUE; 4660 } 4661 else { 4662 int i; 4663 for (i = 0; name[i]; i++) { | 5350 id->xmlns = XML_TRUE; 5351 } 5352 else { 5353 int i; 5354 for (i = 0; name[i]; i++) { |
4664 if (name[i] == XML_T(':')) { | 5355 /* attributes without prefix are *not* in the default namespace */ 5356 if (name[i] == XML_T(ASCII_COLON)) { |
4665 int j; 4666 for (j = 0; j < i; j++) { | 5357 int j; 5358 for (j = 0; j < i; j++) { |
4667 if (!poolAppendChar(&dtd.pool, name[j])) | 5359 if (!poolAppendChar(&dtd->pool, name[j])) |
4668 return NULL; 4669 } | 5360 return NULL; 5361 } |
4670 if (!poolAppendChar(&dtd.pool, XML_T('\0'))) | 5362 if (!poolAppendChar(&dtd->pool, XML_T('\0'))) |
4671 return NULL; | 5363 return NULL; |
4672 id->prefix = (PREFIX *)lookup(&dtd.prefixes, poolStart(&dtd.pool), | 5364 id->prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&dtd->pool), |
4673 sizeof(PREFIX)); | 5365 sizeof(PREFIX)); |
4674 if (id->prefix->name == poolStart(&dtd.pool)) 4675 poolFinish(&dtd.pool); | 5366 if (id->prefix->name == poolStart(&dtd->pool)) 5367 poolFinish(&dtd->pool); |
4676 else | 5368 else |
4677 poolDiscard(&dtd.pool); | 5369 poolDiscard(&dtd->pool); |
4678 break; 4679 } 4680 } 4681 } 4682 } 4683 return id; 4684} 4685 | 5370 break; 5371 } 5372 } 5373 } 5374 } 5375 return id; 5376} 5377 |
4686#define CONTEXT_SEP XML_T('\f') | 5378#define CONTEXT_SEP XML_T(ASCII_FF) |
4687 | 5379 |
4688static const XML_Char * FASTCALL | 5380static const XML_Char * |
4689getContext(XML_Parser parser) 4690{ | 5381getContext(XML_Parser parser) 5382{ |
5383 DTD * const dtd = _dtd; /* save one level of indirection */ |
|
4691 HASH_TABLE_ITER iter; 4692 XML_Bool needSep = XML_FALSE; 4693 | 5384 HASH_TABLE_ITER iter; 5385 XML_Bool needSep = XML_FALSE; 5386 |
4694 if (dtd.defaultPrefix.binding) { | 5387 if (dtd->defaultPrefix.binding) { |
4695 int i; 4696 int len; | 5388 int i; 5389 int len; |
4697 if (!poolAppendChar(&tempPool, XML_T('='))) | 5390 if (!poolAppendChar(&tempPool, XML_T(ASCII_EQUALS))) |
4698 return NULL; | 5391 return NULL; |
4699 len = dtd.defaultPrefix.binding->uriLen; 4700 if (namespaceSeparator != XML_T('\0')) | 5392 len = dtd->defaultPrefix.binding->uriLen; 5393 if (namespaceSeparator) |
4701 len--; 4702 for (i = 0; i < len; i++) | 5394 len--; 5395 for (i = 0; i < len; i++) |
4703 if (!poolAppendChar(&tempPool, dtd.defaultPrefix.binding->uri[i])) | 5396 if (!poolAppendChar(&tempPool, dtd->defaultPrefix.binding->uri[i])) |
4704 return NULL; 4705 needSep = XML_TRUE; 4706 } 4707 | 5397 return NULL; 5398 needSep = XML_TRUE; 5399 } 5400 |
4708 hashTableIterInit(&iter, &(dtd.prefixes)); | 5401 hashTableIterInit(&iter, &(dtd->prefixes)); |
4709 for (;;) { 4710 int i; 4711 int len; 4712 const XML_Char *s; 4713 PREFIX *prefix = (PREFIX *)hashTableIterNext(&iter); 4714 if (!prefix) 4715 break; 4716 if (!prefix->binding) 4717 continue; 4718 if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP)) 4719 return NULL; 4720 for (s = prefix->name; *s; s++) 4721 if (!poolAppendChar(&tempPool, *s)) 4722 return NULL; | 5402 for (;;) { 5403 int i; 5404 int len; 5405 const XML_Char *s; 5406 PREFIX *prefix = (PREFIX *)hashTableIterNext(&iter); 5407 if (!prefix) 5408 break; 5409 if (!prefix->binding) 5410 continue; 5411 if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP)) 5412 return NULL; 5413 for (s = prefix->name; *s; s++) 5414 if (!poolAppendChar(&tempPool, *s)) 5415 return NULL; |
4723 if (!poolAppendChar(&tempPool, XML_T('='))) | 5416 if (!poolAppendChar(&tempPool, XML_T(ASCII_EQUALS))) |
4724 return NULL; 4725 len = prefix->binding->uriLen; | 5417 return NULL; 5418 len = prefix->binding->uriLen; |
4726 if (namespaceSeparator != XML_T('\0')) | 5419 if (namespaceSeparator) |
4727 len--; 4728 for (i = 0; i < len; i++) 4729 if (!poolAppendChar(&tempPool, prefix->binding->uri[i])) 4730 return NULL; 4731 needSep = XML_TRUE; 4732 } 4733 4734 | 5420 len--; 5421 for (i = 0; i < len; i++) 5422 if (!poolAppendChar(&tempPool, prefix->binding->uri[i])) 5423 return NULL; 5424 needSep = XML_TRUE; 5425 } 5426 5427 |
4735 hashTableIterInit(&iter, &(dtd.generalEntities)); | 5428 hashTableIterInit(&iter, &(dtd->generalEntities)); |
4736 for (;;) { 4737 const XML_Char *s; 4738 ENTITY *e = (ENTITY *)hashTableIterNext(&iter); 4739 if (!e) 4740 break; 4741 if (!e->open) 4742 continue; 4743 if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP)) --- 4 unchanged lines hidden (view full) --- 4748 needSep = XML_TRUE; 4749 } 4750 4751 if (!poolAppendChar(&tempPool, XML_T('\0'))) 4752 return NULL; 4753 return tempPool.start; 4754} 4755 | 5429 for (;;) { 5430 const XML_Char *s; 5431 ENTITY *e = (ENTITY *)hashTableIterNext(&iter); 5432 if (!e) 5433 break; 5434 if (!e->open) 5435 continue; 5436 if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP)) --- 4 unchanged lines hidden (view full) --- 5441 needSep = XML_TRUE; 5442 } 5443 5444 if (!poolAppendChar(&tempPool, XML_T('\0'))) 5445 return NULL; 5446 return tempPool.start; 5447} 5448 |
4756static XML_Bool FASTCALL | 5449static XML_Bool |
4757setContext(XML_Parser parser, const XML_Char *context) 4758{ | 5450setContext(XML_Parser parser, const XML_Char *context) 5451{ |
5452 DTD * const dtd = _dtd; /* save one level of indirection */ |
|
4759 const XML_Char *s = context; 4760 4761 while (*context != XML_T('\0')) { 4762 if (*s == CONTEXT_SEP || *s == XML_T('\0')) { 4763 ENTITY *e; 4764 if (!poolAppendChar(&tempPool, XML_T('\0'))) 4765 return XML_FALSE; | 5453 const XML_Char *s = context; 5454 5455 while (*context != XML_T('\0')) { 5456 if (*s == CONTEXT_SEP || *s == XML_T('\0')) { 5457 ENTITY *e; 5458 if (!poolAppendChar(&tempPool, XML_T('\0'))) 5459 return XML_FALSE; |
4766 e = (ENTITY *)lookup(&dtd.generalEntities, poolStart(&tempPool), 0); | 5460 e = (ENTITY *)lookup(&dtd->generalEntities, poolStart(&tempPool), 0); |
4767 if (e) 4768 e->open = XML_TRUE; 4769 if (*s != XML_T('\0')) 4770 s++; 4771 context = s; 4772 poolDiscard(&tempPool); 4773 } | 5461 if (e) 5462 e->open = XML_TRUE; 5463 if (*s != XML_T('\0')) 5464 s++; 5465 context = s; 5466 poolDiscard(&tempPool); 5467 } |
4774 else if (*s == XML_T('=')) { | 5468 else if (*s == XML_T(ASCII_EQUALS)) { |
4775 PREFIX *prefix; 4776 if (poolLength(&tempPool) == 0) | 5469 PREFIX *prefix; 5470 if (poolLength(&tempPool) == 0) |
4777 prefix = &dtd.defaultPrefix; | 5471 prefix = &dtd->defaultPrefix; |
4778 else { 4779 if (!poolAppendChar(&tempPool, XML_T('\0'))) 4780 return XML_FALSE; | 5472 else { 5473 if (!poolAppendChar(&tempPool, XML_T('\0'))) 5474 return XML_FALSE; |
4781 prefix = (PREFIX *)lookup(&dtd.prefixes, poolStart(&tempPool), | 5475 prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&tempPool), |
4782 sizeof(PREFIX)); 4783 if (!prefix) 4784 return XML_FALSE; 4785 if (prefix->name == poolStart(&tempPool)) { | 5476 sizeof(PREFIX)); 5477 if (!prefix) 5478 return XML_FALSE; 5479 if (prefix->name == poolStart(&tempPool)) { |
4786 prefix->name = poolCopyString(&dtd.pool, prefix->name); | 5480 prefix->name = poolCopyString(&dtd->pool, prefix->name); |
4787 if (!prefix->name) 4788 return XML_FALSE; 4789 } 4790 poolDiscard(&tempPool); 4791 } 4792 for (context = s + 1; 4793 *context != CONTEXT_SEP && *context != XML_T('\0'); 4794 context++) 4795 if (!poolAppendChar(&tempPool, *context)) 4796 return XML_FALSE; 4797 if (!poolAppendChar(&tempPool, XML_T('\0'))) 4798 return XML_FALSE; | 5481 if (!prefix->name) 5482 return XML_FALSE; 5483 } 5484 poolDiscard(&tempPool); 5485 } 5486 for (context = s + 1; 5487 *context != CONTEXT_SEP && *context != XML_T('\0'); 5488 context++) 5489 if (!poolAppendChar(&tempPool, *context)) 5490 return XML_FALSE; 5491 if (!poolAppendChar(&tempPool, XML_T('\0'))) 5492 return XML_FALSE; |
4799 if (!addBinding(parser, prefix, 0, poolStart(&tempPool), 4800 &inheritedBindings)) | 5493 if (addBinding(parser, prefix, NULL, poolStart(&tempPool), 5494 &inheritedBindings) != XML_ERROR_NONE) |
4801 return XML_FALSE; 4802 poolDiscard(&tempPool); 4803 if (*context != XML_T('\0')) 4804 ++context; 4805 s = context; 4806 } 4807 else { 4808 if (!poolAppendChar(&tempPool, *s)) --- 21 unchanged lines hidden (view full) --- 4830 *p++ = *s; 4831 } 4832 } 4833 if (p != publicId && p[-1] == 0x20) 4834 --p; 4835 *p = XML_T('\0'); 4836} 4837 | 5495 return XML_FALSE; 5496 poolDiscard(&tempPool); 5497 if (*context != XML_T('\0')) 5498 ++context; 5499 s = context; 5500 } 5501 else { 5502 if (!poolAppendChar(&tempPool, *s)) --- 21 unchanged lines hidden (view full) --- 5524 *p++ = *s; 5525 } 5526 } 5527 if (p != publicId && p[-1] == 0x20) 5528 --p; 5529 *p = XML_T('\0'); 5530} 5531 |
4838static void FASTCALL 4839dtdInit(DTD *p, XML_Parser parser) | 5532static DTD * 5533dtdCreate(const XML_Memory_Handling_Suite *ms) |
4840{ | 5534{ |
4841 XML_Memory_Handling_Suite *ms = &parser->m_mem; | 5535 DTD *p = (DTD *)ms->malloc_fcn(sizeof(DTD)); 5536 if (p == NULL) 5537 return p; |
4842 poolInit(&(p->pool), ms); | 5538 poolInit(&(p->pool), ms); |
4843#ifdef XML_DTD | |
4844 poolInit(&(p->entityValuePool), ms); | 5539 poolInit(&(p->entityValuePool), ms); |
4845#endif /* XML_DTD */ | |
4846 hashTableInit(&(p->generalEntities), ms); 4847 hashTableInit(&(p->elementTypes), ms); 4848 hashTableInit(&(p->attributeIds), ms); 4849 hashTableInit(&(p->prefixes), ms); 4850#ifdef XML_DTD 4851 p->paramEntityRead = XML_FALSE; 4852 hashTableInit(&(p->paramEntities), ms); 4853#endif /* XML_DTD */ --- 6 unchanged lines hidden (view full) --- 4860 p->scaffLevel = 0; 4861 p->scaffSize = 0; 4862 p->scaffCount = 0; 4863 p->contentStringLen = 0; 4864 4865 p->keepProcessing = XML_TRUE; 4866 p->hasParamEntityRefs = XML_FALSE; 4867 p->standalone = XML_FALSE; | 5540 hashTableInit(&(p->generalEntities), ms); 5541 hashTableInit(&(p->elementTypes), ms); 5542 hashTableInit(&(p->attributeIds), ms); 5543 hashTableInit(&(p->prefixes), ms); 5544#ifdef XML_DTD 5545 p->paramEntityRead = XML_FALSE; 5546 hashTableInit(&(p->paramEntities), ms); 5547#endif /* XML_DTD */ --- 6 unchanged lines hidden (view full) --- 5554 p->scaffLevel = 0; 5555 p->scaffSize = 0; 5556 p->scaffCount = 0; 5557 p->contentStringLen = 0; 5558 5559 p->keepProcessing = XML_TRUE; 5560 p->hasParamEntityRefs = XML_FALSE; 5561 p->standalone = XML_FALSE; |
5562 return p; |
|
4868} 4869 | 5563} 5564 |
4870#ifdef XML_DTD 4871 4872static void FASTCALL 4873dtdSwap(DTD *p1, DTD *p2) | 5565static void 5566dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms) |
4874{ | 5567{ |
4875 DTD tem; 4876 memcpy(&tem, p1, sizeof(DTD)); 4877 memcpy(p1, p2, sizeof(DTD)); 4878 memcpy(p2, &tem, sizeof(DTD)); 4879} 4880 4881#endif /* XML_DTD */ 4882 4883static void FASTCALL 4884dtdReset(DTD *p, XML_Parser parser) 4885{ | |
4886 HASH_TABLE_ITER iter; 4887 hashTableIterInit(&iter, &(p->elementTypes)); 4888 for (;;) { 4889 ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter); 4890 if (!e) 4891 break; 4892 if (e->allocDefaultAtts != 0) | 5568 HASH_TABLE_ITER iter; 5569 hashTableIterInit(&iter, &(p->elementTypes)); 5570 for (;;) { 5571 ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter); 5572 if (!e) 5573 break; 5574 if (e->allocDefaultAtts != 0) |
4893 FREE(e->defaultAtts); | 5575 ms->free_fcn(e->defaultAtts); |
4894 } 4895 hashTableClear(&(p->generalEntities)); 4896#ifdef XML_DTD 4897 p->paramEntityRead = XML_FALSE; 4898 hashTableClear(&(p->paramEntities)); 4899#endif /* XML_DTD */ 4900 hashTableClear(&(p->elementTypes)); 4901 hashTableClear(&(p->attributeIds)); 4902 hashTableClear(&(p->prefixes)); 4903 poolClear(&(p->pool)); | 5576 } 5577 hashTableClear(&(p->generalEntities)); 5578#ifdef XML_DTD 5579 p->paramEntityRead = XML_FALSE; 5580 hashTableClear(&(p->paramEntities)); 5581#endif /* XML_DTD */ 5582 hashTableClear(&(p->elementTypes)); 5583 hashTableClear(&(p->attributeIds)); 5584 hashTableClear(&(p->prefixes)); 5585 poolClear(&(p->pool)); |
4904#ifdef XML_DTD | |
4905 poolClear(&(p->entityValuePool)); | 5586 poolClear(&(p->entityValuePool)); |
4906#endif /* XML_DTD */ | |
4907 p->defaultPrefix.name = NULL; 4908 p->defaultPrefix.binding = NULL; 4909 4910 p->in_eldecl = XML_FALSE; | 5587 p->defaultPrefix.name = NULL; 5588 p->defaultPrefix.binding = NULL; 5589 5590 p->in_eldecl = XML_FALSE; |
4911 if (p->scaffIndex) { 4912 FREE(p->scaffIndex); 4913 p->scaffIndex = NULL; 4914 } 4915 if (p->scaffold) { 4916 FREE(p->scaffold); 4917 p->scaffold = NULL; 4918 } | 5591 5592 ms->free_fcn(p->scaffIndex); 5593 p->scaffIndex = NULL; 5594 ms->free_fcn(p->scaffold); 5595 p->scaffold = NULL; 5596 |
4919 p->scaffLevel = 0; 4920 p->scaffSize = 0; 4921 p->scaffCount = 0; 4922 p->contentStringLen = 0; 4923 4924 p->keepProcessing = XML_TRUE; 4925 p->hasParamEntityRefs = XML_FALSE; 4926 p->standalone = XML_FALSE; 4927} 4928 | 5597 p->scaffLevel = 0; 5598 p->scaffSize = 0; 5599 p->scaffCount = 0; 5600 p->contentStringLen = 0; 5601 5602 p->keepProcessing = XML_TRUE; 5603 p->hasParamEntityRefs = XML_FALSE; 5604 p->standalone = XML_FALSE; 5605} 5606 |
4929static void FASTCALL 4930dtdDestroy(DTD *p, XML_Parser parser) | 5607static void 5608dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms) |
4931{ 4932 HASH_TABLE_ITER iter; 4933 hashTableIterInit(&iter, &(p->elementTypes)); 4934 for (;;) { 4935 ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter); 4936 if (!e) 4937 break; 4938 if (e->allocDefaultAtts != 0) | 5609{ 5610 HASH_TABLE_ITER iter; 5611 hashTableIterInit(&iter, &(p->elementTypes)); 5612 for (;;) { 5613 ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter); 5614 if (!e) 5615 break; 5616 if (e->allocDefaultAtts != 0) |
4939 FREE(e->defaultAtts); | 5617 ms->free_fcn(e->defaultAtts); |
4940 } 4941 hashTableDestroy(&(p->generalEntities)); 4942#ifdef XML_DTD 4943 hashTableDestroy(&(p->paramEntities)); 4944#endif /* XML_DTD */ 4945 hashTableDestroy(&(p->elementTypes)); 4946 hashTableDestroy(&(p->attributeIds)); 4947 hashTableDestroy(&(p->prefixes)); 4948 poolDestroy(&(p->pool)); | 5618 } 5619 hashTableDestroy(&(p->generalEntities)); 5620#ifdef XML_DTD 5621 hashTableDestroy(&(p->paramEntities)); 5622#endif /* XML_DTD */ 5623 hashTableDestroy(&(p->elementTypes)); 5624 hashTableDestroy(&(p->attributeIds)); 5625 hashTableDestroy(&(p->prefixes)); 5626 poolDestroy(&(p->pool)); |
4949#ifdef XML_DTD | |
4950 poolDestroy(&(p->entityValuePool)); | 5627 poolDestroy(&(p->entityValuePool)); |
4951#endif /* XML_DTD */ 4952 if (!parentParser) { 4953 if (p->scaffIndex) 4954 FREE(p->scaffIndex); 4955 if (p->scaffold) 4956 FREE(p->scaffold); | 5628 if (isDocEntity) { 5629 ms->free_fcn(p->scaffIndex); 5630 ms->free_fcn(p->scaffold); |
4957 } | 5631 } |
5632 ms->free_fcn(p); |
|
4958} 4959 | 5633} 5634 |
4960/* Do a deep copy of the DTD. Return 0 for out of memory; non-zero otherwise. | 5635/* Do a deep copy of the DTD. Return 0 for out of memory, non-zero otherwise. |
4961 The new DTD has already been initialized. 4962*/ | 5636 The new DTD has already been initialized. 5637*/ |
4963static int FASTCALL 4964dtdCopy(DTD *newDtd, const DTD *oldDtd, XML_Parser parser) | 5638static int 5639dtdCopy(DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms) |
4965{ 4966 HASH_TABLE_ITER iter; 4967 4968 /* Copy the prefix table. */ 4969 4970 hashTableIterInit(&iter, &(oldDtd->prefixes)); 4971 for (;;) { 4972 const XML_Char *name; --- 55 unchanged lines hidden (view full) --- 5028 if (!name) 5029 return 0; 5030 newE = (ELEMENT_TYPE *)lookup(&(newDtd->elementTypes), name, 5031 sizeof(ELEMENT_TYPE)); 5032 if (!newE) 5033 return 0; 5034 if (oldE->nDefaultAtts) { 5035 newE->defaultAtts = (DEFAULT_ATTRIBUTE *) | 5640{ 5641 HASH_TABLE_ITER iter; 5642 5643 /* Copy the prefix table. */ 5644 5645 hashTableIterInit(&iter, &(oldDtd->prefixes)); 5646 for (;;) { 5647 const XML_Char *name; --- 55 unchanged lines hidden (view full) --- 5703 if (!name) 5704 return 0; 5705 newE = (ELEMENT_TYPE *)lookup(&(newDtd->elementTypes), name, 5706 sizeof(ELEMENT_TYPE)); 5707 if (!newE) 5708 return 0; 5709 if (oldE->nDefaultAtts) { 5710 newE->defaultAtts = (DEFAULT_ATTRIBUTE *) |
5036 MALLOC(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); | 5711 ms->malloc_fcn(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); |
5037 if (!newE->defaultAtts) { | 5712 if (!newE->defaultAtts) { |
5038 FREE(newE); | 5713 ms->free_fcn(newE); |
5039 return 0; 5040 } 5041 } 5042 if (oldE->idAtt) 5043 newE->idAtt = (ATTRIBUTE_ID *) 5044 lookup(&(newDtd->attributeIds), oldE->idAtt->name, 0); 5045 newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts; 5046 if (oldE->prefix) --- 12 unchanged lines hidden (view full) --- 5059 else 5060 newE->defaultAtts[i].value = NULL; 5061 } 5062 } 5063 5064 /* Copy the entity tables. */ 5065 if (!copyEntityTable(&(newDtd->generalEntities), 5066 &(newDtd->pool), | 5714 return 0; 5715 } 5716 } 5717 if (oldE->idAtt) 5718 newE->idAtt = (ATTRIBUTE_ID *) 5719 lookup(&(newDtd->attributeIds), oldE->idAtt->name, 0); 5720 newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts; 5721 if (oldE->prefix) --- 12 unchanged lines hidden (view full) --- 5734 else 5735 newE->defaultAtts[i].value = NULL; 5736 } 5737 } 5738 5739 /* Copy the entity tables. */ 5740 if (!copyEntityTable(&(newDtd->generalEntities), 5741 &(newDtd->pool), |
5067 &(oldDtd->generalEntities), parser)) | 5742 &(oldDtd->generalEntities))) |
5068 return 0; 5069 5070#ifdef XML_DTD 5071 if (!copyEntityTable(&(newDtd->paramEntities), 5072 &(newDtd->pool), | 5743 return 0; 5744 5745#ifdef XML_DTD 5746 if (!copyEntityTable(&(newDtd->paramEntities), 5747 &(newDtd->pool), |
5073 &(oldDtd->paramEntities), parser)) | 5748 &(oldDtd->paramEntities))) |
5074 return 0; 5075 newDtd->paramEntityRead = oldDtd->paramEntityRead; 5076#endif /* XML_DTD */ 5077 5078 newDtd->keepProcessing = oldDtd->keepProcessing; 5079 newDtd->hasParamEntityRefs = oldDtd->hasParamEntityRefs; 5080 newDtd->standalone = oldDtd->standalone; 5081 5082 /* Don't want deep copying for scaffolding */ 5083 newDtd->in_eldecl = oldDtd->in_eldecl; 5084 newDtd->scaffold = oldDtd->scaffold; 5085 newDtd->contentStringLen = oldDtd->contentStringLen; 5086 newDtd->scaffSize = oldDtd->scaffSize; 5087 newDtd->scaffLevel = oldDtd->scaffLevel; 5088 newDtd->scaffIndex = oldDtd->scaffIndex; 5089 5090 return 1; 5091} /* End dtdCopy */ 5092 | 5749 return 0; 5750 newDtd->paramEntityRead = oldDtd->paramEntityRead; 5751#endif /* XML_DTD */ 5752 5753 newDtd->keepProcessing = oldDtd->keepProcessing; 5754 newDtd->hasParamEntityRefs = oldDtd->hasParamEntityRefs; 5755 newDtd->standalone = oldDtd->standalone; 5756 5757 /* Don't want deep copying for scaffolding */ 5758 newDtd->in_eldecl = oldDtd->in_eldecl; 5759 newDtd->scaffold = oldDtd->scaffold; 5760 newDtd->contentStringLen = oldDtd->contentStringLen; 5761 newDtd->scaffSize = oldDtd->scaffSize; 5762 newDtd->scaffLevel = oldDtd->scaffLevel; 5763 newDtd->scaffIndex = oldDtd->scaffIndex; 5764 5765 return 1; 5766} /* End dtdCopy */ 5767 |
5093static int FASTCALL | 5768static int |
5094copyEntityTable(HASH_TABLE *newTable, 5095 STRING_POOL *newPool, | 5769copyEntityTable(HASH_TABLE *newTable, 5770 STRING_POOL *newPool, |
5096 const HASH_TABLE *oldTable, 5097 XML_Parser parser) | 5771 const HASH_TABLE *oldTable) |
5098{ 5099 HASH_TABLE_ITER iter; 5100 const XML_Char *cachedOldBase = NULL; 5101 const XML_Char *cachedNewBase = NULL; 5102 5103 hashTableIterInit(&iter, oldTable); 5104 5105 for (;;) { --- 46 unchanged lines hidden (view full) --- 5152 newE->notation = tem; 5153 } 5154 newE->is_param = oldE->is_param; 5155 newE->is_internal = oldE->is_internal; 5156 } 5157 return 1; 5158} 5159 | 5772{ 5773 HASH_TABLE_ITER iter; 5774 const XML_Char *cachedOldBase = NULL; 5775 const XML_Char *cachedNewBase = NULL; 5776 5777 hashTableIterInit(&iter, oldTable); 5778 5779 for (;;) { --- 46 unchanged lines hidden (view full) --- 5826 newE->notation = tem; 5827 } 5828 newE->is_param = oldE->is_param; 5829 newE->is_internal = oldE->is_internal; 5830 } 5831 return 1; 5832} 5833 |
5160#define INIT_SIZE 64 | 5834#define INIT_POWER 6 |
5161 | 5835 |
5162static int FASTCALL | 5836static XML_Bool FASTCALL |
5163keyeq(KEY s1, KEY s2) 5164{ 5165 for (; *s1 == *s2; s1++, s2++) 5166 if (*s1 == 0) | 5837keyeq(KEY s1, KEY s2) 5838{ 5839 for (; *s1 == *s2; s1++, s2++) 5840 if (*s1 == 0) |
5167 return 1; 5168 return 0; | 5841 return XML_TRUE; 5842 return XML_FALSE; |
5169} 5170 5171static unsigned long FASTCALL 5172hash(KEY s) 5173{ 5174 unsigned long h = 0; 5175 while (*s) | 5843} 5844 5845static unsigned long FASTCALL 5846hash(KEY s) 5847{ 5848 unsigned long h = 0; 5849 while (*s) |
5176 h = (h << 5) + h + (unsigned char)*s++; | 5850 h = CHAR_HASH(h, *s++); |
5177 return h; 5178} 5179 | 5851 return h; 5852} 5853 |
5180static NAMED * FASTCALL | 5854static NAMED * |
5181lookup(HASH_TABLE *table, KEY name, size_t createSize) 5182{ 5183 size_t i; 5184 if (table->size == 0) { 5185 size_t tsize; | 5855lookup(HASH_TABLE *table, KEY name, size_t createSize) 5856{ 5857 size_t i; 5858 if (table->size == 0) { 5859 size_t tsize; |
5186 | |
5187 if (!createSize) 5188 return NULL; | 5860 if (!createSize) 5861 return NULL; |
5189 tsize = INIT_SIZE * sizeof(NAMED *); 5190 table->v = table->mem->malloc_fcn(tsize); 5191 if (!table->v) | 5862 table->power = INIT_POWER; 5863 /* table->size is a power of 2 */ 5864 table->size = (size_t)1 << INIT_POWER; 5865 tsize = table->size * sizeof(NAMED *); 5866 table->v = (NAMED **)table->mem->malloc_fcn(tsize); 5867 if (!table->v) { 5868 table->size = 0; |
5192 return NULL; | 5869 return NULL; |
5870 } |
|
5193 memset(table->v, 0, tsize); | 5871 memset(table->v, 0, tsize); |
5194 table->size = INIT_SIZE; 5195 table->usedLim = INIT_SIZE / 2; 5196 i = hash(name) & (table->size - 1); | 5872 i = hash(name) & ((unsigned long)table->size - 1); |
5197 } 5198 else { 5199 unsigned long h = hash(name); | 5873 } 5874 else { 5875 unsigned long h = hash(name); |
5200 for (i = h & (table->size - 1); 5201 table->v[i]; 5202 i == 0 ? i = table->size - 1 : --i) { | 5876 unsigned long mask = (unsigned long)table->size - 1; 5877 unsigned char step = 0; 5878 i = h & mask; 5879 while (table->v[i]) { |
5203 if (keyeq(name, table->v[i]->name)) 5204 return table->v[i]; | 5880 if (keyeq(name, table->v[i]->name)) 5881 return table->v[i]; |
5882 if (!step) 5883 step = PROBE_STEP(h, mask, table->power); 5884 i < step ? (i += table->size - step) : (i -= step); |
|
5205 } 5206 if (!createSize) 5207 return NULL; | 5885 } 5886 if (!createSize) 5887 return NULL; |
5208 if (table->used == table->usedLim) { 5209 /* check for overflow */ 5210 size_t newSize = table->size * 2; | 5888 5889 /* check for overflow (table is half full) */ 5890 if (table->used >> (table->power - 1)) { 5891 unsigned char newPower = table->power + 1; 5892 size_t newSize = (size_t)1 << newPower; 5893 unsigned long newMask = (unsigned long)newSize - 1; |
5211 size_t tsize = newSize * sizeof(NAMED *); | 5894 size_t tsize = newSize * sizeof(NAMED *); |
5212 NAMED **newV = table->mem->malloc_fcn(tsize); | 5895 NAMED **newV = (NAMED **)table->mem->malloc_fcn(tsize); |
5213 if (!newV) 5214 return NULL; 5215 memset(newV, 0, tsize); 5216 for (i = 0; i < table->size; i++) 5217 if (table->v[i]) { | 5896 if (!newV) 5897 return NULL; 5898 memset(newV, 0, tsize); 5899 for (i = 0; i < table->size; i++) 5900 if (table->v[i]) { |
5218 size_t j; 5219 for (j = hash(table->v[i]->name) & (newSize - 1); 5220 newV[j]; 5221 j == 0 ? j = newSize - 1 : --j) 5222 ; | 5901 unsigned long newHash = hash(table->v[i]->name); 5902 size_t j = newHash & newMask; 5903 step = 0; 5904 while (newV[j]) { 5905 if (!step) 5906 step = PROBE_STEP(newHash, newMask, newPower); 5907 j < step ? (j += newSize - step) : (j -= step); 5908 } |
5223 newV[j] = table->v[i]; 5224 } 5225 table->mem->free_fcn(table->v); 5226 table->v = newV; | 5909 newV[j] = table->v[i]; 5910 } 5911 table->mem->free_fcn(table->v); 5912 table->v = newV; |
5913 table->power = newPower; |
|
5227 table->size = newSize; | 5914 table->size = newSize; |
5228 table->usedLim = newSize/2; 5229 for (i = h & (table->size - 1); 5230 table->v[i]; 5231 i == 0 ? i = table->size - 1 : --i) 5232 ; | 5915 i = h & newMask; 5916 step = 0; 5917 while (table->v[i]) { 5918 if (!step) 5919 step = PROBE_STEP(h, newMask, newPower); 5920 i < step ? (i += newSize - step) : (i -= step); 5921 } |
5233 } 5234 } | 5922 } 5923 } |
5235 table->v[i] = table->mem->malloc_fcn(createSize); | 5924 table->v[i] = (NAMED *)table->mem->malloc_fcn(createSize); |
5236 if (!table->v[i]) 5237 return NULL; 5238 memset(table->v[i], 0, createSize); 5239 table->v[i]->name = name; 5240 (table->used)++; 5241 return table->v[i]; 5242} 5243 5244static void FASTCALL 5245hashTableClear(HASH_TABLE *table) 5246{ 5247 size_t i; 5248 for (i = 0; i < table->size; i++) { | 5925 if (!table->v[i]) 5926 return NULL; 5927 memset(table->v[i], 0, createSize); 5928 table->v[i]->name = name; 5929 (table->used)++; 5930 return table->v[i]; 5931} 5932 5933static void FASTCALL 5934hashTableClear(HASH_TABLE *table) 5935{ 5936 size_t i; 5937 for (i = 0; i < table->size; i++) { |
5249 NAMED *p = table->v[i]; 5250 if (p) { 5251 table->mem->free_fcn(p); 5252 table->v[i] = NULL; 5253 } | 5938 table->mem->free_fcn(table->v[i]); 5939 table->v[i] = NULL; |
5254 } | 5940 } |
5255 table->usedLim = table->size / 2; | |
5256 table->used = 0; 5257} 5258 5259static void FASTCALL 5260hashTableDestroy(HASH_TABLE *table) 5261{ 5262 size_t i; | 5941 table->used = 0; 5942} 5943 5944static void FASTCALL 5945hashTableDestroy(HASH_TABLE *table) 5946{ 5947 size_t i; |
5263 for (i = 0; i < table->size; i++) { 5264 NAMED *p = table->v[i]; 5265 if (p) 5266 table->mem->free_fcn(p); 5267 } 5268 if (table->v) 5269 table->mem->free_fcn(table->v); | 5948 for (i = 0; i < table->size; i++) 5949 table->mem->free_fcn(table->v[i]); 5950 table->mem->free_fcn(table->v); |
5270} 5271 5272static void FASTCALL | 5951} 5952 5953static void FASTCALL |
5273hashTableInit(HASH_TABLE *p, XML_Memory_Handling_Suite *ms) | 5954hashTableInit(HASH_TABLE *p, const XML_Memory_Handling_Suite *ms) |
5274{ | 5955{ |
5956 p->power = 0; |
|
5275 p->size = 0; | 5957 p->size = 0; |
5276 p->usedLim = 0; | |
5277 p->used = 0; 5278 p->v = NULL; 5279 p->mem = ms; 5280} 5281 5282static void FASTCALL 5283hashTableIterInit(HASH_TABLE_ITER *iter, const HASH_TABLE *table) 5284{ --- 8 unchanged lines hidden (view full) --- 5293 NAMED *tem = *(iter->p)++; 5294 if (tem) 5295 return tem; 5296 } 5297 return NULL; 5298} 5299 5300static void FASTCALL | 5958 p->used = 0; 5959 p->v = NULL; 5960 p->mem = ms; 5961} 5962 5963static void FASTCALL 5964hashTableIterInit(HASH_TABLE_ITER *iter, const HASH_TABLE *table) 5965{ --- 8 unchanged lines hidden (view full) --- 5974 NAMED *tem = *(iter->p)++; 5975 if (tem) 5976 return tem; 5977 } 5978 return NULL; 5979} 5980 5981static void FASTCALL |
5301poolInit(STRING_POOL *pool, XML_Memory_Handling_Suite *ms) | 5982poolInit(STRING_POOL *pool, const XML_Memory_Handling_Suite *ms) |
5302{ 5303 pool->blocks = NULL; 5304 pool->freeBlocks = NULL; 5305 pool->start = NULL; 5306 pool->ptr = NULL; 5307 pool->end = NULL; 5308 pool->mem = ms; 5309} --- 30 unchanged lines hidden (view full) --- 5340 p = pool->freeBlocks; 5341 while (p) { 5342 BLOCK *tem = p->next; 5343 pool->mem->free_fcn(p); 5344 p = tem; 5345 } 5346} 5347 | 5983{ 5984 pool->blocks = NULL; 5985 pool->freeBlocks = NULL; 5986 pool->start = NULL; 5987 pool->ptr = NULL; 5988 pool->end = NULL; 5989 pool->mem = ms; 5990} --- 30 unchanged lines hidden (view full) --- 6021 p = pool->freeBlocks; 6022 while (p) { 6023 BLOCK *tem = p->next; 6024 pool->mem->free_fcn(p); 6025 p = tem; 6026 } 6027} 6028 |
5348static XML_Char * FASTCALL | 6029static XML_Char * |
5349poolAppend(STRING_POOL *pool, const ENCODING *enc, 5350 const char *ptr, const char *end) 5351{ 5352 if (!pool->ptr && !poolGrow(pool)) 5353 return NULL; 5354 for (;;) { 5355 XmlConvert(enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end); 5356 if (ptr == end) --- 11 unchanged lines hidden (view full) --- 5368 if (!poolAppendChar(pool, *s)) 5369 return NULL; 5370 } while (*s++); 5371 s = pool->start; 5372 poolFinish(pool); 5373 return s; 5374} 5375 | 6030poolAppend(STRING_POOL *pool, const ENCODING *enc, 6031 const char *ptr, const char *end) 6032{ 6033 if (!pool->ptr && !poolGrow(pool)) 6034 return NULL; 6035 for (;;) { 6036 XmlConvert(enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end); 6037 if (ptr == end) --- 11 unchanged lines hidden (view full) --- 6049 if (!poolAppendChar(pool, *s)) 6050 return NULL; 6051 } while (*s++); 6052 s = pool->start; 6053 poolFinish(pool); 6054 return s; 6055} 6056 |
5376static const XML_Char * FASTCALL | 6057static const XML_Char * |
5377poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n) 5378{ 5379 if (!pool->ptr && !poolGrow(pool)) 5380 return NULL; 5381 for (; n > 0; --n, s++) { 5382 if (!poolAppendChar(pool, *s)) 5383 return NULL; 5384 } --- 8 unchanged lines hidden (view full) --- 5393 while (*s) { 5394 if (!poolAppendChar(pool, *s)) 5395 return NULL; 5396 s++; 5397 } 5398 return pool->start; 5399} 5400 | 6058poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n) 6059{ 6060 if (!pool->ptr && !poolGrow(pool)) 6061 return NULL; 6062 for (; n > 0; --n, s++) { 6063 if (!poolAppendChar(pool, *s)) 6064 return NULL; 6065 } --- 8 unchanged lines hidden (view full) --- 6074 while (*s) { 6075 if (!poolAppendChar(pool, *s)) 6076 return NULL; 6077 s++; 6078 } 6079 return pool->start; 6080} 6081 |
5401static XML_Char * FASTCALL | 6082static XML_Char * |
5402poolStoreString(STRING_POOL *pool, const ENCODING *enc, 5403 const char *ptr, const char *end) 5404{ 5405 if (!poolAppend(pool, enc, ptr, end)) 5406 return NULL; 5407 if (pool->ptr == pool->end && !poolGrow(pool)) 5408 return NULL; 5409 *(pool->ptr)++ = 0; --- 22 unchanged lines hidden (view full) --- 5432 (pool->end - pool->start) * sizeof(XML_Char)); 5433 pool->ptr = pool->blocks->s + (pool->ptr - pool->start); 5434 pool->start = pool->blocks->s; 5435 pool->end = pool->start + pool->blocks->size; 5436 return XML_TRUE; 5437 } 5438 } 5439 if (pool->blocks && pool->start == pool->blocks->s) { | 6083poolStoreString(STRING_POOL *pool, const ENCODING *enc, 6084 const char *ptr, const char *end) 6085{ 6086 if (!poolAppend(pool, enc, ptr, end)) 6087 return NULL; 6088 if (pool->ptr == pool->end && !poolGrow(pool)) 6089 return NULL; 6090 *(pool->ptr)++ = 0; --- 22 unchanged lines hidden (view full) --- 6113 (pool->end - pool->start) * sizeof(XML_Char)); 6114 pool->ptr = pool->blocks->s + (pool->ptr - pool->start); 6115 pool->start = pool->blocks->s; 6116 pool->end = pool->start + pool->blocks->size; 6117 return XML_TRUE; 6118 } 6119 } 6120 if (pool->blocks && pool->start == pool->blocks->s) { |
5440 int blockSize = (pool->end - pool->start)*2; 5441 pool->blocks = pool->mem->realloc_fcn(pool->blocks, 5442 offsetof(BLOCK, s) 5443 + blockSize * sizeof(XML_Char)); | 6121 int blockSize = (int)(pool->end - pool->start)*2; 6122 pool->blocks = (BLOCK *) 6123 pool->mem->realloc_fcn(pool->blocks, 6124 (offsetof(BLOCK, s) 6125 + blockSize * sizeof(XML_Char))); |
5444 if (pool->blocks == NULL) 5445 return XML_FALSE; 5446 pool->blocks->size = blockSize; 5447 pool->ptr = pool->blocks->s + (pool->ptr - pool->start); 5448 pool->start = pool->blocks->s; 5449 pool->end = pool->start + blockSize; 5450 } 5451 else { 5452 BLOCK *tem; | 6126 if (pool->blocks == NULL) 6127 return XML_FALSE; 6128 pool->blocks->size = blockSize; 6129 pool->ptr = pool->blocks->s + (pool->ptr - pool->start); 6130 pool->start = pool->blocks->s; 6131 pool->end = pool->start + blockSize; 6132 } 6133 else { 6134 BLOCK *tem; |
5453 int blockSize = pool->end - pool->start; | 6135 int blockSize = (int)(pool->end - pool->start); |
5454 if (blockSize < INIT_BLOCK_SIZE) 5455 blockSize = INIT_BLOCK_SIZE; 5456 else 5457 blockSize *= 2; | 6136 if (blockSize < INIT_BLOCK_SIZE) 6137 blockSize = INIT_BLOCK_SIZE; 6138 else 6139 blockSize *= 2; |
5458 tem = pool->mem->malloc_fcn(offsetof(BLOCK, s) 5459 + blockSize * sizeof(XML_Char)); | 6140 tem = (BLOCK *)pool->mem->malloc_fcn(offsetof(BLOCK, s) 6141 + blockSize * sizeof(XML_Char)); |
5460 if (!tem) 5461 return XML_FALSE; 5462 tem->size = blockSize; 5463 tem->next = pool->blocks; 5464 pool->blocks = tem; 5465 if (pool->ptr != pool->start) 5466 memcpy(tem->s, pool->start, 5467 (pool->ptr - pool->start) * sizeof(XML_Char)); 5468 pool->ptr = tem->s + (pool->ptr - pool->start); 5469 pool->start = tem->s; 5470 pool->end = tem->s + blockSize; 5471 } 5472 return XML_TRUE; 5473} 5474 5475static int FASTCALL 5476nextScaffoldPart(XML_Parser parser) 5477{ | 6142 if (!tem) 6143 return XML_FALSE; 6144 tem->size = blockSize; 6145 tem->next = pool->blocks; 6146 pool->blocks = tem; 6147 if (pool->ptr != pool->start) 6148 memcpy(tem->s, pool->start, 6149 (pool->ptr - pool->start) * sizeof(XML_Char)); 6150 pool->ptr = tem->s + (pool->ptr - pool->start); 6151 pool->start = tem->s; 6152 pool->end = tem->s + blockSize; 6153 } 6154 return XML_TRUE; 6155} 6156 6157static int FASTCALL 6158nextScaffoldPart(XML_Parser parser) 6159{ |
6160 DTD * const dtd = _dtd; /* save one level of indirection */ |
|
5478 CONTENT_SCAFFOLD * me; 5479 int next; 5480 | 6161 CONTENT_SCAFFOLD * me; 6162 int next; 6163 |
5481 if (!dtd.scaffIndex) { 5482 dtd.scaffIndex = MALLOC(groupSize * sizeof(int)); 5483 if (!dtd.scaffIndex) | 6164 if (!dtd->scaffIndex) { 6165 dtd->scaffIndex = (int *)MALLOC(groupSize * sizeof(int)); 6166 if (!dtd->scaffIndex) |
5484 return -1; | 6167 return -1; |
5485 dtd.scaffIndex[0] = 0; | 6168 dtd->scaffIndex[0] = 0; |
5486 } 5487 | 6169 } 6170 |
5488 if (dtd.scaffCount >= dtd.scaffSize) { | 6171 if (dtd->scaffCount >= dtd->scaffSize) { |
5489 CONTENT_SCAFFOLD *temp; | 6172 CONTENT_SCAFFOLD *temp; |
5490 if (dtd.scaffold) { | 6173 if (dtd->scaffold) { |
5491 temp = (CONTENT_SCAFFOLD *) | 6174 temp = (CONTENT_SCAFFOLD *) |
5492 REALLOC(dtd.scaffold, dtd.scaffSize * 2 * sizeof(CONTENT_SCAFFOLD)); | 6175 REALLOC(dtd->scaffold, dtd->scaffSize * 2 * sizeof(CONTENT_SCAFFOLD)); |
5493 if (temp == NULL) 5494 return -1; | 6176 if (temp == NULL) 6177 return -1; |
5495 dtd.scaffSize *= 2; | 6178 dtd->scaffSize *= 2; |
5496 } 5497 else { | 6179 } 6180 else { |
5498 temp = MALLOC(INIT_SCAFFOLD_ELEMENTS * sizeof(CONTENT_SCAFFOLD)); | 6181 temp = (CONTENT_SCAFFOLD *)MALLOC(INIT_SCAFFOLD_ELEMENTS 6182 * sizeof(CONTENT_SCAFFOLD)); |
5499 if (temp == NULL) 5500 return -1; | 6183 if (temp == NULL) 6184 return -1; |
5501 dtd.scaffSize = INIT_SCAFFOLD_ELEMENTS; | 6185 dtd->scaffSize = INIT_SCAFFOLD_ELEMENTS; |
5502 } | 6186 } |
5503 dtd.scaffold = temp; | 6187 dtd->scaffold = temp; |
5504 } | 6188 } |
5505 next = dtd.scaffCount++; 5506 me = &dtd.scaffold[next]; 5507 if (dtd.scaffLevel) { 5508 CONTENT_SCAFFOLD *parent = &dtd.scaffold[dtd.scaffIndex[dtd.scaffLevel-1]]; | 6189 next = dtd->scaffCount++; 6190 me = &dtd->scaffold[next]; 6191 if (dtd->scaffLevel) { 6192 CONTENT_SCAFFOLD *parent = &dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel-1]]; |
5509 if (parent->lastchild) { | 6193 if (parent->lastchild) { |
5510 dtd.scaffold[parent->lastchild].nextsib = next; | 6194 dtd->scaffold[parent->lastchild].nextsib = next; |
5511 } 5512 if (!parent->childcnt) 5513 parent->firstchild = next; 5514 parent->lastchild = next; 5515 parent->childcnt++; 5516 } 5517 me->firstchild = me->lastchild = me->childcnt = me->nextsib = 0; 5518 return next; 5519} 5520 | 6195 } 6196 if (!parent->childcnt) 6197 parent->firstchild = next; 6198 parent->lastchild = next; 6199 parent->childcnt++; 6200 } 6201 me->firstchild = me->lastchild = me->childcnt = me->nextsib = 0; 6202 return next; 6203} 6204 |
5521static void FASTCALL | 6205static void |
5522build_node(XML_Parser parser, 5523 int src_node, 5524 XML_Content *dest, 5525 XML_Content **contpos, 5526 XML_Char **strpos) 5527{ | 6206build_node(XML_Parser parser, 6207 int src_node, 6208 XML_Content *dest, 6209 XML_Content **contpos, 6210 XML_Char **strpos) 6211{ |
5528 dest->type = dtd.scaffold[src_node].type; 5529 dest->quant = dtd.scaffold[src_node].quant; | 6212 DTD * const dtd = _dtd; /* save one level of indirection */ 6213 dest->type = dtd->scaffold[src_node].type; 6214 dest->quant = dtd->scaffold[src_node].quant; |
5530 if (dest->type == XML_CTYPE_NAME) { 5531 const XML_Char *src; 5532 dest->name = *strpos; | 6215 if (dest->type == XML_CTYPE_NAME) { 6216 const XML_Char *src; 6217 dest->name = *strpos; |
5533 src = dtd.scaffold[src_node].name; | 6218 src = dtd->scaffold[src_node].name; |
5534 for (;;) { 5535 *(*strpos)++ = *src; 5536 if (!*src) 5537 break; 5538 src++; 5539 } 5540 dest->numchildren = 0; 5541 dest->children = NULL; 5542 } 5543 else { 5544 unsigned int i; 5545 int cn; | 6219 for (;;) { 6220 *(*strpos)++ = *src; 6221 if (!*src) 6222 break; 6223 src++; 6224 } 6225 dest->numchildren = 0; 6226 dest->children = NULL; 6227 } 6228 else { 6229 unsigned int i; 6230 int cn; |
5546 dest->numchildren = dtd.scaffold[src_node].childcnt; | 6231 dest->numchildren = dtd->scaffold[src_node].childcnt; |
5547 dest->children = *contpos; 5548 *contpos += dest->numchildren; | 6232 dest->children = *contpos; 6233 *contpos += dest->numchildren; |
5549 for (i = 0, cn = dtd.scaffold[src_node].firstchild; | 6234 for (i = 0, cn = dtd->scaffold[src_node].firstchild; |
5550 i < dest->numchildren; | 6235 i < dest->numchildren; |
5551 i++, cn = dtd.scaffold[cn].nextsib) { | 6236 i++, cn = dtd->scaffold[cn].nextsib) { |
5552 build_node(parser, cn, &(dest->children[i]), contpos, strpos); 5553 } 5554 dest->name = NULL; 5555 } 5556} 5557 | 6237 build_node(parser, cn, &(dest->children[i]), contpos, strpos); 6238 } 6239 dest->name = NULL; 6240 } 6241} 6242 |
5558static XML_Content * FASTCALL | 6243static XML_Content * |
5559build_model (XML_Parser parser) 5560{ | 6244build_model (XML_Parser parser) 6245{ |
6246 DTD * const dtd = _dtd; /* save one level of indirection */ |
|
5561 XML_Content *ret; 5562 XML_Content *cpos; 5563 XML_Char * str; | 6247 XML_Content *ret; 6248 XML_Content *cpos; 6249 XML_Char * str; |
5564 int allocsize = (dtd.scaffCount * sizeof(XML_Content) 5565 + (dtd.contentStringLen * sizeof(XML_Char))); | 6250 int allocsize = (dtd->scaffCount * sizeof(XML_Content) 6251 + (dtd->contentStringLen * sizeof(XML_Char))); |
5566 | 6252 |
5567 ret = MALLOC(allocsize); | 6253 ret = (XML_Content *)MALLOC(allocsize); |
5568 if (!ret) 5569 return NULL; 5570 | 6254 if (!ret) 6255 return NULL; 6256 |
5571 str = (XML_Char *) (&ret[dtd.scaffCount]); | 6257 str = (XML_Char *) (&ret[dtd->scaffCount]); |
5572 cpos = &ret[1]; 5573 5574 build_node(parser, 0, ret, &cpos, &str); 5575 return ret; 5576} 5577 | 6258 cpos = &ret[1]; 6259 6260 build_node(parser, 0, ret, &cpos, &str); 6261 return ret; 6262} 6263 |
5578static ELEMENT_TYPE * FASTCALL | 6264static ELEMENT_TYPE * |
5579getElementType(XML_Parser parser, 5580 const ENCODING *enc, 5581 const char *ptr, 5582 const char *end) 5583{ | 6265getElementType(XML_Parser parser, 6266 const ENCODING *enc, 6267 const char *ptr, 6268 const char *end) 6269{ |
5584 const XML_Char *name = poolStoreString(&dtd.pool, enc, ptr, end); | 6270 DTD * const dtd = _dtd; /* save one level of indirection */ 6271 const XML_Char *name = poolStoreString(&dtd->pool, enc, ptr, end); |
5585 ELEMENT_TYPE *ret; 5586 5587 if (!name) 5588 return NULL; | 6272 ELEMENT_TYPE *ret; 6273 6274 if (!name) 6275 return NULL; |
5589 ret = (ELEMENT_TYPE *) lookup(&dtd.elementTypes, name, sizeof(ELEMENT_TYPE)); | 6276 ret = (ELEMENT_TYPE *) lookup(&dtd->elementTypes, name, sizeof(ELEMENT_TYPE)); |
5590 if (!ret) 5591 return NULL; 5592 if (ret->name != name) | 6277 if (!ret) 6278 return NULL; 6279 if (ret->name != name) |
5593 poolDiscard(&dtd.pool); | 6280 poolDiscard(&dtd->pool); |
5594 else { | 6281 else { |
5595 poolFinish(&dtd.pool); | 6282 poolFinish(&dtd->pool); |
5596 if (!setElementTypePrefix(parser, ret)) 5597 return NULL; 5598 } 5599 return ret; 5600} | 6283 if (!setElementTypePrefix(parser, ret)) 6284 return NULL; 6285 } 6286 return ret; 6287} |