1999-10-27 18:30:41 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| PHP version 4.0 |
|
|
|
|
+----------------------------------------------------------------------+
|
2001-02-26 06:11:02 +00:00
|
|
|
| Copyright (c) 1997-2001 The PHP Group |
|
1999-10-27 18:30:41 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2000-05-18 15:34:45 +00:00
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
1999-10-27 18:30:41 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-05-18 15:34:45 +00:00
|
|
|
| http://www.php.net/license/2_02.txt. |
|
1999-10-27 18:30:41 +00:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
2000-06-06 18:54:00 +00:00
|
|
|
| Authors: Zeev Suraski <zeev@zend.com> |
|
2000-10-29 09:14:55 +00:00
|
|
|
| Thies C. Arntzen <thies@thieso.net> |
|
1999-10-27 18:30:41 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2000-07-24 01:40:02 +00:00
|
|
|
/* $Id$ */
|
1999-10-27 18:30:41 +00:00
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
#include "ext/standard/head.h"
|
2001-07-20 14:40:30 +00:00
|
|
|
#include "ext/standard/basic_functions.h"
|
1999-10-27 18:30:41 +00:00
|
|
|
#include "SAPI.h"
|
|
|
|
|
|
|
|
/* output functions */
|
2001-08-05 15:29:47 +00:00
|
|
|
static int php_ub_body_write(const char *str, uint str_length TSRMLS_DC);
|
|
|
|
static int php_ub_body_write_no_header(const char *str, uint str_length TSRMLS_DC);
|
|
|
|
static int php_b_body_write(const char *str, uint str_length TSRMLS_DC);
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2001-08-05 15:29:47 +00:00
|
|
|
static void php_ob_init(uint initial_size, uint block_size, zval *output_handler, uint chunk_size TSRMLS_DC);
|
|
|
|
static void php_ob_append(const char *text, uint text_length TSRMLS_DC);
|
1999-12-05 14:16:37 +00:00
|
|
|
#if 0
|
1999-10-27 18:30:41 +00:00
|
|
|
static void php_ob_prepend(const char *text, uint text_length);
|
1999-12-05 14:16:37 +00:00
|
|
|
#endif
|
1999-10-27 18:30:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef ZTS
|
|
|
|
int output_globals_id;
|
|
|
|
#else
|
|
|
|
php_output_globals output_globals;
|
|
|
|
#endif
|
|
|
|
|
2001-08-05 15:29:47 +00:00
|
|
|
static int php_default_output_func(const char *str, uint str_len TSRMLS_DC)
|
2001-05-07 22:00:13 +00:00
|
|
|
{
|
|
|
|
fwrite(str, 1, str_len, stderr);
|
2001-05-29 20:32:57 +00:00
|
|
|
return str_len;
|
2001-05-07 22:00:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-28 11:36:37 +00:00
|
|
|
static void php_output_init_globals(php_output_globals *output_globals_p TSRMLS_DC)
|
1999-10-27 18:30:41 +00:00
|
|
|
{
|
2001-05-07 22:00:13 +00:00
|
|
|
OG(php_body_write) = php_default_output_func;
|
|
|
|
OG(php_header_write) = php_default_output_func;
|
2000-01-13 17:37:25 +00:00
|
|
|
OG(implicit_flush) = 0;
|
2000-02-04 14:54:30 +00:00
|
|
|
OG(output_start_filename) = NULL;
|
|
|
|
OG(output_start_lineno) = 0;
|
1999-10-27 18:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-23 16:52:45 +00:00
|
|
|
/* Start output layer */
|
2001-07-02 18:17:10 +00:00
|
|
|
PHPAPI void php_output_startup(void)
|
1999-10-27 18:30:41 +00:00
|
|
|
{
|
|
|
|
#ifdef ZTS
|
2001-07-27 10:16:41 +00:00
|
|
|
ts_allocate_id(&output_globals_id, sizeof(php_output_globals), (ts_allocate_ctor) php_output_init_globals, NULL);
|
1999-11-26 18:34:27 +00:00
|
|
|
#else
|
2001-07-28 11:36:37 +00:00
|
|
|
php_output_init_globals(&output_globals TSRMLS_CC);
|
1999-10-27 18:30:41 +00:00
|
|
|
#endif
|
2001-07-02 18:17:10 +00:00
|
|
|
}
|
|
|
|
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2001-08-05 15:29:47 +00:00
|
|
|
PHPAPI void php_output_activate(TSRMLS_D)
|
2001-07-02 18:17:10 +00:00
|
|
|
{
|
|
|
|
OG(php_body_write) = php_ub_body_write;
|
|
|
|
OG(php_header_write) = sapi_module.ub_write;
|
2001-07-20 13:59:00 +00:00
|
|
|
OG(ob_nesting_level) = 0;
|
|
|
|
OG(ob_lock) = 0;
|
|
|
|
OG(disable_output) = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-05 15:29:47 +00:00
|
|
|
PHPAPI void php_output_set_status(zend_bool status TSRMLS_DC)
|
2001-07-20 13:59:00 +00:00
|
|
|
{
|
|
|
|
OG(disable_output) = !status;
|
2001-03-04 01:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-05 15:29:47 +00:00
|
|
|
void php_output_register_constants(TSRMLS_D)
|
2001-03-04 01:45:19 +00:00
|
|
|
{
|
2001-03-04 01:09:36 +00:00
|
|
|
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);
|
1999-10-27 18:30:41 +00:00
|
|
|
}
|
|
|
|
|
2001-03-04 01:45:19 +00:00
|
|
|
|
2001-08-05 15:55:43 +00:00
|
|
|
PHPAPI int php_body_write(const char *str, uint str_length TSRMLS_DC)
|
1999-10-27 18:30:41 +00:00
|
|
|
{
|
2001-08-05 15:29:47 +00:00
|
|
|
return OG(php_body_write)(str, str_length TSRMLS_CC);
|
1999-10-27 18:30:41 +00:00
|
|
|
}
|
|
|
|
|
2001-08-05 15:55:43 +00:00
|
|
|
PHPAPI int php_header_write(const char *str, uint str_length TSRMLS_DC)
|
1999-10-27 18:30:41 +00:00
|
|
|
{
|
2001-07-20 13:59:00 +00:00
|
|
|
if (OG(disable_output)) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
2001-08-05 15:29:47 +00:00
|
|
|
return OG(php_header_write)(str, str_length TSRMLS_CC);
|
2001-07-20 13:59:00 +00:00
|
|
|
}
|
1999-10-27 18:30:41 +00:00
|
|
|
}
|
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_start_ob_buffer
|
|
|
|
* Start output buffering */
|
2001-08-05 15:29:47 +00:00
|
|
|
PHPAPI int php_start_ob_buffer(zval *output_handler, uint chunk_size TSRMLS_DC)
|
1999-10-27 18:30:41 +00:00
|
|
|
{
|
2001-07-20 13:59:00 +00:00
|
|
|
if (OG(ob_lock)) {
|
2000-09-02 18:03:58 +00:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2001-03-04 15:46:13 +00:00
|
|
|
if (chunk_size) {
|
2001-08-05 15:29:47 +00:00
|
|
|
php_ob_init((chunk_size*3/2), chunk_size/2, output_handler, chunk_size TSRMLS_CC);
|
2001-03-04 15:46:13 +00:00
|
|
|
} else {
|
2001-08-05 15:29:47 +00:00
|
|
|
php_ob_init(40*1024, 10*1024, output_handler, chunk_size TSRMLS_CC);
|
2001-03-04 15:46:13 +00:00
|
|
|
}
|
1999-11-23 22:10:44 +00:00
|
|
|
OG(php_body_write) = php_b_body_write;
|
2000-09-02 18:03:58 +00:00
|
|
|
return SUCCESS;
|
1999-10-27 18:30:41 +00:00
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_end_ob_buffer
|
|
|
|
* End output buffering (one level) */
|
2001-08-05 15:29:47 +00:00
|
|
|
PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush TSRMLS_DC)
|
1999-10-27 18:30:41 +00:00
|
|
|
{
|
2000-09-02 18:03:58 +00:00
|
|
|
char *final_buffer=NULL;
|
2000-09-03 15:58:50 +00:00
|
|
|
int final_buffer_length=0;
|
2000-09-02 18:03:58 +00:00
|
|
|
zval *alternate_buffer=NULL;
|
2001-03-06 19:38:33 +00:00
|
|
|
char *to_be_destroyed_buffer;
|
|
|
|
char *to_be_destroyed_handled_output[2] = { 0, 0 };
|
2001-03-06 15:54:49 +00:00
|
|
|
int status;
|
2001-08-31 15:56:48 +00:00
|
|
|
php_ob_buffer *prev_ob_buffer_p=NULL;
|
|
|
|
php_ob_buffer orig_ob_buffer;
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2001-07-20 13:59:00 +00:00
|
|
|
if (OG(ob_nesting_level)==0) {
|
1999-10-27 18:30:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-03-06 15:54:49 +00:00
|
|
|
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;
|
|
|
|
}
|
2000-09-02 18:03:58 +00:00
|
|
|
|
2001-03-06 15:54:49 +00:00
|
|
|
if (OG(active_ob_buffer).internal_output_handler) {
|
2001-03-06 16:28:51 +00:00
|
|
|
final_buffer = OG(active_ob_buffer).internal_output_handler_buffer;
|
|
|
|
final_buffer_length = OG(active_ob_buffer).internal_output_handler_buffer_size;
|
2001-08-05 15:29:47 +00:00
|
|
|
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);
|
2001-03-06 15:54:49 +00:00
|
|
|
} else if (OG(active_ob_buffer).output_handler) {
|
2001-03-04 01:09:36 +00:00
|
|
|
zval **params[2];
|
2000-09-02 18:03:58 +00:00
|
|
|
zval *orig_buffer;
|
2001-03-04 01:09:36 +00:00
|
|
|
zval *z_status;
|
2000-09-02 18:03:58 +00:00
|
|
|
|
|
|
|
ALLOC_INIT_ZVAL(orig_buffer);
|
2001-08-05 01:43:02 +00:00
|
|
|
ZVAL_STRINGL(orig_buffer, OG(active_ob_buffer).buffer, OG(active_ob_buffer).text_length, 0);
|
2000-09-02 18:03:58 +00:00
|
|
|
orig_buffer->refcount=2; /* don't let call_user_function() destroy our buffer */
|
2001-03-17 03:03:50 +00:00
|
|
|
orig_buffer->is_ref=1;
|
2000-09-02 18:03:58 +00:00
|
|
|
|
2001-03-04 01:09:36 +00:00
|
|
|
ALLOC_INIT_ZVAL(z_status);
|
2001-08-05 01:43:02 +00:00
|
|
|
ZVAL_LONG(z_status, status);
|
2001-03-04 01:09:36 +00:00
|
|
|
|
2000-09-02 18:03:58 +00:00
|
|
|
params[0] = &orig_buffer;
|
2001-03-04 01:09:36 +00:00
|
|
|
params[1] = &z_status;
|
2001-07-20 13:59:00 +00:00
|
|
|
OG(ob_lock) = 1;
|
2001-07-30 08:24:42 +00:00
|
|
|
if (call_user_function_ex(CG(function_table), NULL, OG(active_ob_buffer).output_handler, &alternate_buffer, 2, params, 1, NULL TSRMLS_CC)==SUCCESS) {
|
2000-09-02 18:03:58 +00:00
|
|
|
convert_to_string_ex(&alternate_buffer);
|
|
|
|
final_buffer = alternate_buffer->value.str.val;
|
|
|
|
final_buffer_length = alternate_buffer->value.str.len;
|
|
|
|
}
|
2001-07-20 13:59:00 +00:00
|
|
|
OG(ob_lock) = 0;
|
2000-09-02 18:03:58 +00:00
|
|
|
zval_ptr_dtor(&OG(active_ob_buffer).output_handler);
|
|
|
|
if (orig_buffer->refcount==2) { /* free the zval */
|
|
|
|
FREE_ZVAL(orig_buffer);
|
|
|
|
} else {
|
2001-02-27 00:09:14 +00:00
|
|
|
orig_buffer->refcount-=2;
|
2000-09-02 18:03:58 +00:00
|
|
|
}
|
2001-03-04 01:09:36 +00:00
|
|
|
zval_ptr_dtor(&z_status);
|
2000-09-02 18:03:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!final_buffer) {
|
|
|
|
final_buffer = OG(active_ob_buffer).buffer;
|
|
|
|
final_buffer_length = OG(active_ob_buffer).text_length;
|
|
|
|
}
|
2000-11-02 16:46:30 +00:00
|
|
|
|
2001-07-20 13:59:00 +00:00
|
|
|
if (OG(ob_nesting_level)==1) { /* end buffering */
|
2000-07-29 14:46:09 +00:00
|
|
|
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;
|
|
|
|
}
|
2000-09-02 18:03:58 +00:00
|
|
|
}
|
2000-11-02 16:46:30 +00:00
|
|
|
|
|
|
|
to_be_destroyed_buffer = OG(active_ob_buffer).buffer;
|
2001-03-06 19:38:33 +00:00
|
|
|
if (OG(active_ob_buffer).internal_output_handler
|
2001-08-31 15:16:15 +00:00
|
|
|
&& (final_buffer != OG(active_ob_buffer).internal_output_handler_buffer)
|
|
|
|
&& (final_buffer != OG(active_ob_buffer).buffer)) {
|
2001-03-06 19:38:33 +00:00
|
|
|
to_be_destroyed_handled_output[0] = final_buffer;
|
|
|
|
}
|
2000-11-02 16:46:30 +00:00
|
|
|
|
2001-03-04 01:09:36 +00:00
|
|
|
if (!just_flush) {
|
2001-03-06 19:38:33 +00:00
|
|
|
if (OG(active_ob_buffer).internal_output_handler) {
|
|
|
|
to_be_destroyed_handled_output[1] = OG(active_ob_buffer).internal_output_handler_buffer;
|
|
|
|
}
|
2001-08-31 15:56:48 +00:00
|
|
|
}
|
|
|
|
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));
|
2000-11-02 16:46:30 +00:00
|
|
|
}
|
2001-03-04 01:09:36 +00:00
|
|
|
}
|
2001-08-31 15:56:48 +00:00
|
|
|
OG(ob_nesting_level)--;
|
2000-11-02 16:46:30 +00:00
|
|
|
|
2000-09-02 18:03:58 +00:00
|
|
|
if (send_buffer) {
|
2001-08-05 15:29:47 +00:00
|
|
|
OG(php_body_write)(final_buffer, final_buffer_length TSRMLS_CC);
|
2000-09-02 18:03:58 +00:00
|
|
|
}
|
2000-11-02 16:46:30 +00:00
|
|
|
|
2001-08-31 15:56:48 +00:00
|
|
|
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)++;
|
|
|
|
}
|
|
|
|
|
2000-09-02 18:03:58 +00:00
|
|
|
if (alternate_buffer) {
|
|
|
|
zval_ptr_dtor(&alternate_buffer);
|
1999-10-27 18:30:41 +00:00
|
|
|
}
|
2000-11-02 16:46:30 +00:00
|
|
|
|
2001-03-04 01:09:36 +00:00
|
|
|
if (!just_flush) {
|
|
|
|
efree(to_be_destroyed_buffer);
|
|
|
|
} 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;
|
2001-03-06 19:38:33 +00:00
|
|
|
}
|
|
|
|
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]);
|
2001-03-04 01:09:36 +00:00
|
|
|
}
|
1999-10-27 18:30:41 +00:00
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_end_ob_buffers
|
|
|
|
* End output buffering (all buffers) */
|
2001-08-05 15:29:47 +00:00
|
|
|
PHPAPI void php_end_ob_buffers(zend_bool send_buffer TSRMLS_DC)
|
2000-07-29 14:46:09 +00:00
|
|
|
{
|
2001-07-20 13:59:00 +00:00
|
|
|
while (OG(ob_nesting_level)!=0) {
|
2001-08-05 15:29:47 +00:00
|
|
|
php_end_ob_buffer(send_buffer, 0 TSRMLS_CC);
|
2000-07-29 14:46:09 +00:00
|
|
|
}
|
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
2000-07-29 14:46:09 +00:00
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_start_implicit_flush
|
|
|
|
*/
|
2001-08-05 15:29:47 +00:00
|
|
|
PHPAPI void php_start_implicit_flush(TSRMLS_D)
|
2000-01-13 17:37:25 +00:00
|
|
|
{
|
2001-08-05 15:29:47 +00:00
|
|
|
php_end_ob_buffer(1, 0 TSRMLS_CC); /* Switch out of output buffering if we're in it */
|
2000-01-13 17:54:51 +00:00
|
|
|
OG(implicit_flush)=1;
|
2000-01-13 17:37:25 +00:00
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
2000-01-13 17:37:25 +00:00
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_end_implicit_flush
|
|
|
|
*/
|
2001-08-05 15:29:47 +00:00
|
|
|
PHPAPI void php_end_implicit_flush(TSRMLS_D)
|
2000-01-13 17:37:25 +00:00
|
|
|
{
|
2000-01-13 17:54:51 +00:00
|
|
|
OG(implicit_flush)=0;
|
2000-01-13 17:37:25 +00:00
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
2000-01-13 17:37:25 +00:00
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_ob_set_internal_handler
|
|
|
|
*/
|
2001-08-05 15:29:47 +00:00
|
|
|
PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t internal_output_handler, uint buffer_size TSRMLS_DC)
|
2001-03-06 15:54:49 +00:00
|
|
|
{
|
2001-07-20 13:59:00 +00:00
|
|
|
if (OG(ob_nesting_level)==0) {
|
2001-03-06 15:54:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
2001-03-06 15:54:49 +00:00
|
|
|
|
1999-10-27 18:30:41 +00:00
|
|
|
/*
|
|
|
|
* Output buffering - implementation
|
|
|
|
*/
|
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_ob_allocate
|
|
|
|
*/
|
2001-08-05 15:29:47 +00:00
|
|
|
static inline void php_ob_allocate(TSRMLS_D)
|
1999-10-27 18:30:41 +00:00
|
|
|
{
|
2000-07-29 14:46:09 +00:00
|
|
|
if (OG(active_ob_buffer).size<OG(active_ob_buffer).text_length) {
|
|
|
|
while (OG(active_ob_buffer).size <= OG(active_ob_buffer).text_length) {
|
|
|
|
OG(active_ob_buffer).size+=OG(active_ob_buffer).block_size;
|
|
|
|
}
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2000-07-29 14:46:09 +00:00
|
|
|
OG(active_ob_buffer).buffer = (char *) erealloc(OG(active_ob_buffer).buffer, OG(active_ob_buffer).size+1);
|
1999-10-27 18:30:41 +00:00
|
|
|
}
|
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_ob_init
|
|
|
|
*/
|
2001-08-05 15:29:47 +00:00
|
|
|
static void php_ob_init(uint initial_size, uint block_size, zval *output_handler, uint chunk_size TSRMLS_DC)
|
1999-10-27 18:30:41 +00:00
|
|
|
{
|
2001-07-20 13:59:00 +00:00
|
|
|
if (OG(ob_nesting_level)>0) {
|
|
|
|
if (OG(ob_nesting_level)==1) { /* initialize stack */
|
2000-07-29 14:46:09 +00:00
|
|
|
zend_stack_init(&OG(ob_buffers));
|
|
|
|
}
|
|
|
|
zend_stack_push(&OG(ob_buffers), &OG(active_ob_buffer), sizeof(php_ob_buffer));
|
1999-10-27 18:30:41 +00:00
|
|
|
}
|
2001-07-20 13:59:00 +00:00
|
|
|
OG(ob_nesting_level)++;
|
2000-07-29 14:46:09 +00:00
|
|
|
OG(active_ob_buffer).block_size = block_size;
|
|
|
|
OG(active_ob_buffer).size = initial_size;
|
|
|
|
OG(active_ob_buffer).buffer = (char *) emalloc(initial_size+1);
|
|
|
|
OG(active_ob_buffer).text_length = 0;
|
2000-09-02 18:03:58 +00:00
|
|
|
OG(active_ob_buffer).output_handler = output_handler;
|
2000-11-23 18:43:18 +00:00
|
|
|
OG(active_ob_buffer).chunk_size = chunk_size;
|
2001-03-04 01:09:36 +00:00
|
|
|
OG(active_ob_buffer).status = 0;
|
2001-03-06 15:54:49 +00:00
|
|
|
OG(active_ob_buffer).internal_output_handler = NULL;
|
1999-10-27 18:30:41 +00:00
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_ob_append
|
|
|
|
*/
|
2001-08-05 15:29:47 +00:00
|
|
|
static void php_ob_append(const char *text, uint text_length TSRMLS_DC)
|
1999-10-27 18:30:41 +00:00
|
|
|
{
|
|
|
|
char *target;
|
|
|
|
int original_ob_text_length;
|
|
|
|
|
2000-07-29 14:46:09 +00:00
|
|
|
original_ob_text_length=OG(active_ob_buffer).text_length;
|
2001-02-27 00:09:14 +00:00
|
|
|
OG(active_ob_buffer).text_length = OG(active_ob_buffer).text_length + text_length;
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2001-08-05 15:29:47 +00:00
|
|
|
php_ob_allocate(TSRMLS_C);
|
2001-02-27 00:09:14 +00:00
|
|
|
target = OG(active_ob_buffer).buffer+original_ob_text_length;
|
|
|
|
memcpy(target, text, text_length);
|
|
|
|
target[text_length]=0;
|
2000-11-23 18:43:18 +00:00
|
|
|
|
|
|
|
if (OG(active_ob_buffer).chunk_size
|
2001-02-27 00:09:14 +00:00
|
|
|
&& OG(active_ob_buffer).text_length >= OG(active_ob_buffer).chunk_size) {
|
2000-11-23 18:43:18 +00:00
|
|
|
zval *output_handler = OG(active_ob_buffer).output_handler;
|
|
|
|
|
|
|
|
if (output_handler) {
|
|
|
|
output_handler->refcount++;
|
|
|
|
}
|
2001-08-05 15:29:47 +00:00
|
|
|
php_end_ob_buffer(1, 1 TSRMLS_CC);
|
2000-11-23 18:43:18 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-10-27 18:30:41 +00:00
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
1999-10-27 18:30:41 +00:00
|
|
|
|
1999-12-05 14:16:37 +00:00
|
|
|
#if 0
|
1999-10-27 18:30:41 +00:00
|
|
|
static void php_ob_prepend(const char *text, uint text_length)
|
|
|
|
{
|
|
|
|
char *p, *start;
|
2001-07-28 11:36:37 +00:00
|
|
|
TSRMLS_FETCH();
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2000-07-29 14:46:09 +00:00
|
|
|
OG(active_ob_buffer).text_length += text_length;
|
2001-08-05 15:29:47 +00:00
|
|
|
php_ob_allocate(TSRMLS_C);
|
1999-10-27 18:30:41 +00:00
|
|
|
|
1999-11-23 22:10:44 +00:00
|
|
|
/* 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);
|
1999-10-27 18:30:41 +00:00
|
|
|
|
|
|
|
while (--p>=start) {
|
|
|
|
p[text_length] = *p;
|
|
|
|
}
|
1999-11-23 22:10:44 +00:00
|
|
|
memcpy(OG(ob_buffer), text, text_length);
|
2000-07-29 14:46:09 +00:00
|
|
|
OG(ob_buffer)[OG(active_ob_buffer).text_length]=0;
|
1999-10-27 18:30:41 +00:00
|
|
|
}
|
1999-12-05 14:16:37 +00:00
|
|
|
#endif
|
1999-10-27 18:30:41 +00:00
|
|
|
|
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_ob_get_buffer
|
|
|
|
* Return the current output buffer */
|
2001-08-05 15:29:47 +00:00
|
|
|
int php_ob_get_buffer(pval *p TSRMLS_DC)
|
1999-10-27 18:30:41 +00:00
|
|
|
{
|
2001-07-20 13:59:00 +00:00
|
|
|
if (OG(ob_nesting_level)==0) {
|
1999-10-27 18:30:41 +00:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2001-08-05 01:43:02 +00:00
|
|
|
ZVAL_STRINGL(p, OG(active_ob_buffer).buffer, OG(active_ob_buffer).text_length, 1);
|
1999-10-27 18:30:41 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_ob_get_length
|
|
|
|
* Return the size of the current output buffer */
|
2001-08-05 15:29:47 +00:00
|
|
|
int php_ob_get_length(pval *p TSRMLS_DC)
|
2000-08-25 03:10:42 +00:00
|
|
|
{
|
2001-07-20 13:59:00 +00:00
|
|
|
if (OG(ob_nesting_level) == 0) {
|
2000-08-25 03:10:42 +00:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2001-08-05 01:43:02 +00:00
|
|
|
ZVAL_LONG(p, OG(active_ob_buffer).text_length);
|
2000-08-25 03:10:42 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
2000-08-25 03:10:42 +00:00
|
|
|
|
1999-10-27 18:30:41 +00:00
|
|
|
/*
|
|
|
|
* Wrapper functions - implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* buffered output function */
|
2001-08-05 15:29:47 +00:00
|
|
|
static int php_b_body_write(const char *str, uint str_length TSRMLS_DC)
|
1999-10-27 18:30:41 +00:00
|
|
|
{
|
2001-08-05 15:29:47 +00:00
|
|
|
php_ob_append(str, str_length TSRMLS_CC);
|
1999-10-27 18:30:41 +00:00
|
|
|
return str_length;
|
|
|
|
}
|
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_ub_body_write_no_header
|
|
|
|
*/
|
2001-08-05 15:29:47 +00:00
|
|
|
static int php_ub_body_write_no_header(const char *str, uint str_length TSRMLS_DC)
|
1999-10-27 18:30:41 +00:00
|
|
|
{
|
|
|
|
char *newstr = NULL;
|
2000-10-26 18:10:57 +00:00
|
|
|
size_t new_length=0;
|
1999-10-27 18:30:41 +00:00
|
|
|
int result;
|
|
|
|
|
2001-07-20 13:59:00 +00:00
|
|
|
if (OG(disable_output)) {
|
|
|
|
return 0;
|
2001-08-25 15:57:42 +00:00
|
|
|
}
|
1999-10-27 18:30:41 +00:00
|
|
|
if (newstr) {
|
|
|
|
str = newstr;
|
|
|
|
str_length = new_length;
|
|
|
|
}
|
|
|
|
|
2001-08-05 15:29:47 +00:00
|
|
|
result = OG(php_header_write)(str, str_length TSRMLS_CC);
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2000-01-13 17:54:51 +00:00
|
|
|
if (OG(implicit_flush)) {
|
2001-07-31 06:28:05 +00:00
|
|
|
sapi_flush(TSRMLS_C);
|
2000-01-13 17:54:51 +00:00
|
|
|
}
|
2000-01-13 17:37:25 +00:00
|
|
|
|
1999-10-27 18:30:41 +00:00
|
|
|
return result;
|
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_ub_body_write
|
|
|
|
*/
|
2001-08-05 15:29:47 +00:00
|
|
|
static int php_ub_body_write(const char *str, uint str_length TSRMLS_DC)
|
1999-10-27 18:30:41 +00:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
if (SG(request_info).headers_only) {
|
2001-03-31 22:53:19 +00:00
|
|
|
php_header();
|
1999-10-27 18:30:41 +00:00
|
|
|
zend_bailout();
|
|
|
|
}
|
1999-12-17 19:51:39 +00:00
|
|
|
if (php_header()) {
|
2001-07-30 08:24:42 +00:00
|
|
|
if (zend_is_compiling(TSRMLS_C)) {
|
2001-07-28 11:36:37 +00:00
|
|
|
OG(output_start_filename) = zend_get_compiled_filename(TSRMLS_C);
|
|
|
|
OG(output_start_lineno) = zend_get_compiled_lineno(TSRMLS_C);
|
2001-07-30 08:24:42 +00:00
|
|
|
} else if (zend_is_executing(TSRMLS_C)) {
|
2001-07-27 10:16:41 +00:00
|
|
|
OG(output_start_filename) = zend_get_executed_filename(TSRMLS_C);
|
|
|
|
OG(output_start_lineno) = zend_get_executed_lineno(TSRMLS_C);
|
2000-02-04 14:54:30 +00:00
|
|
|
}
|
|
|
|
|
1999-11-23 22:10:44 +00:00
|
|
|
OG(php_body_write) = php_ub_body_write_no_header;
|
2001-08-05 15:29:47 +00:00
|
|
|
result = php_ub_body_write_no_header(str, str_length TSRMLS_CC);
|
1999-10-27 18:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
1999-10-27 18:30:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* HEAD support
|
|
|
|
*/
|
|
|
|
|
2001-03-28 20:08:49 +00:00
|
|
|
/* {{{ proto void ob_start([ string user_function [, int chunk_size]])
|
2000-11-12 22:13:35 +00:00
|
|
|
Turn on Output Buffering (specifying an optional output handler). */
|
1999-10-27 18:30:41 +00:00
|
|
|
PHP_FUNCTION(ob_start)
|
|
|
|
{
|
2001-08-11 22:55:00 +00:00
|
|
|
zval *output_handler=NULL;
|
2001-02-27 00:09:14 +00:00
|
|
|
uint chunk_size=0;
|
2000-09-02 18:03:58 +00:00
|
|
|
|
|
|
|
switch (ZEND_NUM_ARGS()) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1: {
|
|
|
|
zval **output_handler_p;
|
|
|
|
|
|
|
|
if (zend_get_parameters_ex(1, &output_handler_p)==FAILURE) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
SEPARATE_ZVAL(output_handler_p);
|
|
|
|
output_handler = *output_handler_p;
|
|
|
|
output_handler->refcount++;
|
|
|
|
}
|
|
|
|
break;
|
2000-11-23 18:43:18 +00:00
|
|
|
case 2: {
|
|
|
|
zval **output_handler_p, **chunk_size_p;
|
|
|
|
|
|
|
|
if (zend_get_parameters_ex(2, &output_handler_p, &chunk_size_p)==FAILURE) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2001-08-11 22:55:00 +00:00
|
|
|
if (Z_STRLEN_PP(output_handler_p)>0) {
|
|
|
|
SEPARATE_ZVAL(output_handler_p);
|
|
|
|
output_handler = *output_handler_p;
|
|
|
|
output_handler->refcount++;
|
|
|
|
}
|
2000-11-23 18:43:18 +00:00
|
|
|
convert_to_long_ex(chunk_size_p);
|
2001-02-27 00:09:14 +00:00
|
|
|
chunk_size = (uint) Z_LVAL_PP(chunk_size_p);
|
2000-11-23 18:43:18 +00:00
|
|
|
}
|
|
|
|
break;
|
2000-09-03 15:58:50 +00:00
|
|
|
default:
|
|
|
|
ZEND_WRONG_PARAM_COUNT();
|
|
|
|
break;
|
2000-09-02 18:03:58 +00:00
|
|
|
}
|
2001-08-05 15:29:47 +00:00
|
|
|
if (php_start_ob_buffer(output_handler, chunk_size TSRMLS_CC)==FAILURE) {
|
2001-06-26 18:30:31 +00:00
|
|
|
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;
|
|
|
|
}
|
2001-07-20 13:59:00 +00:00
|
|
|
OG(ob_nesting_level) = 0;
|
2001-06-26 18:30:31 +00:00
|
|
|
php_error(E_ERROR, "Cannot use output buffering in output buffering display handlers");
|
2000-09-02 18:03:58 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
1999-10-27 18:30:41 +00:00
|
|
|
}
|
2000-04-18 19:18:47 +00:00
|
|
|
/* }}} */
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2000-04-18 20:00:21 +00:00
|
|
|
/* {{{ proto void ob_end_flush(void)
|
2000-04-18 19:18:47 +00:00
|
|
|
Flush (send) the output buffer, and turn off output buffering */
|
1999-10-27 18:30:41 +00:00
|
|
|
PHP_FUNCTION(ob_end_flush)
|
|
|
|
{
|
2001-08-05 15:29:47 +00:00
|
|
|
php_end_ob_buffer(1, 0 TSRMLS_CC);
|
1999-10-27 18:30:41 +00:00
|
|
|
}
|
2000-04-18 19:18:47 +00:00
|
|
|
/* }}} */
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2000-04-18 20:00:21 +00:00
|
|
|
/* {{{ proto void ob_end_clean(void)
|
2000-04-18 19:18:47 +00:00
|
|
|
Clean (erase) the output buffer, and turn off output buffering */
|
1999-10-27 18:30:41 +00:00
|
|
|
PHP_FUNCTION(ob_end_clean)
|
|
|
|
{
|
2001-08-05 15:29:47 +00:00
|
|
|
php_end_ob_buffer(0, 0 TSRMLS_CC);
|
1999-10-27 18:30:41 +00:00
|
|
|
}
|
2000-04-18 19:18:47 +00:00
|
|
|
/* }}} */
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2000-05-23 23:13:02 +00:00
|
|
|
/* {{{ proto string ob_get_contents(void)
|
2000-04-18 19:18:47 +00:00
|
|
|
Return the contents of the output buffer */
|
1999-10-27 18:30:41 +00:00
|
|
|
PHP_FUNCTION(ob_get_contents)
|
|
|
|
{
|
2001-08-05 15:29:47 +00:00
|
|
|
if (php_ob_get_buffer(return_value TSRMLS_CC)==FAILURE) {
|
1999-10-27 18:30:41 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2000-04-18 19:18:47 +00:00
|
|
|
/* }}} */
|
1999-10-27 18:30:41 +00:00
|
|
|
|
2000-08-25 03:10:42 +00:00
|
|
|
/* {{{ proto string ob_get_length(void)
|
|
|
|
Return the length of the output buffer */
|
|
|
|
PHP_FUNCTION(ob_get_length)
|
|
|
|
{
|
2001-08-05 15:29:47 +00:00
|
|
|
if (php_ob_get_length(return_value TSRMLS_CC)==FAILURE) {
|
2000-08-25 03:10:42 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2000-04-18 20:00:21 +00:00
|
|
|
/* {{{ proto void ob_implicit_flush([int flag])
|
|
|
|
Turn implicit flush on/off and is equivalent to calling flush() after every output call */
|
2000-01-13 17:37:25 +00:00
|
|
|
PHP_FUNCTION(ob_implicit_flush)
|
|
|
|
{
|
|
|
|
zval **zv_flag;
|
2000-01-15 17:23:18 +00:00
|
|
|
int flag;
|
2000-01-13 17:37:25 +00:00
|
|
|
|
|
|
|
switch(ZEND_NUM_ARGS()) {
|
|
|
|
case 0:
|
|
|
|
flag = 1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (zend_get_parameters_ex(1, &zv_flag)==FAILURE) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
convert_to_long_ex(zv_flag);
|
|
|
|
flag = (*zv_flag)->value.lval;
|
|
|
|
break;
|
2000-01-15 17:23:18 +00:00
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
break;
|
2000-01-13 17:37:25 +00:00
|
|
|
}
|
2000-01-13 17:54:51 +00:00
|
|
|
if (flag) {
|
2001-08-05 15:29:47 +00:00
|
|
|
php_start_implicit_flush(TSRMLS_C);
|
2000-01-13 17:54:51 +00:00
|
|
|
} else {
|
2001-08-05 15:29:47 +00:00
|
|
|
php_end_implicit_flush(TSRMLS_C);
|
2000-01-13 17:54:51 +00:00
|
|
|
}
|
2000-01-13 17:37:25 +00:00
|
|
|
}
|
2000-04-18 19:18:47 +00:00
|
|
|
/* }}} */
|
2000-01-13 17:37:25 +00:00
|
|
|
|
2001-08-05 15:29:47 +00:00
|
|
|
PHPAPI char *php_get_output_start_filename(TSRMLS_D)
|
2000-02-04 14:54:30 +00:00
|
|
|
{
|
|
|
|
return OG(output_start_filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-05 15:29:47 +00:00
|
|
|
PHPAPI int php_get_output_start_lineno(TSRMLS_D)
|
2000-02-04 14:54:30 +00:00
|
|
|
{
|
|
|
|
return OG(output_start_lineno);
|
|
|
|
}
|
|
|
|
|
1999-10-27 18:30:41 +00:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-06-06 13:06:12 +00:00
|
|
|
* vim600: sw=4 ts=4 tw=78 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4 tw=78
|
1999-10-27 18:30:41 +00:00
|
|
|
*/
|