Re: cvs: php4 /ext/zlib php_zlib.h zlib.c /main SAPI.c
| From: | Rasmus Lerdorf | Date: | Sun, 28 Jul 2002 14:56:38 +0000 |
| Subject: | Re: cvs: php4 /ext/zlib php_zlib.h zlib.c /main SAPI.c | ||
| References: | 1 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-13015@lists.php.net to get a copy of this message | ||
Cool, thanks Stefan. Looks good here.
-Rasmus
On Sun, 28 Jul 2002, Stefan Roehrich wrote:
> sr Sun Jul 28 10:08:08 2002 EDT
>
> Modified files:
> /php4/ext/zlib php_zlib.h zlib.c
> /php4/main SAPI.c
> Log:
> Commit patch as discussed on LinuxTag and posted to php-dev in June.
> Disables zlib.output_compression for scripts with image/ content-type
> header (fixes bug #16109) and makes it possible to switch
> zlib.output_compression during script execution before the headers are
> sent.
> @- zlib.output_compression is disabled for "image/" content-type
> @ headers and can be changed during script execution. (Stefan)
>
>
> Index: php4/ext/zlib/php_zlib.h
> diff -u php4/ext/zlib/php_zlib.h:1.30 php4/ext/zlib/php_zlib.h:1.31
> --- php4/ext/zlib/php_zlib.h:1.30 Wed Apr 10 18:42:24 2002
> +++ php4/ext/zlib/php_zlib.h Sun Jul 28 10:08:07 2002
> @@ -17,7 +17,7 @@
> +----------------------------------------------------------------------+
> */
>
> -/* $Id: php_zlib.h,v 1.30 2002/04/10 22:42:24 wez Exp $ */
> +/* $Id: php_zlib.h,v 1.31 2002/07/28 14:08:07 sr Exp $ */
>
> #ifndef PHP_ZLIB_H
> #define PHP_ZLIB_H
> @@ -65,6 +65,9 @@
> #endif
>
> #define phpext_zlib_ptr zlib_module_ptr
> +
> +#define CODING_GZIP 1
> +#define CODING_DEFLATE 2
>
> #endif /* PHP_ZLIB_H */
>
> Index: php4/ext/zlib/zlib.c
> diff -u php4/ext/zlib/zlib.c:1.136 php4/ext/zlib/zlib.c:1.137
> --- php4/ext/zlib/zlib.c:1.136 Tue Jun 18 06:09:41 2002
> +++ php4/ext/zlib/zlib.c Sun Jul 28 10:08:07 2002
> @@ -18,7 +18,7 @@
> | Jade Nicoletti <nicoletti@nns.ch> |
> +----------------------------------------------------------------------+
> */
> -/* $Id: zlib.c,v 1.136 2002/06/18 10:09:41 derick Exp $ */
> +/* $Id: zlib.c,v 1.137 2002/07/28 14:08:07 sr Exp $ */
> #define IS_EXT_MODULE
>
> #ifdef HAVE_CONFIG_H
> @@ -74,8 +74,6 @@
> #endif
>
> #define OS_CODE 0x03 /* FIXME */
> -#define CODING_GZIP 1
> -#define CODING_DEFLATE 2
> #define GZIP_HEADER_LENGTH 10
> #define GZIP_FOOTER_LENGTH 8
>
> @@ -144,6 +142,26 @@
> return FAILURE;
> }
>
> + 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 = "4096";
> + new_value_length = sizeof("4096");
> + } else if(stage == PHP_INI_STAGE_RUNTIME &&
> + strncmp(new_value, "0", sizeof("0")) && strncmp(new_value,
> "1", sizeof("1"))) {
> + php_error(E_WARNING, "Cannot change zlib.output_compression buffer size during script
> execution");
> + return FAILURE;
> + }
> +
> + if (stage == PHP_INI_STAGE_RUNTIME && SG(headers_sent) &&
> !SG(request_info).no_headers) {
> + php_error(E_WARNING, "Cannot change zlib.output_compression - headers already
> sent");
> + return FAILURE;
> + }
> +
> OnUpdateInt(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
>
> return SUCCESS;
> @@ -161,7 +179,7 @@
>
>
> PHP_INI_BEGIN()
> - STD_PHP_INI_BOOLEAN("zlib.output_compression", "0",
> PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdate_zlib_output_compression, output_compression,
> zend_zlib_globals, zlib_globals)
> + STD_PHP_INI_BOOLEAN("zlib.output_compression", "0", PHP_INI_ALL,
> OnUpdate_zlib_output_compression, output_compression, zend_zlib_globals, zlib_globals)
> STD_PHP_INI_ENTRY("zlib.output_compression_level", "-1", PHP_INI_ALL,
> OnUpdate_zlib_output_compression_level, output_compression_level, zend_zlib_globals, zlib_globals)
> PHP_INI_END()
>
> @@ -197,6 +215,7 @@
> PHP_RINIT_FUNCTION(zlib)
> {
> ZLIBG(ob_gzhandler_status) = 0;
> + ZLIBG(ob_gzip_coding) = 0;
> switch (ZLIBG(output_compression)) {
> case 0:
> break;
> @@ -947,11 +966,15 @@
> {
> zend_bool do_start, do_end;
>
> - do_start = (mode & PHP_OUTPUT_HANDLER_START ? 1 : 0);
> - do_end = (mode & PHP_OUTPUT_HANDLER_END ? 1 : 0);
> - if (php_deflate_string(output, output_len, handled_output, handled_output_len,
> ZLIBG(ob_gzip_coding), do_start, do_end, ZLIBG(output_compression_level) TSRMLS_CC)!=SUCCESS) {
> - zend_error(E_ERROR, "Compression failed");
> - }
> + if (!ZLIBG(output_compression)) {
> + *handled_output = NULL;
> + } else {
> + do_start = (mode & PHP_OUTPUT_HANDLER_START ? 1 : 0);
> + do_end = (mode & PHP_OUTPUT_HANDLER_END ? 1 : 0);
> + if (php_deflate_string(output, output_len, handled_output, handled_output_len,
> ZLIBG(ob_gzip_coding), do_start, do_end, ZLIBG(output_compression_level) TSRMLS_CC)!=SUCCESS) {
> + zend_error(E_ERROR, "Compression failed");
> + }
> + }
> }
> /* }}} */
>
> @@ -968,20 +991,8 @@
> }
> convert_to_string_ex(a_encoding);
> if (php_memnstr(Z_STRVAL_PP(a_encoding), "gzip", 4, Z_STRVAL_PP(a_encoding) +
> Z_STRLEN_PP(a_encoding))) {
> - if (sapi_add_header("Content-Encoding: gzip", sizeof("Content-Encoding:
> gzip") - 1, 1)==FAILURE) {
> - return FAILURE;
> - }
> - if (sapi_add_header("Vary: Accept-Encoding", sizeof("Vary:
> Accept-Encoding") - 1, 1)==FAILURE) {
> - return FAILURE;
> - }
> ZLIBG(ob_gzip_coding) = CODING_GZIP;
> } else if(php_memnstr(Z_STRVAL_PP(a_encoding), "deflate", 7,
> Z_STRVAL_PP(a_encoding) + Z_STRLEN_PP(a_encoding))) {
> - if (sapi_add_header("Content-Encoding: deflate", sizeof("Content-Encoding:
> deflate") - 1, 1)==FAILURE) {
> - return FAILURE;
> - }
> - if (sapi_add_header("Vary: Accept-Encoding", sizeof("Vary:
> Accept-Encoding") - 1, 1)==FAILURE) {
> - return FAILURE;
> - }
> ZLIBG(ob_gzip_coding) = CODING_DEFLATE;
> } else {
> return FAILURE;
> Index: php4/main/SAPI.c
> diff -u php4/main/SAPI.c:1.137 php4/main/SAPI.c:1.138
> --- php4/main/SAPI.c:1.137 Sat Jul 27 09:58:16 2002
> +++ php4/main/SAPI.c Sun Jul 28 10:08:08 2002
> @@ -18,7 +18,7 @@
> +----------------------------------------------------------------------+
> */
>
> -/* $Id: SAPI.c,v 1.137 2002/07/27 13:58:16 hirokawa Exp $ */
> +/* $Id: SAPI.c,v 1.138 2002/07/28 14:08:08 sr Exp $ */
>
> #include <ctype.h>
> #include <sys/stat.h>
> @@ -30,6 +30,10 @@
> #if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE)
> #include "ext/pcre/php_pcre.h"
> #endif
> +#if HAVE_ZLIB
> +#include "ext/zlib/php_zlib.h"
> +ZEND_EXTERN_MODULE_GLOBALS(zlib)
> +#endif
> #ifdef ZTS
> #include "TSRM.h"
> #endif
> @@ -485,6 +489,11 @@
> if (!STRCASECMP(header_line, "Content-Type")) {
> char *ptr = colon_offset+1, *mimetype = NULL, *newheader;
> size_t len = header_line_len - (ptr - header_line), newlen;
> +#if HAVE_ZLIB
> + if(strncmp(ptr, "image/", sizeof("image/"))) {
> + ZLIBG(output_compression) = 0;
> + }
> +#endif
> while (*ptr == ' ' && *ptr != '\0') {
> ptr++;
> }
> @@ -632,6 +641,31 @@
> if (SG(headers_sent) || SG(request_info).no_headers) {
> return SUCCESS;
> }
> +
> +#if HAVE_ZLIB
> + /* Add output compression headers at this late stage in order to make
> + it possible to switch it off inside the script. */
> + if (ZLIBG(output_compression)) {
> + switch (ZLIBG(ob_gzip_coding)) {
> + case CODING_GZIP:
> + if (sapi_add_header("Content-Encoding: gzip", sizeof("Content-Encoding:
> gzip") - 1, 1)==FAILURE) {
> + return FAILURE;
> + }
> + if (sapi_add_header("Vary: Accept-Encoding", sizeof("Vary:
> Accept-Encoding") - 1, 1)==FAILURE) {
> + return FAILURE;
> + }
> + break;
> + case CODING_DEFLATE:
> + if (sapi_add_header("Content-Encoding: deflate", sizeof("Content-Encoding:
> deflate") - 1, 1)==FAILURE) {
> + return FAILURE;
> + }
> + if (sapi_add_header("Vary: Accept-Encoding", sizeof("Vary:
> Accept-Encoding") - 1, 1)==FAILURE) {
> + return FAILURE;
> + }
> + break;
> + }
> + }
> +#endif
>
> /* Success-oriented. We set headers_sent to 1 here to avoid an infinite loop
> * in case of an error situation.
>
>
>
> --
> PHP CVS Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>