diff options
Diffstat (limited to 'ext/zlib')
41 files changed, 1184 insertions, 422 deletions
diff --git a/ext/zlib/config.w32 b/ext/zlib/config.w32 index 000b1ccabb..820025aa7f 100644 --- a/ext/zlib/config.w32 +++ b/ext/zlib/config.w32 @@ -7,7 +7,7 @@ if (PHP_ZLIB == "yes") { if (CHECK_LIB("zlib_a.lib;zlib.lib", "zlib", PHP_ZLIB) && CHECK_HEADER_ADD_INCLUDE("zlib.h", "CFLAGS", "..\\zlib;" + php_usual_include_suspects)) { - EXTENSION("zlib", "zlib.c zlib_fopen_wrapper.c zlib_filter.c", null, "/D ZLIB_EXPORTS"); + EXTENSION("zlib", "zlib.c zlib_fopen_wrapper.c zlib_filter.c", PHP_ZLIB_SHARED, "/D ZLIB_EXPORTS /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); AC_DEFINE("HAVE_ZLIB", 1, "ZLIB support"); if (!PHP_ZLIB_SHARED) { diff --git a/ext/zlib/config0.m4 b/ext/zlib/config0.m4 index ebf67cc001..ab94c15fe0 100644 --- a/ext/zlib/config0.m4 +++ b/ext/zlib/config0.m4 @@ -9,7 +9,7 @@ PHP_ARG_WITH(zlib-dir,if the location of ZLIB install directory is defined, [ --with-zlib-dir=<DIR> Define the location of zlib install directory], no, no) if test "$PHP_ZLIB" != "no" || test "$PHP_ZLIB_DIR" != "no"; then - PHP_NEW_EXTENSION(zlib, zlib.c zlib_fopen_wrapper.c zlib_filter.c, $ext_shared) + PHP_NEW_EXTENSION(zlib, zlib.c zlib_fopen_wrapper.c zlib_filter.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) PHP_SUBST(ZLIB_SHARED_LIBADD) if test "$PHP_ZLIB" != "yes" -a "$PHP_ZLIB" != "no"; then diff --git a/ext/zlib/package.xml b/ext/zlib/package.xml index 4be42e0936..7eb9fa0936 100644 --- a/ext/zlib/package.xml +++ b/ext/zlib/package.xml @@ -50,7 +50,6 @@ package.xml added to support installation using pear installer <file role="src" name="config.w32"/> <file role="src" name="php_zlib.h"/> <file role="src" name="zlib.c"/> - <file role="src" name="zlib.dsp"/> <file role="src" name="zlib_fopen_wrapper.c"/> <file role="src" name="php_zlib.def"/> <file role="test" name="tests/001.phpt"/> diff --git a/ext/zlib/php_zlib.h b/ext/zlib/php_zlib.h index 7e27c8b894..c24f32e007 100644 --- a/ext/zlib/php_zlib.h +++ b/ext/zlib/php_zlib.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -23,6 +23,9 @@ #ifndef PHP_ZLIB_H #define PHP_ZLIB_H +#include "php_version.h" +#define PHP_ZLIB_VERSION PHP_VERSION + #include <zlib.h> #define PHP_ZLIB_ENCODING_RAW -0xf @@ -44,21 +47,25 @@ typedef struct _php_zlib_buffer { typedef struct _php_zlib_context { z_stream Z; + char *inflateDict; + size_t inflateDictlen; php_zlib_buffer buffer; } php_zlib_context; ZEND_BEGIN_MODULE_GLOBALS(zlib) /* variables for transparent gzip encoding */ - int compression_coding; - long output_compression; - long output_compression_level; + zend_long output_compression; + zend_long output_compression_level; char *output_handler; php_zlib_context *ob_gzhandler; - long output_compression_default; - zend_bool handler_registered; + zend_long output_compression_default; + zend_bool handler_registered; + int compression_coding; ZEND_END_MODULE_GLOBALS(zlib); -php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); +#define ZLIBG(v) ZEND_MODULE_GLOBALS_ACCESSOR(zlib, v) + +php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_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; @@ -66,13 +73,6 @@ 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 -# include "TSRM.h" -# define ZLIBG(v) TSRMG(zlib_globals_id, zend_zlib_globals *, v) -#else -# define ZLIBG(v) (zlib_globals.v) -#endif - #endif /* PHP_ZLIB_H */ /* diff --git a/ext/zlib/tests/deflate_add_basic.phpt b/ext/zlib/tests/deflate_add_basic.phpt new file mode 100644 index 0000000000..05fcb037bd --- /dev/null +++ b/ext/zlib/tests/deflate_add_basic.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test incremental deflate_add() functionality +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) { + print "skip - ZLIB extension not loaded"; +} +?> +--FILE-- +<?php + +function deflateStream($mode, $flushSize, $flushType) { + $buffer = ""; + $deflated = null; + $resource = deflate_init($mode); + + while (true) { + $dataToCompress = yield $deflated; + if (isset($dataToCompress)) { + $buffer .= $dataToCompress; + if (strlen($buffer) >= $flushSize) { + $deflated = deflate_add($resource, $buffer, $flushType); + $buffer = ""; + } else { + $deflated = null; + } + } else { + $deflated = deflate_add($resource, $buffer, ZLIB_FINISH); + } + } +} + +$modes = [ + 'ZLIB_ENCODING_RAW' => ZLIB_ENCODING_RAW, + 'ZLIB_ENCODING_GZIP' => ZLIB_ENCODING_GZIP, + 'ZLIB_ENCODING_DEFLATE' => ZLIB_ENCODING_DEFLATE, +]; +$flushSizes = [1, 4, 32768]; +$flushTypes = [ + 'ZLIB_SYNC_FLUSH' => ZLIB_SYNC_FLUSH, + 'ZLIB_PARTIAL_FLUSH' => ZLIB_PARTIAL_FLUSH, + 'ZLIB_FULL_FLUSH' => ZLIB_FULL_FLUSH, + 'ZLIB_NO_FLUSH' => ZLIB_NO_FLUSH, +]; + +/* Z_BLOCK is only available for deflate when built against zlib >= 1.2.4 */ +if (ZLIB_VERNUM >= 0x1240) { + $flushTypes['ZLIB_BLOCK'] = ZLIB_BLOCK; +} + +foreach ($modes as $modeKey => $mode) { + foreach ($flushSizes as $flushSize) { + foreach ($flushTypes as $flushTypeKey => $flushType) { + $uncompressed = $compressed = ""; + $stream = deflateStream($mode, $flushSize, $flushType); + foreach (range("a", "z") as $c) { + $uncompressed .= $c; + $compressed .= $stream->send($c); + } + $compressed .= $stream->send(null); + if ($uncompressed !== zlib_decode($compressed)) { + echo "Error: {$modeKey} | {$flushSize} | {$flushTypeKey}\n"; + } + } + } +} +?> +===DONE=== +--EXPECTF-- +===DONE=== diff --git a/ext/zlib/tests/deflate_add_block_v123.phpt b/ext/zlib/tests/deflate_add_block_v123.phpt new file mode 100644 index 0000000000..3fe03f99ba --- /dev/null +++ b/ext/zlib/tests/deflate_add_block_v123.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test deflate_add() errors with ZLIB_BLOCK in zlib < 1.2.4 +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) { + print "skip - ZLIB extension not loaded"; +} +if (ZLIB_VERNUM >= 0x1240) { + print "skip - ZLIB < 1.2.4 required for test"; +} +?> +--FILE-- +<?php + +$resource = deflate_init(ZLIB_ENCODING_GZIP); +var_dump(deflate_add($resource, "aaaaaaaaaaaaaaaaaaaaaa", ZLIB_BLOCK)); + +?> +===DONE=== +--EXPECTF-- + +Warning: deflate_add(): zlib >= 1.2.4 required for BLOCK deflate; current version: %s in %s on line %d +bool(false) +===DONE=== diff --git a/ext/zlib/tests/deflate_add_error.phpt b/ext/zlib/tests/deflate_add_error.phpt new file mode 100644 index 0000000000..159f1648c9 --- /dev/null +++ b/ext/zlib/tests/deflate_add_error.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test incremental deflate_add() error functionality +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) { + print "skip - ZLIB extension not loaded"; +} +?> +--FILE-- +<?php +$badResource = fopen("php://memory", "r+"); +var_dump(deflate_add($badResource, "test")); + +$resource = deflate_init(ZLIB_ENCODING_DEFLATE); +$badFlushType = 6789; +var_dump(deflate_add($resource, "test", $badFlushType)); +?> +--EXPECTF-- + +Warning: deflate_add(): Invalid deflate resource in %s on line %d +bool(false) + +Warning: deflate_add(): flush mode must be ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK or ZLIB_FINISH in %s on line %d +bool(false) diff --git a/ext/zlib/tests/deflate_init_error.phpt b/ext/zlib/tests/deflate_init_error.phpt new file mode 100644 index 0000000000..424272c124 --- /dev/null +++ b/ext/zlib/tests/deflate_init_error.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test deflate_init() error +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) { + print "skip - ZLIB extension not loaded"; +} +?> +--FILE-- +<?php +var_dump(deflate_init(42)); +var_dump(deflate_init(ZLIB_ENCODING_DEFLATE, ['level' => 42])); +var_dump(deflate_init(ZLIB_ENCODING_DEFLATE, ['level' => -2])); +var_dump(deflate_init(ZLIB_ENCODING_DEFLATE, ['memory' => 0])); +var_dump(deflate_init(ZLIB_ENCODING_DEFLATE, ['memory' => 10])); +?> +--EXPECTF-- + +Warning: deflate_init(): encoding mode must be ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d +bool(false) + +Warning: deflate_init(): compression level (42) must be within -1..9 in %s on line %d +bool(false) + +Warning: deflate_init(): compression level (-2) must be within -1..9 in %s on line %d +bool(false) + +Warning: deflate_init(): compression memory level (0) must be within 1..9 in %s on line %d +bool(false) + +Warning: deflate_init(): compression memory level (10) must be within 1..9 in %s on line %d +bool(false) diff --git a/ext/zlib/tests/deflate_init_reuse.phpt b/ext/zlib/tests/deflate_init_reuse.phpt new file mode 100644 index 0000000000..b351f496f7 --- /dev/null +++ b/ext/zlib/tests/deflate_init_reuse.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test incremental deflate_init() context reuse +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) { + print "skip - ZLIB extension not loaded"; +} +?> +--FILE-- +<?php +$resource = deflate_init(ZLIB_ENCODING_DEFLATE); +foreach (range("a", "z") as $char) { + deflate_add($resource, $char); +} +deflate_add($resource, "", ZLIB_FINISH); + +// Now reuse the existing resource after finishing the previous operations ... +$uncompressed = $compressed = ""; +foreach (range("a", "z") as $char) { + $uncompressed .= $char; + $compressed .= deflate_add($resource, $char, ZLIB_NO_FLUSH); +} +$compressed .= deflate_add($resource, "", ZLIB_FINISH); +assert($uncompressed === zlib_decode($compressed)); +?> +===DONE=== +--EXPECTF-- +===DONE=== diff --git a/ext/zlib/tests/dictionary_usage.phpt b/ext/zlib/tests/dictionary_usage.phpt new file mode 100644 index 0000000000..f7ef3b3a9c --- /dev/null +++ b/ext/zlib/tests/dictionary_usage.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test dictionary usage on zlib methods +--FILE-- +<?php + +$dict = range("a", "z"); + +$r = deflate_init(ZLIB_ENCODING_DEFLATE, ["dictionary" => $dict]); +$a = deflate_add($r, "abdcde", ZLIB_FINISH); +var_dump($a); + +$r = deflate_init(ZLIB_ENCODING_DEFLATE, ["dictionary" => implode("\0", $dict)."\0"]); +$dictStr_a = deflate_add($r, "abdcde", ZLIB_FINISH); +var_dump($dictStr_a === $a); + +$r = inflate_init(ZLIB_ENCODING_DEFLATE, ["dictionary" => $dict]); +var_dump(inflate_add($r, $a, ZLIB_FINISH)); + + +$r = inflate_init(ZLIB_ENCODING_DEFLATE, ["dictionary" => ["8"] + range("a", "z")]); +var_dump(inflate_add($r, $a, ZLIB_FINISH)); + +?> +--EXPECTF-- +string(%d) "%s" +bool(true) +string(6) "abdcde" + +Warning: inflate_add(): dictionary does not match expected dictionary (incorrect adler32 hash) in %s on line %d +bool(false) diff --git a/ext/zlib/tests/gzclose_basic.phpt b/ext/zlib/tests/gzclose_basic.phpt index d61855bf9f..acad3b2f07 100644 --- a/ext/zlib/tests/gzclose_basic.phpt +++ b/ext/zlib/tests/gzclose_basic.phpt @@ -32,8 +32,8 @@ gzread($h, 20); --EXPECTF-- bool(true) -Warning: gzread(): %d is not a valid stream resource in %s on line %d +Warning: gzread(): supplied resource is not a valid stream resource in %s on line %d bool(true) -Warning: gzread(): %d is not a valid stream resource in %s on line %d +Warning: gzread(): supplied resource is not a valid stream resource in %s on line %d ===DONE=== diff --git a/ext/zlib/tests/gzdeflate_error1.phpt b/ext/zlib/tests/gzdeflate_error1.phpt index 8abd5bec25..740054269f 100644 --- a/ext/zlib/tests/gzdeflate_error1.phpt +++ b/ext/zlib/tests/gzdeflate_error1.phpt @@ -81,6 +81,6 @@ bool(false) Warning: gzdeflate() expects parameter 1 to be string, object given in %s on line %d NULL -Warning: gzdeflate() expects parameter 2 to be long, object given in %s on line %d +Warning: gzdeflate() expects parameter 2 to be integer, object given in %s on line %d NULL ===Done=== diff --git a/ext/zlib/tests/gzencode_error1.phpt b/ext/zlib/tests/gzencode_error1.phpt index 9ecf4b8f08..5a16ffbc5f 100644 --- a/ext/zlib/tests/gzencode_error1.phpt +++ b/ext/zlib/tests/gzencode_error1.phpt @@ -84,15 +84,15 @@ bool(false) Warning: gzencode() expects parameter 1 to be string, object given in %s on line %d NULL -Warning: gzencode() expects parameter 2 to be long, object given in %s on line %d +Warning: gzencode() expects parameter 2 to be integer, object given in %s on line %d NULL 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 +Warning: gzencode() expects parameter 3 to be integer, object given in %s on line %d NULL -Warning: gzencode() expects parameter 2 to be long, string given in %s on line %d +Warning: gzencode() expects parameter 2 to be integer, string given in %s on line %d NULL ===Done=== diff --git a/ext/zlib/tests/gzeof_variation1.phpt b/ext/zlib/tests/gzeof_variation1.phpt index 77a1eccb66..ba0d8e5932 100644 --- a/ext/zlib/tests/gzeof_variation1.phpt +++ b/ext/zlib/tests/gzeof_variation1.phpt @@ -26,6 +26,6 @@ unlink($filename); bool(false) bool(false) -Warning: gzeof(): %d is not a valid stream resource in %s on line %d +Warning: gzeof(): supplied resource is not a valid stream resource in %s on line %d bool(false) -===DONE===
\ No newline at end of file +===DONE=== diff --git a/ext/zlib/tests/gzfile_variation10.phpt b/ext/zlib/tests/gzfile_variation10.phpt index 20de8cb535..145e4c53ca 100644 --- a/ext/zlib/tests/gzfile_variation10.phpt +++ b/ext/zlib/tests/gzfile_variation10.phpt @@ -71,10 +71,10 @@ array(6) { " } -Warning: gzfile() expects parameter 2 to be long, string given in %s on line %d +Warning: gzfile() expects parameter 2 to be integer, string given in %s on line %d NULL -Warning: gzfile() expects parameter 2 to be long, string given in %s on line %d +Warning: gzfile() expects parameter 2 to be integer, string given in %s on line %d NULL array(6) { [0]=> diff --git a/ext/zlib/tests/gzfile_variation11.phpt b/ext/zlib/tests/gzfile_variation11.phpt index a3585e5420..ba25bf570f 100644 --- a/ext/zlib/tests/gzfile_variation11.phpt +++ b/ext/zlib/tests/gzfile_variation11.phpt @@ -3,6 +3,7 @@ Test function gzfile() by substituting argument 2 with float values. --SKIPIF-- <?php if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build'); +if (PHP_INT_SIZE != 8) die('skip 64-bit only'); ?> --FILE-- <?php @@ -126,4 +127,4 @@ array(6) { string(39) "and I know that it descends down on me " } -===DONE===
\ No newline at end of file +===DONE=== diff --git a/ext/zlib/tests/gzfile_variation13.phpt b/ext/zlib/tests/gzfile_variation13.phpt index 4198c474df..24f3c84451 100644 --- a/ext/zlib/tests/gzfile_variation13.phpt +++ b/ext/zlib/tests/gzfile_variation13.phpt @@ -44,8 +44,8 @@ foreach ( $variation as $var ) { ?> ===DONE=== --EXPECTF-- -Error: 2 - gzfile() expects parameter 2 to be long, object given, %s(%d) +Error: 2 - gzfile() expects parameter 2 to be integer, object given, %s(%d) NULL -Error: 2 - gzfile() expects parameter 2 to be long, object given, %s(%d) +Error: 2 - gzfile() expects parameter 2 to be integer, object given, %s(%d) NULL ===DONE===
\ No newline at end of file diff --git a/ext/zlib/tests/gzfile_variation14.phpt b/ext/zlib/tests/gzfile_variation14.phpt index 7462bea809..92547adb7c 100644 --- a/ext/zlib/tests/gzfile_variation14.phpt +++ b/ext/zlib/tests/gzfile_variation14.phpt @@ -30,15 +30,15 @@ foreach ( $variation_array as $var ) { ===DONE=== --EXPECTF-- -Warning: gzfile() expects parameter 2 to be long, string given in %s on line %d +Warning: gzfile() expects parameter 2 to be integer, string given in %s on line %d NULL -Warning: gzfile() expects parameter 2 to be long, string given in %s on line %d +Warning: gzfile() expects parameter 2 to be integer, string given in %s on line %d NULL -Warning: gzfile() expects parameter 2 to be long, string given in %s on line %d +Warning: gzfile() expects parameter 2 to be integer, string given in %s on line %d NULL -Warning: gzfile() expects parameter 2 to be long, string given in %s on line %d +Warning: gzfile() expects parameter 2 to be integer, string given in %s on line %d NULL ===DONE===
\ No newline at end of file diff --git a/ext/zlib/tests/gzfile_variation2.phpt b/ext/zlib/tests/gzfile_variation2.phpt index ba487435cd..36d1d4c71b 100644 --- a/ext/zlib/tests/gzfile_variation2.phpt +++ b/ext/zlib/tests/gzfile_variation2.phpt @@ -26,15 +26,15 @@ foreach ( $variation as $var ) { ===DONE=== --EXPECTF-- -Warning: gzfile() expects parameter 2 to be long, array given in %s on line %d +Warning: gzfile() expects parameter 2 to be integer, array given in %s on line %d NULL -Warning: gzfile() expects parameter 2 to be long, array given in %s on line %d +Warning: gzfile() expects parameter 2 to be integer, array given in %s on line %d NULL -Warning: gzfile() expects parameter 2 to be long, array given in %s on line %d +Warning: gzfile() expects parameter 2 to be integer, array given in %s on line %d NULL -Warning: gzfile() expects parameter 2 to be long, array given in %s on line %d +Warning: gzfile() expects parameter 2 to be integer, array given in %s on line %d NULL ===DONE===
\ No newline at end of file diff --git a/ext/zlib/tests/gzfile_variation8.phpt b/ext/zlib/tests/gzfile_variation8.phpt index 50d042218c..070fa30e40 100644 --- a/ext/zlib/tests/gzfile_variation8.phpt +++ b/ext/zlib/tests/gzfile_variation8.phpt @@ -29,15 +29,15 @@ foreach ( $variation as $var ) { ===DONE=== --EXPECTF-- -Warning: gzfile() expects parameter 2 to be long, array given in %s on line %d +Warning: gzfile() expects parameter 2 to be integer, array given in %s on line %d NULL -Warning: gzfile() expects parameter 2 to be long, array given in %s on line %d +Warning: gzfile() expects parameter 2 to be integer, array given in %s on line %d NULL -Warning: gzfile() expects parameter 2 to be long, array given in %s on line %d +Warning: gzfile() expects parameter 2 to be integer, array given in %s on line %d NULL -Warning: gzfile() expects parameter 2 to be long, array given in %s on line %d +Warning: gzfile() expects parameter 2 to be integer, array given in %s on line %d NULL ===DONE===
\ No newline at end of file diff --git a/ext/zlib/tests/gzgetss.gz b/ext/zlib/tests/gzgetss.gz Binary files differnew file mode 100644 index 0000000000..f6c9f5cd10 --- /dev/null +++ b/ext/zlib/tests/gzgetss.gz diff --git a/ext/zlib/tests/gzgetss.phpt b/ext/zlib/tests/gzgetss.phpt new file mode 100644 index 0000000000..b0bdcb9c86 --- /dev/null +++ b/ext/zlib/tests/gzgetss.phpt @@ -0,0 +1,22 @@ +--TEST-- +gzgetss — Get line from gz-file pointer and strip HTML tags - function +--CREDITS-- +marcosptf - <marcosptf@yahoo.com.br> +--SKIPIF-- +<?php + +<?php +if(!extension_loaded("zlib")){die("skip - ZLIB extension not loaded");} +?> +--FILE-- +<?php +$handle = gzopen(__DIR__ . '/gzgetss.gz', 'r'); + +while (!gzeof($handle)){ + $buffer = gzgetss($handle, 4096, "<code>"); + print($buffer); +} +gzclose($handle); +?> +--EXPECT-- +<code>stringgzgetss(resource $zp, int $length [, string $allowable_tags ]);<code/>
\ No newline at end of file diff --git a/ext/zlib/tests/gzgetss.test b/ext/zlib/tests/gzgetss.test new file mode 100644 index 0000000000..37df4858df --- /dev/null +++ b/ext/zlib/tests/gzgetss.test @@ -0,0 +1,5 @@ +<div> + <p class="para rdfs-comment"> + <code><span class="type">string</span><span class="methodname"><strong>gzgetss</strong></span>(resource $zp, int $length [, string $allowable_tags ]);<code/> + </p> +</div>
\ No newline at end of file diff --git a/ext/zlib/tests/gzinflate_error1.phpt b/ext/zlib/tests/gzinflate_error1.phpt index 6dc8113645..822d9b8129 100644 --- a/ext/zlib/tests/gzinflate_error1.phpt +++ b/ext/zlib/tests/gzinflate_error1.phpt @@ -70,6 +70,6 @@ bool(false) Warning: gzinflate() expects parameter 1 to be string, object given in %s on line %d NULL -Warning: gzinflate() expects parameter 2 to be long, object given in %s on line %d +Warning: gzinflate() expects parameter 2 to be integer, object given in %s on line %d NULL ===DONE===
\ No newline at end of file diff --git a/ext/zlib/tests/gzopen_variation3.phpt b/ext/zlib/tests/gzopen_variation3.phpt index 59e45a893c..4ba607420d 100644 --- a/ext/zlib/tests/gzopen_variation3.phpt +++ b/ext/zlib/tests/gzopen_variation3.phpt @@ -4,7 +4,8 @@ Test gzopen() function : usage variation <?php if (!extension_loaded("zlib")) { print "skip - zlib extension not loaded"; -} +} +if (PHP_INT_SIZE != 8) die('skip 64-bit only'); ?> --FILE-- <?php @@ -141,19 +142,19 @@ resource(%d) of type (stream) resource(%d) of type (stream) --empty array-- -Error: 2 - gzopen() expects parameter 3 to be long, array given, %s(%d) +Error: 2 - gzopen() expects parameter 3 to be integer, array given, %s(%d) NULL --int indexed array-- -Error: 2 - gzopen() expects parameter 3 to be long, array given, %s(%d) +Error: 2 - gzopen() expects parameter 3 to be integer, array given, %s(%d) NULL --associative array-- -Error: 2 - gzopen() expects parameter 3 to be long, array given, %s(%d) +Error: 2 - gzopen() expects parameter 3 to be integer, array given, %s(%d) NULL --nested arrays-- -Error: 2 - gzopen() expects parameter 3 to be long, array given, %s(%d) +Error: 2 - gzopen() expects parameter 3 to be integer, array given, %s(%d) NULL --uppercase NULL-- @@ -175,35 +176,35 @@ resource(%d) of type (stream) resource(%d) of type (stream) --empty string DQ-- -Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d) +Error: 2 - gzopen() expects parameter 3 to be integer, string given, %s(%d) NULL --empty string SQ-- -Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d) +Error: 2 - gzopen() expects parameter 3 to be integer, string given, %s(%d) NULL --string DQ-- -Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d) +Error: 2 - gzopen() expects parameter 3 to be integer, string given, %s(%d) NULL --string SQ-- -Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d) +Error: 2 - gzopen() expects parameter 3 to be integer, string given, %s(%d) NULL --mixed case string-- -Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d) +Error: 2 - gzopen() expects parameter 3 to be integer, string given, %s(%d) NULL --heredoc-- -Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d) +Error: 2 - gzopen() expects parameter 3 to be integer, string given, %s(%d) NULL --instance of classWithToString-- -Error: 2 - gzopen() expects parameter 3 to be long, object given, %s(%d) +Error: 2 - gzopen() expects parameter 3 to be integer, object given, %s(%d) NULL --instance of classWithoutToString-- -Error: 2 - gzopen() expects parameter 3 to be long, object given, %s(%d) +Error: 2 - gzopen() expects parameter 3 to be integer, object given, %s(%d) NULL --undefined var-- @@ -213,6 +214,6 @@ resource(%d) of type (stream) resource(%d) of type (stream) --resource-- -Error: 2 - gzopen() expects parameter 3 to be long, resource given, %s(%d) +Error: 2 - gzopen() expects parameter 3 to be integer, resource given, %s(%d) NULL ===DONE=== diff --git a/ext/zlib/tests/gzuncompress_error1.phpt b/ext/zlib/tests/gzuncompress_error1.phpt index f26a4f5dcd..baf2527c14 100644 --- a/ext/zlib/tests/gzuncompress_error1.phpt +++ b/ext/zlib/tests/gzuncompress_error1.phpt @@ -75,6 +75,6 @@ bool(false) Warning: gzuncompress() expects parameter 1 to be string, object given in %s on line %d NULL -Warning: gzuncompress() expects parameter 2 to be long, string given in %s on line %d +Warning: gzuncompress() expects parameter 2 to be integer, string given in %s on line %d NULL ===DONE=== diff --git a/ext/zlib/tests/inflate_add_basic.phpt b/ext/zlib/tests/inflate_add_basic.phpt new file mode 100644 index 0000000000..ff0458e9ef --- /dev/null +++ b/ext/zlib/tests/inflate_add_basic.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test incremental inflate_add() functionality +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) { + print "skip - ZLIB extension not loaded"; +} +?> +--FILE-- +<?php +function inflateStream($mode, $flushSize) { + $buffer = ""; + $inflated = null; + $resource = inflate_init($mode); + + while (true) { + $dataToInflate = yield $inflated; + if (isset($dataToInflate)) { + $buffer .= $dataToInflate; + if (strlen($buffer) >= $flushSize) { + $inflated = inflate_add($resource, $buffer); + $buffer = ""; + } else { + $inflated = null; + } + } else { + $inflated = inflate_add($resource, $buffer, ZLIB_FINISH); + } + } +} + +$modes = [ + 'ZLIB_ENCODING_RAW' => ZLIB_ENCODING_RAW, + 'ZLIB_ENCODING_GZIP' => ZLIB_ENCODING_GZIP, + 'ZLIB_ENCODING_DEFLATE' => ZLIB_ENCODING_DEFLATE, +]; +$flushSizes = [1, 4, 32768]; +$flushTypes = [ + 'ZLIB_SYNC_FLUSH' => ZLIB_SYNC_FLUSH, + 'ZLIB_PARTIAL_FLUSH' => ZLIB_PARTIAL_FLUSH, + 'ZLIB_FULL_FLUSH' => ZLIB_FULL_FLUSH, + 'ZLIB_NO_FLUSH' => ZLIB_NO_FLUSH, + 'ZLIB_BLOCK' => ZLIB_BLOCK, +]; + +$uncompressed = ""; +for ($i=0;$i<(32768*2);$i++) { + $uncompressed .= chr(rand(48,125)); +} + +foreach ($modes as $modeKey => $mode) { + $compressed = zlib_encode($uncompressed, $mode); + $compressedLen = strlen($compressed); + foreach ($flushSizes as $flushSize) { + foreach ($flushTypes as $flushTypeKey => $flushType) { + $inflated = ""; + $stream = inflateStream($mode, $flushSize, $flushType); + for ($i=0;$i<$compressedLen;$i++) { + $inflated .= $stream->send($compressed[$i]); + } + $inflated .= $stream->send(null); + if ($inflated !== $uncompressed) { + echo "Error: {$modeKey} | {$flushSize} | {$flushTypeKey}\n"; + } + } + + } +} + +?> +===DONE=== +--EXPECTF-- +===DONE=== diff --git a/ext/zlib/tests/inflate_add_error.phpt b/ext/zlib/tests/inflate_add_error.phpt new file mode 100644 index 0000000000..0e1711e0f8 --- /dev/null +++ b/ext/zlib/tests/inflate_add_error.phpt @@ -0,0 +1,23 @@ +--TEST-- +Test incremental inflate_add() error functionality +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) { + print "skip - ZLIB extension not loaded"; +} +?> +--FILE-- +<?php +$badResource = fopen("php://memory", "r+"); +var_dump(inflate_add($badResource, "test")); +$resource = inflate_init(ZLIB_ENCODING_DEFLATE); +$badFlushType = 6789; +var_dump(inflate_add($resource, "test", $badFlushType)); +?> +--EXPECTF-- + +Warning: inflate_add(): Invalid zlib.inflate resource in %s on line %d +bool(false) + +Warning: inflate_add(): flush mode must be ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK or ZLIB_FINISH in %s on line %d +bool(false) diff --git a/ext/zlib/tests/inflate_init_error.phpt b/ext/zlib/tests/inflate_init_error.phpt new file mode 100644 index 0000000000..58c07a426c --- /dev/null +++ b/ext/zlib/tests/inflate_init_error.phpt @@ -0,0 +1,20 @@ +--TEST-- +Test inflate_init() error +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) { + print "skip - ZLIB extension not loaded"; +} +?> +--FILE-- +<?php +var_dump(inflate_init()); +var_dump(inflate_init(42)); +?> +--EXPECTF-- + +Warning: inflate_init() expects at least 1 parameter, 0 given in %s on line %d +NULL + +Warning: inflate_init(): encoding mode must be ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d +bool(false) diff --git a/ext/zlib/tests/inflate_init_reuse.phpt b/ext/zlib/tests/inflate_init_reuse.phpt new file mode 100644 index 0000000000..a6b8a309c0 --- /dev/null +++ b/ext/zlib/tests/inflate_init_reuse.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test incremental inflate_init() context reuse +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) { + print "skip - ZLIB extension not loaded"; +} +?> +--FILE-- +<?php +$resource = inflate_init(ZLIB_ENCODING_GZIP); + +$uncompressed = implode(range("a","z")); +$compressed = gzencode($uncompressed); +$inflated = ""; +for ($i=0;$i<strlen($compressed);$i++) { + $inflated .= inflate_add($resource, $compressed[$i]); +} +$inflated .= inflate_add($resource, "", ZLIB_FINISH); +assert($inflated === $uncompressed); + +// Now reuse the existing resource after finishing the previous operations ... +$inflated = ""; +for ($i=0;$i<strlen($compressed);$i++) { + $inflated .= inflate_add($resource, $compressed[$i]); +} +$inflated .= inflate_add($resource, "", ZLIB_FINISH); +assert($inflated === $uncompressed); +?> +===DONE=== +--EXPECTF-- +===DONE=== diff --git a/ext/zlib/tests/readgzfile_variation10.phpt b/ext/zlib/tests/readgzfile_variation10.phpt index bc6cc5b452..0f24c5efb2 100644 --- a/ext/zlib/tests/readgzfile_variation10.phpt +++ b/ext/zlib/tests/readgzfile_variation10.phpt @@ -45,10 +45,10 @@ as it turns around and I know that it descends down on me int(176) -Warning: readgzfile() expects parameter 2 to be long, string given in %s on line %d +Warning: readgzfile() expects parameter 2 to be integer, string given in %s on line %d NULL -Warning: readgzfile() expects parameter 2 to be long, string given in %s on line %d +Warning: readgzfile() expects parameter 2 to be integer, string given in %s on line %d NULL When you're taught through feelings Destiny flying high above diff --git a/ext/zlib/tests/readgzfile_variation11.phpt b/ext/zlib/tests/readgzfile_variation11.phpt index 01dc78721d..6dd9c2ff39 100644 --- a/ext/zlib/tests/readgzfile_variation11.phpt +++ b/ext/zlib/tests/readgzfile_variation11.phpt @@ -3,6 +3,7 @@ Test function readgzfile() by substituting argument 2 with float values. --SKIPIF-- <?php if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build'); +if (PHP_INT_SIZE != 8) die('skip 64-bit only'); ?> --FILE-- <?php @@ -61,4 +62,4 @@ Destiny who cares as it turns around and I know that it descends down on me int(176) -===DONE===
\ No newline at end of file +===DONE=== diff --git a/ext/zlib/tests/readgzfile_variation13.phpt b/ext/zlib/tests/readgzfile_variation13.phpt index db1bd892a5..d6c1fb4042 100644 --- a/ext/zlib/tests/readgzfile_variation13.phpt +++ b/ext/zlib/tests/readgzfile_variation13.phpt @@ -44,8 +44,8 @@ foreach ( $variation as $var ) { ?> ===DONE=== --EXPECTF-- -Error: 2 - readgzfile() expects parameter 2 to be long, object given, %s(%d) +Error: 2 - readgzfile() expects parameter 2 to be integer, object given, %s(%d) NULL -Error: 2 - readgzfile() expects parameter 2 to be long, object given, %s(%d) +Error: 2 - readgzfile() expects parameter 2 to be integer, object given, %s(%d) NULL ===DONE===
\ No newline at end of file diff --git a/ext/zlib/tests/readgzfile_variation14.phpt b/ext/zlib/tests/readgzfile_variation14.phpt index 90081a9465..08f62935bc 100644 --- a/ext/zlib/tests/readgzfile_variation14.phpt +++ b/ext/zlib/tests/readgzfile_variation14.phpt @@ -30,15 +30,15 @@ foreach ( $variation_array as $var ) { ===DONE=== --EXPECTF-- -Warning: readgzfile() expects parameter 2 to be long, string given in %s on line %d +Warning: readgzfile() expects parameter 2 to be integer, string given in %s on line %d NULL -Warning: readgzfile() expects parameter 2 to be long, string given in %s on line %d +Warning: readgzfile() expects parameter 2 to be integer, string given in %s on line %d NULL -Warning: readgzfile() expects parameter 2 to be long, string given in %s on line %d +Warning: readgzfile() expects parameter 2 to be integer, string given in %s on line %d NULL -Warning: readgzfile() expects parameter 2 to be long, string given in %s on line %d +Warning: readgzfile() expects parameter 2 to be integer, string given in %s on line %d NULL ===DONE=== diff --git a/ext/zlib/tests/readgzfile_variation2.phpt b/ext/zlib/tests/readgzfile_variation2.phpt index 53a9f3e31e..80cb728e93 100644 --- a/ext/zlib/tests/readgzfile_variation2.phpt +++ b/ext/zlib/tests/readgzfile_variation2.phpt @@ -26,15 +26,15 @@ foreach ( $variation as $var ) { ===DONE=== --EXPECTF-- -Warning: readgzfile() expects parameter 2 to be long, array given in %s on line %d +Warning: readgzfile() expects parameter 2 to be integer, array given in %s on line %d NULL -Warning: readgzfile() expects parameter 2 to be long, array given in %s on line %d +Warning: readgzfile() expects parameter 2 to be integer, array given in %s on line %d NULL -Warning: readgzfile() expects parameter 2 to be long, array given in %s on line %d +Warning: readgzfile() expects parameter 2 to be integer, array given in %s on line %d NULL -Warning: readgzfile() expects parameter 2 to be long, array given in %s on line %d +Warning: readgzfile() expects parameter 2 to be integer, array given in %s on line %d NULL ===DONE===
\ No newline at end of file diff --git a/ext/zlib/tests/readgzfile_variation8.phpt b/ext/zlib/tests/readgzfile_variation8.phpt index 291b69efcf..7242f19b22 100644 --- a/ext/zlib/tests/readgzfile_variation8.phpt +++ b/ext/zlib/tests/readgzfile_variation8.phpt @@ -29,15 +29,15 @@ foreach ( $variation as $var ) { ===DONE=== --EXPECTF-- -Warning: readgzfile() expects parameter 2 to be long, array given in %s on line %d +Warning: readgzfile() expects parameter 2 to be integer, array given in %s on line %d NULL -Warning: readgzfile() expects parameter 2 to be long, array given in %s on line %d +Warning: readgzfile() expects parameter 2 to be integer, array given in %s on line %d NULL -Warning: readgzfile() expects parameter 2 to be long, array given in %s on line %d +Warning: readgzfile() expects parameter 2 to be integer, array given in %s on line %d NULL -Warning: readgzfile() expects parameter 2 to be long, array given in %s on line %d +Warning: readgzfile() expects parameter 2 to be integer, array given in %s on line %d NULL ===DONE===
\ No newline at end of file diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 47dc3acf63..d9d6be1638 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -46,6 +46,9 @@ #undef gzseek #undef gztell +int le_deflate; +int le_inflate; + ZEND_DECLARE_MODULE_GLOBALS(zlib); /* {{{ Memory management wrappers */ @@ -61,14 +64,35 @@ static void php_zlib_free(voidpf opaque, voidpf address) } /* }}} */ +/* {{{ Incremental deflate/inflate resource destructors */ + +void deflate_rsrc_dtor(zend_resource *res) +{ + z_stream *ctx = zend_fetch_resource(res, NULL, le_deflate); + deflateEnd(ctx); + efree(ctx); +} + +void inflate_rsrc_dtor(zend_resource *res) +{ + z_stream *ctx = zend_fetch_resource(res, NULL, le_inflate); + if (((php_zlib_context *) ctx)->inflateDict) { + efree(((php_zlib_context *) ctx)->inflateDict); + } + inflateEnd(ctx); + efree(ctx); +} + +/* }}} */ + /* {{{ php_zlib_output_conflict_check() */ -static int php_zlib_output_conflict_check(const char *handler_name, size_t handler_name_len TSRMLS_DC) +static int php_zlib_output_conflict_check(const char *handler_name, size_t handler_name_len) { - 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)) { + if (php_output_get_level() > 0) { + if (php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME)) + || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("ob_gzhandler")) + || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("mb_output_handler")) + || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("URL-Rewriter"))) { return FAILURE; } } @@ -77,17 +101,17 @@ static int php_zlib_output_conflict_check(const char *handler_name, size_t handl /* }}} */ /* {{{ php_zlib_output_encoding() */ -static int php_zlib_output_encoding(TSRMLS_D) +static int php_zlib_output_encoding(void) { - zval **enc; + zval *enc; if (!ZLIBG(compression_coding)) { - if ((PG(http_globals)[TRACK_VARS_SERVER] || zend_is_auto_global(ZEND_STRL("_SERVER") TSRMLS_CC)) && - 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")) { + if ((Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY || zend_is_auto_global_str(ZEND_STRL("_SERVER"))) && + (enc = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING") - 1))) { + convert_to_string(enc); + if (strstr(Z_STRVAL_P(enc), "gzip")) { ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_GZIP; - } else if (strstr(Z_STRVAL_PP(enc), "deflate")) { + } else if (strstr(Z_STRVAL_P(enc), "deflate")) { ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_DEFLATE; } } @@ -100,7 +124,6 @@ static int php_zlib_output_encoding(TSRMLS_D) static int php_zlib_output_handler_ex(php_zlib_context *ctx, php_output_context *output_context) { int flags = Z_SYNC_FLUSH; - PHP_OUTPUT_TSRMLS(output_context); if (output_context->op & PHP_OUTPUT_HANDLER_START) { /* start up */ @@ -186,9 +209,8 @@ static int php_zlib_output_handler_ex(php_zlib_context *ctx, php_output_context static int php_zlib_output_handler(void **handler_context, php_output_context *output_context) { php_zlib_context *ctx = *(php_zlib_context **) handler_context; - PHP_OUTPUT_TSRMLS(output_context); - if (!php_zlib_output_encoding(TSRMLS_C)) { + if (!php_zlib_output_encoding()) { /* "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; @@ -202,7 +224,7 @@ static int php_zlib_output_handler(void **handler_context, php_output_context *o if ((output_context->op & PHP_OUTPUT_HANDLER_START) && (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, 0 TSRMLS_CC); + sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0); } return FAILURE; } @@ -214,7 +236,7 @@ static int php_zlib_output_handler(void **handler_context, php_output_context *o if (!(output_context->op & PHP_OUTPUT_HANDLER_CLEAN)) { int flags; - if (SUCCESS == php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS, &flags TSRMLS_CC)) { + if (SUCCESS == php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS, &flags)) { /* only run this once */ if (!(flags & PHP_OUTPUT_HANDLER_STARTED)) { if (SG(headers_sent) || !ZLIBG(output_compression)) { @@ -223,17 +245,17 @@ static int php_zlib_output_handler(void **handler_context, php_output_context *o } switch (ZLIBG(compression_coding)) { case PHP_ZLIB_ENCODING_GZIP: - sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1 TSRMLS_CC); + sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1); break; case PHP_ZLIB_ENCODING_DEFLATE: - sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1 TSRMLS_CC); + sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1); break; default: deflateEnd(&ctx->Z); return FAILURE; } - sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0 TSRMLS_CC); - php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE, NULL TSRMLS_CC); + sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0); + php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE, NULL); } } } @@ -243,7 +265,7 @@ static int php_zlib_output_handler(void **handler_context, php_output_context *o /* }}} */ /* {{{ php_zlib_output_handler_context_init() */ -static php_zlib_context *php_zlib_output_handler_context_init(TSRMLS_D) +static php_zlib_context *php_zlib_output_handler_context_init(void) { php_zlib_context *ctx = (php_zlib_context *) ecalloc(1, sizeof(php_zlib_context)); ctx->Z.zalloc = php_zlib_alloc; @@ -253,7 +275,7 @@ static php_zlib_context *php_zlib_output_handler_context_init(TSRMLS_D) /* }}} */ /* {{{ php_zlib_output_handler_context_dtor() */ -static void php_zlib_output_handler_context_dtor(void *opaq TSRMLS_DC) +static void php_zlib_output_handler_context_dtor(void *opaq) { php_zlib_context *ctx = (php_zlib_context *) opaq; @@ -267,7 +289,7 @@ static void php_zlib_output_handler_context_dtor(void *opaq TSRMLS_DC) /* }}} */ /* {{{ 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) +static php_output_handler *php_zlib_output_handler_init(const char *handler_name, size_t handler_name_len, size_t chunk_size, int flags) { php_output_handler *h = NULL; @@ -277,8 +299,8 @@ static php_output_handler *php_zlib_output_handler_init(const char *handler_name ZLIBG(handler_registered) = 1; - if ((h = php_output_handler_create_internal(handler_name, handler_name_len, php_zlib_output_handler, chunk_size, flags TSRMLS_CC))) { - php_output_handler_set_context(h, php_zlib_output_handler_context_init(TSRMLS_C), php_zlib_output_handler_context_dtor TSRMLS_CC); + if ((h = php_output_handler_create_internal(handler_name, handler_name_len, php_zlib_output_handler, chunk_size, flags))) { + php_output_handler_set_context(h, php_zlib_output_handler_context_init(), php_zlib_output_handler_context_dtor); } return h; @@ -286,9 +308,9 @@ static php_output_handler *php_zlib_output_handler_init(const char *handler_name /* }}} */ /* {{{ php_zlib_output_compression_start() */ -static void php_zlib_output_compression_start(TSRMLS_D) +static void php_zlib_output_compression_start(void) { - zval *zoh; + zval zoh; php_output_handler *h; switch (ZLIBG(output_compression)) { @@ -298,13 +320,12 @@ static void php_zlib_output_compression_start(TSRMLS_D) ZLIBG(output_compression) = PHP_OUTPUT_HANDLER_DEFAULT_SIZE; /* break omitted intentionally */ default: - if ( php_zlib_output_encoding(TSRMLS_C) && - (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 ( php_zlib_output_encoding() && + (h = php_zlib_output_handler_init(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME), ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS)) && + (SUCCESS == php_output_handler_start(h))) { 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_STRING(&zoh, ZLIBG(output_handler)); + php_output_start_user(&zoh, ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS); zval_ptr_dtor(&zoh); } } @@ -314,42 +335,39 @@ static void php_zlib_output_compression_start(TSRMLS_D) /* }}} */ /* {{{ 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) +static zend_string *php_zlib_encode(const char *in_buf, size_t in_len, int encoding, int level) { int status; z_stream Z; + zend_string *out; memset(&Z, 0, sizeof(z_stream)); Z.zalloc = php_zlib_alloc; Z.zfree = php_zlib_free; 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); + out = zend_string_alloc(PHP_ZLIB_BUFFER_SIZE_GUESS(in_len), 0); Z.next_in = (Bytef *) in_buf; - Z.next_out = (Bytef *) *out_buf; + Z.next_out = (Bytef *) ZSTR_VAL(out); Z.avail_in = in_len; - Z.avail_out = *out_len; + Z.avail_out = ZSTR_LEN(out); 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; + out = zend_string_truncate(out, Z.total_out, 0); + ZSTR_VAL(out)[ZSTR_LEN(out)] = '\0'; + return out; } else { - efree(*out_buf); + zend_string_free(out); } } - *out_buf = NULL; - *out_len = 0; - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status)); - return FAILURE; + php_error_docref(NULL, E_WARNING, "%s", zError(status)); + return NULL; } /* }}} */ @@ -403,7 +421,7 @@ static inline int php_zlib_inflate_rounds(z_stream *Z, size_t max, char **buf, s /* }}} */ /* {{{ 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) +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) { int status = Z_DATA_ERROR; z_stream Z; @@ -439,17 +457,17 @@ retry_raw_inflate: *out_buf = NULL; *out_len = 0; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status)); + php_error_docref(NULL, E_WARNING, "%s", zError(status)); return FAILURE; } /* }}} */ /* {{{ php_zlib_cleanup_ob_gzhandler_mess() */ -static void php_zlib_cleanup_ob_gzhandler_mess(TSRMLS_D) +static void php_zlib_cleanup_ob_gzhandler_mess(void) { if (ZLIBG(ob_gzhandler)) { deflateEnd(&(ZLIBG(ob_gzhandler)->Z)); - php_zlib_output_handler_context_dtor(ZLIBG(ob_gzhandler) TSRMLS_CC); + php_zlib_output_handler_context_dtor(ZLIBG(ob_gzhandler)); ZLIBG(ob_gzhandler) = NULL; } } @@ -460,8 +478,8 @@ static void php_zlib_cleanup_ob_gzhandler_mess(TSRMLS_D) static PHP_FUNCTION(ob_gzhandler) { char *in_str; - int in_len; - long flags = 0; + size_t in_len; + zend_long flags = 0; php_output_context ctx = {0}; int encoding, rv; @@ -473,31 +491,30 @@ static PHP_FUNCTION(ob_gzhandler) * - OG(running) is not set or set to any other output handler * - we have to mess around with php_output_context */ - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &in_str, &in_len, &flags)) { + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "sl", &in_str, &in_len, &flags)) { RETURN_FALSE; } - if (!(encoding = php_zlib_output_encoding(TSRMLS_C))) { + if (!(encoding = php_zlib_output_encoding())) { RETURN_FALSE; } if (flags & PHP_OUTPUT_HANDLER_START) { switch (encoding) { case PHP_ZLIB_ENCODING_GZIP: - sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1 TSRMLS_CC); + sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1); break; case PHP_ZLIB_ENCODING_DEFLATE: - sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1 TSRMLS_CC); + sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1); break; } - sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0 TSRMLS_CC); + sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0); } if (!ZLIBG(ob_gzhandler)) { - ZLIBG(ob_gzhandler) = php_zlib_output_handler_context_init(TSRMLS_C); + ZLIBG(ob_gzhandler) = php_zlib_output_handler_context_init(); } - TSRMLS_SET_CTX(ctx.tsrm_ls); ctx.op = flags; ctx.in.data = in_str; ctx.in.used = in_len; @@ -508,12 +525,12 @@ static PHP_FUNCTION(ob_gzhandler) if (ctx.out.data && ctx.out.free) { efree(ctx.out.data); } - php_zlib_cleanup_ob_gzhandler_mess(TSRMLS_C); + php_zlib_cleanup_ob_gzhandler_mess(); RETURN_FALSE; } if (ctx.out.data) { - RETVAL_STRINGL(ctx.out.data, ctx.out.used, 1); + RETVAL_STRINGL(ctx.out.data, ctx.out.used); if (ctx.out.free) { efree(ctx.out.data); } @@ -532,9 +549,9 @@ static PHP_FUNCTION(zlib_get_coding_type) } switch (ZLIBG(compression_coding)) { case PHP_ZLIB_ENCODING_GZIP: - RETURN_STRINGL("gzip", sizeof("gzip") - 1, 1); + RETURN_STRINGL("gzip", sizeof("gzip") - 1); case PHP_ZLIB_ENCODING_DEFLATE: - RETURN_STRINGL("deflate", sizeof("deflate") - 1, 1); + RETURN_STRINGL("deflate", sizeof("deflate") - 1); default: RETURN_FALSE; } @@ -546,14 +563,14 @@ static PHP_FUNCTION(zlib_get_coding_type) static PHP_FUNCTION(gzfile) { char *filename; - int filename_len; + size_t filename_len; int flags = REPORT_ERRORS; char buf[8192] = {0}; register int i = 0; - long use_include_path = 0; + zend_long use_include_path = 0; php_stream *stream; - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path)) { + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "p|l", &filename, &filename_len, &use_include_path)) { return; } @@ -562,7 +579,7 @@ static PHP_FUNCTION(gzfile) } /* using a stream here is a bit more efficient (resource wise) than php_gzopen_wrapper */ - stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC TSRMLS_CC); + stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC); if (!stream) { /* Error reporting is already done by stream code */ @@ -576,7 +593,7 @@ static PHP_FUNCTION(gzfile) memset(buf, 0, sizeof(buf)); while (php_stream_gets(stream, buf, sizeof(buf) - 1) != NULL) { - add_index_string(return_value, i++, buf, 1); + add_index_string(return_value, i++, buf); } php_stream_close(stream); } @@ -588,12 +605,12 @@ static PHP_FUNCTION(gzopen) { char *filename; char *mode; - int filename_len, mode_len; + size_t filename_len, mode_len; int flags = REPORT_ERRORS; php_stream *stream; - long use_include_path = 0; + zend_long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ps|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) { return; } @@ -601,7 +618,7 @@ static PHP_FUNCTION(gzopen) flags |= USE_PATH; } - stream = php_stream_gzopen(NULL, filename, mode, flags, NULL, NULL STREAMS_CC TSRMLS_CC); + stream = php_stream_gzopen(NULL, filename, mode, flags, NULL, NULL STREAMS_CC); if (!stream) { RETURN_FALSE; @@ -615,13 +632,13 @@ static PHP_FUNCTION(gzopen) static PHP_FUNCTION(readgzfile) { char *filename; - int filename_len; + size_t filename_len; int flags = REPORT_ERRORS; php_stream *stream; - int size; - long use_include_path = 0; + size_t size; + zend_long use_include_path = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|l", &filename, &filename_len, &use_include_path) == FAILURE) { return; } @@ -629,7 +646,7 @@ static PHP_FUNCTION(readgzfile) flags |= USE_PATH; } - stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC TSRMLS_CC); + stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC); if (!stream) { RETURN_FALSE; @@ -643,22 +660,20 @@ static PHP_FUNCTION(readgzfile) #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; \ + zend_string *in, *out; \ + zend_long level = -1; \ + zend_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)) { \ + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S|ll", &in, &level, &encoding)) { \ return; \ } \ } else { \ - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|l", &in_buf, &in_len, &encoding, &level)) { \ + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "Sl|l", &in, &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); \ + php_error_docref(NULL, E_WARNING, "compression level (%pd) must be within -1..9", level); \ RETURN_FALSE; \ } \ switch (encoding) { \ @@ -667,33 +682,34 @@ static PHP_FUNCTION(name) \ 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"); \ + php_error_docref(NULL, 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)) { \ + if ((out = php_zlib_encode(ZSTR_VAL(in), ZSTR_LEN(in), encoding, level)) == NULL) { \ RETURN_FALSE; \ } \ - RETVAL_STRINGL_CHECK(out_buf, out_len, 0); \ + RETURN_STR(out); \ } #define PHP_ZLIB_DECODE_FUNC(name, encoding) \ static PHP_FUNCTION(name) \ { \ char *in_buf, *out_buf; \ - int in_len; \ + size_t 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)) { \ + zend_long max_len = 0; \ + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "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); \ + php_error_docref(NULL, E_WARNING, "length (%pd) 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)) { \ + if (SUCCESS != php_zlib_decode(in_buf, in_len, &out_buf, &out_len, encoding, max_len)) { \ RETURN_FALSE; \ } \ - RETVAL_STRINGL_CHECK(out_buf, out_len, 0); \ + RETVAL_STRINGL(out_buf, out_len); \ + efree(out_buf); \ } /* {{{ proto binary zlib_encode(binary data, int encoding[, int level = -1]) @@ -737,7 +753,442 @@ PHP_ZLIB_DECODE_FUNC(gzdecode, PHP_ZLIB_ENCODING_GZIP); PHP_ZLIB_DECODE_FUNC(gzuncompress, PHP_ZLIB_ENCODING_DEFLATE); /* }}} */ +static zend_bool zlib_create_dictionary_string(HashTable *options, char **dict, size_t *dictlen) { + zval *option_buffer; + + if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("dictionary"))) != NULL) { + ZVAL_DEREF(option_buffer); + switch (Z_TYPE_P(option_buffer)) { + case IS_STRING: { + zend_string *str = Z_STR_P(option_buffer); + int i; + zend_bool last_null = 1; + + for (i = 0; i < ZSTR_LEN(str); i++) { + if (ZSTR_VAL(str)[i]) { + last_null = 0; + } else { + if (last_null) { + php_error_docref(NULL, E_WARNING, "dictionary string must not contain empty entries (two consecutive NULL-bytes or one at the very beginning)"); + return 0; + } + last_null = 1; + } + } + if (!last_null) { + php_error_docref(NULL, E_WARNING, "dictionary string must be NULL-byte terminated (each dictionary entry has to be NULL-terminated)"); + } + + *dict = emalloc(ZSTR_LEN(str)); + memcpy(*dict, ZSTR_VAL(str), ZSTR_LEN(str)); + *dictlen = ZSTR_LEN(str); + } break; + + case IS_ARRAY: { + HashTable *dictionary = Z_ARR_P(option_buffer); + + if (zend_hash_num_elements(dictionary) > 0) { + char *dictptr; + zval *cur; + zend_string **strings = emalloc(sizeof(zend_string *) * zend_hash_num_elements(dictionary)); + zend_string **end, **ptr = strings - 1; + + ZEND_HASH_FOREACH_VAL(dictionary, cur) { + int i; + + *++ptr = zval_get_string(cur); + if (!*ptr || ZSTR_LEN(*ptr) == 0) { + if (*ptr) { + efree(*ptr); + } + while (--ptr >= strings) { + efree(ptr); + } + efree(strings); + php_error_docref(NULL, E_WARNING, "dictionary entries must be non-empty strings"); + return 0; + } + for (i = 0; i < ZSTR_LEN(*ptr); i++) { + if (ZSTR_VAL(*ptr)[i] == 0) { + do { + efree(ptr); + } while (--ptr >= strings); + efree(strings); + php_error_docref(NULL, E_WARNING, "dictionary entries must not contain a NULL-byte"); + return 0; + } + } + + *dictlen += ZSTR_LEN(*ptr) + 1; + } ZEND_HASH_FOREACH_END(); + + dictptr = *dict = emalloc(*dictlen); + ptr = strings; + end = strings + zend_hash_num_elements(dictionary); + do { + memcpy(dictptr, ZSTR_VAL(*ptr), ZSTR_LEN(*ptr)); + dictptr += ZSTR_LEN(*ptr); + *dictptr++ = 0; + zend_string_release(*ptr); + } while (++ptr != end); + efree(strings); + } + } break; + + default: + php_error_docref(NULL, E_WARNING, "dictionary must be of type zero-terminated string or array, got %s", zend_get_type_by_const(Z_TYPE_P(option_buffer))); + return 0; + } + } + + return 1; +} + +/* {{{ proto resource inflate_init(int encoding) + Initialize an incremental inflate context with the specified encoding */ +PHP_FUNCTION(inflate_init) +{ + z_stream *ctx; + zend_long encoding, window = 15; + char *dict = NULL; + size_t dictlen = 0; + HashTable *options = NULL; + zval *option_buffer; + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "l|H", &encoding, &options)) { + return; + } + + if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("window"))) != NULL) { + window = zval_get_long(option_buffer); + } + if (window < 8 || window > 15) { + php_error_docref(NULL, E_WARNING, "zlib window size (lograithm) (%pd) must be within 8..15", window); + RETURN_FALSE; + } + + if (!zlib_create_dictionary_string(options, &dict, &dictlen)) { + 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, E_WARNING, "encoding mode must be ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE"); + RETURN_FALSE; + } + + ctx = ecalloc(1, sizeof(php_zlib_context)); + ctx->zalloc = php_zlib_alloc; + ctx->zfree = php_zlib_free; + ((php_zlib_context *) ctx)->inflateDict = dict; + ((php_zlib_context *) ctx)->inflateDictlen = dictlen; + + if (encoding < 0) { + encoding += 15 - window; + } else { + encoding -= 15 - window; + } + + if (Z_OK == inflateInit2(ctx, encoding)) { + RETURN_RES(zend_register_resource(ctx, le_inflate)); + } else { + efree(ctx); + php_error_docref(NULL, E_WARNING, "failed allocating zlib.inflate context"); + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto string inflate_add(resource context, string encoded_data[, int flush_mode = ZLIB_SYNC_FLUSH]) + Incrementally inflate encoded data in the specified context */ +PHP_FUNCTION(inflate_add) +{ + zend_string *out; + char *in_buf; + size_t in_len, buffer_used = 0, CHUNK_SIZE = 8192; + zval *res; + z_stream *ctx; + zend_long flush_type = Z_SYNC_FLUSH; + int status; + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "rs|l", &res, &in_buf, &in_len, &flush_type)) { + return; + } + + if (!(ctx = zend_fetch_resource_ex(res, NULL, le_inflate))) { + php_error_docref(NULL, E_WARNING, "Invalid zlib.inflate resource"); + RETURN_FALSE; + } + + switch (flush_type) { + case Z_NO_FLUSH: + case Z_PARTIAL_FLUSH: + case Z_SYNC_FLUSH: + case Z_FULL_FLUSH: + case Z_BLOCK: + case Z_FINISH: + break; + + default: + php_error_docref(NULL, E_WARNING, + "flush mode must be ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK or ZLIB_FINISH"); + RETURN_FALSE; + } + + if (in_len <= 0 && flush_type != Z_FINISH) { + RETURN_EMPTY_STRING(); + } + + out = zend_string_alloc((in_len > CHUNK_SIZE) ? in_len : CHUNK_SIZE, 0); + ctx->next_in = (Bytef *) in_buf; + ctx->next_out = (Bytef *) ZSTR_VAL(out); + ctx->avail_in = in_len; + ctx->avail_out = ZSTR_LEN(out); + + do { + status = inflate(ctx, flush_type); + buffer_used = ZSTR_LEN(out) - ctx->avail_out; + + switch (status) { + case Z_OK: + if (ctx->avail_out == 0) { + /* more output buffer space needed; realloc and try again */ + out = zend_string_realloc(out, ZSTR_LEN(out) + CHUNK_SIZE, 0); + ctx->avail_out = CHUNK_SIZE; + ctx->next_out = (Bytef *) ZSTR_VAL(out) + buffer_used; + break; + } else { + goto complete; + } + case Z_STREAM_END: + inflateReset(ctx); + goto complete; + case Z_BUF_ERROR: + if (flush_type == Z_FINISH && ctx->avail_out == 0) { + /* more output buffer space needed; realloc and try again */ + out = zend_string_realloc(out, ZSTR_LEN(out) + CHUNK_SIZE, 0); + ctx->avail_out = CHUNK_SIZE; + ctx->next_out = (Bytef *) ZSTR_VAL(out) + buffer_used; + break; + } else { + /* No more input data; we're finished */ + goto complete; + } + case Z_NEED_DICT: + if (((php_zlib_context *) ctx)->inflateDict) { + php_zlib_context *php_ctx = (php_zlib_context *) ctx; + switch (inflateSetDictionary(ctx, (Bytef *) php_ctx->inflateDict, php_ctx->inflateDictlen)) { + case Z_OK: + efree(php_ctx->inflateDict); + php_ctx->inflateDict = NULL; + break; + case Z_DATA_ERROR: + php_error_docref(NULL, E_WARNING, "dictionary does not match expected dictionary (incorrect adler32 hash)"); + efree(php_ctx->inflateDict); + zend_string_release(out); + php_ctx->inflateDict = NULL; + RETURN_FALSE; + EMPTY_SWITCH_DEFAULT_CASE() + } + break; + } else { + php_error_docref(NULL, E_WARNING, "inflating this data requires a preset dictionary, please specify it in the options array of inflate_init()"); + RETURN_FALSE; + } + default: + zend_string_release(out); + php_error_docref(NULL, E_WARNING, "%s", zError(status)); + RETURN_FALSE; + } + } while (1); + + complete: { + out = zend_string_realloc(out, buffer_used, 0); + ZSTR_VAL(out)[buffer_used] = 0; + RETURN_STR(out); + } +} +/* }}} */ + +/* {{{ proto resource deflate_init(int encoding[, array options]) + Initialize an incremental deflate context using the specified encoding */ +PHP_FUNCTION(deflate_init) +{ + z_stream *ctx; + zend_long encoding, level = -1, memory = 8, window = 15, strategy = Z_DEFAULT_STRATEGY; + char *dict = NULL; + size_t dictlen = 0; + HashTable *options = NULL; + zval *option_buffer; + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "l|H", &encoding, &options)) { + return; + } + + if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("level"))) != NULL) { + level = zval_get_long(option_buffer); + } + if (level < -1 || level > 9) { + php_error_docref(NULL, E_WARNING, "compression level (%pd) must be within -1..9", level); + RETURN_FALSE; + } + + if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("memory"))) != NULL) { + memory = zval_get_long(option_buffer); + } + if (memory < 1 || memory > 9) { + php_error_docref(NULL, E_WARNING, "compression memory level (%pd) must be within 1..9", memory); + RETURN_FALSE; + } + + if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("window"))) != NULL) { + window = zval_get_long(option_buffer); + } + if (window < 8 || window > 15) { + php_error_docref(NULL, E_WARNING, "zlib window size (logarithm) (%pd) must be within 8..15", window); + RETURN_FALSE; + } + + if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("strategy"))) != NULL) { + strategy = zval_get_long(option_buffer); + } + switch (strategy) { + case Z_FILTERED: + case Z_HUFFMAN_ONLY: + case Z_RLE: + case Z_FIXED: + case Z_DEFAULT_STRATEGY: + break; + default: + php_error_docref(NULL, E_WARNING, "strategy must be one of ZLIB_FILTERED, ZLIB_HUFFMAN_ONLY, ZLIB_RLE, ZLIB_FIXED or ZLIB_DEFAULT_STRATEGY"); + RETURN_FALSE; + } + + if (!zlib_create_dictionary_string(options, &dict, &dictlen)) { + 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, E_WARNING, + "encoding mode must be ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE"); + RETURN_FALSE; + } + + ctx = ecalloc(1, sizeof(php_zlib_context)); + ctx->zalloc = php_zlib_alloc; + ctx->zfree = php_zlib_free; + + if (encoding < 0) { + encoding += 15 - window; + } else { + encoding -= 15 - window; + } + + if (Z_OK == deflateInit2(ctx, level, Z_DEFLATED, encoding, memory, strategy)) { + if (dict) { + int success = deflateSetDictionary(ctx, (Bytef *) dict, dictlen); + ZEND_ASSERT(success == Z_OK); + efree(dict); + } + + RETURN_RES(zend_register_resource(ctx, le_deflate)); + } else { + efree(ctx); + php_error_docref(NULL, E_WARNING, "failed allocating zlib.deflate context"); + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto string deflate_add(resource context, string data[, int flush_mode = ZLIB_SYNC_FLUSH]) + Incrementally deflate data in the specified context */ +PHP_FUNCTION(deflate_add) +{ + zend_string *out; + char *in_buf; + size_t in_len, out_size; + zval *res; + z_stream *ctx; + zend_long flush_type = Z_SYNC_FLUSH; + int status; + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "rs|l", &res, &in_buf, &in_len, &flush_type)) { + return; + } + + if (!(ctx = zend_fetch_resource_ex(res, NULL, le_deflate))) { + php_error_docref(NULL, E_WARNING, "Invalid deflate resource"); + RETURN_FALSE; + } + + switch (flush_type) { + case Z_BLOCK: +#if ZLIB_VERNUM < 0x1240L + php_error_docref(NULL, E_WARNING, + "zlib >= 1.2.4 required for BLOCK deflate; current version: %s", ZLIB_VERSION); + RETURN_FALSE; +#endif + case Z_NO_FLUSH: + case Z_PARTIAL_FLUSH: + case Z_SYNC_FLUSH: + case Z_FULL_FLUSH: + case Z_FINISH: + break; + + default: + php_error_docref(NULL, E_WARNING, + "flush mode must be ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK or ZLIB_FINISH"); + RETURN_FALSE; + } + + if (in_len <= 0 && flush_type != Z_FINISH) { + RETURN_EMPTY_STRING(); + } + + out_size = PHP_ZLIB_BUFFER_SIZE_GUESS(ctx->total_in + in_len); + out_size = (ctx->total_out >= out_size) ? 16 : (out_size - ctx->total_out); + out_size = (out_size < 16) ? 16 : out_size; + out = zend_string_alloc(out_size, 0); + + ctx->next_in = (Bytef *) in_buf; + ctx->next_out = (Bytef *) ZSTR_VAL(out); + ctx->avail_in = in_len; + ctx->avail_out = ZSTR_LEN(out); + + status = deflate(ctx, flush_type); + switch (status) { + case Z_OK: + ZSTR_LEN(out) = (char *) ctx->next_out - ZSTR_VAL(out); + ZSTR_VAL(out)[ZSTR_LEN(out)] = 0; + RETURN_STR(out); + break; + case Z_STREAM_END: + ZSTR_LEN(out) = (char *) ctx->next_out - ZSTR_VAL(out); + ZSTR_VAL(out)[ZSTR_LEN(out)] = 0; + deflateReset(ctx); + RETURN_STR(out); + break; + default: + zend_string_release(out); + php_error_docref(NULL, E_WARNING, "zlib error (%s)", zError(status)); + RETURN_FALSE; + } +} +/* }}} */ + #ifdef COMPILE_DL_ZLIB +#ifdef ZTS +ZEND_TSRMLS_CACHE_DEFINE() +#endif ZEND_GET_MODULE(php_zlib) #endif @@ -841,6 +1292,27 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_gzgets, 0, 0, 1) ZEND_ARG_INFO(0, fp) ZEND_ARG_INFO(0, length) ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_deflate_init, 0, 0, 1) + ZEND_ARG_INFO(0, encoding) + ZEND_ARG_INFO(0, level) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_deflate_add, 0, 0, 2) + ZEND_ARG_INFO(0, resource) + ZEND_ARG_INFO(0, add) + ZEND_ARG_INFO(0, flush_behavior) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_inflate_init, 0, 0, 1) + ZEND_ARG_INFO(0, encoding) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_inflate_add, 0, 0, 2) + ZEND_ARG_INFO(0, resource) + ZEND_ARG_INFO(0, flush_behavior) +ZEND_END_ARG_INFO() + /* }}} */ /* {{{ php_zlib_functions[] */ @@ -869,6 +1341,10 @@ static const zend_function_entry php_zlib_functions[] = { 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) + PHP_FE(deflate_init, arginfo_deflate_init) + PHP_FE(deflate_add, arginfo_deflate_add) + PHP_FE(inflate_init, arginfo_inflate_init) + PHP_FE(inflate_add, arginfo_inflate_add) PHP_FE(ob_gzhandler, arginfo_ob_gzhandler) PHP_FE_END }; @@ -877,58 +1353,65 @@ static const zend_function_entry php_zlib_functions[] = { /* {{{ OnUpdate_zlib_output_compression */ static PHP_INI_MH(OnUpdate_zlib_output_compression) { - int status, int_value; + int int_value; char *ini_value; + zend_long *p; +#ifndef ZTS + char *base = (char *) mh_arg2; +#else + char *base; + + base = (char *) ts_resource(*((int *) mh_arg2)); +#endif if (new_value == NULL) { return FAILURE; } - 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"); + if (!strncasecmp(ZSTR_VAL(new_value), "off", sizeof("off"))) { + int_value = 0; + } else if (!strncasecmp(ZSTR_VAL(new_value), "on", sizeof("on"))) { + int_value = 1; + } else { + int_value = zend_atoi(ZSTR_VAL(new_value), ZSTR_LEN(new_value)); } - - 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_error_docref("ref.outcontrol", E_CORE_ERROR, "Cannot use both zlib.output_compression and output_handler together!!"); return FAILURE; } if (stage == PHP_INI_STAGE_RUNTIME) { - status = php_output_get_status(TSRMLS_C); + int status = php_output_get_status(); if (status & PHP_OUTPUT_SENT) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_compression - headers already sent"); + php_error_docref("ref.outcontrol", E_WARNING, "Cannot change zlib.output_compression - headers already sent"); return FAILURE; } } - status = OnUpdateLong(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + p = (zend_long *) (base+(size_t) mh_arg1); + *p = int_value; ZLIBG(output_compression) = ZLIBG(output_compression_default); 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); + if (!php_output_handler_started(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME))) { + php_zlib_output_compression_start(); } } - return status; + return SUCCESS; } /* }}} */ /* {{{ OnUpdate_zlib_output_handler */ static PHP_INI_MH(OnUpdate_zlib_output_handler) { - 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"); + if (stage == PHP_INI_STAGE_RUNTIME && (php_output_get_status() & PHP_OUTPUT_SENT)) { + php_error_docref("ref.outcontrol", E_WARNING, "Cannot change zlib.output_handler - headers already sent"); return FAILURE; } - return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage); } /* }}} */ @@ -944,12 +1427,15 @@ PHP_INI_END() /* {{{ PHP_MINIT_FUNCTION */ static PHP_MINIT_FUNCTION(zlib) { - 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); + php_register_url_stream_wrapper("compress.zlib", &php_stream_gzip_wrapper); + php_stream_filter_register_factory("zlib.*", &php_zlib_filter_factory); + + 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); - php_output_handler_alias_register(ZEND_STRL("ob_gzhandler"), php_zlib_output_handler_init TSRMLS_CC); - php_output_handler_conflict_register(ZEND_STRL("ob_gzhandler"), php_zlib_output_conflict_check TSRMLS_CC); - php_output_handler_conflict_register(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME), php_zlib_output_conflict_check TSRMLS_CC); + le_deflate = zend_register_list_destructors_ex(deflate_rsrc_dtor, NULL, "zlib.deflate", module_number); + le_inflate = zend_register_list_destructors_ex(inflate_rsrc_dtor, NULL, "zlib.inflate", module_number); 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); @@ -957,6 +1443,23 @@ static PHP_MINIT_FUNCTION(zlib) 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_LONG_CONSTANT("ZLIB_NO_FLUSH", Z_NO_FLUSH, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("ZLIB_PARTIAL_FLUSH", Z_PARTIAL_FLUSH, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("ZLIB_SYNC_FLUSH", Z_SYNC_FLUSH, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("ZLIB_FULL_FLUSH", Z_FULL_FLUSH, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("ZLIB_BLOCK", Z_BLOCK, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("ZLIB_FINISH", Z_FINISH, CONST_CS|CONST_PERSISTENT); + + REGISTER_LONG_CONSTANT("ZLIB_FILTERED", Z_FILTERED, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("ZLIB_HUFFMAN_ONLY", Z_HUFFMAN_ONLY, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("ZLIB_RLE", Z_RLE, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("ZLIB_FIXED", Z_FIXED, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("ZLIB_DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY, CONST_CS|CONST_PERSISTENT); + + REGISTER_STRING_CONSTANT("ZLIB_VERSION", ZLIB_VERSION, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("ZLIB_VERNUM", ZLIB_VERNUM, CONST_CS|CONST_PERSISTENT); + REGISTER_INI_ENTRIES(); return SUCCESS; } @@ -965,8 +1468,8 @@ static PHP_MINIT_FUNCTION(zlib) /* {{{ PHP_MSHUTDOWN_FUNCTION */ static PHP_MSHUTDOWN_FUNCTION(zlib) { - php_unregister_url_stream_wrapper("zlib" TSRMLS_CC); - php_stream_filter_unregister_factory("zlib.*" TSRMLS_CC); + php_unregister_url_stream_wrapper("zlib"); + php_stream_filter_unregister_factory("zlib.*"); UNREGISTER_INI_ENTRIES(); @@ -980,7 +1483,7 @@ static PHP_RINIT_FUNCTION(zlib) ZLIBG(compression_coding) = 0; if (!ZLIBG(handler_registered)) { ZLIBG(output_compression) = ZLIBG(output_compression_default); - php_zlib_output_compression_start(TSRMLS_C); + php_zlib_output_compression_start(); } return SUCCESS; @@ -990,7 +1493,7 @@ static PHP_RINIT_FUNCTION(zlib) /* {{{ PHP_RSHUTDOWN_FUNCTION */ static PHP_RSHUTDOWN_FUNCTION(zlib) { - php_zlib_cleanup_ob_gzhandler_mess(TSRMLS_C); + php_zlib_cleanup_ob_gzhandler_mess(); ZLIBG(handler_registered) = 0; return SUCCESS; @@ -1013,8 +1516,11 @@ static PHP_MINFO_FUNCTION(zlib) /* }}} */ /* {{{ ZEND_MODULE_GLOBALS_CTOR */ -static ZEND_MODULE_GLOBALS_CTOR_D(zlib) +static PHP_GINIT_FUNCTION(zlib) { +#if defined(COMPILE_DL_ZLIB) && defined(ZTS) + ZEND_TSRMLS_CACHE_UPDATE(); +#endif zlib_globals->ob_gzhandler = NULL; zlib_globals->handler_registered = 0; } @@ -1030,9 +1536,9 @@ zend_module_entry php_zlib_module_entry = { PHP_RINIT(zlib), PHP_RSHUTDOWN(zlib), PHP_MINFO(zlib), - "2.0", + PHP_ZLIB_VERSION, PHP_MODULE_GLOBALS(zlib), - ZEND_MODULE_GLOBALS_CTOR_N(zlib), + PHP_GINIT(zlib), NULL, NULL, STANDARD_MODULE_PROPERTIES_EX diff --git a/ext/zlib/zlib.dsp b/ext/zlib/zlib.dsp deleted file mode 100644 index 8986bc6f05..0000000000 --- a/ext/zlib/zlib.dsp +++ /dev/null @@ -1,121 +0,0 @@ -# Microsoft Developer Studio Project File - Name="zlib" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=zlib - Win32 Release_TS -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "zlib.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "zlib.mak" CFG="zlib - Win32 Release_TS" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "zlib - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "zlib - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "zlib - Win32 Release_TS" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release_TS" -# PROP BASE Intermediate_Dir "Release_TS" -# PROP BASE Ignore_Export_Lib 0 -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release_TS" -# PROP Intermediate_Dir "Release_TS" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "..\..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\..\TSRM" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL_ZLIB" /D ZTS=1 /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\includes" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ZLIB_EXPORTS" /D "COMPILE_DL_ZLIB" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_ZLIB=1 /YX /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x406 /d "NDEBUG" -# ADD RSC /l 0x406 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php5ts.lib /nologo /dll /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php5ts.lib zlib.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_zlib.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\..\php_build\zlib\Release" /libpath:"..\..\Release_TS_Inline" - -!ELSEIF "$(CFG)" == "zlib - Win32 Debug_TS" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Debug_TS" -# PROP BASE Intermediate_Dir "Debug_TS" -# PROP BASE Ignore_Export_Lib 0 -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Debug_TS" -# PROP Intermediate_Dir "Debug_TS" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL_ZLIB" /D ZTS=1 /YX /FD /c -# ADD CPP /nologo /MDd /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\includes" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ZLIB_EXPORTS" /D "COMPILE_DL_ZLIB" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_ZLIB=1 /FR /YX /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x406 /d "NDEBUG" -# ADD RSC /l 0x406 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php5ts_debug.lib /nologo /dll /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php5ts_debug.lib zlib.lib /nologo /dll /machine:I386 /out:"..\..\Debug_TS/php_zlib.dll" /libpath:"..\..\Debug_TS" /libpath:"..\..\..\php_build\zlib\Debug" - -!ENDIF - -# Begin Target - -# Name "zlib - Win32 Release_TS" -# Name "zlib - Win32 Debug_TS" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\zlib.c -# End Source File -# Begin Source File - -SOURCE=.\zlib_fopen_wrapper.c -# End Source File -# Begin Source File - -SOURCE=.\zlib_filter.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\php_zlib.h -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/ext/zlib/zlib_filter.c b/ext/zlib/zlib_filter.c index 499eb2755e..14dd6ed1e8 100644 --- a/ext/zlib/zlib_filter.c +++ b/ext/zlib/zlib_filter.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -25,12 +25,12 @@ /* Passed as opaque in malloc callbacks */ typedef struct _php_zlib_filter_data { - int persistent; z_stream strm; - char *inbuf; + unsigned char *inbuf; size_t inbuf_len; - char *outbuf; + unsigned char *outbuf; size_t outbuf_len; + int persistent; zend_bool finished; } php_zlib_filter_data; @@ -58,7 +58,7 @@ static php_stream_filter_status_t php_zlib_inflate_filter( php_stream_bucket_brigade *buckets_out, size_t *bytes_consumed, int flags - TSRMLS_DC) + ) { php_zlib_filter_data *data; php_stream_bucket *bucket; @@ -66,19 +66,17 @@ static php_stream_filter_status_t php_zlib_inflate_filter( int status; php_stream_filter_status_t exit_status = PSFS_FEED_ME; - if (!thisfilter || !thisfilter->abstract) { + if (!thisfilter || !Z_PTR(thisfilter->abstract)) { /* Should never happen */ return PSFS_ERR_FATAL; } - data = (php_zlib_filter_data *)(thisfilter->abstract); + data = (php_zlib_filter_data *)(Z_PTR(thisfilter->abstract)); while (buckets_in->head) { size_t bin = 0, desired; - bucket = buckets_in->head; - - bucket = php_stream_bucket_make_writeable(buckets_in->head TSRMLS_CC); + bucket = php_stream_bucket_make_writeable(buckets_in->head); while (bin < (unsigned int) bucket->buflen) { @@ -100,7 +98,7 @@ static php_stream_filter_status_t php_zlib_inflate_filter( data->finished = '\1'; } else if (status != Z_OK) { /* Something bad happened */ - php_stream_bucket_delref(bucket TSRMLS_CC); + php_stream_bucket_delref(bucket); /* reset these because despite the error the filter may be used again */ data->strm.next_in = data->inbuf; data->strm.avail_in = 0; @@ -114,20 +112,21 @@ static php_stream_filter_status_t php_zlib_inflate_filter( if (data->strm.avail_out < data->outbuf_len) { php_stream_bucket *out_bucket; size_t bucketlen = data->outbuf_len - data->strm.avail_out; - out_bucket = php_stream_bucket_new(stream, estrndup(data->outbuf, bucketlen), bucketlen, 1, 0 TSRMLS_CC); - php_stream_bucket_append(buckets_out, out_bucket TSRMLS_CC); + out_bucket = php_stream_bucket_new( + stream, estrndup((char *) data->outbuf, bucketlen), bucketlen, 1, 0); + php_stream_bucket_append(buckets_out, out_bucket); data->strm.avail_out = data->outbuf_len; data->strm.next_out = data->outbuf; exit_status = PSFS_PASS_ON; } else if (status == Z_STREAM_END && data->strm.avail_out >= data->outbuf_len) { /* no more data to decompress, and nothing was spat out */ - php_stream_bucket_delref(bucket TSRMLS_CC); + php_stream_bucket_delref(bucket); return PSFS_PASS_ON; } } consumed += bucket->buflen; - php_stream_bucket_delref(bucket TSRMLS_CC); + php_stream_bucket_delref(bucket); } if (!data->finished && flags & PSFS_FLAG_FLUSH_CLOSE) { @@ -138,8 +137,9 @@ static php_stream_filter_status_t php_zlib_inflate_filter( if (data->strm.avail_out < data->outbuf_len) { size_t bucketlen = data->outbuf_len - data->strm.avail_out; - bucket = php_stream_bucket_new(stream, estrndup(data->outbuf, bucketlen), bucketlen, 1, 0 TSRMLS_CC); - php_stream_bucket_append(buckets_out, bucket TSRMLS_CC); + bucket = php_stream_bucket_new( + stream, estrndup((char *) data->outbuf, bucketlen), bucketlen, 1, 0); + php_stream_bucket_append(buckets_out, bucket); data->strm.avail_out = data->outbuf_len; data->strm.next_out = data->outbuf; exit_status = PSFS_PASS_ON; @@ -154,10 +154,10 @@ static php_stream_filter_status_t php_zlib_inflate_filter( return exit_status; } -static void php_zlib_inflate_dtor(php_stream_filter *thisfilter TSRMLS_DC) +static void php_zlib_inflate_dtor(php_stream_filter *thisfilter) { - if (thisfilter && thisfilter->abstract) { - php_zlib_filter_data *data = thisfilter->abstract; + if (thisfilter && Z_PTR(thisfilter->abstract)) { + php_zlib_filter_data *data = Z_PTR(thisfilter->abstract); if (!data->finished) { inflateEnd(&(data->strm)); } @@ -183,7 +183,7 @@ static php_stream_filter_status_t php_zlib_deflate_filter( php_stream_bucket_brigade *buckets_out, size_t *bytes_consumed, int flags - TSRMLS_DC) + ) { php_zlib_filter_data *data; php_stream_bucket *bucket; @@ -191,19 +191,19 @@ static php_stream_filter_status_t php_zlib_deflate_filter( int status; php_stream_filter_status_t exit_status = PSFS_FEED_ME; - if (!thisfilter || !thisfilter->abstract) { + if (!thisfilter || !Z_PTR(thisfilter->abstract)) { /* Should never happen */ return PSFS_ERR_FATAL; } - data = (php_zlib_filter_data *)(thisfilter->abstract); + data = (php_zlib_filter_data *)(Z_PTR(thisfilter->abstract)); while (buckets_in->head) { size_t bin = 0, desired; bucket = buckets_in->head; - bucket = php_stream_bucket_make_writeable(bucket TSRMLS_CC); + bucket = php_stream_bucket_make_writeable(bucket); while (bin < (unsigned int) bucket->buflen) { desired = bucket->buflen - bin; @@ -216,7 +216,7 @@ static php_stream_filter_status_t php_zlib_deflate_filter( status = deflate(&(data->strm), flags & PSFS_FLAG_FLUSH_CLOSE ? Z_FULL_FLUSH : (flags & PSFS_FLAG_FLUSH_INC ? Z_SYNC_FLUSH : Z_NO_FLUSH)); if (status != Z_OK) { /* Something bad happened */ - php_stream_bucket_delref(bucket TSRMLS_CC); + php_stream_bucket_delref(bucket); return PSFS_ERR_FATAL; } desired -= data->strm.avail_in; /* desired becomes what we consumed this round through */ @@ -228,15 +228,16 @@ static php_stream_filter_status_t php_zlib_deflate_filter( php_stream_bucket *out_bucket; size_t bucketlen = data->outbuf_len - data->strm.avail_out; - out_bucket = php_stream_bucket_new(stream, estrndup(data->outbuf, bucketlen), bucketlen, 1, 0 TSRMLS_CC); - php_stream_bucket_append(buckets_out, out_bucket TSRMLS_CC); + out_bucket = php_stream_bucket_new( + stream, estrndup((char *) data->outbuf, bucketlen), bucketlen, 1, 0); + php_stream_bucket_append(buckets_out, out_bucket); data->strm.avail_out = data->outbuf_len; data->strm.next_out = data->outbuf; exit_status = PSFS_PASS_ON; } } consumed += bucket->buflen; - php_stream_bucket_delref(bucket TSRMLS_CC); + php_stream_bucket_delref(bucket); } if (flags & PSFS_FLAG_FLUSH_CLOSE) { @@ -247,8 +248,9 @@ static php_stream_filter_status_t php_zlib_deflate_filter( if (data->strm.avail_out < data->outbuf_len) { size_t bucketlen = data->outbuf_len - data->strm.avail_out; - bucket = php_stream_bucket_new(stream, estrndup(data->outbuf, bucketlen), bucketlen, 1, 0 TSRMLS_CC); - php_stream_bucket_append(buckets_out, bucket TSRMLS_CC); + bucket = php_stream_bucket_new( + stream, estrndup((char *) data->outbuf, bucketlen), bucketlen, 1, 0); + php_stream_bucket_append(buckets_out, bucket); data->strm.avail_out = data->outbuf_len; data->strm.next_out = data->outbuf; exit_status = PSFS_PASS_ON; @@ -263,10 +265,10 @@ static php_stream_filter_status_t php_zlib_deflate_filter( return exit_status; } -static void php_zlib_deflate_dtor(php_stream_filter *thisfilter TSRMLS_DC) +static void php_zlib_deflate_dtor(php_stream_filter *thisfilter) { - if (thisfilter && thisfilter->abstract) { - php_zlib_filter_data *data = thisfilter->abstract; + if (thisfilter && Z_PTR(thisfilter->abstract)) { + php_zlib_filter_data *data = Z_PTR(thisfilter->abstract); deflateEnd(&(data->strm)); pefree(data->inbuf, data->persistent); pefree(data->outbuf, data->persistent); @@ -284,7 +286,7 @@ static php_stream_filter_ops php_zlib_deflate_ops = { /* {{{ zlib.* common factory */ -static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *filterparams, int persistent TSRMLS_DC) +static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *filterparams, int persistent) { php_stream_filter_ops *fops = NULL; php_zlib_filter_data *data; @@ -293,7 +295,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, E_WARNING, "Failed allocating %zd bytes", sizeof(php_zlib_filter_data)); return NULL; } @@ -305,39 +307,35 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f data->strm.avail_out = data->outbuf_len = data->inbuf_len = 0x8000; 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, 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, E_WARNING, "Failed allocating %zd bytes", data->outbuf_len); pefree(data->inbuf, persistent); pefree(data, persistent); return NULL; } - + data->strm.data_type = Z_ASCII; if (strcasecmp(filtername, "zlib.inflate") == 0) { int windowBits = -MAX_WBITS; if (filterparams) { - zval **tmpzval; + zval *tmpzval; if ((Z_TYPE_P(filterparams) == IS_ARRAY || Z_TYPE_P(filterparams) == IS_OBJECT) && - zend_hash_find(HASH_OF(filterparams), "window", sizeof("window"), (void **) &tmpzval) == SUCCESS) { - zval tmp; - + (tmpzval = zend_hash_str_find(HASH_OF(filterparams), "window", sizeof("window") - 1))) { /* log-2 base of history window (9 - 15) */ - tmp = **tmpzval; - zval_copy_ctor(&tmp); - convert_to_long(&tmp); - if (Z_LVAL(tmp) < -MAX_WBITS || Z_LVAL(tmp) > MAX_WBITS + 32) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter give for window size. (%ld)", Z_LVAL(tmp)); + zend_long tmp = zval_get_long(tmpzval); + if (tmp < -MAX_WBITS || tmp > MAX_WBITS + 32) { + php_error_docref(NULL, E_WARNING, "Invalid parameter give for window size. (%pd)", tmp); } else { - windowBits = Z_LVAL(tmp); + windowBits = tmp; } } } @@ -354,7 +352,8 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f if (filterparams) { - zval **tmpzval, tmp; + zval *tmpzval; + zend_long tmp; /* filterparams can either be a scalar value to indicate compression level (shortcut method) Or can be a hash containing one or more of 'window', 'memory', and/or 'level' members. */ @@ -362,34 +361,28 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f switch (Z_TYPE_P(filterparams)) { case IS_ARRAY: case IS_OBJECT: - if (zend_hash_find(HASH_OF(filterparams), "memory", sizeof("memory"), (void**) &tmpzval) == SUCCESS) { - tmp = **tmpzval; - zval_copy_ctor(&tmp); - convert_to_long(&tmp); - + if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "memory", sizeof("memory") -1))) { /* Memory Level (1 - 9) */ - if (Z_LVAL(tmp) < 1 || Z_LVAL(tmp) > MAX_MEM_LEVEL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter give for memory level. (%ld)", Z_LVAL(tmp)); + tmp = zval_get_long(tmpzval); + if (tmp < 1 || tmp > MAX_MEM_LEVEL) { + php_error_docref(NULL, E_WARNING, "Invalid parameter give for memory level. (%pd)", tmp); } else { - memLevel = Z_LVAL(tmp); + memLevel = tmp; } } - if (zend_hash_find(HASH_OF(filterparams), "window", sizeof("window"), (void**) &tmpzval) == SUCCESS) { - tmp = **tmpzval; - zval_copy_ctor(&tmp); - convert_to_long(&tmp); - + if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "window", sizeof("window") - 1))) { /* log-2 base of history window (9 - 15) */ - if (Z_LVAL(tmp) < -MAX_WBITS || Z_LVAL(tmp) > MAX_WBITS + 16) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter give for window size. (%ld)", Z_LVAL(tmp)); + tmp = zval_get_long(tmpzval); + if (tmp < -MAX_WBITS || tmp > MAX_WBITS + 16) { + php_error_docref(NULL, E_WARNING, "Invalid parameter give for window size. (%pd)", tmp); } else { - windowBits = Z_LVAL(tmp); + windowBits = tmp; } } - if (zend_hash_find(HASH_OF(filterparams), "level", sizeof("level"), (void**) &tmpzval) == SUCCESS) { - tmp = **tmpzval; + if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "level", sizeof("level") - 1))) { + tmp = zval_get_long(tmpzval); /* Pseudo pass through to catch level validating code */ goto factory_setlevel; @@ -398,20 +391,17 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f case IS_STRING: case IS_DOUBLE: case IS_LONG: - tmp = *filterparams; + tmp = zval_get_long(filterparams); factory_setlevel: - zval_copy_ctor(&tmp); - convert_to_long(&tmp); - /* Set compression level within reason (-1 == default, 0 == none, 1-9 == least to most compression */ - if (Z_LVAL(tmp) < -1 || Z_LVAL(tmp) > 9) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid compression level specified. (%ld)", Z_LVAL(tmp)); + if (tmp < -1 || tmp > 9) { + php_error_docref(NULL, E_WARNING, "Invalid compression level specified. (%pd)", tmp); } else { - level = Z_LVAL(tmp); + level = tmp; } break; default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid filter parameter, ignored"); + php_error_docref(NULL, 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 4c00d76138..4c67db6e39 100644 --- a/ext/zlib/zlib_fopen_wrapper.c +++ b/ext/zlib/zlib_fopen_wrapper.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -32,38 +32,40 @@ struct php_gz_stream_data_t { php_stream *stream; }; -static size_t php_gziop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) +static size_t php_gziop_read(php_stream *stream, char *buf, size_t count) { struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract; int read; - + + /* XXX this needs to be looped for the case count > UINT_MAX */ read = gzread(self->gz_file, buf, count); - + if (gzeof(self->gz_file)) { stream->eof = 1; } - - return (read < 0) ? 0 : read; + + return (size_t)((read < 0) ? 0 : read); } -static size_t php_gziop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) +static size_t php_gziop_write(php_stream *stream, const char *buf, size_t count) { struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract; int wrote; + /* XXX this needs to be looped for the case count > UINT_MAX */ wrote = gzwrite(self->gz_file, (char *) buf, count); - return (wrote < 0) ? 0 : wrote; + return (size_t)((wrote < 0) ? 0 : wrote); } -static int php_gziop_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) +static int php_gziop_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs) { struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract; assert(self != NULL); if (whence == SEEK_END) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "SEEK_END is not supported"); + php_error_docref(NULL, E_WARNING, "SEEK_END is not supported"); return -1; } *newoffs = gzseek(self->gz_file, offset, whence); @@ -71,11 +73,11 @@ static int php_gziop_seek(php_stream *stream, off_t offset, int whence, off_t *n return (*newoffs < 0) ? -1 : 0; } -static int php_gziop_close(php_stream *stream, int close_handle TSRMLS_DC) +static int php_gziop_close(php_stream *stream, int close_handle) { struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract; int ret = EOF; - + if (close_handle) { if (self->gz_file) { ret = gzclose(self->gz_file); @@ -91,7 +93,7 @@ static int php_gziop_close(php_stream *stream, int close_handle TSRMLS_DC) return ret; } -static int php_gziop_flush(php_stream *stream TSRMLS_DC) +static int php_gziop_flush(php_stream *stream) { struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract; @@ -102,14 +104,14 @@ php_stream_ops php_stream_gzio_ops = { php_gziop_write, php_gziop_read, php_gziop_close, php_gziop_flush, "ZLIB", - php_gziop_seek, + php_gziop_seek, NULL, /* cast */ NULL, /* stat */ NULL /* set_option */ }; -php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, - char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) +php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, + zend_string **opened_path, php_stream_context *context STREAMS_DC) { struct php_gz_stream_data_t *self; php_stream *stream = NULL, *innerstream = NULL; @@ -117,19 +119,19 @@ php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, const char *path, con /* sanity check the stream: it can be either read-only or write-only */ if (strchr(mode, '+')) { if (options & REPORT_ERRORS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot open a zlib stream for reading and writing at the same time!"); + php_error_docref(NULL, E_WARNING, "cannot open a zlib stream for reading and writing at the same time!"); } return NULL; } - + if (strncasecmp("compress.zlib://", path, 16) == 0) { path += 16; } else if (strncasecmp("zlib:", path, 5) == 0) { path += 5; } - + innerstream = php_stream_open_wrapper_ex(path, mode, STREAM_MUST_SEEK | options | STREAM_WILL_CAST, opened_path, context); - + if (innerstream) { php_socket_t fd; @@ -150,7 +152,7 @@ php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, const char *path, con efree(self); if (options & REPORT_ERRORS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "gzopen failed"); + php_error_docref(NULL, E_WARNING, "gzopen failed"); } } diff --git a/ext/zlib/zlib_win32_howto.txt b/ext/zlib/zlib_win32_howto.txt index e2a2b79cc7..59ff3c4f4c 100644 --- a/ext/zlib/zlib_win32_howto.txt +++ b/ext/zlib/zlib_win32_howto.txt @@ -7,7 +7,7 @@ php_build\zlib\include\zlib.h php_build\zlib\include\zconf.h php_build\zlib\lib\zlibstat.lib -php_build is a directory at the same level as php5. +php_build is a directory at the same level as php7. Start Visual Studio, load php_modules.dsw, select the ZLIB projects, and build it. |