From: Stanislav Malyshev Date: Mon, 6 Jul 2009 23:44:16 +0000 (+0000) Subject: - merge errors support X-Git-Tag: php-5.4.0alpha1~191^2~3155 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8d8026aa922c6290104cb78bff059394edac6928;p=php - merge errors support - merge IDN --- diff --git a/ext/intl/config.m4 b/ext/intl/config.m4 index 05de6fd9b5..00aeceb468 100755 --- a/ext/intl/config.m4 +++ b/ext/intl/config.m4 @@ -45,7 +45,8 @@ if test "$PHP_INTL" != "no"; then msgformat/msgformat_helpers.cpp \ msgformat/msgformat_parse.c \ grapheme/grapheme_string.c \ - grapheme/grapheme_util.c,$ext_shared,,$ICU_INCS) + grapheme/grapheme_util.c \ + idn/idn.c,$ext_shared,,$ICU_INCS) PHP_ADD_BUILD_DIR([$ext_builddir/collator]) PHP_ADD_BUILD_DIR([$ext_builddir/common]) diff --git a/ext/intl/config.w32 b/ext/intl/config.w32 index 4ae35e5f68..46a06f6283 100755 --- a/ext/intl/config.w32 +++ b/ext/intl/config.w32 @@ -55,6 +55,9 @@ if (PHP_INTL != "no") { ADD_SOURCES(configure_module_dirname + "/grapheme", "\ grapheme_string.c grapheme_util.c \ ", "intl"); + ADD_SOURCES(configure_module_dirname + "/idn", "\ + idn.c \ + ", "intl"); ADD_FLAG("LIBS_INTL", "icudt.lib icuin.lib icuio.lib icule.lib iculx.lib"); // if int32_t and uint32_t types are made available in PHP, uncomment next line // ADD_FLAG("CFLAGS_INTL", "/D U_HAVE_INT32_T /D U_HAVE_UINT32_T"); diff --git a/ext/intl/idn/idn.c b/ext/intl/idn/idn.c new file mode 100644 index 0000000000..b4aa9a0ef0 --- /dev/null +++ b/ext/intl/idn/idn.c @@ -0,0 +1,116 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 2009 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Pierre A. Joye | + +----------------------------------------------------------------------+ + */ +/* $Id$ */ + +/* {{{ includes */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include "ext/standard/php_string.h" + +#include "intl_error.h" + #include "intl_convert.h" +/* }}} */ + +/* {{{ idn_register_constants + * Register API constants + */ +void idn_register_constants( INIT_FUNC_ARGS ) +{ + /* Option to prohibit processing of unassigned codepoints in the input and + do not check if the input conforms to STD-3 ASCII rules. */ + REGISTER_LONG_CONSTANT("IDNA_DEFAULT", UIDNA_DEFAULT, CONST_CS | CONST_PERSISTENT); + + /* Option to allow processing of unassigned codepoints in the input */ + REGISTER_LONG_CONSTANT("IDNA_ALLOW_UNASSIGNED", UIDNA_ALLOW_UNASSIGNED, CONST_CS | CONST_PERSISTENT); + + /* Option to check if input conforms to STD-3 ASCII rules */ + REGISTER_LONG_CONSTANT("IDNA_USE_STD3_RULES", UIDNA_USE_STD3_RULES, CONST_CS | CONST_PERSISTENT); +} +/* }}} */ + +enum { + INTL_IDN_TO_ASCII = 0, + INTL_IDN_TO_UNICODE +}; + +static void php_intl_idn_to(INTERNAL_FUNCTION_PARAMETERS, int mode) +{ + int domain_len; + long option = 0; + UChar* domain = NULL; + UParseError parse_error; + UErrorCode status; + UChar converted[MAXPATHLEN]; + int32_t converted_ret_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "u|l", (char **)&domain, &domain_len, &option, &status) == FAILURE) { + return; + } + + if (domain_len < 1) { + intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "idn_to_ascii: empty domain name", 0 TSRMLS_CC ); + RETURN_FALSE; + } + + status = U_ZERO_ERROR; + if (mode == INTL_IDN_TO_ASCII) { + converted_ret_len = uidna_IDNToASCII(domain, domain_len, converted, MAXPATHLEN, (int32_t)option, &parse_error, &status); + } else { + converted_ret_len = uidna_IDNToUnicode(domain, domain_len, converted, MAXPATHLEN, (int32_t)option, &parse_error, &status); + } + + if (U_FAILURE(status)) { + intl_error_set( NULL, status, "idn_to_ascii: cannot convert domain name", 0 TSRMLS_CC ); + RETURN_FALSE; + } + + RETURN_UNICODEL(converted, converted_ret_len, 1); +} + +/* {{{ proto int idn_to_ascii(string domain[, int options]) + Converts a domain name to ASCII representation, as defined in the IDNA RFC */ +PHP_FUNCTION(idn_to_ascii) +{ + php_intl_idn_to(INTERNAL_FUNCTION_PARAM_PASSTHRU, INTL_IDN_TO_ASCII); +} +/* }}} */ + + +/* {{{ proto int idn_to_utf8(string domain[, int options]) + Converts an ASCII representation of the domain to Unicode, as defined in the IDNA RFC */ +PHP_FUNCTION(idn_to_unicode) +{ + php_intl_idn_to(INTERNAL_FUNCTION_PARAM_PASSTHRU, INTL_IDN_TO_UNICODE); +} +/* }}} */ + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: fdm=marker + * vim: noet sw=4 ts=4 + */ diff --git a/ext/intl/idn/idn.h b/ext/intl/idn/idn.h new file mode 100644 index 0000000000..ad43f0e153 --- /dev/null +++ b/ext/intl/idn/idn.h @@ -0,0 +1,30 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 2009 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Pierre A. Joye | + +----------------------------------------------------------------------+ + */ +/* $Id$ s*/ + +#ifndef IDN_IDN_H +#define IDN_IDN_H + +#include + +PHP_FUNCTION(idn_to_ascii); +PHP_FUNCTION(idn_to_unicode); + +void idn_register_constants(INIT_FUNC_ARGS); + +#endif /* IDN_IDN_H */ diff --git a/ext/intl/intl_error.c b/ext/intl/intl_error.c index fd105e9296..4e55d956df 100755 --- a/ext/intl/intl_error.c +++ b/ext/intl/intl_error.c @@ -103,6 +103,9 @@ void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg TSRMLS_D if( !msg ) return; + if(!err && INTL_G(error_level)) { + php_error_docref(NULL TSRMLS_CC, INTL_G(error_level), "%s", msg); + } if( !err && !( err = intl_g_error_get( TSRMLS_C ) ) ) return; diff --git a/ext/intl/php_intl.c b/ext/intl/php_intl.c index f46c70f320..fe6fd25725 100755 --- a/ext/intl/php_intl.c +++ b/ext/intl/php_intl.c @@ -53,6 +53,9 @@ #include "locale/locale.h" #include "locale/locale_class.h" #include "locale/locale_methods.h" + +#include "idn/idn.h" + #include #include "php_ini.h" @@ -284,6 +287,18 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgfmt_get_locale, 0, 0, 1) ZEND_ARG_INFO(0, mf) ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_idn_to_ascii, 0, 0, 1) + ZEND_ARG_INFO(0, domain) + ZEND_ARG_INFO(0, option) + ZEND_ARG_INFO(0, status) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_idn_to_utf8, 0, 0, 1) + ZEND_ARG_INFO(0, domain) + ZEND_ARG_INFO(0, option) + ZEND_ARG_INFO(0, status) +ZEND_END_ARG_INFO() /* }}} */ /* {{{ intl_functions[] @@ -329,9 +344,9 @@ zend_function_entry intl_functions[] = { PHP_FE( normalizer_is_normalized, normalizer_args ) /* Locale functions */ - PHP_NAMED_FE( locale_get_default, zif_locale_get_default, locale_0_args) +/* PHP_NAMED_FE( locale_get_default, zif_locale_get_default, locale_0_args) PHP_NAMED_FE( locale_set_default, zif_locale_set_default, locale_1_arg ) - PHP_FE( locale_get_primary_language, locale_1_arg ) +*/ PHP_FE( locale_get_primary_language, locale_1_arg ) PHP_FE( locale_get_script, locale_1_arg ) PHP_FE( locale_get_region, locale_1_arg ) PHP_FE( locale_get_keywords, locale_1_arg ) @@ -371,6 +386,11 @@ zend_function_entry intl_functions[] = { PHP_FE( grapheme_stristr, grapheme_strstr_args ) PHP_FE( grapheme_extract, grapheme_extract_args ) + /* IDN functions */ + PHP_FE(idn_to_ascii, arginfo_idn_to_ascii) + PHP_FALIAS(idn_to_utf8, idn_to_unicode, arginfo_idn_to_ascii) + PHP_FE(idn_to_unicode, arginfo_idn_to_ascii) + /* common functions */ PHP_FE( intl_get_error_code, intl_0_args ) PHP_FE( intl_get_error_message, intl_0_args ) @@ -384,7 +404,7 @@ zend_function_entry intl_functions[] = { /* {{{ INI Settings */ PHP_INI_BEGIN() STD_PHP_INI_ENTRY(LOCALE_INI_NAME, NULL, PHP_INI_ALL, OnUpdateStringUnempty, default_locale, zend_intl_globals, intl_globals) - + STD_PHP_INI_ENTRY("intl.error_level", "0", PHP_INI_ALL, OnUpdateLong, error_level, zend_intl_globals, intl_globals) PHP_INI_END() /* }}} */ @@ -461,6 +481,9 @@ PHP_MINIT_FUNCTION( intl ) grapheme_register_constants( INIT_FUNC_ARGS_PASSTHRU ); + /* Expose IDN constants to PHP scripts. */ + idn_register_constants( INIT_FUNC_ARGS_PASSTHRU ); + /* Expose ICU error codes to PHP scripts. */ intl_expose_icu_error_codes( INIT_FUNC_ARGS_PASSTHRU ); diff --git a/ext/intl/php_intl.h b/ext/intl/php_intl.h index d5302892ec..c6c21a14f0 100755 --- a/ext/intl/php_intl.h +++ b/ext/intl/php_intl.h @@ -45,6 +45,7 @@ ZEND_BEGIN_MODULE_GLOBALS(intl) collator_compare_func_t compare_func; UBreakIterator* grapheme_iterator; intl_error g_error; + long error_level; ZEND_END_MODULE_GLOBALS(intl) /* Macro to access request-wide global variables. */ diff --git a/ext/intl/tests/idn.phpt b/ext/intl/tests/idn.phpt new file mode 100755 index 0000000000..8911b2b6f2 --- /dev/null +++ b/ext/intl/tests/idn.phpt @@ -0,0 +1,22 @@ +--TEST-- +IDN +--INI-- +unicode.runtime_encoding="utf-8" +--SKIPIF-- + +--FILE-- + +--EXPECT-- +xn--tst-qla.de +t%C3%A4st.de +t%C3%A4st.de \ No newline at end of file