xref: /PHP-8.0/ext/dom/xml_common.h (revision c5f091e4)
1 /*
2   +----------------------------------------------------------------------+
3   | Copyright (c) The PHP Group                                          |
4   +----------------------------------------------------------------------+
5   | This source file is subject to version 3.01 of the PHP license,      |
6   | that is bundled with this package in the file LICENSE, and is        |
7   | available through the world-wide-web at the following url:           |
8   | http://www.php.net/license/3_01.txt                                  |
9   | If you did not receive a copy of the PHP license and are unable to   |
10   | obtain it through the world-wide-web, please send a note to          |
11   | license@php.net so we can mail you a copy immediately.               |
12   +----------------------------------------------------------------------+
13   | Authors: Christian Stocker <chregu@php.net>                          |
14   |          Rob Richards <rrichards@php.net>                            |
15   +----------------------------------------------------------------------+
16 */
17 
18 #ifndef PHP_XML_COMMON_H
19 #define PHP_XML_COMMON_H
20 
21 #include "ext/libxml/php_libxml.h"
22 
23 typedef libxml_doc_props *dom_doc_propsptr;
24 
25 typedef struct _dom_object {
26 	void *ptr;
27 	php_libxml_ref_obj *document;
28 	HashTable *prop_handler;
29 	zend_object std;
30 } dom_object;
31 
php_dom_obj_from_obj(zend_object * obj)32 static inline dom_object *php_dom_obj_from_obj(zend_object *obj) {
33 	return (dom_object*)((char*)(obj) - XtOffsetOf(dom_object, std));
34 }
35 
36 #define Z_DOMOBJ_P(zv)  php_dom_obj_from_obj(Z_OBJ_P((zv)))
37 
38 #ifdef PHP_WIN32
39 #	ifdef DOM_EXPORTS
40 #		define PHP_DOM_EXPORT __declspec(dllexport)
41 #	elif !defined(DOM_LOCAL_DEFINES) /* Allow to counteract LNK4049 warning. */
42 #		define PHP_DOM_EXPORT __declspec(dllimport)
43 #   else
44 #		define PHP_DOM_EXPORT
45 #	endif /* DOM_EXPORTS */
46 #elif defined(__GNUC__) && __GNUC__ >= 4
47 #	define PHP_DOM_EXPORT __attribute__ ((visibility("default")))
48 #elif defined(PHPAPI)
49 #   define PHP_DOM_EXPORT PHPAPI
50 #else
51 #   define PHP_DOM_EXPORT
52 #endif
53 
54 PHP_DOM_EXPORT extern zend_class_entry *dom_node_class_entry;
55 PHP_DOM_EXPORT dom_object *php_dom_object_get_data(xmlNodePtr obj);
56 PHP_DOM_EXPORT zend_bool php_dom_create_object(xmlNodePtr obj, zval* return_value, dom_object *domobj);
57 PHP_DOM_EXPORT xmlNodePtr dom_object_get_node(dom_object *obj);
58 
59 #define DOM_XMLNS_NAMESPACE \
60     (const xmlChar *) "http://www.w3.org/2000/xmlns/"
61 
62 #define NODE_GET_OBJ(__ptr, __id, __prtype, __intern) { \
63 	__intern = Z_LIBXML_NODE_P(__id); \
64 	if (__intern->node == NULL || !(__ptr = (__prtype)__intern->node->node)) { \
65   		php_error_docref(NULL, E_WARNING, "Couldn't fetch %s", \
66 			ZSTR_VAL(__intern->std.ce->name));\
67   		RETURN_NULL();\
68   	} \
69 }
70 
71 #define DOC_GET_OBJ(__ptr, __id, __prtype, __intern) { \
72 	__intern = Z_LIBXML_NODE_P(__id); \
73 	if (__intern->document != NULL) { \
74 		if (!(__ptr = (__prtype)__intern->document->ptr)) { \
75   			php_error_docref(NULL, E_WARNING, "Couldn't fetch %s", __intern->std.ce->name);\
76   			RETURN_NULL();\
77   		} \
78 	} \
79 }
80 
81 #define DOM_RET_OBJ(obj, ret, domobject) \
82 	*ret = php_dom_create_object(obj, return_value, domobject)
83 
84 #define DOM_GET_THIS_OBJ(__ptr, __id, __prtype, __intern) \
85 	__id = ZEND_THIS; \
86 	DOM_GET_OBJ(__ptr, __id, __prtype, __intern);
87 
88 #endif
89