]> granicus.if.org Git - php/commitdiff
Initial work on internal output handlers - should be much quicker
authorZeev Suraski <zeev@php.net>
Tue, 6 Mar 2001 15:54:49 +0000 (15:54 +0000)
committerZeev Suraski <zeev@php.net>
Tue, 6 Mar 2001 15:54:49 +0000 (15:54 +0000)
ext/standard/output.c
ext/standard/php_output.h
main/output.c
main/php_output.h

index 6f2ad8140e2a3057b885ca499770b16b58912f6f..02c85756174116b47269cbedfde053bcfeb97d80 100644 (file)
@@ -123,14 +123,29 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush)
        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;
@@ -144,16 +159,7 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush)
 
                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;
@@ -218,6 +224,10 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush)
                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);
+       }
 }
 
 
@@ -249,6 +259,20 @@ PHPAPI void php_end_implicit_flush()
 }
 
 
+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
  */
@@ -285,6 +309,7 @@ static void php_ob_init(uint initial_size, uint block_size, zval *output_handler
        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;
 }
 
 
index 1792d20257a51b5aa485f4142beff9f1d9b44a43..0cb8647690c09cfcc7f846165dc971fb256afd79 100644 (file)
@@ -23,6 +23,8 @@
 
 #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);
@@ -36,6 +38,7 @@ PHPAPI void php_start_implicit_flush(void);
 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);
@@ -51,9 +54,12 @@ typedef struct _php_ob_buffer {
        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 {
index 6f2ad8140e2a3057b885ca499770b16b58912f6f..02c85756174116b47269cbedfde053bcfeb97d80 100644 (file)
@@ -123,14 +123,29 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush)
        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;
@@ -144,16 +159,7 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush)
 
                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;
@@ -218,6 +224,10 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush)
                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);
+       }
 }
 
 
@@ -249,6 +259,20 @@ PHPAPI void php_end_implicit_flush()
 }
 
 
+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
  */
@@ -285,6 +309,7 @@ static void php_ob_init(uint initial_size, uint block_size, zval *output_handler
        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;
 }
 
 
index 1792d20257a51b5aa485f4142beff9f1d9b44a43..0cb8647690c09cfcc7f846165dc971fb256afd79 100644 (file)
@@ -23,6 +23,8 @@
 
 #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);
@@ -36,6 +38,7 @@ PHPAPI void php_start_implicit_flush(void);
 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);
@@ -51,9 +54,12 @@ typedef struct _php_ob_buffer {
        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 {