xref: /PHP-7.1/ext/libxml/php_libxml.h (revision ccd4716e)
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: Shane Caraveo <shane@php.net>                               |
16    |          Wez Furlong <wez@thebrainroom.com>                          |
17    +----------------------------------------------------------------------+
18 */
19 
20 /* $Id$ */
21 
22 #ifndef PHP_LIBXML_H
23 #define PHP_LIBXML_H
24 
25 #if HAVE_LIBXML
26 extern zend_module_entry libxml_module_entry;
27 #define libxml_module_ptr &libxml_module_entry
28 
29 #include "php_version.h"
30 #define PHP_LIBXML_VERSION PHP_VERSION
31 
32 #ifdef PHP_WIN32
33 #	define PHP_LIBXML_API __declspec(dllexport)
34 #elif defined(__GNUC__) && __GNUC__ >= 4
35 #	define PHP_LIBXML_API __attribute__ ((visibility("default")))
36 #else
37 #	define PHP_LIBXML_API
38 #endif
39 
40 #include "zend_smart_str.h"
41 #include <libxml/tree.h>
42 
43 #define LIBXML_SAVE_NOEMPTYTAG 1<<2
44 
45 ZEND_BEGIN_MODULE_GLOBALS(libxml)
46 	zval stream_context;
47 	smart_str error_buffer;
48 	zend_llist *error_list;
49 	struct _php_libxml_entity_resolver {
50 		zval                    object;
51 		zend_fcall_info			fci;
52 		zend_fcall_info_cache	fcc;
53 	} entity_loader;
54 	zend_bool entity_loader_disabled;
55 ZEND_END_MODULE_GLOBALS(libxml)
56 
57 typedef struct _libxml_doc_props {
58 	int formatoutput;
59 	int validateonparse;
60 	int resolveexternals;
61 	int preservewhitespace;
62 	int substituteentities;
63 	int stricterror;
64 	int recover;
65 	HashTable *classmap;
66 } libxml_doc_props;
67 
68 typedef struct _php_libxml_ref_obj {
69 	void *ptr;
70 	int   refcount;
71 	libxml_doc_props *doc_props;
72 } php_libxml_ref_obj;
73 
74 typedef struct _php_libxml_node_ptr {
75 	xmlNodePtr node;
76 	int	refcount;
77 	void *_private;
78 } php_libxml_node_ptr;
79 
80 typedef struct _php_libxml_node_object {
81 	php_libxml_node_ptr *node;
82 	php_libxml_ref_obj *document;
83 	HashTable *properties;
84 	zend_object  std;
85 } php_libxml_node_object;
86 
87 
php_libxml_node_fetch_object(zend_object * obj)88 static inline php_libxml_node_object *php_libxml_node_fetch_object(zend_object *obj) {
89 	return (php_libxml_node_object *)((char*)(obj) - obj->handlers->offset);
90 }
91 
92 #define Z_LIBXML_NODE_P(zv) php_libxml_node_fetch_object(Z_OBJ_P((zv)))
93 
94 typedef void * (*php_libxml_export_node) (zval *object);
95 
96 PHP_LIBXML_API int php_libxml_increment_node_ptr(php_libxml_node_object *object, xmlNodePtr node, void *private_data);
97 PHP_LIBXML_API int php_libxml_decrement_node_ptr(php_libxml_node_object *object);
98 PHP_LIBXML_API int php_libxml_increment_doc_ref(php_libxml_node_object *object, xmlDocPtr docp);
99 PHP_LIBXML_API int php_libxml_decrement_doc_ref(php_libxml_node_object *object);
100 PHP_LIBXML_API xmlNodePtr php_libxml_import_node(zval *object);
101 PHP_LIBXML_API zval *php_libxml_register_export(zend_class_entry *ce, php_libxml_export_node export_function);
102 /* When an explicit freeing of node and children is required */
103 PHP_LIBXML_API void php_libxml_node_free_list(xmlNodePtr node);
104 PHP_LIBXML_API void php_libxml_node_free_resource(xmlNodePtr node);
105 /* When object dtor is called as node may still be referenced */
106 PHP_LIBXML_API void php_libxml_node_decrement_resource(php_libxml_node_object *object);
107 PHP_LIBXML_API void php_libxml_error_handler(void *ctx, const char *msg, ...);
108 PHP_LIBXML_API void php_libxml_ctx_warning(void *ctx, const char *msg, ...);
109 PHP_LIBXML_API void php_libxml_ctx_error(void *ctx, const char *msg, ...);
110 PHP_LIBXML_API int php_libxml_xmlCheckUTF8(const unsigned char *s);
111 PHP_LIBXML_API void php_libxml_switch_context(zval *context, zval *oldcontext);
112 PHP_LIBXML_API void php_libxml_issue_error(int level, const char *msg);
113 PHP_LIBXML_API zend_bool php_libxml_disable_entity_loader(zend_bool disable);
114 
115 /* Init/shutdown functions*/
116 PHP_LIBXML_API void php_libxml_initialize(void);
117 PHP_LIBXML_API void php_libxml_shutdown(void);
118 
119 #define LIBXML(v) ZEND_MODULE_GLOBALS_ACCESSOR(libxml, v)
120 
121 #if defined(ZTS) && defined(COMPILE_DL_LIBXML)
122 ZEND_TSRMLS_CACHE_EXTERN()
123 #endif
124 
125 #else /* HAVE_LIBXML */
126 #define libxml_module_ptr NULL
127 #endif
128 
129 #define phpext_libxml_ptr libxml_module_ptr
130 
131 #endif /* PHP_LIBXML_H */
132 
133 /*
134  * Local variables:
135  * tab-width: 4
136  * c-basic-offset: 4
137  * End:
138  */
139