]> granicus.if.org Git - php/commitdiff
MFH: fixed zlib.output_compression
authorMoriyoshi Koizumi <moriyoshi@php.net>
Tue, 11 Feb 2003 02:26:37 +0000 (02:26 +0000)
committerMoriyoshi Koizumi <moriyoshi@php.net>
Tue, 11 Feb 2003 02:26:37 +0000 (02:26 +0000)
ext/zlib/php_zlib.h
ext/zlib/zlib.c
main/SAPI.c

index 3f36b73213256b3038585ec70248a6721417f299..1435e7043e95bae1bd797df2d7e634150bde9fd7 100644 (file)
@@ -52,6 +52,7 @@ PHP_FUNCTION(gzdeflate);
 PHP_FUNCTION(gzinflate);
 PHP_FUNCTION(gzencode);
 PHP_FUNCTION(ob_gzhandler);
+PHP_FUNCTION(zlib_get_coding_type);
 
 int php_enable_output_compression(int buffer_size TSRMLS_DC);
 int php_ob_gzhandler_check(TSRMLS_D);
index f4e5e22f5d4098ee6a2bd6a68bcac5041f1bc7fb..d208a8091e0ca8e36d42ff05e1af5c493d9772b1 100644 (file)
@@ -104,6 +104,7 @@ function_entry php_zlib_functions[] = {
        PHP_FE(gzinflate,                               NULL)
        PHP_FE(gzencode,                                                NULL)
        PHP_FE(ob_gzhandler,                                    NULL)
+       PHP_FE(zlib_get_coding_type,                    NULL)
        {NULL, NULL, NULL}
 };
 /* }}} */
@@ -664,6 +665,23 @@ PHP_FUNCTION(gzinflate)
 }
 /* }}} */
 
+/*`{{{ proto zlib_get_coding_type()
+   Returns the coding type used for output compression */
+
+PHP_FUNCTION(zlib_get_coding_type)
+{
+       switch (ZLIBG(ob_gzip_coding)) {
+               case CODING_GZIP:
+                       RETURN_STRINGL("gzip", sizeof("gzip") - 1, 1);
+
+               case CODING_DEFLATE:
+                       RETURN_STRINGL("deflate", sizeof("deflate") - 1, 1);
+       }
+
+       RETURN_FALSE;
+}
+
+
 /* {{{ php_do_deflate
  */
 static int php_do_deflate(uint str_length, Bytef **p_buffer, uint *p_buffer_len, zend_bool do_start, zend_bool do_end TSRMLS_DC)
index dd10339499f970c1ee9a9c42101503bf0a02c79e..b7823c5be7f158201cb7accb7d894ea585254608 100644 (file)
 
 #include "php.h"
 #include "SAPI.h"
+#include "php_ini.h"
 #include "ext/standard/php_string.h"
 #include "ext/standard/pageinfo.h"
 #if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE)
 #include "ext/pcre/php_pcre.h"
 #endif
-#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB)
+#if HAVE_ZLIB
 #include "ext/zlib/php_zlib.h"
-ZEND_EXTERN_MODULE_GLOBALS(zlib)
 #endif
 #ifdef ZTS
 #include "TSRM.h"
@@ -556,9 +556,9 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
                                while (*ptr == ' ' && *ptr != '\0') {
                                        ptr++;
                                }
-#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB)
+#if HAVE_ZLIB
                                if(!strncmp(ptr, "image/", sizeof("image/")-1)) {
-                                       ZLIBG(output_compression) = 0;
+                                       zend_alter_ini_entry("zlib.output_compression", sizeof("zlib.output_compression"), "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
                                }
 #endif
                                mimetype = estrdup(ptr);
@@ -708,27 +708,32 @@ SAPI_API int sapi_send_headers(TSRMLS_D)
                return SUCCESS;
        }
 
-#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB)
+#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;
+
+       if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)) {
+               zval nm_zlib_get_coding_type;
+               zval *uf_result = NULL;
+
+               ZVAL_STRINGL(&nm_zlib_get_coding_type, "zlib_get_coding_type", sizeof("zlib_get_coding_type") - 1, 0);
+
+               if (call_user_function_ex(CG(function_table), NULL, &nm_zlib_get_coding_type, &uf_result, 0, NULL, 1, NULL TSRMLS_CC) != FAILURE && uf_result != NULL && Z_TYPE_P(uf_result) == IS_STRING) {
+                       char buf[128];
+                       int len;
+
+                       assert(Z_STRVAL_P(uf_result) != NULL);
+
+                       len = snprintf(buf, sizeof(buf), "Content-Encoding: %s", Z_STRVAL_P(uf_result));
+                       if (len <= 0 || sapi_add_header(buf, len, 1) == FAILURE) {
+                               return FAILURE;
+                       }
+                       if (sapi_add_header("Vary: Accept-Encoding", sizeof("Vary: Accept-Encoding") - 1, 1) == FAILURE) {
+                               return FAILURE;                 
+                       }
+               }
+               if (uf_result != NULL) {
+                       zval_ptr_dtor(&uf_result);
                }
        }
 #endif