diff options
| author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:34:59 -0400 |
|---|---|---|
| committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:34:59 -0400 |
| commit | ce7edc9b3c7370f32fec0bc7a8ec3e29ed9a5f61 (patch) | |
| tree | acdb9a8816483652a9db1a47db71df5df43707c5 /sapi/cgi | |
| parent | 10f5b47dc7c1cf2b9a00991629f43652710322d3 (diff) | |
| download | php-ce7edc9b3c7370f32fec0bc7a8ec3e29ed9a5f61.tar.gz | |
Imported Upstream version 5.1.1upstream/5.1.1
Diffstat (limited to 'sapi/cgi')
| -rw-r--r-- | sapi/cgi/cgi_main.c | 368 | ||||
| -rw-r--r-- | sapi/cgi/config9.m4 | 28 | ||||
| -rw-r--r-- | sapi/cgi/getopt.c | 2 | ||||
| -rw-r--r-- | sapi/cgi/libfcgi/acinclude.m4 | 6 | ||||
| -rw-r--r-- | sapi/cgi/php_getopt.h | 2 |
5 files changed, 196 insertions, 210 deletions
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 459ceb985..0b85c170a 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | + | Copyright (c) 1997-2005 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: cgi_main.c,v 1.256.2.6 2005/04/28 14:24:21 sniper Exp $ */ +/* $Id: cgi_main.c,v 1.267.2.2 2005/11/02 14:38:13 mike Exp $ */ #include "php.h" #include "php_globals.h" @@ -76,7 +76,6 @@ #include "zend_highlight.h" #include "zend_indent.h" - #include "php_getopt.h" #if PHP_FASTCGI @@ -150,7 +149,7 @@ static const opt_struct OPTIONS[] = { #if ENABLE_PATHINFO_CHECK /* true global. this is retreived once only, even for fastcgi */ -long fix_pathinfo=1; +long fix_pathinfo = 1; #endif #ifdef PHP_WIN32 @@ -178,7 +177,7 @@ static int module_name_cmp(const void *a, const void *b TSRMLS_DC) Bucket *s = *((Bucket **) b); return strcasecmp(((zend_module_entry *)f->pData)->name, - ((zend_module_entry *)s->pData)->name); + ((zend_module_entry *)s->pData)->name); } static void print_modules(TSRMLS_D) @@ -230,8 +229,8 @@ static inline size_t sapi_cgibin_single_write(const char *str, uint str_length T #if PHP_FASTCGI if (!FCGX_IsCGI()) { - FCGX_Request *request = (FCGX_Request *)SG(server_context); - long ret = FCGX_PutStr( str, str_length, request->out ); + FCGX_Request *request = (FCGX_Request *) SG(server_context); + long ret = FCGX_PutStr(str, str_length, request->out); if (ret <= 0) { return 0; } @@ -272,7 +271,7 @@ static void sapi_cgibin_flush(void *server_context) { #if PHP_FASTCGI if (!FCGX_IsCGI()) { - FCGX_Request *request = (FCGX_Request *)server_context; + FCGX_Request *request = (FCGX_Request *) server_context; if ( #ifndef PHP_WIN32 !parent && @@ -283,7 +282,7 @@ static void sapi_cgibin_flush(void *server_context) return; } #endif - if (fflush(stdout)==EOF) { + if (fflush(stdout) == EOF) { php_handle_aborted_connection(); } } @@ -297,7 +296,7 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) zend_llist_position pos; long rfc2616_headers = 0, nph = 0; - if(SG(request_info).no_headers == 1) { + if (SG(request_info).no_headers == 1) { return SAPI_HEADER_SENT_SUCCESSFULLY; } /* Check wheater to send RFC2616 style headers compatible with @@ -313,7 +312,8 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) nph = 0; } - if (nph || SG(sapi_headers).http_response_code != 200) { + if (nph || SG(sapi_headers).http_response_code != 200) + { int len; if (rfc2616_headers && SG(sapi_headers).http_status_line) { @@ -331,20 +331,13 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) PHPWRITE_H(buf, len); } - if (SG(sapi_headers).send_default_content_type) { - char *hd; - - hd = sapi_get_default_content_type(TSRMLS_C); - PHPWRITE_H("Content-type: ", sizeof("Content-type: ")-1); - PHPWRITE_H(hd, strlen(hd)); - PHPWRITE_H("\r\n", 2); - efree(hd); - } - h = zend_llist_get_first_ex(&sapi_headers->headers, &pos); - while (h) { - PHPWRITE_H(h->header, h->header_len); - PHPWRITE_H("\r\n", 2); + while (h) { + /* prevent CRLFCRLF */ + if (h->header_len) { + PHPWRITE_H(h->header, h->header_len); + PHPWRITE_H("\r\n", 2); + } h = zend_llist_get_next_ex(&sapi_headers->headers, &pos); } PHPWRITE_H("\r\n", 2); @@ -360,21 +353,21 @@ static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) char *pos = buffer; #endif - count_bytes = MIN(count_bytes, (uint)SG(request_info).content_length-SG(read_post_bytes)); + count_bytes = MIN(count_bytes, (uint) SG(request_info).content_length - SG(read_post_bytes)); while (read_bytes < count_bytes) { #if PHP_FASTCGI if (!FCGX_IsCGI()) { - FCGX_Request *request = (FCGX_Request *)SG(server_context); - tmp_read_bytes = FCGX_GetStr( pos, count_bytes-read_bytes, request->in ); + FCGX_Request *request = (FCGX_Request *) SG(server_context); + tmp_read_bytes = FCGX_GetStr(pos, count_bytes - read_bytes, request->in); pos += tmp_read_bytes; } else { - tmp_read_bytes = read(0, buffer+read_bytes, count_bytes-read_bytes); + tmp_read_bytes = read(0, buffer + read_bytes, count_bytes - read_bytes); } #else - tmp_read_bytes = read(0, buffer+read_bytes, count_bytes-read_bytes); + tmp_read_bytes = read(0, buffer + read_bytes, count_bytes - read_bytes); #endif - if (tmp_read_bytes<=0) { + if (tmp_read_bytes <= 0) { break; } read_bytes += tmp_read_bytes; @@ -390,7 +383,7 @@ static char *sapi_cgibin_getenv(char *name, size_t name_len TSRMLS_DC) of a request. So we have to do our own lookup to get env vars. This could probably be faster somehow. */ if (!FCGX_IsCGI()) { - FCGX_Request *request = (FCGX_Request *)SG(server_context); + FCGX_Request *request = (FCGX_Request *) SG(server_context); return FCGX_GetParam(name,request->envp); } #endif @@ -401,20 +394,20 @@ static char *sapi_cgibin_getenv(char *name, size_t name_len TSRMLS_DC) static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC) { - int len=0; + int len = 0; char *buf = NULL; if (!name) { return NULL; } - len = strlen(name) + (value?strlen(value):0) + sizeof("=") + 2; - buf = (char *)malloc(len); + len = strlen(name) + (value ? strlen(value) : 0) + sizeof("=") + 2; + buf = (char *) malloc(len); if (buf == NULL) { return getenv(name); } if (value) { - snprintf(buf,len-1,"%s=%s", name, value); + snprintf(buf, len - 1, "%s=%s", name, value); } else { - snprintf(buf,len-1,"%s=", name); + snprintf(buf, len - 1, "%s=", name); } #if PHP_FASTCGI /* when php is started by mod_fastcgi, no regular environment @@ -422,8 +415,8 @@ static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC) of a request. So we have to do our own lookup to get env vars. This could probably be faster somehow. */ if (!FCGX_IsCGI()) { - FCGX_Request *request = (FCGX_Request *)SG(server_context); - FCGX_PutEnv(request,buf); + FCGX_Request *request = (FCGX_Request *) SG(server_context); + FCGX_PutEnv(request, buf); free(buf); return sapi_cgibin_getenv(name,0 TSRMLS_CC); } @@ -439,26 +432,26 @@ static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC) static char *sapi_cgi_read_cookies(TSRMLS_D) { - return sapi_cgibin_getenv((char *)"HTTP_COOKIE",0 TSRMLS_CC); + return sapi_cgibin_getenv((char *) "HTTP_COOKIE", 0 TSRMLS_CC); } #if PHP_FASTCGI void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC) { if (!FCGX_IsCGI()) { - FCGX_Request *request = (FCGX_Request *)SG(server_context); + FCGX_Request *request = (FCGX_Request *) SG(server_context); char **env, *p, *t; - /* turn off magic_quotes while importing environment variables */ int magic_quotes_gpc = PG(magic_quotes_gpc); - PG(magic_quotes_gpc) = 0; + /* turn off magic_quotes while importing environment variables */ + PG(magic_quotes_gpc) = 0; for (env = request->envp; env != NULL && *env != NULL; env++) { p = strchr(*env, '='); if (!p) { /* malformed entry? */ continue; } t = estrndup(*env, p - *env); - php_register_variable(t, p+1, array_ptr TSRMLS_CC); + php_register_variable(t, p + 1, array_ptr TSRMLS_CC); efree(t); } PG(magic_quotes_gpc) = magic_quotes_gpc; @@ -475,10 +468,9 @@ static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC) */ php_import_environment_variables(track_vars_array TSRMLS_CC); /* Build the special-case PHP_SELF variable for the CGI version */ - php_register_variable("PHP_SELF", (SG(request_info).request_uri ? SG(request_info).request_uri:""), track_vars_array TSRMLS_CC); + php_register_variable("PHP_SELF", (SG(request_info).request_uri ? SG(request_info).request_uri : ""), track_vars_array TSRMLS_CC); } - static void sapi_cgi_log_message(char *message) { #if PHP_FASTCGI @@ -488,10 +480,12 @@ static void sapi_cgi_log_message(char *message) if (cfg_get_long("fastcgi.logging", &logging) == FAILURE) { logging = 1; } - + if (!FCGX_IsCGI() && logging) { - FCGX_Request *request = (FCGX_Request *)SG(server_context); - FCGX_FPrintF( request->err, "%s\n", message ); + FCGX_Request *request = (FCGX_Request *) SG(server_context); + if (request) { + FCGX_FPrintF(request->err, "%s\n", message); + } /* ignore return code */ } else #endif /* PHP_FASTCGI */ @@ -505,7 +499,7 @@ static int sapi_cgi_deactivate(TSRMLS_D) 2. When the first call occurs and the request is not set up, flush fails on FastCGI. */ - if(SG(sapi_started)) { + if (SG(sapi_started)) { sapi_cgibin_flush(SG(server_context)); } return SUCCESS; @@ -553,6 +547,7 @@ static sapi_module_struct cgi_sapi_module = { sapi_cgi_register_variables, /* register server variables */ sapi_cgi_log_message, /* Log message */ + NULL, /* Get request time */ STANDARD_SAPI_MODULE_PROPERTIES }; @@ -664,8 +659,8 @@ static void php_cgi_usage(char *argv0) */ static void init_request_info(TSRMLS_D) { - char *env_script_filename = sapi_cgibin_getenv("SCRIPT_FILENAME",0 TSRMLS_CC); - char *env_path_translated = sapi_cgibin_getenv("PATH_TRANSLATED",0 TSRMLS_CC); + char *env_script_filename = sapi_cgibin_getenv("SCRIPT_FILENAME", 0 TSRMLS_CC); + char *env_path_translated = sapi_cgibin_getenv("PATH_TRANSLATED", 0 TSRMLS_CC); char *script_path_translated = env_script_filename; #if !DISCARD_PATH @@ -680,6 +675,7 @@ static void init_request_info(TSRMLS_D) /* initialize the defaults */ SG(request_info).path_translated = NULL; SG(request_info).request_method = NULL; + SG(request_info).proto_num = 1000; SG(request_info).query_string = NULL; SG(request_info).request_uri = NULL; SG(request_info).content_type = NULL; @@ -692,29 +688,29 @@ static void init_request_info(TSRMLS_D) 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",0 TSRMLS_CC); - char *content_type = sapi_cgibin_getenv("CONTENT_TYPE",0 TSRMLS_CC); - char *env_path_info = sapi_cgibin_getenv("PATH_INFO",0 TSRMLS_CC); - char *env_script_name = sapi_cgibin_getenv("SCRIPT_NAME",0 TSRMLS_CC); + char *content_length = sapi_cgibin_getenv("CONTENT_LENGTH", 0 TSRMLS_CC); + char *content_type = sapi_cgibin_getenv("CONTENT_TYPE", 0 TSRMLS_CC); + char *env_path_info = sapi_cgibin_getenv("PATH_INFO", 0 TSRMLS_CC); + char *env_script_name = sapi_cgibin_getenv("SCRIPT_NAME", 0 TSRMLS_CC); #if ENABLE_PATHINFO_CHECK struct stat st; - char *env_redirect_url = sapi_cgibin_getenv("REDIRECT_URL",0 TSRMLS_CC); - char *env_document_root = sapi_cgibin_getenv("DOCUMENT_ROOT",0 TSRMLS_CC); + char *env_redirect_url = sapi_cgibin_getenv("REDIRECT_URL", 0 TSRMLS_CC); + char *env_document_root = sapi_cgibin_getenv("DOCUMENT_ROOT", 0 TSRMLS_CC); if (fix_pathinfo) { /* save the originals first for anything we change later */ if (env_path_translated) { - _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED",env_path_translated TSRMLS_CC); + _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", env_path_translated TSRMLS_CC); } if (env_path_info) { - _sapi_cgibin_putenv("ORIG_PATH_INFO",env_path_info TSRMLS_CC); + _sapi_cgibin_putenv("ORIG_PATH_INFO", env_path_info TSRMLS_CC); } if (env_script_name) { - _sapi_cgibin_putenv("ORIG_SCRIPT_NAME",env_script_name TSRMLS_CC); + _sapi_cgibin_putenv("ORIG_SCRIPT_NAME", env_script_name TSRMLS_CC); } if (env_script_filename) { - _sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME",env_script_filename TSRMLS_CC); + _sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME", env_script_filename TSRMLS_CC); } if (!env_document_root) { /* ini version of document root */ @@ -724,7 +720,7 @@ static void init_request_info(TSRMLS_D) /* set the document root, this makes a more consistent env for php scripts */ if (env_document_root) { - env_document_root = _sapi_cgibin_putenv("DOCUMENT_ROOT",env_document_root TSRMLS_CC); + env_document_root = _sapi_cgibin_putenv("DOCUMENT_ROOT", env_document_root TSRMLS_CC); /* fix docroot */ TRANSLATE_SLASHES(env_document_root); } @@ -738,13 +734,13 @@ static void init_request_info(TSRMLS_D) */ script_path_translated = env_path_translated; /* we correct SCRIPT_NAME now in case we don't have PATH_INFO */ - env_script_name = _sapi_cgibin_putenv("SCRIPT_NAME",env_redirect_url TSRMLS_CC); + env_script_name = _sapi_cgibin_putenv("SCRIPT_NAME", env_redirect_url TSRMLS_CC); } #ifdef __riscos__ /* Convert path to unix format*/ - __riscosify_control|=__RISCOSIFY_DONT_CHECK_DIR; - script_path_translated=__unixify(script_path_translated,0,NULL,1,0); + __riscosify_control |= __RISCOSIFY_DONT_CHECK_DIR; + script_path_translated = __unixify(script_path_translated, 0, NULL, 1, 0); #endif /* @@ -752,14 +748,14 @@ static void init_request_info(TSRMLS_D) * of it by stat'ing back through the '/' * this fixes url's like /info.php/test */ - if (script_path_translated && stat( script_path_translated, &st ) == -1 ) { + if (script_path_translated && stat(script_path_translated, &st) == -1 ) { char *pt = estrdup(script_path_translated); int len = strlen(pt); char *ptr; - while( (ptr = strrchr(pt,'/')) || (ptr = strrchr(pt,'\\')) ) { + while ((ptr = strrchr(pt, '/')) || (ptr = strrchr(pt, '\\'))) { *ptr = 0; - if ( stat(pt, &st) == 0 && S_ISREG(st.st_mode) ) { + if (stat(pt, &st) == 0 && S_ISREG(st.st_mode)) { /* * okay, we found the base script! * work out how many chars we had to strip off; @@ -776,22 +772,24 @@ static void init_request_info(TSRMLS_D) * out what SCRIPT_NAME should be */ int slen = len - strlen(pt); - int pilen = strlen( env_path_info ); + int pilen = strlen(env_path_info); char *path_info = env_path_info + pilen - slen; - env_path_info = _sapi_cgibin_putenv("PATH_INFO",path_info TSRMLS_CC); - script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME",pt TSRMLS_CC); + env_path_info = _sapi_cgibin_putenv("PATH_INFO", path_info TSRMLS_CC); + script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", pt TSRMLS_CC); TRANSLATE_SLASHES(pt); /* figure out docroot SCRIPT_FILENAME minus SCRIPT_NAME - */ + */ - if (env_document_root) { + if (env_document_root) + { int l = strlen(env_document_root); int path_translated_len = 0; char *path_translated = NULL; - if (env_document_root[l-1]=='/') { + + if (env_document_root[l - 1] == '/') { --l; } @@ -801,31 +799,29 @@ static void init_request_info(TSRMLS_D) * * SCRIPT_NAME is the portion of the path beyond docroot */ - env_script_name = _sapi_cgibin_putenv("SCRIPT_NAME",pt+l TSRMLS_CC); + env_script_name = _sapi_cgibin_putenv("SCRIPT_NAME", pt + l TSRMLS_CC); - /* - * PATH_TRANSATED = DOCUMENT_ROOT + PATH_INFO - */ + /* PATH_TRANSATED = DOCUMENT_ROOT + PATH_INFO */ path_translated_len = l + strlen(env_path_info) + 2; - path_translated = (char *)emalloc(path_translated_len); + path_translated = (char *) emalloc(path_translated_len); *path_translated = 0; - strncat(path_translated,env_document_root,l); - strcat(path_translated,env_path_info); - env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED",path_translated TSRMLS_CC); + strncat(path_translated, env_document_root, l); + strcat(path_translated, env_path_info); + env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED", path_translated TSRMLS_CC); efree(path_translated); - } else if (env_script_name && - strstr(pt,env_script_name)) { - /* - * PATH_TRANSATED = PATH_TRANSATED - SCRIPT_NAME + PATH_INFO - */ - int ptlen = strlen(pt)-strlen(env_script_name); + } else if (env_script_name && + strstr(pt, env_script_name) + ) { + /* 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) + 2; char *path_translated = NULL; - path_translated = (char *)emalloc(path_translated_len); + + path_translated = (char *) emalloc(path_translated_len); *path_translated = 0; - strncat(path_translated,pt,ptlen); - strcat(path_translated,env_path_info); - env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED",path_translated TSRMLS_CC); + strncat(path_translated, pt, ptlen); + strcat(path_translated, env_path_info); + env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED", path_translated TSRMLS_CC); efree(path_translated); } break; @@ -837,7 +833,7 @@ static void init_request_info(TSRMLS_D) * a valid path... we will fail, badly. of course we would * have failed anyway... we output 'no input file' now. */ - script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME",NULL TSRMLS_CC); + script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", NULL TSRMLS_CC); SG(sapi_headers).http_response_code = 404; } if (pt) { @@ -845,7 +841,7 @@ static void init_request_info(TSRMLS_D) } } else { /* make sure path_info/translated are empty */ - script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME",script_path_translated TSRMLS_CC); + script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", script_path_translated TSRMLS_CC); _sapi_cgibin_putenv("PATH_INFO", NULL TSRMLS_CC); _sapi_cgibin_putenv("PATH_TRANSLATED", NULL TSRMLS_CC); } @@ -865,15 +861,16 @@ static void init_request_info(TSRMLS_D) #if ENABLE_PATHINFO_CHECK } #endif - SG(request_info).request_method = sapi_cgibin_getenv("REQUEST_METHOD",0 TSRMLS_CC); - SG(request_info).query_string = sapi_cgibin_getenv("QUERY_STRING",0 TSRMLS_CC); + SG(request_info).request_method = sapi_cgibin_getenv("REQUEST_METHOD", 0 TSRMLS_CC); + /* FIXME - Work out proto_num here */ + SG(request_info).query_string = sapi_cgibin_getenv("QUERY_STRING", 0 TSRMLS_CC); /* some server configurations allow '..' to slip through in the translated path. We'll just refuse to handle such a path. */ if (script_path_translated && !strstr(script_path_translated, "..")) { SG(request_info).path_translated = estrdup(script_path_translated); } SG(request_info).content_type = (content_type ? content_type : "" ); - SG(request_info).content_length = (content_length?atoi(content_length):0); + SG(request_info).content_length = (content_length ? atoi(content_length) : 0); /* The CGI RFC allows servers to pass on unvalidated Authorization data */ auth = sapi_cgibin_getenv("HTTP_AUTHORIZATION",0 TSRMLS_CC); @@ -894,7 +891,7 @@ static void define_command_line_ini_entry(char *arg) } else { value = "1"; } - zend_alter_ini_entry(name, strlen(name)+1, value, strlen(value), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); + zend_alter_ini_entry(name, strlen(name) + 1, value, strlen(value), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); } @@ -919,20 +916,19 @@ static void php_register_command_line_global_vars(char **arg TSRMLS_DC) */ void fastcgi_cleanup(int signal) { - #ifdef DEBUG_FASTCGI - fprintf( stderr, "FastCGI shutdown, pid %d\n", getpid() ); + fprintf(stderr, "FastCGI shutdown, pid %d\n", getpid()); #endif #ifndef PHP_WIN32 - sigaction( SIGTERM, &old_term, 0 ); + sigaction(SIGTERM, &old_term, 0); /* Kill all the processes in our process group */ - kill( -pgroup, SIGTERM ); + kill(-pgroup, SIGTERM); #endif /* We should exit at this point, but MacOSX doesn't seem to */ - exit( 0 ); + exit(0); } #endif @@ -946,11 +942,11 @@ int main(int argc, char *argv[]) int retval = FAILURE; char *s; /* temporary locals */ - int behavior=PHP_MODE_STANDARD; - int no_headers=0; - int orig_optind=php_optind; - char *orig_optarg=php_optarg; - char *script_file=NULL; + int behavior = PHP_MODE_STANDARD; + int no_headers = 0; + int orig_optind = php_optind; + char *orig_optarg = php_optarg; + char *script_file = NULL; zend_llist global_vars; #if FORCE_CGI_REDIRECT long force_redirect = 1; @@ -978,7 +974,7 @@ int main(int argc, char *argv[]) #ifdef PHP_WIN32 long impersonate = 0; #else - int status = 0; + int status = 0; #endif #endif /* PHP_FASTCGI */ @@ -988,9 +984,8 @@ int main(int argc, char *argv[]) { char szMessage [256]; 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); + GetCurrentProcessId(), GetCurrentProcessId(), argv[0]); + MessageBox(NULL, szMessage, "CGI Debug Time!", MB_OK|MB_SERVICE_NOTIFICATION); } #endif @@ -1012,10 +1007,10 @@ int main(int argc, char *argv[]) sapi_startup(&cgi_sapi_module); #ifdef PHP_WIN32 - _fmode = _O_BINARY; /*sets default for file streams to binary */ - setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */ - setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */ - setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */ + _fmode = _O_BINARY; /* sets default for file streams to binary */ + setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */ + setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */ + setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */ #endif #if PHP_FASTCGI @@ -1023,17 +1018,18 @@ int main(int argc, char *argv[]) #endif /* 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. */ - if (getenv("SERVER_SOFTWARE") - || getenv("SERVER_NAME") - || getenv("GATEWAY_INTERFACE") - || getenv("REQUEST_METHOD")) { + if (getenv("SERVER_SOFTWARE") || + getenv("SERVER_NAME") || + getenv("GATEWAY_INTERFACE") || + getenv("REQUEST_METHOD") + ) { cgi = 1; } #if PHP_FASTCGI } #endif - while ((c=php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0))!=-1) { + while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) { switch (c) { case 'c': cgi_sapi_module.php_ini_path_override = strdup(php_optarg); @@ -1081,12 +1077,12 @@ int main(int argc, char *argv[]) #if FORCE_CGI_REDIRECT /* check force_cgi after startup, so we have proper output */ if (cfg_get_long("cgi.force_redirect", &force_redirect) == FAILURE) { - force_redirect = 1; + force_redirect = 1; } if (cgi && force_redirect) { - if (cfg_get_string("cgi.redirect_status_env", &redirect_status_env) == FAILURE) { - redirect_status_env = NULL; - } + if (cfg_get_string("cgi.redirect_status_env", &redirect_status_env) == FAILURE) { + redirect_status_env = NULL; + } /* Apache will generate REDIRECT_STATUS, * Netscape and redirect.so will generate HTTP_REDIRECT_STATUS. * redirect.so and installation instructions available from @@ -1096,7 +1092,7 @@ int main(int argc, char *argv[]) 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 */ && (!redirect_status_env || !getenv(redirect_status_env)) ) { SG(sapi_headers).http_response_code = 400; @@ -1111,19 +1107,18 @@ consult the installation file that came with this distribution, or visit \n\ <a href=\"http://php.net/install.windows\">the manual page</a>.</p>\n"); #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. - */ - tsrm_shutdown(); + /* 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. + */ + tsrm_shutdown(); #endif - return FAILURE; } } -#endif /* FORCE_CGI_REDIRECT */ +#endif /* FORCE_CGI_REDIRECT */ #if ENABLE_PATHINFO_CHECK if (cfg_get_long("cgi.fix_pathinfo", &fix_pathinfo) == FAILURE) { @@ -1156,10 +1151,10 @@ consult the installation file that came with this distribution, or visit \n\ } else { fcgi_fd = FCGX_OpenSocket(bindpath, 128); } - if( fcgi_fd < 0 ) { + if (fcgi_fd < 0) { fprintf(stderr, "Couldn't create FastCGI listen socket on port %s\n", bindpath); #ifdef ZTS - tsrm_shutdown(); + tsrm_shutdown(); #endif return FAILURE; } @@ -1168,11 +1163,10 @@ consult the installation file that came with this distribution, or visit \n\ #endif if (fastcgi) { /* How many times to run PHP scripts before dying */ - if( getenv( "PHP_FCGI_MAX_REQUESTS" )) { - max_requests = atoi( getenv( "PHP_FCGI_MAX_REQUESTS" )); - if( !max_requests ) { - fprintf( stderr, - "PHP_FCGI_MAX_REQUESTS is not valid\n" ); + if (getenv("PHP_FCGI_MAX_REQUESTS")) { + max_requests = atoi(getenv("PHP_FCGI_MAX_REQUESTS")); + if (!max_requests) { + fprintf(stderr, "PHP_FCGI_MAX_REQUESTS is not valid\n"); return FAILURE; } } @@ -1183,20 +1177,19 @@ consult the installation file that came with this distribution, or visit \n\ /* library is already initialized, now init our request */ FCGX_Init(); - FCGX_InitRequest( &request, fcgi_fd, 0 ); + FCGX_InitRequest(&request, fcgi_fd, 0); #ifndef PHP_WIN32 /* Pre-fork, if required */ - if( getenv( "PHP_FCGI_CHILDREN" )) { - children = atoi( getenv( "PHP_FCGI_CHILDREN" )); - if( !children ) { - fprintf( stderr, - "PHP_FCGI_CHILDREN is not valid\n" ); + if (getenv("PHP_FCGI_CHILDREN")) { + children = atoi(getenv("PHP_FCGI_CHILDREN")); + if (!children) { + fprintf(stderr, "PHP_FCGI_CHILDREN is not valid\n"); return FAILURE; } } - if( children ) { + if (children) { int running = 0; pid_t pid; @@ -1204,27 +1197,26 @@ consult the installation file that came with this distribution, or visit \n\ setsid(); pgroup = getpgrp(); #ifdef DEBUG_FASTCGI - fprintf( stderr, "Process group %d\n", pgroup ); + fprintf(stderr, "Process group %d\n", pgroup); #endif /* Set up handler to kill children upon exit */ act.sa_flags = 0; act.sa_handler = fastcgi_cleanup; - if( sigaction( SIGTERM, &act, &old_term ) || - sigaction( SIGINT, &act, &old_int ) || - sigaction( SIGQUIT, &act, &old_quit )) { - perror( "Can't set signals" ); - exit( 1 ); + if (sigaction(SIGTERM, &act, &old_term) || + sigaction(SIGINT, &act, &old_int) || + sigaction(SIGQUIT, &act, &old_quit)) { + perror("Can't set signals"); + exit(1); } - while( parent ) { + while (parent) { do { #ifdef DEBUG_FASTCGI - fprintf( stderr, "Forking, %d running\n", - running ); + fprintf(stderr, "Forking, %d running\n", running); #endif pid = fork(); - switch( pid ) { + switch (pid) { case 0: /* One of the children. * Make sure we don't go round the @@ -1233,27 +1225,26 @@ consult the installation file that came with this distribution, or visit \n\ parent = 0; /* don't catch our signals */ - sigaction( SIGTERM, &old_term, 0 ); - sigaction( SIGQUIT, &old_quit, 0 ); - sigaction( SIGINT, &old_int, 0 ); + sigaction(SIGTERM, &old_term, 0); + sigaction(SIGQUIT, &old_quit, 0); + sigaction(SIGINT, &old_int, 0); break; case -1: - perror( "php (pre-forking)" ); - exit( 1 ); + perror("php (pre-forking)"); + exit(1); break; default: /* Fine */ running++; break; } - } while( parent && ( running < children )); + } while (parent && (running < children)); - if( parent ) { + if (parent) { #ifdef DEBUG_FASTCGI - fprintf( stderr, "Wait for kids, pid %d\n", - getpid() ); + fprintf(stderr, "Wait for kids, pid %d\n", getpid()); #endif - wait( &status ); + wait(&status); running--; } } @@ -1264,7 +1255,7 @@ consult the installation file that came with this distribution, or visit \n\ #endif /* FASTCGI */ zend_first_try { - while ((c=php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 1))!=-1) { + while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 1)) != -1) { switch (c) { case 'h': case '?': @@ -1284,7 +1275,6 @@ consult the installation file that came with this distribution, or visit \n\ #if PHP_FASTCGI /* start of FAST CGI loop */ /* 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. */ @@ -1295,9 +1285,7 @@ consult the installation file that came with this distribution, or visit \n\ if (impersonate) OS_SetImpersonate(); } #endif - - while (!fastcgi - || FCGX_Accept_r( &request ) >= 0) { + while (!fastcgi || FCGX_Accept_r(&request) >= 0) { #endif #if PHP_FASTCGI @@ -1305,19 +1293,15 @@ consult the installation file that came with this distribution, or visit \n\ #else SG(server_context) = (void *) 1; /* avoid server_context==NULL checks */ #endif - init_request_info(TSRMLS_C); - zend_llist_init(&global_vars, sizeof(char *), NULL, 0); - CG(interactive) = 0; if (!cgi #if PHP_FASTCGI && !fastcgi #endif - ) { - + ) { if (cgi_sapi_module.php_ini_path_override && cgi_sapi_module.php_ini_ignore) { no_headers = 1; php_output_startup(); @@ -1351,8 +1335,8 @@ consult the installation file that came with this distribution, or visit \n\ script_file = estrdup(php_optarg); no_headers = 1; /* arguments after the file are considered script args */ - SG(request_info).argc = argc - (php_optind-1); - SG(request_info).argv = &argv[php_optind-1]; + SG(request_info).argc = argc - (php_optind - 1); + SG(request_info).argv = &argv[php_optind - 1]; break; case 'g': /* define global variables on command line */ @@ -1374,12 +1358,12 @@ consult the installation file that came with this distribution, or visit \n\ } php_print_info(0xFFFFFFFF TSRMLS_CC); php_end_ob_buffers(1 TSRMLS_CC); - exit(1); + exit(0); break; case 'l': /* syntax check mode */ no_headers = 1; - behavior=PHP_MODE_LINT; + behavior = PHP_MODE_LINT; break; case 'm': /* list compiled in modules */ @@ -1392,7 +1376,7 @@ consult the installation file that came with this distribution, or visit \n\ print_extensions(TSRMLS_C); php_printf("\n"); php_end_ob_buffers(1 TSRMLS_CC); - exit(1); + exit(0); break; #if 0 /* not yet operational, see also below ... */ @@ -1406,7 +1390,7 @@ consult the installation file that came with this distribution, or visit \n\ break; case 's': /* generate highlighted HTML from source */ - behavior=PHP_MODE_HIGHLIGHT; + behavior = PHP_MODE_HIGHLIGHT; break; case 'v': /* show php version & quit */ @@ -1420,16 +1404,16 @@ consult the installation file that came with this distribution, or visit \n\ SG(request_info).no_headers = 1; } #if ZEND_DEBUG - php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2004 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); + php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2005 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); #else - php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2004 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); + php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2005 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); #endif php_end_ob_buffers(1 TSRMLS_CC); - exit(1); + exit(0); break; case 'w': - behavior=PHP_MODE_STRIP; + behavior = PHP_MODE_STRIP; break; case 'z': /* load extension file */ @@ -1511,7 +1495,7 @@ consult the installation file that came with this distribution, or visit \n\ /* request startup only after we've done all we can to get path_translated */ - if (php_request_startup(TSRMLS_C)==FAILURE) { + if (php_request_startup(TSRMLS_C) == FAILURE) { #if PHP_FASTCGI if (fastcgi) { FCGX_Finish_r(&request); @@ -1652,7 +1636,7 @@ fastcgi_request_done: if (!fastcgi) break; /* only fastcgi will get here */ requests++; - if(max_requests && (requests == max_requests)) { + if (max_requests && (requests == max_requests)) { FCGX_Finish_r(&request); #ifndef PHP_WIN32 if (bindpath) { @@ -1680,7 +1664,7 @@ fastcgi_request_done: #endif #if PHP_WIN32 && ZEND_DEBUG && 0 - _CrtDumpMemoryLeaks( ); + _CrtDumpMemoryLeaks(); #endif return exit_status; diff --git a/sapi/cgi/config9.m4 b/sapi/cgi/config9.m4 index 6c969c7b2..a3c4522c9 100644 --- a/sapi/cgi/config9.m4 +++ b/sapi/cgi/config9.m4 @@ -1,5 +1,5 @@ dnl -dnl $Id: config9.m4,v 1.12.2.3 2005/04/21 15:13:16 sniper Exp $ +dnl $Id: config9.m4,v 1.17 2005/07/07 05:54:43 dmitry Exp $ dnl AC_ARG_ENABLE(cgi, @@ -12,9 +12,9 @@ AC_ARG_ENABLE(cgi, AC_ARG_ENABLE(force-cgi-redirect, [ --enable-force-cgi-redirect - Enable the security check for internal server - redirects. You should use this if you are - running the CGI version with Apache.], + CGI: Enable the security check for internal server + redirects. You should use this if you are + running the CGI version with Apache], [ PHP_FORCE_CGI_REDIRECT=$enableval ],[ @@ -22,10 +22,10 @@ AC_ARG_ENABLE(force-cgi-redirect, ]) AC_ARG_ENABLE(discard-path, -[ --enable-discard-path If this is enabled, the PHP CGI binary - can safely be placed outside of the - web tree and people will not be able - to circumvent .htaccess security.], +[ --enable-discard-path CGI: If this is enabled, the PHP CGI binary + can safely be placed outside of the + web tree and people will not be able + to circumvent .htaccess security], [ PHP_DISCARD_PATH=$enableval ],[ @@ -33,8 +33,8 @@ AC_ARG_ENABLE(discard-path, ]) AC_ARG_ENABLE(fastcgi, -[ --enable-fastcgi If this is enabled, the cgi module will - be built with support for fastcgi also.], +[ --enable-fastcgi CGI: If this is enabled, the cgi module will + be built with support for fastcgi also], [ PHP_ENABLE_FASTCGI=$enableval ],[ @@ -42,9 +42,8 @@ AC_ARG_ENABLE(fastcgi, ]) AC_ARG_ENABLE(path-info-check, -[ --disable-path-info-check - If this is disabled, paths such as - /info.php/test?a=b will fail to work.], +[ --disable-path-info-check CGI: If this is disabled, paths such as + /info.php/test?a=b will fail to work], [ PHP_ENABLE_PATHINFO_CHECK=$enableval ],[ @@ -153,6 +152,9 @@ if test "$PHP_SAPI" = "default"; then PHP_SELECT_SAPI(cgi, program, $PHP_FCGI_FILES cgi_main.c getopt.c, $PHP_FCGI_INCLUDE, '$(SAPI_CGI_PATH)') case $host_alias in + *aix*) + BUILD_CGI="echo '\#! .' > php.sym && echo >>php.sym && nm -BCpg \`echo \$(PHP_GLOBAL_OBJS) \$(PHP_SAPI_OBJS) | sed 's/\([A-Za-z0-9_]*\)\.lo/.libs\/\1.o/g'\` | \$(AWK) '{ if (((\$\$2 == \"T\") || (\$\$2 == \"D\") || (\$\$2 == \"B\")) && (substr(\$\$3,1,1) != \".\")) { print \$\$3 } }' | sort -u >> php.sym && \$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) -Wl,-brtl -Wl,-bE:php.sym \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_SAPI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CGI_PATH)" + ;; *darwin*) BUILD_CGI="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_SAPI_OBJS:.lo=.o) \$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CGI_PATH)" ;; diff --git a/sapi/cgi/getopt.c b/sapi/cgi/getopt.c index fb9091a6c..3551e9f27 100644 --- a/sapi/cgi/getopt.c +++ b/sapi/cgi/getopt.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | + | Copyright (c) 1997-2005 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | diff --git a/sapi/cgi/libfcgi/acinclude.m4 b/sapi/cgi/libfcgi/acinclude.m4 index 0397a9b3f..a55ce5cd3 100644 --- a/sapi/cgi/libfcgi/acinclude.m4 +++ b/sapi/cgi/libfcgi/acinclude.m4 @@ -1,4 +1,4 @@ -dnl $Id: acinclude.m4,v 1.2.2.1 2004/12/30 07:04:11 sniper Exp $ +dnl $Id: acinclude.m4,v 1.3 2004/12/30 07:08:37 sniper Exp $ AC_DEFUN([FCGI_COMMON_CHECKS], [ AC_MSG_CHECKING([for sun_len in sys/un.h]) @@ -101,7 +101,7 @@ dnl (with help from M. Frigo), as well as ac_pthread and hb_pthread dnl macros posted by AFC to the autoconf macro repository. We are also dnl grateful for the helpful feedback of numerous users. dnl -dnl @version $Id: acinclude.m4,v 1.2.2.1 2004/12/30 07:04:11 sniper Exp $ +dnl @version $Id: acinclude.m4,v 1.3 2004/12/30 07:08:37 sniper Exp $ dnl @author Steven G. Johnson <stevenj@alum.mit.edu> and Alejandro Forero Cuervo <bachue@bachue.com> AC_DEFUN([ACX_PTHREAD], [ @@ -302,7 +302,7 @@ dnl Currently this macro knows about GCC, Solaris C compiler, dnl Digital Unix C compiler, C for AIX Compiler, HP-UX C compiler, dnl and IRIX C compiler. dnl -dnl @version $Id: acinclude.m4,v 1.2.2.1 2004/12/30 07:04:11 sniper Exp $ +dnl @version $Id: acinclude.m4,v 1.3 2004/12/30 07:08:37 sniper Exp $ dnl @author Ville Laurikari <vl@iki.fi> dnl AC_DEFUN([AC_PROG_CC_WARNINGS], [ diff --git a/sapi/cgi/php_getopt.h b/sapi/cgi/php_getopt.h index 042fb014e..34ec40573 100644 --- a/sapi/cgi/php_getopt.h +++ b/sapi/cgi/php_getopt.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | + | Copyright (c) 1997-2005 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | |
