Skip to content

Commit 724d599

Browse files
committed
Remove deprecated iconv INI settings
1 parent 6bc375f commit 724d599

10 files changed

+89
-266
lines changed

ext/iconv/iconv.c

Lines changed: 26 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "ext/standard/info.h"
2626
#include "main/php_output.h"
2727
#include "SAPI.h"
28-
#include "php_ini.h"
2928

3029
#include <stdlib.h>
3130
#include <errno.h>
@@ -56,9 +55,6 @@
5655
#define _php_iconv_memequal(a, b, c) \
5756
(memcmp(a, b, c) == 0)
5857

59-
ZEND_DECLARE_MODULE_GLOBALS(iconv)
60-
static PHP_GINIT_FUNCTION(iconv);
61-
6258
/* {{{ iconv_module_entry
6359
*/
6460
zend_module_entry iconv_module_entry = {
@@ -71,11 +67,7 @@ zend_module_entry iconv_module_entry = {
7167
NULL,
7268
PHP_MINFO(miconv),
7369
PHP_ICONV_VERSION,
74-
PHP_MODULE_GLOBALS(iconv),
75-
PHP_GINIT(iconv),
76-
NULL,
77-
NULL,
78-
STANDARD_MODULE_PROPERTIES_EX
70+
STANDARD_MODULE_PROPERTIES,
7971
};
8072
/* }}} */
8173

@@ -86,18 +78,6 @@ ZEND_TSRMLS_CACHE_DEFINE()
8678
ZEND_GET_MODULE(iconv)
8779
#endif
8880

89-
/* {{{ PHP_GINIT_FUNCTION */
90-
static PHP_GINIT_FUNCTION(iconv)
91-
{
92-
#if defined(COMPILE_DL_ICONV) && defined(ZTS)
93-
ZEND_TSRMLS_CACHE_UPDATE();
94-
#endif
95-
iconv_globals->input_encoding = NULL;
96-
iconv_globals->output_encoding = NULL;
97-
iconv_globals->internal_encoding = NULL;
98-
}
99-
/* }}} */
100-
10181
#if defined(HAVE_LIBICONV) && defined(ICONV_ALIASED_LIBICONV)
10282
#define iconv libiconv
10383
#endif
@@ -142,55 +122,6 @@ static const char _generic_superset_name[] = ICONV_UCS4_ENCODING;
142122
#define GENERIC_SUPERSET_NBYTES 4
143123
/* }}} */
144124

145-
146-
static PHP_INI_MH(OnUpdateInputEncoding)
147-
{
148-
if (ZSTR_LEN(new_value) >= ICONV_CSNMAXLEN) {
149-
return FAILURE;
150-
}
151-
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
152-
php_error_docref("ref.iconv", E_DEPRECATED, "Use of iconv.input_encoding is deprecated");
153-
}
154-
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
155-
return SUCCESS;
156-
}
157-
158-
159-
static PHP_INI_MH(OnUpdateOutputEncoding)
160-
{
161-
if (ZSTR_LEN(new_value) >= ICONV_CSNMAXLEN) {
162-
return FAILURE;
163-
}
164-
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
165-
php_error_docref("ref.iconv", E_DEPRECATED, "Use of iconv.output_encoding is deprecated");
166-
}
167-
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
168-
return SUCCESS;
169-
}
170-
171-
172-
static PHP_INI_MH(OnUpdateInternalEncoding)
173-
{
174-
if (ZSTR_LEN(new_value) >= ICONV_CSNMAXLEN) {
175-
return FAILURE;
176-
}
177-
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
178-
php_error_docref("ref.iconv", E_DEPRECATED, "Use of iconv.internal_encoding is deprecated");
179-
}
180-
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
181-
return SUCCESS;
182-
}
183-
184-
185-
/* {{{ PHP_INI
186-
*/
187-
PHP_INI_BEGIN()
188-
STD_PHP_INI_ENTRY("iconv.input_encoding", "", PHP_INI_ALL, OnUpdateInputEncoding, input_encoding, zend_iconv_globals, iconv_globals)
189-
STD_PHP_INI_ENTRY("iconv.output_encoding", "", PHP_INI_ALL, OnUpdateOutputEncoding, output_encoding, zend_iconv_globals, iconv_globals)
190-
STD_PHP_INI_ENTRY("iconv.internal_encoding", "", PHP_INI_ALL, OnUpdateInternalEncoding, internal_encoding, zend_iconv_globals, iconv_globals)
191-
PHP_INI_END()
192-
/* }}} */
193-
194125
/* {{{ PHP_MINIT_FUNCTION */
195126
PHP_MINIT_FUNCTION(miconv)
196127
{
@@ -236,7 +167,6 @@ PHP_MINIT_FUNCTION(miconv)
236167
PHP_MSHUTDOWN_FUNCTION(miconv)
237168
{
238169
php_iconv_stream_filter_unregister_factory();
239-
UNREGISTER_INI_ENTRIES();
240170
return SUCCESS;
241171
}
242172
/* }}} */
@@ -254,33 +184,9 @@ PHP_MINFO_FUNCTION(miconv)
254184
php_info_print_table_row(2, "iconv implementation", Z_STRVAL_P(iconv_impl));
255185
php_info_print_table_row(2, "iconv library version", Z_STRVAL_P(iconv_ver));
256186
php_info_print_table_end();
257-
258-
DISPLAY_INI_ENTRIES();
259187
}
260188
/* }}} */
261189

262-
static const char *get_internal_encoding(void) {
263-
if (ICONVG(internal_encoding) && ICONVG(internal_encoding)[0]) {
264-
return ICONVG(internal_encoding);
265-
}
266-
return php_get_internal_encoding();
267-
}
268-
269-
static const char *get_input_encoding(void) {
270-
if (ICONVG(input_encoding) && ICONVG(input_encoding)[0]) {
271-
return ICONVG(input_encoding);
272-
}
273-
return php_get_input_encoding();
274-
}
275-
276-
static const char *get_output_encoding(void) {
277-
if (ICONVG(output_encoding) && ICONVG(output_encoding)[0]) {
278-
return ICONVG(output_encoding);
279-
}
280-
return php_get_output_encoding();
281-
}
282-
283-
284190
static int php_iconv_output_conflict(const char *handler_name, size_t handler_name_len)
285191
{
286192
if (php_output_get_level()) {
@@ -321,12 +227,16 @@ static int php_iconv_output_handler(void **nothing, php_output_context *output_c
321227

322228
if (mimetype != NULL && !(output_context->op & PHP_OUTPUT_HANDLER_CLEAN)) {
323229
size_t len;
324-
char *p = strstr(get_output_encoding(), "//");
230+
char *p = strstr(php_get_output_encoding(), "//");
325231

326232
if (p) {
327-
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%.*s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, (int) (p - get_output_encoding()), get_output_encoding());
233+
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%.*s",
234+
mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype,
235+
(int) (p - php_get_output_encoding()), php_get_output_encoding());
328236
} else {
329-
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, get_output_encoding());
237+
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%s",
238+
mimetype_len ? mimetype_len : (int) strlen(mimetype),
239+
mimetype, php_get_output_encoding());
330240
}
331241
if (content_type && SUCCESS == sapi_add_header(content_type, len, 0)) {
332242
SG(sapi_headers).send_default_content_type = 0;
@@ -338,7 +248,9 @@ static int php_iconv_output_handler(void **nothing, php_output_context *output_c
338248
if (output_context->in.used) {
339249
zend_string *out;
340250
output_context->out.free = 1;
341-
_php_iconv_show_error(php_iconv_string(output_context->in.data, output_context->in.used, &out, get_output_encoding(), get_internal_encoding()), get_output_encoding(), get_internal_encoding());
251+
_php_iconv_show_error(php_iconv_string(output_context->in.data, output_context->in.used, &out,
252+
php_get_output_encoding(), php_get_internal_encoding()), php_get_output_encoding(),
253+
php_get_internal_encoding());
342254
if (out) {
343255
output_context->out.data = estrndup(ZSTR_VAL(out), ZSTR_LEN(out));
344256
output_context->out.used = ZSTR_LEN(out);
@@ -1840,7 +1752,7 @@ PHP_FUNCTION(iconv_strlen)
18401752
}
18411753

18421754
if (charset == NULL) {
1843-
charset = get_internal_encoding();
1755+
charset = php_get_internal_encoding();
18441756
} else if (charset_len >= ICONV_CSNMAXLEN) {
18451757
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
18461758
RETURN_FALSE;
@@ -1877,7 +1789,7 @@ PHP_FUNCTION(iconv_substr)
18771789
}
18781790

18791791
if (charset == NULL) {
1880-
charset = get_internal_encoding();
1792+
charset = php_get_internal_encoding();
18811793
} else if (charset_len >= ICONV_CSNMAXLEN) {
18821794
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
18831795
RETURN_FALSE;
@@ -1919,7 +1831,7 @@ PHP_FUNCTION(iconv_strpos)
19191831
}
19201832

19211833
if (charset == NULL) {
1922-
charset = get_internal_encoding();
1834+
charset = php_get_internal_encoding();
19231835
} else if (charset_len >= ICONV_CSNMAXLEN) {
19241836
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
19251837
RETURN_FALSE;
@@ -1979,7 +1891,7 @@ PHP_FUNCTION(iconv_strrpos)
19791891
}
19801892

19811893
if (charset == NULL) {
1982-
charset = get_internal_encoding();
1894+
charset = php_get_internal_encoding();
19831895
} else if (charset_len >= ICONV_CSNMAXLEN) {
19841896
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
19851897
RETURN_FALSE;
@@ -2008,7 +1920,7 @@ PHP_FUNCTION(iconv_mime_encode)
20081920
smart_str retval = {0};
20091921
php_iconv_err_t err;
20101922

2011-
const char *in_charset = get_internal_encoding();
1923+
const char *in_charset = php_get_internal_encoding();
20121924
const char *out_charset = in_charset;
20131925
zend_long line_len = 76;
20141926
const char *lfchars = "\r\n";
@@ -2120,7 +2032,7 @@ PHP_FUNCTION(iconv_mime_decode)
21202032
}
21212033

21222034
if (charset == NULL) {
2123-
charset = get_internal_encoding();
2035+
charset = php_get_internal_encoding();
21242036
} else if (charset_len >= ICONV_CSNMAXLEN) {
21252037
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
21262038
RETURN_FALSE;
@@ -2162,7 +2074,7 @@ PHP_FUNCTION(iconv_mime_decode_headers)
21622074
}
21632075

21642076
if (charset == NULL) {
2165-
charset = get_internal_encoding();
2077+
charset = php_get_internal_encoding();
21662078
} else if (charset_len >= ICONV_CSNMAXLEN) {
21672079
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
21682080
RETURN_FALSE;
@@ -2281,8 +2193,7 @@ PHP_FUNCTION(iconv_set_encoding)
22812193
{
22822194
char *type;
22832195
zend_string *charset;
2284-
size_t type_len, retval;
2285-
zend_string *name;
2196+
size_t type_len;
22862197

22872198
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sS", &type, &type_len, &charset) == FAILURE) {
22882199
RETURN_THROWS();
@@ -2293,24 +2204,7 @@ PHP_FUNCTION(iconv_set_encoding)
22932204
RETURN_FALSE;
22942205
}
22952206

2296-
if(!strcasecmp("input_encoding", type)) {
2297-
name = zend_string_init("iconv.input_encoding", sizeof("iconv.input_encoding") - 1, 0);
2298-
} else if(!strcasecmp("output_encoding", type)) {
2299-
name = zend_string_init("iconv.output_encoding", sizeof("iconv.output_encoding") - 1, 0);
2300-
} else if(!strcasecmp("internal_encoding", type)) {
2301-
name = zend_string_init("iconv.internal_encoding", sizeof("iconv.internal_encoding") - 1, 0);
2302-
} else {
2303-
RETURN_FALSE;
2304-
}
2305-
2306-
retval = zend_alter_ini_entry(name, charset, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
2307-
zend_string_release_ex(name, 0);
2308-
2309-
if (retval == SUCCESS) {
2310-
RETURN_TRUE;
2311-
} else {
2312-
RETURN_FALSE;
2313-
}
2207+
RETURN_FALSE;
23142208
}
23152209
/* }}} */
23162210

@@ -2327,15 +2221,15 @@ PHP_FUNCTION(iconv_get_encoding)
23272221

23282222
if (!strcasecmp("all", type)) {
23292223
array_init(return_value);
2330-
add_assoc_string(return_value, "input_encoding", get_input_encoding());
2331-
add_assoc_string(return_value, "output_encoding", get_output_encoding());
2332-
add_assoc_string(return_value, "internal_encoding", get_internal_encoding());
2224+
add_assoc_string(return_value, "input_encoding", php_get_input_encoding());
2225+
add_assoc_string(return_value, "output_encoding", php_get_output_encoding());
2226+
add_assoc_string(return_value, "internal_encoding", php_get_internal_encoding());
23332227
} else if (!strcasecmp("input_encoding", type)) {
2334-
RETVAL_STRING(get_input_encoding());
2228+
RETVAL_STRING(php_get_input_encoding());
23352229
} else if (!strcasecmp("output_encoding", type)) {
2336-
RETVAL_STRING(get_output_encoding());
2230+
RETVAL_STRING(php_get_output_encoding());
23372231
} else if (!strcasecmp("internal_encoding", type)) {
2338-
RETVAL_STRING(get_internal_encoding());
2232+
RETVAL_STRING(php_get_internal_encoding());
23392233
} else {
23402234
RETURN_FALSE;
23412235
}

ext/iconv/iconv.stub.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ function iconv_mime_decode_headers(string $headers, int $mode = 0, ?string $char
1818

1919
function iconv(string $in_charset, string $out_charset, string $str): string|false {}
2020

21+
/** @deprecated */
2122
function iconv_set_encoding(string $type, string $charset): bool {}
2223

23-
function iconv_get_encoding(string $type = "all"): array|string|false {}
24+
/** TODO Should be deprecated? */
25+
function iconv_get_encoding(string $type = 'all'): array|string|false {}

ext/iconv/iconv_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_iconv_set_encoding, 0, 2, _IS_BO
5555
ZEND_END_ARG_INFO()
5656

5757
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_get_encoding, 0, 0, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_FALSE)
58-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_STRING, 0, "\"all\"")
58+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_STRING, 0, "\'all\'")
5959
ZEND_END_ARG_INFO()
6060

6161

@@ -80,7 +80,7 @@ static const zend_function_entry ext_functions[] = {
8080
ZEND_FE(iconv_mime_decode, arginfo_iconv_mime_decode)
8181
ZEND_FE(iconv_mime_decode_headers, arginfo_iconv_mime_decode_headers)
8282
ZEND_FE(iconv, arginfo_iconv)
83-
ZEND_FE(iconv_set_encoding, arginfo_iconv_set_encoding)
83+
ZEND_DEP_FE(iconv_set_encoding, arginfo_iconv_set_encoding)
8484
ZEND_FE(iconv_get_encoding, arginfo_iconv_get_encoding)
8585
ZEND_FE_END
8686
};

ext/iconv/php_iconv.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,6 @@ PHP_FUNCTION(iconv_mime_encode);
6565
PHP_FUNCTION(iconv_mime_decode);
6666
PHP_FUNCTION(iconv_mime_decode_headers);
6767

68-
ZEND_BEGIN_MODULE_GLOBALS(iconv)
69-
char *input_encoding;
70-
char *internal_encoding;
71-
char *output_encoding;
72-
ZEND_END_MODULE_GLOBALS(iconv)
73-
74-
#define ICONVG(v) ZEND_MODULE_GLOBALS_ACCESSOR(iconv, v)
75-
76-
#if defined(ZTS) && defined(COMPILE_DL_ICONV)
77-
ZEND_TSRMLS_CACHE_EXTERN()
78-
#endif
79-
8068
#ifdef HAVE_IBM_ICONV
8169
# define ICONV_ASCII_ENCODING "IBM-850"
8270
# define ICONV_UCS4_ENCODING "UCS-4"

0 commit comments

Comments
 (0)