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