1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Get CGI to work with the new headers code.

Now Apache is the only interface that doesn't use it.
This commit is contained in:
Zeev Suraski
1999-05-05 21:05:44 +00:00
parent 2740382c2c
commit aee864e9d8
8 changed files with 45 additions and 17 deletions

View 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;
}

View 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.

2
main.h
View File

@@ -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);

View 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;

View 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);
};

View 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();

View File

@@ -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);

View File

@@ -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);