/* }}} */
-/* {{{ 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
/* }}} */
/* {{{ 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;
string.no_encoding = from_encoding;
string.no_language = MBSTRG(current_language);
- for (i=0; i<num; i++) {
- string.val = (char*)str[i];
- string.len = len[i];
+ string.val = (char*)(*str);
+ string.len = *len;
- /* initialize converter */
- convd = mbfl_buffer_converter_new(from_encoding, to_encoding, string.len);
- if (convd == NULL) {
- return -1;
- }
- mbfl_buffer_converter_illegal_mode(convd, MBSTRG(current_filter_illegal_mode));
- mbfl_buffer_converter_illegal_substchar(convd, MBSTRG(current_filter_illegal_substchar));
+ /* initialize converter */
+ convd = mbfl_buffer_converter_new(from_encoding, to_encoding, string.len);
+ if (convd == NULL) {
+ return -1;
+ }
+ mbfl_buffer_converter_illegal_mode(convd, MBSTRG(current_filter_illegal_mode));
+ mbfl_buffer_converter_illegal_substchar(convd, MBSTRG(current_filter_illegal_substchar));
- /* do it */
- ret = mbfl_buffer_converter_feed_result(convd, &string, &result);
- if (ret != NULL) {
- efree(str[i]);
- str[i] = ret->val;
- 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;
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;
#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; i+=2){
- safe_php_register_variable(val_list[i], val_list[i+1], array_ptr, 0 TSRMLS_CC);
- efree(val_list[i]);
- efree(val_list[i+1]);
- }
- efree(val_list);
- efree(len_list);
- }
-}
-
-void php_mb_gpc_stack_variable(char *param, char *value, char ***pval_list, int **plen_list, int *num_vars, int *num_vars_max TSRMLS_DC)
-{
- char **val_list=*pval_list;
- int *len_list=*plen_list;
-
- if (*num_vars>=*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); \
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]")
#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
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)) {
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))
#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);
}
#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, '\\');
}