#include <stdio.h>
#include "php.h"
+
#ifdef PHP_WIN32
-#include "win32/time.h"
-#include "win32/signal.h"
-#include <process.h>
+# include "win32/time.h"
+# include "win32/signal.h"
+# include <process.h>
#endif
+
#if HAVE_SYS_TIME_H
-#include <sys/time.h>
+# include <sys/time.h>
#endif
+
#if HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#endif
+
#if HAVE_SIGNAL_H
-#include <signal.h>
+# include <signal.h>
#endif
+
#if HAVE_SETLOCALE
-#include <locale.h>
+# include <locale.h>
#endif
+
#if HAVE_SYS_TYPES_H
-#include <sys/types.h>
+# include <sys/types.h>
#endif
+
#if HAVE_SYS_WAIT_H
-#include <sys/wait.h>
+# include <sys/wait.h>
#endif
+
#include "zend.h"
#include "zend_extensions.h"
#include "php_ini.h"
#include "php_main.h"
#include "fopen_wrappers.h"
#include "ext/standard/php_standard.h"
+
#ifdef PHP_WIN32
-#include <io.h>
-#include <fcntl.h>
-#include "win32/php_registry.h"
+# include <io.h>
+# include <fcntl.h>
+# include "win32/php_registry.h"
#endif
#ifdef __riscos__
-#include <unixlib/local.h>
+# include <unixlib/local.h>
int __riscosify_control = __RISCOSIFY_STRICT_UNIX_SPECS;
#endif
/* {{{ user_config_cache
*
* Key for each cache entry is dirname(PATH_TRANSLATED).
- *
+ *
* NOTE: Each cache entry config_hash contains the combination from all user ini files found in
* the path starting from doc_root throught to dirname(PATH_TRANSLATED). There is no point
* storing per-file entries as it would not be possible to detect added / deleted entries
h = (sapi_header_struct*)zend_llist_get_first_ex(&sapi_headers->headers, &pos);
while (h) {
if (h->header_len > sizeof("Status:")-1 &&
- strncasecmp(h->header, "Status:", sizeof("Status:")-1) == 0) {
+ strncasecmp(h->header, "Status:", sizeof("Status:")-1) == 0
+ ) {
has_status = 1;
break;
}
http_error *err = (http_error*)http_error_codes;
while (err->code != 0) {
- if (err->code == SG(sapi_headers).http_response_code) {
+ if (err->code == SG(sapi_headers).http_response_code) {
break;
}
err++;
}
}
}
+
if (!has_status) {
PHPWRITE_H(buf, len);
ignore_status = 1;
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;
+ 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) {
+ } 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 {
static char *sapi_cgibin_getenv(char *name, size_t name_len TSRMLS_DC)
{
/* when php is started by mod_fastcgi, no regular environment
- is provided to PHP. It is always sent to PHP at the start
- of a request. So we have to do our own lookup to get env
- vars. This could probably be faster somehow. */
+ * is provided to PHP. It is always sent to PHP at the start
+ * of a request. So we have to do our own lookup to get env
+ * vars. This could probably be faster somehow. */
if (fcgi_is_fastcgi()) {
fcgi_request *request = (fcgi_request*) SG(server_context);
return fcgi_getenv(request, name, name_len);
name_len = strlen(name);
/* when php is started by mod_fastcgi, no regular environment
- is provided to PHP. It is always sent to PHP at the start
- of a request. So we have to do our own lookup to get env
- vars. This could probably be faster somehow. */
+ * is provided to PHP. It is always sent to PHP at the start
+ * of a request. So we have to do our own lookup to get env
+ * vars. This could probably be faster somehow. */
if (fcgi_is_fastcgi()) {
fcgi_request *request = (fcgi_request*) SG(server_context);
return fcgi_putenv(request, name, name_len, value);
/* turn off magic_quotes while importing environment variables */
PG(magic_quotes_gpc) = 0;
for (zend_hash_internal_pointer_reset_ex(request->env, &pos);
- zend_hash_get_current_key_ex(request->env, &var, &var_len, &idx, 0, &pos) == HASH_KEY_IS_STRING &&
- zend_hash_get_current_data_ex(request->env, (void **) &val, &pos) == SUCCESS;
- zend_hash_move_forward_ex(request->env, &pos)
+ zend_hash_get_current_key_ex(request->env, &var, &var_len, &idx, 0, &pos) == HASH_KEY_IS_STRING &&
+ zend_hash_get_current_data_ex(request->env, (void **) &val, &pos) == SUCCESS;
+ zend_hash_move_forward_ex(request->env, &pos)
) {
unsigned int new_val_len;
}
}
- if (php_ini_has_per_dir_config() ||
- (PG(user_ini_filename) && *PG(user_ini_filename))) {
+ if (php_ini_has_per_dir_config() ||
+ (PG(user_ini_filename) && *PG(user_ini_filename))
+ ) {
/* Prepare search path */
path_len = strlen(SG(request_info).path_translated);
sapi_cgi_register_variables, /* register server variables */
sapi_cgi_log_message, /* Log message */
NULL, /* Get request time */
- NULL, /* Child terminate */
+ NULL, /* Child terminate */
STANDARD_SAPI_MODULE_PROPERTIES
};
p = strstr(path, "..");
if (p) {
if ((p == path || IS_SLASH(*(p-1))) &&
- (*(p+2) == 0 || IS_SLASH(*(p+2)))) {
+ (*(p+2) == 0 || IS_SLASH(*(p+2)))
+ ) {
return 0;
}
while (1) {
break;
}
if (IS_SLASH(*(p-1)) &&
- (*(p+2) == 0 || IS_SLASH(*(p+2)))) {
+ (*(p+2) == 0 || IS_SLASH(*(p+2)))
+ ) {
return 0;
}
}
char *script_path_translated = env_script_filename;
/* some broken servers do not have script_filename or argv0
- an example, IIS configured in some ways. then they do more
- broken stuff and set path_translated to the cgi script location */
+ * an example, IIS configured in some ways. then they do more
+ * broken stuff and set path_translated to the cgi script location */
if (!script_path_translated && env_path_translated) {
script_path_translated = env_path_translated;
}
SG(sapi_headers).http_response_code = 200;
/* script_path_translated being set is a good indication that
- we are running in a cgi environment, since it is always
- null otherwise. otherwise, the filename
- of the script will be retreived later via argc/argv */
+ * we are running in a cgi environment, since it is always
+ * null otherwise. otherwise, the filename
+ * of the script will be retreived later via argc/argv */
if (script_path_translated) {
const char *auth;
char *content_length = sapi_cgibin_getenv("CONTENT_LENGTH", sizeof("CONTENT_LENGTH")-1 TSRMLS_CC);
}
if (env_path_translated != NULL && env_redirect_url != NULL &&
- orig_script_filename != NULL && script_path_translated != NULL) {
+ orig_script_filename != NULL && script_path_translated != NULL
+ ) {
/*
- pretty much apache specific. If we have a redirect_url
- then our script_filename and script_name point to the
- php executable
- */
+ * pretty much apache specific. If we have a redirect_url
+ * then our script_filename and script_name point to the
+ * php executable
+ */
script_path_translated = env_path_translated;
/* we correct SCRIPT_NAME now in case we don't have PATH_INFO */
env_script_name = env_redirect_url;
(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] == '\\' ||
+ script_path_translated[script_path_translated_len-1] == '\\' ||
#endif
(real_path = tsrm_realpath(script_path_translated, NULL TSRMLS_CC)) == NULL)
) {
TRANSLATE_SLASHES(pt);
/* figure out docroot
- SCRIPT_FILENAME minus SCRIPT_NAME
- */
-
+ * SCRIPT_FILENAME minus SCRIPT_NAME
+ */
if (env_document_root) {
int l = strlen(env_document_root);
int path_translated_len = 0;
#if 0 && defined(PHP_DEBUG)
/* IIS is always making things more difficult. This allows
- us to stop PHP and attach a debugger before much gets started */
+ * us to stop PHP and attach a debugger before much gets started */
{
char szMessage [256];
- wsprintf (szMessage, "Please attach a debugger to the process 0x%X [%d] (%s) and click OK",
- GetCurrentProcessId(), GetCurrentProcessId(), argv[0]);
+ wsprintf (szMessage, "Please attach a debugger to the process 0x%X [%d] (%s) and click OK", GetCurrentProcessId(), GetCurrentProcessId(), argv[0]);
MessageBox(NULL, szMessage, "CGI Debug Time!", MB_OK|MB_SERVICE_NOTIFICATION);
}
#endif
if (!fastcgi) {
/* Make sure we detect we are a cgi - a bit redundancy here,
- but the default case is that we have to check only the first one. */
+ * but the default case is that we have to check only the first one. */
if (getenv("SERVER_SOFTWARE") ||
getenv("SERVER_NAME") ||
getenv("GATEWAY_INTERFACE") ||
break;
}
/* if we're started on command line, check to see if
- we are being started as an 'external' fastcgi
- server by accepting a bindpath parameter. */
+ * we are being started as an 'external' fastcgi
+ * server by accepting a bindpath parameter. */
case 'b':
if (!fastcgi) {
bindpath = strdup(php_optarg);
if (!getenv("REDIRECT_STATUS") &&
!getenv ("HTTP_REDIRECT_STATUS") &&
/* this is to allow a different env var to be configured
- in case some server does something different than above */
+ * in case some server does something different than above */
(!CGIG(redirect_status_env) || !getenv(CGIG(redirect_status_env)))
) {
SG(sapi_headers).http_response_code = 400;
#if defined(ZTS) && !defined(PHP_DEBUG)
/* XXX we're crashing here in msvc6 debug builds at
- php_message_handler_for_zend:839 because
- SG(request_info).path_translated is an invalid pointer.
- It still happens even though I set it to null, so something
- weird is going on.
- */
+ * php_message_handler_for_zend:839 because
+ * SG(request_info).path_translated is an invalid pointer.
+ * It still happens even though I set it to null, so something
+ * weird is going on.
+ */
tsrm_shutdown();
#endif
return FAILURE;
break;
} else if (exit_signal) {
break;
- }
+ }
}
if (exit_signal) {
#if 0
/* Initialise FastCGI request structure */
#ifdef PHP_WIN32
/* attempt to set security impersonation for fastcgi
- will only happen on NT based OS, others will ignore it. */
+ * will only happen on NT based OS, others will ignore it. */
if (fastcgi && CGIG(impersonate)) {
fcgi_impersonate();
}
}
/* all remaining arguments are part of the query string
- this section of code concatenates all remaining arguments
- into a single string, seperating args with a &
- this allows command lines like:
-
- test.php v1=test v2=hello+world!
- test.php "v1=test&v2=hello world!"
- test.php v1=test "v2=hello world!"
+ * this section of code concatenates all remaining arguments
+ * into a single string, seperating args with a &
+ * this allows command lines like:
+ *
+ * test.php v1=test v2=hello+world!
+ * test.php "v1=test&v2=hello world!"
+ * test.php v1=test "v2=hello world!"
*/
if (!SG(request_info).query_string && argc > php_optind) {
int slen = strlen(PG(arg_separator).input);
file_handle.free_filename = 0;
/* request startup only after we've done all we can to
- get path_translated */
+ * get path_translated */
if (php_request_startup(TSRMLS_C) == FAILURE) {
if (fastcgi) {
fcgi_finish_request(&request, 1);
PUTS("No input file specified.\n");
}
/* we want to serve more requests if this is fastcgi
- so cleanup and continue, request shutdown is
- handled later */
+ * so cleanup and continue, request shutdown is
+ * handled later */
if (fastcgi) {
goto fastcgi_request_done;
}
{
char *path_translated;
- /* Go through this trouble so that the memory manager doesn't warn
- * about SG(request_info).path_translated leaking
+ /* Go through this trouble so that the memory manager doesn't warn
+ * about SG(request_info).path_translated leaking
*/
if (SG(request_info).path_translated) {
path_translated = strdup(SG(request_info).path_translated);