Annotation of embedaddon/php/Zend/zend_multibyte.c, revision 1.1.1.4

1.1       misho       1: /*
                      2:    +----------------------------------------------------------------------+
                      3:    | Zend Engine                                                          |
                      4:    +----------------------------------------------------------------------+
1.1.1.4 ! misho       5:    | Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) |
1.1       misho       6:    +----------------------------------------------------------------------+
                      7:    | This source file is subject to version 2.00 of the Zend license,     |
                      8:    | that is bundled with this package in the file LICENSE, and is        | 
                      9:    | available through the world-wide-web at                              |
                     10:    | http://www.zend.com/license/2_00.txt.                                |
                     11:    | If you did not receive a copy of the Zend license and are unable to  |
                     12:    | obtain it through the world-wide-web, please send a note to          |
                     13:    | license@zend.com so we can mail you a copy immediately.              |
                     14:    +----------------------------------------------------------------------+
                     15:    | Authors: Masaki Fujimoto <fujimoto@php.net>                          |
                     16:    |          Rui Hirokawa <hirokawa@php.net>                             |
                     17:    +----------------------------------------------------------------------+
                     18: */
                     19: 
1.1.1.2   misho      20: /* $Id$ */
1.1       misho      21: 
                     22: #include "zend.h"
                     23: #include "zend_compile.h"
                     24: #include "zend_operators.h"
                     25: #include "zend_multibyte.h"
1.1.1.2   misho      26: #include "zend_ini.h"
1.1       misho      27: 
1.1.1.2   misho      28: static const zend_encoding *dummy_encoding_fetcher(const char *encoding_name TSRMLS_DC)
1.1       misho      29: {
1.1.1.2   misho      30:        return NULL;
1.1       misho      31: }
                     32: 
1.1.1.2   misho      33: static const char *dummy_encoding_name_getter(const zend_encoding *encoding)
1.1       misho      34: {
1.1.1.2   misho      35:        return (const char*)encoding;
1.1       misho      36: }
                     37: 
1.1.1.2   misho      38: static int dummy_encoding_lexer_compatibility_checker(const zend_encoding *encoding)
1.1       misho      39: {
                     40:        return 0;
                     41: }
                     42: 
1.1.1.2   misho      43: static const zend_encoding *dummy_encoding_detector(const unsigned char *string, size_t length, const zend_encoding **list, size_t list_size TSRMLS_DC)
1.1       misho      44: {
                     45:        return NULL;
                     46: }
                     47: 
1.1.1.2   misho      48: static size_t dummy_encoding_converter(unsigned char **to, size_t *to_length, const unsigned char *from, size_t from_length, const zend_encoding *encoding_to, const zend_encoding *encoding_from TSRMLS_DC)
1.1       misho      49: {
1.1.1.2   misho      50:        return (size_t)-1;
1.1       misho      51: }
                     52: 
1.1.1.2   misho      53: static int dummy_encoding_list_parser(const char *encoding_list, size_t encoding_list_len, const zend_encoding ***return_list, size_t *return_size, int persistent TSRMLS_DC)
1.1       misho      54: {
1.1.1.2   misho      55:        *return_list = pemalloc(0, persistent);
                     56:        return_size = 0;
                     57:        return SUCCESS;
1.1       misho      58: }
                     59: 
1.1.1.2   misho      60: static const zend_encoding *dummy_internal_encoding_getter(TSRMLS_D)
1.1       misho      61: {
1.1.1.2   misho      62:        return NULL;
1.1       misho      63: }
                     64: 
1.1.1.2   misho      65: static int dummy_internal_encoding_setter(const zend_encoding *encoding TSRMLS_DC)
1.1       misho      66: {
1.1.1.2   misho      67:        return FAILURE;
1.1       misho      68: }
                     69: 
1.1.1.2   misho      70: static zend_multibyte_functions multibyte_functions = {
                     71:        NULL,
                     72:        dummy_encoding_fetcher,
                     73:        dummy_encoding_name_getter,
                     74:        dummy_encoding_lexer_compatibility_checker,
                     75:        dummy_encoding_detector,
                     76:        dummy_encoding_converter,
                     77:        dummy_encoding_list_parser,
                     78:        dummy_internal_encoding_getter,
                     79:        dummy_internal_encoding_setter
1.1       misho      80: };
                     81: 
1.1.1.2   misho      82: ZEND_API const zend_encoding *zend_multibyte_encoding_utf32be = (const zend_encoding*)"UTF-32BE";
                     83: ZEND_API const zend_encoding *zend_multibyte_encoding_utf32le = (const zend_encoding*)"UTF-32LE";
                     84: ZEND_API const zend_encoding *zend_multibyte_encoding_utf16be = (const zend_encoding*)"UTF-16BE";
                     85: ZEND_API const zend_encoding *zend_multibyte_encoding_utf16le = (const zend_encoding*)"UTF-32LE";
                     86: ZEND_API const zend_encoding *zend_multibyte_encoding_utf8 = (const zend_encoding*)"UTF-8";
1.1       misho      87: 
1.1.1.2   misho      88: ZEND_API int zend_multibyte_set_functions(const zend_multibyte_functions *functions TSRMLS_DC)
                     89: {
                     90:        zend_multibyte_encoding_utf32be = functions->encoding_fetcher("UTF-32BE" TSRMLS_CC);
                     91:        if (!zend_multibyte_encoding_utf32be) {
                     92:                return FAILURE;
1.1       misho      93:        }
1.1.1.2   misho      94:        zend_multibyte_encoding_utf32le = functions->encoding_fetcher("UTF-32LE" TSRMLS_CC);
                     95:        if (!zend_multibyte_encoding_utf32le) {
                     96:                return FAILURE;
                     97:        }
                     98:        zend_multibyte_encoding_utf16be = functions->encoding_fetcher("UTF-16BE" TSRMLS_CC);
                     99:        if (!zend_multibyte_encoding_utf16be) {
                    100:                return FAILURE;
                    101:        }
                    102:        zend_multibyte_encoding_utf16le = functions->encoding_fetcher("UTF-16LE" TSRMLS_CC);
                    103:        if (!zend_multibyte_encoding_utf16le) {
                    104:                return FAILURE;
                    105:        }
                    106:        zend_multibyte_encoding_utf8 = functions->encoding_fetcher("UTF-8" TSRMLS_CC);
                    107:        if (!zend_multibyte_encoding_utf8) {
                    108:                return FAILURE;
1.1       misho     109:        }
                    110: 
1.1.1.2   misho     111:        multibyte_functions = *functions;
1.1       misho     112: 
1.1.1.2   misho     113:        /* As zend_multibyte_set_functions() gets called after ini settings were
                    114:         * populated, we need to reinitialize script_encoding here.
                    115:         */
                    116:        {
                    117:                const char *value = zend_ini_string("zend.script_encoding", sizeof("zend.script_encoding"), 0);
                    118:                zend_multibyte_set_script_encoding_by_string(value, strlen(value) TSRMLS_CC);
1.1       misho     119:        }
1.1.1.2   misho     120:        return SUCCESS;
1.1       misho     121: }
                    122: 
1.1.1.2   misho     123: ZEND_API const zend_multibyte_functions *zend_multibyte_get_functions(TSRMLS_D)
1.1       misho     124: {
1.1.1.2   misho     125:        return multibyte_functions.provider_name ? &multibyte_functions: NULL;
1.1       misho     126: }
                    127: 
1.1.1.2   misho     128: ZEND_API const zend_encoding *zend_multibyte_fetch_encoding(const char *name TSRMLS_DC)
1.1       misho     129: {
1.1.1.2   misho     130:        return multibyte_functions.encoding_fetcher(name TSRMLS_CC);
1.1       misho     131: }
                    132: 
1.1.1.2   misho     133: ZEND_API const char *zend_multibyte_get_encoding_name(const zend_encoding *encoding)
1.1       misho     134: {
1.1.1.2   misho     135:        return multibyte_functions.encoding_name_getter(encoding);
1.1       misho     136: }
                    137: 
1.1.1.2   misho     138: ZEND_API int zend_multibyte_check_lexer_compatibility(const zend_encoding *encoding)
                    139: {
                    140:        return multibyte_functions.lexer_compatibility_checker(encoding);
                    141: }
1.1       misho     142: 
1.1.1.2   misho     143: ZEND_API const zend_encoding *zend_multibyte_encoding_detector(const unsigned char *string, size_t length, const zend_encoding **list, size_t list_size TSRMLS_DC)
1.1       misho     144: {
1.1.1.2   misho     145:        return multibyte_functions.encoding_detector(string, length, list, list_size TSRMLS_CC);
                    146: }
1.1       misho     147: 
1.1.1.2   misho     148: ZEND_API size_t zend_multibyte_encoding_converter(unsigned char **to, size_t *to_length, const unsigned char *from, size_t from_length, const zend_encoding *encoding_to, const zend_encoding *encoding_from TSRMLS_DC)
                    149: {
                    150:        return multibyte_functions.encoding_converter(to, to_length, from, from_length, encoding_to, encoding_from TSRMLS_CC);
                    151: }
1.1       misho     152: 
1.1.1.2   misho     153: ZEND_API int zend_multibyte_parse_encoding_list(const char *encoding_list, size_t encoding_list_len, const zend_encoding ***return_list, size_t *return_size, int persistent TSRMLS_DC)
                    154: {
                    155:        return multibyte_functions.encoding_list_parser(encoding_list, encoding_list_len, return_list, return_size, persistent TSRMLS_CC);
                    156: }
1.1       misho     157: 
1.1.1.2   misho     158: ZEND_API const zend_encoding *zend_multibyte_get_internal_encoding(TSRMLS_D)
                    159: {
                    160:        return multibyte_functions.internal_encoding_getter(TSRMLS_C);
                    161: }
1.1       misho     162: 
1.1.1.2   misho     163: ZEND_API const zend_encoding *zend_multibyte_get_script_encoding(TSRMLS_D)
                    164: {
                    165:        return LANG_SCNG(script_encoding);
                    166: }
1.1       misho     167: 
1.1.1.2   misho     168: ZEND_API int zend_multibyte_set_script_encoding(const zend_encoding **encoding_list, size_t encoding_list_size TSRMLS_DC)
                    169: {
                    170:        if (CG(script_encoding_list)) {
1.1.1.3   misho     171:                free(CG(script_encoding_list));
1.1       misho     172:        }
1.1.1.2   misho     173:        CG(script_encoding_list) = encoding_list;
                    174:        CG(script_encoding_list_size) = encoding_list_size;
                    175:        return SUCCESS;
                    176: }
1.1       misho     177: 
1.1.1.2   misho     178: ZEND_API int zend_multibyte_set_internal_encoding(const zend_encoding *encoding TSRMLS_DC)
                    179: {
                    180:        return multibyte_functions.internal_encoding_setter(encoding TSRMLS_CC);
1.1       misho     181: }
                    182: 
1.1.1.2   misho     183: ZEND_API int zend_multibyte_set_script_encoding_by_string(const char *new_value, size_t new_value_length TSRMLS_DC)
1.1       misho     184: {
1.1.1.2   misho     185:        const zend_encoding **list = 0;
                    186:        size_t size = 0;
1.1       misho     187: 
1.1.1.2   misho     188:        if (!new_value) {
                    189:                zend_multibyte_set_script_encoding(NULL, 0 TSRMLS_CC);
                    190:                return SUCCESS;
1.1       misho     191:        }
                    192: 
1.1.1.2   misho     193:        if (FAILURE == zend_multibyte_parse_encoding_list(new_value, new_value_length, &list, &size, 1 TSRMLS_CC)) {
                    194:                return FAILURE;
1.1       misho     195:        }
                    196: 
1.1.1.2   misho     197:        if (size == 0) {
                    198:                pefree(list, 1);
                    199:                return FAILURE;
1.1       misho     200:        }
                    201: 
1.1.1.2   misho     202:        if (FAILURE == zend_multibyte_set_script_encoding(list, size TSRMLS_CC)) {
                    203:                return FAILURE;
                    204:        }
                    205: 
                    206:        return SUCCESS;
1.1       misho     207: }
                    208: 
                    209: /*
                    210:  * Local variables:
                    211:  * tab-width: 4
                    212:  * c-basic-offset: 4
                    213:  * End:
                    214:  * vim600: sw=4 ts=4 tw=78
                    215:  * vim<600: sw=4 ts=4 tw=78
                    216:  */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>