diff -urN php-4.1.2.org/sapi/apache2filter/apache_config.c php-4.1.2/sapi/apache2filter/apache_config.c --- php-4.1.2.org/sapi/apache2filter/apache_config.c Mon Apr 8 02:40:24 2002 +++ php-4.1.2/sapi/apache2filter/apache_config.c Wed Feb 28 15:11:34 2001 @@ -88,7 +88,7 @@ php_dir_entry *pe; php_dir_entry *data; char *str; - uint str_len; + ulong str_len; ulong num_index; phpapdebug((stderr, "Merge dir (%p) (%p)\n", base_conf, new_conf)); @@ -110,7 +110,7 @@ { php_conf_rec *d = dummy; char *str; - uint str_len; + ulong str_len; php_dir_entry *data; for (zend_hash_internal_pointer_reset(&d->config); diff -urN php-4.1.2.org/sapi/apache2filter/php_apache.h php-4.1.2/sapi/apache2filter/php_apache.h --- php-4.1.2.org/sapi/apache2filter/php_apache.h Mon Apr 8 02:40:24 2002 +++ php-4.1.2/sapi/apache2filter/php_apache.h Mon Apr 8 02:34:03 2002 @@ -1,8 +1,8 @@ /* +----------------------------------------------------------------------+ - | PHP version 4.0 | + | PHP Version 4 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 The PHP Group | + | 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 | @@ -12,7 +12,7 @@ | 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 | + | Author: Sascha Schumann | +----------------------------------------------------------------------+ */ diff -urN php-4.1.2.org/sapi/apache2filter/php_functions.c php-4.1.2/sapi/apache2filter/php_functions.c --- php-4.1.2.org/sapi/apache2filter/php_functions.c Mon Apr 8 02:40:24 2002 +++ php-4.1.2/sapi/apache2filter/php_functions.c Mon Apr 8 02:39:31 2002 @@ -38,6 +38,7 @@ { zval **p1; php_struct *ctx; + SLS_FETCH(); if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &p1) == FAILURE) return NULL; @@ -109,6 +110,7 @@ php_struct *ctx; apr_array_header_t *arr; char *key, *val; + SLS_FETCH(); if (array_init(return_value) == FAILURE) { RETURN_FALSE; @@ -135,7 +137,7 @@ }; static zend_module_entry php_apache_module = { - STANDARD_MODULE_HEADER, + STANDARD_MODULE_HEADER, "Apache 2.0", apache_functions, NULL, diff -urN php-4.1.2.org/sapi/apache2filter/sapi_apache2.c php-4.1.2/sapi/apache2filter/sapi_apache2.c --- php-4.1.2.org/sapi/apache2filter/sapi_apache2.c Mon Apr 8 02:40:24 2002 +++ php-4.1.2/sapi/apache2filter/sapi_apache2.c Mon Apr 8 02:30:57 2002 @@ -1,8 +1,8 @@ /* +----------------------------------------------------------------------+ - | PHP version 4.0 | + | PHP Version 4 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 The PHP Group | + | 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 | @@ -48,6 +48,7 @@ { apr_bucket *b; apr_bucket_brigade *bb; + apr_bucket_alloc_t *ba; php_struct *ctx; uint now; @@ -55,10 +56,11 @@ if (str_length == 0) return 0; - bb = apr_brigade_create(ctx->f->r->pool); + ba = ctx->f->r->connection->bucket_alloc; + bb = apr_brigade_create(ctx->f->r->pool, ba); while (str_length > 0) { now = MIN(str_length, 4096); - b = apr_bucket_transient_create(str, now); + b = apr_bucket_transient_create(str, now, ba); APR_BRIGADE_INSERT_TAIL(bb, b); str += now; str_length -= now; @@ -145,7 +147,7 @@ php_apache_sapi_register_variables(zval *track_vars_array TSRMLS_DC) { php_struct *ctx = SG(server_context); - apr_array_header_t *arr = apr_table_elts(ctx->f->r->subprocess_env); + const apr_array_header_t *arr = apr_table_elts(ctx->f->r->subprocess_env); char *key, *val; APR_ARRAY_FOREACH_OPEN(arr, key, val) @@ -161,15 +163,20 @@ { php_struct *ctx = server_context; apr_bucket_brigade *bb; + apr_bucket_alloc_t *ba; 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(); + ba = ctx->f->r->connection->bucket_alloc; + bb = apr_brigade_create(ctx->f->r->pool, ba); + b = apr_bucket_flush_create(ba); APR_BRIGADE_INSERT_TAIL(bb, b); if (ap_pass_brigade(ctx->f->next, bb) != APR_SUCCESS) { php_handle_aborted_connection(); @@ -182,8 +189,13 @@ TSRMLS_FETCH(); ctx = SG(server_context); - - apr_file_puts(msg, ctx->f->r->server->error_log); + + /* 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 = { @@ -226,11 +238,11 @@ 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); \ + ctx->bb = apr_brigade_create(f->c->pool, f->c->bucket_alloc); \ } static int php_input_filter(ap_filter_t *f, apr_bucket_brigade *bb, - ap_input_mode_t mode, apr_size_t *readbytes) + ap_input_mode_t mode, apr_read_type_e block, apr_off_t readbytes) { php_struct *ctx; long old_index; @@ -240,11 +252,15 @@ 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, readbytes)) != APR_SUCCESS) { + if ((rv = ap_get_brigade(f->next, bb, mode, block, readbytes)) != APR_SUCCESS) { return rv; } @@ -307,6 +323,14 @@ 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; @@ -361,9 +385,9 @@ php_execute_script(&zfd TSRMLS_CC); } else { -#define NO_DATA "The PHP Filter did not receive suitable input data" +#define PHP_NO_DATA "The PHP Filter did not receive suitable input data" - eos = apr_bucket_transient_create(NO_DATA, sizeof(NO_DATA)-1); + eos = apr_bucket_transient_create(PHP_NO_DATA, sizeof(PHP_NO_DATA)-1, f->c->bucket_alloc); APR_BRIGADE_INSERT_HEAD(bb, eos); } } @@ -372,7 +396,7 @@ SG(server_context) = 0; /* Pass EOS bucket to next filter to signal end of request */ - eos = apr_bucket_eos_create(); + eos = apr_bucket_eos_create(f->c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(bb, eos); return ap_pass_brigade(f->next, bb); @@ -391,21 +415,67 @@ return APR_SUCCESS; } -static void -php_apache_server_startup(apr_pool_t *pchild, server_rec *s) +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(pchild, NULL, php_apache_server_shutdown, NULL); + 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_child_init(php_apache_server_startup, NULL, NULL, APR_HOOK_MIDDLE); - ap_register_output_filter("PHP", php_output_filter, AP_FTYPE_CONTENT); - ap_register_input_filter("PHP", php_input_filter, AP_FTYPE_CONTENT); + 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 = { @@ -417,3 +487,12 @@ 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 + */