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