Index: php_libxml.h =================================================================== RCS file: /repository/php-src/ext/libxml/php_libxml.h,v retrieving revision 1.11 diff -r1.11 php_libxml.h 45a46 > zend_llist *error_list; 69a71,74 > PHP_FUNCTION(libxml_use_internal_errors); > PHP_FUNCTION(libxml_get_last_error); > PHP_FUNCTION(libxml_clear_errors); > PHP_FUNCTION(libxml_get_errors); 73,74c78,79 < int php_libxml_increment_doc_ref(php_libxml_node_object *object, xmlDocPtr docp TSRMLS_DC); < int php_libxml_decrement_doc_ref(php_libxml_node_object *object TSRMLS_DC); --- > PHP_LIBXML_API int php_libxml_increment_doc_ref(php_libxml_node_object *object, xmlDocPtr docp TSRMLS_DC); > PHP_LIBXML_API int php_libxml_decrement_doc_ref(php_libxml_node_object *object TSRMLS_DC); Index: libxml.c =================================================================== RCS file: /repository/php-src/ext/libxml/libxml.c,v retrieving revision 1.27 diff -r1.27 libxml.c 67a68,71 > #if LIBXML_VERSION >= 20600 > zend_class_entry *libxmlerror_class_entry; > #endif > 88a93,96 > PHP_FE(libxml_use_internal_errors, NULL) > PHP_FE(libxml_get_last_error, NULL) > PHP_FE(libxml_clear_errors, NULL) > PHP_FE(libxml_get_errors, NULL) 237a246 > LIBXML(error_list) = NULL; 327a337,375 > static int _php_libxml_free_error(xmlErrorPtr error) { > /* This will free the libxml alloc'd memory */ > xmlResetError(error); > return 1; > } > > static void _php_list_set_error_structure(xmlErrorPtr error, const char *msg) > { > xmlError error_copy; > int ret; > > TSRMLS_FETCH(); > > memset(&error_copy, 0, sizeof(xmlError)); > > if (error) { > ret = xmlCopyError(error, &error_copy); > } else { > error_copy.domain = 0; > error_copy.code = XML_ERR_INTERNAL_ERROR; > error_copy.level = XML_ERR_ERROR; > error_copy.line = 0; > error_copy.node = NULL; > error_copy.int1 = 0; > error_copy.int2 = 0; > error_copy.ctxt = NULL; > error_copy.message = xmlStrdup(msg); > error_copy.file = NULL; > error_copy.str1 = NULL; > error_copy.str2 = NULL; > error_copy.str3 = NULL; > ret = 0; > } > > if (ret == 0) { > zend_llist_add_element(LIBXML(error_list), &error_copy); > } > } > 364,372c412,424 < switch (error_type) { < case PHP_LIBXML_CTX_ERROR: < php_libxml_ctx_error_level(E_WARNING, ctx, LIBXML(error_buffer).c TSRMLS_CC); < break; < case PHP_LIBXML_CTX_WARNING: < php_libxml_ctx_error_level(E_NOTICE, ctx, LIBXML(error_buffer).c TSRMLS_CC); < break; < default: < php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", LIBXML(error_buffer).c); --- > if (LIBXML(error_list)) { > _php_list_set_error_structure(NULL, LIBXML(error_buffer).c); > } else { > switch (error_type) { > case PHP_LIBXML_CTX_ERROR: > php_libxml_ctx_error_level(E_WARNING, ctx, LIBXML(error_buffer).c TSRMLS_CC); > break; > case PHP_LIBXML_CTX_WARNING: > php_libxml_ctx_error_level(E_NOTICE, ctx, LIBXML(error_buffer).c TSRMLS_CC); > break; > default: > php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", LIBXML(error_buffer).c); > } 393a446,452 > PHP_LIBXML_API void php_libxml_structured_error_handler(void *userData, xmlErrorPtr error) > { > _php_list_set_error_structure(error, NULL); > > return; > } > 451a511,514 > #if LIBXML_VERSION >= 20600 > zend_class_entry ce; > #endif > 458a522 > LIBXML(error_list) = NULL; 473a538,546 > > /* Error levels */ > REGISTER_LONG_CONSTANT("LIBXML_ERR_NONE", XML_ERR_NONE, CONST_CS | CONST_PERSISTENT); > REGISTER_LONG_CONSTANT("LIBXML_ERR_WARNING", XML_ERR_WARNING, CONST_CS | CONST_PERSISTENT); > REGISTER_LONG_CONSTANT("LIBXML_ERR_ERROR", XML_ERR_ERROR, CONST_CS | CONST_PERSISTENT); > REGISTER_LONG_CONSTANT("LIBXML_ERR_FATAL", XML_ERR_FATAL, CONST_CS | CONST_PERSISTENT); > > INIT_CLASS_ENTRY(ce, "LibXMLError", NULL); > libxmlerror_class_entry = zend_register_internal_class(&ce TSRMLS_CC); 484d556 < 500a573 > xmlSetStructuredErrorFunc(NULL, NULL); 502a576,581 > if (LIBXML(error_list)) { > zend_llist_destroy(LIBXML(error_list)); > efree(LIBXML(error_list)); > LIBXML(error_list) = NULL; > } > 535a615,752 > /* {{{ proto void libxml_use_internal_errors(boolean use_errors) > Disable libxml errors and allow user to fetch error information as needed */ > PHP_FUNCTION(libxml_use_internal_errors) > { > #if LIBXML_VERSION >= 20600 > xmlStructuredErrorFunc current_handler; > int use_errors=0, retval; > > if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &use_errors) == FAILURE) { > return; > } > > current_handler = xmlStructuredError; > if (current_handler && current_handler == php_libxml_structured_error_handler) { > retval = 1; > } else { > retval = 0; > } > > if (ZEND_NUM_ARGS() == 0) { > RETURN_BOOL(retval); > } > > if (use_errors == 0) { > xmlSetStructuredErrorFunc(NULL, NULL); > if (LIBXML(error_list)) { > zend_llist_destroy(LIBXML(error_list)); > efree(LIBXML(error_list)); > LIBXML(error_list) = NULL; > } > } else { > xmlSetStructuredErrorFunc(NULL, php_libxml_structured_error_handler); > if (LIBXML(error_list) == NULL) { > LIBXML(error_list) = (zend_llist *) emalloc(sizeof(zend_llist)); > zend_llist_init(LIBXML(error_list), sizeof(xmlError), (llist_dtor_func_t) _php_libxml_free_error, 0); > } > } > RETURN_BOOL(retval); > #else > php_error_docref(NULL TSRMLS_CC, E_WARNING, "Libxml 2.6 or higher is required"); > #endif > } > > /* {{{ proto object libxml_get_last_error() > Retrieve last error from libxml */ > PHP_FUNCTION(libxml_get_last_error) > { > #if LIBXML_VERSION >= 20600 > xmlErrorPtr error; > > error = xmlGetLastError(); > > if (error) { > object_init_ex(return_value, libxmlerror_class_entry); > add_property_long(return_value, "level", error->level); > add_property_long(return_value, "code", error->code); > add_property_long(return_value, "column", error->int2); > if (error->message) { > add_property_string(return_value, "message", error->message, 1); > } else { > add_property_stringl(return_value, "message", "", 0, 1); > } > if (error->file) { > add_property_string(return_value, "file", error->file, 1); > } else { > add_property_stringl(return_value, "file", "", 0, 1); > } > add_property_long(return_value, "line", error->line); > } else { > RETURN_FALSE; > } > #else > php_error_docref(NULL TSRMLS_CC, E_WARNING, "Libxml 2.6 or higher is required"); > #endif > } > /* }}} */ > > /* {{{ proto object libxml_get_errors() > Retrieve array of errors */ > PHP_FUNCTION(libxml_get_errors) > { > #if LIBXML_VERSION >= 20600 > > xmlErrorPtr error; > > if (array_init(return_value) == FAILURE) { > RETURN_FALSE; > } > > if (LIBXML(error_list)) { > > error = zend_llist_get_first(LIBXML(error_list)); > > while (error != NULL) { > zval *z_error; > MAKE_STD_ZVAL(z_error); > > object_init_ex(z_error, libxmlerror_class_entry); > add_property_long(z_error, "level", error->level); > add_property_long(z_error, "code", error->code); > add_property_long(z_error, "column", error->int2); > if (error->message) { > add_property_string(z_error, "message", error->message, 1); > } else { > add_property_stringl(z_error, "message", "", 0, 1); > } > if (error->file) { > add_property_string(z_error, "file", error->file, 1); > } else { > add_property_stringl(z_error, "file", "", 0, 1); > } > add_property_long(z_error, "line", error->line); > add_next_index_zval(return_value, z_error); > > error = zend_llist_get_next(LIBXML(error_list)); > } > } > #else > php_error_docref(NULL TSRMLS_CC, E_WARNING, "Libxml 2.6 or higher is required"); > #endif > } > /* }}} */ > > /* {{{ proto void libxml_clear_errors() > Clear last error from libxml */ > PHP_FUNCTION(libxml_clear_errors) > { > #if LIBXML_VERSION >= 20600 > xmlResetLastError(); > if (LIBXML(error_list)) { > zend_llist_clean(LIBXML(error_list)); > } > #else > php_error_docref(NULL TSRMLS_CC, E_WARNING, "Libxml 2.6 or higher is required"); > #endif > } > /* }}} */ >