int final_buffer_length=0;
zval *alternate_buffer=NULL;
char *to_be_destroyed_buffer;
+ char *internal_output_handler_buffer;
+ int status;
SLS_FETCH();
OLS_FETCH();
if (OG(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;
+ }
- if (OG(active_ob_buffer).output_handler) {
+ if (OG(active_ob_buffer).internal_output_handler) {
+ internal_output_handler_buffer = OG(active_ob_buffer).internal_output_handler_buffer;
+ OG(active_ob_buffer).internal_output_handler(OG(active_ob_buffer).buffer, OG(active_ob_buffer).text_length, &internal_output_handler_buffer, status);
+ } else if (OG(active_ob_buffer).output_handler) {
zval **params[2];
zval *orig_buffer;
zval *z_status;
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;
- }
+ Z_LVAL_P(z_status) = status;
params[0] = &orig_buffer;
params[1] = &z_status;
OG(active_ob_buffer).status |= PHP_OUTPUT_HANDLER_START;
OG(php_body_write) = php_b_body_write;
}
+ if (OG(active_ob_buffer).internal_output_handler
+ && (internal_output_handler_buffer != OG(active_ob_buffer).internal_output_handler_buffer)) {
+ efree(internal_output_handler_buffer);
+ }
}
}
+PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t internal_output_handler, uint buffer_size)
+{
+ OLS_FETCH();
+
+ if (OG(nesting_level)==0) {
+ 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;
+}
+
+
/*
* Output buffering - implementation
*/
OG(active_ob_buffer).output_handler = output_handler;
OG(active_ob_buffer).chunk_size = chunk_size;
OG(active_ob_buffer).status = 0;
+ OG(active_ob_buffer).internal_output_handler = NULL;
}
#include "php.h"
+typedef void (*php_output_handler_func_t)(char *output, uint output_len, char **handled_output, int status);
+
PHPAPI void php_output_startup(void);
void php_output_register_constants(void);
PHPAPI int php_body_write(const char *str, uint str_length);
PHPAPI void php_end_implicit_flush(void);
PHPAPI char *php_get_output_start_filename(void);
PHPAPI int php_get_output_start_lineno(void);
+PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t internal_output_handler, uint buffer_size);
PHP_FUNCTION(ob_start);
PHP_FUNCTION(ob_end_flush);
uint size;
uint text_length;
int block_size;
- zval *output_handler;
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;
} php_ob_buffer;
typedef struct _php_output_globals {
int final_buffer_length=0;
zval *alternate_buffer=NULL;
char *to_be_destroyed_buffer;
+ char *internal_output_handler_buffer;
+ int status;
SLS_FETCH();
OLS_FETCH();
if (OG(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;
+ }
- if (OG(active_ob_buffer).output_handler) {
+ if (OG(active_ob_buffer).internal_output_handler) {
+ internal_output_handler_buffer = OG(active_ob_buffer).internal_output_handler_buffer;
+ OG(active_ob_buffer).internal_output_handler(OG(active_ob_buffer).buffer, OG(active_ob_buffer).text_length, &internal_output_handler_buffer, status);
+ } else if (OG(active_ob_buffer).output_handler) {
zval **params[2];
zval *orig_buffer;
zval *z_status;
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;
- }
+ Z_LVAL_P(z_status) = status;
params[0] = &orig_buffer;
params[1] = &z_status;
OG(active_ob_buffer).status |= PHP_OUTPUT_HANDLER_START;
OG(php_body_write) = php_b_body_write;
}
+ if (OG(active_ob_buffer).internal_output_handler
+ && (internal_output_handler_buffer != OG(active_ob_buffer).internal_output_handler_buffer)) {
+ efree(internal_output_handler_buffer);
+ }
}
}
+PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t internal_output_handler, uint buffer_size)
+{
+ OLS_FETCH();
+
+ if (OG(nesting_level)==0) {
+ 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;
+}
+
+
/*
* Output buffering - implementation
*/
OG(active_ob_buffer).output_handler = output_handler;
OG(active_ob_buffer).chunk_size = chunk_size;
OG(active_ob_buffer).status = 0;
+ OG(active_ob_buffer).internal_output_handler = NULL;
}
#include "php.h"
+typedef void (*php_output_handler_func_t)(char *output, uint output_len, char **handled_output, int status);
+
PHPAPI void php_output_startup(void);
void php_output_register_constants(void);
PHPAPI int php_body_write(const char *str, uint str_length);
PHPAPI void php_end_implicit_flush(void);
PHPAPI char *php_get_output_start_filename(void);
PHPAPI int php_get_output_start_lineno(void);
+PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t internal_output_handler, uint buffer_size);
PHP_FUNCTION(ob_start);
PHP_FUNCTION(ob_end_flush);
uint size;
uint text_length;
int block_size;
- zval *output_handler;
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;
} php_ob_buffer;
typedef struct _php_output_globals {