summaryrefslogtreecommitdiff
path: root/sapi/cgi
diff options
context:
space:
mode:
authorMark A. Hershberger <mah@debian.(none)>2009-03-25 00:37:48 -0400
committerMark A. Hershberger <mah@debian.(none)>2009-03-25 00:37:48 -0400
commiteddbbea4325e602ddc87c545531609132d4f0e3b (patch)
treef0994206a7e0a6251be7cc6729ba480f0c8729c2 /sapi/cgi
parent2d4e5b09576bb4f0ba716cc82cdf29ea04d9184b (diff)
downloadphp-eddbbea4325e602ddc87c545531609132d4f0e3b.tar.gz
Imported Upstream version 5.2.3upstream/5.2.3
Diffstat (limited to 'sapi/cgi')
-rw-r--r--sapi/cgi/cgi_main.c35
-rw-r--r--sapi/cgi/config9.m411
-rw-r--r--sapi/cgi/fastcgi.c17
-rw-r--r--sapi/cgi/fastcgi.h3
-rw-r--r--sapi/cgi/tests/009.phpt28
-rw-r--r--sapi/cgi/tests/include.inc4
6 files changed, 77 insertions, 21 deletions
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
index 7ce569466..fd0af132a 100644
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: cgi_main.c,v 1.267.2.15.2.36 2007/04/17 20:00:53 sniper Exp $ */
+/* $Id: cgi_main.c,v 1.267.2.15.2.40 2007/05/28 08:11:59 dmitry Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -331,7 +331,16 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
}
} else {
- len = slprintf(buf, sizeof(buf), "Status: %d\r\n", SG(sapi_headers).http_response_code);
+ char *s;
+
+ if (SG(sapi_headers).http_status_line &&
+ (s = strchr(SG(sapi_headers).http_status_line, ' ')) != 0 &&
+ (s - SG(sapi_headers).http_status_line) >= 5 &&
+ strncasecmp(SG(sapi_headers).http_status_line, "HTTP/", 5) == 0) {
+ len = slprintf(buf, sizeof(buf), "Status:%s\r\n", s);
+ } else {
+ len = slprintf(buf, sizeof(buf), "Status: %d\r\n", SG(sapi_headers).http_response_code);
+ }
}
PHPWRITE_H(buf, len);
@@ -816,8 +825,8 @@ static void init_request_info(TSRMLS_D)
* out what SCRIPT_NAME should be
*/
int slen = len - strlen(pt);
- int pilen = strlen(env_path_info);
- char *path_info = env_path_info + pilen - slen;
+ int pilen = env_path_info ? strlen(env_path_info) : 0;
+ char *path_info = env_path_info ? env_path_info + pilen - slen : NULL;
if (orig_path_info != path_info) {
if (orig_path_info) {
@@ -857,10 +866,12 @@ static void init_request_info(TSRMLS_D)
env_script_name = pt + l;
/* PATH_TRANSATED = DOCUMENT_ROOT + PATH_INFO */
- path_translated_len = l + strlen(env_path_info);
+ path_translated_len = l + (env_path_info ? strlen(env_path_info) : 0);
path_translated = (char *) emalloc(path_translated_len + 1);
memcpy(path_translated, env_document_root, l);
- memcpy(path_translated + l, env_path_info, (path_translated_len - l));
+ if (env_path_info) {
+ memcpy(path_translated + l, env_path_info, (path_translated_len - l));
+ }
path_translated[path_translated_len] = '\0';
if (orig_path_translated) {
_sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC);
@@ -872,12 +883,14 @@ static void init_request_info(TSRMLS_D)
) {
/* PATH_TRANSATED = PATH_TRANSATED - SCRIPT_NAME + PATH_INFO */
int ptlen = strlen(pt) - strlen(env_script_name);
- int path_translated_len = ptlen + strlen(env_path_info);
+ int path_translated_len = ptlen + env_path_info ? strlen(env_path_info) : 0;
char *path_translated = NULL;
path_translated = (char *) emalloc(path_translated_len + 1);
memcpy(path_translated, pt, ptlen);
- memcpy(path_translated + ptlen, env_path_info, path_translated_len - ptlen);
+ if (env_path_info) {
+ memcpy(path_translated + ptlen, env_path_info, path_translated_len - ptlen);
+ }
path_translated[path_translated_len] = '\0';
if (orig_path_translated) {
_sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC);
@@ -1298,8 +1311,6 @@ consult the installation file that came with this distribution, or visit \n\
#endif /* FORCE_CGI_REDIRECT */
#if PHP_FASTCGI
- /* for windows, socket listening is broken in the fastcgi library itself
- so dissabling this feature on windows till time is available to fix it */
if (bindpath) {
fcgi_fd = fcgi_listen(bindpath, 128);
if (fcgi_fd < 0) {
@@ -1416,6 +1427,9 @@ consult the installation file that came with this distribution, or visit \n\
switch (c) {
case 'h':
case '?':
+#if PHP_FASTCGI
+ fcgi_shutdown();
+#endif
no_headers = 1;
php_output_startup();
php_output_activate(TSRMLS_C);
@@ -1810,6 +1824,7 @@ fastcgi_request_done:
}
/* end of fastcgi loop */
}
+ fcgi_shutdown();
#endif
if (cgi_sapi_module.php_ini_path_override) {
diff --git a/sapi/cgi/config9.m4 b/sapi/cgi/config9.m4
index fd933576d..bd04b0cf3 100644
--- a/sapi/cgi/config9.m4
+++ b/sapi/cgi/config9.m4
@@ -1,5 +1,5 @@
dnl
-dnl $Id: config9.m4,v 1.17.2.2.2.2 2007/02/20 20:11:11 tony2001 Exp $
+dnl $Id: config9.m4,v 1.17.2.2.2.4 2007/05/24 23:29:59 sniper Exp $
dnl
AC_ARG_ENABLE(cgi,
@@ -58,10 +58,10 @@ if test "$PHP_SAPI" = "default"; then
PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/cgi/Makefile.frag)
case $host_alias in
*cygwin* )
- SAPI_CGI_PATH=sapi/cgi/php.exe
+ SAPI_CGI_PATH=sapi/cgi/php-cgi.exe
;;
* )
- SAPI_CGI_PATH=sapi/cgi/php
+ SAPI_CGI_PATH=sapi/cgi/php-cgi
;;
esac
PHP_SUBST(SAPI_CGI_PATH)
@@ -98,17 +98,14 @@ if test "$PHP_SAPI" = "default"; then
if test "$PHP_ENABLE_FASTCGI" = "yes"; then
PHP_FASTCGI=1
PHP_FCGI_FILES="fastcgi.c"
- PHP_FCGI_STATIC=1
else
PHP_FASTCGI=0
PHP_FCGI_FILES=""
- PHP_FCGI_STATIC=0
fi
AC_DEFINE_UNQUOTED(PHP_FASTCGI, $PHP_FASTCGI, [ ])
- AC_DEFINE_UNQUOTED(PHP_FCGI_STATIC, $PHP_FCGI_STATIC, [ ])
AC_MSG_RESULT($PHP_ENABLE_FASTCGI)
- INSTALL_IT="@echo \"Installing PHP CGI into: \$(INSTALL_ROOT)\$(bindir)/\"; \$(INSTALL) -m 0755 \$(SAPI_CGI_PATH) \$(INSTALL_ROOT)\$(bindir)/\$(program_prefix)php\$(program_suffix)\$(EXEEXT)"
+ INSTALL_IT="@echo \"Installing PHP CGI binary: \$(INSTALL_ROOT)\$(bindir)/\"; \$(INSTALL) -m 0755 \$(SAPI_CGI_PATH) \$(INSTALL_ROOT)\$(bindir)/\$(program_prefix)php-cgi\$(program_suffix)\$(EXEEXT)"
PHP_SELECT_SAPI(cgi, program, $PHP_FCGI_FILES cgi_main.c getopt.c, , '$(SAPI_CGI_PATH)')
case $host_alias in
diff --git a/sapi/cgi/fastcgi.c b/sapi/cgi/fastcgi.c
index 7fd1fa86b..a0064888f 100644
--- a/sapi/cgi/fastcgi.c
+++ b/sapi/cgi/fastcgi.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: fastcgi.c,v 1.4.2.13.2.24 2007/04/09 15:39:59 dmitry Exp $ */
+/* $Id: fastcgi.c,v 1.4.2.13.2.26 2007/05/21 09:08:13 dmitry Exp $ */
#include "php.h"
#include "fastcgi.h"
@@ -255,6 +255,11 @@ int fcgi_is_fastcgi(void)
}
}
+void fcgi_shutdown(void)
+{
+ is_fastcgi = 0;
+}
+
#ifdef _WIN32
/* Do some black magic with the NT security API.
* We prepare a DACL (Discretionary Access Control List) so that
@@ -345,6 +350,13 @@ int fcgi_listen(const char *path, int backlog)
int listen_socket;
sa_t sa;
socklen_t sock_len;
+#ifdef SO_REUSEADDR
+# ifdef _WIN32
+ BOOL reuse = 1;
+# else
+ int reuse = 1;
+# endif
+#endif
if ((s = strchr(path, ':'))) {
port = atoi(s+1);
@@ -434,6 +446,9 @@ int fcgi_listen(const char *path, int backlog)
/* Create, bind socket and start listen on it */
if ((listen_socket = socket(sa.sa.sa_family, SOCK_STREAM, 0)) < 0 ||
+#ifdef SO_REUSEADDR
+ setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, (char*)&reuse, sizeof(reuse)) < 0 ||
+#endif
bind(listen_socket, (struct sockaddr *) &sa, sock_len) < 0 ||
listen(listen_socket, backlog) < 0) {
diff --git a/sapi/cgi/fastcgi.h b/sapi/cgi/fastcgi.h
index 43885c26a..8fcc0951d 100644
--- a/sapi/cgi/fastcgi.h
+++ b/sapi/cgi/fastcgi.h
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: fastcgi.h,v 1.2.2.4.2.4 2007/03/28 15:39:22 dmitry Exp $ */
+/* $Id: fastcgi.h,v 1.2.2.4.2.5 2007/05/21 09:08:13 dmitry Exp $ */
/* FastCGI protocol */
@@ -112,6 +112,7 @@ typedef struct _fcgi_request {
} fcgi_request;
int fcgi_init(void);
+void fcgi_shutdown(void);
int fcgi_is_fastcgi(void);
int fcgi_in_shutdown(void);
int fcgi_listen(const char *path, int backlog);
diff --git a/sapi/cgi/tests/009.phpt b/sapi/cgi/tests/009.phpt
new file mode 100644
index 000000000..c92fc87a8
--- /dev/null
+++ b/sapi/cgi/tests/009.phpt
@@ -0,0 +1,28 @@
+--TEST--
+path info request without exported PATH_INFO
+--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 var_dump($_SERVER["TRANSLATED_PATH"]); ');
+
+echo (`$php $f`);
+
+echo "Done\n";
+?>
+--EXPECTF--
+X-Powered-By: PHP/%s
+Content-type: text/html
+
+string(%d) "%s/x"
+Done
diff --git a/sapi/cgi/tests/include.inc b/sapi/cgi/tests/include.inc
index 2a8732149..11bf8f3b8 100644
--- a/sapi/cgi/tests/include.inc
+++ b/sapi/cgi/tests/include.inc
@@ -30,9 +30,9 @@ function get_cgi_path() /* {{{ */
}
}
- if ($php_path && is_dir($php_path) && file_exists($php_path."/cgi/php") && is_executable($php_path."/cgi/php")) {
+ if ($php_path && is_dir($php_path) && file_exists($php_path."/cgi/php-cgi") && is_executable($php_path."/cgi/php-cgi")) {
/* gotcha */
- return $php_path."/cgi/php";
+ return $php_path."/cgi/php-cgi";
}
return false;
}