com php-src: Add strategy option to deflate_init(): e xt/zlib/zlib.c
| From: | Bob Weinand | Date: | Fri, 15 May 2015 00:28:38 +0000 |
| Subject: | com php-src: Add strategy option to deflate_init(): e xt/zlib/zlib.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-86767@lists.php.net to get a copy of this message | ||
Commit: 227a21b297c73f09e15e72a80c21254554d49d66
Author: Bob Weinand <bobwei9@hotmail.com> Fri, 15 May 2015 02:28:22 +0200
Parents: dd17e18f41439ecf04eda48420771e1753ee77cd
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=227a21b297c73f09e15e72a80c21254554d49d66
Log:
Add strategy option to deflate_init()
Changed paths:
M ext/zlib/zlib.c
Diff:
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index 2b9b34e..f09ba00 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -982,7 +982,7 @@ PHP_FUNCTION(inflate_add)
PHP_FUNCTION(deflate_init)
{
z_stream *ctx;
- zend_long encoding, level = -1, memory = 8, window = 15;
+ zend_long encoding, level = -1, memory = 8, window = 15, strategy = Z_DEFAULT_STRATEGY;
char *dict = NULL;
size_t dictlen = 0;
HashTable *options = 0;
@@ -1012,11 +1012,24 @@ PHP_FUNCTION(deflate_init)
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);
+ php_error_docref(NULL, E_WARNING, "zlib window size (logarithm) (%pd) must be within
8..15", window);
RETURN_FALSE;
}
- /* @TODO: in the future we may add "strategy" option */
+ 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", strategy);
+ RETURN_FALSE;
+ }
if (!zlib_create_dictionary_string(options, &dict, &dictlen)) {
RETURN_FALSE;
@@ -1043,7 +1056,7 @@ PHP_FUNCTION(deflate_init)
encoding &= window;
}
- if (Z_OK == deflateInit2(ctx, level, Z_DEFLATED, encoding, memory, Z_DEFAULT_STRATEGY)) {
+ 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);
@@ -1401,6 +1414,12 @@ static PHP_MINIT_FUNCTION(zlib)
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);