]> granicus.if.org Git - php/commitdiff
- merge errors support
authorStanislav Malyshev <stas@php.net>
Mon, 6 Jul 2009 23:44:16 +0000 (23:44 +0000)
committerStanislav Malyshev <stas@php.net>
Mon, 6 Jul 2009 23:44:16 +0000 (23:44 +0000)
- merge IDN

ext/intl/config.m4
ext/intl/config.w32
ext/intl/idn/idn.c [new file with mode: 0644]
ext/intl/idn/idn.h [new file with mode: 0644]
ext/intl/intl_error.c
ext/intl/php_intl.c
ext/intl/php_intl.h
ext/intl/tests/idn.phpt [new file with mode: 0755]

index 05de6fd9b508664b639eca26eda56f4fdbfd68dd..00aeceb468cae264759c6bba168262621f828457 100755 (executable)
@@ -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])
index 4ae35e5f68778cac046f5e99acca1e9e14b5c139..46a06f62839da8836e3f5397d73c8eacb69873c4 100755 (executable)
@@ -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 (file)
index 0000000..b4aa9a0
--- /dev/null
@@ -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 <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
+ */
diff --git a/ext/intl/idn/idn.h b/ext/intl/idn/idn.h
new file mode 100644 (file)
index 0000000..ad43f0e
--- /dev/null
@@ -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 <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 */
index fd105e9296ec352445dc4d40ee5b9a2413b826c2..4e55d956df99c5708335f13ea01a9834395477b0 100755 (executable)
@@ -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;
 
index f46c70f3203836df6e300ea5d7e14b8b850dcc03..fe6fd25725f02ecab28e949ef8f1197607cfa302 100755 (executable)
@@ -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_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 );
 
index d5302892ecc8c1cb3940ffcd27d99ad774af75e0..c6c21a14f06580acb304adf8c45b027dbcad6acd 100755 (executable)
@@ -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 (executable)
index 0000000..8911b2b
--- /dev/null
@@ -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