9 #define XML_BUILDING_EXPAT 1
11 #ifdef COMPILED_FROM_DSP
13 #elif defined(MACOS_CLASSIC)
15 #elif defined(__amigaos4__)
17 #elif defined(__WATCOMC__)
18 #include "watcomconfig.h"
19 #elif defined(HAVE_EXPAT_CONFIG_H)
27 #define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX
28 #define XmlConvert XmlUtf16Convert
29 #define XmlGetInternalEncoding XmlGetUtf16InternalEncoding
30 #define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS
31 #define XmlEncode XmlUtf16Encode
33 #define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((char *)(s) - (char *)NULL) & 1))
34 typedef unsigned short ICHAR;
36 #define XML_ENCODE_MAX XML_UTF8_ENCODE_MAX
37 #define XmlConvert XmlUtf8Convert
38 #define XmlGetInternalEncoding XmlGetUtf8InternalEncoding
39 #define XmlGetInternalEncodingNS XmlGetUtf8InternalEncodingNS
40 #define XmlEncode XmlUtf8Encode
41 #define MUST_CONVERT(enc, s) (!(enc)->isUtf8)
48 #define XmlInitEncodingNS XmlInitEncoding
49 #define XmlInitUnknownEncodingNS XmlInitUnknownEncoding
50 #undef XmlGetInternalEncodingNS
51 #define XmlGetInternalEncodingNS XmlGetInternalEncoding
52 #define XmlParseXmlDeclNS XmlParseXmlDecl
58 #ifdef XML_UNICODE_WCHAR_T
59 #define XML_T(x) (const wchar_t)x
60 #define XML_L(x) L ## x
62 #define XML_T(x) (const unsigned short)x
74 #define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))
79 #define memmove(d,s,l) bcopy((s),(d),(l))
81 #error memmove does not exist on this platform, nor is a substitute available
108 #define CHAR_HASH(h, c) \
109 (((h) * 0xF4243) ^ (unsigned short)(c))
111 #define CHAR_HASH(h, c) \
112 (((h) * 0xF4243) ^ (unsigned char)(c))
123 #define SECOND_HASH(hash, mask, power) \
124 ((((hash) & ~(mask)) >> ((power) - 1)) & ((mask) >> 2))
125 #define PROBE_STEP(hash, mask, power) \
126 ((unsigned char)((SECOND_HASH(hash, mask, power)) | 1))
133 #define INIT_TAG_BUF_SIZE 32
134 #define INIT_DATA_BUF_SIZE 1024
135 #define INIT_ATTS_SIZE 16
136 #define INIT_ATTS_VERSION 0xFFFFFFFF
137 #define INIT_BLOCK_SIZE 1024
138 #define INIT_BUFFER_SIZE 1024
140 #define EXPAND_SPARE 24
213 #define INIT_SCAFFOLD_ELEMENTS 32
301 const char **endPtr);
309 static Processor externalParEntProcessor;
310 static Processor externalParEntInitProcessor;
312 static Processor entityValueInitProcessor;
316 static Processor externalEntityInitProcessor;
317 static Processor externalEntityInitProcessor2;
318 static Processor externalEntityInitProcessor3;
319 static Processor externalEntityContentProcessor;
320 static Processor internalEntityProcessor;
325 processXmlDecl(
XML_Parser parser,
int isGeneralTextEntity,
326 const char *
s,
const char *
next);
331 const char *end,
int tok,
const char *
next,
const char **nextPtr,
338 const char *start,
const char *end,
const char **endPtr,
342 const char *end,
const char **nextPtr,
XML_Bool haveMore);
346 const char *end,
const char **nextPtr,
XML_Bool haveMore);
374 const char *start,
const char *end);
414 const char *ptr,
const char *end);
417 const char *ptr,
const char *end);
430 const char *ptr,
const char *end);
433 parserCreate(
const XML_Char *encodingName,
440 #define poolStart(pool) ((pool)->start)
441 #define poolEnd(pool) ((pool)->ptr)
442 #define poolLength(pool) ((pool)->ptr - (pool)->start)
443 #define poolChop(pool) ((void)--(pool->ptr))
444 #define poolLastChar(pool) (((pool)->ptr)[-1])
445 #define poolDiscard(pool) ((pool)->ptr = (pool)->start)
446 #define poolFinish(pool) ((pool)->start = (pool)->ptr)
447 #define poolAppendChar(pool, c) \
448 (((pool)->ptr == (pool)->end && !poolGrow(pool)) \
450 : ((*((pool)->ptr)++ = c), 1))
551 #define MALLOC(s) (parser->m_mem.malloc_fcn((s)))
552 #define REALLOC(p,s) (parser->m_mem.realloc_fcn((p),(s)))
553 #define FREE(p) (parser->m_mem.free_fcn((p)))
555 #define userData (parser->m_userData)
556 #define handlerArg (parser->m_handlerArg)
557 #define startElementHandler (parser->m_startElementHandler)
558 #define endElementHandler (parser->m_endElementHandler)
559 #define characterDataHandler (parser->m_characterDataHandler)
560 #define processingInstructionHandler \
561 (parser->m_processingInstructionHandler)
562 #define commentHandler (parser->m_commentHandler)
563 #define startCdataSectionHandler \
564 (parser->m_startCdataSectionHandler)
565 #define endCdataSectionHandler (parser->m_endCdataSectionHandler)
566 #define defaultHandler (parser->m_defaultHandler)
567 #define startDoctypeDeclHandler (parser->m_startDoctypeDeclHandler)
568 #define endDoctypeDeclHandler (parser->m_endDoctypeDeclHandler)
569 #define unparsedEntityDeclHandler \
570 (parser->m_unparsedEntityDeclHandler)
571 #define notationDeclHandler (parser->m_notationDeclHandler)
572 #define startNamespaceDeclHandler \
573 (parser->m_startNamespaceDeclHandler)
574 #define endNamespaceDeclHandler (parser->m_endNamespaceDeclHandler)
575 #define notStandaloneHandler (parser->m_notStandaloneHandler)
576 #define externalEntityRefHandler \
577 (parser->m_externalEntityRefHandler)
578 #define externalEntityRefHandlerArg \
579 (parser->m_externalEntityRefHandlerArg)
580 #define internalEntityRefHandler \
581 (parser->m_internalEntityRefHandler)
582 #define skippedEntityHandler (parser->m_skippedEntityHandler)
583 #define unknownEncodingHandler (parser->m_unknownEncodingHandler)
584 #define elementDeclHandler (parser->m_elementDeclHandler)
585 #define attlistDeclHandler (parser->m_attlistDeclHandler)
586 #define entityDeclHandler (parser->m_entityDeclHandler)
587 #define xmlDeclHandler (parser->m_xmlDeclHandler)
588 #define encoding (parser->m_encoding)
589 #define initEncoding (parser->m_initEncoding)
590 #define internalEncoding (parser->m_internalEncoding)
591 #define unknownEncodingMem (parser->m_unknownEncodingMem)
592 #define unknownEncodingData (parser->m_unknownEncodingData)
593 #define unknownEncodingHandlerData \
594 (parser->m_unknownEncodingHandlerData)
595 #define unknownEncodingRelease (parser->m_unknownEncodingRelease)
596 #define protocolEncodingName (parser->m_protocolEncodingName)
597 #define ns (parser->m_ns)
598 #define ns_triplets (parser->m_ns_triplets)
599 #define prologState (parser->m_prologState)
600 #define processor (parser->m_processor)
601 #define errorCode (parser->m_errorCode)
602 #define eventPtr (parser->m_eventPtr)
603 #define eventEndPtr (parser->m_eventEndPtr)
604 #define positionPtr (parser->m_positionPtr)
605 #define position (parser->m_position)
606 #define openInternalEntities (parser->m_openInternalEntities)
607 #define freeInternalEntities (parser->m_freeInternalEntities)
608 #define defaultExpandInternalEntities \
609 (parser->m_defaultExpandInternalEntities)
610 #define tagLevel (parser->m_tagLevel)
611 #define buffer (parser->m_buffer)
612 #define bufferPtr (parser->m_bufferPtr)
613 #define bufferEnd (parser->m_bufferEnd)
614 #define parseEndByteIndex (parser->m_parseEndByteIndex)
615 #define parseEndPtr (parser->m_parseEndPtr)
616 #define bufferLim (parser->m_bufferLim)
617 #define dataBuf (parser->m_dataBuf)
618 #define dataBufEnd (parser->m_dataBufEnd)
619 #define _dtd (parser->m_dtd)
620 #define curBase (parser->m_curBase)
621 #define declEntity (parser->m_declEntity)
622 #define doctypeName (parser->m_doctypeName)
623 #define doctypeSysid (parser->m_doctypeSysid)
624 #define doctypePubid (parser->m_doctypePubid)
625 #define declAttributeType (parser->m_declAttributeType)
626 #define declNotationName (parser->m_declNotationName)
627 #define declNotationPublicId (parser->m_declNotationPublicId)
628 #define declElementType (parser->m_declElementType)
629 #define declAttributeId (parser->m_declAttributeId)
630 #define declAttributeIsCdata (parser->m_declAttributeIsCdata)
631 #define declAttributeIsId (parser->m_declAttributeIsId)
632 #define freeTagList (parser->m_freeTagList)
633 #define freeBindingList (parser->m_freeBindingList)
634 #define inheritedBindings (parser->m_inheritedBindings)
635 #define tagStack (parser->m_tagStack)
636 #define atts (parser->m_atts)
637 #define attsSize (parser->m_attsSize)
638 #define nSpecifiedAtts (parser->m_nSpecifiedAtts)
639 #define idAttIndex (parser->m_idAttIndex)
640 #define nsAtts (parser->m_nsAtts)
641 #define nsAttsVersion (parser->m_nsAttsVersion)
642 #define nsAttsPower (parser->m_nsAttsPower)
643 #define tempPool (parser->m_tempPool)
644 #define temp2Pool (parser->m_temp2Pool)
645 #define groupConnector (parser->m_groupConnector)
646 #define groupSize (parser->m_groupSize)
647 #define namespaceSeparator (parser->m_namespaceSeparator)
648 #define parentParser (parser->m_parentParser)
649 #define ps_parsing (parser->m_parsingStatus.parsing)
650 #define ps_finalBuffer (parser->m_parsingStatus.finalBuffer)
652 #define isParamEntity (parser->m_isParamEntity)
653 #define useForeignDTD (parser->m_useForeignDTD)
654 #define paramEntityParsing (parser->m_paramEntityParsing)
671 static const XML_Char implicitContext[] = {
685 XML_Parser parser = parserCreate(encodingName, memsuite, nameSep, NULL);
686 if (parser != NULL &&
ns) {
690 if (!setContext(parser, implicitContext)) {
699 parserCreate(
const XML_Char *encodingName,
710 if (parser != NULL) {
720 if (parser != NULL) {
780 parserInit(parser, encodingName);
805 ? poolCopyString(&
tempPool, encodingName)
896 moveToFreeBindingList(parser, tag->
bindings);
902 while (openEntityList) {
904 openEntityList = openEntity->
next;
914 parserInit(parser, encodingName);
916 return setContext(parser, implicitContext);
928 if (encodingName == NULL)
949 XML_ProcessingInstructionHandler oldProcessingInstructionHandler
952 XML_StartCdataSectionHandler oldStartCdataSectionHandler
954 XML_EndCdataSectionHandler oldEndCdataSectionHandler
957 XML_UnparsedEntityDeclHandler oldUnparsedEntityDeclHandler
960 XML_StartNamespaceDeclHandler oldStartNamespaceDeclHandler
962 XML_EndNamespaceDeclHandler oldEndNamespaceDeclHandler
965 XML_ExternalEntityRefHandler oldExternalEntityRefHandler
968 XML_UnknownEncodingHandler oldUnknownEncodingHandler
999 parser = parserCreate(encodingName, &parser->
m_mem, tmp, newDtd);
1002 parser = parserCreate(encodingName, &parser->
m_mem, NULL, newDtd);
1030 if (oldUserData == oldHandlerArg)
1034 if (oldExternalEntityRefHandlerArg != oldParser)
1040 paramEntityParsing = oldParamEntityParsing;
1044 if (!dtdCopy(
_dtd, oldDtd, &parser->
m_mem)
1045 || !setContext(parser, context)) {
1049 processor = externalEntityInitProcessor;
1062 processor = externalParEntInitProcessor;
1092 if (tagList == NULL) {
1099 tagList = tagList->
parent;
1101 destroyBindings(p->
bindings, parser);
1108 if (entityList == NULL) {
1114 openEntity = entityList;
1115 entityList = entityList->
next;
1127 if (!isParamEntity &&
_dtd)
1156 useForeignDTD = useDTD;
1185 p = poolCopyString(&
_dtd->pool, p);
1215 XML_StartElementHandler start,
1216 XML_EndElementHandler end)
1224 XML_StartElementHandler start) {
1230 XML_EndElementHandler end) {
1236 XML_CharacterDataHandler handler)
1243 XML_ProcessingInstructionHandler handler)
1250 XML_CommentHandler handler)
1257 XML_StartCdataSectionHandler start,
1258 XML_EndCdataSectionHandler end)
1266 XML_StartCdataSectionHandler start) {
1272 XML_EndCdataSectionHandler end) {
1278 XML_DefaultHandler handler)
1286 XML_DefaultHandler handler)
1294 XML_StartDoctypeDeclHandler start,
1303 XML_StartDoctypeDeclHandler start) {
1315 XML_UnparsedEntityDeclHandler handler)
1322 XML_NotationDeclHandler handler)
1329 XML_StartNamespaceDeclHandler start,
1330 XML_EndNamespaceDeclHandler end)
1338 XML_StartNamespaceDeclHandler start) {
1344 XML_EndNamespaceDeclHandler end) {
1350 XML_NotStandaloneHandler handler)
1357 XML_ExternalEntityRefHandler handler)
1373 XML_SkippedEntityHandler handler)
1380 XML_UnknownEncodingHandler handler,
1389 XML_ElementDeclHandler eldecl)
1396 XML_AttlistDeclHandler attdecl)
1403 XML_EntityDeclHandler handler)
1410 XML_XmlDeclHandler handler) {
1422 paramEntityParsing = peParsing;
1474 #ifndef XML_CONTEXT_BYTES
1506 nLeftOver = s + len - end;
1512 ? (
char *)
MALLOC(len * 2)
1527 memcpy(
buffer, end, nLeftOver);
1543 memcpy(buff, s, len);
1616 #ifdef XML_CONTEXT_BYTES
1624 #ifdef XML_CONTEXT_BYTES
1640 if (bufferSize == 0)
1644 }
while (bufferSize < neededSize);
1645 newBuf = (
char *)
MALLOC(bufferSize);
1651 #ifdef XML_CONTEXT_BYTES
1696 if (isParamEntity) {
1750 assert(status != NULL);
1779 #ifdef XML_CONTEXT_BYTES
1838 reportDefault(parser,
1850 static const XML_LChar*
const message[] = {
1852 XML_L(
"out of memory"),
1853 XML_L(
"syntax error"),
1854 XML_L(
"no element found"),
1855 XML_L(
"not well-formed (invalid token)"),
1856 XML_L(
"unclosed token"),
1857 XML_L(
"partial character"),
1858 XML_L(
"mismatched tag"),
1859 XML_L(
"duplicate attribute"),
1860 XML_L(
"junk after document element"),
1861 XML_L(
"illegal parameter entity reference"),
1862 XML_L(
"undefined entity"),
1863 XML_L(
"recursive entity reference"),
1864 XML_L(
"asynchronous entity"),
1865 XML_L(
"reference to invalid character number"),
1866 XML_L(
"reference to binary entity"),
1867 XML_L(
"reference to external entity in attribute"),
1868 XML_L(
"XML or text declaration not at start of entity"),
1869 XML_L(
"unknown encoding"),
1870 XML_L(
"encoding specified in XML declaration is incorrect"),
1871 XML_L(
"unclosed CDATA section"),
1872 XML_L(
"error in processing external entity reference"),
1873 XML_L(
"document is not standalone"),
1874 XML_L(
"unexpected parser state - please send a bug report"),
1875 XML_L(
"entity declared in parameter entity"),
1876 XML_L(
"requested feature requires XML_DTD support in Expat"),
1877 XML_L(
"cannot change setting once parsing has begun"),
1878 XML_L(
"unbound prefix"),
1879 XML_L(
"must not undeclare prefix"),
1880 XML_L(
"incomplete markup in parameter entity"),
1881 XML_L(
"XML declaration not well-formed"),
1882 XML_L(
"text declaration not well-formed"),
1883 XML_L(
"illegal character(s) in public id"),
1884 XML_L(
"parser suspended"),
1885 XML_L(
"parser not suspended"),
1886 XML_L(
"parsing aborted"),
1887 XML_L(
"parsing finished"),
1888 XML_L(
"cannot suspend in external parameter entity"),
1889 XML_L(
"reserved prefix (xml) must not be undeclared or bound to another namespace name"),
1890 XML_L(
"reserved prefix (xmlns) must not be declared or undeclared"),
1891 XML_L(
"prefix must not be bound to one of the reserved namespace names")
1893 if (code > 0 &&
unsigned(code) <
sizeof(message)/
sizeof(message[0]))
1894 return message[code];
1909 #define V1(a,b,c) XML_L(#a)XML_L(".")XML_L(#b)XML_L(".")XML_L(#c)
1910 #define V2(a,b,c) XML_L("expat_")V1(a,b,c)
1941 #ifdef XML_UNICODE_WCHAR_T
1947 #ifdef XML_CONTEXT_BYTES
1957 #ifdef XML_LARGE_SIZE
1978 char *rawNameBuf = tag->
buf + nameLen;
1984 if (tag->
rawName == rawNameBuf)
1991 char *temp = (
char *)
REALLOC(tag->
buf, bufSize);
2006 tag->
bufEnd = temp + bufSize;
2007 rawNameBuf = temp + nameLen;
2020 const char **endPtr)
2025 if (!storeRawNames(parser))
2032 externalEntityInitProcessor(
XML_Parser parser,
2035 const char **endPtr)
2037 enum XML_Error result = initializeEncoding(parser);
2040 processor = externalEntityInitProcessor2;
2041 return externalEntityInitProcessor2(parser, start, end, endPtr);
2045 externalEntityInitProcessor2(
XML_Parser parser,
2048 const char **endPtr)
2050 const char *next = start;
2080 processor = externalEntityInitProcessor3;
2081 return externalEntityInitProcessor3(parser, start, end, endPtr);
2085 externalEntityInitProcessor3(
XML_Parser parser,
2088 const char **endPtr)
2091 const char *next = start;
2100 result = processXmlDecl(parser, 1, start, next);
2127 processor = externalEntityContentProcessor;
2129 return externalEntityContentProcessor(parser, start, end, endPtr);
2133 externalEntityContentProcessor(
XML_Parser parser,
2136 const char **endPtr)
2141 if (!storeRawNames(parser))
2153 const char **nextPtr,
2159 const char **eventPP;
2160 const char **eventEndPP;
2172 const char *next =
s;
2187 reportDefault(parser, enc, s, end);
2191 if (startTagLevel == 0)
2202 if (startTagLevel > 0) {
2235 reportDefault(parser, enc, s, next);
2238 name = poolStoreString(&dtd->
pool, enc,
2259 reportDefault(parser, enc, s, next);
2272 reportDefault(parser, enc, s, next);
2275 result = processInternalEntity(parser, entity,
XML_FALSE);
2282 context = getContext(parser);
2295 reportDefault(parser, enc, s, next);
2330 const char *fromPtr = tag->
rawName;
2336 &fromPtr, rawNameEnd,
2339 if (fromPtr == rawNameEnd) {
2345 char *temp = (
char *)
REALLOC(tag->
buf, bufSize);
2349 tag->
bufEnd = temp + bufSize;
2350 toPtr = (
XML_Char *)temp + convLen;
2355 *toPtr =
XML_T(
'\0');
2356 result = storeAtts(parser, enc, s, &(tag->
name), &(tag->
bindings));
2363 reportDefault(parser, enc, s, next);
2376 name.
str = poolStoreString(&
tempPool, enc, rawName,
2381 result = storeAtts(parser, enc, s, &name, &bindings);
2391 *eventPP = *eventEndPP;
2396 reportDefault(parser, enc, s, next);
2409 return epilogProcessor(parser, next, end, nextPtr);
2416 const char *rawName;
2424 || memcmp(tag->
rawName, rawName, len) != 0) {
2434 if (
ns && localPart) {
2441 while (*localPart) *uri++ = *localPart++;
2445 while (*prefix) *uri++ = *prefix++;
2452 reportDefault(parser, enc, s, next);
2463 return epilogProcessor(parser, next, end, nextPtr);
2476 reportDefault(parser, enc, s, next);
2487 reportDefault(parser, enc, s, next);
2511 reportDefault(parser, enc, s, next);
2512 result = doCdataSection(parser, enc, &next, end, nextPtr, haveMore);
2539 reportDefault(parser, enc, s, end);
2543 if (startTagLevel == 0) {
2556 if (charDataHandler) {
2575 reportDefault(parser, enc, s, next);
2579 if (!reportProcessingInstruction(parser, enc, s, next))
2583 if (!reportComment(parser, enc, s, next))
2588 reportDefault(parser, enc, s, next);
2591 *eventPP = s = next;
2616 const char *attStr,
TAG_NAME *tagNamePtr,
2642 if (
ns && !setElementTypePrefix(parser, elementType))
2657 if (n > oldAttsSize)
2662 for (i = 0; i <
n; i++) {
2673 if ((attId->
name)[-1]) {
2678 (attId->
name)[-1] = 1;
2679 appAtts[attIndex++] = attId->
name;
2680 if (!
atts[i].normalized) {
2687 for (j = 0; j < nDefaultAtts; j++) {
2696 result = storeAttributeValue(parser, enc, isCdata,
2697 atts[i].valuePtr,
atts[i].valueEnd,
2706 appAtts[attIndex] = poolStoreString(&
tempPool, enc,
atts[i].valuePtr,
2708 if (appAtts[attIndex] == 0)
2717 appAtts[attIndex], bindingsPtr);
2726 (attId->
name)[-1] = 2;
2736 for (i = 0; i < attIndex; i += 2)
2737 if (appAtts[i] == elementType->
idAtt->
name) {
2746 for (i = 0; i < nDefaultAtts; i++) {
2752 da->
value, bindingsPtr);
2759 appAtts[attIndex++] = da->
id->
name;
2760 appAtts[attIndex++] = da->
value;
2765 appAtts[attIndex++] = da->
id->
name;
2766 appAtts[attIndex++] = da->
value;
2770 appAtts[attIndex] = 0;
2796 for (j = nsAttsSize; j != 0; )
2797 nsAtts[--j].version = version;
2802 for (; i < attIndex; i += 2) {
2807 unsigned long uriHash = 0;
2815 for (j = 0; j < b->
uriLen; j++) {
2833 unsigned char step = 0;
2834 unsigned long mask = nsAttsSize - 1;
2836 while (
nsAtts[j].version == version) {
2838 if (uriHash ==
nsAtts[j].hash) {
2842 for (; *s1 == *s2 && *s1 != 0; s1++, s2++);
2848 j < step ? (j += nsAttsSize - step) : (j -= step);
2868 nsAtts[j].hash = uriHash;
2881 for (; i < attIndex; i += 2)
2882 ((
XML_Char *)(appAtts[i]))[-1] = 0;
2883 for (binding = *bindingsPtr; binding; binding = binding->
nextTagBinding)
2890 if (elementType->
prefix) {
2894 localPart = tagNamePtr->
str;
2900 localPart = tagNamePtr->
str;
2913 for (i = 0; localPart[i++];)
2915 n = i + binding->
uriLen + prefixLen;
2931 memcpy(uri, localPart, i *
sizeof(
XML_Char));
2938 tagNamePtr->
str = binding->
uri;
2949 static const XML_Char xmlNamespace[] = {
2957 static const int xmlLen =
2959 static const XML_Char xmlnsNamespace[] = {
2966 static const int xmlnsLen =
2977 if (*uri ==
XML_T(
'\0') && prefix->
name)
2995 for (len = 0; uri[
len]; len++) {
2996 if (isXML && (len > xmlLen || uri[len] != xmlNamespace[len]))
2999 if (!mustBeXML && isXMLNS
3000 && (len > xmlnsLen || uri[len] != xmlnsNamespace[len]))
3003 isXML = isXML && len == xmlLen;
3004 isXMLNS = isXMLNS && len == xmlnsLen;
3006 if (mustBeXML != isXML)
3046 if (*uri ==
XML_T(
'\0') && prefix == &
_dtd->defaultPrefix)
3066 const char **endPtr)
3074 processor = externalEntityContentProcessor;
3075 return externalEntityContentProcessor(parser, start, end, endPtr);
3079 return contentProcessor(parser, start, end, endPtr);
3091 const char **startPtr,
3093 const char **nextPtr,
3096 const char *s = *startPtr;
3097 const char **eventPP;
3098 const char **eventEndPP;
3125 reportDefault(parser, enc, s, next);
3138 reportDefault(parser, enc, s, next);
3143 if (charDataHandler) {
3162 reportDefault(parser, enc, s, next);
3186 *eventPP = s = next;
3208 const char **endPtr)
3216 return prologProcessor(parser, start, end, endPtr);
3227 const char **startPtr,
3229 const char **nextPtr,
3234 const char *s = *startPtr;
3235 const char **eventPP;
3236 const char **eventEndPP;
3248 tok = XmlIgnoreSectionTok(enc, s, end, &next);
3251 case XML_TOK_IGNORE_SECT:
3253 reportDefault(parser, enc, s, next);
3290 char encodingBuf[128];
3296 if (i ==
sizeof(encodingBuf) - 1
3298 encodingBuf[0] =
'\0';
3303 encodingBuf[i] =
'\0';
3315 processXmlDecl(
XML_Parser parser,
int isGeneralTextEntity,
3316 const char *s,
const char *next)
3318 const char *encodingName = NULL;
3319 const XML_Char *storedEncName = NULL;
3320 const ENCODING *newEncoding = NULL;
3322 const char *versionend;
3323 const XML_Char *storedversion = NULL;
3337 if (isGeneralTextEntity)
3342 if (!isGeneralTextEntity && standalone == 1) {
3350 if (encodingName != NULL) {
3351 storedEncName = poolStoreString(&
temp2Pool,
3361 storedversion = poolStoreString(&
temp2Pool,
3371 reportDefault(parser,
encoding, s, next);
3380 else if (encodingName) {
3382 if (!storedEncName) {
3383 storedEncName = poolStoreString(
3389 result = handleUnknownEncoding(parser, storedEncName);
3397 if (storedEncName || storedversion)
3409 for (i = 0; i < 256; i++)
3411 info.convert = NULL;
3413 info.release = NULL;
3420 info.release(info.
data);
3436 if (info.release != NULL)
3437 info.release(info.
data);
3446 const char **nextPtr)
3448 enum XML_Error result = initializeEncoding(parser);
3452 return prologProcessor(parser, s, end, nextPtr);
3458 externalParEntInitProcessor(
XML_Parser parser,
3461 const char **nextPtr)
3463 enum XML_Error result = initializeEncoding(parser);
3473 return entityValueInitProcessor(parser, s, end, nextPtr);
3477 return externalParEntProcessor(parser, s, end, nextPtr);
3485 const char **nextPtr)
3488 const char *start =
s;
3489 const char *next = start;
3512 return storeEntityValue(parser,
encoding, s, end);
3516 result = processXmlDecl(parser, 0, start, next);
3530 return entityValueProcessor(parser, next, end, nextPtr);
3552 const char **nextPtr)
3554 const char *next =
s;
3585 return doProlog(parser,
encoding, s, end, tok, next,
3593 const char **nextPtr)
3595 const char *start =
s;
3596 const char *next =
s;
3619 return storeEntityValue(parser, enc, s, end);
3631 const char **nextPtr)
3633 const char *next =
s;
3635 return doProlog(parser,
encoding, s, end, tok, next,
3646 const char **nextPtr,
3652 static const XML_Char atypeCDATA[] =
3655 static const XML_Char atypeIDREF[] =
3657 static const XML_Char atypeIDREFS[] =
3659 static const XML_Char atypeENTITY[] =
3663 static const XML_Char atypeNMTOKEN[] = {
3675 const char **eventPP;
3676 const char **eventEndPP;
3717 if (isParamEntity || enc !=
encoding) {
3736 enum XML_Error result = processXmlDecl(parser, 0, s, next);
3764 case XML_ROLE_TEXT_DECL:
3766 enum XML_Error result = processXmlDecl(parser, 1, s, next);
3795 goto alreadyChecked;
3809 normalizePublicId(tem);
3846 if (dtd->paramEntityRead) {
3872 if (useForeignDTD) {
3889 if (dtd->paramEntityRead) {
3905 return contentProcessor(parser, s, end, nextPtr);
3910 goto checkAttListDeclHandler;
3918 goto checkAttListDeclHandler;
3922 goto checkAttListDeclHandler;
3926 goto checkAttListDeclHandler;
3929 goto checkAttListDeclHandler;
3932 goto checkAttListDeclHandler;
3935 goto checkAttListDeclHandler;
3938 goto checkAttListDeclHandler;
3941 goto checkAttListDeclHandler;
3944 checkAttListDeclHandler:
3953 prefix = enumValueSep;
3960 if (!poolAppendString(&
tempPool, prefix))
3962 if (!poolAppend(&
tempPool, enc, s, next))
4035 enum XML_Error result = storeEntityValue(parser, enc,
4081 && !paramEntityParsing
4128 declEntity->notation = poolStoreString(&dtd->
pool, enc, s, next);
4246 normalizePublicId(tem);
4294 case XML_ROLE_IGNORE_SECT:
4298 reportDefault(parser, enc, s, next);
4300 result = doIgnoreSection(parser, enc, &next, end, nextPtr, haveMore);
4333 int myindex = nextScaffoldPart(parser);
4367 case XML_ROLE_INNER_PARAM_ENTITY_REF:
4369 if (!paramEntityParsing)
4374 name = poolStoreString(&dtd->
pool, enc,
4379 entity = (
ENTITY *)lookup(&dtd->paramEntities, name, 0);
4409 result = processInternalEntity(parser, entity, betweenDecl);
4428 if (!dtd->paramEntityRead) {
4467 content->
name = NULL;
4492 goto elementContent;
4495 goto elementContent;
4498 goto elementContent;
4509 int myindex = nextScaffoldPart(parser);
4514 el = getElementType(parser, enc, s, nxt);
4520 for (; name[nameLen++]; );
4545 if (!handleDefault) {
4560 if (!reportProcessingInstruction(parser, enc, s, next))
4565 if (!reportComment(parser, enc, s, next))
4599 reportDefault(parser, enc, s, next);
4619 const char **nextPtr)
4624 const char *next = NULL;
4631 reportDefault(parser,
encoding, s, next);
4642 reportDefault(parser,
encoding, s, next);
4645 if (!reportProcessingInstruction(parser,
encoding, s, next))
4649 if (!reportComment(parser,
encoding, s, next))
4686 const char *textStart, *textEnd;
4704 openEntity->
entity = entity;
4709 textStart = (
char *)entity->
textPtr;
4743 const char **nextPtr)
4746 const char *textStart, *textEnd;
4753 entity = openEntity->
entity;
4787 return doProlog(parser,
encoding, s, end, tok, next, nextPtr,
4804 const char **nextPtr)
4811 const char *ptr,
const char *end,
4814 enum XML_Error result = appendAttributeValue(parser, enc, isCdata, ptr,
4827 const char *ptr,
const char *end,
4865 for (i = 0; i <
n; i++) {
4872 if (!poolAppend(pool, enc, ptr, next))
4889 char checkEntityDecl;
4908 if (pool == &dtd->
pool)
4918 if (checkEntityDecl) {
4958 (
char *)textEnd, pool);
4978 const char *entityTextPtr,
4979 const char *entityTextEnd)
4992 if (!poolGrow(pool))
5002 if (isParamEntity || enc !=
encoding) {
5005 name = poolStoreString(&
tempPool, enc,
5010 goto endEntityValue;
5012 entity = (
ENTITY *)lookup(&dtd->paramEntities, name, 0);
5022 goto endEntityValue;
5028 goto endEntityValue;
5041 goto endEntityValue;
5044 if (!dtd->paramEntityRead)
5052 result = storeEntityValue(parser,
5059 goto endEntityValue;
5068 goto endEntityValue;
5071 goto endEntityValue;
5074 if (!poolAppend(pool, enc, entityTextPtr, next)) {
5076 goto endEntityValue;
5083 if (pool->
end == pool->
ptr && !poolGrow(pool)) {
5085 goto endEntityValue;
5087 *(pool->
ptr)++ = 0xA;
5098 goto endEntityValue;
5105 goto endEntityValue;
5107 for (i = 0; i <
n; i++) {
5108 if (pool->
end == pool->
ptr && !poolGrow(pool)) {
5110 goto endEntityValue;
5112 *(pool->
ptr)++ = buf[i];
5120 goto endEntityValue;
5125 goto endEntityValue;
5130 goto endEntityValue;
5132 entityTextPtr = next;
5146 if (*s ==
XML_T(
'\0'))
5166 const char *start,
const char *end)
5173 reportDefault(parser, enc, start, end);
5178 target = poolStoreString(&
tempPool, enc, start, tem);
5182 data = poolStoreString(&
tempPool, enc,
5187 normalizeLines(data);
5195 const char *start,
const char *end)
5200 reportDefault(parser, enc, start, end);
5209 normalizeLines(data);
5217 const char *s,
const char *end)
5220 const char **eventPP;
5221 const char **eventEndPP;
5248 if (value || isId) {
5256 type->
idAtt = attId;
5292 for (name = elementType->
name; *name; name++) {
5296 for (s = elementType->
name; s != name; s++) {
5319 const char *start,
const char *end)
5326 name = poolStoreString(&dtd->
pool, enc, start, end);
5334 if (id->
name != name)
5346 if (name[5] ==
XML_T(
'\0'))
5354 for (i = 0; name[i]; i++) {
5358 for (j = 0; j < i; j++) {
5378 #define CONTEXT_SEP XML_T(ASCII_FF)
5395 for (i = 0; i <
len; i++)
5401 hashTableIterInit(&iter, &(dtd->
prefixes));
5413 for (s = prefix->
name; *s; s++)
5421 for (i = 0; i <
len; i++)
5438 for (s = e->
name; *s; s++)
5455 while (*context !=
XML_T(
'\0')) {
5463 if (*s !=
XML_T(
'\0'))
5480 prefix->
name = poolCopyString(&dtd->
pool, prefix->
name);
5486 for (context = s + 1;
5497 if (*context !=
XML_T(
'\0'))
5515 for (s = publicId; *
s; s++) {
5520 if (p != publicId && p[-1] != 0x20)
5527 if (p != publicId && p[-1] == 0x20)
5538 poolInit(&(p->
pool), ms);
5546 hashTableInit(&(p->paramEntities), ms);
5580 hashTableClear(&(p->paramEntities));
5585 poolClear(&(p->
pool));
5621 hashTableDestroy(&(p->paramEntities));
5626 poolDestroy(&(p->
pool));
5645 hashTableIterInit(&iter, &(oldDtd->
prefixes));
5648 const PREFIX *oldP = (
PREFIX *)hashTableIterNext(&iter);
5651 name = poolCopyString(&(newDtd->
pool), oldP->
name);
5672 name = poolCopyString(&(newDtd->
pool), oldA->
name);
5702 name = poolCopyString(&(newDtd->
pool), oldE->
name);
5746 if (!copyEntityTable(&(newDtd->paramEntities),
5748 &(oldDtd->paramEntities)))
5750 newDtd->paramEntityRead = oldDtd->paramEntityRead;
5774 const XML_Char *cachedOldBase = NULL;
5775 const XML_Char *cachedNewBase = NULL;
5777 hashTableIterInit(&iter, oldTable);
5782 const ENTITY *oldE = (
ENTITY *)hashTableIterNext(&iter);
5785 name = poolCopyString(newPool, oldE->
name);
5788 newE = (
ENTITY *)lookup(newTable, name,
sizeof(
ENTITY));
5797 if (oldE->
base == cachedOldBase)
5798 newE->
base = cachedNewBase;
5800 cachedOldBase = oldE->
base;
5801 tem = poolCopyString(newPool, cachedOldBase);
5804 cachedNewBase = newE->
base = tem;
5808 tem = poolCopyString(newPool, oldE->
publicId);
5834 #define INIT_POWER 6
5839 for (; *s1 == *s2; s1++, s2++)
5848 unsigned long h = 0;
5858 if (table->
size == 0) {
5871 memset(table->
v, 0, tsize);
5872 i = hash(name) & ((
unsigned long)table->
size - 1);
5875 unsigned long h = hash(name);
5876 unsigned long mask = (
unsigned long)table->
size - 1;
5877 unsigned char step = 0;
5880 if (keyeq(name, table->
v[i]->
name))
5884 i < step ? (i += table->
size - step) : (i -= step);
5890 if (table->
used >> (table->
power - 1)) {
5891 unsigned char newPower = table->
power + 1;
5892 size_t newSize = (size_t)1 << newPower;
5893 unsigned long newMask = (
unsigned long)newSize - 1;
5894 size_t tsize = newSize *
sizeof(
NAMED *);
5898 memset(newV, 0, tsize);
5899 for (i = 0; i < table->
size; i++)
5901 unsigned long newHash = hash(table->
v[i]->
name);
5902 size_t j = newHash & newMask;
5906 step =
PROBE_STEP(newHash, newMask, newPower);
5907 j < step ? (j += newSize - step) : (j -= step);
5909 newV[j] = table->
v[i];
5913 table->
power = newPower;
5914 table->
size = newSize;
5917 while (table->
v[i]) {
5920 i < step ? (i += newSize - step) : (i -= step);
5927 memset(table->
v[i], 0, createSize);
5937 for (i = 0; i < table->
size; i++) {
5948 for (i = 0; i < table->
size; i++)
5973 while (iter->
p != iter->
end) {
5974 NAMED *tem = *(iter->
p)++;
6031 const char *ptr,
const char *end)
6033 if (!pool->
ptr && !poolGrow(pool))
6039 if (!poolGrow(pool))
6060 if (!pool->
ptr && !poolGrow(pool))
6062 for (; n > 0; --
n, s++) {
6084 const char *ptr,
const char *end)
6086 if (!poolAppend(pool, enc, ptr, end))
6088 if (pool->
ptr == pool->
end && !poolGrow(pool))
6098 if (pool->
start == 0) {
6126 if (pool->
blocks == NULL)
6131 pool->
end = pool->
start + blockSize;
6144 tem->
size = blockSize;
6148 memcpy(tem->
s, pool->
start,
6152 pool->
end = tem->
s + blockSize;
6217 dest->
name = *strpos;
6220 *(*strpos)++ = *src;
6235 i < dest->numchildren;
6237 build_node(parser, cn, &(dest->
children[i]), contpos, strpos);
6260 build_node(parser, 0, ret, &cpos, &str);
6271 const XML_Char *name = poolStoreString(&dtd->
pool, enc, ptr, end);
6279 if (ret->
name != name)
6283 if (!setElementTypePrefix(parser, ret))