From: Rob Richards Date: Fri, 26 Jun 2009 20:27:44 +0000 (+0000) Subject: MFH: add libxml_disable_entity_loader function X-Git-Tag: php-5.2.11RC1~231 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c4e0f38aa790d7990b48f0ee904294b1fda17f12;p=php MFH: add libxml_disable_entity_loader function --- diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index 25d5173c6f..930cf49307 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -68,6 +68,7 @@ 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_disable_entity_loader); static zend_class_entry *libxmlerror_class_entry; @@ -109,6 +110,11 @@ static ZEND_BEGIN_ARG_INFO(arginfo_libxml_clear_errors, 0) ZEND_END_ARG_INFO() +static +ZEND_BEGIN_ARG_INFO_EX(arginfo_libxml_disable_entity_loader, 0, 0, 0) + ZEND_ARG_INFO(0, disable) +ZEND_END_ARG_INFO() + /* }}} */ /* {{{ extension definition structures */ @@ -118,6 +124,7 @@ static zend_function_entry libxml_functions[] = { 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) {NULL, NULL, NULL} }; @@ -348,6 +355,12 @@ static int php_libxml_streams_IO_close(void *context) return php_stream_close((php_stream*)context); } +static xmlParserInputBufferPtr +php_libxml_input_buffer_noload(const char *URI, xmlCharEncoding enc) +{ + return NULL; +} + static xmlParserInputBufferPtr php_libxml_input_buffer_create_filename(const char *URI, xmlCharEncoding enc) { @@ -823,6 +836,31 @@ static PHP_FUNCTION(libxml_clear_errors) } /* }}} */ +/* {{{ proto bool libxml_disable_entity_loader([boolean disable]) + Disable/Enable ability to load external entities */ +static PHP_FUNCTION(libxml_disable_entity_loader) +{ + zend_bool disable = 1; + xmlParserInputBufferCreateFilenameFunc old; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &disable) == FAILURE) { + return; + } + + if (disable == 0) { + old = xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_create_filename); + } else { + old = xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_noload); + } + + if (old == php_libxml_input_buffer_noload) { + RETURN_TRUE; + } + + RETURN_FALSE; +} +/* }}} */ + /* {{{ Common functions shared by extensions */ int php_libxml_xmlCheckUTF8(const unsigned char *s) {