diff options
Diffstat (limited to 'ext/zlib')
35 files changed, 965 insertions, 971 deletions
diff --git a/ext/zlib/CREDITS b/ext/zlib/CREDITS index c0a47dd293..a1773c463d 100644 --- a/ext/zlib/CREDITS +++ b/ext/zlib/CREDITS @@ -1,2 +1,2 @@ Zlib -Rasmus Lerdorf, Stefan Roehrich, Zeev Suraski, Jade Nicoletti +Rasmus Lerdorf, Stefan Roehrich, Zeev Suraski, Jade Nicoletti, Michael Wallner diff --git a/ext/zlib/config0.m4 b/ext/zlib/config0.m4 index 62e05fbd02..25c7f4f420 100644 --- a/ext/zlib/config0.m4 +++ b/ext/zlib/config0.m4 @@ -41,10 +41,17 @@ if test "$PHP_ZLIB" != "no" || test "$PHP_ZLIB_DIR" != "no"; then *) ac_extra=-L$ZLIB_DIR/$PHP_LIBDIR ;; esac + AC_MSG_CHECKING([for zlib version >= 1.2.0.4]) + ZLIB_VERSION=`$EGREP "define ZLIB_VERSION" $ZLIB_DIR/include/zlib.h | $SED -e 's/[[^0-9\.]]//g'` + AC_MSG_RESULT([$ZLIB_VERSION]) + if test `echo $ZLIB_VERSION | $SED -e 's/[[^0-9]]/ /g' | $AWK '{print $1*1000000 + $2*10000 + $3*100 + $4}'` -lt 1020004; then + AC_MSG_ERROR([libz version greater or equal to 1.2.0.4 required]) + fi + PHP_CHECK_LIBRARY(z, gzgets, [ AC_DEFINE(HAVE_ZLIB,1,[ ]) ],[ - AC_MSG_ERROR(ZLIB extension requires zlib >= 1.0.9) + AC_MSG_ERROR(ZLIB extension requires gzgets in zlib) ],[ $ac_extra ]) diff --git a/ext/zlib/php_zlib.h b/ext/zlib/php_zlib.h index 790c695977..564c9e14f1 100644 --- a/ext/zlib/php_zlib.h +++ b/ext/zlib/php_zlib.h @@ -14,6 +14,7 @@ +----------------------------------------------------------------------+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | | Stefan Röhrich <sr@linux.de> | + | Michael Wallner <mike@php.net> | +----------------------------------------------------------------------+ */ @@ -24,39 +25,50 @@ #include <zlib.h> +#define PHP_ZLIB_ENCODING_RAW -0xf +#define PHP_ZLIB_ENCODING_GZIP 0x1f +#define PHP_ZLIB_ENCODING_DEFLATE 0x0f + +#define PHP_ZLIB_ENCODING_ANY 0x2f + +#define PHP_ZLIB_OUTPUT_HANDLER_NAME "zlib output compression" +#define PHP_ZLIB_BUFFER_SIZE_GUESS(in_len) (((size_t) ((double) in_len * (double) 1.015)) + 10 + 8 + 4 + 1) + ZEND_BEGIN_MODULE_GLOBALS(zlib) /* variables for transparent gzip encoding */ int compression_coding; - z_stream stream; - uLong crc; - int ob_gzhandler_status; long output_compression; long output_compression_level; char *output_handler; -ZEND_END_MODULE_GLOBALS(zlib) - -PHPAPI ZEND_EXTERN_MODULE_GLOBALS(zlib) +ZEND_END_MODULE_GLOBALS(zlib); -extern php_stream_filter_factory php_zlib_filter_factory; -extern zend_module_entry php_zlib_module_entry; -#define zlib_module_ptr &php_zlib_module_entry +typedef struct _php_zlib_buffer { + char *data; + char *aptr; + size_t used; + size_t free; + size_t size; +} php_zlib_buffer; -int php_ob_gzhandler_check(TSRMLS_D); +typedef struct _php_zlib_context { + z_stream Z; + php_zlib_buffer buffer; +} php_zlib_context; php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); +extern php_stream_ops php_stream_gzio_ops; extern php_stream_wrapper php_stream_gzip_wrapper; +extern php_stream_filter_factory php_zlib_filter_factory; +extern zend_module_entry php_zlib_module_entry; +#define zlib_module_ptr &php_zlib_module_entry +#define phpext_zlib_ptr zlib_module_ptr #ifdef ZTS -#define ZLIBG(v) TSRMG(zlib_globals_id, zend_zlib_globals *, v) +# define ZLIBG(v) TSRMG(zlib_globals_id, zend_zlib_globals *, v) #else -#define ZLIBG(v) (zlib_globals.v) +# define ZLIBG(v) (zlib_globals.v) #endif -#define phpext_zlib_ptr zlib_module_ptr - -#define CODING_GZIP 1 -#define CODING_DEFLATE 2 - #endif /* PHP_ZLIB_H */ /* diff --git a/ext/zlib/tests/006.phpt b/ext/zlib/tests/006.phpt index 6a4e0f4e67..8c03ea068d 100644 --- a/ext/zlib/tests/006.phpt +++ b/ext/zlib/tests/006.phpt @@ -48,6 +48,8 @@ string(%d) "%a" Warning: gzinflate() expects at least 1 parameter, 0 given in %s on line %d NULL + +Warning: gzinflate(): data error in %s on line %d bool(false) Warning: gzinflate(): data error in %s on line %d diff --git a/ext/zlib/tests/007.phpt b/ext/zlib/tests/007.phpt index ec37b99de6..09207a583e 100644 --- a/ext/zlib/tests/007.phpt +++ b/ext/zlib/tests/007.phpt @@ -11,8 +11,8 @@ var_dump(gzencode("", -10)); var_dump(gzencode("", 100)); var_dump(gzencode("", 1, 100)); -var_dump(gzencode("", -1, 1)); -var_dump(gzencode("", 9, 2)); +var_dump(gzencode("", -1, ZLIB_ENCODING_GZIP)); +var_dump(gzencode("", 9, ZLIB_ENCODING_DEFLATE)); $string = "Light of my sun Light in this temple @@ -21,8 +21,8 @@ Lies in the darkness"; var_dump(gzencode($string, 9, 3)); -var_dump(gzencode($string, -1, 1)); -var_dump(gzencode($string, 9, 2)); +var_dump(gzencode($string, -1, ZLIB_ENCODING_GZIP)); +var_dump(gzencode($string, 9, ZLIB_ENCODING_DEFLATE)); echo "Done\n"; ?> @@ -33,18 +33,18 @@ NULL Warning: gzencode() expects at most 3 parameters, 4 given in %s on line %d NULL -Warning: gzencode(): compression level(-10) must be within -1..9 in %s on line %d +Warning: gzencode(): compression level (-10) must be within -1..9 in %s on line %d bool(false) -Warning: gzencode(): compression level(100) must be within -1..9 in %s on line %d +Warning: gzencode(): compression level (100) must be within -1..9 in %s on line %d bool(false) -Warning: gzencode(): encoding mode must be FORCE_GZIP or FORCE_DEFLATE in %s on line %d +Warning: gzencode(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d bool(false) string(%d) "%s" string(%d) "%s" -Warning: gzencode(): encoding mode must be FORCE_GZIP or FORCE_DEFLATE in %s on line %d +Warning: gzencode(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d bool(false) string(%d) "%s" string(%d) "%s" diff --git a/ext/zlib/tests/gzcompress_basic1.phpt b/ext/zlib/tests/gzcompress_basic1.phpt index dddeb1d55d..1506d0c1ee 100644 --- a/ext/zlib/tests/gzcompress_basic1.phpt +++ b/ext/zlib/tests/gzcompress_basic1.phpt @@ -8,7 +8,7 @@ if (!extension_loaded("zlib")) { ?> --FILE-- <?php -/* Prototype : string gzcompress(string data [, int level]) +/* Prototype : string gzcompress(string data [, int level, [int encoding]]) * Description: Gzip-compress a string * Source code: ext/zlib/zlib.c * Alias to functions: @@ -63,7 +63,7 @@ int(0) string(32) "c2e070f4320d1f674965eaab95b53d9c" int(0) -- Compression level 2 -- -string(32) "400a53d19ca337727f8cd362f5cd3ee0" +string(32) "36922f486410d08209d0d0d21b26030e" int(0) -- Compression level 3 -- string(32) "a441a2f5169bb303cd45b860a5a9dbf9" @@ -122,4 +122,4 @@ int(0) -- Testing with no specified compression level -- string(70) "789c735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee6020087a509cb" -===Done===
\ No newline at end of file +===Done=== diff --git a/ext/zlib/tests/gzcompress_error1.phpt b/ext/zlib/tests/gzcompress_error1.phpt index 7fa60b9003..9db0a56fa1 100644 --- a/ext/zlib/tests/gzcompress_error1.phpt +++ b/ext/zlib/tests/gzcompress_error1.phpt @@ -8,7 +8,7 @@ if (!extension_loaded("zlib")) { ?> --FILE-- <?php -/* Prototype : string gzcompress(string data [, int level]) +/* Prototype : string gzcompress(string data [, int level, [int encoding]]) * Description: Gzip-compress a string * Source code: ext/zlib/zlib.c * Alias to functions: @@ -28,26 +28,30 @@ var_dump( gzcompress() ); echo "\n-- Testing gzcompress() function with more than expected no. of arguments --\n"; $data = 'string_val'; $level = 2; +$encoding = ZLIB_ENCODING_RAW; $extra_arg = 10; -var_dump( gzcompress($data, $level, $extra_arg) ); +var_dump( gzcompress($data, $level, $encoding, $extra_arg) ); echo "\n-- Testing with incorrect compression level --\n"; $bad_level = 99; var_dump(gzcompress($data, $bad_level)); +echo "\n-- Testing with invalid encoding --\n"; +$data = 'string_val'; +$encoding = 99; +var_dump(gzcompress($data, $level, $encoding)); + +echo "\n-- Testing with incorrect parameters --\n"; + class Tester { function Hello() { echo "Hello\n"; } } -echo "\n-- Testing with incorrect parameters --\n"; $testclass = new Tester(); var_dump(gzcompress($testclass)); -var_dump(gzcompress($data, $testclass)); - - ?> ===Done=== --EXPECTF-- @@ -60,7 +64,7 @@ NULL -- Testing gzcompress() function with more than expected no. of arguments -- -Warning: gzcompress() expects at most 2 parameters, 3 given in %s on line %d +Warning: gzcompress() expects at most 3 parameters, 4 given in %s on line %d NULL -- Testing with incorrect compression level -- @@ -68,11 +72,13 @@ NULL Warning: gzcompress(): compression level (99) must be within -1..9 in %s on line %d bool(false) +-- Testing with invalid encoding -- + +Warning: gzcompress(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d +bool(false) + -- Testing with incorrect parameters -- Warning: gzcompress() expects parameter 1 to be string, object given in %s on line %d NULL - -Warning: gzcompress() expects parameter 2 to be long, object given in %s on line %d -NULL -===Done===
\ No newline at end of file +===Done=== diff --git a/ext/zlib/tests/gzcompress_variation1.phpt b/ext/zlib/tests/gzcompress_variation1.phpt index 04aac01085..7a8457c24f 100644 --- a/ext/zlib/tests/gzcompress_variation1.phpt +++ b/ext/zlib/tests/gzcompress_variation1.phpt @@ -8,7 +8,7 @@ if (!extension_loaded("zlib")) { ?> --FILE-- <?php -/* Prototype : string gzcompress(string data [, int level]) +/* Prototype : string gzcompress(string data [, int level, [int encoding]]) * Description: Gzip-compress a string * Source code: ext/zlib/zlib.c * Alias to functions: @@ -18,8 +18,6 @@ include(dirname(__FILE__) . '/data.inc'); echo "*** Testing gzcompress() : variation ***\n"; - - echo "\n-- Testing multiple compression --\n"; $output = gzcompress($data); var_dump( md5($output)); @@ -33,4 +31,4 @@ var_dump(md5(gzcompress($output))); -- Testing multiple compression -- string(32) "764809aef15bb34cb73ad49ecb600d99" string(32) "eba942bc2061f23ea8688cc5101872a4" -===Done===
\ No newline at end of file +===Done=== diff --git a/ext/zlib/tests/gzdeflate_basic1.phpt b/ext/zlib/tests/gzdeflate_basic1.phpt index 823f320352..a2ae0f01da 100644 --- a/ext/zlib/tests/gzdeflate_basic1.phpt +++ b/ext/zlib/tests/gzdeflate_basic1.phpt @@ -8,7 +8,7 @@ if (!extension_loaded("zlib")) { ?> --FILE-- <?php -/* Prototype : proto string gzdeflate(string data [, int level]) +/* Prototype : string gzdeflate(string data [, int level, [int encoding]]) * Description: Gzip-compress a string * Source code: ext/zlib/zlib.c * Alias to functions: diff --git a/ext/zlib/tests/gzdeflate_error1.phpt b/ext/zlib/tests/gzdeflate_error1.phpt index 78491af9f1..8abd5bec25 100644 --- a/ext/zlib/tests/gzdeflate_error1.phpt +++ b/ext/zlib/tests/gzdeflate_error1.phpt @@ -8,7 +8,7 @@ if (!extension_loaded("zlib")) { ?> --FILE-- <?php -/* Prototype : string gzdeflate(string data [, int level]) +/* Prototype : string gzdeflate(string data [, int level, [int encoding]]) * Description: Gzip-compress a string * Source code: ext/zlib/zlib.c * Alias to functions: @@ -28,13 +28,18 @@ var_dump( gzdeflate() ); echo "\n-- Testing gzdeflate() function with more than expected no. of arguments --\n"; $data = 'string_val'; $level = 2; +$encoding = ZLIB_ENCODING_RAW; $extra_arg = 10; -var_dump( gzdeflate($data, $level, $extra_arg) ); +var_dump( gzdeflate($data, $level, $encoding, $extra_arg) ); echo "\n-- Testing with incorrect compression level --\n"; $bad_level = 99; var_dump(gzdeflate($data, $bad_level)); +echo "\n-- Testing with incorrect encoding --\n"; +$bad_encoding = 99; +var_dump(gzdeflate($data, $level, $bad_encoding)); + class Tester { function Hello() { echo "Hello\n"; @@ -58,7 +63,7 @@ NULL -- Testing gzdeflate() function with more than expected no. of arguments -- -Warning: gzdeflate() expects at most 2 parameters, 3 given in %s on line %d +Warning: gzdeflate() expects at most 3 parameters, 4 given in %s on line %d NULL -- Testing with incorrect compression level -- @@ -66,6 +71,11 @@ NULL Warning: gzdeflate(): compression level (99) must be within -1..9 in %s on line %d bool(false) +-- Testing with incorrect encoding -- + +Warning: gzdeflate(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d +bool(false) + -- Testing with incorrect parameters -- Warning: gzdeflate() expects parameter 1 to be string, object given in %s on line %d @@ -73,4 +83,4 @@ NULL Warning: gzdeflate() expects parameter 2 to be long, object given in %s on line %d NULL -===Done===
\ No newline at end of file +===Done=== diff --git a/ext/zlib/tests/gzencode_basic1.phpt b/ext/zlib/tests/gzencode_basic1.phpt index 9b3dcc8a38..3c0ec559e9 100644 --- a/ext/zlib/tests/gzencode_basic1.phpt +++ b/ext/zlib/tests/gzencode_basic1.phpt @@ -51,6 +51,13 @@ for($i = -1; $i < 10; $i++) { var_dump(md5($output)); } +// Calling gzencode() with mandatory arguments +echo "\n-- Testing with no specified compression level --\n"; +var_dump(bin2hex(gzencode($smallstring))); + +echo "\n-- Testing gzencode with mode specified --\n"; +var_dump(bin2hex(gzencode($smallstring, -1, FORCE_GZIP))); + ?> ===Done=== --EXPECTF-- @@ -58,9 +65,9 @@ for($i = -1; $i < 10; $i++) { -- Compression level -1 -- string(32) "d9ede02415ce91d21e5a94274e2b9c42" -- Compression level 0 -- -string(32) "67aaf60426bb2cbd86d7fe530cb12306" +string(32) "bbf32d5508e5f1f4e6d42790489dae15" -- Compression level 1 -- -string(32) "bce9c439cf767c1988ff4881b287d1ce" +string(32) "0bfaaa7a5a57f8fb533074fca6c85eeb" -- Compression level 2 -- string(32) "7ddbfed63a76c42808722b66f1c133fc" -- Compression level 3 -- @@ -76,13 +83,13 @@ string(32) "d9ede02415ce91d21e5a94274e2b9c42" -- Compression level 8 -- string(32) "d9ede02415ce91d21e5a94274e2b9c42" -- Compression level 9 -- -string(32) "d9ede02415ce91d21e5a94274e2b9c42" +string(32) "0f220a09e9895bcb3a1308d2bc99cfdf" -- Compression level -1 -- string(32) "f77bd31e1e4dd11d12828fb661a08010" -- Compression level 0 -- -string(32) "36220d650930849b67e8e0622f9bf270" +string(32) "9c5005db88490d6fe102ea2c233b2872" -- Compression level 1 -- -string(32) "f77bd31e1e4dd11d12828fb661a08010" +string(32) "d24ff7c4c20cef69b9c3abd603368db9" -- Compression level 2 -- string(32) "f77bd31e1e4dd11d12828fb661a08010" -- Compression level 3 -- @@ -98,5 +105,11 @@ string(32) "f77bd31e1e4dd11d12828fb661a08010" -- Compression level 8 -- string(32) "f77bd31e1e4dd11d12828fb661a08010" -- Compression level 9 -- -string(32) "f77bd31e1e4dd11d12828fb661a08010" -===Done===
\ No newline at end of file +string(32) "8849e9a1543c04b3f882b5ce20839ed2" + +-- Testing with no specified compression level -- +string(94) "1f8b08000000000000%c%c735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200edc4e40b1b000000" + +-- Testing gzencode with mode specified -- +string(94) "1f8b08000000000000%c%c735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200edc4e40b1b000000" +===Done=== diff --git a/ext/zlib/tests/gzencode_error1.phpt b/ext/zlib/tests/gzencode_error1.phpt index ed8c977477..9ecf4b8f08 100644 --- a/ext/zlib/tests/gzencode_error1.phpt +++ b/ext/zlib/tests/gzencode_error1.phpt @@ -71,12 +71,12 @@ NULL -- Testing with incorrect compression level -- -Warning: gzencode(): compression level(99) must be within -1..9 in %s on line %d +Warning: gzencode(): compression level (99) must be within -1..9 in %s on line %d bool(false) -- Testing with incorrect encoding_mode -- -Warning: gzencode(): encoding mode must be FORCE_GZIP or FORCE_DEFLATE in %s on line %d +Warning: gzencode(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d bool(false) -- Testing with incorrect parameters -- @@ -87,7 +87,7 @@ NULL Warning: gzencode() expects parameter 2 to be long, object given in %s on line %d NULL -Warning: gzencode(): encoding mode must be FORCE_GZIP or FORCE_DEFLATE in %s on line %d +Warning: gzencode(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d bool(false) Warning: gzencode() expects parameter 3 to be long, object given in %s on line %d @@ -95,4 +95,4 @@ NULL Warning: gzencode() expects parameter 2 to be long, string given in %s on line %d NULL -===Done===
\ No newline at end of file +===Done=== diff --git a/ext/zlib/tests/gzencode_variation1.phpt b/ext/zlib/tests/gzencode_variation1.phpt index 47e2097f5f..ef1d3a77f7 100644 --- a/ext/zlib/tests/gzencode_variation1.phpt +++ b/ext/zlib/tests/gzencode_variation1.phpt @@ -3,6 +3,10 @@ Test gzencode() function : variation --SKIPIF-- <?php +if( substr(PHP_OS, 0, 3) == "WIN" ) { + die("skip.. Do not run on Windows"); +} + if (!extension_loaded("zlib")) { print "skip - ZLIB extension not loaded"; } @@ -30,4 +34,4 @@ var_dump(bin2hex(gzencode($output))); -- Testing multiple compression -- string(3658) "1f8b0800000000000003010e07f1f81f8b08000000000000036d574d6fe4c80dbdeb57d4ad2f3dfe01eb83e1ec22980e309b4562c067b64449159754dafab0b6e7d7e73d96da1e4c72184c4b2ab2c8f7c847fa25baabba98dc1a8b2b7c38bb324b713ee37f757f56cdc5c7f5b17b9d152f923b157c5ae335e0b75fedd0e2d781c6b98ea3a6ee05affe1dfc3a6527f8f09c52dcb38ba38bb5249934d6ecfe1e53a9ab76ff4c342cf2a64ed2028349fc9a8b139755685352acb82b9fbb67f8bade5cdcb698e1fcec94b7ceba3cb897e806cfc8114350dd1ebbdfa35b62d2478b0056d23ed809b9b95d696d91ce2aa97c911e3fa539c43f84c887554a4d125c9e63ff96711cc08c0866263cb37a0bbe2122ae8f6baecb2284abfb4ddf916db8354cddeef37c1afe5fa02fc7afb3db34f5b3acbdf2eb905490d8f38d7468d253a323d5ebb903760d7944d3b2024e834a99ddce77669bdd823cfbb8e899d4ad4c799677452e6029e80023a03b2374005590641f7d3877df2ad09f3c0e82a54d6a5644fd63049a37ed4bc362016fd9f51264f1e5c630727421ae930b7ed416e93e47b7c71a400390361ffbecb7561bb98f69b5da289e91becc27f08b3b724cb8704f9144d366431d0cb870c56b205deaa2e17636063761a911039fb7e4bf9f06c4f0aecd2ec80e8b41831ca7515e31286166458ea3ef71f2ce7cde2ae269c96d60525724a9c9170b713ed5750758f3cd2a361fc8b288fc92358ce884692e8ea0fe59bd969a0da2eed5831b715749eaae7178f3ebd30fb88c92105f367cce2c882955dc6bf8eca0d5d57540b3092894743ba0fd5b2dad021836191f1afc0bba14dde1642cb0b1aa6879c38907dcefa0720082b801bec61417469219175267dfa047df35b0bd1332001c28cdfafd3bcabe91e74368cdd8d8478e494c190e7ee90c67f2bde288e68ab6b15e883c995be4f8feb6c6dda4278e4f38578ddbdc7be36788daf0c3cb1d1819c73822f7000a0d1813fa94153b572315e51343b536bc64977dff163cebfd8418773261f524017e251fccc60ae29a5770ae097594d52e9c1229d87ce967a36401c46b69945afb249d101c9d420ffa9a123e232c20e76467d5d169202a2dd4c582949e013e745df7958d4b0cc4fd4377a737cd4feea7974070000f314d423e0634cb9a618fdf5dc64fd422181fd59c9230c9f6f9d18dc8fc23e9cccbc7188733b04aa57de83ebea0be3633cff5fa1ff83269be7f44f5a8d84550cc703255fd345dd402034d0b3e11a73ec6e3d4a77f4f685b614329f1b3132ae7af33d02e1e55e291fa6574b758d1f0200e7423dbc852211818043a7c9ce80aa9d59fce0401959f5ea2cf71fde90824f8c9192dbe9d329db143794675ddcf257dd7755273b67340414e3ccad12e3f661f8aad9cf9957dc1275d10a51d3934fa81e68dc6768fb8ee23e373936c8e13feab8b0f50d227f7af76f561fb0950f3d099bbc316c3892a42fb36806d8660e800fa4f43fd4b962d2097d71933a54b77ff948677848eb17bb3a88b621682cfb3bbb49cf42fed6b3944124ad8358ca688aa44dd5f2144c7c9ab16f25b9aca9654ef357ec9ad55c40d324d6cc3d9e3920b863c231d31a95d937fb5520f9c816c79b7dcecc593fb9593cc05a51ebb1eeddd5b49eb437769738d0f64adc579d372b8b7f7c0208487ee3915ebf5766e148ebd77cf4e01f3ec285047011e55838968b6494d517fe29224777b24dd3ddf933101695b102e87db805eef291b74dcfd91628fb2a53f93dbd2968ef2e598746c9204f89fba1f0246fc671610a0591806e46a1346f77c40d910a47c5e20ffb23f003c04b648327a4ed98032c1965bd35bb0044f5344248f56fdb99aa61d6451d68e33489a83bffbe6573541b2da5f64681ea12090f778b2075374778810f73965fa3626a9d41f4df2f83f7c34658cec921b5a9bde49dd5007ec882b02adc514f81aa85898b5cc98e1b137733c0a8789b7f5648d2d231b80bf74978f25d61ce08a8abd11801fd8f995e066676307192ff7641f1cc6e0dee68565b8b22ac3889cd067bf732754a6b270af1044c6a8776811a4f6d8bd0477a9f516064201b920b92d7cd4dc7eee13e6b3eb3528a82f9abb3f388ebe6a8f871393461b73816ec54c99d604174bc5a6801de13908f86aea6a7d0fea107d682bcf1ec348b83872e6b8a316ecd02eb8f8dc86a609bf59a2dd03f1dfa4079436d55e24617be1a2854d008b2b2b1705e2078a7f3946318df1c24f6bf70d4b456eca286ec2b585b28262cc048a098c3e2d5f325a92bb36f691afdc14c822da1b116c9c1c07bb362eb0a04b78834c812134230ebf2044ac2e3c0e3ad00f848dc5010f3bf917ec2fc700b7bf26dacea8440620e04f90f4d97d6dd77cfde8a05c7d3930f1e5811fb8ec5c70964dcc8187ec90e32fdd6b64eec7586413b7d55bed65c4cce39a9b6c15e70e9da94e53fc904e6286f01f5b5562c94211befbc23507e01b2a3865e2f45b5d7b591f290087a5605b82495b4e393f31aa5b37211ec40241a746d903c5eebf117a4d3ddb0d00007b64cbc70e070000" -===Done===
\ No newline at end of file +===Done=== diff --git a/ext/zlib/tests/gzencode_variation2-win32.phpt b/ext/zlib/tests/gzencode_variation2-win32.phpt new file mode 100644 index 0000000000..f664359e2a --- /dev/null +++ b/ext/zlib/tests/gzencode_variation2-win32.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test gzencode() function : variation - verify header contents with all encoding modes +--XFAIL-- +Test will fail until bug #47178 resolved; missing gzip headers whne FORCE_DEFLATE specified +--SKIPIF-- +<?php + +if( substr(PHP_OS, 0, 3) != "WIN" ) { + die("skip.. only for Windows"); +} + +if (!extension_loaded("zlib")) { + print "skip - ZLIB extension not loaded"; +} +?> +--FILE-- +<?php +/* Prototype : string gzencode ( string $data [, int $level [, int $encoding_mode ]] ) + * Description: Gzip-compress a string + * Source code: ext/zlib/zlib.c + * Alias to functions: + */ + +echo "*** Testing gzencode() : variation ***\n"; + +$data = "A small string to encode\n"; + +echo "\n-- Testing with each encoding_mode --\n"; +var_dump(bin2hex(gzencode($data, -1))); +var_dump(bin2hex(gzencode($data, -1, FORCE_GZIP))); +var_dump(bin2hex(gzencode($data, -1, FORCE_DEFLATE))); + +?> +===DONE=== +--EXPECTF-- +*** Testing gzencode() : variation *** + +-- Testing with each encoding_mode -- +string(90) "1f8b080000000000000b735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200d7739de519000000" +string(90) "1f8b080000000000000b735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200d7739de519000000" +string(86) "1f8b080000000000000b789c735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200735808cd" +===DONE=== diff --git a/ext/zlib/tests/gzencode_variation2.phpt b/ext/zlib/tests/gzencode_variation2.phpt index 901cd53c19..e6fe7dd65c 100644 --- a/ext/zlib/tests/gzencode_variation2.phpt +++ b/ext/zlib/tests/gzencode_variation2.phpt @@ -1,8 +1,14 @@ --TEST-- Test gzencode() function : variation - verify header contents with all encoding modes +--XFAIL-- +Test will fail until bug #47178 resolved; missing gzip headers whne FORCE_DEFLATE specified --SKIPIF-- <?php +if( substr(PHP_OS, 0, 3) == "WIN" ) { + die("skip.. Do not run on Windows"); +} + if (!extension_loaded("zlib")) { print "skip - ZLIB extension not loaded"; } @@ -33,4 +39,4 @@ var_dump(bin2hex(gzencode($data, -1, FORCE_DEFLATE))); string(90) "1f8b0800000000000003735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200d7739de519000000" string(90) "1f8b0800000000000003735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200d7739de519000000" string(86) "1f8b0800000000000003789c735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200735808cd" -===DONE===
\ No newline at end of file +===DONE=== diff --git a/ext/zlib/tests/gzinflate-bug42663.phpt b/ext/zlib/tests/gzinflate-bug42663.phpt index dd53c78f4e..4f0ca9fa7f 100644 --- a/ext/zlib/tests/gzinflate-bug42663.phpt +++ b/ext/zlib/tests/gzinflate-bug42663.phpt @@ -5,8 +5,8 @@ Bug #42663 (gzinflate() try to allocate all memory with truncated $data) --FILE-- <?php // build a predictable string -$string = b''; -for($i=0; $i<30000; ++$i) $string .= (binary)$i . b' '; +$string = ''; +for($i=0; $i<30000; ++$i) $string .= $i . ' '; var_dump(strlen($string)); // deflate string $deflated = gzdeflate($string,9); @@ -15,9 +15,12 @@ var_dump(strlen($deflated)); $truncated = substr($deflated, 0, 65535); var_dump(strlen($truncated)); // inflate $truncated string (check if it will not eat all memory) -gzinflate($truncated); +var_dump(gzinflate($truncated)); ?> ---EXPECT-- +--EXPECTF-- int(168890) int(66743) int(65535) + +Warning: gzinflate(): data error in %s on line %d +bool(false) diff --git a/ext/zlib/tests/gzinflate_length.phpt b/ext/zlib/tests/gzinflate_length.phpt index 436025d13a..6e86d865ee 100644 --- a/ext/zlib/tests/gzinflate_length.phpt +++ b/ext/zlib/tests/gzinflate_length.phpt @@ -4,7 +4,7 @@ gzinflate() and $length argument <?php if (!extension_loaded("zlib")) print "skip"; ?> --FILE-- <?php -$original = b'aaaaaaaaaaaaaaa'; +$original = 'aaaaaaaaaaaaaaa'; $packed=gzdeflate($original); echo strlen($packed)." ".strlen($original)."\n"; $unpacked=gzinflate($packed, strlen($original)); diff --git a/ext/zlib/tests/gzreadgzwrite.phpt b/ext/zlib/tests/gzreadgzwrite.phpt index 6d6729a72f..71d728b6ed 100644 --- a/ext/zlib/tests/gzreadgzwrite.phpt +++ b/ext/zlib/tests/gzreadgzwrite.phpt @@ -5,7 +5,7 @@ gzopen(), gzread(), gzwrite() if (!extension_loaded("zlib")) print "skip"; ?> --FILE-- <?php -$original = str_repeat("hallo php",4096); +$original = str_repeat(b"hallo php",4096); $filename = tempnam("/tmp", "phpt"); $fp = gzopen($filename, "wb"); @@ -15,7 +15,12 @@ var_dump(gztell($fp)); fclose($fp); $fp = gzopen($filename, "rb"); -$data = gzread($fp, strlen($original)); + +$data = ''; +while ($buf = gzread($fp, 8092)) { + $data .= $buf; +} + if ($data == $original) { echo "Strings are equal\n"; } else { diff --git a/ext/zlib/tests/gzreadgzwriteplain.phpt b/ext/zlib/tests/gzreadgzwriteplain.phpt index 7bb567d889..6a752b6212 100644 --- a/ext/zlib/tests/gzreadgzwriteplain.phpt +++ b/ext/zlib/tests/gzreadgzwriteplain.phpt @@ -5,7 +5,7 @@ gzopen(), gzread(), gzwrite() for non-compressed data if (!extension_loaded("zlib")) print "skip"; ?> --FILE-- <?php -$original = str_repeat("hallo php",4096); +$original = str_repeat(b"hallo php",4096); $filename = tempnam("/tmp", "phpt"); $fp = fopen($filename, "wb"); @@ -15,7 +15,12 @@ var_dump(ftell($fp)); fclose($fp); $fp = gzopen($filename, "rb"); -$data = gzread($fp, strlen($original)); + +$data = ''; +while ($buf = gzread($fp, 8192)) { + $data .= $buf; +} + if ($data == $original) { echo "Strings are equal\n"; } else { @@ -24,7 +29,11 @@ if ($data == $original) { } gzseek($fp, strlen($original) / 2); -$data = gzread($fp, strlen($original)); + +$data = ''; +while ($buf = gzread($fp, 8192)) { + $data .= $buf; +} var_dump(strlen($data)); if ($data == substr($original, strlen($original) / 2)) { diff --git a/ext/zlib/tests/gzuncompress_error1.phpt b/ext/zlib/tests/gzuncompress_error1.phpt index 66e5b2ac43..f26a4f5dcd 100644 --- a/ext/zlib/tests/gzuncompress_error1.phpt +++ b/ext/zlib/tests/gzuncompress_error1.phpt @@ -14,8 +14,6 @@ if (!extension_loaded("zlib")) { * Alias to functions: */ - - echo "*** Testing gzuncompress() : error conditions ***\n"; // Zero arguments @@ -29,14 +27,12 @@ $length = 10; $extra_arg = 10; var_dump( gzuncompress($data, $length, $extra_arg) ); - echo "\n-- Testing with a buffer that is too small --\n"; $short_len = strlen($data) - 1; $compressed = gzcompress($data); var_dump(gzuncompress($compressed, $short_len)); - echo "\n-- Testing with incorrect arguments --\n"; var_dump(gzuncompress(123)); @@ -68,7 +64,7 @@ NULL -- Testing with a buffer that is too small -- -Warning: gzuncompress(): buffer error in %s on line %d +Warning: gzuncompress(): insufficient memory in %s on line %d bool(false) -- Testing with incorrect arguments -- @@ -81,4 +77,4 @@ NULL Warning: gzuncompress() expects parameter 2 to be long, string given in %s on line %d NULL -===DONE===
\ No newline at end of file +===DONE=== diff --git a/ext/zlib/tests/gzwrite_variation1.phpt b/ext/zlib/tests/gzwrite_variation1.phpt index bd3778e366..ab6c2606b4 100644 --- a/ext/zlib/tests/gzwrite_variation1.phpt +++ b/ext/zlib/tests/gzwrite_variation1.phpt @@ -11,7 +11,7 @@ if (!extension_loaded("zlib")) { $filename = dirname(__FILE__)."/004.txt.gz"; $h = gzopen($filename, 'r'); -$str = "Here is the string to be written. "; +$str = b"Here is the string to be written. "; $length = 10; var_dump(gzwrite( $h, $str ) ); var_dump(gzread($h, 10)); diff --git a/ext/zlib/tests/ob_001.phpt b/ext/zlib/tests/ob_001.phpt new file mode 100644 index 0000000000..b074a4f55b --- /dev/null +++ b/ext/zlib/tests/ob_001.phpt @@ -0,0 +1,20 @@ +--TEST-- +zlib.output_compression +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) die("skip need ext/zlib"); +if (false === stristr(PHP_SAPI, "cgi")) die("skip need sapi/cgi"); +?> +--GET-- +a=b +--INI-- +zlib.output_compression=1 +--ENV-- +HTTP_ACCEPT_ENCODING=gzip +--FILE-- +<?php +echo "hi\n"; +?> +--EXPECTF-- +‹%s + diff --git a/ext/zlib/tests/ob_002.phpt b/ext/zlib/tests/ob_002.phpt new file mode 100644 index 0000000000..53cf25ceb1 --- /dev/null +++ b/ext/zlib/tests/ob_002.phpt @@ -0,0 +1,18 @@ +--TEST-- +zlib.output_compression +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) die("skip need ext/zlib"); +?> +--INI-- +zlib.output_compression=1 +--ENV-- +HTTP_ACCEPT_ENCODING=gzip +--FILE-- +<?php +ini_set("zlib.output_compression", 0); +echo "hi\n"; +?> +--EXPECTF-- +hi + diff --git a/ext/zlib/tests/ob_003.phpt b/ext/zlib/tests/ob_003.phpt new file mode 100644 index 0000000000..43dbb08969 --- /dev/null +++ b/ext/zlib/tests/ob_003.phpt @@ -0,0 +1,25 @@ +--TEST-- +zlib.output_compression +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) die("skip need ext/zlib"); +if (false === stristr(PHP_SAPI, "cgi")) die("skip need sapi/cgi"); +?> +--INI-- +zlib.output_compression=0 +--ENV-- +HTTP_ACCEPT_ENCODING=gzip +--POST-- +dummy=42 +--FILE-- +<?php +ini_set("zlib.output_compression", 1); +echo "hi\n"; +?> +--EXPECTF-- +%s +Content-Encoding: gzip +Vary: Accept-Encoding +%s + +‹%s diff --git a/ext/zlib/tests/ob_004.phpt b/ext/zlib/tests/ob_004.phpt new file mode 100644 index 0000000000..3d3be9df7b --- /dev/null +++ b/ext/zlib/tests/ob_004.phpt @@ -0,0 +1,25 @@ +--TEST-- +ob_gzhandler +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) die("skip need ext/zlib"); +if (false === stristr(PHP_SAPI, "cgi")) die("skip need sapi/cgi"); +?> +--INI-- +zlib.output_compression=0 +--ENV-- +HTTP_ACCEPT_ENCODING=gzip +--POST-- +dummy=42 +--FILE-- +<?php +ob_start("ob_gzhandler"); +echo "hi\n"; +?> +--EXPECTF-- +%s +Content-Encoding: gzip +Vary: Accept-Encoding +%s + +‹%s diff --git a/ext/zlib/tests/ob_005.phpt b/ext/zlib/tests/ob_005.phpt new file mode 100644 index 0000000000..c266cb71f3 --- /dev/null +++ b/ext/zlib/tests/ob_005.phpt @@ -0,0 +1,21 @@ +--TEST-- +ob_gzhandler +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) die("skip need ext/zlib"); +if (false === stristr(PHP_SAPI, "cgi")) die("skip need sapi/cgi"); +?> +--INI-- +zlib.output_compression=0 +--ENV-- +HTTP_ACCEPT_ENCODING=gzip +--POST-- +dummy=42 +--FILE-- +<?php +ob_start("ob_gzhandler"); +ini_set("zlib.output_compression", 0); +echo "hi\n"; +?> +--EXPECTF-- +%shi diff --git a/ext/zlib/tests/readgzfile_variation14.phpt b/ext/zlib/tests/readgzfile_variation14.phpt index 165bf59b89..ee0d6d6d4e 100644 --- a/ext/zlib/tests/readgzfile_variation14.phpt +++ b/ext/zlib/tests/readgzfile_variation14.phpt @@ -41,4 +41,4 @@ NULL Warning: readgzfile() expects parameter 2 to be long, string given in %s on line %d NULL -===DONE===
\ No newline at end of file +===DONE=== diff --git a/ext/zlib/tests/readgzfile_variation4.phpt b/ext/zlib/tests/readgzfile_variation4.phpt index cbc561c71d..ece84a990e 100644 --- a/ext/zlib/tests/readgzfile_variation4.phpt +++ b/ext/zlib/tests/readgzfile_variation4.phpt @@ -26,9 +26,18 @@ foreach ( $variation as $var ) { ?> ===DONE=== --EXPECTF-- +Warning: readgzfile(10.5): failed to open stream: No such file or directory in %s on line %d bool(false) + +Warning: readgzfile(-10.5): failed to open stream: No such file or directory in %s on line %d bool(false) + +Warning: readgzfile(123456789000): failed to open stream: No such file or directory in %s on line %d bool(false) + +Warning: readgzfile(-123456789000): failed to open stream: No such file or directory in %s on line %d bool(false) + +Warning: readgzfile(0.5): failed to open stream: No such file or directory in %s on line %d bool(false) ===DONE=== diff --git a/ext/zlib/tests/readgzfile_variation5.phpt b/ext/zlib/tests/readgzfile_variation5.phpt index dde0dabdd0..460e188930 100644 --- a/ext/zlib/tests/readgzfile_variation5.phpt +++ b/ext/zlib/tests/readgzfile_variation5.phpt @@ -25,8 +25,15 @@ foreach ( $variation as $var ) { ?> ===DONE=== --EXPECTF-- +Warning: readgzfile(0): failed to open stream: No such file or directory in %s on line %d bool(false) + +Warning: readgzfile(1): failed to open stream: No such file or directory in %s on line %d bool(false) + +Warning: readgzfile(12345): failed to open stream: No such file or directory in %s on line %d bool(false) + +Warning: readgzfile(-2345): failed to open stream: No such file or directory in %s on line %d bool(false) -===DONE===
\ No newline at end of file +===DONE=== diff --git a/ext/zlib/tests/readgzfile_variation6.phpt b/ext/zlib/tests/readgzfile_variation6.phpt index 1beeca764b..69a4dc190a 100644 --- a/ext/zlib/tests/readgzfile_variation6.phpt +++ b/ext/zlib/tests/readgzfile_variation6.phpt @@ -43,6 +43,7 @@ foreach ( $variation as $var ) { } ?> --EXPECTF-- +Error: 2 - readgzfile(Class A object): failed to open stream: No such file or directory, %s(%d) bool(false) Error: 2 - readgzfile() expects parameter 1 to be string, object given, %s(%d) NULL
\ No newline at end of file diff --git a/ext/zlib/tests/readgzfile_variation7.phpt b/ext/zlib/tests/readgzfile_variation7.phpt index df244d3954..20162b5cb5 100644 --- a/ext/zlib/tests/readgzfile_variation7.phpt +++ b/ext/zlib/tests/readgzfile_variation7.phpt @@ -29,8 +29,15 @@ foreach ( $variation_array as $var ) { ?> ===DONE=== --EXPECTF-- +Warning: readgzfile(string): failed to open stream: No such file or directory in %s on line %d bool(false) + +Warning: readgzfile(string): failed to open stream: No such file or directory in %s on line %d bool(false) + +Warning: readgzfile(sTrInG): failed to open stream: No such file or directory in %s on line %d bool(false) + +Warning: readgzfile(hello world): failed to open stream: No such file or directory in %s on line %d bool(false) ===DONE=== diff --git a/ext/zlib/tests/zlib_filter_inflate2.phpt b/ext/zlib/tests/zlib_filter_inflate2.phpt index 4332d8e5e6..a2099b6f7a 100644 --- a/ext/zlib/tests/zlib_filter_inflate2.phpt +++ b/ext/zlib/tests/zlib_filter_inflate2.phpt @@ -6,7 +6,7 @@ zlib.inflate of gzip-encoded stream <?php /* $Id$ */ $a = gzopen(dirname(__FILE__) . '/test.txt.gz', 'w'); -fwrite($a, "This is quite the thing ain't it\n"); +fwrite($a, b"This is quite the thing ain't it\n"); fclose($a); $fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r'); @@ -38,4 +38,4 @@ fclose($fp); 2 This is quite the thing ain't it 3 -This is quite the thing ain't it
\ No newline at end of file +This is quite the thing ain't it diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index af23b29100..114c90b287 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -16,6 +16,7 @@ | Stefan Röhrich <sr@linux.de> | | Zeev Suraski <zeev@zend.com> | | Jade Nicoletti <nicoletti@nns.ch> | + | Michael Wallner <mike@php.net> | +----------------------------------------------------------------------+ */ @@ -28,188 +29,12 @@ #include "php.h" #include "SAPI.h" #include "php_ini.h" - -#include <stdlib.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -#ifdef PHP_WIN32 -# define O_RDONLY _O_RDONLY -# include "win32/param.h" -#else -# include <sys/param.h> -/* #include <sys/uio.h> */ -#endif - -#include "ext/standard/head.h" -#include "ext/standard/php_standard.h" #include "ext/standard/info.h" +#include "ext/standard/file.h" +#include "ext/standard/php_string.h" #include "php_zlib.h" -#include "fopen_wrappers.h" - -#if HAVE_PWD_H -# ifdef PHP_WIN32 -# include "win32/pwd.h" -# else -# include <pwd.h> -# endif -#endif - -#if defined(HAVE_UNISTD_H) && defined(PHP_WIN32) -# undef HAVE_UNISTD_H -#endif - -#ifdef COMPILE_DL_ZLIB -# ifndef PUTS -# define PUTS(a) php_printf("%s",a) -# endif -# ifndef PUTC -# define PUTC(a) PUTS(a) -# endif -# ifndef PHPWRITE -# define PHPWRITE(a,n) php_write((a),(n) TSRMLS_CC) -# endif -#endif - -/* Win32 needs some more memory */ -#ifdef PHP_WIN32 -# define PHP_ZLIB_MODIFIER 100 -#else -# define PHP_ZLIB_MODIFIER 1000 -#endif - -#define OS_CODE 0x03 /* FIXME */ -#define GZIP_HEADER_LENGTH 10 -#define GZIP_FOOTER_LENGTH 8 - -/* True globals, no need for thread safety */ -static const int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */ - -static int php_zlib_output_compression_start(TSRMLS_D); - -static PHP_MINIT_FUNCTION(zlib); -static PHP_MSHUTDOWN_FUNCTION(zlib); -static PHP_RINIT_FUNCTION(zlib); -static PHP_MINFO_FUNCTION(zlib); -static PHP_FUNCTION(gzopen); -static PHP_FUNCTION(readgzfile); -static PHP_FUNCTION(gzfile); -static PHP_FUNCTION(gzcompress); -static PHP_FUNCTION(gzuncompress); -static PHP_FUNCTION(gzdeflate); -static PHP_FUNCTION(gzinflate); -static PHP_FUNCTION(gzencode); -static PHP_FUNCTION(ob_gzhandler); -static PHP_FUNCTION(zlib_get_coding_type); - -/* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_gzfile, 0, 0, 1) - ZEND_ARG_INFO(0, filename) - ZEND_ARG_INFO(0, use_include_path) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_gzopen, 0, 0, 2) - ZEND_ARG_INFO(0, filename) - ZEND_ARG_INFO(0, mode) - ZEND_ARG_INFO(0, use_include_path) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_readgzfile, 0, 0, 1) - ZEND_ARG_INFO(0, filename) - ZEND_ARG_INFO(0, use_include_path) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_gzcompress, 0, 0, 1) - ZEND_ARG_INFO(0, data) - ZEND_ARG_INFO(0, level) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_gzuncompress, 0, 0, 1) - ZEND_ARG_INFO(0, data) - ZEND_ARG_INFO(0, length) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_gzdeflate, 0, 0, 1) - ZEND_ARG_INFO(0, data) - ZEND_ARG_INFO(0, level) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_gzinflate, 0, 0, 1) - ZEND_ARG_INFO(0, data) - ZEND_ARG_INFO(0, length) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_zlib_get_coding_type, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_gzencode, 0, 0, 1) - ZEND_ARG_INFO(0, data) - ZEND_ARG_INFO(0, level) - ZEND_ARG_INFO(0, encoding_mode) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_ob_gzhandler, 0, 0, 2) - ZEND_ARG_INFO(0, str) - ZEND_ARG_INFO(0, mode) -ZEND_END_ARG_INFO() -/* }}} */ - -/* {{{ php_zlib_functions[] - */ -static const zend_function_entry php_zlib_functions[] = { - PHP_FE(readgzfile, arginfo_readgzfile) - PHP_FALIAS(gzrewind, rewind, NULL) - PHP_FALIAS(gzclose, fclose, NULL) - PHP_FALIAS(gzeof, feof, NULL) - PHP_FALIAS(gzgetc, fgetc, NULL) - PHP_FALIAS(gzgets, fgets, NULL) - PHP_FALIAS(gzgetss, fgetss, NULL) - PHP_FALIAS(gzread, fread, NULL) - PHP_FE(gzopen, arginfo_gzopen) - PHP_FALIAS(gzpassthru, fpassthru, NULL) - PHP_FALIAS(gzseek, fseek, NULL) - PHP_FALIAS(gztell, ftell, NULL) - PHP_FALIAS(gzwrite, fwrite, NULL) - PHP_FALIAS(gzputs, fwrite, NULL) - PHP_FE(gzfile, arginfo_gzfile) - PHP_FE(gzcompress, arginfo_gzcompress) - PHP_FE(gzuncompress, arginfo_gzuncompress) - PHP_FE(gzdeflate, arginfo_gzdeflate) - PHP_FE(gzinflate, arginfo_gzinflate) - PHP_FE(gzencode, arginfo_gzencode) - PHP_FE(ob_gzhandler, arginfo_ob_gzhandler) - PHP_FE(zlib_get_coding_type, arginfo_zlib_get_coding_type) - {NULL, NULL, NULL} -}; -/* }}} */ -ZEND_DECLARE_MODULE_GLOBALS(zlib) - -/* {{{ php_zlib_module_entry - */ -zend_module_entry php_zlib_module_entry = { - STANDARD_MODULE_HEADER, - "zlib", - php_zlib_functions, - PHP_MINIT(zlib), - PHP_MSHUTDOWN(zlib), - PHP_RINIT(zlib), - NULL, - PHP_MINFO(zlib), - "1.1", - PHP_MODULE_GLOBALS(zlib), - NULL, - NULL, - NULL, - STANDARD_MODULE_PROPERTIES_EX -}; -/* }}} */ - -#ifdef COMPILE_DL_ZLIB -ZEND_GET_MODULE(php_zlib) -#endif +ZEND_DECLARE_MODULE_GLOBALS(zlib); /* {{{ Memory management wrappers */ @@ -224,156 +49,400 @@ static void php_zlib_free(voidpf opaque, voidpf address) } /* }}} */ -/* {{{ OnUpdate_zlib_output_compression */ -static PHP_INI_MH(OnUpdate_zlib_output_compression) +/* {{{ php_zlib_output_conflict_check() */ +static int php_zlib_output_conflict_check(const char *handler_name, size_t handler_name_len TSRMLS_DC) { - int status, int_value; - char *ini_value; - - if (new_value == NULL) { - return FAILURE; + if (php_output_get_level(TSRMLS_C) > 0) { + if (php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME) TSRMLS_CC) + || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("ob_gzhandler") TSRMLS_CC) + || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("mb_output_handler") TSRMLS_CC) + || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("URL-Rewriter") TSRMLS_CC)) { + return FAILURE; + } } + return SUCCESS; +} +/* }}} */ - if (!strncasecmp(new_value, "off", sizeof("off"))) { - new_value = "0"; - new_value_length = sizeof("0"); - } else if (!strncasecmp(new_value, "on", sizeof("on"))) { - new_value = "1"; - new_value_length = sizeof("1"); +/* {{{ php_zlib_output_encoding() */ +static int php_zlib_output_encoding(TSRMLS_D) +{ + zval **enc; + + if (!ZLIBG(compression_coding)) { + zend_is_auto_global(ZEND_STRL("_SERVER") TSRMLS_CC); + if (PG(http_globals)[TRACK_VARS_SERVER] && SUCCESS == zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING"), (void *) &enc)) { + convert_to_string(*enc); + if (strstr(Z_STRVAL_PP(enc), "gzip")) { + ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_GZIP; + } else if (strstr(Z_STRVAL_PP(enc), "deflate")) { + ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_DEFLATE; + } + } } + return ZLIBG(compression_coding); +} +/* }}} */ - int_value = zend_atoi(new_value, new_value_length); - ini_value = zend_ini_string("output_handler", sizeof("output_handler"), 0); - - if (ini_value && *ini_value && int_value) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_CORE_ERROR, "Cannot use both zlib.output_compression and output_handler together!!"); +/* {{{ php_zlib_output_handler() */ +static int php_zlib_output_handler(void **handler_context, php_output_context *output_context) +{ + php_zlib_context *ctx = *(php_zlib_context **) handler_context; + int flags = Z_SYNC_FLUSH; + PHP_OUTPUT_TSRMLS(output_context); + + if (!php_zlib_output_encoding(TSRMLS_C)) { + /* "Vary: Accept-Encoding" header sent along uncompressed content breaks caching in MSIE, + so let's just send it with successfully compressed content or unless the complete + buffer gets discarded, see http://bugs.php.net/40325; + + Test as follows: + +Vary: $ HTTP_ACCEPT_ENCODING=gzip ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n";' + +Vary: $ HTTP_ACCEPT_ENCODING= ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n";' + -Vary: $ HTTP_ACCEPT_ENCODING=gzip ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n"; ob_end_clean();' + -Vary: $ HTTP_ACCEPT_ENCODING= ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n"; ob_end_clean();' + */ + if (output_context->op != (PHP_OUTPUT_HANDLER_START|PHP_OUTPUT_HANDLER_CLEAN|PHP_OUTPUT_HANDLER_FINAL)) { + sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 1 TSRMLS_CC); + } return FAILURE; } - if (stage == PHP_INI_STAGE_RUNTIME && SG(headers_sent) && !SG(request_info).no_headers) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_compression - headers already sent"); - return FAILURE; + if (output_context->op & PHP_OUTPUT_HANDLER_START) { + /* start up */ + if (Z_OK != deflateInit2(&ctx->Z, ZLIBG(output_compression_level), Z_DEFLATED, ZLIBG(compression_coding), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) { + return FAILURE; + } } - status = OnUpdateLong(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + if (output_context->op & PHP_OUTPUT_HANDLER_CLEAN) { + /* free buffers */ + deflateEnd(&ctx->Z); - if (stage == PHP_INI_STAGE_RUNTIME && int_value) { - status = php_zlib_output_compression_start(TSRMLS_C); - } + if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) { + /* discard */ + return SUCCESS; + } else { + /* restart */ + if (Z_OK != deflateInit2(&ctx->Z, ZLIBG(output_compression_level), Z_DEFLATED, ZLIBG(compression_coding), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) { + return FAILURE; + } + ctx->buffer.used = 0; + } + } else { + if (output_context->in.used) { + /* append input */ + if (ctx->buffer.free < output_context->in.used) { + if (!(ctx->buffer.aptr = erealloc_recoverable(ctx->buffer.data, ctx->buffer.used + ctx->buffer.free + output_context->in.used))) { + deflateEnd(&ctx->Z); + return FAILURE; + } + ctx->buffer.data = ctx->buffer.aptr; + ctx->buffer.free += output_context->in.used; + } + memcpy(ctx->buffer.data + ctx->buffer.used, output_context->in.data, output_context->in.used); + ctx->buffer.free -= output_context->in.used; + ctx->buffer.used += output_context->in.used; + } + output_context->out.size = PHP_ZLIB_BUFFER_SIZE_GUESS(output_context->in.used); + output_context->out.data = emalloc(output_context->out.size); + output_context->out.free = 1; + output_context->out.used = 0; + + ctx->Z.avail_in = ctx->buffer.used; + ctx->Z.next_in = (Bytef *) ctx->buffer.data; + ctx->Z.avail_out = output_context->out.size; + ctx->Z.next_out = (Bytef *) output_context->out.data; + + if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) { + flags = Z_FINISH; + } else if (output_context->op & PHP_OUTPUT_HANDLER_FLUSH) { + flags = Z_FULL_FLUSH; + } - return status; + switch (deflate(&ctx->Z, flags)) { + case Z_OK: + if (flags == Z_FINISH) { + deflateEnd(&ctx->Z); + return FAILURE; + } + case Z_STREAM_END: + if (ctx->Z.avail_in) { + memmove(ctx->buffer.data, ctx->buffer.data + ctx->buffer.used - ctx->Z.avail_in, ctx->Z.avail_in); + } + ctx->buffer.free += ctx->buffer.used - ctx->Z.avail_in; + ctx->buffer.used = ctx->Z.avail_in; + output_context->out.used = output_context->out.size - ctx->Z.avail_out; + break; + default: + deflateEnd(&ctx->Z); + return FAILURE; + } + + php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS, &flags TSRMLS_CC); + if (!(flags & PHP_OUTPUT_HANDLER_STARTED)) { + if (SG(headers_sent) || !ZLIBG(output_compression)) { + deflateEnd(&ctx->Z); + return FAILURE; + } + switch (ZLIBG(compression_coding)) { + case PHP_ZLIB_ENCODING_GZIP: + sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1 TSRMLS_CC); + break; + case PHP_ZLIB_ENCODING_DEFLATE: + sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1 TSRMLS_CC); + break; + default: + deflateEnd(&ctx->Z); + return FAILURE; + } + sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 1 TSRMLS_CC); + php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE, NULL TSRMLS_CC); + } + + if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) { + deflateEnd(&ctx->Z); + } + } + return SUCCESS; } /* }}} */ -/* {{{ OnUpdate_zlib_output_compression_level */ -static PHP_INI_MH(OnUpdate_zlib_output_compression_level) +/* {{{ php_zlib_output_handler_dtor() */ +static void php_zlib_output_handler_dtor(void *opaq TSRMLS_DC) { - OnUpdateLong(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + php_zlib_context *ctx = (php_zlib_context *) opaq; - return SUCCESS; + if (ctx) { + if (ctx->buffer.data) { + efree(ctx->buffer.data); + } + efree(ctx); + } } /* }}} */ -/* {{{ OnUpdate_zlib_output_handler */ -static PHP_INI_MH(OnUpdate_zlib_output_handler) +/* {{{ php_zlib_output_handler_init() */ +static php_output_handler *php_zlib_output_handler_init(const char *handler_name, size_t handler_name_len, size_t chunk_size, int flags TSRMLS_DC) { - if (stage == PHP_INI_STAGE_RUNTIME && SG(headers_sent) && !SG(request_info).no_headers) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_handler - headers already sent"); - return FAILURE; + php_output_handler *h = NULL; + php_zlib_context *ctx; + + if (!ZLIBG(output_compression)) { + ZLIBG(output_compression) = chunk_size ? chunk_size : PHP_OUTPUT_HANDLER_DEFAULT_SIZE; } - OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + if ((h = php_output_handler_create_internal(handler_name, handler_name_len, php_zlib_output_handler, chunk_size, flags TSRMLS_CC))) { + ctx = (php_zlib_context *) ecalloc(1, sizeof(php_zlib_context)); + ctx->Z.zalloc = php_zlib_alloc; + ctx->Z.zfree = php_zlib_free; + php_output_handler_set_context(h, ctx, php_zlib_output_handler_dtor TSRMLS_CC); + } - return SUCCESS; + return h; } /* }}} */ +/* {{{ php_zlib_output_compression_start() */ +static void php_zlib_output_compression_start(TSRMLS_D) +{ + zval *zoh; + php_output_handler *h; -PHP_INI_BEGIN() - STD_PHP_INI_BOOLEAN("zlib.output_compression", "0", PHP_INI_ALL, OnUpdate_zlib_output_compression, output_compression, zend_zlib_globals, zlib_globals) - STD_PHP_INI_ENTRY("zlib.output_compression_level", "-1", PHP_INI_ALL, OnUpdate_zlib_output_compression_level, output_compression_level, zend_zlib_globals, zlib_globals) - STD_PHP_INI_ENTRY("zlib.output_handler", "", PHP_INI_ALL, OnUpdate_zlib_output_handler, output_handler, zend_zlib_globals, zlib_globals) -PHP_INI_END() + switch (ZLIBG(output_compression)) { + case 0: + break; + case 1: + ZLIBG(output_compression) = PHP_OUTPUT_HANDLER_DEFAULT_SIZE; + /* break omitted intentionally */ + default: + if ( (h = php_zlib_output_handler_init(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME), ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC)) && + (SUCCESS == php_output_handler_start(h TSRMLS_CC))) { + if (ZLIBG(output_handler) && *ZLIBG(output_handler)) { + MAKE_STD_ZVAL(zoh); + ZVAL_STRING(zoh, ZLIBG(output_handler), 1); + php_output_start_user(zoh, ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC); + zval_ptr_dtor(&zoh); + } + } + break; + } +} +/* }}} */ -/* {{{ PHP_MINIT_FUNCTION - */ -static PHP_MINIT_FUNCTION(zlib) +/* {{{ php_zlib_encode() */ +static int php_zlib_encode(const char *in_buf, size_t in_len, char **out_buf, size_t *out_len, int encoding, int level TSRMLS_DC) { - php_register_url_stream_wrapper("compress.zlib", &php_stream_gzip_wrapper TSRMLS_CC); - php_stream_filter_register_factory("zlib.*", &php_zlib_filter_factory TSRMLS_CC); + int status; + z_stream Z; - REGISTER_LONG_CONSTANT("FORCE_GZIP", CODING_GZIP, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("FORCE_DEFLATE", CODING_DEFLATE, CONST_CS | CONST_PERSISTENT); + memset(&Z, 0, sizeof(z_stream)); + Z.zalloc = php_zlib_alloc; + Z.zfree = php_zlib_free; - REGISTER_INI_ENTRIES(); + if (Z_OK == (status = deflateInit2(&Z, level, Z_DEFLATED, encoding, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) { + *out_len = PHP_ZLIB_BUFFER_SIZE_GUESS(in_len); + *out_buf = emalloc(*out_len); - return SUCCESS; + Z.next_in = (Bytef *) in_buf; + Z.next_out = (Bytef *) *out_buf; + Z.avail_in = in_len; + Z.avail_out = *out_len; + + status = deflate(&Z, Z_FINISH); + deflateEnd(&Z); + + if (Z_STREAM_END == status) { + /* size buffer down to actual length */ + *out_buf = erealloc(*out_buf, Z.total_out + 1); + (*out_buf)[*out_len = Z.total_out] = '\0'; + return SUCCESS; + } else { + efree(*out_buf); + } + } + + *out_buf = NULL; + *out_len = 0; + + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status)); + return FAILURE; } /* }}} */ -/* {{{ PHP_RINIT_FUNCTION - */ -static PHP_RINIT_FUNCTION(zlib) +/* {{{ php_zlib_inflate_rounds() */ +static inline int php_zlib_inflate_rounds(z_stream *Z, size_t max, char **buf, size_t *len) { - ZLIBG(ob_gzhandler_status) = 0; - ZLIBG(compression_coding) = 0; + int status, round = 0; + php_zlib_buffer buffer = {NULL, NULL, 0, 0, 0}; - php_zlib_output_compression_start(TSRMLS_C); + *buf = NULL; + *len = 0; - return SUCCESS; + buffer.size = (max && (max < Z->avail_in)) ? max : Z->avail_in; + + do { + if ((max && (max <= buffer.used)) || !(buffer.aptr = erealloc_recoverable(buffer.data, buffer.size))) { + status = Z_MEM_ERROR; + } else { + buffer.data = buffer.aptr; + Z->avail_out = buffer.free = buffer.size - buffer.used; + Z->next_out = (Bytef *) buffer.data + buffer.used; +#if 0 + fprintf(stderr, "\n%3d: %3d PRIOR: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out); +#endif + status = inflate(Z, Z_NO_FLUSH); + + buffer.used += buffer.free - Z->avail_out; + buffer.free = Z->avail_out; +#if 0 + fprintf(stderr, "%3d: %3d AFTER: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out); +#endif + buffer.size += (buffer.size >> 3) + 1; + } + } while ((Z_BUF_ERROR == status || (Z_OK == status && Z->avail_in)) && ++round < 100); + + if (status == Z_STREAM_END) { + buffer.data = erealloc(buffer.data, buffer.used + 1); + buffer.data[buffer.used] = '\0'; + *buf = buffer.data; + *len = buffer.used; + } else { + if (buffer.data) { + efree(buffer.data); + } + /* HACK: See zlib/examples/zpipe.c inf() function for explanation. */ + /* This works as long as this function is not used for streaming. Required to catch very short invalid data. */ + status = (status == Z_OK) ? Z_DATA_ERROR : status; + } + return status; } /* }}} */ -/* {{{ PHP_MSHUTDOWN_FUNCTION - */ -static PHP_MSHUTDOWN_FUNCTION(zlib) +/* {{{ php_zlib_decode() */ +static int php_zlib_decode(const char *in_buf, size_t in_len, char **out_buf, size_t *out_len, int encoding, size_t max_len TSRMLS_DC) { - php_unregister_url_stream_wrapper("zlib" TSRMLS_CC); - php_stream_filter_unregister_factory("zlib.*" TSRMLS_CC); + int status = Z_DATA_ERROR; + z_stream Z; + + memset(&Z, 0, sizeof(z_stream)); + Z.zalloc = php_zlib_alloc; + Z.zfree = php_zlib_free; + + if (in_len) { +retry_raw_inflate: + status = inflateInit2(&Z, encoding); + if (Z_OK == status) { + Z.next_in = (Bytef *) in_buf; + Z.avail_in = in_len; + + switch (status = php_zlib_inflate_rounds(&Z, max_len, out_buf, out_len)) { + case Z_STREAM_END: + inflateEnd(&Z); + return SUCCESS; + + case Z_DATA_ERROR: + /* raw deflated data? */ + if (PHP_ZLIB_ENCODING_ANY == encoding) { + inflateEnd(&Z); + encoding = PHP_ZLIB_ENCODING_RAW; + goto retry_raw_inflate; + } + } + inflateEnd(&Z); + } + } - UNREGISTER_INI_ENTRIES(); + *out_buf = NULL; + *out_len = 0; - return SUCCESS; + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status)); + return FAILURE; } /* }}} */ -/* {{{ PHP_MINFO_FUNCTION - */ -static PHP_MINFO_FUNCTION(zlib) +/* {{{ proto string zlib_get_coding_type(void) + Returns the coding type used for output compression */ +static PHP_FUNCTION(zlib_get_coding_type) { - php_info_print_table_start(); - php_info_print_table_row(2, "ZLib Support", "enabled"); - php_info_print_table_row(2, "Stream Wrapper support", "compress.zlib://"); - php_info_print_table_row(2, "Stream Filter support", "zlib.inflate, zlib.deflate"); - php_info_print_table_row(2, "Compiled Version", ZLIB_VERSION); - php_info_print_table_row(2, "Linked Version", (char *) zlibVersion()); - php_info_print_table_end(); - - DISPLAY_INI_ENTRIES(); + if (zend_parse_parameters_none() == FAILURE) { + return; + } + switch (ZLIBG(compression_coding)) { + case PHP_ZLIB_ENCODING_GZIP: + RETURN_STRINGL("gzip", sizeof("gzip") - 1, 1); + case PHP_ZLIB_ENCODING_DEFLATE: + RETURN_STRINGL("deflate", sizeof("deflate") - 1, 1); + default: + RETURN_FALSE; + } } /* }}} */ /* {{{ proto array gzfile(string filename [, int use_include_path]) - Read und uncompress entire .gz-file into an array */ + Read and uncompress entire .gz-file into an array */ static PHP_FUNCTION(gzfile) { char *filename; int filename_len; - long flags = 0; - char *slashed, buf[8192]; + int flags = REPORT_ERRORS; + char *slashed, buf[8192] = {0}; register int i = 0; - int use_include_path = 0; + long use_include_path = 0; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &flags) == FAILURE) { + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path)) { return; } - use_include_path = flags ? USE_PATH : 0; + if (use_include_path) { + flags |= USE_PATH; + } /* using a stream here is a bit more efficient (resource wise) than php_gzopen_wrapper */ - stream = php_stream_gzopen(NULL, filename, "rb", use_include_path | REPORT_ERRORS, NULL, NULL STREAMS_CC TSRMLS_CC); - if (stream == NULL) { + stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC TSRMLS_CC); + + if (!stream) { /* Error reporting is already done by stream code */ RETURN_FALSE; } @@ -382,12 +451,12 @@ static PHP_FUNCTION(gzfile) array_init(return_value); /* Now loop through the file and do the magic quotes thing if needed */ - memset(buf,0,sizeof(buf)); - + memset(buf, 0, sizeof(buf)); + while (php_stream_gets(stream, buf, sizeof(buf) - 1) != NULL) { if (PG(magic_quotes_runtime)) { int len; - + slashed = php_addslashes(buf, 0, &len, 0 TSRMLS_CC); /* 0 = don't free source string */ add_index_stringl(return_value, i++, slashed, len, 0); } else { @@ -402,19 +471,22 @@ static PHP_FUNCTION(gzfile) Open a .gz-file and return a .gz-file pointer */ static PHP_FUNCTION(gzopen) { - char *filename, *mode; + char *filename; + char *mode; int filename_len, mode_len; - long flags = 0; + int flags = REPORT_ERRORS; php_stream *stream; - int use_include_path = 0; + long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } - use_include_path = flags ? USE_PATH : 0; + if (use_include_path) { + flags |= USE_PATH; + } - stream = php_stream_gzopen(NULL, filename, mode, use_include_path | REPORT_ERRORS, NULL, NULL STREAMS_CC TSRMLS_CC); + stream = php_stream_gzopen(NULL, filename, mode, flags, NULL, NULL STREAMS_CC TSRMLS_CC); if (!stream) { RETURN_FALSE; @@ -423,27 +495,27 @@ static PHP_FUNCTION(gzopen) } /* }}} */ -/* - * Read a file and write the ouput to stdout - */ /* {{{ proto int readgzfile(string filename [, int use_include_path]) Output a .gz-file */ static PHP_FUNCTION(readgzfile) { char *filename; int filename_len; - long flags = 0; + int flags = REPORT_ERRORS; php_stream *stream; int size; - int use_include_path = 0; + long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; } - use_include_path = flags ? USE_PATH : 0; + if (use_include_path) { + flags |= USE_PATH; + } + + stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC TSRMLS_CC); - stream = php_stream_gzopen(NULL, filename, "rb", use_include_path, NULL, NULL STREAMS_CC TSRMLS_CC); if (!stream) { RETURN_FALSE; } @@ -453,676 +525,345 @@ static PHP_FUNCTION(readgzfile) } /* }}} */ -/* {{{ proto string gzcompress(string data [, int level]) - Gzip-compress a string */ -static PHP_FUNCTION(gzcompress) -{ - int data_len, status; - long level = Z_DEFAULT_COMPRESSION; - unsigned long l2; - char *data, *s2; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &level) == FAILURE) { - return; - } - - if ((level < -1) || (level > 9)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "compression level (%ld) must be within -1..9", level); - RETURN_FALSE; - } - - l2 = data_len + (data_len / PHP_ZLIB_MODIFIER) + 15 + 1; /* room for \0 */ - s2 = (char *) emalloc(l2); - if (!s2) { - RETURN_FALSE; - } - - if (level >= 0) { - status = compress2(s2, &l2, data, data_len, level); - } else { - status = compress(s2, &l2, data, data_len); - } - - if (status == Z_OK) { - s2 = erealloc(s2, l2 + 1); - s2[l2] = '\0'; - RETURN_STRINGL(s2, l2, 0); - } else { - efree(s2); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status)); - RETURN_FALSE; - } +#define PHP_ZLIB_ENCODE_FUNC(name, default_encoding) \ +static PHP_FUNCTION(name) \ +{ \ + char *in_buf, *out_buf; \ + int in_len; \ + size_t out_len; \ + long level = -1; \ + long encoding = default_encoding; \ + if (default_encoding) { \ + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &in_buf, &in_len, &level, &encoding)) { \ + return; \ + } \ + } else { \ + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|l", &in_buf, &in_len, &encoding, &level)) { \ + return; \ + } \ + } \ + if (level < -1 || level > 9) { \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "compression level (%ld) must be within -1..9", level); \ + RETURN_FALSE; \ + } \ + switch (encoding) { \ + case PHP_ZLIB_ENCODING_RAW: \ + case PHP_ZLIB_ENCODING_GZIP: \ + case PHP_ZLIB_ENCODING_DEFLATE: \ + break; \ + default: \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE"); \ + RETURN_FALSE; \ + } \ + if (SUCCESS != php_zlib_encode(in_buf, in_len, &out_buf, &out_len, encoding, level TSRMLS_CC)) { \ + RETURN_FALSE; \ + } \ + RETURN_STRINGL(out_buf, out_len, 0); \ } -/* }}} */ - -/* {{{ proto string gzuncompress(string data [, int length]) - Unzip a gzip-compressed string */ -static PHP_FUNCTION(gzuncompress) -{ - int data_len, status; - unsigned int factor=1, maxfactor=16; - long limit = 0; - unsigned long plength=0, length; - char *data, *s1=NULL, *s2=NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &limit) == FAILURE) { - return; - } - - if (limit < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "length (%ld) must be greater or equal zero", limit); - RETURN_FALSE; - } - plength = limit; - - /* - zlib::uncompress() wants to know the output data length - if none was given as a parameter - we try from input length * 2 up to input length * 2^15 - doubling it whenever it wasn't big enough - that should be eneugh for all real life cases - */ - do { - length = plength ? plength : (unsigned long)data_len * (1 << factor++); - s2 = (char *) erealloc(s1, length); - status = uncompress(s2, &length, data, data_len); - s1 = s2; - } while ((status == Z_BUF_ERROR) && (!plength) && (factor < maxfactor)); - - if (status == Z_OK) { - s2 = erealloc(s2, length + 1); /* space for \0 */ - s2[ length ] = '\0'; - RETURN_STRINGL(s2, length, 0); - } else { - efree(s2); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status)); - RETURN_FALSE; - } +#define PHP_ZLIB_DECODE_FUNC(name, encoding) \ +static PHP_FUNCTION(name) \ +{ \ + char *in_buf, *out_buf; \ + int in_len; \ + size_t out_len; \ + long max_len = 0; \ + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &in_buf, &in_len, &max_len)) { \ + return; \ + } \ + if (max_len < 0) { \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "length (%ld) must be greater or equal zero", max_len); \ + RETURN_FALSE; \ + } \ + if (SUCCESS != php_zlib_decode(in_buf, in_len, &out_buf, &out_len, encoding, max_len TSRMLS_CC)) { \ + RETURN_FALSE; \ + } \ + RETURN_STRINGL(out_buf, out_len, 0); \ } -/* }}} */ - -/* {{{ proto string gzdeflate(string data [, int level]) - Gzip-compress a string */ -static PHP_FUNCTION(gzdeflate) -{ - int data_len,status; - long level = Z_DEFAULT_COMPRESSION; - z_stream stream; - char *data, *s2; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &level) == FAILURE) { - return; - } - - if ((level < -1) || (level > 9)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "compression level (%ld) must be within -1..9", level); - RETURN_FALSE; - } +/* {{{ proto binary zlib_encode(binary data, int encoding[, int level = -1]) + Compress data with the specified encoding */ +PHP_ZLIB_ENCODE_FUNC(zlib_encode, 0); +/* }}} */ - stream.data_type = Z_ASCII; - stream.zalloc = php_zlib_alloc; - stream.zfree = php_zlib_free; - stream.opaque = (voidpf) Z_NULL; +/* {{{ proto binary zlib_decode(binary data[, int max_decoded_len]) + Uncompress any raw/gzip/zlib encoded data */ +PHP_ZLIB_DECODE_FUNC(zlib_decode, PHP_ZLIB_ENCODING_ANY); - stream.next_in = (Bytef *) data; - stream.avail_in = data_len; +/* NOTE: The naming of these userland functions was quite unlucky */ +/* {{{ proto binary gzdeflate(binary data[, int level = -1[, int encoding = ZLIB_ENCODING_RAW]) + Encode data with the raw deflate encoding */ +PHP_ZLIB_ENCODE_FUNC(gzdeflate, PHP_ZLIB_ENCODING_RAW); +/* }}} */ - stream.avail_out = stream.avail_in + (stream.avail_in / PHP_ZLIB_MODIFIER) + 15 + 1; /* room for \0 */ +/* {{{ proto binary gzencode(binary data[, int level = -1[, int encoding = ZLIB_ENCODING_GZIP]) + Encode data with the gzip encoding */ +PHP_ZLIB_ENCODE_FUNC(gzencode, PHP_ZLIB_ENCODING_GZIP); +/* }}} */ +/* {{{ proto binary gzcompress(binary data[, int level = -1[, int encoding = ZLIB_ENCODING_DEFLATE]) + Encode data with the zlib encoding */ +PHP_ZLIB_ENCODE_FUNC(gzcompress, PHP_ZLIB_ENCODING_DEFLATE); +/* }}} */ +/* {{{ proto binary gzinflate(binary data[, int max_decoded_len]) + Decode raw deflate encoded data */ +PHP_ZLIB_DECODE_FUNC(gzinflate, PHP_ZLIB_ENCODING_RAW); +/* }}} */ +/* {{{ proto binary gzdecode(binary data[, int max_decoded_len]) + Decode gzip encoded data */ +PHP_ZLIB_DECODE_FUNC(gzdecode, PHP_ZLIB_ENCODING_GZIP); +/* }}} */ +/* {{{ proto binary gzuncompress(binary data[, int max_decoded_len]) + Decode zlib encoded data */ +PHP_ZLIB_DECODE_FUNC(gzuncompress, PHP_ZLIB_ENCODING_DEFLATE); +/* }}} */ - s2 = (char *) emalloc(stream.avail_out); - if (!s2) { - RETURN_FALSE; - } +#ifdef COMPILE_DL_ZLIB +ZEND_GET_MODULE(php_zlib) +#endif - stream.next_out = s2; +/* {{{ arginfo */ +ZEND_BEGIN_ARG_INFO(arginfo_zlib_get_coding_type, 0) +ZEND_END_ARG_INFO() - /* init with -MAX_WBITS disables the zlib internal headers */ - status = deflateInit2(&stream, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, 0); - if (status == Z_OK) { - status = deflate(&stream, Z_FINISH); - if (status != Z_STREAM_END) { - deflateEnd(&stream); - if (status == Z_OK) { - status = Z_BUF_ERROR; - } - } else { - status = deflateEnd(&stream); - } - } +ZEND_BEGIN_ARG_INFO_EX(arginfo_gzfile, 0, 0, 1) + ZEND_ARG_INFO(0, filename) + ZEND_ARG_INFO(0, use_include_path) +ZEND_END_ARG_INFO() - if (status == Z_OK) { - s2 = erealloc(s2,stream.total_out + 1); /* resize to buffer to the "right" size */ - s2[ stream.total_out ] = '\0'; - RETURN_STRINGL(s2, stream.total_out, 0); - } else { - efree(s2); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status)); - RETURN_FALSE; - } -} -/* }}} */ +ZEND_BEGIN_ARG_INFO_EX(arginfo_gzopen, 0, 0, 2) + ZEND_ARG_INFO(0, filename) + ZEND_ARG_INFO(0, mode) + ZEND_ARG_INFO(0, use_include_path) +ZEND_END_ARG_INFO() -/* {{{ proto string gzinflate(string data [, int length]) - Unzip a gzip-compressed string */ -static PHP_FUNCTION(gzinflate) -{ - int data_len, status; - unsigned int factor=1, maxfactor=16; - long limit = 0; - unsigned long plength=0, length; - char *data, *s1=NULL, *s2=NULL; - z_stream stream; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &limit) == FAILURE) { - return; - } +ZEND_BEGIN_ARG_INFO_EX(arginfo_readgzfile, 0, 0, 1) + ZEND_ARG_INFO(0, filename) + ZEND_ARG_INFO(0, use_include_path) +ZEND_END_ARG_INFO() - if (!data_len) { - RETURN_FALSE; - } +ZEND_BEGIN_ARG_INFO_EX(arginfo_zlib_encode, 0, 0, 2) + ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, encoding) + ZEND_ARG_INFO(0, level) +ZEND_END_ARG_INFO() - if (limit < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "length (%ld) must be greater or equal zero", limit); - RETURN_FALSE; - } - plength = limit; - - stream.zalloc = php_zlib_alloc; - stream.zfree = php_zlib_free; - stream.opaque = Z_NULL; - stream.avail_in = data_len + 1; /* there is room for \0 */ - stream.next_in = (Bytef *) data; - stream.total_out = 0; - - /* init with -MAX_WBITS disables the zlib internal headers */ - status = inflateInit2(&stream, -MAX_WBITS); - if (status != Z_OK) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status)); - RETURN_FALSE; - } +ZEND_BEGIN_ARG_INFO_EX(arginfo_zlib_decode, 0, 0, 1) + ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, max_decoded_len) +ZEND_END_ARG_INFO() - /* - stream.avail_out wants to know the output data length - if none was given as a parameter - we try from input length * 2 up to input length * 2^15 - doubling it whenever it wasn't big enough - that should be enaugh for all real life cases - */ - do { - length = plength ? plength : (unsigned long)data_len * (1 << factor++); - s2 = (char *) erealloc(s1, length); +ZEND_BEGIN_ARG_INFO_EX(arginfo_gzdeflate, 0, 0, 1) + ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, level) + ZEND_ARG_INFO(0, encoding) +ZEND_END_ARG_INFO() - if (!s2) { - if (s1) { - efree(s1); - } - inflateEnd(&stream); - RETURN_FALSE; - } - s1 = s2; +ZEND_BEGIN_ARG_INFO_EX(arginfo_gzencode, 0, 0, 1) + ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, level) + ZEND_ARG_INFO(0, encoding) +ZEND_END_ARG_INFO() - stream.next_out = (Bytef *) &s2[stream.total_out]; - stream.avail_out = length - stream.total_out; - status = inflate(&stream, Z_NO_FLUSH); +ZEND_BEGIN_ARG_INFO_EX(arginfo_gzcompress, 0, 0, 1) + ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, level) + ZEND_ARG_INFO(0, encoding) +ZEND_END_ARG_INFO() - } while ((Z_BUF_ERROR == status || (Z_OK == status && stream.avail_in)) && !plength && factor < maxfactor); +ZEND_BEGIN_ARG_INFO_EX(arginfo_gzinflate, 0, 0, 1) + ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, max_decoded_len) +ZEND_END_ARG_INFO() - inflateEnd(&stream); +ZEND_BEGIN_ARG_INFO_EX(arginfo_gzdecode, 0, 0, 1) + ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, max_decoded_len) +ZEND_END_ARG_INFO() - if ((plength && Z_OK == status) || factor >= maxfactor) { - status = Z_MEM_ERROR; - } +ZEND_BEGIN_ARG_INFO_EX(arginfo_gzuncompress, 0, 0, 1) + ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, max_decoded_len) +ZEND_END_ARG_INFO() +/* }}} */ - if (Z_STREAM_END == status || Z_OK == status) { - s2 = erealloc(s2, stream.total_out + 1); /* room for \0 */ - s2[ stream.total_out ] = '\0'; - RETURN_STRINGL(s2, stream.total_out, 0); - } else { - efree(s2); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status)); - RETURN_FALSE; - } -} +/* {{{ php_zlib_functions[] */ +static const zend_function_entry php_zlib_functions[] = { + PHP_FE(readgzfile, arginfo_readgzfile) + PHP_FALIAS(gzrewind, rewind, NULL) + PHP_FALIAS(gzclose, fclose, NULL) + PHP_FALIAS(gzeof, feof, NULL) + PHP_FALIAS(gzgetc, fgetc, NULL) + PHP_FALIAS(gzgets, fgets, NULL) + PHP_FALIAS(gzgetss, fgetss, NULL) + PHP_FALIAS(gzread, fread, NULL) + PHP_FE(gzopen, arginfo_gzopen) + PHP_FALIAS(gzpassthru, fpassthru, NULL) + PHP_FALIAS(gzseek, fseek, NULL) + PHP_FALIAS(gztell, ftell, NULL) + PHP_FALIAS(gzwrite, fwrite, NULL) + PHP_FALIAS(gzputs, fwrite, NULL) + PHP_FE(gzfile, NULL) + PHP_FE(gzcompress, arginfo_gzcompress) + PHP_FE(gzuncompress, arginfo_gzuncompress) + PHP_FE(gzdeflate, arginfo_gzdeflate) + PHP_FE(gzinflate, arginfo_gzinflate) + PHP_FE(gzencode, arginfo_gzencode) + PHP_FE(gzdecode, arginfo_gzdecode) + PHP_FE(zlib_encode, arginfo_zlib_encode) + PHP_FE(zlib_decode, arginfo_zlib_decode) + PHP_FE(zlib_get_coding_type, arginfo_zlib_get_coding_type) + {NULL, NULL, NULL} +}; /* }}} */ -/* {{{ proto string zlib_get_coding_type(void) - Returns the coding type used for output compression */ -static PHP_FUNCTION(zlib_get_coding_type) +/* {{{ OnUpdate_zlib_output_compression */ +static PHP_INI_MH(OnUpdate_zlib_output_compression) { - switch (ZLIBG(compression_coding)) { - case CODING_GZIP: - RETURN_STRINGL("gzip", sizeof("gzip") - 1, 1); + int status, int_value; + char *ini_value; - case CODING_DEFLATE: - RETURN_STRINGL("deflate", sizeof("deflate") - 1, 1); + if (new_value == NULL) { + return FAILURE; } - RETURN_FALSE; -} - -/* {{{ php_do_deflate - */ -static int php_do_deflate(uint str_length, Bytef **p_buffer, uint *p_buffer_len, zend_bool do_start, zend_bool do_end TSRMLS_DC) -{ - Bytef *buffer; - uInt prev_outlen, outlen; - int err; - int start_offset = ((do_start && ZLIBG(compression_coding) == CODING_GZIP) ? 10 : 0); - int end_offset = (do_end ? 8 : 0); - - outlen = (uint) (str_length + (str_length / PHP_ZLIB_MODIFIER) + 12 + 1); /* leave some room for a trailing \0 */ - if ((outlen + start_offset + end_offset) > *p_buffer_len) { - buffer = (Bytef *) emalloc(outlen + start_offset + end_offset); - } else { - buffer = *p_buffer; + if (!strncasecmp(new_value, "off", sizeof("off"))) { + new_value = "0"; + new_value_length = sizeof("0"); + } else if (!strncasecmp(new_value, "on", sizeof("on"))) { + new_value = "1"; + new_value_length = sizeof("1"); } - ZLIBG(stream).next_out = buffer + start_offset; - ZLIBG(stream).avail_out = outlen; - - err = deflate(&ZLIBG(stream), Z_SYNC_FLUSH); - while (err == Z_OK && !ZLIBG(stream).avail_out) { - prev_outlen = outlen; - outlen *= 3; - if ((outlen + start_offset + end_offset) > *p_buffer_len) { - buffer = erealloc(buffer, outlen + start_offset + end_offset); - } - - ZLIBG(stream).next_out = buffer + start_offset + prev_outlen; - ZLIBG(stream).avail_out = prev_outlen * 2; - - err = deflate(&ZLIBG(stream), Z_SYNC_FLUSH); - } + int_value = zend_atoi(new_value, new_value_length); + ini_value = zend_ini_string("output_handler", sizeof("output_handler"), 0); - if (do_end) { - err = deflate(&ZLIBG(stream), Z_FINISH); - buffer[outlen + start_offset - ZLIBG(stream).avail_out] = '\0'; + if (ini_value && *ini_value && int_value) { + php_error_docref("ref.outcontrol" TSRMLS_CC, E_CORE_ERROR, "Cannot use both zlib.output_compression and output_handler together!!"); + return FAILURE; } - - *p_buffer = buffer; - *p_buffer_len = outlen - ZLIBG(stream).avail_out; - - return err; -} -/* }}} */ - -/* {{{ php_deflate_string - */ -static int php_deflate_string(const char *str, uint str_length, char **newstr, uint *new_length, zend_bool do_start, zend_bool do_end TSRMLS_DC) -{ - int err; - - if (do_start) { - ZLIBG(stream).zalloc = php_zlib_alloc; - ZLIBG(stream).zfree = php_zlib_free; - ZLIBG(stream).opaque = Z_NULL; - - switch (ZLIBG(compression_coding)) { - case CODING_GZIP: - /* windowBits is passed < 0 to suppress zlib header & trailer */ - if (deflateInit2(&ZLIBG(stream), ZLIBG(output_compression_level), Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY) != Z_OK) { - /* TODO: print out error */ - return FAILURE; - } - - ZLIBG(crc) = crc32(0L, Z_NULL, 0); - break; - - case CODING_DEFLATE: - if (deflateInit(&ZLIBG(stream), ZLIBG(output_compression_level)) != Z_OK) { - /* TODO: print out error */ - return FAILURE; - } - break; + if (stage == PHP_INI_STAGE_RUNTIME) { + status = php_output_get_status(TSRMLS_C); + if (status & PHP_OUTPUT_SENT) { + php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_compression - headers already sent"); + return FAILURE; + } else if ((status & PHP_OUTPUT_WRITTEN) && int_value) { + php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot enable zlib.output_compression - there has already been output"); + return FAILURE; } } - ZLIBG(stream).next_in = (Bytef *) str; - ZLIBG(stream).avail_in = (uInt) str_length; - - if (ZLIBG(compression_coding) == CODING_GZIP) { - ZLIBG(crc) = crc32(ZLIBG(crc), (const Bytef *) str, str_length); - } + status = OnUpdateLong(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); - err = php_do_deflate(str_length, (Bytef **) newstr, new_length, do_start, do_end TSRMLS_CC); - /* TODO: error handling (err may be Z_STREAM_ERROR, Z_BUF_ERROR, ?) */ - - if (do_start && ZLIBG(compression_coding) == CODING_GZIP) { - /* Write a very simple .gz header: */ - (*newstr)[0] = gz_magic[0]; - (*newstr)[1] = gz_magic[1]; - (*newstr)[2] = Z_DEFLATED; - (*newstr)[3] = (*newstr)[4] = (*newstr)[5] = (*newstr)[6] = (*newstr)[7] = (*newstr)[8] = 0; - (*newstr)[9] = OS_CODE; - *new_length += 10; - } - if (do_end) { - if (ZLIBG(compression_coding) == CODING_GZIP) { - char *trailer = (*newstr) + (*new_length); - - /* write crc & stream.total_in in LSB order */ - trailer[0] = (char) ZLIBG(crc) & 0xFF; - trailer[1] = (char) (ZLIBG(crc) >> 8) & 0xFF; - trailer[2] = (char) (ZLIBG(crc) >> 16) & 0xFF; - trailer[3] = (char) (ZLIBG(crc) >> 24) & 0xFF; - trailer[4] = (char) ZLIBG(stream).total_in & 0xFF; - trailer[5] = (char) (ZLIBG(stream).total_in >> 8) & 0xFF; - trailer[6] = (char) (ZLIBG(stream).total_in >> 16) & 0xFF; - trailer[7] = (char) (ZLIBG(stream).total_in >> 24) & 0xFF; - trailer[8] = '\0'; - *new_length += 8; + if (stage == PHP_INI_STAGE_RUNTIME && int_value) { + if (!php_output_handler_started(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME) TSRMLS_CC)) { + php_zlib_output_compression_start(TSRMLS_C); } - deflateEnd(&ZLIBG(stream)); } - return SUCCESS; + return status; } /* }}} */ -/* {{{ proto string gzencode(string data [, int level [, int encoding_mode]]) - GZ encode a string */ -static PHP_FUNCTION(gzencode) +/* {{{ OnUpdate_zlib_output_handler */ +static PHP_INI_MH(OnUpdate_zlib_output_handler) { - char *data, *s2; - int data_len; - long level = Z_DEFAULT_COMPRESSION, coding = CODING_GZIP; - int status; - z_stream stream; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &data, &data_len, &level, &coding) == FAILURE) { - return; - } - - if ((level < -1) || (level > 9)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "compression level(%ld) must be within -1..9", level); - RETURN_FALSE; - } - - if ((coding != CODING_GZIP) && (coding != CODING_DEFLATE)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "encoding mode must be FORCE_GZIP or FORCE_DEFLATE"); - RETURN_FALSE; - } - - stream.zalloc = php_zlib_alloc; - stream.zfree = php_zlib_free; - stream.opaque = Z_NULL; - - stream.next_in = (Bytef *) data; - stream.avail_in = data_len; - - stream.avail_out = stream.avail_in + (stream.avail_in / PHP_ZLIB_MODIFIER) + 15 + 1; /* room for \0 */ - s2 = (char *) emalloc(stream.avail_out + GZIP_HEADER_LENGTH + (coding == CODING_GZIP ? GZIP_FOOTER_LENGTH : 0)); - - /* add gzip file header */ - s2[0] = gz_magic[0]; - s2[1] = gz_magic[1]; - s2[2] = Z_DEFLATED; - s2[3] = s2[4] = s2[5] = s2[6] = s2[7] = s2[8] = 0; /* time set to 0 */ - s2[9] = OS_CODE; - - stream.next_out = &(s2[GZIP_HEADER_LENGTH]); - - switch (coding) { - case CODING_GZIP: - /* windowBits is passed < 0 to suppress zlib header & trailer */ - if ((status = deflateInit2(&stream, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) != Z_OK) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status)); - RETURN_FALSE; - } - - break; - case CODING_DEFLATE: - if ((status = deflateInit(&stream, level)) != Z_OK) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status)); - RETURN_FALSE; - } - break; - } - - status = deflate(&stream, Z_FINISH); - if (status != Z_STREAM_END) { - deflateEnd(&stream); - if (status == Z_OK) { - status = Z_BUF_ERROR; - } - } else { - status = deflateEnd(&stream); + if (stage == PHP_INI_STAGE_RUNTIME && (php_output_get_status(TSRMLS_C) & PHP_OUTPUT_SENT)) { + php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_handler - headers already sent"); + return FAILURE; } - if (status == Z_OK) { - /* resize to buffer to the "right" size */ - s2 = erealloc(s2, stream.total_out + GZIP_HEADER_LENGTH + (coding == CODING_GZIP ? GZIP_FOOTER_LENGTH : 0) + 1); - - if (coding == CODING_GZIP) { - char *trailer = s2 + (stream.total_out + GZIP_HEADER_LENGTH); - uLong crc = crc32(0L, Z_NULL, 0); - - crc = crc32(crc, (const Bytef *) data, data_len); - - /* write crc & stream.total_in in LSB order */ - trailer[0] = (char) crc & 0xFF; - trailer[1] = (char) (crc >> 8) & 0xFF; - trailer[2] = (char) (crc >> 16) & 0xFF; - trailer[3] = (char) (crc >> 24) & 0xFF; - trailer[4] = (char) stream.total_in & 0xFF; - trailer[5] = (char) (stream.total_in >> 8) & 0xFF; - trailer[6] = (char) (stream.total_in >> 16) & 0xFF; - trailer[7] = (char) (stream.total_in >> 24) & 0xFF; - trailer[8] = '\0'; - } else { - s2[stream.total_out + GZIP_HEADER_LENGTH + (coding == CODING_GZIP ? GZIP_FOOTER_LENGTH : 0)] = '\0'; - } - RETURN_STRINGL(s2, stream.total_out + GZIP_HEADER_LENGTH + (coding == CODING_GZIP ? GZIP_FOOTER_LENGTH : 0), 0); - } else { - efree(s2); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status)); - RETURN_FALSE; - } + return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); } /* }}} */ - -/* {{{ php_ob_gzhandler_check - */ -int php_ob_gzhandler_check(TSRMLS_D) -{ - /* check for wrong usages */ - if (OG(ob_nesting_level > 0)) { - if (php_ob_handler_used("ob_gzhandler" TSRMLS_CC)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "output handler 'ob_gzhandler' cannot be used twice"); - return FAILURE; - } - if (php_ob_handler_used("mb_output_handler" TSRMLS_CC)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "output handler 'ob_gzhandler' cannot be used after 'mb_output_handler'"); - return FAILURE; - } - if (php_ob_handler_used("URL-Rewriter" TSRMLS_CC)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "output handler 'ob_gzhandler' cannot be used after 'URL-Rewriter'"); - return FAILURE; - } - if (php_ob_init_conflict("ob_gzhandler", "zlib output compression" TSRMLS_CC)) { - return FAILURE; - } - } - - return SUCCESS; -} + +/* {{{ INI */ +PHP_INI_BEGIN() + STD_PHP_INI_BOOLEAN("zlib.output_compression", "0", PHP_INI_ALL, OnUpdate_zlib_output_compression, output_compression, zend_zlib_globals, zlib_globals) + STD_PHP_INI_ENTRY("zlib.output_compression_level", "-1", PHP_INI_ALL, OnUpdateLong, output_compression_level, zend_zlib_globals, zlib_globals) + STD_PHP_INI_ENTRY("zlib.output_handler", "", PHP_INI_ALL, OnUpdate_zlib_output_handler, output_handler, zend_zlib_globals, zlib_globals) +PHP_INI_END() /* }}} */ -/* {{{ proto string ob_gzhandler(string str, int mode) - Encode str based on accept-encoding setting - designed to be called from ob_start() */ -static PHP_FUNCTION(ob_gzhandler) +/* {{{ PHP_MINIT_FUNCTION */ +static PHP_MINIT_FUNCTION(zlib) { - char *string; - int string_len; - long mode; - zval **a_encoding; - zend_bool return_original = 0; - zend_bool do_start, do_end; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &string, &string_len, &mode) == FAILURE) { - return; - } - - if (ZLIBG(ob_gzhandler_status) == -1) { - RETURN_FALSE; - } - - zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC); - - if (!PG(http_globals)[TRACK_VARS_SERVER] - || zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING"), (void **) &a_encoding) == FAILURE - ) { - ZLIBG(ob_gzhandler_status) = -1; - RETURN_FALSE; - } + php_register_url_stream_wrapper("compress.zlib", &php_stream_gzip_wrapper TSRMLS_CC); + php_stream_filter_register_factory("zlib.*", &php_zlib_filter_factory TSRMLS_CC); - convert_to_string_ex(a_encoding); - if (php_memnstr(Z_STRVAL_PP(a_encoding), "gzip", 4, Z_STRVAL_PP(a_encoding) + Z_STRLEN_PP(a_encoding))) { - ZLIBG(compression_coding) = CODING_GZIP; - } else if (php_memnstr(Z_STRVAL_PP(a_encoding), "deflate", 7, Z_STRVAL_PP(a_encoding) + Z_STRLEN_PP(a_encoding))) { - ZLIBG(compression_coding) = CODING_DEFLATE; - } else { - ZLIBG(ob_gzhandler_status) = -1; - RETURN_FALSE; - } + php_output_handler_alias_register(ZEND_STRL("ob_gzhandler"), php_zlib_output_handler_init); + php_output_handler_conflict_register(ZEND_STRL("ob_gzhandler"), php_zlib_output_conflict_check); + php_output_handler_conflict_register(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME), php_zlib_output_conflict_check); - do_start = ((mode & PHP_OUTPUT_HANDLER_START) ? 1 : 0); - do_end = ((mode & PHP_OUTPUT_HANDLER_END) ? 1 : 0); - Z_STRVAL_P(return_value) = NULL; - Z_STRLEN_P(return_value) = 0; + REGISTER_LONG_CONSTANT("FORCE_GZIP", PHP_ZLIB_ENCODING_GZIP, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("FORCE_DEFLATE", PHP_ZLIB_ENCODING_DEFLATE, CONST_CS|CONST_PERSISTENT); - if (php_deflate_string(string, string_len, &Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value), do_start, do_end TSRMLS_CC) == SUCCESS) { - Z_TYPE_P(return_value) = IS_STRING; - if (do_start) { - switch (ZLIBG(compression_coding)) { - case CODING_GZIP: - if (sapi_add_header("Content-Encoding: gzip", sizeof("Content-Encoding: gzip") - 1, 1) == FAILURE) { - return_original = 1; - } - if (sapi_add_header_ex("Vary: Accept-Encoding", sizeof("Vary: Accept-Encoding") - 1, 1, 0 TSRMLS_CC)==FAILURE) { - return_original = 1; - } - break; - case CODING_DEFLATE: - if (sapi_add_header("Content-Encoding: deflate", sizeof("Content-Encoding: deflate") - 1, 1) == FAILURE) { - return_original = 1; - } - if (sapi_add_header_ex("Vary: Accept-Encoding", sizeof("Vary: Accept-Encoding") - 1, 1, 0 TSRMLS_CC)==FAILURE) { - return_original = 1; - } - break; - default: - return_original = 1; - break; - } - } - - if (return_original) { - zval_dtor(return_value); - } - - } else { - return_original = 1; - } + REGISTER_LONG_CONSTANT("ZLIB_ENCODING_RAW", PHP_ZLIB_ENCODING_RAW, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("ZLIB_ENCODING_GZIP", PHP_ZLIB_ENCODING_GZIP, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("ZLIB_ENCODING_DEFLATE", PHP_ZLIB_ENCODING_DEFLATE, CONST_CS|CONST_PERSISTENT); + REGISTER_INI_ENTRIES(); - if (return_original) { - /* return the original string */ - RETURN_STRINGL(string, string_len, 1); - } + return SUCCESS; } /* }}} */ -/* {{{ php_gzip_output_handler - */ -static void php_gzip_output_handler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC) +/* {{{ PHP_MSHUTDOWN_FUNCTION */ +static PHP_MSHUTDOWN_FUNCTION(zlib) { - zend_bool do_start, do_end; + php_unregister_url_stream_wrapper("zlib" TSRMLS_CC); + php_stream_filter_unregister_factory("zlib.*" TSRMLS_CC); - if (!ZLIBG(output_compression) || SG(sapi_headers).http_response_code == 204 || SG(sapi_headers).http_response_code == 304) { - *handled_output = NULL; - } else { - do_start = (mode & PHP_OUTPUT_HANDLER_START ? 1 : 0); - do_end = (mode & PHP_OUTPUT_HANDLER_END ? 1 : 0); - - if (do_start) { - if (!SG(headers_sent) && !SG(request_info).no_headers) { - switch (ZLIBG(compression_coding)) { - case CODING_GZIP: - sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1 TSRMLS_CC); - break; - case CODING_DEFLATE: - sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1 TSRMLS_CC); - break; - } - sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0 TSRMLS_CC); - } else { - /* Disable compression if headers can not be set (Fix for bug #49816) */ - ZLIBG(output_compression) = 0; - *handled_output = NULL; - return; - } - } + UNREGISTER_INI_ENTRIES(); - if (php_deflate_string(output, output_len, handled_output, handled_output_len, do_start, do_end TSRMLS_CC) != SUCCESS) { - zend_error(E_ERROR, "Compression failed"); - } - } + return SUCCESS; } /* }}} */ -/* {{{ php_enable_output_compression - */ -static int php_enable_output_compression(int buffer_size TSRMLS_DC) +/* {{{ PHP_RINIT_FUNCTION */ +static PHP_RINIT_FUNCTION(zlib) { - zval **a_encoding; - - zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC); - - if (!PG(http_globals)[TRACK_VARS_SERVER] - || zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING"), (void **) &a_encoding) == FAILURE - ) { - return FAILURE; - } - - convert_to_string_ex(a_encoding); - - if (php_memnstr(Z_STRVAL_PP(a_encoding), "gzip", 4, Z_STRVAL_PP(a_encoding) + Z_STRLEN_PP(a_encoding))) { - ZLIBG(compression_coding) = CODING_GZIP; - } else if (php_memnstr(Z_STRVAL_PP(a_encoding), "deflate", 7, Z_STRVAL_PP(a_encoding) + Z_STRLEN_PP(a_encoding))) { - ZLIBG(compression_coding) = CODING_DEFLATE; - } else { - return FAILURE; - } + ZLIBG(compression_coding) = 0; - php_ob_set_internal_handler(php_gzip_output_handler, (uint)buffer_size, "zlib output compression", 0 TSRMLS_CC); + php_zlib_output_compression_start(TSRMLS_C); - if (ZLIBG(output_handler) && strlen(ZLIBG(output_handler))) { - php_start_ob_buffer_named(ZLIBG(output_handler), 0, 1 TSRMLS_CC); - } return SUCCESS; } /* }}} */ -/* {{{ php_zlib_output_compression_start() */ -static int php_zlib_output_compression_start(TSRMLS_D) +/* {{{ PHP_MINFO_FUNCTION */ +static PHP_MINFO_FUNCTION(zlib) { - switch (ZLIBG(output_compression)) { - case 0: - break; - case 1: - ZLIBG(output_compression) = 4096; - /* break omitted intentionally */ - default: - /* ZLIBG(compression_coding) should be 0 when zlib compression hasn't been started yet.. */ - if (ZLIBG(compression_coding) == 0) { - return php_enable_output_compression(ZLIBG(output_compression) TSRMLS_CC); - } - } - return SUCCESS; + php_info_print_table_start(); + php_info_print_table_header(2, "ZLib Support", "enabled"); + php_info_print_table_row(2, "Stream Wrapper", "compress.zlib://"); + php_info_print_table_row(2, "Stream Filter", "zlib.inflate, zlib.deflate"); + php_info_print_table_row(2, "Compiled Version", ZLIB_VERSION); + php_info_print_table_row(2, "Linked Version", (char *) zlibVersion()); + php_info_print_table_end(); + + DISPLAY_INI_ENTRIES(); } /* }}} */ +/* {{{ php_zlib_module_entry */ +zend_module_entry php_zlib_module_entry = { + STANDARD_MODULE_HEADER, + "zlib", + php_zlib_functions, + PHP_MINIT(zlib), + PHP_MSHUTDOWN(zlib), + PHP_RINIT(zlib), + NULL, + PHP_MINFO(zlib), + "2.0", + PHP_MODULE_GLOBALS(zlib), + NULL, + NULL, + NULL, + STANDARD_MODULE_PROPERTIES_EX +}; +/* }}} */ + /* * Local variables: * tab-width: 4 diff --git a/ext/zlib/zlib_filter.c b/ext/zlib/zlib_filter.c index 4990cf0e1a..0f6c056390 100644 --- a/ext/zlib/zlib_filter.c +++ b/ext/zlib/zlib_filter.c @@ -80,8 +80,11 @@ static php_stream_filter_status_t php_zlib_inflate_filter( while (buckets_in->head) { size_t bin = 0, desired; + bucket = buckets_in->head; + bucket = php_stream_bucket_make_writeable(buckets_in->head TSRMLS_CC); - while (bin < bucket->buflen) { + + while (bin < (unsigned int) bucket->buflen) { if (data->finished) { consumed += bucket->buflen; @@ -107,7 +110,6 @@ static php_stream_filter_status_t php_zlib_inflate_filter( desired -= data->strm.avail_in; /* desired becomes what we consumed this round through */ data->strm.next_in = data->inbuf; data->strm.avail_in = 0; - consumed += desired; bin += desired; if (data->strm.avail_out < data->outbuf_len) { @@ -123,7 +125,9 @@ static php_stream_filter_status_t php_zlib_inflate_filter( php_stream_bucket_delref(bucket TSRMLS_CC); return PSFS_PASS_ON; } + } + consumed += bucket->buflen; php_stream_bucket_delref(bucket TSRMLS_CC); } @@ -202,9 +206,11 @@ static php_stream_filter_status_t php_zlib_deflate_filter( while (buckets_in->head) { size_t bin = 0, desired; - bucket = php_stream_bucket_make_writeable(buckets_in->head TSRMLS_CC); + bucket = buckets_in->head; + + bucket = php_stream_bucket_make_writeable(bucket TSRMLS_CC); - while (bin < bucket->buflen) { + while (bin < (unsigned int) bucket->buflen) { desired = bucket->buflen - bin; if (desired > data->inbuf_len) { desired = data->inbuf_len; @@ -221,7 +227,6 @@ static php_stream_filter_status_t php_zlib_deflate_filter( desired -= data->strm.avail_in; /* desired becomes what we consumed this round through */ data->strm.next_in = data->inbuf; data->strm.avail_in = 0; - consumed += desired; bin += desired; if (data->strm.avail_out < data->outbuf_len) { @@ -235,6 +240,7 @@ static php_stream_filter_status_t php_zlib_deflate_filter( exit_status = PSFS_PASS_ON; } } + consumed += bucket->buflen; php_stream_bucket_delref(bucket TSRMLS_CC); } @@ -258,6 +264,7 @@ static php_stream_filter_status_t php_zlib_deflate_filter( if (bytes_consumed) { *bytes_consumed = consumed; } + return exit_status; } @@ -291,7 +298,7 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f /* Create this filter */ data = pecalloc(1, sizeof(php_zlib_filter_data), persistent); if (!data) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zd bytes.", sizeof(php_zlib_filter_data)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zd bytes", sizeof(php_zlib_filter_data)); return NULL; } @@ -303,14 +310,14 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f data->strm.avail_out = data->outbuf_len = data->inbuf_len = 2048; data->strm.next_in = data->inbuf = (Bytef *) pemalloc(data->inbuf_len, persistent); if (!data->inbuf) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zd bytes.", data->inbuf_len); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zd bytes", data->inbuf_len); pefree(data, persistent); return NULL; } data->strm.avail_in = 0; data->strm.next_out = data->outbuf = (Bytef *) pemalloc(data->outbuf_len, persistent); if (!data->outbuf) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zd bytes.", data->outbuf_len); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zd bytes", data->outbuf_len); pefree(data->inbuf, persistent); pefree(data, persistent); return NULL; @@ -409,7 +416,7 @@ factory_setlevel: } break; default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid filter parameter, ignored."); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid filter parameter, ignored"); } } status = deflateInit2(&(data->strm), level, Z_DEFLATED, windowBits, memLevel, 0); diff --git a/ext/zlib/zlib_fopen_wrapper.c b/ext/zlib/zlib_fopen_wrapper.c index 8970c55a00..c8b4263927 100644 --- a/ext/zlib/zlib_fopen_wrapper.c +++ b/ext/zlib/zlib_fopen_wrapper.c @@ -96,7 +96,7 @@ static int php_gziop_flush(php_stream *stream TSRMLS_DC) return gzflush(self->gz_file, Z_SYNC_FLUSH); } -static php_stream_ops php_stream_gzio_ops = { +php_stream_ops php_stream_gzio_ops = { php_gziop_write, php_gziop_read, php_gziop_close, php_gziop_flush, "ZLIB", |