rrichards Thu Oct 13 16:34:37 2005 EDT
Modified files: (Branch: PHP_5_1)
/php-src/ext/libxml libxml.c
Log:
MFH: insure stream usage
http://cvs.php.net/diff.php/php-src/ext/libxml/libxml.c?r1=1.32.2.2&r2=1.32.2.3&ty=u
Index: php-src/ext/libxml/libxml.c
diff -u php-src/ext/libxml/libxml.c:1.32.2.2
php-src/ext/libxml/libxml.c:1.32.2.3
--- php-src/ext/libxml/libxml.c:1.32.2.2 Thu Sep 8 06:37:57 2005
+++ php-src/ext/libxml/libxml.c Thu Oct 13 16:34:37 2005
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: libxml.c,v 1.32.2.2 2005/09/08 10:37:57 rrichards Exp $ */
+/* $Id: libxml.c,v 1.32.2.3 2005/10/13 20:34:37 rrichards Exp $ */
#define IS_EXT_MODULE
@@ -249,36 +249,6 @@
/* Channel libxml file io layer through the PHP streams subsystem.
* This allows use of ftps:// and https:// urls */
-int php_libxml_streams_IO_match_wrapper(const char *filename)
-{
- char *resolved_path;
- int retval, isescaped=0;
- xmlURI *uri;
-
- TSRMLS_FETCH();
-
- if (zend_is_executing(TSRMLS_C)) {
- uri = xmlParseURI((xmlChar *)filename);
- if (uri && (uri->scheme == NULL || (xmlStrncmp(uri->scheme,
"file", 4) == 0))) {
- resolved_path = xmlURIUnescapeString(filename, 0, NULL);
- isescaped = 1;
- } else {
- resolved_path = (char *)filename;
- }
-
- if (uri) {
- xmlFreeURI(uri);
- }
-
- retval = php_stream_locate_url_wrapper(resolved_path, NULL, 0
TSRMLS_CC) ? 1 : 0;
- if (resolved_path && isescaped) {
- xmlFree(resolved_path);
- }
- return retval;
- }
- return 0;
-}
-
void *php_libxml_streams_IO_open_wrapper(const char *filename, const char
*mode, const int read_only)
{
php_stream_statbuf ssbuf;
@@ -362,6 +332,78 @@
return php_stream_close((php_stream*)context);
}
+xmlParserInputBufferPtr
+php_libxml_input_buffer_create_filename(const char *URI, xmlCharEncoding enc)
+{
+ xmlParserInputBufferPtr ret;
+ void *context = NULL;
+
+ if (URI == NULL)
+ return(NULL);
+
+ context = php_libxml_streams_IO_open_read_wrapper(URI);
+
+ if (context == NULL) {
+ return(NULL);
+ }
+
+ /* Allocate the Input buffer front-end. */
+ ret = xmlAllocParserInputBuffer(enc);
+ if (ret != NULL) {
+ ret->context = context;
+ ret->readcallback = php_libxml_streams_IO_read;
+ ret->closecallback = php_libxml_streams_IO_close;
+ } else
+ php_libxml_streams_IO_close(context);
+
+ return(ret);
+}
+
+xmlOutputBufferPtr
+php_libxml_output_buffer_create_filename(const char *URI,
+ xmlCharEncodingHandlerPtr encoder,
+ int compression ATTRIBUTE_UNUSED)
+{
+ xmlOutputBufferPtr ret;
+ xmlURIPtr puri;
+ void *context = NULL;
+ char *unescaped = NULL;
+
+ if (URI == NULL)
+ return(NULL);
+
+ puri = xmlParseURI(URI);
+ if (puri != NULL) {
+ if (puri->scheme != NULL)
+ unescaped = xmlURIUnescapeString(URI, 0, NULL);
+ xmlFreeURI(puri);
+ }
+
+ if (unescaped != NULL) {
+ context = php_libxml_streams_IO_open_write_wrapper(unescaped);
+ xmlFree(unescaped);
+ }
+
+ /* try with a non-escaped URI this may be a strange filename */
+ if (context == NULL) {
+ context = context =
php_libxml_streams_IO_open_write_wrapper(URI);
+ }
+
+ if (context == NULL) {
+ return(NULL);
+ }
+
+ /* Allocate the Output buffer front-end. */
+ ret = xmlAllocOutputBuffer(encoder);
+ if (ret != NULL) {
+ ret->context = context;
+ ret->writecallback = php_libxml_streams_IO_write;
+ ret->closecallback = php_libxml_streams_IO_close;
+ }
+
+ return(ret);
+}
+
static int _php_libxml_free_error(xmlErrorPtr error) {
/* This will free the libxml alloc'd memory */
xmlResetError(error);
@@ -501,22 +543,6 @@
/* we should be the only one's to ever init!! */
xmlInitParser();
- /* Enable php stream/wrapper support for libxml
- we only use php streams, so we do not enable
- the default io handlers in libxml.
- */
- xmlRegisterInputCallbacks(
- php_libxml_streams_IO_match_wrapper,
- php_libxml_streams_IO_open_read_wrapper,
- php_libxml_streams_IO_read,
- php_libxml_streams_IO_close);
-
- xmlRegisterOutputCallbacks(
- php_libxml_streams_IO_match_wrapper,
- php_libxml_streams_IO_open_write_wrapper,
- php_libxml_streams_IO_write,
- php_libxml_streams_IO_close);
-
zend_hash_init(&php_libxml_exports, 0, NULL, NULL, 1);
_php_libxml_initialized = 1;
@@ -595,6 +621,8 @@
{
/* report errors via handler rather than stderr */
xmlSetGenericErrorFunc(NULL, php_libxml_error_handler);
+
xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_create_filename);
+
xmlOutputBufferCreateFilenameDefault(php_libxml_output_buffer_create_filename);
return SUCCESS;
}
@@ -613,6 +641,9 @@
xmlSetGenericErrorFunc(NULL, NULL);
xmlSetStructuredErrorFunc(NULL, NULL);
+ xmlParserInputBufferCreateFilenameDefault(NULL);
+ xmlOutputBufferCreateFilenameDefault(NULL);
+
smart_str_free(&LIBXML(error_buffer));
if (LIBXML(error_list)) {
zend_llist_destroy(LIBXML(error_list));
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php