]> granicus.if.org Git - php/commitdiff
Get CGI to work with the new headers code.
authorZeev Suraski <zeev@php.net>
Wed, 5 May 1999 21:05:44 +0000 (21:05 +0000)
committerZeev Suraski <zeev@php.net>
Wed, 5 May 1999 21:05:44 +0000 (21:05 +0000)
Now Apache is the only interface that doesn't use it.

cgi_main.c
ext/standard/head.c
main.h
main/SAPI.c
main/SAPI.h
main/main.c
output.c
output.h

index 792e2fe9c6ed7a5b41ef46babbab4b69c5796af6..4f4b41bba1819d51825e8688129ea698b4873fac 100644 (file)
@@ -76,6 +76,15 @@ static int zend_cgibin_ub_write(const char *str, uint str_length)
 }
 
 
+static void sapi_cgi_send_header(sapi_header_struct *sapi_header, void *server_context)
+{
+       if (sapi_header) {
+               PHPWRITE_H(sapi_header->header, sapi_header->header_len);
+       }
+       PHPWRITE_H("\r\n", 2);
+}
+
+
 static sapi_module_struct sapi_module = {
        "PHP Language",                                 /* name */
                                                                        
@@ -83,6 +92,10 @@ static sapi_module_struct sapi_module = {
        php_module_shutdown_wrapper,    /* shutdown */
 
        zend_cgibin_ub_write,                   /* unbuffered write */
+
+       NULL,                                                   /* header handler */
+       NULL,                                                   /* send headers handler */
+       sapi_cgi_send_header,                   /* send header handler */
 };
 
 
@@ -117,8 +130,15 @@ static void php_cgi_usage(char *argv0)
 
 static void init_request_info(SLS_D)
 {
+       char *request_method = getenv("REQUEST_METHOD");
+
        SG(request_info).query_string = getenv("QUERY_STRING");
        SG(request_info).request_uri = getenv("PATH_INFO");
+       if (request_method && !strcmp(request_method, "HEAD")) {
+               SG(request_info).headers_only = 1;
+       } else {
+               SG(request_info).headers_only = 0;
+       }
 }
 
 
@@ -215,7 +235,7 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
                        switch (c) {
                                case 'f':
                                        if (!_cgi_started){ 
-                                               if (php_request_startup(CLS_C ELS_CC PLS_CC)==FAILURE) {
+                                               if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) {
                                                        php_module_shutdown();
                                                        return FAILURE;
                                                }
@@ -228,7 +248,7 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
                                        break;
                                case 'v':
                                        if (!_cgi_started) {
-                                               if (php_request_startup(CLS_C ELS_CC PLS_CC)==FAILURE) {
+                                               if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) {
                                                        php_module_shutdown();
                                                        return FAILURE;
                                                }
@@ -238,7 +258,7 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
                                        break;
                                case 'i':
                                        if (!_cgi_started) {
-                                               if (php_request_startup(CLS_C ELS_CC PLS_CC)==FAILURE) {
+                                               if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) {
                                                        php_module_shutdown();
                                                        return FAILURE;
                                                }
@@ -286,7 +306,7 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
 #endif
 
        if (!_cgi_started) {
-               if (php_request_startup(CLS_C ELS_CC PLS_CC)==FAILURE) {
+               if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) {
                        php_module_shutdown();
                        return FAILURE;
                }
index d2cd7eeb07cb667ace1c4e6c48ce57619c56b23b..8e757a3e079410dc37563d6d436759a5ca78b99d 100644 (file)
@@ -76,7 +76,7 @@ PHPAPI void php3_noheader(void)
 }
 
 
-#ifndef ZTS
+#ifdef APACHE
 /* Adds header information */
 void php4i_add_header_information(char *header_information, uint header_length)
 {
@@ -227,7 +227,7 @@ void php3_Header(INTERNAL_FUNCTION_PARAMETERS)
 
 
 
-#ifndef ZTS
+#ifdef APACHE
 /*
  * php3_header() flushes the header info built up using calls to
  * the Header() function.  If type is 1, a redirect to str is done.
diff --git a/main.h b/main.h
index df3455c9c9b5904c8dce96c311d06755b32805e0..3bf385f976f76b34a3384694410223f3c994670f 100644 (file)
--- a/main.h
+++ b/main.h
@@ -39,7 +39,7 @@
 #include "php_globals.h"
 #include "SAPI.h"
 
-PHPAPI int php_request_startup(CLS_D ELS_DC PLS_DC);
+PHPAPI int php_request_startup(CLS_D ELS_DC PLS_DC SLS_DC);
 PHPAPI void php_request_shutdown(void *dummy);
 PHPAPI void php_request_shutdown_for_exec(void *dummy);
 PHPAPI int php_module_startup(sapi_module_struct *sf);
index 12499aee3b08d6713c168e904d53f4b2de127cd6..af8f1f0b39ac8569299fa5906dbc92ef97b0534b 100644 (file)
@@ -97,6 +97,7 @@ SAPI_API int sapi_add_header(const char *header_line, uint header_line_len)
 SAPI_API int sapi_send_headers()
 {
        int retval;
+       sapi_header_struct default_header = { DEFAULT_CONTENT_TYPE, sizeof(DEFAULT_CONTENT_TYPE)-1 };
        SLS_FETCH();
 
        if (SG(headers_sent)) {
@@ -115,7 +116,13 @@ SAPI_API int sapi_send_headers()
                        return SUCCESS;
                        break;
                case SAPI_HEADER_DO_SEND:
+                       if (SG(sapi_headers).content_type.header) {
+                               sapi_module.send_header(&SG(sapi_headers).content_type, SG(server_context));
+                       } else {
+                               sapi_module.send_header(&default_header, SG(server_context));
+                       }
                        zend_llist_apply_with_argument(&SG(sapi_headers).headers, (void (*)(void *, void *)) sapi_module.send_header, SG(server_context));
+                       sapi_module.send_header(NULL, SG(server_context));
                        SG(headers_sent) = 1;
                        return SUCCESS;
                        break;
index 58ef0c081a631c39c066dd8b790fb31f81226edd..b6e225257d0b158f8390545c81cb7d9ca0b694c9 100644 (file)
@@ -90,7 +90,7 @@ struct _sapi_module_struct {
 
        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)(void *server_context, sapi_header_struct *sapi_header);
+       void (*send_header)(sapi_header_struct *sapi_header, void *server_context);
 };
 
 
index d1ccc629e41429b867aae47590a026bb7d67f7e8..60d4bab7a277647e7b643b1b3c0853ccd9eedeb1 100644 (file)
@@ -597,7 +597,7 @@ static void php_message_handler_for_zend(long message, void *data)
 
 
 
-int php_request_startup(CLS_D ELS_DC PLS_DC)
+int php_request_startup(CLS_D ELS_DC PLS_DC SLS_DC)
 {
        PG(unclean_shutdown) = 0;
 
@@ -628,12 +628,11 @@ int php_request_startup(CLS_D ELS_DC PLS_DC)
                php3_printf("Unable to initialize request info.\n");
                return FAILURE;
        }
-       
+       sapi_activate(SLS_C);   
        init_compiler(CLS_C ELS_CC);
        init_executor(CLS_C ELS_CC);
        startup_scanner(CLS_C);
 
-
        return SUCCESS;
 }
 
@@ -661,11 +660,11 @@ void php_request_shutdown(void *dummy)
        CLS_FETCH();
        ELS_FETCH();
        PLS_FETCH();
+       SLS_FETCH();
 
        php3_header();
        zend_end_ob_buffering(1);
 
-
        php3_call_shutdown_functions();
        
        php_ini_rshutdown();
@@ -679,6 +678,8 @@ void php_request_shutdown(void *dummy)
        php3_unset_timeout();
 
 
+       sapi_deactivate(SLS_C);
+
 #if CGI_BINARY
        fflush(stdout);
        if(request_info.php_argv0) {
@@ -1193,7 +1194,7 @@ PHPAPI int apache_php3_module_main(request_rec *r, int fd, int display_source_mo
 
        SG(server_context) = r;
 
-       if (php_request_startup(CLS_C ELS_CC PLS_CC) == FAILURE) {
+       if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC) == FAILURE) {
                return FAILURE;
        }
        php3_TreatHeaders();
index 327ed06fb8b18700230179ae66da3d9c7ed046be..d7ffcc981e5b6b509f90d69ae4313327d91ea353 100644 (file)
--- a/output.c
+++ b/output.c
@@ -19,8 +19,8 @@
 #include "SAPI.h"
 
 /* output functions */
-int (*zend_body_write)(const char *str, uint str_length);              /* string output */
-int (*zend_header_write)(const char *str, uint str_length);    /* unbuffer string output */
+PHPAPI int (*zend_body_write)(const char *str, uint str_length);               /* string output */
+PHPAPI int (*zend_header_write)(const char *str, uint str_length);     /* unbuffer string output */
 static int zend_ub_body_write(const char *str, uint str_length);
 static int zend_ub_body_write_no_header(const char *str, uint str_length);
 static int zend_b_body_write(const char *str, uint str_length);
index ae6602351bb8df3bd40bc098c3829b60434c1254..b7523d645d9c6d9e2cf7a1ddf6173e1475c7a546 100644 (file)
--- a/output.h
+++ b/output.h
@@ -6,8 +6,8 @@
 PHPAPI void zend_output_startup();
 
 /* exported output functions */
-int (*zend_body_write)(const char *str, uint str_length);              /* string output */
-int (*zend_header_write)(const char *str, uint str_length);    /* unbuffer string output */
+PHPAPI int (*zend_body_write)(const char *str, uint str_length);               /* string output */
+PHPAPI int (*zend_header_write)(const char *str, uint str_length);     /* unbuffer string output */
 void zend_start_ob_buffering();
 void zend_end_ob_buffering(int send_buffer);
 int zend_ob_get_buffer(pval *p);