1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
|
# $Id: ResConf.pm,v 1.41 2002/02/28 04:25:29 m-kasahr Exp $
#
# Copyright (c) 2001 Japan Network Information Center. All rights reserved.
#
# By using this file, you agree to the terms and conditions set forth bellow.
#
# LICENSE TERMS AND CONDITIONS
#
# The following License Terms and Conditions apply, unless a different
# license is obtained from Japan Network Information Center ("JPNIC"),
# a Japanese association, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
# Tokyo, Japan.
#
# 1. Use, Modification and Redistribution (including distribution of any
# modified or derived work) in source and/or binary forms is permitted
# under this License Terms and Conditions.
#
# 2. Redistribution of source code must retain the copyright notices as they
# appear in each source code file, this License Terms and Conditions.
#
# 3. Redistribution in binary form must reproduce the Copyright Notice,
# this License Terms and Conditions, in the documentation and/or other
# materials provided with the distribution. For the purposes of binary
# distribution the "Copyright Notice" refers to the following language:
# "Copyright (c) Japan Network Information Center. All rights reserved."
#
# 4. Neither the name of JPNIC may be used to endorse or promote products
# derived from this Software without specific prior written approval of
# JPNIC.
#
# 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
#
# 6. Indemnification by Licensee
# Any person or entities using and/or redistributing this Software under
# this License Terms and Conditions shall defend indemnify and hold
# harmless JPNIC from and against any and all judgements damages,
# expenses, settlement liabilities, cost and other liabilities of any
# kind as a result of use and redistribution of this Software or any
# claim, suite, action, litigation or proceeding by any third party
# arising out of or relates to this License Terms and Conditions.
#
# 7. Governing Law, Jurisdiction and Venue
# This License Terms and Conditions shall be governed by and and
# construed in accordance with the law of Japan. Any person or entities
# using and/or redistributing this Software under this License Terms and
# Conditions hereby agrees and consent to the personal and exclusive
# jurisdiction and venue of Tokyo District Court of Japan.
#
package MDN::ResConf;
use strict;
use Carp;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD);
require Exporter;
require DynaLoader;
@ISA = qw(Exporter DynaLoader);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
@EXPORT = qw();
$VERSION = '2.4';
bootstrap MDN::ResConf $VERSION;
# Preloaded methods go here.
# Autoload methods go after =cut, and are processed by the autosplit program.
sub local_to_utf8 {
my ($self, $from) = @_;
return $self->nameconv('l', $from);
}
sub utf8_to_local {
my ($self, $from) = @_;
return $self->nameconv('L', $from);
}
sub delimiter_map {
my ($self, $from) = @_;
return $self->nameconv('d', $from);
}
sub local_map {
my ($self, $from) = @_;
return $self->nameconv('M', $from);
}
sub map {
my ($self, $from) = @_;
return $self->nameconv('m', $from);
}
sub normalize {
my ($self, $from) = @_;
return $self->nameconv('n', $from);
}
sub prohibit_check {
my ($self, $from) = @_;
return $self->nameconv('p', $from);
}
sub nameprep {
my ($self, $from) = @_;
return $self->nameconv('N', $from);
}
sub nameprep_check {
my ($self, $from) = @_;
return $self->nameconv('!N', $from);
}
sub unassigned_check {
my ($self, $from) = @_;
return $self->nameconv('u', $from);
}
sub utf8_to_idn {
my ($self, $from) = @_;
return $self->nameconv('I', $from);
}
sub idn_to_utf8 {
my ($self, $from) = @_;
return $self->nameconv('i', $from);
}
sub local_to_idn {
my ($self, $from) = @_;
return $self->nameconv('ldMNI', $from);
}
sub idn_to_local {
my ($self, $from) = @_;
return $self->nameconv('i!NL', $from);
}
1;
__END__
=head1 NAME
MDN::ResConf - Perl interface to domain name conversion methods of libmdn
=head1 SYNOPSIS
use MDN::ResConf;
$res = MDN::ResConf->new();
$res->load_file('/usr/local/etc/mdn.conf');
$idn_domain_name = $res->local_to_idn($local_domain_name);
$local_domain_name = $res->idn_to_local($idn_domain_name);
=head1 DESCRIPTION
C<MDN::ResConf> provides a Perl object interface to domain name
conversion methods of libmdn, the multilingual domain name library
included in the mDNkit.
This module provides low-level conversion interface to the library.
=head1 CONSTRUCTOR
=over 4
=item new
Creates an object.
It returns C<undef> if no enough memory is remained.
=back
=head1 METHODS
=over 4
=item load_file([$filename])
Loads a configuration file.
If C<$filename> is omitted, the default file
(e.g. F</usr/local/etc/mdn.conf>) is loaded.
=item set_local_encoding([$encoding [, @options]])
Sets local encoding.
If no encoding name is specified, the library determines it using locale
information.
The library currently understands two options,
C<'delayedopen'> and C<'rtcheck'>.
C<'delayedopen'> delays opening the internal I<iconv> converter until
the conversion is actually performed.
C<'rtcheck'> enables round trip check, which is to ensure that the
conversion is correctly performed.
The method returns 1 upon success, C<undef> otherwise.
=item set_idn_encoding($encoding [, @options])
Sets IDN encoding name (e.g. C<'AMC-ACE-Z'>).
The meaning of C<@options> is the same as that of C<set_local_encoding>.
This method corresponds with C<idn-encoding> entry in libmdn
configuration file.
It returns 1 upon success, C<undef> otherwise.
=item set_nameprep_version($version)
Sets NAMEPREP version (e.g. C<'nameprep-07'>).
This method corresponds with C<nameprep> entry in libmdn
configuration file.
It returns 1 upon success, C<undef> otherwise.
=item add_delimiter_map(@ucs)
Recoginzes specified UCS code points (e.g. C<0x3002>) as domain name
delimiter.
This method corresponds with C<delimiter-map> entry in libmdn
configuration file.
It returns 1 upon success, C<undef> otherwise.
=item add_local_map($tld, @names)
Add elements in C<@names> (e.g. C<'filemap:/some/where'>) to
a list of local mapping schemes for the top level domain C<$tld>
(e.g. C<'jp'>).
This method corresponds with C<local-map> entry in libmdn
configuration file.
It returns 1 upon success, C<undef> otherwise.
=item add_nameprep_map(@names)
Add elements in C<@names> (e.g. C<'nameprep-07'>) to a list of
NAMEPREP mapping schemes.
This method corresponds with C<nameprep-map> entry in libmdn
configuration file.
It returns 1 upon success, C<undef> otherwise.
=item add_nameprep_normalize(@names)
Add elements in C<@names> (e.g. C<'unicode-form-kc'>) to a list of
NAMEPREP normalization schemes.
This method corresponds with C<nameprep-normalize> entry in libmdn
configuration file.
It returns 1 upon success, C<undef> otherwise.
=item add_nameprep_prohibit(@names)
Add elements in C<@names> (e.g. C<'fileset:/some/where'>) to a list
of NAMEPREP prohibited-character check schemes.
This method corresponds with C<nameprep-prohibit> entry in libmdn
configuration file.
It returns 1 upon success, C<undef> otherwise.
=item add_nameprep_unassigned(@names)
Add elements in C<@names> (e.g. C<'nameprep-07'>) to a list of NAMEPREP
unassigned-codepoint check schemes.
This method corresponds with C<nameprep-unassigned> entry in libmdn
configuration file.
It returns 1 upon success, C<undef> otherwise.
=item unset_local_encoding()
Unsets local encoding name, set by C<set_local_encoding> method.
=item unset_idn_encoding()
Unsets IDN encoding name, set by C<set_idn_encoding> method
or C<idn-encoding> entry in the loaded configuration file.
=item unset_nameprep_version()
Unsets NAMEPREP version, set by C<set_nameprep_version> method
or C<nameprep> entry in the loaded configuration file.
This methods unsets all of the NAMEPREP mapping, normalization,
prohibited-character check and unassigned-codepoint check schemes,
registered in the object. Therefore,
$res->unset_nameprep_version();
is equivalent to the following codes:
$res->unset_nameprep_map();
$res->unset_nameprep_normalize();
$res->unset_nameprep_prohibit();
$res->unset_nameprep_unassigned();
=item unset_delimiter_map()
Unset delimiters, registered by C<add_delimiter_map> method
or C<delimiter-map> entries in the loaded configuration file.
=item unset_local_map()
Unsets local mapping schemes, registered by C<add_local_map> method
or C<local-map> entries in the loaded configuration file.
=item unset_nameprep_map()
Unsets NAMEPREP mapping schemes, registered by C<add_nameprep_map> method
or C<nameprep-map> entries in the loaded configuration file.
=item unset_nameprep_normalize()
Unsets NAMEPREP normalization schemes,
registered by C<add_nameprep_normalize> method
or C<nameprep-normalize> entries in the loaded configuration file.
=item unset_nameprep_prohibit()
Unsets NAMEPREP prohibited-codepoint check schemes,
registered by C<add_nameprep_prohibit> method
or C<nameprep-prohibit> entries in the loaded configuration file.
=item unset_nameprep_unassigned()
Unsets NAMEPREP unassigned-codepoint check schemes,
set by C<add_nameprep_unassigned> method
or C<nameprep-unassigned> entries in the loaded configuration file.
=item nameconv($instructions, $from)
Converts a domain name C<$from> according with C<$instructions>, and
returns the result.
Similer to C<pack> and C<unpack>, C<$instructions> is a sequence of
characters listed below:
l convert the local encoding to UTF-8.
L convert the UTF-8 to the local encoding.
d covnert local delimiters to periods ('.').
M perfrom local mapping.
m perform the NAMEPREP mapping.
n perform NAMEPREP normalization.
p check whether the string contains NAMEPREP prohibited
character.
u check whether the string contains NAMEPREP unassigned
codepoint.
N perform NAMEPREP (equivalent to 'mnpu').
I convert the UTF-8 string to ACE.
i convert the ACE string to UTF-8.
!m inspect if NAMEPREP mapping has been performed to the
string. If hasn't, convert the string to ACE.
!n inspect if NAMEPREP normalizaion has been performed
to the string. If hasn't, convert the string to ACE.
!p search the string for NAMEPREP prohibited character.
If found, convert the string to ACE.
!u search the string for NAMEPREP unassigned codepoint.
If found, convert the string to ACE.
!N inspect if NAMEPREP has been performed to the string.
If hasn't, convert the string to ACE. (equivalent to
`!m!n!p!u').
The characters in C<$instructions> are applied left to right.
=item enable($on_off)
Enable or disable mulitilingual domain name support provided by
libmdn.
If C<$on_off> is zero, the support is disabled, otherwise enabled.
If this method has not been called, the C<MDN_DISABLE> environment
variabe is used to determine whether mulitilingual domain name
support is enabled.
The support is disabled if that variable is defined,
In disabled condition, conversion methods (e.g. C<nameconv()>)
simply return a copy of input string as the result of conversion.
=item local_to_utf8($from)
Is equivalent to C<nameconv('l', $from)>.
=item utf8_to_local($from)
Is equivalent to C<nameconv('L', $from)>.
=item delimiter_map($from)
Is equivalent to C<nameconv('d', $from)>.
=item local_map($from)
Is equivalent to C<nameconv('M', $from)>.
=item map($from)
Is equivalent to C<nameconv('m', $from)>.
=item normalize($from)
Is equivalent to C<nameconv('n', $from)>.
=item prohibit_check($from)
Is equivalent to C<nameconv('p', $from)>.
=item unassigned_check($from)
Is equivalent to C<nameconv('u', $from)>.
=item nameprep($from)
Is equivalent to C<nameconv('N', $from)>.
=item nameprep_check($from)
Is equivalent to C<nameconv('!N', $from)>.
=item utf8_to_idn($from)
Is equivalent to C<nameconv('I', $from)>.
=item idn_to_utf8($from)
Is equivalent to C<nameconv('i', $from)>.
=item local_to_idn($from)
Is equivalent to C<nameconv('ldMNI', $from)>.
=item idn_to_local($from)
Is equivalent to C<nameconv('i!NL', $from)>.
=back
=head1 CLASS METHOD
=over 4
=item lasterror()
Returns the error message string corresponding to the last error occurred
in this module.
=back
=head1 COMPATIBILITY
Beginning with version 2.4, the instructions C<'N'> and C<'!N'> of
the C<nameconv()> method also perform unassigned codepoint check.
=head1 ISSUE OF HANDLING UNICODE CHARACTERS
See the ``ISSUE OF HANDLING UNICODE CHARACTERS'' section in
L<MDN::UTF8>.
=head1 SEE ALSO
L<mdn.conf(5)>, L<MDN::API>, L<MDN::UTF8>
MDN library specification
=cut
|