thetaphi Sat Nov 29 14:45:51 2008 UTC
Modified files: (Branch: PHP_5_3)
/php-src/sapi/nsapi nsapi.c
Log:
MFH:
- Implement the changes needed for http://news.php.net/php.cvs/54228
- Additionally implement flushing in NSAPI and fix some small things
http://cvs.php.net/viewvc.cgi/php-src/sapi/nsapi/nsapi.c?r1=1.69.2.3.2.6.2.9&r2=1.69.2.3.2.6.2.10&diff_format=u
Index: php-src/sapi/nsapi/nsapi.c
diff -u php-src/sapi/nsapi/nsapi.c:1.69.2.3.2.6.2.9
php-src/sapi/nsapi/nsapi.c:1.69.2.3.2.6.2.10
--- php-src/sapi/nsapi/nsapi.c:1.69.2.3.2.6.2.9 Mon Nov 17 11:28:01 2008
+++ php-src/sapi/nsapi/nsapi.c Sat Nov 29 14:45:51 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: nsapi.c,v 1.69.2.3.2.6.2.9 2008/11/17 11:28:01 felipe Exp $ */
+/* $Id: nsapi.c,v 1.69.2.3.2.6.2.10 2008/11/29 14:45:51 thetaphi Exp $ */
/*
* PHP includes
@@ -321,7 +321,7 @@
PHP_MINFO_FUNCTION(nsapi)
{
php_info_print_table_start();
- php_info_print_table_row(2, "NSAPI Module Revision", "$Revision:
1.69.2.3.2.6.2.9 $");
+ php_info_print_table_row(2, "NSAPI Module Revision", "$Revision:
1.69.2.3.2.6.2.10 $");
php_info_print_table_row(2, "Server Software", system_version());
php_info_print_table_row(2, "Sub-requests with nsapi_virtual()",
(nsapi_servact_service)?((zend_ini_long("zlib.output_compression",
sizeof("zlib.output_compression"), 0))?"not supported with
zlib.output_compression":"enabled"):"not supported on this platform" );
@@ -446,8 +446,6 @@
array_init(return_value);
- php_header(TSRMLS_C);
-
for (i=0; i < rc->rq->srvhdrs->hsize; i++) {
entry=rc->rq->srvhdrs->ht[i];
while (entry) {
@@ -466,9 +464,12 @@
static int sapi_nsapi_ub_write(const char *str, unsigned int str_length
TSRMLS_DC)
{
int retval;
- nsapi_request_context *rc;
+ nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
+
+ if (!SG(headers_sent)) {
+ sapi_send_headers(TSRMLS_C);
+ }
- rc = (nsapi_request_context *)SG(server_context);
retval = net_write(rc->sn->csd, (char *)str, str_length);
if (retval == IO_ERROR /* -1 */ || retval == IO_EOF /* 0 */) {
php_handle_aborted_connection();
@@ -476,38 +477,102 @@
return retval;
}
-static int sapi_nsapi_header_handler(sapi_header_struct *sapi_header,
sapi_headers_struct *sapi_headers TSRMLS_DC)
+/* modified version of apache2 */
+static void sapi_nsapi_flush(void *server_context)
{
- char *header_name, *header_content, *p;
- nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
+ nsapi_request_context *rc = (nsapi_request_context *)server_context;
+ TSRMLS_FETCH();
- header_name = sapi_header->header;
- header_content = p = strchr(header_name, ':');
- if (p == NULL) {
- efree(sapi_header->header);
- return 0;
+ if (!rc) {
+ return;
}
- *p = 0;
- do {
- header_content++;
- } while (*header_content == ' ');
+ if (!SG(headers_sent)) {
+ sapi_send_headers(TSRMLS_C);
+ }
- if (!strcasecmp(header_name, "Content-Type")) {
- param_free(pblock_remove("content-type", rc->rq->srvhdrs));
- pblock_nvinsert("content-type", header_content,
rc->rq->srvhdrs);
- } else {
- /* to lower case because NSAPI reformats the headers and wants
lowercase */
- for (p=header_name; *p; p++) {
- *p=tolower(*p);
- }
- if (sapi_header->replace) param_free(pblock_remove(header_name,
rc->rq->srvhdrs));
- pblock_nvinsert(header_name, header_content, rc->rq->srvhdrs);
+ /* flushing is only supported in iPlanet servers from version 6.1 on,
make it conditional */
+#if defined(net_flush)
+ if (net_flush(rc->sn->csd) < 0) {
+ php_handle_aborted_connection();
}
+#endif
+}
- sapi_free_header(sapi_header);
+/* callback for zend_llist_apply on SAPI_HEADER_DELETE_ALL operation */
+static int php_nsapi_remove_header(sapi_header_struct *sapi_header TSRMLS_DC)
+{
+ char *header_name, *p;
+ nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
+
+ /* copy the header, because NSAPI needs reformatting and we do not want
to change the parameter */
+ header_name = nsapi_strdup(sapi_header->header);
- return 0; /* don't use the default SAPI mechanism, NSAPI
duplicates this functionality */
+ /* extract name, this works, if only the header without ':' is given,
too */
+ if (p = strchr(header_name, ':')) {
+ *p = 0;
+ }
+
+ /* header_name to lower case because NSAPI reformats the headers and
wants lowercase */
+ for (p=header_name; *p; p++) {
+ *p=tolower(*p);
+ }
+
+ /* remove the header */
+ param_free(pblock_remove(header_name, rc->rq->srvhdrs));
+ nsapi_free(header_name);
+
+ return ZEND_HASH_APPLY_KEEP;
+}
+
+static int sapi_nsapi_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;
+ nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
+
+ switch(op) {
+ case SAPI_HEADER_DELETE_ALL:
+ /* this only deletes headers set or overwritten by PHP,
headers previously set by NSAPI are left intact */
+ zend_llist_apply(&sapi_headers->headers,
(llist_apply_func_t) php_nsapi_remove_header TSRMLS_CC);
+ return 0;
+
+ case SAPI_HEADER_DELETE:
+ /* reuse the zend_llist_apply callback function for
this, too */
+ php_nsapi_remove_header(sapi_header TSRMLS_CC);
+ return 0;
+
+ case SAPI_HEADER_ADD:
+ case SAPI_HEADER_REPLACE:
+ /* copy the header, because NSAPI needs reformatting
and we do not want to change the parameter */
+ header_name = nsapi_strdup(sapi_header->header);
+
+ /* split header and align pointer for content */
+ header_content = strchr(header_name, ':');
+ if (header_content) {
+ *header_content = 0;
+ do {
+ header_content++;
+ } while (*header_content==' ');
+
+ /* header_name to lower case because NSAPI
reformats the headers and wants lowercase */
+ for (p=header_name; *p; p++) {
+ *p=tolower(*p);
+ }
+
+ /* if REPLACE, remove first. "Content-type" is
always removed, as SAPI has a bug according to this */
+ if (op==SAPI_HEADER_REPLACE ||
strcmp(header_name, "content-type")==0) {
+ param_free(pblock_remove(header_name,
rc->rq->srvhdrs));
+ }
+ /* ADD header to nsapi table */
+ pblock_nvinsert(header_name, header_content,
rc->rq->srvhdrs);
+ }
+
+ nsapi_free(header_name);
+ return SAPI_HEADER_ADD;
+
+ default:
+ return 0;
+ }
}
static int sapi_nsapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
@@ -760,7 +825,7 @@
NULL, /* deactivate */
sapi_nsapi_ub_write, /* unbuffered write */
- NULL, /* flush */
+ sapi_nsapi_flush, /* flush */
NULL, /* get uid */
NULL, /* getenv */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php