diff options
author | SVN Migration <svn@php.net> | 2002-03-13 18:39:43 +0000 |
---|---|---|
committer | SVN Migration <svn@php.net> | 2002-03-13 18:39:43 +0000 |
commit | 8d6817e7f142091b1c30de30f349c3fde9d7e094 (patch) | |
tree | 45704599905d4a7445ad446fc5337374a3390dbf /sapi/apache2filter | |
parent | 94e6810a2a3e189cf729bdbae8f45cd9d7987ad6 (diff) | |
download | php-git-help.tar.gz |
This commit was manufactured by cvs2svn to create tag 'help'.help
Diffstat (limited to 'sapi/apache2filter')
-rw-r--r-- | sapi/apache2filter/CREDITS | 2 | ||||
-rw-r--r-- | sapi/apache2filter/README | 63 | ||||
-rw-r--r-- | sapi/apache2filter/apache_config.c | 164 | ||||
-rw-r--r-- | sapi/apache2filter/config.m4 | 60 | ||||
-rw-r--r-- | sapi/apache2filter/php.sym | 1 | ||||
-rw-r--r-- | sapi/apache2filter/php_apache.h | 51 | ||||
-rw-r--r-- | sapi/apache2filter/php_functions.c | 171 | ||||
-rw-r--r-- | sapi/apache2filter/sapi_apache2.c | 494 |
8 files changed, 0 insertions, 1006 deletions
diff --git a/sapi/apache2filter/CREDITS b/sapi/apache2filter/CREDITS deleted file mode 100644 index 8fa27e8393..0000000000 --- a/sapi/apache2filter/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Apache 2.0 -Sascha Schumann diff --git a/sapi/apache2filter/README b/sapi/apache2filter/README deleted file mode 100644 index f2b0a0097d..0000000000 --- a/sapi/apache2filter/README +++ /dev/null @@ -1,63 +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 - - Get the latest Apache 2.0 alpha or the CVS code and install it. - - $ 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: - - <Files *.php> - SetOutputFilter PHP - SetInputFilter PHP - </Files> - - That's it. Now start bin/httpd. - -DEBUGGING APACHE AND PHP - - To debug Apache, we recommened: - - 1. Use the Prefork MPM (Apache 1.3-like process model) by - configuring Apache with '--with-mpm=prefork'. - 2. Set the variable "ONE_PROCESS" to 1 and export it before - starting Apache/a debugger. - - 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 - Syntax Highlighter (relies on files as well) diff --git a/sapi/apache2filter/apache_config.c b/sapi/apache2filter/apache_config.c deleted file mode 100644 index 178253d825..0000000000 --- a/sapi/apache2filter/apache_config.c +++ /dev/null @@ -1,164 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 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/2_02.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 "php_ini.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; -} 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; - php_dir_entry *pe; - size_t str_len; - - phpapdebug((stderr, "Getting %s=%s for %p (%d)\n", name, value, dummy, zend_hash_num_elements(&d->config))); - e.value = apr_pstrdup(cmd->pool, value); - e.value_len = strlen(value); - e.status = status; - - str_len = strlen(name); - - if (zend_hash_find(&d->config, (char *) name, str_len + 1, (void **) &pe) == SUCCESS) { - if (pe->status > status) - return NULL; - } - - 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_USER); -} - -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); -} - -void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf) -{ - php_conf_rec *d = base_conf, *e = new_conf; - php_dir_entry *pe; - php_dir_entry *data; - char *str; - uint str_len; - ulong num_index; - - phpapdebug((stderr, "Merge dir (%p) (%p)\n", base_conf, new_conf)); - for (zend_hash_internal_pointer_reset(&d->config); - zend_hash_get_current_key_ex(&d->config, &str, &str_len, &num_index, 0, NULL) == HASH_KEY_IS_STRING; - zend_hash_move_forward(&d->config)) { - pe = NULL; - zend_hash_get_current_data(&d->config, (void **) &data); - if (zend_hash_find(&e->config, str, str_len, (void **) &pe) == SUCCESS) { - if (pe->status >= data->status) continue; - } - zend_hash_update(&e->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 new_conf; -} - -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_ex(&d->config, &str, &str_len, NULL, 0, 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 + 1, - data->status, PHP_INI_STAGE_RUNTIME) == 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_admin_value", php_apache_admin_value_handler, NULL, OR_NONE, - "PHP Value Modifier"), - {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 07be909119..0000000000 --- a/sapi/apache2filter/config.m4 +++ /dev/null @@ -1,60 +0,0 @@ -dnl -dnl $Id$ -dnl - -AC_MSG_CHECKING(for Apache 2.0 module support via DSO through APXS) -AC_ARG_WITH(apxs2, -[ --with-apxs2[=FILE] Build shared Apache 2.0 module. FILE is the optional - pathname to the Apache apxs tool; defaults to "apxs".],[ - if test "$withval" = "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($withval, 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-apxs2=/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 - AC_MSG_ERROR([Aborting]) - fi - - APXS_INCLUDEDIR=`$APXS -q INCLUDEDIR` - APXS_CFLAGS=`$APXS -q CFLAGS` - for flag in $APXS_CFLAGS; do - case $flag in - -D*) CPPFLAGS="$CPPFLAGS $flag";; - esac - done - PHP_ADD_INCLUDE($APXS_INCLUDEDIR) - INSTALL_IT="$APXS -i -a -n php4 $SAPI_LIBTOOL" - PHP_BUILD_THREAD_SAFE - PHP_SELECT_SAPI(apache2filter, shared, sapi_apache2.c apache_config.c php_functions.c) - AC_MSG_RESULT(yes) - case $host_alias in - *aix*) - APXS_SBINDIR=`$APXS -q SBINDIR` - EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-bI:$APXS_SBINDIR/httpd.exp" - ;; - esac -],[ - AC_MSG_RESULT(no) -]) - -PHP_SUBST(APXS) - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/apache2filter/php.sym b/sapi/apache2filter/php.sym deleted file mode 100644 index 2dca1256c2..0000000000 --- a/sapi/apache2filter/php.sym +++ /dev/null @@ -1 +0,0 @@ -php4_module diff --git a/sapi/apache2filter/php_apache.h b/sapi/apache2filter/php_apache.h deleted file mode 100644 index 931f45c28a..0000000000 --- a/sapi/apache2filter/php_apache.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 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/2_02.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_APACHE_H -#define PHP_APACHE_H - -typedef struct php_struct { - int state; - apr_bucket_brigade *bb; - ap_filter_t *f; - /* Length of post_data buffer */ - int post_len; - /* Index for reading from buffer */ - int post_idx; - /* Buffer for request body filter */ - char *post_data; -} php_struct; - -int php_apache_register_module(void); -void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf); -void *create_php_config(apr_pool_t *p, char *dummy); -void apply_config(void *); -extern const command_rec php_dir_cmds[]; - -#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() }} - -#endif /* PHP_APACHE_H */ diff --git a/sapi/apache2filter/php_functions.c b/sapi/apache2filter/php_functions.c deleted file mode 100644 index 3a5131ecb9..0000000000 --- a/sapi/apache2filter/php_functions.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 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/2_02.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 "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" - -#include "php_apache.h" - -static request_rec *php_apache_lookup_uri(INTERNAL_FUNCTION_PARAMETERS) -{ - zval **p1; - php_struct *ctx; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &p1) == FAILURE) - return NULL; - - convert_to_string_ex(p1); - - ctx = SG(server_context); - return ap_sub_req_lookup_uri(Z_STRVAL_PP(p1), ctx->f->r, ctx->f->next); -} - -/* {{{ proto bool virtual(string uri) - Perform an apache sub-request */ -PHP_FUNCTION(virtual) -{ - request_rec *rr; - - rr = php_apache_lookup_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU); - - if (!rr) - WRONG_PARAM_COUNT; - - if (rr->status == HTTP_OK) { - ap_run_sub_req(rr); - ap_destroy_sub_req(rr); - RETURN_TRUE; - } - ap_destroy_sub_req(rr); - RETURN_FALSE; -} - -#define ADD_LONG(name) \ - add_assoc_long(return_value, #name, rr->name) -#define ADD_STRING(name) \ - if (rr->name) add_assoc_string(return_value, #name, (char *) rr->name, 1) - -PHP_FUNCTION(apache_lookup_uri) -{ - request_rec *rr; - - rr = php_apache_lookup_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU); - if (!rr) - WRONG_PARAM_COUNT; - - if (rr->status == HTTP_OK) { - array_init(return_value); - - ADD_LONG(status); - ADD_STRING(the_request); - ADD_STRING(status_line); - ADD_STRING(method); - ADD_LONG(mtime); - ADD_LONG(clength); - ADD_STRING(boundary); - 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); - - ap_destroy_sub_req(rr); - return; - } - ap_destroy_sub_req(rr); - RETURN_FALSE; -} - -/* {{{ proto array getallheaders(void) - Fetch all HTTP request headers */ -PHP_FUNCTION(getallheaders) -{ - php_struct *ctx; - const apr_array_header_t *arr; - char *key, *val; - - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } - - ctx = SG(server_context); - arr = apr_table_elts(ctx->f->r->headers_in); - - APR_ARRAY_FOREACH_OPEN(arr, key, val) - if (!val) val = empty_string; - add_assoc_string(return_value, key, val, 1); - APR_ARRAY_FOREACH_CLOSE() -} -/* }}} */ - -PHP_MINFO_FUNCTION(apache) -{ -} - -static function_entry apache_functions[] = { - PHP_FE(apache_lookup_uri, NULL) - PHP_FE(virtual, NULL) - PHP_FE(getallheaders, NULL) - {NULL, NULL, NULL} -}; - -static zend_module_entry php_apache_module = { - STANDARD_MODULE_HEADER, - "Apache 2.0", - apache_functions, - NULL, - NULL, - NULL, - NULL, - PHP_MINFO(apache), - NULL, - STANDARD_MODULE_PROPERTIES -}; - -int php_apache_register_module(void) -{ - return zend_startup_module(&php_apache_module); -} - -/* - * 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 8923dfd91e..0000000000 --- a/sapi/apache2filter/sapi_apache2.c +++ /dev/null @@ -1,494 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 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/2_02.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 | - +----------------------------------------------------------------------+ - */ - -#include <fcntl.h> - -#include "php.h" -#include "php_main.h" -#include "php_ini.h" -#include "php_variables.h" -#include "SAPI.h" - -#include "ext/standard/php_smart_str.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" - -#include "php_apache.h" - -static int -php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) -{ - apr_bucket *b; - apr_bucket_brigade *bb; - php_struct *ctx; - uint now; - - ctx = SG(server_context); - - if (str_length == 0) return 0; - - bb = apr_brigade_create(ctx->f->r->pool); - while (str_length > 0) { - now = MIN(str_length, 4096); - b = apr_bucket_transient_create(str, now); - APR_BRIGADE_INSERT_TAIL(bb, b); - str += now; - str_length -= now; - } - if (ap_pass_brigade(ctx->f->next, bb) != APR_SUCCESS) { - php_handle_aborted_connection(); - } - - return str_length; -} - -static int -php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC) -{ - php_struct *ctx = SG(server_context); - char *val; - - val = strchr(sapi_header->header, ':'); - - if (!val) return 0; - - *val = '\0'; - - do { - val++; - } while (*val == ' '); - - if (!strcasecmp(sapi_header->header, "content-type")) - ctx->f->r->content_type = apr_pstrdup(ctx->f->r->pool, val); - else if (sapi_header->replace) - apr_table_set(ctx->f->r->headers_out, sapi_header->header, val); - else - apr_table_add(ctx->f->r->headers_out, sapi_header->header, val); - - sapi_free_header(sapi_header); - - return 0; -} - -static int -php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) -{ - php_struct *ctx = SG(server_context); - - ctx->f->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 TSRMLS_DC) -{ - int n; - int to_read; - php_struct *ctx = SG(server_context); - - to_read = ctx->post_len - ctx->post_idx; - n = MIN(to_read, count_bytes); - - if (n > 0) { - memcpy(buf, ctx->post_data + ctx->post_idx, n); - ctx->post_idx += n; - } else { - if (ctx->post_data) free(ctx->post_data); - ctx->post_data = NULL; - } - - return n; -} - -static char * -php_apache_sapi_read_cookies(TSRMLS_D) -{ - php_struct *ctx = SG(server_context); - const char *http_cookie; - - http_cookie = apr_table_get(ctx->f->r->headers_in, "cookie"); - - /* The SAPI interface should use 'const char *' */ - return (char *) http_cookie; -} - -static void -php_apache_sapi_register_variables(zval *track_vars_array TSRMLS_DC) -{ - php_struct *ctx = SG(server_context); - const apr_array_header_t *arr = apr_table_elts(ctx->f->r->subprocess_env); - char *key, *val; - - APR_ARRAY_FOREACH_OPEN(arr, key, val) - if (!val) val = empty_string; - php_register_variable(key, val, track_vars_array TSRMLS_CC); - APR_ARRAY_FOREACH_CLOSE() - - php_register_variable("PHP_SELF", ctx->f->r->uri, track_vars_array TSRMLS_CC); -} - -static void -php_apache_sapi_flush(void *server_context) -{ - php_struct *ctx = server_context; - apr_bucket_brigade *bb; - apr_bucket *b; - - if (!server_context) - return; - - /* 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. - */ - - bb = apr_brigade_create(ctx->f->r->pool); - b = apr_bucket_flush_create(); - APR_BRIGADE_INSERT_TAIL(bb, b); - if (ap_pass_brigade(ctx->f->next, bb) != APR_SUCCESS) { - php_handle_aborted_connection(); - } -} - -static void php_apache_sapi_log_message(char *msg) -{ - php_struct *ctx; - TSRMLS_FETCH(); - - ctx = SG(server_context); - - /* We use APLOG_STARTUP because it keeps us from printing the - * data and time information at the beginning of the error log - * line. Not sure if this is correct, but it mirrors what happens - * with Apache 1.3 -- rbb - */ - ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO | APLOG_STARTUP, 0, ctx->f->r->server, "%s", msg); -} - -static sapi_module_struct apache2_sapi_module = { - "apache2filter", - "Apache 2.0 Filter", - - php_module_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - NULL, /* activate */ - NULL, /* deactivate */ - - php_apache_sapi_ub_write, /* unbuffered write */ - php_apache_sapi_flush, /* flush */ - NULL, /* get uid */ - NULL, /* 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 */ - - NULL, /* Block interruptions */ - NULL, /* Unblock interruptions */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - - -AP_MODULE_DECLARE_DATA module php4_module; - -#define INIT_CTX \ - if (ctx == NULL) { \ - /* Initialize filter context */ \ - SG(server_context) = ctx = apr_pcalloc(f->r->pool, sizeof(*ctx)); \ - ctx->bb = apr_brigade_create(f->c->pool); \ - } - -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; - long old_index; - apr_bucket *b; - const char *str; - apr_ssize_t n; - apr_status_t rv; - TSRMLS_FETCH(); - - if (f->r->proxyreq) { - return ap_get_brigade(f->next, bb, mode, block, readbytes); - } - - ctx = SG(server_context); - - INIT_CTX; - - if ((rv = ap_get_brigade(f->next, bb, mode, block, readbytes)) != APR_SUCCESS) { - return rv; - } - - APR_BRIGADE_FOREACH(b, bb) { - apr_bucket_read(b, &str, &n, 1); - if (n > 0) { - old_index = ctx->post_len; - ctx->post_len += n; - ctx->post_data = realloc(ctx->post_data, ctx->post_len + 1); - memcpy(ctx->post_data + old_index, str, n); - } - } - return APR_SUCCESS; -} - -static void php_apache_request_ctor(ap_filter_t *f, php_struct *ctx TSRMLS_DC) -{ - char *content_type; - const char *auth; - - PG(during_request_startup) = 0; - SG(sapi_headers).http_response_code = 200; - 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).request_uri = safe_strdup(f->r->uri); - f->r->no_local_copy = 1; - content_type = sapi_get_default_content_type(TSRMLS_C); - f->r->content_type = apr_pstrdup(f->r->pool, content_type); - SG(request_info).post_data = ctx->post_data; - SG(request_info).post_data_length = ctx->post_len; - efree(content_type); - 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"); - apr_table_unset(f->r->headers_in, "Connection"); - auth = apr_table_get(f->r->headers_in, "Authorization"); - php_handle_auth_data(auth TSRMLS_CC); - - php_request_startup(TSRMLS_C); -} - -static void php_apache_request_dtor(ap_filter_t *f TSRMLS_DC) -{ - php_request_shutdown(NULL); - -#undef safe_free -#define safe_free(x) ((x)?free((x)):0) - safe_free(SG(request_info).query_string); - safe_free(SG(request_info).request_uri); -} - -static int php_output_filter(ap_filter_t *f, apr_bucket_brigade *bb) -{ - php_struct *ctx; - apr_bucket *b; - void *conf = ap_get_module_config(f->r->per_dir_config, &php4_module); - TSRMLS_FETCH(); - - if (f->r->proxyreq) { - return ap_pass_brigade(f->next, bb); - } - - /* setup standard CGI variables */ - ap_add_common_vars(f->r); - ap_add_cgi_vars(f->r); - - ctx = SG(server_context); - INIT_CTX; - - ctx->f = f; - - /* states: - * 0: request startup - * 1: collecting data - * 2: script execution and request shutdown - */ - if (ctx->state == 0) { - - apply_config(conf); - - ctx->state++; - - php_apache_request_ctor(f, ctx TSRMLS_CC); - } - - /* moves all buckets from bb to ctx->bb */ - ap_save_brigade(f, &ctx->bb, &bb, f->r->pool); - - /* If we have received all data from the previous filters, - * we "flatten" the buckets by creating a single string buffer. - */ - if (ctx->state == 1 && APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(ctx->bb))) { - zend_file_handle zfd; - apr_bucket *eos; - - /* We want to execute only one script per request. - * A bug in Apache or other filters could cause us - * to reenter php_filter during script execution, so - * we protect ourselves here. - */ - ctx->state = 2; - - /* Handle phpinfo/phpcredits/built-in images */ - if (!php_handle_special_queries(TSRMLS_C)) { - - b = APR_BRIGADE_FIRST(ctx->bb); - - if (APR_BUCKET_IS_FILE(b)) { - const char *path; - - apr_file_name_get(&path, ((apr_bucket_file *) b->data)->fd); - - zfd.type = ZEND_HANDLE_FILENAME; - zfd.filename = (char *) path; - zfd.free_filename = 0; - zfd.opened_path = NULL; - - php_execute_script(&zfd TSRMLS_CC); - } else { - -#define PHP_NO_DATA "The PHP Filter did not receive suitable input data" - - eos = apr_bucket_transient_create(PHP_NO_DATA, sizeof(PHP_NO_DATA)-1); - APR_BRIGADE_INSERT_HEAD(bb, eos); - } - } - - php_apache_request_dtor(f TSRMLS_CC); - - SG(server_context) = 0; - /* Pass EOS bucket to next filter to signal end of request */ - eos = apr_bucket_eos_create(); - APR_BRIGADE_INSERT_TAIL(bb, eos); - - return ap_pass_brigade(f->next, bb); - } else - apr_brigade_destroy(bb); - - return APR_SUCCESS; -} - -static apr_status_t -php_apache_server_shutdown(void *tmp) -{ - apache2_sapi_module.shutdown(&apache2_sapi_module); - sapi_shutdown(); - tsrm_shutdown(); - return APR_SUCCESS; -} - -static void php_apache_add_version(apr_pool_t *p) -{ - TSRMLS_FETCH(); - if (PG(expose_php)) { - ap_add_version_component(p, "PHP/" PHP_VERSION); - } -} - -static int -php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, - apr_pool_t *ptemp, server_rec *s) -{ - tsrm_startup(1, 1, 0, NULL); - 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_register_module(); - 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 | APLOG_NOERRNO, - 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) -{ - if (r->content_type && - strcmp(r->content_type, "application/x-httpd-php") == 0) { - php_add_filter(r, r->output_filters); - php_add_filter(r, r->input_filters); - } -} - -static void php_register_hook(apr_pool_t *p) -{ - 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_register_output_filter("PHP", php_output_filter, AP_FTYPE_RESOURCE); - ap_register_input_filter("PHP", php_input_filter, AP_FTYPE_RESOURCE); -} - -AP_MODULE_DECLARE_DATA module php4_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 - */ |