Changeset 38 for trunk/src/helpers/xmlparse.c
- Timestamp:
- Feb 17, 2001, 3:03:14 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/xmlparse.c
r36 r38 5 5 * SourceForge Oct 22, 2000. 6 6 * 7 * Expat is a library, written in C, for parsing XML documents. It's 7 * This was ported to and integrated with the xwphelpers 8 * for V0.9.9 (2001-02-10) [umoeller]. See xml.c for a general 9 * introduction to @XML support in the xwphelpers. 10 * 11 * Expat is a library, written in C, for parsing XML @documents. It's 8 12 * the underlying XML parser for the open source Mozilla project, 9 13 * perl's XML::Parser, and other open-source XML parsers. … … 18 22 * that comes with expat as an HTML file. I (umoeller) 19 23 * have integrated the docs into the sources and added a 20 * couple of remarks on the way. 21 * 22 * See XML_ParserCreate for an introduction to expat. 24 * couple of remarks while trying to implement parsers. 25 * 26 * See XML_ParserCreate for instructions how to parse XML. 27 * 28 * Note that expat is a non-validating XML processor. Validation 29 * is supported by the top layer of xwphelpers XML support. See 30 * xml.c. 23 31 * 24 32 *@@added V0.9.9 (2001-02-10) [umoeller] 33 *@@header "expat\expat.h" 25 34 */ 26 35 … … 48 57 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 49 58 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 59 */ 60 61 /* 62 *@@category: Helpers\C helpers\XML\expat 63 * expat XML parser. See xmlparse.c. 50 64 */ 51 65 … … 95 109 typedef char ICHAR; 96 110 #endif 97 98 111 99 112 #ifndef XML_NS … … 281 294 } OPEN_INTERNAL_ENTITY, *POPEN_INTERNAL_ENTITY; 282 295 283 typedef enum XML_ErrorProcessor(XML_Parser parser,296 typedef XMLERROR Processor(XML_Parser parser, 284 297 const char *start, 285 298 const char *end, … … 302 315 static Processor externalEntityContentProcessor; 303 316 304 static enum XML_ErrorhandleUnknownEncoding(XML_Parser parser,317 static XMLERROR handleUnknownEncoding(XML_Parser parser, 305 318 const XML_Char * encodingName); 306 static enum XML_ErrorprocessXmlDecl(XML_Parser parser,319 static XMLERROR processXmlDecl(XML_Parser parser, 307 320 int isGeneralTextEntity, 308 321 const char *, 309 322 const char *); 310 static enum XML_ErrorinitializeEncoding(XML_Parser parser);311 static enum XML_ErrordoProlog(XML_Parser parser,323 static XMLERROR initializeEncoding(XML_Parser parser); 324 static XMLERROR doProlog(XML_Parser parser, 312 325 const ENCODING * enc, 313 326 const char *s, … … 316 329 const char *next, 317 330 const char **nextPtr); 318 static enum XML_ErrorprocessInternalParamEntity(XML_Parser parser,331 static XMLERROR processInternalParamEntity(XML_Parser parser, 319 332 ENTITY * entity); 320 static enum XML_ErrordoContent(XML_Parser parser,333 static XMLERROR doContent(XML_Parser parser, 321 334 int startTagLevel, 322 335 const ENCODING * enc, … … 324 337 const char *end, 325 338 const char **endPtr); 326 static enum XML_ErrordoCdataSection(XML_Parser parser,339 static XMLERROR doCdataSection(XML_Parser parser, 327 340 const ENCODING *, 328 341 const char **startPtr, … … 331 344 332 345 #ifdef XML_DTD 333 static enum XML_ErrordoIgnoreSection(XML_Parser parser,346 static XMLERROR doIgnoreSection(XML_Parser parser, 334 347 const ENCODING *, 335 348 const char **startPtr, … … 338 351 #endif /* XML_DTD */ 339 352 340 static enum XML_ErrorstoreAtts(XML_Parser parser,353 static XMLERROR storeAtts(XML_Parser parser, 341 354 const ENCODING *, 342 355 const char *s, … … 356 369 XML_Parser parser); 357 370 358 static enum XML_ErrorstoreAttributeValue(XML_Parser parser,371 static XMLERROR storeAttributeValue(XML_Parser parser, 359 372 const ENCODING *, 360 373 int isCdata, … … 362 375 const char *, 363 376 STRING_POOL *); 364 static enum XML_ErrorappendAttributeValue(XML_Parser parser,377 static XMLERROR appendAttributeValue(XML_Parser parser, 365 378 const ENCODING *, 366 379 int isCdata, … … 373 386 const char *end); 374 387 static int setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *); 375 static enum XML_ErrorstoreEntityValue(XML_Parser parser,388 static XMLERROR storeEntityValue(XML_Parser parser, 376 389 const ENCODING * enc, 377 390 const char *start, … … 426 439 427 440 static int nextScaffoldPart(XML_Parser parser); 428 static XML _Content*build_model(XML_Parser parser);441 static XMLCONTENT *build_model(XML_Parser parser); 429 442 430 443 static const XML_Char *poolCopyString(STRING_POOL * pool, const XML_Char * s); … … 499 512 PROLOG_STATE m_prologState; 500 513 Processor *m_processor; 501 enum XML_Errorm_errorCode;514 XMLERROR m_errorCode; 502 515 const char *m_eventPtr; 503 516 const char *m_eventEndPtr; … … 631 644 *@@ XML_ParserCreate: 632 645 * constructs a new parser. If encoding is non-null, it specifies 633 * a character encoding to use for the document . This overrides634 * the document encoding declaration.646 * a character encoding to use for the document (see below). 647 * This overrides the document encoding declaration. 635 648 * 636 649 * Expat is a stream-oriented parser. You register callback (or … … 638 651 * the document. As the parser recognizes parts of the document, 639 652 * it will call the appropriate handler for that part (if you've 640 * registered one .)The document is fed to the parser in pieces,653 * registered one). The document is fed to the parser in pieces, 641 654 * so you can start parsing before you have all the document. 642 655 * This also allows you to parse really huge documents that won't … … 685 698 * 686 699 * The things you're likely to want to keep on a stack are the 687 * currently opened element and it 's attributes. You push this700 * currently opened element and its attributes. You push this 688 701 * information onto the stack in the start handler and you pop 689 702 * it off in the end handler. 690 703 * 691 704 * For some tasks, it is sufficient to just keep information on 692 * what the depth of the stack is (or would be if you had one .)705 * what the depth of the stack is (or would be if you had one). 693 706 * The outline program shown above presents one example. Another 694 707 * such task would be skipping over a complete element. When you … … 710 723 * While XML is based on Unicode, and every XML processor is 711 724 * required to recognized UTF-8 and UTF-16 (1 and 2 byte 712 * encodings of Unicode), other encodings may be declared in725 * encodings of Unicode), other @encodings may be declared in 713 726 * XML documents or entities. For the main document, an XML 714 727 * declaration may contain an encoding declaration in its 715 * @text_declaration: 716 * 717 + <?xml version="1.0" encoding="ISO-8859-2"?> 728 * @text_declaration. See @encodings for additional 729 * information. 718 730 * 719 731 * With expat, you may also specify an encoding at the time 720 732 * of creating a parser. This is useful when the encoding 721 733 * information may come from a source outside the document 722 * itself (like a higher level protocol.) 723 * 724 * There are four built-in encodings in expat: 725 * 726 * -- UTF-8: 8-bit encoding of Unicode. 727 * 728 * -- UTF-16: 16-bit encoding of Unicode. 729 * 730 * -- ISO-8859-1: that's "latin 1". 731 * 732 * -- US-ASCII 733 * 734 * Anything else discovered in an encoding declaration or in 735 * the protocol encoding specified in the parser constructor, 736 * triggers a call to the UnknownEncodingHandler (see 737 * XML_SetUnknownEncodingHandler). This handler gets passed 738 * the encoding name and a pointer to an XML_Encoding data 739 * structure. Your handler must fill in this structure and 740 * return 1 if it knows how to deal with the encoding. Otherwise 741 * the handler should return 0. The handler also gets passed a 742 * pointer to an optional application data structure that you may 743 * indicate when you set the handler. 734 * itself (like a higher level protocol). 735 * 736 * See XML_SetUnknownEncodingHandler for encodings directly 737 * supported by expat and for how to handle other encodings. 744 738 * 745 739 * One pitfall that novice expat users are likely to fall into is … … 751 745 * <B>Handling External Entity References</B> 752 746 * 753 * Expat does not read or parse external entities directly. Note that 754 * any external @DTD is a special case of an external entity. If you've 755 * set no ExternalEntityRefHandler (see XML_SetExternalEntityRefHandler), 756 * then external entity references are silently ignored. Otherwise, it 757 * calls your handler with the information needed to read and parse the 758 * external entity. 759 * 760 * <B>Parsing DTDs</B> 747 * Expat does not read or parse @external_entities directly. Note that 748 * any external @DTD is a special case of an external entity. For how to 749 * handle external entities, see XML_SetExternalEntityRefHandler. 750 * 751 * <B>Parsing Parameter Entities</B> 761 752 * 762 753 * In order to parse @parameter_entities, before starting the parse, … … 933 924 declNotationPublicId = 0; 934 925 memset(&position, 0, sizeof(POSITION)); 935 errorCode = XML_ERROR_NONE;926 errorCode = ERROR_EXPAT_NONE; 936 927 eventPtr = 0; 937 928 eventEndPtr = 0; … … 1349 1340 * This handler must have the following prototype: 1350 1341 * 1351 + void EXPATENTRY StartElementHandler(void * userData,1352 + const XML_Char *name,1353 + const XML_Char **atts);1342 + void EXPATENTRY StartElementHandler(void *pUserData, 1343 + const XML_Char *name, 1344 + const XML_Char **atts); 1354 1345 + 1355 1346 * "data" is the user data pointer set with XML_SetUserData. … … 1398 1389 * Handler prototype: 1399 1390 + 1400 + void EXPATENTRY (void *userData,1401 + const XML_Char *name);1391 + void EXPATENTRY EndElementHandler(void *pUserData, 1392 + const XML_Char *name); 1402 1393 */ 1403 1394 … … 1410 1401 /* 1411 1402 *@@ XML_SetCharacterDataHandler: 1412 * sets a character data (text ) handler.1403 * sets a character data (text, @content) handler. 1413 1404 * 1414 1405 * Handler prototype: 1415 1406 * 1416 + void EXPATENTRY CharacterDataHandler(void * userData,1417 + const XML_Char *s,1418 + int len);1407 + void EXPATENTRY CharacterDataHandler(void *pUserData, 1408 + const XML_Char *s, 1409 + int len); 1419 1410 + 1420 1411 * The string your handler receives is NOT zero terminated. … … 1438 1429 * Handler prototype: 1439 1430 * 1440 + void EXPATENTRY ProcessingInstructionHandler(void * userData,1441 + const XML_Char *target,1442 + const XML_Char *data);1431 + void EXPATENTRY ProcessingInstructionHandler(void *pUserData, 1432 + const XML_Char *target, 1433 + const XML_Char *data); 1443 1434 + 1444 1435 * The target is the first word in the processing instruction. The data … … 1460 1451 * Handler prototype: 1461 1452 * 1462 + void EXPATENTRY CommentHandler(void * userData,1463 + const XML_Char *data);1453 + void EXPATENTRY CommentHandler(void *pUserData, 1454 + const XML_Char *data); 1464 1455 * 1465 1456 */ … … 1492 1483 * Handler prototype: 1493 1484 * 1494 + void EXPATENTRY StartCdataSectionHandler(void * userData);1485 + void EXPATENTRY StartCdataSectionHandler(void *pUserData); 1495 1486 * 1496 1487 */ … … 1509 1500 * Handler prototype: 1510 1501 * 1511 * void EXPATENTRY EndCdataSectionHandler(void * userData);1502 * void EXPATENTRY EndCdataSectionHandler(void *pUserData); 1512 1503 */ 1513 1504 … … 1529 1520 * Handler prototype: 1530 1521 + 1531 + void EXPATENTRY DefaultHandler(void * userData,1532 + const XML_Char *s,1533 + int len);1522 + void EXPATENTRY DefaultHandler(void *pUserData, 1523 + const XML_Char *s, 1524 + int len); 1534 1525 * 1535 1526 * The characters are passed exactly as they were in the XML … … 1547 1538 * turning off expansion of references to internally defined 1548 1539 * general entities. Instead these references are passed to 1549 * the default handler. 1540 * the default handler. To avoid that, use XML_SetDefaultHandlerExpand. 1550 1541 */ 1551 1542 … … 1594 1585 * Handler prototype: 1595 1586 * 1596 + void EXPATENTRY StartDoctypeDeclHandler(void * userData,1597 + const XML_Char *doctypeName,1598 + const XML_Char *sysid,1599 + const XML_Char *pubid,1600 + int has_internal_subset);1601 * 1602 * Both sysid and pubid may be NULL. The has_internal_subset1587 + void EXPATENTRY StartDoctypeDeclHandler(void *pUserData, 1588 + const XML_Char *pcszDoctypeName, 1589 + const XML_Char *pcszSysid, 1590 + const XML_Char *pcszPubid, 1591 + int fHasInternalSubset); 1592 * 1593 * Both pcszSysid and pcszPubid may be NULL. "fHasInternalSubset" 1603 1594 * will be non-zero if the DOCTYPE declaration has an internal subset. 1604 1595 */ … … 1617 1608 * Handler prototype: 1618 1609 * 1619 + void EXPATENTRY EndDoctypeDeclHandler(void * userData);1610 + void EXPATENTRY EndDoctypeDeclHandler(void *pUserData); 1620 1611 * 1621 1612 */ … … 1651 1642 * Handler prototype: 1652 1643 + 1653 + void EXPATENTRY NotationDeclHandler(void * userData,1654 + const XML_Char *notationName,1655 + const XML_Char *base,1656 + const XML_Char *systemId,1657 + const XML_Char *publicId);1644 + void EXPATENTRY NotationDeclHandler(void *pUserData, 1645 + const XML_Char *pcszNotationName, 1646 + const XML_Char *pcszBase, 1647 + const XML_Char *pcszSystemId, 1648 + const XML_Char *pcszPublicId); 1658 1649 + 1659 1650 */ … … 1689 1680 * Handler prototype: 1690 1681 * 1691 + void EXPATENTRY StartNamespaceDeclHandler(void * userData,1692 + const XML_Char *prefix,1693 + const XML_Char *uri);1682 + void EXPATENTRY StartNamespaceDeclHandler(void *pUserData, 1683 + const XML_Char *prefix, 1684 + const XML_Char *uri); 1694 1685 + 1695 1686 */ … … 1710 1701 * Handler prototype: 1711 1702 + 1712 + void EXPATENTRY EndNamespaceDeclHandler )(void *userData,1713 + const XML_Char *prefix);1703 + void EXPATENTRY EndNamespaceDeclHandler(void *pUserData, 1704 + const XML_Char *prefix); 1714 1705 */ 1715 1706 … … 1728 1719 * not have standalone set to "yes" in an XML declaration. 1729 1720 * If this handler returns 0, then the parser will throw an 1730 * XML_ERROR_NOT_STANDALONE error.1721 * ERROR_EXPAT_NOT_STANDALONE error. 1731 1722 * 1732 1723 * Handler prototype: 1733 1724 * 1734 + int EXPATENTRY NotStandaloneHandler(void * userData);1725 + int EXPATENTRY NotStandaloneHandler(void *pUserData); 1735 1726 */ 1736 1727 … … 1743 1734 /* 1744 1735 *@@ XML_SetExternalEntityRefHandler: 1745 * sets an external entity reference handler. This handler is 1746 * also called for processing an external DTD subset if 1747 * parameter entity parsing is in effect. 1736 * sets a handler for references to @external_entities. 1737 * 1738 * This handler is also called for processing an external DTD 1739 * subset if parameter entity parsing is in effect. 1748 1740 * (See XML_SetParamEntityParsing.) 1741 * 1742 * Warning: If you have set no ExternalEntityRefHandler, then 1743 * external entity references are silently ignored. Otherwise, 1744 * they trigger a call to your handler with the information 1745 * needed to read and parse the external entity. 1749 1746 * 1750 1747 * Handler prototype: 1751 1748 + 1752 1749 + int EXPATENTRY ExternalEntityRefHandler(XML_Parser parser, 1753 + const XML_Char *context,1754 + const XML_Char *base,1755 + const XML_Char *systemId,1756 + const XML_Char *publicId);1750 + const XML_Char *pcszContext, 1751 + const XML_Char *pcszBase, 1752 + const XML_Char *pcszSystemId, 1753 + const XML_Char *pcszPublicId); 1757 1754 + 1758 * The context argument specifies the parsing context in the1755 * The pcszContext argument specifies the parsing context in the 1759 1756 * format expected by the context argument to 1760 * XML_ExternalEntityParserCreate; context is valid only until1757 * XML_ExternalEntityParserCreate; pcszContext is valid only until 1761 1758 * the handler returns, so if the referenced entity is to be 1762 1759 * parsed later, it must be copied. 1763 1760 * 1764 * The base parameter is the base to use for relative system1761 * The pcszBase parameter is the base to use for relative system 1765 1762 * identifiers. It is set by XML_SetBase and may be null. 1766 1763 * 1767 * The p ublicId parameter is the public id given in the entity1764 * The pcszPublicId parameter is the public id given in the entity 1768 1765 * declaration and may be null. 1769 1766 * 1770 * The systemId is the system identifier specified in the1767 * The pcszSystemId is the system identifier specified in the 1771 1768 * entity declaration and is never null. 1772 1769 * … … 1776 1773 * of the external entity reference. Returning a zero indicates 1777 1774 * failure, and causes the calling parser to return an 1778 * XML_ERROR_EXTERNAL_ENTITY_HANDLING error.1779 * 1780 * Second, instead of having userData as its first argument,1775 * ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING error. 1776 * 1777 * Second, instead of having pUserData as its first argument, 1781 1778 * it receives the parser that encountered the entity reference. 1782 1779 * This, along with the context parameter, may be used as … … 1790 1787 * Your handler isn't actually responsible for parsing the entity, 1791 1788 * but it is responsible for creating a subsidiary parser with 1792 * XML_ExternalEntityParserCreate that will do the job. Th isreturns1789 * XML_ExternalEntityParserCreate that will do the job. That returns 1793 1790 * an instance of XML_Parser that has handlers and other data 1794 1791 * structures initialized from the parent parser. You may then use 1795 * XML_Parse or XML_ParseBuffer calls against th isparser. Since1792 * XML_Parse or XML_ParseBuffer calls against that parser. Since 1796 1793 * external entities may refer to other external entities, your 1797 1794 * handler should be prepared to be called recursively. … … 1814 1811 /* 1815 1812 *@@ XML_SetUnknownEncodingHandler: 1816 * sets a handler to deal with encodings other than the 1817 * built in set (see XML_ParserCreate). 1813 * sets a handler to deal with @encodings other than the 1814 * built-in set. 1815 * 1816 * There are four built-in encodings in expat: 1817 * 1818 * -- UTF-8: 8-bit encoding of Unicode. 1819 * 1820 * -- UTF-16: 16-bit encoding of Unicode. 1821 * 1822 * -- ISO-8859-1: that's "latin 1". 1823 * 1824 * -- US-ASCII 1825 * 1826 * Anything else discovered in an encoding declaration or in 1827 * the protocol encoding specified in the parser constructor 1828 * triggers a call to the UnknownEncodingHandler. 1818 1829 * 1819 1830 * Handler prototype: 1820 1831 * 1821 1832 + int EXPATENTRY UnknownEncodingHandler(void *encodingHandlerData, 1822 + const XML_Char *name,1823 + XML_Encoding *info);1833 + const XML_Char *name, 1834 + XML_Encoding *info); 1824 1835 + 1825 1836 * The encodingHandlerData argument is that which was passed as the … … 1843 1854 * 1. Every ASCII character that can appear in a well-formed XML 1844 1855 * document must be represented by a single byte, and that byte 1845 * must correspond to it 's ASCII encoding (except for the1856 * must correspond to its ASCII encoding (except for the 1846 1857 * characters $@\^'{}~). 1847 1858 * … … 1852 1863 * the built-in support for UTF-16 and UTF-8.) 1853 1864 * 1854 * 4. No character may be encoded by more tha tone distinct1865 * 4. No character may be encoded by more than one distinct 1855 1866 * sequence of bytes. 1856 1867 */ … … 1866 1877 /* 1867 1878 *@@ XML_SetElementDeclHandler: 1868 * sets a handler for element declarations in aDTD. The1879 * sets a handler for an @element_declaration in a @DTD. The 1869 1880 * handler gets called with the name of the element in 1870 1881 * the declaration and a pointer to a structure that contains … … 1874 1885 * This handler must have the following prototype: 1875 1886 * 1876 + void EXPATENTRY ElementDeclHandler(void *userData, 1877 + const XML_Char *name, 1878 + XML_Content *model); 1879 * 1880 * The model argument is the root of a tree of XML_Content 1881 * nodes. If type equals XML_CTYPE_EMPTY or XML_CTYPE_ANY, 1882 * then quant will be XML_CQUANT_NONE, and the other fields 1883 * will be zero or NULL. 1884 * 1885 * If type is XML_CTYPE_MIXED, then quant will be 1886 * XML_CQUANT_NONE or XML_CQUANT_REP and numchildren will 1887 * contain the number of elements that are allowed to be 1888 * mixed in and children points to an array of XML_Content 1889 * structures that will all have type XML_CTYPE_NAME with no 1890 * quantification. Only the root node can be type 1891 * XML_CTYPE_EMPTY, XML_CTYPE_ANY, or XML_CTYPE_MIXED. 1892 * 1893 * For type XML_CTYPE_NAME, the name field points to the 1894 * name and the numchildren and children fields will be 1895 * zero and NULL. The quant field will indicate any 1896 * quantifiers placed on the name. 1897 * 1898 * Types XML_CTYPE_CHOICE and XML_CTYPE_SEQ indicate a 1899 * choice or sequence respectively. The numchildren field 1900 * indicates how many nodes in the choice or sequence and 1901 * children points to the nodes. 1887 + void EXPATENTRY ElementDeclHandler(void *pUserData, 1888 + const XML_Char *name, 1889 + XMLCONTENT *model); 1890 * 1891 * See _XMLCONTENT for details. 1902 1892 */ 1903 1893 … … 1910 1900 /* 1911 1901 *@@ XML_SetAttlistDeclHandler: 1912 * sets a handler for a ttlist declarations in theDTD.1902 * sets a handler for an @attribute_declaration in the @DTD. 1913 1903 * 1914 1904 * This handler must have the following prototype: 1915 1905 * 1916 + void EXPATENTRY AttlistDeclHandler(void * userData,1917 + const XML_Char *elname,1918 + const XML_Char *attname,1919 + const XML_Char *att_type,1920 + const XML_Char *dflt,1921 + int isrequired);1906 + void EXPATENTRY AttlistDeclHandler(void *pUserData, 1907 + const XML_Char *pcszElementName, 1908 + const XML_Char *pcszAttribName, 1909 + const XML_Char *pcszAttribType, 1910 + const XML_Char *pcszDefault, 1911 + int fIsRequired); 1922 1912 * 1923 1913 * This handler is called for each attribute. So a single attlist 1924 1914 * declaration with multiple attributes declared will generate 1925 * multiple calls to this handler. The elname parameter 1926 * returns the name of the element for which the attribute 1927 * is being declared. The attribute name is in the attname 1928 * parameter. The attribute type is in the att_type parameter. 1929 * It is the string representing the type in the declaration 1930 * with whitespace removed. 1931 * 1932 * The dflt parameter holds the default value. It will be 1933 * NULL in the case of "#IMPLIED" or "#REQUIRED" attributes. 1934 * You can distinguish these two cases by checking the 1935 * isrequired parameter, which will be true in the case of 1936 * "#REQUIRED" attributes. Attributes which are "#FIXED" 1937 * will have also have a true isrequired, but they will have 1938 * the non-NULL fixed value in the dflt parameter. 1915 * multiple calls to this handler. 1916 * 1917 * -- pcszElementName is the name of the element for which the 1918 * attribute is being declared. 1919 * 1920 * -- pcszAttribName has the attribute name being declared. 1921 * 1922 * -- pcszAttribType is the attribute type. 1923 * It is the string representing the type in the declaration 1924 * with whitespace removed. 1925 * 1926 * -- pcszDefault holds the default value. It will be 1927 * NULL in the case of "#IMPLIED" or "#REQUIRED" attributes. 1928 * You can distinguish these two cases by checking the 1929 * fIsRequired parameter, which will be true in the case of 1930 * "#REQUIRED" attributes. Attributes which are "#FIXED" 1931 * will have also have a TRUE fIsRequired, but they will have 1932 * the non-NULL fixed value in the pcszDefault parameter. 1939 1933 */ 1940 1934 … … 1951 1945 * Handler prototype: 1952 1946 * 1953 + void EXPATENTRY EntityDeclHandler(void * userData,1954 + const XML_Char *entityName,1955 + int is_parameter_entity,1956 + const XML_Char *value,1957 + int value_length,1958 + const XML_Char *base,1959 + const XML_Char *systemId,1960 + const XML_Char *publicId,1961 + const XML_Char *notationName);1947 + void EXPATENTRY EntityDeclHandler(void *pUserData, 1948 + const XML_Char *pcszEntityName, 1949 + int fIsParameterEntity, 1950 + const XML_Char *pcszValue, 1951 + int iValueLength, 1952 + const XML_Char *pcszBase, 1953 + const XML_Char *pcszSystemId, 1954 + const XML_Char *pcszPublicId, 1955 + const XML_Char *pcszNotationName); 1962 1956 + 1963 * The is_parameter_entity argument will be non-zero in the case1957 * The fIsParameterEntity argument will be non-zero in the case 1964 1958 * of parameter entities and zero otherwise. 1965 1959 * 1966 * For internal entities (<!ENTITY foo "bar">), value will be1967 * non-NULL and systemId, publicId, and notationName will all1968 * be NULL. The value string is not NULL terminated; the length1969 * is provided in the value_length parameter. Do not use1970 * value_length to test for internal entities, since it is legal1960 * For internal entities (<!ENTITY foo "bar">), pcszValue will be 1961 * non-NULL and pcszSystemId, pcszPublicId, and pcszNotationName 1962 * will all be NULL. The value string is not NULL terminated; the 1963 * lengthis provided in the iValueLength parameter. Do not use 1964 * iValueLength to test for internal entities, since it is legal 1971 1965 * to have zero-length values. Instead check for whether or not 1972 * value is NULL.1973 * 1974 * The notationName argument will have a non-NULL value only for1975 * unparsed entity declarations.1966 * pcszValue is NULL. 1967 * 1968 * The pcszNotationName argument will have a non-NULL value only 1969 * for unparsed entity declarations. 1976 1970 */ 1977 1971 … … 1989 1983 * Handler prototype: 1990 1984 * 1991 + void EXPATENTRY XmlDeclHandler(void *userData,1992 + const XML_Char *version,1993 + const XML_Char *encoding,1994 + intstandalone);1985 + void EXPATENTRY XmlDeclHandler(void *pUserData, 1986 + const XML_Char *pcszVersion, 1987 + const XML_Char *pcszEncoding, 1988 + int standalone); 1995 1989 * 1996 1990 * The way to distinguish is that the version parameter will … … 2010 2004 /* 2011 2005 *@@ XML_SetParamEntityParsing: 2012 * this enables parsing of parameter entities, including the 2013 * external parameter entity that is the external DTD subset, 2014 * according to code. The choices for code are: 2006 * this enables parsing of @parameter_entities, including the 2007 * external parameter entity that is the external @DTD subset, 2008 * according to code. 2009 * 2010 * If parsing of parameter entities is enabled, then references 2011 * to external parameter entities (including the external DTD 2012 * subset) will be passed to the handler set with 2013 * XML_SetExternalEntityRefHandler. The context passed will be 0. 2014 * 2015 * Unlike external general entities, external parameter entities 2016 * can only be parsed synchronously. If the external parameter 2017 * entity is to be parsed, it must be parsed during the call to 2018 * the external entity ref handler: the complete sequence of 2019 * XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and 2020 * XML_ParserFree calls must be made during this call. 2021 * 2022 * After XML_ExternalEntityParserCreate has been called to create 2023 * the parser for the external parameter entity (context must be 0 2024 * for this call), it is illegal to make any calls on the old parser 2025 * until XML_ParserFree has been called on the newly created parser. 2026 * If the library has been compiled without support for parameter 2027 * entity parsing (ie without XML_DTD being defined), then 2028 * XML_SetParamEntityParsing will return 0 if parsing of parameter 2029 * entities is requested; otherwise it will return non-zero. 2030 * 2031 * NOTE: The xwphelpers implementation #defines XML_DTD in 2032 * include\expat\expat_setup.h, which is included in all expat 2033 * files. 2034 * 2035 * The choices for code are: 2015 2036 * 2016 2037 * -- XML_PARAM_ENTITY_PARSING_NEVER: 2017 * Don't parse parameter entities or the external subset 2038 * Don't parse parameter entities or the external subset. 2039 * This is the only choice if XML_DTD is not defined. 2018 2040 * 2019 2041 * -- XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE: 2020 * Parse parameter entit es and the external subset unless2042 * Parse parameter entities and the external subset unless 2021 2043 * standalone was set to "yes" in the XML declaration. 2022 2044 * … … 2067 2089 return 1; 2068 2090 positionPtr = bufferPtr; 2069 errorCode = processor(parser, bufferPtr, parseEndPtr = bufferEnd, 0); 2070 if (errorCode == XML_ERROR_NONE) 2091 errorCode = processor(parser, 2092 bufferPtr, 2093 parseEndPtr = bufferEnd, 2094 0); 2095 if (errorCode == ERROR_EXPAT_NONE) 2071 2096 return 1; 2072 2097 eventEndPtr = eventPtr; … … 2084 2109 if (isFinal) 2085 2110 { 2086 errorCode = processor(parser, s, parseEndPtr = s + len, 0); 2087 if (errorCode == XML_ERROR_NONE) 2111 errorCode = processor(parser, 2112 s, 2113 parseEndPtr = s + len, 2114 0); 2115 if (errorCode == ERROR_EXPAT_NONE) 2088 2116 return 1; 2089 2117 eventEndPtr = eventPtr; … … 2092 2120 } 2093 2121 errorCode = processor(parser, s, parseEndPtr = s + len, &end); 2094 if (errorCode != XML_ERROR_NONE)2122 if (errorCode != ERROR_EXPAT_NONE) 2095 2123 { 2096 2124 eventEndPtr = eventPtr; … … 2109 2137 if (!buffer) 2110 2138 { 2111 errorCode = XML_ERROR_NO_MEMORY;2139 errorCode = ERROR_EXPAT_NO_MEMORY; 2112 2140 eventPtr = eventEndPtr = 0; 2113 2141 processor = errorProcessor; … … 2147 2175 errorCode = processor(parser, start, parseEndPtr = bufferEnd, 2148 2176 isFinal ? (const char **)0 : &bufferPtr); 2149 if (errorCode == XML_ERROR_NONE)2177 if (errorCode == ERROR_EXPAT_NONE) 2150 2178 { 2151 2179 if (!isFinal) … … 2236 2264 if (newBuf == 0) 2237 2265 { 2238 errorCode = XML_ERROR_NO_MEMORY;2266 errorCode = ERROR_EXPAT_NO_MEMORY; 2239 2267 return 0; 2240 2268 } … … 2289 2317 */ 2290 2318 2291 enum XML_ErrorXML_GetErrorCode(XML_Parser parser)2319 XMLERROR XML_GetErrorCode(XML_Parser parser) 2292 2320 { 2293 2321 return errorCode; … … 2357 2385 * returns the line number of the position. 2358 2386 * 2359 * Tobe called on parser errors. See XML_GetErrorCode.2387 * Can be called on parser errors. See XML_GetErrorCode. 2360 2388 */ 2361 2389 … … 2375 2403 * line, of the position. 2376 2404 * 2377 * Tobe called on parser errors. See XML_GetErrorCode.2405 * Can be called on parser errors. See XML_GetErrorCode. 2378 2406 */ 2379 2407 … … 2408 2436 2409 2437 /* 2410 *@@ XML_ErrorString:2411 * returns a string describing the error corresponding to code.2412 * The code should be one of the enums that can be returned from2413 * XML_GetErrorCode.2414 */2415 2416 const XML_LChar* XML_ErrorString(int code)2417 {2418 static const XML_LChar *message[] =2419 {2420 0,2421 XML_T("out of memory"),2422 XML_T("syntax error"),2423 XML_T("no element found"),2424 XML_T("not well-formed (invalid token)"),2425 XML_T("unclosed token"),2426 XML_T("unclosed token"),2427 XML_T("mismatched tag"),2428 XML_T("duplicate attribute"),2429 XML_T("junk after document element"),2430 XML_T("illegal parameter entity reference"),2431 XML_T("undefined entity"),2432 XML_T("recursive entity reference"),2433 XML_T("asynchronous entity"),2434 XML_T("reference to invalid character number"),2435 XML_T("reference to binary entity"),2436 XML_T("reference to external entity in attribute"),2437 XML_T("xml processing instruction not at start of external entity"),2438 XML_T("unknown encoding"),2439 XML_T("encoding specified in XML declaration is incorrect"),2440 XML_T("unclosed CDATA section"),2441 XML_T("error in processing external entity reference"),2442 XML_T("document is not standalone"),2443 XML_T("unexpected parser state - please send a bug report")2444 };2445 2446 if (code > 0 && code < sizeof(message) / sizeof(message[0]))2447 return message[code];2448 return 0;2449 }2450 2451 /*2452 2438 *@@ XML_ExpatVersion: 2453 2439 * returns the library version string (e.g. "expat_1.95.1"). … … 2459 2445 } 2460 2446 2461 static enum XML_ErrorcontentProcessor(XML_Parser parser,2447 static XMLERROR contentProcessor(XML_Parser parser, 2462 2448 const char *start, 2463 2449 const char *end, … … 2467 2453 } 2468 2454 2469 static enum XML_ErrorexternalEntityInitProcessor(XML_Parser parser,2455 static XMLERROR externalEntityInitProcessor(XML_Parser parser, 2470 2456 const char *start, 2471 2457 const char *end, 2472 2458 const char **endPtr) 2473 2459 { 2474 enum XML_Errorresult = initializeEncoding(parser);2475 2476 if (result != XML_ERROR_NONE)2460 XMLERROR result = initializeEncoding(parser); 2461 2462 if (result != ERROR_EXPAT_NONE) 2477 2463 return result; 2478 2464 processor = externalEntityInitProcessor2; … … 2480 2466 } 2481 2467 2482 static enum XML_ErrorexternalEntityInitProcessor2(XML_Parser parser,2468 static XMLERROR externalEntityInitProcessor2(XML_Parser parser, 2483 2469 const char *start, 2484 2470 const char *end, … … 2497 2483 { 2498 2484 *endPtr = start; 2499 return XML_ERROR_NONE;2485 return ERROR_EXPAT_NONE; 2500 2486 } 2501 2487 eventPtr = start; 2502 return XML_ERROR_UNCLOSED_TOKEN;2488 return ERROR_EXPAT_UNCLOSED_TOKEN; 2503 2489 case XML_TOK_PARTIAL_CHAR: 2504 2490 if (endPtr) 2505 2491 { 2506 2492 *endPtr = start; 2507 return XML_ERROR_NONE;2493 return ERROR_EXPAT_NONE; 2508 2494 } 2509 2495 eventPtr = start; 2510 return XML_ERROR_PARTIAL_CHAR;2496 return ERROR_EXPAT_PARTIAL_CHAR; 2511 2497 } 2512 2498 processor = externalEntityInitProcessor3; … … 2514 2500 } 2515 2501 2516 static enum XML_ErrorexternalEntityInitProcessor3(XML_Parser parser,2502 static XMLERROR externalEntityInitProcessor3(XML_Parser parser, 2517 2503 const char *start, 2518 2504 const char *end, … … 2526 2512 case XML_TOK_XML_DECL: 2527 2513 { 2528 enum XML_Errorresult = processXmlDecl(parser, 1, start, next);2529 2530 if (result != XML_ERROR_NONE)2514 XMLERROR result = processXmlDecl(parser, 1, start, next); 2515 2516 if (result != ERROR_EXPAT_NONE) 2531 2517 return result; 2532 2518 start = next; … … 2537 2523 { 2538 2524 *endPtr = start; 2539 return XML_ERROR_NONE;2525 return ERROR_EXPAT_NONE; 2540 2526 } 2541 2527 eventPtr = start; 2542 return XML_ERROR_UNCLOSED_TOKEN;2528 return ERROR_EXPAT_UNCLOSED_TOKEN; 2543 2529 case XML_TOK_PARTIAL_CHAR: 2544 2530 if (endPtr) 2545 2531 { 2546 2532 *endPtr = start; 2547 return XML_ERROR_NONE;2533 return ERROR_EXPAT_NONE; 2548 2534 } 2549 2535 eventPtr = start; 2550 return XML_ERROR_PARTIAL_CHAR;2536 return ERROR_EXPAT_PARTIAL_CHAR; 2551 2537 } 2552 2538 processor = externalEntityContentProcessor; … … 2555 2541 } 2556 2542 2557 static enum XML_ErrorexternalEntityContentProcessor(XML_Parser parser,2543 static XMLERROR externalEntityContentProcessor(XML_Parser parser, 2558 2544 const char *start, 2559 2545 const char *end, … … 2563 2549 } 2564 2550 2565 static enum XML_Error2551 static XMLERROR 2566 2552 doContent(XML_Parser parser, 2567 2553 int startTagLevel, … … 2597 2583 { 2598 2584 *nextPtr = s; 2599 return XML_ERROR_NONE;2585 return ERROR_EXPAT_NONE; 2600 2586 } 2601 2587 *eventEndPP = end; … … 2609 2595 reportDefault(parser, enc, s, end); 2610 2596 if (startTagLevel == 0) 2611 return XML_ERROR_NO_ELEMENTS;2597 return ERROR_EXPAT_NO_ELEMENTS; 2612 2598 if (tagLevel != startTagLevel) 2613 return XML_ERROR_ASYNC_ENTITY;2614 return XML_ERROR_NONE;2599 return ERROR_EXPAT_ASYNC_ENTITY; 2600 return ERROR_EXPAT_NONE; 2615 2601 case XML_TOK_NONE: 2616 2602 if (nextPtr) 2617 2603 { 2618 2604 *nextPtr = s; 2619 return XML_ERROR_NONE;2605 return ERROR_EXPAT_NONE; 2620 2606 } 2621 2607 if (startTagLevel > 0) 2622 2608 { 2623 2609 if (tagLevel != startTagLevel) 2624 return XML_ERROR_ASYNC_ENTITY;2625 return XML_ERROR_NONE;2626 } 2627 return XML_ERROR_NO_ELEMENTS;2610 return ERROR_EXPAT_ASYNC_ENTITY; 2611 return ERROR_EXPAT_NONE; 2612 } 2613 return ERROR_EXPAT_NO_ELEMENTS; 2628 2614 case XML_TOK_INVALID: 2629 2615 *eventPP = next; 2630 return XML_ERROR_INVALID_TOKEN;2616 return ERROR_EXPAT_INVALID_TOKEN; 2631 2617 case XML_TOK_PARTIAL: 2632 2618 if (nextPtr) 2633 2619 { 2634 2620 *nextPtr = s; 2635 return XML_ERROR_NONE;2636 } 2637 return XML_ERROR_UNCLOSED_TOKEN;2621 return ERROR_EXPAT_NONE; 2622 } 2623 return ERROR_EXPAT_UNCLOSED_TOKEN; 2638 2624 case XML_TOK_PARTIAL_CHAR: 2639 2625 if (nextPtr) 2640 2626 { 2641 2627 *nextPtr = s; 2642 return XML_ERROR_NONE;2643 } 2644 return XML_ERROR_PARTIAL_CHAR;2628 return ERROR_EXPAT_NONE; 2629 } 2630 return ERROR_EXPAT_PARTIAL_CHAR; 2645 2631 case XML_TOK_ENTITY_REF: 2646 2632 { … … 2663 2649 next - enc->minBytesPerChar); 2664 2650 if (!name) 2665 return XML_ERROR_NO_MEMORY;2651 return ERROR_EXPAT_NO_MEMORY; 2666 2652 entity = (ENTITY*)lookup(&dtd.generalEntities, name, 0); 2667 2653 poolDiscard(&dtd.pool); … … 2669 2655 { 2670 2656 if (dtd.complete || dtd.standalone) 2671 return XML_ERROR_UNDEFINED_ENTITY;2657 return ERROR_EXPAT_UNDEFINED_ENTITY; 2672 2658 if (defaultHandler) 2673 2659 reportDefault(parser, enc, s, next); … … 2675 2661 } 2676 2662 if (entity->open) 2677 return XML_ERROR_RECURSIVE_ENTITY_REF;2663 return ERROR_EXPAT_RECURSIVE_ENTITY_REF; 2678 2664 if (entity->notation) 2679 return XML_ERROR_BINARY_ENTITY_REF;2665 return ERROR_EXPAT_BINARY_ENTITY_REF; 2680 2666 if (entity) 2681 2667 { 2682 2668 if (entity->textPtr) 2683 2669 { 2684 enum XML_Errorresult;2670 XMLERROR result; 2685 2671 OPEN_INTERNAL_ENTITY openEntity; 2686 2672 … … 2715 2701 entity->open = 0; 2716 2702 if (!context) 2717 return XML_ERROR_NO_MEMORY;2703 return ERROR_EXPAT_NO_MEMORY; 2718 2704 if (!externalEntityRefHandler(externalEntityRefHandlerArg, 2719 2705 context, … … 2721 2707 entity->systemId, 2722 2708 entity->publicId)) 2723 return XML_ERROR_EXTERNAL_ENTITY_HANDLING;2709 return ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING; 2724 2710 poolDiscard(&tempPool); 2725 2711 } … … 2732 2718 if (!startElementHandler) 2733 2719 { 2734 enum XML_Errorresult = storeAtts(parser, enc, s, 0, 0);2720 XMLERROR result = storeAtts(parser, enc, s, 0, 0); 2735 2721 2736 2722 if (result) … … 2751 2737 tag = (TAG*)MALLOC(sizeof(TAG)); 2752 2738 if (!tag) 2753 return XML_ERROR_NO_MEMORY;2739 return ERROR_EXPAT_NO_MEMORY; 2754 2740 tag->buf = (char*)MALLOC(INIT_TAG_BUF_SIZE); 2755 2741 if (!tag->buf) 2756 return XML_ERROR_NO_MEMORY;2742 return ERROR_EXPAT_NO_MEMORY; 2757 2743 tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE; 2758 2744 } … … 2774 2760 tag->buf = (char*)REALLOC(tag->buf, bufSize); 2775 2761 if (!tag->buf) 2776 return XML_ERROR_NO_MEMORY;2762 return ERROR_EXPAT_NO_MEMORY; 2777 2763 tag->bufEnd = tag->buf + bufSize; 2778 2764 } … … 2783 2769 if (startElementHandler) 2784 2770 { 2785 enum XML_Errorresult;2771 XMLERROR result; 2786 2772 XML_Char *toPtr; 2787 2773 … … 2805 2791 tag->buf = (char*)REALLOC(tag->buf, bufSize); 2806 2792 if (!tag->buf) 2807 return XML_ERROR_NO_MEMORY;2793 return ERROR_EXPAT_NO_MEMORY; 2808 2794 tag->bufEnd = tag->buf + bufSize; 2809 2795 if (nextPtr) … … 2828 2814 if (!startElementHandler) 2829 2815 { 2830 enum XML_Errorresult = storeAtts(parser, enc, s, 0, 0);2816 XMLERROR result = storeAtts(parser, enc, s, 0, 0); 2831 2817 2832 2818 if (result) … … 2838 2824 { 2839 2825 const char *rawName = s + enc->minBytesPerChar; 2840 enum XML_Errorresult;2826 XMLERROR result; 2841 2827 BINDING *bindings = 0; 2842 2828 TAG_NAME name; … … 2845 2831 rawName + XmlNameLength(enc, rawName)); 2846 2832 if (!name.str) 2847 return XML_ERROR_NO_MEMORY;2833 return ERROR_EXPAT_NO_MEMORY; 2848 2834 poolFinish(&tempPool); 2849 2835 result = storeAtts(parser, enc, s, &name, &bindings); … … 2879 2865 case XML_TOK_END_TAG: 2880 2866 if (tagLevel == startTagLevel) 2881 return XML_ERROR_ASYNC_ENTITY;2867 return ERROR_EXPAT_ASYNC_ENTITY; 2882 2868 else 2883 2869 { … … 2895 2881 { 2896 2882 *eventPP = rawName; 2897 return XML_ERROR_TAG_MISMATCH;2883 return ERROR_EXPAT_TAG_MISMATCH; 2898 2884 } 2899 2885 --tagLevel; … … 2932 2918 2933 2919 if (n < 0) 2934 return XML_ERROR_BAD_CHAR_REF;2920 return ERROR_EXPAT_BAD_CHAR_REF; 2935 2921 if (characterDataHandler) 2936 2922 { … … 2944 2930 break; 2945 2931 case XML_TOK_XML_DECL: 2946 return XML_ERROR_MISPLACED_XML_PI;2932 return ERROR_EXPAT_MISPLACED_XML_PI; 2947 2933 case XML_TOK_DATA_NEWLINE: 2948 2934 if (characterDataHandler) … … 2957 2943 case XML_TOK_CDATA_SECT_OPEN: 2958 2944 { 2959 enum XML_Errorresult;2945 XMLERROR result; 2960 2946 2961 2947 if (startCdataSectionHandler) … … 2990 2976 { 2991 2977 *nextPtr = s; 2992 return XML_ERROR_NONE;2978 return ERROR_EXPAT_NONE; 2993 2979 } 2994 2980 if (characterDataHandler) … … 3011 2997 { 3012 2998 *eventPP = end; 3013 return XML_ERROR_NO_ELEMENTS;2999 return ERROR_EXPAT_NO_ELEMENTS; 3014 3000 } 3015 3001 if (tagLevel != startTagLevel) 3016 3002 { 3017 3003 *eventPP = end; 3018 return XML_ERROR_ASYNC_ENTITY;3019 } 3020 return XML_ERROR_NONE;3004 return ERROR_EXPAT_ASYNC_ENTITY; 3005 } 3006 return ERROR_EXPAT_NONE; 3021 3007 case XML_TOK_DATA_CHARS: 3022 3008 if (characterDataHandler) … … 3046 3032 case XML_TOK_PI: 3047 3033 if (!reportProcessingInstruction(parser, enc, s, next)) 3048 return XML_ERROR_NO_MEMORY;3034 return ERROR_EXPAT_NO_MEMORY; 3049 3035 break; 3050 3036 case XML_TOK_COMMENT: 3051 3037 if (!reportComment(parser, enc, s, next)) 3052 return XML_ERROR_NO_MEMORY;3038 return ERROR_EXPAT_NO_MEMORY; 3053 3039 break; 3054 3040 default: … … 3065 3051 * otherwise just check the attributes for well-formedness. */ 3066 3052 3067 static enum XML_ErrorstoreAtts(XML_Parser parser,3053 static XMLERROR storeAtts(XML_Parser parser, 3068 3054 const ENCODING * enc, 3069 3055 const char *attStr, … … 3089 3075 tagNamePtr->str = poolCopyString(&dtd.pool, tagNamePtr->str); 3090 3076 if (!tagNamePtr->str) 3091 return XML_ERROR_NO_MEMORY;3077 return ERROR_EXPAT_NO_MEMORY; 3092 3078 elementType = (ELEMENT_TYPE*)lookup(&dtd.elementTypes, tagNamePtr->str, sizeof(ELEMENT_TYPE)); 3093 3079 if (!elementType) 3094 return XML_ERROR_NO_MEMORY;3080 return ERROR_EXPAT_NO_MEMORY; 3095 3081 if (ns && !setElementTypePrefix(parser, elementType)) 3096 return XML_ERROR_NO_MEMORY;3082 return ERROR_EXPAT_NO_MEMORY; 3097 3083 } 3098 3084 nDefaultAtts = elementType->nDefaultAtts; … … 3107 3093 atts = (PATTRIBUTE)REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE)); 3108 3094 if (!atts) 3109 return XML_ERROR_NO_MEMORY;3095 return ERROR_EXPAT_NO_MEMORY; 3110 3096 if (n > oldAttsSize) 3111 3097 XmlGetAttributes(enc, attStr, n, atts); … … 3120 3106 3121 3107 if (!attId) 3122 return XML_ERROR_NO_MEMORY;3108 return ERROR_EXPAT_NO_MEMORY; 3123 3109 /* detect duplicate attributes */ 3124 3110 if ((attId->name)[-1]) … … 3126 3112 if (enc == encoding) 3127 3113 eventPtr = atts[i].name; 3128 return XML_ERROR_DUPLICATE_ATTRIBUTE;3114 return ERROR_EXPAT_DUPLICATE_ATTRIBUTE; 3129 3115 } 3130 3116 (attId->name)[-1] = 1; … … 3132 3118 if (!atts[i].normalized) 3133 3119 { 3134 enum XML_Errorresult;3120 XMLERROR result; 3135 3121 int isCdata = 1; 3136 3122 … … 3169 3155 appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr, atts[i].valueEnd); 3170 3156 if (appAtts[attIndex] == 0) 3171 return XML_ERROR_NO_MEMORY;3157 return ERROR_EXPAT_NO_MEMORY; 3172 3158 poolFinish(&tempPool); 3173 3159 } … … 3179 3165 /* deal with namespace declarations here */ 3180 3166 if (!addBinding(parser, attId->prefix, attId, appAtts[attIndex], bindingsPtr)) 3181 return XML_ERROR_NO_MEMORY;3167 return ERROR_EXPAT_NO_MEMORY; 3182 3168 --attIndex; 3183 3169 } … … 3221 3207 { 3222 3208 if (!addBinding(parser, da->id->prefix, da->id, da->value, bindingsPtr)) 3223 return XML_ERROR_NO_MEMORY;3209 return ERROR_EXPAT_NO_MEMORY; 3224 3210 } 3225 3211 else … … 3262 3248 { 3263 3249 if (!poolAppendChar(&tempPool, b->uri[j])) 3264 return XML_ERROR_NO_MEMORY;3250 return ERROR_EXPAT_NO_MEMORY; 3265 3251 } 3266 3252 while (*s++ != ':') … … 3269 3255 { 3270 3256 if (!poolAppendChar(&tempPool, *s)) 3271 return XML_ERROR_NO_MEMORY;3257 return ERROR_EXPAT_NO_MEMORY; 3272 3258 } 3273 3259 while (*s++); … … 3279 3265 { 3280 3266 if (!poolAppendChar(&tempPool, *s)) 3281 return XML_ERROR_NO_MEMORY;3267 return ERROR_EXPAT_NO_MEMORY; 3282 3268 } 3283 3269 while (*s++); … … 3298 3284 ((XML_Char*)(appAtts[i]))[-1] = 0; 3299 3285 if (!tagNamePtr) 3300 return XML_ERROR_NONE;3286 return ERROR_EXPAT_NONE; 3301 3287 for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding) 3302 3288 binding->attId->name[-1] = 0; … … 3306 3292 binding = elementType->prefix->binding; 3307 3293 if (!binding) 3308 return XML_ERROR_NONE;3294 return ERROR_EXPAT_NONE; 3309 3295 localPart = tagNamePtr->str; 3310 3296 while (*localPart++ != XML_T(':')) … … 3317 3303 } 3318 3304 else 3319 return XML_ERROR_NONE;3305 return ERROR_EXPAT_NONE; 3320 3306 tagNamePtr->localPart = localPart; 3321 3307 tagNamePtr->uriLen = binding->uriLen; … … 3329 3315 3330 3316 if (!uri) 3331 return XML_ERROR_NO_MEMORY;3317 return ERROR_EXPAT_NO_MEMORY; 3332 3318 binding->uriAlloc = n + EXPAND_SPARE; 3333 3319 memcpy(uri, binding->uri, binding->uriLen * sizeof(XML_Char)); … … 3340 3326 memcpy(binding->uri + binding->uriLen, localPart, i * sizeof(XML_Char)); 3341 3327 tagNamePtr->str = binding->uri; 3342 return XML_ERROR_NONE;3328 return ERROR_EXPAT_NONE; 3343 3329 } 3344 3330 … … 3399 3385 * the whole file is parsed with one call. */ 3400 3386 3401 static enum XML_ErrorcdataSectionProcessor(XML_Parser parser,3387 static XMLERROR cdataSectionProcessor(XML_Parser parser, 3402 3388 const char *start, 3403 3389 const char *end, 3404 3390 const char **endPtr) 3405 3391 { 3406 enum XML_Errorresult = doCdataSection(parser, encoding, &start, end, endPtr);3392 XMLERROR result = doCdataSection(parser, encoding, &start, end, endPtr); 3407 3393 3408 3394 if (start) … … 3417 3403 * the section is not yet closed. */ 3418 3404 3419 static enum XML_ErrordoCdataSection(XML_Parser parser,3405 static XMLERROR doCdataSection(XML_Parser parser, 3420 3406 const ENCODING * enc, 3421 3407 const char **startPtr, … … 3459 3445 reportDefault(parser, enc, s, next); 3460 3446 *startPtr = next; 3461 return XML_ERROR_NONE;3447 return ERROR_EXPAT_NONE; 3462 3448 case XML_TOK_DATA_NEWLINE: 3463 3449 if (characterDataHandler) … … 3497 3483 case XML_TOK_INVALID: 3498 3484 *eventPP = next; 3499 return XML_ERROR_INVALID_TOKEN;3485 return ERROR_EXPAT_INVALID_TOKEN; 3500 3486 case XML_TOK_PARTIAL_CHAR: 3501 3487 if (nextPtr) 3502 3488 { 3503 3489 *nextPtr = s; 3504 return XML_ERROR_NONE;3505 } 3506 return XML_ERROR_PARTIAL_CHAR;3490 return ERROR_EXPAT_NONE; 3491 } 3492 return ERROR_EXPAT_PARTIAL_CHAR; 3507 3493 case XML_TOK_PARTIAL: 3508 3494 case XML_TOK_NONE: … … 3510 3496 { 3511 3497 *nextPtr = s; 3512 return XML_ERROR_NONE;3513 } 3514 return XML_ERROR_UNCLOSED_CDATA_SECTION;3498 return ERROR_EXPAT_NONE; 3499 } 3500 return ERROR_EXPAT_UNCLOSED_CDATA_SECTION; 3515 3501 default: 3516 3502 *eventPP = next; 3517 return XML_ERROR_UNEXPECTED_STATE;3503 return ERROR_EXPAT_UNEXPECTED_STATE; 3518 3504 } 3519 3505 *eventPP = s = next; … … 3527 3513 * the whole file is parsed with one call. */ 3528 3514 3529 static enum XML_ErrorignoreSectionProcessor(XML_Parser parser,3515 static XMLERROR ignoreSectionProcessor(XML_Parser parser, 3530 3516 const char *start, 3531 3517 const char *end, 3532 3518 const char **endPtr) 3533 3519 { 3534 enum XML_Errorresult = doIgnoreSection(parser, encoding, &start, end, endPtr);3520 XMLERROR result = doIgnoreSection(parser, encoding, &start, end, endPtr); 3535 3521 3536 3522 if (start) … … 3545 3531 * the section is not yet closed. */ 3546 3532 3547 static enum XML_ErrordoIgnoreSection(XML_Parser parser,3533 static XMLERROR doIgnoreSection(XML_Parser parser, 3548 3534 const ENCODING * enc, 3549 3535 const char **startPtr, … … 3578 3564 reportDefault(parser, enc, s, next); 3579 3565 *startPtr = next; 3580 return XML_ERROR_NONE;3566 return ERROR_EXPAT_NONE; 3581 3567 case XML_TOK_INVALID: 3582 3568 *eventPP = next; 3583 return XML_ERROR_INVALID_TOKEN;3569 return ERROR_EXPAT_INVALID_TOKEN; 3584 3570 case XML_TOK_PARTIAL_CHAR: 3585 3571 if (nextPtr) 3586 3572 { 3587 3573 *nextPtr = s; 3588 return XML_ERROR_NONE;3574 return ERROR_EXPAT_NONE; 3589 3575 } 3590 return XML_ERROR_PARTIAL_CHAR;3576 return ERROR_EXPAT_PARTIAL_CHAR; 3591 3577 case XML_TOK_PARTIAL: 3592 3578 case XML_TOK_NONE: … … 3594 3580 { 3595 3581 *nextPtr = s; 3596 return XML_ERROR_NONE;3582 return ERROR_EXPAT_NONE; 3597 3583 } 3598 return XML_ERROR_SYNTAX; /* XML_ERROR_UNCLOSED_IGNORE_SECTION */3584 return ERROR_EXPAT_SYNTAX; /* ERROR_EXPAT_UNCLOSED_IGNORE_SECTION */ 3599 3585 default: 3600 3586 *eventPP = next; 3601 return XML_ERROR_UNEXPECTED_STATE;3587 return ERROR_EXPAT_UNEXPECTED_STATE; 3602 3588 } 3603 3589 /* not reached */ … … 3606 3592 #endif /* XML_DTD */ 3607 3593 3608 static enum XML_ErrorinitializeEncoding(XML_Parser parser)3594 static XMLERROR initializeEncoding(XML_Parser parser) 3609 3595 { 3610 3596 const char *s; … … 3636 3622 #endif 3637 3623 if ((ns ? XmlInitEncodingNS : XmlInitEncoding) (&initEncoding, &encoding, s)) 3638 return XML_ERROR_NONE;3624 return ERROR_EXPAT_NONE; 3639 3625 return handleUnknownEncoding(parser, protocolEncodingName); 3640 3626 } 3641 3627 3642 static enum XML_ErrorprocessXmlDecl(XML_Parser parser, int isGeneralTextEntity,3628 static XMLERROR processXmlDecl(XML_Parser parser, int isGeneralTextEntity, 3643 3629 const char *s, const char *next) 3644 3630 { … … 3663 3649 &newEncoding, 3664 3650 &standalone)) 3665 return XML_ERROR_SYNTAX;3651 return ERROR_EXPAT_SYNTAX; 3666 3652 if (!isGeneralTextEntity && standalone == 1) 3667 3653 { … … 3682 3668 + XmlNameLength(encoding, encodingName)); 3683 3669 if (!storedEncName) 3684 return XML_ERROR_NO_MEMORY;3670 return ERROR_EXPAT_NO_MEMORY; 3685 3671 poolFinish(&temp2Pool); 3686 3672 } … … 3692 3678 versionend - encoding->minBytesPerChar); 3693 3679 if (!storedversion) 3694 return XML_ERROR_NO_MEMORY;3680 return ERROR_EXPAT_NO_MEMORY; 3695 3681 } 3696 3682 xmlDeclHandler(handlerArg, storedversion, storedEncName, standalone); … … 3705 3691 { 3706 3692 eventPtr = encodingName; 3707 return XML_ERROR_INCORRECT_ENCODING;3693 return ERROR_EXPAT_INCORRECT_ENCODING; 3708 3694 } 3709 3695 encoding = newEncoding; … … 3711 3697 else if (encodingName) 3712 3698 { 3713 enum XML_Errorresult;3699 XMLERROR result; 3714 3700 3715 3701 if (!storedEncName) … … 3721 3707 + XmlNameLength(encoding, encodingName)); 3722 3708 if (!storedEncName) 3723 return XML_ERROR_NO_MEMORY;3709 return ERROR_EXPAT_NO_MEMORY; 3724 3710 } 3725 3711 result = handleUnknownEncoding(parser, storedEncName); 3726 3712 poolClear(&tempPool); 3727 if (result == XML_ERROR_UNKNOWN_ENCODING)3713 if (result == ERROR_EXPAT_UNKNOWN_ENCODING) 3728 3714 eventPtr = encodingName; 3729 3715 return result; … … 3734 3720 poolClear(&temp2Pool); 3735 3721 3736 return XML_ERROR_NONE;3737 } 3738 3739 static enum XML_ErrorhandleUnknownEncoding(XML_Parser parser,3722 return ERROR_EXPAT_NONE; 3723 } 3724 3725 static XMLERROR handleUnknownEncoding(XML_Parser parser, 3740 3726 const XML_Char* encodingName) 3741 3727 { … … 3761 3747 if (info.release) 3762 3748 info.release(info.data); 3763 return XML_ERROR_NO_MEMORY;3749 return ERROR_EXPAT_NO_MEMORY; 3764 3750 } 3765 3751 enc = (ns … … 3774 3760 unknownEncodingRelease = info.release; 3775 3761 encoding = enc; 3776 return XML_ERROR_NONE;3762 return ERROR_EXPAT_NONE; 3777 3763 } 3778 3764 } … … 3780 3766 info.release(info.data); 3781 3767 } 3782 return XML_ERROR_UNKNOWN_ENCODING;3783 } 3784 3785 static enum XML_ErrorprologInitProcessor(XML_Parser parser,3768 return ERROR_EXPAT_UNKNOWN_ENCODING; 3769 } 3770 3771 static XMLERROR prologInitProcessor(XML_Parser parser, 3786 3772 const char *s, 3787 3773 const char *end, 3788 3774 const char **nextPtr) 3789 3775 { 3790 enum XML_Errorresult = initializeEncoding(parser);3791 3792 if (result != XML_ERROR_NONE)3776 XMLERROR result = initializeEncoding(parser); 3777 3778 if (result != ERROR_EXPAT_NONE) 3793 3779 return result; 3794 3780 processor = prologProcessor; … … 3796 3782 } 3797 3783 3798 static enum XML_ErrorprologProcessor(XML_Parser parser,3784 static XMLERROR prologProcessor(XML_Parser parser, 3799 3785 const char *s, 3800 3786 const char *end, … … 3807 3793 } 3808 3794 3809 static enum XML_ErrordoProlog(XML_Parser parser,3795 static XMLERROR doProlog(XML_Parser parser, 3810 3796 const ENCODING * enc, 3811 3797 const char *s, … … 3846 3832 { 3847 3833 *nextPtr = s; 3848 return XML_ERROR_NONE;3834 return ERROR_EXPAT_NONE; 3849 3835 } 3850 3836 switch (tok) … … 3852 3838 case XML_TOK_INVALID: 3853 3839 *eventPP = next; 3854 return XML_ERROR_INVALID_TOKEN;3840 return ERROR_EXPAT_INVALID_TOKEN; 3855 3841 case XML_TOK_PARTIAL: 3856 return XML_ERROR_UNCLOSED_TOKEN;3842 return ERROR_EXPAT_UNCLOSED_TOKEN; 3857 3843 case XML_TOK_PARTIAL_CHAR: 3858 return XML_ERROR_PARTIAL_CHAR;3844 return ERROR_EXPAT_PARTIAL_CHAR; 3859 3845 case XML_TOK_NONE: 3860 3846 #ifdef XML_DTD 3861 3847 if (enc != encoding) 3862 return XML_ERROR_NONE;3848 return ERROR_EXPAT_NONE; 3863 3849 if (parentParser) 3864 3850 { 3865 3851 if (XmlTokenRole(&prologState, XML_TOK_NONE, end, end, enc) 3866 3852 == XML_ROLE_ERROR) 3867 return XML_ERROR_SYNTAX;3853 return ERROR_EXPAT_SYNTAX; 3868 3854 hadExternalDoctype = 0; 3869 return XML_ERROR_NONE;3855 return ERROR_EXPAT_NONE; 3870 3856 } 3871 3857 #endif /* XML_DTD */ 3872 return XML_ERROR_NO_ELEMENTS;3858 return ERROR_EXPAT_NO_ELEMENTS; 3873 3859 default: 3874 3860 tok = -tok; … … 3882 3868 case XML_ROLE_XML_DECL: 3883 3869 { 3884 enum XML_Errorresult = processXmlDecl(parser, 0, s, next);3885 3886 if (result != XML_ERROR_NONE)3870 XMLERROR result = processXmlDecl(parser, 0, s, next); 3871 3872 if (result != ERROR_EXPAT_NONE) 3887 3873 return result; 3888 3874 enc = encoding; … … 3894 3880 doctypeName = poolStoreString(&tempPool, enc, s, next); 3895 3881 if (!doctypeName) 3896 return XML_ERROR_NO_MEMORY;3882 return ERROR_EXPAT_NO_MEMORY; 3897 3883 poolFinish(&tempPool); 3898 3884 doctypeSysid = 0; … … 3912 3898 case XML_ROLE_TEXT_DECL: 3913 3899 { 3914 enum XML_Errorresult = processXmlDecl(parser, 1, s, next);3915 3916 if (result != XML_ERROR_NONE)3900 XMLERROR result = processXmlDecl(parser, 1, s, next); 3901 3902 if (result != ERROR_EXPAT_NONE) 3917 3903 return result; 3918 3904 enc = encoding; … … 3925 3911 doctypePubid = poolStoreString(&tempPool, enc, s + 1, next - 1); 3926 3912 if (!doctypePubid) 3927 return XML_ERROR_NO_MEMORY;3913 return ERROR_EXPAT_NO_MEMORY; 3928 3914 poolFinish(&tempPool); 3929 3915 } … … 3933 3919 sizeof(ENTITY)); 3934 3920 if (!declEntity) 3935 return XML_ERROR_NO_MEMORY;3921 return ERROR_EXPAT_NO_MEMORY; 3936 3922 #endif /* XML_DTD */ 3937 3923 /* fall through */ 3938 3924 case XML_ROLE_ENTITY_PUBLIC_ID: 3939 3925 if (!XmlIsPublicId(enc, s, next, eventPP)) 3940 return XML_ERROR_SYNTAX;3926 return ERROR_EXPAT_SYNTAX; 3941 3927 if (declEntity) 3942 3928 { … … 3947 3933 3948 3934 if (!tem) 3949 return XML_ERROR_NO_MEMORY;3935 return ERROR_EXPAT_NO_MEMORY; 3950 3936 normalizePublicId(tem); 3951 3937 declEntity->publicId = tem; … … 3975 3961 entity->systemId, 3976 3962 entity->publicId)) 3977 return XML_ERROR_EXTERNAL_ENTITY_HANDLING;3963 return ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING; 3978 3964 } 3979 3965 #endif /* XML_DTD */ … … 3982 3968 && notStandaloneHandler 3983 3969 && !notStandaloneHandler(handlerArg)) 3984 return XML_ERROR_NOT_STANDALONE;3970 return ERROR_EXPAT_NOT_STANDALONE; 3985 3971 } 3986 3972 if (endDoctypeDeclHandler) … … 3993 3979 declElementType = getElementType(parser, enc, s, next); 3994 3980 if (!declElementType) 3995 return XML_ERROR_NO_MEMORY;3981 return ERROR_EXPAT_NO_MEMORY; 3996 3982 break; 3997 3983 case XML_ROLE_ATTRIBUTE_NAME: 3998 3984 declAttributeId = getAttributeId(parser, enc, s, next); 3999 3985 if (!declAttributeId) 4000 return XML_ERROR_NO_MEMORY;3986 return ERROR_EXPAT_NO_MEMORY; 4001 3987 declAttributeIsCdata = 0; 4002 3988 declAttributeType = 0; … … 4047 4033 } 4048 4034 if (!poolAppendString(&tempPool, prefix)) 4049 return XML_ERROR_NO_MEMORY;4035 return ERROR_EXPAT_NO_MEMORY; 4050 4036 if (!poolAppend(&tempPool, enc, s, next)) 4051 return XML_ERROR_NO_MEMORY;4037 return ERROR_EXPAT_NO_MEMORY; 4052 4038 declAttributeType = tempPool.start; 4053 4039 } … … 4059 4045 declAttributeIsCdata, declAttributeIsId, 0, 4060 4046 parser)) 4061 return XML_ERROR_NO_MEMORY;4047 return ERROR_EXPAT_NO_MEMORY; 4062 4048 if (attlistDeclHandler && declAttributeType) 4063 4049 { … … 4068 4054 if (!poolAppendChar(&tempPool, ')') 4069 4055 || !poolAppendChar(&tempPool, '\0')) 4070 return XML_ERROR_NO_MEMORY;4056 return ERROR_EXPAT_NO_MEMORY; 4071 4057 declAttributeType = tempPool.start; 4072 4058 poolFinish(&tempPool); … … 4083 4069 { 4084 4070 const XML_Char *attVal; 4085 enum XML_Errorresult4071 XMLERROR result 4086 4072 = storeAttributeValue(parser, enc, declAttributeIsCdata, 4087 4073 s + enc->minBytesPerChar, … … 4096 4082 /* ID attributes aren't allowed to have a default */ 4097 4083 && !defineAttribute(declElementType, declAttributeId, declAttributeIsCdata, 0, attVal, parser)) 4098 return XML_ERROR_NO_MEMORY;4084 return ERROR_EXPAT_NO_MEMORY; 4099 4085 if (attlistDeclHandler && declAttributeType) 4100 4086 { … … 4105 4091 if (!poolAppendChar(&tempPool, ')') 4106 4092 || !poolAppendChar(&tempPool, '\0')) 4107 return XML_ERROR_NO_MEMORY;4093 return ERROR_EXPAT_NO_MEMORY; 4108 4094 declAttributeType = tempPool.start; 4109 4095 poolFinish(&tempPool); … … 4120 4106 case XML_ROLE_ENTITY_VALUE: 4121 4107 { 4122 enum XML_Errorresult = storeEntityValue(parser, enc,4108 XMLERROR result = storeEntityValue(parser, enc, 4123 4109 s + enc->minBytesPerChar, 4124 4110 next - enc->minBytesPerChar); … … 4142 4128 else 4143 4129 poolDiscard(&dtd.pool); 4144 if (result != XML_ERROR_NONE)4130 if (result != ERROR_EXPAT_NONE) 4145 4131 return result; 4146 4132 } … … 4151 4137 doctypeSysid = poolStoreString(&tempPool, enc, s + 1, next - 1); 4152 4138 if (!doctypeSysid) 4153 return XML_ERROR_NO_MEMORY;4139 return ERROR_EXPAT_NO_MEMORY; 4154 4140 poolFinish(&tempPool); 4155 4141 } … … 4160 4146 && notStandaloneHandler 4161 4147 && !notStandaloneHandler(handlerArg)) 4162 return XML_ERROR_NOT_STANDALONE;4148 return ERROR_EXPAT_NOT_STANDALONE; 4163 4149 hadExternalDoctype = 1; 4164 4150 #ifndef XML_DTD … … 4172 4158 declEntity->publicId = 0; 4173 4159 if (!declEntity) 4174 return XML_ERROR_NO_MEMORY;4160 return ERROR_EXPAT_NO_MEMORY; 4175 4161 } 4176 4162 /* fall through */ … … 4183 4169 next - enc->minBytesPerChar); 4184 4170 if (!declEntity->systemId) 4185 return XML_ERROR_NO_MEMORY;4171 return ERROR_EXPAT_NO_MEMORY; 4186 4172 declEntity->base = curBase; 4187 4173 poolFinish(&dtd.pool); … … 4206 4192 declEntity->notation = poolStoreString(&dtd.pool, enc, s, next); 4207 4193 if (!declEntity->notation) 4208 return XML_ERROR_NO_MEMORY;4194 return ERROR_EXPAT_NO_MEMORY; 4209 4195 poolFinish(&dtd.pool); 4210 4196 if (unparsedEntityDeclHandler) … … 4242 4228 name = poolStoreString(&dtd.pool, enc, s, next); 4243 4229 if (!name) 4244 return XML_ERROR_NO_MEMORY;4230 return ERROR_EXPAT_NO_MEMORY; 4245 4231 if (dtd.complete) 4246 4232 { 4247 4233 declEntity = (ENTITY*)lookup(&dtd.generalEntities, name, sizeof(ENTITY)); 4248 4234 if (!declEntity) 4249 return XML_ERROR_NO_MEMORY;4235 return ERROR_EXPAT_NO_MEMORY; 4250 4236 if (declEntity->name != name) 4251 4237 { … … 4274 4260 4275 4261 if (!name) 4276 return XML_ERROR_NO_MEMORY;4262 return ERROR_EXPAT_NO_MEMORY; 4277 4263 declEntity = (ENTITY*)lookup(&dtd.paramEntities, 4278 4264 name, sizeof(ENTITY)); 4279 4265 if (!declEntity) 4280 return XML_ERROR_NO_MEMORY;4266 return ERROR_EXPAT_NO_MEMORY; 4281 4267 if (declEntity->name != name) 4282 4268 { … … 4302 4288 declNotationName = poolStoreString(&tempPool, enc, s, next); 4303 4289 if (!declNotationName) 4304 return XML_ERROR_NO_MEMORY;4290 return ERROR_EXPAT_NO_MEMORY; 4305 4291 poolFinish(&tempPool); 4306 4292 } … … 4308 4294 case XML_ROLE_NOTATION_PUBLIC_ID: 4309 4295 if (!XmlIsPublicId(enc, s, next, eventPP)) 4310 return XML_ERROR_SYNTAX;4296 return ERROR_EXPAT_SYNTAX; 4311 4297 if (declNotationName) 4312 4298 { … … 4317 4303 4318 4304 if (!tem) 4319 return XML_ERROR_NO_MEMORY;4305 return ERROR_EXPAT_NO_MEMORY; 4320 4306 normalizePublicId(tem); 4321 4307 declNotationPublicId = tem; … … 4332 4318 4333 4319 if (!systemId) 4334 return XML_ERROR_NO_MEMORY;4320 return ERROR_EXPAT_NO_MEMORY; 4335 4321 *eventEndPP = s; 4336 4322 notationDeclHandler(handlerArg, … … 4358 4344 { 4359 4345 case XML_TOK_PARAM_ENTITY_REF: 4360 return XML_ERROR_PARAM_ENTITY_REF;4346 return ERROR_EXPAT_PARAM_ENTITY_REF; 4361 4347 case XML_TOK_XML_DECL: 4362 return XML_ERROR_MISPLACED_XML_PI;4348 return ERROR_EXPAT_MISPLACED_XML_PI; 4363 4349 default: 4364 return XML_ERROR_SYNTAX;4350 return ERROR_EXPAT_SYNTAX; 4365 4351 } 4366 4352 #ifdef XML_DTD 4367 4353 case XML_ROLE_IGNORE_SECT: 4368 4354 { 4369 enum XML_Errorresult;4355 XMLERROR result; 4370 4356 4371 4357 if (defaultHandler) … … 4392 4378 groupConnector = (char*)MALLOC(groupSize = 32); 4393 4379 if (!groupConnector) 4394 return XML_ERROR_NO_MEMORY;4380 return ERROR_EXPAT_NO_MEMORY; 4395 4381 } 4396 4382 groupConnector[prologState.level] = 0; … … 4400 4386 4401 4387 if (myindex < 0) 4402 return XML_ERROR_NO_MEMORY;4388 return ERROR_EXPAT_NO_MEMORY; 4403 4389 dtd.scaffIndex[dtd.scaffLevel] = myindex; 4404 4390 dtd.scaffLevel++; … … 4408 4394 case XML_ROLE_GROUP_SEQUENCE: 4409 4395 if (groupConnector[prologState.level] == '|') 4410 return XML_ERROR_SYNTAX;4396 return ERROR_EXPAT_SYNTAX; 4411 4397 groupConnector[prologState.level] = ','; 4412 4398 break; 4413 4399 case XML_ROLE_GROUP_CHOICE: 4414 4400 if (groupConnector[prologState.level] == ',') 4415 return XML_ERROR_SYNTAX;4401 return ERROR_EXPAT_SYNTAX; 4416 4402 if (dtd.in_eldecl 4417 4403 && !groupConnector[prologState.level] … … 4436 4422 next - enc->minBytesPerChar); 4437 4423 if (!name) 4438 return XML_ERROR_NO_MEMORY;4424 return ERROR_EXPAT_NO_MEMORY; 4439 4425 entity = (ENTITY*)lookup(&dtd.paramEntities, name, 0); 4440 4426 poolDiscard(&dtd.pool); … … 4442 4428 { 4443 4429 /* FIXME what to do if !dtd.complete? */ 4444 return XML_ERROR_UNDEFINED_ENTITY;4430 return ERROR_EXPAT_UNDEFINED_ENTITY; 4445 4431 } 4446 4432 if (entity->open) 4447 return XML_ERROR_RECURSIVE_ENTITY_REF;4433 return ERROR_EXPAT_RECURSIVE_ENTITY_REF; 4448 4434 if (entity->textPtr) 4449 4435 { 4450 enum XML_Errorresult;4436 XMLERROR result; 4451 4437 4452 4438 result = processInternalParamEntity(parser, entity); 4453 if (result != XML_ERROR_NONE)4439 if (result != ERROR_EXPAT_NONE) 4454 4440 return result; 4455 4441 break; 4456 4442 } 4457 4443 if (role == XML_ROLE_INNER_PARAM_ENTITY_REF) 4458 return XML_ERROR_PARAM_ENTITY_REF;4444 return ERROR_EXPAT_PARAM_ENTITY_REF; 4459 4445 if (externalEntityRefHandler) 4460 4446 { … … 4468 4454 { 4469 4455 entity->open = 0; 4470 return XML_ERROR_EXTERNAL_ENTITY_HANDLING;4456 return ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING; 4471 4457 } 4472 4458 entity->open = 0; … … 4479 4465 && notStandaloneHandler 4480 4466 && !notStandaloneHandler(handlerArg)) 4481 return XML_ERROR_NOT_STANDALONE;4467 return ERROR_EXPAT_NOT_STANDALONE; 4482 4468 dtd.complete = 0; 4483 4469 if (defaultHandler) … … 4492 4478 declElementType = getElementType(parser, enc, s, next); 4493 4479 if (!declElementType) 4494 return XML_ERROR_NO_MEMORY;4480 return ERROR_EXPAT_NO_MEMORY; 4495 4481 dtd.scaffLevel = 0; 4496 4482 dtd.scaffCount = 0; … … 4505 4491 if (elementDeclHandler) 4506 4492 { 4507 XML _Content *content = (XML_Content*)MALLOC(sizeof(XML_Content));4493 XMLCONTENT *content = (XMLCONTENT*)MALLOC(sizeof(XMLCONTENT)); 4508 4494 4509 4495 if (!content) 4510 return XML_ERROR_NO_MEMORY;4496 return ERROR_EXPAT_NO_MEMORY; 4511 4497 content->quant = XML_CQUANT_NONE; 4512 4498 content->name = 0; … … 4549 4535 4550 4536 if (myindex < 0) 4551 return XML_ERROR_NO_MEMORY;4537 return ERROR_EXPAT_NO_MEMORY; 4552 4538 dtd.scaffold[myindex].type = XML_CTYPE_NAME; 4553 4539 dtd.scaffold[myindex].quant = quant; 4554 4540 el = getElementType(parser, enc, s, nxt); 4555 4541 if (!el) 4556 return XML_ERROR_NO_MEMORY;4542 return ERROR_EXPAT_NO_MEMORY; 4557 4543 dtd.scaffold[myindex].name = el->name; 4558 4544 dtd.contentStringLen += nxt - s + 1; … … 4580 4566 if (elementDeclHandler) 4581 4567 { 4582 XML _Content*model = build_model(parser);4568 XMLCONTENT *model = build_model(parser); 4583 4569 4584 4570 if (!model) 4585 return XML_ERROR_NO_MEMORY;4571 return ERROR_EXPAT_NO_MEMORY; 4586 4572 *eventEndPP = s; 4587 4573 elementDeclHandler(handlerArg, declElementType->name, model); … … 4599 4585 case XML_TOK_PI: 4600 4586 if (!reportProcessingInstruction(parser, enc, s, next)) 4601 return XML_ERROR_NO_MEMORY;4587 return ERROR_EXPAT_NO_MEMORY; 4602 4588 break; 4603 4589 case XML_TOK_COMMENT: 4604 4590 if (!reportComment(parser, enc, s, next)) 4605 return XML_ERROR_NO_MEMORY;4591 return ERROR_EXPAT_NO_MEMORY; 4606 4592 break; 4607 4593 } … … 4634 4620 } 4635 4621 4636 static enum XML_ErrorepilogProcessor(XML_Parser parser,4622 static XMLERROR epilogProcessor(XML_Parser parser, 4637 4623 const char *s, 4638 4624 const char *end, … … 4659 4645 if (nextPtr) 4660 4646 *nextPtr = end; 4661 return XML_ERROR_NONE;4647 return ERROR_EXPAT_NONE; 4662 4648 case XML_TOK_PROLOG_S: 4663 4649 if (defaultHandler) … … 4666 4652 case XML_TOK_PI: 4667 4653 if (!reportProcessingInstruction(parser, encoding, s, next)) 4668 return XML_ERROR_NO_MEMORY;4654 return ERROR_EXPAT_NO_MEMORY; 4669 4655 break; 4670 4656 case XML_TOK_COMMENT: 4671 4657 if (!reportComment(parser, encoding, s, next)) 4672 return XML_ERROR_NO_MEMORY;4658 return ERROR_EXPAT_NO_MEMORY; 4673 4659 break; 4674 4660 case XML_TOK_INVALID: 4675 4661 eventPtr = next; 4676 return XML_ERROR_INVALID_TOKEN;4662 return ERROR_EXPAT_INVALID_TOKEN; 4677 4663 case XML_TOK_PARTIAL: 4678 4664 if (nextPtr) 4679 4665 { 4680 4666 *nextPtr = s; 4681 return XML_ERROR_NONE;4682 } 4683 return XML_ERROR_UNCLOSED_TOKEN;4667 return ERROR_EXPAT_NONE; 4668 } 4669 return ERROR_EXPAT_UNCLOSED_TOKEN; 4684 4670 case XML_TOK_PARTIAL_CHAR: 4685 4671 if (nextPtr) 4686 4672 { 4687 4673 *nextPtr = s; 4688 return XML_ERROR_NONE;4689 } 4690 return XML_ERROR_PARTIAL_CHAR;4674 return ERROR_EXPAT_NONE; 4675 } 4676 return ERROR_EXPAT_PARTIAL_CHAR; 4691 4677 default: 4692 return XML_ERROR_JUNK_AFTER_DOC_ELEMENT;4678 return ERROR_EXPAT_JUNK_AFTER_DOC_ELEMENT; 4693 4679 } 4694 4680 eventPtr = s = next; … … 4698 4684 #ifdef XML_DTD 4699 4685 4700 static enum XML_ErrorprocessInternalParamEntity(XML_Parser parser, ENTITY * entity)4686 static XMLERROR processInternalParamEntity(XML_Parser parser, ENTITY * entity) 4701 4687 { 4702 4688 const char *s, *end, *next; 4703 4689 int tok; 4704 enum XML_Errorresult;4690 XMLERROR result; 4705 4691 OPEN_INTERNAL_ENTITY openEntity; 4706 4692 … … 4722 4708 #endif /* XML_DTD */ 4723 4709 4724 static enum XML_ErrorerrorProcessor(XML_Parser parser,4710 static XMLERROR errorProcessor(XML_Parser parser, 4725 4711 const char *s, 4726 4712 const char *end, … … 4730 4716 } 4731 4717 4732 static enum XML_ErrorstoreAttributeValue(XML_Parser parser,4718 static XMLERROR storeAttributeValue(XML_Parser parser, 4733 4719 const ENCODING * enc, 4734 4720 int isCdata, … … 4737 4723 STRING_POOL * pool) 4738 4724 { 4739 enum XML_Errorresult = appendAttributeValue(parser, enc, isCdata, ptr, end, pool);4725 XMLERROR result = appendAttributeValue(parser, enc, isCdata, ptr, end, pool); 4740 4726 4741 4727 if (result) … … 4744 4730 poolChop(pool); 4745 4731 if (!poolAppendChar(pool, XML_T('\0'))) 4746 return XML_ERROR_NO_MEMORY;4747 return XML_ERROR_NONE;4748 } 4749 4750 static enum XML_ErrorappendAttributeValue(XML_Parser parser, const ENCODING * enc, int isCdata,4732 return ERROR_EXPAT_NO_MEMORY; 4733 return ERROR_EXPAT_NONE; 4734 } 4735 4736 static XMLERROR appendAttributeValue(XML_Parser parser, const ENCODING * enc, int isCdata, 4751 4737 const char *ptr, const char *end, 4752 4738 STRING_POOL * pool) … … 4760 4746 { 4761 4747 case XML_TOK_NONE: 4762 return XML_ERROR_NONE;4748 return ERROR_EXPAT_NONE; 4763 4749 case XML_TOK_INVALID: 4764 4750 if (enc == encoding) 4765 4751 eventPtr = next; 4766 return XML_ERROR_INVALID_TOKEN;4752 return ERROR_EXPAT_INVALID_TOKEN; 4767 4753 case XML_TOK_PARTIAL: 4768 4754 if (enc == encoding) 4769 4755 eventPtr = ptr; 4770 return XML_ERROR_INVALID_TOKEN;4756 return ERROR_EXPAT_INVALID_TOKEN; 4771 4757 case XML_TOK_CHAR_REF: 4772 4758 { … … 4779 4765 if (enc == encoding) 4780 4766 eventPtr = ptr; 4781 return XML_ERROR_BAD_CHAR_REF;4767 return ERROR_EXPAT_BAD_CHAR_REF; 4782 4768 } 4783 4769 if (!isCdata … … 4790 4776 if (enc == encoding) 4791 4777 eventPtr = ptr; 4792 return XML_ERROR_BAD_CHAR_REF;4778 return ERROR_EXPAT_BAD_CHAR_REF; 4793 4779 } 4794 4780 for (i = 0; i < n; i++) 4795 4781 { 4796 4782 if (!poolAppendChar(pool, buf[i])) 4797 return XML_ERROR_NO_MEMORY;4783 return ERROR_EXPAT_NO_MEMORY; 4798 4784 } 4799 4785 } … … 4801 4787 case XML_TOK_DATA_CHARS: 4802 4788 if (!poolAppend(pool, enc, ptr, next)) 4803 return XML_ERROR_NO_MEMORY;4789 return ERROR_EXPAT_NO_MEMORY; 4804 4790 break; 4805 4791 case XML_TOK_TRAILING_CR: … … 4811 4797 break; 4812 4798 if (!poolAppendChar(pool, 0x20)) 4813 return XML_ERROR_NO_MEMORY;4799 return ERROR_EXPAT_NO_MEMORY; 4814 4800 break; 4815 4801 case XML_TOK_ENTITY_REF: … … 4824 4810 { 4825 4811 if (!poolAppendChar(pool, ch)) 4826 return XML_ERROR_NO_MEMORY;4812 return ERROR_EXPAT_NO_MEMORY; 4827 4813 break; 4828 4814 } … … 4831 4817 next - enc->minBytesPerChar); 4832 4818 if (!name) 4833 return XML_ERROR_NO_MEMORY;4819 return ERROR_EXPAT_NO_MEMORY; 4834 4820 entity = (ENTITY*)lookup(&dtd.generalEntities, name, 0); 4835 4821 poolDiscard(&temp2Pool); … … 4840 4826 if (enc == encoding) 4841 4827 eventPtr = ptr; 4842 return XML_ERROR_UNDEFINED_ENTITY;4828 return ERROR_EXPAT_UNDEFINED_ENTITY; 4843 4829 } 4844 4830 } … … 4847 4833 if (enc == encoding) 4848 4834 eventPtr = ptr; 4849 return XML_ERROR_RECURSIVE_ENTITY_REF;4835 return ERROR_EXPAT_RECURSIVE_ENTITY_REF; 4850 4836 } 4851 4837 else if (entity->notation) … … 4853 4839 if (enc == encoding) 4854 4840 eventPtr = ptr; 4855 return XML_ERROR_BINARY_ENTITY_REF;4841 return ERROR_EXPAT_BINARY_ENTITY_REF; 4856 4842 } 4857 4843 else if (!entity->textPtr) … … 4859 4845 if (enc == encoding) 4860 4846 eventPtr = ptr; 4861 return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF;4847 return ERROR_EXPAT_ATTRIBUTE_EXTERNAL_ENTITY_REF; 4862 4848 } 4863 4849 else 4864 4850 { 4865 enum XML_Errorresult;4851 XMLERROR result; 4866 4852 const XML_Char *textEnd = entity->textPtr + entity->textLen; 4867 4853 … … 4877 4863 if (enc == encoding) 4878 4864 eventPtr = ptr; 4879 return XML_ERROR_UNEXPECTED_STATE;4865 return ERROR_EXPAT_UNEXPECTED_STATE; 4880 4866 } 4881 4867 ptr = next; … … 4884 4870 } 4885 4871 4886 static enum XML_ErrorstoreEntityValue(XML_Parser parser,4872 static XMLERROR storeEntityValue(XML_Parser parser, 4887 4873 const ENCODING * enc, 4888 4874 const char *entityTextPtr, … … 4902 4888 if (parentParser || enc != encoding) 4903 4889 { 4904 enum XML_Errorresult;4890 XMLERROR result; 4905 4891 const XML_Char *name; 4906 4892 ENTITY *entity; … … 4910 4896 next - enc->minBytesPerChar); 4911 4897 if (!name) 4912 return XML_ERROR_NO_MEMORY;4898 return ERROR_EXPAT_NO_MEMORY; 4913 4899 entity = (ENTITY*)lookup(&dtd.paramEntities, name, 0); 4914 4900 poolDiscard(&tempPool); … … 4917 4903 if (enc == encoding) 4918 4904 eventPtr = entityTextPtr; 4919 return XML_ERROR_UNDEFINED_ENTITY;4905 return ERROR_EXPAT_UNDEFINED_ENTITY; 4920 4906 } 4921 4907 if (entity->open) … … 4923 4909 if (enc == encoding) 4924 4910 eventPtr = entityTextPtr; 4925 return XML_ERROR_RECURSIVE_ENTITY_REF;4911 return ERROR_EXPAT_RECURSIVE_ENTITY_REF; 4926 4912 } 4927 4913 if (entity->systemId) … … 4929 4915 if (enc == encoding) 4930 4916 eventPtr = entityTextPtr; 4931 return XML_ERROR_PARAM_ENTITY_REF;4917 return ERROR_EXPAT_PARAM_ENTITY_REF; 4932 4918 } 4933 4919 entity->open = 1; … … 4943 4929 #endif /* XML_DTD */ 4944 4930 eventPtr = entityTextPtr; 4945 return XML_ERROR_SYNTAX;4931 return ERROR_EXPAT_SYNTAX; 4946 4932 case XML_TOK_NONE: 4947 return XML_ERROR_NONE;4933 return ERROR_EXPAT_NONE; 4948 4934 case XML_TOK_ENTITY_REF: 4949 4935 case XML_TOK_DATA_CHARS: 4950 4936 if (!poolAppend(pool, enc, entityTextPtr, next)) 4951 return XML_ERROR_NO_MEMORY;4937 return ERROR_EXPAT_NO_MEMORY; 4952 4938 break; 4953 4939 case XML_TOK_TRAILING_CR: … … 4956 4942 case XML_TOK_DATA_NEWLINE: 4957 4943 if (pool->end == pool->ptr && !poolGrow(pool)) 4958 return XML_ERROR_NO_MEMORY;4944 return ERROR_EXPAT_NO_MEMORY; 4959 4945 *(pool->ptr)++ = 0xA; 4960 4946 break; … … 4969 4955 if (enc == encoding) 4970 4956 eventPtr = entityTextPtr; 4971 return XML_ERROR_BAD_CHAR_REF;4957 return ERROR_EXPAT_BAD_CHAR_REF; 4972 4958 } 4973 4959 n = XmlEncode(n, (ICHAR*)buf); … … 4976 4962 if (enc == encoding) 4977 4963 eventPtr = entityTextPtr; 4978 return XML_ERROR_BAD_CHAR_REF;4964 return ERROR_EXPAT_BAD_CHAR_REF; 4979 4965 } 4980 4966 for (i = 0; i < n; i++) 4981 4967 { 4982 4968 if (pool->end == pool->ptr && !poolGrow(pool)) 4983 return XML_ERROR_NO_MEMORY;4969 return ERROR_EXPAT_NO_MEMORY; 4984 4970 *(pool->ptr)++ = buf[i]; 4985 4971 } … … 4989 4975 if (enc == encoding) 4990 4976 eventPtr = entityTextPtr; 4991 return XML_ERROR_INVALID_TOKEN;4977 return ERROR_EXPAT_INVALID_TOKEN; 4992 4978 case XML_TOK_INVALID: 4993 4979 if (enc == encoding) 4994 4980 eventPtr = next; 4995 return XML_ERROR_INVALID_TOKEN;4981 return ERROR_EXPAT_INVALID_TOKEN; 4996 4982 default: 4997 4983 if (enc == encoding) 4998 4984 eventPtr = entityTextPtr; 4999 return XML_ERROR_UNEXPECTED_STATE;4985 return ERROR_EXPAT_UNEXPECTED_STATE; 5000 4986 } 5001 4987 entityTextPtr = next; … … 5486 5472 } 5487 5473 5488 /* Do a deep copy of the DTD. Return 0 for out of memory; non-zero otherwise. 5489 * The new DTD has already been initialized. */ 5474 /* 5475 * Do a deep copy of the DTD. Return 0 for out of memory; non-zero otherwise. 5476 * The new DTD has already been initialized. 5477 * 5478 */ 5490 5479 5491 5480 static int dtdCopy(DTD * newDtd, const DTD * oldDtd, XML_Parser parser) … … 6058 6047 static void build_node(XML_Parser parser, 6059 6048 int src_node, 6060 XML _Content* dest,6061 XML _Content** contpos,6049 XMLCONTENT * dest, 6050 XMLCONTENT ** contpos, 6062 6051 char **strpos) 6063 6052 { … … 6098 6087 } /* End build_node */ 6099 6088 6100 static XML _Content* build_model(XML_Parser parser)6101 { 6102 XML _Content*ret;6103 XML _Content*cpos;6089 static XMLCONTENT * build_model(XML_Parser parser) 6090 { 6091 XMLCONTENT *ret; 6092 XMLCONTENT *cpos; 6104 6093 char *str; 6105 int allocsize = dtd.scaffCount * sizeof(XML _Content) + dtd.contentStringLen;6106 6107 ret = (XML _Content*)MALLOC(allocsize);6094 int allocsize = dtd.scaffCount * sizeof(XMLCONTENT) + dtd.contentStringLen; 6095 6096 ret = (XMLCONTENT*)MALLOC(allocsize); 6108 6097 if (!ret) 6109 6098 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.