stas Mon Jul 6 23:44:16 2009 UTC Modified files: /php-src/ext/intl config.m4 config.w32 intl_error.c php_intl.c php_intl.h /php-src/ext/intl/idn idn.c idn.h /php-src/ext/intl/tests idn.phpt Log: - merge errors support - merge IDN
http://cvs.php.net/viewvc.cgi/php-src/ext/intl/config.m4?r1=1.3&r2=1.4&diff_format=u Index: php-src/ext/intl/config.m4 diff -u php-src/ext/intl/config.m4:1.3 php-src/ext/intl/config.m4:1.4 --- php-src/ext/intl/config.m4:1.3 Mon Jul 21 08:38:39 2008 +++ php-src/ext/intl/config.m4 Mon Jul 6 23:44:16 2009 @@ -45,7 +45,8 @@ 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]) http://cvs.php.net/viewvc.cgi/php-src/ext/intl/config.w32?r1=1.2&r2=1.3&diff_format=u Index: php-src/ext/intl/config.w32 diff -u php-src/ext/intl/config.w32:1.2 php-src/ext/intl/config.w32:1.3 --- php-src/ext/intl/config.w32:1.2 Mon Jul 7 23:42:29 2008 +++ php-src/ext/intl/config.w32 Mon Jul 6 23:44:16 2009 @@ -1,4 +1,4 @@ -// $Id: config.w32,v 1.2 2008/07/07 23:42:29 stas Exp $ +// $Id: config.w32,v 1.3 2009/07/06 23:44:16 stas Exp $ // vim:ft=javascript ARG_ENABLE("intl", "Enable internationalization support", "no"); @@ -55,6 +55,9 @@ 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"); http://cvs.php.net/viewvc.cgi/php-src/ext/intl/intl_error.c?r1=1.5&r2=1.6&diff_format=u Index: php-src/ext/intl/intl_error.c diff -u php-src/ext/intl/intl_error.c:1.5 php-src/ext/intl/intl_error.c:1.6 --- php-src/ext/intl/intl_error.c:1.5 Sun May 10 21:01:38 2009 +++ php-src/ext/intl/intl_error.c Mon Jul 6 23:44:16 2009 @@ -103,6 +103,9 @@ 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; http://cvs.php.net/viewvc.cgi/php-src/ext/intl/php_intl.c?r1=1.9&r2=1.10&diff_format=u Index: php-src/ext/intl/php_intl.c diff -u php-src/ext/intl/php_intl.c:1.9 php-src/ext/intl/php_intl.c:1.10 --- php-src/ext/intl/php_intl.c:1.9 Tue Mar 10 23:39:22 2009 +++ php-src/ext/intl/php_intl.c Mon Jul 6 23:44:16 2009 @@ -53,6 +53,9 @@ #include "locale/locale.h" #include "locale/locale_class.h" #include "locale/locale_methods.h" + +#include "idn/idn.h" + #include <unicode/uloc.h> #include "php_ini.h" @@ -284,6 +287,18 @@ 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 @@ 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 @@ 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 @@ /* {{{ 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 @@ 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 ); http://cvs.php.net/viewvc.cgi/php-src/ext/intl/php_intl.h?r1=1.3&r2=1.4&diff_format=u Index: php-src/ext/intl/php_intl.h diff -u php-src/ext/intl/php_intl.h:1.3 php-src/ext/intl/php_intl.h:1.4 --- php-src/ext/intl/php_intl.h:1.3 Tue Mar 10 23:39:22 2009 +++ php-src/ext/intl/php_intl.h Mon Jul 6 23:44:16 2009 @@ -45,6 +45,7 @@ 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. */ http://cvs.php.net/viewvc.cgi/php-src/ext/intl/idn/idn.c?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/intl/idn/idn.c diff -u /dev/null php-src/ext/intl/idn/idn.c:1.2 --- /dev/null Mon Jul 6 23:44:16 2009 +++ php-src/ext/intl/idn/idn.c Mon Jul 6 23:44:16 2009 @@ -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 | + | lice...@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Pierre A. Joye <pie...@php.net> | + +----------------------------------------------------------------------+ + */ +/* $Id: idn.c,v 1.2 2009/07/06 23:44:16 stas Exp $ */ + +/* {{{ includes */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <php.h> + +#include <unicode/uidna.h> +#include <unicode/ustring.h> +#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 + */ http://cvs.php.net/viewvc.cgi/php-src/ext/intl/idn/idn.h?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/intl/idn/idn.h diff -u /dev/null php-src/ext/intl/idn/idn.h:1.2 --- /dev/null Mon Jul 6 23:44:16 2009 +++ php-src/ext/intl/idn/idn.h Mon Jul 6 23:44:16 2009 @@ -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 | + | lice...@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Pierre A. Joye <pie...@php.net> | + +----------------------------------------------------------------------+ + */ +/* $Id: idn.h,v 1.2 2009/07/06 23:44:16 stas Exp $ s*/ + +#ifndef IDN_IDN_H +#define IDN_IDN_H + +#include <php.h> + +PHP_FUNCTION(idn_to_ascii); +PHP_FUNCTION(idn_to_unicode); + +void idn_register_constants(INIT_FUNC_ARGS); + +#endif /* IDN_IDN_H */ http://cvs.php.net/viewvc.cgi/php-src/ext/intl/tests/idn.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/intl/tests/idn.phpt diff -u /dev/null php-src/ext/intl/tests/idn.phpt:1.2 --- /dev/null Mon Jul 6 23:44:16 2009 +++ php-src/ext/intl/tests/idn.phpt Mon Jul 6 23:44:16 2009 @@ -0,0 +1,22 @@ +--TEST-- +IDN +--INI-- +unicode.runtime_encoding="utf-8" +--SKIPIF-- +<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?> +--FILE-- +<?php + +/* + * Test IDN functions (procedural only) + */ + +echo idn_to_ascii(b"t\xC3\xA4st.de")."\n"; +echo urlencode((binary)idn_to_unicode('xn--tst-qla.de'))."\n"; +echo urlencode((binary)idn_to_utf8('xn--tst-qla.de'))."\n"; + +?> +--EXPECT-- +xn--tst-qla.de +t%C3%A4st.de +t%C3%A4st.de \ No newline at end of file
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php