From: Marcus Boerger Date: Mon, 5 Aug 2002 03:09:42 +0000 (+0000) Subject: -New function ob_list_handlers X-Git-Tag: dev~23 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fd26a5c0a99dbdfe0909473283a24125edaf2200;p=php -New function ob_list_handlers @- Added ob_list_handlers() which returns an array of all active output @ handlers. (marcus) --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 24df4bf049..6d30b50e04 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -731,6 +731,7 @@ function_entry basic_functions[] = { PHP_FE(ob_get_status, NULL) PHP_FE(ob_get_contents, NULL) PHP_FE(ob_implicit_flush, NULL) + PHP_FE(ob_list_handlers, NULL) /* functions from array.c */ PHP_FE(ksort, first_arg_force_ref) diff --git a/main/output.c b/main/output.c index 1461b37080..025a0aeeec 100644 --- a/main/output.c +++ b/main/output.c @@ -367,6 +367,42 @@ static void php_ob_init(uint initial_size, uint block_size, zval *output_handler } /* }}} */ +/* {{{ php_ob_list_each + */ + +static int php_ob_list_each(php_ob_buffer *ob_buffer, zval *ob_handler_array) +{ + if (!strcmp(ob_buffer->handler_name, "zlib output compression") && ob_buffer->internal_output_handler) { + add_next_index_string(ob_handler_array, "ob_gzhandler", 1); + } else { + add_next_index_string(ob_handler_array, ob_buffer->handler_name, 1); + } + return 0; +} +/* }}} */ + +/* {{{ proto array ob_list_handlers() + List all output_buffers in an array */ +PHP_FUNCTION(ob_list_handlers) +{ + if (ZEND_NUM_ARGS()!=0) { + WRONG_PARAM_COUNT; + return; + } + + if (array_init(return_value) == FAILURE) { + php_error(E_ERROR, "%s(): Unable to initialize array", get_active_function_name(TSRMLS_C)); + return; + } + 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); + } +} +/* }}} */ + /* {{{ php_ob_append */ static void php_ob_append(const char *text, uint text_length TSRMLS_DC) diff --git a/main/php_output.h b/main/php_output.h index 48f9bde31d..977c217d65 100644 --- a/main/php_output.h +++ b/main/php_output.h @@ -50,6 +50,7 @@ PHP_FUNCTION(ob_get_length); PHP_FUNCTION(ob_get_level); PHP_FUNCTION(ob_get_status); PHP_FUNCTION(ob_implicit_flush); +PHP_FUNCTION(ob_list_handlers); typedef struct _php_ob_buffer { char *buffer;