expat_compat.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Sterling Hughes <sterling@php.net> |
  14. +----------------------------------------------------------------------+
  15. */
  16. #ifndef PHP_EXPAT_COMPAT_H
  17. #define PHP_EXPAT_COMPAT_H
  18. #ifdef PHP_WIN32
  19. #include "config.w32.h"
  20. #else
  21. #include <php_config.h>
  22. #endif
  23. #ifdef PHP_WIN32
  24. # define PHP_XML_API __declspec(dllexport)
  25. #elif defined(__GNUC__) && __GNUC__ >= 4
  26. # define PHP_XML_API __attribute__ ((visibility("default")))
  27. #else
  28. # define PHP_XML_API
  29. #endif
  30. #if !defined(HAVE_LIBEXPAT) && defined(HAVE_LIBXML)
  31. #define LIBXML_EXPAT_COMPAT 1
  32. #include "php.h"
  33. #include "php_compat.h"
  34. #include <libxml/parser.h>
  35. #include <libxml/parserInternals.h>
  36. #include <libxml/tree.h>
  37. #include <libxml/hash.h>
  38. /* For compatibility with the misspelled version. */
  39. #define _ns_seperator _ns_separator
  40. typedef xmlChar XML_Char;
  41. typedef void (*XML_StartElementHandler)(void *, const XML_Char *, const XML_Char **);
  42. typedef void (*XML_EndElementHandler)(void *, const XML_Char *);
  43. typedef void (*XML_CharacterDataHandler)(void *, const XML_Char *, int);
  44. typedef void (*XML_ProcessingInstructionHandler)(void *, const XML_Char *, const XML_Char *);
  45. typedef void (*XML_CommentHandler)(void *, const XML_Char *);
  46. typedef void (*XML_DefaultHandler)(void *, const XML_Char *, int);
  47. typedef void (*XML_UnparsedEntityDeclHandler)(void *, const XML_Char *, const XML_Char *, const XML_Char *, const XML_Char *, const XML_Char *);
  48. typedef void (*XML_NotationDeclHandler)(void *, const XML_Char *, const XML_Char *, const XML_Char *, const XML_Char *);
  49. typedef int (*XML_ExternalEntityRefHandler)(void *, const XML_Char *, const XML_Char *, const XML_Char *, const XML_Char *);
  50. typedef void (*XML_StartNamespaceDeclHandler)(void *, const XML_Char *, const XML_Char *);
  51. typedef void (*XML_EndNamespaceDeclHandler)(void *, const XML_Char *);
  52. typedef struct _XML_Memory_Handling_Suite {
  53. void *(*malloc_fcn)(size_t size);
  54. void *(*realloc_fcn)(void *ptr, size_t size);
  55. void (*free_fcn)(void *ptr);
  56. } XML_Memory_Handling_Suite;
  57. typedef struct _XML_Parser {
  58. int use_namespace;
  59. xmlChar *_ns_separator;
  60. void *user;
  61. xmlParserCtxtPtr parser;
  62. XML_StartElementHandler h_start_element;
  63. XML_EndElementHandler h_end_element;
  64. XML_CharacterDataHandler h_cdata;
  65. XML_ProcessingInstructionHandler h_pi;
  66. XML_CommentHandler h_comment;
  67. XML_DefaultHandler h_default;
  68. XML_UnparsedEntityDeclHandler h_unparsed_entity_decl;
  69. XML_NotationDeclHandler h_notation_decl;
  70. XML_ExternalEntityRefHandler h_external_entity_ref;
  71. XML_StartNamespaceDeclHandler h_start_ns;
  72. XML_EndNamespaceDeclHandler h_end_ns;
  73. } *XML_Parser;
  74. enum XML_Error {
  75. XML_ERROR_NONE,
  76. XML_ERROR_NO_MEMORY,
  77. XML_ERROR_SYNTAX,
  78. XML_ERROR_NO_ELEMENTS,
  79. XML_ERROR_INVALID_TOKEN,
  80. XML_ERROR_UNCLOSED_TOKEN,
  81. XML_ERROR_PARTIAL_CHAR,
  82. XML_ERROR_TAG_MISMATCH,
  83. XML_ERROR_DUPLICATE_ATTRIBUTE,
  84. XML_ERROR_JUNK_AFTER_DOC_ELEMENT,
  85. XML_ERROR_PARAM_ENTITY_REF,
  86. XML_ERROR_UNDEFINED_ENTITY,
  87. XML_ERROR_RECURSIVE_ENTITY_REF,
  88. XML_ERROR_ASYNC_ENTITY,
  89. XML_ERROR_BAD_CHAR_REF,
  90. XML_ERROR_BINARY_ENTITY_REF,
  91. XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
  92. XML_ERROR_MISPLACED_XML_PI,
  93. XML_ERROR_UNKNOWN_ENCODING,
  94. XML_ERROR_INCORRECT_ENCODING,
  95. XML_ERROR_UNCLOSED_CDATA_SECTION,
  96. XML_ERROR_EXTERNAL_ENTITY_HANDLING,
  97. XML_ERROR_NOT_STANDALONE,
  98. XML_ERROR_UNEXPECTED_STATE,
  99. XML_ERROR_ENTITY_DECLARED_IN_PE,
  100. XML_ERROR_FEATURE_REQUIRES_XML_DTD,
  101. XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING
  102. };
  103. enum XML_Content_Type {
  104. XML_CTYPE_EMPTY = 1,
  105. XML_CTYPE_ANY,
  106. XML_CTYPE_MIXED,
  107. XML_CTYPE_NAME,
  108. XML_CTYPE_CHOICE,
  109. XML_CTYPE_SEQ
  110. };
  111. PHP_XML_API XML_Parser XML_ParserCreate(const XML_Char *);
  112. PHP_XML_API XML_Parser XML_ParserCreateNS(const XML_Char *, const XML_Char);
  113. PHP_XML_API XML_Parser XML_ParserCreate_MM(const XML_Char *, const XML_Memory_Handling_Suite *, const XML_Char *);
  114. PHP_XML_API void XML_SetUserData(XML_Parser, void *);
  115. PHP_XML_API void *XML_GetUserData(XML_Parser);
  116. PHP_XML_API void XML_SetElementHandler(XML_Parser, XML_StartElementHandler, XML_EndElementHandler);
  117. PHP_XML_API void XML_SetCharacterDataHandler(XML_Parser, XML_CharacterDataHandler);
  118. PHP_XML_API void XML_SetProcessingInstructionHandler(XML_Parser, XML_ProcessingInstructionHandler);
  119. PHP_XML_API void XML_SetDefaultHandler(XML_Parser, XML_DefaultHandler);
  120. PHP_XML_API void XML_SetUnparsedEntityDeclHandler(XML_Parser, XML_UnparsedEntityDeclHandler);
  121. PHP_XML_API void XML_SetNotationDeclHandler(XML_Parser, XML_NotationDeclHandler);
  122. PHP_XML_API void XML_SetExternalEntityRefHandler(XML_Parser, XML_ExternalEntityRefHandler);
  123. PHP_XML_API void XML_SetStartNamespaceDeclHandler(XML_Parser, XML_StartNamespaceDeclHandler);
  124. PHP_XML_API void XML_SetEndNamespaceDeclHandler(XML_Parser, XML_EndNamespaceDeclHandler);
  125. PHP_XML_API int XML_Parse(XML_Parser, const XML_Char *, int data_len, int is_final);
  126. PHP_XML_API int XML_GetErrorCode(XML_Parser);
  127. PHP_XML_API const XML_Char *XML_ErrorString(int);
  128. PHP_XML_API int XML_GetCurrentLineNumber(XML_Parser);
  129. PHP_XML_API int XML_GetCurrentColumnNumber(XML_Parser);
  130. PHP_XML_API int XML_GetCurrentByteIndex(XML_Parser);
  131. PHP_XML_API int XML_GetCurrentByteCount(XML_Parser);
  132. PHP_XML_API const XML_Char *XML_ExpatVersion(void);
  133. PHP_XML_API void XML_ParserFree(XML_Parser);
  134. #elif defined(HAVE_LIBEXPAT)
  135. #include "php.h"
  136. #include <expat.h>
  137. #endif /* HAVE_LIBEXPAT */
  138. #endif /* PHP_EXPAT_COMPAT_H */