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])
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");
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | 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 <pierre@php.net> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id$ */
+
+/* {{{ 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
+ */
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | 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 <pierre@php.net> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id$ 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 */
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;
#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"
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[]
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 )
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 )
/* {{{ 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()
/* }}} */
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 );
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. */
--- /dev/null
+--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