Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: third_party/expat/files/lib/xmlparse.c

Issue 68713003: Update libexpat to 2.1.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed commit message and Security Critical = no Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/expat/files/lib/expat_config.h ('k') | third_party/expat/files/lib/xmlrole.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd 1 /* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
2 See the file COPYING for copying permission. 2 See the file COPYING for copying permission.
3 */ 3 */
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <string.h> /* memset(), memcpy() */ 6 #include <string.h> /* memset(), memcpy() */
7 #include <assert.h> 7 #include <assert.h>
8 #include <limits.h> /* UINT_MAX */
9 #include <time.h> /* time() */
8 10
9 #define XML_BUILDING_EXPAT 1 11 #define XML_BUILDING_EXPAT 1
10 12
11 #ifdef COMPILED_FROM_DSP 13 #ifdef COMPILED_FROM_DSP
12 #include "winconfig.h" 14 #include "winconfig.h"
13 #elif defined(MACOS_CLASSIC) 15 #elif defined(MACOS_CLASSIC)
14 #include "macconfig.h" 16 #include "macconfig.h"
15 #elif defined(__amigaos4__) 17 #elif defined(__amigaos__)
16 #include "amigaconfig.h" 18 #include "amigaconfig.h"
17 #elif defined(__WATCOMC__) 19 #elif defined(__WATCOMC__)
18 #include "watcomconfig.h" 20 #include "watcomconfig.h"
19 #elif defined(HAVE_EXPAT_CONFIG_H) 21 #elif defined(HAVE_EXPAT_CONFIG_H)
20 #include <expat_config.h> 22 #include <expat_config.h>
21 #endif /* ndef COMPILED_FROM_DSP */ 23 #endif /* ndef COMPILED_FROM_DSP */
22 24
23 #include "ascii.h" 25 #include "ascii.h"
24 #include "expat.h" 26 #include "expat.h"
25 27
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 static Processor internalEntityProcessor; 322 static Processor internalEntityProcessor;
321 323
322 static enum XML_Error 324 static enum XML_Error
323 handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName); 325 handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName);
324 static enum XML_Error 326 static enum XML_Error
325 processXmlDecl(XML_Parser parser, int isGeneralTextEntity, 327 processXmlDecl(XML_Parser parser, int isGeneralTextEntity,
326 const char *s, const char *next); 328 const char *s, const char *next);
327 static enum XML_Error 329 static enum XML_Error
328 initializeEncoding(XML_Parser parser); 330 initializeEncoding(XML_Parser parser);
329 static enum XML_Error 331 static enum XML_Error
330 doProlog(XML_Parser parser, const ENCODING *enc, const char *s, 332 doProlog(XML_Parser parser, const ENCODING *enc, const char *s,
331 const char *end, int tok, const char *next, const char **nextPtr, 333 const char *end, int tok, const char *next, const char **nextPtr,
332 XML_Bool haveMore); 334 XML_Bool haveMore);
333 static enum XML_Error 335 static enum XML_Error
334 processInternalEntity(XML_Parser parser, ENTITY *entity, 336 processInternalEntity(XML_Parser parser, ENTITY *entity,
335 XML_Bool betweenDecl); 337 XML_Bool betweenDecl);
336 static enum XML_Error 338 static enum XML_Error
337 doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, 339 doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc,
338 const char *start, const char *end, const char **endPtr, 340 const char *start, const char *end, const char **endPtr,
339 XML_Bool haveMore); 341 XML_Bool haveMore);
340 static enum XML_Error 342 static enum XML_Error
341 doCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr, 343 doCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr,
342 const char *end, const char **nextPtr, XML_Bool haveMore); 344 const char *end, const char **nextPtr, XML_Bool haveMore);
343 #ifdef XML_DTD 345 #ifdef XML_DTD
344 static enum XML_Error 346 static enum XML_Error
345 doIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr, 347 doIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr,
346 const char *end, const char **nextPtr, XML_Bool haveMore); 348 const char *end, const char **nextPtr, XML_Bool haveMore);
347 #endif /* XML_DTD */ 349 #endif /* XML_DTD */
348 350
349 static enum XML_Error 351 static enum XML_Error
350 storeAtts(XML_Parser parser, const ENCODING *, const char *s, 352 storeAtts(XML_Parser parser, const ENCODING *, const char *s,
351 TAG_NAME *tagNamePtr, BINDING **bindingsPtr); 353 TAG_NAME *tagNamePtr, BINDING **bindingsPtr);
352 static enum XML_Error 354 static enum XML_Error
353 addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, 355 addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId,
354 const XML_Char *uri, BINDING **bindingsPtr); 356 const XML_Char *uri, BINDING **bindingsPtr);
355 static int 357 static int
356 defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *, XML_Bool isCdata, 358 defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *, XML_Bool isCdata,
357 XML_Bool isId, const XML_Char *dfltValue, XML_Parser parser); 359 XML_Bool isId, const XML_Char *dfltValue, XML_Parser parser);
358 static enum XML_Error 360 static enum XML_Error
359 storeAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, 361 storeAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata,
360 const char *, const char *, STRING_POOL *); 362 const char *, const char *, STRING_POOL *);
361 static enum XML_Error 363 static enum XML_Error
362 appendAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, 364 appendAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata,
363 const char *, const char *, STRING_POOL *); 365 const char *, const char *, STRING_POOL *);
364 static ATTRIBUTE_ID * 366 static ATTRIBUTE_ID *
365 getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start, 367 getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start,
366 const char *end); 368 const char *end);
(...skipping 17 matching lines...) Expand all
384 setContext(XML_Parser parser, const XML_Char *context); 386 setContext(XML_Parser parser, const XML_Char *context);
385 387
386 static void FASTCALL normalizePublicId(XML_Char *s); 388 static void FASTCALL normalizePublicId(XML_Char *s);
387 389
388 static DTD * dtdCreate(const XML_Memory_Handling_Suite *ms); 390 static DTD * dtdCreate(const XML_Memory_Handling_Suite *ms);
389 /* do not call if parentParser != NULL */ 391 /* do not call if parentParser != NULL */
390 static void dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms); 392 static void dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms);
391 static void 393 static void
392 dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms); 394 dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms);
393 static int 395 static int
394 dtdCopy(DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms); 396 dtdCopy(XML_Parser oldParser,
397 DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms);
395 static int 398 static int
396 copyEntityTable(HASH_TABLE *, STRING_POOL *, const HASH_TABLE *); 399 copyEntityTable(XML_Parser oldParser,
397 400 HASH_TABLE *, STRING_POOL *, const HASH_TABLE *);
398 static NAMED * 401 static NAMED *
399 lookup(HASH_TABLE *table, KEY name, size_t createSize); 402 lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize);
400 static void FASTCALL 403 static void FASTCALL
401 hashTableInit(HASH_TABLE *, const XML_Memory_Handling_Suite *ms); 404 hashTableInit(HASH_TABLE *, const XML_Memory_Handling_Suite *ms);
402 static void FASTCALL hashTableClear(HASH_TABLE *); 405 static void FASTCALL hashTableClear(HASH_TABLE *);
403 static void FASTCALL hashTableDestroy(HASH_TABLE *); 406 static void FASTCALL hashTableDestroy(HASH_TABLE *);
404 static void FASTCALL 407 static void FASTCALL
405 hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *); 408 hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *);
406 static NAMED * FASTCALL hashTableIterNext(HASH_TABLE_ITER *); 409 static NAMED * FASTCALL hashTableIterNext(HASH_TABLE_ITER *);
407 410
408 static void FASTCALL 411 static void FASTCALL
409 poolInit(STRING_POOL *, const XML_Memory_Handling_Suite *ms); 412 poolInit(STRING_POOL *, const XML_Memory_Handling_Suite *ms);
(...skipping 12 matching lines...) Expand all
422 poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n); 425 poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n);
423 static const XML_Char * FASTCALL 426 static const XML_Char * FASTCALL
424 poolAppendString(STRING_POOL *pool, const XML_Char *s); 427 poolAppendString(STRING_POOL *pool, const XML_Char *s);
425 428
426 static int FASTCALL nextScaffoldPart(XML_Parser parser); 429 static int FASTCALL nextScaffoldPart(XML_Parser parser);
427 static XML_Content * build_model(XML_Parser parser); 430 static XML_Content * build_model(XML_Parser parser);
428 static ELEMENT_TYPE * 431 static ELEMENT_TYPE *
429 getElementType(XML_Parser parser, const ENCODING *enc, 432 getElementType(XML_Parser parser, const ENCODING *enc,
430 const char *ptr, const char *end); 433 const char *ptr, const char *end);
431 434
435 static unsigned long generate_hash_secret_salt(void);
436 static XML_Bool startParsing(XML_Parser parser);
437
432 static XML_Parser 438 static XML_Parser
433 parserCreate(const XML_Char *encodingName, 439 parserCreate(const XML_Char *encodingName,
434 const XML_Memory_Handling_Suite *memsuite, 440 const XML_Memory_Handling_Suite *memsuite,
435 const XML_Char *nameSep, 441 const XML_Char *nameSep,
436 DTD *dtd); 442 DTD *dtd);
443
437 static void 444 static void
438 parserInit(XML_Parser parser, const XML_Char *encodingName); 445 parserInit(XML_Parser parser, const XML_Char *encodingName);
439 446
440 #define poolStart(pool) ((pool)->start) 447 #define poolStart(pool) ((pool)->start)
441 #define poolEnd(pool) ((pool)->ptr) 448 #define poolEnd(pool) ((pool)->ptr)
442 #define poolLength(pool) ((pool)->ptr - (pool)->start) 449 #define poolLength(pool) ((pool)->ptr - (pool)->start)
443 #define poolChop(pool) ((void)--(pool->ptr)) 450 #define poolChop(pool) ((void)--(pool->ptr))
444 #define poolLastChar(pool) (((pool)->ptr)[-1]) 451 #define poolLastChar(pool) (((pool)->ptr)[-1])
445 #define poolDiscard(pool) ((pool)->ptr = (pool)->start) 452 #define poolDiscard(pool) ((pool)->ptr = (pool)->start)
446 #define poolFinish(pool) ((pool)->start = (pool)->ptr) 453 #define poolFinish(pool) ((pool)->start = (pool)->ptr)
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 TAG *m_freeTagList; 533 TAG *m_freeTagList;
527 BINDING *m_inheritedBindings; 534 BINDING *m_inheritedBindings;
528 BINDING *m_freeBindingList; 535 BINDING *m_freeBindingList;
529 int m_attsSize; 536 int m_attsSize;
530 int m_nSpecifiedAtts; 537 int m_nSpecifiedAtts;
531 int m_idAttIndex; 538 int m_idAttIndex;
532 ATTRIBUTE *m_atts; 539 ATTRIBUTE *m_atts;
533 NS_ATT *m_nsAtts; 540 NS_ATT *m_nsAtts;
534 unsigned long m_nsAttsVersion; 541 unsigned long m_nsAttsVersion;
535 unsigned char m_nsAttsPower; 542 unsigned char m_nsAttsPower;
543 #ifdef XML_ATTR_INFO
544 XML_AttrInfo *m_attInfo;
545 #endif
536 POSITION m_position; 546 POSITION m_position;
537 STRING_POOL m_tempPool; 547 STRING_POOL m_tempPool;
538 STRING_POOL m_temp2Pool; 548 STRING_POOL m_temp2Pool;
539 char *m_groupConnector; 549 char *m_groupConnector;
540 unsigned int m_groupSize; 550 unsigned int m_groupSize;
541 XML_Char m_namespaceSeparator; 551 XML_Char m_namespaceSeparator;
542 XML_Parser m_parentParser; 552 XML_Parser m_parentParser;
543 XML_ParsingStatus m_parsingStatus; 553 XML_ParsingStatus m_parsingStatus;
544 #ifdef XML_DTD 554 #ifdef XML_DTD
545 XML_Bool m_isParamEntity; 555 XML_Bool m_isParamEntity;
546 XML_Bool m_useForeignDTD; 556 XML_Bool m_useForeignDTD;
547 enum XML_ParamEntityParsing m_paramEntityParsing; 557 enum XML_ParamEntityParsing m_paramEntityParsing;
548 #endif 558 #endif
559 unsigned long m_hash_secret_salt;
549 }; 560 };
550 561
551 #define MALLOC(s) (parser->m_mem.malloc_fcn((s))) 562 #define MALLOC(s) (parser->m_mem.malloc_fcn((s)))
552 #define REALLOC(p,s) (parser->m_mem.realloc_fcn((p),(s))) 563 #define REALLOC(p,s) (parser->m_mem.realloc_fcn((p),(s)))
553 #define FREE(p) (parser->m_mem.free_fcn((p))) 564 #define FREE(p) (parser->m_mem.free_fcn((p)))
554 565
555 #define userData (parser->m_userData) 566 #define userData (parser->m_userData)
556 #define handlerArg (parser->m_handlerArg) 567 #define handlerArg (parser->m_handlerArg)
557 #define startElementHandler (parser->m_startElementHandler) 568 #define startElementHandler (parser->m_startElementHandler)
558 #define endElementHandler (parser->m_endElementHandler) 569 #define endElementHandler (parser->m_endElementHandler)
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 #define freeBindingList (parser->m_freeBindingList) 644 #define freeBindingList (parser->m_freeBindingList)
634 #define inheritedBindings (parser->m_inheritedBindings) 645 #define inheritedBindings (parser->m_inheritedBindings)
635 #define tagStack (parser->m_tagStack) 646 #define tagStack (parser->m_tagStack)
636 #define atts (parser->m_atts) 647 #define atts (parser->m_atts)
637 #define attsSize (parser->m_attsSize) 648 #define attsSize (parser->m_attsSize)
638 #define nSpecifiedAtts (parser->m_nSpecifiedAtts) 649 #define nSpecifiedAtts (parser->m_nSpecifiedAtts)
639 #define idAttIndex (parser->m_idAttIndex) 650 #define idAttIndex (parser->m_idAttIndex)
640 #define nsAtts (parser->m_nsAtts) 651 #define nsAtts (parser->m_nsAtts)
641 #define nsAttsVersion (parser->m_nsAttsVersion) 652 #define nsAttsVersion (parser->m_nsAttsVersion)
642 #define nsAttsPower (parser->m_nsAttsPower) 653 #define nsAttsPower (parser->m_nsAttsPower)
654 #define attInfo (parser->m_attInfo)
643 #define tempPool (parser->m_tempPool) 655 #define tempPool (parser->m_tempPool)
644 #define temp2Pool (parser->m_temp2Pool) 656 #define temp2Pool (parser->m_temp2Pool)
645 #define groupConnector (parser->m_groupConnector) 657 #define groupConnector (parser->m_groupConnector)
646 #define groupSize (parser->m_groupSize) 658 #define groupSize (parser->m_groupSize)
647 #define namespaceSeparator (parser->m_namespaceSeparator) 659 #define namespaceSeparator (parser->m_namespaceSeparator)
648 #define parentParser (parser->m_parentParser) 660 #define parentParser (parser->m_parentParser)
649 #define ps_parsing (parser->m_parsingStatus.parsing) 661 #define ps_parsing (parser->m_parsingStatus.parsing)
650 #define ps_finalBuffer (parser->m_parsingStatus.finalBuffer) 662 #define ps_finalBuffer (parser->m_parsingStatus.finalBuffer)
651 #ifdef XML_DTD 663 #ifdef XML_DTD
652 #define isParamEntity (parser->m_isParamEntity) 664 #define isParamEntity (parser->m_isParamEntity)
653 #define useForeignDTD (parser->m_useForeignDTD) 665 #define useForeignDTD (parser->m_useForeignDTD)
654 #define paramEntityParsing (parser->m_paramEntityParsing) 666 #define paramEntityParsing (parser->m_paramEntityParsing)
655 #endif /* XML_DTD */ 667 #endif /* XML_DTD */
668 #define hash_secret_salt (parser->m_hash_secret_salt)
656 669
657 XML_Parser XMLCALL 670 XML_Parser XMLCALL
658 XML_ParserCreate(const XML_Char *encodingName) 671 XML_ParserCreate(const XML_Char *encodingName)
659 { 672 {
660 return XML_ParserCreate_MM(encodingName, NULL, NULL); 673 return XML_ParserCreate_MM(encodingName, NULL, NULL);
661 } 674 }
662 675
663 XML_Parser XMLCALL 676 XML_Parser XMLCALL
664 XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep) 677 XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep)
665 { 678 {
666 XML_Char tmp[2]; 679 XML_Char tmp[2];
667 *tmp = nsSep; 680 *tmp = nsSep;
668 return XML_ParserCreate_MM(encodingName, NULL, tmp); 681 return XML_ParserCreate_MM(encodingName, NULL, tmp);
669 } 682 }
670 683
671 static const XML_Char implicitContext[] = { 684 static const XML_Char implicitContext[] = {
672 ASCII_x, ASCII_m, ASCII_l, ASCII_EQUALS, ASCII_h, ASCII_t, ASCII_t, ASCII_p, 685 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, 686 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, 687 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, 688 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, 689 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' 690 ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, '\0'
678 }; 691 };
679 692
693 static unsigned long
694 generate_hash_secret_salt(void)
695 {
696 unsigned int seed = time(NULL) % UINT_MAX;
697 srand(seed);
698 return rand();
699 }
700
701 static XML_Bool /* only valid for root parser */
702 startParsing(XML_Parser parser)
703 {
704 /* hash functions must be initialized before setContext() is called */
705 if (hash_secret_salt == 0)
706 hash_secret_salt = generate_hash_secret_salt();
707 if (ns) {
708 /* implicit context only set for root parser, since child
709 parsers (i.e. external entity parsers) will inherit it
710 */
711 return setContext(parser, implicitContext);
712 }
713 return XML_TRUE;
714 }
715
680 XML_Parser XMLCALL 716 XML_Parser XMLCALL
681 XML_ParserCreate_MM(const XML_Char *encodingName, 717 XML_ParserCreate_MM(const XML_Char *encodingName,
682 const XML_Memory_Handling_Suite *memsuite, 718 const XML_Memory_Handling_Suite *memsuite,
683 const XML_Char *nameSep) 719 const XML_Char *nameSep)
684 { 720 {
685 XML_Parser parser = parserCreate(encodingName, memsuite, nameSep, NULL); 721 return 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 } 722 }
697 723
698 static XML_Parser 724 static XML_Parser
699 parserCreate(const XML_Char *encodingName, 725 parserCreate(const XML_Char *encodingName,
700 const XML_Memory_Handling_Suite *memsuite, 726 const XML_Memory_Handling_Suite *memsuite,
701 const XML_Char *nameSep, 727 const XML_Char *nameSep,
702 DTD *dtd) 728 DTD *dtd)
703 { 729 {
704 XML_Parser parser; 730 XML_Parser parser;
705 731
(...skipping 24 matching lines...) Expand all
730 756
731 buffer = NULL; 757 buffer = NULL;
732 bufferLim = NULL; 758 bufferLim = NULL;
733 759
734 attsSize = INIT_ATTS_SIZE; 760 attsSize = INIT_ATTS_SIZE;
735 atts = (ATTRIBUTE *)MALLOC(attsSize * sizeof(ATTRIBUTE)); 761 atts = (ATTRIBUTE *)MALLOC(attsSize * sizeof(ATTRIBUTE));
736 if (atts == NULL) { 762 if (atts == NULL) {
737 FREE(parser); 763 FREE(parser);
738 return NULL; 764 return NULL;
739 } 765 }
740 dataBuf = (XML_Char *)MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char)); 766 #ifdef XML_ATTR_INFO
741 if (dataBuf == NULL) { 767 attInfo = (XML_AttrInfo*)MALLOC(attsSize * sizeof(XML_AttrInfo));
768 if (attInfo == NULL) {
742 FREE(atts); 769 FREE(atts);
743 FREE(parser); 770 FREE(parser);
744 return NULL; 771 return NULL;
745 } 772 }
773 #endif
774 dataBuf = (XML_Char *)MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char));
775 if (dataBuf == NULL) {
776 FREE(atts);
777 #ifdef XML_ATTR_INFO
778 FREE(attInfo);
779 #endif
780 FREE(parser);
781 return NULL;
782 }
746 dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE; 783 dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE;
747 784
748 if (dtd) 785 if (dtd)
749 _dtd = dtd; 786 _dtd = dtd;
750 else { 787 else {
751 _dtd = dtdCreate(&parser->m_mem); 788 _dtd = dtdCreate(&parser->m_mem);
752 if (_dtd == NULL) { 789 if (_dtd == NULL) {
753 FREE(dataBuf); 790 FREE(dataBuf);
754 FREE(atts); 791 FREE(atts);
792 #ifdef XML_ATTR_INFO
793 FREE(attInfo);
794 #endif
755 FREE(parser); 795 FREE(parser);
756 return NULL; 796 return NULL;
757 } 797 }
758 } 798 }
759 799
760 freeBindingList = NULL; 800 freeBindingList = NULL;
761 freeTagList = NULL; 801 freeTagList = NULL;
762 freeInternalEntities = NULL; 802 freeInternalEntities = NULL;
763 803
764 groupSize = 0; 804 groupSize = 0;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 unknownEncodingMem = NULL; 899 unknownEncodingMem = NULL;
860 unknownEncodingRelease = NULL; 900 unknownEncodingRelease = NULL;
861 unknownEncodingData = NULL; 901 unknownEncodingData = NULL;
862 parentParser = NULL; 902 parentParser = NULL;
863 ps_parsing = XML_INITIALIZED; 903 ps_parsing = XML_INITIALIZED;
864 #ifdef XML_DTD 904 #ifdef XML_DTD
865 isParamEntity = XML_FALSE; 905 isParamEntity = XML_FALSE;
866 useForeignDTD = XML_FALSE; 906 useForeignDTD = XML_FALSE;
867 paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; 907 paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER;
868 #endif 908 #endif
909 hash_secret_salt = 0;
869 } 910 }
870 911
871 /* moves list of bindings to freeBindingList */ 912 /* moves list of bindings to freeBindingList */
872 static void FASTCALL 913 static void FASTCALL
873 moveToFreeBindingList(XML_Parser parser, BINDING *bindings) 914 moveToFreeBindingList(XML_Parser parser, BINDING *bindings)
874 { 915 {
875 while (bindings) { 916 while (bindings) {
876 BINDING *b = bindings; 917 BINDING *b = bindings;
877 bindings = bindings->nextTagBinding; 918 bindings = bindings->nextTagBinding;
878 b->nextTagBinding = freeBindingList; 919 b->nextTagBinding = freeBindingList;
(...skipping 27 matching lines...) Expand all
906 freeInternalEntities = openEntity; 947 freeInternalEntities = openEntity;
907 } 948 }
908 moveToFreeBindingList(parser, inheritedBindings); 949 moveToFreeBindingList(parser, inheritedBindings);
909 FREE(unknownEncodingMem); 950 FREE(unknownEncodingMem);
910 if (unknownEncodingRelease) 951 if (unknownEncodingRelease)
911 unknownEncodingRelease(unknownEncodingData); 952 unknownEncodingRelease(unknownEncodingData);
912 poolClear(&tempPool); 953 poolClear(&tempPool);
913 poolClear(&temp2Pool); 954 poolClear(&temp2Pool);
914 parserInit(parser, encodingName); 955 parserInit(parser, encodingName);
915 dtdReset(_dtd, &parser->m_mem); 956 dtdReset(_dtd, &parser->m_mem);
916 return setContext(parser, implicitContext); 957 return XML_TRUE;
917 } 958 }
918 959
919 enum XML_Status XMLCALL 960 enum XML_Status XMLCALL
920 XML_SetEncoding(XML_Parser parser, const XML_Char *encodingName) 961 XML_SetEncoding(XML_Parser parser, const XML_Char *encodingName)
921 { 962 {
922 /* Block after XML_Parse()/XML_ParseBuffer() has been called. 963 /* Block after XML_Parse()/XML_ParseBuffer() has been called.
923 XXX There's no way for the caller to determine which of the 964 XXX There's no way for the caller to determine which of the
924 XXX possible error cases caused the XML_STATUS_ERROR return. 965 XXX possible error cases caused the XML_STATUS_ERROR return.
925 */ 966 */
926 if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) 967 if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 1016
976 void *oldUserData = userData; 1017 void *oldUserData = userData;
977 void *oldHandlerArg = handlerArg; 1018 void *oldHandlerArg = handlerArg;
978 XML_Bool oldDefaultExpandInternalEntities = defaultExpandInternalEntities; 1019 XML_Bool oldDefaultExpandInternalEntities = defaultExpandInternalEntities;
979 XML_Parser oldExternalEntityRefHandlerArg = externalEntityRefHandlerArg; 1020 XML_Parser oldExternalEntityRefHandlerArg = externalEntityRefHandlerArg;
980 #ifdef XML_DTD 1021 #ifdef XML_DTD
981 enum XML_ParamEntityParsing oldParamEntityParsing = paramEntityParsing; 1022 enum XML_ParamEntityParsing oldParamEntityParsing = paramEntityParsing;
982 int oldInEntityValue = prologState.inEntityValue; 1023 int oldInEntityValue = prologState.inEntityValue;
983 #endif 1024 #endif
984 XML_Bool oldns_triplets = ns_triplets; 1025 XML_Bool oldns_triplets = ns_triplets;
1026 /* Note that the new parser shares the same hash secret as the old
1027 parser, so that dtdCopy and copyEntityTable can lookup values
1028 from hash tables associated with either parser without us having
1029 to worry which hash secrets each table has.
1030 */
1031 unsigned long oldhash_secret_salt = hash_secret_salt;
985 1032
986 #ifdef XML_DTD 1033 #ifdef XML_DTD
987 if (!context) 1034 if (!context)
988 newDtd = oldDtd; 1035 newDtd = oldDtd;
989 #endif /* XML_DTD */ 1036 #endif /* XML_DTD */
990 1037
991 /* Note that the magical uses of the pre-processor to make field 1038 /* Note that the magical uses of the pre-processor to make field
992 access look more like C++ require that `parser' be overwritten 1039 access look more like C++ require that `parser' be overwritten
993 here. This makes this function more painful to follow than it 1040 here. This makes this function more painful to follow than it
994 would be otherwise. 1041 would be otherwise.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 declElementType = oldDeclElementType; 1075 declElementType = oldDeclElementType;
1029 userData = oldUserData; 1076 userData = oldUserData;
1030 if (oldUserData == oldHandlerArg) 1077 if (oldUserData == oldHandlerArg)
1031 handlerArg = userData; 1078 handlerArg = userData;
1032 else 1079 else
1033 handlerArg = parser; 1080 handlerArg = parser;
1034 if (oldExternalEntityRefHandlerArg != oldParser) 1081 if (oldExternalEntityRefHandlerArg != oldParser)
1035 externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg; 1082 externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg;
1036 defaultExpandInternalEntities = oldDefaultExpandInternalEntities; 1083 defaultExpandInternalEntities = oldDefaultExpandInternalEntities;
1037 ns_triplets = oldns_triplets; 1084 ns_triplets = oldns_triplets;
1085 hash_secret_salt = oldhash_secret_salt;
1038 parentParser = oldParser; 1086 parentParser = oldParser;
1039 #ifdef XML_DTD 1087 #ifdef XML_DTD
1040 paramEntityParsing = oldParamEntityParsing; 1088 paramEntityParsing = oldParamEntityParsing;
1041 prologState.inEntityValue = oldInEntityValue; 1089 prologState.inEntityValue = oldInEntityValue;
1042 if (context) { 1090 if (context) {
1043 #endif /* XML_DTD */ 1091 #endif /* XML_DTD */
1044 if (!dtdCopy(_dtd, oldDtd, &parser->m_mem) 1092 if (!dtdCopy(oldParser, _dtd, oldDtd, &parser->m_mem)
1045 || !setContext(parser, context)) { 1093 || !setContext(parser, context)) {
1046 XML_ParserFree(parser); 1094 XML_ParserFree(parser);
1047 return NULL; 1095 return NULL;
1048 } 1096 }
1049 processor = externalEntityInitProcessor; 1097 processor = externalEntityInitProcessor;
1050 #ifdef XML_DTD 1098 #ifdef XML_DTD
1051 } 1099 }
1052 else { 1100 else {
1053 /* The DTD instance referenced by _dtd is shared between the document's 1101 /* 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 1102 root parser and external PE parsers, therefore one does not need to
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 #ifdef XML_DTD 1171 #ifdef XML_DTD
1124 /* external parameter entity parsers share the DTD structure 1172 /* external parameter entity parsers share the DTD structure
1125 parser->m_dtd with the root parser, so we must not destroy it 1173 parser->m_dtd with the root parser, so we must not destroy it
1126 */ 1174 */
1127 if (!isParamEntity && _dtd) 1175 if (!isParamEntity && _dtd)
1128 #else 1176 #else
1129 if (_dtd) 1177 if (_dtd)
1130 #endif /* XML_DTD */ 1178 #endif /* XML_DTD */
1131 dtdDestroy(_dtd, (XML_Bool)!parentParser, &parser->m_mem); 1179 dtdDestroy(_dtd, (XML_Bool)!parentParser, &parser->m_mem);
1132 FREE((void *)atts); 1180 FREE((void *)atts);
1181 #ifdef XML_ATTR_INFO
1182 FREE((void *)attInfo);
1183 #endif
1133 FREE(groupConnector); 1184 FREE(groupConnector);
1134 FREE(buffer); 1185 FREE(buffer);
1135 FREE(dataBuf); 1186 FREE(dataBuf);
1136 FREE(nsAtts); 1187 FREE(nsAtts);
1137 FREE(unknownEncodingMem); 1188 FREE(unknownEncodingMem);
1138 if (unknownEncodingRelease) 1189 if (unknownEncodingRelease)
1139 unknownEncodingRelease(unknownEncodingData); 1190 unknownEncodingRelease(unknownEncodingData);
1140 FREE(parser); 1191 FREE(parser);
1141 } 1192 }
1142 1193
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 { 1254 {
1204 return nSpecifiedAtts; 1255 return nSpecifiedAtts;
1205 } 1256 }
1206 1257
1207 int XMLCALL 1258 int XMLCALL
1208 XML_GetIdAttributeIndex(XML_Parser parser) 1259 XML_GetIdAttributeIndex(XML_Parser parser)
1209 { 1260 {
1210 return idAttIndex; 1261 return idAttIndex;
1211 } 1262 }
1212 1263
1264 #ifdef XML_ATTR_INFO
1265 const XML_AttrInfo * XMLCALL
1266 XML_GetAttributeInfo(XML_Parser parser)
1267 {
1268 return attInfo;
1269 }
1270 #endif
1271
1213 void XMLCALL 1272 void XMLCALL
1214 XML_SetElementHandler(XML_Parser parser, 1273 XML_SetElementHandler(XML_Parser parser,
1215 XML_StartElementHandler start, 1274 XML_StartElementHandler start,
1216 XML_EndElementHandler end) 1275 XML_EndElementHandler end)
1217 { 1276 {
1218 startElementHandler = start; 1277 startElementHandler = start;
1219 endElementHandler = end; 1278 endElementHandler = end;
1220 } 1279 }
1221 1280
1222 void XMLCALL 1281 void XMLCALL
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) 1478 if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
1420 return 0; 1479 return 0;
1421 #ifdef XML_DTD 1480 #ifdef XML_DTD
1422 paramEntityParsing = peParsing; 1481 paramEntityParsing = peParsing;
1423 return 1; 1482 return 1;
1424 #else 1483 #else
1425 return peParsing == XML_PARAM_ENTITY_PARSING_NEVER; 1484 return peParsing == XML_PARAM_ENTITY_PARSING_NEVER;
1426 #endif 1485 #endif
1427 } 1486 }
1428 1487
1488 int XMLCALL
1489 XML_SetHashSalt(XML_Parser parser,
1490 unsigned long hash_salt)
1491 {
1492 /* block after XML_Parse()/XML_ParseBuffer() has been called */
1493 if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
1494 return 0;
1495 hash_secret_salt = hash_salt;
1496 return 1;
1497 }
1498
1429 enum XML_Status XMLCALL 1499 enum XML_Status XMLCALL
1430 XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) 1500 XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
1431 { 1501 {
1432 switch (ps_parsing) { 1502 switch (ps_parsing) {
1433 case XML_SUSPENDED: 1503 case XML_SUSPENDED:
1434 errorCode = XML_ERROR_SUSPENDED; 1504 errorCode = XML_ERROR_SUSPENDED;
1435 return XML_STATUS_ERROR; 1505 return XML_STATUS_ERROR;
1436 case XML_FINISHED: 1506 case XML_FINISHED:
1437 errorCode = XML_ERROR_FINISHED; 1507 errorCode = XML_ERROR_FINISHED;
1438 return XML_STATUS_ERROR; 1508 return XML_STATUS_ERROR;
1509 case XML_INITIALIZED:
1510 if (parentParser == NULL && !startParsing(parser)) {
1511 errorCode = XML_ERROR_NO_MEMORY;
1512 return XML_STATUS_ERROR;
1513 }
1439 default: 1514 default:
1440 ps_parsing = XML_PARSING; 1515 ps_parsing = XML_PARSING;
1441 } 1516 }
1442 1517
1443 if (len == 0) { 1518 if (len == 0) {
1444 ps_finalBuffer = (XML_Bool)isFinal; 1519 ps_finalBuffer = (XML_Bool)isFinal;
1445 if (!isFinal) 1520 if (!isFinal)
1446 return XML_STATUS_OK; 1521 return XML_STATUS_OK;
1447 positionPtr = bufferPtr; 1522 positionPtr = bufferPtr;
1448 parseEndPtr = bufferEnd; 1523 parseEndPtr = bufferEnd;
1449 1524
1450 /* If data are left over from last buffer, and we now know that these 1525 /* 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 1526 data are the final chunk of input, then we have to check them again
1452 to detect errors based on that fact. 1527 to detect errors based on that fact.
1453 */ 1528 */
1454 errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr); 1529 errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr);
1455 1530
1456 if (errorCode == XML_ERROR_NONE) { 1531 if (errorCode == XML_ERROR_NONE) {
1457 switch (ps_parsing) { 1532 switch (ps_parsing) {
1458 case XML_SUSPENDED: 1533 case XML_SUSPENDED:
1459 XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); 1534 XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);
1460 positionPtr = bufferPtr; 1535 positionPtr = bufferPtr;
1461 return XML_STATUS_SUSPENDED; 1536 return XML_STATUS_SUSPENDED;
1462 case XML_INITIALIZED: 1537 case XML_INITIALIZED:
1463 case XML_PARSING: 1538 case XML_PARSING:
1464 ps_parsing = XML_FINISHED; 1539 ps_parsing = XML_FINISHED;
1465 /* fall through */ 1540 /* fall through */
1466 default: 1541 default:
1467 return XML_STATUS_OK; 1542 return XML_STATUS_OK;
1468 } 1543 }
1469 } 1544 }
1470 eventEndPtr = eventPtr; 1545 eventEndPtr = eventPtr;
1471 processor = errorProcessor; 1546 processor = errorProcessor;
1472 return XML_STATUS_ERROR; 1547 return XML_STATUS_ERROR;
(...skipping 14 matching lines...) Expand all
1487 processor = errorProcessor; 1562 processor = errorProcessor;
1488 return XML_STATUS_ERROR; 1563 return XML_STATUS_ERROR;
1489 } 1564 }
1490 else { 1565 else {
1491 switch (ps_parsing) { 1566 switch (ps_parsing) {
1492 case XML_SUSPENDED: 1567 case XML_SUSPENDED:
1493 result = XML_STATUS_SUSPENDED; 1568 result = XML_STATUS_SUSPENDED;
1494 break; 1569 break;
1495 case XML_INITIALIZED: 1570 case XML_INITIALIZED:
1496 case XML_PARSING: 1571 case XML_PARSING:
1497 result = XML_STATUS_OK;
1498 if (isFinal) { 1572 if (isFinal) {
1499 ps_parsing = XML_FINISHED; 1573 ps_parsing = XML_FINISHED;
1500 return result; 1574 return XML_STATUS_OK;
1501 } 1575 }
1576 /* fall through */
1577 default:
1578 result = XML_STATUS_OK;
1502 } 1579 }
1503 } 1580 }
1504 1581
1505 XmlUpdatePosition(encoding, positionPtr, end, &position); 1582 XmlUpdatePosition(encoding, positionPtr, end, &position);
1506 nLeftOver = s + len - end; 1583 nLeftOver = s + len - end;
1507 if (nLeftOver) { 1584 if (nLeftOver) {
1508 if (buffer == NULL || nLeftOver > bufferLim - buffer) { 1585 if (buffer == NULL || nLeftOver > bufferLim - buffer) {
1509 /* FIXME avoid integer overflow */ 1586 /* FIXME avoid integer overflow */
1510 char *temp; 1587 char *temp;
1511 temp = (buffer == NULL 1588 temp = (buffer == NULL
1512 ? (char *)MALLOC(len * 2) 1589 ? (char *)MALLOC(len * 2)
1513 : (char *)REALLOC(buffer, len * 2)); 1590 : (char *)REALLOC(buffer, len * 2));
1514 if (temp == NULL) { 1591 if (temp == NULL) {
1515 errorCode = XML_ERROR_NO_MEMORY; 1592 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; 1593 eventPtr = eventEndPtr = NULL;
1522 processor = errorProcessor; 1594 processor = errorProcessor;
1523 return XML_STATUS_ERROR; 1595 return XML_STATUS_ERROR;
1524 } 1596 }
1597 buffer = temp;
1525 bufferLim = buffer + len * 2; 1598 bufferLim = buffer + len * 2;
1526 } 1599 }
1527 memcpy(buffer, end, nLeftOver); 1600 memcpy(buffer, end, nLeftOver);
1528 } 1601 }
1529 bufferPtr = buffer; 1602 bufferPtr = buffer;
1530 bufferEnd = buffer + nLeftOver; 1603 bufferEnd = buffer + nLeftOver;
1531 positionPtr = bufferPtr; 1604 positionPtr = bufferPtr;
1532 parseEndPtr = bufferEnd; 1605 parseEndPtr = bufferEnd;
1533 eventPtr = bufferPtr; 1606 eventPtr = bufferPtr;
1534 eventEndPtr = bufferPtr; 1607 eventEndPtr = bufferPtr;
(...skipping 17 matching lines...) Expand all
1552 const char *start; 1625 const char *start;
1553 enum XML_Status result = XML_STATUS_OK; 1626 enum XML_Status result = XML_STATUS_OK;
1554 1627
1555 switch (ps_parsing) { 1628 switch (ps_parsing) {
1556 case XML_SUSPENDED: 1629 case XML_SUSPENDED:
1557 errorCode = XML_ERROR_SUSPENDED; 1630 errorCode = XML_ERROR_SUSPENDED;
1558 return XML_STATUS_ERROR; 1631 return XML_STATUS_ERROR;
1559 case XML_FINISHED: 1632 case XML_FINISHED:
1560 errorCode = XML_ERROR_FINISHED; 1633 errorCode = XML_ERROR_FINISHED;
1561 return XML_STATUS_ERROR; 1634 return XML_STATUS_ERROR;
1635 case XML_INITIALIZED:
1636 if (parentParser == NULL && !startParsing(parser)) {
1637 errorCode = XML_ERROR_NO_MEMORY;
1638 return XML_STATUS_ERROR;
1639 }
1562 default: 1640 default:
1563 ps_parsing = XML_PARSING; 1641 ps_parsing = XML_PARSING;
1564 } 1642 }
1565 1643
1566 start = bufferPtr; 1644 start = bufferPtr;
1567 positionPtr = start; 1645 positionPtr = start;
1568 bufferEnd += len; 1646 bufferEnd += len;
1569 parseEndPtr = bufferEnd; 1647 parseEndPtr = bufferEnd;
1570 parseEndByteIndex += len; 1648 parseEndByteIndex += len;
1571 ps_finalBuffer = (XML_Bool)isFinal; 1649 ps_finalBuffer = (XML_Bool)isFinal;
1572 1650
1573 errorCode = processor(parser, start, parseEndPtr, &bufferPtr); 1651 errorCode = processor(parser, start, parseEndPtr, &bufferPtr);
1574 1652
1575 if (errorCode != XML_ERROR_NONE) { 1653 if (errorCode != XML_ERROR_NONE) {
1576 eventEndPtr = eventPtr; 1654 eventEndPtr = eventPtr;
1577 processor = errorProcessor; 1655 processor = errorProcessor;
1578 return XML_STATUS_ERROR; 1656 return XML_STATUS_ERROR;
1579 } 1657 }
1580 else { 1658 else {
1581 switch (ps_parsing) { 1659 switch (ps_parsing) {
1582 case XML_SUSPENDED: 1660 case XML_SUSPENDED:
1583 result = XML_STATUS_SUSPENDED; 1661 result = XML_STATUS_SUSPENDED;
1584 break; 1662 break;
1585 case XML_INITIALIZED: 1663 case XML_INITIALIZED:
1586 case XML_PARSING: 1664 case XML_PARSING:
1587 if (isFinal) { 1665 if (isFinal) {
1588 ps_parsing = XML_FINISHED; 1666 ps_parsing = XML_FINISHED;
1589 return result; 1667 return result;
1590 } 1668 }
1591 default: ; /* should not happen */ 1669 default: ; /* should not happen */
1592 } 1670 }
1593 } 1671 }
1594 1672
1595 XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); 1673 XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 } 1743 }
1666 #else 1744 #else
1667 if (bufferPtr) { 1745 if (bufferPtr) {
1668 memcpy(newBuf, bufferPtr, bufferEnd - bufferPtr); 1746 memcpy(newBuf, bufferPtr, bufferEnd - bufferPtr);
1669 FREE(buffer); 1747 FREE(buffer);
1670 } 1748 }
1671 bufferEnd = newBuf + (bufferEnd - bufferPtr); 1749 bufferEnd = newBuf + (bufferEnd - bufferPtr);
1672 bufferPtr = buffer = newBuf; 1750 bufferPtr = buffer = newBuf;
1673 #endif /* not defined XML_CONTEXT_BYTES */ 1751 #endif /* not defined XML_CONTEXT_BYTES */
1674 } 1752 }
1753 eventPtr = eventEndPtr = NULL;
1754 positionPtr = NULL;
1675 } 1755 }
1676 return bufferEnd; 1756 return bufferEnd;
1677 } 1757 }
1678 1758
1679 enum XML_Status XMLCALL 1759 enum XML_Status XMLCALL
1680 XML_StopParser(XML_Parser parser, XML_Bool resumable) 1760 XML_StopParser(XML_Parser parser, XML_Bool resumable)
1681 { 1761 {
1682 switch (ps_parsing) { 1762 switch (ps_parsing) {
1683 case XML_SUSPENDED: 1763 case XML_SUSPENDED:
1684 if (resumable) { 1764 if (resumable) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 if (errorCode != XML_ERROR_NONE) { 1802 if (errorCode != XML_ERROR_NONE) {
1723 eventEndPtr = eventPtr; 1803 eventEndPtr = eventPtr;
1724 processor = errorProcessor; 1804 processor = errorProcessor;
1725 return XML_STATUS_ERROR; 1805 return XML_STATUS_ERROR;
1726 } 1806 }
1727 else { 1807 else {
1728 switch (ps_parsing) { 1808 switch (ps_parsing) {
1729 case XML_SUSPENDED: 1809 case XML_SUSPENDED:
1730 result = XML_STATUS_SUSPENDED; 1810 result = XML_STATUS_SUSPENDED;
1731 break; 1811 break;
1732 case XML_INITIALIZED: 1812 case XML_INITIALIZED:
1733 case XML_PARSING: 1813 case XML_PARSING:
1734 if (ps_finalBuffer) { 1814 if (ps_finalBuffer) {
1735 ps_parsing = XML_FINISHED; 1815 ps_parsing = XML_FINISHED;
1736 return result; 1816 return result;
1737 } 1817 }
1738 default: ; 1818 default: ;
1739 } 1819 }
1740 } 1820 }
1741 1821
1742 XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); 1822 XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 XML_CONTEXT_BYTES}, 2029 XML_CONTEXT_BYTES},
1950 #endif 2030 #endif
1951 #ifdef XML_MIN_SIZE 2031 #ifdef XML_MIN_SIZE
1952 {XML_FEATURE_MIN_SIZE, XML_L("XML_MIN_SIZE"), 0}, 2032 {XML_FEATURE_MIN_SIZE, XML_L("XML_MIN_SIZE"), 0},
1953 #endif 2033 #endif
1954 #ifdef XML_NS 2034 #ifdef XML_NS
1955 {XML_FEATURE_NS, XML_L("XML_NS"), 0}, 2035 {XML_FEATURE_NS, XML_L("XML_NS"), 0},
1956 #endif 2036 #endif
1957 #ifdef XML_LARGE_SIZE 2037 #ifdef XML_LARGE_SIZE
1958 {XML_FEATURE_LARGE_SIZE, XML_L("XML_LARGE_SIZE"), 0}, 2038 {XML_FEATURE_LARGE_SIZE, XML_L("XML_LARGE_SIZE"), 0},
1959 #endif 2039 #endif
2040 #ifdef XML_ATTR_INFO
2041 {XML_FEATURE_ATTR_INFO, XML_L("XML_ATTR_INFO"), 0},
2042 #endif
1960 {XML_FEATURE_END, NULL, 0} 2043 {XML_FEATURE_END, NULL, 0}
1961 }; 2044 };
1962 2045
1963 return features; 2046 return features;
1964 } 2047 }
1965 2048
1966 /* Initially tag->rawName always points into the parse buffer; 2049 /* Initially tag->rawName always points into the parse buffer;
1967 for those TAG instances opened while the current parse buffer was 2050 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 2051 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. 2052 permanent location, since the parse buffer is about to be discarded.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2012 } 2095 }
2013 return XML_TRUE; 2096 return XML_TRUE;
2014 } 2097 }
2015 2098
2016 static enum XML_Error PTRCALL 2099 static enum XML_Error PTRCALL
2017 contentProcessor(XML_Parser parser, 2100 contentProcessor(XML_Parser parser,
2018 const char *start, 2101 const char *start,
2019 const char *end, 2102 const char *end,
2020 const char **endPtr) 2103 const char **endPtr)
2021 { 2104 {
2022 enum XML_Error result = doContent(parser, 0, encoding, start, end, 2105 enum XML_Error result = doContent(parser, 0, encoding, start, end,
2023 endPtr, (XML_Bool)!ps_finalBuffer); 2106 endPtr, (XML_Bool)!ps_finalBuffer);
2024 if (result == XML_ERROR_NONE) { 2107 if (result == XML_ERROR_NONE) {
2025 if (!storeRawNames(parser)) 2108 if (!storeRawNames(parser))
2026 return XML_ERROR_NO_MEMORY; 2109 return XML_ERROR_NO_MEMORY;
2027 } 2110 }
2028 return result; 2111 return result;
2029 } 2112 }
2030 2113
2031 static enum XML_Error PTRCALL 2114 static enum XML_Error PTRCALL
2032 externalEntityInitProcessor(XML_Parser parser, 2115 externalEntityInitProcessor(XML_Parser parser,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 eventEndPtr = next; 2177 eventEndPtr = next;
2095 2178
2096 switch (tok) { 2179 switch (tok) {
2097 case XML_TOK_XML_DECL: 2180 case XML_TOK_XML_DECL:
2098 { 2181 {
2099 enum XML_Error result; 2182 enum XML_Error result;
2100 result = processXmlDecl(parser, 1, start, next); 2183 result = processXmlDecl(parser, 1, start, next);
2101 if (result != XML_ERROR_NONE) 2184 if (result != XML_ERROR_NONE)
2102 return result; 2185 return result;
2103 switch (ps_parsing) { 2186 switch (ps_parsing) {
2104 case XML_SUSPENDED: 2187 case XML_SUSPENDED:
2105 *endPtr = next; 2188 *endPtr = next;
2106 return XML_ERROR_NONE; 2189 return XML_ERROR_NONE;
2107 case XML_FINISHED: 2190 case XML_FINISHED:
2108 return XML_ERROR_ABORTED; 2191 return XML_ERROR_ABORTED;
2109 default: 2192 default:
2110 start = next; 2193 start = next;
2111 } 2194 }
2112 } 2195 }
2113 break; 2196 break;
2114 case XML_TOK_PARTIAL: 2197 case XML_TOK_PARTIAL:
(...skipping 13 matching lines...) Expand all
2128 tagLevel = 1; 2211 tagLevel = 1;
2129 return externalEntityContentProcessor(parser, start, end, endPtr); 2212 return externalEntityContentProcessor(parser, start, end, endPtr);
2130 } 2213 }
2131 2214
2132 static enum XML_Error PTRCALL 2215 static enum XML_Error PTRCALL
2133 externalEntityContentProcessor(XML_Parser parser, 2216 externalEntityContentProcessor(XML_Parser parser,
2134 const char *start, 2217 const char *start,
2135 const char *end, 2218 const char *end,
2136 const char **endPtr) 2219 const char **endPtr)
2137 { 2220 {
2138 enum XML_Error result = doContent(parser, 1, encoding, start, end, 2221 enum XML_Error result = doContent(parser, 1, encoding, start, end,
2139 endPtr, (XML_Bool)!ps_finalBuffer); 2222 endPtr, (XML_Bool)!ps_finalBuffer);
2140 if (result == XML_ERROR_NONE) { 2223 if (result == XML_ERROR_NONE) {
2141 if (!storeRawNames(parser)) 2224 if (!storeRawNames(parser))
2142 return XML_ERROR_NO_MEMORY; 2225 return XML_ERROR_NO_MEMORY;
2143 } 2226 }
2144 return result; 2227 return result;
2145 } 2228 }
2146 2229
2147 static enum XML_Error 2230 static enum XML_Error
2148 doContent(XML_Parser parser, 2231 doContent(XML_Parser parser,
2149 int startTagLevel, 2232 int startTagLevel,
2150 const ENCODING *enc, 2233 const ENCODING *enc,
2151 const char *s, 2234 const char *s,
2152 const char *end, 2235 const char *end,
2153 const char **nextPtr, 2236 const char **nextPtr,
2154 XML_Bool haveMore) 2237 XML_Bool haveMore)
2155 { 2238 {
2156 /* save one level of indirection */ 2239 /* save one level of indirection */
2157 DTD * const dtd = _dtd; 2240 DTD * const dtd = _dtd;
2158 2241
2159 const char **eventPP; 2242 const char **eventPP;
2160 const char **eventEndPP; 2243 const char **eventEndPP;
2161 if (enc == encoding) { 2244 if (enc == encoding) {
2162 eventPP = &eventPtr; 2245 eventPP = &eventPtr;
2163 eventEndPP = &eventEndPtr; 2246 eventEndPP = &eventEndPtr;
2164 } 2247 }
2165 else { 2248 else {
2166 eventPP = &(openInternalEntities->internalEventPtr); 2249 eventPP = &(openInternalEntities->internalEventPtr);
2167 eventEndPP = &(openInternalEntities->internalEventEndPtr); 2250 eventEndPP = &(openInternalEntities->internalEventEndPtr);
(...skipping 10 matching lines...) Expand all
2178 *nextPtr = s; 2261 *nextPtr = s;
2179 return XML_ERROR_NONE; 2262 return XML_ERROR_NONE;
2180 } 2263 }
2181 *eventEndPP = end; 2264 *eventEndPP = end;
2182 if (characterDataHandler) { 2265 if (characterDataHandler) {
2183 XML_Char c = 0xA; 2266 XML_Char c = 0xA;
2184 characterDataHandler(handlerArg, &c, 1); 2267 characterDataHandler(handlerArg, &c, 1);
2185 } 2268 }
2186 else if (defaultHandler) 2269 else if (defaultHandler)
2187 reportDefault(parser, enc, s, end); 2270 reportDefault(parser, enc, s, end);
2188 /* We are at the end of the final buffer, should we check for 2271 /* We are at the end of the final buffer, should we check for
2189 XML_SUSPENDED, XML_FINISHED? 2272 XML_SUSPENDED, XML_FINISHED?
2190 */ 2273 */
2191 if (startTagLevel == 0) 2274 if (startTagLevel == 0)
2192 return XML_ERROR_NO_ELEMENTS; 2275 return XML_ERROR_NO_ELEMENTS;
2193 if (tagLevel != startTagLevel) 2276 if (tagLevel != startTagLevel)
2194 return XML_ERROR_ASYNC_ENTITY; 2277 return XML_ERROR_ASYNC_ENTITY;
2195 *nextPtr = end; 2278 *nextPtr = end;
2196 return XML_ERROR_NONE; 2279 return XML_ERROR_NONE;
2197 case XML_TOK_NONE: 2280 case XML_TOK_NONE:
2198 if (haveMore) { 2281 if (haveMore) {
2199 *nextPtr = s; 2282 *nextPtr = s;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2233 characterDataHandler(handlerArg, &ch, 1); 2316 characterDataHandler(handlerArg, &ch, 1);
2234 else if (defaultHandler) 2317 else if (defaultHandler)
2235 reportDefault(parser, enc, s, next); 2318 reportDefault(parser, enc, s, next);
2236 break; 2319 break;
2237 } 2320 }
2238 name = poolStoreString(&dtd->pool, enc, 2321 name = poolStoreString(&dtd->pool, enc,
2239 s + enc->minBytesPerChar, 2322 s + enc->minBytesPerChar,
2240 next - enc->minBytesPerChar); 2323 next - enc->minBytesPerChar);
2241 if (!name) 2324 if (!name)
2242 return XML_ERROR_NO_MEMORY; 2325 return XML_ERROR_NO_MEMORY;
2243 entity = (ENTITY *)lookup(&dtd->generalEntities, name, 0); 2326 entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0);
2244 poolDiscard(&dtd->pool); 2327 poolDiscard(&dtd->pool);
2245 /* First, determine if a check for an existing declaration is needed; 2328 /* First, determine if a check for an existing declaration is needed;
2246 if yes, check that the entity exists, and that it is internal, 2329 if yes, check that the entity exists, and that it is internal,
2247 otherwise call the skipped entity or default handler. 2330 otherwise call the skipped entity or default handler.
2248 */ 2331 */
2249 if (!dtd->hasParamEntityRefs || dtd->standalone) { 2332 if (!dtd->hasParamEntityRefs || dtd->standalone) {
2250 if (!entity) 2333 if (!entity)
2251 return XML_ERROR_UNDEFINED_ENTITY; 2334 return XML_ERROR_UNDEFINED_ENTITY;
2252 else if (!entity->is_internal) 2335 else if (!entity->is_internal)
2253 return XML_ERROR_ENTITY_DECLARED_IN_PE; 2336 return XML_ERROR_ENTITY_DECLARED_IN_PE;
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
2530 characterDataHandler(handlerArg, dataBuf, 2613 characterDataHandler(handlerArg, dataBuf,
2531 (int)(dataPtr - (ICHAR *)dataBuf)); 2614 (int)(dataPtr - (ICHAR *)dataBuf));
2532 } 2615 }
2533 else 2616 else
2534 characterDataHandler(handlerArg, 2617 characterDataHandler(handlerArg,
2535 (XML_Char *)s, 2618 (XML_Char *)s,
2536 (int)((XML_Char *)end - (XML_Char *)s)); 2619 (int)((XML_Char *)end - (XML_Char *)s));
2537 } 2620 }
2538 else if (defaultHandler) 2621 else if (defaultHandler)
2539 reportDefault(parser, enc, s, end); 2622 reportDefault(parser, enc, s, end);
2540 /* We are at the end of the final buffer, should we check for 2623 /* We are at the end of the final buffer, should we check for
2541 XML_SUSPENDED, XML_FINISHED? 2624 XML_SUSPENDED, XML_FINISHED?
2542 */ 2625 */
2543 if (startTagLevel == 0) { 2626 if (startTagLevel == 0) {
2544 *eventPP = end; 2627 *eventPP = end;
2545 return XML_ERROR_NO_ELEMENTS; 2628 return XML_ERROR_NO_ELEMENTS;
2546 } 2629 }
2547 if (tagLevel != startTagLevel) { 2630 if (tagLevel != startTagLevel) {
2548 *eventPP = end; 2631 *eventPP = end;
2549 return XML_ERROR_ASYNC_ENTITY; 2632 return XML_ERROR_ASYNC_ENTITY;
2550 } 2633 }
2551 *nextPtr = end; 2634 *nextPtr = end;
2552 return XML_ERROR_NONE; 2635 return XML_ERROR_NONE;
2553 case XML_TOK_DATA_CHARS: 2636 case XML_TOK_DATA_CHARS:
2554 { 2637 {
2555 XML_CharacterDataHandler charDataHandler = characterDataHandler; 2638 XML_CharacterDataHandler charDataHandler = characterDataHandler;
2556 if (charDataHandler) { 2639 if (charDataHandler) {
2557 if (MUST_CONVERT(enc, s)) { 2640 if (MUST_CONVERT(enc, s)) {
2558 for (;;) { 2641 for (;;) {
2559 ICHAR *dataPtr = (ICHAR *)dataBuf; 2642 ICHAR *dataPtr = (ICHAR *)dataBuf;
2560 XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); 2643 XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
2561 *eventEndPP = s; 2644 *eventEndPP = s;
2562 charDataHandler(handlerArg, dataBuf, 2645 charDataHandler(handlerArg, dataBuf,
2563 (int)(dataPtr - (ICHAR *)dataBuf)); 2646 (int)(dataPtr - (ICHAR *)dataBuf));
(...skipping 19 matching lines...) Expand all
2583 if (!reportComment(parser, enc, s, next)) 2666 if (!reportComment(parser, enc, s, next))
2584 return XML_ERROR_NO_MEMORY; 2667 return XML_ERROR_NO_MEMORY;
2585 break; 2668 break;
2586 default: 2669 default:
2587 if (defaultHandler) 2670 if (defaultHandler)
2588 reportDefault(parser, enc, s, next); 2671 reportDefault(parser, enc, s, next);
2589 break; 2672 break;
2590 } 2673 }
2591 *eventPP = s = next; 2674 *eventPP = s = next;
2592 switch (ps_parsing) { 2675 switch (ps_parsing) {
2593 case XML_SUSPENDED: 2676 case XML_SUSPENDED:
2594 *nextPtr = next; 2677 *nextPtr = next;
2595 return XML_ERROR_NONE; 2678 return XML_ERROR_NONE;
2596 case XML_FINISHED: 2679 case XML_FINISHED:
2597 return XML_ERROR_ABORTED; 2680 return XML_ERROR_ABORTED;
2598 default: ; 2681 default: ;
2599 } 2682 }
2600 } 2683 }
2601 /* not reached */ 2684 /* not reached */
2602 } 2685 }
2603 2686
(...skipping 19 matching lines...) Expand all
2623 int attIndex = 0; 2706 int attIndex = 0;
2624 int prefixLen; 2707 int prefixLen;
2625 int i; 2708 int i;
2626 int n; 2709 int n;
2627 XML_Char *uri; 2710 XML_Char *uri;
2628 int nPrefixes = 0; 2711 int nPrefixes = 0;
2629 BINDING *binding; 2712 BINDING *binding;
2630 const XML_Char *localPart; 2713 const XML_Char *localPart;
2631 2714
2632 /* lookup the element type name */ 2715 /* lookup the element type name */
2633 elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, tagNamePtr->str,0); 2716 elementType = (ELEMENT_TYPE *)lookup(parser, &dtd->elementTypes, tagNamePtr->s tr,0);
2634 if (!elementType) { 2717 if (!elementType) {
2635 const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str); 2718 const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str);
2636 if (!name) 2719 if (!name)
2637 return XML_ERROR_NO_MEMORY; 2720 return XML_ERROR_NO_MEMORY;
2638 elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, name, 2721 elementType = (ELEMENT_TYPE *)lookup(parser, &dtd->elementTypes, name,
2639 sizeof(ELEMENT_TYPE)); 2722 sizeof(ELEMENT_TYPE));
2640 if (!elementType) 2723 if (!elementType)
2641 return XML_ERROR_NO_MEMORY; 2724 return XML_ERROR_NO_MEMORY;
2642 if (ns && !setElementTypePrefix(parser, elementType)) 2725 if (ns && !setElementTypePrefix(parser, elementType))
2643 return XML_ERROR_NO_MEMORY; 2726 return XML_ERROR_NO_MEMORY;
2644 } 2727 }
2645 nDefaultAtts = elementType->nDefaultAtts; 2728 nDefaultAtts = elementType->nDefaultAtts;
2646 2729
2647 /* get the attributes from the tokenizer */ 2730 /* get the attributes from the tokenizer */
2648 n = XmlGetAttributes(enc, attStr, attsSize, atts); 2731 n = XmlGetAttributes(enc, attStr, attsSize, atts);
2649 if (n + nDefaultAtts > attsSize) { 2732 if (n + nDefaultAtts > attsSize) {
2650 int oldAttsSize = attsSize; 2733 int oldAttsSize = attsSize;
2651 ATTRIBUTE *temp; 2734 ATTRIBUTE *temp;
2735 #ifdef XML_ATTR_INFO
2736 XML_AttrInfo *temp2;
2737 #endif
2652 attsSize = n + nDefaultAtts + INIT_ATTS_SIZE; 2738 attsSize = n + nDefaultAtts + INIT_ATTS_SIZE;
2653 temp = (ATTRIBUTE *)REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE)); 2739 temp = (ATTRIBUTE *)REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE));
2654 if (temp == NULL) 2740 if (temp == NULL)
2655 return XML_ERROR_NO_MEMORY; 2741 return XML_ERROR_NO_MEMORY;
2656 atts = temp; 2742 atts = temp;
2743 #ifdef XML_ATTR_INFO
2744 temp2 = (XML_AttrInfo *)REALLOC((void *)attInfo, attsSize * sizeof(XML_AttrI nfo));
2745 if (temp2 == NULL)
2746 return XML_ERROR_NO_MEMORY;
2747 attInfo = temp2;
2748 #endif
2657 if (n > oldAttsSize) 2749 if (n > oldAttsSize)
2658 XmlGetAttributes(enc, attStr, n, atts); 2750 XmlGetAttributes(enc, attStr, n, atts);
2659 } 2751 }
2660 2752
2661 appAtts = (const XML_Char **)atts; 2753 appAtts = (const XML_Char **)atts;
2662 for (i = 0; i < n; i++) { 2754 for (i = 0; i < n; i++) {
2755 ATTRIBUTE *currAtt = &atts[i];
2756 #ifdef XML_ATTR_INFO
2757 XML_AttrInfo *currAttInfo = &attInfo[i];
2758 #endif
2663 /* add the name and value to the attribute list */ 2759 /* add the name and value to the attribute list */
2664 ATTRIBUTE_ID *attId = getAttributeId(parser, enc, atts[i].name, 2760 ATTRIBUTE_ID *attId = getAttributeId(parser, enc, currAtt->name,
2665 atts[i].name 2761 currAtt->name
2666 + XmlNameLength(enc, atts[i].name)); 2762 + XmlNameLength(enc, currAtt->name));
2667 if (!attId) 2763 if (!attId)
2668 return XML_ERROR_NO_MEMORY; 2764 return XML_ERROR_NO_MEMORY;
2765 #ifdef XML_ATTR_INFO
2766 currAttInfo->nameStart = parseEndByteIndex - (parseEndPtr - currAtt->name);
2767 currAttInfo->nameEnd = currAttInfo->nameStart +
2768 XmlNameLength(enc, currAtt->name);
2769 currAttInfo->valueStart = parseEndByteIndex -
2770 (parseEndPtr - currAtt->valuePtr);
2771 currAttInfo->valueEnd = parseEndByteIndex - (parseEndPtr - currAtt->valueEnd );
2772 #endif
2669 /* Detect duplicate attributes by their QNames. This does not work when 2773 /* Detect duplicate attributes by their QNames. This does not work when
2670 namespace processing is turned on and different prefixes for the same 2774 namespace processing is turned on and different prefixes for the same
2671 namespace are used. For this case we have a check further down. 2775 namespace are used. For this case we have a check further down.
2672 */ 2776 */
2673 if ((attId->name)[-1]) { 2777 if ((attId->name)[-1]) {
2674 if (enc == encoding) 2778 if (enc == encoding)
2675 eventPtr = atts[i].name; 2779 eventPtr = atts[i].name;
2676 return XML_ERROR_DUPLICATE_ATTRIBUTE; 2780 return XML_ERROR_DUPLICATE_ATTRIBUTE;
2677 } 2781 }
2678 (attId->name)[-1] = 1; 2782 (attId->name)[-1] = 1;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
2797 nsAtts[--j].version = version; 2901 nsAtts[--j].version = version;
2798 } 2902 }
2799 nsAttsVersion = --version; 2903 nsAttsVersion = --version;
2800 2904
2801 /* expand prefixed names and check for duplicates */ 2905 /* expand prefixed names and check for duplicates */
2802 for (; i < attIndex; i += 2) { 2906 for (; i < attIndex; i += 2) {
2803 const XML_Char *s = appAtts[i]; 2907 const XML_Char *s = appAtts[i];
2804 if (s[-1] == 2) { /* prefixed */ 2908 if (s[-1] == 2) { /* prefixed */
2805 ATTRIBUTE_ID *id; 2909 ATTRIBUTE_ID *id;
2806 const BINDING *b; 2910 const BINDING *b;
2807 unsigned long uriHash = 0; 2911 unsigned long uriHash = hash_secret_salt;
2808 ((XML_Char *)s)[-1] = 0; /* clear flag */ 2912 ((XML_Char *)s)[-1] = 0; /* clear flag */
2809 id = (ATTRIBUTE_ID *)lookup(&dtd->attributeIds, s, 0); 2913 id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, s, 0);
2810 b = id->prefix->binding; 2914 b = id->prefix->binding;
2811 if (!b) 2915 if (!b)
2812 return XML_ERROR_UNBOUND_PREFIX; 2916 return XML_ERROR_UNBOUND_PREFIX;
2813 2917
2814 /* as we expand the name we also calculate its hash value */ 2918 /* as we expand the name we also calculate its hash value */
2815 for (j = 0; j < b->uriLen; j++) { 2919 for (j = 0; j < b->uriLen; j++) {
2816 const XML_Char c = b->uri[j]; 2920 const XML_Char c = b->uri[j];
2817 if (!poolAppendChar(&tempPool, c)) 2921 if (!poolAppendChar(&tempPool, c))
2818 return XML_ERROR_NO_MEMORY; 2922 return XML_ERROR_NO_MEMORY;
2819 uriHash = CHAR_HASH(uriHash, c); 2923 uriHash = CHAR_HASH(uriHash, c);
2820 } 2924 }
2821 while (*s++ != XML_T(ASCII_COLON)) 2925 while (*s++ != XML_T(ASCII_COLON))
2822 ; 2926 ;
2823 do { /* copies null terminator */ 2927 do { /* copies null terminator */
2824 const XML_Char c = *s; 2928 const XML_Char c = *s;
2825 if (!poolAppendChar(&tempPool, *s)) 2929 if (!poolAppendChar(&tempPool, *s))
2826 return XML_ERROR_NO_MEMORY; 2930 return XML_ERROR_NO_MEMORY;
2827 uriHash = CHAR_HASH(uriHash, c); 2931 uriHash = CHAR_HASH(uriHash, c);
2828 } while (*s++); 2932 } while (*s++);
2829 2933
2830 { /* Check hash table for duplicate of expanded name (uriName). 2934 { /* Check hash table for duplicate of expanded name (uriName).
2831 Derived from code in lookup(HASH_TABLE *table, ...). 2935 Derived from code in lookup(parser, HASH_TABLE *table, ...).
2832 */ 2936 */
2833 unsigned char step = 0; 2937 unsigned char step = 0;
2834 unsigned long mask = nsAttsSize - 1; 2938 unsigned long mask = nsAttsSize - 1;
2835 j = uriHash & mask; /* index into hash table */ 2939 j = uriHash & mask; /* index into hash table */
2836 while (nsAtts[j].version == version) { 2940 while (nsAtts[j].version == version) {
2837 /* for speed we compare stored hash values first */ 2941 /* for speed we compare stored hash values first */
2838 if (uriHash == nsAtts[j].hash) { 2942 if (uriHash == nsAtts[j].hash) {
2839 const XML_Char *s1 = poolStart(&tempPool); 2943 const XML_Char *s1 = poolStart(&tempPool);
2840 const XML_Char *s2 = nsAtts[j].uriName; 2944 const XML_Char *s2 = nsAtts[j].uriName;
2841 /* s1 is null terminated, but not s2 */ 2945 /* s1 is null terminated, but not s2 */
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2942 /* addBinding() overwrites the value of prefix->binding without checking. 3046 /* addBinding() overwrites the value of prefix->binding without checking.
2943 Therefore one must keep track of the old value outside of addBinding(). 3047 Therefore one must keep track of the old value outside of addBinding().
2944 */ 3048 */
2945 static enum XML_Error 3049 static enum XML_Error
2946 addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, 3050 addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId,
2947 const XML_Char *uri, BINDING **bindingsPtr) 3051 const XML_Char *uri, BINDING **bindingsPtr)
2948 { 3052 {
2949 static const XML_Char xmlNamespace[] = { 3053 static const XML_Char xmlNamespace[] = {
2950 ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, 3054 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, 3055 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, 3056 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, 3057 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, 3058 ASCII_n, ASCII_a, ASCII_m, ASCII_e, ASCII_s, ASCII_p, ASCII_a, ASCII_c,
2955 ASCII_e, '\0' 3059 ASCII_e, '\0'
2956 }; 3060 };
2957 static const int xmlLen = 3061 static const int xmlLen =
2958 (int)sizeof(xmlNamespace)/sizeof(XML_Char) - 1; 3062 (int)sizeof(xmlNamespace)/sizeof(XML_Char) - 1;
2959 static const XML_Char xmlnsNamespace[] = { 3063 static const XML_Char xmlnsNamespace[] = {
2960 ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, 3064 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, 3065 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, 3066 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, 3067 ASCII_0, ASCII_SLASH, ASCII_x, ASCII_m, ASCII_l, ASCII_n, ASCII_s,
2964 ASCII_SLASH, '\0' 3068 ASCII_SLASH, '\0'
2965 }; 3069 };
2966 static const int xmlnsLen = 3070 static const int xmlnsLen =
2967 (int)sizeof(xmlnsNamespace)/sizeof(XML_Char) - 1; 3071 (int)sizeof(xmlnsNamespace)/sizeof(XML_Char) - 1;
2968 3072
2969 XML_Bool mustBeXML = XML_FALSE; 3073 XML_Bool mustBeXML = XML_FALSE;
2970 XML_Bool isXML = XML_TRUE; 3074 XML_Bool isXML = XML_TRUE;
2971 XML_Bool isXMLNS = XML_TRUE; 3075 XML_Bool isXMLNS = XML_TRUE;
2972 3076
2973 BINDING *b; 3077 BINDING *b;
2974 int len; 3078 int len;
2975 3079
2976 /* empty URI is only valid for default namespace per XML NS 1.0 (not 1.1) */ 3080 /* empty URI is only valid for default namespace per XML NS 1.0 (not 1.1) */
2977 if (*uri == XML_T('\0') && prefix->name) 3081 if (*uri == XML_T('\0') && prefix->name)
2978 return XML_ERROR_UNDECLARING_PREFIX; 3082 return XML_ERROR_UNDECLARING_PREFIX;
2979 3083
2980 if (prefix->name 3084 if (prefix->name
2981 && prefix->name[0] == XML_T(ASCII_x) 3085 && prefix->name[0] == XML_T(ASCII_x)
2982 && prefix->name[1] == XML_T(ASCII_m) 3086 && prefix->name[1] == XML_T(ASCII_m)
2983 && prefix->name[2] == XML_T(ASCII_l)) { 3087 && prefix->name[2] == XML_T(ASCII_l)) {
2984 3088
2985 /* Not allowed to bind xmlns */ 3089 /* Not allowed to bind xmlns */
2986 if (prefix->name[3] == XML_T(ASCII_n) 3090 if (prefix->name[3] == XML_T(ASCII_n)
2987 && prefix->name[4] == XML_T(ASCII_s) 3091 && prefix->name[4] == XML_T(ASCII_s)
2988 && prefix->name[5] == XML_T('\0')) 3092 && prefix->name[5] == XML_T('\0'))
2989 return XML_ERROR_RESERVED_PREFIX_XMLNS; 3093 return XML_ERROR_RESERVED_PREFIX_XMLNS;
2990 3094
2991 if (prefix->name[3] == XML_T('\0')) 3095 if (prefix->name[3] == XML_T('\0'))
2992 mustBeXML = XML_TRUE; 3096 mustBeXML = XML_TRUE;
2993 } 3097 }
2994 3098
2995 for (len = 0; uri[len]; len++) { 3099 for (len = 0; uri[len]; len++) {
2996 if (isXML && (len > xmlLen || uri[len] != xmlNamespace[len])) 3100 if (isXML && (len > xmlLen || uri[len] != xmlNamespace[len]))
2997 isXML = XML_FALSE; 3101 isXML = XML_FALSE;
2998 3102
2999 if (!mustBeXML && isXMLNS 3103 if (!mustBeXML && isXMLNS
3000 && (len > xmlnsLen || uri[len] != xmlnsNamespace[len])) 3104 && (len > xmlnsLen || uri[len] != xmlnsNamespace[len]))
3001 isXMLNS = XML_FALSE; 3105 isXMLNS = XML_FALSE;
3002 } 3106 }
3003 isXML = isXML && len == xmlLen; 3107 isXML = isXML && len == xmlLen;
3004 isXMLNS = isXMLNS && len == xmlnsLen; 3108 isXMLNS = isXMLNS && len == xmlnsLen;
3005 3109
3006 if (mustBeXML != isXML) 3110 if (mustBeXML != isXML)
3007 return mustBeXML ? XML_ERROR_RESERVED_PREFIX_XML 3111 return mustBeXML ? XML_ERROR_RESERVED_PREFIX_XML
3008 : XML_ERROR_RESERVED_NAMESPACE_URI; 3112 : XML_ERROR_RESERVED_NAMESPACE_URI;
3009 3113
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
3200 3304
3201 /* The idea here is to avoid using stack for each IGNORE section when 3305 /* The idea here is to avoid using stack for each IGNORE section when
3202 the whole file is parsed with one call. 3306 the whole file is parsed with one call.
3203 */ 3307 */
3204 static enum XML_Error PTRCALL 3308 static enum XML_Error PTRCALL
3205 ignoreSectionProcessor(XML_Parser parser, 3309 ignoreSectionProcessor(XML_Parser parser,
3206 const char *start, 3310 const char *start,
3207 const char *end, 3311 const char *end,
3208 const char **endPtr) 3312 const char **endPtr)
3209 { 3313 {
3210 enum XML_Error result = doIgnoreSection(parser, encoding, &start, end, 3314 enum XML_Error result = doIgnoreSection(parser, encoding, &start, end,
3211 endPtr, (XML_Bool)!ps_finalBuffer); 3315 endPtr, (XML_Bool)!ps_finalBuffer);
3212 if (result != XML_ERROR_NONE) 3316 if (result != XML_ERROR_NONE)
3213 return result; 3317 return result;
3214 if (start) { 3318 if (start) {
3215 processor = prologProcessor; 3319 processor = prologProcessor;
3216 return prologProcessor(parser, start, end, endPtr); 3320 return prologProcessor(parser, start, end, endPtr);
3217 } 3321 }
3218 return result; 3322 return result;
3219 } 3323 }
3220 3324
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
3482 entityValueInitProcessor(XML_Parser parser, 3586 entityValueInitProcessor(XML_Parser parser,
3483 const char *s, 3587 const char *s,
3484 const char *end, 3588 const char *end,
3485 const char **nextPtr) 3589 const char **nextPtr)
3486 { 3590 {
3487 int tok; 3591 int tok;
3488 const char *start = s; 3592 const char *start = s;
3489 const char *next = start; 3593 const char *next = start;
3490 eventPtr = start; 3594 eventPtr = start;
3491 3595
3492 for (;;) { 3596 for (;;) {
3493 tok = XmlPrologTok(encoding, start, end, &next); 3597 tok = XmlPrologTok(encoding, start, end, &next);
3494 eventEndPtr = next; 3598 eventEndPtr = next;
3495 if (tok <= 0) { 3599 if (tok <= 0) {
3496 if (!ps_finalBuffer && tok != XML_TOK_INVALID) { 3600 if (!ps_finalBuffer && tok != XML_TOK_INVALID) {
3497 *nextPtr = s; 3601 *nextPtr = s;
3498 return XML_ERROR_NONE; 3602 return XML_ERROR_NONE;
3499 } 3603 }
3500 switch (tok) { 3604 switch (tok) {
3501 case XML_TOK_INVALID: 3605 case XML_TOK_INVALID:
3502 return XML_ERROR_INVALID_TOKEN; 3606 return XML_ERROR_INVALID_TOKEN;
3503 case XML_TOK_PARTIAL: 3607 case XML_TOK_PARTIAL:
3504 return XML_ERROR_UNCLOSED_TOKEN; 3608 return XML_ERROR_UNCLOSED_TOKEN;
3505 case XML_TOK_PARTIAL_CHAR: 3609 case XML_TOK_PARTIAL_CHAR:
3506 return XML_ERROR_PARTIAL_CHAR; 3610 return XML_ERROR_PARTIAL_CHAR;
3507 case XML_TOK_NONE: /* start == end */ 3611 case XML_TOK_NONE: /* start == end */
3508 default: 3612 default:
3509 break; 3613 break;
3510 } 3614 }
3511 /* found end of entity value - can store it now */ 3615 /* found end of entity value - can store it now */
3512 return storeEntityValue(parser, encoding, s, end); 3616 return storeEntityValue(parser, encoding, s, end);
3513 } 3617 }
3514 else if (tok == XML_TOK_XML_DECL) { 3618 else if (tok == XML_TOK_XML_DECL) {
3515 enum XML_Error result; 3619 enum XML_Error result;
3516 result = processXmlDecl(parser, 0, start, next); 3620 result = processXmlDecl(parser, 0, start, next);
3517 if (result != XML_ERROR_NONE) 3621 if (result != XML_ERROR_NONE)
3518 return result; 3622 return result;
3519 switch (ps_parsing) { 3623 switch (ps_parsing) {
3520 case XML_SUSPENDED: 3624 case XML_SUSPENDED:
3521 *nextPtr = next; 3625 *nextPtr = next;
3522 return XML_ERROR_NONE; 3626 return XML_ERROR_NONE;
3523 case XML_FINISHED: 3627 case XML_FINISHED:
3524 return XML_ERROR_ABORTED; 3628 return XML_ERROR_ABORTED;
3525 default: 3629 default:
3526 *nextPtr = next; 3630 *nextPtr = next;
3527 } 3631 }
3528 /* stop scanning for text declaration - we found one */ 3632 /* stop scanning for text declaration - we found one */
3529 processor = entityValueProcessor; 3633 processor = entityValueProcessor;
3530 return entityValueProcessor(parser, next, end, nextPtr); 3634 return entityValueProcessor(parser, next, end, nextPtr);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
3575 /* This would cause the next stage, i.e. doProlog to be passed XML_TOK_BOM. 3679 /* This would cause the next stage, i.e. doProlog to be passed XML_TOK_BOM.
3576 However, when parsing an external subset, doProlog will not accept a BOM 3680 However, when parsing an external subset, doProlog will not accept a BOM
3577 as valid, and report a syntax error, so we have to skip the BOM 3681 as valid, and report a syntax error, so we have to skip the BOM
3578 */ 3682 */
3579 else if (tok == XML_TOK_BOM) { 3683 else if (tok == XML_TOK_BOM) {
3580 s = next; 3684 s = next;
3581 tok = XmlPrologTok(encoding, s, end, &next); 3685 tok = XmlPrologTok(encoding, s, end, &next);
3582 } 3686 }
3583 3687
3584 processor = prologProcessor; 3688 processor = prologProcessor;
3585 return doProlog(parser, encoding, s, end, tok, next, 3689 return doProlog(parser, encoding, s, end, tok, next,
3586 nextPtr, (XML_Bool)!ps_finalBuffer); 3690 nextPtr, (XML_Bool)!ps_finalBuffer);
3587 } 3691 }
3588 3692
3589 static enum XML_Error PTRCALL 3693 static enum XML_Error PTRCALL
3590 entityValueProcessor(XML_Parser parser, 3694 entityValueProcessor(XML_Parser parser,
3591 const char *s, 3695 const char *s,
3592 const char *end, 3696 const char *end,
3593 const char **nextPtr) 3697 const char **nextPtr)
3594 { 3698 {
3595 const char *start = s; 3699 const char *start = s;
(...skipping 29 matching lines...) Expand all
3625 #endif /* XML_DTD */ 3729 #endif /* XML_DTD */
3626 3730
3627 static enum XML_Error PTRCALL 3731 static enum XML_Error PTRCALL
3628 prologProcessor(XML_Parser parser, 3732 prologProcessor(XML_Parser parser,
3629 const char *s, 3733 const char *s,
3630 const char *end, 3734 const char *end,
3631 const char **nextPtr) 3735 const char **nextPtr)
3632 { 3736 {
3633 const char *next = s; 3737 const char *next = s;
3634 int tok = XmlPrologTok(encoding, s, end, &next); 3738 int tok = XmlPrologTok(encoding, s, end, &next);
3635 return doProlog(parser, encoding, s, end, tok, next, 3739 return doProlog(parser, encoding, s, end, tok, next,
3636 nextPtr, (XML_Bool)!ps_finalBuffer); 3740 nextPtr, (XML_Bool)!ps_finalBuffer);
3637 } 3741 }
3638 3742
3639 static enum XML_Error 3743 static enum XML_Error
3640 doProlog(XML_Parser parser, 3744 doProlog(XML_Parser parser,
3641 const ENCODING *enc, 3745 const ENCODING *enc,
3642 const char *s, 3746 const char *s,
3643 const char *end, 3747 const char *end,
3644 int tok, 3748 int tok,
3645 const char *next, 3749 const char *next,
3646 const char **nextPtr, 3750 const char **nextPtr,
3647 XML_Bool haveMore) 3751 XML_Bool haveMore)
3648 { 3752 {
3649 #ifdef XML_DTD 3753 #ifdef XML_DTD
3650 static const XML_Char externalSubsetName[] = { ASCII_HASH , '\0' }; 3754 static const XML_Char externalSubsetName[] = { ASCII_HASH , '\0' };
3651 #endif /* XML_DTD */ 3755 #endif /* XML_DTD */
3652 static const XML_Char atypeCDATA[] = 3756 static const XML_Char atypeCDATA[] =
3653 { ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; 3757 { ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' };
3654 static const XML_Char atypeID[] = { ASCII_I, ASCII_D, '\0' }; 3758 static const XML_Char atypeID[] = { ASCII_I, ASCII_D, '\0' };
3655 static const XML_Char atypeIDREF[] = 3759 static const XML_Char atypeIDREF[] =
3656 { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' }; 3760 { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' };
3657 static const XML_Char atypeIDREFS[] = 3761 static const XML_Char atypeIDREFS[] =
3658 { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' }; 3762 { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' };
3659 static const XML_Char atypeENTITY[] = 3763 static const XML_Char atypeENTITY[] =
3660 { ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' }; 3764 { ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' };
3661 static const XML_Char atypeENTITIES[] = { ASCII_E, ASCII_N, 3765 static const XML_Char atypeENTITIES[] = { ASCII_E, ASCII_N,
3662 ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, '\0' }; 3766 ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, '\0' };
3663 static const XML_Char atypeNMTOKEN[] = { 3767 static const XML_Char atypeNMTOKEN[] = {
3664 ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' }; 3768 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, 3769 static const XML_Char atypeNMTOKENS[] = { ASCII_N, ASCII_M, ASCII_T,
3666 ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, '\0' }; 3770 ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, '\0' };
3667 static const XML_Char notationPrefix[] = { ASCII_N, ASCII_O, ASCII_T, 3771 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' }; 3772 ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, ASCII_LPAREN, '\0' };
3669 static const XML_Char enumValueSep[] = { ASCII_PIPE, '\0' }; 3773 static const XML_Char enumValueSep[] = { ASCII_PIPE, '\0' };
3670 static const XML_Char enumValueStart[] = { ASCII_LPAREN, '\0' }; 3774 static const XML_Char enumValueStart[] = { ASCII_LPAREN, '\0' };
3671 3775
3672 /* save one level of indirection */ 3776 /* save one level of indirection */
3673 DTD * const dtd = _dtd; 3777 DTD * const dtd = _dtd;
3674 3778
3675 const char **eventPP; 3779 const char **eventPP;
3676 const char **eventEndPP; 3780 const char **eventEndPP;
3677 enum XML_Content_Quant quant; 3781 enum XML_Content_Quant quant;
3678 3782
3679 if (enc == encoding) { 3783 if (enc == encoding) {
3680 eventPP = &eventPtr; 3784 eventPP = &eventPtr;
3681 eventEndPP = &eventEndPtr; 3785 eventEndPP = &eventEndPtr;
3682 } 3786 }
3683 else { 3787 else {
(...skipping 12 matching lines...) Expand all
3696 return XML_ERROR_NONE; 3800 return XML_ERROR_NONE;
3697 } 3801 }
3698 switch (tok) { 3802 switch (tok) {
3699 case XML_TOK_INVALID: 3803 case XML_TOK_INVALID:
3700 *eventPP = next; 3804 *eventPP = next;
3701 return XML_ERROR_INVALID_TOKEN; 3805 return XML_ERROR_INVALID_TOKEN;
3702 case XML_TOK_PARTIAL: 3806 case XML_TOK_PARTIAL:
3703 return XML_ERROR_UNCLOSED_TOKEN; 3807 return XML_ERROR_UNCLOSED_TOKEN;
3704 case XML_TOK_PARTIAL_CHAR: 3808 case XML_TOK_PARTIAL_CHAR:
3705 return XML_ERROR_PARTIAL_CHAR; 3809 return XML_ERROR_PARTIAL_CHAR;
3810 case -XML_TOK_PROLOG_S:
3811 tok = -tok;
3812 break;
3706 case XML_TOK_NONE: 3813 case XML_TOK_NONE:
3707 #ifdef XML_DTD 3814 #ifdef XML_DTD
3708 /* for internal PE NOT referenced between declarations */ 3815 /* for internal PE NOT referenced between declarations */
3709 if (enc != encoding && !openInternalEntities->betweenDecl) { 3816 if (enc != encoding && !openInternalEntities->betweenDecl) {
3710 *nextPtr = s; 3817 *nextPtr = s;
3711 return XML_ERROR_NONE; 3818 return XML_ERROR_NONE;
3712 } 3819 }
3713 /* WFC: PE Between Declarations - must check that PE contains 3820 /* WFC: PE Between Declarations - must check that PE contains
3714 complete markup, not only for external PEs, but also for 3821 complete markup, not only for external PEs, but also for
3715 internal PEs if the reference occurs between declarations. 3822 internal PEs if the reference occurs between declarations.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3767 if (result != XML_ERROR_NONE) 3874 if (result != XML_ERROR_NONE)
3768 return result; 3875 return result;
3769 enc = encoding; 3876 enc = encoding;
3770 handleDefault = XML_FALSE; 3877 handleDefault = XML_FALSE;
3771 } 3878 }
3772 break; 3879 break;
3773 #endif /* XML_DTD */ 3880 #endif /* XML_DTD */
3774 case XML_ROLE_DOCTYPE_PUBLIC_ID: 3881 case XML_ROLE_DOCTYPE_PUBLIC_ID:
3775 #ifdef XML_DTD 3882 #ifdef XML_DTD
3776 useForeignDTD = XML_FALSE; 3883 useForeignDTD = XML_FALSE;
3777 declEntity = (ENTITY *)lookup(&dtd->paramEntities, 3884 declEntity = (ENTITY *)lookup(parser,
3885 &dtd->paramEntities,
3778 externalSubsetName, 3886 externalSubsetName,
3779 sizeof(ENTITY)); 3887 sizeof(ENTITY));
3780 if (!declEntity) 3888 if (!declEntity)
3781 return XML_ERROR_NO_MEMORY; 3889 return XML_ERROR_NO_MEMORY;
3782 #endif /* XML_DTD */ 3890 #endif /* XML_DTD */
3783 dtd->hasParamEntityRefs = XML_TRUE; 3891 dtd->hasParamEntityRefs = XML_TRUE;
3784 if (startDoctypeDeclHandler) { 3892 if (startDoctypeDeclHandler) {
3893 XML_Char *pubId;
3785 if (!XmlIsPublicId(enc, s, next, eventPP)) 3894 if (!XmlIsPublicId(enc, s, next, eventPP))
3786 return XML_ERROR_PUBLICID; 3895 return XML_ERROR_PUBLICID;
3787 doctypePubid = poolStoreString(&tempPool, enc, 3896 pubId = poolStoreString(&tempPool, enc,
3788 s + enc->minBytesPerChar, 3897 s + enc->minBytesPerChar,
3789 next - enc->minBytesPerChar); 3898 next - enc->minBytesPerChar);
3790 if (!doctypePubid) 3899 if (!pubId)
3791 return XML_ERROR_NO_MEMORY; 3900 return XML_ERROR_NO_MEMORY;
3792 normalizePublicId((XML_Char *)doctypePubid); 3901 normalizePublicId(pubId);
3793 poolFinish(&tempPool); 3902 poolFinish(&tempPool);
3903 doctypePubid = pubId;
3794 handleDefault = XML_FALSE; 3904 handleDefault = XML_FALSE;
3795 goto alreadyChecked; 3905 goto alreadyChecked;
3796 } 3906 }
3797 /* fall through */ 3907 /* fall through */
3798 case XML_ROLE_ENTITY_PUBLIC_ID: 3908 case XML_ROLE_ENTITY_PUBLIC_ID:
3799 if (!XmlIsPublicId(enc, s, next, eventPP)) 3909 if (!XmlIsPublicId(enc, s, next, eventPP))
3800 return XML_ERROR_PUBLICID; 3910 return XML_ERROR_PUBLICID;
3801 alreadyChecked: 3911 alreadyChecked:
3802 if (dtd->keepProcessing && declEntity) { 3912 if (dtd->keepProcessing && declEntity) {
3803 XML_Char *tem = poolStoreString(&dtd->pool, 3913 XML_Char *tem = poolStoreString(&dtd->pool,
(...skipping 18 matching lines...) Expand all
3822 } 3932 }
3823 /* doctypeSysid will be non-NULL in the case of a previous 3933 /* doctypeSysid will be non-NULL in the case of a previous
3824 XML_ROLE_DOCTYPE_SYSTEM_ID, even if startDoctypeDeclHandler 3934 XML_ROLE_DOCTYPE_SYSTEM_ID, even if startDoctypeDeclHandler
3825 was not set, indicating an external subset 3935 was not set, indicating an external subset
3826 */ 3936 */
3827 #ifdef XML_DTD 3937 #ifdef XML_DTD
3828 if (doctypeSysid || useForeignDTD) { 3938 if (doctypeSysid || useForeignDTD) {
3829 XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; 3939 XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs;
3830 dtd->hasParamEntityRefs = XML_TRUE; 3940 dtd->hasParamEntityRefs = XML_TRUE;
3831 if (paramEntityParsing && externalEntityRefHandler) { 3941 if (paramEntityParsing && externalEntityRefHandler) {
3832 ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities, 3942 ENTITY *entity = (ENTITY *)lookup(parser,
3943 &dtd->paramEntities,
3833 externalSubsetName, 3944 externalSubsetName,
3834 sizeof(ENTITY)); 3945 sizeof(ENTITY));
3835 if (!entity) 3946 if (!entity)
3836 return XML_ERROR_NO_MEMORY; 3947 return XML_ERROR_NO_MEMORY;
3837 if (useForeignDTD) 3948 if (useForeignDTD)
3838 entity->base = curBase; 3949 entity->base = curBase;
3839 dtd->paramEntityRead = XML_FALSE; 3950 dtd->paramEntityRead = XML_FALSE;
3840 if (!externalEntityRefHandler(externalEntityRefHandlerArg, 3951 if (!externalEntityRefHandler(externalEntityRefHandlerArg,
3841 0, 3952 0,
3842 entity->base, 3953 entity->base,
3843 entity->systemId, 3954 entity->systemId,
3844 entity->publicId)) 3955 entity->publicId))
3845 return XML_ERROR_EXTERNAL_ENTITY_HANDLING; 3956 return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
3846 if (dtd->paramEntityRead) { 3957 if (dtd->paramEntityRead) {
3847 if (!dtd->standalone && 3958 if (!dtd->standalone &&
3848 notStandaloneHandler && 3959 notStandaloneHandler &&
3849 !notStandaloneHandler(handlerArg)) 3960 !notStandaloneHandler(handlerArg))
3850 return XML_ERROR_NOT_STANDALONE; 3961 return XML_ERROR_NOT_STANDALONE;
3851 } 3962 }
3852 /* if we didn't read the foreign DTD then this means that there 3963 /* if we didn't read the foreign DTD then this means that there
3853 is no external subset and we must reset dtd->hasParamEntityRefs 3964 is no external subset and we must reset dtd->hasParamEntityRefs
3854 */ 3965 */
3855 else if (!doctypeSysid) 3966 else if (!doctypeSysid)
3856 dtd->hasParamEntityRefs = hadParamEntityRefs; 3967 dtd->hasParamEntityRefs = hadParamEntityRefs;
3857 /* end of DTD - no need to update dtd->keepProcessing */ 3968 /* end of DTD - no need to update dtd->keepProcessing */
3858 } 3969 }
3859 useForeignDTD = XML_FALSE; 3970 useForeignDTD = XML_FALSE;
3860 } 3971 }
3861 #endif /* XML_DTD */ 3972 #endif /* XML_DTD */
3862 if (endDoctypeDeclHandler) { 3973 if (endDoctypeDeclHandler) {
3863 endDoctypeDeclHandler(handlerArg); 3974 endDoctypeDeclHandler(handlerArg);
3864 handleDefault = XML_FALSE; 3975 handleDefault = XML_FALSE;
3865 } 3976 }
3866 break; 3977 break;
3867 case XML_ROLE_INSTANCE_START: 3978 case XML_ROLE_INSTANCE_START:
3868 #ifdef XML_DTD 3979 #ifdef XML_DTD
3869 /* if there is no DOCTYPE declaration then now is the 3980 /* if there is no DOCTYPE declaration then now is the
3870 last chance to read the foreign DTD 3981 last chance to read the foreign DTD
3871 */ 3982 */
3872 if (useForeignDTD) { 3983 if (useForeignDTD) {
3873 XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; 3984 XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs;
3874 dtd->hasParamEntityRefs = XML_TRUE; 3985 dtd->hasParamEntityRefs = XML_TRUE;
3875 if (paramEntityParsing && externalEntityRefHandler) { 3986 if (paramEntityParsing && externalEntityRefHandler) {
3876 ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities, 3987 ENTITY *entity = (ENTITY *)lookup(parser, &dtd->paramEntities,
3877 externalSubsetName, 3988 externalSubsetName,
3878 sizeof(ENTITY)); 3989 sizeof(ENTITY));
3879 if (!entity) 3990 if (!entity)
3880 return XML_ERROR_NO_MEMORY; 3991 return XML_ERROR_NO_MEMORY;
3881 entity->base = curBase; 3992 entity->base = curBase;
3882 dtd->paramEntityRead = XML_FALSE; 3993 dtd->paramEntityRead = XML_FALSE;
3883 if (!externalEntityRefHandler(externalEntityRefHandlerArg, 3994 if (!externalEntityRefHandler(externalEntityRefHandlerArg,
3884 0, 3995 0,
3885 entity->base, 3996 entity->base,
3886 entity->systemId, 3997 entity->systemId,
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
4080 #ifdef XML_DTD 4191 #ifdef XML_DTD
4081 && !paramEntityParsing 4192 && !paramEntityParsing
4082 #endif /* XML_DTD */ 4193 #endif /* XML_DTD */
4083 && notStandaloneHandler 4194 && notStandaloneHandler
4084 && !notStandaloneHandler(handlerArg)) 4195 && !notStandaloneHandler(handlerArg))
4085 return XML_ERROR_NOT_STANDALONE; 4196 return XML_ERROR_NOT_STANDALONE;
4086 #ifndef XML_DTD 4197 #ifndef XML_DTD
4087 break; 4198 break;
4088 #else /* XML_DTD */ 4199 #else /* XML_DTD */
4089 if (!declEntity) { 4200 if (!declEntity) {
4090 declEntity = (ENTITY *)lookup(&dtd->paramEntities, 4201 declEntity = (ENTITY *)lookup(parser,
4202 &dtd->paramEntities,
4091 externalSubsetName, 4203 externalSubsetName,
4092 sizeof(ENTITY)); 4204 sizeof(ENTITY));
4093 if (!declEntity) 4205 if (!declEntity)
4094 return XML_ERROR_NO_MEMORY; 4206 return XML_ERROR_NO_MEMORY;
4095 declEntity->publicId = NULL; 4207 declEntity->publicId = NULL;
4096 } 4208 }
4097 /* fall through */ 4209 /* fall through */
4098 #endif /* XML_DTD */ 4210 #endif /* XML_DTD */
4099 case XML_ROLE_ENTITY_SYSTEM_ID: 4211 case XML_ROLE_ENTITY_SYSTEM_ID:
4100 if (dtd->keepProcessing && declEntity) { 4212 if (dtd->keepProcessing && declEntity) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
4155 case XML_ROLE_GENERAL_ENTITY_NAME: 4267 case XML_ROLE_GENERAL_ENTITY_NAME:
4156 { 4268 {
4157 if (XmlPredefinedEntityName(enc, s, next)) { 4269 if (XmlPredefinedEntityName(enc, s, next)) {
4158 declEntity = NULL; 4270 declEntity = NULL;
4159 break; 4271 break;
4160 } 4272 }
4161 if (dtd->keepProcessing) { 4273 if (dtd->keepProcessing) {
4162 const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); 4274 const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next);
4163 if (!name) 4275 if (!name)
4164 return XML_ERROR_NO_MEMORY; 4276 return XML_ERROR_NO_MEMORY;
4165 declEntity = (ENTITY *)lookup(&dtd->generalEntities, name, 4277 declEntity = (ENTITY *)lookup(parser, &dtd->generalEntities, name,
4166 sizeof(ENTITY)); 4278 sizeof(ENTITY));
4167 if (!declEntity) 4279 if (!declEntity)
4168 return XML_ERROR_NO_MEMORY; 4280 return XML_ERROR_NO_MEMORY;
4169 if (declEntity->name != name) { 4281 if (declEntity->name != name) {
4170 poolDiscard(&dtd->pool); 4282 poolDiscard(&dtd->pool);
4171 declEntity = NULL; 4283 declEntity = NULL;
4172 } 4284 }
4173 else { 4285 else {
4174 poolFinish(&dtd->pool); 4286 poolFinish(&dtd->pool);
4175 declEntity->publicId = NULL; 4287 declEntity->publicId = NULL;
(...skipping 11 matching lines...) Expand all
4187 declEntity = NULL; 4299 declEntity = NULL;
4188 } 4300 }
4189 } 4301 }
4190 break; 4302 break;
4191 case XML_ROLE_PARAM_ENTITY_NAME: 4303 case XML_ROLE_PARAM_ENTITY_NAME:
4192 #ifdef XML_DTD 4304 #ifdef XML_DTD
4193 if (dtd->keepProcessing) { 4305 if (dtd->keepProcessing) {
4194 const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); 4306 const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next);
4195 if (!name) 4307 if (!name)
4196 return XML_ERROR_NO_MEMORY; 4308 return XML_ERROR_NO_MEMORY;
4197 declEntity = (ENTITY *)lookup(&dtd->paramEntities, 4309 declEntity = (ENTITY *)lookup(parser, &dtd->paramEntities,
4198 name, sizeof(ENTITY)); 4310 name, sizeof(ENTITY));
4199 if (!declEntity) 4311 if (!declEntity)
4200 return XML_ERROR_NO_MEMORY; 4312 return XML_ERROR_NO_MEMORY;
4201 if (declEntity->name != name) { 4313 if (declEntity->name != name) {
4202 poolDiscard(&dtd->pool); 4314 poolDiscard(&dtd->pool);
4203 declEntity = NULL; 4315 declEntity = NULL;
4204 } 4316 }
4205 else { 4317 else {
4206 poolFinish(&dtd->pool); 4318 poolFinish(&dtd->pool);
4207 declEntity->publicId = NULL; 4319 declEntity->publicId = NULL;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
4276 0, 4388 0,
4277 declNotationPublicId); 4389 declNotationPublicId);
4278 handleDefault = XML_FALSE; 4390 handleDefault = XML_FALSE;
4279 } 4391 }
4280 poolClear(&tempPool); 4392 poolClear(&tempPool);
4281 break; 4393 break;
4282 case XML_ROLE_ERROR: 4394 case XML_ROLE_ERROR:
4283 switch (tok) { 4395 switch (tok) {
4284 case XML_TOK_PARAM_ENTITY_REF: 4396 case XML_TOK_PARAM_ENTITY_REF:
4285 /* PE references in internal subset are 4397 /* PE references in internal subset are
4286 not allowed within declarations. */ 4398 not allowed within declarations. */
4287 return XML_ERROR_PARAM_ENTITY_REF; 4399 return XML_ERROR_PARAM_ENTITY_REF;
4288 case XML_TOK_XML_DECL: 4400 case XML_TOK_XML_DECL:
4289 return XML_ERROR_MISPLACED_XML_PI; 4401 return XML_ERROR_MISPLACED_XML_PI;
4290 default: 4402 default:
4291 return XML_ERROR_SYNTAX; 4403 return XML_ERROR_SYNTAX;
4292 } 4404 }
4293 #ifdef XML_DTD 4405 #ifdef XML_DTD
4294 case XML_ROLE_IGNORE_SECT: 4406 case XML_ROLE_IGNORE_SECT:
4295 { 4407 {
4296 enum XML_Error result; 4408 enum XML_Error result;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
4369 if (!paramEntityParsing) 4481 if (!paramEntityParsing)
4370 dtd->keepProcessing = dtd->standalone; 4482 dtd->keepProcessing = dtd->standalone;
4371 else { 4483 else {
4372 const XML_Char *name; 4484 const XML_Char *name;
4373 ENTITY *entity; 4485 ENTITY *entity;
4374 name = poolStoreString(&dtd->pool, enc, 4486 name = poolStoreString(&dtd->pool, enc,
4375 s + enc->minBytesPerChar, 4487 s + enc->minBytesPerChar,
4376 next - enc->minBytesPerChar); 4488 next - enc->minBytesPerChar);
4377 if (!name) 4489 if (!name)
4378 return XML_ERROR_NO_MEMORY; 4490 return XML_ERROR_NO_MEMORY;
4379 entity = (ENTITY *)lookup(&dtd->paramEntities, name, 0); 4491 entity = (ENTITY *)lookup(parser, &dtd->paramEntities, name, 0);
4380 poolDiscard(&dtd->pool); 4492 poolDiscard(&dtd->pool);
4381 /* first, determine if a check for an existing declaration is needed; 4493 /* first, determine if a check for an existing declaration is needed;
4382 if yes, check that the entity exists, and that it is internal, 4494 if yes, check that the entity exists, and that it is internal,
4383 otherwise call the skipped entity handler 4495 otherwise call the skipped entity handler
4384 */ 4496 */
4385 if (prologState.documentEntity && 4497 if (prologState.documentEntity &&
4386 (dtd->standalone 4498 (dtd->standalone
4387 ? !openInternalEntities 4499 ? !openInternalEntities
4388 : !dtd->hasParamEntityRefs)) { 4500 : !dtd->hasParamEntityRefs)) {
4389 if (!entity) 4501 if (!entity)
4390 return XML_ERROR_UNDEFINED_ENTITY; 4502 return XML_ERROR_UNDEFINED_ENTITY;
4391 else if (!entity->is_internal) 4503 else if (!entity->is_internal)
4392 return XML_ERROR_ENTITY_DECLARED_IN_PE; 4504 return XML_ERROR_ENTITY_DECLARED_IN_PE;
4393 } 4505 }
4394 else if (!entity) { 4506 else if (!entity) {
4395 dtd->keepProcessing = dtd->standalone; 4507 dtd->keepProcessing = dtd->standalone;
4396 /* cannot report skipped entities in declarations */ 4508 /* cannot report skipped entities in declarations */
4397 if ((role == XML_ROLE_PARAM_ENTITY_REF) && skippedEntityHandler) { 4509 if ((role == XML_ROLE_PARAM_ENTITY_REF) && skippedEntityHandler) {
4398 skippedEntityHandler(handlerArg, name, 1); 4510 skippedEntityHandler(handlerArg, name, 1);
4399 handleDefault = XML_FALSE; 4511 handleDefault = XML_FALSE;
4400 } 4512 }
4401 break; 4513 break;
4402 } 4514 }
4403 if (entity->open) 4515 if (entity->open)
4404 return XML_ERROR_RECURSIVE_ENTITY_REF; 4516 return XML_ERROR_RECURSIVE_ENTITY_REF;
4405 if (entity->textPtr) { 4517 if (entity->textPtr) {
4406 enum XML_Error result; 4518 enum XML_Error result;
4407 XML_Bool betweenDecl = 4519 XML_Bool betweenDecl =
4408 (role == XML_ROLE_PARAM_ENTITY_REF ? XML_TRUE : XML_FALSE); 4520 (role == XML_ROLE_PARAM_ENTITY_REF ? XML_TRUE : XML_FALSE);
4409 result = processInternalEntity(parser, entity, betweenDecl); 4521 result = processInternalEntity(parser, entity, betweenDecl);
4410 if (result != XML_ERROR_NONE) 4522 if (result != XML_ERROR_NONE)
4411 return result; 4523 return result;
4412 handleDefault = XML_FALSE; 4524 handleDefault = XML_FALSE;
4413 break; 4525 break;
4414 } 4526 }
4415 if (externalEntityRefHandler) { 4527 if (externalEntityRefHandler) {
4416 dtd->paramEntityRead = XML_FALSE; 4528 dtd->paramEntityRead = XML_FALSE;
4417 entity->open = XML_TRUE; 4529 entity->open = XML_TRUE;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
4592 case XML_ROLE_ELEMENT_NONE: 4704 case XML_ROLE_ELEMENT_NONE:
4593 if (elementDeclHandler) 4705 if (elementDeclHandler)
4594 handleDefault = XML_FALSE; 4706 handleDefault = XML_FALSE;
4595 break; 4707 break;
4596 } /* end of big switch */ 4708 } /* end of big switch */
4597 4709
4598 if (handleDefault && defaultHandler) 4710 if (handleDefault && defaultHandler)
4599 reportDefault(parser, enc, s, next); 4711 reportDefault(parser, enc, s, next);
4600 4712
4601 switch (ps_parsing) { 4713 switch (ps_parsing) {
4602 case XML_SUSPENDED: 4714 case XML_SUSPENDED:
4603 *nextPtr = next; 4715 *nextPtr = next;
4604 return XML_ERROR_NONE; 4716 return XML_ERROR_NONE;
4605 case XML_FINISHED: 4717 case XML_FINISHED:
4606 return XML_ERROR_ABORTED; 4718 return XML_ERROR_ABORTED;
4607 default: 4719 default:
4608 s = next; 4720 s = next;
4609 tok = XmlPrologTok(enc, s, end, &next); 4721 tok = XmlPrologTok(enc, s, end, &next);
4610 } 4722 }
4611 } 4723 }
4612 /* not reached */ 4724 /* not reached */
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
4662 if (!ps_finalBuffer) { 4774 if (!ps_finalBuffer) {
4663 *nextPtr = s; 4775 *nextPtr = s;
4664 return XML_ERROR_NONE; 4776 return XML_ERROR_NONE;
4665 } 4777 }
4666 return XML_ERROR_PARTIAL_CHAR; 4778 return XML_ERROR_PARTIAL_CHAR;
4667 default: 4779 default:
4668 return XML_ERROR_JUNK_AFTER_DOC_ELEMENT; 4780 return XML_ERROR_JUNK_AFTER_DOC_ELEMENT;
4669 } 4781 }
4670 eventPtr = s = next; 4782 eventPtr = s = next;
4671 switch (ps_parsing) { 4783 switch (ps_parsing) {
4672 case XML_SUSPENDED: 4784 case XML_SUSPENDED:
4673 *nextPtr = next; 4785 *nextPtr = next;
4674 return XML_ERROR_NONE; 4786 return XML_ERROR_NONE;
4675 case XML_FINISHED: 4787 case XML_FINISHED:
4676 return XML_ERROR_ABORTED; 4788 return XML_ERROR_ABORTED;
4677 default: ; 4789 default: ;
4678 } 4790 }
4679 } 4791 }
4680 } 4792 }
4681 4793
4682 static enum XML_Error 4794 static enum XML_Error
(...skipping 22 matching lines...) Expand all
4705 openEntity->startTagLevel = tagLevel; 4817 openEntity->startTagLevel = tagLevel;
4706 openEntity->betweenDecl = betweenDecl; 4818 openEntity->betweenDecl = betweenDecl;
4707 openEntity->internalEventPtr = NULL; 4819 openEntity->internalEventPtr = NULL;
4708 openEntity->internalEventEndPtr = NULL; 4820 openEntity->internalEventEndPtr = NULL;
4709 textStart = (char *)entity->textPtr; 4821 textStart = (char *)entity->textPtr;
4710 textEnd = (char *)(entity->textPtr + entity->textLen); 4822 textEnd = (char *)(entity->textPtr + entity->textLen);
4711 4823
4712 #ifdef XML_DTD 4824 #ifdef XML_DTD
4713 if (entity->is_param) { 4825 if (entity->is_param) {
4714 int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next); 4826 int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next);
4715 result = doProlog(parser, internalEncoding, textStart, textEnd, tok, 4827 result = doProlog(parser, internalEncoding, textStart, textEnd, tok,
4716 next, &next, XML_FALSE); 4828 next, &next, XML_FALSE);
4717 } 4829 }
4718 else 4830 else
4719 #endif /* XML_DTD */ 4831 #endif /* XML_DTD */
4720 result = doContent(parser, tagLevel, internalEncoding, textStart, 4832 result = doContent(parser, tagLevel, internalEncoding, textStart,
4721 textEnd, &next, XML_FALSE); 4833 textEnd, &next, XML_FALSE);
4722 4834
4723 if (result == XML_ERROR_NONE) { 4835 if (result == XML_ERROR_NONE) {
4724 if (textEnd != next && ps_parsing == XML_SUSPENDED) { 4836 if (textEnd != next && ps_parsing == XML_SUSPENDED) {
4725 entity->processed = (int)(next - textStart); 4837 entity->processed = (int)(next - textStart);
4726 processor = internalEntityProcessor; 4838 processor = internalEntityProcessor;
4727 } 4839 }
4728 else { 4840 else {
4729 entity->open = XML_FALSE; 4841 entity->open = XML_FALSE;
4730 openInternalEntities = openEntity->next; 4842 openInternalEntities = openEntity->next;
(...skipping 19 matching lines...) Expand all
4750 if (!openEntity) 4862 if (!openEntity)
4751 return XML_ERROR_UNEXPECTED_STATE; 4863 return XML_ERROR_UNEXPECTED_STATE;
4752 4864
4753 entity = openEntity->entity; 4865 entity = openEntity->entity;
4754 textStart = ((char *)entity->textPtr) + entity->processed; 4866 textStart = ((char *)entity->textPtr) + entity->processed;
4755 textEnd = (char *)(entity->textPtr + entity->textLen); 4867 textEnd = (char *)(entity->textPtr + entity->textLen);
4756 4868
4757 #ifdef XML_DTD 4869 #ifdef XML_DTD
4758 if (entity->is_param) { 4870 if (entity->is_param) {
4759 int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next); 4871 int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next);
4760 result = doProlog(parser, internalEncoding, textStart, textEnd, tok, 4872 result = doProlog(parser, internalEncoding, textStart, textEnd, tok,
4761 next, &next, XML_FALSE); 4873 next, &next, XML_FALSE);
4762 } 4874 }
4763 else 4875 else
4764 #endif /* XML_DTD */ 4876 #endif /* XML_DTD */
4765 result = doContent(parser, openEntity->startTagLevel, internalEncoding, 4877 result = doContent(parser, openEntity->startTagLevel, internalEncoding,
4766 textStart, textEnd, &next, XML_FALSE); 4878 textStart, textEnd, &next, XML_FALSE);
4767 4879
4768 if (result != XML_ERROR_NONE) 4880 if (result != XML_ERROR_NONE)
4769 return result; 4881 return result;
4770 else if (textEnd != next && ps_parsing == XML_SUSPENDED) { 4882 else if (textEnd != next && ps_parsing == XML_SUSPENDED) {
4771 entity->processed = (int)(next - (char *)entity->textPtr); 4883 entity->processed = (int)(next - (char *)entity->textPtr);
4772 return result; 4884 return result;
4773 } 4885 }
4774 else { 4886 else {
4775 entity->open = XML_FALSE; 4887 entity->open = XML_FALSE;
4776 openInternalEntities = openEntity->next; 4888 openInternalEntities = openEntity->next;
4777 /* put openEntity back in list of free instances */ 4889 /* put openEntity back in list of free instances */
4778 openEntity->next = freeInternalEntities; 4890 openEntity->next = freeInternalEntities;
4779 freeInternalEntities = openEntity; 4891 freeInternalEntities = openEntity;
4780 } 4892 }
4781 4893
4782 #ifdef XML_DTD 4894 #ifdef XML_DTD
4783 if (entity->is_param) { 4895 if (entity->is_param) {
4784 int tok; 4896 int tok;
4785 processor = prologProcessor; 4897 processor = prologProcessor;
4786 tok = XmlPrologTok(encoding, s, end, &next); 4898 tok = XmlPrologTok(encoding, s, end, &next);
4787 return doProlog(parser, encoding, s, end, tok, next, nextPtr, 4899 return doProlog(parser, encoding, s, end, tok, next, nextPtr,
4788 (XML_Bool)!ps_finalBuffer); 4900 (XML_Bool)!ps_finalBuffer);
4789 } 4901 }
4790 else 4902 else
4791 #endif /* XML_DTD */ 4903 #endif /* XML_DTD */
4792 { 4904 {
4793 processor = contentProcessor; 4905 processor = contentProcessor;
4794 /* see externalEntityContentProcessor vs contentProcessor */ 4906 /* see externalEntityContentProcessor vs contentProcessor */
4795 return doContent(parser, parentParser ? 1 : 0, encoding, s, end, 4907 return doContent(parser, parentParser ? 1 : 0, encoding, s, end,
4796 nextPtr, (XML_Bool)!ps_finalBuffer); 4908 nextPtr, (XML_Bool)!ps_finalBuffer);
4797 } 4909 }
4798 } 4910 }
4799 4911
4800 static enum XML_Error PTRCALL 4912 static enum XML_Error PTRCALL
4801 errorProcessor(XML_Parser parser, 4913 errorProcessor(XML_Parser parser,
4802 const char *s, 4914 const char *s,
4803 const char *end, 4915 const char *end,
4804 const char **nextPtr) 4916 const char **nextPtr)
4805 { 4917 {
4806 return errorCode; 4918 return errorCode;
4807 } 4919 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
4893 if (ch) { 5005 if (ch) {
4894 if (!poolAppendChar(pool, ch)) 5006 if (!poolAppendChar(pool, ch))
4895 return XML_ERROR_NO_MEMORY; 5007 return XML_ERROR_NO_MEMORY;
4896 break; 5008 break;
4897 } 5009 }
4898 name = poolStoreString(&temp2Pool, enc, 5010 name = poolStoreString(&temp2Pool, enc,
4899 ptr + enc->minBytesPerChar, 5011 ptr + enc->minBytesPerChar,
4900 next - enc->minBytesPerChar); 5012 next - enc->minBytesPerChar);
4901 if (!name) 5013 if (!name)
4902 return XML_ERROR_NO_MEMORY; 5014 return XML_ERROR_NO_MEMORY;
4903 entity = (ENTITY *)lookup(&dtd->generalEntities, name, 0); 5015 entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0);
4904 poolDiscard(&temp2Pool); 5016 poolDiscard(&temp2Pool);
4905 /* First, determine if a check for an existing declaration is needed; 5017 /* First, determine if a check for an existing declaration is needed;
4906 if yes, check that the entity exists, and that it is internal. 5018 if yes, check that the entity exists, and that it is internal.
4907 */ 5019 */
4908 if (pool == &dtd->pool) /* are we called from prolog? */ 5020 if (pool == &dtd->pool) /* are we called from prolog? */
4909 checkEntityDecl = 5021 checkEntityDecl =
4910 #ifdef XML_DTD 5022 #ifdef XML_DTD
4911 prologState.documentEntity && 5023 prologState.documentEntity &&
4912 #endif /* XML_DTD */ 5024 #endif /* XML_DTD */
4913 (dtd->standalone 5025 (dtd->standalone
(...skipping 26 matching lines...) Expand all
4940 return XML_ERROR_RECURSIVE_ENTITY_REF; 5052 return XML_ERROR_RECURSIVE_ENTITY_REF;
4941 } 5053 }
4942 if (entity->notation) { 5054 if (entity->notation) {
4943 if (enc == encoding) 5055 if (enc == encoding)
4944 eventPtr = ptr; 5056 eventPtr = ptr;
4945 return XML_ERROR_BINARY_ENTITY_REF; 5057 return XML_ERROR_BINARY_ENTITY_REF;
4946 } 5058 }
4947 if (!entity->textPtr) { 5059 if (!entity->textPtr) {
4948 if (enc == encoding) 5060 if (enc == encoding)
4949 eventPtr = ptr; 5061 eventPtr = ptr;
4950 return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF; 5062 return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF;
4951 } 5063 }
4952 else { 5064 else {
4953 enum XML_Error result; 5065 enum XML_Error result;
4954 const XML_Char *textEnd = entity->textPtr + entity->textLen; 5066 const XML_Char *textEnd = entity->textPtr + entity->textLen;
4955 entity->open = XML_TRUE; 5067 entity->open = XML_TRUE;
4956 result = appendAttributeValue(parser, internalEncoding, isCdata, 5068 result = appendAttributeValue(parser, internalEncoding, isCdata,
4957 (char *)entity->textPtr, 5069 (char *)entity->textPtr,
4958 (char *)textEnd, pool); 5070 (char *)textEnd, pool);
4959 entity->open = XML_FALSE; 5071 entity->open = XML_FALSE;
4960 if (result) 5072 if (result)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
5002 if (isParamEntity || enc != encoding) { 5114 if (isParamEntity || enc != encoding) {
5003 const XML_Char *name; 5115 const XML_Char *name;
5004 ENTITY *entity; 5116 ENTITY *entity;
5005 name = poolStoreString(&tempPool, enc, 5117 name = poolStoreString(&tempPool, enc,
5006 entityTextPtr + enc->minBytesPerChar, 5118 entityTextPtr + enc->minBytesPerChar,
5007 next - enc->minBytesPerChar); 5119 next - enc->minBytesPerChar);
5008 if (!name) { 5120 if (!name) {
5009 result = XML_ERROR_NO_MEMORY; 5121 result = XML_ERROR_NO_MEMORY;
5010 goto endEntityValue; 5122 goto endEntityValue;
5011 } 5123 }
5012 entity = (ENTITY *)lookup(&dtd->paramEntities, name, 0); 5124 entity = (ENTITY *)lookup(parser, &dtd->paramEntities, name, 0);
5013 poolDiscard(&tempPool); 5125 poolDiscard(&tempPool);
5014 if (!entity) { 5126 if (!entity) {
5015 /* not a well-formedness error - see XML 1.0: WFC Entity Declared */ 5127 /* not a well-formedness error - see XML 1.0: WFC Entity Declared */
5016 /* cannot report skipped entity here - see comments on 5128 /* cannot report skipped entity here - see comments on
5017 skippedEntityHandler 5129 skippedEntityHandler
5018 if (skippedEntityHandler) 5130 if (skippedEntityHandler)
5019 skippedEntityHandler(handlerArg, name, 0); 5131 skippedEntityHandler(handlerArg, name, 0);
5020 */ 5132 */
5021 dtd->keepProcessing = dtd->standalone; 5133 dtd->keepProcessing = dtd->standalone;
5022 goto endEntityValue; 5134 goto endEntityValue;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
5292 for (name = elementType->name; *name; name++) { 5404 for (name = elementType->name; *name; name++) {
5293 if (*name == XML_T(ASCII_COLON)) { 5405 if (*name == XML_T(ASCII_COLON)) {
5294 PREFIX *prefix; 5406 PREFIX *prefix;
5295 const XML_Char *s; 5407 const XML_Char *s;
5296 for (s = elementType->name; s != name; s++) { 5408 for (s = elementType->name; s != name; s++) {
5297 if (!poolAppendChar(&dtd->pool, *s)) 5409 if (!poolAppendChar(&dtd->pool, *s))
5298 return 0; 5410 return 0;
5299 } 5411 }
5300 if (!poolAppendChar(&dtd->pool, XML_T('\0'))) 5412 if (!poolAppendChar(&dtd->pool, XML_T('\0')))
5301 return 0; 5413 return 0;
5302 prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&dtd->pool), 5414 prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd->pool),
5303 sizeof(PREFIX)); 5415 sizeof(PREFIX));
5304 if (!prefix) 5416 if (!prefix)
5305 return 0; 5417 return 0;
5306 if (prefix->name == poolStart(&dtd->pool)) 5418 if (prefix->name == poolStart(&dtd->pool))
5307 poolFinish(&dtd->pool); 5419 poolFinish(&dtd->pool);
5308 else 5420 else
5309 poolDiscard(&dtd->pool); 5421 poolDiscard(&dtd->pool);
5310 elementType->prefix = prefix; 5422 elementType->prefix = prefix;
5311 5423
5312 } 5424 }
5313 } 5425 }
5314 return 1; 5426 return 1;
5315 } 5427 }
5316 5428
5317 static ATTRIBUTE_ID * 5429 static ATTRIBUTE_ID *
5318 getAttributeId(XML_Parser parser, const ENCODING *enc, 5430 getAttributeId(XML_Parser parser, const ENCODING *enc,
5319 const char *start, const char *end) 5431 const char *start, const char *end)
5320 { 5432 {
5321 DTD * const dtd = _dtd; /* save one level of indirection */ 5433 DTD * const dtd = _dtd; /* save one level of indirection */
5322 ATTRIBUTE_ID *id; 5434 ATTRIBUTE_ID *id;
5323 const XML_Char *name; 5435 const XML_Char *name;
5324 if (!poolAppendChar(&dtd->pool, XML_T('\0'))) 5436 if (!poolAppendChar(&dtd->pool, XML_T('\0')))
5325 return NULL; 5437 return NULL;
5326 name = poolStoreString(&dtd->pool, enc, start, end); 5438 name = poolStoreString(&dtd->pool, enc, start, end);
5327 if (!name) 5439 if (!name)
5328 return NULL; 5440 return NULL;
5329 /* skip quotation mark - its storage will be re-used (like in name[-1]) */ 5441 /* skip quotation mark - its storage will be re-used (like in name[-1]) */
5330 ++name; 5442 ++name;
5331 id = (ATTRIBUTE_ID *)lookup(&dtd->attributeIds, name, sizeof(ATTRIBUTE_ID)); 5443 id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, name, sizeof(ATTRIBUTE _ID));
5332 if (!id) 5444 if (!id)
5333 return NULL; 5445 return NULL;
5334 if (id->name != name) 5446 if (id->name != name)
5335 poolDiscard(&dtd->pool); 5447 poolDiscard(&dtd->pool);
5336 else { 5448 else {
5337 poolFinish(&dtd->pool); 5449 poolFinish(&dtd->pool);
5338 if (!ns) 5450 if (!ns)
5339 ; 5451 ;
5340 else if (name[0] == XML_T(ASCII_x) 5452 else if (name[0] == XML_T(ASCII_x)
5341 && name[1] == XML_T(ASCII_m) 5453 && name[1] == XML_T(ASCII_m)
5342 && name[2] == XML_T(ASCII_l) 5454 && name[2] == XML_T(ASCII_l)
5343 && name[3] == XML_T(ASCII_n) 5455 && name[3] == XML_T(ASCII_n)
5344 && name[4] == XML_T(ASCII_s) 5456 && name[4] == XML_T(ASCII_s)
5345 && (name[5] == XML_T('\0') || name[5] == XML_T(ASCII_COLON))) { 5457 && (name[5] == XML_T('\0') || name[5] == XML_T(ASCII_COLON))) {
5346 if (name[5] == XML_T('\0')) 5458 if (name[5] == XML_T('\0'))
5347 id->prefix = &dtd->defaultPrefix; 5459 id->prefix = &dtd->defaultPrefix;
5348 else 5460 else
5349 id->prefix = (PREFIX *)lookup(&dtd->prefixes, name + 6, sizeof(PREFIX)); 5461 id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, name + 6, sizeof(P REFIX));
5350 id->xmlns = XML_TRUE; 5462 id->xmlns = XML_TRUE;
5351 } 5463 }
5352 else { 5464 else {
5353 int i; 5465 int i;
5354 for (i = 0; name[i]; i++) { 5466 for (i = 0; name[i]; i++) {
5355 /* attributes without prefix are *not* in the default namespace */ 5467 /* attributes without prefix are *not* in the default namespace */
5356 if (name[i] == XML_T(ASCII_COLON)) { 5468 if (name[i] == XML_T(ASCII_COLON)) {
5357 int j; 5469 int j;
5358 for (j = 0; j < i; j++) { 5470 for (j = 0; j < i; j++) {
5359 if (!poolAppendChar(&dtd->pool, name[j])) 5471 if (!poolAppendChar(&dtd->pool, name[j]))
5360 return NULL; 5472 return NULL;
5361 } 5473 }
5362 if (!poolAppendChar(&dtd->pool, XML_T('\0'))) 5474 if (!poolAppendChar(&dtd->pool, XML_T('\0')))
5363 return NULL; 5475 return NULL;
5364 id->prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&dtd->pool), 5476 id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd-> pool),
5365 sizeof(PREFIX)); 5477 sizeof(PREFIX));
5366 if (id->prefix->name == poolStart(&dtd->pool)) 5478 if (id->prefix->name == poolStart(&dtd->pool))
5367 poolFinish(&dtd->pool); 5479 poolFinish(&dtd->pool);
5368 else 5480 else
5369 poolDiscard(&dtd->pool); 5481 poolDiscard(&dtd->pool);
5370 break; 5482 break;
5371 } 5483 }
5372 } 5484 }
5373 } 5485 }
5374 } 5486 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
5450 setContext(XML_Parser parser, const XML_Char *context) 5562 setContext(XML_Parser parser, const XML_Char *context)
5451 { 5563 {
5452 DTD * const dtd = _dtd; /* save one level of indirection */ 5564 DTD * const dtd = _dtd; /* save one level of indirection */
5453 const XML_Char *s = context; 5565 const XML_Char *s = context;
5454 5566
5455 while (*context != XML_T('\0')) { 5567 while (*context != XML_T('\0')) {
5456 if (*s == CONTEXT_SEP || *s == XML_T('\0')) { 5568 if (*s == CONTEXT_SEP || *s == XML_T('\0')) {
5457 ENTITY *e; 5569 ENTITY *e;
5458 if (!poolAppendChar(&tempPool, XML_T('\0'))) 5570 if (!poolAppendChar(&tempPool, XML_T('\0')))
5459 return XML_FALSE; 5571 return XML_FALSE;
5460 e = (ENTITY *)lookup(&dtd->generalEntities, poolStart(&tempPool), 0); 5572 e = (ENTITY *)lookup(parser, &dtd->generalEntities, poolStart(&tempPool), 0);
5461 if (e) 5573 if (e)
5462 e->open = XML_TRUE; 5574 e->open = XML_TRUE;
5463 if (*s != XML_T('\0')) 5575 if (*s != XML_T('\0'))
5464 s++; 5576 s++;
5465 context = s; 5577 context = s;
5466 poolDiscard(&tempPool); 5578 poolDiscard(&tempPool);
5467 } 5579 }
5468 else if (*s == XML_T(ASCII_EQUALS)) { 5580 else if (*s == XML_T(ASCII_EQUALS)) {
5469 PREFIX *prefix; 5581 PREFIX *prefix;
5470 if (poolLength(&tempPool) == 0) 5582 if (poolLength(&tempPool) == 0)
5471 prefix = &dtd->defaultPrefix; 5583 prefix = &dtd->defaultPrefix;
5472 else { 5584 else {
5473 if (!poolAppendChar(&tempPool, XML_T('\0'))) 5585 if (!poolAppendChar(&tempPool, XML_T('\0')))
5474 return XML_FALSE; 5586 return XML_FALSE;
5475 prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&tempPool), 5587 prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&tempPool),
5476 sizeof(PREFIX)); 5588 sizeof(PREFIX));
5477 if (!prefix) 5589 if (!prefix)
5478 return XML_FALSE; 5590 return XML_FALSE;
5479 if (prefix->name == poolStart(&tempPool)) { 5591 if (prefix->name == poolStart(&tempPool)) {
5480 prefix->name = poolCopyString(&dtd->pool, prefix->name); 5592 prefix->name = poolCopyString(&dtd->pool, prefix->name);
5481 if (!prefix->name) 5593 if (!prefix->name)
5482 return XML_FALSE; 5594 return XML_FALSE;
5483 } 5595 }
5484 poolDiscard(&tempPool); 5596 poolDiscard(&tempPool);
5485 } 5597 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
5629 ms->free_fcn(p->scaffIndex); 5741 ms->free_fcn(p->scaffIndex);
5630 ms->free_fcn(p->scaffold); 5742 ms->free_fcn(p->scaffold);
5631 } 5743 }
5632 ms->free_fcn(p); 5744 ms->free_fcn(p);
5633 } 5745 }
5634 5746
5635 /* Do a deep copy of the DTD. Return 0 for out of memory, non-zero otherwise. 5747 /* Do a deep copy of the DTD. Return 0 for out of memory, non-zero otherwise.
5636 The new DTD has already been initialized. 5748 The new DTD has already been initialized.
5637 */ 5749 */
5638 static int 5750 static int
5639 dtdCopy(DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms) 5751 dtdCopy(XML_Parser oldParser, DTD *newDtd, const DTD *oldDtd, const XML_Memory_H andling_Suite *ms)
5640 { 5752 {
5641 HASH_TABLE_ITER iter; 5753 HASH_TABLE_ITER iter;
5642 5754
5643 /* Copy the prefix table. */ 5755 /* Copy the prefix table. */
5644 5756
5645 hashTableIterInit(&iter, &(oldDtd->prefixes)); 5757 hashTableIterInit(&iter, &(oldDtd->prefixes));
5646 for (;;) { 5758 for (;;) {
5647 const XML_Char *name; 5759 const XML_Char *name;
5648 const PREFIX *oldP = (PREFIX *)hashTableIterNext(&iter); 5760 const PREFIX *oldP = (PREFIX *)hashTableIterNext(&iter);
5649 if (!oldP) 5761 if (!oldP)
5650 break; 5762 break;
5651 name = poolCopyString(&(newDtd->pool), oldP->name); 5763 name = poolCopyString(&(newDtd->pool), oldP->name);
5652 if (!name) 5764 if (!name)
5653 return 0; 5765 return 0;
5654 if (!lookup(&(newDtd->prefixes), name, sizeof(PREFIX))) 5766 if (!lookup(oldParser, &(newDtd->prefixes), name, sizeof(PREFIX)))
5655 return 0; 5767 return 0;
5656 } 5768 }
5657 5769
5658 hashTableIterInit(&iter, &(oldDtd->attributeIds)); 5770 hashTableIterInit(&iter, &(oldDtd->attributeIds));
5659 5771
5660 /* Copy the attribute id table. */ 5772 /* Copy the attribute id table. */
5661 5773
5662 for (;;) { 5774 for (;;) {
5663 ATTRIBUTE_ID *newA; 5775 ATTRIBUTE_ID *newA;
5664 const XML_Char *name; 5776 const XML_Char *name;
5665 const ATTRIBUTE_ID *oldA = (ATTRIBUTE_ID *)hashTableIterNext(&iter); 5777 const ATTRIBUTE_ID *oldA = (ATTRIBUTE_ID *)hashTableIterNext(&iter);
5666 5778
5667 if (!oldA) 5779 if (!oldA)
5668 break; 5780 break;
5669 /* Remember to allocate the scratch byte before the name. */ 5781 /* Remember to allocate the scratch byte before the name. */
5670 if (!poolAppendChar(&(newDtd->pool), XML_T('\0'))) 5782 if (!poolAppendChar(&(newDtd->pool), XML_T('\0')))
5671 return 0; 5783 return 0;
5672 name = poolCopyString(&(newDtd->pool), oldA->name); 5784 name = poolCopyString(&(newDtd->pool), oldA->name);
5673 if (!name) 5785 if (!name)
5674 return 0; 5786 return 0;
5675 ++name; 5787 ++name;
5676 newA = (ATTRIBUTE_ID *)lookup(&(newDtd->attributeIds), name, 5788 newA = (ATTRIBUTE_ID *)lookup(oldParser, &(newDtd->attributeIds), name,
5677 sizeof(ATTRIBUTE_ID)); 5789 sizeof(ATTRIBUTE_ID));
5678 if (!newA) 5790 if (!newA)
5679 return 0; 5791 return 0;
5680 newA->maybeTokenized = oldA->maybeTokenized; 5792 newA->maybeTokenized = oldA->maybeTokenized;
5681 if (oldA->prefix) { 5793 if (oldA->prefix) {
5682 newA->xmlns = oldA->xmlns; 5794 newA->xmlns = oldA->xmlns;
5683 if (oldA->prefix == &oldDtd->defaultPrefix) 5795 if (oldA->prefix == &oldDtd->defaultPrefix)
5684 newA->prefix = &newDtd->defaultPrefix; 5796 newA->prefix = &newDtd->defaultPrefix;
5685 else 5797 else
5686 newA->prefix = (PREFIX *)lookup(&(newDtd->prefixes), 5798 newA->prefix = (PREFIX *)lookup(oldParser, &(newDtd->prefixes),
5687 oldA->prefix->name, 0); 5799 oldA->prefix->name, 0);
5688 } 5800 }
5689 } 5801 }
5690 5802
5691 /* Copy the element type table. */ 5803 /* Copy the element type table. */
5692 5804
5693 hashTableIterInit(&iter, &(oldDtd->elementTypes)); 5805 hashTableIterInit(&iter, &(oldDtd->elementTypes));
5694 5806
5695 for (;;) { 5807 for (;;) {
5696 int i; 5808 int i;
5697 ELEMENT_TYPE *newE; 5809 ELEMENT_TYPE *newE;
5698 const XML_Char *name; 5810 const XML_Char *name;
5699 const ELEMENT_TYPE *oldE = (ELEMENT_TYPE *)hashTableIterNext(&iter); 5811 const ELEMENT_TYPE *oldE = (ELEMENT_TYPE *)hashTableIterNext(&iter);
5700 if (!oldE) 5812 if (!oldE)
5701 break; 5813 break;
5702 name = poolCopyString(&(newDtd->pool), oldE->name); 5814 name = poolCopyString(&(newDtd->pool), oldE->name);
5703 if (!name) 5815 if (!name)
5704 return 0; 5816 return 0;
5705 newE = (ELEMENT_TYPE *)lookup(&(newDtd->elementTypes), name, 5817 newE = (ELEMENT_TYPE *)lookup(oldParser, &(newDtd->elementTypes), name,
5706 sizeof(ELEMENT_TYPE)); 5818 sizeof(ELEMENT_TYPE));
5707 if (!newE) 5819 if (!newE)
5708 return 0; 5820 return 0;
5709 if (oldE->nDefaultAtts) { 5821 if (oldE->nDefaultAtts) {
5710 newE->defaultAtts = (DEFAULT_ATTRIBUTE *) 5822 newE->defaultAtts = (DEFAULT_ATTRIBUTE *)
5711 ms->malloc_fcn(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); 5823 ms->malloc_fcn(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE));
5712 if (!newE->defaultAtts) { 5824 if (!newE->defaultAtts) {
5713 ms->free_fcn(newE); 5825 ms->free_fcn(newE);
5714 return 0; 5826 return 0;
5715 } 5827 }
5716 } 5828 }
5717 if (oldE->idAtt) 5829 if (oldE->idAtt)
5718 newE->idAtt = (ATTRIBUTE_ID *) 5830 newE->idAtt = (ATTRIBUTE_ID *)
5719 lookup(&(newDtd->attributeIds), oldE->idAtt->name, 0); 5831 lookup(oldParser, &(newDtd->attributeIds), oldE->idAtt->name, 0);
5720 newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts; 5832 newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts;
5721 if (oldE->prefix) 5833 if (oldE->prefix)
5722 newE->prefix = (PREFIX *)lookup(&(newDtd->prefixes), 5834 newE->prefix = (PREFIX *)lookup(oldParser, &(newDtd->prefixes),
5723 oldE->prefix->name, 0); 5835 oldE->prefix->name, 0);
5724 for (i = 0; i < newE->nDefaultAtts; i++) { 5836 for (i = 0; i < newE->nDefaultAtts; i++) {
5725 newE->defaultAtts[i].id = (ATTRIBUTE_ID *) 5837 newE->defaultAtts[i].id = (ATTRIBUTE_ID *)
5726 lookup(&(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0); 5838 lookup(oldParser, &(newDtd->attributeIds), oldE->defaultAtts[i].id->na me, 0);
5727 newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata; 5839 newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata;
5728 if (oldE->defaultAtts[i].value) { 5840 if (oldE->defaultAtts[i].value) {
5729 newE->defaultAtts[i].value 5841 newE->defaultAtts[i].value
5730 = poolCopyString(&(newDtd->pool), oldE->defaultAtts[i].value); 5842 = poolCopyString(&(newDtd->pool), oldE->defaultAtts[i].value);
5731 if (!newE->defaultAtts[i].value) 5843 if (!newE->defaultAtts[i].value)
5732 return 0; 5844 return 0;
5733 } 5845 }
5734 else 5846 else
5735 newE->defaultAtts[i].value = NULL; 5847 newE->defaultAtts[i].value = NULL;
5736 } 5848 }
5737 } 5849 }
5738 5850
5739 /* Copy the entity tables. */ 5851 /* Copy the entity tables. */
5740 if (!copyEntityTable(&(newDtd->generalEntities), 5852 if (!copyEntityTable(oldParser,
5853 &(newDtd->generalEntities),
5741 &(newDtd->pool), 5854 &(newDtd->pool),
5742 &(oldDtd->generalEntities))) 5855 &(oldDtd->generalEntities)))
5743 return 0; 5856 return 0;
5744 5857
5745 #ifdef XML_DTD 5858 #ifdef XML_DTD
5746 if (!copyEntityTable(&(newDtd->paramEntities), 5859 if (!copyEntityTable(oldParser,
5860 &(newDtd->paramEntities),
5747 &(newDtd->pool), 5861 &(newDtd->pool),
5748 &(oldDtd->paramEntities))) 5862 &(oldDtd->paramEntities)))
5749 return 0; 5863 return 0;
5750 newDtd->paramEntityRead = oldDtd->paramEntityRead; 5864 newDtd->paramEntityRead = oldDtd->paramEntityRead;
5751 #endif /* XML_DTD */ 5865 #endif /* XML_DTD */
5752 5866
5753 newDtd->keepProcessing = oldDtd->keepProcessing; 5867 newDtd->keepProcessing = oldDtd->keepProcessing;
5754 newDtd->hasParamEntityRefs = oldDtd->hasParamEntityRefs; 5868 newDtd->hasParamEntityRefs = oldDtd->hasParamEntityRefs;
5755 newDtd->standalone = oldDtd->standalone; 5869 newDtd->standalone = oldDtd->standalone;
5756 5870
5757 /* Don't want deep copying for scaffolding */ 5871 /* Don't want deep copying for scaffolding */
5758 newDtd->in_eldecl = oldDtd->in_eldecl; 5872 newDtd->in_eldecl = oldDtd->in_eldecl;
5759 newDtd->scaffold = oldDtd->scaffold; 5873 newDtd->scaffold = oldDtd->scaffold;
5760 newDtd->contentStringLen = oldDtd->contentStringLen; 5874 newDtd->contentStringLen = oldDtd->contentStringLen;
5761 newDtd->scaffSize = oldDtd->scaffSize; 5875 newDtd->scaffSize = oldDtd->scaffSize;
5762 newDtd->scaffLevel = oldDtd->scaffLevel; 5876 newDtd->scaffLevel = oldDtd->scaffLevel;
5763 newDtd->scaffIndex = oldDtd->scaffIndex; 5877 newDtd->scaffIndex = oldDtd->scaffIndex;
5764 5878
5765 return 1; 5879 return 1;
5766 } /* End dtdCopy */ 5880 } /* End dtdCopy */
5767 5881
5768 static int 5882 static int
5769 copyEntityTable(HASH_TABLE *newTable, 5883 copyEntityTable(XML_Parser oldParser,
5884 HASH_TABLE *newTable,
5770 STRING_POOL *newPool, 5885 STRING_POOL *newPool,
5771 const HASH_TABLE *oldTable) 5886 const HASH_TABLE *oldTable)
5772 { 5887 {
5773 HASH_TABLE_ITER iter; 5888 HASH_TABLE_ITER iter;
5774 const XML_Char *cachedOldBase = NULL; 5889 const XML_Char *cachedOldBase = NULL;
5775 const XML_Char *cachedNewBase = NULL; 5890 const XML_Char *cachedNewBase = NULL;
5776 5891
5777 hashTableIterInit(&iter, oldTable); 5892 hashTableIterInit(&iter, oldTable);
5778 5893
5779 for (;;) { 5894 for (;;) {
5780 ENTITY *newE; 5895 ENTITY *newE;
5781 const XML_Char *name; 5896 const XML_Char *name;
5782 const ENTITY *oldE = (ENTITY *)hashTableIterNext(&iter); 5897 const ENTITY *oldE = (ENTITY *)hashTableIterNext(&iter);
5783 if (!oldE) 5898 if (!oldE)
5784 break; 5899 break;
5785 name = poolCopyString(newPool, oldE->name); 5900 name = poolCopyString(newPool, oldE->name);
5786 if (!name) 5901 if (!name)
5787 return 0; 5902 return 0;
5788 newE = (ENTITY *)lookup(newTable, name, sizeof(ENTITY)); 5903 newE = (ENTITY *)lookup(oldParser, newTable, name, sizeof(ENTITY));
5789 if (!newE) 5904 if (!newE)
5790 return 0; 5905 return 0;
5791 if (oldE->systemId) { 5906 if (oldE->systemId) {
5792 const XML_Char *tem = poolCopyString(newPool, oldE->systemId); 5907 const XML_Char *tem = poolCopyString(newPool, oldE->systemId);
5793 if (!tem) 5908 if (!tem)
5794 return 0; 5909 return 0;
5795 newE->systemId = tem; 5910 newE->systemId = tem;
5796 if (oldE->base) { 5911 if (oldE->base) {
5797 if (oldE->base == cachedOldBase) 5912 if (oldE->base == cachedOldBase)
5798 newE->base = cachedNewBase; 5913 newE->base = cachedNewBase;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
5836 static XML_Bool FASTCALL 5951 static XML_Bool FASTCALL
5837 keyeq(KEY s1, KEY s2) 5952 keyeq(KEY s1, KEY s2)
5838 { 5953 {
5839 for (; *s1 == *s2; s1++, s2++) 5954 for (; *s1 == *s2; s1++, s2++)
5840 if (*s1 == 0) 5955 if (*s1 == 0)
5841 return XML_TRUE; 5956 return XML_TRUE;
5842 return XML_FALSE; 5957 return XML_FALSE;
5843 } 5958 }
5844 5959
5845 static unsigned long FASTCALL 5960 static unsigned long FASTCALL
5846 hash(KEY s) 5961 hash(XML_Parser parser, KEY s)
5847 { 5962 {
5848 unsigned long h = 0; 5963 unsigned long h = hash_secret_salt;
5849 while (*s) 5964 while (*s)
5850 h = CHAR_HASH(h, *s++); 5965 h = CHAR_HASH(h, *s++);
5851 return h; 5966 return h;
5852 } 5967 }
5853 5968
5854 static NAMED * 5969 static NAMED *
5855 lookup(HASH_TABLE *table, KEY name, size_t createSize) 5970 lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize)
5856 { 5971 {
5857 size_t i; 5972 size_t i;
5858 if (table->size == 0) { 5973 if (table->size == 0) {
5859 size_t tsize; 5974 size_t tsize;
5860 if (!createSize) 5975 if (!createSize)
5861 return NULL; 5976 return NULL;
5862 table->power = INIT_POWER; 5977 table->power = INIT_POWER;
5863 /* table->size is a power of 2 */ 5978 /* table->size is a power of 2 */
5864 table->size = (size_t)1 << INIT_POWER; 5979 table->size = (size_t)1 << INIT_POWER;
5865 tsize = table->size * sizeof(NAMED *); 5980 tsize = table->size * sizeof(NAMED *);
5866 table->v = (NAMED **)table->mem->malloc_fcn(tsize); 5981 table->v = (NAMED **)table->mem->malloc_fcn(tsize);
5867 if (!table->v) { 5982 if (!table->v) {
5868 table->size = 0; 5983 table->size = 0;
5869 return NULL; 5984 return NULL;
5870 } 5985 }
5871 memset(table->v, 0, tsize); 5986 memset(table->v, 0, tsize);
5872 i = hash(name) & ((unsigned long)table->size - 1); 5987 i = hash(parser, name) & ((unsigned long)table->size - 1);
5873 } 5988 }
5874 else { 5989 else {
5875 unsigned long h = hash(name); 5990 unsigned long h = hash(parser, name);
5876 unsigned long mask = (unsigned long)table->size - 1; 5991 unsigned long mask = (unsigned long)table->size - 1;
5877 unsigned char step = 0; 5992 unsigned char step = 0;
5878 i = h & mask; 5993 i = h & mask;
5879 while (table->v[i]) { 5994 while (table->v[i]) {
5880 if (keyeq(name, table->v[i]->name)) 5995 if (keyeq(name, table->v[i]->name))
5881 return table->v[i]; 5996 return table->v[i];
5882 if (!step) 5997 if (!step)
5883 step = PROBE_STEP(h, mask, table->power); 5998 step = PROBE_STEP(h, mask, table->power);
5884 i < step ? (i += table->size - step) : (i -= step); 5999 i < step ? (i += table->size - step) : (i -= step);
5885 } 6000 }
5886 if (!createSize) 6001 if (!createSize)
5887 return NULL; 6002 return NULL;
5888 6003
5889 /* check for overflow (table is half full) */ 6004 /* check for overflow (table is half full) */
5890 if (table->used >> (table->power - 1)) { 6005 if (table->used >> (table->power - 1)) {
5891 unsigned char newPower = table->power + 1; 6006 unsigned char newPower = table->power + 1;
5892 size_t newSize = (size_t)1 << newPower; 6007 size_t newSize = (size_t)1 << newPower;
5893 unsigned long newMask = (unsigned long)newSize - 1; 6008 unsigned long newMask = (unsigned long)newSize - 1;
5894 size_t tsize = newSize * sizeof(NAMED *); 6009 size_t tsize = newSize * sizeof(NAMED *);
5895 NAMED **newV = (NAMED **)table->mem->malloc_fcn(tsize); 6010 NAMED **newV = (NAMED **)table->mem->malloc_fcn(tsize);
5896 if (!newV) 6011 if (!newV)
5897 return NULL; 6012 return NULL;
5898 memset(newV, 0, tsize); 6013 memset(newV, 0, tsize);
5899 for (i = 0; i < table->size; i++) 6014 for (i = 0; i < table->size; i++)
5900 if (table->v[i]) { 6015 if (table->v[i]) {
5901 unsigned long newHash = hash(table->v[i]->name); 6016 unsigned long newHash = hash(parser, table->v[i]->name);
5902 size_t j = newHash & newMask; 6017 size_t j = newHash & newMask;
5903 step = 0; 6018 step = 0;
5904 while (newV[j]) { 6019 while (newV[j]) {
5905 if (!step) 6020 if (!step)
5906 step = PROBE_STEP(newHash, newMask, newPower); 6021 step = PROBE_STEP(newHash, newMask, newPower);
5907 j < step ? (j += newSize - step) : (j -= step); 6022 j < step ? (j += newSize - step) : (j -= step);
5908 } 6023 }
5909 newV[j] = table->v[i]; 6024 newV[j] = table->v[i];
5910 } 6025 }
5911 table->mem->free_fcn(table->v); 6026 table->mem->free_fcn(table->v);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
6112 memcpy(pool->blocks->s, pool->start, 6227 memcpy(pool->blocks->s, pool->start,
6113 (pool->end - pool->start) * sizeof(XML_Char)); 6228 (pool->end - pool->start) * sizeof(XML_Char));
6114 pool->ptr = pool->blocks->s + (pool->ptr - pool->start); 6229 pool->ptr = pool->blocks->s + (pool->ptr - pool->start);
6115 pool->start = pool->blocks->s; 6230 pool->start = pool->blocks->s;
6116 pool->end = pool->start + pool->blocks->size; 6231 pool->end = pool->start + pool->blocks->size;
6117 return XML_TRUE; 6232 return XML_TRUE;
6118 } 6233 }
6119 } 6234 }
6120 if (pool->blocks && pool->start == pool->blocks->s) { 6235 if (pool->blocks && pool->start == pool->blocks->s) {
6121 int blockSize = (int)(pool->end - pool->start)*2; 6236 int blockSize = (int)(pool->end - pool->start)*2;
6122 pool->blocks = (BLOCK *) 6237 BLOCK *temp = (BLOCK *)
6123 pool->mem->realloc_fcn(pool->blocks, 6238 pool->mem->realloc_fcn(pool->blocks,
6124 (offsetof(BLOCK, s) 6239 (offsetof(BLOCK, s)
6125 + blockSize * sizeof(XML_Char))); 6240 + blockSize * sizeof(XML_Char)));
6126 if (pool->blocks == NULL) 6241 if (temp == NULL)
6127 return XML_FALSE; 6242 return XML_FALSE;
6243 pool->blocks = temp;
6128 pool->blocks->size = blockSize; 6244 pool->blocks->size = blockSize;
6129 pool->ptr = pool->blocks->s + (pool->ptr - pool->start); 6245 pool->ptr = pool->blocks->s + (pool->ptr - pool->start);
6130 pool->start = pool->blocks->s; 6246 pool->start = pool->blocks->s;
6131 pool->end = pool->start + blockSize; 6247 pool->end = pool->start + blockSize;
6132 } 6248 }
6133 else { 6249 else {
6134 BLOCK *tem; 6250 BLOCK *tem;
6135 int blockSize = (int)(pool->end - pool->start); 6251 int blockSize = (int)(pool->end - pool->start);
6136 if (blockSize < INIT_BLOCK_SIZE) 6252 if (blockSize < INIT_BLOCK_SIZE)
6137 blockSize = INIT_BLOCK_SIZE; 6253 blockSize = INIT_BLOCK_SIZE;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
6266 const ENCODING *enc, 6382 const ENCODING *enc,
6267 const char *ptr, 6383 const char *ptr,
6268 const char *end) 6384 const char *end)
6269 { 6385 {
6270 DTD * const dtd = _dtd; /* save one level of indirection */ 6386 DTD * const dtd = _dtd; /* save one level of indirection */
6271 const XML_Char *name = poolStoreString(&dtd->pool, enc, ptr, end); 6387 const XML_Char *name = poolStoreString(&dtd->pool, enc, ptr, end);
6272 ELEMENT_TYPE *ret; 6388 ELEMENT_TYPE *ret;
6273 6389
6274 if (!name) 6390 if (!name)
6275 return NULL; 6391 return NULL;
6276 ret = (ELEMENT_TYPE *) lookup(&dtd->elementTypes, name, sizeof(ELEMENT_TYPE)); 6392 ret = (ELEMENT_TYPE *) lookup(parser, &dtd->elementTypes, name, sizeof(ELEMENT _TYPE));
6277 if (!ret) 6393 if (!ret)
6278 return NULL; 6394 return NULL;
6279 if (ret->name != name) 6395 if (ret->name != name)
6280 poolDiscard(&dtd->pool); 6396 poolDiscard(&dtd->pool);
6281 else { 6397 else {
6282 poolFinish(&dtd->pool); 6398 poolFinish(&dtd->pool);
6283 if (!setElementTypePrefix(parser, ret)) 6399 if (!setElementTypePrefix(parser, ret))
6284 return NULL; 6400 return NULL;
6285 } 6401 }
6286 return ret; 6402 return ret;
6287 } 6403 }
OLDNEW
« no previous file with comments | « third_party/expat/files/lib/expat_config.h ('k') | third_party/expat/files/lib/xmlrole.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698