23#define libxml_module_ptr &libxml_module_entry
26#define PHP_LIBXML_VERSION PHP_VERSION
29# define PHP_LIBXML_API __declspec(dllexport)
30#elif defined(__GNUC__) && __GNUC__ >= 4
31# define PHP_LIBXML_API __attribute__ ((visibility("default")))
33# define PHP_LIBXML_API
37#include <libxml/tree.h>
38#include <libxml/parser.h>
40#define LIBXML_SAVE_NOEMPTYTAG 1<<2
42#define LIBXML_NS_TAG_HOOK 1
49 bool entity_loader_disabled;
52typedef struct _libxml_doc_props {
56 bool resolveexternals;
57 bool preservewhitespace;
58 bool substituteentities;
67 size_t modification_nr;
68} php_libxml_cache_tag;
81typedef struct php_libxml_document_handlers {
82 zend_string *(*dump_node_to_str)(xmlDocPtr doc, xmlNodePtr node,
bool format,
const char *
encoding);
84 zend_long (*dump_node_to_file)(
const char *filename, xmlDocPtr doc, xmlNodePtr node,
bool format,
const char *
encoding);
85 zend_long (*dump_doc_to_file)(
const char *filename, xmlDocPtr doc,
bool format,
const char *
encoding);
86} php_libxml_document_handlers;
98typedef enum _php_libxml_class_type {
99 PHP_LIBXML_CLASS_UNSET = 0,
100 PHP_LIBXML_CLASS_LEGACY = 1,
101 PHP_LIBXML_CLASS_MODERN = 2,
102} php_libxml_class_type;
104typedef enum php_libxml_quirks_mode {
105 PHP_LIBXML_NO_QUIRKS = 0,
107 PHP_LIBXML_LIMITED_QUIRKS,
108} php_libxml_quirks_mode;
110typedef struct _php_libxml_ref_obj {
112 libxml_doc_props *doc_props;
113 php_libxml_cache_tag cache_tag;
115 const php_libxml_document_handlers *
handlers;
116 unsigned int refcount;
117 php_libxml_class_type class_type : 8;
118 php_libxml_quirks_mode quirks_mode : 8;
121typedef struct _php_libxml_node_ptr {
123 unsigned int refcount;
125} php_libxml_node_ptr;
127typedef struct _php_libxml_node_object {
128 php_libxml_node_ptr *node;
129 php_libxml_ref_obj *document;
131} php_libxml_node_object;
134static inline php_libxml_node_object *php_libxml_node_fetch_object(
zend_object *obj) {
135 return (php_libxml_node_object *)((
char*)(obj) - obj->
handlers->
offset);
138static zend_always_inline void php_libxml_invalidate_cache_tag(php_libxml_cache_tag *cache_tag)
140#if SIZEOF_SIZE_T == 8
143 cache_tag->modification_nr++;
145 size_t new_modification_nr = cache_tag->modification_nr + 1;
146 if (
EXPECTED(new_modification_nr > 0)) {
147 cache_tag->modification_nr = new_modification_nr;
152static zend_always_inline bool php_libxml_is_cache_tag_stale(
const php_libxml_cache_tag *object_tag,
const php_libxml_cache_tag *cache_tag)
157#if SIZEOF_SIZE_T == 8
158 return cache_tag->modification_nr != object_tag->modification_nr;
160 return cache_tag->modification_nr != object_tag->modification_nr ||
UNEXPECTED(object_tag->modification_nr ==
SIZE_MAX);
164static zend_always_inline void php_libxml_invalidate_node_list_cache(php_libxml_ref_obj *doc_ptr)
167 php_libxml_invalidate_cache_tag(&doc_ptr->cache_tag);
171static zend_always_inline void php_libxml_invalidate_node_list_cache_from_doc(xmlDocPtr docp)
173 if (docp && docp->_private) {
174 php_libxml_node_ptr *node_private = (php_libxml_node_ptr *) docp->_private;
175 php_libxml_node_object *object_private = (php_libxml_node_object *) node_private->_private;
176 if (object_private) {
177 php_libxml_invalidate_node_list_cache(object_private->document);
182#define Z_LIBXML_NODE_P(zv) php_libxml_node_fetch_object(Z_OBJ_P((zv)))
184typedef void * (*php_libxml_export_node) (
zval *
object);
187 PHP_LIBXML_ERROR = 0,
188 PHP_LIBXML_CTX_ERROR = 1,
189 PHP_LIBXML_CTX_WARNING = 2,
190} php_libxml_error_level;
192PHP_LIBXML_API
int php_libxml_increment_node_ptr(php_libxml_node_object *
object, xmlNodePtr node,
void *private_data);
193PHP_LIBXML_API
int php_libxml_decrement_node_ptr(php_libxml_node_object *
object);
194PHP_LIBXML_API
int php_libxml_decrement_node_ptr_ref(php_libxml_node_ptr *
ptr);
195PHP_LIBXML_API
int php_libxml_increment_doc_ref(php_libxml_node_object *
object, xmlDocPtr docp);
196PHP_LIBXML_API
int php_libxml_decrement_doc_ref_directly(php_libxml_ref_obj *document);
197PHP_LIBXML_API
int php_libxml_decrement_doc_ref(php_libxml_node_object *
object);
198PHP_LIBXML_API xmlNodePtr php_libxml_import_node(
zval *
object);
199PHP_LIBXML_API
zval *php_libxml_register_export(
zend_class_entry *ce, php_libxml_export_node export_function);
201PHP_LIBXML_API
void php_libxml_node_free_list(xmlNodePtr node);
202PHP_LIBXML_API
void php_libxml_node_free_resource(xmlNodePtr node);
204PHP_LIBXML_API
void php_libxml_node_decrement_resource(php_libxml_node_object *
object);
205PHP_LIBXML_API
void php_libxml_error_handler(
void *ctx,
const char *
msg, ...);
206PHP_LIBXML_API
void php_libxml_ctx_warning(
void *ctx,
const char *
msg, ...);
207PHP_LIBXML_API
void php_libxml_pretend_ctx_error_ex(
const char *
file,
int line,
int column,
const char *
msg,...);
208PHP_LIBXML_API
void php_libxml_ctx_error(
void *ctx,
const char *
msg, ...);
209PHP_LIBXML_API
void php_libxml_error_handler_va(php_libxml_error_level error_type,
void *ctx,
const char *
msg, va_list
args);
210PHP_LIBXML_API
int php_libxml_xmlCheckUTF8(
const unsigned char *
s);
211PHP_LIBXML_API
void php_libxml_switch_context(
zval *
context,
zval *oldcontext);
212PHP_LIBXML_API
void php_libxml_issue_error(
int level,
const char *
msg);
213PHP_LIBXML_API
bool php_libxml_disable_entity_loader(
bool disable);
214PHP_LIBXML_API
void php_libxml_set_old_ns(xmlDocPtr doc, xmlNsPtr ns);
216PHP_LIBXML_API
bool php_libxml_uses_internal_errors(
void);
218PHP_LIBXML_API xmlChar *php_libxml_attr_value(
const xmlAttr *
attr,
bool *free);
220PHP_LIBXML_API
zend_string *php_libxml_sniff_charset_from_string(
const char *
start,
const char *
end);
224PHP_LIBXML_API
void php_libxml_initialize(
void);
225PHP_LIBXML_API
void php_libxml_shutdown(
void);
227#define LIBXML(v) ZEND_MODULE_GLOBALS_ACCESSOR(libxml, v)
229#if defined(ZTS) && defined(COMPILE_DL_LIBXML)
238# define PHP_LIBXML_SANITIZE_GLOBALS(unique_name) \
239 ZEND_DIAGNOSTIC_IGNORED_START("-Wdeprecated-declarations") \
240 int xml_old_loadsubset_##unique_name = xmlLoadExtDtdDefaultValue; \
241 xmlLoadExtDtdDefaultValue = 0; \
242 int xml_old_validate_##unique_name = xmlDoValidityCheckingDefaultValue; \
243 xmlDoValidityCheckingDefaultValue = 0; \
244 int xml_old_pedantic_##unique_name = xmlPedanticParserDefault(0); \
245 int xml_old_substitute_##unique_name = xmlSubstituteEntitiesDefault(0); \
246 int xml_old_linenrs_##unique_name = xmlLineNumbersDefault(0); \
247 int xml_old_blanks_##unique_name = xmlKeepBlanksDefault(1); \
248 ZEND_DIAGNOSTIC_IGNORED_END
250# define PHP_LIBXML_RESTORE_GLOBALS(unique_name) \
251 ZEND_DIAGNOSTIC_IGNORED_START("-Wdeprecated-declarations") \
252 xmlLoadExtDtdDefaultValue = xml_old_loadsubset_##unique_name; \
253 xmlDoValidityCheckingDefaultValue = xml_old_validate_##unique_name; \
254 (void) xmlPedanticParserDefault(xml_old_pedantic_##unique_name); \
255 (void) xmlSubstituteEntitiesDefault(xml_old_substitute_##unique_name); \
256 (void) xmlLineNumbersDefault(xml_old_linenrs_##unique_name); \
257 (void) xmlKeepBlanksDefault(xml_old_blanks_##unique_name); \
258 ZEND_DIAGNOSTIC_IGNORED_END
262static zend_always_inline void php_libxml_sanitize_parse_ctxt_options(xmlParserCtxtPtr ctxt)
265 ctxt->loadsubset = 0;
268 ctxt->replaceEntities = 0;
269 ctxt->linenumbers = 0;
270 ctxt->keepBlanks = 1;
276#define phpext_libxml_ptr libxml_module_ptr
file(string $filename, int $flags=0, $context=null)
unsigned const char * end
PHP_JSON_API size_t int options
xmlCharEncodingHandlerPtr encoding
struct _php_stream php_stream
struct _php_stream_context php_stream_context
struct php_libxml_private_data_header php_libxml_private_data_header
const zend_object_handlers * handlers
#define ZEND_TSRMLS_CACHE_EXTERN()
struct _zend_fcall_info_cache zend_fcall_info_cache
#define ZEND_END_MODULE_GLOBALS(module_name)
#define ZEND_BEGIN_MODULE_GLOBALS(module_name)
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
struct _zend_llist zend_llist
struct _zend_string zend_string
struct _zend_module_entry zend_module_entry
#define EXPECTED(condition)
#define ZEND_DIAGNOSTIC_IGNORED_END
#define zend_always_inline
#define ZEND_DIAGNOSTIC_IGNORED_START(warning)
#define UNEXPECTED(condition)
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
struct _zend_array HashTable