]> granicus.if.org Git - php/commitdiff
* Get output buffering to work again
authorZeev Suraski <zeev@php.net>
Thu, 6 May 1999 21:58:49 +0000 (21:58 +0000)
committerZeev Suraski <zeev@php.net>
Thu, 6 May 1999 21:58:49 +0000 (21:58 +0000)
* Warn about adding header information after headers are sent
* Several fixes

cgi_main.c
main/SAPI.c
main/SAPI.h
main/main.c

index 4f4b41bba1819d51825e8688129ea698b4873fac..fa438d6eac0c838e0222feb502a3df5efdcaed78 100644 (file)
@@ -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 */
index ede0176fac7cb18a4efccb59e99a2f116b9c4a43..55c5c966daf8901887337b50ee598b3a264d3608 100644 (file)
@@ -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 <shane@caraveo.com>                           |
+   | Authors: Andi Gutmans <andi@zend.com>                                |
+   |          Zeev Suraski <zeev@zend.com>                                |
+   +----------------------------------------------------------------------+
+*/
+
+
 #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) {
index 6a1ff8a9afc6384ad0e7d284cd77aa80c0c08f8a..58925b630e3027d07895bd453544bb4aaa19618f 100644 (file)
@@ -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);
index 0ce2c62570baa00a7eceb1840b4aeaedec44bde8..52a1f07b85d639696a421afcdfe2ab9cb9792062 100644 (file)
@@ -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;