lbarnaud Thu Nov 13 10:14:04 2008 UTC Added files: (Branch: PHP_5_3) /php-src/sapi/cgi/tests 011.phpt
Modified files: /php-src NEWS /php-src/ext/standard basic_functions.c head.c head.h /php-src/main SAPI.c SAPI.h /php-src/sapi/apache mod_php5.c /php-src/sapi/apache2handler sapi_apache2.c /php-src/sapi/cli php_cli.c Log: Added header_remove() (chsc at peytz dotdk, Arnaud) [DOC] proto void header_remove([string header_name]) Removes an HTTP header previously set using header() The header_name parameter is optionnal, all headers are removed if it is not set [SAPIs] The header_handler callback in sapi_module_struct has been changed, it now take a new argument. When it is set to SAPI_HEADER_DELETE, sapi_header->header is the name of an header, header_handler has to delete it. When it is set to SAPI_HEADER_DELETE_ALL, header_handler has to delete all headers. When sapi_header_op_enum is SAPI_HEADER_ADD or _REPLACE, sapi_header->header is in the form "Name: value", header_handler has to add or replace the given header. In all cases, header_handler must not free sapi_header or sapi_header->header. SAPI_HEADER_ADD must be returned if the header has been added or replaced, or 0 in other cases.
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.375&r2=1.2027.2.547.2.965.2.376&diff_format=u Index: php-src/NEWS diff -u php-src/NEWS:1.2027.2.547.2.965.2.375 php-src/NEWS:1.2027.2.547.2.965.2.376 --- php-src/NEWS:1.2027.2.547.2.965.2.375 Thu Nov 13 05:47:47 2008 +++ php-src/NEWS Thu Nov 13 10:14:03 2008 @@ -10,6 +10,7 @@ parameter validation. (Felipe) - Changed openssl info to show the shared library version number. (Scott) +- Added header_remove() function. (chsc at peytz dot dk, Arnaud) - Added stream_context_get_params() function. (Arnaud) - Added optional parameter "new" to sybase_connect() (Timm) - Added parse_ini_string() function. (grange at lemonde dot fr, Arnaud) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.725.2.31.2.64.2.70&r2=1.725.2.31.2.64.2.71&diff_format=u Index: php-src/ext/standard/basic_functions.c diff -u php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.70 php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.71 --- php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.70 Thu Nov 13 05:47:47 2008 +++ php-src/ext/standard/basic_functions.c Thu Nov 13 10:14:03 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.70 2008/11/13 05:47:47 lbarnaud Exp $ */ +/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.71 2008/11/13 10:14:03 lbarnaud Exp $ */ #include "php.h" #include "php_streams.h" @@ -1692,6 +1692,11 @@ ZEND_END_ARG_INFO() static +ZEND_BEGIN_ARG_INFO_EX(arginfo_header_remove, 0, 0, 0) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +static ZEND_BEGIN_ARG_INFO_EX(arginfo_setcookie, 0, 0, 1) ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(0, value) @@ -3455,6 +3460,7 @@ PHP_FE(setcookie, arginfo_setcookie) PHP_FE(setrawcookie, arginfo_setrawcookie) PHP_FE(header, arginfo_header) + PHP_FE(header_remove, arginfo_header_remove) PHP_FE(headers_sent, arginfo_headers_sent) PHP_FE(headers_list, arginfo_headers_list) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/head.c?r1=1.84.2.1.2.7.2.5&r2=1.84.2.1.2.7.2.6&diff_format=u Index: php-src/ext/standard/head.c diff -u php-src/ext/standard/head.c:1.84.2.1.2.7.2.5 php-src/ext/standard/head.c:1.84.2.1.2.7.2.6 --- php-src/ext/standard/head.c:1.84.2.1.2.7.2.5 Tue Oct 21 22:08:37 2008 +++ php-src/ext/standard/head.c Thu Nov 13 10:14:04 2008 @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: head.c,v 1.84.2.1.2.7.2.5 2008/10/21 22:08:37 lbarnaud Exp $ */ +/* $Id: head.c,v 1.84.2.1.2.7.2.6 2008/11/13 10:14:04 lbarnaud Exp $ */ #include <stdio.h> #include "php.h" @@ -50,6 +50,20 @@ } /* }}} */ +/* {{{ proto void header_remove([string name]) + Removes an HTTP header previously set using header() */ +PHP_FUNCTION(header_remove) +{ + sapi_header_line ctr = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &ctr.line, + &ctr.line_len) == FAILURE) + return; + + sapi_header_op(ZEND_NUM_ARGS() == 0 ? SAPI_HEADER_DELETE_ALL : SAPI_HEADER_DELETE, &ctr TSRMLS_CC); +} +/* }}} */ + PHPAPI int php_header(TSRMLS_D) { if (sapi_send_headers(TSRMLS_C)==FAILURE || SG(request_info).headers_only) { http://cvs.php.net/viewvc.cgi/php-src/ext/standard/head.h?r1=1.28.2.1.2.2.2.1&r2=1.28.2.1.2.2.2.2&diff_format=u Index: php-src/ext/standard/head.h diff -u php-src/ext/standard/head.h:1.28.2.1.2.2.2.1 php-src/ext/standard/head.h:1.28.2.1.2.2.2.2 --- php-src/ext/standard/head.h:1.28.2.1.2.2.2.1 Mon Dec 31 07:17:15 2007 +++ php-src/ext/standard/head.h Thu Nov 13 10:14:04 2008 @@ -16,13 +16,14 @@ +----------------------------------------------------------------------+ */ -/* $Id: head.h,v 1.28.2.1.2.2.2.1 2007/12/31 07:17:15 sebastian Exp $ */ +/* $Id: head.h,v 1.28.2.1.2.2.2.2 2008/11/13 10:14:04 lbarnaud Exp $ */ #ifndef HEAD_H #define HEAD_H extern PHP_RINIT_FUNCTION(head); PHP_FUNCTION(header); +PHP_FUNCTION(header_remove); PHP_FUNCTION(setcookie); PHP_FUNCTION(setrawcookie); PHP_FUNCTION(headers_sent); http://cvs.php.net/viewvc.cgi/php-src/main/SAPI.c?r1=1.202.2.7.2.15.2.4&r2=1.202.2.7.2.15.2.5&diff_format=u Index: php-src/main/SAPI.c diff -u php-src/main/SAPI.c:1.202.2.7.2.15.2.4 php-src/main/SAPI.c:1.202.2.7.2.15.2.5 --- php-src/main/SAPI.c:1.202.2.7.2.15.2.4 Tue Mar 18 21:42:50 2008 +++ php-src/main/SAPI.c Thu Nov 13 10:14:04 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: SAPI.c,v 1.202.2.7.2.15.2.4 2008/03/18 21:42:50 rasmus Exp $ */ +/* $Id: SAPI.c,v 1.202.2.7.2.15.2.5 2008/11/13 10:14:04 lbarnaud Exp $ */ #include <ctype.h> #include <sys/stat.h> @@ -497,7 +497,8 @@ static int sapi_find_matching_header(void *element1, void *element2) { - return strncasecmp(((sapi_header_struct*)element1)->header, (char*)element2, strlen((char*)element2)) == 0; + int len = strlen((char*)element2); + return strncasecmp(((sapi_header_struct*)element1)->header, (char*)element2, len) == 0 && ((sapi_header_struct*)element1)->header[len] == ':'; } SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bool duplicate, zend_bool replace TSRMLS_DC) @@ -525,7 +526,6 @@ long myuid = 0L; char *header_line; uint header_line_len; - zend_bool replace; int http_response_code; if (SG(headers_sent) && !SG(request_info).no_headers) { @@ -546,8 +546,9 @@ sapi_update_response_code((int)(zend_intptr_t) arg TSRMLS_CC); return SUCCESS; + case SAPI_HEADER_ADD: case SAPI_HEADER_REPLACE: - case SAPI_HEADER_ADD: { + case SAPI_HEADER_DELETE: { sapi_header_line *p = arg; if (!p->line || !p->line_len) { @@ -556,10 +557,16 @@ header_line = p->line; header_line_len = p->line_len; http_response_code = p->response_code; - replace = (op == SAPI_HEADER_REPLACE); break; } + case SAPI_HEADER_DELETE_ALL: + if (sapi_module.header_handler) { + sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers) TSRMLS_CC); + } + zend_llist_clean(&SG(sapi_headers).headers); + return SUCCESS; + default: return FAILURE; } @@ -570,8 +577,14 @@ while(header_line_len && isspace(header_line[header_line_len-1])) header_line[--header_line_len]='\0'; - /* new line safety check */ - { + if (op == SAPI_HEADER_DELETE) { + if (strchr(header_line, ':')) { + efree(header_line); + sapi_module.sapi_error(E_WARNING, "Header to delete may not contain colon."); + return FAILURE; + } + } else { + /* new line safety check */ char *s = header_line, *e = header_line + header_line_len, *p; while (s < e && (p = memchr(s, '\n', (e - s)))) { if (*(p + 1) == ' ' || *(p + 1) == '\t') { @@ -586,7 +599,15 @@ sapi_header.header = header_line; sapi_header.header_len = header_line_len; - sapi_header.replace = replace; + + if (op == SAPI_HEADER_DELETE) { + if (sapi_module.header_handler) { + sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers) TSRMLS_CC); + } + zend_llist_del_element(&SG(sapi_headers).headers, sapi_header.header, (int(*)(void*, void*))sapi_find_matching_header); + sapi_free_header(&sapi_header); + return SUCCESS; + } /* Check the header for a few cases that we have special support for in SAPI */ if (header_line_len>=5 @@ -728,20 +749,16 @@ sapi_update_response_code(http_response_code TSRMLS_CC); } if (sapi_module.header_handler) { - retval = sapi_module.header_handler(&sapi_header, &SG(sapi_headers) TSRMLS_CC); + retval = sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers) TSRMLS_CC); } else { retval = SAPI_HEADER_ADD; } - if (retval & SAPI_HEADER_DELETE_ALL) { - zend_llist_clean(&SG(sapi_headers).headers); - } if (retval & SAPI_HEADER_ADD) { /* in replace mode first remove the header if it already exists in the headers llist */ - if (replace) { + if (op == SAPI_HEADER_REPLACE) { colon_offset = strchr(sapi_header.header, ':'); if (colon_offset) { char sav; - colon_offset++; sav = *colon_offset; *colon_offset = 0; zend_llist_del_element(&SG(sapi_headers).headers, sapi_header.header, (int(*)(void*, void*))sapi_find_matching_header); @@ -750,6 +767,8 @@ } zend_llist_add_element(&SG(sapi_headers).headers, (void *) &sapi_header); + } else { + sapi_free_header(&sapi_header); } return SUCCESS; } http://cvs.php.net/viewvc.cgi/php-src/main/SAPI.h?r1=1.114.2.1.2.3.2.3&r2=1.114.2.1.2.3.2.4&diff_format=u Index: php-src/main/SAPI.h diff -u php-src/main/SAPI.h:1.114.2.1.2.3.2.3 php-src/main/SAPI.h:1.114.2.1.2.3.2.4 --- php-src/main/SAPI.h:1.114.2.1.2.3.2.3 Tue Mar 18 21:42:50 2008 +++ php-src/main/SAPI.h Thu Nov 13 10:14:04 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: SAPI.h,v 1.114.2.1.2.3.2.3 2008/03/18 21:42:50 rasmus Exp $ */ +/* $Id: SAPI.h,v 1.114.2.1.2.3.2.4 2008/11/13 10:14:04 lbarnaud Exp $ */ #ifndef SAPI_H #define SAPI_H @@ -50,7 +50,6 @@ typedef struct { char *header; uint header_len; - zend_bool replace; } sapi_header_struct; @@ -170,6 +169,8 @@ typedef enum { /* Parameter: */ SAPI_HEADER_REPLACE, /* sapi_header_line* */ SAPI_HEADER_ADD, /* sapi_header_line* */ + SAPI_HEADER_DELETE, /* sapi_header_line* */ + SAPI_HEADER_DELETE_ALL, /* void */ SAPI_HEADER_SET_STATUS /* int */ } sapi_header_op_enum; @@ -227,7 +228,7 @@ void (*sapi_error)(int type, const char *error_msg, ...); - int (*header_handler)(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC); + int (*header_handler)(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC); int (*send_headers)(sapi_headers_struct *sapi_headers TSRMLS_DC); void (*send_header)(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC); @@ -275,8 +276,6 @@ /* header_handler() constants */ #define SAPI_HEADER_ADD (1<<0) -#define SAPI_HEADER_DELETE_ALL (1<<1) -#define SAPI_HEADER_SEND_NOW (1<<2) #define SAPI_HEADER_SENT_SUCCESSFULLY 1 http://cvs.php.net/viewvc.cgi/php-src/sapi/apache/mod_php5.c?r1=1.19.2.7.2.13.2.7&r2=1.19.2.7.2.13.2.8&diff_format=u Index: php-src/sapi/apache/mod_php5.c diff -u php-src/sapi/apache/mod_php5.c:1.19.2.7.2.13.2.7 php-src/sapi/apache/mod_php5.c:1.19.2.7.2.13.2.8 --- php-src/sapi/apache/mod_php5.c:1.19.2.7.2.13.2.7 Sat Jun 28 10:01:17 2008 +++ php-src/sapi/apache/mod_php5.c Thu Nov 13 10:14:04 2008 @@ -17,7 +17,7 @@ | PHP 4.0 patches by Zeev Suraski <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: mod_php5.c,v 1.19.2.7.2.13.2.7 2008/06/28 10:01:17 indeyets Exp $ */ +/* $Id: mod_php5.c,v 1.19.2.7.2.13.2.8 2008/11/13 10:14:04 lbarnaud Exp $ */ #include "php_apache_http.h" #include "http_conf_globals.h" @@ -35,7 +35,7 @@ static void php_restore_umask(void); static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC); static char *sapi_apache_read_cookies(TSRMLS_D); -static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC); +static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC); static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC); static int send_php(request_rec *r, int display_source_mode, char *filename); static int send_parsed_php(request_rec * r); @@ -163,41 +163,54 @@ /* {{{ sapi_apache_header_handler */ -static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC) +static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC) { char *header_name, *header_content, *p; request_rec *r = (request_rec *) SG(server_context); if(!r) { - efree(sapi_header->header); return 0; } - header_name = sapi_header->header; + switch(op) { + case SAPI_HEADER_DELETE_ALL: + clear_table(r->headers_out); + return 0; + + case SAPI_HEADER_DELETE: + table_unset(r->headers_out, sapi_header->header); + return 0; + + case SAPI_HEADER_ADD: + case SAPI_HEADER_REPLACE: + header_name = sapi_header->header; + + header_content = p = strchr(header_name, ':'); + if (!p) { + return 0; + } - header_content = p = strchr(header_name, ':'); - if (!p) { - efree(sapi_header->header); - return 0; - } + *p = 0; + do { + header_content++; + } while (*header_content==' '); + + if (!strcasecmp(header_name, "Content-Type")) { + r->content_type = pstrdup(r->pool, header_content); + } else if (!strcasecmp(header_name, "Set-Cookie")) { + table_add(r->headers_out, header_name, header_content); + } else if (op == SAPI_HEADER_REPLACE) { + table_set(r->headers_out, header_name, header_content); + } else { + table_add(r->headers_out, header_name, header_content); + } - *p = 0; - do { - header_content++; - } while (*header_content==' '); - - if (!strcasecmp(header_name, "Content-Type")) { - r->content_type = pstrdup(r->pool, header_content); - } else if (!strcasecmp(header_name, "Set-Cookie")) { - table_add(r->headers_out, header_name, header_content); - } else if (sapi_header->replace) { - table_set(r->headers_out, header_name, header_content); - } else { - table_add(r->headers_out, header_name, header_content); - } + *p = ':'; /* a well behaved header handler shouldn't change its original arguments */ - *p = ':'; /* a well behaved header handler shouldn't change its original arguments */ + return SAPI_HEADER_ADD; - return SAPI_HEADER_ADD; + default: + return 0; + } } /* }}} */ http://cvs.php.net/viewvc.cgi/php-src/sapi/apache2handler/sapi_apache2.c?r1=1.57.2.10.2.15.2.3&r2=1.57.2.10.2.15.2.4&diff_format=u Index: php-src/sapi/apache2handler/sapi_apache2.c diff -u php-src/sapi/apache2handler/sapi_apache2.c:1.57.2.10.2.15.2.3 php-src/sapi/apache2handler/sapi_apache2.c:1.57.2.10.2.15.2.4 --- php-src/sapi/apache2handler/sapi_apache2.c:1.57.2.10.2.15.2.3 Tue Mar 18 22:23:20 2008 +++ php-src/sapi/apache2handler/sapi_apache2.c Thu Nov 13 10:14:04 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: sapi_apache2.c,v 1.57.2.10.2.15.2.3 2008/03/18 22:23:20 rasmus Exp $ */ +/* $Id: sapi_apache2.c,v 1.57.2.10.2.15.2.4 2008/11/13 10:14:04 lbarnaud Exp $ */ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS @@ -83,40 +83,55 @@ } static int -php_apache_sapi_header_handler(sapi_header_struct *sapi_header,sapi_headers_struct *sapi_headers TSRMLS_DC) +php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC) { php_struct *ctx; char *val, *ptr; ctx = SG(server_context); - val = strchr(sapi_header->header, ':'); + switch (op) { + case SAPI_HEADER_DELETE: + apr_table_unset(ctx->r->headers_out, sapi_header->header); + return 0; + + case SAPI_HEADER_DELETE_ALL: + apr_table_clear(ctx->r->headers_out); + return 0; + + case SAPI_HEADER_ADD: + case SAPI_HEADER_REPLACE: + val = strchr(sapi_header->header, ':'); - if (!val) { - sapi_free_header(sapi_header); - return 0; - } - ptr = val; + if (!val) { + return 0; + } + ptr = val; - *val = '\0'; + *val = '\0'; - do { - val++; - } while (*val == ' '); - - if (!strcasecmp(sapi_header->header, "content-type")) { - if (ctx->content_type) { - efree(ctx->content_type); - } - ctx->content_type = estrdup(val); - } else if (sapi_header->replace) { - apr_table_set(ctx->r->headers_out, sapi_header->header, val); - } else { - apr_table_add(ctx->r->headers_out, sapi_header->header, val); + do { + val++; + } while (*val == ' '); + + if (!strcasecmp(sapi_header->header, "content-type")) { + if (ctx->content_type) { + efree(ctx->content_type); + } + ctx->content_type = estrdup(val); + } else if (op == SAPI_HEADER_REPLACE) { + apr_table_set(ctx->r->headers_out, sapi_header->header, val); + } else { + apr_table_add(ctx->r->headers_out, sapi_header->header, val); + } + + *ptr = ':'; + + return SAPI_HEADER_ADD; + + default: + return 0; } - *ptr = ':'; - - return SAPI_HEADER_ADD; } static int http://cvs.php.net/viewvc.cgi/php-src/sapi/cli/php_cli.c?r1=1.129.2.13.2.22.2.15&r2=1.129.2.13.2.22.2.16&diff_format=u Index: php-src/sapi/cli/php_cli.c diff -u php-src/sapi/cli/php_cli.c:1.129.2.13.2.22.2.15 php-src/sapi/cli/php_cli.c:1.129.2.13.2.22.2.16 --- php-src/sapi/cli/php_cli.c:1.129.2.13.2.22.2.15 Thu Aug 14 09:46:26 2008 +++ php-src/sapi/cli/php_cli.c Thu Nov 13 10:14:04 2008 @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_cli.c,v 1.129.2.13.2.22.2.15 2008/08/14 09:46:26 tony2001 Exp $ */ +/* $Id: php_cli.c,v 1.129.2.13.2.22.2.16 2008/11/13 10:14:04 lbarnaud Exp $ */ #include "php.h" #include "php_globals.h" @@ -347,11 +347,8 @@ } /* }}} */ -static int sapi_cli_header_handler(sapi_header_struct *h, sapi_headers_struct *s TSRMLS_DC) /* {{{ */ +static int sapi_cli_header_handler(sapi_header_struct *h, sapi_header_op_enum op, sapi_headers_struct *s TSRMLS_DC) /* {{{ */ { - /* free allocated header line */ - efree(h->header); - /* avoid pushing headers into SAPI headers list */ return 0; } /* }}} */ http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/tests/011.phpt?view=markup&rev=1.1 Index: php-src/sapi/cgi/tests/011.phpt +++ php-src/sapi/cgi/tests/011.phpt
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php