filter tests & fixes
authorMichael Wallner <mike@php.net>
Mon, 23 Jan 2012 09:05:46 +0000 (09:05 +0000)
committerMichael Wallner <mike@php.net>
Mon, 23 Jan 2012 09:05:46 +0000 (09:05 +0000)
php_http_filter.c
tests/filterchunked.phpt [new file with mode: 0644]
tests/filterzlib.phpt [new file with mode: 0644]

index 121966b86a6f7292a912d0fc77dc4822595cce59..2c5335848910682695489a3a8576d52e3dad9016 100644 (file)
@@ -363,7 +363,28 @@ static php_stream_filter *http_filter_create(const char *name, zval *params, int
 {
        zval **tmp = &params;
        php_stream_filter *f = NULL;
+       int flags = p ? PHP_HTTP_ENCODING_STREAM_PERSISTENT : 0;
        
+       if (params) {
+               switch (Z_TYPE_P(params)) {
+                       case IS_ARRAY:
+                       case IS_OBJECT:
+                               if (SUCCESS != zend_hash_find(HASH_OF(params), "flags", sizeof("flags"), (void *) &tmp)) {
+                                       break;
+                               }
+                               /* no break */
+                       default:
+                       {
+                               zval *num = php_http_ztyp(IS_LONG, *tmp);
+                               
+                               flags |= (Z_LVAL_P(num) & 0x0fffffff);
+                               zval_ptr_dtor(&num);
+
+                       }
+                       break;
+               }
+       }
+
        if (!strcasecmp(name, "http.chunked_decode")) {
                PHP_HTTP_FILTER_BUFFER(chunked_decode) *b = NULL;
                
@@ -380,7 +401,6 @@ static php_stream_filter *http_filter_create(const char *name, zval *params, int
        } else
        
        if (!strcasecmp(name, "http.inflate")) {
-               int flags = p ? PHP_HTTP_ENCODING_STREAM_PERSISTENT : 0;
                PHP_HTTP_FILTER_BUFFER(zlib) *b = NULL;
                
                if ((b = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_inflate_ops(), flags TSRMLS_CC))) {
@@ -391,28 +411,8 @@ static php_stream_filter *http_filter_create(const char *name, zval *params, int
        } else
        
        if (!strcasecmp(name, "http.deflate")) {
-               int flags = p ? PHP_HTTP_ENCODING_STREAM_PERSISTENT : 0;
                PHP_HTTP_FILTER_BUFFER(zlib) *b = NULL;
                
-               if (params) {
-                       switch (Z_TYPE_P(params)) {
-                               case IS_ARRAY:
-                               case IS_OBJECT:
-                                       if (SUCCESS != zend_hash_find(HASH_OF(params), "flags", sizeof("flags"), (void *) &tmp)) {
-                                               break;
-                                       }
-                                       /* no break */
-                               default:
-                               {
-                                       zval *num = php_http_ztyp(IS_LONG, *tmp);
-                                       
-                                       flags |= (Z_LVAL_P(num) & 0x0fffffff);
-                                       zval_ptr_dtor(&num);
-
-                               }
-                               break;
-                       }
-               }
                if ((b = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), flags TSRMLS_CC))) {
                        if (!(f = php_stream_filter_alloc(&PHP_HTTP_FILTER_OP(deflate), b, p))) {
                                php_http_encoding_stream_free(&b);
diff --git a/tests/filterchunked.phpt b/tests/filterchunked.phpt
new file mode 100644 (file)
index 0000000..f2d2850
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+chunked filter
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--FILE--
+<?php
+list($in, $out) = stream_socket_pair(
+    STREAM_PF_UNIX,
+    STREAM_SOCK_STREAM,
+    STREAM_IPPROTO_IP
+);
+stream_filter_append($in, "http.chunked_decode", STREAM_FILTER_READ);
+stream_filter_append($out, "http.chunked_encode", STREAM_FILTER_WRITE,
+    array());
+
+$file = file(__FILE__);
+foreach($file as $line) {
+    fwrite($out, $line);
+    fflush($out);
+}
+fclose($out);
+if (implode("",$file) !== ($read = fread($in, filesize(__FILE__)))) {
+    echo "got: $read\n";
+}
+fclose($in);
+?>
+DONE
+--EXPECT--
+DONE
diff --git a/tests/filterzlib.phpt b/tests/filterzlib.phpt
new file mode 100644 (file)
index 0000000..bbfac86
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+zlib filter
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--FILE--
+<?php
+list($in, $out) = stream_socket_pair(
+    STREAM_PF_UNIX,
+    STREAM_SOCK_STREAM,
+    STREAM_IPPROTO_IP
+);
+stream_filter_append($in, "http.inflate", STREAM_FILTER_READ);
+stream_filter_append($out, "http.deflate", STREAM_FILTER_WRITE,
+    http\Encoding\Stream\Deflate::LEVEL_MAX);
+
+$file = file(__FILE__);
+foreach ($file as $line) {
+    fwrite($out, $line);
+    fflush($out);
+}
+fclose($out);
+if (implode("",$file) !== ($read = fread($in, filesize(__FILE__)))) {
+    echo "got: $read\n";
+}
+fclose($in);
+?>
+DONE
+--EXPECT--
+DONE