summaryrefslogtreecommitdiff
path: root/sapi/cgi
diff options
context:
space:
mode:
authorSVN Migration <svn@php.net>2008-12-03 20:30:45 +0000
committerSVN Migration <svn@php.net>2008-12-03 20:30:45 +0000
commit2876046398950e59c3b3c460e67e6fec7ff2ba3c (patch)
tree33b2b8b4b859960a6446ad19d0ada1c55f9cfcda /sapi/cgi
parent3fb86b0b9e79e6a3312b694f30ee627e2e1b325c (diff)
downloadphp-git-php-5.3.0alpha2.tar.gz
This commit was manufactured by cvs2svn to create tag 'php_5_3_0alpha2'.php-5.3.0alpha2
Diffstat (limited to 'sapi/cgi')
-rw-r--r--sapi/cgi/cgi_main.c37
-rw-r--r--sapi/cgi/fastcgi.c80
-rw-r--r--sapi/cgi/fastcgi.h4
-rw-r--r--sapi/cgi/tests/010.phpt53
-rw-r--r--sapi/cgi/tests/011.phpt165
5 files changed, 20 insertions, 319 deletions
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
index a39df163e4..87f7998201 100644
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
@@ -375,8 +375,6 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
char buf[SAPI_CGI_MAX_HEADER_LENGTH];
sapi_header_struct *h;
zend_llist_position pos;
- zend_bool ignore_status = 0;
- int response_status = SG(sapi_headers).http_response_code;
if (SG(request_info).no_headers == 1) {
return SAPI_HEADER_SENT_SUCCESSFULLY;
@@ -388,11 +386,7 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
zend_bool has_status = 0;
if (CGIG(rfc2616_headers) && SG(sapi_headers).http_status_line) {
- char *s;
len = slprintf(buf, SAPI_CGI_MAX_HEADER_LENGTH, "%s\r\n", SG(sapi_headers).http_status_line);
- if ((s = strchr(SG(sapi_headers).http_status_line, ' '))) {
- response_status = atoi((s + 1));
- }
if (len > SAPI_CGI_MAX_HEADER_LENGTH) {
len = SAPI_CGI_MAX_HEADER_LENGTH;
@@ -407,7 +401,6 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
strncasecmp(SG(sapi_headers).http_status_line, "HTTP/", 5) == 0
) {
len = slprintf(buf, sizeof(buf), "Status:%s\r\n", s);
- response_status = atoi((s + 1));
} else {
h = (sapi_header_struct*)zend_llist_get_first_ex(&sapi_headers->headers, &pos);
while (h) {
@@ -437,7 +430,6 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
}
if (!has_status) {
PHPWRITE_H(buf, len);
- ignore_status = 1;
}
}
@@ -445,21 +437,8 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
while (h) {
/* prevent CRLFCRLF */
if (h->header_len) {
- if (h->header_len > sizeof("Status:")-1 &&
- strncasecmp(h->header, "Status:", sizeof("Status:")-1) == 0) {
- if (!ignore_status) {
- ignore_status = 1;
- PHPWRITE_H(h->header, h->header_len);
- PHPWRITE_H("\r\n", 2);
- }
- } else if (response_status == 304 && h->header_len > sizeof("Content-Type:")-1 &&
- strncasecmp(h->header, "Content-Type:", sizeof("Content-Type:")-1) == 0) {
- h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);
- continue;
- } else {
- PHPWRITE_H(h->header, h->header_len);
- PHPWRITE_H("\r\n", 2);
- }
+ PHPWRITE_H(h->header, h->header_len);
+ PHPWRITE_H("\r\n", 2);
}
h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);
}
@@ -1078,9 +1057,6 @@ static void init_request_info(TSRMLS_D)
if (script_path_translated &&
(script_path_translated_len = strlen(script_path_translated)) > 0 &&
(script_path_translated[script_path_translated_len-1] == '/' ||
-#ifdef PHP_WIN32
- script_path_translated[script_path_translated_len-1] == '\\' ||
-#endif
(real_path = tsrm_realpath(script_path_translated, NULL TSRMLS_CC)) == NULL)
) {
char *pt = estrndup(script_path_translated, script_path_translated_len);
@@ -1612,18 +1588,11 @@ consult the installation file that came with this distribution, or visit \n\
#ifndef PHP_WIN32
/* Pre-fork, if required */
if (getenv("PHP_FCGI_CHILDREN")) {
- char * children_str = getenv("PHP_FCGI_CHILDREN");
- children = atoi(children_str);
+ children = atoi(getenv("PHP_FCGI_CHILDREN"));
if (children < 0) {
fprintf(stderr, "PHP_FCGI_CHILDREN is not valid\n");
return FAILURE;
}
- fcgi_set_mgmt_var("FCGI_MAX_CONNS", sizeof("FCGI_MAX_CONNS")-1, children_str, strlen(children_str));
- /* This is the number of concurrent requests, equals FCGI_MAX_CONNS */
- fcgi_set_mgmt_var("FCGI_MAX_REQS", sizeof("FCGI_MAX_REQS")-1, children_str, strlen(children_str));
- } else {
- fcgi_set_mgmt_var("FCGI_MAX_CONNS", sizeof("FCGI_MAX_CONNS")-1, "1", sizeof("1")-1);
- fcgi_set_mgmt_var("FCGI_MAX_REQS", sizeof("FCGI_MAX_REQS")-1, "1", sizeof("1")-1);
}
if (children) {
diff --git a/sapi/cgi/fastcgi.c b/sapi/cgi/fastcgi.c
index 03921995f7..8315c0c472 100644
--- a/sapi/cgi/fastcgi.c
+++ b/sapi/cgi/fastcgi.c
@@ -133,7 +133,18 @@ typedef union _sa_t {
struct sockaddr_in sa_inet;
} sa_t;
-static HashTable fcgi_mgmt_vars;
+typedef struct _fcgi_mgmt_rec {
+ char* name;
+ char name_len;
+ char val;
+} fcgi_mgmt_rec;
+
+static const fcgi_mgmt_rec fcgi_mgmt_vars[] = {
+ {"FCGI_MAX_CONNS", sizeof("FCGI_MAX_CONNS")-1, 1},
+ {"FCGI_MAX_REQS", sizeof("FCGI_MAX_REQS")-1, 1},
+ {"FCGI_MPXS_CONNS", sizeof("FCGI_MPXS_CONNS")-1, 0}
+};
+
static int is_initialized = 0;
static int is_fastcgi = 0;
@@ -183,8 +194,6 @@ int fcgi_in_shutdown(void)
int fcgi_init(void)
{
if (!is_initialized) {
- zend_hash_init(&fcgi_mgmt_vars, 0, NULL, fcgi_free_mgmt_var_cb, 1);
- fcgi_set_mgmt_var("FCGI_MPXS_CONNS", sizeof("FCGI_MPXS_CONNS")-1, "0", sizeof("0")-1);
#ifdef _WIN32
# if 0
/* TODO: Support for TCP sockets */
@@ -251,9 +260,6 @@ int fcgi_is_fastcgi(void)
void fcgi_shutdown(void)
{
- if (is_initialized) {
- zend_hash_destroy(&fcgi_mgmt_vars);
- }
is_fastcgi = 0;
}
@@ -744,13 +750,8 @@ static int fcgi_read_request(fcgi_request *req)
padding = hdr.paddingLength;
}
} else if (hdr.type == FCGI_GET_VALUES) {
+ int j;
unsigned char *p = buf + sizeof(fcgi_header);
- HashPosition pos;
- char * str_index;
- uint str_length;
- ulong num_index;
- int key_type;
- zval ** value;
if (safe_read(req, buf, len+padding) != len+padding) {
req->keep = 0;
@@ -762,41 +763,11 @@ static int fcgi_read_request(fcgi_request *req)
return 0;
}
- zend_hash_internal_pointer_reset_ex(req->env, &pos);
- while ((key_type = zend_hash_get_current_key_ex(req->env, &str_index, &str_length, &num_index, 0, &pos)) != HASH_KEY_NON_EXISTANT) {
- int zlen;
- zend_hash_move_forward_ex(req->env, &pos);
- if (key_type != HASH_KEY_IS_STRING) {
- continue;
- }
- if (zend_hash_find(&fcgi_mgmt_vars, str_index, str_length, (void**) &value) != SUCCESS) {
- continue;
- }
- --str_length;
- zlen = Z_STRLEN_PP(value);
- if ((p + 4 + 4 + str_length + zlen) >= (buf + sizeof(buf))) {
- break;
- }
- if (str_length < 0x80) {
- *p++ = str_length;
- } else {
- *p++ = ((str_length >> 24) & 0xff) | 0x80;
- *p++ = (str_length >> 16) & 0xff;
- *p++ = (str_length >> 8) & 0xff;
- *p++ = str_length & 0xff;
+ for (j = 0; j < sizeof(fcgi_mgmt_vars)/sizeof(fcgi_mgmt_vars[0]); j++) {
+ if (zend_hash_exists(req->env, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].name_len+1) == 0) {
+ sprintf((char*)p, "%c%c%s%c", fcgi_mgmt_vars[j].name_len, 1, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].val);
+ p += fcgi_mgmt_vars[j].name_len + 3;
}
- if (zlen < 0x80) {
- *p++ = zlen;
- } else {
- *p++ = ((zlen >> 24) & 0xff) | 0x80;
- *p++ = (zlen >> 16) & 0xff;
- *p++ = (zlen >> 8) & 0xff;
- *p++ = zlen & 0xff;
- }
- memcpy(p, str_index, str_length);
- p += str_length;
- memcpy(p, Z_STRVAL_PP(value), zlen);
- p += zlen;
}
len = p - buf - sizeof(fcgi_header);
len += fcgi_make_header((fcgi_header*)buf, FCGI_GET_VALUES_RESULT, 0, len);
@@ -1261,23 +1232,6 @@ void fcgi_impersonate(void)
}
#endif
-void fcgi_set_mgmt_var(const char * name, size_t name_len, const char * value, size_t value_len)
-{
- zval * zvalue;
- zvalue = pemalloc(sizeof(*zvalue), 1);
- Z_TYPE_P(zvalue) = IS_STRING;
- Z_STRVAL_P(zvalue) = pestrndup(value, value_len, 1);
- Z_STRLEN_P(zvalue) = value_len;
- zend_hash_add(&fcgi_mgmt_vars, name, name_len + 1, &zvalue, sizeof(zvalue), NULL);
-}
-
-void fcgi_free_mgmt_var_cb(void * ptr)
-{
- zval ** var = (zval **)ptr;
- pefree(Z_STRVAL_PP(var), 1);
- pefree(*var, 1);
-}
-
/*
* Local variables:
* tab-width: 4
diff --git a/sapi/cgi/fastcgi.h b/sapi/cgi/fastcgi.h
index a9662bc0fb..b5c418138a 100644
--- a/sapi/cgi/fastcgi.h
+++ b/sapi/cgi/fastcgi.h
@@ -132,10 +132,6 @@ int fcgi_flush(fcgi_request *req, int close);
#ifdef PHP_WIN32
void fcgi_impersonate(void);
#endif
-
-void fcgi_set_mgmt_var(const char * name, size_t name_len, const char * value, size_t value_len);
-void fcgi_free_mgmt_var_cb(void * ptr);
-
/*
* Local variables:
* tab-width: 4
diff --git a/sapi/cgi/tests/010.phpt b/sapi/cgi/tests/010.phpt
deleted file mode 100644
index e633ad28ba..0000000000
--- a/sapi/cgi/tests/010.phpt
+++ /dev/null
@@ -1,53 +0,0 @@
---TEST--
-Bug #45860 (header() function fails to correctly replace all Status lines)
---SKIPIF--
-<?php include "skipif.inc"; ?>
---FILE--
-<?php
-
-include "include.inc";
-
-$php = get_cgi_path();
-reset_env_vars();
-
-$f = tempnam(sys_get_temp_dir(), 'cgitest');
-
-putenv("TRANSLATED_PATH=".$f."/x");
-putenv("SCRIPT_FILENAME=".$f."/x");
-file_put_contents($f, '<?php
-header("HTTP/1.1 403 Forbidden");
-header("Status: 403 Also Forbidden");
-?>');
-
-echo (`$php -n $f`);
-
-file_put_contents($f, '<?php
-header("HTTP/1.1 403 Forbidden");
-?>');
-
-echo (`$php -n $f`);
-
-file_put_contents($f, '<?php
-header("Status: 403 Also Forbidden");
-?>');
-
-echo (`$php -n $f`);
-
-echo "Done\n";
-
-@unlink($f);
-?>
---EXPECTF--
-Status: 403 Forbidden
-X-Powered-By: PHP/%s
-Content-type: text/html
-
-Status: 403 Forbidden
-X-Powered-By: PHP/%s
-Content-type: text/html
-
-X-Powered-By: PHP/%s
-Status: 403 Also Forbidden
-Content-type: text/html
-
-Done
diff --git a/sapi/cgi/tests/011.phpt b/sapi/cgi/tests/011.phpt
deleted file mode 100644
index 177df021a6..0000000000
--- a/sapi/cgi/tests/011.phpt
+++ /dev/null
@@ -1,165 +0,0 @@
---TEST--
-header_remove()
---SKIPIF--
-<?php include "skipif.inc"; ?>
---FILE--
-<?php
-
-include "include.inc";
-
-$php = get_cgi_path();
-reset_env_vars();
-
-$f = tempnam(sys_get_temp_dir(), 'cgitest');
-
-function test($script) {
- file_put_contents($GLOBALS['f'], $script);
- $cmd = escapeshellcmd($GLOBALS['php']);
- $cmd .= ' -n -dreport_zend_debug=0 -dhtml_errors=0 ' . escapeshellarg($GLOBALS['f']);
- echo "----------\n";
- echo rtrim($script) . "\n";
- echo "----------\n";
- passthru($cmd);
-}
-
-test('<?php ?>');
-test('<?php header_remove(); ?>');
-test('<?php header_remove("X-Foo"); ?>');
-test('<?php
-header("X-Foo: Bar");
-?>');
-test('<?php
-header("X-Foo: Bar");
-header("X-Bar: Baz");
-header_remove("X-Foo");
-?>');
-test('<?php
-header("X-Foo: Bar");
-header_remove("X-Foo: Bar");
-?>');
-test('<?php
-header("X-Foo: Bar");
-header_remove("X-Foo:");
-?>');
-test('<?php
-header("X-Foo: Bar");
-header_remove();
-?>');
-test('<?php
-header_remove("");
-?>');
-test('<?php
-header_remove(":");
-?>');
-test('<?php
-header("X-Foo: Bar");
-echo "flush\n";
-flush();
-header_remove("X-Foo");
-?>');
-
-@unlink($f);
-?>
---EXPECTF--
-----------
-<?php ?>
-----------
-X-Powered-By: PHP/%s
-Content-type: text/html
-
-----------
-<?php header_remove(); ?>
-----------
-Content-type: text/html
-
-----------
-<?php header_remove("X-Foo"); ?>
-----------
-X-Powered-By: PHP/%s
-Content-type: text/html
-
-----------
-<?php
-header("X-Foo: Bar");
-?>
-----------
-X-Powered-By: PHP/%s
-X-Foo: Bar
-Content-type: text/html
-
-----------
-<?php
-header("X-Foo: Bar");
-header("X-Bar: Baz");
-header_remove("X-Foo");
-?>
-----------
-X-Powered-By: PHP/%s
-X-Bar: Baz
-Content-type: text/html
-
-----------
-<?php
-header("X-Foo: Bar");
-header_remove("X-Foo: Bar");
-?>
-----------
-X-Powered-By: PHP/%s
-X-Foo: Bar
-Content-type: text/html
-
-
-Warning: Header to delete may not contain colon. in %s on line 3
-----------
-<?php
-header("X-Foo: Bar");
-header_remove("X-Foo:");
-?>
-----------
-X-Powered-By: PHP/%s
-X-Foo: Bar
-Content-type: text/html
-
-
-Warning: Header to delete may not contain colon. in %s on line 3
-----------
-<?php
-header("X-Foo: Bar");
-header_remove();
-?>
-----------
-Content-type: text/html
-
-----------
-<?php
-header_remove("");
-?>
-----------
-X-Powered-By: PHP/%s
-Content-type: text/html
-
-----------
-<?php
-header_remove(":");
-?>
-----------
-X-Powered-By: PHP/%s
-Content-type: text/html
-
-
-Warning: Header to delete may not contain colon. in %s on line 2
-----------
-<?php
-header("X-Foo: Bar");
-echo "flush\n";
-flush();
-header_remove("X-Foo");
-?>
-----------
-X-Powered-By: PHP/%s
-X-Foo: Bar
-Content-type: text/html
-
-flush
-
-Warning: Cannot modify header information - headers already sent by (output started at %s:3) in %s on line 5