jani            Sat May 23 18:59:17 2009 UTC

  Modified files:              
    /php-src/sapi/cgi   cgi_main.c 
  Log:
  ws + cs
  
http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.379&r2=1.380&diff_format=u
Index: php-src/sapi/cgi/cgi_main.c
diff -u php-src/sapi/cgi/cgi_main.c:1.379 php-src/sapi/cgi/cgi_main.c:1.380
--- php-src/sapi/cgi/cgi_main.c:1.379   Sat May 23 18:03:27 2009
+++ php-src/sapi/cgi/cgi_main.c Sat May 23 18:59:17 2009
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: cgi_main.c,v 1.379 2009/05/23 18:03:27 andrei Exp $ */
+/* $Id: cgi_main.c,v 1.380 2009/05/23 18:59:17 jani Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -32,29 +32,37 @@
 
 #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"
@@ -62,14 +70,15 @@
 #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
 
@@ -164,7 +173,7 @@
 /* {{{ 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
@@ -412,7 +421,8 @@
                                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;
                                        }
@@ -422,7 +432,7 @@
                                        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++;
@@ -447,14 +457,16 @@
                /* 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;
+                               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 {
@@ -494,9 +506,9 @@
 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);
@@ -520,9 +532,9 @@
        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);
@@ -609,14 +621,13 @@
                UConverter *conv = ZEND_U_CONVERTER(UG(runtime_encoding_conv));
 
                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_register_variable_with_conv(conv, var.s, 
strlen(var.s), val, strlen(*val),
-                                                                               
                array_ptr, filter_arg TSRMLS_CC) == FAILURE) {
+                       if (php_register_variable_with_conv(conv, var.s, 
strlen(var.s), val, strlen(*val), array_ptr, filter_arg TSRMLS_CC) == FAILURE) {
                                php_error(E_WARNING, "Failed to decode %s array 
entry", (filter_arg == PARSE_ENV?"_ENV":"_SERVER"));
                        }
                }
@@ -651,16 +662,14 @@
                }
 
                /* Build the special-case PHP_SELF variable for the CGI version 
*/
-               if (php_register_variable_with_conv(conv, 
ZEND_STRL("PHP_SELF"), php_self,
-                                                                               
        php_self_len, track_vars_array, PARSE_SERVER TSRMLS_CC) == FAILURE) {
+               if (php_register_variable_with_conv(conv, 
ZEND_STRL("PHP_SELF"), php_self, php_self_len, track_vars_array, PARSE_SERVER 
TSRMLS_CC) == FAILURE) {
                        php_error(E_WARNING, "Failed to decode _SERVER array 
entry");
                }
                efree(php_self);
        } else {
                php_self = SG(request_info).request_uri ? 
SG(request_info).request_uri : "";
                php_self_len = strlen(php_self);
-               if (php_register_variable_with_conv(conv, 
ZEND_STRL("PHP_SELF"), php_self,
-                                                                               
        php_self_len, track_vars_array, PARSE_SERVER TSRMLS_CC) == FAILURE) {
+               if (php_register_variable_with_conv(conv, 
ZEND_STRL("PHP_SELF"), php_self, php_self_len, track_vars_array, PARSE_SERVER 
TSRMLS_CC) == FAILURE) {
                        php_error(E_WARNING, "Failed to decode _SERVER array 
entry");
                }
        }
@@ -750,8 +759,9 @@
                }
        }
 
-       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);
 
@@ -917,7 +927,8 @@
        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) {
@@ -926,7 +937,8 @@
                                break;
                        }
                        if (IS_SLASH(*(p-1)) &&
-                           (*(p+2) == 0 || IS_SLASH(*(p+2)))) {
+                               (*(p+2) == 0 || IS_SLASH(*(p+2)))
+                       ) {
                                        return 0;
                        }
                }
@@ -1008,8 +1020,8 @@
        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;
        }
@@ -1025,9 +1037,9 @@
        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);
@@ -1069,12 +1081,13 @@
                        }
 
                        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;
@@ -1095,7 +1108,7 @@
                                (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)
                        ) {
@@ -1155,9 +1168,8 @@
                                                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;
@@ -1440,11 +1452,10 @@
 
 #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
@@ -1477,7 +1488,7 @@
 
        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") ||
@@ -1530,8 +1541,8 @@
                                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);
@@ -1573,7 +1584,7 @@
                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;
@@ -1589,11 +1600,11 @@
 
 #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;
@@ -1712,7 +1723,7 @@
                                                break;
                                        } else if (exit_signal) {
                                                break;
-                                       }                                       
        
+                                       }
                                }
                                if (exit_signal) {
 #if 0
@@ -1763,7 +1774,7 @@
                /* 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();
                }
@@ -1905,13 +1916,13 @@
                                }
 
                                /* 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);
@@ -1957,7 +1968,7 @@
                        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);
@@ -1986,8 +1997,8 @@
                                                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;
                                        }
@@ -2063,8 +2074,8 @@
                        {
                                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);

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to