1LibIDN(3) User Contributed Perl Documentation LibIDN(3)
2
3
4
6 Net::LibIDN - Perl bindings for GNU Libidn
7
9 use Net::LibIDN ':all';
10
11 idn_to_ascii("Räksmörgås.Josefßon.ORG") eq
12 idn_to_ascii(idn_to_unicode("xn--rksmrgs-5wao1o.josefsson.org"));
13
14 idn_prep_name("LibÜDN") eq "libüdn";
15
16 idn_punycode_encode("kistenmöhre") eq
17 idn_punycode_encode(idn_punycode_decode("kistenmhre-kcb"));
18
19 my $errpos;
20 tld_check("mèrle.se", $errpos) eq undef;
21 $errpos == 1;
22
23 tld_get("mainbase.mars") eq "mars";
24
25 my $hashref = Net::LibIDN::tld_get_table("de");
26
27 print "$hashref->{version}\n";
28 foreach (@{$hashref->{valid}})
29 {
30 print "Unicode range from ".$_->{start}." to ".$_->{end}."\n";
31 }
32
34 Provides bindings for GNU Libidn, a C library for handling
35 Internationalized Domain Names according to IDNA (RFC 3490), in a way
36 very much inspired by Turbo Fredriksson's PHP-IDN.
37
38 Functions
39 Net::LibIDN::idn_to_ascii($clear_hostname, [$charset, [$flags]]);
40 Converts $clear_hostname which might contain characters outside the
41 range allowed in DNS names, to IDNA ACE. If $charset is specified,
42 treats string as being encoded in it, otherwise assumes it is
43 ISO-8859-1 encoded. If flag IDNA_ALLOW_UNASSIGNED is set in $flags,
44 accepts also unassigned Unicode characters, if
45 IDNA_USE_STD3_ASCII_RULES is set, accepts only ASCII LDH characters
46 (letter-digit-hyphen). Flags can be combined with ||. Returns
47 result of conversion or undef on error.
48
49 Net::LibIDN::idn_to_unicode($idn_hostname, [$charset, [$flags]]);
50 Converts ASCII $idn_hostname, which might be IDNA ACE encoded, into
51 the decoded form in $charset or ISO-8859-1. Flags are interpreted
52 as above. Returns result of conversion or undef on error.
53
54 Net::LibIDN::idn_punycode_encode($string, [$charset]);
55 Encodes $string into "punycode" (RFC 3492). If $charset is present,
56 treats $string as being in $charset, otherwise uses ISO-8859-1.
57 Returns result of conversion or undef on error.
58
59 Net::LibIDN::idn_punycode_decode($string, [$charset]);
60 Decodes $string from "punycode" (RFC 3492). If $charset is present,
61 result is converted to $charset, otherwise it is converted to
62 ISO-8859-1. Returns result of conversion or undef on error.
63
64 Net::LibIDN::idn_prep_name($string, [$charset]);
65 Net::LibIDN::idn_prep_kerberos5($string, [$charset]);
66 Net::LibIDN::idn_prep_node($string, [$charset]);
67 Net::LibIDN::idn_prep_resource($string, [$charset]);
68 Net::LibIDN::idn_prep_plain($string, [$charset]);
69 Net::LibIDN::idn_prep_trace($string, [$charset]);
70 Net::LibIDN::idn_prep_sasl($string, [$charset]);
71 Net::LibIDN::idn_prep_iscsi($string, [$charset]);
72 Performs "stringprep" (RFC 3454) on $string according to the named
73 profile (e.g. *_name -> "nameprep" (RFC 3491)). If $charset is
74 present, converts from and to this charset before and after the
75 operation respectively. Returns result string, or undef on error.
76
77 Net::LibIDN::tdl_check($string, $errpos, [$charset, [$tld]]);
78 Checks whether or not $string conforms to the restrictions on the
79 sets of valid characters defined by TLD authorities around the
80 World. Treats $string as a hostname if $tld is not present,
81 determining the TLD from the hostname. If $tld is present, uses the
82 restrictions defined by the parties responsible for TLD $tld.
83 $charset may be used to specify the character set the $string is
84 in. Should an invalid character be detected, returns 0 and the
85 0-based position of the offending character in $errpos. In case of
86 other failure conditions, $errpos is not touched, and undef is
87 returned. Should $string conform to the TLD restrictions, 1 is
88 returned.
89
90 Net::LibIDN::tld_get($hostname);
91 Returns top level domain of $hostname, or undef if an error occurs
92 or if no top level domain was found.
93
94 Net::LibIDN::tld_get_table($tld);
95 Retrieves a hash reference with the TLD restriction info of given
96 TLD $tld, or undef if $tld is not found. The hash ref contains the
97 following fields:
98
99 · $h->{name} ... name of TLD
100
101 · $h->{version} ... version string of this restriction table
102
103 · $h->{nvalid} ... number of Unicode intervals
104
105 · $h->{valid} ... [ {start => number, end => number}, ...] ...
106 Unicode intervals
107
108 Limitations
109 There is currently no support for Perl's unicode capabilities (man
110 perlunicode). All input strings are assumed to be octet strings, all
111 output strings are generated as octet strings. Thus, if you require
112 Perl's unicode features, you will have to convert your strings
113 manually. For example:
114
115 use Encode;
116
117 use Data::Dumper;
118
119 print Dumper(Net::LibIDN::idn_to_unicode('xn--uro-j50a.com',
120 'utf-8'));
121
122 print Dumper(decode('utf-8',
123 Net::LibIDN::idn_to_unicode('xn--uro-j50a.com', 'utf-8')));
124
126 Thomas Jacob, http://internet24.de
127
129 perl(1), RFC 3454, RFC 3490-3492, http://www.gnu.org/software/libidn.
130
131
132
133perl v5.30.1 2020-01-30 LibIDN(3)