cvs: php4 /ext/mbstring mbstring.c /main SAPI.c SAPI.h

From: Date: Sat, 27 Jul 2002 13:58:16 +0000
Subject: cvs: php4 /ext/mbstring mbstring.c /main SAPI.c SAPI.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-13003@lists.php.net to get a copy of this message
hirokawa Sat Jul 27 09:58:16 2002 EDT Modified files: /php4/ext/mbstring mbstring.c /php4/main SAPI.c SAPI.h Log: fixed: output encoding translation by mb_output_handler() in ext/mbstring was not usable when Content-Type is set by header(). Index: php4/ext/mbstring/mbstring.c diff -u php4/ext/mbstring/mbstring.c:1.81 php4/ext/mbstring/mbstring.c:1.82 --- php4/ext/mbstring/mbstring.c:1.81 Mon Jul 15 13:48:54 2002 +++ php4/ext/mbstring/mbstring.c Sat Jul 27 09:58:16 2002 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mbstring.c,v 1.81 2002/07/15 17:48:54 edink Exp $ */ +/* $Id: mbstring.c,v 1.82 2002/07/27 13:58:16 hirokawa Exp $ */ /* * PHP4 Multibyte String module "mbstring" (currently only for Japanese) @@ -1728,10 +1728,12 @@ size_t arg_string_len; long arg_status; mbfl_string string, result; - const char *mimetype, *charset; + const char *charset; char *p; enum mbfl_no_encoding encoding; int last_feed, len; + unsigned char send_text_mimetype = 0; + char *s, *mimetype = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &arg_string, &arg_string_len, &arg_status) == FAILURE) { WRONG_PARAM_COUNT; @@ -1749,9 +1751,22 @@ if (encoding == mbfl_no_encoding_pass) { RETURN_STRINGL(arg_string, arg_string_len, 1); } - /* if content-type is not yet set, set it and activate the converter */ - if (SG(sapi_headers).send_default_content_type ) { + + /* analyze mime type */ + if (SG(sapi_headers).mimetype && + strncmp(SG(sapi_headers).mimetype, "text/", 5) == 0) { + if ((s = strchr(SG(sapi_headers).mimetype,';')) == NULL){ + mimetype = estrdup(SG(sapi_headers).mimetype); + } else { + mimetype = estrndup(SG(sapi_headers).mimetype,s-SG(sapi_headers).mimetype); + } + send_text_mimetype = 1; + } else if (SG(sapi_headers).send_default_content_type) { mimetype = SG(default_mimetype) ? SG(default_mimetype) : SAPI_DEFAULT_MIMETYPE; + } + + /* if content-type is not yet set, set it and activate the converter */ + if (SG(sapi_headers).send_default_content_type || send_text_mimetype) { charset = mbfl_no2preferred_mime_name(encoding); if (charset) { len = (sizeof ("Content-Type:")-1) + strlen(mimetype) + (sizeof (";charset=")-1) + strlen(charset) + 1; @@ -1765,6 +1780,9 @@ } /* activate the converter */ MBSTRG(outconv) = mbfl_buffer_converter_new(MBSTRG(current_internal_encoding), encoding, 0 TSRMLS_CC); + if (send_text_mimetype){ + efree(mimetype); + } } } Index: php4/main/SAPI.c diff -u php4/main/SAPI.c:1.136 php4/main/SAPI.c:1.137 --- php4/main/SAPI.c:1.136 Fri Jul 12 20:15:22 2002 +++ php4/main/SAPI.c Sat Jul 27 09:58:16 2002 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: SAPI.c,v 1.136 2002/07/13 00:15:22 sniper Exp $ */ +/* $Id: SAPI.c,v 1.137 2002/07/27 13:58:16 hirokawa Exp $ */ #include <ctype.h> #include <sys/stat.h> @@ -490,6 +490,10 @@ } mimetype = estrdup(ptr); newlen = sapi_apply_default_charset(&mimetype, len TSRMLS_CC); + if (!SG(sapi_headers).mimetype){ + SG(sapi_headers).mimetype = estrdup(mimetype); + } + if (newlen != 0) { newlen += sizeof("Content-type: "); newheader = emalloc(newlen); @@ -676,6 +680,9 @@ if (SG(sapi_headers).http_status_line) { efree(SG(sapi_headers).http_status_line); + } + if (SG(sapi_headers).mimetype) { + efree(SG(sapi_headers).mimetype); } return ret; Index: php4/main/SAPI.h diff -u php4/main/SAPI.h:1.83 php4/main/SAPI.h:1.84 --- php4/main/SAPI.h:1.83 Wed Jul 3 06:42:31 2002 +++ php4/main/SAPI.h Sat Jul 27 09:58:16 2002 @@ -51,6 +51,7 @@ zend_llist headers; int http_response_code; unsigned char send_default_content_type; + char *mimetype; char *http_status_line; } sapi_headers_struct;

« previous php.cvs (#13003) next »