This is the 3rd Time I have posted this patch. The first time I recieved 0 replies[1]. The 2nd time around Andi Gutmans provided some questions, but nothing negative about the patches[2].
These patchs add two new functions for handling output filters in the Apache2Handler SAPI: bool apache_add_output_filter(string filter_name) - Attempts to add the named filter to the Filter Chain. This function takes in a String with the name of a Filter. First it gets then Output Filter Handler from Apache, based on the submitted named. If a filter by that name is not found, it will return false. If a filter was found, it will add this filter to the Output Filter Chain. This filter will then be run after the PHP Handler has completed its work. array apache_get_output_filters() - Returns an array of all active Output filters for this request This function loops through all output filters that are active on this request. It then returns an array of strings with the string names of the active filters. An example use for this is the ability to add an XSLT output filter on the fly, depending on conditions decided upon by PHP code. This is can to render XML generated from PHP to the HTML for the client browser. The attached patches are for both PHP4 CVS and PHP5 CVS. They are also online at: http://force-elite.com/~chip/patches/php-src/apache2-filters/ Online at the URL above, there is also a simple example. The file demo.phps generates some simple XML, then the demo.xsl is used to transform it into HTML. I would like to see these Patches commited. Are there any problems with how they are written? Thank You, -Paul Querna [1] http://marc.theaimsgroup.com/?l=php-dev&m=108243950923432&w=2 [2] http://marc.theaimsgroup.com/?t=108294567400003&r=1&w=2
Index: sapi/apache2handler/php_functions.c =================================================================== RCS file: /repository/php-src/sapi/apache2handler/php_functions.c,v retrieving revision 1.1.2.10 diff -u -r1.1.2.10 php_functions.c --- sapi/apache2handler/php_functions.c 11 Nov 2003 20:04:19 -0000 1.1.2.10 +++ sapi/apache2handler/php_functions.c 20 Apr 2004 05:22:03 -0000 @@ -207,6 +207,65 @@ } /* }}} */ +/* {{{ proto array apache_get_output_filters() + Get All Active Output filters */ +PHP_FUNCTION(apache_get_output_filters) +{ + ap_filter_t* ff; + php_struct *ctx; + + if (ZEND_NUM_ARGS() != 0) { + WRONG_PARAM_COUNT; + } + + if(array_init(return_value) != SUCCESS) + { + RETURN_NULL(); + } + + ctx = SG(server_context); + + ff = ctx->r->output_filters; + + do { + add_next_index_string(return_value, ff->frec->name, 1); + ff = ff->next ; + } while (ff); + +} +/* }}} */ + +/* {{{ proto bool apache_add_output_filter(string filter_name) + Add an output filter to this request */ +PHP_FUNCTION(apache_add_output_filter) +{ + php_struct *ctx; + int arg_count = ZEND_NUM_ARGS(); + zval **filter_name; + ap_filter_rec_t* ap_filter; + + if (arg_count != 1 || + zend_get_parameters_ex(arg_count, &filter_name) == FAILURE) { + WRONG_PARAM_COUNT; + } + + ctx = SG(server_context); + + convert_to_string_ex(filter_name); + + ap_filter = ap_get_output_filter_handle(Z_STRVAL_PP(filter_name)); + + /* requested output filter was not found */ + if(ap_filter == NULL) { + RETURN_FALSE; + } + else { + ap_add_output_filter_handle(ap_filter, NULL, ctx->r, ctx->r->connection); + RETURN_TRUE; + } +} +/* }}} */ + /* {{{ proto string apache_note(string note_name [, string note_value]) Get and set Apache request notes */ PHP_FUNCTION(apache_note) @@ -461,6 +520,8 @@ PHP_FE(apache_response_headers, NULL) PHP_FE(apache_setenv, NULL) PHP_FE(apache_getenv, NULL) + PHP_FE(apache_get_output_filters, NULL) + PHP_FE(apache_add_output_filter, NULL) PHP_FE(apache_note, NULL) PHP_FE(apache_get_version, NULL) PHP_FE(apache_get_modules, NULL)
Index: sapi/apache2handler/php_functions.c =================================================================== RCS file: /repository/php-src/sapi/apache2handler/php_functions.c,v retrieving revision 1.13 diff -u -r1.13 php_functions.c --- sapi/apache2handler/php_functions.c 8 Jan 2004 08:18:05 -0000 1.13 +++ sapi/apache2handler/php_functions.c 20 Apr 2004 05:00:59 -0000 @@ -209,6 +209,65 @@ } /* }}} */ +/* {{{ proto array apache_get_output_filters() + Get All Active Output filters */ +PHP_FUNCTION(apache_get_output_filters) +{ + ap_filter_t* ff; + php_struct *ctx; + + if (ZEND_NUM_ARGS() != 0) { + WRONG_PARAM_COUNT; + } + + if(array_init(return_value) != SUCCESS) + { + RETURN_NULL(); + } + + ctx = SG(server_context); + + ff = ctx->r->output_filters; + + do { + add_next_index_string(return_value, ff->frec->name, 1); + ff = ff->next ; + } while (ff); + +} +/* }}} */ + +/* {{{ proto bool apache_add_output_filter(string filter_name) + Add an output filter to this request */ +PHP_FUNCTION(apache_add_output_filter) +{ + php_struct *ctx; + int arg_count = ZEND_NUM_ARGS(); + zval **filter_name; + ap_filter_rec_t* ap_filter; + + if (arg_count != 1 || + zend_get_parameters_ex(arg_count, &filter_name) == FAILURE) { + WRONG_PARAM_COUNT; + } + + ctx = SG(server_context); + + convert_to_string_ex(filter_name); + + ap_filter = ap_get_output_filter_handle(Z_STRVAL_PP(filter_name)); + + /* requested output filter was not found */ + if(ap_filter == NULL) { + RETURN_FALSE; + } + else { + ap_add_output_filter_handle(ap_filter, NULL, ctx->r, ctx->r->connection); + RETURN_TRUE; + } +} +/* }}} */ + /* {{{ proto string apache_note(string note_name [, string note_value]) Get and set Apache request notes */ PHP_FUNCTION(apache_note) @@ -459,6 +518,8 @@ static function_entry apache_functions[] = { PHP_FE(apache_lookup_uri, NULL) PHP_FE(virtual, NULL) + PHP_FE(apache_get_output_filters, NULL) + PHP_FE(apache_add_output_filter, NULL) PHP_FE(apache_request_headers, NULL) PHP_FE(apache_response_headers, NULL) PHP_FE(apache_setenv, NULL)
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php