]> granicus.if.org Git - php/commitdiff
use php streams for uri I/O under PHP 4
authorRob Richards <rrichards@php.net>
Fri, 4 Mar 2005 15:41:33 +0000 (15:41 +0000)
committerRob Richards <rrichards@php.net>
Fri, 4 Mar 2005 15:41:33 +0000 (15:41 +0000)
ext/xmlwriter/php_xmlwriter.c
ext/xmlwriter/php_xmlwriter.h

index aa0533e7c9c08b4d36a120afc5c414555dfbefa3..cb45373fedf91fd1ff2d986ad3afa293e81c986b 100644 (file)
@@ -126,6 +126,32 @@ char *_xmlwriter_get_valid_file_path(char *source, char *resolved_path, int reso
        return file_dest;
 }
 
+#ifndef ZEND_ENGINE_2
+/* Channel libxml file io layer through the PHP streams subsystem.
+ * This allows use of ftps:// and https:// urls */
+
+static void *php_xmlwriter_streams_IO_open_write_wrapper(const char *filename TSRMLS_DC)
+{
+       php_stream_wrapper *wrapper = NULL;
+       void *ret_val = NULL;
+
+       ret_val = php_stream_open_wrapper_ex((char *)filename, "wb", ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL, NULL);
+       return ret_val;
+}
+
+int php_xmlwriter_streams_IO_write(void *context, const char *buffer, int len)
+{
+       TSRMLS_FETCH();
+       return php_stream_write((php_stream*)context, buffer, len);
+}
+
+int php_xmlwriter_streams_IO_close(void *context)
+{
+       TSRMLS_FETCH();
+       return php_stream_close((php_stream*)context);
+}
+#endif
+
 /* {{{ xmlwriter_module_entry
  */
 zend_module_entry xmlwriter_module_entry = {
@@ -1294,18 +1320,38 @@ PHP_FUNCTION(xmlwriter_open_uri)
        char *source;
        char resolved_path[MAXPATHLEN + 1];
        int source_len;
+#ifndef ZEND_ENGINE_2
+       xmlOutputBufferPtr out_buffer;
+       void *ioctx;
+#endif
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
                WRONG_PARAM_COUNT;
                return;
        }
 
-       valid_file = _xmlwriter_get_valid_file_path(source, resolved_path, MAXPATHLEN  TSRMLS_CC);
+       valid_file = _xmlwriter_get_valid_file_path(source, resolved_path, MAXPATHLEN TSRMLS_CC);
        if (!valid_file) {
                RETURN_FALSE;
        }
 
+#ifndef ZEND_ENGINE_2
+       ioctx = php_xmlwriter_streams_IO_open_write_wrapper(valid_file TSRMLS_CC);
+       if (ioctx == NULL) {
+               RETURN_FALSE;
+       }
+
+       out_buffer = xmlOutputBufferCreateIO(php_xmlwriter_streams_IO_write, 
+               php_xmlwriter_streams_IO_close, ioctx, NULL);
+
+       if (out_buffer == NULL) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create output buffer");
+               RETURN_FALSE;
+       }
+       ptr = xmlNewTextWriter(out_buffer);
+#else
        ptr = xmlNewTextWriterFilename(valid_file, 0);
+#endif
        if (! ptr) {
                RETURN_FALSE;
        }
@@ -1313,6 +1359,9 @@ PHP_FUNCTION(xmlwriter_open_uri)
        intern = emalloc(sizeof(xmlwriter_object));
        intern->ptr = ptr;
        intern->output = NULL;
+#ifndef ZEND_ENGINE_2
+       intern->uri_output = out_buffer;
+#endif
 
        ZEND_REGISTER_RESOURCE(return_value,intern,le_xmlwriter);
 
@@ -1343,6 +1392,9 @@ PHP_FUNCTION(xmlwriter_open_memory)
        intern = emalloc(sizeof(xmlwriter_object));
        intern->ptr = ptr;
        intern->output = buffer;
+#ifndef ZEND_ENGINE_2
+       intern->uri_output = NULL;
+#endif
 
        ZEND_REGISTER_RESOURCE(return_value,intern,le_xmlwriter);
 
index ca55142e0c6afe640c4cba3372d957c364e00297..d4f0e33aee6619afeb25d1a3d37ac24f72058fd8 100644 (file)
@@ -41,6 +41,9 @@ extern zend_module_entry xmlwriter_module_entry;
 typedef struct _xmlwriter_object {
        xmlTextWriterPtr ptr;
        xmlBufferPtr output;
+#ifndef ZEND_ENGINE_2
+       xmlOutputBufferPtr uri_output;
+#endif
 } xmlwriter_object;
 
 #if LIBXML_VERSION >= 20605