📄 mbstring.c
字号:
*entry++ = *src++; l--; n++; } } } else { no_encoding = mbfl_name2no_encoding(p1); if (no_encoding != mbfl_no_encoding_invalid) { *entry++ = no_encoding; n++; } else { ret = 0; } } p1 = p2 + 1; } while (n < size && p2 != NULL); if (n > 0) { if (return_list) { *return_list = list; } else { pefree(list, persistent); } } else { pefree(list, persistent); if (return_list) { *return_list = NULL; } ret = 0; } if (return_size) { *return_size = n; } } else { if (return_list) { *return_list = NULL; } if (return_size) { *return_size = 0; } ret = 0; } efree(tmpstr); } return ret;}/* }}} *//* {{{ MBSTRING_API php_mb_check_encoding_list */MBSTRING_API int php_mb_check_encoding_list(const char *encoding_list TSRMLS_DC) { return php_mb_parse_encoding_list(encoding_list, strlen(encoding_list), NULL, NULL, 0 TSRMLS_CC); }/* }}} *//* {{{ static int php_mb_parse_encoding_array() * Return 0 if input contains any illegal encoding, otherwise 1. * Even if any illegal encoding is detected the result may contain a list * of parsed encodings. */static intphp_mb_parse_encoding_array(zval *array, enum mbfl_no_encoding **return_list, int *return_size, int persistent TSRMLS_DC){ zval **hash_entry; HashTable *target_hash; int i, n, l, size, bauto,ret = 1; enum mbfl_no_encoding no_encoding; enum mbfl_no_encoding *src, *list, *entry; list = NULL; if (Z_TYPE_P(array) == IS_ARRAY) { enum mbfl_no_encoding *identify_list; int identify_list_size; identify_list = MBSTRG(default_detect_order_list); identify_list_size = MBSTRG(default_detect_order_list_size); target_hash = Z_ARRVAL_P(array); zend_hash_internal_pointer_reset(target_hash); i = zend_hash_num_elements(target_hash); size = i + identify_list_size; list = (enum mbfl_no_encoding *)pecalloc(size, sizeof(int), persistent); if (list != NULL) { entry = list; bauto = 0; n = 0; while (i > 0) { if (zend_hash_get_current_data(target_hash, (void **) &hash_entry) == FAILURE) { break; } convert_to_string_ex(hash_entry); if (strcasecmp(Z_STRVAL_PP(hash_entry), "auto") == 0) { if (!bauto) { bauto = 1; l = identify_list_size; src = identify_list; while (l > 0) { *entry++ = *src++; l--; n++; } } } else { no_encoding = mbfl_name2no_encoding(Z_STRVAL_PP(hash_entry)); if (no_encoding != mbfl_no_encoding_invalid) { *entry++ = no_encoding; n++; } else { ret = 0; } } zend_hash_move_forward(target_hash); i--; } if (n > 0) { if (return_list) { *return_list = list; } else { pefree(list, persistent); } } else { pefree(list, persistent); if (return_list) { *return_list = NULL; } ret = 0; } if (return_size) { *return_size = n; } } else { if (return_list) { *return_list = NULL; } if (return_size) { *return_size = 0; } ret = 0; } } return ret;}/* }}} *//* {{{ php_mb_nls_get_default_detect_order_list */static int php_mb_nls_get_default_detect_order_list(enum mbfl_no_language lang, enum mbfl_no_encoding **plist, int* plist_size){ size_t i; *plist = (enum mbfl_no_encoding *) php_mb_default_identify_list_neut; *plist_size = sizeof(php_mb_default_identify_list_neut) / sizeof(php_mb_default_identify_list_neut[0]); for (i = 0; i < sizeof(php_mb_default_identify_list) / sizeof(php_mb_default_identify_list[0]); i++) { if (php_mb_default_identify_list[i].lang == lang) { *plist = php_mb_default_identify_list[i].list; *plist_size = php_mb_default_identify_list[i].list_size; return 1; } } return 0;}/* }}} */#if HAVE_MBREGEX/* {{{ static void php_mbregex_free_cache() */static voidphp_mbregex_free_cache(mb_regex_t *pre) { mbre_free_pattern(pre);}/* }}} */#endif/* {{{ php.ini directive handler */static PHP_INI_MH(OnUpdate_mbstring_language){ enum mbfl_no_language no_language; no_language = mbfl_name2no_language(new_value); if (no_language == mbfl_no_language_invalid) { return FAILURE; } MBSTRG(language) = no_language; php_mb_nls_get_default_detect_order_list(no_language, &MBSTRG(default_detect_order_list), &MBSTRG(default_detect_order_list_size)); return SUCCESS;}/* }}} *//* {{{ static PHP_INI_MH(OnUpdate_mbstring_detect_order) */static PHP_INI_MH(OnUpdate_mbstring_detect_order){ enum mbfl_no_encoding *list; int size; if (php_mb_parse_encoding_list(new_value, new_value_length, &list, &size, 1 TSRMLS_CC)) { if (MBSTRG(detect_order_list) != NULL) { free(MBSTRG(detect_order_list)); } MBSTRG(detect_order_list) = list; MBSTRG(detect_order_list_size) = size; } else { return FAILURE; } return SUCCESS;}/* }}} *//* {{{ static PHP_INI_MH(OnUpdate_mbstring_http_input) */static PHP_INI_MH(OnUpdate_mbstring_http_input){ enum mbfl_no_encoding *list; int size; if (php_mb_parse_encoding_list(new_value, new_value_length, &list, &size, 1 TSRMLS_CC)) { if (MBSTRG(http_input_list) != NULL) { free(MBSTRG(http_input_list)); } MBSTRG(http_input_list) = list; MBSTRG(http_input_list_size) = size; } else { return FAILURE; } return SUCCESS;}/* }}} *//* {{{ static PHP_INI_MH(OnUpdate_mbstring_http_output) */static PHP_INI_MH(OnUpdate_mbstring_http_output){ enum mbfl_no_encoding no_encoding; no_encoding = mbfl_name2no_encoding(new_value); if (no_encoding != mbfl_no_encoding_invalid) { MBSTRG(http_output_encoding) = no_encoding; MBSTRG(current_http_output_encoding) = no_encoding; } else { if (new_value != NULL && new_value_length > 0) { return FAILURE; } } return SUCCESS;}/* }}} *//* {{{ static PHP_INI_MH(OnUpdate_mbstring_internal_encoding) */static PHP_INI_MH(OnUpdate_mbstring_internal_encoding){ enum mbfl_no_encoding no_encoding;#if HAVE_MBREGEX const struct def_mbctype_tbl *p = NULL;#endif if (new_value == NULL) { return SUCCESS; } no_encoding = mbfl_name2no_encoding(new_value); if (no_encoding != mbfl_no_encoding_invalid) { MBSTRG(internal_encoding) = no_encoding; MBSTRG(current_internal_encoding) = no_encoding;#if HAVE_MBREGEX p=&(mbctype_tbl[0]); while (p->regex_encoding >= 0){ if (p->mbfl_encoding == MBSTRG(internal_encoding)){ MBSTRG(default_mbctype) = p->regex_encoding; MBSTRG(current_mbctype) = p->regex_encoding; break; } p++; }#endif#ifdef ZEND_MULTIBYTE zend_multibyte_set_internal_encoding(new_value, new_value_length TSRMLS_CC);#endif /* ZEND_MULTIBYTE */ } else { if (new_value != NULL && new_value_length > 0) { return FAILURE; } } return SUCCESS;}/* }}} */#ifdef ZEND_MULTIBYTE/* {{{ static PHP_INI_MH(OnUpdate_mbstring_script_encoding) */static PHP_INI_MH(OnUpdate_mbstring_script_encoding){ int *list, size; if (php_mb_parse_encoding_list(new_value, new_value_length, &list, &size, 1 TSRMLS_CC)) { if (MBSTRG(script_encoding_list) != NULL) { free(MBSTRG(script_encoding_list)); } MBSTRG(script_encoding_list) = list; MBSTRG(script_encoding_list_size) = size; } else { return FAILURE; } return SUCCESS;}/* }}} */#endif /* ZEND_MULTIBYTE *//* {{{ static PHP_INI_MH(OnUpdate_mbstring_substitute_character) */static PHP_INI_MH(OnUpdate_mbstring_substitute_character){ int c; char *endptr = NULL; if (new_value != NULL) { if (strcasecmp("none", new_value) == 0) { MBSTRG(filter_illegal_mode) = MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE; } else if (strcasecmp("long", new_value) == 0) { MBSTRG(filter_illegal_mode) = MBFL_OUTPUTFILTER_ILLEGAL_MODE_LONG; } else { MBSTRG(filter_illegal_mode) = MBFL_OUTPUTFILTER_ILLEGAL_MODE_CHAR; if (new_value_length >0) { c = strtol(new_value, &endptr, 0); if (*endptr == '\0') { MBSTRG(filter_illegal_substchar) = c; } } } } return SUCCESS;}/* }}} *//* {{{ static PHP_INI_MH(OnUpdate_mbstring_encoding_translation) */static PHP_INI_MH(OnUpdate_mbstring_encoding_translation){ if (new_value == NULL) { return FAILURE; } OnUpdateBool(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); if (MBSTRG(encoding_translation)){ sapi_unregister_post_entry(php_post_entries); sapi_register_post_entries(mbstr_post_entries); sapi_register_treat_data(mbstr_treat_data); } else { sapi_unregister_post_entry(mbstr_post_entries); sapi_register_post_entries(php_post_entries); sapi_register_treat_data(php_default_treat_data); } return SUCCESS;}/* }}} *//* {{{ php.ini directive registration */PHP_INI_BEGIN() PHP_INI_ENTRY("mbstring.language", "neutral", PHP_INI_SYSTEM | PHP_INI_PERDIR, OnUpdate_mbstring_language) PHP_INI_ENTRY("mbstring.detect_order", NULL, PHP_INI_ALL, OnUpdate_mbstring_detect_order) PHP_INI_ENTRY("mbstring.http_input", "pass", PHP_INI_ALL, OnUpdate_mbstring_http_input) PHP_INI_ENTRY("mbstring.http_output", "pass", PHP_INI_ALL, OnUpdate_mbstring_http_output) PHP_INI_ENTRY("mbstring.internal_encoding", NULL, PHP_INI_ALL, OnUpdate_mbstring_internal_encoding)#ifdef ZEND_MULTIBYTE PHP_INI_ENTRY("mbstring.script_encoding", NULL, PHP_INI_ALL, OnUpdate_mbstring_script_encoding)#endif /* ZEND_MULTIBYTE */ PHP_INI_ENTRY("mbstring.substitute_character", NULL, PHP_INI_ALL, OnUpdate_mbstring_substitute_character) STD_PHP_INI_ENTRY("mbstring.func_overload", "0", PHP_INI_SYSTEM | PHP_INI_PERDIR, OnUpdateInt, func_overload, zend_mbstring_globals, mbstring_globals) STD_PHP_INI_BOOLEAN("mbstring.encoding_translation", "0", PHP_INI_SYSTEM | PHP_INI_PERDIR, OnUpdate_mbstring_encoding_translation, encoding_translation, zend_mbstring_globals, mbstring_globals) PHP_INI_END()/* }}} *//* {{{ module global initialize handler */static voidphp_mb_init_globals(zend_mbstring_globals *pglobals TSRMLS_DC){ MBSTRG(language) = mbfl_no_language_uni; MBSTRG(current_language) = MBSTRG(language); MBSTRG(internal_encoding) = mbfl_no_encoding_invalid; MBSTRG(current_internal_encoding) = MBSTRG(internal_encoding);#ifdef ZEND_MULTIBYTE MBSTRG(script_encoding_list) = NULL; MBSTRG(script_encoding_list_size) = 0;#endif /* ZEND_MULTIBYTE */ MBSTRG(http_output_encoding) = mbfl_no_encoding_pass; MBSTRG(current_http_output_encoding) = mbfl_no_encoding_pass; MBSTRG(http_input_identify) = mbfl_no_encoding_invalid; MBSTRG(http_input_identify_get) = mbfl_no_encoding_invalid; MBSTRG(http_input_identify_post) = mbfl_no_encoding_invalid; MBSTRG(http_input_identify_cookie) = mbfl_no_encoding_invalid; MBSTRG(http_input_identify_string) = mbfl_no_encoding_invalid; MBSTRG(http_input_list) = NULL; MBSTRG(http_input_list_size) = 0; MBSTRG(detect_order_list) = NULL; MBSTRG(detect_order_list_size) = 0; MBSTRG(current_detect_order_list) = NULL; MBSTRG(current_detect_order_list_size) = 0; MBSTRG(default_detect_order_list) = (enum mbfl_no_encoding *) php_mb_default_identify_list_neut; MBSTRG(default_detect_order_list_size) = sizeof(php_mb_default_identify_list_neut) / sizeof(php_mb_default_identify_list_neut[0]); MBSTRG(filter_illegal_mode) = MBFL_OUTPUTFILTER_ILLEGAL_MODE_CHAR; MBSTRG(filter_illegal_substchar) = 0x3f; /* '?' */ MBSTRG(current_filter_illegal_mode) = MBFL_OUTPUTFILTER_ILLEGAL_MODE_CHAR; MBSTRG(current_filter_illegal_substchar) = 0x3f; /* '?' */ MBSTRG(illegalchars) = 0; MBSTRG(func_overload) = 0; MBSTRG(encoding_translation) = 0; pglobals->outconv = NULL;#if HAVE_MBREGEX MBSTRG(default_mbctype) = MBCTYPE_EUC; MBSTRG(current_mbctype) = MBCTYPE_EUC; zend_hash_init(&(MBSTRG(ht_rc)), 0, NULL, (void (*)(void *)) php_mbregex_free_cache, 1); MBSTRG(search_str) = (zval**)0; MBSTRG(search_str_val) = (zval*)0; MBSTRG(search_re) = (mb_regex_t*)0; MBSTRG(search_pos) = 0; MBSTRG(search_regs) = (struct mbre_registers*)0;#endif}/* }}} *//* {{{ static void mbstring_globals_dtor() */static voidmbstring_globals_dtor(zend_mbstring_globals *pglobals TSRMLS_DC){#if HAVE_MBREGEX zend_hash_destroy(&MBSTRG(ht_rc));#endif}/* }}} *//* {{{ PHP_MINIT_FUNCTION(mbstring) */PHP_MINIT_FUNCTION(mbstring){ __mbfl_allocators = &_php_mb_allocators;#ifdef ZTS ts_allocate_id(&mbstring_globals_id, sizeof(zend_mbstring_globals), (ts_allocate_ctor) php_mb_init_globals, (ts_allocate_dtor) mbstring_globals_dtor);#else php_mb_init_globals(&mbstring_globals TSRMLS_CC);#endif REGISTER_INI_ENTRIES();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -