jani            Thu Jun  4 11:47:27 2009 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src/sapi/cgi   cgi_main.c 
  Log:
  MFH: CS + WS changes
  
http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.267.2.15.2.50.2.38&r2=1.267.2.15.2.50.2.39&diff_format=u
Index: php-src/sapi/cgi/cgi_main.c
diff -u php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.50.2.38 
php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.50.2.39
--- php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.50.2.38    Tue May 19 16:02:55 2009
+++ php-src/sapi/cgi/cgi_main.c Thu Jun  4 11:47:27 2009
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: cgi_main.c,v 1.267.2.15.2.50.2.38 2009/05/19 16:02:55 kalle Exp $ */
+/* $Id: cgi_main.c,v 1.267.2.15.2.50.2.39 2009/06/04 11:47:27 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++;
@@ -435,6 +445,7 @@
                                }
                        }
                }
+
                if (!has_status) {
                        PHPWRITE_H(buf, len);
                        ignore_status = 1;
@@ -445,15 +456,17 @@
        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 {
@@ -493,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);
@@ -519,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,9 +622,9 @@
                /* 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;
 
@@ -747,8 +760,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);
 
@@ -845,7 +859,7 @@
        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
 };
@@ -914,7 +928,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) {
@@ -923,7 +938,8 @@
                                break;
                        }
                        if (IS_SLASH(*(p-1)) &&
-                           (*(p+2) == 0 || IS_SLASH(*(p+2)))) {
+                               (*(p+2) == 0 || IS_SLASH(*(p+2)))
+                       ) {
                                        return 0;
                        }
                }
@@ -1005,8 +1021,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;
        }
@@ -1022,9 +1038,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);
@@ -1066,12 +1082,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;
@@ -1092,7 +1109,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)
                        ) {
@@ -1152,9 +1169,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;
@@ -1437,11 +1453,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
@@ -1474,7 +1489,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") ||
@@ -1527,8 +1542,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);
@@ -1570,7 +1585,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;
@@ -1586,11 +1601,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;
@@ -1709,7 +1724,7 @@
                                                break;
                                        } else if (exit_signal) {
                                                break;
-                                       }                                       
        
+                                       }
                                }
                                if (exit_signal) {
 #if 0
@@ -1762,7 +1777,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();
                }
@@ -1906,13 +1921,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);
@@ -1958,7 +1973,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);
@@ -1987,8 +2002,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 +2078,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