summaryrefslogtreecommitdiff
path: root/ext/mbstring
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mbstring')
-rw-r--r--ext/mbstring/mbstring.c70
-rw-r--r--ext/mbstring/mbstring.h1
2 files changed, 49 insertions, 22 deletions
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index 044dd761b9..a776d4cb04 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -71,7 +71,7 @@
#include "mbregex.h"
#endif
-static enum mbfl_no_encoding php_mbstr_default_identify_list[] = {
+static const enum mbfl_no_encoding php_mbstr_default_identify_list[] = {
mbfl_no_encoding_ascii,
mbfl_no_encoding_jis,
mbfl_no_encoding_utf8,
@@ -79,7 +79,7 @@ static enum mbfl_no_encoding php_mbstr_default_identify_list[] = {
mbfl_no_encoding_sjis
};
-static int php_mbstr_default_identify_list_size = sizeof(php_mbstr_default_identify_list)/sizeof(enum mbfl_no_encoding);
+static const int php_mbstr_default_identify_list_size = sizeof(php_mbstr_default_identify_list)/sizeof(enum mbfl_no_encoding);
static unsigned char third_and_rest_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE_REST };
static unsigned char second_args_force_ref[] = { 2, BYREF_NONE, BYREF_FORCE };
@@ -233,6 +233,10 @@ php_mbstring_parse_encoding_list(const char *value, int value_length, int **retu
list = NULL;
if (value == NULL || value_length <= 0) {
+ if (return_list)
+ *return_list = NULL;
+ if (return_size)
+ *return_size = 0;
return 0;
} else {
/* copy the value string for work */
@@ -277,7 +281,7 @@ php_mbstring_parse_encoding_list(const char *value, int value_length, int **retu
if (!bauto) {
bauto = 1;
l = php_mbstr_default_identify_list_size;
- src = php_mbstr_default_identify_list;
+ src = (int*)php_mbstr_default_identify_list;
while (l > 0) {
*entry++ = *src++;
l--;
@@ -292,24 +296,38 @@ php_mbstring_parse_encoding_list(const char *value, int value_length, int **retu
}
p1 = p2 + 1;
} while (n < size && p2 != NULL);
- if (n > 0){
- *return_list = list;
- *return_size = n;
+ if (n > 0) {
+ if (return_list)
+ *return_list = list;
+ else
+ pefree(list, persistent);
} else {
- efree(list);
- *return_list = NULL;
+ 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);
}
- if (list == NULL) {
- return 0;
- }
-
return ret;
}
+/* {{{ php_mb_check_encoding_list */
+PHPAPI int php_mb_check_encoding_list(const char *encoding_list TSRMLS_DC) {
+ return php_mbstring_parse_encoding_list(encoding_list, strlen(encoding_list), NULL, NULL, 0);
+}
+/* }}} */
+
/* 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.
@@ -343,7 +361,7 @@ php_mbstring_parse_encoding_array(zval *array, int **return_list, int *return_si
if (!bauto) {
bauto = 1;
l = php_mbstr_default_identify_list_size;
- src = php_mbstr_default_identify_list;
+ src = (int*)php_mbstr_default_identify_list;
while (l > 0) {
*entry++ = *src++;
l--;
@@ -360,19 +378,27 @@ php_mbstring_parse_encoding_array(zval *array, int **return_list, int *return_si
i--;
}
if (n > 0) {
- *return_list = list;
- *return_size = n;
+ if (return_list)
+ *return_list = list;
+ else
+ pefree(list, persistent);
} else {
- efree(list);
- *return_list = NULL;
+ 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;
}
}
- if (list == NULL) {
- return 0;
- }
-
return ret;
}
@@ -594,7 +620,7 @@ PHP_RINIT_FUNCTION(mbstring)
n = MBSTRG(detect_order_list_size);
}
if (n <= 0) {
- list = php_mbstr_default_identify_list;
+ list = (int*)php_mbstr_default_identify_list;
n = php_mbstr_default_identify_list_size;
}
entry = (int *)emalloc(n*sizeof(int));
diff --git a/ext/mbstring/mbstring.h b/ext/mbstring/mbstring.h
index 57f05e1de2..5744bf1631 100644
--- a/ext/mbstring/mbstring.h
+++ b/ext/mbstring/mbstring.h
@@ -58,6 +58,7 @@
#define PHP_MBSTRING_API 20020405
PHPAPI char * php_mb_convert_encoding(char *input, size_t length, char *_to_encoding, char *_from_encodings, size_t *output_len TSRMLS_DC);
+PHPAPI int php_mb_check_encoding_list(const char *encoding_list TSRMLS_DC);
#if HAVE_MBREGEX
#include "mbregex.h"