From 324b3f960f0c1aec3a6ae25ada9f152c0678a8e9 Mon Sep 17 00:00:00 2001 From: Rui Hirokawa Date: Tue, 21 Mar 2006 02:49:09 +0000 Subject: [PATCH] MFH. --- ext/mbstring/libmbfl/mbfl/mbfilter.c | 14 ++++++++++++++ ext/mbstring/libmbfl/mbfl/mbfilter.h | 1 + ext/mbstring/libmbfl/mbfl/mbfl_convert.c | 4 +++- ext/mbstring/libmbfl/mbfl/mbfl_convert.h | 1 + ext/mbstring/mbstring.c | 13 +++++++++++++ ext/mbstring/mbstring.h | 1 + 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter.c b/ext/mbstring/libmbfl/mbfl/mbfilter.c index ec3409d8ea..9f16331874 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfilter.c +++ b/ext/mbstring/libmbfl/mbfl/mbfilter.c @@ -331,6 +331,20 @@ mbfl_buffer_converter_feed_result(mbfl_buffer_converter *convd, mbfl_string *str return mbfl_memory_device_result(&convd->device, result); } +int mbfl_buffer_illegalchars(mbfl_buffer_converter *convd) +{ + int num_illegalchars = 0; + + if (convd->filter1 != NULL) { + num_illegalchars += convd->filter1->num_illegalchar; + } + + if (convd->filter2 != NULL) { + num_illegalchars += convd->filter2->num_illegalchar; + } + + return (num_illegalchars); +} /* * encoding detector diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter.h b/ext/mbstring/libmbfl/mbfl/mbfilter.h index 702079ac45..f958e936ab 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfilter.h +++ b/ext/mbstring/libmbfl/mbfl/mbfilter.h @@ -129,6 +129,7 @@ MBFLAPI extern int mbfl_buffer_converter_flush(mbfl_buffer_converter *convd); MBFLAPI extern mbfl_string * mbfl_buffer_converter_getbuffer(mbfl_buffer_converter *convd, mbfl_string *result); MBFLAPI extern mbfl_string * mbfl_buffer_converter_result(mbfl_buffer_converter *convd, mbfl_string *result); MBFLAPI extern mbfl_string * mbfl_buffer_converter_feed_result(mbfl_buffer_converter *convd, mbfl_string *string, mbfl_string *result); +MBFLAPI extern int mbfl_buffer_illegalchars(mbfl_buffer_converter *convd); /* * encoding detector diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_convert.c b/ext/mbstring/libmbfl/mbfl/mbfl_convert.c index 981bba6af9..78a995cd25 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfl_convert.c +++ b/ext/mbstring/libmbfl/mbfl/mbfl_convert.c @@ -250,6 +250,7 @@ mbfl_convert_filter_new( filter->data = data; filter->illegal_mode = MBFL_OUTPUTFILTER_ILLEGAL_MODE_CHAR; filter->illegal_substchar = 0x3f; /* '?' */ + filter->num_illegalchar = 0; /* setup the function table */ mbfl_convert_filter_reset_vtbl(filter); @@ -317,6 +318,7 @@ mbfl_convert_filter_copy( dist->to = src->to; dist->illegal_mode = src->illegal_mode; dist->illegal_substchar = src->illegal_substchar; + dist->num_illegalchar = src->num_illegalchar; } int mbfl_convert_filter_devcat(mbfl_convert_filter *filter, mbfl_memory_device *src) @@ -432,7 +434,7 @@ mbfl_filt_conv_illegal_output(int c, mbfl_convert_filter *filter) break; } filter->illegal_mode = mode_backup; - + filter->num_illegalchar++; return ret; } diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_convert.h b/ext/mbstring/libmbfl/mbfl/mbfl_convert.h index afec8f0627..bf8b3bd630 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfl_convert.h +++ b/ext/mbstring/libmbfl/mbfl/mbfl_convert.h @@ -51,6 +51,7 @@ struct _mbfl_convert_filter { const mbfl_encoding *to; int illegal_mode; int illegal_substchar; + int num_illegalchar; void *opaque; }; diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 904dd02764..f02ce1c76e 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -854,6 +854,7 @@ php_mb_init_globals(zend_mbstring_globals *pglobals TSRMLS_DC) 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; @@ -1011,6 +1012,7 @@ PHP_RINIT_FUNCTION(mbstring) MBSTRG(current_http_output_encoding) = MBSTRG(http_output_encoding); MBSTRG(current_filter_illegal_mode) = MBSTRG(filter_illegal_mode); MBSTRG(current_filter_illegal_substchar) = MBSTRG(filter_illegal_substchar); + MBSTRG(illegalchars) = 0; n = 0; if (MBSTRG(detect_order_list)) { @@ -1078,6 +1080,7 @@ PHP_RSHUTDOWN_FUNCTION(mbstring) MBSTRG(current_detect_order_list_size) = 0; } if (MBSTRG(outconv) != NULL) { + MBSTRG(illegalchars) += mbfl_buffer_illegalchars(MBSTRG(outconv)); mbfl_buffer_converter_delete(MBSTRG(outconv)); MBSTRG(outconv) = NULL; } @@ -1627,6 +1630,7 @@ php_mbstr_encoding_handler(const php_mb_encoding_handler_info_t *info, zval *arg } if (convd != NULL) { + MBSTRG(illegalchars) += mbfl_buffer_illegalchars(convd); mbfl_buffer_converter_delete(convd); } if (val_list != NULL) { @@ -1978,6 +1982,7 @@ PHP_FUNCTION(mb_parse_str) PG(register_globals) = old_rg; if (convd != NULL) { + MBSTRG(illegalchars) += mbfl_buffer_illegalchars(convd); mbfl_buffer_converter_delete(convd); } efree((void *)str_list); @@ -2015,6 +2020,7 @@ PHP_FUNCTION(mb_output_handler) if ((arg_status & PHP_OUTPUT_HANDLER_START) != 0) { /* delete the converter just in case. */ if (MBSTRG(outconv)) { + MBSTRG(illegalchars) += mbfl_buffer_illegalchars(MBSTRG(outconv)); mbfl_buffer_converter_delete(MBSTRG(outconv)); MBSTRG(outconv) = NULL; } @@ -2079,6 +2085,7 @@ PHP_FUNCTION(mb_output_handler) /* delete the converter if it is the last feed. */ if (last_feed) { + MBSTRG(illegalchars) += mbfl_buffer_illegalchars(MBSTRG(outconv)); mbfl_buffer_converter_delete(MBSTRG(outconv)); MBSTRG(outconv) = NULL; } @@ -2711,6 +2718,7 @@ MBSTRING_API char * php_mb_convert_encoding(char *input, size_t length, char *_t output = (char *)ret->val; } + MBSTRG(illegalchars) += mbfl_buffer_illegalchars(convd); mbfl_buffer_converter_delete(convd); return output; } @@ -3376,6 +3384,7 @@ detect_end: } efree(stack); } + MBSTRG(illegalchars) += mbfl_buffer_illegalchars(convd); mbfl_buffer_converter_delete(convd); } @@ -3795,6 +3804,8 @@ PHP_FUNCTION(mb_get_info) if (lang != NULL && (name = (char *)mbfl_no_encoding2name(lang->mail_body_encoding)) != NULL) { RETVAL_STRING(name, 1); } + } else if (!strcasecmp("illegal_chars", typ)) { + RETVAL_LONG(MBSTRG(illegalchars)); } else { RETURN_FALSE; } @@ -3961,6 +3972,7 @@ MBSTRING_API int php_mb_gpc_encoding_converter(char **str, int *len, int num, co str[i] = ret->val; len[i] = ret->len; } + MBSTRG(illegalchars) += mbfl_buffer_illegalchars(convd); mbfl_buffer_converter_delete(convd); } return ret ? 0 : -1; @@ -4184,6 +4196,7 @@ int php_mb_encoding_converter(char **to, int *to_length, const char *from, *to = ret->val; *to_length = ret->len; } + MBSTRG(illegalchars) += mbfl_buffer_illegalchars(convd); mbfl_buffer_converter_delete(convd); return ret ? 0 : -1; diff --git a/ext/mbstring/mbstring.h b/ext/mbstring/mbstring.h index 22ca422c75..95e2616077 100644 --- a/ext/mbstring/mbstring.h +++ b/ext/mbstring/mbstring.h @@ -176,6 +176,7 @@ ZEND_BEGIN_MODULE_GLOBALS(mbstring) int current_filter_illegal_substchar; long func_overload; zend_bool encoding_translation; + long illegalchars; mbfl_buffer_converter *outconv; #if HAVE_MBREGEX && defined(PHP_MBREGEX_GLOBALS) PHP_MBREGEX_GLOBALS -- 2.40.0