xref: /PHP-7.3/ext/xml/php_xml.h (revision 902d39a3)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2018 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: Stig Sæther Bakken <ssb@php.net>                            |
16    |          Thies C. Arntzen <thies@thieso.net>                         |
17    |          Sterling Hughes <sterling@php.net>                          |
18    +----------------------------------------------------------------------+
19 */
20 
21 #ifndef PHP_XML_H
22 #define PHP_XML_H
23 
24 #ifdef HAVE_XML
25 extern zend_module_entry xml_module_entry;
26 #define xml_module_ptr &xml_module_entry
27 
28 #include "php_version.h"
29 #define PHP_XML_VERSION PHP_VERSION
30 
31 #else
32 #define xml_module_ptr NULL
33 #endif
34 
35 #ifdef HAVE_XML
36 
37 #include "expat_compat.h"
38 
39 #ifdef XML_UNICODE
40 #error "UTF-16 Unicode support not implemented!"
41 #endif
42 
ZEND_BEGIN_MODULE_GLOBALS(xml)43 ZEND_BEGIN_MODULE_GLOBALS(xml)
44 	XML_Char *default_encoding;
45 ZEND_END_MODULE_GLOBALS(xml)
46 
47 typedef struct {
48 	int case_folding;
49 	XML_Parser parser;
50 	XML_Char *target_encoding;
51 
52 	zval index;
53 	zval startElementHandler;
54 	zval endElementHandler;
55 	zval characterDataHandler;
56 	zval processingInstructionHandler;
57 	zval defaultHandler;
58 	zval unparsedEntityDeclHandler;
59 	zval notationDeclHandler;
60 	zval externalEntityRefHandler;
61 	zval unknownEncodingHandler;
62 	zval startNamespaceDeclHandler;
63 	zval endNamespaceDeclHandler;
64 
65 	zend_function *startElementPtr;
66 	zend_function *endElementPtr;
67 	zend_function *characterDataPtr;
68 	zend_function *processingInstructionPtr;
69 	zend_function *defaultPtr;
70 	zend_function *unparsedEntityDeclPtr;
71 	zend_function *notationDeclPtr;
72 	zend_function *externalEntityRefPtr;
73 	zend_function *unknownEncodingPtr;
74 	zend_function *startNamespaceDeclPtr;
75 	zend_function *endNamespaceDeclPtr;
76 
77 	zval object;
78 
79 	zval data;
80 	zval info;
81 	int level;
82 	int toffset;
83 	int curtag;
84 	zval *ctag;
85 	char **ltags;
86 	int lastwasopen;
87 	int skipwhite;
88 	int isparsing;
89 
90 	XML_Char *baseURI;
91 } xml_parser;
92 
93 
94 typedef struct {
95 	XML_Char *name;
96 	char (*decoding_function)(unsigned short);
97 	unsigned short (*encoding_function)(unsigned char);
98 } xml_encoding;
99 
100 
101 enum php_xml_option {
102     PHP_XML_OPTION_CASE_FOLDING = 1,
103     PHP_XML_OPTION_TARGET_ENCODING,
104     PHP_XML_OPTION_SKIP_TAGSTART,
105     PHP_XML_OPTION_SKIP_WHITE
106 };
107 
108 /* for xml_parse_into_struct */
109 
110 #define XML_MAXLEVEL 255 /* XXX this should be dynamic */
111 
112 PHP_FUNCTION(xml_parser_create);
113 PHP_FUNCTION(xml_parser_create_ns);
114 PHP_FUNCTION(xml_set_object);
115 PHP_FUNCTION(xml_set_element_handler);
116 PHP_FUNCTION(xml_set_character_data_handler);
117 PHP_FUNCTION(xml_set_processing_instruction_handler);
118 PHP_FUNCTION(xml_set_default_handler);
119 PHP_FUNCTION(xml_set_unparsed_entity_decl_handler);
120 PHP_FUNCTION(xml_set_notation_decl_handler);
121 PHP_FUNCTION(xml_set_external_entity_ref_handler);
122 PHP_FUNCTION(xml_set_start_namespace_decl_handler);
123 PHP_FUNCTION(xml_set_end_namespace_decl_handler);
124 PHP_FUNCTION(xml_parse);
125 PHP_FUNCTION(xml_get_error_code);
126 PHP_FUNCTION(xml_error_string);
127 PHP_FUNCTION(xml_get_current_line_number);
128 PHP_FUNCTION(xml_get_current_column_number);
129 PHP_FUNCTION(xml_get_current_byte_index);
130 PHP_FUNCTION(xml_parser_free);
131 PHP_FUNCTION(xml_parser_set_option);
132 PHP_FUNCTION(xml_parser_get_option);
133 PHP_FUNCTION(utf8_encode);
134 PHP_FUNCTION(utf8_decode);
135 PHP_FUNCTION(xml_parse_into_struct);
136 
137 PHP_XML_API char *_xml_zval_strdup(zval *);
138 PHP_XML_API zend_string *xml_utf8_decode(const XML_Char *, size_t, const XML_Char *);
139 PHP_XML_API zend_string *xml_utf8_encode(const char *, size_t, const XML_Char *);
140 
141 #endif /* HAVE_LIBEXPAT */
142 
143 #define phpext_xml_ptr xml_module_ptr
144 
145 #define XML(v) ZEND_MODULE_GLOBALS_ACCESSOR(xml, v)
146 
147 #if defined(ZTS) && defined(COMPILE_DL_XML)
148 ZEND_TSRMLS_CACHE_EXTERN()
149 #endif
150 
151 #endif /* PHP_XML_H */
152 
153 /*
154  * Local variables:
155  * tab-width: 4
156  * c-basic-offset: 4
157  * End:
158  */
159