35 static const char* s_cpUtf8 =
"UTF-8";
36 static const char* s_cpUtf8Default =
"UTF-8 (default value)";
37 static const char* s_cpVersionDefault =
"1.0 (default value)";
38 static const char* s_cpNoDefault=
"no (default value)";
39 static const char* s_cpUtf16 =
"UTF-16";
40 static const char* s_cpVersion =
"1.0";
41 static const char* s_cpYes =
"yes";
42 static const char* s_cpNo =
"no";
43 static const char* s_cpStandaloneError=
"standalone declaration error: must be \"yes\" or \"no\"";
44 static const char* s_cpCData =
"CDATA";
45 static const uint32_t s_uiAmp = 38;
46 static const uint32_t s_uiSemi = 59;
56 XML_THROW(
"Syntax error. A syntactically correct document was found but followed by extraneous characters.");
59 XML_THROW(
"Syntax error. Document not matched.");
75 if(spXml->pfnXmlDeclCallback){
82 spXml->pfnXmlDeclCallback(&sInfo, spXml->vpXmlDeclData);
91 const char* cpEncoding = s_cpUtf8;
92 const char* cpStandalone;
94 if(!spXml->sXmlDecl.cpVersion){
95 XML_THROW(
"XML declaration version number not declared");
97 if(strcmp(spXml->sXmlDecl.cpVersion, s_cpVersion) != 0){
98 XML_THROW(
"XML declaration version number is \"%s\". Must be \"1.0\"");
100 if(!spXml->sXmlDecl.cpEncoding){
101 cpEncoding = s_cpUtf8Default;
103 if(strcmp(spXml->sXmlDecl.cpEncoding, s_cpUtf8) == 0){
104 cpEncoding = s_cpUtf8;
105 if(spXml->uiTrueType !=
UTF_8){
107 "XML declaration encoding is %s but data has type %s",
108 spXml->sXmlDecl.cpEncoding, cpTrueType);
111 }
else if(strcmp(spXml->sXmlDecl.cpEncoding, s_cpUtf16) == 0){
112 cpEncoding =s_cpUtf16;
115 "XML declaration encoding is %s but data has type %s",
116 spXml->sXmlDecl.cpEncoding, cpTrueType);
121 "XML declaration encoding is \"%s\": Must be \"UTF-8\" or \"UTF-16\"",
122 spXml->sXmlDecl.cpEncoding);
126 if(spXml->sXmlDecl.cpStandalone){
127 cpStandalone = spXml->sXmlDecl.cpStandalone;
128 if(strcmp(spXml->sXmlDecl.cpStandalone, s_cpStandaloneError) == 0){
132 cpStandalone = s_cpNoDefault;
134 if(spXml->pfnXmlDeclCallback){
136 spXml->sXmlDecl.cpExists = s_cpYes;
137 spXml->sXmlDecl.cpVersion = s_cpVersion;
138 spXml->sXmlDecl.cpEncoding = cpEncoding;
139 spXml->sXmlDecl.cpStandalone = cpStandalone;
140 spXml->pfnXmlDeclCallback(&spXml->sXmlDecl, spXml->vpXmlDeclData);
149 XML_THROW(
"XML declaration syntax error.");
155 XML_THROW(
"version information is malformed");
167 spXml->sXmlDecl.cpVersion = cpNum;
170 XML_THROW(
"XML declaration syntax error. Version number not of form \"1.123...\"");
177 XML_THROW(
"XML declaration syntax error. Malformed encoding definition.");
189 spXml->sXmlDecl.cpEncoding = cpBuf;
191 XML_THROW(
"XML declaration syntax error. Malformed encoding name.");
197 XML_THROW(
"XML declaration syntax error. standalone must be either \"yes\" or \"no\".");
203 spXml->sXmlDecl.cpStandalone = s_cpYes;
210 spXml->sXmlDecl.cpStandalone = s_cpNo;
227 if(spXml->pfnDTDCallback){
229 spXml->pfnDTDCallback(&sDtd, spXml->vpDTDData);
236 spXml->sDtdName.uiOffset =
uiVecLen(spXml->vpVec32);
237 spXml->sDtdName.uiLength = (uint32_t)
uiVecLen(spXml->vpVecName);
244 if(spXml->pfnDTDCallback){
245 aint ui, uiIndex, uiCount;
264 uiCount =
uiVecLen(spXml->vpVecGEDefs);
267 uiIndex =
uiVecLen(spXml->vpVecCData);
269 for(ui = 0; ui < uiCount; ui++, spNamedValues++){
276 uiIndex =
uiVecLen(spXml->vpVecCData);
278 for(ui = 0; ui < uiCount; ui++, spNamedValues++){
286 uiCount =
uiVecLen(spXml->vpVecAttDecls);
290 uiIndex =
uiVecLen(spXml->vpVecCData);
292 for(ui = 0; ui < uiCount; ui++, spAttList++){
299 uiIndex =
uiVecLen(spXml->vpVecCData);
301 for(ui = 0; ui < uiCount; ui++, spAttList++){
308 uiIndex =
uiVecLen(spXml->vpVecCData);
310 for(ui = 0; ui < uiCount; ui++, spAttList++){
317 uiIndex =
uiVecLen(spXml->vpVecCData);
319 for(ui = 0; ui < uiCount; ui++, spAttList++){
327 uiIndex =
uiVecLen(spXml->vpVecCData);
336 uiIndex =
uiVecLen(spXml->vpVecCData);
346 spXml->pfnDTDCallback(&sDtd, spXml->vpDTDData);
353 vThrowError(spXml,
"Document Type Declaration bad content",
354 spXml->uiDTDOffset, __LINE__, __FILE__, __func__);
363 XML_THROW(
"Document Type Declaration syntax error");
378 spXml->uiExternalIds++;
385 spXml->uiExternalIds++;
399 XML_THROW(
"Parameter Entity Declaration syntax error. Expected closure not found");
411 XML_THROW(
"Well-formedness constraint: PEs in Internal Subset\n"
412 "In the internal DTD subset, parameter-entity references MUST NOT occur within markup declarations...");
420 uint32_t* uipName = (uint32_t*)
vpVecFirst(spXml->vpVecName);
422 if(!uipName || !uiNameLen){
423 XML_THROW(
"General Entity Declaration has no name.");
427 memset((
void*)&spXml->sCurrentEntity, 0,
sizeof(
entity_decl));
429 spXml->sCurrentEntity.sName.uiOffset = (uint32_t)
uiVecLen(spXml->vpVec32);
430 spXml->sCurrentEntity.sName.uiLength = uiNameLen;
431 vpVecPushn(spXml->vpVec32, uipName, uiNameLen);
434 spXml->sCurrentEntity.sValue.uiOffset = (uint32_t)
uiVecLen(spXml->vpVec32);
435 spXml->sCurrentEntity.sValue.uiLength = 0;
443 spXml->sCurrentEntity.bGEPERef =
APG_TRUE;
444 vLogMsg(spXml, spData->
uiParserOffset,
"General Entity declaration contains unread Parameter Entity");
450 spXml->sCurrentEntity.bGEDefEx =
APG_TRUE;
457 spXml->uiGEDeclsTotal++;
459 if((spXml->uiPERefs == 0) || spXml->bStandalone){
461 uint32_t* uipChars = (uint32_t*)
vpVecFirst(spXml->vpVec32);
463 if(uiLen32 < spXml->sCurrentEntity.sValue.uiOffset){
464 XML_THROW(
"General Entity Declaration syntax error. No value data.");
466 spXml->sCurrentEntity.sValue.uiLength = uiLen32 - spXml->sCurrentEntity.sValue.uiOffset;
469 uint32_t* uipName = uipChars + spXml->sCurrentEntity.sName.uiOffset;
470 uint32_t uiLen = spXml->sCurrentEntity.sName.uiLength;
474 spXml->sCurrentEntity.spXml = spXml;
475 vpVecPush(spXml->vpVecGEDefs, &spXml->sCurrentEntity);
481 spXml->uiGEDeclsNotProcessed++;
482 if(spXml->sCurrentEntity.bGEPERef){
484 vLogMsg(spXml, spXml->uiSavedOffset,
"General Entity not processed (contains parameter entity)");
487 if(spXml->sCurrentEntity.bGEDefEx){
489 vLogMsg(spXml, spXml->uiSavedOffset,
"General Entity not processed (contains external definition)");
493 vLogMsg(spXml, spXml->uiSavedOffset,
"General Entity not processed (preceded by parameter entity)");
498 XML_THROW(
"General Entity Declaration syntax error. Expected closure not found");
504 XML_THROW(
"Expected closing quotation mark (single or double) not found");
510 vpVecPush(spXml->vpVec32, (
void*)&spXml->uiChar);
516 uint32_t* uipRefName = (uint32_t*)
vpVecFirst(spXml->vpVecName);
517 uint32_t uiRefLen = (uint32_t)
uiVecLen(spXml->vpVecName);
518 uint32_t* uipThisName = (uint32_t*)
vpVecFirst(spXml->vpVec32) + spXml->sCurrentEntity.sName.uiOffset;
519 uint32_t uiThisLen = spXml->sCurrentEntity.sName.uiLength;
520 if(
bCompNames(uipRefName, uiRefLen, uipThisName, uiThisLen)){
521 vLogMsg(spXml, spXml->uiSavedOffset,
522 "Well-formedness constraint: No Recursion\n"
523 "A parsed entity MUST NOT contain a recursive reference to itself, either directly or indirectly.");
524 spXml->sCurrentEntity.bEntityDeclaredError =
APG_TRUE;
528 vpVecPush(spXml->vpVec32, (
void*)&s_uiAmp);
530 vpVecPush(spXml->vpVec32, (
void*)&s_uiSemi);
538 spXml->uiAttListsDeclared++;
539 if((spXml->uiPERefs == 0) || spXml->bStandalone){
541 uint32_t* uipName = (uint32_t*)
vpVecFirst(spXml->vpVecName);
543 if(!uipName || !uiNameLen){
544 XML_THROW(
"Attribute List Declaration element has no name.");
548 memset((
void*)&spXml->sCurrentAttList, 0,
sizeof(spXml->sCurrentAttList));
549 spXml->sCurrentAttList.spXml = spXml;
550 spXml->sCurrentAttList.sElementName.uiOffset = (uint32_t)
uiVecLen(spXml->vpVec32);
551 spXml->sCurrentAttList.sElementName.uiLength = (uint32_t)uiNameLen;
552 vpVecPushn(spXml->vpVec32, uipName, uiNameLen);
560 if((spXml->uiPERefs == 0) || spXml->bStandalone){
562 uint32_t* uipName = (uint32_t*)
vpVecFirst(spXml->vpVecName);
564 if(!uipName || !uiNameLen){
565 XML_THROW(
"Attribute List Declaration attribute has no name.");
569 spXml->sCurrentAttList.sAttName.uiOffset = (uint32_t)
uiVecLen(spXml->vpVec32);
570 spXml->sCurrentAttList.sAttName.uiLength = (uint32_t)uiNameLen;
571 vpVecPushn(spXml->vpVec32, uipName, uiNameLen);
578 if((spXml->uiPERefs == 0) || spXml->bStandalone){
580 &spXml->sCurrentAttList.sAttType.uiOffset, &spXml->sCurrentAttList.sAttType.uiLength);
582 uint32_t* uipData = (uint32_t*)
vpVecFirst(spXml->vpVec32) + spXml->sCurrentAttList.sAttType.uiOffset;
583 spXml->sCurrentAttList.bIsCDATA =
APG_FALSE;
584 if(spXml->sCurrentAttList.sAttType.uiLength == 5){
585 for(ui = 0; ui < 5; ui++){
586 if(s_cpCData[ui] != (
char)uipData[ui]){
590 spXml->sCurrentAttList.bIsCDATA =
APG_TRUE;
595 spXml->sCurrentAttList.sAttValue.uiOffset = (uint32_t)
uiVecLen(spXml->vpVec32);
596 spXml->sCurrentAttList.sAttValue.uiLength = 0;
603 if((spXml->uiPERefs == 0) || spXml->bStandalone){
605 spXml->sCurrentAttList.bHasData =
APG_TRUE;
606 uint32_t* uipAttValue = (uint32_t*)
vpVecAt(spXml->vpVec32, spXml->sCurrentAttList.sAttValue.uiOffset);
607 spXml->sCurrentAttList.sAttValue.uiLength = (uint32_t)
uiVecLen(spXml->vpVec32) -
608 spXml->sCurrentAttList.sAttValue.uiOffset;
610 spXml->sCurrentAttList.sAttValue.uiLength, spXml->sCurrentAttList.bIsCDATA);
617 if(spXml->sCurrentAttList.uiAttCount){
618 spXml->uiAttListsDeclared++;
620 if((spXml->uiPERefs == 0) || spXml->bStandalone){
622 if(spXml->sCurrentAttList.bHasData || !spXml->sCurrentAttList.bInvalidValue){
629 uint32_t* uipChars = (uint32_t*)
vpVecFirst(spXml->vpVec32);
630 uint32_t* uipLName = uipChars + spXml->sCurrentAttList.sAttName.uiOffset;
631 uint32_t uiLLen = spXml->sCurrentAttList.sAttName.uiLength;
637 if(
bCompNames(uipLName, uiLLen, uipRName, uiRLen)){
647 spXml->sCurrentAttList.uiAttCount = spFound->
uiAttCount;
648 vpVecPush(spXml->vpVecAttDecls, &spXml->sCurrentAttList);
653 spXml->sCurrentAttList.uiAttCount = 1;
654 vpVecPush(spXml->vpVecAttDecls, &spXml->sCurrentAttList);
661 "Attribute List declaration not processed due to PE references found and standalone=\"no\".");
662 spXml->uiAttListsNotProcessed++;
669 XML_THROW(
"Expected close of attribute list declaration not found");
678 uint32_t* uipName = (uint32_t*)
vpVecFirst(spXml->vpVecName);
680 if(!uipName || !uiNameLen){
681 XML_THROW(
"Notation Declaration has no name.");
691 vpVecPushn(spXml->vpVec32, uipName, uiNameLen);
703 XML_THROW(
"Notation Declaration syntax error. Name value of Notation should not be empty.");
707 &spNotation->sValue.uiOffset, &spNotation->sValue.uiLength);
713 XML_THROW(
"Notation Declaration syntax error. Expected closure not found");
721 spXml->uiElementDecls++;
727 vLogMsg(spXml, spXml->uiSavedOffset,
"Malformed element declaration.");
728 XML_THROW(
"Element declaration expected closure not found");
740 XML_THROW(
"mal formed reference, expected ; not found");