diff options
Diffstat (limited to 'ext/iconv/iconv.c')
-rw-r--r-- | ext/iconv/iconv.c | 89 |
1 files changed, 60 insertions, 29 deletions
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 87ad5eeaa..2df759f99 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -226,11 +226,10 @@ static PHP_INI_MH(OnUpdateInputEncoding) if (new_value_length >= ICONV_CSNMAXLEN) { return FAILURE; } - if (new_value_length) { - OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); - } else { - OnUpdateString(entry, PG(input_encoding), strlen(PG(input_encoding))+1, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) { + php_error_docref("ref.iconv" TSRMLS_CC, E_DEPRECATED, "Use of iconv.input_encoding is deprecated"); } + OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); return SUCCESS; } @@ -240,11 +239,10 @@ static PHP_INI_MH(OnUpdateOutputEncoding) if(new_value_length >= ICONV_CSNMAXLEN) { return FAILURE; } - if (new_value_length) { - OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); - } else { - OnUpdateString(entry, PG(output_encoding), strlen(PG(output_encoding))+1, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) { + php_error_docref("ref.iconv" TSRMLS_CC, E_DEPRECATED, "Use of iconv.output_encoding is deprecated"); } + OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); return SUCCESS; } @@ -254,11 +252,10 @@ static PHP_INI_MH(OnUpdateInternalEncoding) if(new_value_length >= ICONV_CSNMAXLEN) { return FAILURE; } - if (new_value_length) { - OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); - } else { - OnUpdateString(entry, PG(internal_encoding), strlen(PG(internal_encoding))+1, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) { + php_error_docref("ref.iconv" TSRMLS_CC, E_DEPRECATED, "Use of iconv.internal_encoding is deprecated"); } + OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); return SUCCESS; } @@ -347,6 +344,40 @@ PHP_MINFO_FUNCTION(miconv) } /* }}} */ +static char *get_internal_encoding(TSRMLS_D) { + if (ICONVG(internal_encoding) && ICONVG(internal_encoding)[0]) { + return ICONVG(internal_encoding); + } else if (PG(internal_encoding) && PG(internal_encoding)[0]) { + return PG(internal_encoding); + } else if (SG(default_charset)) { + return SG(default_charset); + } + return ""; +} + +static char *get_input_encoding(TSRMLS_D) { + if (ICONVG(input_encoding) && ICONVG(input_encoding)[0]) { + return ICONVG(input_encoding); + } else if (PG(input_encoding) && PG(input_encoding)[0]) { + return PG(input_encoding); + } else if (SG(default_charset)) { + return SG(default_charset); + } + return ""; +} + +static char *get_output_encoding(TSRMLS_D) { + if (ICONVG(output_encoding) && ICONVG(output_encoding)[0]) { + return ICONVG(output_encoding); + } else if (PG(output_encoding) && PG(output_encoding)[0]) { + return PG(output_encoding); + } else if (SG(default_charset)) { + return SG(default_charset); + } + return ""; +} + + static int php_iconv_output_conflict(const char *handler_name, size_t handler_name_len TSRMLS_DC) { if (php_output_get_level(TSRMLS_C)) { @@ -388,12 +419,12 @@ static int php_iconv_output_handler(void **nothing, php_output_context *output_c if (mimetype != NULL && !(output_context->op & PHP_OUTPUT_HANDLER_CLEAN)) { int len; - char *p = strstr(ICONVG(output_encoding), "//"); + char *p = strstr(get_output_encoding(TSRMLS_C), "//"); if (p) { - len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%.*s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, (int)(p - ICONVG(output_encoding)), ICONVG(output_encoding)); + len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%.*s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, (int)(p - get_output_encoding(TSRMLS_C)), get_output_encoding(TSRMLS_C)); } else { - len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, ICONVG(output_encoding)); + len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, get_output_encoding(TSRMLS_C)); } if (content_type && SUCCESS == sapi_add_header(content_type, len, 0)) { SG(sapi_headers).send_default_content_type = 0; @@ -404,7 +435,7 @@ static int php_iconv_output_handler(void **nothing, php_output_context *output_c if (output_context->in.used) { output_context->out.free = 1; - _php_iconv_show_error(php_iconv_string(output_context->in.data, output_context->in.used, &output_context->out.data, &output_context->out.used, ICONVG(output_encoding), ICONVG(internal_encoding)), ICONVG(output_encoding), ICONVG(internal_encoding) TSRMLS_CC); + _php_iconv_show_error(php_iconv_string(output_context->in.data, output_context->in.used, &output_context->out.data, &output_context->out.used, get_output_encoding(TSRMLS_C), get_internal_encoding(TSRMLS_C)), get_output_encoding(TSRMLS_C), get_internal_encoding(TSRMLS_C) TSRMLS_CC); } return SUCCESS; @@ -1991,7 +2022,7 @@ static void _php_iconv_show_error(php_iconv_err_t err, const char *out_charset, Returns the character count of str */ PHP_FUNCTION(iconv_strlen) { - char *charset = ICONVG(internal_encoding); + char *charset = get_internal_encoding(TSRMLS_C); int charset_len = 0; char *str; int str_len; @@ -2024,7 +2055,7 @@ PHP_FUNCTION(iconv_strlen) Returns specified part of a string */ PHP_FUNCTION(iconv_substr) { - char *charset = ICONVG(internal_encoding); + char *charset = get_internal_encoding(TSRMLS_C); int charset_len = 0; char *str; int str_len; @@ -2064,7 +2095,7 @@ PHP_FUNCTION(iconv_substr) Finds position of first occurrence of needle within part of haystack beginning with offset */ PHP_FUNCTION(iconv_strpos) { - char *charset = ICONVG(internal_encoding); + char *charset = get_internal_encoding(TSRMLS_C); int charset_len = 0; char *haystk; int haystk_len; @@ -2112,7 +2143,7 @@ PHP_FUNCTION(iconv_strpos) Finds position of last occurrence of needle within part of haystack beginning with offset */ PHP_FUNCTION(iconv_strrpos) { - char *charset = ICONVG(internal_encoding); + char *charset = get_internal_encoding(TSRMLS_C); int charset_len = 0; char *haystk; int haystk_len; @@ -2163,7 +2194,7 @@ PHP_FUNCTION(iconv_mime_encode) smart_str retval = {0}; php_iconv_err_t err; - const char *in_charset = ICONVG(internal_encoding); + const char *in_charset = get_internal_encoding(TSRMLS_C); const char *out_charset = in_charset; long line_len = 76; const char *lfchars = "\r\n"; @@ -2276,7 +2307,7 @@ PHP_FUNCTION(iconv_mime_decode) { char *encoded_str; int encoded_str_len; - char *charset = ICONVG(internal_encoding); + char *charset = get_internal_encoding(TSRMLS_C); int charset_len = 0; long mode = 0; @@ -2317,7 +2348,7 @@ PHP_FUNCTION(iconv_mime_decode_headers) { const char *encoded_str; int encoded_str_len; - char *charset = ICONVG(internal_encoding); + char *charset = get_internal_encoding(TSRMLS_C); int charset_len = 0; long mode = 0; @@ -2485,15 +2516,15 @@ PHP_FUNCTION(iconv_get_encoding) if (!strcasecmp("all", type)) { array_init(return_value); - add_assoc_string(return_value, "input_encoding", ICONVG(input_encoding), 1); - add_assoc_string(return_value, "output_encoding", ICONVG(output_encoding), 1); - add_assoc_string(return_value, "internal_encoding", ICONVG(internal_encoding), 1); + add_assoc_string(return_value, "input_encoding", get_input_encoding(TSRMLS_C), 1); + add_assoc_string(return_value, "output_encoding", get_output_encoding(TSRMLS_C), 1); + add_assoc_string(return_value, "internal_encoding", get_internal_encoding(TSRMLS_C), 1); } else if (!strcasecmp("input_encoding", type)) { - RETVAL_STRING(ICONVG(input_encoding), 1); + RETVAL_STRING(get_input_encoding(TSRMLS_C), 1); } else if (!strcasecmp("output_encoding", type)) { - RETVAL_STRING(ICONVG(output_encoding), 1); + RETVAL_STRING(get_output_encoding(TSRMLS_C), 1); } else if (!strcasecmp("internal_encoding", type)) { - RETVAL_STRING(ICONVG(internal_encoding), 1); + RETVAL_STRING(get_internal_encoding(TSRMLS_C), 1); } else { RETURN_FALSE; } |