* current output buffer (so we don't send data twice)
*/
if (tRes)
- php_end_ob_buffer(0);
+ php_end_ob_buffer(0, 0);
PUTS(tRes);
if (tRes)
SablotFree(tRes);
else
- php_end_ob_buffer(1);
+ php_end_ob_buffer(1, 0);
}
/* }}} */
PHPAPI void php_output_startup()
{
OLS_FETCH();
+ ELS_FETCH();
OG(php_body_write) = php_ub_body_write;
OG(php_header_write) = sapi_module.ub_write;
OG(nesting_level) = 0;
OG(lock) = 0;
+
+ 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);
}
PHPAPI int php_body_write(const char *str, uint str_length)
/* End output buffering (one level) */
-PHPAPI void php_end_ob_buffer(int send_buffer)
+PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush)
{
char *final_buffer=NULL;
int final_buffer_length=0;
}
if (OG(active_ob_buffer).output_handler) {
- zval **params[1];
+ zval **params[2];
zval *orig_buffer;
+ zval *z_status;
CLS_FETCH();
ALLOC_INIT_ZVAL(orig_buffer);
orig_buffer->type = IS_STRING;
orig_buffer->refcount=2; /* don't let call_user_function() destroy our buffer */
+ ALLOC_INIT_ZVAL(z_status);
+ Z_TYPE_P(z_status) = IS_LONG;
+ Z_LVAL_P(z_status) = 0;
+ if (!OG(active_ob_buffer).status & PHP_OUTPUT_HANDLER_START) {
+ /* our first call */
+ Z_LVAL_P(z_status) |= PHP_OUTPUT_HANDLER_START;
+ }
+ if (just_flush) {
+ Z_LVAL_P(z_status) |= PHP_OUTPUT_HANDLER_CONT;
+ } else {
+ Z_LVAL_P(z_status) |= PHP_OUTPUT_HANDLER_END;
+ }
+
params[0] = &orig_buffer;
+ params[1] = &z_status;
OG(lock) = 1;
- if (call_user_function_ex(CG(function_table), NULL, OG(active_ob_buffer).output_handler, &alternate_buffer, 1, params, 1, NULL)==SUCCESS) {
+ if (call_user_function_ex(CG(function_table), NULL, OG(active_ob_buffer).output_handler, &alternate_buffer, 2, params, 1, NULL)==SUCCESS) {
convert_to_string_ex(&alternate_buffer);
final_buffer = alternate_buffer->value.str.val;
final_buffer_length = alternate_buffer->value.str.len;
} else {
orig_buffer->refcount-=2;
}
+ zval_ptr_dtor(&z_status);
}
if (!final_buffer) {
to_be_destroyed_buffer = OG(active_ob_buffer).buffer;
- if (OG(nesting_level)>1) { /* restore previous buffer */
- php_ob_buffer *ob_buffer_p;
+ if (!just_flush) {
+ if (OG(nesting_level)>1) { /* restore previous buffer */
+ php_ob_buffer *ob_buffer_p;
- zend_stack_top(&OG(ob_buffers), (void **) &ob_buffer_p);
- OG(active_ob_buffer) = *ob_buffer_p;
- zend_stack_del_top(&OG(ob_buffers));
- if (OG(nesting_level)==2) { /* destroy the stack */
- zend_stack_destroy(&OG(ob_buffers));
+ zend_stack_top(&OG(ob_buffers), (void **) &ob_buffer_p);
+ OG(active_ob_buffer) = *ob_buffer_p;
+ zend_stack_del_top(&OG(ob_buffers));
+ if (OG(nesting_level)==2) { /* destroy the stack */
+ zend_stack_destroy(&OG(ob_buffers));
+ }
}
- }
+ }
if (send_buffer) {
OG(php_body_write)(final_buffer, final_buffer_length);
zval_ptr_dtor(&alternate_buffer);
}
- efree(to_be_destroyed_buffer);
+ if (!just_flush) {
+ efree(to_be_destroyed_buffer);
- OG(nesting_level)--;
+ OG(nesting_level)--;
+ } 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;
+ }
}
/* End output buffering (all buffers) */
-PHPAPI void php_end_ob_buffers(int send_buffer)
+PHPAPI void php_end_ob_buffers(zend_bool send_buffer)
{
OLS_FETCH();
while (OG(nesting_level)!=0) {
- php_end_ob_buffer(send_buffer);
+ php_end_ob_buffer(send_buffer, 0);
}
}
{
OLS_FETCH();
- php_end_ob_buffer(1); /* Switch out of output buffering if we're in it */
+ php_end_ob_buffer(1, 0); /* Switch out of output buffering if we're in it */
OG(implicit_flush)=1;
}
OG(active_ob_buffer).text_length = 0;
OG(active_ob_buffer).output_handler = output_handler;
OG(active_ob_buffer).chunk_size = chunk_size;
+ OG(active_ob_buffer).status = 0;
}
if (output_handler) {
output_handler->refcount++;
}
- php_end_ob_buffer(1);
- php_start_ob_buffer(output_handler, chunk_size);
+ php_end_ob_buffer(1, 1);
return;
}
}
Flush (send) the output buffer, and turn off output buffering */
PHP_FUNCTION(ob_end_flush)
{
- php_end_ob_buffer(1);
+ php_end_ob_buffer(1, 0);
}
/* }}} */
Clean (erase) the output buffer, and turn off output buffering */
PHP_FUNCTION(ob_end_clean)
{
- php_end_ob_buffer(0);
+ php_end_ob_buffer(0, 0);
}
/* }}} */
PHPAPI int php_body_write(const char *str, uint str_length);
PHPAPI int php_header_write(const char *str, uint str_length);
PHPAPI int php_start_ob_buffer(zval *output_handler, uint chunk_size);
-PHPAPI void php_end_ob_buffer(int send_buffer);
-PHPAPI void php_end_ob_buffers(int send_buffer);
+PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush);
+PHPAPI void php_end_ob_buffers(zend_bool send_buffer);
PHPAPI int php_ob_get_buffer(pval *p);
PHPAPI int php_ob_get_length(pval *p);
PHPAPI void php_start_implicit_flush(void);
int block_size;
zval *output_handler;
uint chunk_size;
+ int status;
} php_ob_buffer;
typedef struct _php_output_globals {
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)
#endif /* PHP_OUTPUT_H */
PHPAPI void php_output_startup()
{
OLS_FETCH();
+ ELS_FETCH();
OG(php_body_write) = php_ub_body_write;
OG(php_header_write) = sapi_module.ub_write;
OG(nesting_level) = 0;
OG(lock) = 0;
+
+ 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);
}
PHPAPI int php_body_write(const char *str, uint str_length)
/* End output buffering (one level) */
-PHPAPI void php_end_ob_buffer(int send_buffer)
+PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush)
{
char *final_buffer=NULL;
int final_buffer_length=0;
}
if (OG(active_ob_buffer).output_handler) {
- zval **params[1];
+ zval **params[2];
zval *orig_buffer;
+ zval *z_status;
CLS_FETCH();
ALLOC_INIT_ZVAL(orig_buffer);
orig_buffer->type = IS_STRING;
orig_buffer->refcount=2; /* don't let call_user_function() destroy our buffer */
+ ALLOC_INIT_ZVAL(z_status);
+ Z_TYPE_P(z_status) = IS_LONG;
+ Z_LVAL_P(z_status) = 0;
+ if (!OG(active_ob_buffer).status & PHP_OUTPUT_HANDLER_START) {
+ /* our first call */
+ Z_LVAL_P(z_status) |= PHP_OUTPUT_HANDLER_START;
+ }
+ if (just_flush) {
+ Z_LVAL_P(z_status) |= PHP_OUTPUT_HANDLER_CONT;
+ } else {
+ Z_LVAL_P(z_status) |= PHP_OUTPUT_HANDLER_END;
+ }
+
params[0] = &orig_buffer;
+ params[1] = &z_status;
OG(lock) = 1;
- if (call_user_function_ex(CG(function_table), NULL, OG(active_ob_buffer).output_handler, &alternate_buffer, 1, params, 1, NULL)==SUCCESS) {
+ if (call_user_function_ex(CG(function_table), NULL, OG(active_ob_buffer).output_handler, &alternate_buffer, 2, params, 1, NULL)==SUCCESS) {
convert_to_string_ex(&alternate_buffer);
final_buffer = alternate_buffer->value.str.val;
final_buffer_length = alternate_buffer->value.str.len;
} else {
orig_buffer->refcount-=2;
}
+ zval_ptr_dtor(&z_status);
}
if (!final_buffer) {
to_be_destroyed_buffer = OG(active_ob_buffer).buffer;
- if (OG(nesting_level)>1) { /* restore previous buffer */
- php_ob_buffer *ob_buffer_p;
+ if (!just_flush) {
+ if (OG(nesting_level)>1) { /* restore previous buffer */
+ php_ob_buffer *ob_buffer_p;
- zend_stack_top(&OG(ob_buffers), (void **) &ob_buffer_p);
- OG(active_ob_buffer) = *ob_buffer_p;
- zend_stack_del_top(&OG(ob_buffers));
- if (OG(nesting_level)==2) { /* destroy the stack */
- zend_stack_destroy(&OG(ob_buffers));
+ zend_stack_top(&OG(ob_buffers), (void **) &ob_buffer_p);
+ OG(active_ob_buffer) = *ob_buffer_p;
+ zend_stack_del_top(&OG(ob_buffers));
+ if (OG(nesting_level)==2) { /* destroy the stack */
+ zend_stack_destroy(&OG(ob_buffers));
+ }
}
- }
+ }
if (send_buffer) {
OG(php_body_write)(final_buffer, final_buffer_length);
zval_ptr_dtor(&alternate_buffer);
}
- efree(to_be_destroyed_buffer);
+ if (!just_flush) {
+ efree(to_be_destroyed_buffer);
- OG(nesting_level)--;
+ OG(nesting_level)--;
+ } 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;
+ }
}
/* End output buffering (all buffers) */
-PHPAPI void php_end_ob_buffers(int send_buffer)
+PHPAPI void php_end_ob_buffers(zend_bool send_buffer)
{
OLS_FETCH();
while (OG(nesting_level)!=0) {
- php_end_ob_buffer(send_buffer);
+ php_end_ob_buffer(send_buffer, 0);
}
}
{
OLS_FETCH();
- php_end_ob_buffer(1); /* Switch out of output buffering if we're in it */
+ php_end_ob_buffer(1, 0); /* Switch out of output buffering if we're in it */
OG(implicit_flush)=1;
}
OG(active_ob_buffer).text_length = 0;
OG(active_ob_buffer).output_handler = output_handler;
OG(active_ob_buffer).chunk_size = chunk_size;
+ OG(active_ob_buffer).status = 0;
}
if (output_handler) {
output_handler->refcount++;
}
- php_end_ob_buffer(1);
- php_start_ob_buffer(output_handler, chunk_size);
+ php_end_ob_buffer(1, 1);
return;
}
}
Flush (send) the output buffer, and turn off output buffering */
PHP_FUNCTION(ob_end_flush)
{
- php_end_ob_buffer(1);
+ php_end_ob_buffer(1, 0);
}
/* }}} */
Clean (erase) the output buffer, and turn off output buffering */
PHP_FUNCTION(ob_end_clean)
{
- php_end_ob_buffer(0);
+ php_end_ob_buffer(0, 0);
}
/* }}} */
PHPAPI int php_body_write(const char *str, uint str_length);
PHPAPI int php_header_write(const char *str, uint str_length);
PHPAPI int php_start_ob_buffer(zval *output_handler, uint chunk_size);
-PHPAPI void php_end_ob_buffer(int send_buffer);
-PHPAPI void php_end_ob_buffers(int send_buffer);
+PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush);
+PHPAPI void php_end_ob_buffers(zend_bool send_buffer);
PHPAPI int php_ob_get_buffer(pval *p);
PHPAPI int php_ob_get_length(pval *p);
PHPAPI void php_start_implicit_flush(void);
int block_size;
zval *output_handler;
uint chunk_size;
+ int status;
} php_ob_buffer;
typedef struct _php_output_globals {
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)
#endif /* PHP_OUTPUT_H */