From: Zeev Suraski Date: Thu, 6 May 1999 21:58:49 +0000 (+0000) Subject: * Get output buffering to work again X-Git-Tag: BEFORE_PHP4_APACHE_MODULE_CHANGE~87 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ade1117ebd6a7a64faccf48a3811ee92e2ac9d9d;p=php * Get output buffering to work again * Warn about adding header information after headers are sent * Several fixes --- diff --git a/cgi_main.c b/cgi_main.c index 4f4b41bba1..fa438d6eac 100644 --- a/cgi_main.c +++ b/cgi_main.c @@ -93,6 +93,8 @@ static sapi_module_struct sapi_module = { zend_cgibin_ub_write, /* unbuffered write */ + php3_error, /* error handler */ + NULL, /* header handler */ NULL, /* send headers handler */ sapi_cgi_send_header, /* send header handler */ diff --git a/main/SAPI.c b/main/SAPI.c index ede0176fac..55c5c966da 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -1,3 +1,21 @@ +/* + +----------------------------------------------------------------------+ + | Server API Abstraction Layer | + +----------------------------------------------------------------------+ + | Copyright (c) 1998, 1999 SAPI Development Team | + +----------------------------------------------------------------------+ + | This source file is subject to the Zend license, that is bundled | + | with this package in the file LICENSE. If you did not receive a | + | copy of the Zend license, please mail us at zend@zend.com so we can | + | send you a copy immediately. | + +----------------------------------------------------------------------+ + | Design: Shane Caraveo | + | Authors: Andi Gutmans | + | Zeev Suraski | + +----------------------------------------------------------------------+ +*/ + + #include "SAPI.h" #ifdef ZTS #include "TSRM.h" @@ -10,6 +28,9 @@ #endif +SAPI_API void (*sapi_error)(int error_type, const char *message, ...); + + #ifdef ZTS SAPI_API int sapi_globals_id; #else @@ -17,8 +38,9 @@ sapi_globals_struct sapi_globals; #endif -/* A true global (no need for thread safety) */ +/* True globals (no need for thread safety) */ sapi_module_struct sapi_module; +SAPI_API void (*sapi_error)(int error_type, const char *message, ...); SAPI_API void sapi_startup(sapi_module_struct *sf) @@ -57,13 +79,19 @@ SAPI_API void sapi_deactivate(SLS_D) /* This function expects a *duplicated* string, that was previously emalloc()'d. * Pointers sent to this functions will be automatically freed by the framework. */ -SAPI_API int sapi_add_header(const char *header_line, uint header_line_len) +SAPI_API int sapi_add_header(char *header_line, uint header_line_len) { int retval; sapi_header_struct sapi_header; SLS_FETCH(); - sapi_header.header = (char *) header_line; + if (SG(headers_sent)) { + sapi_module.sapi_error(E_WARNING, "Cannot add header information - headers already sent"); + efree(header_line); + return FAILURE; + } + + sapi_header.header = header_line; sapi_header.header_len = header_line_len; if (sapi_module.header_handler) { diff --git a/main/SAPI.h b/main/SAPI.h index 6a1ff8a9af..58925b630e 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -76,10 +76,9 @@ SAPI_API void sapi_startup(sapi_module_struct *sf); SAPI_API void sapi_activate(SLS_D); SAPI_API void sapi_deactivate(SLS_D); -SAPI_API int sapi_add_header(const char *header_line, uint header_line_len); +SAPI_API int sapi_add_header(char *header_line, uint header_line_len); SAPI_API int sapi_send_headers(); - struct _sapi_module_struct { char *name; @@ -88,6 +87,8 @@ struct _sapi_module_struct { int (*ub_write)(const char *str, unsigned int str_length); + void (*sapi_error)(int type, const char *error_msg, ...); + int (*header_handler)(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers); int (*send_headers)(sapi_headers_struct *sapi_headers SLS_DC); void (*send_header)(sapi_header_struct *sapi_header, void *server_context); diff --git a/main/main.c b/main/main.c index 0ce2c62570..52a1f07b85 100644 --- a/main/main.c +++ b/main/main.c @@ -758,6 +758,12 @@ static core_globals_ctor(php_core_globals *core_globals) #endif +static int zend_body_write_wrapper(const char *str, uint str_length) +{ + return zend_body_write(str, str_length); +} + + int php_module_startup(sapi_module_struct *sf) { zend_utility_functions zuf; @@ -784,7 +790,7 @@ int php_module_startup(sapi_module_struct *sf) zuf.error_function = php3_error; zuf.printf_function = php3_printf; - zuf.write_function = zend_body_write; + zuf.write_function = zend_body_write_wrapper; zuf.fopen_function = php_fopen_wrapper_for_zend; zuf.message_handler = php_message_handler_for_zend; zuf.block_interruptions = BLOCK_INTERRUPTIONS;