cvs: php4(PHP_4_3) /ext/zlib php_zlib.h zlib.c /main SAPI.c
| From: | Moriyoshi Koizumi | Date: | Tue, 11 Feb 2003 02:26:37 +0000 |
| Subject: | cvs: php4(PHP_4_3) /ext/zlib php_zlib.h zlib.c /main SAPI.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-18661@lists.php.net to get a copy of this message | ||
moriyoshi Mon Feb 10 21:26:37 2003 EDT
Modified files: (Branch: PHP_4_3)
/php4/ext/zlib zlib.c php_zlib.h
/php4/main SAPI.c
Log:
MFH: fixed zlib.output_compression
Index: php4/ext/zlib/zlib.c
diff -u php4/ext/zlib/zlib.c:1.153.2.5 php4/ext/zlib/zlib.c:1.153.2.6
--- php4/ext/zlib/zlib.c:1.153.2.5 Tue Dec 31 11:35:48 2002
+++ php4/ext/zlib/zlib.c Mon Feb 10 21:26:37 2003
@@ -18,7 +18,7 @@
| Jade Nicoletti <nicoletti@nns.ch> |
+----------------------------------------------------------------------+
*/
-/* $Id: zlib.c,v 1.153.2.5 2002/12/31 16:35:48 sebastian Exp $ */
+/* $Id: zlib.c,v 1.153.2.6 2003/02/11 02:26:37 moriyoshi Exp $ */
#define IS_EXT_MODULE
#ifdef HAVE_CONFIG_H
@@ -104,6 +104,7 @@
PHP_FE(gzinflate, NULL)
PHP_FE(gzencode, NULL)
PHP_FE(ob_gzhandler, NULL)
+ PHP_FE(zlib_get_coding_type, NULL)
{NULL, NULL, NULL}
};
/* }}} */
@@ -663,6 +664,23 @@
}
}
/* }}} */
+
+/*`{{{ 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
*/
Index: php4/ext/zlib/php_zlib.h
diff -u php4/ext/zlib/php_zlib.h:1.32.4.3 php4/ext/zlib/php_zlib.h:1.32.4.4
--- php4/ext/zlib/php_zlib.h:1.32.4.3 Tue Dec 31 11:35:48 2002
+++ php4/ext/zlib/php_zlib.h Mon Feb 10 21:26:37 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_zlib.h,v 1.32.4.3 2002/12/31 16:35:48 sebastian Exp $ */
+/* $Id: php_zlib.h,v 1.32.4.4 2003/02/11 02:26:37 moriyoshi Exp $ */
#ifndef PHP_ZLIB_H
#define PHP_ZLIB_H
@@ -52,6 +52,7 @@
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: php4/main/SAPI.c
diff -u php4/main/SAPI.c:1.155.2.7 php4/main/SAPI.c:1.155.2.8
--- php4/main/SAPI.c:1.155.2.7 Mon Feb 10 15:13:36 2003
+++ php4/main/SAPI.c Mon Feb 10 21:26:37 2003
@@ -18,21 +18,21 @@
+----------------------------------------------------------------------+
*/
-/* $Id: SAPI.c,v 1.155.2.7 2003/02/10 20:13:36 moriyoshi Exp $ */
+/* $Id: SAPI.c,v 1.155.2.8 2003/02/11 02:26:37 moriyoshi Exp $ */
#include <ctype.h>
#include <sys/stat.h>
#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 @@
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 @@
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