xref: /PHP-7.4/ext/dom/php_dom.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: Christian Stocker <chregu@php.net>                          |
16    |          Rob Richards <rrichards@php.net>							  |
17    |          Marcus Borger <helly@php.net>                               |
18    +----------------------------------------------------------------------+
19 */
20 
21 #ifndef PHP_DOM_H
22 #define PHP_DOM_H
23 
24 extern zend_module_entry dom_module_entry;
25 #define phpext_dom_ptr &dom_module_entry
26 
27 #ifdef ZTS
28 #include "TSRM.h"
29 #endif
30 
31 #include <libxml/parser.h>
32 #include <libxml/parserInternals.h>
33 #include <libxml/tree.h>
34 #include <libxml/uri.h>
35 #include <libxml/xmlerror.h>
36 #include <libxml/xinclude.h>
37 #include <libxml/hash.h>
38 #include <libxml/c14n.h>
39 #if defined(LIBXML_HTML_ENABLED)
40 #include <libxml/HTMLparser.h>
41 #include <libxml/HTMLtree.h>
42 #endif
43 #if defined(LIBXML_XPATH_ENABLED)
44 #include <libxml/xpath.h>
45 #include <libxml/xpathInternals.h>
46 #endif
47 #if defined(LIBXML_XPTR_ENABLED)
48 #include <libxml/xpointer.h>
49 #endif
50 #ifdef PHP_WIN32
51 #ifndef DOM_EXPORTS
52 #define DOM_EXPORTS
53 #endif
54 #endif
55 
56 #include "xml_common.h"
57 #include "ext/libxml/php_libxml.h"
58 #include "zend_exceptions.h"
59 #include "dom_ce.h"
60 /* DOM API_VERSION, please bump it up, if you change anything in the API
61     therefore it's easier for the script-programmers to check, what's working how
62    Can be checked with phpversion("dom");
63 */
64 #define DOM_API_VERSION "20031129"
65 /* Define a custom type for iterating using an unused nodetype */
66 #define DOM_NODESET XML_XINCLUDE_START
67 
68 typedef struct _dom_xpath_object {
69 	int registerPhpFunctions;
70 	HashTable *registered_phpfunctions;
71 	HashTable *node_list;
72 	dom_object dom;
73 } dom_xpath_object;
74 
php_xpath_obj_from_obj(zend_object * obj)75 static inline dom_xpath_object *php_xpath_obj_from_obj(zend_object *obj) {
76 	return (dom_xpath_object*)((char*)(obj)
77 		- XtOffsetOf(dom_xpath_object, dom) - XtOffsetOf(dom_object, std));
78 }
79 
80 #define Z_XPATHOBJ_P(zv)  php_xpath_obj_from_obj(Z_OBJ_P((zv)))
81 
82 typedef struct _dom_nnodemap_object {
83 	dom_object *baseobj;
84 	zval baseobj_zv;
85 	int nodetype;
86 	xmlHashTable *ht;
87 	xmlChar *local;
88 	xmlChar *ns;
89 } dom_nnodemap_object;
90 
91 typedef struct {
92 	zend_object_iterator intern;
93 	zval curobj;
94 	HashPosition pos;
95 } php_dom_iterator;
96 
97 #include "dom_fe.h"
98 
99 dom_object *dom_object_get_data(xmlNodePtr obj);
100 dom_doc_propsptr dom_get_doc_props(php_libxml_ref_obj *document);
101 zend_object *dom_objects_new(zend_class_entry *class_type);
102 zend_object *dom_nnodemap_objects_new(zend_class_entry *class_type);
103 #if defined(LIBXML_XPATH_ENABLED)
104 zend_object *dom_xpath_objects_new(zend_class_entry *class_type);
105 #endif
106 int dom_get_strict_error(php_libxml_ref_obj *document);
107 void php_dom_throw_error(int error_code, int strict_error);
108 void php_dom_throw_error_with_message(int error_code, char *error_message, int strict_error);
109 void node_list_unlink(xmlNodePtr node);
110 int dom_check_qname(char *qname, char **localname, char **prefix, int uri_len, int name_len);
111 xmlNsPtr dom_get_ns(xmlNodePtr node, char *uri, int *errorcode, char *prefix);
112 void dom_set_old_ns(xmlDoc *doc, xmlNs *ns);
113 xmlNsPtr dom_get_nsdecl(xmlNode *node, xmlChar *localName);
114 void dom_normalize (xmlNodePtr nodep);
115 xmlNode *dom_get_elements_by_tag_name_ns_raw(xmlNodePtr nodep, char *ns, char *local, int *cur, int index);
116 void php_dom_create_implementation(zval *retval);
117 int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child);
118 int dom_has_feature(char *feature, char *version);
119 int dom_node_is_read_only(xmlNodePtr node);
120 int dom_node_children_valid(xmlNodePtr node);
121 void php_dom_create_interator(zval *return_value, int ce_type);
122 void dom_namednode_iter(dom_object *basenode, int ntype, dom_object *intern, xmlHashTablePtr ht, xmlChar *local, xmlChar *ns);
123 xmlNodePtr create_notation(const xmlChar *name, const xmlChar *ExternalID, const xmlChar *SystemID);
124 xmlNode *php_dom_libxml_hash_iter(xmlHashTable *ht, int index);
125 xmlNode *php_dom_libxml_notation_iter(xmlHashTable *ht, int index);
126 zend_object_iterator *php_dom_get_iterator(zend_class_entry *ce, zval *object, int by_ref);
127 void dom_set_doc_classmap(php_libxml_ref_obj *document, zend_class_entry *basece, zend_class_entry *ce);
128 zval *dom_nodelist_read_dimension(zval *object, zval *offset, int type, zval *rv);
129 int dom_nodelist_has_dimension(zval *object, zval *member, int check_empty);
130 
131 #define REGISTER_DOM_CLASS(ce, name, parent_ce, funcs, entry) \
132 INIT_CLASS_ENTRY(ce, name, funcs); \
133 ce.create_object = dom_objects_new; \
134 entry = zend_register_internal_class_ex(&ce, parent_ce);
135 
136 #define DOM_GET_OBJ(__ptr, __id, __prtype, __intern) { \
137 	__intern = Z_DOMOBJ_P(__id); \
138 	if (__intern->ptr == NULL || !(__ptr = (__prtype)((php_libxml_node_ptr *)__intern->ptr)->node)) { \
139   		php_error_docref(NULL, E_WARNING, "Couldn't fetch %s", ZSTR_VAL(__intern->std.ce->name));\
140   		RETURN_NULL();\
141   	} \
142 }
143 
144 #define DOM_NO_ARGS() \
145 	if (zend_parse_parameters_none() == FAILURE) { \
146 		return; \
147 	}
148 
149 #define DOM_NOT_IMPLEMENTED() \
150 	php_error_docref(NULL, E_WARNING, "Not yet implemented"); \
151 	return;
152 
153 #define DOM_NODELIST 0
154 #define DOM_NAMEDNODEMAP 1
155 
156 PHP_MINIT_FUNCTION(dom);
157 PHP_MSHUTDOWN_FUNCTION(dom);
158 PHP_MINFO_FUNCTION(dom);
159 
160 #endif /* PHP_DOM_H */
161