33
33
/* }}} */
34
34
35
35
enum {
36
- INTL_IDN_VARIANT_2003 = 0 ,
37
- INTL_IDN_VARIANT_UTS46
36
+ INTL_IDN_VARIANT_UTS46 = 1
38
37
};
39
38
40
39
/* {{{ grapheme_register_constants
@@ -73,7 +72,6 @@ void idn_register_constants( INIT_FUNC_ARGS )
73
72
REGISTER_LONG_CONSTANT ("IDNA_NONTRANSITIONAL_TO_UNICODE" , UIDNA_NONTRANSITIONAL_TO_UNICODE , CONST_CS | CONST_PERSISTENT );
74
73
75
74
/* VARIANTS */
76
- REGISTER_LONG_CONSTANT ("INTL_IDNA_VARIANT_2003" , INTL_IDN_VARIANT_2003 , CONST_CS | CONST_PERSISTENT );
77
75
REGISTER_LONG_CONSTANT ("INTL_IDNA_VARIANT_UTS46" , INTL_IDN_VARIANT_UTS46 , CONST_CS | CONST_PERSISTENT );
78
76
79
77
/* PINFO ERROR CODES */
@@ -176,85 +174,11 @@ static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS,
176
174
uidna_close (uts46 );
177
175
}
178
176
179
- static void php_intl_idn_to (INTERNAL_FUNCTION_PARAMETERS ,
180
- const zend_string * domain , uint32_t option , int mode )
181
- {
182
- UChar * ustring = NULL ;
183
- int ustring_len = 0 ;
184
- UErrorCode status ;
185
- zend_string * u8str ;
186
-
187
- /* convert the string to UTF-16. */
188
- status = U_ZERO_ERROR ;
189
- intl_convert_utf8_to_utf16 (& ustring , & ustring_len , ZSTR_VAL (domain ), ZSTR_LEN (domain ), & status );
190
-
191
- if (U_FAILURE (status )) {
192
- intl_error_set_code (NULL , status );
193
-
194
- /* Set error messages. */
195
- intl_error_set_custom_msg ( NULL , "Error converting input string to UTF-16" , 0 );
196
- if (ustring ) {
197
- efree (ustring );
198
- }
199
- RETURN_FALSE ;
200
- } else {
201
- UChar converted [MAXPATHLEN ];
202
- int32_t converted_ret_len ;
203
-
204
- status = U_ZERO_ERROR ;
205
-
206
- #if U_ICU_VERSION_MAJOR_NUM >= 55
207
- UIDNAInfo info = UIDNA_INFO_INITIALIZER ;
208
- UIDNA * idna = uidna_openUTS46 ((int32_t )option , & status );
209
-
210
- if (U_FAILURE (status )) {
211
- intl_error_set ( NULL , status , "idn_to_ascii: failed to create an UIDNA instance" , 0 );
212
- RETURN_FALSE ;
213
- }
214
-
215
- if (mode == INTL_IDN_TO_ASCII ) {
216
- converted_ret_len = uidna_nameToASCII (idna , ustring , ustring_len , converted , MAXPATHLEN , & info , & status );
217
- } else {
218
- converted_ret_len = uidna_nameToUnicode (idna , ustring , ustring_len , converted , MAXPATHLEN , & info , & status );
219
- }
220
- uidna_close (idna );
221
- #else
222
- UParseError parse_error ;
223
- if (mode == INTL_IDN_TO_ASCII ) {
224
- converted_ret_len = uidna_IDNToASCII (ustring , ustring_len , converted , MAXPATHLEN , (int32_t )option , & parse_error , & status );
225
- } else {
226
- converted_ret_len = uidna_IDNToUnicode (ustring , ustring_len , converted , MAXPATHLEN , (int32_t )option , & parse_error , & status );
227
- }
228
- #endif
229
- efree (ustring );
230
-
231
- if (U_FAILURE (status )) {
232
- intl_error_set ( NULL , status , "idn_to_ascii: cannot convert to ASCII" , 0 );
233
- RETURN_FALSE ;
234
- }
235
-
236
- status = U_ZERO_ERROR ;
237
- u8str = intl_convert_utf16_to_utf8 (converted , converted_ret_len , & status );
238
-
239
- if (!u8str ) {
240
- /* Set global error code. */
241
- intl_error_set_code (NULL , status );
242
-
243
- /* Set error messages. */
244
- intl_error_set_custom_msg ( NULL , "Error converting output string to UTF-8" , 0 );
245
- RETURN_FALSE ;
246
- }
247
- }
248
-
249
- /* return the allocated string, not a duplicate */
250
- RETVAL_NEW_STR (u8str );
251
- }
252
-
253
177
static void php_intl_idn_handoff (INTERNAL_FUNCTION_PARAMETERS , int mode )
254
178
{
255
179
zend_string * domain ;
256
180
zend_long option = 0 ,
257
- variant = INTL_IDN_VARIANT_UTS46 ;
181
+ variant = INTL_IDN_VARIANT_UTS46 ;
258
182
zval * idna_info = NULL ;
259
183
260
184
intl_error_reset (NULL );
@@ -265,9 +189,8 @@ static void php_intl_idn_handoff(INTERNAL_FUNCTION_PARAMETERS, int mode)
265
189
RETURN_NULL (); /* don't set FALSE because that's not the way it was before... */
266
190
}
267
191
268
- if (variant != INTL_IDN_VARIANT_2003 && variant != INTL_IDN_VARIANT_UTS46 ) {
269
- php_intl_bad_args ("invalid variant, must be one of {"
270
- "INTL_IDNA_VARIANT_2003, INTL_IDNA_VARIANT_UTS46}" );
192
+ if (variant != INTL_IDN_VARIANT_UTS46 ) {
193
+ php_intl_bad_args ("invalid variant, must be INTL_IDNA_VARIANT_UTS46" );
271
194
RETURN_FALSE ;
272
195
}
273
196
@@ -281,29 +204,14 @@ static void php_intl_idn_handoff(INTERNAL_FUNCTION_PARAMETERS, int mode)
281
204
}
282
205
/* don't check options; it wasn't checked before */
283
206
284
- if (variant == INTL_IDN_VARIANT_2003 ) {
285
- php_error_docref (NULL , E_DEPRECATED , "INTL_IDNA_VARIANT_2003 is deprecated" );
286
- }
287
-
288
207
if (idna_info != NULL ) {
289
- if (variant == INTL_IDN_VARIANT_2003 ) {
290
- php_error_docref0 (NULL , E_NOTICE ,
291
- "4 arguments were provided, but INTL_IDNA_VARIANT_2003 only "
292
- "takes 3 - extra argument ignored" );
293
- } else {
294
- idna_info = zend_try_array_init (idna_info );
295
- if (!idna_info ) {
296
- return ;
297
- }
208
+ idna_info = zend_try_array_init (idna_info );
209
+ if (!idna_info ) {
210
+ return ;
298
211
}
299
212
}
300
213
301
- if (variant == INTL_IDN_VARIANT_2003 ) {
302
- php_intl_idn_to (INTERNAL_FUNCTION_PARAM_PASSTHRU , domain , (uint32_t )option , mode );
303
- }
304
- else {
305
- php_intl_idn_to_46 (INTERNAL_FUNCTION_PARAM_PASSTHRU , domain , (uint32_t )option , mode , idna_info );
306
- }
214
+ php_intl_idn_to_46 (INTERNAL_FUNCTION_PARAM_PASSTHRU , domain , (uint32_t )option , mode , idna_info );
307
215
}
308
216
309
217
/* {{{ proto string idn_to_ascii(string domain[, int options[, int variant[, array &idna_info]]])
0 commit comments