32#include <libxml/parser.h>
33#include <libxml/parserInternals.h>
34#include <libxml/tree.h>
35#include <libxml/uri.h>
36#include <libxml/xmlerror.h>
37#include <libxml/xmlsave.h>
38#include <libxml/xmlerror.h>
39#include <libxml/entities.h>
40#ifdef LIBXML_SCHEMAS_ENABLED
41#include <libxml/relaxng.h>
42#include <libxml/xmlschemas.h>
47#define PHP_LIBXML_LOADED_VERSION ((char *)xmlParserVersion)
52static int _php_libxml_initialized = 0;
53static int _php_libxml_per_request_initialization = 1;
54static xmlExternalEntityLoader _php_libxml_default_entity_loader;
56typedef struct _php_libxml_func_handler {
57 php_libxml_export_node export_func;
58} php_libxml_func_handler;
68#ifdef COMPILE_DL_LIBXML
84static zend_string *php_libxml_default_dump_node_to_str(xmlDocPtr doc, xmlNodePtr node,
bool format,
const char *
encoding);
86static zend_long php_libxml_dump_node_to_file(
const char *filename, xmlDocPtr doc, xmlNodePtr node,
bool format,
const char *
encoding);
87static zend_long php_libxml_default_dump_doc_to_file(
const char *filename, xmlDocPtr doc,
bool format,
const char *
encoding);
104 php_libxml_post_deactivate,
110static const php_libxml_document_handlers php_libxml_default_document_handlers = {
111 .dump_node_to_str = php_libxml_default_dump_node_to_str,
112 .dump_doc_to_str = php_libxml_default_dump_doc_to_str,
113 .dump_node_to_file = php_libxml_dump_node_to_file,
114 .dump_doc_to_file = php_libxml_default_dump_doc_to_file,
117static void php_libxml_set_old_ns_list(xmlDocPtr doc, xmlNsPtr first, xmlNsPtr
last)
131 doc->oldNs = (xmlNsPtr) xmlMalloc(
sizeof(xmlNs));
132 if (doc->oldNs ==
NULL) {
135 memset(doc->oldNs, 0,
sizeof(xmlNs));
137 doc->oldNs->href = xmlStrdup(XML_XML_NAMESPACE);
138 doc->oldNs->prefix = xmlStrdup((
const xmlChar *)
"xml");
140 last->next = doc->oldNs->next;
142 doc->oldNs->next = first;
145PHP_LIBXML_API
void php_libxml_set_old_ns(xmlDocPtr doc, xmlNsPtr ns)
147 php_libxml_set_old_ns_list(doc, ns, ns);
151#if LIBXML_VERSION >= 20908
152static void php_libxml_unlink_entity(
void *
data,
void *table,
const xmlChar *
name)
154static void php_libxml_unlink_entity(
void *
data,
void *table, xmlChar *
name)
157 xmlEntityPtr entity =
data;
158 if (entity->_private !=
NULL) {
159 xmlHashRemoveEntry(table,
name,
NULL);
164static void php_libxml_unregister_node(xmlNodePtr nodep)
166 php_libxml_node_ptr *nodeptr = nodep->_private;
168 if (nodeptr !=
NULL) {
169 php_libxml_node_object *wrapper = nodeptr->_private;
171 php_libxml_decrement_node_ptr(wrapper);
172 php_libxml_decrement_doc_ref(wrapper);
175 nodep->_private =
NULL;
177 nodeptr->node =
NULL;
183static void php_libxml_unlink_entity_decl(xmlEntityPtr entity)
185 xmlDtdPtr dtd = entity->parent;
187 if (xmlHashLookup(dtd->entities, entity->name) == entity) {
188 xmlHashRemoveEntry(dtd->entities, entity->name,
NULL);
190 if (xmlHashLookup(dtd->pentities, entity->name) == entity) {
191 xmlHashRemoveEntry(dtd->pentities, entity->name,
NULL);
196static void php_libxml_node_free(xmlNodePtr node)
198 if (node->_private !=
NULL) {
199 ((php_libxml_node_ptr *) node->_private)->node =
NULL;
201 switch (node->type) {
203 xmlFreeProp((xmlAttrPtr) node);
207 case XML_ENTITY_DECL: {
208 xmlEntityPtr entity = (xmlEntityPtr) node;
209 if (entity->etype != XML_INTERNAL_PREDEFINED_ENTITY) {
210 php_libxml_unlink_entity_decl(entity);
211#if LIBXML_VERSION >= 21200
212 xmlFreeEntity(entity);
214 if (entity->children !=
NULL && entity->owner && entity == (xmlEntityPtr) entity->children->parent) {
215 xmlFreeNodeList(entity->children);
217 xmlDictPtr dict = entity->doc !=
NULL ? entity->doc->dict :
NULL;
218 if (dict ==
NULL || !xmlDictOwns(dict, entity->name)) {
219 xmlFree((xmlChar *) entity->name);
221 if (dict ==
NULL || !xmlDictOwns(dict, entity->ExternalID)) {
222 xmlFree((xmlChar *) entity->ExternalID);
224 if (dict ==
NULL || !xmlDictOwns(dict, entity->SystemID)) {
225 xmlFree((xmlChar *) entity->SystemID);
227 if (dict ==
NULL || !xmlDictOwns(dict, entity->URI)) {
228 xmlFree((xmlChar *) entity->URI);
230 if (dict ==
NULL || !xmlDictOwns(dict, entity->content)) {
231 xmlFree(entity->content);
233 if (dict ==
NULL || !xmlDictOwns(dict, entity->orig)) {
234 xmlFree(entity->orig);
243 xmlEntityPtr entity = (xmlEntityPtr) node;
244 if (node->name !=
NULL) {
245 xmlFree((
char *) node->name);
247 if (entity->ExternalID !=
NULL) {
248 xmlFree((
char *) entity->ExternalID);
250 if (entity->SystemID !=
NULL) {
251 xmlFree((
char *) entity->SystemID);
256 case XML_ELEMENT_DECL:
257 case XML_ATTRIBUTE_DECL:
259 case XML_NAMESPACE_DECL:
268 xmlDtdPtr dtd = (xmlDtdPtr) node;
269 if (dtd->_private ==
NULL) {
272 xmlHashScan(dtd->entities, php_libxml_unlink_entity, dtd->entities);
273 xmlHashScan(dtd->pentities, php_libxml_unlink_entity, dtd->pentities);
280 if (node->ns && (((uintptr_t) node->ns->_private) & 1) == LIBXML_NS_TAG_HOOK) {
285 if (node->nsDef && node->doc) {
306 xmlNsPtr ns = node->nsDef;
311 php_libxml_set_old_ns_list(node->doc, ns,
last);
323PHP_LIBXML_API
void php_libxml_node_free_list(xmlNodePtr node)
329 while (curnode !=
NULL) {
331 if (curnode->_private) {
332 xmlNodePtr
next = curnode->next;
334 xmlUnlinkNode(curnode);
338 php_libxml_node_ptr *
ptr = curnode->_private;
342 php_libxml_node_object *obj =
ptr->_private;
343 if (!obj->document || obj->document->class_type < PHP_LIBXML_CLASS_MODERN) {
344 xmlReconciliateNs(curnode->doc, curnode);
354 switch (node->type) {
359 case XML_ENTITY_DECL:
360 php_libxml_unlink_entity_decl((xmlEntityPtr) node);
364 xmlRemoveID(node->doc, (xmlAttrPtr) node);
367 case XML_ATTRIBUTE_DECL:
370 case XML_NAMESPACE_DECL:
372 php_libxml_node_free_list(node->children);
375 php_libxml_node_free_list(node->children);
376 php_libxml_node_free_list((xmlNodePtr) node->properties);
379 curnode = node->next;
381 php_libxml_unregister_node(node);
382 php_libxml_node_free(node);
392#if defined(COMPILE_DL_LIBXML) && defined(ZTS)
396 libxml_globals->error_buffer.s =
NULL;
397 libxml_globals->error_list =
NULL;
409static void *php_libxml_streams_IO_open_wrapper(
const char *filename,
const char *
mode,
const int read_only)
413 const char *path_to_open =
NULL;
414 bool isescaped =
false;
416 if (
strstr(filename,
"%00")) {
421 xmlURI *uri = xmlParseURI(filename);
422 if (uri && (uri->scheme ==
NULL ||
423 (xmlStrncmp(BAD_CAST uri->scheme, BAD_CAST
"file", 4) == 0))) {
424 resolved_path = xmlURIUnescapeString(filename, 0,
NULL);
426#if LIBXML_VERSION >= 20902 && LIBXML_VERSION < 21300 && defined(PHP_WIN32)
432 size_t pre_len =
sizeof(
"file:/") - 1;
434 if (
strncasecmp(resolved_path,
"file:/", pre_len) == 0
435 &&
'/' != resolved_path[pre_len]) {
436 xmlChar *tmp = xmlStrdup(resolved_path + pre_len);
437 xmlFree(resolved_path);
443 resolved_path = (
char *)filename;
450 if (resolved_path ==
NULL) {
464 xmlFree(resolved_path);
478 xmlFree(resolved_path);
483static void *php_libxml_streams_IO_open_read_wrapper(
const char *filename)
485 return php_libxml_streams_IO_open_wrapper(filename,
"rb", 1);
488static void *php_libxml_streams_IO_open_write_wrapper(
const char *filename)
490 return php_libxml_streams_IO_open_wrapper(filename,
"wb", 0);
498static int php_libxml_streams_IO_write(
void *
context,
const char *
buffer,
int len)
503static int php_libxml_streams_IO_close(
void *
context)
508static xmlParserInputBufferPtr
509php_libxml_input_buffer_create_filename(
const char *URI, xmlCharEncoding enc)
511 xmlParserInputBufferPtr
ret;
514 if (LIBXML(entity_loader_disabled)) {
521 context = php_libxml_streams_IO_open_read_wrapper(URI);
528 if (enc == XML_CHAR_ENCODING_NONE) {
533 if (enc <= XML_CHAR_ENCODING_NONE) {
534 enc = XML_CHAR_ENCODING_NONE;
541 ret = xmlAllocParserInputBuffer(enc);
544 ret->readcallback = php_libxml_streams_IO_read;
545 ret->closecallback = php_libxml_streams_IO_close;
547 php_libxml_streams_IO_close(
context);
552static xmlOutputBufferPtr
553php_libxml_output_buffer_create_filename(
const char *URI,
554 xmlCharEncodingHandlerPtr encoder,
559 xmlOutputBufferPtr
ret;
562 char *unescaped =
NULL;
572 puri = xmlParseURI(URI);
574 if (puri->scheme !=
NULL)
575 unescaped = xmlURIUnescapeString(URI, 0,
NULL);
579 if (unescaped !=
NULL) {
580 context = php_libxml_streams_IO_open_write_wrapper(unescaped);
586 context = php_libxml_streams_IO_open_write_wrapper(URI);
594 ret = xmlAllocOutputBuffer(encoder);
597 ret->writecallback = php_libxml_streams_IO_write;
598 ret->closecallback = php_libxml_streams_IO_close;
605 xmlCharEncCloseFunc(encoder);
609static void _php_libxml_free_error(
void *
ptr)
612 xmlResetError((xmlErrorPtr)
ptr);
615#if LIBXML_VERSION >= 21200
616static void _php_list_set_error_structure(
const xmlError *
error,
const char *
msg,
int line,
int column)
618static void _php_list_set_error_structure(xmlError *
error,
const char *
msg,
int line,
int column)
625 memset(&error_copy, 0,
sizeof(xmlError));
628 ret = xmlCopyError(
error, &error_copy);
630 error_copy.code = XML_ERR_INTERNAL_ERROR;
631 error_copy.level = XML_ERR_ERROR;
632 error_copy.line =
line;
633 error_copy.int2 = column;
634 error_copy.message = (
char*)xmlStrdup((
const xmlChar*)
msg);
643static void php_libxml_ctx_error_level(
int level,
void *ctx,
const char *
msg,
int line)
645 xmlParserCtxtPtr parser;
647 parser = (xmlParserCtxtPtr) ctx;
649 if (parser !=
NULL && parser->input !=
NULL) {
650 if (parser->input->filename) {
660void php_libxml_issue_error(
int level,
const char *
msg)
662 if (LIBXML(error_list)) {
663 _php_list_set_error_structure(
NULL,
msg, 0, 0);
669static void php_libxml_internal_error_handler_ex(php_libxml_error_level error_type,
void *ctx,
const char *
msg, va_list ap,
int line,
int column)
675 size_t len_iter =
len;
678 while (len_iter &&
buf[--len_iter] ==
'\n') {
679 buf[len_iter] =
'\0';
683 smart_str_appendl(&LIBXML(error_buffer),
buf,
len);
688 if (LIBXML(error_list)) {
689 _php_list_set_error_structure(
NULL,
ZSTR_VAL(LIBXML(error_buffer).
s),
line, column);
692 switch (error_type) {
693 case PHP_LIBXML_CTX_ERROR:
696 case PHP_LIBXML_CTX_WARNING:
703 smart_str_free(&LIBXML(error_buffer));
707PHP_LIBXML_API
void php_libxml_error_handler_va(php_libxml_error_level error_type,
void *ctx,
const char *
msg, va_list ap)
711 xmlParserCtxtPtr parser = (xmlParserCtxtPtr) ctx;
713 if (error_type != PHP_LIBXML_ERROR && parser !=
NULL && parser->input !=
NULL) {
714 line = parser->input->line;
715 column = parser->input->col;
717 php_libxml_internal_error_handler_ex(error_type, ctx,
msg, ap,
line, column);
720static xmlParserInputPtr _php_libxml_external_entity_loader(
const char *URL,
721 const char *ID, xmlParserCtxtPtr
context)
724 const char *resource =
NULL;
730 return _php_libxml_default_entity_loader(URL, ID,
context);
746#define ADD_NULL_OR_STRING_KEY(memb) \
747 if (context->memb == NULL) { \
748 add_assoc_null_ex(ctxzv, #memb, sizeof(#memb) - 1); \
750 add_assoc_string_ex(ctxzv, #memb, sizeof(#memb) - 1, \
751 (char *)context->memb); \
754 ADD_NULL_OR_STRING_KEY(directory)
755 ADD_NULL_OR_STRING_KEY(intSubName)
756 ADD_NULL_OR_STRING_KEY(extSubURI)
757 ADD_NULL_OR_STRING_KEY(extSubSystem)
759#undef ADD_NULL_OR_STRING_KEY
761 zend_call_known_fcc(&LIBXML(entity_loader_callback), &
retval, 3, params,
NULL);
765 "Call to user entity loader callback '%s' has failed",
766 ZSTR_VAL(LIBXML(entity_loader_callback).function_handler->common.function_name));
779 "%s(): The user entity loader callback \"%s\" has returned a resource, but it is not a stream",
782 zend_string_release(callable_name);
786 xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
787 xmlParserInputBufferPtr pib = xmlAllocParserInputBuffer(enc);
789 php_libxml_ctx_error(
context,
"Could not allocate parser "
794 pib->context = stream;
795 pib->readcallback = php_libxml_streams_IO_read;
796 pib->closecallback = php_libxml_streams_IO_close;
800 xmlFreeParserInputBuffer(pib);
806 if (try_convert_to_string(&
retval)) {
813 if (resource ==
NULL) {
816 "Failed to load external entity because the resolver function returned null\n");
819 "Failed to load external entity \"%s\"\n", ID);
834static xmlParserInputPtr _php_libxml_pre_ext_ent_loader(
const char *URL,
835 const char *ID, xmlParserCtxtPtr
context)
847 if (xmlGenericError == php_libxml_error_handler &&
PG(modules_activated)) {
848 return _php_libxml_external_entity_loader(URL, ID,
context);
850 return _php_libxml_default_entity_loader(URL, ID,
context);
854PHP_LIBXML_API
void php_libxml_pretend_ctx_error_ex(
const char *
file,
int line,
int column,
const char *
msg,...)
858 php_libxml_internal_error_handler_ex(PHP_LIBXML_CTX_ERROR,
NULL,
msg,
args,
line, column);
862 if (LIBXML(error_list)) {
863 xmlErrorPtr
last = zend_llist_get_last(LIBXML(error_list));
870PHP_LIBXML_API
void php_libxml_ctx_error(
void *ctx,
const char *
msg, ...)
874 php_libxml_error_handler_va(PHP_LIBXML_CTX_ERROR, ctx,
msg,
args);
878PHP_LIBXML_API
void php_libxml_ctx_warning(
void *ctx,
const char *
msg, ...)
882 php_libxml_error_handler_va(PHP_LIBXML_CTX_WARNING, ctx,
msg,
args);
886#if LIBXML_VERSION >= 21200
887static void php_libxml_structured_error_handler(
void *userData,
const xmlError *
error)
889static void php_libxml_structured_error_handler(
void *userData, xmlErrorPtr
error)
892 _php_list_set_error_structure(
error,
NULL, 0, 0);
895PHP_LIBXML_API
void php_libxml_error_handler(
void *ctx,
const char *
msg, ...)
899 php_libxml_error_handler_va(PHP_LIBXML_ERROR, ctx,
msg,
args);
903static void php_libxml_exports_dtor(
zval *
zv)
908PHP_LIBXML_API
void php_libxml_initialize(
void)
910 if (!_php_libxml_initialized) {
916 _php_libxml_default_entity_loader = xmlGetExternalEntityLoader();
917 xmlSetExternalEntityLoader(_php_libxml_pre_ext_ent_loader);
921 _php_libxml_initialized = 1;
925PHP_LIBXML_API
void php_libxml_shutdown(
void)
927 if (_php_libxml_initialized) {
928#if defined(LIBXML_SCHEMAS_ENABLED) && LIBXML_VERSION < 21000
929 xmlRelaxNGCleanupTypes();
934 xmlSetExternalEntityLoader(_php_libxml_default_entity_loader);
935 _php_libxml_initialized = 0;
939PHP_LIBXML_API
void php_libxml_switch_context(
zval *
context,
zval *oldcontext)
951 php_libxml_initialize();
953 register_libxml_symbols(module_number);
955 libxmlerror_class_entry = register_class_LibXMLError();
958 static const char *
const supported_sapis[] = {
963 const char *
const *sapi_name;
965 for (sapi_name = supported_sapis; *sapi_name; sapi_name++) {
967 _php_libxml_per_request_initialization = 0;
973 if (!_php_libxml_per_request_initialization) {
975 xmlSetGenericErrorFunc(
NULL, php_libxml_error_handler);
976 xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_create_filename);
977 xmlOutputBufferCreateFilenameDefault(php_libxml_output_buffer_create_filename);
986 if (_php_libxml_per_request_initialization) {
988 xmlSetGenericErrorFunc(
NULL, php_libxml_error_handler);
989 xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_create_filename);
990 xmlOutputBufferCreateFilenameDefault(php_libxml_output_buffer_create_filename);
997 LIBXML(entity_loader_disabled) = 0;
1005 zend_fcc_dtor(&LIBXML(entity_loader_callback));
1013 if (!_php_libxml_per_request_initialization) {
1014 xmlSetGenericErrorFunc(
NULL,
NULL);
1016 xmlParserInputBufferCreateFilenameDefault(
NULL);
1017 xmlOutputBufferCreateFilenameDefault(
NULL);
1019 php_libxml_shutdown();
1024static zend_result php_libxml_post_deactivate(
void)
1027 if (_php_libxml_per_request_initialization) {
1028 xmlSetGenericErrorFunc(
NULL,
NULL);
1030 xmlParserInputBufferCreateFilenameDefault(
NULL);
1031 xmlOutputBufferCreateFilenameDefault(
NULL);
1033 xmlSetStructuredErrorFunc(
NULL,
NULL);
1037 smart_str_free(&LIBXML(error_buffer));
1038 if (LIBXML(error_list)) {
1040 efree(LIBXML(error_list));
1041 LIBXML(error_list) =
NULL;
1043 xmlResetLastError();
1070 if (!
Z_ISUNDEF(LIBXML(stream_context))) {
1078PHP_LIBXML_API
bool php_libxml_uses_internal_errors(
void)
1080 return xmlStructuredError == php_libxml_structured_error_handler;
1086 bool use_errors, use_errors_is_null =
true;
1093 bool retval = php_libxml_uses_internal_errors();
1095 if (use_errors_is_null) {
1099 if (use_errors == 0) {
1100 xmlSetStructuredErrorFunc(
NULL,
NULL);
1101 if (LIBXML(error_list)) {
1103 efree(LIBXML(error_list));
1104 LIBXML(error_list) =
NULL;
1107 xmlSetStructuredErrorFunc(
NULL, php_libxml_structured_error_handler);
1108 if (LIBXML(error_list) ==
NULL) {
1110 zend_llist_init(LIBXML(error_list),
sizeof(xmlError), _php_libxml_free_error, 0);
1123 if (
error->message) {
1141 const xmlError *
error;
1143 if (LIBXML(error_list)) {
1144 error = zend_llist_get_last(LIBXML(error_list));
1146 error = xmlGetLastError();
1164 if (LIBXML(error_list)) {
1166 error = zend_llist_get_first(LIBXML(error_list));
1170 php_libxml_create_error_object(&z_error,
error);
1172 error = zend_llist_get_next(LIBXML(error_list));
1185 xmlResetLastError();
1186 if (LIBXML(error_list)) {
1192PHP_LIBXML_API
bool php_libxml_disable_entity_loader(
bool disable)
1194 bool old = LIBXML(entity_loader_disabled);
1196 LIBXML(entity_loader_disabled) = disable;
1210 RETURN_BOOL(php_libxml_disable_entity_loader(disable));
1226 zend_fcc_dtor(&LIBXML(entity_loader_callback));
1229 zend_fcc_dup(&LIBXML(entity_loader_callback), &fcc);
1249int php_libxml_xmlCheckUTF8(
const unsigned char *
s)
1254 for (i = 0; (c =
s[i++]);) {
1255 if ((c & 0x80) == 0) {
1256 }
else if ((c & 0xe0) == 0xc0) {
1257 if ((
s[i++] & 0xc0) != 0x80) {
1260 }
else if ((c & 0xf0) == 0xe0) {
1261 if ((
s[i++] & 0xc0) != 0x80 || (
s[i++] & 0xc0) != 0x80) {
1264 }
else if ((c & 0xf8) == 0xf0) {
1265 if ((
s[i++] & 0xc0) != 0x80 || (
s[i++] & 0xc0) != 0x80 || (
s[i++] & 0xc0) != 0x80) {
1277 php_libxml_func_handler export_hnd;
1280 php_libxml_initialize();
1281 export_hnd.export_func = export_function;
1283 return zend_hash_add_mem(&php_libxml_exports, ce->
name, &export_hnd,
sizeof(export_hnd));
1286PHP_LIBXML_API xmlNodePtr php_libxml_import_node(
zval *
object)
1289 xmlNodePtr node =
NULL;
1290 php_libxml_func_handler *export_hnd;
1297 if ((export_hnd = zend_hash_find_ptr(&php_libxml_exports, ce->
name))) {
1298 node = export_hnd->export_func(
object);
1304PHP_LIBXML_API
int php_libxml_increment_node_ptr(php_libxml_node_object *
object, xmlNodePtr node,
void *private_data)
1306 int ret_refcount = -1;
1308 if (
object !=
NULL && node !=
NULL) {
1310 if (
object->node->node == node) {
1311 return object->node->refcount;
1313 php_libxml_decrement_node_ptr(
object);
1316 if (node->_private !=
NULL) {
1317 object->node = node->_private;
1318 ret_refcount = ++
object->node->refcount;
1321 object->node->_private = private_data;
1324 object->node =
emalloc(
sizeof(php_libxml_node_ptr));
1326 object->node->node = node;
1327 object->node->refcount = 1;
1328 object->node->_private = private_data;
1329 node->_private =
object->node;
1333 return ret_refcount;
1336PHP_LIBXML_API
int php_libxml_decrement_node_ptr_ref(php_libxml_node_ptr *
ptr)
1340 int ret_refcount = --
ptr->refcount;
1341 if (ret_refcount == 0) {
1345 if (
ptr->_private) {
1346 php_libxml_node_object *
object = (php_libxml_node_object *)
ptr->_private;
1347 object->node =
NULL;
1351 return ret_refcount;
1354PHP_LIBXML_API
int php_libxml_decrement_node_ptr(php_libxml_node_object *
object)
1357 return php_libxml_decrement_node_ptr_ref(
object->node);
1362PHP_LIBXML_API
int php_libxml_increment_doc_ref(php_libxml_node_object *
object, xmlDocPtr docp)
1364 int ret_refcount = -1;
1367 object->document->refcount++;
1368 ret_refcount =
object->document->refcount;
1369 }
else if (docp !=
NULL) {
1371 object->document =
emalloc(
sizeof(php_libxml_ref_obj));
1372 object->document->ptr = docp;
1373 object->document->refcount = ret_refcount;
1374 object->document->doc_props =
NULL;
1375 object->document->cache_tag.modification_nr = 1;
1376 object->document->private_data =
NULL;
1377 object->document->class_type = PHP_LIBXML_CLASS_UNSET;
1378 object->document->handlers = &php_libxml_default_document_handlers;
1379 object->document->quirks_mode = PHP_LIBXML_NO_QUIRKS;
1382 return ret_refcount;
1385PHP_LIBXML_API
int php_libxml_decrement_doc_ref_directly(php_libxml_ref_obj *document)
1387 int ret_refcount = --document->refcount;
1388 if (ret_refcount == 0) {
1389 if (document->private_data !=
NULL) {
1390 document->private_data->dtor(document->private_data);
1392 if (document->ptr !=
NULL) {
1393 xmlFreeDoc((xmlDoc *) document->ptr);
1395 if (document->doc_props !=
NULL) {
1396 if (document->doc_props->classmap) {
1400 efree(document->doc_props);
1405 return ret_refcount;
1408PHP_LIBXML_API
int php_libxml_decrement_doc_ref(php_libxml_node_object *
object)
1410 int ret_refcount = -1;
1413 ret_refcount = php_libxml_decrement_doc_ref_directly(
object->document);
1414 object->document =
NULL;
1417 return ret_refcount;
1420PHP_LIBXML_API
void php_libxml_node_free_resource(xmlNodePtr node)
1426 switch (node->type) {
1434 php_libxml_unregister_node(node);
1435 if (node->parent ==
NULL) {
1436 php_libxml_node_free(node);
1440 if (node->parent ==
NULL || node->type == XML_NAMESPACE_DECL) {
1441 php_libxml_node_free_list((xmlNodePtr) node->children);
1443 php_libxml_node_free_list((xmlNodePtr) node->properties);
1445 php_libxml_unregister_node(node);
1446 php_libxml_node_free(node);
1448 php_libxml_unregister_node(node);
1453PHP_LIBXML_API
void php_libxml_node_decrement_resource(php_libxml_node_object *
object)
1456 php_libxml_node_ptr *obj_node = (php_libxml_node_ptr *)
object->node;
1457 xmlNodePtr nodep = obj_node->node;
1458 int ret_refcount = php_libxml_decrement_node_ptr(
object);
1459 if (ret_refcount == 0) {
1460 php_libxml_node_free_resource(nodep);
1462 if (
object == obj_node->_private) {
1463 obj_node->_private =
NULL;
1469 php_libxml_decrement_doc_ref(
object);
1474PHP_LIBXML_API xmlChar *php_libxml_attr_value(
const xmlAttr *
attr,
bool *free)
1488 if (
attr->children->content ==
NULL) {
1491 return attr->children->content;
1495 xmlChar *
value = xmlNodeGetContent((
const xmlNode *)
attr);
1504static int php_libxml_write_smart_str(
void *
context,
const char *
buffer,
int len)
1516 xmlSaveCtxtPtr ctxt = xmlSaveToIO(php_libxml_write_smart_str,
NULL, &str,
encoding,
options);
1521 long status = xmlSaveDoc(ctxt, doc);
1522 (
void) xmlSaveClose(ctxt);
1524 smart_str_free_ex(&str,
false);
1528 return smart_str_extract(&str);
1531static zend_string *php_libxml_default_dump_node_to_str(xmlDocPtr doc, xmlNodePtr node,
bool format,
const char *
encoding)
1535 xmlOutputBufferPtr
buf = xmlOutputBufferCreateIO(php_libxml_write_smart_str,
NULL, &str,
NULL);
1540 xmlNodeDumpOutput(
buf, doc, node, 0, format,
encoding);
1542 if (xmlOutputBufferFlush(
buf) < 0) {
1543 smart_str_free_ex(&str,
false);
1544 xmlOutputBufferClose(
buf);
1548 xmlOutputBufferClose(
buf);
1550 return smart_str_extract(&str);
1553static zend_long php_libxml_default_dump_doc_to_file(
const char *filename, xmlDocPtr doc,
bool format,
const char *
encoding)
1555 return xmlSaveFormatFileEnc(filename, doc,
encoding, format);
1558static zend_long php_libxml_dump_node_to_file(
const char *filename, xmlDocPtr doc, xmlNodePtr node,
bool format,
const char *
encoding)
1560 xmlOutputBufferPtr outbuf = xmlOutputBufferCreateFilename(filename,
NULL, 0);
1565 xmlNodeDumpOutput(outbuf, doc, node, 0, format,
encoding);
1566 return xmlOutputBufferClose(outbuf);
1569#if defined(PHP_WIN32) && defined(COMPILE_DL_LIBXML)
1570PHP_LIBXML_API
BOOL WINAPI
DllMain(HINSTANCE hinstDLL,
DWORD fdwReason, LPVOID lpvReserved)
1572 return xmlDllMain(hinstDLL, fdwReason, lpvReserved);
SAPI_API sapi_module_struct sapi_module
file(string $filename, int $flags=0, $context=null)
header(string $header, bool $replace=true, int $response_code=0)
strstr(string $haystack, string $needle, bool $before_needle=false)
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID dummy)
memset(ptr, 0, type->size)
zend_ffi_ctype_name_buf buf
foreach($dp as $el) foreach( $dp as $el) if( $pass2< 2) echo ""
enum entity_charset charset
libxml_use_internal_errors(?bool $use_errors=null)
libxml_get_external_entity_loader()
libxml_disable_entity_loader(bool $disable=true)
libxml_set_streams_context($context)
libxml_set_external_entity_loader(?callable $resolver_function)
const LIBXML_DOTTED_VERSION
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
php_info_print_table_start()
php_info_print_table_row(2, "PDO Driver for Firebird", "enabled")
php_info_print_table_end()
#define PHP_MSHUTDOWN_FUNCTION
#define PHP_MINIT_FUNCTION
#define PHP_MINFO_FUNCTION
#define PHP_GINIT_FUNCTION
#define PHP_RINIT_FUNCTION
#define PHP_RSHUTDOWN_FUNCTION
#define PHP_MODULE_GLOBALS
const XML_DOCUMENT_TYPE_NODE
const XML_HTML_DOCUMENT_NODE
const XML_LOCAL_NAMESPACE
const XML_ENTITY_REF_NODE
PHP_JSON_API size_t int options
xmlCharEncodingHandlerPtr encoding
#define php_stream_context_from_zval(zcontext, nocontext)
struct _php_stream php_stream
struct _php_stream_context php_stream_context
#define php_stream_read(stream, buf, count)
#define php_stream_open_wrapper_ex(path, mode, options, opened, context)
#define php_stream_close(stream)
PHPAPI int php_file_le_pstream(void)
struct _php_stream_wrapper php_stream_wrapper
#define PHP_STREAM_FLAG_NO_FCLOSE
PHPAPI php_stream_wrapper * php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options)
#define PHP_STREAM_URL_STAT_QUIET
struct _php_stream_statbuf php_stream_statbuf
#define php_stream_write(stream, buf, count)
PHPAPI int php_file_le_stream(void)
struct php_libxml_private_data_header php_libxml_private_data_header
int(* url_stat)(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context)
const php_stream_wrapper_ops * wops
zend_class_entry * parent
ZEND_API ZEND_COLD void zend_type_error(const char *format,...)
#define ZEND_TSRMLS_CACHE_UPDATE()
#define ZEND_TSRMLS_CACHE_DEFINE()
ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *class_type)
ZEND_API void zend_get_callable_zval_from_fcc(const zend_fcall_info_cache *fcc, zval *callable)
ZEND_API zend_string * zend_get_callable_name(zval *callable)
ZEND_API const zend_fcall_info_cache empty_fcall_info_cache
struct _zend_fcall_info_cache zend_fcall_info_cache
#define ZEND_PARSE_PARAMETERS_END()
#define Z_PARAM_RESOURCE(dest)
#define ZEND_PARSE_PARAMETERS_NONE()
#define ZVAL_STRING(z, s)
#define ZEND_DECLARE_MODULE_GLOBALS(module_name)
#define array_init_size(arg, size)
#define ZEND_GET_MODULE(name)
#define ZEND_FCI_INITIALIZED(fci)
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
#define Z_PARAM_BOOL_OR_NULL(dest, is_null)
struct _zend_fcall_info zend_fcall_info
#define Z_PARAM_FUNC_NO_TRAMPOLINE_FREE_OR_NULL(dest_fci, dest_fcc)
#define ZEND_FCC_INITIALIZED(fcc)
#define Z_PARAM_BOOL(dest)
#define RETURN_EMPTY_ARRAY()
#define FREE_HASHTABLE(ht)
strcmp(string $string1, string $string2)
zend_string_release_ex(func->internal_function.function_name, 0)
#define strncasecmp(s1, s2, n)
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
ZEND_API zend_string * get_active_function_or_method_name(void)
ZEND_API void ZEND_FASTCALL zend_hash_destroy(HashTable *ht)
#define zend_hash_init(ht, nSize, pHashFunction, pDestructor, persistent)
ZEND_API void * zend_fetch_resource2_ex(zval *res, const char *resource_type_name, int resource_type1, int resource_type2)
ZEND_API void zend_llist_destroy(zend_llist *l)
ZEND_API void zend_llist_add_element(zend_llist *l, const void *element)
ZEND_API void zend_llist_init(zend_llist *l, size_t size, llist_dtor_func_t dtor, unsigned char persistent)
ZEND_API void zend_llist_clean(zend_llist *l)
struct _zend_llist zend_llist
struct _zend_string zend_string
#define STANDARD_MODULE_HEADER
struct _zend_module_entry zend_module_entry
#define STANDARD_MODULE_PROPERTIES_EX
#define ZEND_IGNORE_LEAKS_END()
#define ZEND_IGNORE_VALUE(x)
#define ZEND_IGNORE_LEAKS_BEGIN()
#define UNEXPECTED(condition)
struct _zend_class_entry zend_class_entry
ZEND_API zend_string * zend_empty_string
struct _zend_array HashTable
#define Z_OBJCE_P(zval_p)
ZEND_RESULT_CODE zend_result
#define ZVAL_COPY_VALUE(z, v)
ZEND_API void zval_ptr_dtor(zval *zval_ptr)