]> granicus.if.org Git - php/commitdiff
Add INI controlled default stream encoding (unicode.stream_encoding).
authorSara Golemon <pollita@php.net>
Tue, 19 Sep 2006 20:36:48 +0000 (20:36 +0000)
committerSara Golemon <pollita@php.net>
Tue, 19 Sep 2006 20:36:48 +0000 (20:36 +0000)
Add convenience function stream_defualt_encoding() for setting it.

Zend/zend.c
Zend/zend_globals.h
ext/standard/streamsfuncs.c
main/streams/streams.c

index 8bd09c67790fb32c9aef6126d03d2c3bc5c2dc86..079bea13ebd63f2ea7f2b2f62b9707a2fff35349 100644 (file)
@@ -181,6 +181,7 @@ ZEND_INI_BEGIN()
        STD_ZEND_INI_ENTRY("unicode.script_encoding",  NULL, ZEND_INI_ALL, OnUpdateEncoding,   script_encoding_conv, zend_unicode_globals, unicode_globals)
        STD_ZEND_INI_ENTRY("unicode.http_input_encoding",  NULL, ZEND_INI_ALL, OnUpdateEncoding,   http_input_encoding_conv, zend_unicode_globals, unicode_globals)
        STD_ZEND_INI_ENTRY("unicode.filesystem_encoding",  NULL, ZEND_INI_ALL, OnUpdateEncoding,   filesystem_encoding_conv, zend_unicode_globals, unicode_globals)
+       STD_ZEND_INI_ENTRY("unicode.stream_encoding",  "utf8", ZEND_INI_ALL, OnUpdateStringUnempty,   stream_encoding, zend_unicode_globals, unicode_globals)
 ZEND_INI_END()
 
 
index 2b8ca89d8ec533375ed1aaeed0b6edb9d9edf16a..710e52f3b625656969e8e419ef67819fff73f76d 100644 (file)
@@ -276,6 +276,10 @@ struct _zend_unicode_globals {
        UConverter *utf8_conv;                           /* all-purpose UTF-8 converter */
        UConverter *ascii_conv;                          /* all-purpose ASCII converter */
 
+       char *stream_encoding;              /* default stream encoding (contents, not FS entries)
+                                               Uses name of encoding rather than a real converter
+                                               because each stream needs its own instance */
+
        uint16_t from_error_mode;
        UChar from_subst_char[3];
        uint16_t to_error_mode;
index 9b08f9c0586bf48d86ee9765269b8c5a8b7a707e..3dcac49748877ab72a074335f20f93780c1e56d4 100644 (file)
@@ -1458,6 +1458,24 @@ PHP_FUNCTION(stream_socket_enable_crypto)
 }
 /* }}} */
 
+
+/* {{{ proto bool stream_default_encoding(string encoding) U
+Convenience wrapper for ini_set('unicode.stream_encoding', $encoding) */
+PHP_FUNCTION(stream_default_encoding)
+{
+       char *encoding;
+       int encoding_len;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &encoding, &encoding_len) == FAILURE) {
+               return;
+       }
+
+       RETURN_BOOL(SUCCESS == zend_alter_ini_entry("unicode.stream_encoding", sizeof("unicode.stream_encoding"),
+                                                       encoding, encoding_len, PHP_INI_ALL, PHP_INI_STAGE_RUNTIME));
+}
+/* }}} */
+
+
 /* {{{ proto void stream_encoding(resource stream[, string encoding])
 Set character set for stream encoding
 UTODO: Return current encoding charset
index 4176dcb850471a697bb62d2c46b2e286d20ccabd..2aa84d0ee1a15545a58bc5c8a9c867241279329a 100755 (executable)
@@ -2306,7 +2306,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int optio
                /* Only apply implicit unicode.to. filter if the wrapper didn't do it for us */
                if ((php_stream_filter_product(&stream->writefilters, IS_UNICODE) == IS_UNICODE) && 
                        (strchr(implicit_mode, 'w') || strchr(implicit_mode, 'a') || strchr(implicit_mode, '+'))) {
-                       char *encoding = (context && context->output_encoding) ? context->output_encoding : "utf8";
+                       char *encoding = (context && context->output_encoding) ? context->output_encoding : UG(stream_encoding);
 
                        /* UTODO: (Maybe?) Allow overriding the default error handlers on a per-stream basis via context params */
                        php_stream_encoding_apply(stream, 1, encoding, UG(from_error_mode), UG(from_subst_char));
@@ -2314,7 +2314,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int optio
 
                /* Only apply implicit unicode.from. filter if the wrapper didn't do it for us */
                if ((stream->readbuf_type == IS_STRING) && (strchr(implicit_mode, 'r') || strchr(implicit_mode, '+'))) {
-                       char *encoding = (context && context->input_encoding) ? context->input_encoding : "utf8";
+                       char *encoding = (context && context->input_encoding) ? context->input_encoding : UG(stream_encoding);
 
                        /* UTODO: (Maybe?) Allow overriding the default error handlers on a per-stream basis via context params */
                        php_stream_encoding_apply(stream, 0, encoding, UG(to_error_mode), NULL);