summaryrefslogtreecommitdiff
path: root/ext/libxml/libxml.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/libxml/libxml.c')
-rw-r--r--ext/libxml/libxml.c152
1 files changed, 64 insertions, 88 deletions
diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c
index e21d6fdbbe..fab8c3cf07 100644
--- a/ext/libxml/libxml.c
+++ b/ext/libxml/libxml.c
@@ -1,7 +1,5 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
@@ -29,7 +27,7 @@
#include "ext/standard/info.h"
#include "ext/standard/file.h"
-#if HAVE_LIBXML
+#ifdef HAVE_LIBXML
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
@@ -43,6 +41,7 @@
#endif
#include "php_libxml.h"
+#include "libxml_arginfo.h"
#define PHP_LIBXML_ERROR 0
#define PHP_LIBXML_CTX_ERROR 1
@@ -62,14 +61,6 @@ static HashTable php_libxml_exports;
static ZEND_DECLARE_MODULE_GLOBALS(libxml)
static PHP_GINIT_FUNCTION(libxml);
-static PHP_FUNCTION(libxml_set_streams_context);
-static PHP_FUNCTION(libxml_use_internal_errors);
-static PHP_FUNCTION(libxml_get_last_error);
-static PHP_FUNCTION(libxml_clear_errors);
-static PHP_FUNCTION(libxml_get_errors);
-static PHP_FUNCTION(libxml_set_external_entity_loader);
-static PHP_FUNCTION(libxml_disable_entity_loader);
-
static zend_class_entry *libxmlerror_class_entry;
/* {{{ dynamically loadable module stuff */
@@ -87,53 +78,14 @@ static PHP_RINIT_FUNCTION(libxml);
static PHP_RSHUTDOWN_FUNCTION(libxml);
static PHP_MSHUTDOWN_FUNCTION(libxml);
static PHP_MINFO_FUNCTION(libxml);
-static int php_libxml_post_deactivate(void);
+static zend_result php_libxml_post_deactivate(void);
/* }}} */
-/* {{{ arginfo */
-ZEND_BEGIN_ARG_INFO(arginfo_libxml_set_streams_context, 0)
- ZEND_ARG_INFO(0, context)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_libxml_use_internal_errors, 0, 0, 0)
- ZEND_ARG_INFO(0, use_errors)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO(arginfo_libxml_get_last_error, 0)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO(arginfo_libxml_get_errors, 0)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO(arginfo_libxml_clear_errors, 0)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_libxml_disable_entity_loader, 0, 0, 0)
- ZEND_ARG_INFO(0, disable)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_libxml_set_external_entity_loader, 0, 0, 1)
- ZEND_ARG_INFO(0, resolver_function)
-ZEND_END_ARG_INFO()
-/* }}} */
-
-/* {{{ extension definition structures */
-static const zend_function_entry libxml_functions[] = {
- PHP_FE(libxml_set_streams_context, arginfo_libxml_set_streams_context)
- PHP_FE(libxml_use_internal_errors, arginfo_libxml_use_internal_errors)
- PHP_FE(libxml_get_last_error, arginfo_libxml_get_last_error)
- PHP_FE(libxml_clear_errors, arginfo_libxml_clear_errors)
- PHP_FE(libxml_get_errors, arginfo_libxml_get_errors)
- PHP_FE(libxml_disable_entity_loader, arginfo_libxml_disable_entity_loader)
- PHP_FE(libxml_set_external_entity_loader, arginfo_libxml_set_external_entity_loader)
- PHP_FE_END
-};
-
zend_module_entry libxml_module_entry = {
STANDARD_MODULE_HEADER,
"libxml", /* extension name */
- libxml_functions, /* extension function list */
+ ext_functions, /* extension function list */
PHP_MINIT(libxml), /* extension-wide startup function */
PHP_MSHUTDOWN(libxml), /* extension-wide shutdown function */
PHP_RINIT(libxml), /* per-request startup function */
@@ -514,11 +466,10 @@ php_libxml_output_buffer_create_filename(const char *URI,
return(ret);
}
-static int _php_libxml_free_error(xmlErrorPtr error)
+static void _php_libxml_free_error(void *ptr)
{
/* This will free the libxml alloc'd memory */
- xmlResetError(error);
- return 1;
+ xmlResetError((xmlErrorPtr) ptr);
}
static void _php_list_set_error_structure(xmlErrorPtr error, const char *msg)
@@ -582,7 +533,6 @@ static void php_libxml_internal_error_handler(int error_type, void *ctx, const c
char *buf;
int len, len_iter, output = 0;
-
len = vspprintf(&buf, 0, *msg, ap);
len_iter = len;
@@ -599,7 +549,8 @@ static void php_libxml_internal_error_handler(int error_type, void *ctx, const c
if (output == 1) {
if (LIBXML(error_list)) {
_php_list_set_error_structure(NULL, ZSTR_VAL(LIBXML(error_buffer).s));
- } else {
+ } else if (!EG(exception)) {
+ /* Don't throw additional notices/warnings if an exception has already been thrown. */
switch (error_type) {
case PHP_LIBXML_CTX_ERROR:
php_libxml_ctx_error_level(E_WARNING, ctx, ZSTR_VAL(LIBXML(error_buffer).s));
@@ -663,7 +614,6 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
fci->retval = &retval;
fci->params = params;
fci->param_count = sizeof(params)/sizeof(*params);
- fci->no_separation = 1;
status = zend_call_function(fci, &LIBXML(entity_loader).fcc);
if (status != SUCCESS || Z_ISUNDEF(retval)) {
@@ -813,7 +763,7 @@ PHP_LIBXML_API void php_libxml_initialize(void)
PHP_LIBXML_API void php_libxml_shutdown(void)
{
if (_php_libxml_initialized) {
-#if defined(LIBXML_SCHEMAS_ENABLED)
+#ifdef LIBXML_SCHEMAS_ENABLED
xmlRelaxNGCleanupTypes();
#endif
/* xmlCleanupParser(); */
@@ -866,7 +816,7 @@ static PHP_MINIT_FUNCTION(libxml)
REGISTER_LONG_CONSTANT("LIBXML_NOEMPTYTAG", LIBXML_SAVE_NOEMPTYTAG, CONST_CS | CONST_PERSISTENT);
/* Schema validation options */
-#if defined(LIBXML_SCHEMAS_ENABLED)
+#ifdef LIBXML_SCHEMAS_ENABLED
REGISTER_LONG_CONSTANT("LIBXML_SCHEMA_CREATE", XML_SCHEMA_VAL_VC_I_CREATE, CONST_CS | CONST_PERSISTENT);
#endif
@@ -888,6 +838,33 @@ static PHP_MINIT_FUNCTION(libxml)
INIT_CLASS_ENTRY(ce, "LibXMLError", NULL);
libxmlerror_class_entry = zend_register_internal_class(&ce);
+ zval default_val;
+ zend_string *name;
+ ZVAL_UNDEF(&default_val);
+
+ name = zend_string_init("level", sizeof("level")-1, 1);
+ zend_declare_typed_property(
+ libxmlerror_class_entry, name, &default_val, ZEND_ACC_PUBLIC, NULL,
+ (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
+ zend_string_release(name);
+ zend_declare_typed_property(
+ libxmlerror_class_entry, ZSTR_KNOWN(ZEND_STR_CODE), &default_val, ZEND_ACC_PUBLIC, NULL,
+ (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
+ name = zend_string_init("column", sizeof("column")-1, 1);
+ zend_declare_typed_property(
+ libxmlerror_class_entry, name, &default_val, ZEND_ACC_PUBLIC, NULL,
+ (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
+ zend_string_release(name);
+ zend_declare_typed_property(
+ libxmlerror_class_entry, ZSTR_KNOWN(ZEND_STR_MESSAGE), &default_val, ZEND_ACC_PUBLIC, NULL,
+ (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
+ zend_declare_typed_property(
+ libxmlerror_class_entry, ZSTR_KNOWN(ZEND_STR_FILE), &default_val, ZEND_ACC_PUBLIC, NULL,
+ (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
+ zend_declare_typed_property(
+ libxmlerror_class_entry, ZSTR_KNOWN(ZEND_STR_LINE), &default_val, ZEND_ACC_PUBLIC, NULL,
+ (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
+
if (sapi_module.name) {
static const char * const supported_sapis[] = {
"cgi-fcgi",
@@ -953,7 +930,7 @@ static PHP_MSHUTDOWN_FUNCTION(libxml)
return SUCCESS;
}
-static int php_libxml_post_deactivate(void)
+static zend_result php_libxml_post_deactivate(void)
{
/* reset libxml generic error handling */
if (_php_libxml_per_request_initialization) {
@@ -989,9 +966,8 @@ static PHP_MINFO_FUNCTION(libxml)
}
/* }}} */
-/* {{{ proto void libxml_set_streams_context(resource streams_context)
- Set the streams context for the next libxml document load or write */
-static PHP_FUNCTION(libxml_set_streams_context)
+/* {{{ Set the streams context for the next libxml document load or write */
+PHP_FUNCTION(libxml_set_streams_context)
{
zval *arg;
@@ -1007,16 +983,15 @@ static PHP_FUNCTION(libxml_set_streams_context)
}
/* }}} */
-/* {{{ proto bool libxml_use_internal_errors([boolean use_errors])
- Disable libxml errors and allow user to fetch error information as needed */
-static PHP_FUNCTION(libxml_use_internal_errors)
+/* {{{ Disable libxml errors and allow user to fetch error information as needed */
+PHP_FUNCTION(libxml_use_internal_errors)
{
xmlStructuredErrorFunc current_handler;
- zend_bool use_errors=0, retval;
+ zend_bool use_errors, use_errors_is_null = 1, retval;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
- Z_PARAM_BOOL(use_errors)
+ Z_PARAM_BOOL_OR_NULL(use_errors, use_errors_is_null)
ZEND_PARSE_PARAMETERS_END();
current_handler = xmlStructuredError;
@@ -1026,7 +1001,7 @@ static PHP_FUNCTION(libxml_use_internal_errors)
retval = 0;
}
- if (ZEND_NUM_ARGS() == 0) {
+ if (use_errors_is_null) {
RETURN_BOOL(retval);
}
@@ -1041,19 +1016,20 @@ static PHP_FUNCTION(libxml_use_internal_errors)
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);
+ zend_llist_init(LIBXML(error_list), sizeof(xmlError), _php_libxml_free_error, 0);
}
}
RETURN_BOOL(retval);
}
/* }}} */
-/* {{{ proto object libxml_get_last_error()
- Retrieve last error from libxml */
-static PHP_FUNCTION(libxml_get_last_error)
+/* {{{ Retrieve last error from libxml */
+PHP_FUNCTION(libxml_get_last_error)
{
xmlErrorPtr error;
+ ZEND_PARSE_PARAMETERS_NONE();
+
error = xmlGetLastError();
if (error) {
@@ -1078,13 +1054,14 @@ static PHP_FUNCTION(libxml_get_last_error)
}
/* }}} */
-/* {{{ proto object libxml_get_errors()
- Retrieve array of errors */
-static PHP_FUNCTION(libxml_get_errors)
+/* {{{ Retrieve array of errors */
+PHP_FUNCTION(libxml_get_errors)
{
xmlErrorPtr error;
+ ZEND_PARSE_PARAMETERS_NONE();
+
if (LIBXML(error_list)) {
array_init(return_value);
@@ -1118,10 +1095,11 @@ static PHP_FUNCTION(libxml_get_errors)
}
/* }}} */
-/* {{{ proto void libxml_clear_errors()
- Clear last error from libxml */
-static PHP_FUNCTION(libxml_clear_errors)
+/* {{{ Clear last error from libxml */
+PHP_FUNCTION(libxml_clear_errors)
{
+ ZEND_PARSE_PARAMETERS_NONE();
+
xmlResetLastError();
if (LIBXML(error_list)) {
zend_llist_clean(LIBXML(error_list));
@@ -1137,9 +1115,8 @@ PHP_LIBXML_API zend_bool php_libxml_disable_entity_loader(zend_bool disable) /*
return old;
} /* }}} */
-/* {{{ proto bool libxml_disable_entity_loader([boolean disable])
- Disable/Enable ability to load external entities */
-static PHP_FUNCTION(libxml_disable_entity_loader)
+/* {{{ Disable/Enable ability to load external entities */
+PHP_FUNCTION(libxml_disable_entity_loader)
{
zend_bool disable = 1;
@@ -1152,20 +1129,19 @@ static PHP_FUNCTION(libxml_disable_entity_loader)
}
/* }}} */
-/* {{{ proto void libxml_set_external_entity_loader(callback resolver_function)
- Changes the default external entity loader */
-static PHP_FUNCTION(libxml_set_external_entity_loader)
+/* {{{ Changes the default external entity loader */
+PHP_FUNCTION(libxml_set_external_entity_loader)
{
zend_fcall_info fci;
zend_fcall_info_cache fcc;
ZEND_PARSE_PARAMETERS_START(1, 1)
- Z_PARAM_FUNC_EX(fci, fcc, 1, 0)
+ Z_PARAM_FUNC_OR_NULL(fci, fcc)
ZEND_PARSE_PARAMETERS_END();
_php_libxml_destroy_fci(&LIBXML(entity_loader).fci, &LIBXML(entity_loader).object);
- if (fci.size > 0) { /* argument not null */
+ if (ZEND_FCI_INITIALIZED(fci)) { /* argument not null */
LIBXML(entity_loader).fci = fci;
Z_ADDREF(fci.function_name);
if (fci.object != NULL) {