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 17 #ifndef PHP_EXPAT_COMPAT_H 18 #define PHP_EXPAT_COMPAT_H 19 20 #ifdef PHP_WIN32 21 #include "config.w32.h" 22 #else 23 #include <php_config.h> 24 #endif 25 26 #ifdef PHP_WIN32 27 # define PHP_XML_API __declspec(dllexport) 28 #elif defined(__GNUC__) && __GNUC__ >= 4 29 # define PHP_XML_API __attribute__ ((visibility("default"))) 30 #else 31 # define PHP_XML_API 32 #endif 33 34 #if !defined(HAVE_LIBEXPAT) && defined(HAVE_LIBXML) 35 #define LIBXML_EXPAT_COMPAT 1 36 37 #include "php.h" 38 #include "php_compat.h" 39 40 #include <libxml/parser.h> 41 #include <libxml/parserInternals.h> 42 #include <libxml/tree.h> 43 #include <libxml/hash.h> 44 45 /* For compatibility with the misspelled version. */ 46 #define _ns_seperator _ns_separator 47 48 typedef xmlChar XML_Char; 49 50 typedef void (*XML_StartElementHandler)(void *, const XML_Char *, const XML_Char **); 51 typedef void (*XML_EndElementHandler)(void *, const XML_Char *); 52 typedef void (*XML_CharacterDataHandler)(void *, const XML_Char *, int); 53 typedef void (*XML_ProcessingInstructionHandler)(void *, const XML_Char *, const XML_Char *); 54 typedef void (*XML_CommentHandler)(void *, const XML_Char *); 55 typedef void (*XML_DefaultHandler)(void *, const XML_Char *, int); 56 typedef void (*XML_UnparsedEntityDeclHandler)(void *, const XML_Char *, const XML_Char *, const XML_Char *, const XML_Char *, const XML_Char *); 57 typedef void (*XML_NotationDeclHandler)(void *, const XML_Char *, const XML_Char *, const XML_Char *, const XML_Char *); 58 typedef int (*XML_ExternalEntityRefHandler)(void *, const XML_Char *, const XML_Char *, const XML_Char *, const XML_Char *); 59 typedef void (*XML_StartNamespaceDeclHandler)(void *, const XML_Char *, const XML_Char *); 60 typedef void (*XML_EndNamespaceDeclHandler)(void *, const XML_Char *); 61 62 typedef struct _XML_Memory_Handling_Suite { 63 void *(*malloc_fcn)(size_t size); 64 void *(*realloc_fcn)(void *ptr, size_t size); 65 void (*free_fcn)(void *ptr); 66 } XML_Memory_Handling_Suite; 67 68 typedef struct _XML_Parser { 69 int use_namespace; 70 71 xmlChar *_ns_separator; 72 73 void *user; 74 xmlParserCtxtPtr parser; 75 76 XML_StartElementHandler h_start_element; 77 XML_EndElementHandler h_end_element; 78 XML_CharacterDataHandler h_cdata; 79 XML_ProcessingInstructionHandler h_pi; 80 XML_CommentHandler h_comment; 81 XML_DefaultHandler h_default; 82 XML_UnparsedEntityDeclHandler h_unparsed_entity_decl; 83 XML_NotationDeclHandler h_notation_decl; 84 XML_ExternalEntityRefHandler h_external_entity_ref; 85 XML_StartNamespaceDeclHandler h_start_ns; 86 XML_EndNamespaceDeclHandler h_end_ns; 87 } *XML_Parser; 88 89 enum XML_Error { 90 XML_ERROR_NONE, 91 XML_ERROR_NO_MEMORY, 92 XML_ERROR_SYNTAX, 93 XML_ERROR_NO_ELEMENTS, 94 XML_ERROR_INVALID_TOKEN, 95 XML_ERROR_UNCLOSED_TOKEN, 96 XML_ERROR_PARTIAL_CHAR, 97 XML_ERROR_TAG_MISMATCH, 98 XML_ERROR_DUPLICATE_ATTRIBUTE, 99 XML_ERROR_JUNK_AFTER_DOC_ELEMENT, 100 XML_ERROR_PARAM_ENTITY_REF, 101 XML_ERROR_UNDEFINED_ENTITY, 102 XML_ERROR_RECURSIVE_ENTITY_REF, 103 XML_ERROR_ASYNC_ENTITY, 104 XML_ERROR_BAD_CHAR_REF, 105 XML_ERROR_BINARY_ENTITY_REF, 106 XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, 107 XML_ERROR_MISPLACED_XML_PI, 108 XML_ERROR_UNKNOWN_ENCODING, 109 XML_ERROR_INCORRECT_ENCODING, 110 XML_ERROR_UNCLOSED_CDATA_SECTION, 111 XML_ERROR_EXTERNAL_ENTITY_HANDLING, 112 XML_ERROR_NOT_STANDALONE, 113 XML_ERROR_UNEXPECTED_STATE, 114 XML_ERROR_ENTITY_DECLARED_IN_PE, 115 XML_ERROR_FEATURE_REQUIRES_XML_DTD, 116 XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING 117 }; 118 119 enum XML_Content_Type { 120 XML_CTYPE_EMPTY = 1, 121 XML_CTYPE_ANY, 122 XML_CTYPE_MIXED, 123 XML_CTYPE_NAME, 124 XML_CTYPE_CHOICE, 125 XML_CTYPE_SEQ 126 }; 127 128 PHP_XML_API XML_Parser XML_ParserCreate(const XML_Char *); 129 PHP_XML_API XML_Parser XML_ParserCreateNS(const XML_Char *, const XML_Char); 130 PHP_XML_API XML_Parser XML_ParserCreate_MM(const XML_Char *, const XML_Memory_Handling_Suite *, const XML_Char *); 131 PHP_XML_API void XML_SetUserData(XML_Parser, void *); 132 PHP_XML_API void *XML_GetUserData(XML_Parser); 133 PHP_XML_API void XML_SetElementHandler(XML_Parser, XML_StartElementHandler, XML_EndElementHandler); 134 PHP_XML_API void XML_SetCharacterDataHandler(XML_Parser, XML_CharacterDataHandler); 135 PHP_XML_API void XML_SetProcessingInstructionHandler(XML_Parser, XML_ProcessingInstructionHandler); 136 PHP_XML_API void XML_SetDefaultHandler(XML_Parser, XML_DefaultHandler); 137 PHP_XML_API void XML_SetUnparsedEntityDeclHandler(XML_Parser, XML_UnparsedEntityDeclHandler); 138 PHP_XML_API void XML_SetNotationDeclHandler(XML_Parser, XML_NotationDeclHandler); 139 PHP_XML_API void XML_SetExternalEntityRefHandler(XML_Parser, XML_ExternalEntityRefHandler); 140 PHP_XML_API void XML_SetStartNamespaceDeclHandler(XML_Parser, XML_StartNamespaceDeclHandler); 141 PHP_XML_API void XML_SetEndNamespaceDeclHandler(XML_Parser, XML_EndNamespaceDeclHandler); 142 PHP_XML_API int XML_Parse(XML_Parser, const XML_Char *, int data_len, int is_final); 143 PHP_XML_API int XML_GetErrorCode(XML_Parser); 144 PHP_XML_API const XML_Char *XML_ErrorString(int); 145 PHP_XML_API int XML_GetCurrentLineNumber(XML_Parser); 146 PHP_XML_API int XML_GetCurrentColumnNumber(XML_Parser); 147 PHP_XML_API int XML_GetCurrentByteIndex(XML_Parser); 148 PHP_XML_API int XML_GetCurrentByteCount(XML_Parser); 149 PHP_XML_API const XML_Char *XML_ExpatVersion(void); 150 PHP_XML_API void XML_ParserFree(XML_Parser); 151 152 #elif defined(HAVE_LIBEXPAT) 153 #include "php.h" 154 #include <expat.h> 155 #endif /* HAVE_LIBEXPAT */ 156 157 #endif /* PHP_EXPAT_COMPAT_H */ 158