summaryrefslogtreecommitdiffstats
path: root/contrib/idn/idnkit-1.0-src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/idn/idnkit-1.0-src/tools')
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/Makefile.in65
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/idnconv/Makefile.in116
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/idnconv/idnconv.1373
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/idnconv/idnconv.c803
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/idnconv/idnslookup.in116
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/idnconv/make.wnt72
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/idnconv/selectiveencode.c127
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/idnconv/selectiveencode.h70
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/idnconv/util.c554
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/idnconv/util.h96
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/make.wnt57
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/rpm/idnkit.spec142
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/runidn/Makefile.in167
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/runidn/resolver.c1056
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/runidn/resolver.h70
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/runidn/runidn.1151
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/runidn/runidn.in109
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/runidn/stub.c387
-rw-r--r--contrib/idn/idnkit-1.0-src/tools/runidn/stub.h94
19 files changed, 4625 insertions, 0 deletions
diff --git a/contrib/idn/idnkit-1.0-src/tools/Makefile.in b/contrib/idn/idnkit-1.0-src/tools/Makefile.in
new file mode 100644
index 0000000..108bf24
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/Makefile.in
@@ -0,0 +1,65 @@
+# $Id: Makefile.in,v 1.1.1.1 2003/06/04 00:27:05 marka Exp $
+# Copyright (c) 2000 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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+# Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+#
+# 4. The name of JPNIC may not 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.
+
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+SUBDIRS = idnconv runidn
+
+SHELL = @SHELL@
+
+all: all-subdirs
+install: install-subdirs
+clean: clean-subdirs
+distclean: distclean-localdir distclean-subdirs
+test check: test-subdirs
+
+all-subdirs install-subdirs clean-subdirs distclean-subdirs test-subdirs:
+ @target=`echo $@ | sed 's/-subdirs$$//'`; \
+ for d in $(SUBDIRS); do \
+ (cd $$d; $(MAKE) DESTDIR=$(DESTDIR) $$target); \
+ done
+
+distclean-localdir:
+ rm -f Makefile
diff --git a/contrib/idn/idnkit-1.0-src/tools/idnconv/Makefile.in b/contrib/idn/idnkit-1.0-src/tools/idnconv/Makefile.in
new file mode 100644
index 0000000..671c2c0
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/idnconv/Makefile.in
@@ -0,0 +1,116 @@
+# $Id: Makefile.in,v 1.1.1.1 2003/06/04 00:27:05 marka Exp $
+# Copyright (c) 2000, 2002 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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+# Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+#
+# 4. The name of JPNIC may not 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.
+
+top_builddir = ../..
+
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+bindir = @bindir@
+mandir = @mandir@
+man1dir = $(mandir)/man1
+
+CC = @CC@
+RANLIB = @RANLIB@
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_DATA = @INSTALL_DATA@
+MKINSTALLDIRS = @top_srcdir@/mkinstalldirs
+SHELL = @SHELL@
+LIBTOOL = @LIBTOOL@
+
+ICONVINC = @ICONVINC@
+ICONVLIB = @ICONVLIB@
+IDNLIB = ../../lib/libidnkit.la
+
+INCS = -I$(srcdir) -I$(srcdir)/../../include -I../../include $(ICONVINC)
+DEFS =
+
+CFLAGS = $(INCS) $(DEFS) @CPPFLAGS@ @CFLAGS@
+LDFLAGS = @LDFLAGS@
+
+SRCS = idnconv.c util.c selectiveencode.c
+OBJS = idnconv.o util.o selectiveencode.o
+
+@LITEONLY_TRUE@all:
+@LITEONLY_FALSE@all: idnconv idnslookup idnconv.1
+
+idnconv: $(OBJS) $(IDNLIB)
+ $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ \
+ $(OBJS) $(IDNLIB) $(ICONVLIB)
+
+idnslookup: $(srcdir)/idnslookup.in
+ sed -e 's%[@]bindir[@]%$(bindir)%' $(srcdir)/idnslookup.in > idnslookup
+ chmod 0755 idnslookup
+
+@LITEONLY_TRUE@install:
+@LITEONLY_FALSE@@COMPAT_TRUE@install: all install-nolite install-compat
+@LITEONLY_FALSE@@COMPAT_FALSE@install: all install-nolite
+
+install-nolite:
+ $(MKINSTALLDIRS) $(DESTDIR)$(bindir)
+ $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) idnconv \
+ $(DESTDIR)$(bindir)/idnconv
+ $(MKINSTALLDIRS) $(DESTDIR)$(man1dir)
+ $(INSTALL_DATA) $(srcdir)/idnconv.1 $(DESTDIR)$(man1dir)/idnconv.1
+
+install-compat:
+ src=$(DESTDIR)$(bindir)/idnconv; \
+ dst=$(DESTDIR)$(bindir)/mdnconv; \
+ rm -f $$dst; \
+ ln $$src $$dst || cp $$src $$dst
+ src=$(DESTDIR)$(man1dir)/idnconv.1; \
+ dst=$(DESTDIR)$(man1dir)/mdnconv.1; \
+ rm -f $$dst; \
+ ln $$src $$dst || cp $$src $$dst
+
+clean:
+ rm -f *.o idnconv idnslookup *.core core *~
+ rm -fr .libs/
+
+distclean: clean
+ rm -f Makefile
+
+test check:
diff --git a/contrib/idn/idnkit-1.0-src/tools/idnconv/idnconv.1 b/contrib/idn/idnkit-1.0-src/tools/idnconv/idnconv.1
new file mode 100644
index 0000000..5e7551e
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/idnconv/idnconv.1
@@ -0,0 +1,373 @@
+.\" $Id: idnconv.1,v 1.1.1.1 2003/06/04 00:27:10 marka Exp $
+.\"
+.\" Copyright (c) 2000,2001,2002 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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+.\" Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+.\"
+.\" 4. The name of JPNIC may not 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.
+.\"
+.TH IDNCONV 1 "Mar 3, 2001"
+.\"
+.SH NAME
+idnconv \- codeset converter for named.conf and zone master files
+.\"
+.SH SYNOPSIS
+\fBidnconv\fP [\fIoptions..\fP] [\fIfile\fP...]
+.\"
+.SH DESCRIPTION
+\fBidnconv\fR is a codeset converter for named configuration files
+and zone master files.
+\fBidnconv\fR performs codeset conversion specified either
+by the command-line arguments or by the configuration file,
+and writes the converted text to stdout.
+.PP
+If file name is specified, \fBidnconv\fR converts the contents of
+the file.
+Otherwise, \fBidnconv\fR converts \fIstdin\fR.
+.PP
+Since \fBidnconv\fR is specifically designed for converting
+internatinalized domain names, it may not be suitable as a general
+codeset converter.
+.\"
+.SH "OPERATION MODES"
+\fBidnconv\fR has two operation modes.
+.PP
+One is a mode to convert local-encoded domain names to IDN-encoded
+one. Usually this mode is used for preparing domain names to be
+listed in named configuration files or zone master files.
+In this mode, the following processes are performed in addition to
+the codeset (encoding) conversion.
+.RS 2
+.IP \- 2
+local mapping
+.IP \- 2
+standard domain name preperation (NAMEPREP)
+.RE
+.PP
+The other mode is a reverse conversion, from IDN-encoded domain name to
+local-encoded domain names.
+In this mode, local mapping and NAMEPREP are not performed since
+IDN-encoded names should already be normalized.
+Instead, a check is done in order to make sure the IDN-encoded domain name
+is properly NAMEPREP'ed. If it is not, the name will be output in
+IDN encoding, not in the local encoding.
+.\"
+.SH OPTIONS
+Normally \fBidnconv\fR reads system's default configuration file
+(idn.conf) and performs conversion or name preparation according to
+the parameters specified in the file.
+You can override the setting in the configuration file by various
+command line options below.
+.TP 4
+\fB\-in\fP \fIin-code\fP, \fB\-i\fP \fIin-code\fP
+Specify the codeset name of the input text.
+Any of the following codeset names can be specified.
+.RS 4
+.IP "\(bu" 2
+Any codeset names which \fIiconv_open()\fP library function accepts
+.IP "\(bu" 2
+\f(CWPunycode\fR
+.IP "\(bu" 2
+\f(CWUTF-8\fR
+.IP "\(bu" 2
+Any alias names for the above, defined by the codeset alias file.
+.RE
+.IP "" 4
+If this option is not specified, the default codeset is determined
+from the locale in normal conversion mode.
+In reverse conversion mode, the default codeset is the IDN encoding
+specified by the configuration file (``idn-encoding'' entry).
+.TP 4
+\fB\-out\fP \fIout-code\fP, \fB\-o\fP \fIout-code\fP
+Specify the codeset name of the output text. \fIout-code\fP can be any
+codeset name that can be specified for \fB\-in\fR option.
+.IP "" 4
+If this option is not specified, the default is the IDN encoding
+specified by the configuration file (``idn-encoding'' entry) in
+normal conversion mode.
+In reverse conversion mode, the default codeset is determined from
+the locale.
+.TP 4
+\fB\-conf\fP \fIpath\fP, \fB\-c\fP \fIpath\fP
+Specify the pathname of idnkit configuration file (``idn.conf'').
+If not specified, system's default file is used, unless \-noconf
+option is specified.
+.TP 4
+\fB\-noconf\fP, \fB\-C\fP
+Specify that no configuration file is to be used.
+.TP 4
+\fB\-reverse\fP, \fB\-r\fP
+Specify reverse conversion mode.
+.br
+If this option is not specified, the normal conversion mode is used.
+.TP 4
+\fB\-nameprep\fR \fIversion\fR, \fB\-n\fR \fIversion\fR
+Specify the version of NAMEPREP.
+The following is a list of currently available versions.
+.RS 4
+.IP \f(CWRFC3491\fR 4
+Perform NAMEPREP according to the RFC3491
+``rfc-3491.txt''.
+.RE
+.TP 4
+\fB\-nonameprep\fR, \fB\-N\fR
+Specify to skip NAMEPREP process (or NAMEPREP verification process
+in the reverse conversion mode).
+This option implies -nounassigncheck and -nobidicheck.
+.TP 4
+\fB\-localmap\fR \fImap\fR
+Specify the name of local mapping rule.
+Currently, following maps are available.
+.RS 4
+.IP \f(CWRFC3491\fR 4
+Use the list of mappings specified by RFC3491.
+.IP \f(CWfilemap:\fR\fIpath\fR 4
+Use list of mappings specified by mapfile \fIpath\fR.
+See idn.conf(5) for the format of a mapfile.
+.RE
+.IP "" 4
+This option can be specified more than once.
+In that case, each mapping will be performed in the order of the
+specification.
+.TP 4
+\fB\-nounassigncheck\fR, \fB\-U\fR
+Skip unassigned codepoint check.
+.TP 4
+\fB\-nobidicheck\fR, \fB\-B\fR
+Skip bidi character check.
+.TP 4
+\fB\-nolengthcheck\fR
+Do not check label length of normal conversion result.
+This option is only meaningful in the normal conversion mode.
+.TP 4
+\fB\-noasciicheck\fR, \fB\-A\fR
+Do not check ASCII range characters.
+This option is only meaningful in the normal conversion mode.
+.TP 4
+\fB\-noroundtripcheck\fR
+Do not perform round trip check.
+This option is only meaningful in the reverse conversion mode.
+.TP 4
+\fB\-delimiter\fR \fIcodepoint\fP
+Specify the character to be mapped to domain name delimiter (period).
+This option can be specified more than once in order to specify multiple
+characters.
+.br
+This option is only meaningful in the normal conversion mode.
+.TP 4
+\fB\-whole\fP, \fB\-w\fP
+Perform local mapping, nameprep and conversion to output codeset for the entire
+input text. If this option is not specified, only non-ASCII characters
+and their surrounding texts will be processed.
+See ``NORAML CONVERSION MECHANISM'' and ``REVERSE CONVERSION MECHANISM''
+for details.
+.TP 4
+\fB\-alias\fP \fIpath\fP, \fB\-a\fP \fIpath\fP
+Specify a codeset alias file. It is a simple text file, where
+each line has a pair of alias name and real name separated by one
+or more white spaces like below:
+.nf
+.ft CW
+
+ \fIalias-codeset-name\fP \fIreal-codeset-name\fP
+
+.ft R
+.fi
+Lines starting with ``#'' are treated as comments.
+.TP 4
+\fB\-flush\fP
+Force line-buffering mode.
+.TP 4
+\fB\-version\fP, \fB\-v\fP
+Print version information and quit.
+.\"
+.SH LOCAL CODESET
+idnconv guesses local codeset from locale and environment variables.
+See the ``LOCAL CODESET'' section in idn.conf(5) for more details.
+.\"
+.SH NORMAL CONVERSION MECHANISM
+\fBidnconv\fR performs conversion line by line.
+Here describes how \fBidnconv\fR does its job for each line.
+.\"
+.IP "1. read a line from input text" 4
+.IP "2. convert the line to UTF-8" 4
+\fBidnconv\fR converts the line from local encoding to UTF-8.
+.IP "3. find internationalized domain names" 4
+If the \-whole\ (or \-w) option is specified, the entire line is
+assumed as an internationalized domain name.
+Otherwise, \fBidnconv\fR recognizes any character sequences having
+the following properties in the line as internationalized domain names.
+.RS 4
+.IP "\(bu" 2
+containing at least one non-ASCII character, and
+.IP "\(bu" 2
+consisting of legal domain name characters (alphabets, digits, hypens),
+non-ASCII characters and period.
+.RE
+.IP "4. convert internationalized domain names to ACE" 4
+For each internationalized domain name found in the line,
+\fBidnconv\fR converts the name to ACE.
+The details about the conversion procedure is:
+.RS 4
+.IP "4.1. delimiter mapping" 4
+Substibute certain characters specified as domain name delimiter
+with period.
+.IP "4.2. local mapping" 4
+Perform local mapping.
+If the local mapping is specified by command line option \-localmap,
+the specified mapping rule is applied. Otherwise, find the mapping rule
+from the configuration file which matches to the TLD of the name,
+and perform mapping according to the matched rule.
+.br
+This step is skipped if the \-nolocalmap (or \-L) option is specified.
+.IP "4.3. NAMEPREP" 4
+Perform name preparation (NAMEPREP).
+Mapping, normalization, prohibited character checking, unassigned
+codepoint checking, bidirectional character checking are done in
+that order.
+If the prohibited character check, unassigned codepoint check, or
+bidi character check fails, the normal conversion procedure aborts.
+.br
+This step is skipped if the \-nonameprep (or \-N) option is specified.
+.IP "4.4. ASCII character checking" 4
+Checks ASCII range character in the domain name.
+the normal conversion procedure aborts, if the domain name has a label
+beginning or end with hyphen (U+002D) or it contains ASCII range character
+except for alphanumeric and hyphen,
+.br
+This step is skipped if the \-noasciicheck (or \-A) option is specified.
+.IP "4.5. ACE conversion" 4
+Convert the string to ACE.
+.IP "4.6. label length checking" 4
+The normal conversion procedure aborts, if the domain name has an empty
+label or too long label (64 characters or more).
+.br
+This step is skipped if the \-nolengthcheck option is specified.
+.RE
+.IP "5. output the result" 4
+.PP
+.\"
+.SH REVERSE CONVERSION MECHANISM
+This is like the normal conversion mechanism, but they are not symmetric.
+\fBidnconv\fR does its job for each line.
+.\"
+.IP "1. read a line from input text" 4
+.IP "2. convert the line to UTF-8" 4
+\fBidnconv\fR converts the line from local encoding to UTF-8.
+.IP "3. find internationalized domain names" 4
+If the \-whole\ (or \-w) option is specified, the entire line is
+assumed as an internationalized domain name.
+Otherwise, \fBidnconv\fR decodes any valid ASCII domain names
+including ACE names in the line.
+.IP "4. convert domain names to local encoding"
+Then, \fBidnconv\fR decodes the domain names.
+The decode procedure consists of the following steps.
+.RS 4
+.IP "4.1. Delimiter mapping" 4
+Substibute certain characters specified as domain name delimiter
+with period.
+.br
+.IP "4.2. NAMEPREP" 4
+Perform name preparation (NAMEPREP) for each label in the domain name.
+Mapping, normalization, prohibited character checking, unassigned
+codepoint checking, bidirectional character checking are done in
+that order.
+If the prohibited character check, unassigned codepoint check, or
+bidi character check fails, disqualified labels are restored to
+original input strings and further conversion on those labels are
+not performed.
+.br
+This step is skipped if the \-nonameprep (or \-N) option is specified.
+.IP "4.3. ACE conversion" 4
+Convert the string from ACE to UTF-8.
+.IP "4.4. Round trip checkning" 4
+For each label, perform the normal conversion and compare it with
+the result of the step 4.2.
+This check succeeds, if they are equivalent strings.
+In case of failure, disqualified labels are restored to original
+input strings and further conversion on those labels are not
+performed.
+.br
+This step is skipped if the \-noroundtripcheck option is specified.
+.IP "4.5. local encoding conversion" 4
+Convert the result of the step 4.3. from UTF-8 to local encoding.
+If a label in the domain name contains a character which cannot be
+represented in the local encoding, the label is restored to the
+original input string.
+.RE
+.IP "5. output the result" 4
+.PP
+.\"
+.SH FILE MANAGEMENT
+Maybe the best way to manage named.conf or zone master files that contains
+internationalized domain name is to keep them in your local codeset so that
+they can be edited with your favorite editor, and generate a version in
+the IDN encoding using \fBidnconv\fP.
+.PP
+`make' is a convenient tool for this purpose.
+Suppose the local codeset version has suffix `.lc', and its ACE version
+has suffix `.ace'. The following Makefile enables you to generate
+ACE version from local codeset version by just typing `make'.
+.RS 4
+.nf
+.ft CW
+
+\&.SUFFIXES: .lc .ace
+\&.lc.ace:
+ idnconv -in $(LOCALCODE) -out $(IDNCODE) \\
+ $(IDNCONVOPT) $< > $@
+
+LOCALCODE = EUC-JP
+IDNCODE = Punycode
+IDNCONVOPT =
+
+DESTFILES = db.zone1.ace db.zone2.ace
+
+all: $(DESTFILES)
+.ft
+.fi
+.RE
+.\"
+.SH SEE ALSO
+idn.conf(5),
+iconv(3)
+.\"
+.SH BUGS
+The automatic input-code selection depends on your system, and sometimes
+it cannot guess or guess wrong. It is better to explicitly specify it
+using \-in option.
diff --git a/contrib/idn/idnkit-1.0-src/tools/idnconv/idnconv.c b/contrib/idn/idnkit-1.0-src/tools/idnconv/idnconv.c
new file mode 100644
index 0000000..a10a738
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/idnconv/idnconv.c
@@ -0,0 +1,803 @@
+#ifndef lint
+static char *rcsid = "$Id: idnconv.c,v 1.1.1.1 2003/06/04 00:27:07 marka Exp $";
+#endif
+
+/*
+ * Copyright (c) 2000,2001,2002 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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+ * Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+ *
+ * 4. The name of JPNIC may not 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.
+ */
+
+/*
+ * idnconv -- Codeset converter for named.conf and zone files
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
+#include <idn/result.h>
+#include <idn/converter.h>
+#include <idn/normalizer.h>
+#include <idn/utf8.h>
+#include <idn/resconf.h>
+#include <idn/res.h>
+#include <idn/util.h>
+#include <idn/version.h>
+
+#include "util.h"
+
+#define MAX_DELIMITER 10
+#define MAX_LOCALMAPPER 10
+#define MAX_MAPPER 10
+#define MAX_NORMALIZER 10
+#define MAX_CHEKER 10
+
+#define FLAG_REVERSE 0x0001
+#define FLAG_DELIMMAP 0x0002
+#define FLAG_LOCALMAP 0x0004
+#define FLAG_MAP 0x0008
+#define FLAG_NORMALIZE 0x0010
+#define FLAG_PROHIBITCHECK 0x0020
+#define FLAG_UNASSIGNCHECK 0x0040
+#define FLAG_BIDICHECK 0x0080
+#define FLAG_ASCIICHECK 0x0100
+#define FLAG_LENGTHCHECK 0x0200
+#define FLAG_ROUNDTRIPCHECK 0x0400
+#define FLAG_SELECTIVE 0x0800
+
+#define FLAG_NAMEPREP \
+ (FLAG_MAP|FLAG_NORMALIZE|FLAG_PROHIBITCHECK|FLAG_UNASSIGNCHECK|\
+ FLAG_BIDICHECK)
+
+#define DEFAULT_FLAGS \
+ (FLAG_LOCALMAP|FLAG_NAMEPREP|FLAG_ASCIICHECK|FLAG_LENGTHCHECK|\
+ FLAG_ROUNDTRIPCHECK|FLAG_SELECTIVE|FLAG_DELIMMAP)
+
+int line_number; /* current input file line number */
+static int flush_every_line = 0; /* pretty obvious */
+
+static int encode_file(idn_resconf_t conf1, idn_resconf_t conf2,
+ FILE *fp, int flags);
+static int decode_file(idn_resconf_t conf1, idn_resconf_t conf2,
+ FILE *fp, int flags);
+static int trim_newline(idnconv_strbuf_t *buf);
+static idn_result_t convert_line(idnconv_strbuf_t *from,
+ idnconv_strbuf_t *to,
+ idn_resconf_t conf,
+ idn_action_t actions, int flags);
+static void print_usage(char *cmd);
+static void print_version(void);
+static unsigned long get_ucs(const char *p);
+
+int
+main(int ac, char **av) {
+ char *cmd = *av;
+ char *cname;
+ unsigned long delimiters[MAX_DELIMITER];
+ char *localmappers[MAX_LOCALMAPPER];
+ char *nameprep_version = NULL;
+ int ndelimiters = 0;
+ int nlocalmappers = 0;
+ char *in_code = NULL;
+ char *out_code = NULL;
+ char *resconf_file = NULL;
+ int no_resconf = 0;
+ char *encoding_alias = NULL;
+ int flags = DEFAULT_FLAGS;
+ FILE *fp;
+ idn_result_t r;
+ idn_resconf_t resconf1, resconf2;
+ idn_converter_t conv;
+ int exit_value;
+
+#ifdef HAVE_SETLOCALE
+ (void)setlocale(LC_ALL, "");
+#endif
+
+ /*
+ * If the command name begins with 'r', reverse mode is assumed.
+ */
+ if ((cname = strrchr(cmd, '/')) != NULL)
+ cname++;
+ else
+ cname = cmd;
+ if (cname[0] == 'r')
+ flags |= FLAG_REVERSE;
+
+ ac--;
+ av++;
+ while (ac > 0 && **av == '-') {
+
+#define OPT_MATCH(opt) (strcmp(*av, opt) == 0)
+#define MUST_HAVE_ARG if (ac < 2) print_usage(cmd)
+#define APPEND_LIST(array, size, item, what) \
+ if (size >= (sizeof(array) / sizeof(array[0]))) { \
+ errormsg("too many " what "\n"); \
+ exit(1); \
+ } \
+ array[size++] = item; \
+ ac--; av++
+
+ if (OPT_MATCH("-in") || OPT_MATCH("-i")) {
+ MUST_HAVE_ARG;
+ in_code = av[1];
+ ac--;
+ av++;
+ } else if (OPT_MATCH("-out") || OPT_MATCH("-o")) {
+ MUST_HAVE_ARG;
+ out_code = av[1];
+ ac--;
+ av++;
+ } else if (OPT_MATCH("-conf") || OPT_MATCH("-c")) {
+ MUST_HAVE_ARG;
+ resconf_file = av[1];
+ ac--;
+ av++;
+ } else if (OPT_MATCH("-nameprep") || OPT_MATCH("-n")) {
+ MUST_HAVE_ARG;
+ nameprep_version = av[1];
+ ac--;
+ av++;
+ } else if (OPT_MATCH("-noconf") || OPT_MATCH("-C")) {
+ no_resconf = 1;
+ } else if (OPT_MATCH("-reverse") || OPT_MATCH("-r")) {
+ flags |= FLAG_REVERSE;
+ } else if (OPT_MATCH("-nolocalmap") || OPT_MATCH("-L")) {
+ flags &= ~FLAG_LOCALMAP;
+ } else if (OPT_MATCH("-nonameprep") || OPT_MATCH("-N")) {
+ flags &= ~FLAG_NAMEPREP;
+ } else if (OPT_MATCH("-unassigncheck") || OPT_MATCH("-u")) {
+ flags |= FLAG_UNASSIGNCHECK;
+ } else if (OPT_MATCH("-nounassigncheck") || OPT_MATCH("-U")) {
+ flags &= ~FLAG_UNASSIGNCHECK;
+ } else if (OPT_MATCH("-nobidicheck") || OPT_MATCH("-B")) {
+ flags &= ~FLAG_BIDICHECK;
+ } else if (OPT_MATCH("-noasciicheck") || OPT_MATCH("-A")) {
+ flags &= ~FLAG_ASCIICHECK;
+ } else if (OPT_MATCH("-nolengthcheck")) {
+ flags &= ~FLAG_LENGTHCHECK;
+ } else if (OPT_MATCH("-noroundtripcheck")) {
+ flags &= ~FLAG_ROUNDTRIPCHECK;
+ } else if (OPT_MATCH("-whole") || OPT_MATCH("-w")) {
+ flags &= ~FLAG_SELECTIVE;
+ } else if (OPT_MATCH("-localmap")) {
+ MUST_HAVE_ARG;
+ APPEND_LIST(localmappers, nlocalmappers, av[1],
+ "local maps");
+ } else if (OPT_MATCH("-delimiter")) {
+ unsigned long v;
+ MUST_HAVE_ARG;
+ v = get_ucs(av[1]);
+ APPEND_LIST(delimiters, ndelimiters, v,
+ "delimiter maps");
+ } else if (OPT_MATCH("-alias") || OPT_MATCH("-a")) {
+ MUST_HAVE_ARG;
+ encoding_alias = av[1];
+ ac--;
+ av++;
+ } else if (OPT_MATCH("-flush")) {
+ flush_every_line = 1;
+ } else if (OPT_MATCH("-version") || OPT_MATCH("-v")) {
+ print_version();
+ } else {
+ print_usage(cmd);
+ }
+#undef OPT_MATCH
+#undef MUST_HAVE_ARG
+#undef APPEND_LIST
+
+ ac--;
+ av++;
+ }
+
+ if (ac > 1)
+ print_usage(cmd);
+
+ /* Initialize. */
+ if ((r = idn_resconf_initialize()) != idn_success) {
+ errormsg("error initializing library\n");
+ return (1);
+ }
+
+ /*
+ * Create resource contexts.
+ * `resconf1' and `resconf2' are almost the same but local and
+ * IDN encodings are reversed.
+ */
+ resconf1 = NULL;
+ resconf2 = NULL;
+ if (idn_resconf_create(&resconf1) != idn_success ||
+ idn_resconf_create(&resconf2) != idn_success) {
+ errormsg("error initializing configuration contexts\n");
+ return (1);
+ }
+
+ /* Load configuration file. */
+ if (no_resconf) {
+ set_defaults(resconf1);
+ set_defaults(resconf2);
+ } else {
+ load_conf_file(resconf1, resconf_file);
+ load_conf_file(resconf2, resconf_file);
+ }
+
+ /* Set encoding alias file. */
+ if (encoding_alias != NULL)
+ set_encoding_alias(encoding_alias);
+
+ /* Set input codeset. */
+ if (flags & FLAG_REVERSE) {
+ if (in_code == NULL) {
+ conv = idn_resconf_getidnconverter(resconf1);
+ if (conv == NULL) {
+ errormsg("cannot get the IDN encoding.\n"
+ "please specify an appropriate one "
+ "with `-in' option.\n");
+ exit(1);
+ }
+ idn_resconf_setlocalconverter(resconf2, conv);
+ idn_converter_destroy(conv);
+ } else {
+ set_idncode(resconf1, in_code);
+ set_localcode(resconf2, in_code);
+ }
+ } else {
+ if (in_code == NULL) {
+ conv = idn_resconf_getlocalconverter(resconf1);
+ if (conv == NULL) {
+ errormsg("cannot get the local encoding.\n"
+ "please specify an appropriate one "
+ "with `-in' option.\n");
+ exit(1);
+ }
+ idn_resconf_setidnconverter(resconf2, conv);
+ idn_converter_destroy(conv);
+ } else {
+ set_localcode(resconf1, in_code);
+ set_idncode(resconf2, in_code);
+ }
+ }
+
+ /* Set output codeset. */
+ if (flags & FLAG_REVERSE) {
+ if (out_code == NULL) {
+ conv = idn_resconf_getlocalconverter(resconf1);
+ if (conv == NULL) {
+ errormsg("cannot get the local encoding.\n"
+ "please specify an appropriate one "
+ "with `-out' option.\n");
+ exit(1);
+ }
+ idn_resconf_setidnconverter(resconf2, conv);
+ idn_converter_destroy(conv);
+ } else {
+ set_localcode(resconf1, out_code);
+ set_idncode(resconf2, out_code);
+ }
+ } else {
+ if (out_code == NULL) {
+ conv = idn_resconf_getidnconverter(resconf1);
+ if (conv == NULL) {
+ errormsg("cannot get the IDN encoding.\n"
+ "please specify an appropriate one "
+ "with `-out' option.\n");
+ exit(1);
+ }
+ idn_resconf_setlocalconverter(resconf2, conv);
+ idn_converter_destroy(conv);
+ } else {
+ set_idncode(resconf1, out_code);
+ set_localcode(resconf2, out_code);
+ }
+ }
+
+ /* Set delimiter map(s). */
+ if (ndelimiters > 0) {
+ set_delimitermapper(resconf1, delimiters, ndelimiters);
+ set_delimitermapper(resconf2, delimiters, ndelimiters);
+ }
+
+ /* Set local map(s). */
+ if (nlocalmappers > 0) {
+ set_localmapper(resconf1, localmappers, nlocalmappers);
+ set_localmapper(resconf2, localmappers, nlocalmappers);
+ }
+
+ /* Set NAMEPREP version. */
+ if (nameprep_version != NULL) {
+ set_nameprep(resconf1, nameprep_version);
+ set_nameprep(resconf2, nameprep_version);
+ }
+
+ idn_res_enable(1);
+
+ /* Open input file. */
+ if (ac > 0) {
+ if ((fp = fopen(av[0], "r")) == NULL) {
+ errormsg("cannot open file %s: %s\n",
+ av[0], strerror(errno));
+ return (1);
+ }
+ } else {
+ fp = stdin;
+ }
+
+ /* Do the conversion. */
+ if (flags & FLAG_REVERSE)
+ exit_value = decode_file(resconf1, resconf2, fp, flags);
+ else
+ exit_value = encode_file(resconf1, resconf2, fp, flags);
+
+ idn_resconf_destroy(resconf1);
+ idn_resconf_destroy(resconf2);
+
+ return exit_value;
+}
+
+static int
+encode_file(idn_resconf_t conf1, idn_resconf_t conf2, FILE *fp, int flags) {
+ idn_result_t r;
+ idnconv_strbuf_t buf1, buf2;
+ idn_action_t actions1, actions2;
+ int nl_trimmed;
+ int local_ace_hack;
+ idn_converter_t conv;
+
+ /*
+ * See if the input codeset is an ACE.
+ */
+ conv = idn_resconf_getlocalconverter(conf1);
+ if (conv != NULL && idn_converter_isasciicompatible(conv) &&
+ (flags & FLAG_SELECTIVE))
+ local_ace_hack = 1;
+ else
+ local_ace_hack = 0;
+ if (conv != NULL)
+ idn_converter_destroy(conv);
+
+ if (local_ace_hack) {
+ actions1 = IDN_IDNCONV;
+ if (flags & FLAG_ROUNDTRIPCHECK)
+ actions1 |= IDN_RTCHECK;
+ } else {
+ actions1 = IDN_LOCALCONV;
+ }
+
+ actions2 = IDN_IDNCONV;
+ if (flags & FLAG_DELIMMAP)
+ actions2 |= IDN_DELIMMAP;
+ if (flags & FLAG_LOCALMAP)
+ actions2 |= IDN_LOCALMAP;
+ if (flags & FLAG_MAP)
+ actions2 |= IDN_MAP;
+ if (flags & FLAG_NORMALIZE)
+ actions2 |= IDN_NORMALIZE;
+ if (flags & FLAG_PROHIBITCHECK)
+ actions2 |= IDN_PROHCHECK;
+ if (flags & FLAG_UNASSIGNCHECK)
+ actions2 |= IDN_UNASCHECK;
+ if (flags & FLAG_BIDICHECK)
+ actions2 |= IDN_BIDICHECK;
+ if (flags & FLAG_ASCIICHECK)
+ actions2 |= IDN_ASCCHECK;
+ if (flags & FLAG_LENGTHCHECK)
+ actions2 |= IDN_LENCHECK;
+
+ strbuf_init(&buf1);
+ strbuf_init(&buf2);
+ line_number = 1;
+ while (strbuf_getline(&buf1, fp) != NULL) {
+ /*
+ * Trim newline at the end. This is needed for
+ * those ascii-comatible encodings such as UTF-5 or RACE
+ * not to try converting newlines, which will result
+ * in `invalid encoding' error.
+ */
+ nl_trimmed = trim_newline(&buf1);
+
+ /*
+ * Convert input line to UTF-8.
+ */
+ if (local_ace_hack)
+ r = convert_line(&buf1, &buf2, conf2, actions1,
+ FLAG_REVERSE|FLAG_SELECTIVE);
+ else
+ r = convert_line(&buf1, &buf2, conf1, actions1,
+ 0);
+
+ if (r != idn_success) {
+ errormsg("conversion failed at line %d: %s\n",
+ line_number,
+ idn_result_tostring(r));
+ goto error;
+ }
+ if (!idn_utf8_isvalidstring(strbuf_get(&buf2))) {
+ errormsg("conversion to utf-8 failed at line %d\n",
+ line_number);
+ goto error;
+ }
+
+ /*
+ * Perform local mapping and NAMEPREP, and convert to
+ * the output codeset.
+ */
+ r = convert_line(&buf2, &buf1, conf1, actions2,
+ flags & FLAG_SELECTIVE);
+
+ if (r != idn_success) {
+ errormsg("error in nameprep or output conversion "
+ "at line %d: %s\n",
+ line_number, idn_result_tostring(r));
+ goto error;
+ }
+
+ fputs(strbuf_get(&buf1), stdout);
+ if (nl_trimmed)
+ putc('\n', stdout);
+
+ if (flush_every_line)
+ fflush(stdout);
+
+ line_number++;
+ }
+
+ strbuf_reset(&buf1);
+ strbuf_reset(&buf2);
+ return (0);
+
+ error:
+ strbuf_reset(&buf1);
+ strbuf_reset(&buf2);
+ return (1);
+}
+
+static int
+decode_file(idn_resconf_t conf1, idn_resconf_t conf2, FILE *fp, int flags) {
+ idn_result_t r;
+ idnconv_strbuf_t buf1, buf2;
+ idn_action_t actions1, actions2;
+ int nl_trimmed;
+ int local_ace_hack, idn_ace_hack;
+ idn_converter_t conv;
+
+ /*
+ * See if the input codeset is an ACE.
+ */
+ conv = idn_resconf_getidnconverter(conf1);
+ if (conv != NULL && idn_converter_isasciicompatible(conv) &&
+ (flags & FLAG_SELECTIVE))
+ idn_ace_hack = 1;
+ else
+ idn_ace_hack = 0;
+ if (conv != NULL)
+ idn_converter_destroy(conv);
+
+ conv = idn_resconf_getlocalconverter(conf1);
+ if (conv != NULL && idn_converter_isasciicompatible(conv) &&
+ (flags & FLAG_SELECTIVE))
+ local_ace_hack = 1;
+ else
+ local_ace_hack = 0;
+ if (conv != NULL)
+ idn_converter_destroy(conv);
+
+ actions1 = IDN_IDNCONV;
+
+ if (local_ace_hack) {
+ actions2 = IDN_IDNCONV;
+ if (flags & FLAG_MAP)
+ actions2 |= IDN_MAP;
+ if (flags & FLAG_NORMALIZE)
+ actions2 |= IDN_NORMALIZE;
+ if (flags & FLAG_PROHIBITCHECK)
+ actions2 |= IDN_PROHCHECK;
+ if (flags & FLAG_UNASSIGNCHECK)
+ actions2 |= IDN_UNASCHECK;
+ if (flags & FLAG_BIDICHECK)
+ actions2 |= IDN_BIDICHECK;
+ if (flags & FLAG_ASCIICHECK)
+ actions2 |= IDN_ASCCHECK;
+ if (flags & FLAG_LENGTHCHECK)
+ actions2 |= IDN_LENCHECK;
+ } else {
+ actions2 = IDN_LOCALCONV;
+ }
+
+ if (flags & FLAG_DELIMMAP)
+ actions1 |= IDN_DELIMMAP;
+ if (flags & FLAG_MAP)
+ actions1 |= IDN_MAP;
+ if (flags & FLAG_NORMALIZE)
+ actions1 |= IDN_NORMALIZE;
+ if (flags & FLAG_NORMALIZE)
+ actions1 |= IDN_NORMALIZE;
+ if (flags & FLAG_PROHIBITCHECK)
+ actions1 |= IDN_PROHCHECK;
+ if (flags & FLAG_UNASSIGNCHECK)
+ actions1 |= IDN_UNASCHECK;
+ if (flags & FLAG_BIDICHECK)
+ actions1 |= IDN_BIDICHECK;
+ if (flags & FLAG_ASCIICHECK)
+ actions1 |= IDN_ASCCHECK;
+ if (flags & FLAG_ROUNDTRIPCHECK)
+ actions1 |= IDN_RTCHECK;
+
+ strbuf_init(&buf1);
+ strbuf_init(&buf2);
+ line_number = 1;
+ while (strbuf_getline(&buf1, fp) != NULL) {
+ /*
+ * Trim newline at the end. This is needed for
+ * those ascii-comatible encodings such as UTF-5 or RACE
+ * not to try converting newlines, which will result
+ * in `invalid encoding' error.
+ */
+ nl_trimmed = trim_newline(&buf1);
+
+ /*
+ * Treat input line as the string encoded in local
+ * encoding and convert it to UTF-8 encoded string.
+ */
+ if (local_ace_hack) {
+ if (strbuf_copy(&buf2, strbuf_get(&buf1)) == NULL)
+ r = idn_nomemory;
+ else
+ r = idn_success;
+ } else {
+ r = convert_line(&buf1, &buf2, conf1, IDN_LOCALCONV,
+ 0);
+ }
+ if (r != idn_success) {
+ errormsg("conversion failed at line %d: %s\n",
+ line_number, idn_result_tostring(r));
+ goto error;
+ }
+
+ /*
+ * Convert internationalized domain names in the line.
+ */
+ if (idn_ace_hack) {
+ r = convert_line(&buf2, &buf1, conf1, actions1,
+ FLAG_REVERSE|FLAG_SELECTIVE);
+ } else {
+ r = convert_line(&buf2, &buf1, conf1, actions1,
+ FLAG_REVERSE);
+ }
+ if (r != idn_success) {
+ errormsg("conversion failed at line %d: %s\n",
+ line_number,
+ idn_result_tostring(r));
+ goto error;
+ }
+ if (!idn_utf8_isvalidstring(strbuf_get(&buf1))) {
+ errormsg("conversion to utf-8 failed at line %d\n",
+ line_number);
+ goto error;
+ }
+
+ /*
+ * Perform round trip check and convert to the output
+ * codeset.
+ */
+ if (local_ace_hack) {
+ r = convert_line(&buf1, &buf2, conf2, actions2,
+ FLAG_SELECTIVE);
+ } else {
+ r = convert_line(&buf1, &buf2, conf1, actions2,
+ FLAG_REVERSE);
+ }
+
+ if (r != idn_success) {
+ errormsg("error in nameprep or output conversion "
+ "at line %d: %s\n",
+ line_number, idn_result_tostring(r));
+ goto error;
+ }
+
+ fputs(strbuf_get(&buf2), stdout);
+ if (nl_trimmed)
+ putc('\n', stdout);
+
+ if (flush_every_line)
+ fflush(stdout);
+
+ line_number++;
+ }
+ strbuf_reset(&buf1);
+ strbuf_reset(&buf2);
+ return (0);
+
+ error:
+ strbuf_reset(&buf1);
+ strbuf_reset(&buf2);
+ return (1);
+}
+
+static int
+trim_newline(idnconv_strbuf_t *buf) {
+ /*
+ * If the string in BUF ends with a newline, trim it and
+ * return 1. Otherwise, just return 0 without modifying BUF.
+ */
+ char *s = strbuf_get(buf);
+ size_t len = strlen(s);
+
+ if (s[len - 1] == '\n') {
+ s[len - 1] = '\0';
+ return (1);
+ }
+
+ return (0);
+}
+
+static idn_result_t
+convert_line(idnconv_strbuf_t *from, idnconv_strbuf_t *to,
+ idn_resconf_t conf, idn_action_t actions, int flags)
+{
+ idn_result_t r = idn_success;
+ char *from_str = strbuf_get(from);
+
+ for (;;) {
+ char *to_str = strbuf_get(to);
+ size_t to_size = strbuf_size(to);
+
+ switch (flags & (FLAG_REVERSE|FLAG_SELECTIVE)) {
+ case 0:
+ r = idn_res_encodename(conf, actions, from_str,
+ to_str, to_size);
+ break;
+ case FLAG_REVERSE:
+ r = idn_res_decodename(conf, actions, from_str,
+ to_str, to_size);
+ break;
+ case FLAG_SELECTIVE:
+ r = selective_encode(conf, actions, from_str,
+ to_str, to_size);
+ break;
+ case FLAG_REVERSE|FLAG_SELECTIVE:
+ r = selective_decode(conf, actions, from_str,
+ to_str, to_size);
+ break;
+ }
+ if (r == idn_buffer_overflow) {
+ /*
+ * Conversion is not successful because
+ * the size of the target buffer is not enough.
+ * Double the size and retry.
+ */
+ if (strbuf_double(to) == NULL) {
+ /* oops. allocation failed. */
+ return (idn_nomemory);
+ }
+ } else {
+ break;
+ }
+ }
+ return (r);
+}
+
+static char *options[] = {
+ "-in INPUT-CODESET : specifies input codeset name.",
+ "-i INPUT-CODESET : synonym for -in",
+ "-out OUTPUT-CODESET : specifies output codeset name.",
+ "-o OUTPUT-CODESET : synonym for -out",
+ "-conf CONF-FILE : specifies idnkit configuration file.",
+ "-c CONF-FILE : synonym for -conf",
+ "-noconf : do not load idnkit configuration file.",
+ "-C : synonym for -noconf",
+ "-reverse : specifies reverse conversion.",
+ " (i.e. IDN encoding to local encoding)",
+ "-r : synonym for -reverse",
+ "-nameprep VERSION : specifies version name of NAMEPREP.",
+ "-n VERSION : synonym for -nameprep",
+ "-nonameprep : do not perform NAMEPREP.",
+ "-N : synonym for -nonameprep",
+ "-localmap MAPPING : specifies local mapping.",
+ "-nolocalmap : do not perform local mapping.",
+ "-L : synonym for -nolocalmap",
+ "-nounassigncheck : do not perform unassigned codepoint check.",
+ "-U : synonym for -nounassigncheck",
+ "-nobidicheck : do not perform bidirectional text check.",
+ "-B : synonym for -nobidicheck",
+ "-nolengthcheck : do not check label length.",
+ "-noasciicheck : do not check ASCII range characters.",
+ "-A : synonym for -noasciicheck",
+ "-noroundtripcheck : do not perform round trip check.",
+ "-delimiter U+XXXX : specifies local delimiter code point.",
+ "-alias alias-file : specifies codeset alias file.",
+ "-a : synonym for -alias",
+ "-flush : line-buffering mode.",
+ "-whole : convert the whole region instead of",
+ " regions containing non-ascii characters.",
+ "-w : synonym for -whole",
+ "-version : print version number, then exit.",
+ "-v : synonym for -version",
+ "",
+ " The following options can be specified multiple times",
+ " -localmap, -delimiter",
+ NULL,
+};
+
+static void
+print_version() {
+ fprintf(stderr, "idnconv (idnkit) version: %s\n"
+ "library version: %s\n",
+ IDNKIT_VERSION,
+ idn_version_getstring());
+ exit(0);
+}
+
+static void
+print_usage(char *cmd) {
+ int i;
+
+ fprintf(stderr, "Usage: %s [options..] [file]\n", cmd);
+
+ for (i = 0; options[i] != NULL; i++)
+ fprintf(stderr, "\t%s\n", options[i]);
+
+ exit(1);
+}
+
+static unsigned long
+get_ucs(const char *p) {
+ unsigned long v;
+ char *end;
+
+ /* Skip optional 'U+' */
+ if (strncmp(p, "U+", 2) == 0)
+ p += 2;
+
+ v = strtoul(p, &end, 16);
+ if (*end != '\0') {
+ fprintf(stderr, "invalid UCS code point \"%s\"\n", p);
+ exit(1);
+ }
+
+ return v;
+}
diff --git a/contrib/idn/idnkit-1.0-src/tools/idnconv/idnslookup.in b/contrib/idn/idnkit-1.0-src/tools/idnconv/idnslookup.in
new file mode 100644
index 0000000..d380f1e
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/idnconv/idnslookup.in
@@ -0,0 +1,116 @@
+#! /bin/sh
+# $Id: idnslookup.in,v 1.1.1.1 2003/06/04 00:27:10 marka Exp $
+#
+# Copyright (c) 2000 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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+# Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+#
+# 4. The name of JPNIC may not 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.
+
+USAGE="Usage: $0 domain-name DNS-server"
+
+#
+# Parse command line arguments.
+#
+if [ $# -lt 2 ] ; then
+ echo "$0: too few argument" 1>&2
+ echo $USAGE 1>&2
+ exit 1
+fi
+
+if [ $# -gt 2 ] ; then
+ echo "$0: too many argument" 1>&2
+ echo $USAGE 1>&2
+ exit 1
+fi
+
+case "$1" in
+-*) echo "$0: unknown option $1" 1>&2
+ echo $USAGE 1>&2
+ exit 1
+ ;;
+esac
+
+LOCAL_DOMAIN_NAME="$1"
+NAME_SERVER="$2"
+
+#
+# Append some directories to PATH.
+#
+[ -d /usr/sbin ] && PATH=$PATH:/usr/sbin
+[ -d /sbin ] && PATH=$PATH:/sbin
+
+#
+# Find `nslookup' command.
+#
+if [ x"$NSLOOKUP" = x ] ; then
+ for I in `echo $PATH | sed -e 's/:/ /g'` ; do
+ if [ -x $I/nslookup ] ; then
+ NSLOOKUP="$I/nslookup"
+ break
+ fi
+ done
+ if [ "$NSLOOKUP" = "" ] ; then
+ echo "$0: nslookup not found" 1>&2
+ exit 1
+ fi
+fi
+if [ ! -x "$NSLOOKUP" ] ; then
+ echo "$0: nslookup not found" 1>&2
+ exit 1
+fi
+
+#
+# Check if `idnconv' command exists.
+#
+IDNCONV=${IDNCONV-"@bindir@/idnconv"}
+if [ ! -x "$IDNCONV" ] ; then
+ echo "$0: idnconv not found" 1>&2
+ exit 1
+fi
+
+#
+# Convert domain name to IDN encoding.
+#
+IDN_DOMAIN_NAME="`echo $LOCAL_DOMAIN_NAME | $IDNCONV -w`" || exit 1
+
+#
+# Invoke nslookup.
+#
+$NSLOOKUP $IDN_DOMAIN_NAME $NAME_SERVER < /dev/null || exit 1
+
+exit 0
diff --git a/contrib/idn/idnkit-1.0-src/tools/idnconv/make.wnt b/contrib/idn/idnkit-1.0-src/tools/idnconv/make.wnt
new file mode 100644
index 0000000..97ce188
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/idnconv/make.wnt
@@ -0,0 +1,72 @@
+# $Id: make.wnt,v 1.1.1.1 2003/06/04 00:27:06 marka Exp $
+# Makefile for idnconv, manually configured for WIN-NT (VC5.0)
+#
+# Copyright (c) 2000,2002 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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+# Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+#
+# 4. The name of JPNIC may not 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.
+
+!include <ntwin32.mak>
+
+INCDIR = ..\..\include
+ICONVDIR = ..\..\win
+IDNLIBDIR = ..\..\lib
+LIBS = $(IDNLIBDIR)\idnkit.lib $(ICONVDIR)\iconv.lib
+SYSLIBS = $(conlibsdll)
+
+SRCS = idnconv.c util.c selectiveencode.c
+OBJS = idnconv.obj util.obj selectiveencode.obj
+
+TARGET = idnconv.exe
+
+all: $(TARGET)
+
+idnconv.exe: $(OBJS) $(LIBS)
+ $(link) $(conflags) /out:idnconv.exe $(OBJS) $(LIBS) $(SYSLIBS)
+
+install:
+
+clean:
+ -del *.exe *.obj *.lib core *.core *~
+
+idnconv.obj: idnconv.c
+ $(cc) $(cflags) $(cvarsdll) -I$(INCDIR) $*.c
+util.obj: util.c
+ $(cc) $(cflags) $(cvarsdll) -I$(INCDIR) $*.c
+selectiveencode.obj: selectiveencode.c
+ $(cc) $(cflags) $(cvarsdll) -I$(INCDIR) $*.c
diff --git a/contrib/idn/idnkit-1.0-src/tools/idnconv/selectiveencode.c b/contrib/idn/idnkit-1.0-src/tools/idnconv/selectiveencode.c
new file mode 100644
index 0000000..ae509df
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/idnconv/selectiveencode.c
@@ -0,0 +1,127 @@
+#ifndef lint
+static char *rcsid = "$Id: selectiveencode.c,v 1.1.1.1 2003/06/04 00:27:07 marka Exp $";
+#endif
+
+/*
+ * Copyright (c) 2000,2002 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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+ * Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+ *
+ * 4. The name of JPNIC may not 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.
+ */
+
+#include <config.h>
+
+#include <stddef.h>
+
+#include <idn/assert.h>
+#include <idn/logmacro.h>
+#include <idn/result.h>
+#include <idn/utf8.h>
+#include <idn/debug.h>
+
+#include "selectiveencode.h"
+
+static int is_domain_delimiter(char c);
+static char *find_nonascii(const char *s);
+
+idn_result_t
+idn_selectiveencode_findregion(const char *s,
+ char **startp, char **endp)
+{
+ char *non_ascii;
+ char *start, *end;
+
+ assert(s != NULL && startp != NULL && endp != NULL);
+
+ TRACE(("idn_selectiveencode_findregion(s=\"%s\")\n",
+ idn__debug_xstring(s, 20)));
+
+ /*
+ * Scan the specified string looking for non-ascii character.
+ */
+ if ((non_ascii = find_nonascii(s)) == NULL)
+ return (idn_notfound);
+
+ /*
+ * Non-ascii character found.
+ * Determine the region to encode.
+ */
+
+ /*
+ * First, we scan backwards to find the beginning of the region
+ * that should be converted.
+ */
+ start = non_ascii;
+ while (start > s) {
+ char *prev = idn_utf8_findfirstbyte(start - 1, s);
+ if (is_domain_delimiter(*prev))
+ break; /* Found */
+ start = prev;
+ }
+ *startp = start;
+
+ /*
+ * Next we scan forwards looking for the end of the region.
+ */
+ end = non_ascii + idn_utf8_mblen(non_ascii);
+ while (!is_domain_delimiter(*end))
+ end += idn_utf8_mblen(end);
+ *endp = end;
+
+ return (idn_success);
+}
+
+static int
+is_domain_delimiter(char c) {
+ return ((unsigned char)c < 0x80 &&
+ !('A' <= c && c <= 'Z') &&
+ !('a' <= c && c <= 'z') &&
+ !('0' <= c && c <= '9') &&
+ c != '-' && c != '.');
+}
+
+static char *
+find_nonascii(const char *s) {
+ while (*s != '\0' && (unsigned char)*s < 0x80)
+ s++;
+ if (*s == '\0')
+ return (NULL);
+ else
+ return ((char *)s);
+}
diff --git a/contrib/idn/idnkit-1.0-src/tools/idnconv/selectiveencode.h b/contrib/idn/idnkit-1.0-src/tools/idnconv/selectiveencode.h
new file mode 100644
index 0000000..ec4d8f6
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/idnconv/selectiveencode.h
@@ -0,0 +1,70 @@
+/* $Id: selectiveencode.h,v 1.1.1.1 2003/06/04 00:27:08 marka Exp $ */
+/*
+ * Copyright (c) 2000,2002 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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+ * Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+ *
+ * 4. The name of JPNIC may not 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.
+ */
+
+#ifndef IDN_SELECTIVENCODE_H
+#define IDN_SELECTIVENCODE_H 1
+
+/*
+ * Find where to convert.
+ *
+ * Find a substring for which IDN domain name codeset conversion is necessary.
+ */
+
+#include <idn/result.h>
+
+/*
+ * Scan the given string 's' (in UTF-8 encoding) looking for a substring
+ * made of
+ * + at least one non-ascii character and
+ * + zero or more legitimate domain-name characters (i.e. ascii alphabets,
+ * digits and hyphens) and periods.
+ *
+ * Returns:
+ * idn_success -- ok, found.
+ * idn_notfound -- not found.
+ */
+extern idn_result_t
+idn_selectiveencode_findregion(const char *s, char **startp, char **endp);
+
+#endif /* IDN_SELECTIVENCODE_H */
diff --git a/contrib/idn/idnkit-1.0-src/tools/idnconv/util.c b/contrib/idn/idnkit-1.0-src/tools/idnconv/util.c
new file mode 100644
index 0000000..35677e9
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/idnconv/util.c
@@ -0,0 +1,554 @@
+#ifndef lint
+static char *rcsid = "$Id: util.c,v 1.1.1.1 2003/06/04 00:27:08 marka Exp $";
+#endif
+
+/*
+ * Copyright (c) 2000,2002 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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+ * Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+ *
+ * 4. The name of JPNIC may not 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.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+
+#include <idn/resconf.h>
+#include <idn/converter.h>
+#include <idn/res.h>
+#include <idn/utf8.h>
+
+#include "util.h"
+#include "selectiveencode.h"
+
+extern int line_number;
+
+idn_result_t
+selective_encode(idn_resconf_t conf, idn_action_t actions,
+ char *from, char *to, int tolen)
+{
+ for (;;) {
+ int len;
+ char *region_start, *region_end;
+ idn_result_t r;
+ char save;
+
+ /*
+ * Find the region that needs conversion.
+ */
+ r = idn_selectiveencode_findregion(from, &region_start,
+ &region_end);
+ if (r == idn_notfound) {
+ /*
+ * Not found. Just copy the whole thing.
+ */
+ if (tolen <= strlen(from))
+ return (idn_buffer_overflow);
+ (void)strcpy(to, from);
+ return (idn_success);
+ } else if (r != idn_success) {
+ /* This should not happen.. */
+ errormsg("internal error at line %d: %s\n",
+ line_number, idn_result_tostring(r));
+ return (r);
+ }
+
+ /*
+ * We have found a region to convert.
+ * First, copy the prefix part verbatim.
+ */
+ len = region_start - from;
+ if (tolen < len) {
+ errormsg("internal buffer overflow at line %d\n",
+ line_number);
+ return (idn_buffer_overflow);
+ }
+ (void)memcpy(to, from, len);
+ to += len;
+ tolen -= len;
+
+ /*
+ * Terminate the region with NUL.
+ */
+ save = *region_end;
+ *region_end = '\0';
+
+ /*
+ * Encode the region.
+ */
+ r = idn_res_encodename(conf, actions, region_start, to, tolen);
+
+ /*
+ * Restore character.
+ */
+ *region_end = save;
+
+ if (r != idn_success)
+ return (r);
+
+ len = strlen(to);
+ to += len;
+ tolen -= len;
+
+ from = region_end;
+ }
+}
+
+idn_result_t
+selective_decode(idn_resconf_t conf, idn_action_t actions,
+ char *from, char *to, int tolen)
+{
+ char *domain_name;
+ char *ignored_chunk;
+ char save;
+ int len;
+ idn_result_t r;
+
+ /*
+ * While `*from' points to a character in a string which may be
+ * a domain name, `domain_name' refers to the beginning of the
+ * domain name.
+ */
+ domain_name = NULL;
+
+ /*
+ * We ignore chunks matching to the regular expression:
+ * [\-\.][0-9A-Za-z\-\.]*
+ *
+ * While `*from' points to a character in such a chunk,
+ * `ignored_chunk' refers to the beginning of the chunk.
+ */
+ ignored_chunk = NULL;
+
+ for (;;) {
+ if (*from == '-') {
+ /*
+ * We don't recognize `.-' as a part of domain name.
+ */
+ if (domain_name != NULL) {
+ if (*(from - 1) == '.') {
+ ignored_chunk = domain_name;
+ domain_name = NULL;
+ }
+ } else if (ignored_chunk == NULL) {
+ ignored_chunk = from;
+ }
+
+ } else if (*from == '.') {
+ /*
+ * We don't recognize `-.' nor `..' as a part of
+ * domain name.
+ */
+ if (domain_name != NULL) {
+ if (*(from - 1) == '-' || *(from - 1) == '.') {
+ ignored_chunk = domain_name;
+ domain_name = NULL;
+ }
+ } else if (ignored_chunk == NULL) {
+ ignored_chunk = from;
+ }
+
+ } else if (('a' <= *from && *from <= 'z') ||
+ ('A' <= *from && *from <= 'Z') ||
+ ('0' <= *from && *from <= '9')) {
+ if (ignored_chunk == NULL && domain_name == NULL)
+ domain_name = from;
+
+ } else {
+ if (ignored_chunk != NULL) {
+ /*
+ * `from' reaches the end of the ignored chunk.
+ * Copy the chunk to `to'.
+ */
+ len = from - ignored_chunk;
+ if (tolen < len)
+ return (idn_buffer_overflow);
+ (void)memcpy(to, ignored_chunk, len);
+ to += len;
+ tolen -= len;
+
+ } else if (domain_name != NULL) {
+ /*
+ * `from' reaches the end of the domain name.
+ * Decode the domain name, and copy the result
+ * to `to'.
+ */
+ save = *from;
+ *from = '\0';
+ r = idn_res_decodename(conf, actions,
+ domain_name, to, tolen);
+ *from = save;
+
+ if (r == idn_success) {
+ len = strlen(to);
+ } else if (r == idn_invalid_encoding) {
+ len = from - domain_name;
+ if (tolen < len)
+ return (idn_buffer_overflow);
+ (void)memcpy(to, domain_name, len);
+ } else {
+ return (r);
+ }
+ to += len;
+ tolen -= len;
+ }
+
+ /*
+ * Copy a character `*from' to `to'.
+ */
+ if (tolen < 1)
+ return (idn_buffer_overflow);
+ *to = *from;
+ to++;
+ tolen--;
+
+ domain_name = NULL;
+ ignored_chunk = NULL;
+
+ if (*from == '\0')
+ break;
+ }
+
+ from++;
+ }
+
+ return (idn_success);
+}
+
+void
+set_defaults(idn_resconf_t conf) {
+ idn_result_t r;
+
+ if ((r = idn_resconf_setdefaults(conf)) != idn_success) {
+ errormsg("error setting default configuration: %s\n",
+ idn_result_tostring(r));
+ exit(1);
+ }
+}
+
+void
+load_conf_file(idn_resconf_t conf, const char *file) {
+ idn_result_t r;
+
+ if ((r = idn_resconf_loadfile(conf, file)) != idn_success) {
+ errormsg("error reading configuration file: %s\n",
+ idn_result_tostring(r));
+ exit(1);
+ }
+}
+
+void
+set_encoding_alias(const char *encoding_alias) {
+ idn_result_t r;
+
+ if ((r = idn_converter_resetalias()) != idn_success) {
+ errormsg("cannot reset alias information: %s\n",
+ idn_result_tostring(r));
+ exit(1);
+ }
+
+ if ((r = idn_converter_aliasfile(encoding_alias)) != idn_success) {
+ errormsg("cannot read alias file %s: %s\n",
+ encoding_alias, idn_result_tostring(r));
+ exit(1);
+ }
+}
+
+void
+set_localcode(idn_resconf_t conf, const char *code) {
+ idn_result_t r;
+
+ r = idn_resconf_setlocalconvertername(conf, code,
+ IDN_CONVERTER_RTCHECK);
+ if (r != idn_success) {
+ errormsg("cannot create converter for codeset %s: %s\n",
+ code, idn_result_tostring(r));
+ exit(1);
+ }
+}
+
+void
+set_idncode(idn_resconf_t conf, const char *code) {
+ idn_result_t r;
+
+ r = idn_resconf_setidnconvertername(conf, code,
+ IDN_CONVERTER_RTCHECK);
+ if (r != idn_success) {
+ errormsg("cannot create converter for codeset %s: %s\n",
+ code, idn_result_tostring(r));
+ exit(1);
+ }
+}
+
+void
+set_delimitermapper(idn_resconf_t conf, unsigned long *delimiters,
+ int ndelimiters) {
+ idn_result_t r;
+
+ r = idn_resconf_addalldelimitermapucs(conf, delimiters, ndelimiters);
+ if (r != idn_success) {
+ errormsg("cannot add delimiter: %s\n",
+ idn_result_tostring(r));
+ exit(1);
+ }
+}
+
+void
+set_localmapper(idn_resconf_t conf, char **mappers, int nmappers) {
+ idn_result_t r;
+
+ /* Add mapping. */
+ r = idn_resconf_addalllocalmapselectornames(conf,
+ IDN_MAPSELECTOR_DEFAULTTLD,
+ (const char **)mappers,
+ nmappers);
+ if (r != idn_success) {
+ errormsg("cannot add local map: %s\n",
+ idn_result_tostring(r));
+ exit(1);
+ }
+}
+
+void
+set_nameprep(idn_resconf_t conf, char *version) {
+ idn_result_t r;
+
+ r = idn_resconf_setnameprepversion(conf, version);
+ if (r != idn_success) {
+ errormsg("error setting nameprep %s: %s\n",
+ version, idn_result_tostring(r));
+ exit(1);
+ }
+}
+
+void
+set_mapper(idn_resconf_t conf, char **mappers, int nmappers) {
+ idn_result_t r;
+
+ /* Configure mapper. */
+ r = idn_resconf_addallmappernames(conf, (const char **)mappers,
+ nmappers);
+ if (r != idn_success) {
+ errormsg("cannot add nameprep map: %s\n",
+ idn_result_tostring(r));
+ exit(1);
+ }
+}
+
+void
+set_normalizer(idn_resconf_t conf, char **normalizers, int nnormalizer) {
+ idn_result_t r;
+
+ r = idn_resconf_addallnormalizernames(conf,
+ (const char **)normalizers,
+ nnormalizer);
+ if (r != idn_success) {
+ errormsg("cannot add normalizer: %s\n",
+ idn_result_tostring(r));
+ exit(1);
+ }
+}
+
+void
+set_prohibit_checkers(idn_resconf_t conf, char **prohibits, int nprohibits) {
+ idn_result_t r;
+
+ r = idn_resconf_addallprohibitcheckernames(conf,
+ (const char **)prohibits,
+ nprohibits);
+ if (r != idn_success) {
+ errormsg("cannot add prohibit checker: %s\n",
+ idn_result_tostring(r));
+ exit(1);
+ }
+}
+
+void
+set_unassigned_checkers(idn_resconf_t conf, char **unassigns, int nunassigns) {
+ idn_result_t r;
+
+ r = idn_resconf_addallunassignedcheckernames(conf,
+ (const char **)unassigns,
+ nunassigns);
+ if (r != idn_success) {
+ errormsg("cannot add unassigned checker: %s\n",
+ idn_result_tostring(r));
+ exit(1);
+ }
+}
+
+void
+errormsg(const char *fmt, ...) {
+ va_list args;
+
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ va_end(args);
+}
+
+
+/*
+ * Dynamic Stirng Buffer Utility
+ */
+
+void
+strbuf_init(idnconv_strbuf_t *buf) {
+ /*
+ * Initialize the given string buffer.
+ * Caller must allocate the structure (idnconv_strbuf_t)
+ * as an automatic variable or by malloc().
+ */
+ buf->str = buf->local_buf;
+ buf->str[0] = '\0';
+ buf->size = sizeof(buf->local_buf);
+}
+
+void
+strbuf_reset(idnconv_strbuf_t *buf) {
+ /*
+ * Reset the given string buffer.
+ * Free memory allocated by this utility, and
+ * re-initialize.
+ */
+ if (buf->str != NULL && buf->str != buf->local_buf) {
+ free(buf->str);
+ }
+ strbuf_init(buf);
+}
+
+char *
+strbuf_get(idnconv_strbuf_t *buf) {
+ /*
+ * Get the pointer of the buffer.
+ */
+ return (buf->str);
+}
+
+size_t
+strbuf_size(idnconv_strbuf_t *buf) {
+ /*
+ * Get the allocated size of the buffer.
+ */
+ return (buf->size);
+}
+
+char *
+strbuf_copy(idnconv_strbuf_t *buf, const char *str) {
+ /*
+ * Copy STR to BUF.
+ */
+ size_t len = strlen(str);
+
+ if (strbuf_alloc(buf, len + 1) == NULL)
+ return (NULL);
+ strcpy(buf->str, str);
+ return (buf->str);
+}
+
+char *
+strbuf_append(idnconv_strbuf_t *buf, const char *str) {
+ /*
+ * Append STR to the end of BUF.
+ */
+ size_t len1 = strlen(buf->str);
+ size_t len2 = strlen(str);
+ char *p;
+#define MARGIN 50
+
+ p = strbuf_alloc(buf, len1 + len2 + 1 + MARGIN);
+ if (p != NULL)
+ strcpy(buf->str + len1, str);
+ return (p);
+}
+
+char *
+strbuf_alloc(idnconv_strbuf_t *buf, size_t size) {
+ /*
+ * Reallocate the buffer of BUF if needed
+ * so that BUF can hold SIZE bytes of data at least.
+ */
+ char *p;
+
+ if (buf->size >= size)
+ return (buf->str);
+ if (buf->str == buf->local_buf) {
+ if ((p = malloc(size)) == NULL)
+ return (NULL);
+ memcpy(p, buf->local_buf, sizeof(buf->local_buf));
+ } else {
+ if ((p = realloc(buf->str, size)) == NULL)
+ return (NULL);
+ }
+ buf->str = p;
+ buf->size = size;
+ return (buf->str);
+}
+
+char *
+strbuf_double(idnconv_strbuf_t *buf) {
+ /*
+ * Double the size of the buffer of BUF.
+ */
+ return (strbuf_alloc(buf, buf->size * 2));
+}
+
+char *
+strbuf_getline(idnconv_strbuf_t *buf, FILE *fp) {
+ /*
+ * Read a line from FP.
+ */
+ char s[256];
+
+ buf->str[0] = '\0';
+ while (fgets(s, sizeof(s), fp) != NULL) {
+ if (strbuf_append(buf, s) == NULL)
+ return (NULL);
+ if (strlen(s) < sizeof(s) - 1 || s[sizeof(s) - 2] == '\n')
+ return (buf->str);
+ }
+ if (buf->str[0] != '\0')
+ return (buf->str);
+ return (NULL);
+}
diff --git a/contrib/idn/idnkit-1.0-src/tools/idnconv/util.h b/contrib/idn/idnkit-1.0-src/tools/idnconv/util.h
new file mode 100644
index 0000000..43c5b41
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/idnconv/util.h
@@ -0,0 +1,96 @@
+/* $Id: util.h,v 1.1.1.1 2003/06/04 00:27:09 marka Exp $ */
+/*
+ * Copyright (c) 2000,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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+ * Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+ *
+ * 4. The name of JPNIC may not 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.
+ */
+
+#ifndef IDN_IDNCONV_UTIL_H
+#define IDN_IDNCONV_UTIL_H 1
+
+#include <idn/res.h>
+
+#define IDNCONV_LOCALBUF_SIZE 512
+
+typedef struct {
+ char *str;
+ size_t size;
+ char local_buf[IDNCONV_LOCALBUF_SIZE];
+} idnconv_strbuf_t;
+
+extern idn_result_t selective_encode(idn_resconf_t conf,
+ idn_action_t actions, char *from,
+ char *to, int tolen);
+extern idn_result_t selective_decode(idn_resconf_t conf,
+ idn_action_t actions, char *from,
+ char *to, int tolen);
+extern void set_defaults(idn_resconf_t conf);
+extern void load_conf_file(idn_resconf_t conf, const char *file);
+extern void set_encoding_alias(const char *encoding_alias);
+extern void set_localcode(idn_resconf_t conf, const char *code);
+extern void set_idncode(idn_resconf_t conf, const char *code);
+extern void set_delimitermapper(idn_resconf_t conf,
+ unsigned long *delimiters,
+ int ndelimiters);
+extern void set_localmapper(idn_resconf_t conf,
+ char **mappers, int nmappers);
+extern void set_nameprep(idn_resconf_t conf, char *version);
+extern void set_mapper(idn_resconf_t conf,
+ char **mappers, int nmappers);
+extern void set_normalizer(idn_resconf_t conf,
+ char **normalizer, int nnormalizer);
+extern void set_prohibit_checkers(idn_resconf_t conf,
+ char **prohibits,
+ int nprohibits);
+extern void set_unassigned_checkers(idn_resconf_t conf,
+ char **unassigns,
+ int nunassigns);
+extern void errormsg(const char *fmt, ...);
+extern void strbuf_init(idnconv_strbuf_t *buf);
+extern void strbuf_reset(idnconv_strbuf_t *buf);
+extern char *strbuf_get(idnconv_strbuf_t *buf);
+extern size_t strbuf_size(idnconv_strbuf_t *buf);
+extern char *strbuf_copy(idnconv_strbuf_t *buf, const char *str);
+extern char *strbuf_append(idnconv_strbuf_t *buf, const char *str);
+extern char *strbuf_alloc(idnconv_strbuf_t *buf, size_t size);
+extern char *strbuf_double(idnconv_strbuf_t *buf);
+extern char *strbuf_getline(idnconv_strbuf_t *buf, FILE *fp);
+
+#endif /* IDN_IDNCONV_UTIL_H */
diff --git a/contrib/idn/idnkit-1.0-src/tools/make.wnt b/contrib/idn/idnkit-1.0-src/tools/make.wnt
new file mode 100644
index 0000000..60518f4
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/make.wnt
@@ -0,0 +1,57 @@
+# $Id: make.wnt,v 1.1.1.1 2003/06/04 00:27:05 marka Exp $
+# Copyright (c) 2000 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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+# Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+#
+# 4. The name of JPNIC may not 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.
+
+all : force
+ cd idnconv
+ $(MAKE) -f make.wnt
+ cd ..
+
+install : all
+ cd idnconv
+ $(MAKE) -f make.wnt install
+ cd ..
+
+clean : force
+ cd idnconv
+ $(MAKE) -f make.wnt clean
+ cd ..
+
+force:
diff --git a/contrib/idn/idnkit-1.0-src/tools/rpm/idnkit.spec b/contrib/idn/idnkit-1.0-src/tools/rpm/idnkit.spec
new file mode 100644
index 0000000..c740570
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/rpm/idnkit.spec
@@ -0,0 +1,142 @@
+%define prefix /usr
+%define sysconfdir /etc
+%define version 1.0
+
+# official/beta release:
+#define release 1
+#define distrel %{version}
+
+# release candidate:
+%define release rc1
+%define distrel %{version}-%{release}
+
+%define serial 2002051501
+
+%define name idnkit
+%define distsrc %{name}-%{distrel}-src
+
+Name: %{name}
+Version: %{version}
+Release: %{release}
+Copyright: distributable
+Group: System Environment
+Source: %{distsrc}.tar.gz
+BuildRoot: /var/tmp/%{name}-root
+Serial: %{serial}
+Summary: Internationalized Domain Name kit (idnkit/JPNIC)
+Vendor: JPNIC
+Packager: Japan Network Information Center
+
+%description
+idnkit is a kit for handling Internationalized Domain Name.
+
+%package devel
+Group: Development/Libraries
+Summary: The development files for idnkit
+
+%description devel
+The header files and libraries (libidnkit.a and libidnkitlite.a)
+to develop applications that use the libraries.
+
+%prep
+%setup -n %{distsrc}
+
+%build
+if [ -f /usr/lib/libiconv.a -o -f /usr/lib/libiconv.so ]
+then
+ if [ -f /lib/libc-2.0* ]
+ then
+ ICONV="--with-iconv=yes"
+ fi
+fi
+
+CFLAGS="$RPM_OPT_FLAGS" ./configure \
+ --prefix=%{prefix} --sysconfdir=%{sysconfdir} \
+ --enable-runidn \
+ $ICONV
+make
+
+%install
+rm -fr $RPM_BUILD_ROOT
+make DESTDIR=$RPM_BUILD_ROOT install
+mv $RPM_BUILD_ROOT/etc/idn.conf.sample $RPM_BUILD_ROOT/etc/idn.conf
+mv $RPM_BUILD_ROOT/etc/idnalias.conf.sample $RPM_BUILD_ROOT/etc/idnalias.conf
+
+# devel kit
+#install -c lib/libidnkit.a $RPM_BUILD_ROOT/usr/lib
+#cp -r include/idn $RPM_BUILD_ROOT/usr/include
+
+# docs
+mkdir rpm_docs
+(cp NEWS INSTALL INSTALL.ja DISTFILES README.ja README LICENSE.txt \
+ ChangeLog rpm_docs)
+cp -r patch rpm_docs
+
+%clean
+rm -fr $RPM_BUILD_ROOT
+
+%files
+%defattr(-, root, root)
+%{prefix}/bin/idnconv
+%{prefix}/bin/runidn
+%{prefix}/lib/libidnkit.so.*
+%{prefix}/lib/libidnkitlite.so.*
+%{prefix}/lib/libidnkitres.so.*
+%{prefix}/share/idnkit/*
+%config %{sysconfdir}/idn.conf
+%config %{sysconfdir}/idnalias.conf
+%attr(0644, root, root) %config(noreplace)
+%attr(0644, root, man) %{prefix}/man/man1/*
+%attr(0644, root, man) %{prefix}/man/man3/*
+%attr(0644, root, man) %{prefix}/man/man5/*
+%doc rpm_docs/*
+
+%files devel
+%defattr(-, root, root)
+%{prefix}/lib/libidnkit.a
+%{prefix}/lib/libidnkit.la
+%{prefix}/lib/libidnkit.so
+%{prefix}/lib/libidnkitlite.a
+%{prefix}/lib/libidnkitlite.la
+%{prefix}/lib/libidnkitlite.so
+%{prefix}/lib/libidnkitres.a
+%{prefix}/lib/libidnkitres.la
+%{prefix}/lib/libidnkitres.so
+%{prefix}/include/idn/*
+
+%changelog
+* Web May 15 2002 Motoyuki Kasahara <m-kasahr@sra.co.jp>
+- 1.0beta2, experimental.
+
+* Mon May 28 2001 MANABE Takashi <manabe@dsl.gr.jp>
+- include runmdn, libmdnresolv
+
+* Mon Apr 4 2001 Motoyuki Kasahara <m-kasahr@sra.co.jp>
+- 2.1 release
+
+* Mon Apr 4 2001 Motoyuki Kasahara <m-kasahr@sra.co.jp>
+- 2.0.1 release
+
+* Mon Apr 2 2001 MANABE Takashi <manabe@dsl.gr.jp>
+- 2.0 release
+
+* Fri Mar 3 2001 MANABE Takashi <manabe@dsl.gr.jp>
+- 1.3 release
+
+* Mon Dec 6 2000 MANABE Takashi <manabe@dsl.gr.jp>
+- add brace/lace functions to libmdnresolv(mdnkit-1.2-runmdn.patch)
+- include /var/dnsproxy
+- change files section for compressed man pages
+
+* Mon Nov 27 2000 Makoto Ishisone <ishisone@sra.co.jp>
+- 1.2 release
+
+* Thu Nov 2 2000 MANABE Takashi <manabe@dsl.gr.jp>
+- 1.1 release
+
+* Fri Oct 27 2000 MANABE Takashi <manabe@dsl.gr.jp>
+- dnsproxy.patch1
+- move libmdnresolv.{la,so} from mdnkit-devel to mdnkit package
+
+* Wed Oct 18 2000 MANABE Takashi <manabe@dsl.gr.jp>
+- 1.0 release
diff --git a/contrib/idn/idnkit-1.0-src/tools/runidn/Makefile.in b/contrib/idn/idnkit-1.0-src/tools/runidn/Makefile.in
new file mode 100644
index 0000000..c3098ff
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/runidn/Makefile.in
@@ -0,0 +1,167 @@
+# $Id: Makefile.in,v 1.1.1.1 2003/06/04 00:27:11 marka Exp $
+# Copyright (c) 2000 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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+# Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+#
+# 4. The name of JPNIC may not 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.
+
+LIB_CURRENT = 1
+LIB_REVISION = 1
+LIB_AGE = 0
+
+.SUFFIXES:
+.SUFFIXES: .c .lo
+
+top_builddir = ../..
+subdir = tools/runidn
+
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+bindir = @bindir@
+libdir = @libdir@
+mandir = @mandir@
+man1dir = $(mandir)/man1
+
+CC = @CC@
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_DATA = @INSTALL_DATA@
+MKINSTALLDIRS = @top_srcdir@/mkinstalldirs
+SHELL = @SHELL@
+LIBTOOL = @LIBTOOL@
+
+ICONVINC = @ICONVINC@
+ICONVLIB = @ICONVLIB@
+
+INCS = -I$(srcdir) -I$(srcdir)/../../include -I../../include $(ICONVINC)
+DEFS =
+
+CFLAGS = $(INCS) $(DEFS) @CPPFLAGS@ @CFLAGS@
+LDFLAGS = @LDFLAGS@
+
+LIB = libidnkitres
+OBJS = rtresolver.lo stub.lo $(IDNOBJS)
+SCRIPT = runidn
+LIBDL = @LIBDL@
+
+IDNDIR = ../../lib
+IDNOBJS = \
+ $(IDNDIR)/aliaslist.lo \
+ $(IDNDIR)/api.lo \
+ $(IDNDIR)/checker.lo \
+ $(IDNDIR)/converter.lo \
+ $(IDNDIR)/debug.lo \
+ $(IDNDIR)/delimitermap.lo \
+ $(IDNDIR)/filechecker.lo \
+ $(IDNDIR)/filemapper.lo \
+ $(IDNDIR)/localencoding.lo \
+ $(IDNDIR)/log.lo \
+ $(IDNDIR)/mapper.lo \
+ $(IDNDIR)/mapselector.lo \
+ $(IDNDIR)/nameprep.lo \
+ $(IDNDIR)/normalizer.lo \
+ $(IDNDIR)/punycode.lo \
+ $(IDNDIR)/race.lo \
+ $(IDNDIR)/res.lo \
+ $(IDNDIR)/resconf.lo \
+ $(IDNDIR)/result.lo \
+ $(IDNDIR)/strhash.lo \
+ $(IDNDIR)/ucsmap.lo \
+ $(IDNDIR)/ucsset.lo \
+ $(IDNDIR)/unicode.lo \
+ $(IDNDIR)/unormalize.lo \
+ $(IDNDIR)/ucs4.lo \
+ $(IDNDIR)/utf8.lo \
+ $(IDNDIR)/util.lo \
+ $(IDNDIR)/version.lo
+
+.c.lo:
+ $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c $<
+
+@RUNIDN_TRUE@all: $(LIB).la runidn
+@RUNIDN_FALSE@all:
+
+rtresolver.lo: $(srcdir)/resolver.c
+ $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -DFOR_RUNIDN -o $@ \
+ -c $(srcdir)/resolver.c
+
+$(LIB).la: $(OBJS)
+ $(LIBTOOL) --mode=link $(LD) $(LDFLAGS) -o $@ \
+ -version-info $(LIB_CURRENT):$(LIB_REVISION):$(LIB_AGE) \
+ -module -rpath $(libdir) $(OBJS) $(LIBDL)
+
+runidn: $(srcdir)/runidn.in
+ cd $(top_builddir) && \
+ CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= CONFIG_LINKS= \
+ $(SHELL) ./config.status
+
+@RUNIDN_TRUE@@COMPAT_TRUE@install: all install-runidn install-compat
+@RUNIDN_TRUE@@COMPAT_FALSE@install: all install-runidn
+@RUNIDN_FALSE@install:
+
+install-runidn:
+ $(MKINSTALLDIRS) $(DESTDIR)$(libdir)
+ $(LIBTOOL) --mode=install $(INSTALL_DATA) $(LIB).la \
+ $(DESTDIR)$(libdir)/$(LIB).la
+ $(MKINSTALLDIRS) $(DESTDIR)$(bindir)
+ $(INSTALL_SCRIPT) $(SCRIPT) $(DESTDIR)$(bindir)
+ $(MKINSTALLDIRS) $(DESTDIR)$(man1dir)
+ $(INSTALL_DATA) $(srcdir)/runidn.1 $(DESTDIR)$(man1dir)/runidn.1
+
+install-compat:
+ src=$(DESTDIR)$(bindir)/runidn; \
+ dst=$(DESTDIR)$(bindir)/runmdn; \
+ rm -f $$dst; \
+ ln $$src $$dst || cp $$src $$dst
+ src=$(DESTDIR)$(man1dir)/runidn.1; \
+ dst=$(DESTDIR)$(man1dir)/runmdn.1; \
+ rm -f $$dst; \
+ ln $$src $$dst || cp $$src $$dst
+
+clean:
+ rm -f *.lo *.la *.o
+ rm -fr .libs/
+
+distclean: clean
+ rm -f runidn Makefile
+
+test check:
diff --git a/contrib/idn/idnkit-1.0-src/tools/runidn/resolver.c b/contrib/idn/idnkit-1.0-src/tools/runidn/resolver.c
new file mode 100644
index 0000000..129c704
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/runidn/resolver.c
@@ -0,0 +1,1056 @@
+#ifndef lint
+static char *rcsid = "$Id: resolver.c,v 1.1.1.1 2003/06/04 00:27:12 marka Exp $";
+#endif
+
+/*
+ * 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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+ * Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+ *
+ * 4. The name of JPNIC may not 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.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stddef.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <errno.h>
+
+#include <idn/api.h>
+#include <idn/log.h>
+#include <idn/logmacro.h>
+#include <idn/debug.h>
+
+#ifdef FOR_RUNIDN
+/*
+ * This file is specially compiled for runidn.
+ * runidn replaces existing resolver functions dynamically with ones
+ * with IDN processing (encoding conversion and normalization).
+ * So entry names must be same as the system's one.
+ */
+#include "stub.h"
+
+#define ENTRY(name) name
+#define REAL(name) idn_stub_ ## name
+#else
+/*
+ * For normal use. All the entry names are prefixed with "idn_resolver_".
+ * <idn/resolver.h> has bunch of #defines to substitute the standard
+ * name resolver functions with ones provided here.
+ */
+#include "resolver.h"
+#undef gethostbyname
+#undef gethostbyname2
+#undef gethostbyaddr
+#undef gethostbyname_r
+#undef gethostbyname2_r
+#undef gethostbyaddr_r
+#undef getipnodebyname
+#undef getipnodebyaddr
+#undef getaddrinfo
+#undef getnameinfo
+
+#define ENTRY(name) idn_resolver_ ## name
+#define REAL(name) name
+#endif
+
+#define IDN_NAME_SIZE 512
+
+#define IDN_HOSTBUF_SIZE 2048
+typedef union {
+ char *dummy_for_alignment;
+ char data[IDN_HOSTBUF_SIZE];
+} hostbuf_t;
+
+typedef struct obj_lock {
+ void *key;
+ struct obj_lock *next;
+} obj_lock_t;
+
+#define OBJLOCKHASH_SIZE 127
+static obj_lock_t *obj_lock_hash[OBJLOCKHASH_SIZE];
+
+/*
+ * This variable is to prevent IDN processing occuring more than once for
+ * a single name resolution. This will happen if some resolver function
+ * is implemented using another function (e.g. gethostbyname() implemented
+ * using gethostbyname2()).
+ * No, using the static variable is not a correct thing to do for a multi-
+ * threading environment, but I don't think of a better solution..
+ */
+static int idn_isprocessing = 0;
+
+static int obj_hash(void *key);
+static int obj_islocked(void *key);
+static void obj_lock(void *key);
+static void obj_unlock(void *key);
+static struct hostent *copy_decode_hostent_static(struct hostent *hp,
+ struct hostent *newhp,
+ char *buf, size_t buflen,
+ int *errp);
+static char *decode_name_dynamic(const char *name);
+static struct hostent *copy_decode_hostent_dynamic(struct hostent *hp,
+ int *errp);
+static void free_copied_hostent(struct hostent *hp);
+#ifdef HAVE_GETADDRINFO
+static struct addrinfo *copy_decode_addrinfo_dynamic(struct addrinfo *aip);
+#endif
+#ifdef HAVE_FREEADDRINFO
+static void free_copied_addrinfo(struct addrinfo *aip);
+#endif
+
+/*
+ * Object locking facility.
+ */
+
+static int
+obj_hash(void *key) {
+ /*
+ * Hash function for obj_*.
+ * 'key' is supposed to be an address.
+ */
+ unsigned long v = (unsigned long)key;
+
+ return ((v >> 3) % OBJLOCKHASH_SIZE);
+}
+
+static int
+obj_islocked(void *key)
+{
+ /*
+ * Check if the object specified by 'key' is locked.
+ * Return 1 if so, 0 otherwise.
+ */
+ int h = obj_hash(key);
+ obj_lock_t *olp = obj_lock_hash[h];
+
+ while (olp != NULL) {
+ if (olp->key == key)
+ return (1);
+ olp = olp->next;
+ }
+ return (0);
+}
+
+static void
+obj_lock(void *key)
+{
+ /*
+ * Lock an object specified by 'key'.
+ */
+ int h = obj_hash(key);
+ obj_lock_t *olp;
+
+ olp = malloc(sizeof(obj_lock_t));
+ if (olp != NULL) {
+ olp->key = key;
+ olp->next = obj_lock_hash[h];
+ obj_lock_hash[h] = olp;
+ }
+}
+
+static void
+obj_unlock(void *key)
+{
+ /*
+ * Unlock an object specified by 'key'.
+ */
+ int h = obj_hash(key);
+ obj_lock_t *olp, *olp0;
+
+ olp = obj_lock_hash[h];
+ olp0 = NULL;
+ while (olp != NULL) {
+ if (olp->key == key) {
+ if (olp0 == NULL)
+ obj_lock_hash[h] = olp->next;
+ else
+ olp0->next = olp->next;
+ free(olp);
+ return;
+ }
+ olp0 = olp;
+ olp = olp->next;
+ }
+}
+
+static struct hostent *
+copy_decode_hostent_static(struct hostent *hp, struct hostent *newhp,
+ char *buf, size_t buflen, int *errp)
+{
+ /*
+ * Copy "struct hostent" data referenced by 'hp' to 'newhp'.
+ * It's a deep-copy, meaning all the data referenced by 'hp' are
+ * also copied. They are copied into 'buf', whose length is 'buflen'.
+ * The domain names ('hp->h_name' and 'hp->h_aliases') are
+ * decoded from ACE to the local encoding before they are copied.
+ * If 'buf' is too small to hold all the data, NULL will be
+ * returned and '*errp' is set to NO_RECOVERY.
+ */
+ int naliases = 0;
+ int naddrs = 0;
+
+ if (hp == NULL)
+ return (NULL);
+
+ *newhp = *hp;
+
+ if (hp->h_aliases != NULL) {
+ /*
+ * Allocate aliase table in 'buf'.
+ */
+ size_t sz;
+
+ while (hp->h_aliases[naliases] != NULL)
+ naliases++;
+
+ newhp->h_aliases = (char **)buf;
+ sz = sizeof(char *) * (naliases + 1);
+
+ if (buflen < sz)
+ goto overflow;
+
+ buf += sz;
+ buflen -= sz;
+ }
+
+ if (hp->h_addr_list != NULL) {
+ /*
+ * Allocate address table in 'buf'.
+ */
+ size_t sz;
+ int i;
+
+ while (hp->h_addr_list[naddrs] != NULL)
+ naddrs++;
+
+ newhp->h_addr_list = (char **)buf;
+ sz = sizeof(char *) * (naddrs + 1);
+
+ if (buflen < sz)
+ goto overflow;
+
+ buf += sz;
+ buflen -= sz;
+
+ /*
+ * Copy the addresses.
+ */
+ sz = hp->h_length * naddrs;
+ if (buflen < sz)
+ goto overflow;
+
+ for (i = 0; i < naddrs; i++) {
+ newhp->h_addr_list[i] = buf;
+ memcpy(buf, hp->h_addr_list[i], hp->h_length);
+ buf += hp->h_length;
+ }
+ newhp->h_addr_list[naddrs] = NULL;
+
+ buf += sz;
+ buflen -= sz;
+ }
+
+ if (hp->h_name != NULL) {
+ /*
+ * Decode the name in h_name.
+ */
+ idn_result_t r;
+ size_t slen;
+
+ idn_enable(1);
+ idn_nameinit(1);
+ r = idn_decodename(IDN_DECODE_APP, hp->h_name,
+ buf, buflen);
+ switch (r) {
+ case idn_success:
+ newhp->h_name = buf;
+ break;
+ default:
+ /* Copy hp->h_name verbatim. */
+ if (strlen(hp->h_name) + 1 <= buflen) {
+ newhp->h_name = buf;
+ strcpy(buf, hp->h_name);
+ break;
+ }
+ /* falllthrough */
+ case idn_buffer_overflow:
+ goto overflow;
+ }
+
+ slen = strlen(buf) + 1;
+ buf += slen;
+ buflen -= slen;
+ }
+
+ if (hp->h_aliases != NULL) {
+ /*
+ * Decode the names in h_aliases.
+ */
+ char **aliases = hp->h_aliases;
+ char **newaliases = newhp->h_aliases;
+ int i;
+
+ for (i = 0; i < naliases; i++) {
+ idn_result_t r;
+ size_t slen;
+
+ idn_enable(1);
+ idn_nameinit(1);
+ r = idn_decodename(IDN_DECODE_APP, aliases[i],
+ buf, buflen);
+
+ switch (r) {
+ case idn_success:
+ newaliases[i] = buf;
+ break;
+ default:
+ /* Copy hp->h_name verbatim. */
+ if (strlen(aliases[i]) + 1 <= buflen) {
+ newaliases[i] = buf;
+ strcpy(buf, aliases[i]);
+ break;
+ }
+ /* falllthrough */
+ case idn_buffer_overflow:
+ goto overflow;
+ }
+
+ slen = strlen(buf) + 1;
+ buf += slen;
+ buflen -= slen;
+ }
+ newaliases[naliases] = NULL;
+ }
+
+ return (newhp);
+
+ overflow:
+ *errp = NO_RECOVERY;
+ return (NULL);
+}
+
+static char *
+decode_name_dynamic(const char *name) {
+ idn_result_t r;
+ char buf[IDN_NAME_SIZE];
+ char *s;
+
+ idn_enable(1);
+ idn_nameinit(1);
+ r = idn_decodename(IDN_DECODE_APP, name, buf, sizeof(buf));
+ if (r == idn_success) {
+ name = buf;
+ }
+ s = malloc(strlen(name) + 1);
+ if (s == NULL)
+ return (NULL);
+ else
+ return (strcpy(s, name));
+}
+
+static struct hostent *
+copy_decode_hostent_dynamic(struct hostent *hp, int *errp) {
+ /*
+ * Make a deep-copy of the data referenced by 'hp', and return
+ * a pointer to the copied data.
+ * All the data are dynamically allocated using malloc().
+ * The domain names ('hp->h_name' and 'hp->h_aliases') are
+ * decoded from ACE to the local encoding before they are copied.
+ * If malloc() fails, NULL will be returned and '*errp' is set to
+ * NO_RECOVERY.
+ */
+ struct hostent *newhp;
+ char **pp;
+ size_t alloc_size;
+ int naliases = 0;
+ int naddrs = 0;
+ int i;
+
+ if (hp == NULL)
+ return (NULL);
+
+ if (hp->h_aliases != NULL) {
+ while (hp->h_aliases[naliases] != NULL)
+ naliases++;
+ }
+
+ if (hp->h_addr_list != NULL) {
+ while (hp->h_addr_list[naddrs] != NULL)
+ naddrs++;
+ }
+
+ alloc_size = sizeof(struct hostent) +
+ sizeof(char *) * (naliases + 1) +
+ sizeof(char *) * (naddrs + 1) +
+ hp->h_length * naddrs;
+
+ if ((newhp = malloc(alloc_size)) == NULL) {
+ return (hp);
+ }
+
+ memset(newhp, 0, alloc_size);
+
+ pp = (char **)(newhp + 1);
+
+ if (hp->h_name != NULL) {
+ newhp->h_name = decode_name_dynamic(hp->h_name);
+ if (newhp->h_name == NULL)
+ goto alloc_fail;
+ }
+
+ newhp->h_addrtype = hp->h_addrtype;
+ newhp->h_length = hp->h_length;
+
+ if (hp->h_aliases != NULL) {
+ newhp->h_aliases = pp;
+ for (i = 0; i < naliases; i++) {
+ newhp->h_aliases[i] =
+ decode_name_dynamic(hp->h_aliases[i]);
+ if (newhp->h_aliases[i] == NULL)
+ goto alloc_fail;
+ }
+ newhp->h_aliases[naliases] = NULL;
+ pp += naliases + 1;
+ }
+
+ if (hp->h_addr_list != NULL) {
+ char *p;
+
+ newhp->h_addr_list = pp;
+ pp += naddrs + 1;
+ p = (char *)pp;
+
+ for (i = 0; i < naddrs; i++) {
+ newhp->h_addr_list[i] = p;
+ memcpy(p, hp->h_addr_list[i], hp->h_length);
+ p += hp->h_length;
+ }
+ newhp->h_addr_list[naddrs] = NULL;
+ }
+
+ return (newhp);
+
+ alloc_fail:
+ free_copied_hostent(hp);
+ *errp = NO_RECOVERY;
+ return (NULL);
+}
+
+static void
+free_copied_hostent(struct hostent *hp) {
+ /*
+ * Free all the memory allocated by copy_decode_hostent_dynamic().
+ */
+ if (hp->h_name != NULL)
+ free(hp->h_name);
+ if (hp->h_aliases != NULL) {
+ char **pp = hp->h_aliases;
+ while (*pp != NULL)
+ free(*pp++);
+ }
+ free(hp);
+}
+
+#ifdef HAVE_GETNAMEINFO
+static struct addrinfo *
+copy_decode_addrinfo_dynamic(struct addrinfo *aip) {
+ struct addrinfo *newaip;
+
+ if (aip == NULL)
+ return (NULL);
+
+ newaip = malloc(sizeof(struct addrinfo) + aip->ai_addrlen);
+ if (newaip == NULL)
+ return (NULL);
+
+ *newaip = *aip;
+ newaip->ai_addr = (struct sockaddr *)(newaip + 1);
+ memcpy(newaip->ai_addr, aip->ai_addr, aip->ai_addrlen);
+
+ if (newaip->ai_canonname != NULL)
+ newaip->ai_canonname = decode_name_dynamic(aip->ai_canonname);
+
+ newaip->ai_next = copy_decode_addrinfo_dynamic(aip->ai_next);
+ return (newaip);
+}
+#endif
+
+#ifdef HAVE_FREEADDRINFO
+static void
+free_copied_addrinfo(struct addrinfo *aip) {
+ while (aip != NULL) {
+ struct addrinfo *next = aip->ai_next;
+
+ if (aip->ai_canonname != NULL)
+ free(aip->ai_canonname);
+ free(aip);
+ aip = next;
+ }
+}
+#endif
+
+#ifdef HAVE_GETHOSTBYNAME
+struct hostent *
+ENTRY(gethostbyname)(const char *name) {
+ static hostbuf_t buf;
+ static struct hostent he;
+ idn_result_t r;
+ struct hostent *hp;
+
+ if (idn_isprocessing)
+ return (REAL(gethostbyname)(name));
+
+ TRACE(("gethostbyname(name=%s)\n", idn__debug_xstring(name, 60)));
+
+ idn_isprocessing = 1;
+ idn_enable(1);
+ idn_nameinit(1);
+ r = idn_encodename(IDN_ENCODE_APP, name, buf.data, sizeof(buf));
+ if (r == idn_success)
+ name = buf.data;
+
+ hp = copy_decode_hostent_static(REAL(gethostbyname)(name),
+ &he, buf.data, sizeof(buf),
+ &h_errno);
+ idn_isprocessing = 0;
+ return (hp);
+}
+#endif
+
+#ifdef HAVE_GETHOSTBYNAME2
+struct hostent *
+ENTRY(gethostbyname2)(const char *name, int af) {
+ static hostbuf_t buf;
+ static struct hostent he;
+ idn_result_t r;
+ struct hostent *hp;
+
+ if (idn_isprocessing)
+ return (REAL(gethostbyname2)(name, af));
+
+ TRACE(("gethostbyname2(name=%s)\n", idn__debug_xstring(name, 60), af));
+
+ idn_isprocessing = 1;
+ idn_enable(1);
+ idn_nameinit(1);
+ r = idn_encodename(IDN_ENCODE_APP, name, buf.data, sizeof(buf));
+ if (r == idn_success)
+ name = buf.data;
+
+ hp = copy_decode_hostent_static(REAL(gethostbyname2)(name, af),
+ &he, buf.data, sizeof(buf),
+ &h_errno);
+ idn_isprocessing = 0;
+ return (hp);
+}
+#endif
+
+#ifdef HAVE_GETHOSTBYADDR
+struct hostent *
+ENTRY(gethostbyaddr)(GHBA_ADDR_T addr, GHBA_ADDRLEN_T len, int type) {
+ static hostbuf_t buf;
+ static struct hostent he;
+ struct hostent *hp;
+
+ if (idn_isprocessing)
+ return (REAL(gethostbyaddr)(addr, len, type));
+
+ TRACE(("gethostbyaddr()\n"));
+
+ idn_isprocessing = 1;
+ hp = copy_decode_hostent_static(REAL(gethostbyaddr)(addr, len, type),
+ &he, buf.data, sizeof(buf),
+ &h_errno);
+ idn_isprocessing = 0;
+ return (hp);
+}
+#endif
+
+#ifdef GETHOST_R_GLIBC_FLAVOR
+
+#ifdef HAVE_GETHOSTBYNAME_R
+int
+ENTRY(gethostbyname_r)(const char *name, struct hostent *result,
+ char *buffer, size_t buflen,
+ struct hostent **rp, int *errp)
+{
+ char namebuf[IDN_NAME_SIZE];
+ char *data;
+ size_t datalen;
+ idn_result_t r;
+ struct hostent he;
+ hostbuf_t buf;
+ int n;
+
+ if (idn_isprocessing)
+ return (REAL(gethostbyname_r)(name, result, buffer,
+ buflen, rp, errp));
+
+ TRACE(("gethostbyname_r(name=%s,buflen=%d)\n",
+ idn__debug_xstring(name, 60), buflen));
+
+ if (buflen <= sizeof(buf)) {
+ data = buf.data;
+ datalen = sizeof(buf);
+ } else {
+ data = malloc(buflen);
+ datalen = buflen;
+ if (data == NULL) {
+ *errp = NO_RECOVERY;
+ return (ENOMEM);
+ }
+ }
+
+ idn_isprocessing = 1;
+ idn_enable(1);
+ idn_nameinit(1);
+ r = idn_encodename(IDN_ENCODE_APP, name, namebuf, sizeof(namebuf));
+ if (r == idn_success)
+ name = namebuf;
+
+ *errp = 0;
+ n = REAL(gethostbyname_r)(name, &he, data, datalen, rp, errp);
+
+ if (n == 0 && *rp != NULL)
+ *rp = copy_decode_hostent_static(*rp, result, buffer, buflen,
+ errp);
+ idn_isprocessing = 0;
+
+ if (data != buf.data)
+ free(data);
+
+ if (*errp != 0)
+ n = EINVAL; /* XXX */
+
+ return (n);
+}
+#endif
+
+#ifdef HAVE_GETHOSTBYNAME2_R
+int
+ENTRY(gethostbyname2_r)(const char *name, int af, struct hostent *result,
+ char *buffer, size_t buflen,
+ struct hostent **rp, int *errp)
+{
+ char namebuf[IDN_NAME_SIZE];
+ char *data;
+ size_t datalen;
+ idn_result_t r;
+ struct hostent he;
+ hostbuf_t buf;
+ int n;
+
+ if (idn_isprocessing)
+ return (REAL(gethostbyname2_r)(name, af, result, buffer,
+ buflen, rp, errp));
+
+ TRACE(("gethostbyname2_r(name=%s,buflen=%d)\n",
+ idn__debug_xstring(name, 60), buflen));
+
+ if (buflen <= sizeof(buf)) {
+ data = buf.data;
+ datalen = sizeof(buf);
+ } else {
+ data = malloc(buflen);
+ datalen = buflen;
+ if (data == NULL) {
+ *errp = NO_RECOVERY;
+ return (ENOMEM);
+ }
+ }
+
+ idn_isprocessing = 1;
+ idn_enable(1);
+ idn_nameinit(1);
+ r = idn_encodename(IDN_ENCODE_APP, name, namebuf, sizeof(namebuf));
+ if (r == idn_success)
+ name = namebuf;
+
+ n = REAL(gethostbyname2_r)(name, af, &he, data, datalen, rp, errp);
+
+ if (n == 0 && *rp != NULL)
+ *rp = copy_decode_hostent_static(*rp, result, buffer, buflen,
+ errp);
+ idn_isprocessing = 0;
+
+ if (data != buf.data)
+ free(data);
+
+ if (*errp != 0)
+ n = EINVAL; /* XXX */
+
+ return (n);
+}
+#endif
+
+#ifdef HAVE_GETHOSTBYADDR_R
+int
+ENTRY(gethostbyaddr_r)(GHBA_ADDR_T addr, GHBA_ADDRLEN_T len, int type,
+ struct hostent *result,
+ char *buffer, size_t buflen,
+ struct hostent **rp, int *errp)
+{
+ char *data;
+ size_t datalen;
+ struct hostent he;
+ hostbuf_t buf;
+ int n;
+
+ if (idn_isprocessing) {
+ return (REAL(gethostbyaddr_r)(addr, len, type, result,
+ buffer, buflen, rp, errp));
+ }
+
+ TRACE(("gethostbyaddr_r(buflen=%d)\n", buflen));
+
+ if (buflen <= sizeof(buf)) {
+ data = buf.data;
+ datalen = sizeof(buf);
+ } else {
+ data = malloc(buflen);
+ datalen = buflen;
+ if (data == NULL) {
+ *errp = NO_RECOVERY;
+ return (ENOMEM);
+ }
+ }
+
+ idn_isprocessing = 1;
+ n = REAL(gethostbyaddr_r)(addr, len, type, &he,
+ data, datalen, rp, errp);
+
+ if (n == 0 && *rp != NULL)
+ *rp = copy_decode_hostent_static(*rp, result, buffer, buflen,
+ errp);
+ idn_isprocessing = 0;
+
+ if (data != buf.data)
+ free(data);
+
+ if (*errp != 0)
+ n = EINVAL; /* XXX */
+
+ return (0);
+}
+#endif
+
+#else /* GETHOST_R_GLIBC_FLAVOR */
+
+#ifdef HAVE_GETHOSTBYNAME_R
+struct hostent *
+ENTRY(gethostbyname_r)(const char *name, struct hostent *result,
+ char *buffer, int buflen, int *errp)
+{
+ char namebuf[IDN_NAME_SIZE];
+ char *data;
+ size_t datalen;
+ idn_result_t r;
+ struct hostent *hp, he;
+ hostbuf_t buf;
+
+ if (idn_isprocessing)
+ return (REAL(gethostbyname_r)(name, result, buffer,
+ buflen, errp));
+
+ TRACE(("gethostbyname_r(name=%s,buflen=%d)\n",
+ idn__debug_xstring(name, 60), buflen));
+
+ if (buflen <= sizeof(buf)) {
+ data = buf.data;
+ datalen = sizeof(buf);
+ } else {
+ data = malloc(buflen);
+ datalen = buflen;
+ if (data == NULL) {
+ *errp = NO_RECOVERY;
+ return (NULL);
+ }
+ }
+
+ idn_isprocessing = 1;
+ idn_enable(1);
+ idn_nameinit(1);
+ r = idn_encodename(IDN_ENCODE_APP, name, namebuf, sizeof(namebuf));
+ if (r == idn_success)
+ name = namebuf;
+
+ hp = REAL(gethostbyname_r)(name, &he, data, datalen, errp);
+
+ if (hp != NULL)
+ hp = copy_decode_hostent_static(hp, result, buffer, buflen,
+ errp);
+ idn_isprocessing = 0;
+
+ if (data != buf.data)
+ free(data);
+
+ return (hp);
+}
+#endif
+
+#ifdef HAVE_GETHOSTBYADDR_R
+struct hostent *
+ENTRY(gethostbyaddr_r)(GHBA_ADDR_T addr, GHBA_ADDRLEN_T len, int type,
+ struct hostent *result,
+ char *buffer, int buflen, int *errp)
+{
+ char *data;
+ size_t datalen;
+ struct hostent *hp, he;
+ hostbuf_t buf;
+
+ if (idn_isprocessing) {
+ return (REAL(gethostbyaddr_r)(addr, len, type, result,
+ buffer, buflen, errp));
+ }
+
+ TRACE(("gethostbyaddr_r(buflen=%d)\n", buflen));
+
+ if (buflen <= sizeof(buf)) {
+ data = buf.data;
+ datalen = sizeof(buf);
+ } else {
+ data = malloc(buflen);
+ datalen = buflen;
+ if (data == NULL) {
+ *errp = NO_RECOVERY;
+ return (NULL);
+ }
+ }
+
+ idn_isprocessing = 1;
+ hp = REAL(gethostbyaddr_r)(addr, len, type, &he, data, datalen, errp);
+
+ if (hp != NULL)
+ hp = copy_decode_hostent_static(hp, result, buffer, buflen,
+ errp);
+ idn_isprocessing = 0;
+
+ if (data != buf.data)
+ free(data);
+
+ return (hp);
+}
+#endif
+
+#endif /* GETHOST_R_GLIBC_FLAVOR */
+
+#ifdef HAVE_GETIPNODEBYNAME
+struct hostent *
+ENTRY(getipnodebyname)(const char *name, int af, int flags, int *errp) {
+ char namebuf[IDN_NAME_SIZE];
+ idn_result_t r;
+ struct hostent *hp;
+
+ if (idn_isprocessing)
+ return (REAL(getipnodebyname)(name, af, flags, errp));
+
+ TRACE(("getipnodebyname(name=%s)\n", idn__debug_xstring(name, 60), af));
+
+ idn_isprocessing = 1;
+ idn_enable(1);
+ idn_nameinit(1);
+ r = idn_encodename(IDN_ENCODE_APP, name, namebuf, sizeof(namebuf));
+ if (r == idn_success)
+ name = namebuf;
+
+ hp = REAL(getipnodebyname)(name, af, flags, errp);
+ if (hp != NULL) {
+ struct hostent *newhp = copy_decode_hostent_dynamic(hp, errp);
+ if (newhp != hp) {
+ REAL(freehostent)(hp);
+ obj_lock(newhp);
+ hp = newhp;
+ }
+ }
+ idn_isprocessing = 0;
+ return (hp);
+}
+#endif
+
+#ifdef HAVE_GETIPNODEBYADDR
+struct hostent *
+ENTRY(getipnodebyaddr)(const void *src, size_t len, int af, int *errp) {
+ struct hostent *hp;
+
+ if (idn_isprocessing)
+ return (REAL(getipnodebyaddr)(src, len, af, errp));
+
+ TRACE(("getipnodebyaddr()\n"));
+
+ idn_isprocessing = 1;
+ hp = REAL(getipnodebyaddr)(src, len, af, errp);
+ if (hp != NULL) {
+ struct hostent *newhp = copy_decode_hostent_dynamic(hp, errp);
+ if (newhp != hp) {
+ REAL(freehostent)(hp);
+ obj_lock(newhp);
+ hp = newhp;
+ }
+ }
+ idn_isprocessing = 0;
+ return (hp);
+}
+#endif
+
+#ifdef HAVE_FREEHOSTENT
+void
+ENTRY(freehostent)(struct hostent *hp) {
+ TRACE(("freehostent(hp=%p)\n", (void *)hp));
+
+ if (obj_islocked(hp)) {
+ /*
+ * We allocated the data.
+ */
+ obj_unlock(hp);
+ free_copied_hostent(hp);
+ } else {
+ /*
+ * It was allocated the original getipnodeby*().
+ */
+ REAL(freehostent)(hp);
+ }
+}
+#endif
+
+#ifdef HAVE_GETADDRINFO
+int
+ENTRY(getaddrinfo)(const char *nodename, const char *servname,
+ const struct addrinfo *hints, struct addrinfo **res)
+{
+ char namebuf[IDN_NAME_SIZE];
+ idn_result_t r;
+ struct addrinfo *aip;
+ int err;
+
+ if (nodename == NULL || idn_isprocessing)
+ return (REAL(getaddrinfo)(nodename, servname, hints, res));
+
+ TRACE(("getaddrinfo(nodename=%s)\n", idn__debug_xstring(nodename, 60)));
+
+ idn_isprocessing = 1;
+ idn_enable(1);
+ idn_nameinit(1);
+ r = idn_encodename(IDN_ENCODE_APP, nodename,
+ namebuf, sizeof(namebuf));
+ if (r == idn_success)
+ nodename = namebuf;
+
+ err = REAL(getaddrinfo)(nodename, servname, hints, &aip);
+ if (err == 0 && aip != NULL) {
+ *res = copy_decode_addrinfo_dynamic(aip);
+ if (*res == NULL)
+ err = EAI_FAIL;
+ else
+ obj_lock(*res);
+ if (aip != NULL)
+ REAL(freeaddrinfo)(aip);
+ }
+ idn_isprocessing = 0;
+ return (err);
+}
+#endif
+
+#ifdef HAVE_FREEADDRINFO
+void
+ENTRY(freeaddrinfo)(struct addrinfo *aip) {
+ TRACE(("freeaddrinfo(aip=%p)\n", (void *)aip));
+
+ if (obj_islocked(aip)) {
+ /*
+ * We allocated the data.
+ */
+ obj_unlock(aip);
+ free_copied_addrinfo(aip);
+ } else {
+ /*
+ * It was allocated the original getaddrinfo().
+ */
+ REAL(freeaddrinfo)(aip);
+ }
+}
+#endif
+
+#ifdef HAVE_GETNAMEINFO
+int
+ENTRY(getnameinfo)(const struct sockaddr *sa, GNI_SALEN_T salen,
+ char *host, GNI_HOSTLEN_T hostlen, char *serv,
+ GNI_SERVLEN_T servlen, GNI_FLAGS_T flags)
+{
+ char name[IDN_NAME_SIZE];
+ size_t namelen = sizeof(name);
+ int code;
+ idn_result_t r;
+
+ if (host == NULL || hostlen == 0 || idn_isprocessing) {
+ return (REAL(getnameinfo)(sa, salen, host, hostlen,
+ serv, servlen, flags));
+ }
+
+ TRACE(("getnameinfo(hostlen=%u)\n", hostlen));
+
+ idn_isprocessing = 1;
+ code = REAL(getnameinfo)(sa, salen, name, namelen,
+ serv, servlen, flags);
+ if (code == 0 && name[0] != '\0') {
+ idn_enable(1);
+ idn_nameinit(1);
+ r = idn_decodename(IDN_DECODE_APP, name, host, hostlen);
+ switch (r) {
+ case idn_success:
+ code = 0;
+ break;
+ case idn_buffer_overflow:
+ case idn_nomemory:
+ code = EAI_MEMORY;
+ break;
+ default:
+ code = EAI_FAIL;
+ break;
+ }
+ }
+ idn_isprocessing = 0;
+ return (code);
+}
+#endif
diff --git a/contrib/idn/idnkit-1.0-src/tools/runidn/resolver.h b/contrib/idn/idnkit-1.0-src/tools/runidn/resolver.h
new file mode 100644
index 0000000..e3fc35e
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/runidn/resolver.h
@@ -0,0 +1,70 @@
+/* $Id: resolver.h,v 1.1.1.1 2003/06/04 00:27:13 marka 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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+ * Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+ *
+ * 4. The name of JPNIC may not 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.
+ */
+
+#ifndef RESOLVER_H
+#define RESOLVER_H 1
+
+#undef gethostbyname
+#define gethostbyname idn_resolver_gethostbyname
+#undef gethostbyname2
+#define gethostbyname2 idn_resolver_gethostbyname2
+#undef gethostbyname_r
+#define gethostbyname_r idn_resolver_gethostbyname_r
+#undef gethostbyaddr
+#define gethostbyaddr idn_resolver_gethostbyaddr
+#undef gethostbyaddr
+#define gethostbyaddr_r idn_resolver_gethostbyaddr_r
+#undef getipnodebyname
+#define getipnodebyname idn_resolver_getipnodebyname
+#undef getipnodebyaddr
+#define getipnodebyaddr idn_resolver_getipnodebyaddr
+#undef freehostent
+#define freehostent idn_resolver_freehostent
+#undef getaddrinfo
+#define getaddrinfo idn_resolver_getaddrinfo
+#undef freeaddrinfo
+#define freeaddrinfo idn_resolver_freeaddrinfo
+#undef getnameinfo
+#define getnameinfo idn_resolver_getnameinfo
+
+#endif /* RESOLVER_H */
diff --git a/contrib/idn/idnkit-1.0-src/tools/runidn/runidn.1 b/contrib/idn/idnkit-1.0-src/tools/runidn/runidn.1
new file mode 100644
index 0000000..a8b1270
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/runidn/runidn.1
@@ -0,0 +1,151 @@
+.\" $Id: runidn.1,v 1.1.1.1 2003/06/04 00:27:14 marka Exp $
+.\"
+.\" Copyright (c) 2000,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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+.\" Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+.\"
+.\" 4. The name of JPNIC may not 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.
+.\"
+.TH RUNIDN 1 "April 6, 2001"
+.\"
+.SH NAME
+runidn \- A script to allow applications to use internationalized domain names.
+.\"
+.SH SYNOPSIS
+\fBrunidn\fP [\fB-e\fP \fIlocal-codeset\fP] \fIprogram-name\fP [\fIargs..\fP]
+.\"
+.SH DESCRIPTION
+\fBrunidn\fP enables applications to use internationalized domain names
+without recompilation.
+Just add ``runidn'' before the application-name, and the application
+can handle non-ASCII domain names. For example, you can do:
+.PP
+.RS 4
+.nf
+\f(CW% runidn telnet \fInon-ASCII-hostname\fR
+.fi
+.RE
+.PP
+Before using runidn, you should set up properties related to
+internationalized DNS by configuring idnkit's configuration file
+\fBidn.conf\fP.
+See idn.conf(5) which describes the configuration.
+.\"
+.SH OPTION
+The following option is available:
+.TP 4
+\fB\-e\fP \fIlocal-codeset\fP
+Specify the application's local codeset.
+If the option is not specified, \fBrunidn\fR guesses the codeset
+from the current locale.
+See the ``NOTE'' section for more details about local codeset.
+.\"
+.SH IMPLEMENTATION
+\fBrunidn\fR is a small shell script that sets up an environment variable
+called ``LD_PRELOAD'', so that an application dynamically links a shared
+library ``libidnkitres'' before any other shared libraries.
+.PP
+The library ``libidnkitres'' provides a special version of resolver
+functions which implement features for handling internationalized
+domain names.
+\fBrunidn\fR replaces the following functions with the special version:
+.PP
+.RS 4
+.nf
+.ft CW
+gethostbyname
+gethostbyname2
+gethostbyaddr
+gethostbyname_r
+gethostbyname2_r
+gethostbyaddr_r
+getipnodebyname
+getipnodebyaddr
+freehostent
+getaddrinfo
+freeaddrinfo
+getnameinfo
+.ft R
+.fi
+.RE
+.PP
+By overriding them in the standard libraries with the special version
+provided by ``libidnkitres'',
+\fBrunidn\fR enables applications to use internationalized domain names.
+.RS 4
+.IP \(bu 2
+These API functions accept non-ASCII domain names encoded
+in the local codeset that the application is using.
+Also the result from these APIs may contain non-ASCII domain names.
+.IP \(bu 2
+The normalization and codeset conversion between application's local
+codeset and the codeset used in DNS protocol data are handled
+automatically, so users/applications need not worry about them.
+.RE
+.PP
+Properties of internationalized DNS (such as the normalization or
+the codeset used on DNS protocol data) can be configured with the
+idnkit's configuration file (\fBidn.conf\fR).
+See idn.conf(5) for details.
+.\"
+.SH NOTE
+Unless \fB\-e\fP option is specified, \fBrunidn\fR tries to guess
+the application's local codeset from the application's current locale.
+However, sometimes it cannot guess the codeset correctly, for example
+if the application does not set the locale appropriately by calling
+`setlocale()'.
+In that case, you can explicitly specify the local codeset by setting an
+environment variable ``IDN_LOCAL_CODESET''.
+See the section ``LOCAL CODESET'' in idn.conf(5) for details.
+.PP
+The idea of using ``LD_PRELOAD'' to replace some functions in the standard
+library was taken from ``runsocks'' script distributed as part of SOCKS5
+reference implementation.
+.SH BUGS
+There are many cases where \fBrunidn\fR does not work.
+.PP
+Your system must support ``LD_PRELOAD'' mechanism in the first place.
+.PP
+Due to security reasons, ``LD_PRELOAD'' mechanism is disabled for
+setuid programs in any sane systems.
+So \fBrunidn\fR does not work for setuid programs such as ping or rsh.
+.PP
+If your application uses a function other than the ones runidn supports for
+name resolution, you lose.
+.SH "SEE ALSO"
+idn.conf(5), runsocks(1)
diff --git a/contrib/idn/idnkit-1.0-src/tools/runidn/runidn.in b/contrib/idn/idnkit-1.0-src/tools/runidn/runidn.in
new file mode 100644
index 0000000..6437658
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/runidn/runidn.in
@@ -0,0 +1,109 @@
+#! /bin/sh
+# $Id: runidn.in,v 1.1.1.1 2003/06/04 00:27:14 marka Exp $
+#
+# Copyright (c) 2000 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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+# Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+#
+# 4. The name of JPNIC may not 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.
+
+# Parse command line options.
+usage="Usage: `basename $0` [-e local-encoding] command [argument..]"
+while test $# -gt 0; do
+ case "$1" in
+ -e)
+ if test $# -le 1; then
+ echo $usage 1>&2
+ exit 1
+ fi
+ IDN_LOCAL_CODESET="$2"
+ export IDN_LOCAL_CODESET
+ shift
+ ;;
+ -)
+ break
+ ;;
+ -*)
+ echo $usage 1>&2
+ exit 1
+ ;;
+ *)
+ break
+ ;;
+ esac
+ shift
+done
+if test $# -eq 0; then
+ echo $usage 1>&2
+ exit 1
+fi
+
+# Load library info.
+preload=
+iconv_file=@ICONVSOFILE@
+if test "$iconv_file" != none; then
+ preload="$iconv_file@PRELOAD_SEP@"
+fi
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=`echo @libdir@`
+if test ! -f $libdir/libidnkitres.la; then
+ cat <<EOF 1>&2
+Have you installed idnkit? I cannot find libidnkitres.la.
+EOF
+ exit 1
+fi
+eval `grep '^dlname' $libdir/libidnkitres.la`
+if test "$dlname" = ""; then
+ cat <<EOF 1>&2
+Sorry, runidn won't work because libidnkitres is not dynamically loadable.
+EOF
+ exit 1
+fi
+preload=$preload$libdir/$dlname
+
+# Set @PRELOAD_VAR@.
+if [ X$@PRELOAD_VAR@ = X ]; then
+ @PRELOAD_VAR@="$preload@PRELOAD_LAST@"
+else
+ @PRELOAD_VAR@="$preload@PRELOAD_SEP@$@PRELOAD_VAR@@PRELOAD_LAST@"
+fi
+export @PRELOAD_VAR@
+
+# Shoot.
+exec "$@"
diff --git a/contrib/idn/idnkit-1.0-src/tools/runidn/stub.c b/contrib/idn/idnkit-1.0-src/tools/runidn/stub.c
new file mode 100644
index 0000000..0ec1685
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/runidn/stub.c
@@ -0,0 +1,387 @@
+#ifndef lint
+static char *rcsid = "$Id: stub.c,v 1.1.1.1 2003/06/04 00:27:13 marka Exp $";
+#endif
+
+/*
+ * 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, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+ * Chiyoda-ku, Tokyo 101-0047, 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) 2000-2002 Japan Network Information Center. All rights reserved."
+ *
+ * 4. The name of JPNIC may not 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.
+ */
+
+#include <config.h>
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <errno.h>
+#ifdef HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include <idn/logmacro.h>
+#include <idn/debug.h>
+
+#include "stub.h"
+
+#ifndef RTLD_NEXT
+typedef struct {
+ const char *name;
+ void *handle;
+} shared_obj_t;
+
+static shared_obj_t shobj[] = {
+#ifdef SOPATH_LIBC
+ { SOPATH_LIBC },
+#endif
+#ifdef SOPATH_LIBNSL
+ { SOPATH_LIBNSL },
+#endif
+ { NULL },
+};
+#endif
+
+static void *shared_obj_findsym(void *handle, const char *name);
+static void *shared_obj_findsymx(void *handle, const char *name);
+static void *get_func_addr(const char *name);
+
+#ifndef RTLD_NEXT
+static void *
+shared_obj_open(const char *path) {
+#ifdef HAVE_DLOPEN
+ return (dlopen(path, RTLD_LAZY));
+#endif
+ FATAL(("stub: no way to load shared object file\n"));
+ return (NULL);
+}
+#endif
+
+static void *
+shared_obj_findsym(void *handle, const char *name) {
+ char namebuf[100];
+ void *addr;
+ static int need_leading_underscore = -1;
+
+ /* Prepend underscore. */
+ namebuf[0] = '_';
+ (void)strcpy(namebuf + 1, name);
+ name = namebuf;
+
+ if (need_leading_underscore < 0) {
+ /* First try without one. */
+ if ((addr = shared_obj_findsymx(handle, name + 1)) != NULL) {
+ need_leading_underscore = 0;
+ return (addr);
+ }
+ /* Then try with one. */
+ if ((addr = shared_obj_findsymx(handle, name)) != NULL) {
+ need_leading_underscore = 1;
+ return (addr);
+ }
+ } else if (need_leading_underscore) {
+ return (shared_obj_findsymx(handle, name));
+ } else {
+ return (shared_obj_findsymx(handle, name + 1));
+ }
+ return (NULL);
+}
+
+static void *
+shared_obj_findsymx(void *handle, const char *name) {
+#ifdef HAVE_DLSYM
+ return (dlsym(handle, name));
+#endif
+ /* logging */
+ FATAL(("stub: no way to get symbol address\n"));
+ return (NULL);
+}
+
+static void *
+get_func_addr(const char *name) {
+#ifdef RTLD_NEXT
+ void *addr = shared_obj_findsym(RTLD_NEXT, name);
+
+ if (addr != NULL) {
+ TRACE(("stub: %s found in the subsequent objects\n", name));
+ return (addr);
+ }
+#else
+ int i;
+
+ for (i = 0; shobj[i].name != NULL; i++) {
+ if (shobj[i].handle == NULL) {
+ TRACE(("stub: loading %s\n", shobj[i].name));
+ shobj[i].handle = shared_obj_open(shobj[i].name);
+ }
+ if (shobj[i].handle != NULL) {
+ void *addr = shared_obj_findsym(shobj[i].handle, name);
+ if (addr != NULL) {
+ TRACE(("stub: %s found in %s\n",
+ name, shobj[i].name));
+ return (addr);
+ }
+ }
+ }
+#endif
+ TRACE(("stub: %s not found\n", name));
+ return (NULL);
+}
+
+#ifdef HAVE_GETHOSTBYNAME
+struct hostent *
+idn_stub_gethostbyname(const char *name) {
+ static struct hostent *(*fp)(const char *name);
+
+ if (fp == NULL)
+ fp = get_func_addr("gethostbyname");
+ if (fp != NULL)
+ return ((*fp)(name));
+ return (NULL);
+}
+#endif
+
+#ifdef HAVE_GETHOSTBYNAME2
+struct hostent *
+idn_stub_gethostbyname2(const char *name, int af) {
+ static struct hostent *(*fp)(const char *name, int af);
+
+ if (fp == NULL)
+ fp = get_func_addr("gethostbyname2");
+ if (fp != NULL)
+ return ((*fp)(name, af));
+ return (NULL);
+}
+#endif
+
+#ifdef HAVE_GETHOSTBYADDR
+struct hostent *
+idn_stub_gethostbyaddr(GHBA_ADDR_T addr, GHBA_ADDRLEN_T len, int type) {
+ static struct hostent *(*fp)(GHBA_ADDR_T name,
+ GHBA_ADDRLEN_T len, int type);
+
+ if (fp == NULL)
+ fp = get_func_addr("gethostbyaddr");
+ if (fp != NULL)
+ return ((*fp)(addr, len, type));
+ return (NULL);
+}
+#endif
+
+#ifdef GETHOST_R_GLIBC_FLAVOR
+
+#ifdef HAVE_GETHOSTBYNAME_R
+int
+idn_stub_gethostbyname_r(const char *name, struct hostent *result,
+ char *buffer, size_t buflen,
+ struct hostent **rp, int *errp)
+{
+ static int (*fp)(const char *name, struct hostent *result,
+ char *buffer, size_t buflen,
+ struct hostent **rp, int *errp);
+
+ if (fp == NULL)
+ fp = get_func_addr("gethostbyname_r");
+ if (fp != NULL)
+ return ((*fp)(name, result, buffer, buflen, rp, errp));
+ return (ENOENT); /* ??? */
+}
+#endif
+
+#ifdef HAVE_GETHOSTBYNAME2_R
+int
+idn_stub_gethostbyname2_r(const char *name, int af, struct hostent *result,
+ char *buffer, size_t buflen,
+ struct hostent **rp, int *errp)
+{
+ static int (*fp)(const char *name, int af, struct hostent *result,
+ char *buffer, size_t buflen,
+ struct hostent **rp, int *errp);
+
+ if (fp == NULL)
+ fp = get_func_addr("gethostbyname2_r");
+ if (fp != NULL)
+ return ((*fp)(name, af, result, buffer, buflen, rp, errp));
+ return (ENOENT); /* ??? */
+}
+#endif
+
+#ifdef HAVE_GETHOSTBYADDR_R
+int
+idn_stub_gethostbyaddr_r(GHBA_ADDR_T addr, GHBA_ADDRLEN_T len, int type,
+ struct hostent *result, char *buffer,
+ size_t buflen, struct hostent **rp, int *errp)
+{
+ static int (*fp)(GHBA_ADDR_T addr, GHBA_ADDRLEN_T len, int type,
+ struct hostent *result, char *buffer,
+ size_t buflen, struct hostent **rp, int *errp);
+
+ if (fp == NULL)
+ fp = get_func_addr("gethostbyaddr_r");
+ if (fp != NULL)
+ return ((*fp)(addr, len, type, result,
+ buffer, buflen, rp, errp));
+ return (ENOENT); /* ??? */
+}
+#endif
+
+#else /* GETHOST_R_GLIBC_FLAVOR */
+
+#ifdef HAVE_GETHOSTBYNAME_R
+struct hostent *
+idn_stub_gethostbyname_r(const char *name, struct hostent *result,
+ char *buffer, int buflen, int *errp)
+{
+ static struct hostent *(*fp)(const char *name, struct hostent *result,
+ char *buffer, int buflen, int *errp);
+
+ if (fp == NULL)
+ fp = get_func_addr("gethostbyname_r");
+ if (fp != NULL)
+ return ((*fp)(name, result, buffer, buflen, errp));
+ return (NULL);
+}
+#endif
+
+#ifdef HAVE_GETHOSTBYADDR_R
+struct hostent *
+idn_stub_gethostbyaddr_r(GHBA_ADDR_T addr, int len, int type,
+ struct hostent *result, char *buffer,
+ int buflen, int *errp)
+{
+ static struct hostent *(*fp)(GHBA_ADDR_T addr, int len, int type,
+ struct hostent *result, char *buffer,
+ int buflen, int *errp);
+
+ if (fp == NULL)
+ fp = get_func_addr("gethostbyaddr_r");
+ if (fp != NULL)
+ return ((*fp)(addr, len, type, result, buffer, buflen, errp));
+ return (NULL);
+}
+#endif
+
+#endif /* GETHOST_R_GLIBC_FLAVOR */
+
+#ifdef HAVE_GETIPNODEBYNAME
+struct hostent *
+idn_stub_getipnodebyname(const char *name, int af, int flags, int *errp) {
+ static struct hostent *(*fp)(const char *name, int af, int flags,
+ int *errp);
+
+ if (fp == NULL)
+ fp = get_func_addr("getipnodebyname");
+ if (fp != NULL)
+ return ((*fp)(name, af, flags, errp));
+ return (NULL);
+}
+#endif
+
+#ifdef HAVE_GETIPNODEBYADDR
+struct hostent *
+idn_stub_getipnodebyaddr(const void *src, size_t len, int af, int *errp) {
+ static struct hostent *(*fp)(const void *src, size_t len, int af,
+ int *errp);
+
+ if (fp == NULL)
+ fp = get_func_addr("getipnodebyaddr");
+ if (fp != NULL)
+ return ((*fp)(src, len, af, errp));
+ return (NULL);
+}
+#endif
+
+#ifdef HAVE_FREEHOSTENT
+void
+idn_stub_freehostent(struct hostent *hp) {
+ static void (*fp)(struct hostent *hp);
+
+ if (fp == NULL)
+ fp = get_func_addr("freehostent");
+ if (fp != NULL)
+ (*fp)(hp);
+}
+#endif
+
+#ifdef HAVE_GETADDRINFO
+int
+idn_stub_getaddrinfo(const char *nodename, const char *servname,
+ const struct addrinfo *hints, struct addrinfo **res)
+{
+ static int (*fp)(const char *nodename, const char *servname,
+ const struct addrinfo *hints, struct addrinfo **res);
+
+ if (fp == NULL)
+ fp = get_func_addr("getaddrinfo");
+ if (fp != NULL)
+ return ((*fp)(nodename, servname, hints, res));
+ return (EAI_FAIL);
+}
+#endif
+
+#ifdef HAVE_FREEADDRINFO
+void
+idn_stub_freeaddrinfo(struct addrinfo *aip) {
+ static void (*fp)(struct addrinfo *aip);
+
+ if (fp == NULL)
+ fp = get_func_addr("freeaddrinfo");
+ if (fp != NULL)
+ (*fp)(aip);
+}
+#endif
+
+#ifdef HAVE_GETNAMEINFO
+int
+idn_stub_getnameinfo(const struct sockaddr *sa, GNI_SALEN_T salen,
+ char *host, GNI_HOSTLEN_T hostlen,
+ char *serv, GNI_SERVLEN_T servlen, GNI_FLAGS_T flags) {
+ static int (*fp)(const struct sockaddr *sa, GNI_SALEN_T salen,
+ char *host, GNI_HOSTLEN_T hostlen,
+ char *serv, GNI_SERVLEN_T servlen,
+ GNI_FLAGS_T flags);
+
+ if (fp == NULL)
+ fp = get_func_addr("getnameinfo");
+ if (fp != NULL)
+ return ((*fp)(sa, salen, host, hostlen, serv, servlen, flags));
+ return (EAI_FAIL);
+}
+#endif
diff --git a/contrib/idn/idnkit-1.0-src/tools/runidn/stub.h b/contrib/idn/idnkit-1.0-src/tools/runidn/stub.h
new file mode 100644
index 0000000..48167ed
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/tools/runidn/stub.h
@@ -0,0 +1,94 @@
+/* $Id: stub.h,v 1.1.1.1 2003/06/04 00:27:13 marka Exp $ */
+
+#ifndef STUB_H
+#define STUB_H
+
+#ifdef HAVE_GETHOSTBYNAME
+extern struct hostent *
+idn_stub_gethostbyname(const char *name);
+#endif
+
+#ifdef GETHOST_R_GLIBC_FLAVOR
+#ifdef HAVE_GETHOSTBYNAME_R
+extern int
+idn_stub_gethostbyname_r(const char *name, struct hostent *result,
+ char *buffer, size_t buflen,
+ struct hostent **rp, int *errp);
+#endif
+#else /* GETHOST_R_GLIBC_FLAVOR */
+#ifdef HAVE_GETHOSTBYNAME_R
+extern struct hostent *
+idn_stub_gethostbyname_r(const char *name, struct hostent *result,
+ char *buffer, int buflen, int *errp);
+#endif
+#endif /* GETHOST_R_GLIBC_FLAVOR */
+
+#ifdef HAVE_GETHOSTBYNAME2
+extern struct hostent *
+idn_stub_gethostbyname2(const char *name, int af);
+#endif
+
+#ifdef GETHOST_R_GLIBC_FLAVOR
+#ifdef HAVE_GETHOSTBYNAME2_R
+extern int
+idn_stub_gethostbyname2_r(const char *name, int af, struct hostent *result,
+ char *buffer, size_t buflen,
+ struct hostent **rp, int *errp);
+#endif
+#endif /* GETHOST_R_GLIBC_FLAVOR */
+
+#ifdef HAVE_GETHOSTBYADDR
+extern struct hostent *
+idn_stub_gethostbyaddr(GHBA_ADDR_T addr, GHBA_ADDRLEN_T len, int type);
+#endif
+
+#ifdef GETHOST_R_GLIBC_FLAVOR
+#ifdef HAVE_GETHOSTBYADDR_R
+extern int
+idn_stub_gethostbyaddr_r(GHBA_ADDR_T addr, GHBA_ADDRLEN_T len, int type,
+ struct hostent *result, char *buffer,
+ size_t buflen, struct hostent **rp, int *errp);
+#endif
+#else /* GETHOST_R_GLIBC_FLAVOR */
+#ifdef HAVE_GETHOSTBYADDR_R
+extern struct hostent *
+idn_stub_gethostbyaddr_r(GHBA_ADDR_T addr, GHBA_ADDRLEN_T len, int type,
+ struct hostent *result, char *buffer,
+ int buflen, int *errp);
+#endif
+#endif /* GETHOST_R_GLIBC_FLAVOR */
+
+#ifdef HAVE_GETIPNODEBYNAME
+extern struct hostent *
+idn_stub_getipnodebyname(const char *name, int af, int flags, int *errp);
+#endif
+
+#ifdef HAVE_GETIPNODEBYADDR
+extern struct hostent *
+idn_stub_getipnodebyaddr(const void *src, size_t len, int af, int *errp);
+#endif
+
+#ifdef HAVE_FREEHOSTENT
+extern void
+idn_stub_freehostent(struct hostent *hp);
+#endif
+
+#ifdef HAVE_GETADDRINFO
+extern int
+idn_stub_getaddrinfo(const char *nodename, const char *servname,
+ const struct addrinfo *hints, struct addrinfo **res);
+#endif
+
+#ifdef HAVE_FREEADDRINFO
+extern void
+idn_stub_freeaddrinfo(struct addrinfo *aip);
+#endif
+
+#ifdef HAVE_GETNAMEINFO
+extern int
+idn_stub_getnameinfo(const struct sockaddr *sa, GNI_SALEN_T salen,
+ char *host, GNI_HOSTLEN_T hostlen, char *serv,
+ GNI_SERVLEN_T servlen, GNI_FLAGS_T flags);
+#endif
+
+#endif /* STUB_H */