Hello all, hello Andi.

Andi, I'd like to ask your permission to commit the patch for 
http://bugs.php.net/bug.php?id=29983
It adds OnUpdateDefaultCharset, which calls sapi_header_op() (only in runtime) 
to substitute SAPI content-type/charset header.
See the patch in attachment.

-- 
Wbr, 
Antony Dovgal
Index: main/main.c
===================================================================
RCS file: /repository/php-src/main/main.c,v
retrieving revision 1.634
diff -u -p -d -r1.634 main.c
--- main/main.c 20 Jun 2005 19:58:51 -0000      1.634
+++ main/main.c 22 Jun 2005 21:22:18 -0000
@@ -207,6 +207,43 @@ static PHP_INI_MH(OnUpdateTimeout)
 }
 /* }}} */
 
+/* {{{ PHP_INI_MH
+ */
+static PHP_INI_MH(OnUpdateDefaultCharset)
+{
+       if (stage == PHP_INI_STAGE_RUNTIME) {
+               sapi_header_line ctr = {0};
+               int mimetype_len = SG(default_mimetype) ? 
strlen(SG(default_mimetype)) : 0;
+               
+               if (new_value_length) {
+                       ctr.line = emalloc( sizeof("Content-type: ")-1 + 
mimetype_len + sizeof("; charset=")-1 + new_value_length + 1);
+               
+                       memcpy(ctr.line, "Content-type: ", 
sizeof("Content-type: "));
+                       memcpy(ctr.line + sizeof("Content-type: ")-1, 
SG(default_mimetype), mimetype_len);
+                       memcpy(ctr.line + sizeof("Content-type: ")-1 + 
mimetype_len, "; charset=", sizeof("; charset="));
+                       memcpy(ctr.line + sizeof("Content-type: ")-1 + 
mimetype_len + sizeof("; charset=")-1, new_value, new_value_length);
+
+                       ctr.line_len = sizeof("Content-type: ")-1 + 
mimetype_len + sizeof("; charset=")-1 + new_value_length;
+               }
+               else {
+                       ctr.line = emalloc( sizeof("Content-type: ")-1 + 
mimetype_len + 1);
+                       
+                       memcpy(ctr.line, "Content-type: ", 
sizeof("Content-type: "));
+                       memcpy(ctr.line + sizeof("Content-type: ")-1, 
SG(default_mimetype), mimetype_len);
+
+                       ctr.line_len = sizeof("Content-type: ")-1 + 
mimetype_len;
+               }
+               ctr.line[ctr.line_len] = 0;
+               
+               sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
+               efree(ctr.line);
+       }
+
+       OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, 
mh_arg3, stage TSRMLS_CC);
+       return SUCCESS;
+}
+/* }}} */
+
 /* Need to convert to strings and make use of:
  * PHP_SAFE_MODE
  *
@@ -287,8 +324,8 @@ PHP_INI_BEGIN()
        STD_PHP_INI_ENTRY("auto_append_file",           NULL,           
PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateString,                 
auto_append_file,               php_core_globals,       core_globals)
        STD_PHP_INI_ENTRY("auto_prepend_file",          NULL,           
PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateString,                 
auto_prepend_file,              php_core_globals,       core_globals)
        STD_PHP_INI_ENTRY("doc_root",                           NULL,           
PHP_INI_SYSTEM,         OnUpdateStringUnempty,  doc_root,                       
        php_core_globals,       core_globals)
-       STD_PHP_INI_ENTRY("default_charset",            SAPI_DEFAULT_CHARSET,   
PHP_INI_ALL,    OnUpdateString,                 default_charset,                
sapi_globals_struct,sapi_globals)
        STD_PHP_INI_ENTRY("default_mimetype",           SAPI_DEFAULT_MIMETYPE,  
PHP_INI_ALL,    OnUpdateString,                 default_mimetype,               
sapi_globals_struct,sapi_globals)
+       STD_PHP_INI_ENTRY("default_charset",            SAPI_DEFAULT_CHARSET,   
PHP_INI_ALL,    OnUpdateDefaultCharset,                 default_charset,        
        sapi_globals_struct,sapi_globals)
        STD_PHP_INI_ENTRY("error_log",                          NULL,           
PHP_INI_ALL,            OnUpdateString,                 error_log,              
                php_core_globals,       core_globals)
        STD_PHP_INI_ENTRY("extension_dir",                      
PHP_EXTENSION_DIR,              PHP_INI_SYSTEM,         OnUpdateStringUnempty,  
extension_dir,                  php_core_globals,       core_globals)
        STD_PHP_INI_ENTRY("include_path",                       
PHP_INCLUDE_PATH,               PHP_INI_ALL,            OnUpdateStringUnempty,  
include_path,                   php_core_globals,       core_globals)

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to