summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorRob Richards <rrichards@php.net>2005-03-04 15:41:33 (GMT)
committerRob Richards <rrichards@php.net>2005-03-04 15:41:33 (GMT)
commitd42656b0336025b491f5bb33a8661db558c78180 (patch)
tree7fb696daa23a4a907cc744a9f954e9a62514366a /ext
parenta942bcd669c0e07e549165d7c39abbba127e28bd (diff)
downloadphp-d42656b0336025b491f5bb33a8661db558c78180.tar.gz
use php streams for uri I/O under PHP 4
Diffstat (limited to 'ext')
-rw-r--r--ext/xmlwriter/php_xmlwriter.c54
-rw-r--r--ext/xmlwriter/php_xmlwriter.h3
2 files changed, 56 insertions, 1 deletions
diff --git a/ext/xmlwriter/php_xmlwriter.c b/ext/xmlwriter/php_xmlwriter.c
index aa0533e..cb45373 100644
--- a/ext/xmlwriter/php_xmlwriter.c
+++ b/ext/xmlwriter/php_xmlwriter.c
@@ -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);
diff --git a/ext/xmlwriter/php_xmlwriter.h b/ext/xmlwriter/php_xmlwriter.h
index ca55142..d4f0e33 100644
--- a/ext/xmlwriter/php_xmlwriter.h
+++ b/ext/xmlwriter/php_xmlwriter.h
@@ -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