PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/zlib - zlib.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 283 359 78.8 %
Date: 2014-10-22 Functions: 32 35 91.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2014 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca>                       |
      16             :    |          Stefan Röhrich <sr@linux.de>                                |
      17             :    |          Zeev Suraski <zeev@zend.com>                                |
      18             :    |          Jade Nicoletti <nicoletti@nns.ch>                           |
      19             :    |          Michael Wallner <mike@php.net>                              |
      20             :    +----------------------------------------------------------------------+
      21             :  */
      22             : 
      23             : /* $Id$ */
      24             : 
      25             : #ifdef HAVE_CONFIG_H
      26             : #include "config.h"
      27             : #endif
      28             : 
      29             : #include "php.h"
      30             : #include "SAPI.h"
      31             : #include "php_ini.h"
      32             : #include "ext/standard/info.h"
      33             : #include "ext/standard/file.h"
      34             : #include "ext/standard/php_string.h"
      35             : #include "php_zlib.h"
      36             : 
      37             : ZEND_DECLARE_MODULE_GLOBALS(zlib);
      38             : 
      39             : /* {{{ Memory management wrappers */
      40             : 
      41         799 : static voidpf php_zlib_alloc(voidpf opaque, uInt items, uInt size)
      42             : {
      43         799 :         return (voidpf)safe_emalloc(items, size, 0);
      44             : }
      45             : 
      46         799 : static void php_zlib_free(voidpf opaque, voidpf address)
      47             : {
      48         799 :         efree((void*)address);
      49         799 : }
      50             : /* }}} */
      51             : 
      52             : /* {{{ php_zlib_output_conflict_check() */
      53          20 : static int php_zlib_output_conflict_check(const char *handler_name, size_t handler_name_len TSRMLS_DC)
      54             : {
      55          20 :         if (php_output_get_level(TSRMLS_C) > 0) {
      56           5 :                 if (php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME) TSRMLS_CC)
      57           2 :                 ||      php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("ob_gzhandler") TSRMLS_CC)
      58           1 :                 ||  php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("mb_output_handler") TSRMLS_CC)
      59           2 :                 ||      php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("URL-Rewriter") TSRMLS_CC)) {
      60           1 :                         return FAILURE;
      61             :                 }
      62             :         }
      63          19 :         return SUCCESS;
      64             : }
      65             : /* }}} */
      66             : 
      67             : /* {{{ php_zlib_output_encoding() */
      68          36 : static int php_zlib_output_encoding(TSRMLS_D)
      69             : {
      70             :         zval *enc;
      71             : 
      72          36 :         if (!ZLIBG(compression_coding)) {
      73          25 :                 zend_string *name = zend_string_init("_SERVER", sizeof("_SERVER") - 1, 0);
      74          25 :                 zend_is_auto_global(name TSRMLS_CC);
      75             :                 zend_string_release(name);
      76          50 :                 if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
      77          25 :                         (enc = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING") - 1))) {
      78          16 :                         convert_to_string(enc);
      79          16 :                         if (strstr(Z_STRVAL_P(enc), "gzip")) {
      80          16 :                                 ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_GZIP;
      81           0 :                         } else if (strstr(Z_STRVAL_P(enc), "deflate")) {
      82           0 :                                 ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_DEFLATE;
      83             :                         }
      84             :                 }
      85             :         }
      86          36 :         return ZLIBG(compression_coding);
      87             : }
      88             : /* }}} */
      89             : 
      90             : /* {{{ php_zlib_output_handler_ex() */
      91          16 : static int php_zlib_output_handler_ex(php_zlib_context *ctx, php_output_context *output_context)
      92             : {
      93          16 :         int flags = Z_SYNC_FLUSH;
      94             :         PHP_OUTPUT_TSRMLS(output_context);
      95             : 
      96          16 :         if (output_context->op & PHP_OUTPUT_HANDLER_START) {
      97             :                 /* start up */
      98          16 :                 if (Z_OK != deflateInit2(&ctx->Z, ZLIBG(output_compression_level), Z_DEFLATED, ZLIBG(compression_coding), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) {
      99           0 :                         return FAILURE;
     100             :                 }
     101             :         }
     102             : 
     103          16 :         if (output_context->op & PHP_OUTPUT_HANDLER_CLEAN) {
     104             :                 /* free buffers */
     105           0 :                 deflateEnd(&ctx->Z);
     106             : 
     107           0 :                 if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) {
     108             :                         /* discard */
     109           0 :                         return SUCCESS;
     110             :                 } else {
     111             :                         /* restart */
     112           0 :                         if (Z_OK != deflateInit2(&ctx->Z, ZLIBG(output_compression_level), Z_DEFLATED, ZLIBG(compression_coding), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) {
     113           0 :                                 return FAILURE;
     114             :                         }
     115           0 :                         ctx->buffer.used = 0;
     116             :                 }
     117             :         } else {
     118          16 :                 if (output_context->in.used) {
     119             :                         /* append input */
     120          10 :                         if (ctx->buffer.free < output_context->in.used) {
     121          10 :                                 if (!(ctx->buffer.aptr = erealloc_recoverable(ctx->buffer.data, ctx->buffer.used + ctx->buffer.free + output_context->in.used))) {
     122           0 :                                         deflateEnd(&ctx->Z);
     123           0 :                                         return FAILURE;
     124             :                                 }
     125          10 :                                 ctx->buffer.data = ctx->buffer.aptr;
     126          10 :                                 ctx->buffer.free += output_context->in.used;
     127             :                         }
     128          10 :                         memcpy(ctx->buffer.data + ctx->buffer.used, output_context->in.data, output_context->in.used);
     129          10 :                         ctx->buffer.free -= output_context->in.used;
     130          10 :                         ctx->buffer.used += output_context->in.used;
     131             :                 }
     132          16 :                 output_context->out.size = PHP_ZLIB_BUFFER_SIZE_GUESS(output_context->in.used);
     133          16 :                 output_context->out.data = emalloc(output_context->out.size);
     134          16 :                 output_context->out.free = 1;
     135          16 :                 output_context->out.used = 0;
     136             : 
     137          16 :                 ctx->Z.avail_in = ctx->buffer.used;
     138          16 :                 ctx->Z.next_in = (Bytef *) ctx->buffer.data;
     139          16 :                 ctx->Z.avail_out = output_context->out.size;
     140          16 :                 ctx->Z.next_out = (Bytef *) output_context->out.data;
     141             : 
     142          16 :                 if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) {
     143          16 :                         flags = Z_FINISH;
     144           0 :                 } else if (output_context->op & PHP_OUTPUT_HANDLER_FLUSH) {
     145           0 :                         flags = Z_FULL_FLUSH;
     146             :                 }
     147             : 
     148          16 :                 switch (deflate(&ctx->Z, flags)) {
     149             :                         case Z_OK:
     150           0 :                                 if (flags == Z_FINISH) {
     151           0 :                                         deflateEnd(&ctx->Z);
     152           0 :                                         return FAILURE;
     153             :                                 }
     154             :                         case Z_STREAM_END:
     155          16 :                                 if (ctx->Z.avail_in) {
     156           0 :                                         memmove(ctx->buffer.data, ctx->buffer.data + ctx->buffer.used - ctx->Z.avail_in, ctx->Z.avail_in);
     157             :                                 }
     158          16 :                                 ctx->buffer.free += ctx->buffer.used - ctx->Z.avail_in;
     159          16 :                                 ctx->buffer.used = ctx->Z.avail_in;
     160          16 :                                 output_context->out.used = output_context->out.size - ctx->Z.avail_out;
     161          16 :                                 break;
     162             :                         default:
     163           0 :                                 deflateEnd(&ctx->Z);
     164           0 :                                 return FAILURE;
     165             :                 }
     166             : 
     167          16 :                 if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) {
     168          16 :                         deflateEnd(&ctx->Z);
     169             :                 }
     170             :         }
     171             : 
     172          16 :         return SUCCESS;
     173             : }
     174             : /* }}} */
     175             : 
     176             : /* {{{ php_zlib_output_handler() */
     177          20 : static int php_zlib_output_handler(void **handler_context, php_output_context *output_context)
     178             : {
     179          20 :         php_zlib_context *ctx = *(php_zlib_context **) handler_context;
     180             :         PHP_OUTPUT_TSRMLS(output_context);
     181             : 
     182          20 :         if (!php_zlib_output_encoding(TSRMLS_C)) {
     183             :                 /* "Vary: Accept-Encoding" header sent along uncompressed content breaks caching in MSIE,
     184             :                         so let's just send it with successfully compressed content or unless the complete
     185             :                         buffer gets discarded, see http://bugs.php.net/40325;
     186             : 
     187             :                         Test as follows:
     188             :                         +Vary: $ HTTP_ACCEPT_ENCODING=gzip ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n";'
     189             :                         +Vary: $ HTTP_ACCEPT_ENCODING= ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n";'
     190             :                         -Vary: $ HTTP_ACCEPT_ENCODING=gzip ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n"; ob_end_clean();'
     191             :                         -Vary: $ HTTP_ACCEPT_ENCODING= ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n"; ob_end_clean();'
     192             :                 */
     193           7 :                 if ((output_context->op & PHP_OUTPUT_HANDLER_START)
     194           3 :                 &&      (output_context->op != (PHP_OUTPUT_HANDLER_START|PHP_OUTPUT_HANDLER_CLEAN|PHP_OUTPUT_HANDLER_FINAL))
     195             :                 ) {
     196           3 :                         sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0 TSRMLS_CC);
     197             :                 }
     198           4 :                 return FAILURE;
     199             :         }
     200             : 
     201          16 :         if (SUCCESS != php_zlib_output_handler_ex(ctx, output_context)) {
     202           0 :                 return FAILURE;
     203             :         }
     204             : 
     205          16 :         if (!(output_context->op & PHP_OUTPUT_HANDLER_CLEAN)) {
     206             :                 int flags;
     207             : 
     208          16 :                 if (SUCCESS == php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS, &flags TSRMLS_CC)) {
     209             :                         /* only run this once */
     210          16 :                         if (!(flags & PHP_OUTPUT_HANDLER_STARTED)) {
     211          16 :                                 if (SG(headers_sent) || !ZLIBG(output_compression)) {
     212           7 :                                         deflateEnd(&ctx->Z);
     213           7 :                                         return FAILURE;
     214             :                                 }
     215           9 :                                 switch (ZLIBG(compression_coding)) {
     216             :                                         case PHP_ZLIB_ENCODING_GZIP:
     217           9 :                                                 sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1 TSRMLS_CC);
     218           9 :                                                 break;
     219             :                                         case PHP_ZLIB_ENCODING_DEFLATE:
     220           0 :                                                 sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1 TSRMLS_CC);
     221           0 :                                                 break;
     222             :                                         default:
     223           0 :                                                 deflateEnd(&ctx->Z);
     224           0 :                                                 return FAILURE;
     225             :                                 }
     226           9 :                                 sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0 TSRMLS_CC);
     227           9 :                                 php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE, NULL TSRMLS_CC);
     228             :                         }
     229             :                 }
     230             :         }
     231             : 
     232           9 :         return SUCCESS;
     233             : }
     234             : /* }}} */
     235             : 
     236             : /* {{{ php_zlib_output_handler_context_init() */
     237          20 : static php_zlib_context *php_zlib_output_handler_context_init(TSRMLS_D)
     238             : {
     239          20 :         php_zlib_context *ctx = (php_zlib_context *) ecalloc(1, sizeof(php_zlib_context));
     240          20 :         ctx->Z.zalloc = php_zlib_alloc;
     241          20 :         ctx->Z.zfree = php_zlib_free;
     242          20 :         return ctx;
     243             : }
     244             : /* }}} */
     245             : 
     246             : /* {{{ php_zlib_output_handler_context_dtor() */
     247          20 : static void php_zlib_output_handler_context_dtor(void *opaq TSRMLS_DC)
     248             : {
     249          20 :         php_zlib_context *ctx = (php_zlib_context *) opaq;
     250             : 
     251          20 :         if (ctx) {
     252          20 :                 if (ctx->buffer.data) {
     253          10 :                         efree(ctx->buffer.data);
     254             :                 }
     255          20 :                 efree(ctx);
     256             :         }
     257          20 : }
     258             : /* }}} */
     259             : 
     260             : /* {{{ php_zlib_output_handler_init() */
     261          20 : 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)
     262             : {
     263          20 :         php_output_handler *h = NULL;
     264             : 
     265          20 :         if (!ZLIBG(output_compression)) {
     266           8 :                 ZLIBG(output_compression) = chunk_size ? chunk_size : PHP_OUTPUT_HANDLER_DEFAULT_SIZE;
     267             :         }
     268             : 
     269          20 :     ZLIBG(handler_registered) = 1;
     270             : 
     271          20 :         if ((h = php_output_handler_create_internal(handler_name, handler_name_len, php_zlib_output_handler, chunk_size, flags TSRMLS_CC))) {
     272          20 :                 php_output_handler_set_context(h, php_zlib_output_handler_context_init(TSRMLS_C), php_zlib_output_handler_context_dtor TSRMLS_CC);
     273             :         }
     274             : 
     275          20 :         return h;
     276             : }
     277             : /* }}} */
     278             : 
     279             : /* {{{ php_zlib_output_compression_start() */
     280       20380 : static void php_zlib_output_compression_start(TSRMLS_D)
     281             : {
     282             :         zval zoh;
     283             :         php_output_handler *h;
     284             : 
     285       20380 :         switch (ZLIBG(output_compression)) {
     286             :                 case 0:
     287       20365 :                         break;
     288             :                 case 1:
     289          14 :                         ZLIBG(output_compression) = PHP_OUTPUT_HANDLER_DEFAULT_SIZE;
     290             :                         /* break omitted intentionally */
     291             :                 default:
     292          37 :                         if (    php_zlib_output_encoding(TSRMLS_C) &&
     293          11 :                                         (h = php_zlib_output_handler_init(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME), ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC)) &&
     294          11 :                                         (SUCCESS == php_output_handler_start(h TSRMLS_CC))) {
     295          11 :                                 if (ZLIBG(output_handler) && *ZLIBG(output_handler)) {
     296           0 :                                         ZVAL_STRING(&zoh, ZLIBG(output_handler));
     297           0 :                                         php_output_start_user(&zoh, ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
     298           0 :                                         zval_ptr_dtor(&zoh);
     299             :                                 }
     300             :                         }
     301             :                         break;
     302             :         }
     303       20380 : }
     304             : /* }}} */
     305             : 
     306             : /* {{{ php_zlib_encode() */
     307         120 : static zend_string *php_zlib_encode(const char *in_buf, size_t in_len, int encoding, int level TSRMLS_DC)
     308             : {
     309             :         int status;
     310             :         z_stream Z;
     311             :         zend_string *out;
     312             : 
     313         120 :         memset(&Z, 0, sizeof(z_stream));
     314         120 :         Z.zalloc = php_zlib_alloc;
     315         120 :         Z.zfree = php_zlib_free;
     316             : 
     317         120 :         if (Z_OK == (status = deflateInit2(&Z, level, Z_DEFLATED, encoding, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) {
     318         240 :                 out = zend_string_alloc(PHP_ZLIB_BUFFER_SIZE_GUESS(in_len), 0);
     319             : 
     320         120 :                 Z.next_in = (Bytef *) in_buf;
     321         120 :                 Z.next_out = (Bytef *) out->val;
     322         120 :                 Z.avail_in = in_len;
     323         120 :                 Z.avail_out = out->len;
     324             : 
     325         120 :                 status = deflate(&Z, Z_FINISH);
     326         120 :                 deflateEnd(&Z);
     327             : 
     328         120 :                 if (Z_STREAM_END == status) {
     329             :                         /* size buffer down to actual length */
     330         240 :                         out = zend_string_realloc(out, Z.total_out, 0);
     331         120 :                         out->val[out->len] = '\0';
     332         120 :                         return out;
     333             :                 } else {
     334             :                         zend_string_free(out);
     335             :                 }
     336             :         }
     337             : 
     338           0 :         php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status));
     339           0 :         return NULL;
     340             : }
     341             : /* }}} */
     342             : 
     343             : /* {{{ php_zlib_inflate_rounds() */
     344          81 : static inline int php_zlib_inflate_rounds(z_stream *Z, size_t max, char **buf, size_t *len)
     345             : {
     346          81 :         int status, round = 0;
     347          81 :         php_zlib_buffer buffer = {NULL, NULL, 0, 0, 0};
     348             : 
     349          81 :         *buf = NULL;
     350          81 :         *len = 0;
     351             : 
     352          81 :         buffer.size = (max && (max < Z->avail_in)) ? max : Z->avail_in;
     353             : 
     354             :         do {
     355         499 :                 if ((max && (max <= buffer.used)) || !(buffer.aptr = erealloc_recoverable(buffer.data, buffer.size))) {
     356           2 :                         status = Z_MEM_ERROR;
     357             :                 } else {
     358         495 :                         buffer.data = buffer.aptr;
     359         495 :                         Z->avail_out = buffer.free = buffer.size - buffer.used;
     360         495 :                         Z->next_out = (Bytef *) buffer.data + buffer.used;
     361             : #if 0
     362             :                         fprintf(stderr, "\n%3d: %3d PRIOR: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out);
     363             : #endif
     364         495 :                         status = inflate(Z, Z_NO_FLUSH);
     365             : 
     366         495 :                         buffer.used += buffer.free - Z->avail_out;
     367         495 :                         buffer.free = Z->avail_out;
     368             : #if 0
     369             :                         fprintf(stderr, "%3d: %3d AFTER: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out);
     370             : #endif
     371         495 :                         buffer.size += (buffer.size >> 3) + 1;
     372             :                 }
     373         497 :         } while ((Z_BUF_ERROR == status || (Z_OK == status && Z->avail_in)) && ++round < 100);
     374             : 
     375          81 :         if (status == Z_STREAM_END) {
     376          71 :                 buffer.data = erealloc(buffer.data, buffer.used + 1);
     377          71 :                 buffer.data[buffer.used] = '\0';
     378          71 :                 *buf = buffer.data;
     379          71 :                 *len = buffer.used;
     380             :         } else {
     381          10 :                 if (buffer.data) {
     382          10 :                         efree(buffer.data);
     383             :                 }
     384             :                 /* HACK: See zlib/examples/zpipe.c inf() function for explanation. */
     385             :                 /* This works as long as this function is not used for streaming. Required to catch very short invalid data. */
     386          10 :                 status = (status == Z_OK) ? Z_DATA_ERROR : status;
     387             :         }
     388          81 :         return status;
     389             : }
     390             : /* }}} */
     391             : 
     392             : /* {{{ php_zlib_decode() */
     393          85 : 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)
     394             : {
     395          85 :         int status = Z_DATA_ERROR;
     396             :         z_stream Z;
     397             : 
     398          85 :         memset(&Z, 0, sizeof(z_stream));
     399          85 :         Z.zalloc = php_zlib_alloc;
     400          85 :         Z.zfree = php_zlib_free;
     401             : 
     402          85 :         if (in_len) {
     403             : retry_raw_inflate:
     404          81 :                 status = inflateInit2(&Z, encoding);
     405          81 :                 if (Z_OK == status) {
     406          81 :                         Z.next_in = (Bytef *) in_buf;
     407          81 :                         Z.avail_in = in_len + 1; /* NOTE: data must be zero terminated */
     408             : 
     409          81 :                         switch (status = php_zlib_inflate_rounds(&Z, max_len, out_buf, out_len)) {
     410             :                                 case Z_STREAM_END:
     411          71 :                                         inflateEnd(&Z);
     412          71 :                                         return SUCCESS;
     413             : 
     414             :                                 case Z_DATA_ERROR:
     415             :                                         /* raw deflated data? */
     416           8 :                                         if (PHP_ZLIB_ENCODING_ANY == encoding) {
     417           0 :                                                 inflateEnd(&Z);
     418           0 :                                                 encoding = PHP_ZLIB_ENCODING_RAW;
     419           0 :                                                 goto retry_raw_inflate;
     420             :                                         }
     421             :                         }
     422          10 :                         inflateEnd(&Z);
     423             :                 }
     424             :         }
     425             : 
     426          14 :         *out_buf = NULL;
     427          14 :         *out_len = 0;
     428             : 
     429          14 :         php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status));
     430          14 :         return FAILURE;
     431             : }
     432             : /* }}} */
     433             : 
     434             : /* {{{ php_zlib_cleanup_ob_gzhandler_mess() */
     435       20416 : static void php_zlib_cleanup_ob_gzhandler_mess(TSRMLS_D)
     436             : {
     437       20416 :         if (ZLIBG(ob_gzhandler)) {
     438           0 :                 deflateEnd(&(ZLIBG(ob_gzhandler)->Z));
     439           0 :                 php_zlib_output_handler_context_dtor(ZLIBG(ob_gzhandler) TSRMLS_CC);
     440           0 :                 ZLIBG(ob_gzhandler) = NULL;
     441             :         }
     442       20416 : }
     443             : /* }}} */
     444             : 
     445             : /* {{{ proto string ob_gzhandler(string data, int flags)
     446             :    Legacy hack */
     447           1 : static PHP_FUNCTION(ob_gzhandler)
     448             : {
     449             :         char *in_str;
     450             :         size_t in_len;
     451           1 :         zend_long flags = 0;
     452           1 :         php_output_context ctx = {0};
     453             :         int encoding, rv;
     454             : 
     455             :         /*
     456             :          * NOTE that the real ob_gzhandler is an alias to "zlib output compression".
     457             :          * This is a really bad hack, because
     458             :          * - we have to initialize a php_zlib_context on demand
     459             :          * - we have to clean it up in RSHUTDOWN
     460             :          * - OG(running) is not set or set to any other output handler
     461             :          * - we have to mess around with php_output_context */
     462             : 
     463           1 :         if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &in_str, &in_len, &flags)) {
     464           0 :                 RETURN_FALSE;
     465             :         }
     466             : 
     467           1 :         if (!(encoding = php_zlib_output_encoding(TSRMLS_C))) {
     468           1 :                 RETURN_FALSE;
     469             :         }
     470             : 
     471           0 :         if (flags & PHP_OUTPUT_HANDLER_START) {
     472           0 :                 switch (encoding) {
     473             :                         case PHP_ZLIB_ENCODING_GZIP:
     474           0 :                                 sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1 TSRMLS_CC);
     475           0 :                                 break;
     476             :                         case PHP_ZLIB_ENCODING_DEFLATE:
     477           0 :                                 sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1 TSRMLS_CC);
     478             :                                 break;
     479             :                 }
     480           0 :                 sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0 TSRMLS_CC);
     481             :         }
     482             : 
     483           0 :         if (!ZLIBG(ob_gzhandler)) {
     484           0 :                 ZLIBG(ob_gzhandler) = php_zlib_output_handler_context_init(TSRMLS_C);
     485             :         }
     486             : 
     487             :         TSRMLS_SET_CTX(ctx.tsrm_ls);
     488           0 :         ctx.op = flags;
     489           0 :         ctx.in.data = in_str;
     490           0 :         ctx.in.used = in_len;
     491             : 
     492           0 :         rv = php_zlib_output_handler_ex(ZLIBG(ob_gzhandler), &ctx);
     493             : 
     494           0 :         if (SUCCESS != rv) {
     495           0 :                 if (ctx.out.data && ctx.out.free) {
     496           0 :                         efree(ctx.out.data);
     497             :                 }
     498           0 :                 php_zlib_cleanup_ob_gzhandler_mess(TSRMLS_C);
     499           0 :                 RETURN_FALSE;
     500             :         }
     501             : 
     502           0 :         if (ctx.out.data) {
     503           0 :                 RETVAL_STRINGL(ctx.out.data, ctx.out.used);
     504           0 :                 if (ctx.out.free) {
     505           0 :                         efree(ctx.out.data);
     506             :                 }
     507             :         } else {
     508           0 :                 RETVAL_EMPTY_STRING();
     509             :         }
     510             : }
     511             : /* }}} */
     512             : 
     513             : /* {{{ proto string zlib_get_coding_type(void)
     514             :    Returns the coding type used for output compression */
     515           0 : static PHP_FUNCTION(zlib_get_coding_type)
     516             : {
     517           0 :         if (zend_parse_parameters_none() == FAILURE) {
     518           0 :                 return;
     519             :         }
     520           0 :         switch (ZLIBG(compression_coding)) {
     521             :                 case PHP_ZLIB_ENCODING_GZIP:
     522           0 :                         RETURN_STRINGL("gzip", sizeof("gzip") - 1);
     523             :                 case PHP_ZLIB_ENCODING_DEFLATE:
     524           0 :                         RETURN_STRINGL("deflate", sizeof("deflate") - 1);
     525             :                 default:
     526           0 :                         RETURN_FALSE;
     527             :         }
     528             : }
     529             : /* }}} */
     530             : 
     531             : /* {{{ proto array gzfile(string filename [, int use_include_path])
     532             :    Read and uncompress entire .gz-file into an array */
     533          73 : static PHP_FUNCTION(gzfile)
     534             : {
     535             :         char *filename;
     536             :         size_t filename_len;
     537          73 :         int flags = REPORT_ERRORS;
     538          73 :         char buf[8192] = {0};
     539          73 :         register int i = 0;
     540          73 :         zend_long use_include_path = 0;
     541             :         php_stream *stream;
     542             : 
     543          73 :         if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path)) {
     544          25 :                 return;
     545             :         }
     546             : 
     547          48 :         if (use_include_path) {
     548          16 :                 flags |= USE_PATH;
     549             :         }
     550             : 
     551             :         /* using a stream here is a bit more efficient (resource wise) than php_gzopen_wrapper */
     552          48 :         stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC TSRMLS_CC);
     553             : 
     554          48 :         if (!stream) {
     555             :                 /* Error reporting is already done by stream code */
     556          21 :                 RETURN_FALSE;
     557             :         }
     558             : 
     559             :         /* Initialize return array */
     560          27 :         array_init(return_value);
     561             : 
     562             :         /* Now loop through the file and do the magic quotes thing if needed */
     563          27 :         memset(buf, 0, sizeof(buf));
     564             :             
     565         195 :         while (php_stream_gets(stream, buf, sizeof(buf) - 1) != NULL) {
     566         141 :                 add_index_string(return_value, i++, buf);
     567             :         }
     568          27 :         php_stream_close(stream);
     569             : }
     570             : /* }}} */
     571             : 
     572             : /* {{{ proto resource gzopen(string filename, string mode [, int use_include_path])
     573             :    Open a .gz-file and return a .gz-file pointer */
     574         208 : static PHP_FUNCTION(gzopen)
     575             : {
     576             :         char *filename;
     577             :         char *mode;
     578             :         size_t filename_len, mode_len;
     579         208 :         int flags = REPORT_ERRORS;
     580             :         php_stream *stream;
     581         208 :         zend_long use_include_path = 0;
     582             : 
     583         208 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) {
     584          27 :                 return;
     585             :         }
     586             : 
     587         181 :         if (use_include_path) {
     588          23 :                 flags |= USE_PATH;
     589             :         }
     590             : 
     591         181 :         stream = php_stream_gzopen(NULL, filename, mode, flags, NULL, NULL STREAMS_CC TSRMLS_CC);
     592             : 
     593         181 :         if (!stream) {
     594          52 :                 RETURN_FALSE;
     595             :         }
     596         129 :         php_stream_to_zval(stream, return_value);
     597             : }
     598             : /* }}} */
     599             : 
     600             : /* {{{ proto int readgzfile(string filename [, int use_include_path])
     601             :    Output a .gz-file */
     602          68 : static PHP_FUNCTION(readgzfile)
     603             : {
     604             :         char *filename;
     605             :         size_t filename_len;
     606          68 :         int flags = REPORT_ERRORS;
     607             :         php_stream *stream;
     608             :         size_t size;
     609          68 :         zend_long use_include_path = 0;
     610             : 
     611          68 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) {
     612          23 :                 return;
     613             :         }
     614             : 
     615          45 :         if (use_include_path) {
     616          14 :                 flags |= USE_PATH;
     617             :         }
     618             : 
     619          45 :         stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC TSRMLS_CC);
     620             : 
     621          45 :         if (!stream) {
     622          20 :                 RETURN_FALSE;
     623             :         }
     624          25 :         size = php_stream_passthru(stream);
     625          25 :         php_stream_close(stream);
     626          25 :         RETURN_LONG(size);
     627             : }
     628             : /* }}} */
     629             : 
     630             : #define PHP_ZLIB_ENCODE_FUNC(name, default_encoding) \
     631             : static PHP_FUNCTION(name) \
     632             : { \
     633             :         zend_string *in, *out; \
     634             :         zend_long level = -1; \
     635             :         zend_long encoding = default_encoding; \
     636             :         if (default_encoding) { \
     637             :                 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|ll", &in, &level, &encoding)) { \
     638             :                         return; \
     639             :                 } \
     640             :         } else { \
     641             :                 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sl|l", &in, &encoding, &level)) { \
     642             :                         return; \
     643             :                 } \
     644             :         } \
     645             :         if (level < -1 || level > 9) { \
     646             :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "compression level (%pd) must be within -1..9", level); \
     647             :                 RETURN_FALSE; \
     648             :         } \
     649             :         switch (encoding) { \
     650             :                 case PHP_ZLIB_ENCODING_RAW: \
     651             :                 case PHP_ZLIB_ENCODING_GZIP: \
     652             :                 case PHP_ZLIB_ENCODING_DEFLATE: \
     653             :                         break; \
     654             :                 default: \
     655             :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE"); \
     656             :                         RETURN_FALSE; \
     657             :         } \
     658             :         if ((out = php_zlib_encode(in->val, in->len, encoding, level TSRMLS_CC)) == NULL) { \
     659             :                 RETURN_FALSE; \
     660             :         } \
     661             :         RETURN_STR(out); \
     662             : }
     663             : 
     664             : #define PHP_ZLIB_DECODE_FUNC(name, encoding) \
     665             : static PHP_FUNCTION(name) \
     666             : { \
     667             :         char *in_buf, *out_buf; \
     668             :         size_t in_len; \
     669             :         size_t out_len; \
     670             :         zend_long max_len = 0; \
     671             :         if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &in_buf, &in_len, &max_len)) { \
     672             :                 return; \
     673             :         } \
     674             :         if (max_len < 0) { \
     675             :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "length (%pd) must be greater or equal zero", max_len); \
     676             :                 RETURN_FALSE; \
     677             :         } \
     678             :         if (SUCCESS != php_zlib_decode(in_buf, in_len, &out_buf, &out_len, encoding, max_len TSRMLS_CC)) { \
     679             :                 RETURN_FALSE; \
     680             :         } \
     681             :         RETVAL_STRINGL(out_buf, out_len); \
     682             :         efree(out_buf); \
     683             : }
     684             : 
     685             : /* {{{ proto binary zlib_encode(binary data, int encoding[, int level = -1])
     686             :    Compress data with the specified encoding */
     687           0 : PHP_ZLIB_ENCODE_FUNC(zlib_encode, 0);
     688             : /* }}} */
     689             : 
     690             : /* {{{ proto binary zlib_decode(binary data[, int max_decoded_len])
     691             :    Uncompress any raw/gzip/zlib encoded data */
     692           0 : PHP_ZLIB_DECODE_FUNC(zlib_decode, PHP_ZLIB_ENCODING_ANY);
     693             : /* }}} */
     694             : 
     695             : /* NOTE: The naming of these userland functions was quite unlucky */
     696             : /* {{{ proto binary gzdeflate(binary data[, int level = -1[, int encoding = ZLIB_ENCODING_RAW])
     697             :    Encode data with the raw deflate encoding */
     698          48 : PHP_ZLIB_ENCODE_FUNC(gzdeflate, PHP_ZLIB_ENCODING_RAW);
     699             : /* }}} */
     700             : 
     701             : /* {{{ proto binary gzencode(binary data[, int level = -1[, int encoding = ZLIB_ENCODING_GZIP])
     702             :    Encode data with the gzip encoding */
     703          55 : PHP_ZLIB_ENCODE_FUNC(gzencode, PHP_ZLIB_ENCODING_GZIP);
     704             : /* }}} */
     705             : 
     706             : /* {{{ proto binary gzcompress(binary data[, int level = -1[, int encoding = ZLIB_ENCODING_DEFLATE])
     707             :    Encode data with the zlib encoding */
     708          47 : PHP_ZLIB_ENCODE_FUNC(gzcompress, PHP_ZLIB_ENCODING_DEFLATE);
     709             : /* }}} */
     710             : 
     711             : /* {{{ proto binary gzinflate(binary data[, int max_decoded_len])
     712             :    Decode raw deflate encoded data */
     713          90 : PHP_ZLIB_DECODE_FUNC(gzinflate, PHP_ZLIB_ENCODING_RAW);
     714             : /* }}} */
     715             : 
     716             : /* {{{ proto binary gzdecode(binary data[, int max_decoded_len])
     717             :    Decode gzip encoded data */
     718           2 : PHP_ZLIB_DECODE_FUNC(gzdecode, PHP_ZLIB_ENCODING_GZIP);
     719             : /* }}} */
     720             : 
     721             : /* {{{ proto binary gzuncompress(binary data[, int max_decoded_len])
     722             :    Decode zlib encoded data */
     723          76 : PHP_ZLIB_DECODE_FUNC(gzuncompress, PHP_ZLIB_ENCODING_DEFLATE);
     724             : /* }}} */
     725             : 
     726             : #ifdef COMPILE_DL_ZLIB
     727             : ZEND_GET_MODULE(php_zlib)
     728             : #endif
     729             : 
     730             : /* {{{ arginfo */
     731             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ob_gzhandler, 0, 0, 2)
     732             :         ZEND_ARG_INFO(0, data)
     733             :         ZEND_ARG_INFO(0, flags)
     734             : ZEND_END_ARG_INFO()
     735             : 
     736             : ZEND_BEGIN_ARG_INFO(arginfo_zlib_get_coding_type, 0)
     737             : ZEND_END_ARG_INFO()
     738             : 
     739             : ZEND_BEGIN_ARG_INFO_EX(arginfo_gzfile, 0, 0, 1)
     740             :         ZEND_ARG_INFO(0, filename)
     741             :         ZEND_ARG_INFO(0, use_include_path)
     742             : ZEND_END_ARG_INFO()
     743             : 
     744             : ZEND_BEGIN_ARG_INFO_EX(arginfo_gzopen, 0, 0, 2)
     745             :         ZEND_ARG_INFO(0, filename)
     746             :         ZEND_ARG_INFO(0, mode)
     747             :         ZEND_ARG_INFO(0, use_include_path)
     748             : ZEND_END_ARG_INFO()
     749             : 
     750             : ZEND_BEGIN_ARG_INFO_EX(arginfo_readgzfile, 0, 0, 1)
     751             :         ZEND_ARG_INFO(0, filename)
     752             :         ZEND_ARG_INFO(0, use_include_path)
     753             : ZEND_END_ARG_INFO()
     754             : 
     755             : ZEND_BEGIN_ARG_INFO_EX(arginfo_zlib_encode, 0, 0, 2)
     756             :         ZEND_ARG_INFO(0, data)
     757             :         ZEND_ARG_INFO(0, encoding)
     758             :         ZEND_ARG_INFO(0, level)
     759             : ZEND_END_ARG_INFO()
     760             : 
     761             : ZEND_BEGIN_ARG_INFO_EX(arginfo_zlib_decode, 0, 0, 1)
     762             :         ZEND_ARG_INFO(0, data)
     763             :         ZEND_ARG_INFO(0, max_decoded_len)
     764             : ZEND_END_ARG_INFO()
     765             : 
     766             : ZEND_BEGIN_ARG_INFO_EX(arginfo_gzdeflate, 0, 0, 1)
     767             :         ZEND_ARG_INFO(0, data)
     768             :         ZEND_ARG_INFO(0, level)
     769             :         ZEND_ARG_INFO(0, encoding)
     770             : ZEND_END_ARG_INFO()
     771             : 
     772             : ZEND_BEGIN_ARG_INFO_EX(arginfo_gzencode, 0, 0, 1)
     773             :         ZEND_ARG_INFO(0, data)
     774             :         ZEND_ARG_INFO(0, level)
     775             :         ZEND_ARG_INFO(0, encoding)
     776             : ZEND_END_ARG_INFO()
     777             : 
     778             : ZEND_BEGIN_ARG_INFO_EX(arginfo_gzcompress, 0, 0, 1)
     779             :         ZEND_ARG_INFO(0, data)
     780             :         ZEND_ARG_INFO(0, level)
     781             :         ZEND_ARG_INFO(0, encoding)
     782             : ZEND_END_ARG_INFO()
     783             : 
     784             : ZEND_BEGIN_ARG_INFO_EX(arginfo_gzinflate, 0, 0, 1)
     785             :         ZEND_ARG_INFO(0, data)
     786             :         ZEND_ARG_INFO(0, max_decoded_len)
     787             : ZEND_END_ARG_INFO()
     788             : 
     789             : ZEND_BEGIN_ARG_INFO_EX(arginfo_gzdecode, 0, 0, 1)
     790             :         ZEND_ARG_INFO(0, data)
     791             :         ZEND_ARG_INFO(0, max_decoded_len)
     792             : ZEND_END_ARG_INFO()
     793             : 
     794             : ZEND_BEGIN_ARG_INFO_EX(arginfo_gzuncompress, 0, 0, 1)
     795             :         ZEND_ARG_INFO(0, data)
     796             :         ZEND_ARG_INFO(0, max_decoded_len)
     797             : ZEND_END_ARG_INFO()
     798             : 
     799             : ZEND_BEGIN_ARG_INFO_EX(arginfo_gzputs, 0, 0, 2)
     800             :         ZEND_ARG_INFO(0, fp)
     801             :         ZEND_ARG_INFO(0, str)
     802             :         ZEND_ARG_INFO(0, length)
     803             : ZEND_END_ARG_INFO()
     804             : 
     805             : ZEND_BEGIN_ARG_INFO(arginfo_gzpassthru, 0)
     806             :         ZEND_ARG_INFO(0, fp)
     807             : ZEND_END_ARG_INFO()
     808             : 
     809             : ZEND_BEGIN_ARG_INFO_EX(arginfo_gzseek, 0, 0, 2)
     810             :         ZEND_ARG_INFO(0, fp)
     811             :         ZEND_ARG_INFO(0, offset)
     812             :         ZEND_ARG_INFO(0, whence)
     813             : ZEND_END_ARG_INFO()
     814             : 
     815             : ZEND_BEGIN_ARG_INFO(arginfo_gzread, 0)
     816             :         ZEND_ARG_INFO(0, fp)
     817             :         ZEND_ARG_INFO(0, length)
     818             : ZEND_END_ARG_INFO()
     819             : 
     820             : ZEND_BEGIN_ARG_INFO_EX(arginfo_gzgetss, 0, 0, 1)
     821             :         ZEND_ARG_INFO(0, fp)
     822             :         ZEND_ARG_INFO(0, length)
     823             :         ZEND_ARG_INFO(0, allowable_tags)
     824             : ZEND_END_ARG_INFO()
     825             : 
     826             : ZEND_BEGIN_ARG_INFO_EX(arginfo_gzgets, 0, 0, 1)
     827             :         ZEND_ARG_INFO(0, fp)
     828             :         ZEND_ARG_INFO(0, length)
     829             : ZEND_END_ARG_INFO()
     830             : /* }}} */
     831             : 
     832             : /* {{{ php_zlib_functions[] */
     833             : static const zend_function_entry php_zlib_functions[] = {
     834             :         PHP_FE(readgzfile,                                              arginfo_readgzfile)
     835             :         PHP_FALIAS(gzrewind,    rewind,                 arginfo_gzpassthru)
     836             :         PHP_FALIAS(gzclose,             fclose,                 arginfo_gzpassthru)
     837             :         PHP_FALIAS(gzeof,               feof,                   arginfo_gzpassthru)
     838             :         PHP_FALIAS(gzgetc,              fgetc,                  arginfo_gzpassthru)
     839             :         PHP_FALIAS(gzgets,              fgets,                  arginfo_gzgets)
     840             :         PHP_FALIAS(gzgetss,             fgetss,                 arginfo_gzgetss)
     841             :         PHP_FALIAS(gzread,              fread,                  arginfo_gzread)
     842             :         PHP_FE(gzopen,                                                  arginfo_gzopen)
     843             :         PHP_FALIAS(gzpassthru,  fpassthru,              arginfo_gzpassthru)
     844             :         PHP_FALIAS(gzseek,              fseek,                  arginfo_gzseek)
     845             :         PHP_FALIAS(gztell,              ftell,                  arginfo_gzpassthru)
     846             :         PHP_FALIAS(gzwrite,             fwrite,                 arginfo_gzputs)
     847             :         PHP_FALIAS(gzputs,              fwrite,                 arginfo_gzputs)
     848             :         PHP_FE(gzfile,                                                  arginfo_gzfile)
     849             :         PHP_FE(gzcompress,                                              arginfo_gzcompress)
     850             :         PHP_FE(gzuncompress,                                    arginfo_gzuncompress)
     851             :         PHP_FE(gzdeflate,                                               arginfo_gzdeflate)
     852             :         PHP_FE(gzinflate,                                               arginfo_gzinflate)
     853             :         PHP_FE(gzencode,                                                arginfo_gzencode)
     854             :         PHP_FE(gzdecode,                                                arginfo_gzdecode)
     855             :         PHP_FE(zlib_encode,                                             arginfo_zlib_encode)
     856             :         PHP_FE(zlib_decode,                                             arginfo_zlib_decode)
     857             :         PHP_FE(zlib_get_coding_type,                    arginfo_zlib_get_coding_type)
     858             :         PHP_FE(ob_gzhandler,                                    arginfo_ob_gzhandler)
     859             :         PHP_FE_END
     860             : };
     861             : /* }}} */
     862             : 
     863             : /* {{{ OnUpdate_zlib_output_compression */
     864       20924 : static PHP_INI_MH(OnUpdate_zlib_output_compression)
     865             : {
     866             :         int int_value;
     867             :         char *ini_value;
     868             :         zend_long *p;
     869             : #ifndef ZTS
     870       20924 :         char *base = (char *) mh_arg2;
     871             : #else
     872             :         char *base;
     873             : 
     874             :         base = (char *) ts_resource(*((int *) mh_arg2));
     875             : #endif
     876             : 
     877       20924 :         if (new_value == NULL) {
     878           0 :                 return FAILURE;
     879             :         }
     880             : 
     881       20924 :         if (!strncasecmp(new_value->val, "off", sizeof("off"))) {
     882           0 :                 int_value = 0;
     883       20924 :         } else if (!strncasecmp(new_value->val, "on", sizeof("on"))) {
     884           0 :                 int_value = 1;
     885             :         } else {
     886       20924 :                 int_value = zend_atoi(new_value->val, new_value->len);
     887             :         }
     888       20924 :         ini_value = zend_ini_string("output_handler", sizeof("output_handler"), 0);
     889             : 
     890       20924 :         if (ini_value && *ini_value && int_value) {
     891           0 :                 php_error_docref("ref.outcontrol" TSRMLS_CC, E_CORE_ERROR, "Cannot use both zlib.output_compression and output_handler together!!");
     892           0 :                 return FAILURE;
     893             :         }
     894       20924 :         if (stage == PHP_INI_STAGE_RUNTIME) {
     895         254 :                 int status = php_output_get_status(TSRMLS_C);
     896         254 :                 if (status & PHP_OUTPUT_SENT) {
     897           0 :                         php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_compression - headers already sent");
     898           0 :                         return FAILURE;
     899             :                 }
     900             :         }
     901             : 
     902       20924 :         p = (zend_long *) (base+(size_t) mh_arg1);
     903       20924 :         *p = int_value;
     904             : 
     905       20924 :         ZLIBG(output_compression) = ZLIBG(output_compression_default);
     906       20924 :         if (stage == PHP_INI_STAGE_RUNTIME && int_value) {
     907           3 :                 if (!php_output_handler_started(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME) TSRMLS_CC)) {
     908           3 :                         php_zlib_output_compression_start(TSRMLS_C);
     909             :                 }
     910             :         }
     911             : 
     912       20924 :         return SUCCESS;
     913             : }
     914             : /* }}} */
     915             : 
     916             : /* {{{ OnUpdate_zlib_output_handler */
     917       20423 : static PHP_INI_MH(OnUpdate_zlib_output_handler)
     918             : {
     919       20423 :         if (stage == PHP_INI_STAGE_RUNTIME && (php_output_get_status(TSRMLS_C) & PHP_OUTPUT_SENT)) {
     920           0 :                 php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_handler - headers already sent");
     921           0 :                 return FAILURE;
     922             :         }
     923             : 
     924       20423 :         return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
     925             : }
     926             : /* }}} */
     927             :  
     928             : /* {{{ INI */
     929             : PHP_INI_BEGIN()
     930             :         STD_PHP_INI_BOOLEAN("zlib.output_compression",      "0", PHP_INI_ALL, OnUpdate_zlib_output_compression,       output_compression_default,       zend_zlib_globals, zlib_globals)
     931             :         STD_PHP_INI_ENTRY("zlib.output_compression_level", "-1", PHP_INI_ALL, OnUpdateLong,                           output_compression_level, zend_zlib_globals, zlib_globals)
     932             :         STD_PHP_INI_ENTRY("zlib.output_handler",             "", PHP_INI_ALL, OnUpdate_zlib_output_handler,           output_handler,           zend_zlib_globals, zlib_globals)
     933             : PHP_INI_END()
     934             : 
     935             : /* }}} */
     936             : 
     937             : /* {{{ PHP_MINIT_FUNCTION */
     938       20423 : static PHP_MINIT_FUNCTION(zlib)
     939             : {
     940       20423 :         php_register_url_stream_wrapper("compress.zlib", &php_stream_gzip_wrapper TSRMLS_CC);
     941       20423 :         php_stream_filter_register_factory("zlib.*", &php_zlib_filter_factory TSRMLS_CC);
     942             : 
     943       20423 :         php_output_handler_alias_register(ZEND_STRL("ob_gzhandler"), php_zlib_output_handler_init TSRMLS_CC);
     944       20423 :         php_output_handler_conflict_register(ZEND_STRL("ob_gzhandler"), php_zlib_output_conflict_check TSRMLS_CC);
     945       20423 :         php_output_handler_conflict_register(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME), php_zlib_output_conflict_check TSRMLS_CC);
     946             : 
     947       20423 :         REGISTER_LONG_CONSTANT("FORCE_GZIP", PHP_ZLIB_ENCODING_GZIP, CONST_CS|CONST_PERSISTENT);
     948       20423 :         REGISTER_LONG_CONSTANT("FORCE_DEFLATE", PHP_ZLIB_ENCODING_DEFLATE, CONST_CS|CONST_PERSISTENT);
     949             : 
     950       20423 :         REGISTER_LONG_CONSTANT("ZLIB_ENCODING_RAW", PHP_ZLIB_ENCODING_RAW, CONST_CS|CONST_PERSISTENT);
     951       20423 :         REGISTER_LONG_CONSTANT("ZLIB_ENCODING_GZIP", PHP_ZLIB_ENCODING_GZIP, CONST_CS|CONST_PERSISTENT);
     952       20423 :         REGISTER_LONG_CONSTANT("ZLIB_ENCODING_DEFLATE", PHP_ZLIB_ENCODING_DEFLATE, CONST_CS|CONST_PERSISTENT);
     953       20423 :         REGISTER_INI_ENTRIES();
     954       20423 :         return SUCCESS;
     955             : }
     956             : /* }}} */
     957             : 
     958             : /* {{{ PHP_MSHUTDOWN_FUNCTION */
     959       20457 : static PHP_MSHUTDOWN_FUNCTION(zlib)
     960             : {
     961       20457 :         php_unregister_url_stream_wrapper("zlib" TSRMLS_CC);
     962       20457 :         php_stream_filter_unregister_factory("zlib.*" TSRMLS_CC);
     963             : 
     964       20457 :         UNREGISTER_INI_ENTRIES();
     965             : 
     966       20457 :         return SUCCESS;
     967             : }
     968             : /* }}} */
     969             : 
     970             : /* {{{ PHP_RINIT_FUNCTION */
     971       20380 : static PHP_RINIT_FUNCTION(zlib)
     972             : {
     973       20380 :         ZLIBG(compression_coding) = 0;
     974       20380 :     if (!ZLIBG(handler_registered)) {
     975       20377 :         ZLIBG(output_compression) = ZLIBG(output_compression_default);
     976       20377 :         php_zlib_output_compression_start(TSRMLS_C);
     977             :     }
     978             : 
     979       20380 :         return SUCCESS;
     980             : }
     981             : /* }}} */
     982             : 
     983             : /* {{{ PHP_RSHUTDOWN_FUNCTION */
     984       20416 : static PHP_RSHUTDOWN_FUNCTION(zlib)
     985             : {
     986       20416 :         php_zlib_cleanup_ob_gzhandler_mess(TSRMLS_C);
     987       20416 :     ZLIBG(handler_registered) = 0;
     988             : 
     989       20416 :     return SUCCESS;
     990             : }
     991             : /* }}} */
     992             : 
     993             : /* {{{ PHP_MINFO_FUNCTION */
     994         143 : static PHP_MINFO_FUNCTION(zlib)
     995             : {
     996         143 :         php_info_print_table_start();
     997         143 :         php_info_print_table_header(2, "ZLib Support", "enabled");
     998         143 :         php_info_print_table_row(2, "Stream Wrapper", "compress.zlib://");
     999         143 :         php_info_print_table_row(2, "Stream Filter", "zlib.inflate, zlib.deflate");
    1000         143 :         php_info_print_table_row(2, "Compiled Version", ZLIB_VERSION);
    1001         143 :         php_info_print_table_row(2, "Linked Version", (char *) zlibVersion());
    1002         143 :         php_info_print_table_end();
    1003             : 
    1004         143 :         DISPLAY_INI_ENTRIES();
    1005         143 : }
    1006             : /* }}} */
    1007             : 
    1008             : /* {{{ ZEND_MODULE_GLOBALS_CTOR */
    1009       20423 : static PHP_GINIT_FUNCTION(zlib)
    1010             : {
    1011       20423 :         zlib_globals->ob_gzhandler = NULL;
    1012       20423 :     zlib_globals->handler_registered = 0;
    1013       20423 : }
    1014             : /* }}} */
    1015             : 
    1016             : /* {{{ php_zlib_module_entry */
    1017             : zend_module_entry php_zlib_module_entry = {
    1018             :         STANDARD_MODULE_HEADER,
    1019             :         "zlib",
    1020             :         php_zlib_functions,
    1021             :         PHP_MINIT(zlib),
    1022             :         PHP_MSHUTDOWN(zlib),
    1023             :         PHP_RINIT(zlib),
    1024             :         PHP_RSHUTDOWN(zlib),
    1025             :         PHP_MINFO(zlib),
    1026             :         "2.0",
    1027             :         PHP_MODULE_GLOBALS(zlib),
    1028             :         PHP_GINIT(zlib),
    1029             :         NULL,
    1030             :         NULL,
    1031             :         STANDARD_MODULE_PROPERTIES_EX
    1032             : };
    1033             : /* }}} */
    1034             : 
    1035             : /*
    1036             :  * Local variables:
    1037             :  * tab-width: 4
    1038             :  * c-basic-offset: 4
    1039             :  * End:
    1040             :  * vim600: sw=4 ts=4 fdm=marker
    1041             :  * vim<600: sw=4 ts=4
    1042             :  */

Generated by: LCOV version 1.10

Generated at Wed, 22 Oct 2014 07:25:01 +0000 (33 hours ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.