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