xref: /PHP-7.4/ext/dom/xml_common.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   +----------------------------------------------------------------------+
18 */
19 
20 #ifndef PHP_XML_COMMON_H
21 #define PHP_XML_COMMON_H
22 
23 #include "ext/libxml/php_libxml.h"
24 
25 typedef libxml_doc_props *dom_doc_propsptr;
26 
27 typedef struct _dom_object {
28 	void *ptr;
29 	php_libxml_ref_obj *document;
30 	HashTable *prop_handler;
31 	zend_object std;
32 } dom_object;
33 
php_dom_obj_from_obj(zend_object * obj)34 static inline dom_object *php_dom_obj_from_obj(zend_object *obj) {
35 	return (dom_object*)((char*)(obj) - XtOffsetOf(dom_object, std));
36 }
37 
38 #define Z_DOMOBJ_P(zv)  php_dom_obj_from_obj(Z_OBJ_P((zv)))
39 
40 #ifdef PHP_WIN32
41 #	ifdef DOM_EXPORTS
42 #		define PHP_DOM_EXPORT __declspec(dllexport)
43 #	elif !defined(DOM_LOCAL_DEFINES) /* Allow to counteract LNK4049 warning. */
44 #		define PHP_DOM_EXPORT __declspec(dllimport)
45 #   else
46 #		define PHP_DOM_EXPORT
47 #	endif /* DOM_EXPORTS */
48 #elif defined(__GNUC__) && __GNUC__ >= 4
49 #	define PHP_DOM_EXPORT __attribute__ ((visibility("default")))
50 #elif defined(PHPAPI)
51 #   define PHP_DOM_EXPORT PHPAPI
52 #else
53 #   define PHP_DOM_EXPORT
54 #endif
55 
56 PHP_DOM_EXPORT extern zend_class_entry *dom_node_class_entry;
57 PHP_DOM_EXPORT dom_object *php_dom_object_get_data(xmlNodePtr obj);
58 PHP_DOM_EXPORT zend_bool php_dom_create_object(xmlNodePtr obj, zval* return_value, dom_object *domobj);
59 PHP_DOM_EXPORT xmlNodePtr dom_object_get_node(dom_object *obj);
60 
61 #define DOM_XMLNS_NAMESPACE \
62     (const xmlChar *) "http://www.w3.org/2000/xmlns/"
63 
64 #define NODE_GET_OBJ(__ptr, __id, __prtype, __intern) { \
65 	__intern = Z_LIBXML_NODE_P(__id); \
66 	if (__intern->node == NULL || !(__ptr = (__prtype)__intern->node->node)) { \
67   		php_error_docref(NULL, E_WARNING, "Couldn't fetch %s", \
68 			ZSTR_VAL(__intern->std.ce->name));\
69   		RETURN_NULL();\
70   	} \
71 }
72 
73 #define DOC_GET_OBJ(__ptr, __id, __prtype, __intern) { \
74 	__intern = Z_LIBXML_NODE_P(__id); \
75 	if (__intern->document != NULL) { \
76 		if (!(__ptr = (__prtype)__intern->document->ptr)) { \
77   			php_error_docref(NULL, E_WARNING, "Couldn't fetch %s", __intern->std.ce->name);\
78   			RETURN_NULL();\
79   		} \
80 	} \
81 }
82 
83 #define DOM_RET_OBJ(obj, ret, domobject) \
84 	*ret = php_dom_create_object(obj, return_value, domobject)
85 
86 #define DOM_GET_THIS(zval) \
87 	do { zval = ZEND_THIS; } while (0)
88 
89 #define DOM_GET_THIS_OBJ(__ptr, __id, __prtype, __intern) \
90 	DOM_GET_THIS(__id); \
91 	DOM_GET_OBJ(__ptr, __id, __prtype, __intern);
92 
93 #endif
94