summaryrefslogtreecommitdiff
path: root/ext/standard/php_fopen_wrapper.c
diff options
context:
space:
mode:
authorSara Golemon <pollita@php.net>2003-02-18 06:10:14 +0000
committerSara Golemon <pollita@php.net>2003-02-18 06:10:14 +0000
commit73c78270b61884788cdd6df87e938c9f9865ddf6 (patch)
treea662bd1961be4acff5a363afa8ab1f6108241a9a /ext/standard/php_fopen_wrapper.c
parentffe0f52be6855c3c059ae2bc02948adbb0ffc059 (diff)
downloadphp-git-73c78270b61884788cdd6df87e938c9f9865ddf6.tar.gz
Introduce //filter target to php: wrapper to allow inline application of filters during fopen() style opperations
Diffstat (limited to 'ext/standard/php_fopen_wrapper.c')
-rw-r--r--ext/standard/php_fopen_wrapper.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c
index bf163cc783..3df43f029c 100644
--- a/ext/standard/php_fopen_wrapper.c
+++ b/ext/standard/php_fopen_wrapper.c
@@ -122,10 +122,36 @@ php_stream_ops php_stream_input_ops = {
NULL /* set_option */
};
+static void php_stream_apply_filter_list(php_stream *stream, char *filterlist, int read_chain, int write_chain TSRMLS_DC) {
+ char *p, *token;
+ php_stream_filter *temp_filter;
+
+ p = php_strtok_r(filterlist, "|", &token);
+ while (p) {
+ if (read_chain) {
+ if (temp_filter = php_stream_filter_create(p, "", 0, php_stream_is_persistent(stream) TSRMLS_CC)) {
+ php_stream_filter_append(&stream->readfilters, temp_filter);
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create filter (%s)\n", p);
+ }
+ }
+ if (write_chain) {
+ if (temp_filter = php_stream_filter_create(p, "", 0, php_stream_is_persistent(stream) TSRMLS_CC)) {
+ php_stream_filter_append(&stream->writefilters, temp_filter);
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create filter (%s)\n", p);
+ }
+ }
+ p = php_strtok_r(NULL, "|", &token);
+ }
+}
+
+
php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
{
int fd = -1;
php_stream * stream = NULL;
+ char *p, *token, *pathdup;
if (!strncasecmp(path, "php://", 6))
path += 6;
@@ -151,6 +177,36 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch
if (stream == NULL)
close(fd);
}
+
+ if (!strncasecmp(path, "filter/", 7)) {
+ pathdup = estrndup(path + 6, strlen(path + 6));
+ p = strstr(pathdup, "/resource=");
+ if (!p) {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "No URL resource specified.");
+ efree(pathdup);
+ return NULL;
+ }
+ if (!(stream = php_stream_open_wrapper(p + 10, mode, options, opened_path))) {
+ efree(pathdup);
+ return NULL;
+ }
+
+ *p = '\0';
+
+ p = php_strtok_r(pathdup + 1, "/", &token);
+ while (p) {
+ if (!strncasecmp(p, "read=", 5)) {
+ php_stream_apply_filter_list(stream, p + 5, 1, 0 TSRMLS_CC);
+ } else if (!strncasecmp(p, "write=", 6)) {
+ php_stream_apply_filter_list(stream, p + 6, 0, 1 TSRMLS_CC);
+ } else {
+ php_stream_apply_filter_list(stream, p, 1, 1 TSRMLS_CC);
+ }
+ p = php_strtok_r(NULL, "/", &token);
+ }
+ efree(pathdup);
+ }
+
return stream;
}