summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Wallner <mike@php.net>2010-05-31 10:29:43 (GMT)
committerMichael Wallner <mike@php.net>2010-05-31 10:29:43 (GMT)
commit11d24c1593d6617f73d3f290617bd8994182f4dc (patch)
treeeddeffa97ad3893b731144afb003e26ef0952de9
parent27299b7e4084adb236acfbfb25168d72306ee802 (diff)
downloadphp-11d24c1593d6617f73d3f290617bd8994182f4dc.tar.gz
* implement new output API, fixing some bugs and implementing some feature
requests--let's see what I can dig out of the bugtracker for NEWS-- and while crossing the road: * implemented new zlib API * fixed up ext/tidy (what was "s&" in zend_parse_parameters() supposed to do?) Thanks to Jani and Felipe for pioneering.
-rw-r--r--README.NEW-OUTPUT-API426
-rw-r--r--ext/iconv/iconv.c129
-rw-r--r--ext/session/session.c8
-rw-r--r--ext/soap/soap.c102
-rw-r--r--ext/standard/basic_functions.c50
-rw-r--r--ext/standard/exec.c4
-rw-r--r--ext/standard/head.c4
-rw-r--r--ext/standard/info.c599
-rw-r--r--ext/standard/tests/general_functions/ob_get_flush_error.phpt2
-rw-r--r--ext/standard/url_scanner_ex.c8
-rw-r--r--ext/standard/url_scanner_ex.re6
-rw-r--r--ext/standard/var.c6
-rw-r--r--ext/tidy/php_tidy.h1
-rw-r--r--ext/tidy/tidy.c254
-rw-r--r--ext/zlib/CREDITS2
-rw-r--r--ext/zlib/config0.m49
-rw-r--r--ext/zlib/php_zlib.h46
-rw-r--r--ext/zlib/tests/006.phpt2
-rw-r--r--ext/zlib/tests/007.phpt16
-rw-r--r--ext/zlib/tests/gzcompress_basic1.phpt6
-rw-r--r--ext/zlib/tests/gzcompress_error1.phpt28
-rw-r--r--ext/zlib/tests/gzcompress_variation1.phpt6
-rw-r--r--ext/zlib/tests/gzdeflate_basic1.phpt2
-rw-r--r--ext/zlib/tests/gzdeflate_error1.phpt18
-rw-r--r--ext/zlib/tests/gzencode_basic1.phpt27
-rw-r--r--ext/zlib/tests/gzencode_error1.phpt8
-rw-r--r--ext/zlib/tests/gzencode_variation1.phpt6
-rw-r--r--ext/zlib/tests/gzencode_variation2-win32.phpt42
-rw-r--r--ext/zlib/tests/gzencode_variation2.phpt8
-rw-r--r--ext/zlib/tests/gzinflate-bug42663.phpt11
-rw-r--r--ext/zlib/tests/gzinflate_length.phpt2
-rw-r--r--ext/zlib/tests/gzreadgzwrite.phpt9
-rw-r--r--ext/zlib/tests/gzreadgzwriteplain.phpt15
-rw-r--r--ext/zlib/tests/gzuncompress_error1.phpt8
-rw-r--r--ext/zlib/tests/gzwrite_variation1.phpt2
-rw-r--r--ext/zlib/tests/ob_001.phpt20
-rw-r--r--ext/zlib/tests/ob_002.phpt18
-rw-r--r--ext/zlib/tests/ob_003.phpt25
-rw-r--r--ext/zlib/tests/ob_004.phpt25
-rw-r--r--ext/zlib/tests/ob_005.phpt21
-rw-r--r--ext/zlib/tests/readgzfile_variation14.phpt2
-rw-r--r--ext/zlib/tests/readgzfile_variation4.phpt9
-rw-r--r--ext/zlib/tests/readgzfile_variation5.phpt9
-rw-r--r--ext/zlib/tests/readgzfile_variation6.phpt1
-rw-r--r--ext/zlib/tests/readgzfile_variation7.phpt7
-rw-r--r--ext/zlib/tests/zlib_filter_inflate2.phpt4
-rw-r--r--ext/zlib/zlib.c1495
-rw-r--r--ext/zlib/zlib_filter.c25
-rw-r--r--ext/zlib/zlib_fopen_wrapper.c2
-rw-r--r--main/SAPI.c4
-rw-r--r--main/main.c60
-rw-r--r--main/output.c1724
-rw-r--r--main/php.h15
-rw-r--r--main/php_logos.c2
-rw-r--r--main/php_output.h294
-rw-r--r--sapi/apache/mod_php5.c2
-rw-r--r--sapi/apache/php_apache.c2
-rw-r--r--sapi/apache2handler/php_functions.c2
-rw-r--r--sapi/apache_hooks/mod_php5.c2
-rw-r--r--sapi/apache_hooks/php_apache.c2
-rw-r--r--sapi/cgi/cgi_main.c13
-rw-r--r--sapi/cli/php_cli.c8
-rw-r--r--sapi/milter/php_milter.c12
-rw-r--r--sapi/nsapi/nsapi.c2
-rw-r--r--tests/output/bug46897.phpt4
-rw-r--r--tests/output/ob_011.phpt2
-rw-r--r--tests/output/ob_013.phpt72
-rw-r--r--tests/output/ob_017.phpt12
-rw-r--r--tests/output/ob_clean_basic_001.phpt4
-rw-r--r--tests/output/ob_end_clean_basic_001.phpt4
-rw-r--r--tests/output/ob_end_flush_basic_001.phpt6
-rw-r--r--tests/output/ob_flush_basic_001.phpt4
-rw-r--r--tests/output/ob_get_clean_basic_001.phpt1
-rw-r--r--tests/output/ob_get_level_basic_001.phpt4
-rw-r--r--tests/output/ob_get_status.phpt23
-rw-r--r--tests/output/ob_start_basic_004.phpt18
-rw-r--r--tests/output/ob_start_basic_006.phpt43
-rw-r--r--tests/output/ob_start_basic_unerasable_002.phpt6
-rw-r--r--tests/output/ob_start_basic_unerasable_003.phpt9
-rw-r--r--tests/output/ob_start_basic_unerasable_004.phpt9
-rw-r--r--tests/output/ob_start_basic_unerasable_005.phpt4
-rw-r--r--tests/output/ob_start_error_001.phpt13
-rw-r--r--tests/output/ob_start_error_002.phpt7
-rw-r--r--tests/output/ob_start_error_003.phpt4
-rw-r--r--tests/output/ob_start_error_004.phpt4
85 files changed, 3396 insertions, 2536 deletions
diff --git a/README.NEW-OUTPUT-API b/README.NEW-OUTPUT-API
new file mode 100644
index 0000000..82e3f48
--- /dev/null
+++ b/README.NEW-OUTPUT-API
@@ -0,0 +1,426 @@
+$Id: README.NEW-OUTPUT-API 219039 2006-08-30 07:39:09Z mike $
+
+
+API adjustment to the old output control code:
+
+ Everything now resides beneath the php_output namespace,
+ and there's an API call for every output handler op.
+
+ Checking output control layers status:
+ // Using OG()
+ php_output_get_status(TSRMLS_C);
+
+ Starting the default output handler:
+ // php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC);
+ php_output_start_default(TSRMLS_C);
+
+ Starting an user handler by zval:
+ // php_start_ob_buffer(zhandler, chunk_size, erase TSRMLS_CC);
+ php_output_start_user(zhandler, chunk_size, flags TSRMLS_CC);
+
+ Starting an internal handler whithout context:
+ // php_ob_set_internal_handler(my_php_output_handler_func_t, buffer_size, "output handler name", erase TSRMLS_CC);
+ php_output_start_internal(handler_name_zval, my_php_output_handler_func_t, chunk_size, flags TSRMLS_CC);
+
+ Starting an internal handler with context:
+ // not possible with old API
+ php_output_handler *h;
+ h = php_output_handler_create_internal(handler_name_zval, my_php_output_handler_context_func_t, chunk_size, flags TSRMLS_CC);
+ php_output_handler_set_context(h, my_context, my_context_dtor);
+ php_output_handler_start(h TSRMLS_CC);
+
+ Testing whether a certain output handler has already been started:
+ // php_ob_handler_used("output handler name" TSRMLS_CC);
+ php_output_handler_started(handler_name_zval TSRMLS_CC);
+
+ Flushing one output buffer:
+ // php_ob_end_buffer(1, 1 TSRMLS_CC);
+ php_output_flush(TSRMLS_C);
+
+ Flushing all output buffers:
+ // not possible with old API
+ php_output_flush_all(TSRMLS_C);
+
+ Cleaning one output buffer:
+ // php_ob_end_buffer(0, 1 TSRMLS_CC);
+ php_output_clean(TSRMLS_C);
+
+ Cleaning all output buffers:
+ // not possible with old API
+ php_output_clean_all(TSRMLS_C);
+
+ Discarding one output buffer:
+ // php_ob_end_buffer(0, 0 TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
+
+ Discarding all output buffers:
+ // php_ob_end_buffers(0 TSRMLS_CC);
+ php_output_discard_all(TSRMLS_C);
+
+ Stopping (and dropping) one output buffer:
+ // php_ob_end_buffer(1, 0 TSRMLS_CC)
+ php_output_end(TSRMLS_C);
+
+ Stopping (and dropping) all output buffers:
+ // php_ob_end_buffers(1, 0 TSRMLS_CC);
+ php_output_end_all(TSRMLS_C);
+
+ Retrieving output buffers contents:
+ // php_ob_get_buffer(zstring TSRMLS_CC);
+ php_output_get_contents(zstring TSRMLS_CC);
+
+ Retrieving output buffers length:
+ // php_ob_get_length(zlength TSRMLS_CC);
+ php_output_get_length(zlength TSRMLS_CC);
+
+ Retrieving output buffering level:
+ // OG(nesting_level);
+ php_output_get_level(TSRMLS_C);
+
+ Issue a warning because of an output handler conflict:
+ // php_ob_init_conflict("to be started handler name", "to be tested if already started handler name" TSRMLS_CC);
+ php_output_handler_conflict(new_handler_name_zval, set_handler_name_zval TSRMLS_CC);
+
+ Registering a conflict checking function, which will be checked prior starting the handler:
+ // not possible with old API, unless hardcoding into output.c
+ php_output_handler_conflict_register(handler_name_zval, my_php_output_handler_conflict_check_t TSRMLS_CC);
+
+ Registering a reverse conflict checking function, which will be checked prior starting the specified foreign handler:
+ // not possible with old API
+ php_output_handler_reverse_conflict_register(foreign_handler_name_zval, my_php_output_handler_conflict_check_t TSRMLS_CC);
+
+ Facilitating a context from within an output handler callable with ob_start():
+ // not possible with old API
+ php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_GET_OPAQ, (void *) &custom_ctx_ptr_ptr TSRMLS_CC);
+
+ Disabling of the output handler by itself:
+ //not possible with old API
+ php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_DISABLE, NULL TSRMLS_CC);
+
+ Marking an output handler immutable by itself because of irreversibility of its operation:
+ // not possible with old API
+ php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE, NULL TSRMLS_CC);
+
+ Restarting the output handler because of a CLEAN operation:
+ // not possible with old API
+ if (flags & PHP_OUTPUT_HANDLER_CLEAN) { ... }
+
+ Recognizing by the output handler itself if it gets discarded:
+ // not possible with old API
+ if ((flags & PHP_OUTPUT_HANDLER_CLEAN) && (flags & PHP_OUTPUT_HANDLER_FINAL)) { ... }
+
+
+Output handler hooks
+
+ The output handler can change its abilities at runtime. Eg. the gz handler can
+ remove the CLEANABLE and REMOVABLE bits when the first output has passed through it;
+ or handlers implemented in C to be used with ob_start() can contain a non-global
+ context:
+ PHP_OUTPUT_HANDLER_HOOK_GET_OPAQ
+ pass a void*** pointer as second arg to receive the address of a pointer
+ pointer to the opaque field of the output handler context
+ PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS
+ pass a int* pointer as second arg to receive the flags set for the output handler
+ PHP_OUTPUT_HANDLER_HOOK_GET_LEVEL
+ pass a int* pointer as second arg to receive the level of this output handler
+ (starts with 0)
+ PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE
+ the second arg is ignored; marks the output handler to be neither cleanable
+ nor removable
+ PHP_OUTPUT_HANDLER_HOOK_DISABLE
+ the second arg is ignored; marks the output handler as disabled
+
+
+Open questions
+
+ Should the userland API be adjusted and unified?
+
+ Many bits of the manual (and very first implementation) do not comply
+ with the behaviour of the current (to be obsoleted) code, thus should
+ the manual or the behaviour be adjusted?
+
+END
+$Id: README.NEW-OUTPUT-API 219039 2006-08-30 07:39:09Z mike $
+
+
+API adjustment to the old output control code:
+
+ Everything now resides beneath the php_output namespace,
+ and there's an API call for every output handler op.
+
+ Checking output control layers status:
+ // Using OG()
+ php_output_get_status(TSRMLS_C);
+
+ Starting the default output handler:
+ // php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC);
+ php_output_start_default(TSRMLS_C);
+
+ Starting an user handler by zval:
+ // php_start_ob_buffer(zhandler, chunk_size, erase TSRMLS_CC);
+ php_output_start_user(zhandler, chunk_size, flags TSRMLS_CC);
+
+ Starting an internal handler whithout context:
+ // php_ob_set_internal_handler(my_php_output_handler_func_t, buffer_size, "output handler name", erase TSRMLS_CC);
+ php_output_start_internal(handler_name_zval, my_php_output_handler_func_t, chunk_size, flags TSRMLS_CC);
+
+ Starting an internal handler with context:
+ // not possible with old API
+ php_output_handler *h;
+ h = php_output_handler_create_internal(handler_name_zval, my_php_output_handler_context_func_t, chunk_size, flags TSRMLS_CC);
+ php_output_handler_set_context(h, my_context, my_context_dtor);
+ php_output_handler_start(h TSRMLS_CC);
+
+ Testing whether a certain output handler has already been started:
+ // php_ob_handler_used("output handler name" TSRMLS_CC);
+ php_output_handler_started(handler_name_zval TSRMLS_CC);
+
+ Flushing one output buffer:
+ // php_ob_end_buffer(1, 1 TSRMLS_CC);
+ php_output_flush(TSRMLS_C);
+
+ Flushing all output buffers:
+ // not possible with old API
+ php_output_flush_all(TSRMLS_C);
+
+ Cleaning one output buffer:
+ // php_ob_end_buffer(0, 1 TSRMLS_CC);
+ php_output_clean(TSRMLS_C);
+
+ Cleaning all output buffers:
+ // not possible with old API
+ php_output_clean_all(TSRMLS_C);
+
+ Discarding one output buffer:
+ // php_ob_end_buffer(0, 0 TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
+
+ Discarding all output buffers:
+ // php_ob_end_buffers(0 TSRMLS_CC);
+ php_output_discard_all(TSRMLS_C);
+
+ Stopping (and dropping) one output buffer:
+ // php_ob_end_buffer(1, 0 TSRMLS_CC)
+ php_output_end(TSRMLS_C);
+
+ Stopping (and dropping) all output buffers:
+ // php_ob_end_buffers(1, 0 TSRMLS_CC);
+ php_output_end_all(TSRMLS_C);
+
+ Retrieving output buffers contents:
+ // php_ob_get_buffer(zstring TSRMLS_CC);
+ php_output_get_contents(zstring TSRMLS_CC);
+
+ Retrieving output buffers length:
+ // php_ob_get_length(zlength TSRMLS_CC);
+ php_output_get_length(zlength TSRMLS_CC);
+
+ Retrieving output buffering level:
+ // OG(nesting_level);
+ php_output_get_level(TSRMLS_C);
+
+ Issue a warning because of an output handler conflict:
+ // php_ob_init_conflict("to be started handler name", "to be tested if already started handler name" TSRMLS_CC);
+ php_output_handler_conflict(new_handler_name_zval, set_handler_name_zval TSRMLS_CC);
+
+ Registering a conflict checking function, which will be checked prior starting the handler:
+ // not possible with old API, unless hardcoding into output.c
+ php_output_handler_conflict_register(handler_name_zval, my_php_output_handler_conflict_check_t TSRMLS_CC);
+
+ Registering a reverse conflict checking function, which will be checked prior starting the specified foreign handler:
+ // not possible with old API
+ php_output_handler_reverse_conflict_register(foreign_handler_name_zval, my_php_output_handler_conflict_check_t TSRMLS_CC);
+
+ Facilitating a context from within an output handler callable with ob_start():
+ // not possible with old API
+ php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_GET_OPAQ, (void *) &custom_ctx_ptr_ptr TSRMLS_CC);
+
+ Disabling of the output handler by itself:
+ //not possible with old API
+ php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_DISABLE, NULL TSRMLS_CC);
+
+ Marking an output handler immutable by itself because of irreversibility of its operation:
+ // not possible with old API
+ php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE, NULL TSRMLS_CC);
+
+ Restarting the output handler because of a CLEAN operation:
+ // not possible with old API
+ if (flags & PHP_OUTPUT_HANDLER_CLEAN) { ... }
+
+ Recognizing by the output handler itself if it gets discarded:
+ // not possible with old API
+ if ((flags & PHP_OUTPUT_HANDLER_CLEAN) && (flags & PHP_OUTPUT_HANDLER_FINAL)) { ... }
+
+
+Output handler hooks
+
+ The output handler can change its abilities at runtime. Eg. the gz handler can
+ remove the CLEANABLE and REMOVABLE bits when the first output has passed through it;
+ or handlers implemented in C to be used with ob_start() can contain a non-global
+ context:
+ PHP_OUTPUT_HANDLER_HOOK_GET_OPAQ
+ pass a void*** pointer as second arg to receive the address of a pointer
+ pointer to the opaque field of the output handler context
+ PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS
+ pass a int* pointer as second arg to receive the flags set for the output handler
+ PHP_OUTPUT_HANDLER_HOOK_GET_LEVEL
+ pass a int* pointer as second arg to receive the level of this output handler
+ (starts with 0)
+ PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE
+ the second arg is ignored; marks the output handler to be neither cleanable
+ nor removable
+ PHP_OUTPUT_HANDLER_HOOK_DISABLE
+ the second arg is ignored; marks the output handler as disabled
+
+
+Open questions
+
+ Should the userland API be adjusted and unified?
+
+ Many bits of the manual (and very first implementation) do not comply
+ with the behaviour of the current (to be obsoleted) code, thus should
+ the manual or the behaviour be adjusted?
+
+END
+$Id: README.NEW-OUTPUT-API 219039 2006-08-30 07:39:09Z mike $
+
+
+API adjustment to the old output control code:
+
+ Everything now resides beneath the php_output namespace,
+ and there's an API call for every output handler op.
+
+ Checking output control layers status:
+ // Using OG()
+ php_output_get_status(TSRMLS_C);
+
+ Starting the default output handler:
+ // php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC);
+ php_output_start_default(TSRMLS_C);
+
+ Starting an user handler by zval:
+ // php_start_ob_buffer(zhandler, chunk_size, erase TSRMLS_CC);
+ php_output_start_user(zhandler, chunk_size, flags TSRMLS_CC);
+
+ Starting an internal handler whithout context:
+ // php_ob_set_internal_handler(my_php_output_handler_func_t, buffer_size, "output handler name", erase TSRMLS_CC);
+ php_output_start_internal(handler_name_zval, my_php_output_handler_func_t, chunk_size, flags TSRMLS_CC);
+
+ Starting an internal handler with context:
+ // not possible with old API
+ php_output_handler *h;
+ h = php_output_handler_create_internal(handler_name_zval, my_php_output_handler_context_func_t, chunk_size, flags TSRMLS_CC);
+ php_output_handler_set_context(h, my_context, my_context_dtor);
+ php_output_handler_start(h TSRMLS_CC);
+
+ Testing whether a certain output handler has already been started:
+ // php_ob_handler_used("output handler name" TSRMLS_CC);
+ php_output_handler_started(handler_name_zval TSRMLS_CC);
+
+ Flushing one output buffer:
+ // php_ob_end_buffer(1, 1 TSRMLS_CC);
+ php_output_flush(TSRMLS_C);
+
+ Flushing all output buffers:
+ // not possible with old API
+ php_output_flush_all(TSRMLS_C);
+
+ Cleaning one output buffer:
+ // php_ob_end_buffer(0, 1 TSRMLS_CC);
+ php_output_clean(TSRMLS_C);
+
+ Cleaning all output buffers:
+ // not possible with old API
+ php_output_clean_all(TSRMLS_C);
+
+ Discarding one output buffer:
+ // php_ob_end_buffer(0, 0 TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
+
+ Discarding all output buffers:
+ // php_ob_end_buffers(0 TSRMLS_CC);
+ php_output_discard_all(TSRMLS_C);
+
+ Stopping (and dropping) one output buffer:
+ // php_ob_end_buffer(1, 0 TSRMLS_CC)
+ php_output_end(TSRMLS_C);
+
+ Stopping (and dropping) all output buffers:
+ // php_ob_end_buffers(1, 0 TSRMLS_CC);
+ php_output_end_all(TSRMLS_C);
+
+ Retrieving output buffers contents:
+ // php_ob_get_buffer(zstring TSRMLS_CC);
+ php_output_get_contents(zstring TSRMLS_CC);
+
+ Retrieving output buffers length:
+ // php_ob_get_length(zlength TSRMLS_CC);
+ php_output_get_length(zlength TSRMLS_CC);
+
+ Retrieving output buffering level:
+ // OG(nesting_level);
+ php_output_get_level(TSRMLS_C);
+
+ Issue a warning because of an output handler conflict:
+ // php_ob_init_conflict("to be started handler name", "to be tested if already started handler name" TSRMLS_CC);
+ php_output_handler_conflict(new_handler_name_zval, set_handler_name_zval TSRMLS_CC);
+
+ Registering a conflict checking function, which will be checked prior starting the handler:
+ // not possible with old API, unless hardcoding into output.c
+ php_output_handler_conflict_register(handler_name_zval, my_php_output_handler_conflict_check_t TSRMLS_CC);
+
+ Registering a reverse conflict checking function, which will be checked prior starting the specified foreign handler:
+ // not possible with old API
+ php_output_handler_reverse_conflict_register(foreign_handler_name_zval, my_php_output_handler_conflict_check_t TSRMLS_CC);
+
+ Facilitating a context from within an output handler callable with ob_start():
+ // not possible with old API
+ php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_GET_OPAQ, (void *) &custom_ctx_ptr_ptr TSRMLS_CC);
+
+ Disabling of the output handler by itself:
+ //not possible with old API
+ php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_DISABLE, NULL TSRMLS_CC);
+
+ Marking an output handler immutable by itself because of irreversibility of its operation:
+ // not possible with old API
+ php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE, NULL TSRMLS_CC);
+
+ Restarting the output handler because of a CLEAN operation:
+ // not possible with old API
+ if (flags & PHP_OUTPUT_HANDLER_CLEAN) { ... }
+
+ Recognizing by the output handler itself if it gets discarded:
+ // not possible with old API
+ if ((flags & PHP_OUTPUT_HANDLER_CLEAN) && (flags & PHP_OUTPUT_HANDLER_FINAL)) { ... }
+
+
+Output handler hooks
+
+ The output handler can change its abilities at runtime. Eg. the gz handler can
+ remove the CLEANABLE and REMOVABLE bits when the first output has passed through it;
+ or handlers implemented in C to be used with ob_start() can contain a non-global
+ context:
+ PHP_OUTPUT_HANDLER_HOOK_GET_OPAQ
+ pass a void*** pointer as second arg to receive the address of a pointer
+ pointer to the opaque field of the output handler context
+ PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS
+ pass a int* pointer as second arg to receive the flags set for the output handler
+ PHP_OUTPUT_HANDLER_HOOK_GET_LEVEL
+ pass a int* pointer as second arg to receive the level of this output handler
+ (starts with 0)
+ PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE
+ the second arg is ignored; marks the output handler to be neither cleanable
+ nor removable
+ PHP_OUTPUT_HANDLER_HOOK_DISABLE
+ the second arg is ignored; marks the output handler as disabled
+
+
+Open questions
+
+ Should the userland API be adjusted and unified?
+
+ Many bits of the manual (and very first implementation) do not comply
+ with the behaviour of the current (to be obsoleted) code, thus should
+ the manual or the behaviour be adjusted?
+
+END
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 7f90d6d..07fb359 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -112,11 +112,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_iconv, 0)
ZEND_ARG_INFO(0, str)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO(arginfo_ob_iconv_handler, 0)
- ZEND_ARG_INFO(0, contents)
- ZEND_ARG_INFO(0, status)
-ZEND_END_ARG_INFO()
-
ZEND_BEGIN_ARG_INFO(arginfo_iconv_set_encoding, 0)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, charset)
@@ -132,7 +127,6 @@ ZEND_END_ARG_INFO()
*/
const zend_function_entry iconv_functions[] = {
PHP_RAW_NAMED_FE(iconv,php_if_iconv, arginfo_iconv)
- PHP_FE(ob_iconv_handler, arginfo_ob_iconv_handler)
PHP_FE(iconv_get_encoding, arginfo_iconv_get_encoding)
PHP_FE(iconv_set_encoding, arginfo_iconv_set_encoding)
PHP_FE(iconv_strlen, arginfo_iconv_strlen)
@@ -214,6 +208,10 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char *st
static php_iconv_err_t php_iconv_stream_filter_register_factory(TSRMLS_D);
static php_iconv_err_t php_iconv_stream_filter_unregister_factory(TSRMLS_D);
+
+static int php_iconv_output_conflict(const char *handler_name, size_t handler_name_len TSRMLS_DC);
+static php_output_handler *php_iconv_output_handler_init(const char *name, size_t name_len, size_t chunk_size, int flags TSRMLS_DC);
+static int php_iconv_output_handler(void **nothing, php_output_context *output_context);
/* }}} */
/* {{{ static globals */
@@ -278,6 +276,9 @@ PHP_MINIT_FUNCTION(miconv)
return FAILURE;
}
+ php_output_handler_alias_register(ZEND_STRL("ob_iconv_handler"), php_iconv_output_handler_init TSRMLS_CC);
+ php_output_handler_conflict_register(ZEND_STRL("ob_iconv_handler"), php_iconv_output_conflict TSRMLS_CC);
+
return SUCCESS;
}
/* }}} */
@@ -312,6 +313,62 @@ PHP_MINFO_FUNCTION(miconv)
}
/* }}} */
+static int php_iconv_output_conflict(const char *handler_name, size_t handler_name_len TSRMLS_DC)
+{
+ if (php_output_get_level(TSRMLS_C)) {
+ if (php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("ob_iconv_handler") TSRMLS_CC)
+ || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("mb_output_handler") TSRMLS_CC)) {
+ return FAILURE;
+ }
+ }
+ return SUCCESS;
+}
+
+static php_output_handler *php_iconv_output_handler_init(const char *handler_name, size_t handler_name_len, size_t chunk_size, int flags TSRMLS_DC)
+{
+ return php_output_handler_create_internal(handler_name, handler_name_len, php_iconv_output_handler, chunk_size, flags TSRMLS_CC);
+}
+
+static int php_iconv_output_handler(void **nothing, php_output_context *output_context)
+{
+ char *s, *content_type, *mimetype = NULL;
+ int output_status, mimetype_len = 0;
+ PHP_OUTPUT_TSRMLS(output_context);
+
+ if (output_context->op & PHP_OUTPUT_HANDLER_START) {
+ output_status = php_output_get_status(TSRMLS_C);
+ if (output_status & PHP_OUTPUT_SENT) {
+ return FAILURE;
+ }
+
+ if (SG(sapi_headers).mimetype && !strncasecmp(SG(sapi_headers).mimetype, "text/", 5)) {
+ if ((s = strchr(SG(sapi_headers).mimetype,';')) == NULL){
+ mimetype = SG(sapi_headers).mimetype;
+ } else {
+ mimetype = SG(sapi_headers).mimetype;
+ mimetype_len = s - SG(sapi_headers).mimetype;
+ }
+ } else if (SG(sapi_headers).send_default_content_type) {
+ mimetype = SG(default_mimetype) ? SG(default_mimetype) : SAPI_DEFAULT_MIMETYPE;
+ }
+
+ if (mimetype != NULL && !(output_context->op & PHP_OUTPUT_HANDLER_CLEAN)) {
+ int len = spprintf(&content_type, 0, "Content-Type: %.*s; charset=%s", mimetype_len?mimetype_len:strlen(mimetype), mimetype, ICONVG(output_encoding));
+ if (content_type && SUCCESS == sapi_add_header(content_type, len, 0)) {
+ SG(sapi_headers).send_default_content_type = 0;
+ php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE, NULL TSRMLS_CC);
+ }
+ }
+ }
+
+ if (output_context->in.used) {
+ output_context->out.free = 1;
+ _php_iconv_show_error(php_iconv_string(output_context->in.data, output_context->in.used, &output_context->out.data, &output_context->out.used, ICONVG(output_encoding), ICONVG(internal_encoding)), ICONVG(output_encoding), ICONVG(internal_encoding) TSRMLS_CC);
+ }
+
+ return SUCCESS;
+}
+
/* {{{ _php_iconv_appendl() */
static php_iconv_err_t _php_iconv_appendl(smart_str *d, const char *s, size_t l, iconv_t cd)
{
@@ -1131,7 +1188,7 @@ static php_iconv_err_t _php_iconv_mime_encode(smart_str *pretval, const char *fn
goto out;
}
break;
-
+
default:
err = PHP_ICONV_ERR_UNKNOWN;
goto out;
@@ -1725,7 +1782,7 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char *st
break;
case '\n':
- scan_stat = 8;
+ scan_stat = 8;
break;
case '=': /* first letter of an encoded chunk */
@@ -2308,58 +2365,6 @@ PHP_NAMED_FUNCTION(php_if_iconv)
}
/* }}} */
-/* {{{ proto string ob_iconv_handler(string contents, int status)
- Returns str in output buffer converted to the iconv.output_encoding character set */
-PHP_FUNCTION(ob_iconv_handler)
-{
- char *out_buffer, *content_type, *mimetype = NULL, *s;
- zval *zv_string;
- size_t out_len;
- int mimetype_alloced = 0;
- long status;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &zv_string, &status) == FAILURE)
- return;
-
- convert_to_string(zv_string);
-
- if (SG(sapi_headers).mimetype &&
- strncasecmp(SG(sapi_headers).mimetype, "text/", 5) == 0) {
- if ((s = strchr(SG(sapi_headers).mimetype,';')) == NULL){
- mimetype = SG(sapi_headers).mimetype;
- } else {
- mimetype = estrndup(SG(sapi_headers).mimetype, s-SG(sapi_headers).mimetype);
- mimetype_alloced = 1;
- }
- } else if (SG(sapi_headers).send_default_content_type) {
- mimetype =(SG(default_mimetype) ? SG(default_mimetype) : SAPI_DEFAULT_MIMETYPE);
- }
- if (mimetype != NULL) {
- php_iconv_err_t err = php_iconv_string(Z_STRVAL_P(zv_string),
- Z_STRLEN_P(zv_string), &out_buffer, &out_len,
- ICONVG(output_encoding), ICONVG(internal_encoding));
- _php_iconv_show_error(err, ICONVG(output_encoding), ICONVG(internal_encoding) TSRMLS_CC);
- if (out_buffer != NULL) {
- int len = spprintf(&content_type, 0, "Content-Type:%s; charset=%s", mimetype, ICONVG(output_encoding));
- if (content_type && sapi_add_header(content_type, len, 0) != FAILURE) {
- SG(sapi_headers).send_default_content_type = 0;
- }
- if (mimetype_alloced) {
- efree(mimetype);
- }
- RETURN_STRINGL(out_buffer, out_len, 0);
- }
- if (mimetype_alloced) {
- efree(mimetype);
- }
- }
-
- zval_dtor(return_value);
- *return_value = *zv_string;
- zval_copy_ctor(return_value);
-}
-/* }}} */
-
/* {{{ proto bool iconv_set_encoding(string type, string charset)
Sets internal encoding and output encoding for ob_iconv_handler() */
PHP_FUNCTION(iconv_set_encoding)
@@ -2488,7 +2493,7 @@ static int php_iconv_stream_filter_append_bucket(
char *pd, *pt;
size_t ocnt, prev_ocnt, icnt, tcnt;
size_t initial_out_buf_size;
-
+
if (ps == NULL) {
initial_out_buf_size = 64;
icnt = 1;
@@ -2784,7 +2789,7 @@ static php_stream_filter *php_iconv_stream_filter_factory_create(const char *nam
pefree(inst, persistent);
}
- return retval;
+ return retval;
}
/* }}} */
diff --git a/ext/session/session.c b/ext/session/session.c
index 25fa28f..ad406d8 100644
--- a/ext/session/session.c
+++ b/ext/session/session.c
@@ -1093,8 +1093,8 @@ static int php_session_cache_limiter(TSRMLS_D) /* {{{ */
if (PS(cache_limiter)[0] == '\0') return 0;
if (SG(headers_sent)) {
- char *output_start_filename = php_get_output_start_filename(TSRMLS_C);
- int output_start_lineno = php_get_output_start_lineno(TSRMLS_C);
+ char *output_start_filename = php_output_get_start_filename(TSRMLS_C);
+ int output_start_lineno = php_output_get_start_lineno(TSRMLS_C);
if (output_start_filename) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot send session cache limiter - headers already sent (output started at %s:%d)", output_start_filename, output_start_lineno);
@@ -1133,8 +1133,8 @@ static void php_session_send_cookie(TSRMLS_D) /* {{{ */
char *e_session_name, *e_id;
if (SG(headers_sent)) {
- char *output_start_filename = php_get_output_start_filename(TSRMLS_C);
- int output_start_lineno = php_get_output_start_lineno(TSRMLS_C);
+ char *output_start_filename = php_output_get_start_filename(TSRMLS_C);
+ int output_start_lineno = php_output_get_start_lineno(TSRMLS_C);
if (output_start_filename) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot send session cookie - headers already sent by (output started at %s:%d)", output_start_filename, output_start_lineno);
diff --git a/ext/soap/soap.c b/ext/soap/soap.c
index 02e7550..c27b9d0 100644
--- a/ext/soap/soap.c
+++ b/ext/soap/soap.c
@@ -1650,7 +1650,7 @@ PHP_METHOD(SoapServer, handle)
ALLOC_INIT_ZVAL(retval);
- if (php_start_ob_buffer(NULL, 0, 0 TSRMLS_CC) != SUCCESS) {
+ if (php_output_start_default(TSRMLS_C) != SUCCESS) {
php_error_docref(NULL TSRMLS_CC, E_ERROR,"ob_start failed");
}
@@ -1738,7 +1738,7 @@ PHP_METHOD(SoapServer, handle)
#ifdef ZEND_ENGINE_2
if (EG(exception)) {
- php_end_ob_buffer(0, 0 TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
if (Z_TYPE_P(EG(exception)) == IS_OBJECT &&
instanceof_function(Z_OBJCE_P(EG(exception)), soap_fault_class_entry TSRMLS_CC)) {
soap_server_fault_ex(function, EG(exception), NULL TSRMLS_CC);
@@ -1792,7 +1792,7 @@ PHP_METHOD(SoapServer, handle)
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error calling constructor");
}
if (EG(exception)) {
- php_end_ob_buffer(0, 0 TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
if (Z_TYPE_P(EG(exception)) == IS_OBJECT &&
instanceof_function(Z_OBJCE_P(EG(exception)), soap_fault_class_entry TSRMLS_CC)) {
soap_server_fault_ex(function, EG(exception), NULL TSRMLS_CC);
@@ -1824,7 +1824,7 @@ PHP_METHOD(SoapServer, handle)
}
#ifdef ZEND_ENGINE_2
if (EG(exception)) {
- php_end_ob_buffer(0, 0 TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
if (Z_TYPE_P(EG(exception)) == IS_OBJECT &&
instanceof_function(Z_OBJCE_P(EG(exception)), soap_fault_class_entry TSRMLS_CC)) {
soap_server_fault_ex(function, EG(exception), NULL TSRMLS_CC);
@@ -1904,14 +1904,14 @@ PHP_METHOD(SoapServer, handle)
Z_TYPE_PP(tmp) != IS_NULL) {
headerfault = *tmp;
}
- php_end_ob_buffer(0, 0 TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
soap_server_fault_ex(function, &h->retval, h TSRMLS_CC);
efree(fn_name);
if (service->type == SOAP_CLASS && soap_obj) {zval_ptr_dtor(&soap_obj);}
goto fail;
#ifdef ZEND_ENGINE_2
} else if (EG(exception)) {
- php_end_ob_buffer(0, 0 TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
if (Z_TYPE_P(EG(exception)) == IS_OBJECT &&
instanceof_function(Z_OBJCE_P(EG(exception)), soap_fault_class_entry TSRMLS_CC)) {
zval *headerfault = NULL, **tmp;
@@ -1961,7 +1961,7 @@ PHP_METHOD(SoapServer, handle)
#ifdef ZEND_ENGINE_2
if (EG(exception)) {
- php_end_ob_buffer(0, 0 TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
if (Z_TYPE_P(EG(exception)) == IS_OBJECT &&
instanceof_function(Z_OBJCE_P(EG(exception)), soap_fault_class_entry TSRMLS_CC)) {
soap_server_fault_ex(function, EG(exception), NULL TSRMLS_CC);
@@ -1983,7 +1983,7 @@ PHP_METHOD(SoapServer, handle)
if (Z_TYPE_P(retval) == IS_OBJECT &&
instanceof_function(Z_OBJCE_P(retval), soap_fault_class_entry TSRMLS_CC)) {
- php_end_ob_buffer(0, 0 TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
soap_server_fault_ex(function, retval, NULL TSRMLS_CC);
goto fail;
}
@@ -2004,7 +2004,7 @@ PHP_METHOD(SoapServer, handle)
#ifdef ZEND_ENGINE_2
if (EG(exception)) {
- php_end_ob_buffer(0, 0 TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
if (Z_TYPE_P(EG(exception)) == IS_OBJECT &&
instanceof_function(Z_OBJCE_P(EG(exception)), soap_fault_class_entry TSRMLS_CC)) {
soap_server_fault_ex(function, EG(exception), NULL TSRMLS_CC);
@@ -2023,7 +2023,7 @@ PHP_METHOD(SoapServer, handle)
#endif
/* Flush buffer */
- php_end_ob_buffer(0, 0 TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
if (doc_return) {
/* xmlDocDumpMemoryEnc(doc_return, &buf, &size, XML_CHAR_ENCODING_UTF8); */
@@ -2041,39 +2041,14 @@ PHP_METHOD(SoapServer, handle)
xmlFreeDoc(doc_return);
- if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0) &&
- zend_hash_exists(EG(function_table), "ob_gzhandler", sizeof("ob_gzhandler"))) {
- zval nm_ob_gzhandler;
- zval str;
- zval mode;
- zval result;
- zval *params[2];
-
- INIT_ZVAL(result);
- ZVAL_STRINGL(&nm_ob_gzhandler, "ob_gzhandler", sizeof("ob_gzhandler") - 1, 0);
- INIT_PZVAL(&str);
- ZVAL_STRINGL(&str, (char*)buf, size, 0);
- params[0] = &str;
- INIT_PZVAL(&mode);
- ZVAL_LONG(&mode, PHP_OUTPUT_HANDLER_START | PHP_OUTPUT_HANDLER_END);
- params[1] = &mode;
- if (call_user_function(CG(function_table), NULL, &nm_ob_gzhandler, &result, 2, params TSRMLS_CC) != FAILURE &&
- Z_TYPE(result) == IS_STRING &&
- zend_alter_ini_entry("zlib.output_compression", sizeof("zlib.output_compression"), "0", sizeof("0")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME) == SUCCESS) {
- xmlFree(buf);
- buf = NULL;
- snprintf(cont_len, sizeof(cont_len), "Content-Length: %d", Z_STRLEN(result));
- sapi_add_header(cont_len, strlen(cont_len), 1);
- php_write(Z_STRVAL(result), Z_STRLEN(result) TSRMLS_CC);
- }
- zval_dtor(&result);
- }
- if (buf) {
+ if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)) {
+ sapi_add_header("Connection: close", sizeof("Connection: close")-1, 1);
+ } else {
snprintf(cont_len, sizeof(cont_len), "Content-Length: %d", size);
sapi_add_header(cont_len, strlen(cont_len), 1);
- php_write(buf, size TSRMLS_CC);
- xmlFree(buf);
}
+ php_write(buf, size TSRMLS_CC);
+ xmlFree(buf);
} else {
sapi_add_header("HTTP/1.1 202 Accepted", sizeof("HTTP/1.1 202 Accepted")-1, 1);
sapi_add_header("Content-Length: 0", sizeof("Content-Length: 0")-1, 1);
@@ -2212,47 +2187,22 @@ static void soap_server_fault_ex(sdlFunctionPtr function, zval* fault, soapHeade
if (use_http_error_status) {
sapi_add_header("HTTP/1.1 500 Internal Service Error", sizeof("HTTP/1.1 500 Internal Service Error")-1, 1);
}
+ if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)) {
+ sapi_add_header("Connection: close", sizeof("Connection: close")-1, 1);
+ } else {
+ snprintf(cont_len, sizeof(cont_len), "Content-Length: %d", size);
+ sapi_add_header(cont_len, strlen(cont_len), 1);
+ }
if (soap_version == SOAP_1_2) {
sapi_add_header("Content-Type: application/soap+xml; charset=utf-8", sizeof("Content-Type: application/soap+xml; charset=utf-8")-1, 1);
} else {
sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8")-1, 1);
}
- if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0) &&
- zend_hash_exists(EG(function_table), "ob_gzhandler", sizeof("ob_gzhandler"))) {
- zval nm_ob_gzhandler;
- zval str;
- zval mode;
- zval result;
- zval *params[2];
-
- INIT_ZVAL(result);
- ZVAL_STRINGL(&nm_ob_gzhandler, "ob_gzhandler", sizeof("ob_gzhandler") - 1, 0);
- INIT_PZVAL(&str);
- ZVAL_STRINGL(&str, (char*)buf, size, 0);
- params[0] = &str;
- INIT_PZVAL(&mode);
- ZVAL_LONG(&mode, PHP_OUTPUT_HANDLER_START | PHP_OUTPUT_HANDLER_END);
- params[1] = &mode;
- if (call_user_function(CG(function_table), NULL, &nm_ob_gzhandler, &result, 2, params TSRMLS_CC) != FAILURE &&
- Z_TYPE(result) == IS_STRING &&
- zend_alter_ini_entry("zlib.output_compression", sizeof("zlib.output_compression"), "0", sizeof("0")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME) == SUCCESS) {
- xmlFree(buf);
- buf = NULL;
- snprintf(cont_len, sizeof(cont_len), "Content-Length: %d", Z_STRLEN(result));
- sapi_add_header(cont_len, strlen(cont_len), 1);
- php_write(Z_STRVAL(result), Z_STRLEN(result) TSRMLS_CC);
- }
- zval_dtor(&result);
- }
- if (buf) {
- snprintf(cont_len, sizeof(cont_len), "Content-Length: %d", size);
- sapi_add_header(cont_len, strlen(cont_len), 1);
- php_write(buf, size TSRMLS_CC);
- xmlFree(buf);
- }
+ php_write(buf, size TSRMLS_CC);
xmlFreeDoc(doc_return);
+ xmlFree(buf);
zend_clear_exception(TSRMLS_C);
}
@@ -2415,11 +2365,11 @@ static void soap_error_handler(int error_num, const char *error_filename, const
}
/* Get output buffer and send as fault detials */
- if (php_ob_get_length(&outbuflen TSRMLS_CC) != FAILURE && Z_LVAL(outbuflen) != 0) {
+ if (php_output_get_length(&outbuflen TSRMLS_CC) != FAILURE && Z_LVAL(outbuflen) != 0) {
ALLOC_INIT_ZVAL(outbuf);
- php_ob_get_buffer(outbuf TSRMLS_CC);
+ php_output_get_contents(outbuf TSRMLS_CC);
}
- php_end_ob_buffer(0, 0 TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
}
INIT_ZVAL(fault_obj);
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index fd16d4a..c48c01e 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -5055,7 +5055,7 @@ ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highl
PHP_FUNCTION(highlight_file)
{
char *filename;
- int filename_len;
+ int filename_len, ret;
zend_syntax_highlighter_ini syntax_highlighter_ini;
zend_bool i = 0;
@@ -5068,32 +5068,23 @@ PHP_FUNCTION(highlight_file)
}
if (i) {
- php_start_ob_buffer (NULL, 0, 1 TSRMLS_CC);
+ php_output_start_default(TSRMLS_C);
}
php_get_highlight_struct(&syntax_highlighter_ini);
- if (highlight_file(filename, &syntax_highlighter_ini TSRMLS_CC) == FAILURE) {
- if (i) {
- int res = php_ob_get_buffer(return_value TSRMLS_CC);
+ ret = highlight_file(filename, &syntax_highlighter_ini TSRMLS_CC);
- /* flush the buffer only if there is something to flush */
- if (res == SUCCESS && Z_STRLEN_P(return_value) > 0) {
- php_end_ob_buffer (1, 0 TSRMLS_CC);
- zval_dtor(return_value);
- } else {
- php_end_ob_buffer (0, 0 TSRMLS_CC);
- if (res == SUCCESS) {
- zval_dtor(return_value);
- }
- }
+ if (ret == FAILURE) {
+ if (i) {
+ php_output_end(TSRMLS_C);
}
RETURN_FALSE;
}
if (i) {
- php_ob_get_buffer (return_value TSRMLS_CC);
- php_end_ob_buffer (0, 0 TSRMLS_CC);
+ php_output_get_contents(return_value TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
} else {
RETURN_TRUE;
}
@@ -5113,25 +5104,26 @@ PHP_FUNCTION(php_strip_whitespace)
RETURN_FALSE;
}
+ php_output_start_default(TSRMLS_C);
+
file_handle.type = ZEND_HANDLE_FILENAME;
file_handle.filename = filename;
file_handle.free_filename = 0;
file_handle.opened_path = NULL;
zend_save_lexical_state(&original_lex_state TSRMLS_CC);
- if (open_file_for_scanning(&file_handle TSRMLS_CC)==FAILURE) {
+ if (open_file_for_scanning(&file_handle TSRMLS_CC) == FAILURE) {
zend_restore_lexical_state(&original_lex_state TSRMLS_CC);
+ php_output_end(TSRMLS_C);
RETURN_EMPTY_STRING();
}
- php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC);
-
zend_strip(TSRMLS_C);
zend_destroy_file_handle(&file_handle TSRMLS_CC);
zend_restore_lexical_state(&original_lex_state TSRMLS_CC);
- php_ob_get_buffer(return_value TSRMLS_CC);
- php_end_ob_buffer(0, 0 TSRMLS_CC);
+ php_output_get_contents(return_value TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
}
/* }}} */
@@ -5151,7 +5143,7 @@ PHP_FUNCTION(highlight_string)
convert_to_string_ex(expr);
if (i) {
- php_start_ob_buffer (NULL, 0, 1 TSRMLS_CC);
+ php_output_start_default(TSRMLS_C);
}
EG(error_reporting) = E_ERROR;
@@ -5164,7 +5156,7 @@ PHP_FUNCTION(highlight_string)
efree(hicompiled_string_description);
EG(error_reporting) = old_error_reporting;
if (i) {
- php_end_ob_buffer (1, 0 TSRMLS_CC);
+ php_output_end(TSRMLS_C);
}
RETURN_FALSE;
}
@@ -5173,8 +5165,8 @@ PHP_FUNCTION(highlight_string)
EG(error_reporting) = old_error_reporting;
if (i) {
- php_ob_get_buffer (return_value TSRMLS_CC);
- php_end_ob_buffer (0, 0 TSRMLS_CC);
+ php_output_get_contents(return_value TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
} else {
RETURN_TRUE;
}
@@ -5416,14 +5408,14 @@ PHP_FUNCTION(print_r)
}
if (do_return) {
- php_start_ob_buffer (NULL, 0, 1 TSRMLS_CC);
+ php_output_start_default(TSRMLS_C);
}
zend_print_zval_r(var, 0 TSRMLS_CC);
if (do_return) {
- php_ob_get_buffer (return_value TSRMLS_CC);
- php_end_ob_buffer (0, 0 TSRMLS_CC);
+ php_output_get_contents(return_value TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
} else {
RETURN_TRUE;
}
diff --git a/ext/standard/exec.c b/ext/standard/exec.c
index ab8daa9..d52c0dd 100644
--- a/ext/standard/exec.c
+++ b/ext/standard/exec.c
@@ -108,8 +108,10 @@ PHPAPI int php_exec(int type, char *cmd, zval *array, zval *return_value TSRMLS_
}
if (type == 1) {
+ int ob_level;
+
PHPWRITE(buf, bufl);
- if (OG(ob_nesting_level) < 1) {
+ if (php_output_get_level(TSRMLS_C) < 1) {
sapi_flush(TSRMLS_C);
}
} else if (type == 2) {
diff --git a/ext/standard/head.c b/ext/standard/head.c
index 5b297b9..2293985 100644
--- a/ext/standard/head.c
+++ b/ext/standard/head.c
@@ -228,8 +228,8 @@ PHP_FUNCTION(headers_sent)
return;
if (SG(headers_sent)) {
- line = php_get_output_start_lineno(TSRMLS_C);
- file = php_get_output_start_filename(TSRMLS_C);
+ line = php_output_get_start_lineno(TSRMLS_C);
+ file = php_output_get_start_filename(TSRMLS_C);
}
switch(ZEND_NUM_ARGS()) {
diff --git a/ext/standard/info.c b/ext/standard/info.c
index 480317b..d3a7503 100644
--- a/ext/standard/info.c
+++ b/ext/standard/info.c
@@ -38,16 +38,15 @@
#include <sys/utsname.h>
#endif
+
#ifdef PHP_WIN32
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
-
# include "winver.h"
-#if _MSC_VER < 1300
-# define OSVERSIONINFOEX php_win_OSVERSIONINFOEX
-#endif
-
+# if _MSC_VER < 1300
+# define OSVERSIONINFOEX php_win_OSVERSIONINFOEX
+# endif
#endif
#if HAVE_MBSTRING
@@ -61,7 +60,7 @@ ZEND_EXTERN_MODULE_GLOBALS(iconv)
#endif
#define SECTION(name) if (!sapi_module.phpinfo_as_text) { \
- PUTS("<h2>" name "</h2>\n"); \
+ php_info_print("<h2>" name "</h2>\n"); \
} else { \
php_info_print_table_start(); \
php_info_print_table_header(1, name); \
@@ -71,29 +70,99 @@ ZEND_EXTERN_MODULE_GLOBALS(iconv)
PHPAPI extern char *php_ini_opened_path;
PHPAPI extern char *php_ini_scanned_path;
PHPAPI extern char *php_ini_scanned_files;
-
-static int php_info_write_wrapper(const char *str, uint str_length)
+
+static int php_info_print_html_esc(const char *str, int len) /* {{{ */
{
int new_len, written;
- char *elem_esc;
+ char *new_str;
+ TSRMLS_FETCH();
+
+ new_str = php_escape_html_entities((char *) str, len, &new_len, 0, ENT_QUOTES, "utf-8" TSRMLS_CC);
+ written = php_output_write(new_str, new_len TSRMLS_CC);
+ efree(new_str);
+ return written;
+}
+/* }}} */
+static int php_info_printf(const char *fmt, ...) /* {{{ */
+{
+ char *buf;
+ int len, written;
+ va_list argv;
TSRMLS_FETCH();
+
+ va_start(argv, fmt);
+ len = vspprintf(&buf, 0, fmt, argv);
+ va_end(argv);
+
+ written = php_output_write(buf, len TSRMLS_CC);
+ efree(buf);
+ return written;
+}
+/* }}} */
- elem_esc = php_escape_html_entities((unsigned char *)str, str_length, &new_len, 0, ENT_QUOTES, NULL TSRMLS_CC);
+static void php_info_print_request_uri(TSRMLS_D) /* {{{ */
+{
+ if (SG(request_info).request_uri) {
+ php_info_print_html_esc(SG(request_info).request_uri, strlen(SG(request_info).request_uri));
+ }
+}
+/* }}} */
- written = php_body_write(elem_esc, new_len TSRMLS_CC);
+static int php_info_print(const char *str) /* {{{ */
+{
+ TSRMLS_FETCH();
+ return php_output_write(str, strlen(str) TSRMLS_CC);
+}
+/* }}} */
- efree(elem_esc);
+static void php_info_print_stream_hash(const char *name, HashTable *ht TSRMLS_DC) /* {{{ */
+{
+ char *key;
+ uint len;
+ int type;
+
+ if (ht) {
+ if (zend_hash_num_elements(ht)) {
+ HashPosition pos;
- return written;
+ if (!sapi_module.phpinfo_as_text) {
+ php_info_printf("<tr class=\"v\"><td>Registered %s</td><td>", name);
+ } else {
+ php_info_printf("\nRegistered %s => ", name);
+ }
+
+ zend_hash_internal_pointer_reset_ex(ht, &pos);
+ while (zend_hash_get_current_key_ex(ht, &key, &len, NULL, 0, &pos) == HASH_KEY_IS_STRING)
+ {
+ php_info_print(key);
+ zend_hash_move_forward_ex(ht, &pos);
+ if (zend_hash_get_current_key_ex(ht, &key, &len, NULL, 0, &pos) == HASH_KEY_IS_STRING) {
+ php_info_print(", ");
+ } else {
+ break;
+ }
+ }
+
+ if (!sapi_module.phpinfo_as_text) {
+ php_info_print("</td></tr>\n");
+ }
+ } else {
+ char reg_name[128];
+ snprintf(reg_name, sizeof(reg_name), "Registered %s", name);
+ php_info_print_table_row(2, reg_name, "none registered");
+ }
+ } else {
+ php_info_print_table_row(2, name, "disabled");
+ }
}
-
+/* }}} */
PHPAPI void php_info_print_module(zend_module_entry *zend_module TSRMLS_DC) /* {{{ */
{
if (zend_module->info_func || zend_module->version) {
if (!sapi_module.phpinfo_as_text) {
- php_printf("<h2><a name=\"module_%s\">%s</a></h2>\n", zend_module->name, zend_module->name);
+ php_info_printf("<h2><a name=\"module_%s\">%s</a></h2>\n", zend_module->name, zend_module->name);
} else {
php_info_print_table_start();
php_info_print_table_header(1, zend_module->name);
@@ -109,9 +178,9 @@ PHPAPI void php_info_print_module(zend_module_entry *zend_module TSRMLS_DC) /* {
}
} else {
if (!sapi_module.phpinfo_as_text) {
- php_printf("<tr><td>%s</td></tr>\n", zend_module->name);
+ php_info_printf("<tr><td>%s</td></tr>\n", zend_module->name);
} else {
- php_printf("%s\n", zend_module->name);
+ php_info_printf("%s\n", zend_module->name);
}
}
}
@@ -151,70 +220,66 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC)
zend_hash_internal_pointer_reset(Z_ARRVAL_PP(data));
while (zend_hash_get_current_data(Z_ARRVAL_PP(data), (void **) &tmp) == SUCCESS) {
if (!sapi_module.phpinfo_as_text) {
- PUTS("<tr>");
- PUTS("<td class=\"e\">");
-
+ php_info_print("<tr>");
+ php_info_print("<td class=\"e\">");
}
- PUTS(name);
- PUTS("[\"");
+ php_info_print(name);
+ php_info_print("[\"");
switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(data), &string_key, &string_len, &num_key, 0, NULL)) {
case HASH_KEY_IS_STRING:
if (!sapi_module.phpinfo_as_text) {
- php_info_html_esc_write(string_key, string_len - 1 TSRMLS_CC);
+ php_info_print_html_esc(string_key, string_len-1);
} else {
- PHPWRITE(string_key, string_len - 1);
- }
+ php_info_print(string_key);
+ }
break;
case HASH_KEY_IS_LONG:
- php_printf("%ld", num_key);
+ php_info_printf("%ld", num_key);
break;
}
- PUTS("\"]");
+ php_info_print("\"]");
if (!sapi_module.phpinfo_as_text) {
- PUTS("</td><td class=\"v\">");
+ php_info_print("</td><td class=\"v\">");
} else {
- PUTS(" => ");
+ php_info_print(" => ");
}
if (Z_TYPE_PP(tmp) == IS_ARRAY) {
if (!sapi_module.phpinfo_as_text) {
- PUTS("<pre>");
- zend_print_zval_r_ex((zend_write_func_t) php_info_write_wrapper, *tmp, 0 TSRMLS_CC);
- PUTS("</pre>");
+ php_info_print("<pre>");
+ zend_print_zval_r_ex((zend_write_func_t) php_info_print_html_esc, *tmp, 0 TSRMLS_CC);
+ php_info_print("</pre>");
} else {
zend_print_zval_r(*tmp, 0 TSRMLS_CC);
}
- } else if (Z_TYPE_PP(tmp) != IS_STRING) {
- tmp2 = **tmp;
- zval_copy_ctor(&tmp2);
- convert_to_string(&tmp2);
- if (!sapi_module.phpinfo_as_text) {
- if (Z_STRLEN(tmp2) == 0) {
- PUTS("<i>no value</i>");
- } else {
- php_info_html_esc_write(Z_STRVAL(tmp2), Z_STRLEN(tmp2) TSRMLS_CC);
- }
- } else {
- PHPWRITE(Z_STRVAL(tmp2), Z_STRLEN(tmp2));
- }
- zval_dtor(&tmp2);
} else {
- if (!sapi_module.phpinfo_as_text) {
- if (Z_STRLEN_PP(tmp) == 0) {
- PUTS("<i>no value</i>");
- } else {
- php_info_html_esc_write(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp) TSRMLS_CC);
- }
- } else {
- PHPWRITE(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
- }
+ tmp2 = **tmp;
+ switch (Z_TYPE_PP(tmp)) {
+ default:
+ tmp = NULL;
+ zval_copy_ctor(&tmp2);
+ convert_to_string(&tmp2);
+ case IS_STRING:
+ if (!sapi_module.phpinfo_as_text) {
+ if (Z_STRLEN(tmp2) == 0) {
+ php_info_print("<i>no value</i>");
+ } else {
+ php_info_print_html_esc(Z_STRVAL(tmp2), Z_STRLEN(tmp2));
+ }
+ } else {
+ php_info_print(Z_STRVAL(tmp2));
+ }
+ }
+ if (!tmp) {
+ zval_dtor(&tmp2);
+ }
}
if (!sapi_module.phpinfo_as_text) {
- PUTS("</td></tr>\n");
+ php_info_print("</td></tr>\n");
} else {
- PUTS("\n");
- }
+ php_info_print("\n");
+ }
zend_hash_move_forward(Z_ARRVAL_PP(data));
}
}
@@ -225,21 +290,9 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC)
*/
void php_info_print_style(TSRMLS_D)
{
- php_printf("<style type=\"text/css\">\n");
+ php_info_printf("<style type=\"text/css\">\n");
php_info_print_css(TSRMLS_C);
- php_printf("</style>\n");
-}
-/* }}} */
-
-/* {{{ php_info_html_esc_write
- */
-PHPAPI void php_info_html_esc_write(char *string, int str_len TSRMLS_DC)
-{
- int new_len;
- char *ret = php_escape_html_entities((unsigned char *)string, str_len, &new_len, 0, ENT_QUOTES, NULL TSRMLS_CC);
-
- PHPWRITE(ret, new_len);
- efree(ret);
+ php_info_printf("</style>\n");
}
/* }}} */
@@ -248,13 +301,13 @@ PHPAPI void php_info_html_esc_write(char *string, int str_len TSRMLS_DC)
PHPAPI char *php_info_html_esc(char *string TSRMLS_DC)
{
int new_len;
- return php_escape_html_entities((unsigned char *)string, strlen(string), &new_len, 0, ENT_QUOTES, NULL TSRMLS_CC);
+ return php_escape_html_entities(string, strlen(string), &new_len, 0, ENT_QUOTES, NULL TSRMLS_CC);
}
/* }}} */
-
#ifdef PHP_WIN32
/* {{{ */
+
char* php_get_windows_name()
{
OSVERSIONINFOEX osvi;
@@ -360,9 +413,9 @@ char* php_get_windows_name()
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) {
if (GetSystemMetrics(SM_SERVERR2))
major = "Windows Server 2003 R2";
- else if (osvi.wSuiteMask == VER_SUITE_STORAGE_SERVER)
+ else if (osvi.wSuiteMask==VER_SUITE_STORAGE_SERVER)
major = "Windows Storage Server 2003";
- else if (osvi.wSuiteMask == VER_SUITE_WH_SERVER)
+ else if (osvi.wSuiteMask==VER_SUITE_WH_SERVER)
major = "Windows Home Server";
else if (osvi.wProductType == VER_NT_WORKSTATION &&
si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) {
@@ -588,54 +641,18 @@ PHPAPI char *php_get_uname(char mode)
}
/* }}} */
-
/* {{{ php_print_info_htmlhead
*/
PHPAPI void php_print_info_htmlhead(TSRMLS_D)
{
-
-/*** none of this is needed now ***
-
- const char *charset = NULL;
-
- if (SG(default_charset)) {
- charset = SG(default_charset);
- }
-
-#if HAVE_MBSTRING
- if (php_ob_handler_used("mb_output_handler" TSRMLS_CC)) {
- if (MBSTRG(current_http_output_encoding) == mbfl_no_encoding_pass) {
- charset = "US-ASCII";
- } else {
- charset = mbfl_no2preferred_mime_name(MBSTRG(current_http_output_encoding));
- }
- }
-#endif
-
-#if HAVE_ICONV
- if (php_ob_handler_used("ob_iconv_handler" TSRMLS_CC)) {
- charset = ICONVG(output_encoding);
- }
-#endif
-
- if (!charset || !charset[0]) {
- charset = "US-ASCII";
- }
-
-*** none of that is needed now ***/
-
-
- PUTS("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n");
- PUTS("<html>");
- PUTS("<head>\n");
+ php_info_print("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n");
+ php_info_print("<html>");
+ php_info_print("<head>\n");
php_info_print_style(TSRMLS_C);
- PUTS("<title>phpinfo()</title>");
- PUTS("<meta name=\"ROBOTS\" content=\"NOINDEX,NOFOLLOW,NOARCHIVE\" />");
-/*
- php_printf("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\" />\n", charset);
-*/
- PUTS("</head>\n");
- PUTS("<body><div class=\"center\">\n");
+ php_info_print("<title>phpinfo()</title>");
+ php_info_print("<meta name=\"ROBOTS\" content=\"NOINDEX,NOFOLLOW,NOARCHIVE\" />");
+ php_info_print("</head>\n");
+ php_info_print("<body><div class=\"center\">\n");
}
/* }}} */
@@ -661,8 +678,8 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
if (!sapi_module.phpinfo_as_text) {
php_print_info_htmlhead(TSRMLS_C);
} else {
- PUTS("phpinfo()\n");
- }
+ php_info_print("phpinfo()\n");
+ }
if (flag & PHP_INFO_GENERAL) {
char *zend_version = get_zend_version();
@@ -676,21 +693,17 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
}
if (expose_php && !sapi_module.phpinfo_as_text) {
- PUTS("<a href=\"http://www.php.net/\"><img border=\"0\" src=\"");
- if (SG(request_info).request_uri) {
- char *elem_esc = php_info_html_esc(SG(request_info).request_uri TSRMLS_CC);
- PUTS(elem_esc);
- efree(elem_esc);
- }
- PUTS("?=");
+ php_info_print("<a href=\"http://www.php.net/\"><img border=\"0\" src=\"");
+ php_info_print_request_uri(TSRMLS_C);
+ php_info_print("?=");
logo_guid = php_logo_guid();
- PUTS(logo_guid);
+ php_info_print(logo_guid);
efree(logo_guid);
- PUTS("\" alt=\"PHP Logo\" /></a>");
+ php_info_print("\" alt=\"PHP Logo\" /></a>");
}
if (!sapi_module.phpinfo_as_text) {
- php_printf("<h1 class=\"p\">PHP Version %s</h1>\n", PHP_VERSION);
+ php_info_printf("<h1 class=\"p\">PHP Version %s</h1>\n", PHP_VERSION);
} else {
php_info_print_table_row(2, "PHP Version", PHP_VERSION);
}
@@ -766,139 +779,24 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
#else
php_info_print_table_row(2, "DTrace Support", "disabled" );
#endif
- {
- HashTable *url_stream_wrappers_hash;
- char *stream_protocol, *stream_protocols_buf = NULL;
- int stream_protocol_len, stream_protocols_buf_len = 0;
- ulong num_key;
-
- if ((url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash())) {
- HashPosition pos;
- for (zend_hash_internal_pointer_reset_ex(url_stream_wrappers_hash, &pos);
- zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, (uint *)&stream_protocol_len, &num_key, 0, &pos) == HASH_KEY_IS_STRING;
- zend_hash_move_forward_ex(url_stream_wrappers_hash, &pos)) {
- stream_protocols_buf = erealloc(stream_protocols_buf, stream_protocols_buf_len + stream_protocol_len + 2 + 1);
- memcpy(stream_protocols_buf + stream_protocols_buf_len, stream_protocol, stream_protocol_len - 1);
- stream_protocols_buf[stream_protocols_buf_len + stream_protocol_len - 1] = ',';
- stream_protocols_buf[stream_protocols_buf_len + stream_protocol_len] = ' ';
- stream_protocols_buf_len += stream_protocol_len + 1;
- }
- if (stream_protocols_buf) {
- stream_protocols_buf[stream_protocols_buf_len - 2] = ' ';
- stream_protocols_buf[stream_protocols_buf_len] = 0;
- php_info_print_table_row(2, "Registered PHP Streams", stream_protocols_buf);
- efree(stream_protocols_buf);
- } else {
- /* Any chances we will ever hit this? */
- php_info_print_table_row(2, "Registered PHP Streams", "no streams registered");
- }
- } else {
- /* Any chances we will ever hit this? */
- php_info_print_table_row(2, "PHP Streams", "disabled"); /* ?? */
- }
- }
-
- {
- HashTable *stream_xport_hash;
- char *xport_name, *xport_buf = NULL;
- int xport_name_len, xport_buf_len = 0, xport_buf_size = 0;
- ulong num_key;
-
- if ((stream_xport_hash = php_stream_xport_get_hash())) {
- HashPosition pos;
- for(zend_hash_internal_pointer_reset_ex(stream_xport_hash, &pos);
- zend_hash_get_current_key_ex(stream_xport_hash, &xport_name, (uint *)&xport_name_len, &num_key, 0, &pos) == HASH_KEY_IS_STRING;
- zend_hash_move_forward_ex(stream_xport_hash, &pos)) {
- if (xport_buf_len + xport_name_len + 2 > xport_buf_size) {
- while (xport_buf_len + xport_name_len + 2 > xport_buf_size) {
- xport_buf_size += 256;
- }
- if (xport_buf) {
- xport_buf = erealloc(xport_buf, xport_buf_size);
- } else {
- xport_buf = emalloc(xport_buf_size);
- }
- }
- if (xport_buf_len > 0) {
- xport_buf[xport_buf_len++] = ',';
- xport_buf[xport_buf_len++] = ' ';
- }
- memcpy(xport_buf + xport_buf_len, xport_name, xport_name_len - 1);
- xport_buf_len += xport_name_len - 1;
- xport_buf[xport_buf_len] = '\0';
- }
- if (xport_buf) {
- php_info_print_table_row(2, "Registered Stream Socket Transports", xport_buf);
- efree(xport_buf);
- } else {
- /* Any chances we will ever hit this? */
- php_info_print_table_row(2, "Registered Stream Socket Transports", "no transports registered");
- }
- } else {
- /* Any chances we will ever hit this? */
- php_info_print_table_row(2, "Stream Socket Transports", "disabled"); /* ?? */
- }
- }
-
- {
- HashTable *stream_filter_hash;
- char *filter_name, *filter_buf = NULL;
- int filter_name_len, filter_buf_len = 0, filter_buf_size = 0;
- ulong num_key;
-
- if ((stream_filter_hash = php_get_stream_filters_hash())) {
- HashPosition pos;
- for(zend_hash_internal_pointer_reset_ex(stream_filter_hash, &pos);
- zend_hash_get_current_key_ex(stream_filter_hash, &filter_name, (uint *)&filter_name_len, &num_key, 0, &pos) == HASH_KEY_IS_STRING;
- zend_hash_move_forward_ex(stream_filter_hash, &pos)) {
- if (filter_buf_len + filter_name_len + 2 > filter_buf_size) {
- while (filter_buf_len + filter_name_len + 2 > filter_buf_size) {
- filter_buf_size += 256;
- }
- if (filter_buf) {
- filter_buf = erealloc(filter_buf, filter_buf_size);
- } else {
- filter_buf = emalloc(filter_buf_size);
- }
- }
- if (filter_buf_len > 0) {
- filter_buf[filter_buf_len++] = ',';
- filter_buf[filter_buf_len++] = ' ';
- }
- memcpy(filter_buf + filter_buf_len, filter_name, filter_name_len - 1);
- filter_buf_len += filter_name_len - 1;
- filter_buf[filter_buf_len] = '\0';
- }
- if (filter_buf) {
- php_info_print_table_row(2, "Registered Stream Filters", filter_buf);
- efree(filter_buf);
- } else {
- /* Any chances we will ever hit this? */
- php_info_print_table_row(2, "Registered Stream Filters", "no filters registered");
- }
- } else {
- /* Any chances we will ever hit this? */
- php_info_print_table_row(2, "Stream Filters", "disabled"); /* ?? */
- }
- }
+ php_info_print_stream_hash("PHP Streams", php_stream_get_url_stream_wrappers_hash() TSRMLS_CC);
+ php_info_print_stream_hash("Stream Socket Transports", php_stream_xport_get_hash() TSRMLS_CC);
+ php_info_print_stream_hash("Stream Filters", php_get_stream_filters_hash() TSRMLS_CC);
+
php_info_print_table_end();
/* Zend Engine */
php_info_print_box_start(0);
if (expose_php && !sapi_module.phpinfo_as_text) {
- PUTS("<a href=\"http://www.zend.com/\"><img border=\"0\" src=\"");
- if (SG(request_info).request_uri) {
- char *elem_esc = php_info_html_esc(SG(request_info).request_uri TSRMLS_CC);
- PUTS(elem_esc);
- efree(elem_esc);
- }
- PUTS("?="ZEND_LOGO_GUID"\" alt=\"Zend logo\" /></a>\n");
+ php_info_print("<a href=\"http://www.zend.com/\"><img border=\"0\" src=\"");
+ php_info_print_request_uri(TSRMLS_C);
+ php_info_print("?="ZEND_LOGO_GUID"\" alt=\"Zend logo\" /></a>\n");
}
- PUTS("This program makes use of the Zend Scripting Language Engine:");
- PUTS(!sapi_module.phpinfo_as_text?"<br />":"\n");
+ php_info_print("This program makes use of the Zend Scripting Language Engine:");
+ php_info_print(!sapi_module.phpinfo_as_text?"<br />":"\n");
if (sapi_module.phpinfo_as_text) {
- PUTS(zend_version);
+ php_info_print(zend_version);
} else {
zend_html_puts(zend_version, strlen(zend_version) TSRMLS_CC);
}
@@ -908,15 +806,11 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
if ((flag & PHP_INFO_CREDITS) && expose_php && !sapi_module.phpinfo_as_text) {
php_info_print_hr();
- PUTS("<h1><a href=\"");
- if (SG(request_info).request_uri) {
- char *elem_esc = php_info_html_esc(SG(request_info).request_uri TSRMLS_CC);
- PUTS(elem_esc);
- efree(elem_esc);
- }
- PUTS("?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000\">");
- PUTS("PHP Credits");
- PUTS("</a></h1>\n");
+ php_info_print("<h1><a href=\"");
+ php_info_print_request_uri(TSRMLS_C);
+ php_info_print("?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000\">");
+ php_info_print("PHP Credits");
+ php_info_print("</a></h1>\n");
}
zend_ini_sort_entries(TSRMLS_C);
@@ -924,7 +818,7 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
if (flag & PHP_INFO_CONFIGURATION) {
php_info_print_hr();
if (!sapi_module.phpinfo_as_text) {
- PUTS("<h1>Configuration</h1>\n");
+ php_info_print("<h1>Configuration</h1>\n");
} else {
SECTION("Configuration");
}
@@ -1004,103 +898,108 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
if (!sapi_module.phpinfo_as_text) {
SECTION("PHP License");
php_info_print_box_start(0);
- PUTS("<p>\n");
- PUTS("This program is free software; you can redistribute it and/or modify ");
- PUTS("it under the terms of the PHP License as published by the PHP Group ");
- PUTS("and included in the distribution in the file: LICENSE\n");
- PUTS("</p>\n");
- PUTS("<p>");
- PUTS("This program is distributed in the hope that it will be useful, ");
- PUTS("but WITHOUT ANY WARRANTY; without even the implied warranty of ");
- PUTS("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
- PUTS("</p>\n");
- PUTS("<p>");
- PUTS("If you did not receive a copy of the PHP license, or have any questions about ");
- PUTS("PHP licensing, please contact license@php.net.\n");
- PUTS("</p>\n");
+ php_info_print("<p>\n");
+ php_info_print("This program is free software; you can redistribute it and/or modify ");
+ php_info_print("it under the terms of the PHP License as published by the PHP Group ");
+ php_info_print("and included in the distribution in the file: LICENSE\n");
+ php_info_print("</p>\n");
+ php_info_print("<p>");
+ php_info_print("This program is distributed in the hope that it will be useful, ");
+ php_info_print("but WITHOUT ANY WARRANTY; without even the implied warranty of ");
+ php_info_print("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
+ php_info_print("</p>\n");
+ php_info_print("<p>");
+ php_info_print("If you did not receive a copy of the PHP license, or have any questions about ");
+ php_info_print("PHP licensing, please contact license@php.net.\n");
+ php_info_print("</p>\n");
php_info_print_box_end();
} else {
- PUTS("\nPHP License\n");
- PUTS("This program is free software; you can redistribute it and/or modify\n");
- PUTS("it under the terms of the PHP License as published by the PHP Group\n");
- PUTS("and included in the distribution in the file: LICENSE\n");
- PUTS("\n");
- PUTS("This program is distributed in the hope that it will be useful,\n");
- PUTS("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
- PUTS("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
- PUTS("\n");
- PUTS("If you did not receive a copy of the PHP license, or have any\n");
- PUTS("questions about PHP licensing, please contact license@php.net.\n");
+ php_info_print("\nPHP License\n");
+ php_info_print("This program is free software; you can redistribute it and/or modify\n");
+ php_info_print("it under the terms of the PHP License as published by the PHP Group\n");
+ php_info_print("and included in the distribution in the file: LICENSE\n");
+ php_info_print("\n");
+ php_info_print("This program is distributed in the hope that it will be useful,\n");
+ php_info_print("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
+ php_info_print("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
+ php_info_print("\n");
+ php_info_print("If you did not receive a copy of the PHP license, or have any\n");
+ php_info_print("questions about PHP licensing, please contact license@php.net.\n");
}
}
if (!sapi_module.phpinfo_as_text) {
- PUTS("</div></body></html>");
+ php_info_print("</div></body></html>");
}
}
/* }}} */
-
-PHPAPI void php_info_print_table_start(void)
+PHPAPI void php_info_print_table_start(void) /* {{{ */
{
if (!sapi_module.phpinfo_as_text) {
- php_printf("<table border=\"0\" cellpadding=\"3\" width=\"600\">\n");
+ php_info_print("<table border=\"0\" cellpadding=\"3\" width=\"600\">\n");
} else {
- php_printf("\n");
+ php_info_print("\n");
}
}
+/* }}} */
-PHPAPI void php_info_print_table_end(void)
+PHPAPI void php_info_print_table_end(void) /* {{{ */
{
if (!sapi_module.phpinfo_as_text) {
- php_printf("</table><br />\n");
+ php_info_print("</table><br />\n");
}
}
+/* }}} */
-PHPAPI void php_info_print_box_start(int flag)
+PHPAPI void php_info_print_box_start(int flag) /* {{{ */
{
php_info_print_table_start();
if (flag) {
if (!sapi_module.phpinfo_as_text) {
- php_printf("<tr class=\"h\"><td>\n");
+ php_info_print("<tr class=\"h\"><td>\n");
}
} else {
if (!sapi_module.phpinfo_as_text) {
- php_printf("<tr class=\"v\"><td>\n");
+ php_info_print("<tr class=\"v\"><td>\n");
} else {
- php_printf("\n");
+ php_info_print("\n");
}
}
}
+/* }}} */
-PHPAPI void php_info_print_box_end(void)
+PHPAPI void php_info_print_box_end(void) /* {{{ */
{
if (!sapi_module.phpinfo_as_text) {
- php_printf("</td></tr>\n");
+ php_info_print("</td></tr>\n");
}
php_info_print_table_end();
}
+/* }}} */
-PHPAPI void php_info_print_hr(void)
+PHPAPI void php_info_print_hr(void) /* {{{ */
{
if (!sapi_module.phpinfo_as_text) {
- php_printf("<hr />\n");
+ php_info_print("<hr />\n");
} else {
- php_printf("\n\n _______________________________________________________________________\n\n");
+ php_info_print("\n\n _______________________________________________________________________\n\n");
}
}
+/* }}} */
-PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header)
+PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header) /* {{{ */
{
int spaces;
if (!sapi_module.phpinfo_as_text) {
- php_printf("<tr class=\"h\"><th colspan=\"%d\">%s</th></tr>\n", num_cols, header );
+ php_info_printf("<tr class=\"h\"><th colspan=\"%d\">%s</th></tr>\n", num_cols, header );
} else {
spaces = (74 - strlen(header));
- php_printf("%*s%s%*s\n", (int)(spaces/2), " ", header, (int)(spaces/2), " ");
+ php_info_printf("%*s%s%*s\n", (int)(spaces/2), " ", header, (int)(spaces/2), " ");
}
}
+/* }}} */
/* {{{ php_info_print_table_header
*/
@@ -1110,11 +1009,9 @@ PHPAPI void php_info_print_table_header(int num_cols, ...)
va_list row_elements;
char *row_element;
- TSRMLS_FETCH();
-
va_start(row_elements, num_cols);
if (!sapi_module.phpinfo_as_text) {
- php_printf("<tr class=\"h\">");
+ php_info_print("<tr class=\"h\">");
}
for (i=0; i<num_cols; i++) {
row_element = va_arg(row_elements, char *);
@@ -1122,21 +1019,21 @@ PHPAPI void php_info_print_table_header(int num_cols, ...)
row_element = " ";
}
if (!sapi_module.phpinfo_as_text) {
- PUTS("<th>");
- PUTS(row_element);
- PUTS("</th>");
+ php_info_print("<th>");
+ php_info_print(row_element);
+ php_info_print("</th>");
} else {
- PUTS(row_element);
+ php_info_print(row_element);
if (i < num_cols-1) {
- PUTS(" => ");
+ php_info_print(" => ");
} else {
- PUTS("\n");
- }
- }
+ php_info_print("\n");
+ }
+ }
}
if (!sapi_module.phpinfo_as_text) {
- php_printf("</tr>\n");
- }
+ php_info_print("</tr>\n");
+ }
va_end(row_elements);
}
@@ -1149,49 +1046,41 @@ static void php_info_print_table_row_internal(int num_cols,
{
int i;
char *row_element;
- char *elem_esc = NULL;
-/*
- int elem_esc_len;
-*/
-
- TSRMLS_FETCH();
if (!sapi_module.phpinfo_as_text) {
- php_printf("<tr>");
+ php_info_print("<tr>");
}
for (i=0; i<num_cols; i++) {
if (!sapi_module.phpinfo_as_text) {
- php_printf("<td class=\"%s\">",
+ php_info_printf("<td class=\"%s\">",
(i==0 ? "e" : value_class )
);
}
row_element = va_arg(row_elements, char *);
if (!row_element || !*row_element) {
if (!sapi_module.phpinfo_as_text) {
- PUTS( "<i>no value</i>" );
+ php_info_print( "<i>no value</i>" );
} else {
- PUTS( " " );
+ php_info_print( " " );
}
} else {
if (!sapi_module.phpinfo_as_text) {
- elem_esc = php_info_html_esc(row_element TSRMLS_CC);
- PUTS(elem_esc);
- efree(elem_esc);
+ php_info_print_html_esc(row_element, strlen(row_element));
} else {
- PUTS(row_element);
+ php_info_print(row_element);
if (i < num_cols-1) {
- PUTS(" => ");
+ php_info_print(" => ");
}
}
}
if (!sapi_module.phpinfo_as_text) {
- php_printf(" </td>");
+ php_info_print(" </td>");
} else if (i == (num_cols - 1)) {
- PUTS("\n");
+ php_info_print("\n");
}
}
if (!sapi_module.phpinfo_as_text) {
- php_printf("</tr>\n");
+ php_info_print("</tr>\n");
}
}
/* }}} */
@@ -1255,9 +1144,9 @@ PHP_FUNCTION(phpinfo)
}
/* Andale! Andale! Yee-Hah! */
- php_start_ob_buffer(NULL, 4096, 0 TSRMLS_CC);
+ php_output_start_default(TSRMLS_C);
php_print_info(flag TSRMLS_CC);
- php_end_ob_buffer(1, 0 TSRMLS_CC);
+ php_output_end(TSRMLS_C);
RETURN_TRUE;
}
@@ -1268,20 +1157,18 @@ PHP_FUNCTION(phpinfo)
Return the current PHP version */
PHP_FUNCTION(phpversion)
{
- zval **arg;
- const char *version;
- int argc = ZEND_NUM_ARGS();
+ char *ext_name = NULL;
+ int ext_name_len = 0;
- if (argc == 0) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &ext_name, &ext_name_len) == FAILURE) {
+ return;
+ }
+
+ if (!ext_name) {
RETURN_STRING(PHP_VERSION, 1);
} else {
- if (zend_parse_parameters(argc TSRMLS_CC, "Z", &arg) == FAILURE) {
- return;
- }
-
- convert_to_string_ex(arg);
- version = zend_get_module_version(Z_STRVAL_PP(arg));
-
+ const char *version;
+ version = zend_get_module_version(ext_name);
if (version == NULL) {
RETURN_FALSE;
}
@@ -1305,7 +1192,6 @@ PHP_FUNCTION(phpcredits)
}
/* }}} */
-
/* {{{ php_logo_guid
*/
PHPAPI char *php_logo_guid(void)
@@ -1333,7 +1219,6 @@ PHPAPI char *php_logo_guid(void)
Return the special ID used to request the PHP logo in phpinfo screens*/
PHP_FUNCTION(php_logo_guid)
{
-
if (zend_parse_parameters_none() == FAILURE) {
return;
}
@@ -1346,7 +1231,6 @@ PHP_FUNCTION(php_logo_guid)
Return the special ID used to request the PHP logo in phpinfo screens*/
PHP_FUNCTION(php_real_logo_guid)
{
-
if (zend_parse_parameters_none() == FAILURE) {
return;
}
@@ -1402,6 +1286,7 @@ PHP_FUNCTION(php_uname)
{
char *mode = "a";
int modelen = sizeof("a")-1;
+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &mode, &modelen) == FAILURE) {
return;
}
diff --git a/ext/standard/tests/general_functions/ob_get_flush_error.phpt b/ext/standard/tests/general_functions/ob_get_flush_error.phpt
index db666c5..1d35381 100644
--- a/ext/standard/tests/general_functions/ob_get_flush_error.phpt
+++ b/ext/standard/tests/general_functions/ob_get_flush_error.phpt
@@ -26,5 +26,7 @@ var_dump( ob_get_flush() );
Warning: ob_get_flush() expects exactly 0 parameters, 1 given in %s on line %d
NULL
+
+Notice: ob_get_flush(): failed to delete and flush buffer. No buffer to delete or flush in %s on line %d
bool(false)
===DONE===
diff --git a/ext/standard/url_scanner_ex.c b/ext/standard/url_scanner_ex.c
index 9057349..e589a6e 100644
--- a/ext/standard/url_scanner_ex.c
+++ b/ext/standard/url_scanner_ex.c
@@ -1,8 +1,8 @@
-/* Generated by re2c 0.13.5 on Mon Jul 27 02:20:40 2009 */
+/* Generated by re2c 0.13.5 on Mon May 31 11:07:50 2010 */
#line 1 "ext/standard/url_scanner_ex.re"
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 6 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2006 The PHP Group |
+----------------------------------------------------------------------+
@@ -993,7 +993,7 @@ static void php_url_scanner_output_handler(char *output, uint output_len, char *
size_t len;
if (BG(url_adapt_state_ex).url_app.len != 0) {
- *handled_output = url_adapt_ext(output, output_len, &len, (zend_bool) (mode & (PHP_OUTPUT_HANDLER_END | PHP_OUTPUT_HANDLER_CONT) ? 1 : 0) TSRMLS_CC);
+ *handled_output = url_adapt_ext(output, output_len, &len, (zend_bool) (mode & (PHP_OUTPUT_HANDLER_END | PHP_OUTPUT_HANDLER_CONT | PHP_OUTPUT_HANDLER_FLUSH | PHP_OUTPUT_HANDLER_FINAL) ? 1 : 0) TSRMLS_CC);
if (sizeof(uint) < sizeof(size_t)) {
if (len > UINT_MAX)
len = UINT_MAX;
@@ -1027,7 +1027,7 @@ PHPAPI int php_url_scanner_add_var(char *name, int name_len, char *value, int va
if (! BG(url_adapt_state_ex).active) {
php_url_scanner_ex_activate(TSRMLS_C);
- php_ob_set_internal_handler(php_url_scanner_output_handler, 0, "URL-Rewriter", 1 TSRMLS_CC);
+ php_output_start_internal(ZEND_STRL("URL-Rewriter"), php_url_scanner_output_handler, 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
BG(url_adapt_state_ex).active = 1;
}
diff --git a/ext/standard/url_scanner_ex.re b/ext/standard/url_scanner_ex.re
index 888bb06..44879da 100644
--- a/ext/standard/url_scanner_ex.re
+++ b/ext/standard/url_scanner_ex.re
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 6 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2006 The PHP Group |
+----------------------------------------------------------------------+
@@ -431,7 +431,7 @@ static void php_url_scanner_output_handler(char *output, uint output_len, char *
size_t len;
if (BG(url_adapt_state_ex).url_app.len != 0) {
- *handled_output = url_adapt_ext(output, output_len, &len, (zend_bool) (mode & (PHP_OUTPUT_HANDLER_END | PHP_OUTPUT_HANDLER_CONT) ? 1 : 0) TSRMLS_CC);
+ *handled_output = url_adapt_ext(output, output_len, &len, (zend_bool) (mode & (PHP_OUTPUT_HANDLER_END | PHP_OUTPUT_HANDLER_CONT | PHP_OUTPUT_HANDLER_FLUSH | PHP_OUTPUT_HANDLER_FINAL) ? 1 : 0) TSRMLS_CC);
if (sizeof(uint) < sizeof(size_t)) {
if (len > UINT_MAX)
len = UINT_MAX;
@@ -465,7 +465,7 @@ PHPAPI int php_url_scanner_add_var(char *name, int name_len, char *value, int va
if (! BG(url_adapt_state_ex).active) {
php_url_scanner_ex_activate(TSRMLS_C);
- php_ob_set_internal_handler(php_url_scanner_output_handler, 0, "URL-Rewriter", 1 TSRMLS_CC);
+ php_output_start_internal(ZEND_STRL("URL-Rewriter"), php_url_scanner_output_handler, 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
BG(url_adapt_state_ex).active = 1;
}
diff --git a/ext/standard/var.c b/ext/standard/var.c
index 6c5ae27..54bd1da 100644
--- a/ext/standard/var.c
+++ b/ext/standard/var.c
@@ -456,14 +456,14 @@ PHP_FUNCTION(var_export)
}
if (return_output) {
- php_start_ob_buffer (NULL, 0, 1 TSRMLS_CC);
+ php_output_start_default(TSRMLS_C);
}
php_var_export(&var, 1 TSRMLS_CC);
if (return_output) {
- php_ob_get_buffer (return_value TSRMLS_CC);
- php_end_ob_buffer (0, 0 TSRMLS_CC);
+ php_output_get_contents(return_value TSRMLS_CC);
+ php_output_discard(TSRMLS_C);
}
}
/* }}} */
diff --git a/ext/tidy/php_tidy.h b/ext/tidy/php_tidy.h
index 90a3e09..45d81ea 100644
--- a/ext/tidy/php_tidy.h
+++ b/ext/tidy/php_tidy.h
@@ -36,6 +36,7 @@ extern zend_module_entry tidy_module_entry;
ZEND_BEGIN_MODULE_GLOBALS(tidy)
char *default_config;
+ zend_bool clean_output;
ZEND_END_MODULE_GLOBALS(tidy)
#ifdef ZTS
diff --git a/ext/tidy/tidy.c b/ext/tidy/tidy.c
index cc66e97..6db96d9 100644
--- a/ext/tidy/tidy.c
+++ b/ext/tidy/tidy.c
@@ -42,6 +42,8 @@
/* {{{ ext/tidy macros
*/
+#define FIX_BUFFER(bptr) do { if ((bptr)->size) { (bptr)->bp[(bptr)->size-1] = '\0'; } } while(0)
+
#define TIDY_SET_CONTEXT \
zval *object = getThis();
@@ -186,16 +188,16 @@ typedef enum {
} tidy_base_nodetypes;
struct _PHPTidyDoc {
- TidyDoc doc;
- TidyBuffer *errbuf;
- unsigned int ref_count;
+ TidyDoc doc;
+ TidyBuffer *errbuf;
+ unsigned int ref_count;
};
struct _PHPTidyObj {
- zend_object std;
- TidyNode node;
- tidy_obj_type type;
- PHPTidyDoc *ptdoc;
+ zend_object std;
+ TidyNode node;
+ tidy_obj_type type;
+ PHPTidyDoc *ptdoc;
};
/* }}} */
@@ -216,6 +218,10 @@ static int _php_tidy_set_tidy_opt(TidyDoc, char *, zval * TSRMLS_DC);
static int _php_tidy_apply_config_array(TidyDoc doc, HashTable *ht_options TSRMLS_DC);
static void _php_tidy_register_nodetypes(INIT_FUNC_ARGS);
static void _php_tidy_register_tags(INIT_FUNC_ARGS);
+static PHP_INI_MH(php_tidy_set_clean_output);
+static void php_tidy_clean_output_start(const char *name, size_t name_len TSRMLS_DC);
+static php_output_handler *php_tidy_output_handler_init(const char *handler_name, size_t handler_name_len, size_t chunk_size, int flags TSRMLS_DC);
+static int php_tidy_output_handler(void **nothing, php_output_context *output_context);
static PHP_MINIT_FUNCTION(tidy);
static PHP_MSHUTDOWN_FUNCTION(tidy);
@@ -245,8 +251,6 @@ static PHP_FUNCTION(tidy_warning_count);
static PHP_FUNCTION(tidy_access_count);
static PHP_FUNCTION(tidy_config_count);
-static PHP_FUNCTION(ob_tidyhandler);
-
static PHP_FUNCTION(tidy_get_root);
static PHP_FUNCTION(tidy_get_html);
static PHP_FUNCTION(tidy_get_head);
@@ -271,8 +275,8 @@ static TIDY_NODE_METHOD(__construct);
ZEND_DECLARE_MODULE_GLOBALS(tidy)
PHP_INI_BEGIN()
-STD_PHP_INI_ENTRY("tidy.default_config", "", PHP_INI_SYSTEM, OnUpdateString, default_config, zend_tidy_globals, tidy_globals)
-PHP_INI_ENTRY("tidy.clean_output", "0", PHP_INI_PERDIR, NULL)
+STD_PHP_INI_ENTRY("tidy.default_config", "", PHP_INI_SYSTEM, OnUpdateString, default_config, zend_tidy_globals, tidy_globals)
+STD_PHP_INI_ENTRY("tidy.clean_output", "0", PHP_INI_USER, php_tidy_set_clean_output, clean_output, zend_tidy_globals, tidy_globals)
PHP_INI_END()
/* {{{ arginfo */
@@ -282,8 +286,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_parse_string, 0, 0, 1)
ZEND_ARG_INFO(0, encoding)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_get_error_buffer, 0, 0, 0)
- ZEND_ARG_INFO(0, detailed)
+ZEND_BEGIN_ARG_INFO(arginfo_tidy_get_error_buffer, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_tidy_get_output, 0)
@@ -368,11 +371,6 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_get_body, 0, 0, 1)
ZEND_ARG_INFO(0, tidy)
ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_ob_tidyhandler, 0, 0, 1)
- ZEND_ARG_INFO(0, input)
- ZEND_ARG_INFO(0, mode)
-ZEND_END_ARG_INFO()
/* }}} */
static const zend_function_entry tidy_functions[] = {
@@ -402,7 +400,6 @@ static const zend_function_entry tidy_functions[] = {
PHP_FE(tidy_get_head, arginfo_tidy_get_head)
PHP_FE(tidy_get_html, arginfo_tidy_get_html)
PHP_FE(tidy_get_body, arginfo_tidy_get_body)
- PHP_FE(ob_tidyhandler, arginfo_ob_tidyhandler)
{NULL, NULL, NULL}
};
@@ -605,7 +602,7 @@ static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_fil
TidyBuffer buf;
tidyBufInit(&buf);
- tidyBufAppend(&buf, data, data_len);
+ tidyBufAttach(&buf, (byte *) data, data_len);
if (tidyParseBuffer(doc, &buf) < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", errbuf->bp);
@@ -616,20 +613,19 @@ static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_fil
tidyBufInit(&output);
tidySaveBuffer (doc, &output);
- RETVAL_STRINGL((char*)output.bp, output.size ? output.size-1 : 0, 1);
+ FIX_BUFFER(&output);
+ RETVAL_STRINGL((char *) output.bp, output.size ? output.size-1 : 0, 1);
tidyBufFree(&output);
} else {
RETVAL_FALSE;
}
}
-
- tidyBufFree(&buf);
}
if (is_file) {
efree(data);
}
-
+
tidyBufFree(errbuf);
efree(errbuf);
tidyRelease(doc);
@@ -643,7 +639,7 @@ static char *php_tidy_file_to_mem(char *filename, zend_bool use_include_path, in
if (!(stream = php_stream_open_wrapper(filename, "rb", (use_include_path ? USE_PATH : 0), NULL))) {
return NULL;
}
- if ((*len = (int) php_stream_copy_to_mem(stream, &data, PHP_STREAM_COPY_ALL, 0)) == 0) {
+ if ((*len = (int) php_stream_copy_to_mem(stream, (void*) &data, PHP_STREAM_COPY_ALL, 0)) == 0) {
data = estrdup("");
*len = 0;
}
@@ -687,11 +683,6 @@ static void tidy_object_new(zend_class_entry *class_type, zend_object_handlers *
break;
case is_doc:
- tidySetMallocCall(php_tidy_malloc);
- tidySetReallocCall(php_tidy_realloc);
- tidySetFreeCall(php_tidy_free);
- tidySetPanicCall(php_tidy_panic);
-
intern->ptdoc = emalloc(sizeof(PHPTidyDoc));
intern->ptdoc->doc = tidyCreate();
intern->ptdoc->ref_count = 1;
@@ -714,9 +705,6 @@ static void tidy_object_new(zend_class_entry *class_type, zend_object_handlers *
tidy_add_default_properties(intern, is_doc TSRMLS_CC);
break;
-
- default:
- break;
}
retval->handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) tidy_object_free_storage, NULL TSRMLS_CC);
@@ -772,7 +760,7 @@ static int tidy_doc_cast_handler(zval *in, zval *out, int type TSRMLS_DC)
obj = (PHPTidyObj *)zend_object_store_get_object(in TSRMLS_CC);
tidyBufInit(&output);
tidySaveBuffer (obj->ptdoc->doc, &output);
- ZVAL_STRINGL(out, (char*)output.bp, output.size ? output.size-1 : 0, TRUE);
+ ZVAL_STRINGL(out, (char *) output.bp, output.size ? output.size-1 : 0, 1);
tidyBufFree(&output);
break;
@@ -806,8 +794,10 @@ static int tidy_node_cast_handler(zval *in, zval *out, int type TSRMLS_DC)
tidyBufInit(&buf);
if (obj->ptdoc) {
tidyNodeGetText(obj->ptdoc->doc, obj->node, &buf);
+ ZVAL_STRINGL(out, (char *) buf.bp, buf.size-1, 1);
+ } else {
+ ZVAL_EMPTY_STRING(out);
}
- ZVAL_STRINGL(out, (char*)buf.bp, buf.size ? buf.size-1 : 0, TRUE);
tidyBufFree(&buf);
break;
@@ -865,7 +855,7 @@ static void tidy_add_default_properties(PHPTidyObj *obj, tidy_obj_type type TSRM
}
tidyBufInit(&buf);
tidyNodeGetText(obj->ptdoc->doc, obj->node, &buf);
- ADD_PROPERTY_STRINGL(obj->std.properties, value, buf.bp, buf.size-1);
+ ADD_PROPERTY_STRINGL(obj->std.properties, value, buf.bp, buf.size ? buf.size-1 : 0);
tidyBufFree(&buf);
ADD_PROPERTY_STRING(obj->std.properties, name, tidyNodeGetName(obj->node));
@@ -1009,24 +999,33 @@ static void php_tidy_create_node(INTERNAL_FUNCTION_PARAMETERS, tidy_base_nodetyp
static int _php_tidy_apply_config_array(TidyDoc doc, HashTable *ht_options TSRMLS_DC)
{
- char *opt_name = NULL;
+ char *opt_name;
zval **opt_val;
ulong opt_indx;
-
+ uint opt_name_len;
+ zend_bool clear_str;
+
for (zend_hash_internal_pointer_reset(ht_options);
- zend_hash_get_current_data(ht_options, (void **)&opt_val) == SUCCESS;
+ zend_hash_get_current_data(ht_options, (void *) &opt_val) == SUCCESS;
zend_hash_move_forward(ht_options)) {
-
- if(zend_hash_get_current_key(ht_options, &opt_name, &opt_indx, FALSE) == FAILURE) {
+
+ switch (zend_hash_get_current_key_ex(ht_options, &opt_name, &opt_name_len, &opt_indx, FALSE, NULL)) {
+ case HASH_KEY_IS_STRING:
+ clear_str = 0;
+ break;
+
+ case HASH_KEY_IS_LONG:
+ continue; /* ignore numeric keys */
+
+ default:
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not retrieve key from option array");
return FAILURE;
}
- if(opt_name) {
- _php_tidy_set_tidy_opt(doc, opt_name, *opt_val TSRMLS_CC);
- opt_name = NULL;
+ _php_tidy_set_tidy_opt(doc, opt_name, *opt_val TSRMLS_CC);
+ if (clear_str) {
+ efree(opt_name);
}
-
}
return SUCCESS;
@@ -1035,7 +1034,7 @@ static int _php_tidy_apply_config_array(TidyDoc doc, HashTable *ht_options TSRML
static int php_tidy_parse_string(PHPTidyObj *obj, char *string, int len, char *enc TSRMLS_DC)
{
TidyBuffer buf;
-
+
if(enc) {
if (tidySetCharEncoding(obj->ptdoc->doc, enc) < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not set encoding '%s'", enc);
@@ -1044,14 +1043,11 @@ static int php_tidy_parse_string(PHPTidyObj *obj, char *string, int len, char *e
}
tidyBufInit(&buf);
- tidyBufAppend(&buf, string, len);
+ tidyBufAttach(&buf, (byte *) string, len);
if (tidyParseBuffer(obj->ptdoc->doc, &buf) < 0) {
- tidyBufFree(&buf);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", obj->ptdoc->errbuf->bp);
return FAILURE;
-
}
- tidyBufFree(&buf);
tidy_doc_update_properties(obj TSRMLS_CC);
return SUCCESS;
@@ -1059,6 +1055,11 @@ static int php_tidy_parse_string(PHPTidyObj *obj, char *string, int len, char *e
static PHP_MINIT_FUNCTION(tidy)
{
+ tidySetMallocCall(php_tidy_malloc);
+ tidySetReallocCall(php_tidy_realloc);
+ tidySetFreeCall(php_tidy_free);
+ tidySetPanicCall(php_tidy_panic);
+
REGISTER_INI_ENTRIES();
REGISTER_TIDY_CLASS(tidy, doc, NULL, 0);
REGISTER_TIDY_CLASS(tidyNode, node, NULL, ZEND_ACC_FINAL_CLASS);
@@ -1069,16 +1070,14 @@ static PHP_MINIT_FUNCTION(tidy)
_php_tidy_register_tags(INIT_FUNC_ARGS_PASSTHRU);
_php_tidy_register_nodetypes(INIT_FUNC_ARGS_PASSTHRU);
+ php_output_handler_alias_register(ZEND_STRL("ob_tidyhandler"), php_tidy_output_handler_init TSRMLS_CC);
+
return SUCCESS;
}
static PHP_RINIT_FUNCTION(tidy)
{
- if (INI_BOOL("tidy.clean_output") == TRUE) {
- if (php_start_ob_buffer_named("ob_tidyhandler", 0, 1 TSRMLS_CC) == FAILURE) {
- zend_error(E_NOTICE, "Failure installing Tidy output buffering.");
- }
- }
+ php_tidy_clean_output_start(ZEND_STRL("ob_tidyhandler") TSRMLS_CC);
return SUCCESS;
}
@@ -1100,59 +1099,106 @@ static PHP_MINFO_FUNCTION(tidy)
DISPLAY_INI_ENTRIES();
}
-static PHP_FUNCTION(ob_tidyhandler)
+static PHP_INI_MH(php_tidy_set_clean_output)
{
- char *input;
- int input_len;
- long mode;
- TidyBuffer errbuf;
- TidyDoc doc;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &input, &input_len, &mode) == FAILURE) {
- return;
+ int status;
+ zend_bool value;
+
+ if (new_value_length==2 && strcasecmp("on", new_value)==0) {
+ value = (zend_bool) 1;
+ } else if (new_value_length==3 && strcasecmp("yes", new_value)==0) {
+ value = (zend_bool) 1;
+ } else if (new_value_length==4 && strcasecmp("true", new_value)==0) {
+ value = (zend_bool) 1;
+ } else {
+ value = (zend_bool) atoi(new_value);
}
- doc = tidyCreate();
- tidyBufInit(&errbuf);
+ if (stage == PHP_INI_STAGE_RUNTIME) {
+ status = php_output_get_status(TSRMLS_C);
- tidyOptSetBool(doc, TidyForceOutput, yes);
- tidyOptSetBool(doc, TidyMark, no);
+ if (value && (status & PHP_OUTPUT_WRITTEN)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot enable tidy.clean_output - there has already been output");
+ return FAILURE;
+ }
+ if (status & PHP_OUTPUT_SENT) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot change tidy.clean_output - headers already sent");
+ return FAILURE;
+ }
+ }
- if (tidySetErrorBuffer(doc, &errbuf) != 0) {
- tidyRelease(doc);
- tidyBufFree(&errbuf);
+ status = OnUpdateBool(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not set Tidy error buffer");
+ if (stage == PHP_INI_STAGE_RUNTIME && value) {
+ if (!php_output_handler_started(ZEND_STRL("ob_tidyhandler") TSRMLS_CC)) {
+ php_tidy_clean_output_start(ZEND_STRL("ob_tidyhandler") TSRMLS_CC);
+ }
}
- TIDY_SET_DEFAULT_CONFIG(doc);
+ return status;
+}
- if (input_len > 1) {
- TidyBuffer buf;
-
- tidyBufInit(&buf);
- tidyBufAppend(&buf, input, input_len);
-
- if (tidyParseBuffer(doc, &buf) < 0 || tidyCleanAndRepair(doc) < 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", errbuf.bp);
- RETVAL_NULL();
- } else {
- TidyBuffer output;
- tidyBufInit(&output);
+/*
+ * NOTE: tidy does not support iterative/cumulative parsing, so chunk-sized output handler is not possible
+ */
+
+static void php_tidy_clean_output_start(const char *name, size_t name_len TSRMLS_DC)
+{
+ php_output_handler *h;
- tidySaveBuffer(doc, &output);
- RETVAL_STRINGL((char*)output.bp, output.size ? output.size-1 : 0, 1);
+ if (TG(clean_output) && (h = php_tidy_output_handler_init(name, name_len, 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC))) {
+ php_output_handler_start(h TSRMLS_CC);
+ }
+}
- tidyBufFree(&output);
+static php_output_handler *php_tidy_output_handler_init(const char *handler_name, size_t handler_name_len, size_t chunk_size, int flags TSRMLS_DC)
+{
+ if (chunk_size) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot use a chunk size for ob_tidyhandler");
+ return NULL;
+ }
+ if (!TG(clean_output)) {
+ TG(clean_output) = 1;
+ }
+ return php_output_handler_create_internal(handler_name, handler_name_len, php_tidy_output_handler, chunk_size, flags TSRMLS_CC);
+}
+
+static int php_tidy_output_handler(void **nothing, php_output_context *output_context)
+{
+ int status = FAILURE;
+ TidyDoc doc;
+ TidyBuffer inbuf, outbuf, errbuf;
+ PHP_OUTPUT_TSRMLS(output_context);
+
+ if (TG(clean_output) && (output_context->op & PHP_OUTPUT_HANDLER_START) && (output_context->op & PHP_OUTPUT_HANDLER_FINAL)) {
+ doc = tidyCreate();
+ tidyBufInit(&errbuf);
+
+ if (0 == tidySetErrorBuffer(doc, &errbuf)) {
+ tidyOptSetBool(doc, TidyForceOutput, yes);
+ tidyOptSetBool(doc, TidyMark, no);
+
+ TIDY_SET_DEFAULT_CONFIG(doc);
+
+ tidyBufInit(&inbuf);
+ tidyBufAttach(&inbuf, (byte *) output_context->in.data, output_context->in.used);
+
+ if (0 <= tidyParseBuffer(doc, &inbuf) && 0 <= tidyCleanAndRepair(doc)) {
+ tidyBufInit(&outbuf);
+ tidySaveBuffer(doc, &outbuf);
+ FIX_BUFFER(&outbuf);
+ output_context->out.data = (char *) outbuf.bp;
+ output_context->out.used = outbuf.size ? outbuf.size-1 : 0;
+ output_context->out.free = 1;
+ status = SUCCESS;
+ }
}
-
- tidyBufFree(&buf);
- } else {
- RETVAL_NULL();
+
+ tidyRelease(doc);
+ tidyBufFree(&errbuf);
}
- tidyRelease(doc);
- tidyBufFree(&errbuf);
+ return status;
}
/* {{{ proto bool tidy_parse_string(string input [, mixed config_options [, string encoding]])
@@ -1162,7 +1208,6 @@ static PHP_FUNCTION(tidy_parse_string)
char *input, *enc = NULL;
int input_len, enc_len = 0;
zval **options = NULL;
-
PHPTidyObj *obj;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|Zs", &input, &input_len, &options, &enc, &enc_len) == FAILURE) {
@@ -1179,11 +1224,10 @@ static PHP_FUNCTION(tidy_parse_string)
INIT_ZVAL(*return_value);
RETURN_FALSE;
}
-
}
/* }}} */
-/* {{{ proto string tidy_get_error_buffer([boolean detailed])
+/* {{{ proto string tidy_get_error_buffer()
Return warnings and errors which occured parsing the specified document*/
static PHP_FUNCTION(tidy_get_error_buffer)
{
@@ -1206,9 +1250,8 @@ static PHP_FUNCTION(tidy_get_output)
tidyBufInit(&output);
tidySaveBuffer(obj->ptdoc->doc, &output);
-
- RETVAL_STRINGL((char*)output.bp, output.size ? output.size-1 : 0, 1);
-
+ FIX_BUFFER(&output);
+ RETVAL_STRINGL((char *) output.bp, output.size ? output.size-1 : 0, 1);
tidyBufFree(&output);
}
/* }}} */
@@ -1234,7 +1277,7 @@ static PHP_FUNCTION(tidy_parse_file)
obj = (PHPTidyObj *) zend_object_store_get_object(return_value TSRMLS_CC);
if (!(contents = php_tidy_file_to_mem(inputfile, use_include_path, &contents_len TSRMLS_CC))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Load '%s' into memory %s", inputfile, (use_include_path) ? "(Using include path)" : "");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Load '%s' into memory%s", inputfile, (use_include_path) ? " (Using include path)" : "");
RETURN_FALSE;
}
@@ -1315,7 +1358,7 @@ static PHP_FUNCTION(tidy_get_release)
static PHP_FUNCTION(tidy_get_opt_doc)
{
PHPTidyObj *obj;
- char *optname, *optval;
+ char *optval, *optname;
int optname_len;
TidyOption opt;
@@ -1351,7 +1394,7 @@ static PHP_FUNCTION(tidy_get_opt_doc)
/* {{{ proto array tidy_get_config()
- Get current Tidy configuarion */
+ Get current Tidy configuration */
static PHP_FUNCTION(tidy_get_config)
{
TidyIterator itOpt;
@@ -1548,7 +1591,7 @@ static TIDY_DOC_METHOD(__construct)
if (inputfile) {
if (!(contents = php_tidy_file_to_mem(inputfile, use_include_path, &contents_len TSRMLS_CC))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Load '%s' into memory %s", inputfile, (use_include_path) ? "(Using include path)" : "");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Load '%s' into memory%s", inputfile, (use_include_path) ? " (Using include path)" : "");
return;
}
@@ -1579,7 +1622,7 @@ static TIDY_DOC_METHOD(parseFile)
}
if (!(contents = php_tidy_file_to_mem(inputfile, use_include_path, &contents_len TSRMLS_CC))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Load '%s' into memory %s", inputfile, (use_include_path) ? "(Using include path)" : "");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Load '%s' into memory%s", inputfile, (use_include_path) ? " (Using include path)" : "");
RETURN_FALSE;
}
@@ -1786,6 +1829,7 @@ static TIDY_NODE_METHOD(getParent)
}
/* }}} */
+
/* {{{ proto void tidyNode::__construct()
__constructor for tidyNode. */
static TIDY_NODE_METHOD(__construct)
diff --git a/ext/zlib/CREDITS b/ext/zlib/CREDITS
index c0a47dd..a1773c4 100644
--- a/ext/zlib/CREDITS
+++ b/ext/zlib/CREDITS
@@ -1,2 +1,2 @@
Zlib
-Rasmus Lerdorf, Stefan Roehrich, Zeev Suraski, Jade Nicoletti
+Rasmus Lerdorf, Stefan Roehrich, Zeev Suraski, Jade Nicoletti, Michael Wallner
diff --git a/ext/zlib/config0.m4 b/ext/zlib/config0.m4
index 62e05fb..25c7f4f 100644
--- a/ext/zlib/config0.m4
+++ b/ext/zlib/config0.m4
@@ -41,10 +41,17 @@ if test "$PHP_ZLIB" != "no" || test "$PHP_ZLIB_DIR" != "no"; then
*) ac_extra=-L$ZLIB_DIR/$PHP_LIBDIR ;;
esac
+ AC_MSG_CHECKING([for zlib version >= 1.2.0.4])
+ ZLIB_VERSION=`$EGREP "define ZLIB_VERSION" $ZLIB_DIR/include/zlib.h | $SED -e 's/[[^0-9\.]]//g'`
+ AC_MSG_RESULT([$ZLIB_VERSION])
+ if test `echo $ZLIB_VERSION | $SED -e 's/[[^0-9]]/ /g' | $AWK '{print $1*1000000 + $2*10000 + $3*100 + $4}'` -lt 1020004; then
+ AC_MSG_ERROR([libz version greater or equal to 1.2.0.4 required])
+ fi
+
PHP_CHECK_LIBRARY(z, gzgets, [
AC_DEFINE(HAVE_ZLIB,1,[ ])
],[
- AC_MSG_ERROR(ZLIB extension requires zlib >= 1.0.9)
+ AC_MSG_ERROR(ZLIB extension requires gzgets in zlib)
],[
$ac_extra
])
diff --git a/ext/zlib/php_zlib.h b/ext/zlib/php_zlib.h
index 790c695..564c9e1 100644
--- a/ext/zlib/php_zlib.h
+++ b/ext/zlib/php_zlib.h
@@ -14,6 +14,7 @@
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
| Stefan Röhrich <sr@linux.de> |
+ | Michael Wallner <mike@php.net> |
+----------------------------------------------------------------------+
*/
@@ -24,39 +25,50 @@
#include <zlib.h>
+#define PHP_ZLIB_ENCODING_RAW -0xf
+#define PHP_ZLIB_ENCODING_GZIP 0x1f
+#define PHP_ZLIB_ENCODING_DEFLATE 0x0f
+
+#define PHP_ZLIB_ENCODING_ANY 0x2f
+
+#define PHP_ZLIB_OUTPUT_HANDLER_NAME "zlib output compression"
+#define PHP_ZLIB_BUFFER_SIZE_GUESS(in_len) (((size_t) ((double) in_len * (double) 1.015)) + 10 + 8 + 4 + 1)
+
ZEND_BEGIN_MODULE_GLOBALS(zlib)
/* variables for transparent gzip encoding */
int compression_coding;
- z_stream stream;
- uLong crc;
- int ob_gzhandler_status;
long output_compression;
long output_compression_level;
char *output_handler;
-ZEND_END_MODULE_GLOBALS(zlib)
-
-PHPAPI ZEND_EXTERN_MODULE_GLOBALS(zlib)
+ZEND_END_MODULE_GLOBALS(zlib);
-extern php_stream_filter_factory php_zlib_filter_factory;
-extern zend_module_entry php_zlib_module_entry;
-#define zlib_module_ptr &php_zlib_module_entry
+typedef struct _php_zlib_buffer {
+ char *data;
+ char *aptr;
+ size_t used;
+ size_t free;
+ size_t size;
+} php_zlib_buffer;
-int php_ob_gzhandler_check(TSRMLS_D);
+typedef struct _php_zlib_context {
+ z_stream Z;
+ php_zlib_buffer buffer;
+} php_zlib_context;
php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
+extern php_stream_ops php_stream_gzio_ops;
extern php_stream_wrapper php_stream_gzip_wrapper;
+extern php_stream_filter_factory php_zlib_filter_factory;
+extern zend_module_entry php_zlib_module_entry;
+#define zlib_module_ptr &php_zlib_module_entry
+#define phpext_zlib_ptr zlib_module_ptr
#ifdef ZTS
-#define ZLIBG(v) TSRMG(zlib_globals_id, zend_zlib_globals *, v)
+# define ZLIBG(v) TSRMG(zlib_globals_id, zend_zlib_globals *, v)
#else
-#define ZLIBG(v) (zlib_globals.v)
+# define ZLIBG(v) (zlib_globals.v)
#endif
-#define phpext_zlib_ptr zlib_module_ptr
-
-#define CODING_GZIP 1
-#define CODING_DEFLATE 2
-
#endif /* PHP_ZLIB_H */
/*
diff --git a/ext/zlib/tests/006.phpt b/ext/zlib/tests/006.phpt
index 6a4e0f4..8c03ea0 100644
--- a/ext/zlib/tests/006.phpt
+++ b/ext/zlib/tests/006.phpt
@@ -48,6 +48,8 @@ string(%d) "%a"
Warning: gzinflate() expects at least 1 parameter, 0 given in %s on line %d
NULL
+
+Warning: gzinflate(): data error in %s on line %d
bool(false)
Warning: gzinflate(): data error in %s on line %d
diff --git a/ext/zlib/tests/007.phpt b/ext/zlib/tests/007.phpt
index ec37b99..09207a5 100644
--- a/ext/zlib/tests/007.phpt
+++ b/ext/zlib/tests/007.phpt
@@ -11,8 +11,8 @@ var_dump(gzencode("", -10));
var_dump(gzencode("", 100));
var_dump(gzencode("", 1, 100));
-var_dump(gzencode("", -1, 1));
-var_dump(gzencode("", 9, 2));
+var_dump(gzencode("", -1, ZLIB_ENCODING_GZIP));
+var_dump(gzencode("", 9, ZLIB_ENCODING_DEFLATE));
$string = "Light of my sun
Light in this temple
@@ -21,8 +21,8 @@ Lies in the darkness";
var_dump(gzencode($string, 9, 3));
-var_dump(gzencode($string, -1, 1));
-var_dump(gzencode($string, 9, 2));
+var_dump(gzencode($string, -1, ZLIB_ENCODING_GZIP));
+var_dump(gzencode($string, 9, ZLIB_ENCODING_DEFLATE));
echo "Done\n";
?>
@@ -33,18 +33,18 @@ NULL
Warning: gzencode() expects at most 3 parameters, 4 given in %s on line %d
NULL
-Warning: gzencode(): compression level(-10) must be within -1..9 in %s on line %d
+Warning: gzencode(): compression level (-10) must be within -1..9 in %s on line %d
bool(false)
-Warning: gzencode(): compression level(100) must be within -1..9 in %s on line %d
+Warning: gzencode(): compression level (100) must be within -1..9 in %s on line %d
bool(false)
-Warning: gzencode(): encoding mode must be FORCE_GZIP or FORCE_DEFLATE in %s on line %d
+Warning: gzencode(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d
bool(false)
string(%d) "%s"
string(%d) "%s"
-Warning: gzencode(): encoding mode must be FORCE_GZIP or FORCE_DEFLATE in %s on line %d
+Warning: gzencode(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d
bool(false)
string(%d) "%s"
string(%d) "%s"
diff --git a/ext/zlib/tests/gzcompress_basic1.phpt b/ext/zlib/tests/gzcompress_basic1.phpt
index dddeb1d..1506d0c 100644
--- a/ext/zlib/tests/gzcompress_basic1.phpt
+++ b/ext/zlib/tests/gzcompress_basic1.phpt
@@ -8,7 +8,7 @@ if (!extension_loaded("zlib")) {
?>
--FILE--
<?php
-/* Prototype : string gzcompress(string data [, int level])
+/* Prototype : string gzcompress(string data [, int level, [int encoding]])
* Description: Gzip-compress a string
* Source code: ext/zlib/zlib.c
* Alias to functions:
@@ -63,7 +63,7 @@ int(0)
string(32) "c2e070f4320d1f674965eaab95b53d9c"
int(0)
-- Compression level 2 --
-string(32) "400a53d19ca337727f8cd362f5cd3ee0"
+string(32) "36922f486410d08209d0d0d21b26030e"
int(0)
-- Compression level 3 --
string(32) "a441a2f5169bb303cd45b860a5a9dbf9"
@@ -122,4 +122,4 @@ int(0)
-- Testing with no specified compression level --
string(70) "789c735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee6020087a509cb"
-===Done=== \ No newline at end of file
+===Done===
diff --git a/ext/zlib/tests/gzcompress_error1.phpt b/ext/zlib/tests/gzcompress_error1.phpt
index 7fa60b9..9db0a56 100644
--- a/ext/zlib/tests/gzcompress_error1.phpt
+++ b/ext/zlib/tests/gzcompress_error1.phpt
@@ -8,7 +8,7 @@ if (!extension_loaded("zlib")) {
?>
--FILE--
<?php
-/* Prototype : string gzcompress(string data [, int level])
+/* Prototype : string gzcompress(string data [, int level, [int encoding]])
* Description: Gzip-compress a string
* Source code: ext/zlib/zlib.c
* Alias to functions:
@@ -28,26 +28,30 @@ var_dump( gzcompress() );
echo "\n-- Testing gzcompress() function with more than expected no. of arguments --\n";
$data = 'string_val';
$level = 2;
+$encoding = ZLIB_ENCODING_RAW;
$extra_arg = 10;
-var_dump( gzcompress($data, $level, $extra_arg) );
+var_dump( gzcompress($data, $level, $encoding, $extra_arg) );
echo "\n-- Testing with incorrect compression level --\n";
$bad_level = 99;
var_dump(gzcompress($data, $bad_level));
+echo "\n-- Testing with invalid encoding --\n";
+$data = 'string_val';
+$encoding = 99;
+var_dump(gzcompress($data, $level, $encoding));
+
+echo "\n-- Testing with incorrect parameters --\n";
+
class Tester {
function Hello() {
echo "Hello\n";
}
}
-echo "\n-- Testing with incorrect parameters --\n";
$testclass = new Tester();
var_dump(gzcompress($testclass));
-var_dump(gzcompress($data, $testclass));
-
-
?>
===Done===
--EXPECTF--
@@ -60,7 +64,7 @@ NULL
-- Testing gzcompress() function with more than expected no. of arguments --
-Warning: gzcompress() expects at most 2 parameters, 3 given in %s on line %d
+Warning: gzcompress() expects at most 3 parameters, 4 given in %s on line %d
NULL
-- Testing with incorrect compression level --
@@ -68,11 +72,13 @@ NULL
Warning: gzcompress(): compression level (99) must be within -1..9 in %s on line %d
bool(false)
+-- Testing with invalid encoding --
+
+Warning: gzcompress(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d
+bool(false)
+
-- Testing with incorrect parameters --
Warning: gzcompress() expects parameter 1 to be string, object given in %s on line %d
NULL
-
-Warning: gzcompress() expects parameter 2 to be long, object given in %s on line %d
-NULL
-===Done=== \ No newline at end of file
+===Done===
diff --git a/ext/zlib/tests/gzcompress_variation1.phpt b/ext/zlib/tests/gzcompress_variation1.phpt
index 04aac01..7a8457c 100644
--- a/ext/zlib/tests/gzcompress_variation1.phpt
+++ b/ext/zlib/tests/gzcompress_variation1.phpt
@@ -8,7 +8,7 @@ if (!extension_loaded("zlib")) {
?>
--FILE--
<?php
-/* Prototype : string gzcompress(string data [, int level])
+/* Prototype : string gzcompress(string data [, int level, [int encoding]])
* Description: Gzip-compress a string
* Source code: ext/zlib/zlib.c
* Alias to functions:
@@ -18,8 +18,6 @@ include(dirname(__FILE__) . '/data.inc');
echo "*** Testing gzcompress() : variation ***\n";
-
-
echo "\n-- Testing multiple compression --\n";
$output = gzcompress($data);
var_dump( md5($output));
@@ -33,4 +31,4 @@ var_dump(md5(gzcompress($output)));
-- Testing multiple compression --
string(32) "764809aef15bb34cb73ad49ecb600d99"
string(32) "eba942bc2061f23ea8688cc5101872a4"
-===Done=== \ No newline at end of file
+===Done===
diff --git a/ext/zlib/tests/gzdeflate_basic1.phpt b/ext/zlib/tests/gzdeflate_basic1.phpt
index 823f320..a2ae0f0 100644
--- a/ext/zlib/tests/gzdeflate_basic1.phpt
+++ b/ext/zlib/tests/gzdeflate_basic1.phpt
@@ -8,7 +8,7 @@ if (!extension_loaded("zlib")) {
?>
--FILE--
<?php
-/* Prototype : proto string gzdeflate(string data [, int level])
+/* Prototype : string gzdeflate(string data [, int level, [int encoding]])
* Description: Gzip-compress a string
* Source code: ext/zlib/zlib.c
* Alias to functions:
diff --git a/ext/zlib/tests/gzdeflate_error1.phpt b/ext/zlib/tests/gzdeflate_error1.phpt
index 78491af..8abd5be 100644
--- a/ext/zlib/tests/gzdeflate_error1.phpt
+++ b/ext/zlib/tests/gzdeflate_error1.phpt
@@ -8,7 +8,7 @@ if (!extension_loaded("zlib")) {
?>
--FILE--
<?php
-/* Prototype : string gzdeflate(string data [, int level])
+/* Prototype : string gzdeflate(string data [, int level, [int encoding]])
* Description: Gzip-compress a string
* Source code: ext/zlib/zlib.c
* Alias to functions:
@@ -28,13 +28,18 @@ var_dump( gzdeflate() );
echo "\n-- Testing gzdeflate() function with more than expected no. of arguments --\n";
$data = 'string_val';
$level = 2;
+$encoding = ZLIB_ENCODING_RAW;
$extra_arg = 10;
-var_dump( gzdeflate($data, $level, $extra_arg) );
+var_dump( gzdeflate($data, $level, $encoding, $extra_arg) );
echo "\n-- Testing with incorrect compression level --\n";
$bad_level = 99;
var_dump(gzdeflate($data, $bad_level));
+echo "\n-- Testing with incorrect encoding --\n";
+$bad_encoding = 99;
+var_dump(gzdeflate($data, $level, $bad_encoding));
+
class Tester {
function Hello() {
echo "Hello\n";
@@ -58,7 +63,7 @@ NULL
-- Testing gzdeflate() function with more than expected no. of arguments --
-Warning: gzdeflate() expects at most 2 parameters, 3 given in %s on line %d
+Warning: gzdeflate() expects at most 3 parameters, 4 given in %s on line %d
NULL
-- Testing with incorrect compression level --
@@ -66,6 +71,11 @@ NULL
Warning: gzdeflate(): compression level (99) must be within -1..9 in %s on line %d
bool(false)
+-- Testing with incorrect encoding --
+
+Warning: gzdeflate(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d
+bool(false)
+
-- Testing with incorrect parameters --
Warning: gzdeflate() expects parameter 1 to be string, object given in %s on line %d
@@ -73,4 +83,4 @@ NULL
Warning: gzdeflate() expects parameter 2 to be long, object given in %s on line %d
NULL
-===Done=== \ No newline at end of file
+===Done===
diff --git a/ext/zlib/tests/gzencode_basic1.phpt b/ext/zlib/tests/gzencode_basic1.phpt
index 9b3dcc8..3c0ec55 100644
--- a/ext/zlib/tests/gzencode_basic1.phpt
+++ b/ext/zlib/tests/gzencode_basic1.phpt
@@ -51,6 +51,13 @@ for($i = -1; $i < 10; $i++) {
var_dump(md5($output));
}
+// Calling gzencode() with mandatory arguments
+echo "\n-- Testing with no specified compression level --\n";
+var_dump(bin2hex(gzencode($smallstring)));
+
+echo "\n-- Testing gzencode with mode specified --\n";
+var_dump(bin2hex(gzencode($smallstring, -1, FORCE_GZIP)));
+
?>
===Done===
--EXPECTF--
@@ -58,9 +65,9 @@ for($i = -1; $i < 10; $i++) {
-- Compression level -1 --
string(32) "d9ede02415ce91d21e5a94274e2b9c42"
-- Compression level 0 --
-string(32) "67aaf60426bb2cbd86d7fe530cb12306"
+string(32) "bbf32d5508e5f1f4e6d42790489dae15"
-- Compression level 1 --
-string(32) "bce9c439cf767c1988ff4881b287d1ce"
+string(32) "0bfaaa7a5a57f8fb533074fca6c85eeb"
-- Compression level 2 --
string(32) "7ddbfed63a76c42808722b66f1c133fc"
-- Compression level 3 --
@@ -76,13 +83,13 @@ string(32) "d9ede02415ce91d21e5a94274e2b9c42"
-- Compression level 8 --
string(32) "d9ede02415ce91d21e5a94274e2b9c42"
-- Compression level 9 --
-string(32) "d9ede02415ce91d21e5a94274e2b9c42"
+string(32) "0f220a09e9895bcb3a1308d2bc99cfdf"
-- Compression level -1 --
string(32) "f77bd31e1e4dd11d12828fb661a08010"
-- Compression level 0 --
-string(32) "36220d650930849b67e8e0622f9bf270"
+string(32) "9c5005db88490d6fe102ea2c233b2872"
-- Compression level 1 --
-string(32) "f77bd31e1e4dd11d12828fb661a08010"
+string(32) "d24ff7c4c20cef69b9c3abd603368db9"
-- Compression level 2 --
string(32) "f77bd31e1e4dd11d12828fb661a08010"
-- Compression level 3 --
@@ -98,5 +105,11 @@ string(32) "f77bd31e1e4dd11d12828fb661a08010"
-- Compression level 8 --
string(32) "f77bd31e1e4dd11d12828fb661a08010"
-- Compression level 9 --
-string(32) "f77bd31e1e4dd11d12828fb661a08010"
-===Done=== \ No newline at end of file
+string(32) "8849e9a1543c04b3f882b5ce20839ed2"
+
+-- Testing with no specified compression level --
+string(94) "1f8b08000000000000%c%c735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200edc4e40b1b000000"
+
+-- Testing gzencode with mode specified --
+string(94) "1f8b08000000000000%c%c735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200edc4e40b1b000000"
+===Done===
diff --git a/ext/zlib/tests/gzencode_error1.phpt b/ext/zlib/tests/gzencode_error1.phpt
index ed8c977..9ecf4b8 100644
--- a/ext/zlib/tests/gzencode_error1.phpt
+++ b/ext/zlib/tests/gzencode_error1.phpt
@@ -71,12 +71,12 @@ NULL
-- Testing with incorrect compression level --
-Warning: gzencode(): compression level(99) must be within -1..9 in %s on line %d
+Warning: gzencode(): compression level (99) must be within -1..9 in %s on line %d
bool(false)
-- Testing with incorrect encoding_mode --
-Warning: gzencode(): encoding mode must be FORCE_GZIP or FORCE_DEFLATE in %s on line %d
+Warning: gzencode(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d
bool(false)
-- Testing with incorrect parameters --
@@ -87,7 +87,7 @@ NULL
Warning: gzencode() expects parameter 2 to be long, object given in %s on line %d
NULL
-Warning: gzencode(): encoding mode must be FORCE_GZIP or FORCE_DEFLATE in %s on line %d
+Warning: gzencode(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d
bool(false)
Warning: gzencode() expects parameter 3 to be long, object given in %s on line %d
@@ -95,4 +95,4 @@ NULL
Warning: gzencode() expects parameter 2 to be long, string given in %s on line %d
NULL
-===Done=== \ No newline at end of file
+===Done===
diff --git a/ext/zlib/tests/gzencode_variation1.phpt b/ext/zlib/tests/gzencode_variation1.phpt
index 47e2097..ef1d3a7 100644
--- a/ext/zlib/tests/gzencode_variation1.phpt
+++ b/ext/zlib/tests/gzencode_variation1.phpt
@@ -3,6 +3,10 @@ Test gzencode() function : variation
--SKIPIF--
<?php
+if( substr(PHP_OS, 0, 3) == "WIN" ) {
+ die("skip.. Do not run on Windows");
+}
+
if (!extension_loaded("zlib")) {
print "skip - ZLIB extension not loaded";
}
@@ -30,4 +34,4 @@ var_dump(bin2hex(gzencode($output)));
-- Testing multiple compression --
string(3658) "1f8b0800000000000003010e07f1f81f8b08000000000000036d574d6fe4c80dbdeb57d4ad2f3dfe01eb83e1ec22980e309b4562c067b64449159754dafab0b6e7d7e73d96da1e4c72184c4b2ab2c8f7c847fa25baabba98dc1a8b2b7c38bb324b713ee37f757f56cdc5c7f5b17b9d152f923b157c5ae335e0b75fedd0e2d781c6b98ea3a6ee05affe1dfc3a6527f8f09c52dcb38ba38bb5249934d6ecfe1e53a9ab76ff4c342cf2a64ed2028349fc9a8b139755685352acb82b9fbb67f8bade5cdcb698e1fcec94b7ceba3cb897e806cfc8114350dd1ebbdfa35b62d2478b0056d23ed809b9b95d696d91ce2aa97c911e3fa539c43f84c887554a4d125c9e63ff96711cc08c0866263cb37a0bbe2122ae8f6baecb2284abfb4ddf916db8354cddeef37c1afe5fa02fc7afb3db34f5b3acbdf2eb905490d8f38d7468d253a323d5ebb903760d7944d3b2024e834a99ddce77669bdd823cfbb8e899d4ad4c799677452e6029e80023a03b2374005590641f7d3877df2ad09f3c0e82a54d6a5644fd63049a37ed4bc362016fd9f51264f1e5c630727421ae930b7ed416e93e47b7c71a400390361ffbecb7561bb98f69b5da289e91becc27f08b3b724cb8704f9144d366431d0cb870c56b205deaa2e17636063761a911039fb7e4bf9f06c4f0aecd2ec80e8b41831ca7515e31286166458ea3ef71f2ce7cde2ae269c96d60525724a9c9170b713ed5750758f3cd2a361fc8b288fc92358ce884692e8ea0fe59bd969a0da2eed5831b715749eaae7178f3ebd30fb88c92105f367cce2c882955dc6bf8eca0d5d57540b3092894743ba0fd5b2dad021836191f1afc0bba14dde1642cb0b1aa6879c38907dcefa0720082b801bec61417469219175267dfa047df35b0bd1332001c28cdfafd3bcabe91e74368cdd8d8478e494c190e7ee90c67f2bde288e68ab6b15e883c995be4f8feb6c6dda4278e4f38578ddbdc7be36788daf0c3cb1d1819c73822f7000a0d1813fa94153b572315e51343b536bc64977dff163cebfd8418773261f524017e251fccc60ae29a5770ae097594d52e9c1229d87ce967a36401c46b69945afb249d101c9d420ffa9a123e232c20e76467d5d169202a2dd4c582949e013e745df7958d4b0cc4fd4377a737cd4feea7974070000f314d423e0634cb9a618fdf5dc64fd422181fd59c9230c9f6f9d18dc8fc23e9cccbc7188733b04aa57de83ebea0be3633cff5fa1ff83269be7f44f5a8d84550cc703255fd345dd402034d0b3e11a73ec6e3d4a77f4f685b614329f1b3132ae7af33d02e1e55e291fa6574b758d1f0200e7423dbc852211818043a7c9ce80aa9d59fce0401959f5ea2cf71fde90824f8c9192dbe9d329db143794675ddcf257dd7755273b67340414e3ccad12e3f661f8aad9cf9957dc1275d10a51d3934fa81e68dc6768fb8ee23e373936c8e13feab8b0f50d227f7af76f561fb0950f3d099bbc316c3892a42fb36806d8660e800fa4f43fd4b962d2097d71933a54b77ff948677848eb17bb3a88b621682cfb3bbb49cf42fed6b3944124ad8358ca688aa44dd5f2144c7c9ab16f25b9aca9654ef357ec9ad55c40d324d6cc3d9e3920b863c231d31a95d937fb5520f9c816c79b7dcecc593fb9593cc05a51ebb1eeddd5b49eb437769738d0f64adc579d372b8b7f7c0208487ee3915ebf5766e148ebd77cf4e01f3ec285047011e55838968b6494d517fe29224777b24dd3ddf933101695b102e87db805eef291b74dcfd91628fb2a53f93dbd2968ef2e598746c9204f89fba1f0246fc671610a0591806e46a1346f77c40d910a47c5e20ffb23f003c04b648327a4ed98032c1965bd35bb0044f5344248f56fdb99aa61d6451d68e33489a83bffbe6573541b2da5f64681ea12090f778b2075374778810f73965fa3626a9d41f4df2f83f7c34658cec921b5a9bde49dd5007ec882b02adc514f81aa85898b5cc98e1b137733c0a8789b7f5648d2d231b80bf74978f25d61ce08a8abd11801fd8f995e066676307192ff7641f1cc6e0dee68565b8b22ac3889cd067bf732754a6b270af1044c6a8776811a4f6d8bd0477a9f516064201b920b92d7cd4dc7eee13e6b3eb3528a82f9abb3f388ebe6a8f871393461b73816ec54c99d604174bc5a6801de13908f86aea6a7d0fea107d682bcf1ec348b83872e6b8a316ecd02eb8f8dc86a609bf59a2dd03f1dfa4079436d55e24617be1a2854d008b2b2b1705e2078a7f3946318df1c24f6bf70d4b456eca286ec2b585b28262cc048a098c3e2d5f325a92bb36f691afdc14c822da1b116c9c1c07bb362eb0a04b78834c812134230ebf2044ac2e3c0e3ad00f848dc5010f3bf917ec2fc700b7bf26dacea8440620e04f90f4d97d6dd77cfde8a05c7d3930f1e5811fb8ec5c70964dcc8187ec90e32fdd6b64eec7586413b7d55bed65c4cce39a9b6c15e70e9da94e53fc904e6286f01f5b5562c94211befbc23507e01b2a3865e2f45b5d7b591f290087a5605b82495b4e393f31aa5b37211ec40241a746d903c5eebf117a4d3ddb0d00007b64cbc70e070000"
-===Done=== \ No newline at end of file
+===Done===
diff --git a/ext/zlib/tests/gzencode_variation2-win32.phpt b/ext/zlib/tests/gzencode_variation2-win32.phpt
new file mode 100644
index 0000000..f664359
--- /dev/null
+++ b/ext/zlib/tests/gzencode_variation2-win32.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Test gzencode() function : variation - verify header contents with all encoding modes
+--XFAIL--
+Test will fail until bug #47178 resolved; missing gzip headers whne FORCE_DEFLATE specified
+--SKIPIF--
+<?php
+
+if( substr(PHP_OS, 0, 3) != "WIN" ) {
+ die("skip.. only for Windows");
+}
+
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : string gzencode ( string $data [, int $level [, int $encoding_mode ]] )
+ * Description: Gzip-compress a string
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+echo "*** Testing gzencode() : variation ***\n";
+
+$data = "A small string to encode\n";
+
+echo "\n-- Testing with each encoding_mode --\n";
+var_dump(bin2hex(gzencode($data, -1)));
+var_dump(bin2hex(gzencode($data, -1, FORCE_GZIP)));
+var_dump(bin2hex(gzencode($data, -1, FORCE_DEFLATE)));
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing gzencode() : variation ***
+
+-- Testing with each encoding_mode --
+string(90) "1f8b080000000000000b735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200d7739de519000000"
+string(90) "1f8b080000000000000b735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200d7739de519000000"
+string(86) "1f8b080000000000000b789c735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200735808cd"
+===DONE===
diff --git a/ext/zlib/tests/gzencode_variation2.phpt b/ext/zlib/tests/gzencode_variation2.phpt
index 901cd53..e6fe7dd 100644
--- a/ext/zlib/tests/gzencode_variation2.phpt
+++ b/ext/zlib/tests/gzencode_variation2.phpt
@@ -1,8 +1,14 @@
--TEST--
Test gzencode() function : variation - verify header contents with all encoding modes
+--XFAIL--
+Test will fail until bug #47178 resolved; missing gzip headers whne FORCE_DEFLATE specified
--SKIPIF--
<?php
+if( substr(PHP_OS, 0, 3) == "WIN" ) {
+ die("skip.. Do not run on Windows");
+}
+
if (!extension_loaded("zlib")) {
print "skip - ZLIB extension not loaded";
}
@@ -33,4 +39,4 @@ var_dump(bin2hex(gzencode($data, -1, FORCE_DEFLATE)));
string(90) "1f8b0800000000000003735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200d7739de519000000"
string(90) "1f8b0800000000000003735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200d7739de519000000"
string(86) "1f8b0800000000000003789c735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200735808cd"
-===DONE=== \ No newline at end of file
+===DONE===
diff --git a/ext/zlib/tests/gzinflate-bug42663.phpt b/ext/zlib/tests/gzinflate-bug42663.phpt
index dd53c78..4f0ca9f 100644
--- a/ext/zlib/tests/gzinflate-bug42663.phpt
+++ b/ext/zlib/tests/gzinflate-bug42663.phpt
@@ -5,8 +5,8 @@ Bug #42663 (gzinflate() try to allocate all memory with truncated $data)
--FILE--
<?php
// build a predictable string
-$string = b'';
-for($i=0; $i<30000; ++$i) $string .= (binary)$i . b' ';
+$string = '';
+for($i=0; $i<30000; ++$i) $string .= $i . ' ';
var_dump(strlen($string));
// deflate string
$deflated = gzdeflate($string,9);
@@ -15,9 +15,12 @@ var_dump(strlen($deflated));
$truncated = substr($deflated, 0, 65535);
var_dump(strlen($truncated));
// inflate $truncated string (check if it will not eat all memory)
-gzinflate($truncated);
+var_dump(gzinflate($truncated));
?>
---EXPECT--
+--EXPECTF--
int(168890)
int(66743)
int(65535)
+
+Warning: gzinflate(): data error in %s on line %d
+bool(false)
diff --git a/ext/zlib/tests/gzinflate_length.phpt b/ext/zlib/tests/gzinflate_length.phpt
index 436025d..6e86d86 100644
--- a/ext/zlib/tests/gzinflate_length.phpt
+++ b/ext/zlib/tests/gzinflate_length.phpt
@@ -4,7 +4,7 @@ gzinflate() and $length argument
<?php if (!extension_loaded("zlib")) print "skip"; ?>
--FILE--
<?php
-$original = b'aaaaaaaaaaaaaaa';
+$original = 'aaaaaaaaaaaaaaa';
$packed=gzdeflate($original);
echo strlen($packed)." ".strlen($original)."\n";
$unpacked=gzinflate($packed, strlen($original));
diff --git a/ext/zlib/tests/gzreadgzwrite.phpt b/ext/zlib/tests/gzreadgzwrite.phpt
index 6d6729a..71d728b 100644
--- a/ext/zlib/tests/gzreadgzwrite.phpt
+++ b/ext/zlib/tests/gzreadgzwrite.phpt
@@ -5,7 +5,7 @@ gzopen(), gzread(), gzwrite()
if (!extension_loaded("zlib")) print "skip"; ?>
--FILE--
<?php
-$original = str_repeat("hallo php",4096);
+$original = str_repeat(b"hallo php",4096);
$filename = tempnam("/tmp", "phpt");
$fp = gzopen($filename, "wb");
@@ -15,7 +15,12 @@ var_dump(gztell($fp));
fclose($fp);
$fp = gzopen($filename, "rb");
-$data = gzread($fp, strlen($original));
+
+$data = '';
+while ($buf = gzread($fp, 8092)) {
+ $data .= $buf;
+}
+
if ($data == $original) {
echo "Strings are equal\n";
} else {
diff --git a/ext/zlib/tests/gzreadgzwriteplain.phpt b/ext/zlib/tests/gzreadgzwriteplain.phpt
index 7bb567d..6a752b6 100644
--- a/ext/zlib/tests/gzreadgzwriteplain.phpt
+++ b/ext/zlib/tests/gzreadgzwriteplain.phpt
@@ -5,7 +5,7 @@ gzopen(), gzread(), gzwrite() for non-compressed data
if (!extension_loaded("zlib")) print "skip"; ?>
--FILE--
<?php
-$original = str_repeat("hallo php",4096);
+$original = str_repeat(b"hallo php",4096);
$filename = tempnam("/tmp", "phpt");
$fp = fopen($filename, "wb");
@@ -15,7 +15,12 @@ var_dump(ftell($fp));
fclose($fp);
$fp = gzopen($filename, "rb");
-$data = gzread($fp, strlen($original));
+
+$data = '';
+while ($buf = gzread($fp, 8192)) {
+ $data .= $buf;
+}
+
if ($data == $original) {
echo "Strings are equal\n";
} else {
@@ -24,7 +29,11 @@ if ($data == $original) {
}
gzseek($fp, strlen($original) / 2);
-$data = gzread($fp, strlen($original));
+
+$data = '';
+while ($buf = gzread($fp, 8192)) {
+ $data .= $buf;
+}
var_dump(strlen($data));
if ($data == substr($original, strlen($original) / 2)) {
diff --git a/ext/zlib/tests/gzuncompress_error1.phpt b/ext/zlib/tests/gzuncompress_error1.phpt
index 66e5b2a..f26a4f5 100644
--- a/ext/zlib/tests/gzuncompress_error1.phpt
+++ b/ext/zlib/tests/gzuncompress_error1.phpt
@@ -14,8 +14,6 @@ if (!extension_loaded("zlib")) {
* Alias to functions:
*/
-
-
echo "*** Testing gzuncompress() : error conditions ***\n";
// Zero arguments
@@ -29,14 +27,12 @@ $length = 10;
$extra_arg = 10;
var_dump( gzuncompress($data, $length, $extra_arg) );
-
echo "\n-- Testing with a buffer that is too small --\n";
$short_len = strlen($data) - 1;
$compressed = gzcompress($data);
var_dump(gzuncompress($compressed, $short_len));
-
echo "\n-- Testing with incorrect arguments --\n";
var_dump(gzuncompress(123));
@@ -68,7 +64,7 @@ NULL
-- Testing with a buffer that is too small --
-Warning: gzuncompress(): buffer error in %s on line %d
+Warning: gzuncompress(): insufficient memory in %s on line %d
bool(false)
-- Testing with incorrect arguments --
@@ -81,4 +77,4 @@ NULL
Warning: gzuncompress() expects parameter 2 to be long, string given in %s on line %d
NULL
-===DONE=== \ No newline at end of file
+===DONE===
diff --git a/ext/zlib/tests/gzwrite_variation1.phpt b/ext/zlib/tests/gzwrite_variation1.phpt
index bd3778e..ab6c260 100644
--- a/ext/zlib/tests/gzwrite_variation1.phpt
+++ b/ext/zlib/tests/gzwrite_variation1.phpt
@@ -11,7 +11,7 @@ if (!extension_loaded("zlib")) {
$filename = dirname(__FILE__)."/004.txt.gz";
$h = gzopen($filename, 'r');
-$str = "Here is the string to be written. ";
+$str = b"Here is the string to be written. ";
$length = 10;
var_dump(gzwrite( $h, $str ) );
var_dump(gzread($h, 10));
diff --git a/ext/zlib/tests/ob_001.phpt b/ext/zlib/tests/ob_001.phpt
new file mode 100644
index 0000000..b074a4f
--- /dev/null
+++ b/ext/zlib/tests/ob_001.phpt
@@ -0,0 +1,20 @@
+--TEST--
+zlib.output_compression
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) die("skip need ext/zlib");
+if (false === stristr(PHP_SAPI, "cgi")) die("skip need sapi/cgi");
+?>
+--GET--
+a=b
+--INI--
+zlib.output_compression=1
+--ENV--
+HTTP_ACCEPT_ENCODING=gzip
+--FILE--
+<?php
+echo "hi\n";
+?>
+--EXPECTF--
+‹%s
+
diff --git a/ext/zlib/tests/ob_002.phpt b/ext/zlib/tests/ob_002.phpt
new file mode 100644
index 0000000..53cf25c
--- /dev/null
+++ b/ext/zlib/tests/ob_002.phpt
@@ -0,0 +1,18 @@
+--TEST--
+zlib.output_compression
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) die("skip need ext/zlib");
+?>
+--INI--
+zlib.output_compression=1
+--ENV--
+HTTP_ACCEPT_ENCODING=gzip
+--FILE--
+<?php
+ini_set("zlib.output_compression", 0);
+echo "hi\n";
+?>
+--EXPECTF--
+hi
+
diff --git a/ext/zlib/tests/ob_003.phpt b/ext/zlib/tests/ob_003.phpt
new file mode 100644
index 0000000..43dbb08
--- /dev/null
+++ b/ext/zlib/tests/ob_003.phpt
@@ -0,0 +1,25 @@
+--TEST--
+zlib.output_compression
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) die("skip need ext/zlib");
+if (false === stristr(PHP_SAPI, "cgi")) die("skip need sapi/cgi");
+?>
+--INI--
+zlib.output_compression=0
+--ENV--
+HTTP_ACCEPT_ENCODING=gzip
+--POST--
+dummy=42
+--FILE--
+<?php
+ini_set("zlib.output_compression", 1);
+echo "hi\n";
+?>
+--EXPECTF--
+%s
+Content-Encoding: gzip
+Vary: Accept-Encoding
+%s
+
+‹%s
diff --git a/ext/zlib/tests/ob_004.phpt b/ext/zlib/tests/ob_004.phpt
new file mode 100644
index 0000000..3d3be9d
--- /dev/null
+++ b/ext/zlib/tests/ob_004.phpt
@@ -0,0 +1,25 @@
+--TEST--
+ob_gzhandler
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) die("skip need ext/zlib");
+if (false === stristr(PHP_SAPI, "cgi")) die("skip need sapi/cgi");
+?>
+--INI--
+zlib.output_compression=0
+--ENV--
+HTTP_ACCEPT_ENCODING=gzip
+--POST--
+dummy=42
+--FILE--
+<?php
+ob_start("ob_gzhandler");
+echo "hi\n";
+?>
+--EXPECTF--
+%s
+Content-Encoding: gzip
+Vary: Accept-Encoding
+%s
+
+‹%s
diff --git a/ext/zlib/tests/ob_005.phpt b/ext/zlib/tests/ob_005.phpt
new file mode 100644
index 0000000..c266cb7
--- /dev/null
+++ b/ext/zlib/tests/ob_005.phpt
@@ -0,0 +1,21 @@
+--TEST--
+ob_gzhandler
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) die("skip need ext/zlib");
+if (false === stristr(PHP_SAPI, "cgi")) die("skip need sapi/cgi");
+?>
+--INI--
+zlib.output_compression=0
+--ENV--
+HTTP_ACCEPT_ENCODING=gzip
+--POST--
+dummy=42
+--FILE--
+<?php
+ob_start("ob_gzhandler");
+ini_set("zlib.output_compression", 0);
+echo "hi\n";
+?>
+--EXPECTF--
+%shi
diff --git a/ext/zlib/tests/readgzfile_variation14.phpt b/ext/zlib/tests/readgzfile_variation14.phpt
index 165bf59..ee0d6d6 100644
--- a/ext/zlib/tests/readgzfile_variation14.phpt
+++ b/ext/zlib/tests/readgzfile_variation14.phpt
@@ -41,4 +41,4 @@ NULL
Warning: readgzfile() expects parameter 2 to be long, string given in %s on line %d
NULL
-===DONE=== \ No newline at end of file
+===DONE===
diff --git a/ext/zlib/tests/readgzfile_variation4.phpt b/ext/zlib/tests/readgzfile_variation4.phpt
index cbc561c..ece84a9 100644
--- a/ext/zlib/tests/readgzfile_variation4.phpt
+++ b/ext/zlib/tests/readgzfile_variation4.phpt
@@ -26,9 +26,18 @@ foreach ( $variation as $var ) {
?>
===DONE===
--EXPECTF--
+Warning: readgzfile(10.5): failed to open stream: No such file or directory in %s on line %d
bool(false)
+
+Warning: readgzfile(-10.5): failed to open stream: No such file or directory in %s on line %d
bool(false)
+
+Warning: readgzfile(123456789000): failed to open stream: No such file or directory in %s on line %d
bool(false)
+
+Warning: readgzfile(-123456789000): failed to open stream: No such file or directory in %s on line %d
bool(false)
+
+Warning: readgzfile(0.5): failed to open stream: No such file or directory in %s on line %d
bool(false)
===DONE===
diff --git a/ext/zlib/tests/readgzfile_variation5.phpt b/ext/zlib/tests/readgzfile_variation5.phpt
index dde0dab..460e188 100644
--- a/ext/zlib/tests/readgzfile_variation5.phpt
+++ b/ext/zlib/tests/readgzfile_variation5.phpt
@@ -25,8 +25,15 @@ foreach ( $variation as $var ) {
?>
===DONE===
--EXPECTF--
+Warning: readgzfile(0): failed to open stream: No such file or directory in %s on line %d
bool(false)
+
+Warning: readgzfile(1): failed to open stream: No such file or directory in %s on line %d
bool(false)
+
+Warning: readgzfile(12345): failed to open stream: No such file or directory in %s on line %d
bool(false)
+
+Warning: readgzfile(-2345): failed to open stream: No such file or directory in %s on line %d
bool(false)
-===DONE=== \ No newline at end of file
+===DONE===
diff --git a/ext/zlib/tests/readgzfile_variation6.phpt b/ext/zlib/tests/readgzfile_variation6.phpt
index 1beeca7..69a4dc1 100644
--- a/ext/zlib/tests/readgzfile_variation6.phpt
+++ b/ext/zlib/tests/readgzfile_variation6.phpt
@@ -43,6 +43,7 @@ foreach ( $variation as $var ) {
}
?>
--EXPECTF--
+Error: 2 - readgzfile(Class A object): failed to open stream: No such file or directory, %s(%d)
bool(false)
Error: 2 - readgzfile() expects parameter 1 to be string, object given, %s(%d)
NULL \ No newline at end of file
diff --git a/ext/zlib/tests/readgzfile_variation7.phpt b/ext/zlib/tests/readgzfile_variation7.phpt
index df244d3..20162b5 100644
--- a/ext/zlib/tests/readgzfile_variation7.phpt
+++ b/ext/zlib/tests/readgzfile_variation7.phpt
@@ -29,8 +29,15 @@ foreach ( $variation_array as $var ) {
?>
===DONE===
--EXPECTF--
+Warning: readgzfile(string): failed to open stream: No such file or directory in %s on line %d
bool(false)
+
+Warning: readgzfile(string): failed to open stream: No such file or directory in %s on line %d
bool(false)
+
+Warning: readgzfile(sTrInG): failed to open stream: No such file or directory in %s on line %d
bool(false)
+
+Warning: readgzfile(hello world): failed to open stream: No such file or directory in %s on line %d
bool(false)
===DONE===
diff --git a/ext/zlib/tests/zlib_filter_inflate2.phpt b/ext/zlib/tests/zlib_filter_inflate2.phpt
index 4332d8e..a2099b6 100644
--- a/ext/zlib/tests/zlib_filter_inflate2.phpt
+++ b/ext/zlib/tests/zlib_filter_inflate2.phpt
@@ -6,7 +6,7 @@ zlib.inflate of gzip-encoded stream
<?php /* $Id$ */
$a = gzopen(dirname(__FILE__) . '/test.txt.gz', 'w');
-fwrite($a, "This is quite the thing ain't it\n");
+fwrite($a, b"This is quite the thing ain't it\n");
fclose($a);
$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
@@ -38,4 +38,4 @@ fclose($fp);
2
This is quite the thing ain't it
3
-This is quite the thing ain't it \ No newline at end of file
+This is quite the thing ain't it
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index af23b29..114c90b 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -16,6 +16,7 @@
| Stefan Röhrich <sr@linux.de> |
| Zeev Suraski <zeev@zend.com> |
| Jade Nicoletti <nicoletti@nns.ch> |
+ | Michael Wallner <mike@php.net> |
+----------------------------------------------------------------------+
*/
@@ -28,188 +29,12 @@
#include "php.h"
#include "SAPI.h"
#include "php_ini.h"
-
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#ifdef PHP_WIN32
-# define O_RDONLY _O_RDONLY
-# include "win32/param.h"
-#else
-# include <sys/param.h>
-/* #include <sys/uio.h> */
-#endif
-
-#include "ext/standard/head.h"
-#include "ext/standard/php_standard.h"
#include "ext/standard/info.h"
+#include "ext/standard/file.h"
+#include "ext/standard/php_string.h"
#include "php_zlib.h"
-#include "fopen_wrappers.h"
-
-#if HAVE_PWD_H
-# ifdef PHP_WIN32
-# include "win32/pwd.h"
-# else
-# include <pwd.h>
-# endif
-#endif
-
-#if defined(HAVE_UNISTD_H) && defined(PHP_WIN32)
-# undef HAVE_UNISTD_H
-#endif
-
-#ifdef COMPILE_DL_ZLIB
-# ifndef PUTS
-# define PUTS(a) php_printf("%s",a)
-# endif
-# ifndef PUTC
-# define PUTC(a) PUTS(a)
-# endif
-# ifndef PHPWRITE
-# define PHPWRITE(a,n) php_write((a),(n) TSRMLS_CC)
-# endif
-#endif
-
-/* Win32 needs some more memory */
-#ifdef PHP_WIN32
-# define PHP_ZLIB_MODIFIER 100
-#else
-# define PHP_ZLIB_MODIFIER 1000
-#endif
-
-#define OS_CODE 0x03 /* FIXME */
-#define GZIP_HEADER_LENGTH 10
-#define GZIP_FOOTER_LENGTH 8
-
-/* True globals, no need for thread safety */
-static const int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
-
-static int php_zlib_output_compression_start(TSRMLS_D);
-
-static PHP_MINIT_FUNCTION(zlib);
-static PHP_MSHUTDOWN_FUNCTION(zlib);
-static PHP_RINIT_FUNCTION(zlib);
-static PHP_MINFO_FUNCTION(zlib);
-static PHP_FUNCTION(gzopen);
-static PHP_FUNCTION(readgzfile);
-static PHP_FUNCTION(gzfile);
-static PHP_FUNCTION(gzcompress);
-static PHP_FUNCTION(gzuncompress);
-static PHP_FUNCTION(gzdeflate);
-static PHP_FUNCTION(gzinflate);
-static PHP_FUNCTION(gzencode);
-static PHP_FUNCTION(ob_gzhandler);
-static PHP_FUNCTION(zlib_get_coding_type);
-
-/* {{{ arginfo */
-ZEND_BEGIN_ARG_INFO_EX(arginfo_gzfile, 0, 0, 1)
- ZEND_ARG_INFO(0, filename)
- ZEND_ARG_INFO(0, use_include_path)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_gzopen, 0, 0, 2)
- ZEND_ARG_INFO(0, filename)
- ZEND_ARG_INFO(0, mode)
- ZEND_ARG_INFO(0, use_include_path)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_readgzfile, 0, 0, 1)
- ZEND_ARG_INFO(0, filename)
- ZEND_ARG_INFO(0, use_include_path)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_gzcompress, 0, 0, 1)
- ZEND_ARG_INFO(0, data)
- ZEND_ARG_INFO(0, level)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_gzuncompress, 0, 0, 1)
- ZEND_ARG_INFO(0, data)
- ZEND_ARG_INFO(0, length)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_gzdeflate, 0, 0, 1)
- ZEND_ARG_INFO(0, data)
- ZEND_ARG_INFO(0, level)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_gzinflate, 0, 0, 1)
- ZEND_ARG_INFO(0, data)
- ZEND_ARG_INFO(0, length)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO(arginfo_zlib_get_coding_type, 0)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_gzencode, 0, 0, 1)
- ZEND_ARG_INFO(0, data)
- ZEND_ARG_INFO(0, level)
- ZEND_ARG_INFO(0, encoding_mode)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_ob_gzhandler, 0, 0, 2)
- ZEND_ARG_INFO(0, str)
- ZEND_ARG_INFO(0, mode)
-ZEND_END_ARG_INFO()
-/* }}} */
-
-/* {{{ php_zlib_functions[]
- */
-static const zend_function_entry php_zlib_functions[] = {
- PHP_FE(readgzfile, arginfo_readgzfile)
- PHP_FALIAS(gzrewind, rewind, NULL)
- PHP_FALIAS(gzclose, fclose, NULL)
- PHP_FALIAS(gzeof, feof, NULL)
- PHP_FALIAS(gzgetc, fgetc, NULL)
- PHP_FALIAS(gzgets, fgets, NULL)
- PHP_FALIAS(gzgetss, fgetss, NULL)
- PHP_FALIAS(gzread, fread, NULL)
- PHP_FE(gzopen, arginfo_gzopen)
- PHP_FALIAS(gzpassthru, fpassthru, NULL)
- PHP_FALIAS(gzseek, fseek, NULL)
- PHP_FALIAS(gztell, ftell, NULL)
- PHP_FALIAS(gzwrite, fwrite, NULL)
- PHP_FALIAS(gzputs, fwrite, NULL)
- PHP_FE(gzfile, arginfo_gzfile)
- PHP_FE(gzcompress, arginfo_gzcompress)
- PHP_FE(gzuncompress, arginfo_gzuncompress)
- PHP_FE(gzdeflate, arginfo_gzdeflate)
- PHP_FE(gzinflate, arginfo_gzinflate)
- PHP_FE(gzencode, arginfo_gzencode)
- PHP_FE(ob_gzhandler, arginfo_ob_gzhandler)
- PHP_FE(zlib_get_coding_type, arginfo_zlib_get_coding_type)
- {NULL, NULL, NULL}
-};
-/* }}} */
-ZEND_DECLARE_MODULE_GLOBALS(zlib)
-
-/* {{{ php_zlib_module_entry
- */
-zend_module_entry php_zlib_module_entry = {
- STANDARD_MODULE_HEADER,
- "zlib",
- php_zlib_functions,
- PHP_MINIT(zlib),
- PHP_MSHUTDOWN(zlib),
- PHP_RINIT(zlib),
- NULL,
- PHP_MINFO(zlib),
- "1.1",
- PHP_MODULE_GLOBALS(zlib),
- NULL,
- NULL,
- NULL,
- STANDARD_MODULE_PROPERTIES_EX
-};
-/* }}} */
-
-#ifdef COMPILE_DL_ZLIB
-ZEND_GET_MODULE(php_zlib)
-#endif
+ZEND_DECLARE_MODULE_GLOBALS(zlib);
/* {{{ Memory management wrappers */
@@ -224,156 +49,400 @@ static void php_zlib_free(voidpf opaque, voidpf address)
}
/* }}} */
-/* {{{ OnUpdate_zlib_output_compression */
-static PHP_INI_MH(OnUpdate_zlib_output_compression)
+/* {{{ php_zlib_output_conflict_check() */
+static int php_zlib_output_conflict_check(const char *handler_name, size_t handler_name_len TSRMLS_DC)
{
- int status, int_value;
- char *ini_value;
-
- if (new_value == NULL) {
- return FAILURE;
+ if (php_output_get_level(TSRMLS_C) > 0) {
+ if (php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME) TSRMLS_CC)
+ || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("ob_gzhandler") TSRMLS_CC)
+ || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("mb_output_handler") TSRMLS_CC)
+ || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("URL-Rewriter") TSRMLS_CC)) {
+ return FAILURE;
+ }
}
+ return SUCCESS;
+}
+/* }}} */
- 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 = "1";
- new_value_length = sizeof("1");
+/* {{{ php_zlib_output_encoding() */
+static int php_zlib_output_encoding(TSRMLS_D)
+{
+ zval **enc;
+
+ if (!ZLIBG(compression_coding)) {
+ zend_is_auto_global(ZEND_STRL("_SERVER") TSRMLS_CC);
+ if (PG(http_globals)[TRACK_VARS_SERVER] && SUCCESS == zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING"), (void *) &enc)) {
+ convert_to_string(*enc);
+ if (strstr(Z_STRVAL_PP(enc), "gzip")) {
+ ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_GZIP;
+ } else if (strstr(Z_STRVAL_PP(enc), "deflate")) {
+ ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_DEFLATE;
+ }
+ }
}
+ return ZLIBG(compression_coding);
+}
+/* }}} */
- int_value = zend_atoi(new_value, new_value_length);
- ini_value = zend_ini_string("output_handler", sizeof("output_handler"), 0);
-
- if (ini_value && *ini_value && int_value) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_CORE_ERROR, "Cannot use both zlib.output_compression and output_handler together!!");
+/* {{{ php_zlib_output_handler() */
+static int php_zlib_output_handler(void **handler_context, php_output_context *output_context)
+{
+ php_zlib_context *ctx = *(php_zlib_context **) handler_context;
+ int flags = Z_SYNC_FLUSH;
+ PHP_OUTPUT_TSRMLS(output_context);
+
+ if (!php_zlib_output_encoding(TSRMLS_C)) {
+ /* "Vary: Accept-Encoding" header sent along uncompressed content breaks caching in MSIE,
+ so let's just send it with successfully compressed content or unless the complete
+ buffer gets discarded, see http://bugs.php.net/40325;
+
+ Test as follows:
+ +Vary: $ HTTP_ACCEPT_ENCODING=gzip ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n";'
+ +Vary: $ HTTP_ACCEPT_ENCODING= ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n";'
+ -Vary: $ HTTP_ACCEPT_ENCODING=gzip ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n"; ob_end_clean();'
+ -Vary: $ HTTP_ACCEPT_ENCODING= ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n"; ob_end_clean();'
+ */
+ if (output_context->op != (PHP_OUTPUT_HANDLER_START|PHP_OUTPUT_HANDLER_CLEAN|PHP_OUTPUT_HANDLER_FINAL)) {
+ sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 1 TSRMLS_CC);
+ }
return FAILURE;
}
- if (stage == PHP_INI_STAGE_RUNTIME && SG(headers_sent) && !SG(request_info).no_headers) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_compression - headers already sent");
- return FAILURE;
+ if (output_context->op & PHP_OUTPUT_HANDLER_START) {
+ /* start up */
+ if (Z_OK != deflateInit2(&ctx->Z, ZLIBG(output_compression_level), Z_DEFLATED, ZLIBG(compression_coding), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) {
+ return FAILURE;
+ }
}
- status = OnUpdateLong(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+ if (output_context->op & PHP_OUTPUT_HANDLER_CLEAN) {
+ /* free buffers */
+ deflateEnd(&ctx->Z);
- if (stage == PHP_INI_STAGE_RUNTIME && int_value) {
- status = php_zlib_output_compression_start(TSRMLS_C);
- }
+ if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) {
+ /* discard */
+ return SUCCESS;
+ } else {
+ /* restart */
+ if (Z_OK != deflateInit2(&ctx->Z, ZLIBG(output_compression_level), Z_DEFLATED, ZLIBG(compression_coding), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) {
+ return FAILURE;
+ }
+ ctx->buffer.used = 0;
+ }
+ } else {
+ if (output_context->in.used) {
+ /* append input */
+ if (ctx->buffer.free < output_context->in.used) {
+ if (!(ctx->buffer.aptr = erealloc_recoverable(ctx->buffer.data, ctx->buffer.used + ctx->buffer.free + output_context->in.used))) {
+ deflateEnd(&ctx->Z);
+ return FAILURE;
+ }
+ ctx->buffer.data = ctx->buffer.aptr;
+ ctx->buffer.free += output_context->in.used;
+ }
+ memcpy(ctx->buffer.data + ctx->buffer.used, output_context->in.data, output_context->in.used);
+ ctx->buffer.free -= output_context->in.used;
+ ctx->buffer.used += output_context->in.used;
+ }
+ output_context->out.size = PHP_ZLIB_BUFFER_SIZE_GUESS(output_context->in.used);
+ output_context->out.data = emalloc(output_context->out.size);
+ output_context->out.free = 1;
+ output_context->out.used = 0;
+
+ ctx->Z.avail_in = ctx->buffer.used;
+ ctx->Z.next_in = (Bytef *) ctx->buffer.data;
+ ctx->Z.avail_out = output_context->out.size;
+ ctx->Z.next_out = (Bytef *) output_context->out.data;
+
+ if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) {
+ flags = Z_FINISH;
+ } else if (output_context->op & PHP_OUTPUT_HANDLER_FLUSH) {
+ flags = Z_FULL_FLUSH;
+ }
- return status;
+ switch (deflate(&ctx->Z, flags)) {
+ case Z_OK:
+ if (flags == Z_FINISH) {
+ deflateEnd(&ctx->Z);
+ return FAILURE;
+ }
+ case Z_STREAM_END:
+ if (ctx->Z.avail_in) {
+ memmove(ctx->buffer.data, ctx->buffer.data + ctx->buffer.used - ctx->Z.avail_in, ctx->Z.avail_in);
+ }
+ ctx->buffer.free += ctx->buffer.used - ctx->Z.avail_in;
+ ctx->buffer.used = ctx->Z.avail_in;
+ output_context->out.used = output_context->out.size - ctx->Z.avail_out;
+ break;
+ default:
+ deflateEnd(&ctx->Z);
+ return FAILURE;
+ }
+
+ php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS, &flags TSRMLS_CC);
+ if (!(flags & PHP_OUTPUT_HANDLER_STARTED)) {
+ if (SG(headers_sent) || !ZLIBG(output_compression)) {
+ deflateEnd(&ctx->Z);
+ return FAILURE;
+ }
+ switch (ZLIBG(compression_coding)) {
+ case PHP_ZLIB_ENCODING_GZIP:
+ sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1 TSRMLS_CC);
+ break;
+ case PHP_ZLIB_ENCODING_DEFLATE:
+ sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1 TSRMLS_CC);
+ break;
+ default:
+ deflateEnd(&ctx->Z);
+ return FAILURE;
+ }
+ sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 1 TSRMLS_CC);
+ php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE, NULL TSRMLS_CC);
+ }
+
+ if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) {
+ deflateEnd(&ctx->Z);
+ }
+ }
+ return SUCCESS;
}
/* }}} */
-/* {{{ OnUpdate_zlib_output_compression_level */
-static PHP_INI_MH(OnUpdate_zlib_output_compression_level)
+/* {{{ php_zlib_output_handler_dtor() */
+static void php_zlib_output_handler_dtor(void *opaq TSRMLS_DC)
{
- OnUpdateLong(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+ php_zlib_context *ctx = (php_zlib_context *) opaq;
- return SUCCESS;
+ if (ctx) {
+ if (ctx->buffer.data) {
+ efree(ctx->buffer.data);
+ }
+ efree(ctx);
+ }
}
/* }}} */
-/* {{{ OnUpdate_zlib_output_handler */
-static PHP_INI_MH(OnUpdate_zlib_output_handler)
+/* {{{ php_zlib_output_handler_init() */
+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)
{
- if (stage == PHP_INI_STAGE_RUNTIME && SG(headers_sent) && !SG(request_info).no_headers) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_handler - headers already sent");
- return FAILURE;
+ php_output_handler *h = NULL;
+ php_zlib_context *ctx;
+
+ if (!ZLIBG(output_compression)) {
+ ZLIBG(output_compression) = chunk_size ? chunk_size : PHP_OUTPUT_HANDLER_DEFAULT_SIZE;
}
- OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+ if ((h = php_output_handler_create_internal(handler_name, handler_name_len, php_zlib_output_handler, chunk_size, flags TSRMLS_CC))) {
+ ctx = (php_zlib_context *) ecalloc(1, sizeof(php_zlib_context));
+ ctx->Z.zalloc = php_zlib_alloc;
+ ctx->Z.zfree = php_zlib_free;
+ php_output_handler_set_context(h, ctx, php_zlib_output_handler_dtor TSRMLS_CC);
+ }
- return SUCCESS;
+ return h;
}
/* }}} */
+/* {{{ php_zlib_output_compression_start() */
+static void php_zlib_output_compression_start(TSRMLS_D)
+{
+ zval *zoh;
+ php_output_handler *h;
-PHP_INI_BEGIN()
- 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)
- STD_PHP_INI_ENTRY("zlib.output_handler", "", PHP_INI_ALL, OnUpdate_zlib_output_handler, output_handler, zend_zlib_globals, zlib_globals)
-PHP_INI_END()
+ switch (ZLIBG(output_compression)) {
+ case 0:
+ break;
+ case 1:
+ ZLIBG(output_compression) = PHP_OUTPUT_HANDLER_DEFAULT_SIZE;
+ /* break omitted intentionally */
+ default:
+ if ( (h = php_zlib_output_handler_init(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME), ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC)) &&
+ (SUCCESS == php_output_handler_start(h TSRMLS_CC))) {
+ if (ZLIBG(output_handler) && *ZLIBG(output_handler)) {
+ MAKE_STD_ZVAL(zoh);
+ ZVAL_STRING(zoh, ZLIBG(output_handler), 1);
+ php_output_start_user(zoh, ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
+ zval_ptr_dtor(&zoh);
+ }
+ }
+ break;
+ }
+}
+/* }}} */
-/* {{{ PHP_MINIT_FUNCTION
- */
-static PHP_MINIT_FUNCTION(zlib)
+/* {{{ php_zlib_encode() */
+static int php_zlib_encode(const char *in_buf, size_t in_len, char **out_buf, size_t *out_len, int encoding, int level TSRMLS_DC)
{
- php_register_url_stream_wrapper("compress.zlib", &php_stream_gzip_wrapper TSRMLS_CC);
- php_stream_filter_register_factory("zlib.*", &php_zlib_filter_factory TSRMLS_CC);
+ int status;
+ z_stream Z;
- REGISTER_LONG_CONSTANT("FORCE_GZIP", CODING_GZIP, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("FORCE_DEFLATE", CODING_DEFLATE, CONST_CS | CONST_PERSISTENT);
+ memset(&Z, 0, sizeof(z_stream));
+ Z.zalloc = php_zlib_alloc;
+ Z.zfree = php_zlib_free;
- REGISTER_INI_ENTRIES();
+ if (Z_OK == (status = deflateInit2(&Z, level, Z_DEFLATED, encoding, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) {
+ *out_len = PHP_ZLIB_BUFFER_SIZE_GUESS(in_len);
+ *out_buf = emalloc(*out_len);
- return SUCCESS;
+ Z.next_in = (Bytef *) in_buf;
+ Z.next_out = (Bytef *) *out_buf;
+ Z.avail_in = in_len;
+ Z.avail_out = *out_len;
+
+ status = deflate(&Z, Z_FINISH);
+ deflateEnd(&Z);
+
+ if (Z_STREAM_END == status) {
+ /* size buffer down to actual length */
+ *out_buf = erealloc(*out_buf, Z.total_out + 1);
+ (*out_buf)[*out_len = Z.total_out] = '\0';
+ return SUCCESS;
+ } else {
+ efree(*out_buf);
+ }
+ }
+
+ *out_buf = NULL;
+ *out_len = 0;
+
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status));
+ return FAILURE;
}
/* }}} */
-/* {{{ PHP_RINIT_FUNCTION
- */
-static PHP_RINIT_FUNCTION(zlib)
+/* {{{ php_zlib_inflate_rounds() */
+static inline int php_zlib_inflate_rounds(z_stream *Z, size_t max, char **buf, size_t *len)
{
- ZLIBG(ob_gzhandler_status) = 0;
- ZLIBG(compression_coding) = 0;
+ int status, round = 0;
+ php_zlib_buffer buffer = {NULL, NULL, 0, 0, 0};
- php_zlib_output_compression_start(TSRMLS_C);
+ *buf = NULL;
+ *len = 0;
- return SUCCESS;
+ buffer.size = (max && (max < Z->avail_in)) ? max : Z->avail_in;
+
+ do {
+ if ((max && (max <= buffer.used)) || !(buffer.aptr = erealloc_recoverable(buffer.data, buffer.size))) {
+ status = Z_MEM_ERROR;
+ } else {
+ buffer.data = buffer.aptr;
+ Z->avail_out = buffer.free = buffer.size - buffer.used;
+ Z->next_out = (Bytef *) buffer.data + buffer.used;
+#if 0
+ 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);
+#endif
+ status = inflate(Z, Z_NO_FLUSH);
+
+ buffer.used += buffer.free - Z->avail_out;
+ buffer.free = Z->avail_out;
+#if 0
+ 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);
+#endif
+ buffer.size += (buffer.size >> 3) + 1;
+ }
+ } while ((Z_BUF_ERROR == status || (Z_OK == status && Z->avail_in)) && ++round < 100);
+
+ if (status == Z_STREAM_END) {
+ buffer.data = erealloc(buffer.data, buffer.used + 1);
+ buffer.data[buffer.used] = '\0';
+ *buf = buffer.data;
+ *len = buffer.used;
+ } else {
+ if (buffer.data) {
+ efree(buffer.data);
+ }
+ /* HACK: See zlib/examples/zpipe.c inf() function for explanation. */
+ /* This works as long as this function is not used for streaming. Required to catch very short invalid data. */
+ status = (status == Z_OK) ? Z_DATA_ERROR : status;
+ }
+ return status;
}
/* }}} */
-/* {{{ PHP_MSHUTDOWN_FUNCTION
- */
-static PHP_MSHUTDOWN_FUNCTION(zlib)
+/* {{{ php_zlib_decode() */
+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)
{
- php_unregister_url_stream_wrapper("zlib" TSRMLS_CC);
- php_stream_filter_unregister_factory("zlib.*" TSRMLS_CC);
+ int status = Z_DATA_ERROR;
+ z_stream Z;
+
+ memset(&Z, 0, sizeof(z_stream));
+ Z.zalloc = php_zlib_alloc;
+ Z.zfree = php_zlib_free;
+
+ if (in_len) {
+retry_raw_inflate:
+ status = inflateInit2(&Z, encoding);
+ if (Z_OK == status) {
+ Z.next_in = (Bytef *) in_buf;
+ Z.avail_in = in_len;
+
+ switch (status = php_zlib_inflate_rounds(&Z, max_len, out_buf, out_len)) {
+ case Z_STREAM_END:
+ inflateEnd(&Z);
+ return SUCCESS;
+
+ case Z_DATA_ERROR:
+ /* raw deflated data? */
+ if (PHP_ZLIB_ENCODING_ANY == encoding) {
+ inflateEnd(&Z);
+ encoding = PHP_ZLIB_ENCODING_RAW;
+ goto retry_raw_inflate;
+ }
+ }
+ inflateEnd(&Z);
+ }
+ }
- UNREGISTER_INI_ENTRIES();
+ *out_buf = NULL;
+ *out_len = 0;
- return SUCCESS;
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status));
+ return FAILURE;
}
/* }}} */
-/* {{{ PHP_MINFO_FUNCTION
- */
-static PHP_MINFO_FUNCTION(zlib)
+/* {{{ proto string zlib_get_coding_type(void)
+ Returns the coding type used for output compression */
+static PHP_FUNCTION(zlib_get_coding_type)
{
- php_info_print_table_start();
- php_info_print_table_row(2, "ZLib Support", "enabled");
- php_info_print_table_row(2, "Stream Wrapper support", "compress.zlib://");
- php_info_print_table_row(2, "Stream Filter support", "zlib.inflate, zlib.deflate");
- php_info_print_table_row(2, "Compiled Version", ZLIB_VERSION);
- php_info_print_table_row(2, "Linked Version", (char *) zlibVersion());
- php_info_print_table_end();
-
- DISPLAY_INI_ENTRIES();
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+ switch (ZLIBG(compression_coding)) {
+ case PHP_ZLIB_ENCODING_GZIP:
+ RETURN_STRINGL("gzip", sizeof("gzip") - 1, 1);
+ case PHP_ZLIB_ENCODING_DEFLATE:
+ RETURN_STRINGL("deflate", sizeof("deflate") - 1, 1);
+ default:
+ RETURN_FALSE;
+ }
}
/* }}} */
/* {{{ proto array gzfile(string filename [, int use_include_path])
- Read und uncompress entire .gz-file into an array */
+ Read and uncompress entire .gz-file into an array */
static PHP_FUNCTION(gzfile)
{
char *filename;
int filename_len;
- long flags = 0;
- char *slashed, buf[8192];
+ int flags = REPORT_ERRORS;
+ char *slashed, buf[8192] = {0};
register int i = 0;
- int use_include_path = 0;
+ long use_include_path = 0;
php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &flags) == FAILURE) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path)) {
return;
}
- use_include_path = flags ? USE_PATH : 0;
+ if (use_include_path) {
+ flags |= USE_PATH;
+ }
/* using a stream here is a bit more efficient (resource wise) than php_gzopen_wrapper */
- stream = php_stream_gzopen(NULL, filename, "rb", use_include_path | REPORT_ERRORS, NULL, NULL STREAMS_CC TSRMLS_CC);
- if (stream == NULL) {
+ stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC TSRMLS_CC);
+
+ if (!stream) {
/* Error reporting is already done by stream code */
RETURN_FALSE;
}
@@ -382,12 +451,12 @@ static PHP_FUNCTION(gzfile)
array_init(return_value);
/* Now loop through the file and do the magic quotes thing if needed */
- memset(buf,0,sizeof(buf));
-
+ memset(buf, 0, sizeof(buf));
+
while (php_stream_gets(stream, buf, sizeof(buf) - 1) != NULL) {
if (PG(magic_quotes_runtime)) {
int len;
-
+
slashed = php_addslashes(buf, 0, &len, 0 TSRMLS_CC); /* 0 = don't free source string */
add_index_stringl(return_value, i++, slashed, len, 0);
} else {
@@ -402,19 +471,22 @@ static PHP_FUNCTION(gzfile)
Open a .gz-file and return a .gz-file pointer */
static PHP_FUNCTION(gzopen)
{
- char *filename, *mode;
+ char *filename;
+ char *mode;
int filename_len, mode_len;
- long flags = 0;
+ int flags = REPORT_ERRORS;
php_stream *stream;
- int use_include_path = 0;
+ long use_include_path = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &flags) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) {
return;
}
- use_include_path = flags ? USE_PATH : 0;
+ if (use_include_path) {
+ flags |= USE_PATH;
+ }
- stream = php_stream_gzopen(NULL, filename, mode, use_include_path | REPORT_ERRORS, NULL, NULL STREAMS_CC TSRMLS_CC);
+ stream = php_stream_gzopen(NULL, filename, mode, flags, NULL, NULL STREAMS_CC TSRMLS_CC);
if (!stream) {
RETURN_FALSE;
@@ -423,27 +495,27 @@ static PHP_FUNCTION(gzopen)
}
/* }}} */
-/*
- * Read a file and write the ouput to stdout
- */
/* {{{ proto int readgzfile(string filename [, int use_include_path])
Output a .gz-file */
static PHP_FUNCTION(readgzfile)
{
char *filename;
int filename_len;
- long flags = 0;
+ int flags = REPORT_ERRORS;
php_stream *stream;
int size;
- int use_include_path = 0;
+ long use_include_path = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &flags) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) {
return;
}
- use_include_path = flags ? USE_PATH : 0;
+ if (use_include_path) {
+ flags |= USE_PATH;
+ }
+
+ stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC TSRMLS_CC);
- stream = php_stream_gzopen(NULL, filename, "rb", use_include_path, NULL, NULL STREAMS_CC TSRMLS_CC);
if (!stream) {
RETURN_FALSE;
}
@@ -453,676 +525,345 @@ static PHP_FUNCTION(readgzfile)
}
/* }}} */
-/* {{{ proto string gzcompress(string data [, int level])
- Gzip-compress a string */
-static PHP_FUNCTION(gzcompress)
-{
- int data_len, status;
- long level = Z_DEFAULT_COMPRESSION;
- unsigned long l2;
- char *data, *s2;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &level) == FAILURE) {
- return;
- }
-
- if ((level < -1) || (level > 9)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "compression level (%ld) must be within -1..9", level);
- RETURN_FALSE;
- }
-
- l2 = data_len + (data_len / PHP_ZLIB_MODIFIER) + 15 + 1; /* room for \0 */
- s2 = (char *) emalloc(l2);
- if (!s2) {
- RETURN_FALSE;
- }
-
- if (level >= 0) {
- status = compress2(s2, &l2, data, data_len, level);
- } else {
- status = compress(s2, &l2, data, data_len);
- }
-
- if (status == Z_OK) {
- s2 = erealloc(s2, l2 + 1);
- s2[l2] = '\0';
- RETURN_STRINGL(s2, l2, 0);
- } else {
- efree(s2);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status));
- RETURN_FALSE;
- }
+#define PHP_ZLIB_ENCODE_FUNC(name, default_encoding) \
+static PHP_FUNCTION(name) \
+{ \
+ char *in_buf, *out_buf; \
+ int in_len; \
+ size_t out_len; \
+ long level = -1; \
+ long encoding = default_encoding; \
+ if (default_encoding) { \
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &in_buf, &in_len, &level, &encoding)) { \
+ return; \
+ } \
+ } else { \
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|l", &in_buf, &in_len, &encoding, &level)) { \
+ return; \
+ } \
+ } \
+ if (level < -1 || level > 9) { \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "compression level (%ld) must be within -1..9", level); \
+ RETURN_FALSE; \
+ } \
+ switch (encoding) { \
+ case PHP_ZLIB_ENCODING_RAW: \
+ case PHP_ZLIB_ENCODING_GZIP: \
+ case PHP_ZLIB_ENCODING_DEFLATE: \
+ break; \
+ default: \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE"); \
+ RETURN_FALSE; \
+ } \
+ if (SUCCESS != php_zlib_encode(in_buf, in_len, &out_buf, &out_len, encoding, level TSRMLS_CC)) { \
+ RETURN_FALSE; \
+ } \
+ RETURN_STRINGL(out_buf, out_len, 0); \
}
-/* }}} */
-
-/* {{{ proto string gzuncompress(string data [, int length])
- Unzip a gzip-compressed string */
-static PHP_FUNCTION(gzuncompress)
-{
- int data_len, status;
- unsigned int factor=1, maxfactor=16;
- long limit = 0;
- unsigned long plength=0, length;
- char *data, *s1=NULL, *s2=NULL;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &limit) == FAILURE) {
- return;
- }
-
- if (limit < 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "length (%ld) must be greater or equal zero", limit);
- RETURN_FALSE;
- }
- plength = limit;
-
- /*
- zlib::uncompress() wants to know the output data length
- if none was given as a parameter
- we try from input length * 2 up to input length * 2^15
- doubling it whenever it wasn't big enough
- that should be eneugh for all real life cases
- */
- do {
- length = plength ? plength : (unsigned long)data_len * (1 << factor++);
- s2 = (char *) erealloc(s1, length);
- status = uncompress(s2, &length, data, data_len);
- s1 = s2;
- } while ((status == Z_BUF_ERROR) && (!plength) && (factor < maxfactor));
-
- if (status == Z_OK) {
- s2 = erealloc(s2, length + 1); /* space for \0 */
- s2[ length ] = '\0';
- RETURN_STRINGL(s2, length, 0);
- } else {
- efree(s2);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status));
- RETURN_FALSE;
- }
+#define PHP_ZLIB_DECODE_FUNC(name, encoding) \
+static PHP_FUNCTION(name) \
+{ \
+ char *in_buf, *out_buf; \
+ int in_len; \
+ size_t out_len; \
+ long max_len = 0; \
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &in_buf, &in_len, &max_len)) { \
+ return; \
+ } \
+ if (max_len < 0) { \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "length (%ld) must be greater or equal zero", max_len); \
+ RETURN_FALSE; \
+ } \
+ if (SUCCESS != php_zlib_decode(in_buf, in_len, &out_buf, &out_len, encoding, max_len TSRMLS_CC)) { \
+ RETURN_FALSE; \
+ } \
+ RETURN_STRINGL(out_buf, out_len, 0); \
}
-/* }}} */
-
-/* {{{ proto string gzdeflate(string data [, int level])
- Gzip-compress a string */
-static PHP_FUNCTION(gzdeflate)
-{
- int data_len,status;
- long level = Z_DEFAULT_COMPRESSION;
- z_stream stream;
- char *data, *s2;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &level) == FAILURE) {
- return;
- }
-
- if ((level < -1) || (level > 9)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "compression level (%ld) must be within -1..9", level);
- RETURN_FALSE;
- }
+/* {{{ proto binary zlib_encode(binary data, int encoding[, int level = -1])
+ Compress data with the specified encoding */
+PHP_ZLIB_ENCODE_FUNC(zlib_encode, 0);
+/* }}} */
- stream.data_type = Z_ASCII;
- stream.zalloc = php_zlib_alloc;
- stream.zfree = php_zlib_free;
- stream.opaque = (voidpf) Z_NULL;
+/* {{{ proto binary zlib_decode(binary data[, int max_decoded_len])
+ Uncompress any raw/gzip/zlib encoded data */
+PHP_ZLIB_DECODE_FUNC(zlib_decode, PHP_ZLIB_ENCODING_ANY);
- stream.next_in = (Bytef *) data;
- stream.avail_in = data_len;
+/* NOTE: The naming of these userland functions was quite unlucky */
+/* {{{ proto binary gzdeflate(binary data[, int level = -1[, int encoding = ZLIB_ENCODING_RAW])
+ Encode data with the raw deflate encoding */
+PHP_ZLIB_ENCODE_FUNC(gzdeflate, PHP_ZLIB_ENCODING_RAW);
+/* }}} */
- stream.avail_out = stream.avail_in + (stream.avail_in / PHP_ZLIB_MODIFIER) + 15 + 1; /* room for \0 */
+/* {{{ proto binary gzencode(binary data[, int level = -1[, int encoding = ZLIB_ENCODING_GZIP])
+ Encode data with the gzip encoding */
+PHP_ZLIB_ENCODE_FUNC(gzencode, PHP_ZLIB_ENCODING_GZIP);
+/* }}} */
+/* {{{ proto binary gzcompress(binary data[, int level = -1[, int encoding = ZLIB_ENCODING_DEFLATE])
+ Encode data with the zlib encoding */
+PHP_ZLIB_ENCODE_FUNC(gzcompress, PHP_ZLIB_ENCODING_DEFLATE);
+/* }}} */
+/* {{{ proto binary gzinflate(binary data[, int max_decoded_len])
+ Decode raw deflate encoded data */
+PHP_ZLIB_DECODE_FUNC(gzinflate, PHP_ZLIB_ENCODING_RAW);
+/* }}} */
+/* {{{ proto binary gzdecode(binary data[, int max_decoded_len])
+ Decode gzip encoded data */
+PHP_ZLIB_DECODE_FUNC(gzdecode, PHP_ZLIB_ENCODING_GZIP);
+/* }}} */
+/* {{{ proto binary gzuncompress(binary data[, int max_decoded_len])
+ Decode zlib encoded data */
+PHP_ZLIB_DECODE_FUNC(gzuncompress, PHP_ZLIB_ENCODING_DEFLATE);
+/* }}} */
- s2 = (char *) emalloc(stream.avail_out);
- if (!s2) {
- RETURN_FALSE;
- }
+#ifdef COMPILE_DL_ZLIB
+ZEND_GET_MODULE(php_zlib)
+#endif
- stream.next_out = s2;
+/* {{{ arginfo */
+ZEND_BEGIN_ARG_INFO(arginfo_zlib_get_coding_type, 0)
+ZEND_END_ARG_INFO()
- /* init with -MAX_WBITS disables the zlib internal headers */
- status = deflateInit2(&stream, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, 0);
- if (status == Z_OK) {
- status = deflate(&stream, Z_FINISH);
- if (status != Z_STREAM_END) {
- deflateEnd(&stream);
- if (status == Z_OK) {
- status = Z_BUF_ERROR;
- }
- } else {
- status = deflateEnd(&stream);
- }
- }
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzfile, 0, 0, 1)
+ ZEND_ARG_INFO(0, filename)
+ ZEND_ARG_INFO(0, use_include_path)
+ZEND_END_ARG_INFO()
- if (status == Z_OK) {
- s2 = erealloc(s2,stream.total_out + 1); /* resize to buffer to the "right" size */
- s2[ stream.total_out ] = '\0';
- RETURN_STRINGL(s2, stream.total_out, 0);
- } else {
- efree(s2);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status));
- RETURN_FALSE;
- }
-}
-/* }}} */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzopen, 0, 0, 2)
+ ZEND_ARG_INFO(0, filename)
+ ZEND_ARG_INFO(0, mode)
+ ZEND_ARG_INFO(0, use_include_path)
+ZEND_END_ARG_INFO()
-/* {{{ proto string gzinflate(string data [, int length])
- Unzip a gzip-compressed string */
-static PHP_FUNCTION(gzinflate)
-{
- int data_len, status;
- unsigned int factor=1, maxfactor=16;
- long limit = 0;
- unsigned long plength=0, length;
- char *data, *s1=NULL, *s2=NULL;
- z_stream stream;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &limit) == FAILURE) {
- return;
- }
+ZEND_BEGIN_ARG_INFO_EX(arginfo_readgzfile, 0, 0, 1)
+ ZEND_ARG_INFO(0, filename)
+ ZEND_ARG_INFO(0, use_include_path)
+ZEND_END_ARG_INFO()
- if (!data_len) {
- RETURN_FALSE;
- }
+ZEND_BEGIN_ARG_INFO_EX(arginfo_zlib_encode, 0, 0, 2)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, encoding)
+ ZEND_ARG_INFO(0, level)
+ZEND_END_ARG_INFO()
- if (limit < 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "length (%ld) must be greater or equal zero", limit);
- RETURN_FALSE;
- }
- plength = limit;
-
- stream.zalloc = php_zlib_alloc;
- stream.zfree = php_zlib_free;
- stream.opaque = Z_NULL;
- stream.avail_in = data_len + 1; /* there is room for \0 */
- stream.next_in = (Bytef *) data;
- stream.total_out = 0;
-
- /* init with -MAX_WBITS disables the zlib internal headers */
- status = inflateInit2(&stream, -MAX_WBITS);
- if (status != Z_OK) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status));
- RETURN_FALSE;
- }
+ZEND_BEGIN_ARG_INFO_EX(arginfo_zlib_decode, 0, 0, 1)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, max_decoded_len)
+ZEND_END_ARG_INFO()
- /*
- stream.avail_out wants to know the output data length
- if none was given as a parameter
- we try from input length * 2 up to input length * 2^15
- doubling it whenever it wasn't big enough
- that should be enaugh for all real life cases
- */
- do {
- length = plength ? plength : (unsigned long)data_len * (1 << factor++);
- s2 = (char *) erealloc(s1, length);
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzdeflate, 0, 0, 1)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, level)
+ ZEND_ARG_INFO(0, encoding)
+ZEND_END_ARG_INFO()
- if (!s2) {
- if (s1) {
- efree(s1);
- }
- inflateEnd(&stream);
- RETURN_FALSE;
- }
- s1 = s2;
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzencode, 0, 0, 1)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, level)
+ ZEND_ARG_INFO(0, encoding)
+ZEND_END_ARG_INFO()
- stream.next_out = (Bytef *) &s2[stream.total_out];
- stream.avail_out = length - stream.total_out;
- status = inflate(&stream, Z_NO_FLUSH);
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzcompress, 0, 0, 1)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, level)
+ ZEND_ARG_INFO(0, encoding)
+ZEND_END_ARG_INFO()
- } while ((Z_BUF_ERROR == status || (Z_OK == status && stream.avail_in)) && !plength && factor < maxfactor);
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzinflate, 0, 0, 1)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, max_decoded_len)
+ZEND_END_ARG_INFO()
- inflateEnd(&stream);
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzdecode, 0, 0, 1)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, max_decoded_len)
+ZEND_END_ARG_INFO()
- if ((plength && Z_OK == status) || factor >= maxfactor) {
- status = Z_MEM_ERROR;
- }
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzuncompress, 0, 0, 1)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, max_decoded_len)
+ZEND_END_ARG_INFO()
+/* }}} */
- if (Z_STREAM_END == status || Z_OK == status) {
- s2 = erealloc(s2, stream.total_out + 1); /* room for \0 */
- s2[ stream.total_out ] = '\0';
- RETURN_STRINGL(s2, stream.total_out, 0);
- } else {
- efree(s2);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status));
- RETURN_FALSE;
- }
-}
+/* {{{ php_zlib_functions[] */
+static const zend_function_entry php_zlib_functions[] = {
+ PHP_FE(readgzfile, arginfo_readgzfile)
+ PHP_FALIAS(gzrewind, rewind, NULL)
+ PHP_FALIAS(gzclose, fclose, NULL)
+ PHP_FALIAS(gzeof, feof, NULL)
+ PHP_FALIAS(gzgetc, fgetc, NULL)
+ PHP_FALIAS(gzgets, fgets, NULL)
+ PHP_FALIAS(gzgetss, fgetss, NULL)
+ PHP_FALIAS(gzread, fread, NULL)
+ PHP_FE(gzopen, arginfo_gzopen)
+ PHP_FALIAS(gzpassthru, fpassthru, NULL)
+ PHP_FALIAS(gzseek, fseek, NULL)
+ PHP_FALIAS(gztell, ftell, NULL)
+ PHP_FALIAS(gzwrite, fwrite, NULL)
+ PHP_FALIAS(gzputs, fwrite, NULL)
+ PHP_FE(gzfile, NULL)
+ PHP_FE(gzcompress, arginfo_gzcompress)
+ PHP_FE(gzuncompress, arginfo_gzuncompress)
+ PHP_FE(gzdeflate, arginfo_gzdeflate)
+ PHP_FE(gzinflate, arginfo_gzinflate)
+ PHP_FE(gzencode, arginfo_gzencode)
+ PHP_FE(gzdecode, arginfo_gzdecode)
+ PHP_FE(zlib_encode, arginfo_zlib_encode)
+ PHP_FE(zlib_decode, arginfo_zlib_decode)
+ PHP_FE(zlib_get_coding_type, arginfo_zlib_get_coding_type)
+ {NULL, NULL, NULL}
+};
/* }}} */
-/* {{{ proto string zlib_get_coding_type(void)
- Returns the coding type used for output compression */
-static PHP_FUNCTION(zlib_get_coding_type)
+/* {{{ OnUpdate_zlib_output_compression */
+static PHP_INI_MH(OnUpdate_zlib_output_compression)
{
- switch (ZLIBG(compression_coding)) {
- case CODING_GZIP:
- RETURN_STRINGL("gzip", sizeof("gzip") - 1, 1);
+ int status, int_value;
+ char *ini_value;
- case CODING_DEFLATE:
- RETURN_STRINGL("deflate", sizeof("deflate") - 1, 1);
+ if (new_value == NULL) {
+ return FAILURE;
}
- 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)
-{
- Bytef *buffer;
- uInt prev_outlen, outlen;
- int err;
- int start_offset = ((do_start && ZLIBG(compression_coding) == CODING_GZIP) ? 10 : 0);
- int end_offset = (do_end ? 8 : 0);
-
- outlen = (uint) (str_length + (str_length / PHP_ZLIB_MODIFIER) + 12 + 1); /* leave some room for a trailing \0 */
- if ((outlen + start_offset + end_offset) > *p_buffer_len) {
- buffer = (Bytef *) emalloc(outlen + start_offset + end_offset);
- } else {
- buffer = *p_buffer;
+ 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 = "1";
+ new_value_length = sizeof("1");
}
- ZLIBG(stream).next_out = buffer + start_offset;
- ZLIBG(stream).avail_out = outlen;
-
- err = deflate(&ZLIBG(stream), Z_SYNC_FLUSH);
- while (err == Z_OK && !ZLIBG(stream).avail_out) {
- prev_outlen = outlen;
- outlen *= 3;
- if ((outlen + start_offset + end_offset) > *p_buffer_len) {
- buffer = erealloc(buffer, outlen + start_offset + end_offset);
- }
-
- ZLIBG(stream).next_out = buffer + start_offset + prev_outlen;
- ZLIBG(stream).avail_out = prev_outlen * 2;
-
- err = deflate(&ZLIBG(stream), Z_SYNC_FLUSH);
- }
+ int_value = zend_atoi(new_value, new_value_length);
+ ini_value = zend_ini_string("output_handler", sizeof("output_handler"), 0);
- if (do_end) {
- err = deflate(&ZLIBG(stream), Z_FINISH);
- buffer[outlen + start_offset - ZLIBG(stream).avail_out] = '\0';
+ if (ini_value && *ini_value && int_value) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_CORE_ERROR, "Cannot use both zlib.output_compression and output_handler together!!");
+ return FAILURE;
}
-
- *p_buffer = buffer;
- *p_buffer_len = outlen - ZLIBG(stream).avail_out;
-
- return err;
-}
-/* }}} */
-
-/* {{{ php_deflate_string
- */
-static int php_deflate_string(const char *str, uint str_length, char **newstr, uint *new_length, zend_bool do_start, zend_bool do_end TSRMLS_DC)
-{
- int err;
-
- if (do_start) {
- ZLIBG(stream).zalloc = php_zlib_alloc;
- ZLIBG(stream).zfree = php_zlib_free;
- ZLIBG(stream).opaque = Z_NULL;
-
- switch (ZLIBG(compression_coding)) {
- case CODING_GZIP:
- /* windowBits is passed < 0 to suppress zlib header & trailer */
- if (deflateInit2(&ZLIBG(stream), ZLIBG(output_compression_level), Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY) != Z_OK) {
- /* TODO: print out error */
- return FAILURE;
- }
-
- ZLIBG(crc) = crc32(0L, Z_NULL, 0);
- break;
-
- case CODING_DEFLATE:
- if (deflateInit(&ZLIBG(stream), ZLIBG(output_compression_level)) != Z_OK) {
- /* TODO: print out error */
- return FAILURE;
- }
- break;
+ if (stage == PHP_INI_STAGE_RUNTIME) {
+ status = php_output_get_status(TSRMLS_C);
+ if (status & PHP_OUTPUT_SENT) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_compression - headers already sent");
+ return FAILURE;
+ } else if ((status & PHP_OUTPUT_WRITTEN) && int_value) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot enable zlib.output_compression - there has already been output");
+ return FAILURE;
}
}
- ZLIBG(stream).next_in = (Bytef *) str;
- ZLIBG(stream).avail_in = (uInt) str_length;
-
- if (ZLIBG(compression_coding) == CODING_GZIP) {
- ZLIBG(crc) = crc32(ZLIBG(crc), (const Bytef *) str, str_length);
- }
+ status = OnUpdateLong(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
- err = php_do_deflate(str_length, (Bytef **) newstr, new_length, do_start, do_end TSRMLS_CC);
- /* TODO: error handling (err may be Z_STREAM_ERROR, Z_BUF_ERROR, ?) */
-
- if (do_start && ZLIBG(compression_coding) == CODING_GZIP) {
- /* Write a very simple .gz header: */
- (*newstr)[0] = gz_magic[0];
- (*newstr)[1] = gz_magic[1];
- (*newstr)[2] = Z_DEFLATED;
- (*newstr)[3] = (*newstr)[4] = (*newstr)[5] = (*newstr)[6] = (*newstr)[7] = (*newstr)[8] = 0;
- (*newstr)[9] = OS_CODE;
- *new_length += 10;
- }
- if (do_end) {
- if (ZLIBG(compression_coding) == CODING_GZIP) {
- char *trailer = (*newstr) + (*new_length);
-
- /* write crc & stream.total_in in LSB order */
- trailer[0] = (char) ZLIBG(crc) & 0xFF;
- trailer[1] = (char) (ZLIBG(crc) >> 8) & 0xFF;
- trailer[2] = (char) (ZLIBG(crc) >> 16) & 0xFF;
- trailer[3] = (char) (ZLIBG(crc) >> 24) & 0xFF;
- trailer[4] = (char) ZLIBG(stream).total_in & 0xFF;
- trailer[5] = (char) (ZLIBG(stream).total_in >> 8) & 0xFF;
- trailer[6] = (char) (ZLIBG(stream).total_in >> 16) & 0xFF;
- trailer[7] = (char) (ZLIBG(stream).total_in >> 24) & 0xFF;
- trailer[8] = '\0';
- *new_length += 8;
+ if (stage == PHP_INI_STAGE_RUNTIME && int_value) {
+ if (!php_output_handler_started(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME) TSRMLS_CC)) {
+ php_zlib_output_compression_start(TSRMLS_C);
}
- deflateEnd(&ZLIBG(stream));
}
- return SUCCESS;
+ return status;
}
/* }}} */
-/* {{{ proto string gzencode(string data [, int level [, int encoding_mode]])
- GZ encode a string */
-static PHP_FUNCTION(gzencode)
+/* {{{ OnUpdate_zlib_output_handler */
+static PHP_INI_MH(OnUpdate_zlib_output_handler)
{
- char *data, *s2;
- int data_len;
- long level = Z_DEFAULT_COMPRESSION, coding = CODING_GZIP;
- int status;
- z_stream stream;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &data, &data_len, &level, &coding) == FAILURE) {
- return;
- }
-
- if ((level < -1) || (level > 9)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "compression level(%ld) must be within -1..9", level);
- RETURN_FALSE;
- }
-
- if ((coding != CODING_GZIP) && (coding != CODING_DEFLATE)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "encoding mode must be FORCE_GZIP or FORCE_DEFLATE");
- RETURN_FALSE;
- }
-
- stream.zalloc = php_zlib_alloc;
- stream.zfree = php_zlib_free;
- stream.opaque = Z_NULL;
-
- stream.next_in = (Bytef *) data;
- stream.avail_in = data_len;
-
- stream.avail_out = stream.avail_in + (stream.avail_in / PHP_ZLIB_MODIFIER) + 15 + 1; /* room for \0 */
- s2 = (char *) emalloc(stream.avail_out + GZIP_HEADER_LENGTH + (coding == CODING_GZIP ? GZIP_FOOTER_LENGTH : 0));
-
- /* add gzip file header */
- s2[0] = gz_magic[0];
- s2[1] = gz_magic[1];
- s2[2] = Z_DEFLATED;
- s2[3] = s2[4] = s2[5] = s2[6] = s2[7] = s2[8] = 0; /* time set to 0 */
- s2[9] = OS_CODE;
-
- stream.next_out = &(s2[GZIP_HEADER_LENGTH]);
-
- switch (coding) {
- case CODING_GZIP:
- /* windowBits is passed < 0 to suppress zlib header & trailer */
- if ((status = deflateInit2(&stream, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) != Z_OK) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status));
- RETURN_FALSE;
- }
-
- break;
- case CODING_DEFLATE:
- if ((status = deflateInit(&stream, level)) != Z_OK) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status));
- RETURN_FALSE;
- }
- break;
- }
-
- status = deflate(&stream, Z_FINISH);
- if (status != Z_STREAM_END) {
- deflateEnd(&stream);
- if (status == Z_OK) {
- status = Z_BUF_ERROR;
- }
- } else {
- status = deflateEnd(&stream);
+ if (stage == PHP_INI_STAGE_RUNTIME && (php_output_get_status(TSRMLS_C) & PHP_OUTPUT_SENT)) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_handler - headers already sent");
+ return FAILURE;
}
- if (status == Z_OK) {
- /* resize to buffer to the "right" size */
- s2 = erealloc(s2, stream.total_out + GZIP_HEADER_LENGTH + (coding == CODING_GZIP ? GZIP_FOOTER_LENGTH : 0) + 1);
-
- if (coding == CODING_GZIP) {
- char *trailer = s2 + (stream.total_out + GZIP_HEADER_LENGTH);
- uLong crc = crc32(0L, Z_NULL, 0);
-
- crc = crc32(crc, (const Bytef *) data, data_len);
-
- /* write crc & stream.total_in in LSB order */
- trailer[0] = (char) crc & 0xFF;
- trailer[1] = (char) (crc >> 8) & 0xFF;
- trailer[2] = (char) (crc >> 16) & 0xFF;
- trailer[3] = (char) (crc >> 24) & 0xFF;
- trailer[4] = (char) stream.total_in & 0xFF;
- trailer[5] = (char) (stream.total_in >> 8) & 0xFF;
- trailer[6] = (char) (stream.total_in >> 16) & 0xFF;
- trailer[7] = (char) (stream.total_in >> 24) & 0xFF;
- trailer[8] = '\0';
- } else {
- s2[stream.total_out + GZIP_HEADER_LENGTH + (coding == CODING_GZIP ? GZIP_FOOTER_LENGTH : 0)] = '\0';
- }
- RETURN_STRINGL(s2, stream.total_out + GZIP_HEADER_LENGTH + (coding == CODING_GZIP ? GZIP_FOOTER_LENGTH : 0), 0);
- } else {
- efree(s2);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status));
- RETURN_FALSE;
- }
+ return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
}
/* }}} */
-
-/* {{{ php_ob_gzhandler_check
- */
-int php_ob_gzhandler_check(TSRMLS_D)
-{
- /* check for wrong usages */
- if (OG(ob_nesting_level > 0)) {
- if (php_ob_handler_used("ob_gzhandler" TSRMLS_CC)) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "output handler 'ob_gzhandler' cannot be used twice");
- return FAILURE;
- }
- if (php_ob_handler_used("mb_output_handler" TSRMLS_CC)) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "output handler 'ob_gzhandler' cannot be used after 'mb_output_handler'");
- return FAILURE;
- }
- if (php_ob_handler_used("URL-Rewriter" TSRMLS_CC)) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "output handler 'ob_gzhandler' cannot be used after 'URL-Rewriter'");
- return FAILURE;
- }
- if (php_ob_init_conflict("ob_gzhandler", "zlib output compression" TSRMLS_CC)) {
- return FAILURE;
- }
- }
-
- return SUCCESS;
-}
+
+/* {{{ INI */
+PHP_INI_BEGIN()
+ 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, OnUpdateLong, output_compression_level, zend_zlib_globals, zlib_globals)
+ STD_PHP_INI_ENTRY("zlib.output_handler", "", PHP_INI_ALL, OnUpdate_zlib_output_handler, output_handler, zend_zlib_globals, zlib_globals)
+PHP_INI_END()
/* }}} */
-/* {{{ proto string ob_gzhandler(string str, int mode)
- Encode str based on accept-encoding setting - designed to be called from ob_start() */
-static PHP_FUNCTION(ob_gzhandler)
+/* {{{ PHP_MINIT_FUNCTION */
+static PHP_MINIT_FUNCTION(zlib)
{
- char *string;
- int string_len;
- long mode;
- zval **a_encoding;
- zend_bool return_original = 0;
- zend_bool do_start, do_end;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &string, &string_len, &mode) == FAILURE) {
- return;
- }
-
- if (ZLIBG(ob_gzhandler_status) == -1) {
- RETURN_FALSE;
- }
-
- zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
-
- if (!PG(http_globals)[TRACK_VARS_SERVER]
- || zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING"), (void **) &a_encoding) == FAILURE
- ) {
- ZLIBG(ob_gzhandler_status) = -1;
- RETURN_FALSE;
- }
+ php_register_url_stream_wrapper("compress.zlib", &php_stream_gzip_wrapper TSRMLS_CC);
+ php_stream_filter_register_factory("zlib.*", &php_zlib_filter_factory TSRMLS_CC);
- 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))) {
- ZLIBG(compression_coding) = CODING_GZIP;
- } else if (php_memnstr(Z_STRVAL_PP(a_encoding), "deflate", 7, Z_STRVAL_PP(a_encoding) + Z_STRLEN_PP(a_encoding))) {
- ZLIBG(compression_coding) = CODING_DEFLATE;
- } else {
- ZLIBG(ob_gzhandler_status) = -1;
- RETURN_FALSE;
- }
+ php_output_handler_alias_register(ZEND_STRL("ob_gzhandler"), php_zlib_output_handler_init);
+ php_output_handler_conflict_register(ZEND_STRL("ob_gzhandler"), php_zlib_output_conflict_check);
+ php_output_handler_conflict_register(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME), php_zlib_output_conflict_check);
- do_start = ((mode & PHP_OUTPUT_HANDLER_START) ? 1 : 0);
- do_end = ((mode & PHP_OUTPUT_HANDLER_END) ? 1 : 0);
- Z_STRVAL_P(return_value) = NULL;
- Z_STRLEN_P(return_value) = 0;
+ REGISTER_LONG_CONSTANT("FORCE_GZIP", PHP_ZLIB_ENCODING_GZIP, CONST_CS|CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("FORCE_DEFLATE", PHP_ZLIB_ENCODING_DEFLATE, CONST_CS|CONST_PERSISTENT);
- if (php_deflate_string(string, string_len, &Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value), do_start, do_end TSRMLS_CC) == SUCCESS) {
- Z_TYPE_P(return_value) = IS_STRING;
- if (do_start) {
- switch (ZLIBG(compression_coding)) {
- case CODING_GZIP:
- if (sapi_add_header("Content-Encoding: gzip", sizeof("Content-Encoding: gzip") - 1, 1) == FAILURE) {
- return_original = 1;
- }
- if (sapi_add_header_ex("Vary: Accept-Encoding", sizeof("Vary: Accept-Encoding") - 1, 1, 0 TSRMLS_CC)==FAILURE) {
- return_original = 1;
- }
- break;
- case CODING_DEFLATE:
- if (sapi_add_header("Content-Encoding: deflate", sizeof("Content-Encoding: deflate") - 1, 1) == FAILURE) {
- return_original = 1;
- }
- if (sapi_add_header_ex("Vary: Accept-Encoding", sizeof("Vary: Accept-Encoding") - 1, 1, 0 TSRMLS_CC)==FAILURE) {
- return_original = 1;
- }
- break;
- default:
- return_original = 1;
- break;
- }
- }
-
- if (return_original) {
- zval_dtor(return_value);
- }
-
- } else {
- return_original = 1;
- }
+ REGISTER_LONG_CONSTANT("ZLIB_ENCODING_RAW", PHP_ZLIB_ENCODING_RAW, CONST_CS|CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("ZLIB_ENCODING_GZIP", PHP_ZLIB_ENCODING_GZIP, CONST_CS|CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("ZLIB_ENCODING_DEFLATE", PHP_ZLIB_ENCODING_DEFLATE, CONST_CS|CONST_PERSISTENT);
+ REGISTER_INI_ENTRIES();
- if (return_original) {
- /* return the original string */
- RETURN_STRINGL(string, string_len, 1);
- }
+ return SUCCESS;
}
/* }}} */
-/* {{{ php_gzip_output_handler
- */
-static void php_gzip_output_handler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC)
+/* {{{ PHP_MSHUTDOWN_FUNCTION */
+static PHP_MSHUTDOWN_FUNCTION(zlib)
{
- zend_bool do_start, do_end;
+ php_unregister_url_stream_wrapper("zlib" TSRMLS_CC);
+ php_stream_filter_unregister_factory("zlib.*" TSRMLS_CC);
- if (!ZLIBG(output_compression) || SG(sapi_headers).http_response_code == 204 || SG(sapi_headers).http_response_code == 304) {
- *handled_output = NULL;
- } else {
- do_start = (mode & PHP_OUTPUT_HANDLER_START ? 1 : 0);
- do_end = (mode & PHP_OUTPUT_HANDLER_END ? 1 : 0);
-
- if (do_start) {
- if (!SG(headers_sent) && !SG(request_info).no_headers) {
- switch (ZLIBG(compression_coding)) {
- case CODING_GZIP:
- sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1 TSRMLS_CC);
- break;
- case CODING_DEFLATE:
- sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1 TSRMLS_CC);
- break;
- }
- sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0 TSRMLS_CC);
- } else {
- /* Disable compression if headers can not be set (Fix for bug #49816) */
- ZLIBG(output_compression) = 0;
- *handled_output = NULL;
- return;
- }
- }
+ UNREGISTER_INI_ENTRIES();
- if (php_deflate_string(output, output_len, handled_output, handled_output_len, do_start, do_end TSRMLS_CC) != SUCCESS) {
- zend_error(E_ERROR, "Compression failed");
- }
- }
+ return SUCCESS;
}
/* }}} */
-/* {{{ php_enable_output_compression
- */
-static int php_enable_output_compression(int buffer_size TSRMLS_DC)
+/* {{{ PHP_RINIT_FUNCTION */
+static PHP_RINIT_FUNCTION(zlib)
{
- zval **a_encoding;
-
- zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
-
- if (!PG(http_globals)[TRACK_VARS_SERVER]
- || zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING"), (void **) &a_encoding) == FAILURE
- ) {
- return FAILURE;
- }
-
- 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))) {
- ZLIBG(compression_coding) = CODING_GZIP;
- } else if (php_memnstr(Z_STRVAL_PP(a_encoding), "deflate", 7, Z_STRVAL_PP(a_encoding) + Z_STRLEN_PP(a_encoding))) {
- ZLIBG(compression_coding) = CODING_DEFLATE;
- } else {
- return FAILURE;
- }
+ ZLIBG(compression_coding) = 0;
- php_ob_set_internal_handler(php_gzip_output_handler, (uint)buffer_size, "zlib output compression", 0 TSRMLS_CC);
+ php_zlib_output_compression_start(TSRMLS_C);
- if (ZLIBG(output_handler) && strlen(ZLIBG(output_handler))) {
- php_start_ob_buffer_named(ZLIBG(output_handler), 0, 1 TSRMLS_CC);
- }
return SUCCESS;
}
/* }}} */
-/* {{{ php_zlib_output_compression_start() */
-static int php_zlib_output_compression_start(TSRMLS_D)
+/* {{{ PHP_MINFO_FUNCTION */
+static PHP_MINFO_FUNCTION(zlib)
{
- switch (ZLIBG(output_compression)) {
- case 0:
- break;
- case 1:
- ZLIBG(output_compression) = 4096;
- /* break omitted intentionally */
- default:
- /* ZLIBG(compression_coding) should be 0 when zlib compression hasn't been started yet.. */
- if (ZLIBG(compression_coding) == 0) {
- return php_enable_output_compression(ZLIBG(output_compression) TSRMLS_CC);
- }
- }
- return SUCCESS;
+ php_info_print_table_start();
+ php_info_print_table_header(2, "ZLib Support", "enabled");
+ php_info_print_table_row(2, "Stream Wrapper", "compress.zlib://");
+ php_info_print_table_row(2, "Stream Filter", "zlib.inflate, zlib.deflate");
+ php_info_print_table_row(2, "Compiled Version", ZLIB_VERSION);
+ php_info_print_table_row(2, "Linked Version", (char *) zlibVersion());
+ php_info_print_table_end();
+
+ DISPLAY_INI_ENTRIES();
}
/* }}} */
+/* {{{ php_zlib_module_entry */
+zend_module_entry php_zlib_module_entry = {
+ STANDARD_MODULE_HEADER,
+ "zlib",
+ php_zlib_functions,
+ PHP_MINIT(zlib),
+ PHP_MSHUTDOWN(zlib),
+ PHP_RINIT(zlib),
+ NULL,
+ PHP_MINFO(zlib),
+ "2.0",
+ PHP_MODULE_GLOBALS(zlib),
+ NULL,
+ NULL,
+ NULL,
+ STANDARD_MODULE_PROPERTIES_EX
+};
+/* }}} */
+
/*
* Local variables:
* tab-width: 4
diff --git a/ext/zlib/zlib_filter.c b/ext/zlib/zlib_filter.c
index 4990cf0..0f6c056 100644
--- a/ext/zlib/zlib_filter.c
+++ b/ext/zlib/zlib_filter.c
@@ -80,8 +80,11 @@ static php_stream_filter_status_t php_zlib_inflate_filter(
while (buckets_in->head) {
size_t bin = 0, desired;
+ bucket = buckets_in->head;
+
bucket = php_stream_bucket_make_writeable(buckets_in->head TSRMLS_CC);
- while (bin < bucket->buflen) {
+
+ while (bin < (unsigned int) bucket->buflen) {
if (data->finished) {
consumed += bucket->buflen;
@@ -107,7 +110,6 @@ static php_stream_filter_status_t php_zlib_inflate_filter(
desired -= data->strm.avail_in; /* desired becomes what we consumed this round through */
data->strm.next_in = data->inbuf;
data->strm.avail_in = 0;
- consumed += desired;
bin += desired;
if (data->strm.avail_out < data->outbuf_len) {
@@ -123,7 +125,9 @@ static php_stream_filter_status_t php_zlib_inflate_filter(
php_stream_bucket_delref(bucket TSRMLS_CC);
return PSFS_PASS_ON;
}
+
}
+ consumed += bucket->buflen;
php_stream_bucket_delref(bucket TSRMLS_CC);
}
@@ -202,9 +206,11 @@ static php_stream_filter_status_t php_zlib_deflate_filter(
while (buckets_in->head) {
size_t bin = 0, desired;
- bucket = php_stream_bucket_make_writeable(buckets_in->head TSRMLS_CC);
+ bucket = buckets_in->head;
+
+ bucket = php_stream_bucket_make_writeable(bucket TSRMLS_CC);
- while (bin < bucket->buflen) {
+ while (bin < (unsigned int) bucket->buflen) {
desired = bucket->buflen - bin;
if (desired > data->inbuf_len) {
desired = data->inbuf_len;
@@ -221,7 +227,6 @@ static php_stream_filter_status_t php_zlib_deflate_filter(
desired -= data->strm.avail_in; /* desired becomes what we consumed this round through */
data->strm.next_in = data->inbuf;
data->strm.avail_in = 0;
- consumed += desired;
bin += desired;
if (data->strm.avail_out < data->outbuf_len) {
@@ -235,6 +240,7 @@ static php_stream_filter_status_t php_zlib_deflate_filter(
exit_status = PSFS_PASS_ON;
}
}
+ consumed += bucket->buflen;
php_stream_bucket_delref(bucket TSRMLS_CC);
}
@@ -258,6 +264,7 @@ static php_stream_filter_status_t php_zlib_deflate_filter(
if (bytes_consumed) {
*bytes_consumed = consumed;
}
+
return exit_status;
}
@@ -291,7 +298,7 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f
/* Create this filter */
data = pecalloc(1, sizeof(php_zlib_filter_data), persistent);
if (!data) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zd bytes.", sizeof(php_zlib_filter_data));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zd bytes", sizeof(php_zlib_filter_data));
return NULL;
}
@@ -303,14 +310,14 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f
data->strm.avail_out = data->outbuf_len = data->inbuf_len = 2048;
data->strm.next_in = data->inbuf = (Bytef *) pemalloc(data->inbuf_len, persistent);
if (!data->inbuf) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zd bytes.", data->inbuf_len);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zd bytes", data->inbuf_len);
pefree(data, persistent);
return NULL;
}
data->strm.avail_in = 0;
data->strm.next_out = data->outbuf = (Bytef *) pemalloc(data->outbuf_len, persistent);
if (!data->outbuf) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zd bytes.", data->outbuf_len);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zd bytes", data->outbuf_len);
pefree(data->inbuf, persistent);
pefree(data, persistent);
return NULL;
@@ -409,7 +416,7 @@ factory_setlevel:
}
break;
default:
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid filter parameter, ignored.");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid filter parameter, ignored");
}
}
status = deflateInit2(&(data->strm), level, Z_DEFLATED, windowBits, memLevel, 0);
diff --git a/ext/zlib/zlib_fopen_wrapper.c b/ext/zlib/zlib_fopen_wrapper.c
index 8970c55..c8b4263 100644
--- a/ext/zlib/zlib_fopen_wrapper.c
+++ b/ext/zlib/zlib_fopen_wrapper.c
@@ -96,7 +96,7 @@ static int php_gziop_flush(php_stream *stream TSRMLS_DC)
return gzflush(self->gz_file, Z_SYNC_FLUSH);
}
-static php_stream_ops php_stream_gzio_ops = {
+php_stream_ops php_stream_gzio_ops = {
php_gziop_write, php_gziop_read,
php_gziop_close, php_gziop_flush,
"ZLIB",
diff --git a/main/SAPI.c b/main/SAPI.c
index 22012d6..ca54b3d 100644
--- a/main/SAPI.c
+++ b/main/SAPI.c
@@ -532,8 +532,8 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
int http_response_code;
if (SG(headers_sent) && !SG(request_info).no_headers) {
- char *output_start_filename = php_get_output_start_filename(TSRMLS_C);
- int output_start_lineno = php_get_output_start_lineno(TSRMLS_C);
+ char *output_start_filename = php_output_get_start_filename(TSRMLS_C);
+ int output_start_lineno = php_output_get_start_lineno(TSRMLS_C);
if (output_start_filename) {
sapi_module.sapi_error(E_WARNING, "Cannot modify header information - headers already sent by (output started at %s:%d)",
diff --git a/main/main.c b/main/main.c
index f975c7f..9106b91 100644
--- a/main/main.c
+++ b/main/main.c
@@ -972,14 +972,7 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
efree(log_buffer);
}
- if (PG(display_errors)
- && ((module_initialized && !PG(during_request_startup))
- || (PG(display_startup_errors)
- && (OG(php_body_write)==php_default_output_func || OG(php_body_write)==php_ub_body_write_no_header || OG(php_body_write)==php_ub_body_write)
- )
- )
- ) {
-
+ if (PG(display_errors) && ((module_initialized && !PG(during_request_startup)) || (PG(display_startup_errors)))) {
if (PG(xmlrpc_errors)) {
php_printf("<?xml version=\"1.0\"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>%ld</int></value></member><member><name>faultString</name><value><string>%s:%s in %s on line %d</string></value></member></struct></value></fault></methodResponse>", PG(xmlrpc_error_number), error_type_str, buffer, error_filename, error_lineno);
} else {
@@ -1456,15 +1449,16 @@ int php_request_startup(TSRMLS_D)
}
if (PG(output_handler) && PG(output_handler)[0]) {
- php_start_ob_buffer_named(PG(output_handler), 0, 1 TSRMLS_CC);
+ zval *oh;
+
+ MAKE_STD_ZVAL(oh);
+ ZVAL_STRING(oh, PG(output_handler), 1);
+ php_output_start_user(oh, 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
+ zval_ptr_dtor(&oh);
} else if (PG(output_buffering)) {
- if (PG(output_buffering)>1) {
- php_start_ob_buffer(NULL, PG(output_buffering), 1 TSRMLS_CC);
- } else {
- php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC);
- }
+ php_output_start_user(NULL, PG(output_buffering) > 1 ? PG(output_buffering) : 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
} else if (PG(implicit_flush)) {
- php_start_implicit_flush(TSRMLS_C);
+ php_output_set_implicit_flush(1 TSRMLS_CC);
}
/* We turn this off in php_execute_script() */
@@ -1500,7 +1494,6 @@ int php_request_startup(TSRMLS_D)
zend_try {
PG(during_request_startup) = 1;
- php_output_activate(TSRMLS_C);
if (PG(expose_php)) {
sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
}
@@ -1626,14 +1619,22 @@ void php_request_shutdown(void *dummy)
/* 3. Flush all output buffers */
zend_try {
zend_bool send_buffer = SG(request_info).headers_only ? 0 : 1;
+
if (CG(unclean_shutdown) && PG(last_error_type) == E_ERROR &&
- OG(ob_nesting_level) && !OG(active_ob_buffer).chunk_size && PG(memory_limit) < zend_memory_usage(1 TSRMLS_CC)) {
+ PG(memory_limit) < zend_memory_usage(1 TSRMLS_CC)
+ ) {
send_buffer = 0;
}
- php_end_ob_buffers(send_buffer TSRMLS_CC);
+
+ if (!send_buffer) {
+ php_output_discard_all(TSRMLS_C);
+ } else {
+ php_output_end_all(TSRMLS_C);
+ }
+ php_output_deactivate(TSRMLS_C);
} zend_end_try();
- /* 4. Send the set HTTP headers (note: This must be done AFTER php_end_ob_buffers() !!) */
+ /* 4. Send the set HTTP headers (note: This must be done AFTER php_output_discard_all() / php_output_end_all() !!) */
zend_try {
sapi_send_headers(TSRMLS_C);
} zend_end_try();
@@ -1720,12 +1721,12 @@ PHPAPI void php_com_initialize(TSRMLS_D)
}
/* }}} */
-/* {{{ php_body_write_wrapper
+/* {{{ php_output_wrapper
*/
-static int php_body_write_wrapper(const char *str, uint str_length)
+static int php_output_wrapper(const char *str, uint str_length)
{
TSRMLS_FETCH();
- return php_body_write(str, str_length TSRMLS_CC);
+ return php_output_write(str, str_length TSRMLS_CC);
}
/* }}} */
@@ -1872,7 +1873,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
zuf.error_function = php_error_cb;
zuf.printf_function = php_printf;
- zuf.write_function = php_body_write_wrapper;
+ zuf.write_function = php_output_wrapper;
zuf.fopen_function = php_fopen_wrapper_for_zend;
zuf.message_handler = php_message_handler_for_zend;
zuf.block_interruptions = sapi_module.block_interruptions;
@@ -2213,17 +2214,22 @@ void php_module_shutdown(TSRMLS_D)
#ifndef ZTS
zend_ini_shutdown(TSRMLS_C);
shutdown_memory_manager(CG(unclean_shutdown), 1 TSRMLS_CC);
- core_globals_dtor(&core_globals TSRMLS_CC);
- gc_globals_dtor(TSRMLS_C);
#else
zend_ini_global_shutdown(TSRMLS_C);
- ts_free_id(core_globals_id);
#endif
+ php_output_shutdown();
php_shutdown_temporary_directory();
module_initialized = 0;
+#ifndef ZTS
+ core_globals_dtor(&core_globals TSRMLS_CC);
+ gc_globals_dtor(TSRMLS_C);
+#else
+ ts_free_id(core_globals_id);
+#endif
+
#if defined(PHP_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1400)
if (old_invalid_parameter_handler == NULL) {
_set_invalid_parameter_handler(old_invalid_parameter_handler);
@@ -2384,7 +2390,7 @@ PHPAPI void php_handle_aborted_connection(void)
TSRMLS_FETCH();
PG(connection_status) = PHP_CONNECTION_ABORTED;
- php_output_set_status(0 TSRMLS_CC);
+ php_output_set_status(PHP_OUTPUT_DISABLED TSRMLS_CC);
if (!PG(ignore_user_abort)) {
zend_bailout();
diff --git a/main/output.c b/main/output.c
index bee6ef8..e3c834d 100644
--- a/main/output.c
+++ b/main/output.c
@@ -1,4 +1,4 @@
-/*
+/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
@@ -15,744 +15,1229 @@
| Authors: Zeev Suraski <zeev@zend.com> |
| Thies C. Arntzen <thies@thieso.net> |
| Marcus Boerger <helly@php.net> |
+ | New API: Michael Wallner <mike@php.net> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
+#ifndef PHP_OUTPUT_DEBUG
+# define PHP_OUTPUT_DEBUG 0
+#endif
+#ifndef PHP_OUTPUT_NOINLINE
+# define PHP_OUTPUT_NOINLINE 0
+#endif
+
#include "php.h"
#include "ext/standard/head.h"
-#include "ext/standard/basic_functions.h"
#include "ext/standard/url_scanner_ex.h"
-#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB)
-#include "ext/zlib/php_zlib.h"
-#endif
#include "SAPI.h"
+#include "zend_stack.h"
+#include "php_output.h"
-#define OB_DEFAULT_HANDLER_NAME "default output handler"
+ZEND_DECLARE_MODULE_GLOBALS(output);
-/* output functions */
-static int php_b_body_write(const char *str, uint str_length TSRMLS_DC);
+PHPAPI const char php_output_default_handler_name[sizeof("default output handler")] = "default output handler";
+PHPAPI const char php_output_devnull_handler_name[sizeof("null output handler")] = "null output handler";
-static int php_ob_init(uint initial_size, uint block_size, zval *output_handler, uint chunk_size, zend_bool erase TSRMLS_DC);
-static void php_ob_append(const char *text, uint text_length TSRMLS_DC);
-#if 0
-static void php_ob_prepend(const char *text, uint text_length);
+#if PHP_OUTPUT_NOINLINE || PHP_OUTPUT_DEBUG
+# undef inline
+# define inline
#endif
-#ifdef ZTS
-int output_globals_id;
-#else
-php_output_globals output_globals;
-#endif
+/* {{{ aliases, conflict and reverse conflict hash tables */
+static HashTable php_output_handler_aliases;
+static HashTable php_output_handler_conflicts;
+static HashTable php_output_handler_reverse_conflicts;
+/* }}} */
+
+/* {{{ forward declarations */
+static inline int php_output_lock_error(int op TSRMLS_DC);
+static inline void php_output_op(int op, const char *str, size_t len TSRMLS_DC);
+
+static inline php_output_handler *php_output_handler_init(const char *name, size_t name_len, size_t chunk_size, int flags TSRMLS_DC);
+static inline php_output_handler_status_t php_output_handler_op(php_output_handler *handler, php_output_context *context);
+static inline int php_output_handler_append(php_output_handler *handler, const php_output_buffer *buf TSRMLS_DC);
+static inline zval *php_output_handler_status(php_output_handler *handler, zval *entry);
+
+static inline php_output_context *php_output_context_init(php_output_context *context, int op TSRMLS_DC);
+static inline void php_output_context_reset(php_output_context *context);
+static inline void php_output_context_swap(php_output_context *context);
+static inline void php_output_context_dtor(php_output_context *context);
+
+static inline int php_output_stack_pop(int flags TSRMLS_DC);
+
+static int php_output_stack_apply_op(void *h, void *c);
+static int php_output_stack_apply_clean(void *h, void *c);
+static int php_output_stack_apply_list(void *h, void *z);
+static int php_output_stack_apply_status(void *h, void *z);
-/* {{{ php_default_output_func */
-PHPAPI int php_default_output_func(const char *str, uint str_len TSRMLS_DC)
+static int php_output_handler_compat_func(void **handler_context, php_output_context *output_context);
+static int php_output_handler_default_func(void **handler_context, php_output_context *output_context);
+static int php_output_handler_devnull_func(void **handler_context, php_output_context *output_context);
+/* }}} */
+
+/* {{{ static void php_output_init_globals(zend_output_globals *G)
+ Initialize the module globals on MINIT */
+static inline void php_output_init_globals(zend_output_globals *G)
{
- fwrite(str, 1, str_len, stderr);
-/* See http://support.microsoft.com/kb/190351 */
-#ifdef PHP_WIN32
- fflush(stderr);
-#endif
- return str_len;
+ memset(G, 0, sizeof(*G));
}
/* }}} */
-/* {{{ php_output_init_globals */
-static void php_output_init_globals(php_output_globals *output_globals_p TSRMLS_DC)
+/* {{{ void php_output_startup(void)
+ Set up module globals and initalize the conflict and reverse conflict hash tables */
+PHPAPI void php_output_startup(void)
{
- OG(php_body_write) = php_default_output_func;
- OG(php_header_write) = php_default_output_func;
- OG(implicit_flush) = 0;
- OG(output_start_filename) = NULL;
- OG(output_start_lineno) = 0;
+ ZEND_INIT_MODULE_GLOBALS(output, php_output_init_globals, NULL);
+ zend_hash_init(&php_output_handler_aliases, 0, NULL, NULL, 1);
+ zend_hash_init(&php_output_handler_conflicts, 0, NULL, NULL, 1);
+ zend_hash_init(&php_output_handler_reverse_conflicts, 0, NULL, (void (*)(void *)) zend_hash_destroy, 1);
}
/* }}} */
+/* {{{ void php_output_shutdown(void)
+ Destroy module globals and the conflict and reverse conflict hash tables */
+PHPAPI void php_output_shutdown(void)
+{
+ zend_hash_destroy(&php_output_handler_aliases);
+ zend_hash_destroy(&php_output_handler_conflicts);
+ zend_hash_destroy(&php_output_handler_reverse_conflicts);
+}
+/* }}} */
-/* {{{ php_output_startup
- Start output layer */
-PHPAPI void php_output_startup(void)
+/* {{{ SUCCESS|FAILURE php_output_activate(TSRMLS_D)
+ Reset output globals and setup the output handler stack */
+PHPAPI int php_output_activate(TSRMLS_D)
{
#ifdef ZTS
- ts_allocate_id(&output_globals_id, sizeof(php_output_globals), (ts_allocate_ctor) php_output_init_globals, NULL);
-#else
- php_output_init_globals(&output_globals TSRMLS_CC);
+ memset((*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(output_globals_id)], 0, sizeof(zend_output_globals));
+#else
+ memset(&output_globals, 0, sizeof(zend_output_globals));
#endif
+
+ OG(handlers) = emalloc(sizeof(zend_stack));
+ if (SUCCESS != zend_stack_init(OG(handlers))) {
+ return FAILURE;
+ }
+
+ return SUCCESS;
}
/* }}} */
-
-/* {{{ php_output_activate
- Initilize output global for activation */
-PHPAPI void php_output_activate(TSRMLS_D)
+/* {{{ void php_output_deactivate(TSRMLS_D)
+ Destroy the output handler stack */
+PHPAPI void php_output_deactivate(TSRMLS_D)
{
- OG(php_body_write) = php_ub_body_write;
- OG(php_header_write) = sapi_module.ub_write;
- OG(ob_nesting_level) = 0;
- OG(ob_lock) = 0;
- OG(disable_output) = 0;
- OG(output_start_filename) = NULL;
- OG(output_start_lineno) = 0;
+ php_output_handler **handler = NULL;
+
+ OG(active) = NULL;
+ OG(running) = NULL;
+
+ /* release all output handlers */
+ if (OG(handlers)) {
+ while (SUCCESS == zend_stack_top(OG(handlers), (void *) &handler)) {
+ php_output_handler_free(handler TSRMLS_CC);
+ zend_stack_del_top(OG(handlers));
+ }
+ zend_stack_destroy(OG(handlers));
+ efree(OG(handlers));
+ OG(handlers) = NULL;
+ }
}
/* }}} */
-
-/* {{{ php_output_set_status
- Toggle output status. Do NOT use in application code, only in SAPIs where appropriate. */
-PHPAPI void php_output_set_status(zend_bool status TSRMLS_DC)
+/* {{{ void php_output_register_constants() */
+PHPAPI void php_output_register_constants(TSRMLS_D)
{
- OG(disable_output) = !status;
+ REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_START", PHP_OUTPUT_HANDLER_START, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_WRITE", PHP_OUTPUT_HANDLER_WRITE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_FLUSH", PHP_OUTPUT_HANDLER_FLUSH, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_CLEAN", PHP_OUTPUT_HANDLER_CLEAN, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_FINAL", PHP_OUTPUT_HANDLER_FINAL, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_CONT", PHP_OUTPUT_HANDLER_WRITE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_END", PHP_OUTPUT_HANDLER_FINAL, CONST_CS | CONST_PERSISTENT);
+
+ REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_CLEANABLE", PHP_OUTPUT_HANDLER_CLEANABLE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_FLUSHABLE", PHP_OUTPUT_HANDLER_FLUSHABLE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_REMOVABLE", PHP_OUTPUT_HANDLER_REMOVABLE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_STDFLAGS", PHP_OUTPUT_HANDLER_STDFLAGS, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_STARTED", PHP_OUTPUT_HANDLER_STARTED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_DISABLED", PHP_OUTPUT_HANDLER_DISABLED, CONST_CS | CONST_PERSISTENT);
}
/* }}} */
-/* {{{ php_output_register_constants */
-void php_output_register_constants(TSRMLS_D)
+/* {{{ void php_output_set_status(int status TSRMLS_DC)
+ Used by SAPIs to disable output */
+PHPAPI void php_output_set_status(int status TSRMLS_DC)
{
- REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_START", PHP_OUTPUT_HANDLER_START, CONST_CS | CONST_PERSISTENT);
- REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_CONT", PHP_OUTPUT_HANDLER_CONT, CONST_CS | CONST_PERSISTENT);
- REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_END", PHP_OUTPUT_HANDLER_END, CONST_CS | CONST_PERSISTENT);
+ OG(flags) = status & 0xf;
}
/* }}} */
-
-/* {{{ php_body_write
- * Write body part */
-PHPAPI int php_body_write(const char *str, uint str_length TSRMLS_DC)
+/* {{{ int php_output_get_status(TSRMLS_C)
+ Get output control status */
+PHPAPI int php_output_get_status(TSRMLS_D)
{
- return OG(php_body_write)(str, str_length TSRMLS_CC);
+ return OG(flags)
+ | (OG(active) ? PHP_OUTPUT_ACTIVE : 0)
+ | (OG(running)? PHP_OUTPUT_LOCKED : 0);
}
/* }}} */
-/* {{{ php_header_write
- * Write HTTP header */
-PHPAPI int php_header_write(const char *str, uint str_length TSRMLS_DC)
+/* {{{ int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC)
+ Unbuffered write */
+PHPAPI int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC)
{
- if (OG(disable_output)) {
+ if (OG(flags) & PHP_OUTPUT_DISABLED) {
return 0;
- } else {
- return OG(php_header_write)(str, str_length TSRMLS_CC);
}
+ return sapi_module.ub_write(str, len TSRMLS_CC);
}
/* }}} */
-/* {{{ php_start_ob_buffer
- * Start output buffering */
-PHPAPI int php_start_ob_buffer(zval *output_handler, uint chunk_size, zend_bool erase TSRMLS_DC)
+/* {{{ int php_output_write(const char *str, size_t len TSRMLS_DC)
+ Buffered write */
+PHPAPI int php_output_write(const char *str, size_t len TSRMLS_DC)
{
- uint initial_size, block_size;
-
- if (OG(ob_lock)) {
- if (SG(headers_sent) && !SG(request_info).headers_only) {
- OG(php_body_write) = php_ub_body_write_no_header;
- } else {
- OG(php_body_write) = php_ub_body_write;
- }
- OG(ob_nesting_level) = 0;
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_ERROR, "Cannot use output buffering in output buffering display handlers");
- return FAILURE;
+ if (OG(flags) & PHP_OUTPUT_DISABLED) {
+ return 0;
}
- if (chunk_size > 0) {
- if (chunk_size==1) {
- chunk_size = 4096;
+ php_output_op(PHP_OUTPUT_HANDLER_WRITE, str, len TSRMLS_CC);
+ return (int) len;
+}
+/* }}} */
+
+/* {{{ SUCCESS|FAILURE php_output_flush(TSRMLS_D)
+ Flush the most recent output handlers buffer */
+PHPAPI int php_output_flush(TSRMLS_D)
+{
+ php_output_context context;
+
+ if (OG(active) && (OG(active)->flags & PHP_OUTPUT_HANDLER_FLUSHABLE)) {
+ php_output_context_init(&context, PHP_OUTPUT_HANDLER_FLUSH TSRMLS_CC);
+ php_output_handler_op(OG(active), &context);
+ if (context.out.data && context.out.used) {
+ zend_stack_del_top(OG(handlers));
+ php_output_write(context.out.data, context.out.used TSRMLS_CC);
+ zend_stack_push(OG(handlers), &OG(active), sizeof(php_output_handler *));
}
- initial_size = (chunk_size*3/2);
- block_size = chunk_size/2;
- } else {
- initial_size = 40*1024;
- block_size = 10*1024;
+ php_output_context_dtor(&context);
+ return SUCCESS;
}
- return php_ob_init(initial_size, block_size, output_handler, chunk_size, erase TSRMLS_CC);
+ return FAILURE;
}
/* }}} */
-/* {{{ php_start_ob_buffer_named
- * Start output buffering */
-PHPAPI int php_start_ob_buffer_named(const char *output_handler_name, uint chunk_size, zend_bool erase TSRMLS_DC)
+/* {{{ void php_output_flush_all(TSRMLS_C)
+ Flush all output buffers subsequently */
+PHPAPI void php_output_flush_all(TSRMLS_D)
{
- zval *output_handler;
- int result;
-
- ALLOC_INIT_ZVAL(output_handler);
- Z_STRLEN_P(output_handler) = strlen(output_handler_name); /* this can be optimized */
- Z_STRVAL_P(output_handler) = estrndup(output_handler_name, Z_STRLEN_P(output_handler));
- Z_TYPE_P(output_handler) = IS_STRING;
- result = php_start_ob_buffer(output_handler, chunk_size, erase TSRMLS_CC);
- zval_dtor(output_handler);
- FREE_ZVAL(output_handler);
- return result;
+ if (OG(active)) {
+ php_output_op(PHP_OUTPUT_HANDLER_FLUSH, NULL, 0 TSRMLS_CC);
+ }
}
/* }}} */
-/* {{{ php_end_ob_buffer
- * End output buffering (one level) */
-PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush TSRMLS_DC)
+/* {{{ SUCCESS|FAILURE php_output_clean(TSRMLS_D)
+ Cleans the most recent output handlers buffer if the handler is cleanable */
+PHPAPI int php_output_clean(TSRMLS_D)
{
- char *final_buffer=NULL;
- unsigned int final_buffer_length=0;
- zval *alternate_buffer=NULL;
- char *to_be_destroyed_buffer, *to_be_destroyed_handler_name;
- char *to_be_destroyed_handled_output[2] = { 0, 0 };
- int status;
- php_ob_buffer *prev_ob_buffer_p=NULL;
- php_ob_buffer orig_ob_buffer;
-
- if (OG(ob_nesting_level)==0) {
- return;
- }
- status = 0;
- if (!OG(active_ob_buffer).status & PHP_OUTPUT_HANDLER_START) {
- /* our first call */
- status |= PHP_OUTPUT_HANDLER_START;
- }
- if (just_flush) {
- status |= PHP_OUTPUT_HANDLER_CONT;
- } else {
- status |= PHP_OUTPUT_HANDLER_END;
- }
+ php_output_context context;
+
+ if (OG(active) && (OG(active)->flags & PHP_OUTPUT_HANDLER_CLEANABLE)) {
+ OG(active)->buffer.used = 0;
+ php_output_context_init(&context, PHP_OUTPUT_HANDLER_CLEAN TSRMLS_CC);
+ php_output_handler_op(OG(active), &context);
+ php_output_context_dtor(&context);
+ return SUCCESS;
+ }
+ return FAILURE;
+}
+/* }}} */
-#if 0
- {
- FILE *fp;
- fp = fopen("/tmp/ob_log", "a");
- fprintf(fp, "NestLevel: %d ObStatus: %d HandlerName: %s\n", OG(ob_nesting_level), status, OG(active_ob_buffer).handler_name);
- fclose(fp);
- }
-#endif
+/* {{{ void php_output_clean_all(TSRMLS_D)
+ Cleans all output handler buffers, without regard whether the handler is cleanable */
+PHPAPI void php_output_clean_all(TSRMLS_D)
+{
+ php_output_context context;
- if (OG(active_ob_buffer).internal_output_handler) {
- final_buffer = OG(active_ob_buffer).internal_output_handler_buffer;
- final_buffer_length = OG(active_ob_buffer).internal_output_handler_buffer_size;
- OG(active_ob_buffer).internal_output_handler(OG(active_ob_buffer).buffer, OG(active_ob_buffer).text_length, &final_buffer, &final_buffer_length, status TSRMLS_CC);
- } else if (OG(active_ob_buffer).output_handler) {
- zval **params[2];
- zval *orig_buffer;
- zval *z_status;
-
- ALLOC_INIT_ZVAL(orig_buffer);
- ZVAL_STRINGL(orig_buffer, OG(active_ob_buffer).buffer, OG(active_ob_buffer).text_length, 1);
-
- ALLOC_INIT_ZVAL(z_status);
- ZVAL_LONG(z_status, status);
-
- params[0] = &orig_buffer;
- params[1] = &z_status;
- OG(ob_lock) = 1;
-
- if (call_user_function_ex(CG(function_table), NULL, OG(active_ob_buffer).output_handler, &alternate_buffer, 2, params, 1, NULL TSRMLS_CC)==SUCCESS) {
- if (alternate_buffer && !(Z_TYPE_P(alternate_buffer)==IS_BOOL && Z_BVAL_P(alternate_buffer)==0)) {
- convert_to_string_ex(&alternate_buffer);
- final_buffer = Z_STRVAL_P(alternate_buffer);
- final_buffer_length = Z_STRLEN_P(alternate_buffer);
- }
- }
- OG(ob_lock) = 0;
- if (!just_flush) {
- zval_ptr_dtor(&OG(active_ob_buffer).output_handler);
- }
- zval_ptr_dtor(&orig_buffer);
- zval_ptr_dtor(&z_status);
+ if (OG(active)) {
+ php_output_context_init(&context, PHP_OUTPUT_HANDLER_CLEAN TSRMLS_CC);
+ zend_stack_apply_with_argument(OG(handlers), ZEND_STACK_APPLY_TOPDOWN, php_output_stack_apply_clean, &context);
}
+}
- if (!final_buffer) {
- final_buffer = OG(active_ob_buffer).buffer;
- final_buffer_length = OG(active_ob_buffer).text_length;
+/* {{{ SUCCESS|FAILURE php_output_end(TSRMLS_D)
+ Finalizes the most recent output handler at pops it off the stack if the handler is removable */
+PHPAPI int php_output_end(TSRMLS_D)
+{
+ if (php_output_stack_pop(PHP_OUTPUT_POP_TRY TSRMLS_CC)) {
+ return SUCCESS;
}
+ return FAILURE;
+}
+/* }}} */
- if (OG(ob_nesting_level)==1) { /* end buffering */
- if (SG(headers_sent) && !SG(request_info).headers_only) {
- OG(php_body_write) = php_ub_body_write_no_header;
- } else {
- OG(php_body_write) = php_ub_body_write;
- }
- }
+/* {{{ void php_output_end_all(TSRMLS_D)
+ Finalizes all output handlers and ends output buffering without regard whether a handler is removable */
+PHPAPI void php_output_end_all(TSRMLS_D)
+{
+ while (OG(active) && php_output_stack_pop(PHP_OUTPUT_POP_FORCE TSRMLS_CC));
+}
+/* }}} */
- to_be_destroyed_buffer = OG(active_ob_buffer).buffer;
- to_be_destroyed_handler_name = OG(active_ob_buffer).handler_name;
- if (OG(active_ob_buffer).internal_output_handler
- && (final_buffer != OG(active_ob_buffer).internal_output_handler_buffer)
- && (final_buffer != OG(active_ob_buffer).buffer)) {
- to_be_destroyed_handled_output[0] = final_buffer;
+/* {{{ SUCCESS|FAILURE php_output_discard(TSRMLS_D)
+ Discards the most recent output handlers buffer and pops it off the stack if the handler is removable */
+PHPAPI int php_output_discard(TSRMLS_D)
+{
+ if (php_output_stack_pop(PHP_OUTPUT_POP_DISCARD|PHP_OUTPUT_POP_TRY TSRMLS_CC)) {
+ return SUCCESS;
}
+ return FAILURE;
+}
+/* }}} */
- if (!just_flush) {
- if (OG(active_ob_buffer).internal_output_handler) {
- to_be_destroyed_handled_output[1] = OG(active_ob_buffer).internal_output_handler_buffer;
- }
- }
- if (OG(ob_nesting_level)>1) { /* restore previous buffer */
- zend_stack_top(&OG(ob_buffers), (void **) &prev_ob_buffer_p);
- orig_ob_buffer = OG(active_ob_buffer);
- OG(active_ob_buffer) = *prev_ob_buffer_p;
- zend_stack_del_top(&OG(ob_buffers));
- if (!just_flush && OG(ob_nesting_level)==2) { /* destroy the stack */
- zend_stack_destroy(&OG(ob_buffers));
- }
+/* {{{ void php_output_discard_all(TSRMLS_D)
+ Discard all output handlers and buffers without regard whether a handler is removable */
+PHPAPI void php_output_discard_all(TSRMLS_D)
+{
+ while (OG(active)) {
+ php_output_stack_pop(PHP_OUTPUT_POP_DISCARD|PHP_OUTPUT_POP_FORCE TSRMLS_CC);
}
- OG(ob_nesting_level)--;
+}
+/* }}} */
- if (send_buffer) {
- if (just_flush) { /* if flush is called prior to proper end, ensure presence of NUL */
- final_buffer[final_buffer_length] = '\0';
- }
- OG(php_body_write)(final_buffer, final_buffer_length TSRMLS_CC);
+/* {{{ int php_output_get_level(TSRMLS_D)
+ Get output buffering level, ie. how many output handlers the stack contains */
+PHPAPI int php_output_get_level(TSRMLS_D)
+{
+ return OG(active) ? zend_stack_count(OG(handlers)) : 0;
+}
+/* }}} */
+
+/* {{{ SUCCESS|FAILURE php_output_get_contents(zval *z TSRMLS_DC)
+ Get the contents of the active output handlers buffer */
+PHPAPI int php_output_get_contents(zval *p TSRMLS_DC)
+{
+ if (OG(active)) {
+ ZVAL_STRINGL(p, OG(active)->buffer.data, OG(active)->buffer.used, 1);
+ return SUCCESS;
+ } else {
+ ZVAL_NULL(p);
+ return FAILURE;
}
+}
- if (just_flush) { /* we restored the previous ob, return to the current */
- if (prev_ob_buffer_p) {
- zend_stack_push(&OG(ob_buffers), &OG(active_ob_buffer), sizeof(php_ob_buffer));
- OG(active_ob_buffer) = orig_ob_buffer;
- }
- OG(ob_nesting_level)++;
+/* {{{ SUCCESS|FAILURE php_output_get_length(zval *z TSRMLS_DC)
+ Get the length of the active output handlers buffer */
+PHPAPI int php_output_get_length(zval *p TSRMLS_DC)
+{
+ if (OG(active)) {
+ ZVAL_LONG(p, OG(active)->buffer.used);
+ return SUCCESS;
+ } else {
+ ZVAL_NULL(p);
+ return FAILURE;
}
+}
+/* }}} */
- if (alternate_buffer) {
- zval_ptr_dtor(&alternate_buffer);
+/* {{{ SUCCESS|FAILURE php_output_handler_start_default(TSRMLS_D)
+ Start a "default output handler" */
+PHPAPI int php_output_start_default(TSRMLS_D)
+{
+ php_output_handler *handler;
+
+ handler = php_output_handler_create_internal(ZEND_STRL(php_output_default_handler_name), php_output_handler_default_func, 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
+ if (SUCCESS == php_output_handler_start(handler TSRMLS_CC)) {
+ return SUCCESS;
}
+ php_output_handler_free(&handler TSRMLS_CC);
+ return FAILURE;
+}
+/* }}} */
- if (status & PHP_OUTPUT_HANDLER_END) {
- efree(to_be_destroyed_handler_name);
+/* {{{ SUCCESS|FAILURE php_output_handler_start_devnull(TSRMLS_D)
+ Start a "null output handler" */
+PHPAPI int php_output_start_devnull(TSRMLS_D)
+{
+ php_output_handler *handler;
+
+ handler = php_output_handler_create_internal(ZEND_STRL(php_output_devnull_handler_name), php_output_handler_devnull_func, PHP_OUTPUT_HANDLER_DEFAULT_SIZE, 0 TSRMLS_CC);
+ if (SUCCESS == php_output_handler_start(handler TSRMLS_CC)) {
+ return SUCCESS;
}
- if (!just_flush) {
- efree(to_be_destroyed_buffer);
+ php_output_handler_free(&handler TSRMLS_CC);
+ return FAILURE;
+}
+/* }}} */
+
+/* {{{ SUCCESS|FAILURE php_output_start_user(zval *handler, size_t chunk_size, int flags TSRMLS_DC)
+ Start a user level output handler */
+PHPAPI int php_output_start_user(zval *output_handler, size_t chunk_size, int flags TSRMLS_DC)
+{
+ php_output_handler *handler;
+
+ if (output_handler) {
+ handler = php_output_handler_create_user(output_handler, chunk_size, flags TSRMLS_CC);
} else {
- OG(active_ob_buffer).text_length = 0;
- OG(active_ob_buffer).status |= PHP_OUTPUT_HANDLER_START;
- OG(php_body_write) = php_b_body_write;
+ handler = php_output_handler_create_internal(ZEND_STRL(php_output_default_handler_name), php_output_handler_default_func, chunk_size, flags TSRMLS_CC);
}
- if (to_be_destroyed_handled_output[0]) {
- efree(to_be_destroyed_handled_output[0]);
- }
- if (to_be_destroyed_handled_output[1]) {
- efree(to_be_destroyed_handled_output[1]);
+ if (SUCCESS == php_output_handler_start(handler TSRMLS_CC)) {
+ return SUCCESS;
}
+ php_output_handler_free(&handler TSRMLS_CC);
+ return FAILURE;
}
/* }}} */
-/* {{{ php_end_ob_buffers
- * End output buffering (all buffers) */
-PHPAPI void php_end_ob_buffers(zend_bool send_buffer TSRMLS_DC)
+/* {{{ SUCCESS|FAILURE php_output_start_internal(zval *name, php_output_handler_func_t handler, size_t chunk_size, int flags TSRMLS_DC)
+ Start an internal output handler that does not have to maintain a non-global state */
+PHPAPI int php_output_start_internal(const char *name, size_t name_len, php_output_handler_func_t output_handler, size_t chunk_size, int flags TSRMLS_DC)
{
- while (OG(ob_nesting_level)!=0) {
- php_end_ob_buffer(send_buffer, 0 TSRMLS_CC);
+ php_output_handler *handler;
+
+ handler = php_output_handler_create_internal(name, name_len, php_output_handler_compat_func, chunk_size, flags TSRMLS_CC);
+ php_output_handler_set_context(handler, output_handler, NULL TSRMLS_CC);
+ if (SUCCESS == php_output_handler_start(handler TSRMLS_CC)) {
+ return SUCCESS;
}
+ php_output_handler_free(&handler TSRMLS_CC);
+ return FAILURE;
}
/* }}} */
-/* {{{ php_start_implicit_flush
- */
-PHPAPI void php_start_implicit_flush(TSRMLS_D)
+/* {{{ php_output_handler *php_output_handler_create_user(zval *handler, size_t chunk_size, int flags TSRMLS_DC)
+ Create a user level output handler */
+PHPAPI php_output_handler *php_output_handler_create_user(zval *output_handler, size_t chunk_size, int flags TSRMLS_DC)
{
- OG(implicit_flush)=1;
+ char *handler_name = NULL;
+ php_output_handler *handler = NULL;
+ php_output_handler_alias_ctor_t *alias = NULL;
+ php_output_handler_user_func_t *user = NULL;
+
+ switch (Z_TYPE_P(output_handler)) {
+ case IS_NULL:
+ handler = php_output_handler_create_internal(ZEND_STRL(php_output_default_handler_name), php_output_handler_default_func, chunk_size, flags TSRMLS_CC);
+ break;
+ case IS_STRING:
+ if (Z_STRLEN_P(output_handler) && (alias = php_output_handler_alias(Z_STRVAL_P(output_handler), Z_STRLEN_P(output_handler) TSRMLS_CC))) {
+ handler = (*alias)(Z_STRVAL_P(output_handler), Z_STRLEN_P(output_handler), chunk_size, flags TSRMLS_CC);
+ break;
+ }
+ default:
+ user = ecalloc(1, sizeof(php_output_handler_user_func_t));
+ if (SUCCESS == zend_fcall_info_init(output_handler, 0, &user->fci, &user->fcc, &handler_name, NULL TSRMLS_CC)) {
+ handler = php_output_handler_init(handler_name, strlen(handler_name), chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_USER TSRMLS_CC);
+ Z_ADDREF_P(output_handler);
+ user->zoh = output_handler;
+ handler->func.user = user;
+ } else {
+ /* TODO(helly) log the rror? */
+ efree(user);
+ }
+ if (handler_name) {
+ efree(handler_name);
+ }
+ }
+
+ return handler;
}
/* }}} */
-/* {{{ php_end_implicit_flush
- */
-PHPAPI void php_end_implicit_flush(TSRMLS_D)
+/* {{{ php_output_handler *php_output_handler_create_internal(zval *name, php_output_handler_context_func_t handler, size_t chunk_size, int flags TSRMLS_DC)
+ Create an internal output handler that can maintain a non-global state */
+PHPAPI php_output_handler *php_output_handler_create_internal(const char *name, size_t name_len, php_output_handler_context_func_t output_handler, size_t chunk_size, int flags TSRMLS_DC)
{
- OG(implicit_flush)=0;
+ php_output_handler *handler;
+
+ handler = php_output_handler_init(name, name_len, chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_INTERNAL TSRMLS_CC);
+ handler->func.internal = output_handler;
+
+ return handler;
}
/* }}} */
-/* {{{ php_ob_set_internal_handler
- */
-PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t internal_output_handler, uint buffer_size, char *handler_name, zend_bool erase TSRMLS_DC)
+/* {{{ void php_output_handler_set_context(php_output_handler *handler, void *opaq, void (*dtor)(void* TSRMLS_DC) TSRMLS_DC)
+ Set the context/state of an output handler. Calls the dtor of the previous context if there is one */
+PHPAPI void php_output_handler_set_context(php_output_handler *handler, void *opaq, void (*dtor)(void* TSRMLS_DC) TSRMLS_DC)
{
- if (OG(ob_nesting_level)==0 || OG(active_ob_buffer).internal_output_handler || strcmp(OG(active_ob_buffer).handler_name, OB_DEFAULT_HANDLER_NAME)) {
- php_start_ob_buffer(NULL, buffer_size, erase TSRMLS_CC);
+ if (handler->dtor && handler->opaq) {
+ handler->dtor(handler->opaq TSRMLS_CC);
}
+ handler->dtor = dtor;
+ handler->opaq = opaq;
+}
+/* }}} */
- OG(active_ob_buffer).internal_output_handler = internal_output_handler;
- OG(active_ob_buffer).internal_output_handler_buffer = (char *) emalloc(buffer_size);
- OG(active_ob_buffer).internal_output_handler_buffer_size = buffer_size;
- if (OG(active_ob_buffer).handler_name) {
- efree(OG(active_ob_buffer).handler_name);
+/* {{{ SUCCESS|FAILURE php_output_handler_start(php_output_handler *handler TSRMLS_DC)
+ Starts the set up output handler and pushes it on top of the stack. Checks for any conflicts regarding the output handler to start */
+PHPAPI int php_output_handler_start(php_output_handler *handler TSRMLS_DC)
+{
+ HashPosition pos;
+ HashTable *rconflicts;
+ php_output_handler_conflict_check_t *conflict;
+
+ if (php_output_lock_error(PHP_OUTPUT_HANDLER_START TSRMLS_CC) || !handler) {
+ return FAILURE;
+ }
+ if (SUCCESS == zend_hash_find(&php_output_handler_conflicts, handler->name, handler->name_len+1, (void *) &conflict)) {
+ if (SUCCESS != (*conflict)(handler->name, handler->name_len TSRMLS_CC)) {
+ return FAILURE;
+ }
+ }
+ if (SUCCESS == zend_hash_find(&php_output_handler_reverse_conflicts, handler->name, handler->name_len+1, (void *) &rconflicts)) {
+ for ( zend_hash_internal_pointer_reset_ex(rconflicts, &pos);
+ zend_hash_get_current_data_ex(rconflicts, (void *) &conflict, &pos) == SUCCESS;
+ zend_hash_move_forward_ex(rconflicts, &pos)) {
+ if (SUCCESS != (*conflict)(handler->name, handler->name_len TSRMLS_CC)) {
+ return FAILURE;
+ }
+ }
}
- OG(active_ob_buffer).handler_name = estrdup(handler_name);
- OG(active_ob_buffer).erase = erase;
+ /* zend_stack_push never returns SUCCESS but FAILURE or stack level */
+ if (FAILURE == (handler->level = zend_stack_push(OG(handlers), &handler, sizeof(php_output_handler *)))) {
+ return FAILURE;
+ }
+ OG(active) = handler;
+ return SUCCESS;
}
/* }}} */
-/*
- * Output buffering - implementation
- */
-
-/* {{{ php_ob_allocate
- */
-static inline void php_ob_allocate(uint text_length TSRMLS_DC)
+/* {{{ int php_output_handler_started(zval *name TSRMLS_DC)
+ Check whether a certain output handler is in use */
+PHPAPI int php_output_handler_started(const char *name, size_t name_len TSRMLS_DC)
{
- uint new_len = OG(active_ob_buffer).text_length + text_length;
-
- if (OG(active_ob_buffer).size < new_len) {
- uint buf_size = OG(active_ob_buffer).size;
- while (buf_size <= new_len) {
- buf_size += OG(active_ob_buffer).block_size;
+ php_output_handler **handlers;
+ int i, count = php_output_get_level(TSRMLS_C);
+
+ if (count) {
+ handlers = *(php_output_handler ***) zend_stack_base(OG(handlers));
+
+ for (i = 0; i < count; ++i) {
+ if (name_len == handlers[i]->name_len && !memcmp(handlers[i]->name, name, name_len)) {
+ return 1;
+ }
}
-
- OG(active_ob_buffer).buffer = (char *) erealloc(OG(active_ob_buffer).buffer, buf_size+1);
- OG(active_ob_buffer).size = buf_size;
}
- OG(active_ob_buffer).text_length = new_len;
+
+ return 0;
}
/* }}} */
-/* {{{ php_ob_init_conflict
- * Returns 1 if handler_set is already used and generates error message
- */
-PHPAPI int php_ob_init_conflict(char *handler_new, char *handler_set TSRMLS_DC)
+/* {{{ int php_output_handler_conflict(zval *handler_new, zval *handler_old TSRMLS_DC)
+ Check whether a certain handler is in use and issue a warning that the new handler would conflict with the already used one */
+PHPAPI int php_output_handler_conflict(const char *handler_new, size_t handler_new_len, const char *handler_set, size_t handler_set_len TSRMLS_DC)
{
- if (php_ob_handler_used(handler_set TSRMLS_CC)) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "output handler '%s' conflicts with '%s'", handler_new, handler_set);
+ if (php_output_handler_started(handler_set, handler_set_len TSRMLS_CC)) {
+ if (handler_new_len != handler_set_len || memcmp(handler_new, handler_set, handler_set_len)) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "output handler '%s' conflicts with '%s'", handler_new, handler_set);
+ } else {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "output handler '%s' cannot be used twice", handler_new);
+ }
return 1;
}
return 0;
}
/* }}} */
-/* {{{ php_ob_init_named
- */
-static int php_ob_init_named(uint initial_size, uint block_size, char *handler_name, zval *output_handler, uint chunk_size, zend_bool erase TSRMLS_DC)
+/* {{{ SUCCESS|FAILURE php_output_handler_conflict_register(zval *name, php_output_handler_conflict_check_t check_func TSRMLS_DC)
+ Register a conflict checking function on MINIT */
+PHPAPI int php_output_handler_conflict_register(const char *name, size_t name_len, php_output_handler_conflict_check_t check_func TSRMLS_DC)
{
- php_ob_buffer tmp_buf;
+ if (!EG(current_module)) {
+ zend_error(E_ERROR, "Cannot register an output handler conflict outside of MINIT");
+ return FAILURE;
+ }
+ return zend_hash_update(&php_output_handler_conflicts, name, name_len+1, &check_func, sizeof(php_output_handler_conflict_check_t *), NULL);
+}
+/* }}} */
- if (output_handler && !zend_is_callable(output_handler, 0, NULL TSRMLS_CC)) {
+/* {{{ SUCCESS|FAILURE php_output_handler_reverse_conflict_register(zval *name, php_output_handler_conflict_check_t check_func TSRMLS_DC)
+ Register a reverse conflict checking function on MINIT */
+PHPAPI int php_output_handler_reverse_conflict_register(const char *name, size_t name_len, php_output_handler_conflict_check_t check_func TSRMLS_DC)
+{
+ HashTable rev, *rev_ptr = NULL;
+
+ if (!EG(current_module)) {
+ zend_error(E_ERROR, "Cannot register a reverse output handler conflict outside of MINIT");
return FAILURE;
}
- tmp_buf.block_size = block_size;
- tmp_buf.size = initial_size;
- tmp_buf.buffer = (char *) emalloc(initial_size+1);
- tmp_buf.text_length = 0;
- tmp_buf.output_handler = output_handler;
- tmp_buf.chunk_size = chunk_size;
- tmp_buf.status = 0;
- tmp_buf.internal_output_handler = NULL;
- tmp_buf.internal_output_handler_buffer = NULL;
- tmp_buf.internal_output_handler_buffer_size = 0;
- tmp_buf.handler_name = estrdup(handler_name&&handler_name[0]?handler_name:OB_DEFAULT_HANDLER_NAME);
- tmp_buf.erase = erase;
-
- if (OG(ob_nesting_level)>0) {
-#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB)
- if (!strncmp(handler_name, "ob_gzhandler", sizeof("ob_gzhandler")) && php_ob_gzhandler_check(TSRMLS_C)) {
+ if (SUCCESS == zend_hash_find(&php_output_handler_reverse_conflicts, name, name_len+1, (void *) &rev_ptr)) {
+ return zend_hash_next_index_insert(rev_ptr, &check_func, sizeof(php_output_handler_conflict_check_t *), NULL);
+ } else {
+ zend_hash_init(&rev, 1, NULL, NULL, 1);
+ if (SUCCESS != zend_hash_next_index_insert(&rev, &check_func, sizeof(php_output_handler_conflict_check_t *), NULL)) {
+ zend_hash_destroy(&rev);
+ return FAILURE;
+ }
+ if (SUCCESS != zend_hash_update(&php_output_handler_reverse_conflicts, name, name_len+1, &rev, sizeof(HashTable), NULL)) {
+ zend_hash_destroy(&rev);
return FAILURE;
}
-#endif
- if (OG(ob_nesting_level)==1) { /* initialize stack */
- zend_stack_init(&OG(ob_buffers));
- }
- zend_stack_push(&OG(ob_buffers), &OG(active_ob_buffer), sizeof(php_ob_buffer));
+ return SUCCESS;
}
- OG(ob_nesting_level)++;
- OG(active_ob_buffer) = tmp_buf;
- OG(php_body_write) = php_b_body_write;
- return SUCCESS;
}
/* }}} */
-/* {{{ php_ob_handler_from_string
- * Create zval output handler from string
- */
-static zval* php_ob_handler_from_string(const char *handler_name, int len TSRMLS_DC)
+/* {{{ php_output_handler_alias_ctor_t php_output_handler_alias(zval *name TSRMLS_DC)
+ Get an internal output handler for a user handler if it exists */
+PHPAPI php_output_handler_alias_ctor_t *php_output_handler_alias(const char *name, size_t name_len TSRMLS_DC)
{
- zval *output_handler;
-
- ALLOC_INIT_ZVAL(output_handler);
- Z_STRLEN_P(output_handler) = len;
- Z_STRVAL_P(output_handler) = estrndup(handler_name, len);
- Z_TYPE_P(output_handler) = IS_STRING;
- return output_handler;
+ php_output_handler_alias_ctor_t *func = NULL;
+
+ zend_hash_find(&php_output_handler_aliases, name, name_len+1, (void *) &func);
+ return func;
}
/* }}} */
-/* {{{ php_ob_init
- */
-static int php_ob_init(uint initial_size, uint block_size, zval *output_handler, uint chunk_size, zend_bool erase TSRMLS_DC)
+/* {{{ SUCCESS|FAILURE php_output_handler_alias_register(zval *name, php_output_handler_alias_ctor_t func TSRMLS_DC)
+ Registers an internal output handler as alias for a user handler */
+PHPAPI int php_output_handler_alias_register(const char *name, size_t name_len, php_output_handler_alias_ctor_t func TSRMLS_DC)
{
- int result = FAILURE, handler_len, len;
- char *handler_name, *next_handler_name;
- HashPosition pos;
- zval **tmp;
- zval *handler_zval;
-
- if (output_handler && output_handler->type == IS_STRING) {
- handler_name = Z_STRVAL_P(output_handler);
- handler_len = Z_STRLEN_P(output_handler);
-
- result = SUCCESS;
- if (handler_len && handler_name[0] != '\0') {
- while ((next_handler_name=strchr(handler_name, ',')) != NULL) {
- len = next_handler_name-handler_name;
- next_handler_name = estrndup(handler_name, len);
- handler_zval = php_ob_handler_from_string(next_handler_name, len TSRMLS_CC);
- result = php_ob_init_named(initial_size, block_size, next_handler_name, handler_zval, chunk_size, erase TSRMLS_CC);
- if (result != SUCCESS) {
- zval_dtor(handler_zval);
- FREE_ZVAL(handler_zval);
- }
- handler_name += len+1;
- handler_len -= len+1;
- efree(next_handler_name);
- }
- }
- if (result == SUCCESS) {
- handler_zval = php_ob_handler_from_string(handler_name, handler_len TSRMLS_CC);
- result = php_ob_init_named(initial_size, block_size, handler_name, handler_zval, chunk_size, erase TSRMLS_CC);
- if (result != SUCCESS) {
- zval_dtor(handler_zval);
- FREE_ZVAL(handler_zval);
- }
- }
- } else if (output_handler && output_handler->type == IS_ARRAY) {
- /* do we have array(object,method) */
- if (zend_is_callable(output_handler, 0, &handler_name TSRMLS_CC)) {
- SEPARATE_ZVAL(&output_handler);
- Z_ADDREF_P(output_handler);
- result = php_ob_init_named(initial_size, block_size, handler_name, output_handler, chunk_size, erase TSRMLS_CC);
- efree(handler_name);
- } else {
- efree(handler_name);
- /* init all array elements recursively */
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(output_handler), &pos);
- while (zend_hash_get_current_data_ex(Z_ARRVAL_P(output_handler), (void **)&tmp, &pos) == SUCCESS) {
- result = php_ob_init(initial_size, block_size, *tmp, chunk_size, erase TSRMLS_CC);
- if (result == FAILURE) {
- break;
- }
- zend_hash_move_forward_ex(Z_ARRVAL_P(output_handler), &pos);
- }
- }
- } else if (output_handler && output_handler->type == IS_OBJECT) {
- /* do we have callable object */
- if (zend_is_callable(output_handler, 0, &handler_name TSRMLS_CC)) {
- SEPARATE_ZVAL(&output_handler);
- Z_ADDREF_P(output_handler);
- result = php_ob_init_named(initial_size, block_size, handler_name, output_handler, chunk_size, erase TSRMLS_CC);
- efree(handler_name);
- } else {
- efree(handler_name);
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "No method name given: use ob_start(array($object,'method')) to specify instance $object and the name of a method of class %s to use as output handler", Z_OBJCE_P(output_handler)->name);
- result = FAILURE;
- }
- } else {
- result = php_ob_init_named(initial_size, block_size, OB_DEFAULT_HANDLER_NAME, NULL, chunk_size, erase TSRMLS_CC);
+ if (!EG(current_module)) {
+ zend_error(E_ERROR, "Cannot register an output handler alias outside of MINIT");
+ return FAILURE;
}
- return result;
+ return zend_hash_update(&php_output_handler_aliases, name, name_len+1, &func, sizeof(php_output_handler_alias_ctor_t *), NULL);
}
/* }}} */
-/* {{{ php_ob_list_each
- */
-static int php_ob_list_each(php_ob_buffer *ob_buffer, zval *ob_handler_array)
+/* {{{ SUCCESS|FAILURE php_output_handler_hook(php_output_handler_hook_t type, void *arg TSMRLS_DC)
+ Output handler hook for output handler functions to check/modify the current handlers abilities */
+PHPAPI int php_output_handler_hook(php_output_handler_hook_t type, void *arg TSRMLS_DC)
{
- add_next_index_string(ob_handler_array, ob_buffer->handler_name, 1);
- return 0;
+ if (OG(running)) {
+ switch (type) {
+ case PHP_OUTPUT_HANDLER_HOOK_GET_OPAQ:
+ *(void ***) arg = &OG(running)->opaq;
+ return SUCCESS;
+ case PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS:
+ *(int *) arg = OG(running)->flags;
+ return SUCCESS;
+ case PHP_OUTPUT_HANDLER_HOOK_GET_LEVEL:
+ *(int *) arg = OG(running)->level;
+ case PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE:
+ OG(running)->flags &= ~(PHP_OUTPUT_HANDLER_REMOVABLE|PHP_OUTPUT_HANDLER_CLEANABLE);
+ return SUCCESS;
+ case PHP_OUTPUT_HANDLER_HOOK_DISABLE:
+ OG(running)->flags |= PHP_OUTPUT_HANDLER_DISABLED;
+ return SUCCESS;
+ default:
+ break;
+ }
+ }
+ return FAILURE;
}
/* }}} */
-/* {{{ proto false|array ob_list_handlers()
- * List all output_buffers in an array
- */
-PHP_FUNCTION(ob_list_handlers)
+/* {{{ void php_output_handler_dtor(php_output_handler *handler TSRMLS_DC)
+ Destroy an output handler */
+PHPAPI void php_output_handler_dtor(php_output_handler *handler TSRMLS_DC)
{
- if (zend_parse_parameters_none() == FAILURE) {
- return;
+ STR_FREE(handler->name);
+ STR_FREE(handler->buffer.data);
+ if (handler->flags & PHP_OUTPUT_HANDLER_USER) {
+ zval_ptr_dtor(&handler->func.user->zoh);
+ efree(handler->func.user);
}
-
- array_init(return_value);
- if (OG(ob_nesting_level)) {
- if (OG(ob_nesting_level)>1) {
- zend_stack_apply_with_argument(&OG(ob_buffers), ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_ob_list_each, return_value);
- }
- php_ob_list_each(&OG(active_ob_buffer), return_value);
+ if (handler->dtor && handler->opaq) {
+ handler->dtor(handler->opaq TSRMLS_CC);
}
+ memset(handler, 0, sizeof(*handler));
}
/* }}} */
-/* {{{ php_ob_used_each
- * Sets handler_name to NULL is found
- */
-static int php_ob_handler_used_each(php_ob_buffer *ob_buffer, char **handler_name)
+/* {{{ void php_output_handler_free(php_output_handler **handler TSMRLS_DC)
+ Destroy and free an output handler */
+PHPAPI void php_output_handler_free(php_output_handler **h TSRMLS_DC)
{
- if (!strcmp(ob_buffer->handler_name, *handler_name)) {
- *handler_name = NULL;
- return 1;
+ if (*h) {
+ php_output_handler_dtor(*h TSRMLS_CC);
+ efree(*h);
+ *h = NULL;
}
- return 0;
}
/* }}} */
-/* {{{ php_ob_used
- * returns 1 if given handler_name is used as output_handler
- */
-PHPAPI int php_ob_handler_used(char *handler_name TSRMLS_DC)
+/* void php_output_set_implicit_flush(int enabled TSRMLS_DC)
+ Enable or disable implicit flush */
+PHPAPI void php_output_set_implicit_flush(int flush TSRMLS_DC)
{
- char *tmp = handler_name;
-
- if (OG(ob_nesting_level)) {
- if (!strcmp(OG(active_ob_buffer).handler_name, handler_name)) {
- return 1;
- }
- if (OG(ob_nesting_level)>1) {
- zend_stack_apply_with_argument(&OG(ob_buffers), ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_ob_handler_used_each, &tmp);
- }
+ if (flush) {
+ OG(flags) |= PHP_OUTPUT_IMPLICITFLUSH;
+ } else {
+ OG(flags) &= ~PHP_OUTPUT_IMPLICITFLUSH;
}
- return tmp ? 0 : 1;
}
/* }}} */
-/* {{{ php_ob_append
- */
-static inline void php_ob_append(const char *text, uint text_length TSRMLS_DC)
+/* {{{ char *php_output_get_start_filename(TSRMLS_D)
+ Get the file name where output has started */
+PHPAPI char *php_output_get_start_filename(TSRMLS_D)
{
- char *target;
- int original_ob_text_length;
+ return OG(output_start_filename);
+}
+/* }}} */
- original_ob_text_length=OG(active_ob_buffer).text_length;
+/* {{{ int php_output_get_start_lineno(TSRMLS_D)
+ Get the line number where output has started */
+PHPAPI int php_output_get_start_lineno(TSRMLS_D)
+{
+ return OG(output_start_lineno);
+}
+/* }}} */
- php_ob_allocate(text_length TSRMLS_CC);
- target = OG(active_ob_buffer).buffer+original_ob_text_length;
- memcpy(target, text, text_length);
- target[text_length]=0;
+/* {{{ static int php_output_lock_error(int op TSRMLS_DC)
+ Checks whether an unallowed operation is attempted from within the output handler and issues a fatal error */
+static inline int php_output_lock_error(int op TSRMLS_DC)
+{
+ /* if there's no ob active, ob has been stopped */
+ if (op && OG(active) && OG(running)) {
+ /* fatal error */
+ php_output_deactivate(TSRMLS_C);
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_ERROR, "Cannot use output buffering in output buffering display handlers");
+ return 1;
+ }
+ return 0;
+}
+/* }}} */
- /* If implicit_flush is On or chunked buffering, send contents to next buffer and return. */
- if (OG(active_ob_buffer).chunk_size
- && OG(active_ob_buffer).text_length >= OG(active_ob_buffer).chunk_size) {
-
- php_end_ob_buffer(1, 1 TSRMLS_CC);
- return;
+/* {{{ static php_output_context *php_output_context_init(php_output_context *context, int op TSRMLS_DC)
+ Initialize a new output context */
+static inline php_output_context *php_output_context_init(php_output_context *context, int op TSRMLS_DC)
+{
+ if (!context) {
+ context = emalloc(sizeof(php_output_context));
}
+
+ memset(context, 0, sizeof(php_output_context));
+ TSRMLS_SET_CTX(context->tsrm_ls);
+ context->op = op;
+
+ return context;
}
/* }}} */
-#if 0
-static inline void php_ob_prepend(const char *text, uint text_length)
+/* {{{ static void php_output_context_reset(php_output_context *context)
+ Reset an output context */
+static inline void php_output_context_reset(php_output_context *context)
{
- char *p, *start;
- TSRMLS_FETCH();
+ int op = context->op;
+ php_output_context_dtor(context);
+ memset(context, 0, sizeof(php_output_context));
+ context->op = op;
+}
+/* }}} */
- php_ob_allocate(text_length TSRMLS_CC);
+/* {{{ static void php_output_context_swap(php_output_context *context)
+ Swap output contexts buffers */
+static inline void php_output_context_swap(php_output_context *context)
+{
+ if (context->in.free && context->in.data) {
+ efree(context->in.data);
+ }
+ context->in.data = context->out.data;
+ context->in.used = context->out.used;
+ context->in.free = context->out.free;
+ context->in.size = context->out.size;
+ context->out.data = NULL;
+ context->out.used = 0;
+ context->out.size = 0;
+}
+/* }}} */
- /* php_ob_allocate() may change OG(ob_buffer), so we can't initialize p&start earlier */
- p = OG(ob_buffer)+OG(ob_text_length);
- start = OG(ob_buffer);
+/* {{{ static void php_output_context_pass(php_output_context *context)
+ Pass input to output buffer */
+static inline void php_output_context_pass(php_output_context *context)
+{
+ context->out.data = context->in.data;
+ context->out.used = context->in.used;
+ context->out.size = context->in.size;
+ context->out.free = context->in.free;
+ context->in.data = NULL;
+ context->in.used = 0;
+ context->in.size = 0;
+}
+/* }}} */
- while (--p>=start) {
- p[text_length] = *p;
+/* {{{ static void php_output_context_dtor(php_output_context *context)
+ Destroy the contents of an output context */
+static inline void php_output_context_dtor(php_output_context *context)
+{
+ if (context->in.free && context->in.data) {
+ efree(context->in.data);
+ context->in.data = NULL;
+ }
+ if (context->out.free && context->out.data) {
+ efree(context->out.data);
+ context->out.data = NULL;
}
- memcpy(OG(ob_buffer), text, text_length);
- OG(ob_buffer)[OG(active_ob_buffer).text_length]=0;
}
-#endif
+/* }}} */
+/* {{{ static php_output_handler *php_output_handler_init(zval *name, size_t chunk_size, int flags TSRMLS_DC)
+ Allocates and initializes a php_output_handler structure */
+static inline php_output_handler *php_output_handler_init(const char *name, size_t name_len, size_t chunk_size, int flags TSRMLS_DC)
+{
+ php_output_handler *handler;
+
+ handler = ecalloc(1, sizeof(php_output_handler));
+ handler->name = estrndup(name, name_len);
+ handler->name_len = name_len;
+ handler->size = chunk_size;
+ handler->flags = flags;
+ handler->buffer.size = PHP_OUTPUT_HANDLER_INITBUF_SIZE(chunk_size);
+ handler->buffer.data = emalloc(handler->buffer.size);
+
+ return handler;
+}
+/* }}} */
-/* {{{ php_ob_get_buffer
- * Return the current output buffer */
-PHPAPI int php_ob_get_buffer(zval *p TSRMLS_DC)
+/* {{{ static int php_output_handler_appen(php_output_handler *handler, const php_output_buffer *buf TSRMLS_DC)
+ Appends input to the output handlers buffer and indicates whether the buffer does not have to be processed by the output handler */
+static inline int php_output_handler_append(php_output_handler *handler, const php_output_buffer *buf TSRMLS_DC)
{
- if (OG(ob_nesting_level)==0) {
- return FAILURE;
+ if (buf->used) {
+ OG(flags) |= PHP_OUTPUT_WRITTEN;
+ /* store it away */
+ if ((handler->buffer.size - handler->buffer.used) <= buf->used) {
+ size_t grow_int = PHP_OUTPUT_HANDLER_INITBUF_SIZE(handler->size);
+ size_t grow_buf = PHP_OUTPUT_HANDLER_INITBUF_SIZE(buf->used - (handler->buffer.size - handler->buffer.used));
+ size_t grow_max = MAX(grow_int, grow_buf);
+
+ handler->buffer.data = erealloc(handler->buffer.data, handler->buffer.size + grow_max);
+ handler->buffer.size += grow_max;
+ }
+ memcpy(handler->buffer.data + handler->buffer.used, buf->data, buf->used);
+ handler->buffer.used += buf->used;
+
+ /* chunked buffering */
+ if (handler->size && (handler->buffer.used >= handler->size)) {
+ /* store away errors and/or any intermediate output */
+ return OG(running) ? 1 : 0;
+ }
}
- ZVAL_STRINGL(p, OG(active_ob_buffer).buffer, OG(active_ob_buffer).text_length, 1);
- return SUCCESS;
+ return 1;
}
/* }}} */
-/* {{{ php_ob_get_length
- * Return the size of the current output buffer */
-PHPAPI int php_ob_get_length(zval *p TSRMLS_DC)
+/* {{{ static php_output_handler_status_t php_output_handler_op(php_output_handler *handler, php_output_context *context)
+ Output handler operation dispatcher, applying context op to the php_output_handler handler */
+static inline php_output_handler_status_t php_output_handler_op(php_output_handler *handler, php_output_context *context)
{
- if (OG(ob_nesting_level) == 0) {
- return FAILURE;
+ php_output_handler_status_t status;
+ int original_op = context->op;
+ PHP_OUTPUT_TSRMLS(context);
+
+#if PHP_OUTPUT_DEBUG
+ fprintf(stderr, ">>> op(%d, "
+ "handler=%p, "
+ "name=%s, "
+ "flags=%d, "
+ "buffer.data=%s, "
+ "buffer.used=%zu, "
+ "buffer.size=%zu, "
+ "in.data=%s, "
+ "in.used=%zu)\n",
+ context->op,
+ handler,
+ handler->name,
+ handler->flags,
+ handler->buffer.used?handler->buffer.data:"",
+ handler->buffer.used,
+ handler->buffer.size,
+ context->in.used?context->in.data:"",
+ context->in.used
+ );
+#endif
+
+ if (php_output_lock_error(context->op TSRMLS_CC)) {
+ /* fatal error */
+ return PHP_OUTPUT_HANDLER_FAILURE;
}
- ZVAL_LONG(p, OG(active_ob_buffer).text_length);
- return SUCCESS;
+
+ /* storable? */
+ if (php_output_handler_append(handler, &context->in TSRMLS_CC) && !context->op) {
+ status = PHP_OUTPUT_HANDLER_NO_DATA;
+ } else {
+ /* need to start? */
+ if (!(handler->flags & PHP_OUTPUT_HANDLER_STARTED)) {
+ context->op |= PHP_OUTPUT_HANDLER_START;
+ }
+
+ OG(running) = handler;
+ if (handler->flags & PHP_OUTPUT_HANDLER_USER) {
+ zval *retval = NULL, *ob_data, *ob_mode;
+
+ MAKE_STD_ZVAL(ob_data);
+ ZVAL_STRINGL(ob_data, handler->buffer.data, handler->buffer.used, 1);
+ MAKE_STD_ZVAL(ob_mode);
+ ZVAL_LONG(ob_mode, (long) context->op);
+ zend_fcall_info_argn(&handler->func.user->fci TSRMLS_CC, 2, &ob_data, &ob_mode);
+
+#define PHP_OUTPUT_USER_SUCCESS(retval) (retval && !(Z_TYPE_P(retval) == IS_BOOL && Z_BVAL_P(retval)==0))
+ if (SUCCESS == zend_fcall_info_call(&handler->func.user->fci, &handler->func.user->fcc, &retval, NULL TSRMLS_CC) && PHP_OUTPUT_USER_SUCCESS(retval)) {
+ /* user handler may have returned TRUE */
+ status = PHP_OUTPUT_HANDLER_NO_DATA;
+ if (Z_TYPE_P(retval) != IS_BOOL) {
+ convert_to_string_ex(&retval);
+ if (Z_STRLEN_P(retval)) {
+ context->out.data = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval));
+ context->out.used = Z_STRLEN_P(retval);
+ context->out.free = 1;
+ status = PHP_OUTPUT_HANDLER_SUCCESS;
+ }
+ }
+ } else {
+ /* call failed, pass internal buffer along */
+ status = PHP_OUTPUT_HANDLER_FAILURE;
+ }
+
+ zend_fcall_info_argn(&handler->func.user->fci TSRMLS_CC, 0);
+ zval_ptr_dtor(&ob_data);
+ zval_ptr_dtor(&ob_mode);
+ if (retval) {
+ zval_ptr_dtor(&retval);
+ }
+
+ } else {
+
+ context->in.data = handler->buffer.data;
+ context->in.used = handler->buffer.used;
+ context->in.free = 0;
+
+ if (SUCCESS == handler->func.internal(&handler->opaq, context)) {
+ if (context->out.used) {
+ status = PHP_OUTPUT_HANDLER_SUCCESS;
+ } else {
+ status = PHP_OUTPUT_HANDLER_NO_DATA;
+ }
+ } else {
+ status = PHP_OUTPUT_HANDLER_FAILURE;
+ }
+ }
+ handler->flags |= PHP_OUTPUT_HANDLER_STARTED;
+ OG(running) = NULL;
+ }
+
+ switch (status) {
+ case PHP_OUTPUT_HANDLER_FAILURE:
+ /* disable this handler */
+ handler->flags |= PHP_OUTPUT_HANDLER_DISABLED;
+ /* discard any output */
+ if (context->out.data && context->out.free) {
+ efree(context->out.data);
+ }
+ /* returns handlers buffer */
+ context->out.data = handler->buffer.data;
+ context->out.used = handler->buffer.used;
+ context->out.free = 1;
+ handler->buffer.data = NULL;
+ handler->buffer.used = 0;
+ handler->buffer.size = 0;
+ break;
+ case PHP_OUTPUT_HANDLER_SUCCESS:
+ /* no more buffered data */
+ handler->buffer.used = 0;
+ break;
+ case PHP_OUTPUT_HANDLER_NO_DATA:
+ /* handler ate all */
+ php_output_context_reset(context);
+ break;
+ }
+
+ context->op = original_op;
+ return status;
}
/* }}} */
-/*
- * Wrapper functions - implementation
- */
-
-/* buffered output function */
-static int php_b_body_write(const char *str, uint str_length TSRMLS_DC)
+/* {{{ static void php_output_op(int op, const char *str, size_t len TSRMLS_DC)
+ Output op dispatcher, passes input and output handlers output through the output handler stack until it gets written to the SAPI */
+static inline void php_output_op(int op, const char *str, size_t len TSRMLS_DC)
{
- php_ob_append(str, str_length TSRMLS_CC);
- return str_length;
+ php_output_context context;
+ php_output_handler **active;
+ int obh_cnt;
+
+ if (php_output_lock_error(op TSRMLS_CC)) {
+ return;
+ }
+
+ php_output_context_init(&context, op TSRMLS_CC);
+
+ /*
+ * broken up for better performance:
+ * - apply op to the one active handler; note that OG(active) might be popped off the stack on a flush
+ * - or apply op to the handler stack
+ */
+ if (OG(active) && (obh_cnt = zend_stack_count(OG(handlers)))) {
+ context.in.data = (char *) str;
+ context.in.used = len;
+
+ if (obh_cnt > 1) {
+ zend_stack_apply_with_argument(OG(handlers), ZEND_STACK_APPLY_TOPDOWN, php_output_stack_apply_op, &context);
+ } else if ((SUCCESS == zend_stack_top(OG(handlers), (void *) &active)) && (!((*active)->flags & PHP_OUTPUT_HANDLER_DISABLED))) {
+ php_output_handler_op(*active, &context);
+ } else {
+ php_output_context_pass(&context);
+ }
+ } else {
+ context.out.data = (char *) str;
+ context.out.used = len;
+ }
+
+ if (context.out.data && context.out.used) {
+#if PHP_OUTPUT_DEBUG
+ fprintf(stderr, "::: sapi_write('%s', %zu)\n", context.out.data, context.out.used);
+#endif
+ if (!SG(headers_sent) && php_header(TSRMLS_C)) {
+ if (zend_is_compiling(TSRMLS_C)) {
+ OG(output_start_filename) = zend_get_compiled_filename(TSRMLS_C);
+ OG(output_start_lineno) = zend_get_compiled_lineno(TSRMLS_C);
+ } else if (zend_is_executing(TSRMLS_C)) {
+ OG(output_start_filename) = zend_get_executed_filename(TSRMLS_C);
+ OG(output_start_lineno) = zend_get_executed_lineno(TSRMLS_C);
+ }
+#if PHP_OUTPUT_DEBUG
+ fprintf(stderr, "!!! output started at: %s (%d)\n", OG(output_start_filename), OG(output_start_lineno));
+#endif
+ }
+ sapi_module.ub_write(context.out.data, context.out.used TSRMLS_CC);
+ if (OG(flags) & PHP_OUTPUT_IMPLICITFLUSH) {
+ sapi_flush(TSRMLS_C);
+ }
+ OG(flags) |= PHP_OUTPUT_SENT;
+ }
+ php_output_context_dtor(&context);
}
+/* }}} */
-/* {{{ php_ub_body_write_no_header
- */
-PHPAPI int php_ub_body_write_no_header(const char *str, uint str_length TSRMLS_DC)
+/* {{{ static int php_output_stack_apply_op(void *h, void *c)
+ Operation callback for the stack apply function */
+static int php_output_stack_apply_op(void *h, void *c)
{
- int result;
+ int was_disabled;
+ php_output_handler_status_t status;
+ php_output_handler *handler = *(php_output_handler **) h;
+ php_output_context *context = (php_output_context *) c;
+
+ if ((was_disabled = (handler->flags & PHP_OUTPUT_HANDLER_DISABLED))) {
+ status = PHP_OUTPUT_HANDLER_FAILURE;
+ } else {
+ status = php_output_handler_op(handler, context);
+ }
+
+ /*
+ * handler ate all => break
+ * handler returned data or failed resp. is disabled => continue
+ */
+ switch (status) {
+ case PHP_OUTPUT_HANDLER_NO_DATA:
+ return 1;
+
+ case PHP_OUTPUT_HANDLER_SUCCESS:
+ /* swap contexts buffers, unless this is the last handler in the stack */
+ if (handler->level) {
+ php_output_context_swap(context);
+ }
+ return 0;
+
+ case PHP_OUTPUT_HANDLER_FAILURE:
+ default:
+ if (was_disabled) {
+ /* pass input along, if it's the last handler in the stack */
+ if (!handler->level) {
+ php_output_context_pass(context);
+ }
+ } else {
+ /* swap buffers, unless this is the last handler */
+ if (handler->level) {
+ php_output_context_swap(context);
+ }
+ }
+ return 0;
+ }
+}
+/* }}} */
- if (OG(disable_output)) {
- return 0;
- }
+/* {{{ static int php_output_stack_apply_clean(void *h, void *c)
+ Clean callback for the stack apply function */
+static int php_output_stack_apply_clean(void *h, void *c)
+{
+ php_output_handler *handler = *(php_output_handler **) h;
+ php_output_context *context = (php_output_context *) c;
+
+ handler->buffer.used = 0;
+ php_output_handler_op(handler, context);
+ php_output_context_reset(context);
+ return 0;
+}
+/* }}} */
+
+/* {{{ static int php_output_stack_apply_list(void *h, void *z)
+ List callback for the stack apply function */
+static int php_output_stack_apply_list(void *h, void *z)
+{
+ php_output_handler *handler = *(php_output_handler **) h;
+ zval *array = (zval *) z;
+
+ add_next_index_stringl(array, handler->name, handler->name_len, 1);
+ return 0;
+}
+/* }}} */
- result = OG(php_header_write)(str, str_length TSRMLS_CC);
+/* {{{ static int php_output_stack_apply_status(void *h, void *z)
+ Status callback for the stack apply function */
+static int php_output_stack_apply_status(void *h, void *z)
+{
+ php_output_handler *handler = *(php_output_handler **) h;
+ zval *array = (zval *) z;
+
+ add_next_index_zval(array, php_output_handler_status(handler, NULL));
+
+ return 0;
+}
- if (OG(implicit_flush)) {
- sapi_flush(TSRMLS_C);
+/* {{{ static zval *php_output_handler_status(php_output_handler *handler, zval *entry)
+ Returns an array with the status of the output handler */
+static inline zval *php_output_handler_status(php_output_handler *handler, zval *entry)
+{
+ if (!entry) {
+ MAKE_STD_ZVAL(entry);
+ array_init(entry);
}
-
- return result;
+
+ add_assoc_stringl(entry, "name", handler->name, handler->name_len, 1);
+ add_assoc_long(entry, "type", (long) (handler->flags & 0xf));
+ add_assoc_long(entry, "flags", (long) handler->flags);
+ add_assoc_long(entry, "level", (long) handler->level);
+ add_assoc_long(entry, "chunk_size", (long) handler->size);
+ add_assoc_long(entry, "buffer_size", (long) handler->buffer.size);
+ add_assoc_long(entry, "buffer_used", (long) handler->buffer.used);
+
+ return entry;
}
/* }}} */
-/* {{{ php_ub_body_write
- */
-PHPAPI int php_ub_body_write(const char *str, uint str_length TSRMLS_DC)
+/* {{{ static int php_output_stack_pop(int flags TSRMLS_DC)
+ Pops an output handler off the stack */
+static inline int php_output_stack_pop(int flags TSRMLS_DC)
{
- int result = 0;
-
- if (SG(request_info).headers_only) {
- if(SG(headers_sent)) {
- return 0;
+ php_output_context context;
+ php_output_handler **current, *orphan = OG(active);
+
+ if (!orphan) {
+ if (!(flags & PHP_OUTPUT_POP_SILENT)) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to %s buffer. No buffer to %s", (flags&PHP_OUTPUT_POP_DISCARD)?"discard":"send", (flags&PHP_OUTPUT_POP_DISCARD)?"discard":"send");
+ }
+ return 0;
+ } else if (!(flags & PHP_OUTPUT_POP_FORCE) && !(orphan->flags & PHP_OUTPUT_HANDLER_REMOVABLE)) {
+ if (!(flags & PHP_OUTPUT_POP_SILENT)) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to %s buffer of %s (%d)", (flags&PHP_OUTPUT_POP_DISCARD)?"discard":"send", orphan->name, orphan->level);
+ }
+ return 0;
+ } else {
+ php_output_context_init(&context, PHP_OUTPUT_HANDLER_FINAL TSRMLS_CC);
+
+ /* don't run the output handler if it's disabled */
+ if (!(orphan->flags & PHP_OUTPUT_HANDLER_DISABLED)) {
+ /* didn't it start yet? */
+ if (!(orphan->flags & PHP_OUTPUT_HANDLER_STARTED)) {
+ context.op |= PHP_OUTPUT_HANDLER_START;
+ }
+ /* signal that we're cleaning up */
+ if (flags & PHP_OUTPUT_POP_DISCARD) {
+ context.op |= PHP_OUTPUT_HANDLER_CLEAN;
+ orphan->buffer.used = 0;
+ }
+ php_output_handler_op(orphan, &context);
+ }
+
+ /* pop it off the stack */
+ zend_stack_del_top(OG(handlers));
+ if (SUCCESS == zend_stack_top(OG(handlers), (void *) &current)) {
+ OG(active) = *current;
+ } else {
+ OG(active) = NULL;
}
- php_header(TSRMLS_C);
- zend_bailout();
- }
- if (php_header(TSRMLS_C)) {
- if (zend_is_compiling(TSRMLS_C)) {
- OG(output_start_filename) = zend_get_compiled_filename(TSRMLS_C);
- OG(output_start_lineno) = zend_get_compiled_lineno(TSRMLS_C);
- } else if (zend_is_executing(TSRMLS_C)) {
- OG(output_start_filename) = zend_get_executed_filename(TSRMLS_C);
- OG(output_start_lineno) = zend_get_executed_lineno(TSRMLS_C);
+
+ /* pass output along */
+ if (context.out.data && context.out.used && !(flags & PHP_OUTPUT_POP_DISCARD)) {
+ php_output_write(context.out.data, context.out.used TSRMLS_CC);
}
+
+ /* destroy the handler (after write!) */
+ php_output_handler_free(&orphan TSRMLS_CC);
+ php_output_context_dtor(&context);
+
+ return 1;
+ }
+}
+/* }}} */
- OG(php_body_write) = php_ub_body_write_no_header;
- result = php_ub_body_write_no_header(str, str_length TSRMLS_CC);
+/* {{{ static SUCCESS|FAILURE php_output_handler_compat_func(void *ctx, php_output_context *)
+ php_output_handler_context_func_t for php_output_handler_func_t output handlers */
+static int php_output_handler_compat_func(void **handler_context, php_output_context *output_context)
+{
+ php_output_handler_func_t func = *(php_output_handler_func_t *) handler_context;
+ PHP_OUTPUT_TSRMLS(output_context);
+
+ if (func) {
+ func(output_context->in.data, output_context->in.used, &output_context->out.data, &output_context->out.used, output_context->op TSRMLS_CC);
+ output_context->out.free = 1;
+ return SUCCESS;
}
+ return FAILURE;
+}
+/* }}} */
+
+/* {{{ static SUCCESS|FAILURE php_output_handler_default_func(void *ctx, php_output_context *)
+ Default output handler */
+static int php_output_handler_default_func(void **handler_context, php_output_context *output_context)
+{
+ output_context->out.data = output_context->in.data;
+ output_context->out.used = output_context->in.used;
+ output_context->out.free = output_context->in.free;
+ output_context->in.data = NULL;
+ output_context->in.used = 0;
+ output_context->in.free = 0;
+ return SUCCESS;
+}
+/* }}} */
- return result;
+/* {{{ static SUCCESS|FAILURE php_output_handler_devnull_func(void *ctx, php_output_context *)
+ Null output handler */
+static int php_output_handler_devnull_func(void **handler_context, php_output_context *output_context)
+{
+ return SUCCESS;
}
/* }}} */
/*
- * HEAD support
+ * USERLAND (nearly 1:1 of old output.c)
*/
-/* {{{ proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]])
+/* {{{ proto bool ob_start([string|array user_function [, int chunk_size [, int flags]]])
Turn on Output Buffering (specifying an optional output handler). */
PHP_FUNCTION(ob_start)
{
- zval *output_handler=NULL;
- long chunk_size=0;
- zend_bool erase=1;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zlb", &output_handler, &chunk_size, &erase) == FAILURE) {
- return;
+ zval *output_handler = NULL;
+ long chunk_size = 0;
+ long flags = PHP_OUTPUT_HANDLER_STDFLAGS;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z/ll", &output_handler, &chunk_size, &flags)) {
+ RETURN_FALSE;
}
if (chunk_size < 0)
chunk_size = 0;
- if (php_start_ob_buffer(output_handler, chunk_size, erase TSRMLS_CC)==FAILURE) {
+ if (SUCCESS != php_output_start_user(output_handler, chunk_size, flags TSRMLS_CC)) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to create buffer");
RETURN_FALSE;
}
RETURN_TRUE;
@@ -766,18 +1251,15 @@ PHP_FUNCTION(ob_flush)
if (zend_parse_parameters_none() == FAILURE) {
return;
}
-
- if (!OG(ob_nesting_level)) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer. No buffer to flush.");
+
+ if (!OG(active)) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer. No buffer to flush");
RETURN_FALSE;
}
-
- if (!OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer %s.", OG(active_ob_buffer).handler_name);
+ if (SUCCESS != php_output_flush(TSRMLS_C)) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer of %s (%d)", OG(active)->name, OG(active)->level);
RETURN_FALSE;
}
-
- php_end_ob_buffer(1, 1 TSRMLS_CC);
RETURN_TRUE;
}
/* }}} */
@@ -791,17 +1273,14 @@ PHP_FUNCTION(ob_clean)
return;
}
- if (!OG(ob_nesting_level)) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete.");
+ if (!OG(active)) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete");
RETURN_FALSE;
}
-
- if (!OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", OG(active_ob_buffer).handler_name);
+ if (SUCCESS != php_output_clean(TSRMLS_C)) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name, OG(active)->level);
RETURN_FALSE;
}
-
- php_end_ob_buffer(0, 1 TSRMLS_CC);
RETURN_TRUE;
}
/* }}} */
@@ -814,17 +1293,11 @@ PHP_FUNCTION(ob_end_flush)
return;
}
- if (!OG(ob_nesting_level)) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete and flush buffer. No buffer to delete or flush.");
- RETURN_FALSE;
- }
- if (OG(ob_nesting_level) && !OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", OG(active_ob_buffer).handler_name);
+ if (!OG(active)) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete and flush buffer. No buffer to delete or flush");
RETURN_FALSE;
}
-
- php_end_ob_buffer(1, 0 TSRMLS_CC);
- RETURN_TRUE;
+ RETURN_BOOL(SUCCESS == php_output_end(TSRMLS_C));
}
/* }}} */
@@ -835,18 +1308,12 @@ PHP_FUNCTION(ob_end_clean)
if (zend_parse_parameters_none() == FAILURE) {
return;
}
-
- if (!OG(ob_nesting_level)) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete.");
- RETURN_FALSE;
- }
- if (OG(ob_nesting_level) && !OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", OG(active_ob_buffer).handler_name);
+
+ if (!OG(active)) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete");
RETURN_FALSE;
}
-
- php_end_ob_buffer(0, 0 TSRMLS_CC);
- RETURN_TRUE;
+ RETURN_BOOL(SUCCESS == php_output_discard(TSRMLS_C));
}
/* }}} */
@@ -857,24 +1324,14 @@ PHP_FUNCTION(ob_get_flush)
if (zend_parse_parameters_none() == FAILURE) {
return;
}
-
- /* get contents */
- if (php_ob_get_buffer(return_value TSRMLS_CC)==FAILURE) {
- RETURN_FALSE;
- }
- /* error checks */
- if (!OG(ob_nesting_level)) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete and flush buffer. No buffer to delete or flush.");
- zval_dtor(return_value);
+
+ if (SUCCESS != php_output_get_contents(return_value TSRMLS_CC)) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete and flush buffer. No buffer to delete or flush");
RETURN_FALSE;
}
- if (OG(ob_nesting_level) && !OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", OG(active_ob_buffer).handler_name);
- zval_dtor(return_value);
- RETURN_FALSE;
+ if (SUCCESS != php_output_end(TSRMLS_C)) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name, OG(active)->level);
}
- /* flush */
- php_end_ob_buffer(1, 0 TSRMLS_CC);
}
/* }}} */
@@ -885,23 +1342,14 @@ PHP_FUNCTION(ob_get_clean)
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- /* get contents */
- if (php_ob_get_buffer(return_value TSRMLS_CC)==FAILURE) {
- RETURN_FALSE;
- }
- /* error checks */
- if (!OG(ob_nesting_level)) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete.");
- zval_dtor(return_value);
+
+ if (SUCCESS != php_output_get_contents(return_value TSRMLS_CC)) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete");
RETURN_FALSE;
}
- if (OG(ob_nesting_level) && !OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) {
- php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", OG(active_ob_buffer).handler_name);
- zval_dtor(return_value);
- RETURN_FALSE;
+ if (SUCCESS != php_output_discard(TSRMLS_C)) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name, OG(active)->level);
}
- /* delete buffer */
- php_end_ob_buffer(0, 0 TSRMLS_CC);
}
/* }}} */
@@ -912,8 +1360,7 @@ PHP_FUNCTION(ob_get_contents)
if (zend_parse_parameters_none() == FAILURE) {
return;
}
-
- if (php_ob_get_buffer(return_value TSRMLS_CC)==FAILURE) {
+ if (SUCCESS != php_output_get_contents(return_value TSRMLS_CC)) {
RETURN_FALSE;
}
}
@@ -926,8 +1373,7 @@ PHP_FUNCTION(ob_get_level)
if (zend_parse_parameters_none() == FAILURE) {
return;
}
-
- RETURN_LONG (OG(ob_nesting_level));
+ RETURN_LONG(php_output_get_level(TSRMLS_C));
}
/* }}} */
@@ -938,114 +1384,65 @@ PHP_FUNCTION(ob_get_length)
if (zend_parse_parameters_none() == FAILURE) {
return;
}
-
- if (php_ob_get_length(return_value TSRMLS_CC)==FAILURE) {
+ if (SUCCESS != php_output_get_length(return_value TSRMLS_CC)) {
RETURN_FALSE;
}
}
/* }}} */
-/* {{{ int php_ob_buffer_status(php_ob_buffer *ob_buffer, zval *result) */
-static int php_ob_buffer_status(php_ob_buffer *ob_buffer, zval *result)
+/* {{{ proto false|array ob_list_handlers()
+ * List all output_buffers in an array
+ */
+PHP_FUNCTION(ob_list_handlers)
{
- zval *elem;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
- MAKE_STD_ZVAL(elem);
- array_init(elem);
+ array_init(return_value);
- add_assoc_long(elem, "chunk_size", ob_buffer->chunk_size);
- if (!ob_buffer->chunk_size) {
- add_assoc_long(elem, "size", ob_buffer->size);
- add_assoc_long(elem, "block_size", ob_buffer->block_size);
- }
- if (ob_buffer->internal_output_handler) {
- add_assoc_long(elem, "type", PHP_OUTPUT_HANDLER_INTERNAL);
- add_assoc_long(elem, "buffer_size", ob_buffer->internal_output_handler_buffer_size);
- }
- else {
- add_assoc_long(elem, "type", PHP_OUTPUT_HANDLER_USER);
+ if (!OG(active)) {
+ return;
}
- add_assoc_long(elem, "status", ob_buffer->status);
- add_assoc_string(elem, "name", ob_buffer->handler_name, 1);
- add_assoc_bool(elem, "del", ob_buffer->erase);
- add_next_index_zval(result, elem);
-
- return SUCCESS;
+
+ zend_stack_apply_with_argument(OG(handlers), ZEND_STACK_APPLY_BOTTOMUP, php_output_stack_apply_list, return_value);
}
/* }}} */
-
/* {{{ proto false|array ob_get_status([bool full_status])
Return the status of the active or all output buffers */
PHP_FUNCTION(ob_get_status)
{
zend_bool full_status = 0;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &full_status) == FAILURE ) {
- return;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &full_status)) {
+ RETURN_FALSE;
}
-
+ if (!OG(active)) {
+ RETURN_FALSE;
+ }
+
array_init(return_value);
-
if (full_status) {
- if (OG(ob_nesting_level)>1) {
- zend_stack_apply_with_argument(&OG(ob_buffers), ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *elem, void *))php_ob_buffer_status, return_value);
- }
- if (OG(ob_nesting_level)>0 && php_ob_buffer_status(&OG(active_ob_buffer), return_value)==FAILURE) {
- RETURN_FALSE;
- }
- } else if (OG(ob_nesting_level)>0) {
- add_assoc_long(return_value, "level", OG(ob_nesting_level));
- if (OG(active_ob_buffer).internal_output_handler) {
- add_assoc_long(return_value, "type", PHP_OUTPUT_HANDLER_INTERNAL);
- } else {
- add_assoc_long(return_value, "type", PHP_OUTPUT_HANDLER_USER);
- }
- add_assoc_long(return_value, "status", OG(active_ob_buffer).status);
- add_assoc_string(return_value, "name", OG(active_ob_buffer).handler_name, 1);
- add_assoc_bool(return_value, "del", OG(active_ob_buffer).erase);
+ zend_stack_apply_with_argument(OG(handlers), ZEND_STACK_APPLY_BOTTOMUP, php_output_stack_apply_status, return_value);
+ } else {
+ php_output_handler_status(OG(active), return_value);
}
}
/* }}} */
-
/* {{{ proto void ob_implicit_flush([int flag])
Turn implicit flush on/off and is equivalent to calling flush() after every output call */
PHP_FUNCTION(ob_implicit_flush)
{
long flag = 1;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag) == FAILURE) {
- return;
- }
-
- if (flag) {
- php_start_implicit_flush(TSRMLS_C);
- } else {
- php_end_implicit_flush(TSRMLS_C);
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag)) {
+ php_output_set_implicit_flush(flag TSRMLS_CC);
}
}
/* }}} */
-
-/* {{{ char *php_get_output_start_filename(TSRMLS_D)
- Return filename start output something */
-PHPAPI char *php_get_output_start_filename(TSRMLS_D)
-{
- return OG(output_start_filename);
-}
-/* }}} */
-
-
-/* {{{ char *php_get_output_start_lineno(TSRMLS_D)
- Return line number start output something */
-PHPAPI int php_get_output_start_lineno(TSRMLS_D)
-{
- return OG(output_start_lineno);
-}
-/* }}} */
-
-
/* {{{ proto bool output_reset_rewrite_vars(void)
Reset(clear) URL rewriter values */
PHP_FUNCTION(output_reset_rewrite_vars)
@@ -1058,7 +1455,6 @@ PHP_FUNCTION(output_reset_rewrite_vars)
}
/* }}} */
-
/* {{{ proto bool output_add_rewrite_var(string name, string value)
Add URL rewriter values */
PHP_FUNCTION(output_add_rewrite_var)
@@ -1067,7 +1463,7 @@ PHP_FUNCTION(output_add_rewrite_var)
int name_len, value_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &value, &value_len) == FAILURE) {
- return;
+ RETURN_FALSE;
}
if (php_url_scanner_add_var(name, name_len, value, value_len, 1 TSRMLS_CC) == SUCCESS) {
diff --git a/main/php.h b/main/php.h
index ccb0012..af5c910 100644
--- a/main/php.h
+++ b/main/php.h
@@ -384,20 +384,7 @@ END_EXTERN_C()
/* Output support */
#include "main/php_output.h"
-#define PHPWRITE(str, str_len) php_body_write((str), (str_len) TSRMLS_CC)
-#define PUTS(str) do { \
- const char *__str = (str); \
- php_body_write(__str, strlen(__str) TSRMLS_CC); \
-} while (0)
-
-#define PUTC(c) (php_body_write(&(c), 1 TSRMLS_CC), (c))
-#define PHPWRITE_H(str, str_len) php_header_write((str), (str_len) TSRMLS_CC)
-#define PUTS_H(str) do { \
- const char *__str = (str); \
- php_header_write(__str, strlen(__str) TSRMLS_CC); \
-} while (0)
-
-#define PUTC_H(c) (php_header_write(&(c), 1 TSRMLS_CC), (c))
+
#include "php_streams.h"
#include "php_memory_streams.h"
diff --git a/main/php_logos.c b/main/php_logos.c
index 5350fb8..43b50a3 100644
--- a/main/php_logos.c
+++ b/main/php_logos.c
@@ -85,7 +85,7 @@ int php_info_logos(const char *logo_string TSRMLS_DC)
content_header[len] = '\0';
sapi_add_header(content_header, len, 0);
- PHPWRITE(logo_image->data, logo_image->size);
+ PHPWRITE((char*)logo_image->data, logo_image->size);
return 1;
}
diff --git a/main/php_output.h b/main/php_output.h
index f340ba4..921ac0d 100644
--- a/main/php_output.h
+++ b/main/php_output.h
@@ -12,7 +12,7 @@
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
- | Author: Zeev Suraski <zeev@zend.com> |
+ | Author: Michael Wallner <mike@php.net> |
+----------------------------------------------------------------------+
*/
@@ -21,35 +21,230 @@
#ifndef PHP_OUTPUT_H
#define PHP_OUTPUT_H
+#define PHP_OUTPUT_NEWAPI 1
+
+/* handler ops */
+#define PHP_OUTPUT_HANDLER_WRITE 0x00 /* standard passthru */
+#define PHP_OUTPUT_HANDLER_START 0x01 /* start */
+#define PHP_OUTPUT_HANDLER_CLEAN 0x02 /* restart */
+#define PHP_OUTPUT_HANDLER_FLUSH 0x04 /* pass along as much as possible */
+#define PHP_OUTPUT_HANDLER_FINAL 0x08 /* finalize */
+#define PHP_OUTPUT_HANDLER_CONT PHP_OUTPUT_HANDLER_WRITE
+#define PHP_OUTPUT_HANDLER_END PHP_OUTPUT_HANDLER_FINAL
+
+/* handler types */
+#define PHP_OUTPUT_HANDLER_INTERNAL 0x0000
+#define PHP_OUTPUT_HANDLER_USER 0x0001
+
+/* handler ability flags */
+#define PHP_OUTPUT_HANDLER_CLEANABLE 0x0010
+#define PHP_OUTPUT_HANDLER_FLUSHABLE 0x0020
+#define PHP_OUTPUT_HANDLER_REMOVABLE 0x0040
+#define PHP_OUTPUT_HANDLER_STDFLAGS 0x0070
+
+/* handler status flags */
+#define PHP_OUTPUT_HANDLER_STARTED 0x1000
+#define PHP_OUTPUT_HANDLER_DISABLED 0x2000
+
+/* handler op return values */
+typedef enum _php_output_handler_status_t {
+ PHP_OUTPUT_HANDLER_FAILURE,
+ PHP_OUTPUT_HANDLER_SUCCESS,
+ PHP_OUTPUT_HANDLER_NO_DATA,
+} php_output_handler_status_t;
+
+/* php_output_stack_pop() flags */
+#define PHP_OUTPUT_POP_TRY 0x000
+#define PHP_OUTPUT_POP_FORCE 0x001
+#define PHP_OUTPUT_POP_DISCARD 0x010
+#define PHP_OUTPUT_POP_SILENT 0x100
+
+/* real global flags */
+#define PHP_OUTPUT_IMPLICITFLUSH 0x01
+#define PHP_OUTPUT_DISABLED 0x02
+#define PHP_OUTPUT_WRITTEN 0x04
+#define PHP_OUTPUT_SENT 0x08
+/* supplementary flags for php_output_get_status() */
+#define PHP_OUTPUT_ACTIVE 0x10
+#define PHP_OUTPUT_LOCKED 0x20
+
+/* handler hooks */
+typedef enum _php_output_handler_hook_t {
+ PHP_OUTPUT_HANDLER_HOOK_GET_OPAQ,
+ PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS,
+ PHP_OUTPUT_HANDLER_HOOK_GET_LEVEL,
+ PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE,
+ PHP_OUTPUT_HANDLER_HOOK_DISABLE,
+ /* unused */
+ PHP_OUTPUT_HANDLER_HOOK_LAST,
+} php_output_handler_hook_t;
+
+#define PHP_OUTPUT_HANDLER_INITBUF_SIZE(s) \
+( (s) ? \
+ (s) + PHP_OUTPUT_HANDLER_ALIGNTO_SIZE - ((s) % (PHP_OUTPUT_HANDLER_ALIGNTO_SIZE)) : \
+ PHP_OUTPUT_HANDLER_DEFAULT_SIZE \
+)
+#define PHP_OUTPUT_HANDLER_ALIGNTO_SIZE 0x1000
+#define PHP_OUTPUT_HANDLER_DEFAULT_SIZE 0x4000
+
+typedef struct _php_output_buffer {
+ char *data;
+ size_t size;
+ size_t used;
+ uint free:1;
+ uint _res:31;
+} php_output_buffer;
+
+typedef struct _php_output_context {
+ int op;
+ php_output_buffer in;
+ php_output_buffer out;
+#ifdef ZTS
+ void ***tsrm_ls;
+#endif
+} php_output_context;
+
+#define PHP_OUTPUT_TSRMLS(ctx) TSRMLS_FETCH_FROM_CTX((ctx)->tsrm_ls)
+
+/* old-style, stateless callback */
typedef void (*php_output_handler_func_t)(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC);
+/* new-style, opaque context callback */
+typedef int (*php_output_handler_context_func_t)(void **handler_context, php_output_context *output_context);
+/* output handler context dtor */
+typedef void (*php_output_handler_context_dtor_t)(void *opaq TSRMLS_DC);
+/* conflict check callback */
+typedef int (*php_output_handler_conflict_check_t)(const char *handler_name, size_t handler_name_len TSRMLS_DC);
+/* ctor for aliases */
+typedef struct _php_output_handler *(*php_output_handler_alias_ctor_t)(const char *handler_name, size_t handler_name_len, size_t chunk_size, int flags TSRMLS_DC);
+
+typedef struct _php_output_handler_user_func_t {
+ zend_fcall_info fci;
+ zend_fcall_info_cache fcc;
+ zval *zoh;
+} php_output_handler_user_func_t;
+
+typedef struct _php_output_handler {
+ char *name;
+ size_t name_len;
+ int flags;
+ int level;
+ size_t size;
+ php_output_buffer buffer;
+
+ void *opaq;
+ void (*dtor)(void *opaq TSRMLS_DC);
+
+ union {
+ php_output_handler_user_func_t *user;
+ php_output_handler_context_func_t internal;
+ } func;
+} php_output_handler;
+
+PHPAPI const char php_output_default_handler_name[sizeof("default output handler")];
+PHPAPI const char php_output_devnull_handler_name[sizeof("null output handler")];
+
+ZEND_BEGIN_MODULE_GLOBALS(output)
+ int flags;
+ zend_stack *handlers;
+ php_output_handler *active;
+ php_output_handler *running;
+ char *output_start_filename;
+ int output_start_lineno;
+ZEND_END_MODULE_GLOBALS(output);
+
+/* there should not be a need to use OG() from outside of output.c */
+#ifdef ZTS
+# define OG(v) TSRMG(output_globals_id, zend_output_globals *, v)
+#else
+# define OG(v) (output_globals.v)
+#endif
+
+/* convenience macros */
+#define PHPWRITE(str, str_len) php_output_write((str), (str_len) TSRMLS_CC)
+#define PHPWRITE_H(str, str_len) php_output_write_unbuffered((str), (str_len) TSRMLS_CC)
+
+#define PUTC(c) (php_output_write(&(c), 1 TSRMLS_CC), (c))
+#define PUTC_H(c) (php_output_write_unbuffered(&(c), 1 TSRMLS_CC), (c))
+
+#define PUTS(str) do { \
+ const char *__str = (str); \
+ php_output_write(__str, strlen(__str) TSRMLS_CC); \
+} while (0)
+#define PUTS_H(str) do { \
+ const char *__str = (str); \
+ php_output_write_unbuffered(__str, strlen(__str) TSRMLS_CC); \
+} while (0)
+
BEGIN_EXTERN_C()
+#define php_output_tearup() \
+ php_output_startup(); \
+ php_output_activate(TSRMLS_C)
+#define php_output_teardown() \
+ php_output_end_all(TSRMLS_C); \
+ php_output_deactivate(TSRMLS_C); \
+ php_output_shutdown()
+
+/* MINIT */
PHPAPI void php_output_startup(void);
-PHPAPI void php_output_activate(TSRMLS_D);
-PHPAPI void php_output_set_status(zend_bool status TSRMLS_DC);
+/* MSHUTDOWN */
+PHPAPI void php_output_shutdown(void);
+
PHPAPI void php_output_register_constants(TSRMLS_D);
-PHPAPI int php_default_output_func(const char *str, uint str_len TSRMLS_DC);
-PHPAPI int php_ub_body_write(const char *str, uint str_length TSRMLS_DC);
-PHPAPI int php_ub_body_write_no_header(const char *str, uint str_length TSRMLS_DC);
-PHPAPI int php_body_write(const char *str, uint str_length TSRMLS_DC);
-PHPAPI int php_header_write(const char *str, uint str_length TSRMLS_DC);
-PHPAPI int php_start_ob_buffer(zval *output_handler, uint chunk_size, zend_bool erase TSRMLS_DC);
-PHPAPI int php_start_ob_buffer_named(const char *output_handler_name, uint chunk_size, zend_bool erase TSRMLS_DC);
-PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush TSRMLS_DC);
-PHPAPI void php_end_ob_buffers(zend_bool send_buffer TSRMLS_DC);
-PHPAPI int php_ob_get_buffer(zval *p TSRMLS_DC);
-PHPAPI int php_ob_get_length(zval *p TSRMLS_DC);
-PHPAPI void php_start_implicit_flush(TSRMLS_D);
-PHPAPI void php_end_implicit_flush(TSRMLS_D);
-PHPAPI char *php_get_output_start_filename(TSRMLS_D);
-PHPAPI int php_get_output_start_lineno(TSRMLS_D);
-PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t internal_output_handler, uint buffer_size, char *handler_name, zend_bool erase TSRMLS_DC);
-PHPAPI int php_ob_handler_used(char *handler_name TSRMLS_DC);
-PHPAPI int php_ob_init_conflict(char *handler_new, char *handler_set TSRMLS_DC);
-PHPAPI int php_ob_get_buffer(zval *p TSRMLS_DC);
-PHPAPI int php_ob_get_length(zval *p TSRMLS_DC);
+
+/* RINIT */
+PHPAPI int php_output_activate(TSRMLS_D);
+/* RSHUTDOWN */
+PHPAPI void php_output_deactivate(TSRMLS_D);
+
+PHPAPI void php_output_set_status(int status TSRMLS_DC);
+PHPAPI int php_output_get_status(TSRMLS_D);
+PHPAPI void php_output_set_implicit_flush(int flush TSRMLS_DC);
+PHPAPI char *php_output_get_start_filename(TSRMLS_D);
+PHPAPI int php_output_get_start_lineno(TSRMLS_D);
+
+PHPAPI int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC);
+PHPAPI int php_output_write(const char *str, size_t len TSRMLS_DC);
+
+PHPAPI int php_output_flush(TSRMLS_D);
+PHPAPI void php_output_flush_all(TSRMLS_D);
+PHPAPI int php_output_clean(TSRMLS_D);
+PHPAPI void php_output_clean_all(TSRMLS_D);
+PHPAPI int php_output_end(TSRMLS_D);
+PHPAPI void php_output_end_all(TSRMLS_D);
+PHPAPI int php_output_discard(TSRMLS_D);
+PHPAPI void php_output_discard_all(TSRMLS_D);
+
+PHPAPI int php_output_get_contents(zval *p TSRMLS_DC);
+PHPAPI int php_output_get_length(zval *p TSRMLS_DC);
+PHPAPI int php_output_get_level(TSRMLS_D);
+
+PHPAPI int php_output_start_default(TSRMLS_D);
+PHPAPI int php_output_start_devnull(TSRMLS_D);
+
+PHPAPI int php_output_start_user(zval *output_handler, size_t chunk_size, int flags TSRMLS_DC);
+PHPAPI int php_output_start_internal(const char *name, size_t name_len, php_output_handler_func_t output_handler, size_t chunk_size, int flags TSRMLS_DC);
+
+PHPAPI php_output_handler *php_output_handler_create_user(zval *handler, size_t chunk_size, int flags TSRMLS_DC);
+PHPAPI php_output_handler *php_output_handler_create_internal(const char *name, size_t name_len, php_output_handler_context_func_t handler, size_t chunk_size, int flags TSRMLS_DC);
+
+PHPAPI void php_output_handler_set_context(php_output_handler *handler, void *opaq, void (*dtor)(void* TSRMLS_DC) TSRMLS_DC);
+PHPAPI int php_output_handler_start(php_output_handler *handler TSRMLS_DC);
+PHPAPI int php_output_handler_started(const char *name, size_t name_len TSRMLS_DC);
+PHPAPI int php_output_handler_hook(php_output_handler_hook_t type, void *arg TSRMLS_DC);
+PHPAPI void php_output_handler_dtor(php_output_handler *handler TSRMLS_DC);
+PHPAPI void php_output_handler_free(php_output_handler **handler TSRMLS_DC);
+
+PHPAPI int php_output_handler_conflict(const char *handler_new, size_t handler_new_len, const char *handler_set, size_t handler_set_len TSRMLS_DC);
+PHPAPI int php_output_handler_conflict_register(const char *handler_name, size_t handler_name_len, php_output_handler_conflict_check_t check_func TSRMLS_DC);
+PHPAPI int php_output_handler_reverse_conflict_register(const char *handler_name, size_t handler_name_len, php_output_handler_conflict_check_t check_func TSRMLS_DC);
+
+PHPAPI php_output_handler_alias_ctor_t *php_output_handler_alias(const char *handler_name, size_t handler_name_len TSRMLS_DC);
+PHPAPI int php_output_handler_alias_register(const char *handler_name, size_t handler_name_len, php_output_handler_alias_ctor_t func TSRMLS_DC);
+
END_EXTERN_C()
+
PHP_FUNCTION(ob_start);
PHP_FUNCTION(ob_flush);
PHP_FUNCTION(ob_clean);
@@ -64,51 +259,16 @@ PHP_FUNCTION(ob_get_status);
PHP_FUNCTION(ob_implicit_flush);
PHP_FUNCTION(ob_list_handlers);
-typedef struct _php_ob_buffer {
- char *buffer;
- uint size;
- uint text_length;
- int block_size;
- uint chunk_size;
- int status;
- zval *output_handler;
- php_output_handler_func_t internal_output_handler;
- char *internal_output_handler_buffer;
- uint internal_output_handler_buffer_size;
- char *handler_name;
- zend_bool erase;
-} php_ob_buffer;
-
-typedef struct _php_output_globals {
- int (*php_body_write)(const char *str, uint str_length TSRMLS_DC); /* string output */
- int (*php_header_write)(const char *str, uint str_length TSRMLS_DC); /* unbuffer string output */
- php_ob_buffer active_ob_buffer;
- unsigned char implicit_flush;
- char *output_start_filename;
- int output_start_lineno;
- zend_stack ob_buffers;
- int ob_nesting_level;
- zend_bool ob_lock;
- zend_bool disable_output;
-} php_output_globals;
-
-#ifdef ZTS
-#define OG(v) TSRMG(output_globals_id, php_output_globals *, v)
-ZEND_API extern int output_globals_id;
-#else
-#define OG(v) (output_globals.v)
-ZEND_API extern php_output_globals output_globals;
-#endif
-
-#define PHP_OUTPUT_HANDLER_START (1<<0)
-#define PHP_OUTPUT_HANDLER_CONT (1<<1)
-#define PHP_OUTPUT_HANDLER_END (1<<2)
-
-#define PHP_OUTPUT_HANDLER_INTERNAL 0
-#define PHP_OUTPUT_HANDLER_USER 1
-
PHP_FUNCTION(output_add_rewrite_var);
PHP_FUNCTION(output_reset_rewrite_vars);
+#endif
-#endif /* PHP_OUTPUT_H */
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
diff --git a/sapi/apache/mod_php5.c b/sapi/apache/mod_php5.c
index 25b5ef7..2b64270 100644
--- a/sapi/apache/mod_php5.c
+++ b/sapi/apache/mod_php5.c
@@ -329,7 +329,7 @@ static void php_apache_request_shutdown(void *dummy)
{
TSRMLS_FETCH();
- php_output_set_status(0 TSRMLS_CC);
+ php_output_set_status(PHP_OUTPUT_DISABLED TSRMLS_CC);
if (AP(in_request)) {
AP(in_request) = 0;
php_request_shutdown(dummy);
diff --git a/sapi/apache/php_apache.c b/sapi/apache/php_apache.c
index 2eb9277..57d6f3b 100644
--- a/sapi/apache/php_apache.c
+++ b/sapi/apache/php_apache.c
@@ -368,7 +368,7 @@ PHP_FUNCTION(virtual)
RETURN_FALSE;
}
- php_end_ob_buffers(1 TSRMLS_CC);
+ php_output_end_all(TSRMLS_C);
php_header(TSRMLS_C);
if (run_sub_req(rr)) {
diff --git a/sapi/apache2handler/php_functions.c b/sapi/apache2handler/php_functions.c
index 32f6b57..3b275d3 100644
--- a/sapi/apache2handler/php_functions.c
+++ b/sapi/apache2handler/php_functions.c
@@ -91,7 +91,7 @@ PHP_FUNCTION(virtual)
}
/* Flush everything. */
- php_end_ob_buffers(1 TSRMLS_CC);
+ php_output_end_all(TSRMLS_C);
php_header(TSRMLS_C);
/* Ensure that the ap_r* layer for the main request is flushed, to
diff --git a/sapi/apache_hooks/mod_php5.c b/sapi/apache_hooks/mod_php5.c
index aaedb69..8e7cd2f 100644
--- a/sapi/apache_hooks/mod_php5.c
+++ b/sapi/apache_hooks/mod_php5.c
@@ -453,7 +453,7 @@ static void php_apache_request_shutdown(void *dummy)
{
TSRMLS_FETCH();
AP(current_hook) = AP_CLEANUP;
- php_output_set_status(0 TSRMLS_CC);
+ php_output_set_status(PHP_OUTPUT_DISABLED TSRMLS_CC);
SG(server_context) = NULL; /* The server context (request) is invalid by the time run_cleanups() is called */
if(SG(sapi_started)) {
php_request_shutdown(dummy);
diff --git a/sapi/apache_hooks/php_apache.c b/sapi/apache_hooks/php_apache.c
index c0fd59e..bbbf415 100644
--- a/sapi/apache_hooks/php_apache.c
+++ b/sapi/apache_hooks/php_apache.c
@@ -1734,7 +1734,7 @@ PHP_FUNCTION(virtual)
RETURN_FALSE;
}
- php_end_ob_buffers(1 TSRMLS_CC);
+ php_output_end_all(TSRMLS_C);
php_header(TSRMLS_C);
if (run_sub_req(rr)) {
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
index 8b71faa..81aafcb 100644
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
@@ -1812,11 +1812,9 @@ consult the installation file that came with this distribution, or visit \n\
case '?':
fcgi_shutdown();
no_headers = 1;
- php_output_startup();
- php_output_activate(TSRMLS_C);
SG(headers_sent) = 1;
php_cgi_usage(argv[0]);
- php_end_ob_buffers(1 TSRMLS_CC);
+ php_output_end_all(TSRMLS_C);
exit_status = 0;
goto out;
}
@@ -1890,15 +1888,13 @@ consult the installation file that came with this distribution, or visit \n\
if (script_file) {
efree(script_file);
}
- php_output_startup();
- php_output_activate(TSRMLS_C);
SG(headers_sent) = 1;
php_printf("[PHP Modules]\n");
print_modules(TSRMLS_C);
php_printf("\n[Zend Modules]\n");
print_extensions(TSRMLS_C);
php_printf("\n");
- php_end_ob_buffers(1 TSRMLS_CC);
+ php_output_end_all(TSRMLS_C);
exit_status = 0;
goto out;
@@ -2117,7 +2113,7 @@ consult the installation file that came with this distribution, or visit \n\
if (open_file_for_scanning(&file_handle TSRMLS_CC) == SUCCESS) {
zend_strip(TSRMLS_C);
zend_file_handle_dtor(&file_handle TSRMLS_CC);
- php_end_ob_buffers(1 TSRMLS_CC);
+ php_output_teardown();
}
return SUCCESS;
break;
@@ -2132,7 +2128,7 @@ consult the installation file that came with this distribution, or visit \n\
goto fastcgi_request_done;
}
zend_file_handle_dtor(&file_handle TSRMLS_CC);
- php_end_ob_buffers(1 TSRMLS_CC);
+ php_output_teardown();
}
return SUCCESS;
}
@@ -2143,6 +2139,7 @@ consult the installation file that came with this distribution, or visit \n\
open_file_for_scanning(&file_handle TSRMLS_CC);
zend_indent();
zend_file_handle_dtor(&file_handle TSRMLS_CC);
+ php_output_teardown();
return SUCCESS;
break;
#endif
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
index bf272b4..8856bf8 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -822,7 +822,7 @@ int main(int argc, char *argv[])
}
request_started = 1;
php_cli_usage(argv[0]);
- php_end_ob_buffers(1 TSRMLS_CC);
+ php_output_end_all(TSRMLS_C);
exit_status=0;
goto out;
@@ -832,7 +832,7 @@ int main(int argc, char *argv[])
}
request_started = 1;
php_print_info(0xFFFFFFFF TSRMLS_CC);
- php_end_ob_buffers(1 TSRMLS_CC);
+ php_output_end_all(TSRMLS_C);
exit_status=0;
goto out;
@@ -846,7 +846,7 @@ int main(int argc, char *argv[])
php_printf("\n[Zend Modules]\n");
print_extensions(TSRMLS_C);
php_printf("\n");
- php_end_ob_buffers(1 TSRMLS_CC);
+ php_output_end_all(TSRMLS_C);
exit_status=0;
goto out;
@@ -869,7 +869,7 @@ int main(int argc, char *argv[])
#endif
get_zend_version()
);
- php_end_ob_buffers(1 TSRMLS_CC);
+ php_output_end_all(TSRMLS_C);
exit_status=0;
goto out;
diff --git a/sapi/milter/php_milter.c b/sapi/milter/php_milter.c
index 11724c4..6451864 100644
--- a/sapi/milter/php_milter.c
+++ b/sapi/milter/php_milter.c
@@ -1040,11 +1040,10 @@ int main(int argc, char *argv[])
while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
switch (c) {
case '?':
- php_output_startup();
- php_output_activate(TSRMLS_C);
+ php_output_tearup();
SG(headers_sent) = 1;
php_milter_usage(argv[0]);
- php_end_ob_buffers(1 TSRMLS_CC);
+ php_output_teardown();
exit(1);
break;
}
@@ -1088,11 +1087,10 @@ int main(int argc, char *argv[])
case 'h': /* help & quit */
case '?':
- php_output_startup();
- php_output_activate(TSRMLS_C);
+ php_output_tearup();
SG(headers_sent) = 1;
php_milter_usage(argv[0]);
- php_end_ob_buffers(1 TSRMLS_CC);
+ php_output_teardown();
exit(1);
break;
@@ -1112,7 +1110,7 @@ int main(int argc, char *argv[])
SG(headers_sent) = 1;
SG(request_info).no_headers = 1;
php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2010 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
- php_end_ob_buffers(1 TSRMLS_CC);
+ php_output_teardown();
exit(1);
break;
diff --git a/sapi/nsapi/nsapi.c b/sapi/nsapi/nsapi.c
index e2048fd..0b5f005 100644
--- a/sapi/nsapi/nsapi.c
+++ b/sapi/nsapi/nsapi.c
@@ -347,7 +347,7 @@ PHP_FUNCTION(nsapi_virtual)
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include uri '%s' - Sub-requests do not work with zlib.output_compression", uri);
RETURN_FALSE;
} else {
- php_end_ob_buffers(1 TSRMLS_CC);
+ php_output_end_all(TSRMLS_C);
php_header(TSRMLS_C);
/* do the sub-request */
diff --git a/tests/output/bug46897.phpt b/tests/output/bug46897.phpt
index 6cfb102..8fe80bc 100644
--- a/tests/output/bug46897.phpt
+++ b/tests/output/bug46897.phpt
@@ -18,10 +18,10 @@ echo 'Done';
?>
--EXPECTF--
[callback:1]Attempt to flush unerasable buffer - should fail...
-Notice: ob_flush(): failed to flush buffer callback. in %s on line %d
+Notice: ob_flush(): failed to flush buffer of callback (0) in %s on line %d
bool(false)
string(%d) "Attempt to flush unerasable buffer - should fail...
-Notice: ob_flush(): failed to flush buffer callback. in %s on line %d
+Notice: ob_flush(): failed to flush buffer of callback (0) in %s on line %d
bool(false)
"
Done
diff --git a/tests/output/ob_011.phpt b/tests/output/ob_011.phpt
index a90fd56..35b0388 100644
--- a/tests/output/ob_011.phpt
+++ b/tests/output/ob_011.phpt
@@ -1,7 +1,5 @@
--TEST--
output buffering - fatalism
---XFAIL--
-This test will fail until the fix in revision r214155 is backported from php 6
--FILE--
<?php
function obh($s)
diff --git a/tests/output/ob_013.phpt b/tests/output/ob_013.phpt
index ce5b5e5..e96de46 100644
--- a/tests/output/ob_013.phpt
+++ b/tests/output/ob_013.phpt
@@ -37,67 +37,69 @@ Array
)
Array
(
- [level] => 5
- [type] => 1
- [status] => 1
[name] => d
- [del] => 1
+ [type] => 1
+ [flags] => 4209
+ [level] => 4
+ [chunk_size] => %d
+ [buffer_size] => 16384
+ [buffer_used] => 96
)
Array
(
[0] => Array
(
- [chunk_size] => 0
- [size] => 40960
- [block_size] => 10240
- [type] => 1
- [status] => 0
[name] => default output handler
- [del] => 1
+ [type] => 0
+ [flags] => 112
+ [level] => 0
+ [chunk_size] => %d
+ [buffer_size] => 16384
+ [buffer_used] => 0
)
[1] => Array
(
- [chunk_size] => 0
- [size] => 40960
- [block_size] => 10240
- [type] => 1
- [status] => 0
[name] => a
- [del] => 1
+ [type] => 1
+ [flags] => 113
+ [level] => 1
+ [chunk_size] => %d
+ [buffer_size] => 16384
+ [buffer_used] => 0
)
[2] => Array
(
- [chunk_size] => 0
- [size] => 40960
- [block_size] => 10240
- [type] => 1
- [status] => 0
[name] => b
- [del] => 1
+ [type] => 1
+ [flags] => 113
+ [level] => 2
+ [chunk_size] => %d
+ [buffer_size] => 16384
+ [buffer_used] => 0
)
[3] => Array
(
- [chunk_size] => 0
- [size] => 40960
- [block_size] => 10240
- [type] => 1
- [status] => 0
[name] => c
- [del] => 1
+ [type] => 1
+ [flags] => 113
+ [level] => 3
+ [chunk_size] => %d
+ [buffer_size] => 16384
+ [buffer_used] => 4
)
[4] => Array
(
- [chunk_size] => 0
- [size] => 40960
- [block_size] => 10240
- [type] => 1
- [status] => 1
[name] => d
- [del] => 1
+ [type] => 1
+ [flags] => 4209
+ [level] => 4
+ [chunk_size] => %d
+ [buffer_size] => 16384
+ [buffer_used] => %d
)
-) \ No newline at end of file
+)
diff --git a/tests/output/ob_017.phpt b/tests/output/ob_017.phpt
index fc50e2f..070df60 100644
--- a/tests/output/ob_017.phpt
+++ b/tests/output/ob_017.phpt
@@ -24,11 +24,11 @@ yes!
yes!
Array
(
- [0] => 3: yes
- [1] => 2: !
+ [0] => 1: yes
+ [1] => 4: !
- [2] => 2: no
- [3] => 2: yes!
+ [2] => 2:
+ [3] => 0: yes!
- [4] => 4: no
-) \ No newline at end of file
+ [4] => 10:
+)
diff --git a/tests/output/ob_clean_basic_001.phpt b/tests/output/ob_clean_basic_001.phpt
index c93bea3..afaa7e2 100644
--- a/tests/output/ob_clean_basic_001.phpt
+++ b/tests/output/ob_clean_basic_001.phpt
@@ -29,8 +29,8 @@ echo "Done";
-- Testing ob_clean() function with Zero arguments --
-Notice: ob_clean(): failed to delete buffer. No buffer to delete. in %s on line 12
+Notice: ob_clean(): failed to delete buffer. No buffer to delete in %s on line 12
bool(false)
string(61) "bool(true)
Ensure the buffer is still active after the clean."
-Done \ No newline at end of file
+Done
diff --git a/tests/output/ob_end_clean_basic_001.phpt b/tests/output/ob_end_clean_basic_001.phpt
index 0b694e3..54e840b 100644
--- a/tests/output/ob_end_clean_basic_001.phpt
+++ b/tests/output/ob_end_clean_basic_001.phpt
@@ -21,11 +21,11 @@ var_dump(ob_end_clean());
?>
--EXPECTF--
-Notice: ob_end_clean(): failed to delete buffer. No buffer to delete. in %s on line 7
+Notice: ob_end_clean(): failed to delete buffer. No buffer to delete in %s on line 7
bool(false)
bool(true)
bool(true)
-Notice: ob_end_clean(): failed to delete buffer. No buffer to delete. in %s on line 16
+Notice: ob_end_clean(): failed to delete buffer. No buffer to delete in %s on line 16
bool(false)
diff --git a/tests/output/ob_end_flush_basic_001.phpt b/tests/output/ob_end_flush_basic_001.phpt
index 7515fac..cba7802 100644
--- a/tests/output/ob_end_flush_basic_001.phpt
+++ b/tests/output/ob_end_flush_basic_001.phpt
@@ -30,12 +30,12 @@ echo "Done";
-- Testing ob_end_flush() function with Zero arguments --
-Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush. in %s on line 12
+Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush in %s on line 12
bool(false)
bool(true)
Hello
bool(true)
-Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush. in %s on line 21
+Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush in %s on line 21
bool(false)
-Done \ No newline at end of file
+Done
diff --git a/tests/output/ob_flush_basic_001.phpt b/tests/output/ob_flush_basic_001.phpt
index 91fb695..57de5e3 100644
--- a/tests/output/ob_flush_basic_001.phpt
+++ b/tests/output/ob_flush_basic_001.phpt
@@ -30,10 +30,10 @@ echo "Done";
-- Testing ob_flush() function with Zero arguments --
-Notice: ob_flush(): failed to flush buffer. No buffer to flush. in %s on line 12
+Notice: ob_flush(): failed to flush buffer. No buffer to flush in %s on line 12
bool(false)
This should get flushed.
bool(true)
Ensure the buffer is still active after the flush.
bool(true)
-Done \ No newline at end of file
+Done
diff --git a/tests/output/ob_get_clean_basic_001.phpt b/tests/output/ob_get_clean_basic_001.phpt
index 07673df..b57ddab 100644
--- a/tests/output/ob_get_clean_basic_001.phpt
+++ b/tests/output/ob_get_clean_basic_001.phpt
@@ -14,5 +14,6 @@ echo "Hello World";
var_dump(ob_get_clean());
?>
--EXPECTF--
+Notice: ob_get_clean(): failed to delete buffer. No buffer to delete in %s on line 7
bool(false)
string(11) "Hello World" \ No newline at end of file
diff --git a/tests/output/ob_get_level_basic_001.phpt b/tests/output/ob_get_level_basic_001.phpt
index 78217e4..65f3291 100644
--- a/tests/output/ob_get_level_basic_001.phpt
+++ b/tests/output/ob_get_level_basic_001.phpt
@@ -42,6 +42,6 @@ int(2)
int(1)
int(0)
-Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush. in %s on line 26
+Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush in %s on line 26
int(0)
-Done \ No newline at end of file
+Done
diff --git a/tests/output/ob_get_status.phpt b/tests/output/ob_get_status.phpt
index a6a3498..9580729 100644
--- a/tests/output/ob_get_status.phpt
+++ b/tests/output/ob_get_status.phpt
@@ -15,20 +15,19 @@ var_dump($status);
array(1) {
[0]=>
array(7) {
+ ["name"]=>
+ string(22) "default output handler"
+ ["type"]=>
+ int(0)
+ ["flags"]=>
+ int(112)
+ ["level"]=>
+ int(0)
["chunk_size"]=>
int(0)
- ["size"]=>
- int(40960)
- ["block_size"]=>
- int(10240)
- ["type"]=>
- int(1)
- ["status"]=>
+ ["buffer_size"]=>
+ int(16384)
+ ["buffer_used"]=>
int(0)
- ["name"]=>
- string(22) "default output handler"
- ["del"]=>
- bool(true)
}
}
-
diff --git a/tests/output/ob_start_basic_004.phpt b/tests/output/ob_start_basic_004.phpt
index 39d3aad..16f09e8 100644
--- a/tests/output/ob_start_basic_004.phpt
+++ b/tests/output/ob_start_basic_004.phpt
@@ -1,12 +1,12 @@
--TEST--
-ob_start() chunk_size: confirm buffer is flushed after any output call that causes its length to equal or exceed chunk_size.
+ob_start() chunk_size: confirm buffer is flushed after any output call that causes its length to equal or exceed chunk_size.
--FILE--
<?php
/*
* proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]])
* Function is implemented in main/output.c
*/
-
+// In HEAD, $chunk_size value of 1 should not have any special behaviour (http://marc.info/?l=php-internals&m=123476465621346&w=2).
function callback($string) {
global $callback_invocations;
$callback_invocations++;
@@ -40,7 +40,15 @@ f[call:1; len:8]12345678
f[call:1; len:8]12345678
----( chunk_size: 1, output append size: 1 )----
-f[call:1; len:8]12345678
+f[call:1; len:1]1
+f[call:2; len:1]2
+f[call:3; len:1]3
+f[call:4; len:1]4
+f[call:5; len:1]5
+f[call:6; len:1]6
+f[call:7; len:1]7
+f[call:8; len:1]8
+f[call:9; len:0]
----( chunk_size: 2, output append size: 1 )----
f[call:1; len:2]12
@@ -85,7 +93,9 @@ f[call:1; len:8]12345678
f[call:1; len:8]12345678
----( chunk_size: 1, output append size: 4 )----
-f[call:1; len:8]12345678
+f[call:1; len:4]1234
+f[call:2; len:4]5678
+f[call:3; len:0]
----( chunk_size: 2, output append size: 4 )----
f[call:1; len:4]1234
diff --git a/tests/output/ob_start_basic_006.phpt b/tests/output/ob_start_basic_006.phpt
index e24ebd6..ff7a0cd 100644
--- a/tests/output/ob_start_basic_006.phpt
+++ b/tests/output/ob_start_basic_006.phpt
@@ -1,5 +1,5 @@
--TEST--
-ob_start(): multiple buffer initialization with a single call, using arrays.
+ob_start(): ensure multiple buffer initialization with a single call using arrays is not supported on PHP6 (http://bugs.php.net/42641)
--FILE--
<?php
/*
@@ -72,46 +72,37 @@ var_dump(ob_start(array('f', 'C::g', array(array($c, "g"), array($c, "h")))));
checkAndClean();
?>
--EXPECTF--
-
---> Test arrays:
-f[call:1; len:34] - bool(true)
+
+Notice: ob_start(): failed to create buffer in %s on line 44
+bool(false)
Array
(
- [0] => f
)
-f[call:3; len:68] - f[call:2; len:47] - bool(true)
+Notice: ob_start(): failed to create buffer in %s on line 47
+bool(false)
Array
(
- [0] => f
- [1] => f
)
-
-f[call:5; len:150] - C::g[call:2; len:125] - f[call:4; len:103] - C::g[call:1; len:79] - bool(true)
+Notice: ob_start(): failed to create buffer in %s on line 50
+bool(false)
Array
(
- [0] => f
- [1] => C::g
- [2] => f
- [3] => C::g
)
-
-
-
-f[call:6; len:35] - bool(false)
+Notice: ob_start(): failed to create buffer in %s on line 53
+bool(false)
Array
(
- [0] => f
)
-f[call:7; len:35] - bool(false)
+Notice: ob_start(): failed to create buffer in %s on line 56
+bool(false)
Array
(
- [0] => f
)
-
C::h[call:1; len:37; id:originalID] - bool(true)
Array
(
@@ -124,11 +115,9 @@ Array
[0] => C::h
)
-f[call:8; len:175] - C::g[call:4; len:150] - C::g[call:3; len:125] - C::h[call:3; len:82; id:changedIDagain] - bool(true)
+
+Notice: ob_start(): failed to create buffer in %s on line 68
+bool(false)
Array
(
- [0] => f
- [1] => C::g
- [2] => C::g
- [3] => C::h
-) \ No newline at end of file
+)
diff --git a/tests/output/ob_start_basic_unerasable_002.phpt b/tests/output/ob_start_basic_unerasable_002.phpt
index 2ffcbb9..21db1f3 100644
--- a/tests/output/ob_start_basic_unerasable_002.phpt
+++ b/tests/output/ob_start_basic_unerasable_002.phpt
@@ -21,13 +21,13 @@ var_dump(ob_get_level());
--EXPECTF--
[callback:1]All of the following calls will fail to clean/remove the topmost buffer:
-Notice: ob_clean(): failed to delete buffer callback. in %s on line 11
+Notice: ob_clean(): failed to delete buffer of callback (0) in %s on line 11
bool(false)
-Notice: ob_end_clean(): failed to delete buffer callback. in %s on line 12
+Notice: ob_end_clean(): failed to discard buffer of callback (0) in %s on line 12
bool(false)
-Notice: ob_end_flush(): failed to delete buffer callback. in %s on line 13
+Notice: ob_end_flush(): failed to send buffer of callback (0) in %s on line 13
bool(false)
The OB nesting will still be 1 level deep:
int(1) \ No newline at end of file
diff --git a/tests/output/ob_start_basic_unerasable_003.phpt b/tests/output/ob_start_basic_unerasable_003.phpt
index d201414..6eb6418 100644
--- a/tests/output/ob_start_basic_unerasable_003.phpt
+++ b/tests/output/ob_start_basic_unerasable_003.phpt
@@ -10,12 +10,13 @@ function callback($string) {
ob_start('callback', 0, false);
-echo "This call will fail to obtain the content, since it is also requesting a clean:\n";
+echo "This call will obtain the content, but will not clean the buffer.";
$str = ob_get_clean();
var_dump($str);
?>
--EXPECTF--
-[callback:1]This call will fail to obtain the content, since it is also requesting a clean:
+[callback:1]This call will obtain the content, but will not clean the buffer.
+Notice: ob_get_clean(): failed to discard buffer of callback (0) in %s on line 11
-Notice: ob_get_clean(): failed to delete buffer callback. in %s on line 11
-bool(false) \ No newline at end of file
+Notice: ob_get_clean(): failed to delete buffer of callback (0) in %s on line 11
+string(65) "This call will obtain the content, but will not clean the buffer." \ No newline at end of file
diff --git a/tests/output/ob_start_basic_unerasable_004.phpt b/tests/output/ob_start_basic_unerasable_004.phpt
index 6669856..62d9756 100644
--- a/tests/output/ob_start_basic_unerasable_004.phpt
+++ b/tests/output/ob_start_basic_unerasable_004.phpt
@@ -10,12 +10,13 @@ function callback($string) {
ob_start('callback', 0, false);
-echo "This call will fail to flush and fail to obtain the content:\n";
+echo "This call will obtain the content, but will not flush the buffer.";
$str = ob_get_flush();
var_dump($str);
?>
--EXPECTF--
-[callback:1]This call will fail to flush and fail to obtain the content:
+[callback:1]This call will obtain the content, but will not flush the buffer.
+Notice: ob_get_flush(): failed to send buffer of callback (0) in %s on line 11
-Notice: ob_get_flush(): failed to delete buffer callback. in %s on line 11
-bool(false)
+Notice: ob_get_flush(): failed to delete buffer of callback (0) in %s on line 11
+string(65) "This call will obtain the content, but will not flush the buffer." \ No newline at end of file
diff --git a/tests/output/ob_start_basic_unerasable_005.phpt b/tests/output/ob_start_basic_unerasable_005.phpt
index 7be71e5..2c52f00 100644
--- a/tests/output/ob_start_basic_unerasable_005.phpt
+++ b/tests/output/ob_start_basic_unerasable_005.phpt
@@ -17,9 +17,9 @@ var_dump(ob_get_contents());
?>
--EXPECTF--
[callback:1]Attempt to flush unerasable buffer - should fail...
-Notice: ob_flush(): failed to flush buffer callback. in %s on line 11
+Notice: ob_flush(): failed to flush buffer of callback (0) in %s on line 11
bool(false)
string(%d) "Attempt to flush unerasable buffer - should fail...
-Notice: ob_flush(): failed to flush buffer callback. in %s on line 11
+Notice: ob_flush(): failed to flush buffer of callback (0) in %s on line 11
bool(false)
"
diff --git a/tests/output/ob_start_error_001.phpt b/tests/output/ob_start_error_001.phpt
index ca02801..0f6daf3 100644
--- a/tests/output/ob_start_error_001.phpt
+++ b/tests/output/ob_start_error_001.phpt
@@ -30,19 +30,22 @@ var_dump(ob_start("justPrint", 0, "this should be a bool"));
?>
--EXPECTF--
-
- Too many arguments
Warning: ob_start() expects at most 3 parameters, 4 given in %s on line 17
-NULL
+bool(false)
- Arg 1 wrong type
-bool(true)
+
+Notice: ob_start(): failed to create buffer in %s on line 20
+bool(false)
- Arg 2 wrong type
Warning: ob_start() expects parameter 2 to be long, string given in %s on line 23
-NULL
+bool(false)
- Arg 3 wrong type
-bool(true) \ No newline at end of file
+
+Warning: ob_start() expects parameter 3 to be long, string given in %s on line 26
+bool(false)
diff --git a/tests/output/ob_start_error_002.phpt b/tests/output/ob_start_error_002.phpt
index aca2ad9..822aeb4 100644
--- a/tests/output/ob_start_error_002.phpt
+++ b/tests/output/ob_start_error_002.phpt
@@ -20,8 +20,15 @@ var_dump(ob_start("no"));
echo "done"
?>
--EXPECTF--
+Notice: ob_start(): failed to create buffer in %s on line 13
bool(false)
+
+Notice: ob_start(): failed to create buffer in %s on line 14
bool(false)
+
+Notice: ob_start(): failed to create buffer in %s on line 15
bool(false)
+
+Notice: ob_start(): failed to create buffer in %s on line 16
bool(false)
done \ No newline at end of file
diff --git a/tests/output/ob_start_error_003.phpt b/tests/output/ob_start_error_003.phpt
index ce2a249..7bb88b4 100644
--- a/tests/output/ob_start_error_003.phpt
+++ b/tests/output/ob_start_error_003.phpt
@@ -15,4 +15,6 @@ var_dump(ob_start(array($c)));
echo "done"
?>
--EXPECTF--
-Catchable fatal error: Object of class C could not be converted to string in %s on line 11 \ No newline at end of file
+Notice: ob_start(): failed to create buffer in %s on line 11
+bool(false)
+done \ No newline at end of file
diff --git a/tests/output/ob_start_error_004.phpt b/tests/output/ob_start_error_004.phpt
index ec6d44d..aeb5be9 100644
--- a/tests/output/ob_start_error_004.phpt
+++ b/tests/output/ob_start_error_004.phpt
@@ -15,4 +15,6 @@ var_dump(ob_start(array($c, 'f')));
echo "done"
?>
--EXPECTF--
-Catchable fatal error: Object of class C could not be converted to string in %s on line 11 \ No newline at end of file
+Notice: ob_start(): failed to create buffer in %s on line 11
+bool(false)
+done \ No newline at end of file