]> granicus.if.org Git - php/commitdiff
fixed: output encoding translation by mb_output_handler() in ext/mbstring was not...
authorRui Hirokawa <hirokawa@php.net>
Sat, 27 Jul 2002 13:15:42 +0000 (13:15 +0000)
committerRui Hirokawa <hirokawa@php.net>
Sat, 27 Jul 2002 13:15:42 +0000 (13:15 +0000)
ext/mbstring/mbstring.c
main/SAPI.c
main/SAPI.h

index 202aab5d996fd0af6d0bd8156325c4fdc2038b04..657ed6d6b3dcb155b56a7989d0f278c6a74d0d6c 100644 (file)
@@ -1489,10 +1489,12 @@ PHP_FUNCTION(mb_output_handler)
        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;
@@ -1510,9 +1512,23 @@ PHP_FUNCTION(mb_output_handler)
                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 or text mimetype is 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;
@@ -1526,6 +1542,9 @@ PHP_FUNCTION(mb_output_handler)
                        }
                        /* activate the converter */
                        MBSTRG(outconv) = mbfl_buffer_converter_new(MBSTRG(current_internal_encoding), encoding, 0);
+                       if (send_text_mimetype){
+                               efree(mimetype);
+                       }
                }
        }
 
index e351349c3565c42a1def4857595517d3f889a5bd..289041f35640a8b10941ce34cc4d9f2ff8c1da78 100644 (file)
@@ -284,6 +284,7 @@ SAPI_API void sapi_activate(TSRMLS_D)
        SG(sapi_headers).http_response_code = 200;
        */
        SG(sapi_headers).http_status_line = NULL;
+       SG(sapi_headers).mimetype = NULL;
        SG(headers_sent) = 0;
        SG(read_post_bytes) = 0;
        SG(request_info).post_data = NULL;
@@ -448,6 +449,10 @@ SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bo
                                }
                                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);
@@ -459,6 +464,7 @@ SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bo
                                        *colon_offset = '\0';
                                        efree(header_line);
                                }
+                               
                                efree(mimetype);
                                SG(sapi_headers).send_default_content_type = 0;
                        } else if (!STRCASECMP(header_line, "Location")) {
@@ -628,6 +634,9 @@ SAPI_API int sapi_send_headers(TSRMLS_D)
        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 1b228cb5f37d0509caa7289530e5dd3ab64d0130..4f84b5f8d4aea4ce14d31f3cbbfc4916927e7c33 100644 (file)
@@ -51,6 +51,7 @@ typedef struct {
        zend_llist headers;
        int http_response_code;
        unsigned char send_default_content_type;
+       char *mimetype;
        char *http_status_line;
 } sapi_headers_struct;