Re: [RUNKIT]Patch to add header support
| From: | Julien MORTUAIRE | Date: | Wed, 27 Feb 2008 08:44:04 +0000 |
| Subject: | Re: [RUNKIT]Patch to add header support | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-5146@lists.php.net to get a copy of this message | ||
Ok, i think i can't attach my patch file to my mail.
I copy/past it :
--- runkit_sandbox.c 2008-02-26 23:50:43.000000000 +0100
+++ runkit_sandbox.new.c 2008-02-26 23:56:55.000000000 +0100
@@ -27,6 +27,8 @@
static zend_object_handlers php_runkit_sandbox_object_handlers;
static zend_class_entry *php_runkit_sandbox_class_entry;
+zval *headers_tab;
+
#define PHP_RUNKIT_SANDBOX_BEGIN(objval) \
{ \
void *prior_context = tsrm_set_interpreter_context(objval->context); \
@@ -904,8 +906,8 @@
{
php_runkit_sandbox_object *objval = RUNKIT_G(current_sandbox);
int bytes_written;
-
- if (!str_length) {
+
+ if (!str_length && !headers_tab) {
return 0;
}
@@ -921,7 +923,8 @@
tsrm_set_interpreter_context(objval->parent_context);
{
- zval **output_buffer[1], *bufcopy, *retval = NULL;
+ zval **output_buffer[2], *bufcopy, *header, *retval = NULL;
+
TSRMLS_FETCH();
if (!objval->output_handler ||
@@ -937,8 +940,9 @@
MAKE_STD_ZVAL(bufcopy);
ZVAL_STRINGL(bufcopy, (char*)str, str_length, 1);
output_buffer[0] = &bufcopy;
-
- if (call_user_function_ex(EG(function_table), NULL,
objval->output_handler, &retval, 1, output_buffer, 0, NULL TSRMLS_CC)
== SUCCESS) {
+ output_buffer[1] = &headers_tab;
+
+ if (call_user_function_ex(EG(function_table), NULL,
objval->output_handler, &retval, 2, output_buffer, 0, NULL TSRMLS_CC)
== SUCCESS) {
if (retval) {
if (Z_TYPE_P(retval) != IS_NULL) {
convert_to_string(retval);
@@ -1099,14 +1103,14 @@
*/
static int php_runkit_sandbox_sapi_header_handler(sapi_header_struct
*sapi_header,sapi_headers_struct *sapi_headers TSRMLS_DC)
{
- if (!RUNKIT_G(current_sandbox)) {
- /* Not in a sandbox use SAPI's actual handler */
- return php_runkit_sandbox_original_sapi.header_handler(sapi_header,
sapi_headers TSRMLS_CC);
- }
-
- /* Otherwise ignore headers -- TODO: Provide a way for the calling
scope to receive these a la output handler */
- return SAPI_HEADER_ADD;
-}
+ if (!RUNKIT_G(current_sandbox)) {
+ /* Not in a sandbox use SAPI's actual handler */
+ return
php_runkit_sandbox_original_sapi.header_handler(sapi_header,
sapi_headers TSRMLS_CC);
+ }
+
+ /* Otherwise ignore headers -- TODO: Provide a way for the
calling scope to receive these a la output handler */
+ return SAPI_HEADER_ADD;
+}
/* }}} */
/* {{{ php_runkit_sandbox_sapi_send_headers
@@ -1118,8 +1122,23 @@
/* Not in a sandbox use SAPI's actual handler */
return php_runkit_sandbox_original_sapi.send_headers(sapi_headers TSRMLS_CC);
}
-
- /* Do nothing */
+
+ sapi_header_struct *h;
+ zend_llist_position pos;
+ int idx = 0;
+
+ MAKE_STD_ZVAL(headers_tab);
+ array_init(headers_tab);
+
+ h = (sapi_header_struct*)zend_llist_get_first_ex(&sapi_headers->headers,
&pos);
+ while (h) {
+ if (h->header_len) {
+ add_index_string(headers_tab, idx, h->header, 0);
+ idx++;
+ }
+ h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers,
&pos);
+ }
+
return SAPI_HEADER_SENT_SUCCESSFULLY;
}
/* }}} */
@@ -1129,14 +1148,14 @@
*/
static void php_runkit_sandbox_sapi_send_header(sapi_header_struct
*sapi_header, void *server_context TSRMLS_DC)
{
- if (!RUNKIT_G(current_sandbox)) {
- /* Not in a sandbox use SAPI's actual handler */
- php_runkit_sandbox_sapi_send_header(sapi_header, server_context TSRMLS_CC);
- return;
- }
+ if (!RUNKIT_G(current_sandbox)) {
+ /* Not in a sandbox use SAPI's actual handler */
+ php_runkit_sandbox_sapi_send_header(sapi_header,
server_context TSRMLS_CC);
+ return;
+ }
- /* Do nothing */
- return;
+ /* Do nothing */
+ return;
}
/* }}} */
@@ -1148,7 +1167,7 @@
/* Not in a sandbox use SAPI's actual handler */
return php_runkit_sandbox_original_sapi.read_post(buffer,
count_bytes TSRMLS_CC);
}
-
+
/* return nothing */
return 0;
}
@@ -1480,6 +1499,7 @@
PHP_RUNKIT_SANDBOX_SETTING_BOOL_WR(name) \
PHP_RUNKIT_SANDBOX_SETTING_BOOL_RD(name)
+
PHP_RUNKIT_SANDBOX_SETTING_GETTER(output_handler)
{
if (!objval->output_handler) {
2008/2/27, Julien MORTUAIRE <julien.m@deltaconnexion.com>:
> Hello all,
>
> I make a litle patch to add the capacity to execut header() PHP
> function on a sanboxed environement.
> The call_back function for the output handler must have two parameters
> to work, one for the content and one for headers. Look at this example
> :
>
> <?php
> $Sandbox = new Runkit_Sandbox();
> $Sandbox->header("X-Powered-By: PHP-sandoxed");
>
> function callback($content, $headers){
> foreach($headers as $header)
> header($header);
> echo($content);
> }
>
> runkit_sandbox_output_handler($Sandbox, "callback");
> ?>
>
> I try this solution with php-cgi, works fine. Apply the patch to the
> last CVS version of runkit_sandbox.c .
>
> This is my first patch, please be concilient with me :)
>
> (Sorry for my poor english)
>
>
> Julien Mortuaire
>
>