From: Doug MacEachern Date: Mon, 20 Aug 2001 16:34:45 +0000 (+0000) Subject: automatically add php input/output filters when give the standard 1.x config: X-Git-Tag: PRE_SUBST_Z_MACROS~418 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9b137805c8014b80425ed695095b07e5edb5836b;p=php automatically add php input/output filters when give the standard 1.x config: AddType application/x-httpd-php .php with that, no longer need "Set{In,Out}putFilter PHP" configuration for 2.0 --- diff --git a/sapi/apache2filter/sapi_apache2.c b/sapi/apache2filter/sapi_apache2.c index 89003f8a9e..63f07f6968 100644 --- a/sapi/apache2filter/sapi_apache2.c +++ b/sapi/apache2filter/sapi_apache2.c @@ -417,9 +417,43 @@ php_apache_server_startup(apr_pool_t *pchild, server_rec *s) php_apache_register_module(); } +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_hook_insert_filter(php_insert_filter, 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); }