From 78f795af8085557a5dcaefcddf5fac2d88c5577b Mon Sep 17 00:00:00 2001 From: Rui Hirokawa Date: Sun, 26 Oct 2003 07:47:42 +0000 Subject: [PATCH] revert my previous patch. --- ext/mbstring/mbstring.c | 65 ++++++++++------------------- ext/mbstring/mbstring.h | 4 +- main/rfc1867.c | 91 +++++------------------------------------ 3 files changed, 34 insertions(+), 126 deletions(-) diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 5127780cf5..a5ad99bcec 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -356,12 +356,6 @@ static mbfl_allocators _php_mb_allocators = { /* }}} */ -/* {{{ static int php_mb_parse_encoding_list() - * 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 int php_mb_parse_encoding_list() * Return 0 if input contains any illegal encoding, otherwise 1. * Even if any illegal encoding is detected the result may contain a list @@ -3737,10 +3731,9 @@ MBSTRING_API size_t php_mb_gpc_mbchar_bytes(const char *s TSRMLS_DC) /* }}} */ /* {{{ MBSTRING_API int php_mb_gpc_encoding_converter() */ -MBSTRING_API int php_mb_gpc_encoding_converter(char **str, int *len, int num, const char *encoding_to, const char *encoding_from +MBSTRING_API int php_mb_gpc_encoding_converter(char **str, int *len, const char *encoding_to, const char *encoding_from TSRMLS_DC) { - int i; mbfl_string string, result, *ret; enum mbfl_no_encoding from_encoding, to_encoding; mbfl_buffer_converter *convd; @@ -3774,38 +3767,35 @@ MBSTRING_API int php_mb_gpc_encoding_converter(char **str, int *len, int num, co string.no_encoding = from_encoding; string.no_language = MBSTRG(current_language); - for (i=0; ival; - len[i] = ret->len; - } - mbfl_buffer_converter_delete(convd); + /* do it */ + ret = mbfl_buffer_converter_feed_result(convd, &string, &result); + if (ret != NULL) { + efree(*str); + *str = ret->val; + *len = ret->len; } + mbfl_buffer_converter_delete(convd); return ret ? 0 : -1; } /* {{{ MBSTRING_API int php_mb_gpc_encoding_detector() */ -MBSTRING_API int php_mb_gpc_encoding_detector(char **arg_string, int *arg_length, int num, char *arg_list TSRMLS_DC) +MBSTRING_API int php_mb_gpc_encoding_detector(const char *arg_string, int arg_length, char *arg_list TSRMLS_DC) { mbfl_string string; enum mbfl_no_encoding *elist; enum mbfl_no_encoding encoding; - mbfl_encoding_detector *identd = NULL; int size, *list; @@ -3849,22 +3839,9 @@ MBSTRING_API int php_mb_gpc_encoding_detector(char **arg_string, int *arg_length mbfl_string_init(&string); string.no_language = MBSTRG(current_language); - - identd = mbfl_encoding_detector_new(elist, size); - - if (identd) { - int n = 0; - while (n < num) { - string.val = (unsigned char*)arg_string[n]; - string.len = arg_length[n]; - if (mbfl_encoding_detector_feed(identd, &string)) { - break; - } - n++; - } - encoding = mbfl_encoding_detector_judge(identd); - mbfl_encoding_detector_delete(identd); - } + string.val = (char*)arg_string; + string.len = arg_length; + encoding = mbfl_identify_encoding_no(&string, elist, size TSRMLS_CC); if (encoding != mbfl_no_encoding_invalid) { MBSTRG(http_input_identify) = encoding; diff --git a/ext/mbstring/mbstring.h b/ext/mbstring/mbstring.h index a167c3ab3a..3286d06760 100644 --- a/ext/mbstring/mbstring.h +++ b/ext/mbstring/mbstring.h @@ -142,9 +142,9 @@ MBSTRING_API int php_mb_encoding_detector_ex(const char *arg_string, int arg_len MBSTRING_API int php_mb_encoding_converter_ex(char **str, int *len, const char *encoding_to, const char *encoding_from TSRMLS_DC); -MBSTRING_API int php_mb_gpc_encoding_converter(char **str, int *len, int num, const char *encoding_to, const char *encoding_from TSRMLS_DC); +MBSTRING_API int php_mb_gpc_encoding_converter(char **str, int *len, const char *encoding_to, const char *encoding_from TSRMLS_DC); -MBSTRING_API int php_mb_gpc_encoding_detector(char **arg_string, int *arg_length, int num, char *arg_list TSRMLS_DC); +MBSTRING_API int php_mb_gpc_encoding_detector(const char *arg_string, int arg_length, char *arg_list TSRMLS_DC); ZEND_BEGIN_MODULE_GLOBALS(mbstring) enum mbfl_no_language language; diff --git a/main/rfc1867.c b/main/rfc1867.c index 2a75ad8e70..0603638353 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -32,66 +32,11 @@ #include "php_variables.h" #include "rfc1867.h" -#undef DEBUG_FILE_UPLOAD - - #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING) #include "ext/mbstring/mbstring.h" +#endif -static void safe_php_register_variable(char *var, char *strval, zval *track_vars_array, zend_bool override_protection TSRMLS_DC); - -#define SAFE_RETURN { \ - php_mb_flush_gpc_variables(num_vars, val_list, len_list, array_ptr TSRMLS_CC); \ - if (lbuf) efree(lbuf); \ - if (abuf) efree(abuf); \ - if (array_index) efree(array_index); \ - zend_hash_destroy(&PG(rfc1867_protected_variables)); \ - zend_llist_destroy(&header); \ - if (mbuff->boundary_next) efree(mbuff->boundary_next); \ - if (mbuff->boundary) efree(mbuff->boundary); \ - if (mbuff->buffer) efree(mbuff->buffer); \ - if (mbuff) efree(mbuff); \ - return; } - -void php_mb_flush_gpc_variables(int num_vars, char **val_list, int *len_list, zval *array_ptr TSRMLS_DC) -{ - int i; - if (php_mb_encoding_translation(TSRMLS_C)) { - if (num_vars > 0 && - php_mb_gpc_encoding_detector(val_list, len_list, num_vars, NULL TSRMLS_CC) == SUCCESS) { - php_mb_gpc_encoding_converter(val_list, len_list, num_vars, NULL, NULL TSRMLS_CC); - } - for (i=0; i=*num_vars_max){ - (*num_vars_max) += 16; - *pval_list = (char **)erealloc(val_list, *num_vars_max*sizeof(char *)); - *plen_list = (int *)erealloc(len_list, *num_vars_max*sizeof(int)); - val_list=*pval_list; - len_list=*plen_list; - } - val_list[*num_vars] = (char *)estrdup(param); - len_list[*num_vars] = strlen(param); - (*num_vars)++; - val_list[*num_vars] = (char *)estrdup(value); - len_list[*num_vars] = strlen(value); - (*num_vars)++; -} - -#else +#undef DEBUG_FILE_UPLOAD #define SAFE_RETURN { \ if (lbuf) efree(lbuf); \ @@ -105,7 +50,6 @@ void php_mb_gpc_stack_variable(char *param, char *value, char ***pval_list, int if (mbuff) efree(mbuff); \ return; } -#endif /* The longest property name we use in an uploaded file array */ #define MAX_SIZE_OF_INDEX sizeof("[tmp_name]") @@ -602,8 +546,7 @@ static char *php_ap_getword_conf(char **line TSRMLS_DC) #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING) if (php_mb_encoding_translation(TSRMLS_C)) { - int len=strlen(str); - php_mb_gpc_encoding_detector(&str, &len, 1, NULL TSRMLS_CC); + php_mb_gpc_encoding_detector(str, strlen(str), NULL TSRMLS_CC); } #endif @@ -757,8 +700,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) FILE *fp; zend_llist header; #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING) - int str_len = 0, num_vars = 0, num_vars_max = 2*10+1, *len_list = NULL; - char **val_list = NULL; + int str_len=0; #endif if (SG(request_info).content_length > SG(post_max_size)) { @@ -809,12 +751,6 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) INIT_PZVAL(http_post_files); PG(http_globals)[TRACK_VARS_FILES] = http_post_files; -#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING) - if (php_mb_encoding_translation(TSRMLS_C)) { - val_list = (char **)ecalloc(num_vars_max, sizeof(char *)); - len_list = (int *)ecalloc(num_vars_max, sizeof(int)); - } -#endif zend_llist_init(&header, sizeof(mime_header_entry), (llist_dtor_func_t) php_free_hdr_entry, 0); while (!multipart_buffer_eof(mbuff TSRMLS_CC)) @@ -876,14 +812,13 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING) if (php_mb_encoding_translation(TSRMLS_C)) { - php_mb_gpc_stack_variable(param, value, &val_list, &len_list, - &num_vars, &num_vars_max TSRMLS_CC); - } else { - safe_php_register_variable(param, value, array_ptr, 0 TSRMLS_CC); + if (php_mb_gpc_encoding_detector(value, strlen(value), NULL TSRMLS_CC) == SUCCESS) { + str_len = strlen(value); + php_mb_gpc_encoding_converter(&value , &str_len, NULL, NULL TSRMLS_CC); + } } -#else - safe_php_register_variable(param, value, array_ptr, 0 TSRMLS_CC); #endif + safe_php_register_variable(param, value, array_ptr, 0 TSRMLS_CC); if (!strcasecmp(param, "MAX_FILE_SIZE")) { max_file_size = atol(value); } @@ -1009,15 +944,11 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING) if (php_mb_encoding_translation(TSRMLS_C)) { - val_list[num_vars] = filename; - len_list[num_vars] = strlen(filename); - num_vars++; - if(php_mb_gpc_encoding_detector(val_list, len_list, num_vars, NULL TSRMLS_CC) == SUCCESS) { + if(php_mb_gpc_encoding_detector(filename, strlen(filename), NULL TSRMLS_CC) == SUCCESS) { str_len = strlen(filename); - php_mb_gpc_encoding_converter(&filename, &str_len, 1, NULL, NULL TSRMLS_CC); + php_mb_gpc_encoding_converter(&filename, &str_len, NULL, NULL TSRMLS_CC); } s = php_mb_strrchr(filename, '\\' TSRMLS_CC); - num_vars--; } else { s = strrchr(filename, '\\'); } -- 2.40.0