mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
made sapi_register_treat_data() to support multibyte input encoding translation without MBSTR_ENC_TRANS and changed php_treat_data to php_default_treat_data.
This commit is contained in:
parent
82b5dc103f
commit
7527bf0c58
10 changed files with 62 additions and 35 deletions
|
@ -137,15 +137,12 @@ static unsigned char second_args_force_ref[] = { 2, BYREF_NONE, BYREF_FORCE };
|
|||
#if HAVE_MBREGEX
|
||||
static unsigned char third_argument_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE };
|
||||
#endif
|
||||
#if defined(MBSTR_ENC_TRANS)
|
||||
SAPI_POST_HANDLER_FUNC(php_mbstr_post_handler);
|
||||
|
||||
static sapi_post_entry mbstr_post_entries[] = {
|
||||
{ DEFAULT_POST_CONTENT_TYPE, sizeof(DEFAULT_POST_CONTENT_TYPE)-1, sapi_read_standard_form_data, php_mbstr_post_handler },
|
||||
{ MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, NULL, rfc1867_post_handler },
|
||||
{ NULL, 0, NULL, NULL }
|
||||
};
|
||||
#endif
|
||||
|
||||
static struct mb_overload_def mb_ovld[] = {
|
||||
{MB_OVERLOAD_MAIL, "mail", "mb_send_mail", "mb_orig_mail"},
|
||||
|
@ -646,6 +643,9 @@ PHP_INI_BEGIN()
|
|||
#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, OnUpdateInt, func_overload, zend_mbstring_globals, mbstring_globals)
|
||||
#if !defined(COMPILE_DL_MBSTRING)
|
||||
STD_PHP_INI_BOOLEAN("mbstring.encoding_translation", "0", PHP_INI_SYSTEM, OnUpdateBool, encoding_translation, zend_mbstring_globals, mbstring_globals)
|
||||
#endif /* !defined(COMPILE_DL_MBSTRING) */
|
||||
PHP_INI_END()
|
||||
|
||||
|
||||
|
@ -704,6 +704,7 @@ php_mbstring_init_globals(zend_mbstring_globals *pglobals TSRMLS_DC)
|
|||
MBSTRG(current_filter_illegal_mode) = MBFL_OUTPUTFILTER_ILLEGAL_MODE_CHAR;
|
||||
MBSTRG(current_filter_illegal_substchar) = 0x3f; /* '?' */
|
||||
MBSTRG(func_overload) = 0;
|
||||
MBSTRG(encoding_translation) = 0;
|
||||
pglobals->outconv = NULL;
|
||||
#if HAVE_MBREGEX
|
||||
MBSTRG(default_mbctype) = MBCTYPE_EUC;
|
||||
|
@ -727,10 +728,12 @@ PHP_MINIT_FUNCTION(mbstring)
|
|||
|
||||
REGISTER_INI_ENTRIES();
|
||||
|
||||
#if defined(MBSTR_ENC_TRANS)
|
||||
sapi_unregister_post_entry(mbstr_post_entries);
|
||||
sapi_register_post_entries(mbstr_post_entries);
|
||||
#endif
|
||||
|
||||
if(MBSTRG(encoding_translation)) {
|
||||
sapi_unregister_post_entry(mbstr_post_entries);
|
||||
sapi_register_post_entries(mbstr_post_entries);
|
||||
sapi_register_treat_data(mbstr_treat_data);
|
||||
}
|
||||
|
||||
REGISTER_LONG_CONSTANT("MB_OVERLOAD_MAIL", MB_OVERLOAD_MAIL, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("MB_OVERLOAD_STRING", MB_OVERLOAD_STRING, CONST_CS | CONST_PERSISTENT);
|
||||
|
@ -756,6 +759,10 @@ PHP_MSHUTDOWN_FUNCTION(mbstring)
|
|||
free(MBSTRG(detect_order_list));
|
||||
}
|
||||
|
||||
if(MBSTRG(encoding_translation)) {
|
||||
sapi_register_treat_data(php_default_treat_data);
|
||||
}
|
||||
|
||||
#if HAVE_MBREGEX
|
||||
zend_hash_destroy(&MBSTRG(ht_rc));
|
||||
#endif
|
||||
|
@ -899,9 +906,9 @@ PHP_MINFO_FUNCTION(mbstring)
|
|||
#if defined(HAVE_MBSTR_KR)
|
||||
php_info_print_table_row(2, "korean support", "enabled");
|
||||
#endif
|
||||
#if defined(MBSTR_ENC_TRANS)
|
||||
php_info_print_table_row(2, "http input encoding translation", "enabled");
|
||||
#endif
|
||||
if(MBSTRG(encoding_translation)) {
|
||||
php_info_print_table_row(2, "http input encoding translation", "enabled");
|
||||
}
|
||||
#if defined(HAVE_MBREGEX)
|
||||
php_info_print_table_row(2, "multibyte (japanese) regex support", "enabled");
|
||||
#endif
|
||||
|
@ -1227,7 +1234,6 @@ PHP_FUNCTION(mb_preferred_mime_name)
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
#if defined(MBSTR_ENC_TRANS)
|
||||
static void
|
||||
php_mbstr_encoding_handler(zval *arg, char *res, char *separator TSRMLS_DC)
|
||||
{
|
||||
|
@ -1412,7 +1418,7 @@ int mbstr_is_mb_leadbyte(const char *s TSRMLS_DC){
|
|||
}
|
||||
|
||||
/* http input processing */
|
||||
void mbstr_treat_data(int arg, char *str, zval* destArray TSRMLS_DC)
|
||||
SAPI_API SAPI_TREAT_DATA_FUNC(mbstr_treat_data)
|
||||
{
|
||||
char *res = NULL, *separator=NULL;
|
||||
const char *c_var;
|
||||
|
@ -1526,7 +1532,6 @@ void mbstr_treat_data(int arg, char *str, zval* destArray TSRMLS_DC)
|
|||
efree(res);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* {{{ proto bool mb_parse_str(string encoded_string [, array result])
|
||||
Parses GET/POST/COOKIE data and sets global variables */
|
||||
|
@ -3335,6 +3340,9 @@ PHP_FUNCTION(mb_get_info)
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
PHPAPI int mbstr_encoding_translation(TSRMLS_DC) {
|
||||
return MBSTRG(encoding_translation);
|
||||
}
|
||||
|
||||
#ifdef ZEND_MULTIBYTE
|
||||
PHPAPI int php_mbstring_set_zend_encoding(TSRMLS_D)
|
||||
|
@ -3380,13 +3388,13 @@ PHPAPI int php_mbstring_set_zend_encoding(TSRMLS_D)
|
|||
encoding_converter = NULL;
|
||||
multibyte_oddlen = php_mbstring_oddlen;
|
||||
|
||||
#if defined(MBSTR_ENC_TRANS)
|
||||
/* notify internal encoding to Zend Engine */
|
||||
name = (char*)mbfl_no_encoding2name(MBSTRG(current_internal_encoding));
|
||||
zend_multibyte_set_internal_encoding(name, strlen(name) TSRMLS_CC);
|
||||
if(MBSTRG(encoding_translation)) {
|
||||
/* notify internal encoding to Zend Engine */
|
||||
name = (char*)mbfl_no_encoding2name(MBSTRG(current_internal_encoding));
|
||||
zend_multibyte_set_internal_encoding(name, strlen(name) TSRMLS_CC);
|
||||
|
||||
encoding_converter = php_mbstring_encoding_converter;
|
||||
#endif /* defined(MBSTR_ENC_TRANS) */
|
||||
encoding_converter = php_mbstring_encoding_converter;
|
||||
}
|
||||
|
||||
zend_multibyte_set_functions(encoding_detector, encoding_converter,
|
||||
multibyte_oddlen TSRMLS_CC);
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#if HAVE_MBSTRING
|
||||
|
||||
#include "mbfilter.h"
|
||||
#include "SAPI.h"
|
||||
|
||||
#define PHP_MBSTRING_API 20020405
|
||||
|
||||
|
@ -126,6 +127,7 @@ int php_mbregex_name2mbctype(const char *pname);
|
|||
|
||||
char *mbstr_strrchr(const char *s, char c TSRMLS_DC);
|
||||
int mbstr_is_mb_leadbyte(const char *s TSRMLS_DC);
|
||||
int mbstr_encoding_translation(TSRMLS_DC) ;
|
||||
|
||||
ZEND_BEGIN_MODULE_GLOBALS(mbstring)
|
||||
int language;
|
||||
|
@ -154,6 +156,7 @@ ZEND_BEGIN_MODULE_GLOBALS(mbstring)
|
|||
int current_filter_illegal_mode;
|
||||
int current_filter_illegal_substchar;
|
||||
long func_overload;
|
||||
int encoding_translation;
|
||||
mbfl_buffer_converter *outconv;
|
||||
#if HAVE_MBREGEX
|
||||
int default_mbctype;
|
||||
|
@ -194,6 +197,9 @@ int php_mbstring_encoding_converter(char **to, int *to_length, char *from,
|
|||
int php_mbstring_oddlen(char *string, int length, const char *encoding TSRMLS_DC);
|
||||
#endif /* ZEND_MULTIBYTE */
|
||||
|
||||
SAPI_POST_HANDLER_FUNC(php_mbstr_post_handler);
|
||||
SAPI_API SAPI_TREAT_DATA_FUNC(mbstr_treat_data);
|
||||
|
||||
#else /* HAVE_MBSTRING */
|
||||
|
||||
#define mbstring_module_ptr NULL
|
||||
|
|
|
@ -3223,14 +3223,14 @@ PHP_FUNCTION(parse_str)
|
|||
old_rg = PG(register_globals);
|
||||
if(argCount == 1) {
|
||||
PG(register_globals) = 1;
|
||||
php_treat_data(PARSE_STRING, res, NULL TSRMLS_CC);
|
||||
sapi_module.treat_data(PARSE_STRING, res, NULL TSRMLS_CC);
|
||||
} else {
|
||||
PG(register_globals) = 0;
|
||||
/* Clear out the array that was passed in. */
|
||||
zval_dtor(*arrayArg);
|
||||
array_init(*arrayArg);
|
||||
|
||||
php_treat_data(PARSE_STRING, res, *arrayArg TSRMLS_CC);
|
||||
sapi_module.treat_data(PARSE_STRING, res, *arrayArg TSRMLS_CC);
|
||||
}
|
||||
PG(register_globals) = old_rg;
|
||||
}
|
||||
|
|
|
@ -763,6 +763,13 @@ SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRML
|
|||
}
|
||||
|
||||
|
||||
SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC))
|
||||
{
|
||||
sapi_module.treat_data = treat_data;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
SAPI_API int sapi_flush(TSRMLS_D)
|
||||
{
|
||||
if (sapi_module.flush) {
|
||||
|
|
|
@ -173,6 +173,7 @@ SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entry);
|
|||
SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry);
|
||||
SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry);
|
||||
SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRMLS_D));
|
||||
SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC));
|
||||
|
||||
SAPI_API int sapi_flush(TSRMLS_D);
|
||||
SAPI_API struct stat *sapi_get_stat(TSRMLS_D);
|
||||
|
@ -215,6 +216,7 @@ struct _sapi_module_struct {
|
|||
void (*unblock_interruptions)(void);
|
||||
|
||||
void (*default_post_reader)(TSRMLS_D);
|
||||
void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC);
|
||||
char *executable_location;
|
||||
};
|
||||
|
||||
|
@ -243,8 +245,11 @@ struct _sapi_post_entry {
|
|||
#define SAPI_POST_READER_FUNC(post_reader) void post_reader(TSRMLS_D)
|
||||
#define SAPI_POST_HANDLER_FUNC(post_handler) void post_handler(char *content_type_dup, void *arg TSRMLS_DC)
|
||||
|
||||
#define SAPI_TREAT_DATA_FUNC(treat_data) void treat_data(int arg, char *str, zval* destArray TSRMLS_DC)
|
||||
|
||||
SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data);
|
||||
SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader);
|
||||
SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data);
|
||||
|
||||
#define STANDARD_SAPI_MODULE_PROPERTIES NULL, NULL
|
||||
|
||||
|
|
|
@ -1152,21 +1152,21 @@ static int php_hash_environment(TSRMLS_D)
|
|||
case 'p':
|
||||
case 'P':
|
||||
if (!_gpc_flags[0] && !SG(headers_sent) && SG(request_info).request_method && !strcasecmp(SG(request_info).request_method, "POST")) {
|
||||
php_treat_data(PARSE_POST, NULL, NULL TSRMLS_CC); /* POST Data */
|
||||
sapi_module.treat_data(PARSE_POST, NULL, NULL TSRMLS_CC); /* POST Data */
|
||||
_gpc_flags[0]=1;
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
case 'C':
|
||||
if (!_gpc_flags[1]) {
|
||||
php_treat_data(PARSE_COOKIE, NULL, NULL TSRMLS_CC); /* Cookie Data */
|
||||
sapi_module.treat_data(PARSE_COOKIE, NULL, NULL TSRMLS_CC); /* Cookie Data */
|
||||
_gpc_flags[1]=1;
|
||||
}
|
||||
break;
|
||||
case 'g':
|
||||
case 'G':
|
||||
if (!_gpc_flags[2]) {
|
||||
php_treat_data(PARSE_GET, NULL, NULL TSRMLS_CC); /* GET Data */
|
||||
sapi_module.treat_data(PARSE_GET, NULL, NULL TSRMLS_CC); /* GET Data */
|
||||
_gpc_flags[2]=1;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -51,6 +51,7 @@ int php_startup_sapi_content_types(void)
|
|||
{
|
||||
sapi_register_post_entries(php_post_entries);
|
||||
sapi_register_default_post_reader(php_default_post_reader);
|
||||
sapi_register_treat_data(php_default_treat_data);
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
|
|
@ -53,8 +53,4 @@ extern void php_call_shutdown_functions(void);
|
|||
extern int php_init_environ(void);
|
||||
extern int php_shutdown_environ(void);
|
||||
|
||||
#if defined(MBSTR_ENC_TRANS)
|
||||
#define php_treat_data mbstr_treat_data
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -216,8 +216,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void php_treat_data(int arg, char *str, zval* destArray TSRMLS_DC)
|
||||
SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data)
|
||||
{
|
||||
char *res = NULL, *var, *val, *separator=NULL;
|
||||
const char *c_var;
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "php_variables.h"
|
||||
#include "rfc1867.h"
|
||||
|
||||
#if HAVE_MBSTRING && MBSTR_ENC_TRANS && !defined(COMPILE_DL_MBSTRING)
|
||||
#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
|
||||
#include "ext/mbstring/mbstring.h"
|
||||
#endif
|
||||
|
||||
|
@ -459,8 +459,9 @@ static char *substring_conf(char *start, int len, char quote TSRMLS_DC)
|
|||
*resp++ = start[++i];
|
||||
} else {
|
||||
*resp++ = start[i];
|
||||
#if HAVE_MBSTRING && MBSTR_ENC_TRANS && !defined(COMPILE_DL_MBSTRING)
|
||||
if (mbstr_is_mb_leadbyte(start+i TSRMLS_CC)) {
|
||||
#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
|
||||
if (mbstr_encoding_translation(TSRMLS_CC) &&
|
||||
mbstr_is_mb_leadbyte(start+i TSRMLS_CC)) {
|
||||
*resp++ = start[++i];
|
||||
}
|
||||
#endif
|
||||
|
@ -840,8 +841,12 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler)
|
|||
sprintf(lbuf, "%s_name", param);
|
||||
}
|
||||
|
||||
#if HAVE_MBSTRING && MBSTR_ENC_TRANS && !defined(COMPILE_DL_MBSTRING)
|
||||
s = mbstr_strrchr(filename, '\\' TSRMLS_CC);
|
||||
#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
|
||||
if (mbstr_encoding_translation(TSRMLS_CC)) {
|
||||
s = mbstr_strrchr(filename, '\\' TSRMLS_CC);
|
||||
} else {
|
||||
s = strrchr(filename, '\\');
|
||||
}
|
||||
#else
|
||||
s = strrchr(filename, '\\');
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue