diff options
Diffstat (limited to 'sapi')
107 files changed, 0 insertions, 20433 deletions
diff --git a/sapi/aolserver/CREDITS b/sapi/aolserver/CREDITS deleted file mode 100644 index 8f9a4af950..0000000000 --- a/sapi/aolserver/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -AOLserver -Sascha Schumann diff --git a/sapi/aolserver/README b/sapi/aolserver/README deleted file mode 100644 index 86af6a54b3..0000000000 --- a/sapi/aolserver/README +++ /dev/null @@ -1,69 +0,0 @@ -AOLserver README ($Id$) - -To compile PHP 4.0 as a module for AOLserver, you need: - -- installed AOLserver 3.1 or later - (see the note below for AOLserver 3.0) - -NOTE: You should not use this module in production. PHP is not 100% stable - yet in threaded mode. To increase reliability enable the Global Lock - by removing #define NO_GLOBAL_LOCK in main/main.c. Also don't use - php_value as it will lead to races in a sub-system (use an ini file - instead). - - -1.) Configuring AOLserver - -Read doc/install.txt in the source distribution - -It usually boils down to changing the INST/PREFIX variable in -include/Makefile.global and running make all install. - -2.) Configuring PHP - -$ ./configure \ - --with-aolserver=/path/to/installed/aolserver \ - <other options> - -NOTE: If you are still using AOLserver 3.0, you need to retain the - AOLserver source code and pass another option to PHP: - - --with-aolserver-src=/path/to/source/distribution - -3.) Compiling and Installing PHP - -$ make install - -4.) Changing nsd.tcl - -a) New section - -Add a new section to pass options to PHP (required): - -ns_section "ns/server/${servername}/module/php" - -You can use the following commands in this section: - -The 'map' command will cause AOLserver to pass all requests to *.php to -the PHP module (can be specified multiple times). Example: - -ns_param map *.php - -The 'php_value "name val"' command assigns the configuration option name -the value val (can be used multiple times). Example: - -ns_param php_value "session.auto_start 1" - -b) Enabling PHP - -Then enable the PHP module: - -ns_section "ns/server/${servername}/modules" -... -ns_param php ${bindir}/libphp7.so - - -============================================================================= -This has been tested with AOLserver release 3.0. - -AOLserver support has been written by Sascha Schumann <sascha@schumann.cx>. diff --git a/sapi/aolserver/aolserver.c b/sapi/aolserver/aolserver.c deleted file mode 100644 index 4b6c5868b0..0000000000 --- a/sapi/aolserver/aolserver.c +++ /dev/null @@ -1,624 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* - * TODO: - * - write documentation - * - CGI/1.1 conformance - */ - -/* $Id$ */ - -/* conflict between PHP and AOLserver headers */ -#define Debug php_Debug -#include "php.h" -#undef Debug - -#ifdef HAVE_AOLSERVER - -#ifndef ZTS -#error AOLserver module is only useable in thread-safe mode -#endif - -#include "ext/standard/info.h" -#define SECTION(name) PUTS("<h2>" name "</h2>\n") - -#define NS_BUF_SIZE 511 - -#include "php_ini.h" -#include "php_globals.h" -#include "SAPI.h" -#include "php_main.h" -#include "php_variables.h" - -#include "ns.h" - -#include "php_version.h" - -/* This symbol is used by AOLserver to tell the API version we expect */ - -int Ns_ModuleVersion = 1; - -#define NSG(v) TSRMG(ns_globals_id, ns_globals_struct *, v) - -/* php_ns_context is per-server (thus only once at all) */ - -typedef struct { - sapi_module_struct *sapi_module; - char *ns_server; - char *ns_module; -} php_ns_context; - -/* ns_globals_struct is per-thread */ - -typedef struct { - Ns_Conn *conn; - size_t data_avail; -} ns_globals_struct; - -/* TSRM id */ - -static int ns_globals_id; - -/* global context */ - -static php_ns_context *global_context; - -static void php_ns_config(php_ns_context *ctx, char global); - -/* - * php_ns_sapi_ub_write() writes data to the client connection. - */ - -static int -php_ns_sapi_ub_write(const char *str, uint str_length) -{ - int n; - uint sent = 0; - - while (str_length > 0) { - n = Ns_ConnWrite(NSG(conn), (void *) str, str_length); - - if (n == -1) - php_handle_aborted_connection(); - - str += n; - sent += n; - str_length -= n; - } - - return sent; -} - -/* - * php_ns_sapi_header_handler() sets a HTTP reply header to be - * sent to the client. - */ - -static int -php_ns_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers) -{ - char *header_name, *header_content; - char *p; - - header_name = sapi_header->header; - header_content = p = strchr(header_name, ':'); - - if (p) { - *p = '\0'; - do { - header_content++; - } while (*header_content == ' '); - - if (!strcasecmp(header_name, "Content-type")) { - Ns_ConnSetTypeHeader(NSG(conn), header_content); - } else { - Ns_ConnSetHeaders(NSG(conn), header_name, header_content); - } - - *p = ':'; - } - - sapi_free_header(sapi_header); - - return 0; -} - -/* - * php_ns_sapi_send_headers() flushes the headers to the client. - * Called before real content is sent by PHP. - */ - -static int -php_ns_sapi_send_headers(sapi_headers_struct *sapi_headers) -{ - if(SG(sapi_headers).send_default_content_type) { - Ns_ConnSetRequiredHeaders(NSG(conn), "text/html", 0); - } - - Ns_ConnFlushHeaders(NSG(conn), SG(sapi_headers).http_response_code); - - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - -/* - * php_ns_sapi_read_post() reads a specified number of bytes from - * the client. Used for POST/PUT requests. - */ - -static int -php_ns_sapi_read_post(char *buf, uint count_bytes) -{ - uint max_read; - uint total_read = 0; - - max_read = MIN(NSG(data_avail), count_bytes); - - total_read = Ns_ConnRead(NSG(conn), buf, max_read); - - if(total_read == NS_ERROR) { - total_read = -1; - } else { - NSG(data_avail) -= total_read; - } - - return total_read; -} - -/* - * php_ns_sapi_read_cookies() returns the Cookie header from - * the HTTP request header - */ - -static char *php_ns_sapi_read_cookies(void) -{ - int i; - char *http_cookie = NULL; - - i = Ns_SetIFind(NSG(conn->headers), "cookie"); - if(i != -1) { - http_cookie = Ns_SetValue(NSG(conn->headers), i); - } - - return http_cookie; -} - -static void php_info_aolserver(ZEND_MODULE_INFO_FUNC_ARGS) -{ - char buf[512]; - int uptime = Ns_InfoUptime(); - int i; - - php_info_print_table_start(); - php_info_print_table_row(2, "SAPI module version", "$Id$"); - 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()); - php_info_print_table_row(2, "Installation path", Ns_InfoHomePath()); - php_info_print_table_row(2, "Hostname of server", Ns_InfoHostname()); - php_info_print_table_row(2, "Source code label", Ns_InfoLabel()); - php_info_print_table_row(2, "Server platform", Ns_InfoPlatform()); - snprintf(buf, 511, "%s/%s", Ns_InfoServerName(), Ns_InfoServerVersion()); - php_info_print_table_row(2, "Server version", buf); - snprintf(buf, 511, "%d day(s), %02d:%02d:%02d", - uptime / 86400, - (uptime / 3600) % 24, - (uptime / 60) % 60, - uptime % 60); - php_info_print_table_row(2, "Server uptime", buf); - php_info_print_table_end(); - - SECTION("HTTP Headers Information"); - php_info_print_table_start(); - php_info_print_table_colspan_header(2, "HTTP Request Headers"); - php_info_print_table_row(2, "HTTP Request", NSG(conn)->request->line); - for (i = 0; i < Ns_SetSize(NSG(conn)->headers); i++) { - php_info_print_table_row(2, Ns_SetKey(NSG(conn)->headers, i), Ns_SetValue(NSG(conn)->headers, i)); - } - - php_info_print_table_colspan_header(2, "HTTP Response Headers"); - for (i = 0; i < Ns_SetSize(NSG(conn)->outputheaders); i++) { - php_info_print_table_row(2, Ns_SetKey(NSG(conn)->outputheaders, i), Ns_SetValue(NSG(conn)->outputheaders, i)); - } - php_info_print_table_end(); -} - -PHP_FUNCTION(getallheaders); - -/* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO(arginfo_aolserver_getallheaders, 0) -ZEND_END_ARG_INFO() -/* }}} */ - -static const zend_function_entry aolserver_functions[] = { - PHP_FE(getallheaders, arginfo_aolserver_getallheaders) - {NULL, NULL, NULL} -}; - -static zend_module_entry php_aolserver_module = { - STANDARD_MODULE_HEADER, - "AOLserver", - aolserver_functions, - NULL, - NULL, - NULL, - NULL, - php_info_aolserver, - NULL, - STANDARD_MODULE_PROPERTIES -}; - -PHP_FUNCTION(getallheaders) -{ - int i; - - array_init(return_value); - - for (i = 0; i < Ns_SetSize(NSG(conn->headers)); i++) { - char *key = Ns_SetKey(NSG(conn->headers), i); - char *value = Ns_SetValue(NSG(conn->headers), i); - - add_assoc_string(return_value, key, value); - } -} - -static int -php_ns_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, &php_aolserver_module, 1) == FAILURE) { - return FAILURE; - } else { - return SUCCESS; - } -} - - -/* - * php_ns_sapi_register_variables() populates the php script environment - * with a number of variables. HTTP_* variables are created for - * the HTTP header data, so that a script can access these. - */ - -#define ADD_STRINGX(name, buf) \ - php_register_variable(name, buf, track_vars_array) - -#define ADD_STRING(name) \ - ADD_STRINGX(name, buf) - -static void -php_ns_sapi_register_variables(zval *track_vars_array) -{ - int i; - char buf[NS_BUF_SIZE + 1]; - char *tmp; - - for(i = 0; i < Ns_SetSize(NSG(conn->headers)); i++) { - char *key = Ns_SetKey(NSG(conn->headers), i); - char *value = Ns_SetValue(NSG(conn->headers), i); - char *p; - char c; - - snprintf(buf, NS_BUF_SIZE, "HTTP_%s", key); - - for(p = buf + 5; (c = *p); p++) { - c = toupper(c); - if(c < 'A' || c > 'Z') { - c = '_'; - } - *p = c; - } - - ADD_STRINGX(buf, value); - } - - snprintf(buf, NS_BUF_SIZE, "%s/%s", Ns_InfoServerName(), Ns_InfoServerVersion()); - ADD_STRING("SERVER_SOFTWARE"); - snprintf(buf, NS_BUF_SIZE, "HTTP/%1.1f", NSG(conn)->request->version); - ADD_STRING("SERVER_PROTOCOL"); - - ADD_STRINGX("REQUEST_METHOD", NSG(conn)->request->method); - - if(NSG(conn)->request->query) - ADD_STRINGX("QUERY_STRING", NSG(conn)->request->query); - - ADD_STRINGX("SERVER_BUILDDATE", Ns_InfoBuildDate()); - - ADD_STRINGX("REMOTE_ADDR", Ns_ConnPeer(NSG(conn))); - - snprintf(buf, NS_BUF_SIZE, "%d", Ns_ConnPeerPort(NSG(conn))); - ADD_STRING("REMOTE_PORT"); - - snprintf(buf, NS_BUF_SIZE, "%d", Ns_ConnPort(NSG(conn))); - ADD_STRING("SERVER_PORT"); - - tmp = Ns_ConnHost(NSG(conn)); - if (tmp) - ADD_STRINGX("SERVER_NAME", tmp); - - ADD_STRINGX("PATH_TRANSLATED", SG(request_info).path_translated); - ADD_STRINGX("REQUEST_URI", SG(request_info).request_uri); - ADD_STRINGX("PHP_SELF", SG(request_info).request_uri); - - ADD_STRINGX("GATEWAY_INTERFACE", "CGI/1.1"); - - snprintf(buf, NS_BUF_SIZE, "%d", Ns_InfoBootTime()); - ADD_STRING("SERVER_BOOTTIME"); -} - - - -/* this structure is static (as in "it does not change") */ - -static sapi_module_struct aolserver_sapi_module = { - "aolserver", - "AOLserver", - - php_ns_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - NULL, /* activate */ - NULL, /* deactivate */ - - php_ns_sapi_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, /* error handler */ - - php_ns_sapi_header_handler, /* header handler */ - php_ns_sapi_send_headers, /* send headers handler */ - NULL, /* send header handler */ - - php_ns_sapi_read_post, /* read POST data */ - php_ns_sapi_read_cookies, /* read Cookies */ - - php_ns_sapi_register_variables, - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* child terminate */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - -/* - * php_ns_module_main() is called by the per-request handler and - * "executes" the script - */ - -static int -php_ns_module_main(void) -{ - zend_file_handle file_handle; - - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = SG(request_info).path_translated; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - - php_ns_config(global_context, 0); - if (php_request_startup() == FAILURE) { - return NS_ERROR; - } - - php_execute_script(&file_handle); - php_request_shutdown(NULL); - - return NS_OK; -} - -/* - * php_ns_request_ctor() initializes the per-request data structure - * and fills it with data provided by the web server - */ - -static void -php_ns_request_ctor(void) -{ - char *server; - Ns_DString ds; - char *root; - int index; - char *tmp; - - server = Ns_ConnServer(NSG(conn)); - -#define safe_strdup(x) ((x)?strdup((x)):NULL) - SG(request_info).query_string = safe_strdup(NSG(conn->request->query)); - - Ns_DStringInit(&ds); - Ns_UrlToFile(&ds, server, NSG(conn->request->url)); - - /* path_translated is the absolute path to the file */ - SG(request_info).path_translated = safe_strdup(Ns_DStringValue(&ds)); - Ns_DStringFree(&ds); - root = Ns_PageRoot(server); - SG(request_info).request_uri = strdup(SG(request_info).path_translated + strlen(root)); - SG(request_info).request_method = NSG(conn)->request->method; - if(NSG(conn)->request->version > 1.0) SG(request_info).proto_num = 1001; - else SG(request_info).proto_num = 1000; - SG(request_info).content_length = Ns_ConnContentLength(NSG(conn)); - index = Ns_SetIFind(NSG(conn)->headers, "content-type"); - SG(request_info).content_type = index == -1 ? NULL : - Ns_SetValue(NSG(conn)->headers, index); - SG(sapi_headers).http_response_code = 200; - - tmp = Ns_ConnAuthUser(NSG(conn)); - if (tmp) - tmp = estrdup(tmp); - SG(request_info).auth_user = tmp; - - tmp = Ns_ConnAuthPasswd(NSG(conn)); - if (tmp) - tmp = estrdup(tmp); - SG(request_info).auth_password = tmp; - - NSG(data_avail) = SG(request_info).content_length; -} - -/* - * php_ns_request_dtor() destroys all data associated with - * the per-request structure - */ - -static void -php_ns_request_dtor(void) -{ - free(SG(request_info).path_translated); - if (SG(request_info).query_string) - free(SG(request_info).query_string); - free(SG(request_info).request_uri); -} - -/* - * The php_ns_request_handler() is called per request and handles - * everything for one request. - */ - -static int -php_ns_request_handler(void *context, Ns_Conn *conn) -{ - int status = NS_OK; - - NSG(conn) = conn; - - SG(server_context) = global_context; - - php_ns_request_ctor(); - - status = php_ns_module_main(); - - php_ns_request_dtor(); - - return status; -} - -/* - * php_ns_config() fetches the configuration data. - * - * It understands the "map" and "php_value" command. - */ - -static void -php_ns_config(php_ns_context *ctx, char global) -{ - int i; - char *path; - Ns_Set *set; - - path = Ns_ConfigGetPath(ctx->ns_server, ctx->ns_module, NULL); - set = Ns_ConfigGetSection(path); - - for (i = 0; set && i < Ns_SetSize(set); i++) { - char *key = Ns_SetKey(set, i); - char *value = Ns_SetValue(set, i); - - if (global && !strcasecmp(key, "map")) { - Ns_Log(Notice, "Registering PHP for \"%s\"", value); - Ns_RegisterRequest(ctx->ns_server, "GET", value, php_ns_request_handler, NULL, ctx, 0); - Ns_RegisterRequest(ctx->ns_server, "POST", value, php_ns_request_handler, NULL, ctx, 0); - Ns_RegisterRequest(ctx->ns_server, "HEAD", value, php_ns_request_handler, NULL, ctx, 0); - - /* - * Deactivated for now. The ini system will cause random crashes when - * accessed from here (since there are no locks to protect the global - * known_directives) - */ - - } else if (!global && !strcasecmp(key, "php_value")) { - Ns_Log(Notice, "php_value has been deactivated temporarily. Please use a php.ini file to pass directives to PHP. Thanks."); -#if 0 - char *val; - - val = strchr(value, ' '); - if (val) { - char *new_key; - - new_key = estrndup(value, val - value); - - do { - val++; - } while(*val == ' '); - - Ns_Log(Debug, "PHP configuration option '%s=%s'", new_key, val); - zend_alter_ini_entry(new_key, strlen(new_key) + 1, val, - strlen(val) + 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); - - efree(new_key); - } -#endif - } - - } -} - -/* - * php_ns_server_shutdown() performs the last steps before the - * server exits. Shutdowns basic services and frees memory - */ - -static void -php_ns_server_shutdown(void *context) -{ - php_ns_context *ctx = (php_ns_context *) context; - - ctx->sapi_module->shutdown(ctx->sapi_module); - sapi_shutdown(); - tsrm_shutdown(); - - free(ctx->ns_module); - free(ctx->ns_server); - free(ctx); -} - -/* - * Ns_ModuleInit() is called by AOLserver once at startup - * - * This functions allocates basic structures and initializes - * basic services. - */ - -int Ns_ModuleInit(char *server, char *module) -{ - php_ns_context *ctx; - - tsrm_startup(1, 1, 0, NULL); - sapi_startup(&aolserver_sapi_module); - sapi_module.startup(&aolserver_sapi_module); - - /* TSRM is used to allocate a per-thread structure */ - ts_allocate_id(&ns_globals_id, sizeof(ns_globals_struct), NULL, NULL); - - /* the context contains data valid for all threads */ - ctx = malloc(sizeof *ctx); - ctx->sapi_module = &aolserver_sapi_module; - ctx->ns_server = strdup(server); - ctx->ns_module = strdup(module); - - /* read the configuration */ - php_ns_config(ctx, 1); - - global_context = ctx; - - /* register shutdown handler */ - Ns_RegisterServerShutdown(server, php_ns_server_shutdown, ctx); - - return NS_OK; -} - -#endif diff --git a/sapi/aolserver/config.m4 b/sapi/aolserver/config.m4 deleted file mode 100644 index a193bfd058..0000000000 --- a/sapi/aolserver/config.m4 +++ /dev/null @@ -1,31 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(aolserver,, -[ --with-aolserver=DIR Specify path to the installed AOLserver], no, no) - -AC_MSG_CHECKING([for AOLserver support]) - -if test "$PHP_AOLSERVER" != "no"; then - if test -d "$PHP_AOLSERVER/include"; then - PHP_AOLSERVER_SRC=$PHP_AOLSERVER - fi - if test -z "$PHP_AOLSERVER_SRC" || test ! -d $PHP_AOLSERVER_SRC/include; then - AC_MSG_ERROR(Please specify the path to the source distribution of AOLserver using --with-aolserver-src=DIR) - fi - if test ! -d $PHP_AOLSERVER/bin ; then - AC_MSG_ERROR(Please specify the path to the root of AOLserver using --with-aolserver=DIR) - fi - PHP_BUILD_THREAD_SAFE - PHP_ADD_INCLUDE($PHP_AOLSERVER_SRC/include) - AC_DEFINE(HAVE_AOLSERVER,1,[Whether you have AOLserver]) - PHP_SELECT_SAPI(aolserver, shared, aolserver.c) - INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)$PHP_AOLSERVER/bin/" -fi - -AC_MSG_RESULT([$PHP_AOLSERVER]) - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/aolserver/config.w32 b/sapi/aolserver/config.w32 deleted file mode 100644 index 75b4361efc..0000000000 --- a/sapi/aolserver/config.w32 +++ /dev/null @@ -1,16 +0,0 @@ -// vim:ft=javascript -// $Id$ - -ARG_WITH('aolserver', 'Build AOLserver support', 'no'); - -if (PHP_AOLSERVER != "no") { - if (PHP_ZTS == "no") { - WARNING("AOLSERVER module requires an --enable-zts build of PHP"); - } else { - if (CHECK_HEADER_ADD_INCLUDE("ns.h", "CFLAGS_AOLSERVER", PHP_AOLSERVER) && CHECK_LIB("nsd.lib", "aolserver", PHP_AOLSERVER)) { - SAPI('aolserver', 'aolserver.c', 'php' + PHP_VERSION + 'aolserver.so', '/D XP_WIN32 '); - } else { - WARNING("sapi/aolserver not enabled: Could not find libraries/headers"); - } - } -} diff --git a/sapi/aolserver/php.sym b/sapi/aolserver/php.sym deleted file mode 100644 index b401ffd2b3..0000000000 --- a/sapi/aolserver/php.sym +++ /dev/null @@ -1,2 +0,0 @@ -Ns_ModuleVersion -Ns_ModuleInit diff --git a/sapi/apache/CREDITS b/sapi/apache/CREDITS deleted file mode 100644 index 991deb5633..0000000000 --- a/sapi/apache/CREDITS +++ /dev/null @@ -1,3 +0,0 @@ -Apache 1.3 -Rasmus Lerdorf, Zeev Suraski, Stig Bakken, David Sklar - diff --git a/sapi/apache/apMakefile.libdir b/sapi/apache/apMakefile.libdir deleted file mode 100644 index 7b5254013a..0000000000 --- a/sapi/apache/apMakefile.libdir +++ /dev/null @@ -1,4 +0,0 @@ -This is a place-holder which indicates to Configure that it shouldn't -provide the default targets when building the Makefile in this directory. -Instead it'll just prepend all the important variable definitions, and -copy the Makefile.tmpl onto the end. diff --git a/sapi/apache/apMakefile.tmpl b/sapi/apache/apMakefile.tmpl deleted file mode 100644 index c8b174775e..0000000000 --- a/sapi/apache/apMakefile.tmpl +++ /dev/null @@ -1,77 +0,0 @@ -## -## Apache 1.3 Makefile template for PHP 7.0 Module -## [src/modules/php7/Makefile.tmpl] -## - -# the parametrized target -LIB=libphp7.$(LIBEXT) - -# objects for building the static library -OBJS=mod_php7.o -OBJS_LIB=libmodphp7.a - -# objects for building the shared object library -SHLIB_OBJS=mod_php7.so-o -SHLIB_OBJS_LIB=libmodphp7.a - -# the general targets -all: lib -lib: $(LIB) - -# build the static library by merging the object files -libphp7.a: $(OBJS) $(OBJS_LIB) - cp $(OBJS_LIB) $@ - ar r $@ $(OBJS) - $(RANLIB) $@ - -# ugly hack to support older Apache-1.3 betas that don't set $LIBEXT -libphp7.: $(OBJS) $(OBJS_LIB) - cp $(OBJS_LIB) $@ - ar r $@ $(OBJS) - $(RANLIB) $@ - cp libphp7. libphp7.a - -# build the shared object library by linking the object files -libphp7.so: $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) - rm -f $@ - $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) $(LIBS) $(PHP_LIBS) - -# 1. extension .o for shared objects cannot be used here because -# first these files aren't still shared objects and second we -# have to use a different name to trigger the different -# implicit Make rule -# 2. extension -so.o (as used elsewhere) cannot be used because -# the suffix feature of Make really wants just .x, so we use -# extension .so-o -.SUFFIXES: .o .so-o -.c.o: - $(CC) -c $(INCLUDES) $(CFLAGS) $(PHP_CFLAGS) $(CPPFLAGS) $(SPACER) $< -.c.so-o: - $(CC) -c $(INCLUDES) $(CFLAGS) $(CFLAGS_SHLIB) $(PHP_CFLAGS) $(CPPFLAGS) $(SPACER) $< && mv $*.o $*.so-o - -# cleanup -clean: - -rm -f $(OBJS) $(SHLIB_OBJS) $(LIB) - -# We really don't expect end users to use this rule. It works only with -# gcc, and rebuilds Makefile.tmpl. You have to re-run Configure after -# using it. -depend: - cp Makefile.tmpl Makefile.tmpl.bak \ - && sed -ne '1,/^# DO NOT REMOVE/p' Makefile.tmpl > Makefile.new \ - && gcc -MM $(INCLUDES) $(CFLAGS) $(PHP_CFLAGS) $(CPPFLAGS) *.c >> Makefile.new \ - && sed -e '1,$$s: $(INCDIR)/: $$(INCDIR)/:g' Makefile.new \ - > Makefile.tmpl \ - && rm Makefile.new - -#Dependencies - -$(OBJS): Makefile - -# DO NOT REMOVE -mod_php7.o: mod_php7.c $(INCDIR)/httpd.h $(INCDIR)/conf.h \ - $(INCDIR)/buff.h \ - $(INCDIR)/http_config.h \ - $(INCDIR)/http_core.h $(INCDIR)/http_main.h \ - $(INCDIR)/http_protocol.h $(INCDIR)/http_request.h \ - $(INCDIR)/http_log.h $(INCDIR)/util_script.h mod_php7.h diff --git a/sapi/apache/config.m4 b/sapi/apache/config.m4 deleted file mode 100644 index f5bfde4d68..0000000000 --- a/sapi/apache/config.m4 +++ /dev/null @@ -1,273 +0,0 @@ -dnl -dnl $Id$ -dnl -AC_DEFUN([PHP_APACHE_FD_CHECK], [ -AC_CACHE_CHECK([for member fd in BUFF *],ac_cv_php_fd_in_buff,[ - save=$CPPFLAGS - if test -n "$APXS_INCLUDEDIR"; then - CPPFLAGS="$CPPFLAGS -I$APXS_INCLUDEDIR" - else - CPPFLAGS="$CPPFLAGS $APACHE_INCLUDE" - fi - AC_TRY_COMPILE([#include <httpd.h>],[conn_rec *c; int fd = c->client->fd;],[ - ac_cv_php_fd_in_buff=yes],[ac_cv_php_fd_in_buff=no],[ac_cv_php_fd_in_buff=no]) - CPPFLAGS=$save -]) -if test "$ac_cv_php_fd_in_buff" = "yes"; then - AC_DEFINE(PHP_APACHE_HAVE_CLIENT_FD,1,[ ]) -fi -]) - -dnl Apache 1.x shared module -PHP_ARG_WITH(apxs,, -[ --with-apxs[=FILE] Build shared Apache 1.x module. FILE is the optional - pathname to the Apache apxs tool [apxs]], no, no) - -AC_MSG_CHECKING([for Apache 1.x module support via DSO through APXS]) - -if test "$PHP_APXS" != "no"; then - if test "$PHP_APXS" = "yes"; then - APXS=apxs - $APXS -q CFLAGS >/dev/null 2>&1 - if test "$?" != "0" && test -x /usr/sbin/apxs; then #SUSE 6.x - APXS=/usr/sbin/apxs - fi - else - PHP_EXPAND_PATH($PHP_APXS, APXS) - fi - - $APXS -q CFLAGS >/dev/null 2>&1 - if test "$?" != "0"; then - AC_MSG_RESULT() - AC_MSG_RESULT() - AC_MSG_RESULT([Sorry, I was not able to successfully run APXS. Possible reasons:]) - AC_MSG_RESULT() - AC_MSG_RESULT([1. Perl is not installed;]) - AC_MSG_RESULT([2. Apache was not compiled with DSO support (--enable-module=so);]) - AC_MSG_RESULT([3. 'apxs' is not in your path. Try to use --with-apxs=/path/to/apxs]) - AC_MSG_RESULT([The output of $APXS follows]) - $APXS -q CFLAGS - AC_MSG_ERROR([Aborting]) - fi - - APXS_LDFLAGS="@SYBASE_LFLAGS@ @SYBASE_LIBS@ @SYBASE_CT_LFLAGS@ @SYBASE_CT_LIBS@" - APXS_INCLUDEDIR=`$APXS -q INCLUDEDIR` - APXS_CFLAGS=`$APXS -q CFLAGS` - APXS_HTTPD=`$APXS -q SBINDIR`/`$APXS -q TARGET` - APACHE_INCLUDE=-I$APXS_INCLUDEDIR - - # Test that we're trying to configure with apache 1.x - PHP_AP_EXTRACT_VERSION($APXS_HTTPD) - if test "$APACHE_VERSION" -ge 2000000; then - AC_MSG_ERROR([You have enabled Apache 1.3 support while your server is Apache 2. Please use the appropriate switch --with-apxs2]) - fi - - for flag in $APXS_CFLAGS; do - case $flag in - -D*) APACHE_CPPFLAGS="$APACHE_CPPFLAGS $flag";; - esac - done - - case $host_alias in - *aix*) - APXS_LIBEXECDIR=`$APXS -q LIBEXECDIR` - EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-brtl -Wl,-bI:$APXS_LIBEXECDIR/httpd.exp" - PHP_AIX_LDFLAGS="-Wl,-brtl" - build_type=shared - ;; - *darwin*) - MH_BUNDLE_FLAGS="-dynamic -twolevel_namespace -bundle -bundle_loader $APXS_HTTPD" - PHP_SUBST(MH_BUNDLE_FLAGS) - SAPI_SHARED=libs/libphp7.so - build_type=bundle - ;; - *) - build_type=shared - ;; - esac - - PHP_SELECT_SAPI(apache, $build_type, sapi_apache.c mod_php7.c php_apache.c, $APACHE_CPPFLAGS -I$APXS_INCLUDEDIR) - - # Test whether apxs support -S option - $APXS -q -S CFLAGS="$APXS_CFLAGS" CFLAGS >/dev/null 2>&1 - - if test "$?" != "0"; then - APACHE_INSTALL="$APXS -i -a -n php7 $SAPI_SHARED" # Old apxs does not have -S option - else - APXS_LIBEXECDIR='$(INSTALL_ROOT)'`$APXS -q LIBEXECDIR` - if test -z `$APXS -q SYSCONFDIR`; then - APACHE_INSTALL="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ - $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ - -i -n php7 $SAPI_SHARED" - else - APXS_SYSCONFDIR='$(INSTALL_ROOT)'`$APXS -q SYSCONFDIR` - APACHE_INSTALL="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ - \$(mkinstalldirs) '$APXS_SYSCONFDIR' && \ - $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ - -S SYSCONFDIR='$APXS_SYSCONFDIR' \ - -i -a -n php7 $SAPI_SHARED" - fi - fi - - if test -z "`$APXS -q LD_SHLIB`" || test "`$APXS -q LIBEXECDIR`" = "modules"; then - PHP_APXS_BROKEN=yes - fi - STRONGHOLD= - AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ]) - AC_DEFINE(HAVE_AP_COMPAT_H,1,[ ]) - AC_DEFINE(HAVE_APACHE,1,[ ]) - AC_MSG_RESULT(yes) -else - AC_MSG_RESULT(no) -fi - -dnl Apache 1.x static module -PHP_ARG_WITH(apache,, -[ --with-apache[=DIR] Build Apache 1.x module. DIR is the top-level Apache - build directory [/usr/local/apache]], no, no) - -AC_MSG_CHECKING([for Apache 1.x module support]) - -if test "$PHP_SAPI" != "apache" && test "$PHP_APACHE" != "no"; then - - if test "$PHP_APACHE" = "yes"; then - # Apache's default directory - PHP_APACHE=/usr/local/apache - fi - - APACHE_INSTALL_FILES="\$(srcdir)/sapi/apache/mod_php7.* sapi/apache/libphp7.module" - - AC_DEFINE(HAVE_APACHE,1,[ ]) - APACHE_MODULE=yes - PHP_EXPAND_PATH($PHP_APACHE, PHP_APACHE) - # For Apache 1.2.x - if test -f $PHP_APACHE/src/httpd.h; then - APACHE_INCLUDE=-I$PHP_APACHE/src - APACHE_TARGET=$PHP_APACHE/src - PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) - APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_INSTALL_FILES $APACHE_TARGET" - PHP_LIBS="-L. -lphp3" - AC_MSG_RESULT([yes - Apache 1.2.x]) - STRONGHOLD= - if test -f $PHP_APACHE/src/ap_config.h; then - AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ]) - fi - # For Apache 2.0.x - elif test -f $PHP_APACHE/include/httpd.h && test -f $PHP_APACHE/srclib/apr/include/apr_general.h ; then - AC_MSG_ERROR([Use --with-apxs2 with Apache 2.x!]) - # For Apache 1.3.x - elif test -f $PHP_APACHE/src/main/httpd.h; then - APACHE_HAS_REGEX=1 - APACHE_INCLUDE="-I$PHP_APACHE/src/main -I$PHP_APACHE/src/os/unix -I$PHP_APACHE/src/ap" - APACHE_TARGET=$PHP_APACHE/src/modules/php7 - if test ! -d $APACHE_TARGET; then - mkdir $APACHE_TARGET - fi - PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) - APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp7.a; cp $APACHE_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/sapi/apache/apMakefile.libdir $APACHE_TARGET/Makefile.libdir" - PHP_LIBS="-Lmodules/php7 -L../modules/php7 -L../../modules/php7 -lmodphp7" - AC_MSG_RESULT([yes - Apache 1.3.x]) - STRONGHOLD= - if test -f $PHP_APACHE/src/include/ap_config.h; then - AC_DEFINE(HAVE_AP_CONFIG_H, 1, [ ]) - fi - if test -f $PHP_APACHE/src/include/ap_compat.h; then - AC_DEFINE(HAVE_AP_COMPAT_H, 1, [ ]) - if test ! -f $PHP_APACHE/src/include/ap_config_auto.h; then - AC_MSG_ERROR([Please run Apache\'s configure or src/Configure program once and try again]) - fi - elif test -f $PHP_APACHE/src/include/compat.h; then - AC_DEFINE(HAVE_OLD_COMPAT_H, 1, [ ]) - fi - # Also for Apache 1.3.x - elif test -f $PHP_APACHE/src/include/httpd.h; then - APACHE_HAS_REGEX=1 - APACHE_INCLUDE="-I$PHP_APACHE/src/include -I$PHP_APACHE/src/os/unix" - APACHE_TARGET=$PHP_APACHE/src/modules/php7 - if test ! -d $APACHE_TARGET; then - mkdir $APACHE_TARGET - fi - PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) - PHP_LIBS="-Lmodules/php7 -L../modules/php7 -L../../modules/php7 -lmodphp7" - APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp7.a; cp $APACHE_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/sapi/apache/apMakefile.libdir $APACHE_TARGET/Makefile.libdir" - AC_MSG_RESULT([yes - Apache 1.3.x]) - STRONGHOLD= - if test -f $PHP_APACHE/src/include/ap_config.h; then - AC_DEFINE(HAVE_AP_CONFIG_H, 1, [ ]) - fi - if test -f $PHP_APACHE/src/include/ap_compat.h; then - AC_DEFINE(HAVE_AP_COMPAT_H, 1, [ ]) - if test ! -f $PHP_APACHE/src/include/ap_config_auto.h; then - AC_MSG_ERROR([Please run Apache\'s configure or src/Configure program once and try again]) - fi - elif test -f $PHP_APACHE/src/include/compat.h; then - AC_DEFINE(HAVE_OLD_COMPAT_H, 1, [ ]) - fi - # For StrongHold 2.2 - elif test -f $PHP_APACHE/apache/httpd.h; then - APACHE_INCLUDE="-I$PHP_APACHE/apache -I$PHP_APACHE/ssl/include" - APACHE_TARGET=$PHP_APACHE/apache - PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) - PHP_LIBS="-Lmodules/php7 -L../modules/php7 -L../../modules/php7 -lmodphp7" - APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp7.a; cp $APACHE_INSTALL_FILES $APACHE_TARGET" - STRONGHOLD=-DSTRONGHOLD=1 - AC_MSG_RESULT([yes - StrongHold]) - if test -f $PHP_APACHE/apache/ap_config.h; then - AC_DEFINE(HAVE_AP_CONFIG_H, 1, [ ]) - fi - if test -f $PHP_APACHE/src/ap_compat.h; then - AC_DEFINE(HAVE_AP_COMPAT_H, 1, [ ]) - if test ! -f $PHP_APACHE/src/include/ap_config_auto.h; then - AC_MSG_ERROR([Please run Apache\'s configure or src/Configure program once and try again]) - fi - elif test -f $PHP_APACHE/src/compat.h; then - AC_DEFINE(HAVE_OLD_COMPAT_H, 1, [ ]) - fi - else - AC_MSG_RESULT(no) - AC_MSG_ERROR([Invalid Apache directory - unable to find httpd.h under $PHP_APACHE]) - fi -else - AC_MSG_RESULT(no) -fi - -# compatibility -if test -z "$enable_mod_charset" && test "$with_mod_charset"; then - enable_mod_charset=$with_mod_charset -fi - -PHP_ARG_ENABLE(mod-charset, whether to enable Apache charset compatibility option, -[ --enable-mod-charset APACHE: Enable transfer tables for mod_charset (Rus Apache)], no, no) - -if test "$PHP_MOD_CHARSET" = "yes"; then - AC_DEFINE(USE_TRANSFER_TABLES, 1, [ ]) -fi - -dnl Build as static module -if test "$APACHE_MODULE" = "yes"; then - PHP_TARGET_RDYNAMIC - $php_shtool mkdir -p sapi/apache - PHP_OUTPUT(sapi/apache/libphp7.module) -fi - -dnl General -if test -n "$APACHE_INSTALL"; then - if test "x$APXS" != "x" -a "`uname -sv`" = "AIX 4" -a "$GCC" != "yes"; then - APXS_EXP=-bE:sapi/apache/mod_php7.exp - fi - - PHP_APACHE_FD_CHECK - INSTALL_IT=$APACHE_INSTALL - - PHP_SUBST(APXS_EXP) - PHP_SUBST(APACHE_INCLUDE) - PHP_SUBST(APACHE_TARGET) - PHP_SUBST(APXS) - PHP_SUBST(APXS_LDFLAGS) - PHP_SUBST(APACHE_INSTALL) - PHP_SUBST(STRONGHOLD) -fi - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/apache/config.w32 b/sapi/apache/config.w32 deleted file mode 100644 index e5b72f1bcf..0000000000 --- a/sapi/apache/config.w32 +++ /dev/null @@ -1,24 +0,0 @@ -// vim:ft=javascript -// $Id$ - -ARG_ENABLE('apache', 'Build Apache 1.3.x version of PHP', 'no'); - -ARG_WITH('apache-includes', 'Where to find Apache 1.3 headers', null); -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_PHP_BUILD + "\\apache\\src\\include") && - CHECK_LIB("ApacheCore.lib", "apache", php_usual_lib_suspects + - ';' + PROGRAM_FILES + '\\Apache Group\\Apache\\libexec' + - ";" + PHP_PHP_BUILD + "\\apache\\src\\corer")) { - // We need to play tricks to get our readdir.h used by apache - // headers - SAPI('apache', 'mod_php7.c sapi_apache.c php_apache.c', - 'php' + PHP_VERSION + 'apache.dll', - '/D APACHEPHP7_EXPORTS /D APACHE_READDIR_H /I win32'); - } else { - WARNING("Could not find apache libraries/headers"); - } -} diff --git a/sapi/apache/libphp7.module.in b/sapi/apache/libphp7.module.in deleted file mode 100644 index 892df4d5cc..0000000000 --- a/sapi/apache/libphp7.module.in +++ /dev/null @@ -1,11 +0,0 @@ -Name: php7_module -ConfigStart - RULE_WANTHSREGEX=no - RULE_HIDE=yes - PHP_LIBS="@NATIVE_RPATHS@ @PHP_LDFLAGS@ @PHP_LIBS@ @EXTRA_LDFLAGS@ @EXTRA_LIBS@ $LIBS" - PHP_CFLAGS="$CFLAGS @OPENSSL_INCDIR_OPT@ -I@php_abs_top_builddir@/main -I@php_abs_top_builddir@/Zend -I@php_abs_top_builddir@/TSRM -I@php_abs_top_srcdir@ -I@php_abs_top_srcdir@/sapi/apache -I@php_abs_top_srcdir@/main -I@php_abs_top_srcdir@/Zend -I@php_abs_top_srcdir@/TSRM" - my_outfile="Makefile.config" - echo "PHP_CFLAGS=$PHP_CFLAGS" >>$my_outfile - echo "PHP_LIBS=$PHP_LIBS" >>$my_outfile - LIBS=$PHP_LIBS -ConfigEnd diff --git a/sapi/apache/libpre.c b/sapi/apache/libpre.c deleted file mode 100644 index 94385dbbd1..0000000000 --- a/sapi/apache/libpre.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifdef NETWARE - -/* ------------------------------------------------------------------ - * These functions are to be called when the shared NLM starts and - * stops. By using these functions instead of defining a main() - * and calling ExitThread(TSR_THREAD, 0), the load time of the - * shared NLM is faster and memory size reduced. - * - * You may also want to override these in your own Apache module - * to do any cleanup other than the mechanism Apache modules provide. - * ------------------------------------------------------------------ - */ - - -#ifdef __GNUC__ -#include <string.h> /* memset */ -extern char _edata, _end ; /* end of DATA (start of BSS), end of BSS */ -#endif - -int _lib_start() -{ -/* printf("Inside _lib_start\n");*/ -#ifdef __GNUC__ - memset (&_edata, 0, &_end - &_edata); -#endif - return 0; -} - -int _lib_stop() -{ -/* printf("Inside _lib_stop\n");*/ - return 0; -} - -#endif /* NETWARE */ diff --git a/sapi/apache/mod_php7.c b/sapi/apache/mod_php7.c deleted file mode 100644 index 27d6579da8..0000000000 --- a/sapi/apache/mod_php7.c +++ /dev/null @@ -1,1045 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | (with helpful hints from Dean Gaudet <dgaudet@arctic.org> | - | PHP 4.0 patches by Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php_apache_http.h" -#include "http_conf_globals.h" - -#ifdef NETWARE -#define SIGPIPE SIGINT -#endif - -#undef shutdown - -/* {{{ Prototypes - */ -int apache_php_module_main(request_rec *r, int display_source_mode); -static void php_save_umask(void); -static void php_restore_umask(void); -static int sapi_apache_read_post(char *buffer, uint count_bytes); -static char *sapi_apache_read_cookies(void); -static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers); -static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers); -static int send_php(request_rec *r, int display_source_mode, char *filename); -static int send_parsed_php(request_rec * r); -static int send_parsed_php_source(request_rec * r); -static int php_xbithack_handler(request_rec * r); -static void php_init_handler(server_rec *s, pool *p); -/* }}} */ - -#if MODULE_MAGIC_NUMBER >= 19970728 -static void php_child_exit_handler(server_rec *s, pool *p); -#endif - -#if MODULE_MAGIC_NUMBER > 19961007 -#define CONST_PREFIX const -#else -#define CONST_PREFIX -#endif -static CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode); -static CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2); -static CONST_PREFIX char *php_apache_admin_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2); -static CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2); -static CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode); -static CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2); - -/* ### these should be defined in mod_php7.h or somewhere else */ -#define USE_PATH 1 -#define IGNORE_URL 2 -#define MAX_STATUS_LENGTH sizeof("xxxx LONGEST POSSIBLE STATUS DESCRIPTION") - -module MODULE_VAR_EXPORT php7_module; - -int saved_umask; -static unsigned char apache_php_initialized; - -typedef struct _php_per_dir_entry { - char *key; - char *value; - uint key_length; - uint value_length; - int type; - char htaccess; -} php_per_dir_entry; - -/* some systems are missing these from their header files */ - -/* {{{ php_save_umask - */ -static void php_save_umask(void) -{ - saved_umask = umask(077); - umask(saved_umask); -} -/* }}} */ - -/* {{{ sapi_apache_ub_write - */ -static int sapi_apache_ub_write(const char *str, uint str_length) -{ - int ret=0; - - if (SG(server_context)) { - ret = rwrite(str, str_length, (request_rec *) SG(server_context)); - } - if (ret != str_length) { - php_handle_aborted_connection(); - } - return ret; -} -/* }}} */ - -/* {{{ sapi_apache_flush - */ -static void sapi_apache_flush(void *server_context) -{ - if (server_context) { -#if MODULE_MAGIC_NUMBER > 19970110 - rflush((request_rec *) server_context); -#else - bflush((request_rec *) server_context->connection->client); -#endif - } -} -/* }}} */ - -/* {{{ sapi_apache_read_post - */ -static int sapi_apache_read_post(char *buffer, uint count_bytes) -{ - int total_read_bytes=0, read_bytes; - request_rec *r = (request_rec *) SG(server_context); - void (*handler)(int); - - /* - * This handles the situation where the browser sends a Expect: 100-continue header - * and needs to receive confirmation from the server on whether or not it can send - * the rest of the request. RFC 2616 - * - */ - if (!SG(read_post_bytes) && !ap_should_client_block(r)) { - return total_read_bytes; - } - - handler = signal(SIGPIPE, SIG_IGN); - while (total_read_bytes<count_bytes) { - hard_timeout("Read POST information", r); /* start timeout timer */ - read_bytes = get_client_block(r, buffer+total_read_bytes, count_bytes-total_read_bytes); - reset_timeout(r); - if (read_bytes<=0) { - break; - } - total_read_bytes += read_bytes; - } - signal(SIGPIPE, handler); - return total_read_bytes; -} -/* }}} */ - -/* {{{ sapi_apache_read_cookies - */ -static char *sapi_apache_read_cookies(void) -{ - return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, "HTTP_COOKIE"); -} -/* }}} */ - -/* {{{ sapi_apache_header_handler - */ -static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers) -{ - char *header_name, *header_content, *p; - request_rec *r = (request_rec *) SG(server_context); - if(!r) { - return 0; - } - - switch(op) { - case SAPI_HEADER_DELETE_ALL: - clear_table(r->headers_out); - return 0; - - 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, "Content-Length")) { - ap_set_content_length(r, strtol(header_content, (char **)NULL, 10)); - } 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 */ - - return SAPI_HEADER_ADD; - - default: - return 0; - } -} -/* }}} */ - -/* {{{ sapi_apache_send_headers - */ -static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers) -{ - request_rec *r = SG(server_context); - const char *sline = SG(sapi_headers).http_status_line; - int sline_len; - - if(r == NULL) { /* server_context is not here anymore */ - return SAPI_HEADER_SEND_FAILED; - } - - r->status = SG(sapi_headers).http_response_code; - - /* httpd requires that r->status_line is set to the first digit of - * the status-code: */ - if (sline && ((sline_len = strlen(sline)) > 12) && strncmp(sline, "HTTP/1.", 7) == 0 && sline[8] == ' ' && sline[12] == ' ') { - if ((sline_len - 9) > MAX_STATUS_LENGTH) { - r->status_line = ap_pstrndup(r->pool, sline + 9, MAX_STATUS_LENGTH); - } else { - r->status_line = ap_pstrndup(r->pool, sline + 9, sline_len - 9); - } - } - - if(r->status==304) { - send_error_response(r,0); - } else { - send_http_header(r); - } - return SAPI_HEADER_SENT_SUCCESSFULLY; -} -/* }}} */ - -/* {{{ sapi_apache_register_server_variables - */ -static void sapi_apache_register_server_variables(zval *track_vars_array) -{ - register int i; - array_header *arr = table_elts(((request_rec *) SG(server_context))->subprocess_env); - table_entry *elts = (table_entry *) arr->elts; - zval *path_translated; - HashTable *symbol_table; - unsigned int new_val_len; - - for (i = 0; i < arr->nelts; i++) { - char *val; - int val_len; - - if (elts[i].val) { - val = elts[i].val; - } else { - val = ""; - } - val_len = strlen(val); - if (sapi_module.input_filter(PARSE_SERVER, elts[i].key, &val, val_len, &new_val_len)) { - php_register_variable_safe(elts[i].key, val, new_val_len, track_vars_array); - } - } - - /* If PATH_TRANSLATED doesn't exist, copy it from SCRIPT_FILENAME */ - if (track_vars_array) { - symbol_table = Z_ARRVAL_P(track_vars_array); - } else { - symbol_table = NULL; - } - if (symbol_table - && !zend_hash_str_exists(symbol_table, "PATH_TRANSLATED", sizeof("PATH_TRANSLATED")-1) - && (path_translated = zend_hash_str_find(symbol_table, "SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME")-1)) != NULL) { - php_register_variable("PATH_TRANSLATED", Z_STRVAL_P(path_translated), track_vars_array); - } - - if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &((request_rec *) SG(server_context))->uri, strlen(((request_rec *) SG(server_context))->uri), &new_val_len)) { - php_register_variable("PHP_SELF", ((request_rec *) SG(server_context))->uri, track_vars_array); - } -} -/* }}} */ - -/* {{{ php_apache_startup - */ -static int php_apache_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, &apache_module_entry, 1) == FAILURE) { - return FAILURE; - } else { - return SUCCESS; - } -} -/* }}} */ - -/* {{{ php_apache_log_message - */ -static void php_apache_log_message(char *message) -{ - if (SG(server_context)) { -#if MODULE_MAGIC_NUMBER >= 19970831 - aplog_error(NULL, 0, APLOG_ERR | APLOG_NOERRNO, ((request_rec *) SG(server_context))->server, "%s", message); -#else - log_error(message, ((request_rec *) SG(server_context))->server); -#endif - } else { - fprintf(stderr, "%s\n", message); - } -} -/* }}} */ - -/* {{{ php_apache_request_shutdown - */ -static void php_apache_request_shutdown(void *dummy) -{ - - php_output_set_status(PHP_OUTPUT_DISABLED); - if (AP(in_request)) { - AP(in_request) = 0; - php_request_shutdown(dummy); - } - SG(server_context) = NULL; - /* - * The server context (request) is NOT invalid by the time - * run_cleanups() is called - */ -} -/* }}} */ - -/* {{{ php_apache_sapi_activate - */ -static int php_apache_sapi_activate(void) -{ - request_rec *r = (request_rec *) SG(server_context); - - /* - * For the Apache module version, this bit of code registers a cleanup - * function that gets triggered when our request pool is destroyed. - * We need this because at any point in our code we can be interrupted - * and that may happen before we have had time to free our memory. - * The php_request_shutdown function needs to free all outstanding allocated - * memory. - */ - block_alarms(); - register_cleanup(r->pool, NULL, php_apache_request_shutdown, php_request_shutdown_for_exec); - AP(in_request)=1; - unblock_alarms(); - - /* Override the default headers_only value - sometimes "GET" requests should actually only - * send headers. - */ - SG(request_info).headers_only = r->header_only; - return SUCCESS; -} -/* }}} */ - -/* {{{ php_apache_get_stat - */ -static struct stat *php_apache_get_stat(void) -{ - return &((request_rec *) SG(server_context))->finfo; -} -/* }}} */ - -/* {{{ php_apache_getenv - */ -static char *php_apache_getenv(char *name, size_t name_len) -{ - if (SG(server_context) == NULL) { - return NULL; - } - - return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, name); -} -/* }}} */ - -/* {{{ sapi_apache_get_fd - */ -static int sapi_apache_get_fd(int *nfd) -{ -#if PHP_APACHE_HAVE_CLIENT_FD - request_rec *r = SG(server_context); - int fd; - - fd = r->connection->client->fd; - - if (fd >= 0) { - if (nfd) *nfd = fd; - return SUCCESS; - } -#endif - return FAILURE; -} -/* }}} */ - -/* {{{ sapi_apache_force_http_10 - */ -static int sapi_apache_force_http_10(void) -{ - request_rec *r = SG(server_context); - - r->proto_num = HTTP_VERSION(1,0); - - return SUCCESS; -} -/* }}} */ - -/* {{{ sapi_apache_get_target_uid - */ -static int sapi_apache_get_target_uid(uid_t *obj) -{ - *obj = ap_user_id; - return SUCCESS; -} -/* }}} */ - -/* {{{ sapi_apache_get_target_gid - */ -static int sapi_apache_get_target_gid(gid_t *obj) -{ - *obj = ap_group_id; - return SUCCESS; -} -/* }}} */ - -/* {{{ php_apache_get_request_time - */ -static double php_apache_get_request_time(void) -{ - return (double) ((request_rec *)SG(server_context))->request_time; -} -/* }}} */ - -/* {{{ sapi_apache_child_terminate - */ -static void sapi_apache_child_terminate(void) -{ -#ifndef MULTITHREAD - ap_child_terminate((request_rec *)SG(server_context)); -#endif -} -/* }}} */ - -/* {{{ sapi_module_struct apache_sapi_module - */ -static sapi_module_struct apache_sapi_module = { - "apache", /* name */ - "Apache", /* pretty name */ - - php_apache_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - php_apache_sapi_activate, /* activate */ - NULL, /* deactivate */ - - sapi_apache_ub_write, /* unbuffered write */ - sapi_apache_flush, /* flush */ - php_apache_get_stat, /* get uid */ - php_apache_getenv, /* getenv */ - - php_error, /* error handler */ - - sapi_apache_header_handler, /* header handler */ - sapi_apache_send_headers, /* send headers handler */ - NULL, /* send header handler */ - - sapi_apache_read_post, /* read POST data */ - sapi_apache_read_cookies, /* read Cookies */ - - 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 */ - -#ifdef PHP_WIN32 - NULL, - NULL, -#else - block_alarms, /* Block interruptions */ - unblock_alarms, /* Unblock interruptions */ -#endif - - NULL, /* default post reader */ - NULL, /* treat data */ - NULL, /* exe location */ - 0, /* ini ignore */ - 0, /* ini ignore cwd */ - sapi_apache_get_fd, - sapi_apache_force_http_10, - sapi_apache_get_target_uid, - sapi_apache_get_target_gid -}; -/* }}} */ - -/* {{{ php_restore_umask - */ -static void php_restore_umask(void) -{ - umask(saved_umask); -} -/* }}} */ - -/* {{{ init_request_info - */ -static void init_request_info(void) -{ - request_rec *r = ((request_rec *) SG(server_context)); - char *content_length = (char *) table_get(r->subprocess_env, "CONTENT_LENGTH"); - const char *authorization=NULL; - char *tmp, *tmp_user; - - SG(request_info).query_string = r->args; - SG(request_info).path_translated = r->filename; - SG(request_info).request_uri = r->uri; - SG(request_info).request_method = (char *)r->method; - SG(request_info).content_type = (char *) table_get(r->subprocess_env, "CONTENT_TYPE"); - SG(request_info).content_length = (content_length ? atol(content_length) : 0); - SG(sapi_headers).http_response_code = r->status; - SG(request_info).proto_num = r->proto_num; - - if (r->headers_in) { - authorization = table_get(r->headers_in, "Authorization"); - } - - SG(request_info).auth_user = NULL; - SG(request_info).auth_password = NULL; - SG(request_info).auth_digest = NULL; - - if (authorization) { - char *p = getword(r->pool, &authorization, ' '); - if (!strcasecmp(p, "Basic")) { - tmp = uudecode(r->pool, authorization); - tmp_user = getword_nulls_nc(r->pool, &tmp, ':'); - if (tmp_user) { - r->connection->user = pstrdup(r->connection->pool, tmp_user); - r->connection->ap_auth_type = "Basic"; - SG(request_info).auth_user = estrdup(tmp_user); - } - if (tmp) { - SG(request_info).auth_password = estrdup(tmp); - } - } else if (!strcasecmp(p, "Digest")) { - r->connection->ap_auth_type = "Digest"; - SG(request_info).auth_digest = estrdup(authorization); - } - } -} -/* }}} */ - -/* {{{ php_apache_alter_ini_entries - */ -static int php_apache_alter_ini_entries(php_per_dir_entry *per_dir_entry) -{ - zend_string *key = zend_string_init(per_dir_entry->key, per_dir_entry->key_length, 0); - zend_alter_ini_entry_chars(key, per_dir_entry->value, per_dir_entry->value_length, per_dir_entry->type, per_dir_entry->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE); - zend_string_release(key); - return 0; -} -/* }}} */ - -/* {{{ php_apache_get_default_mimetype - */ -static char *php_apache_get_default_mimetype(request_rec *r) -{ - - char *mimetype; - if (SG(default_mimetype) || SG(default_charset)) { - /* Assume output will be of the default MIME type. Individual - scripts may change this later. */ - char *tmpmimetype; - tmpmimetype = sapi_get_default_content_type(); - mimetype = pstrdup(r->pool, tmpmimetype); - efree(tmpmimetype); - } else { - mimetype = SAPI_DEFAULT_MIMETYPE "; charset=" SAPI_DEFAULT_CHARSET; - } - return mimetype; -} -/* }}} */ - -/* {{{ send_php - */ -static int send_php(request_rec *r, int display_source_mode, char *filename) -{ - int retval; - HashTable *per_dir_conf; - - if (AP(in_request)) { - zend_file_handle fh; - - fh.filename = r->filename; - fh.opened_path = NULL; - fh.free_filename = 0; - fh.type = ZEND_HANDLE_FILENAME; - - zend_execute_scripts(ZEND_INCLUDE, NULL, 1, &fh); - return OK; - } - - SG(server_context) = r; - - zend_first_try { - - /* Make sure file exists */ - if (filename == NULL && r->finfo.st_mode == 0) { - return DECLINED; - } - - per_dir_conf = (HashTable *) get_module_config(r->per_dir_config, &php7_module); - if (per_dir_conf) { - zend_hash_apply((HashTable *) per_dir_conf, (apply_func_t) php_apache_alter_ini_entries); - } - - /* If PHP parser engine has been turned off with an "engine off" - * directive, then decline to handle this request - */ - if (!AP(engine)) { - r->content_type = php_apache_get_default_mimetype(r); - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return DECLINED; - } - if (filename == NULL) { - filename = r->filename; - } - - /* Apache 1.2 has a more complex mechanism for reading POST data */ -#if MODULE_MAGIC_NUMBER > 19961007 - if ((retval = setup_client_block(r, REQUEST_CHUNKED_DECHUNK))) { - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return retval; - } -#endif - - if (AP(last_modified)) { -#if MODULE_MAGIC_NUMBER < 19970912 - if ((retval = set_last_modified(r, r->finfo.st_mtime))) { - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return retval; - } -#else - update_mtime (r, r->finfo.st_mtime); - set_last_modified(r); - set_etag(r); -#endif - } - /* Assume output will be of the default MIME type. Individual - scripts may change this later in the request. */ - r->content_type = php_apache_get_default_mimetype(r); - - /* Init timeout */ - hard_timeout("send", r); - - php_save_umask(); - add_common_vars(r); - add_cgi_vars(r); - - init_request_info(); - apache_php_module_main(r, display_source_mode); - - /* Done, restore umask, turn off timeout, close file and return */ - php_restore_umask(); - kill_timeout(r); - } zend_end_try(); - - return OK; -} -/* }}} */ - -/* {{{ send_parsed_php - */ -static int send_parsed_php(request_rec * r) -{ - int result = send_php(r, 0, NULL); - - ap_table_setn(r->notes, "mod_php_memory_usage", - ap_psprintf(r->pool, "%lu", zend_memory_peak_usage(1))); - - return result; -} -/* }}} */ - -/* {{{ send_parsed_php_source - */ -static int send_parsed_php_source(request_rec * r) -{ - return send_php(r, 1, NULL); -} -/* }}} */ - -/* {{{ destroy_per_dir_entry - */ -static void destroy_per_dir_entry(zval *zv) -{ - php_per_dir_entry *per_dir_entry = Z_PTR_P(zv); - - free(per_dir_entry->key); - free(per_dir_entry->value); - free(per_dir_entry); -} -/* }}} */ - -/* {{{ copy_per_dir_entry - */ -static void copy_per_dir_entry(zval *zv) -{ - php_per_dir_entry *old_per_dir_entry = Z_PTR_P(zv); - php_per_dir_entry *new_per_dir_entry = malloc(sizeof(php_per_dir_entry)); - - memcpy(new_per_dir_entry, old_per_dir_entry, sizeof(php_per_dir_entry)); - Z_PTR_P(zv) = new_per_dir_entry; - - new_per_dir_entry->key = (char *) malloc(old_per_dir_entry->key_length+1); - memcpy(new_per_dir_entry->key, old_per_dir_entry->key, old_per_dir_entry->key_length); - new_per_dir_entry->key[new_per_dir_entry->key_length] = 0; - - new_per_dir_entry->value = (char *) malloc(old_per_dir_entry->value_length+1); - memcpy(new_per_dir_entry->value, old_per_dir_entry->value, old_per_dir_entry->value_length); - new_per_dir_entry->value[new_per_dir_entry->value_length] = 0; -} -/* }}} */ - -/* {{{ should_overwrite_per_dir_entry - */ -static zend_bool should_overwrite_per_dir_entry(HashTable *target_ht, zval *zv, zend_hash_key *hash_key, void *pData) -{ - php_per_dir_entry *new_per_dir_entry = Z_PTR_P(zv); - php_per_dir_entry *orig_per_dir_entry; - - if ((orig_per_dir_entry = zend_hash_find_ptr(target_ht, hash_key->key)) == NULL) { - return 1; /* does not exist in dest, copy from source */ - } - - if (orig_per_dir_entry->type==PHP_INI_SYSTEM - && new_per_dir_entry->type!=PHP_INI_SYSTEM) { - return 0; - } else { - return 1; - } -} -/* }}} */ - -/* {{{ php_destroy_per_dir_info - */ -static void php_destroy_per_dir_info(HashTable *per_dir_info) -{ - zend_hash_destroy(per_dir_info); - free(per_dir_info); -} -/* }}} */ - -/* {{{ php_create_dir - */ -static void *php_create_dir(pool *p, char *dummy) -{ - HashTable *per_dir_info; - - per_dir_info = (HashTable *) malloc(sizeof(HashTable)); - zend_hash_init_ex(per_dir_info, 5, NULL, destroy_per_dir_entry, 1, 0); - register_cleanup(p, (void *) per_dir_info, (void (*)(void *)) php_destroy_per_dir_info, (void (*)(void *)) zend_hash_destroy); - - return per_dir_info; -} -/* }}} */ - -/* {{{ php_merge_dir - */ -static void *php_merge_dir(pool *p, void *basev, void *addv) -{ - /* This function *must* not modify addv or basev */ - HashTable *new; - - /* need a copy of addv to merge */ - new = php_create_dir(p, "php_merge_dir"); - zend_hash_copy(new, (HashTable *) basev, copy_per_dir_entry); - - zend_hash_merge_ex(new, (HashTable *) addv, copy_per_dir_entry, should_overwrite_per_dir_entry, NULL); - return new; -} -/* }}} */ - -/* {{{ php_apache_value_handler_ex - */ -static CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode) -{ - php_per_dir_entry per_dir_entry; - - if (!apache_php_initialized) { - apache_php_initialized = 1; -#ifdef ZTS - tsrm_startup(1, 1, 0, NULL); -#endif - sapi_startup(&apache_sapi_module); - php_apache_startup(&apache_sapi_module); - } - per_dir_entry.type = mode; - per_dir_entry.htaccess = ((cmd->override & (RSRC_CONF|ACCESS_CONF)) == 0); - - if (strcasecmp(arg2, "none") == 0) { - arg2 = ""; - } - - per_dir_entry.key_length = strlen(arg1); - per_dir_entry.value_length = strlen(arg2); - - per_dir_entry.key = (char *) malloc(per_dir_entry.key_length+1); - memcpy(per_dir_entry.key, arg1, per_dir_entry.key_length); - per_dir_entry.key[per_dir_entry.key_length] = 0; - - per_dir_entry.value = (char *) malloc(per_dir_entry.value_length+1); - memcpy(per_dir_entry.value, arg2, per_dir_entry.value_length); - per_dir_entry.value[per_dir_entry.value_length] = 0; - - zend_hash_str_update_mem(conf, per_dir_entry.key, per_dir_entry.key_length, &per_dir_entry, sizeof(php_per_dir_entry)); - return NULL; -} -/* }}} */ - -/* {{{ php_apache_value_handler - */ -static CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2) -{ - return php_apache_value_handler_ex(cmd, conf, arg1, arg2, PHP_INI_PERDIR); -} -/* }}} */ - -/* {{{ php_apache_admin_value_handler - */ -static CONST_PREFIX char *php_apache_admin_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2) -{ - return php_apache_value_handler_ex(cmd, conf, arg1, arg2, PHP_INI_SYSTEM); -} -/* }}} */ - -/* {{{ php_apache_flag_handler_ex - */ -static CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode) -{ - char bool_val[2]; - - if (!strcasecmp(arg2, "On") || (arg2[0] == '1' && arg2[1] == '\0')) { - bool_val[0] = '1'; - } else { - bool_val[0] = '0'; - } - bool_val[1] = 0; - - return php_apache_value_handler_ex(cmd, conf, arg1, bool_val, mode); -} -/* }}} */ - -/* {{{ php_apache_flag_handler - */ -static CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2) -{ - return php_apache_flag_handler_ex(cmd, conf, arg1, arg2, PHP_INI_PERDIR); -} -/* }}} */ - -/* {{{ php_apache_admin_flag_handler - */ -static CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2) -{ - return php_apache_flag_handler_ex(cmd, conf, arg1, arg2, PHP_INI_SYSTEM); -} -/* }}} */ - -/* {{{ php_apache_phpini_set - */ -static CONST_PREFIX char *php_apache_phpini_set(cmd_parms *cmd, HashTable *conf, char *arg) -{ - if (apache_sapi_module.php_ini_path_override) { - return "Only first PHPINIDir directive honored per configuration tree - subsequent ones ignored"; - } - apache_sapi_module.php_ini_path_override = ap_server_root_relative(cmd->pool, arg); - return NULL; -} -/* }}} */ - -/* {{{ int php_xbithack_handler(request_rec * r) - */ -static int php_xbithack_handler(request_rec * r) -{ - HashTable *per_dir_conf; - - if (!(r->finfo.st_mode & S_IXUSR)) { - return DECLINED; - } - per_dir_conf = (HashTable *) get_module_config(r->per_dir_config, &php7_module); - if (per_dir_conf) { - zend_hash_apply((HashTable *) per_dir_conf, (apply_func_t) php_apache_alter_ini_entries); - } - if(!AP(xbithack)) { - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return DECLINED; - } - return send_parsed_php(r); -} -/* }}} */ - -/* {{{ apache_php_module_shutdown_wrapper - */ -static void apache_php_module_shutdown_wrapper(void) -{ - apache_php_initialized = 0; - apache_sapi_module.shutdown(&apache_sapi_module); - -#if MODULE_MAGIC_NUMBER >= 19970728 - /* This function is only called on server exit if the apache API - * child_exit handler exists, so shutdown globally - */ - sapi_shutdown(); -#endif - -#ifdef ZTS - tsrm_shutdown(); -#endif -} -/* }}} */ - -#if MODULE_MAGIC_NUMBER >= 19970728 -/* {{{ php_child_exit_handler - */ -static void php_child_exit_handler(server_rec *s, pool *p) -{ -/* apache_php_initialized = 0; */ - apache_sapi_module.shutdown(&apache_sapi_module); - -#ifdef ZTS - tsrm_shutdown(); -#endif -} -/* }}} */ -#endif - -/* {{{ void php_init_handler(server_rec *s, pool *p) - */ -static void php_init_handler(server_rec *s, pool *p) -{ - register_cleanup(p, NULL, (void (*)(void *))apache_php_module_shutdown_wrapper, (void (*)(void *))php_module_shutdown_for_exec); - if (!apache_php_initialized) { - apache_php_initialized = 1; -#ifdef ZTS - tsrm_startup(1, 1, 0, NULL); -#endif - sapi_startup(&apache_sapi_module); - php_apache_startup(&apache_sapi_module); - } -#if MODULE_MAGIC_NUMBER >= 19980527 - { - if (PG(expose_php)) { - ap_add_version_component("PHP/" PHP_VERSION); - } - } -#endif -} -/* }}} */ - -/* {{{ handler_rec php_handlers[] - */ -handler_rec php_handlers[] = -{ - {"application/x-httpd-php", send_parsed_php}, - {"application/x-httpd-php-source", send_parsed_php_source}, - {"text/html", php_xbithack_handler}, - {NULL} -}; -/* }}} */ - -/* {{{ command_rec php_commands[] - */ -command_rec php_commands[] = -{ - {"php_value", php_apache_value_handler, NULL, OR_OPTIONS, TAKE2, "PHP Value Modifier"}, - {"php_flag", php_apache_flag_handler, NULL, OR_OPTIONS, TAKE2, "PHP Flag Modifier"}, - {"php_admin_value", php_apache_admin_value_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Value Modifier (Admin)"}, - {"php_admin_flag", php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Flag Modifier (Admin)"}, - {"PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF, TAKE1, "Directory containing the php.ini file"}, - {NULL} -}; -/* }}} */ - -/* {{{ odule MODULE_VAR_EXPORT php7_module - */ -module MODULE_VAR_EXPORT php7_module = -{ - STANDARD_MODULE_STUFF, - php_init_handler, /* initializer */ - php_create_dir, /* per-directory config creator */ - php_merge_dir, /* dir merger */ - NULL, /* per-server config creator */ - NULL, /* merge server config */ - php_commands, /* command table */ - php_handlers, /* handlers */ - NULL, /* filename translation */ - NULL, /* check_user_id */ - NULL, /* check auth */ - NULL, /* check access */ - NULL, /* type_checker */ - NULL, /* fixups */ - NULL /* logger */ -#if MODULE_MAGIC_NUMBER >= 19970103 - , NULL /* header parser */ -#endif -#if MODULE_MAGIC_NUMBER >= 19970719 - , NULL /* child_init */ -#endif -#if MODULE_MAGIC_NUMBER >= 19970728 - , php_child_exit_handler /* child_exit */ -#endif -#if MODULE_MAGIC_NUMBER >= 19970902 - , NULL /* post read-request */ -#endif -}; -/* }}} */ - -/* - * 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/apache/mod_php7.exp b/sapi/apache/mod_php7.exp deleted file mode 100644 index 1469b0314d..0000000000 --- a/sapi/apache/mod_php7.exp +++ /dev/null @@ -1 +0,0 @@ -php7_module diff --git a/sapi/apache/mod_php7.h b/sapi/apache/mod_php7.h deleted file mode 100644 index 81b6b30b42..0000000000 --- a/sapi/apache/mod_php7.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: Rasmus Lerdorf <rasmus@php.net> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#ifndef MOD_PHP7_H -#define MOD_PHP7_H - -#if !defined(WIN32) && !defined(WINNT) -#ifndef MODULE_VAR_EXPORT -#define MODULE_VAR_EXPORT -#endif -#endif - -typedef struct { - long engine; - long last_modified; - long xbithack; - long terminate_child; - zend_bool in_request; -} php_apache_info_struct; - -extern zend_module_entry apache_module_entry; - -#ifdef ZTS -extern int php_apache_info_id; -#define AP(v) TSRMG(php_apache_info_id, php_apache_info_struct *, v) -#else -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_PHP7_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/sapi/apache/php.sym b/sapi/apache/php.sym deleted file mode 100644 index 1469b0314d..0000000000 --- a/sapi/apache/php.sym +++ /dev/null @@ -1 +0,0 @@ -php7_module diff --git a/sapi/apache/php_apache.c b/sapi/apache/php_apache.c deleted file mode 100644 index 33d8a72b99..0000000000 --- a/sapi/apache/php_apache.c +++ /dev/null @@ -1,607 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | Stig Sæther Bakken <ssb@php.net> | - | David Sklar <sklar@student.net> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php_apache_http.h" - -#if defined(PHP_WIN32) || defined(NETWARE) -#include "zend.h" -#include "ap_compat.h" -#endif - -#ifdef ZTS -int php_apache_info_id; -#else -php_apache_info_struct php_apache_info; -#endif - -#define SECTION(name) PUTS("<h2>" name "</h2>\n") - -#ifndef PHP_WIN32 -extern module *top_module; -extern module **ap_loaded_modules; -#else -extern __declspec(dllimport) module *top_module; -extern __declspec(dllimport) module **ap_loaded_modules; -#endif - -PHP_FUNCTION(virtual); -PHP_FUNCTION(apache_request_headers); -PHP_FUNCTION(apache_response_headers); -PHP_FUNCTION(apachelog); -PHP_FUNCTION(apache_note); -PHP_FUNCTION(apache_lookup_uri); -PHP_FUNCTION(apache_child_terminate); -PHP_FUNCTION(apache_setenv); -PHP_FUNCTION(apache_get_version); -PHP_FUNCTION(apache_get_modules); -PHP_FUNCTION(apache_reset_timeout); - -PHP_MINFO_FUNCTION(apache); - -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} -}; - - -PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("xbithack", "0", PHP_INI_ALL, OnUpdateLong, xbithack, php_apache_info_struct, php_apache_info) - STD_PHP_INI_ENTRY("engine", "1", PHP_INI_ALL, OnUpdateLong, engine, php_apache_info_struct, php_apache_info) - STD_PHP_INI_ENTRY("last_modified", "0", PHP_INI_ALL, OnUpdateLong, last_modified, php_apache_info_struct, php_apache_info) - STD_PHP_INI_ENTRY("child_terminate", "0", PHP_INI_ALL, OnUpdateLong, terminate_child, php_apache_info_struct, php_apache_info) -PHP_INI_END() - - - -static void php_apache_globals_ctor(php_apache_info_struct *apache_globals) -{ - apache_globals->in_request = 0; -} - - -static PHP_MINIT_FUNCTION(apache) -{ -#ifdef ZTS - ts_allocate_id(&php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL); -#else - php_apache_globals_ctor(&php_apache_info); -#endif - REGISTER_INI_ENTRIES(); - return SUCCESS; -} - - -static PHP_MSHUTDOWN_FUNCTION(apache) -{ - UNREGISTER_INI_ENTRIES(); - return SUCCESS; -} - -zend_module_entry apache_module_entry = { - STANDARD_MODULE_HEADER, - "apache", - apache_functions, - PHP_MINIT(apache), - PHP_MSHUTDOWN(apache), - NULL, - NULL, - PHP_MINFO(apache), - NO_VERSION_YET, - STANDARD_MODULE_PROPERTIES -}; - -/* {{{ PHP_MINFO_FUNCTION - */ -PHP_MINFO_FUNCTION(apache) -{ - char *apv = (char *) ap_get_server_version(); - module *modp = NULL; - char output_buf[128]; -#if !defined(WIN32) && !defined(WINNT) - char name[64]; - char modulenames[1024]; - char *p; -#endif - server_rec *serv; - extern char server_root[MAX_STRING_LEN]; - extern uid_t user_id; - extern char *user_name; - extern gid_t group_id; - extern int max_requests_per_child; - - serv = ((request_rec *) SG(server_context))->server; - - - php_info_print_table_start(); - -#ifdef PHP_WIN32 - php_info_print_table_row(1, "Apache for Windows 95/NT"); - php_info_print_table_end(); - php_info_print_table_start(); -#elif defined(NETWARE) - php_info_print_table_row(1, "Apache for NetWare"); - php_info_print_table_end(); - php_info_print_table_start(); -#else - php_info_print_table_row(2, "APACHE_INCLUDE", PHP_APACHE_INCLUDE); - php_info_print_table_row(2, "APACHE_TARGET", PHP_APACHE_TARGET); -#endif - - if (apv && *apv) { - php_info_print_table_row(2, "Apache Version", apv); - } - -#ifdef APACHE_RELEASE - snprintf(output_buf, sizeof(output_buf), "%d", APACHE_RELEASE); - php_info_print_table_row(2, "Apache Release", output_buf); -#endif - snprintf(output_buf, sizeof(output_buf), "%d", MODULE_MAGIC_NUMBER); - php_info_print_table_row(2, "Apache API Version", output_buf); - snprintf(output_buf, sizeof(output_buf), "%s:%u", serv->server_hostname, serv->port); - php_info_print_table_row(2, "Hostname:Port", output_buf); -#if !defined(WIN32) && !defined(WINNT) - snprintf(output_buf, sizeof(output_buf), "%s(%d)/%d", user_name, (int)user_id, (int)group_id); - php_info_print_table_row(2, "User/Group", output_buf); - snprintf(output_buf, sizeof(output_buf), "Per Child: %d - Keep Alive: %s - Max Per Connection: %d", max_requests_per_child, serv->keep_alive ? "on":"off", serv->keep_alive_max); - php_info_print_table_row(2, "Max Requests", output_buf); -#endif - snprintf(output_buf, sizeof(output_buf), "Connection: %d - Keep-Alive: %d", serv->timeout, serv->keep_alive_timeout); - php_info_print_table_row(2, "Timeouts", output_buf); -#if !defined(WIN32) && !defined(WINNT) -/* - This block seems to be working on NetWare; But it seems to be showing - all modules instead of just the loaded ones -*/ - php_info_print_table_row(2, "Server Root", server_root); - - strcpy(modulenames, ""); - for(modp = top_module; modp; modp = modp->next) { - strlcpy(name, modp->name, sizeof(name)); - if ((p = strrchr(name, '.'))) { - *p='\0'; /* Cut off ugly .c extensions on module names */ - } - strlcat(modulenames, name, sizeof(modulenames)); - if (modp->next) { - strlcat(modulenames, ", ", sizeof(modulenames)); - } - } - php_info_print_table_row(2, "Loaded Modules", modulenames); -#endif - - php_info_print_table_end(); - - DISPLAY_INI_ENTRIES(); - - { - register int i; - array_header *arr; - table_entry *elts; - request_rec *r; - - r = ((request_rec *) SG(server_context)); - arr = table_elts(r->subprocess_env); - elts = (table_entry *)arr->elts; - - SECTION("Apache Environment"); - php_info_print_table_start(); - php_info_print_table_header(2, "Variable", "Value"); - for (i=0; i < arr->nelts; i++) { - php_info_print_table_row(2, elts[i].key, elts[i].val); - } - php_info_print_table_end(); - } - - { - array_header *env_arr; - table_entry *env; - int i; - request_rec *r; - - r = ((request_rec *) SG(server_context)); - SECTION("HTTP Headers Information"); - php_info_print_table_start(); - php_info_print_table_colspan_header(2, "HTTP Request Headers"); - php_info_print_table_row(2, "HTTP Request", r->the_request); - env_arr = table_elts(r->headers_in); - env = (table_entry *)env_arr->elts; - for (i = 0; i < env_arr->nelts; ++i) { - if (env[i].key) { - php_info_print_table_row(2, env[i].key, env[i].val); - } - } - php_info_print_table_colspan_header(2, "HTTP Response Headers"); - env_arr = table_elts(r->headers_out); - env = (table_entry *)env_arr->elts; - for(i = 0; i < env_arr->nelts; ++i) { - if (env[i].key) { - php_info_print_table_row(2, env[i].key, env[i].val); - } - } - php_info_print_table_end(); - } -} -/* }}} */ - -/* {{{ 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, E_WARNING, "This function is disabled"); - RETURN_FALSE; - } -#else - php_error_docref(NULL, 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(), "s|s", ¬e_name, ¬e_name_len, ¬e_val, ¬e_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); - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool virtual(string filename) - Perform an Apache sub-request */ -/* This function is equivalent to <!--#include virtual...--> - * in mod_include. It does an Apache sub-request. It is useful - * for including CGI scripts or .shtml files, or anything else - * that you'd parse through Apache (for .phtml files, you'd probably - * want to use <?Include>. This only works when PHP is compiled - * as an Apache module, since it uses the Apache API for doing - * sub requests. - */ -PHP_FUNCTION(virtual) -{ - char *filename; - int filename_len; - request_rec *rr = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { - return; - } - - if (!(rr = sub_req_lookup_uri (filename, ((request_rec *) SG(server_context))))) { - php_error_docref(NULL, 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, E_WARNING, "Unable to include '%s' - error finding URI", filename); - if (rr) - destroy_sub_req (rr); - RETURN_FALSE; - } - - php_output_end_all(); - php_header(); - - if (run_sub_req(rr)) { - php_error_docref(NULL, E_WARNING, "Unable to include '%s' - request execution failed", filename); - if (rr) - destroy_sub_req (rr); - RETURN_FALSE; - } - - 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) { - if (!tenv[i].key) { - continue; - } - if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val)==FAILURE) { - RETURN_FALSE; - } - } -} -/* }}} */ - -/* {{{ proto array apache_response_headers(void) - 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) { - if (!tenv[i].key) continue; - if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val)==FAILURE) { - RETURN_FALSE; - } - } -} -/* }}} */ - -/* {{{ proto bool apache_setenv(string variable, string value [, bool walk_to_top]) - Set an Apache subprocess_env variable */ -PHP_FUNCTION(apache_setenv) -{ - int var_len, val_len; - zend_bool top=0; - char *var = NULL, *val = NULL; - request_rec *r = (request_rec *) SG(server_context); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) { - return; - } - - while(top) { - if(r->prev) r = r->prev; - else break; - } - - ap_table_setn(r->subprocess_env, ap_pstrndup(r->pool, var, var_len), ap_pstrndup(r->pool, val, val_len)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto object apache_lookup_uri(string URI) - Perform a partial request of the given URI to obtain information about it */ -PHP_FUNCTION(apache_lookup_uri) -{ - char *filename; - int filename_len; - request_rec *rr=NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) { - return; - } - - if (!(rr = sub_req_lookup_uri(filename, ((request_rec *) SG(server_context))))) { - php_error_docref(NULL, 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); - } - if (rr->status_line) { - add_property_string(return_value,"status_line", (char *)rr->status_line); - } - if (rr->method) { - add_property_string(return_value,"method", (char *)rr->method); - } - if (rr->content_type) { - add_property_string(return_value,"content_type", (char *)rr->content_type); - } - if (rr->handler) { - add_property_string(return_value,"handler", (char *)rr->handler); - } - if (rr->uri) { - add_property_string(return_value,"uri", rr->uri); - } - if (rr->filename) { - add_property_string(return_value,"filename", rr->filename); - } - if (rr->path_info) { - add_property_string(return_value,"path_info", rr->path_info); - } - if (rr->args) { - add_property_string(return_value,"args", rr->args); - } - if (rr->boundary) { - add_property_string(return_value,"boundary", rr->boundary); - } - - 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); - add_property_long(return_value,"sent_bodyct", rr->sent_bodyct); - add_property_long(return_value,"bytes_sent", rr->bytes_sent); - add_property_long(return_value,"byterange", rr->byterange); - add_property_long(return_value,"clength", rr->clength); - -#if MODULE_MAGIC_NUMBER >= 19980324 - if (rr->unparsed_uri) { - add_property_string(return_value,"unparsed_uri", rr->unparsed_uri); - } - if(rr->mtime) { - add_property_long(return_value,"mtime", rr->mtime); - } -#endif - if(rr->request_time) { - add_property_long(return_value,"request_time", rr->request_time); - } - - destroy_sub_req(rr); -} -/* }}} */ - - -#if 0 -/* -This function is most likely a bad idea. Just playing with it for now. -*/ -PHP_FUNCTION(apache_exec_uri) -{ - char *filename; - int filename_len; - request_rec *rr=NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) { - return; - } - - if(!(rr = ap_sub_req_lookup_uri(filename, ((request_rec *) SG(server_context))))) { - php_error_docref(NULL, E_WARNING, "URI lookup failed", filename); - RETURN_FALSE; - } - - RETVAL_LONG(ap_run_sub_req(rr)); - ap_destroy_sub_req(rr); -} -#endif - -/* {{{ proto string apache_get_version(void) - Fetch Apache version */ -PHP_FUNCTION(apache_get_version) -{ - char *apv = (char *) ap_get_server_version(); - - if (apv && *apv) { - RETURN_STRING(apv); - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto array apache_get_modules(void) - Get a list of loaded Apache modules */ -PHP_FUNCTION(apache_get_modules) -{ - int n; - char *p; - - array_init(return_value); - - for (n = 0; ap_loaded_modules[n]; ++n) { - char *s = (char *) ap_loaded_modules[n]->name; - if ((p = strchr(s, '.'))) { - add_next_index_stringl(return_value, s, (p - s)); - } else { - add_next_index_string(return_value, s); - } - } -} -/* }}} */ - -/* {{{ proto bool apache_reset_timeout(void) - Reset the Apache write timer */ -PHP_FUNCTION(apache_reset_timeout) -{ - ap_reset_timeout((request_rec *)SG(server_context)); - RETURN_TRUE; -} -/* }}} */ - -/* - * 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/apache/php_apache_http.h b/sapi/apache/php_apache_http.h deleted file mode 100644 index 00bb9ca91a..0000000000 --- a/sapi/apache/php_apache_http.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | Stig Sæther Bakken <ssb@php.net> | - | David Sklar <sklar@student.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#define NO_REGEX_EXTRA_H - -#ifdef WIN32 -#include <stddef.h> -#endif - -#ifdef NETWARE -#include <netinet/in.h> -#endif - -#include "zend.h" -#include "ext/ereg/php_regex.h" -#include "php_compat.h" - -#ifdef HAVE_OPENSSL_EXT -/* zlib typedefs free_func which causes problems if the SSL includes happen - * after zlib.h is included */ -# include <openssl/ssl.h> -#endif - -#ifdef regex_t -#undef regex_t -#endif - -#include "httpd.h" -#include "http_config.h" - -#if MODULE_MAGIC_NUMBER > 19980712 -# include "ap_compat.h" -#else -# if MODULE_MAGIC_NUMBER > 19980324 -# include "compat.h" -# endif -#endif - -#include "http_core.h" -#include "http_main.h" -#include "http_protocol.h" -#include "http_request.h" -#include "http_log.h" -#include "util_script.h" - -#include "php_variables.h" -#include "php_main.h" -#include "php_ini.h" -#include "ext/standard/php_standard.h" - -#include "mod_php7.h" diff --git a/sapi/apache/sapi_apache.c b/sapi/apache/sapi_apache.c deleted file mode 100644 index 302055ef25..0000000000 --- a/sapi/apache/sapi_apache.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | (with helpful hints from Dean Gaudet <dgaudet@arctic.org> | - | PHP 4.0 patches by: | - | Zeev Suraski <zeev@zend.com> | - | Stig Bakken <ssb@php.net> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php_apache_http.h" - -/* {{{ apache_php_module_main - */ -int apache_php_module_main(request_rec *r, int display_source_mode) -{ - int retval = OK; - zend_file_handle file_handle; - - if (php_request_startup() == FAILURE) { - return FAILURE; - } - /* sending a file handle to another dll is not working - so let zend open it. */ - - if (display_source_mode) { - zend_syntax_highlighter_ini syntax_highlighter_ini; - - php_get_highlight_struct(&syntax_highlighter_ini); - if (highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini) != SUCCESS) { - retval = NOT_FOUND; - } - } else { - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.handle.fd = 0; - file_handle.filename = SG(request_info).path_translated; - file_handle.opened_path = NULL; - file_handle.free_filename = 0; - - (void) php_execute_script(&file_handle); - } - - AP(in_request) = 0; - - zend_try { - php_request_shutdown(NULL); - } zend_end_try(); - - return retval; -} -/* }}} */ - -/* - * 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/apache2filter/CREDITS b/sapi/apache2filter/CREDITS deleted file mode 100644 index c298a9bf6a..0000000000 --- a/sapi/apache2filter/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Apache 2.0 Filter -Sascha Schumann, Aaron Bannert diff --git a/sapi/apache2filter/EXPERIMENTAL b/sapi/apache2filter/EXPERIMENTAL deleted file mode 100644 index 293159a693..0000000000 --- a/sapi/apache2filter/EXPERIMENTAL +++ /dev/null @@ -1,5 +0,0 @@ -this module is experimental, -its functions may change their names -or move to extension all together -so do not rely to much on them -you have been warned! diff --git a/sapi/apache2filter/README b/sapi/apache2filter/README deleted file mode 100644 index bd6eb17066..0000000000 --- a/sapi/apache2filter/README +++ /dev/null @@ -1,71 +0,0 @@ -WHAT IS THIS? - - This module exploits the layered I/O support in Apache 2.0. - -HOW DOES IT WORK? - - In Apache 2.0, you have handlers which generate content (like - reading a script from disk). The content goes then through - a chain of filters. PHP can be such a filter, so that it processes - your script and hands the output to the next filter (which will - usually cause a write to the network). - -DOES IT WORK? - - It is experimental as interfaces in Apache 2.0 might change in the - future. - -HOW TO INSTALL - - This SAPI module is known to work with Apache 2.0.40. - - $ cd apache-2.x - $ cd src - $ ./configure --enable-so - $ make install - - For testing purposes, you might want to use --with-mpm=prefork. - (Albeit PHP also works with threaded MPMs.) - - Configure PHP 4: - - $ cd php-4.x - $ ./configure --with-apxs2=/path/to/apache-2.0/bin/apxs - $ make install - - At the end of conf/httpd.conf, add: - - AddType application/x-httpd-php .php - - If you would like to enable source code highlighting functionality add: - - AddType application/x-httpd-php-source .phps - - That's it. Now start bin/httpd. - -HOW TO CONFIGURE - - The Apache 2.0 PHP module supports a new configuration directive that - allows an admin to override the php.ini search path. For example, - place your php.ini file in Apache's ServerRoot/conf directory and - add this to your httpd.conf file: - - PHPINIDir "conf" - -DEBUGGING APACHE AND PHP - - To debug Apache, we recommend: - - 1. Use the Prefork MPM (Apache 1.3-like process model) by - configuring Apache with '--with-mpm=prefork'. - 2. Start httpd using -DONE_PROCESS (e.g. (gdb) r -DONE_PROCESS). - - If you want to debug a part of the PHP startup procedure, set a - breakpoint on 'load_module'. Step through it until apr_dso_load() is - done. Then you can set a breakpoint on any PHP-related symbol. - -TODO - - PHP functions like apache_sub_req (see php_functions.c) - Protocol handlers - Passing script data to engine without temporary file diff --git a/sapi/apache2filter/apache_config.c b/sapi/apache2filter/apache_config.c deleted file mode 100644 index ed27616d16..0000000000 --- a/sapi/apache2filter/apache_config.c +++ /dev/null @@ -1,217 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS - -#include "php.h" -#include "php_ini.h" -#include "php_apache.h" - -#include "apr_strings.h" -#include "ap_config.h" -#include "util_filter.h" -#include "httpd.h" -#include "http_config.h" -#include "http_request.h" -#include "http_core.h" -#include "http_protocol.h" -#include "http_log.h" -#include "http_main.h" -#include "util_script.h" -#include "http_core.h" - -#ifdef PHP_AP_DEBUG -#define phpapdebug(a) fprintf a -#else -#define phpapdebug(a) -#endif - -typedef struct { - HashTable config; -} php_conf_rec; - -typedef struct { - char *value; - size_t value_len; - char status; - char htaccess; -} php_dir_entry; - -static const char *real_value_hnd(cmd_parms *cmd, void *dummy, const char *name, const char *value, int status) -{ - php_conf_rec *d = dummy; - php_dir_entry e; - - phpapdebug((stderr, "Getting %s=%s for %p (%d)\n", name, value, dummy, zend_hash_num_elements(&d->config))); - - if (!strncasecmp(value, "none", sizeof("none"))) { - value = ""; - } - - e.value = apr_pstrdup(cmd->pool, value); - e.value_len = strlen(value); - e.status = status; - e.htaccess = ((cmd->override & (RSRC_CONF|ACCESS_CONF)) == 0); - - zend_hash_update(&d->config, (char *) name, strlen(name) + 1, &e, sizeof(e), NULL); - return NULL; -} - -static const char *php_apache_value_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value) -{ - return real_value_hnd(cmd, dummy, name, value, PHP_INI_PERDIR); -} - -static const char *php_apache_admin_value_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value) -{ - return real_value_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM); -} - -static const char *real_flag_hnd(cmd_parms *cmd, void *dummy, const char *arg1, const char *arg2, int status) -{ - char bool_val[2]; - - if (!strcasecmp(arg2, "On") || (arg2[0] == '1' && arg2[1] == '\0')) { - bool_val[0] = '1'; - } else { - bool_val[0] = '0'; - } - bool_val[1] = 0; - - return real_value_hnd(cmd, dummy, arg1, bool_val, status); -} - -static const char *php_apache_flag_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value) -{ - return real_flag_hnd(cmd, dummy, name, value, PHP_INI_PERDIR); -} - -static const char *php_apache_admin_flag_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value) -{ - return real_flag_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM); -} - -static const char *php_apache_phpini_set(cmd_parms *cmd, void *mconfig, const char *arg) -{ - if (apache2_php_ini_path_override) { - return "Only first PHPINIDir directive honored per configuration tree - subsequent ones ignored"; - } - apache2_php_ini_path_override = ap_server_root_relative(cmd->pool, arg); - return NULL; -} - - -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; - php_dir_entry *pe; - php_dir_entry *data; - char *str; - uint str_len; - ulong num_index; - - n = create_php_config(p, "merge_php_config"); - zend_hash_copy(&n->config, &e->config, NULL, NULL, sizeof(php_dir_entry)); - - phpapdebug((stderr, "Merge dir (%p)+(%p)=(%p)\n", base_conf, new_conf, n)); - for (zend_hash_internal_pointer_reset(&d->config); - zend_hash_get_current_key(&d->config, &str, &str_len, - &num_index) == HASH_KEY_IS_STRING; - zend_hash_move_forward(&d->config)) { - pe = NULL; - zend_hash_get_current_data(&d->config, (void **) &data); - if ((pe = zend_hash_find(&n->config, str, str_len) != NULL) != NULL) { - if (pe->status >= data->status) continue; - } - zend_hash_update(&n->config, str, str_len, data, sizeof(*data), NULL); - phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", str, data->status, pe?pe->status:-1)); - } - - return n; -} - -char *get_php_config(void *conf, char *name, size_t name_len) -{ - php_conf_rec *d = conf; - php_dir_entry *pe; - - if ((pe = zend_hash_find(&d->config, name, name_len)) != NULL) { - return pe->value; - } - - return ""; -} - -void apply_config(void *dummy) -{ - php_conf_rec *d = dummy; - char *str; - uint str_len; - php_dir_entry *data; - - for (zend_hash_internal_pointer_reset(&d->config); - zend_hash_get_current_key(&d->config, &str, &str_len, NULL) == HASH_KEY_IS_STRING; - zend_hash_move_forward(&d->config)) { - zend_hash_get_current_data(&d->config, (void **) &data); - phpapdebug((stderr, "APPLYING (%s)(%s)\n", str, data->value)); - if (zend_alter_ini_entry(str, str_len, data->value, data->value_len, data->status, data->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE) == FAILURE) { - phpapdebug((stderr, "..FAILED\n")); - } - } -} - -const command_rec php_dir_cmds[] = -{ - AP_INIT_TAKE2("php_value", php_apache_value_handler, NULL, OR_OPTIONS, "PHP Value Modifier"), - AP_INIT_TAKE2("php_flag", php_apache_flag_handler, NULL, OR_OPTIONS, "PHP Flag Modifier"), - AP_INIT_TAKE2("php_admin_value", php_apache_admin_value_handler, NULL, ACCESS_CONF|RSRC_CONF, "PHP Value Modifier (Admin)"), - AP_INIT_TAKE2("php_admin_flag", php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, "PHP Flag Modifier (Admin)"), - AP_INIT_TAKE1("PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF, "Directory containing the php.ini file"), - {NULL} -}; - -static apr_status_t destroy_php_config(void *data) -{ - php_conf_rec *d = data; - - phpapdebug((stderr, "Destroying config %p\n", data)); - zend_hash_destroy(&d->config); - - return APR_SUCCESS; -} - -void *create_php_config(apr_pool_t *p, char *dummy) -{ - php_conf_rec *newx = (php_conf_rec *) apr_pcalloc(p, sizeof(*newx)); - - phpapdebug((stderr, "Creating new config (%p) for %s\n", newx, dummy)); - zend_hash_init(&newx->config, 0, NULL, NULL, 1); - apr_pool_cleanup_register(p, newx, destroy_php_config, apr_pool_cleanup_null); - return (void *) newx; -} - -/* - * 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/apache2filter/config.m4 b/sapi/apache2filter/config.m4 deleted file mode 100644 index 11cc051015..0000000000 --- a/sapi/apache2filter/config.m4 +++ /dev/null @@ -1,139 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(apxs2filter,, -[ --with-apxs2filter[=FILE] - EXPERIMENTAL: Build shared Apache 2.0 Filter module. FILE is the optional - pathname to the Apache apxs tool [apxs]], no, no) - -AC_MSG_CHECKING([for Apache 2.0 filter-module support via DSO through APXS]) - -if test "$PHP_APXS2FILTER" != "no"; then - if test "$PHP_APXS2FILTER" = "yes"; then - APXS=apxs - $APXS -q CFLAGS >/dev/null 2>&1 - if test "$?" != "0" && test -x /usr/sbin/apxs; then - APXS=/usr/sbin/apxs - fi - else - PHP_EXPAND_PATH($PHP_APXS2FILTER, APXS) - fi - - $APXS -q CFLAGS >/dev/null 2>&1 - if test "$?" != "0"; then - AC_MSG_RESULT() - AC_MSG_RESULT() - AC_MSG_RESULT([Sorry, I cannot run apxs. Possible reasons follow:]) - AC_MSG_RESULT() - AC_MSG_RESULT([1. Perl is not installed]) - AC_MSG_RESULT([2. apxs was not found. Try to pass the path using --with-apxs2filter=/path/to/apxs]) - AC_MSG_RESULT([3. Apache was not built using --enable-so (the apxs usage page is displayed)]) - AC_MSG_RESULT() - AC_MSG_RESULT([The output of $APXS follows:]) - $APXS -q CFLAGS - AC_MSG_ERROR([Aborting]) - fi - - APXS_INCLUDEDIR=`$APXS -q INCLUDEDIR` - APXS_BINDIR=`$APXS -q BINDIR` - APXS_HTTPD=`$APXS -q SBINDIR`/`$APXS -q TARGET` - APXS_CFLAGS=`$APXS -q CFLAGS` - APU_BINDIR=`$APXS -q APU_BINDIR` - APR_BINDIR=`$APXS -q APR_BINDIR` - - # Pick up ap[ru]-N-config if using httpd >=2.1 - APR_CONFIG=`$APXS -q APR_CONFIG 2>/dev/null || - echo $APR_BINDIR/apr-config` - APU_CONFIG=`$APXS -q APU_CONFIG 2>/dev/null || - echo $APU_BINDIR/apu-config` - - APR_CFLAGS="`$APR_CONFIG --cppflags --includes`" - APU_CFLAGS="`$APU_CONFIG --includes`" - - for flag in $APXS_CFLAGS; do - case $flag in - -D*) APACHE_CPPFLAGS="$APACHE_CPPFLAGS $flag";; - esac - done - - APACHE_CFLAGS="$APACHE_CPPFLAGS -I$APXS_INCLUDEDIR $APR_CFLAGS $APU_CFLAGS" - - # Test that we're trying to configure with apache 2.x - PHP_AP_EXTRACT_VERSION($APXS_HTTPD) - if test "$APACHE_VERSION" -le 2000000; then - AC_MSG_ERROR([You have enabled Apache 2 support while your server is Apache 1.3. Please use the appropriate switch --with-apxs (without the 2)]) - elif test "$APACHE_VERSION" -lt 2000040; then - AC_MSG_ERROR([Please note that Apache version >= 2.0.40 is required]) - fi - - APXS_LIBEXECDIR='$(INSTALL_ROOT)'`$APXS -q LIBEXECDIR` - if test -z `$APXS -q SYSCONFDIR`; then - INSTALL_IT="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ - $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ - -i -n php7" - else - APXS_SYSCONFDIR='$(INSTALL_ROOT)'`$APXS -q SYSCONFDIR` - INSTALL_IT="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ - \$(mkinstalldirs) '$APXS_SYSCONFDIR' && \ - $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ - -S SYSCONFDIR='$APXS_SYSCONFDIR' \ - -i -a -n php7" - fi - - case $host_alias in - *aix*) - EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-brtl -Wl,-bI:$APXS_LIBEXECDIR/httpd.exp" - PHP_SELECT_SAPI(apache2filter, shared, sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS) - INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL" - ;; - *darwin*) - dnl When using bundles on Darwin, we must resolve all symbols. However, - dnl the linker does not recursively look at the bundle loader and - dnl pull in its dependencies. Therefore, we must pull in the APR - dnl and APR-util libraries. - if test -x "$APR_CONFIG"; then - MH_BUNDLE_FLAGS="`$APR_CONFIG --ldflags --link-ld --libs`" - fi - if test -x "$APU_CONFIG"; then - MH_BUNDLE_FLAGS="`$APU_CONFIG --ldflags --link-ld --libs` $MH_BUNDLE_FLAGS" - fi - MH_BUNDLE_FLAGS="-bundle -bundle_loader $APXS_HTTPD $MH_BUNDLE_FLAGS" - PHP_SUBST(MH_BUNDLE_FLAGS) - PHP_SELECT_SAPI(apache2filter, bundle, sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS) - SAPI_SHARED=libs/libphp7.so - INSTALL_IT="$INSTALL_IT $SAPI_SHARED" - ;; - *beos*) - if test -f _APP_; then `rm _APP_`; fi - `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" - ;; - *) - PHP_SELECT_SAPI(apache2filter, shared, sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS) - INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL" - ;; - esac - - if test "$APACHE_VERSION" -lt 2004001; then - APXS_MPM=`$APXS -q MPM_NAME` - if test "$APXS_MPM" != "prefork" && test "$APXS_MPM" != "peruser" && test "$APXS_MPM" != "itk"; then - PHP_BUILD_THREAD_SAFE - fi - else - APACHE_THREADED_MPM=`$APXS_HTTPD -V | grep 'threaded:.*yes'` - if test -n "$APACHE_THREADED_MPM"; then - PHP_BUILD_THREAD_SAFE - fi - fi - AC_MSG_RESULT(yes) - PHP_SUBST(APXS) -else - AC_MSG_RESULT(no) -fi - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/apache2filter/config.w32 b/sapi/apache2filter/config.w32 deleted file mode 100755 index 361d031074..0000000000 --- a/sapi/apache2filter/config.w32 +++ /dev/null @@ -1,39 +0,0 @@ -// vim:ft=javascript -// $Id$ - -ARG_ENABLE('apache2filter', 'Build Apache 2.x filter', 'no'); - -if (PHP_APACHE2FILTER != "no") { - 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") - ) { - SAPI('apache2filter', 'sapi_apache2.c apache_config.c php_functions.c', - 'php' + PHP_VERSION + 'apache2_filter.dll', - '/D PHP_APACHE2_EXPORTS /I win32'); - } else { - WARNING("Could not find apache2 filter libraries/headers"); - } -} - -ARG_ENABLE('apache2-2filter', 'Build Apache 2.2.x filter', 'no'); - -if (PHP_APACHE2_2FILTER != "no") { - 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") - ) { - SAPI('apache2_2filter', 'sapi_apache2.c apache_config.c php_functions.c', - 'php' + PHP_VERSION + 'apache2_2_filter.dll', - '/D PHP_APACHE2_EXPORTS /I win32', - 'sapi\\apache2_2filter'); - } else { - WARNING("Could not find apache2.2 filter libraries/headers"); - } -} diff --git a/sapi/apache2filter/php.sym b/sapi/apache2filter/php.sym deleted file mode 100644 index 1469b0314d..0000000000 --- a/sapi/apache2filter/php.sym +++ /dev/null @@ -1 +0,0 @@ -php7_module diff --git a/sapi/apache2filter/php_apache.h b/sapi/apache2filter/php_apache.h deleted file mode 100644 index 72d4896820..0000000000 --- a/sapi/apache2filter/php_apache.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef PHP_APACHE_H -#define PHP_APACHE_H - -#include "httpd.h" -#include "http_config.h" -#include "http_core.h" - -/* Declare this so we can get to it from outside the sapi_apache2.c file */ -extern module AP_MODULE_DECLARE_DATA php7_module; - -/* A way to specify the location of the php.ini dir in an apache directive */ -extern char *apache2_php_ini_path_override; - -/* The server_context used by PHP */ -typedef struct php_struct { - int state; - request_rec *r; - ap_filter_t *f; /* downstream output filters after the PHP filter. */ - /* stat structure of the current file */ - struct stat finfo; - /* Set-aside request body bucket brigade */ - apr_bucket_brigade *post_data; - /* Whether or not we've processed PHP in the output filters yet. */ - int request_processed; -} php_struct; - -typedef struct _php_apr_bucket_brigade { - apr_bucket_brigade *bb; -} php_apr_bucket_brigade; - -void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf); -void *create_php_config(apr_pool_t *p, char *dummy); -char *get_php_config(void *conf, char *name, size_t name_len); -void apply_config(void *); -extern const command_rec php_dir_cmds[]; - -static size_t php_apache_read_stream(void *, char *, size_t); -static size_t php_apache_fsizer_stream(void *); - -#define APR_ARRAY_FOREACH_OPEN(arr, key, val) \ -{ \ - apr_table_entry_t *elts; \ - int i; \ - elts = (apr_table_entry_t *) arr->elts; \ - for (i = 0; i < arr->nelts; i++) { \ - key = elts[i].key; \ - val = elts[i].val; - -#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 deleted file mode 100644 index 061fc7b26c..0000000000 --- a/sapi/apache2filter/php_functions.c +++ /dev/null @@ -1,425 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - - -#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS - -#include "php.h" -#include "zend_smart_str.h" -#include "ext/standard/info.h" -#include "SAPI.h" - -#define CORE_PRIVATE -#include "apr_strings.h" -#include "apr_time.h" -#include "ap_config.h" -#include "util_filter.h" -#include "httpd.h" -#include "http_config.h" -#include "http_request.h" -#include "http_core.h" -#include "http_protocol.h" -#include "http_log.h" -#include "http_main.h" -#include "util_script.h" -#include "http_core.h" - -#include "php_apache.h" - -static request_rec *php_apache_lookup_uri(char *filename) -{ - php_struct *ctx; - - if (!filename) { - return NULL; - } - - ctx = SG(server_context); - return ap_sub_req_lookup_uri(filename, ctx->f->r, ctx->f->next); -} - -/* {{{ proto bool virtual(string uri) - Perform an apache sub-request */ -PHP_FUNCTION(virtual) -{ - char *filename; - int filename_len; - request_rec *rr; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { - return; - } - - if (!(rr = php_apache_lookup_uri(filename))) { - php_error_docref(NULL, 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, E_WARNING, "Unable to include '%s' - request execution failed", filename); - ap_destroy_sub_req(rr); - RETURN_FALSE; - } - ap_destroy_sub_req(rr); - RETURN_TRUE; - } - - php_error_docref(NULL, E_WARNING, "Unable to include '%s' - error finding URI", filename); - ap_destroy_sub_req(rr); - RETURN_FALSE; -} -/* }}} */ - -#define ADD_LONG(name) \ - add_property_long(return_value, #name, rr->name) -#define ADD_TIME(name) \ - add_property_long(return_value, #name, apr_time_sec(rr->name)); -#define ADD_STRING(name) \ - if (rr->name) add_property_string(return_value, #name, (char *) rr->name) - -PHP_FUNCTION(apache_lookup_uri) -{ - request_rec *rr; - char *filename; - int filename_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { - return; - } - - if (!(rr = php_apache_lookup_uri(filename))) { - php_error_docref(NULL, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); - RETURN_FALSE; - } - - if (rr->status == HTTP_OK) { - object_init(return_value); - - ADD_LONG(status); - ADD_STRING(the_request); - ADD_STRING(status_line); - ADD_STRING(method); - ADD_TIME(mtime); - ADD_LONG(clength); -#if MODULE_MAGIC_NUMBER < 20020506 - ADD_STRING(boundary); -#endif - ADD_STRING(range); - ADD_LONG(chunked); - ADD_STRING(content_type); - ADD_STRING(handler); - ADD_LONG(no_cache); - ADD_LONG(no_local_copy); - ADD_STRING(unparsed_uri); - ADD_STRING(uri); - ADD_STRING(filename); - ADD_STRING(path_info); - ADD_STRING(args); - ADD_LONG(allowed); - ADD_LONG(sent_bodyct); - ADD_LONG(bytes_sent); - ADD_LONG(mtime); - ADD_TIME(request_time); - - ap_destroy_sub_req(rr); - return; - } - - php_error_docref(NULL, E_WARNING, "Unable to include '%s' - error finding URI", filename); - ap_destroy_sub_req(rr); - RETURN_FALSE; -} - -/* {{{ proto array getallheaders(void) - Fetch all HTTP request headers */ -PHP_FUNCTION(apache_request_headers) -{ - php_struct *ctx; - const apr_array_header_t *arr; - char *key, *val; - - array_init(return_value); - - ctx = SG(server_context); - arr = apr_table_elts(ctx->f->r->headers_in); - - APR_ARRAY_FOREACH_OPEN(arr, key, val) - if (!val) val = ""; - add_assoc_string(return_value, key, val); - APR_ARRAY_FOREACH_CLOSE() -} -/* }}} */ - -/* {{{ proto array apache_response_headers(void) - Fetch all HTTP response headers */ -PHP_FUNCTION(apache_response_headers) -{ - php_struct *ctx; - const apr_array_header_t *arr; - char *key, *val; - - array_init(return_value); - - ctx = SG(server_context); - arr = apr_table_elts(ctx->f->r->headers_out); - - APR_ARRAY_FOREACH_OPEN(arr, key, val) - if (!val) val = ""; - add_assoc_string(return_value, key, val); - APR_ARRAY_FOREACH_CLOSE() -} -/* }}} */ - -/* {{{ proto string apache_note(string note_name [, string note_value]) - Get and set Apache request notes */ -PHP_FUNCTION(apache_note) -{ - php_struct *ctx; - char *note_name, *note_val = NULL; - int note_name_len, note_val_len; - char *old_note_val=NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", ¬e_name, ¬e_name_len, ¬e_val, ¬e_val_len) == FAILURE) { - return; - } - - ctx = SG(server_context); - - 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); - } - - RETURN_FALSE; -} -/* }}} */ - - -/* {{{ proto bool apache_setenv(string variable, string value [, bool walk_to_top]) - Set an Apache subprocess_env variable */ -PHP_FUNCTION(apache_setenv) -{ - php_struct *ctx; - 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 (zend_parse_parameters(arg_count, "ss|b", &variable, &variable_len, &string_val, &string_val_len, &walk_to_top) == FAILURE) { - return; - } - - ctx = SG(server_context); - - if (arg_count == 3 && walk_to_top) { - while(ctx->f->r->prev) { - ctx->f->r = ctx->f->r->prev; - } - } - - apr_table_set(ctx->r->subprocess_env, variable, string_val); - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool apache_getenv(string variable [, bool walk_to_top]) - Get an Apache subprocess_env variable */ -PHP_FUNCTION(apache_getenv) -{ - php_struct *ctx; - char *variable=NULL; - int variable_len; - zend_bool walk_to_top = 0; - int arg_count = ZEND_NUM_ARGS(); - char *env_val=NULL; - - if (zend_parse_parameters(arg_count, "s|b", &variable, &variable_len, &walk_to_top) == FAILURE) { - return; - } - - ctx = SG(server_context); - - if (arg_count == 2 && walk_to_top) { - while(ctx->f->r->prev) { - ctx->f->r = ctx->f->r->prev; - } - } - - env_val = (char*) apr_table_get(ctx->r->subprocess_env, variable); - if (env_val != NULL) { - RETURN_STRING(env_val, 1); - } - - RETURN_FALSE; -} -/* }}} */ - -static char *php_apache_get_version() -{ -#if MODULE_MAGIC_NUMBER_MAJOR >= 20060905 - return (char *) ap_get_server_banner(); -#else - return (char *) ap_get_server_version(); -#endif -} - -/* {{{ proto string apache_get_version(void) - Fetch Apache version */ -PHP_FUNCTION(apache_get_version) -{ - char *apv = php_apache_get_version(); - - if (apv && *apv) { - RETURN_STRING(apv, 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto array apache_get_modules(void) - Get a list of loaded Apache modules */ -PHP_FUNCTION(apache_get_modules) -{ - int n; - char *p; - - array_init(return_value); - - for (n = 0; ap_loaded_modules[n]; ++n) { - char *s = (char *) ap_loaded_modules[n]->name; - if ((p = strchr(s, '.'))) { - add_next_index_stringl(return_value, s, (p - s)); - } else { - add_next_index_string(return_value, s); - } - } -} -/* }}} */ - -PHP_MINFO_FUNCTION(apache) -{ - char *apv = php_apache_get_version(); - smart_str tmp1 = {0}; - int n; - char *p; - - for (n = 0; ap_loaded_modules[n]; ++n) { - char *s = (char *) ap_loaded_modules[n]->name; - if ((p = strchr(s, '.'))) { - smart_str_appendl(&tmp1, s, (p - s)); - } else { - smart_str_appends(&tmp1, s); - } - smart_str_appendc(&tmp1, ' '); - } - if ((tmp1.len - 1) >= 0) { - tmp1.c[tmp1.len - 1] = '\0'; - } - - php_info_print_table_start(); - if (apv && *apv) { - php_info_print_table_row(2, "Apache Version", apv); - } - php_info_print_table_row(2, "Loaded Modules", tmp1.c); - smart_str_free(&tmp1); - php_info_print_table_end(); -} - -/* {{{ 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} -}; - -zend_module_entry php_apache_module = { - STANDARD_MODULE_HEADER, - "apache2filter", - apache_functions, - NULL, - NULL, - NULL, - NULL, - PHP_MINFO(apache), - NULL, - STANDARD_MODULE_PROPERTIES -}; - -/* - * 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/apache2filter/sapi_apache2.c b/sapi/apache2filter/sapi_apache2.c deleted file mode 100644 index 3b639db61a..0000000000 --- a/sapi/apache2filter/sapi_apache2.c +++ /dev/null @@ -1,756 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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. | - +----------------------------------------------------------------------+ - | Authors: Sascha Schumann <sascha@schumann.cx> | - | Parts based on Apache 1.3 SAPI module by | - | Rasmus Lerdorf and Zeev Suraski | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include <fcntl.h> - -#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS - -#include "php.h" -#include "php_main.h" -#include "php_ini.h" -#include "php_variables.h" -#include "SAPI.h" - -#include "zend_smart_str.h" -#ifndef NETWARE -#include "ext/standard/php_standard.h" -#else -#include "ext/standard/basic_functions.h" -#endif - -#include "apr_strings.h" -#include "ap_config.h" -#include "apr_buckets.h" -#include "util_filter.h" -#include "httpd.h" -#include "http_config.h" -#include "http_request.h" -#include "http_core.h" -#include "http_protocol.h" -#include "http_log.h" -#include "http_main.h" -#include "util_script.h" -#include "http_core.h" -#include "ap_mpm.h" - -#include "php_apache.h" - -/* UnixWare and Netware define shutdown to _shutdown, which causes problems later - * on when using a structure member named shutdown. Since this source - * file does not use the system call shutdown, it is safe to #undef it. - */ -#undef shutdown - -/* A way to specify the location of the php.ini dir in an apache directive */ -char *apache2_php_ini_path_override = NULL; - -static int -php_apache_sapi_ub_write(const char *str, uint str_length) -{ - apr_bucket *b; - apr_bucket_brigade *bb; - apr_bucket_alloc_t *ba; - ap_filter_t *f; /* remaining output filters */ - php_struct *ctx; - - ctx = SG(server_context); - f = ctx->f; - - if (str_length == 0) return 0; - - ba = f->c->bucket_alloc; - bb = apr_brigade_create(ctx->r->pool, ba); - - b = apr_bucket_transient_create(str, str_length, ba); - APR_BRIGADE_INSERT_TAIL(bb, b); - - if (ap_pass_brigade(f->next, bb) != APR_SUCCESS || ctx->r->connection->aborted) { - php_handle_aborted_connection(); - } - - return str_length; /* we always consume all the data passed to us. */ -} - -static int -php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers) -{ - php_struct *ctx; - char *val, *ptr; - - ctx = SG(server_context); - - 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 (!strcasecmp(sapi_header->header, "content-length")) - ap_set_content_length(ctx->r, strtol(val, (char **)NULL, 10)); - 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; - } -} - -static int -php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers) -{ - php_struct *ctx = SG(server_context); - - ctx->r->status = SG(sapi_headers).http_response_code; - - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - -static int -php_apache_sapi_read_post(char *buf, uint count_bytes) -{ - apr_size_t len; - php_struct *ctx = SG(server_context); - apr_bucket_brigade *brigade; - apr_bucket *partition; - - brigade = ctx->post_data; - len = count_bytes; - - switch (apr_brigade_partition(ctx->post_data, count_bytes, &partition)) { - case APR_SUCCESS: - apr_brigade_flatten(ctx->post_data, buf, &len); - brigade = apr_brigade_split(ctx->post_data, partition); - apr_brigade_destroy(ctx->post_data); - ctx->post_data = brigade; - break; - case APR_INCOMPLETE: - apr_brigade_flatten(ctx->post_data, buf, &len); - apr_brigade_cleanup(ctx->post_data); - break; - } - - return len; -} -static struct stat* -php_apache_sapi_get_stat(void) -{ - php_struct *ctx = SG(server_context); - - ctx->finfo.st_uid = ctx->r->finfo.user; - ctx->finfo.st_gid = ctx->r->finfo.group; - ctx->finfo.st_dev = ctx->r->finfo.device; - ctx->finfo.st_ino = ctx->r->finfo.inode; -#ifdef NETWARE - ctx->finfo.st_atime.tv_sec = apr_time_sec(ctx->r->finfo.atime); - ctx->finfo.st_mtime.tv_sec = apr_time_sec(ctx->r->finfo.mtime); - ctx->finfo.st_ctime.tv_sec = apr_time_sec(ctx->r->finfo.ctime); -#else - ctx->finfo.st_atime = apr_time_sec(ctx->r->finfo.atime); - ctx->finfo.st_mtime = apr_time_sec(ctx->r->finfo.mtime); - ctx->finfo.st_ctime = apr_time_sec(ctx->r->finfo.ctime); -#endif - - ctx->finfo.st_size = ctx->r->finfo.size; - ctx->finfo.st_nlink = ctx->r->finfo.nlink; - - return &ctx->finfo; -} - -static char * -php_apache_sapi_read_cookies(void) -{ - php_struct *ctx = SG(server_context); - const char *http_cookie; - - http_cookie = apr_table_get(ctx->r->headers_in, "cookie"); - - /* The SAPI interface should use 'const char *' */ - return (char *) http_cookie; -} - -static char * -php_apache_sapi_getenv(char *name, size_t name_len) -{ - php_struct *ctx = SG(server_context); - const char *env_var; - - env_var = apr_table_get(ctx->r->subprocess_env, name); - - return (char *) env_var; -} - -static void -php_apache_sapi_register_variables(zval *track_vars_array) -{ - php_struct *ctx = SG(server_context); - const apr_array_header_t *arr = apr_table_elts(ctx->r->subprocess_env); - char *key, *val; - unsigned int new_val_len; - - APR_ARRAY_FOREACH_OPEN(arr, key, val) - if (!val) { - val = ""; - } - if (sapi_module.input_filter(PARSE_SERVER, key, &val, strlen(val), &new_val_len)) { - php_register_variable_safe(key, val, new_val_len, track_vars_array); - } - APR_ARRAY_FOREACH_CLOSE() - - php_register_variable("PHP_SELF", ctx->r->uri, track_vars_array); - if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &ctx->r->uri, strlen(ctx->r->uri), &new_val_len)) { - php_register_variable_safe("PHP_SELF", ctx->r->uri, new_val_len, track_vars_array); - } -} - -static void -php_apache_sapi_flush(void *server_context) -{ - php_struct *ctx; - apr_bucket_brigade *bb; - apr_bucket_alloc_t *ba; - apr_bucket *b; - ap_filter_t *f; /* output filters */ - - ctx = server_context; - - /* If we haven't registered a server_context yet, - * then don't bother flushing. */ - if (!server_context) - return; - - sapi_send_headers(); - - ctx->r->status = SG(sapi_headers).http_response_code; - SG(headers_sent) = 1; - - f = ctx->f; - - /* Send a flush bucket down the filter chain. The current default - * handler seems to act on the first flush bucket, but ignores - * all further flush buckets. - */ - - ba = ctx->r->connection->bucket_alloc; - bb = apr_brigade_create(ctx->r->pool, ba); - b = apr_bucket_flush_create(ba); - APR_BRIGADE_INSERT_TAIL(bb, b); - if (ap_pass_brigade(f->next, bb) != APR_SUCCESS || ctx->r->connection->aborted) { - php_handle_aborted_connection(); - } -} - -static void php_apache_sapi_log_message(char *msg) -{ - php_struct *ctx; - - ctx = SG(server_context); - - if (ctx == NULL) { /* we haven't initialized our ctx yet, oh well */ - ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, 0, NULL, "%s", msg); - } - else { - ap_log_error(APLOG_MARK, APLOG_ERR, 0, ctx->r->server, "%s", msg); - } -} - -static int -php_apache_disable_caching(ap_filter_t *f) -{ - /* Identify PHP scripts as non-cacheable, thus preventing - * Apache from sending a 304 status when the browser sends - * If-Modified-Since header. - */ - f->r->no_local_copy = 1; - - return OK; -} - -static double php_apache_sapi_get_request_time(void) -{ - php_struct *ctx = SG(server_context); - return ((double) apr_time_as_msec(ctx->r->request_time)) / 1000.0; -} - -extern zend_module_entry php_apache_module; - -static int php_apache2_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, &php_apache_module, 1)==FAILURE) { - return FAILURE; - } - return SUCCESS; -} - -static sapi_module_struct apache2_sapi_module = { - "apache2filter", - "Apache 2.0 Filter", - - php_apache2_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - NULL, /* activate */ - NULL, /* deactivate */ - - php_apache_sapi_ub_write, /* unbuffered write */ - php_apache_sapi_flush, /* flush */ - php_apache_sapi_get_stat, /* get uid */ - php_apache_sapi_getenv, /* getenv */ - - php_error, /* error handler */ - - php_apache_sapi_header_handler, /* header handler */ - php_apache_sapi_send_headers, /* send headers handler */ - NULL, /* send header handler */ - - php_apache_sapi_read_post, /* read POST data */ - php_apache_sapi_read_cookies, /* read Cookies */ - - 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 -}; - -static int php_input_filter(ap_filter_t *f, apr_bucket_brigade *bb, - ap_input_mode_t mode, apr_read_type_e block, apr_off_t readbytes) -{ - php_struct *ctx; - apr_status_t rv; - - if (f->r->proxyreq) { - return ap_get_brigade(f->next, bb, mode, block, readbytes); - } - - ctx = SG(server_context); - if (ctx == NULL) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r, - "php failed to get server context"); - return HTTP_INTERNAL_SERVER_ERROR; - } - - if ((rv = ap_get_brigade(f->next, bb, mode, block, readbytes)) != APR_SUCCESS) { - return rv; - } - - if (!ctx->post_data) { - ctx->post_data = apr_brigade_create(f->r->pool, f->c->bucket_alloc); - } - if ((rv = ap_save_brigade(f, &ctx->post_data, &bb, f->r->pool)) != APR_SUCCESS) { - return rv; - } - apr_brigade_cleanup(bb); - APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_eos_create(bb->bucket_alloc)); - - return APR_SUCCESS; -} - -static void php_apache_request_ctor(ap_filter_t *f, php_struct *ctx) -{ - char *content_type; - char *content_length; - const char *auth; - - PG(during_request_startup) = 0; - SG(sapi_headers).http_response_code = !f->r->status ? HTTP_OK : f->r->status; - SG(request_info).content_type = apr_table_get(f->r->headers_in, "Content-Type"); -#undef safe_strdup -#define safe_strdup(x) ((x)?strdup((x)):NULL) - SG(request_info).query_string = safe_strdup(f->r->args); - SG(request_info).request_method = f->r->method; - SG(request_info).proto_num = f->r->proto_num; - SG(request_info).request_uri = safe_strdup(f->r->uri); - SG(request_info).path_translated = safe_strdup(f->r->filename); - f->r->no_local_copy = 1; - content_type = sapi_get_default_content_type(); - f->r->content_type = apr_pstrdup(f->r->pool, content_type); - - efree(content_type); - - content_length = (char *) apr_table_get(f->r->headers_in, "Content-Length"); - SG(request_info).content_length = (content_length ? atol(content_length) : 0); - - apr_table_unset(f->r->headers_out, "Content-Length"); - apr_table_unset(f->r->headers_out, "Last-Modified"); - apr_table_unset(f->r->headers_out, "Expires"); - apr_table_unset(f->r->headers_out, "ETag"); - - auth = apr_table_get(f->r->headers_in, "Authorization"); - php_handle_auth_data(auth); - - if (SG(request_info).auth_user == NULL && f->r->user) { - SG(request_info).auth_user = estrdup(f->r->user); - } - - ctx->r->user = apr_pstrdup(ctx->r->pool, SG(request_info).auth_user); - - php_request_startup(); -} - -static void php_apache_request_dtor(ap_filter_t *f) -{ - php_apr_bucket_brigade *pbb = (php_apr_bucket_brigade *)f->ctx; - - php_request_shutdown(NULL); - - if (SG(request_info).query_string) { - free(SG(request_info).query_string); - } - if (SG(request_info).request_uri) { - free(SG(request_info).request_uri); - } - if (SG(request_info).path_translated) { - free(SG(request_info).path_translated); - } - - apr_brigade_destroy(pbb->bb); -} - -static int php_output_filter(ap_filter_t *f, apr_bucket_brigade *bb) -{ - php_struct *ctx; - void *conf = ap_get_module_config(f->r->per_dir_config, &php7_module); - char *p = get_php_config(conf, "engine", sizeof("engine")); - zend_file_handle zfd; - php_apr_bucket_brigade *pbb; - apr_bucket *b; - - if (f->r->proxyreq) { - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return ap_pass_brigade(f->next, bb); - } - - /* handle situations where user turns the engine off */ - if (*p == '0') { - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return ap_pass_brigade(f->next, bb); - } - - if(f->ctx) { - pbb = (php_apr_bucket_brigade *)f->ctx; - } else { - pbb = f->ctx = apr_palloc(f->r->pool, sizeof(*pbb)); - pbb->bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc); - } - - if(ap_save_brigade(NULL, &pbb->bb, &bb, f->r->pool) != APR_SUCCESS) { - /* Bad */ - } - - apr_brigade_cleanup(bb); - - /* 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; - } - - /* Setup the CGI variables if this is the main request.. */ - if (f->r->main == NULL || - /* .. or if the sub-request envinronment differs from the main-request. */ - f->r->subprocess_env != f->r->main->subprocess_env - ) { - /* setup standard CGI variables */ - ap_add_common_vars(f->r); - ap_add_cgi_vars(f->r); - } - - ctx = SG(server_context); - if (ctx == NULL) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r, - "php failed to get server context"); - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return HTTP_INTERNAL_SERVER_ERROR; - } - - ctx->f = f->next; /* save whatever filters are after us in the chain. */ - - if (ctx->request_processed) { - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return ap_pass_brigade(f->next, bb); - } - - apply_config(conf); - php_apache_request_ctor(f, ctx); - - /* 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 = NULL; - zfd.handle.stream.fsizer = php_apache_fsizer_stream; - zfd.handle.stream.isatty = 0; - - zfd.filename = f->r->filename; - zfd.opened_path = NULL; - zfd.free_filename = 0; - - php_execute_script(&zfd); - - apr_table_set(ctx->r->notes, "mod_php_memory_usage", - apr_psprintf(ctx->r->pool, "%lu", (unsigned long) zend_memory_peak_usage(1))); - - php_apache_request_dtor(f); - - if (!f->r->main) { - ctx->request_processed = 1; - } - - b = apr_bucket_eos_create(f->c->bucket_alloc); - APR_BRIGADE_INSERT_TAIL(pbb->bb, b); - - /* Pass whatever is left on the brigade. */ - return ap_pass_brigade(f->next, pbb->bb); -} - -static apr_status_t -php_apache_server_shutdown(void *tmp) -{ - apache2_sapi_module.shutdown(&apache2_sapi_module); - sapi_shutdown(); -#ifdef ZTS - tsrm_shutdown(); -#endif - return APR_SUCCESS; -} - -static void php_apache_add_version(apr_pool_t *p) -{ - if (PG(expose_php)) { - ap_add_version_component(p, "PHP/" PHP_VERSION); - } -} - -static int php_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp) -{ -#ifndef ZTS - int threaded_mpm; - - ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded_mpm); - if(threaded_mpm) { - ap_log_error(APLOG_MARK, APLOG_CRIT, 0, 0, "Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP."); - return DONE; - } -#endif - /* When this is NULL, apache won't override the hard-coded default - * php.ini path setting. */ - apache2_php_ini_path_override = NULL; - return OK; -} - -static int -php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, - apr_pool_t *ptemp, server_rec *s) -{ - void *data = NULL; - const char *userdata_key = "apache2filter_post_config"; - - /* Apache will load, unload and then reload a DSO module. This - * prevents us from starting PHP until the second load. */ - apr_pool_userdata_get(&data, userdata_key, s->process->pool); - if (data == NULL) { - /* We must use set() here and *not* setn(), otherwise the - * static string pointed to by userdata_key will be mapped - * to a different location when the DSO is reloaded and the - * pointers won't match, causing get() to return NULL when - * we expected it to return non-NULL. */ - apr_pool_userdata_set((const void *)1, userdata_key, - apr_pool_cleanup_null, s->process->pool); - return OK; - } - - /* Set up our overridden path. */ - if (apache2_php_ini_path_override) { - apache2_sapi_module.php_ini_path_override = apache2_php_ini_path_override; - } -#ifdef ZTS - tsrm_startup(1, 1, 0, NULL); -#endif - sapi_startup(&apache2_sapi_module); - apache2_sapi_module.startup(&apache2_sapi_module); - apr_pool_cleanup_register(pconf, NULL, php_apache_server_shutdown, apr_pool_cleanup_null); - php_apache_add_version(pconf); - - return OK; -} - -static void php_add_filter(request_rec *r, ap_filter_t *f) -{ - int output = (f == r->output_filters); - - /* for those who still have Set*Filter PHP configured */ - while (f) { - if (strcmp(f->frec->name, "PHP") == 0) { - ap_log_error(APLOG_MARK, APLOG_WARNING, - 0, r->server, - "\"Set%sFilter PHP\" already configured for %s", - output ? "Output" : "Input", r->uri); - return; - } - f = f->next; - } - - if (output) { - ap_add_output_filter("PHP", NULL, r, r->connection); - } else { - ap_add_input_filter("PHP", NULL, r, r->connection); - } -} - -static void php_insert_filter(request_rec *r) -{ - int content_type_len = strlen("application/x-httpd-php"); - - if (r->content_type && !strncmp(r->content_type, "application/x-httpd-php", content_type_len-1)) { - if (r->content_type[content_type_len] == '\0' || !strncmp(r->content_type+content_type_len, "-source", sizeof("-source"))) { - php_add_filter(r, r->output_filters); - php_add_filter(r, r->input_filters); - } - } -} - -static apr_status_t php_server_context_cleanup(void *data_) -{ - void **data = data_; - *data = NULL; - return APR_SUCCESS; -} - -static int php_post_read_request(request_rec *r) -{ - php_struct *ctx; - - /* Initialize filter context */ - SG(server_context) = ctx = apr_pcalloc(r->pool, sizeof(*ctx)); - - /* register a cleanup so we clear out the SG(server_context) - * after each request. Note: We pass in the pointer to the - * server_context in case this is handled by a different thread. */ - apr_pool_cleanup_register(r->pool, (void *)&SG(server_context), - php_server_context_cleanup, - apr_pool_cleanup_null); - - /* Save the entire request, so we can get the input or output - * filters if we need them. */ - ctx->r = r; - - return OK; -} - -static void php_register_hook(apr_pool_t *p) -{ - ap_hook_pre_config(php_pre_config, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_post_config(php_apache_server_startup, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_insert_filter(php_insert_filter, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_post_read_request(php_post_read_request, NULL, NULL, APR_HOOK_MIDDLE); - ap_register_output_filter("PHP", php_output_filter, php_apache_disable_caching, AP_FTYPE_RESOURCE); - ap_register_input_filter("PHP", php_input_filter, php_apache_disable_caching, AP_FTYPE_RESOURCE); -} - -static size_t php_apache_read_stream(void *handle, char *buf, size_t wantlen) -{ - php_apr_bucket_brigade *pbb = (php_apr_bucket_brigade *)handle; - apr_bucket_brigade *rbb; - apr_size_t readlen; - apr_bucket *b = NULL; - - rbb = pbb->bb; - - if((apr_brigade_partition(pbb->bb, wantlen, &b) == APR_SUCCESS) && b){ - pbb->bb = apr_brigade_split(rbb, b); - } - - readlen = wantlen; - apr_brigade_flatten(rbb, buf, &readlen); - apr_brigade_cleanup(rbb); - - return readlen; -} - -static size_t php_apache_fsizer_stream(void *handle) -{ - php_apr_bucket_brigade *pbb = (php_apr_bucket_brigade *)handle; - apr_off_t actual = 0; - - if (apr_brigade_length(pbb->bb, 1, &actual) == APR_SUCCESS) { - return actual; - } - - return 0; -} - -AP_MODULE_DECLARE_DATA module php7_module = { - STANDARD20_MODULE_STUFF, - create_php_config, /* create per-directory config structure */ - merge_php_config, /* merge per-directory config structures */ - NULL, /* create per-server config structure */ - NULL, /* merge per-server config structures */ - php_dir_cmds, /* command apr_table_t */ - php_register_hook /* register hooks */ -}; - -/* - * 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/apache_hooks/CREDITS b/sapi/apache_hooks/CREDITS deleted file mode 100644 index 86ac27d0b7..0000000000 --- a/sapi/apache_hooks/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Apache 1.3 (apache_hooks) -Rasmus Lerdorf, Zeev Suraski, Stig Bakken, David Sklar, George Schlossnagle, Lukas Schroeder diff --git a/sapi/apache_hooks/README b/sapi/apache_hooks/README deleted file mode 100644 index 9a5a3e2b64..0000000000 --- a/sapi/apache_hooks/README +++ /dev/null @@ -1,206 +0,0 @@ -This is very beta documentation. Clearly better stuff can and will follow. - -INTRO: - -apache_hooks is a full super-set enhancement of the apache 1.3 sapi that allows for -php code to be run on the apache request object at every stage of the apache -request. It supports all of the apache 1.3 sapi commands and configurations, and -additionally supports the following httpd.conf directives: - - -HTTPD.CONF DIRECTIEVS: - -phpRequire /path/to/file = requires a file at the beginning of an -initial apache request - -phpUriHandler /path/to/file = registers a hook that will run the -specified file at the uri translation stage of the apache request -phpUriHandler Class::Method = registers a hook to run Class::Method at -the uri translation stage of the apache request - -phpPostReadHandler /path/to/file = hook for post-read phase -phpPostReadHandlerMethod Class::Method - -phpHeaderHandler = hook for header parsing phase -phpHeaderHandlerMethod - -phpAuthHandler = hook for authentication phase -phpAuthHandlerMethod - -phpAccessHandler = hook for access control phase -phpAccessHandlerMethod - -phpTypeHandler = hook for Type Checking phase -phpTypeHandlerMethod - -phpFixupHandler = hook for 'fixup' phase -phpFixupHandlerMethod - -phpLoggerHandler = hook for logging phase -phpLoggerHandlerMethod - -AddHandler php-script = set's up a special type handler -phpResponseHandler /path/to/file = sets file to be called to handle -response phase -phpResponseHandlerMethod Class::Method - - -All handlers may be stacked, i.e. you can list multiple handler directives -in a single scope and they will be run in order. - - -EXAMPLES: - -So, to set up a 'hello world' location handler (so that any request to -/hello/* returns hello world) you can: - -phpRequire /tmp/setup.php -<Location /hello> -AddHandler php-script -phpResponseHandlerMethod Hello::World -</Location> - -with -#/tmp/setup.php -<? -class Hello { - function World() { - global $request; - $request->send_http_header(); - echo "Hello World"; - } -} -?> - -$request is the apache request. It is instantiated at all stages -automatically. The methods of that class are: - -getallheaders -args -boundary -content_encoding -content_type -filename -handler -hostname -method -path_info -protocol -status_line -the_request -unparsed_uri -uri -allowed -bytes_sent -chunked -content_length -header_only -method_number -mtime -no_cache -no_local_copy -proto_num -proxyreq -read_body -remaining -request_time -status -headers_in -headers_out -err_headers_out -auth_name -auth_type -basic_auth_pw -discard_request_body -is_initial_req -meets_conditions -remote_host -satisfies -server_port -set_etag -set_last_modified -some_auth_required -update_mtime -send_http_header -basic_http_header -send_header_field -send_http_trace -send_http_options -send_error_response -set_content_length -set_keepalive -rputs -log_error -lookup_uri -lookup_file -method_uri -run -internal_redirect - - -These all wrap the ap_* apache EXPORT_API functions using the same -semantics (and are also the same as the Apache::Request methods in -mod_perl if you are familiar with that) - -So, a uri handler to redirect all non-local traffic to /404.php (an -error page) would be - -phpUriHandler /tmp/uri.php - -#/tmp/uri.php -<? - if($REMOTE_ADDR != '127.0.0.1') { - $request->uri('/404.php'); - } - return OK; -?> - -It's important to note that since this is called from the uri -translations phase, this validation is performed for every request to -the server, not just for php pages. - -Also, scope is shared between all the hooks. So in the above, we could -merge the two and do something like: - -#/tmp/uri.php -<? - if($REMOTE_ADDR != '127.0.0.1') { - $whoami = 'Stranger'; - } - else { - $whoami = 'Friend'; - } - return DECLINED; # because we're not redirecting, just messing around -?> - -and then: - -#/tmp/setup.php -<? -class Hello { - function World() { - global $request; - global $whoami; - $request->send_http_header(); - echo "Hello $whoami"; - } -} -?> - -These variables are also in the same scope as a script if your script is -being handled by the standard application/x-httpd-php handler. - -This allows you to make decisions and pass data between your handlers -and scripts at all stages. - -The above are clearly trite examples, but hopefully give you a starting -point. - -One note: all handlers can be validly re-entered 'in sub-requests'. -For this reason you should not define functions/classes here without -anti-redefinition guards (I would just recommend putting them in an -include and using include_one). This is not true for phpRequire, which -is only entered once, at the main request, and so it is safe to make -function/class declarations there (in fact that's what it's for). - -Hope that helps! diff --git a/sapi/apache_hooks/apMakefile.libdir b/sapi/apache_hooks/apMakefile.libdir deleted file mode 100644 index 7b5254013a..0000000000 --- a/sapi/apache_hooks/apMakefile.libdir +++ /dev/null @@ -1,4 +0,0 @@ -This is a place-holder which indicates to Configure that it shouldn't -provide the default targets when building the Makefile in this directory. -Instead it'll just prepend all the important variable definitions, and -copy the Makefile.tmpl onto the end. diff --git a/sapi/apache_hooks/apMakefile.tmpl b/sapi/apache_hooks/apMakefile.tmpl deleted file mode 100644 index 1e5e465f65..0000000000 --- a/sapi/apache_hooks/apMakefile.tmpl +++ /dev/null @@ -1,77 +0,0 @@ -## -## Apache 1.3 Makefile template for PHP 4.0 Module -## [src/modules/php7/Makefile.tmpl] -## - -# the parametrized target -LIB=libphp7.$(LIBEXT) - -# objects for building the static library -OBJS=mod_php7.o -OBJS_LIB=libmodphp7.a - -# objects for building the shared object library -SHLIB_OBJS=mod_php7.so-o -SHLIB_OBJS_LIB=libmodphp7.a - -# the general targets -all: lib -lib: $(LIB) - -# build the static library by merging the object files -libphp7.a: $(OBJS) $(OBJS_LIB) - cp $(OBJS_LIB) $@ - ar r $@ $(OBJS) - $(RANLIB) $@ - -# ugly hack to support older Apache-1.3 betas that don't set $LIBEXT -libphp7.: $(OBJS) $(OBJS_LIB) - cp $(OBJS_LIB) $@ - ar r $@ $(OBJS) - $(RANLIB) $@ - cp libphp7. libphp7.a - -# build the shared object library by linking the object files -libphp7.so: $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) - rm -f $@ - $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) $(LIBS) $(PHP_LIBS) - -# 1. extension .o for shared objects cannot be used here because -# first these files aren't still shared objects and second we -# have to use a different name to trigger the different -# implicit Make rule -# 2. extension -so.o (as used elsewhere) cannot be used because -# the suffix feature of Make really wants just .x, so we use -# extension .so-o -.SUFFIXES: .o .so-o -.c.o: - $(CC) -c $(INCLUDES) $(CFLAGS) $(PHP_CFLAGS) $(CPPFLAGS) $(SPACER) $< -.c.so-o: - $(CC) -c $(INCLUDES) $(CFLAGS) $(CFLAGS_SHLIB) $(PHP_CFLAGS) $(CPPFLAGS) $(SPACER) $< && mv $*.o $*.so-o - -# cleanup -clean: - -rm -f $(OBJS) $(SHLIB_OBJS) $(LIB) - -# We really don't expect end users to use this rule. It works only with -# gcc, and rebuilds Makefile.tmpl. You have to re-run Configure after -# using it. -depend: - cp Makefile.tmpl Makefile.tmpl.bak \ - && sed -ne '1,/^# DO NOT REMOVE/p' Makefile.tmpl > Makefile.new \ - && gcc -MM $(INCLUDES) $(CFLAGS) $(PHP_CFLAGS) $(CPPFLAGS) *.c >> Makefile.new \ - && sed -e '1,$$s: $(INCDIR)/: $$(INCDIR)/:g' Makefile.new \ - > Makefile.tmpl \ - && rm Makefile.new - -#Dependencies - -$(OBJS): Makefile - -# DO NOT REMOVE -mod_php7.o: mod_php7.c $(INCDIR)/httpd.h $(INCDIR)/conf.h \ - $(INCDIR)/buff.h \ - $(INCDIR)/http_config.h \ - $(INCDIR)/http_core.h $(INCDIR)/http_main.h \ - $(INCDIR)/http_protocol.h $(INCDIR)/http_request.h \ - $(INCDIR)/http_log.h $(INCDIR)/util_script.h mod_php7.h diff --git a/sapi/apache_hooks/config.m4 b/sapi/apache_hooks/config.m4 deleted file mode 100644 index a1ee213492..0000000000 --- a/sapi/apache_hooks/config.m4 +++ /dev/null @@ -1,275 +0,0 @@ -dnl -dnl $Id$ -dnl -AC_DEFUN([PHP_APACHE_FD_CHECK], [ -AC_CACHE_CHECK([for member fd in BUFF *],ac_cv_php_fd_in_buff,[ - save=$CPPFLAGS - if test -n "$APXS_INCLUDEDIR"; then - CPPFLAGS="$CPPFLAGS -I$APXS_INCLUDEDIR" - else - CPPFLAGS="$CPPFLAGS $APACHE_INCLUDE" - fi - AC_TRY_COMPILE([#include <httpd.h>],[conn_rec *c; int fd = c->client->fd;],[ - ac_cv_php_fd_in_buff=yes],[ac_cv_php_fd_in_buff=no],[ac_cv_php_fd_in_buff=no]) - CPPFLAGS=$save -]) -if test "$ac_cv_php_fd_in_buff" = "yes"; then - AC_DEFINE(PHP_APACHE_HAVE_CLIENT_FD,1,[ ]) -fi -]) - -dnl Apache 1.x shared module -PHP_ARG_WITH(apache-hooks,, -[ --with-apache-hooks[=FILE] - EXPERIMENTAL: Build shared Apache 1.x module. FILE is the optional - pathname to the Apache apxs tool [apxs]], no, no) - -AC_MSG_CHECKING([for Apache 1.x (hooks) module support via DSO through APXS]) - -if test "$PHP_APACHE_HOOKS" != "no"; then - if test "$PHP_APACHE_HOOKS" = "yes"; then - APXS=apxs - $APXS -q CFLAGS >/dev/null 2>&1 - if test "$?" != "0" && test -x /usr/sbin/apxs; then #SUSE 6.x - APXS=/usr/sbin/apxs - fi - else - PHP_EXPAND_PATH($PHP_APACHE_HOOKS, APXS) - fi - - $APXS -q CFLAGS >/dev/null 2>&1 - if test "$?" != "0"; then - AC_MSG_RESULT() - AC_MSG_RESULT() - AC_MSG_RESULT([Sorry, I was not able to successfully run APXS. Possible reasons:]) - AC_MSG_RESULT() - AC_MSG_RESULT([1. Perl is not installed;]) - AC_MSG_RESULT([2. Apache was not compiled with DSO support (--enable-module=so);]) - AC_MSG_RESULT([3. 'apxs' is not in your path. Try to use --with-apxs=/path/to/apxs]) - AC_MSG_RESULT([The output of $APXS follows]) - $APXS -q CFLAGS - AC_MSG_ERROR([Aborting]) - fi - - APXS_LDFLAGS="@SYBASE_LFLAGS@ @SYBASE_LIBS@ @SYBASE_CT_LFLAGS@ @SYBASE_CT_LIBS@" - APXS_INCLUDEDIR=`$APXS -q INCLUDEDIR` - APXS_CFLAGS=`$APXS -q CFLAGS` - APXS_HTTPD=`$APXS -q SBINDIR`/`$APXS -q TARGET` - APACHE_INCLUDE=-I$APXS_INCLUDEDIR - - # Test that we're trying to configure with apache 1.x - PHP_AP_EXTRACT_VERSION($APXS_HTTPD) - if test "$APACHE_VERSION" -ge 2000000; then - AC_MSG_ERROR([You have enabled Apache 1.3 support while your server is Apache 2. Please use the appropriate switch --with-apxs2]) - fi - - for flag in $APXS_CFLAGS; do - case $flag in - -D*) APACHE_CPPFLAGS="$APACHE_CPPFLAGS $flag";; - esac - done - - case $host_alias in - *aix*) - APXS_LIBEXECDIR=`$APXS -q LIBEXECDIR` - EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-brtl -Wl,-bI:$APXS_LIBEXECDIR/httpd.exp" - PHP_AIX_LDFLAGS="-Wl,-brtl" - build_type=shared - ;; - *darwin*) - MH_BUNDLE_FLAGS="-dynamic -twolevel_namespace -bundle -bundle_loader $APXS_HTTPD" - PHP_SUBST(MH_BUNDLE_FLAGS) - SAPI_SHARED=libs/libphp7.so - build_type=bundle - ;; - *) - build_type=shared - ;; - esac - - PHP_SELECT_SAPI(apache_hooks, $build_type, sapi_apache.c mod_php7.c php_apache.c, $APACHE_CPPFLAGS -I$APXS_INCLUDEDIR) - - # Test whether apxs support -S option - $APXS -q -S CFLAGS="$APXS_CFLAGS" CFLAGS >/dev/null 2>&1 - - if test "$?" != "0"; then - APACHE_HOOKS_INSTALL="$APXS -i -a -n php7 $SAPI_SHARED" # Old apxs does not have -S option - else - APXS_LIBEXECDIR='$(INSTALL_ROOT)'`$APXS -q LIBEXECDIR` - if test -z `$APXS -q SYSCONFDIR`; then - APACHE_HOOKS_INSTALL="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ - $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ - -i -n php7 $SAPI_SHARED" - else - APXS_SYSCONFDIR='$(INSTALL_ROOT)'`$APXS -q SYSCONFDIR` - APACHE_HOOKS_INSTALL="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ - \$(mkinstalldirs) '$APXS_SYSCONFDIR' && \ - $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ - -S SYSCONFDIR='$APXS_SYSCONFDIR' \ - -i -a -n php7 $SAPI_SHARED" - fi - fi - - if test -z "`$APXS -q LD_SHLIB`" || test "`$APXS -q LIBEXECDIR`" = "modules"; then - PHP_APXS_BROKEN=yes - fi - STRONGHOLD= - AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ]) - AC_DEFINE(HAVE_AP_COMPAT_H,1,[ ]) - AC_DEFINE(HAVE_APACHE_HOOKS,1,[ ]) - AC_MSG_RESULT(yes) -else - AC_MSG_RESULT(no) -fi - -dnl Apache 1.x static module -PHP_ARG_WITH(apache-hooks-static,, -[ --with-apache-hooks-static[=DIR] - EXPERIMENTAL: Build Apache 1.x module. DIR is the top-level Apache - build directory [/usr/local/apache]], no, no) - -AC_MSG_CHECKING(for Apache 1.x (hooks) module support) - -if test "$PHP_SAPI" != "apache" && test "$PHP_SAPI" != "apache_hooks" && test "$PHP_APACHE_HOOKS_STATIC" != "no"; then - - if test "$PHP_APACHE_HOOKS_STATIC" = "yes"; then - # Apache's default directory - PHP_APACHE_HOOKS_STATIC=/usr/local/apache - fi - - APACHE_HOOKS_INSTALL_FILES="\$(srcdir)/sapi/apache_hooks/mod_php7.* sapi/apache_hooks/libphp7.module" - - AC_DEFINE(HAVE_APACHE,1,[ ]) - APACHE_HOOKS_MODULE=yes - PHP_EXPAND_PATH($PHP_APACHE_HOOKS_STATIC, PHP_APACHE_HOOKS_STATIC) - # For Apache 1.2.x - if test -f $PHP_APACHE_HOOKS_STATIC/src/httpd.h; then - APACHE_INCLUDE=-I$PHP_APACHE_HOOKS_STATIC/src - APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/src - PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) - APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET" - PHP_LIBS="-L. -lphp3" - AC_MSG_RESULT([yes - Apache 1.2.x]) - STRONGHOLD= - if test -f $PHP_APACHE_HOOKS_STATIC/src/ap_config.h; then - AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ]) - fi - # For Apache 2.0.x - elif test -f $PHP_APACHE_HOOKS_STATIC/include/httpd.h && test -f $PHP_APACHE_HOOKS_STATIC/srclib/apr/include/apr_general.h ; then - AC_MSG_ERROR([Use --with-apxs2 with Apache 2.x!]) - # For Apache 1.3.x - elif test -f $PHP_APACHE_HOOKS_STATIC/src/main/httpd.h; then - APACHE_HAS_REGEX=1 - APACHE_INCLUDE="-I$PHP_APACHE_HOOKS_STATIC/src/main -I$PHP_APACHE_HOOKS_STATIC/src/os/unix -I$PHP_APACHE_HOOKS_STATIC/src/ap" - APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/src/modules/php7 - if test ! -d $APACHE_TARGET; then - mkdir $APACHE_TARGET - fi - PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) - APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp7.a; cp $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache_hooks/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/sapi/apache_hooks/apMakefile.libdir $APACHE_TARGET/Makefile.libdir" - PHP_LIBS="-Lmodules/php7 -L../modules/php7 -L../../modules/php7 -lmodphp7" - AC_MSG_RESULT([yes - Apache 1.3.x]) - STRONGHOLD= - if test -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config.h; then - AC_DEFINE(HAVE_AP_CONFIG_H, 1, [ ]) - fi - if test -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_compat.h; then - AC_DEFINE(HAVE_AP_COMPAT_H, 1, [ ]) - if test ! -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config_auto.h; then - AC_MSG_ERROR([Please run Apache\'s configure or src/Configure program once and try again]) - fi - elif test -f $PHP_APACHE_HOOKS_STATIC/src/include/compat.h; then - AC_DEFINE(HAVE_OLD_COMPAT_H, 1, [ ]) - fi - # Also for Apache 1.3.x - elif test -f $PHP_APACHE_HOOKS_STATIC/src/include/httpd.h; then - APACHE_HAS_REGEX=1 - APACHE_INCLUDE="-I$PHP_APACHE_HOOKS_STATIC/src/include -I$PHP_APACHE_HOOKS_STATIC/src/os/unix" - APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/src/modules/php7 - if test ! -d $APACHE_TARGET; then - mkdir $APACHE_TARGET - fi - PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) - PHP_LIBS="-Lmodules/php7 -L../modules/php7 -L../../modules/php7 -lmodphp7" - APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp7.a; cp $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache_hooks/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/sapi/apache_hooks/apMakefile.libdir $APACHE_TARGET/Makefile.libdir" - AC_MSG_RESULT([yes - Apache 1.3.x]) - STRONGHOLD= - if test -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config.h; then - AC_DEFINE(HAVE_AP_CONFIG_H, 1, [ ]) - fi - if test -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_compat.h; then - AC_DEFINE(HAVE_AP_COMPAT_H, 1, [ ]) - if test ! -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config_auto.h; then - AC_MSG_ERROR([Please run Apache\'s configure or src/Configure program once and try again]) - fi - elif test -f $PHP_APACHE_HOOKS_STATIC/src/include/compat.h; then - AC_DEFINE(HAVE_OLD_COMPAT_H, 1, [ ]) - fi - # For StrongHold 2.2 - elif test -f $PHP_APACHE_HOOKS_STATIC/apache/httpd.h; then - APACHE_INCLUDE="-I$PHP_APACHE_HOOKS_STATIC/apache -I$PHP_APACHE_HOOKS_STATIC/ssl/include" - APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/apache - PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) - PHP_LIBS="-Lmodules/php7 -L../modules/php7 -L../../modules/php7 -lmodphp7" - APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp7.a; cp $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET" - STRONGHOLD=-DSTRONGHOLD=1 - AC_MSG_RESULT([yes - StrongHold]) - if test -f $PHP_APACHE_HOOKS_STATIC/apache/ap_config.h; then - AC_DEFINE(HAVE_AP_CONFIG_H, 1, [ ]) - fi - if test -f $PHP_APACHE_HOOKS_STATIC/src/ap_compat.h; then - AC_DEFINE(HAVE_AP_COMPAT_H, 1, [ ]) - if test ! -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config_auto.h; then - AC_MSG_ERROR([Please run Apache\'s configure or src/Configure program once and try again]) - fi - elif test -f $PHP_APACHE_HOOKS_STATIC/src/compat.h; then - AC_DEFINE(HAVE_OLD_COMPAT_H, 1, [ ]) - fi - else - AC_MSG_RESULT(no) - AC_MSG_ERROR([Invalid Apache directory - unable to find httpd.h under $PHP_APACHE_HOOKS_STATIC]) - fi -else - AC_MSG_RESULT(no) -fi - -# compatibility -if test -z "$enable_mod_charset" && test "$with_mod_charset"; then - enable_mod_charset=$with_mod_charset -fi - -PHP_ARG_ENABLE(mod-charset, whether to enable Apache charset compatibility option, -[ --enable-mod-charset APACHE (hooks): Enable transfer tables for mod_charset (Rus Apache)], no, no) - -if test "$PHP_MOD_CHARSET" = "yes"; then - AC_DEFINE(USE_TRANSFER_TABLES, 1, [ ]) -fi - -dnl Build as static module -if test "$APACHE_HOOKS_MODULE" = "yes"; then - PHP_TARGET_RDYNAMIC - $php_shtool mkdir -p sapi/apache_hooks - PHP_OUTPUT(sapi/apache_hooks/libphp7.module) -fi - -dnl General -if test -n "$APACHE_HOOKS_INSTALL"; then - if test "x$APXS" != "x" -a "`uname -sv`" = "AIX 4" -a "$GCC" != "yes"; then - APXS_EXP=-bE:sapi/apache_hooks/mod_php7.exp - fi - - PHP_APACHE_FD_CHECK - INSTALL_IT=$APACHE_HOOKS_INSTALL - - PHP_SUBST(APXS_EXP) - PHP_SUBST(APACHE_INCLUDE) - PHP_SUBST(APACHE_TARGET) - PHP_SUBST(APXS) - PHP_SUBST(APXS_LDFLAGS) - PHP_SUBST(APACHE_HOOKS_INSTALL) - PHP_SUBST(STRONGHOLD) -fi - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/apache_hooks/config.w32 b/sapi/apache_hooks/config.w32 deleted file mode 100644 index 1c9129e615..0000000000 --- a/sapi/apache_hooks/config.w32 +++ /dev/null @@ -1,21 +0,0 @@ -// vim:ft=javascript -// $Id$ - -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_PHP_BUILD + "\\apache\\src\\include") && - CHECK_LIB("ApacheCore.lib", "apache_hooks", php_usual_lib_suspects + - ';' + PROGRAM_FILES + '\\Apache Group\\Apache\\libexec' + - ";" + PHP_PHP_BUILD + "\\apache\\src\\corer")) { - // We need to play tricks to get our readdir.h used by apache - // headers - SAPI('apache_hooks', 'mod_php7.c sapi_apache.c php_apache.c', - 'php' + PHP_VERSION + 'apache_hooks.dll', - '/D APACHEPHP7_EXPORTS /D APACHE_READDIR_H /I win32'); - } else { - WARNING("Could not find apache libraries/headers"); - } -} diff --git a/sapi/apache_hooks/libphp7.module.in b/sapi/apache_hooks/libphp7.module.in deleted file mode 100644 index 5bea79ef95..0000000000 --- a/sapi/apache_hooks/libphp7.module.in +++ /dev/null @@ -1,11 +0,0 @@ -Name: php7_module -ConfigStart - RULE_WANTHSREGEX=no - RULE_HIDE=yes - PHP_LIBS="@NATIVE_RPATHS@ @PHP_LDFLAGS@ @PHP_LIBS@ @EXTRA_LIBS@ $LIBS" - PHP_CFLAGS="$CFLAGS @OPENSSL_INCDIR_OPT@ -I@php_abs_top_builddir@/main -I@php_abs_top_builddir@/Zend -I@php_abs_top_builddir@/TSRM -I@php_abs_top_srcdir@ -I@php_abs_top_srcdir@/sapi/apache -I@php_abs_top_srcdir@/main -I@php_abs_top_srcdir@/Zend -I@php_abs_top_srcdir@/TSRM" - my_outfile="Makefile.config" - echo "PHP_CFLAGS=$PHP_CFLAGS" >>$my_outfile - echo "PHP_LIBS=$PHP_LIBS" >>$my_outfile - LIBS=$PHP_LIBS -ConfigEnd diff --git a/sapi/apache_hooks/mod_php7.c b/sapi/apache_hooks/mod_php7.c deleted file mode 100644 index 6eb15f3ef8..0000000000 --- a/sapi/apache_hooks/mod_php7.c +++ /dev/null @@ -1,1478 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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 | - | 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. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | (with helpful hints from Dean Gaudet <dgaudet@arctic.org> | - | PHP 4.0 patches by Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php_apache_http.h" - -#ifdef NETWARE -#define SIGPIPE SIGINT -#endif - -#undef shutdown - -/* {{{ Prototypes - */ -int apache_php_module_main(request_rec *r, int display_source_mode); -static void php_save_umask(void); -static void php_restore_umask(void); -static int sapi_apache_read_post(char *buffer, uint count_bytes); -static char *sapi_apache_read_cookies(void); -static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers); -static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers); -static int send_php(request_rec *r, int display_source_mode, char *filename); -static int send_parsed_php(request_rec * r); -static int send_parsed_php_source(request_rec * r); -static int php_xbithack_handler(request_rec * r); -static void php_init_handler(server_rec *s, pool *p); -/* }}} */ - -#if MODULE_MAGIC_NUMBER >= 19970728 -static void php_child_exit_handler(server_rec *s, pool *p); -#endif - -#if MODULE_MAGIC_NUMBER > 19961007 -#define CONST_PREFIX const -#else -#define CONST_PREFIX -#endif - - -typedef struct _sapi_stack { - int top, max, persistent; - void **elements; -} sapi_stack; - -typedef struct _php_per_dir_config { - HashTable *ini_settings; - sapi_stack headers_handlers; - sapi_stack auth_handlers; - sapi_stack access_handlers; - sapi_stack type_handlers; - sapi_stack fixup_handlers; - sapi_stack logger_handlers; - sapi_stack post_read_handlers; - sapi_stack response_handlers; -} php_per_dir_config; - -typedef struct _php_per_server_config { - sapi_stack uri_handlers; - sapi_stack requires; -} php_per_server_config; - - -static CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode); -static CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2); -static CONST_PREFIX char *php_apache_admin_value_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2); -static CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2); -static CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode); -static CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2); - -/* ### these should be defined in mod_php7.h or somewhere else */ -#define USE_PATH 1 -#define IGNORE_URL 2 - -module MODULE_VAR_EXPORT php7_module; - -int saved_umask; -/* static int setup_env = 0; */ -static unsigned char apache_php_initialized; - -typedef struct _php_per_dir_entry { - char *key; - char *value; - uint key_length; - uint value_length; - int type; -} php_per_dir_entry; - -/* some systems are missing these from their header files */ - -/* {{{ zend stack utility functions - */ - -/* This code is ripped part and parcel from zend_stack.[ch]. Assuming that the - patch supporting zend_stack_init_ex is applied, all but the bottom two - module-specific iterators will be removed - */ - -int sapi_stack_init_ex(sapi_stack *stack, int persistent) -{ - stack->top = 0; - stack->persistent = persistent; - stack->elements = (void **) pemalloc(sizeof(void **) * STACK_BLOCK_SIZE, persistent); - if (!stack->elements) { - return FAILURE; - } else { - stack->max = STACK_BLOCK_SIZE; - return SUCCESS; - } -} -int sapi_stack_push(sapi_stack *stack, void *element) -{ - if (stack->top >= stack->max) { /* we need to allocate more memory */ - stack->elements = (void **) perealloc(stack->elements, - (sizeof(void **) * (stack->max += STACK_BLOCK_SIZE)), stack->persistent); - if (!stack->elements) { - return FAILURE; - } - } - stack->elements[stack->top] = (void *) element; - return stack->top++; -} -void* sapi_stack_pop(sapi_stack *stack) { - if(stack->top == 0) { - return NULL; - } - else { - return stack->elements[--stack->top]; - } -} - -int sapi_stack_destroy(sapi_stack *stack) -{ - return SUCCESS; -} - -int sapi_stack_apply_with_argument_all(sapi_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg) -{ - int i, retval; - - switch (type) { - case ZEND_STACK_APPLY_TOPDOWN: - for (i=stack->top-1; i>=0; i--) { - retval = apply_function(stack->elements[i], arg); - } - break; - case ZEND_STACK_APPLY_BOTTOMUP: - for (i=0; i<stack->top; i++) { - retval = apply_function(stack->elements[i], arg); - } - break; - } - return retval; -} - - -int sapi_stack_apply_with_argument_stop_if_equals(sapi_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg, int stopval) -{ - int i; - int ret = DECLINED; - switch (type) { - case ZEND_STACK_APPLY_TOPDOWN: - for (i=stack->top-1; i>=0; i--) { - if ((ret = apply_function(stack->elements[i], arg)) == stopval) { - break; - } - } - break; - case ZEND_STACK_APPLY_BOTTOMUP: - for (i=0; i<stack->top; i++) { - if ((ret = apply_function(stack->elements[i], arg)) == stopval) { - break; - } - } - break; - } - return ret; -} - -int sapi_stack_apply_with_argument_stop_if_http_error(sapi_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg) -{ - int i; - int ret = DECLINED; - switch (type) { - case ZEND_STACK_APPLY_TOPDOWN: - for (i=stack->top-1; i>=0; i--) { - if ((ret = apply_function(stack->elements[i], arg)) > 0) { - break; - } - } - break; - case ZEND_STACK_APPLY_BOTTOMUP: - for (i=0; i<stack->top; i++) { - if ((ret = apply_function(stack->elements[i], arg)) > 0) { - break; - } - } - break; - } - return ret; -} - -void php_handler_stack_destroy(sapi_stack *stack) -{ - php_handler *ph; - while((ph = (php_handler *)sapi_stack_pop(stack)) != NULL) { - free(ph->name); - free(ph); - } -} -/* }}} */ - -/* {{{ php_save_umask - */ -static void php_save_umask(void) -{ - saved_umask = umask(077); - umask(saved_umask); -} -/* }}} */ - -/* {{{ sapi_apache_ub_write - */ -static int sapi_apache_ub_write(const char *str, uint str_length) -{ - int ret=0; - - if (SG(server_context)) { - ret = rwrite(str, str_length, (request_rec *) SG(server_context)); - } - if (ret != str_length) { - php_handle_aborted_connection(); - } - return ret; -} -/* }}} */ - -/* {{{ sapi_apache_flush - */ -static void sapi_apache_flush(void *server_context) -{ - if (server_context) { -#if MODULE_MAGIC_NUMBER > 19970110 - rflush((request_rec *) server_context); -#else - bflush((request_rec *) server_context->connection->client); -#endif - } -} -/* }}} */ - -/* {{{ sapi_apache_read_post - */ -static int sapi_apache_read_post(char *buffer, uint count_bytes) -{ - uint total_read_bytes=0, read_bytes; - request_rec *r = (request_rec *) SG(server_context); - void (*handler)(int); - - /* - * This handles the situation where the browser sends a Expect: 100-continue header - * and needs to receive confirmation from the server on whether or not it can send - * the rest of the request. RFC 2616 - * - */ - if (!SG(read_post_bytes) && !ap_should_client_block(r)) { - return total_read_bytes; - } - - handler = signal(SIGPIPE, SIG_IGN); - while (total_read_bytes<count_bytes) { - hard_timeout("Read POST information", r); /* start timeout timer */ - read_bytes = get_client_block(r, buffer+total_read_bytes, count_bytes-total_read_bytes); - reset_timeout(r); - if (read_bytes<=0) { - break; - } - total_read_bytes += read_bytes; - } - signal(SIGPIPE, handler); - return total_read_bytes; -} -/* }}} */ - -/* {{{ sapi_apache_read_cookies - */ -static char *sapi_apache_read_cookies(void) -{ - return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, "HTTP_COOKIE"); -} -/* }}} */ - -/* {{{ sapi_apache_header_handler - */ -static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers) -{ - char *header_name, *header_content, *p; - request_rec *r = (request_rec *) SG(server_context); - if(!r) { - return 0; - } - - switch(op) { - case SAPI_HEADER_DELETE_ALL: - clear_table(r->headers_out); - return 0; - - 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 */ - - return SAPI_HEADER_ADD; - - default: - return 0; - } -} -/* }}} */ - -/* {{{ sapi_apache_send_headers - */ -static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers) -{ - if(SG(server_context) == NULL) { /* server_context is not here anymore */ - return SAPI_HEADER_SEND_FAILED; - } - - ((request_rec *) SG(server_context))->status = SG(sapi_headers).http_response_code; - /* check that we haven't sent headers already, we use our own - * headers_sent since we may send headers at anytime - */ - if(!AP(headers_sent)) { - send_http_header((request_rec *) SG(server_context)); - AP(headers_sent) = 1; - } - return SAPI_HEADER_SENT_SUCCESSFULLY; -} -/* }}} */ - -/* {{{ sapi_apache_register_server_variables - */ -static void sapi_apache_register_server_variables(zval *track_vars_array) -{ - register int i; - array_header *arr = table_elts(((request_rec *) SG(server_context))->subprocess_env); - table_entry *elts = (table_entry *) arr->elts; - zval **path_translated; - HashTable *symbol_table; - - for (i = 0; i < arr->nelts; i++) { - char *val; - - if (elts[i].val) { - val = elts[i].val; - } else { - val = ""; - } - php_register_variable(elts[i].key, val, track_vars_array ); - } - - /* If PATH_TRANSLATED doesn't exist, copy it from SCRIPT_FILENAME */ - if (track_vars_array) { - symbol_table = track_vars_array->value.ht; - } else { - symbol_table = NULL; - } - if (symbol_table - && !zend_hash_exists(symbol_table, "PATH_TRANSLATED", sizeof("PATH_TRANSLATED")) - && zend_hash_find(symbol_table, "SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME"), (void **) &path_translated)==SUCCESS) { - php_register_variable("PATH_TRANSLATED", Z_STRVAL_PP(path_translated), track_vars_array); - } - - php_register_variable("PHP_SELF", ((request_rec *) SG(server_context))->uri, track_vars_array); -} -/* }}} */ - -/* {{{ php_apache_startup - */ -static int php_apache_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, &apache_module_entry, 1) == FAILURE) { - return FAILURE; - } else { - return SUCCESS; - } -} -/* }}} */ - -/* {{{ php_apache_log_message - */ -static void php_apache_log_message(char *message) -{ - if (SG(server_context)) { -#if MODULE_MAGIC_NUMBER >= 19970831 - aplog_error(NULL, 0, APLOG_ERR | APLOG_NOERRNO, ((request_rec *) SG(server_context))->server, "%s", message); -#else - log_error(message, ((request_rec *) SG(server_context))->server); -#endif - } else { - fprintf(stderr, "%s", message); - fprintf(stderr, "\n"); - } -} -/* }}} */ - -/* {{{ php_apache_request_shutdown - */ -static void php_apache_request_shutdown(void *dummy) -{ - AP(current_hook) = AP_CLEANUP; - php_output_set_status(PHP_OUTPUT_DISABLED); - SG(server_context) = NULL; /* The server context (request) is invalid by the time run_cleanups() is called */ - if(SG(sapi_started)) { - php_request_shutdown(dummy); - SG(sapi_started) = 0; - } - AP(in_request) = 0; - if(AP(setup_env)) { - AP(setup_env) = 0; - } - AP(current_hook) = AP_WAITING_FOR_REQUEST; - AP(headers_sent) = 0; -} -/* }}} */ - -/* {{{ php_apache_sapi_activate - */ -static int php_apache_sapi_activate(void) -{ - request_rec *r = (request_rec *) SG(server_context); - - /* - * For the Apache module version, this bit of code registers a cleanup - * function that gets triggered when our request pool is destroyed. - * We need this because at any point in our code we can be interrupted - * and that may happen before we have had time to free our memory. - * The php_request_shutdown function needs to free all outstanding allocated - * memory. - */ - block_alarms(); - register_cleanup(r->pool, NULL, php_apache_request_shutdown, php_request_shutdown_for_exec); - AP(in_request)=1; - unblock_alarms(); - - /* Override the default headers_only value - sometimes "GET" requests should actually only - * send headers. - */ - SG(request_info).headers_only = r->header_only; - return SUCCESS; -} -/* }}} */ - -/* {{{ php_apache_get_stat - */ -static struct stat *php_apache_get_stat(void) -{ - return &((request_rec *) SG(server_context))->finfo; -} -/* }}} */ - -/* {{{ php_apache_getenv - */ -static char *php_apache_getenv(char *name, size_t name_len) -{ - return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, name); -} -/* }}} */ - -/* {{{ sapi_module_struct apache_sapi_module - */ -static sapi_module_struct apache_sapi_module = { - "apache", /* name */ - "Apache", /* pretty name */ - - php_apache_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - php_apache_sapi_activate, /* activate */ - NULL, /* deactivate */ - - sapi_apache_ub_write, /* unbuffered write */ - sapi_apache_flush, /* flush */ - php_apache_get_stat, /* get uid */ - php_apache_getenv, /* getenv */ - - php_error, /* error handler */ - - sapi_apache_header_handler, /* header handler */ - sapi_apache_send_headers, /* send headers handler */ - NULL, /* send header handler */ - - sapi_apache_read_post, /* read POST data */ - sapi_apache_read_cookies, /* read Cookies */ - - 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 */ - -#ifdef PHP_WIN32 - NULL, - NULL, -#else - block_alarms, /* Block interruptions */ - unblock_alarms, /* Unblock interruptions */ -#endif - - NULL, /* default post reader */ - NULL, /* treat data */ - NULL, /* exe location */ - 0, /* ini ignore */ - NULL - -}; -/* }}} */ - -/* {{{ php_restore_umask - */ -static void php_restore_umask(void) -{ - umask(saved_umask); -} -/* }}} */ - -/* {{{ init_request_info - */ -static void init_request_info(void) -{ - request_rec *r = ((request_rec *) SG(server_context)); - char *content_length = (char *) table_get(r->subprocess_env, "CONTENT_LENGTH"); - const char *authorization=NULL; - char *tmp, *tmp_user; - - SG(request_info).query_string = r->args; - SG(request_info).path_translated = r->filename; - SG(request_info).request_uri = r->uri; - SG(request_info).request_method = (char *)r->method; - SG(request_info).proto_num = r->proto_num; - SG(request_info).content_type = (char *) table_get(r->subprocess_env, "CONTENT_TYPE"); - SG(request_info).content_length = (content_length ? atol(content_length) : 0); - SG(sapi_headers).http_response_code = r->status; - - if (r->headers_in) { - authorization = table_get(r->headers_in, "Authorization"); - } - - SG(request_info).auth_user = NULL; - SG(request_info).auth_password = NULL; - - if (authorization && !auth_type(r)) { - if (!strcasecmp(getword(r->pool, &authorization, ' '), "Basic")) { - tmp = uudecode(r->pool, authorization); - tmp_user = getword_nulls_nc(r->pool, &tmp, ':'); - if (tmp_user) { - r->connection->user = pstrdup(r->connection->pool, tmp_user); - r->connection->ap_auth_type = "Basic"; - SG(request_info).auth_user = estrdup(tmp_user); - } - if (tmp) { - SG(request_info).auth_password = estrdup(tmp); - } - } else if (!strcasecmp(getword(r->pool, &authorization, ' '), "Digest")) { - r->connection->ap_auth_type = "Digest"; - SG(request_info).auth_digest = estrdup(authorization); - } - } -} -/* }}} */ - -/* {{{ php_apache_alter_ini_entries - */ -static int php_apache_alter_ini_entries(php_per_dir_entry *per_dir_entry) -{ - zend_alter_ini_entry(per_dir_entry->key, per_dir_entry->key_length+1, per_dir_entry->value, per_dir_entry->value_length, per_dir_entry->type, PHP_INI_STAGE_ACTIVATE); - return 0; -} -/* }}} */ - -/* {{{ php_apache_get_default_mimetype - */ -static char *php_apache_get_default_mimetype(request_rec *r) -{ - - char *mimetype; - if (SG(default_mimetype) || SG(default_charset)) { - /* Assume output will be of the default MIME type. Individual - scripts may change this later. */ - char *tmpmimetype; - tmpmimetype = sapi_get_default_content_type(); - mimetype = pstrdup(r->pool, tmpmimetype); - efree(tmpmimetype); - } else { - mimetype = SAPI_DEFAULT_MIMETYPE "; charset=" SAPI_DEFAULT_CHARSET; - } - return mimetype; -} -/* }}} */ - -/* {{{ send_php - */ -static int send_php(request_rec *r, int display_source_mode, char *filename) -{ - int retval; - php_per_dir_config *per_dir_conf; - if (AP(in_request)) { - zend_file_handle fh; - - fh.filename = r->filename; - fh.opened_path = NULL; - fh.free_filename = 0; - fh.type = ZEND_HANDLE_FILENAME; - - zend_execute_scripts(ZEND_INCLUDE, NULL, 1, &fh); - return OK; - } - - zend_first_try { - - /* Make sure file exists */ - if (filename == NULL && r->finfo.st_mode == 0) { - return DECLINED; - } - - per_dir_conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - if (per_dir_conf) { - zend_hash_apply((HashTable *) per_dir_conf->ini_settings, (apply_func_t) php_apache_alter_ini_entries); - } - - /* If PHP parser engine has been turned off with an "engine off" - * directive, then decline to handle this request - */ - if (!AP(engine)) { - r->content_type = php_apache_get_default_mimetype(r); - r->allowed |= (1 << METHODS) - 1; - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return DECLINED; - } - if (filename == NULL) { - filename = r->filename; - } - - /* Apache 1.2 has a more complex mechanism for reading POST data */ -#if MODULE_MAGIC_NUMBER > 19961007 - if ((retval = setup_client_block(r, REQUEST_CHUNKED_ERROR))) { - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return retval; - } -#endif - - if (AP(last_modified)) { -#if MODULE_MAGIC_NUMBER < 19970912 - if ((retval = set_last_modified(r, r->finfo.st_mtime))) { - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return retval; - } -#else - update_mtime (r, r->finfo.st_mtime); - set_last_modified(r); - set_etag(r); -#endif - } - /* Assume output will be of the default MIME type. Individual - scripts may change this later in the request. */ - r->content_type = php_apache_get_default_mimetype(r); - - /* Init timeout */ - hard_timeout("send", r); - - SG(server_context) = r; - - php_save_umask(); - if(!AP(setup_env)) { - AP(setup_env) = 1; - add_common_vars(r); - add_cgi_vars(r); - } - init_request_info(); - apache_php_module_main(r, display_source_mode); - - /* Done, restore umask, turn off timeout, close file and return */ - php_restore_umask(); - kill_timeout(r); - } zend_end_try(); - - return OK; -} -/* }}} */ - -/* {{{ send_parsed_php - */ -static int send_parsed_php(request_rec * r) -{ - int result = send_php(r, 0, NULL); - - ap_table_setn(r->notes, "mod_php_memory_usage", - ap_psprintf(r->pool, "%u", zend_memory_peak_usage(1))); - - return result; -} -/* }}} */ - -/* {{{ send_parsed_php_source - */ -static int send_parsed_php_source(request_rec * r) -{ - return send_php(r, 1, NULL); -} -/* }}} */ - - -/* {{{ destroy_per_dir_entry - */ -static void destroy_per_dir_entry(php_per_dir_entry *per_dir_entry) -{ - free(per_dir_entry->key); - free(per_dir_entry->value); -} -/* }}} */ - -/* {{{ copy_per_dir_entry - */ -static void copy_per_dir_entry(php_per_dir_entry *per_dir_entry) -{ - php_per_dir_entry tmp = *per_dir_entry; - - per_dir_entry->key = (char *) malloc(tmp.key_length+1); - memcpy(per_dir_entry->key, tmp.key, tmp.key_length); - per_dir_entry->key[per_dir_entry->key_length] = 0; - - per_dir_entry->value = (char *) malloc(tmp.value_length+1); - memcpy(per_dir_entry->value, tmp.value, tmp.value_length); - per_dir_entry->value[per_dir_entry->value_length] = 0; -} -/* }}} */ - -/* {{{ should_overwrite_per_dir_entry; - - */ -static zend_bool should_overwrite_per_dir_entry(HashTable *target_ht, php_per_dir_entry *orig_per_dir_entry, zend_hash_key *hash_key, void *pData) -{ - php_per_dir_entry *new_per_dir_entry; - - if (zend_hash_find(target_ht, hash_key->arKey, hash_key->nKeyLength, (void **) &new_per_dir_entry)==FAILURE) { - return 1; /* does not exist in dest, copy from source */ - } - - if (new_per_dir_entry->type==PHP_INI_SYSTEM - && orig_per_dir_entry->type!=PHP_INI_SYSTEM) { - return 1; - } else { - return 0; - } -} -/* }}} */ -/* {{{ php_destroy_per_server_info - */ -static void php_destroy_per_server_info(php_per_server_config *conf) -{ - php_handler_stack_destroy(&conf->requires); - php_handler_stack_destroy(&conf->uri_handlers); -} -/* }}} */ - -/* {{{ php_destroy_per_dir_info - */ -static void php_destroy_per_dir_info(php_per_dir_config *conf) -{ - zend_hash_destroy(conf->ini_settings); - php_handler_stack_destroy(&conf->response_handlers); - php_handler_stack_destroy(&conf->auth_handlers); - php_handler_stack_destroy(&conf->access_handlers); - php_handler_stack_destroy(&conf->type_handlers); - php_handler_stack_destroy(&conf->fixup_handlers); - php_handler_stack_destroy(&conf->logger_handlers); - php_handler_stack_destroy(&conf->post_read_handlers); - php_handler_stack_destroy(&conf->headers_handlers); - free(conf->ini_settings); -} -/* }}} */ - -/* {{{ php_create_server - */ -static void *php_create_server(pool *p, char *dummy) -{ - php_per_server_config *conf; - conf = (php_per_server_config *) malloc(sizeof(php_per_server_config)); - register_cleanup(p, (void *) conf, (void (*)(void *)) php_destroy_per_server_info, (void (*)(void *)) php_destroy_per_server_info); - - sapi_stack_init_ex(&conf->requires, 1); - sapi_stack_init_ex(&conf->uri_handlers, 1); - return conf; -} - -/* }}} */ - - -/* {{{ php_create_dir - */ -static void *php_create_dir(pool *p, char *dummy) -{ - php_per_dir_config *conf; - conf = (php_per_dir_config *) malloc(sizeof(php_per_dir_config)); - conf->ini_settings = (HashTable *) malloc(sizeof(HashTable)); - zend_hash_init_ex(conf->ini_settings, 5, NULL, (void (*)(void *)) destroy_per_dir_entry, 1, 0); - sapi_stack_init_ex(&conf->response_handlers, 1); - sapi_stack_init_ex(&conf->headers_handlers, 1); - sapi_stack_init_ex(&conf->auth_handlers, 1); - sapi_stack_init_ex(&conf->access_handlers, 1); - sapi_stack_init_ex(&conf->type_handlers, 1); - sapi_stack_init_ex(&conf->fixup_handlers, 1); - sapi_stack_init_ex(&conf->logger_handlers, 1); - sapi_stack_init_ex(&conf->post_read_handlers, 1); - register_cleanup(p, (void *) conf, (void (*)(void *)) php_destroy_per_dir_info, (void (*)(void *)) php_destroy_per_dir_info); - - return conf; -} - -/* }}} */ - -/* {{{ php_merge_dir - */ -static void *php_merge_dir(pool *p, void *basev, void *addv) -{ - php_per_dir_config *a = (php_per_dir_config *) addv; - php_per_dir_config *b = (php_per_dir_config *) basev; - /* This function *must* return addv, and not modify basev */ - zend_hash_merge_ex((HashTable *) a->ini_settings, (HashTable *) b->ini_settings, (copy_ctor_func_t) copy_per_dir_entry, sizeof(php_per_dir_entry), (merge_checker_func_t) should_overwrite_per_dir_entry, NULL); - a->headers_handlers = (a->headers_handlers.top)?a->headers_handlers:b->headers_handlers; - a->auth_handlers = (a->auth_handlers.top)?a->auth_handlers:b->auth_handlers; - a->access_handlers = (a->access_handlers.top)?a->access_handlers:b->access_handlers; - a->type_handlers = (a->type_handlers.top)?a->type_handlers:b->type_handlers; - a->fixup_handlers = (a->fixup_handlers.top)?a->fixup_handlers:b->fixup_handlers; - a->logger_handlers = (a->logger_handlers.top)?a->logger_handlers:b->logger_handlers; - a->post_read_handlers = (a->post_read_handlers.top)?a->post_read_handlers:b->post_read_handlers; - a->response_handlers = (a->response_handlers.top)?a->response_handlers:b->response_handlers; - return a; -} -/* }}} */ - -/* {{{ php_apache_value_handler_ex - */ -static CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode) -{ - php_per_dir_entry per_dir_entry; - - if (!apache_php_initialized) { - apache_php_initialized = 1; -#ifdef ZTS - tsrm_startup(1, 1, 0, NULL); -#endif - sapi_startup(&apache_sapi_module); - php_apache_startup(&apache_sapi_module); - } - per_dir_entry.type = mode; - - if (strcasecmp(arg2, "none") == 0) { - arg2 = ""; - } - - per_dir_entry.key_length = strlen(arg1); - per_dir_entry.value_length = strlen(arg2); - - per_dir_entry.key = (char *) malloc(per_dir_entry.key_length+1); - memcpy(per_dir_entry.key, arg1, per_dir_entry.key_length); - per_dir_entry.key[per_dir_entry.key_length] = 0; - - per_dir_entry.value = (char *) malloc(per_dir_entry.value_length+1); - memcpy(per_dir_entry.value, arg2, per_dir_entry.value_length); - per_dir_entry.value[per_dir_entry.value_length] = 0; - - zend_hash_update(conf, per_dir_entry.key, per_dir_entry.key_length, &per_dir_entry, sizeof(php_per_dir_entry), NULL); - return NULL; -} -/* }}} */ - -static CONST_PREFIX char *php_set_server_handler(server_rec *s, char *arg1, long handler_stage, long handler_type) -{ - php_per_server_config *conf; - php_handler *handler; - handler = (php_handler *) malloc(sizeof(php_handler)); - handler->type = handler_type; - handler->stage = handler_stage; - handler->name = strdup(arg1); - conf = get_module_config(s->module_config, &php7_module); - switch(handler_stage) { - case AP_URI_TRANS: - sapi_stack_push(&conf->uri_handlers, handler); - break; - default: - sapi_stack_push(&conf->requires, handler); - break; - } - return NULL; -} - -static CONST_PREFIX char *php_set_dir_handler(php_per_dir_config *conf, char *arg1, long handler_stage, long handler_type) -{ - php_handler *handler; - handler = (php_handler *) malloc(sizeof(php_handler)); - handler->type = handler_type; - handler->stage = handler_stage; - handler->name = strdup(arg1); - switch(handler_stage) { - case AP_POST_READ: - sapi_stack_push(&conf->post_read_handlers, handler); - break; - case AP_HEADER_PARSE: - sapi_stack_push(&conf->headers_handlers, handler); - break; - case AP_ACCESS_CONTROL: - sapi_stack_push(&conf->access_handlers, handler); - break; - case AP_AUTHENTICATION: - sapi_stack_push(&conf->auth_handlers, handler); - break; - case AP_AUTHORIZATION: - break; - case AP_TYPE_CHECKING: - sapi_stack_push(&conf->type_handlers, handler); - break; - case AP_FIXUP: - sapi_stack_push(&conf->fixup_handlers, handler); - break; - case AP_RESPONSE: - sapi_stack_push(&conf->response_handlers, handler); - break; - case AP_LOGGING: - sapi_stack_push(&conf->logger_handlers, handler); - break; - default: - break; - } - return NULL; -} - -/* {{{ php_set_uri_handler - */ -static CONST_PREFIX char *php_set_uri_handler(cmd_parms *cmd, void *dummy, char *arg1) -{ - return php_set_server_handler(cmd->server, arg1, AP_URI_TRANS, AP_HANDLER_TYPE_FILE); -} -/* }}} */ - -/* {{{ php_set_uri_handler_code */ -static CONST_PREFIX char *php_set_uri_handler_code(cmd_parms *cmd, void *dummy, char *arg1) -{ - return php_set_server_handler(cmd->server, arg1, AP_URI_TRANS, AP_HANDLER_TYPE_METHOD); -} -/* }}} */ - -/* {{{ php_set_header_handler - */ -static CONST_PREFIX char *php_set_header_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_HEADER_PARSE, AP_HANDLER_TYPE_FILE); -} -static CONST_PREFIX char *php_set_header_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_HEADER_PARSE, AP_HANDLER_TYPE_METHOD); -} -/* }}} */ - -/* {{{ php_set_auth_handler - */ -static CONST_PREFIX char *php_set_auth_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_AUTHENTICATION, AP_HANDLER_TYPE_FILE); -} -static CONST_PREFIX char *php_set_auth_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_AUTHENTICATION, AP_HANDLER_TYPE_METHOD); -} - -/* }}} */ - -/* {{{ php_set_access_handler - */ -static CONST_PREFIX char *php_set_access_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_ACCESS_CONTROL, AP_HANDLER_TYPE_FILE); -} -static CONST_PREFIX char *php_set_access_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_ACCESS_CONTROL, AP_HANDLER_TYPE_METHOD); -} - -/* }}} */ - -/* {{{ php_set_type_handler - */ -static CONST_PREFIX char *php_set_type_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_TYPE_CHECKING, AP_HANDLER_TYPE_FILE); -} -static CONST_PREFIX char *php_set_type_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_TYPE_CHECKING, AP_HANDLER_TYPE_METHOD); -} - -/* }}} */ - -/* {{{ php_set_fixup_handler - */ -static CONST_PREFIX char *php_set_fixup_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_FIXUP, AP_HANDLER_TYPE_FILE); -} -static CONST_PREFIX char *php_set_fixup_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_FIXUP, AP_HANDLER_TYPE_METHOD); -} -/* }}} */ - -/* {{{ php_set_logger_handler - */ -static CONST_PREFIX char *php_set_logger_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_LOGGING, AP_HANDLER_TYPE_FILE); -} -static CONST_PREFIX char *php_set_logger_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_LOGGING, AP_HANDLER_TYPE_METHOD); -} - -/* }}} */ - -/* {{{ php_set_post_read_handler - */ -static CONST_PREFIX char *php_set_post_read_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_POST_READ, AP_HANDLER_TYPE_FILE); -} -static CONST_PREFIX char *php_set_post_read_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_POST_READ, AP_HANDLER_TYPE_METHOD); -} - - -/* }}} */ - -/* {{{ php_set_require - */ - -static CONST_PREFIX char *php_set_require(cmd_parms *cmd, void *dummy, char *arg1) -{ - return php_set_server_handler(cmd->server, arg1, 0, AP_HANDLER_TYPE_FILE); -} -/* }}} */ - -/* {{{ php_set_response_handler - */ -static CONST_PREFIX char *php_set_response_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_RESPONSE, AP_HANDLER_TYPE_FILE); -} -static CONST_PREFIX char *php_set_response_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_RESPONSE, AP_HANDLER_TYPE_METHOD); -} -/* }}} */ - -/* {{{ php_apache_value_handler - */ -static CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2) -{ - return php_apache_value_handler_ex(cmd, conf->ini_settings, arg1, arg2, PHP_INI_PERDIR); -} -/* }}} */ - -/* {{{ php_apache_admin_value_handler - */ -static CONST_PREFIX char *php_apache_admin_value_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2) -{ - return php_apache_value_handler_ex(cmd, conf->ini_settings, arg1, arg2, PHP_INI_SYSTEM); -} -/* }}} */ - -/* {{{ php_apache_flag_handler_ex - */ -static CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode) -{ - char bool_val[2]; - - if (!strcasecmp(arg2, "On")) { - bool_val[0] = '1'; - } else { - bool_val[0] = '0'; - } - bool_val[1] = 0; - - return php_apache_value_handler_ex(cmd, conf, arg1, bool_val, mode); -} -/* }}} */ - -/* {{{ php_apache_flag_handler - */ -static CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2) -{ - return php_apache_flag_handler_ex(cmd, conf->ini_settings, arg1, arg2, PHP_INI_PERDIR); -} -/* }}} */ - -/* {{{ php_apache_admin_flag_handler - */ -static CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2) -{ - return php_apache_flag_handler_ex(cmd, conf->ini_settings, arg1, arg2, PHP_INI_SYSTEM); -} -/* }}} */ - -/* {{{ php_apache_phpini_set - */ -static CONST_PREFIX char *php_apache_phpini_set(cmd_parms *cmd, HashTable *conf, char *arg) -{ - if (apache_sapi_module.php_ini_path_override) { - return "Only first PHPINIDir directive honored per configuration tree - subsequent ones ignored"; - } - apache_sapi_module.php_ini_path_override = ap_server_root_relative(cmd->pool, arg); - return NULL; -} -/* }}} */ - -/* {{{ int php_xbithack_handler(request_rec * r) - */ -static int php_xbithack_handler(request_rec * r) -{ - php_per_dir_config *conf; - - if (!(r->finfo.st_mode & S_IXUSR)) { - r->allowed |= (1 << METHODS) - 1; - return DECLINED; - } - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - if (conf) { - zend_hash_apply((HashTable *) conf->ini_settings, (apply_func_t) php_apache_alter_ini_entries); - } - if(!AP(xbithack)) { - r->allowed |= (1 << METHODS) - 1; - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return DECLINED; - } - return send_parsed_php(r); -} -/* }}} */ - -/* {{{ apache_php_module_shutdown_wrapper - */ -static void apache_php_module_shutdown_wrapper(void) -{ - apache_php_initialized = 0; - apache_sapi_module.shutdown(&apache_sapi_module); - -#if MODULE_MAGIC_NUMBER >= 19970728 - /* This function is only called on server exit if the apache API - * child_exit handler exists, so shutdown globally - */ - sapi_shutdown(); -#endif - -#ifdef ZTS - tsrm_shutdown(); -#endif -} -/* }}} */ - -#if MODULE_MAGIC_NUMBER >= 19970728 -/* {{{ php_child_exit_handler - */ -static void php_child_exit_handler(server_rec *s, pool *p) -{ -/* apache_php_initialized = 0; */ - apache_sapi_module.shutdown(&apache_sapi_module); - -#ifdef ZTS - tsrm_shutdown(); -#endif -} -/* }}} */ -#endif - -/* {{{ void php_init_handler(server_rec *s, pool *p) - */ -static void php_init_handler(server_rec *s, pool *p) -{ - register_cleanup(p, NULL, (void (*)(void *))apache_php_module_shutdown_wrapper, (void (*)(void *))php_module_shutdown_for_exec); - if (!apache_php_initialized) { - apache_php_initialized = 1; -#ifdef ZTS - tsrm_startup(1, 1, 0, NULL); -#endif - sapi_startup(&apache_sapi_module); - php_apache_startup(&apache_sapi_module); - } -#if MODULE_MAGIC_NUMBER >= 19980527 - { - if (PG(expose_php)) { - ap_add_version_component("PHP/" PHP_VERSION); - } - } -#endif -} -/* }}} */ - -static int php_run_hook(php_handler *handler, request_rec *r) -{ - zval *ret = NULL; - php_per_dir_config *conf; - - - if(!AP(apache_config_loaded)) { - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - if (conf) - zend_hash_apply((HashTable *)conf->ini_settings, (apply_func_t) php_apache_alter_ini_entries); - AP(apache_config_loaded) = 1; - } - if (!handler->name) { - return DECLINED; - } - php_save_umask(); - if (!AP(setup_env)) { - AP(setup_env) = 1; - add_common_vars(r); - add_cgi_vars(r); - } - SG(server_context) = r; - init_request_info(); - apache_php_module_hook(r, handler, &ret); - php_restore_umask(); - kill_timeout(r); - if (ret) { - convert_to_long(ret); - return Z_LVAL_P(ret); - } - return HTTP_INTERNAL_SERVER_ERROR; -} - - -static int php_uri_translation(request_rec *r) -{ - php_per_server_config *conf; - AP(current_hook) = AP_URI_TRANS; - conf = (php_per_server_config *) get_module_config(r->server->module_config, &php7_module); - return sapi_stack_apply_with_argument_stop_if_equals(&conf->uri_handlers, - ZEND_STACK_APPLY_BOTTOMUP, - (int (*)(void *element, void *)) php_run_hook, r, OK); -} - -static int php_header_hook(request_rec *r) -{ - php_per_dir_config *conf; - AP(current_hook) = AP_HEADER_PARSE; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - return sapi_stack_apply_with_argument_stop_if_http_error(&conf->headers_handlers, - ZEND_STACK_APPLY_BOTTOMUP, - (int (*)(void *element, void *)) php_run_hook, r); -} - -static int php_auth_hook(request_rec *r) -{ - php_per_dir_config *conf; - AP(current_hook) = AP_AUTHENTICATION; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - return sapi_stack_apply_with_argument_stop_if_equals(&conf->auth_handlers, - ZEND_STACK_APPLY_BOTTOMUP, - (int (*)(void *element, void *)) php_run_hook, r, OK); -} - -static int php_access_hook(request_rec *r) -{ - php_per_dir_config *conf; - int status = DECLINED; - AP(current_hook) = AP_ACCESS_CONTROL; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - status = sapi_stack_apply_with_argument_stop_if_http_error(&conf->access_handlers, - ZEND_STACK_APPLY_BOTTOMUP, - (int (*)(void *element, void *)) php_run_hook, r); - return status; - -} - -static int php_type_hook(request_rec *r) -{ - php_per_dir_config *conf; - AP(current_hook) = AP_TYPE_CHECKING; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - return sapi_stack_apply_with_argument_stop_if_equals(&conf->type_handlers, - ZEND_STACK_APPLY_BOTTOMUP, - (int (*)(void *element, void *)) php_run_hook, - r, OK); -} - -static int php_fixup_hook(request_rec *r) -{ - php_per_dir_config *conf; - AP(current_hook) = AP_FIXUP; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - return sapi_stack_apply_with_argument_stop_if_http_error(&conf->fixup_handlers, - ZEND_STACK_APPLY_BOTTOMUP, - (int (*)(void *element, void *)) php_run_hook, - r); -} - -static int php_logger_hook(request_rec *r) -{ - php_per_dir_config *conf; - AP(current_hook) = AP_LOGGING; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - return sapi_stack_apply_with_argument_stop_if_http_error(&conf->logger_handlers, - ZEND_STACK_APPLY_BOTTOMUP, - (int (*)(void *element, void *)) php_run_hook, - r); -} - -static int php_post_read_hook(request_rec *r) -{ - php_per_dir_config *conf; - php_per_server_config *svr; - AP(current_hook) = AP_POST_READ; - svr = get_module_config(r->server->module_config, &php7_module); - if(ap_is_initial_req(r)) { - sapi_stack_apply_with_argument_all(&svr->requires, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r); - } - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - return sapi_stack_apply_with_argument_stop_if_http_error(&conf->post_read_handlers, - ZEND_STACK_APPLY_BOTTOMUP, - (int (*)(void *element, void *)) php_run_hook, r); -} - -static int php_response_handler(request_rec *r) -{ - php_per_dir_config *conf; - AP(current_hook) = AP_RESPONSE; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - return sapi_stack_apply_with_argument_all(&conf->response_handlers, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r); -} - -/* {{{ handler_rec php_handlers[] - */ -handler_rec php_handlers[] = -{ - {"application/x-httpd-php", send_parsed_php}, - {"application/x-httpd-php-source", send_parsed_php_source}, - {"text/html", php_xbithack_handler}, - {"php-script", php_response_handler}, - {NULL} -}; -/* }}} */ - -/* {{{ command_rec php_commands[] - */ -command_rec php_commands[] = -{ - {"php_value", php_apache_value_handler, NULL, OR_OPTIONS, TAKE2, "PHP Value Modifier"}, - {"phpUriHandler", php_set_uri_handler, NULL, RSRC_CONF, TAKE1, "PHP Value Modifier"}, - {"phpUriHandlerMethod", php_set_uri_handler_code, NULL, RSRC_CONF, TAKE1, "PHP Value Modifier"}, -#if MODULE_MAGIC_NUMBER >= 19970103 - {"phpHeaderHandler", php_set_header_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpHeaderHandlerMethod", php_set_header_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, -#endif - {"phpAuthHandler", php_set_auth_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpAuthHandlerMethod", php_set_auth_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpAccessHandler", php_set_access_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpAccessHandlerMethod", php_set_access_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpTypeHandler", php_set_type_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpTypeHandlerMethod", php_set_type_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpFixupHandler", php_set_fixup_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpFixupHandlerMethod", php_set_fixup_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpLoggerHandler", php_set_logger_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpLoggerHandlerMethod", php_set_logger_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, -#if MODULE_MAGIC_NUMBER >= 19970902 - {"phpPostReadHandler", php_set_post_read_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpPostReadHandlerMethod", php_set_post_read_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpRequire", php_set_require, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpResponseHandler", php_set_response_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpResponseHandlerMethod", php_set_response_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, -#endif - {"php_flag", php_apache_flag_handler, NULL, OR_OPTIONS, TAKE2, "PHP Flag Modifier"}, - {"php_admin_value", php_apache_admin_value_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Value Modifier (Admin)"}, - {"php_admin_flag", php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Flag Modifier (Admin)"}, - {"PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF, TAKE1, "Directory containing the php.ini file"}, - {NULL} -}; -/* }}} */ - -/* {{{ module MODULE_VAR_EXPORT php7_module - */ -module MODULE_VAR_EXPORT php7_module = -{ - STANDARD_MODULE_STUFF, - php_init_handler, /* initializer */ - php_create_dir, /* per-directory config creator */ - php_merge_dir, /* dir merger */ - php_create_server, /* per-server config creator */ - NULL, /* merge server config */ - php_commands, /* command table */ - php_handlers, /* handlers */ - php_uri_translation, /* filename translation */ - NULL, /* check_user_id */ - php_auth_hook, /* check auth */ - php_access_hook, /* check access */ - php_type_hook, /* type_checker */ - php_fixup_hook, /* fixups */ - php_logger_hook /* logger */ -#if MODULE_MAGIC_NUMBER >= 19970103 - , php_header_hook /* header parser */ -#endif -#if MODULE_MAGIC_NUMBER >= 19970719 - , NULL /* child_init */ -#endif -#if MODULE_MAGIC_NUMBER >= 19970728 - , php_child_exit_handler /* child_exit */ -#endif -#if MODULE_MAGIC_NUMBER >= 19970902 - , php_post_read_hook /* post read-request */ -#endif -}; -/* }}} */ - -/* - * 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/apache_hooks/mod_php7.exp b/sapi/apache_hooks/mod_php7.exp deleted file mode 100644 index 1469b0314d..0000000000 --- a/sapi/apache_hooks/mod_php7.exp +++ /dev/null @@ -1 +0,0 @@ -php7_module diff --git a/sapi/apache_hooks/mod_php7.h b/sapi/apache_hooks/mod_php7.h deleted file mode 100644 index 34fc20bd31..0000000000 --- a/sapi/apache_hooks/mod_php7.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: Rasmus Lerdorf <rasmus@php.net> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#ifndef MOD_PHP7_H -#define MOD_PHP7_H - -#if !defined(WIN32) && !defined(WINNT) -#ifndef MODULE_VAR_EXPORT -#define MODULE_VAR_EXPORT -#endif -#endif - -typedef struct { - long engine; - long last_modified; - long xbithack; - long terminate_child; - long setup_env; - long current_hook; - zend_bool in_request; - zend_bool apache_config_loaded; - zend_bool headers_sent; -} php_apache_info_struct; - -typedef struct _php_handler { - long type; - long stage; - char *name; -} php_handler; - -#define AP_HANDLER_TYPE_FILE 0 -#define AP_HANDLER_TYPE_METHOD 1 - -extern zend_module_entry apache_module_entry; - -#ifdef ZTS -extern int php_apache_info_id; -#define AP(v) TSRMG(php_apache_info_id, php_apache_info_struct *, v) -#else -extern php_apache_info_struct php_apache_info; -#define AP(v) (php_apache_info.v) -#endif - -/* defines for the various stages of the apache request */ -#define AP_WAITING_FOR_REQUEST 0 -#define AP_POST_READ 1 -#define AP_URI_TRANS 2 -#define AP_HEADER_PARSE 3 -#define AP_ACCESS_CONTROL 4 -#define AP_AUTHENTICATION 5 -#define AP_AUTHORIZATION 6 -#define AP_TYPE_CHECKING 7 -#define AP_FIXUP 8 -#define AP_RESPONSE 9 -#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_PHP7_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/sapi/apache_hooks/php.sym b/sapi/apache_hooks/php.sym deleted file mode 100644 index 1469b0314d..0000000000 --- a/sapi/apache_hooks/php.sym +++ /dev/null @@ -1 +0,0 @@ -php7_module diff --git a/sapi/apache_hooks/php_apache.c b/sapi/apache_hooks/php_apache.c deleted file mode 100644 index 55581b9bb8..0000000000 --- a/sapi/apache_hooks/php_apache.c +++ /dev/null @@ -1,1970 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | Stig Sæther Bakken <ssb@php.net> | - | David Sklar <sklar@student.net> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php_apache_http.h" - -#if defined(PHP_WIN32) || defined(NETWARE) -#include "zend.h" -#include "ap_compat.h" -#else -#include <build-defs.h> -#endif - -#ifdef ZTS -int php_apache_info_id; -#else -php_apache_info_struct php_apache_info; -#endif - -#define SECTION(name) PUTS("<H2 align=\"center\">" name "</H2>\n") - -#undef offsetof -#define offsetof(s_type,field) ((size_t)&(((s_type*)0)->field)) - -extern module *top_module; -extern module **ap_loaded_modules; -static int le_apachereq; -static zend_class_entry *apacherequest_class_entry; - -static void apache_table_to_zval(table *, zval *return_value); - -PHP_FUNCTION(virtual); -PHP_FUNCTION(apache_request_headers); -PHP_FUNCTION(apache_response_headers); -PHP_FUNCTION(apachelog); -PHP_FUNCTION(apache_note); -PHP_FUNCTION(apache_lookup_uri); -PHP_FUNCTION(apache_child_terminate); -PHP_FUNCTION(apache_setenv); -PHP_FUNCTION(apache_get_version); -PHP_FUNCTION(apache_get_modules); - -PHP_MINFO_FUNCTION(apache); - -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} -}; - -/* {{{ php_apache ini entries - */ -PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("xbithack", "0", PHP_INI_ALL, OnUpdateLong, xbithack, php_apache_info_struct, php_apache_info) - STD_PHP_INI_ENTRY("engine", "1", PHP_INI_ALL, OnUpdateLong, engine, php_apache_info_struct, php_apache_info) - STD_PHP_INI_ENTRY("last_modified", "0", PHP_INI_ALL, OnUpdateLong, last_modified, php_apache_info_struct, php_apache_info) - STD_PHP_INI_ENTRY("child_terminate", "0", PHP_INI_ALL, OnUpdateLong, terminate_child, php_apache_info_struct, php_apache_info) -PHP_INI_END() -/* }}} */ - -static void php_apache_globals_ctor(php_apache_info_struct *apache_globals) -{ - apache_globals->in_request = 0; -} - - -#define APREQ_GET_THIS(ZVAL) if (NULL == (ZVAL = getThis())) { \ - php_error(E_WARNING, "%s(): underlying ApacheRequest object missing", \ - get_active_function_name()); \ - RETURN_FALSE; \ - } -#define APREQ_GET_REQUEST(ZVAL, R) APREQ_GET_THIS(ZVAL); \ - R = get_apache_request(ZVAL) - -static void php_apache_request_free(zend_rsrc_list_entry *rsrc) -{ - zval *z = (zval *)rsrc->ptr; -/* fprintf(stderr, "%s() %p\n", __FUNCTION__, z); */ - zval_ptr_dtor(&z); -} - -static request_rec *get_apache_request(zval *z) -{ - request_rec *r; - zval **addr; - - if (NULL == z) { - php_error(E_WARNING, "get_apache_request() invalid wrapper passed"); - return NULL; - } - - if (Z_TYPE_P(z) != IS_OBJECT) { - php_error(E_WARNING, "%s(): wrapper is not an object", get_active_function_name()); - return NULL; - } - - if (zend_hash_index_find(Z_OBJPROP_P(z), 0, (void **)&addr) == FAILURE) { - php_error(E_WARNING, "%s(): underlying object missing", get_active_function_name()); - return NULL; - } - - r = (request_rec *)Z_LVAL_PP(addr); - if (!r) { - php_error(E_WARNING, "%s(): request_rec invalid", get_active_function_name()); - return NULL; - } - - return r; -} - -/* {{{ php_apache_request_new(request_rec *r) - * create a new zval-instance for ApacheRequest that wraps request_rec - */ -zval *php_apache_request_new(request_rec *r) -{ - zval *req; - zval *addr; - - MAKE_STD_ZVAL(addr); - Z_TYPE_P(addr) = IS_LONG; - Z_LVAL_P(addr) = (int) r; - - MAKE_STD_ZVAL(req); - object_init_ex(req, apacherequest_class_entry); - zend_hash_index_update(Z_OBJPROP_P(req), 0, &addr, sizeof(zval *), NULL); - - return req; -} -/* }}} */ - -/* {{{ apache_request_read_string_slot() - */ -static void apache_request_read_string_slot(int offset, INTERNAL_FUNCTION_PARAMETERS) -{ - zval *id; - request_rec *r; - char *s; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - s = *(char **)((char*)r + offset); - - if (s) { - RETURN_STRING(s, 1); - } - - RETURN_EMPTY_STRING(); -} -/* }}} */ - - -/* {{{ apache_request_string_slot() - */ -static void apache_request_string_slot(int offset, INTERNAL_FUNCTION_PARAMETERS) -{ - zval *id; - request_rec *r; - char *old_value, *new_value = NULL; - int new_value_len; - char **target; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &new_value, &new_value_len) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - target = (char **)((char*)r + offset); - old_value = *target; - - if (new_value) { - *target = ap_pstrdup(r->pool, new_value); - } - - if (old_value) { - RETURN_STRING(old_value, 1); - } - - RETURN_EMPTY_STRING(); -} -/* }}} */ - -/* {{{ apache_request_read_int_slot() - */ -static void apache_request_read_int_slot(int offset, INTERNAL_FUNCTION_PARAMETERS) -{ - zval *id; - request_rec *r; - long l; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - l = *(long *)((char*)r + offset); - - RETURN_LONG(l); -} -/* }}} */ - -/* {{{ apache_request_int_slot() - */ -static void apache_request_int_slot(int offset, INTERNAL_FUNCTION_PARAMETERS) -{ - zval *id; - request_rec *r; - long old_value, new_value; - long *target; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &new_value) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - target = (long *)((char*)r + offset); - old_value = *target; - - switch (ZEND_NUM_ARGS()) { - case 0: - break; - case 1: - *target = new_value; - break; - default: - WRONG_PARAM_COUNT; - break; - } - - RETURN_LONG(old_value); -} -/* }}} */ - - -/* {{{ access string slots of request rec - */ - -/* {{{ proto string ApacheRequest::filename([string new_filename]) - */ -PHP_FUNCTION(apache_request_filename) -{ - apache_request_string_slot(offsetof(request_rec, filename), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::uri([string new_uri]) - */ -PHP_FUNCTION(apache_request_uri) -{ - apache_request_string_slot(offsetof(request_rec, uri), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::unparsed_uri([string new_unparsed_uri]) - */ -PHP_FUNCTION(apache_request_unparsed_uri) -{ - apache_request_string_slot(offsetof(request_rec, unparsed_uri), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::path_info([string new_path_info]) - */ -PHP_FUNCTION(apache_request_path_info) -{ - apache_request_string_slot(offsetof(request_rec, path_info), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::args([string new_args]) - */ -PHP_FUNCTION(apache_request_args) -{ - apache_request_string_slot(offsetof(request_rec, args), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::boundary() - */ -PHP_FUNCTION(apache_request_boundary) -{ - apache_request_read_string_slot(offsetof(request_rec, boundary), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - - -/* {{{ proto string ApacheRequest::content_type([string new_type]) - */ -PHP_FUNCTION(apache_request_content_type) -{ - apache_request_string_slot(offsetof(request_rec, content_type), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::content_encoding([string new_encoding]) - */ -PHP_FUNCTION(apache_request_content_encoding) -{ - apache_request_string_slot(offsetof(request_rec, content_encoding), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::handler([string new_handler]) - */ -PHP_FUNCTION(apache_request_handler) -{ - apache_request_string_slot(offsetof(request_rec, handler), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::the_request() - */ -PHP_FUNCTION(apache_request_the_request) -{ - apache_request_read_string_slot(offsetof(request_rec, the_request), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::protocol() - */ -PHP_FUNCTION(apache_request_protocol) -{ - apache_request_read_string_slot(offsetof(request_rec, protocol), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::hostname() - */ -PHP_FUNCTION(apache_request_hostname) -{ - apache_request_read_string_slot(offsetof(request_rec, hostname), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::status_line([string new_status_line]) - */ -PHP_FUNCTION(apache_request_status_line) -{ - apache_request_string_slot(offsetof(request_rec, status_line), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::method() - */ -PHP_FUNCTION(apache_request_method) -{ - apache_request_read_string_slot(offsetof(request_rec, method), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* }}} access string slots of request rec */ - -/* {{{ access int slots of request_rec - */ - -/* {{{ proto int ApacheRequest::proto_num() - */ -PHP_FUNCTION(apache_request_proto_num) -{ - apache_request_read_int_slot(offsetof(request_rec, proto_num), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::assbackwards() - */ -PHP_FUNCTION(apache_request_assbackwards) -{ - apache_request_read_int_slot(offsetof(request_rec, assbackwards), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - - -/* {{{ proto int ApacheRequest::proxyreq([int new_proxyreq]) - */ -PHP_FUNCTION(apache_request_proxyreq) -{ - apache_request_int_slot(offsetof(request_rec, proxyreq), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::chunked() - */ -PHP_FUNCTION(apache_request_chunked) -{ - apache_request_read_int_slot(offsetof(request_rec, chunked), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - - -/* {{{ proto int ApacheRequest::header_only() - */ -PHP_FUNCTION(apache_request_header_only) -{ - apache_request_read_int_slot(offsetof(request_rec, header_only), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::request_time() - */ -PHP_FUNCTION(apache_request_request_time) -{ - apache_request_read_int_slot(offsetof(request_rec, request_time), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::status([int new_status]) - */ -PHP_FUNCTION(apache_request_status) -{ - apache_request_int_slot(offsetof(request_rec, status), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::method_number([int method_number]) - */ -PHP_FUNCTION(apache_request_method_number) -{ - apache_request_read_int_slot(offsetof(request_rec, method_number), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::allowed([int allowed]) - */ -PHP_FUNCTION(apache_request_allowed) -{ - apache_request_int_slot(offsetof(request_rec, allowed), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::bytes_sent() - */ -PHP_FUNCTION(apache_request_bytes_sent) -{ - apache_request_read_int_slot(offsetof(request_rec, bytes_sent), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::mtime() - */ -PHP_FUNCTION(apache_request_mtime) -{ - apache_request_read_int_slot(offsetof(request_rec, mtime), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::content_length([int new_content_length]) - */ -PHP_FUNCTION(apache_request_content_length) -{ - zval *id; - long zlen; - request_rec *r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &zlen) == FAILURE) { - return; - } - - if (ZEND_NUM_ARGS() == 0) { - apache_request_read_int_slot(offsetof(request_rec, clength), INTERNAL_FUNCTION_PARAM_PASSTHRU); - } else { - APREQ_GET_REQUEST(id, r); - - (void)ap_set_content_length(r, zlen); - RETURN_TRUE; - } -} -/* }}} */ - -/* {{{ proto int ApacheRequest::remaining() - */ -PHP_FUNCTION(apache_request_remaining) -{ - apache_request_read_int_slot(offsetof(request_rec, remaining), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::no_cache() - */ -PHP_FUNCTION(apache_request_no_cache) -{ - apache_request_int_slot(offsetof(request_rec, no_cache), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::no_local_copy() - */ -PHP_FUNCTION(apache_request_no_local_copy) -{ - apache_request_int_slot(offsetof(request_rec, no_local_copy), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::read_body() - */ -PHP_FUNCTION(apache_request_read_body) -{ - apache_request_int_slot(offsetof(request_rec, read_body), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - - -/* }}} access int slots of request_rec */ - - -/* {{{ proto array apache_request_headers_in() - * fetch all incoming request headers - */ -PHP_FUNCTION(apache_request_headers_in) -{ - zval *id; - request_rec *r; - - APREQ_GET_REQUEST(id, r); - - apache_table_to_zval(r->headers_in, return_value); -} -/* }}} */ - - -/* {{{ add_header_to_table -*/ -static void add_header_to_table(table *t, INTERNAL_FUNCTION_PARAMETERS) -{ - zval *first = NULL; - zval *second = NULL; - zval **entry, **value; - char *string_key; - uint string_key_len; - ulong num_key; - - zend_bool replace = 0; - HashPosition pos; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|zb", &first, &second, &replace) == FAILURE) { - RETURN_FALSE; - } - - if (Z_TYPE_P(first) == IS_ARRAY) { - switch(ZEND_NUM_ARGS()) { - case 1: - case 3: - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(first), &pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(first), (void **)&entry, &pos) == SUCCESS) { - switch(zend_hash_get_current_key_ex(Z_ARRVAL_P(first), &string_key, &string_key_len, &num_key, &pos)) { - case HASH_KEY_IS_STRING: - if (zend_hash_find(Z_ARRVAL_P(first), string_key, string_key_len, (void **)&value) == FAILURE) { - zend_hash_move_forward_ex(Z_ARRVAL_P(first), &pos); - continue; - } - if (!value) { - zend_hash_move_forward_ex(Z_ARRVAL_P(first), &pos); - continue; - } - - convert_to_string_ex(value); - if (replace) { - ap_table_set(t, string_key, Z_STRVAL_PP(value)); - } else { - ap_table_merge(t, string_key, Z_STRVAL_PP(value)); - } - break; - case HASH_KEY_IS_LONG: - default: - php_error(E_WARNING, "%s(): Can only add STRING keys to headers!", get_active_function_name()); - break; - } - - zend_hash_move_forward_ex(Z_ARRVAL_P(first), &pos); - } - break; - default: - WRONG_PARAM_COUNT; - break; - } - } else if (Z_TYPE_P(first) == IS_STRING) { - switch(ZEND_NUM_ARGS()) { - case 2: - case 3: - convert_to_string_ex(&second); - if (replace) { - ap_table_set(t, Z_STRVAL_P(first), Z_STRVAL_P(second)); - } else { - ap_table_merge(t, Z_STRVAL_P(first), Z_STRVAL_P(second)); - } - break; - default: - WRONG_PARAM_COUNT; - break; - } - } else { - RETURN_FALSE; - } -} - -/* }}} */ - - -/* {{{ proto array apache_request_headers_out([{string name|array list} [, string value [, bool replace = false]]]) - * fetch all outgoing request headers - */ -PHP_FUNCTION(apache_request_headers_out) -{ - zval *id; - request_rec *r; - - APREQ_GET_REQUEST(id, r); - - if (ZEND_NUM_ARGS() > 0) { - add_header_to_table(r->headers_out, INTERNAL_FUNCTION_PARAM_PASSTHRU); - } - - apache_table_to_zval(r->headers_out, return_value); -} -/* }}} */ - - -/* {{{ proto array apache_request_err_headers_out([{string name|array list} [, string value [, bool replace = false]]]) - * fetch all headers that go out in case of an error or a subrequest - */ -PHP_FUNCTION(apache_request_err_headers_out) -{ - zval *id; - request_rec *r; - - APREQ_GET_REQUEST(id, r); - - 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, return_value); -} -/* }}} */ - - -/* {{{ proxy functions for the ap_* functions family - */ - -/* {{{ proto int apache_request_server_port() - */ -PHP_FUNCTION(apache_request_server_port) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - RETURN_LONG(ap_get_server_port(r)); -} -/* }}} */ - -/* {{{ proto int apache_request_remote_host([int type]) - */ -PHP_FUNCTION(apache_request_remote_host) -{ - zval *id; - long type = 0; - request_rec *r; - char *res; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|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, (int)type); - - if (res) { - RETURN_STRING(res, 1); - } - - RETURN_EMPTY_STRING(); -} -/* }}} */ - -/* {{{ proto long apache_request_update_mtime([int dependency_mtime]) - */ -PHP_FUNCTION(apache_request_update_mtime) -{ - zval *id; - request_rec *r; - long mtime = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &mtime) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - RETURN_LONG(ap_update_mtime(r, (int) mtime)); -} -/* }}} */ - - -/* {{{ proto void apache_request_set_etag() - */ -PHP_FUNCTION(apache_request_set_etag) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - ap_set_etag(r); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto void apache_request_set_last_modified() - */ -PHP_FUNCTION(apache_request_set_last_modified) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - ap_set_last_modified(r); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto long apache_request_meets_conditions() - */ -PHP_FUNCTION(apache_request_meets_conditions) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - RETURN_LONG(ap_meets_conditions(r)); -} -/* }}} */ - -/* {{{ proto long apache_request_discard_request_body() - */ -PHP_FUNCTION(apache_request_discard_request_body) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - RETURN_LONG(ap_discard_request_body(r)); -} -/* }}} */ - -/* {{{ proto long apache_request_satisfies() - */ -PHP_FUNCTION(apache_request_satisfies) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - RETURN_LONG(ap_satisfies(r)); -} -/* }}} */ - - -/* {{{ proto bool apache_request_is_initial_req() - */ -PHP_FUNCTION(apache_request_is_initial_req) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - RETURN_BOOL(ap_is_initial_req(r)); -} -/* }}} */ - -/* {{{ proto bool apache_request_some_auth_required() - */ -PHP_FUNCTION(apache_request_some_auth_required) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - RETURN_BOOL(ap_some_auth_required(r)); -} -/* }}} */ - -/* {{{ proto string apache_request_auth_type() - */ -PHP_FUNCTION(apache_request_auth_type) -{ - zval *id; - request_rec *r; - char *t; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - t = (char *)ap_auth_type(r); - if (!t) { - RETURN_NULL(); - } - - RETURN_STRING(t, 1); -} -/* }}} */ - -/* {{{ proto string apache_request_auth_name() - */ -PHP_FUNCTION(apache_request_auth_name) -{ - zval *id; - request_rec *r; - char *t; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - t = (char *)ap_auth_name(r); - if (!t) { - RETURN_NULL(); - } - - RETURN_STRING(t, 1); -} -/* }}} */ - -/* {{{ proto apache_request_basic_auth_pw() - */ -PHP_FUNCTION(apache_request_basic_auth_pw) -{ - zval *id, *zpw; - request_rec *r; - const char *pw; - long status; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zpw) == FAILURE) { - return; - } - - if (!PZVAL_IS_REF(zpw)) { - zend_error(E_WARNING, "Parameter wasn't passed by reference"); - 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 { - ZVAL_NULL(zpw); - } - RETURN_LONG(status); -} -/* }}} */ - - -/* http_protocol.h */ - -PHP_FUNCTION(apache_request_send_http_header) -{ - zval *id; - request_rec *r; - char *type = NULL; - int typelen; - - if (zend_parse_parameters(ZEND_NUM_ARGS() , "|s", &type, &typelen) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - if(type) { - r->content_type = pstrdup(r->pool, type); - } - ap_send_http_header(r); - SG(headers_sent) = 1; - AP(headers_sent) = 1; - RETURN_TRUE; -} - -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)); - SG(headers_sent) = 1; - AP(headers_sent) = 1; - RETURN_TRUE; -} - -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)); - SG(headers_sent) = 1; - AP(headers_sent) = 1; - RETURN_TRUE; -} - -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)); - SG(headers_sent) = 1; - AP(headers_sent) = 1; - RETURN_TRUE; -} - -PHP_FUNCTION(apache_request_send_error_response) -{ - zval *id; - request_rec *r; - long rec = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &rec) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - ap_send_error_response(r, (int) rec); - RETURN_TRUE; -} - -PHP_FUNCTION(apache_request_set_content_length) -{ - long length; - zval *id; - request_rec *r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &length) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - ap_set_content_length(r, length); - RETURN_TRUE; -} - -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; -} - -/* This stuff should use streams or however this is implemented now - -PHP_FUNCTION(apache_request_send_fd) -{ -} - -PHP_FUNCTION(apache_request_send_fd_length) -{ -} -*/ - -/* These are for overriding default output behaviour */ -PHP_FUNCTION(apache_request_rputs) -{ - char *buffer; - int buffer_len; - zval *id; - request_rec *r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &buffer, &buffer_len) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - ap_rwrite(buffer, buffer_len, (request_rec*)SG(server_context)); -} - -/* This stuff would be useful for custom POST handlers, - which should be supported. Probably by not using - sapi_activate at all inside a phpResponseHandler - and instead using a builtin composed of the below - calls as a apache_read_request_body() and allow - people to custom craft their own. - -PHP_FUNCTION(apache_request_setup_client_block) -{ -} - -PHP_FUNCTION(apache_request_should_client_block) -{ -} - -PHP_FUNCTION(apache_request_get_client_block) -{ -} - -PHP_FUNCTION(apache_request_discard_request_body) -{ -} -*/ - -/* http_log.h */ - -/* {{{ proto boolean apache_request_log_error(string message, [long facility]) - */ -PHP_FUNCTION(apache_request_log_error) -{ - zval *id; - char *z_errstr; - int z_errstr_len; - long facility = APLOG_ERR; - request_rec *r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &z_errstr, &z_errstr_len, &facility) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - ap_log_error(APLOG_MARK, (int) facility, r->server, "%s", z_errstr); - RETURN_TRUE; -} -/* }}} */ -/* http_main.h */ - -/* {{{ proto object apache_request_sub_req_lookup_uri(string uri) - Returns sub-request for the specified uri. You would - need to run it yourself with run() -*/ -PHP_FUNCTION(apache_request_sub_req_lookup_uri) -{ - zval *id; - char *file; - int file_len; - request_rec *r, *sub_r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &file, &file_len) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - sub_r = ap_sub_req_lookup_uri(file, r); - - if (!sub_r) { - RETURN_FALSE; - } - return_value = php_apache_request_new(sub_r); -} -/* }}} */ - -/* {{{ proto object apache_request_sub_req_lookup_file(string file) - Returns sub-request for the specified file. You would - need to run it yourself with run(). -*/ -PHP_FUNCTION(apache_request_sub_req_lookup_file) -{ - zval *id; - char *file; - int file_len; - request_rec *r, *sub_r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &file, &file_len) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - sub_r = ap_sub_req_lookup_file(file, r); - - if (!sub_r) { - RETURN_FALSE; - } - return_value = php_apache_request_new(sub_r); -} -/* }}} */ - -/* {{{ proto object apache_request_sub_req_method_uri(string method, string uri) - Returns sub-request for the specified file. You would - need to run it yourself with run(). -*/ -PHP_FUNCTION(apache_request_sub_req_method_uri) -{ - zval *id; - char *file, *method; - int file_len, method_len; - request_rec *r, *sub_r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &method, &method_len, &file, &file_len) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - sub_r = ap_sub_req_method_uri(method, file, r); - - if (!sub_r) { - RETURN_FALSE; - } - return_value = php_apache_request_new(sub_r); -} -/* }}} */ - -/* {{{ proto long apache_request_run() - This is a wrapper for ap_sub_run_req and ap_destory_sub_req. It takes - sub_request, runs it, destroys it, and returns it's status. -*/ -PHP_FUNCTION(apache_request_run) -{ - zval *id; - request_rec *r; - int status; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - if (!r || ap_is_initial_req(r)) { - RETURN_FALSE; - } - status = ap_run_sub_req(r); - ap_destroy_sub_req(r); - RETURN_LONG(status); -} -/* }}} */ - -PHP_FUNCTION(apache_request_internal_redirect) -{ - zval *id; - char *new_uri; - int new_uri_len; - request_rec *r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &new_uri, &new_uri_len) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - ap_internal_redirect(new_uri, r); -} - -PHP_FUNCTION(apache_request_send_header_field) -{ - char *fieldname, *fieldval; - int fieldname_len, fieldval_len; - zval *id; - request_rec *r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &fieldname, &fieldname_len, &fieldval, &fieldval_len) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - ap_send_header_field(r, fieldname, fieldval); - SG(headers_sent) = 1; - AP(headers_sent) = 1; -} - - - -/* }}} */ - -/* {{{ 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) - PHP_FALIAS(content_encoding, apache_request_content_encoding, NULL) - PHP_FALIAS(content_type, apache_request_content_type, NULL) - PHP_FALIAS(filename, apache_request_filename, NULL) - PHP_FALIAS(handler, apache_request_handler, NULL) - PHP_FALIAS(hostname, apache_request_hostname, NULL) - PHP_FALIAS(method, apache_request_method, NULL) - PHP_FALIAS(path_info, apache_request_path_info, NULL) - PHP_FALIAS(protocol, apache_request_protocol, NULL) - PHP_FALIAS(status_line, apache_request_status_line, NULL) - PHP_FALIAS(the_request, apache_request_the_request, NULL) - PHP_FALIAS(unparsed_uri, apache_request_unparsed_uri, NULL) - PHP_FALIAS(uri, apache_request_uri, NULL) - - /* int slots */ - PHP_FALIAS(allowed, apache_request_allowed, NULL) - PHP_FALIAS(bytes_sent, apache_request_bytes_sent, NULL) - PHP_FALIAS(chunked, apache_request_chunked, NULL) - PHP_FALIAS(content_length, apache_request_content_length, NULL) - PHP_FALIAS(header_only, apache_request_header_only, NULL) - PHP_FALIAS(method_number, apache_request_method_number, NULL) - PHP_FALIAS(mtime, apache_request_mtime, NULL) - PHP_FALIAS(no_cache, apache_request_no_cache, NULL) - PHP_FALIAS(no_local_copy, apache_request_no_local_copy, NULL) - PHP_FALIAS(proto_num, apache_request_proto_num, NULL) - PHP_FALIAS(proxyreq, apache_request_proxyreq, NULL) - PHP_FALIAS(read_body, apache_request_read_body, NULL) - PHP_FALIAS(remaining, apache_request_remaining, NULL) - PHP_FALIAS(request_time, apache_request_request_time, NULL) - PHP_FALIAS(status, apache_request_status, NULL) - - /* tables & arrays */ - PHP_FALIAS(headers_in, apache_request_headers_in, NULL) - PHP_FALIAS(headers_out, apache_request_headers_out, NULL) - PHP_FALIAS(err_headers_out, apache_request_err_headers_out, NULL) - - - /* proxy functions for the ap_* functions family */ -#undef auth_name -#undef auth_type -#undef discard_request_body -#undef is_initial_req -#undef meets_conditions -#undef satisfies -#undef set_etag -#undef set_last_modified -#undef some_auth_required -#undef update_mtime -#undef send_http_header -#undef send_header_field -#undef basic_http_header -#undef send_http_trace -#undef send_http_options -#undef send_error_response -#undef set_content_length -#undef set_keepalive -#undef rputs -#undef log_error -#undef lookup_uri -#undef lookup_file -#undef method_uri -#undef run -#undef internal_redirect - PHP_FALIAS(auth_name, apache_request_auth_name, NULL) - PHP_FALIAS(auth_type, apache_request_auth_type, NULL) - PHP_FALIAS(basic_auth_pw, apache_request_basic_auth_pw, NULL) - PHP_FALIAS(discard_request_body, apache_request_discard_request_body, NULL) - PHP_FALIAS(is_initial_req, apache_request_is_initial_req, NULL) - PHP_FALIAS(meets_conditions, apache_request_meets_conditions, NULL) - PHP_FALIAS(remote_host, apache_request_remote_host, NULL) - PHP_FALIAS(satisfies, apache_request_satisfies, NULL) - PHP_FALIAS(server_port, apache_request_server_port, NULL) - PHP_FALIAS(set_etag, apache_request_set_etag, NULL) - PHP_FALIAS(set_last_modified, apache_request_set_last_modified, NULL) - PHP_FALIAS(some_auth_required, apache_request_some_auth_required, NULL) - PHP_FALIAS(update_mtime, apache_request_update_mtime, NULL) - PHP_FALIAS(send_http_header, apache_request_send_http_header, NULL) - PHP_FALIAS(basic_http_header, apache_request_basic_http_header, NULL) - PHP_FALIAS(send_header_field, apache_request_send_header_field, NULL) - PHP_FALIAS(send_http_trace, apache_request_send_http_trace, NULL) - PHP_FALIAS(send_http_options, apache_request_send_http_trace, NULL) - PHP_FALIAS(send_error_response, apache_request_send_error_response, NULL) - PHP_FALIAS(set_content_length, apache_request_set_content_length, NULL) - PHP_FALIAS(set_keepalive, apache_request_set_keepalive, NULL) - PHP_FALIAS(rputs, apache_request_rputs, NULL) - PHP_FALIAS(log_error, apache_request_log_error, NULL) - PHP_FALIAS(lookup_uri, apache_request_sub_req_lookup_uri, NULL) - PHP_FALIAS(lookup_file, apache_request_sub_req_lookup_file, NULL) - PHP_FALIAS(method_uri, apache_request_sub_req_method_uri, NULL) - PHP_FALIAS(run, apache_request_run, NULL) - PHP_FALIAS(internal_redirect, apache_request_internal_redirect, NULL) - PHP_FE_END -}; -/* }}} */ - - -static PHP_MINIT_FUNCTION(apache) -{ - zend_class_entry ce; - -#ifdef ZTS - ts_allocate_id(&php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL); -#else - php_apache_globals_ctor(&php_apache_info); -#endif - REGISTER_INI_ENTRIES(); - - - le_apachereq = zend_register_list_destructors_ex(php_apache_request_free, NULL, "ApacheRequest", module_number); - INIT_OVERLOADED_CLASS_ENTRY(ce, "ApacheRequest", php_apache_request_class_functions, NULL, NULL, NULL); - apacherequest_class_entry = zend_register_internal_class_ex(&ce, NULL); - - REGISTER_LONG_CONSTANT("OK", OK, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DECLINED", DECLINED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("FORBIDDEN", FORBIDDEN, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AUTH_REQUIRED", AUTH_REQUIRED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DONE", DONE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SERVER_ERROR", SERVER_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("REDIRECT", REDIRECT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("BAD_REQUEST", BAD_REQUEST, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("NOT_FOUND", NOT_FOUND, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_CONTINUE", HTTP_CONTINUE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_SWITCHING_PROTOCOLS", HTTP_SWITCHING_PROTOCOLS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_PROCESSING", HTTP_PROCESSING, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_OK", HTTP_OK, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_CREATED", HTTP_CREATED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_ACCEPTED", HTTP_ACCEPTED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_NON_AUTHORITATIVE", HTTP_NON_AUTHORITATIVE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_NO_CONTENT", HTTP_NO_CONTENT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_RESET_CONTENT", HTTP_RESET_CONTENT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_PARTIAL_CONTENT", HTTP_PARTIAL_CONTENT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_MULTI_STATUS", HTTP_MULTI_STATUS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_MULTIPLE_CHOICES", HTTP_MULTIPLE_CHOICES, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_MOVED_PERMANENTLY", HTTP_MOVED_PERMANENTLY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_MOVED_TEMPORARILY", HTTP_MOVED_TEMPORARILY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_SEE_OTHER", HTTP_SEE_OTHER, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_NOT_MODIFIED", HTTP_NOT_MODIFIED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_USE_PROXY", HTTP_USE_PROXY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_TEMPORARY_REDIRECT", HTTP_TEMPORARY_REDIRECT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_BAD_REQUEST", HTTP_BAD_REQUEST, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_UNAUTHORIZED", HTTP_UNAUTHORIZED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_PAYMENT_REQUIRED", HTTP_PAYMENT_REQUIRED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_FORBIDDEN", HTTP_FORBIDDEN, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_NOT_FOUND", HTTP_NOT_FOUND, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_METHOD_NOT_ALLOWED", HTTP_METHOD_NOT_ALLOWED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_NOT_ACCEPTABLE", HTTP_NOT_ACCEPTABLE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_PROXY_AUTHENTICATION_REQUIRED", HTTP_PROXY_AUTHENTICATION_REQUIRED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_REQUEST_TIME_OUT", HTTP_REQUEST_TIME_OUT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_CONFLICT", HTTP_CONFLICT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_GONE", HTTP_GONE, CONST_CS | CONST_PERSISTENT);REGISTER_LONG_CONSTANT("HTTP_LENGTH_REQUIRED", HTTP_LENGTH_REQUIRED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_PRECONDITION_FAILED", HTTP_PRECONDITION_FAILED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_REQUEST_ENTITY_TOO_LARGE", HTTP_REQUEST_ENTITY_TOO_LARGE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_REQUEST_URI_TOO_LARGE", HTTP_REQUEST_URI_TOO_LARGE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_UNSUPPORTED_MEDIA_TYPE", HTTP_UNSUPPORTED_MEDIA_TYPE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_RANGE_NOT_SATISFIABLE", HTTP_RANGE_NOT_SATISFIABLE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_EXPECTATION_FAILED", HTTP_EXPECTATION_FAILED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_UNPROCESSABLE_ENTITY", HTTP_UNPROCESSABLE_ENTITY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_LOCKED", HTTP_LOCKED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_FAILED_DEPENDENCY", HTTP_FAILED_DEPENDENCY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_INTERNAL_SERVER_ERROR", HTTP_INTERNAL_SERVER_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_NOT_IMPLEMENTED", HTTP_NOT_IMPLEMENTED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_BAD_GATEWAY", HTTP_BAD_GATEWAY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_SERVICE_UNAVAILABLE", HTTP_SERVICE_UNAVAILABLE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_GATEWAY_TIME_OUT", HTTP_GATEWAY_TIME_OUT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_VERSION_NOT_SUPPORTED", HTTP_VERSION_NOT_SUPPORTED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_VARIANT_ALSO_VARIES", HTTP_VARIANT_ALSO_VARIES, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_INSUFFICIENT_STORAGE", HTTP_INSUFFICIENT_STORAGE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_NOT_EXTENDED", HTTP_NOT_EXTENDED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APLOG_EMERG", APLOG_EMERG, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APLOG_ALERT", APLOG_ALERT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APLOG_CRIT", APLOG_CRIT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APLOG_ERR", APLOG_ERR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APLOG_WARNING", APLOG_WARNING, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APLOG_NOTICE", APLOG_NOTICE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APLOG_INFO", APLOG_INFO, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APLOG_DEBUG", APLOG_DEBUG, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_GET", M_GET, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_PUT", M_PUT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_POST", M_POST, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_DELETE", M_DELETE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_CONNECT", M_CONNECT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_OPTIONS", M_OPTIONS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_TRACE", M_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_PATCH", M_PATCH, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_PROPFIND", M_PROPFIND, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_PROPPATCH", M_PROPPATCH, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_MKCOL", M_MKCOL, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_COPY", M_COPY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_MOVE", M_MOVE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_LOCK", M_LOCK, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_UNLOCK", M_UNLOCK, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_INVALID", M_INVALID, CONST_CS | CONST_PERSISTENT); - - /* Possible values for request_rec.read_body (set by handling module): - * REQUEST_NO_BODY Send 413 error if message has any body - * REQUEST_CHUNKED_ERROR Send 411 error if body without Content-Length - * REQUEST_CHUNKED_DECHUNK If chunked, remove the chunks for me. - * REQUEST_CHUNKED_PASS Pass the chunks to me without removal. - */ - REGISTER_LONG_CONSTANT("REQUEST_NO_BODY", REQUEST_NO_BODY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_ERROR", REQUEST_CHUNKED_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_DECHUNK", REQUEST_CHUNKED_DECHUNK, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_PASS", REQUEST_CHUNKED_PASS, CONST_CS | CONST_PERSISTENT); - - /* resolve types for remote_host() */ - REGISTER_LONG_CONSTANT("REMOTE_HOST", REMOTE_HOST, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("REMOTE_NAME", REMOTE_NAME, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("REMOTE_NOLOOKUP", REMOTE_NOLOOKUP, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("REMOTE_DOUBLE_REV", REMOTE_DOUBLE_REV, CONST_CS | CONST_PERSISTENT); - - return SUCCESS; -} - - -static PHP_MSHUTDOWN_FUNCTION(apache) -{ - UNREGISTER_INI_ENTRIES(); - return SUCCESS; -} - -zend_module_entry apache_module_entry = { - STANDARD_MODULE_HEADER, - "apache", - apache_functions, - PHP_MINIT(apache), - PHP_MSHUTDOWN(apache), - NULL, - NULL, - PHP_MINFO(apache), - NO_VERSION_YET, - 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(E_WARNING, "apache.child_terminate is disabled"); - RETURN_FALSE; - } -#else - php_error(E_WARNING, "apache_child_terminate() 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 *arg_name, *arg_val = NULL; - int arg_name_len, arg_val_len; - char *note_val; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &arg_name, &arg_name_len, &arg_val, &arg_val_len) == FAILURE) { - return; - } - - 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_FALSE; - } - - RETURN_STRING(note_val, 1); -} -/* }}} */ - -/* {{{ PHP_MINFO_FUNCTION - */ -PHP_MINFO_FUNCTION(apache) -{ - module *modp = NULL; - char output_buf[128]; -#if !defined(WIN32) && !defined(WINNT) - char name[64]; - char modulenames[1024]; - char *p; -#endif - server_rec *serv; - extern char server_root[MAX_STRING_LEN]; - extern uid_t user_id; - extern char *user_name; - extern gid_t group_id; - extern int max_requests_per_child; - - serv = ((request_rec *) SG(server_context))->server; - - - php_info_print_table_start(); - -#ifdef PHP_WIN32 - php_info_print_table_row(1, "Apache for Windows 95/NT"); - php_info_print_table_end(); - php_info_print_table_start(); -#elif defined(NETWARE) - php_info_print_table_row(1, "Apache for NetWare"); - php_info_print_table_end(); - php_info_print_table_start(); -#else - php_info_print_table_row(2, "APACHE_INCLUDE", PHP_APACHE_INCLUDE); - php_info_print_table_row(2, "APACHE_TARGET", PHP_APACHE_TARGET); -#endif - - php_info_print_table_row(2, "Apache Version", SERVER_VERSION); - -#ifdef APACHE_RELEASE - snprintf(output_buf, sizeof(output_buf), "%d", APACHE_RELEASE); - php_info_print_table_row(2, "Apache Release", output_buf); -#endif - snprintf(output_buf, sizeof(output_buf), "%d", MODULE_MAGIC_NUMBER); - php_info_print_table_row(2, "Apache API Version", output_buf); - snprintf(output_buf, sizeof(output_buf), "%s:%u", serv->server_hostname, serv->port); - php_info_print_table_row(2, "Hostname:Port", output_buf); -#if !defined(WIN32) && !defined(WINNT) - snprintf(output_buf, sizeof(output_buf), "%s(%d)/%d", user_name, (int)user_id, (int)group_id); - php_info_print_table_row(2, "User/Group", output_buf); - snprintf(output_buf, sizeof(output_buf), "Per Child: %d - Keep Alive: %s - Max Per Connection: %d", max_requests_per_child, serv->keep_alive ? "on":"off", serv->keep_alive_max); - php_info_print_table_row(2, "Max Requests", output_buf); -#endif - snprintf(output_buf, sizeof(output_buf), "Connection: %d - Keep-Alive: %d", serv->timeout, serv->keep_alive_timeout); - php_info_print_table_row(2, "Timeouts", output_buf); -#if !defined(WIN32) && !defined(WINNT) -/* - This block seems to be working on NetWare; But it seems to be showing - all modules instead of just the loaded ones -*/ - php_info_print_table_row(2, "Server Root", server_root); - - strcpy(modulenames, ""); - for(modp = top_module; modp; modp = modp->next) { - strlcpy(name, modp->name, sizeof(name)); - if ((p = strrchr(name, '.'))) { - *p='\0'; /* Cut off ugly .c extensions on module names */ - } - strlcat(modulenames, name, sizeof(modulenames)); - if (modp->next) { - strlcat(modulenames, ", ", sizeof(modulenames)); - } - } - php_info_print_table_row(2, "Loaded Modules", modulenames); -#endif - - php_info_print_table_end(); - - DISPLAY_INI_ENTRIES(); - - { - register int i; - array_header *arr; - table_entry *elts; - request_rec *r; - - r = ((request_rec *) SG(server_context)); - arr = table_elts(r->subprocess_env); - elts = (table_entry *)arr->elts; - - SECTION("Apache Environment"); - php_info_print_table_start(); - php_info_print_table_header(2, "Variable", "Value"); - for (i=0; i < arr->nelts; i++) { - php_info_print_table_row(2, elts[i].key, elts[i].val); - } - php_info_print_table_end(); - } - - { - array_header *env_arr; - table_entry *env; - int i; - request_rec *r; - - r = ((request_rec *) SG(server_context)); - SECTION("HTTP Headers Information"); - php_info_print_table_start(); - php_info_print_table_colspan_header(2, "HTTP Request Headers"); - php_info_print_table_row(2, "HTTP Request", r->the_request); - env_arr = table_elts(r->headers_in); - env = (table_entry *)env_arr->elts; - for (i = 0; i < env_arr->nelts; ++i) { - if (env[i].key) { - php_info_print_table_row(2, env[i].key, env[i].val); - } - } - php_info_print_table_colspan_header(2, "HTTP Response Headers"); - env_arr = table_elts(r->headers_out); - env = (table_entry *)env_arr->elts; - for(i = 0; i < env_arr->nelts; ++i) { - if (env[i].key) { - php_info_print_table_row(2, env[i].key, env[i].val); - } - } - php_info_print_table_end(); - } -} -/* }}} */ - -/* {{{ proto bool virtual(string filename) - Perform an Apache sub-request */ -/* This function is equivalent to <!--#include virtual...--> - * in mod_include. It does an Apache sub-request. It is useful - * for including CGI scripts or .shtml files, or anything else - * that you'd parse through Apache (for .phtml files, you'd probably - * want to use <?Include>. This only works when PHP is compiled - * as an Apache module, since it uses the Apache API for doing - * sub requests. - */ -PHP_FUNCTION(virtual) -{ - char *filename; - int filename_len; - request_rec *rr = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) { - return; - } - - 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); - if (rr) - destroy_sub_req (rr); - RETURN_FALSE; - } - - php_output_end_all(); - php_header(); - - if (run_sub_req(rr)) { - php_error(E_WARNING, "Unable to include '%s' - request execution failed", filename); - if (rr) - destroy_sub_req (rr); - RETURN_FALSE; - } - - if (rr) - destroy_sub_req (rr); - RETURN_TRUE; -} -/* }}} */ - - -/* {{{ apache_table_to_zval(table *, zval *return_value) - Fetch all HTTP request headers */ -static void apache_table_to_zval(table *t, zval *return_value) -{ - array_header *env_arr; - table_entry *tenv; - int i; - - array_init(return_value); - env_arr = table_elts(t); - 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)==FAILURE) { - RETURN_FALSE; - } - } - -} -/* }}} */ - - -/* {{{ 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) -{ - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - apache_table_to_zval(((request_rec *)SG(server_context))->headers_in, return_value); -} -/* }}} */ - -/* {{{ proto array apache_response_headers(void) - 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, return_value); -} -/* }}} */ - -/* {{{ proto bool apache_setenv(string variable, string value [, bool walk_to_top]) - Set an Apache subprocess_env variable */ -PHP_FUNCTION(apache_setenv) -{ - int var_len, val_len; - zend_bool top=0; - char *var = NULL, *val = NULL; - request_rec *r = (request_rec *) SG(server_context); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) { - RETURN_FALSE; - } - - while(top) { - if (r->prev) { - r = r->prev; - } - else break; - } - - ap_table_setn(r->subprocess_env, ap_pstrndup(r->pool, var, var_len), ap_pstrndup(r->pool, val, val_len)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto object apache_lookup_uri(string URI) - Perform a partial request of the given URI to obtain information about it */ -PHP_FUNCTION(apache_lookup_uri) -{ - char *filename; - int filename_len; - request_rec *rr=NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) { - return; - } - - 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); - } - if (rr->status_line) { - add_property_string(return_value,"status_line", (char *)rr->status_line); - } - if (rr->method) { - add_property_string(return_value,"method", (char *)rr->method); - } - if (rr->content_type) { - add_property_string(return_value,"content_type", (char *)rr->content_type); - } - if (rr->handler) { - add_property_string(return_value,"handler", (char *)rr->handler); - } - if (rr->uri) { - add_property_string(return_value,"uri", rr->uri); - } - if (rr->filename) { - add_property_string(return_value,"filename", rr->filename); - } - if (rr->path_info) { - add_property_string(return_value,"path_info", rr->path_info); - } - if (rr->args) { - add_property_string(return_value,"args", rr->args); - } - if (rr->boundary) { - add_property_string(return_value,"boundary", rr->boundary); - } - 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); - add_property_long(return_value,"sent_bodyct", rr->sent_bodyct); - add_property_long(return_value,"bytes_sent", rr->bytes_sent); - add_property_long(return_value,"byterange", rr->byterange); - add_property_long(return_value,"clength", rr->clength); - -#if MODULE_MAGIC_NUMBER >= 19980324 - if (rr->unparsed_uri) { - add_property_string(return_value,"unparsed_uri", rr->unparsed_uri); - } - if(rr->mtime) { - add_property_long(return_value,"mtime", rr->mtime); - } -#endif - if(rr->request_time) { - add_property_long(return_value,"request_time", rr->request_time); - } - - destroy_sub_req(rr); -} -/* }}} */ - - -#if 0 -/* -This function is most likely a bad idea. Just playing with it for now. -*/ - -PHP_FUNCTION(apache_exec_uri) -{ - zval **filename; - request_rec *rr=NULL; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - - if(!(rr = ap_sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) { - php_error(E_WARNING, "URI lookup failed", (*filename)->value.str.val); - RETURN_FALSE; - } - RETVAL_LONG(ap_run_sub_req(rr)); - ap_destroy_sub_req(rr); -} -#endif - -/* {{{ proto string apache_get_version(void) - Fetch Apache version */ -PHP_FUNCTION(apache_get_version) -{ - char *apv = (char *) ap_get_server_version(); - - if (apv && *apv) { - RETURN_STRING(apv, 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto array apache_get_modules(void) - Get a list of loaded Apache modules */ -PHP_FUNCTION(apache_get_modules) -{ - int n; - char *p; - - array_init(return_value); - - for (n = 0; ap_loaded_modules[n]; ++n) { - char *s = (char *) ap_loaded_modules[n]->name; - if ((p = strchr(s, '.'))) { - add_next_index_stringl(return_value, s, (p - s)); - } else { - add_next_index_string(return_value, s); - } - } -} -/* }}} */ - -/* - * 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/apache_hooks/php_apache_http.h b/sapi/apache_hooks/php_apache_http.h deleted file mode 100644 index 5684de9179..0000000000 --- a/sapi/apache_hooks/php_apache_http.h +++ /dev/null @@ -1,44 +0,0 @@ -#define NO_REGEX_EXTRA_H - -#ifdef WIN32 -#include <winsock2.h> -#include <stddef.h> -#endif - -#ifdef NETWARE -#include <netinet/in.h> -#endif - -#include "zend.h" -#include "zend_stack.h" -#include "ext/ereg/php_regex.h" - -#include "httpd.h" -#include "http_config.h" - -#if MODULE_MAGIC_NUMBER > 19980712 -# include "ap_compat.h" -#else -# if MODULE_MAGIC_NUMBER > 19980324 -# include "compat.h" -# endif -#endif - -#include "http_core.h" -#include "http_main.h" -#include "http_protocol.h" -#include "http_request.h" -#include "http_log.h" -#include "util_script.h" - -#include "php_variables.h" -#include "php_main.h" -#include "php_ini.h" -#include "ext/standard/php_standard.h" - -#include "mod_php7.h" - - -zval *php_apache_request_new(request_rec *r); - -int apache_php_module_hook(request_rec *r, php_handler *handler, zval **ret); diff --git a/sapi/apache_hooks/sapi_apache.c b/sapi/apache_hooks/sapi_apache.c deleted file mode 100644 index dd5a6b60ea..0000000000 --- a/sapi/apache_hooks/sapi_apache.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | (with helpful hints from Dean Gaudet <dgaudet@arctic.org> | - | PHP 4.0 patches by: | - | Zeev Suraski <zeev@zend.com> | - | Stig Bakken <ssb@php.net> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php_apache_http.h" - -/* {{{ apache_php_module_main - */ -int apache_php_module_main(request_rec *r, int display_source_mode) -{ - zend_file_handle file_handle; - - if (php_request_startup() == FAILURE) { - return FAILURE; - } - /* sending a file handle to another dll is not working - so let zend open it. */ - - if (display_source_mode) { - zend_syntax_highlighter_ini syntax_highlighter_ini; - - php_get_highlight_struct(&syntax_highlighter_ini); - if (highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini)){ - return OK; - } else { - return NOT_FOUND; - } - } else { - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.handle.fd = 0; - file_handle.filename = SG(request_info).path_translated; - file_handle.opened_path = NULL; - file_handle.free_filename = 0; - (void) php_execute_script(&file_handle); - } - AP(in_request) = 0; - - return (OK); -} -/* }}} */ - -/* {{{ apache_php_module_hook - */ -int apache_php_module_hook(request_rec *r, php_handler *handler, zval **ret) -{ - zend_file_handle file_handle; - zval *req; - char *tmp; - -#if PHP_SIGCHILD - signal(SIGCHLD, sigchld_handler); -#endif - if(AP(current_hook) == AP_RESPONSE) { - if (php_request_startup_for_hook() == FAILURE) - return FAILURE; - } - else { - if (php_request_startup_for_hook() == FAILURE) - return FAILURE; - } - - req = php_apache_request_new(r); - php_register_variable_ex("request", req, PG(http_globals)[TRACK_VARS_SERVER]); - - switch(handler->type) { - case AP_HANDLER_TYPE_FILE: - php_register_variable("PHP_SELF_HOOK", handler->name, PG(http_globals)[TRACK_VARS_SERVER]); - memset(&file_handle, 0, sizeof(file_handle)); - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = handler->name; - (void) php_execute_simple_script(&file_handle, ret); - break; - case AP_HANDLER_TYPE_METHOD: - if( (tmp = strstr(handler->name, "::")) != NULL && *(tmp+2) != '\0' ) { - zval *class; - zval *method; - *tmp = '\0'; - ALLOC_ZVAL(class); - ZVAL_STRING(class, handler->name, 1); - ALLOC_ZVAL(method); - ZVAL_STRING(method, tmp +2, 1); - *tmp = ':'; - call_user_function_ex(EG(function_table), &class, method, ret, 0, NULL, 0, NULL); - zval_dtor(class); - zval_dtor(method); - } - else { - php_error(E_ERROR, "Unable to call %s - not a Class::Method\n", handler->name); - /* not a class::method */ - } - break; - default: - /* not a valid type */ - assert(0); - break; - } - zval_dtor(req); - AP(in_request) = 0; - - return OK; -} - -/* }}} */ - -/* - * 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/caudium/CREDITS b/sapi/caudium/CREDITS deleted file mode 100644 index 45789dbdfe..0000000000 --- a/sapi/caudium/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Caudium / Roxen -David Hedbor diff --git a/sapi/caudium/README b/sapi/caudium/README deleted file mode 100644 index 86ef65655d..0000000000 --- a/sapi/caudium/README +++ /dev/null @@ -1,16 +0,0 @@ -Embedded Caudium PHP support. It seems to work but isn't tested -much. Due to a design choice it requires _Pike_ threads and a -thread-safe PHP. It doesn't however require _Caudium_ to run in -threaded mode. Due to the design, utilization of multiple processors -should be pretty good. - -It requires a new Pike 7.0 and Caudium. It will not work with -Roxen. Also, with the help of the VIRTUAL_DIR code in PHP, PHP -execution should be very similar to that of mod_php or the cgi -script. - -If you have any questions, please contact me, David Hedbor -(neotron@php.net or neotron@caudium.net). For more information on -Caudium, see http://caudium.net/ and http://caudium.org/. - - diff --git a/sapi/caudium/TODO b/sapi/caudium/TODO deleted file mode 100644 index b8217c5934..0000000000 --- a/sapi/caudium/TODO +++ /dev/null @@ -1,30 +0,0 @@ -TODO: - -- per-virtual-server configuration -- configurable limit of number of concurrent PHP executions -- fix setting of auth info. - -FIXED: -+ => fixed -- => not fixed and no fix planned -? => Maybe fixed, maybe not. - -+ Allow multiple headers - This is now fixed. -+ fix backtraces - Uses th_farm, thus problem is fixed -+ exit in PHP exits Caudium - Name conflict with do_exit in Pike and PHP. Reported to both teams. -+ POST newline added? - Was a Caudium bug. -+ use th_farm - Yeppers. Works great. -- change cwd in single threaded mode - There will be no single threaded mode support. The Caudium module - will requite PHP ZTS and Pike threads to run. Single threaded PHP - is rather uninteresting anyway. -? Recursive mutex lock problem: - Dunno if this is fixed. Major rewrite so it would have to be - retested. - - diff --git a/sapi/caudium/caudium.c b/sapi/caudium/caudium.c deleted file mode 100644 index 9a00b1620a..0000000000 --- a/sapi/caudium/caudium.c +++ /dev/null @@ -1,782 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: David Hedbor <neotron@php.net> | - | Based on aolserver SAPI by Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#ifdef HAVE_CAUDIUM - -#include "php_ini.h" -#include "php_globals.h" -#include "SAPI.h" -#include "php_main.h" -#include "ext/standard/info.h" - -#include "php_version.h" - -/* Pike Include Files - * - * conflicts with pike avoided by only using long names. Requires a new - * Pike 0.7 since it was implemented for this interface only. - * - */ -#define NO_PIKE_SHORTHAND - -/* Ok, we are now using Pike level threads to handle PHP7 since - * the nice th_farm threads aren't working on Linux with glibc 2.2 - * (why this is I don't know). - */ -#define USE_PIKE_LEVEL_THREADS - -#include <fdlib.h> -#include <program.h> -#include <pike_types.h> -#include <interpret.h> -#include <module_support.h> -#include <array.h> -#include <backend.h> -#include <stralloc.h> -#include <mapping.h> -#include <object.h> -#include <threads.h> -#include <builtin_functions.h> -#include <operators.h> -#include <version.h> - -#if (PIKE_MAJOR_VERSION == 7 && PIKE_MINOR_VERSION == 1 && PIKE_BUILD_VERSION >= 12) || PIKE_MAJOR_VERSION > 7 || (PIKE_MAJOR_VERSION == 7 && PIKE_MINOR_VERSION > 1) -# include "pike_error.h" -#else -# include "error.h" -# ifndef Pike_error -# define Pike_error error -# endif -#endif - -/* Pike 7.x and newer */ -#define MY_MAPPING_LOOP(md, COUNT, KEY) \ - for(COUNT=0;COUNT < md->data->hashsize; COUNT++ ) \ - for(KEY=md->data->hash[COUNT];KEY;KEY=KEY->next) - -#ifndef ZTS -/* Need thread safety */ -#error You need to compile PHP with threads. -#endif - -#ifndef PIKE_THREADS -#error The PHP7 module requires that your Pike has thread support. -#endif - -#undef HIDE_GLOBAL_VARIABLES -#undef REVEAL_GLOBAL_VARIABLES -#define HIDE_GLOBAL_VARIABLES() -#define REVEAL_GLOBAL_VARIABLES() - -/* php_caudium_request is per-request object storage */ - -typedef struct -{ - struct mapping *request_data; - struct object *my_fd_obj; - struct svalue done_cb; - struct pike_string *filename; - int my_fd; - int written; - TSRMLS_D; -} php_caudium_request; - - -void pike_module_init(void); -void pike_module_exit(void); -static void free_struct(void); -void f_php_caudium_request_handler(INT32 args); - -/* Defines to get to the data supplied when the script is started. */ - -/* Per thread storage area id... */ -static int caudium_globals_id; - -#define GET_THIS() php_caudium_request *_request = ts_resource(caudium_globals_id) -#define THIS _request -#define PTHIS ((php_caudium_request *)(Pike_fp->current_storage)) -/* File descriptor integer. Used to write directly to the FD without - * passing Pike - */ -#define MY_FD (THIS->my_fd) - -/* FD object. Really a PHPScript object from Pike which implements a couple - * of functions to handle headers, writing and buffering. - */ -#define MY_FD_OBJ ((struct object *)(THIS->my_fd_obj)) - -/* Mapping with data supplied from the calling Caudium module. Contains - * a mapping with headers, an FD object etc. - */ -#define REQUEST_DATA ((struct mapping *)(THIS->request_data)) - -extern int fd_from_object(struct object *o); -static unsigned char caudium_php_initialized; - -#ifndef mt_lock_interpreter -#define mt_lock_interpreter() mt_lock(&interpreter_lock); -#define mt_unlock_interpreter() mt_unlock(&interpreter_lock); -#endif - - -/* This allows calling of pike functions from the PHP callbacks, - * which requires the Pike interpreter to be locked. - */ -#define THREAD_SAFE_RUN(COMMAND, what) do {\ - struct thread_state *state;\ - if((state = thread_state_for_id(th_self()))!=NULL) {\ - if(!state->swapped) {\ - COMMAND;\ - } else {\ - mt_lock_interpreter();\ - SWAP_IN_THREAD(state);\ - COMMAND;\ - SWAP_OUT_THREAD(state);\ - mt_unlock_interpreter();\ - }\ - }\ -} while(0) - - - -/* Low level header lookup. Basically looks for the named header in the mapping - * headers in the supplied options mapping. - */ - -INLINE static struct svalue *lookup_header(char *headername) -{ - struct svalue *headers, *value; - struct pike_string *sind; - GET_THIS(); - sind = make_shared_string("env"); - headers = low_mapping_string_lookup(REQUEST_DATA, sind); - free_string(sind); - if(!headers || headers->type != PIKE_T_MAPPING) return NULL; - sind = make_shared_string(headername); - value = low_mapping_string_lookup(headers->u.mapping, sind); - free_string(sind); - if(!value) return NULL; - return value; -} - -/* Lookup a header in the mapping and return the value as a string, or - * return the default if it's missing - */ -INLINE static char *lookup_string_header(char *headername, char *default_value) -{ - struct svalue *head = NULL; - THREAD_SAFE_RUN(head = lookup_header(headername), "header lookup"); - if(!head || head->type != PIKE_T_STRING) - return default_value; - return head->u.string->str; -} - -/* Lookup a header in the mapping and return the value as if it's an integer - * and otherwise return the default. - */ -INLINE static int lookup_integer_header(char *headername, int default_value) -{ - struct svalue *head = NULL; - THREAD_SAFE_RUN(head = lookup_header(headername), "header lookup"); - if(!head || head->type != PIKE_T_INT) - return default_value; - return head->u.integer; -} - -/* - * php_caudium_low_ub_write() writes data to the client connection. Might be - * rewritten to do more direct IO to save CPU and the need to lock the - * interpreter for better threading. - */ - -INLINE static int -php_caudium_low_ub_write(const char *str, uint str_length) { - int sent_bytes = 0; - struct pike_string *to_write = NULL; - GET_THIS(); - if(!MY_FD_OBJ->prog) { - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - return -1; - } - to_write = make_shared_binary_string(str, str_length); - push_string(to_write); - safe_apply(MY_FD_OBJ, "write", 1); - if(Pike_sp[-1].type == PIKE_T_INT) - sent_bytes = Pike_sp[-1].u.integer; - pop_stack(); - if(sent_bytes != str_length) { - /* This means the connection is closed. Dead. Gone. *sniff* */ - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - } - return sent_bytes; -} - -/* - * php_caudium_sapi_ub_write() calls php_caudium_low_ub_write in a Pike thread - * safe manner or writes directly to the output FD if RXML post-parsing is - * disabled. - */ - -static int -php_caudium_sapi_ub_write(const char *str, uint str_length) -{ - GET_THIS(); - int sent_bytes = 0, fd = MY_FD; - if(fd) - { - for(sent_bytes=0;sent_bytes < str_length;) - { - int written; - written = fd_write(fd, str + sent_bytes, str_length - sent_bytes); - if(written < 0) - { - switch(errno) - { - default: - /* This means the connection is closed. Dead. Gone. *sniff* */ - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - THIS->written += sent_bytes; - return sent_bytes; - case EINTR: - case EWOULDBLOCK: - continue; - } - } else { - sent_bytes += written; - } - } - THIS->written += sent_bytes; - } else { - THREAD_SAFE_RUN(sent_bytes = php_caudium_low_ub_write(str, str_length), - "write"); - } - return sent_bytes; -} - -/* php_caudium_set_header() sets a header in the header mapping. Called in a - * thread safe manner from php_caudium_sapi_header_handler. - */ -INLINE static void -php_caudium_set_header(char *header_name, char *value, char *p) -{ - struct svalue hsval; - struct pike_string *hval, *ind, *hind; - struct mapping *headermap; - struct svalue *s_headermap, *soldval; - int vallen; - GET_THIS(); - /* hval = make_shared_string(value); */ - ind = make_shared_string(" _headers"); - hind = make_shared_binary_string(header_name, - (int)(p - header_name)); - - s_headermap = low_mapping_string_lookup(REQUEST_DATA, ind); - if(!s_headermap || s_headermap->type != PIKE_T_MAPPING) - { - struct svalue mappie; - mappie.type = PIKE_T_MAPPING; - headermap = allocate_mapping(1); - mappie.u.mapping = headermap; - mapping_string_insert(REQUEST_DATA, ind, &mappie); - free_mapping(headermap); - hval = make_shared_string(value); - } else { - headermap = s_headermap->u.mapping; - soldval = low_mapping_string_lookup(headermap, hind); - vallen = strlen(value); - if(soldval != NULL && - soldval->type == PIKE_T_STRING && - soldval->u.string->size_shift == 0) { - /* Existing, valid header. Prepend.*/ - hval = begin_shared_string(soldval->u.string->len + 1 + vallen); - MEMCPY(hval->str, soldval->u.string->str, soldval->u.string->len); - STR0(hval)[soldval->u.string->len] = '\0'; - MEMCPY(hval->str+soldval->u.string->len+1, value, vallen); - hval = end_shared_string(hval); - } else { - hval = make_shared_string(value); - } - } - hsval.type = PIKE_T_STRING; - hsval.u.string = hval; - - mapping_string_insert(headermap, hind, &hsval); - - free_string(hval); - free_string(ind); - free_string(hind); -} - -/* - * php_caudium_sapi_header_handler() sets a HTTP reply header to be - * sent to the client. - */ -static int -php_caudium_sapi_header_handler(sapi_header_struct *sapi_header, - sapi_headers_struct *sapi_headers) -{ - char *header_name, *header_content, *p; - header_name = sapi_header->header; - header_content = p = strchr(header_name, ':'); - - if(p) { - do { - header_content++; - } while(*header_content == ' '); - THREAD_SAFE_RUN(php_caudium_set_header(header_name, header_content, p), "header handler"); - } - sapi_free_header(sapi_header); - return 0; -} - -/* - * php_caudium_sapi_send_headers() flushes the headers to the client. - * Called before real content is sent by PHP. - */ - -INLINE static int -php_caudium_low_send_headers(sapi_headers_struct *sapi_headers) -{ - struct pike_string *ind; - struct svalue *s_headermap; - GET_THIS(); - if(!MY_FD_OBJ->prog) { - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - return SAPI_HEADER_SEND_FAILED; - } - ind = make_shared_string(" _headers"); - s_headermap = low_mapping_string_lookup(REQUEST_DATA, ind); - free_string(ind); - - push_int(SG(sapi_headers).http_response_code); - if(s_headermap && s_headermap->type == PIKE_T_MAPPING) - ref_push_mapping(s_headermap->u.mapping); - else - push_int(0); - safe_apply(MY_FD_OBJ, "send_headers", 2); - pop_stack(); - - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - -static int -php_caudium_sapi_send_headers(sapi_headers_struct *sapi_headers) -{ - int res = 0; - THREAD_SAFE_RUN(res = php_caudium_low_send_headers(sapi_headers), "send headers"); - return res; -} - -/* - * php_caudium_sapi_read_post() reads a specified number of bytes from - * the client. Used for POST/PUT requests. - */ - -INLINE static int php_caudium_low_read_post(char *buf, uint count_bytes) -{ - uint total_read = 0; - GET_THIS(); - - if(!MY_FD_OBJ->prog) - { - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - return -1; - } - push_int(count_bytes); - safe_apply(MY_FD_OBJ, "read_post", 1); - if(Pike_sp[-1].type == PIKE_T_STRING) { - MEMCPY(buf, Pike_sp[-1].u.string->str, - (total_read = Pike_sp[-1].u.string->len)); - buf[total_read] = '\0'; - } else - total_read = 0; - pop_stack(); - return total_read; -} - -static int -php_caudium_sapi_read_post(char *buf, uint count_bytes) -{ - uint total_read = 0; - THREAD_SAFE_RUN(total_read = php_caudium_low_read_post(buf, count_bytes), "read post"); - return total_read; -} - -/* - * php_caudium_sapi_read_cookies() returns the Cookie header from - * the HTTP request header - */ - -static char * -php_caudium_sapi_read_cookies(void) -{ - char *cookies; - cookies = lookup_string_header("HTTP_COOKIE", NULL); - return cookies; -} - -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$"); - /* 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()); - php_info_print_table_row(2, "Installation path", Ns_InfoHomePath()); - php_info_print_table_row(2, "Hostname of server", Ns_InfoHostname()); - php_info_print_table_row(2, "Source code label", Ns_InfoLabel()); - php_info_print_table_row(2, "Server platform", Ns_InfoPlatform()); - snprintf(buf, 511, "%s/%s", Ns_InfoServerName(), Ns_InfoServerVersion()); - php_info_print_table_row(2, "Server version", buf); - snprintf(buf, 511, "%d day(s), %02d:%02d:%02d", - uptime / 86400, - (uptime / 3600) % 24, - (uptime / 60) % 60, - uptime % 60); - php_info_print_table_row(2, "Server uptime", buf); - */ - php_info_print_table_end(); -} - -static zend_module_entry php_caudium_module = { - STANDARD_MODULE_HEADER, - "Caudium", - NULL, - NULL, - NULL, - NULL, - NULL, - php_info_caudium, - NULL, - STANDARD_MODULE_PROPERTIES -}; - - -INLINE static void low_sapi_caudium_register_variables(zval *track_vars_array) -{ - int i; - struct keypair *k; - struct svalue *headers; - struct pike_string *sind; - struct svalue *ind; - struct svalue *val; - GET_THIS(); - php_register_variable("PHP_SELF", SG(request_info).request_uri, - track_vars_array); - php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", - track_vars_array); - php_register_variable("REQUEST_METHOD", - (char *) SG(request_info).request_method, - track_vars_array); - php_register_variable("REQUEST_URI", SG(request_info).request_uri, - track_vars_array); - php_register_variable("PATH_TRANSLATED", SG(request_info).path_translated, - track_vars_array); - - sind = make_shared_string("env"); - headers = low_mapping_string_lookup(REQUEST_DATA, sind); - free_string(sind); - if(headers && headers->type == PIKE_T_MAPPING) { - MY_MAPPING_LOOP(headers->u.mapping, i, k) { - ind = &k->ind; - val = &k->val; - if(ind && ind->type == PIKE_T_STRING && - val && val->type == PIKE_T_STRING) { - php_register_variable(ind->u.string->str, val->u.string->str, - track_vars_array ); - } - } - } -} - -static void sapi_caudium_register_variables(zval *track_vars_array) -{ - THREAD_SAFE_RUN(low_sapi_caudium_register_variables(track_vars_array), "register_variables"); -} - - -static int php_caudium_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, &php_caudium_module, 1)==FAILURE) { - return FAILURE; - } - return SUCCESS; -} - - -/* this structure is static (as in "it does not change") */ -static sapi_module_struct caudium_sapi_module = { - "caudium", - "Caudium", - php_caudium_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - NULL, /* activate */ - NULL, /* deactivate */ - php_caudium_sapi_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - php_error, /* error handler */ - php_caudium_sapi_header_handler, /* header handler */ - php_caudium_sapi_send_headers, /* send headers handler */ - NULL, /* send header handler */ - php_caudium_sapi_read_post, /* read POST data */ - php_caudium_sapi_read_cookies, /* read cookies */ - sapi_caudium_register_variables, /* register server variables */ - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - -/* - * php_caudium_module_main() is called by the per-request handler and - * "executes" the script - */ - -static void php_caudium_module_main(php_caudium_request *ureq) -{ - int res; - zend_file_handle file_handle; -#ifndef USE_PIKE_LEVEL_THREADS - struct thread_state *state; - extern struct program *thread_id_prog; -#endif - GET_THIS(); - THIS->filename = ureq->filename; - THIS->done_cb = ureq->done_cb; - THIS->my_fd_obj = ureq->my_fd_obj; - THIS->my_fd = ureq->my_fd; - THIS->request_data = ureq->request_data; - free(ureq); - -#ifndef USE_PIKE_LEVEL_THREADS - mt_lock_interpreter(); - init_interpreter(); -#if PIKE_MAJOR_VERSION == 7 && PIKE_MINOR_VERSION < 1 - thread_id = low_clone(thread_id_prog); - state = OBJ2THREAD(thread_id); - Pike_stack_top=((char *)&state)+ (thread_stack_size-16384) * STACK_DIRECTION; - recoveries = NULL; - call_c_initializers(thread_id); - OBJ2THREAD(thread_id)->id=th_self(); - num_threads++; - thread_table_insert(thread_id); - state->status=THREAD_RUNNING; -#else - Pike_interpreter.thread_id = low_clone(thread_id_prog); - state = OBJ2THREAD(Pike_interpreter.thread_id); - Pike_interpreter.stack_top=((char *)&state)+ (thread_stack_size-16384) * STACK_DIRECTION; - Pike_interpreter.recoveries = NULL; - call_c_initializers(Pike_interpreter.thread_id); - state->id=th_self(); - /* SWAP_OUT_THREAD(OBJ2THREAD(Pike_interpreter.thread_id)); */ - num_threads++; - thread_table_insert(Pike_interpreter.thread_id); - state->status=THREAD_RUNNING; -#endif - state->swapped = 0; -#endif - SG(request_info).query_string = lookup_string_header("QUERY_STRING", 0); - SG(server_context) = (void *)1; /* avoid server_context == NULL */ - - /* path_translated is apparently the absolute path to the file, not - the translated PATH_INFO - */ - SG(request_info).path_translated = - lookup_string_header("SCRIPT_FILENAME", NULL); - SG(request_info).request_uri = lookup_string_header("DOCUMENT_URI", NULL); - if(!SG(request_info).request_uri) - SG(request_info).request_uri = lookup_string_header("SCRIPT_NAME", NULL); - SG(request_info).request_method = lookup_string_header("REQUEST_METHOD", "GET"); - SG(request_info).content_length = lookup_integer_header("HTTP_CONTENT_LENGTH", 0); - SG(request_info).content_type = lookup_string_header("HTTP_CONTENT_TYPE", NULL); - SG(sapi_headers).http_response_code = 200; - if (!strcmp(SG(request_info).request_method, "HEAD")) { - SG(request_info).headers_only = 1; - } else { - SG(request_info).headers_only = 0; - } - - /* Let PHP7 handle the deconding of the AUTH */ - php_handle_auth_data(lookup_string_header("HTTP_AUTHORIZATION", NULL), ); - /* Swap out this thread and release the interpreter lock to allow - * Pike threads to run. We wait since the above would otherwise require - * a lot of unlock/lock. - */ -#ifndef USE_PIKE_LEVEL_THREADS - SWAP_OUT_THREAD(state); - mt_unlock_interpreter(); -#else - THREADS_ALLOW(); -#endif - - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = THIS->filename->str; - file_handle.opened_path = NULL; - file_handle.free_filename = 0; - - THIS->written = 0; - res = php_request_startup(); - - if(res == FAILURE) { - THREAD_SAFE_RUN({ - apply_svalue(&THIS->done_cb, 0); - pop_stack(); - free_struct(); - }, "Negative run response"); - } else { - php_execute_script(&file_handle); - php_request_shutdown(NULL); - THREAD_SAFE_RUN({ - push_int(THIS->written); - apply_svalue(&THIS->done_cb, 1); - pop_stack(); - free_struct(); - }, "positive run response"); - } - -#ifndef USE_PIKE_LEVEL_THREADS - mt_lock_interpreter(); - SWAP_IN_THREAD(state); -#if PIKE_MAJOR_VERSION == 7 && PIKE_MINOR_VERSION < 1 - state->status=THREAD_EXITED; - co_signal(& state->status_change); - thread_table_delete(thread_id); - free_object(thread_id); - thread_id=NULL; -#else - state->status=THREAD_EXITED; - co_signal(& state->status_change); - thread_table_delete(Pike_interpreter.thread_id); - free_object(Pike_interpreter.thread_id); - Pike_interpreter.thread_id=NULL; -#endif - cleanup_interpret(); - num_threads--; - mt_unlock_interpreter(); -#else - THREADS_DISALLOW(); -#endif -} - -/* - * The php_caudium_request_handler() is called per request and handles - * everything for one request. - */ - -void f_php_caudium_request_handler(INT32 args) -{ - struct object *my_fd_obj; - struct mapping *request_data; - struct svalue *done_callback; - struct pike_string *script; - struct svalue *raw_fd; - struct pike_string *ind; - php_caudium_request *_request; - THIS = malloc(sizeof(php_caudium_request)); - if(THIS == NULL) - Pike_error("Out of memory."); - - get_all_args("PHP5.Interpreter->run", args, "%S%m%O%*", &script, - &request_data, &my_fd_obj, &done_callback); - if(done_callback->type != PIKE_T_FUNCTION) - Pike_error("PHP5.Interpreter->run: Bad argument 4, expected function.\n"); - add_ref(request_data); - add_ref(my_fd_obj); - add_ref(script); - - THIS->request_data = request_data; - THIS->my_fd_obj = my_fd_obj; - THIS->filename = script; - assign_svalue_no_free(&THIS->done_cb, done_callback); - - ind = make_shared_binary_string("my_fd", 5); - raw_fd = low_mapping_string_lookup(THIS->request_data, ind); - if(raw_fd && raw_fd->type == PIKE_T_OBJECT) - { - int fd = fd_from_object(raw_fd->u.object); - if(fd == -1) - THIS->my_fd = 0; /* Don't send directly to this FD... */ - else - THIS->my_fd = fd; - } else - THIS->my_fd = 0; -#ifdef USE_PIKE_LEVEL_THREADS - php_caudium_module_main(THIS); -#else - th_farm((void (*)(void *))php_caudium_module_main, THIS); -#endif - pop_n_elems(args); -} - -static void free_struct(void) -{ - GET_THIS(); - if(THIS->request_data) free_mapping(THIS->request_data); - if(THIS->my_fd_obj) free_object(THIS->my_fd_obj); - free_svalue(&THIS->done_cb); - if(THIS->filename) free_string(THIS->filename); - MEMSET(THIS, 0, sizeof(php_caudium_request)); -} - - -/* - * pike_module_init() is called by Pike once at startup - * - * This functions allocates basic structures - */ - -void pike_module_init( void ) -{ - if (!caudium_php_initialized) { - caudium_php_initialized = 1; - tsrm_startup(1, 1, 0, NULL); - ts_allocate_id(&caudium_globals_id, sizeof(php_caudium_request), NULL, NULL); - sapi_startup(&caudium_sapi_module); - sapi_module.startup(&caudium_sapi_module); - } - start_new_program(); /* Text */ - pike_add_function("run", f_php_caudium_request_handler, - "function(string, mapping, object, function:void)", 0); - end_class("Interpreter", 0); -} - -/* - * pike_module_exit() performs the last steps before the - * server exists. Shutdowns basic services and frees memory - */ - -void pike_module_exit(void) -{ - caudium_php_initialized = 0; - sapi_module.shutdown(&caudium_sapi_module); - tsrm_shutdown(); -} -#endif diff --git a/sapi/caudium/config.m4 b/sapi/caudium/config.m4 deleted file mode 100644 index 13a6b2943e..0000000000 --- a/sapi/caudium/config.m4 +++ /dev/null @@ -1,98 +0,0 @@ -dnl -dnl $Id$ -dnl - -RESULT=no -PHP_ARG_WITH(caudium,, -[ --with-caudium[=DIR] Build PHP as a Pike module for use with Caudium. - DIR is the Caudium server dir [/usr/local/caudium/server]], no, no) - -AC_MSG_CHECKING([for Caudium support]) - -if test "$PHP_CAUDIUM" != "no"; then - if test "$prefix" = "NONE"; then CPREF=/usr/local/; fi - if test ! -d $PHP_CAUDIUM ; then - if test "$prefix" = "NONE"; then - PHP_CAUDIUM=/usr/local/caudium/server/ - else - PHP_CAUDIUM=$prefix/caudium/server/ - fi - fi - if test -f $PHP_CAUDIUM/bin/caudium; then - PIKE=$PHP_CAUDIUM/bin/caudium - elif test -f $PHP_CAUDIUM/bin/pike; then - PIKE=$PHP_CAUDIUM/bin/pike - else - AC_MSG_ERROR([Could not find a pike in $PHP_CAUDIUM/bin/]) - fi - if $PIKE -e 'float v; int rel;sscanf(version(), "Pike v%f release %d", v, rel);v += rel/10000.0; if(v < 7.0268) exit(1); exit(0);'; then - PIKE_MODULE_DIR=`$PIKE --show-paths 2>&1| grep '^Module' | sed -e 's/.*: //'` - PIKE_INCLUDE_DIR=`echo $PIKE_MODULE_DIR | sed -e 's,lib/pike/modules,include/pike,' -e 's,lib/modules,include/pike,' ` - if test -z "$PIKE_INCLUDE_DIR" || test -z "$PIKE_MODULE_DIR"; then - AC_MSG_ERROR(Failed to figure out Pike module and include directories) - fi - AC_MSG_RESULT(yes) - PIKE=`echo $PIKE | pike -e 'int tries=100; - string orig,pike=Stdio.File("stdin")->read()-"\n"; - orig=pike; - if(search(orig, "/")) - orig = combine_path(getcwd(), orig); - while(!catch(pike=readlink(pike)) && tries--) - ; - write(combine_path(dirname(orig), pike)); '` - PHP_ADD_INCLUDE($PIKE_INCLUDE_DIR) - if test "$prefix" != "NONE"; then - PIKE_C_INCLUDE=$prefix/include/`basename $PIKE` - else - PIKE_C_INCLUDE=/usr/local/include/`basename $PIKE` - fi - AC_MSG_CHECKING([for C includes in $PIKE_C_INCLUDE]) - if test -f $PIKE_C_INCLUDE/version.h; then - PIKE_TEST_VER=`$PIKE -e 'string v; int rel;sscanf(version(), "Pike v%s release %d", v, rel); write(v+"."+rel);'` - ###### VERSION MATCH CHECK ####### - PMAJOR="^#define PIKE_MAJOR_VERSION" - PMINOR="^#define PIKE_MINOR_VERSION" - PBUILD="^#define PIKE_BUILD_VERSION" - - PIKE_CMAJOR_VERSION=0 - PIKE_CMINOR_VERSION=0 - PIKE_CBUILD_VERSION=0 - - PIKE_CMAJOR_VERSION=`grep "$PMAJOR" $PIKE_C_INCLUDE/version.h | sed -e 's/\(#define.*N \)\(.*\)/\2/'` - if test -z "$PIKE_CMAJOR_VERSION"; then - if test -n "`grep f_version $PIKE_C_INCLUDE/version.h`"; then - PIKE_CMAJOR_VERSION=6 - fi - else - PIKE_CMINOR_VERSION=`grep "$PMINOR" $PIKE_C_INCLUDE/version.h | sed -e 's/\(#define.*N \)\(.*\)/\2/'` - PIKE_CBUILD_VERSION=`grep "$PBUILD" $PIKE_C_INCLUDE/version.h | sed -e 's/\(#define.*N \)\(.*\)/\2/'` - fi - - if test "$PIKE_TEST_VER" = "${PIKE_CMAJOR_VERSION}.${PIKE_CMINOR_VERSION}.${PIKE_CBUILD_VERSION}"; then - PHP_ADD_INCLUDE($PIKE_C_INCLUDE) - PIKE_INCLUDE_DIR="$PIKE_INCLUDE_DIR, $PIKE_C_INCLUDE" - AC_MSG_RESULT(found) - else - AC_MSG_RESULT(version mismatch) - fi - else - AC_MSG_RESULT(not found) - fi - else - AC_MSG_ERROR([Caudium PHP7 requires Pike 7.0 or newer]) - fi - PIKE_VERSION=`$PIKE -e 'string v; int rel;sscanf(version(), "Pike v%s release %d", v, rel); write(v+"."+rel);'` - AC_DEFINE(HAVE_CAUDIUM,1,[Whether to compile with Caudium support]) - PHP_SELECT_SAPI(caudium, shared, caudium.c) - INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED $PHP_CAUDIUM/lib/$PIKE_VERSION/PHP7.so" - RESULT=" *** Pike binary used: $PIKE - *** Pike include dir(s) used: $PIKE_INCLUDE_DIR - *** Pike version: $PIKE_VERSION" - dnl Always use threads since thread-free support really blows. - PHP_BUILD_THREAD_SAFE -fi -AC_MSG_RESULT($RESULT) - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/continuity/CREDITS b/sapi/continuity/CREDITS deleted file mode 100644 index 35335e9266..0000000000 --- a/sapi/continuity/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Continuity -Alex Leigh (based on nsapi code) diff --git a/sapi/continuity/capi.c b/sapi/continuity/capi.c deleted file mode 100644 index 2f943e3be0..0000000000 --- a/sapi/continuity/capi.c +++ /dev/null @@ -1,507 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: Alex Leigh <php (at) postfin (dot) com> | - +----------------------------------------------------------------------+ -*/ - -/* For more information on Continuity: http://www.ashpool.com/ */ - -/* - * This code is based on the PHP5 SAPI module for NSAPI by Jayakumar - * Muthukumarasamy - */ - -/* PHP includes */ -#define CONTINUITY 1 -#define CAPI_DEBUG - -/* Define for CDP specific extensions */ -#undef CONTINUITY_CDPEXT - -#include "php.h" -#include "php_variables.h" -#include "ext/standard/info.h" -#include "php_ini.h" -#include "php_globals.h" -#include "SAPI.h" -#include "php_main.h" -#include "php_version.h" -#include "TSRM.h" -#include "ext/standard/php_standard.h" - -/* - * CAPI includes - */ -#include <continuity.h> -#include <http.h> - -#define NSLS_D struct capi_request_context *request_context -#define NSLS_DC , NSLS_D -#define NSLS_C request_context -#define NSLS_CC , NSLS_C -#define NSG(v) (request_context->v) - -/* - * ZTS needs to be defined for CAPI to work - */ -#if !defined(ZTS) -#error "CAPI module needs ZTS to be defined" -#endif - -/* - * Structure to encapsulate the CAPI request in SAPI - */ -typedef struct capi_request_context { - httpTtrans *t; - int read_post_bytes; -} capi_request_context; - -/**************/ - -PHP_MINIT_FUNCTION(continuity); -PHP_MSHUTDOWN_FUNCTION(continuity); -PHP_RINIT_FUNCTION(continuity); -PHP_RSHUTDOWN_FUNCTION(continuity); -PHP_MINFO_FUNCTION(continuity); - -PHP_FUNCTION(continuity_virtual); -PHP_FUNCTION(continuity_request_headers); -PHP_FUNCTION(continuity_response_headers); - -const zend_function_entry continuity_functions[] = { - {NULL, NULL, NULL} -}; - -zend_module_entry continuity_module_entry = { - STANDARD_MODULE_HEADER, - "continuity", - continuity_functions, - PHP_MINIT(continuity), - PHP_MSHUTDOWN(continuity), - NULL, - NULL, - PHP_MINFO(continuity), - NO_VERSION_YET, - STANDARD_MODULE_PROPERTIES -}; - -PHP_MINIT_FUNCTION(continuity) -{ - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(continuity) -{ - return SUCCESS; -} - -PHP_MINFO_FUNCTION(continuity) -{ - php_info_print_table_start(); - php_info_print_table_row(2, "Continuity Module Revision", "$Id$"); - php_info_print_table_row(2, "Server Version", conFget_build()); -#ifdef CONTINUITY_CDPEXT - php_info_print_table_row(2,"CDP Extensions", "enabled"); -#else - php_info_print_table_row(2,"CDP Extensions", "disabled"); -#endif - php_info_print_table_end(); - -/* DISPLAY_INI_ENTRIES(); */ -} - -/**************/ - -/* - * sapi_capi_ub_write: Write len bytes to the connection output. - */ -static int sapi_capi_ub_write(const char *str, unsigned int str_length) -{ - int retval; - capi_request_context *rc; - - rc = (capi_request_context *) SG(server_context); - retval = httpFwrite(rc->t, (char *) str, str_length); - if (retval == -1 || retval == 0) - php_handle_aborted_connection(); - return retval; -} - -/* - * sapi_capi_header_handler: Add/update response headers with those provided - * by the PHP engine. - */ -static int sapi_capi_header_handler(sapi_header_struct * sapi_header, sapi_headers_struct * sapi_headers) -{ - char *header_name, *header_content, *p; - capi_request_context *rc = (capi_request_context *) SG(server_context); - - lstFset_delete_key(rc->t->res_hdrs, "Content-Type"); - - header_name = sapi_header->header; - header_content = p = strchr(header_name, ':'); - if (p == NULL) { - return 0; - } - *p = 0; - do { - header_content++; - } while (*header_content == ' '); - - lstFset_add(rc->t->res_hdrs, header_name, header_content); - - *p = ':'; /* restore '*p' */ - - efree(sapi_header->header); - - return 0; /* don't use the default SAPI mechanism, CAPI - * duplicates this functionality */ -} - -/* - * sapi_capi_send_headers: Transmit the headers to the client. This has the - * effect of starting the response under Continuity. - */ -static int sapi_capi_send_headers(sapi_headers_struct * sapi_headers) -{ - int retval; - capi_request_context *rc = (capi_request_context *) SG(server_context); - - /* - * We could probably just do this in the header_handler. But, I don't know - * what the implication of doing it there is. - */ - - if (SG(sapi_headers).send_default_content_type) { - /* lstFset_delete_key(rc->t->res_hdrs, "Content-Type"); */ - lstFset_update(rc->t->res_hdrs, "Content-Type", "text/html"); - } - httpFset_status(rc->t, SG(sapi_headers).http_response_code, NULL); - httpFstart_response(rc->t); - - return SAPI_HEADER_SENT_SUCCESSFULLY; - -} - -static int sapi_capi_read_post(char *buffer, uint count_bytes) -{ - unsigned int max_read, total_read = 0; - capi_request_context *rc = (capi_request_context *) SG(server_context); - - if (rc->read_post_bytes == -1) { - max_read = MIN(count_bytes, SG(request_info).content_length); - } else { - if (rc->read_post_bytes == 0) - return 0; - max_read = MIN(count_bytes, (SG(request_info).content_length - rc->read_post_bytes)); - } - - total_read = httpFread(rc->t, buffer, max_read); - - if (total_read < 0) - total_read = -1; - else - rc->read_post_bytes = total_read; - - return total_read; -} - -/* - * sapi_capi_read_cookies: Return cookie information into PHP. - */ -static char *sapi_capi_read_cookies(void) -{ - char *cookie_string; - capi_request_context *rc = (capi_request_context *) SG(server_context); - - cookie_string = lstFset_get(rc->t->req_hdrs, "cookie"); - return cookie_string; -} - -static void sapi_capi_register_server_variables(zval * track_vars_array) -{ - capi_request_context *rc = (capi_request_context *) SG(server_context); - size_t i; - char *value; - char buf[128]; - - /* PHP_SELF and REQUEST_URI */ - value = lstFset_get(rc->t->vars, "uri"); - if (value != NULL) { - php_register_variable("PHP_SELF", value, track_vars_array); - php_register_variable("REQUEST_URI", value, track_vars_array); - } - - /* COUNTRY CODE */ - value = lstFset_get(rc->t->vars, "ccode"); - if(value!=NULL) - php_register_variable("COUNTRY_CODE", value, track_vars_array); - - /* argv */ - value = lstFset_get(rc->t->vars, "query"); - if (value != NULL) - php_register_variable("argv", value, track_vars_array); - - /* GATEWAY_INTERFACE */ - php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array); - - /* SERVER_NAME and HTTP_HOST */ - value = lstFset_get(rc->t->req_hdrs, "host"); - if (value != NULL) { - php_register_variable("HTTP_HOST", value, track_vars_array); - /* TODO: This should probably scrub the port value if one is present. */ - php_register_variable("SERVER_NAME", value, track_vars_array); - } - /* SERVER_SOFTWARE */ - value = lstFset_get(rc->t->res_hdrs, "Server"); - if (value != NULL) - php_register_variable("SERVER_SOFTWARE", value, track_vars_array); - - /* SERVER_PROTOCOL */ - value = lstFset_get(rc->t->vars, "protocol"); - if (value != NULL) - php_register_variable("SERVER_PROTOCOL", value, track_vars_array); - - /* REQUEST_METHOD */ - value = lstFset_get(rc->t->vars, "method"); - if (value != NULL) - php_register_variable("REQUEST_METHOD", value, track_vars_array); - - /* QUERY_STRING */ - value = lstFset_get(rc->t->vars, "query"); - if (value != NULL) - php_register_variable("QUERY_STRING", value, track_vars_array); - - /* DOCUMENT_ROOT */ - value = lstFset_get(rc->t->vars, "docroot"); - if (value != NULL) - php_register_variable("DOCUMENT_ROOT", value, track_vars_array); - - /* HTTP_ACCEPT */ - value = lstFset_get(rc->t->req_hdrs, "accept"); - if (value != NULL) - php_register_variable("HTTP_ACCEPT", value, track_vars_array); - - /* HTTP_ACCEPT_CHARSET */ - value = lstFset_get(rc->t->req_hdrs, "accept-charset"); - if (value != NULL) - php_register_variable("HTTP_ACCEPT_CHARSET", value, track_vars_array); - - /* HTTP_ACCEPT_ENCODING */ - value = lstFset_get(rc->t->req_hdrs, "accept-encoding"); - if (value != NULL) - php_register_variable("HTTP_ACCEPT_ENCODING", value, track_vars_array); - - /* HTTP_ACCEPT_LANGUAGE */ - value = lstFset_get(rc->t->req_hdrs, "accept-language"); - if (value != NULL) - php_register_variable("HTTP_ACCEPT_LANGUAGE", value, track_vars_array); - - /* HTTP_CONNECTION */ - value = lstFset_get(rc->t->req_hdrs, "connection"); - if (value != NULL) - php_register_variable("HTTP_CONNECTION", value, track_vars_array); - - /* HTTP_REFERER */ - value = lstFset_get(rc->t->req_hdrs, "referer"); - if (value != NULL) - php_register_variable("HTTP_REFERER", value, track_vars_array); - - /* HTTP_USER_AGENT */ - value = lstFset_get(rc->t->req_hdrs, "user-agent"); - if (value != NULL) - php_register_variable("HTTP_USER_AGENT", value, track_vars_array); - - /* REMOTE_ADDR */ - utlFip_to_str(rc->t->cli_ipv4_addr, buf, sizeof(buf)); - php_register_variable("REMOTE_ADDR", buf, track_vars_array); - - /* REMOTE_PORT */ - - /* SCRIPT_FILENAME and PATH_TRANSLATED */ - value = lstFset_get(rc->t->vars, "path"); - if (value != NULL) { - php_register_variable("SCRIPT_FILENAME", value, track_vars_array); - php_register_variable("PATH_TRANSLATED", value, track_vars_array); - } - /* SERVER_ADMIN */ - /* Not applicable */ - - /* SERVER_PORT */ - -} - -static void capi_log_message(char *message) -{ - capi_request_context *rc = (capi_request_context *) SG(server_context); - logFmsg(0, "mod/php: %s", message); -} - -static int php_capi_startup(sapi_module_struct *sapi_module); - -sapi_module_struct capi_sapi_module = { - "Continuity", /* name */ - "Continuity Server Enterprise Edition", /* pretty name */ - - php_capi_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - NULL, /* activate */ - NULL, /* deactivate */ - - sapi_capi_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, /* error handler */ - - sapi_capi_header_handler, /* header handler */ - sapi_capi_send_headers, /* send headers handler */ - NULL, /* send header handler */ - - sapi_capi_read_post, /* read POST data */ - sapi_capi_read_cookies, /* read Cookies */ - - sapi_capi_register_server_variables, /* register server variables */ - capi_log_message, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - NULL, /* Block interruptions */ - NULL, /* Unblock interruptions */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - -static int php_capi_startup(sapi_module_struct *sapi_module) { - if(php_module_startup(sapi_module,&continuity_module_entry,1)==FAILURE) { - return FAILURE; - } - return SUCCESS; -} - - -static char * - capi_strdup(char *str) -{ - if (str != NULL) - return strFcopy(str); - return NULL; -} - -static void capi_free(void *addr) -{ - if (addr != NULL) - free(addr); -} - -static void capi_request_ctor(NSLS_D) -{ - char *query_string = lstFset_get(NSG(t->vars), "query"); - char *uri = lstFset_get(NSG(t->vars), "uri"); - char *path_info = lstFset_get(NSG(t->vars), "path-info"); - char *path_translated = lstFset_get(NSG(t->vars), "path"); - char *request_method = lstFset_get(NSG(t->vars), "method"); - char *content_type = lstFset_get(NSG(t->req_hdrs), "content-type"); - char *content_length = lstFset_get(NSG(t->req_hdrs), "content-length"); - - SG(request_info).query_string = capi_strdup(query_string); - SG(request_info).request_uri = capi_strdup(uri); - SG(request_info).request_method = capi_strdup(request_method); - SG(request_info).path_translated = capi_strdup(path_translated); - SG(request_info).content_type = capi_strdup(content_type); - SG(request_info).content_length = (content_length == NULL) ? 0 : strtoul(content_length, 0, 0); - SG(sapi_headers).http_response_code = 200; -} - -static void capi_request_dtor(NSLS_D) -{ - capi_free(SG(request_info).query_string); - capi_free(SG(request_info).request_uri); - capi_free(SG(request_info).request_method); - capi_free(SG(request_info).path_translated); - capi_free(SG(request_info).content_type); -} - -int capi_module_main(NSLS_D) -{ - zend_file_handle file_handle; - - if (php_request_startup() == FAILURE) { - return FAILURE; - } - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = SG(request_info).path_translated; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - - php_execute_script(&file_handle); - php_request_shutdown(NULL); - - return SUCCESS; -} - -int phpFinit(lstTset * opt) -{ - php_core_globals *core_globals; - - tsrm_startup(128, 1, 0, NULL); - core_globals = ts_resource(core_globals_id); - - logFmsg(0, "mod/php: PHP Interface v3 (module)"); - logFmsg(0, "mod/php: Copyright (c) 1999-2015 The PHP Group. All rights reserved."); - - sapi_startup(&capi_sapi_module); - capi_sapi_module.startup(&capi_sapi_module); - - return STATUS_PROCEED; -} - -int phpFservice(httpTtrans * t, lstTset * opts) -{ - int retval; - capi_request_context *request_context; - - - request_context = (capi_request_context *) malloc(sizeof(capi_request_context)); - request_context->t = t; - request_context->read_post_bytes = -1; - - SG(server_context) = request_context; - - capi_request_ctor(NSLS_C); - retval = capi_module_main(NSLS_C); - capi_request_dtor(NSLS_C); - - free(request_context); - - /* - * This call is ostensibly provided to free the memory from PHP/TSRM when - * the thread terminated, but, it leaks a structure in some hash list - * according to the developers. Not calling this will leak the entire - * interpreter, around 100k, but calling it and then terminating the - * thread will leak the struct (around a k). The only answer with the - * current TSRM implementation is to reuse the threads that allocate TSRM - * resources. - */ - /* ts_free_thread(); */ - - if (retval == SUCCESS) { - return STATUS_EXIT; - } else { - return STATUS_ERROR; - } -} diff --git a/sapi/continuity/config.m4 b/sapi/continuity/config.m4 deleted file mode 100644 index 8d2741921a..0000000000 --- a/sapi/continuity/config.m4 +++ /dev/null @@ -1,28 +0,0 @@ -dnl ## $Id$ -*- sh -*- - -PHP_ARG_WITH(continuity, for Continuity support, -[ --with-continuity=DIR Build PHP as Continuity Server module. - DIR is path to the installed Continuity Server root], no, no) - -if test "$PHP_CONTINUITY" != "no"; then - if test ! -d $PHP_CONTINUITY; then - AC_MSG_ERROR([Please specify the path to the root of your Continuity server using --with-continuity=DIR]) - fi - AC_MSG_CHECKING([for Continuity include files]) - if test -d $PHP_CONTINUITY/include ; then - CAPI_INCLUDE=$PHP_CONTINUITY/include - AC_MSG_RESULT([Continuity Binary Distribution]) - else - AC_MSG_ERROR([Cannot find your CAPI include files in either DIR/src or DIR/include]) - fi - - PHP_SELECT_SAPI(continuity, shared, capi.c) - PHP_ADD_INCLUDE($CAPI_INCLUDE) - PHP_BUILD_THREAD_SAFE - AC_DEFINE(HAVE_CONTINUITY, 1, [Whether you have a Continuity Server]) - INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)$PHP_CONTINUITY/lib/" -fi - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/isapi/CREDITS b/sapi/isapi/CREDITS deleted file mode 100644 index 11c6fdc73c..0000000000 --- a/sapi/isapi/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -ISAPI -Andi Gutmans, Zeev Suraski diff --git a/sapi/isapi/config.m4 b/sapi/isapi/config.m4 deleted file mode 100644 index 4073173eaf..0000000000 --- a/sapi/isapi/config.m4 +++ /dev/null @@ -1,24 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(isapi, for Zeus ISAPI support, -[ --with-isapi[=DIR] Build PHP as an ISAPI module for use with Zeus], no, no) - -if test "$PHP_ISAPI" != "no"; then - if test "$PHP_ISAPI" = "yes"; then - ZEUSPATH=/usr/local/zeus # the default - else - ZEUSPATH=$PHP_ISAPI - fi - test -f "$ZEUSPATH/web/include/httpext.h" || AC_MSG_ERROR(Unable to find httpext.h in $ZEUSPATH/web/include) - PHP_BUILD_THREAD_SAFE - AC_DEFINE(WITH_ZEUS, 1, [ ]) - PHP_ADD_INCLUDE($ZEUSPATH/web/include) - PHP_SELECT_SAPI(isapi, shared, php7isapi.c) - INSTALL_IT="\$(SHELL) \$(srcdir)/install-sh -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)$ZEUSPATH/web/bin/" -fi - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/isapi/config.w32 b/sapi/isapi/config.w32 deleted file mode 100644 index 5a359f11b2..0000000000 --- a/sapi/isapi/config.w32 +++ /dev/null @@ -1,13 +0,0 @@ -// vim:ft=javascript -// $Id$ - -ARG_ENABLE('isapi', 'Build ISAPI version of PHP', 'no'); - -if (PHP_ISAPI == "yes") { - if (PHP_ZTS == "no") { - WARNING("ISAPI module requires an --enable-zts build of PHP"); - } else { - SAPI('isapi', 'php7isapi.c', 'php' + PHP_VERSION + 'isapi.dll', '/D PHP7ISAPI_EXPORTS'); - ADD_FLAG('LDFLAGS_ISAPI', '/DEF:sapi\\isapi\\php7isapi.def'); - } -} diff --git a/sapi/isapi/php.sym b/sapi/isapi/php.sym deleted file mode 100644 index 34b50b851c..0000000000 --- a/sapi/isapi/php.sym +++ /dev/null @@ -1,5 +0,0 @@ -GetFilterVersion -HttpFilterProc -GetExtensionVersion -HttpExtensionProc -ZSLMain diff --git a/sapi/isapi/php7isapi.c b/sapi/isapi/php7isapi.c deleted file mode 100644 index 627c20c18c..0000000000 --- a/sapi/isapi/php7isapi.c +++ /dev/null @@ -1,971 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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. | - +----------------------------------------------------------------------+ - | Authors: Zeev Suraski <zeev@zend.com> | - | Ben Mansell <ben@zeus.com> (Zeus Support) | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php.h" -#include <httpext.h> -#include <httpfilt.h> -#include <httpext.h> -#include "php_main.h" -#include "SAPI.h" -#include "php_globals.h" -#include "ext/standard/info.h" -#include "php_variables.h" -#include "php_ini.h" - -#ifdef PHP_WIN32 -# include <process.h> -#else -# define __try -# define __except(val) -# define __declspec(foo) -#endif - - -#ifdef WITH_ZEUS -# include "httpext.h" -# include <errno.h> -# define GetLastError() errno -#endif - -#ifdef PHP_WIN32 -#define PHP_ENABLE_SEH -#endif - -/* -uncomment the following lines to turn off -exception trapping when running under a debugger - -#ifdef _DEBUG -#undef PHP_ENABLE_SEH -#endif -*/ - -#define MAX_STATUS_LENGTH sizeof("xxxx LONGEST POSSIBLE STATUS DESCRIPTION") -#define ISAPI_SERVER_VAR_BUF_SIZE 1024 -#define ISAPI_POST_DATA_BUF 1024 - -static zend_bool bFilterLoaded=0; -static zend_bool bTerminateThreadsOnError=0; - -static char *isapi_special_server_variable_names[] = { - "ALL_HTTP", - "HTTPS", -#ifndef WITH_ZEUS - "SCRIPT_NAME", -#endif - NULL -}; - -#define NUM_SPECIAL_VARS (sizeof(isapi_special_server_variable_names)/sizeof(char *)) -#define SPECIAL_VAR_ALL_HTTP 0 -#define SPECIAL_VAR_HTTPS 1 -#define SPECIAL_VAR_PHP_SELF 2 - -static char *isapi_server_variable_names[] = { - "AUTH_PASSWORD", - "AUTH_TYPE", - "AUTH_USER", - "CONTENT_LENGTH", - "CONTENT_TYPE", - "PATH_TRANSLATED", - "QUERY_STRING", - "REMOTE_ADDR", - "REMOTE_HOST", - "REMOTE_USER", - "REQUEST_METHOD", - "SERVER_NAME", - "SERVER_PORT", - "SERVER_PROTOCOL", - "SERVER_SOFTWARE", -#ifndef WITH_ZEUS - "APPL_MD_PATH", - "APPL_PHYSICAL_PATH", - "INSTANCE_ID", - "INSTANCE_META_PATH", - "LOGON_USER", - "REQUEST_URI", - "URL", -#else - "DOCUMENT_ROOT", -#endif - NULL -}; - - -static char *isapi_secure_server_variable_names[] = { - "CERT_COOKIE", - "CERT_FLAGS", - "CERT_ISSUER", - "CERT_KEYSIZE", - "CERT_SECRETKEYSIZE", - "CERT_SERIALNUMBER", - "CERT_SERVER_ISSUER", - "CERT_SERVER_SUBJECT", - "CERT_SUBJECT", - "HTTPS_KEYSIZE", - "HTTPS_SECRETKEYSIZE", - "HTTPS_SERVER_ISSUER", - "HTTPS_SERVER_SUBJECT", - "SERVER_PORT_SECURE", -#ifdef WITH_ZEUS - "SSL_CLIENT_CN", - "SSL_CLIENT_EMAIL", - "SSL_CLIENT_OU", - "SSL_CLIENT_O", - "SSL_CLIENT_L", - "SSL_CLIENT_ST", - "SSL_CLIENT_C", - "SSL_CLIENT_I_CN", - "SSL_CLIENT_I_EMAIL", - "SSL_CLIENT_I_OU", - "SSL_CLIENT_I_O", - "SSL_CLIENT_I_L", - "SSL_CLIENT_I_ST", - "SSL_CLIENT_I_C", -#endif - NULL -}; - - -static void php_info_isapi(ZEND_MODULE_INFO_FUNC_ARGS) -{ - char **p; - char variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; - DWORD variable_len; - char **all_variables[] = { - isapi_server_variable_names, - isapi_special_server_variable_names, - isapi_secure_server_variable_names, - NULL - }; - char ***server_variable_names; - LPEXTENSION_CONTROL_BLOCK lpECB; - - lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); - - php_info_print_table_start(); - php_info_print_table_header(2, "Server Variable", "Value"); - server_variable_names = all_variables; - while (*server_variable_names) { - p = *server_variable_names; - while (*p) { - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if (lpECB->GetServerVariable(lpECB->ConnID, *p, variable_buf, &variable_len) - && variable_buf[0]) { - php_info_print_table_row(2, *p, variable_buf); - } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { - char *tmp_variable_buf; - - tmp_variable_buf = (char *) emalloc(variable_len); - if (lpECB->GetServerVariable(lpECB->ConnID, *p, tmp_variable_buf, &variable_len) - && variable_buf[0]) { - php_info_print_table_row(2, *p, tmp_variable_buf); - } - efree(tmp_variable_buf); - } - p++; - } - server_variable_names++; - } - php_info_print_table_end(); -} - - -static zend_module_entry php_isapi_module = { - STANDARD_MODULE_HEADER, - "ISAPI", - NULL, - NULL, - NULL, - NULL, - NULL, - php_info_isapi, - NULL, - STANDARD_MODULE_PROPERTIES -}; - - -static int sapi_isapi_ub_write(const char *str, uint str_length) -{ - DWORD num_bytes = str_length; - LPEXTENSION_CONTROL_BLOCK ecb; - - ecb = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); - if (ecb->WriteClient(ecb->ConnID, (char *) str, &num_bytes, HSE_IO_SYNC) == FALSE) { - php_handle_aborted_connection(); - } - return num_bytes; -} - - -static int sapi_isapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers) -{ - return SAPI_HEADER_ADD; -} - - - -static void accumulate_header_length(sapi_header_struct *sapi_header, uint *total_length) -{ - *total_length += sapi_header->header_len+2; -} - - -static void concat_header(sapi_header_struct *sapi_header, char **combined_headers_ptr) -{ - memcpy(*combined_headers_ptr, sapi_header->header, sapi_header->header_len); - *combined_headers_ptr += sapi_header->header_len; - **combined_headers_ptr = '\r'; - (*combined_headers_ptr)++; - **combined_headers_ptr = '\n'; - (*combined_headers_ptr)++; -} - - -static int sapi_isapi_send_headers(sapi_headers_struct *sapi_headers) -{ - uint total_length = 2; /* account for the trailing \r\n */ - char *combined_headers, *combined_headers_ptr; - LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); - HSE_SEND_HEADER_EX_INFO header_info; - sapi_header_struct default_content_type; - char *status_buf = NULL; - - /* Obtain headers length */ - if (SG(sapi_headers).send_default_content_type) { - sapi_get_default_content_type_header(&default_content_type); - accumulate_header_length(&default_content_type, (void *) &total_length); - } - zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) accumulate_header_length, (void *) &total_length); - - /* Generate headers */ - combined_headers = (char *) emalloc(total_length+1); - combined_headers_ptr = combined_headers; - if (SG(sapi_headers).send_default_content_type) { - concat_header(&default_content_type, (void *) &combined_headers_ptr); - sapi_free_header(&default_content_type); /* we no longer need it */ - } - zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) concat_header, (void *) &combined_headers_ptr); - *combined_headers_ptr++ = '\r'; - *combined_headers_ptr++ = '\n'; - *combined_headers_ptr = 0; - - switch (SG(sapi_headers).http_response_code) { - case 200: - header_info.pszStatus = "200 OK"; - break; - case 302: - header_info.pszStatus = "302 Moved Temporarily"; - break; - case 401: - header_info.pszStatus = "401 Authorization Required"; - break; - default: { - const char *sline = SG(sapi_headers).http_status_line; - int sline_len; - - /* httpd requires that r->status_line is set to the first digit of - * the status-code: */ - if (sline && ((sline_len = strlen(sline)) > 12) && strncmp(sline, "HTTP/1.", 7) == 0 && sline[8] == ' ') { - if ((sline_len - 9) > MAX_STATUS_LENGTH) { - status_buf = estrndup(sline + 9, MAX_STATUS_LENGTH); - } else { - status_buf = estrndup(sline + 9, sline_len - 9); - } - } else { - status_buf = emalloc(MAX_STATUS_LENGTH + 1); - snprintf(status_buf, MAX_STATUS_LENGTH, "%d Undescribed", SG(sapi_headers).http_response_code); - } - header_info.pszStatus = status_buf; - break; - } - } - header_info.cchStatus = strlen(header_info.pszStatus); - header_info.pszHeader = combined_headers; - header_info.cchHeader = total_length; - header_info.fKeepConn = FALSE; - lpECB->dwHttpStatusCode = SG(sapi_headers).http_response_code; - - lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); - - efree(combined_headers); - if (status_buf) { - efree(status_buf); - } - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - - -static int php_isapi_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, &php_isapi_module, 1)==FAILURE) { - return FAILURE; - } else { - bTerminateThreadsOnError = (zend_bool) INI_INT("isapi.terminate_threads_on_error"); - return SUCCESS; - } -} - - -static int sapi_isapi_read_post(char *buffer, uint count_bytes) -{ - LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); - DWORD read_from_buf=0; - DWORD read_from_input=0; - DWORD total_read=0; - - if ((DWORD) SG(read_post_bytes) < lpECB->cbAvailable) { - read_from_buf = MIN(lpECB->cbAvailable-SG(read_post_bytes), count_bytes); - memcpy(buffer, lpECB->lpbData+SG(read_post_bytes), read_from_buf); - total_read += read_from_buf; - } - if (read_from_buf<count_bytes - && (SG(read_post_bytes)+read_from_buf) < lpECB->cbTotalBytes) { - DWORD cbRead=0, cbSize; - - read_from_input = MIN(count_bytes-read_from_buf, lpECB->cbTotalBytes-SG(read_post_bytes)-read_from_buf); - while (cbRead < read_from_input) { - cbSize = read_from_input - cbRead; - if (!lpECB->ReadClient(lpECB->ConnID, buffer+read_from_buf+cbRead, &cbSize) || cbSize==0) { - break; - } - cbRead += cbSize; - } - total_read += cbRead; - } - return total_read; -} - - -static char *sapi_isapi_read_cookies(void) -{ - LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); - char variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; - DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - - if (lpECB->GetServerVariable(lpECB->ConnID, "HTTP_COOKIE", variable_buf, &variable_len)) { - return estrndup(variable_buf, variable_len); - } else if (GetLastError()==ERROR_INSUFFICIENT_BUFFER) { - char *tmp_variable_buf = (char *) emalloc(variable_len+1); - - if (lpECB->GetServerVariable(lpECB->ConnID, "HTTP_COOKIE", tmp_variable_buf, &variable_len)) { - tmp_variable_buf[variable_len] = 0; - return tmp_variable_buf; - } else { - efree(tmp_variable_buf); - } - } - return STR_EMPTY_ALLOC(); -} - - -#ifdef WITH_ZEUS - -static void sapi_isapi_register_zeus_ssl_variables(LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array) -{ - char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; - DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - char static_cons_buf[ISAPI_SERVER_VAR_BUF_SIZE]; - /* - * We need to construct the /C=.../ST=... - * DN's for SSL_CLIENT_DN and SSL_CLIENT_I_DN - */ - strcpy( static_cons_buf, "/C=" ); - if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_C", static_variable_buf, &variable_len ) && static_variable_buf[0] ) { - strlcat( static_cons_buf, static_variable_buf, ISAPI_SERVER_VAR_BUF_SIZE); - } - strlcat( static_cons_buf, "/ST=", ISAPI_SERVER_VAR_BUF_SIZE); - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_ST", static_variable_buf, &variable_len ) && static_variable_buf[0] ) { - strlcat( static_cons_buf, static_variable_buf, ISAPI_SERVER_VAR_BUF_SIZE ); - } - php_register_variable( "SSL_CLIENT_DN", static_cons_buf, track_vars_array ); - - strcpy( static_cons_buf, "/C=" ); - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_I_C", static_variable_buf, &variable_len ) && static_variable_buf[0] ) { - strlcat( static_cons_buf, static_variable_buf, ISAPI_SERVER_VAR_BUF_SIZE ); - } - strlcat( static_cons_buf, "/ST=", ISAPI_SERVER_VAR_BUF_SIZE); - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_I_ST", static_variable_buf, &variable_len ) && static_variable_buf[0] ) { - strlcat( static_cons_buf, static_variable_buf, ISAPI_SERVER_VAR_BUF_SIZE ); - } - php_register_variable( "SSL_CLIENT_I_DN", static_cons_buf, track_vars_array ); -} - -static void sapi_isapi_register_zeus_variables(LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array) -{ - char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; - DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - DWORD scriptname_len = ISAPI_SERVER_VAR_BUF_SIZE; - DWORD pathinfo_len = 0; - char *strtok_buf = NULL; - - /* Get SCRIPT_NAME, we use this to work out which bit of the URL - * belongs in PHP's version of PATH_INFO - */ - lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_NAME", static_variable_buf, &scriptname_len); - - /* Adjust Zeus' version of PATH_INFO, set PHP_SELF, - * and generate REQUEST_URI - */ - if ( lpECB->GetServerVariable(lpECB->ConnID, "PATH_INFO", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - - /* PHP_SELF is just PATH_INFO */ - php_register_variable( "PHP_SELF", static_variable_buf, track_vars_array ); - - /* Chop off filename to get just the 'real' PATH_INFO' */ - pathinfo_len = variable_len - scriptname_len; - php_register_variable( "PATH_INFO", static_variable_buf + scriptname_len - 1, track_vars_array ); - /* append query string to give url... extra byte for '?' */ - if ( strlen(lpECB->lpszQueryString) + variable_len + 1 < ISAPI_SERVER_VAR_BUF_SIZE ) { - /* append query string only if it is present... */ - if ( strlen(lpECB->lpszQueryString) ) { - static_variable_buf[ variable_len - 1 ] = '?'; - strcpy( static_variable_buf + variable_len, lpECB->lpszQueryString ); - } - php_register_variable( "URL", static_variable_buf, track_vars_array ); - php_register_variable( "REQUEST_URI", static_variable_buf, track_vars_array ); - } - } - - /* Get and adjust PATH_TRANSLATED to what PHP wants */ - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if ( lpECB->GetServerVariable(lpECB->ConnID, "PATH_TRANSLATED", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - static_variable_buf[ variable_len - pathinfo_len - 1 ] = '\0'; - php_register_variable( "PATH_TRANSLATED", static_variable_buf, track_vars_array ); - } - - /* Bring in the AUTHENTICATION stuff as needed */ - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if ( lpECB->GetServerVariable(lpECB->ConnID, "AUTH_USER", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - php_register_variable( "PHP_AUTH_USER", static_variable_buf, track_vars_array ); - } - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if ( lpECB->GetServerVariable(lpECB->ConnID, "AUTH_PASSWORD", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - php_register_variable( "PHP_AUTH_PW", static_variable_buf, track_vars_array ); - } - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if ( lpECB->GetServerVariable(lpECB->ConnID, "AUTH_TYPE", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - php_register_variable( "AUTH_TYPE", static_variable_buf, track_vars_array ); - } - - /* And now, for the SSL variables (if applicable) */ - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if ( lpECB->GetServerVariable(lpECB->ConnID, "CERT_COOKIE", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - sapi_isapi_register_zeus_ssl_variables( lpECB, track_vars_array ); - } - /* Copy some of the variables we need to meet Apache specs */ - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if ( lpECB->GetServerVariable(lpECB->ConnID, "SERVER_SOFTWARE", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - php_register_variable( "SERVER_SIGNATURE", static_variable_buf, track_vars_array ); - } -} -#else - -static void sapi_isapi_register_iis_variables(LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array) -{ - char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; - char path_info_buf[ISAPI_SERVER_VAR_BUF_SIZE]; - DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - DWORD scriptname_len = ISAPI_SERVER_VAR_BUF_SIZE; - DWORD pathinfo_len = 0; - HSE_URL_MAPEX_INFO humi; - - /* Get SCRIPT_NAME, we use this to work out which bit of the URL - * belongs in PHP's version of PATH_INFO. SCRIPT_NAME also becomes PHP_SELF. - */ - lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_NAME", static_variable_buf, &scriptname_len); - php_register_variable("SCRIPT_FILENAME", SG(request_info).path_translated, track_vars_array); - - /* Adjust IIS' version of PATH_INFO, set PHP_SELF, - * and generate REQUEST_URI - * Get and adjust PATH_TRANSLATED to what PHP wants - */ - if ( lpECB->GetServerVariable(lpECB->ConnID, "PATH_INFO", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - - /* Chop off filename to get just the 'real' PATH_INFO' */ - php_register_variable( "ORIG_PATH_INFO", static_variable_buf, track_vars_array ); - pathinfo_len = variable_len - scriptname_len; - strncpy(path_info_buf, static_variable_buf + scriptname_len - 1, sizeof(path_info_buf)-1); - php_register_variable( "PATH_INFO", path_info_buf, track_vars_array ); - /* append query string to give url... extra byte for '?' */ - if ( strlen(lpECB->lpszQueryString) + variable_len + 1 < ISAPI_SERVER_VAR_BUF_SIZE ) { - /* append query string only if it is present... */ - if ( strlen(lpECB->lpszQueryString) ) { - static_variable_buf[ variable_len - 1 ] = '?'; - strcpy( static_variable_buf + variable_len, lpECB->lpszQueryString ); - } - php_register_variable( "URL", static_variable_buf, track_vars_array ); - php_register_variable( "REQUEST_URI", static_variable_buf, track_vars_array ); - } - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if ( lpECB->GetServerVariable(lpECB->ConnID, "PATH_TRANSLATED", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - php_register_variable( "ORIG_PATH_TRANSLATED", static_variable_buf, track_vars_array ); - } - if (lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_MAP_URL_TO_PATH_EX, path_info_buf, &pathinfo_len, (LPDWORD) &humi)) { - /* Remove trailing \ */ - if (humi.lpszPath[variable_len-2] == '\\') { - humi.lpszPath[variable_len-2] = 0; - } - php_register_variable("PATH_TRANSLATED", humi.lpszPath, track_vars_array); - } - } - - static_variable_buf[0] = '/'; - static_variable_buf[1] = 0; - variable_len = 2; - if (lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_MAP_URL_TO_PATH_EX, static_variable_buf, &variable_len, (LPDWORD) &humi)) { - /* Remove trailing \ */ - if (humi.lpszPath[variable_len-2] == '\\') { - humi.lpszPath[variable_len-2] = 0; - } - php_register_variable("DOCUMENT_ROOT", humi.lpszPath, track_vars_array); - } - - if (!SG(request_info).auth_user || !SG(request_info).auth_password || - !SG(request_info).auth_user[0] || !SG(request_info).auth_password[0]) { - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if (lpECB->GetServerVariable(lpECB->ConnID, "HTTP_AUTHORIZATION", static_variable_buf, &variable_len) - && static_variable_buf[0]) { - php_handle_auth_data(static_variable_buf); - } - } - - if (SG(request_info).auth_user) { - php_register_variable("PHP_AUTH_USER", SG(request_info).auth_user, track_vars_array ); - } - if (SG(request_info).auth_password) { - php_register_variable("PHP_AUTH_PW", SG(request_info).auth_password, track_vars_array ); - } -} -#endif - -static void sapi_isapi_register_server_variables2(char **server_variables, LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array, char **recorded_values) -{ - char **p=server_variables; - DWORD variable_len; - char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; - char *variable_buf; - - while (*p) { - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if (lpECB->GetServerVariable(lpECB->ConnID, *p, static_variable_buf, &variable_len) - && static_variable_buf[0]) { - php_register_variable(*p, static_variable_buf, track_vars_array); - if (recorded_values) { - recorded_values[p-server_variables] = estrndup(static_variable_buf, variable_len); - } - } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { - variable_buf = (char *) emalloc(variable_len+1); - if (lpECB->GetServerVariable(lpECB->ConnID, *p, variable_buf, &variable_len) - && variable_buf[0]) { - php_register_variable(*p, variable_buf, track_vars_array); - } - if (recorded_values) { - recorded_values[p-server_variables] = variable_buf; - } else { - efree(variable_buf); - } - } else { /* for compatibility with Apache SAPIs */ - php_register_variable(*p, "", track_vars_array); - } - p++; - } -} - - -static void sapi_isapi_register_server_variables(zval *track_vars_array) -{ - DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - char *variable; - char *strtok_buf = NULL; - char *isapi_special_server_variables[NUM_SPECIAL_VARS]; - LPEXTENSION_CONTROL_BLOCK lpECB; - - lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); - - /* Register the special ISAPI variables */ - memset(isapi_special_server_variables, 0, sizeof(isapi_special_server_variables)); - sapi_isapi_register_server_variables2(isapi_special_server_variable_names, lpECB, track_vars_array, isapi_special_server_variables); - if (SG(request_info).cookie_data) { - php_register_variable("HTTP_COOKIE", SG(request_info).cookie_data, track_vars_array); - } - - /* Register the standard ISAPI variables */ - sapi_isapi_register_server_variables2(isapi_server_variable_names, lpECB, track_vars_array, NULL); - - if (isapi_special_server_variables[SPECIAL_VAR_HTTPS] - && (atoi(isapi_special_server_variables[SPECIAL_VAR_HTTPS]) - || !strcasecmp(isapi_special_server_variables[SPECIAL_VAR_HTTPS], "on")) - ) { - /* Register SSL ISAPI variables */ - sapi_isapi_register_server_variables2(isapi_secure_server_variable_names, lpECB, track_vars_array, NULL); - } - - if (isapi_special_server_variables[SPECIAL_VAR_HTTPS]) { - efree(isapi_special_server_variables[SPECIAL_VAR_HTTPS]); - } - - -#ifdef WITH_ZEUS - sapi_isapi_register_zeus_variables(lpECB, track_vars_array); -#else - sapi_isapi_register_iis_variables(lpECB, track_vars_array); -#endif - - /* PHP_SELF support */ - if (isapi_special_server_variables[SPECIAL_VAR_PHP_SELF]) { - php_register_variable("PHP_SELF", isapi_special_server_variables[SPECIAL_VAR_PHP_SELF], track_vars_array); - efree(isapi_special_server_variables[SPECIAL_VAR_PHP_SELF]); - } - - if (isapi_special_server_variables[SPECIAL_VAR_ALL_HTTP]) { - /* Register the internal bits of ALL_HTTP */ - variable = php_strtok_r(isapi_special_server_variables[SPECIAL_VAR_ALL_HTTP], "\r\n", &strtok_buf); - while (variable) { - char *colon = strchr(variable, ':'); - - if (colon) { - char *value = colon+1; - - while (*value==' ') { - value++; - } - *colon = 0; - php_register_variable(variable, value, track_vars_array); - *colon = ':'; - } - variable = php_strtok_r(NULL, "\r\n", &strtok_buf); - } - efree(isapi_special_server_variables[SPECIAL_VAR_ALL_HTTP]); - } -} - - -static sapi_module_struct isapi_sapi_module = { - "isapi", /* name */ - "ISAPI", /* pretty name */ - - php_isapi_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - NULL, /* activate */ - NULL, /* deactivate */ - - sapi_isapi_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, /* error handler */ - - sapi_isapi_header_handler, /* header handler */ - sapi_isapi_send_headers, /* send headers handler */ - NULL, /* send header handler */ - - sapi_isapi_read_post, /* read POST data */ - sapi_isapi_read_cookies, /* read Cookies */ - - sapi_isapi_register_server_variables, /* register server variables */ - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - - -BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pFilterVersion) -{ - bFilterLoaded = 1; - pFilterVersion->dwFilterVersion = HTTP_FILTER_REVISION; - strcpy(pFilterVersion->lpszFilterDesc, isapi_sapi_module.pretty_name); - pFilterVersion->dwFlags= (SF_NOTIFY_AUTHENTICATION | SF_NOTIFY_PREPROC_HEADERS); - return TRUE; -} - - -DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD notificationType, LPVOID pvNotification) -{ - - switch (notificationType) { - case SF_NOTIFY_PREPROC_HEADERS: - SG(request_info).auth_user = NULL; - SG(request_info).auth_password = NULL; - SG(request_info).auth_digest = NULL; - break; - case SF_NOTIFY_AUTHENTICATION: { - char *auth_user = ((HTTP_FILTER_AUTHENT *) pvNotification)->pszUser; - char *auth_password = ((HTTP_FILTER_AUTHENT *) pvNotification)->pszPassword; - - if (auth_user && auth_user[0]) { - SG(request_info).auth_user = estrdup(auth_user); - } - if (auth_password && auth_password[0]) { - SG(request_info).auth_password = estrdup(auth_password); - } - return SF_STATUS_REQ_HANDLED_NOTIFICATION; - } - break; - } - return SF_STATUS_REQ_NEXT_NOTIFICATION; -} - - -static void init_request_info(LPEXTENSION_CONTROL_BLOCK lpECB) -{ - DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; -#ifndef WITH_ZEUS - HSE_URL_MAPEX_INFO humi; -#endif - - SG(request_info).request_method = lpECB->lpszMethod; - SG(request_info).query_string = lpECB->lpszQueryString; - SG(request_info).request_uri = lpECB->lpszPathInfo; - SG(request_info).content_type = lpECB->lpszContentType; - SG(request_info).content_length = lpECB->cbTotalBytes; - SG(sapi_headers).http_response_code = 200; /* I think dwHttpStatusCode is invalid at this stage -RL */ - if (!bFilterLoaded) { /* we don't have valid ISAPI Filter information */ - SG(request_info).auth_user = SG(request_info).auth_password = SG(request_info).auth_digest = NULL; - } - -#ifdef WITH_ZEUS - /* PATH_TRANSLATED can contain extra PATH_INFO stuff after the - * file being loaded, so we must use SCRIPT_FILENAME instead - */ - if(lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_FILENAME", static_variable_buf, &variable_len)) { - SG(request_info).path_translated = estrdup(static_variable_buf); - } else -#else - /* happily, IIS gives us SCRIPT_NAME which is correct (without PATH_INFO stuff) - so we can just map that to the physical path and we have our filename */ - - lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_NAME", static_variable_buf, &variable_len); - if (lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_MAP_URL_TO_PATH_EX, static_variable_buf, &variable_len, (LPDWORD) &humi)) { - SG(request_info).path_translated = estrdup(humi.lpszPath); - } else -#endif - /* if mapping fails, default to what the server tells us */ - SG(request_info).path_translated = estrdup(lpECB->lpszPathTranslated); - - /* some server configurations allow '..' to slip through in the - translated path. We'll just refuse to handle such a path. */ - if (strstr(SG(request_info).path_translated,"..")) { - SG(sapi_headers).http_response_code = 404; - efree(SG(request_info).path_translated); - SG(request_info).path_translated = NULL; - } -} - - -static void php_isapi_report_exception(char *message, int message_len) -{ - if (!SG(headers_sent)) { - HSE_SEND_HEADER_EX_INFO header_info; - LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); - - header_info.pszStatus = "500 Internal Server Error"; - header_info.cchStatus = strlen(header_info.pszStatus); - header_info.pszHeader = "Content-Type: text/html\r\n\r\n"; - header_info.cchHeader = strlen(header_info.pszHeader); - - lpECB->dwHttpStatusCode = 500; - lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); - SG(headers_sent)=1; - } - sapi_isapi_ub_write(message, message_len); -} - - -BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer) -{ - pVer->dwExtensionVersion = HSE_VERSION; -#ifdef WITH_ZEUS - strncpy( pVer->lpszExtensionDesc, isapi_sapi_module.name, HSE_MAX_EXT_DLL_NAME_LEN); -#else - lstrcpyn(pVer->lpszExtensionDesc, isapi_sapi_module.name, HSE_MAX_EXT_DLL_NAME_LEN); -#endif - return TRUE; -} - - -static void my_endthread() -{ -#ifdef PHP_WIN32 - if (bTerminateThreadsOnError) { - _endthread(); - } -#endif -} - -#ifdef PHP_WIN32 -/* ep is accessible only in the context of the __except expression, - * so we have to call this function to obtain it. - */ -BOOL exceptionhandler(LPEXCEPTION_POINTERS *e, LPEXCEPTION_POINTERS ep) -{ - *e=ep; - return TRUE; -} -#endif - -DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) -{ - zend_file_handle file_handle; - zend_bool stack_overflown=0; - int retval = FAILURE; -#ifdef PHP_ENABLE_SEH - LPEXCEPTION_POINTERS e; -#endif - - zend_first_try { -#ifdef PHP_ENABLE_SEH - __try { -#endif - init_request_info(lpECB); - SG(server_context) = lpECB; - - php_request_startup(); - - file_handle.filename = SG(request_info).path_translated; - file_handle.free_filename = 0; - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.opened_path = NULL; - - /* open the script here so we can 404 if it fails */ - if (file_handle.filename) - retval = php_fopen_primary_script(&file_handle); - - if (!file_handle.filename || retval == FAILURE) { - SG(sapi_headers).http_response_code = 404; - PUTS("No input file specified.\n"); - } else { - php_execute_script(&file_handle); - } - - if (SG(request_info).cookie_data) { - efree(SG(request_info).cookie_data); - } - if (SG(request_info).path_translated) - efree(SG(request_info).path_translated); -#ifdef PHP_ENABLE_SEH - } __except(exceptionhandler(&e, GetExceptionInformation())) { - char buf[1024]; - if (_exception_code()==EXCEPTION_STACK_OVERFLOW) { - LPBYTE lpPage; - static SYSTEM_INFO si; - static MEMORY_BASIC_INFORMATION mi; - static DWORD dwOldProtect; - - GetSystemInfo(&si); - - /* Get page ESP is pointing to */ - _asm mov lpPage, esp; - - /* Get stack allocation base */ - VirtualQuery(lpPage, &mi, sizeof(mi)); - - /* Go to the page below the current page */ - lpPage = (LPBYTE) (mi.BaseAddress) - si.dwPageSize; - - /* Free pages below current page */ - if (!VirtualFree(mi.AllocationBase, (LPBYTE)lpPage - (LPBYTE) mi.AllocationBase, MEM_DECOMMIT)) { - _endthread(); - } - - /* Restore the guard page */ - if (!VirtualProtect(lpPage, si.dwPageSize, PAGE_GUARD | PAGE_READWRITE, &dwOldProtect)) { - _endthread(); - } - - CG(unclean_shutdown)=1; - _snprintf(buf, sizeof(buf)-1,"PHP has encountered a Stack overflow"); - php_isapi_report_exception(buf, strlen(buf)); - } else if (_exception_code()==EXCEPTION_ACCESS_VIOLATION) { - _snprintf(buf, sizeof(buf)-1,"PHP has encountered an Access Violation at %p", e->ExceptionRecord->ExceptionAddress); - php_isapi_report_exception(buf, strlen(buf)); - my_endthread(); - } else { - _snprintf(buf, sizeof(buf)-1,"PHP has encountered an Unhandled Exception Code %d at %p", e->ExceptionRecord->ExceptionCode , e->ExceptionRecord->ExceptionAddress); - php_isapi_report_exception(buf, strlen(buf)); - my_endthread(); - } - } -#endif -#ifdef PHP_ENABLE_SEH - __try { - php_request_shutdown(NULL); - } __except(EXCEPTION_EXECUTE_HANDLER) { - my_endthread(); - } -#else - php_request_shutdown(NULL); -#endif - } zend_catch { - zend_try { - php_request_shutdown(NULL); - } zend_end_try(); - return HSE_STATUS_ERROR; - } zend_end_try(); - - return HSE_STATUS_SUCCESS; -} - - - -__declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) -{ - switch (fdwReason) { - case DLL_PROCESS_ATTACH: -#ifdef WITH_ZEUS - tsrm_startup(128, 1, TSRM_ERROR_LEVEL_CORE, "TSRM.log"); -#else - tsrm_startup(128, 1, TSRM_ERROR_LEVEL_CORE, "C:\\TSRM.log"); -#endif - sapi_startup(&isapi_sapi_module); - if (isapi_sapi_module.startup) { - isapi_sapi_module.startup(&sapi_module); - } - break; - case DLL_THREAD_ATTACH: - break; - case DLL_THREAD_DETACH: - ts_free_thread(); - break; - case DLL_PROCESS_DETACH: - if (isapi_sapi_module.shutdown) { - isapi_sapi_module.shutdown(&sapi_module); - } - sapi_shutdown(); - tsrm_shutdown(); - break; - } - return TRUE; -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/sapi/isapi/php7isapi.def b/sapi/isapi/php7isapi.def deleted file mode 100644 index 596023ef55..0000000000 --- a/sapi/isapi/php7isapi.def +++ /dev/null @@ -1,5 +0,0 @@ -EXPORTS -HttpFilterProc -GetFilterVersion -HttpExtensionProc -GetExtensionVersion diff --git a/sapi/isapi/stresstest/getopt.c b/sapi/isapi/stresstest/getopt.c deleted file mode 100644 index 21056bf883..0000000000 --- a/sapi/isapi/stresstest/getopt.c +++ /dev/null @@ -1,175 +0,0 @@ -/* Borrowed from Apache NT Port */ - -#include <stdio.h> -#include <string.h> -#include <assert.h> -#include <stdlib.h> -#include "getopt.h" -#define OPTERRCOLON (1) -#define OPTERRNF (2) -#define OPTERRARG (3) - - -char *ap_optarg; -int ap_optind = 1; -static int ap_opterr = 1; -static int ap_optopt; - -static int -ap_optiserr(int argc, char * const *argv, int oint, const char *optstr, - int optchr, int err) -{ - if (ap_opterr) - { - 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; - } - } - ap_optopt = argv[oint][optchr]; - return('?'); -} - -int ap_getopt(int argc, char* const *argv, const char *optstr) -{ - static int optchr = 0; - static int dash = 0; /* have already seen the - */ - - char *cp; - - if (ap_optind >= argc) - return(EOF); - if (!dash && (argv[ap_optind][0] != '-')) - return(EOF); - if (!dash && (argv[ap_optind][0] == '-') && !argv[ap_optind][1]) - { - /* - * use to specify stdin. Need to let pgm process this and - * the following args - */ - return(EOF); - } - if ((argv[ap_optind][0] == '-') && (argv[ap_optind][1] == '-')) - { - /* -- indicates end of args */ - ap_optind++; - return(EOF); - } - if (!dash) - { - assert((argv[ap_optind][0] == '-') && argv[ap_optind][1]); - dash = 1; - optchr = 1; - } - - /* Check if the guy tries to do a -: kind of flag */ - assert(dash); - if (argv[ap_optind][optchr] == ':') - { - dash = 0; - ap_optind++; - return(ap_optiserr(argc, argv, ap_optind-1, optstr, optchr, OPTERRCOLON)); - } - if (!(cp = strchr(optstr, argv[ap_optind][optchr]))) - { - int errind = ap_optind; - int errchr = optchr; - - if (!argv[ap_optind][optchr+1]) - { - dash = 0; - ap_optind++; - } - else - optchr++; - return(ap_optiserr(argc, argv, errind, optstr, errchr, OPTERRNF)); - } - if (cp[1] == ':') - { - /* 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[ap_optind][2]) { - ap_optind++; - if (ap_optind == argc) - return(ap_optiserr(argc, argv, ap_optind-1, optstr, optchr, OPTERRARG)); - ap_optarg = argv[ap_optind++]; - } - else - { - ap_optarg = &argv[ap_optind][2]; - ap_optind++; - } - return(*cp); - } - else - { - if (!argv[ap_optind][optchr+1]) - { - dash = 0; - ap_optind++; - } - else - optchr++; - return(*cp); - } - assert(0); - return(0); -} - -#ifdef TESTGETOPT -int - main (int argc, char **argv) - { - int c; - extern char *ap_optarg; - extern int ap_optind; - int aflg = 0; - int bflg = 0; - int errflg = 0; - char *ofile = NULL; - - while ((c = ap_getopt(argc, argv, "abo:")) != EOF) - switch (c) { - case 'a': - if (bflg) - errflg++; - else - aflg++; - break; - case 'b': - if (aflg) - errflg++; - else - bflg++; - break; - case 'o': - ofile = ap_optarg; - (void)printf("ofile = %s\n", ofile); - break; - case '?': - errflg++; - } - if (errflg) { - (void)fprintf(stderr, - "usage: cmd [-a|-b] [-o <filename>] files...\n"); - exit (2); - } - for ( ; ap_optind < argc; ap_optind++) - (void)printf("%s\n", argv[ap_optind]); - return 0; - } - -#endif /* TESTGETOPT */ diff --git a/sapi/isapi/stresstest/getopt.h b/sapi/isapi/stresstest/getopt.h deleted file mode 100644 index 6d4139bfe0..0000000000 --- a/sapi/isapi/stresstest/getopt.h +++ /dev/null @@ -1,12 +0,0 @@ -/* Borrowed from Apache NT Port */ -#ifdef __cplusplus -extern "C" { -#endif -extern char *ap_optarg; -extern int ap_optind; - -int ap_getopt(int argc, char* const *argv, const char *optstr); - -#ifdef __cplusplus -} -#endif diff --git a/sapi/isapi/stresstest/notes.txt b/sapi/isapi/stresstest/notes.txt deleted file mode 100644 index e6d10dd486..0000000000 --- a/sapi/isapi/stresstest/notes.txt +++ /dev/null @@ -1,56 +0,0 @@ -This stress test program is for debugging threading issues with the ISAPI -module. - -2 ways to use it: - -1: test any php script file on multiple threads -2: run the php test scripts bundled with the source code - - - -GLOBAL SETTINGS -=============== - -If you need to set special environement variables, in addition to your -regular environment, create a file that contains them, one setting per line: - -MY_ENV_VAR=XXXXXXXX - -This can be used to simulate ISAPI environment variables if need be. - -By default, stress test uses 10 threads. To change this, change the define -NUM_THREADS in stresstest.cpp. - - - -1: Test any php script file on multiple threads -=============================================== - -Create a file that contains a list of php script files, one per line. If -you need to provide input, place the GET data, or Query String, after the -filename. File contents would look like: - -e:\inetpub\pages\index.php -e:\inetpub\pages\info.php -e:\inetpub\pages\test.php a=1&b=2 - -Run: stresstest L files.txt - - - -2: Run the php test scripts bundled with the source code -======================================================== - -supply the path to the parent of the "tests" directory (expect a couple -long pauses for a couple of the larger tests) - -Run: stresstest T c:\php7-source - - - -TODO: - -* Make more options configurable: number of threads, iterations, etc. -* Improve stdout output to make it more useful -* Implement support for SKIPIF -* Improve speed of CompareFile function (too slow on big files). diff --git a/sapi/isapi/stresstest/stresstest.cpp b/sapi/isapi/stresstest/stresstest.cpp deleted file mode 100644 index ddb06473c2..0000000000 --- a/sapi/isapi/stresstest/stresstest.cpp +++ /dev/null @@ -1,936 +0,0 @@ -/* - * ======================================================================= * - * File: stress .c * - * stress tester for isapi dll's * - * based on cgiwrap * - * ======================================================================= * - * -*/ -#define WIN32_LEAN_AND_MEAN -#include <afx.h> -#include <afxtempl.h> -#include <winbase.h> -#include <winerror.h> -#include <httpext.h> -#include <stdio.h> -#include <stdlib.h> -#include "getopt.h" - -// These are things that go out in the Response Header -// -#define HTTP_VER "HTTP/1.0" -#define SERVER_VERSION "Http-Srv-Beta2/1.0" - -// -// Simple wrappers for the heap APIS -// -#define xmalloc(s) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (s)) -#define xfree(s) HeapFree(GetProcessHeap(), 0, (s)) - -// -// The mandatory exports from the ISAPI DLL -// -DWORD numThreads = 1; -DWORD iterations = 1; - -HANDLE StartNow; -// quick and dirty environment -typedef CMapStringToString TEnvironment; -TEnvironment IsapiEnvironment; - -typedef struct _TResults { - LONG ok; - LONG bad; -} TResults; - -CStringArray IsapiFileList; // list of filenames -CStringArray TestNames; // --TEST-- -CStringArray IsapiGetData; // --GET-- -CStringArray IsapiPostData; // --POST-- -CStringArray IsapiMatchData; // --EXPECT-- -CArray<TResults, TResults> Results; - -typedef struct _TIsapiContext { - HANDLE in; - HANDLE out; - DWORD tid; - TEnvironment env; - HANDLE waitEvent; -} TIsapiContext; - -// -// Prototypes of the functions this sample implements -// -extern "C" { -HINSTANCE hDll; -typedef BOOL (WINAPI *VersionProc)(HSE_VERSION_INFO *) ; -typedef DWORD (WINAPI *HttpExtProc)(EXTENSION_CONTROL_BLOCK *); -typedef BOOL (WINAPI *TerminateProc) (DWORD); -BOOL WINAPI FillExtensionControlBlock(EXTENSION_CONTROL_BLOCK *, TIsapiContext *) ; -BOOL WINAPI GetServerVariable(HCONN, LPSTR, LPVOID, LPDWORD ); -BOOL WINAPI ReadClient(HCONN, LPVOID, LPDWORD); -BOOL WINAPI WriteClient(HCONN, LPVOID, LPDWORD, DWORD); -BOOL WINAPI ServerSupportFunction(HCONN, DWORD, LPVOID, LPDWORD, LPDWORD); -VersionProc IsapiGetExtensionVersion; -HttpExtProc IsapiHttpExtensionProc; -TerminateProc TerminateExtensionProc; -HSE_VERSION_INFO version_info; -} - -char * MakeDateStr(VOID); -char * GetEnv(char *); - - - - -DWORD CALLBACK IsapiThread(void *); -int stress_main(const char *filename, - const char *arg, - const char *postfile, - const char *matchdata); - - - -BOOL bUseTestFiles = FALSE; -char temppath[MAX_PATH]; - -void stripcrlf(char *line) -{ - DWORD l = strlen(line)-1; - if (line[l]==10 || line[l]==13) line[l]=0; - l = strlen(line)-1; - if (line[l]==10 || line[l]==13) line[l]=0; -} - -#define COMPARE_BUF_SIZE 1024 - -BOOL CompareFiles(const char*f1, const char*f2) -{ - FILE *fp1, *fp2; - bool retval; - char buf1[COMPARE_BUF_SIZE], buf2[COMPARE_BUF_SIZE]; - int length1, length2; - - if ((fp1=fopen(f1, "r"))==NULL) { - return FALSE; - } - - if ((fp2=fopen(f2, "r"))==NULL) { - fclose(fp1); - return FALSE; - } - - retval = TRUE; // success oriented - while (true) { - length1 = fread(buf1, 1, sizeof(buf1), fp1); - length2 = fread(buf2, 1, sizeof(buf2), fp2); - - // check for end of file - if (feof(fp1)) { - if (!feof(fp2)) { - retval = FALSE; - } - break; - } else if (feof(fp2)) { - if (!feof(fp1)) { - retval = FALSE; - } - break; - } - - // compare data - if (length1!=length2 - || memcmp(buf1, buf2, length1)!=0) { - retval = FALSE; - break; - } - } - fclose(fp1); - fclose(fp2); - - return retval; -} - - -BOOL CompareStringWithFile(const char *filename, const char *str, unsigned int str_length) -{ - FILE *fp; - bool retval; - char buf[COMPARE_BUF_SIZE]; - unsigned int offset=0, readbytes; - fprintf(stderr, "test %s\n",filename); - if ((fp=fopen(filename, "rb"))==NULL) { - fprintf(stderr, "Error opening %s\n",filename); - return FALSE; - } - - retval = TRUE; // success oriented - while (true) { - readbytes = fread(buf, 1, sizeof(buf), fp); - - // check for end of file - - if (offset+readbytes > str_length - || memcmp(buf, str+offset, readbytes)!=NULL) { - fprintf(stderr, "File missmatch %s\n",filename); - retval = FALSE; - break; - } - if (feof(fp)) { - if (!retval) fprintf(stderr, "File zero length %s\n",filename); - break; - } - } - fclose(fp); - - return retval; -} - - -BOOL ReadGlobalEnvironment(const char *environment) -{ - if (environment) { - FILE *fp = fopen(environment, "r"); - DWORD i=0; - if (fp) { - char line[2048]; - while (fgets(line, sizeof(line)-1, fp)) { - // file.php arg1 arg2 etc. - char *p = strchr(line, '='); - if (p) { - *p=0; - IsapiEnvironment[line]=p+1; - } - } - fclose(fp); - return IsapiEnvironment.GetCount() > 0; - } - } - return FALSE; -} - -BOOL ReadFileList(const char *filelist) -{ - FILE *fp = fopen(filelist, "r"); - if (!fp) { - printf("Unable to open %s\r\n", filelist); - } - char line[2048]; - int i=0; - while (fgets(line, sizeof(line)-1, fp)) { - // file.php arg1 arg2 etc. - stripcrlf(line); - if (strlen(line)>3) { - char *p = strchr(line, ' '); - if (p) { - *p = 0; - // get file - - IsapiFileList.Add(line); - IsapiGetData.Add(p+1); - } else { - // just a filename is all - IsapiFileList.Add(line); - IsapiGetData.Add(""); - } - } - - // future use - IsapiPostData.Add(""); - IsapiMatchData.Add(""); - TestNames.Add(""); - - i++; - } - Results.SetSize(TestNames.GetSize()); - - fclose(fp); - return IsapiFileList.GetSize() > 0; -} - -void DoThreads() { - - if (IsapiFileList.GetSize() == 0) { - printf("No Files to test\n"); - return; - } - - printf("Starting Threads...\n"); - // loop creating threads - DWORD tid; - HANDLE *threads = new HANDLE[numThreads]; - DWORD i; - for (i=0; i< numThreads; i++) { - threads[i]=CreateThread(NULL, 0, IsapiThread, NULL, CREATE_SUSPENDED, &tid); - } - for (i=0; i< numThreads; i++) { - if (threads[i]) ResumeThread(threads[i]); - } - // wait for threads to finish - WaitForMultipleObjects(numThreads, threads, TRUE, INFINITE); - for (i=0; i< numThreads; i++) { - CloseHandle(threads[i]); - } - delete [] threads; -} - -void DoFileList(const char *filelist, const char *environment) -{ - // read config files - - if (!ReadFileList(filelist)) { - printf("No Files to test!\r\n"); - return; - } - - ReadGlobalEnvironment(environment); - - DoThreads(); -} - - -/** - * ParseTestFile - * parse a single phpt file and add it to the arrays - */ -BOOL ParseTestFile(const char *path, const char *fn) -{ - // parse the test file - char filename[MAX_PATH]; - _snprintf(filename, sizeof(filename)-1, "%s\\%s", path, fn); - char line[1024]; - memset(line, 0, sizeof(line)); - CString cTest, cSkipIf, cPost, cGet, cFile, cExpect; - printf("Reading %s\r\n", filename); - - enum state {none, test, skipif, post, get, file, expect} parsestate = none; - - FILE *fp = fopen(filename, "rb"); - char *tn = _tempnam(temppath,"pht."); - char *en = _tempnam(temppath,"exp."); - FILE *ft = fopen(tn, "wb+"); - FILE *fe = fopen(en, "wb+"); - if (fp && ft && fe) { - while (fgets(line, sizeof(line)-1, fp)) { - if (line[0]=='-') { - if (_strnicmp(line, "--TEST--", 8)==0) { - parsestate = test; - continue; - } else if (_strnicmp(line, "--SKIPIF--", 10)==0) { - parsestate = skipif; - continue; - } else if (_strnicmp(line, "--POST--", 8)==0) { - parsestate = post; - continue; - } else if (_strnicmp(line, "--GET--", 7)==0) { - parsestate = get; - continue; - } else if (_strnicmp(line, "--FILE--", 8)==0) { - parsestate = file; - continue; - } else if (_strnicmp(line, "--EXPECT--", 10)==0) { - parsestate = expect; - continue; - } - } - switch (parsestate) { - case test: - stripcrlf(line); - cTest = line; - break; - case skipif: - cSkipIf += line; - break; - case post: - cPost += line; - break; - case get: - cGet += line; - break; - case file: - fputs(line, ft); - break; - case expect: - fputs(line, fe); - break; - } - } - - fclose(fp); - fclose(ft); - fclose(fe); - - if (!cTest.IsEmpty()) { - IsapiFileList.Add(tn); - TestNames.Add(cTest); - IsapiGetData.Add(cGet); - IsapiPostData.Add(cPost); - IsapiMatchData.Add(en); - free(tn); - free(en); - return TRUE; - } - } - free(tn); - free(en); - return FALSE; -} - - -/** - * GetTestFiles - * Recurse through the path and subdirectories, parse each phpt file - */ -BOOL GetTestFiles(const char *path) -{ - // find all files .phpt under testpath\tests - char FindPath[MAX_PATH]; - WIN32_FIND_DATA fd; - memset(&fd, 0, sizeof(WIN32_FIND_DATA)); - - _snprintf(FindPath, sizeof(FindPath)-1, "%s\\*.*", path); - HANDLE fh = FindFirstFile(FindPath, &fd); - if (fh != INVALID_HANDLE_VALUE) { - do { - if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && - !strchr(fd.cFileName, '.')) { - // subdirectory, recurse into it - char NewFindPath[MAX_PATH]; - _snprintf(NewFindPath, sizeof(NewFindPath)-1, "%s\\%s", path, fd.cFileName); - GetTestFiles(NewFindPath); - } else if (strstr(fd.cFileName, ".phpt")) { - // got test file, parse it now - if (ParseTestFile(path, fd.cFileName)) { - printf("Test File Added: %s\\%s\r\n", path, fd.cFileName); - } - } - memset(&fd, 0, sizeof(WIN32_FIND_DATA)); - } while (FindNextFile(fh, &fd) != 0); - FindClose(fh); - } - return IsapiFileList.GetSize() > 0; -} - -void DeleteTempFiles(const char *mask) -{ - char FindPath[MAX_PATH]; - WIN32_FIND_DATA fd; - memset(&fd, 0, sizeof(WIN32_FIND_DATA)); - - _snprintf(FindPath, sizeof(FindPath)-1, "%s\\%s", temppath, mask); - HANDLE fh = FindFirstFile(FindPath, &fd); - if (fh != INVALID_HANDLE_VALUE) { - do { - char NewFindPath[MAX_PATH]; - _snprintf(NewFindPath, sizeof(NewFindPath)-1, "%s\\%s", temppath, fd.cFileName); - DeleteFile(NewFindPath); - memset(&fd, 0, sizeof(WIN32_FIND_DATA)); - } while (FindNextFile(fh, &fd) != 0); - FindClose(fh); - } -} - -void DoTestFiles(const char *filelist, const char *environment) -{ - if (!GetTestFiles(filelist)) { - printf("No Files to test!\r\n"); - return; - } - - Results.SetSize(IsapiFileList.GetSize()); - - ReadGlobalEnvironment(environment); - - DoThreads(); - - printf("\r\nRESULTS:\r\n"); - // show results: - DWORD r = Results.GetSize(); - for (DWORD i=0; i< r; i++) { - TResults result = Results.GetAt(i); - printf("%s\r\nOK: %d FAILED: %d\r\n", TestNames.GetAt(i), result.ok, result.bad); - } - - // delete temp files - printf("Deleting Temp Files\r\n"); - DeleteTempFiles("exp.*"); - DeleteTempFiles("pht.*"); - printf("Done\r\n"); -} - -#define OPTSTRING "m:f:d:h:t:i:" -static void _usage(char *argv0) -{ - char *prog; - - prog = strrchr(argv0, '/'); - if (prog) { - prog++; - } else { - prog = "stresstest"; - } - - printf("Usage: %s -m <isapi.dll> -d|-l <file> [-t <numthreads>] [-i <numiterations>]\n" - " -m path to isapi dll\n" - " -d <directory> php directory (to run php test files).\n" - " -f <file> file containing list of files to run\n" - " -t number of threads to use (default=1)\n" - " -i number of iterations per thread (default=1)\n" - " -h This help\n", prog); -} -int main(int argc, char* argv[]) -{ - LPVOID lpMsgBuf; - char *filelist=NULL, *environment=NULL, *module=NULL; - int c = NULL; - while ((c=ap_getopt(argc, argv, OPTSTRING))!=-1) { - switch (c) { - case 'd': - bUseTestFiles = TRUE; - filelist = strdup(ap_optarg); - break; - case 'f': - bUseTestFiles = FALSE; - filelist = strdup(ap_optarg); - break; - case 'e': - environment = strdup(ap_optarg); - break; - case 't': - numThreads = atoi(ap_optarg); - break; - case 'i': - iterations = atoi(ap_optarg); - break; - case 'm': - module = strdup(ap_optarg); - break; - case 'h': - _usage(argv[0]); - exit(0); - break; - } - } - if (!module || !filelist) { - _usage(argv[0]); - exit(0); - } - - GetTempPath(sizeof(temppath), temppath); - hDll = LoadLibrary(module); // Load our DLL - - if (!hDll) { - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &lpMsgBuf, - 0, - NULL - ); - fprintf(stderr,"Error: Dll 'php7isapi.dll' not found -%d\n%s\n", GetLastError(), lpMsgBuf); - free (module); - free(filelist); - LocalFree( lpMsgBuf ); - return -1; - } - - // - // Find the exported functions - - IsapiGetExtensionVersion = (VersionProc)GetProcAddress(hDll,"GetExtensionVersion"); - if (!IsapiGetExtensionVersion) { - fprintf(stderr,"Can't Get Extension Version %d\n", GetLastError()); - free (module); - free(filelist); - return -1; - } - IsapiHttpExtensionProc = (HttpExtProc)GetProcAddress(hDll,"HttpExtensionProc"); - if (!IsapiHttpExtensionProc) { - fprintf(stderr,"Can't Get Extension proc %d\n", GetLastError()); - free (module); - free(filelist); - return -1; - } - TerminateExtensionProc = (TerminateProc) GetProcAddress(hDll, - "TerminateExtension"); - - // This should really check if the version information matches what we - // expect. - // - if (!IsapiGetExtensionVersion(&version_info) ) { - fprintf(stderr,"Fatal: GetExtensionVersion failed\n"); - free (module); - free(filelist); - return -1; - } - - if (bUseTestFiles) { - char TestPath[MAX_PATH]; - if (filelist != NULL) - _snprintf(TestPath, sizeof(TestPath)-1, "%s\\tests", filelist); - else strcpy(TestPath, "tests"); - DoTestFiles(TestPath, environment); - } else { - DoFileList(filelist, environment); - } - - // cleanup - if (TerminateExtensionProc) TerminateExtensionProc(0); - - // We should really free memory (e.g., from GetEnv), but we'll be dead - // soon enough - - FreeLibrary(hDll); - free (module); - free(filelist); - return 0; -} - - -DWORD CALLBACK IsapiThread(void *p) -{ - DWORD filecount = IsapiFileList.GetSize(); - - for (DWORD j=0; j<iterations; j++) { - for (DWORD i=0; i<filecount; i++) { - // execute each file - CString testname = TestNames.GetAt(i); - BOOL ok = FALSE; - if (stress_main(IsapiFileList.GetAt(i), - IsapiGetData.GetAt(i), - IsapiPostData.GetAt(i), - IsapiMatchData.GetAt(i))) { - InterlockedIncrement(&Results[i].ok); - ok = TRUE; - } else { - InterlockedIncrement(&Results[i].bad); - ok = FALSE; - } - - if (testname.IsEmpty()) { - printf("Thread %d File %s\n", GetCurrentThreadId(), IsapiFileList.GetAt(i)); - } else { - printf("tid %d: %s %s\n", GetCurrentThreadId(), testname, ok?"OK":"FAIL"); - } - Sleep(10); - } - } - printf("Thread ending...\n"); - return 0; -} - -/* - * ======================================================================= * - * In the startup of this program, we look at our executable name and * - * replace the ".EXE" with ".DLL" to find the ISAPI DLL we need to load. * - * This means that the executable need only be given the same "name" as * - * the DLL to load. There is no recompilation required. * - * ======================================================================= * -*/ -BOOL stress_main(const char *filename, - const char *arg, - const char *postdata, - const char *matchdata) -{ - - EXTENSION_CONTROL_BLOCK ECB; - DWORD rc; - TIsapiContext context; - - // open output and input files - context.tid = GetCurrentThreadId(); - CString fname; - fname.Format("%08X.out", context.tid); - - context.out = CreateFile(fname, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL); - if (context.out==INVALID_HANDLE_VALUE) { - printf("failed to open output file %s\n", fname); - return 0; - } - - // not using post files - context.in = INVALID_HANDLE_VALUE; - - // - // Fill the ECB with the necessary information - // - if (!FillExtensionControlBlock(&ECB, &context) ) { - fprintf(stderr,"Fill Ext Block Failed\n"); - return -1; - } - - // check for command line argument, - // first arg = filename - // this is added for testing php from command line - - context.env.RemoveAll(); - context.env["PATH_TRANSLATED"]= filename; - context.env["SCRIPT_MAP"]= filename; - context.env["CONTENT_TYPE"]= ""; - context.env["CONTENT_LENGTH"]= ""; - context.env["QUERY_STRING"]= arg; - context.env["METHOD"]="GET"; - context.env["PATH_INFO"] = ""; - context.waitEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - char buf[MAX_PATH]; - if (postdata && *postdata !=0) { - ECB.cbAvailable = strlen(postdata); - ECB.cbTotalBytes = ECB.cbAvailable; - ECB.lpbData = (unsigned char *)postdata; - context.env["METHOD"]="POST"; - - _snprintf(buf, sizeof(buf)-1, "%d", ECB.cbTotalBytes); - context.env["CONTENT_LENGTH"]=buf; - - context.env["CONTENT_TYPE"]="application/x-www-form-urlencoded"; - } - ECB.lpszMethod = strdup(context.env["METHOD"]); - ECB.lpszPathTranslated = strdup(filename); - ECB.lpszQueryString = strdup(arg); - ECB.lpszPathInfo = strdup(context.env["PATH_INFO"]); - - - // Call the DLL - // - rc = IsapiHttpExtensionProc(&ECB); - if (rc == HSE_STATUS_PENDING) { - // We will exit in ServerSupportFunction - WaitForSingleObject(context.waitEvent, INFINITE); - } - CloseHandle(context.waitEvent); - //Sleep(75); - free(ECB.lpszPathTranslated); - free(ECB.lpszQueryString); - free(ECB.lpszMethod); - free(ECB.lpszPathInfo); - - BOOL ok = TRUE; - - if (context.out != INVALID_HANDLE_VALUE) CloseHandle(context.out); - - // compare the output with the EXPECT section - if (matchdata && *matchdata != 0) { - ok = CompareFiles(fname, matchdata); - } - - DeleteFile(fname); - - return ok; - -} -// -// GetServerVariable() is how the DLL calls the main program to figure out -// the environment variables it needs. This is a required function. -// -BOOL WINAPI GetServerVariable(HCONN hConn, LPSTR lpszVariableName, - LPVOID lpBuffer, LPDWORD lpdwSize){ - - DWORD rc; - CString value; - TIsapiContext *c = (TIsapiContext *)hConn; - if (!c) return FALSE; - - if (IsapiEnvironment.Lookup(lpszVariableName, value)) { - rc = value.GetLength(); - strncpy((char *)lpBuffer, value, *lpdwSize-1); - } else if (c->env.Lookup(lpszVariableName, value)) { - rc = value.GetLength(); - strncpy((char *)lpBuffer, value, *lpdwSize-1); - } else - rc = GetEnvironmentVariable(lpszVariableName, (char *)lpBuffer, *lpdwSize) ; - - if (!rc) { // return of 0 indicates the variable was not found - SetLastError(ERROR_NO_DATA); - return FALSE; - } - - if (rc > *lpdwSize) { - SetLastError(ERROR_INSUFFICIENT_BUFFER); - return FALSE; - } - - *lpdwSize =rc + 1 ; // GetEnvironmentVariable does not count the NULL - - return TRUE; - -} -// -// Again, we don't have an HCONN, so we simply wrap ReadClient() to -// ReadFile on stdin. The semantics of the two functions are the same -// -BOOL WINAPI ReadClient(HCONN hConn, LPVOID lpBuffer, LPDWORD lpdwSize) { - TIsapiContext *c = (TIsapiContext *)hConn; - if (!c) return FALSE; - - if (c->in != INVALID_HANDLE_VALUE) - return ReadFile(c->in, lpBuffer, (*lpdwSize), lpdwSize, NULL); - - return FALSE; -} -// -// ditto for WriteClient() -// -BOOL WINAPI WriteClient(HCONN hConn, LPVOID lpBuffer, LPDWORD lpdwSize, - DWORD dwReserved) { - TIsapiContext *c = (TIsapiContext *)hConn; - if (!c) return FALSE; - - if (c->out != INVALID_HANDLE_VALUE) - return WriteFile(c->out, lpBuffer, *lpdwSize, lpdwSize, NULL); - return FALSE; -} -// -// This is a special callback function used by the DLL for certain extra -// functionality. Look at the API help for details. -// -BOOL WINAPI ServerSupportFunction(HCONN hConn, DWORD dwHSERequest, - LPVOID lpvBuffer, LPDWORD lpdwSize, LPDWORD lpdwDataType){ - - TIsapiContext *c = (TIsapiContext *)hConn; - char *lpszRespBuf; - char * temp = NULL; - DWORD dwBytes; - BOOL bRet = TRUE; - - switch(dwHSERequest) { - case (HSE_REQ_SEND_RESPONSE_HEADER) : - lpszRespBuf = (char *)xmalloc(*lpdwSize);//+ 80);//accommodate our header - if (!lpszRespBuf) - return FALSE; - wsprintf(lpszRespBuf,"%s", - //HTTP_VER, - - /* Default response is 200 Ok */ - - //lpvBuffer?lpvBuffer:"200 Ok", - - /* Create a string for the time. */ - //temp=MakeDateStr(), - - //SERVER_VERSION, - - /* If this exists, it is a pointer to a data buffer to - be sent. */ - lpdwDataType?(char *)lpdwDataType:NULL); - - if (temp) xfree(temp); - - dwBytes = strlen(lpszRespBuf); - bRet = WriteClient(0, lpszRespBuf, &dwBytes, 0); - xfree(lpszRespBuf); - - break; - // - // A real server would do cleanup here - case (HSE_REQ_DONE_WITH_SESSION): - SetEvent(c->waitEvent); - //ExitThread(0); - break; - - // - // This sends a redirect (temporary) to the client. - // The header construction is similar to RESPONSE_HEADER above. - // - case (HSE_REQ_SEND_URL_REDIRECT_RESP): - lpszRespBuf = (char *)xmalloc(*lpdwSize +80) ; - if (!lpszRespBuf) - return FALSE; - wsprintf(lpszRespBuf,"%s %s %s\r\n", - HTTP_VER, - "302 Moved Temporarily", - (lpdwSize > 0)?lpvBuffer:0); - xfree(temp); - dwBytes = strlen(lpszRespBuf); - bRet = WriteClient(0, lpszRespBuf, &dwBytes, 0); - xfree(lpszRespBuf); - break; - default: - return FALSE; - break; - } - return bRet; - -} -// -// Makes a string of the date and time from GetSystemTime(). -// This is in UTC, as required by the HTTP spec.` -// -char * MakeDateStr(void){ - SYSTEMTIME systime; - char *szDate= (char *)xmalloc(64); - - char * DaysofWeek[] = {"Sun","Mon","Tue","Wed","Thurs","Fri","Sat"}; - char * Months[] = {"NULL","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug", - "Sep","Oct","Nov","Dec"}; - - GetSystemTime(&systime); - - wsprintf(szDate,"%s, %d %s %d %d:%d.%d", DaysofWeek[systime.wDayOfWeek], - systime.wDay, - Months[systime.wMonth], - systime.wYear, - systime.wHour, systime.wMinute, - systime.wSecond ); - - return szDate; -} -// -// Fill the ECB up -// -BOOL WINAPI FillExtensionControlBlock(EXTENSION_CONTROL_BLOCK *ECB, TIsapiContext *context) { - - char * temp; - ECB->cbSize = sizeof(EXTENSION_CONTROL_BLOCK); - ECB->dwVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR); - ECB->ConnID = (void *)context; - // - // Pointers to the functions the DLL will call. - // - ECB->GetServerVariable = GetServerVariable; - ECB->ReadClient = ReadClient; - ECB->WriteClient = WriteClient; - ECB->ServerSupportFunction = ServerSupportFunction; - - // - // Fill in the standard CGI environment variables - // - ECB->lpszMethod = GetEnv("REQUEST_METHOD"); - if (!ECB->lpszMethod) ECB->lpszMethod = "GET"; - - ECB->lpszQueryString = GetEnv("QUERY_STRING"); - ECB->lpszPathInfo = GetEnv("PATH_INFO"); - ECB->lpszPathTranslated = GetEnv("PATH_TRANSLATED"); - ECB->cbTotalBytes=( (temp=GetEnv("CONTENT_LENGTH")) ? (atoi(temp)): 0); - ECB->cbAvailable = 0; - ECB->lpbData = (unsigned char *)""; - ECB->lpszContentType = GetEnv("CONTENT_TYPE"); - return TRUE; - -} - -// -// Works like _getenv(), but uses win32 functions instead. -// -char *GetEnv(LPSTR lpszEnvVar) -{ - - char *var, dummy; - DWORD dwLen; - - if (!lpszEnvVar) - return ""; - - dwLen =GetEnvironmentVariable(lpszEnvVar, &dummy, 1); - - if (dwLen == 0) - return ""; - - var = (char *)xmalloc(dwLen); - if (!var) - return ""; - (void)GetEnvironmentVariable(lpszEnvVar, var, dwLen); - - return var; -} diff --git a/sapi/milter/CREDITS b/sapi/milter/CREDITS deleted file mode 100644 index cd00d6774b..0000000000 --- a/sapi/milter/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Sendmail Milter -Harald Radi diff --git a/sapi/milter/EXPERIMENTAL b/sapi/milter/EXPERIMENTAL deleted file mode 100644 index 293159a693..0000000000 --- a/sapi/milter/EXPERIMENTAL +++ /dev/null @@ -1,5 +0,0 @@ -this module is experimental, -its functions may change their names -or move to extension all together -so do not rely to much on them -you have been warned! diff --git a/sapi/milter/Makefile.frag b/sapi/milter/Makefile.frag deleted file mode 100644 index f193f56b01..0000000000 --- a/sapi/milter/Makefile.frag +++ /dev/null @@ -1,8 +0,0 @@ -milter: $(SAPI_MILTER_PATH) - -$(SAPI_MILTER_PATH): $(PHP_GLOBAL_OBJS) $(PHP_BINARY_OBJS) $(PHP_MILTER_OBJS) - $(BUILD_MILTER) - -install-milter: $(SAPI_MILTER_PATH) - @$(INSTALL) -m 0755 $(SAPI_MILTER_PATH) $(INSTALL_ROOT)$(bindir)/php-milter - diff --git a/sapi/milter/TODO b/sapi/milter/TODO deleted file mode 100644 index 4a427ea131..0000000000 --- a/sapi/milter/TODO +++ /dev/null @@ -1,5 +0,0 @@ -threaded version still leaks mem, don't know why -extensions aren't loaded -stdout to syslog -testing -documentation
\ No newline at end of file diff --git a/sapi/milter/config.m4 b/sapi/milter/config.m4 deleted file mode 100644 index a69ab2e1e7..0000000000 --- a/sapi/milter/config.m4 +++ /dev/null @@ -1,31 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(milter, for Milter support, -[ --with-milter[=DIR] Build PHP as Milter application], no, no) - -if test "$PHP_MILTER" != "no"; then - if test "$PHP_MILTER" = "yes"; then - if test -f /usr/lib/libmilter.a ; then - MILTERPATH=/usr/lib - else - if test -f /usr/lib/libmilter/libmilter.a ; then - MILTERPATH=/usr/lib/libmilter - else - AC_MSG_ERROR([Unable to find libmilter.a]) - fi - fi - else - MILTERPATH=$PHP_MILTER - fi - - SAPI_MILTER_PATH=sapi/milter/php-milter - PHP_BUILD_THREAD_SAFE - PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/milter/Makefile.frag,$abs_srcdir/sapi/milter,sapi/milter) - PHP_SELECT_SAPI(milter, program, php_milter.c getopt.c,,'$(SAPI_MILTER_PATH)') - PHP_ADD_LIBRARY_WITH_PATH(milter, $MILTERPATH,) - BUILD_MILTER="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_BINARY_OBJS) \$(PHP_MILTER_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_MILTER_PATH)" - PHP_SUBST(SAPI_MILTER_PATH) - PHP_SUBST(BUILD_MILTER) -fi diff --git a/sapi/milter/getopt.c b/sapi/milter/getopt.c deleted file mode 100644 index df2c77f94c..0000000000 --- a/sapi/milter/getopt.c +++ /dev/null @@ -1,173 +0,0 @@ -/* Borrowed from Apache NT Port */ - -#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) - - -char *ap_php_optarg; -int ap_php_optind = 1; -static int ap_php_opterr = 1; - -static int -ap_php_optiserr(int argc, char * const *argv, int oint, const char *optstr, - int optchr, int err) -{ - if (ap_php_opterr) - { - 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 ap_php_getopt(int argc, char* const *argv, const char *optstr) -{ - static int optchr = 0; - static int dash = 0; /* have already seen the - */ - - char *cp; - - if (ap_php_optind >= argc) - return(EOF); - if (!dash && (argv[ap_php_optind][0] != '-')) - return(EOF); - if (!dash && (argv[ap_php_optind][0] == '-') && !argv[ap_php_optind][1]) - { - /* - * use to specify stdin. Need to let pgm process this and - * the following args - */ - return(EOF); - } - if ((argv[ap_php_optind][0] == '-') && (argv[ap_php_optind][1] == '-')) - { - /* -- indicates end of args */ - ap_php_optind++; - return(EOF); - } - if (!dash) - { - assert((argv[ap_php_optind][0] == '-') && argv[ap_php_optind][1]); - dash = 1; - optchr = 1; - } - - /* Check if the guy tries to do a -: kind of flag */ - assert(dash); - if (argv[ap_php_optind][optchr] == ':') - { - dash = 0; - ap_php_optind++; - return(ap_php_optiserr(argc, argv, ap_php_optind-1, optstr, optchr, OPTERRCOLON)); - } - if (!(cp = strchr(optstr, argv[ap_php_optind][optchr]))) - { - int errind = ap_php_optind; - int errchr = optchr; - - if (!argv[ap_php_optind][optchr+1]) - { - dash = 0; - ap_php_optind++; - } - else - optchr++; - return(ap_php_optiserr(argc, argv, errind, optstr, errchr, OPTERRNF)); - } - if (cp[1] == ':') - { - /* 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[ap_php_optind][2]) { - ap_php_optind++; - if (ap_php_optind == argc) - return(ap_php_optiserr(argc, argv, ap_php_optind-1, optstr, optchr, OPTERRARG)); - ap_php_optarg = argv[ap_php_optind++]; - } - else - { - ap_php_optarg = &argv[ap_php_optind][2]; - ap_php_optind++; - } - return(*cp); - } - else - { - if (!argv[ap_php_optind][optchr+1]) - { - dash = 0; - ap_php_optind++; - } - else - optchr++; - return(*cp); - } - assert(0); - return(0); /* never reached */ -} - -#ifdef TESTGETOPT -int - main (int argc, char **argv) - { - int c; - extern char *ap_php_optarg; - extern int ap_php_optind; - int aflg = 0; - int bflg = 0; - int errflg = 0; - char *ofile = NULL; - - while ((c = ap_php_getopt(argc, argv, "abo:")) != EOF) - switch (c) { - case 'a': - if (bflg) - errflg++; - else - aflg++; - break; - case 'b': - if (aflg) - errflg++; - else - bflg++; - break; - case 'o': - ofile = ap_php_optarg; - (void)printf("ofile = %s\n", ofile); - break; - case '?': - errflg++; - } - if (errflg) { - (void)fprintf(stderr, - "usage: cmd [-a|-b] [-o <filename>] files...\n"); - exit (2); - } - for ( ; ap_php_optind < argc; ap_php_optind++) - (void)printf("%s\n", argv[ap_php_optind]); - return 0; - } - -#endif /* TESTGETOPT */ diff --git a/sapi/milter/milter.php b/sapi/milter/milter.php deleted file mode 100644 index 0878f2a4d9..0000000000 --- a/sapi/milter/milter.php +++ /dev/null @@ -1,132 +0,0 @@ -<?php -/** - * example milter script - * - * run: php-milter -D -p /path/to/sock milter.php - * - * for details on how to set up sendmail and configure the milter see - * http://www.sendmail.com/partner/resources/development/milter_api/ - * - * for api details see - * http://www.sendmail.com/partner/resources/development/milter_api/api.html - * - * below is a list of all callbacks, that are available through the milter sapi, - * if you leave one or more out they simply won't get called (e.g. if you secify an - * empty php file, the milter would do nothing :) - */ - -/** - * this function is called once on sapi startup, - * here you can specify the actions the filter may take - * - * see http://www.sendmail.com/partner/resources/development/milter_api/smfi_register.html#flags - */ - -function milter_log($msg) -{ - $GLOBALS['log'] = fopen("/tmp/milter.log", "a"); - fwrite($GLOBALS['log'], date("[H:i:s d.m.Y]") . "\t{$msg}\n"); - fclose($GLOBALS['log']); -} - -function milter_init() { - milter_log("-- startup --"); - milter_log("milter_init()"); - smfi_setflags(SMFIF_ADDHDRS); -} - -/** - * is called once, at the start of each SMTP connection - */ -function milter_connect($connect) -{ - milter_log("milter_connect('$connect')"); -} - -/** - * is called whenever the client sends a HELO/EHLO command. - * It may therefore be called between zero and three times. - */ -function milter_helo($helo) -{ - milter_log("milter_helo('$helo')"); -} - -/** - * is called once at the beginning of each message, - * before milter_envrcpt. - */ -function milter_envfrom($args) -{ - milter_log("milter_envfrom(args[])"); - foreach ($args as $ix => $arg) { - milter_log("\targs[$ix] = $arg"); - } -} - -/** - * is called once per recipient, hence one or more times per message, - * immediately after milter_envfrom - */ -function milter_envrcpt($args) -{ - milter_log("milter_envrcpt(args[])"); - foreach ($args as $ix => $arg) { - milter_log("\targs[$ix] = $arg"); - } -} - -/** - * is called zero or more times between milter_envrcpt and milter_eoh, - * once per message header - */ -function milter_header($header, $value) -{ - milter_log("milter_header('$header', '$value')"); -} - -/** - * is called once after all headers have been sent and processed. - */ -function milter_eoh() -{ - milter_log("milter_eoh()"); -} - -/** - * is called zero or more times between milter_eoh and milter_eom. - */ -function milter_body($bodypart) -{ - milter_log("milter_body('$bodypart')"); -} - -/** - * is called once after all calls to milter_body for a given message. - * most of the api functions, that alter the message can only be called - * within this callback. - */ -function milter_eom() -{ - milter_log("milter_eom()"); - /* add PHP header to the message */ - smfi_addheader("X-PHP", phpversion()); -} - -/** - * may be called at any time during message processing - * (i.e. between some message-oriented routine and milter_eom). - */ -function milter_abort() -{ - milter_log("milter_abort()"); -} - -/** - * is always called once at the end of each connection. - */ -function milter_close() -{ - milter_log("milter_close()"); -} -?> diff --git a/sapi/milter/php_getopt.h b/sapi/milter/php_getopt.h deleted file mode 100644 index 40da432b59..0000000000 --- a/sapi/milter/php_getopt.h +++ /dev/null @@ -1,7 +0,0 @@ -/* Borrowed from Apache NT Port */ -#include "php.h" - -extern char *ap_php_optarg; -extern int ap_php_optind; - -int ap_php_getopt(int argc, char* const *argv, const char *optstr); diff --git a/sapi/milter/php_milter.c b/sapi/milter/php_milter.c deleted file mode 100644 index 73a0667326..0000000000 --- a/sapi/milter/php_milter.c +++ /dev/null @@ -1,1196 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: Harald Radi <phanto@php.net> | - | Parts based on CGI SAPI Module by | - | Rasmus Lerdorf, Stig Bakken and Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "php_globals.h" -#include "php_variables.h" -#include "zend_modules.h" - -#ifndef ZTS -#error SRM sapi module is only useable in thread-safe mode -#endif - -#include "SAPI.h" - -#include <stdio.h> -#include "php.h" -#if HAVE_SYS_TIME_H -#include <sys/time.h> -#endif -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#if HAVE_SIGNAL_H -#include <signal.h> -#endif -#if HAVE_SETLOCALE -#include <locale.h> -#endif -#include "zend.h" -#include "zend_extensions.h" -#include "php_ini.h" -#include "php_globals.h" -#include "php_main.h" -#include "fopen_wrappers.h" -#include "ext/standard/php_standard.h" - -#ifdef __riscos__ -#include <unixlib/local.h> -#endif - -#include "zend_compile.h" -#include "zend_execute.h" -#include "zend_highlight.h" -#include "zend_indent.h" - -#include "libmilter/mfapi.h" - -#include "php_getopt.h" - -#define OPTSTRING "ac:d:Def:hnp:vVz:?" -#define MG(v) TSRMG(milter_globals_id, zend_milter_globals *, v) - -#define IS_NONE "%s(): This function must not be called outside of a milter callback function's scope" -#define NOT_EOM "%s(): This function can only be used inside the milter_eom callback's scope" -#define NOT_INIT "%s(): This function can only be used inside the milter_init callback's scope" - -#define MLFI_NONE 0 -#define MLFI_CONNECT 1 -#define MLFI_HELO 2 -#define MLFI_ENVFROM 3 -#define MLFI_ENVRCPT 4 -#define MLFI_HEADER 5 -#define MLFI_EOH 6 -#define MLFI_BODY 7 -#define MLFI_EOM 8 -#define MLFI_ABORT 9 -#define MLFI_CLOSE 10 -#define MLFI_INIT 11 - -/* {{{ globals - */ -extern char *ap_php_optarg; -extern int ap_php_optind; - -static int flag_debug=0; -static char *filename = NULL; - -/* per thread */ -ZEND_BEGIN_MODULE_GLOBALS(milter) - SMFICTX *ctx; - int state; - int initialized; -ZEND_END_MODULE_GLOBALS(milter) - -ZEND_DECLARE_MODULE_GLOBALS(milter) -/* }}} */ - -/* this method is called only once when the milter starts */ -/* {{{ Init Milter -*/ -static int mlfi_init() -{ - int ret = 0; - zend_file_handle file_handle; - zval function_name, retval; - int status; - - /* request startup */ - if (php_request_startup()==FAILURE) { - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - php_request_shutdown((void *) 0); - - return -1; - } - - /* disable headers */ - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - - if (filename == NULL) { - php_printf("No input file specified"); - return SMFIS_TEMPFAIL; - } - - if (!(file_handle.handle.fp = VCWD_FOPEN(filename, "rb"))) { - php_printf("Could not open input file: %s\n", filename); - return SMFIS_TEMPFAIL; - } - - file_handle.type = ZEND_HANDLE_FP; - file_handle.filename = filename; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - - php_execute_script(&file_handle); - - /* call userland */ - INIT_ZVAL(function_name); - - ZVAL_STRING(&function_name, "milter_init", 0); - - /* set the milter context for possible use in API functions */ - MG(state) = MLFI_INIT; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL); - - MG(state) = MLFI_NONE; - MG(initialized) = 1; - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - ret = Z_LVAL(retval); - } - - php_request_shutdown((void *) 0); - - return ret; -} -/* }}} */ - -/* {{{ Milter callback functions - */ - -/* connection info filter, is called whenever sendmail connects to the milter */ -/* {{{ mlfi_connect() -*/ -static sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr) -{ - zend_file_handle file_handle; - zval function_name, retval, *param[1]; - int status; - - /* request startup */ - if (php_request_startup()==FAILURE) { - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - php_request_shutdown((void *) 0); - - return SMFIS_TEMPFAIL; - } - - /* disable headers */ - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - - if (filename == NULL) { - php_printf("No input file specified"); - return SMFIS_TEMPFAIL; - } - - if (!(file_handle.handle.fp = VCWD_FOPEN(filename, "rb"))) { - php_printf("Could not open input file: %s\n", filename); - return SMFIS_TEMPFAIL; - } - - file_handle.type = ZEND_HANDLE_FP; - file_handle.filename = filename; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - - php_execute_script(&file_handle); - - /* call userland */ - INIT_ZVAL(function_name); - - ALLOC_ZVAL(param[0]); - INIT_PZVAL(param[0]); - - ZVAL_STRING(&function_name, "milter_connect", 0); - ZVAL_STRING(param[0], hostname, 1); - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_CONNECT; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param); - - MG(state) = MLFI_NONE; - zval_ptr_dtor(param); - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* SMTP HELO command filter */ -/* {{{ mlfi_helo() -*/ -static sfsistat mlfi_helo(SMFICTX *ctx, char *helohost) -{ - zval function_name, retval, *param[1]; - int status; - - /* call userland */ - INIT_ZVAL(function_name); - - ALLOC_ZVAL(param[0]); - INIT_PZVAL(param[0]); - - ZVAL_STRING(&function_name, "milter_helo", 0); - ZVAL_STRING(param[0], helohost, 1); - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_HELO; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param); - - MG(state) = MLFI_NONE; - zval_ptr_dtor(param); - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* envelope sender filter */ -/* {{{ mlfi_envform() -*/ -static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv) -{ - zval function_name, retval, *param[1]; - int status; - - /* call userland */ - INIT_ZVAL(function_name); - - ALLOC_ZVAL(param[0]); - INIT_PZVAL(param[0]); - - ZVAL_STRING(&function_name, "milter_envfrom", 0); - array_init(param[0]); - - while (*argv) { - add_next_index_string(param[0], *argv); - argv++; - } - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_ENVFROM; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param); - - MG(state) = MLFI_NONE; - zval_ptr_dtor(param); - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* envelope recipient filter */ -/* {{{ mlfi_envrcpt() -*/ -static sfsistat mlfi_envrcpt(SMFICTX *ctx, char **argv) -{ - zval function_name, retval, *param[1]; - int status; - - /* call userland */ - INIT_ZVAL(function_name); - - ALLOC_ZVAL(param[0]); - INIT_PZVAL(param[0]); - - ZVAL_STRING(&function_name, "milter_envrcpt", 0); - array_init(param[0]); - - while (*argv) { - add_next_index_string(param[0], *argv); - argv++; - } - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_ENVRCPT; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param); - - MG(state) = MLFI_NONE; - - zval_ptr_dtor(param); - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* header filter */ -/* {{{ mlfi_header() -*/ -static sfsistat mlfi_header(SMFICTX *ctx, char *headerf, char *headerv) -{ - zval function_name, retval, *param[2]; - int status; - - /* call userland */ - INIT_ZVAL(function_name); - - ALLOC_ZVAL(param[0]); - ALLOC_ZVAL(param[1]); - INIT_PZVAL(param[0]); - INIT_PZVAL(param[1]); - - ZVAL_STRING(&function_name, "milter_header", 0); - ZVAL_STRING(param[0], headerf, 1); - ZVAL_STRING(param[1], headerv, 1); - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_HEADER; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 2, param); - - MG(state) = MLFI_NONE; - - zval_ptr_dtor(¶m[0]); - zval_ptr_dtor(¶m[1]); - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* end of header */ -/* {{{ mlfi_eoh() -*/ -static sfsistat mlfi_eoh(SMFICTX *ctx) -{ - zval function_name, retval; - int status; - - /* call userland */ - INIT_ZVAL(function_name); - ZVAL_STRING(&function_name, "milter_eoh", 0); - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_EOH; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL); - - MG(state) = MLFI_NONE; - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* body block */ -/* {{{ mlfi_body() -*/ -static sfsistat mlfi_body(SMFICTX *ctx, u_char *bodyp, size_t len) -{ - zval function_name, retval, *param[1]; - int status; - - /* call userland */ - INIT_ZVAL(function_name); - - ALLOC_ZVAL(param[0]); - INIT_PZVAL(param[0]); - - ZVAL_STRING(&function_name, "milter_body", 0); - ZVAL_STRINGL(param[0], (char*)bodyp, len, 1); /*alex*/ - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_BODY; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param); - - MG(state) = MLFI_NONE; - - zval_ptr_dtor(param); - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* end of message */ -/* {{{ mlfi_eom() -*/ -static sfsistat mlfi_eom(SMFICTX *ctx) -{ - zval function_name, retval; - int status; - - /* call userland */ - INIT_ZVAL(function_name); - ZVAL_STRING(&function_name, "milter_eom", 0); - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_EOM; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL); - - MG(state) = MLFI_NONE; - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* message aborted */ -/* {{{ mlfi_abort() -*/ -static sfsistat mlfi_abort(SMFICTX *ctx) -{ - zval function_name, retval; - int status; - - /* call userland */ - INIT_ZVAL(function_name); - ZVAL_STRING(&function_name, "milter_abort", 0); - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_ABORT; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL); - - MG(state) = MLFI_NONE; - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* connection cleanup */ -/* {{{ mlfi_close() -*/ -static sfsistat mlfi_close(SMFICTX *ctx) -{ - int ret = SMFIS_CONTINUE; - zval function_name, retval; - int status; - - if (!SG(sapi_started) && SUCCESS != php_request_startup()) { - return ret; - } - - /* call userland */ - INIT_ZVAL(function_name); - ZVAL_STRING(&function_name, "milter_close", 0); - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_CLOSE; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL); - - MG(state) = MLFI_NONE; - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - ret = Z_LVAL(retval); - } - - php_request_shutdown((void *) 0); - - return ret; -} -/* }}} */ -/* }}} */ - -/* {{{ Milter entry struct - */ -static struct smfiDesc smfilter = { - "php-milter", /* filter name */ - SMFI_VERSION, /* version code -- leave untouched */ - 0, /* flags */ - mlfi_connect, /* info filter callback */ - mlfi_helo, /* HELO filter callback */ - mlfi_envfrom, /* envelope filter callback */ - mlfi_envrcpt, /* envelope recipient filter callback */ - mlfi_header, /* header filter callback */ - mlfi_eoh, /* end of header callback */ - mlfi_body, /* body filter callback */ - mlfi_eom, /* end of message callback */ - mlfi_abort, /* message aborted callback */ - mlfi_close, /* connection cleanup callback */ -}; -/* }}} */ - -/* {{{ PHP Milter API - */ - -/* {{{ proto void smfi_setflags(long flags) - Sets the flags describing the actions the filter may take. */ -PHP_FUNCTION(smfi_setflags) -{ - long flags; - - /* valid only in the init callback */ - if (MG(state) != MLFI_INIT) { - php_error(E_WARNING, NOT_INIT, get_active_function_name()); - } else if (zend_parse_parameters(1, "l", &flags) == SUCCESS) { - flags = flags & (SMFIF_ADDHDRS|SMFIF_CHGHDRS|SMFIF_CHGBODY|SMFIF_ADDRCPT|SMFIF_DELRCPT); - smfilter.xxfi_flags = flags; - } -} -/* }}} */ - -/* {{{ proto void smfi_settimeout(long timeout) - Sets the number of seconds libmilter will wait for an MTA connection before timing out a socket. */ -PHP_FUNCTION(smfi_settimeout) -{ - long timeout; - - /* valid only in the init callback */ - if (MG(state) != MLFI_INIT) { - php_error(E_WARNING, NOT_INIT, get_active_function_name()); - } else if (zend_parse_parameters(1, "l", &timeout) == SUCCESS) { - smfi_settimeout(timeout); - } -} -/* }}} */ - -/* {{{ proto string smfi_getsymval(string macro) - Returns the value of the given macro or NULL if the macro is not defined. */ -PHP_FUNCTION(smfi_getsymval) -{ - char *symname, *ret; - int len; - - /* valid in any callback */ - if (MG(state) == MLFI_NONE) { - php_error(E_WARNING, IS_NONE, get_active_function_name()); - } else if (zend_parse_parameters(1, "s", &symname, &len) == SUCCESS) { - if ((ret = smfi_getsymval(MG(ctx), symname)) != NULL) { - RETURN_STRING(ret, 1); - } - } - - RETURN_NULL(); -} -/* }}} */ - -/* {{{ proto bool smfi_setreply(string rcode, string xcode, string message) - Directly set the SMTP error reply code for this connection. - This code will be used on subsequent error replies resulting from actions taken by this filter. */ -PHP_FUNCTION(smfi_setreply) -{ - char *rcode, *xcode, *message; - int len; - - /* valid in any callback */ - if (MG(state) == MLFI_NONE) { - php_error(E_WARNING, IS_NONE, get_active_function_name()); - } else if (zend_parse_parameters(3, "sss", &rcode, &len, &xcode, &len, &message, &len) == SUCCESS) { - if (smfi_setreply(MG(ctx), rcode, xcode, message) == MI_SUCCESS) { - RETURN_TRUE; - } - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool smfi_addheader(string headerf, string headerv) - Adds a header to the current message. */ -PHP_FUNCTION(smfi_addheader) -{ - char *f, *v; - int len; - - /* valid only in milter_eom */ - if (MG(state) != MLFI_EOM) { - php_error(E_WARNING, NOT_EOM, get_active_function_name()); - } else if (zend_parse_parameters(2, "ss", &f, &len, &v, &len) == SUCCESS) { - if (smfi_addheader(MG(ctx), f, v) == MI_SUCCESS) { - RETURN_TRUE; - } - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool smfi_chgheader(string headerf, string headerv) - Changes a header's value for the current message. */ -PHP_FUNCTION(smfi_chgheader) -{ - char *f, *v; - long idx; - int len; - - /* valid only in milter_eom */ - if (MG(state) != MLFI_EOM) { - php_error(E_WARNING, NOT_EOM, get_active_function_name()); - } else if (zend_parse_parameters(3, "sls", &f, &len, &idx, &v, &len) == SUCCESS) { - if (smfi_chgheader(MG(ctx), f, idx, v) == MI_SUCCESS) { - RETURN_TRUE; - } - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool smfi_addrcpt(string rcpt) - Add a recipient to the message envelope. */ -PHP_FUNCTION(smfi_addrcpt) -{ - char *rcpt; - int len; - - /* valid only in milter_eom */ - if (MG(state) != MLFI_EOM) { - php_error(E_WARNING, NOT_EOM, get_active_function_name()); - } else if (zend_parse_parameters(1, "s", &rcpt, &len) == SUCCESS) { - if (smfi_addrcpt(MG(ctx), rcpt) == MI_SUCCESS) { - RETURN_TRUE; - } - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool smfi_delrcpt(string rcpt) - Removes the named recipient from the current message's envelope. */ -PHP_FUNCTION(smfi_delrcpt) -{ - char *rcpt; - int len; - - /* valid only in milter_eom */ - if (MG(state) != MLFI_EOM) { - php_error(E_WARNING, NOT_EOM, get_active_function_name()); - } else if (zend_parse_parameters(1, "s", &rcpt, &len) == SUCCESS) { - if (smfi_delrcpt(MG(ctx), rcpt) == MI_SUCCESS) { - RETURN_TRUE; - } - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool smfi_replacebody(string body) - Replaces the body of the current message. If called more than once, - subsequent calls result in data being appended to the new body. */ -PHP_FUNCTION(smfi_replacebody) -{ - char *body; - int len; - - /* valid only in milter_eom */ - if (MG(state) != MLFI_EOM) { - php_error(E_WARNING, NOT_EOM, get_active_function_name()); - } else if (zend_parse_parameters(1, "s", &body, &len) == SUCCESS) { - if (smfi_replacebody(MG(ctx), (u_char*)body, len) == MI_SUCCESS) { - RETURN_TRUE; - } - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ PHP_MINIT_FUNCTION - */ -PHP_MINIT_FUNCTION(milter) -{ - REGISTER_LONG_CONSTANT("SMFIS_CONTINUE", SMFIS_CONTINUE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SMFIS_REJECT", SMFIS_REJECT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SMFIS_DISCARD", SMFIS_DISCARD, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SMFIS_ACCEPT", SMFIS_ACCEPT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SMFIS_TEMPFAIL", SMFIS_TEMPFAIL, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("SMFIF_ADDHDRS", SMFIF_ADDHDRS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SMFIF_CHGHDRS", SMFIF_CHGHDRS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SMFIF_CHGBODY", SMFIF_CHGBODY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SMFIF_ADDRCPT", SMFIF_ADDRCPT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SMFIF_DELRCPT", SMFIF_DELRCPT, CONST_CS | CONST_PERSISTENT); - - ZEND_INIT_MODULE_GLOBALS(milter, NULL, NULL); - - MG(state) = MLFI_NONE; - MG(initialized) = 0; - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_MINFO_FUNCTION - */ -PHP_MINFO_FUNCTION(milter) -{ - php_info_print_table_start(); - php_info_print_table_header(2, "Milter support", "enabled"); - php_info_print_table_end(); -} -/* }}} */ -/* }}} */ - -/* {{{ 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[] -*/ -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) - PHP_FE_END -}; -/* }}} */ - -/* {{{ Zend module entry -*/ -static zend_module_entry php_milter_module = { - STANDARD_MODULE_HEADER, - "Milter", - milter_functions, - PHP_MINIT(milter), - NULL, - NULL, - NULL, - PHP_MINFO(milter), - "0.1.0", - STANDARD_MODULE_PROPERTIES -}; -/* }}} */ - -/* {{{ Milter SAPI -*/ -static int sapi_milter_ub_write(const char *str, uint str_length) -{ - return str_length; -} - -static void sapi_milter_register_variables(zval *track_vars_array) -{ - php_register_variable ("SERVER_SOFTWARE", "Sendmail Milter", track_vars_array); -} - -static int sapi_milter_post_read(char *buf, uint count_bytes) -{ - return 0; -} - -static char* sapi_milter_read_cookies(void) -{ - return NULL; -} - -static int sapi_milter_send_headers(sapi_headers_struct *sapi_headers) -{ - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - -static int php_milter_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, &php_milter_module, 1) == FAILURE) { - return FAILURE; - } - return SUCCESS; -} -/* }}} */ - -/* {{{ sapi_module_struct milter_sapi_module -*/ -static sapi_module_struct milter_sapi_module = { - "milter", /* name */ - "Sendmail Milter SAPI", /* pretty name */ - - php_milter_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - NULL, /* activate */ - NULL, /* deactivate */ - - sapi_milter_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, /* error handler */ - - NULL, /* header handler */ - sapi_milter_send_headers, /* send headers handler */ - NULL, /* send header handler */ - - sapi_milter_post_read, /* read POST data */ - sapi_milter_read_cookies, /* read Cookies */ - - sapi_milter_register_variables, /* register server variables */ - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - NULL, /* Block interruptions */ - NULL, /* Unblock interruptions */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; -/* }}} */ - -/**** -* ripped from cli, has to be cleaned up ! -*/ - -/* {{{ php_milter_usage -*/ -static void php_milter_usage(char *argv0) -{ - char *prog; - - prog = strrchr(argv0, '/'); - if (prog) { - prog++; - } else { - prog = "php-milter"; - } - - printf( "Usage: %s [options] [-f] <file> [args...]\n" - " %s [options] [-- args...]\n" - " -a Run interactively\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" - " -D run as daemon\n" - " -e Generate extended information for debugger/profiler\n" - " -f <file> Parse <file>.\n" - " -h This help\n" - " -p <socket> path to create socket\n" - " -v Version number\n" - " -V <n> set debug level to n (1 or 2).\n" - " -z <file> Load Zend extension <file>.\n" - " args... Arguments passed to script. Use -- args when first argument \n" - " starts with - or script is read from stdin\n" - , prog, prog); -} -/* }}} */ - -static void define_command_line_ini_entry(char *arg) /* {{{ */ -{ - char *name, *value; - - name = arg; - value = strchr(arg, '='); - if (value) { - *value = 0; - value++; - } else { - value = "1"; - } - zend_alter_ini_entry(name, strlen(name)+1, value, strlen(value), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); -} -/* }}} */ - -/* {{{ main -*/ -int main(int argc, char *argv[]) -{ - char *sock = NULL; - int dofork = 0; - - int exit_status = SUCCESS; - int c; -/* temporary locals */ - int orig_optind=ap_php_optind; - char *orig_optarg=ap_php_optarg; - int interactive=0; - char *param_error=NULL; -/* end of temporary locals */ - - void ***tsrm_ls; - -#ifdef HAVE_SIGNAL_H -#if defined(SIGPIPE) && defined(SIG_IGN) - signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so - that sockets created via fsockopen() - don't kill PHP if the remote site - closes it. in apache|apxs mode apache - does that for us! thies@thieso.net - 20000419 */ -#endif -#endif - - - tsrm_startup(1, 1, 0, NULL); - tsrm_ls = ts_resource(0); - sapi_startup(&milter_sapi_module); - - while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) { - switch (c) { - case 'c': - milter_sapi_module.php_ini_path_override = strdup(ap_php_optarg); - break; - case 'n': - milter_sapi_module.php_ini_ignore = 1; - break; - } - } - ap_php_optind = orig_optind; - ap_php_optarg = orig_optarg; - - milter_sapi_module.executable_location = argv[0]; - - - sapi_module.startup(&milter_sapi_module); - - zend_first_try { - while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) { - switch (c) { - case '?': - php_output_tearup(); - SG(headers_sent) = 1; - php_milter_usage(argv[0]); - php_output_teardown(); - exit(1); - break; - } - } - ap_php_optind = orig_optind; - ap_php_optarg = orig_optarg; - - /* Set some CLI defaults */ - SG(options) |= SAPI_OPTION_NO_CHDIR; - zend_alter_ini_entry("html_errors", 12, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); - zend_alter_ini_entry("max_execution_time", 19, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); - - zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */ - - while ((c = ap_php_getopt(argc, argv, OPTSTRING)) != -1) { - switch (c) { - - case 'a': /* interactive mode */ - printf("Interactive mode enabled\n\n"); - interactive=1; - break; - - case 'C': /* don't chdir to the script directory */ - /* This is default so NOP */ - break; - case 'd': /* define ini entries on command line */ - define_command_line_ini_entry(ap_php_optarg); - break; - - case 'D': /* daemon */ - dofork = 1; - break; - - case 'e': /* enable extended info output */ - CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO; - break; - - case 'f': /* parse file */ - filename = ap_php_optarg; - break; - - case 'h': /* help & quit */ - case '?': - php_output_tearup(); - SG(headers_sent) = 1; - php_milter_usage(argv[0]); - php_output_teardown(); - exit(1); - break; - - case 'p': /* socket */ - sock = strdup(ap_php_optarg); - break; - - case 'v': /* show php version & quit */ - if (php_request_startup()==FAILURE) { - zend_ini_deactivate(); - php_module_shutdown(); - sapi_shutdown(); - tsrm_shutdown(); - - exit(1); - } - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2015 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); - php_output_teardown(); - exit(1); - break; - - case 'V': /* verbose */ - flag_debug = atoi(ap_php_optarg); - break; - - case 'z': /* load extension file */ - zend_load_extension(ap_php_optarg); - break; - - default: - break; - } - } - - if (param_error) { - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - PUTS(param_error); - exit(1); - } - - /* only set script_file if not set already and not in direct mode and not at end of parameter list */ - if (argc > ap_php_optind && !filename) { - filename=argv[ap_php_optind]; - ap_php_optind++; - } - - /* check if file exists, exit else */ - - if (dofork) { - switch(fork()) { - case -1: /* Uh-oh, we have a problem forking. */ - fprintf(stderr, "Uh-oh, couldn't fork!\n"); - exit(errno); - break; - case 0: /* Child */ - break; - default: /* Parent */ - exit(0); - } - } - - if (sock) { - struct stat junk; - if (stat(sock,&junk) == 0) unlink(sock); - } - - openlog("php-milter", LOG_PID, LOG_MAIL); - - if ((exit_status = mlfi_init())) { - syslog(1, "mlfi_init failed."); - closelog(); - goto err; - } - - smfi_setconn(sock); - if (smfi_register(smfilter) == MI_FAILURE) { - syslog(1, "smfi_register failed."); - fprintf(stderr, "smfi_register failed\n"); - closelog(); - goto err; - } else { - exit_status = smfi_main(); - } - - closelog(); - - if (milter_sapi_module.php_ini_path_override) { - free(milter_sapi_module.php_ini_path_override); - } - - } zend_catch { - exit_status = EG(exit_status); - } zend_end_try(); - -err: - php_module_shutdown(); - sapi_shutdown(); - tsrm_shutdown(); - - exit(exit_status); -} -/* }}} */ - -/* - * 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/milter/php_milter.h b/sapi/milter/php_milter.h deleted file mode 100644 index 72d7ac51ee..0000000000 --- a/sapi/milter/php_milter.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef PHP_MILTER_H -#define PHP_MILTER_H - -#include "libmilter/mfapi.h" - -#define MLFI_NONE 0 -#define MLFI_CONNECT 1 -#define MLFI_HELO 2 -#define MLFI_ENVFROM 3 -#define MLFI_ENVRCPT 4 -#define MLFI_HEADER 5 -#define MLFI_EOH 6 -#define MLFI_BODY 7 -#define MLFI_EOM 8 -#define MLFI_ABORT 9 -#define MLFI_CLOSE 10 -#define MLFI_INIT 11 - -#define MG(v) TSRMG(milter_globals_id, zend_milter_globals *, v) - -typedef struct { - pthread_t thread; - MUTEX_T receiver; - MUTEX_T sender; - SMFICTX *ctx; - sfsistat retval; - int message; - void **args; -} worker_thread; - -#endif diff --git a/sapi/phttpd/CREDITS b/sapi/phttpd/CREDITS deleted file mode 100644 index 134cc54825..0000000000 --- a/sapi/phttpd/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -phttpd -Thies C. Arntzen diff --git a/sapi/phttpd/README b/sapi/phttpd/README deleted file mode 100644 index cdb6f7c381..0000000000 --- a/sapi/phttpd/README +++ /dev/null @@ -1,5 +0,0 @@ -phttpd sapi module. - -THIS IS BY NO MEANS COMPLETE NOR USABLE RIGHT NOW! - -thies@thieso.net 03.01.2000 diff --git a/sapi/phttpd/config.m4 b/sapi/phttpd/config.m4 deleted file mode 100644 index 91339a5278..0000000000 --- a/sapi/phttpd/config.m4 +++ /dev/null @@ -1,21 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(phttpd, for PHTTPD support, -[ --with-phttpd=DIR Build PHP as phttpd module], no, no) - -if test "$PHP_PHTTPD" != "no"; then - if test ! -d $PHP_PHTTPD ; then - AC_MSG_ERROR([You did not specify a directory]) - fi - PHP_BUILD_THREAD_SAFE - PHP_ADD_INCLUDE($PHP_PHTTPD/include) - AC_DEFINE(HAVE_PHTTPD, 1, [Whether you have phttpd]) - PHP_SELECT_SAPI(phttpd, shared, phttpd.c) - INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)$PHP_PHTTPD/modules/" -fi - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/phttpd/php.sym b/sapi/phttpd/php.sym deleted file mode 100644 index f10b883a99..0000000000 --- a/sapi/phttpd/php.sym +++ /dev/null @@ -1,4 +0,0 @@ -pm_init -pm_exit -pm_request - diff --git a/sapi/phttpd/php_phttpd.h b/sapi/phttpd/php_phttpd.h deleted file mode 100644 index af53d188e2..0000000000 --- a/sapi/phttpd/php_phttpd.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: Thies C. Arntzen <thies@thieso.net> | - +----------------------------------------------------------------------+ -*/ - -#ifndef PHP_PHTTPD_H -#define PHP_PHTTPD_H - -#include <phttpd.h> - -#endif diff --git a/sapi/phttpd/phttpd.c b/sapi/phttpd/phttpd.c deleted file mode 100644 index d47cdc94cc..0000000000 --- a/sapi/phttpd/phttpd.c +++ /dev/null @@ -1,300 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: Thies C. Arntzen <thies@thieso.net> | - | Based on aolserver SAPI by Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ -*/ - -#include "php.h" -#include "SAPI.h" -#include "php_main.h" - -#ifdef HAVE_PHTTPD - -#include "ext/standard/info.h" - -#ifndef ZTS -#error PHTTPD module is only useable in thread-safe mode -#endif - -#include "php_phttpd.h" - -typedef struct { - struct connectioninfo *cip; - struct stat sb; -} phttpd_globals_struct; - -static int ph_globals_id; - -#define PHG(v) TSRMG(ph_globals_id, phttpd_globals_struct *, v) - -static int -php_phttpd_startup(sapi_module_struct *sapi_module) -{ - fprintf(stderr,"***php_phttpd_startup\n"); - - if (php_module_startup(sapi_module, NULL, 0)) { - return FAILURE; - } else { - return SUCCESS; - } -} - -static int -php_phttpd_sapi_ub_write(const char *str, uint str_length) -{ - int sent_bytes; - - sent_bytes = fd_write(PHG(cip)->fd, str, str_length); - - if (sent_bytes == -1) { - php_handle_aborted_connection(); - } - - return sent_bytes; -} - -static int -php_phttpd_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers) -{ - char *header_name, *header_content; - char *p; - - http_sendheaders(PHG(cip)->fd, PHG(cip), SG(sapi_headers).http_response_code, NULL); - - header_name = sapi_header->header; - header_content = p = strchr(header_name, ':'); - - if (p) { - *p = '\0'; - do { - header_content++; - } while (*header_content == ' '); - - fd_printf(PHG(cip)->fd,"%s: %s\n", header_name, header_content); - - *p = ':'; - } - - sapi_free_header(sapi_header); - - return 0; -} - -static int -php_phttpd_sapi_send_headers(sapi_headers_struct *sapi_headers) -{ - if (SG(sapi_headers).send_default_content_type) { - fd_printf(PHG(cip)->fd,"Content-Type: text/html\n"); - } - - fd_putc('\n', PHG(cip)->fd); - - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - -static char * -php_phttpd_sapi_read_cookies(void) -{ - -/* - int i; - char *http_cookie = NULL; - - i = Ns_SetIFind(NSG(conn->headers), "cookie"); - if(i != -1) { - http_cookie = Ns_SetValue(NSG(conn->headers), i); - } - - return http_cookie; -*/ - fprintf(stderr,"***php_phttpd_sapi_read_cookies\n"); - - return 0; -} - -static int -php_phttpd_sapi_read_post(char *buf, uint count_bytes) -{ -/* - uint max_read; - uint total_read = 0; - - max_read = MIN(NSG(data_avail), count_bytes); - - total_read = Ns_ConnRead(NSG(conn), buf, max_read); - - if(total_read == NS_ERROR) { - total_read = -1; - } else { - NSG(data_avail) -= total_read; - } - - return total_read; -*/ - fprintf(stderr,"***php_phttpd_sapi_read_post\n"); - return 0; -} - -static sapi_module_struct phttpd_sapi_module = { - "phttpd", - "PHTTPD", - - php_phttpd_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - NULL, /* activate */ - NULL, /* deactivate */ - - php_phttpd_sapi_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, /* error handler */ - - php_phttpd_sapi_header_handler, /* header handler */ - php_phttpd_sapi_send_headers, /* send headers handler */ - NULL, /* send header handler */ - - php_phttpd_sapi_read_post, /* read POST data */ - php_phttpd_sapi_read_cookies, /* read Cookies */ - - NULL, /* register server variables */ - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - -static void -php_phttpd_request_ctor(void) -{ - memset(&SG(request_info), 0, sizeof(sapi_globals_struct)); /* pfusch! */ - - SG(request_info).query_string = PHG(cip)->hip->request; - SG(request_info).request_method = PHG(cip)->hip->method; - SG(request_info).path_translated = malloc(MAXPATHLEN); - SG(sapi_headers).http_response_code = 200; - if (url_expand(PHG(cip)->hip->url, SG(request_info).path_translated, MAXPATHLEN, &PHG(sb), NULL, NULL) == NULL) { - /* handle error */ - } - -#if 0 - char *server; - Ns_DString ds; - char *root; - int index; - char *tmp; - - server = Ns_ConnServer(NSG(conn)); - - Ns_DStringInit(&ds); - Ns_UrlToFile(&ds, server, NSG(conn->request->url)); - - /* path_translated is the absolute path to the file */ - SG(request_info).path_translated = strdup(Ns_DStringValue(&ds)); - Ns_DStringFree(&ds); - root = Ns_PageRoot(server); - SG(request_info).request_uri = SG(request_info).path_translated + strlen(root); - SG(request_info).content_length = Ns_ConnContentLength(NSG(conn)); - index = Ns_SetIFind(NSG(conn)->headers, "content-type"); - SG(request_info).content_type = index == -1 ? NULL : - Ns_SetValue(NSG(conn)->headers, index); - - tmp = Ns_ConnAuthUser(NSG(conn)); - if(tmp) { - tmp = estrdup(tmp); - } - SG(request_info).auth_user = tmp; - - tmp = Ns_ConnAuthPasswd(NSG(conn)); - if(tmp) { - tmp = estrdup(tmp); - } - SG(request_info).auth_password = tmp; - - NSG(data_avail) = SG(request_info).content_length; -#endif -} - -static void -php_phttpd_request_dtor(void) -{ - free(SG(request_info).path_translated); -} - - -int php_doit(void) -{ - struct stat sb; - zend_file_handle file_handle; - struct httpinfo *hip = PHG(cip)->hip; - - if (php_request_startup() == FAILURE) { - return -1; - } - - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = SG(request_info).path_translated; - file_handle.free_filename = 0; - -/* - php_phttpd_hash_environment(); -*/ - php_execute_script(&file_handle); - php_request_shutdown(NULL); - - return SG(sapi_headers).http_response_code; -} - -int pm_init(const char **argv) -{ - tsrm_startup(1, 1, 0, NULL); - sapi_startup(&phttpd_sapi_module); - phttpd_sapi_module.startup(&phttpd_sapi_module); - - ts_allocate_id(&ph_globals_id, sizeof(phttpd_globals_struct), NULL, NULL); - - return 0; -} - -void pm_exit(void) -{ - fprintf(stderr,"***pm_exit\n"); -} - -int pm_request(struct connectioninfo *cip) -{ - struct httpinfo *hip = cip->hip; - int status; - - if (strcasecmp(hip->method, "GET") == 0 || - strcasecmp(hip->method, "HEAD") == 0 || - strcasecmp(hip->method, "POST") == 0) { - PHG(cip) = cip; - - php_phttpd_request_ctor(); - status = php_doit(); - php_phttpd_request_dtor(); - - return status; - } else { - return -2; - } -} - -#endif diff --git a/sapi/pi3web/CREDITS b/sapi/pi3web/CREDITS deleted file mode 100644 index c4541f89da..0000000000 --- a/sapi/pi3web/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -pi3web -Holger Zimmermann diff --git a/sapi/pi3web/README b/sapi/pi3web/README deleted file mode 100644 index e7726edcf4..0000000000 --- a/sapi/pi3web/README +++ /dev/null @@ -1,50 +0,0 @@ -PHP7 Module -========== -This module requires PHP7 as thread safe shared library. Have a look -into the INSTALL file which accompanies that distribution. - -If you distribute this software bundled with the PHP software in source -or binary form, then you must adhere to the PHP copyright conditions - -the terms are reasonable. - -You should have checked out and built the PHP7 source package from the -PHP CVS tree into the Pi3Web source directory called 'PHP7' first. Then -build PHP7 as Pi3Web module and after that build the Pi3Web PHP7 wrapper: - -1. Checkout PHP7 -================ -cvs -d :pserver:cvsread@cvs.php.net:/repository login -The required password is phpfi - -cvs -z3 -d :pserver:cvsread@cvs.php.net:/repository co php7 - -You must also checkout the TSRM and the ZEND module from the ZEND cvs tree -into the PHP7 root directory - -cvs -d :pserver:cvsread@cvs.zend.com:/repository login -The required password is zend - -cvs -z3 -d :pserver:cvsread@cvs.zend.com:/repository co Zend TSRM - -2. Build PHP7 -============= -2.1 POSIX ---------- -cd ./php7 -./buildconf -./configure --with-pi3web -make - -2.2 Win32 ---------- -other required downloads from the php website - - bison 1.25 - - bindlib32 - - number4.tar.gz -nmake php7dllts.mak - -3. Build Pi3Web PHP7 wrapper -============================ -Run make in the Pi3Web /Source/PHP7 directory. - -For further information refer to http://www.php.net/version4/ diff --git a/sapi/pi3web/config.m4 b/sapi/pi3web/config.m4 deleted file mode 100644 index 42ff164394..0000000000 --- a/sapi/pi3web/config.m4 +++ /dev/null @@ -1,27 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(pi3web, for Pi3Web support, -[ --with-pi3web[=DIR] Build PHP as Pi3Web module], no, no) - -if test "$PHP_PI3WEB" != "no"; then - if test "$PHP_PI3WEB" = "yes"; then - PI3PATH=../.. # the default - else - PI3PATH=$PHP_PI3WEB - fi - test -f "$PI3PATH/PiAPI/PiAPI.h" || AC_MSG_ERROR([Unable to find PiAPI.h in $PI3PATH/PiAPI]) - PHP_BUILD_THREAD_SAFE - AC_DEFINE(WITH_PI3WEB, 1, [whether you want Pi3Web support]) - PHP_ADD_INCLUDE($PI3PATH/PiAPI) - PHP_ADD_INCLUDE($PI3PATH/Pi2API) - PHP_ADD_INCLUDE($PI3PATH/Pi3API) - PHP_ADD_INCLUDE($PI3PATH/PHP7) - PHP_SELECT_SAPI(pi3web, shared, pi3web_sapi.c) - INSTALL_IT="\$(SHELL) \$(srcdir)/install-sh -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)$PI3PATH/bin/" -fi - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/pi3web/config.w32 b/sapi/pi3web/config.w32 deleted file mode 100644 index 9441784468..0000000000 --- a/sapi/pi3web/config.w32 +++ /dev/null @@ -1,16 +0,0 @@ -// vim:ft=javascript -// $Id$ - -ARG_WITH('pi3web', 'Pi3Web', 'no'); - -if (PHP_PI3WEB != "no") { - if (CHECK_HEADER_ADD_INCLUDE('PiAPI.h', 'CFLAGS_PI3WEB', PHP_PHP_BUILD + "\\Pi3Web\\include;" + PHP_PI3WEB) && - CHECK_LIB('piapi.lib', 'pi3web', PHP_PHP_BUILD + "\\Pi3Web\\lib;" + PHP_PI3WEB) && - CHECK_LIB('pi2api.lib', 'pi3web', PHP_PHP_BUILD + "\\Pi3Web\\lib;" + PHP_PI3WEB) && - CHECK_LIB('pi3api.lib', 'pi3web', PHP_PHP_BUILD + "\\Pi3Web\\lib;" + PHP_PI3WEB)) { - SAPI('pi3web', 'pi3web_sapi.c', 'php' + PHP_VERSION + 'pi3web.dll', '/D PHP7PI3WEB_EXPORTS'); - AC_DEFINE('WITH_PI3WEB', 1); - } else { - WARNING('Pi3Web not enabled; headers/libraries not found'); - } -} diff --git a/sapi/pi3web/php.sym b/sapi/pi3web/php.sym deleted file mode 100644 index e69de29bb2..0000000000 --- a/sapi/pi3web/php.sym +++ /dev/null diff --git a/sapi/pi3web/pi3web_sapi.c b/sapi/pi3web/pi3web_sapi.c deleted file mode 100644 index a91660ca6f..0000000000 --- a/sapi/pi3web/pi3web_sapi.c +++ /dev/null @@ -1,438 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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. | - +----------------------------------------------------------------------+ - | Pi3Web version 2.0 | - +----------------------------------------------------------------------+ - | This file is committed by the Pi3 development group. | - | (pi3web.sourceforge.net) | - | | - | Author: Holger Zimmermann (zimpel@users.sourceforge.net) | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS - -#include "php.h" -#include "php_main.h" -#include "php_variables.h" -#include "SAPI.h" -#include "php_globals.h" -#include "ext/standard/info.h" -#include "zend_highlight.h" -#include "zend_indent.h" -#include "zend_alloc.h" -#include "ext/standard/basic_functions.h" -#include "TSRM/TSRM.h" -#include "PiAPI.h" -#include "Pi3API.h" - -#include "pi3web_sapi.h" - -#define PI3WEB_SERVER_VAR_BUF_SIZE 1024 - -int IWasLoaded=0; - - -static void php_info_pi3web(ZEND_MODULE_INFO_FUNC_ARGS) -{ - char variable_buf[PI3WEB_SERVER_VAR_BUF_SIZE]; - DWORD variable_len; - LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context); - PIDB *pDB = (PIDB *)lpCB->GetVariableNames(lpCB->ConnID); - PIDBIterator *pIter = PIDB_getIterator( pDB, PIDBTYPE_STRING, 0, 0 ); - - 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$"); - 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); - PIPlatform_getCurrentDirectory( variable_buf, PI3WEB_SERVER_VAR_BUF_SIZE); - php_info_print_table_row(2, "Current Path", variable_buf); - if (lpCB->GetServerVariable(lpCB->ConnID, "SERVER_NAME", variable_buf, &variable_len) - && variable_buf[0]) { - php_info_print_table_row(2, "Main Virtual Hostname", variable_buf); - }; - snprintf(variable_buf, 511, "%d", PIPlatform_getProcessId()); - php_info_print_table_row(2, "Server PID", variable_buf); - php_info_print_table_row(2, "Server Platform", PIPlatform_getDescription()); - - PUTS("</table><br />"); - - PUTS("<table border=0 cellpadding=3 cellspacing=1 width=600 align=center>\n"); - PUTS("<tr><th colspan=2 bgcolor=\"" PHP_HEADER_COLOR "\">HTTP Request Information</th></tr>\n"); - php_info_print_table_row(2, "HTTP Request Line", lpCB->lpszReq); - PUTS("<tr><th colspan=2 bgcolor=\"" PHP_HEADER_COLOR "\">HTTP Headers</th></tr>\n"); - php_info_print_table_header(2, "Server Variable", "Value"); - - /* --- loop over all registered server variables --- */ - for(; pIter && PIDBIterator_atValidElement( pIter ); PIDBIterator_next( pIter ) ) - { - PCHAR pKey; - PIDBIterator_current( pIter, &pKey ); - if ( !pKey ) { /* sanity */ continue; }; - - variable_len = PI3WEB_SERVER_VAR_BUF_SIZE; - if (lpCB->GetServerVariable(lpCB->ConnID, pKey, variable_buf, &variable_len) - && variable_buf[0]) { - php_info_print_table_row(2, pKey, variable_buf); - } else if (PIPlatform_getLastError() == PIAPI_EINVAL) { - char *tmp_variable_buf; - - tmp_variable_buf = (char *) emalloc(variable_len); - if (lpCB->GetServerVariable(lpCB->ConnID, pKey, tmp_variable_buf, &variable_len) - && variable_buf[0]) { - php_info_print_table_row(2, pKey, tmp_variable_buf); - } - efree(tmp_variable_buf); - } - } - - PUTS("</table>"); -} - - -static zend_module_entry php_pi3web_module = { - STANDARD_MODULE_HEADER, - "PI3WEB", - NULL, - NULL, - NULL, - NULL, - NULL, - php_info_pi3web, - NULL, - STANDARD_MODULE_PROPERTIES -}; - - -static int zend_pi3web_ub_write(const char *str, uint str_length) -{ - DWORD num_bytes = str_length; - LPCONTROL_BLOCK cb; - - cb = (LPCONTROL_BLOCK) SG(server_context); - - if ( !IWasLoaded ) return 0; - cb->WriteClient(cb->ConnID, (char *) str, &num_bytes, 0 ); - - if (num_bytes != str_length) - php_handle_aborted_connection(); - return num_bytes; -} - - -static int sapi_pi3web_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers) -{ - return SAPI_HEADER_ADD; -} - - -static void accumulate_header_length(sapi_header_struct *sapi_header, uint *total_length) -{ - *total_length += sapi_header->header_len+2; -} - - -static void concat_header(sapi_header_struct *sapi_header, char **combined_headers_ptr) -{ - memcpy(*combined_headers_ptr, sapi_header->header, sapi_header->header_len); - *combined_headers_ptr += sapi_header->header_len; - **combined_headers_ptr = '\r'; - (*combined_headers_ptr)++; - **combined_headers_ptr = '\n'; - (*combined_headers_ptr)++; -} - - -static int sapi_pi3web_send_headers(sapi_headers_struct *sapi_headers) -{ - uint total_length = 2; /* account for the trailing \r\n */ - char *combined_headers, *combined_headers_ptr; - LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context); - sapi_header_struct default_content_type; - - if ( !IWasLoaded ) return SAPI_HEADER_SENT_SUCCESSFULLY; - - - if (SG(sapi_headers).send_default_content_type) { - sapi_get_default_content_type_header(&default_content_type); - accumulate_header_length(&default_content_type, (void *) &total_length); - } - zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) accumulate_header_length, (void *) &total_length); - - /* Generate headers */ - combined_headers = (char *) emalloc(total_length+1); - combined_headers_ptr = combined_headers; - if (SG(sapi_headers).send_default_content_type) { - concat_header(&default_content_type, (void *) &combined_headers_ptr); - sapi_free_header(&default_content_type); /* we no longer need it */ - } - zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) concat_header, (void *) &combined_headers_ptr); - *combined_headers_ptr++ = '\r'; - *combined_headers_ptr++ = '\n'; - *combined_headers_ptr = 0; - - lpCB->dwHttpStatusCode = SG(sapi_headers).http_response_code; - lpCB->SendHeaderFunction(lpCB->ConnID, &total_length, (LPDWORD) combined_headers); - - efree(combined_headers); - if (SG(sapi_headers).http_status_line) { - efree(SG(sapi_headers).http_status_line); - SG(sapi_headers).http_status_line = 0; - } - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - - -static int php_pi3web_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, &php_pi3web_module, 1)==FAILURE) { - return FAILURE; - } else { - return SUCCESS; - } -} - - -static int sapi_pi3web_read_post(char *buffer, uint count_bytes) -{ - LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context); - DWORD read_from_buf=0; - DWORD read_from_input=0; - DWORD total_read=0; - - if ((DWORD)SG(read_post_bytes) < lpCB->cbAvailable) { - read_from_buf = MIN(lpCB->cbAvailable-SG(read_post_bytes), count_bytes); - memcpy(buffer, lpCB->lpbData+SG(read_post_bytes), read_from_buf); - total_read += read_from_buf; - } - if (read_from_buf<count_bytes - && (SG(read_post_bytes)+read_from_buf) < lpCB->cbTotalBytes) { - DWORD cbRead=0, cbSize; - - read_from_input = MIN(count_bytes-read_from_buf, lpCB->cbTotalBytes-SG(read_post_bytes)-read_from_buf); - while (cbRead < read_from_input) { - cbSize = read_from_input - cbRead; - if (!lpCB->ReadClient(lpCB->ConnID, buffer+read_from_buf+cbRead, &cbSize) || cbSize==0) { - break; - } - cbRead += cbSize; - } - total_read += cbRead; - } - - /* removed after re-testing POST with Pi3Web 2.0.2 */ - /* SG(read_post_bytes) += total_read; */ - return total_read; -} - - -static char *sapi_pi3web_read_cookies(void) -{ - LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context); - char variable_buf[PI3WEB_SERVER_VAR_BUF_SIZE]; - DWORD variable_len = PI3WEB_SERVER_VAR_BUF_SIZE; - - if (lpCB->GetServerVariable(lpCB->ConnID, "HTTP_COOKIE", variable_buf, &variable_len)) { - return estrndup(variable_buf, variable_len); - } else if (PIPlatform_getLastError()==PIAPI_EINVAL) { - char *tmp_variable_buf = (char *) emalloc(variable_len+1); - - if (lpCB->GetServerVariable(lpCB->ConnID, "HTTP_COOKIE", tmp_variable_buf, &variable_len)) { - tmp_variable_buf[variable_len] = 0; - return tmp_variable_buf; - } else { - efree(tmp_variable_buf); - } - } - return NULL; -} - -static void init_request_info(LPCONTROL_BLOCK lpCB) -{ - SG(server_context) = lpCB; - SG(request_info).request_method = lpCB->lpszMethod; - SG(request_info).query_string = lpCB->lpszQueryString; - SG(request_info).path_translated = lpCB->lpszPathTranslated; - SG(request_info).request_uri = lpCB->lpszUri; - SG(request_info).content_type = lpCB->lpszContentType; - SG(request_info).content_length = lpCB->cbTotalBytes; - SG(request_info).auth_user = (lpCB->lpszUser) ? (char *)estrdup((const char *)(lpCB->lpszUser)) : 0; - SG(request_info).auth_password = (lpCB->lpszPassword) ? (char *)estrdup((const char *)(lpCB->lpszPassword)) : 0; - SG(sapi_headers).http_response_code = 200; -} - -static void sapi_pi3web_register_variables(zval *track_vars_array) -{ - char static_variable_buf[PI3WEB_SERVER_VAR_BUF_SIZE]; - char *variable_buf; - DWORD variable_len = PI3WEB_SERVER_VAR_BUF_SIZE; - LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context); - PIDB *pDB = (PIDB *)lpCB->GetVariableNames(lpCB->ConnID); - PIDBIterator *pIter = PIDB_getIterator( pDB, PIDBTYPE_STRING, 0, 0 ); - - /* --- loop over all registered server variables --- */ - for(; pIter && PIDBIterator_atValidElement( pIter ); PIDBIterator_next( pIter ) ) - { - PCHAR pKey; - PIDBIterator_current( pIter, &pKey ); - if ( !pKey ) { /* sanity */ continue; }; - - variable_len = PI3WEB_SERVER_VAR_BUF_SIZE; - if (lpCB->GetServerVariable(lpCB->ConnID, pKey, static_variable_buf, &variable_len) - && (variable_len > 1)) { - php_register_variable(pKey, static_variable_buf, track_vars_array); - } else if (PIPlatform_getLastError()==PIAPI_EINVAL) { - variable_buf = (char *) emalloc(variable_len); - if (lpCB->GetServerVariable(lpCB->ConnID, pKey, variable_buf, &variable_len)) { - php_register_variable(pKey, variable_buf, track_vars_array); - } - efree(variable_buf); - } - - } - - - /* PHP_SELF support */ - variable_len = PI3WEB_SERVER_VAR_BUF_SIZE; - if (lpCB->GetServerVariable(lpCB->ConnID, "SCRIPT_NAME", static_variable_buf, &variable_len) - && (variable_len > 1)) { - php_register_variable("PHP_SELF", static_variable_buf, track_vars_array); - } -} - -static sapi_module_struct pi3web_sapi_module = { - "pi3web", /* name */ - "PI3WEB", /* pretty name */ - - php_pi3web_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - NULL, /* activate */ - NULL, /* deactivate */ - zend_pi3web_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - php_error, /* error handler */ - sapi_pi3web_header_handler, /* header handler */ - sapi_pi3web_send_headers, /* send headers handler */ - NULL, /* send header handler */ - sapi_pi3web_read_post, /* read POST data */ - sapi_pi3web_read_cookies, /* read Cookies */ - sapi_pi3web_register_variables, /* register server variables */ - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - -MODULE_API DWORD PHP7_wrapper(LPCONTROL_BLOCK lpCB) -{ - zend_file_handle file_handle = {0}; - int iRet = PIAPI_COMPLETED; - - zend_first_try { - file_handle.filename = lpCB->lpszFileName; - file_handle.free_filename = 0; - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.opened_path = NULL; - - init_request_info(lpCB); - php_request_startup(); - - switch ( lpCB->dwBehavior ) { - case PHP_MODE_STANDARD: - iRet = ( php_execute_script( &file_handle ) ) ? - PIAPI_COMPLETED : PIAPI_ERROR; - break; - case PHP_MODE_HIGHLIGHT: { - zend_syntax_highlighter_ini syntax_highlighter_ini; - if ( open_file_for_scanning( &file_handle ) == SUCCESS ) - { - php_get_highlight_struct( &syntax_highlighter_ini ); - zend_highlight( &syntax_highlighter_ini ); - } - else - { - iRet = PIAPI_ERROR; - }; - }; - break; - case PHP_MODE_INDENT: { - sapi_header_line ctr = {0}; - - ctr.line = "Content-Type: text/plain"; - ctr.line_len = strlen(ctr.line); - - sapi_header_op(SAPI_HEADER_REPLACE, &ctr); - } - if ( open_file_for_scanning( &file_handle ) == SUCCESS ) - { - zend_indent(); - } - else - { - iRet = PIAPI_ERROR; - }; - break; - case PHP_MODE_LINT: - iRet = (php_lint_script(&file_handle) == SUCCESS) ? - PIAPI_COMPLETED : PIAPI_ERROR; - break; - default: - iRet = PIAPI_ERROR;; - } - - if (SG(request_info).cookie_data) { - efree(SG(request_info).cookie_data); - }; - - php_request_shutdown(NULL); - } zend_catch { - iRet = PIAPI_ERROR; - } zend_end_try(); - return iRet; -} - -MODULE_API BOOL PHP7_startup() { - tsrm_startup(1, 1, 0, NULL); - sapi_startup(&pi3web_sapi_module); - if (pi3web_sapi_module.startup) { - pi3web_sapi_module.startup(&pi3web_sapi_module); - }; - IWasLoaded = 1; - return IWasLoaded; -}; - -MODULE_API BOOL PHP7_shutdown() { - if (pi3web_sapi_module.shutdown) { - pi3web_sapi_module.shutdown(&pi3web_sapi_module); - }; - sapi_shutdown(); - tsrm_shutdown(); - IWasLoaded = 0; - return !IWasLoaded; -}; - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/sapi/pi3web/pi3web_sapi.h b/sapi/pi3web/pi3web_sapi.h deleted file mode 100644 index 70eec611b4..0000000000 --- a/sapi/pi3web/pi3web_sapi.h +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef _PI3WEB_SAPI_H_ -#define _PI3WEB_SAPI_H_ - -#ifdef PHP_WIN32 -# include <windows.h> -# ifdef PHP7PI3WEB_EXPORTS -# define MODULE_API __declspec(dllexport) -# else -# 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 - - typedef int BOOL; - typedef void far *LPVOID; - typedef unsigned long DWORD; - typedef DWORD far *LPDWORD; - typedef char CHAR; - typedef CHAR *LPSTR; - typedef unsigned char BYTE; - typedef BYTE far *LPBYTE; -#endif - - typedef LPVOID HCONN; - -#ifdef __cplusplus -extern "C" { -#endif - -#define PHP_MODE_STANDARD 1 -#define PHP_MODE_HIGHLIGHT 2 -#define PHP_MODE_INDENT 3 -#define PHP_MODE_LINT 4 - -// -// passed to the procedure on a new request -// -typedef struct _CONTROL_BLOCK { - DWORD cbSize; // size of this struct. - HCONN ConnID; // Context number not to be modified! - DWORD dwHttpStatusCode; // HTTP Status code - CHAR lpszLogData[80]; // null terminated log info - - LPSTR lpszMethod; // REQUEST_METHOD - LPSTR lpszQueryString; // QUERY_STRING - LPSTR lpszPathInfo; // PATH_INFO - LPSTR lpszPathTranslated; // PATH_TRANSLATED - LPSTR lpszFileName; // FileName to PHP3 physical file - LPSTR lpszUri; // The request URI - LPSTR lpszReq; // The whole HTTP request line - LPSTR lpszUser; // The authenticated user - LPSTR lpszPassword; // The authenticated password - - DWORD cbTotalBytes; // Total bytes indicated from client - DWORD cbAvailable; // Available number of bytes - LPBYTE lpbData; // pointer to cbAvailable bytes - - LPSTR lpszContentType; // Content type of client data - DWORD dwBehavior; // PHP behavior (standard, highlight, intend - - - LPVOID (* GetVariableNames) (HCONN hConn); - - BOOL (* GetServerVariable) ( HCONN hConn, - LPSTR lpszVariableName, - LPVOID lpvBuffer, - LPDWORD lpdwSize ); - - BOOL (* WriteClient) ( HCONN hConn, - LPVOID lpvBuffer, - LPDWORD lpdwBytes, - DWORD dwReserved ); - - BOOL (* ReadClient) ( HCONN hConn, - LPVOID lpvBuffer, - LPDWORD lpdwSize ); - - BOOL (* SendHeaderFunction)( HCONN hConn, - LPDWORD lpdwSize, - LPDWORD lpdwDataType ); - -} CONTROL_BLOCK, *LPCONTROL_BLOCK; - -MODULE_API DWORD PHP7_wrapper(LPCONTROL_BLOCK lpCB); -MODULE_API BOOL PHP7_startup(); -MODULE_API BOOL PHP7_shutdown(); - -// the following type declaration is for the server side -typedef DWORD ( * PFN_WRAPPERFUNC )( CONTROL_BLOCK *pCB ); - - - -#ifdef __cplusplus -} -#endif - -#endif // end definition _PI3WEB_SAPI_H_ diff --git a/sapi/roxen/README b/sapi/roxen/README deleted file mode 100644 index 59c215cba0..0000000000 --- a/sapi/roxen/README +++ /dev/null @@ -1,18 +0,0 @@ -Roxen PHP support. Early version. Don't expect to be able to get it to -work. Requires Pike 0.7.79 and Roxen 1.4. Anything less won't work. - -The module is now thread safe, in a couple of different modes. First -mode, the default, uses a process global PHP lock in the Roxen -module. This means that all PHP-requests are serialized (ie only one -script is executed at any one time). The second option is using ZTS -(Zend Thread Safe mode). Unless --enable-roxen-zts is specified, this -won't be used. - -This solution now works fine and is recommended. Multiple PHP7 -requests will be run in parallell. The maximum number of parallell -PHP7-execution is limited to the number of handle threads Roxen is -started with. - -Support for this module is lacking. Please contact Roxen Internet -Software for support and help. See http://www.roxen.com/company/contact/ -for contact information. diff --git a/sapi/roxen/TODO b/sapi/roxen/TODO deleted file mode 100644 index 47143f1be1..0000000000 --- a/sapi/roxen/TODO +++ /dev/null @@ -1,33 +0,0 @@ -BUGS: - -- fix backtraces -- exit in PHP exits Roxen -- POST newline added? -- Rewriting header handling so that more than one header with the same - name can be set (most importantly, cookies). -- Recursive mutex lock problem: - - And another error (when trying to include a class) - - Recursive mutex locks! - /Usr/local/pike/7.0.54/lib/modules/PHP7.so.Interpreter: - run("/home/www/www.tx.pl/news/test.php",mapping[3],modules/scripting/php7.pike.PHPScript(),modules/scripting/php7.pike.PHPScript.done) - modules/scripting/php7.pike:169: run() - base_server/roxen.pike:569: handler_thread(3). - - And after this every access to any php script (on other virtual sites - also) ends (of course there is no proper output) with this error: - - Php4.Interpreter->run: Tried to run a PHP-script from a PHP - callback!/usr/local/pike/7.0.54/lib/modules/PHP7.so.Interpreter: - run("/home/www/biall.com.pl/index.php3",mapping[2],modules/scripting/php7.pike.PHPScript(),modules/scripting/php7.pike.PHPScript.done) - modules/scripting/php7.pike:169: run() - base_server/roxen.pike:569: handler_thread(3). - - -ADDITIONS: - -- use th_farm -- change cwd in single threaded mode -- per-virtual-server configuration - diff --git a/sapi/roxen/config.m4 b/sapi/roxen/config.m4 deleted file mode 100644 index d536ac571b..0000000000 --- a/sapi/roxen/config.m4 +++ /dev/null @@ -1,55 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(roxen,, -[ --with-roxen=DIR Build PHP as a Pike module. DIR is the base Roxen - directory, normally /usr/local/roxen/server], no, no) - -PHP_ARG_ENABLE(roxen-zts, whether Roxen module is build using ZTS, -[ --enable-roxen-zts ROXEN: Build the Roxen module using Zend Thread Safety], no, no) - -RESULT= -AC_MSG_CHECKING([for Roxen/Pike support]) -if test "$PHP_ROXEN" != "no"; then - if test ! -d $PHP_ROXEN ; then - AC_MSG_ERROR([You did not specify a directory]) - fi - if test -f $PHP_ROXEN/bin/roxen; then - PIKE=$PHP_ROXEN/bin/roxen - elif test -f $PHP_ROXEN/bin/pike; then - PIKE=$PHP_ROXEN/bin/pike - else - AC_MSG_ERROR([Could not find a pike in $PHP_ROXEN/bin/]) - fi - - if $PIKE -e 'float v; catch(v = __VERSION__ + (__BUILD__/10000.0)); if(v < 0.7079) exit(1); exit(0);'; then - PIKE_MODULE_DIR=`$PIKE --show-paths 2>&1| grep '^Module' | sed -e 's/.*: //'` - PIKE_INCLUDE_DIR=`echo $PIKE_MODULE_DIR | sed -e 's,lib/pike/modules,include/pike,' -e 's,lib/modules,include/pike,'` - if test -z "$PIKE_INCLUDE_DIR" || test -z "$PIKE_MODULE_DIR"; then - AC_MSG_ERROR([Failed to figure out Pike module and include directories]) - fi - else - AC_MSG_ERROR([Roxen/PHP requires Pike 0.7.79 or newer]) - fi - - PHP_ADD_INCLUDE($PIKE_INCLUDE_DIR) - AC_DEFINE(HAVE_ROXEN, 1, [Whether you use Roxen]) - PHP_SELECT_SAPI(roxen, shared, roxen.c) - INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED $PIKE_MODULE_DIR/PHP7.so" - RESULT="yes - Pike binary used: $PIKE - Pike include dir: $PIKE_INCLUDE_DIR - Pike module directory: $PIKE_MODULE_DIR" - PIKE_INCLUDE_DIR=" -I$PIKE_INCLUDE_DIR " - - if test "$PHP_ROXEN_ZTS" != "no"; then - PHP_BUILD_THREAD_SAFE - AC_DEFINE(ROXEN_USE_ZTS, 1, [Whether to use Roxen in ZTS mode]) - fi -fi -AC_MSG_RESULT([$RESULT]) - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/roxen/roxen.c b/sapi/roxen/roxen.c deleted file mode 100644 index 4afba3829c..0000000000 --- a/sapi/roxen/roxen.c +++ /dev/null @@ -1,725 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: David Hedbor <neotron@php.net> | - | Based on aolserver SAPI by Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#ifdef HAVE_ROXEN - -#include "php_ini.h" -#include "php_globals.h" -#include "SAPI.h" -#include "php_main.h" -#include "ext/standard/info.h" - -#include "php_version.h" - -#ifndef ZTS -/* Only valid if thread safety is enabled. */ -#undef ROXEN_USE_ZTS -#endif - - -/* Pike Include Files - * - * conflicts with pike avoided by only using long names. Requires a new - * Pike 0.7 since it was implemented for this interface only. - * - */ -#define NO_PIKE_SHORTHAND - -#include <fdlib.h> -#include <program.h> -#include <pike_types.h> -#include <interpret.h> -#include <module_support.h> -#include <error.h> -#include <array.h> -#include <backend.h> -#include <stralloc.h> -#include <mapping.h> -#include <object.h> -#include <threads.h> -#include <builtin_functions.h> -#include <operators.h> - -#undef HIDE_GLOBAL_VARIABLES -#undef REVEAL_GLOBAL_VARIABLES -#define HIDE_GLOBAL_VARIABLES() -#define REVEAL_GLOBAL_VARIABLES() - -/* php_roxen_request is per-request object storage */ - -typedef struct -{ - struct mapping *request_data; - struct object *my_fd_obj; - int my_fd; - char *filename; -} php_roxen_request; - - -/* Defines to get to the data supplied when the script is started. */ - -#ifdef ROXEN_USE_ZTS - -/* ZTS does work now, but it seems like it's faster using the "serialization" - * method I previously used. Thus it's not used unless ROXEN_USE_ZTS is defined. - */ - -/* Per thread storage area id... */ -static int roxen_globals_id; - -# define GET_THIS() php_roxen_request *_request = ts_resource(roxen_globals_id) -# define THIS _request -#else -static php_roxen_request *current_request = NULL; - -# define GET_THIS() current_request = ((php_roxen_request *)Pike_fp->current_storage) -# define THIS current_request -#endif - -/* File descriptor integer. Used to write directly to the FD without - * passing Pike - */ -#define MY_FD (THIS->my_fd) - -/* FD object. Really a PHPScript object from Pike which implements a couple - * of functions to handle headers, writing and buffering. - */ -#define MY_FD_OBJ ((struct object *)(THIS->my_fd_obj)) - -/* Mapping with data supplied from the calling Roxen module. Contains - * a mapping with headers, an FD object etc. - */ -#define REQUEST_DATA ((struct mapping *)(THIS->request_data)) - - -#if defined(_REENTRANT) && !defined(ROXEN_USE_ZTS) -/* Lock used to serialize the PHP execution. If ROXEN_USE_ZTS is defined, we - * are using the PHP thread safe mechanism instead. - */ -static PIKE_MUTEX_T roxen_php_execution_lock; -# define PHP_INIT_LOCK() mt_init(&roxen_php_execution_lock) -# define PHP_LOCK(X) THREADS_ALLOW();mt_lock(&roxen_php_execution_lock);THREADS_DISALLOW() -# define PHP_UNLOCK(X) mt_unlock(&roxen_php_execution_lock); -# define PHP_DESTROY() mt_destroy(&roxen_php_execution_lock) -#else /* !_REENTRANT */ -# define PHP_INIT_LOCK() -# define PHP_LOCK(X) -# define PHP_UNLOCK(X) -# define PHP_DESTROY() -#endif /* _REENTRANT */ - -extern int fd_from_object(struct object *o); -static unsigned char roxen_php_initialized; - -/* This allows calling of pike functions from the PHP callbacks, - * which requires the Pike interpreter to be locked. - */ -#define THREAD_SAFE_RUN(COMMAND, what) do {\ - struct thread_state *state;\ - if((state = thread_state_for_id(th_self()))!=NULL) {\ - if(!state->swapped) {\ - COMMAND;\ - } else {\ - mt_lock(&interpreter_lock);\ - SWAP_IN_THREAD(state);\ - COMMAND;\ - SWAP_OUT_THREAD(state);\ - mt_unlock(&interpreter_lock);\ - }\ - }\ -} while(0) - -struct program *php_program; - - -/* To avoid executing a PHP script from a PHP callback, which would - * create a deadlock, a global thread id is used. If the thread calling the - * php-script is the same as the current thread, it fails. - */ -static int current_thread = -1; - - -/* Low level header lookup. Basically looks for the named header in the mapping - * headers in the supplied options mapping. - */ - -static INLINE struct svalue *lookup_header(char *headername) -{ - struct svalue *headers, *value; - struct pike_string *sind; -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - sind = make_shared_string("env"); - headers = low_mapping_string_lookup(REQUEST_DATA, sind); - free_string(sind); - if(!headers || headers->type != PIKE_T_MAPPING) return NULL; - sind = make_shared_string(headername); - value = low_mapping_string_lookup(headers->u.mapping, sind); - free_string(sind); - if(!value) return NULL; - return value; -} - -/* Lookup a header in the mapping and return the value as a string, or - * return the default if it's missing - */ -INLINE static char *lookup_string_header(char *headername, char *default_value) -{ - struct svalue *head = NULL; - THREAD_SAFE_RUN(head = lookup_header(headername), "header lookup"); - if(!head || head->type != PIKE_T_STRING) - return default_value; - return head->u.string->str; -} - -/* Lookup a header in the mapping and return the value as if it's an integer - * and otherwise return the default. - */ -INLINE static int lookup_integer_header(char *headername, int default_value) -{ - struct svalue *head = NULL; - THREAD_SAFE_RUN(head = lookup_header(headername), "header lookup"); - if(!head || head->type != PIKE_T_INT) - return default_value; - return head->u.integer; -} - -/* - * php_roxen_low_ub_write() writes data to the client connection. Might be - * rewritten to do more direct IO to save CPU and the need to lock the * - * interpreter for better threading. - */ - -static int -php_roxen_low_ub_write(const char *str, uint str_length) { - int sent_bytes = 0; - struct pike_string *to_write = NULL; -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - - if(!MY_FD_OBJ->prog) { - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - return -1; - } - to_write = make_shared_binary_string(str, str_length); - push_string(to_write); - safe_apply(MY_FD_OBJ, "write", 1); - if(Pike_sp[-1].type == PIKE_T_INT) - sent_bytes = Pike_sp[-1].u.integer; - pop_stack(); - if(sent_bytes != str_length) { - /* This means the connection is closed. Dead. Gone. *sniff* */ - php_handle_aborted_connection(); - } - return sent_bytes; -} - -/* - * php_roxen_sapi_ub_write() calls php_roxen_low_ub_write in a Pike thread - * safe manner. - */ - -static int -php_roxen_sapi_ub_write(const char *str, uint str_length) -{ -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - - int sent_bytes = 0, fd = MY_FD; - if(fd) - { - for(sent_bytes=0;sent_bytes < str_length;) - { - int written; - written = fd_write(fd, str + sent_bytes, str_length - sent_bytes); - if(written < 0) - { - switch(errno) - { - default: - /* This means the connection is closed. Dead. Gone. *sniff* */ - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - return sent_bytes; - case EINTR: - case EWOULDBLOCK: - continue; - } - - } else { - sent_bytes += written; - } - } - } else { - THREAD_SAFE_RUN(sent_bytes = php_roxen_low_ub_write(str, str_length), - "write"); - } - return sent_bytes; -} - -/* php_roxen_set_header() sets a header in the header mapping. Called in a - * thread safe manner from php_roxen_sapi_header_handler. - */ -static void php_roxen_set_header(char *header_name, char *value, char *p) -{ - struct svalue hsval; - struct pike_string *hval, *ind, *hind; - struct mapping *headermap; - struct svalue *s_headermap; -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - hval = make_shared_string(value); - ind = make_shared_string(" _headers"); - hind = make_shared_binary_string(header_name, - (int)(p - header_name)); - - s_headermap = low_mapping_string_lookup(REQUEST_DATA, ind); - if(!s_headermap) - { - struct svalue mappie; - mappie.type = PIKE_T_MAPPING; - headermap = allocate_mapping(1); - mappie.u.mapping = headermap; - mapping_string_insert(REQUEST_DATA, ind, &mappie); - free_mapping(headermap); - } else - headermap = s_headermap->u.mapping; - - hsval.type = PIKE_T_STRING; - hsval.u.string = hval; - mapping_string_insert(headermap, hind, &hsval); - - free_string(hval); - free_string(ind); - free_string(hind); -} - -/* - * php_roxen_sapi_header_handler() sets a HTTP reply header to be - * sent to the client. - */ -static int -php_roxen_sapi_header_handler(sapi_header_struct *sapi_header, - sapi_headers_struct *sapi_headers) -{ - char *header_name, *header_content, *p; - header_name = sapi_header->header; - header_content = p = strchr(header_name, ':'); - - if(p) { - do { - header_content++; - } while(*header_content == ' '); - THREAD_SAFE_RUN(php_roxen_set_header(header_name, header_content, p), "header handler"); - } - sapi_free_header(sapi_header); - return 0; -} - -/* - * php_roxen_sapi_send_headers() flushes the headers to the client. - * Called before real content is sent by PHP. - */ - -static int -php_roxen_low_send_headers(sapi_headers_struct *sapi_headers) -{ - struct pike_string *ind; - struct svalue *s_headermap; -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - - if(!MY_FD_OBJ->prog) { - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - return SAPI_HEADER_SEND_FAILED; - } - ind = make_shared_string(" _headers"); - s_headermap = low_mapping_string_lookup(REQUEST_DATA, ind); - free_string(ind); - - push_int(SG(sapi_headers).http_response_code); - if(s_headermap && s_headermap->type == PIKE_T_MAPPING) - ref_push_mapping(s_headermap->u.mapping); - else - push_int(0); - safe_apply(MY_FD_OBJ, "send_headers", 2); - pop_stack(); - - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - -static int -php_roxen_sapi_send_headers(sapi_headers_struct *sapi_headers) -{ - int res = 0; - THREAD_SAFE_RUN(res = php_roxen_low_send_headers(sapi_headers), "send headers"); - return res; -} - -/* - * php_roxen_sapi_read_post() reads a specified number of bytes from - * the client. Used for POST/PUT requests. - */ - -INLINE static int php_roxen_low_read_post(char *buf, uint count_bytes) -{ - uint total_read = 0; -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - - if(!MY_FD_OBJ->prog) - { - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - return -1; - } - push_int(count_bytes); - safe_apply(MY_FD_OBJ, "read_post", 1); - if(Pike_sp[-1].type == PIKE_T_STRING) { - MEMCPY(buf, Pike_sp[-1].u.string->str, - (total_read = Pike_sp[-1].u.string->len)); - buf[total_read] = '\0'; - } else - total_read = 0; - pop_stack(); - return total_read; -} - -static int -php_roxen_sapi_read_post(char *buf, uint count_bytes) -{ - uint total_read = 0; - THREAD_SAFE_RUN(total_read = php_roxen_low_read_post(buf, count_bytes), "read post"); - return total_read; -} - -/* - * php_roxen_sapi_read_cookies() returns the Cookie header from - * the HTTP request header - */ - -static char * -php_roxen_sapi_read_cookies(void) -{ - char *cookies; - cookies = lookup_string_header("HTTP_COOKIE", NULL); - return cookies; -} - -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$"); - /* 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()); - php_info_print_table_row(2, "Installation path", Ns_InfoHomePath()); - php_info_print_table_row(2, "Hostname of server", Ns_InfoHostname()); - php_info_print_table_row(2, "Source code label", Ns_InfoLabel()); - php_info_print_table_row(2, "Server platform", Ns_InfoPlatform()); - snprintf(buf, 511, "%s/%s", Ns_InfoServerName(), Ns_InfoServerVersion()); - php_info_print_table_row(2, "Server version", buf); - snprintf(buf, 511, "%d day(s), %02d:%02d:%02d", - uptime / 86400, - (uptime / 3600) % 24, - (uptime / 60) % 60, - uptime % 60); - php_info_print_table_row(2, "Server uptime", buf); - */ - php_info_print_table_end(); -} - -static zend_module_entry php_roxen_module = { - STANDARD_MODULE_HEADER, - "Roxen", - NULL, - NULL, - NULL, - NULL, - NULL, - php_info_roxen, - NULL, - STANDARD_MODULE_PROPERTIES -}; - -static int php_roxen_startup(sapi_module_struct *sapi_module) -{ - if(php_module_startup(sapi_module, &php_roxen_module, 1) == FAILURE) { - return FAILURE; - } else { - return SUCCESS; - } -} - -/* this structure is static (as in "it does not change") */ - -static sapi_module_struct roxen_sapi_module = { - "roxen", - "Roxen", - php_roxen_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - NULL, /* activate */ - NULL, /* deactivate */ - php_roxen_sapi_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - php_error, /* error handler */ - php_roxen_sapi_header_handler, /* header handler */ - php_roxen_sapi_send_headers, /* send headers handler */ - NULL, /* send header handler */ - php_roxen_sapi_read_post, /* read POST data */ - php_roxen_sapi_read_cookies, /* read Cookies */ - NULL, /* register server variables */ - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - -/* - * php_roxen_hash_environment() populates the php script environment - * with a number of variables. HTTP_* variables are created for - * the HTTP header data, so that a script can access these. - */ -#define ADD_STRING(name) \ - MAKE_STD_ZVAL(zvalue); \ - zvalue->type = IS_STRING; \ - zvalue->value.str.len = strlen(buf); \ - zvalue->value.str.val = estrndup(buf, zvalue->value.str.len); \ - zend_hash_update(&EG(symbol_table), name, sizeof(name), \ - &zvalue, sizeof(zval *), NULL) - -static void -php_roxen_hash_environment(void) -{ - int i; - char buf[512]; - zval *zvalue; - struct svalue *headers; - struct pike_string *sind; - struct array *indices; - struct svalue *ind, *val; -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - sind = make_shared_string("env"); - headers = low_mapping_string_lookup(REQUEST_DATA, sind); - free_string(sind); - if(headers && headers->type == PIKE_T_MAPPING) { - indices = mapping_indices(headers->u.mapping); - for(i = 0; i < indices->size; i++) { - ind = &indices->item[i]; - val = low_mapping_lookup(headers->u.mapping, ind); - if(ind && ind->type == PIKE_T_STRING && - val && val->type == PIKE_T_STRING) { - int buf_len; - buf_len = MIN(511, ind->u.string->len); - strncpy(buf, ind->u.string->str, buf_len); - buf[buf_len] = '\0'; /* Terminate correctly */ - MAKE_STD_ZVAL(zvalue); - zvalue->type = IS_STRING; - zvalue->value.str.len = val->u.string->len; - zvalue->value.str.val = estrndup(val->u.string->str, zvalue->value.str.len); - - zend_hash_update(&EG(symbol_table), buf, buf_len + 1, &zvalue, sizeof(zval *), NULL); - } - } - free_array(indices); - } - - /* - MAKE_STD_ZVAL(zvalue); - zvalue->type = IS_LONG; - zvalue->value.lval = Ns_InfoBootTime(); - zend_hash_update(&EG(symbol_table), "SERVER_BOOTTIME", sizeof("SERVER_BOOTTIME"), &zvalue, sizeof(zval *), NULL); - */ -} - -/* - * php_roxen_module_main() is called by the per-request handler and - * "executes" the script - */ - -static int php_roxen_module_main(void) -{ - int res, len; - char *dir; - zend_file_handle file_handle; -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = THIS->filename; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - - THREADS_ALLOW(); - res = php_request_startup(); - THREADS_DISALLOW(); - if(res == FAILURE) { - return 0; - } - php_roxen_hash_environment(); - THREADS_ALLOW(); - php_execute_script(&file_handle); - php_request_shutdown(NULL); - THREADS_DISALLOW(); - return 1; -} - -/* - * The php_roxen_request_handler() is called per request and handles - * everything for one request. - */ - -void f_php_roxen_request_handler(INT32 args) -{ - struct object *my_fd_obj; - struct mapping *request_data; - struct svalue *done_callback, *raw_fd; - struct pike_string *script, *ind; - int status = 1; -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - - if(current_thread == th_self()) - php_error(E_WARNING, "PHP7.Interpreter->run: Tried to run a PHP-script from a PHP " - "callback!"); - get_all_args("PHP7.Interpreter->run", args, "%S%m%O%*", &script, - &request_data, &my_fd_obj, &done_callback); - if(done_callback->type != PIKE_T_FUNCTION) - php_error(E_WARNING, "PHP7.Interpreter->run: Bad argument 4, expected function.\n"); - PHP_LOCK(THIS); /* Need to lock here or reusing the same object might cause - * problems in changing stuff in that object */ -#ifndef ROXEN_USE_ZTS - GET_THIS(); -#endif - THIS->request_data = request_data; - THIS->my_fd_obj = my_fd_obj; - THIS->filename = script->str; - current_thread = th_self(); - SG(request_info).query_string = lookup_string_header("QUERY_STRING", 0); - SG(server_context) = (void *)1; /* avoid server_context == NULL */ - - /* path_translated is apparently the absolute path to the file, not - the translated PATH_INFO - */ - SG(request_info).path_translated = - lookup_string_header("SCRIPT_FILENAME", NULL); - SG(request_info).request_uri = lookup_string_header("DOCUMENT_URI", NULL); - if(!SG(request_info).request_uri) - SG(request_info).request_uri = lookup_string_header("SCRIPT_NAME", NULL); - SG(request_info).request_method = lookup_string_header("REQUEST_METHOD", "GET"); - SG(request_info).content_length = lookup_integer_header("HTTP_CONTENT_LENGTH", 0); - SG(request_info).content_type = lookup_string_header("HTTP_CONTENT_TYPE", NULL); - SG(sapi_headers).http_response_code = 200; - - /* FIXME: Check for auth stuff needs to be fixed... */ - SG(request_info).auth_user = NULL; - SG(request_info).auth_password = NULL; - - ind = make_shared_binary_string("my_fd", 5); - raw_fd = low_mapping_string_lookup(THIS->request_data, ind); - if(raw_fd && raw_fd->type == PIKE_T_OBJECT) - { - int fd = fd_from_object(raw_fd->u.object); - if(fd == -1) - php_error(E_WARNING, "PHP7.Interpreter->run: my_fd object not open or not an FD.\n"); - THIS->my_fd = fd; - } else - THIS->my_fd = 0; - - status = php_roxen_module_main(); - current_thread = -1; - - apply_svalue(done_callback, 0); - pop_stack(); - pop_n_elems(args); - push_int(status); - PHP_UNLOCK(THIS); -} - - -/* Clear the object global struct */ -static void clear_struct(struct object *o) -{ - MEMSET(Pike_fp->current_storage, 0, sizeof(php_roxen_request)); -} - - -/* - * pike_module_init() is called by Pike once at startup - * - * This functions allocates basic structures - */ - -void pike_module_init( void ) -{ - if (!roxen_php_initialized) { -#ifdef ZTS - tsrm_startup(1, 1, 0, NULL); -#ifdef ROXEN_USE_ZTS - ts_allocate_id(&roxen_globals_id, sizeof(php_roxen_request), NULL, NULL); -#endif -#endif - sapi_startup(&roxen_sapi_module); - /*php_roxen_startup(&roxen_sapi_module); removed - should be called from SAPI activation*/ - roxen_php_initialized = 1; - PHP_INIT_LOCK(); - } - start_new_program(); /* Text */ - ADD_STORAGE(php_roxen_request); - set_init_callback(clear_struct); - pike_add_function("run", f_php_roxen_request_handler, - "function(string, mapping, object, function:int)", 0); - add_program_constant("Interpreter", (php_program = end_program()), 0); -} - -/* - * pike_module_exit() performs the last steps before the - * server exists. Shutdowns basic services and frees memory - */ - -void pike_module_exit(void) -{ - roxen_php_initialized = 0; - roxen_sapi_module.shutdown(&roxen_sapi_module); - if(php_program) free_program(php_program); -#ifdef ZTS - tsrm_shutdown(); -#endif - PHP_DESTROY(); -} -#endif diff --git a/sapi/thttpd/CREDITS b/sapi/thttpd/CREDITS deleted file mode 100644 index 8f02f36f4f..0000000000 --- a/sapi/thttpd/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -thttpd -Sascha Schumann diff --git a/sapi/thttpd/README b/sapi/thttpd/README deleted file mode 100644 index 1e80a01956..0000000000 --- a/sapi/thttpd/README +++ /dev/null @@ -1,85 +0,0 @@ -README FOR THTTPD MODULE (by Sascha Schumann) -($Date$) - - This is a SAPI module for PHP 4.x supporting thttpd, the tiny, - turbo, throttling HTTP server by Jef Poskanzer. - - NOTE: All HTTP requests will be serialized. That means, one long running - script will block all other requests. Choose another web server, - if you want to execute arbitrarily long running scripts. - - The module contains a patch against version 2.21b of thttpd. The patch - fixes a number of bugs and adds some functionality: - - - HTTP/1.1 Persistent Connection/Pipeline Support - - PHP Scripting (**.php by default) - - Highlighting PHP Scripts (**.phps by default) - - Fast Accept Loop (unique to PHP) - - Periodic Connection Expiring (unique to PHP) - - Log to stdout (logfile=-) - - Fixes the Host: header vulnerability (affects vhosts only) - - Asynchronous request body handling (e.g. for POSTs) - - Accept filter for Linux - - Fix for non-blocking sending of thttpd-generated responses - - You can configure the filename extensions by creating a config file for - thttpd and setting these entries: - - phppat=PATTERN - phpspat=PATTERN - - The PATTERN has the same format as defined here: - - http://acme.com/software/thttpd/options.html#CGI_PATTERN - - "**.php" means: match any file ending in .php in any directory. - Setting the pattern from the command line is not supported. - - NOTE: This version supports *only* thttpd 2.21b, no prior or later - version. - - This is a functional and stable module (it runs a large application - like IMP 2.2.0 without any problems). Its original intention was to - demonstrate the ability of PHP to work in every web server environment. - -REQUIRED DOWNLOADS - - 1. thttpd 2.21b (2.20 or +2.22beta will _not_ work) - - Full Distribution: - http://www.acme.com/software/thttpd/thttpd-2.21b.tar.gz - - 2. PHP 4.x - - Download: - http://www.php.net/ - - Snapshots from CVS: - http://snaps.php.net/ - - -BUILD INSTRUCTIONS - - 1. Extract software packages - - $ gunzip -c thttpd-2.xx.tar.gz | tar xf - - $ gunzip -c php-*.tar.gz | tar xf - - - 2. Prepare PHP - - $ cd php-* - $ ./configure \ - --with-thttpd=../thttpd-2.xx \ - <further PHP options> - $ make install - $ cd .. - - You can see the list of valid PHP options by executing - - $ ./configure --help - - 3. Configure, compile, install thttpd - - Now follow the thttpd instructions. The Makefile template of - thttpd was changed to automatically use the components - required by PHP. diff --git a/sapi/thttpd/config.m4 b/sapi/thttpd/config.m4 deleted file mode 100644 index fddb709d92..0000000000 --- a/sapi/thttpd/config.m4 +++ /dev/null @@ -1,39 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(thttpd,, -[ --with-thttpd=SRCDIR Build PHP as thttpd module], no, no) - -AC_MSG_CHECKING([for thttpd]) - -if test "$PHP_THTTPD" != "no"; then - if test ! -d $PHP_THTTPD; then - AC_MSG_RESULT(thttpd directory does not exist ($PHP_THTTPD)) - fi - - PHP_EXPAND_PATH($PHP_THTTPD, THTTPD) - - if grep thttpd.2.21b $PHP_THTTPD/version.h >/dev/null; then - patch="test -f $THTTPD/php_patched || \ - (cd $THTTPD && patch -p1 < $abs_srcdir/sapi/thttpd/thttpd_patch && touch php_patched)" - - elif grep Premium $PHP_THTTPD/version.h >/dev/null; then - patch= - else - AC_MSG_ERROR([This version only supports thttpd-2.21b and Premium thttpd]) - fi - PHP_TARGET_RDYNAMIC - INSTALL_IT="\ - echo 'PHP_LIBS = -L. -lphp7 \$(PHP_LIBS) \$(EXTRA_LIBS)' > $THTTPD/php_makefile; \ - echo 'PHP_LDFLAGS = \$(NATIVE_RPATHS) \$(PHP_LDFLAGS)' >> $THTTPD/php_makefile; \ - echo 'PHP_CFLAGS = \$(COMMON_FLAGS) \$(CFLAGS_CLEAN) \$(CPPFLAGS) \$(EXTRA_CFLAGS)' >> $THTTPD/php_makefile; \ - rm -f $THTTPD/php_thttpd.c $THTTPD/php_thttpd.h $THTTPD/libphp7.a; \ - \$(LN_S) $abs_srcdir/sapi/thttpd/thttpd.c $THTTPD/php_thttpd.c; \ - \$(LN_S) $abs_srcdir/sapi/thttpd/php_thttpd.h $abs_builddir/$SAPI_STATIC $THTTPD/;\ - $patch" - PHP_THTTPD="yes, using $THTTPD" - PHP_ADD_INCLUDE($THTTPD) - PHP_SELECT_SAPI(thttpd, static) -fi -AC_MSG_RESULT($PHP_THTTPD) diff --git a/sapi/thttpd/php.sym b/sapi/thttpd/php.sym deleted file mode 100644 index 2214d3964d..0000000000 --- a/sapi/thttpd/php.sym +++ /dev/null @@ -1,3 +0,0 @@ -thttpd_php_request -thttpd_php_init -thttpd_php_shutdown diff --git a/sapi/thttpd/php_thttpd.h b/sapi/thttpd/php_thttpd.h deleted file mode 100644 index ace252a356..0000000000 --- a/sapi/thttpd/php_thttpd.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ -*/ - -#ifndef PHP_THTTPD_H -#define PHP_THTTPD_H - -#include <sys/types.h> -#include <sys/stat.h> -#include <libhttpd.h> - -void thttpd_php_shutdown(void); -void thttpd_php_init(void); -off_t thttpd_php_request(httpd_conn *hc, int show_source); - -void thttpd_register_on_close(void (*)(int)); -void thttpd_closed_conn(int fd); -int thttpd_get_fd(void); -void thttpd_set_dont_close(void); - -#endif diff --git a/sapi/thttpd/stub.c b/sapi/thttpd/stub.c deleted file mode 100644 index e69de29bb2..0000000000 --- a/sapi/thttpd/stub.c +++ /dev/null diff --git a/sapi/thttpd/thttpd.c b/sapi/thttpd/thttpd.c deleted file mode 100644 index ad4e8e366e..0000000000 --- a/sapi/thttpd/thttpd.c +++ /dev/null @@ -1,766 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "SAPI.h" -#include "php_main.h" -#include "php_thttpd.h" -#include "php_variables.h" -#include "version.h" -#include "php_ini.h" -#include "zend_highlight.h" - -#include "zend_smart_str.h" - -#include <sys/time.h> -#include <sys/types.h> -#include <sys/uio.h> -#include <stdlib.h> -#include <unistd.h> - -#ifdef HAVE_GETNAMEINFO -#include <sys/socket.h> -#include <netdb.h> -#endif - -typedef struct { - httpd_conn *hc; - void (*on_close)(int); - - size_t unconsumed_length; - smart_str sbuf; - int seen_cl; - int seen_cn; -} php_thttpd_globals; - -#define PHP_SYS_CALL(x) do { x } while (n == -1 && errno == EINTR) - -#ifdef PREMIUM_THTTPD -# define do_keep_alive persistent -#endif - -#ifdef ZTS -static int thttpd_globals_id; -#define TG(v) TSRMG(thttpd_globals_id, php_thttpd_globals *, v) -#else -static php_thttpd_globals thttpd_globals; -#define TG(v) (thttpd_globals.v) -#endif - -static int sapi_thttpd_ub_write(const char *str, uint str_length) -{ - int n; - uint sent = 0; - - if (TG(sbuf).c != 0) { - smart_str_appendl_ex(&TG(sbuf), str, str_length, 1); - return str_length; - } - - while (str_length > 0) { - PHP_SYS_CALL(n = send(TG(hc)->conn_fd, str, str_length, 0);); - - if (n == -1) { - if (errno == EAGAIN) { - smart_str_appendl_ex(&TG(sbuf), str, str_length, 1); - - return sent + str_length; - } else - php_handle_aborted_connection(); - } - - TG(hc)->bytes_sent += n; - str += n; - sent += n; - str_length -= n; - } - - return sent; -} - -#define COMBINE_HEADERS 64 - -#if defined(IOV_MAX) -# if IOV_MAX - 64 <= 0 -# define SERIALIZE_HEADERS -# endif -#endif - -static int do_writev(struct iovec *vec, int nvec, int len) -{ - int n; - - assert(nvec <= IOV_MAX); - - if (TG(sbuf).c == 0) { - PHP_SYS_CALL(n = writev(TG(hc)->conn_fd, vec, nvec);); - - if (n == -1) { - if (errno == EAGAIN) { - n = 0; - } else { - php_handle_aborted_connection(); - } - } - - - TG(hc)->bytes_sent += n; - } else { - n = 0; - } - - if (n < len) { - int i; - - /* merge all unwritten data into sbuf */ - for (i = 0; i < nvec; vec++, i++) { - /* has this vector been written completely? */ - if (n >= vec->iov_len) { - /* yes, proceed */ - n -= vec->iov_len; - continue; - } - - if (n > 0) { - /* adjust vector */ - vec->iov_base = (char *) vec->iov_base + n; - vec->iov_len -= n; - n = 0; - } - - smart_str_appendl_ex(&TG(sbuf), vec->iov_base, vec->iov_len, 1); - } - } - - return 0; -} - -#ifdef SERIALIZE_HEADERS -# define ADD_VEC(str,l) smart_str_appendl(&vec_str, (str), (l)) -# define VEC_BASE() smart_str vec_str = {0} -# define VEC_FREE() smart_str_free(&vec_str) -#else -# define ADD_VEC(str,l) vec[n].iov_base=str;len += (vec[n].iov_len=l); n++ -# define VEC_BASE() struct iovec vec[COMBINE_HEADERS] -# define VEC_FREE() do {} while (0) -#endif - -#define ADD_VEC_S(str) ADD_VEC((str), sizeof(str)-1) - -#define CL_TOKEN "Content-length: " -#define CN_TOKEN "Connection: " -#define KA_DO "Connection: keep-alive\r\n" -#define KA_NO "Connection: close\r\n" -#define DEF_CT "Content-Type: text/html\r\n" - -static int sapi_thttpd_send_headers(sapi_headers_struct *sapi_headers) -{ - char buf[1024], *p; - VEC_BASE(); - int n = 0; - zend_llist_position pos; - sapi_header_struct *h; - size_t len = 0; - - if (!SG(sapi_headers).http_status_line) { - ADD_VEC_S("HTTP/1.1 "); - p = zend_print_long_to_buf(buf+sizeof(buf)-1, - SG(sapi_headers).http_response_code); - ADD_VEC(p, strlen(p)); - ADD_VEC_S(" HTTP\r\n"); - } else { - ADD_VEC(SG(sapi_headers).http_status_line, - strlen(SG(sapi_headers).http_status_line)); - ADD_VEC("\r\n", 2); - } - TG(hc)->status = SG(sapi_headers).http_response_code; - - if (SG(sapi_headers).send_default_content_type) { - ADD_VEC(DEF_CT, strlen(DEF_CT)); - } - - h = zend_llist_get_first_ex(&sapi_headers->headers, &pos); - while (h) { - - switch (h->header[0]) { - case 'c': case 'C': - if (!TG(seen_cl) && strncasecmp(h->header, CL_TOKEN, sizeof(CL_TOKEN)-1) == 0) { - TG(seen_cl) = 1; - } else if (!TG(seen_cn) && strncasecmp(h->header, CN_TOKEN, sizeof(CN_TOKEN)-1) == 0) { - TG(seen_cn) = 1; - } - } - - ADD_VEC(h->header, h->header_len); -#ifndef SERIALIZE_HEADERS - if (n >= COMBINE_HEADERS - 1) { - len = do_writev(vec, n, len); - n = 0; - } -#endif - ADD_VEC("\r\n", 2); - - h = zend_llist_get_next_ex(&sapi_headers->headers, &pos); - } - - if (TG(seen_cl) && !TG(seen_cn) && TG(hc)->do_keep_alive) { - ADD_VEC(KA_DO, sizeof(KA_DO)-1); - } else { - TG(hc)->do_keep_alive = 0; - ADD_VEC(KA_NO, sizeof(KA_NO)-1); - } - - ADD_VEC("\r\n", 2); - -#ifdef SERIALIZE_HEADERS - sapi_thttpd_ub_write(vec_str.c, vec_str.len); -#else - do_writev(vec, n, len); -#endif - - VEC_FREE(); - - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - -/* to understand this, read cgi_interpose_input() in libhttpd.c */ -#define SIZEOF_UNCONSUMED_BYTES() (TG(hc)->read_idx - TG(hc)->checked_idx) -#define CONSUME_BYTES(n) do { TG(hc)->checked_idx += (n); } while (0) - - -static int sapi_thttpd_read_post(char *buffer, uint count_bytes) -{ - size_t read_bytes = 0; - - if (TG(unconsumed_length) > 0) { - read_bytes = MIN(TG(unconsumed_length), count_bytes); - memcpy(buffer, TG(hc)->read_buf + TG(hc)->checked_idx, read_bytes); - TG(unconsumed_length) -= read_bytes; - CONSUME_BYTES(read_bytes); - } - - return read_bytes; -} - -static char *sapi_thttpd_read_cookies(void) -{ - return TG(hc)->cookie; -} - -#define BUF_SIZE 512 -#define ADD_STRING_EX(name,buf) \ - php_register_variable(name, buf, track_vars_array) -#define ADD_STRING(name) ADD_STRING_EX((name), buf) - -static void sapi_thttpd_register_variables(zval *track_vars_array) -{ - char buf[BUF_SIZE + 1]; - char *p; - - php_register_variable("PHP_SELF", SG(request_info).request_uri, track_vars_array); - php_register_variable("SERVER_SOFTWARE", SERVER_SOFTWARE, track_vars_array); - php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array); - php_register_variable("REQUEST_METHOD", (char *) SG(request_info).request_method, track_vars_array); - php_register_variable("REQUEST_URI", SG(request_info).request_uri, track_vars_array); - php_register_variable("PATH_TRANSLATED", SG(request_info).path_translated, track_vars_array); - - if (TG(hc)->one_one) { - php_register_variable("SERVER_PROTOCOL", "HTTP/1.1", track_vars_array); - } else { - php_register_variable("SERVER_PROTOCOL", "HTTP/1.0", track_vars_array); - } - - p = httpd_ntoa(&TG(hc)->client_addr); - - ADD_STRING_EX("REMOTE_ADDR", p); - ADD_STRING_EX("REMOTE_HOST", p); - - ADD_STRING_EX("SERVER_PORT", - zend_print_long_to_buf(buf + sizeof(buf) - 1, - TG(hc)->hs->port)); - - buf[0] = '/'; - memcpy(buf + 1, TG(hc)->pathinfo, strlen(TG(hc)->pathinfo) + 1); - ADD_STRING("PATH_INFO"); - - buf[0] = '/'; - memcpy(buf + 1, TG(hc)->origfilename, strlen(TG(hc)->origfilename) + 1); - ADD_STRING("SCRIPT_NAME"); - -#define CONDADD(name, field) \ - if (TG(hc)->field[0]) { \ - php_register_variable(#name, TG(hc)->field, track_vars_array); \ - } - - CONDADD(QUERY_STRING, query); - CONDADD(HTTP_HOST, hdrhost); - CONDADD(HTTP_REFERER, referer); - CONDADD(HTTP_USER_AGENT, useragent); - CONDADD(HTTP_ACCEPT, accept); - CONDADD(HTTP_ACCEPT_LANGUAGE, acceptl); - CONDADD(HTTP_ACCEPT_ENCODING, accepte); - CONDADD(HTTP_COOKIE, cookie); - CONDADD(CONTENT_TYPE, contenttype); - CONDADD(REMOTE_USER, remoteuser); - CONDADD(SERVER_PROTOCOL, protocol); - - if (TG(hc)->contentlength != -1) { - ADD_STRING_EX("CONTENT_LENGTH", - zend_print_long_to_buf(buf + sizeof(buf) - 1, - TG(hc)->contentlength)); - } - - if (TG(hc)->authorization[0]) - php_register_variable("AUTH_TYPE", "Basic", track_vars_array); -} - -static PHP_MINIT_FUNCTION(thttpd) -{ - return SUCCESS; -} - -static zend_module_entry php_thttpd_module = { - STANDARD_MODULE_HEADER, - "thttpd", - NULL, - PHP_MINIT(thttpd), - NULL, - NULL, - NULL, - NULL, /* info */ - NULL, - STANDARD_MODULE_PROPERTIES -}; - -static int php_thttpd_startup(sapi_module_struct *sapi_module) -{ -#if PHP_API_VERSION >= 20020918 - if (php_module_startup(sapi_module, &php_thttpd_module, 1) == FAILURE) { -#else - /* No here to zend_startup_module() as 5.6 and older does not have that parameter */ - if (php_module_startup(sapi_module) == FAILURE - || zend_startup_module(&php_thttpd_module) == FAILURE) { -#endif - return FAILURE; - } - return SUCCESS; -} - -static int sapi_thttpd_get_fd(int *nfd) -{ - if (nfd) *nfd = TG(hc)->conn_fd; - return SUCCESS; -} - -static sapi_module_struct thttpd_sapi_module = { - "thttpd", - "thttpd", - - php_thttpd_startup, - php_module_shutdown_wrapper, - - NULL, /* activate */ - NULL, /* deactivate */ - - sapi_thttpd_ub_write, - NULL, - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, - - NULL, - sapi_thttpd_send_headers, - NULL, - sapi_thttpd_read_post, - sapi_thttpd_read_cookies, - - sapi_thttpd_register_variables, - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - NULL, /* php.ini path override */ - NULL, /* Block interruptions */ - NULL, /* Unblock interruptions */ - - NULL, - NULL, - NULL, - 0, - sapi_thttpd_get_fd -}; - -static void thttpd_module_main(int show_source) -{ - zend_file_handle file_handle; - - if (php_request_startup() == FAILURE) { - return; - } - - 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); - } else { - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = SG(request_info).path_translated; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - - php_execute_script(&file_handle); - } - - php_request_shutdown(NULL); -} - -static void thttpd_request_ctor(void) -{ - smart_str s = {0}; - - TG(seen_cl) = 0; - TG(seen_cn) = 0; - TG(sbuf).c = 0; - SG(request_info).query_string = TG(hc)->query?strdup(TG(hc)->query):NULL; - - smart_str_appends_ex(&s, TG(hc)->hs->cwd, 1); - smart_str_appends_ex(&s, TG(hc)->expnfilename, 1); - smart_str_0(&s); - SG(request_info).path_translated = s.c; - - s.c = NULL; - smart_str_appendc_ex(&s, '/', 1); - smart_str_appends_ex(&s, TG(hc)->origfilename, 1); - smart_str_0(&s); - SG(request_info).request_uri = s.c; - SG(request_info).request_method = httpd_method_str(TG(hc)->method); - if (TG(hc)->one_one) SG(request_info).proto_num = 1001; - else SG(request_info).proto_num = 1000; - SG(sapi_headers).http_response_code = 200; - if (TG(hc)->contenttype) - SG(request_info).content_type = strdup(TG(hc)->contenttype); - SG(request_info).content_length = TG(hc)->contentlength == -1 ? 0 - : TG(hc)->contentlength; - - TG(unconsumed_length) = SG(request_info).content_length; - - php_handle_auth_data(TG(hc)->authorization); -} - -static void thttpd_request_dtor(void) -{ - smart_str_free(&TG(sbuf)); - if (SG(request_info).query_string) - free(SG(request_info).query_string); - free(SG(request_info).request_uri); - free(SG(request_info).path_translated); - if (SG(request_info).content_type) - free(SG(request_info).content_type); -} - -#ifdef ZTS - -#ifdef TSRM_ST -#define thread_create_simple_detached(n) st_thread_create(n, NULL, 0, 0) -#define thread_usleep(n) st_usleep(n) -#define thread_exit() st_thread_exit(NULL) -/* No preemption, simple operations are safe */ -#define thread_atomic_inc(n) (++n) -#define thread_atomic_dec(n) (--n) -#else -#error No thread primitives available -#endif - -/* We might want to replace this with a STAILQ */ -typedef struct qreq { - httpd_conn *hc; - struct qreq *next; -} qreq_t; - -static MUTEX_T qr_lock; -static qreq_t *queued_requests; -static qreq_t *last_qr; -static int nr_free_threads; -static int nr_threads; -static int max_threads = 50; - -#define HANDLE_STRINGS() { \ - HANDLE_STR(encodedurl); \ - HANDLE_STR(decodedurl); \ - HANDLE_STR(origfilename); \ - HANDLE_STR(expnfilename); \ - HANDLE_STR(pathinfo); \ - HANDLE_STR(query); \ - HANDLE_STR(referer); \ - HANDLE_STR(useragent); \ - HANDLE_STR(accept); \ - HANDLE_STR(accepte); \ - HANDLE_STR(acceptl); \ - HANDLE_STR(cookie); \ - HANDLE_STR(contenttype); \ - HANDLE_STR(authorization); \ - HANDLE_STR(remoteuser); \ - } - -static httpd_conn *duplicate_conn(httpd_conn *hc, httpd_conn *nhc) -{ - memcpy(nhc, hc, sizeof(*nhc)); - -#define HANDLE_STR(m) nhc->m = nhc->m ? strdup(nhc->m) : NULL - HANDLE_STRINGS(); -#undef HANDLE_STR - - return nhc; -} - -static void destroy_conn(httpd_conn *hc) -{ -#define HANDLE_STR(m) if (hc->m) free(hc->m) - HANDLE_STRINGS(); -#undef HANDLE_STR -} - -static httpd_conn *dequeue_request(void) -{ - httpd_conn *ret = NULL; - qreq_t *m; - - tsrm_mutex_lock(qr_lock); - if (queued_requests) { - m = queued_requests; - ret = m->hc; - if (!(queued_requests = m->next)) - last_qr = NULL; - free(m); - } - tsrm_mutex_unlock(qr_lock); - - return ret; -} - -static void *worker_thread(void *); - -static void queue_request(httpd_conn *hc) -{ - qreq_t *m; - httpd_conn *nhc; - - /* Mark as long-running request */ - hc->file_address = (char *) 1; - - /* - * We cannot synchronously revoke accesses to hc in the worker - * thread, so we need to pass a copy of hc to the worker thread. - */ - nhc = malloc(sizeof *nhc); - duplicate_conn(hc, nhc); - - /* Allocate request queue container */ - m = malloc(sizeof *m); - m->hc = nhc; - m->next = NULL; - - tsrm_mutex_lock(qr_lock); - /* Create new threads when reaching a certain threshold */ - if (nr_threads < max_threads && nr_free_threads < 2) { - nr_threads++; /* protected by qr_lock */ - - thread_atomic_inc(nr_free_threads); - thread_create_simple_detached(worker_thread); - } - /* Insert container into request queue */ - if (queued_requests) - last_qr->next = m; - else - queued_requests = m; - last_qr = m; - tsrm_mutex_unlock(qr_lock); -} - -static off_t thttpd_real_php_request(httpd_conn *hc, int); - -static void *worker_thread(void *dummy) -{ - int do_work = 50; - httpd_conn *hc; - - while (do_work) { - hc = dequeue_request(); - - if (!hc) { -/* do_work--; */ - thread_usleep(500000); - continue; - } -/* do_work = 50; */ - - thread_atomic_dec(nr_free_threads); - - thttpd_real_php_request(hc, 0); - shutdown(hc->conn_fd, 0); - destroy_conn(hc); - free(hc); - - thread_atomic_inc(nr_free_threads); - } - thread_atomic_dec(nr_free_threads); - thread_atomic_dec(nr_threads); - thread_exit(); -} - -static void remove_dead_conn(int fd) -{ - qreq_t *m, *prev = NULL; - - tsrm_mutex_lock(qr_lock); - m = queued_requests; - while (m) { - if (m->hc->conn_fd == fd) { - if (prev) - if (!(prev->next = m->next)) - last_qr = prev; - else - if (!(queued_requests = m->next)) - last_qr = NULL; - destroy_conn(m->hc); - free(m->hc); - free(m); - break; - } - prev = m; - m = m->next; - } - tsrm_mutex_unlock(qr_lock); -} - -#endif - -static off_t thttpd_real_php_request(httpd_conn *hc, int show_source) -{ - TG(hc) = hc; - hc->bytes_sent = 0; - - if (hc->contentlength != -1) { - hc->should_linger = 1; - hc->do_keep_alive = 0; - } - - if (hc->contentlength != -1 - && SIZEOF_UNCONSUMED_BYTES() < hc->contentlength) { - hc->read_body_into_mem = 1; - return 0; - } - - thttpd_request_ctor(); - - thttpd_module_main(show_source); - - /* disable kl, if no content-length was seen or Connection: was set */ - if (TG(seen_cl) == 0 || TG(seen_cn) == 1) { - TG(hc)->do_keep_alive = 0; - } - - if (TG(sbuf).c != 0) { - if (TG(hc)->response) - free(TG(hc)->response); - - TG(hc)->response = TG(sbuf).c; - TG(hc)->responselen = TG(sbuf).len; - TG(hc)->maxresponse = TG(sbuf).a; - - TG(sbuf).c = 0; - TG(sbuf).len = 0; - TG(sbuf).a = 0; - } - - thttpd_request_dtor(); - - return 0; -} - -off_t thttpd_php_request(httpd_conn *hc, int show_source) -{ -#ifdef ZTS - queue_request(hc); -#else - return thttpd_real_php_request(hc, show_source); -#endif -} - -void thttpd_register_on_close(void (*arg)(int)) -{ - TG(on_close) = arg; -} - -void thttpd_closed_conn(int fd) -{ - if (TG(on_close)) TG(on_close)(fd); -} - -int thttpd_get_fd(void) -{ - return TG(hc)->conn_fd; -} - -void thttpd_set_dont_close(void) -{ -#ifndef PREMIUM_THTTPD - TG(hc)->file_address = (char *) 1; -#endif -} - - -void thttpd_php_init(void) -{ - char *ini; - -#ifdef ZTS - tsrm_startup(1, 1, 0, NULL); - ts_allocate_id(&thttpd_globals_id, sizeof(php_thttpd_globals), NULL, NULL); - qr_lock = tsrm_mutex_alloc(); - thttpd_register_on_close(remove_dead_conn); -#endif - - if ((ini = getenv("PHP_INI_PATH"))) { - thttpd_sapi_module.php_ini_path_override = ini; - } - - sapi_startup(&thttpd_sapi_module); - thttpd_sapi_module.startup(&thttpd_sapi_module); - - { - - SG(server_context) = (void *) 1; - } -} - -void thttpd_php_shutdown(void) -{ - - if (SG(server_context) != NULL) { - thttpd_sapi_module.shutdown(&thttpd_sapi_module); - sapi_shutdown(); -#ifdef ZTS - tsrm_shutdown(); -#endif - } -} diff --git a/sapi/thttpd/thttpd_patch b/sapi/thttpd/thttpd_patch deleted file mode 100644 index 1463d8fe0a..0000000000 --- a/sapi/thttpd/thttpd_patch +++ /dev/null @@ -1,2377 +0,0 @@ -diff -ur thttpd-2.21b/Makefile.in thttpd-2.21b-cool/Makefile.in ---- thttpd-2.21b/Makefile.in Thu Mar 29 20:36:21 2001 -+++ thttpd-2.21b-cool/Makefile.in Sat Sep 20 14:43:20 2003 -@@ -46,13 +46,15 @@ - - # You shouldn't need to edit anything below here. - -+include php_makefile -+ - CC = @CC@ - CCOPT = @V_CCOPT@ - DEFS = @DEFS@ --INCLS = -I. -+INCLS = -I. $(PHP_CFLAGS) - CFLAGS = $(CCOPT) $(DEFS) $(INCLS) --LDFLAGS = @LDFLAGS@ --LIBS = @LIBS@ -+LDFLAGS = @LDFLAGS@ $(PHP_LDFLAGS) -+LIBS = @LIBS@ $(PHP_LIBS) - NETLIBS = @V_NETLIBS@ - INSTALL = @INSTALL@ - -@@ -62,7 +64,7 @@ - @rm -f $@ - $(CC) $(CFLAGS) -c $*.c - --SRC = thttpd.c libhttpd.c fdwatch.c mmc.c timers.c match.c tdate_parse.c syslog.c -+SRC = thttpd.c libhttpd.c fdwatch.c mmc.c timers.c match.c tdate_parse.c syslog.c php_thttpd.c - - OBJ = $(SRC:.c=.o) @LIBOBJS@ - -@@ -77,7 +79,7 @@ - all: this subdirs - this: $(ALL) - --thttpd: $(OBJ) -+thttpd: $(OBJ) libphp7.a - @rm -f $@ - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $(NETLIBS) - -diff -ur thttpd-2.21b/config.h thttpd-2.21b-cool/config.h ---- thttpd-2.21b/config.h Mon Apr 9 23:57:36 2001 -+++ thttpd-2.21b-cool/config.h Sat Sep 20 14:43:20 2003 -@@ -82,6 +82,11 @@ - */ - #define IDLE_READ_TIMELIMIT 60 - -+/* CONFIGURE: How many seconds to allow for reading the subsequent requests -+** on a keep-alive connection. Should be simiar to LINGER_TIME -+*/ -+#define IDLE_KEEPALIVE_TIMELIMIT 2 -+ - /* CONFIGURE: How many seconds before an idle connection gets closed. - */ - #define IDLE_SEND_TIMELIMIT 300 -@@ -316,7 +321,7 @@ - /* CONFIGURE: A list of index filenames to check. The files are searched - ** for in this order. - */ --#define INDEX_NAMES "index.html", "index.htm", "Default.htm", "index.cgi" -+#define INDEX_NAMES "index.php", "index.html", "index.htm", "Default.htm", "index.cgi" - - /* CONFIGURE: If this is defined then thttpd will automatically generate - ** index pages for directories that don't have an explicit index file. -diff -ur thttpd-2.21b/configure thttpd-2.21b-cool/configure ---- thttpd-2.21b/configure Sat Apr 21 02:07:14 2001 -+++ thttpd-2.21b-cool/configure Sat Sep 20 14:43:20 2003 -@@ -1021,7 +1021,7 @@ - fi - echo "$ac_t""$CPP" 1>&6 - --for ac_hdr in fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h -+for ac_hdr in fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h netinet/tcp.h - do - ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` - echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -diff -ur thttpd-2.21b/configure.in thttpd-2.21b-cool/configure.in ---- thttpd-2.21b/configure.in Sat Apr 21 02:06:23 2001 -+++ thttpd-2.21b-cool/configure.in Sat Sep 20 14:43:20 2003 -@@ -64,7 +64,7 @@ - AC_MSG_RESULT(no) - fi - --AC_CHECK_HEADERS(fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h) -+AC_CHECK_HEADERS(fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h netinet/tcp.h) - AC_HEADER_TIME - AC_HEADER_DIRENT - -diff -ur thttpd-2.21b/fdwatch.c thttpd-2.21b-cool/fdwatch.c ---- thttpd-2.21b/fdwatch.c Fri Apr 13 07:36:08 2001 -+++ thttpd-2.21b-cool/fdwatch.c Sat Sep 20 14:43:20 2003 -@@ -419,6 +419,7 @@ - if ( pollfds == (struct pollfd*) 0 || poll_fdidx == (int*) 0 || - poll_rfdidx == (int*) 0 ) - return -1; -+ memset(pollfds, 0, sizeof(struct pollfd) * nfiles); - return 0; - } - -@@ -460,7 +461,7 @@ - - ridx = 0; - for ( i = 0; i < npollfds; ++i ) -- if ( pollfds[i].revents & ( POLLIN | POLLOUT ) ) -+ if ( pollfds[i].revents & ( POLLIN | POLLOUT | POLLERR | POLLHUP | POLLNVAL ) ) - poll_rfdidx[ridx++] = pollfds[i].fd; - - return r; -@@ -472,8 +473,8 @@ - { - switch ( fd_rw[fd] ) - { -- case FDW_READ: return pollfds[poll_fdidx[fd]].revents & POLLIN; -- case FDW_WRITE: return pollfds[poll_fdidx[fd]].revents & POLLOUT; -+ case FDW_READ: return pollfds[poll_fdidx[fd]].revents & ( POLLIN | POLLERR | POLLHUP | POLLNVAL ); -+ case FDW_WRITE: return pollfds[poll_fdidx[fd]].revents & ( POLLOUT | POLLERR | POLLHUP | POLLNVAL ); - default: return 0; - } - } -diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c ---- thttpd-2.21b/libhttpd.c Tue Apr 24 00:42:40 2001 -+++ thttpd-2.21b-cool/libhttpd.c Sat Sep 20 14:43:29 2003 -@@ -56,6 +56,10 @@ - #include <unistd.h> - #include <stdarg.h> - -+#ifdef HAVE_NETINET_TCP_H -+#include <netinet/tcp.h> -+#endif -+ - #ifdef HAVE_OSRELDATE_H - #include <osreldate.h> - #endif /* HAVE_OSRELDATE_H */ -@@ -85,6 +89,12 @@ - #include "match.h" - #include "tdate_parse.h" - -+#include "php_thttpd.h" -+ -+#ifdef __CYGWIN__ -+# define timezone _timezone -+#endif -+ - #ifndef STDIN_FILENO - #define STDIN_FILENO 0 - #endif -@@ -111,7 +121,7 @@ - static int initialize_listen_socket( httpd_sockaddr* saP ); - static void unlisten( httpd_server* hs ); - static void add_response( httpd_conn* hc, char* str ); --static void send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads, char* type, int length, time_t mod ); -+static void send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads, char* type, int length, time_t mod, const char *, size_t ); - static void send_response( httpd_conn* hc, int status, char* title, char* extraheads, char* form, char* arg ); - static void send_response_tail( httpd_conn* hc ); - static void defang( char* str, char* dfstr, int dfsize ); -@@ -242,6 +252,10 @@ - free( (void*) hs->cwd ); - if ( hs->cgi_pattern != (char*) 0 ) - free( (void*) hs->cgi_pattern ); -+ if ( hs->php_pattern != (char*) 0 ) -+ free( (void*) hs->php_pattern ); -+ if ( hs->phps_pattern != (char*) 0 ) -+ free( (void*) hs->phps_pattern ); - if ( hs->charset != (char*) 0 ) - free( (void*) hs->charset ); - if ( hs->url_pattern != (char*) 0 ) -@@ -249,6 +263,7 @@ - if ( hs->local_pattern != (char*) 0 ) - free( (void*) hs->local_pattern ); - free( (void*) hs ); -+ thttpd_php_shutdown(); - } - - -@@ -257,7 +272,8 @@ - char* hostname, httpd_sockaddr* sa4P, httpd_sockaddr* sa6P, int port, - char* cgi_pattern, char* charset, char* cwd, int no_log, FILE* logfp, - int no_symlink, int vhost, int global_passwd, char* url_pattern, -- char* local_pattern, int no_empty_referers ) -+ char* local_pattern, int no_empty_referers, char* php_pattern, -+ char* phps_pattern ) - { - httpd_server* hs; - static char ghnbuf[256]; -@@ -312,6 +328,8 @@ - } - - hs->port = port; -+ hs->php_pattern = strdup(php_pattern); -+ hs->phps_pattern = strdup(phps_pattern); - if ( cgi_pattern == (char*) 0 ) - hs->cgi_pattern = (char*) 0; - else -@@ -329,7 +347,7 @@ - while ( ( cp = strstr( hs->cgi_pattern, "|/" ) ) != (char*) 0 ) - (void) strcpy( cp + 1, cp + 2 ); - } -- hs->charset = strdup( charset ); -+ hs->charset = strdup( charset ); - hs->cwd = strdup( cwd ); - if ( hs->cwd == (char*) 0 ) - { -@@ -385,6 +403,8 @@ - return (httpd_server*) 0; - } - -+ thttpd_php_init(); -+ - /* Done initializing. */ - if ( hs->binding_hostname == (char*) 0 ) - syslog( LOG_INFO, "%.80s starting on port %d", SERVER_SOFTWARE, hs->port ); -@@ -418,6 +438,11 @@ - } - (void) fcntl( listen_fd, F_SETFD, 1 ); - -+#if defined(TCP_DEFER_ACCEPT) && defined(SOL_TCP) -+ on = 30; /* give clients 30s to send first data packet */ -+ setsockopt(listen_fd, SOL_TCP, TCP_DEFER_ACCEPT, &on, sizeof(on)); -+#endif -+ - /* Allow reuse of local addresses. */ - on = 1; - if ( setsockopt( -@@ -582,6 +607,9 @@ - /* And send it, if necessary. */ - if ( hc->responselen > 0 ) - { -+/* -+printf("**RESPONSE [%d]** len = %d\n%*.*s\n", hc->conn_fd, hc->responselen, hc->responselen, hc->responselen, hc->response); -+*/ - (void) write( hc->conn_fd, hc->response, hc->responselen ); - hc->responselen = 0; - } -@@ -619,18 +647,22 @@ - } - } - -+extern time_t httpd_time_now; -+extern char httpd_now_buf[]; -+ -+#define SMART_STR_USE_REALLOC -+ -+#include "zend_smart_str.h" - - static void --send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads, char* type, int length, time_t mod ) -+send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads, char* type, int length, time_t mod, const char *last_modified, size_t last_modified_len) - { -- time_t now; - const char* rfc1123fmt = "%a, %d %b %Y %H:%M:%S GMT"; -- char nowbuf[100]; - char modbuf[100]; -- char fixed_type[500]; -- char buf[1000]; - int partial_content; -- -+ smart_str s = {0}; -+ int type_len; -+ - hc->status = status; - hc->bytes_to_send = length; - if ( hc->mime_flag ) -@@ -649,41 +681,89 @@ - else - partial_content = 0; - -- now = time( (time_t*) 0 ); - if ( mod == (time_t) 0 ) -- mod = now; -- (void) strftime( nowbuf, sizeof(nowbuf), rfc1123fmt, gmtime( &now ) ); -- (void) strftime( modbuf, sizeof(modbuf), rfc1123fmt, gmtime( &mod ) ); -- (void) my_snprintf( -- fixed_type, sizeof(fixed_type), type, hc->hs->charset ); -- (void) my_snprintf( buf, sizeof(buf), -- "%.20s %d %s\r\nServer: %s\r\nContent-Type: %s\r\nDate: %s\r\nLast-Modified: %s\r\nAccept-Ranges: bytes\r\nConnection: close\r\n", -- hc->protocol, status, title, EXPOSED_SERVER_SOFTWARE, fixed_type, -- nowbuf, modbuf ); -- add_response( hc, buf ); -+ mod = httpd_time_now; -+ -+ if (last_modified == 0) { -+ (void) strftime( modbuf, sizeof(modbuf), rfc1123fmt, gmtime( &mod ) ); -+ last_modified = modbuf; -+ last_modified_len = strlen(modbuf); -+ } -+ -+ type_len = strlen(type); -+ -+ if (hc->response) { -+ s.c = hc->response; -+ s.len = 0; -+ s.a = hc->maxresponse; -+ hc->response = 0; -+ hc->maxresponse = 0; -+ } -+ -+ smart_str_appends(&s, "HTTP/1.1 "); -+ smart_str_append_long(&s, status); -+ smart_str_appends(&s, " HTTP\r\nServer: " EXPOSED_SERVER_SOFTWARE "\r\n" -+ "Content-Type: "); -+ -+ if (type[type_len-2] == '%' && type[type_len-1] == 's') { -+ smart_str_appendl(&s, type, type_len - 2); -+ smart_str_appends(&s, hc->hs->charset); -+ } else { -+ smart_str_appendl(&s, type, type_len); -+ } -+ -+ -+ smart_str_appends(&s, "\r\nDate: "); -+ smart_str_appends(&s, httpd_now_buf); -+ smart_str_appends(&s, "\r\nLast-Modified: "); -+ smart_str_appendl(&s, last_modified, last_modified_len); -+ smart_str_appends(&s, "\r\nAccept-Ranges: bytes\r\n"); -+ - if ( encodings[0] != '\0' ) - { -- (void) my_snprintf( buf, sizeof(buf), -- "Content-Encoding: %s\r\n", encodings ); -- add_response( hc, buf ); -+ smart_str_appends(&s, "Content-Encoding: "); -+ smart_str_appends(&s, encodings); -+ smart_str_appends(&s, "\r\n"); - } - if ( partial_content ) - { -- (void) my_snprintf( buf, sizeof(buf), -- "Content-Range: bytes %ld-%ld/%d\r\nContent-Length: %ld\r\n", -- (long) hc->init_byte_loc, (long) hc->end_byte_loc, length, -- (long) ( hc->end_byte_loc - hc->init_byte_loc + 1 ) ); -- add_response( hc, buf ); -+ -+ smart_str_appends(&s, "Content-Range: bytes "); -+ smart_str_append_long(&s, hc->init_byte_loc); -+ smart_str_appendc(&s, '-'); -+ smart_str_append_long(&s, hc->end_byte_loc); -+ smart_str_appendc(&s, '/'); -+ smart_str_append_long(&s, length); -+ smart_str_appends(&s, "\r\nContent-Length: "); -+ smart_str_append_long(&s, hc->end_byte_loc - hc->init_byte_loc + 1); -+ smart_str_appends(&s, "\r\n"); -+ - } - else if ( length >= 0 ) - { -- (void) my_snprintf( buf, sizeof(buf), -- "Content-Length: %d\r\n", length ); -- add_response( hc, buf ); -+ smart_str_appends(&s, "Content-Length: "); -+ smart_str_append_long(&s, length); -+ smart_str_appends(&s, "\r\n"); - } -+ else { -+ hc->do_keep_alive = 0; -+ } - if ( extraheads[0] != '\0' ) -- add_response( hc, extraheads ); -- add_response( hc, "\r\n" ); -+ smart_str_appends(&s, extraheads); -+ if (hc->do_keep_alive) { -+ smart_str_appends(&s, "Connection: keep-alive\r\n\r\n" ); -+ } else { -+ smart_str_appends(&s, "Connection: close\r\n\r\n" ); -+ } -+ smart_str_0(&s); -+ -+ if (hc->response) { -+ free(hc->response); -+ } -+ hc->response = s.c; -+ hc->maxresponse = s.a; -+ hc->responselen = s.len; -+ - } - } - -@@ -725,7 +805,7 @@ - { - char defanged_arg[1000], buf[2000]; - -- send_mime( hc, status, title, "", extraheads, "text/html", -1, 0 ); -+ send_mime( hc, status, title, "", extraheads, "text/html", -1, 0, 0, 0 ); - (void) my_snprintf( buf, sizeof(buf), - "<HTML><HEAD><TITLE>%d %s</TITLE></HEAD>\n<BODY BGCOLOR=\"#cc9999\"><H2>%d %s</H2>\n", - status, title, status, title ); -@@ -764,7 +844,7 @@ - char* cp2; - - for ( cp1 = str, cp2 = dfstr; -- *cp1 != '\0' && cp2 - dfstr < dfsize - 1; -+ *cp1 != '\0' && cp2 - dfstr < dfsize - 5; - ++cp1, ++cp2 ) - { - switch ( *cp1 ) -@@ -834,7 +914,7 @@ - fp = fopen( filename, "r" ); - if ( fp == (FILE*) 0 ) - return 0; -- send_mime( hc, status, title, "", extraheads, "text/html", -1, 0 ); -+ send_mime( hc, status, title, "", extraheads, "text/html", -1, 0, 0, 0 ); - for (;;) - { - r = fread( buf, 1, sizeof(buf) - 1, fp ); -@@ -1336,6 +1416,9 @@ - if ( hc->tildemapped ) - return 1; - -+ if ( hc->hostname[0] == '.' || strchr( hc->hostname, '/' ) != (char*) 0 ) -+ return 0; -+ - /* Figure out the host directory. */ - #ifdef VHOST_DIRLEVELS - httpd_realloc_str( -@@ -1436,7 +1519,7 @@ - restlen = strlen( path ); - httpd_realloc_str( &rest, &maxrest, restlen ); - (void) strcpy( rest, path ); -- if ( rest[restlen - 1] == '/' ) -+ if ( restlen > 0 && rest[restlen - 1] == '/' ) - rest[--restlen] = '\0'; /* trim trailing slash */ - if ( ! tildemapped ) - /* Remove any leading slashes. */ -@@ -1603,6 +1686,70 @@ - - - int -+httpd_request_reset(httpd_conn* hc, int preserve_read_buf ) -+{ -+ if (!preserve_read_buf) { -+ hc->read_idx = 0; -+ hc->checked_idx = 0; -+ } -+ -+ if (hc->read_buf_is_mmap) { -+ hc->read_buf_is_mmap = 0; -+ munmap(hc->read_buf, hc->read_size); -+ hc->read_buf = NULL; -+ hc->read_size = 0; -+ httpd_realloc_str( &hc->read_buf, &hc->read_size, 500 ); -+ } -+ hc->checked_state = CHST_FIRSTWORD; -+ hc->method = METHOD_UNKNOWN; -+ hc->status = 0; -+ hc->bytes_to_send = 0; -+ hc->bytes_sent = 0; -+ hc->encodedurl = ""; -+ hc->decodedurl[0] = '\0'; -+ hc->protocol = "UNKNOWN"; -+ hc->origfilename[0] = '\0'; -+ hc->expnfilename[0] = '\0'; -+ hc->encodings[0] = '\0'; -+ hc->pathinfo[0] = '\0'; -+ hc->query[0] = '\0'; -+ hc->referer = ""; -+ hc->useragent = ""; -+ hc->accept[0] = '\0'; -+ hc->accepte[0] = '\0'; -+ hc->acceptl = ""; -+ hc->cookie = ""; -+ hc->contenttype = ""; -+ hc->reqhost[0] = '\0'; -+ hc->hdrhost = ""; -+ hc->hostdir[0] = '\0'; -+ hc->authorization = ""; -+ hc->remoteuser[0] = '\0'; -+ hc->response[0] = '\0'; -+#ifdef TILDE_MAP_2 -+ hc->altdir[0] = '\0'; -+#endif /* TILDE_MAP_2 */ -+ hc->responselen = 0; -+ hc->if_modified_since = (time_t) -1; -+ hc->range_if = (time_t) -1; -+ hc->contentlength = -1; -+ hc->type = ""; -+ hc->hostname = (char*) 0; -+ hc->mime_flag = 1; -+ hc->one_one = 0; -+ hc->got_range = 0; -+ hc->tildemapped = 0; -+ hc->init_byte_loc = 0; -+ hc->end_byte_loc = -1; -+ hc->keep_alive = 0; -+ hc->do_keep_alive = 0; -+ hc->should_linger = 0; -+ hc->file_address = (char*) 0; -+ hc->read_body_into_mem = 0; -+ return GC_OK; -+} -+ -+int - httpd_get_conn( httpd_server* hs, int listen_fd, httpd_conn* hc ) - { - httpd_sockaddr sa; -@@ -1612,6 +1759,7 @@ - { - hc->read_size = 0; - httpd_realloc_str( &hc->read_buf, &hc->read_size, 500 ); -+ hc->read_buf_is_mmap = 0; - hc->maxdecodedurl = - hc->maxorigfilename = hc->maxexpnfilename = hc->maxencodings = - hc->maxpathinfo = hc->maxquery = hc->maxaccept = -@@ -1631,12 +1779,19 @@ - httpd_realloc_str( &hc->reqhost, &hc->maxreqhost, 0 ); - httpd_realloc_str( &hc->hostdir, &hc->maxhostdir, 0 ); - httpd_realloc_str( &hc->remoteuser, &hc->maxremoteuser, 0 ); -- httpd_realloc_str( &hc->response, &hc->maxresponse, 0 ); -+ httpd_realloc_str( &hc->response, &hc->maxresponse, 350 ); - #ifdef TILDE_MAP_2 - httpd_realloc_str( &hc->altdir, &hc->maxaltdir, 0 ); - #endif /* TILDE_MAP_2 */ - hc->initialized = 1; - } -+ if (hc->read_buf_is_mmap) { -+ hc->read_buf_is_mmap = 0; -+ munmap(hc->read_buf, hc->read_size); -+ hc->read_buf = NULL; -+ hc->read_size = 0; -+ httpd_realloc_str( &hc->read_buf, &hc->read_size, 500 ); -+ } - - /* Accept the new connection. */ - sz = sizeof(sa); -@@ -1657,53 +1812,12 @@ - hc->hs = hs; - memset( &hc->client_addr, 0, sizeof(hc->client_addr) ); - memcpy( &hc->client_addr, &sa, sockaddr_len( &sa ) ); -- hc->read_idx = 0; -- hc->checked_idx = 0; -- hc->checked_state = CHST_FIRSTWORD; -- hc->method = METHOD_UNKNOWN; -- hc->status = 0; -- hc->bytes_to_send = 0; -- hc->bytes_sent = 0; -- hc->encodedurl = ""; -- hc->decodedurl[0] = '\0'; -- hc->protocol = "UNKNOWN"; -- hc->origfilename[0] = '\0'; -- hc->expnfilename[0] = '\0'; -- hc->encodings[0] = '\0'; -- hc->pathinfo[0] = '\0'; -- hc->query[0] = '\0'; -- hc->referer = ""; -- hc->useragent = ""; -- hc->accept[0] = '\0'; -- hc->accepte[0] = '\0'; -- hc->acceptl = ""; -- hc->cookie = ""; -- hc->contenttype = ""; -- hc->reqhost[0] = '\0'; -- hc->hdrhost = ""; -- hc->hostdir[0] = '\0'; -- hc->authorization = ""; -- hc->remoteuser[0] = '\0'; -- hc->response[0] = '\0'; --#ifdef TILDE_MAP_2 -- hc->altdir[0] = '\0'; --#endif /* TILDE_MAP_2 */ -- hc->responselen = 0; -- hc->if_modified_since = (time_t) -1; -- hc->range_if = (time_t) -1; -- hc->contentlength = -1; -- hc->type = ""; -- hc->hostname = (char*) 0; -- hc->mime_flag = 1; -- hc->one_one = 0; -- hc->got_range = 0; -- hc->tildemapped = 0; -- hc->init_byte_loc = 0; -- hc->end_byte_loc = -1; -- hc->keep_alive = 0; -- hc->should_linger = 0; -- hc->file_address = (char*) 0; -- return GC_OK; -+ -+/* -+printf("doing httpd_get_con(%d)\n", hc->conn_fd); -+*/ -+ -+ return httpd_request_reset(hc, 0); - } - - -@@ -1720,6 +1834,9 @@ - { - char c; - -+/* -+printf("**REQUEST [%d]**\n%*.*s\n", hc->conn_fd, hc->read_idx, hc->read_idx, hc->read_buf); -+*/ - for ( ; hc->checked_idx < hc->read_idx; ++hc->checked_idx ) - { - c = hc->read_buf[hc->checked_idx]; -@@ -1912,8 +2029,11 @@ - eol = strpbrk( protocol, " \t\n\r" ); - if ( eol != (char*) 0 ) - *eol = '\0'; -- if ( strcasecmp( protocol, "HTTP/1.0" ) != 0 ) -+ if ( strcasecmp( protocol, "HTTP/1.0" ) != 0 ) { - hc->one_one = 1; -+ hc->keep_alive = 1; -+ hc->do_keep_alive = 1; -+ } - } - } - /* Check for HTTP/1.1 absolute URL. */ -@@ -2129,6 +2249,7 @@ - cp = &buf[11]; - cp += strspn( cp, " \t" ); - if ( strcasecmp( cp, "keep-alive" ) == 0 ) -+ hc->do_keep_alive = 1; - hc->keep_alive = 1; - } - #ifdef LOG_UNKNOWN_HEADERS -@@ -2168,6 +2289,9 @@ - } - } - -+/* -+printf("one_one = %d keep_alive = %d\n", hc->one_one, hc->keep_alive); -+*/ - if ( hc->one_one ) - { - /* Check that HTTP/1.1 requests specify a host, as required. */ -@@ -2177,14 +2301,14 @@ - return -1; - } - -- /* If the client wants to do keep-alives, it might also be doing -- ** pipelining. There's no way for us to tell. Since we don't -- ** implement keep-alives yet, if we close such a connection there -- ** might be unread pipelined requests waiting. So, we have to -- ** do a lingering close. -+ /* -+ ** Disable keep alive support for bad browsers, -+ ** list taken from Apache 1.3.19 - */ -- if ( hc->keep_alive ) -- hc->should_linger = 1; -+ if ( hc->do_keep_alive && -+ ( strstr(hc->useragent, "Mozilla/2") != NULL || -+ strstr(hc->useragent, "MSIE 4.0b2;") != NULL)) -+ hc->do_keep_alive = 0; - } - - /* Ok, the request has been parsed. Now we resolve stuff that -@@ -2349,15 +2473,24 @@ - - - void --httpd_close_conn( httpd_conn* hc, struct timeval* nowP ) -- { -- make_log_entry( hc, nowP ); -+httpd_complete_request( httpd_conn* hc, struct timeval* nowP) -+{ -+ if (hc->method != METHOD_UNKNOWN) -+ make_log_entry( hc, nowP ); - -- if ( hc->file_address != (char*) 0 ) -+ if ( hc->file_address == (char*) 1 ) -+ { -+ thttpd_closed_conn(hc->conn_fd); -+ } else if ( hc->file_address != (char*) 0 ) - { - mmc_unmap( hc->file_address, &(hc->sb), nowP ); - hc->file_address = (char*) 0; - } -+ } -+ -+void -+httpd_close_conn( httpd_conn* hc, struct timeval* nowP ) -+{ - if ( hc->conn_fd >= 0 ) - { - (void) close( hc->conn_fd ); -@@ -2370,7 +2503,12 @@ - { - if ( hc->initialized ) - { -- free( (void*) hc->read_buf ); -+ -+ if ( hc->read_buf_is_mmap ) { -+ munmap( hc->read_buf, hc->read_size ); -+ } else { -+ free( (void*) hc->read_buf ); -+ } - free( (void*) hc->decodedurl ); - free( (void*) hc->origfilename ); - free( (void*) hc->expnfilename ); -@@ -2556,7 +2694,7 @@ - return -1; - } - -- send_mime( hc, 200, ok200title, "", "", "text/html", -1, hc->sb.st_mtime ); -+ send_mime( hc, 200, ok200title, "", "", "text/html", -1, hc->sb.st_mtime, 0, 0 ); - if ( hc->method == METHOD_HEAD ) - closedir( dirp ); - else if ( hc->method == METHOD_GET ) -@@ -3026,11 +3164,9 @@ - post_post_garbage_hack( httpd_conn* hc ) - { - char buf[2]; -- int r; - -- r = recv( hc->conn_fd, buf, sizeof(buf), MSG_PEEK ); -- if ( r > 0 ) -- (void) read( hc->conn_fd, buf, r ); -+ fcntl(hc->conn_fd, F_SETFL, O_NONBLOCK); -+ (void) read( hc->conn_fd, buf, 2 ); - } - - -@@ -3313,6 +3449,11 @@ - int r; - ClientData client_data; - -+ /* -+ ** We are not going to leave the socket open after a CGI... too hard -+ */ -+ hc->do_keep_alive = 0; -+ - if ( hc->method == METHOD_GET || hc->method == METHOD_POST ) - { - httpd_clear_ndelay( hc->conn_fd ); -@@ -3369,6 +3510,7 @@ - int expnlen, indxlen; - char* cp; - char* pi; -+ int nocache = 0; - - expnlen = strlen( hc->expnfilename ); - -@@ -3561,6 +3703,16 @@ - match( hc->hs->cgi_pattern, hc->expnfilename ) ) - return cgi( hc ); - -+ if ( hc->hs->php_pattern != (char*) 0 && -+ match( hc->hs->php_pattern, hc->expnfilename)) { -+ return thttpd_php_request( hc, 0 ); -+ } -+ -+ if ( hc->hs->phps_pattern != (char*) 0 && -+ match( hc->hs->phps_pattern, hc->expnfilename)) { -+ return thttpd_php_request( hc, 1 ); -+ } -+ - /* It's not CGI. If it's executable or there's pathinfo, someone's - ** trying to either serve or run a non-CGI file as CGI. Either case - ** is prohibited. -@@ -3594,32 +3746,46 @@ - hc->end_byte_loc = hc->sb.st_size - 1; - - figure_mime( hc ); -+ if ( strncmp(hc->decodedurl, "/nocache/", sizeof("/nocache/") - 1 ) == 0 ) -+ nocache = 1; - - if ( hc->method == METHOD_HEAD ) - { - send_mime( - hc, 200, ok200title, hc->encodings, "", hc->type, hc->sb.st_size, -- hc->sb.st_mtime ); -+ hc->sb.st_mtime, 0, 0 ); - } -- else if ( hc->if_modified_since != (time_t) -1 && -+ else if ( !nocache && hc->if_modified_since != (time_t) -1 && - hc->if_modified_since >= hc->sb.st_mtime ) - { -- hc->method = METHOD_HEAD; - send_mime( -- hc, 304, err304title, hc->encodings, "", hc->type, hc->sb.st_size, -- hc->sb.st_mtime ); -+ hc, 304, err304title, hc->encodings, "", hc->type, -1, -+ hc->sb.st_mtime, 0, 0 ); - } - else - { -- hc->file_address = mmc_map( hc->expnfilename, &(hc->sb), nowP ); -+ char *extraheads = ""; -+ char *lm; -+ size_t lml; -+ -+ if ( nocache ) -+ { -+ extraheads = "Expires: Thu, 19 Nov 1981 08:52:00 GMT\r\n" -+ "Cache-Control: no-store, no-cache, must-revalidate, " -+ "post-check=0, pre-check=0\r\n" -+ "Pragma: no-cache\r\n"; -+ } -+ -+ hc->file_address = mmc_map( hc->expnfilename, &(hc->sb), nowP, nocache, &lm, &lml ); - if ( hc->file_address == (char*) 0 ) - { - httpd_send_err( hc, 500, err500title, "", err500form, hc->encodedurl ); - return -1; - } -+ - send_mime( -- hc, 200, ok200title, hc->encodings, "", hc->type, hc->sb.st_size, -- hc->sb.st_mtime ); -+ hc, 200, ok200title, hc->encodings, extraheads, hc->type, hc->sb.st_size, -+ hc->sb.st_mtime, lm, lml ); - } - - return 0; -@@ -3638,6 +3804,9 @@ - return r; - } - -+#define smart_str_append_const(a,b) smart_str_appendl(a,b,sizeof(b)-1) -+ -+static smart_str bentries; - - static void - make_log_entry( httpd_conn* hc, struct timeval* nowP ) -@@ -3648,88 +3817,62 @@ - - if ( hc->hs->no_log ) - return; -- -- /* This is straight CERN Combined Log Format - the only tweak -- ** being that if we're using syslog() we leave out the date, because -- ** syslogd puts it in. The included syslogtocern script turns the -- ** results into true CERN format. -- */ -- - /* Format remote user. */ - if ( hc->remoteuser[0] != '\0' ) -- ru = hc->remoteuser; -+ ru = hc->remoteuser; - else -- ru = "-"; -+ ru = "-"; - /* If we're vhosting, prepend the hostname to the url. This is - ** a little weird, perhaps writing separate log files for - ** each vhost would make more sense. - */ -- if ( hc->hs->vhost && ! hc->tildemapped ) -- (void) my_snprintf( url, sizeof(url), -- "/%.100s%.200s", -- hc->hostname == (char*) 0 ? hc->hs->server_hostname : hc->hostname, -- hc->encodedurl ); -- else -- (void) my_snprintf( url, sizeof(url), -- "%.200s", hc->encodedurl ); -- /* Format the bytes. */ -- if ( (long) hc->bytes_sent >= 0 ) -- (void) my_snprintf( bytes, sizeof(bytes), -- "%ld", (long) hc->bytes_sent ); -- else -- (void) strcpy( bytes, "-" ); - - /* Logfile or syslog? */ - if ( hc->hs->logfp != (FILE*) 0 ) -- { -- time_t now; -- struct tm* t; -- const char* cernfmt_nozone = "%d/%b/%Y:%H:%M:%S"; -- char date_nozone[100]; -- int zone; -- char sign; -- char date[100]; -- -- /* Get the current time, if necessary. */ -- if ( nowP != (struct timeval*) 0 ) -- now = nowP->tv_sec; -- else -- now = time( (time_t*) 0 ); -- /* Format the time, forcing a numeric timezone (some log analyzers -- ** are stoooopid about this). -- */ -- t = localtime( &now ); -- (void) strftime( date_nozone, sizeof(date_nozone), cernfmt_nozone, t ); --#ifdef HAVE_TM_GMTOFF -- zone = t->tm_gmtoff / 60L; --#else -- zone = -timezone / 60L; -- /* Probably have to add something about daylight time here. */ --#endif -- if ( zone >= 0 ) -- sign = '+'; -- else -- { -- sign = '-'; -- zone = -zone; -- } -- zone = ( zone / 60 ) * 100 + zone % 60; -- (void) my_snprintf( date, sizeof(date), -- "%s %c%04d", date_nozone, sign, zone ); -- /* And write the log entry. */ -- (void) fprintf( hc->hs->logfp, -- "%.80s - %.80s [%s] \"%.80s %.300s %.80s\" %d %s \"%.200s\" \"%.80s\"\n", -- httpd_ntoa( &hc->client_addr ), ru, date, -- httpd_method_str( hc->method ), url, hc->protocol, -- hc->status, bytes, hc->referer, hc->useragent ); -- (void) fflush( hc->hs->logfp ); /* don't need to flush every time */ -- } -- else -- syslog( LOG_INFO, -- "%.80s - %.80s \"%.80s %.200s %.80s\" %d %s \"%.200s\" \"%.80s\"", -- httpd_ntoa( &hc->client_addr ), ru, -- httpd_method_str( hc->method ), url, hc->protocol, -- hc->status, bytes, hc->referer, hc->useragent ); -+ { -+ /* XXXXXXX */ -+ -+ smart_str_appends(&bentries, httpd_ntoa(&hc->client_addr)); -+ smart_str_append_const(&bentries, " - "); -+ smart_str_appends(&bentries, ru); -+ smart_str_append_const(&bentries, " ["); -+ smart_str_appendl(&bentries, hc->hs->log_date, hc->hs->log_date_len); -+ smart_str_append_const(&bentries, "] \""); -+ smart_str_appends(&bentries, httpd_method_str(hc->method)); -+ smart_str_appendc(&bentries, ' '); -+ -+ if (hc->hs->vhost && ! hc->tildemapped) { -+ smart_str_appendc(&bentries, '/'); -+ if (hc->hostname) -+ smart_str_appends(&bentries, hc->hostname); -+ else -+ smart_str_appends(&bentries, hc->hs->server_hostname); -+ } -+ smart_str_appends(&bentries, hc->encodedurl); -+ -+ smart_str_appendc(&bentries, ' '); -+ smart_str_appends(&bentries, hc->protocol); -+ smart_str_append_const(&bentries, "\" "); -+ smart_str_append_long(&bentries, hc->status); -+ if (hc->bytes_sent >= 0) { -+ smart_str_appendc(&bentries, ' '); -+ smart_str_append_long(&bentries, hc->bytes_sent); -+ smart_str_append_const(&bentries, " \""); -+ } else { -+ smart_str_append_const(&bentries, " - \""); -+ } -+ smart_str_appends(&bentries, hc->referer); -+ smart_str_append_const(&bentries, "\" \""); -+ smart_str_appends(&bentries, hc->useragent); -+ smart_str_append_const(&bentries, "\"\n"); -+ -+ if (bentries.len > 16384) { -+ int fd = fileno(hc->hs->logfp); -+ write(fd, bentries.c, bentries.len); -+ bentries.len = 0; -+ } -+ } -+ - } - - -@@ -3840,7 +3983,24 @@ - { - #ifdef HAVE_GETNAMEINFO - static char str[200]; -+ static smart_str httpd_ntoa_buf; -+ -+ if (saP->sa_in.sin_family == AF_INET) { -+ unsigned long n = ntohl(saP->sa_in.sin_addr.s_addr); - -+ httpd_ntoa_buf.len = 0; -+ smart_str_append_long(&httpd_ntoa_buf, (n >> 24)); -+ smart_str_appendc(&httpd_ntoa_buf, '.'); -+ smart_str_append_long(&httpd_ntoa_buf, (n >> 16) & 255); -+ smart_str_appendc(&httpd_ntoa_buf, '.'); -+ smart_str_append_long(&httpd_ntoa_buf, (n >> 8) & 255); -+ smart_str_appendc(&httpd_ntoa_buf, '.'); -+ smart_str_append_long(&httpd_ntoa_buf, (n >> 0) & 255); -+ smart_str_0(&httpd_ntoa_buf); -+ -+ return httpd_ntoa_buf.c; -+ } -+ - if ( getnameinfo( &saP->sa, sockaddr_len( saP ), str, sizeof(str), 0, 0, NI_NUMERICHOST ) != 0 ) - { - str[0] = '?'; -diff -ur thttpd-2.21b/libhttpd.h thttpd-2.21b-cool/libhttpd.h ---- thttpd-2.21b/libhttpd.h Tue Apr 24 00:36:50 2001 -+++ thttpd-2.21b-cool/libhttpd.h Sat Sep 20 14:43:20 2003 -@@ -69,6 +69,8 @@ - char* server_hostname; - int port; - char* cgi_pattern; -+ char* php_pattern; -+ char* phps_pattern; - char* charset; - char* cwd; - int listen4_fd, listen6_fd; -@@ -80,6 +82,8 @@ - char* url_pattern; - char* local_pattern; - int no_empty_referers; -+ size_t log_date_len; -+ char log_date[100]; - } httpd_server; - - /* A connection. */ -@@ -88,6 +92,7 @@ - httpd_server* hs; - httpd_sockaddr client_addr; - char* read_buf; -+ char read_buf_is_mmap; - int read_size, read_idx, checked_idx; - int checked_state; - int method; -@@ -132,11 +137,12 @@ - int got_range; - int tildemapped; /* this connection got tilde-mapped */ - off_t init_byte_loc, end_byte_loc; -- int keep_alive; -+ int keep_alive, do_keep_alive; - int should_linger; - struct stat sb; - int conn_fd; - char* file_address; -+ char read_body_into_mem; - } httpd_conn; - - /* Methods. */ -@@ -168,7 +174,8 @@ - char* hostname, httpd_sockaddr* sa4P, httpd_sockaddr* sa6P, int port, - char* cgi_pattern, char* charset, char* cwd, int no_log, FILE* logfp, - int no_symlink, int vhost, int global_passwd, char* url_pattern, -- char* local_pattern, int no_empty_referers ); -+ char* local_pattern, int no_empty_referers, char* php_pattern, -+ char* phps_pattern ); - - /* Change the log file. */ - extern void httpd_set_logfp( httpd_server* hs, FILE* logfp ); -@@ -229,6 +236,8 @@ - ** If you don't have a current timeval handy just pass in 0. - */ - extern void httpd_close_conn( httpd_conn* hc, struct timeval* nowP ); -+void httpd_complete_request( httpd_conn* hc, struct timeval* nowP); -+int httpd_request_reset(httpd_conn* hc,int ); - - /* Call this to de-initialize a connection struct and *really* free the - ** mallocced strings. -diff -ur thttpd-2.21b/mime_encodings.txt thttpd-2.21b-cool/mime_encodings.txt ---- thttpd-2.21b/mime_encodings.txt Wed May 10 03:22:28 2000 -+++ thttpd-2.21b-cool/mime_encodings.txt Sat Sep 20 14:43:20 2003 -@@ -3,6 +3,6 @@ - # A list of file extensions followed by the corresponding MIME encoding. - # Extensions not found in the table proceed to the mime_types table. - --Z x-compress --gz x-gzip -+Z compress -+gz gzip - uu x-uuencode -diff -ur thttpd-2.21b/mime_types.txt thttpd-2.21b-cool/mime_types.txt ---- thttpd-2.21b/mime_types.txt Sat Apr 14 04:53:30 2001 -+++ thttpd-2.21b-cool/mime_types.txt Sat Sep 20 14:43:20 2003 -@@ -1,135 +1,138 @@ --# mime_types.txt --# --# A list of file extensions followed by the corresponding MIME type. --# Extensions not found in the table are returned as text/plain. -- --html text/html; charset=%s --htm text/html; charset=%s --txt text/plain; charset=%s --rtx text/richtext --etx text/x-setext --tsv text/tab-separated-values --css text/css --xml text/xml --dtd text/xml -- --gif image/gif --jpg image/jpeg --jpeg image/jpeg --jpe image/jpeg --jfif image/jpeg --tif image/tiff --tiff image/tiff --pbm image/x-portable-bitmap --pgm image/x-portable-graymap --ppm image/x-portable-pixmap --pnm image/x-portable-anymap --xbm image/x-xbitmap --xpm image/x-xpixmap --xwd image/x-xwindowdump --ief image/ief --png image/png -- --au audio/basic --snd audio/basic --aif audio/x-aiff --aiff audio/x-aiff --aifc audio/x-aiff --ra audio/x-pn-realaudio --ram audio/x-pn-realaudio --rm audio/x-pn-realaudio --rpm audio/x-pn-realaudio-plugin --wav audio/wav --mid audio/midi --midi audio/midi --kar audio/midi --mpga audio/mpeg --mp2 audio/mpeg --mp3 audio/mpeg -- --mpeg video/mpeg --mpg video/mpeg --mpe video/mpeg --qt video/quicktime --mov video/quicktime --avi video/x-msvideo --movie video/x-sgi-movie --mv video/x-sgi-movie --vx video/x-rad-screenplay -- --a application/octet-stream -+ez application/andrew-inset -+hqx application/mac-binhex40 -+cpt application/mac-compactpro -+doc application/msword - bin application/octet-stream -+dms application/octet-stream -+lha application/octet-stream -+lzh application/octet-stream - exe application/octet-stream --dump application/octet-stream --o application/octet-stream --class application/java --js application/x-javascript -+class application/octet-stream -+so application/octet-stream -+dll application/octet-stream -+oda application/oda -+pdf application/pdf - ai application/postscript - eps application/postscript - ps application/postscript --dir application/x-director -+smi application/smil -+smil application/smil -+mif application/vnd.mif -+xls application/vnd.ms-excel -+ppt application/vnd.ms-powerpoint -+wbxml application/vnd.wap.wbxml -+wmlc application/vnd.wap.wmlc -+wmlsc application/vnd.wap.wmlscriptc -+bcpio application/x-bcpio -+vcd application/x-cdlink -+pgn application/x-chess-pgn -+cpio application/x-cpio -+csh application/x-csh - dcr application/x-director -+dir application/x-director - dxr application/x-director --fgd application/x-director --aam application/x-authorware-map --aas application/x-authorware-seg --aab application/x-authorware-bin --fh4 image/x-freehand --fh7 image/x-freehand --fh5 image/x-freehand --fhc image/x-freehand --fh image/x-freehand --spl application/futuresplash --swf application/x-shockwave-flash - dvi application/x-dvi -+spl application/x-futuresplash - gtar application/x-gtar - hdf application/x-hdf --hqx application/mac-binhex40 --iv application/x-inventor -+js application/x-javascript -+skp application/x-koan -+skd application/x-koan -+skt application/x-koan -+skm application/x-koan - latex application/x-latex --man application/x-troff-man --me application/x-troff-me --mif application/x-mif --ms application/x-troff-ms --oda application/oda --pdf application/pdf --rtf application/rtf --bcpio application/x-bcpio --cpio application/x-cpio --sv4cpio application/x-sv4cpio --sv4crc application/x-sv4crc --sh application/x-shar -+nc application/x-netcdf -+cdf application/x-netcdf -+sh application/x-sh - shar application/x-shar -+swf application/x-shockwave-flash - sit application/x-stuffit -+sv4cpio application/x-sv4cpio -+sv4crc application/x-sv4crc - tar application/x-tar -+tcl application/x-tcl - tex application/x-tex --texi application/x-texinfo - texinfo application/x-texinfo -+texi application/x-texinfo -+t application/x-troff - tr application/x-troff - roff application/x-troff - man application/x-troff-man - me application/x-troff-me - ms application/x-troff-ms --zip application/x-zip-compressed --tsp application/dsptype --wsrc application/x-wais-source - ustar application/x-ustar --cdf application/x-netcdf --nc application/x-netcdf --doc application/msword --ppt application/powerpoint -- --crt application/x-x509-ca-cert --crl application/x-pkcs7-crl -- -+src application/x-wais-source -+xhtml application/xhtml+xml -+xht application/xhtml+xml -+zip application/zip -+au audio/basic -+snd audio/basic -+mid audio/midi -+midi audio/midi -+kar audio/midi -+mpga audio/mpeg -+mp2 audio/mpeg -+mp3 audio/mpeg -+aif audio/x-aiff -+aiff audio/x-aiff -+aifc audio/x-aiff -+m3u audio/x-mpegurl -+ram audio/x-pn-realaudio -+rm audio/x-pn-realaudio -+rpm audio/x-pn-realaudio-plugin -+ra audio/x-realaudio -+wav audio/x-wav -+pdb chemical/x-pdb -+xyz chemical/x-xyz -+bmp image/bmp -+gif image/gif -+ief image/ief -+jpeg image/jpeg -+jpg image/jpeg -+jpe image/jpeg -+png image/png -+tiff image/tiff -+tif image/tiff -+djvu image/vnd.djvu -+djv image/vnd.djvu -+wbmp image/vnd.wap.wbmp -+ras image/x-cmu-raster -+pnm image/x-portable-anymap -+pbm image/x-portable-bitmap -+pgm image/x-portable-graymap -+ppm image/x-portable-pixmap -+rgb image/x-rgb -+xbm image/x-xbitmap -+xpm image/x-xpixmap -+xwd image/x-xwindowdump -+igs model/iges -+iges model/iges -+msh model/mesh -+mesh model/mesh -+silo model/mesh - wrl model/vrml - vrml model/vrml --mime message/rfc822 -- --pac application/x-ns-proxy-autoconfig -- -+css text/css -+html text/html; charset=%s -+htm text/html; charset=%s -+asc text/plain; charset=%s -+txt text/plain; charset=%s -+rtx text/richtext -+rtf text/rtf -+sgml text/sgml -+sgm text/sgml -+tsv text/tab-separated-values - wml text/vnd.wap.wml --wmlc application/vnd.wap.wmlc - wmls text/vnd.wap.wmlscript --wmlsc application/vnd.wap.wmlscriptc --wbmp image/vnd.wap.wbmp -+etx text/x-setext -+xml text/xml -+xsl text/xml -+mpeg video/mpeg -+mpg video/mpeg -+mpe video/mpeg -+qt video/quicktime -+mov video/quicktime -+mxu video/vnd.mpegurl -+avi video/x-msvideo -+movie video/x-sgi-movie -+ice x-conference/x-cooltalk -diff -ur thttpd-2.21b/mmc.c thttpd-2.21b-cool/mmc.c ---- thttpd-2.21b/mmc.c Fri Apr 13 23:02:15 2001 -+++ thttpd-2.21b-cool/mmc.c Sat Sep 20 14:43:20 2003 -@@ -70,6 +70,9 @@ - unsigned int hash; - int hash_idx; - struct MapStruct* next; -+ char nocache; -+ size_t last_modified_len; -+ char last_modified[100]; - } Map; - - -@@ -93,12 +96,13 @@ - - - void* --mmc_map( char* filename, struct stat* sbP, struct timeval* nowP ) -+mmc_map( char* filename, struct stat* sbP, struct timeval* nowP, int nocache, char **last_modified, size_t *last_modified_len ) - { - time_t now; - struct stat sb; - Map* m; - int fd; -+ const char* rfc1123fmt = "%a, %d %b %Y %H:%M:%S GMT"; - - /* Stat the file, if necessary. */ - if ( sbP != (struct stat*) 0 ) -@@ -130,7 +134,7 @@ - /* Yep. Just return the existing map */ - ++m->refcount; - m->reftime = now; -- return m->addr; -+ goto done; - } - - /* Open the file. */ -@@ -167,12 +171,13 @@ - m->ctime = sb.st_ctime; - m->refcount = 1; - m->reftime = now; -+ m->nocache = (char) nocache; - - /* Avoid doing anything for zero-length files; some systems don't like - ** to mmap them, other systems dislike mallocing zero bytes. - */ - if ( m->size == 0 ) -- m->addr = (void*) 1; /* arbitrary non-NULL address */ -+ m->addr = (void*) 5; /* arbitrary non-NULL address */ - else - { - #ifdef HAVE_MMAP -@@ -223,6 +228,13 @@ - maps = m; - ++map_count; - -+ strftime( m->last_modified, sizeof(m->last_modified), rfc1123fmt, gmtime( &sb.st_mtime ) ); -+ m->last_modified_len = strlen(m->last_modified); -+ -+done: -+ *last_modified = m->last_modified; -+ *last_modified_len = m->last_modified_len; -+ - /* And return the address. */ - return m->addr; - } -@@ -231,27 +243,32 @@ - void - mmc_unmap( void* addr, struct stat* sbP, struct timeval* nowP ) - { -- Map* m = (Map*) 0; -+ Map* m = (Map*) 0, **mm = &maps; - - /* Find the Map entry for this address. First try a hash. */ - if ( sbP != (struct stat*) 0 ) - { - m = find_hash( sbP->st_ino, sbP->st_dev, sbP->st_size, sbP->st_ctime ); -- if ( m != (Map*) 0 && m->addr != addr ) -+ if ( m != (Map*) 0 && ( m->addr != addr || m->nocache == 1 ) ) - m = (Map*) 0; - } - /* If that didn't work, try a full search. */ - if ( m == (Map*) 0 ) -- for ( m = maps; m != (Map*) 0; m = m->next ) -+ for ( m = maps; m != (Map*) 0; m = m->next ) { - if ( m->addr == addr ) - break; -+ mm = &m->next; -+ } - if ( m == (Map*) 0 ) - syslog( LOG_ERR, "mmc_unmap failed to find entry!" ); - else if ( m->refcount <= 0 ) - syslog( LOG_ERR, "mmc_unmap found zero or negative refcount!" ); - else - { -- --m->refcount; -+ if ( --m->refcount == 0 && m->nocache == 1 ) { -+ really_unmap( mm ); -+ return; -+ } - if ( nowP != (struct timeval*) 0 ) - m->reftime = nowP->tv_sec; - else -diff -ur thttpd-2.21b/mmc.h thttpd-2.21b-cool/mmc.h ---- thttpd-2.21b/mmc.h Fri Apr 13 07:36:54 2001 -+++ thttpd-2.21b-cool/mmc.h Sat Sep 20 14:43:20 2003 -@@ -31,8 +31,9 @@ - /* Returns an mmap()ed area for the given file, or (void*) 0 on errors. - ** If you have a stat buffer on the file, pass it in, otherwise pass 0. - ** Same for the current time. -+** Set nocache to 1, if this entry is supposed to be removed quickly. - */ --extern void* mmc_map( char* filename, struct stat* sbP, struct timeval* nowP ); -+extern void* mmc_map( char* filename, struct stat* sbP, struct timeval* nowP, int nocache, char **last_modified, size_t *last_modified_len ); - - /* Done with an mmap()ed area that was returned by mmc_map(). - ** If you have a stat buffer on the file, pass it in, otherwise pass 0. -diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c ---- thttpd-2.21b/thttpd.c Tue Apr 24 00:41:57 2001 -+++ thttpd-2.21b-cool/thttpd.c Sat Sep 20 14:43:20 2003 -@@ -53,6 +53,10 @@ - #endif - #include <unistd.h> - -+#include <sys/mman.h> -+ -+#include <limits.h> -+ - #include "fdwatch.h" - #include "libhttpd.h" - #include "mmc.h" -@@ -66,6 +70,8 @@ - static char* dir; - static int do_chroot, no_log, no_symlink, do_vhost, do_global_passwd; - static char* cgi_pattern; -+static char* php_pattern; -+static char* phps_pattern; - static char* url_pattern; - static int no_empty_referers; - static char* local_pattern; -@@ -95,10 +101,10 @@ - httpd_conn* hc; - int tnums[MAXTHROTTLENUMS]; /* throttle indexes */ - int numtnums; -+ int keep_alive; - long limit; - time_t started_at; -- Timer* idle_read_timer; -- Timer* idle_send_timer; -+ time_t last_io; - Timer* wakeup_timer; - Timer* linger_timer; - long wouldblock_delay; -@@ -106,17 +112,22 @@ - off_t bytes_sent; - off_t bytes_to_send; - } connecttab; --static connecttab* connects; -+static connecttab* connects, **free_connects; -+static int next_free_connect; - static int numconnects, maxconnects; - static int httpd_conn_count; - - /* The connection states. */ --#define CNST_FREE 0 --#define CNST_READING 1 --#define CNST_SENDING 2 --#define CNST_PAUSING 3 --#define CNST_LINGERING 4 -- -+enum { -+ CNST_FREE = 0, -+ CNST_READING, -+ CNST_SENDING, -+ CNST_PAUSING, -+ CNST_LINGERING, -+ CNST_SENDING_RESP, -+ CNST_READING_BODY, -+ CNST_TOTAL_NR -+}; - - static httpd_server* hs = (httpd_server*) 0; - int terminate = 0; -@@ -140,23 +151,32 @@ - static int handle_newconnect( struct timeval* tvP, int listen_fd ); - static void handle_read( connecttab* c, struct timeval* tvP ); - static void handle_send( connecttab* c, struct timeval* tvP ); -+static void handle_send_resp( connecttab* c, struct timeval* tvP ); -+static void handle_read_body( connecttab* c, struct timeval* tvP ); - static void handle_linger( connecttab* c, struct timeval* tvP ); - static int check_throttles( connecttab* c ); -+static void timeout_conns( ClientData client_data, struct timeval* nowP ); - static void clear_throttles( connecttab* c, struct timeval* tvP ); - static void update_throttles( ClientData client_data, struct timeval* nowP ); --static void clear_connection( connecttab* c, struct timeval* tvP ); -+static void clear_connection( connecttab* c, struct timeval* tvP, int ); - static void really_clear_connection( connecttab* c, struct timeval* tvP ); --static void idle_read_connection( ClientData client_data, struct timeval* nowP ); --static void idle_send_connection( ClientData client_data, struct timeval* nowP ); - static void wakeup_connection( ClientData client_data, struct timeval* nowP ); - static void linger_clear_connection( ClientData client_data, struct timeval* nowP ); - static void occasional( ClientData client_data, struct timeval* nowP ); -+static void periodic_jobs( ClientData client_data, struct timeval* nowP ); - #ifdef STATS_TIME - static void show_stats( ClientData client_data, struct timeval* nowP ); - #endif /* STATS_TIME */ - static void logstats( struct timeval* nowP ); - static void thttpd_logstats( long secs ); -+static void boot_request(connecttab *c, struct timeval *tvP); -+ -+typedef void (*handler_func)(connecttab*, struct timeval *); -+ -+handler_func handler_array[CNST_TOTAL_NR] = -+{NULL, handle_read, handle_send, NULL, handle_linger, handle_send_resp, handle_read_body}; - -+#define RUN_HANDLER(type, c) if (handler_array[type]) handler_array[type](c, &tv) - - static void - handle_term( int sig ) -@@ -177,7 +197,7 @@ - return; - - /* Re-open the log file. */ -- if ( logfile != (char*) 0 ) -+ if ( logfile != (char*) 0 && strcmp(logfile, "-") != 0) - { - logfp = fopen( logfile, "a" ); - if ( logfp == (FILE*) 0 ) -@@ -198,6 +218,8 @@ - } - - -+time_t httpd_time_now; -+ - static void - handle_usr2( int sig ) - { -@@ -217,7 +239,6 @@ - int num_ready; - int cnum, ridx; - connecttab* c; -- httpd_conn* hc; - httpd_sockaddr sa4; - httpd_sockaddr sa6; - int gotv4, gotv6; -@@ -270,7 +291,9 @@ - no_log = 1; - logfp = (FILE*) 0; - } -- else -+ else if (strcmp(logfile, "-") == 0) { -+ logfp = stdout; -+ } else - { - logfp = fopen( logfile, "a" ); - if ( logfp == (FILE*) 0 ) -@@ -420,7 +443,8 @@ - hostname, - gotv4 ? &sa4 : (httpd_sockaddr*) 0, gotv6 ? &sa6 : (httpd_sockaddr*) 0, - port, cgi_pattern, charset, cwd, no_log, logfp, no_symlink, do_vhost, -- do_global_passwd, url_pattern, local_pattern, no_empty_referers ); -+ do_global_passwd, url_pattern, local_pattern, no_empty_referers, -+ php_pattern, phps_pattern); - if ( hs == (httpd_server*) 0 ) - exit( 1 ); - -@@ -430,6 +454,12 @@ - syslog( LOG_CRIT, "tmr_create(occasional) failed" ); - exit( 1 ); - } -+ -+ if (tmr_create(0, timeout_conns, JunkClientData, 30 * 1000, 1) == 0) { -+ syslog(LOG_CRIT, "tmr_create(timeout_conns) failed"); -+ exit(1); -+ } -+ - if ( numthrottles > 0 ) - { - /* Set up the throttles timer. */ -@@ -439,6 +469,12 @@ - exit( 1 ); - } - } -+ -+ if (tmr_create(0, periodic_jobs, JunkClientData, 2000, 1) == 0) { -+ syslog(LOG_CRIT, "tmr_create failed"); -+ exit(1); -+ } -+ - #ifdef STATS_TIME - /* Set up the stats timer. */ - if ( tmr_create( (struct timeval*) 0, show_stats, JunkClientData, STATS_TIME * 1000L, 1 ) == (Timer*) 0 ) -@@ -454,12 +490,14 @@ - /* If we're root, try to become someone else. */ - if ( getuid() == 0 ) - { -+#ifndef __CYGWIN__ - /* Set aux groups to null. */ - if ( setgroups( 0, (const gid_t*) 0 ) < 0 ) - { - syslog( LOG_CRIT, "setgroups - %m" ); - exit( 1 ); - } -+#endif - /* Set primary group. */ - if ( setgid( gid ) < 0 ) - { -@@ -495,13 +533,17 @@ - } - maxconnects -= SPARE_FDS; - connects = NEW( connecttab, maxconnects ); -+ free_connects = malloc(sizeof(connecttab *) * maxconnects); -+ next_free_connect = maxconnects; - if ( connects == (connecttab*) 0 ) - { - syslog( LOG_CRIT, "out of memory allocating a connecttab" ); - exit( 1 ); - } -+ - for ( cnum = 0; cnum < maxconnects; ++cnum ) - { -+ free_connects[cnum] = &connects[maxconnects - cnum - 1]; - connects[cnum].conn_state = CNST_FREE; - connects[cnum].hc = (httpd_conn*) 0; - } -@@ -518,6 +560,9 @@ - - /* Main loop. */ - (void) gettimeofday( &tv, (struct timezone*) 0 ); -+ httpd_time_now = tv.tv_sec; -+ periodic_jobs(JunkClientData, &tv); -+ - while ( ( ! terminate ) || numconnects > 0 ) - { - /* Do the fd watch. */ -@@ -530,6 +575,7 @@ - exit( 1 ); - } - (void) gettimeofday( &tv, (struct timezone*) 0 ); -+ httpd_time_now = tv.tv_sec; - if ( num_ready == 0 ) - { - /* No fd's are ready - run the timers. */ -@@ -565,16 +611,10 @@ - c = (connecttab*) fdwatch_get_client_data( ridx ); - if ( c == (connecttab*) 0 ) - continue; -- hc = c->hc; -- if ( c->conn_state == CNST_READING && -- fdwatch_check_fd( hc->conn_fd ) ) -- handle_read( c, &tv ); -- else if ( c->conn_state == CNST_SENDING && -- fdwatch_check_fd( hc->conn_fd ) ) -- handle_send( c, &tv ); -- else if ( c->conn_state == CNST_LINGERING && -- fdwatch_check_fd( hc->conn_fd ) ) -- handle_linger( c, &tv ); -+#if DO_UNNECESSARY_CHECK_FD -+ fdwatch_check_fd(c->hc->conn_fd); -+#endif -+ RUN_HANDLER(c->conn_state, c); - } - tmr_run( &tv ); - -@@ -627,6 +667,8 @@ - #else /* CGI_PATTERN */ - cgi_pattern = (char*) 0; - #endif /* CGI_PATTERN */ -+ php_pattern = "**.php"; -+ phps_pattern = "**.phps"; - url_pattern = (char*) 0; - no_empty_referers = 0; - local_pattern = (char*) 0; -@@ -833,6 +875,16 @@ - value_required( name, value ); - cgi_pattern = e_strdup( value ); - } -+ else if ( strcasecmp( name, "phppat" ) == 0 ) -+ { -+ value_required( name, value ); -+ php_pattern = e_strdup( value ); -+ } -+ else if ( strcasecmp( name, "phpspat" ) == 0 ) -+ { -+ value_required( name, value ); -+ phps_pattern = e_strdup( value ); -+ } - else if ( strcasecmp( name, "urlpat" ) == 0 ) - { - value_required( name, value ); -@@ -1196,8 +1248,10 @@ - logstats( &tv ); - for ( cnum = 0; cnum < maxconnects; ++cnum ) - { -- if ( connects[cnum].conn_state != CNST_FREE ) -+ if ( connects[cnum].conn_state != CNST_FREE ) { -+ httpd_complete_request( connects[cnum].hc, &tv ); - httpd_close_conn( connects[cnum].hc, &tv ); -+ } - if ( connects[cnum].hc != (httpd_conn*) 0 ) - { - httpd_destroy_conn( connects[cnum].hc ); -@@ -1214,6 +1268,7 @@ - } - mmc_destroy(); - tmr_destroy(); -+ free( (void*) free_connects ); - free( (void*) connects ); - if ( throttles != (throttletab*) 0 ) - free( (void*) throttles ); -@@ -1234,7 +1289,7 @@ - for (;;) - { - /* Is there room in the connection table? */ -- if ( numconnects >= maxconnects ) -+ if ( numconnects >= maxconnects || next_free_connect == 0 ) - { - /* Out of connection slots. Run the timers, then the - ** existing connections, and maybe we'll free up a slot -@@ -1245,10 +1300,10 @@ - return 0; - } - /* Find a free connection entry. */ -- for ( cnum = 0; cnum < maxconnects; ++cnum ) -- if ( connects[cnum].conn_state == CNST_FREE ) -- break; -- c = &connects[cnum]; -+ -+ c = free_connects[--next_free_connect]; -+ free_connects[next_free_connect] = NULL; -+ - /* Make the httpd_conn if necessary. */ - if ( c->hc == (httpd_conn*) 0 ) - { -@@ -1267,24 +1322,18 @@ - { - case GC_FAIL: - case GC_NO_MORE: -+ free_connects[next_free_connect++] = c; - return 1; - } - c->conn_state = CNST_READING; - ++numconnects; - client_data.p = c; -- c->idle_read_timer = tmr_create( -- tvP, idle_read_connection, client_data, IDLE_READ_TIMELIMIT * 1000L, -- 0 ); -- if ( c->idle_read_timer == (Timer*) 0 ) -- { -- syslog( LOG_CRIT, "tmr_create(idle_read_connection) failed" ); -- exit( 1 ); -- } -- c->idle_send_timer = (Timer*) 0; - c->wakeup_timer = (Timer*) 0; - c->linger_timer = (Timer*) 0; - c->bytes_sent = 0; - c->numtnums = 0; -+ c->keep_alive = 0; -+ c->last_io = httpd_time_now; - - /* Set the connection file descriptor to no-delay mode. */ - httpd_set_ndelay( c->hc->conn_fd ); -@@ -1298,11 +1347,100 @@ - } - - -+#define FIXUP(x) if (hc->x >= oldptr && hc->x < pe) hc->x += d -+ -+static void -+realign_hc(httpd_conn *hc, char *oldptr) -+{ -+ int d = hc->read_buf - oldptr; -+ char *pe = oldptr + hc->checked_idx; -+ -+ FIXUP(encodedurl); -+ FIXUP(protocol); -+ FIXUP(referer); -+ FIXUP(useragent); -+ FIXUP(acceptl); -+ FIXUP(cookie); -+ FIXUP(contenttype); -+ FIXUP(hdrhost); -+ FIXUP(authorization); -+} -+ -+#undef FIXUP -+ -+static void -+setup_read_body(connecttab *c, struct timeval *tvP) -+{ -+ httpd_conn *hc = c->hc; -+ int already, missing; -+ char *oldptr = hc->read_buf; -+ -+ c->conn_state = CNST_READING_BODY; -+ -+ hc->read_body_into_mem = 0; -+ -+ already = hc->read_idx - hc->checked_idx; -+ missing = hc->contentlength - already; -+ -+ if (missing > 16384) { -+ char filename[] = "/tmp/thttpd.upload.XXXXXX"; -+ int tmp = mkstemp(filename); -+ -+ if (tmp >= 0) { -+ void *p; -+ size_t sz = hc->contentlength + hc->checked_idx + 10; -+ -+ unlink(filename); -+ -+ ftruncate(tmp, sz); -+ p = mmap(NULL, sz, -+ PROT_READ|PROT_WRITE, MAP_PRIVATE, tmp, 0); -+ -+ if (p != MAP_FAILED) { -+ memcpy(p, hc->read_buf, hc->read_idx); -+ free(hc->read_buf); -+ hc->read_size = sz; -+ hc->read_buf = p; -+ hc->read_buf_is_mmap = 1; -+ } -+ close(tmp); -+ } -+ -+ if (!hc->read_buf_is_mmap) { -+ clear_connection( c, tvP, 0 ); -+ return; -+ } -+ } else if (missing > 0) { -+ httpd_realloc_str(&hc->read_buf, &hc->read_size, hc->checked_idx + hc->contentlength + 10); -+ } -+ if (oldptr != hc->read_buf) realign_hc(hc, oldptr); -+ -+ fdwatch_del_fd( hc->conn_fd ); -+ fdwatch_add_fd( hc->conn_fd, c, FDW_READ ); -+} -+ -+static void -+setup_sending(connecttab *c, int state, struct timeval *tvP) -+{ -+ httpd_conn *hc = c->hc; -+ ClientData client_data; -+ -+ c->conn_state = state; -+ c->started_at = tvP->tv_sec; -+ c->wouldblock_delay = 0; -+ client_data.p = c; -+ -+ fdwatch_del_fd( hc->conn_fd ); -+ fdwatch_add_fd( hc->conn_fd, c, FDW_WRITE ); -+} -+ -+static void handle_request( connecttab *c, struct timeval *tvP); -+ -+ - static void - handle_read( connecttab* c, struct timeval* tvP ) - { - int sz; -- ClientData client_data; - httpd_conn* hc = c->hc; - - /* Is there room in our buffer to read more bytes? */ -@@ -1311,7 +1449,7 @@ - if ( hc->read_size > 5000 ) - { - httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" ); -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 0 ); - return; - } - httpd_realloc_str( -@@ -1327,14 +1465,53 @@ - ** EWOULDBLOCK; however, this apparently can happen if a packet gets - ** garbled. - */ -- if ( sz == 0 || ( sz < 0 && ( errno != EWOULDBLOCK ) ) ) -- { -- httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" ); -- clear_connection( c, tvP ); -+ if ( sz == 0 ) { -+ if (! c->keep_alive) { -+ httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" ); -+ } -+ clear_connection( c, tvP, 0 ); -+ return; -+ } else if ( sz < 0 ) { -+ if (errno != EWOULDBLOCK) { -+ clear_connection( c, tvP, 0 ); -+ } - return; -+ } -+ -+ /* If this is a persistent PHP connection, we must not receive -+ ** any further requests on this connection. Some broken HTTP/1.1 -+ ** implementations (e.g. Mozilla 1.0.1) are known to do -+ ** pipelining on a connection, although a prior response included -+ ** Connection: close -+ */ -+ if (c->hc->file_address == (char *) 1) { -+ return; -+ } -+ -+ c->last_io = httpd_time_now; -+ if (sz > 0) hc->read_idx += sz; -+ -+ /* -+ ** if we start getting new data on this socket, "promote" it -+ ** to read timeout -+ */ -+ if ( hc->keep_alive ) { -+ ClientData client_data; -+ -+ -+ client_data.p = c; -+ -+ hc->keep_alive = 0; -+ } -+ handle_request(c, tvP); - } -- hc->read_idx += sz; - -+ -+static void -+handle_request( connecttab *c, struct timeval *tvP) -+{ -+ httpd_conn* hc = c->hc; -+ - /* Do we have a complete request yet? */ - switch ( httpd_got_request( hc ) ) - { -@@ -1342,14 +1519,14 @@ - return; - case GR_BAD_REQUEST: - httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" ); -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 0 ); - return; - } - - /* Yes. Try parsing and resolving it. */ - if ( httpd_parse_request( hc ) < 0 ) - { -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 0 ); - return; - } - -@@ -1358,18 +1535,28 @@ - { - httpd_send_err( - hc, 503, httpd_err503title, "", httpd_err503form, hc->encodedurl ); -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 0 ); - return; - } -+ boot_request(c, tvP); -+} - -+static void boot_request(connecttab *c, struct timeval *tvP) -+{ -+ httpd_conn *hc = c->hc; - /* Start the connection going. */ - if ( httpd_start_request( hc, tvP ) < 0 ) - { - /* Something went wrong. Close down the connection. */ -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 0 ); - return; - } - -+ if ( hc->read_body_into_mem ) { -+ setup_read_body( c, tvP ); -+ return; -+ } -+ - /* Fill in bytes_to_send. */ - if ( hc->got_range ) - { -@@ -1384,37 +1571,25 @@ - { - /* No file address means someone else is handling it. */ - c->bytes_sent = hc->bytes_sent; -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 1 ); - return; - } -+ if (hc->file_address == (char *) 1) { -+ c->last_io = (time_t) LONG_MAX; -+ c->wouldblock_delay = 0; -+ return; -+ } - if ( c->bytes_sent >= c->bytes_to_send ) - { - /* There's nothing to send. */ -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 1 ); - return; - } - - /* Cool, we have a valid connection and a file to send to it. */ -- c->conn_state = CNST_SENDING; -- c->started_at = tvP->tv_sec; -- c->wouldblock_delay = 0; -- client_data.p = c; -- tmr_cancel( c->idle_read_timer ); -- c->idle_read_timer = (Timer*) 0; -- c->idle_send_timer = tmr_create( -- tvP, idle_send_connection, client_data, IDLE_SEND_TIMELIMIT * 1000L, -- 0 ); -- if ( c->idle_send_timer == (Timer*) 0 ) -- { -- syslog( LOG_CRIT, "tmr_create(idle_send_connection) failed" ); -- exit( 1 ); -- } -- -- fdwatch_del_fd( hc->conn_fd ); -- fdwatch_add_fd( hc->conn_fd, c, FDW_WRITE ); -+ setup_sending(c, CNST_SENDING, tvP); - } - -- - static void - handle_send( connecttab* c, struct timeval* tvP ) - { -@@ -1443,6 +1618,9 @@ - iv[1].iov_base = &(hc->file_address[c->bytes_sent]); - iv[1].iov_len = MIN( c->bytes_to_send - c->bytes_sent, c->limit ); - sz = writev( hc->conn_fd, iv, 2 ); -+/* -+printf("**RESPONSE2 [%d]** len = %d\n%*.*s\n", hc->conn_fd, hc->responselen, hc->responselen, hc->responselen, hc->response); -+*/ - } - - if ( sz == 0 || -@@ -1486,12 +1664,12 @@ - */ - if ( errno != EPIPE && errno != EINVAL && errno != ECONNRESET ) - syslog( LOG_ERR, "write - %m sending %.80s", hc->encodedurl ); -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 0 ); - return; - } - - /* Ok, we wrote something. */ -- tmr_reset( tvP, c->idle_send_timer ); -+ c->last_io = httpd_time_now; - /* Was this a headers + file writev()? */ - if ( hc->responselen > 0 ) - { -@@ -1500,7 +1678,7 @@ - { - /* Yes; move the unwritten part to the front of the buffer. */ - int newlen = hc->responselen - sz; -- (void) memcpy( hc->response, &(hc->response[sz]), newlen ); -+ (void) memmove( hc->response, &(hc->response[sz]), newlen ); - hc->responselen = newlen; - sz = 0; - } -@@ -1519,7 +1697,7 @@ - if ( c->bytes_sent >= c->bytes_to_send ) - { - /* This connection is finished! */ -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 1 ); - return; - } - -@@ -1560,6 +1738,9 @@ - char buf[1024]; - int r; - -+/* -+printf("*LINGER read\n"); -+*/ - /* In lingering-close mode we just read and ignore bytes. An error - ** or EOF ends things, otherwise we go until a timeout. - */ -@@ -1569,6 +1750,63 @@ - } - - -+static void -+handle_read_body(connecttab *c, struct timeval *tvP) -+{ -+ httpd_conn *hc = c->hc; -+ int n; -+ -+ n = read(hc->conn_fd, hc->read_buf + hc->read_idx, -+ hc->contentlength - (hc->read_idx - hc->checked_idx)); -+ -+ if (n <= 0) { -+ if (errno == EAGAIN) -+ return; -+ clear_connection(c, tvP, 0); -+ return; -+ } -+ -+ c->last_io = httpd_time_now; -+ -+ hc->read_idx += n; -+ -+ if (hc->contentlength == hc->read_idx - hc->checked_idx) { -+ boot_request(c, tvP); -+ return; -+ } -+} -+ -+static void -+handle_send_resp(connecttab *c, struct timeval *tvP) -+{ -+ httpd_conn* hc = c->hc; -+ int n = send(hc->conn_fd, hc->response, hc->responselen, 0); -+ int dokeep = 1; -+ -+ if (n < 0) { -+ if (errno == EAGAIN) -+ return; -+ -+ dokeep = 0; -+ goto clear; -+ } -+ -+ c->last_io = httpd_time_now; -+ -+ if (n == hc->responselen) { -+clear: -+ hc->response = realloc(hc->response, hc->maxresponse + 1); -+ hc->responselen = 0; -+ -+ clear_connection(c, tvP, dokeep); -+ return; -+ } -+ -+ hc->responselen -= n; -+ -+ memmove(hc->response, hc->response + n, hc->responselen); -+} -+ - static int - check_throttles( connecttab* c ) - { -@@ -1635,23 +1873,18 @@ - - - static void --clear_connection( connecttab* c, struct timeval* tvP ) -+clear_connection( connecttab* c, struct timeval* tvP, int doKeep ) - { - ClientData client_data; -+ int linger; - - /* If we haven't actually sent the buffered response yet, do so now. */ -- httpd_write_response( c->hc ); -+ if (c->hc->responselen && c->conn_state != CNST_SENDING_RESP) { -+ setup_sending(c, CNST_SENDING_RESP, tvP); - -- if ( c->idle_read_timer != (Timer*) 0 ) -- { -- tmr_cancel( c->idle_read_timer ); -- c->idle_read_timer = 0; -- } -- if ( c->idle_send_timer != (Timer*) 0 ) -- { -- tmr_cancel( c->idle_send_timer ); -- c->idle_send_timer = 0; -+ return; - } -+ - if ( c->wakeup_timer != (Timer*) 0 ) - { - tmr_cancel( c->wakeup_timer ); -@@ -1669,13 +1902,36 @@ - ** circumstances that make a lingering close necessary. If the flag - ** isn't set we do the real close now. - */ -- if ( c->hc->should_linger ) -+ -+ if ( c->hc->do_keep_alive && doKeep) - { -- c->conn_state = CNST_LINGERING; -+ httpd_conn *hc = c->hc; -+ c->conn_state = CNST_READING; -+ -+ client_data.p = c; -+ c->bytes_sent = 0; -+ c->numtnums = 0; -+ c->keep_alive = 1; -+ -+ httpd_complete_request( c->hc, tvP ); -+ - fdwatch_del_fd( c->hc->conn_fd ); - fdwatch_add_fd( c->hc->conn_fd, c, FDW_READ ); -+ -+ httpd_request_reset( c->hc, 1 ); -+ -+ hc->read_idx -= hc->checked_idx; -+ memmove(hc->read_buf, hc->read_buf + hc->checked_idx, hc->read_idx); -+ hc->checked_idx = 0; -+ - /* Make sure we are still in no-delay mode. */ - httpd_set_ndelay( c->hc->conn_fd ); -+ handle_request(c, tvP); -+ } -+ else if ( c->hc->should_linger ) -+ { -+ c->conn_state = CNST_LINGERING; -+ - client_data.p = c; - c->linger_timer = tmr_create( - tvP, linger_clear_connection, client_data, LINGER_TIME * 1000L, 0 ); -@@ -1684,9 +1940,19 @@ - syslog( LOG_CRIT, "tmr_create(linger_clear_connection) failed" ); - exit( 1 ); - } -+ -+ httpd_complete_request( c->hc, tvP ); -+ -+ fdwatch_del_fd( c->hc->conn_fd ); -+ fdwatch_add_fd( c->hc->conn_fd, c, FDW_READ ); -+ /* Make sure we are still in no-delay mode. */ -+ httpd_set_ndelay( c->hc->conn_fd ); - } -- else -+ else -+ { -+ httpd_complete_request( c->hc, tvP ); - really_clear_connection( c, tvP ); -+ } - } - - -@@ -1702,45 +1968,12 @@ - tmr_cancel( c->linger_timer ); - c->linger_timer = 0; - } -+ free_connects[next_free_connect++] = c; - c->conn_state = CNST_FREE; - --numconnects; - } - - --static void --idle_read_connection( ClientData client_data, struct timeval* nowP ) -- { -- connecttab* c; -- -- c = (connecttab*) client_data.p; -- c->idle_read_timer = (Timer*) 0; -- if ( c->conn_state != CNST_FREE ) -- { -- syslog( LOG_INFO, -- "%.80s connection timed out reading", -- httpd_ntoa( &c->hc->client_addr ) ); -- httpd_send_err( c->hc, 408, httpd_err408title, "", httpd_err408form, "" ); -- clear_connection( c, nowP ); -- } -- } -- -- --static void --idle_send_connection( ClientData client_data, struct timeval* nowP ) -- { -- connecttab* c; -- -- c = (connecttab*) client_data.p; -- c->idle_send_timer = (Timer*) 0; -- if ( c->conn_state != CNST_FREE ) -- { -- syslog( LOG_INFO, -- "%.80s connection timed out sending", -- httpd_ntoa( &c->hc->client_addr ) ); -- clear_connection( c, nowP ); -- } -- } -- - - static void - wakeup_connection( ClientData client_data, struct timeval* nowP ) -@@ -1783,6 +2016,43 @@ - } - #endif /* STATS_TIME */ - -+char httpd_now_buf[100]; -+ -+ -+ -+static void -+periodic_jobs( ClientData client_data, struct timeval* nowP ) -+{ -+ const char* rfc1123fmt = "%a, %d %b %Y %H:%M:%S GMT"; -+ struct tm *t; -+ char date_nozone[100]; -+ const char* cernfmt_nozone = "%d/%b/%Y:%H:%M:%S"; -+ char data[100]; -+ int zone; -+ char sign; -+ -+ strftime( httpd_now_buf, sizeof(httpd_now_buf), rfc1123fmt, gmtime( &nowP->tv_sec ) ); -+ -+ t = localtime(&nowP->tv_sec); -+ strftime( date_nozone, sizeof(date_nozone), cernfmt_nozone, t ); -+#ifdef HAVE_TM_GMTOFF -+ zone = t->tm_gmtoff / 60L; -+#else -+ zone = -timezone / 60L; -+ /* Probably have to add something about daylight time here. */ -+#endif -+ if ( zone >= 0 ) -+ sign = '+'; -+ else -+ { -+ sign = '-'; -+ zone = -zone; -+ } -+ zone = ( zone / 60 ) * 100 + zone % 60; -+ hs->log_date_len = sprintf( hs->log_date, "%s %c%04d", date_nozone, sign, -+ zone ); -+} -+ - - /* Generate debugging statistics syslog messages for all packages. */ - static void -@@ -1826,3 +2096,42 @@ - stats_connections = stats_bytes = 0L; - stats_simultaneous = 0; - } -+ -+static void -+timeout_conns(ClientData client_data, struct timeval *nowP) -+{ -+ connecttab *c = connects, *ce = c + maxconnects; -+ time_t now = nowP->tv_sec; -+ int r = 0, w = 0; -+ int checked = 0; -+ -+ while (c < ce) { -+ switch (c->conn_state) { -+ case CNST_SENDING: -+ case CNST_SENDING_RESP: -+ checked++; -+ if ((now - c->last_io) > IDLE_SEND_TIMELIMIT) { -+ clear_connection( c, nowP, 0 ); -+ w++; -+ } -+ break; -+ case CNST_READING: -+ case CNST_READING_BODY: -+ checked++; -+ if ((now - c->last_io) > IDLE_READ_TIMELIMIT) { -+ clear_connection( c, nowP, 0 ); -+ r++; -+ } -+ break; -+ case CNST_FREE: break; -+ default: checked++; break; -+ } -+ c++; -+ if (checked >= numconnects) break; -+ } -+ -+ if (r > 0 || w > 0) { -+ syslog(LOG_INFO, "Expired %d/%d connections in read/write state", r, w); -+ } -+} -+ -diff -ur thttpd-2.21b/version.h thttpd-2.21b-cool/version.h ---- thttpd-2.21b/version.h Tue Apr 24 04:05:23 2001 -+++ thttpd-2.21b-cool/version.h Sat Sep 20 14:43:20 2003 -@@ -3,7 +3,7 @@ - #ifndef _VERSION_H_ - #define _VERSION_H_ - --#define SERVER_SOFTWARE "thttpd/2.21b 23apr2001" -+#define SERVER_SOFTWARE "thttpd/2.21b PHP/20030920" - #define SERVER_ADDRESS "http://www.acme.com/software/thttpd/" - - #endif /* _VERSION_H_ */ diff --git a/sapi/tux/CREDITS b/sapi/tux/CREDITS deleted file mode 100644 index 3b7aa70c01..0000000000 --- a/sapi/tux/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -tux -Sascha Schumann diff --git a/sapi/tux/README b/sapi/tux/README deleted file mode 100644 index 3c5ebc56ba..0000000000 --- a/sapi/tux/README +++ /dev/null @@ -1,86 +0,0 @@ -README FOR THE TUX MODULE (by Sascha Schumann) -($Date$) - - This is a SAPI module for the TUX web-server by Ingo Molnar. - - The special thing about TUX is that it is integrated into the Linux - kernel and thus provides high-speed serving of static files. - - The web-server provides a user-space API which allows arbitrary - plug-ins to be made available. - - All requests to the PHP userspace module are currently serialized. - - This module is of alpha quality. Due to incomplete APIs, HTTP - authentication and handling of POST requests has not been - implemented yet. - - SECURITY NOTE: PHP will happily run everything under the - web-root through the parser; so be careful what you put - there. - - Note that requests are served in a chroot'ed environment. - The initialization of PHP does not take place in the chroot'ed - environment, so that e.g. /usr/local/lib/php.ini is treated - as usual. - -REQUIRED DOWNLOADS - - 1. TUX - - http://people.redhat.com/~mingo/TUX-patches/QuickStart-TUX.txt - - 2. PHP 4.0.x - - Download: - http://www.php.net/ - - Snapshots from CVS: - http://snaps.php.net/ - - -BUILD INSTRUCTIONS - - 1. Install TUX as outlined in the QuickStart text. - Create /tux-modules where modules will reside. - - 2. Prepare PHP - - $ cd php-* - $ ./configure \ - --with-tux=/tux-modules \ - <further PHP options> - # make install - - You can see the list of valid PHP options by executing - - $ ./configure --help - - 3. Touch a file in your web-root 'php7.tux'. This will - cause requests to '/php7.tux' to be redirected to the - userspace module php7.tux. - - 4. Start TUX with something like - - # tux -d -t 8 -r /www -m /tux-modules php7.tux - - (daemon mode, eight threads, web-root /www, modules in - /tux-modules, load php7.tux) - - BEFORE running this command, the kernel side of TUX has to - be properly setup. - - 5. Try to access - - http://yourserver/php7.tux?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000 - - It should display the PHP credits page. - - To access a script /foo/bar.php, use - - http://yourserver/php7.tux?/foo/bar.php - - Parameters can be appended: - - http://yourserver/php7.tux?/foo/bar.php&var=value - diff --git a/sapi/tux/config.m4 b/sapi/tux/config.m4 deleted file mode 100644 index db4be82cf1..0000000000 --- a/sapi/tux/config.m4 +++ /dev/null @@ -1,16 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(tux,, -[ --with-tux=MODULEDIR Build PHP as a TUX module (Linux only)], no, no) - -AC_MSG_CHECKING([for TUX]) -if test "$PHP_TUX" != "no"; then - INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED $PHP_TUX/php7.tux.so" - AC_CHECK_HEADERS(tuxmodule.h,[:],[AC_MSG_ERROR([Cannot find tuxmodule.h])]) - PHP_SELECT_SAPI(tux, shared, php_tux.c) - AC_MSG_RESULT([$PHP_TUX]) -else - AC_MSG_RESULT(no) -fi diff --git a/sapi/tux/php.sym b/sapi/tux/php.sym deleted file mode 100644 index b968c5f5a2..0000000000 --- a/sapi/tux/php.sym +++ /dev/null @@ -1,2 +0,0 @@ -TUXAPI_handle_events -TUXAPI_init diff --git a/sapi/tux/php_tux.c b/sapi/tux/php_tux.c deleted file mode 100644 index 11755e18e2..0000000000 --- a/sapi/tux/php_tux.c +++ /dev/null @@ -1,449 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ -*/ - -#include "php.h" -#include "SAPI.h" -#include "php_main.h" -#include "php_variables.h" - -#include "zend_smart_str.h" - -#include "tuxmodule.h" - -#include <sys/uio.h> - -#if 0 -#include <pthread.h> -#endif - -void tux_closed_conn(int fd); - -enum { - PHP_TUX_BACKGROUND_CONN = 1 -}; - -typedef struct { - user_req_t *req; - void (*on_close)(int); - int tux_action; - struct iovec *header_vec; - int number_vec; -} php_tux_globals; - -static php_tux_globals tux_globals; - -#define TG(v) (tux_globals.v) - -static int sapi_tux_ub_write(const char *str, uint str_length) -{ - int n; - int m; - const char *estr; - - /* combine headers and body */ - if (TG(number_vec)) { - struct iovec *vec = TG(header_vec); - - n = TG(number_vec); - vec[n].iov_base = (void *) str; - vec[n++].iov_len = str_length; - - /* XXX: this might need more complete error handling */ - if ((m = writev(TG(req)->sock, vec, n)) == -1 && errno == EPIPE) - php_handle_aborted_connection(); - - if (m > 0) - TG(req)->bytes_sent += str_length; - - TG(number_vec) = 0; - return str_length; - } - - estr = str + str_length; - - while (str < estr) { - n = send(TG(req)->sock, str, estr - str, 0); - - if (n == -1 && errno == EPIPE) - php_handle_aborted_connection(); - if (n == -1 && errno == EAGAIN) - continue; - if (n <= 0) - return n; - - str += n; - } - - n = str_length - (estr - str); - - TG(req)->bytes_sent += n; - - return n; -} - -static int sapi_tux_send_headers(sapi_headers_struct *sapi_headers) -{ - char buf[1024]; - struct iovec *vec; - int n; - int max_headers; - zend_llist_position pos; - sapi_header_struct *h; - size_t len; - char *status_line; - int locate_cl; - - max_headers = 30; - n = 1; - - vec = malloc(sizeof(struct iovec) * max_headers); - status_line = malloc(30); - - /* safe sprintf use */ - len = slprintf(status_line, 30, "HTTP/1.1 %d NA\r\n", SG(sapi_headers).http_response_code); - - vec[0].iov_base = status_line; - vec[0].iov_len = len; - - TG(req)->http_status = SG(sapi_headers).http_response_code; - - if (TG(tux_action) == TUX_ACTION_FINISH_CLOSE_REQ && TG(req)->http_version == HTTP_1_1) - locate_cl = 1; - else - locate_cl = 0; - - h = zend_llist_get_first_ex(&sapi_headers->headers, &pos); - while (h) { - if (locate_cl - && strncasecmp(h->header, "Content-length:", sizeof("Content-length:")-1) == 0) { - TG(tux_action) = TUX_ACTION_FINISH_REQ; - locate_cl = 0; - } - - vec[n].iov_base = h->header; - vec[n++].iov_len = h->header_len; - if (n >= max_headers - 3) { - max_headers *= 2; - vec = realloc(vec, sizeof(struct iovec) * max_headers); - } - vec[n].iov_base = "\r\n"; - vec[n++].iov_len = 2; - - h = zend_llist_get_next_ex(&sapi_headers->headers, &pos); - } - - vec[n].iov_base = "\r\n"; - vec[n++].iov_len = 2; - - TG(number_vec) = n; - TG(header_vec) = vec; - - - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - -static int sapi_tux_read_post(char *buffer, uint count_bytes) -{ -#if 0 - int amount = 0; - - TG(req)->objectlen = count_bytes; - TG(req)->object_addr = buffer; - if (tux(TUX_ACTION_READ_POST_DATA, TG(req))) - return 0; - - TG(read_post_data) = 1; - - return TG(req)->objectlen; -#else - return 0; -#endif -} - -static char *sapi_tux_read_cookies(void) -{ - return TG(req)->cookies; -} - -#define BUF_SIZE 512 -#define ADD_STRING(name) \ - php_register_variable(name, buf, track_vars_array) - -static void sapi_tux_register_variables(zval *track_vars_array) -{ - char buf[BUF_SIZE + 1]; - char *p; - sapi_header_line ctr = {0}; - - ctr.line = buf; - ctr.line_len = slprintf(buf, sizeof(buf), "Server: %s", TUXAPI_version); - sapi_header_op(SAPI_HEADER_REPLACE, &ctr); - - php_register_variable("PHP_SELF", SG(request_info).request_uri, track_vars_array); - php_register_variable("SERVER_SOFTWARE", TUXAPI_version, track_vars_array); - php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array); - php_register_variable("REQUEST_METHOD", (char *) SG(request_info).request_method, track_vars_array); - php_register_variable("DOCUMENT_ROOT", TUXAPI_docroot, track_vars_array); - php_register_variable("SERVER_NAME", TUXAPI_servername, track_vars_array); - php_register_variable("REQUEST_URI", SG(request_info).request_uri, track_vars_array); - php_register_variable("PATH_TRANSLATED", SG(request_info).path_translated, track_vars_array); - - p = inet_ntoa(TG(req)->client_host); - /* string representation of IPs are never larger than 512 bytes */ - if (p) { - memcpy(buf, p, strlen(p) + 1); - ADD_STRING("REMOTE_ADDR"); - ADD_STRING("REMOTE_HOST"); - } - - snprintf(buf, sizeof(buf), "%d", CGI_SERVER_PORT(TG(req))); - ADD_STRING("SERVER_PORT"); - -#if 0 - snprintf(buf, BUF_SIZE, "/%s", TG(hc)->pathinfo); - ADD_STRING("PATH_INFO"); - - snprintf(buf, BUF_SIZE, "/%s", TG(hc)->origfilename); - ADD_STRING("SCRIPT_NAME"); -#endif - -#define CONDADD(name, field) \ - if (TG(req)->field[0]) { \ - php_register_variable(#name, TG(req)->field, track_vars_array); \ - } - - CONDADD(HTTP_REFERER, referer); - CONDADD(HTTP_USER_AGENT, user_agent); - CONDADD(HTTP_ACCEPT, accept); - CONDADD(HTTP_ACCEPT_ENCODING, accept_encoding); - CONDADD(HTTP_ACCEPT_LANGUAGE, accept_language); - CONDADD(HTTP_COOKIE, cookies); - CONDADD(CONTENT_TYPE, content_type); - -#if 0 - if (TG(hc)->contentlength != -1) { - snprintf(buf, sizeof(buf), "%ld", (long) TG(hc)->contentlength); - ADD_STRING("CONTENT_LENGTH"); - } -#endif - -#if 0 - if (TG(hc)->authorization[0]) - php_register_variable("AUTH_TYPE", "Basic", track_vars_array); -#endif -} - - -static int php_tux_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, NULL, 0)==FAILURE) { - return FAILURE; - } else { - return SUCCESS; - } -} - -static sapi_module_struct tux_sapi_module = { - "tux", - "tux", - - php_tux_startup, - php_module_shutdown_wrapper, - - NULL, /* activate */ - NULL, /* deactivate */ - - sapi_tux_ub_write, - NULL, - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, - - NULL, - sapi_tux_send_headers, - NULL, - sapi_tux_read_post, - sapi_tux_read_cookies, - - sapi_tux_register_variables, - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - -static void tux_module_main(void) -{ - zend_file_handle file_handle; - - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = SG(request_info).path_translated; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - - if (php_request_startup() == FAILURE) { - return; - } - - php_execute_script(&file_handle); - php_request_shutdown(NULL); -} - -static void tux_request_ctor(void) -{ - char buf[1024]; - int offset; - size_t filename_len; - size_t cwd_len; - smart_str s = {0}; - char *p; - - TG(number_vec) = 0; - TG(header_vec) = NULL; - SG(request_info).query_string = strdup(TG(req)->query); - - smart_str_appends_ex(&s, "/", 1); - smart_str_appends_ex(&s, TG(req)->query, 1); - smart_str_0(&s); - p = strchr(s.c, '&'); - if (p) - *p = '\0'; - SG(request_info).path_translated = s.c; - - s.c = NULL; - smart_str_appendc_ex(&s, '/', 1); - smart_str_appends_ex(&s, TG(req)->objectname, 1); - smart_str_0(&s); - SG(request_info).request_uri = s.c; - SG(request_info).request_method = CGI_REQUEST_METHOD(TG(req)); - if(TG(req)->http_version == HTTP_1_1) SG(request_info).proto_num = 1001; - else SG(request_info).proto_num = 1000; - SG(sapi_headers).http_response_code = 200; - SG(request_info).content_type = TG(req)->content_type; - SG(request_info).content_length = 0; /* TG(req)->contentlength; */ - -#if 0 - php_handle_auth_data(TG(hc)->authorization); -#endif -} - -static void tux_request_dtor(void) -{ - if (TG(header_vec)) { - /* free status_line */ - free(TG(header_vec)[0].iov_base); - free(TG(header_vec)); - } - if (SG(request_info).query_string) - free(SG(request_info).query_string); - free(SG(request_info).request_uri); - free(SG(request_info).path_translated); -} - -#if 0 -static void *separate_thread(void *bla) -{ - int fd; - int i = 0; - - fd = (int) bla; - - while (i++ < 5) { - send(fd, "test<br />\n", 9, 0); - sleep(1); - } - - tux(TUX_ACTION_CONTINUE_REQ, (user_req_t *) fd); - /* We HAVE to trigger some event on the fd. Otherwise - fast_thread won't wake up, so that the eventloop - won't be entered -> TUX hangs */ - shutdown(fd, 2); - pthread_exit(NULL); -} -#endif - -int TUXAPI_handle_events(user_req_t *req) -{ - - if (req->event == PHP_TUX_BACKGROUND_CONN) { - tux_closed_conn(req->sock); - return tux(TUX_ACTION_FINISH_CLOSE_REQ, req); - } - - TG(req) = req; - TG(tux_action) = TUX_ACTION_FINISH_CLOSE_REQ; - - tux_request_ctor(); - - tux_module_main(); - - tux_request_dtor(); - - return tux(TG(tux_action), req); -} - -void tux_register_on_close(void (*arg)(int)) -{ - TG(on_close) = arg; -} - -void tux_closed_conn(int fd) -{ - - if (TG(on_close)) TG(on_close)(fd); -} - -int tux_get_fd(void) -{ - - return TG(req)->sock; -} - -void tux_set_dont_close(void) -{ - - TG(req)->event = PHP_TUX_BACKGROUND_CONN; - tux(TUX_ACTION_POSTPONE_REQ, TG(req)); - TG(tux_action) = TUX_ACTION_EVENTLOOP; -} - -void TUXAPI_init(void) -{ - sapi_startup(&tux_sapi_module); - tux_sapi_module.startup(&tux_sapi_module); - SG(server_context) = (void *) 1; -} - -void doesnotmatter_fini(void) -{ - if (SG(server_context) != NULL) { - tux_sapi_module.shutdown(&tux_sapi_module); - sapi_shutdown(); - } -} - -/* - * 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/webjames/CREDITS b/sapi/webjames/CREDITS deleted file mode 100644 index 73a7983e92..0000000000 --- a/sapi/webjames/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -WebJames -Alex Waugh diff --git a/sapi/webjames/README b/sapi/webjames/README deleted file mode 100644 index 15a7be3de0..0000000000 --- a/sapi/webjames/README +++ /dev/null @@ -1,28 +0,0 @@ -README for WebJames SAPI module -by Alex Waugh <alex@alexwaugh.com> - -This is a SAPI module for the WebJames HTTP server, which runs on the -RISC OS operating system. - - -DOWNLOADS - -A recent (February 2002 or later) version of the GCCSDK cross compiler -http://www.hard-mofo.dsvr.net/ - -WebJames 0.35 or later -http://www.webjames.alexwaugh.com/ - - -BUILDING - -$ cd php7 -$ ./configure \ - --host=arm-riscos-aof \ - --with-webjames=../webjames/src \ - --with-config-file-path=/Choices: \ - other PHP options -$ make install -$ cd ../webjames -$ ./configure --enable-php -$ make diff --git a/sapi/webjames/config.m4 b/sapi/webjames/config.m4 deleted file mode 100644 index 78c8a1936d..0000000000 --- a/sapi/webjames/config.m4 +++ /dev/null @@ -1,21 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(webjames,, -[ --with-webjames=SRCDIR Build PHP as a WebJames module (RISC OS only)], no, no) - -AC_MSG_CHECKING([for webjames]) - -if test "$PHP_WEBJAMES" != "no"; then - PHP_EXPAND_PATH($PHP_WEBJAMES, PHP_WEBJAMES) - INSTALL_IT="\ - echo 'PHP_LIBS = -l$abs_srcdir/$SAPI_STATIC \$(PHP_LIBS) \$(EXTRA_LIBS)' > $PHP_WEBJAMES/build/php; \ - echo 'PHP_LDFLAGS = \$(NATIVE_RPATHS) \$(PHP_LDFLAGS)' >> $PHP_WEBJAMES/build/php; \ - echo 'PHP_CFLAGS = -DPHP \$(COMMON_FLAGS) \$(EXTRA_CFLAGS) -I$abs_srcdir/sapi/webjames' >> $PHP_WEBJAMES/build/php;" - PHP_ADD_INCLUDE($PHP_WEBJAMES) - PHP_SELECT_SAPI(webjames, static, webjames.c) - AC_MSG_RESULT([yes, using $PHP_WEBJAMES]) -else - AC_MSG_RESULT(no) -fi diff --git a/sapi/webjames/php_webjames.h b/sapi/webjames/php_webjames.h deleted file mode 100644 index 63a9b047fb..0000000000 --- a/sapi/webjames/php_webjames.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: Alex Waugh <alex@alexwaugh.com> | - +----------------------------------------------------------------------+ -*/ - -#ifndef PHP_WEBJAMES_H -#define PHP_WEBJAMES_H - -#include "webjames.h" - -void webjames_php_shutdown(void); -int webjames_php_init(void); -void webjames_php_request(struct connection *conn); - -#endif diff --git a/sapi/webjames/webjames.c b/sapi/webjames/webjames.c deleted file mode 100644 index 02c7dcf1c1..0000000000 --- a/sapi/webjames/webjames.c +++ /dev/null @@ -1,327 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 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: Alex Waugh <alex@alexwaugh.com> | - +----------------------------------------------------------------------+ -*/ - - -#include "php.h" -#include "SAPI.h" -#include "php_main.h" -#include "php_variables.h" - -#define WEBJAMES_PHP_ONLY -#include "php_webjames.h" - -#include <unixlib/local.h> - -#define WEBJAMES_SAPI_VERSION "1.0.2" - -typedef struct { - struct connection *conn; /*structure holding all the details of the current request*/ - int bodyread; /*amount of POST body read*/ - closefn oldclose; /*function to call to close the connection*/ -} php_webjames_globals; - -static php_webjames_globals webjames_globals; - -#define WG(v) (webjames_globals.v) - -static int sapi_webjames_ub_write(const char *str, uint str_length) -/*unbuffered write - send data straight out to socket*/ -{ - int totalbytes = 0; - - do { - int bytes; - bytes = webjames_writebuffer(WG(conn),str,str_length); - if (bytes<0) { - PG(connection_status) = PHP_CONNECTION_ABORTED; - if (!PG(ignore_user_abort)) { - zend_bailout(); - } - return bytes; - } - str += bytes; - str_length -= bytes; - totalbytes += bytes; - } while (str_length); - return totalbytes; -} - -static void sapi_webjames_send_header(sapi_header_struct *sapi_header, void *server_context) -/*send an HTTP header*/ -{ - char *header = sapi_header->header; - int len = sapi_header->header_len; - if (WG(conn)->flags.outputheaders) { - while (sapi_header && len > 0) { - int bytes; - bytes = webjames_writebuffer(WG(conn), header, len); - if (bytes<0) { - PG(connection_status) = PHP_CONNECTION_ABORTED; - if (!PG(ignore_user_abort)) { - zend_bailout(); - } - return; - } - header += bytes; - len -= bytes; - } - webjames_writestring(WG(conn), "\r\n"); - } -} - -static int sapi_webjames_read_post(char *buffer, uint count_bytes) -/*read some of the post data*/ -{ - if (WG(conn)->body==NULL) return 0; - if (count_bytes+WG(bodyread)>WG(conn)->bodysize) count_bytes=WG(conn)->bodysize-WG(bodyread); - memcpy(buffer, WG(conn)->body+WG(bodyread), count_bytes); - WG(bodyread)+=count_bytes; - return count_bytes; -} - -static char *sapi_webjames_read_cookies(void) -{ - return WG(conn)->cookie; -} - -#define BUF_SIZE 512 -#define ADD_STRING(name,string)\ - php_register_variable(name, string, track_vars_array) - -#define ADD_NUM(name,field) {\ - snprintf(buf, BUF_SIZE, "%d", WG(conn)->field);\ - php_register_variable(name, buf, track_vars_array);\ -} - -#define ADD_FIELD(name, field) \ - if (WG(conn)->field) { \ - php_register_variable(name, WG(conn)->field, track_vars_array); \ - } - -static void sapi_webjames_register_variables(zval *track_vars_array) -{ - char buf[BUF_SIZE + 1]; - char *docroot; - - buf[BUF_SIZE] = '\0'; - - ADD_STRING("SERVER_SOFTWARE", configuration.server); - ADD_STRING("SERVER_NAME", configuration.serverip); - ADD_FIELD("SERVER_PROTOCOL", protocol); - ADD_NUM("SERVER_PORT", port); - ADD_STRING("SERVER_ADMIN",configuration.webmaster); - ADD_STRING("GATEWAY_INTERFACE", "CGI/1.1"); - - docroot = __unixify(WG(conn)->homedir,0,NULL,1024,0); - if (docroot) ADD_STRING("DOCUMENT_ROOT", docroot); - - ADD_FIELD("REQUEST_METHOD", methodstr); - ADD_FIELD("REQUEST_URI", requesturi); - ADD_STRING("PATH_TRANSLATED", SG(request_info).path_translated); - ADD_FIELD("SCRIPT_NAME", uri); - ADD_FIELD("PHP_SELF", uri); - ADD_FIELD("QUERY_STRING", args); - - - snprintf(buf, BUF_SIZE, "%d.%d.%d.%d", WG(conn)->ipaddr[0], WG(conn)->ipaddr[1], WG(conn)->ipaddr[2], WG(conn)->ipaddr[3]); - ADD_STRING("REMOTE_ADDR", buf); - if (WG(conn)->dnsstatus == DNS_OK) ADD_FIELD("REMOTE_HOST", host); - - if ((WG(conn)->method == METHOD_POST) || (WG(conn)->method == METHOD_PUT)) { - ADD_NUM("CONTENT_LENGTH", bodysize); - ADD_FIELD("CONTENT_TYPE", type); - } - - if ((WG(conn)->method == METHOD_PUT) || (WG(conn)->method == METHOD_DELETE)) ADD_FIELD("ENTITY_PATH", requesturi); - - if (WG(conn)->pwd) { - ADD_STRING("AUTH_TYPE", "basic"); - ADD_FIELD("REMOTE_USER", authorization); - } - - ADD_FIELD("HTTP_COOKIE", cookie); - ADD_FIELD("HTTP_USER_AGENT", useragent); - ADD_FIELD("HTTP_REFERER", referer); - ADD_FIELD("HTTP_ACCEPT", accept); - ADD_FIELD("HTTP_ACCEPT_LANGUAGE", acceptlanguage); - ADD_FIELD("HTTP_ACCEPT_CHARSET", acceptcharset); - ADD_FIELD("HTTP_ACCEPT_ENCODING", acceptencoding); -} - -static void webjames_module_main(void) -{ - zend_file_handle file_handle; - FILE *fp=NULL; - char *path; - - /* Convert filename to Unix format*/ - __riscosify_control|=__RISCOSIFY_STRICT_UNIX_SPECS; - path = __unixify(WG(conn)->filename,0,NULL,1024,0); - if (path) SG(request_info).path_translated = estrdup(path); - - SG(request_info).query_string = WG(conn)->args; - SG(request_info).request_uri = WG(conn)->requesturi; - SG(request_info).request_method = WG(conn)->methodstr; - if (WG(conn)->method==METHOD_HEAD) { - SG(request_info).headers_only = 1; - } else { - SG(request_info).headers_only = 0; - } - SG(sapi_headers).http_response_code = 200; - SG(request_info).content_type = WG(conn)->type; - SG(request_info).content_length = WG(conn)->bodysize; - - SG(request_info).auth_user = NULL; - SG(request_info).auth_password = NULL; - if (WG(conn)->authorization) { - char *colon=strchr(WG(conn)->authorization,':'); - if (colon) { - SG(request_info).auth_user = emalloc(colon-WG(conn)->authorization+1); - if (SG(request_info).auth_user) { - memcpy(SG(request_info).auth_user,WG(conn)->authorization,colon-WG(conn)->authorization); - SG(request_info).auth_user[colon-WG(conn)->authorization]='\0'; - SG(request_info).auth_password = estrdup(colon+1); - } - } - } - - /*ensure that syslog calls get logged separately from WebJames' main log */ - openlog("PHP",0,0); - - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = SG(request_info).path_translated; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - - if (php_request_startup() == FAILURE) { - return; - } - - php_execute_script(&file_handle); - php_request_shutdown(NULL); -} - -static void webjames_php_close(struct connection *conn, int force) -/*called by webjames if it wants to close the connection*/ -{ - - php_request_shutdown(NULL); - WG(oldclose)(conn,force); -} - -void webjames_php_request(struct connection *conn) -/*called by WebJames to start handler*/ -{ - - WG(conn) = conn; - WG(bodyread) = 0; - WG(oldclose) = conn->close; - conn->close=webjames_php_close; - - webjames_module_main(); - - WG(oldclose)(WG(conn), 0); -} - -static void php_info_webjames(ZEND_MODULE_INFO_FUNC_ARGS) -{ - php_info_print_table_start(); - php_info_print_table_row(2, "SAPI module version", WEBJAMES_SAPI_VERSION); - php_info_print_table_row(2, "WebJames version", WEBJAMES_VERSION " (" WEBJAMES_DATE ")"); - php_info_print_table_end(); -} - -static zend_module_entry php_webjames_module = { -#if ZEND_MODULE_API_NO >= 20010901 - STANDARD_MODULE_HEADER, -#endif - "WebJames", - NULL, - NULL, - NULL, - NULL, - NULL, - php_info_webjames, -#if ZEND_MODULE_API_NO >= 20010901 - WEBJAMES_SAPI_VERSION, -#endif - STANDARD_MODULE_PROPERTIES -}; - - -static int php_webjames_startup(sapi_module_struct *sapi_module) -{ - if(php_module_startup(sapi_module, &php_webjames_module, 1) == FAILURE) { - return FAILURE; - } else { - return SUCCESS; - } -} - -static sapi_module_struct sapi_module = { - "webjames", /* name */ - "WebJames", /* pretty name */ - - php_webjames_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - NULL, /* activate */ - NULL, /* deactivate */ - - sapi_webjames_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, /* error handler */ - - NULL, /* header handler */ - NULL, /* send headers handler */ - sapi_webjames_send_header, /* send header handler */ - sapi_webjames_read_post, /* read POST data */ - sapi_webjames_read_cookies, /* read Cookies */ - - sapi_webjames_register_variables, /* register server variables */ - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - -int webjames_php_init(void) -/*called when WebJames initialises*/ -{ - if (strcmp(configuration.webjames_h_revision,WEBJAMES_H_REVISION)!=0) { - /*This file was compiled against a different revision of - webjames.h than webjames was, which could be bad news*/ - webjames_writelog(0,"PHP module is compiled for WebJames (%s) and was linked with a different version (%s)",WEBJAMES_H_REVISION,configuration.webjames_h_revision); - return 0; /*failed to initialise*/ - } - sapi_startup(&sapi_module); - sapi_module.startup(&sapi_module); - SG(server_context) = (void *) 1; - return 1; /*initialised correctly*/ -} - -void webjames_php_shutdown(void) -/*called when WebJames is about to quit*/ -{ - sapi_module.shutdown(&sapi_module); - sapi_shutdown(); -} |