diff options
author | Ondřej Surý <ondrej@sury.org> | 2012-11-16 13:25:37 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2012-11-16 13:25:37 +0100 |
commit | 0b82e05fe264306004119e30119e665365331e17 (patch) | |
tree | b6ee689804e9ca3946a644a80760d821a032d42f /sapi | |
parent | b57a2691d5b72c3894e2d4e0f945cecc6b3a1953 (diff) | |
download | php-0b82e05fe264306004119e30119e665365331e17.tar.gz |
Imported Upstream version 5.5.0~alpha1upstream/5.5.0_alpha1
Diffstat (limited to 'sapi')
-rw-r--r-- | sapi/apache2handler/config.w32 | 20 | ||||
-rw-r--r-- | sapi/cgi/cgi_main.c | 1 | ||||
-rw-r--r-- | sapi/cli/php_cli_server.c | 86 | ||||
-rw-r--r--[-rwxr-xr-x] | sapi/cli/tests/003-2.phpt | 0 | ||||
-rw-r--r-- | sapi/cli/tests/php_cli_server_011.phpt | 41 | ||||
-rw-r--r-- | sapi/cli/tests/php_cli_server_013.phpt | 18 | ||||
-rw-r--r-- | sapi/cli/tests/php_cli_server_014.phpt | 6 | ||||
-rw-r--r-- | sapi/fpm/config.m4 | 4 | ||||
-rw-r--r-- | sapi/litespeed/lsapi_main.c | 1297 | ||||
-rw-r--r-- | sapi/litespeed/lsapilib.c | 47 | ||||
-rw-r--r-- | sapi/litespeed/lsapilib.h | 5 |
11 files changed, 610 insertions, 915 deletions
diff --git a/sapi/apache2handler/config.w32 b/sapi/apache2handler/config.w32 index 8d8a6c4b6..a7547514d 100644 --- a/sapi/apache2handler/config.w32 +++ b/sapi/apache2handler/config.w32 @@ -38,21 +38,21 @@ if (PHP_APACHE2_2HANDLER != "no") { } } -ARG_ENABLE('apache2-3handler', 'Build Apache 2.3.x handler', 'no'); -if (PHP_APACHE2_3HANDLER != "no") { +ARG_ENABLE('apache2-4handler', 'Build Apache 2.4.x handler', 'no'); +if (PHP_APACHE2_4HANDLER != "no") { if (PHP_ZTS == "no") { - WARNING("Apache 2.3 module requires an --enable-zts build of PHP on windows"); - } else if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE2_3HANDLER", PHP_PHP_BUILD + "\\include\\apache2_3") && - CHECK_LIB("libhttpd.lib", "apache2_3handler", PHP_PHP_BUILD + "\\lib\\apache2_3") && - CHECK_LIB("libapr-1.lib", "apache2_3handler", PHP_PHP_BUILD + "\\lib\\apache2_3") && - CHECK_LIB("libaprutil-1.lib", "apache2_3handler", PHP_PHP_BUILD + "\\lib\\apache2_3") + WARNING("Apache 2.4 module requires an --enable-zts build of PHP on windows"); + } else if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE2_4HANDLER", PHP_PHP_BUILD + "\\include\\apache2_4") && + CHECK_LIB("libhttpd.lib", "apache2_4handler", PHP_PHP_BUILD + "\\lib\\apache2_4") && + CHECK_LIB("libapr-1.lib", "apache2_4handler", PHP_PHP_BUILD + "\\lib\\apache2_4") && + CHECK_LIB("libaprutil-1.lib", "apache2_4handler", PHP_PHP_BUILD + "\\lib\\apache2_4") ) { - SAPI('apache2_3handler', 'mod_php5.c sapi_apache2.c apache_config.c php_functions.c', - 'php' + PHP_VERSION + 'apache2_3.dll', + SAPI('apache2_4handler', 'mod_php5.c sapi_apache2.c apache_config.c php_functions.c', + 'php' + PHP_VERSION + 'apache2_4.dll', '/D PHP_APACHE2_EXPORTS /I win32', 'sapi\\apache2handler'); } else { - WARNING("Could not find apache2.3 libraries/headers"); + WARNING("Could not find apache 2.4 libraries/headers"); } } diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 7856e0c58..ceba7174c 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -880,7 +880,6 @@ static int sapi_cgi_activate(TSRMLS_D) } else { doc_root = getenv("DOCUMENT_ROOT"); } - /* DOCUMENT_ROOT should also be defined at this stage..but better check it anyway */ if (doc_root) { doc_root_len = strlen(doc_root); diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 4d15db44a..d0d4cefb9 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -245,10 +245,10 @@ static php_cli_server_http_reponse_status_code_pair status_map[] = { }; static php_cli_server_http_reponse_status_code_pair template_map[] = { - { 400, "<h1 class=\"h\">%s</h1><p>Your browser sent a request that this server could not understand.</p>" }, - { 404, "<h1 class=\"h\">%s</h1><p>The requested resource %s was not found on this server.</p>" }, - { 500, "<h1 class=\"h\">%s</h1><p>The server is temporarily unavailable.</p>" }, - { 501, "<h1 class=\"h\">%s</h1><p>Request method not supported.</p>" } + { 400, "<h1>%s</h1><p>Your browser sent a request that this server could not understand.</p>" }, + { 404, "<h1>%s</h1><p>The requested resource %s was not found on this server.</p>" }, + { 500, "<h1>%s</h1><p>The server is temporarily unavailable.</p>" }, + { 501, "<h1>%s</h1><p>Request method not supported.</p>" } }; static php_cli_server_ext_mime_type_pair mime_type_map[] = { @@ -279,22 +279,10 @@ ZEND_DECLARE_MODULE_GLOBALS(cli_server); /* {{{ static char php_cli_server_css[] * copied from ext/standard/info.c */ -static const char php_cli_server_css[] = "<style type=\"text/css\">\n" \ - "body {background-color: #ffffff; color: #000000;}\n" \ - "body, td, th, h1, h2 {font-family: sans-serif;}\n" \ - ".center {text-align: center;}\n" \ - ".center table { margin-left: auto; margin-right: auto; text-align: left;}\n" \ - ".center th { text-align: center !important; }\n" \ - "h1 {font-size: 150%;}\n" \ - "h2 {font-size: 125%;}\n" \ - ".p {text-align: left;}\n" \ - ".e {background-color: #ccccff; font-weight: bold; color: #000000;}\n" \ - ".h {background-color: #9999cc; font-weight: bold; color: #000000;}\n" \ - ".v {background-color: #cccccc; color: #000000;}\n" \ - ".vr {background-color: #cccccc; text-align: right; color: #000000;}\n" \ - "img {float: right; border: 0px;}\n" \ - "hr {width: 600px; background-color: #cccccc; border: 0px; height: 1px; color: #000000;}\n" \ - "</style>\n"; +static const char php_cli_server_css[] = "<style>\n" \ + "body { background-color: #ffffff; color: #000000; }\n" \ + "h1 { font-family: sans-serif; font-size: 150%; background-color: #9999cc; font-weight: bold; color: #000000; margin-top: 0;}\n" \ + "</style>\n"; /* }}} */ static void char_ptr_dtor_p(char **p) /* {{{ */ @@ -1757,7 +1745,7 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server escaped_request_uri = php_escape_html_entities_ex((unsigned char *)client->request.request_uri, client->request.request_uri_len, &escaped_request_uri_len, 0, ENT_QUOTES, NULL, 0 TSRMLS_CC); { - static const char prologue_template[] = "<html><head><title>%d %s</title>"; + static const char prologue_template[] = "<!doctype html><html><head><title>%d %s</title>"; php_cli_server_chunk *chunk = php_cli_server_chunk_heap_new_self_contained(strlen(prologue_template) + 3 + strlen(status_string) + 1); if (!chunk) { goto fail; @@ -1949,40 +1937,38 @@ static int php_cli_server_request_shutdown(php_cli_server *server, php_cli_serve static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) /* {{{ */ { int decline = 0; - if (!php_handle_special_queries(TSRMLS_C)) { - zend_file_handle zfd; - char *old_cwd; - - ALLOCA_FLAG(use_heap) - old_cwd = do_alloca(MAXPATHLEN, use_heap); - old_cwd[0] = '\0'; - php_ignore_value(VCWD_GETCWD(old_cwd, MAXPATHLEN - 1)); - - zfd.type = ZEND_HANDLE_FILENAME; - zfd.filename = server->router; - zfd.handle.fp = NULL; - zfd.free_filename = 0; - zfd.opened_path = NULL; - - zend_try { - zval *retval = NULL; - if (SUCCESS == zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, &retval, 1, &zfd)) { - if (retval) { - decline = Z_TYPE_P(retval) == IS_BOOL && !Z_LVAL_P(retval); - zval_ptr_dtor(&retval); - } - } else { - decline = 1; + zend_file_handle zfd; + char *old_cwd; + + ALLOCA_FLAG(use_heap) + old_cwd = do_alloca(MAXPATHLEN, use_heap); + old_cwd[0] = '\0'; + php_ignore_value(VCWD_GETCWD(old_cwd, MAXPATHLEN - 1)); + + zfd.type = ZEND_HANDLE_FILENAME; + zfd.filename = server->router; + zfd.handle.fp = NULL; + zfd.free_filename = 0; + zfd.opened_path = NULL; + + zend_try { + zval *retval = NULL; + if (SUCCESS == zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, &retval, 1, &zfd)) { + if (retval) { + decline = Z_TYPE_P(retval) == IS_BOOL && !Z_LVAL_P(retval); + zval_ptr_dtor(&retval); } - } zend_end_try(); - - if (old_cwd[0] != '\0') { - php_ignore_value(VCWD_CHDIR(old_cwd)); + } else { + decline = 1; } + } zend_end_try(); - free_alloca(old_cwd, use_heap); + if (old_cwd[0] != '\0') { + php_ignore_value(VCWD_CHDIR(old_cwd)); } + free_alloca(old_cwd, use_heap); + return decline; } /* }}} */ diff --git a/sapi/cli/tests/003-2.phpt b/sapi/cli/tests/003-2.phpt index 2ed9b07db..2ed9b07db 100755..100644 --- a/sapi/cli/tests/003-2.phpt +++ b/sapi/cli/tests/003-2.phpt diff --git a/sapi/cli/tests/php_cli_server_011.phpt b/sapi/cli/tests/php_cli_server_011.phpt deleted file mode 100644 index a957a8ed4..000000000 --- a/sapi/cli/tests/php_cli_server_011.phpt +++ /dev/null @@ -1,41 +0,0 @@ ---TEST-- -Bug #60180 ($_SERVER["PHP_SELF"] incorrect) ---SKIPIF-- -<?php -include "skipif.inc"; -?> ---FILE-- -<?php -include "php_cli_server.inc"; -php_cli_server_start('sytanx error;', TRUE); - -list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); -$port = intval($port)?:80; - -$fp = fsockopen($host, $port, $errno, $errstr, 0.5); -if (!$fp) { - die("connect failed"); -} - -$logo_id = php_logo_guid(); - -if(fwrite($fp, <<<HEADER -GET /?={$logo_id} HTTP/1.1 -Host: {$host} - - -HEADER -)) { - while (!feof($fp)) { - if (("Content-Type: image/gif") == trim(fgets($fp))) { - echo "okey"; - break; - } - } -} - -fclose($fp); - -?> ---EXPECTF-- -okey diff --git a/sapi/cli/tests/php_cli_server_013.phpt b/sapi/cli/tests/php_cli_server_013.phpt index 18b7375b3..570798a88 100644 --- a/sapi/cli/tests/php_cli_server_013.phpt +++ b/sapi/cli/tests/php_cli_server_013.phpt @@ -33,7 +33,7 @@ HEADER } } -echo preg_replace("/<style type=\"text\/css\">(.*?)<\/style>/s", "<style type=\"text/css\">AAA</style>", $output), "\n"; +echo preg_replace("/<style>(.*?)<\/style>/s", "<style>AAA</style>", $output), "\n"; fclose($fp); @@ -55,7 +55,7 @@ HEADER } } -echo preg_replace("/<style type=\"text\/css\">(.*?)<\/style>/s", "<style type=\"text/css\">AAA</style>", $output), "\n"; +echo preg_replace("/<style>(.*?)<\/style>/s", "<style>AAA</style>", $output), "\n"; fclose($fp); $output = ''; @@ -76,7 +76,7 @@ HEADER } } -echo preg_replace("/<style type=\"text\/css\">(.*?)<\/style>/s", "<style type=\"text/css\">AAA</style>", $output), "\n"; +echo preg_replace("/<style>(.*?)<\/style>/s", "<style>AAA</style>", $output), "\n"; fclose($fp); ?> --EXPECTF-- @@ -87,22 +87,22 @@ Connection: close Content-Type: text/html; charset=UTF-8 Content-Length: %d -<html><head><title>404 Not Found</title><style type="text/css">AAA</style> -</head><body><h1 class="h">Not Found</h1><p>The requested resource / was not found on this server.</p></body></html> +<!doctype html><html><head><title>404 Not Found</title><style>AAA</style> +</head><body><h1>Not Found</h1><p>The requested resource / was not found on this server.</p></body></html> HTTP/1.1 404 Not Found Host: %s Connection: close Content-Type: text/html; charset=UTF-8 Content-Length: %d -<html><head><title>404 Not Found</title><style type="text/css">AAA</style> -</head><body><h1 class="h">Not Found</h1><p>The requested resource /main/style.css was not found on this server.</p></body></html> +<!doctype html><html><head><title>404 Not Found</title><style>AAA</style> +</head><body><h1>Not Found</h1><p>The requested resource /main/style.css was not found on this server.</p></body></html> HTTP/1.1 404 Not Found Host: %s Connection: close Content-Type: text/html; charset=UTF-8 Content-Length: %d -<html><head><title>404 Not Found</title><style type="text/css">AAA</style> -</head><body><h1 class="h">Not Found</h1><p>The requested resource /main/foo/bar was not found on this server.</p></body></html> +<!doctype html><html><head><title>404 Not Found</title><style>AAA</style> +</head><body><h1>Not Found</h1><p>The requested resource /main/foo/bar was not found on this server.</p></body></html> diff --git a/sapi/cli/tests/php_cli_server_014.phpt b/sapi/cli/tests/php_cli_server_014.phpt index 2eca8706b..f8a990561 100644 --- a/sapi/cli/tests/php_cli_server_014.phpt +++ b/sapi/cli/tests/php_cli_server_014.phpt @@ -57,7 +57,7 @@ HEADER } } -echo preg_replace("/<style type=\"text\/css\">(.*?)<\/style>/s", "<style type=\"text/css\">AAA</style>", $output), "\n"; +echo preg_replace("/<style>(.*?)<\/style>/s", "<style>AAA</style>", $output), "\n"; fclose($fp); ?> @@ -76,5 +76,5 @@ Connection: close Content-Type: %s Content-Length: %d -<html><head><title>404 Not Found</title><style type="text/css">AAA</style> -</head><body><h1 class="h">Not Found</h1><p>The requested resource /main/no-exists.php was not found on this server.</p></body></html> +<!doctype html><html><head><title>404 Not Found</title><style>AAA</style> +</head><body><h1>Not Found</h1><p>The requested resource /main/no-exists.php was not found on this server.</p></body></html> diff --git a/sapi/fpm/config.m4 b/sapi/fpm/config.m4 index 6191c329b..3a2690ee2 100644 --- a/sapi/fpm/config.m4 +++ b/sapi/fpm/config.m4 @@ -587,16 +587,12 @@ if test "$PHP_FPM" != "no"; then AC_DEFINE_UNQUOTED(PHP_FPM_USER, "$php_fpm_user", [fpm user name]) AC_DEFINE_UNQUOTED(PHP_FPM_GROUP, "$php_fpm_group", [fpm group name]) - AC_DEFINE_UNQUOTED(PHP_FPM_USER, "$php_fpm_user", [fpm user name]) - AC_DEFINE_UNQUOTED(PHP_FPM_GROUP, "$php_fpm_group", [fpm group name]) - PHP_ADD_BUILD_DIR(sapi/fpm/fpm) PHP_ADD_BUILD_DIR(sapi/fpm/fpm/events) PHP_OUTPUT(sapi/fpm/php-fpm.conf sapi/fpm/init.d.php-fpm sapi/fpm/php-fpm.service sapi/fpm/php-fpm.8 sapi/fpm/status.html) PHP_ADD_MAKEFILE_FRAGMENT([$abs_srcdir/sapi/fpm/Makefile.frag]) SAPI_FPM_PATH=sapi/fpm/php-fpm - if test "$fpm_trace_type" && test -f "$abs_srcdir/sapi/fpm/fpm/fpm_trace_$fpm_trace_type.c"; then PHP_FPM_TRACE_FILES="fpm/fpm_trace.c fpm/fpm_trace_$fpm_trace_type.c" diff --git a/sapi/litespeed/lsapi_main.c b/sapi/litespeed/lsapi_main.c index bb532d836..338b8e9d1 100644 --- a/sapi/litespeed/lsapi_main.c +++ b/sapi/litespeed/lsapi_main.c @@ -75,8 +75,7 @@ static int lsapi_mode = 1; static char *php_self = ""; static char *script_filename = ""; static int source_highlight = 0; -static char * argv0 = NULL; -static int engine = 1; + #ifdef ZTS zend_compiler_globals *compiler_globals; zend_executor_globals *executor_globals; @@ -91,65 +90,40 @@ zend_module_entry litespeed_module_entry; */ static int php_lsapi_startup(sapi_module_struct *sapi_module) { - if (php_module_startup(sapi_module, NULL, 0)==FAILURE) { - return FAILURE; - } - argv0 = sapi_module->executable_location; - return SUCCESS; + if (php_module_startup(sapi_module, NULL, 0)==FAILURE) { + return FAILURE; + } + return SUCCESS; } /* }}} */ -/* {{{ sapi_lsapi_ini_defaults */ - -/* overwriteable ini defaults must be set in sapi_cli_ini_defaults() */ -#define INI_DEFAULT(name,value)\ - ZVAL_STRING(tmp, value, 0);\ - zend_hash_update(configuration_hash, name, sizeof(name), tmp, sizeof(zval), (void**)&entry);\ - Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry)) - -static void sapi_lsapi_ini_defaults(HashTable *configuration_hash) -{ - zval *tmp, *entry; - -#if PHP_MAJOR_VERSION > 4 -/* - MAKE_STD_ZVAL(tmp); - - INI_DEFAULT("register_long_arrays", "0"); - - FREE_ZVAL(tmp); -*/ -#endif - -} -/* }}} */ /* {{{ sapi_lsapi_ub_write */ static int sapi_lsapi_ub_write(const char *str, uint str_length TSRMLS_DC) { - int ret; - int remain; - if ( lsapi_mode ) { - ret = LSAPI_Write( str, str_length ); - if ( ret < str_length ) { - php_handle_aborted_connection(); - return str_length - ret; - } - } else { - remain = str_length; - while( remain > 0 ) { - ret = write( 1, str, remain ); - if ( ret <= 0 ) { - php_handle_aborted_connection(); - return str_length - remain; - } - str += ret; - remain -= ret; - } - } - return str_length; + int ret; + int remain; + if ( lsapi_mode ) { + ret = LSAPI_Write( str, str_length ); + if ( ret < str_length ) { + php_handle_aborted_connection(); + return str_length - ret; + } + } else { + remain = str_length; + while( remain > 0 ) { + ret = write( 1, str, remain ); + if ( ret <= 0 ) { + php_handle_aborted_connection(); + return str_length - remain; + } + str += ret; + remain -= ret; + } + } + return str_length; } /* }}} */ @@ -158,11 +132,11 @@ static int sapi_lsapi_ub_write(const char *str, uint str_length TSRMLS_DC) */ static void sapi_lsapi_flush( void * server_context ) { - if ( lsapi_mode ) { - if ( LSAPI_Flush() == -1) { - php_handle_aborted_connection(); - } - } + if ( lsapi_mode ) { + if ( LSAPI_Flush() == -1) { + php_handle_aborted_connection(); + } + } } /* }}} */ @@ -171,12 +145,8 @@ static void sapi_lsapi_flush( void * server_context ) */ static int sapi_lsapi_deactivate(TSRMLS_D) { - if ( SG(request_info).path_translated ) - { - efree( SG(request_info).path_translated ); - } - - return SUCCESS; + LSAPI_Finish(); + return SUCCESS; } /* }}} */ @@ -187,99 +157,46 @@ static int sapi_lsapi_deactivate(TSRMLS_D) */ static char *sapi_lsapi_getenv( char * name, size_t name_len TSRMLS_DC ) { - if ( lsapi_mode ) { - return LSAPI_GetEnv( name ); - } else { - return getenv( name ); - } + if ( lsapi_mode ) { + return LSAPI_GetEnv( name ); + } else { + return getenv( name ); + } } /* }}} */ -/* -static int add_variable( const char * pKey, int keyLen, const char * pValue, int valLen, - void * arg ) -{ - php_register_variable_safe((char *)pKey, (char *)pValue, valLen, (zval *)arg TSRMLS_CC); - return 1; -} -*/ static int add_variable( const char * pKey, int keyLen, const char * pValue, int valLen, - void * arg ) + void * arg ) { - zval * gpc_element, **gpc_element_p; - HashTable * symtable1 = Z_ARRVAL_P((zval * )arg); - register char * pKey1 = (char *)pKey; - - MAKE_STD_ZVAL(gpc_element); - Z_STRLEN_P( gpc_element ) = valLen; - Z_STRVAL_P( gpc_element ) = estrndup(pValue, valLen); - Z_TYPE_P( gpc_element ) = IS_STRING; -#if PHP_MAJOR_VERSION > 4 - zend_symtable_update( symtable1, pKey1, keyLen + 1, &gpc_element, sizeof( zval *), (void **) &gpc_element_p ); -#else - zend_hash_update( symtable1, pKey1, keyLen + 1, &gpc_element, sizeof( zval *), (void **) &gpc_element_p ); -#endif - return 1; + php_register_variable_safe((char *)pKey, (char *)pValue, valLen, (zval *)arg TSRMLS_CC); + return 1; } -#if ((PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 4) || PHP_MAJOR_VERSION < 5) -static int add_variable_magic_quote( const char * pKey, int keyLen, const char * pValue, int valLen, - void * arg ) -{ - zval * gpc_element, **gpc_element_p; - HashTable * symtable1 = Z_ARRVAL_P((zval * )arg); - register char * pKey1 = (char *)pKey; - - MAKE_STD_ZVAL(gpc_element); - Z_STRLEN_P( gpc_element ) = valLen; - Z_STRVAL_P( gpc_element ) = php_addslashes((char *)pValue, valLen, &Z_STRLEN_P( gpc_element ), 0 ); - Z_TYPE_P( gpc_element ) = IS_STRING; -#if PHP_MAJOR_VERSION > 4 - zend_symtable_update( symtable1, pKey1, keyLen + 1, &gpc_element, sizeof( zval *), (void **) &gpc_element_p ); -#else - zend_hash_update( symtable1, pKey1, keyLen + 1, &gpc_element, sizeof( zval *), (void **) &gpc_element_p ); -#endif - return 1; -} - -#endif /* {{{ sapi_lsapi_register_variables */ static void sapi_lsapi_register_variables(zval *track_vars_array TSRMLS_DC) { - char * php_self = ""; - if ( lsapi_mode ) { - if ( (SG(request_info).request_uri ) ) - php_self = (SG(request_info).request_uri ); -#if ((PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 4) || PHP_MAJOR_VERSION < 5) - if (!PG(magic_quotes_gpc)) { -#endif - LSAPI_ForeachHeader( add_variable, track_vars_array ); - LSAPI_ForeachEnv( add_variable, track_vars_array ); - add_variable("PHP_SELF", 8, php_self, strlen( php_self ), track_vars_array ); -#if ((PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 4) || PHP_MAJOR_VERSION < 5) - } else { - LSAPI_ForeachHeader( add_variable_magic_quote, track_vars_array ); - LSAPI_ForeachEnv( add_variable_magic_quote, track_vars_array ); - add_variable_magic_quote("PHP_SELF", 8, php_self, strlen( php_self ), track_vars_array ); - } -#endif - php_import_environment_variables(track_vars_array TSRMLS_CC); - } else { - php_import_environment_variables(track_vars_array TSRMLS_CC); + if ( lsapi_mode ) { + LSAPI_ForeachHeader( add_variable, track_vars_array ); + LSAPI_ForeachEnv( add_variable, track_vars_array ); + php_import_environment_variables(track_vars_array TSRMLS_CC); - php_register_variable("PHP_SELF", php_self, track_vars_array TSRMLS_CC); - php_register_variable("SCRIPT_NAME", php_self, track_vars_array TSRMLS_CC); - php_register_variable("SCRIPT_FILENAME", script_filename, track_vars_array TSRMLS_CC); - php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array TSRMLS_CC); - php_register_variable("DOCUMENT_ROOT", "", 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); + } else { + php_import_environment_variables(track_vars_array TSRMLS_CC); - } + php_register_variable("PHP_SELF", php_self, track_vars_array TSRMLS_CC); + php_register_variable("SCRIPT_NAME", php_self, track_vars_array TSRMLS_CC); + php_register_variable("SCRIPT_FILENAME", script_filename, track_vars_array TSRMLS_CC); + php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array TSRMLS_CC); + php_register_variable("DOCUMENT_ROOT", "", track_vars_array TSRMLS_CC); + + } } /* }}} */ @@ -288,11 +205,11 @@ static void sapi_lsapi_register_variables(zval *track_vars_array TSRMLS_DC) */ static int sapi_lsapi_read_post(char *buffer, uint count_bytes TSRMLS_DC) { - if ( lsapi_mode ) { - return LSAPI_ReadReqBody( buffer, count_bytes ); - } else { - return 0; - } + if ( lsapi_mode ) { + return LSAPI_ReadReqBody( buffer, count_bytes ); + } else { + return 0; + } } /* }}} */ @@ -303,11 +220,11 @@ static int sapi_lsapi_read_post(char *buffer, uint count_bytes TSRMLS_DC) */ static char *sapi_lsapi_read_cookies(TSRMLS_D) { - if ( lsapi_mode ) { - return LSAPI_GetHeader( H_COOKIE ); - } else { - return NULL; - } + if ( lsapi_mode ) { + return LSAPI_GetHeader( H_COOKIE ); + } else { + return NULL; + } } /* }}} */ @@ -316,33 +233,33 @@ static char *sapi_lsapi_read_cookies(TSRMLS_D) */ static int sapi_lsapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) { - sapi_header_struct *h; - zend_llist_position pos; - if ( lsapi_mode ) { - LSAPI_SetRespStatus( SG(sapi_headers).http_response_code ); - - h = zend_llist_get_first_ex(&sapi_headers->headers, &pos); - while (h) { - if ( h->header_len > 0 ) { - LSAPI_AppendRespHeader(h->header, h->header_len); - } - h = zend_llist_get_next_ex(&sapi_headers->headers, &pos); - } - if (SG(sapi_headers).send_default_content_type) { - char *hd; - int len; - char headerBuf[SAPI_LSAPI_MAX_HEADER_LENGTH]; - - hd = sapi_get_default_content_type(TSRMLS_C); - len = snprintf( headerBuf, SAPI_LSAPI_MAX_HEADER_LENGTH - 1, - "Content-type: %s", hd ); - efree(hd); - - LSAPI_AppendRespHeader( headerBuf, len ); - } - } - LSAPI_FinalizeRespHeaders(); - return SAPI_HEADER_SENT_SUCCESSFULLY; + sapi_header_struct *h; + zend_llist_position pos; + if ( lsapi_mode ) { + LSAPI_SetRespStatus( SG(sapi_headers).http_response_code ); + + h = zend_llist_get_first_ex(&sapi_headers->headers, &pos); + while (h) { + if ( h->header_len > 0 ) { + LSAPI_AppendRespHeader(h->header, h->header_len); + } + h = zend_llist_get_next_ex(&sapi_headers->headers, &pos); + } + if (SG(sapi_headers).send_default_content_type) { + char *hd; + int len; + char headerBuf[SAPI_LSAPI_MAX_HEADER_LENGTH]; + + hd = sapi_get_default_content_type(TSRMLS_C); + len = snprintf( headerBuf, SAPI_LSAPI_MAX_HEADER_LENGTH - 1, + "Content-type: %s", hd ); + efree(hd); + + LSAPI_AppendRespHeader( headerBuf, len ); + } + } + LSAPI_FinalizeRespHeaders(); + return SAPI_HEADER_SENT_SUCCESSFULLY; } @@ -353,8 +270,8 @@ static int sapi_lsapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) */ static void sapi_lsapi_log_message(char *message TSRMLS_DC) { - int len = strlen( message ); - LSAPI_Write_Stderr( message, len); + int len = strlen( message ); + LSAPI_Write_Stderr( message, len); } /* }}} */ @@ -363,247 +280,158 @@ static void sapi_lsapi_log_message(char *message TSRMLS_DC) */ static sapi_module_struct lsapi_sapi_module = { - "litespeed", - "LiteSpeed V5.5", + "litespeed", + "LiteSpeed", - php_lsapi_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ + php_lsapi_startup, /* startup */ + php_module_shutdown_wrapper, /* shutdown */ - NULL, /* activate */ - sapi_lsapi_deactivate, /* deactivate */ + NULL, /* activate */ + sapi_lsapi_deactivate, /* deactivate */ - sapi_lsapi_ub_write, /* unbuffered write */ - sapi_lsapi_flush, /* flush */ - NULL, /* get uid */ - sapi_lsapi_getenv, /* getenv */ + sapi_lsapi_ub_write, /* unbuffered write */ + sapi_lsapi_flush, /* flush */ + NULL, /* get uid */ + sapi_lsapi_getenv, /* getenv */ - php_error, /* error handler */ + php_error, /* error handler */ - NULL, /* header handler */ - sapi_lsapi_send_headers, /* send headers handler */ - NULL, /* send header handler */ + NULL, /* header handler */ + sapi_lsapi_send_headers, /* send headers handler */ + NULL, /* send header handler */ - sapi_lsapi_read_post, /* read POST data */ - sapi_lsapi_read_cookies, /* read Cookies */ + sapi_lsapi_read_post, /* read POST data */ + sapi_lsapi_read_cookies, /* read Cookies */ - sapi_lsapi_register_variables, /* register server variables */ - sapi_lsapi_log_message, /* Log message */ + sapi_lsapi_register_variables, /* register server variables */ + sapi_lsapi_log_message, /* Log message */ - NULL, /* php.ini path override */ - NULL, /* block interruptions */ - NULL, /* unblock interruptions */ - NULL, /* default post reader */ - NULL, /* treat data */ - NULL, /* executable location */ + NULL, /* php.ini path override */ + NULL, /* block interruptions */ + NULL, /* unblock interruptions */ + NULL, /* default post reader */ + NULL, /* treat data */ + NULL, /* executable location */ - 0, /* php.ini ignore */ + 0, /* php.ini ignore */ - STANDARD_SAPI_MODULE_PROPERTIES + STANDARD_SAPI_MODULE_PROPERTIES }; /* }}} */ static int init_request_info( TSRMLS_D ) { - char * pContentType = LSAPI_GetHeader( H_CONTENT_TYPE ); - char * pAuth; - - SG(request_info).content_type = pContentType ? pContentType : ""; - SG(request_info).request_method = LSAPI_GetRequestMethod(); - SG(request_info).query_string = LSAPI_GetQueryString(); - SG(request_info).request_uri = LSAPI_GetScriptName(); - SG(request_info).content_length = LSAPI_GetReqBodyLen(); - SG(request_info).path_translated = estrdup( LSAPI_GetScriptFileName()); - - /* It is not reset by zend engine, set it to 0. */ - SG(sapi_headers).http_response_code = 0; - - pAuth = LSAPI_GetHeader( H_AUTHORIZATION ); - php_handle_auth_data(pAuth TSRMLS_CC); -} - -static char s_cur_chdir[4096] = ""; + char * pContentType = LSAPI_GetHeader( H_CONTENT_TYPE ); + char * pAuth; + + SG(request_info).content_type = pContentType ? pContentType : ""; + SG(request_info).request_method = LSAPI_GetRequestMethod(); + SG(request_info).query_string = LSAPI_GetQueryString(); + SG(request_info).request_uri = LSAPI_GetScriptName(); + SG(request_info).content_length = LSAPI_GetReqBodyLen(); + SG(request_info).path_translated = LSAPI_GetScriptFileName(); -static int lsapi_chdir_primary_script( zend_file_handle * file_handle ) -{ -#if PHP_MAJOR_VERSION > 4 - char * p; - char ch; - - SG(options) |= SAPI_OPTION_NO_CHDIR; - getcwd( s_cur_chdir, sizeof( s_cur_chdir ) ); - - p = strrchr( file_handle->filename, '/' ); - if ( *p ) - { - *p = 0; - if ( strcmp( file_handle->filename, s_cur_chdir ) != 0 ) { - chdir( file_handle->filename ); - } - *p++ = '/'; - ch = *p; - *p = 0; - if ( !CWDG(cwd).cwd || - ( strcmp( file_handle->filename, CWDG(cwd).cwd ) != 0 ) ) { - CWDG(cwd).cwd_length = p - file_handle->filename; - CWDG(cwd).cwd = (char *) realloc(CWDG(cwd).cwd, CWDG(cwd).cwd_length+1); - memmove( CWDG(cwd).cwd, file_handle->filename, CWDG(cwd).cwd_length+1 ); - } - *p = ch; - } - /* virtual_file_ex(&CWDG(cwd), file_handle->filename, NULL, CWD_REALPATH); */ -#else - VCWD_CHDIR_FILE( file_handle->filename ); -#endif - return 0; -} - -static int lsapi_fopen_primary_script( zend_file_handle * file_handle ) -{ - FILE * fp; - char * p; - fp = fopen( SG(request_info).path_translated, "rb" ); - if ( !fp ) - { - return -1; - } - file_handle->type = ZEND_HANDLE_FP; - file_handle->handle.fp = fp; - file_handle->filename = SG(request_info).path_translated; - file_handle->free_filename = 0; - file_handle->opened_path = NULL; - - lsapi_chdir_primary_script( file_handle ); - - return 0; + /* It is not reset by zend engine, set it to 0. */ + SG(sapi_headers).http_response_code = 0; + + pAuth = LSAPI_GetHeader( H_AUTHORIZATION ); + php_handle_auth_data(pAuth TSRMLS_CC); } -static int lsapi_execute_script( zend_file_handle * file_handle TSRMLS_DC) +static int lsapi_module_main(int show_source TSRMLS_DC) { - char *p; - int len; - file_handle->type = ZEND_HANDLE_FILENAME; - file_handle->handle.fd = 0; - file_handle->filename = SG(request_info).path_translated; - file_handle->free_filename = 0; - file_handle->opened_path = NULL; - - p = argv0; - *p++ = ':'; - len = strlen( SG(request_info).path_translated ); - if ( len > 45 ) - len = len - 45; - else - len = 0; - memccpy( p, SG(request_info).path_translated + len, 0, 46 ); - - php_execute_script(file_handle TSRMLS_CC); - return 0; + zend_file_handle file_handle = {0}; -} + if (php_request_startup(TSRMLS_C) == FAILURE ) { + return -1; + } + if (show_source) { + zend_syntax_highlighter_ini syntax_highlighter_ini; + php_get_highlight_struct(&syntax_highlighter_ini); + highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini TSRMLS_CC); + } else { + file_handle.type = ZEND_HANDLE_FILENAME; + file_handle.handle.fd = 0; + file_handle.filename = SG(request_info).path_translated; + file_handle.free_filename = 0; + file_handle.opened_path = NULL; -static int lsapi_module_main(int show_source TSRMLS_DC) -{ - zend_file_handle file_handle = {0}; - - if (php_request_startup(TSRMLS_C) == FAILURE ) { - return -1; - } - if (show_source) { - zend_syntax_highlighter_ini syntax_highlighter_ini; - - php_get_highlight_struct(&syntax_highlighter_ini); - highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini TSRMLS_CC); - } else { - lsapi_execute_script( &file_handle TSRMLS_CC); - } - zend_try { - php_request_shutdown(NULL); - *argv0 = 0; - } zend_end_try(); - return 0; + php_execute_script(&file_handle TSRMLS_CC); + } + zend_try { + php_request_shutdown(NULL); + } zend_end_try(); + return 0; } static int alter_ini( const char * pKey, int keyLen, const char * pValue, int valLen, - void * arg ) + void * arg ) { - int type = ZEND_INI_PERDIR; - if ( '\001' == *pKey ) { - ++pKey; - if ( *pKey == 4 ) { - type = ZEND_INI_SYSTEM; - } - ++pKey; - --keyLen; - if (( keyLen == 7 )&&( strncasecmp( pKey, "engine", 6 )== 0 )) - { - if ( *pValue == '0' ) - engine = 0; - } - else - zend_alter_ini_entry((char *)pKey, keyLen, - (char *)pValue, valLen, - type, PHP_INI_STAGE_ACTIVATE); - } - return 1; + int type = ZEND_INI_PERDIR; + if ( '\001' == *pKey ) { + ++pKey; + if ( *pKey == 4 ) { + type = ZEND_INI_SYSTEM; + } + ++pKey; + --keyLen; + zend_alter_ini_entry((char *)pKey, keyLen, + (char *)pValue, valLen, + type, PHP_INI_STAGE_ACTIVATE); + } + return 1; } static void override_ini() { - LSAPI_ForeachSpecialEnv( alter_ini, NULL ); + LSAPI_ForeachSpecialEnv( alter_ini, NULL ); } static int processReq( TSRMLS_D ) { - int ret = 0; - zend_first_try { - /* avoid server_context==NULL checks */ - SG(server_context) = (void *) 1; - - engine = 1; - override_ini(); - - if ( engine ) { - init_request_info( TSRMLS_C ); - - if ( lsapi_module_main( source_highlight TSRMLS_CC ) == -1 ) { - ret = -1; - } - } else { - LSAPI_AppendRespHeader( "status: 403", 11 ); - LSAPI_AppendRespHeader( "content-type: text/html", 23 ); - LSAPI_Write( "Forbidden: PHP engine is disable.\n", 34 ); - } - } zend_end_try(); - return ret; + int ret = 0; + zend_first_try { + /* avoid server_context==NULL checks */ + SG(server_context) = (void *) 1; + + init_request_info( TSRMLS_C ); + + override_ini(); + + if ( lsapi_module_main( source_highlight TSRMLS_CC ) == -1 ) { + ret = -1; + } + } zend_end_try(); + return ret; } static void cli_usage( TSRMLS_D ) { - static const char * usage = - "Usage: php\n" - " php -[b|c|h|i|q|s|v|?] [<file>] [args...]\n" - " Run in LSAPI mode, only '-b', '-s' and '-c' are effective\n" - " Run in Command Line Interpreter mode when parameters are specified\n" - "\n" - " -b <address:port>|<port> Bind Path for external LSAPI Server mode\n" - " -c <path>|<file> Look for php.ini file in this directory\n" - " -h This help\n" - " -i PHP information\n" - " -q Quiet-mode. Suppress HTTP Header output.\n" - " -s Display colour syntax highlighted source.\n" - " -v Version number\n" - " -? This help\n" - "\n" - " args... Arguments passed to script.\n"; - php_output_startup(); - php_output_activate(TSRMLS_C); - php_printf( usage ); + static const char * usage = + "Usage: php\n" + " php -[b|c|h|i|q|s|v|?] [<file>] [args...]\n" + " Run in LSAPI mode, only '-b', '-s' and '-c' are effective\n" + " Run in Command Line Interpreter mode when parameters are specified\n" + "\n" + " -b <address:port>|<port> Bind Path for external LSAPI Server mode\n" + " -c <path>|<file> Look for php.ini file in this directory\n" + " -h This help\n" + " -i PHP information\n" + " -q Quiet-mode. Suppress HTTP Header output.\n" + " -s Display colour syntax highlighted source.\n" + " -v Version number\n" + " -? This help\n" + "\n" + " args... Arguments passed to script.\n"; + php_output_startup(); + php_output_activate(TSRMLS_C); + php_printf( "%s", usage ); #ifdef PHP_OUTPUT_NEWAPI php_output_end_all(TSRMLS_C); #else @@ -612,250 +440,250 @@ static void cli_usage( TSRMLS_D ) } static int parse_opt( int argc, char * argv[], int *climode, - char **php_ini_path, char ** php_bind ) -{ - char ** p = &argv[1]; - char ** argend= &argv[argc]; - int c; - while (( p < argend )&&(**p == '-' )) { - c = *((*p)+1); - ++p; - switch( c ) { - case 'b': - if ( p >= argend ) { - fprintf( stderr, "TCP or socket address must be specified following '-b' option.\n"); - return -1; - } - *php_bind = *p++; - break; - - case 'c': - if ( p >= argend ) { - fprintf( stderr, "<path> or <file> must be specified following '-c' option.\n"); - - return -1; - } - *php_ini_path = *p++; - break; - case 's': - source_highlight = 1; - break; - case 'h': - case 'i': - case 'q': - case 'v': - case '?': - default: - *climode = 1; - break; - } - } - if ( p - argv < argc ) { - *climode = 1; - } - return 0; + char **php_ini_path, char ** php_bind ) +{ + char ** p = &argv[1]; + char ** argend= &argv[argc]; + int c; + while (( p < argend )&&(**p == '-' )) { + c = *((*p)+1); + ++p; + switch( c ) { + case 'b': + if ( p >= argend ) { + fprintf( stderr, "TCP or socket address must be specified following '-b' option.\n"); + return -1; + } + *php_bind = *p++; + break; + + case 'c': + if ( p >= argend ) { + fprintf( stderr, "<path> or <file> must be specified following '-c' option.\n"); + + return -1; + } + *php_ini_path = *p++; + break; + case 's': + source_highlight = 1; + break; + case 'h': + case 'i': + case 'q': + case 'v': + case '?': + default: + *climode = 1; + break; + } + } + if ( p - argv < argc ) { + *climode = 1; + } + return 0; } static int cli_main( int argc, char * argv[] ) { - static const char * ini_defaults[] = { - "report_zend_debug", "0", - "display_errors", "1", - "register_argc_argv", "1", - "html_errors", "0", - "implicit_flush", "1", - "output_buffering", "0", - "max_execution_time", "0", - "max_input_time", "-1", - NULL - }; - - const char ** ini; - char ** p = &argv[1]; - char ** argend= &argv[argc]; - int ret = 0; - int c; - lsapi_mode = 0; /* enter CLI mode */ + static const char * ini_defaults[] = { + "report_zend_debug", "0", + "display_errors", "1", + "register_argc_argv", "1", + "html_errors", "0", + "implicit_flush", "1", + "output_buffering", "0", + "max_execution_time", "0", + "max_input_time", "-1", + NULL + }; + + const char ** ini; + char ** p = &argv[1]; + char ** argend= &argv[argc]; + int ret = 0; + int c; + lsapi_mode = 0; /* enter CLI mode */ #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 - zend_first_try { - SG(server_context) = (void *) 1; - - zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */ - CG(in_compilation) = 0; /* not initialized but needed for several options */ - EG(uninitialized_zval_ptr) = NULL; - - for( ini = ini_defaults; *ini; ini+=2 ) { - zend_alter_ini_entry( (char *)*ini, strlen( *ini )+1, - (char *)*(ini+1), strlen( *(ini+1) ), - PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); - } - - while (( p < argend )&&(**p == '-' )) { - c = *((*p)+1); - ++p; - switch( c ) { - case 'q': - break; - case 'i': - if (php_request_startup(TSRMLS_C) != FAILURE) { - php_print_info(0xFFFFFFFF TSRMLS_CC); + zend_first_try { + SG(server_context) = (void *) 1; + + zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */ + CG(in_compilation) = 0; /* not initialized but needed for several options */ + EG(uninitialized_zval_ptr) = NULL; + + for( ini = ini_defaults; *ini; ini+=2 ) { + zend_alter_ini_entry( (char *)*ini, strlen( *ini )+1, + (char *)*(ini+1), strlen( *(ini+1) ), + PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); + } + + while (( p < argend )&&(**p == '-' )) { + c = *((*p)+1); + ++p; + switch( c ) { + case 'q': + break; + case 'i': + if (php_request_startup(TSRMLS_C) != FAILURE) { + php_print_info(0xFFFFFFFF TSRMLS_CC); #ifdef PHP_OUTPUT_NEWAPI php_output_end_all(TSRMLS_C); #else php_end_ob_buffers(1 TSRMLS_CC); #endif - php_request_shutdown( NULL ); - } - ret = 1; - break; - case 'v': - if (php_request_startup(TSRMLS_C) != FAILURE) { + php_request_shutdown( NULL ); + } + ret = 1; + break; + case 'v': + if (php_request_startup(TSRMLS_C) != FAILURE) { #if ZEND_DEBUG - php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2012 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-2012 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-2012 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-2012 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); #endif #ifdef PHP_OUTPUT_NEWAPI php_output_end_all(TSRMLS_C); #else php_end_ob_buffers(1 TSRMLS_CC); #endif - php_request_shutdown( NULL ); - } - ret = 1; - break; - case 'c': - ++p; - /* fall through */ - case 's': - break; - - case 'h': - case '?': - default: - cli_usage(TSRMLS_C); - ret = 1; - break; - - } - } - if ( !ret ) { - if ( *p ) { - zend_file_handle file_handle = {0}; - - file_handle.type = ZEND_HANDLE_FP; - file_handle.handle.fp = VCWD_FOPEN(*p, "rb"); - - if ( file_handle.handle.fp ) { - script_filename = *p; - php_self = *p; - - SG(request_info).path_translated = estrdup(*p); - SG(request_info).argc = argc - (p - argv); - SG(request_info).argv = p; - - if (php_request_startup(TSRMLS_C) == FAILURE ) { - fclose( file_handle.handle.fp ); - ret = 2; - } else { - if (source_highlight) { - zend_syntax_highlighter_ini syntax_highlighter_ini; - - php_get_highlight_struct(&syntax_highlighter_ini); - highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini TSRMLS_CC); - } else { - file_handle.filename = *p; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - - php_execute_script(&file_handle TSRMLS_CC); - } - - php_request_shutdown( NULL ); - } - } else { - php_printf("Could not open input file: %s.\n", *p); - } - } else { - cli_usage(TSRMLS_C); - } - } - - }zend_end_try(); - - php_module_shutdown(TSRMLS_C); + php_request_shutdown( NULL ); + } + ret = 1; + break; + case 'c': + ++p; + /* fall through */ + case 's': + break; + + case 'h': + case '?': + default: + cli_usage(TSRMLS_C); + ret = 1; + break; + + } + } + if ( !ret ) { + if ( *p ) { + zend_file_handle file_handle = {0}; + + file_handle.type = ZEND_HANDLE_FP; + file_handle.handle.fp = VCWD_FOPEN(*p, "rb"); + + if ( file_handle.handle.fp ) { + script_filename = *p; + php_self = *p; + + SG(request_info).path_translated = *p; + SG(request_info).argc = argc - (p - argv); + SG(request_info).argv = p; + + if (php_request_startup(TSRMLS_C) == FAILURE ) { + fclose( file_handle.handle.fp ); + ret = 2; + } else { + if (source_highlight) { + zend_syntax_highlighter_ini syntax_highlighter_ini; + + php_get_highlight_struct(&syntax_highlighter_ini); + highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini TSRMLS_CC); + } else { + file_handle.filename = *p; + file_handle.free_filename = 0; + file_handle.opened_path = NULL; + + php_execute_script(&file_handle TSRMLS_CC); + } + + php_request_shutdown( NULL ); + } + } else { + php_printf("Could not open input file: %s.\n", *p); + } + } else { + cli_usage(TSRMLS_C); + } + } + + }zend_end_try(); + + php_module_shutdown(TSRMLS_C); #ifdef ZTS - tsrm_shutdown(); + tsrm_shutdown(); #endif - return ret; + return ret; } static int s_stop; void litespeed_cleanup(int signal) { - s_stop = signal; + s_stop = signal; } void start_children( int children ) { - struct sigaction act, old_term, old_quit, old_int, old_usr1; - int running = 0; - int status; - pid_t pid; - - /* Create a process group */ - setsid(); - - /* Set up handler to kill children upon exit */ - act.sa_flags = 0; - act.sa_handler = litespeed_cleanup; - if( sigaction( SIGTERM, &act, &old_term ) || - sigaction( SIGINT, &act, &old_int ) || - sigaction( SIGUSR1, &act, &old_usr1 ) || - sigaction( SIGQUIT, &act, &old_quit )) { - perror( "Can't set signals" ); - exit( 1 ); - } - s_stop = 0; - while( 1 ) { - while((!s_stop )&&( running < children )) { - pid = fork(); - switch( pid ) { - case 0: /* children process */ - - /* don't catch our signals */ - sigaction( SIGTERM, &old_term, 0 ); - sigaction( SIGQUIT, &old_quit, 0 ); - sigaction( SIGINT, &old_int, 0 ); - sigaction( SIGUSR1, &old_usr1, 0 ); - return ; - case -1: - perror( "php (pre-forking)" ); - exit( 1 ); - break; - default: /* parent process */ - running++; - break; - } - } - if ( s_stop ) { - break; - } - pid = wait( &status ); - running--; - } - kill( -getpgrp(), SIGUSR1 ); - exit( 0 ); + struct sigaction act, old_term, old_quit, old_int, old_usr1; + int running = 0; + int status; + pid_t pid; + + /* Create a process group */ + setsid(); + + /* Set up handler to kill children upon exit */ + act.sa_flags = 0; + act.sa_handler = litespeed_cleanup; + if( sigaction( SIGTERM, &act, &old_term ) || + sigaction( SIGINT, &act, &old_int ) || + sigaction( SIGUSR1, &act, &old_usr1 ) || + sigaction( SIGQUIT, &act, &old_quit )) { + perror( "Can't set signals" ); + exit( 1 ); + } + s_stop = 0; + while( 1 ) { + while((!s_stop )&&( running < children )) { + pid = fork(); + switch( pid ) { + case 0: /* children process */ + + /* don't catch our signals */ + sigaction( SIGTERM, &old_term, 0 ); + sigaction( SIGQUIT, &old_quit, 0 ); + sigaction( SIGINT, &old_int, 0 ); + sigaction( SIGUSR1, &old_usr1, 0 ); + return ; + case -1: + perror( "php (pre-forking)" ); + exit( 1 ); + break; + default: /* parent process */ + running++; + break; + } + } + if ( s_stop ) { + break; + } + pid = wait( &status ); + running--; + } + kill( -getpgrp(), SIGUSR1 ); + exit( 0 ); } @@ -863,185 +691,153 @@ void start_children( int children ) #include <fcntl.h> int main( int argc, char * argv[] ) { - int ret; - int bindFd; - - char * php_ini_path = NULL; - char * php_bind = NULL; - char * p; - int n; - int climode = 0; - struct timeval tv_req_begin; - struct timeval tv_req_end; - int slow_script_msec = 0; - char time_buf[40]; - + int ret; + int bindFd; + + char * php_ini_path = NULL; + char * php_bind = NULL; + char * p; + int n; + int climode = 0; + #ifdef HAVE_SIGNAL_H #if defined(SIGPIPE) && defined(SIG_IGN) - signal(SIGPIPE, SIG_IGN); + signal(SIGPIPE, SIG_IGN); #endif #endif #ifdef ZTS - tsrm_startup(1, 1, 0, NULL); + tsrm_startup(1, 1, 0, NULL); #endif - if (argc > 1 ) { - if ( parse_opt( argc, argv, &climode, - &php_ini_path, &php_bind ) == -1 ) { - return 1; - } - } - if ( climode ) { - lsapi_sapi_module.phpinfo_as_text = 1; - } - argv0 = argv[0] + strlen( argv[0] ); - sapi_startup(&lsapi_sapi_module); + if (argc > 1 ) { + if ( parse_opt( argc, argv, &climode, + &php_ini_path, &php_bind ) == -1 ) { + return 1; + } + } + if ( climode ) { + lsapi_sapi_module.phpinfo_as_text = 1; + } + sapi_startup(&lsapi_sapi_module); #ifdef ZTS - compiler_globals = ts_resource(compiler_globals_id); - executor_globals = ts_resource(executor_globals_id); - core_globals = ts_resource(core_globals_id); - sapi_globals = ts_resource(sapi_globals_id); - tsrm_ls = ts_resource(0); + compiler_globals = ts_resource(compiler_globals_id); + executor_globals = ts_resource(executor_globals_id); + core_globals = ts_resource(core_globals_id); + sapi_globals = ts_resource(sapi_globals_id); + tsrm_ls = ts_resource(0); - SG(request_info).path_translated = NULL; + SG(request_info).path_translated = NULL; #endif - lsapi_sapi_module.executable_location = argv[0]; - - if ( php_ini_path ) { - lsapi_sapi_module.php_ini_path_override = php_ini_path; - } + lsapi_sapi_module.executable_location = argv[0]; + if ( php_ini_path ) { + lsapi_sapi_module.php_ini_path_override = php_ini_path; + } - lsapi_sapi_module.ini_defaults = sapi_lsapi_ini_defaults; - - if (php_module_startup(&lsapi_sapi_module, &litespeed_module_entry, 1) == FAILURE) { + if (php_module_startup(&lsapi_sapi_module, &litespeed_module_entry, 1) == FAILURE) { #ifdef ZTS - tsrm_shutdown(); + tsrm_shutdown(); #endif - return FAILURE; - } - - if ( climode ) { - return cli_main(argc, argv); - } - - if ( php_bind ) { - bindFd = LSAPI_CreateListenSock( php_bind, 10 ); - if ( bindFd == -1 ) { - fprintf( stderr, - "Failed to bind socket [%s]: %s\n", php_bind, strerror( errno ) ); - exit( 2 ); - } - if ( bindFd != 0 ) { - dup2( bindFd, 0 ); - close( bindFd ); - } - } - - LSAPI_Init(); + return FAILURE; + } + + if ( climode ) { + return cli_main(argc, argv); + } + + + if ( php_bind ) { + bindFd = LSAPI_CreateListenSock( php_bind, 10 ); + if ( bindFd == -1 ) { + fprintf( stderr, + "Failed to bind socket [%s]: %s\n", php_bind, strerror( errno ) ); + exit( 2 ); + } + if ( bindFd != 0 ) { + dup2( bindFd, 0 ); + close( bindFd ); + } + } + + LSAPI_Init(); - LSAPI_Init_Env_Parameters( NULL ); - - slow_script_msec = LSAPI_Get_Slow_Req_Msecs(); - - if ( php_bind ) { - LSAPI_No_Check_ppid(); - } - - while( LSAPI_Prefork_Accept_r( &g_req ) >= 0 ) { - if ( slow_script_msec ) { - gettimeofday( &tv_req_begin, NULL ); - } - ret = processReq(TSRMLS_C); - if ( slow_script_msec ) { - gettimeofday( &tv_req_end, NULL ); - n = ((long) tv_req_end.tv_sec - tv_req_begin.tv_sec ) * 1000 - + (tv_req_end.tv_usec - tv_req_begin.tv_usec) / 1000; - if ( n > slow_script_msec ) - { - strftime( time_buf, 30, "%d/%b/%Y:%H:%M:%S", localtime( &tv_req_end.tv_sec ) ); - fprintf( stderr, "[%s] Slow PHP script: %d ms\n URL: %s %s\n Query String: %s\n Script: %s\n", - time_buf, n, LSAPI_GetRequestMethod(), - LSAPI_GetScriptName(), LSAPI_GetQueryString(), - LSAPI_GetScriptFileName() ); - - } - } - LSAPI_Finish(); - if ( ret ) { - break; - } - } - php_module_shutdown(TSRMLS_C); + LSAPI_Init_Env_Parameters( NULL ); + + if ( php_bind ) { + LSAPI_No_Check_ppid(); + } + + while( LSAPI_Prefork_Accept_r( &g_req ) >= 0 ) { + ret = processReq(TSRMLS_C); + LSAPI_Finish(); + if ( ret ) { + break; + } + } + php_module_shutdown(TSRMLS_C); #ifdef ZTS - tsrm_shutdown(); + tsrm_shutdown(); #endif - return ret; + return ret; } /* LiteSpeed PHP module starts here */ -#if PHP_MAJOR_VERSION > 4 - /* {{{ arginfo */ ZEND_BEGIN_ARG_INFO(arginfo_litespeed__void, 0) ZEND_END_ARG_INFO() /* }}} */ -#else -#define arginfo_litespeed__void NULL -#endif - PHP_FUNCTION(litespeed_request_headers); PHP_FUNCTION(litespeed_response_headers); PHP_MINFO_FUNCTION(litespeed); zend_function_entry litespeed_functions[] = { - PHP_FE(litespeed_request_headers, arginfo_litespeed__void) - PHP_FE(litespeed_response_headers, arginfo_litespeed__void) - PHP_FALIAS(getallheaders, litespeed_request_headers, arginfo_litespeed__void) - PHP_FALIAS(apache_request_headers, litespeed_request_headers, arginfo_litespeed__void) - PHP_FALIAS(apache_response_headers, litespeed_response_headers, arginfo_litespeed__void) - {NULL, NULL, NULL} + PHP_FE(litespeed_request_headers, arginfo_litespeed__void) + PHP_FE(litespeed_response_headers, arginfo_litespeed__void) + PHP_FALIAS(getallheaders, litespeed_request_headers, arginfo_litespeed__void) + PHP_FALIAS(apache_request_headers, litespeed_request_headers, arginfo_litespeed__void) + PHP_FALIAS(apache_response_headers, litespeed_response_headers, arginfo_litespeed__void) + {NULL, NULL, NULL} }; static PHP_MINIT_FUNCTION(litespeed) { - /* REGISTER_INI_ENTRIES(); */ - return SUCCESS; + /* REGISTER_INI_ENTRIES(); */ + return SUCCESS; } static PHP_MSHUTDOWN_FUNCTION(litespeed) { - /* UNREGISTER_INI_ENTRIES(); */ - return SUCCESS; + /* UNREGISTER_INI_ENTRIES(); */ + return SUCCESS; } zend_module_entry litespeed_module_entry = { - STANDARD_MODULE_HEADER, - "litespeed", - litespeed_functions, - PHP_MINIT(litespeed), - PHP_MSHUTDOWN(litespeed), - NULL, - NULL, - NULL, - NO_VERSION_YET, - STANDARD_MODULE_PROPERTIES + STANDARD_MODULE_HEADER, + "litespeed", + litespeed_functions, + PHP_MINIT(litespeed), + PHP_MSHUTDOWN(litespeed), + NULL, + NULL, + NULL, + NO_VERSION_YET, + STANDARD_MODULE_PROPERTIES }; static int add_associate_array( const char * pKey, int keyLen, const char * pValue, int valLen, - void * arg ) + void * arg ) { - add_assoc_string_ex( (zval *)arg, (char *)pKey, keyLen+1, (char *)pValue, 1 ); - return 1; + add_assoc_string_ex( (zval *)arg, (char *)pKey, keyLen+1, (char *)pValue, 1 ); + return 1; } @@ -1049,14 +845,13 @@ static int add_associate_array( const char * pKey, int keyLen, const char * pVal Fetch all HTTP request headers */ PHP_FUNCTION(litespeed_request_headers) { - /* TODO: */ - if (ZEND_NUM_ARGS() > 0) { - WRONG_PARAM_COUNT; - } - array_init(return_value); + /* TODO: */ + if (ZEND_NUM_ARGS() > 0) { + WRONG_PARAM_COUNT; + } + array_init(return_value); - if ( lsapi_mode ) - LSAPI_ForeachOrgHeader( add_associate_array, return_value ); + LSAPI_ForeachOrgHeader( add_associate_array, return_value ); } /* }}} */ @@ -1067,40 +862,40 @@ PHP_FUNCTION(litespeed_request_headers) Fetch all HTTP response headers */ PHP_FUNCTION(litespeed_response_headers) { - sapi_header_struct *h; - zend_llist_position pos; - char * p; - int len; - char headerBuf[SAPI_LSAPI_MAX_HEADER_LENGTH]; - - if (ZEND_NUM_ARGS() > 0) { - WRONG_PARAM_COUNT; - } - - if (!&SG(sapi_headers).headers) { - RETURN_FALSE; - } - array_init(return_value); - - h = zend_llist_get_first_ex(&SG(sapi_headers).headers, &pos); - while (h) { - if ( h->header_len > 0 ) { - p = strchr( h->header, ':' ); - len = p - h->header; - if (( p )&&( len > 0 )) { - memmove( headerBuf, h->header, len ); - while( len > 0 && (isspace( headerBuf[len-1])) ) { - --len; - } - headerBuf[len] = 0; - if ( len ) { - while( isspace(*++p)); - add_assoc_string_ex(return_value, headerBuf, len+1, p, 1 ); - } - } - } - h = zend_llist_get_next_ex(&SG(sapi_headers).headers, &pos); - } + sapi_header_struct *h; + zend_llist_position pos; + char * p; + int len; + char headerBuf[SAPI_LSAPI_MAX_HEADER_LENGTH]; + + if (ZEND_NUM_ARGS() > 0) { + WRONG_PARAM_COUNT; + } + + if (!&SG(sapi_headers).headers) { + RETURN_FALSE; + } + array_init(return_value); + + h = zend_llist_get_first_ex(&SG(sapi_headers).headers, &pos); + while (h) { + if ( h->header_len > 0 ) { + p = strchr( h->header, ':' ); + len = p - h->header; + if (( p )&&( len > 0 )) { + memmove( headerBuf, h->header, len ); + while( len > 0 && (isspace( headerBuf[len-1])) ) { + --len; + } + headerBuf[len] = 0; + if ( len ) { + while( isspace(*++p)); + add_assoc_string_ex(return_value, headerBuf, len+1, p, 1 ); + } + } + } + h = zend_llist_get_next_ex(&SG(sapi_headers).headers, &pos); + } } /* }}} */ diff --git a/sapi/litespeed/lsapilib.c b/sapi/litespeed/lsapilib.c index fe89ebab2..4beea56b3 100644 --- a/sapi/litespeed/lsapilib.c +++ b/sapi/litespeed/lsapilib.c @@ -86,7 +86,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. static int g_inited = 0; static int g_running = 1; static int s_ppid; -static int s_slow_req_msecs = 0; LSAPI_Request g_req = { -1, -1 }; void Flush_RespBuf_r( LSAPI_Request * pReq ); @@ -508,13 +507,11 @@ static int parseRequest( LSAPI_Request * pReq, int totalLen ) return 0; } -static int s_accept_notify = 0; - static struct lsapi_packet_header ack = {'L', 'S', LSAPI_REQ_RECEIVED, LSAPI_ENDIAN, {LSAPI_PACKET_HEADER_LEN} }; -static inline int notify_req_received( int fd ) +static inline int notify_req_received( LSAPI_Request * pReq ) { - if ( write( fd, &ack, LSAPI_PACKET_HEADER_LEN ) + if ( write( pReq->m_fd, &ack, LSAPI_PACKET_HEADER_LEN ) < LSAPI_PACKET_HEADER_LEN ) { return -1; } @@ -570,10 +567,7 @@ static int readReq( LSAPI_Request * pReq ) pReq->m_bufProcessed = packetLen; pReq->m_reqState = LSAPI_ST_REQ_BODY | LSAPI_ST_RESP_HEADER; - if ( !s_accept_notify ) - return notify_req_received( pReq->m_fd ); - else - return 0; + return notify_req_received( pReq ); } @@ -683,10 +677,6 @@ int LSAPI_Accept_r( LSAPI_Request * pReq ) setsockopt(pReq->m_fd, IPPROTO_TCP, TCP_NODELAY, (char *)&nodelay, sizeof(nodelay)); } - - if ( s_accept_notify ) - return notify_req_received( pReq->m_fd ); - } } else { return -1; @@ -1249,13 +1239,12 @@ int LSAPI_ForeachHeader_r( LSAPI_Request * pReq, while( pCur < pEnd ) { pKey = pReq->m_pHttpHeader + pCur->nameOff; keyLen = pCur->nameLen; - if ( keyLen > 250 ) { - keyLen = 250; - } - pKeyEnd = pKey + keyLen; memcpy( achHeaderName, "HTTP_", 5 ); p = &achHeaderName[5]; + if ( keyLen > 250 ) { + keyLen = 250; + } while( pKey < pKeyEnd ) { char ch = *pKey++; @@ -1640,9 +1629,6 @@ static int lsapi_accept( int fdListen ) setsockopt( fd, IPPROTO_TCP, TCP_NODELAY, (char *)&nodelay, sizeof(nodelay)); } - - if ( s_accept_notify ) - notify_req_received( fd ); } return fd; @@ -2087,15 +2073,6 @@ void LSAPI_Set_Server_Max_Idle_Secs( int serverMaxIdle ) } } -void LSAPI_Set_Slow_Req_Msecs( int msecs ) -{ - s_slow_req_msecs = msecs; -} - -int LSAPI_Get_Slow_Req_Msecs() -{ - return s_slow_req_msecs; -} void LSAPI_No_Check_ppid() { @@ -2149,18 +2126,6 @@ void LSAPI_Init_Env_Parameters( fn_select_t fp ) avoidFork = atoi( p ); } - p = getenv( "LSAPI_ACCEPT_NOTIFY" ); - if ( p ) { - s_accept_notify = atoi( p ); - } - - p = getenv( "LSAPI_SLOW_REQ_MSECS" ); - if ( p ) { - n = atoi( p ); - LSAPI_Set_Slow_Req_Msecs( n ); - } - - #if defined( RLIMIT_CORE ) p = getenv( "LSAPI_ALLOW_CORE_DUMP" ); if ( !p ) { diff --git a/sapi/litespeed/lsapilib.h b/sapi/litespeed/lsapilib.h index 701b5284c..9772ea199 100644 --- a/sapi/litespeed/lsapilib.h +++ b/sapi/litespeed/lsapilib.h @@ -343,11 +343,6 @@ void LSAPI_Set_Max_Process_Time( int secs ); void LSAPI_Init_Env_Parameters( fn_select_t fp ); -void LSAPI_Set_Slow_Req_Msecs( int msecs ); - -int LSAPI_Get_Slow_Req_Msecs( ); - - #if defined (c_plusplus) || defined (__cplusplus) } #endif |