summaryrefslogtreecommitdiff
path: root/sapi
diff options
context:
space:
mode:
authorMark A. Hershberger <mah@debian.(none)>2009-03-25 19:39:21 -0400
committerMark A. Hershberger <mah@debian.(none)>2009-03-25 19:39:21 -0400
commit6821b67124604da690c5e9276d5370d679c63ac8 (patch)
treebefb4ca2520eb577950cef6cb76d10b914cbf67a /sapi
parentcd0b49c72aee33b3e44a9c589fcd93b9e1c7a64f (diff)
downloadphp-6821b67124604da690c5e9276d5370d679c63ac8.tar.gz
Imported Upstream version 5.3.0RC1upstream/5.3.0_RC1upstream/5.3.0RC1
Diffstat (limited to 'sapi')
-rw-r--r--sapi/aolserver/aolserver.c14
-rw-r--r--sapi/apache/config.w326
-rw-r--r--sapi/apache/libpre.c2
-rw-r--r--sapi/apache/mod_php5.c88
-rw-r--r--sapi/apache/mod_php5.h8
-rw-r--r--sapi/apache/php_apache.c260
-rw-r--r--sapi/apache/php_apache_http.h4
-rw-r--r--sapi/apache/sapi_apache.c2
-rw-r--r--sapi/apache2filter/apache_config.c2
-rw-r--r--sapi/apache2filter/config.m46
-rwxr-xr-xsapi/apache2filter/config.w3210
-rw-r--r--sapi/apache2filter/php_apache.h12
-rw-r--r--sapi/apache2filter/php_functions.c161
-rw-r--r--sapi/apache2filter/sapi_apache2.c99
-rw-r--r--sapi/apache2handler/apache_config.c4
-rw-r--r--sapi/apache2handler/config.m46
-rw-r--r--sapi/apache2handler/config.w3210
-rw-r--r--sapi/apache2handler/mod_php5.c2
-rw-r--r--sapi/apache2handler/php_apache.h7
-rw-r--r--sapi/apache2handler/php_functions.c177
-rw-r--r--sapi/apache2handler/sapi_apache2.c64
-rw-r--r--sapi/apache_hooks/config.w326
-rw-r--r--sapi/apache_hooks/mod_php5.c72
-rw-r--r--sapi/apache_hooks/mod_php5.h9
-rw-r--r--sapi/apache_hooks/php_apache.c533
-rw-r--r--sapi/apache_hooks/php_apache_http.h2
-rw-r--r--sapi/apache_hooks/sapi_apache.c2
-rw-r--r--sapi/caudium/caudium.c14
-rwxr-xr-xsapi/cgi/CHANGES34
-rw-r--r--sapi/cgi/cgi_main.c1132
-rw-r--r--sapi/cgi/config.w3222
-rw-r--r--sapi/cgi/config9.m490
-rw-r--r--sapi/cgi/fastcgi.c168
-rw-r--r--sapi/cgi/fastcgi.h9
-rw-r--r--sapi/cgi/getopt.c164
-rw-r--r--sapi/cgi/php_getopt.h39
-rw-r--r--sapi/cgi/tests/006.phpt2
-rw-r--r--sapi/cgi/tests/007.phpt4
-rw-r--r--sapi/cgi/tests/011.phpt165
-rw-r--r--sapi/cli/config.m42
-rw-r--r--sapi/cli/config.w326
-rw-r--r--sapi/cli/getopt.c175
-rw-r--r--sapi/cli/php_cli.c102
-rw-r--r--sapi/cli/php_cli_readline.c4
-rw-r--r--sapi/cli/php_cli_readline.h2
-rw-r--r--sapi/cli/php_getopt.h39
-rw-r--r--sapi/cli/tests/002-win32.phpt2
-rw-r--r--sapi/cli/tests/005.phpt39
-rw-r--r--sapi/cli/tests/006.phpt330
-rw-r--r--sapi/cli/tests/010.phpt23
-rw-r--r--sapi/cli/tests/016.phpt108
-rw-r--r--sapi/cli/tests/017.phpt106
-rw-r--r--sapi/cli/tests/018.phpt27
-rw-r--r--sapi/cli/tests/019.phpt36
-rw-r--r--sapi/cli/tests/020.phpt32
-rw-r--r--sapi/cli/tests/021.phpt4
-rw-r--r--sapi/continuity/capi.c7
-rw-r--r--sapi/embed/php_embed.c17
-rw-r--r--sapi/embed/php_embed.h2
-rw-r--r--sapi/isapi/config.w3210
-rw-r--r--sapi/isapi/php5isapi.c3
-rw-r--r--sapi/litespeed/CREDITS2
-rw-r--r--sapi/litespeed/Makefile.frag3
-rw-r--r--sapi/litespeed/README225
-rw-r--r--sapi/litespeed/config.m431
-rw-r--r--sapi/litespeed/lsapi_main.c909
-rw-r--r--sapi/litespeed/lsapidef.h196
-rw-r--r--sapi/litespeed/lsapilib.c2192
-rw-r--r--sapi/litespeed/lsapilib.h358
-rw-r--r--sapi/milter/php_milter.c67
-rw-r--r--sapi/nsapi/config.w323
-rw-r--r--sapi/nsapi/nsapi.c140
-rw-r--r--sapi/phttpd/phttpd.c1
-rw-r--r--sapi/pi3web/pi3web_sapi.c5
-rw-r--r--sapi/pi3web/pi3web_sapi.h6
-rw-r--r--sapi/roxen/roxen.c5
-rw-r--r--sapi/tests/test003.phpt6
-rw-r--r--sapi/tests/test004.phpt6
-rw-r--r--sapi/thttpd/thttpd.c3
-rw-r--r--sapi/tux/php_tux.c1
-rw-r--r--sapi/webjames/webjames.c1
81 files changed, 6407 insertions, 2240 deletions
diff --git a/sapi/aolserver/aolserver.c b/sapi/aolserver/aolserver.c
index 92b4da851..5584ef745 100644
--- a/sapi/aolserver/aolserver.c
+++ b/sapi/aolserver/aolserver.c
@@ -22,7 +22,7 @@
* - CGI/1.1 conformance
*/
-/* $Id: aolserver.c,v 1.81.2.2.2.3 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: aolserver.c,v 1.81.2.2.2.1.2.8 2008/12/31 11:15:48 sebastian Exp $ */
/* conflict between PHP and AOLserver headers */
#define Debug php_Debug
@@ -205,7 +205,7 @@ static void php_info_aolserver(ZEND_MODULE_INFO_FUNC_ARGS)
int i;
php_info_print_table_start();
- php_info_print_table_row(2, "SAPI module version", "$Id: aolserver.c,v 1.81.2.2.2.3 2008/12/31 11:17:48 sebastian Exp $");
+ php_info_print_table_row(2, "SAPI module version", "$Id: aolserver.c,v 1.81.2.2.2.1.2.8 2008/12/31 11:15:48 sebastian Exp $");
php_info_print_table_row(2, "Build date", Ns_InfoBuildDate());
php_info_print_table_row(2, "Config file path", Ns_InfoConfigFile());
php_info_print_table_row(2, "Error Log path", Ns_InfoErrorLog());
@@ -240,8 +240,13 @@ static void php_info_aolserver(ZEND_MODULE_INFO_FUNC_ARGS)
PHP_FUNCTION(getallheaders);
-static zend_function_entry aolserver_functions[] = {
- PHP_FE(getallheaders, NULL)
+/* {{{ arginfo */
+ZEND_BEGIN_ARG_INFO(arginfo_aolserver_getallheaders, 0)
+ZEND_END_ARG_INFO()
+/* }}} */
+
+const static zend_function_entry aolserver_functions[] = {
+ PHP_FE(getallheaders, arginfo_aolserver_getallheaders)
{NULL, NULL, NULL}
};
@@ -386,6 +391,7 @@ static sapi_module_struct aolserver_sapi_module = {
php_ns_sapi_register_variables,
NULL, /* Log message */
NULL, /* Get request time */
+ NULL, /* child terminate */
STANDARD_SAPI_MODULE_PROPERTIES
};
diff --git a/sapi/apache/config.w32 b/sapi/apache/config.w32
index d3ba676ea..36ae1411c 100644
--- a/sapi/apache/config.w32
+++ b/sapi/apache/config.w32
@@ -1,5 +1,5 @@
// vim:ft=javascript
-// $Id: config.w32,v 1.7 2004/01/17 13:00:04 sniper Exp $
+// $Id: config.w32,v 1.7.8.1 2008/04/15 16:55:53 auroraeosrose Exp $
ARG_ENABLE('apache', 'Build Apache 1.3.x version of PHP', 'no');
@@ -9,10 +9,10 @@ ARG_WITH('apache-libs', 'Where to find Apache 1.3 libraries', null);
if (PHP_APACHE != "no") {
if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE", php_usual_include_suspects +
";" + PROGRAM_FILES + "\\Apache Group\\Apache\\include" +
- ";..\\php_build\\apache\\src\\include") &&
+ ";" + PHP_PHP_BUILD + "\\apache\\src\\include") &&
CHECK_LIB("ApacheCore.lib", "apache", php_usual_lib_suspects +
';' + PROGRAM_FILES + '\\Apache Group\\Apache\\libexec' +
- ';..\\php_build\\apache\\src\\corer')) {
+ ";" + PHP_PHP_BUILD + "\\apache\\src\\corer")) {
// We need to play tricks to get our readdir.h used by apache
// headers
SAPI('apache', 'mod_php5.c sapi_apache.c php_apache.c',
diff --git a/sapi/apache/libpre.c b/sapi/apache/libpre.c
index e375424e0..48eebf7e0 100644
--- a/sapi/apache/libpre.c
+++ b/sapi/apache/libpre.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: libpre.c,v 1.6.2.1.2.3 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: libpre.c,v 1.6.2.1.2.1.2.2 2008/12/31 11:15:48 sebastian Exp $ */
#ifdef NETWARE
diff --git a/sapi/apache/mod_php5.c b/sapi/apache/mod_php5.c
index 325c295f0..9bb98ceba 100644
--- a/sapi/apache/mod_php5.c
+++ b/sapi/apache/mod_php5.c
@@ -17,7 +17,7 @@
| PHP 4.0 patches by Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
-/* $Id: mod_php5.c,v 1.19.2.7.2.17 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: mod_php5.c,v 1.19.2.7.2.13.2.11 2008/12/31 11:15:48 sebastian Exp $ */
#include "php_apache_http.h"
#include "http_conf_globals.h"
@@ -26,10 +26,6 @@
#define SIGPIPE SIGINT
#endif
-#if defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING)
-#include "ext/mbstring/mbstring.h"
-#endif /* defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING) */
-
#undef shutdown
/* {{{ Prototypes
@@ -39,7 +35,7 @@ static void php_save_umask(void);
static void php_restore_umask(void);
static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC);
static char *sapi_apache_read_cookies(TSRMLS_D);
-static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC);
+static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC);
static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC);
static int send_php(request_rec *r, int display_source_mode, char *filename);
static int send_parsed_php(request_rec * r);
@@ -167,41 +163,54 @@ static char *sapi_apache_read_cookies(TSRMLS_D)
/* {{{ sapi_apache_header_handler
*/
-static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC)
+static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC)
{
char *header_name, *header_content, *p;
request_rec *r = (request_rec *) SG(server_context);
if(!r) {
- efree(sapi_header->header);
return 0;
}
- header_name = sapi_header->header;
+ switch(op) {
+ case SAPI_HEADER_DELETE_ALL:
+ clear_table(r->headers_out);
+ return 0;
- header_content = p = strchr(header_name, ':');
- if (!p) {
- efree(sapi_header->header);
- return 0;
- }
+ case SAPI_HEADER_DELETE:
+ table_unset(r->headers_out, sapi_header->header);
+ return 0;
- *p = 0;
- do {
- header_content++;
- } while (*header_content==' ');
-
- if (!strcasecmp(header_name, "Content-Type")) {
- r->content_type = pstrdup(r->pool, header_content);
- } else if (!strcasecmp(header_name, "Set-Cookie")) {
- table_add(r->headers_out, header_name, header_content);
- } else if (sapi_header->replace) {
- table_set(r->headers_out, header_name, header_content);
- } else {
- table_add(r->headers_out, header_name, header_content);
- }
+ case SAPI_HEADER_ADD:
+ case SAPI_HEADER_REPLACE:
+ header_name = sapi_header->header;
+
+ header_content = p = strchr(header_name, ':');
+ if (!p) {
+ return 0;
+ }
+
+ *p = 0;
+ do {
+ header_content++;
+ } while (*header_content==' ');
+
+ if (!strcasecmp(header_name, "Content-Type")) {
+ r->content_type = pstrdup(r->pool, header_content);
+ } else if (!strcasecmp(header_name, "Set-Cookie")) {
+ table_add(r->headers_out, header_name, header_content);
+ } else if (op == SAPI_HEADER_REPLACE) {
+ table_set(r->headers_out, header_name, header_content);
+ } else {
+ table_add(r->headers_out, header_name, header_content);
+ }
- *p = ':'; /* a well behaved header handler shouldn't change its original arguments */
+ *p = ':'; /* a well behaved header handler shouldn't change its original arguments */
- return SAPI_HEADER_ADD;
+ return SAPI_HEADER_ADD;
+
+ default:
+ return 0;
+ }
}
/* }}} */
@@ -247,7 +256,7 @@ static void sapi_apache_register_server_variables(zval *track_vars_array TSRMLS_
table_entry *elts = (table_entry *) arr->elts;
zval **path_translated;
HashTable *symbol_table;
- int new_val_len;
+ unsigned int new_val_len;
for (i = 0; i < arr->nelts; i++) {
char *val;
@@ -438,6 +447,16 @@ static time_t php_apache_get_request_time(TSRMLS_D)
}
/* }}} */
+/* {{{ sapi_apache_child_terminate
+ */
+static void sapi_apache_child_terminate(TSRMLS_D)
+{
+#ifndef MULTITHREAD
+ ap_child_terminate((request_rec *)SG(server_context));
+#endif
+}
+/* }}} */
+
/* {{{ sapi_module_struct apache_sapi_module
*/
static sapi_module_struct apache_sapi_module = {
@@ -467,6 +486,7 @@ static sapi_module_struct apache_sapi_module = {
sapi_apache_register_server_variables, /* register server variables */
php_apache_log_message, /* Log message */
php_apache_get_request_time, /* Get request time */
+ sapi_apache_child_terminate,
NULL, /* php.ini path override */
@@ -589,10 +609,6 @@ static int send_php(request_rec *r, int display_source_mode, char *filename)
fh.free_filename = 0;
fh.type = ZEND_HANDLE_FILENAME;
-#if defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING)
- php_mb_set_zend_encoding(TSRMLS_C);
-#endif /* defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING) */
-
zend_execute_scripts(ZEND_INCLUDE TSRMLS_CC, NULL, 1, &fh);
return OK;
}
@@ -680,7 +696,7 @@ static int send_parsed_php(request_rec * r)
TSRMLS_FETCH();
ap_table_setn(r->notes, "mod_php_memory_usage",
- ap_psprintf(r->pool, "%u", zend_memory_peak_usage(1 TSRMLS_CC)));
+ ap_psprintf(r->pool, "%lu", zend_memory_peak_usage(1 TSRMLS_CC)));
return result;
}
diff --git a/sapi/apache/mod_php5.h b/sapi/apache/mod_php5.h
index fecdbf948..c5a4d1b10 100644
--- a/sapi/apache/mod_php5.h
+++ b/sapi/apache/mod_php5.h
@@ -15,7 +15,7 @@
| Author: Rasmus Lerdorf <rasmus@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: mod_php5.h,v 1.4.2.1.2.3 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: mod_php5.h,v 1.4.2.1.2.1.2.3 2008/12/31 11:15:48 sebastian Exp $ */
#ifndef MOD_PHP5_H
#define MOD_PHP5_H
@@ -44,6 +44,12 @@ extern php_apache_info_struct php_apache_info;
#define AP(v) (php_apache_info.v)
#endif
+/* fix for gcc4 visibility patch */
+#ifndef PHP_WIN32
+# undef MODULE_VAR_EXPORT
+# define MODULE_VAR_EXPORT PHPAPI
+#endif
+
#endif /* MOD_PHP5_H */
/*
diff --git a/sapi/apache/php_apache.c b/sapi/apache/php_apache.c
index 5941615e8..44d969a89 100644
--- a/sapi/apache/php_apache.c
+++ b/sapi/apache/php_apache.c
@@ -17,7 +17,7 @@
| David Sklar <sklar@student.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: php_apache.c,v 1.89.2.4.2.8 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: php_apache.c,v 1.89.2.4.2.6.2.10 2009/01/05 16:24:26 iliaa Exp $ */
#include "php_apache_http.h"
@@ -56,18 +56,57 @@ PHP_FUNCTION(apache_reset_timeout);
PHP_MINFO_FUNCTION(apache);
-zend_function_entry apache_functions[] = {
- PHP_FE(virtual, NULL)
- PHP_FE(apache_request_headers, NULL)
- PHP_FE(apache_note, NULL)
- PHP_FE(apache_lookup_uri, NULL)
- PHP_FE(apache_child_terminate, NULL)
- PHP_FE(apache_setenv, NULL)
- PHP_FE(apache_response_headers, NULL)
- PHP_FE(apache_get_version, NULL)
- PHP_FE(apache_get_modules, NULL)
- PHP_FE(apache_reset_timeout, NULL)
- PHP_FALIAS(getallheaders, apache_request_headers, NULL)
+ZEND_BEGIN_ARG_INFO(arginfo_apache_child_terminate, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apache_note, 0, 0, 1)
+ ZEND_ARG_INFO(0, note_name)
+ ZEND_ARG_INFO(0, note_value)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apache_virtual, 0, 0, 1)
+ ZEND_ARG_INFO(0, filename)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_apache_request_headers, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_apache_response_headers, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apache_setenv, 0, 0, 2)
+ ZEND_ARG_INFO(0, variable)
+ ZEND_ARG_INFO(0, value)
+ ZEND_ARG_INFO(0, walk_to_top)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apache_lookup_uri, 0, 0, 1)
+ ZEND_ARG_INFO(0, uri)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_apache_get_version, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_apache_get_modules, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_apache_reset_timeout, 0)
+ZEND_END_ARG_INFO()
+
+
+
+const zend_function_entry apache_functions[] = {
+ PHP_FE(virtual, arginfo_apache_virtual)
+ PHP_FE(apache_request_headers, arginfo_apache_request_headers)
+ PHP_FE(apache_note, arginfo_apache_note)
+ PHP_FE(apache_lookup_uri, arginfo_apache_lookup_uri)
+ PHP_FE(apache_child_terminate, arginfo_apache_child_terminate)
+ PHP_FE(apache_setenv, arginfo_apache_setenv)
+ PHP_FE(apache_response_headers, arginfo_apache_response_headers)
+ PHP_FE(apache_get_version, arginfo_apache_get_version)
+ PHP_FE(apache_get_modules, arginfo_apache_get_modules)
+ PHP_FE(apache_reset_timeout, arginfo_apache_reset_timeout)
+ PHP_FALIAS(getallheaders, apache_request_headers, arginfo_apache_request_headers)
{NULL, NULL, NULL}
};
@@ -118,54 +157,6 @@ zend_module_entry apache_module_entry = {
STANDARD_MODULE_PROPERTIES
};
-/* {{{ proto bool apache_child_terminate(void)
- Terminate apache process after this request */
-PHP_FUNCTION(apache_child_terminate)
-{
-#ifndef MULTITHREAD
- if (AP(terminate_child)) {
- ap_child_terminate( ((request_rec *)SG(server_context)) );
- RETURN_TRUE;
- } else { /* tell them to get lost! */
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function is disabled");
- RETURN_FALSE;
- }
-#else
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function is not supported in this build");
- RETURN_FALSE;
-#endif
-}
-/* }}} */
-
-/* {{{ proto string apache_note(string note_name [, string note_value])
- Get and set Apache request notes */
-PHP_FUNCTION(apache_note)
-{
- zval **arg_name, **arg_val;
- char *note_val;
- int arg_count = ZEND_NUM_ARGS();
-
- if (arg_count<1 || arg_count>2 ||
- zend_get_parameters_ex(arg_count, &arg_name, &arg_val) ==FAILURE ) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(arg_name);
- note_val = (char *) table_get(((request_rec *)SG(server_context))->notes, (*arg_name)->value.str.val);
-
- if (arg_count == 2) {
- convert_to_string_ex(arg_val);
- table_set(((request_rec *)SG(server_context))->notes, (*arg_name)->value.str.val, (*arg_val)->value.str.val);
- }
-
- if (note_val) {
- RETURN_STRING(note_val, 1);
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(apache)
@@ -298,6 +289,51 @@ PHP_MINFO_FUNCTION(apache)
}
/* }}} */
+/* {{{ proto bool apache_child_terminate(void)
+ Terminate apache process after this request */
+PHP_FUNCTION(apache_child_terminate)
+{
+#ifndef MULTITHREAD
+ if (AP(terminate_child)) {
+ ap_child_terminate( ((request_rec *)SG(server_context)) );
+ RETURN_TRUE;
+ } else { /* tell them to get lost! */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function is disabled");
+ RETURN_FALSE;
+ }
+#else
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function is not supported in this build");
+ RETURN_FALSE;
+#endif
+}
+/* }}} */
+
+/* {{{ proto string apache_note(string note_name [, string note_value])
+ Get and set Apache request notes */
+PHP_FUNCTION(apache_note)
+{
+ char *note_name, *note_val = NULL;
+ int note_name_len, note_val_len;
+ char *old_val;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &note_name, &note_name_len, &note_val, &note_val_len) == FAILURE) {
+ return;
+ }
+
+ old_val = (char *) table_get(((request_rec *)SG(server_context))->notes, note_name);
+
+ if (note_val) {
+ table_set(((request_rec *)SG(server_context))->notes, note_name, note_val);
+ }
+
+ if (old_val) {
+ RETURN_STRING(old_val, 1);
+ }
+
+ RETURN_FALSE;
+}
+/* }}} */
+
/* {{{ proto bool virtual(string filename)
Perform an Apache sub-request */
/* This function is equivalent to <!--#include virtual...-->
@@ -310,23 +346,25 @@ PHP_MINFO_FUNCTION(apache)
*/
PHP_FUNCTION(virtual)
{
- zval **filename;
+ char *filename;
+ int filename_len;
request_rec *rr = NULL;
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ return;
}
- convert_to_string_ex(filename);
- if (!(rr = sub_req_lookup_uri ((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", (*filename)->value.str.val);
- if (rr) destroy_sub_req (rr);
+ if (!(rr = sub_req_lookup_uri (filename, ((request_rec *) SG(server_context))))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", filename);
+ if (rr)
+ destroy_sub_req (rr);
RETURN_FALSE;
}
if (rr->status != 200) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", (*filename)->value.str.val);
- if (rr) destroy_sub_req (rr);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", filename);
+ if (rr)
+ destroy_sub_req (rr);
RETURN_FALSE;
}
@@ -334,31 +372,35 @@ PHP_FUNCTION(virtual)
php_header(TSRMLS_C);
if (run_sub_req(rr)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", (*filename)->value.str.val);
- if (rr) destroy_sub_req (rr);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", filename);
+ if (rr)
+ destroy_sub_req (rr);
RETURN_FALSE;
- } else {
- if (rr) destroy_sub_req (rr);
- RETURN_TRUE;
}
+
+ if (rr)
+ destroy_sub_req (rr);
+
+ RETURN_TRUE;
}
/* }}} */
/* {{{ proto array getallheaders(void)
Alias for apache_request_headers() */
/* }}} */
+
/* {{{ proto array apache_request_headers(void)
Fetch all HTTP request headers */
PHP_FUNCTION(apache_request_headers)
{
- array_header *env_arr;
- table_entry *tenv;
- int i;
-
- array_init(return_value);
- env_arr = table_elts(((request_rec *) SG(server_context))->headers_in);
- tenv = (table_entry *)env_arr->elts;
- for (i = 0; i < env_arr->nelts; ++i) {
+ array_header *env_arr;
+ table_entry *tenv;
+ int i;
+
+ array_init(return_value);
+ env_arr = table_elts(((request_rec *) SG(server_context))->headers_in);
+ tenv = (table_entry *)env_arr->elts;
+ for (i = 0; i < env_arr->nelts; ++i) {
if (!tenv[i].key ||
(PG(safe_mode) &&
!strncasecmp(tenv[i].key, "authorization", 13))) {
@@ -375,14 +417,14 @@ PHP_FUNCTION(apache_request_headers)
Fetch all HTTP response headers */
PHP_FUNCTION(apache_response_headers)
{
- array_header *env_arr;
- table_entry *tenv;
- int i;
-
- array_init(return_value);
- env_arr = table_elts(((request_rec *) SG(server_context))->headers_out);
- tenv = (table_entry *)env_arr->elts;
- for (i = 0; i < env_arr->nelts; ++i) {
+ array_header *env_arr;
+ table_entry *tenv;
+ int i;
+
+ array_init(return_value);
+ env_arr = table_elts(((request_rec *) SG(server_context))->headers_out);
+ tenv = (table_entry *)env_arr->elts;
+ for (i = 0; i < env_arr->nelts; ++i) {
if (!tenv[i].key) continue;
if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) {
RETURN_FALSE;
@@ -400,8 +442,8 @@ PHP_FUNCTION(apache_setenv)
char *var = NULL, *val = NULL;
request_rec *r = (request_rec *) SG(server_context);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) {
- RETURN_FALSE;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) {
+ return;
}
while(top) {
@@ -418,20 +460,22 @@ PHP_FUNCTION(apache_setenv)
Perform a partial request of the given URI to obtain information about it */
PHP_FUNCTION(apache_lookup_uri)
{
- zval **filename;
+ char *filename;
+ int filename_len;
request_rec *rr=NULL;
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ return;
}
- convert_to_string_ex(filename);
- if(!(rr = sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed '%s'", (*filename)->value.str.val);
+ if (!(rr = sub_req_lookup_uri(filename, ((request_rec *) SG(server_context))))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed '%s'", filename);
RETURN_FALSE;
}
+
object_init(return_value);
add_property_long(return_value,"status", rr->status);
+
if (rr->the_request) {
add_property_string(return_value,"the_request", rr->the_request, 1);
}
@@ -462,6 +506,7 @@ PHP_FUNCTION(apache_lookup_uri)
if (rr->boundary) {
add_property_string(return_value,"boundary", rr->boundary, 1);
}
+
add_property_long(return_value,"no_cache", rr->no_cache);
add_property_long(return_value,"no_local_copy", rr->no_local_copy);
add_property_long(return_value,"allowed", rr->allowed);
@@ -492,19 +537,20 @@ This function is most likely a bad idea. Just playing with it for now.
PHP_FUNCTION(apache_exec_uri)
{
- zval **filename;
+ char *filename;
+ int filename_len;
request_rec *rr=NULL;
TSRMLS_FETCH();
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ return;
}
- convert_to_string_ex(filename);
- if(!(rr = ap_sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed", (*filename)->value.str.val);
+ if(!(rr = ap_sub_req_lookup_uri(filename, ((request_rec *) SG(server_context))))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed", filename);
RETURN_FALSE;
}
+
RETVAL_LONG(ap_run_sub_req(rr));
ap_destroy_sub_req(rr);
}
@@ -518,9 +564,9 @@ PHP_FUNCTION(apache_get_version)
if (apv && *apv) {
RETURN_STRING(apv, 1);
- } else {
- RETURN_FALSE;
}
+
+ RETURN_FALSE;
}
/* }}} */
diff --git a/sapi/apache/php_apache_http.h b/sapi/apache/php_apache_http.h
index 848485d68..42e32adcd 100644
--- a/sapi/apache/php_apache_http.h
+++ b/sapi/apache/php_apache_http.h
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_apache_http.h,v 1.13.2.1.2.3 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: php_apache_http.h,v 1.13.2.1.2.1.2.3 2008/12/31 11:15:48 sebastian Exp $ */
#define NO_REGEX_EXTRA_H
@@ -31,7 +31,7 @@
#endif
#include "zend.h"
-#include "php_regex.h"
+#include "ext/ereg/php_regex.h"
#include "php_compat.h"
#ifdef HAVE_OPENSSL_EXT
diff --git a/sapi/apache/sapi_apache.c b/sapi/apache/sapi_apache.c
index 2ead2f83e..f736119ee 100644
--- a/sapi/apache/sapi_apache.c
+++ b/sapi/apache/sapi_apache.c
@@ -19,7 +19,7 @@
| Stig Bakken <ssb@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: sapi_apache.c,v 1.47.2.1.2.3 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: sapi_apache.c,v 1.47.2.1.2.1.2.2 2008/12/31 11:15:48 sebastian Exp $ */
#include "php_apache_http.h"
diff --git a/sapi/apache2filter/apache_config.c b/sapi/apache2filter/apache_config.c
index 97d6825b1..0afd83d57 100644
--- a/sapi/apache2filter/apache_config.c
+++ b/sapi/apache2filter/apache_config.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: apache_config.c,v 1.34.2.1.2.5 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: apache_config.c,v 1.34.2.1.2.3.2.2 2008/12/31 11:15:48 sebastian Exp $ */
#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
diff --git a/sapi/apache2filter/config.m4 b/sapi/apache2filter/config.m4
index f9677334a..1fa03d4a9 100644
--- a/sapi/apache2filter/config.m4
+++ b/sapi/apache2filter/config.m4
@@ -1,5 +1,5 @@
dnl
-dnl $Id: config.m4,v 1.41.2.1.2.2 2007/07/11 23:20:36 jani Exp $
+dnl $Id: config.m4,v 1.41.2.1.2.2.2.2 2008/03/09 12:35:56 lstrojny Exp $
dnl
PHP_ARG_WITH(apxs2filter,,
@@ -110,7 +110,7 @@ if test "$PHP_APXS2FILTER" != "no"; then
`ln -s $APXS_BINDIR/httpd _APP_`
EXTRA_LIBS="$EXTRA_LIBS _APP_"
PHP_SELECT_SAPI(apache2filter, shared, sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS)
- INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL"
+ INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL"
;;
*)
PHP_SELECT_SAPI(apache2filter, shared, sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS)
@@ -118,7 +118,7 @@ if test "$PHP_APXS2FILTER" != "no"; then
;;
esac
- if test "$APXS_MPM" != "prefork"; then
+ if test "$APXS_MPM" != "prefork" && test "$APXS_MPM" != "peruser"; then
PHP_BUILD_THREAD_SAFE
fi
AC_MSG_RESULT(yes)
diff --git a/sapi/apache2filter/config.w32 b/sapi/apache2filter/config.w32
index 2bef33b23..5aa9078c6 100755
--- a/sapi/apache2filter/config.w32
+++ b/sapi/apache2filter/config.w32
@@ -1,10 +1,12 @@
// vim:ft=javascript
-// $Id: config.w32,v 1.1.2.1 2007/05/04 18:17:55 edink Exp $
+// $Id: config.w32,v 1.1.2.1.2.1 2008/05/14 03:13:17 auroraeosrose Exp $
ARG_ENABLE('apache2filter', 'Build Apache 2.x filter', 'no');
if (PHP_APACHE2FILTER != "no") {
- if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE2FILTER", PHP_PHP_BUILD + "\\include\\apache2") &&
+ if (PHP_ZTS == "no") {
+ WARNING("Apache2 module requires an --enable-zts build of PHP on windows");
+ } else if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE2FILTER", PHP_PHP_BUILD + "\\include\\apache2") &&
CHECK_LIB("libhttpd.lib", "apache2filter", PHP_PHP_BUILD + "\\lib\\apache2") &&
CHECK_LIB("libapr.lib", "apache2filter", PHP_PHP_BUILD + "\\lib\\apache2") &&
CHECK_LIB("libaprutil.lib", "apache2filter", PHP_PHP_BUILD + "\\lib\\apache2")
@@ -20,7 +22,9 @@ if (PHP_APACHE2FILTER != "no") {
ARG_ENABLE('apache2-2filter', 'Build Apache 2.2.x filter', 'no');
if (PHP_APACHE2_2FILTER != "no") {
- if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE2_2FILTER", PHP_PHP_BUILD + "\\include\\apache2_2") &&
+ if (PHP_ZTS == "no") {
+ WARNING("Apache2 module requires an --enable-zts build of PHP on windows");
+ } else if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE2_2FILTER", PHP_PHP_BUILD + "\\include\\apache2_2") &&
CHECK_LIB("libhttpd.lib", "apache2_2filter", PHP_PHP_BUILD + "\\lib\\apache2_2") &&
CHECK_LIB("libapr-1.lib", "apache2_2filter", PHP_PHP_BUILD + "\\lib\\apache2_2") &&
CHECK_LIB("libaprutil-1.lib", "apache2_2filter", PHP_PHP_BUILD + "\\lib\\apache2_2")
diff --git a/sapi/apache2filter/php_apache.h b/sapi/apache2filter/php_apache.h
index 681f19f3b..49bd5f262 100644
--- a/sapi/apache2filter/php_apache.h
+++ b/sapi/apache2filter/php_apache.h
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_apache.h,v 1.25.2.1.2.4 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: php_apache.h,v 1.25.2.1.2.2.2.4 2008/12/31 11:15:48 sebastian Exp $ */
#ifndef PHP_APACHE_H
#define PHP_APACHE_H
@@ -49,7 +49,6 @@ typedef struct php_struct {
} php_struct;
typedef struct _php_apr_bucket_brigade {
- unsigned int total_len;
apr_bucket_brigade *bb;
} php_apr_bucket_brigade;
@@ -60,8 +59,7 @@ void apply_config(void *);
extern const command_rec php_dir_cmds[];
static size_t php_apache_read_stream(void *, char *, size_t TSRMLS_DC);
-static void php_apache_close_stream(void * TSRMLS_DC);
-static long php_apache_fteller_stream(void * TSRMLS_DC);
+static size_t php_apache_fsizer_stream(void * TSRMLS_DC);
#define APR_ARRAY_FOREACH_OPEN(arr, key, val) \
{ \
@@ -74,4 +72,10 @@ static long php_apache_fteller_stream(void * TSRMLS_DC);
#define APR_ARRAY_FOREACH_CLOSE() }}
+/* fix for gcc4 visibility patch */
+#ifndef PHP_WIN32
+# undef AP_MODULE_DECLARE_DATA
+# define AP_MODULE_DECLARE_DATA PHPAPI
+#endif
+
#endif /* PHP_APACHE_H */
diff --git a/sapi/apache2filter/php_functions.c b/sapi/apache2filter/php_functions.c
index d01196f26..845f70dff 100644
--- a/sapi/apache2filter/php_functions.c
+++ b/sapi/apache2filter/php_functions.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_functions.c,v 1.44.2.2.2.4 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: php_functions.c,v 1.44.2.2.2.2.2.9 2009/01/05 16:24:26 iliaa Exp $ */
#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
@@ -59,23 +59,22 @@ static request_rec *php_apache_lookup_uri(char *filename TSRMLS_DC)
Perform an apache sub-request */
PHP_FUNCTION(virtual)
{
- zval **filename;
+ char *filename;
+ int filename_len;
request_rec *rr;
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ return;
}
- convert_to_string_ex(filename);
-
- if (!(rr = php_apache_lookup_uri(Z_STRVAL_PP(filename) TSRMLS_CC))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", Z_STRVAL_PP(filename));
+ if (!(rr = php_apache_lookup_uri(filename TSRMLS_CC))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", filename);
RETURN_FALSE;
}
if (rr->status == HTTP_OK) {
if (ap_run_sub_req(rr)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", Z_STRVAL_PP(filename));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", filename);
ap_destroy_sub_req(rr);
RETURN_FALSE;
}
@@ -83,7 +82,7 @@ PHP_FUNCTION(virtual)
RETURN_TRUE;
}
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", Z_STRVAL_PP(filename));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", filename);
ap_destroy_sub_req(rr);
RETURN_FALSE;
}
@@ -99,16 +98,15 @@ PHP_FUNCTION(virtual)
PHP_FUNCTION(apache_lookup_uri)
{
request_rec *rr;
- zval **filename;
+ char *filename;
+ int filename_len;
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ return;
}
- convert_to_string_ex(filename);
-
- if (!(rr = php_apache_lookup_uri(Z_STRVAL_PP(filename) TSRMLS_CC))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", Z_STRVAL_PP(filename));
+ if (!(rr = php_apache_lookup_uri(filename TSRMLS_CC))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", filename);
RETURN_FALSE;
}
@@ -145,7 +143,7 @@ PHP_FUNCTION(apache_lookup_uri)
return;
}
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", Z_STRVAL_PP(filename));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", filename);
ap_destroy_sub_req(rr);
RETURN_FALSE;
}
@@ -195,31 +193,27 @@ PHP_FUNCTION(apache_response_headers)
PHP_FUNCTION(apache_note)
{
php_struct *ctx;
- zval **note_name, **note_val;
+ char *note_name, *note_val = NULL;
+ int note_name_len, note_val_len;
char *old_note_val=NULL;
- int arg_count = ZEND_NUM_ARGS();
- if (arg_count<1 || arg_count>2 ||
- zend_get_parameters_ex(arg_count, &note_name, &note_val) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &note_name, &note_name_len, &note_val, &note_val_len) == FAILURE) {
+ return;
}
-
+
ctx = SG(server_context);
-
- convert_to_string_ex(note_name);
- old_note_val = (char *) apr_table_get(ctx->r->notes, Z_STRVAL_PP(note_name));
-
- if (arg_count == 2) {
- convert_to_string_ex(note_val);
- apr_table_set(ctx->r->notes, Z_STRVAL_PP(note_name), Z_STRVAL_PP(note_val));
+ old_note_val = (char *) apr_table_get(ctx->r->notes, note_name);
+
+ if (note_val) {
+ apr_table_set(ctx->r->notes, note_name, note_val);
}
if (old_note_val) {
RETURN_STRING(old_note_val, 1);
- } else {
- RETURN_FALSE;
}
+
+ RETURN_FALSE;
}
/* }}} */
@@ -229,26 +223,24 @@ PHP_FUNCTION(apache_note)
PHP_FUNCTION(apache_setenv)
{
php_struct *ctx;
- zval **variable=NULL, **string_val=NULL, **walk_to_top=NULL;
+ char *variable=NULL, *string_val=NULL;
+ int variable_len, string_val_len;
+ zend_bool walk_to_top = 0;
int arg_count = ZEND_NUM_ARGS();
- if (arg_count<1 || arg_count>3 ||
- zend_get_parameters_ex(arg_count, &variable, &string_val, &walk_to_top) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(arg_count TSRMLS_CC, "ss|b", &variable, &variable_len, &string_val, &string_val_len, &walk_to_top) == FAILURE) {
+ return;
}
ctx = SG(server_context);
- if (arg_count == 3 && Z_STRVAL_PP(walk_to_top)) {
+ if (arg_count == 3 && walk_to_top) {
while(ctx->f->r->prev) {
ctx->f->r = ctx->f->r->prev;
- }
+ }
}
- convert_to_string_ex(variable);
- convert_to_string_ex(string_val);
-
- apr_table_set(ctx->r->subprocess_env, Z_STRVAL_PP(variable), Z_STRVAL_PP(string_val));
+ apr_table_set(ctx->r->subprocess_env, variable, string_val);
RETURN_TRUE;
}
@@ -259,31 +251,30 @@ PHP_FUNCTION(apache_setenv)
PHP_FUNCTION(apache_getenv)
{
php_struct *ctx;
- zval **variable=NULL, **walk_to_top=NULL;
+ char *variable=NULL;
+ int variable_len;
+ zend_bool walk_to_top = 0;
int arg_count = ZEND_NUM_ARGS();
char *env_val=NULL;
- if (arg_count<1 || arg_count>2 ||
- zend_get_parameters_ex(arg_count, &variable, &walk_to_top) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(arg_count TSRMLS_CC, "s|b", &variable, &variable_len, &walk_to_top) == FAILURE) {
+ return;
}
ctx = SG(server_context);
- if (arg_count == 2 && Z_STRVAL_PP(walk_to_top)) {
+ if (arg_count == 2 && walk_to_top) {
while(ctx->f->r->prev) {
ctx->f->r = ctx->f->r->prev;
- }
+ }
}
- convert_to_string_ex(variable);
-
- env_val = (char*) apr_table_get(ctx->r->subprocess_env, Z_STRVAL_PP(variable));
+ env_val = (char*) apr_table_get(ctx->r->subprocess_env, variable);
if (env_val != NULL) {
RETURN_STRING(env_val, 1);
- } else {
- RETURN_FALSE;
- }
+ }
+
+ RETURN_FALSE;
}
/* }}} */
@@ -359,17 +350,55 @@ PHP_MINFO_FUNCTION(apache)
php_info_print_table_end();
}
-static zend_function_entry apache_functions[] = {
- PHP_FE(apache_lookup_uri, NULL)
- PHP_FE(virtual, NULL)
- PHP_FE(apache_request_headers, NULL)
- PHP_FE(apache_response_headers, NULL)
- PHP_FE(apache_setenv, NULL)
- PHP_FE(apache_getenv, NULL)
- PHP_FE(apache_note, NULL)
- PHP_FE(apache_get_version, NULL)
- PHP_FE(apache_get_modules, NULL)
- PHP_FALIAS(getallheaders, apache_request_headers, NULL)
+/* {{{ arginfo */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apache2filter_lookup_uri, 0, 0, 1)
+ ZEND_ARG_INFO(0, filename)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apache2filter_virtual, 0, 0, 1)
+ ZEND_ARG_INFO(0, uri)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_apache2filter_getallheaders, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_apache2filter_response_headers, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apache2filter_note, 0, 0, 1)
+ ZEND_ARG_INFO(0, note_name)
+ ZEND_ARG_INFO(0, note_value)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apache2filter_setenv, 0, 0, 2)
+ ZEND_ARG_INFO(0, variable)
+ ZEND_ARG_INFO(0, value)
+ ZEND_ARG_INFO(0, walk_to_top)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apache2filter_getenv, 0, 0, 1)
+ ZEND_ARG_INFO(0, variable)
+ ZEND_ARG_INFO(0, walk_to_top)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_apache2filter_get_version, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_apache2filter_get_modules, 0)
+ZEND_END_ARG_INFO()
+/* }}} */
+
+static const zend_function_entry apache_functions[] = {
+ PHP_FE(apache_lookup_uri, arginfo_apache2filter_lookup_uri)
+ PHP_FE(virtual, arginfo_apache2filter_virtual)
+ PHP_FE(apache_request_headers, arginfo_apache2filter_getallheaders)
+ PHP_FE(apache_response_headers, arginfo_apache2filter_response_headers)
+ PHP_FE(apache_setenv, arginfo_apache2filter_setenv)
+ PHP_FE(apache_getenv, arginfo_apache2filter_getenv)
+ PHP_FE(apache_note, arginfo_apache2filter_note)
+ PHP_FE(apache_get_version, arginfo_apache2filter_get_version)
+ PHP_FE(apache_get_modules, arginfo_apache2filter_get_modules)
+ PHP_FALIAS(getallheaders, apache_request_headers, arginfo_apache2filter_getallheaders)
{NULL, NULL, NULL}
};
diff --git a/sapi/apache2filter/sapi_apache2.c b/sapi/apache2filter/sapi_apache2.c
index 6e91647ee..d963c1c56 100644
--- a/sapi/apache2filter/sapi_apache2.c
+++ b/sapi/apache2filter/sapi_apache2.c
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: sapi_apache2.c,v 1.136.2.2.2.11 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: sapi_apache2.c,v 1.136.2.2.2.8.2.7 2008/12/31 11:15:48 sebastian Exp $ */
#include <fcntl.h>
@@ -91,7 +91,7 @@ php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
}
static int
-php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC)
+php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC)
{
php_struct *ctx;
ap_filter_t *f;
@@ -100,29 +100,44 @@ php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_str
ctx = SG(server_context);
f = ctx->r->output_filters;
- val = strchr(sapi_header->header, ':');
-
- if (!val) {
- sapi_free_header(sapi_header);
- return 0;
+ switch(op) {
+ case SAPI_HEADER_DELETE:
+ apr_table_unset(ctx->r->headers_out, sapi_header->header);
+ return 0;
+
+ case SAPI_HEADER_DELETE_ALL:
+ apr_table_clear(ctx->r->headers_out);
+ return 0;
+
+ case SAPI_HEADER_ADD:
+ case SAPI_HEADER_REPLACE:
+ val = strchr(sapi_header->header, ':');
+
+ if (!val) {
+ sapi_free_header(sapi_header);
+ return 0;
+ }
+ ptr = val;
+
+ *val = '\0';
+
+ do {
+ val++;
+ } while (*val == ' ');
+
+ if (!strcasecmp(sapi_header->header, "content-type"))
+ ctx->r->content_type = apr_pstrdup(ctx->r->pool, val);
+ else if (op == SAPI_HEADER_REPLACE)
+ apr_table_set(ctx->r->headers_out, sapi_header->header, val);
+ else
+ apr_table_add(ctx->r->headers_out, sapi_header->header, val);
+
+ *ptr = ':';
+ return SAPI_HEADER_ADD;
+
+ default:
+ return 0;
}
- ptr = val;
-
- *val = '\0';
-
- do {
- val++;
- } while (*val == ' ');
-
- if (!strcasecmp(sapi_header->header, "content-type"))
- ctx->r->content_type = apr_pstrdup(ctx->r->pool, val);
- else if (sapi_header->replace)
- apr_table_set(ctx->r->headers_out, sapi_header->header, val);
- else
- apr_table_add(ctx->r->headers_out, sapi_header->header, val);
-
- *ptr = ':';
- return SAPI_HEADER_ADD;
}
static int
@@ -210,7 +225,7 @@ php_apache_sapi_register_variables(zval *track_vars_array TSRMLS_DC)
php_struct *ctx = SG(server_context);
const apr_array_header_t *arr = apr_table_elts(ctx->r->subprocess_env);
char *key, *val;
- int new_val_len;
+ unsigned int new_val_len;
APR_ARRAY_FOREACH_OPEN(arr, key, val)
if (!val) {
@@ -335,6 +350,7 @@ static sapi_module_struct apache2_sapi_module = {
php_apache_sapi_register_variables,
php_apache_sapi_log_message, /* Log message */
php_apache_sapi_get_request_time, /* Get Request Time */
+ NULL, /* Child terminate */
STANDARD_SAPI_MODULE_PROPERTIES
};
@@ -471,17 +487,16 @@ static int php_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
} else {
pbb = f->ctx = apr_palloc(f->r->pool, sizeof(*pbb));
pbb->bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc);
- pbb->total_len = 0;
}
if(ap_save_brigade(NULL, &pbb->bb, &bb, f->r->pool) != APR_SUCCESS) {
- // Bad
+ /* Bad */
}
apr_brigade_cleanup(bb);
- // Check to see if the last bucket in this brigade, it not
- // we have to wait until then.
+ /* Check to see if the last bucket in this brigade, it not
+ * we have to wait until then. */
if(!APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(pbb->bb))) {
return 0;
}
@@ -518,16 +533,16 @@ static int php_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
apply_config(conf);
php_apache_request_ctor(f, ctx TSRMLS_CC);
- // It'd be nice if we could highlight based of a zend_file_handle here....
- // ...but we can't.
+ /* It'd be nice if we could highlight based of a zend_file_handle here....
+ * ...but we can't. */
zfd.type = ZEND_HANDLE_STREAM;
zfd.handle.stream.handle = pbb;
zfd.handle.stream.reader = php_apache_read_stream;
- zfd.handle.stream.closer = php_apache_close_stream;
- zfd.handle.stream.fteller = php_apache_fteller_stream;
- zfd.handle.stream.interactive = 0;
+ zfd.handle.stream.closer = NULL;
+ zfd.handle.stream.fsizer = php_apache_fsizer_stream;
+ zfd.handle.stream.isatty = 0;
zfd.filename = f->r->filename;
zfd.opened_path = NULL;
@@ -713,20 +728,20 @@ static size_t php_apache_read_stream(void *handle, char *buf, size_t wantlen TSR
readlen = wantlen;
apr_brigade_flatten(rbb, buf, &readlen);
apr_brigade_cleanup(rbb);
- pbb->total_len += readlen;
return readlen;
}
-static void php_apache_close_stream(void *handle TSRMLS_DC)
-{
- return;
-}
-
-static long php_apache_fteller_stream(void *handle TSRMLS_DC)
+static size_t php_apache_fsizer_stream(void *handle TSRMLS_DC)
{
php_apr_bucket_brigade *pbb = (php_apr_bucket_brigade *)handle;
- return pbb->total_len;
+ apr_off_t actual = 0;
+
+ if (apr_brigade_length(pbb->bb, 1, &actual) == APR_SUCCESS) {
+ return actual;
+ }
+
+ return 0;
}
AP_MODULE_DECLARE_DATA module php5_module = {
diff --git a/sapi/apache2handler/apache_config.c b/sapi/apache2handler/apache_config.c
index 1e961083d..24358fa08 100644
--- a/sapi/apache2handler/apache_config.c
+++ b/sapi/apache2handler/apache_config.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: apache_config.c,v 1.7.2.1.2.7 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: apache_config.c,v 1.7.2.1.2.4.2.4 2008/12/31 14:45:14 bjori Exp $ */
#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
@@ -138,11 +138,13 @@ static zend_bool should_overwrite_per_dir_entry(HashTable *target_ht, php_dir_en
void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
{
php_conf_rec *d = base_conf, *e = new_conf, *n = NULL;
+#if STAS_0
php_dir_entry *pe;
php_dir_entry *data;
char *str;
uint str_len;
ulong num_index;
+#endif
n = create_php_config(p, "merge_php_config");
/* copy old config */
diff --git a/sapi/apache2handler/config.m4 b/sapi/apache2handler/config.m4
index 41ace4ef0..08ab1b909 100644
--- a/sapi/apache2handler/config.m4
+++ b/sapi/apache2handler/config.m4
@@ -1,5 +1,5 @@
dnl
-dnl $Id: config.m4,v 1.14.2.1.2.2 2007/07/11 23:20:36 jani Exp $
+dnl $Id: config.m4,v 1.14.2.1.2.2.2.3 2008/03/11 22:47:39 lstrojny Exp $
dnl
PHP_ARG_WITH(apxs2,,
@@ -109,7 +109,7 @@ if test "$PHP_APXS2" != "no"; then
`ln -s $APXS_BINDIR/httpd _APP_`
EXTRA_LIBS="$EXTRA_LIBS _APP_"
PHP_SELECT_SAPI(apache2handler, shared, mod_php5.c sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS)
- INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL"
+ INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL"
;;
*)
PHP_SELECT_SAPI(apache2handler, shared, mod_php5.c sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS)
@@ -117,7 +117,7 @@ if test "$PHP_APXS2" != "no"; then
;;
esac
- if test "$APXS_MPM" != "prefork"; then
+ if test "$APXS_MPM" != "prefork" && test "$APXS_MPM" != "peruser" && test "$APXS_MPM" != "itk"; then
PHP_BUILD_THREAD_SAFE
fi
AC_MSG_RESULT(yes)
diff --git a/sapi/apache2handler/config.w32 b/sapi/apache2handler/config.w32
index b35dd33ac..70aee0b71 100644
--- a/sapi/apache2handler/config.w32
+++ b/sapi/apache2handler/config.w32
@@ -1,10 +1,12 @@
// vim:ft=javascript
-// $Id: config.w32,v 1.1.6.2 2007/05/04 18:17:55 edink Exp $
+// $Id: config.w32,v 1.1.6.2.2.1 2008/05/14 03:13:17 auroraeosrose Exp $
ARG_ENABLE('apache2handler', 'Build Apache 2.x handler', 'no');
if (PHP_APACHE2HANDLER != "no") {
- if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE2HANDLER", PHP_PHP_BUILD + "\\include\\apache2") &&
+ if (PHP_ZTS == "no") {
+ WARNING("Apache2 module requires an --enable-zts build of PHP on windows");
+ } else if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE2HANDLER", PHP_PHP_BUILD + "\\include\\apache2") &&
CHECK_LIB("libhttpd.lib", "apache2handler", PHP_PHP_BUILD + "\\lib\\apache2") &&
CHECK_LIB("libapr.lib", "apache2handler", PHP_PHP_BUILD + "\\lib\\apache2") &&
CHECK_LIB("libaprutil.lib", "apache2handler", PHP_PHP_BUILD + "\\lib\\apache2")
@@ -20,7 +22,9 @@ if (PHP_APACHE2HANDLER != "no") {
ARG_ENABLE('apache2-2handler', 'Build Apache 2.2.x handler', 'no');
if (PHP_APACHE2_2HANDLER != "no") {
- if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE2_2HANDLER", PHP_PHP_BUILD + "\\include\\apache2_2") &&
+ if (PHP_ZTS == "no") {
+ WARNING("Apache2 module requires an --enable-zts build of PHP on windows");
+ } else if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE2_2HANDLER", PHP_PHP_BUILD + "\\include\\apache2_2") &&
CHECK_LIB("libhttpd.lib", "apache2_2handler", PHP_PHP_BUILD + "\\lib\\apache2_2") &&
CHECK_LIB("libapr-1.lib", "apache2_2handler", PHP_PHP_BUILD + "\\lib\\apache2_2") &&
CHECK_LIB("libaprutil-1.lib", "apache2_2handler", PHP_PHP_BUILD + "\\lib\\apache2_2")
diff --git a/sapi/apache2handler/mod_php5.c b/sapi/apache2handler/mod_php5.c
index 0a3ed7a22..68082eca6 100644
--- a/sapi/apache2handler/mod_php5.c
+++ b/sapi/apache2handler/mod_php5.c
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: mod_php5.c,v 1.5.2.1.2.3 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: mod_php5.c,v 1.5.2.1.2.1.2.2 2008/12/31 11:15:48 sebastian Exp $ */
#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
diff --git a/sapi/apache2handler/php_apache.h b/sapi/apache2handler/php_apache.h
index c1c9474a6..b0ac5464e 100644
--- a/sapi/apache2handler/php_apache.h
+++ b/sapi/apache2handler/php_apache.h
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_apache.h,v 1.8.2.1.2.4 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: php_apache.h,v 1.8.2.1.2.2.2.3 2008/12/31 11:15:48 sebastian Exp $ */
#ifndef PHP_APACHE_H
#define PHP_APACHE_H
@@ -82,5 +82,10 @@ extern php_apache2_info_struct php_apache2_info;
#define AP2(v) (php_apache2_info.v)
#endif
+/* fix for gcc4 visibility patch */
+#ifndef PHP_WIN32
+# undef AP_MODULE_DECLARE_DATA
+# define AP_MODULE_DECLARE_DATA PHPAPI
+#endif
#endif /* PHP_APACHE_H */
diff --git a/sapi/apache2handler/php_functions.c b/sapi/apache2handler/php_functions.c
index 7db52a5b7..65b280642 100644
--- a/sapi/apache2handler/php_functions.c
+++ b/sapi/apache2handler/php_functions.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_functions.c,v 1.18.2.6.2.7 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: php_functions.c,v 1.18.2.6.2.5.2.11 2009/01/19 19:32:40 scottmac Exp $ */
#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
@@ -71,23 +71,21 @@ static request_rec *php_apache_lookup_uri(char *filename TSRMLS_DC)
Perform an apache sub-request */
PHP_FUNCTION(virtual)
{
- zval **filename;
+ char *filename;
+ int filename_len;
request_rec *rr;
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ return;
}
- convert_to_string_ex(filename);
-
-
- if (!(rr = php_apache_lookup_uri(Z_STRVAL_PP(filename) TSRMLS_CC))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", Z_STRVAL_PP(filename));
+ if (!(rr = php_apache_lookup_uri(filename TSRMLS_CC))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", filename);
RETURN_FALSE;
}
if (rr->status != HTTP_OK) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", Z_STRVAL_PP(filename));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", filename);
ap_destroy_sub_req(rr);
RETURN_FALSE;
}
@@ -101,7 +99,7 @@ PHP_FUNCTION(virtual)
ap_rflush(rr->main);
if (ap_run_sub_req(rr)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", Z_STRVAL_PP(filename));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", filename);
ap_destroy_sub_req(rr);
RETURN_FALSE;
}
@@ -120,16 +118,15 @@ PHP_FUNCTION(virtual)
PHP_FUNCTION(apache_lookup_uri)
{
request_rec *rr;
- zval **filename;
+ char *filename;
+ int filename_len;
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ return;
}
- convert_to_string_ex(filename);
-
- if (!(rr = php_apache_lookup_uri(Z_STRVAL_PP(filename) TSRMLS_CC))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", Z_STRVAL_PP(filename));
+ if (!(rr = php_apache_lookup_uri(filename TSRMLS_CC))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", filename);
RETURN_FALSE;
}
@@ -166,7 +163,7 @@ PHP_FUNCTION(apache_lookup_uri)
return;
}
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", Z_STRVAL_PP(filename));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", filename);
ap_destroy_sub_req(rr);
RETURN_FALSE;
}
@@ -179,8 +176,8 @@ PHP_FUNCTION(apache_request_headers)
const apr_array_header_t *arr;
char *key, *val;
- if (ZEND_NUM_ARGS()) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
array_init(return_value);
@@ -203,8 +200,8 @@ PHP_FUNCTION(apache_response_headers)
const apr_array_header_t *arr;
char *key, *val;
- if (ZEND_NUM_ARGS()) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
array_init(return_value);
@@ -224,31 +221,27 @@ PHP_FUNCTION(apache_response_headers)
PHP_FUNCTION(apache_note)
{
php_struct *ctx;
- zval **note_name, **note_val;
+ char *note_name, *note_val = NULL;
+ int note_name_len, note_val_len;
char *old_note_val=NULL;
- int arg_count = ZEND_NUM_ARGS();
- if (arg_count<1 || arg_count>2 ||
- zend_get_parameters_ex(arg_count, &note_name, &note_val) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &note_name, &note_name_len, &note_val, &note_val_len) == FAILURE) {
+ return;
}
-
+
ctx = SG(server_context);
-
- convert_to_string_ex(note_name);
- old_note_val = (char *) apr_table_get(ctx->r->notes, Z_STRVAL_PP(note_name));
-
- if (arg_count == 2) {
- convert_to_string_ex(note_val);
- apr_table_set(ctx->r->notes, Z_STRVAL_PP(note_name), Z_STRVAL_PP(note_val));
+ old_note_val = (char *) apr_table_get(ctx->r->notes, note_name);
+
+ if (note_val) {
+ apr_table_set(ctx->r->notes, note_name, note_val);
}
if (old_note_val) {
RETURN_STRING(old_note_val, 1);
- } else {
- RETURN_FALSE;
}
+
+ RETURN_FALSE;
}
/* }}} */
@@ -260,31 +253,28 @@ PHP_FUNCTION(apache_note)
PHP_FUNCTION(apache_setenv)
{
php_struct *ctx;
- zval **variable=NULL, **string_val=NULL, **walk_to_top=NULL;
+ char *variable=NULL, *string_val=NULL;
+ int variable_len, string_val_len;
+ zend_bool walk_to_top = 0;
int arg_count = ZEND_NUM_ARGS();
request_rec *r;
- if (arg_count < 2 || arg_count > 3 ||
- zend_get_parameters_ex(arg_count, &variable, &string_val, &walk_to_top) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(arg_count TSRMLS_CC, "ss|b", &variable, &variable_len, &string_val, &string_val_len, &walk_to_top) == FAILURE) {
+ return;
}
ctx = SG(server_context);
r = ctx->r;
if (arg_count == 3) {
- convert_to_boolean_ex(walk_to_top);
- if (Z_LVAL_PP(walk_to_top)) {
+ if (walk_to_top) {
while(r->prev) {
r = r->prev;
}
}
}
- convert_to_string_ex(variable);
- convert_to_string_ex(string_val);
-
- apr_table_set(r->subprocess_env, Z_STRVAL_PP(variable), Z_STRVAL_PP(string_val));
+ apr_table_set(r->subprocess_env, variable, string_val);
RETURN_TRUE;
}
@@ -298,36 +288,35 @@ PHP_FUNCTION(apache_setenv)
PHP_FUNCTION(apache_getenv)
{
php_struct *ctx;
- zval **variable=NULL, **walk_to_top=NULL;
+ char *variable=NULL;
+ int variable_len;
+ zend_bool walk_to_top = 0;
int arg_count = ZEND_NUM_ARGS();
char *env_val=NULL;
request_rec *r;
- if (arg_count<1 || arg_count>2 ||
- zend_get_parameters_ex(arg_count, &variable, &walk_to_top) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(arg_count TSRMLS_CC, "s|b", &variable, &variable_len, &walk_to_top) == FAILURE) {
+ return;
}
ctx = SG(server_context);
r = ctx->r;
if (arg_count == 2) {
- convert_to_boolean_ex(walk_to_top);
- if (Z_LVAL_PP(walk_to_top)) {
+ if (walk_to_top) {
while(r->prev) {
r = r->prev;
}
}
}
- convert_to_string_ex(variable);
-
- env_val = (char*) apr_table_get(r->subprocess_env, Z_STRVAL_PP(variable));
+ env_val = (char*) apr_table_get(r->subprocess_env, variable);
+
if (env_val != NULL) {
RETURN_STRING(env_val, 1);
- } else {
- RETURN_FALSE;
- }
+ }
+
+ RETURN_FALSE;
}
/* }}} */
@@ -383,8 +372,12 @@ PHP_MINFO_FUNCTION(apache)
char *p;
server_rec *serv = ((php_struct *) SG(server_context))->r->server;
#if !defined(WIN32) && !defined(WINNT) && !defined(NETWARE)
+#if MODULE_MAGIC_NUMBER_MAJOR >= 20081201
+ AP_DECLARE_DATA extern unixd_config_rec ap_unixd_config;
+#else
AP_DECLARE_DATA extern unixd_config_rec unixd_config;
#endif
+#endif
for (n = 0; ap_loaded_modules[n]; ++n) {
char *s = (char *) ap_loaded_modules[n]->name;
@@ -414,7 +407,11 @@ PHP_MINFO_FUNCTION(apache)
php_info_print_table_row(2, "Hostname:Port", tmp);
#if !defined(WIN32) && !defined(WINNT) && !defined(NETWARE)
+#if MODULE_MAGIC_NUMBER_MAJOR >= 20081201
+ snprintf(tmp, sizeof(tmp), "%s(%d)/%d", ap_unixd_config.user_name, ap_unixd_config.user_id, ap_unixd_config.group_id);
+#else
snprintf(tmp, sizeof(tmp), "%s(%d)/%d", unixd_config.user_name, unixd_config.user_id, unixd_config.group_id);
+#endif
php_info_print_table_row(2, "User/Group", tmp);
#endif
@@ -478,17 +475,55 @@ PHP_MINFO_FUNCTION(apache)
}
}
-static zend_function_entry apache_functions[] = {
- PHP_FE(apache_lookup_uri, NULL)
- PHP_FE(virtual, NULL)
- PHP_FE(apache_request_headers, NULL)
- PHP_FE(apache_response_headers, NULL)
- PHP_FE(apache_setenv, NULL)
- PHP_FE(apache_getenv, NULL)
- PHP_FE(apache_note, NULL)
- PHP_FE(apache_get_version, NULL)
- PHP_FE(apache_get_modules, NULL)
- PHP_FALIAS(getallheaders, apache_request_headers, NULL)
+/* {{{ arginfo */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apache2handler_lookup_uri, 0, 0, 1)
+ ZEND_ARG_INFO(0, filename)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apache2handler_virtual, 0, 0, 1)
+ ZEND_ARG_INFO(0, uri)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_apache2handler_response_headers, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_apache2handler_getallheaders, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apache2handler_note, 0, 0, 1)
+ ZEND_ARG_INFO(0, note_name)
+ ZEND_ARG_INFO(0, note_value)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apache2handler_setenv, 0, 0, 2)
+ ZEND_ARG_INFO(0, variable)
+ ZEND_ARG_INFO(0, value)
+ ZEND_ARG_INFO(0, walk_to_top)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apache2handler_getenv, 0, 0, 1)
+ ZEND_ARG_INFO(0, variable)
+ ZEND_ARG_INFO(0, walk_to_top)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_apache2handler_get_version, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_apache2handler_get_modules, 0)
+ZEND_END_ARG_INFO()
+/* }}} */
+
+static const zend_function_entry apache_functions[] = {
+ PHP_FE(apache_lookup_uri, arginfo_apache2handler_lookup_uri)
+ PHP_FE(virtual, arginfo_apache2handler_virtual)
+ PHP_FE(apache_request_headers, arginfo_apache2handler_getallheaders)
+ PHP_FE(apache_response_headers, arginfo_apache2handler_response_headers)
+ PHP_FE(apache_setenv, arginfo_apache2handler_setenv)
+ PHP_FE(apache_getenv, arginfo_apache2handler_getenv)
+ PHP_FE(apache_note, arginfo_apache2handler_note)
+ PHP_FE(apache_get_version, arginfo_apache2handler_get_version)
+ PHP_FE(apache_get_modules, arginfo_apache2handler_get_modules)
+ PHP_FALIAS(getallheaders, apache_request_headers, arginfo_apache2handler_getallheaders)
{NULL, NULL, NULL}
};
diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c
index c7733b443..00ef1b28e 100644
--- a/sapi/apache2handler/sapi_apache2.c
+++ b/sapi/apache2handler/sapi_apache2.c
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: sapi_apache2.c,v 1.57.2.10.2.19 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: sapi_apache2.c,v 1.57.2.10.2.15.2.6 2008/12/31 11:15:48 sebastian Exp $ */
#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
@@ -83,40 +83,55 @@ php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
}
static int
-php_apache_sapi_header_handler(sapi_header_struct *sapi_header,sapi_headers_struct *sapi_headers TSRMLS_DC)
+php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC)
{
php_struct *ctx;
char *val, *ptr;
ctx = SG(server_context);
- val = strchr(sapi_header->header, ':');
+ switch (op) {
+ case SAPI_HEADER_DELETE:
+ apr_table_unset(ctx->r->headers_out, sapi_header->header);
+ return 0;
- if (!val) {
- sapi_free_header(sapi_header);
- return 0;
- }
- ptr = val;
+ case SAPI_HEADER_DELETE_ALL:
+ apr_table_clear(ctx->r->headers_out);
+ return 0;
+
+ case SAPI_HEADER_ADD:
+ case SAPI_HEADER_REPLACE:
+ val = strchr(sapi_header->header, ':');
- *val = '\0';
+ if (!val) {
+ return 0;
+ }
+ ptr = val;
+
+ *val = '\0';
- do {
- val++;
- } while (*val == ' ');
+ do {
+ val++;
+ } while (*val == ' ');
+
+ if (!strcasecmp(sapi_header->header, "content-type")) {
+ if (ctx->content_type) {
+ efree(ctx->content_type);
+ }
+ ctx->content_type = estrdup(val);
+ } else if (op == SAPI_HEADER_REPLACE) {
+ apr_table_set(ctx->r->headers_out, sapi_header->header, val);
+ } else {
+ apr_table_add(ctx->r->headers_out, sapi_header->header, val);
+ }
- if (!strcasecmp(sapi_header->header, "content-type")) {
- if (ctx->content_type) {
- efree(ctx->content_type);
- }
- ctx->content_type = estrdup(val);
- } else if (sapi_header->replace) {
- apr_table_set(ctx->r->headers_out, sapi_header->header, val);
- } else {
- apr_table_add(ctx->r->headers_out, sapi_header->header, val);
+ *ptr = ':';
+
+ return SAPI_HEADER_ADD;
+
+ default:
+ return 0;
}
- *ptr = ':';
-
- return SAPI_HEADER_ADD;
}
static int
@@ -343,6 +358,7 @@ static sapi_module_struct apache2_sapi_module = {
php_apache_sapi_register_variables,
php_apache_sapi_log_message, /* Log message */
php_apache_sapi_get_request_time, /* Request Time */
+ NULL, /* Child Terminate */
STANDARD_SAPI_MODULE_PROPERTIES
};
diff --git a/sapi/apache_hooks/config.w32 b/sapi/apache_hooks/config.w32
index f2ff89ef8..76869bd24 100644
--- a/sapi/apache_hooks/config.w32
+++ b/sapi/apache_hooks/config.w32
@@ -1,15 +1,15 @@
// vim:ft=javascript
-// $Id: config.w32,v 1.2 2004/01/17 13:00:08 sniper Exp $
+// $Id: config.w32,v 1.2.8.1 2008/04/15 16:55:53 auroraeosrose Exp $
ARG_WITH('apache-hooks', 'Build Apache 1.3.x (hooks) version of PHP', 'no');
if (PHP_APACHE_HOOKS != "no") {
if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE_HOOKS", php_usual_include_suspects +
";" + PROGRAM_FILES + "\\Apache Group\\Apache\\include" +
- ";..\\php_build\\apache\\src\\include") &&
+ ";" + PHP_PHP_BUILD + "\\apache\\src\\include") &&
CHECK_LIB("ApacheCore.lib", "apache_hooks", php_usual_lib_suspects +
';' + PROGRAM_FILES + '\\Apache Group\\Apache\\libexec' +
- ';..\\php_build\\apache\\src\\corer')) {
+ ";" + PHP_PHP_BUILD + "\\apache\\src\\corer")) {
// We need to play tricks to get our readdir.h used by apache
// headers
SAPI('apache_hooks', 'mod_php5.c sapi_apache.c php_apache.c',
diff --git a/sapi/apache_hooks/mod_php5.c b/sapi/apache_hooks/mod_php5.c
index 0f9d8a12f..4c2f346a7 100644
--- a/sapi/apache_hooks/mod_php5.c
+++ b/sapi/apache_hooks/mod_php5.c
@@ -17,7 +17,7 @@
| PHP 4.0 patches by Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
-/* $Id: mod_php5.c,v 1.11.2.1.2.7 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: mod_php5.c,v 1.11.2.1.2.5.2.5 2008/12/31 11:15:48 sebastian Exp $ */
#include "php_apache_http.h"
@@ -25,10 +25,6 @@
#define SIGPIPE SIGINT
#endif
-#if defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING)
-#include "ext/mbstring/mbstring.h"
-#endif /* defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING) */
-
#undef shutdown
/* {{{ Prototypes
@@ -38,7 +34,7 @@ static void php_save_umask(void);
static void php_restore_umask(void);
static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC);
static char *sapi_apache_read_cookies(TSRMLS_D);
-static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC);
+static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC);
static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC);
static int send_php(request_rec *r, int display_source_mode, char *filename);
static int send_parsed_php(request_rec * r);
@@ -312,35 +308,54 @@ static char *sapi_apache_read_cookies(TSRMLS_D)
/* {{{ sapi_apache_header_handler
*/
-static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC)
+static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC)
{
char *header_name, *header_content, *p;
request_rec *r = (request_rec *) SG(server_context);
-
- header_name = sapi_header->header;
-
- header_content = p = strchr(header_name, ':');
- if (!p) {
- efree(sapi_header->header);
+ if(!r) {
return 0;
}
- *p = 0;
- do {
- header_content++;
- } while (*header_content==' ');
+ switch(op) {
+ case SAPI_HEADER_DELETE_ALL:
+ clear_table(r->headers_out);
+ return 0;
- if (!strcasecmp(header_name, "Content-Type")) {
- r->content_type = pstrdup(r->pool, header_content);
- } else if (!strcasecmp(header_name, "Set-Cookie")) {
- table_add(r->headers_out, header_name, header_content);
- } else {
- table_set(r->headers_out, header_name, header_content);
- }
+ case SAPI_HEADER_DELETE:
+ table_unset(r->headers_out, sapi_header->header);
+ return 0;
+
+ case SAPI_HEADER_ADD:
+ case SAPI_HEADER_REPLACE:
+ header_name = sapi_header->header;
+
+ header_content = p = strchr(header_name, ':');
+ if (!p) {
+ return 0;
+ }
+
+ *p = 0;
+ do {
+ header_content++;
+ } while (*header_content==' ');
+
+ if (!strcasecmp(header_name, "Content-Type")) {
+ r->content_type = pstrdup(r->pool, header_content);
+ } else if (!strcasecmp(header_name, "Set-Cookie")) {
+ table_add(r->headers_out, header_name, header_content);
+ } else if (op == SAPI_HEADER_REPLACE) {
+ table_set(r->headers_out, header_name, header_content);
+ } else {
+ table_add(r->headers_out, header_name, header_content);
+ }
+
+ *p = ':'; /* a well behaved header handler shouldn't change its original arguments */
- *p = ':'; /* a well behaved header handler shouldn't change its original arguments */
+ return SAPI_HEADER_ADD;
- return SAPI_HEADER_ADD;
+ default:
+ return 0;
+ }
}
/* }}} */
@@ -528,6 +543,7 @@ static sapi_module_struct apache_sapi_module = {
sapi_apache_register_server_variables, /* register server variables */
php_apache_log_message, /* Log message */
NULL, /* Get request time */
+ NULL, /* child terminate */
NULL, /* php.ini path override */
@@ -645,10 +661,6 @@ static int send_php(request_rec *r, int display_source_mode, char *filename)
fh.free_filename = 0;
fh.type = ZEND_HANDLE_FILENAME;
-#if defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING)
- php_mbstring_set_zend_encoding(TSRMLS_C);
-#endif /* defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING) */
-
zend_execute_scripts(ZEND_INCLUDE TSRMLS_CC, NULL, 1, &fh);
return OK;
}
diff --git a/sapi/apache_hooks/mod_php5.h b/sapi/apache_hooks/mod_php5.h
index ffa815fa5..85767d196 100644
--- a/sapi/apache_hooks/mod_php5.h
+++ b/sapi/apache_hooks/mod_php5.h
@@ -15,7 +15,7 @@
| Author: Rasmus Lerdorf <rasmus@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: mod_php5.h,v 1.2.2.1.2.3 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: mod_php5.h,v 1.2.2.1.2.1.2.3 2008/12/31 11:15:48 sebastian Exp $ */
#ifndef MOD_PHP5_H
#define MOD_PHP5_H
@@ -71,6 +71,13 @@ extern php_apache_info_struct php_apache_info;
#define AP_LOGGING 10
#define AP_CLEANUP 11
+
+/* fix for gcc4 visibility patch */
+#ifndef PHP_WIN32
+# undef MODULE_VAR_EXPORT
+# define MODULE_VAR_EXPORT PHPAPI
+#endif
+
#endif /* MOD_PHP5_H */
/*
diff --git a/sapi/apache_hooks/php_apache.c b/sapi/apache_hooks/php_apache.c
index 982e72a36..1c9600537 100644
--- a/sapi/apache_hooks/php_apache.c
+++ b/sapi/apache_hooks/php_apache.c
@@ -17,7 +17,7 @@
| David Sklar <sklar@student.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: php_apache.c,v 1.19.2.3.2.7 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: php_apache.c,v 1.19.2.3.2.5.2.18 2009/03/16 10:13:18 pajoye Exp $ */
#include "php_apache_http.h"
@@ -59,18 +59,39 @@ PHP_FUNCTION(apache_get_modules);
PHP_MINFO_FUNCTION(apache);
-
-zend_function_entry apache_functions[] = {
- PHP_FE(virtual, NULL)
- PHP_FE(apache_request_headers, NULL)
- PHP_FE(apache_note, NULL)
- PHP_FE(apache_lookup_uri, NULL)
- PHP_FE(apache_child_terminate, NULL)
- PHP_FE(apache_setenv, NULL)
- PHP_FE(apache_response_headers, NULL)
- PHP_FE(apache_get_version, NULL)
- PHP_FE(apache_get_modules, NULL)
- PHP_FALIAS(getallheaders, apache_request_headers, NULL)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apachehooks_virtual, 0, 0, 1)
+ ZEND_ARG_INFO(0, filename)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apachehooks_setenv, 0, 0, 2)
+ ZEND_ARG_INFO(0, variable)
+ ZEND_ARG_INFO(0, value)
+ ZEND_ARG_INFO(0, walk_to_top)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apachehooks_lookup_uri, 0, 0, 1)
+ ZEND_ARG_INFO(0, uri)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_apachehooks__void, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apachehooks_note, 0, 0, 1)
+ ZEND_ARG_INFO(0, note_name)
+ ZEND_ARG_INFO(0, note_value)
+ZEND_END_ARG_INFO()
+
+const zend_function_entry apache_functions[] = {
+ PHP_FE(virtual, arginfo_apachehooks_virtual)
+ PHP_FE(apache_request_headers, arginfo_apachehooks__void)
+ PHP_FE(apache_note, arginfo_apachehooks_note)
+ PHP_FE(apache_lookup_uri, arginfo_apachehooks_lookup_uri)
+ PHP_FE(apache_child_terminate, arginfo_apachehooks__void)
+ PHP_FE(apache_setenv, arginfo_apachehooks_setenv)
+ PHP_FE(apache_response_headers, arginfo_apachehooks__void)
+ PHP_FE(apache_get_version, arginfo_apachehooks__void)
+ PHP_FE(apache_get_modules, arginfo_apachehooks__void)
+ PHP_FALIAS(getallheaders, apache_request_headers, arginfo_apachehooks__void)
{NULL, NULL, NULL}
};
@@ -164,16 +185,17 @@ static void apache_request_read_string_slot(int offset, INTERNAL_FUNCTION_PARAME
request_rec *r;
char *s;
- if (ZEND_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
APREQ_GET_REQUEST(id, r);
s = *(char **)((char*)r + offset);
- if (s)
+ if (s) {
RETURN_STRING(s, 1);
+ }
RETURN_EMPTY_STRING();
}
@@ -184,33 +206,28 @@ static void apache_request_read_string_slot(int offset, INTERNAL_FUNCTION_PARAME
*/
static void apache_request_string_slot(int offset, INTERNAL_FUNCTION_PARAMETERS)
{
- zval *id, **new_value;
+ zval *id;
request_rec *r;
- char *old_value;
+ char *old_value, *new_value = NULL;
+ int new_value_len;
char **target;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &new_value, &new_value_len) == FAILURE) {
+ return;
+ }
+
APREQ_GET_REQUEST(id, r);
target = (char **)((char*)r + offset);
old_value = *target;
- switch (ZEND_NUM_ARGS()) {
- case 0:
- break;
- case 1:
- if (zend_get_parameters_ex(1, &new_value) == FAILURE) {
- RETURN_FALSE;
- }
- convert_to_string_ex(new_value);
- *target = ap_pstrdup(r->pool, Z_STRVAL_PP(new_value));
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
+ if (new_value) {
+ *target = ap_pstrdup(r->pool, new_value);
}
- if (old_value)
+ if (old_value) {
RETURN_STRING(old_value, 1);
+ }
RETURN_EMPTY_STRING();
}
@@ -224,8 +241,8 @@ static void apache_request_read_int_slot(int offset, INTERNAL_FUNCTION_PARAMETER
request_rec *r;
long l;
- if (ZEND_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
APREQ_GET_REQUEST(id, r);
@@ -240,11 +257,15 @@ static void apache_request_read_int_slot(int offset, INTERNAL_FUNCTION_PARAMETER
*/
static void apache_request_int_slot(int offset, INTERNAL_FUNCTION_PARAMETERS)
{
- zval *id, **new_value;
+ zval *id;
request_rec *r;
- long old_value;
+ long old_value, new_value;
long *target;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &new_value) == FAILURE) {
+ return;
+ }
+
APREQ_GET_REQUEST(id, r);
target = (long *)((char*)r + offset);
@@ -254,11 +275,7 @@ static void apache_request_int_slot(int offset, INTERNAL_FUNCTION_PARAMETERS)
case 0:
break;
case 1:
- if (zend_get_parameters_ex(1, &new_value) == FAILURE) {
- RETURN_FALSE;
- }
- convert_to_long_ex(new_value);
- *target = Z_LVAL_PP(new_value);
+ *target = new_value;
break;
default:
WRONG_PARAM_COUNT;
@@ -485,24 +502,20 @@ PHP_FUNCTION(apache_request_mtime)
*/
PHP_FUNCTION(apache_request_content_length)
{
- zval *id, **zlen;
+ zval *id;
+ long zlen;
request_rec *r;
- if (ZEND_NUM_ARGS() == 0) {
- apache_request_read_int_slot(offsetof(request_rec, clength), INTERNAL_FUNCTION_PARAM_PASSTHRU);
- }
- else if (ZEND_NUM_ARGS() > 1) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &zlen) == FAILURE) {
+ return;
}
- else {
- if (zend_get_parameters_ex(1, &zlen) == FAILURE) {
- RETURN_FALSE;
- }
+ if (ZEND_NUM_ARGS() == 0) {
+ apache_request_read_int_slot(offsetof(request_rec, clength), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ } else {
APREQ_GET_REQUEST(id, r);
- convert_to_long_ex(zlen);
- (void)ap_set_content_length(r, Z_LVAL_PP(zlen));
+ (void)ap_set_content_length(r, zlen);
RETURN_TRUE;
}
}
@@ -573,8 +586,9 @@ static void add_header_to_table(table *t, INTERNAL_FUNCTION_PARAMETERS)
zend_bool replace = 0;
HashPosition pos;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zb", &first, &second, &replace) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zb", &first, &second, &replace) == FAILURE) {
RETURN_FALSE;
+ }
if (Z_TYPE_P(first) == IS_ARRAY) {
switch(ZEND_NUM_ARGS()) {
@@ -594,11 +608,11 @@ static void add_header_to_table(table *t, INTERNAL_FUNCTION_PARAMETERS)
}
convert_to_string_ex(value);
- if (replace)
+ if (replace) {
ap_table_set(t, string_key, Z_STRVAL_PP(value));
- else
+ } else {
ap_table_merge(t, string_key, Z_STRVAL_PP(value));
-
+ }
break;
case HASH_KEY_IS_LONG:
default:
@@ -613,23 +627,22 @@ static void add_header_to_table(table *t, INTERNAL_FUNCTION_PARAMETERS)
WRONG_PARAM_COUNT;
break;
}
- }
- else if (Z_TYPE_P(first) == IS_STRING) {
+ } else if (Z_TYPE_P(first) == IS_STRING) {
switch(ZEND_NUM_ARGS()) {
case 2:
case 3:
convert_to_string_ex(&second);
- if (replace)
+ if (replace) {
ap_table_set(t, Z_STRVAL_P(first), Z_STRVAL_P(second));
- else
+ } else {
ap_table_merge(t, Z_STRVAL_P(first), Z_STRVAL_P(second));
+ }
break;
default:
WRONG_PARAM_COUNT;
break;
}
- }
- else {
+ } else {
RETURN_FALSE;
}
}
@@ -647,8 +660,9 @@ PHP_FUNCTION(apache_request_headers_out)
APREQ_GET_REQUEST(id, r);
- if (ZEND_NUM_ARGS() > 0)
+ if (ZEND_NUM_ARGS() > 0) {
add_header_to_table(r->headers_out, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ }
apache_table_to_zval(r->headers_out, 0, return_value);
}
@@ -665,8 +679,9 @@ PHP_FUNCTION(apache_request_err_headers_out)
APREQ_GET_REQUEST(id, r);
- if (ZEND_NUM_ARGS() > 0)
+ if (ZEND_NUM_ARGS() > 0) {
add_header_to_table(r->err_headers_out, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ }
apache_table_to_zval(r->err_headers_out, 0, return_value);
}
@@ -683,8 +698,8 @@ PHP_FUNCTION(apache_request_server_port)
zval *id;
request_rec *r;
- if (ZEND_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
APREQ_GET_REQUEST(id, r);
@@ -697,32 +712,26 @@ PHP_FUNCTION(apache_request_server_port)
*/
PHP_FUNCTION(apache_request_remote_host)
{
- zval *id, **ztype;
+ zval *id;
+ long type = 0;
request_rec *r;
char *res;
- int type = REMOTE_NAME;
- switch (ZEND_NUM_ARGS()) {
- case 0:
- break;
- case 1:
- if (zend_get_parameters_ex(1, &ztype) == FAILURE) {
- RETURN_FALSE;
- }
- convert_to_long_ex(ztype);
- type = Z_LVAL_PP(ztype);
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &type) == FAILURE) {
+ return;
}
+ if (!type) {
+ type = REMOTE_NAME;
+ }
APREQ_GET_REQUEST(id, r);
- res = (char *)ap_get_remote_host(r->connection, r->per_dir_config, type);
- if (res)
+ res = (char *)ap_get_remote_host(r->connection, r->per_dir_config, (int)type);
+
+ if (res) {
RETURN_STRING(res, 1);
+ }
RETURN_EMPTY_STRING();
}
@@ -732,29 +741,17 @@ PHP_FUNCTION(apache_request_remote_host)
*/
PHP_FUNCTION(apache_request_update_mtime)
{
- zval *id, **zmtime;
+ zval *id;
request_rec *r;
- int mtime = 0;
+ long mtime = 0;
- switch (ZEND_NUM_ARGS()) {
- case 0:
- break;
- case 1:
- if (zend_get_parameters_ex(1, &zmtime) == FAILURE) {
- RETURN_FALSE;
- }
- convert_to_long_ex(zmtime);
- mtime = Z_LVAL_PP(zmtime);
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &mtime) == FAILURE) {
+ return;
}
-
APREQ_GET_REQUEST(id, r);
- RETURN_LONG(ap_update_mtime(r, mtime));
+ RETURN_LONG(ap_update_mtime(r, (int) mtime));
}
/* }}} */
@@ -766,8 +763,8 @@ PHP_FUNCTION(apache_request_set_etag)
zval *id;
request_rec *r;
- if (ZEND_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
APREQ_GET_REQUEST(id, r);
@@ -784,8 +781,8 @@ PHP_FUNCTION(apache_request_set_last_modified)
zval *id;
request_rec *r;
- if (ZEND_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
APREQ_GET_REQUEST(id, r);
@@ -802,8 +799,8 @@ PHP_FUNCTION(apache_request_meets_conditions)
zval *id;
request_rec *r;
- if (ZEND_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
APREQ_GET_REQUEST(id, r);
@@ -819,8 +816,8 @@ PHP_FUNCTION(apache_request_discard_request_body)
zval *id;
request_rec *r;
- if (ZEND_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
APREQ_GET_REQUEST(id, r);
@@ -836,8 +833,8 @@ PHP_FUNCTION(apache_request_satisfies)
zval *id;
request_rec *r;
- if (ZEND_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
APREQ_GET_REQUEST(id, r);
@@ -854,8 +851,8 @@ PHP_FUNCTION(apache_request_is_initial_req)
zval *id;
request_rec *r;
- if (ZEND_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
APREQ_GET_REQUEST(id, r);
@@ -871,8 +868,8 @@ PHP_FUNCTION(apache_request_some_auth_required)
zval *id;
request_rec *r;
- if (ZEND_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
APREQ_GET_REQUEST(id, r);
@@ -889,15 +886,16 @@ PHP_FUNCTION(apache_request_auth_type)
request_rec *r;
char *t;
- if (ZEND_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
APREQ_GET_REQUEST(id, r);
t = (char *)ap_auth_type(r);
- if (!t)
+ if (!t) {
RETURN_NULL();
+ }
RETURN_STRING(t, 1);
}
@@ -911,15 +909,16 @@ PHP_FUNCTION(apache_request_auth_name)
request_rec *r;
char *t;
- if (ZEND_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
APREQ_GET_REQUEST(id, r);
t = (char *)ap_auth_name(r);
- if (!t)
+ if (!t) {
RETURN_NULL();
+ }
RETURN_STRING(t, 1);
}
@@ -934,12 +933,8 @@ PHP_FUNCTION(apache_request_basic_auth_pw)
const char *pw;
long status;
- if (ZEND_NUM_ARGS() != 1) {
- WRONG_PARAM_COUNT;
- }
-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zpw) == FAILURE) {
- RETURN_NULL();
+ return;
}
if (!PZVAL_IS_REF(zpw)) {
@@ -947,16 +942,15 @@ PHP_FUNCTION(apache_request_basic_auth_pw)
RETURN_NULL();
}
-
APREQ_GET_REQUEST(id, r);
pw = NULL;
status = ap_get_basic_auth_pw(r, &pw);
if (status == OK && pw) {
ZVAL_STRING(zpw, (char *)pw, 1);
- }
- else
+ } else {
ZVAL_NULL(zpw);
+ }
RETURN_LONG(status);
}
/* }}} */
@@ -971,8 +965,10 @@ PHP_FUNCTION(apache_request_send_http_header)
char *type = NULL;
int typelen;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &type, &typelen) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &type, &typelen) == FAILURE) {
return;
+ }
+
APREQ_GET_REQUEST(id, r);
if(type) {
r->content_type = pstrdup(r->pool, type);
@@ -988,6 +984,10 @@ PHP_FUNCTION(apache_request_basic_http_header)
zval *id;
request_rec *r;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
APREQ_GET_REQUEST(id, r);
ap_basic_http_header((request_rec *)SG(server_context));
@@ -1001,6 +1001,10 @@ PHP_FUNCTION(apache_request_send_http_trace)
zval *id;
request_rec *r;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
APREQ_GET_REQUEST(id, r);
ap_send_http_trace((request_rec *)SG(server_context));
@@ -1014,6 +1018,10 @@ PHP_FUNCTION(apache_request_send_http_options)
zval *id;
request_rec *r;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
APREQ_GET_REQUEST(id, r);
ap_send_http_options((request_rec *)SG(server_context));
@@ -1024,43 +1032,32 @@ PHP_FUNCTION(apache_request_send_http_options)
PHP_FUNCTION(apache_request_send_error_response)
{
- zval **recursive;
zval *id;
request_rec *r;
- int rec;
-
- switch(ZEND_NUM_ARGS()) {
- case 0:
- rec = 0;
- break;
- case 1:
- if(zend_get_parameters_ex(1, &recursive) == FAILURE) {
- RETURN_FALSE;
- }
- convert_to_long_ex(recursive);
- rec = Z_LVAL_PP(recursive);
- break;
- default:
- WRONG_PARAM_COUNT;
- }
+ long rec = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &rec) == FAILURE) {
+ return;
+ }
+
APREQ_GET_REQUEST(id, r);
- ap_send_error_response(r, rec);
+ ap_send_error_response(r, (int) rec);
RETURN_TRUE;
}
PHP_FUNCTION(apache_request_set_content_length)
{
- zval **length;
+ long length;
zval *id;
request_rec *r;
- if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &length) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &length) == FAILURE) {
+ return;
+ }
+
APREQ_GET_REQUEST(id, r);
- convert_to_long_ex(length);
- ap_set_content_length(r, Z_LVAL_PP(length));
+ ap_set_content_length(r, length);
RETURN_TRUE;
}
@@ -1068,6 +1065,11 @@ PHP_FUNCTION(apache_request_set_keepalive)
{
zval *id;
request_rec *r;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
APREQ_GET_REQUEST(id, r);
ap_set_keepalive(r);
RETURN_TRUE;
@@ -1087,16 +1089,17 @@ PHP_FUNCTION(apache_request_send_fd_length)
/* These are for overriding default output behaviour */
PHP_FUNCTION(apache_request_rputs)
{
- zval **buffer;
+ char *buffer;
+ int buffer_len;
zval *id;
request_rec *r;
- if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &buffer) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buffer, &buffer_len) == FAILURE) {
+ return;
+ }
+
APREQ_GET_REQUEST(id, r);
- convert_to_string_ex(buffer);
- ap_rwrite(Z_STRVAL_PP(buffer), Z_STRLEN_PP(buffer), (request_rec*)SG(server_context));
+ ap_rwrite(buffer, buffer_len, (request_rec*)SG(server_context));
}
/* This stuff would be useful for custom POST handlers,
@@ -1130,30 +1133,17 @@ PHP_FUNCTION(apache_request_discard_request_body)
PHP_FUNCTION(apache_request_log_error)
{
zval *id;
- zval **z_errstr, **z_facility;
+ char *z_errstr;
+ int z_errstr_len;
+ long facility = APLOG_ERR;
request_rec *r;
- int facility = APLOG_ERR;
-
- switch(ZEND_NUM_ARGS()) {
- case 1:
- if(zend_get_parameters_ex(1, &z_errstr) == FAILURE) {
- RETURN_FALSE;
- }
- break;
- case 2:
- if(zend_get_parameters_ex(1, &z_errstr, &z_facility) == FAILURE) {
- RETURN_FALSE;
- }
- convert_to_long_ex(z_facility);
- facility = Z_LVAL_PP(z_facility);
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &z_errstr, &z_errstr_len, &facility) == FAILURE) {
+ return;
+ }
+
APREQ_GET_REQUEST(id, r);
- convert_to_string_ex(z_errstr);
- ap_log_error(APLOG_MARK, facility, r->server, "%s", Z_STRVAL_PP(z_errstr));
+ ap_log_error(APLOG_MARK, (int) facility, r->server, "%s", z_errstr);
RETURN_TRUE;
}
/* }}} */
@@ -1166,15 +1156,18 @@ PHP_FUNCTION(apache_request_log_error)
PHP_FUNCTION(apache_request_sub_req_lookup_uri)
{
zval *id;
- zval **file;
+ char *file;
+ int file_len;
request_rec *r, *sub_r;
- if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
+ return;
+ }
+
APREQ_GET_REQUEST(id, r);
- convert_to_string_ex(file);
- sub_r = ap_sub_req_lookup_uri(Z_STRVAL_PP(file), r);
- if(!sub_r) {
+ sub_r = ap_sub_req_lookup_uri(file, r);
+
+ if (!sub_r) {
RETURN_FALSE;
}
return_value = php_apache_request_new(sub_r);
@@ -1188,16 +1181,19 @@ PHP_FUNCTION(apache_request_sub_req_lookup_uri)
PHP_FUNCTION(apache_request_sub_req_lookup_file)
{
zval *id;
- zval **file;
+ char *file;
+ int file_len;
request_rec *r, *sub_r;
- if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
+ return;
+ }
+
APREQ_GET_REQUEST(id, r);
- convert_to_string_ex(file);
- sub_r = ap_sub_req_lookup_file(Z_STRVAL_PP(file), r);
- if(!sub_r) {
+
+ sub_r = ap_sub_req_lookup_file(file, r);
+
+ if (!sub_r) {
RETURN_FALSE;
}
return_value = php_apache_request_new(sub_r);
@@ -1211,17 +1207,19 @@ PHP_FUNCTION(apache_request_sub_req_lookup_file)
PHP_FUNCTION(apache_request_sub_req_method_uri)
{
zval *id;
- zval **file, **method;
+ char *file, *method;
+ int file_len, method_len;
request_rec *r, *sub_r;
- if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &method, &file) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &method, &method_len, &file, &file_len) == FAILURE) {
+ return;
+ }
+
APREQ_GET_REQUEST(id, r);
- convert_to_string_ex(method);
- convert_to_string_ex(file);
- sub_r = ap_sub_req_method_uri(Z_STRVAL_PP(method),Z_STRVAL_PP(file), r);
- if(!sub_r) {
+
+ sub_r = ap_sub_req_method_uri(method, file, r);
+
+ if (!sub_r) {
RETURN_FALSE;
}
return_value = php_apache_request_new(sub_r);
@@ -1238,9 +1236,14 @@ PHP_FUNCTION(apache_request_run)
request_rec *r;
int status;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
APREQ_GET_REQUEST(id, r);
- if(!r || ap_is_initial_req(r))
+ if (!r || ap_is_initial_req(r)) {
RETURN_FALSE;
+ }
status = ap_run_sub_req(r);
ap_destroy_sub_req(r);
RETURN_LONG(status);
@@ -1250,32 +1253,33 @@ PHP_FUNCTION(apache_request_run)
PHP_FUNCTION(apache_request_internal_redirect)
{
zval *id;
- zval **new_uri;
+ char *new_uri;
+ int new_uri_len;
request_rec *r;
- if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_uri) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &new_uri, &new_uri_len) == FAILURE) {
+ return;
+ }
+
APREQ_GET_REQUEST(id, r);
- convert_to_string_ex(new_uri);
- ap_internal_redirect(Z_STRVAL_PP(new_uri), r);
+
+ ap_internal_redirect(new_uri, r);
}
PHP_FUNCTION(apache_request_send_header_field)
{
- zval **fieldname;
- zval **fieldval;
+ char *fieldname, *fieldval;
+ int fieldname_len, fieldval_len;
zval *id;
request_rec *r;
- if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fieldname, &fieldval) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(fieldname);
- convert_to_string_ex(fieldval);
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &fieldname, &fieldname_len, &fieldval, &fieldval_len) == FAILURE) {
+ return;
+ }
+
APREQ_GET_REQUEST(id, r);
- ap_send_header_field(r, Z_STRVAL_PP(fieldname), Z_STRVAL_PP(fieldval));
+ ap_send_header_field(r, fieldname, fieldval);
SG(headers_sent) = 1;
AP(headers_sent) = 1;
}
@@ -1286,7 +1290,7 @@ PHP_FUNCTION(apache_request_send_header_field)
/* {{{ php_apache_request_class_functions
*/
-static zend_function_entry php_apache_request_class_functions[] = {
+const static zend_function_entry php_apache_request_class_functions[] = {
/* string slots */
PHP_FALIAS(args, apache_request_args, NULL)
PHP_FALIAS(boundary, apache_request_boundary, NULL)
@@ -1545,28 +1549,25 @@ PHP_FUNCTION(apache_child_terminate)
Get and set Apache request notes */
PHP_FUNCTION(apache_note)
{
- zval **arg_name, **arg_val;
+ char *arg_name, *arg_val = NULL;
+ int arg_name_len, arg_val_len;
char *note_val;
- int arg_count = ZEND_NUM_ARGS();
- if (arg_count<1 || arg_count>2 ||
- zend_get_parameters_ex(arg_count, &arg_name, &arg_val) ==FAILURE ) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &arg_name, &arg_name_len, &arg_val, &arg_val_len) == FAILURE) {
+ return;
}
-
- convert_to_string_ex(arg_name);
- note_val = (char *) table_get(((request_rec *)SG(server_context))->notes, (*arg_name)->value.str.val);
-
- if (arg_count == 2) {
- convert_to_string_ex(arg_val);
- table_set(((request_rec *)SG(server_context))->notes, (*arg_name)->value.str.val, (*arg_val)->value.str.val);
+
+ note_val = (char *) table_get(((request_rec *)SG(server_context))->notes, arg_name);
+
+ if (arg_val) {
+ table_set(((request_rec *)SG(server_context))->notes, arg_name, arg_val);
}
- if (note_val) {
- RETURN_STRING(note_val, 1);
- } else {
+ if (!note_val) {
RETURN_FALSE;
}
+
+ RETURN_STRING(note_val, 1);
}
/* }}} */
@@ -1711,23 +1712,25 @@ PHP_MINFO_FUNCTION(apache)
*/
PHP_FUNCTION(virtual)
{
- zval **filename;
+ char *filename;
+ int filename_len;
request_rec *rr = NULL;
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ return;
}
- convert_to_string_ex(filename);
-
- if (!(rr = sub_req_lookup_uri ((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
- php_error(E_WARNING, "Unable to include '%s' - URI lookup failed", (*filename)->value.str.val);
- if (rr) destroy_sub_req (rr);
+
+ if (!(rr = sub_req_lookup_uri (filename, ((request_rec *) SG(server_context))))) {
+ php_error(E_WARNING, "Unable to include '%s' - URI lookup failed", filename);
+ if (rr)
+ destroy_sub_req (rr);
RETURN_FALSE;
}
if (rr->status != 200) {
- php_error(E_WARNING, "Unable to include '%s' - error finding URI", (*filename)->value.str.val);
- if (rr) destroy_sub_req (rr);
+ php_error(E_WARNING, "Unable to include '%s' - error finding URI", filename);
+ if (rr)
+ destroy_sub_req (rr);
RETURN_FALSE;
}
@@ -1735,13 +1738,15 @@ PHP_FUNCTION(virtual)
php_header(TSRMLS_C);
if (run_sub_req(rr)) {
- php_error(E_WARNING, "Unable to include '%s' - request execution failed", (*filename)->value.str.val);
- if (rr) destroy_sub_req (rr);
+ php_error(E_WARNING, "Unable to include '%s' - request execution failed", filename);
+ if (rr)
+ destroy_sub_req (rr);
RETURN_FALSE;
- } else {
- if (rr) destroy_sub_req (rr);
- RETURN_TRUE;
- }
+ }
+
+ if (rr)
+ destroy_sub_req (rr);
+ RETURN_TRUE;
}
/* }}} */
@@ -1780,6 +1785,10 @@ static void apache_table_to_zval(table *t, int safe_mode, zval *return_value)
Fetch all HTTP request headers */
PHP_FUNCTION(apache_request_headers)
{
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
apache_table_to_zval(((request_rec *)SG(server_context))->headers_in, PG(safe_mode), return_value);
}
/* }}} */
@@ -1788,6 +1797,10 @@ PHP_FUNCTION(apache_request_headers)
Fetch all HTTP response headers */
PHP_FUNCTION(apache_response_headers)
{
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
apache_table_to_zval(((request_rec *) SG(server_context))->headers_out, 0, return_value);
}
/* }}} */
@@ -1806,7 +1819,9 @@ PHP_FUNCTION(apache_setenv)
}
while(top) {
- if(r->prev) r = r->prev;
+ if (r->prev) {
+ r = r->prev;
+ }
else break;
}
@@ -1819,20 +1834,22 @@ PHP_FUNCTION(apache_setenv)
Perform a partial request of the given URI to obtain information about it */
PHP_FUNCTION(apache_lookup_uri)
{
- zval **filename;
+ char *filename;
+ int filename_len;
request_rec *rr=NULL;
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ return;
}
- convert_to_string_ex(filename);
- if(!(rr = sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
- php_error(E_WARNING, "URI lookup failed", (*filename)->value.str.val);
+ if(!(rr = sub_req_lookup_uri(filename, ((request_rec *) SG(server_context))))) {
+ php_error(E_WARNING, "URI lookup failed", filename);
RETURN_FALSE;
}
+
object_init(return_value);
add_property_long(return_value,"status", rr->status);
+
if (rr->the_request) {
add_property_string(return_value,"the_request", rr->the_request, 1);
}
diff --git a/sapi/apache_hooks/php_apache_http.h b/sapi/apache_hooks/php_apache_http.h
index 2a030482f..23cf7fea6 100644
--- a/sapi/apache_hooks/php_apache_http.h
+++ b/sapi/apache_hooks/php_apache_http.h
@@ -11,7 +11,7 @@
#include "zend.h"
#include "zend_stack.h"
-#include "php_regex.h"
+#include "ext/ereg/php_regex.h"
#include "httpd.h"
#include "http_config.h"
diff --git a/sapi/apache_hooks/sapi_apache.c b/sapi/apache_hooks/sapi_apache.c
index f7ac1d765..6df3fc770 100644
--- a/sapi/apache_hooks/sapi_apache.c
+++ b/sapi/apache_hooks/sapi_apache.c
@@ -19,7 +19,7 @@
| Stig Bakken <ssb@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: sapi_apache.c,v 1.9.2.1.2.3 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: sapi_apache.c,v 1.9.2.1.2.1.2.2 2008/12/31 11:15:48 sebastian Exp $ */
#include "php_apache_http.h"
diff --git a/sapi/caudium/caudium.c b/sapi/caudium/caudium.c
index 3b7d85e5e..3ec0f4d8e 100644
--- a/sapi/caudium/caudium.c
+++ b/sapi/caudium/caudium.c
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: caudium.c,v 1.36.2.1.2.3 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: caudium.c,v 1.36.2.1.2.1.2.4 2008/12/31 11:15:48 sebastian Exp $ */
#include "php.h"
#ifdef HAVE_CAUDIUM
@@ -444,7 +444,7 @@ static void php_info_caudium(ZEND_MODULE_INFO_FUNC_ARGS)
{
/* char buf[512]; */
php_info_print_table_start();
- php_info_print_table_row(2, "SAPI module version", "$Id: caudium.c,v 1.36.2.1.2.3 2008/12/31 11:17:48 sebastian Exp $");
+ php_info_print_table_row(2, "SAPI module version", "$Id: caudium.c,v 1.36.2.1.2.1.2.4 2008/12/31 11:15:48 sebastian Exp $");
/* php_info_print_table_row(2, "Build date", Ns_InfoBuildDate());
php_info_print_table_row(2, "Config file path", Ns_InfoConfigFile());
php_info_print_table_row(2, "Error Log path", Ns_InfoErrorLog());
@@ -551,6 +551,7 @@ static sapi_module_struct caudium_sapi_module = {
sapi_caudium_register_variables, /* register server variables */
NULL, /* Log message */
NULL, /* Get request time */
+ NULL, /* Child terminate */
STANDARD_SAPI_MODULE_PROPERTIES
};
@@ -638,15 +639,6 @@ static void php_caudium_module_main(php_caudium_request *ureq)
THREADS_ALLOW();
#endif
-#ifdef VIRTUAL_DIR
- /* Change virtual directory, if the feature is enabled, which is
- * (almost) a requirement for PHP in Caudium. Might want to fail if it
- * isn't. Not a problem though, since it's on by default when using ZTS
- * which we require.
- */
- VCWD_CHDIR_FILE(THIS->filename->str);
-#endif
-
file_handle.type = ZEND_HANDLE_FILENAME;
file_handle.filename = THIS->filename->str;
file_handle.opened_path = NULL;
diff --git a/sapi/cgi/CHANGES b/sapi/cgi/CHANGES
new file mode 100755
index 000000000..de0b36907
--- /dev/null
+++ b/sapi/cgi/CHANGES
@@ -0,0 +1,34 @@
+In PHP5.3 all additional configure options (except --enable-cgi) are removed:
+
+ --enable-fastcgi CGI: If this is enabled, the cgi module will
+ be built with support for fastcgi also
+
+ Now fastcgi is always enabled
+
+ --disable-path-info-check CGI: If this is disabled, paths such as
+ /info.php/test?a=b will fail to work
+
+ Now it is enabled by default, but can be disabled
+ with ini directive "cgi.fix_pathinfo=0"
+
+ --enable-force-cgi-redirect
+ CGI: Enable the security check for internal server
+ redirects. You should use this if you are
+ running the CGI version with Apache
+
+ Now it is enabled by default, but can be disabled
+ with ini directive "cgi.force_redirect=0"
+
+ --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
+
+ This option had effect only with
+ --disable-path-info-check or "cgi.fix_pathinfo=0".
+ Seems it needs only for CGI configuration that
+ require each script start from "#! /usr/bin/php".
+
+ Now it is disabled by default, but can be enabled
+ with ini directive "cgi.discard_path=1".
+
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
index 6e1139966..32c62479a 100644
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: cgi_main.c,v 1.267.2.15.2.69 2009/01/19 18:17:59 dsp Exp $ */
+/* $Id: cgi_main.c,v 1.267.2.15.2.50.2.37 2009/01/19 18:17:32 dsp Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -80,12 +80,10 @@ int __riscosify_control = __RISCOSIFY_STRICT_UNIX_SPECS;
#include "php_getopt.h"
-#if PHP_FASTCGI
#include "fastcgi.h"
#ifndef PHP_WIN32
-/* XXX this will need to change later when threaded fastcgi is
- implemented. shane */
+/* XXX this will need to change later when threaded fastcgi is implemented. shane */
struct sigaction act, old_term, old_quit, old_int;
#endif
@@ -115,8 +113,6 @@ static int parent_waiting = 0;
static pid_t pgroup;
#endif
-#endif
-
#define PHP_MODE_STANDARD 1
#define PHP_MODE_HIGHLIGHT 2
#define PHP_MODE_INDENT 3
@@ -147,31 +143,45 @@ static const opt_struct OPTIONS[] = {
{'?', 0, "usage"},/* help alias (both '?' and 'usage') */
{'v', 0, "version"},
{'z', 1, "zend-extension"},
-#if PHP_FASTCGI
{'T', 1, "timing"},
-#endif
{'-', 0, NULL} /* end of args */
};
typedef struct _php_cgi_globals_struct {
zend_bool rfc2616_headers;
zend_bool nph;
- zend_bool check_shebang_line;
-#if ENABLE_PATHINFO_CHECK
zend_bool fix_pathinfo;
-#endif
-#if FORCE_CGI_REDIRECT
zend_bool force_redirect;
- char *redirect_status_env;
-#endif
-#if PHP_FASTCGI
+ zend_bool discard_path;
zend_bool fcgi_logging;
-# ifdef PHP_WIN32
+ char *redirect_status_env;
+#ifdef PHP_WIN32
zend_bool impersonate;
-# endif
#endif
+ HashTable user_config_cache;
} php_cgi_globals_struct;
+/* {{{ user_config_cache
+ *
+ * Key for each cache entry is dirname(PATH_TRANSLATED).
+ *
+ * NOTE: Each cache entry config_hash contains the combination from all user ini files found in
+ * the path starting from doc_root throught to dirname(PATH_TRANSLATED). There is no point
+ * storing per-file entries as it would not be possible to detect added / deleted entries
+ * between separate files.
+ */
+typedef struct _user_config_cache_entry {
+ time_t expires;
+ HashTable *user_config;
+} user_config_cache_entry;
+
+static void user_config_cache_entry_dtor(user_config_cache_entry *entry)
+{
+ zend_hash_destroy(entry->user_config);
+ free(entry->user_config);
+}
+/* }}} */
+
#ifdef ZTS
static int php_cgi_globals_id;
#define CGIG(v) TSRMG(php_cgi_globals_id, php_cgi_globals_struct *, v)
@@ -204,8 +214,8 @@ static int module_name_cmp(const void *a, const void *b TSRMLS_DC)
Bucket *f = *((Bucket **) a);
Bucket *s = *((Bucket **) b);
- return strcasecmp(((zend_module_entry *)f->pData)->name,
- ((zend_module_entry *)s->pData)->name);
+ return strcasecmp( ((zend_module_entry *)f->pData)->name,
+ ((zend_module_entry *)s->pData)->name);
}
static void print_modules(TSRMLS_D)
@@ -226,11 +236,10 @@ static int print_extension_info(zend_extension *ext, void *arg TSRMLS_DC)
return 0;
}
-static int extension_name_cmp(const zend_llist_element **f,
- const zend_llist_element **s TSRMLS_DC)
+static int extension_name_cmp(const zend_llist_element **f, const zend_llist_element **s TSRMLS_DC)
{
- return strcmp(((zend_extension *)(*f)->data)->name,
- ((zend_extension *)(*s)->data)->name);
+ return strcmp( ((zend_extension *)(*f)->data)->name,
+ ((zend_extension *)(*s)->data)->name);
}
static void print_extensions(TSRMLS_D)
@@ -256,7 +265,6 @@ static inline size_t sapi_cgibin_single_write(const char *str, uint str_length T
size_t ret;
#endif
-#if PHP_FASTCGI
if (fcgi_is_fastcgi()) {
fcgi_request *request = (fcgi_request*) SG(server_context);
long ret = fcgi_write(request, FCGI_STDOUT, str, str_length);
@@ -265,7 +273,7 @@ static inline size_t sapi_cgibin_single_write(const char *str, uint str_length T
}
return ret;
}
-#endif
+
#ifdef PHP_WRITE_STDOUT
ret = write(STDOUT_FILENO, str, str_length);
if (ret <= 0) return 0;
@@ -298,19 +306,17 @@ static int sapi_cgibin_ub_write(const char *str, uint str_length TSRMLS_DC)
static void sapi_cgibin_flush(void *server_context)
{
-#if PHP_FASTCGI
if (fcgi_is_fastcgi()) {
fcgi_request *request = (fcgi_request*) server_context;
if (
#ifndef PHP_WIN32
- !parent &&
+ !parent &&
#endif
request && !fcgi_flush(request, 0)) {
php_handle_aborted_connection();
}
return;
}
-#endif
if (fflush(stdout) == EOF) {
php_handle_aborted_connection();
}
@@ -396,9 +402,10 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
char *s;
if (SG(sapi_headers).http_status_line &&
- (s = strchr(SG(sapi_headers).http_status_line, ' ')) != 0 &&
- (s - SG(sapi_headers).http_status_line) >= 5 &&
- strncasecmp(SG(sapi_headers).http_status_line, "HTTP/", 5) == 0) {
+ (s = strchr(SG(sapi_headers).http_status_line, ' ')) != 0 &&
+ (s - SG(sapi_headers).http_status_line) >= 5 &&
+ strncasecmp(SG(sapi_headers).http_status_line, "HTTP/", 5) == 0
+ ) {
len = slprintf(buf, sizeof(buf), "Status:%s\r\n", s);
response_status = atoi((s + 1));
} else {
@@ -468,17 +475,12 @@ static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
count_bytes = MIN(count_bytes, (uint) SG(request_info).content_length - SG(read_post_bytes));
while (read_bytes < count_bytes) {
-#if PHP_FASTCGI
if (fcgi_is_fastcgi()) {
fcgi_request *request = (fcgi_request*) SG(server_context);
tmp_read_bytes = fcgi_read(request, buffer + read_bytes, count_bytes - read_bytes);
} else {
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);
-#endif
-
if (tmp_read_bytes <= 0) {
break;
}
@@ -489,7 +491,6 @@ static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
static char *sapi_cgibin_getenv(char *name, size_t name_len TSRMLS_DC)
{
-#if PHP_FASTCGI
/* when php is started by mod_fastcgi, no regular environment
is provided to PHP. It is always sent to PHP at the start
of a request. So we have to do our own lookup to get env
@@ -498,7 +499,6 @@ static char *sapi_cgibin_getenv(char *name, size_t name_len TSRMLS_DC)
fcgi_request *request = (fcgi_request*) SG(server_context);
return fcgi_getenv(request, name, name_len);
}
-#endif
/* if cgi, or fastcgi and not found in fcgi env
check the regular environment */
return getenv(name);
@@ -517,7 +517,6 @@ static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC)
}
name_len = strlen(name);
-#if PHP_FASTCGI
/* when php is started by mod_fastcgi, no regular environment
is provided to PHP. It is always sent to PHP at the start
of a request. So we have to do our own lookup to get env
@@ -526,7 +525,7 @@ static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC)
fcgi_request *request = (fcgi_request*) SG(server_context);
return fcgi_putenv(request, name, name_len, value);
}
-#endif
+
#if HAVE_SETENV
if (value) {
setenv(name, value, 1);
@@ -540,7 +539,7 @@ static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC)
#if !HAVE_SETENV || !HAVE_UNSETENV
/* if cgi, or fastcgi and not found in fcgi env
- check the regular environment
+ check the regular environment
this leaks, but it's only cgi anyway, we'll fix
it for 5.0
*/
@@ -570,29 +569,30 @@ static char *sapi_cgi_read_cookies(TSRMLS_D)
return sapi_cgibin_getenv((char *) "HTTP_COOKIE", sizeof("HTTP_COOKIE")-1 TSRMLS_CC);
}
-#if PHP_FASTCGI
void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC)
{
if (PG(http_globals)[TRACK_VARS_ENV] &&
- array_ptr != PG(http_globals)[TRACK_VARS_ENV] &&
- Z_TYPE_P(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY &&
- zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV])) > 0) {
- zval_dtor(array_ptr);
- *array_ptr = *PG(http_globals)[TRACK_VARS_ENV];
- INIT_PZVAL(array_ptr);
- zval_copy_ctor(array_ptr);
- return;
+ array_ptr != PG(http_globals)[TRACK_VARS_ENV] &&
+ Z_TYPE_P(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY &&
+ zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV])) > 0
+ ) {
+ zval_dtor(array_ptr);
+ *array_ptr = *PG(http_globals)[TRACK_VARS_ENV];
+ INIT_PZVAL(array_ptr);
+ zval_copy_ctor(array_ptr);
+ return;
} else if (PG(http_globals)[TRACK_VARS_SERVER] &&
array_ptr != PG(http_globals)[TRACK_VARS_SERVER] &&
- Z_TYPE_P(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
- zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])) > 0) {
- zval_dtor(array_ptr);
- *array_ptr = *PG(http_globals)[TRACK_VARS_SERVER];
- INIT_PZVAL(array_ptr);
- zval_copy_ctor(array_ptr);
- return;
+ Z_TYPE_P(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
+ zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])) > 0
+ ) {
+ zval_dtor(array_ptr);
+ *array_ptr = *PG(http_globals)[TRACK_VARS_SERVER];
+ INIT_PZVAL(array_ptr);
+ zval_copy_ctor(array_ptr);
+ return;
}
-
+
/* call php's original import as a catch-all */
php_php_import_environment_variables(array_ptr TSRMLS_CC);
@@ -607,11 +607,13 @@ void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC)
/* turn off magic_quotes while importing environment variables */
PG(magic_quotes_gpc) = 0;
- for (zend_hash_internal_pointer_reset_ex(&request->env, &pos);
- zend_hash_get_current_key_ex(&request->env, &var, &var_len, &idx, 0, &pos) == HASH_KEY_IS_STRING &&
- zend_hash_get_current_data_ex(&request->env, (void **) &val, &pos) == SUCCESS;
- zend_hash_move_forward_ex(&request->env, &pos)) {
+ for (zend_hash_internal_pointer_reset_ex(request->env, &pos);
+ zend_hash_get_current_key_ex(request->env, &var, &var_len, &idx, 0, &pos) == HASH_KEY_IS_STRING &&
+ zend_hash_get_current_data_ex(request->env, (void **) &val, &pos) == SUCCESS;
+ zend_hash_move_forward_ex(request->env, &pos)
+ ) {
unsigned int new_val_len;
+
if (sapi_module.input_filter(filter_arg, var, val, strlen(*val), &new_val_len TSRMLS_CC)) {
php_register_variable_safe(var, *val, new_val_len, array_ptr TSRMLS_CC);
}
@@ -619,7 +621,6 @@ void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC)
PG(magic_quotes_gpc) = magic_quotes_gpc;
}
}
-#endif
static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC)
{
@@ -631,15 +632,15 @@ static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC)
*/
php_import_environment_variables(track_vars_array TSRMLS_CC);
-#if ENABLE_PATHINFO_CHECK
if (CGIG(fix_pathinfo)) {
- char *script_name = SG(request_info).request_uri;
+ char *script_name = SG(request_info).request_uri;
unsigned int script_name_len = script_name ? strlen(script_name) : 0;
- char *path_info = sapi_cgibin_getenv("PATH_INFO", sizeof("PATH_INFO")-1 TSRMLS_CC);
+ char *path_info = sapi_cgibin_getenv("PATH_INFO", sizeof("PATH_INFO")-1 TSRMLS_CC);
unsigned int path_info_len = path_info ? strlen(path_info) : 0;
php_self_len = script_name_len + path_info_len;
php_self = emalloc(php_self_len + 1);
+
if (script_name) {
memcpy(php_self, script_name, script_name_len + 1);
}
@@ -652,27 +653,24 @@ static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC)
php_register_variable_safe("PHP_SELF", php_self, php_self_len, track_vars_array TSRMLS_CC);
}
efree(php_self);
- return;
- }
-#endif
-
- php_self = SG(request_info).request_uri ? SG(request_info).request_uri : "";
- php_self_len = strlen(php_self);
- if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, php_self_len, &php_self_len TSRMLS_CC)) {
- php_register_variable_safe("PHP_SELF", php_self, php_self_len, track_vars_array TSRMLS_CC);
+ } else {
+ php_self = SG(request_info).request_uri ? SG(request_info).request_uri : "";
+ php_self_len = strlen(php_self);
+ if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, php_self_len, &php_self_len TSRMLS_CC)) {
+ php_register_variable_safe("PHP_SELF", php_self, php_self_len, track_vars_array TSRMLS_CC);
+ }
}
}
static void sapi_cgi_log_message(char *message)
{
-#if PHP_FASTCGI
TSRMLS_FETCH();
if (fcgi_is_fastcgi() && CGIG(fcgi_logging)) {
fcgi_request *request;
-
+
request = (fcgi_request*) SG(server_context);
- if (request) {
+ if (request) {
int len = strlen(message);
char *buf = malloc(len+2);
@@ -684,20 +682,127 @@ static void sapi_cgi_log_message(char *message)
fprintf(stderr, "%s\n", message);
}
/* ignore return code */
- } else
-#endif /* PHP_FASTCGI */
- fprintf(stderr, "%s\n", message);
+ } else {
+ fprintf(stderr, "%s\n", message);
+ }
+}
+
+/* {{{ php_cgi_ini_activate_user_config
+ */
+static void php_cgi_ini_activate_user_config(char *path, int path_len, int start TSRMLS_DC)
+{
+ char *ptr;
+ user_config_cache_entry *new_entry, *entry;
+ time_t request_time = sapi_get_request_time(TSRMLS_C);
+
+ /* Find cached config entry: If not found, create one */
+ if (zend_hash_find(&CGIG(user_config_cache), path, path_len + 1, (void **) &entry) == FAILURE) {
+ new_entry = pemalloc(sizeof(user_config_cache_entry), 1);
+ new_entry->expires = 0;
+ new_entry->user_config = (HashTable *) pemalloc(sizeof(HashTable), 1);
+ zend_hash_init(new_entry->user_config, 0, NULL, (dtor_func_t) config_zval_dtor, 1);
+ zend_hash_update(&CGIG(user_config_cache), path, path_len + 1, new_entry, sizeof(user_config_cache_entry), (void **) &entry);
+ free(new_entry);
+ }
+
+ /* Check whether cache entry has expired and rescan if it is */
+ if (request_time > entry->expires) {
+
+ /* Clear the expired config */
+ zend_hash_clean(entry->user_config);
+
+ /* Walk through each directory and apply entries to user_config hash */
+ ptr = path + start; /* start is the point where doc_root ends! */
+ while ((ptr = strchr(ptr, DEFAULT_SLASH)) != NULL) {
+ *ptr = 0;
+ php_parse_user_ini_file(path, PG(user_ini_filename), entry->user_config TSRMLS_CC);
+ *ptr = '/';
+ ptr++;
+ }
+ entry->expires = request_time + PG(user_ini_cache_ttl);
+ }
+
+ /* Activate ini entries with values from the user config hash */
+ php_ini_activate_config(entry->user_config, PHP_INI_PERDIR, PHP_INI_STAGE_HTACCESS TSRMLS_CC);
+}
+/* }}} */
+
+static int sapi_cgi_activate(TSRMLS_D)
+{
+ char *path, *doc_root, *server_name;
+ uint path_len, doc_root_len;
+
+ /* PATH_TRANSLATED should be defined at this stage but better safe than sorry :) */
+ if (!SG(request_info).path_translated) {
+ return FAILURE;
+ }
+
+ if (php_ini_has_per_host_config()) {
+ /* Activate per-host-system-configuration defined in php.ini and stored into configuration_hash during startup */
+ server_name = sapi_cgibin_getenv("SERVER_NAME", sizeof("SERVER_NAME") - 1 TSRMLS_CC);
+ /* SERVER_NAME should also be defined at this stage..but better check it anyway */
+ if (server_name) {
+ php_ini_activate_per_host_config(server_name, strlen(server_name) + 1 TSRMLS_CC);
+ }
+ }
+
+ if (php_ini_has_per_dir_config() ||
+ (PG(user_ini_filename) && *PG(user_ini_filename))) {
+ /* Prepare search path */
+ path_len = strlen(SG(request_info).path_translated);
+
+ /* Make sure we have trailing slash! */
+ if (!IS_SLASH(SG(request_info).path_translated[path_len])) {
+ path = emalloc(path_len + 2);
+ memcpy(path, SG(request_info).path_translated, path_len + 1);
+ path_len = zend_dirname(path, path_len);
+ path[path_len++] = DEFAULT_SLASH;
+ } else {
+ path = estrndup(SG(request_info).path_translated, path_len);
+ path_len = zend_dirname(path, path_len);
+ }
+ path[path_len] = 0;
+
+ /* Activate per-dir-system-configuration defined in php.ini and stored into configuration_hash during startup */
+ php_ini_activate_per_dir_config(path, path_len TSRMLS_CC); /* Note: for global settings sake we check from root to path */
+
+ /* Load and activate user ini files in path starting from DOCUMENT_ROOT */
+ if (PG(user_ini_filename) && *PG(user_ini_filename)) {
+ doc_root = sapi_cgibin_getenv("DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT") - 1 TSRMLS_CC);
+ /* DOCUMENT_ROOT should also be defined at this stage..but better check it anyway */
+ if (doc_root) {
+ doc_root_len = strlen(doc_root);
+ if (doc_root[doc_root_len - 1] == '/') {
+ --doc_root_len;
+ }
+ php_cgi_ini_activate_user_config(path, path_len, doc_root_len - 1 TSRMLS_CC);
+ }
+ }
+
+ efree(path);
+ }
+
+ return SUCCESS;
}
static int sapi_cgi_deactivate(TSRMLS_D)
{
/* flush only when SAPI was started. The reasons are:
1. SAPI Deactivate is called from two places: module init and request shutdown
- 2. When the first call occurs and the request is not set up, flush fails on
- FastCGI.
+ 2. When the first call occurs and the request is not set up, flush fails on FastCGI.
*/
if (SG(sapi_started)) {
- sapi_cgibin_flush(SG(server_context));
+ if (fcgi_is_fastcgi()) {
+ if (
+#ifndef PHP_WIN32
+ !parent &&
+#endif
+ !fcgi_finish_request((fcgi_request*)SG(server_context), 0)) {
+ php_handle_aborted_connection();
+ }
+ } else {
+ sapi_cgibin_flush(SG(server_context));
+ }
}
return SUCCESS;
}
@@ -710,22 +815,16 @@ static int php_cgi_startup(sapi_module_struct *sapi_module)
return SUCCESS;
}
-
/* {{{ sapi_module_struct cgi_sapi_module
*/
static sapi_module_struct cgi_sapi_module = {
-#if PHP_FASTCGI
"cgi-fcgi", /* name */
"CGI/FastCGI", /* pretty name */
-#else
- "cgi", /* name */
- "CGI", /* pretty name */
-#endif
php_cgi_startup, /* startup */
php_module_shutdown_wrapper, /* shutdown */
- NULL, /* activate */
+ sapi_cgi_activate, /* activate */
sapi_cgi_deactivate, /* deactivate */
sapi_cgibin_ub_write, /* unbuffered write */
@@ -745,11 +844,23 @@ static sapi_module_struct cgi_sapi_module = {
sapi_cgi_register_variables, /* register server variables */
sapi_cgi_log_message, /* Log message */
NULL, /* Get request time */
+ NULL, /* Child terminate */
STANDARD_SAPI_MODULE_PROPERTIES
};
/* }}} */
+/* {{{ arginfo ext/standard/dl.c */
+ZEND_BEGIN_ARG_INFO(arginfo_dl, 0)
+ ZEND_ARG_INFO(0, extension_filename)
+ZEND_END_ARG_INFO()
+/* }}} */
+
+static const zend_function_entry additional_functions[] = {
+ ZEND_FE(dl, arginfo_dl)
+ {NULL, NULL, NULL}
+};
+
/* {{{ php_cgi_usage
*/
static void php_cgi_usage(char *argv0)
@@ -763,32 +874,27 @@ static void php_cgi_usage(char *argv0)
prog = "php";
}
- php_printf("Usage: %s [-q] [-h] [-s] [-v] [-i] [-f <file>]\n"
- " %s <file> [args...]\n"
- " -a Run interactively\n"
-#if PHP_FASTCGI
- " -b <address:port>|<port> Bind Path for external FASTCGI Server mode\n"
-#endif
- " -C Do not chdir to the script's directory\n"
- " -c <path>|<file> Look for php.ini file in this directory\n"
- " -n No php.ini file will be used\n"
- " -d foo[=bar] Define INI entry foo with value 'bar'\n"
- " -e Generate extended information for debugger/profiler\n"
- " -f <file> Parse <file>. Implies `-q'\n"
- " -h This help\n"
- " -i PHP information\n"
- " -l Syntax check only (lint)\n"
- " -m Show compiled in modules\n"
- " -q Quiet-mode. Suppress HTTP Header output.\n"
- " -s Display colour syntax highlighted source.\n"
- " -v Version number\n"
- " -w Display source with stripped comments and whitespace.\n"
- " -z <file> Load Zend extension <file>.\n"
-#if PHP_FASTCGI
- " -T <count> Measure execution time of script repeated <count> times.\n"
-#endif
- ,
- prog, prog);
+ php_printf( "Usage: %s [-q] [-h] [-s] [-v] [-i] [-f <file>]\n"
+ " %s <file> [args...]\n"
+ " -a Run interactively\n"
+ " -b <address:port>|<port> Bind Path for external FASTCGI Server mode\n"
+ " -C Do not chdir to the script's directory\n"
+ " -c <path>|<file> Look for php.ini file in this directory\n"
+ " -n No php.ini file will be used\n"
+ " -d foo[=bar] Define INI entry foo with value 'bar'\n"
+ " -e Generate extended information for debugger/profiler\n"
+ " -f <file> Parse <file>. Implies `-q'\n"
+ " -h This help\n"
+ " -i PHP information\n"
+ " -l Syntax check only (lint)\n"
+ " -m Show compiled in modules\n"
+ " -q Quiet-mode. Suppress HTTP Header output.\n"
+ " -s Display colour syntax highlighted source.\n"
+ " -v Version number\n"
+ " -w Display source with stripped comments and whitespace.\n"
+ " -z <file> Load Zend extension <file>.\n"
+ " -T <count> Measure execution time of script repeated <count> times.\n",
+ prog, prog);
}
/* }}} */
@@ -833,14 +939,14 @@ static int is_valid_path(const char *path)
for:
PATH_INFO
- derived from the portion of the URI path following
+ derived from the portion of the URI path following
the script name but preceding any query data
may be empty
PATH_TRANSLATED
- derived by taking any path-info component of the
- request URI and performing any virtual-to-physical
- translation appropriate to map it onto the server's
+ derived by taking any path-info component of the
+ request URI and performing any virtual-to-physical
+ translation appropriate to map it onto the server's
document repository structure
empty if PATH_INFO is empty
@@ -851,13 +957,13 @@ static int is_valid_path(const char *path)
SCRIPT_NAME
set to a URL path that could identify the CGI script
- rather than the interpreter. PHP_SELF is set to this.
+ rather than the interpreter. PHP_SELF is set to this
REQUEST_URI
uri section following the domain:port part of a URI
SCRIPT_FILENAME
- The virtual-to-physical translation of SCRIPT_NAME (as per
+ The virtual-to-physical translation of SCRIPT_NAME (as per
PATH_TRANSLATED)
These settings are documented at
@@ -865,29 +971,29 @@ static int is_valid_path(const char *path)
Based on the following URL request:
-
- http://localhost/info.php/test?a=b
-
+
+ http://localhost/info.php/test?a=b
+
should produce, which btw is the same as if
we were running under mod_cgi on apache (ie. not
using ScriptAlias directives):
-
+
PATH_INFO=/test
PATH_TRANSLATED=/docroot/test
SCRIPT_NAME=/info.php
REQUEST_URI=/info.php/test?a=b
SCRIPT_FILENAME=/docroot/info.php
QUERY_STRING=a=b
-
+
but what we get is (cgi/mod_fastcgi under apache):
-
+
PATH_INFO=/info.php/test
PATH_TRANSLATED=/docroot/info.php/test
SCRIPT_NAME=/php/php-cgi (from the Action setting I suppose)
REQUEST_URI=/info.php/test?a=b
SCRIPT_FILENAME=/path/to/php/bin/php-cgi (Action setting translated)
QUERY_STRING=a=b
-
+
Comments in the code below refer to using the above URL in a request
*/
@@ -897,14 +1003,12 @@ static void init_request_info(TSRMLS_D)
char *env_path_translated = sapi_cgibin_getenv("PATH_TRANSLATED", sizeof("PATH_TRANSLATED")-1 TSRMLS_CC);
char *script_path_translated = env_script_filename;
-#if !DISCARD_PATH
/* some broken servers do not have script_filename or argv0
an example, IIS configured in some ways. then they do more
broken stuff and set path_translated to the cgi script location */
if (!script_path_translated && env_path_translated) {
script_path_translated = env_path_translated;
}
-#endif
/* initialize the defaults */
SG(request_info).path_translated = NULL;
@@ -926,43 +1030,43 @@ static void init_request_info(TSRMLS_D)
char *content_type = sapi_cgibin_getenv("CONTENT_TYPE", sizeof("CONTENT_TYPE")-1 TSRMLS_CC);
char *env_path_info = sapi_cgibin_getenv("PATH_INFO", sizeof("PATH_INFO")-1 TSRMLS_CC);
char *env_script_name = sapi_cgibin_getenv("SCRIPT_NAME", sizeof("SCRIPT_NAME")-1 TSRMLS_CC);
-#if ENABLE_PATHINFO_CHECK
- struct stat st;
- char *env_redirect_url = sapi_cgibin_getenv("REDIRECT_URL", sizeof("REDIRECT_URL")-1 TSRMLS_CC);
- char *env_document_root = sapi_cgibin_getenv("DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT")-1 TSRMLS_CC);
- int script_path_translated_len;
/* Hack for buggy IIS that sets incorrect PATH_INFO */
char *env_server_software = sapi_cgibin_getenv("SERVER_SOFTWARE", sizeof("SERVER_SOFTWARE")-1 TSRMLS_CC);
if (env_server_software &&
- env_script_name &&
- env_path_info &&
- strncmp(env_server_software, "Microsoft-IIS", sizeof("Microsoft-IIS")-1) == 0 &&
- strncmp(env_path_info, env_script_name, strlen(env_script_name)) == 0) {
+ env_script_name &&
+ env_path_info &&
+ strncmp(env_server_software, "Microsoft-IIS", sizeof("Microsoft-IIS")-1) == 0 &&
+ strncmp(env_path_info, env_script_name, strlen(env_script_name)) == 0
+ ) {
env_path_info = _sapi_cgibin_putenv("ORIG_PATH_INFO", env_path_info TSRMLS_CC);
- env_path_info += strlen(env_script_name);
- if (*env_path_info == 0) {
- env_path_info = NULL;
- }
+ env_path_info += strlen(env_script_name);
+ if (*env_path_info == 0) {
+ env_path_info = NULL;
+ }
env_path_info = _sapi_cgibin_putenv("PATH_INFO", env_path_info TSRMLS_CC);
}
if (CGIG(fix_pathinfo)) {
+ struct stat st;
char *real_path = NULL;
+ char *env_redirect_url = sapi_cgibin_getenv("REDIRECT_URL", sizeof("REDIRECT_URL")-1 TSRMLS_CC);
+ char *env_document_root = sapi_cgibin_getenv("DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT")-1 TSRMLS_CC);
char *orig_path_translated = env_path_translated;
char *orig_path_info = env_path_info;
char *orig_script_name = env_script_name;
char *orig_script_filename = env_script_filename;
+ int script_path_translated_len;
if (!env_document_root && PG(doc_root)) {
env_document_root = _sapi_cgibin_putenv("DOCUMENT_ROOT", PG(doc_root) TSRMLS_CC);
/* fix docroot */
TRANSLATE_SLASHES(env_document_root);
- }
+ }
- if (env_path_translated != NULL && env_redirect_url != NULL &&
- orig_script_filename != NULL && script_path_translated != NULL) {
- /*
+ if (env_path_translated != NULL && env_redirect_url != NULL &&
+ orig_script_filename != NULL && script_path_translated != NULL) {
+ /*
pretty much apache specific. If we have a redirect_url
then our script_filename and script_name point to the
php executable
@@ -977,7 +1081,7 @@ static void init_request_info(TSRMLS_D)
__riscosify_control |= __RISCOSIFY_DONT_CHECK_DIR;
script_path_translated = __unixify(script_path_translated, 0, NULL, 1, 0);
#endif
-
+
/*
* if the file doesn't exist, try to extract PATH_INFO out
* of it by stat'ing back through the '/'
@@ -989,7 +1093,8 @@ static void init_request_info(TSRMLS_D)
#ifdef PHP_WIN32
script_path_translated[script_path_translated_len-1] == '\\' ||
#endif
- (real_path = tsrm_realpath(script_path_translated, NULL TSRMLS_CC)) == NULL)) {
+ (real_path = tsrm_realpath(script_path_translated, NULL TSRMLS_CC)) == NULL)
+ ) {
char *pt = estrndup(script_path_translated, script_path_translated_len);
int len = script_path_translated_len;
char *ptr;
@@ -1053,7 +1158,7 @@ static void init_request_info(TSRMLS_D)
int l = strlen(env_document_root);
int path_translated_len = 0;
char *path_translated = NULL;
-
+
if (l && env_document_root[l - 1] == '/') {
--l;
}
@@ -1073,11 +1178,11 @@ static void init_request_info(TSRMLS_D)
path_translated[path_translated_len] = '\0';
if (orig_path_translated) {
_sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC);
- }
+ }
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)
+ } else if ( env_script_name &&
+ strstr(pt, env_script_name)
) {
/* PATH_TRANSLATED = PATH_TRANSLATED - SCRIPT_NAME + PATH_INFO */
int ptlen = strlen(pt) - strlen(env_script_name);
@@ -1092,7 +1197,7 @@ static void init_request_info(TSRMLS_D)
path_translated[path_translated_len] = '\0';
if (orig_path_translated) {
_sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC);
- }
+ }
env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED", path_translated TSRMLS_CC);
efree(path_translated);
}
@@ -1121,7 +1226,7 @@ static void init_request_info(TSRMLS_D)
} else {
SG(request_info).request_uri = orig_script_name;
}
- }
+ }
if (pt) {
efree(pt);
}
@@ -1139,12 +1244,12 @@ static void init_request_info(TSRMLS_D)
script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", script_path_translated TSRMLS_CC);
}
if (env_redirect_url) {
- if (orig_path_info) {
+ if (orig_path_info) {
_sapi_cgibin_putenv("ORIG_PATH_INFO", orig_path_info TSRMLS_CC);
_sapi_cgibin_putenv("PATH_INFO", NULL TSRMLS_CC);
}
if (orig_path_translated) {
- _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC);
+ _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC);
_sapi_cgibin_putenv("PATH_TRANSLATED", NULL TSRMLS_CC);
}
}
@@ -1162,30 +1267,26 @@ static void init_request_info(TSRMLS_D)
free(real_path);
}
} else {
-#endif
/* pre 4.3 behaviour, shouldn't be used but provides BC */
if (env_path_info) {
SG(request_info).request_uri = env_path_info;
} else {
SG(request_info).request_uri = env_script_name;
}
-#if !DISCARD_PATH
- if (env_path_translated) {
+ if (!CGIG(discard_path) && env_path_translated) {
script_path_translated = env_path_translated;
}
-#endif
if (is_valid_path(script_path_translated)) {
SG(request_info).path_translated = estrdup(script_path_translated);
}
-#if ENABLE_PATHINFO_CHECK
}
-#endif
+
SG(request_info).request_method = sapi_cgibin_getenv("REQUEST_METHOD", sizeof("REQUEST_METHOD")-1 TSRMLS_CC);
/* FIXME - Work out proto_num here */
SG(request_info).query_string = sapi_cgibin_getenv("QUERY_STRING", sizeof("QUERY_STRING")-1 TSRMLS_CC);
SG(request_info).content_type = (content_type ? content_type : "" );
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", sizeof("HTTP_AUTHORIZATION")-1 TSRMLS_CC);
php_handle_auth_data(auth TSRMLS_CC);
@@ -1193,7 +1294,7 @@ static void init_request_info(TSRMLS_D)
}
/* }}} */
-#if PHP_FASTCGI && !defined(PHP_WIN32)
+#ifndef PHP_WIN32
/**
* Clean up child processes upon exit
*/
@@ -1219,19 +1320,13 @@ void fastcgi_cleanup(int signal)
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("cgi.rfc2616_headers", "0", PHP_INI_ALL, OnUpdateBool, rfc2616_headers, php_cgi_globals_struct, php_cgi_globals)
STD_PHP_INI_ENTRY("cgi.nph", "0", PHP_INI_ALL, OnUpdateBool, nph, php_cgi_globals_struct, php_cgi_globals)
- STD_PHP_INI_ENTRY("cgi.check_shebang_line", "1", PHP_INI_SYSTEM, OnUpdateBool, check_shebang_line, php_cgi_globals_struct, php_cgi_globals)
-#if FORCE_CGI_REDIRECT
STD_PHP_INI_ENTRY("cgi.force_redirect", "1", PHP_INI_SYSTEM, OnUpdateBool, force_redirect, php_cgi_globals_struct, php_cgi_globals)
STD_PHP_INI_ENTRY("cgi.redirect_status_env", NULL, PHP_INI_SYSTEM, OnUpdateString, redirect_status_env, php_cgi_globals_struct, php_cgi_globals)
-#endif
-#if ENABLE_PATHINFO_CHECK
STD_PHP_INI_ENTRY("cgi.fix_pathinfo", "1", PHP_INI_SYSTEM, OnUpdateBool, fix_pathinfo, php_cgi_globals_struct, php_cgi_globals)
-#endif
-#if PHP_FASTCGI
+ STD_PHP_INI_ENTRY("cgi.discard_path", "0", PHP_INI_SYSTEM, OnUpdateBool, discard_path, php_cgi_globals_struct, php_cgi_globals)
STD_PHP_INI_ENTRY("fastcgi.logging", "1", PHP_INI_SYSTEM, OnUpdateBool, fcgi_logging, php_cgi_globals_struct, php_cgi_globals)
-# ifdef PHP_WIN32
+#ifdef PHP_WIN32
STD_PHP_INI_ENTRY("fastcgi.impersonate", "0", PHP_INI_SYSTEM, OnUpdateBool, impersonate, php_cgi_globals_struct, php_cgi_globals)
-# endif
#endif
PHP_INI_END()
@@ -1241,20 +1336,15 @@ static void php_cgi_globals_ctor(php_cgi_globals_struct *php_cgi_globals TSRMLS_
{
php_cgi_globals->rfc2616_headers = 0;
php_cgi_globals->nph = 0;
- php_cgi_globals->check_shebang_line = 1;
-#if FORCE_CGI_REDIRECT
php_cgi_globals->force_redirect = 1;
php_cgi_globals->redirect_status_env = NULL;
-#endif
-#if ENABLE_PATHINFO_CHECK
php_cgi_globals->fix_pathinfo = 1;
-#endif
-#if PHP_FASTCGI
+ php_cgi_globals->discard_path = 0;
php_cgi_globals->fcgi_logging = 1;
-# ifdef PHP_WIN32
+#ifdef PHP_WIN32
php_cgi_globals->impersonate = 0;
-# endif
#endif
+ zend_hash_init(&php_cgi_globals->user_config_cache, 0, NULL, (dtor_func_t) user_config_cache_entry_dtor, 1);
}
/* }}} */
@@ -1276,6 +1366,8 @@ static PHP_MINIT_FUNCTION(cgi)
*/
static PHP_MSHUTDOWN_FUNCTION(cgi)
{
+ zend_hash_destroy(&CGIG(user_config_cache));
+
UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
@@ -1291,17 +1383,13 @@ static PHP_MINFO_FUNCTION(cgi)
static zend_module_entry cgi_module_entry = {
STANDARD_MODULE_HEADER,
-#if PHP_FASTCGI
"cgi-fcgi",
-#else
- "cgi",
-#endif
- NULL,
- PHP_MINIT(cgi),
- PHP_MSHUTDOWN(cgi),
- NULL,
- NULL,
- PHP_MINFO(cgi),
+ NULL,
+ PHP_MINIT(cgi),
+ PHP_MSHUTDOWN(cgi),
+ NULL,
+ NULL,
+ PHP_MINFO(cgi),
NO_VERSION_YET,
STANDARD_MODULE_PROPERTIES
};
@@ -1314,22 +1402,21 @@ int main(int argc, char *argv[])
int exit_status = SUCCESS;
int cgi = 0, c, i, len;
zend_file_handle file_handle;
- int retval = FAILURE;
char *s;
-/* temporary locals */
+
+ /* 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 ini_entries_len = 0;
+ /* end of temporary locals */
-/* end of temporary locals */
#ifdef ZTS
void ***tsrm_ls;
#endif
-#if PHP_FASTCGI
int max_requests = 500;
int requests = 0;
int fastcgi = fcgi_is_fastcgi();
@@ -1346,7 +1433,6 @@ int main(int argc, char *argv[])
#ifndef PHP_WIN32
int status = 0;
#endif
-#endif /* PHP_FASTCGI */
#if 0 && defined(PHP_DEBUG)
/* IIS is always making things more difficult. This allows
@@ -1385,23 +1471,19 @@ int main(int argc, char *argv[])
setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */
#endif
-#if PHP_FASTCGI
if (!fastcgi) {
-#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")
- ) {
- cgi = 1;
- }
-#if PHP_FASTCGI
+ /* Make sure we detect we are a cgi - a bit redundancy here,
+ but the default case is that we have to check only the first one. */
+ if (getenv("SERVER_SOFTWARE") ||
+ getenv("SERVER_NAME") ||
+ getenv("GATEWAY_INTERFACE") ||
+ getenv("REQUEST_METHOD")
+ ) {
+ cgi = 1;
+ }
}
-#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, 2)) != -1) {
switch (c) {
case 'c':
if (cgi_sapi_module.php_ini_path_override) {
@@ -1412,7 +1494,7 @@ int main(int argc, char *argv[])
case 'n':
cgi_sapi_module.php_ini_ignore = 1;
break;
- case 'd': {
+ case 'd': {
/* define ini entries on command line */
int len = strlen(php_optarg);
char *val;
@@ -1443,7 +1525,6 @@ int main(int argc, char *argv[])
}
break;
}
-#if PHP_FASTCGI
/* if we're started on command line, check to see if
we are being started as an 'external' fastcgi
server by accepting a bindpath parameter. */
@@ -1452,13 +1533,10 @@ int main(int argc, char *argv[])
bindpath = strdup(php_optarg);
}
break;
-#endif
case 's': /* generate highlighted HTML from source */
behavior = PHP_MODE_HIGHLIGHT;
break;
-
}
-
}
php_optind = orig_optind;
php_optarg = orig_optarg;
@@ -1468,6 +1546,9 @@ int main(int argc, char *argv[])
#endif
cgi_sapi_module.executable_location = argv[0];
+ if (!cgi && !fastcgi && !bindpath) {
+ cgi_sapi_module.additional_functions = additional_functions;
+ }
/* startup after we get the above ini override se we get things right */
if (cgi_sapi_module.startup(&cgi_sapi_module) == FAILURE) {
@@ -1477,7 +1558,6 @@ int main(int argc, char *argv[])
return FAILURE;
}
-#if FORCE_CGI_REDIRECT
/* check force_cgi after startup, so we have proper output */
if (cgi && CGIG(force_redirect)) {
/* Apache will generate REDIRECT_STATUS,
@@ -1486,12 +1566,12 @@ int main(int argc, char *argv[])
* http://www.koehntopp.de/php.
* -- kk@netuse.de
*/
- if (!getenv("REDIRECT_STATUS")
- && !getenv ("HTTP_REDIRECT_STATUS")
+ 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 */
- && (!CGIG(redirect_status_env) || !getenv(CGIG(redirect_status_env)))
- ) {
+ (!CGIG(redirect_status_env) || !getenv(CGIG(redirect_status_env)))
+ ) {
SG(sapi_headers).http_response_code = 400;
PUTS("<b>Security Alert!</b> The PHP CGI cannot be accessed directly.\n\n\
<p>This PHP CGI binary was compiled with force-cgi-redirect enabled. This\n\
@@ -1515,9 +1595,7 @@ consult the installation file that came with this distribution, or visit \n\
return FAILURE;
}
}
-#endif /* FORCE_CGI_REDIRECT */
-#if PHP_FASTCGI
if (bindpath) {
fcgi_fd = fcgi_listen(bindpath, 128);
if (fcgi_fd < 0) {
@@ -1529,7 +1607,6 @@ consult the installation file that came with this distribution, or visit \n\
}
fastcgi = fcgi_is_fastcgi();
}
-
if (fastcgi) {
/* How many times to run PHP scripts before dying */
if (getenv("PHP_FCGI_MAX_REQUESTS")) {
@@ -1579,8 +1656,9 @@ consult the installation file that came with this distribution, or visit \n\
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)) {
+ sigaction(SIGINT, &act, &old_int) ||
+ sigaction(SIGQUIT, &act, &old_quit)
+ ) {
perror("Can't set signals");
exit(1);
}
@@ -1650,14 +1728,12 @@ consult the installation file that came with this distribution, or visit \n\
#endif /* WIN32 */
}
-#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, 2)) != -1) {
switch (c) {
-#if PHP_FASTCGI
case 'T':
- benchmark = 1;
+ benchmark = 1;
repeats = atoi(php_optarg);
#ifdef HAVE_GETTIMEOFDAY
gettimeofday(&start, NULL);
@@ -1665,12 +1741,9 @@ consult the installation file that came with this distribution, or visit \n\
time(&start);
#endif
break;
-#endif
case 'h':
case '?':
-#if PHP_FASTCGI
fcgi_shutdown();
-#endif
no_headers = 1;
php_output_startup();
php_output_activate(TSRMLS_C);
@@ -1684,7 +1757,6 @@ consult the installation file that came with this distribution, or visit \n\
php_optind = orig_optind;
php_optarg = orig_optarg;
-#if PHP_FASTCGI
/* start of FAST CGI loop */
/* Initialise FastCGI request structure */
#ifdef PHP_WIN32
@@ -1695,378 +1767,325 @@ consult the installation file that came with this distribution, or visit \n\
}
#endif
while (!fastcgi || fcgi_accept_request(&request) >= 0) {
-#endif
+ SG(server_context) = (void *) &request;
+ init_request_info(TSRMLS_C);
+ CG(interactive) = 0;
-#if PHP_FASTCGI
- SG(server_context) = (void *) &request;
-#else
- SG(server_context) = (void *) 1; /* avoid server_context==NULL checks */
-#endif
- init_request_info(TSRMLS_C);
- CG(interactive) = 0;
+ if (!cgi && !fastcgi) {
+ while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
+ switch (c) {
- if (!cgi
-#if PHP_FASTCGI
- && !fastcgi
-#endif
- ) {
- while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) {
- switch (c) {
+ case 'a': /* interactive mode */
+ printf("Interactive mode enabled\n\n");
+ CG(interactive) = 1;
+ break;
- case 'a': /* interactive mode */
- printf("Interactive mode enabled\n\n");
- CG(interactive) = 1;
- break;
+ case 'C': /* don't chdir to the script directory */
+ SG(options) |= SAPI_OPTION_NO_CHDIR;
+ break;
- case 'C': /* don't chdir to the script directory */
- SG(options) |= SAPI_OPTION_NO_CHDIR;
- break;
+ case 'e': /* enable extended info output */
+ CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
+ break;
- case 'e': /* enable extended info output */
- CG(extended_info) = 1;
- break;
+ case 'f': /* parse file */
+ if (script_file) {
+ efree(script_file);
+ }
+ script_file = estrdup(php_optarg);
+ no_headers = 1;
+ break;
- case 'f': /* parse file */
- if (script_file) {
- efree(script_file);
- }
- script_file = estrdup(php_optarg);
- no_headers = 1;
- break;
+ case 'i': /* php info & quit */
+ if (script_file) {
+ efree(script_file);
+ }
+ if (php_request_startup(TSRMLS_C) == FAILURE) {
+ SG(server_context) = NULL;
+ php_module_shutdown(TSRMLS_C);
+ return FAILURE;
+ }
+ if (no_headers) {
+ SG(headers_sent) = 1;
+ SG(request_info).no_headers = 1;
+ }
+ php_print_info(0xFFFFFFFF TSRMLS_CC);
+ php_request_shutdown((void *) 0);
+ exit_status = 0;
+ goto out;
+
+ case 'l': /* syntax check mode */
+ no_headers = 1;
+ behavior = PHP_MODE_LINT;
+ break;
- case 'i': /* php info & quit */
- if (script_file) {
- efree(script_file);
- }
- if (php_request_startup(TSRMLS_C) == FAILURE) {
- SG(server_context) = NULL;
- php_module_shutdown(TSRMLS_C);
- return FAILURE;
- }
- if (no_headers) {
+ case 'm': /* list compiled in modules */
+ if (script_file) {
+ efree(script_file);
+ }
+ php_output_startup();
+ php_output_activate(TSRMLS_C);
SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- }
- php_print_info(0xFFFFFFFF TSRMLS_CC);
- php_request_shutdown((void *) 0);
- exit_status = 0;
- goto out;
-
- case 'l': /* syntax check mode */
- no_headers = 1;
- behavior = PHP_MODE_LINT;
- break;
-
- case 'm': /* list compiled in modules */
- if (script_file) {
- efree(script_file);
- }
- php_output_startup();
- php_output_activate(TSRMLS_C);
- SG(headers_sent) = 1;
- php_printf("[PHP Modules]\n");
- print_modules(TSRMLS_C);
- php_printf("\n[Zend Modules]\n");
- print_extensions(TSRMLS_C);
- php_printf("\n");
- php_end_ob_buffers(1 TSRMLS_CC);
- exit_status = 0;
- goto out;
+ php_printf("[PHP Modules]\n");
+ print_modules(TSRMLS_C);
+ php_printf("\n[Zend Modules]\n");
+ print_extensions(TSRMLS_C);
+ php_printf("\n");
+ php_end_ob_buffers(1 TSRMLS_CC);
+ exit_status = 0;
+ goto out;
#if 0 /* not yet operational, see also below ... */
- case '': /* generate indented source mode*/
- behavior=PHP_MODE_INDENT;
- break;
+ case '': /* generate indented source mode*/
+ behavior=PHP_MODE_INDENT;
+ break;
#endif
- case 'q': /* do not generate HTTP headers */
- no_headers = 1;
- break;
+ case 'q': /* do not generate HTTP headers */
+ no_headers = 1;
+ break;
- case 'v': /* show php version & quit */
- if (script_file) {
- efree(script_file);
- }
- no_headers = 1;
- if (php_request_startup(TSRMLS_C) == FAILURE) {
- SG(server_context) = NULL;
- php_module_shutdown(TSRMLS_C);
- return FAILURE;
- }
- if (no_headers) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- }
+ case 'v': /* show php version & quit */
+ if (script_file) {
+ efree(script_file);
+ }
+ no_headers = 1;
+ if (php_request_startup(TSRMLS_C) == FAILURE) {
+ SG(server_context) = NULL;
+ php_module_shutdown(TSRMLS_C);
+ return FAILURE;
+ }
+ if (no_headers) {
+ SG(headers_sent) = 1;
+ SG(request_info).no_headers = 1;
+ }
#if ZEND_DEBUG
- php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2009 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-2009 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-2009 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-2009 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
#endif
- php_request_shutdown((void *) 0);
- exit_status = 0;
- goto out;
+ php_request_shutdown((void *) 0);
+ exit_status = 0;
+ goto out;
- case 'w':
- behavior = PHP_MODE_STRIP;
- break;
+ case 'w':
+ behavior = PHP_MODE_STRIP;
+ break;
- case 'z': /* load extension file */
- zend_load_extension(php_optarg);
- break;
+ case 'z': /* load extension file */
+ zend_load_extension(php_optarg);
+ break;
- default:
- break;
+ default:
+ break;
+ }
}
- }
- if (script_file) {
- /* override path_translated if -f on command line */
- STR_FREE(SG(request_info).path_translated);
- SG(request_info).path_translated = script_file;
- /* before registering argv to module exchange the *new* argv[0] */
- /* we can achieve this without allocating more memory */
- SG(request_info).argc = argc - (php_optind - 1);
- SG(request_info).argv = &argv[php_optind - 1];
- SG(request_info).argv[0] = script_file;
- } else if (argc > php_optind) {
- /* file is on command line, but not in -f opt */
- STR_FREE(SG(request_info).path_translated);
- SG(request_info).path_translated = estrdup(argv[php_optind]);
- /* arguments after the file are considered script args */
- SG(request_info).argc = argc - php_optind;
- SG(request_info).argv = &argv[php_optind];
- }
+ if (script_file) {
+ /* override path_translated if -f on command line */
+ STR_FREE(SG(request_info).path_translated);
+ SG(request_info).path_translated = script_file;
+ /* before registering argv to module exchange the *new* argv[0] */
+ /* we can achieve this without allocating more memory */
+ SG(request_info).argc = argc - (php_optind - 1);
+ SG(request_info).argv = &argv[php_optind - 1];
+ SG(request_info).argv[0] = script_file;
+ } else if (argc > php_optind) {
+ /* file is on command line, but not in -f opt */
+ STR_FREE(SG(request_info).path_translated);
+ SG(request_info).path_translated = estrdup(argv[php_optind]);
+ /* arguments after the file are considered script args */
+ SG(request_info).argc = argc - php_optind;
+ SG(request_info).argv = &argv[php_optind];
+ }
- if (no_headers) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- }
+ if (no_headers) {
+ SG(headers_sent) = 1;
+ SG(request_info).no_headers = 1;
+ }
- /* all remaining arguments are part of the query string
- this section of code concatenates all remaining arguments
- into a single string, seperating args with a &
- this allows command lines like:
+ /* all remaining arguments are part of the query string
+ this section of code concatenates all remaining arguments
+ into a single string, seperating args with a &
+ this allows command lines like:
- test.php v1=test v2=hello+world!
- test.php "v1=test&v2=hello world!"
- test.php v1=test "v2=hello world!"
- */
- if (!SG(request_info).query_string && argc > php_optind) {
- int slen = strlen(PG(arg_separator).input);
- len = 0;
- for (i = php_optind; i < argc; i++) {
- if (i < (argc - 1)) {
- len += strlen(argv[i]) + slen;
- } else {
- len += strlen(argv[i]);
+ test.php v1=test v2=hello+world!
+ test.php "v1=test&v2=hello world!"
+ test.php v1=test "v2=hello world!"
+ */
+ if (!SG(request_info).query_string && argc > php_optind) {
+ int slen = strlen(PG(arg_separator).input);
+ len = 0;
+ for (i = php_optind; i < argc; i++) {
+ if (i < (argc - 1)) {
+ len += strlen(argv[i]) + slen;
+ } else {
+ len += strlen(argv[i]);
+ }
}
- }
- len += 2;
- s = malloc(len);
- *s = '\0'; /* we are pretending it came from the environment */
- for (i = php_optind; i < argc; i++) {
- strlcat(s, argv[i], len);
- if (i < (argc - 1)) {
- strlcat(s, PG(arg_separator).input, len);
+ len += 2;
+ s = malloc(len);
+ *s = '\0'; /* we are pretending it came from the environment */
+ for (i = php_optind; i < argc; i++) {
+ strlcat(s, argv[i], len);
+ if (i < (argc - 1)) {
+ strlcat(s, PG(arg_separator).input, len);
+ }
}
+ SG(request_info).query_string = s;
+ free_query_string = 1;
}
- SG(request_info).query_string = s;
- free_query_string = 1;
- }
- } /* end !cgi && !fastcgi */
-
- /*
- we never take stdin if we're (f)cgi, always
- rely on the web server giving us the info
- we need in the environment.
- */
- if (SG(request_info).path_translated || cgi
-#if PHP_FASTCGI
- || fastcgi
-#endif
- )
- {
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = SG(request_info).path_translated;
- file_handle.handle.fp = NULL;
- } else {
- file_handle.filename = "-";
- file_handle.type = ZEND_HANDLE_FP;
- file_handle.handle.fp = stdin;
- }
+ } /* end !cgi && !fastcgi */
- file_handle.opened_path = NULL;
- file_handle.free_filename = 0;
-
- /* request startup only after we've done all we can to
- get path_translated */
- if (php_request_startup(TSRMLS_C) == FAILURE) {
-#if PHP_FASTCGI
- if (fastcgi) {
- fcgi_finish_request(&request);
+ /*
+ we never take stdin if we're (f)cgi, always
+ rely on the web server giving us the info
+ we need in the environment.
+ */
+ if (SG(request_info).path_translated || cgi || fastcgi) {
+ file_handle.type = ZEND_HANDLE_FILENAME;
+ file_handle.filename = SG(request_info).path_translated;
+ file_handle.handle.fp = NULL;
+ } else {
+ file_handle.filename = "-";
+ file_handle.type = ZEND_HANDLE_FP;
+ file_handle.handle.fp = stdin;
}
-#endif
- SG(server_context) = NULL;
- php_module_shutdown(TSRMLS_C);
- return FAILURE;
- }
- if (no_headers) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- }
- /*
- at this point path_translated will be set if:
- 1. we are running from shell and got filename was there
- 2. we are running as cgi or fastcgi
- */
- retval = FAILURE;
- if (cgi || SG(request_info).path_translated) {
- if (!php_check_open_basedir(SG(request_info).path_translated TSRMLS_CC)) {
- retval = php_fopen_primary_script(&file_handle TSRMLS_CC);
- }
- }
- /*
- if we are unable to open path_translated and we are not
- running from shell (so fp == NULL), then fail.
- */
- if (retval == FAILURE && file_handle.handle.fp == NULL) {
- if (errno == EACCES) {
- SG(sapi_headers).http_response_code = 403;
- PUTS("Access denied.\n");
- } else {
- SG(sapi_headers).http_response_code = 404;
- PUTS("No input file specified.\n");
+ file_handle.opened_path = NULL;
+ file_handle.free_filename = 0;
+
+ /* request startup only after we've done all we can to
+ get path_translated */
+ if (php_request_startup(TSRMLS_C) == FAILURE) {
+ if (fastcgi) {
+ fcgi_finish_request(&request, 1);
+ }
+ SG(server_context) = NULL;
+ php_module_shutdown(TSRMLS_C);
+ return FAILURE;
}
-#if PHP_FASTCGI
- /* we want to serve more requests if this is fastcgi
- so cleanup and continue, request shutdown is
- handled later */
- if (fastcgi) {
- goto fastcgi_request_done;
+ if (no_headers) {
+ SG(headers_sent) = 1;
+ SG(request_info).no_headers = 1;
}
-#endif
- STR_FREE(SG(request_info).path_translated);
+ /*
+ at this point path_translated will be set if:
+ 1. we are running from shell and got filename was there
+ 2. we are running as cgi or fastcgi
+ */
+ if (cgi || SG(request_info).path_translated) {
+ if (php_fopen_primary_script(&file_handle TSRMLS_CC) == FAILURE) {
+ if (errno == EACCES) {
+ SG(sapi_headers).http_response_code = 403;
+ PUTS("Access denied.\n");
+ } else {
+ SG(sapi_headers).http_response_code = 404;
+ PUTS("No input file specified.\n");
+ }
+ /* we want to serve more requests if this is fastcgi
+ so cleanup and continue, request shutdown is
+ handled later */
+ if (fastcgi) {
+ goto fastcgi_request_done;
+ }
- if (free_query_string && SG(request_info).query_string) {
- free(SG(request_info).query_string);
- SG(request_info).query_string = NULL;
- }
+ STR_FREE(SG(request_info).path_translated);
- php_request_shutdown((void *) 0);
- SG(server_context) = NULL;
- php_module_shutdown(TSRMLS_C);
- sapi_shutdown();
+ if (free_query_string && SG(request_info).query_string) {
+ free(SG(request_info).query_string);
+ SG(request_info).query_string = NULL;
+ }
+
+ php_request_shutdown((void *) 0);
+ SG(server_context) = NULL;
+ php_module_shutdown(TSRMLS_C);
+ sapi_shutdown();
#ifdef ZTS
- tsrm_shutdown();
+ tsrm_shutdown();
#endif
- return FAILURE;
- }
-
- if (CGIG(check_shebang_line) && file_handle.handle.fp && (file_handle.handle.fp != stdin)) {
- /* #!php support */
- c = fgetc(file_handle.handle.fp);
- if (c == '#') {
- while (c != '\n' && c != '\r' && c != EOF) {
- c = fgetc(file_handle.handle.fp); /* skip to end of line */
+ return FAILURE;
}
- /* handle situations where line is terminated by \r\n */
- if (c == '\r') {
- if (fgetc(file_handle.handle.fp) != '\n') {
- long pos = ftell(file_handle.handle.fp);
- fseek(file_handle.handle.fp, pos - 1, SEEK_SET);
- }
- }
- CG(start_lineno) = 2;
- } else {
- rewind(file_handle.handle.fp);
}
- }
-
- switch (behavior) {
- case PHP_MODE_STANDARD:
- php_execute_script(&file_handle TSRMLS_CC);
- break;
- case PHP_MODE_LINT:
- PG(during_request_startup) = 0;
- exit_status = php_lint_script(&file_handle TSRMLS_CC);
- if (exit_status == SUCCESS) {
- zend_printf("No syntax errors detected in %s\n", file_handle.filename);
- } else {
- zend_printf("Errors parsing %s\n", file_handle.filename);
- }
- break;
- case PHP_MODE_STRIP:
- if (open_file_for_scanning(&file_handle TSRMLS_CC) == SUCCESS) {
- zend_strip(TSRMLS_C);
- fclose(file_handle.handle.fp);
- php_end_ob_buffers(1 TSRMLS_CC);
- }
- return SUCCESS;
- break;
- case PHP_MODE_HIGHLIGHT:
- {
- zend_syntax_highlighter_ini syntax_highlighter_ini;
+ switch (behavior) {
+ case PHP_MODE_STANDARD:
+ php_execute_script(&file_handle TSRMLS_CC);
+ break;
+ case PHP_MODE_LINT:
+ PG(during_request_startup) = 0;
+ exit_status = php_lint_script(&file_handle TSRMLS_CC);
+ if (exit_status == SUCCESS) {
+ zend_printf("No syntax errors detected in %s\n", file_handle.filename);
+ } else {
+ zend_printf("Errors parsing %s\n", file_handle.filename);
+ }
+ break;
+ case PHP_MODE_STRIP:
if (open_file_for_scanning(&file_handle TSRMLS_CC) == SUCCESS) {
- php_get_highlight_struct(&syntax_highlighter_ini);
- zend_highlight(&syntax_highlighter_ini TSRMLS_CC);
-#if PHP_FASTCGI
- if (fastcgi) {
- goto fastcgi_request_done;
- }
-#endif
- fclose(file_handle.handle.fp);
+ zend_strip(TSRMLS_C);
+ zend_file_handle_dtor(&file_handle TSRMLS_CC);
php_end_ob_buffers(1 TSRMLS_CC);
}
return SUCCESS;
- }
- break;
+ break;
+ case PHP_MODE_HIGHLIGHT:
+ {
+ zend_syntax_highlighter_ini syntax_highlighter_ini;
+
+ if (open_file_for_scanning(&file_handle TSRMLS_CC) == SUCCESS) {
+ php_get_highlight_struct(&syntax_highlighter_ini);
+ zend_highlight(&syntax_highlighter_ini TSRMLS_CC);
+ if (fastcgi) {
+ goto fastcgi_request_done;
+ }
+ zend_file_handle_dtor(&file_handle TSRMLS_CC);
+ php_end_ob_buffers(1 TSRMLS_CC);
+ }
+ return SUCCESS;
+ }
+ break;
#if 0
- /* Zeev might want to do something with this one day */
- case PHP_MODE_INDENT:
- open_file_for_scanning(&file_handle TSRMLS_CC);
- zend_indent();
- fclose(file_handle.handle.fp);
- return SUCCESS;
- break;
+ /* Zeev might want to do something with this one day */
+ case PHP_MODE_INDENT:
+ open_file_for_scanning(&file_handle TSRMLS_CC);
+ zend_indent();
+ zend_file_handle_dtor(&file_handle TSRMLS_CC);
+ return SUCCESS;
+ break;
#endif
- }
+ }
-#if PHP_FASTCGI
fastcgi_request_done:
-#endif
- {
- char *path_translated;
-
- /* Go through this trouble so that the memory manager doesn't warn
- * about SG(request_info).path_translated leaking
- */
- if (SG(request_info).path_translated) {
- path_translated = strdup(SG(request_info).path_translated);
- STR_FREE(SG(request_info).path_translated);
- SG(request_info).path_translated = path_translated;
- }
+ {
+ char *path_translated;
+
+ /* Go through this trouble so that the memory manager doesn't warn
+ * about SG(request_info).path_translated leaking
+ */
+ if (SG(request_info).path_translated) {
+ path_translated = strdup(SG(request_info).path_translated);
+ STR_FREE(SG(request_info).path_translated);
+ SG(request_info).path_translated = path_translated;
+ }
- php_request_shutdown((void *) 0);
- if (exit_status == 0) {
- exit_status = EG(exit_status);
- }
+ php_request_shutdown((void *) 0);
+ if (exit_status == 0) {
+ exit_status = EG(exit_status);
+ }
- if (SG(request_info).path_translated) {
- free(SG(request_info).path_translated);
- SG(request_info).path_translated = NULL;
- }
- if (free_query_string && SG(request_info).query_string) {
- free(SG(request_info).query_string);
- SG(request_info).query_string = NULL;
+ if (SG(request_info).path_translated) {
+ free(SG(request_info).path_translated);
+ SG(request_info).path_translated = NULL;
+ }
+ if (free_query_string && SG(request_info).query_string) {
+ free(SG(request_info).query_string);
+ SG(request_info).query_string = NULL;
+ }
}
- }
-
-#if PHP_FASTCGI
if (!fastcgi) {
if (benchmark) {
repeats--;
@@ -2083,7 +2102,7 @@ fastcgi_request_done:
/* only fastcgi will get here */
requests++;
if (max_requests && (requests == max_requests)) {
- fcgi_finish_request(&request);
+ fcgi_finish_request(&request, 1);
if (bindpath) {
free(bindpath);
}
@@ -2096,7 +2115,6 @@ fastcgi_request_done:
/* end of fastcgi loop */
}
fcgi_shutdown();
-#endif
if (cgi_sapi_module.php_ini_path_override) {
free(cgi_sapi_module.php_ini_path_override);
@@ -2109,7 +2127,6 @@ fastcgi_request_done:
} zend_end_try();
out:
-#if PHP_FASTCGI
if (benchmark) {
int sec;
#ifdef HAVE_GETTIMEOFDAY
@@ -2130,7 +2147,6 @@ out:
fprintf(stderr, "\nElapsed time: %d sec\n", sec);
#endif
}
-#endif
#ifndef PHP_WIN32
parent_out:
@@ -2141,7 +2157,7 @@ parent_out:
sapi_shutdown();
#ifdef ZTS
- /*tsrm_shutdown();*/
+ tsrm_shutdown();
#endif
#if defined(PHP_WIN32) && ZEND_DEBUG && 0
diff --git a/sapi/cgi/config.w32 b/sapi/cgi/config.w32
index edd43eead..a6a54ad89 100644
--- a/sapi/cgi/config.w32
+++ b/sapi/cgi/config.w32
@@ -1,26 +1,10 @@
// vim:ft=javascript
-// $Id: config.w32,v 1.2.4.1.2.2 2006/09/28 09:37:52 dmitry Exp $
+// $Id: config.w32,v 1.2.4.1.2.2.2.3 2007/10/05 16:00:30 rrichards Exp $
ARG_ENABLE('cgi', 'Build CGI version of PHP', 'yes');
-ARG_ENABLE('fastcgi', 'Build FastCGI support into CGI binary', 'yes');
-ARG_ENABLE('path-info-check',
- 'If this is disabled, paths such as /info.php/test?a=b will fail to work', 'yes');
-
-ARG_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.", "yes");
-
-AC_DEFINE("FORCE_CGI_REDIRECT", PHP_FORCE_CGI_REDIRECT == "yes" ? 1 : 0, "CGI redirect mode");
-AC_DEFINE("ENABLE_PATHINFO_CHECK", PHP_PATH_INFO_CHECK == "yes" ? 1 : 0, "Pathinfo check");
if (PHP_CGI == "yes") {
- AC_DEFINE('PHP_FASTCGI', PHP_FASTCGI == "yes" ? 1 : 0);
ADD_FLAG("LDFLAGS_CGI", "/stack:8388608");
-
- if (PHP_FASTCGI == "yes") {
- SAPI('cgi', 'cgi_main.c getopt.c fastcgi.c', 'php-cgi.exe');
- ADD_FLAG('LIBS_CGI', 'ws2_32.lib kernel32.lib advapi32.lib');
- } else {
- SAPI('cgi', 'cgi_main.c getopt.c', 'php-cgi.exe');
- }
+ SAPI('cgi', 'cgi_main.c fastcgi.c', 'php-cgi.exe');
+ ADD_FLAG('LIBS_CGI', 'ws2_32.lib kernel32.lib advapi32.lib');
}
diff --git a/sapi/cgi/config9.m4 b/sapi/cgi/config9.m4
index 26ed76618..7aae33bf7 100644
--- a/sapi/cgi/config9.m4
+++ b/sapi/cgi/config9.m4
@@ -1,27 +1,10 @@
dnl
-dnl $Id: config9.m4,v 1.17.2.2.2.6 2007/07/11 23:20:36 jani Exp $
+dnl $Id: config9.m4,v 1.17.2.2.2.6.2.2 2007/10/01 12:40:54 jani Exp $
dnl
PHP_ARG_ENABLE(cgi,,
[ --disable-cgi Disable building CGI version of PHP], yes, no)
-PHP_ARG_ENABLE(fastcgi,,
-[ --enable-fastcgi CGI: Enable FastCGI support in the CGI binary], no, no)
-
-PHP_ARG_ENABLE(force-cgi-redirect,,
-[ --enable-force-cgi-redirect
- CGI: Enable security check for internal server
- redirects. Use this if you run the PHP CGI with Apache], no, no)
-
-PHP_ARG_ENABLE(discard-path,,
-[ --enable-discard-path CGI: When 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], no, no)
-
-PHP_ARG_ENABLE(path-info-check,,
-[ --disable-path-info-check CGI: If this is disabled, paths such as
- /info.php/test?a=b will fail to work], yes, no)
-
dnl
dnl CGI setup
dnl
@@ -29,6 +12,33 @@ if test "$PHP_SAPI" = "default"; then
AC_MSG_CHECKING(whether to build CGI binary)
if test "$PHP_CGI" != "no"; then
AC_MSG_RESULT(yes)
+
+ AC_MSG_CHECKING([for socklen_t in sys/socket.h])
+ AC_EGREP_HEADER([socklen_t], [sys/socket.h],
+ [AC_MSG_RESULT([yes])
+ AC_DEFINE([HAVE_SOCKLEN_T], [1],
+ [Define if the socklen_t typedef is in sys/socket.h])],
+ AC_MSG_RESULT([no]))
+
+ AC_MSG_CHECKING([for sun_len in sys/un.h])
+ AC_EGREP_HEADER([sun_len], [sys/un.h],
+ [AC_MSG_RESULT([yes])
+ AC_DEFINE([HAVE_SOCKADDR_UN_SUN_LEN], [1],
+ [Define if sockaddr_un in sys/un.h contains a sun_len component])],
+ AC_MSG_RESULT([no]))
+
+ AC_MSG_CHECKING([whether cross-process locking is required by accept()])
+ case "`uname -sr`" in
+ IRIX\ 5.* | SunOS\ 5.* | UNIX_System_V\ 4.0)
+ AC_MSG_RESULT([yes])
+ AC_DEFINE([USE_LOCKING], [1],
+ [Define if cross-process locking is required by accept()])
+ ;;
+ *)
+ AC_MSG_RESULT([no])
+ ;;
+ esac
+
PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/cgi/Makefile.frag)
dnl Set filename
@@ -42,51 +52,9 @@ if test "$PHP_SAPI" = "default"; then
esac
PHP_SUBST(SAPI_CGI_PATH)
- dnl --enable-fastcgi
- AC_MSG_CHECKING(whether to enable fastcgi support)
- if test "$PHP_FASTCGI" = "yes"; then
- PHP_ENABLE_FASTCGI=1
- PHP_FCGI_FILES="fastcgi.c"
- else
- PHP_ENABLE_FASTCGI=0
- PHP_FCGI_FILES=
- fi
- AC_DEFINE_UNQUOTED(PHP_FASTCGI, $PHP_ENABLE_FASTCGI, [ ])
- AC_MSG_RESULT($PHP_FASTCGI)
-
- dnl --enable-force-cgi-redirect
- AC_MSG_CHECKING(whether to force Apache CGI redirect)
- if test "$PHP_FORCE_CGI_REDIRECT" = "yes"; then
- CGI_REDIRECT=1
- else
- CGI_REDIRECT=0
- fi
- AC_DEFINE_UNQUOTED(FORCE_CGI_REDIRECT, $CGI_REDIRECT, [ ])
- AC_MSG_RESULT($PHP_FORCE_CGI_REDIRECT)
-
- dnl --enable-discard-path
- AC_MSG_CHECKING(whether to discard path_info + path_translated)
- if test "$PHP_DISCARD_PATH" = "yes"; then
- DISCARD_PATH=1
- else
- DISCARD_PATH=0
- fi
- AC_DEFINE_UNQUOTED(DISCARD_PATH, $DISCARD_PATH, [ ])
- AC_MSG_RESULT($PHP_DISCARD_PATH)
-
- dnl --enable-path-info-check
- AC_MSG_CHECKING(whether to enable path info checking)
- if test "$PHP_PATH_INFO_CHECK" = "yes"; then
- ENABLE_PATHINFO_CHECK=1
- else
- ENABLE_PATHINFO_CHECK=0
- fi
- AC_DEFINE_UNQUOTED(ENABLE_PATHINFO_CHECK, $ENABLE_PATHINFO_CHECK, [ ])
- AC_MSG_RESULT($PHP_PATH_INFO_CHECK)
-
dnl Set install target and select SAPI
INSTALL_IT="@echo \"Installing PHP CGI binary: \$(INSTALL_ROOT)\$(bindir)/\"; \$(INSTALL) -m 0755 \$(SAPI_CGI_PATH) \$(INSTALL_ROOT)\$(bindir)/\$(program_prefix)php-cgi\$(program_suffix)\$(EXEEXT)"
- PHP_SELECT_SAPI(cgi, program, $PHP_FCGI_FILES cgi_main.c getopt.c,, '$(SAPI_CGI_PATH)')
+ PHP_SELECT_SAPI(cgi, program, cgi_main.c fastcgi.c,, '$(SAPI_CGI_PATH)')
case $host_alias in
*aix*)
diff --git a/sapi/cgi/fastcgi.c b/sapi/cgi/fastcgi.c
index f94d82d17..ff8e880a8 100644
--- a/sapi/cgi/fastcgi.c
+++ b/sapi/cgi/fastcgi.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: fastcgi.c,v 1.4.2.13.2.35 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: fastcgi.c,v 1.4.2.13.2.28.2.11 2008/12/31 11:15:49 sebastian Exp $ */
#include "php.h"
#include "fastcgi.h"
@@ -267,63 +267,63 @@ void fcgi_shutdown(void)
*/
static PACL prepare_named_pipe_acl(PSECURITY_DESCRIPTOR sd, LPSECURITY_ATTRIBUTES sa)
{
- DWORD req_acl_size;
- char everyone_buf[32], owner_buf[32];
- PSID sid_everyone, sid_owner;
- SID_IDENTIFIER_AUTHORITY
- siaWorld = SECURITY_WORLD_SID_AUTHORITY,
- siaCreator = SECURITY_CREATOR_SID_AUTHORITY;
- PACL acl;
+ DWORD req_acl_size;
+ char everyone_buf[32], owner_buf[32];
+ PSID sid_everyone, sid_owner;
+ SID_IDENTIFIER_AUTHORITY
+ siaWorld = SECURITY_WORLD_SID_AUTHORITY,
+ siaCreator = SECURITY_CREATOR_SID_AUTHORITY;
+ PACL acl;
- sid_everyone = (PSID)&everyone_buf;
- sid_owner = (PSID)&owner_buf;
+ sid_everyone = (PSID)&everyone_buf;
+ sid_owner = (PSID)&owner_buf;
- req_acl_size = sizeof(ACL) +
- (2 * ((sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) + GetSidLengthRequired(1)));
+ req_acl_size = sizeof(ACL) +
+ (2 * ((sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) + GetSidLengthRequired(1)));
- acl = malloc(req_acl_size);
+ acl = malloc(req_acl_size);
- if (acl == NULL) {
- return NULL;
- }
+ if (acl == NULL) {
+ return NULL;
+ }
- if (!InitializeSid(sid_everyone, &siaWorld, 1)) {
- goto out_fail;
- }
- *GetSidSubAuthority(sid_everyone, 0) = SECURITY_WORLD_RID;
+ if (!InitializeSid(sid_everyone, &siaWorld, 1)) {
+ goto out_fail;
+ }
+ *GetSidSubAuthority(sid_everyone, 0) = SECURITY_WORLD_RID;
- if (!InitializeSid(sid_owner, &siaCreator, 1)) {
- goto out_fail;
- }
- *GetSidSubAuthority(sid_owner, 0) = SECURITY_CREATOR_OWNER_RID;
+ if (!InitializeSid(sid_owner, &siaCreator, 1)) {
+ goto out_fail;
+ }
+ *GetSidSubAuthority(sid_owner, 0) = SECURITY_CREATOR_OWNER_RID;
- if (!InitializeAcl(acl, req_acl_size, ACL_REVISION)) {
- goto out_fail;
- }
+ if (!InitializeAcl(acl, req_acl_size, ACL_REVISION)) {
+ goto out_fail;
+ }
- if (!AddAccessAllowedAce(acl, ACL_REVISION, FILE_GENERIC_READ | FILE_GENERIC_WRITE, sid_everyone)) {
- goto out_fail;
- }
+ if (!AddAccessAllowedAce(acl, ACL_REVISION, FILE_GENERIC_READ | FILE_GENERIC_WRITE, sid_everyone)) {
+ goto out_fail;
+ }
- if (!AddAccessAllowedAce(acl, ACL_REVISION, FILE_ALL_ACCESS, sid_owner)) {
- goto out_fail;
- }
+ if (!AddAccessAllowedAce(acl, ACL_REVISION, FILE_ALL_ACCESS, sid_owner)) {
+ goto out_fail;
+ }
- if (!InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION)) {
- goto out_fail;
- }
+ if (!InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION)) {
+ goto out_fail;
+ }
- if (!SetSecurityDescriptorDacl(sd, TRUE, acl, FALSE)) {
- goto out_fail;
- }
+ if (!SetSecurityDescriptorDacl(sd, TRUE, acl, FALSE)) {
+ goto out_fail;
+ }
- sa->lpSecurityDescriptor = sd;
+ sa->lpSecurityDescriptor = sd;
- return acl;
+ return acl;
out_fail:
- free(acl);
- return NULL;
+ free(acl);
+ return NULL;
}
#endif
@@ -397,9 +397,9 @@ int fcgi_listen(const char *path, int backlog)
}
} else {
#ifdef _WIN32
- SECURITY_DESCRIPTOR sd;
- SECURITY_ATTRIBUTES sa;
- PACL acl;
+ SECURITY_DESCRIPTOR sd;
+ SECURITY_ATTRIBUTES sa;
+ PACL acl;
HANDLE namedPipe;
memset(&sa, 0, sizeof(sa));
@@ -514,8 +514,8 @@ void fcgi_init_request(fcgi_request *req, int listen_socket)
req->in_len = 0;
req->in_pad = 0;
- req->out_hdr = NULL;
- req->out_pos = req->out_buf;
+ req->out_hdr = NULL;
+ req->out_pos = req->out_buf;
#ifdef _WIN32
req->tcp = !GetNamedPipeInfo((HANDLE)_get_osfhandle(req->listen_socket), NULL, NULL, NULL, NULL);
@@ -634,8 +634,8 @@ static int fcgi_get_params(fcgi_request *req, unsigned char *p, unsigned char *e
}
memcpy(tmp, p, name_len);
tmp[name_len] = 0;
- s = zend_strndup((char*)p + name_len, val_len);
- zend_hash_update(&req->env, tmp, name_len+1, &s, sizeof(char*), NULL);
+ s = estrndup((char*)p + name_len, val_len);
+ zend_hash_update(req->env, tmp, name_len+1, &s, sizeof(char*), NULL);
p += name_len + val_len;
}
if (tmp != buf && tmp != NULL) {
@@ -646,7 +646,7 @@ static int fcgi_get_params(fcgi_request *req, unsigned char *p, unsigned char *e
static void fcgi_free_var(char **s)
{
- free(*s);
+ efree(*s);
}
static int fcgi_read_request(fcgi_request *req)
@@ -656,10 +656,12 @@ static int fcgi_read_request(fcgi_request *req)
unsigned char buf[FCGI_MAX_LENGTH+8];
req->keep = 0;
+ req->closed = 0;
req->in_len = 0;
req->out_hdr = NULL;
req->out_pos = req->out_buf;
- zend_hash_init(&req->env, 0, NULL, (void (*)(void *)) fcgi_free_var, 1);
+ ALLOC_HASHTABLE(req->env);
+ zend_hash_init(req->env, 0, NULL, (void (*)(void *)) fcgi_free_var, 0);
if (safe_read(req, &hdr, sizeof(fcgi_header)) != sizeof(fcgi_header) ||
hdr.version < FCGI_VERSION_1) {
@@ -695,16 +697,16 @@ static int fcgi_read_request(fcgi_request *req)
req->keep = (((fcgi_begin_request*)buf)->flags & FCGI_KEEP_CONN);
switch ((((fcgi_begin_request*)buf)->roleB1 << 8) + ((fcgi_begin_request*)buf)->roleB0) {
case FCGI_RESPONDER:
- val = strdup("RESPONDER");
- zend_hash_update(&req->env, "FCGI_ROLE", sizeof("FCGI_ROLE"), &val, sizeof(char*), NULL);
+ val = estrdup("RESPONDER");
+ zend_hash_update(req->env, "FCGI_ROLE", sizeof("FCGI_ROLE"), &val, sizeof(char*), NULL);
break;
case FCGI_AUTHORIZER:
- val = strdup("AUTHORIZER");
- zend_hash_update(&req->env, "FCGI_ROLE", sizeof("FCGI_ROLE"), &val, sizeof(char*), NULL);
+ val = estrdup("AUTHORIZER");
+ zend_hash_update(req->env, "FCGI_ROLE", sizeof("FCGI_ROLE"), &val, sizeof(char*), NULL);
break;
case FCGI_FILTER:
- val = strdup("FILTER");
- zend_hash_update(&req->env, "FCGI_ROLE", sizeof("FCGI_ROLE"), &val, sizeof(char*), NULL);
+ val = estrdup("FILTER");
+ zend_hash_update(req->env, "FCGI_ROLE", sizeof("FCGI_ROLE"), &val, sizeof(char*), NULL);
break;
default:
return 0;
@@ -760,10 +762,10 @@ static int fcgi_read_request(fcgi_request *req)
return 0;
}
- zend_hash_internal_pointer_reset_ex(&req->env, &pos);
- while ((key_type = zend_hash_get_current_key_ex(&req->env, &str_index, &str_length, &num_index, 0, &pos)) != HASH_KEY_NON_EXISTANT) {
+ zend_hash_internal_pointer_reset_ex(req->env, &pos);
+ while ((key_type = zend_hash_get_current_key_ex(req->env, &str_index, &str_length, &num_index, 0, &pos)) != HASH_KEY_NON_EXISTANT) {
int zlen;
- zend_hash_move_forward_ex(&req->env, &pos);
+ zend_hash_move_forward_ex(req->env, &pos);
if (key_type != HASH_KEY_IS_STRING) {
continue;
}
@@ -865,8 +867,10 @@ int fcgi_read(fcgi_request *req, char *str, int len)
static inline void fcgi_close(fcgi_request *req, int force, int destroy)
{
- if (destroy) {
- zend_hash_destroy(&req->env);
+ if (destroy && req->env) {
+ zend_hash_destroy(req->env);
+ FREE_HASHTABLE(req->env);
+ req->env = NULL;
}
#ifdef _WIN32
@@ -912,7 +916,6 @@ int fcgi_accept_request(fcgi_request *req)
HANDLE pipe;
OVERLAPPED ov;
#endif
- fcgi_finish_request(req);
while (1) {
if (req->fd < 0) {
@@ -957,13 +960,13 @@ int fcgi_accept_request(fcgi_request *req)
int n = 0;
int allowed = 0;
- while (allowed_clients[n] != INADDR_NONE) {
- if (allowed_clients[n] == sa.sa_inet.sin_addr.s_addr) {
- allowed = 1;
- break;
- }
- n++;
- }
+ while (allowed_clients[n] != INADDR_NONE) {
+ if (allowed_clients[n] == sa.sa_inet.sin_addr.s_addr) {
+ allowed = 1;
+ break;
+ }
+ n++;
+ }
if (!allowed) {
fprintf(stderr, "Connection from disallowed IP address '%s' is dropped.\n", inet_ntoa(sa.sa_inet.sin_addr));
closesocket(req->fd);
@@ -1203,13 +1206,18 @@ int fcgi_write(fcgi_request *req, fcgi_request_type type, const char *str, int l
return len;
}
-int fcgi_finish_request(fcgi_request *req)
+int fcgi_finish_request(fcgi_request *req, int force_close)
{
+ int ret = 1;
+
if (req->fd >= 0) {
- fcgi_flush(req, 1);
- fcgi_close(req, 0, 1);
+ if (!req->closed) {
+ ret = fcgi_flush(req, 1);
+ req->closed = 1;
+ }
+ fcgi_close(req, force_close, 1);
}
- return 1;
+ return ret;
}
char* fcgi_getenv(fcgi_request *req, const char* var, int var_len)
@@ -1218,7 +1226,7 @@ char* fcgi_getenv(fcgi_request *req, const char* var, int var_len)
if (!req) return NULL;
- if (zend_hash_find(&req->env, (char*)var, var_len+1, (void**)&val) == SUCCESS) {
+ if (zend_hash_find(req->env, (char*)var, var_len+1, (void**)&val) == SUCCESS) {
return *val;
}
return NULL;
@@ -1228,12 +1236,12 @@ char* fcgi_putenv(fcgi_request *req, char* var, int var_len, char* val)
{
if (var && req) {
if (val == NULL) {
- zend_hash_del(&req->env, var, var_len+1);
+ zend_hash_del(req->env, var, var_len+1);
} else {
char **ret;
- val = strdup(val);
- if (zend_hash_update(&req->env, var, var_len+1, &val, sizeof(char*), (void**)&ret) == SUCCESS) {
+ val = estrdup(val);
+ if (zend_hash_update(req->env, var, var_len+1, &val, sizeof(char*), (void**)&ret) == SUCCESS) {
return *ret;
}
}
@@ -1253,7 +1261,7 @@ void fcgi_impersonate(void)
}
#endif
-void fcgi_set_mgmt_var(char * name, size_t name_len, const char * value, size_t value_len)
+void fcgi_set_mgmt_var(const char * name, size_t name_len, const char * value, size_t value_len)
{
zval * zvalue;
zvalue = pemalloc(sizeof(*zvalue), 1);
diff --git a/sapi/cgi/fastcgi.h b/sapi/cgi/fastcgi.h
index 6df318052..a3570b7bd 100644
--- a/sapi/cgi/fastcgi.h
+++ b/sapi/cgi/fastcgi.h
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: fastcgi.h,v 1.2.2.4.2.8 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: fastcgi.h,v 1.2.2.4.2.5.2.5 2008/12/31 11:15:49 sebastian Exp $ */
/* FastCGI protocol */
@@ -99,6 +99,7 @@ typedef struct _fcgi_request {
int fd;
int id;
int keep;
+ int closed;
int in_len;
int in_pad;
@@ -108,7 +109,7 @@ typedef struct _fcgi_request {
unsigned char out_buf[1024*8];
unsigned char reserved[sizeof(fcgi_end_request_rec)];
- HashTable env;
+ HashTable *env;
} fcgi_request;
int fcgi_init(void);
@@ -118,7 +119,7 @@ int fcgi_in_shutdown(void);
int fcgi_listen(const char *path, int backlog);
void fcgi_init_request(fcgi_request *req, int listen_socket);
int fcgi_accept_request(fcgi_request *req);
-int fcgi_finish_request(fcgi_request *req);
+int fcgi_finish_request(fcgi_request *req, int force_close);
char* fcgi_getenv(fcgi_request *req, const char* var, int var_len);
char* fcgi_putenv(fcgi_request *req, char* var, int var_len, char* val);
@@ -132,7 +133,7 @@ int fcgi_flush(fcgi_request *req, int close);
void fcgi_impersonate(void);
#endif
-void fcgi_set_mgmt_var(char * name, size_t name_len, const char * value, size_t value_len);
+void fcgi_set_mgmt_var(const char * name, size_t name_len, const char * value, size_t value_len);
void fcgi_free_mgmt_var_cb(void * ptr);
/*
diff --git a/sapi/cgi/getopt.c b/sapi/cgi/getopt.c
deleted file mode 100644
index 1e2182f32..000000000
--- a/sapi/cgi/getopt.c
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 5 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2009 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 3.01 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available through the world-wide-web at the following url: |
- | http://www.php.net/license/3_01.txt |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Marcus Boerger <helly@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id: getopt.c,v 1.9.2.1.2.6 2008/12/31 11:17:48 sebastian Exp $ */
-
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <stdlib.h>
-#include "php_getopt.h"
-#define OPTERRCOLON (1)
-#define OPTERRNF (2)
-#define OPTERRARG (3)
-
-
-static int php_opt_error(int argc, char * const *argv, int oint, int optchr, int err, int show_err)
-{
- if (show_err)
- {
- fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr+1);
- switch(err)
- {
- case OPTERRCOLON:
- fprintf(stderr, ": in flags\n");
- break;
- case OPTERRNF:
- fprintf(stderr, "option not found %c\n", argv[oint][optchr]);
- break;
- case OPTERRARG:
- fprintf(stderr, "no argument for option %c\n", argv[oint][optchr]);
- break;
- default:
- fprintf(stderr, "unknown\n");
- break;
- }
- }
- return('?');
-}
-
-int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err)
-{
- static int optchr = 0;
- static int dash = 0; /* have already seen the - */
- int arg_start = 2;
-
- int opts_idx = -1;
-
- if (*optind >= argc) {
- return(EOF);
- }
- if (!dash) {
- if ((argv[*optind][0] != '-')) {
- return(EOF);
- } else {
- if (!argv[*optind][1])
- {
- /*
- * use to specify stdin. Need to let pgm process this and
- * the following args
- */
- return(EOF);
- }
- }
- }
- if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) {
- /* '--' indicates end of args if not followed by a known long option name */
- if (argv[*optind][2] == '\0') {
- (*optind)++;
- return(EOF);
- }
-
- while (1) {
- opts_idx++;
- if (opts[opts_idx].opt_char == '-') {
- (*optind)++;
- return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err));
- } else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) {
- break;
- }
- }
- optchr = 0;
- dash = 0;
- arg_start = 2 + strlen(opts[opts_idx].opt_name);
- } else {
- if (!dash) {
- dash = 1;
- optchr = 1;
- }
- /* Check if the guy tries to do a -: kind of flag */
- if (argv[*optind][optchr] == ':') {
- dash = 0;
- (*optind)++;
- return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err));
- }
- arg_start = 1 + optchr;
- }
- if (opts_idx < 0) {
- while (1) {
- opts_idx++;
- if (opts[opts_idx].opt_char == '-') {
- int errind = *optind;
- int errchr = optchr;
-
- if (!argv[*optind][optchr+1]) {
- dash = 0;
- (*optind)++;
- } else {
- optchr++;
- arg_start++;
- }
- return(php_opt_error(argc, argv, errind, errchr, OPTERRNF, show_err));
- } else if (argv[*optind][optchr] == opts[opts_idx].opt_char) {
- break;
- }
- }
- }
- if (opts[opts_idx].need_param) {
- /* Check for cases where the value of the argument
- is in the form -<arg> <val> or in the form -<arg><val> */
- dash = 0;
- if(!argv[*optind][arg_start]) {
- (*optind)++;
- if (*optind == argc) {
- return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err));
- }
- *optarg = argv[(*optind)++];
- } else {
- *optarg = &argv[*optind][arg_start];
- (*optind)++;
- }
- return opts[opts_idx].opt_char;
- } else {
- /* multiple options specified as one (exclude long opts) */
- if (arg_start >= 2 && !((argv[*optind][0] == '-') && (argv[*optind][1] == '-'))) {
- if (!argv[*optind][optchr+1])
- {
- dash = 0;
- (*optind)++;
- } else {
- optchr++;
- }
- } else {
- (*optind)++;
- }
- return opts[opts_idx].opt_char;
- }
- assert(0);
- return(0); /* never reached */
-}
diff --git a/sapi/cgi/php_getopt.h b/sapi/cgi/php_getopt.h
deleted file mode 100644
index ac6cf5123..000000000
--- a/sapi/cgi/php_getopt.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 5 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2009 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 3.01 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available through the world-wide-web at the following url: |
- | http://www.php.net/license/3_01.txt |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Marcus Boerger <helly@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id: php_getopt.h,v 1.7.2.1.2.4 2008/12/31 11:17:48 sebastian Exp $ */
-
-#include "php.h"
-
-#ifdef NETWARE
-/*
-As NetWare LibC has optind and optarg macros defined in unistd.h our local variables were getting mistakenly preprocessed so undeffing optind and optarg
-*/
-#undef optarg
-#undef optind
-#endif
-/* Define structure for one recognized option (both single char and long name).
- * If short_open is '-' this is the last option.
- */
-typedef struct _opt_struct {
- const char opt_char;
- const int need_param;
- const char * opt_name;
-} opt_struct;
-
-int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err);
diff --git a/sapi/cgi/tests/006.phpt b/sapi/cgi/tests/006.phpt
index 107ddc774..e183fea6b 100644
--- a/sapi/cgi/tests/006.phpt
+++ b/sapi/cgi/tests/006.phpt
@@ -42,7 +42,7 @@ class test
file_put_contents($filename, $code);
-var_dump(`"$php" -n -l "$filename" 2>/dev/null`);
+var_dump(`"$php" -l "$filename" 2>/dev/null`);
@unlink($filename);
diff --git a/sapi/cgi/tests/007.phpt b/sapi/cgi/tests/007.phpt
index 92bf0f6aa..f2c9c0226 100644
--- a/sapi/cgi/tests/007.phpt
+++ b/sapi/cgi/tests/007.phpt
@@ -12,11 +12,11 @@ reset_env_vars();
var_dump(`"$php" -n -f some.php -f some.php`);
var_dump(`"$php" -n -s -w -l`);
-echo "Done\n";
?>
+===DONE===
--EXPECTF--
string(25) "No input file specified.
"
string(31) "No syntax errors detected in -
"
-Done
+===DONE===
diff --git a/sapi/cgi/tests/011.phpt b/sapi/cgi/tests/011.phpt
new file mode 100644
index 000000000..177df021a
--- /dev/null
+++ b/sapi/cgi/tests/011.phpt
@@ -0,0 +1,165 @@
+--TEST--
+header_remove()
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--FILE--
+<?php
+
+include "include.inc";
+
+$php = get_cgi_path();
+reset_env_vars();
+
+$f = tempnam(sys_get_temp_dir(), 'cgitest');
+
+function test($script) {
+ file_put_contents($GLOBALS['f'], $script);
+ $cmd = escapeshellcmd($GLOBALS['php']);
+ $cmd .= ' -n -dreport_zend_debug=0 -dhtml_errors=0 ' . escapeshellarg($GLOBALS['f']);
+ echo "----------\n";
+ echo rtrim($script) . "\n";
+ echo "----------\n";
+ passthru($cmd);
+}
+
+test('<?php ?>');
+test('<?php header_remove(); ?>');
+test('<?php header_remove("X-Foo"); ?>');
+test('<?php
+header("X-Foo: Bar");
+?>');
+test('<?php
+header("X-Foo: Bar");
+header("X-Bar: Baz");
+header_remove("X-Foo");
+?>');
+test('<?php
+header("X-Foo: Bar");
+header_remove("X-Foo: Bar");
+?>');
+test('<?php
+header("X-Foo: Bar");
+header_remove("X-Foo:");
+?>');
+test('<?php
+header("X-Foo: Bar");
+header_remove();
+?>');
+test('<?php
+header_remove("");
+?>');
+test('<?php
+header_remove(":");
+?>');
+test('<?php
+header("X-Foo: Bar");
+echo "flush\n";
+flush();
+header_remove("X-Foo");
+?>');
+
+@unlink($f);
+?>
+--EXPECTF--
+----------
+<?php ?>
+----------
+X-Powered-By: PHP/%s
+Content-type: text/html
+
+----------
+<?php header_remove(); ?>
+----------
+Content-type: text/html
+
+----------
+<?php header_remove("X-Foo"); ?>
+----------
+X-Powered-By: PHP/%s
+Content-type: text/html
+
+----------
+<?php
+header("X-Foo: Bar");
+?>
+----------
+X-Powered-By: PHP/%s
+X-Foo: Bar
+Content-type: text/html
+
+----------
+<?php
+header("X-Foo: Bar");
+header("X-Bar: Baz");
+header_remove("X-Foo");
+?>
+----------
+X-Powered-By: PHP/%s
+X-Bar: Baz
+Content-type: text/html
+
+----------
+<?php
+header("X-Foo: Bar");
+header_remove("X-Foo: Bar");
+?>
+----------
+X-Powered-By: PHP/%s
+X-Foo: Bar
+Content-type: text/html
+
+
+Warning: Header to delete may not contain colon. in %s on line 3
+----------
+<?php
+header("X-Foo: Bar");
+header_remove("X-Foo:");
+?>
+----------
+X-Powered-By: PHP/%s
+X-Foo: Bar
+Content-type: text/html
+
+
+Warning: Header to delete may not contain colon. in %s on line 3
+----------
+<?php
+header("X-Foo: Bar");
+header_remove();
+?>
+----------
+Content-type: text/html
+
+----------
+<?php
+header_remove("");
+?>
+----------
+X-Powered-By: PHP/%s
+Content-type: text/html
+
+----------
+<?php
+header_remove(":");
+?>
+----------
+X-Powered-By: PHP/%s
+Content-type: text/html
+
+
+Warning: Header to delete may not contain colon. in %s on line 2
+----------
+<?php
+header("X-Foo: Bar");
+echo "flush\n";
+flush();
+header_remove("X-Foo");
+?>
+----------
+X-Powered-By: PHP/%s
+X-Foo: Bar
+Content-type: text/html
+
+flush
+
+Warning: Cannot modify header information - headers already sent by (output started at %s:3) in %s on line 5
diff --git a/sapi/cli/config.m4 b/sapi/cli/config.m4
index 104b1a733..e8043577e 100644
--- a/sapi/cli/config.m4
+++ b/sapi/cli/config.m4
@@ -1,5 +1,5 @@
dnl
-dnl $Id: config.m4,v 1.22.2.1.2.2 2008/09/01 13:15:15 dmitry Exp $
+dnl $Id: config.m4,v 1.22.2.1.2.1.2.1 2008/09/01 13:15:31 dmitry Exp $
dnl
PHP_ARG_ENABLE(cli,,
diff --git a/sapi/cli/config.w32 b/sapi/cli/config.w32
index 37b1ca6f1..f167828fc 100644
--- a/sapi/cli/config.w32
+++ b/sapi/cli/config.w32
@@ -1,12 +1,12 @@
// vim:ft=javascript
-// $Id: config.w32,v 1.4.4.1 2006/05/18 21:46:12 edink Exp $
+// $Id: config.w32,v 1.4.4.1.2.2 2007/10/05 16:00:30 rrichards Exp $
ARG_ENABLE('cli', 'Build CLI version of PHP', 'yes');
ARG_ENABLE('crt-debug', 'Extra CRT debugging', 'no');
ARG_ENABLE('cli-win32', 'Build console-less CLI version of PHP', 'no');
if (PHP_CLI == "yes") {
- SAPI('cli', 'getopt.c php_cli.c php_cli_readline.c', 'php.exe');
+ SAPI('cli', 'php_cli.c php_cli_readline.c', 'php.exe');
if (PHP_CRT_DEBUG == "yes") {
ADD_FLAG("CFLAGS_CLI", "/D PHP_WIN32_DEBUG_HEAP");
}
@@ -14,7 +14,7 @@ if (PHP_CLI == "yes") {
}
if (PHP_CLI_WIN32 == "yes") {
- SAPI('cli_win32', 'getopt.c cli_win32.c php_cli_readline.c', 'php-win.exe');
+ SAPI('cli_win32', 'cli_win32.c php_cli_readline.c', 'php-win.exe');
ADD_FLAG("LDFLAGS_CLI_WIN32", "/stack:8388608");
}
diff --git a/sapi/cli/getopt.c b/sapi/cli/getopt.c
deleted file mode 100644
index bf9012b52..000000000
--- a/sapi/cli/getopt.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 5 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2009 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 3.01 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available through the world-wide-web at the following url: |
- | http://www.php.net/license/3_01.txt |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Marcus Boerger <helly@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id: getopt.c,v 1.8.2.1.2.8 2008/12/31 11:17:49 sebastian Exp $ */
-
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <stdlib.h>
-#include "php_getopt.h"
-#define OPTERRCOLON (1)
-#define OPTERRNF (2)
-#define OPTERRARG (3)
-
-
-static int php_opt_error(int argc, char * const *argv, int oint, int optchr, int err, int show_err) /* {{{ */
-{
- if (show_err)
- {
- fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr+1);
- switch(err)
- {
- case OPTERRCOLON:
- fprintf(stderr, ": in flags\n");
- break;
- case OPTERRNF:
- fprintf(stderr, "option not found %c\n", argv[oint][optchr]);
- break;
- case OPTERRARG:
- fprintf(stderr, "no argument for option %c\n", argv[oint][optchr]);
- break;
- default:
- fprintf(stderr, "unknown\n");
- break;
- }
- }
- return('?');
-}
-/* }}} */
-
-int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err) /* {{{ */
-{
- static int optchr = 0;
- static int dash = 0; /* have already seen the - */
- int arg_start = 2;
-
- int opts_idx = -1;
-
- if (*optind >= argc) {
- return(EOF);
- }
- if (!dash) {
- if ((argv[*optind][0] != '-')) {
- return(EOF);
- } else {
- if (!argv[*optind][1])
- {
- /*
- * use to specify stdin. Need to let pgm process this and
- * the following args
- */
- return(EOF);
- }
- }
- }
- if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) {
- /* '--' indicates end of args if not followed by a known long option name */
- if (argv[*optind][2] == '\0') {
- (*optind)++;
- return(EOF);
- }
-
- while (1) {
- opts_idx++;
- if (opts[opts_idx].opt_char == '-') {
- (*optind)++;
- return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err));
- } else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) {
- break;
- }
- }
- optchr = 0;
- dash = 0;
- arg_start = 2 + strlen(opts[opts_idx].opt_name);
- } else {
- if (!dash) {
- dash = 1;
- optchr = 1;
- }
- /* Check if the guy tries to do a -: kind of flag */
- if (argv[*optind][optchr] == ':') {
- dash = 0;
- (*optind)++;
- return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err));
- }
- arg_start = 1 + optchr;
- }
- if (opts_idx < 0) {
- while (1) {
- opts_idx++;
- if (opts[opts_idx].opt_char == '-') {
- int errind = *optind;
- int errchr = optchr;
-
- if (!argv[*optind][optchr+1]) {
- dash = 0;
- (*optind)++;
- } else {
- optchr++;
- arg_start++;
- }
- return(php_opt_error(argc, argv, errind, errchr, OPTERRNF, show_err));
- } else if (argv[*optind][optchr] == opts[opts_idx].opt_char) {
- break;
- }
- }
- }
- if (opts[opts_idx].need_param) {
- /* Check for cases where the value of the argument
- is in the form -<arg> <val> or in the form -<arg><val> */
- dash = 0;
- if(!argv[*optind][arg_start]) {
- (*optind)++;
- if (*optind == argc) {
- return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err));
- }
- *optarg = argv[(*optind)++];
- } else {
- *optarg = &argv[*optind][arg_start];
- (*optind)++;
- }
- return opts[opts_idx].opt_char;
- } else {
- /* multiple options specified as one (exclude long opts) */
- if (arg_start >= 2 && !((argv[*optind][0] == '-') && (argv[*optind][1] == '-'))) {
- if (!argv[*optind][optchr+1])
- {
- dash = 0;
- (*optind)++;
- } else {
- optchr++;
- }
- } else {
- (*optind)++;
- }
- return opts[opts_idx].opt_char;
- }
- assert(0);
- return(0); /* never reached */
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
index 813485e43..bafd1a570 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_cli.c,v 1.129.2.13.2.30 2008/12/31 11:17:49 sebastian Exp $ */
+/* $Id: php_cli.c,v 1.129.2.13.2.22.2.21 2009/01/09 17:21:11 iliaa Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -111,13 +111,13 @@ PHPAPI extern char *php_ini_scanned_files;
#define PHP_MODE_REFLECTION_EXT_INFO 11
#define PHP_MODE_SHOW_INI_CONFIG 12
-#define HARDCODED_INI \
- "html_errors=0\n" \
- "register_argc_argv=1\n" \
- "implicit_flush=1\n" \
- "output_buffering=0\n" \
- "max_execution_time=0\n" \
- "max_input_time=-1\n"
+const char HARDCODED_INI[] =
+ "html_errors=0\n"
+ "register_argc_argv=1\n"
+ "implicit_flush=1\n"
+ "output_buffering=0\n"
+ "max_execution_time=0\n"
+ "max_input_time=-1\n\0";
static char *php_optarg = NULL;
static int php_optind = 1;
@@ -291,19 +291,35 @@ static char *script_filename = "";
static void sapi_cli_register_variables(zval *track_vars_array TSRMLS_DC) /* {{{ */
{
+ unsigned int len;
+ char *docroot = "";
+
/* In CGI mode, we consider the environment to be a part of the server
* variables
*/
php_import_environment_variables(track_vars_array TSRMLS_CC);
/* Build the special-case PHP_SELF variable for the CLI version */
- php_register_variable("PHP_SELF", php_self, track_vars_array TSRMLS_CC);
- php_register_variable("SCRIPT_NAME", php_self, track_vars_array TSRMLS_CC);
+ len = strlen(php_self);
+ if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, len, &len TSRMLS_CC)) {
+ php_register_variable("PHP_SELF", php_self, track_vars_array TSRMLS_CC);
+ }
+ if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_NAME", &php_self, len, &len TSRMLS_CC)) {
+ php_register_variable("SCRIPT_NAME", php_self, track_vars_array TSRMLS_CC);
+ }
/* filenames are empty for stdin */
- php_register_variable("SCRIPT_FILENAME", script_filename, track_vars_array TSRMLS_CC);
- php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array TSRMLS_CC);
+ len = strlen(script_filename);
+ if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_FILENAME", &script_filename, len, &len TSRMLS_CC)) {
+ php_register_variable("SCRIPT_FILENAME", script_filename, track_vars_array TSRMLS_CC);
+ }
+ if (sapi_module.input_filter(PARSE_SERVER, "PATH_TRANSLATED", &script_filename, len, &len TSRMLS_CC)) {
+ php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array TSRMLS_CC);
+ }
/* just make it available */
- php_register_variable("DOCUMENT_ROOT", "", track_vars_array TSRMLS_CC);
+ len = 0U;
+ if (sapi_module.input_filter(PARSE_SERVER, "DOCUMENT_ROOT", &docroot, len, &len TSRMLS_CC)) {
+ php_register_variable("DOCUMENT_ROOT", docroot, track_vars_array TSRMLS_CC);
+ }
}
/* }}} */
@@ -330,11 +346,8 @@ static char* sapi_cli_read_cookies(TSRMLS_D) /* {{{ */
}
/* }}} */
-static int sapi_cli_header_handler(sapi_header_struct *h, sapi_headers_struct *s TSRMLS_DC) /* {{{ */
+static int sapi_cli_header_handler(sapi_header_struct *h, sapi_header_op_enum op, sapi_headers_struct *s TSRMLS_DC) /* {{{ */
{
- /* free allocated header line */
- efree(h->header);
- /* avoid pushing headers into SAPI headers list */
return 0;
}
/* }}} */
@@ -365,20 +378,16 @@ static int php_cli_startup(sapi_module_struct *sapi_module) /* {{{ */
/* 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))
+ Z_SET_REFCOUNT(tmp, 0);\
+ Z_UNSET_ISREF(tmp); \
+ ZVAL_STRINGL(&tmp, zend_strndup(value, sizeof(value)-1), sizeof(value)-1, 0);\
+ zend_hash_update(configuration_hash, name, sizeof(name), &tmp, sizeof(zval), NULL);\
static void sapi_cli_ini_defaults(HashTable *configuration_hash)
{
- zval *tmp, *entry;
-
- MAKE_STD_ZVAL(tmp);
-
+ zval tmp;
INI_DEFAULT("report_zend_debug", "0");
INI_DEFAULT("display_errors", "1");
-
- FREE_ZVAL(tmp);
}
/* }}} */
@@ -411,11 +420,23 @@ static sapi_module_struct cli_sapi_module = {
sapi_cli_register_variables, /* register server variables */
sapi_cli_log_message, /* Log message */
NULL, /* Get request time */
+ NULL, /* Child terminate */
STANDARD_SAPI_MODULE_PROPERTIES
};
/* }}} */
+/* {{{ arginfo ext/standard/dl.c */
+ZEND_BEGIN_ARG_INFO(arginfo_dl, 0)
+ ZEND_ARG_INFO(0, extension_filename)
+ZEND_END_ARG_INFO()
+/* }}} */
+
+static const zend_function_entry additional_functions[] = {
+ ZEND_FE(dl, arginfo_dl)
+ {NULL, NULL, NULL}
+};
+
/* {{{ php_cli_usage
*/
static void php_cli_usage(char *argv0)
@@ -549,18 +570,22 @@ static const char *param_mode_conflict = "Either execute direct code, process st
*/
static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, int *lineno TSRMLS_DC)
{
- int c;
+ char c;
*lineno = 1;
+ file_handle->type = ZEND_HANDLE_FP;
+ file_handle->opened_path = NULL;
+ file_handle->free_filename = 0;
if (!(file_handle->handle.fp = VCWD_FOPEN(script_file, "rb"))) {
php_printf("Could not open input file: %s\n", script_file);
return FAILURE;
}
file_handle->filename = script_file;
+
/* #!php support */
c = fgetc(file_handle->handle.fp);
- if (c == '#') {
+ if (c == '#' && (c = fgetc(file_handle->handle.fp)) == '!') {
while (c != '\n' && c != '\r' && c != EOF) {
c = fgetc(file_handle->handle.fp); /* skip to end of line */
}
@@ -575,6 +600,7 @@ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file,
} else {
rewind(file_handle->handle.fp);
}
+
return SUCCESS;
}
/* }}} */
@@ -658,12 +684,11 @@ int main(int argc, char *argv[])
setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */
#endif
- ini_entries_len = strlen(HARDCODED_INI);
- cli_sapi_module.ini_entries = malloc(ini_entries_len+2);
- memcpy(cli_sapi_module.ini_entries, HARDCODED_INI, ini_entries_len+1);
- cli_sapi_module.ini_entries[ini_entries_len+1] = 0;
+ ini_entries_len = sizeof(HARDCODED_INI)-2;
+ cli_sapi_module.ini_entries = malloc(sizeof(HARDCODED_INI));
+ memcpy(cli_sapi_module.ini_entries, HARDCODED_INI, sizeof(HARDCODED_INI));
- 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, 2))!=-1) {
switch (c) {
case 'c':
if (cli_sapi_module.php_ini_path_override) {
@@ -711,6 +736,7 @@ int main(int argc, char *argv[])
php_optarg = orig_optarg;
cli_sapi_module.executable_location = argv[0];
+ cli_sapi_module.additional_functions = additional_functions;
/* startup after we get the above ini override se we get things right */
if (cli_sapi_module.startup(&cli_sapi_module)==FAILURE) {
@@ -728,7 +754,7 @@ int main(int argc, char *argv[])
CG(in_compilation) = 0; /* not initialized but needed for several options */
EG(uninitialized_zval_ptr) = NULL;
- 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, 2)) != -1) {
switch (c) {
case 'h': /* help & quit */
@@ -799,7 +825,7 @@ int main(int argc, char *argv[])
php_optind = orig_optind;
php_optarg = orig_optarg;
- 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, 2)) != -1) {
switch (c) {
case 'a': /* interactive mode */
@@ -818,7 +844,7 @@ int main(int argc, char *argv[])
break;
case 'e': /* enable extended info output */
- CG(extended_info) = 1;
+ CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
break;
case 'F':
@@ -1118,7 +1144,7 @@ int main(int argc, char *argv[])
}
if (EG(exception)) {
- zend_exception_error(EG(exception) TSRMLS_CC);
+ zend_exception_error(EG(exception), E_WARNING TSRMLS_CC);
}
php_last_char = '\0';
@@ -1163,7 +1189,7 @@ int main(int argc, char *argv[])
case PHP_MODE_INDENT:
open_file_for_scanning(&file_handle TSRMLS_CC);
zend_indent();
- fclose(file_handle.handle.fp);
+ zend_file_handle_dtor(file_handle.handle TSRMLS_CC);
goto out;
break;
#endif
diff --git a/sapi/cli/php_cli_readline.c b/sapi/cli/php_cli_readline.c
index dd76c3518..c79aa227c 100644
--- a/sapi/cli/php_cli_readline.c
+++ b/sapi/cli/php_cli_readline.c
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_cli_readline.c,v 1.3.2.5.2.5 2008/12/31 11:17:49 sebastian Exp $ */
+/* $Id: php_cli_readline.c,v 1.3.2.5.2.3.2.3 2008/12/31 11:15:49 sebastian Exp $ */
#include "php.h"
@@ -362,7 +362,7 @@ TODO:
- future: respect scope ("php > function foo() { $[tab]" should only expand to local variables...)
*/
- char *retval;
+ char *retval = NULL;
int textlen = strlen(text);
TSRMLS_FETCH();
diff --git a/sapi/cli/php_cli_readline.h b/sapi/cli/php_cli_readline.h
index cdf4e5a08..a200f656c 100644
--- a/sapi/cli/php_cli_readline.h
+++ b/sapi/cli/php_cli_readline.h
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_cli_readline.h,v 1.2.2.1.2.3 2008/12/31 11:17:49 sebastian Exp $ */
+/* $Id: php_cli_readline.h,v 1.2.2.1.2.1.2.2 2008/12/31 11:15:49 sebastian Exp $ */
#include "php.h"
diff --git a/sapi/cli/php_getopt.h b/sapi/cli/php_getopt.h
deleted file mode 100644
index ef10db00c..000000000
--- a/sapi/cli/php_getopt.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 5 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2009 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 3.01 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available through the world-wide-web at the following url: |
- | http://www.php.net/license/3_01.txt |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Marcus Boerger <helly@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id: php_getopt.h,v 1.7.2.1.2.3 2008/12/31 11:17:49 sebastian Exp $ */
-
-#include "php.h"
-
-#ifdef NETWARE
-/*
-As NetWare LibC has optind and optarg macros defined in unistd.h our local variables were getting mistakenly preprocessed so undeffing optind and optarg
-*/
-#undef optarg
-#undef optind
-#endif
-/* Define structure for one recognized option (both single char and long name).
- * If short_open is '-' this is the last option.
- */
-typedef struct _opt_struct {
- const char opt_char;
- const int need_param;
- const char * opt_name;
-} opt_struct;
-
-int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err);
diff --git a/sapi/cli/tests/002-win32.phpt b/sapi/cli/tests/002-win32.phpt
index ca0e66ddc..5a00c67f7 100644
--- a/sapi/cli/tests/002-win32.phpt
+++ b/sapi/cli/tests/002-win32.phpt
@@ -10,7 +10,7 @@ if (substr(PHP_OS, 0, 3) != 'WIN') {
--FILE--
<?php
-$php = $_ENV['TEST_PHP_EXECUTABLE'];
+$php = getenv('TEST_PHP_EXECUTABLE');
var_dump(`$php -n -r "var_dump('hello');"`);
diff --git a/sapi/cli/tests/005.phpt b/sapi/cli/tests/005.phpt
index 0b38bba76..914e33c7f 100644
--- a/sapi/cli/tests/005.phpt
+++ b/sapi/cli/tests/005.phpt
@@ -12,16 +12,16 @@ if (!extension_loaded("reflection")) {
$php = getenv('TEST_PHP_EXECUTABLE');
-var_dump(`$php -n --rc unknown`);
-var_dump(`$php -n --rc stdclass`);
-var_dump(`$php -n --rc exception`);
+var_dump(`"$php" -n --rc unknown`);
+var_dump(`"$php" -n --rc stdclass`);
+var_dump(`"$php" -n --rc exception`);
echo "Done\n";
?>
--EXPECTF--
string(40) "Exception: Class unknown does not exist
"
-string(178) "Class [ <internal> class stdClass ] {
+string(183) "Class [ <internal:Core> class stdClass ] {
- Constants [0] {
}
@@ -40,7 +40,7 @@ string(178) "Class [ <internal> class stdClass ] {
}
"
-string(1141) "Class [ <internal> class Exception ] {
+string(1355) "Class [ <internal:Core> class Exception ] {
- Constants [0] {
}
@@ -51,46 +51,51 @@ string(1141) "Class [ <internal> class Exception ] {
- Static methods [0] {
}
- - Properties [6] {
+ - Properties [7] {
Property [ <default> protected $message ]
Property [ <default> private $string ]
Property [ <default> protected $code ]
Property [ <default> protected $file ]
Property [ <default> protected $line ]
Property [ <default> private $trace ]
+ Property [ <default> private $previous ]
}
- - Methods [9] {
- Method [ <internal> final private method __clone ] {
+ - Methods [10] {
+ Method [ <internal:Core> final private method __clone ] {
}
- Method [ <internal, ctor> public method __construct ] {
+ Method [ <internal:Core, ctor> public method __construct ] {
- - Parameters [2] {
+ - Parameters [3] {
Parameter #0 [ <optional> $message ]
Parameter #1 [ <optional> $code ]
+ Parameter #2 [ <optional> $previous ]
}
}
- Method [ <internal> final public method getMessage ] {
+ Method [ <internal:Core> final public method getMessage ] {
}
- Method [ <internal> final public method getCode ] {
+ Method [ <internal:Core> final public method getCode ] {
}
- Method [ <internal> final public method getFile ] {
+ Method [ <internal:Core> final public method getFile ] {
}
- Method [ <internal> final public method getLine ] {
+ Method [ <internal:Core> final public method getLine ] {
}
- Method [ <internal> final public method getTrace ] {
+ Method [ <internal:Core> final public method getTrace ] {
}
- Method [ <internal> final public method getTraceAsString ] {
+ Method [ <internal:Core> final public method getPrevious ] {
}
- Method [ <internal> public method __toString ] {
+ Method [ <internal:Core> final public method getTraceAsString ] {
+ }
+
+ Method [ <internal:Core> public method __toString ] {
}
}
}
diff --git a/sapi/cli/tests/006.phpt b/sapi/cli/tests/006.phpt
index c553a8369..f9d243224 100644
--- a/sapi/cli/tests/006.phpt
+++ b/sapi/cli/tests/006.phpt
@@ -16,7 +16,7 @@ $php = getenv('TEST_PHP_EXECUTABLE');
var_dump(`$php -n --re unknown`);
var_dump(`$php -n --re ""`);
-var_dump(`$php -n --re date`);
+var_dump(`$php -n --re pcre`);
echo "Done\n";
?>
@@ -25,302 +25,112 @@ string(44) "Exception: Extension unknown does not exist
"
string(37) "Exception: Extension does not exist
"
-string(%d) "Extension [ <persistent> extension #%d date version %s ] {
-
- - Dependencies {
- Dependency [ session (Optional) ]
- }
+string(%d) "Extension [ <persistent> extension #%d pcre version <no_version> ] {
- INI {
- Entry [ date.timezone <ALL> ]
- Current = ''
- }
- Entry [ date.default_latitude <ALL> ]
- Current = '%s'
+ Entry [ pcre.backtrack_limit <ALL> ]
+ Current = '%d'
}
- Entry [ date.default_longitude <ALL> ]
- Current = '%s'
- }
- Entry [ date.sunset_zenith <ALL> ]
- Current = '%s'
- }
- Entry [ date.sunrise_zenith <ALL> ]
- Current = '%s'
+ Entry [ pcre.recursion_limit <ALL> ]
+ Current = '%d'
}
}
- Constants [14] {
- Constant [ string DATE_ATOM ] { Y-m-d\TH:i:sP }
- Constant [ string DATE_COOKIE ] { l, d-M-y H:i:s T }
- Constant [ string DATE_ISO8601 ] { Y-m-d\TH:i:sO }
- Constant [ string DATE_RFC822 ] { D, d M y H:i:s O }
- Constant [ string DATE_RFC850 ] { l, d-M-y H:i:s T }
- Constant [ string DATE_RFC1036 ] { D, d M y H:i:s O }
- Constant [ string DATE_RFC1123 ] { D, d M Y H:i:s O }
- Constant [ string DATE_RFC2822 ] { D, d M Y H:i:s O }
- Constant [ string DATE_RFC3339 ] { Y-m-d\TH:i:sP }
- Constant [ string DATE_RSS ] { D, d M Y H:i:s O }
- Constant [ string DATE_W3C ] { Y-m-d\TH:i:sP }
- Constant [ integer SUNFUNCS_RET_TIMESTAMP ] { 0 }
- Constant [ integer SUNFUNCS_RET_STRING ] { 1 }
- Constant [ integer SUNFUNCS_RET_DOUBLE ] { 2 }
+ Constant [ integer PREG_PATTERN_ORDER ] { 1 }
+ Constant [ integer PREG_SET_ORDER ] { 2 }
+ Constant [ integer PREG_OFFSET_CAPTURE ] { 256 }
+ Constant [ integer PREG_SPLIT_NO_EMPTY ] { 1 }
+ Constant [ integer PREG_SPLIT_DELIM_CAPTURE ] { 2 }
+ Constant [ integer PREG_SPLIT_OFFSET_CAPTURE ] { 4 }
+ Constant [ integer PREG_GREP_INVERT ] { 1 }
+ Constant [ integer PREG_NO_ERROR ] { 0 }
+ Constant [ integer PREG_INTERNAL_ERROR ] { 1 }
+ Constant [ integer PREG_BACKTRACK_LIMIT_ERROR ] { 2 }
+ Constant [ integer PREG_RECURSION_LIMIT_ERROR ] { 3 }
+ Constant [ integer PREG_BAD_UTF8_ERROR ] { 4 }
+ Constant [ integer PREG_BAD_UTF8_OFFSET_ERROR ] { 5 }
+ Constant [ string PCRE_VERSION ] { %s }
}
- Functions {
- Function [ <internal:date> function strtotime ] {
-
- - Parameters [2] {
- Parameter #0 [ <required> $time ]
- Parameter #1 [ <optional> $now ]
- }
- }
- Function [ <internal:date> function date ] {
-
- - Parameters [2] {
- Parameter #0 [ <required> $format ]
- Parameter #1 [ <optional> $timestamp ]
- }
- }
- Function [ <internal:date> function idate ] {
+ Function [ <internal:pcre> function preg_match ] {
- - Parameters [2] {
- Parameter #0 [ <required> $format ]
- Parameter #1 [ <optional> $timestamp ]
+ - Parameters [5] {
+ Parameter #0 [ <required> $pattern ]
+ Parameter #1 [ <required> $subject ]
+ Parameter #2 [ <optional> &$subpatterns ]
+ Parameter #3 [ <optional> $flags ]
+ Parameter #4 [ <optional> $offset ]
}
}
- Function [ <internal:date> function gmdate ] {
+ Function [ <internal:pcre> function preg_match_all ] {
- - Parameters [2] {
- Parameter #0 [ <required> $format ]
- Parameter #1 [ <optional> $timestamp ]
+ - Parameters [5] {
+ Parameter #0 [ <required> $pattern ]
+ Parameter #1 [ <required> $subject ]
+ Parameter #2 [ <required> &$subpatterns ]
+ Parameter #3 [ <optional> $flags ]
+ Parameter #4 [ <optional> $offset ]
}
}
- Function [ <internal:date> function mktime ] {
+ Function [ <internal:pcre> function preg_replace ] {
- - Parameters [6] {
- Parameter #0 [ <optional> $hour ]
- Parameter #1 [ <optional> $min ]
- Parameter #2 [ <optional> $sec ]
- Parameter #3 [ <optional> $mon ]
- Parameter #4 [ <optional> $day ]
- Parameter #5 [ <optional> $year ]
+ - Parameters [5] {
+ Parameter #0 [ <required> $regex ]
+ Parameter #1 [ <required> $replace ]
+ Parameter #2 [ <optional> $subject ]
+ Parameter #3 [ <optional> $limit ]
+ Parameter #4 [ <optional> &$count ]
}
}
- Function [ <internal:date> function gmmktime ] {
+ Function [ <internal:pcre> function preg_replace_callback ] {
- - Parameters [6] {
- Parameter #0 [ <optional> $hour ]
- Parameter #1 [ <optional> $min ]
- Parameter #2 [ <optional> $sec ]
- Parameter #3 [ <optional> $mon ]
- Parameter #4 [ <optional> $day ]
- Parameter #5 [ <optional> $year ]
+ - Parameters [5] {
+ Parameter #0 [ <required> $regex ]
+ Parameter #1 [ <required> $callback ]
+ Parameter #2 [ <required> $subject ]
+ Parameter #3 [ <optional> $limit ]
+ Parameter #4 [ <optional> &$count ]
}
}
- Function [ <internal:date> function checkdate ] {
+ Function [ <internal:pcre> function preg_filter ] {
- - Parameters [3] {
- Parameter #0 [ <required> $month ]
- Parameter #1 [ <required> $day ]
- Parameter #2 [ <required> $year ]
+ - Parameters [5] {
+ Parameter #0 [ <required> $regex ]
+ Parameter #1 [ <required> $replace ]
+ Parameter #2 [ <optional> $subject ]
+ Parameter #3 [ <optional> $limit ]
+ Parameter #4 [ <optional> &$count ]
}
}
- Function [ <internal:date> function strftime ] {
+ Function [ <internal:pcre> function preg_split ] {
- - Parameters [2] {
- Parameter #0 [ <required> $format ]
- Parameter #1 [ <optional> $timestamp ]
+ - Parameters [4] {
+ Parameter #0 [ <required> $pattern ]
+ Parameter #1 [ <required> $subject ]
+ Parameter #2 [ <optional> $limit ]
+ Parameter #3 [ <optional> $flags ]
}
}
- Function [ <internal:date> function gmstrftime ] {
+ Function [ <internal:pcre> function preg_quote ] {
- Parameters [2] {
- Parameter #0 [ <required> $format ]
- Parameter #1 [ <optional> $timestamp ]
- }
- }
- Function [ <internal:date> function time ] {
-
- - Parameters [0] {
+ Parameter #0 [ <required> $str ]
+ Parameter #1 [ <optional> $delim_char ]
}
}
- Function [ <internal:date> function localtime ] {
-
- - Parameters [2] {
- Parameter #0 [ <optional> $timestamp ]
- Parameter #1 [ <optional> $associative_array ]
- }
- }
- Function [ <internal:date> function getdate ] {
-
- - Parameters [1] {
- Parameter #0 [ <optional> $timestamp ]
- }
- }
- Function [ <internal:date> function date_create ] {
- }
- Function [ <internal:date> function date_parse ] {
- }
- Function [ <internal:date> function date_format ] {
- }
- Function [ <internal:date> function date_modify ] {
- }
- Function [ <internal:date> function date_timezone_get ] {
- }
- Function [ <internal:date> function date_timezone_set ] {
- }
- Function [ <internal:date> function date_offset_get ] {
- }
- Function [ <internal:date> function date_time_set ] {
- }
- Function [ <internal:date> function date_date_set ] {
- }
- Function [ <internal:date> function date_isodate_set ] {
- }
- Function [ <internal:date> function timezone_open ] {
- }
- Function [ <internal:date> function timezone_name_get ] {
- }
- Function [ <internal:date> function timezone_name_from_abbr ] {
- }
- Function [ <internal:date> function timezone_offset_get ] {
- }
- Function [ <internal:date> function timezone_transitions_get ] {
- }
- Function [ <internal:date> function timezone_identifiers_list ] {
- }
- Function [ <internal:date> function timezone_abbreviations_list ] {
- }
- Function [ <internal:date> function date_default_timezone_set ] {
-
- - Parameters [1] {
- Parameter #0 [ <required> $timezone_identifier ]
- }
- }
- Function [ <internal:date> function date_default_timezone_get ] {
-
- - Parameters [0] {
- }
- }
- Function [ <internal:date> function date_sunrise ] {
-
- - Parameters [6] {
- Parameter #0 [ <required> $time ]
- Parameter #1 [ <optional> $format ]
- Parameter #2 [ <optional> $latitude ]
- Parameter #3 [ <optional> $longitude ]
- Parameter #4 [ <optional> $zenith ]
- Parameter #5 [ <optional> $gmt_offset ]
- }
- }
- Function [ <internal:date> function date_sunset ] {
-
- - Parameters [6] {
- Parameter #0 [ <required> $time ]
- Parameter #1 [ <optional> $format ]
- Parameter #2 [ <optional> $latitude ]
- Parameter #3 [ <optional> $longitude ]
- Parameter #4 [ <optional> $zenith ]
- Parameter #5 [ <optional> $gmt_offset ]
- }
- }
- Function [ <internal:date> function date_sun_info ] {
+ Function [ <internal:pcre> function preg_grep ] {
- Parameters [3] {
- Parameter #0 [ <required> $time ]
- Parameter #1 [ <required> $latitude ]
- Parameter #2 [ <required> $longitude ]
- }
- }
- }
-
- - Classes [2] {
- Class [ <internal:date> class DateTime ] {
-
- - Constants [11] {
- Constant [ string ATOM ] { Y-m-d\TH:i:sP }
- Constant [ string COOKIE ] { l, d-M-y H:i:s T }
- Constant [ string ISO8601 ] { Y-m-d\TH:i:sO }
- Constant [ string RFC822 ] { D, d M y H:i:s O }
- Constant [ string RFC850 ] { l, d-M-y H:i:s T }
- Constant [ string RFC1036 ] { D, d M y H:i:s O }
- Constant [ string RFC1123 ] { D, d M Y H:i:s O }
- Constant [ string RFC2822 ] { D, d M Y H:i:s O }
- Constant [ string RFC3339 ] { Y-m-d\TH:i:sP }
- Constant [ string RSS ] { D, d M Y H:i:s O }
- Constant [ string W3C ] { Y-m-d\TH:i:sP }
- }
-
- - Static properties [0] {
- }
-
- - Static methods [0] {
- }
-
- - Properties [0] {
- }
-
- - Methods [9] {
- Method [ <internal:date, ctor> public method __construct ] {
- }
-
- Method [ <internal:date> public method format ] {
- }
-
- Method [ <internal:date> public method modify ] {
- }
-
- Method [ <internal:date> public method getTimezone ] {
- }
-
- Method [ <internal:date> public method setTimezone ] {
- }
-
- Method [ <internal:date> public method getOffset ] {
- }
-
- Method [ <internal:date> public method setTime ] {
- }
-
- Method [ <internal:date> public method setDate ] {
- }
-
- Method [ <internal:date> public method setISODate ] {
- }
+ Parameter #0 [ <required> $regex ]
+ Parameter #1 [ <required> $input ]
+ Parameter #2 [ <optional> $flags ]
}
}
+ Function [ <internal:pcre> function preg_last_error ] {
- Class [ <internal:date> class DateTimeZone ] {
-
- - Constants [0] {
- }
-
- - Static properties [0] {
- }
-
- - Static methods [2] {
- Method [ <internal:date> static public method listAbbreviations ] {
- }
-
- Method [ <internal:date> static public method listIdentifiers ] {
- }
- }
-
- - Properties [0] {
- }
-
- - Methods [4] {
- Method [ <internal:date, ctor> public method __construct ] {
- }
-
- Method [ <internal:date> public method getName ] {
- }
-
- Method [ <internal:date> public method getOffset ] {
- }
-
- Method [ <internal:date> public method getTransitions ] {
- }
+ - Parameters [0] {
}
}
}
diff --git a/sapi/cli/tests/010.phpt b/sapi/cli/tests/010.phpt
index e465e3797..77c76c194 100644
--- a/sapi/cli/tests/010.phpt
+++ b/sapi/cli/tests/010.phpt
@@ -12,8 +12,8 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
$php = getenv('TEST_PHP_EXECUTABLE');
-$filename = dirname(__FILE__)."/010.test.php";
-$filename_txt = dirname(__FILE__)."/010.test.txt";
+$filename = __DIR__."/010.test.php";
+$filename_txt = __DIR__."/010.test.txt";
$code = '
<?php
@@ -25,23 +25,22 @@ file_put_contents($filename, $code);
$txt = '
test
-hello
-';
+hello';
file_put_contents($filename_txt, $txt);
var_dump(`cat "$filename_txt" | "$php" -n -F "$filename"`);
-@unlink($filename);
-@unlink($filename_txt);
-
-echo "Done\n";
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(__DIR__."/010.test.php");
+@unlink(__DIR__."/010.test.txt");
?>
--EXPECTF--
-string(39) "
+string(25) "
string(10) "test
hello"
-
-string(0) ""
"
-Done
+===DONE===
diff --git a/sapi/cli/tests/016.phpt b/sapi/cli/tests/016.phpt
new file mode 100644
index 000000000..adde106df
--- /dev/null
+++ b/sapi/cli/tests/016.phpt
@@ -0,0 +1,108 @@
+--TEST--
+CLI -a and readline
+--SKIPIF--
+<?php
+include "skipif.inc";
+if (!extension_loaded('readline') || readline_info('done') === NULL) {
+ die ("skip need readline support");
+}
+?>
+--FILE--
+<?php
+$php = getenv('TEST_PHP_EXECUTABLE');
+
+// disallow console escape sequences that may break the output
+putenv('TERM=VT100');
+
+$codes = array();
+
+$codes[1] = <<<EOT
+echo 'Hello world';
+exit
+EOT;
+
+$codes[] = <<<EOT
+echo 'multine
+single
+quote';
+exit
+EOT;
+
+$codes[] = <<<EOT
+echo <<<HEREDOC
+Here
+comes
+the
+doc
+HEREDOC;
+EOT;
+
+$codes[] = <<<EOT
+if (0) {
+ echo "I'm not there";
+}
+echo "Done";
+EOT;
+
+$codes[] = <<<EOT
+function a_function_with_some_name() {
+ echo "I was called!";
+}
+a_function_w );
+EOT;
+
+foreach ($codes as $key => $code) {
+ echo "\n--------------\nSnippet no. $key:\n--------------\n";
+ $code = escapeshellarg($code);
+ echo `echo $code | "$php" -a`, "\n";
+}
+
+echo "\nDone\n";
+?>
+--EXPECTF--
+--------------
+Snippet no. 1:
+--------------
+Interactive shell
+
+php > Hello world
+php >
+
+--------------
+Snippet no. 2:
+--------------
+Interactive shell
+
+php > php ' php ' multine
+single
+quote
+php >
+
+--------------
+Snippet no. 3:
+--------------
+Interactive shell
+
+php > <<< > <<< > <<< > <<< > <<< > Here
+comes
+the
+doc
+php >
+
+--------------
+Snippet no. 4:
+--------------
+Interactive shell
+
+php > php { php { php > Done
+php >
+
+--------------
+Snippet no. 5:
+--------------
+Interactive shell
+
+php > php { php { php > I was called!
+php >
+
+Done
diff --git a/sapi/cli/tests/017.phpt b/sapi/cli/tests/017.phpt
new file mode 100644
index 000000000..efaf977db
--- /dev/null
+++ b/sapi/cli/tests/017.phpt
@@ -0,0 +1,106 @@
+--TEST--
+CLI -a and libedit
+--SKIPIF--
+<?php
+include "skipif.inc";
+if (!extension_loaded('readline') || readline_info('done') !== NULL) {
+ die ("skip need readline support using libedit");
+}
+?>
+--FILE--
+<?php
+$php = getenv('TEST_PHP_EXECUTABLE');
+
+$codes = array();
+
+$codes[1] = <<<EOT
+echo 'Hello world';
+exit
+EOT;
+
+$codes[] = <<<EOT
+echo 'multine
+single
+quote';
+exit
+EOT;
+
+$codes[] = <<<EOT
+echo <<<HEREDOC
+Here
+comes
+the
+doc
+HEREDOC;
+EOT;
+
+$codes[] = <<<EOT
+if (0) {
+ echo "I'm not there";
+}
+echo "Done";
+EOT;
+
+$codes[] = <<<EOT
+function a_function_with_some_name() {
+ echo "I was called!";
+}
+a_function_w );
+EOT;
+
+foreach ($codes as $key => $code) {
+ echo "\n--------------\nSnippet no. $key:\n--------------\n";
+ $code = escapeshellarg($code);
+ echo `echo $code | "$php" -a`, "\n";
+}
+
+echo "\nDone\n";
+?>
+--EXPECTF--
+--------------
+Snippet no. 1:
+--------------
+Interactive shell
+
+Hello world
+
+
+--------------
+Snippet no. 2:
+--------------
+Interactive shell
+
+multine
+single
+quote
+
+
+--------------
+Snippet no. 3:
+--------------
+Interactive shell
+
+Here
+comes
+the
+doc
+
+
+--------------
+Snippet no. 4:
+--------------
+Interactive shell
+
+Done
+
+
+--------------
+Snippet no. 5:
+--------------
+Interactive shell
+
+
+Parse error: syntax error, unexpected ')' in php shell code on line 1
+
+
+Done
diff --git a/sapi/cli/tests/018.phpt b/sapi/cli/tests/018.phpt
new file mode 100644
index 000000000..56921bd66
--- /dev/null
+++ b/sapi/cli/tests/018.phpt
@@ -0,0 +1,27 @@
+--TEST--
+CLI php -m
+--SKIPIF--
+<?php
+include "skipif.inc";
+if (substr(PHP_OS, 0, 3) == 'WIN') {
+ die ("skip not for Windows");
+}
+?>
+--FILE--
+<?php
+
+$php = getenv('TEST_PHP_EXECUTABLE');
+
+
+echo `"$php" -n -m`;
+
+echo "Done\n";
+?>
+--EXPECTF--
+[PHP Modules]
+%a
+pcre
+%a
+
+[Zend Modules]
+%aDone
diff --git a/sapi/cli/tests/019.phpt b/sapi/cli/tests/019.phpt
new file mode 100644
index 000000000..c98155d8d
--- /dev/null
+++ b/sapi/cli/tests/019.phpt
@@ -0,0 +1,36 @@
+--TEST--
+CLI php -i
+--SKIPIF--
+<?php
+include "skipif.inc";
+if (substr(PHP_OS, 0, 3) == 'WIN') {
+ die ("skip not for Windows");
+}
+?>
+--FILE--
+<?php
+
+$php = getenv('TEST_PHP_EXECUTABLE');
+
+
+echo `"$php" -n -i`;
+
+echo "\nDone\n";
+?>
+--EXPECTF--
+phpinfo()
+PHP Version => %s
+%a
+PHP License
+This program is free software; you can redistribute it and/or modify
+it under the terms of the PHP License as published by the PHP Group
+and included in the distribution in the file: LICENSE
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+If you did not receive a copy of the PHP license, or have any
+questions about PHP licensing, please contact license@php.net.
+
+Done
diff --git a/sapi/cli/tests/020.phpt b/sapi/cli/tests/020.phpt
new file mode 100644
index 000000000..62be4ba31
--- /dev/null
+++ b/sapi/cli/tests/020.phpt
@@ -0,0 +1,32 @@
+--TEST--
+CLI php --ri
+--SKIPIF--
+<?php
+include "skipif.inc";
+if (substr(PHP_OS, 0, 3) == 'WIN') {
+ die ("skip not for Windows");
+}
+?>
+--FILE--
+<?php
+
+$php = getenv('TEST_PHP_EXECUTABLE');
+
+
+echo `"$php" -n --ri this_extension_does_not_exist_568537753423`;
+echo `"$php" -n --ri standard`;
+
+echo "\nDone\n";
+?>
+--EXPECTF--
+Extension 'this_extension_does_not_exist_568537753423' not present.
+
+standard
+
+%a
+
+Directive => Local Value => Master Value
+%a
+
+Done
+
diff --git a/sapi/cli/tests/021.phpt b/sapi/cli/tests/021.phpt
index b127b8969..a4442b0e0 100644
--- a/sapi/cli/tests/021.phpt
+++ b/sapi/cli/tests/021.phpt
@@ -12,7 +12,7 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
$php = getenv('TEST_PHP_EXECUTABLE');
-$filename = dirname(__FILE__).'/021.tmp.php';
+$filename = __DIR__.'/021.tmp.php';
$script = "#!$php -n\n".
"ola\n".
@@ -29,7 +29,7 @@ echo "\nDone\n";
?>
--CLEAN--
<?php
-unlink(dirname(__FILE__).'/021.tmp.php');
+unlink(__DIR__.'/021.tmp.php');
?>
--EXPECTF--
ola
diff --git a/sapi/continuity/capi.c b/sapi/continuity/capi.c
index b57008951..504739df3 100644
--- a/sapi/continuity/capi.c
+++ b/sapi/continuity/capi.c
@@ -80,7 +80,7 @@ PHP_FUNCTION(continuity_virtual);
PHP_FUNCTION(continuity_request_headers);
PHP_FUNCTION(continuity_response_headers);
-zend_function_entry continuity_functions[] = {
+const zend_function_entry continuity_functions[] = {
{NULL, NULL, NULL}
};
@@ -110,7 +110,7 @@ PHP_MSHUTDOWN_FUNCTION(continuity)
PHP_MINFO_FUNCTION(continuity)
{
php_info_print_table_start();
- php_info_print_table_row(2, "Continuity Module Revision", "$Revision: 1.11.2.2.2.3 $");
+ php_info_print_table_row(2, "Continuity Module Revision", "$Revision: 1.11.2.2.2.1.2.5 $");
php_info_print_table_row(2, "Server Version", conFget_build());
#ifdef CONTINUITY_CDPEXT
php_info_print_table_row(2,"CDP Extensions", "enabled");
@@ -378,7 +378,8 @@ sapi_module_struct capi_sapi_module = {
sapi_capi_register_server_variables, /* register server variables */
capi_log_message, /* Log message */
- NULL, /* Get request time */
+ NULL, /* Get request time */
+ NULL, /* Child terminate */
NULL, /* Block interruptions */
NULL, /* Unblock interruptions */
diff --git a/sapi/embed/php_embed.c b/sapi/embed/php_embed.c
index d5e4363c2..d3df27ade 100644
--- a/sapi/embed/php_embed.c
+++ b/sapi/embed/php_embed.c
@@ -15,9 +15,10 @@
| Author: Edin Kadribasic <edink@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: php_embed.c,v 1.11.2.1.2.8 2008/12/31 11:17:49 sebastian Exp $ */
+/* $Id: php_embed.c,v 1.11.2.1.2.5.2.6 2009/01/04 20:18:57 pajoye Exp $ */
#include "php_embed.h"
+#include "ext/standard/php_standard.h"
#ifdef PHP_WIN32
#include <io.h>
@@ -134,11 +135,23 @@ sapi_module_struct php_embed_module = {
php_embed_register_variables, /* register server variables */
php_embed_log_message, /* Log message */
NULL, /* Get request time */
+ NULL, /* Child terminate */
STANDARD_SAPI_MODULE_PROPERTIES
};
/* }}} */
+/* {{{ arginfo ext/standard/dl.c */
+ZEND_BEGIN_ARG_INFO(arginfo_dl, 0)
+ ZEND_ARG_INFO(0, extension_filename)
+ZEND_END_ARG_INFO()
+/* }}} */
+
+static const zend_function_entry additional_functions[] = {
+ ZEND_FE(dl, arginfo_dl)
+ {NULL, NULL, NULL}
+};
+
int php_embed_init(int argc, char **argv PTSRMLS_DC)
{
zend_llist global_vars;
@@ -175,6 +188,8 @@ int php_embed_init(int argc, char **argv PTSRMLS_DC)
php_embed_module.ini_entries = malloc(sizeof(HARDCODED_INI));
memcpy(php_embed_module.ini_entries, HARDCODED_INI, sizeof(HARDCODED_INI));
+ php_embed_module.additional_functions = additional_functions;
+
if (argv) {
php_embed_module.executable_location = argv[0];
}
diff --git a/sapi/embed/php_embed.h b/sapi/embed/php_embed.h
index 9f729ba3c..8c2fbb1e3 100644
--- a/sapi/embed/php_embed.h
+++ b/sapi/embed/php_embed.h
@@ -15,7 +15,7 @@
| Author: Edin Kadribasic <edink@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: php_embed.h,v 1.6.2.2.2.3 2008/12/31 11:17:49 sebastian Exp $ */
+/* $Id: php_embed.h,v 1.6.2.2.2.1.2.2 2008/12/31 11:15:49 sebastian Exp $ */
#ifndef _PHP_EMBED_H_
#define _PHP_EMBED_H_
diff --git a/sapi/isapi/config.w32 b/sapi/isapi/config.w32
index cb7398e0b..bb720fe39 100644
--- a/sapi/isapi/config.w32
+++ b/sapi/isapi/config.w32
@@ -1,13 +1,13 @@
// vim:ft=javascript
-// $Id: config.w32,v 1.4 2004/01/17 13:00:13 sniper Exp $
+// $Id: config.w32,v 1.4.8.1 2008/05/14 03:13:17 auroraeosrose Exp $
ARG_ENABLE('isapi', 'Build ISAPI version of PHP', 'no');
if (PHP_ISAPI == "yes") {
if (PHP_ZTS == "no") {
- ERROR("ISAPI module requires an --enable-zts build of PHP");
+ WARNING("ISAPI module requires an --enable-zts build of PHP");
+ } else {
+ SAPI('isapi', 'php5isapi.c', 'php' + PHP_VERSION + 'isapi.dll', '/D PHP5ISAPI_EXPORTS');
+ ADD_FLAG('LDFLAGS_ISAPI', '/DEF:sapi\\isapi\\php5isapi.def');
}
-
- SAPI('isapi', 'php5isapi.c', 'php' + PHP_VERSION + 'isapi.dll', '/D PHP5ISAPI_EXPORTS');
- ADD_FLAG('LDFLAGS_ISAPI', '/DEF:sapi\\isapi\\php5isapi.def');
}
diff --git a/sapi/isapi/php5isapi.c b/sapi/isapi/php5isapi.c
index 36303c583..b4d76cb80 100644
--- a/sapi/isapi/php5isapi.c
+++ b/sapi/isapi/php5isapi.c
@@ -16,7 +16,7 @@
| Ben Mansell <ben@zeus.com> (Zeus Support) |
+----------------------------------------------------------------------+
*/
-/* $Id: php5isapi.c,v 1.8.2.2.2.6 2008/12/31 11:17:49 sebastian Exp $ */
+/* $Id: php5isapi.c,v 1.8.2.2.2.3.2.4 2008/12/31 11:15:49 sebastian Exp $ */
#include "php.h"
#include <httpext.h>
@@ -688,6 +688,7 @@ static sapi_module_struct isapi_sapi_module = {
sapi_isapi_register_server_variables, /* register server variables */
NULL, /* Log message */
NULL, /* Get request time */
+ NULL, /* Child terminate */
STANDARD_SAPI_MODULE_PROPERTIES
};
diff --git a/sapi/litespeed/CREDITS b/sapi/litespeed/CREDITS
new file mode 100644
index 000000000..2fa192e97
--- /dev/null
+++ b/sapi/litespeed/CREDITS
@@ -0,0 +1,2 @@
+litespeed
+George Wang
diff --git a/sapi/litespeed/Makefile.frag b/sapi/litespeed/Makefile.frag
new file mode 100644
index 000000000..e1af2b90c
--- /dev/null
+++ b/sapi/litespeed/Makefile.frag
@@ -0,0 +1,3 @@
+$(SAPI_LITESPEED_PATH): $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
+ $(BUILD_LITESPEED)
+
diff --git a/sapi/litespeed/README b/sapi/litespeed/README
new file mode 100644
index 000000000..ef3fe80ad
--- /dev/null
+++ b/sapi/litespeed/README
@@ -0,0 +1,225 @@
+Introduction
+============
+
+LiteSpeed SAPI module is a dedicated interface for PHP integration with
+LiteSpeed Web Server. LiteSpeed SAPI has similar architecture to the
+FastCGI SAPI with there major enhancements: better performance, dynamic
+spawning and PHP configuration modification through web server
+configuration and .htaccess files.
+
+Our simple benchmark test ("hello world") shows that PHP with
+LiteSpeed SAPI has 30% better performance over PHP with FastCGI SAPI,
+which is nearly twice the performance that Apache mod_php can deliver.
+
+A major drawback of FastCGI PHP comparing to Apache mod_php is lacking
+the flexibilities in PHP configurations. PHP configurations cannot be
+changed at runtime via configuration files like .htaccess files or web
+server's virtual host configuration. In shared hosting environment,
+each hosting account will has its own "open_basedir" overridden in
+server configuration to enhance server security when mod_php is used.
+usually, FastCGI PHP is not an option in shared hosting environment
+due to lacking of this flexibility. LiteSpeed SAPI is carefully designed
+to address this issue. PHP configurations can be modified the same way
+as that in mod_php with the the same configuration directives.
+
+PHP with LiteSpeed SAPI is highly recommended over FastCGI PHP for
+PHP scripting with LiteSpeed web server.
+
+
+Building PHP with LiteSpeed SAPI
+================================
+
+You need to add "--with-litespeed" to the configure command to build
+PHP with LiteSpeed SAPI, all other SAPI related configure options
+should be removed.
+
+For example:
+ ./configure --with-litespeed
+ make
+
+You should find an executable called 'php' under sapi/litespeed/
+directory after the compilation succeeds. Copy it to
+'lsws/fcgi-bin/lsphp' or wherever you prefer, if LiteSpeed web server
+has been configured to run PHP with LiteSpeed SAPI already, you just
+need to overwrite the old executable with this one and you are all
+set.
+
+Start PHP from command line
+===========================
+
+Usually, lsphp is managed by LiteSpeed web server in a single server
+installation. lsphp can be used in clustered environment with one
+LiteSpeed web server at the front, load balancing lsphp processes
+running on multiple backend servers. In such environment, lsphp can be
+start manually from command with option "-b <socket_address>", socket
+address can be IPv4, IPv6 or Unix Domain Socket address.
+for example:
+
+ ./lsphp -b [::]:3000
+
+have lsphp bind to port 3000 on all IPv4 and IPv6 address,
+
+ ./lsphp -b *:3000
+
+have lsphp bind to port 300 on all IPv4 address.
+
+ ./lsphp -b 192.168.0.2:3000
+
+have lsphp bind to address 192.168.0.2:3000.
+
+ ./lsphp -b /tmp/lsphp_manual.sock
+
+have lsphp accept request on Unix domain socket "/tmp/lsphp_manual.sock"
+
+
+Using LiteSpeed PHP with LiteSpeed Web Server
+=============================================
+
+Detailed information about how to configure LiteSpeed web server with
+PHP support is available from our website, at:
+
+http://www.litespeedtech.com/docs/HowTo_QA.html
+
+Usually, PHP support has been configured out of box, you don't need to
+change it unless you want to change PHP interface from FastCGI to
+LiteSpeed SAPI or vice versa.
+
+Brief instructions are as follow:
+
+1) Login to web administration interface, go to 'Server'->'Ext App' tab,
+ add an external application of type "LSAPI app", "Command" should be
+ set to a shell command that executes the PHP binary you just built.
+ "Instances" should be set to "1". Add "LSAPI_CHILDREN" environment
+ variable to match the value of "Max Connections". More tunable
+ environment variable described below can be added.
+
+2) Go to 'Server'->'Script Handler' tab, add a script handler
+ configuration: set 'suffix' to 'php', 'Handler Type' to 'LiteSpeed
+ API', 'Handler Name' should be the name of external application
+ just defined.
+
+
+3) Click 'Apply Changes' link on the top left of the page, then click
+ 'graceful restart'. Now PHP is running with LiteSpeed SAPI.
+
+Tunings
+-------
+
+There are a few environment variables that can be tweaked to control the
+behavior of LSAPI application.
+
+* LSAPI_CHILDREN or PHP_LSAPI_CHILDREN (default: 0)
+
+There are two ways to let PHP handle multiple requests concurrently,
+Server Managed Mode and Self Managed Mode. In Server Managed Mode,
+LiteSpeed web server dynamically spawn/stop PHP processes, in this mode
+"Instances" should match "Max Connections" configuration for PHP
+external application. To start PHP in Self Managed Mode, "Instances"
+should be set to "1", while "LSAPI_CHILDREN" environment variable should
+be set to match the value of "Max Connections" and >1. Web Server will
+start one PHP process, this process will start/stop children PHP processes
+dynamically based on on demand. If "LSAPI_CHILDREN" <=1, PHP will be
+started in server managed mode.
+
+Self Managed Mode is preferred because all PHP processes can share one
+shared memory block for the opcode cache.
+
+Usually, there is no need to set value of LSAPI_CHILDREN over 100 in
+most server environment.
+
+
+* LSAPI_AVOID_FORK (default: 0)
+
+LSAPI_AVOID_FORK specifies the policy of the internal process manager in
+"Self Managed Mode". When set to 0, the internal process manager will stop
+and start children process on demand to save system resource. This is
+preferred in a shared hosting environment. When set to 1, the internal
+process manager will try to avoid freqently stopping and starting children
+process. This might be preferred in a dedicate hosting environment.
+
+
+* LSAPI_EXTRA_CHILDREN (default: 1/3 of LSAPI_CHILDREN or 0)
+
+LSAPI_EXTRA_CHILDREN controls the maximum number of extra children processes
+can be started when some or all existing children processes are in
+malfunctioning state. Total number of children processes will be reduced to
+LSAPI_CHILDREN level as soon as service is back to normal.
+When LSAPI_AVOID_FORK is set to 0, the default value is 1/3 of
+LSAPI_CHIDLREN, When LSAPI_AVOID_FORK is set to 1, the default value is 0.
+
+
+* LSAPI_MAX_REQS or PHP_LSAPI_MAX_REQUESTS (default value: 10000)
+
+This controls how many requests each child process will handle before
+it exits automatically. Several PHP functions have been identified
+having memory leaks. This parameter can help reducing memory usage
+of leaky PHP functions.
+
+
+* LSAPI_MAX_IDLE (default value: 300 seconds)
+
+In Self Managed Mode, LSAPI_MAX_IDLE controls how long a idle child
+process will wait for a new request before it exits. This option help
+releasing system resources taken by idle processes.
+
+
+* LSAPI_MAX_IDLE_CHILDREN
+ (default value: 1/3 of LSAPI_CHILDREN or LSAPI_CHILDREN)
+
+In Self Managed Mode, LSAI_MAX_IDLE_CHILDREN controls how many idle
+children processes are allowed. Excessive idle children processes
+will be killed by the parent process immediately.
+When LSAPI_AVOID_FORK is set to 0, the default value is 1/3 of
+LSAPI_CHIDLREN, When LSAPI_AVOID_FORK is set to 1, the default value
+is LSAPI_CHILDREN.
+
+
+* LSAPI_MAX_PROCESS_TIME (default value: 300 seconds)
+
+In Self Managed Mode, LSAPI_MAX_PROCESS_TIME controls the maximum
+processing time allowed when processing a request. If a child process
+can not finish processing of a request in the given time period, it
+will be killed by the parent process. This option can help getting rid
+of dead or runaway child process.
+
+
+* LSAPI_PGRP_MAX_IDLE (default value: FOREVER )
+
+In Self Managed Mode, LSAPI_PGRP_MAX_IDLE controls how long the parent
+process will wait before exiting when there is no child process.
+This option help releasing system resources taken by an idle parent
+process.
+
+
+* LSAPI_PPID_NO_CHECK
+
+By default a LSAPI application check the existence of its parent process
+and exits automatically if the parent process died. This is to reduce
+orphan process when web server is restarted. However, it is desireable
+to disable this feature, such as when a LSAPI process was started
+manually from command line. LSAPI_PPID_NO_CHECK should be set when
+you want to disable the checking of existence of parent process.
+When PHP started by "-b" option, it is disabled automatically.
+
+
+Compatibility with Apache mod_php
+=================================
+
+LSAPI PHP supports PHP configuration overridden via web server configuration
+as well as .htaccess.
+Since 4.0 release "apache_response_headers" function is supported.
+
+
+
+Contact
+=======
+
+For support questions, please post to our free support forum, at:
+
+http://www.litespeedtech.com/forum/
+
+For bug report, please send bug report to bug [at] litespeedtech.com.
+
+
+
+
diff --git a/sapi/litespeed/config.m4 b/sapi/litespeed/config.m4
new file mode 100644
index 000000000..7d72a28cc
--- /dev/null
+++ b/sapi/litespeed/config.m4
@@ -0,0 +1,31 @@
+dnl
+dnl $Id: config.m4,v 1.2.2.4 2008/08/07 19:32:15 nlopess Exp $
+dnl
+
+AC_MSG_CHECKING(for LiteSpeed support)
+
+PHP_ARG_WITH(litespeed,,
+[ --with-litespeed Build PHP as litespeed module], no)
+
+if test "$PHP_LITESPEED" != "no"; then
+ PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/litespeed/Makefile.frag,$abs_srcdir/sapi/litespeed,sapi/litespeed)
+ SAPI_LITESPEED_PATH=sapi/litespeed/php
+ PHP_SUBST(SAPI_LITESPEED_PATH)
+ PHP_SELECT_SAPI(litespeed, program, lsapi_main.c lsapilib.c, "", '$(SAPI_LITESPEED_PATH)')
+ case $host_alias in
+ *darwin*)
+ BUILD_LITESPEED="\$(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_LITESPEED_PATH)"
+ ;;
+ *cygwin*)
+ SAPI_LITESPEED_PATH=sapi/litespeed/php.exe
+ BUILD_LITESPEED="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_SAPI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_LITESPEED_PATH)"
+ ;;
+ *)
+ BUILD_LITESPEED="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_SAPI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_LITESPEED_PATH)"
+ ;;
+ esac
+
+ PHP_SUBST(BUILD_LITESPEED)
+fi
+
+AC_MSG_RESULT($PHP_LITESPEED)
diff --git a/sapi/litespeed/lsapi_main.c b/sapi/litespeed/lsapi_main.c
new file mode 100644
index 000000000..70409c903
--- /dev/null
+++ b/sapi/litespeed/lsapi_main.c
@@ -0,0 +1,909 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2007 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: George Wang <gwang@litespeedtech.com> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id: lsapi_main.c,v 1.7.2.3 2008/08/26 22:05:17 gwang Exp $ */
+
+#include "php.h"
+#include "SAPI.h"
+#include "php_main.h"
+#include "php_ini.h"
+#include "php_variables.h"
+#include "zend_highlight.h"
+#include "zend.h"
+
+#include "lsapilib.h"
+
+#include <stdio.h>
+
+#if HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef PHP_WIN32
+
+#include <io.h>
+#include <fcntl.h>
+#include "win32/php_registry.h"
+
+#else
+
+#include <sys/wait.h>
+
+#endif
+
+#include <sys/stat.h>
+
+#if HAVE_SYS_TYPES_H
+
+#include <sys/types.h>
+
+#endif
+
+#if HAVE_SIGNAL_H
+
+#include <signal.h>
+
+#endif
+
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+
+#define SAPI_LSAPI_MAX_HEADER_LENGTH 2048
+
+static int lsapi_mode = 1;
+static char *php_self = "";
+static char *script_filename = "";
+static int source_highlight = 0;
+
+#ifdef ZTS
+zend_compiler_globals *compiler_globals;
+zend_executor_globals *executor_globals;
+php_core_globals *core_globals;
+sapi_globals_struct *sapi_globals;
+void ***tsrm_ls;
+#endif
+
+zend_module_entry litespeed_module_entry;
+
+/* {{{ php_lsapi_startup
+ */
+static int php_lsapi_startup(sapi_module_struct *sapi_module)
+{
+ if (php_module_startup(sapi_module, NULL, 0)==FAILURE) {
+ return FAILURE;
+ }
+ return SUCCESS;
+}
+/* }}} */
+
+
+
+/* {{{ 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;
+}
+/* }}} */
+
+
+/* {{{ sapi_lsapi_flush
+ */
+static void sapi_lsapi_flush( void * server_context )
+{
+ if ( lsapi_mode ) {
+ if ( LSAPI_Flush() == -1) {
+ php_handle_aborted_connection();
+ }
+ }
+}
+/* }}} */
+
+
+/* {{{ sapi_lsapi_deactivate
+ */
+static int sapi_lsapi_deactivate(TSRMLS_D)
+{
+ LSAPI_Finish();
+ return SUCCESS;
+}
+/* }}} */
+
+
+
+
+/* {{{ sapi_lsapi_getenv
+ */
+static char *sapi_lsapi_getenv( char * name, size_t name_len TSRMLS_DC )
+{
+ 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;
+}
+
+
+
+/* {{{ sapi_lsapi_register_variables
+ */
+static void sapi_lsapi_register_variables(zval *track_vars_array TSRMLS_DC)
+{
+
+ 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", (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);
+
+ }
+}
+/* }}} */
+
+
+/* {{{ sapi_lsapi_read_post
+ */
+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;
+ }
+}
+/* }}} */
+
+
+
+
+/* {{{ sapi_lsapi_read_cookies
+ */
+static char *sapi_lsapi_read_cookies(TSRMLS_D)
+{
+ if ( lsapi_mode ) {
+ return LSAPI_GetHeader( H_COOKIE );
+ } else {
+ return NULL;
+ }
+}
+/* }}} */
+
+
+/* {{{ sapi_lsapi_send_headers
+ */
+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_lsapi_send_headers
+ */
+static void sapi_lsapi_log_message(char *message)
+{
+ int len = strlen( message );
+ LSAPI_Write_Stderr( message, len);
+}
+/* }}} */
+
+
+/* {{{ sapi_module_struct cgi_sapi_module
+ */
+static sapi_module_struct lsapi_sapi_module =
+{
+ "litespeed",
+ "LiteSpeed",
+
+ php_lsapi_startup, /* startup */
+ php_module_shutdown_wrapper, /* shutdown */
+
+ NULL, /* activate */
+ sapi_lsapi_deactivate, /* deactivate */
+
+ sapi_lsapi_ub_write, /* unbuffered write */
+ sapi_lsapi_flush, /* flush */
+ NULL, /* get uid */
+ sapi_lsapi_getenv, /* getenv */
+
+ php_error, /* error 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_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 */
+
+ 0, /* php.ini ignore */
+
+ 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 = 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 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 {
+ 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;
+
+ 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 )
+{
+ 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 );
+
+}
+
+static int processReq( TSRMLS_D )
+{
+ 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 );
+#ifdef PHP_OUTPUT_NEWAPI
+ php_output_end_all(TSRMLS_C);
+#else
+ php_end_ob_buffers(1 TSRMLS_CC);
+#endif
+}
+
+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;
+}
+
+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",
+ 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 */
+#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);
+#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) {
+#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());
+#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());
+#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 = *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();
+#endif
+ return ret;
+}
+
+static int s_stop;
+void litespeed_cleanup(int 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 );
+}
+
+
+
+#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;
+
+#ifdef HAVE_SIGNAL_H
+#if defined(SIGPIPE) && defined(SIG_IGN)
+ signal(SIGPIPE, SIG_IGN);
+#endif
+#endif
+
+#ifdef ZTS
+ 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;
+ }
+ 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);
+
+ 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;
+ }
+
+ if (php_module_startup(&lsapi_sapi_module, &litespeed_module_entry, 1) == FAILURE) {
+#ifdef ZTS
+ 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();
+
+ 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();
+#endif
+ return ret;
+}
+
+
+/* LiteSpeed PHP module starts here */
+
+
+
+PHP_FUNCTION(litespeed_request_headers);
+PHP_FUNCTION(litespeed_response_headers);
+
+PHP_MINFO_FUNCTION(litespeed);
+
+zend_function_entry litespeed_functions[] = {
+ PHP_FE(litespeed_request_headers, NULL)
+ PHP_FE(litespeed_response_headers, NULL)
+ PHP_FALIAS(getallheaders, litespeed_request_headers, NULL)
+ PHP_FALIAS(apache_request_headers, litespeed_request_headers, NULL)
+ PHP_FALIAS(apache_response_headers, litespeed_response_headers, NULL)
+ {NULL, NULL, NULL}
+};
+
+static PHP_MINIT_FUNCTION(litespeed)
+{
+ /* REGISTER_INI_ENTRIES(); */
+ return SUCCESS;
+}
+
+
+static PHP_MSHUTDOWN_FUNCTION(litespeed)
+{
+ /* 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
+};
+
+static int add_associate_array( const char * pKey, int keyLen, const char * pValue, int valLen,
+ void * arg )
+{
+ add_assoc_string_ex( (zval *)arg, (char *)pKey, keyLen+1, (char *)pValue, 1 );
+ return 1;
+}
+
+
+/* {{{ proto array litespeed_request_headers(void)
+ Fetch all HTTP request headers */
+PHP_FUNCTION(litespeed_request_headers)
+{
+ /* TODO: */
+ if (ZEND_NUM_ARGS() > 0) {
+ WRONG_PARAM_COUNT;
+ }
+ array_init(return_value);
+
+ LSAPI_ForeachOrgHeader( add_associate_array, return_value );
+
+}
+/* }}} */
+
+
+
+/* {{{ proto array litespeed_response_headers(void)
+ 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);
+ }
+}
+
+/* }}} */
+
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
+
+
diff --git a/sapi/litespeed/lsapidef.h b/sapi/litespeed/lsapidef.h
new file mode 100644
index 000000000..276c579b2
--- /dev/null
+++ b/sapi/litespeed/lsapidef.h
@@ -0,0 +1,196 @@
+
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2007 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: George Wang <gwang@litespeedtech.com> |
+ +----------------------------------------------------------------------+
+*/
+
+
+/*
+Copyright (c) 2007, Lite Speed Technologies Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+ * Neither the name of the Lite Speed Technologies Inc nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#ifndef _LSAPIDEF_H_
+#define _LSAPIDEF_H_
+
+#include <inttypes.h>
+
+#if defined (c_plusplus) || defined (__cplusplus)
+extern "C" {
+#endif
+
+enum
+{
+ H_ACCEPT = 0,
+ H_ACC_CHARSET,
+ H_ACC_ENCODING,
+ H_ACC_LANG,
+ H_AUTHORIZATION,
+ H_CONNECTION,
+ H_CONTENT_TYPE,
+ H_CONTENT_LENGTH,
+ H_COOKIE,
+ H_COOKIE2,
+ H_HOST,
+ H_PRAGMA,
+ H_REFERER,
+ H_USERAGENT,
+ H_CACHE_CTRL,
+ H_IF_MODIFIED_SINCE,
+ H_IF_MATCH,
+ H_IF_NO_MATCH,
+ H_IF_RANGE,
+ H_IF_UNMOD_SINCE,
+ H_KEEP_ALIVE,
+ H_RANGE,
+ H_X_FORWARDED_FOR,
+ H_VIA,
+ H_TRANSFER_ENCODING
+
+};
+#define LSAPI_SOCK_FILENO 0
+
+#define LSAPI_VERSION_B0 'L'
+#define LSAPI_VERSION_B1 'S'
+
+/* Values for m_flag in lsapi_packet_header */
+#define LSAPI_ENDIAN_LITTLE 0
+#define LSAPI_ENDIAN_BIG 1
+#define LSAPI_ENDIAN_BIT 1
+
+#if defined(__i386__)||defined( __x86_64 )||defined( __x86_64__ )
+#define LSAPI_ENDIAN LSAPI_ENDIAN_LITTLE
+#else
+#define LSAPI_ENDIAN LSAPI_ENDIAN_BIG
+#endif
+
+/* Values for m_type in lsapi_packet_header */
+#define LSAPI_BEGIN_REQUEST 1
+#define LSAPI_ABORT_REQUEST 2
+#define LSAPI_RESP_HEADER 3
+#define LSAPI_RESP_STREAM 4
+#define LSAPI_RESP_END 5
+#define LSAPI_STDERR_STREAM 6
+#define LSAPI_REQ_RECEIVED 7
+
+
+#define LSAPI_MAX_HEADER_LEN 65535
+#define LSAPI_MAX_DATA_PACKET_LEN 16384
+
+#define LSAPI_RESP_HTTP_HEADER_MAX 4096
+#define LSAPI_PACKET_HEADER_LEN 8
+
+
+struct lsapi_packet_header
+{
+ char m_versionB0; /* LSAPI protocol version */
+ char m_versionB1;
+ char m_type;
+ char m_flag;
+ union
+ {
+ int32_t m_iLen; /* include this header */
+ char m_bytes[4];
+ }m_packetLen;
+};
+
+/*
+ LSAPI request header packet
+
+ 1. struct lsapi_req_header
+ 2. struct lsapi_http_header_index
+ 3. lsapi_header_offset * unknownHeaders
+ 4. org http request header
+ 5. request body if available
+*/
+
+struct lsapi_req_header
+{
+ struct lsapi_packet_header m_pktHeader;
+
+ int32_t m_httpHeaderLen;
+ int32_t m_reqBodyLen;
+ int32_t m_scriptFileOff; /* path to the script file. */
+ int32_t m_scriptNameOff; /* decrypted URI, without pathinfo, */
+ int32_t m_queryStringOff; /* Query string inside env */
+ int32_t m_requestMethodOff;
+ int32_t m_cntUnknownHeaders;
+ int32_t m_cntEnv;
+ int32_t m_cntSpecialEnv;
+} ;
+
+
+struct lsapi_http_header_index
+{
+ int16_t m_headerLen[H_TRANSFER_ENCODING+1];
+ int32_t m_headerOff[H_TRANSFER_ENCODING+1];
+} ;
+
+struct lsapi_header_offset
+{
+ int32_t nameOff;
+ int32_t nameLen;
+ int32_t valueOff;
+ int32_t valueLen;
+} ;
+
+struct lsapi_resp_info
+{
+ int32_t m_cntHeaders;
+ int32_t m_status;
+};
+
+struct lsapi_resp_header
+{
+ struct lsapi_packet_header m_pktHeader;
+ struct lsapi_resp_info m_respInfo;
+};
+
+#if defined (c_plusplus) || defined (__cplusplus)
+}
+#endif
+
+
+#endif
+
diff --git a/sapi/litespeed/lsapilib.c b/sapi/litespeed/lsapilib.c
new file mode 100644
index 000000000..5d0e43aba
--- /dev/null
+++ b/sapi/litespeed/lsapilib.c
@@ -0,0 +1,2192 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2007 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: George Wang <gwang@litespeedtech.com> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id: lsapilib.c,v 1.5.2.6 2009/02/27 23:33:01 gwang Exp $ */
+
+/*
+Copyright (c) 2007, Lite Speed Technologies Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+ * Neither the name of the Lite Speed Technologies Inc nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <lsapilib.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <sys/un.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/resource.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/uio.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <unistd.h>
+
+#define LSAPI_ST_REQ_HEADER 1
+#define LSAPI_ST_REQ_BODY 2
+#define LSAPI_ST_RESP_HEADER 4
+#define LSAPI_ST_RESP_BODY 8
+
+#define LSAPI_RESP_BUF_SIZE 8192
+#define LSAPI_INIT_RESP_HEADER_LEN 4096
+
+
+static int g_inited = 0;
+static int g_running = 1;
+static int s_ppid;
+LSAPI_Request g_req = { -1, -1 };
+
+void Flush_RespBuf_r( LSAPI_Request * pReq );
+
+static const char *CGI_HEADERS[H_TRANSFER_ENCODING+1] =
+{
+ "HTTP_ACCEPT", "HTTP_ACCEPT_CHARSET",
+ "HTTP_ACCEPT_ENCODING",
+ "HTTP_ACCEPT_LANGUAGE", "HTTP_AUTHORIZATION",
+ "HTTP_CONNECTION", "CONTENT_TYPE",
+ "CONTENT_LENGTH", "HTTP_COOKIE", "HTTP_COOKIE2",
+ "HTTP_HOST", "HTTP_PRAGMA",
+ "HTTP_REFERER", "HTTP_USER_AGENT",
+ "HTTP_CACHE_CONTROL",
+ "HTTP_IF_MODIFIED_SINCE", "HTTP_IF_MATCH",
+ "HTTP_IF_NONE_MATCH",
+ "HTTP_IF_RANGE",
+ "HTTP_IF_UNMODIFIED_SINCE",
+ "HTTP_KEEP_ALIVE",
+ "HTTP_RANGE",
+ "HTTP_X_FORWARDED_FOR",
+ "HTTP_VIA",
+ "HTTP_TRANSFER_ENCODING"
+};
+
+static int CGI_HEADER_LEN[H_TRANSFER_ENCODING+1] = {
+ 11, 19, 20, 20, 18, 15, 12, 14, 11, 12, 9, 11, 12, 15, 18,
+ 22, 13, 18, 13, 24, 15, 10, 20, 8, 22
+};
+
+
+static const char *HTTP_HEADERS[H_TRANSFER_ENCODING+1] = {
+ "Accept", "Accept-Charset",
+ "Accept-Encoding",
+ "Accept-Language", "Authorization",
+ "Connection", "Content-Type",
+ "Content-Length", "Cookie", "Cookie2",
+ "Host", "Pragma",
+ "Referer", "User-Agent",
+ "Cache-Control",
+ "If-Modified-Since", "If-Match",
+ "If-None-Match",
+ "If-Range",
+ "If-Unmodified-Since",
+ "Keep-Alive",
+ "Range",
+ "X-Forwarded-For",
+ "Via",
+ "Transfer-Encoding"
+};
+
+static int HTTP_HEADER_LEN[H_TRANSFER_ENCODING+1] = {
+ 6, 14, 15, 15, 13, 10, 12, 14, 6, 7, 4, 6, 7, 10, /* user-agent */
+ 13,17, 8, 13, 8, 19, 10, 5, 15, 3, 17
+};
+
+static void lsapi_sigpipe( int sig )
+{
+}
+static void lsapi_siguser1( int sig )
+{
+ g_running = 0;
+}
+
+#ifndef sighandler_t
+typedef void (*sighandler_t)(int);
+#endif
+
+static void lsapi_signal(int signo, sighandler_t handler)
+{
+ struct sigaction sa;
+
+ sigaction(signo, NULL, &sa);
+
+ if (sa.sa_handler == SIG_DFL) {
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = handler;
+ sigaction(signo, &sa, NULL);
+ }
+}
+
+
+static inline void lsapi_buildPacketHeader( struct lsapi_packet_header * pHeader,
+ char type, int len )
+{
+ pHeader->m_versionB0 = LSAPI_VERSION_B0; /* LSAPI protocol version */
+ pHeader->m_versionB1 = LSAPI_VERSION_B1;
+ pHeader->m_type = type;
+ pHeader->m_flag = LSAPI_ENDIAN;
+ pHeader->m_packetLen.m_iLen = len;
+}
+
+static int lsapi_set_nblock( int fd, int nonblock )
+{
+ int val = fcntl( fd, F_GETFL, 0 );
+ if ( nonblock )
+ {
+ if (!( val & O_NONBLOCK ))
+ {
+ return fcntl( fd, F_SETFL, val | O_NONBLOCK );
+ }
+ }
+ else
+ {
+ if ( val & O_NONBLOCK )
+ {
+ return fcntl( fd, F_SETFL, val &(~O_NONBLOCK) );
+ }
+ }
+ return 0;
+}
+
+
+static int lsapi_close( int fd )
+{
+ int ret;
+ while( 1 ) {
+ ret = close( fd );
+ if (( ret == -1 )&&( errno == EINTR )&&(g_running)) {
+ continue;
+ }
+ return ret;
+ }
+}
+
+static inline int lsapi_read( int fd, void * pBuf, int len )
+{
+ int ret;
+ while( 1 ) {
+ ret = read( fd, (char *)pBuf, len );
+ if (( ret == -1 )&&( errno == EINTR )&&(g_running)) {
+ continue;
+ }
+ return ret;
+ }
+}
+
+
+static int lsapi_writev( int fd, struct iovec ** pVec, int count, int totalLen )
+{
+ int ret;
+ int left = totalLen;
+ int n = count;
+ while(( left > 0 )&&g_running ) {
+ ret = writev( fd, *pVec, n );
+ if ( ret > 0 ) {
+ left -= ret;
+ if (( left <= 0)||( !g_running )) {
+ return totalLen - left;
+ }
+ while( ret > 0 ) {
+ if ( (*pVec)->iov_len <= ret ) {
+ ret -= (*pVec)->iov_len;
+ ++(*pVec);
+ } else {
+ (*pVec)->iov_base = (char *)(*pVec)->iov_base + ret;
+ (*pVec)->iov_len -= ret;
+ break;
+ }
+ }
+ } else if ( ret == -1 ) {
+ if ( errno == EAGAIN ) {
+ if ( totalLen - left > 0 ) {
+ return totalLen - left;
+ } else {
+ return -1;
+ }
+ } else {
+ if ( errno != EINTR ) {
+ return ret;
+ }
+ }
+ }
+ }
+ return totalLen - left;
+}
+
+static inline int allocateBuf( LSAPI_Request * pReq, int size )
+{
+ char * pBuf = (char *)realloc( pReq->m_pReqBuf, size );
+ if ( pBuf ) {
+ pReq->m_pReqBuf = pBuf;
+ pReq->m_reqBufSize = size;
+ pReq->m_pHeader = (struct lsapi_req_header *)pReq->m_pReqBuf;
+ return 0;
+ }
+ return -1;
+}
+
+
+static int allocateIovec( LSAPI_Request * pReq, int n )
+{
+ struct iovec * p = (struct iovec *)realloc(
+ pReq->m_pIovec, sizeof(struct iovec) * n );
+ if ( !p ) {
+ return -1;
+ }
+ pReq->m_pIovecToWrite = p + ( pReq->m_pIovecToWrite - pReq->m_pIovec );
+ pReq->m_pIovecCur = p + ( pReq->m_pIovecCur - pReq->m_pIovec );
+ pReq->m_pIovec = p;
+ pReq->m_pIovecEnd = p + n;
+ return 0;
+}
+
+static int allocateRespHeaderBuf( LSAPI_Request * pReq, int size )
+{
+ char * p = (char *)realloc( pReq->m_pRespHeaderBuf, size );
+ if ( !p ) {
+ return -1;
+ }
+ pReq->m_pRespHeaderBufPos = p + ( pReq->m_pRespHeaderBufPos - pReq->m_pRespHeaderBuf );
+ pReq->m_pRespHeaderBuf = p;
+ pReq->m_pRespHeaderBufEnd = p + size;
+ return 0;
+}
+
+
+static inline int verifyHeader( struct lsapi_packet_header * pHeader, char pktType )
+{
+ if (( LSAPI_VERSION_B0 != pHeader->m_versionB0 )||
+ ( LSAPI_VERSION_B1 != pHeader->m_versionB1 )||
+ ( pktType != pHeader->m_type )) {
+ return -1;
+ }
+ if ( LSAPI_ENDIAN != (pHeader->m_flag & LSAPI_ENDIAN_BIT )) {
+ register char b;
+ b = pHeader->m_packetLen.m_bytes[0];
+ pHeader->m_packetLen.m_bytes[0] = pHeader->m_packetLen.m_bytes[3];
+ pHeader->m_packetLen.m_bytes[3] = b;
+ b = pHeader->m_packetLen.m_bytes[1];
+ pHeader->m_packetLen.m_bytes[1] = pHeader->m_packetLen.m_bytes[2];
+ pHeader->m_packetLen.m_bytes[2] = b;
+ }
+ return pHeader->m_packetLen.m_iLen;
+}
+
+static int allocateEnvList( struct LSAPI_key_value_pair ** pEnvList,
+ int *curSize, int newSize )
+{
+ struct LSAPI_key_value_pair * pBuf;
+ if ( *curSize >= newSize ) {
+ return 0;
+ }
+ if ( newSize > 8192 ) {
+ return -1;
+ }
+ pBuf = (struct LSAPI_key_value_pair *)realloc( *pEnvList, newSize *
+ sizeof(struct LSAPI_key_value_pair) );
+ if ( pBuf ) {
+ *pEnvList = pBuf;
+ *curSize = newSize;
+ return 0;
+ } else {
+ return -1;
+ }
+
+}
+
+static inline int isPipe( int fd )
+{
+ char achPeer[128];
+ socklen_t len = 128;
+ if (( getpeername( fd, (struct sockaddr *)achPeer, &len ) != 0 )&&
+ ( errno == ENOTCONN )) {
+ return 0;
+ } else {
+ return 1;
+ }
+}
+
+static int parseEnv( struct LSAPI_key_value_pair * pEnvList, int count,
+ char **pBegin, char * pEnd )
+{
+ struct LSAPI_key_value_pair * pEnvEnd;
+ int keyLen = 0, valLen = 0;
+ if ( count > 8192 ) {
+ return -1;
+ }
+ pEnvEnd = pEnvList + count;
+ while( pEnvList != pEnvEnd ) {
+ if ( pEnd - *pBegin < 4 ) {
+ return -1;
+ }
+ keyLen = *((unsigned char *)((*pBegin)++));
+ keyLen = (keyLen << 8) + *((unsigned char *)((*pBegin)++));
+ valLen = *((unsigned char *)((*pBegin)++));
+ valLen = (valLen << 8) + *((unsigned char *)((*pBegin)++));
+ if ( *pBegin + keyLen + valLen > pEnd ) {
+ return -1;
+ }
+ if (( !keyLen )||( !valLen )) {
+ return -1;
+ }
+
+ pEnvList->pKey = *pBegin;
+ *pBegin += keyLen;
+ pEnvList->pValue = *pBegin;
+ *pBegin += valLen;
+
+ pEnvList->keyLen = keyLen - 1;
+ pEnvList->valLen = valLen - 1;
+ ++pEnvList;
+ }
+ if ( memcmp( *pBegin, "\0\0\0\0", 4 ) != 0 ) {
+ return -1;
+ }
+ *pBegin += 4;
+ return 0;
+}
+
+static inline void swapIntEndian( int * pInteger )
+{
+ char * p = (char *)pInteger;
+ register char b;
+ b = p[0];
+ p[0] = p[3];
+ p[3] = b;
+ b = p[1];
+ p[1] = p[2];
+ p[2] = b;
+
+}
+
+static inline void fixEndian( LSAPI_Request * pReq )
+{
+ struct lsapi_req_header *p= pReq->m_pHeader;
+ swapIntEndian( &p->m_httpHeaderLen );
+ swapIntEndian( &p->m_reqBodyLen );
+ swapIntEndian( &p->m_scriptFileOff );
+ swapIntEndian( &p->m_scriptNameOff );
+ swapIntEndian( &p->m_queryStringOff );
+ swapIntEndian( &p->m_requestMethodOff );
+ swapIntEndian( &p->m_cntUnknownHeaders );
+ swapIntEndian( &p->m_cntEnv );
+ swapIntEndian( &p->m_cntSpecialEnv );
+}
+
+static void fixHeaderIndexEndian( LSAPI_Request * pReq )
+{
+ int i;
+ for( i = 0; i < H_TRANSFER_ENCODING; ++i ) {
+ if ( pReq->m_pHeaderIndex->m_headerOff[i] ) {
+ register char b;
+ char * p = (char *)(&pReq->m_pHeaderIndex->m_headerLen[i]);
+ b = p[0];
+ p[0] = p[1];
+ p[1] = b;
+ swapIntEndian( &pReq->m_pHeaderIndex->m_headerOff[i] );
+ }
+ }
+ if ( pReq->m_pHeader->m_cntUnknownHeaders > 0 ) {
+ struct lsapi_header_offset * pCur, *pEnd;
+ pCur = pReq->m_pUnknownHeader;
+ pEnd = pCur + pReq->m_pHeader->m_cntUnknownHeaders;
+ while( pCur < pEnd ) {
+ swapIntEndian( &pCur->nameOff );
+ swapIntEndian( &pCur->nameLen );
+ swapIntEndian( &pCur->valueOff );
+ swapIntEndian( &pCur->valueLen );
+ ++pCur;
+ }
+ }
+}
+
+static int parseRequest( LSAPI_Request * pReq, int totalLen )
+{
+ int shouldFixEndian;
+ char * pBegin = pReq->m_pReqBuf + sizeof( struct lsapi_req_header );
+ char * pEnd = pReq->m_pReqBuf + totalLen;
+ shouldFixEndian = ( LSAPI_ENDIAN != (
+ pReq->m_pHeader->m_pktHeader.m_flag & LSAPI_ENDIAN_BIT ) );
+ if ( shouldFixEndian ) {
+ fixEndian( pReq );
+ }
+ if ( (pReq->m_specialEnvListSize < pReq->m_pHeader->m_cntSpecialEnv )&&
+ allocateEnvList( &pReq->m_pSpecialEnvList,
+ &pReq->m_specialEnvListSize,
+ pReq->m_pHeader->m_cntSpecialEnv ) == -1 ) {
+ return -1;
+ }
+ if ( (pReq->m_envListSize < pReq->m_pHeader->m_cntEnv )&&
+ allocateEnvList( &pReq->m_pEnvList, &pReq->m_envListSize,
+ pReq->m_pHeader->m_cntEnv ) == -1 ) {
+ return -1;
+ }
+ if ( parseEnv( pReq->m_pSpecialEnvList,
+ pReq->m_pHeader->m_cntSpecialEnv,
+ &pBegin, pEnd ) == -1 ) {
+ return -1;
+ }
+ if ( parseEnv( pReq->m_pEnvList, pReq->m_pHeader->m_cntEnv,
+ &pBegin, pEnd ) == -1 ) {
+ return -1;
+ }
+ pReq->m_pScriptFile = pReq->m_pReqBuf + pReq->m_pHeader->m_scriptFileOff;
+ pReq->m_pScriptName = pReq->m_pReqBuf + pReq->m_pHeader->m_scriptNameOff;
+ pReq->m_pQueryString = pReq->m_pReqBuf + pReq->m_pHeader->m_queryStringOff;
+ pReq->m_pRequestMethod = pReq->m_pReqBuf + pReq->m_pHeader->m_requestMethodOff;
+
+ pBegin = pReq->m_pReqBuf + (( pBegin - pReq->m_pReqBuf + 7 ) & (~0x7));
+ pReq->m_pHeaderIndex = ( struct lsapi_http_header_index * )pBegin;
+ pBegin += sizeof( struct lsapi_http_header_index );
+
+ pReq->m_pUnknownHeader = (struct lsapi_header_offset *)pBegin;
+ pBegin += sizeof( struct lsapi_header_offset) *
+ pReq->m_pHeader->m_cntUnknownHeaders;
+
+ pReq->m_pHttpHeader = pBegin;
+ pBegin += pReq->m_pHeader->m_httpHeaderLen;
+ if ( pBegin != pEnd ) {
+ return -1;
+ }
+
+ if ( shouldFixEndian ) {
+ fixHeaderIndexEndian( pReq );
+ }
+
+ return 0;
+}
+
+static struct lsapi_packet_header ack = {'L', 'S',
+ LSAPI_REQ_RECEIVED, LSAPI_ENDIAN, {LSAPI_PACKET_HEADER_LEN} };
+static inline int notify_req_received( LSAPI_Request * pReq )
+{
+ if ( write( pReq->m_fd, &ack, LSAPI_PACKET_HEADER_LEN )
+ < LSAPI_PACKET_HEADER_LEN ) {
+ return -1;
+ }
+ return 0;
+}
+
+
+static int readReq( LSAPI_Request * pReq )
+{
+ int len;
+ int packetLen;
+ if ( !pReq ) {
+ return -1;
+ }
+ if ( pReq->m_reqBufSize < 8192 ) {
+ if ( allocateBuf( pReq, 8192 ) == -1 ) {
+ return -1;
+ }
+ }
+
+ while ( pReq->m_bufRead < LSAPI_PACKET_HEADER_LEN ) {
+ len = lsapi_read( pReq->m_fd, pReq->m_pReqBuf, pReq->m_reqBufSize );
+ if ( len <= 0 ) {
+ return -1;
+ }
+ pReq->m_bufRead += len;
+ }
+ pReq->m_reqState = LSAPI_ST_REQ_HEADER;
+
+ packetLen = verifyHeader( &pReq->m_pHeader->m_pktHeader, LSAPI_BEGIN_REQUEST );
+ if ( packetLen < 0 ) {
+ return -1;
+ }
+ if ( packetLen > LSAPI_MAX_HEADER_LEN ) {
+ return -1;
+ }
+
+ if ( packetLen + 1024 > pReq->m_reqBufSize ) {
+ if ( allocateBuf( pReq, packetLen + 1024 ) == -1 ) {
+ return -1;
+ }
+ }
+ while( packetLen > pReq->m_bufRead ) {
+ len = lsapi_read( pReq->m_fd, pReq->m_pReqBuf + pReq->m_bufRead, packetLen - pReq->m_bufRead );
+ if ( len <= 0 ) {
+ return -1;
+ }
+ pReq->m_bufRead += len;
+ }
+ if ( parseRequest( pReq, packetLen ) < 0 ) {
+ return -1;
+ }
+ pReq->m_bufProcessed = packetLen;
+ pReq->m_reqState = LSAPI_ST_REQ_BODY | LSAPI_ST_RESP_HEADER;
+
+ return notify_req_received( pReq );
+}
+
+
+
+int LSAPI_Init(void)
+{
+ if ( !g_inited ) {
+ lsapi_signal(SIGPIPE, lsapi_sigpipe);
+ lsapi_signal(SIGUSR1, lsapi_siguser1);
+
+#if defined(SIGXFSZ) && defined(SIG_IGN)
+ signal(SIGXFSZ, SIG_IGN);
+#endif
+ /* let STDOUT function as STDERR,
+ just in case writing to STDOUT directly */
+ dup2( 2, 1 );
+
+ if ( LSAPI_InitRequest( &g_req, LSAPI_SOCK_FILENO ) == -1 ) {
+ return -1;
+ }
+ g_inited = 1;
+ s_ppid = getppid();
+ }
+ return 0;
+}
+
+void LSAPI_Stop(void)
+{
+ g_running = 0;
+}
+
+int LSAPI_IsRunning(void)
+{
+ return g_running;
+}
+
+int LSAPI_InitRequest( LSAPI_Request * pReq, int fd )
+{
+ if ( !pReq ) {
+ return -1;
+ }
+ memset( pReq, 0, sizeof( LSAPI_Request ) );
+ if ( allocateIovec( pReq, 16 ) == -1 ) {
+ return -1;
+ }
+ pReq->m_pRespBuf = pReq->m_pRespBufPos = (char *)malloc( LSAPI_RESP_BUF_SIZE );
+ if ( !pReq->m_pRespBuf ) {
+ return -1;
+ }
+ pReq->m_pRespBufEnd = pReq->m_pRespBuf + LSAPI_RESP_BUF_SIZE;
+ pReq->m_pIovecCur = pReq->m_pIovecToWrite = pReq->m_pIovec + 1;
+ pReq->m_respPktHeaderEnd = &pReq->m_respPktHeader[5];
+ if ( allocateRespHeaderBuf( pReq, LSAPI_INIT_RESP_HEADER_LEN ) == -1 ) {
+ return -1;
+ }
+
+ if ( isPipe( fd ) ) {
+ pReq->m_fdListen = -1;
+ pReq->m_fd = fd;
+ } else {
+ pReq->m_fdListen = fd;
+ pReq->m_fd = -1;
+ lsapi_set_nblock( fd, 1 );
+ }
+ return 0;
+}
+
+int LSAPI_Is_Listen( void )
+{
+ return LSAPI_Is_Listen_r( &g_req );
+}
+
+int LSAPI_Is_Listen_r( LSAPI_Request * pReq)
+{
+ return pReq->m_fdListen != -1;
+}
+
+
+
+int LSAPI_Accept_r( LSAPI_Request * pReq )
+{
+ char achPeer[128];
+ socklen_t len;
+ int nodelay = 1;
+
+ if ( !pReq ) {
+ return -1;
+ }
+ if ( LSAPI_Finish_r( pReq ) == -1 ) {
+ return -1;
+ }
+ while( g_running ) {
+ if ( pReq->m_fd == -1 ) {
+ if ( pReq->m_fdListen != -1) {
+ len = sizeof( achPeer );
+ pReq->m_fd = accept( pReq->m_fdListen,
+ (struct sockaddr *)&achPeer, &len );
+ if ( pReq->m_fd == -1 ) {
+ if (( errno == EINTR )||( errno == EAGAIN)) {
+ continue;
+ } else {
+ return -1;
+ }
+ } else {
+ lsapi_set_nblock( pReq->m_fd , 0 );
+ if (((struct sockaddr *)&achPeer)->sa_family == AF_INET ) {
+ setsockopt(pReq->m_fd, IPPROTO_TCP, TCP_NODELAY,
+ (char *)&nodelay, sizeof(nodelay));
+ }
+ }
+ } else {
+ return -1;
+ }
+ }
+ if ( !readReq( pReq ) ) {
+ break;
+ }
+ lsapi_close( pReq->m_fd );
+ pReq->m_fd = -1;
+ LSAPI_Reset_r( pReq );
+ }
+ return 0;
+}
+
+static struct lsapi_packet_header finish = {'L', 'S',
+ LSAPI_RESP_END, LSAPI_ENDIAN, {LSAPI_PACKET_HEADER_LEN} };
+
+int LSAPI_Finish_r( LSAPI_Request * pReq )
+{
+ /* finish req body */
+ if ( !pReq ) {
+ return -1;
+ }
+ if (pReq->m_reqState) {
+ if ( pReq->m_fd != -1 ) {
+ if ( pReq->m_reqState & LSAPI_ST_RESP_HEADER ) {
+ LSAPI_FinalizeRespHeaders_r( pReq );
+ }
+ if ( pReq->m_pRespBufPos != pReq->m_pRespBuf ) {
+ Flush_RespBuf_r( pReq );
+ }
+
+ pReq->m_pIovecCur->iov_base = (void *)&finish;
+ pReq->m_pIovecCur->iov_len = LSAPI_PACKET_HEADER_LEN;
+ pReq->m_totalLen += LSAPI_PACKET_HEADER_LEN;
+ ++pReq->m_pIovecCur;
+ LSAPI_Flush_r( pReq );
+ }
+ LSAPI_Reset_r( pReq );
+ }
+ return 0;
+}
+
+
+void LSAPI_Reset_r( LSAPI_Request * pReq )
+{
+ pReq->m_pRespBufPos = pReq->m_pRespBuf;
+ pReq->m_pIovecCur = pReq->m_pIovecToWrite = pReq->m_pIovec + 1;
+ pReq->m_pRespHeaderBufPos = pReq->m_pRespHeaderBuf;
+
+ memset( &pReq->m_pHeaderIndex, 0,
+ (char *)(pReq->m_respHeaderLen) - (char *)&pReq->m_pHeaderIndex );
+}
+
+
+int LSAPI_Release_r( LSAPI_Request * pReq )
+{
+ if ( pReq->m_pReqBuf ) {
+ free( pReq->m_pReqBuf );
+ }
+ if ( pReq->m_pSpecialEnvList ) {
+ free( pReq->m_pSpecialEnvList );
+ }
+ if ( pReq->m_pEnvList ) {
+ free( pReq->m_pEnvList );
+ }
+ if ( pReq->m_pRespHeaderBuf ) {
+ free( pReq->m_pRespHeaderBuf );
+ }
+ return 0;
+}
+
+
+char * LSAPI_GetHeader_r( LSAPI_Request * pReq, int headerIndex )
+{
+ int off;
+ if ( !pReq || ((unsigned int)headerIndex > H_TRANSFER_ENCODING) ) {
+ return NULL;
+ }
+ off = pReq->m_pHeaderIndex->m_headerOff[ headerIndex ];
+ if ( !off ) {
+ return NULL;
+ }
+ if ( *(pReq->m_pHttpHeader + off +
+ pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) ) {
+ *( pReq->m_pHttpHeader + off +
+ pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) = 0;
+ }
+ return pReq->m_pHttpHeader + off;
+}
+
+static int readBodyToReqBuf( LSAPI_Request * pReq )
+{
+ int bodyLeft;
+ int len = pReq->m_bufRead - pReq->m_bufProcessed;
+ if ( len > 0 ) {
+ return len;
+ }
+ pReq->m_bufRead = pReq->m_bufProcessed = pReq->m_pHeader->m_pktHeader.m_packetLen.m_iLen;
+
+ bodyLeft = pReq->m_pHeader->m_reqBodyLen - pReq->m_reqBodyRead;
+ len = pReq->m_reqBufSize - pReq->m_bufRead;
+ if ( len < 0 ) {
+ return -1;
+ }
+ if ( len > bodyLeft ) {
+ len = bodyLeft;
+ }
+ len = lsapi_read( pReq->m_fd, pReq->m_pReqBuf + pReq->m_bufRead, len );
+ if ( len > 0 ) {
+ pReq->m_bufRead += len;
+ }
+ return len;
+}
+
+
+int LSAPI_ReqBodyGetChar_r( LSAPI_Request * pReq )
+{
+ if (!pReq || (pReq->m_fd ==-1) ) {
+ return EOF;
+ }
+ if ( pReq->m_bufProcessed >= pReq->m_bufRead ) {
+ if ( readBodyToReqBuf( pReq ) <= 0 ) {
+ return EOF;
+ }
+ }
+ ++pReq->m_reqBodyRead;
+ return (unsigned char)*(pReq->m_pReqBuf + pReq->m_bufProcessed++);
+}
+
+
+
+int LSAPI_ReqBodyGetLine_r( LSAPI_Request * pReq, char * pBuf, int bufLen, int *getLF )
+{
+ int len;
+ int left;
+ char * pBufEnd = pBuf + bufLen - 1;
+ char * pBufCur = pBuf;
+ char * pCur;
+ char * p;
+ if (!pReq || (pReq->m_fd ==-1) ||( !pBuf )||(bufLen < 0 )|| !getLF ) {
+ return -1;
+ }
+ *getLF = 0;
+ while( (left = pBufEnd - pBufCur ) > 0 ) {
+
+ len = pReq->m_bufRead - pReq->m_bufProcessed;
+ if ( len <= 0 ) {
+ if ( (len = readBodyToReqBuf( pReq )) <= 0 ) {
+ *getLF = 1;
+ break;
+ }
+ }
+ if ( len > left ) {
+ len = left;
+ }
+ pCur = pReq->m_pReqBuf + pReq->m_bufProcessed;
+ p = memchr( pCur, '\n', len );
+ if ( p ) {
+ len = p - pCur + 1;
+ }
+ memmove( pBufCur, pCur, len );
+ pBufCur += len;
+ pReq->m_bufProcessed += len;
+
+ pReq->m_reqBodyRead += len;
+
+ if ( p ) {
+ *getLF = 1;
+ break;
+ }
+ }
+ *pBufCur = 0;
+
+ return pBufCur - pBuf;
+}
+
+
+int LSAPI_ReadReqBody_r( LSAPI_Request * pReq, char * pBuf, int bufLen )
+{
+ int len;
+ int total;
+ /* char *pOldBuf = pBuf; */
+ if (!pReq || (pReq->m_fd ==-1) || ( !pBuf )||(bufLen < 0 )) {
+ return -1;
+ }
+ total = pReq->m_pHeader->m_reqBodyLen - pReq->m_reqBodyRead;
+
+ if ( total <= 0 ) {
+ return 0;
+ }
+ if ( total < bufLen ) {
+ bufLen = total;
+ }
+
+ total = 0;
+ len = pReq->m_bufRead - pReq->m_bufProcessed;
+ if ( len > 0 ) {
+ if ( len > bufLen ) {
+ len = bufLen;
+ }
+ memmove( pBuf, pReq->m_pReqBuf + pReq->m_bufProcessed, len );
+ pReq->m_bufProcessed += len;
+ total += len;
+ pBuf += len;
+ bufLen -= len;
+ }
+ while( bufLen > 0 ) {
+ len = lsapi_read( pReq->m_fd, pBuf, bufLen );
+ if ( len > 0 ) {
+ total += len;
+ pBuf += len;
+ bufLen -= len;
+ } else {
+ if ( len <= 0 ) {
+ if ( !total) {
+ return -1;
+ }
+ break;
+ }
+ }
+ }
+ pReq->m_reqBodyRead += total;
+ return total;
+
+}
+
+
+int LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, int len )
+{
+ struct lsapi_packet_header * pHeader;
+ const char * pEnd;
+ const char * p;
+ int bufLen;
+ int toWrite;
+ int packetLen;
+
+ if ( !pReq || !pBuf || (pReq->m_fd == -1) ) {
+ return -1;
+ }
+ if ( len < pReq->m_pRespBufEnd - pReq->m_pRespBufPos ) {
+ memmove( pReq->m_pRespBufPos, pBuf, len );
+ pReq->m_pRespBufPos += len;
+ return len;
+ }
+
+ if ( pReq->m_reqState & LSAPI_ST_RESP_HEADER ) {
+ LSAPI_FinalizeRespHeaders_r( pReq );
+ }
+ pReq->m_reqState |= LSAPI_ST_RESP_BODY;
+
+ pHeader = pReq->m_respPktHeader;
+ p = pBuf;
+ pEnd = pBuf + len;
+ bufLen = pReq->m_pRespBufPos - pReq->m_pRespBuf;
+
+ while( ( toWrite = pEnd - p ) > 0 ) {
+ packetLen = toWrite + bufLen;
+ if ( LSAPI_MAX_DATA_PACKET_LEN < packetLen) {
+ packetLen = LSAPI_MAX_DATA_PACKET_LEN;
+ toWrite = packetLen - bufLen;
+ }
+
+ lsapi_buildPacketHeader( pHeader, LSAPI_RESP_STREAM,
+ packetLen + LSAPI_PACKET_HEADER_LEN );
+ pReq->m_totalLen += packetLen + LSAPI_PACKET_HEADER_LEN;
+
+ pReq->m_pIovecCur->iov_base = (void *)pHeader;
+ pReq->m_pIovecCur->iov_len = LSAPI_PACKET_HEADER_LEN;
+ ++pReq->m_pIovecCur;
+ ++pHeader;
+ if ( bufLen > 0 ) {
+ pReq->m_pIovecCur->iov_base = (void *)pReq->m_pRespBuf;
+ pReq->m_pIovecCur->iov_len = bufLen;
+ pReq->m_pRespBufPos = pReq->m_pRespBuf;
+ ++pReq->m_pIovecCur;
+ bufLen = 0;
+ }
+
+ pReq->m_pIovecCur->iov_base = (void *)p;
+ pReq->m_pIovecCur->iov_len = toWrite;
+ ++pReq->m_pIovecCur;
+ p += toWrite;
+
+ if ( pHeader >= pReq->m_respPktHeaderEnd - 1) {
+ if ( LSAPI_Flush_r( pReq ) == -1 ) {
+ return -1;
+ }
+ pHeader = pReq->m_respPktHeader;
+ }
+ }
+ if ( pHeader != pReq->m_respPktHeader ) {
+ if ( LSAPI_Flush_r( pReq ) == -1 ) {
+ return -1;
+ }
+ }
+ return p - pBuf;
+}
+
+void Flush_RespBuf_r( LSAPI_Request * pReq )
+{
+ struct lsapi_packet_header * pHeader = pReq->m_respPktHeader;
+ int bufLen = pReq->m_pRespBufPos - pReq->m_pRespBuf;
+ pReq->m_reqState |= LSAPI_ST_RESP_BODY;
+ lsapi_buildPacketHeader( pHeader, LSAPI_RESP_STREAM,
+ bufLen + LSAPI_PACKET_HEADER_LEN );
+ pReq->m_totalLen += bufLen + LSAPI_PACKET_HEADER_LEN;
+
+ pReq->m_pIovecCur->iov_base = (void *)pHeader;
+ pReq->m_pIovecCur->iov_len = LSAPI_PACKET_HEADER_LEN;
+ ++pReq->m_pIovecCur;
+ ++pHeader;
+ if ( bufLen > 0 ) {
+ pReq->m_pIovecCur->iov_base = (void *)pReq->m_pRespBuf;
+ pReq->m_pIovecCur->iov_len = bufLen;
+ pReq->m_pRespBufPos = pReq->m_pRespBuf;
+ ++pReq->m_pIovecCur;
+ bufLen = 0;
+ }
+}
+
+
+
+
+int LSAPI_Flush_r( LSAPI_Request * pReq )
+{
+ int ret = 0;
+ int n;
+ if ( !pReq ) {
+ return -1;
+ }
+ n = pReq->m_pIovecCur - pReq->m_pIovecToWrite;
+ if (( 0 == n )&&( pReq->m_pRespBufPos == pReq->m_pRespBuf )) {
+ return 0;
+ }
+ if ( pReq->m_fd == -1 ) {
+ pReq->m_pRespBufPos = pReq->m_pRespBuf;
+ pReq->m_totalLen = 0;
+ pReq->m_pIovecCur = pReq->m_pIovecToWrite = pReq->m_pIovec;
+ return -1;
+ }
+ if ( pReq->m_reqState & LSAPI_ST_RESP_HEADER ) {
+ LSAPI_FinalizeRespHeaders_r( pReq );
+ }
+ if ( pReq->m_pRespBufPos != pReq->m_pRespBuf ) {
+ Flush_RespBuf_r( pReq );
+ }
+
+ n = pReq->m_pIovecCur - pReq->m_pIovecToWrite;
+ if ( n > 0 ) {
+
+ ret = lsapi_writev( pReq->m_fd, &pReq->m_pIovecToWrite,
+ n, pReq->m_totalLen );
+ if ( ret < pReq->m_totalLen ) {
+ lsapi_close( pReq->m_fd );
+ pReq->m_fd = -1;
+ ret = -1;
+ }
+ pReq->m_totalLen = 0;
+ pReq->m_pIovecCur = pReq->m_pIovecToWrite = pReq->m_pIovec;
+ }
+ return ret;
+}
+
+
+int LSAPI_Write_Stderr_r( LSAPI_Request * pReq, const char * pBuf, int len )
+{
+ struct lsapi_packet_header header;
+ const char * pEnd;
+ const char * p;
+ int packetLen;
+ int totalLen;
+ int ret;
+ struct iovec iov[2];
+ struct iovec *pIov;
+
+ if ( !pReq ) {
+ return -1;
+ }
+ if (( pReq->m_fd == -1 )||(pReq->m_fd == pReq->m_fdListen )) {
+ return write( 2, pBuf, len );
+ }
+ if ( pReq->m_pRespBufPos != pReq->m_pRespBuf ) {
+ LSAPI_Flush_r( pReq );
+ }
+
+ p = pBuf;
+ pEnd = pBuf + len;
+
+ while( ( packetLen = pEnd - p ) > 0 ) {
+ if ( LSAPI_MAX_DATA_PACKET_LEN < packetLen) {
+ packetLen = LSAPI_MAX_DATA_PACKET_LEN;
+ }
+
+ lsapi_buildPacketHeader( &header, LSAPI_STDERR_STREAM,
+ packetLen + LSAPI_PACKET_HEADER_LEN );
+ totalLen = packetLen + LSAPI_PACKET_HEADER_LEN;
+
+ iov[0].iov_base = (void *)&header;
+ iov[0].iov_len = LSAPI_PACKET_HEADER_LEN;
+
+ iov[1].iov_base = (void *)p;
+ iov[1].iov_len = packetLen;
+ p += packetLen;
+ pIov = iov;
+ ret = lsapi_writev( pReq->m_fd, &pIov,
+ 2, totalLen );
+ if ( ret < totalLen ) {
+ lsapi_close( pReq->m_fd );
+ pReq->m_fd = -1;
+ ret = -1;
+ }
+ }
+ return p - pBuf;
+}
+
+static char * GetHeaderVar( LSAPI_Request * pReq, const char * name )
+{
+ int i;
+ for( i = 0; i < H_TRANSFER_ENCODING; ++i ) {
+ if ( pReq->m_pHeaderIndex->m_headerOff[i] ) {
+ if ( strcmp( name, CGI_HEADERS[i] ) == 0 ) {
+ return pReq->m_pHttpHeader + pReq->m_pHeaderIndex->m_headerOff[i];
+ }
+ }
+ }
+ if ( pReq->m_pHeader->m_cntUnknownHeaders > 0 ) {
+ const char *p;
+ char *pKey;
+ char *pKeyEnd;
+ int keyLen;
+ struct lsapi_header_offset * pCur, *pEnd;
+ pCur = pReq->m_pUnknownHeader;
+ pEnd = pCur + pReq->m_pHeader->m_cntUnknownHeaders;
+ while( pCur < pEnd ) {
+ pKey = pReq->m_pHttpHeader + pCur->nameOff;
+ keyLen = pCur->nameLen;
+ pKeyEnd = pKey + keyLen;
+ p = &name[5];
+
+ while(( pKey < pKeyEnd )&&( *p )) {
+ char ch = toupper( *pKey );
+ if ((ch != *p )||(( *p == '_' )&&( ch != '-'))) {
+ break;
+ }
+ ++p; ++pKey;
+ }
+ if (( pKey == pKeyEnd )&& (!*p )) {
+ return pReq->m_pHttpHeader + pCur->valueOff;
+ }
+ ++pCur;
+ }
+ }
+ return NULL;
+}
+
+
+char * LSAPI_GetEnv_r( LSAPI_Request * pReq, const char * name )
+{
+ struct LSAPI_key_value_pair * pBegin = pReq->m_pEnvList;
+ struct LSAPI_key_value_pair * pEnd = pBegin + pReq->m_pHeader->m_cntEnv;
+ if ( !pReq || !name ) {
+ return NULL;
+ }
+ if ( strncmp( name, "HTTP_", 5 ) == 0 ) {
+ return GetHeaderVar( pReq, name );
+ }
+ while( pBegin < pEnd ) {
+ if ( strcmp( name, pBegin->pKey ) == 0 ) {
+ return pBegin->pValue;
+ }
+ ++pBegin;
+ }
+ return NULL;
+}
+
+int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq,
+ LSAPI_CB_EnvHandler fn, void * arg )
+{
+ int i;
+ int len = 0;
+ char * pValue;
+ int ret;
+ int count = 0;
+ if ( !pReq || !fn ) {
+ return -1;
+ }
+ for( i = 0; i < H_TRANSFER_ENCODING; ++i ) {
+ if ( pReq->m_pHeaderIndex->m_headerOff[i] ) {
+ len = pReq->m_pHeaderIndex->m_headerLen[i];
+ pValue = pReq->m_pHttpHeader + pReq->m_pHeaderIndex->m_headerOff[i];
+ *(pValue + len ) = 0;
+ ret = (*fn)( HTTP_HEADERS[i], HTTP_HEADER_LEN[i],
+ pValue, len, arg );
+ ++count;
+ if ( ret <= 0 ) {
+ return ret;
+ }
+ }
+ }
+ if ( pReq->m_pHeader->m_cntUnknownHeaders > 0 ) {
+ char *pKey;
+ int keyLen;
+ struct lsapi_header_offset * pCur, *pEnd;
+ pCur = pReq->m_pUnknownHeader;
+ pEnd = pCur + pReq->m_pHeader->m_cntUnknownHeaders;
+ while( pCur < pEnd ) {
+ pKey = pReq->m_pHttpHeader + pCur->nameOff;
+ keyLen = pCur->nameLen;
+
+ pValue = pReq->m_pHttpHeader + pCur->valueOff;
+ *(pValue + pCur->valueLen ) = 0;
+ ret = (*fn)( pKey, keyLen,
+ pValue, pCur->valueLen, arg );
+ if ( ret <= 0 ) {
+ return ret;
+ }
+ ++pCur;
+ }
+ }
+ return count + pReq->m_pHeader->m_cntUnknownHeaders;
+
+}
+
+
+int LSAPI_ForeachHeader_r( LSAPI_Request * pReq,
+ LSAPI_CB_EnvHandler fn, void * arg )
+{
+ int i;
+ int len = 0;
+ char * pValue;
+ int ret;
+ int count = 0;
+ if ( !pReq || !fn ) {
+ return -1;
+ }
+ for( i = 0; i < H_TRANSFER_ENCODING; ++i ) {
+ if ( pReq->m_pHeaderIndex->m_headerOff[i] ) {
+ len = pReq->m_pHeaderIndex->m_headerLen[i];
+ pValue = pReq->m_pHttpHeader + pReq->m_pHeaderIndex->m_headerOff[i];
+ *(pValue + len ) = 0;
+ ret = (*fn)( CGI_HEADERS[i], CGI_HEADER_LEN[i],
+ pValue, len, arg );
+ ++count;
+ if ( ret <= 0 ) {
+ return ret;
+ }
+ }
+ }
+ if ( pReq->m_pHeader->m_cntUnknownHeaders > 0 ) {
+ char achHeaderName[256];
+ char *p;
+ char *pKey;
+ char *pKeyEnd ;
+ int keyLen;
+ struct lsapi_header_offset * pCur, *pEnd;
+ pCur = pReq->m_pUnknownHeader;
+ pEnd = pCur + pReq->m_pHeader->m_cntUnknownHeaders;
+ while( pCur < pEnd ) {
+ pKey = pReq->m_pHttpHeader + pCur->nameOff;
+ keyLen = pCur->nameLen;
+ pKeyEnd = pKey + keyLen;
+ memcpy( achHeaderName, "HTTP_", 5 );
+ p = &achHeaderName[5];
+ if ( keyLen > 250 ) {
+ keyLen = 250;
+ }
+
+ while( pKey < pKeyEnd ) {
+ char ch = *pKey++;
+ if ( ch == '-' ) {
+ *p++ = '_';
+ } else {
+ *p++ = toupper( ch );
+ }
+ }
+ *p = 0;
+ keyLen += 5;
+
+ pValue = pReq->m_pHttpHeader + pCur->valueOff;
+ *(pValue + pCur->valueLen ) = 0;
+ ret = (*fn)( achHeaderName, keyLen,
+ pValue, pCur->valueLen, arg );
+ if ( ret <= 0 ) {
+ return ret;
+ }
+ ++pCur;
+ }
+ }
+ return count + pReq->m_pHeader->m_cntUnknownHeaders;
+
+}
+
+static int EnvForeach( struct LSAPI_key_value_pair * pEnv,
+ int n, LSAPI_CB_EnvHandler fn, void * arg )
+{
+ struct LSAPI_key_value_pair * pEnd = pEnv + n;
+ int ret;
+ if ( !pEnv || !fn ) {
+ return -1;
+ }
+ while( pEnv < pEnd ) {
+ ret = (*fn)( pEnv->pKey, pEnv->keyLen,
+ pEnv->pValue, pEnv->valLen, arg );
+ if ( ret <= 0 ) {
+ return ret;
+ }
+ ++pEnv;
+ }
+ return n;
+}
+
+
+
+int LSAPI_ForeachEnv_r( LSAPI_Request * pReq,
+ LSAPI_CB_EnvHandler fn, void * arg )
+{
+ if ( !pReq || !fn ) {
+ return -1;
+ }
+ if ( pReq->m_pHeader->m_cntEnv > 0 ) {
+ return EnvForeach( pReq->m_pEnvList, pReq->m_pHeader->m_cntEnv,
+ fn, arg );
+ }
+ return 0;
+}
+
+
+
+int LSAPI_ForeachSpecialEnv_r( LSAPI_Request * pReq,
+ LSAPI_CB_EnvHandler fn, void * arg )
+{
+ if ( !pReq || !fn ) {
+ return -1;
+ }
+ if ( pReq->m_pHeader->m_cntSpecialEnv > 0 ) {
+ return EnvForeach( pReq->m_pSpecialEnvList,
+ pReq->m_pHeader->m_cntSpecialEnv,
+ fn, arg );
+ }
+ return 0;
+
+}
+
+
+
+int LSAPI_FinalizeRespHeaders_r( LSAPI_Request * pReq )
+{
+ if ( !pReq || !pReq->m_pIovec ) {
+ return -1;
+ }
+ if ( !( pReq->m_reqState & LSAPI_ST_RESP_HEADER ) ) {
+ return 0;
+ }
+ pReq->m_reqState &= ~LSAPI_ST_RESP_HEADER;
+ if ( pReq->m_pRespHeaderBufPos > pReq->m_pRespHeaderBuf ) {
+ pReq->m_pIovecCur->iov_base = (void *)pReq->m_pRespHeaderBuf;
+ pReq->m_pIovecCur->iov_len = pReq->m_pRespHeaderBufPos - pReq->m_pRespHeaderBuf;
+ pReq->m_totalLen += pReq->m_pIovecCur->iov_len;
+ ++pReq->m_pIovecCur;
+ }
+
+ pReq->m_pIovec->iov_len = sizeof( struct lsapi_resp_header)
+ + pReq->m_respHeader.m_respInfo.m_cntHeaders * sizeof( short );
+ pReq->m_totalLen += pReq->m_pIovec->iov_len;
+
+ lsapi_buildPacketHeader( &pReq->m_respHeader.m_pktHeader,
+ LSAPI_RESP_HEADER, pReq->m_totalLen );
+ pReq->m_pIovec->iov_base = (void *)&pReq->m_respHeader;
+ pReq->m_pIovecToWrite = pReq->m_pIovec;
+ return 0;
+}
+
+
+
+
+int LSAPI_AppendRespHeader_r( LSAPI_Request * pReq, char * pBuf, int len )
+{
+ if ( !pReq || !pBuf || len <= 0 || len > LSAPI_RESP_HTTP_HEADER_MAX ) {
+ return -1;
+ }
+ if ( pReq->m_reqState & LSAPI_ST_RESP_BODY ) {
+ return -1;
+ }
+ if ( pReq->m_respHeader.m_respInfo.m_cntHeaders >= LSAPI_MAX_RESP_HEADERS ) {
+ return -1;
+ }
+ if ( pReq->m_pRespHeaderBufPos + len + 1 > pReq->m_pRespHeaderBufEnd ) {
+ int newlen = pReq->m_pRespHeaderBufPos + len + 4096 - pReq->m_pRespHeaderBuf;
+ newlen -= newlen % 4096;
+ if ( allocateRespHeaderBuf( pReq, newlen ) == -1 ) {
+ return -1;
+ }
+ }
+ memmove( pReq->m_pRespHeaderBufPos, pBuf, len );
+ pReq->m_pRespHeaderBufPos += len;
+ *pReq->m_pRespHeaderBufPos++ = 0;
+ ++len; /* add one byte padding for \0 */
+ pReq->m_respHeaderLen[pReq->m_respHeader.m_respInfo.m_cntHeaders] = len;
+ ++pReq->m_respHeader.m_respInfo.m_cntHeaders;
+ return 0;
+}
+
+
+int LSAPI_CreateListenSock2( const struct sockaddr * pServerAddr, int backlog )
+{
+ int ret;
+ int fd;
+ int flag = 1;
+ int addr_len;
+
+ switch( pServerAddr->sa_family ) {
+ case AF_INET:
+ addr_len = 16;
+ break;
+ case AF_INET6:
+ addr_len = sizeof( struct sockaddr_in6 );
+ break;
+ case AF_UNIX:
+ addr_len = sizeof( struct sockaddr_un );
+ unlink( ((struct sockaddr_un *)pServerAddr)->sun_path );
+ break;
+ default:
+ return -1;
+ }
+
+ fd = socket( pServerAddr->sa_family, SOCK_STREAM, 0 );
+ if ( fd == -1 ) {
+ return -1;
+ }
+
+ fcntl( fd, F_SETFD, FD_CLOEXEC );
+
+ if(setsockopt( fd, SOL_SOCKET, SO_REUSEADDR,
+ (char *)( &flag ), sizeof(flag)) == 0) {
+ ret = bind( fd, pServerAddr, addr_len );
+ if ( !ret ) {
+ ret = listen( fd, backlog );
+ if ( !ret ) {
+ return fd;
+ }
+ }
+ }
+
+ ret = errno;
+ close(fd);
+ errno = ret;
+ return -1;
+
+}
+
+int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr )
+{
+ char achAddr[256];
+ char * p = achAddr;
+ char * pEnd;
+ struct addrinfo *res, hints;
+ int doAddrInfo = 0;
+ int port;
+
+ if ( !pBind ) {
+ return -1;
+ }
+
+ while( isspace( *p ) ) {
+ ++pBind;
+ }
+
+ strncpy( achAddr, pBind, 256 );
+
+ switch( *p ) {
+ case '/':
+ pAddr->sa_family = AF_UNIX;
+ strncpy( ((struct sockaddr_un *)pAddr)->sun_path, p,
+ sizeof(((struct sockaddr_un *)pAddr)->sun_path) );
+ return 0;
+
+ case '[':
+ pAddr->sa_family = AF_INET6;
+ ++p;
+ pEnd = strchr( p, ']' );
+ if ( !pEnd )
+ return -1;
+ *pEnd++ = 0;
+
+ if ( *p == '*' ) {
+ strcpy( achAddr, "::" );
+ p = achAddr;
+ }
+ doAddrInfo = 1;
+ break;
+
+ default:
+ pAddr->sa_family = AF_INET;
+ pEnd = strchr( p, ':' );
+ if ( !pEnd ) {
+ return -1;
+ }
+ *pEnd++ = 0;
+
+ doAddrInfo = 0;
+ if ( *p == '*' ) {
+ ((struct sockaddr_in *)pAddr)->sin_addr.s_addr = htonl(INADDR_ANY);
+ } else {
+ if (!strcasecmp( p, "localhost" ) ) {
+ ((struct sockaddr_in *)pAddr)->sin_addr.s_addr = htonl( INADDR_LOOPBACK );
+ } else {
+ ((struct sockaddr_in *)pAddr)->sin_addr.s_addr = inet_addr( p );
+ if ( ((struct sockaddr_in *)pAddr)->sin_addr.s_addr == INADDR_BROADCAST) {
+ doAddrInfo = 1;
+ }
+ }
+ }
+ break;
+ }
+ if ( *pEnd == ':' ) {
+ ++pEnd;
+ }
+
+ port = atoi( pEnd );
+ if (( port <= 0 )||( port > 655535 )) {
+ return -1;
+ }
+ if ( doAddrInfo ) {
+
+ memset(&hints, 0, sizeof(hints));
+
+ hints.ai_family = pAddr->sa_family;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
+
+ if ( getaddrinfo(p, NULL, &hints, &res) ) {
+ return -1;
+ }
+
+ memcpy(pAddr, res->ai_addr, res->ai_addrlen);
+ freeaddrinfo(res);
+ }
+
+ if ( pAddr->sa_family == AF_INET ) {
+ ((struct sockaddr_in *)pAddr)->sin_port = htons( port );
+ } else {
+ ((struct sockaddr_in6 *)pAddr)->sin6_port = htons( port );
+ }
+ return 0;
+
+}
+
+int LSAPI_CreateListenSock( const char * pBind, int backlog )
+{
+ char serverAddr[128];
+ int ret;
+ int fd = -1;
+ ret = LSAPI_ParseSockAddr( pBind, (struct sockaddr *)serverAddr );
+ if ( !ret ) {
+ fd = LSAPI_CreateListenSock2( (struct sockaddr *)serverAddr, backlog );
+ }
+ return fd;
+}
+
+static fn_select_t g_fnSelect = select;
+
+typedef struct _lsapi_child_status
+{
+ int m_pid;
+
+ volatile short m_iKillSent;
+ volatile short m_inProcess;
+
+ volatile long m_tmWaitBegin;
+ volatile long m_tmReqBegin;
+ volatile long m_tmLastCheckPoint;
+}
+lsapi_child_status;
+
+static lsapi_child_status * s_pChildStatus = NULL;
+
+typedef struct _lsapi_prefork_server
+{
+ int m_fd;
+ int m_iMaxChildren;
+ int m_iExtraChildren;
+ int m_iCurChildren;
+ int m_iMaxIdleChildren;
+ int m_iServerMaxIdle;
+ int m_iChildrenMaxIdleTime;
+ int m_iMaxReqProcessTime;
+ int m_iAvoidFork;
+
+ lsapi_child_status * m_pChildrenStatus;
+
+}lsapi_prefork_server;
+
+static lsapi_prefork_server * g_prefork_server = NULL;
+
+int LSAPI_Init_Prefork_Server( int max_children, fn_select_t fp, int avoidFork )
+{
+ if ( g_prefork_server ) {
+ return 0;
+ }
+ if ( max_children <= 1 ) {
+ return -1;
+ }
+ if ( max_children >= 10000) {
+ max_children = 10000;
+ }
+
+
+ g_prefork_server = (lsapi_prefork_server *)malloc( sizeof( lsapi_prefork_server ) );
+ if ( !g_prefork_server ) {
+ return -1;
+ }
+ memset( g_prefork_server, 0, sizeof( lsapi_prefork_server ) );
+
+ if ( fp != NULL ) {
+ g_fnSelect = fp;
+ }
+
+ s_ppid = getppid();
+ g_prefork_server->m_iAvoidFork = avoidFork;
+ g_prefork_server->m_iMaxChildren = max_children;
+
+ g_prefork_server->m_iExtraChildren = ( avoidFork ) ? 0 : (max_children / 3) ;
+ g_prefork_server->m_iMaxIdleChildren = ( avoidFork ) ? (max_children + 1) : (max_children / 3);
+ g_prefork_server->m_iChildrenMaxIdleTime = 300;
+ g_prefork_server->m_iMaxReqProcessTime = 300;
+ return 0;
+}
+
+void LSAPI_Set_Server_fd( int fd )
+{
+ if( g_prefork_server ) {
+ g_prefork_server->m_fd = fd;
+ }
+}
+
+
+static int lsapi_accept( int fdListen )
+{
+ int fd;
+ int nodelay = 1;
+ socklen_t len;
+ char achPeer[128];
+
+ len = sizeof( achPeer );
+ fd = accept( fdListen, (struct sockaddr *)&achPeer, &len );
+ if ( fd != -1 ) {
+ if (((struct sockaddr *)&achPeer)->sa_family == AF_INET ) {
+ setsockopt( fd, IPPROTO_TCP, TCP_NODELAY,
+ (char *)&nodelay, sizeof(nodelay));
+ }
+ }
+ return fd;
+
+}
+
+
+
+
+static int s_req_processed = 0;
+static int s_max_reqs = 10000;
+static int s_max_idle_secs = 300;
+
+static int s_stop;
+
+static void lsapi_cleanup(int signal)
+{
+ s_stop = signal;
+}
+
+static lsapi_child_status * find_child_status( int pid )
+{
+ lsapi_child_status * pStatus = g_prefork_server->m_pChildrenStatus;
+ lsapi_child_status * pEnd = g_prefork_server->m_pChildrenStatus + g_prefork_server->m_iMaxChildren * 2;
+ while( pStatus < pEnd ) {
+ if ( pStatus->m_pid == pid ) {
+ return pStatus;
+ }
+ ++pStatus;
+ }
+ return NULL;
+}
+
+
+
+static void lsapi_sigchild( int signal )
+{
+ int status, pid;
+ lsapi_child_status * child_status;
+ while( 1 ) {
+ pid = waitpid( -1, &status, WNOHANG|WUNTRACED );
+ if ( pid <= 0 ) {
+ break;
+ }
+ child_status = find_child_status( pid );
+ if ( child_status ) {
+ child_status->m_pid = 0;
+ }
+ --g_prefork_server->m_iCurChildren;
+ }
+
+}
+
+static int lsapi_init_children_status()
+{
+ int size = 4096;
+
+ char * pBuf;
+ size = g_prefork_server->m_iMaxChildren * sizeof( lsapi_child_status ) * 2;
+ size = (size + 4095 ) / 4096 * 4096;
+ pBuf =( char*) mmap( NULL, size, PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_SHARED, -1, 0 );
+ if ( pBuf == MAP_FAILED ) {
+ perror( "Anonymous mmap() failed" );
+ return -1;
+ }
+ memset( pBuf, 0, size );
+ g_prefork_server->m_pChildrenStatus = (lsapi_child_status *)pBuf;
+ return 0;
+}
+
+static void lsapi_check_child_status( long tmCur )
+{
+ int idle = 0;
+ int tobekilled;
+ int dying = 0;
+ lsapi_child_status * pStatus = g_prefork_server->m_pChildrenStatus;
+ lsapi_child_status * pEnd = g_prefork_server->m_pChildrenStatus + g_prefork_server->m_iMaxChildren * 2;
+ while( pStatus < pEnd ) {
+ tobekilled = pStatus->m_iKillSent;
+ if ( pStatus->m_pid != 0 ) {
+ if ( !tobekilled ) {
+ if ( !pStatus->m_inProcess ) {
+
+ if (( g_prefork_server->m_iCurChildren - dying > g_prefork_server->m_iMaxChildren)||
+ ( idle >= g_prefork_server->m_iMaxIdleChildren )) {
+
+ tobekilled = 1;
+ } else {
+ if (( s_max_idle_secs> 0)&&(tmCur - pStatus->m_tmWaitBegin > s_max_idle_secs + 5 )) {
+ tobekilled = 1;
+ }
+ }
+ if ( !tobekilled ) {
+ ++idle;
+ }
+ } else {
+ if ( tmCur - pStatus->m_tmReqBegin >
+ g_prefork_server->m_iMaxReqProcessTime ) {
+ tobekilled = 1;
+ }
+ }
+ } else {
+ if ( pStatus->m_inProcess ) {
+ tobekilled = pStatus->m_iKillSent = 0;
+ }
+ }
+ if ( tobekilled ) {
+ tobekilled = 0;
+ if ( pStatus->m_iKillSent > 5 ) {
+ tobekilled = SIGKILL;
+ } else {
+ if ( pStatus->m_iKillSent == 3 ) {
+ tobekilled = SIGTERM;
+ } else {
+ if ( pStatus->m_iKillSent == 1 ) {
+ tobekilled = SIGUSR1;
+ }
+ }
+ }
+ if ( tobekilled ) {
+ kill( pStatus->m_pid, tobekilled );
+ }
+ ++pStatus->m_iKillSent;
+ ++dying;
+ }
+
+ } else {
+ ++dying;
+ }
+ ++pStatus;
+ }
+}
+
+static int lsapi_all_children_must_die()
+{
+ int maxWait;
+ int sec =0;
+ g_prefork_server->m_iMaxReqProcessTime = 10;
+ g_prefork_server->m_iMaxIdleChildren = -1;
+ maxWait = 15;
+
+ while( g_prefork_server->m_iCurChildren && (sec < maxWait) ) {
+ lsapi_check_child_status(time(NULL));
+ sleep( 1 );
+ sec++;
+ }
+ if ( g_prefork_server->m_iCurChildren != 0 ) {
+ kill( -getpgrp(), SIGKILL );
+ }
+ return 0;
+}
+
+
+
+static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Request * pReq )
+{
+ struct sigaction act, old_term, old_quit, old_int,
+ old_usr1, old_child;
+ lsapi_child_status * child_status;
+ int wait_secs = 0;
+ int ret = 0;
+ int pid;
+ time_t lastTime = 0;
+ time_t curTime = 0;
+ fd_set readfds;
+ struct timeval timeout;
+
+ lsapi_init_children_status();
+
+ setsid();
+
+ act.sa_flags = 0;
+ act.sa_handler = lsapi_sigchild;
+ if( sigaction( SIGCHLD, &act, &old_child ) ) {
+ perror( "Can't set signal handler for SIGCHILD" );
+ return -1;
+ }
+
+ /* Set up handler to kill children upon exit */
+ act.sa_flags = 0;
+ act.sa_handler = lsapi_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" );
+ return -1;
+ }
+ s_stop = 0;
+ while( !s_stop ) {
+ if ( ret ) {
+ curTime = time( NULL );
+ } else {
+ ++curTime;
+ }
+ if (curTime != lastTime ) {
+ lastTime = curTime;
+ if (s_ppid && (getppid() != s_ppid )) {
+ break;
+ }
+ lsapi_check_child_status(curTime );
+ if (pServer->m_iServerMaxIdle) {
+ if ( pServer->m_iCurChildren <= 0 ) {
+ ++wait_secs;
+ if ( wait_secs > pServer->m_iServerMaxIdle ) {
+ return -1;
+ }
+ } else {
+ wait_secs = 0;
+ }
+ }
+ }
+
+ if ( pServer->m_iCurChildren >= (pServer->m_iMaxChildren + pServer->m_iExtraChildren ) ) {
+ usleep( 100000 );
+ continue;
+ }
+
+ FD_ZERO( &readfds );
+ FD_SET( pServer->m_fd, &readfds );
+ timeout.tv_sec = 1; timeout.tv_usec = 0;
+ if ((ret = (*g_fnSelect)(pServer->m_fd+1, &readfds, NULL, NULL, &timeout)) == 1 ) {
+ if ( pServer->m_iCurChildren >= 0 ) {
+ usleep( 10 );
+ FD_ZERO( &readfds );
+ FD_SET( pServer->m_fd, &readfds );
+ timeout.tv_sec = 0; timeout.tv_usec = 0;
+ if ( (*g_fnSelect)(pServer->m_fd+1, &readfds, NULL, NULL, &timeout) == 0 ) {
+ continue;
+ }
+ }
+ } else {
+ if ( ret == -1 ) {
+ if ( errno == EINTR ) {
+ continue;
+ }
+ /* perror( "select()" ); */
+ break;
+ } else {
+ continue;
+ }
+ }
+
+ pReq->m_fd = lsapi_accept( pServer->m_fd );
+ if ( pReq->m_fd != -1 ) {
+ child_status = find_child_status( 0 );
+ pid = fork();
+ if ( !pid ) {
+ g_prefork_server = NULL;
+ s_ppid = getppid();
+ s_req_processed = 0;
+ s_pChildStatus = child_status;
+ child_status->m_iKillSent = 0;
+ lsapi_set_nblock( pReq->m_fd, 0 );
+
+ /* don't catch our signals */
+ sigaction( SIGCHLD, &old_child, 0 );
+ sigaction( SIGTERM, &old_term, 0 );
+ sigaction( SIGQUIT, &old_quit, 0 );
+ sigaction( SIGINT, &old_int, 0 );
+ sigaction( SIGUSR1, &old_usr1, 0 );
+ return 0;
+ } else {
+ if ( pid == -1 ) {
+ perror( "fork() failed, please increase process limit" );
+ } else {
+ ++pServer->m_iCurChildren;
+ if ( child_status ) {
+ child_status->m_pid = pid;
+ child_status->m_iKillSent = 0;
+ child_status->m_tmWaitBegin = time(NULL);
+ }
+ }
+ }
+ close( pReq->m_fd );
+ pReq->m_fd = -1;
+
+ } else {
+ if (( errno == EINTR )||( errno == EAGAIN)) {
+ continue;
+ }
+ perror( "accept() failed" );
+ return -1;
+ }
+ }
+ sigaction( SIGUSR1, &old_usr1, 0 );
+ kill( -getpgrp(), SIGUSR1 );
+ lsapi_all_children_must_die(); /* Sorry, children ;-) */
+ return -1;
+
+}
+
+int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
+{
+ int fd;
+ int ret;
+ int wait_secs;
+ fd_set readfds;
+ struct timeval timeout;
+
+ LSAPI_Finish_r( pReq );
+
+
+ if ( g_prefork_server ) {
+ if ( g_prefork_server->m_fd != -1 ) {
+ if ( lsapi_prefork_server_accept( g_prefork_server, pReq ) == -1 ) {
+ return -1;
+ }
+ }
+ }
+ if ( s_req_processed >= s_max_reqs ) {
+ return -1;
+ }
+
+ if ( s_pChildStatus ) {
+ s_pChildStatus->m_tmWaitBegin = time( NULL );
+ }
+
+ while( g_running ) {
+ if ( pReq->m_fd != -1 ) {
+ fd = pReq->m_fd;
+ } else {
+ if ( pReq->m_fdListen != -1 ) {
+ fd = pReq->m_fdListen;
+ } else {
+ return -1;
+ }
+ }
+ wait_secs = 0;
+ while( 1 ) {
+ if ( !g_running ) {
+ return -1;
+ }
+ if (( s_pChildStatus )&&( s_pChildStatus->m_iKillSent )) {
+ return -1;
+ }
+ FD_ZERO( &readfds );
+ FD_SET( fd, &readfds );
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
+ ret = (*g_fnSelect)(fd+1, &readfds, NULL, NULL, &timeout);
+ if ( ret == 0 ) {
+ if ( s_pChildStatus ) {
+ s_pChildStatus->m_inProcess = 0;
+ }
+ ++wait_secs;
+ if (( s_max_idle_secs > 0 )&&(wait_secs >= s_max_idle_secs )) {
+ return -1;
+ }
+ if ( s_ppid &&( getppid() != s_ppid)) {
+ return -1;
+ }
+ } else {
+ if ( ret == -1 ) {
+ if ( errno == EINTR ) {
+ continue;
+ } else {
+ return -1;
+ }
+ } else {
+ if ( ret >= 1 ) {
+ if (( s_pChildStatus )&&( s_pChildStatus->m_iKillSent )) {
+ return -1;
+ }
+ if ( fd == pReq->m_fdListen ) {
+ pReq->m_fd = lsapi_accept( pReq->m_fdListen );
+ if ( pReq->m_fd != -1 ) {
+ fd = pReq->m_fd;
+ lsapi_set_nblock( fd, 0 );
+ } else {
+ if (( errno == EINTR )||( errno == EAGAIN)) {
+ continue;
+ }
+ return -1;
+ }
+ } else {
+ break;
+ }
+ }
+ }
+ }
+ }
+ if ( !readReq( pReq ) ) {
+ if ( s_pChildStatus ) {
+ s_pChildStatus->m_inProcess = 1;
+ s_pChildStatus->m_tmReqBegin = s_pChildStatus->m_tmLastCheckPoint = time(NULL);
+ }
+ ++s_req_processed;
+ return 0;
+ }
+ lsapi_close( pReq->m_fd );
+ pReq->m_fd = -1;
+ LSAPI_Reset_r( pReq );
+ }
+ return -1;
+
+}
+
+void LSAPI_Set_Max_Reqs( int reqs )
+{
+ s_max_reqs = reqs;
+}
+
+void LSAPI_Set_Max_Idle( int secs )
+{
+ s_max_idle_secs = secs;
+}
+
+void LSAPI_Set_Max_Children( int maxChildren )
+{
+ if ( g_prefork_server ) {
+ g_prefork_server->m_iMaxChildren = maxChildren;
+ }
+}
+
+void LSAPI_Set_Extra_Children( int extraChildren )
+{
+ if (( g_prefork_server )&&( extraChildren >= 0 )) {
+ g_prefork_server->m_iExtraChildren = extraChildren;
+ }
+}
+
+void LSAPI_Set_Max_Process_Time( int secs )
+{
+ if (( g_prefork_server )&&( secs > 0 )) {
+ g_prefork_server->m_iMaxReqProcessTime = secs;
+ }
+}
+
+
+void LSAPI_Set_Max_Idle_Children( int maxIdleChld )
+{
+ if (( g_prefork_server )&&( maxIdleChld > 0 )) {
+ g_prefork_server->m_iMaxIdleChildren = maxIdleChld;
+ }
+}
+
+void LSAPI_Set_Server_Max_Idle_Secs( int serverMaxIdle )
+{
+ if ( g_prefork_server ) {
+ g_prefork_server->m_iServerMaxIdle = serverMaxIdle;
+ }
+}
+
+
+void LSAPI_No_Check_ppid()
+{
+ s_ppid = 0;
+}
+
+#if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
+#include <crt_externs.h>
+#else
+extern char ** environ;
+#endif
+static void unset_lsapi_envs()
+{
+ char **env;
+#if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
+ env = *_NSGetEnviron();
+#else
+ env = environ;
+#endif
+ while( env != NULL && *env != NULL ) {
+ if ( !strncmp(*env, "LSAPI_", 6) ||
+ !strncmp( *env, "PHP_LSAPI_", 10 ) ) {
+ char ** del = env;
+ do {
+ *del = del[1];
+ } while( *del++ );
+ } else {
+ ++env;
+ }
+ }
+}
+
+void LSAPI_Init_Env_Parameters( fn_select_t fp )
+{
+ const char *p;
+ int n;
+ int avoidFork = 0;
+ p = getenv( "PHP_LSAPI_MAX_REQUESTS" );
+ if ( !p ) {
+ p = getenv( "LSAPI_MAX_REQS" );
+ }
+ if ( p ) {
+ n = atoi( p );
+ if ( n > 0 ) {
+ LSAPI_Set_Max_Reqs( n );
+ }
+ }
+
+ p = getenv( "LSAPI_AVOID_FORK" );
+ if ( p ) {
+ avoidFork = atoi( p );
+ }
+
+#if defined( RLIMIT_CORE )
+ p = getenv( "LSAPI_ALLOW_CORE_DUMP" );
+ if ( !p ) {
+ struct rlimit limit = { 0, 0 };
+ setrlimit( RLIMIT_CORE, &limit );
+ }
+#endif
+
+ p = getenv( "LSAPI_MAX_IDLE" );
+ if ( p ) {
+ n = atoi( p );
+ LSAPI_Set_Max_Idle( n );
+ }
+
+ if ( LSAPI_Is_Listen() ) {
+ n = 0;
+ p = getenv( "PHP_LSAPI_CHILDREN" );
+ if ( !p ) {
+ p = getenv( "LSAPI_CHILDREN" );
+ }
+ if ( p ) {
+ n = atoi( p );
+ }
+ if ( n > 1 ) {
+ LSAPI_Init_Prefork_Server( n, fp, avoidFork );
+ LSAPI_Set_Server_fd( g_req.m_fdListen );
+ }
+
+ p = getenv( "LSAPI_EXTRA_CHILDREN" );
+ if ( p ) {
+ LSAPI_Set_Extra_Children( atoi( p ) );
+ }
+
+ p = getenv( "LSAPI_MAX_IDLE_CHILDREN" );
+ if ( p ) {
+ LSAPI_Set_Max_Idle_Children( atoi( p ) );
+ }
+ p = getenv( "LSAPI_PGRP_MAX_IDLE" );
+ if ( p ) {
+ LSAPI_Set_Server_Max_Idle_Secs( atoi( p ) );
+ }
+
+ p = getenv( "LSAPI_MAX_PROCESS_TIME" );
+ if ( p ) {
+ LSAPI_Set_Max_Process_Time( atoi( p ) );
+ }
+ if ( getenv( "LSAPI_PPID_NO_CHECK" ) ) {
+ LSAPI_No_Check_ppid();
+ }
+ }
+ unset_lsapi_envs();
+}
+
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
+
+
diff --git a/sapi/litespeed/lsapilib.h b/sapi/litespeed/lsapilib.h
new file mode 100644
index 000000000..b7b82e359
--- /dev/null
+++ b/sapi/litespeed/lsapilib.h
@@ -0,0 +1,358 @@
+
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2007 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: George Wang <gwang@litespeedtech.com> |
+ +----------------------------------------------------------------------+
+*/
+
+/*
+Copyright (c) 2007, Lite Speed Technologies Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+ * Neither the name of the Lite Speed Technologies Inc nor the
+ names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+
+#ifndef _LSAPILIB_H_
+#define _LSAPILIB_H_
+
+#if defined (c_plusplus) || defined (__cplusplus)
+extern "C" {
+#endif
+
+#include <stddef.h>
+#include <lsapidef.h>
+
+#include <sys/time.h>
+#include <sys/types.h>
+
+struct LSAPI_key_value_pair
+{
+ char * pKey;
+ char * pValue;
+ int keyLen;
+ int valLen;
+};
+
+
+#define LSAPI_MAX_RESP_HEADERS 100
+
+typedef struct lsapi_request
+{
+ int m_fdListen;
+ int m_fd;
+
+ long m_lLastActive;
+ long m_lReqBegin;
+
+ char * m_pReqBuf;
+ int m_reqBufSize;
+
+ char * m_pRespBuf;
+ char * m_pRespBufEnd;
+ char * m_pRespBufPos;
+
+ char * m_pRespHeaderBuf;
+ char * m_pRespHeaderBufEnd;
+ char * m_pRespHeaderBufPos;
+
+
+ struct iovec * m_pIovec;
+ struct iovec * m_pIovecEnd;
+ struct iovec * m_pIovecCur;
+ struct iovec * m_pIovecToWrite;
+
+ struct lsapi_packet_header * m_respPktHeaderEnd;
+
+ struct lsapi_req_header * m_pHeader;
+ struct LSAPI_key_value_pair * m_pEnvList;
+ struct LSAPI_key_value_pair * m_pSpecialEnvList;
+ int m_envListSize;
+ int m_specialEnvListSize;
+
+ struct lsapi_http_header_index * m_pHeaderIndex;
+ struct lsapi_header_offset * m_pUnknownHeader;
+
+ char * m_pScriptFile;
+ char * m_pScriptName;
+ char * m_pQueryString;
+ char * m_pHttpHeader;
+ char * m_pRequestMethod;
+ int m_totalLen;
+ int m_reqState;
+ int m_reqBodyRead;
+ int m_bufProcessed;
+ int m_bufRead;
+
+ struct lsapi_packet_header m_respPktHeader[5];
+
+ struct lsapi_resp_header m_respHeader;
+ short m_respHeaderLen[LSAPI_MAX_RESP_HEADERS];
+
+}LSAPI_Request;
+
+extern LSAPI_Request g_req;
+
+
+/* return: >0 continue, ==0 stop, -1 failed */
+typedef int (*LSAPI_CB_EnvHandler )( const char * pKey, int keyLen,
+ const char * pValue, int valLen, void * arg );
+
+
+int LSAPI_Init(void);
+
+void LSAPI_Stop(void);
+
+int LSAPI_Is_Listen_r( LSAPI_Request * pReq);
+
+int LSAPI_InitRequest( LSAPI_Request * pReq, int fd );
+
+int LSAPI_Accept_r( LSAPI_Request * pReq );
+
+void LSAPI_Reset_r( LSAPI_Request * pReq );
+
+int LSAPI_Finish_r( LSAPI_Request * pReq );
+
+int LSAPI_Release_r( LSAPI_Request * pReq );
+
+char * LSAPI_GetHeader_r( LSAPI_Request * pReq, int headerIndex );
+
+int LSAPI_ForeachHeader_r( LSAPI_Request * pReq,
+ LSAPI_CB_EnvHandler fn, void * arg );
+
+int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq,
+ LSAPI_CB_EnvHandler fn, void * arg );
+
+int LSAPI_ForeachEnv_r( LSAPI_Request * pReq,
+ LSAPI_CB_EnvHandler fn, void * arg );
+
+int LSAPI_ForeachSpecialEnv_r( LSAPI_Request * pReq,
+ LSAPI_CB_EnvHandler fn, void * arg );
+
+char * LSAPI_GetEnv_r( LSAPI_Request * pReq, const char * name );
+
+
+int LSAPI_ReadReqBody_r( LSAPI_Request * pReq, char * pBuf, int len );
+
+int LSAPI_ReqBodyGetChar_r( LSAPI_Request * pReq );
+
+int LSAPI_ReqBodyGetLine_r( LSAPI_Request * pReq, char * pBuf, int bufLen, int *getLF );
+
+
+int LSAPI_FinalizeRespHeaders_r( LSAPI_Request * pReq );
+
+int LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, int len );
+
+int LSAPI_Write_Stderr_r( LSAPI_Request * pReq, const char * pBuf, int len );
+
+int LSAPI_Flush_r( LSAPI_Request * pReq );
+
+int LSAPI_AppendRespHeader_r( LSAPI_Request * pHeader, char * pBuf, int len );
+
+static inline int LSAPI_SetRespStatus_r( LSAPI_Request * pReq, int code )
+{
+ if ( !pReq )
+ return -1;
+ pReq->m_respHeader.m_respInfo.m_status = code;
+ return 0;
+}
+
+static inline char * LSAPI_GetQueryString_r( LSAPI_Request * pReq )
+{
+ if ( pReq )
+ return pReq->m_pQueryString;
+ return NULL;
+}
+
+
+static inline char * LSAPI_GetScriptFileName_r( LSAPI_Request * pReq )
+{
+ if ( pReq )
+ return pReq->m_pScriptFile;
+ return NULL;
+}
+
+
+static inline char * LSAPI_GetScriptName_r( LSAPI_Request * pReq )
+{
+ if ( pReq )
+ return pReq->m_pScriptName;
+ return NULL;
+}
+
+
+static inline char * LSAPI_GetRequestMethod_r( LSAPI_Request * pReq)
+{
+ if ( pReq )
+ return pReq->m_pRequestMethod;
+ return NULL;
+}
+
+
+
+static inline int LSAPI_GetReqBodyLen_r( LSAPI_Request * pReq )
+{
+ if ( pReq )
+ return pReq->m_pHeader->m_reqBodyLen;
+ return -1;
+}
+
+static inline int LSAPI_GetReqBodyRemain_r( LSAPI_Request * pReq )
+{
+ if ( pReq )
+ return pReq->m_pHeader->m_reqBodyLen - pReq->m_reqBodyRead;
+ return -1;
+}
+
+
+int LSAPI_Is_Listen(void);
+
+static inline int LSAPI_Accept( void )
+{ return LSAPI_Accept_r( &g_req ); }
+
+static inline int LSAPI_Finish(void)
+{ return LSAPI_Finish_r( &g_req ); }
+
+static inline char * LSAPI_GetHeader( int headerIndex )
+{ return LSAPI_GetHeader_r( &g_req, headerIndex ); }
+
+static inline int LSAPI_ForeachHeader( LSAPI_CB_EnvHandler fn, void * arg )
+{ return LSAPI_ForeachHeader_r( &g_req, fn, arg ); }
+
+static inline int LSAPI_ForeachOrgHeader(
+ LSAPI_CB_EnvHandler fn, void * arg )
+{ return LSAPI_ForeachOrgHeader_r( &g_req, fn, arg ); }
+
+static inline int LSAPI_ForeachEnv( LSAPI_CB_EnvHandler fn, void * arg )
+{ return LSAPI_ForeachEnv_r( &g_req, fn, arg ); }
+
+static inline int LSAPI_ForeachSpecialEnv( LSAPI_CB_EnvHandler fn, void * arg )
+{ return LSAPI_ForeachSpecialEnv_r( &g_req, fn, arg ); }
+
+static inline char * LSAPI_GetEnv( const char * name )
+{ return LSAPI_GetEnv_r( &g_req, name ); }
+
+static inline char * LSAPI_GetQueryString()
+{ return LSAPI_GetQueryString_r( &g_req ); }
+
+static inline char * LSAPI_GetScriptFileName()
+{ return LSAPI_GetScriptFileName_r( &g_req ); }
+
+static inline char * LSAPI_GetScriptName()
+{ return LSAPI_GetScriptName_r( &g_req ); }
+
+static inline char * LSAPI_GetRequestMethod()
+{ return LSAPI_GetRequestMethod_r( &g_req ); }
+
+static inline int LSAPI_GetReqBodyLen()
+{ return LSAPI_GetReqBodyLen_r( &g_req ); }
+
+static inline int LSAPI_GetReqBodyRemain()
+{ return LSAPI_GetReqBodyRemain_r( &g_req ); }
+
+static inline int LSAPI_ReadReqBody( char * pBuf, int len )
+{ return LSAPI_ReadReqBody_r( &g_req, pBuf, len ); }
+
+static inline int LSAPI_ReqBodyGetChar()
+{ return LSAPI_ReqBodyGetChar_r( &g_req ); }
+
+static inline int LSAPI_ReqBodyGetLine( char * pBuf, int len, int *getLF )
+{ return LSAPI_ReqBodyGetLine_r( &g_req, pBuf, len, getLF ); }
+
+
+
+static inline int LSAPI_FinalizeRespHeaders(void)
+{ return LSAPI_FinalizeRespHeaders_r( &g_req ); }
+
+static inline int LSAPI_Write( const char * pBuf, int len )
+{ return LSAPI_Write_r( &g_req, pBuf, len ); }
+
+static inline int LSAPI_Write_Stderr( const char * pBuf, int len )
+{ return LSAPI_Write_Stderr_r( &g_req, pBuf, len ); }
+
+static inline int LSAPI_Flush()
+{ return LSAPI_Flush_r( &g_req ); }
+
+static inline int LSAPI_AppendRespHeader( char * pBuf, int len )
+{ return LSAPI_AppendRespHeader_r( &g_req, pBuf, len ); }
+
+static inline int LSAPI_SetRespStatus( int code )
+{ return LSAPI_SetRespStatus_r( &g_req, code ); }
+
+int LSAPI_IsRunning(void);
+
+int LSAPI_CreateListenSock( const char * pBind, int backlog );
+
+typedef int (*fn_select_t)( int, fd_set *, fd_set *, fd_set *, struct timeval * );
+
+int LSAPI_Init_Prefork_Server( int max_children, fn_select_t fp, int avoidFork );
+
+void LSAPI_Set_Server_fd( int fd );
+
+int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq );
+
+void LSAPI_Set_Max_Reqs( int reqs );
+
+void LSAPI_Set_Max_Idle( int secs );
+
+void LSAPI_Set_Max_Children( int maxChildren );
+
+void LSAPI_Set_Max_Idle_Children( int maxIdleChld );
+
+void LSAPI_Set_Server_Max_Idle_Secs( int serverMaxIdle );
+
+void LSAPI_Set_Max_Process_Time( int secs );
+
+void LSAPI_Init_Env_Parameters( fn_select_t fp );
+
+#if defined (c_plusplus) || defined (__cplusplus)
+}
+#endif
+
+
+#endif
+
+
+
+
+
+
+
diff --git a/sapi/milter/php_milter.c b/sapi/milter/php_milter.c
index 0ae314f4c..c07e8c98b 100644
--- a/sapi/milter/php_milter.c
+++ b/sapi/milter/php_milter.c
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_milter.c,v 1.14.2.2.2.6 2008/12/31 11:17:49 sebastian Exp $ */
+/* $Id: php_milter.c,v 1.14.2.2.2.3.2.10 2008/12/31 11:15:49 sebastian Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -769,18 +769,60 @@ PHP_MINFO_FUNCTION(milter)
/* }}} */
/* }}} */
+/* {{{ arginfo */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_setflags, 0, 0, 1)
+ ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_settimeout, 0, 0, 1)
+ ZEND_ARG_INFO(0, timeout)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_getsymval, 0, 0, 1)
+ ZEND_ARG_INFO(0, macro)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_setreply, 0, 0, 3)
+ ZEND_ARG_INFO(0, rcode)
+ ZEND_ARG_INFO(0, xcode)
+ ZEND_ARG_INFO(0, message)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_addheader, 0, 0, 2)
+ ZEND_ARG_INFO(0, headerf)
+ ZEND_ARG_INFO(0, headerv)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_chgheader, 0, 0, 2)
+ ZEND_ARG_INFO(0, headerf)
+ ZEND_ARG_INFO(0, headerv)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_addrcpt, 0, 0, 1)
+ ZEND_ARG_INFO(0, rcpt)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_delrcpt, 0, 0, 1)
+ ZEND_ARG_INFO(0, rcpt)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_replacebody, 0, 0, 1)
+ ZEND_ARG_INFO(0, body)
+ZEND_END_ARG_INFO()
+/* }}} */
+
/* {{{ milter_functions[]
*/
-static zend_function_entry milter_functions[] = {
- PHP_FE(smfi_setflags, NULL)
- PHP_FE(smfi_settimeout, NULL)
- PHP_FE(smfi_getsymval, NULL)
- PHP_FE(smfi_setreply, NULL)
- PHP_FE(smfi_addheader, NULL)
- PHP_FE(smfi_chgheader, NULL)
- PHP_FE(smfi_addrcpt, NULL)
- PHP_FE(smfi_delrcpt, NULL)
- PHP_FE(smfi_replacebody, NULL)
+const static zend_function_entry milter_functions[] = {
+ PHP_FE(smfi_setflags, arginfo_smfi_setflags)
+ PHP_FE(smfi_settimeout, arginfo_smfi_settimeout)
+ PHP_FE(smfi_getsymval, arginfo_smfi_getsymval)
+ PHP_FE(smfi_setreply, arginfo_smfi_setreply)
+ PHP_FE(smfi_addheader, arginfo_smfi_addheader)
+ PHP_FE(smfi_chgheader, arginfo_smfi_chgheader)
+ PHP_FE(smfi_addrcpt, arginfo_smfi_addrcpt)
+ PHP_FE(smfi_delrcpt, arginfo_smfi_delrcpt)
+ PHP_FE(smfi_replacebody, arginfo_smfi_replacebody)
{ NULL, NULL, NULL }
};
/* }}} */
@@ -870,6 +912,7 @@ static sapi_module_struct milter_sapi_module = {
sapi_milter_register_variables, /* register server variables */
NULL, /* Log message */
NULL, /* Get request time */
+ NULL, /* Child terminate */
NULL, /* Block interruptions */
NULL, /* Unblock interruptions */
@@ -1027,7 +1070,7 @@ int main(int argc, char *argv[])
break;
case 'e': /* enable extended info output */
- CG(extended_info) = 1;
+ CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
break;
case 'f': /* parse file */
diff --git a/sapi/nsapi/config.w32 b/sapi/nsapi/config.w32
index cb183c4dd..f81825da5 100644
--- a/sapi/nsapi/config.w32
+++ b/sapi/nsapi/config.w32
@@ -1,5 +1,5 @@
// vim:ft=javascript
-// $Id: config.w32,v 1.4 2004/01/07 20:06:31 wez Exp $
+// $Id: config.w32,v 1.4.8.1 2009/03/20 18:49:37 pajoye Exp $
ARG_ENABLE('nsapi', 'Build NSAPI for Netscape/iPlanet/SunONE webservers', 'no');
@@ -9,6 +9,7 @@ ARG_WITH('nsapi-libs', 'Where to find NSAPI libraries', null);
if (PHP_NSAPI != "no") {
if (PHP_ZTS == "no") {
WARNING("NSAPI module requires an --enable-zts build of PHP");
+ PHP_NSAPI = "no"
} else if (CHECK_HEADER_ADD_INCLUDE("nsapi.h", "CFLAGS_NSAPI",
PHP_NSAPI + ';' + PHP_NSAPI_INCLUDES) &&
CHECK_LIB("ns-httpd*.lib", "nsapi", PHP_NSAPI + ";" + PHP_NSAPI_LIBS)) {
diff --git a/sapi/nsapi/nsapi.c b/sapi/nsapi/nsapi.c
index 18c3aae3e..95b34e1f2 100644
--- a/sapi/nsapi/nsapi.c
+++ b/sapi/nsapi/nsapi.c
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: nsapi.c,v 1.69.2.3.2.16 2009/01/06 13:46:49 thetaphi Exp $ */
+/* $Id: nsapi.c,v 1.69.2.3.2.6.2.18 2009/01/11 13:47:01 thetaphi Exp $ */
/*
* PHP includes
@@ -55,7 +55,7 @@
#define XP_UNIX
#endif
#endif
-
+
/*
* NSAPI includes
*/
@@ -162,18 +162,31 @@ ZEND_DECLARE_MODULE_GLOBALS(nsapi)
#define NSAPI_G(v) TSRMG(nsapi_globals_id, zend_nsapi_globals *, v)
+
+/* {{{ arginfo */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_nsapi_virtual, 0, 0, 1)
+ ZEND_ARG_INFO(0, uri)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_nsapi_request_headers, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_nsapi_response_headers, 0)
+ZEND_END_ARG_INFO()
+/* }}} */
+
/* {{{ nsapi_functions[]
*
* Every user visible function must have an entry in nsapi_functions[].
*/
-zend_function_entry nsapi_functions[] = {
- PHP_FE(nsapi_virtual, NULL) /* Make subrequest */
- PHP_FALIAS(virtual, nsapi_virtual, NULL) /* compatibility */
- PHP_FE(nsapi_request_headers, NULL) /* get request headers */
- PHP_FALIAS(getallheaders, nsapi_request_headers, NULL) /* compatibility */
- PHP_FALIAS(apache_request_headers, nsapi_request_headers, NULL) /* compatibility */
- PHP_FE(nsapi_response_headers, NULL) /* get response headers */
- PHP_FALIAS(apache_response_headers, nsapi_response_headers, NULL) /* compatibility */
+const zend_function_entry nsapi_functions[] = {
+ PHP_FE(nsapi_virtual, arginfo_nsapi_virtual) /* Make subrequest */
+ PHP_FALIAS(virtual, nsapi_virtual, arginfo_nsapi_virtual) /* compatibility */
+ PHP_FE(nsapi_request_headers, arginfo_nsapi_request_headers) /* get request headers */
+ PHP_FALIAS(getallheaders, nsapi_request_headers, arginfo_nsapi_request_headers) /* compatibility */
+ PHP_FALIAS(apache_request_headers, nsapi_request_headers, arginfo_nsapi_request_headers) /* compatibility */
+ PHP_FE(nsapi_response_headers, arginfo_nsapi_response_headers) /* get response headers */
+ PHP_FALIAS(apache_response_headers, nsapi_response_headers, arginfo_nsapi_response_headers) /* compatibility */
{NULL, NULL, NULL}
};
/* }}} */
@@ -294,7 +307,7 @@ PHP_MSHUTDOWN_FUNCTION(nsapi)
PHP_MINFO_FUNCTION(nsapi)
{
php_info_print_table_start();
- php_info_print_table_row(2, "NSAPI Module Revision", "$Revision: 1.69.2.3.2.16 $");
+ php_info_print_table_row(2, "NSAPI Module Revision", "$Revision: 1.69.2.3.2.6.2.18 $");
php_info_print_table_row(2, "Server Software", system_version());
php_info_print_table_row(2, "Sub-requests with nsapi_virtual()",
(nsapi_servact_service)?((zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0))?"not supported with zlib.output_compression":"enabled"):"not supported on this platform" );
@@ -387,10 +400,10 @@ PHP_FUNCTION(nsapi_request_headers)
struct pb_entry *entry;
nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
- if (ZEND_NUM_ARGS()) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
-
+
array_init(return_value);
for (i=0; i < rc->rq->headers->hsize; i++) {
@@ -413,10 +426,10 @@ PHP_FUNCTION(nsapi_response_headers)
struct pb_entry *entry;
nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
- if (ZEND_NUM_ARGS()) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
-
+
array_init(return_value);
for (i=0; i < rc->rq->srvhdrs->hsize; i++) {
@@ -468,38 +481,80 @@ static void sapi_nsapi_flush(void *server_context)
#endif
}
-static int sapi_nsapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC)
+/* callback for zend_llist_apply on SAPI_HEADER_DELETE_ALL operation */
+static int php_nsapi_remove_header(sapi_header_struct *sapi_header TSRMLS_DC)
{
- char *header_name, *header_content, *p;
+ char *header_name, *p;
nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
+
+ /* copy the header, because NSAPI needs reformatting and we do not want to change the parameter */
+ header_name = nsapi_strdup(sapi_header->header);
- header_name = sapi_header->header;
- header_content = p = strchr(header_name, ':');
- if (p == NULL) {
- efree(sapi_header->header);
- return 0;
+ /* extract name, this works, if only the header without ':' is given, too */
+ if (p = strchr(header_name, ':')) {
+ *p = 0;
}
-
- *p = 0;
- do {
- header_content++;
- } while (*header_content == ' ');
-
- if (!strcasecmp(header_name, "Content-Type")) {
- param_free(pblock_remove("content-type", rc->rq->srvhdrs));
- pblock_nvinsert("content-type", header_content, rc->rq->srvhdrs);
- } else {
- /* to lower case because NSAPI reformats the headers and wants lowercase */
- for (p=header_name; *p; p++) {
- *p=tolower(*p);
- }
- if (sapi_header->replace) param_free(pblock_remove(header_name, rc->rq->srvhdrs));
- pblock_nvinsert(header_name, header_content, rc->rq->srvhdrs);
+
+ /* header_name to lower case because NSAPI reformats the headers and wants lowercase */
+ for (p=header_name; *p; p++) {
+ *p=tolower(*p);
}
+
+ /* remove the header */
+ param_free(pblock_remove(header_name, rc->rq->srvhdrs));
+ nsapi_free(header_name);
+
+ return ZEND_HASH_APPLY_KEEP;
+}
- sapi_free_header(sapi_header);
+static int sapi_nsapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC)
+{
+ char *header_name, *header_content, *p;
+ nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
+
+ switch(op) {
+ case SAPI_HEADER_DELETE_ALL:
+ /* this only deletes headers set or overwritten by PHP, headers previously set by NSAPI are left intact */
+ zend_llist_apply(&sapi_headers->headers, (llist_apply_func_t) php_nsapi_remove_header TSRMLS_CC);
+ return 0;
+
+ case SAPI_HEADER_DELETE:
+ /* reuse the zend_llist_apply callback function for this, too */
+ php_nsapi_remove_header(sapi_header TSRMLS_CC);
+ return 0;
+
+ case SAPI_HEADER_ADD:
+ case SAPI_HEADER_REPLACE:
+ /* copy the header, because NSAPI needs reformatting and we do not want to change the parameter */
+ header_name = nsapi_strdup(sapi_header->header);
+
+ /* split header and align pointer for content */
+ header_content = strchr(header_name, ':');
+ if (header_content) {
+ *header_content = 0;
+ do {
+ header_content++;
+ } while (*header_content==' ');
+
+ /* header_name to lower case because NSAPI reformats the headers and wants lowercase */
+ for (p=header_name; *p; p++) {
+ *p=tolower(*p);
+ }
- return 0; /* don't use the default SAPI mechanism, NSAPI duplicates this functionality */
+ /* if REPLACE, remove first. "Content-type" is always removed, as SAPI has a bug according to this */
+ if (op==SAPI_HEADER_REPLACE || strcmp(header_name, "content-type")==0) {
+ param_free(pblock_remove(header_name, rc->rq->srvhdrs));
+ }
+ /* ADD header to nsapi table */
+ pblock_nvinsert(header_name, header_content, rc->rq->srvhdrs);
+ }
+
+ nsapi_free(header_name);
+ return SAPI_HEADER_ADD;
+
+ default:
+ return 0;
+ }
}
static int sapi_nsapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
@@ -775,6 +830,7 @@ static sapi_module_struct nsapi_sapi_module = {
sapi_nsapi_register_server_variables, /* register server variables */
nsapi_log_message, /* Log message */
sapi_nsapi_get_request_time, /* Get request time */
+ NULL, /* Child terminate */
NULL, /* Block interruptions */
NULL, /* Unblock interruptions */
diff --git a/sapi/phttpd/phttpd.c b/sapi/phttpd/phttpd.c
index c9a0fad04..2934abfbf 100644
--- a/sapi/phttpd/phttpd.c
+++ b/sapi/phttpd/phttpd.c
@@ -180,6 +180,7 @@ static sapi_module_struct phttpd_sapi_module = {
NULL, /* register server variables */
NULL, /* Log message */
NULL, /* Get request time */
+ NULL, /* Child terminate */
STANDARD_SAPI_MODULE_PROPERTIES
};
diff --git a/sapi/pi3web/pi3web_sapi.c b/sapi/pi3web/pi3web_sapi.c
index 746b8bbbc..7f34858ca 100644
--- a/sapi/pi3web/pi3web_sapi.c
+++ b/sapi/pi3web/pi3web_sapi.c
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pi3web_sapi.c,v 1.60.2.1.2.3 2008/12/31 11:17:49 sebastian Exp $ */
+/* $Id: pi3web_sapi.c,v 1.60.2.1.2.1.2.3 2008/12/31 11:15:49 sebastian Exp $ */
#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
@@ -57,7 +57,7 @@ static void php_info_pi3web(ZEND_MODULE_INFO_FUNC_ARGS)
PUTS("<table border=0 cellpadding=3 cellspacing=1 width=600 align=center>\n");
PUTS("<tr><th colspan=2 bgcolor=\"" PHP_HEADER_COLOR "\">Pi3Web Server Information</th></tr>\n");
php_info_print_table_header(2, "Information Field", "Value");
- php_info_print_table_row(2, "Pi3Web SAPI module version", "$Id: pi3web_sapi.c,v 1.60.2.1.2.3 2008/12/31 11:17:49 sebastian Exp $");
+ php_info_print_table_row(2, "Pi3Web SAPI module version", "$Id: pi3web_sapi.c,v 1.60.2.1.2.1.2.3 2008/12/31 11:15:49 sebastian Exp $");
php_info_print_table_row(2, "Server Name Stamp", HTTPCore_getServerStamp());
snprintf(variable_buf, 511, "%d", HTTPCore_debugEnabled());
php_info_print_table_row(2, "Debug Enabled", variable_buf);
@@ -337,6 +337,7 @@ static sapi_module_struct pi3web_sapi_module = {
sapi_pi3web_register_variables, /* register server variables */
NULL, /* Log message */
NULL, /* Get request time */
+ NULL, /* Child terminate */
STANDARD_SAPI_MODULE_PROPERTIES
};
diff --git a/sapi/pi3web/pi3web_sapi.h b/sapi/pi3web/pi3web_sapi.h
index 9300241d4..d229fec53 100644
--- a/sapi/pi3web/pi3web_sapi.h
+++ b/sapi/pi3web/pi3web_sapi.h
@@ -9,8 +9,12 @@
# define MODULE_API __declspec(dllimport)
# endif
#else
+# if defined(__GNUC__) && __GNUC__ >= 4
+# define MODULE_API __attribute__ ((visibility("default")))
+# else
+# define MODULE_API
+# endif
# define far
-# define MODULE_API
typedef int BOOL;
typedef void far *LPVOID;
diff --git a/sapi/roxen/roxen.c b/sapi/roxen/roxen.c
index 558268a67..94a6f51ad 100644
--- a/sapi/roxen/roxen.c
+++ b/sapi/roxen/roxen.c
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: roxen.c,v 1.61.2.2.2.3 2008/12/31 11:17:49 sebastian Exp $ */
+/* $Id: roxen.c,v 1.61.2.2.2.1.2.3 2008/12/31 11:15:49 sebastian Exp $ */
#include "php.h"
#ifdef HAVE_ROXEN
@@ -438,7 +438,7 @@ static void php_info_roxen(ZEND_MODULE_INFO_FUNC_ARGS)
{
/* char buf[512]; */
php_info_print_table_start();
- php_info_print_table_row(2, "SAPI module version", "$Id: roxen.c,v 1.61.2.2.2.3 2008/12/31 11:17:49 sebastian Exp $");
+ php_info_print_table_row(2, "SAPI module version", "$Id: roxen.c,v 1.61.2.2.2.1.2.3 2008/12/31 11:15:49 sebastian Exp $");
/* php_info_print_table_row(2, "Build date", Ns_InfoBuildDate());
php_info_print_table_row(2, "Config file path", Ns_InfoConfigFile());
php_info_print_table_row(2, "Error Log path", Ns_InfoErrorLog());
@@ -502,6 +502,7 @@ static sapi_module_struct roxen_sapi_module = {
NULL, /* register server variables */
NULL, /* Log message */
NULL, /* Get request time */
+ NULL, /* Child terminate */
STANDARD_SAPI_MODULE_PROPERTIES
};
diff --git a/sapi/tests/test003.phpt b/sapi/tests/test003.phpt
index 522d78db4..5cabe66b3 100644
--- a/sapi/tests/test003.phpt
+++ b/sapi/tests/test003.phpt
@@ -9,9 +9,9 @@ PATH_INFO=/path/info
END;
--ENV--
return <<<END
-PATH_TRANSLATED=$filename/path/info
-PATH_INFO=$scriptname/path/info
-SCRIPT_NAME=$scriptname
+PATH_TRANSLATED=/path/bla
+PATH_INFO=/path/info
+SCRIPT_NAME=path
END;
--FILE--
<?php
diff --git a/sapi/tests/test004.phpt b/sapi/tests/test004.phpt
index dad0dd0ee..ef4377484 100644
--- a/sapi/tests/test004.phpt
+++ b/sapi/tests/test004.phpt
@@ -12,9 +12,9 @@ PATH_INFO=/path/info
END;
--ENV--
return <<<END
-REDIRECT_URL=$scriptname
-PATH_TRANSLATED=$filename/path/info
-PATH_INFO=$scriptname/path/info
+REDIRECT_URL=/path
+PATH_TRANSLATED=/path/info/fpp
+PATH_INFO=/path/info
SCRIPT_NAME=/scriptalias/php
SCRIPT_FILENAME=$this->conf['TEST_PHP_EXECUTABLE']
END;
diff --git a/sapi/thttpd/thttpd.c b/sapi/thttpd/thttpd.c
index ec26ac619..fd7a80fd5 100644
--- a/sapi/thttpd/thttpd.c
+++ b/sapi/thttpd/thttpd.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: thttpd.c,v 1.95.2.1.2.3 2008/12/31 11:17:49 sebastian Exp $ */
+/* $Id: thttpd.c,v 1.95.2.1.2.1.2.3 2008/12/31 11:15:49 sebastian Exp $ */
#include "php.h"
#include "SAPI.h"
@@ -394,6 +394,7 @@ static sapi_module_struct thttpd_sapi_module = {
sapi_thttpd_register_variables,
NULL, /* Log message */
NULL, /* Get request time */
+ NULL, /* Child terminate */
NULL, /* php.ini path override */
NULL, /* Block interruptions */
diff --git a/sapi/tux/php_tux.c b/sapi/tux/php_tux.c
index 806dcad14..c94ed0845 100644
--- a/sapi/tux/php_tux.c
+++ b/sapi/tux/php_tux.c
@@ -288,6 +288,7 @@ static sapi_module_struct tux_sapi_module = {
sapi_tux_register_variables,
NULL, /* Log message */
NULL, /* Get request time */
+ NULL, /* Child terminate */
STANDARD_SAPI_MODULE_PROPERTIES
};
diff --git a/sapi/webjames/webjames.c b/sapi/webjames/webjames.c
index e5bce4e7b..6783b5ed1 100644
--- a/sapi/webjames/webjames.c
+++ b/sapi/webjames/webjames.c
@@ -301,6 +301,7 @@ static sapi_module_struct sapi_module = {
sapi_webjames_register_variables, /* register server variables */
NULL, /* Log message */
NULL, /* Get request time */
+ NULL, /* Child terminate */
STANDARD_SAPI_MODULE_PROPERTIES
};